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