@twin.org/standards-dataspace-protocol 0.0.3-next.53 → 0.0.3-next.54

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.
@@ -18,41 +18,39 @@ export class DataspaceProtocolHelper {
18
18
  /**
19
19
  * Checks whether the object passed as parameter is conformant to the DS Protocol definitions.
20
20
  * @param object The object to check
21
- * @param validationFailures the Validation failures obtained during the conformance checking.
22
- * @returns true or false depending whether the object is conformant or not
21
+ * @returns An array of validation failures, empty if the object is conformant
23
22
  */
24
- static async checkConformance(object, validationFailures) {
25
- let result = false;
23
+ static async validate(object) {
26
24
  const dcatNamespace = DcatContexts.Namespace;
25
+ const validationFailures = [];
27
26
  const objectTypes = await JsonLdHelper.getType(object);
28
- for (const type of objectTypes) {
29
- let dataTypeIdentifier = type;
30
- // If the DCAT3 types are used, convert to the DS Protocol equivalent
31
- // which have the enhancements and constraints defined by the DS Protocol
32
- if (type.startsWith(dcatNamespace)) {
33
- const nonQualifiedType = type.replace(dcatNamespace, "");
34
- dataTypeIdentifier = `${DataspaceProtocolContexts.Namespace}${nonQualifiedType}`;
35
- }
36
- const schema = await DataTypeHelper.getSchemaForType(dataTypeIdentifier);
37
- if (!schema) {
38
- throw new GeneralError(DataspaceProtocolHelper.CLASS_NAME, "schemaNotRegistered", {
39
- schemaId: dataTypeIdentifier
40
- });
41
- }
42
- const normalizedObject = await DataspaceProtocolHelper.normalize(object);
43
- const validationResult = await JsonSchemaHelper.validate(schema, normalizedObject);
44
- result = validationResult.result;
45
- if (!result && Is.array(validationResult.error)) {
46
- for (const aError of validationResult.error) {
47
- const validationFailure = {
48
- property: aError.instancePath,
49
- reason: aError.message
50
- };
51
- validationFailures.push(validationFailure);
27
+ if (objectTypes.length === 0) {
28
+ validationFailures.push({
29
+ property: "@type",
30
+ reason: "validation.missingType"
31
+ });
32
+ }
33
+ else {
34
+ for (const type of objectTypes) {
35
+ let dataTypeIdentifier = type;
36
+ // If the DCAT3 types are used, convert to the DS Protocol equivalent
37
+ // which have the enhancements and constraints defined by the DS Protocol
38
+ if (type.startsWith(dcatNamespace)) {
39
+ const nonQualifiedType = type.replace(dcatNamespace, "");
40
+ dataTypeIdentifier = `${DataspaceProtocolContexts.Namespace}${nonQualifiedType}`;
52
41
  }
42
+ const schema = await DataTypeHelper.getSchemaForType(dataTypeIdentifier);
43
+ if (!schema) {
44
+ throw new GeneralError(DataspaceProtocolHelper.CLASS_NAME, "schemaNotRegistered", {
45
+ schemaId: dataTypeIdentifier
46
+ });
47
+ }
48
+ const normalizedObject = await DataspaceProtocolHelper.normalize(object);
49
+ const validationResult = await JsonSchemaHelper.validate(schema, normalizedObject);
50
+ validationFailures.push(...validationResult);
53
51
  }
54
52
  }
55
- return result;
53
+ return validationFailures;
56
54
  }
57
55
  /**
58
56
  * Normalizes the input object making it compliant with the DS Protocol specifications.
@@ -1 +1 @@
1
- {"version":3,"file":"dataspaceProtocolHelper.js","sourceRoot":"","sources":["../../../src/utils/dataspaceProtocolHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AAEvC,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE,YAAY,EAA2B,MAAM,gBAAgB,CAAC;AACzF,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EACN,YAAY,EACZ,eAAe,EAGf,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,yBAAyB,EAAE,MAAM,wCAAwC,CAAC;AACnF,OAAO,EAAE,qCAAqC,EAAE,MAAM,oEAAoE,CAAC;AAE3H;;GAEG;AACH,MAAM,OAAgB,uBAAuB;IAC5C;;;OAGG;IACI,MAAM,CAAU,UAAU,6BAAqC;IAEtE;;;;;OAKG;IACI,MAAM,CAAC,KAAK,CAAC,gBAAgB,CACnC,MAAyB,EACzB,kBAAwC;QAExC,IAAI,MAAM,G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AAK,EAAE,gBAAgB;gBACvB,OAAO,EAAE,QAAQ;aACjB;SACD,CAAC;QACF,MAAM,SAAS,GAAG,YAAY,CAAC,WAAW,CAA+B,MAAM,EAAE,UAAU,CAAC,CAAC;QAC7F,IAAI,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;YACzB,SAAS,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QAClC,CAAC;aAAM,IAAI,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;YACjC,YAAY,CAAC,WAAW,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE,GAAG,SAAS,EAAE,GAAG,gBAAgB,EAAE,CAAC,CAAC;QACrF,CAAC;aAAM,IAAI,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;YACjC,YAAY,CAAC,WAAW,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC,CAAC;QAC7E,CAAC;QAED,OAAO,MAAM,CAAC;IACf,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\nimport { GeneralError, Is, ObjectHelper, type IValidationFailure } from \"@twin.org/core\";\nimport { DataTypeHelper, JsonSchemaHelper } from \"@twin.org/data-core\";\nimport {\n\tJsonLdHelper,\n\tJsonLdProcessor,\n\ttype IJsonLdContextDefinitionRoot,\n\ttype IJsonLdNodeObject\n} from \"@twin.org/data-json-ld\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { DcatContexts } from \"@twin.org/standards-w3c-dcat\";\nimport { DataspaceProtocolContexts } from \"../models/dataspaceProtocolContexts.js\";\nimport { DataspaceProtocolTransferProcessTypes } from \"../models/transferProcess/dataspaceProtocolTransferProcessTypes.js\";\n\n/**\n * Dataspace protocol helper.\n */\nexport abstract class DataspaceProtocolHelper {\n\t/**\n\t * The class name.\n\t * @internal\n\t */\n\tpublic static readonly CLASS_NAME = nameof<DataspaceProtocolHelper>();\n\n\t/**\n\t * Checks whether the object passed as parameter is conformant to the DS Protocol definitions.\n\t * @param object The object to check\n\t * @param validationFailures the Validation failures obtained during the conformance checking.\n\t * @returns true or false depending whether the object is conformant or not\n\t */\n\tpublic static async checkConformance(\n\t\tobject: IJsonLdNodeObject,\n\t\tvalidationFailures: IValidationFailure[]\n\t): Promise<boolean> {\n\t\tlet result = false;\n\n\t\tconst dcatNamespace = DcatContexts.Namespace;\n\n\t\tconst objectTypes = await JsonLdHelper.getType(object);\n\n\t\tfor (const type of objectTypes) {\n\t\t\tlet dataTypeIdentifier = type;\n\n\t\t\t// If the DCAT3 types are used, convert to the DS Protocol equivalent\n\t\t\t// which have the enhancements and constraints defined by the DS Protocol\n\t\t\tif (type.startsWith(dcatNamespace)) {\n\t\t\t\tconst nonQualifiedType = type.replace(dcatNamespace, \"\");\n\t\t\t\tdataTypeIdentifier = `${DataspaceProtocolContexts.Namespace}${nonQualifiedType}`;\n\t\t\t}\n\n\t\t\tconst schema = await DataTypeHelper.getSchemaForType(dataTypeIdentifier);\n\t\t\tif (!schema) {\n\t\t\t\tthrow new GeneralError(DataspaceProtocolHelper.CLASS_NAME, \"schemaNotRegistered\", {\n\t\t\t\t\tschemaId: dataTypeIdentifier\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst normalizedObject = await DataspaceProtocolHelper.normalize(object);\n\n\t\t\tconst validationResult = await JsonSchemaHelper.validate(schema, normalizedObject);\n\t\t\tresult = validationResult.result;\n\n\t\t\tif (!result && Is.array(validationResult.error)) {\n\t\t\t\tfor (const aError of validationResult.error) {\n\t\t\t\t\tconst validationFailure: IValidationFailure = {\n\t\t\t\t\t\tproperty: aError.instancePath,\n\t\t\t\t\t\treason: aError.message as string\n\t\t\t\t\t};\n\t\t\t\t\tvalidationFailures.push(validationFailure);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * Normalizes the input object making it compliant with the DS Protocol specifications.\n\t * @param object The input object.\n\t * @returns The input object normalized.\n\t */\n\tpublic static async normalize(object: IJsonLdNodeObject): Promise<IJsonLdNodeObject> {\n\t\tconst annotatedObject = DataspaceProtocolHelper.annotateLDContextForFormat(object);\n\n\t\t// Determine if this is a message/transfer type (which expects Context) or a catalog type (which expects JsonLdContext)\n\t\tconst objectType = ObjectHelper.propertyGet<string | string[]>(object, \"@type\");\n\t\tconst isTransferProcessType =\n\t\t\tIs.string(objectType) &&\n\t\t\t(objectType.includes(\"Message\") ||\n\t\t\t\tobjectType === DataspaceProtocolTransferProcessTypes.TransferProcess ||\n\t\t\t\tobjectType === DataspaceProtocolTransferProcessTypes.TransferError);\n\n\t\tconst contextToUse = isTransferProcessType\n\t\t\t? DataspaceProtocolContexts.Context\n\t\t\t: DataspaceProtocolContexts.JsonLdContext;\n\n\t\tconst compactedObject = await JsonLdProcessor.compact(annotatedObject, [contextToUse]);\n\n\t\tif (!Is.array(compactedObject[\"@context\"])) {\n\t\t\tObjectHelper.propertySet(compactedObject, \"@context\", [\n\t\t\t\tObjectHelper.propertyGet(compactedObject, \"@context\")\n\t\t\t]);\n\t\t}\n\n\t\treturn compactedObject;\n\t}\n\n\t/**\n\t * Ensures format property has a proper LD Context.\n\t * @param object The object.\n\t * @returns a copy of the object annotated with the proper LD Context.\n\t * @internal\n\t */\n\tprivate static annotateLDContextForFormat(object: IJsonLdNodeObject): IJsonLdNodeObject {\n\t\tconst result = ObjectHelper.clone<IJsonLdNodeObject>(object);\n\n\t\t// This step is needed before compaction as 'dcterms:format' is not defined originally as '@vocab'\n\t\t// but it is in the DSP LD Context\n\t\tconst EXTRA_ANNOTATION = {\n\t\t\t\"dcterms:format\": {\n\t\t\t\t\"@id\": \"dcterms:format\",\n\t\t\t\t\"@type\": \"@vocab\"\n\t\t\t}\n\t\t};\n\t\tconst ldContext = ObjectHelper.propertyGet<IJsonLdContextDefinitionRoot>(result, \"@context\");\n\t\tif (Is.array(ldContext)) {\n\t\t\tldContext.push(EXTRA_ANNOTATION);\n\t\t} else if (Is.object(ldContext)) {\n\t\t\tObjectHelper.propertySet(result, \"@context\", { ...ldContext, ...EXTRA_ANNOTATION });\n\t\t} else if (Is.string(ldContext)) {\n\t\t\tObjectHelper.propertySet(result, \"@context\", [ldContext, EXTRA_ANNOTATION]);\n\t\t}\n\n\t\treturn result;\n\t}\n}\n"]}
1
+ {"version":3,"file":"dataspaceProtocolHelper.js","sourceRoot":"","sources":["../../../src/utils/dataspaceProtocolHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AAEvC,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE,YAAY,EAA2B,MAAM,gBAAgB,CAAC;AACzF,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EACN,YAAY,EACZ,eAAe,EAGf,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,yBAAyB,EAAE,MAAM,wCAAwC,CAAC;AACnF,OAAO,EAAE,qCAAqC,EAAE,MAAM,oEAAoE,CAAC;AAE3H;;GAEG;AACH,MAAM,OAAgB,uBAAuB;IAC5C;;;OAGG;IACI,MAAM,CAAU,UAAU,6BAAqC;IAEtE;;;;OAIG;IACI,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAyB;QACrD,MAAM,aAAa,GAAG,YAAY,CAAC,SAAS,CAAC;QAC7C,MAAM,kBAAkB,GAAyB,EAAE,CAAC;QAEpD,MAAM,WAAW,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACvD,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC9B,kBAAkB,CAAC,IAAI,CAAC;gBACvB,QAAQ,EAAE,OAAO;gBACjB,MAAM,EAAE,wBAAwB;aAChC,CAAC,CAAC;QACJ,CAAC;aAAM,CAAC;YACP,KAAK,MAAM,IAAI,IAA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C,SAAS,CAAC,EAAE,CAAC;YACjC,YAAY,CAAC,WAAW,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC,CAAC;QAC7E,CAAC;QAED,OAAO,MAAM,CAAC;IACf,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\nimport { GeneralError, Is, ObjectHelper, type IValidationFailure } from \"@twin.org/core\";\nimport { DataTypeHelper, JsonSchemaHelper } from \"@twin.org/data-core\";\nimport {\n\tJsonLdHelper,\n\tJsonLdProcessor,\n\ttype IJsonLdContextDefinitionRoot,\n\ttype IJsonLdNodeObject\n} from \"@twin.org/data-json-ld\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { DcatContexts } from \"@twin.org/standards-w3c-dcat\";\nimport { DataspaceProtocolContexts } from \"../models/dataspaceProtocolContexts.js\";\nimport { DataspaceProtocolTransferProcessTypes } from \"../models/transferProcess/dataspaceProtocolTransferProcessTypes.js\";\n\n/**\n * Dataspace protocol helper.\n */\nexport abstract class DataspaceProtocolHelper {\n\t/**\n\t * The class name.\n\t * @internal\n\t */\n\tpublic static readonly CLASS_NAME = nameof<DataspaceProtocolHelper>();\n\n\t/**\n\t * Checks whether the object passed as parameter is conformant to the DS Protocol definitions.\n\t * @param object The object to check\n\t * @returns An array of validation failures, empty if the object is conformant\n\t */\n\tpublic static async validate(object: IJsonLdNodeObject): Promise<IValidationFailure[]> {\n\t\tconst dcatNamespace = DcatContexts.Namespace;\n\t\tconst validationFailures: IValidationFailure[] = [];\n\n\t\tconst objectTypes = await JsonLdHelper.getType(object);\n\t\tif (objectTypes.length === 0) {\n\t\t\tvalidationFailures.push({\n\t\t\t\tproperty: \"@type\",\n\t\t\t\treason: \"validation.missingType\"\n\t\t\t});\n\t\t} else {\n\t\t\tfor (const type of objectTypes) {\n\t\t\t\tlet dataTypeIdentifier = type;\n\n\t\t\t\t// If the DCAT3 types are used, convert to the DS Protocol equivalent\n\t\t\t\t// which have the enhancements and constraints defined by the DS Protocol\n\t\t\t\tif (type.startsWith(dcatNamespace)) {\n\t\t\t\t\tconst nonQualifiedType = type.replace(dcatNamespace, \"\");\n\t\t\t\t\tdataTypeIdentifier = `${DataspaceProtocolContexts.Namespace}${nonQualifiedType}`;\n\t\t\t\t}\n\n\t\t\t\tconst schema = await DataTypeHelper.getSchemaForType(dataTypeIdentifier);\n\t\t\t\tif (!schema) {\n\t\t\t\t\tthrow new GeneralError(DataspaceProtocolHelper.CLASS_NAME, \"schemaNotRegistered\", {\n\t\t\t\t\t\tschemaId: dataTypeIdentifier\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tconst normalizedObject = await DataspaceProtocolHelper.normalize(object);\n\n\t\t\t\tconst validationResult = await JsonSchemaHelper.validate(schema, normalizedObject);\n\t\t\t\tvalidationFailures.push(...validationResult);\n\t\t\t}\n\t\t}\n\n\t\treturn validationFailures;\n\t}\n\n\t/**\n\t * Normalizes the input object making it compliant with the DS Protocol specifications.\n\t * @param object The input object.\n\t * @returns The input object normalized.\n\t */\n\tpublic static async normalize(object: IJsonLdNodeObject): Promise<IJsonLdNodeObject> {\n\t\tconst annotatedObject = DataspaceProtocolHelper.annotateLDContextForFormat(object);\n\n\t\t// Determine if this is a message/transfer type (which expects Context) or a catalog type (which expects JsonLdContext)\n\t\tconst objectType = ObjectHelper.propertyGet<string | string[]>(object, \"@type\");\n\t\tconst isTransferProcessType =\n\t\t\tIs.string(objectType) &&\n\t\t\t(objectType.includes(\"Message\") ||\n\t\t\t\tobjectType === DataspaceProtocolTransferProcessTypes.TransferProcess ||\n\t\t\t\tobjectType === DataspaceProtocolTransferProcessTypes.TransferError);\n\n\t\tconst contextToUse = isTransferProcessType\n\t\t\t? DataspaceProtocolContexts.Context\n\t\t\t: DataspaceProtocolContexts.JsonLdContext;\n\n\t\tconst compactedObject = await JsonLdProcessor.compact(annotatedObject, [contextToUse]);\n\n\t\tif (!Is.array(compactedObject[\"@context\"])) {\n\t\t\tObjectHelper.propertySet(compactedObject, \"@context\", [\n\t\t\t\tObjectHelper.propertyGet(compactedObject, \"@context\")\n\t\t\t]);\n\t\t}\n\n\t\treturn compactedObject;\n\t}\n\n\t/**\n\t * Ensures format property has a proper LD Context.\n\t * @param object The object.\n\t * @returns a copy of the object annotated with the proper LD Context.\n\t * @internal\n\t */\n\tprivate static annotateLDContextForFormat(object: IJsonLdNodeObject): IJsonLdNodeObject {\n\t\tconst result = ObjectHelper.clone<IJsonLdNodeObject>(object);\n\n\t\t// This step is needed before compaction as 'dcterms:format' is not defined originally as '@vocab'\n\t\t// but it is in the DSP LD Context\n\t\tconst EXTRA_ANNOTATION = {\n\t\t\t\"dcterms:format\": {\n\t\t\t\t\"@id\": \"dcterms:format\",\n\t\t\t\t\"@type\": \"@vocab\"\n\t\t\t}\n\t\t};\n\t\tconst ldContext = ObjectHelper.propertyGet<IJsonLdContextDefinitionRoot>(result, \"@context\");\n\t\tif (Is.array(ldContext)) {\n\t\t\tldContext.push(EXTRA_ANNOTATION);\n\t\t} else if (Is.object(ldContext)) {\n\t\t\tObjectHelper.propertySet(result, \"@context\", { ...ldContext, ...EXTRA_ANNOTATION });\n\t\t} else if (Is.string(ldContext)) {\n\t\t\tObjectHelper.propertySet(result, \"@context\", [ldContext, EXTRA_ANNOTATION]);\n\t\t}\n\n\t\treturn result;\n\t}\n}\n"]}
@@ -7,10 +7,9 @@ export declare abstract class DataspaceProtocolHelper {
7
7
  /**
8
8
  * Checks whether the object passed as parameter is conformant to the DS Protocol definitions.
9
9
  * @param object The object to check
10
- * @param validationFailures the Validation failures obtained during the conformance checking.
11
- * @returns true or false depending whether the object is conformant or not
10
+ * @returns An array of validation failures, empty if the object is conformant
12
11
  */
13
- static checkConformance(object: IJsonLdNodeObject, validationFailures: IValidationFailure[]): Promise<boolean>;
12
+ static validate(object: IJsonLdNodeObject): Promise<IValidationFailure[]>;
14
13
  /**
15
14
  * Normalizes the input object making it compliant with the DS Protocol specifications.
16
15
  * @param object The input object.
package/docs/changelog.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.0.3-next.54](https://github.com/twinfoundation/standards/compare/standards-dataspace-protocol-v0.0.3-next.53...standards-dataspace-protocol-v0.0.3-next.54) (2026-03-12)
4
+
5
+
6
+ ### Features
7
+
8
+ * update JsonSchemaHelper.validate usage ([fe08315](https://github.com/twinfoundation/standards/commit/fe0831571cc618465a4510b52c3032a750e6e149))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/standards-w3c-dcat bumped from 0.0.3-next.53 to 0.0.3-next.54
16
+ * @twin.org/standards-w3c-odrl bumped from 0.0.3-next.53 to 0.0.3-next.54
17
+ * devDependencies
18
+ * @twin.org/standards-ld-contexts bumped from 0.0.3-next.53 to 0.0.3-next.54
19
+
3
20
  ## [0.0.3-next.53](https://github.com/twinfoundation/standards/compare/standards-dataspace-protocol-v0.0.3-next.52...standards-dataspace-protocol-v0.0.3-next.53) (2026-03-11)
4
21
 
5
22
 
package/docs/examples.md CHANGED
@@ -18,12 +18,10 @@ const payload: IJsonLdNodeObject = {
18
18
  state: 'STARTED'
19
19
  };
20
20
 
21
- const failures: IValidationFailure[] = [];
22
21
  const normalised = await DataspaceProtocolHelper.normalize(payload);
23
- const isConformant = await DataspaceProtocolHelper.checkConformance(normalised, failures);
22
+ const validationFailures = await DataspaceProtocolHelper.validate(normalised);
24
23
 
25
- console.log(isConformant); // true
26
- console.log(failures.length); // 0
24
+ console.log(validationFailures.length); // 0
27
25
  ```
28
26
 
29
27
  ## Data Types
@@ -14,9 +14,9 @@ Dataspace protocol helper.
14
14
 
15
15
  ## Methods
16
16
 
17
- ### checkConformance()
17
+ ### validate()
18
18
 
19
- > `static` **checkConformance**(`object`, `validationFailures`): `Promise`\<`boolean`\>
19
+ > `static` **validate**(`object`): `Promise`\<`IValidationFailure`[]\>
20
20
 
21
21
  Checks whether the object passed as parameter is conformant to the DS Protocol definitions.
22
22
 
@@ -28,17 +28,11 @@ Checks whether the object passed as parameter is conformant to the DS Protocol d
28
28
 
29
29
  The object to check
30
30
 
31
- ##### validationFailures
32
-
33
- `IValidationFailure`[]
34
-
35
- the Validation failures obtained during the conformance checking.
36
-
37
31
  #### Returns
38
32
 
39
- `Promise`\<`boolean`\>
33
+ `Promise`\<`IValidationFailure`[]\>
40
34
 
41
- true or false depending whether the object is conformant or not
35
+ An array of validation failures, empty if the object is conformant
42
36
 
43
37
  ***
44
38
 
package/locales/en.json CHANGED
@@ -2,6 +2,9 @@
2
2
  "error": {
3
3
  "dataspaceProtocolHelper": {
4
4
  "schemaNotRegistered": "JSON Schema \"{schemaId}\" is not registered in DataTypeHandlerFactory"
5
+ },
6
+ "validation": {
7
+ "missingType": "The object must include at least one @type value"
5
8
  }
6
9
  }
7
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/standards-dataspace-protocol",
3
- "version": "0.0.3-next.53",
3
+ "version": "0.0.3-next.54",
4
4
  "description": "Data models for the Dataspace Protocol specification.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,8 +17,8 @@
17
17
  "@twin.org/core": "next",
18
18
  "@twin.org/data-core": "next",
19
19
  "@twin.org/data-json-ld": "next",
20
- "@twin.org/standards-w3c-dcat": "0.0.3-next.53",
21
- "@twin.org/standards-w3c-odrl": "0.0.3-next.53",
20
+ "@twin.org/standards-w3c-dcat": "0.0.3-next.54",
21
+ "@twin.org/standards-w3c-odrl": "0.0.3-next.54",
22
22
  "@twin.org/web": "next"
23
23
  },
24
24
  "main": "./dist/es/index.js",