@twin.org/data-json-ld 0.0.3-next.2 → 0.0.3-next.21

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.
Files changed (88) hide show
  1. package/README.md +1 -1
  2. package/dist/es/dataTypes/jsonLdDataTypes.js +104 -131
  3. package/dist/es/dataTypes/jsonLdDataTypes.js.map +1 -1
  4. package/dist/es/helpers/jsonLdHelperTypes.js +2 -0
  5. package/dist/es/helpers/jsonLdHelperTypes.js.map +1 -0
  6. package/dist/es/index.js +1 -0
  7. package/dist/es/index.js.map +1 -1
  8. package/dist/es/models/jsonLdContexts.js +10 -2
  9. package/dist/es/models/jsonLdContexts.js.map +1 -1
  10. package/dist/es/schemas/JsonLdContainerType.json +17 -7
  11. package/dist/es/schemas/JsonLdContainerTypeArray.json +129 -142
  12. package/dist/es/schemas/JsonLdContextDefinition.json +76 -18
  13. package/dist/es/schemas/JsonLdContextDefinitionElement.json +1 -0
  14. package/dist/es/schemas/JsonLdContextDefinitionRoot.json +1 -0
  15. package/dist/es/schemas/JsonLdDocument.json +3 -3
  16. package/dist/es/schemas/JsonLdExpandedTermDefinition.json +101 -89
  17. package/dist/es/schemas/JsonLdGraphObject.json +2 -2
  18. package/dist/es/schemas/JsonLdIdMap.json +1 -0
  19. package/dist/es/schemas/JsonLdIncludedBlock.json +1 -0
  20. package/dist/es/schemas/JsonLdIndexMap.json +2 -1
  21. package/dist/es/schemas/JsonLdIndexMapItem.json +1 -0
  22. package/dist/es/schemas/JsonLdJsonArray.json +1 -0
  23. package/dist/es/schemas/JsonLdJsonObject.json +2 -8
  24. package/dist/es/schemas/JsonLdJsonPrimitive.json +14 -5
  25. package/dist/es/schemas/JsonLdJsonValue.json +1 -0
  26. package/dist/es/schemas/JsonLdLanguageMap.json +1 -0
  27. package/dist/es/schemas/JsonLdListObject.json +2 -2
  28. package/dist/es/schemas/JsonLdListOrSetItem.json +1 -0
  29. package/dist/es/schemas/JsonLdNodeObject.json +12 -72
  30. package/dist/es/schemas/JsonLdNodePrimitive.json +1 -0
  31. package/dist/es/schemas/JsonLdObject.json +3 -3
  32. package/dist/es/schemas/JsonLdSetObject.json +2 -2
  33. package/dist/es/schemas/JsonLdTypeMap.json +1 -0
  34. package/dist/es/schemas/JsonLdValueObject.json +99 -87
  35. package/dist/es/utils/jsonLdHelper.js +181 -15
  36. package/dist/es/utils/jsonLdHelper.js.map +1 -1
  37. package/dist/es/utils/jsonLdProcessor.js +125 -34
  38. package/dist/es/utils/jsonLdProcessor.js.map +1 -1
  39. package/dist/types/helpers/jsonLdHelperTypes.d.ts +127 -0
  40. package/dist/types/index.d.ts +1 -0
  41. package/dist/types/models/jsonLdContexts.d.ts +10 -2
  42. package/dist/types/utils/jsonLdHelper.d.ts +63 -6
  43. package/dist/types/utils/jsonLdProcessor.d.ts +10 -7
  44. package/docs/changelog.md +349 -63
  45. package/docs/examples.md +214 -1
  46. package/docs/reference/classes/JsonLdDataTypes.md +1 -1
  47. package/docs/reference/classes/JsonLdHelper.md +249 -13
  48. package/docs/reference/classes/JsonLdProcessor.md +51 -58
  49. package/docs/reference/index.md +23 -0
  50. package/docs/reference/interfaces/IJsonLdContextDefinition.md +20 -20
  51. package/docs/reference/interfaces/IJsonLdGraphObject.md +7 -7
  52. package/docs/reference/interfaces/IJsonLdIdMap.md +1 -1
  53. package/docs/reference/interfaces/IJsonLdIndexMap.md +1 -1
  54. package/docs/reference/interfaces/IJsonLdJsonObject.md +1 -1
  55. package/docs/reference/interfaces/IJsonLdLanguageMap.md +1 -1
  56. package/docs/reference/interfaces/IJsonLdListObject.md +3 -3
  57. package/docs/reference/interfaces/IJsonLdNodeObject.md +17 -17
  58. package/docs/reference/interfaces/IJsonLdObject.md +16 -16
  59. package/docs/reference/interfaces/IJsonLdSetObject.md +3 -3
  60. package/docs/reference/interfaces/IJsonLdTypeMap.md +1 -1
  61. package/docs/reference/type-aliases/IJsonLdExpandedTermDefinition.md +7 -7
  62. package/docs/reference/type-aliases/IJsonLdValueObject.md +2 -2
  63. package/docs/reference/type-aliases/JsonLdAliasKey.md +15 -0
  64. package/docs/reference/type-aliases/JsonLdExistingProperty.md +19 -0
  65. package/docs/reference/type-aliases/JsonLdExistingPropertyEither.md +24 -0
  66. package/docs/reference/type-aliases/JsonLdKeys.md +11 -0
  67. package/docs/reference/type-aliases/JsonLdObjectWithAliases.md +16 -0
  68. package/docs/reference/type-aliases/JsonLdObjectWithAtId.md +21 -0
  69. package/docs/reference/type-aliases/JsonLdObjectWithAtType.md +21 -0
  70. package/docs/reference/type-aliases/JsonLdObjectWithContext.md +21 -0
  71. package/docs/reference/type-aliases/JsonLdObjectWithId.md +21 -0
  72. package/docs/reference/type-aliases/JsonLdObjectWithNoAtId.md +11 -0
  73. package/docs/reference/type-aliases/JsonLdObjectWithNoAtType.md +11 -0
  74. package/docs/reference/type-aliases/JsonLdObjectWithNoContext.md +12 -0
  75. package/docs/reference/type-aliases/JsonLdObjectWithNoId.md +11 -0
  76. package/docs/reference/type-aliases/JsonLdObjectWithNoType.md +11 -0
  77. package/docs/reference/type-aliases/JsonLdObjectWithOptionalAtId.md +21 -0
  78. package/docs/reference/type-aliases/JsonLdObjectWithOptionalAtType.md +21 -0
  79. package/docs/reference/type-aliases/JsonLdObjectWithOptionalContext.md +22 -0
  80. package/docs/reference/type-aliases/JsonLdObjectWithOptionalId.md +21 -0
  81. package/docs/reference/type-aliases/JsonLdObjectWithOptionalType.md +21 -0
  82. package/docs/reference/type-aliases/JsonLdObjectWithType.md +21 -0
  83. package/docs/reference/type-aliases/JsonLdOptionalKeys.md +11 -0
  84. package/docs/reference/type-aliases/JsonLdRequiredKeys.md +11 -0
  85. package/docs/reference/type-aliases/JsonLdWithAliases.md +17 -0
  86. package/docs/reference/variables/JsonLdContexts.md +15 -3
  87. package/docs/reference/variables/JsonLdTypes.md +26 -26
  88. package/package.json +6 -6
@@ -1,112 +1,124 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "https://schema.twindev.org/json-ld/JsonLdValueObject",
4
- "description": "A value object is used to explicitly associate a type or a language with a value to create a typed value or a language-tagged string and possibly associate a base direction.",
5
- "anyOf": [
4
+ "title": "JsonLdValueObject",
5
+ "description": "A value object is used to explicitly associate a type or a language with a value\nto create a typed value or a language-tagged string and possibly associate a base direction.",
6
+ "allOf": [
6
7
  {
7
8
  "type": "object",
8
- "additionalProperties": false,
9
9
  "properties": {
10
- "@value": {
11
- "type": [
12
- "null",
13
- "boolean",
14
- "number",
15
- "string"
16
- ]
17
- },
18
- "@language": {
19
- "type": "string"
20
- },
21
- "@direction": {
22
- "type": [
23
- "string",
24
- "null"
25
- ],
26
- "enum": [
27
- "ltr",
28
- "rtl",
29
- null
30
- ]
31
- },
32
10
  "@index": {
33
11
  "type": "string"
34
12
  },
35
13
  "@context": {
36
14
  "$ref": "https://schema.twindev.org/json-ld/JsonLdContextDefinitionRoot"
37
15
  }
38
- },
39
- "required": [
40
- "@value"
41
- ]
16
+ }
42
17
  },
43
18
  {
44
- "type": "object",
45
- "additionalProperties": false,
46
- "properties": {
47
- "@value": {
48
- "type": [
49
- "null",
50
- "boolean",
51
- "number",
52
- "string"
53
- ]
54
- },
55
- "@type": {
56
- "type": "string"
57
- },
58
- "@index": {
59
- "type": "string"
60
- },
61
- "@context": {
62
- "$ref": "https://schema.twindev.org/json-ld/JsonLdContextDefinitionRoot"
63
- }
64
- },
65
- "required": [
66
- "@type",
67
- "@value"
68
- ]
69
- },
70
- {
71
- "type": "object",
72
- "additionalProperties": false,
73
- "properties": {
74
- "@value": {
75
- "anyOf": [
76
- {
77
- "type": "null"
78
- },
79
- {
80
- "type": "boolean"
19
+ "anyOf": [
20
+ {
21
+ "type": "object",
22
+ "properties": {
23
+ "@value": {
24
+ "anyOf": [
25
+ {
26
+ "type": "null"
27
+ },
28
+ {
29
+ "type": "boolean"
30
+ },
31
+ {
32
+ "type": "number"
33
+ },
34
+ {
35
+ "type": "string"
36
+ }
37
+ ]
81
38
  },
82
- {
83
- "type": "number"
84
- },
85
- {
39
+ "@language": {
86
40
  "type": "string"
87
41
  },
88
- {
89
- "$ref": "https://schema.twindev.org/json-ld/JsonLdJsonObject"
90
- },
91
- {
92
- "$ref": "https://schema.twindev.org/json-ld/JsonLdJsonArray"
42
+ "@direction": {
43
+ "anyOf": [
44
+ {
45
+ "const": "ltr"
46
+ },
47
+ {
48
+ "const": "rtl"
49
+ },
50
+ {
51
+ "type": "null"
52
+ }
53
+ ]
93
54
  }
55
+ },
56
+ "required": [
57
+ "@value"
94
58
  ]
95
59
  },
96
- "@type": {
97
- "type": "string",
98
- "const": "@json"
99
- },
100
- "@index": {
101
- "type": "string"
60
+ {
61
+ "type": "object",
62
+ "properties": {
63
+ "@value": {
64
+ "anyOf": [
65
+ {
66
+ "type": "null"
67
+ },
68
+ {
69
+ "type": "boolean"
70
+ },
71
+ {
72
+ "type": "number"
73
+ },
74
+ {
75
+ "type": "string"
76
+ }
77
+ ]
78
+ },
79
+ "@type": {
80
+ "type": "string"
81
+ }
82
+ },
83
+ "required": [
84
+ "@value",
85
+ "@type"
86
+ ]
102
87
  },
103
- "@context": {
104
- "$ref": "https://schema.twindev.org/json-ld/JsonLdContextDefinitionRoot"
88
+ {
89
+ "type": "object",
90
+ "properties": {
91
+ "@value": {
92
+ "anyOf": [
93
+ {
94
+ "type": "null"
95
+ },
96
+ {
97
+ "type": "boolean"
98
+ },
99
+ {
100
+ "type": "number"
101
+ },
102
+ {
103
+ "type": "string"
104
+ },
105
+ {
106
+ "$ref": "https://schema.twindev.org/json-ld/JsonLdJsonObject"
107
+ },
108
+ {
109
+ "$ref": "https://schema.twindev.org/json-ld/JsonLdJsonArray"
110
+ }
111
+ ]
112
+ },
113
+ "@type": {
114
+ "const": "@json"
115
+ }
116
+ },
117
+ "required": [
118
+ "@value",
119
+ "@type"
120
+ ]
105
121
  }
106
- },
107
- "required": [
108
- "@type",
109
- "@value"
110
122
  ]
111
123
  }
112
124
  ]
@@ -51,16 +51,42 @@ export class JsonLdHelper {
51
51
  }
52
52
  return validationFailures.length === 0;
53
53
  }
54
+ /**
55
+ * Convert an object to a JSON-LD node object.
56
+ * @param object The object to convert.
57
+ * @returns The JSON-LD node object.
58
+ */
59
+ static toNodeObject(object) {
60
+ Guards.object(JsonLdHelper.CLASS_NAME, "object", object);
61
+ return object;
62
+ }
63
+ /**
64
+ * Convert the JSON-LD node object to a structured object.
65
+ * @param nodeObject The JSON-LD node object to convert.
66
+ * @returns The structured object.
67
+ */
68
+ static toStructuredObject(nodeObject) {
69
+ Guards.object(JsonLdHelper.CLASS_NAME, "nodeObject", nodeObject);
70
+ return nodeObject;
71
+ }
72
+ /**
73
+ * Expand the JSON-LD document.
74
+ * @param document The JSON-LD document to expand.
75
+ * @returns The expanded JSON-LD document.
76
+ */
77
+ static async expand(document) {
78
+ Guards.object(JsonLdHelper.CLASS_NAME, "document", document);
79
+ return JsonLdProcessor.expand(document);
80
+ }
54
81
  /**
55
82
  * Expand the JSON-LD document and check if it is of a specific type.
56
- * @param document The JSON-LD document to check.
83
+ * @param documentOrExpanded The JSON-LD document to check or already expanded document.
57
84
  * @param type The type to check for.
58
85
  * @returns True if the document is of the specified type.
59
86
  */
60
- static async isType(document, type) {
61
- Guards.object(JsonLdHelper.CLASS_NAME, "document", document);
87
+ static async isType(documentOrExpanded, type) {
88
+ const expanded = await JsonLdHelper.getExpandedDocument(documentOrExpanded);
62
89
  Guards.arrayValue(JsonLdHelper.CLASS_NAME, "type", type);
63
- const expanded = await JsonLdProcessor.expand(document);
64
90
  if (Is.arrayValue(expanded)) {
65
91
  for (const item of expanded) {
66
92
  const types = ArrayHelper.fromObjectOrArray(item["@type"]);
@@ -77,15 +103,14 @@ export class JsonLdHelper {
77
103
  }
78
104
  /**
79
105
  * Get the types from the document.
80
- * @param document The JSON-LD document to check.
106
+ * @param documentOrExpanded The JSON-LD document to check or already expanded document.
81
107
  * @returns The type(s) extracted from the document.
82
108
  */
83
- static async getType(document) {
84
- Guards.object(JsonLdHelper.CLASS_NAME, "document", document);
85
- const expandedDocs = await JsonLdProcessor.expand(document);
109
+ static async getType(documentOrExpanded) {
110
+ const expanded = await JsonLdHelper.getExpandedDocument(documentOrExpanded);
86
111
  const types = new Set();
87
112
  const props = ["@type", "type"];
88
- for (const expandedDoc of expandedDocs) {
113
+ for (const expandedDoc of expanded) {
89
114
  for (const prop of props) {
90
115
  const expandedProps = ArrayHelper.fromObjectOrArray(expandedDoc[prop]);
91
116
  if (Is.arrayValue(expandedProps)) {
@@ -104,14 +129,14 @@ export class JsonLdHelper {
104
129
  }
105
130
  /**
106
131
  * Get the id from the document.
107
- * @param document The JSON-LD document to get the id from.
132
+ * @param documentOrExpanded The JSON-LD document to get the id from or already expanded document.
133
+ * @param additionalIdProperties Optional additional properties to check for the id, in addition to "@id" and "id".
108
134
  * @returns The id extracted from the document.
109
135
  */
110
- static async getId(document) {
111
- Guards.object(JsonLdHelper.CLASS_NAME, "document", document);
112
- const expandedDocs = await JsonLdProcessor.expand(document);
113
- const props = ["@id", "id"];
114
- for (const expandedDoc of expandedDocs) {
136
+ static async getId(documentOrExpanded, additionalIdProperties) {
137
+ const expanded = await JsonLdHelper.getExpandedDocument(documentOrExpanded);
138
+ const props = ["@id", "id", ...(additionalIdProperties ?? [])];
139
+ for (const expandedDoc of expanded) {
115
140
  for (const prop of props) {
116
141
  const expandedProps = ArrayHelper.fromObjectOrArray(expandedDoc[prop]);
117
142
  if (Is.arrayValue(expandedProps)) {
@@ -127,5 +152,146 @@ export class JsonLdHelper {
127
152
  }
128
153
  }
129
154
  }
155
+ /**
156
+ * Get property values by a single full expanded property name.
157
+ * @param documentOrExpanded The JSON-LD document to get the property from or already expanded document.
158
+ * @param propertyFullName The full expanded property name.
159
+ * @param language Optional filter values by their language property.
160
+ * @returns Matching property values for the input property.
161
+ */
162
+ static async getPropertyValue(documentOrExpanded, propertyFullName, language) {
163
+ const results = await JsonLdHelper.getPropertyValues(documentOrExpanded, [propertyFullName], language);
164
+ return results[0];
165
+ }
166
+ /**
167
+ * Get property values by their full expanded property names.
168
+ * @param documentOrExpanded The JSON-LD document to get the property from or already expanded document.
169
+ * @param propertyFullNames The full expanded property names.
170
+ * @param language Optional filter values by their language property.
171
+ * @returns Matching property values for each input property, in the same index order.
172
+ */
173
+ static async getPropertyValues(documentOrExpanded, propertyFullNames, language) {
174
+ const expanded = await JsonLdHelper.getExpandedDocument(documentOrExpanded);
175
+ Guards.arrayValue(JsonLdHelper.CLASS_NAME, "propertyFullNames", propertyFullNames);
176
+ if (Is.stringValue(language)) {
177
+ Guards.stringValue(JsonLdHelper.CLASS_NAME, "language", language);
178
+ }
179
+ const languageLower = Is.stringValue(language) ? language.toLowerCase() : undefined;
180
+ const result = [];
181
+ for (const propertyFullName of propertyFullNames) {
182
+ Guards.stringValue(JsonLdHelper.CLASS_NAME, "propertyFullName", propertyFullName);
183
+ const values = [];
184
+ for (const expandedDoc of expanded) {
185
+ const propValue = expandedDoc[propertyFullName];
186
+ if (!Is.empty(propValue)) {
187
+ const expandedProps = ArrayHelper.fromObjectOrArray(propValue);
188
+ if (Is.arrayValue(expandedProps)) {
189
+ for (const expandedProp of expandedProps) {
190
+ if (Is.object(expandedProp)) {
191
+ if (!Is.empty(expandedProp["@value"])) {
192
+ let shouldAdd = true;
193
+ if (Is.stringValue(languageLower)) {
194
+ const itemLanguage = Is.stringValue(expandedProp["@language"])
195
+ ? expandedProp["@language"].toLowerCase()
196
+ : undefined;
197
+ shouldAdd = itemLanguage === languageLower;
198
+ }
199
+ if (shouldAdd) {
200
+ values.push(expandedProp["@value"]);
201
+ }
202
+ }
203
+ else if (!Is.stringValue(languageLower)) {
204
+ values.push(expandedProp);
205
+ }
206
+ }
207
+ else if (Is.stringValue(expandedProp) ||
208
+ Is.boolean(expandedProp) ||
209
+ Is.number(expandedProp)) {
210
+ if (!Is.stringValue(languageLower)) {
211
+ values.push(expandedProp);
212
+ }
213
+ }
214
+ }
215
+ }
216
+ }
217
+ }
218
+ result.push(values.length > 0 ? values : undefined);
219
+ }
220
+ return result;
221
+ }
222
+ /**
223
+ * Prefix all properties in the document with the provided prefix, except for JSON-LD properties.
224
+ * This is useful for ensuring that all properties are fully qualified with a namespace.
225
+ * For example, if the prefix is "ex" and the document has a property "name", it will be transformed to "ex:name".
226
+ * @param nodeObject The JSON-LD node object to prefix properties on.
227
+ * @param prefix The prefix to add to the properties.
228
+ * @param properties Optional list of properties to prefix. If not provided, all properties except for JSON-LD properties.
229
+ * @returns A new JSON-LD node object with the properties prefixed.
230
+ */
231
+ static prefixProperties(nodeObject, prefix, properties) {
232
+ Guards.object(JsonLdHelper.CLASS_NAME, "nodeObject", nodeObject);
233
+ Guards.stringValue(JsonLdHelper.CLASS_NAME, "prefix", prefix);
234
+ const normalizedPrefix = prefix.endsWith(":") ? prefix.slice(0, -1) : prefix;
235
+ const hasNoPropertiesFilter = !Is.arrayValue(properties);
236
+ const prefixedNodeObject = {};
237
+ for (const key in nodeObject) {
238
+ const value = nodeObject[key];
239
+ if (Is.stringValue(key) &&
240
+ !key.startsWith("@") &&
241
+ (hasNoPropertiesFilter || properties.includes(key))) {
242
+ prefixedNodeObject[`${normalizedPrefix}:${key}`] = value;
243
+ }
244
+ else {
245
+ prefixedNodeObject[key] = value;
246
+ }
247
+ }
248
+ return prefixedNodeObject;
249
+ }
250
+ /**
251
+ * Strip a prefix from properties in the document, except for JSON-LD properties.
252
+ * This is useful for converting fully qualified namespaced properties back to local names.
253
+ * For example, if the prefix is "ex" and the document has a property "ex:name", it will be transformed to "name".
254
+ * @param nodeObject The JSON-LD node object to strip prefixed properties from.
255
+ * @param prefix The prefix to remove from the properties.
256
+ * @param properties Optional list of unprefixed properties to strip. If not provided, all matching prefixed properties.
257
+ * @returns A new JSON-LD node object with the prefix stripped from matching properties.
258
+ */
259
+ static stripPrefixProperties(nodeObject, prefix, properties) {
260
+ Guards.object(JsonLdHelper.CLASS_NAME, "nodeObject", nodeObject);
261
+ Guards.stringValue(JsonLdHelper.CLASS_NAME, "prefix", prefix);
262
+ const normalizedPrefix = prefix.endsWith(":") ? prefix.slice(0, -1) : prefix;
263
+ const hasNoPropertiesFilter = !Is.arrayValue(properties);
264
+ const strippedNodeObject = {};
265
+ for (const key in nodeObject) {
266
+ const value = nodeObject[key];
267
+ if (Is.stringValue(key) && !key.startsWith("@") && key.startsWith(`${normalizedPrefix}:`)) {
268
+ const strippedKey = key.slice(normalizedPrefix.length + 1);
269
+ if (hasNoPropertiesFilter || properties.includes(strippedKey)) {
270
+ strippedNodeObject[strippedKey] = value;
271
+ }
272
+ else {
273
+ strippedNodeObject[key] = value;
274
+ }
275
+ }
276
+ else {
277
+ strippedNodeObject[key] = value;
278
+ }
279
+ }
280
+ return strippedNodeObject;
281
+ }
282
+ /**
283
+ * Get an expanded JSON-LD document from either compact or expanded input.
284
+ * @param documentOrExpanded The JSON-LD document or expanded document.
285
+ * @returns The expanded JSON-LD document.
286
+ * @internal
287
+ */
288
+ static async getExpandedDocument(documentOrExpanded) {
289
+ if (Is.array(documentOrExpanded)) {
290
+ Guards.array(JsonLdHelper.CLASS_NAME, "documentOrExpanded", documentOrExpanded);
291
+ return documentOrExpanded;
292
+ }
293
+ Guards.object(JsonLdHelper.CLASS_NAME, "documentOrExpanded", documentOrExpanded);
294
+ return JsonLdProcessor.expand(documentOrExpanded);
295
+ }
130
296
  }
131
297
  //# sourceMappingURL=jsonLdHelper.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"jsonLdHelper.js","sourceRoot":"","sources":["../../../src/utils/jsonLdHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE,EAA2B,MAAM,gBAAgB,CAAC;AAClF,OAAO,EAAE,cAAc,EAAuB,MAAM,qBAAqB,CAAC;AAE1E,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAIvD;;GAEG;AACH,MAAM,OAAO,YAAY;IACxB;;;OAGG;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,CAAC,aAAa,CAAC,EAAE,CAAC;oBAClC,KAAK,MAAM,YAAY,IAAI,aAAa,EAAE,CAAC;wBAC1C,MAAM,GAAG,GAAG,WAAW,CAAC,iBAAiB,CAAC,YAAY,CAAC,CAAC;wBACxD,KAAK,MAAM,QAAQ,IAAI,GAAG,EAAE,CAAC;4BAC5B,IAAI,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC;gCAC9B,OAAO,QAAQ,CAAC;4BACjB,CAAC;wBACF,CAAC;oBACF,CAAC;gBACF,CAAC;YACF,CAAC;QACF,CAAC;IACF,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ArrayHelper, Guards, Is, type IValidationFailure } from \"@twin.org/core\";\nimport { DataTypeHelper, type ValidationMode } from \"@twin.org/data-core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { JsonLdProcessor } from \"./jsonLdProcessor.js\";\nimport type { IJsonLdDocument } from \"../models/IJsonLdDocument.js\";\nimport type { IJsonLdNodeObject } from \"../models/IJsonLdNodeObject.js\";\n\n/**\n * Class to help with JSON LD.\n */\nexport class JsonLdHelper {\n\t/**\n\t * The class name.\n\t * @internal\n\t */\n\tpublic static readonly CLASS_NAME = nameof<JsonLdHelper>();\n\n\t/**\n\t * Validate a JSON-LD document.\n\t * @param document The JSON-LD document 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 document was valid.\n\t */\n\tpublic static async validate<T extends IJsonLdDocument = IJsonLdDocument>(\n\t\tdocument: T,\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\tif (Is.array<IJsonLdNodeObject>(document)) {\n\t\t\t// If the document is an array of nodes, validate each node\n\t\t\tfor (const node of document) {\n\t\t\t\tawait JsonLdHelper.validate(node, validationFailures, options);\n\t\t\t}\n\t\t} else if (Is.array<IJsonLdNodeObject>(document[\"@graph\"])) {\n\t\t\t// If the graph is an array of nodes, validate each node\n\t\t\tfor (const node of document[\"@graph\"]) {\n\t\t\t\tawait JsonLdHelper.validate(node, validationFailures, options);\n\t\t\t}\n\t\t} else if (Is.object<IJsonLdNodeObject>(document)) {\n\t\t\t// Expand the document to ensure we have the full context for types\n\t\t\t// As the data types in the factories are always fully qualified\n\t\t\tconst expandedDocs = await JsonLdProcessor.expand(document);\n\t\t\tif (Is.arrayValue(expandedDocs)) {\n\t\t\t\tfor (const expandedDoc of expandedDocs) {\n\t\t\t\t\tconst expandedDataTypes = ArrayHelper.fromObjectOrArray(expandedDoc[\"@type\"]);\n\t\t\t\t\tif (Is.arrayValue(expandedDataTypes)) {\n\t\t\t\t\t\tfor (const expandedDataType of expandedDataTypes) {\n\t\t\t\t\t\t\tawait DataTypeHelper.validate(\n\t\t\t\t\t\t\t\t\"document\",\n\t\t\t\t\t\t\t\texpandedDataType,\n\t\t\t\t\t\t\t\tdocument,\n\t\t\t\t\t\t\t\tvalidationFailures,\n\t\t\t\t\t\t\t\toptions\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn validationFailures.length === 0;\n\t}\n\n\t/**\n\t * Expand the JSON-LD document and check if it is of a specific type.\n\t * @param document The JSON-LD document to check.\n\t * @param type The type to check for.\n\t * @returns True if the document is of the specified type.\n\t */\n\tpublic static async isType(document: IJsonLdDocument, type: string[]): Promise<boolean> {\n\t\tGuards.object<IJsonLdDocument>(JsonLdHelper.CLASS_NAME, nameof(document), document);\n\t\tGuards.arrayValue(JsonLdHelper.CLASS_NAME, nameof(type), type);\n\n\t\tconst expanded = await JsonLdProcessor.expand(document);\n\n\t\tif (Is.arrayValue(expanded)) {\n\t\t\tfor (const item of expanded) {\n\t\t\t\tconst types = ArrayHelper.fromObjectOrArray(item[\"@type\"]);\n\t\t\t\tif (Is.arrayValue(types)) {\n\t\t\t\t\t// All required types must be present in this item's @type array\n\t\t\t\t\tconst itemTypes = new Set(types);\n\t\t\t\t\tif (type.every(t => itemTypes.has(t))) {\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn false;\n\t}\n\n\t/**\n\t * Get the types from the document.\n\t * @param document The JSON-LD document to check.\n\t * @returns The type(s) extracted from the document.\n\t */\n\tpublic static async getType(document: IJsonLdDocument): Promise<string[]> {\n\t\tGuards.object<IJsonLdDocument>(JsonLdHelper.CLASS_NAME, nameof(document), document);\n\n\t\tconst expandedDocs = await JsonLdProcessor.expand(document);\n\n\t\tconst types: Set<string> = new Set<string>();\n\t\tconst props = [\"@type\", \"type\"];\n\n\t\tfor (const expandedDoc of expandedDocs) {\n\t\t\tfor (const prop of props) {\n\t\t\t\tconst expandedProps = ArrayHelper.fromObjectOrArray(expandedDoc[prop]);\n\t\t\t\tif (Is.arrayValue(expandedProps)) {\n\t\t\t\t\tfor (const expandedProp of expandedProps) {\n\t\t\t\t\t\tconst arr = ArrayHelper.fromObjectOrArray(expandedProp);\n\t\t\t\t\t\tfor (const arrValue of arr) {\n\t\t\t\t\t\t\tif (Is.stringValue(arrValue)) {\n\t\t\t\t\t\t\t\ttypes.add(arrValue);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn Array.from(types);\n\t}\n\n\t/**\n\t * Get the id from the document.\n\t * @param document The JSON-LD document to get the id from.\n\t * @returns The id extracted from the document.\n\t */\n\tpublic static async getId(document: IJsonLdDocument): Promise<string | undefined> {\n\t\tGuards.object<IJsonLdDocument>(JsonLdHelper.CLASS_NAME, nameof(document), document);\n\n\t\tconst expandedDocs = await JsonLdProcessor.expand(document);\n\n\t\tconst props = [\"@id\", \"id\"];\n\n\t\tfor (const expandedDoc of expandedDocs) {\n\t\t\tfor (const prop of props) {\n\t\t\t\tconst expandedProps = ArrayHelper.fromObjectOrArray(expandedDoc[prop]);\n\t\t\t\tif (Is.arrayValue(expandedProps)) {\n\t\t\t\t\tfor (const expandedProp of expandedProps) {\n\t\t\t\t\t\tconst arr = ArrayHelper.fromObjectOrArray(expandedProp);\n\t\t\t\t\t\tfor (const arrValue of arr) {\n\t\t\t\t\t\t\tif (Is.stringValue(arrValue)) {\n\t\t\t\t\t\t\t\treturn arrValue;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"jsonLdHelper.js","sourceRoot":"","sources":["../../../src/utils/jsonLdHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE,EAA2B,MAAM,gBAAgB,CAAC;AAClF,OAAO,EAAE,cAAc,EAAuB,MAAM,qBAAqB,CAAC;AAE1E,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAKvD;;GAEG;AACH,MAAM,OAAO,YAAY;IACxB;;;OAGG;IACI,MAAM,CAAU,UAAU,kBAA0B;IAE3D;;;;;;;;OAQG;IACI,MAAM,CAAC,KAAK,CAAC,QAAQ,CAC3B,QAAW,EACX,kBAAwC,EACxC,OAGC;QAED,IAAI,EAAE,CAAC,KAAK,CAAoB,QAAQ,CAAC,EAAE,CAAC;YAC3C,2DAA2D;YAC3D,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;gBAC7B,MAAM,YAAY,CAAC,QAAQ,CAAC,IAAI,EAAE,kBAAkB,EAAE,OAAO,CAAC,CAAC;YAChE,CAAC;QACF,CAAC;aAAM,IAAI,EAAE,CAAC,KAAK,CAAoB,QAAQ,CA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EAAE,CAAC;oBAC/D,kBAAkB,CAAC,WAAW,CAAC,GAAG,KAAK,CAAC;gBACzC,CAAC;qBAAM,CAAC;oBACP,kBAAkB,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;gBACjC,CAAC;YACF,CAAC;iBAAM,CAAC;gBACP,kBAAkB,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YACjC,CAAC;QACF,CAAC;QAED,OAAO,kBAAkB,CAAC;IAC3B,CAAC;IAED;;;;;OAKG;IACK,MAAM,CAAC,KAAK,CAAC,mBAAmB,CACvC,kBAAyD;QAEzD,IAAI,EAAE,CAAC,KAAK,CAAoB,kBAAkB,CAAC,EAAE,CAAC;YACrD,MAAM,CAAC,KAAK,CACX,YAAY,CAAC,UAAU,wBAEvB,kBAAkB,CAClB,CAAC;YAEF,OAAO,kBAAkB,CAAC;QAC3B,CAAC;QAED,MAAM,CAAC,MAAM,CACZ,YAAY,CAAC,UAAU,wBAEvB,kBAAkB,CAClB,CAAC;QAEF,OAAO,eAAe,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;IACnD,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ArrayHelper, Guards, Is, type IValidationFailure } from \"@twin.org/core\";\nimport { DataTypeHelper, type ValidationMode } from \"@twin.org/data-core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { JsonLdProcessor } from \"./jsonLdProcessor.js\";\nimport type { IJsonLdDocument } from \"../models/IJsonLdDocument.js\";\nimport type { IJsonLdNodeObject } from \"../models/IJsonLdNodeObject.js\";\nimport type { IJsonLdNodePrimitive } from \"../models/IJsonLdNodePrimitive.js\";\n\n/**\n * Class to help with JSON LD.\n */\nexport class JsonLdHelper {\n\t/**\n\t * The class name.\n\t * @internal\n\t */\n\tpublic static readonly CLASS_NAME = nameof<JsonLdHelper>();\n\n\t/**\n\t * Validate a JSON-LD document.\n\t * @param document The JSON-LD document 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 document was valid.\n\t */\n\tpublic static async validate<T extends IJsonLdDocument = IJsonLdDocument>(\n\t\tdocument: T,\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\tif (Is.array<IJsonLdNodeObject>(document)) {\n\t\t\t// If the document is an array of nodes, validate each node\n\t\t\tfor (const node of document) {\n\t\t\t\tawait JsonLdHelper.validate(node, validationFailures, options);\n\t\t\t}\n\t\t} else if (Is.array<IJsonLdNodeObject>(document[\"@graph\"])) {\n\t\t\t// If the graph is an array of nodes, validate each node\n\t\t\tfor (const node of document[\"@graph\"]) {\n\t\t\t\tawait JsonLdHelper.validate(node, validationFailures, options);\n\t\t\t}\n\t\t} else if (Is.object<IJsonLdNodeObject>(document)) {\n\t\t\t// Expand the document to ensure we have the full context for types\n\t\t\t// As the data types in the factories are always fully qualified\n\t\t\tconst expandedDocs = await JsonLdProcessor.expand(document);\n\t\t\tif (Is.arrayValue(expandedDocs)) {\n\t\t\t\tfor (const expandedDoc of expandedDocs) {\n\t\t\t\t\tconst expandedDataTypes = ArrayHelper.fromObjectOrArray(expandedDoc[\"@type\"]);\n\t\t\t\t\tif (Is.arrayValue(expandedDataTypes)) {\n\t\t\t\t\t\tfor (const expandedDataType of expandedDataTypes) {\n\t\t\t\t\t\t\tawait DataTypeHelper.validate(\n\t\t\t\t\t\t\t\t\"document\",\n\t\t\t\t\t\t\t\texpandedDataType,\n\t\t\t\t\t\t\t\tdocument,\n\t\t\t\t\t\t\t\tvalidationFailures,\n\t\t\t\t\t\t\t\toptions\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn validationFailures.length === 0;\n\t}\n\n\t/**\n\t * Convert an object to a JSON-LD node object.\n\t * @param object The object to convert.\n\t * @returns The JSON-LD node object.\n\t */\n\tpublic static toNodeObject<T = unknown>(object: T): T & IJsonLdNodeObject {\n\t\tGuards.object<T>(JsonLdHelper.CLASS_NAME, nameof(object), object);\n\t\treturn object as T & IJsonLdNodeObject;\n\t}\n\n\t/**\n\t * Convert the JSON-LD node object to a structured object.\n\t * @param nodeObject The JSON-LD node object to convert.\n\t * @returns The structured object.\n\t */\n\tpublic static toStructuredObject<T = unknown>(nodeObject: IJsonLdNodeObject): T {\n\t\tGuards.object<IJsonLdNodeObject>(JsonLdHelper.CLASS_NAME, nameof(nodeObject), nodeObject);\n\t\treturn nodeObject as unknown as T;\n\t}\n\n\t/**\n\t * Expand the JSON-LD document.\n\t * @param document The JSON-LD document to expand.\n\t * @returns The expanded JSON-LD document.\n\t */\n\tpublic static async expand(document: IJsonLdDocument): Promise<IJsonLdNodeObject[]> {\n\t\tGuards.object<IJsonLdDocument>(JsonLdHelper.CLASS_NAME, nameof(document), document);\n\t\treturn JsonLdProcessor.expand(document);\n\t}\n\n\t/**\n\t * Expand the JSON-LD document and check if it is of a specific type.\n\t * @param documentOrExpanded The JSON-LD document to check or already expanded document.\n\t * @param type The type to check for.\n\t * @returns True if the document is of the specified type.\n\t */\n\tpublic static async isType(\n\t\tdocumentOrExpanded: IJsonLdDocument | IJsonLdNodeObject[],\n\t\ttype: string[]\n\t): Promise<boolean> {\n\t\tconst expanded = await JsonLdHelper.getExpandedDocument(documentOrExpanded);\n\t\tGuards.arrayValue(JsonLdHelper.CLASS_NAME, nameof(type), type);\n\n\t\tif (Is.arrayValue(expanded)) {\n\t\t\tfor (const item of expanded) {\n\t\t\t\tconst types = ArrayHelper.fromObjectOrArray(item[\"@type\"]);\n\t\t\t\tif (Is.arrayValue(types)) {\n\t\t\t\t\t// All required types must be present in this item's @type array\n\t\t\t\t\tconst itemTypes = new Set(types);\n\t\t\t\t\tif (type.every(t => itemTypes.has(t))) {\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn false;\n\t}\n\n\t/**\n\t * Get the types from the document.\n\t * @param documentOrExpanded The JSON-LD document to check or already expanded document.\n\t * @returns The type(s) extracted from the document.\n\t */\n\tpublic static async getType(\n\t\tdocumentOrExpanded: IJsonLdDocument | IJsonLdNodeObject[]\n\t): Promise<string[]> {\n\t\tconst expanded = await JsonLdHelper.getExpandedDocument(documentOrExpanded);\n\n\t\tconst types: Set<string> = new Set<string>();\n\t\tconst props = [\"@type\", \"type\"];\n\n\t\tfor (const expandedDoc of expanded) {\n\t\t\tfor (const prop of props) {\n\t\t\t\tconst expandedProps = ArrayHelper.fromObjectOrArray(expandedDoc[prop]);\n\t\t\t\tif (Is.arrayValue(expandedProps)) {\n\t\t\t\t\tfor (const expandedProp of expandedProps) {\n\t\t\t\t\t\tconst arr = ArrayHelper.fromObjectOrArray(expandedProp);\n\t\t\t\t\t\tfor (const arrValue of arr) {\n\t\t\t\t\t\t\tif (Is.stringValue(arrValue)) {\n\t\t\t\t\t\t\t\ttypes.add(arrValue);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn Array.from(types);\n\t}\n\n\t/**\n\t * Get the id from the document.\n\t * @param documentOrExpanded The JSON-LD document to get the id from or already expanded document.\n\t * @param additionalIdProperties Optional additional properties to check for the id, in addition to \"@id\" and \"id\".\n\t * @returns The id extracted from the document.\n\t */\n\tpublic static async getId(\n\t\tdocumentOrExpanded: IJsonLdDocument | IJsonLdNodeObject[],\n\t\tadditionalIdProperties?: string[]\n\t): Promise<string | undefined> {\n\t\tconst expanded = await JsonLdHelper.getExpandedDocument(documentOrExpanded);\n\n\t\tconst props = [\"@id\", \"id\", ...(additionalIdProperties ?? [])];\n\n\t\tfor (const expandedDoc of expanded) {\n\t\t\tfor (const prop of props) {\n\t\t\t\tconst expandedProps = ArrayHelper.fromObjectOrArray(expandedDoc[prop]);\n\t\t\t\tif (Is.arrayValue(expandedProps)) {\n\t\t\t\t\tfor (const expandedProp of expandedProps) {\n\t\t\t\t\t\tconst arr = ArrayHelper.fromObjectOrArray(expandedProp);\n\t\t\t\t\t\tfor (const arrValue of arr) {\n\t\t\t\t\t\t\tif (Is.stringValue(arrValue)) {\n\t\t\t\t\t\t\t\treturn arrValue;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Get property values by a single full expanded property name.\n\t * @param documentOrExpanded The JSON-LD document to get the property from or already expanded document.\n\t * @param propertyFullName The full expanded property name.\n\t * @param language Optional filter values by their language property.\n\t * @returns Matching property values for the input property.\n\t */\n\tpublic static async getPropertyValue(\n\t\tdocumentOrExpanded: IJsonLdDocument | IJsonLdNodeObject[],\n\t\tpropertyFullName: string,\n\t\tlanguage?: string\n\t): Promise<IJsonLdNodePrimitive[] | undefined> {\n\t\tconst results = await JsonLdHelper.getPropertyValues(\n\t\t\tdocumentOrExpanded,\n\t\t\t[propertyFullName],\n\t\t\tlanguage\n\t\t);\n\n\t\treturn results[0];\n\t}\n\n\t/**\n\t * Get property values by their full expanded property names.\n\t * @param documentOrExpanded The JSON-LD document to get the property from or already expanded document.\n\t * @param propertyFullNames The full expanded property names.\n\t * @param language Optional filter values by their language property.\n\t * @returns Matching property values for each input property, in the same index order.\n\t */\n\tpublic static async getPropertyValues(\n\t\tdocumentOrExpanded: IJsonLdDocument | IJsonLdNodeObject[],\n\t\tpropertyFullNames: string[],\n\t\tlanguage?: string\n\t): Promise<(IJsonLdNodePrimitive[] | undefined)[]> {\n\t\tconst expanded = await JsonLdHelper.getExpandedDocument(documentOrExpanded);\n\n\t\tGuards.arrayValue(JsonLdHelper.CLASS_NAME, nameof(propertyFullNames), propertyFullNames);\n\t\tif (Is.stringValue(language)) {\n\t\t\tGuards.stringValue(JsonLdHelper.CLASS_NAME, nameof(language), language);\n\t\t}\n\t\tconst languageLower = Is.stringValue(language) ? language.toLowerCase() : undefined;\n\t\tconst result: (IJsonLdNodePrimitive[] | undefined)[] = [];\n\n\t\tfor (const propertyFullName of propertyFullNames) {\n\t\t\tGuards.stringValue(JsonLdHelper.CLASS_NAME, nameof(propertyFullName), propertyFullName);\n\t\t\tconst values: IJsonLdNodePrimitive[] = [];\n\n\t\t\tfor (const expandedDoc of expanded) {\n\t\t\t\tconst propValue = expandedDoc[propertyFullName];\n\t\t\t\tif (!Is.empty(propValue)) {\n\t\t\t\t\tconst expandedProps = ArrayHelper.fromObjectOrArray(propValue);\n\t\t\t\t\tif (Is.arrayValue(expandedProps)) {\n\t\t\t\t\t\tfor (const expandedProp of expandedProps) {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tIs.object<{ \"@value\"?: IJsonLdNodePrimitive; \"@language\"?: string }>(expandedProp)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tif (!Is.empty(expandedProp[\"@value\"])) {\n\t\t\t\t\t\t\t\t\tlet shouldAdd = true;\n\t\t\t\t\t\t\t\t\tif (Is.stringValue(languageLower)) {\n\t\t\t\t\t\t\t\t\t\tconst itemLanguage = Is.stringValue(expandedProp[\"@language\"])\n\t\t\t\t\t\t\t\t\t\t\t? expandedProp[\"@language\"].toLowerCase()\n\t\t\t\t\t\t\t\t\t\t\t: undefined;\n\t\t\t\t\t\t\t\t\t\tshouldAdd = itemLanguage === languageLower;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif (shouldAdd) {\n\t\t\t\t\t\t\t\t\t\tvalues.push(expandedProp[\"@value\"]);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} else if (!Is.stringValue(languageLower)) {\n\t\t\t\t\t\t\t\t\tvalues.push(expandedProp);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\t\tIs.stringValue(expandedProp) ||\n\t\t\t\t\t\t\t\tIs.boolean(expandedProp) ||\n\t\t\t\t\t\t\t\tIs.number(expandedProp)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tif (!Is.stringValue(languageLower)) {\n\t\t\t\t\t\t\t\t\tvalues.push(expandedProp);\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}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tresult.push(values.length > 0 ? values : undefined);\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t/**\n\t * Prefix all properties in the document with the provided prefix, except for JSON-LD properties.\n\t * This is useful for ensuring that all properties are fully qualified with a namespace.\n\t * For example, if the prefix is \"ex\" and the document has a property \"name\", it will be transformed to \"ex:name\".\n\t * @param nodeObject The JSON-LD node object to prefix properties on.\n\t * @param prefix The prefix to add to the properties.\n\t * @param properties Optional list of properties to prefix. If not provided, all properties except for JSON-LD properties.\n\t * @returns A new JSON-LD node object with the properties prefixed.\n\t */\n\tpublic static prefixProperties<T extends IJsonLdNodeObject>(\n\t\tnodeObject: T,\n\t\tprefix: string,\n\t\tproperties?: string[]\n\t): IJsonLdNodeObject {\n\t\tGuards.object<IJsonLdNodeObject>(JsonLdHelper.CLASS_NAME, nameof(nodeObject), nodeObject);\n\t\tGuards.stringValue(JsonLdHelper.CLASS_NAME, nameof(prefix), prefix);\n\t\tconst normalizedPrefix = prefix.endsWith(\":\") ? prefix.slice(0, -1) : prefix;\n\t\tconst hasNoPropertiesFilter = !Is.arrayValue(properties);\n\n\t\tconst prefixedNodeObject: IJsonLdNodeObject = {};\n\n\t\tfor (const key in nodeObject) {\n\t\t\tconst value = nodeObject[key];\n\t\t\tif (\n\t\t\t\tIs.stringValue(key) &&\n\t\t\t\t!key.startsWith(\"@\") &&\n\t\t\t\t(hasNoPropertiesFilter || properties.includes(key))\n\t\t\t) {\n\t\t\t\tprefixedNodeObject[`${normalizedPrefix}:${key}`] = value;\n\t\t\t} else {\n\t\t\t\tprefixedNodeObject[key] = value;\n\t\t\t}\n\t\t}\n\n\t\treturn prefixedNodeObject;\n\t}\n\n\t/**\n\t * Strip a prefix from properties in the document, except for JSON-LD properties.\n\t * This is useful for converting fully qualified namespaced properties back to local names.\n\t * For example, if the prefix is \"ex\" and the document has a property \"ex:name\", it will be transformed to \"name\".\n\t * @param nodeObject The JSON-LD node object to strip prefixed properties from.\n\t * @param prefix The prefix to remove from the properties.\n\t * @param properties Optional list of unprefixed properties to strip. If not provided, all matching prefixed properties.\n\t * @returns A new JSON-LD node object with the prefix stripped from matching properties.\n\t */\n\tpublic static stripPrefixProperties<T extends IJsonLdNodeObject>(\n\t\tnodeObject: T,\n\t\tprefix: string,\n\t\tproperties?: string[]\n\t): IJsonLdNodeObject {\n\t\tGuards.object<IJsonLdNodeObject>(JsonLdHelper.CLASS_NAME, nameof(nodeObject), nodeObject);\n\t\tGuards.stringValue(JsonLdHelper.CLASS_NAME, nameof(prefix), prefix);\n\t\tconst normalizedPrefix = prefix.endsWith(\":\") ? prefix.slice(0, -1) : prefix;\n\t\tconst hasNoPropertiesFilter = !Is.arrayValue(properties);\n\n\t\tconst strippedNodeObject: IJsonLdNodeObject = {};\n\n\t\tfor (const key in nodeObject) {\n\t\t\tconst value = nodeObject[key];\n\t\t\tif (Is.stringValue(key) && !key.startsWith(\"@\") && key.startsWith(`${normalizedPrefix}:`)) {\n\t\t\t\tconst strippedKey = key.slice(normalizedPrefix.length + 1);\n\t\t\t\tif (hasNoPropertiesFilter || properties.includes(strippedKey)) {\n\t\t\t\t\tstrippedNodeObject[strippedKey] = value;\n\t\t\t\t} else {\n\t\t\t\t\tstrippedNodeObject[key] = value;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstrippedNodeObject[key] = value;\n\t\t\t}\n\t\t}\n\n\t\treturn strippedNodeObject;\n\t}\n\n\t/**\n\t * Get an expanded JSON-LD document from either compact or expanded input.\n\t * @param documentOrExpanded The JSON-LD document or expanded document.\n\t * @returns The expanded JSON-LD document.\n\t * @internal\n\t */\n\tprivate static async getExpandedDocument(\n\t\tdocumentOrExpanded: IJsonLdDocument | IJsonLdNodeObject[]\n\t): Promise<IJsonLdNodeObject[]> {\n\t\tif (Is.array<IJsonLdNodeObject>(documentOrExpanded)) {\n\t\t\tGuards.array<IJsonLdNodeObject>(\n\t\t\t\tJsonLdHelper.CLASS_NAME,\n\t\t\t\tnameof(documentOrExpanded),\n\t\t\t\tdocumentOrExpanded\n\t\t\t);\n\n\t\t\treturn documentOrExpanded;\n\t\t}\n\n\t\tGuards.object<IJsonLdDocument>(\n\t\t\tJsonLdHelper.CLASS_NAME,\n\t\t\tnameof(documentOrExpanded),\n\t\t\tdocumentOrExpanded\n\t\t);\n\n\t\treturn JsonLdProcessor.expand(documentOrExpanded);\n\t}\n}\n"]}