|
@@ -21,9 +21,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
// src/index.js
|
|
// src/index.js
|
|
|
var index_exports = {};
|
|
var index_exports = {};
|
|
|
__export(index_exports, {
|
|
__export(index_exports, {
|
|
|
|
|
+ DataProjector: () => DataProjector,
|
|
|
|
|
+ ProjectionSchemaRegistry: () => ProjectionSchemaRegistry,
|
|
|
ProjectionScope: () => ProjectionScope,
|
|
ProjectionScope: () => ProjectionScope,
|
|
|
projectData: () => projectData,
|
|
projectData: () => projectData,
|
|
|
- validateProjectionSchema: () => validateProjectionSchema
|
|
|
|
|
|
|
+ validateProjectionSchema: () => validateProjectionSchema,
|
|
|
|
|
+ validateProjectionSchemaDefinition: () => validateProjectionSchemaDefinition
|
|
|
});
|
|
});
|
|
|
module.exports = __toCommonJS(index_exports);
|
|
module.exports = __toCommonJS(index_exports);
|
|
|
|
|
|
|
@@ -229,6 +232,148 @@ function _shouldSelect(propOptionsOrBoolean, strict, scope) {
|
|
|
}
|
|
}
|
|
|
__name(_shouldSelect, "_shouldSelect");
|
|
__name(_shouldSelect, "_shouldSelect");
|
|
|
|
|
|
|
|
|
|
+// src/data-projector.js
|
|
|
|
|
+var import_js_service2 = require("@e22m4u/js-service");
|
|
|
|
|
+
|
|
|
|
|
+// src/definitions/projection-schema-registry.js
|
|
|
|
|
+var import_js_service = require("@e22m4u/js-service");
|
|
|
|
|
+var import_js_format4 = require("@e22m4u/js-format");
|
|
|
|
|
+
|
|
|
|
|
+// src/definitions/validate-projection-schema-definition.js
|
|
|
|
|
+var import_js_format3 = require("@e22m4u/js-format");
|
|
|
|
|
+function validateProjectionSchemaDefinition(schemaDef) {
|
|
|
|
|
+ if (!schemaDef || typeof schemaDef !== "object" || Array.isArray(schemaDef)) {
|
|
|
|
|
+ throw new import_js_format3.InvalidArgumentError(
|
|
|
|
|
+ "Projection schema definition must be an Object, but %v was given.",
|
|
|
|
|
+ schemaDef
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!schemaDef.name || typeof schemaDef.name !== "string") {
|
|
|
|
|
+ throw new import_js_format3.InvalidArgumentError(
|
|
|
|
|
+ "Projection schema name must be a non-empty String, but %v was given.",
|
|
|
|
|
+ schemaDef.name
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!schemaDef.schema || typeof schemaDef.schema !== "object" || Array.isArray(schemaDef.schema)) {
|
|
|
|
|
+ throw new import_js_format3.InvalidArgumentError(
|
|
|
|
|
+ "Projection schema must be an Object, but %v was given.",
|
|
|
|
|
+ schemaDef.schema
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ validateProjectionSchema(schemaDef.schema);
|
|
|
|
|
+}
|
|
|
|
|
+__name(validateProjectionSchemaDefinition, "validateProjectionSchemaDefinition");
|
|
|
|
|
+
|
|
|
|
|
+// src/definitions/projection-schema-registry.js
|
|
|
|
|
+var _ProjectionSchemaRegistry = class _ProjectionSchemaRegistry extends import_js_service.Service {
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Schema map.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @type {Map<string, object>}
|
|
|
|
|
+ */
|
|
|
|
|
+ definitions = /* @__PURE__ */ new Map();
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Define schema.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param {object} schemaDef
|
|
|
|
|
+ * @returns {this}
|
|
|
|
|
+ */
|
|
|
|
|
+ defineSchema(schemaDef) {
|
|
|
|
|
+ validateProjectionSchemaDefinition(schemaDef);
|
|
|
|
|
+ if (this.definitions.has(schemaDef.name)) {
|
|
|
|
|
+ throw new import_js_format4.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 import_js_format4.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 import_js_format4.InvalidArgumentError(
|
|
|
|
|
+ "Projection definition %v is not found.",
|
|
|
|
|
+ schemaName
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ return schemaDef;
|
|
|
|
|
+ }
|
|
|
|
|
+};
|
|
|
|
|
+__name(_ProjectionSchemaRegistry, "ProjectionSchemaRegistry");
|
|
|
|
|
+var ProjectionSchemaRegistry = _ProjectionSchemaRegistry;
|
|
|
|
|
+
|
|
|
|
|
+// src/data-projector.js
|
|
|
|
|
+var _DataProjector = class _DataProjector extends import_js_service2.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 = /* @__PURE__ */ __name((schemaName) => {
|
|
|
|
|
+ return registry.getSchema(schemaName);
|
|
|
|
|
+ }, "resolver");
|
|
|
|
|
+ return projectData(schemaOrFactory, data, { ...options, resolver });
|
|
|
|
|
+ }
|
|
|
|
|
+};
|
|
|
|
|
+__name(_DataProjector, "DataProjector");
|
|
|
|
|
+var DataProjector = _DataProjector;
|
|
|
|
|
+
|
|
|
// src/projection-scope.js
|
|
// src/projection-scope.js
|
|
|
var ProjectionScope = {
|
|
var ProjectionScope = {
|
|
|
INPUT: "input",
|
|
INPUT: "input",
|
|
@@ -236,7 +381,10 @@ var ProjectionScope = {
|
|
|
};
|
|
};
|
|
|
// Annotate the CommonJS export names for ESM import in node:
|
|
// Annotate the CommonJS export names for ESM import in node:
|
|
|
0 && (module.exports = {
|
|
0 && (module.exports = {
|
|
|
|
|
+ DataProjector,
|
|
|
|
|
+ ProjectionSchemaRegistry,
|
|
|
ProjectionScope,
|
|
ProjectionScope,
|
|
|
projectData,
|
|
projectData,
|
|
|
- validateProjectionSchema
|
|
|
|
|
|
|
+ validateProjectionSchema,
|
|
|
|
|
+ validateProjectionSchemaDefinition
|
|
|
});
|
|
});
|