@twin.org/data-json-ld 0.0.1-next.3 → 0.0.1-next.30

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 (67) hide show
  1. package/dist/cjs/index.cjs +613 -350
  2. package/dist/esm/index.mjs +615 -353
  3. package/dist/types/index.d.ts +26 -0
  4. package/dist/types/models/IJsonLdContainerType.d.ts +8 -0
  5. package/dist/types/models/IJsonLdContainerTypeArray.d.ts +9 -0
  6. package/dist/types/models/IJsonLdContextDefinition.d.ts +25 -0
  7. package/dist/types/models/IJsonLdContextDefinitionElement.d.ts +9 -0
  8. package/dist/types/models/IJsonLdContextDefinitionRoot.d.ts +9 -0
  9. package/dist/types/models/IJsonLdDocument.d.ts +2 -189
  10. package/dist/types/models/IJsonLdExpandedTermDefinition.d.ts +28 -0
  11. package/dist/types/models/IJsonLdGraphObject.d.ts +16 -0
  12. package/dist/types/models/IJsonLdIdMap.d.ts +12 -0
  13. package/dist/types/models/IJsonLdIncludedBlock.d.ts +10 -0
  14. package/dist/types/models/IJsonLdIndexMap.d.ts +13 -0
  15. package/dist/types/models/IJsonLdIndexMapItem.d.ts +12 -0
  16. package/dist/types/models/IJsonLdJsonArray.d.ts +9 -0
  17. package/dist/types/models/IJsonLdJsonObject.d.ts +11 -0
  18. package/dist/types/models/IJsonLdJsonPrimitive.d.ts +8 -0
  19. package/dist/types/models/IJsonLdJsonValue.d.ts +11 -0
  20. package/dist/types/models/IJsonLdKeyword.d.ts +42 -0
  21. package/dist/types/models/IJsonLdLanguageMap.d.ts +11 -0
  22. package/dist/types/models/IJsonLdListObject.d.ts +13 -0
  23. package/dist/types/models/IJsonLdListOrSetItem.d.ts +10 -0
  24. package/dist/types/models/IJsonLdNodeObject.d.ts +19 -0
  25. package/dist/types/models/IJsonLdNodePrimitive.d.ts +13 -0
  26. package/dist/types/models/IJsonLdObject.d.ts +24 -0
  27. package/dist/types/models/IJsonLdSetObject.d.ts +13 -0
  28. package/dist/types/models/IJsonLdTypeMap.d.ts +12 -0
  29. package/dist/types/models/IJsonLdValueObject.d.ts +26 -0
  30. package/dist/types/models/jsonLdContexts.d.ts +13 -0
  31. package/dist/types/models/jsonLdTypes.d.ts +27 -23
  32. package/dist/types/utils/jsonLdProcessor.d.ts +82 -8
  33. package/docs/changelog.md +29 -1
  34. package/docs/reference/classes/JsonLdDataTypes.md +3 -3
  35. package/docs/reference/classes/JsonLdHelper.md +16 -8
  36. package/docs/reference/classes/JsonLdProcessor.md +312 -16
  37. package/docs/reference/index.md +20 -15
  38. package/docs/reference/interfaces/IJsonLdContextDefinition.md +1 -1
  39. package/docs/reference/interfaces/IJsonLdGraphObject.md +1 -1
  40. package/docs/reference/interfaces/IJsonLdIdMap.md +1 -1
  41. package/docs/reference/interfaces/IJsonLdIndexMap.md +1 -1
  42. package/docs/reference/interfaces/IJsonLdJsonObject.md +3 -1
  43. package/docs/reference/interfaces/IJsonLdLanguageMap.md +1 -1
  44. package/docs/reference/interfaces/IJsonLdNodeObject.md +40 -4
  45. package/docs/reference/interfaces/IJsonLdObject.md +64 -0
  46. package/docs/reference/interfaces/IJsonLdTypeMap.md +1 -1
  47. package/docs/reference/type-aliases/IJsonLdContainerType.md +3 -1
  48. package/docs/reference/type-aliases/IJsonLdContainerTypeArray.md +3 -1
  49. package/docs/reference/type-aliases/IJsonLdContextDefinitionElement.md +5 -0
  50. package/docs/reference/type-aliases/IJsonLdContextDefinitionRoot.md +5 -0
  51. package/docs/reference/type-aliases/IJsonLdDocument.md +1 -1
  52. package/docs/reference/type-aliases/IJsonLdExpandedTermDefinition.md +1 -1
  53. package/docs/reference/type-aliases/IJsonLdIncludedBlock.md +1 -1
  54. package/docs/reference/type-aliases/IJsonLdIndexMapItem.md +1 -1
  55. package/docs/reference/type-aliases/IJsonLdJsonArray.md +3 -1
  56. package/docs/reference/type-aliases/IJsonLdJsonPrimitive.md +3 -1
  57. package/docs/reference/type-aliases/IJsonLdJsonValue.md +3 -1
  58. package/docs/reference/type-aliases/IJsonLdKeyword.md +51 -7
  59. package/docs/reference/type-aliases/IJsonLdListOrSetItem.md +1 -1
  60. package/docs/reference/type-aliases/IJsonLdNodePrimitive.md +1 -1
  61. package/docs/reference/type-aliases/IJsonLdValueObject.md +1 -1
  62. package/docs/reference/type-aliases/JsonLdContexts.md +5 -0
  63. package/docs/reference/type-aliases/JsonLdTypes.md +1 -1
  64. package/docs/reference/variables/JsonLdContexts.md +13 -0
  65. package/docs/reference/variables/JsonLdTypes.md +29 -23
  66. package/locales/en.json +8 -3
  67. package/package.json +7 -37
@@ -1,8 +1,21 @@
1
1
  import { DataTypeHandlerFactory, DataTypeHelper } from '@twin.org/data-core';
2
- import { Is, GeneralError } from '@twin.org/core';
3
- import { FetchHelper, HttpMethod, MimeTypes } from '@twin.org/web';
2
+ import { Is, SharedStore, ObjectHelper, GeneralError } from '@twin.org/core';
3
+ import { FetchHelper, HttpMethod, MimeTypes, HeaderTypes } from '@twin.org/web';
4
4
  import jsonLd from 'jsonld';
5
5
 
6
+ // Copyright 2024 IOTA Stiftung.
7
+ // SPDX-License-Identifier: Apache-2.0.
8
+ /**
9
+ * The contexts of JSON-LD data.
10
+ */
11
+ // eslint-disable-next-line @typescript-eslint/naming-convention
12
+ const JsonLdContexts = {
13
+ /**
14
+ * Context Root.
15
+ */
16
+ ContextRoot: "https://schema.twindev.org/json-ld/"
17
+ };
18
+
6
19
  // Copyright 2024 IOTA Stiftung.
7
20
  // SPDX-License-Identifier: Apache-2.0.
8
21
  /**
@@ -13,107 +26,113 @@ const JsonLdTypes = {
13
26
  /**
14
27
  * Represents JSON-LD Document.
15
28
  */
16
- Document: "https://schema.twindev.org/json-ld/JsonLdDocument",
29
+ Document: "JsonLdDocument",
30
+ /**
31
+ * Represents JSON-LD Object.
32
+ */
33
+ Object: "JsonLdObject",
17
34
  /**
18
35
  * Represents JSON-LD Node Object.
19
36
  */
20
- NodeObject: "https://schema.twindev.org/json-ld/JsonLdNodeObject",
37
+ NodeObject: "JsonLdNodeObject",
21
38
  /**
22
39
  * Represents JSON-LD Node Primitive.
23
40
  */
24
- NodePrimitive: "https://schema.twindev.org/json-ld/JsonLdNodePrimitive",
41
+ NodePrimitive: "JsonLdNodePrimitive",
25
42
  /**
26
43
  * Represents JSON-LD Graph Object.
27
44
  */
28
- GraphObject: "https://schema.twindev.org/json-ld/JsonLdGraphObject",
45
+ GraphObject: "JsonLdGraphObject",
29
46
  /**
30
47
  * Represents JSON-LD Value Object.
31
48
  */
32
- ValueObject: "https://schema.twindev.org/json-ld/JsonLdValueObject",
49
+ ValueObject: "JsonLdValueObject",
33
50
  /**
34
51
  * Represents JSON-LD List Object.
35
52
  */
36
- ListObject: "https://schema.twindev.org/json-ld/JsonLdListObject",
53
+ ListObject: "JsonLdListObject",
37
54
  /**
38
55
  * Represents JSON-LD Set Object.
39
56
  */
40
- SetObject: "https://schema.twindev.org/json-ld/JsonLdSetObject",
57
+ SetObject: "JsonLdSetObject",
41
58
  /**
42
59
  * Represents JSON-LD Language Map.
43
60
  */
44
- LanguageMap: "https://schema.twindev.org/json-ld/JsonLdLanguageMap",
61
+ LanguageMap: "JsonLdLanguageMap",
45
62
  /**
46
63
  * Represents JSON-LD Index Map.
47
64
  */
48
- IndexMap: "https://schema.twindev.org/json-ld/JsonLdIndexMap",
65
+ IndexMap: "JsonLdIndexMap",
49
66
  /**
50
67
  * Represents JSON-LD Index Map Item.
51
68
  */
52
- IndexMapItem: "https://schema.twindev.org/json-ld/JsonLdIndexMapItem",
69
+ IndexMapItem: "JsonLdIndexMapItem",
53
70
  /**
54
71
  * Represents JSON-LD Id Map.
55
72
  */
56
- IdMap: "https://schema.twindev.org/json-ld/JsonLdIdMap",
73
+ IdMap: "JsonLdIdMap",
57
74
  /**
58
75
  * Represents JSON-LD Type Map.
59
76
  */
60
- TypeMap: "https://schema.twindev.org/json-ld/JsonLdTypeMap",
77
+ TypeMap: "JsonLdTypeMap",
61
78
  /**
62
79
  * Represents JSON-LD Included block.
63
80
  */
64
- IncludedBlock: "https://schema.twindev.org/json-ld/JsonLdIncludedBlock",
81
+ IncludedBlock: "JsonLdIncludedBlock",
65
82
  /**
66
83
  * Represents JSON-LD Context Definition.
67
84
  */
68
- ContextDefinition: "https://schema.twindev.org/json-ld/JsonLdContextDefinition",
85
+ ContextDefinition: "JsonLdContextDefinition",
69
86
  /**
70
87
  * Represents JSON-LD Expanded Term Definition.
71
88
  */
72
- ExpandedTermDefinition: "https://schema.twindev.org/json-ld/JsonLdExpandedTermDefinition",
89
+ ExpandedTermDefinition: "JsonLdExpandedTermDefinition",
73
90
  /**
74
91
  * Represents JSON-LD Keyword.
75
92
  */
76
- Keyword: "https://schema.twindev.org/json-ld/JsonLdKeyword",
93
+ Keyword: "JsonLdKeyword",
77
94
  /**
78
95
  * Represents JSON-LD List or Set Item.
79
96
  */
80
- ListOrSetItem: "https://schema.twindev.org/json-ld/JsonLdListOrSetItem",
97
+ ListOrSetItem: "JsonLdListOrSetItem",
81
98
  /**
82
99
  * Represents JSON-LD Container Type.
83
100
  */
84
- ContainerType: "https://schema.twindev.org/json-ld/JsonLdContainerType",
101
+ ContainerType: "JsonLdContainerType",
85
102
  /**
86
103
  * Represents JSON-LD Container Type Array.
87
104
  */
88
- ContainerTypeArray: "https://schema.twindev.org/json-ld/JsonLdContainerTypeArray",
105
+ ContainerTypeArray: "JsonLdContainerTypeArray",
89
106
  /**
90
107
  * Represents JSON-LD JSON Primitive.
91
108
  */
92
- JsonPrimitive: "https://schema.twindev.org/json-ld/JsonLdJsonPrimitive",
109
+ JsonPrimitive: "JsonLdJsonPrimitive",
93
110
  /**
94
111
  * Represents JSON-LD JSON Array.
95
112
  */
96
- JsonArray: "https://schema.twindev.org/json-ld/JsonLdJsonArray",
113
+ JsonArray: "JsonLdJsonArray",
97
114
  /**
98
115
  * Represents JSON-LD JSON Object.
99
116
  */
100
- JsonObject: "https://schema.twindev.org/json-ld/JsonLdJsonObject",
117
+ JsonObject: "JsonLdJsonObject",
101
118
  /**
102
119
  * Represents JSON-LD JSON Value.
103
120
  */
104
- JsonValue: "https://schema.twindev.org/json-ld/JsonLdJsonValue"
121
+ JsonValue: "JsonLdJsonValue"
105
122
  };
106
123
 
107
- var type$d = "string";
124
+ var type$e = "string";
125
+ var description$n = "Helper Types";
108
126
  var JsonLdContainerTypeSchema = {
109
- type: type$d,
127
+ type: type$e,
110
128
  "enum": [
111
129
  "@language",
112
130
  "@index",
113
131
  "@id",
114
132
  "@graph",
115
133
  "@type"
116
- ]
134
+ ],
135
+ description: description$n
117
136
  };
118
137
 
119
138
  var anyOf$8 = [
@@ -290,29 +309,42 @@ var anyOf$8 = [
290
309
  maxItems: 2
291
310
  }
292
311
  ];
312
+ var description$m = "Helper Types.";
293
313
  var JsonLdContainerTypeArraySchema = {
294
- anyOf: anyOf$8
314
+ anyOf: anyOf$8,
315
+ description: description$m
295
316
  };
296
317
 
297
- var type$c = "object";
298
- var properties$5 = {
318
+ var type$d = "object";
319
+ var properties$6 = {
299
320
  "@base": {
300
- $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
321
+ type: [
322
+ "string",
323
+ "null"
324
+ ]
301
325
  },
302
326
  "@direction": {
303
- $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
327
+ type: [
328
+ "string",
329
+ "null"
330
+ ],
331
+ "enum": [
332
+ "ltr",
333
+ "rtl",
334
+ null
335
+ ]
304
336
  },
305
337
  "@import": {
306
- $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
338
+ type: "string"
307
339
  },
308
340
  "@language": {
309
- $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
341
+ type: "string"
310
342
  },
311
343
  "@propagate": {
312
- $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
344
+ type: "boolean"
313
345
  },
314
346
  "@protected": {
315
- $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
347
+ type: "boolean"
316
348
  },
317
349
  "@type": {
318
350
  type: "object",
@@ -322,7 +354,7 @@ var properties$5 = {
322
354
  "const": "@set"
323
355
  },
324
356
  "@protected": {
325
- $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
357
+ type: "boolean"
326
358
  }
327
359
  },
328
360
  required: [
@@ -331,13 +363,17 @@ var properties$5 = {
331
363
  additionalProperties: false
332
364
  },
333
365
  "@version": {
334
- $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
366
+ type: "string",
367
+ "const": "1.1"
335
368
  },
336
369
  "@vocab": {
337
- $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
370
+ type: [
371
+ "string",
372
+ "null"
373
+ ]
338
374
  }
339
375
  };
340
- var additionalProperties$a = {
376
+ var additionalProperties$b = {
341
377
  anyOf: [
342
378
  {
343
379
  type: "null"
@@ -350,12 +386,12 @@ var additionalProperties$a = {
350
386
  }
351
387
  ]
352
388
  };
353
- var description$g = "A context definition defines a local context in a node object.";
389
+ var description$l = "A context definition defines a local context in a node object.";
354
390
  var JsonLdContextDefinitionSchema = {
355
- type: type$c,
356
- properties: properties$5,
357
- additionalProperties: additionalProperties$a,
358
- description: description$g
391
+ type: type$d,
392
+ properties: properties$6,
393
+ additionalProperties: additionalProperties$b,
394
+ description: description$l
359
395
  };
360
396
 
361
397
  var anyOf$7 = [
@@ -372,33 +408,7 @@ var anyOf$7 = [
372
408
  type: "object",
373
409
  properties: {
374
410
  "@context": {
375
- anyOf: [
376
- {
377
- type: "null"
378
- },
379
- {
380
- type: "string"
381
- },
382
- {
383
- $ref: "https://schema.twindev.org/json-ld/JsonLdContextDefinition"
384
- },
385
- {
386
- type: "array",
387
- items: {
388
- anyOf: [
389
- {
390
- type: "null"
391
- },
392
- {
393
- type: "string"
394
- },
395
- {
396
- $ref: "https://schema.twindev.org/json-ld/JsonLdContextDefinition"
397
- }
398
- ]
399
- }
400
- }
401
- ]
411
+ $ref: "https://schema.twindev.org/json-ld/JsonLdContextDefinitionRoot"
402
412
  },
403
413
  "@graph": {
404
414
  anyOf: [
@@ -427,10 +437,10 @@ var anyOf$7 = [
427
437
  additionalProperties: false
428
438
  }
429
439
  ];
430
- var description$f = "A JSON-LD document MUST be valid JSON text as described in [RFC8259], or some format that can be represented in the JSON-LD internal representation that is equivalent to valid JSON text.";
440
+ var description$k = "A JSON-LD document MUST be valid JSON text as described in [RFC8259], or some format that can be represented in the JSON-LD internal representation that is equivalent to valid JSON text.";
431
441
  var JsonLdDocumentSchema = {
432
442
  anyOf: anyOf$7,
433
- description: description$f
443
+ description: description$k
434
444
  };
435
445
 
436
446
  var anyOf$6 = [
@@ -441,7 +451,13 @@ var anyOf$6 = [
441
451
  "@id": {
442
452
  anyOf: [
443
453
  {
444
- $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
454
+ type: "string"
455
+ },
456
+ {
457
+ type: "array",
458
+ items: {
459
+ type: "string"
460
+ }
445
461
  },
446
462
  {
447
463
  type: "null"
@@ -452,28 +468,64 @@ var anyOf$6 = [
452
468
  type: "string"
453
469
  },
454
470
  "@container": {
455
- $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
471
+ anyOf: [
472
+ {
473
+ type: "string",
474
+ "const": "@list"
475
+ },
476
+ {
477
+ type: "string",
478
+ "const": "@set"
479
+ },
480
+ {
481
+ $ref: "https://schema.twindev.org/json-ld/JsonLdContainerType"
482
+ },
483
+ {
484
+ type: "array",
485
+ items: {
486
+ anyOf: [
487
+ {
488
+ type: "string",
489
+ "const": "@list"
490
+ },
491
+ {
492
+ type: "string",
493
+ "const": "@set"
494
+ },
495
+ {
496
+ $ref: "https://schema.twindev.org/json-ld/JsonLdContainerType"
497
+ }
498
+ ]
499
+ }
500
+ },
501
+ {
502
+ $ref: "https://schema.twindev.org/json-ld/JsonLdContainerTypeArray"
503
+ },
504
+ {
505
+ type: "null"
506
+ }
507
+ ]
456
508
  },
457
509
  "@type": {
458
510
  type: "string"
459
511
  },
460
512
  "@language": {
461
- $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
513
+ type: "string"
462
514
  },
463
515
  "@index": {
464
- $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
516
+ type: "string"
465
517
  },
466
518
  "@context": {
467
519
  $ref: "https://schema.twindev.org/json-ld/JsonLdContextDefinition"
468
520
  },
469
521
  "@prefix": {
470
- $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
522
+ type: "boolean"
471
523
  },
472
524
  "@propagate": {
473
- $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
525
+ type: "boolean"
474
526
  },
475
527
  "@protected": {
476
- $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
528
+ type: "boolean"
477
529
  }
478
530
  }
479
531
  },
@@ -482,7 +534,7 @@ var anyOf$6 = [
482
534
  additionalProperties: false,
483
535
  properties: {
484
536
  "@reverse": {
485
- $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
537
+ type: "string"
486
538
  },
487
539
  "@container": {
488
540
  type: [
@@ -499,22 +551,22 @@ var anyOf$6 = [
499
551
  type: "string"
500
552
  },
501
553
  "@language": {
502
- $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
554
+ type: "string"
503
555
  },
504
556
  "@index": {
505
- $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
557
+ type: "string"
506
558
  },
507
559
  "@context": {
508
560
  $ref: "https://schema.twindev.org/json-ld/JsonLdContextDefinition"
509
561
  },
510
562
  "@prefix": {
511
- $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
563
+ type: "boolean"
512
564
  },
513
565
  "@propagate": {
514
- $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
566
+ type: "boolean"
515
567
  },
516
568
  "@protected": {
517
- $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
569
+ type: "boolean"
518
570
  }
519
571
  },
520
572
  required: [
@@ -522,14 +574,14 @@ var anyOf$6 = [
522
574
  ]
523
575
  }
524
576
  ];
525
- var description$e = "An expanded term definition is used to describe the mapping between a term and its expanded identifier, as well as other properties of the value associated with the term when it is used as key in a node object.";
577
+ var description$j = "An expanded term definition is used to describe the mapping between a term and its expanded identifier, as well as other properties of the value associated with the term when it is used as key in a node object.";
526
578
  var JsonLdExpandedTermDefinitionSchema = {
527
579
  anyOf: anyOf$6,
528
- description: description$e
580
+ description: description$j
529
581
  };
530
582
 
531
- var type$b = "object";
532
- var properties$4 = {
583
+ var type$c = "object";
584
+ var properties$5 = {
533
585
  "@graph": {
534
586
  anyOf: [
535
587
  {
@@ -544,73 +596,37 @@ var properties$4 = {
544
596
  ]
545
597
  },
546
598
  "@index": {
547
- type: "string"
599
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
548
600
  },
549
601
  "@id": {
550
- anyOf: [
551
- {
552
- type: "string"
553
- },
554
- {
555
- type: "array",
556
- items: {
557
- type: "string"
558
- }
559
- }
560
- ]
602
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
561
603
  },
562
604
  "@context": {
563
- anyOf: [
564
- {
565
- type: "null"
566
- },
567
- {
568
- type: "string"
569
- },
570
- {
571
- $ref: "https://schema.twindev.org/json-ld/JsonLdContextDefinition"
572
- },
573
- {
574
- type: "array",
575
- items: {
576
- anyOf: [
577
- {
578
- type: "null"
579
- },
580
- {
581
- type: "string"
582
- },
583
- {
584
- $ref: "https://schema.twindev.org/json-ld/JsonLdContextDefinition"
585
- }
586
- ]
587
- }
588
- }
589
- ]
605
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
590
606
  }
591
607
  };
592
608
  var required$3 = [
593
609
  "@graph"
594
610
  ];
595
- var additionalProperties$9 = false;
596
- var description$d = "A graph object represents a named graph, which MAY include an explicit graph name.";
611
+ var additionalProperties$a = false;
612
+ var description$i = "A graph object represents a named graph, which MAY include an explicit graph name.";
597
613
  var JsonLdGraphObjectSchema = {
598
- type: type$b,
599
- properties: properties$4,
614
+ type: type$c,
615
+ properties: properties$5,
600
616
  required: required$3,
601
- additionalProperties: additionalProperties$9,
602
- description: description$d
617
+ additionalProperties: additionalProperties$a,
618
+ description: description$i
603
619
  };
604
620
 
605
- var type$a = "object";
606
- var additionalProperties$8 = {
621
+ var type$b = "object";
622
+ var additionalProperties$9 = {
607
623
  $ref: "https://schema.twindev.org/json-ld/JsonLdNodeObject"
608
624
  };
609
- var description$c = "An id map is used to associate an IRI with a value that allows easy programmatic access.";
625
+ var description$h = "An id map is used to associate an IRI with a value that allows easy programmatic access.";
610
626
  var JsonLdIdMapSchema = {
611
- type: type$a,
612
- additionalProperties: additionalProperties$8,
613
- description: description$c
627
+ type: type$b,
628
+ additionalProperties: additionalProperties$9,
629
+ description: description$h
614
630
  };
615
631
 
616
632
  var anyOf$5 = [
@@ -624,14 +640,14 @@ var anyOf$5 = [
624
640
  }
625
641
  }
626
642
  ];
627
- var description$b = "An included block is used to provide a set of node objects.";
643
+ var description$g = "An included block is used to provide a set of node objects.";
628
644
  var JsonLdIncludedBlockSchema = {
629
645
  anyOf: anyOf$5,
630
- description: description$b
646
+ description: description$g
631
647
  };
632
648
 
633
- var type$9 = "object";
634
- var additionalProperties$7 = {
649
+ var type$a = "object";
650
+ var additionalProperties$8 = {
635
651
  anyOf: [
636
652
  {
637
653
  $ref: "https://schema.twindev.org/json-ld/JsonLdIndexMapItem"
@@ -644,11 +660,11 @@ var additionalProperties$7 = {
644
660
  }
645
661
  ]
646
662
  };
647
- var description$a = "An index map allows keys that have no semantic meaning, but should be preserved regardless, to be used in JSON-LD documents.";
663
+ var description$f = "An index map allows keys that have no semantic meaning, but should be preserved regardless, to be used in JSON-LD documents.";
648
664
  var JsonLdIndexMapSchema = {
649
- type: type$9,
650
- additionalProperties: additionalProperties$7,
651
- description: description$a
665
+ type: type$a,
666
+ additionalProperties: additionalProperties$8,
667
+ description: description$f
652
668
  };
653
669
 
654
670
  var anyOf$4 = [
@@ -677,23 +693,25 @@ var anyOf$4 = [
677
693
  $ref: "https://schema.twindev.org/json-ld/JsonLdSetObject"
678
694
  }
679
695
  ];
680
- var description$9 = "The items that can be stored in an index map.";
696
+ var description$e = "The items that can be stored in an index map.";
681
697
  var JsonLdIndexMapItemSchema = {
682
698
  anyOf: anyOf$4,
683
- description: description$9
699
+ description: description$e
684
700
  };
685
701
 
686
- var type$8 = "array";
702
+ var type$9 = "array";
687
703
  var items = {
688
704
  $ref: "https://schema.twindev.org/json-ld/JsonLdJsonValue"
689
705
  };
706
+ var description$d = "JSON Type for array.";
690
707
  var JsonLdJsonArraySchema = {
691
- type: type$8,
692
- items: items
708
+ type: type$9,
709
+ items: items,
710
+ description: description$d
693
711
  };
694
712
 
695
- var type$7 = "object";
696
- var additionalProperties$6 = {
713
+ var type$8 = "object";
714
+ var additionalProperties$7 = {
697
715
  anyOf: [
698
716
  {
699
717
  $ref: "https://schema.twindev.org/json-ld/JsonLdJsonValue"
@@ -704,19 +722,23 @@ var additionalProperties$6 = {
704
722
  }
705
723
  ]
706
724
  };
725
+ var description$c = "JSON Type for object.";
707
726
  var JsonLdJsonObjectSchema = {
708
- type: type$7,
709
- additionalProperties: additionalProperties$6
727
+ type: type$8,
728
+ additionalProperties: additionalProperties$7,
729
+ description: description$c
710
730
  };
711
731
 
712
- var type$6 = [
732
+ var type$7 = [
713
733
  "string",
714
734
  "number",
715
735
  "boolean",
716
736
  "null"
717
737
  ];
738
+ var description$b = "JSON Primitive.";
718
739
  var JsonLdJsonPrimitiveSchema = {
719
- type: type$6
740
+ type: type$7,
741
+ description: description$b
720
742
  };
721
743
 
722
744
  var anyOf$3 = [
@@ -730,12 +752,14 @@ var anyOf$3 = [
730
752
  $ref: "https://schema.twindev.org/json-ld/JsonLdJsonObject"
731
753
  }
732
754
  ];
755
+ var description$a = "JSON Value.";
733
756
  var JsonLdJsonValueSchema = {
734
- anyOf: anyOf$3
757
+ anyOf: anyOf$3,
758
+ description: description$a
735
759
  };
736
760
 
737
- var type$5 = "object";
738
- var properties$3 = {
761
+ var type$6 = "object";
762
+ var properties$4 = {
739
763
  "@base": {
740
764
  type: [
741
765
  "string",
@@ -782,33 +806,7 @@ var properties$3 = {
782
806
  ]
783
807
  },
784
808
  "@context": {
785
- anyOf: [
786
- {
787
- type: "null"
788
- },
789
- {
790
- type: "string"
791
- },
792
- {
793
- $ref: "https://schema.twindev.org/json-ld/JsonLdContextDefinition"
794
- },
795
- {
796
- type: "array",
797
- items: {
798
- anyOf: [
799
- {
800
- type: "null"
801
- },
802
- {
803
- type: "string"
804
- },
805
- {
806
- $ref: "https://schema.twindev.org/json-ld/JsonLdContextDefinition"
807
- }
808
- ]
809
- }
810
- }
811
- ]
809
+ $ref: "https://schema.twindev.org/json-ld/JsonLdContextDefinitionRoot"
812
810
  },
813
811
  "@direction": {
814
812
  type: [
@@ -965,18 +963,18 @@ var required$2 = [
965
963
  "@version",
966
964
  "@vocab"
967
965
  ];
968
- var additionalProperties$5 = false;
969
- var description$8 = "A list of keywords and their types. Only used for internal reference; not an actual interface. Not for export.";
966
+ var additionalProperties$6 = false;
967
+ var description$9 = "A list of keywords and their types. Only used for internal reference; not an actual interface. Not for export.";
970
968
  var JsonLdKeywordSchema = {
971
- type: type$5,
972
- properties: properties$3,
969
+ type: type$6,
970
+ properties: properties$4,
973
971
  required: required$2,
974
- additionalProperties: additionalProperties$5,
975
- description: description$8
972
+ additionalProperties: additionalProperties$6,
973
+ description: description$9
976
974
  };
977
975
 
978
- var type$4 = "object";
979
- var additionalProperties$4 = {
976
+ var type$5 = "object";
977
+ var additionalProperties$5 = {
980
978
  anyOf: [
981
979
  {
982
980
  type: "null"
@@ -992,43 +990,33 @@ var additionalProperties$4 = {
992
990
  }
993
991
  ]
994
992
  };
995
- var description$7 = "A language map is used to associate a language with a value in a way that allows easy programmatic access.";
993
+ var description$8 = "A language map is used to associate a language with a value in a way that allows easy programmatic access.";
996
994
  var JsonLdLanguageMapSchema = {
997
- type: type$4,
998
- additionalProperties: additionalProperties$4,
999
- description: description$7
995
+ type: type$5,
996
+ additionalProperties: additionalProperties$5,
997
+ description: description$8
1000
998
  };
1001
999
 
1002
- var type$3 = "object";
1003
- var properties$2 = {
1000
+ var type$4 = "object";
1001
+ var properties$3 = {
1004
1002
  "@list": {
1005
- anyOf: [
1006
- {
1007
- $ref: "https://schema.twindev.org/json-ld/JsonLdListOrSetItem"
1008
- },
1009
- {
1010
- type: "array",
1011
- items: {
1012
- $ref: "https://schema.twindev.org/json-ld/JsonLdListOrSetItem"
1013
- }
1014
- }
1015
- ]
1003
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
1016
1004
  },
1017
1005
  "@index": {
1018
- type: "string"
1006
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
1019
1007
  }
1020
1008
  };
1021
1009
  var required$1 = [
1022
1010
  "@list"
1023
1011
  ];
1024
- var additionalProperties$3 = false;
1025
- var description$6 = "A list represents an ordered set of values.";
1012
+ var additionalProperties$4 = false;
1013
+ var description$7 = "A list represents an ordered set of values.";
1026
1014
  var JsonLdListObjectSchema = {
1027
- type: type$3,
1028
- properties: properties$2,
1015
+ type: type$4,
1016
+ properties: properties$3,
1029
1017
  required: required$1,
1030
- additionalProperties: additionalProperties$3,
1031
- description: description$6
1018
+ additionalProperties: additionalProperties$4,
1019
+ description: description$7
1032
1020
  };
1033
1021
 
1034
1022
  var anyOf$2 = [
@@ -1051,58 +1039,47 @@ var anyOf$2 = [
1051
1039
  $ref: "https://schema.twindev.org/json-ld/JsonLdValueObject"
1052
1040
  }
1053
1041
  ];
1054
- var description$5 = "A list or set item can be a null, boolean, number, string, node object, or value object.";
1042
+ var description$6 = "A list or set item can be a null, boolean, number, string, node object, or value object.";
1055
1043
  var JsonLdListOrSetItemSchema = {
1056
1044
  anyOf: anyOf$2,
1057
- description: description$5
1045
+ description: description$6
1058
1046
  };
1059
1047
 
1060
- var type$2 = "object";
1061
- var properties$1 = {
1048
+ var type$3 = "object";
1049
+ var additionalProperties$3 = {
1050
+ anyOf: [
1051
+ {
1052
+ $ref: "https://schema.twindev.org/json-ld/JsonLdNodePrimitive"
1053
+ },
1054
+ {
1055
+ $ref: "https://schema.twindev.org/json-ld/JsonLdLanguageMap"
1056
+ },
1057
+ {
1058
+ $ref: "https://schema.twindev.org/json-ld/JsonLdIndexMap"
1059
+ },
1060
+ {
1061
+ $ref: "https://schema.twindev.org/json-ld/JsonLdIncludedBlock"
1062
+ },
1063
+ {
1064
+ $ref: "https://schema.twindev.org/json-ld/JsonLdIdMap"
1065
+ },
1066
+ {
1067
+ $ref: "https://schema.twindev.org/json-ld/JsonLdTypeMap"
1068
+ },
1069
+ {
1070
+ type: "array"
1071
+ }
1072
+ ]
1073
+ };
1074
+ var properties$2 = {
1062
1075
  "@context": {
1063
- anyOf: [
1064
- {
1065
- type: "null"
1066
- },
1067
- {
1068
- type: "string"
1069
- },
1070
- {
1071
- $ref: "https://schema.twindev.org/json-ld/JsonLdContextDefinition"
1072
- },
1073
- {
1074
- type: "array",
1075
- items: {
1076
- anyOf: [
1077
- {
1078
- type: "null"
1079
- },
1080
- {
1081
- type: "string"
1082
- },
1083
- {
1084
- $ref: "https://schema.twindev.org/json-ld/JsonLdContextDefinition"
1085
- }
1086
- ]
1087
- }
1088
- }
1089
- ]
1076
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
1090
1077
  },
1091
1078
  "@id": {
1092
- anyOf: [
1093
- {
1094
- type: "string"
1095
- },
1096
- {
1097
- type: "array",
1098
- items: {
1099
- type: "string"
1100
- }
1101
- }
1102
- ]
1079
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
1103
1080
  },
1104
1081
  "@included": {
1105
- $ref: "https://schema.twindev.org/json-ld/JsonLdIncludedBlock"
1082
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
1106
1083
  },
1107
1084
  "@graph": {
1108
1085
  anyOf: [
@@ -1133,12 +1110,12 @@ var properties$1 = {
1133
1110
  "@type": {
1134
1111
  anyOf: [
1135
1112
  {
1136
- type: "string"
1113
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
1137
1114
  },
1138
1115
  {
1139
1116
  type: "array",
1140
1117
  items: {
1141
- type: "string"
1118
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
1142
1119
  }
1143
1120
  }
1144
1121
  ]
@@ -1146,47 +1123,19 @@ var properties$1 = {
1146
1123
  "@reverse": {
1147
1124
  type: "object",
1148
1125
  additionalProperties: {
1149
- type: "string"
1126
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
1150
1127
  }
1151
1128
  },
1152
1129
  "@index": {
1153
- type: "string"
1130
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
1154
1131
  }
1155
1132
  };
1156
- var additionalProperties$2 = {
1157
- anyOf: [
1158
- {
1159
- $ref: "https://schema.twindev.org/json-ld/JsonLdNodePrimitive"
1160
- },
1161
- {
1162
- type: "array",
1163
- items: {
1164
- $ref: "https://schema.twindev.org/json-ld/JsonLdNodePrimitive"
1165
- }
1166
- },
1167
- {
1168
- $ref: "https://schema.twindev.org/json-ld/JsonLdLanguageMap"
1169
- },
1170
- {
1171
- $ref: "https://schema.twindev.org/json-ld/JsonLdIndexMap"
1172
- },
1173
- {
1174
- $ref: "https://schema.twindev.org/json-ld/JsonLdIncludedBlock"
1175
- },
1176
- {
1177
- $ref: "https://schema.twindev.org/json-ld/JsonLdIdMap"
1178
- },
1179
- {
1180
- $ref: "https://schema.twindev.org/json-ld/JsonLdTypeMap"
1181
- }
1182
- ]
1183
- };
1184
- var description$4 = "A node object represents zero or more properties of a node in the graph serialized by the JSON-LD document.";
1133
+ var description$5 = "A node object represents zero or more properties of a node in the graph serialized by the JSON-LD document.";
1185
1134
  var JsonLdNodeObjectSchema = {
1186
- type: type$2,
1187
- properties: properties$1,
1188
- additionalProperties: additionalProperties$2,
1189
- description: description$4
1135
+ type: type$3,
1136
+ additionalProperties: additionalProperties$3,
1137
+ properties: properties$2,
1138
+ description: description$5
1190
1139
  };
1191
1140
 
1192
1141
  var anyOf$1 = [
@@ -1218,29 +1167,88 @@ var anyOf$1 = [
1218
1167
  $ref: "https://schema.twindev.org/json-ld/JsonLdSetObject"
1219
1168
  }
1220
1169
  ];
1221
- var description$3 = "A node primitive is a JSON-LD value which is not one of the defined NodeObject properties.";
1170
+ var description$4 = "A node primitive is a JSON-LD value which is not one of the defined NodeObject properties.";
1222
1171
  var JsonLdNodePrimitiveSchema = {
1223
1172
  anyOf: anyOf$1,
1224
- description: description$3
1173
+ description: description$4
1225
1174
  };
1226
1175
 
1227
- var type$1 = "object";
1228
- var properties = {
1229
- "@set": {
1176
+ var type$2 = "object";
1177
+ var properties$1 = {
1178
+ "@context": {
1179
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
1180
+ },
1181
+ "@id": {
1182
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
1183
+ },
1184
+ "@included": {
1185
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
1186
+ },
1187
+ "@graph": {
1230
1188
  anyOf: [
1231
1189
  {
1232
- $ref: "https://schema.twindev.org/json-ld/JsonLdListOrSetItem"
1190
+ $ref: "https://schema.twindev.org/json-ld/JsonLdNodeObject"
1233
1191
  },
1234
1192
  {
1235
1193
  type: "array",
1236
1194
  items: {
1237
- $ref: "https://schema.twindev.org/json-ld/JsonLdListOrSetItem"
1195
+ $ref: "https://schema.twindev.org/json-ld/JsonLdNodeObject"
1238
1196
  }
1239
1197
  }
1240
1198
  ]
1241
1199
  },
1200
+ "@nest": {
1201
+ anyOf: [
1202
+ {
1203
+ $ref: "https://schema.twindev.org/json-ld/JsonLdJsonObject"
1204
+ },
1205
+ {
1206
+ type: "array",
1207
+ items: {
1208
+ $ref: "https://schema.twindev.org/json-ld/JsonLdJsonObject"
1209
+ }
1210
+ }
1211
+ ]
1212
+ },
1213
+ "@type": {
1214
+ anyOf: [
1215
+ {
1216
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
1217
+ },
1218
+ {
1219
+ type: "array",
1220
+ items: {
1221
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
1222
+ }
1223
+ }
1224
+ ]
1225
+ },
1226
+ "@reverse": {
1227
+ type: "object",
1228
+ additionalProperties: {
1229
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
1230
+ }
1231
+ },
1242
1232
  "@index": {
1243
- type: "string"
1233
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
1234
+ }
1235
+ };
1236
+ var additionalProperties$2 = false;
1237
+ var description$3 = "An object represents the pre-defined properties of the node object in the graph serialized by the JSON-LD document.";
1238
+ var JsonLdObjectSchema = {
1239
+ type: type$2,
1240
+ properties: properties$1,
1241
+ additionalProperties: additionalProperties$2,
1242
+ description: description$3
1243
+ };
1244
+
1245
+ var type$1 = "object";
1246
+ var properties = {
1247
+ "@set": {
1248
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
1249
+ },
1250
+ "@index": {
1251
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
1244
1252
  }
1245
1253
  };
1246
1254
  var required = [
@@ -1371,99 +1379,103 @@ class JsonLdDataTypes {
1371
1379
  * Register all the data types.
1372
1380
  */
1373
1381
  static registerTypes() {
1374
- DataTypeHandlerFactory.register(JsonLdTypes.Document, () => ({
1382
+ DataTypeHandlerFactory.register(`${JsonLdContexts.ContextRoot}${JsonLdTypes.Document}`, () => ({
1375
1383
  type: JsonLdTypes.Document,
1376
1384
  jsonSchema: async () => JsonLdDocumentSchema
1377
1385
  }));
1378
- DataTypeHandlerFactory.register(JsonLdTypes.NodeObject, () => ({
1386
+ DataTypeHandlerFactory.register(`${JsonLdContexts.ContextRoot}${JsonLdTypes.Object}`, () => ({
1387
+ type: JsonLdTypes.Object,
1388
+ jsonSchema: async () => JsonLdObjectSchema
1389
+ }));
1390
+ DataTypeHandlerFactory.register(`${JsonLdContexts.ContextRoot}${JsonLdTypes.NodeObject}`, () => ({
1379
1391
  type: JsonLdTypes.NodeObject,
1380
1392
  jsonSchema: async () => JsonLdNodeObjectSchema
1381
1393
  }));
1382
- DataTypeHandlerFactory.register(JsonLdTypes.NodePrimitive, () => ({
1394
+ DataTypeHandlerFactory.register(`${JsonLdContexts.ContextRoot}${JsonLdTypes.NodePrimitive}`, () => ({
1383
1395
  type: JsonLdTypes.NodePrimitive,
1384
1396
  jsonSchema: async () => JsonLdNodePrimitiveSchema
1385
1397
  }));
1386
- DataTypeHandlerFactory.register(JsonLdTypes.GraphObject, () => ({
1398
+ DataTypeHandlerFactory.register(`${JsonLdContexts.ContextRoot}${JsonLdTypes.GraphObject}`, () => ({
1387
1399
  type: JsonLdTypes.GraphObject,
1388
1400
  jsonSchema: async () => JsonLdGraphObjectSchema
1389
1401
  }));
1390
- DataTypeHandlerFactory.register(JsonLdTypes.ValueObject, () => ({
1402
+ DataTypeHandlerFactory.register(`${JsonLdContexts.ContextRoot}${JsonLdTypes.ValueObject}`, () => ({
1391
1403
  type: JsonLdTypes.ValueObject,
1392
1404
  jsonSchema: async () => JsonLdValueObjectSchema
1393
1405
  }));
1394
- DataTypeHandlerFactory.register(JsonLdTypes.ListObject, () => ({
1406
+ DataTypeHandlerFactory.register(`${JsonLdContexts.ContextRoot}${JsonLdTypes.ListObject}`, () => ({
1395
1407
  type: JsonLdTypes.ListObject,
1396
1408
  jsonSchema: async () => JsonLdListObjectSchema
1397
1409
  }));
1398
- DataTypeHandlerFactory.register(JsonLdTypes.ListObject, () => ({
1410
+ DataTypeHandlerFactory.register(`${JsonLdContexts.ContextRoot}${JsonLdTypes.ListObject}`, () => ({
1399
1411
  type: JsonLdTypes.ListObject,
1400
1412
  jsonSchema: async () => JsonLdListObjectSchema
1401
1413
  }));
1402
- DataTypeHandlerFactory.register(JsonLdTypes.SetObject, () => ({
1414
+ DataTypeHandlerFactory.register(`${JsonLdContexts.ContextRoot}${JsonLdTypes.SetObject}`, () => ({
1403
1415
  type: JsonLdTypes.SetObject,
1404
1416
  jsonSchema: async () => JsonLdSetObjectSchema
1405
1417
  }));
1406
- DataTypeHandlerFactory.register(JsonLdTypes.LanguageMap, () => ({
1418
+ DataTypeHandlerFactory.register(`${JsonLdContexts.ContextRoot}${JsonLdTypes.LanguageMap}`, () => ({
1407
1419
  type: JsonLdTypes.LanguageMap,
1408
1420
  jsonSchema: async () => JsonLdLanguageMapSchema
1409
1421
  }));
1410
- DataTypeHandlerFactory.register(JsonLdTypes.IndexMap, () => ({
1422
+ DataTypeHandlerFactory.register(`${JsonLdContexts.ContextRoot}${JsonLdTypes.IndexMap}`, () => ({
1411
1423
  type: JsonLdTypes.IndexMap,
1412
1424
  jsonSchema: async () => JsonLdIndexMapSchema
1413
1425
  }));
1414
- DataTypeHandlerFactory.register(JsonLdTypes.IndexMapItem, () => ({
1426
+ DataTypeHandlerFactory.register(`${JsonLdContexts.ContextRoot}${JsonLdTypes.IndexMapItem}`, () => ({
1415
1427
  type: JsonLdTypes.IndexMapItem,
1416
1428
  jsonSchema: async () => JsonLdIndexMapItemSchema
1417
1429
  }));
1418
- DataTypeHandlerFactory.register(JsonLdTypes.IdMap, () => ({
1430
+ DataTypeHandlerFactory.register(`${JsonLdContexts.ContextRoot}${JsonLdTypes.IdMap}`, () => ({
1419
1431
  type: JsonLdTypes.IdMap,
1420
1432
  jsonSchema: async () => JsonLdIdMapSchema
1421
1433
  }));
1422
- DataTypeHandlerFactory.register(JsonLdTypes.TypeMap, () => ({
1434
+ DataTypeHandlerFactory.register(`${JsonLdContexts.ContextRoot}${JsonLdTypes.TypeMap}`, () => ({
1423
1435
  type: JsonLdTypes.TypeMap,
1424
1436
  jsonSchema: async () => JsonLdTypeMapSchema
1425
1437
  }));
1426
- DataTypeHandlerFactory.register(JsonLdTypes.IncludedBlock, () => ({
1438
+ DataTypeHandlerFactory.register(`${JsonLdContexts.ContextRoot}${JsonLdTypes.IncludedBlock}`, () => ({
1427
1439
  type: JsonLdTypes.IncludedBlock,
1428
1440
  jsonSchema: async () => JsonLdIncludedBlockSchema
1429
1441
  }));
1430
- DataTypeHandlerFactory.register(JsonLdTypes.ContextDefinition, () => ({
1442
+ DataTypeHandlerFactory.register(`${JsonLdContexts.ContextRoot}${JsonLdTypes.ContextDefinition}`, () => ({
1431
1443
  type: JsonLdTypes.ContextDefinition,
1432
1444
  jsonSchema: async () => JsonLdContextDefinitionSchema
1433
1445
  }));
1434
- DataTypeHandlerFactory.register(JsonLdTypes.ExpandedTermDefinition, () => ({
1446
+ DataTypeHandlerFactory.register(`${JsonLdContexts.ContextRoot}${JsonLdTypes.ExpandedTermDefinition}`, () => ({
1435
1447
  type: JsonLdTypes.ExpandedTermDefinition,
1436
1448
  jsonSchema: async () => JsonLdExpandedTermDefinitionSchema
1437
1449
  }));
1438
- DataTypeHandlerFactory.register(JsonLdTypes.Keyword, () => ({
1450
+ DataTypeHandlerFactory.register(`${JsonLdContexts.ContextRoot}${JsonLdTypes.Keyword}`, () => ({
1439
1451
  type: JsonLdTypes.Keyword,
1440
1452
  jsonSchema: async () => JsonLdKeywordSchema
1441
1453
  }));
1442
- DataTypeHandlerFactory.register(JsonLdTypes.ListOrSetItem, () => ({
1454
+ DataTypeHandlerFactory.register(`${JsonLdContexts.ContextRoot}${JsonLdTypes.ListOrSetItem}`, () => ({
1443
1455
  type: JsonLdTypes.ListOrSetItem,
1444
1456
  jsonSchema: async () => JsonLdListOrSetItemSchema
1445
1457
  }));
1446
- DataTypeHandlerFactory.register(JsonLdTypes.ContainerType, () => ({
1458
+ DataTypeHandlerFactory.register(`${JsonLdContexts.ContextRoot}${JsonLdTypes.ContainerType}`, () => ({
1447
1459
  type: JsonLdTypes.ContainerType,
1448
1460
  jsonSchema: async () => JsonLdContainerTypeSchema
1449
1461
  }));
1450
- DataTypeHandlerFactory.register(JsonLdTypes.ContainerTypeArray, () => ({
1462
+ DataTypeHandlerFactory.register(`${JsonLdContexts.ContextRoot}${JsonLdTypes.ContainerTypeArray}`, () => ({
1451
1463
  type: JsonLdTypes.ContainerTypeArray,
1452
1464
  jsonSchema: async () => JsonLdContainerTypeArraySchema
1453
1465
  }));
1454
- DataTypeHandlerFactory.register(JsonLdTypes.JsonPrimitive, () => ({
1466
+ DataTypeHandlerFactory.register(`${JsonLdContexts.ContextRoot}${JsonLdTypes.JsonPrimitive}`, () => ({
1455
1467
  type: JsonLdTypes.JsonPrimitive,
1456
1468
  jsonSchema: async () => JsonLdJsonPrimitiveSchema
1457
1469
  }));
1458
- DataTypeHandlerFactory.register(JsonLdTypes.JsonArray, () => ({
1470
+ DataTypeHandlerFactory.register(`${JsonLdContexts.ContextRoot}${JsonLdTypes.JsonArray}`, () => ({
1459
1471
  type: JsonLdTypes.JsonArray,
1460
1472
  jsonSchema: async () => JsonLdJsonArraySchema
1461
1473
  }));
1462
- DataTypeHandlerFactory.register(JsonLdTypes.JsonObject, () => ({
1474
+ DataTypeHandlerFactory.register(`${JsonLdContexts.ContextRoot}${JsonLdTypes.JsonObject}`, () => ({
1463
1475
  type: JsonLdTypes.JsonObject,
1464
1476
  jsonSchema: async () => JsonLdJsonObjectSchema
1465
1477
  }));
1466
- DataTypeHandlerFactory.register(JsonLdTypes.JsonValue, () => ({
1478
+ DataTypeHandlerFactory.register(`${JsonLdContexts.ContextRoot}${JsonLdTypes.JsonValue}`, () => ({
1467
1479
  type: JsonLdTypes.JsonValue,
1468
1480
  jsonSchema: async () => JsonLdJsonValueSchema
1469
1481
  }));
@@ -1519,26 +1531,95 @@ class JsonLdProcessor {
1519
1531
  */
1520
1532
  static _CLASS_NAME = "JsonLdProcessor";
1521
1533
  /**
1522
- * Redirects to use during document resolution.
1534
+ * The document loader to use.
1535
+ * @param documentLoader The document loader to use.
1523
1536
  */
1524
- static _redirects = [];
1537
+ static setDocumentLoader(documentLoader) {
1538
+ SharedStore.set("jsonLdDocumentLoader", documentLoader);
1539
+ }
1525
1540
  /**
1526
- * The document loader to use.
1541
+ * The document loader to use for retrieving JSON-LD documents.
1542
+ * @returns The document loader.
1543
+ */
1544
+ static getDocumentLoader() {
1545
+ let documentLoader = SharedStore.get("jsonLdDocumentLoader");
1546
+ if (Is.empty(documentLoader)) {
1547
+ documentLoader = async (url) => JsonLdProcessor.documentLoader(url);
1548
+ }
1549
+ return documentLoader;
1550
+ }
1551
+ /**
1552
+ * Set the cache time limit for documents.
1553
+ * @param cacheLimitMs The cache limit in milliseconds.
1527
1554
  */
1528
- static DOCUMENT_LOADER = async (url) => JsonLdProcessor.documentLoader(url);
1555
+ static setCacheLimit(cacheLimitMs) {
1556
+ SharedStore.set("jsonLdDocumentCacheLimit", cacheLimitMs);
1557
+ }
1558
+ /**
1559
+ * Get the cache limit for documents.
1560
+ * @returns The document loader.
1561
+ */
1562
+ static getCacheLimit() {
1563
+ let cacheLimitMs = SharedStore.get("jsonLdDocumentCacheLimit");
1564
+ if (Is.empty(cacheLimitMs)) {
1565
+ cacheLimitMs = 3600000;
1566
+ SharedStore.set("jsonLdDocumentCacheLimit", cacheLimitMs);
1567
+ }
1568
+ return cacheLimitMs;
1569
+ }
1570
+ /**
1571
+ * Set the global redirects for JSON-LD, use addRedirect for default handling.
1572
+ * @param redirects The redirects to use.
1573
+ */
1574
+ static setRedirects(redirects) {
1575
+ SharedStore.set("jsonLdRedirects", redirects);
1576
+ }
1577
+ /**
1578
+ * Get the global redirects for JSON-LD.
1579
+ * @returns The registered redirects.
1580
+ */
1581
+ static getRedirects() {
1582
+ let redirects = SharedStore.get("jsonLdRedirects");
1583
+ if (Is.empty(redirects)) {
1584
+ redirects = [];
1585
+ SharedStore.set("jsonLdRedirects", redirects);
1586
+ }
1587
+ return redirects;
1588
+ }
1529
1589
  /**
1530
1590
  * Compact a document according to a particular context.
1531
1591
  * @param document The JSON-LD document to compact.
1532
- * @param context The context to compact the document to.
1592
+ * @param context The context to compact the document to, if not provided will try and gather from the object.
1533
1593
  * @returns The compacted JSON-LD document.
1534
1594
  */
1535
1595
  static async compact(document, context) {
1536
1596
  try {
1537
- return jsonLd.compact(document, context ?? {}, {
1538
- documentLoader: JsonLdProcessor.DOCUMENT_LOADER
1539
- });
1597
+ if (Is.object(document)) {
1598
+ if (Is.empty(context)) {
1599
+ context = {};
1600
+ if (Is.array(document)) {
1601
+ for (const node of document) {
1602
+ context = JsonLdProcessor.gatherContexts(node, context);
1603
+ }
1604
+ }
1605
+ else if (Is.array(document["@graph"])) {
1606
+ for (const node of document["@graph"]) {
1607
+ context = JsonLdProcessor.gatherContexts(node, context);
1608
+ }
1609
+ }
1610
+ else if (Is.object(document)) {
1611
+ context = JsonLdProcessor.gatherContexts(document, context);
1612
+ }
1613
+ }
1614
+ const compacted = await jsonLd.compact(ObjectHelper.removeEmptyProperties(document), context, {
1615
+ documentLoader: JsonLdProcessor.getDocumentLoader()
1616
+ });
1617
+ return compacted;
1618
+ }
1619
+ return document;
1540
1620
  }
1541
1621
  catch (err) {
1622
+ JsonLdProcessor.handleCommonErrors(err);
1542
1623
  throw new GeneralError(JsonLdProcessor._CLASS_NAME, "compact", undefined, err);
1543
1624
  }
1544
1625
  }
@@ -1549,24 +1630,189 @@ class JsonLdProcessor {
1549
1630
  */
1550
1631
  static async expand(compacted) {
1551
1632
  try {
1552
- return jsonLd.expand(compacted, {
1553
- documentLoader: JsonLdProcessor.DOCUMENT_LOADER
1554
- });
1633
+ if (Is.object(compacted)) {
1634
+ const expanded = await jsonLd.expand(ObjectHelper.removeEmptyProperties(compacted), {
1635
+ documentLoader: JsonLdProcessor.getDocumentLoader()
1636
+ });
1637
+ return expanded;
1638
+ }
1639
+ return [];
1555
1640
  }
1556
1641
  catch (err) {
1642
+ JsonLdProcessor.handleCommonErrors(err);
1557
1643
  throw new GeneralError(JsonLdProcessor._CLASS_NAME, "expand", undefined, err);
1558
1644
  }
1559
1645
  }
1646
+ /**
1647
+ * Canonize a document.
1648
+ * @param document The document to canonize.
1649
+ * @param options The options for canonization.
1650
+ * @param options.algorithm The algorithm to use for canonization, defaults to URDNA2015.
1651
+ * @returns The canonized document.
1652
+ */
1653
+ static async canonize(document, options) {
1654
+ try {
1655
+ const normalized = await jsonLd.canonize(ObjectHelper.removeEmptyProperties(document), {
1656
+ algorithm: options?.algorithm ?? "URDNA2015",
1657
+ format: "application/n-quads",
1658
+ documentLoader: JsonLdProcessor.getDocumentLoader()
1659
+ });
1660
+ return normalized;
1661
+ }
1662
+ catch (err) {
1663
+ JsonLdProcessor.handleCommonErrors(err);
1664
+ throw new GeneralError(JsonLdProcessor._CLASS_NAME, "canonize", undefined, err);
1665
+ }
1666
+ }
1560
1667
  /**
1561
1668
  * Add a redirect to use during document resolution.
1562
1669
  * @param from The URL to redirect from.
1563
1670
  * @param to The URL to redirect to.
1564
1671
  */
1565
1672
  static addRedirect(from, to) {
1566
- if (!this._redirects.some(r => r.from === from)) {
1567
- this._redirects.push({ from, to });
1673
+ const redirects = JsonLdProcessor.getRedirects();
1674
+ if (!redirects.some(r => r.from === from)) {
1675
+ redirects.push({ from, to });
1568
1676
  }
1569
1677
  }
1678
+ /**
1679
+ * Combine contexts.
1680
+ * @param context1 The first JSON-LD context to combine.
1681
+ * @param context2 The second JSON-LD context to combine.
1682
+ * @returns The combined context.
1683
+ */
1684
+ static combineContexts(context1, context2) {
1685
+ const combinedContext = [];
1686
+ if (Is.string(context1)) {
1687
+ if (!combinedContext.includes(context1)) {
1688
+ combinedContext.push(context1);
1689
+ }
1690
+ }
1691
+ else if (Is.array(context1)) {
1692
+ for (const context of context1) {
1693
+ const hasMatch = combinedContext.some(c => ObjectHelper.equal(c, context));
1694
+ if (!hasMatch) {
1695
+ combinedContext.push(context);
1696
+ }
1697
+ }
1698
+ }
1699
+ else if (Is.object(context1)) {
1700
+ const hasMatch = combinedContext.some(c => ObjectHelper.equal(c, context1));
1701
+ if (!hasMatch) {
1702
+ combinedContext.push(context1);
1703
+ }
1704
+ }
1705
+ if (Is.string(context2)) {
1706
+ if (!combinedContext.includes(context2)) {
1707
+ combinedContext.push(context2);
1708
+ }
1709
+ }
1710
+ else if (Is.array(context2)) {
1711
+ for (const context of context2) {
1712
+ const hasMatch = combinedContext.some(c => ObjectHelper.equal(c, context));
1713
+ if (!hasMatch) {
1714
+ combinedContext.push(context);
1715
+ }
1716
+ }
1717
+ }
1718
+ else if (Is.object(context2)) {
1719
+ const hasMatch = combinedContext.some(c => ObjectHelper.equal(c, context2));
1720
+ if (!hasMatch) {
1721
+ combinedContext.push(context2);
1722
+ }
1723
+ }
1724
+ if (combinedContext.length === 0) {
1725
+ return null;
1726
+ }
1727
+ if (combinedContext.length === 1) {
1728
+ return combinedContext[0];
1729
+ }
1730
+ return combinedContext;
1731
+ }
1732
+ /**
1733
+ * Gather all the contexts from the element and it's children.
1734
+ * @param element The element to gather the contexts from.
1735
+ * @param initial The initial context.
1736
+ * @returns The combined contexts.
1737
+ */
1738
+ static gatherContexts(element, initial) {
1739
+ let combinedContexts = initial;
1740
+ if (Is.object(element)) {
1741
+ if (!Is.empty(element["@context"])) {
1742
+ combinedContexts = JsonLdProcessor.combineContexts(initial, element["@context"]);
1743
+ }
1744
+ for (const prop of Object.keys(element)) {
1745
+ const value = element[prop];
1746
+ if (Is.object(value)) {
1747
+ combinedContexts = this.gatherContexts(value, combinedContexts);
1748
+ }
1749
+ else if (Is.array(value)) {
1750
+ for (const item of value) {
1751
+ if (Is.object(item)) {
1752
+ combinedContexts = this.gatherContexts(item, combinedContexts);
1753
+ }
1754
+ }
1755
+ }
1756
+ }
1757
+ }
1758
+ return combinedContexts;
1759
+ }
1760
+ /**
1761
+ * Remove all the contexts that match the pattern.
1762
+ * @param context The context to remove the entries from.
1763
+ * @param match The element to try and match.
1764
+ * @returns The updated contexts.
1765
+ */
1766
+ static removeContexts(context, match) {
1767
+ if (!Is.arrayValue(match)) {
1768
+ return context;
1769
+ }
1770
+ let finalContext;
1771
+ if (Is.string(context)) {
1772
+ for (const m of match) {
1773
+ if (context === m) {
1774
+ break;
1775
+ }
1776
+ }
1777
+ }
1778
+ else if (Is.array(context)) {
1779
+ for (const item of context) {
1780
+ const hasMatch = match.some(m => ObjectHelper.equal(m, item));
1781
+ if (!hasMatch) {
1782
+ finalContext ??= [];
1783
+ if (Is.array(finalContext)) {
1784
+ finalContext.push(item);
1785
+ }
1786
+ }
1787
+ }
1788
+ }
1789
+ else if (Is.object(context)) {
1790
+ const hasMatch = match.some(m => ObjectHelper.equal(m, context));
1791
+ if (!hasMatch) {
1792
+ finalContext = context;
1793
+ }
1794
+ }
1795
+ return Is.arrayValue(finalContext) && finalContext.length === 1
1796
+ ? finalContext[0]
1797
+ : finalContext;
1798
+ }
1799
+ /**
1800
+ * Add a context directly to the document loader cache.
1801
+ * @param url The url the ld context is for.
1802
+ * @param ldContext The context to add.
1803
+ * @returns Nothing.
1804
+ */
1805
+ static async documentCacheAdd(url, ldContext) {
1806
+ await FetchHelper.setCacheEntry(url, ldContext);
1807
+ }
1808
+ /**
1809
+ * Remove a context from the document loader cache.
1810
+ * @param url The url the ld context is for.
1811
+ * @returns Nothing.
1812
+ */
1813
+ static async documentCacheRemove(url) {
1814
+ await FetchHelper.removeCacheEntry(url);
1815
+ }
1570
1816
  /**
1571
1817
  * Document loader which uses a caching mechanism.
1572
1818
  * @param url The document url to load.
@@ -1574,7 +1820,8 @@ class JsonLdProcessor {
1574
1820
  * @internal
1575
1821
  */
1576
1822
  static async documentLoader(url) {
1577
- for (const redirect of JsonLdProcessor._redirects) {
1823
+ const redirects = JsonLdProcessor.getRedirects();
1824
+ for (const redirect of redirects) {
1578
1825
  if (redirect.from.test(url)) {
1579
1826
  url = redirect.to;
1580
1827
  break;
@@ -1582,9 +1829,9 @@ class JsonLdProcessor {
1582
1829
  }
1583
1830
  // Cache the results for an hour
1584
1831
  const response = await FetchHelper.fetchJson(JsonLdProcessor._CLASS_NAME, url, HttpMethod.GET, undefined, {
1585
- cacheTtlMs: 3600000,
1832
+ cacheTtlMs: JsonLdProcessor.getCacheLimit(),
1586
1833
  headers: {
1587
- Accept: `${MimeTypes.JsonLd},${MimeTypes.Json}`
1834
+ [HeaderTypes.Accept]: `${MimeTypes.JsonLd},${MimeTypes.Json}`
1588
1835
  }
1589
1836
  });
1590
1837
  return {
@@ -1592,6 +1839,21 @@ class JsonLdProcessor {
1592
1839
  document: response
1593
1840
  };
1594
1841
  }
1842
+ /**
1843
+ * Handle common errors.
1844
+ * @param err The error to handle.
1845
+ * @internal
1846
+ */
1847
+ static handleCommonErrors(err) {
1848
+ if (Is.object(err) &&
1849
+ err.name === "jsonld.InvalidUrl") {
1850
+ throw new GeneralError(JsonLdProcessor._CLASS_NAME, "invalidUrl", { url: err.details?.url }, err);
1851
+ }
1852
+ else if (Is.object(err) &&
1853
+ err.name.startsWith("jsonld.")) {
1854
+ throw new GeneralError(JsonLdProcessor._CLASS_NAME, "jsonLdError", err.details, err);
1855
+ }
1856
+ }
1595
1857
  }
1596
1858
 
1597
- export { JsonLdDataTypes, JsonLdHelper, JsonLdProcessor, JsonLdTypes };
1859
+ export { JsonLdContexts, JsonLdDataTypes, JsonLdHelper, JsonLdProcessor, JsonLdTypes };