@3sixty/data-json-ld 0.0.0-stage → 0.20.0-next.1

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 (278) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +24 -2
  3. package/dist/es/compiled/validators.js +3895 -0
  4. package/dist/es/compiled/validators.js.map +1 -0
  5. package/dist/es/dataTypes/jsonLdDataTypes.js +170 -0
  6. package/dist/es/dataTypes/jsonLdDataTypes.js.map +1 -0
  7. package/dist/es/helpers/jsonLdAliasKey.js +4 -0
  8. package/dist/es/helpers/jsonLdAliasKey.js.map +1 -0
  9. package/dist/es/helpers/jsonLdExistingProperty.js +4 -0
  10. package/dist/es/helpers/jsonLdExistingProperty.js.map +1 -0
  11. package/dist/es/helpers/jsonLdExistingPropertyEither.js +2 -0
  12. package/dist/es/helpers/jsonLdExistingPropertyEither.js.map +1 -0
  13. package/dist/es/helpers/jsonLdKeys.js +4 -0
  14. package/dist/es/helpers/jsonLdKeys.js.map +1 -0
  15. package/dist/es/helpers/jsonLdObjectWithAliases.js +2 -0
  16. package/dist/es/helpers/jsonLdObjectWithAliases.js.map +1 -0
  17. package/dist/es/helpers/jsonLdObjectWithAtId.js +2 -0
  18. package/dist/es/helpers/jsonLdObjectWithAtId.js.map +1 -0
  19. package/dist/es/helpers/jsonLdObjectWithAtType.js +2 -0
  20. package/dist/es/helpers/jsonLdObjectWithAtType.js.map +1 -0
  21. package/dist/es/helpers/jsonLdObjectWithContext.js +2 -0
  22. package/dist/es/helpers/jsonLdObjectWithContext.js.map +1 -0
  23. package/dist/es/helpers/jsonLdObjectWithId.js +2 -0
  24. package/dist/es/helpers/jsonLdObjectWithId.js.map +1 -0
  25. package/dist/es/helpers/jsonLdObjectWithNoAtId.js +4 -0
  26. package/dist/es/helpers/jsonLdObjectWithNoAtId.js.map +1 -0
  27. package/dist/es/helpers/jsonLdObjectWithNoAtType.js +4 -0
  28. package/dist/es/helpers/jsonLdObjectWithNoAtType.js.map +1 -0
  29. package/dist/es/helpers/jsonLdObjectWithNoContext.js +4 -0
  30. package/dist/es/helpers/jsonLdObjectWithNoContext.js.map +1 -0
  31. package/dist/es/helpers/jsonLdObjectWithNoId.js +4 -0
  32. package/dist/es/helpers/jsonLdObjectWithNoId.js.map +1 -0
  33. package/dist/es/helpers/jsonLdObjectWithNoType.js +4 -0
  34. package/dist/es/helpers/jsonLdObjectWithNoType.js.map +1 -0
  35. package/dist/es/helpers/jsonLdObjectWithOptionalAtId.js +2 -0
  36. package/dist/es/helpers/jsonLdObjectWithOptionalAtId.js.map +1 -0
  37. package/dist/es/helpers/jsonLdObjectWithOptionalAtType.js +2 -0
  38. package/dist/es/helpers/jsonLdObjectWithOptionalAtType.js.map +1 -0
  39. package/dist/es/helpers/jsonLdObjectWithOptionalContext.js +2 -0
  40. package/dist/es/helpers/jsonLdObjectWithOptionalContext.js.map +1 -0
  41. package/dist/es/helpers/jsonLdObjectWithOptionalId.js +2 -0
  42. package/dist/es/helpers/jsonLdObjectWithOptionalId.js.map +1 -0
  43. package/dist/es/helpers/jsonLdObjectWithOptionalType.js +2 -0
  44. package/dist/es/helpers/jsonLdObjectWithOptionalType.js.map +1 -0
  45. package/dist/es/helpers/jsonLdObjectWithType.js +2 -0
  46. package/dist/es/helpers/jsonLdObjectWithType.js.map +1 -0
  47. package/dist/es/helpers/jsonLdOptionalKeys.js +4 -0
  48. package/dist/es/helpers/jsonLdOptionalKeys.js.map +1 -0
  49. package/dist/es/helpers/jsonLdRequiredKeys.js +2 -0
  50. package/dist/es/helpers/jsonLdRequiredKeys.js.map +1 -0
  51. package/dist/es/helpers/jsonLdWithAliases.js +2 -0
  52. package/dist/es/helpers/jsonLdWithAliases.js.map +1 -0
  53. package/dist/es/index.js +57 -0
  54. package/dist/es/index.js.map +1 -0
  55. package/dist/es/models/IJsonLdContainerType.js +4 -0
  56. package/dist/es/models/IJsonLdContainerType.js.map +1 -0
  57. package/dist/es/models/IJsonLdContainerTypeArray.js +2 -0
  58. package/dist/es/models/IJsonLdContainerTypeArray.js.map +1 -0
  59. package/dist/es/models/IJsonLdContextDefinition.js +2 -0
  60. package/dist/es/models/IJsonLdContextDefinition.js.map +1 -0
  61. package/dist/es/models/IJsonLdContextDefinitionElement.js +2 -0
  62. package/dist/es/models/IJsonLdContextDefinitionElement.js.map +1 -0
  63. package/dist/es/models/IJsonLdContextDefinitionRoot.js +2 -0
  64. package/dist/es/models/IJsonLdContextDefinitionRoot.js.map +1 -0
  65. package/dist/es/models/IJsonLdDocument.js +2 -0
  66. package/dist/es/models/IJsonLdDocument.js.map +1 -0
  67. package/dist/es/models/IJsonLdExpandedTermDefinition.js +2 -0
  68. package/dist/es/models/IJsonLdExpandedTermDefinition.js.map +1 -0
  69. package/dist/es/models/IJsonLdGraphObject.js +2 -0
  70. package/dist/es/models/IJsonLdGraphObject.js.map +1 -0
  71. package/dist/es/models/IJsonLdIdMap.js +2 -0
  72. package/dist/es/models/IJsonLdIdMap.js.map +1 -0
  73. package/dist/es/models/IJsonLdIncludedBlock.js +2 -0
  74. package/dist/es/models/IJsonLdIncludedBlock.js.map +1 -0
  75. package/dist/es/models/IJsonLdIndexMap.js +2 -0
  76. package/dist/es/models/IJsonLdIndexMap.js.map +1 -0
  77. package/dist/es/models/IJsonLdIndexMapItem.js +2 -0
  78. package/dist/es/models/IJsonLdIndexMapItem.js.map +1 -0
  79. package/dist/es/models/IJsonLdJsonArray.js +2 -0
  80. package/dist/es/models/IJsonLdJsonArray.js.map +1 -0
  81. package/dist/es/models/IJsonLdJsonObject.js +2 -0
  82. package/dist/es/models/IJsonLdJsonObject.js.map +1 -0
  83. package/dist/es/models/IJsonLdJsonPrimitive.js +4 -0
  84. package/dist/es/models/IJsonLdJsonPrimitive.js.map +1 -0
  85. package/dist/es/models/IJsonLdJsonValue.js +2 -0
  86. package/dist/es/models/IJsonLdJsonValue.js.map +1 -0
  87. package/dist/es/models/IJsonLdLanguageMap.js +4 -0
  88. package/dist/es/models/IJsonLdLanguageMap.js.map +1 -0
  89. package/dist/es/models/IJsonLdListObject.js +2 -0
  90. package/dist/es/models/IJsonLdListObject.js.map +1 -0
  91. package/dist/es/models/IJsonLdListOrSetItem.js +2 -0
  92. package/dist/es/models/IJsonLdListOrSetItem.js.map +1 -0
  93. package/dist/es/models/IJsonLdNodeObject.js +2 -0
  94. package/dist/es/models/IJsonLdNodeObject.js.map +1 -0
  95. package/dist/es/models/IJsonLdNodePrimitive.js +2 -0
  96. package/dist/es/models/IJsonLdNodePrimitive.js.map +1 -0
  97. package/dist/es/models/IJsonLdObject.js +2 -0
  98. package/dist/es/models/IJsonLdObject.js.map +1 -0
  99. package/dist/es/models/IJsonLdSetObject.js +2 -0
  100. package/dist/es/models/IJsonLdSetObject.js.map +1 -0
  101. package/dist/es/models/IJsonLdTypeMap.js +2 -0
  102. package/dist/es/models/IJsonLdTypeMap.js.map +1 -0
  103. package/dist/es/models/IJsonLdValueObject.js +2 -0
  104. package/dist/es/models/IJsonLdValueObject.js.map +1 -0
  105. package/dist/es/models/jsonLdContexts.js +21 -0
  106. package/dist/es/models/jsonLdContexts.js.map +1 -0
  107. package/dist/es/models/jsonLdTypes.js +113 -0
  108. package/dist/es/models/jsonLdTypes.js.map +1 -0
  109. package/dist/es/schemas/JsonLdContainerType.json +23 -0
  110. package/dist/es/schemas/JsonLdContainerTypeArray.json +166 -0
  111. package/dist/es/schemas/JsonLdContextDefinition.json +134 -0
  112. package/dist/es/schemas/JsonLdContextDefinitionElement.json +17 -0
  113. package/dist/es/schemas/JsonLdContextDefinitionRoot.json +17 -0
  114. package/dist/es/schemas/JsonLdDocument.json +48 -0
  115. package/dist/es/schemas/JsonLdExpandedTermDefinition.json +148 -0
  116. package/dist/es/schemas/JsonLdGraphObject.json +44 -0
  117. package/dist/es/schemas/JsonLdIdMap.json +10 -0
  118. package/dist/es/schemas/JsonLdIncludedBlock.json +17 -0
  119. package/dist/es/schemas/JsonLdIndexMap.json +20 -0
  120. package/dist/es/schemas/JsonLdIndexMapItem.json +32 -0
  121. package/dist/es/schemas/JsonLdJsonArray.json +10 -0
  122. package/dist/es/schemas/JsonLdJsonObject.json +10 -0
  123. package/dist/es/schemas/JsonLdJsonPrimitive.json +20 -0
  124. package/dist/es/schemas/JsonLdJsonValue.json +17 -0
  125. package/dist/es/schemas/JsonLdLanguageMap.json +23 -0
  126. package/dist/es/schemas/JsonLdListObject.json +28 -0
  127. package/dist/es/schemas/JsonLdListOrSetItem.json +26 -0
  128. package/dist/es/schemas/JsonLdNodeObject.json +40 -0
  129. package/dist/es/schemas/JsonLdNodePrimitive.json +35 -0
  130. package/dist/es/schemas/JsonLdObject.json +76 -0
  131. package/dist/es/schemas/JsonLdSetObject.json +28 -0
  132. package/dist/es/schemas/JsonLdTypeMap.json +17 -0
  133. package/dist/es/schemas/JsonLdValueObject.json +125 -0
  134. package/dist/es/utils/jsonLdHelper.js +301 -0
  135. package/dist/es/utils/jsonLdHelper.js.map +1 -0
  136. package/dist/es/utils/jsonLdProcessor.js +507 -0
  137. package/dist/es/utils/jsonLdProcessor.js.map +1 -0
  138. package/dist/types/compiled/validators.d.ts +101 -0
  139. package/dist/types/dataTypes/jsonLdDataTypes.d.ts +9 -0
  140. package/dist/types/helpers/jsonLdAliasKey.d.ts +4 -0
  141. package/dist/types/helpers/jsonLdExistingProperty.d.ts +6 -0
  142. package/dist/types/helpers/jsonLdExistingPropertyEither.d.ts +6 -0
  143. package/dist/types/helpers/jsonLdKeys.d.ts +4 -0
  144. package/dist/types/helpers/jsonLdObjectWithAliases.d.ts +7 -0
  145. package/dist/types/helpers/jsonLdObjectWithAtId.d.ts +7 -0
  146. package/dist/types/helpers/jsonLdObjectWithAtType.d.ts +7 -0
  147. package/dist/types/helpers/jsonLdObjectWithContext.d.ts +7 -0
  148. package/dist/types/helpers/jsonLdObjectWithId.d.ts +7 -0
  149. package/dist/types/helpers/jsonLdObjectWithNoAtId.d.ts +4 -0
  150. package/dist/types/helpers/jsonLdObjectWithNoAtType.d.ts +4 -0
  151. package/dist/types/helpers/jsonLdObjectWithNoContext.d.ts +5 -0
  152. package/dist/types/helpers/jsonLdObjectWithNoId.d.ts +4 -0
  153. package/dist/types/helpers/jsonLdObjectWithNoType.d.ts +4 -0
  154. package/dist/types/helpers/jsonLdObjectWithOptionalAtId.d.ts +7 -0
  155. package/dist/types/helpers/jsonLdObjectWithOptionalAtType.d.ts +7 -0
  156. package/dist/types/helpers/jsonLdObjectWithOptionalContext.d.ts +9 -0
  157. package/dist/types/helpers/jsonLdObjectWithOptionalId.d.ts +7 -0
  158. package/dist/types/helpers/jsonLdObjectWithOptionalType.d.ts +7 -0
  159. package/dist/types/helpers/jsonLdObjectWithType.d.ts +7 -0
  160. package/dist/types/helpers/jsonLdOptionalKeys.d.ts +6 -0
  161. package/dist/types/helpers/jsonLdRequiredKeys.d.ts +5 -0
  162. package/dist/types/helpers/jsonLdWithAliases.d.ts +13 -0
  163. package/dist/types/index.d.ts +54 -0
  164. package/dist/types/models/IJsonLdContainerType.d.ts +8 -0
  165. package/dist/types/models/IJsonLdContainerTypeArray.d.ts +9 -0
  166. package/dist/types/models/IJsonLdContextDefinition.d.ts +24 -0
  167. package/dist/types/models/IJsonLdContextDefinitionElement.d.ts +9 -0
  168. package/dist/types/models/IJsonLdContextDefinitionRoot.d.ts +9 -0
  169. package/dist/types/models/IJsonLdDocument.d.ts +17 -0
  170. package/dist/types/models/IJsonLdExpandedTermDefinition.d.ts +29 -0
  171. package/dist/types/models/IJsonLdGraphObject.d.ts +16 -0
  172. package/dist/types/models/IJsonLdIdMap.d.ts +12 -0
  173. package/dist/types/models/IJsonLdIncludedBlock.d.ts +10 -0
  174. package/dist/types/models/IJsonLdIndexMap.d.ts +13 -0
  175. package/dist/types/models/IJsonLdIndexMapItem.d.ts +12 -0
  176. package/dist/types/models/IJsonLdJsonArray.d.ts +9 -0
  177. package/dist/types/models/IJsonLdJsonObject.d.ts +11 -0
  178. package/dist/types/models/IJsonLdJsonPrimitive.d.ts +8 -0
  179. package/dist/types/models/IJsonLdJsonValue.d.ts +11 -0
  180. package/dist/types/models/IJsonLdLanguageMap.d.ts +11 -0
  181. package/dist/types/models/IJsonLdListObject.d.ts +13 -0
  182. package/dist/types/models/IJsonLdListOrSetItem.d.ts +10 -0
  183. package/dist/types/models/IJsonLdNodeObject.d.ts +19 -0
  184. package/dist/types/models/IJsonLdNodePrimitive.d.ts +13 -0
  185. package/dist/types/models/IJsonLdObject.d.ts +25 -0
  186. package/dist/types/models/IJsonLdSetObject.d.ts +13 -0
  187. package/dist/types/models/IJsonLdTypeMap.d.ts +12 -0
  188. package/dist/types/models/IJsonLdValueObject.d.ts +26 -0
  189. package/dist/types/models/jsonLdContexts.d.ts +21 -0
  190. package/dist/types/models/jsonLdTypes.d.ts +113 -0
  191. package/dist/types/utils/jsonLdHelper.d.ts +97 -0
  192. package/dist/types/utils/jsonLdProcessor.d.ts +117 -0
  193. package/docs/changelog.md +15 -0
  194. package/docs/examples.md +214 -0
  195. package/docs/reference/classes/JsonLdDataTypes.md +25 -0
  196. package/docs/reference/classes/JsonLdHelper.md +371 -0
  197. package/docs/reference/classes/JsonLdProcessor.md +400 -0
  198. package/docs/reference/index.md +93 -0
  199. package/docs/reference/interfaces/IJsonLdContextDefinition.md +73 -0
  200. package/docs/reference/interfaces/IJsonLdGraphObject.md +31 -0
  201. package/docs/reference/interfaces/IJsonLdIdMap.md +11 -0
  202. package/docs/reference/interfaces/IJsonLdIndexMap.md +12 -0
  203. package/docs/reference/interfaces/IJsonLdJsonObject.md +7 -0
  204. package/docs/reference/interfaces/IJsonLdLanguageMap.md +11 -0
  205. package/docs/reference/interfaces/IJsonLdListObject.md +19 -0
  206. package/docs/reference/interfaces/IJsonLdNodeObject.md +100 -0
  207. package/docs/reference/interfaces/IJsonLdObject.md +64 -0
  208. package/docs/reference/interfaces/IJsonLdSetObject.md +19 -0
  209. package/docs/reference/interfaces/IJsonLdTypeMap.md +11 -0
  210. package/docs/reference/type-aliases/IJsonLdContainerType.md +5 -0
  211. package/docs/reference/type-aliases/IJsonLdContainerTypeArray.md +5 -0
  212. package/docs/reference/type-aliases/IJsonLdContextDefinitionElement.md +5 -0
  213. package/docs/reference/type-aliases/IJsonLdContextDefinitionRoot.md +5 -0
  214. package/docs/reference/type-aliases/IJsonLdDocument.md +11 -0
  215. package/docs/reference/type-aliases/IJsonLdExpandedTermDefinition.md +41 -0
  216. package/docs/reference/type-aliases/IJsonLdIncludedBlock.md +9 -0
  217. package/docs/reference/type-aliases/IJsonLdIndexMapItem.md +5 -0
  218. package/docs/reference/type-aliases/IJsonLdJsonArray.md +5 -0
  219. package/docs/reference/type-aliases/IJsonLdJsonPrimitive.md +5 -0
  220. package/docs/reference/type-aliases/IJsonLdJsonValue.md +5 -0
  221. package/docs/reference/type-aliases/IJsonLdListOrSetItem.md +5 -0
  222. package/docs/reference/type-aliases/IJsonLdNodePrimitive.md +5 -0
  223. package/docs/reference/type-aliases/IJsonLdValueObject.md +20 -0
  224. package/docs/reference/type-aliases/JsonLdAliasKey.md +15 -0
  225. package/docs/reference/type-aliases/JsonLdContexts.md +5 -0
  226. package/docs/reference/type-aliases/JsonLdExistingProperty.md +19 -0
  227. package/docs/reference/type-aliases/JsonLdExistingPropertyEither.md +24 -0
  228. package/docs/reference/type-aliases/JsonLdKeys.md +11 -0
  229. package/docs/reference/type-aliases/JsonLdObjectWithAliases.md +16 -0
  230. package/docs/reference/type-aliases/JsonLdObjectWithAtId.md +21 -0
  231. package/docs/reference/type-aliases/JsonLdObjectWithAtType.md +21 -0
  232. package/docs/reference/type-aliases/JsonLdObjectWithContext.md +21 -0
  233. package/docs/reference/type-aliases/JsonLdObjectWithId.md +21 -0
  234. package/docs/reference/type-aliases/JsonLdObjectWithNoAtId.md +11 -0
  235. package/docs/reference/type-aliases/JsonLdObjectWithNoAtType.md +11 -0
  236. package/docs/reference/type-aliases/JsonLdObjectWithNoContext.md +12 -0
  237. package/docs/reference/type-aliases/JsonLdObjectWithNoId.md +11 -0
  238. package/docs/reference/type-aliases/JsonLdObjectWithNoType.md +11 -0
  239. package/docs/reference/type-aliases/JsonLdObjectWithOptionalAtId.md +21 -0
  240. package/docs/reference/type-aliases/JsonLdObjectWithOptionalAtType.md +21 -0
  241. package/docs/reference/type-aliases/JsonLdObjectWithOptionalContext.md +22 -0
  242. package/docs/reference/type-aliases/JsonLdObjectWithOptionalId.md +21 -0
  243. package/docs/reference/type-aliases/JsonLdObjectWithOptionalType.md +21 -0
  244. package/docs/reference/type-aliases/JsonLdObjectWithType.md +21 -0
  245. package/docs/reference/type-aliases/JsonLdOptionalKeys.md +11 -0
  246. package/docs/reference/type-aliases/JsonLdRequiredKeys.md +11 -0
  247. package/docs/reference/type-aliases/JsonLdTypes.md +5 -0
  248. package/docs/reference/type-aliases/JsonLdWithAliases.md +17 -0
  249. package/docs/reference/variables/CompiledJsonLdContainerType.md +5 -0
  250. package/docs/reference/variables/CompiledJsonLdContainerTypeArray.md +5 -0
  251. package/docs/reference/variables/CompiledJsonLdContextDefinition.md +5 -0
  252. package/docs/reference/variables/CompiledJsonLdContextDefinitionElement.md +5 -0
  253. package/docs/reference/variables/CompiledJsonLdContextDefinitionRoot.md +5 -0
  254. package/docs/reference/variables/CompiledJsonLdDocument.md +5 -0
  255. package/docs/reference/variables/CompiledJsonLdExpandedTermDefinition.md +5 -0
  256. package/docs/reference/variables/CompiledJsonLdGraphObject.md +5 -0
  257. package/docs/reference/variables/CompiledJsonLdIdMap.md +5 -0
  258. package/docs/reference/variables/CompiledJsonLdIncludedBlock.md +5 -0
  259. package/docs/reference/variables/CompiledJsonLdIndexMap.md +5 -0
  260. package/docs/reference/variables/CompiledJsonLdIndexMapItem.md +5 -0
  261. package/docs/reference/variables/CompiledJsonLdJsonArray.md +5 -0
  262. package/docs/reference/variables/CompiledJsonLdJsonObject.md +5 -0
  263. package/docs/reference/variables/CompiledJsonLdJsonPrimitive.md +5 -0
  264. package/docs/reference/variables/CompiledJsonLdJsonValue.md +5 -0
  265. package/docs/reference/variables/CompiledJsonLdLanguageMap.md +5 -0
  266. package/docs/reference/variables/CompiledJsonLdListObject.md +5 -0
  267. package/docs/reference/variables/CompiledJsonLdListOrSetItem.md +5 -0
  268. package/docs/reference/variables/CompiledJsonLdNodeObject.md +5 -0
  269. package/docs/reference/variables/CompiledJsonLdNodePrimitive.md +5 -0
  270. package/docs/reference/variables/CompiledJsonLdObject.md +5 -0
  271. package/docs/reference/variables/CompiledJsonLdSetObject.md +5 -0
  272. package/docs/reference/variables/CompiledJsonLdTypeMap.md +5 -0
  273. package/docs/reference/variables/CompiledJsonLdValueObject.md +5 -0
  274. package/docs/reference/variables/JsonLdContexts.md +25 -0
  275. package/docs/reference/variables/JsonLdTypes.md +163 -0
  276. package/locales/.validate-ignore +1 -0
  277. package/locales/en.json +11 -0
  278. package/package.json +52 -5
@@ -0,0 +1,507 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { BaseError, GeneralError, Is, ObjectHelper, SharedStore } from "@3sixty/core";
4
+ import { FetchHelper, HeaderHelper, HeaderTypes, HttpLinkRelType, HttpMethod, HttpStatusCode, MimeTypes } from "@3sixty/web";
5
+ import jsonLd from "jsonld";
6
+ /**
7
+ * JSON-LD Processor.
8
+ */
9
+ export class JsonLdProcessor {
10
+ /**
11
+ * The class name.
12
+ * @internal
13
+ */
14
+ static CLASS_NAME = "JsonLdProcessor";
15
+ /**
16
+ * Maximum number of HTTP Link-header discovery hops (namespace URL → context document).
17
+ * @internal
18
+ */
19
+ static _MAX_LINK_DISCOVERY_DEPTH = 1;
20
+ /**
21
+ * Properties that must always be arrays after compaction, regardless of the compactArrays option.
22
+ * @internal
23
+ */
24
+ static _NO_COMPACT_ARRAY_PROPERTIES = new Set([
25
+ "itemListElement"
26
+ ]);
27
+ /**
28
+ * Set the document loader used for retrieving JSON-LD documents.
29
+ * @param documentLoader The document loader to use.
30
+ */
31
+ static setDocumentLoader(documentLoader) {
32
+ SharedStore.set("jsonLdDocumentLoader", documentLoader);
33
+ }
34
+ /**
35
+ * Get the document loader used for retrieving JSON-LD documents.
36
+ * @returns The active document loader function.
37
+ */
38
+ static getDocumentLoader() {
39
+ let documentLoader = SharedStore.get("jsonLdDocumentLoader");
40
+ if (!Is.function(documentLoader)) {
41
+ documentLoader = async (url) => JsonLdProcessor.documentLoader(url);
42
+ }
43
+ return documentLoader;
44
+ }
45
+ /**
46
+ * Set the cache time limit for documents.
47
+ * @param cacheLimitMs The cache limit in milliseconds.
48
+ */
49
+ static setCacheLimit(cacheLimitMs) {
50
+ SharedStore.set("jsonLdDocumentCacheLimit", cacheLimitMs);
51
+ }
52
+ /**
53
+ * Get the cache limit for documents.
54
+ * @returns The cache limit in milliseconds.
55
+ */
56
+ static getCacheLimit() {
57
+ return SharedStore.get("jsonLdDocumentCacheLimit", () => 3600000);
58
+ }
59
+ /**
60
+ * Replace the global redirect list (use {@link JsonLdProcessor.addRedirect} to append without replacing).
61
+ * Redirects run before any HTTP GET or `Link` discovery; use them for stable overrides, tests, or hosts that do not expose a suitable `Link` header.
62
+ * @param redirects The redirects to use.
63
+ */
64
+ static setRedirects(redirects) {
65
+ SharedStore.set("jsonLdRedirects", redirects);
66
+ }
67
+ /**
68
+ * Get the global redirects for JSON-LD.
69
+ * @returns The registered redirects.
70
+ */
71
+ static getRedirects() {
72
+ return SharedStore.get("jsonLdRedirects", () => []);
73
+ }
74
+ /**
75
+ * Append a redirect rule (ignored if the same `RegExp.source` is already registered).
76
+ * Optional when the vocabulary URL supports HTTP `Link` discovery (`rel` includes `alternate`, `type` is `application/ld+json`) via the default document loader.
77
+ * Standards packages often expose `registerRedirects()` helpers that call this method; those are optional for the same reason.
78
+ * @param from The URL to redirect from.
79
+ * @param to The URL to redirect to.
80
+ */
81
+ static addRedirect(from, to) {
82
+ const redirects = JsonLdProcessor.getRedirects();
83
+ if (!redirects.some(r => r.from.source === from.source)) {
84
+ redirects.push({ from, to });
85
+ }
86
+ }
87
+ /**
88
+ * Compact a document according to a particular context.
89
+ * @param document The JSON-LD document to compact.
90
+ * @param context The context to compact the document to, if not provided will use the one in the document.
91
+ * @param options The options for compacting the document.
92
+ * @param options.compactArrays Whether to allow single-item arrays to be compacted to scalars, defaults to true (matches jsonld.js default behaviour). Set to false to preserve all single-item arrays.
93
+ * @param options.noCompactProperties Additional dot-notation property paths that must always remain arrays, merged with the built-in always-array set.
94
+ * @returns The compacted JSON-LD document.
95
+ */
96
+ static async compact(document, context, options) {
97
+ try {
98
+ if (Is.object(document)) {
99
+ // If the user didn't provide a context, use the one from the document
100
+ if (Is.empty(context) && !Is.empty(document["@context"])) {
101
+ context = document["@context"];
102
+ }
103
+ const pathsToRestore = new Set(JsonLdProcessor._NO_COMPACT_ARRAY_PROPERTIES);
104
+ if (Is.arrayValue(options?.noCompactProperties)) {
105
+ for (const p of options.noCompactProperties) {
106
+ pathsToRestore.add(p);
107
+ }
108
+ }
109
+ if (!(options?.compactArrays ?? true)) {
110
+ JsonLdProcessor.gatherArrayPropertyPaths(document, pathsToRestore);
111
+ }
112
+ const compacted = await jsonLd.compact(ObjectHelper.removeEmptyProperties(document), context, {
113
+ documentLoader: JsonLdProcessor.getDocumentLoader()
114
+ });
115
+ JsonLdProcessor.expandArrayProperties(compacted, pathsToRestore);
116
+ return compacted;
117
+ }
118
+ return document;
119
+ }
120
+ catch (err) {
121
+ JsonLdProcessor.handleCommonErrors(err);
122
+ throw new GeneralError(JsonLdProcessor.CLASS_NAME, "compact", undefined, err);
123
+ }
124
+ }
125
+ /**
126
+ * Expand a document, removing its context.
127
+ * @param compacted The compacted JSON-LD document to expand.
128
+ * @returns The expanded JSON-LD document.
129
+ */
130
+ static async expand(compacted) {
131
+ try {
132
+ if (Is.object(compacted)) {
133
+ const expanded = await jsonLd.expand(ObjectHelper.removeEmptyProperties(compacted), {
134
+ documentLoader: JsonLdProcessor.getDocumentLoader()
135
+ });
136
+ return expanded;
137
+ }
138
+ return [];
139
+ }
140
+ catch (err) {
141
+ JsonLdProcessor.handleCommonErrors(err);
142
+ throw new GeneralError(JsonLdProcessor.CLASS_NAME, "expand", undefined, err);
143
+ }
144
+ }
145
+ /**
146
+ * Canonize a document.
147
+ * @param document The document to canonize.
148
+ * @param options The options for canonization.
149
+ * @param options.algorithm The algorithm to use for canonization, defaults to URDNA2015.
150
+ * @returns The canonized document.
151
+ */
152
+ static async canonize(document, options) {
153
+ try {
154
+ const normalized = await jsonLd.canonize(ObjectHelper.removeEmptyProperties(document), {
155
+ algorithm: options?.algorithm ?? "URDNA2015",
156
+ format: "application/n-quads",
157
+ documentLoader: JsonLdProcessor.getDocumentLoader()
158
+ });
159
+ return normalized;
160
+ }
161
+ catch (err) {
162
+ JsonLdProcessor.handleCommonErrors(err);
163
+ throw new GeneralError(JsonLdProcessor.CLASS_NAME, "canonize", undefined, err);
164
+ }
165
+ }
166
+ /**
167
+ * Combine contexts.
168
+ * @param context1 The first JSON-LD context to combine.
169
+ * @param context2 The second JSON-LD context to combine.
170
+ * @returns The combined context.
171
+ */
172
+ static combineContexts(context1, context2) {
173
+ const combinedContext = [];
174
+ if (Is.string(context1)) {
175
+ if (!combinedContext.includes(context1)) {
176
+ combinedContext.push(context1);
177
+ }
178
+ }
179
+ else if (Is.array(context1)) {
180
+ for (const context of context1) {
181
+ const hasMatch = combinedContext.some(c => ObjectHelper.equal(c, context));
182
+ if (!hasMatch) {
183
+ combinedContext.push(context);
184
+ }
185
+ }
186
+ }
187
+ else if (Is.object(context1)) {
188
+ const hasMatch = combinedContext.some(c => ObjectHelper.equal(c, context1));
189
+ if (!hasMatch) {
190
+ combinedContext.push(context1);
191
+ }
192
+ }
193
+ if (Is.string(context2)) {
194
+ if (!combinedContext.includes(context2)) {
195
+ combinedContext.push(context2);
196
+ }
197
+ }
198
+ else if (Is.array(context2)) {
199
+ for (const context of context2) {
200
+ const hasMatch = combinedContext.some(c => ObjectHelper.equal(c, context));
201
+ if (!hasMatch) {
202
+ combinedContext.push(context);
203
+ }
204
+ }
205
+ }
206
+ else if (Is.object(context2)) {
207
+ const hasMatch = combinedContext.some(c => ObjectHelper.equal(c, context2));
208
+ if (!hasMatch) {
209
+ combinedContext.push(context2);
210
+ }
211
+ }
212
+ if (combinedContext.length === 0) {
213
+ return null;
214
+ }
215
+ if (combinedContext.length === 1) {
216
+ return combinedContext[0];
217
+ }
218
+ return combinedContext;
219
+ }
220
+ /**
221
+ * Gather all the contexts from the element and it's children.
222
+ * @param element The element to gather the contexts from.
223
+ * @param initial The initial context.
224
+ * @returns The combined contexts.
225
+ */
226
+ static gatherContexts(element, initial) {
227
+ let combinedContexts = initial;
228
+ if (Is.object(element)) {
229
+ if (!Is.empty(element["@context"])) {
230
+ combinedContexts = JsonLdProcessor.combineContexts(initial, element["@context"]);
231
+ }
232
+ for (const prop of Object.keys(element)) {
233
+ const value = element[prop];
234
+ if (Is.object(value)) {
235
+ combinedContexts = JsonLdProcessor.gatherContexts(value, combinedContexts);
236
+ }
237
+ else if (Is.array(value)) {
238
+ for (const item of value) {
239
+ if (Is.object(item)) {
240
+ combinedContexts = JsonLdProcessor.gatherContexts(item, combinedContexts);
241
+ }
242
+ }
243
+ }
244
+ }
245
+ }
246
+ return combinedContexts;
247
+ }
248
+ /**
249
+ * Remove all the contexts that match the pattern.
250
+ * @param context The context to remove the entries from.
251
+ * @param match The element to try and match.
252
+ * @returns The updated contexts.
253
+ */
254
+ static removeContexts(context, match) {
255
+ if (!Is.arrayValue(match)) {
256
+ return context;
257
+ }
258
+ let finalContext;
259
+ if (Is.string(context)) {
260
+ for (const m of match) {
261
+ if (context === m) {
262
+ break;
263
+ }
264
+ }
265
+ }
266
+ else if (Is.array(context)) {
267
+ for (const item of context) {
268
+ const hasMatch = match.some(m => ObjectHelper.equal(m, item));
269
+ if (!hasMatch) {
270
+ finalContext ??= [];
271
+ if (Is.array(finalContext)) {
272
+ finalContext.push(item);
273
+ }
274
+ }
275
+ }
276
+ }
277
+ else if (Is.object(context)) {
278
+ const hasMatch = match.some(m => ObjectHelper.equal(m, context));
279
+ if (!hasMatch) {
280
+ finalContext = context;
281
+ }
282
+ }
283
+ return Is.arrayValue(finalContext) && finalContext.length === 1
284
+ ? finalContext[0]
285
+ : finalContext;
286
+ }
287
+ /**
288
+ * Add a context directly to the document loader cache.
289
+ * @param url The url the ld context is for.
290
+ * @param ldContext The context to add.
291
+ * @returns A promise that resolves when the entry has been stored in the cache.
292
+ */
293
+ static async documentCacheAdd(url, ldContext) {
294
+ await FetchHelper.setCacheEntry(url, ldContext);
295
+ }
296
+ /**
297
+ * Remove a context from the document loader cache.
298
+ * @param url The url the ld context is for.
299
+ * @returns A promise that resolves when the entry has been removed from the cache.
300
+ */
301
+ static async documentCacheRemove(url) {
302
+ FetchHelper.removeCacheEntry(url);
303
+ }
304
+ /**
305
+ * Document loader which uses a caching mechanism.
306
+ * @param url The document url to load.
307
+ * @returns The document.
308
+ * @internal
309
+ */
310
+ static async documentLoader(url) {
311
+ const redirects = JsonLdProcessor.getRedirects();
312
+ for (const redirect of redirects) {
313
+ if (redirect.from.test(url)) {
314
+ url = redirect.to;
315
+ break;
316
+ }
317
+ }
318
+ return JsonLdProcessor.fetchRemoteJsonLdDocument(url, 0);
319
+ }
320
+ /**
321
+ * True when FetchHelper failed to decode JSON from the response (e.g. HTML or plain text).
322
+ * @param err The error from fetchJson.
323
+ * @returns True if the error is a JSON decode failure, false otherwise.
324
+ * @internal
325
+ */
326
+ static isFetchJsonDecodeFailure(err) {
327
+ // Raw JSON.parse / response.json() failures (FetchHelper may rethrow as FetchError with cause,
328
+ // or propagate SyntaxError when error-response body is not JSON).
329
+ const error = BaseError.fromError(err);
330
+ if (error.name === "SyntaxError" || error.cause?.name === "SyntaxError") {
331
+ return true;
332
+ }
333
+ return error.message.includes("decodingJSON") || error.message.includes("is not valid JSON");
334
+ }
335
+ /**
336
+ * Use HTTP Link (rel=alternate, type=application/ld+json) to discover a JSON-LD context URL.
337
+ * @param sourceUrl URL that did not yield JSON (e.g. vocabulary namespace HTML page).
338
+ * @returns Absolute context document URL, or undefined.
339
+ * @internal
340
+ */
341
+ static async tryDiscoverAlternateJsonLdContextUrl(sourceUrl) {
342
+ const fetchOpts = {
343
+ timeoutMs: 30_000,
344
+ headers: {
345
+ [HeaderTypes.Accept]: `${MimeTypes.JsonLd},${MimeTypes.Json};q=0.9,*/*;q=0.8`
346
+ }
347
+ };
348
+ let response = await FetchHelper.fetch(JsonLdProcessor.CLASS_NAME, sourceUrl, HttpMethod.HEAD, undefined, fetchOpts);
349
+ if (response.status === HttpStatusCode.methodNotAllowed ||
350
+ response.status === HttpStatusCode.notImplemented) {
351
+ response = await FetchHelper.fetch(JsonLdProcessor.CLASS_NAME, sourceUrl, HttpMethod.GET, undefined, fetchOpts);
352
+ await response.arrayBuffer();
353
+ }
354
+ if (!response.ok) {
355
+ return undefined;
356
+ }
357
+ const linkHeader = response.headers.get(HeaderTypes.Link);
358
+ if (Is.empty(linkHeader)) {
359
+ return undefined;
360
+ }
361
+ // response.url is "" for many mocked/synthetic Responses; Is.empty("") is false, but
362
+ // new URL(absoluteHref, "") throws - use a non-empty resolved URL as base only.
363
+ const baseUrl = Is.stringValue(response.url) ? response.url : sourceUrl;
364
+ const alternateLinkHeaders = HeaderHelper.extractLinkHeaderRelations(linkHeader, HttpLinkRelType.alternate);
365
+ if (Is.arrayValue(alternateLinkHeaders)) {
366
+ for (const alternateLinkHeader of alternateLinkHeaders) {
367
+ if (alternateLinkHeader.params?.type === MimeTypes.JsonLd) {
368
+ try {
369
+ return new URL(alternateLinkHeader.url, baseUrl).href;
370
+ }
371
+ catch {
372
+ // Malformed URL for this segment; try the next Link segment.
373
+ }
374
+ }
375
+ }
376
+ }
377
+ return undefined;
378
+ }
379
+ /**
380
+ * Fetch a remote JSON-LD document, with Accept fallbacks and optional Link-header discovery.
381
+ * @param url Resolved document URL.
382
+ * @param linkDiscoveryDepth Current discovery recursion depth.
383
+ * @returns The fetched remote JSON-LD document.
384
+ * @internal
385
+ */
386
+ static async fetchRemoteJsonLdDocument(url, linkDiscoveryDepth) {
387
+ const cacheTtlMs = JsonLdProcessor.getCacheLimit();
388
+ const fetchJsonLdOptions = {
389
+ cacheTtlMs,
390
+ headers: {
391
+ [HeaderTypes.Accept]: MimeTypes.JsonLd
392
+ }
393
+ };
394
+ const fetchJsonOptions = {
395
+ cacheTtlMs,
396
+ headers: {
397
+ [HeaderTypes.Accept]: MimeTypes.Json
398
+ }
399
+ };
400
+ try {
401
+ const document = await FetchHelper.fetchJson(JsonLdProcessor.CLASS_NAME, url, HttpMethod.GET, undefined, fetchJsonLdOptions);
402
+ return {
403
+ documentUrl: url,
404
+ document
405
+ };
406
+ }
407
+ catch (errLd) {
408
+ if (JsonLdProcessor.isFetchJsonDecodeFailure(errLd)) {
409
+ try {
410
+ const document = await FetchHelper.fetchJson(JsonLdProcessor.CLASS_NAME, url, HttpMethod.GET, undefined, fetchJsonOptions);
411
+ return {
412
+ documentUrl: url,
413
+ document
414
+ };
415
+ }
416
+ catch (errJson) {
417
+ if (linkDiscoveryDepth < JsonLdProcessor._MAX_LINK_DISCOVERY_DEPTH &&
418
+ JsonLdProcessor.isFetchJsonDecodeFailure(errJson)) {
419
+ const discovered = await JsonLdProcessor.tryDiscoverAlternateJsonLdContextUrl(url);
420
+ if (Is.stringValue(discovered) && discovered !== url) {
421
+ return JsonLdProcessor.fetchRemoteJsonLdDocument(discovered, linkDiscoveryDepth + 1);
422
+ }
423
+ }
424
+ throw errJson;
425
+ }
426
+ }
427
+ throw errLd;
428
+ }
429
+ }
430
+ /**
431
+ * Recursively collect dot-notation paths of all single-element array properties in an object,
432
+ * skipping JSON-LD keywords (keys starting with "@"). Paths are added to the provided set.
433
+ * @param obj The object to scan.
434
+ * @param arrayPaths The accumulator set to add discovered paths to.
435
+ * @param prefix The dot-path prefix accumulated from parent calls.
436
+ * @internal
437
+ */
438
+ static gatherArrayPropertyPaths(obj, arrayPaths, prefix = "") {
439
+ for (const key of Object.keys(obj)) {
440
+ if (!key.startsWith("@")) {
441
+ const path = prefix.length > 0 ? `${prefix}.${key}` : key;
442
+ const value = obj[key];
443
+ if (Is.array(value)) {
444
+ if (value.length === 1) {
445
+ arrayPaths.add(path);
446
+ }
447
+ for (const item of value) {
448
+ if (Is.object(item)) {
449
+ JsonLdProcessor.gatherArrayPropertyPaths(item, arrayPaths, path);
450
+ }
451
+ }
452
+ }
453
+ else if (Is.object(value)) {
454
+ JsonLdProcessor.gatherArrayPropertyPaths(value, arrayPaths, path);
455
+ }
456
+ }
457
+ }
458
+ }
459
+ /**
460
+ * Recursively ensure that properties identified by dot-notation paths are arrays.
461
+ * Properties that were collapsed to a single value during compaction are wrapped back into an array.
462
+ * @param obj The object to update in place.
463
+ * @param arrayPaths The set of dot-notation paths that must remain arrays.
464
+ * @param prefix The dot-path prefix accumulated from parent calls.
465
+ * @internal
466
+ */
467
+ static expandArrayProperties(obj, arrayPaths, prefix = "") {
468
+ for (const key of Object.keys(obj)) {
469
+ if (!key.startsWith("@")) {
470
+ const path = prefix.length > 0 ? `${prefix}.${key}` : key;
471
+ const value = obj[key];
472
+ if (arrayPaths.has(path) && !Is.array(value)) {
473
+ obj[key] = [value];
474
+ }
475
+ const current = obj[key];
476
+ if (Is.array(current)) {
477
+ for (const item of current) {
478
+ if (Is.object(item)) {
479
+ JsonLdProcessor.expandArrayProperties(item, arrayPaths, path);
480
+ }
481
+ }
482
+ }
483
+ else if (Is.object(current)) {
484
+ JsonLdProcessor.expandArrayProperties(current, arrayPaths, path);
485
+ }
486
+ }
487
+ }
488
+ }
489
+ /**
490
+ * Handle common errors.
491
+ * @param err The error to handle.
492
+ * @throws GeneralError if the error is a known JSON-LD error type.
493
+ * @internal
494
+ */
495
+ static handleCommonErrors(err) {
496
+ if (Is.object(err) &&
497
+ err.name === "jsonld.InvalidUrl") {
498
+ throw new GeneralError(JsonLdProcessor.CLASS_NAME, "invalidUrl", { url: err.details?.url }, err);
499
+ }
500
+ else if (Is.object(err) &&
501
+ err.name.startsWith("jsonld.")) {
502
+ const { code, ...other } = err.details ?? {};
503
+ throw new GeneralError(JsonLdProcessor.CLASS_NAME, "jsonLdError", { code, ...other }, err);
504
+ }
505
+ }
506
+ }
507
+ //# sourceMappingURL=jsonLdProcessor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonLdProcessor.js","sourceRoot":"","sources":["../../../src/utils/jsonLdProcessor.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,EAAE,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEtF,OAAO,EACN,WAAW,EACX,YAAY,EACZ,WAAW,EACX,eAAe,EACf,UAAU,EACV,cAAc,EACd,SAAS,EACT,MAAM,aAAa,CAAC;AACrB,OAAO,MAAM,MAAM,QAAQ,CAAC;AAO5B;;GAEG;AACH,MAAM,OAAO,eAAe;IAC3B;;;OAGG;IACI,MAAM,CAAU,UAAU,qBAA6B;IAE9D;;;OAGG;IACK,MAAM,CAAU,yBAAyB,GAAG,CAAC,CAAC;IAEtD;;;OAGG;IACK,MAAM,CAAU,4BAA4B,GAAwB,IAAI,GAAG,CAAC;QACnF,iBAAiB;KACjB,CAAC,CAAC;IAEH;;;OAGG;IACI,MAAM,CAAC,iBAAiB,CAAC,cAAqD;QACpF,WAAW,CAAC,GAAG,CAAC,sBAAsB,EAAE,cAAc,CAAC,CAAC;IACzD,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,iBAAiB;QAC9B,IAAI,cAAc,GACjB,WAAW,CAAC,GAAG,CAAwC,sBAAsB,CAAC,CAAC;QAChF,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;YAClC,cAAc,GAAG,KAAK,EAAE,GAAW,EAAE,EAAE,CAAC,eAAe,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;QAC7E,CAAC;QACD,OAAO,cAAc,CAAC;IACvB,CAAC;IAED;;;OAGG;IACI,MA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E,GAAG,CAAC,CAAC;QAC5F,CAAC;IACF,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { BaseError, GeneralError, Is, ObjectHelper, SharedStore } from \"@3sixty/core\";\nimport { nameof } from \"@3sixty/nameof\";\nimport {\n\tFetchHelper,\n\tHeaderHelper,\n\tHeaderTypes,\n\tHttpLinkRelType,\n\tHttpMethod,\n\tHttpStatusCode,\n\tMimeTypes\n} from \"@3sixty/web\";\nimport jsonLd from \"jsonld\";\nimport type { JsonLd, RemoteDocument, Url } from \"jsonld/jsonld-spec.js\";\nimport type { IJsonLdContextDefinition } from \"../models/IJsonLdContextDefinition.js\";\nimport type { IJsonLdContextDefinitionElement } from \"../models/IJsonLdContextDefinitionElement.js\";\nimport type { IJsonLdContextDefinitionRoot } from \"../models/IJsonLdContextDefinitionRoot.js\";\nimport type { IJsonLdNodeObject } from \"../models/IJsonLdNodeObject.js\";\n\n/**\n * JSON-LD Processor.\n */\nexport class JsonLdProcessor {\n\t/**\n\t * The class name.\n\t * @internal\n\t */\n\tpublic static readonly CLASS_NAME = nameof<JsonLdProcessor>();\n\n\t/**\n\t * Maximum number of HTTP Link-header discovery hops (namespace URL → context document).\n\t * @internal\n\t */\n\tprivate static readonly _MAX_LINK_DISCOVERY_DEPTH = 1;\n\n\t/**\n\t * Properties that must always be arrays after compaction, regardless of the compactArrays option.\n\t * @internal\n\t */\n\tprivate static readonly _NO_COMPACT_ARRAY_PROPERTIES: ReadonlySet<string> = new Set([\n\t\t\"itemListElement\"\n\t]);\n\n\t/**\n\t * Set the document loader used for retrieving JSON-LD documents.\n\t * @param documentLoader The document loader to use.\n\t */\n\tpublic static setDocumentLoader(documentLoader: (url: Url) => Promise<RemoteDocument>): void {\n\t\tSharedStore.set(\"jsonLdDocumentLoader\", documentLoader);\n\t}\n\n\t/**\n\t * Get the document loader used for retrieving JSON-LD documents.\n\t * @returns The active document loader function.\n\t */\n\tpublic static getDocumentLoader(): (url: Url) => Promise<RemoteDocument> {\n\t\tlet documentLoader =\n\t\t\tSharedStore.get<(url: Url) => Promise<RemoteDocument>>(\"jsonLdDocumentLoader\");\n\t\tif (!Is.function(documentLoader)) {\n\t\t\tdocumentLoader = async (url: string) => JsonLdProcessor.documentLoader(url);\n\t\t}\n\t\treturn documentLoader;\n\t}\n\n\t/**\n\t * Set the cache time limit for documents.\n\t * @param cacheLimitMs The cache limit in milliseconds.\n\t */\n\tpublic static setCacheLimit(cacheLimitMs: number): void {\n\t\tSharedStore.set(\"jsonLdDocumentCacheLimit\", cacheLimitMs);\n\t}\n\n\t/**\n\t * Get the cache limit for documents.\n\t * @returns The cache limit in milliseconds.\n\t */\n\tpublic static getCacheLimit(): number {\n\t\treturn SharedStore.get<number>(\"jsonLdDocumentCacheLimit\", () => 3600000);\n\t}\n\n\t/**\n\t * Replace the global redirect list (use {@link JsonLdProcessor.addRedirect} to append without replacing).\n\t * Redirects run before any HTTP GET or `Link` discovery; use them for stable overrides, tests, or hosts that do not expose a suitable `Link` header.\n\t * @param redirects The redirects to use.\n\t */\n\tpublic static setRedirects(\n\t\tredirects: {\n\t\t\tfrom: RegExp;\n\t\t\tto: string;\n\t\t}[]\n\t): void {\n\t\tSharedStore.set(\"jsonLdRedirects\", redirects);\n\t}\n\n\t/**\n\t * Get the global redirects for JSON-LD.\n\t * @returns The registered redirects.\n\t */\n\tpublic static getRedirects(): {\n\t\tfrom: RegExp;\n\t\tto: string;\n\t}[] {\n\t\treturn SharedStore.get<\n\t\t\t{\n\t\t\t\tfrom: RegExp;\n\t\t\t\tto: string;\n\t\t\t}[]\n\t\t>(\"jsonLdRedirects\", () => []);\n\t}\n\n\t/**\n\t * Append a redirect rule (ignored if the same `RegExp.source` is already registered).\n\t * Optional when the vocabulary URL supports HTTP `Link` discovery (`rel` includes `alternate`, `type` is `application/ld+json`) via the default document loader.\n\t * Standards packages often expose `registerRedirects()` helpers that call this method; those are optional for the same reason.\n\t * @param from The URL to redirect from.\n\t * @param to The URL to redirect to.\n\t */\n\tpublic static addRedirect(from: RegExp, to: string): void {\n\t\tconst redirects = JsonLdProcessor.getRedirects();\n\t\tif (!redirects.some(r => r.from.source === from.source)) {\n\t\t\tredirects.push({ from, to });\n\t\t}\n\t}\n\n\t/**\n\t * Compact a document according to a particular context.\n\t * @param document The JSON-LD document to compact.\n\t * @param context The context to compact the document to, if not provided will use the one in the document.\n\t * @param options The options for compacting the document.\n\t * @param options.compactArrays Whether to allow single-item arrays to be compacted to scalars, defaults to true (matches jsonld.js default behaviour). Set to false to preserve all single-item arrays.\n\t * @param options.noCompactProperties Additional dot-notation property paths that must always remain arrays, merged with the built-in always-array set.\n\t * @returns The compacted JSON-LD document.\n\t */\n\tpublic static async compact<T>(\n\t\tdocument: T,\n\t\tcontext?: IJsonLdContextDefinitionRoot,\n\t\toptions?: { compactArrays?: boolean; noCompactProperties?: string[] }\n\t): Promise<T> {\n\t\ttry {\n\t\t\tif (Is.object<IJsonLdNodeObject>(document)) {\n\t\t\t\t// If the user didn't provide a context, use the one from the document\n\t\t\t\tif (Is.empty(context) && !Is.empty(document[\"@context\"])) {\n\t\t\t\t\tcontext = document[\"@context\"];\n\t\t\t\t}\n\n\t\t\t\tconst pathsToRestore = new Set<string>(JsonLdProcessor._NO_COMPACT_ARRAY_PROPERTIES);\n\t\t\t\tif (Is.arrayValue(options?.noCompactProperties)) {\n\t\t\t\t\tfor (const p of options.noCompactProperties) {\n\t\t\t\t\t\tpathsToRestore.add(p);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (!(options?.compactArrays ?? true)) {\n\t\t\t\t\tJsonLdProcessor.gatherArrayPropertyPaths(document, pathsToRestore);\n\t\t\t\t}\n\n\t\t\t\tconst compacted = await jsonLd.compact(\n\t\t\t\t\tObjectHelper.removeEmptyProperties(document),\n\t\t\t\t\tcontext as IJsonLdContextDefinition,\n\t\t\t\t\t{\n\t\t\t\t\t\tdocumentLoader: JsonLdProcessor.getDocumentLoader()\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\tJsonLdProcessor.expandArrayProperties(compacted, pathsToRestore);\n\n\t\t\t\treturn compacted as T;\n\t\t\t}\n\t\t\treturn document;\n\t\t} catch (err) {\n\t\t\tJsonLdProcessor.handleCommonErrors(err);\n\n\t\t\tthrow new GeneralError(JsonLdProcessor.CLASS_NAME, \"compact\", undefined, err);\n\t\t}\n\t}\n\n\t/**\n\t * Expand a document, removing its context.\n\t * @param compacted The compacted JSON-LD document to expand.\n\t * @returns The expanded JSON-LD document.\n\t */\n\tpublic static async expand<T>(compacted: T): Promise<IJsonLdNodeObject[]> {\n\t\ttry {\n\t\t\tif (Is.object<IJsonLdNodeObject>(compacted)) {\n\t\t\t\tconst expanded = await jsonLd.expand(ObjectHelper.removeEmptyProperties(compacted), {\n\t\t\t\t\tdocumentLoader: JsonLdProcessor.getDocumentLoader()\n\t\t\t\t});\n\t\t\t\treturn expanded;\n\t\t\t}\n\t\t\treturn [];\n\t\t} catch (err) {\n\t\t\tJsonLdProcessor.handleCommonErrors(err);\n\n\t\t\tthrow new GeneralError(JsonLdProcessor.CLASS_NAME, \"expand\", undefined, err);\n\t\t}\n\t}\n\n\t/**\n\t * Canonize a document.\n\t * @param document The document to canonize.\n\t * @param options The options for canonization.\n\t * @param options.algorithm The algorithm to use for canonization, defaults to URDNA2015.\n\t * @returns The canonized document.\n\t */\n\tpublic static async canonize<T extends IJsonLdNodeObject>(\n\t\tdocument: T,\n\t\toptions?: {\n\t\t\talgorithm?: \"URDNA2015\" | \"URGNA2012\" | undefined;\n\t\t}\n\t): Promise<string> {\n\t\ttry {\n\t\t\tconst normalized = await jsonLd.canonize(ObjectHelper.removeEmptyProperties(document), {\n\t\t\t\talgorithm: options?.algorithm ?? \"URDNA2015\",\n\t\t\t\tformat: \"application/n-quads\",\n\t\t\t\tdocumentLoader: JsonLdProcessor.getDocumentLoader()\n\t\t\t});\n\t\t\treturn normalized;\n\t\t} catch (err) {\n\t\t\tJsonLdProcessor.handleCommonErrors(err);\n\n\t\t\tthrow new GeneralError(JsonLdProcessor.CLASS_NAME, \"canonize\", undefined, err);\n\t\t}\n\t}\n\n\t/**\n\t * Combine contexts.\n\t * @param context1 The first JSON-LD context to combine.\n\t * @param context2 The second JSON-LD context to combine.\n\t * @returns The combined context.\n\t */\n\tpublic static combineContexts(\n\t\tcontext1: IJsonLdContextDefinitionRoot | undefined,\n\t\tcontext2: IJsonLdContextDefinitionRoot | undefined\n\t): IJsonLdContextDefinitionRoot | undefined {\n\t\tconst combinedContext: IJsonLdContextDefinitionRoot = [];\n\n\t\tif (Is.string(context1)) {\n\t\t\tif (!combinedContext.includes(context1)) {\n\t\t\t\tcombinedContext.push(context1);\n\t\t\t}\n\t\t} else if (Is.array(context1)) {\n\t\t\tfor (const context of context1) {\n\t\t\t\tconst hasMatch = combinedContext.some(c => ObjectHelper.equal(c, context));\n\t\t\t\tif (!hasMatch) {\n\t\t\t\t\tcombinedContext.push(context);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (Is.object(context1)) {\n\t\t\tconst hasMatch = combinedContext.some(c => ObjectHelper.equal(c, context1));\n\t\t\tif (!hasMatch) {\n\t\t\t\tcombinedContext.push(context1);\n\t\t\t}\n\t\t}\n\n\t\tif (Is.string(context2)) {\n\t\t\tif (!combinedContext.includes(context2)) {\n\t\t\t\tcombinedContext.push(context2);\n\t\t\t}\n\t\t} else if (Is.array(context2)) {\n\t\t\tfor (const context of context2) {\n\t\t\t\tconst hasMatch = combinedContext.some(c => ObjectHelper.equal(c, context));\n\t\t\t\tif (!hasMatch) {\n\t\t\t\t\tcombinedContext.push(context);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (Is.object(context2)) {\n\t\t\tconst hasMatch = combinedContext.some(c => ObjectHelper.equal(c, context2));\n\t\t\tif (!hasMatch) {\n\t\t\t\tcombinedContext.push(context2);\n\t\t\t}\n\t\t}\n\n\t\tif (combinedContext.length === 0) {\n\t\t\treturn null;\n\t\t}\n\n\t\tif (combinedContext.length === 1) {\n\t\t\treturn combinedContext[0];\n\t\t}\n\n\t\treturn combinedContext;\n\t}\n\n\t/**\n\t * Gather all the contexts from the element and it's children.\n\t * @param element The element to gather the contexts from.\n\t * @param initial The initial context.\n\t * @returns The combined contexts.\n\t */\n\tpublic static gatherContexts<T>(\n\t\telement: T,\n\t\tinitial?: IJsonLdContextDefinitionRoot\n\t): IJsonLdContextDefinitionRoot | undefined {\n\t\tlet combinedContexts: IJsonLdContextDefinitionRoot | undefined = initial;\n\n\t\tif (Is.object<IJsonLdNodeObject>(element)) {\n\t\t\tif (!Is.empty(element[\"@context\"])) {\n\t\t\t\tcombinedContexts = JsonLdProcessor.combineContexts(initial, element[\"@context\"]);\n\t\t\t}\n\n\t\t\tfor (const prop of Object.keys(element)) {\n\t\t\t\tconst value = element[prop];\n\t\t\t\tif (Is.object(value)) {\n\t\t\t\t\tcombinedContexts = JsonLdProcessor.gatherContexts(\n\t\t\t\t\t\tvalue as IJsonLdNodeObject,\n\t\t\t\t\t\tcombinedContexts\n\t\t\t\t\t);\n\t\t\t\t} else if (Is.array(value)) {\n\t\t\t\t\tfor (const item of value) {\n\t\t\t\t\t\tif (Is.object(item)) {\n\t\t\t\t\t\t\tcombinedContexts = JsonLdProcessor.gatherContexts(\n\t\t\t\t\t\t\t\titem as IJsonLdNodeObject,\n\t\t\t\t\t\t\t\tcombinedContexts\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 combinedContexts;\n\t}\n\n\t/**\n\t * Remove all the contexts that match the pattern.\n\t * @param context The context to remove the entries from.\n\t * @param match The element to try and match.\n\t * @returns The updated contexts.\n\t */\n\tpublic static removeContexts(\n\t\tcontext: IJsonLdContextDefinitionRoot | undefined,\n\t\tmatch?: IJsonLdContextDefinitionElement[]\n\t): IJsonLdContextDefinitionRoot | undefined {\n\t\tif (!Is.arrayValue(match)) {\n\t\t\treturn context;\n\t\t}\n\n\t\tlet finalContext: IJsonLdContextDefinitionRoot | undefined;\n\t\tif (Is.string(context)) {\n\t\t\tfor (const m of match) {\n\t\t\t\tif (context === m) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (Is.array(context)) {\n\t\t\tfor (const item of context) {\n\t\t\t\tconst hasMatch = match.some(m => ObjectHelper.equal(m, item));\n\t\t\t\tif (!hasMatch) {\n\t\t\t\t\tfinalContext ??= [];\n\t\t\t\t\tif (Is.array(finalContext)) {\n\t\t\t\t\t\tfinalContext.push(item);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (Is.object(context)) {\n\t\t\tconst hasMatch = match.some(m => ObjectHelper.equal(m, context));\n\t\t\tif (!hasMatch) {\n\t\t\t\tfinalContext = context;\n\t\t\t}\n\t\t}\n\n\t\treturn Is.arrayValue(finalContext) && finalContext.length === 1\n\t\t\t? finalContext[0]\n\t\t\t: finalContext;\n\t}\n\n\t/**\n\t * Add a context directly to the document loader cache.\n\t * @param url The url the ld context is for.\n\t * @param ldContext The context to add.\n\t * @returns A promise that resolves when the entry has been stored in the cache.\n\t */\n\tpublic static async documentCacheAdd(url: string, ldContext: unknown): Promise<void> {\n\t\tawait FetchHelper.setCacheEntry(url, ldContext);\n\t}\n\n\t/**\n\t * Remove a context from the document loader cache.\n\t * @param url The url the ld context is for.\n\t * @returns A promise that resolves when the entry has been removed from the cache.\n\t */\n\tpublic static async documentCacheRemove(url: string): Promise<void> {\n\t\tFetchHelper.removeCacheEntry(url);\n\t}\n\n\t/**\n\t * Document loader which uses a caching mechanism.\n\t * @param url The document url to load.\n\t * @returns The document.\n\t * @internal\n\t */\n\tprivate static async documentLoader(url: Url): Promise<RemoteDocument> {\n\t\tconst redirects = JsonLdProcessor.getRedirects();\n\t\tfor (const redirect of redirects) {\n\t\t\tif (redirect.from.test(url)) {\n\t\t\t\turl = redirect.to;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\treturn JsonLdProcessor.fetchRemoteJsonLdDocument(url, 0);\n\t}\n\n\t/**\n\t * True when FetchHelper failed to decode JSON from the response (e.g. HTML or plain text).\n\t * @param err The error from fetchJson.\n\t * @returns True if the error is a JSON decode failure, false otherwise.\n\t * @internal\n\t */\n\tprivate static isFetchJsonDecodeFailure(err: unknown): boolean {\n\t\t// Raw JSON.parse / response.json() failures (FetchHelper may rethrow as FetchError with cause,\n\t\t// or propagate SyntaxError when error-response body is not JSON).\n\t\tconst error = BaseError.fromError(err);\n\t\tif (error.name === \"SyntaxError\" || error.cause?.name === \"SyntaxError\") {\n\t\t\treturn true;\n\t\t}\n\t\treturn error.message.includes(\"decodingJSON\") || error.message.includes(\"is not valid JSON\");\n\t}\n\n\t/**\n\t * Use HTTP Link (rel=alternate, type=application/ld+json) to discover a JSON-LD context URL.\n\t * @param sourceUrl URL that did not yield JSON (e.g. vocabulary namespace HTML page).\n\t * @returns Absolute context document URL, or undefined.\n\t * @internal\n\t */\n\tprivate static async tryDiscoverAlternateJsonLdContextUrl(\n\t\tsourceUrl: string\n\t): Promise<string | undefined> {\n\t\tconst fetchOpts = {\n\t\t\ttimeoutMs: 30_000,\n\t\t\theaders: {\n\t\t\t\t[HeaderTypes.Accept]: `${MimeTypes.JsonLd},${MimeTypes.Json};q=0.9,*/*;q=0.8`\n\t\t\t}\n\t\t};\n\n\t\tlet response = await FetchHelper.fetch(\n\t\t\tJsonLdProcessor.CLASS_NAME,\n\t\t\tsourceUrl,\n\t\t\tHttpMethod.HEAD,\n\t\t\tundefined,\n\t\t\tfetchOpts\n\t\t);\n\n\t\tif (\n\t\t\tresponse.status === HttpStatusCode.methodNotAllowed ||\n\t\t\tresponse.status === HttpStatusCode.notImplemented\n\t\t) {\n\t\t\tresponse = await FetchHelper.fetch(\n\t\t\t\tJsonLdProcessor.CLASS_NAME,\n\t\t\t\tsourceUrl,\n\t\t\t\tHttpMethod.GET,\n\t\t\t\tundefined,\n\t\t\t\tfetchOpts\n\t\t\t);\n\t\t\tawait response.arrayBuffer();\n\t\t}\n\n\t\tif (!response.ok) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst linkHeader = response.headers.get(HeaderTypes.Link);\n\t\tif (Is.empty(linkHeader)) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// response.url is \"\" for many mocked/synthetic Responses; Is.empty(\"\") is false, but\n\t\t// new URL(absoluteHref, \"\") throws - use a non-empty resolved URL as base only.\n\t\tconst baseUrl = Is.stringValue(response.url) ? response.url : sourceUrl;\n\n\t\tconst alternateLinkHeaders = HeaderHelper.extractLinkHeaderRelations(\n\t\t\tlinkHeader,\n\t\t\tHttpLinkRelType.alternate\n\t\t);\n\n\t\tif (Is.arrayValue(alternateLinkHeaders)) {\n\t\t\tfor (const alternateLinkHeader of alternateLinkHeaders) {\n\t\t\t\tif (alternateLinkHeader.params?.type === MimeTypes.JsonLd) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\treturn new URL(alternateLinkHeader.url, baseUrl).href;\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Malformed URL for this segment; try the next Link segment.\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Fetch a remote JSON-LD document, with Accept fallbacks and optional Link-header discovery.\n\t * @param url Resolved document URL.\n\t * @param linkDiscoveryDepth Current discovery recursion depth.\n\t * @returns The fetched remote JSON-LD document.\n\t * @internal\n\t */\n\tprivate static async fetchRemoteJsonLdDocument(\n\t\turl: string,\n\t\tlinkDiscoveryDepth: number\n\t): Promise<RemoteDocument> {\n\t\tconst cacheTtlMs = JsonLdProcessor.getCacheLimit();\n\t\tconst fetchJsonLdOptions = {\n\t\t\tcacheTtlMs,\n\t\t\theaders: {\n\t\t\t\t[HeaderTypes.Accept]: MimeTypes.JsonLd\n\t\t\t}\n\t\t};\n\t\tconst fetchJsonOptions = {\n\t\t\tcacheTtlMs,\n\t\t\theaders: {\n\t\t\t\t[HeaderTypes.Accept]: MimeTypes.Json\n\t\t\t}\n\t\t};\n\n\t\ttry {\n\t\t\tconst document = await FetchHelper.fetchJson<never, JsonLd>(\n\t\t\t\tJsonLdProcessor.CLASS_NAME,\n\t\t\t\turl,\n\t\t\t\tHttpMethod.GET,\n\t\t\t\tundefined,\n\t\t\t\tfetchJsonLdOptions\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tdocumentUrl: url,\n\t\t\t\tdocument\n\t\t\t};\n\t\t} catch (errLd) {\n\t\t\tif (JsonLdProcessor.isFetchJsonDecodeFailure(errLd)) {\n\t\t\t\ttry {\n\t\t\t\t\tconst document = await FetchHelper.fetchJson<never, JsonLd>(\n\t\t\t\t\t\tJsonLdProcessor.CLASS_NAME,\n\t\t\t\t\t\turl,\n\t\t\t\t\t\tHttpMethod.GET,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\tfetchJsonOptions\n\t\t\t\t\t);\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdocumentUrl: url,\n\t\t\t\t\t\tdocument\n\t\t\t\t\t};\n\t\t\t\t} catch (errJson) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tlinkDiscoveryDepth < JsonLdProcessor._MAX_LINK_DISCOVERY_DEPTH &&\n\t\t\t\t\t\tJsonLdProcessor.isFetchJsonDecodeFailure(errJson)\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst discovered = await JsonLdProcessor.tryDiscoverAlternateJsonLdContextUrl(url);\n\t\t\t\t\t\tif (Is.stringValue(discovered) && discovered !== url) {\n\t\t\t\t\t\t\treturn JsonLdProcessor.fetchRemoteJsonLdDocument(discovered, linkDiscoveryDepth + 1);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tthrow errJson;\n\t\t\t\t}\n\t\t\t}\n\t\t\tthrow errLd;\n\t\t}\n\t}\n\n\t/**\n\t * Recursively collect dot-notation paths of all single-element array properties in an object,\n\t * skipping JSON-LD keywords (keys starting with \"@\"). Paths are added to the provided set.\n\t * @param obj The object to scan.\n\t * @param arrayPaths The accumulator set to add discovered paths to.\n\t * @param prefix The dot-path prefix accumulated from parent calls.\n\t * @internal\n\t */\n\tprivate static gatherArrayPropertyPaths(\n\t\tobj: { [key: string]: unknown },\n\t\tarrayPaths: Set<string>,\n\t\tprefix: string = \"\"\n\t): void {\n\t\tfor (const key of Object.keys(obj)) {\n\t\t\tif (!key.startsWith(\"@\")) {\n\t\t\t\tconst path = prefix.length > 0 ? `${prefix}.${key}` : key;\n\t\t\t\tconst value = obj[key];\n\t\t\t\tif (Is.array(value)) {\n\t\t\t\t\tif (value.length === 1) {\n\t\t\t\t\t\tarrayPaths.add(path);\n\t\t\t\t\t}\n\t\t\t\t\tfor (const item of value) {\n\t\t\t\t\t\tif (Is.object(item)) {\n\t\t\t\t\t\t\tJsonLdProcessor.gatherArrayPropertyPaths(item, arrayPaths, path);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else if (Is.object(value)) {\n\t\t\t\t\tJsonLdProcessor.gatherArrayPropertyPaths(value, arrayPaths, path);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Recursively ensure that properties identified by dot-notation paths are arrays.\n\t * Properties that were collapsed to a single value during compaction are wrapped back into an array.\n\t * @param obj The object to update in place.\n\t * @param arrayPaths The set of dot-notation paths that must remain arrays.\n\t * @param prefix The dot-path prefix accumulated from parent calls.\n\t * @internal\n\t */\n\tprivate static expandArrayProperties(\n\t\tobj: { [key: string]: unknown },\n\t\tarrayPaths: Set<string>,\n\t\tprefix: string = \"\"\n\t): void {\n\t\tfor (const key of Object.keys(obj)) {\n\t\t\tif (!key.startsWith(\"@\")) {\n\t\t\t\tconst path = prefix.length > 0 ? `${prefix}.${key}` : key;\n\t\t\t\tconst value = obj[key];\n\t\t\t\tif (arrayPaths.has(path) && !Is.array(value)) {\n\t\t\t\t\tobj[key] = [value];\n\t\t\t\t}\n\t\t\t\tconst current = obj[key];\n\t\t\t\tif (Is.array(current)) {\n\t\t\t\t\tfor (const item of current) {\n\t\t\t\t\t\tif (Is.object(item)) {\n\t\t\t\t\t\t\tJsonLdProcessor.expandArrayProperties(item, arrayPaths, path);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else if (Is.object(current)) {\n\t\t\t\t\tJsonLdProcessor.expandArrayProperties(current, arrayPaths, path);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Handle common errors.\n\t * @param err The error to handle.\n\t * @throws GeneralError if the error is a known JSON-LD error type.\n\t * @internal\n\t */\n\tprivate static handleCommonErrors(err: unknown): void {\n\t\tif (\n\t\t\tIs.object<{ name: string; details?: { url?: string } }>(err) &&\n\t\t\terr.name === \"jsonld.InvalidUrl\"\n\t\t) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tJsonLdProcessor.CLASS_NAME,\n\t\t\t\t\"invalidUrl\",\n\t\t\t\t{ url: err.details?.url },\n\t\t\t\terr\n\t\t\t);\n\t\t} else if (\n\t\t\tIs.object<{ name: string; details?: { code: string } & { [id: string]: unknown } }>(err) &&\n\t\t\terr.name.startsWith(\"jsonld.\")\n\t\t) {\n\t\t\tconst { code, ...other } = err.details ?? {};\n\t\t\tthrow new GeneralError(JsonLdProcessor.CLASS_NAME, \"jsonLdError\", { code, ...other }, err);\n\t\t}\n\t}\n}\n"]}