| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import {Service} from '@e22m4u/js-service';
- import {InvalidArgumentError} from '@e22m4u/js-format';
- import {validateProjectionSchemaDefinition} from './validate-projection-schema-definition.js';
- /**
- * Projection schema registry.
- */
- export class ProjectionSchemaRegistry extends Service {
- /**
- * Definitions.
- */
- _definitions = new Map();
- /**
- * Define schema.
- *
- * @param {object} schemaDef
- * @returns {this}
- */
- defineSchema(schemaDef) {
- validateProjectionSchemaDefinition(schemaDef);
- if (this._definitions.has(schemaDef.name)) {
- throw new InvalidArgumentError(
- 'Projection schema %v is already registered.',
- schemaDef.name,
- );
- }
- this._definitions.set(schemaDef.name, schemaDef);
- return this;
- }
- /**
- * Has schema.
- *
- * @param {string} schemaName
- * @returns {boolean}
- */
- hasSchema(schemaName) {
- return this._definitions.has(schemaName);
- }
- /**
- * Get schema.
- *
- * @param {string} schemaName
- * @returns {object}
- */
- getSchema(schemaName) {
- const schemaDef = this._definitions.get(schemaName);
- if (!schemaDef) {
- throw new InvalidArgumentError(
- 'Projection schema %v is not found.',
- schemaName,
- );
- }
- return schemaDef.schema;
- }
- /**
- * Get definition.
- *
- * @param {string} schemaName
- * @returns {object}
- */
- getDefinition(schemaName) {
- const schemaDef = this._definitions.get(schemaName);
- if (!schemaDef) {
- throw new InvalidArgumentError(
- 'Schema definition %v is not found.',
- schemaName,
- );
- }
- return schemaDef;
- }
- }
|