| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- import {Service} from '@e22m4u/js-service';
- import {projectData} from './project-data.js';
- import {ProjectionSchemaRegistry} from './definitions/index.js';
- /**
- * Data projector.
- */
- export class DataProjector extends Service {
- /**
- * Define schema.
- *
- * @param {object} schemaDef
- * @returns {this}
- */
- defineSchema(schemaDef) {
- this.getService(ProjectionSchemaRegistry).defineSchema(schemaDef);
- return this;
- }
- /**
- * Has schema.
- *
- * @param {string} schemaName
- * @returns {boolean}
- */
- hasSchema(schemaName) {
- return this.getService(ProjectionSchemaRegistry).hasSchema(schemaName);
- }
- /**
- * Project.
- *
- * @param {object|Function|string} schemaOrFactory
- * @param {*} data
- * @param {object} [options]
- * @returns {*}
- */
- project(schemaOrFactory, data, options) {
- const registry = this.getService(ProjectionSchemaRegistry);
- const resolver = schemaName => {
- return registry.getSchema(schemaName);
- };
- return projectData(schemaOrFactory, data, {...options, resolver});
- }
- }
|