@twin.org/data-json-ld 0.0.3-next.2 → 0.0.3-next.20
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.
- package/README.md +1 -1
- package/dist/es/dataTypes/jsonLdDataTypes.js +104 -131
- package/dist/es/dataTypes/jsonLdDataTypes.js.map +1 -1
- package/dist/es/helpers/jsonLdHelperTypes.js +2 -0
- package/dist/es/helpers/jsonLdHelperTypes.js.map +1 -0
- package/dist/es/index.js +1 -0
- package/dist/es/index.js.map +1 -1
- package/dist/es/models/jsonLdContexts.js +10 -2
- package/dist/es/models/jsonLdContexts.js.map +1 -1
- package/dist/es/schemas/JsonLdContainerType.json +17 -7
- package/dist/es/schemas/JsonLdContainerTypeArray.json +129 -142
- package/dist/es/schemas/JsonLdContextDefinition.json +76 -18
- package/dist/es/schemas/JsonLdContextDefinitionElement.json +1 -0
- package/dist/es/schemas/JsonLdContextDefinitionRoot.json +1 -0
- package/dist/es/schemas/JsonLdDocument.json +3 -3
- package/dist/es/schemas/JsonLdExpandedTermDefinition.json +101 -89
- package/dist/es/schemas/JsonLdGraphObject.json +2 -2
- package/dist/es/schemas/JsonLdIdMap.json +1 -0
- package/dist/es/schemas/JsonLdIncludedBlock.json +1 -0
- package/dist/es/schemas/JsonLdIndexMap.json +2 -1
- package/dist/es/schemas/JsonLdIndexMapItem.json +1 -0
- package/dist/es/schemas/JsonLdJsonArray.json +1 -0
- package/dist/es/schemas/JsonLdJsonObject.json +2 -8
- package/dist/es/schemas/JsonLdJsonPrimitive.json +14 -5
- package/dist/es/schemas/JsonLdJsonValue.json +1 -0
- package/dist/es/schemas/JsonLdLanguageMap.json +1 -0
- package/dist/es/schemas/JsonLdListObject.json +2 -2
- package/dist/es/schemas/JsonLdListOrSetItem.json +1 -0
- package/dist/es/schemas/JsonLdNodeObject.json +12 -72
- package/dist/es/schemas/JsonLdNodePrimitive.json +1 -0
- package/dist/es/schemas/JsonLdObject.json +3 -3
- package/dist/es/schemas/JsonLdSetObject.json +2 -2
- package/dist/es/schemas/JsonLdTypeMap.json +1 -0
- package/dist/es/schemas/JsonLdValueObject.json +99 -87
- package/dist/es/utils/jsonLdHelper.js +181 -15
- package/dist/es/utils/jsonLdHelper.js.map +1 -1
- package/dist/es/utils/jsonLdProcessor.js +122 -33
- package/dist/es/utils/jsonLdProcessor.js.map +1 -1
- package/dist/types/helpers/jsonLdHelperTypes.d.ts +127 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/models/jsonLdContexts.d.ts +10 -2
- package/dist/types/utils/jsonLdHelper.d.ts +63 -6
- package/dist/types/utils/jsonLdProcessor.d.ts +10 -7
- package/docs/changelog.md +273 -1
- package/docs/examples.md +214 -1
- package/docs/reference/classes/JsonLdDataTypes.md +1 -1
- package/docs/reference/classes/JsonLdHelper.md +249 -13
- package/docs/reference/classes/JsonLdProcessor.md +51 -58
- package/docs/reference/index.md +23 -0
- package/docs/reference/interfaces/IJsonLdContextDefinition.md +20 -20
- package/docs/reference/interfaces/IJsonLdGraphObject.md +7 -7
- package/docs/reference/interfaces/IJsonLdIdMap.md +1 -1
- package/docs/reference/interfaces/IJsonLdIndexMap.md +1 -1
- package/docs/reference/interfaces/IJsonLdJsonObject.md +1 -1
- package/docs/reference/interfaces/IJsonLdLanguageMap.md +1 -1
- package/docs/reference/interfaces/IJsonLdListObject.md +3 -3
- package/docs/reference/interfaces/IJsonLdNodeObject.md +17 -17
- package/docs/reference/interfaces/IJsonLdObject.md +16 -16
- package/docs/reference/interfaces/IJsonLdSetObject.md +3 -3
- package/docs/reference/interfaces/IJsonLdTypeMap.md +1 -1
- package/docs/reference/type-aliases/IJsonLdExpandedTermDefinition.md +7 -7
- package/docs/reference/type-aliases/IJsonLdValueObject.md +2 -2
- package/docs/reference/type-aliases/JsonLdAliasKey.md +15 -0
- package/docs/reference/type-aliases/JsonLdExistingProperty.md +19 -0
- package/docs/reference/type-aliases/JsonLdExistingPropertyEither.md +24 -0
- package/docs/reference/type-aliases/JsonLdKeys.md +11 -0
- package/docs/reference/type-aliases/JsonLdObjectWithAliases.md +16 -0
- package/docs/reference/type-aliases/JsonLdObjectWithAtId.md +21 -0
- package/docs/reference/type-aliases/JsonLdObjectWithAtType.md +21 -0
- package/docs/reference/type-aliases/JsonLdObjectWithContext.md +21 -0
- package/docs/reference/type-aliases/JsonLdObjectWithId.md +21 -0
- package/docs/reference/type-aliases/JsonLdObjectWithNoAtId.md +11 -0
- package/docs/reference/type-aliases/JsonLdObjectWithNoAtType.md +11 -0
- package/docs/reference/type-aliases/JsonLdObjectWithNoContext.md +12 -0
- package/docs/reference/type-aliases/JsonLdObjectWithNoId.md +11 -0
- package/docs/reference/type-aliases/JsonLdObjectWithNoType.md +11 -0
- package/docs/reference/type-aliases/JsonLdObjectWithOptionalAtId.md +21 -0
- package/docs/reference/type-aliases/JsonLdObjectWithOptionalAtType.md +21 -0
- package/docs/reference/type-aliases/JsonLdObjectWithOptionalContext.md +22 -0
- package/docs/reference/type-aliases/JsonLdObjectWithOptionalId.md +21 -0
- package/docs/reference/type-aliases/JsonLdObjectWithOptionalType.md +21 -0
- package/docs/reference/type-aliases/JsonLdObjectWithType.md +21 -0
- package/docs/reference/type-aliases/JsonLdOptionalKeys.md +11 -0
- package/docs/reference/type-aliases/JsonLdRequiredKeys.md +11 -0
- package/docs/reference/type-aliases/JsonLdWithAliases.md +17 -0
- package/docs/reference/variables/JsonLdContexts.md +15 -3
- package/docs/reference/variables/JsonLdTypes.md +26 -26
- package/package.json +4 -4
package/docs/changelog.md
CHANGED
|
@@ -1,4 +1,276 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.0.3-next.20](https://github.com/twinfoundation/data/compare/data-json-ld-v0.0.3-next.19...data-json-ld-v0.0.3-next.20) (2026-03-24)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* discover JSON-LD context via HTTP Link ([#62](https://github.com/twinfoundation/data/issues/62)) ([5545864](https://github.com/twinfoundation/data/commit/5545864c08e8c42fb93844f552907648a1130b64))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @twin.org/data-core bumped from 0.0.3-next.19 to 0.0.3-next.20
|
|
16
|
+
|
|
17
|
+
## [0.0.3-next.20](https://github.com/twinfoundation/data/compare/data-json-ld-v0.0.3-next.19...data-json-ld-v0.0.3-next.20) (2026-03-23)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* **JsonLdProcessor:** discover JSON-LD context URLs via HTTP `Link` (`rel="alternate"`, `type="application/ld+json"`) after `GET` Accept fallbacks fail to return JSON; `HEAD` with `GET` fallback on 405/501; at most one discovery hop; resolve `Link` targets with a safe base when `response.url` is empty (e.g. synthetic responses). Registered redirects still take precedence over discovery.
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Documentation
|
|
26
|
+
|
|
27
|
+
* Document remote context resolution order (`docs/examples.md`).
|
|
28
|
+
* Document when vocabulary `registerRedirects()` helpers are optional versus HTTP `Link` discovery (`docs/examples.md`).
|
|
29
|
+
* Expand `JsonLdProcessor` redirect JSDoc (`setRedirects` / `addRedirect`).
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
### Tests
|
|
33
|
+
|
|
34
|
+
* Share schema.org fixture document-cache seeding via `tests/helpers/schemaOrgDocumentCache.ts` (`jsonLdProcessor` / `jsonLdHelper` specs).
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
## [0.0.3-next.19](https://github.com/twinfoundation/data/compare/data-json-ld-v0.0.3-next.18...data-json-ld-v0.0.3-next.19) (2026-03-20)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
### Features
|
|
41
|
+
|
|
42
|
+
* use local LD context fixture in tests instead of remotes ([#60](https://github.com/twinfoundation/data/issues/60)) ([df18303](https://github.com/twinfoundation/data/commit/df18303301f031a5032850c900eea24b094a99a5))
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
### Dependencies
|
|
46
|
+
|
|
47
|
+
* The following workspace dependencies were updated
|
|
48
|
+
* dependencies
|
|
49
|
+
* @twin.org/data-core bumped from 0.0.3-next.18 to 0.0.3-next.19
|
|
50
|
+
|
|
51
|
+
## [0.0.3-next.18](https://github.com/twinfoundation/data/compare/data-json-ld-v0.0.3-next.17...data-json-ld-v0.0.3-next.18) (2026-03-16)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
### Miscellaneous Chores
|
|
55
|
+
|
|
56
|
+
* **data-json-ld:** Synchronize repo versions
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
### Dependencies
|
|
60
|
+
|
|
61
|
+
* The following workspace dependencies were updated
|
|
62
|
+
* dependencies
|
|
63
|
+
* @twin.org/data-core bumped from 0.0.3-next.17 to 0.0.3-next.18
|
|
64
|
+
|
|
65
|
+
## [0.0.3-next.17](https://github.com/twinfoundation/data/compare/data-json-ld-v0.0.3-next.16...data-json-ld-v0.0.3-next.17) (2026-03-12)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
### Miscellaneous Chores
|
|
69
|
+
|
|
70
|
+
* **data-json-ld:** Synchronize repo versions
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
### Dependencies
|
|
74
|
+
|
|
75
|
+
* The following workspace dependencies were updated
|
|
76
|
+
* dependencies
|
|
77
|
+
* @twin.org/data-core bumped from 0.0.3-next.16 to 0.0.3-next.17
|
|
78
|
+
|
|
79
|
+
## [0.0.3-next.16](https://github.com/twinfoundation/data/compare/data-json-ld-v0.0.3-next.15...data-json-ld-v0.0.3-next.16) (2026-03-06)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
### Features
|
|
83
|
+
|
|
84
|
+
* additional JSON-LD helper types ([575627c](https://github.com/twinfoundation/data/commit/575627c707e691086e07163dac44ba1396ac322e))
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
### Dependencies
|
|
88
|
+
|
|
89
|
+
* The following workspace dependencies were updated
|
|
90
|
+
* dependencies
|
|
91
|
+
* @twin.org/data-core bumped from 0.0.3-next.15 to 0.0.3-next.16
|
|
92
|
+
|
|
93
|
+
## [0.0.3-next.15](https://github.com/twinfoundation/data/compare/data-json-ld-v0.0.3-next.14...data-json-ld-v0.0.3-next.15) (2026-02-27)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
### Features
|
|
97
|
+
|
|
98
|
+
* additional json-ld helpers ([c74cbd6](https://github.com/twinfoundation/data/commit/c74cbd60e423c5f780243da9868723e9d54d068a))
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
### Dependencies
|
|
102
|
+
|
|
103
|
+
* The following workspace dependencies were updated
|
|
104
|
+
* dependencies
|
|
105
|
+
* @twin.org/data-core bumped from 0.0.3-next.14 to 0.0.3-next.15
|
|
106
|
+
|
|
107
|
+
## [0.0.3-next.14](https://github.com/twinfoundation/data/compare/data-json-ld-v0.0.3-next.13...data-json-ld-v0.0.3-next.14) (2026-02-25)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
### Features
|
|
111
|
+
|
|
112
|
+
* update schemas ([c30159c](https://github.com/twinfoundation/data/commit/c30159cd24e5f60f9124752738dd1c0312ee17dd))
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
### Dependencies
|
|
116
|
+
|
|
117
|
+
* The following workspace dependencies were updated
|
|
118
|
+
* dependencies
|
|
119
|
+
* @twin.org/data-core bumped from 0.0.3-next.13 to 0.0.3-next.14
|
|
120
|
+
|
|
121
|
+
## [0.0.3-next.13](https://github.com/twinfoundation/data/compare/data-json-ld-v0.0.3-next.12...data-json-ld-v0.0.3-next.13) (2026-02-25)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
### Features
|
|
125
|
+
|
|
126
|
+
* publish npm await ([7bdf0cd](https://github.com/twinfoundation/data/commit/7bdf0cd5d9417e7f8811f295ccf3ab3403ae3753))
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
### Dependencies
|
|
130
|
+
|
|
131
|
+
* The following workspace dependencies were updated
|
|
132
|
+
* dependencies
|
|
133
|
+
* @twin.org/data-core bumped from 0.0.3-next.12 to 0.0.3-next.13
|
|
134
|
+
|
|
135
|
+
## [0.0.3-next.12](https://github.com/twinfoundation/data/compare/data-json-ld-v0.0.3-next.11...data-json-ld-v0.0.3-next.12) (2026-02-25)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
### Features
|
|
139
|
+
|
|
140
|
+
* add toStructuredObject ([58354e0](https://github.com/twinfoundation/data/commit/58354e0096c917f2e2e64214107d68326c79260d))
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
### Dependencies
|
|
144
|
+
|
|
145
|
+
* The following workspace dependencies were updated
|
|
146
|
+
* dependencies
|
|
147
|
+
* @twin.org/data-core bumped from 0.0.3-next.11 to 0.0.3-next.12
|
|
148
|
+
|
|
149
|
+
## [0.0.3-next.11](https://github.com/twinfoundation/data/compare/data-json-ld-v0.0.3-next.10...data-json-ld-v0.0.3-next.11) (2026-02-25)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
### Features
|
|
153
|
+
|
|
154
|
+
* expand JsonLdHelper.getId with custom properties names ([8ec4dcf](https://github.com/twinfoundation/data/commit/8ec4dcf807a6dc416b2df2a77749f841a60be05f))
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
### Dependencies
|
|
158
|
+
|
|
159
|
+
* The following workspace dependencies were updated
|
|
160
|
+
* dependencies
|
|
161
|
+
* @twin.org/data-core bumped from 0.0.3-next.10 to 0.0.3-next.11
|
|
162
|
+
|
|
163
|
+
## [0.0.3-next.10](https://github.com/twinfoundation/data/compare/data-json-ld-v0.0.3-next.9...data-json-ld-v0.0.3-next.10) (2026-02-24)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
### Features
|
|
167
|
+
|
|
168
|
+
* add json ld helper types ([#46](https://github.com/twinfoundation/data/issues/46)) ([22e998e](https://github.com/twinfoundation/data/commit/22e998e29e7eadc9202026ee9743d64ed98035df))
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
### Dependencies
|
|
172
|
+
|
|
173
|
+
* The following workspace dependencies were updated
|
|
174
|
+
* dependencies
|
|
175
|
+
* @twin.org/data-core bumped from 0.0.3-next.9 to 0.0.3-next.10
|
|
176
|
+
|
|
177
|
+
## [0.0.3-next.9](https://github.com/twinfoundation/data/compare/data-json-ld-v0.0.3-next.8...data-json-ld-v0.0.3-next.9) (2026-02-23)
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
### Features
|
|
181
|
+
|
|
182
|
+
* additional JsonLdHelper methods ([#44](https://github.com/twinfoundation/data/issues/44)) ([ebe2cf5](https://github.com/twinfoundation/data/commit/ebe2cf50d1a7fbe0474f0a556d49f43eb7767a2f))
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
### Dependencies
|
|
186
|
+
|
|
187
|
+
* The following workspace dependencies were updated
|
|
188
|
+
* dependencies
|
|
189
|
+
* @twin.org/data-core bumped from 0.0.3-next.8 to 0.0.3-next.9
|
|
190
|
+
|
|
191
|
+
## [0.0.3-next.8](https://github.com/twinfoundation/data/compare/data-json-ld-v0.0.3-next.7...data-json-ld-v0.0.3-next.8) (2026-02-02)
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
### Miscellaneous Chores
|
|
195
|
+
|
|
196
|
+
* **data-json-ld:** Synchronize repo versions
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
### Dependencies
|
|
200
|
+
|
|
201
|
+
* The following workspace dependencies were updated
|
|
202
|
+
* dependencies
|
|
203
|
+
* @twin.org/data-core bumped from 0.0.3-next.7 to 0.0.3-next.8
|
|
204
|
+
|
|
205
|
+
## [0.0.3-next.7](https://github.com/twinfoundation/data/compare/data-json-ld-v0.0.3-next.6...data-json-ld-v0.0.3-next.7) (2026-01-21)
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
### Features
|
|
209
|
+
|
|
210
|
+
* update context naming ([#37](https://github.com/twinfoundation/data/issues/37)) ([9d99360](https://github.com/twinfoundation/data/commit/9d993605aa51f27a09722729057c6ee921617c2d))
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
### Dependencies
|
|
214
|
+
|
|
215
|
+
* The following workspace dependencies were updated
|
|
216
|
+
* dependencies
|
|
217
|
+
* @twin.org/data-core bumped from 0.0.3-next.6 to 0.0.3-next.7
|
|
218
|
+
|
|
219
|
+
## [0.0.3-next.6](https://github.com/twinfoundation/data/compare/data-json-ld-v0.0.3-next.5...data-json-ld-v0.0.3-next.6) (2026-01-14)
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
### Miscellaneous Chores
|
|
223
|
+
|
|
224
|
+
* **data-json-ld:** Synchronize repo versions
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
### Dependencies
|
|
228
|
+
|
|
229
|
+
* The following workspace dependencies were updated
|
|
230
|
+
* dependencies
|
|
231
|
+
* @twin.org/data-core bumped from 0.0.3-next.5 to 0.0.3-next.6
|
|
232
|
+
|
|
233
|
+
## [0.0.3-next.5](https://github.com/twinfoundation/data/compare/data-json-ld-v0.0.3-next.4...data-json-ld-v0.0.3-next.5) (2026-01-14)
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
### Features
|
|
237
|
+
|
|
238
|
+
* improve data type registration ([#34](https://github.com/twinfoundation/data/issues/34)) ([855d110](https://github.com/twinfoundation/data/commit/855d11046a4d85317b77a5c4e0f4a7b1b6d1a767))
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
### Dependencies
|
|
242
|
+
|
|
243
|
+
* The following workspace dependencies were updated
|
|
244
|
+
* dependencies
|
|
245
|
+
* @twin.org/data-core bumped from 0.0.3-next.4 to 0.0.3-next.5
|
|
246
|
+
|
|
247
|
+
## [0.0.3-next.4](https://github.com/twinfoundation/data/compare/data-json-ld-v0.0.3-next.3...data-json-ld-v0.0.3-next.4) (2026-01-06)
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
### Miscellaneous Chores
|
|
251
|
+
|
|
252
|
+
* **data-json-ld:** Synchronize repo versions
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
### Dependencies
|
|
256
|
+
|
|
257
|
+
* The following workspace dependencies were updated
|
|
258
|
+
* dependencies
|
|
259
|
+
* @twin.org/data-core bumped from 0.0.3-next.3 to 0.0.3-next.4
|
|
260
|
+
|
|
261
|
+
## [0.0.3-next.3](https://github.com/twinfoundation/data/compare/data-json-ld-v0.0.3-next.2...data-json-ld-v0.0.3-next.3) (2026-01-05)
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
### Features
|
|
265
|
+
|
|
266
|
+
* add JsonLdHelper.toNodeObject method ([93f2add](https://github.com/twinfoundation/data/commit/93f2add1948f168d7a21223929cf6c65a8115f6f))
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
### Dependencies
|
|
270
|
+
|
|
271
|
+
* The following workspace dependencies were updated
|
|
272
|
+
* dependencies
|
|
273
|
+
* @twin.org/data-core bumped from 0.0.3-next.2 to 0.0.3-next.3
|
|
2
274
|
|
|
3
275
|
## [0.0.3-next.2](https://github.com/twinfoundation/data/compare/data-json-ld-v0.0.3-next.1...data-json-ld-v0.0.3-next.2) (2025-11-24)
|
|
4
276
|
|
package/docs/examples.md
CHANGED
|
@@ -1 +1,214 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Data Json Ld Examples
|
|
2
|
+
|
|
3
|
+
These examples walk through context management, document processing, validation, and property access patterns for JSON-LD documents.
|
|
4
|
+
|
|
5
|
+
## JsonLdProcessor
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { JsonLdProcessor } from '@twin.org/data-json-ld';
|
|
9
|
+
|
|
10
|
+
JsonLdProcessor.setCacheLimit(900000);
|
|
11
|
+
console.log('Cache limit:', JsonLdProcessor.getCacheLimit());
|
|
12
|
+
|
|
13
|
+
JsonLdProcessor.setRedirects([
|
|
14
|
+
{
|
|
15
|
+
from: /^https:\/\/raw\.githubusercontent\.com\//,
|
|
16
|
+
to: 'https://cdn.example.org/github-content'
|
|
17
|
+
}
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
JsonLdProcessor.addRedirect(/^https:\/\/schema\.org\//, 'https://schema.org/');
|
|
21
|
+
console.log('Has redirects:', JsonLdProcessor.getRedirects().length > 0);
|
|
22
|
+
|
|
23
|
+
const loader = JsonLdProcessor.getDocumentLoader();
|
|
24
|
+
console.log('Loader type:', typeof loader);
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { JsonLdProcessor, type IJsonLdNodeObject } from '@twin.org/data-json-ld';
|
|
29
|
+
|
|
30
|
+
const compactedDoc = {
|
|
31
|
+
'@context': {
|
|
32
|
+
ex: 'https://example.org/vocab/',
|
|
33
|
+
name: 'ex:name'
|
|
34
|
+
},
|
|
35
|
+
'@id': 'urn:example:person:1',
|
|
36
|
+
name: 'Ada'
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const expanded = await JsonLdProcessor.expand(compactedDoc);
|
|
40
|
+
const compactedAgain = await JsonLdProcessor.compact(expanded[0], compactedDoc['@context']);
|
|
41
|
+
|
|
42
|
+
console.log('Compacted id:', compactedAgain['@id']);
|
|
43
|
+
|
|
44
|
+
const canonical = await JsonLdProcessor.canonize(expanded[0] as IJsonLdNodeObject);
|
|
45
|
+
console.log('Canonical includes id:', canonical.includes('urn:example:person:1'));
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import { JsonLdProcessor, type IJsonLdNodeObject } from '@twin.org/data-json-ld';
|
|
50
|
+
|
|
51
|
+
const contextA = 'https://example.org/context/base';
|
|
52
|
+
const contextB = {
|
|
53
|
+
ex: 'https://example.org/vocab/',
|
|
54
|
+
name: 'ex:name'
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const combined = JsonLdProcessor.combineContexts(contextA, contextB);
|
|
58
|
+
|
|
59
|
+
const documentWithNestedContexts: IJsonLdNodeObject = {
|
|
60
|
+
'@context': contextA,
|
|
61
|
+
'@graph': [
|
|
62
|
+
{
|
|
63
|
+
'@context': contextB,
|
|
64
|
+
'@id': 'urn:example:item:1',
|
|
65
|
+
'@type': 'ex:Person',
|
|
66
|
+
'ex:name': 'Ada'
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const gathered = JsonLdProcessor.gatherContexts(documentWithNestedContexts);
|
|
72
|
+
const filtered = JsonLdProcessor.removeContexts(gathered, [contextB]);
|
|
73
|
+
|
|
74
|
+
console.log('Combined is array:', Array.isArray(combined));
|
|
75
|
+
console.log('Filtered context equals contextA:', filtered === contextA);
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
import { JsonLdProcessor } from '@twin.org/data-json-ld';
|
|
80
|
+
|
|
81
|
+
await JsonLdProcessor.documentCacheAdd('https://example.org/context', {
|
|
82
|
+
'@context': {
|
|
83
|
+
ex: 'https://example.org/vocab/'
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
await JsonLdProcessor.documentCacheRemove('https://example.org/context');
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Remote `@context` URLs: redirects and HTTP `Link` discovery
|
|
91
|
+
|
|
92
|
+
When a remote `@context` URL is a string, the default document loader resolves it in this order:
|
|
93
|
+
|
|
94
|
+
1. **Registered redirects** — `setRedirects` / `addRedirect` run first. If a pattern matches, the request uses the replacement URL only (no `HEAD` or discovery against the original namespace URL).
|
|
95
|
+
2. **GET with `Accept: application/ld+json`**. If the response is an **HTTP error** (for example **404**), the load fails and discovery does not run. If the response is **OK** but the body is **not valid JSON** (for example HTML), retry **GET** with **`Accept: application/json`**.
|
|
96
|
+
3. **HTTP `Link` discovery** — only if **both** `GET`s in step 2 failed with a **JSON decode** error: `HEAD` on the current URL (or `GET` if the server returns **405** / **501** for `HEAD`), then inspect `Link` for `rel="alternate"` and `type="application/ld+json"`, resolve the target URL, and **fetch that context document once** (at most **one** discovery hop per load chain).
|
|
97
|
+
|
|
98
|
+
Use **manual redirects** for stable overrides, offline tests, or hosts that do not expose a suitable `Link` header. Rely on **discovery** when the namespace URL serves HTML but advertises a JSON-LD context via `Link`.
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
import { JsonLdProcessor } from '@twin.org/data-json-ld';
|
|
102
|
+
|
|
103
|
+
// Optional: force a namespace URL to a known context document (runs before discovery).
|
|
104
|
+
JsonLdProcessor.addRedirect(
|
|
105
|
+
/^https:\/\/example\.org\/vocab\/?$/,
|
|
106
|
+
'https://example.org/context/doc.jsonld'
|
|
107
|
+
);
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Standards packages and `registerRedirects()`
|
|
111
|
+
|
|
112
|
+
Vocabulary packages (for example `@twin.org/standards-schema-org`) often expose `SchemaOrgDataTypes.registerRedirects()`, which forwards to `JsonLdProcessor.addRedirect` for a known namespace URL. That call is **optional** in many deployments: the default loader can reach the same JSON-LD context via **HTTP `Link` discovery** when the namespace URL returns HTML and advertises `rel="alternate"` with `type="application/ld+json"`. Prefer **explicit redirects** when you want predictable URLs without an extra `HEAD`/`GET` for discovery, **fully offline** or hermetic tests, or when the host does not send a usable `Link` header.
|
|
113
|
+
|
|
114
|
+
## JsonLdHelper
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
import { type IValidationFailure } from '@twin.org/core';
|
|
118
|
+
import { ValidationMode } from '@twin.org/data-core';
|
|
119
|
+
import { JsonLdHelper, type IJsonLdNodeObject } from '@twin.org/data-json-ld';
|
|
120
|
+
|
|
121
|
+
const compactedDocument = {
|
|
122
|
+
'@context': {
|
|
123
|
+
ex: 'https://example.org/vocab/',
|
|
124
|
+
id: '@id',
|
|
125
|
+
type: '@type',
|
|
126
|
+
name: 'ex:name'
|
|
127
|
+
},
|
|
128
|
+
id: 'urn:example:person:1',
|
|
129
|
+
type: 'ex:Person',
|
|
130
|
+
name: 'Ada'
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const failures: IValidationFailure[] = [];
|
|
134
|
+
await JsonLdHelper.validate(compactedDocument, failures, {
|
|
135
|
+
validationMode: ValidationMode.Either,
|
|
136
|
+
failOnMissingType: false
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const expanded = await JsonLdHelper.expand(compactedDocument);
|
|
140
|
+
const hasPersonType = await JsonLdHelper.isType(expanded, ['https://example.org/vocab/Person']);
|
|
141
|
+
const types = await JsonLdHelper.getType(expanded);
|
|
142
|
+
const id = await JsonLdHelper.getId(expanded);
|
|
143
|
+
|
|
144
|
+
console.log('Failure count:', failures.length);
|
|
145
|
+
console.log('Has person type:', hasPersonType);
|
|
146
|
+
console.log('Type list includes person:', types.includes('https://example.org/vocab/Person'));
|
|
147
|
+
console.log('Document id:', id);
|
|
148
|
+
|
|
149
|
+
const nodeObject = JsonLdHelper.toNodeObject(compactedDocument);
|
|
150
|
+
const structuredObject = JsonLdHelper.toStructuredObject<{ name: string }>(
|
|
151
|
+
nodeObject as IJsonLdNodeObject
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
console.log('Structured name:', structuredObject.name);
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
import { JsonLdHelper } from '@twin.org/data-json-ld';
|
|
159
|
+
|
|
160
|
+
const expandedDocument = [
|
|
161
|
+
{
|
|
162
|
+
'@id': 'urn:example:article:1',
|
|
163
|
+
'https://schema.org/name': [
|
|
164
|
+
{ '@value': 'Hello', '@language': 'en' },
|
|
165
|
+
{ '@value': 'Hallo', '@language': 'de' }
|
|
166
|
+
],
|
|
167
|
+
'https://schema.org/wordCount': [{ '@value': 240 }]
|
|
168
|
+
}
|
|
169
|
+
];
|
|
170
|
+
|
|
171
|
+
const title = await JsonLdHelper.getPropertyValue(
|
|
172
|
+
expandedDocument,
|
|
173
|
+
'https://schema.org/name',
|
|
174
|
+
'en'
|
|
175
|
+
);
|
|
176
|
+
const [nameValues, wordCountValues] = await JsonLdHelper.getPropertyValues(expandedDocument, [
|
|
177
|
+
'https://schema.org/name',
|
|
178
|
+
'https://schema.org/wordCount'
|
|
179
|
+
]);
|
|
180
|
+
|
|
181
|
+
console.log('English title:', title?.[0]);
|
|
182
|
+
console.log('Name value count:', nameValues?.length);
|
|
183
|
+
console.log('Word count value:', wordCountValues?.[0]);
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
import { JsonLdHelper } from '@twin.org/data-json-ld';
|
|
188
|
+
|
|
189
|
+
const node = {
|
|
190
|
+
'@id': 'urn:example:item:1',
|
|
191
|
+
name: 'Ada',
|
|
192
|
+
role: 'Engineer'
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
const prefixed = JsonLdHelper.prefixProperties(node, 'ex', ['name', 'role']);
|
|
196
|
+
const stripped = JsonLdHelper.stripPrefixProperties(prefixed, 'ex');
|
|
197
|
+
|
|
198
|
+
console.log('Prefixed name:', prefixed['ex:name']);
|
|
199
|
+
console.log('Stripped name:', stripped.name);
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## JsonLdDataTypes
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
import { DataTypeHelper } from '@twin.org/data-core';
|
|
206
|
+
import { JsonLdContexts, JsonLdDataTypes, JsonLdTypes } from '@twin.org/data-json-ld';
|
|
207
|
+
|
|
208
|
+
JsonLdDataTypes.registerTypes();
|
|
209
|
+
|
|
210
|
+
const schema = await DataTypeHelper.getSchemaForType(
|
|
211
|
+
`${JsonLdContexts.Namespace}${JsonLdTypes.Document}`
|
|
212
|
+
);
|
|
213
|
+
console.log('Registered schema type:', schema?.type);
|
|
214
|
+
```
|