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

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