@twin.org/data-json-ld 0.0.3-next.1 → 0.0.3-next.11

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 (34) hide show
  1. package/dist/es/dataTypes/jsonLdDataTypes.js +104 -131
  2. package/dist/es/dataTypes/jsonLdDataTypes.js.map +1 -1
  3. package/dist/es/helpers/jsonLdHelperTypes.js +2 -0
  4. package/dist/es/helpers/jsonLdHelperTypes.js.map +1 -0
  5. package/dist/es/index.js +1 -0
  6. package/dist/es/index.js.map +1 -1
  7. package/dist/es/models/jsonLdContexts.js +10 -2
  8. package/dist/es/models/jsonLdContexts.js.map +1 -1
  9. package/dist/es/utils/jsonLdHelper.js +213 -4
  10. package/dist/es/utils/jsonLdHelper.js.map +1 -1
  11. package/dist/es/utils/jsonLdProcessor.js +1 -1
  12. package/dist/es/utils/jsonLdProcessor.js.map +1 -1
  13. package/dist/types/helpers/jsonLdHelperTypes.d.ts +77 -0
  14. package/dist/types/index.d.ts +1 -0
  15. package/dist/types/models/jsonLdContexts.d.ts +10 -2
  16. package/dist/types/utils/jsonLdHelper.d.ts +65 -2
  17. package/docs/changelog.md +145 -0
  18. package/docs/reference/classes/JsonLdHelper.md +255 -3
  19. package/docs/reference/index.md +13 -0
  20. package/docs/reference/type-aliases/JsonLdAliasKey.md +15 -0
  21. package/docs/reference/type-aliases/JsonLdExistingProperty.md +19 -0
  22. package/docs/reference/type-aliases/JsonLdKeys.md +11 -0
  23. package/docs/reference/type-aliases/JsonLdObjectWithAliases.md +16 -0
  24. package/docs/reference/type-aliases/JsonLdObjectWithContext.md +21 -0
  25. package/docs/reference/type-aliases/JsonLdObjectWithId.md +21 -0
  26. package/docs/reference/type-aliases/JsonLdObjectWithOptionalContext.md +22 -0
  27. package/docs/reference/type-aliases/JsonLdObjectWithOptionalId.md +21 -0
  28. package/docs/reference/type-aliases/JsonLdObjectWithOptionalType.md +21 -0
  29. package/docs/reference/type-aliases/JsonLdObjectWithType.md +21 -0
  30. package/docs/reference/type-aliases/JsonLdOptionalKeys.md +11 -0
  31. package/docs/reference/type-aliases/JsonLdRequiredKeys.md +11 -0
  32. package/docs/reference/type-aliases/JsonLdWithAliases.md +17 -0
  33. package/docs/reference/variables/JsonLdContexts.md +15 -3
  34. package/package.json +2 -2
@@ -64,19 +64,69 @@ True if the document was valid.
64
64
 
65
65
  ***
66
66
 
67
+ ### toNodeObject()
68
+
69
+ > `static` **toNodeObject**\<`T`\>(`object`): `T` & [`IJsonLdNodeObject`](../interfaces/IJsonLdNodeObject.md)
70
+
71
+ Expand an object to a JSON-LD node object.
72
+
73
+ #### Type Parameters
74
+
75
+ ##### T
76
+
77
+ `T` = `unknown`
78
+
79
+ #### Parameters
80
+
81
+ ##### object
82
+
83
+ `T`
84
+
85
+ The object to expand.
86
+
87
+ #### Returns
88
+
89
+ `T` & [`IJsonLdNodeObject`](../interfaces/IJsonLdNodeObject.md)
90
+
91
+ The expanded JSON-LD node object.
92
+
93
+ ***
94
+
95
+ ### expand()
96
+
97
+ > `static` **expand**(`document`): `Promise`\<[`IJsonLdNodeObject`](../interfaces/IJsonLdNodeObject.md)[]\>
98
+
99
+ Expand the JSON-LD document.
100
+
101
+ #### Parameters
102
+
103
+ ##### document
104
+
105
+ [`IJsonLdDocument`](../type-aliases/IJsonLdDocument.md)
106
+
107
+ The JSON-LD document to expand.
108
+
109
+ #### Returns
110
+
111
+ `Promise`\<[`IJsonLdNodeObject`](../interfaces/IJsonLdNodeObject.md)[]\>
112
+
113
+ The expanded JSON-LD document.
114
+
115
+ ***
116
+
67
117
  ### isType()
68
118
 
69
- > `static` **isType**(`document`, `type`): `Promise`\<`boolean`\>
119
+ > `static` **isType**(`documentOrExpanded`, `type`): `Promise`\<`boolean`\>
70
120
 
71
121
  Expand the JSON-LD document and check if it is of a specific type.
72
122
 
73
123
  #### Parameters
74
124
 
75
- ##### document
125
+ ##### documentOrExpanded
76
126
 
77
127
  [`IJsonLdDocument`](../type-aliases/IJsonLdDocument.md)
78
128
 
79
- The JSON-LD document to check.
129
+ The JSON-LD document to check or already expanded document.
80
130
 
81
131
  ##### type
82
132
 
@@ -89,3 +139,205 @@ The type to check for.
89
139
  `Promise`\<`boolean`\>
90
140
 
91
141
  True if the document is of the specified type.
142
+
143
+ ***
144
+
145
+ ### getType()
146
+
147
+ > `static` **getType**(`documentOrExpanded`): `Promise`\<`string`[]\>
148
+
149
+ Get the types from the document.
150
+
151
+ #### Parameters
152
+
153
+ ##### documentOrExpanded
154
+
155
+ [`IJsonLdDocument`](../type-aliases/IJsonLdDocument.md)
156
+
157
+ The JSON-LD document to check or already expanded document.
158
+
159
+ #### Returns
160
+
161
+ `Promise`\<`string`[]\>
162
+
163
+ The type(s) extracted from the document.
164
+
165
+ ***
166
+
167
+ ### getId()
168
+
169
+ > `static` **getId**(`documentOrExpanded`, `additionalIdProperties?`): `Promise`\<`string` \| `undefined`\>
170
+
171
+ Get the id from the document.
172
+
173
+ #### Parameters
174
+
175
+ ##### documentOrExpanded
176
+
177
+ [`IJsonLdDocument`](../type-aliases/IJsonLdDocument.md)
178
+
179
+ The JSON-LD document to get the id from or already expanded document.
180
+
181
+ ##### additionalIdProperties?
182
+
183
+ `string`[]
184
+
185
+ Optional additional properties to check for the id, in addition to "@id" and "id".
186
+
187
+ #### Returns
188
+
189
+ `Promise`\<`string` \| `undefined`\>
190
+
191
+ The id extracted from the document.
192
+
193
+ ***
194
+
195
+ ### getPropertyValue()
196
+
197
+ > `static` **getPropertyValue**(`documentOrExpanded`, `propertyFullName`, `language?`): `Promise`\<[`IJsonLdNodePrimitive`](../type-aliases/IJsonLdNodePrimitive.md)[] \| `undefined`\>
198
+
199
+ Get property values by a single full expanded property name.
200
+
201
+ #### Parameters
202
+
203
+ ##### documentOrExpanded
204
+
205
+ [`IJsonLdDocument`](../type-aliases/IJsonLdDocument.md)
206
+
207
+ The JSON-LD document to get the property from or already expanded document.
208
+
209
+ ##### propertyFullName
210
+
211
+ `string`
212
+
213
+ The full expanded property name.
214
+
215
+ ##### language?
216
+
217
+ `string`
218
+
219
+ Optional filter values by their language property.
220
+
221
+ #### Returns
222
+
223
+ `Promise`\<[`IJsonLdNodePrimitive`](../type-aliases/IJsonLdNodePrimitive.md)[] \| `undefined`\>
224
+
225
+ Matching property values for the input property.
226
+
227
+ ***
228
+
229
+ ### getPropertyValues()
230
+
231
+ > `static` **getPropertyValues**(`documentOrExpanded`, `propertyFullNames`, `language?`): `Promise`\<([`IJsonLdNodePrimitive`](../type-aliases/IJsonLdNodePrimitive.md)[] \| `undefined`)[]\>
232
+
233
+ Get property values by their full expanded property names.
234
+
235
+ #### Parameters
236
+
237
+ ##### documentOrExpanded
238
+
239
+ [`IJsonLdDocument`](../type-aliases/IJsonLdDocument.md)
240
+
241
+ The JSON-LD document to get the property from or already expanded document.
242
+
243
+ ##### propertyFullNames
244
+
245
+ `string`[]
246
+
247
+ The full expanded property names.
248
+
249
+ ##### language?
250
+
251
+ `string`
252
+
253
+ Optional filter values by their language property.
254
+
255
+ #### Returns
256
+
257
+ `Promise`\<([`IJsonLdNodePrimitive`](../type-aliases/IJsonLdNodePrimitive.md)[] \| `undefined`)[]\>
258
+
259
+ Matching property values for each input property, in the same index order.
260
+
261
+ ***
262
+
263
+ ### prefixProperties()
264
+
265
+ > `static` **prefixProperties**\<`T`\>(`nodeObject`, `prefix`, `properties?`): [`IJsonLdNodeObject`](../interfaces/IJsonLdNodeObject.md)
266
+
267
+ Prefix all properties in the document with the provided prefix, except for JSON-LD properties.
268
+ This is useful for ensuring that all properties are fully qualified with a namespace.
269
+ For example, if the prefix is "ex" and the document has a property "name", it will be transformed to "ex:name".
270
+
271
+ #### Type Parameters
272
+
273
+ ##### T
274
+
275
+ `T` *extends* [`IJsonLdNodeObject`](../interfaces/IJsonLdNodeObject.md)
276
+
277
+ #### Parameters
278
+
279
+ ##### nodeObject
280
+
281
+ `T`
282
+
283
+ The JSON-LD node object to prefix properties on.
284
+
285
+ ##### prefix
286
+
287
+ `string`
288
+
289
+ The prefix to add to the properties.
290
+
291
+ ##### properties?
292
+
293
+ `string`[]
294
+
295
+ Optional list of properties to prefix. If not provided, all properties except for JSON-LD properties.
296
+
297
+ #### Returns
298
+
299
+ [`IJsonLdNodeObject`](../interfaces/IJsonLdNodeObject.md)
300
+
301
+ A new JSON-LD node object with the properties prefixed.
302
+
303
+ ***
304
+
305
+ ### stripPrefixProperties()
306
+
307
+ > `static` **stripPrefixProperties**\<`T`\>(`nodeObject`, `prefix`, `properties?`): [`IJsonLdNodeObject`](../interfaces/IJsonLdNodeObject.md)
308
+
309
+ Strip a prefix from properties in the document, except for JSON-LD properties.
310
+ This is useful for converting fully qualified namespaced properties back to local names.
311
+ For example, if the prefix is "ex" and the document has a property "ex:name", it will be transformed to "name".
312
+
313
+ #### Type Parameters
314
+
315
+ ##### T
316
+
317
+ `T` *extends* [`IJsonLdNodeObject`](../interfaces/IJsonLdNodeObject.md)
318
+
319
+ #### Parameters
320
+
321
+ ##### nodeObject
322
+
323
+ `T`
324
+
325
+ The JSON-LD node object to strip prefixed properties from.
326
+
327
+ ##### prefix
328
+
329
+ `string`
330
+
331
+ The prefix to remove from the properties.
332
+
333
+ ##### properties?
334
+
335
+ `string`[]
336
+
337
+ Optional list of unprefixed properties to strip. If not provided, all matching prefixed properties.
338
+
339
+ #### Returns
340
+
341
+ [`IJsonLdNodeObject`](../interfaces/IJsonLdNodeObject.md)
342
+
343
+ A new JSON-LD node object with the prefix stripped from matching properties.
@@ -22,6 +22,19 @@
22
22
 
23
23
  ## Type Aliases
24
24
 
25
+ - [JsonLdOptionalKeys](type-aliases/JsonLdOptionalKeys.md)
26
+ - [JsonLdRequiredKeys](type-aliases/JsonLdRequiredKeys.md)
27
+ - [JsonLdAliasKey](type-aliases/JsonLdAliasKey.md)
28
+ - [JsonLdWithAliases](type-aliases/JsonLdWithAliases.md)
29
+ - [JsonLdKeys](type-aliases/JsonLdKeys.md)
30
+ - [JsonLdObjectWithAliases](type-aliases/JsonLdObjectWithAliases.md)
31
+ - [JsonLdObjectWithContext](type-aliases/JsonLdObjectWithContext.md)
32
+ - [JsonLdExistingProperty](type-aliases/JsonLdExistingProperty.md)
33
+ - [JsonLdObjectWithOptionalContext](type-aliases/JsonLdObjectWithOptionalContext.md)
34
+ - [JsonLdObjectWithType](type-aliases/JsonLdObjectWithType.md)
35
+ - [JsonLdObjectWithOptionalType](type-aliases/JsonLdObjectWithOptionalType.md)
36
+ - [JsonLdObjectWithId](type-aliases/JsonLdObjectWithId.md)
37
+ - [JsonLdObjectWithOptionalId](type-aliases/JsonLdObjectWithOptionalId.md)
25
38
  - [IJsonLdContainerType](type-aliases/IJsonLdContainerType.md)
26
39
  - [IJsonLdContainerTypeArray](type-aliases/IJsonLdContainerTypeArray.md)
27
40
  - [IJsonLdContextDefinitionElement](type-aliases/IJsonLdContextDefinitionElement.md)
@@ -0,0 +1,15 @@
1
+ # Type Alias: JsonLdAliasKey\<K, Prefix\>
2
+
3
+ > **JsonLdAliasKey**\<`K`, `Prefix`\> = `K` *extends* `` `@${string}` `` ? `K` : `` `${Prefix}:${K}` ``
4
+
5
+ Keep JSON-LD keys as-is and prefix non-JSON-LD keys.
6
+
7
+ ## Type Parameters
8
+
9
+ ### K
10
+
11
+ `K` *extends* `string`
12
+
13
+ ### Prefix
14
+
15
+ `Prefix` *extends* `string`
@@ -0,0 +1,19 @@
1
+ # Type Alias: JsonLdExistingProperty\<T, P, D\>
2
+
3
+ > **JsonLdExistingProperty**\<`T`, `P`, `D`\> = `T` *extends* `{ [K in P]?: infer PropertyType }` ? `Exclude`\<`PropertyType`, `undefined`\> : `D`
4
+
5
+ Infer an existing property's type from a source type, or fall back to a default.
6
+
7
+ ## Type Parameters
8
+
9
+ ### T
10
+
11
+ `T` *extends* `object`
12
+
13
+ ### P
14
+
15
+ `P` *extends* `PropertyKey`
16
+
17
+ ### D
18
+
19
+ `D`
@@ -0,0 +1,11 @@
1
+ # Type Alias: JsonLdKeys\<T\>
2
+
3
+ > **JsonLdKeys**\<`T`\> = `Pick`\<`T`, `Extract`\<keyof `T`, `` `@${string}` ``\>\>
4
+
5
+ Keep only JSON-LD keys ("@...") from a type.
6
+
7
+ ## Type Parameters
8
+
9
+ ### T
10
+
11
+ `T` *extends* `object`
@@ -0,0 +1,16 @@
1
+ # Type Alias: JsonLdObjectWithAliases\<T, Prefix\>
2
+
3
+ > **JsonLdObjectWithAliases**\<`T`, `Prefix`\> = [`JsonLdKeys`](JsonLdKeys.md)\<`T`\> & [`JsonLdWithAliases`](JsonLdWithAliases.md)\<`T`, `Prefix`\>
4
+
5
+ Create a JSON-LD object shape containing only JSON-LD keys plus aliased
6
+ non-JSON-LD keys.
7
+
8
+ ## Type Parameters
9
+
10
+ ### T
11
+
12
+ `T` *extends* `object`
13
+
14
+ ### Prefix
15
+
16
+ `Prefix` *extends* `string`
@@ -0,0 +1,21 @@
1
+ # Type Alias: JsonLdObjectWithContext\<T, C\>
2
+
3
+ > **JsonLdObjectWithContext**\<`T`, `C`\> = `Omit`\<`T`, `"@context"`\> & `object`
4
+
5
+ Add "@context" to a type.
6
+
7
+ ## Type Declaration
8
+
9
+ ### @context
10
+
11
+ > **@context**: `C`
12
+
13
+ ## Type Parameters
14
+
15
+ ### T
16
+
17
+ `T` *extends* `object`
18
+
19
+ ### C
20
+
21
+ `C` = [`IJsonLdContextDefinitionRoot`](IJsonLdContextDefinitionRoot.md)
@@ -0,0 +1,21 @@
1
+ # Type Alias: JsonLdObjectWithId\<T, Id\>
2
+
3
+ > **JsonLdObjectWithId**\<`T`, `Id`\> = `Omit`\<`T`, `"@id"`\> & `object`
4
+
5
+ Add "@id" to a type.
6
+
7
+ ## Type Declaration
8
+
9
+ ### @id
10
+
11
+ > **@id**: `Id`
12
+
13
+ ## Type Parameters
14
+
15
+ ### T
16
+
17
+ `T` *extends* `object`
18
+
19
+ ### Id
20
+
21
+ `Id` = [`JsonLdExistingProperty`](JsonLdExistingProperty.md)\<`T`, `"@id"`, `string`\>
@@ -0,0 +1,22 @@
1
+ # Type Alias: JsonLdObjectWithOptionalContext\<T, C\>
2
+
3
+ > **JsonLdObjectWithOptionalContext**\<`T`, `C`\> = `Omit`\<`T`, `"@context"`\> & `object`
4
+
5
+ Add optional "@context" to a type, inferring an existing context type from
6
+ the source type when available, otherwise using the provided default.
7
+
8
+ ## Type Declaration
9
+
10
+ ### @context?
11
+
12
+ > `optional` **@context**: `C`
13
+
14
+ ## Type Parameters
15
+
16
+ ### T
17
+
18
+ `T` *extends* `object`
19
+
20
+ ### C
21
+
22
+ `C` = [`JsonLdExistingProperty`](JsonLdExistingProperty.md)\<`T`, `"@context"`, [`IJsonLdContextDefinitionRoot`](IJsonLdContextDefinitionRoot.md)\>
@@ -0,0 +1,21 @@
1
+ # Type Alias: JsonLdObjectWithOptionalId\<T, Id\>
2
+
3
+ > **JsonLdObjectWithOptionalId**\<`T`, `Id`\> = `Omit`\<`T`, `"@id"`\> & `object`
4
+
5
+ Add optional "@id" to a type.
6
+
7
+ ## Type Declaration
8
+
9
+ ### @id?
10
+
11
+ > `optional` **@id**: `Id`
12
+
13
+ ## Type Parameters
14
+
15
+ ### T
16
+
17
+ `T` *extends* `object`
18
+
19
+ ### Id
20
+
21
+ `Id` = [`JsonLdExistingProperty`](JsonLdExistingProperty.md)\<`T`, `"@id"`, `string`\>
@@ -0,0 +1,21 @@
1
+ # Type Alias: JsonLdObjectWithOptionalType\<T, Ty\>
2
+
3
+ > **JsonLdObjectWithOptionalType**\<`T`, `Ty`\> = `Omit`\<`T`, `"@type"`\> & `object`
4
+
5
+ Add optional "@type" to a type.
6
+
7
+ ## Type Declaration
8
+
9
+ ### @type?
10
+
11
+ > `optional` **@type**: `Ty`
12
+
13
+ ## Type Parameters
14
+
15
+ ### T
16
+
17
+ `T` *extends* `object`
18
+
19
+ ### Ty
20
+
21
+ `Ty` = [`JsonLdExistingProperty`](JsonLdExistingProperty.md)\<`T`, `"@type"`, `string` \| `string`[]\>
@@ -0,0 +1,21 @@
1
+ # Type Alias: JsonLdObjectWithType\<T, Ty\>
2
+
3
+ > **JsonLdObjectWithType**\<`T`, `Ty`\> = `Omit`\<`T`, `"@type"`\> & `object`
4
+
5
+ Add "@type" to a type.
6
+
7
+ ## Type Declaration
8
+
9
+ ### @type
10
+
11
+ > **@type**: `Ty`
12
+
13
+ ## Type Parameters
14
+
15
+ ### T
16
+
17
+ `T` *extends* `object`
18
+
19
+ ### Ty
20
+
21
+ `Ty` = [`JsonLdExistingProperty`](JsonLdExistingProperty.md)\<`T`, `"@type"`, `string` \| `string`[]\>
@@ -0,0 +1,11 @@
1
+ # Type Alias: JsonLdOptionalKeys\<T\>
2
+
3
+ > **JsonLdOptionalKeys**\<`T`\> = `{ [K in keyof T]-?: {} extends Pick<T, K> ? K : never }`\[keyof `T`\]
4
+
5
+ Extract the optional property names from a type.
6
+
7
+ ## Type Parameters
8
+
9
+ ### T
10
+
11
+ `T`
@@ -0,0 +1,11 @@
1
+ # Type Alias: JsonLdRequiredKeys\<T\>
2
+
3
+ > **JsonLdRequiredKeys**\<`T`\> = `Exclude`\<keyof `T`, [`JsonLdOptionalKeys`](JsonLdOptionalKeys.md)\<`T`\>\>
4
+
5
+ Extract the required property names from a type.
6
+
7
+ ## Type Parameters
8
+
9
+ ### T
10
+
11
+ `T`
@@ -0,0 +1,17 @@
1
+ # Type Alias: JsonLdWithAliases\<T, Prefix\>
2
+
3
+ > **JsonLdWithAliases**\<`T`, `Prefix`\> = `{ [K in Extract<JsonLdRequiredKeys<T>, string> as JsonLdAliasKey<K, Prefix>]: T[K] }` & `{ [K in Extract<JsonLdOptionalKeys<T>, string> as JsonLdAliasKey<K, Prefix>]?: T[K] }`
4
+
5
+ Remap an object type so JSON-LD keys ("@...") are preserved and
6
+ non-JSON-LD keys are exposed as `Prefix:key` aliases, while preserving
7
+ each key's original required/optional status.
8
+
9
+ ## Type Parameters
10
+
11
+ ### T
12
+
13
+ `T` *extends* `object`
14
+
15
+ ### Prefix
16
+
17
+ `Prefix` *extends* `string`
@@ -6,8 +6,20 @@ The contexts of JSON-LD data.
6
6
 
7
7
  ## Type Declaration
8
8
 
9
- ### ContextRoot
9
+ ### Namespace
10
10
 
11
- > `readonly` **ContextRoot**: `"https://schema.twindev.org/json-ld/"` = `"https://schema.twindev.org/json-ld/"`
11
+ > `readonly` **Namespace**: `"https://schema.twindev.org/json-ld/"` = `"https://schema.twindev.org/json-ld/"`
12
12
 
13
- Context Root.
13
+ The canonical RDF namespace URI for JSON-LD.
14
+
15
+ ### Context
16
+
17
+ > `readonly` **Context**: `"https://schema.twindev.org/json-ld/"` = `"https://schema.twindev.org/json-ld/"`
18
+
19
+ The value to use in JSON-LD context for JSON-LD.
20
+
21
+ ### JsonLdContext
22
+
23
+ > `readonly` **JsonLdContext**: `"https://schema.twindev.org/json-ld/types.jsonld"` = `"https://schema.twindev.org/json-ld/types.jsonld"`
24
+
25
+ The JSON-LD Context URL for JSON-LD.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/data-json-ld",
3
- "version": "0.0.3-next.1",
3
+ "version": "0.0.3-next.11",
4
4
  "description": "Models which define the structure of JSON LD",
5
5
  "repository": {
6
6
  "type": "git",
@@ -15,7 +15,7 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "@twin.org/core": "next",
18
- "@twin.org/data-core": "0.0.3-next.1",
18
+ "@twin.org/data-core": "0.0.3-next.11",
19
19
  "@twin.org/entity": "next",
20
20
  "@twin.org/nameof": "next",
21
21
  "@twin.org/web": "next",