@twin.org/data-core 0.0.3-next.5 → 0.0.3-next.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -39,7 +39,7 @@ export class DataTypeHelper {
39
39
  * @param dataType The data type to get the schema for.
40
40
  * @returns The JSON schema for the data type or undefined if not found.
41
41
  */
42
- static getSchemaForType(dataType) {
42
+ static async getSchemaForType(dataType) {
43
43
  const handler = DataTypeHandlerFactory.getIfExists(dataType);
44
44
  return handler?.jsonSchema ? handler.jsonSchema() : undefined;
45
45
  }
@@ -1 +1 @@
1
- {"version":3,"file":"dataTypeHelper.js","sourceRoot":"","sources":["../../../src/utils/dataTypeHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,EAAE,EAA2B,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAEhF,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE7D;;GAEG;AACH,MAAM,OAAO,cAAc;IAC1B;;;;;;OAMG;IACI,MAAM,CAAC,YAAY,CACzB,SAAiB,EACjB,IAAY,EACZ,aAAiC,EACjC,MAA0C;QAE1C,sBAAsB,CAAC,QAAQ,CAAC,GAAG,SAAS,GAAG,IAAI,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;YAC7D,SAAS;YACT,aAAa;YACb,IAAI;YACJ,UAAU,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM;SAC9B,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,aAAa,CAC1B,SAAiB,EACjB,aAAiC,EACjC,cAGG;QAEH,KAAK,MAAM,OAAO,IAAI,cAAc,EAAE,CAAC;YACtC,cAAc,CAAC,YAAY,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,EAAE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ACH,OAAO,GAAG,KAAK,CAAC;YACjB,CAAC;QACF,CAAC;QAED,OAAO,OAAO,CAAC;IAChB,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Is, type IValidationFailure } from \"@twin.org/core\";\nimport { JsonSchemaHelper } from \"./jsonSchemaHelper.js\";\nimport { DataTypeHandlerFactory } from \"../factories/dataTypeHandlerFactory.js\";\nimport type { IJsonSchema } from \"../models/IJsonSchema.js\";\nimport { ValidationMode } from \"../models/validationMode.js\";\n\n/**\n * Class to help with data types.\n */\nexport class DataTypeHelper {\n\t/**\n\t * Register a data type.\n\t * @param namespace The namespace for the type.\n\t * @param type The type for the item.\n\t * @param jsonLdContext The JSON LD context for the type.\n\t * @param schema The JSON schema for the type.\n\t */\n\tpublic static registerType(\n\t\tnamespace: string,\n\t\ttype: string,\n\t\tjsonLdContext: string | undefined,\n\t\tschema: IJsonSchema | Promise<IJsonSchema>\n\t): void {\n\t\tDataTypeHandlerFactory.register(`${namespace}${type}`, () => ({\n\t\t\tnamespace,\n\t\t\tjsonLdContext,\n\t\t\ttype,\n\t\t\tjsonSchema: async () => schema\n\t\t}));\n\t}\n\n\t/**\n\t * Register a list of types.\n\t * @param namespace The namespace for the types.\n\t * @param jsonLdContext The JSON LD context for the types.\n\t * @param typeDefinition The type definitions to register.\n\t */\n\tpublic static registerTypes(\n\t\tnamespace: string,\n\t\tjsonLdContext: string | undefined,\n\t\ttypeDefinition: {\n\t\t\ttype: string;\n\t\t\tschema: IJsonSchema | Promise<IJsonSchema>;\n\t\t}[]\n\t): void {\n\t\tfor (const typeDef of typeDefinition) {\n\t\t\tDataTypeHelper.registerType(namespace, typeDef.type, jsonLdContext, typeDef.schema);\n\t\t}\n\t}\n\n\t/**\n\t * Get the JSON schema for a data type.\n\t * @param dataType The data type to get the schema for.\n\t * @returns The JSON schema for the data type or undefined if not found.\n\t */\n\tpublic static getSchemaForType(dataType: string): IJsonSchema | undefined {\n\t\tconst handler = DataTypeHandlerFactory.getIfExists(dataType);\n\t\treturn handler?.jsonSchema ? handler.jsonSchema() : undefined;\n\t}\n\n\t/**\n\t * Validate a data type.\n\t * @param propertyName The name of the property being validated to use in error messages.\n\t * @param dataType The data type to validate.\n\t * @param data The data to validate.\n\t * @param validationFailures The list of validation failures to add to.\n\t * @param options Optional options for validation.\n\t * @param options.failOnMissingType If true, will fail validation if the data type is missing, defaults to false.\n\t * @param options.validationMode The validation mode to use, defaults to either.\n\t * @returns True if the data was valid.\n\t */\n\tpublic static async validate(\n\t\tpropertyName: string,\n\t\tdataType: string | undefined,\n\t\tdata: unknown,\n\t\tvalidationFailures: IValidationFailure[],\n\t\toptions?: {\n\t\t\tvalidationMode?: ValidationMode;\n\t\t\tfailOnMissingType?: boolean;\n\t\t}\n\t): Promise<boolean> {\n\t\tlet isValid = true;\n\n\t\tif (Is.stringValue(dataType)) {\n\t\t\tconst handler = DataTypeHandlerFactory.getIfExists(dataType);\n\n\t\t\tif (handler) {\n\t\t\t\tconst validationMode = options?.validationMode ?? ValidationMode.Either;\n\n\t\t\t\t// If we have a validate function use that as it is more specific\n\t\t\t\t// and will produce better error messages\n\t\t\t\tlet hasValidated = false;\n\t\t\t\tconst validateMethod = handler.validate?.bind(handler);\n\t\t\t\tif (\n\t\t\t\t\t(validationMode === ValidationMode.Validate ||\n\t\t\t\t\t\tvalidationMode === ValidationMode.Both ||\n\t\t\t\t\t\tvalidationMode === ValidationMode.Either) &&\n\t\t\t\t\tIs.function(validateMethod)\n\t\t\t\t) {\n\t\t\t\t\tisValid = await validateMethod(propertyName, data, validationFailures);\n\t\t\t\t\thasValidated = true;\n\t\t\t\t}\n\n\t\t\t\tconst jsonSchemaMethod = handler.jsonSchema?.bind(handler);\n\t\t\t\tif (\n\t\t\t\t\t(validationMode === ValidationMode.JsonSchema ||\n\t\t\t\t\t\t(validationMode === ValidationMode.Either && !hasValidated) ||\n\t\t\t\t\t\tvalidationMode === ValidationMode.Both) &&\n\t\t\t\t\tIs.function(jsonSchemaMethod)\n\t\t\t\t) {\n\t\t\t\t\t// Otherwise use the JSON schema if there is one\n\t\t\t\t\tconst schema = await jsonSchemaMethod();\n\n\t\t\t\t\tif (Is.object<IJsonSchema>(schema)) {\n\t\t\t\t\t\tconst validationResult = await JsonSchemaHelper.validate(schema, data);\n\t\t\t\t\t\tif (Is.arrayValue(validationResult.error)) {\n\t\t\t\t\t\t\tvalidationFailures.push({\n\t\t\t\t\t\t\t\tproperty: propertyName,\n\t\t\t\t\t\t\t\treason: \"validation.schema.failedValidation\",\n\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\tvalue: data,\n\t\t\t\t\t\t\t\t\tschemaErrors: validationResult.error,\n\t\t\t\t\t\t\t\t\tmessage: validationResult.error.map(e => e.message).join(\"\\n\")\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (!validationResult.result) {\n\t\t\t\t\t\t\tisValid = false;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if (options?.failOnMissingType ?? false) {\n\t\t\t\t// If we don't have a handler for a specific type and we are failing on missing type\n\t\t\t\tvalidationFailures.push({\n\t\t\t\t\tproperty: propertyName,\n\t\t\t\t\treason: \"validation.schema.missingType\",\n\t\t\t\t\tproperties: {\n\t\t\t\t\t\tdataType\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tisValid = false;\n\t\t\t}\n\t\t}\n\n\t\treturn isValid;\n\t}\n}\n"]}
1
+ {"version":3,"file":"dataTypeHelper.js","sourceRoot":"","sources":["../../../src/utils/dataTypeHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,EAAE,EAA2B,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM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AoC;gCAC5C,UAAU,EAAE;oCACX,KAAK,EAAE,IAAI;oCACX,YAAY,EAAE,gBAAgB,CAAC,KAAK;oCACpC,OAAO,EAAE,gBAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;iCAC9D;6BACD,CAAC,CAAC;wBACJ,CAAC;wBACD,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,CAAC;4BAC9B,OAAO,GAAG,KAAK,CAAC;wBACjB,CAAC;oBACF,CAAC;gBACF,CAAC;YACF,CAAC;iBAAM,IAAI,OAAO,EAAE,iBAAiB,IAAI,KAAK,EAAE,CAAC;gBAChD,oFAAoF;gBACpF,kBAAkB,CAAC,IAAI,CAAC;oBACvB,QAAQ,EAAE,YAAY;oBACtB,MAAM,EAAE,+BAA+B;oBACvC,UAAU,EAAE;wBACX,QAAQ;qBACR;iBACD,CAAC,CAAC;gBACH,OAAO,GAAG,KAAK,CAAC;YACjB,CAAC;QACF,CAAC;QAED,OAAO,OAAO,CAAC;IAChB,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Is, type IValidationFailure } from \"@twin.org/core\";\nimport { JsonSchemaHelper } from \"./jsonSchemaHelper.js\";\nimport { DataTypeHandlerFactory } from \"../factories/dataTypeHandlerFactory.js\";\nimport type { IJsonSchema } from \"../models/IJsonSchema.js\";\nimport { ValidationMode } from \"../models/validationMode.js\";\n\n/**\n * Class to help with data types.\n */\nexport class DataTypeHelper {\n\t/**\n\t * Register a data type.\n\t * @param namespace The namespace for the type.\n\t * @param type The type for the item.\n\t * @param jsonLdContext The JSON LD context for the type.\n\t * @param schema The JSON schema for the type.\n\t */\n\tpublic static registerType(\n\t\tnamespace: string,\n\t\ttype: string,\n\t\tjsonLdContext: string | undefined,\n\t\tschema: IJsonSchema | Promise<IJsonSchema>\n\t): void {\n\t\tDataTypeHandlerFactory.register(`${namespace}${type}`, () => ({\n\t\t\tnamespace,\n\t\t\tjsonLdContext,\n\t\t\ttype,\n\t\t\tjsonSchema: async () => schema\n\t\t}));\n\t}\n\n\t/**\n\t * Register a list of types.\n\t * @param namespace The namespace for the types.\n\t * @param jsonLdContext The JSON LD context for the types.\n\t * @param typeDefinition The type definitions to register.\n\t */\n\tpublic static registerTypes(\n\t\tnamespace: string,\n\t\tjsonLdContext: string | undefined,\n\t\ttypeDefinition: {\n\t\t\ttype: string;\n\t\t\tschema: IJsonSchema | Promise<IJsonSchema>;\n\t\t}[]\n\t): void {\n\t\tfor (const typeDef of typeDefinition) {\n\t\t\tDataTypeHelper.registerType(namespace, typeDef.type, jsonLdContext, typeDef.schema);\n\t\t}\n\t}\n\n\t/**\n\t * Get the JSON schema for a data type.\n\t * @param dataType The data type to get the schema for.\n\t * @returns The JSON schema for the data type or undefined if not found.\n\t */\n\tpublic static async getSchemaForType(dataType: string): Promise<IJsonSchema | undefined> {\n\t\tconst handler = DataTypeHandlerFactory.getIfExists(dataType);\n\t\treturn handler?.jsonSchema ? handler.jsonSchema() : undefined;\n\t}\n\n\t/**\n\t * Validate a data type.\n\t * @param propertyName The name of the property being validated to use in error messages.\n\t * @param dataType The data type to validate.\n\t * @param data The data to validate.\n\t * @param validationFailures The list of validation failures to add to.\n\t * @param options Optional options for validation.\n\t * @param options.failOnMissingType If true, will fail validation if the data type is missing, defaults to false.\n\t * @param options.validationMode The validation mode to use, defaults to either.\n\t * @returns True if the data was valid.\n\t */\n\tpublic static async validate(\n\t\tpropertyName: string,\n\t\tdataType: string | undefined,\n\t\tdata: unknown,\n\t\tvalidationFailures: IValidationFailure[],\n\t\toptions?: {\n\t\t\tvalidationMode?: ValidationMode;\n\t\t\tfailOnMissingType?: boolean;\n\t\t}\n\t): Promise<boolean> {\n\t\tlet isValid = true;\n\n\t\tif (Is.stringValue(dataType)) {\n\t\t\tconst handler = DataTypeHandlerFactory.getIfExists(dataType);\n\n\t\t\tif (handler) {\n\t\t\t\tconst validationMode = options?.validationMode ?? ValidationMode.Either;\n\n\t\t\t\t// If we have a validate function use that as it is more specific\n\t\t\t\t// and will produce better error messages\n\t\t\t\tlet hasValidated = false;\n\t\t\t\tconst validateMethod = handler.validate?.bind(handler);\n\t\t\t\tif (\n\t\t\t\t\t(validationMode === ValidationMode.Validate ||\n\t\t\t\t\t\tvalidationMode === ValidationMode.Both ||\n\t\t\t\t\t\tvalidationMode === ValidationMode.Either) &&\n\t\t\t\t\tIs.function(validateMethod)\n\t\t\t\t) {\n\t\t\t\t\tisValid = await validateMethod(propertyName, data, validationFailures);\n\t\t\t\t\thasValidated = true;\n\t\t\t\t}\n\n\t\t\t\tconst jsonSchemaMethod = handler.jsonSchema?.bind(handler);\n\t\t\t\tif (\n\t\t\t\t\t(validationMode === ValidationMode.JsonSchema ||\n\t\t\t\t\t\t(validationMode === ValidationMode.Either && !hasValidated) ||\n\t\t\t\t\t\tvalidationMode === ValidationMode.Both) &&\n\t\t\t\t\tIs.function(jsonSchemaMethod)\n\t\t\t\t) {\n\t\t\t\t\t// Otherwise use the JSON schema if there is one\n\t\t\t\t\tconst schema = await jsonSchemaMethod();\n\n\t\t\t\t\tif (Is.object<IJsonSchema>(schema)) {\n\t\t\t\t\t\tconst validationResult = await JsonSchemaHelper.validate(schema, data);\n\t\t\t\t\t\tif (Is.arrayValue(validationResult.error)) {\n\t\t\t\t\t\t\tvalidationFailures.push({\n\t\t\t\t\t\t\t\tproperty: propertyName,\n\t\t\t\t\t\t\t\treason: \"validation.schema.failedValidation\",\n\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\tvalue: data,\n\t\t\t\t\t\t\t\t\tschemaErrors: validationResult.error,\n\t\t\t\t\t\t\t\t\tmessage: validationResult.error.map(e => e.message).join(\"\\n\")\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (!validationResult.result) {\n\t\t\t\t\t\t\tisValid = false;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if (options?.failOnMissingType ?? false) {\n\t\t\t\t// If we don't have a handler for a specific type and we are failing on missing type\n\t\t\t\tvalidationFailures.push({\n\t\t\t\t\tproperty: propertyName,\n\t\t\t\t\treason: \"validation.schema.missingType\",\n\t\t\t\t\tproperties: {\n\t\t\t\t\t\tdataType\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tisValid = false;\n\t\t\t}\n\t\t}\n\n\t\treturn isValid;\n\t}\n}\n"]}
@@ -28,7 +28,7 @@ export declare class DataTypeHelper {
28
28
  * @param dataType The data type to get the schema for.
29
29
  * @returns The JSON schema for the data type or undefined if not found.
30
30
  */
31
- static getSchemaForType(dataType: string): IJsonSchema | undefined;
31
+ static getSchemaForType(dataType: string): Promise<IJsonSchema | undefined>;
32
32
  /**
33
33
  * Validate a data type.
34
34
  * @param propertyName The name of the property being validated to use in error messages.
package/docs/changelog.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @twin.org/data-core - Changelog
2
2
 
3
+ ## [0.0.3-next.6](https://github.com/twinfoundation/data/compare/data-core-v0.0.3-next.5...data-core-v0.0.3-next.6) (2026-01-14)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * getSchemaForType async ([a26a4f0](https://github.com/twinfoundation/data/commit/a26a4f09d6e22ee0882597b71a134db3079d72d0))
9
+
3
10
  ## [0.0.3-next.5](https://github.com/twinfoundation/data/compare/data-core-v0.0.3-next.4...data-core-v0.0.3-next.5) (2026-01-14)
4
11
 
5
12
 
@@ -86,7 +86,7 @@ The type definitions to register.
86
86
 
87
87
  ### getSchemaForType()
88
88
 
89
- > `static` **getSchemaForType**(`dataType`): `SchemaObject` \| `undefined`
89
+ > `static` **getSchemaForType**(`dataType`): `Promise`\<`SchemaObject` \| `undefined`\>
90
90
 
91
91
  Get the JSON schema for a data type.
92
92
 
@@ -100,7 +100,7 @@ The data type to get the schema for.
100
100
 
101
101
  #### Returns
102
102
 
103
- `SchemaObject` \| `undefined`
103
+ `Promise`\<`SchemaObject` \| `undefined`\>
104
104
 
105
105
  The JSON schema for the data type or undefined if not found.
106
106
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/data-core",
3
- "version": "0.0.3-next.5",
3
+ "version": "0.0.3-next.6",
4
4
  "description": "Definitions and helpers for using with data and schemas",
5
5
  "repository": {
6
6
  "type": "git",