@twin.org/data-json-ld 0.0.1-next.32 → 0.0.1-next.34

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.
@@ -1942,29 +1942,37 @@ class JsonLdHelper {
1942
1942
  * Validate a JSON-LD document.
1943
1943
  * @param document The JSON-LD document to validate.
1944
1944
  * @param validationFailures The list of validation failures to add to.
1945
- * @param validationMode The validation mode to use, defaults to either.
1945
+ * @param options Optional options for validation.
1946
+ * @param options.failOnMissingType If true, will fail validation if the data type is missing, defaults to false.
1947
+ * @param options.validationMode The validation mode to use, defaults to either.
1946
1948
  * @returns True if the document was valid.
1947
1949
  */
1948
- static async validate(document, validationFailures, validationMode) {
1950
+ static async validate(document, validationFailures, options) {
1949
1951
  if (core.Is.array(document)) {
1950
1952
  // If the document is an array of nodes, validate each node
1951
1953
  for (const node of document) {
1952
- await JsonLdHelper.validate(node, validationFailures, validationMode);
1954
+ await JsonLdHelper.validate(node, validationFailures, options);
1953
1955
  }
1954
1956
  }
1955
1957
  else if (core.Is.array(document["@graph"])) {
1956
1958
  // If the graph is an array of nodes, validate each node
1957
1959
  for (const node of document["@graph"]) {
1958
- await JsonLdHelper.validate(node, validationFailures, validationMode);
1960
+ await JsonLdHelper.validate(node, validationFailures, options);
1959
1961
  }
1960
1962
  }
1961
1963
  else if (core.Is.object(document)) {
1962
1964
  // Expand the document to ensure we have the full context for types
1963
- // As the data types in the factories are not always fully qualified
1964
- const expandedDoc = await JsonLdProcessor.expand(document);
1965
- const expandedDataType = core.ArrayHelper.fromObjectOrArray(expandedDoc[0]["@type"]);
1966
- if (core.Is.arrayValue(expandedDataType)) {
1967
- await dataCore.DataTypeHelper.validate("document", expandedDataType[0], document, validationFailures, validationMode);
1965
+ // As the data types in the factories are always fully qualified
1966
+ const expandedDocs = await JsonLdProcessor.expand(document);
1967
+ if (core.Is.arrayValue(expandedDocs)) {
1968
+ for (const expandedDoc of expandedDocs) {
1969
+ const expandedDataTypes = core.ArrayHelper.fromObjectOrArray(expandedDoc["@type"]);
1970
+ if (core.Is.arrayValue(expandedDataTypes)) {
1971
+ for (const expandedDataType of expandedDataTypes) {
1972
+ await dataCore.DataTypeHelper.validate("document", expandedDataType, document, validationFailures, options);
1973
+ }
1974
+ }
1975
+ }
1968
1976
  }
1969
1977
  }
1970
1978
  return validationFailures.length === 0;
@@ -1940,29 +1940,37 @@ class JsonLdHelper {
1940
1940
  * Validate a JSON-LD document.
1941
1941
  * @param document The JSON-LD document to validate.
1942
1942
  * @param validationFailures The list of validation failures to add to.
1943
- * @param validationMode The validation mode to use, defaults to either.
1943
+ * @param options Optional options for validation.
1944
+ * @param options.failOnMissingType If true, will fail validation if the data type is missing, defaults to false.
1945
+ * @param options.validationMode The validation mode to use, defaults to either.
1944
1946
  * @returns True if the document was valid.
1945
1947
  */
1946
- static async validate(document, validationFailures, validationMode) {
1948
+ static async validate(document, validationFailures, options) {
1947
1949
  if (Is.array(document)) {
1948
1950
  // If the document is an array of nodes, validate each node
1949
1951
  for (const node of document) {
1950
- await JsonLdHelper.validate(node, validationFailures, validationMode);
1952
+ await JsonLdHelper.validate(node, validationFailures, options);
1951
1953
  }
1952
1954
  }
1953
1955
  else if (Is.array(document["@graph"])) {
1954
1956
  // If the graph is an array of nodes, validate each node
1955
1957
  for (const node of document["@graph"]) {
1956
- await JsonLdHelper.validate(node, validationFailures, validationMode);
1958
+ await JsonLdHelper.validate(node, validationFailures, options);
1957
1959
  }
1958
1960
  }
1959
1961
  else if (Is.object(document)) {
1960
1962
  // Expand the document to ensure we have the full context for types
1961
- // As the data types in the factories are not always fully qualified
1962
- const expandedDoc = await JsonLdProcessor.expand(document);
1963
- const expandedDataType = ArrayHelper.fromObjectOrArray(expandedDoc[0]["@type"]);
1964
- if (Is.arrayValue(expandedDataType)) {
1965
- await DataTypeHelper.validate("document", expandedDataType[0], document, validationFailures, validationMode);
1963
+ // As the data types in the factories are always fully qualified
1964
+ const expandedDocs = await JsonLdProcessor.expand(document);
1965
+ if (Is.arrayValue(expandedDocs)) {
1966
+ for (const expandedDoc of expandedDocs) {
1967
+ const expandedDataTypes = ArrayHelper.fromObjectOrArray(expandedDoc["@type"]);
1968
+ if (Is.arrayValue(expandedDataTypes)) {
1969
+ for (const expandedDataType of expandedDataTypes) {
1970
+ await DataTypeHelper.validate("document", expandedDataType, document, validationFailures, options);
1971
+ }
1972
+ }
1973
+ }
1966
1974
  }
1967
1975
  }
1968
1976
  return validationFailures.length === 0;
@@ -9,8 +9,13 @@ export declare class JsonLdHelper {
9
9
  * Validate a JSON-LD document.
10
10
  * @param document The JSON-LD document to validate.
11
11
  * @param validationFailures The list of validation failures to add to.
12
- * @param validationMode The validation mode to use, defaults to either.
12
+ * @param options Optional options for validation.
13
+ * @param options.failOnMissingType If true, will fail validation if the data type is missing, defaults to false.
14
+ * @param options.validationMode The validation mode to use, defaults to either.
13
15
  * @returns True if the document was valid.
14
16
  */
15
- static validate<T extends IJsonLdDocument = IJsonLdDocument>(document: T, validationFailures: IValidationFailure[], validationMode?: ValidationMode): Promise<boolean>;
17
+ static validate<T extends IJsonLdDocument = IJsonLdDocument>(document: T, validationFailures: IValidationFailure[], options?: {
18
+ validationMode?: ValidationMode;
19
+ failOnMissingType?: boolean;
20
+ }): Promise<boolean>;
16
21
  }
package/docs/changelog.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # @twin.org/data-json-ld - Changelog
2
2
 
3
+ ## [0.0.1-next.34](https://github.com/twinfoundation/data/compare/data-json-ld-v0.0.1-next.33...data-json-ld-v0.0.1-next.34) (2025-06-02)
4
+
5
+
6
+ ### Features
7
+
8
+ * support multiple type JSON-LD ([8f0d530](https://github.com/twinfoundation/data/commit/8f0d530f66302ab19413ecf968f170f97456e31e))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/data-core bumped from 0.0.1-next.33 to 0.0.1-next.34
16
+
17
+ ## [0.0.1-next.33](https://github.com/twinfoundation/data/compare/data-json-ld-v0.0.1-next.32...data-json-ld-v0.0.1-next.33) (2025-06-02)
18
+
19
+
20
+ ### Features
21
+
22
+ * add fail on missing type option and both mode ([e8b9702](https://github.com/twinfoundation/data/commit/e8b97029a04b646497ff0e55b9610291e58ae92a))
23
+
24
+
25
+ ### Dependencies
26
+
27
+ * The following workspace dependencies were updated
28
+ * dependencies
29
+ * @twin.org/data-core bumped from 0.0.1-next.32 to 0.0.1-next.33
30
+
3
31
  ## [0.0.1-next.32](https://github.com/twinfoundation/data/compare/data-json-ld-v0.0.1-next.31...data-json-ld-v0.0.1-next.32) (2025-05-28)
4
32
 
5
33
 
@@ -16,7 +16,7 @@ Class to help with JSON LD.
16
16
 
17
17
  ### validate()
18
18
 
19
- > `static` **validate**\<`T`\>(`document`, `validationFailures`, `validationMode?`): `Promise`\<`boolean`\>
19
+ > `static` **validate**\<`T`\>(`document`, `validationFailures`, `options?`): `Promise`\<`boolean`\>
20
20
 
21
21
  Validate a JSON-LD document.
22
22
 
@@ -40,12 +40,22 @@ The JSON-LD document to validate.
40
40
 
41
41
  The list of validation failures to add to.
42
42
 
43
- ##### validationMode?
43
+ ##### options?
44
+
45
+ Optional options for validation.
46
+
47
+ ###### validationMode?
44
48
 
45
49
  `ValidationMode`
46
50
 
47
51
  The validation mode to use, defaults to either.
48
52
 
53
+ ###### failOnMissingType?
54
+
55
+ `boolean`
56
+
57
+ If true, will fail validation if the data type is missing, defaults to false.
58
+
49
59
  #### Returns
50
60
 
51
61
  `Promise`\<`boolean`\>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/data-json-ld",
3
- "version": "0.0.1-next.32",
3
+ "version": "0.0.1-next.34",
4
4
  "description": "Models which define the structure of JSON LD",
5
5
  "repository": {
6
6
  "type": "git",
@@ -15,7 +15,7 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "@twin.org/core": "next",
18
- "@twin.org/data-core": "0.0.1-next.32",
18
+ "@twin.org/data-core": "0.0.1-next.34",
19
19
  "@twin.org/entity": "next",
20
20
  "@twin.org/nameof": "next",
21
21
  "@twin.org/web": "next",