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

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 (43) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +21 -0
  3. package/dist/cjs/index.cjs +1602 -0
  4. package/dist/esm/index.mjs +1597 -0
  5. package/dist/types/dataTypes/jsonLdDataTypes.d.ts +9 -0
  6. package/dist/types/index.d.ts +5 -0
  7. package/dist/types/models/IJsonLdDocument.d.ts +207 -0
  8. package/dist/types/models/jsonLdTypes.d.ts +101 -0
  9. package/dist/types/utils/jsonLdHelper.d.ts +16 -0
  10. package/dist/types/utils/jsonLdProcessor.d.ts +34 -0
  11. package/docs/changelog.md +5 -0
  12. package/docs/examples.md +1 -0
  13. package/docs/reference/classes/JsonLdDataTypes.md +25 -0
  14. package/docs/reference/classes/JsonLdHelper.md +45 -0
  15. package/docs/reference/classes/JsonLdProcessor.md +95 -0
  16. package/docs/reference/index.md +41 -0
  17. package/docs/reference/interfaces/IJsonLdContextDefinition.md +73 -0
  18. package/docs/reference/interfaces/IJsonLdGraphObject.md +31 -0
  19. package/docs/reference/interfaces/IJsonLdIdMap.md +11 -0
  20. package/docs/reference/interfaces/IJsonLdIndexMap.md +12 -0
  21. package/docs/reference/interfaces/IJsonLdJsonObject.md +5 -0
  22. package/docs/reference/interfaces/IJsonLdLanguageMap.md +11 -0
  23. package/docs/reference/interfaces/IJsonLdListObject.md +19 -0
  24. package/docs/reference/interfaces/IJsonLdNodeObject.md +64 -0
  25. package/docs/reference/interfaces/IJsonLdSetObject.md +19 -0
  26. package/docs/reference/interfaces/IJsonLdTypeMap.md +11 -0
  27. package/docs/reference/type-aliases/IJsonLdContainerType.md +3 -0
  28. package/docs/reference/type-aliases/IJsonLdContainerTypeArray.md +3 -0
  29. package/docs/reference/type-aliases/IJsonLdDocument.md +11 -0
  30. package/docs/reference/type-aliases/IJsonLdExpandedTermDefinition.md +41 -0
  31. package/docs/reference/type-aliases/IJsonLdIncludedBlock.md +9 -0
  32. package/docs/reference/type-aliases/IJsonLdIndexMapItem.md +5 -0
  33. package/docs/reference/type-aliases/IJsonLdJsonArray.md +3 -0
  34. package/docs/reference/type-aliases/IJsonLdJsonPrimitive.md +3 -0
  35. package/docs/reference/type-aliases/IJsonLdJsonValue.md +3 -0
  36. package/docs/reference/type-aliases/IJsonLdKeyword.md +105 -0
  37. package/docs/reference/type-aliases/IJsonLdListOrSetItem.md +5 -0
  38. package/docs/reference/type-aliases/IJsonLdNodePrimitive.md +5 -0
  39. package/docs/reference/type-aliases/IJsonLdValueObject.md +20 -0
  40. package/docs/reference/type-aliases/JsonLdTypes.md +5 -0
  41. package/docs/reference/variables/JsonLdTypes.md +145 -0
  42. package/locales/en.json +6 -0
  43. package/package.json +74 -0
@@ -0,0 +1,1597 @@
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';
4
+ import jsonLd from 'jsonld';
5
+
6
+ // Copyright 2024 IOTA Stiftung.
7
+ // SPDX-License-Identifier: Apache-2.0.
8
+ /**
9
+ * The types of JSON-LD data.
10
+ */
11
+ // eslint-disable-next-line @typescript-eslint/naming-convention
12
+ const JsonLdTypes = {
13
+ /**
14
+ * Represents JSON-LD Document.
15
+ */
16
+ Document: "https://schema.twindev.org/json-ld/JsonLdDocument",
17
+ /**
18
+ * Represents JSON-LD Node Object.
19
+ */
20
+ NodeObject: "https://schema.twindev.org/json-ld/JsonLdNodeObject",
21
+ /**
22
+ * Represents JSON-LD Node Primitive.
23
+ */
24
+ NodePrimitive: "https://schema.twindev.org/json-ld/JsonLdNodePrimitive",
25
+ /**
26
+ * Represents JSON-LD Graph Object.
27
+ */
28
+ GraphObject: "https://schema.twindev.org/json-ld/JsonLdGraphObject",
29
+ /**
30
+ * Represents JSON-LD Value Object.
31
+ */
32
+ ValueObject: "https://schema.twindev.org/json-ld/JsonLdValueObject",
33
+ /**
34
+ * Represents JSON-LD List Object.
35
+ */
36
+ ListObject: "https://schema.twindev.org/json-ld/JsonLdListObject",
37
+ /**
38
+ * Represents JSON-LD Set Object.
39
+ */
40
+ SetObject: "https://schema.twindev.org/json-ld/JsonLdSetObject",
41
+ /**
42
+ * Represents JSON-LD Language Map.
43
+ */
44
+ LanguageMap: "https://schema.twindev.org/json-ld/JsonLdLanguageMap",
45
+ /**
46
+ * Represents JSON-LD Index Map.
47
+ */
48
+ IndexMap: "https://schema.twindev.org/json-ld/JsonLdIndexMap",
49
+ /**
50
+ * Represents JSON-LD Index Map Item.
51
+ */
52
+ IndexMapItem: "https://schema.twindev.org/json-ld/JsonLdIndexMapItem",
53
+ /**
54
+ * Represents JSON-LD Id Map.
55
+ */
56
+ IdMap: "https://schema.twindev.org/json-ld/JsonLdIdMap",
57
+ /**
58
+ * Represents JSON-LD Type Map.
59
+ */
60
+ TypeMap: "https://schema.twindev.org/json-ld/JsonLdTypeMap",
61
+ /**
62
+ * Represents JSON-LD Included block.
63
+ */
64
+ IncludedBlock: "https://schema.twindev.org/json-ld/JsonLdIncludedBlock",
65
+ /**
66
+ * Represents JSON-LD Context Definition.
67
+ */
68
+ ContextDefinition: "https://schema.twindev.org/json-ld/JsonLdContextDefinition",
69
+ /**
70
+ * Represents JSON-LD Expanded Term Definition.
71
+ */
72
+ ExpandedTermDefinition: "https://schema.twindev.org/json-ld/JsonLdExpandedTermDefinition",
73
+ /**
74
+ * Represents JSON-LD Keyword.
75
+ */
76
+ Keyword: "https://schema.twindev.org/json-ld/JsonLdKeyword",
77
+ /**
78
+ * Represents JSON-LD List or Set Item.
79
+ */
80
+ ListOrSetItem: "https://schema.twindev.org/json-ld/JsonLdListOrSetItem",
81
+ /**
82
+ * Represents JSON-LD Container Type.
83
+ */
84
+ ContainerType: "https://schema.twindev.org/json-ld/JsonLdContainerType",
85
+ /**
86
+ * Represents JSON-LD Container Type Array.
87
+ */
88
+ ContainerTypeArray: "https://schema.twindev.org/json-ld/JsonLdContainerTypeArray",
89
+ /**
90
+ * Represents JSON-LD JSON Primitive.
91
+ */
92
+ JsonPrimitive: "https://schema.twindev.org/json-ld/JsonLdJsonPrimitive",
93
+ /**
94
+ * Represents JSON-LD JSON Array.
95
+ */
96
+ JsonArray: "https://schema.twindev.org/json-ld/JsonLdJsonArray",
97
+ /**
98
+ * Represents JSON-LD JSON Object.
99
+ */
100
+ JsonObject: "https://schema.twindev.org/json-ld/JsonLdJsonObject",
101
+ /**
102
+ * Represents JSON-LD JSON Value.
103
+ */
104
+ JsonValue: "https://schema.twindev.org/json-ld/JsonLdJsonValue"
105
+ };
106
+
107
+ var type$d = "string";
108
+ var JsonLdContainerTypeSchema = {
109
+ type: type$d,
110
+ "enum": [
111
+ "@language",
112
+ "@index",
113
+ "@id",
114
+ "@graph",
115
+ "@type"
116
+ ]
117
+ };
118
+
119
+ var anyOf$8 = [
120
+ {
121
+ type: "array",
122
+ minItems: 2,
123
+ items: [
124
+ {
125
+ type: "string",
126
+ "const": "@graph"
127
+ },
128
+ {
129
+ type: "string",
130
+ "const": "@id"
131
+ }
132
+ ],
133
+ maxItems: 2
134
+ },
135
+ {
136
+ type: "array",
137
+ minItems: 2,
138
+ items: [
139
+ {
140
+ type: "string",
141
+ "const": "@id"
142
+ },
143
+ {
144
+ type: "string",
145
+ "const": "@graph"
146
+ }
147
+ ],
148
+ maxItems: 2
149
+ },
150
+ {
151
+ type: "array",
152
+ minItems: 3,
153
+ items: [
154
+ {
155
+ type: "string",
156
+ "const": "@set"
157
+ },
158
+ {
159
+ type: "string",
160
+ "const": "@graph"
161
+ },
162
+ {
163
+ type: "string",
164
+ "const": "@id"
165
+ }
166
+ ],
167
+ maxItems: 3
168
+ },
169
+ {
170
+ type: "array",
171
+ minItems: 3,
172
+ items: [
173
+ {
174
+ type: "string",
175
+ "const": "@set"
176
+ },
177
+ {
178
+ type: "string",
179
+ "const": "@id"
180
+ },
181
+ {
182
+ type: "string",
183
+ "const": "@graph"
184
+ }
185
+ ],
186
+ maxItems: 3
187
+ },
188
+ {
189
+ type: "array",
190
+ minItems: 3,
191
+ items: [
192
+ {
193
+ type: "string",
194
+ "const": "@graph"
195
+ },
196
+ {
197
+ type: "string",
198
+ "const": "@set"
199
+ },
200
+ {
201
+ type: "string",
202
+ "const": "@id"
203
+ }
204
+ ],
205
+ maxItems: 3
206
+ },
207
+ {
208
+ type: "array",
209
+ minItems: 3,
210
+ items: [
211
+ {
212
+ type: "string",
213
+ "const": "@id"
214
+ },
215
+ {
216
+ type: "string",
217
+ "const": "@set"
218
+ },
219
+ {
220
+ type: "string",
221
+ "const": "@graph"
222
+ }
223
+ ],
224
+ maxItems: 3
225
+ },
226
+ {
227
+ type: "array",
228
+ minItems: 3,
229
+ items: [
230
+ {
231
+ type: "string",
232
+ "const": "@graph"
233
+ },
234
+ {
235
+ type: "string",
236
+ "const": "@id"
237
+ },
238
+ {
239
+ type: "string",
240
+ "const": "@set"
241
+ }
242
+ ],
243
+ maxItems: 3
244
+ },
245
+ {
246
+ type: "array",
247
+ minItems: 3,
248
+ items: [
249
+ {
250
+ type: "string",
251
+ "const": "@id"
252
+ },
253
+ {
254
+ type: "string",
255
+ "const": "@graph"
256
+ },
257
+ {
258
+ type: "string",
259
+ "const": "@set"
260
+ }
261
+ ],
262
+ maxItems: 3
263
+ },
264
+ {
265
+ type: "array",
266
+ minItems: 2,
267
+ items: [
268
+ {
269
+ type: "string",
270
+ "const": "@set"
271
+ },
272
+ {
273
+ $ref: "https://schema.twindev.org/json-ld/JsonLdContainerType"
274
+ }
275
+ ],
276
+ maxItems: 2
277
+ },
278
+ {
279
+ type: "array",
280
+ minItems: 2,
281
+ items: [
282
+ {
283
+ $ref: "https://schema.twindev.org/json-ld/JsonLdContainerType"
284
+ },
285
+ {
286
+ type: "string",
287
+ "const": "@set"
288
+ }
289
+ ],
290
+ maxItems: 2
291
+ }
292
+ ];
293
+ var JsonLdContainerTypeArraySchema = {
294
+ anyOf: anyOf$8
295
+ };
296
+
297
+ var type$c = "object";
298
+ var properties$5 = {
299
+ "@base": {
300
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
301
+ },
302
+ "@direction": {
303
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
304
+ },
305
+ "@import": {
306
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
307
+ },
308
+ "@language": {
309
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
310
+ },
311
+ "@propagate": {
312
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
313
+ },
314
+ "@protected": {
315
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
316
+ },
317
+ "@type": {
318
+ type: "object",
319
+ properties: {
320
+ "@container": {
321
+ type: "string",
322
+ "const": "@set"
323
+ },
324
+ "@protected": {
325
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
326
+ }
327
+ },
328
+ required: [
329
+ "@container"
330
+ ],
331
+ additionalProperties: false
332
+ },
333
+ "@version": {
334
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
335
+ },
336
+ "@vocab": {
337
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
338
+ }
339
+ };
340
+ var additionalProperties$a = {
341
+ anyOf: [
342
+ {
343
+ type: "null"
344
+ },
345
+ {
346
+ type: "string"
347
+ },
348
+ {
349
+ $ref: "https://schema.twindev.org/json-ld/JsonLdExpandedTermDefinition"
350
+ }
351
+ ]
352
+ };
353
+ var description$g = "A context definition defines a local context in a node object.";
354
+ var JsonLdContextDefinitionSchema = {
355
+ type: type$c,
356
+ properties: properties$5,
357
+ additionalProperties: additionalProperties$a,
358
+ description: description$g
359
+ };
360
+
361
+ var anyOf$7 = [
362
+ {
363
+ $ref: "https://schema.twindev.org/json-ld/JsonLdNodeObject"
364
+ },
365
+ {
366
+ type: "array",
367
+ items: {
368
+ $ref: "https://schema.twindev.org/json-ld/JsonLdNodeObject"
369
+ }
370
+ },
371
+ {
372
+ type: "object",
373
+ properties: {
374
+ "@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
+ ]
402
+ },
403
+ "@graph": {
404
+ anyOf: [
405
+ {
406
+ $ref: "https://schema.twindev.org/json-ld/JsonLdValueObject"
407
+ },
408
+ {
409
+ $ref: "https://schema.twindev.org/json-ld/JsonLdNodeObject"
410
+ },
411
+ {
412
+ type: "array",
413
+ items: {
414
+ anyOf: [
415
+ {
416
+ $ref: "https://schema.twindev.org/json-ld/JsonLdValueObject"
417
+ },
418
+ {
419
+ $ref: "https://schema.twindev.org/json-ld/JsonLdNodeObject"
420
+ }
421
+ ]
422
+ }
423
+ }
424
+ ]
425
+ }
426
+ },
427
+ additionalProperties: false
428
+ }
429
+ ];
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.";
431
+ var JsonLdDocumentSchema = {
432
+ anyOf: anyOf$7,
433
+ description: description$f
434
+ };
435
+
436
+ var anyOf$6 = [
437
+ {
438
+ type: "object",
439
+ additionalProperties: false,
440
+ properties: {
441
+ "@id": {
442
+ anyOf: [
443
+ {
444
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
445
+ },
446
+ {
447
+ type: "null"
448
+ }
449
+ ]
450
+ },
451
+ "@nest": {
452
+ type: "string"
453
+ },
454
+ "@container": {
455
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
456
+ },
457
+ "@type": {
458
+ type: "string"
459
+ },
460
+ "@language": {
461
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
462
+ },
463
+ "@index": {
464
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
465
+ },
466
+ "@context": {
467
+ $ref: "https://schema.twindev.org/json-ld/JsonLdContextDefinition"
468
+ },
469
+ "@prefix": {
470
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
471
+ },
472
+ "@propagate": {
473
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
474
+ },
475
+ "@protected": {
476
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
477
+ }
478
+ }
479
+ },
480
+ {
481
+ type: "object",
482
+ additionalProperties: false,
483
+ properties: {
484
+ "@reverse": {
485
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
486
+ },
487
+ "@container": {
488
+ type: [
489
+ "string",
490
+ "null"
491
+ ],
492
+ "enum": [
493
+ "@set",
494
+ "@index",
495
+ null
496
+ ]
497
+ },
498
+ "@type": {
499
+ type: "string"
500
+ },
501
+ "@language": {
502
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
503
+ },
504
+ "@index": {
505
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
506
+ },
507
+ "@context": {
508
+ $ref: "https://schema.twindev.org/json-ld/JsonLdContextDefinition"
509
+ },
510
+ "@prefix": {
511
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
512
+ },
513
+ "@propagate": {
514
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
515
+ },
516
+ "@protected": {
517
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
518
+ }
519
+ },
520
+ required: [
521
+ "@reverse"
522
+ ]
523
+ }
524
+ ];
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.";
526
+ var JsonLdExpandedTermDefinitionSchema = {
527
+ anyOf: anyOf$6,
528
+ description: description$e
529
+ };
530
+
531
+ var type$b = "object";
532
+ var properties$4 = {
533
+ "@graph": {
534
+ anyOf: [
535
+ {
536
+ $ref: "https://schema.twindev.org/json-ld/JsonLdNodeObject"
537
+ },
538
+ {
539
+ type: "array",
540
+ items: {
541
+ $ref: "https://schema.twindev.org/json-ld/JsonLdNodeObject"
542
+ }
543
+ }
544
+ ]
545
+ },
546
+ "@index": {
547
+ type: "string"
548
+ },
549
+ "@id": {
550
+ anyOf: [
551
+ {
552
+ type: "string"
553
+ },
554
+ {
555
+ type: "array",
556
+ items: {
557
+ type: "string"
558
+ }
559
+ }
560
+ ]
561
+ },
562
+ "@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
+ ]
590
+ }
591
+ };
592
+ var required$3 = [
593
+ "@graph"
594
+ ];
595
+ var additionalProperties$9 = false;
596
+ var description$d = "A graph object represents a named graph, which MAY include an explicit graph name.";
597
+ var JsonLdGraphObjectSchema = {
598
+ type: type$b,
599
+ properties: properties$4,
600
+ required: required$3,
601
+ additionalProperties: additionalProperties$9,
602
+ description: description$d
603
+ };
604
+
605
+ var type$a = "object";
606
+ var additionalProperties$8 = {
607
+ $ref: "https://schema.twindev.org/json-ld/JsonLdNodeObject"
608
+ };
609
+ var description$c = "An id map is used to associate an IRI with a value that allows easy programmatic access.";
610
+ var JsonLdIdMapSchema = {
611
+ type: type$a,
612
+ additionalProperties: additionalProperties$8,
613
+ description: description$c
614
+ };
615
+
616
+ var anyOf$5 = [
617
+ {
618
+ $ref: "https://schema.twindev.org/json-ld/JsonLdNodeObject"
619
+ },
620
+ {
621
+ type: "array",
622
+ items: {
623
+ $ref: "https://schema.twindev.org/json-ld/JsonLdNodeObject"
624
+ }
625
+ }
626
+ ];
627
+ var description$b = "An included block is used to provide a set of node objects.";
628
+ var JsonLdIncludedBlockSchema = {
629
+ anyOf: anyOf$5,
630
+ description: description$b
631
+ };
632
+
633
+ var type$9 = "object";
634
+ var additionalProperties$7 = {
635
+ anyOf: [
636
+ {
637
+ $ref: "https://schema.twindev.org/json-ld/JsonLdIndexMapItem"
638
+ },
639
+ {
640
+ type: "array",
641
+ items: {
642
+ $ref: "https://schema.twindev.org/json-ld/JsonLdIndexMapItem"
643
+ }
644
+ }
645
+ ]
646
+ };
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.";
648
+ var JsonLdIndexMapSchema = {
649
+ type: type$9,
650
+ additionalProperties: additionalProperties$7,
651
+ description: description$a
652
+ };
653
+
654
+ var anyOf$4 = [
655
+ {
656
+ type: "null"
657
+ },
658
+ {
659
+ type: "boolean"
660
+ },
661
+ {
662
+ type: "number"
663
+ },
664
+ {
665
+ type: "string"
666
+ },
667
+ {
668
+ $ref: "https://schema.twindev.org/json-ld/JsonLdNodeObject"
669
+ },
670
+ {
671
+ $ref: "https://schema.twindev.org/json-ld/JsonLdValueObject"
672
+ },
673
+ {
674
+ $ref: "https://schema.twindev.org/json-ld/JsonLdListObject"
675
+ },
676
+ {
677
+ $ref: "https://schema.twindev.org/json-ld/JsonLdSetObject"
678
+ }
679
+ ];
680
+ var description$9 = "The items that can be stored in an index map.";
681
+ var JsonLdIndexMapItemSchema = {
682
+ anyOf: anyOf$4,
683
+ description: description$9
684
+ };
685
+
686
+ var type$8 = "array";
687
+ var items = {
688
+ $ref: "https://schema.twindev.org/json-ld/JsonLdJsonValue"
689
+ };
690
+ var JsonLdJsonArraySchema = {
691
+ type: type$8,
692
+ items: items
693
+ };
694
+
695
+ var type$7 = "object";
696
+ var additionalProperties$6 = {
697
+ anyOf: [
698
+ {
699
+ $ref: "https://schema.twindev.org/json-ld/JsonLdJsonValue"
700
+ },
701
+ {
702
+ not: {
703
+ }
704
+ }
705
+ ]
706
+ };
707
+ var JsonLdJsonObjectSchema = {
708
+ type: type$7,
709
+ additionalProperties: additionalProperties$6
710
+ };
711
+
712
+ var type$6 = [
713
+ "string",
714
+ "number",
715
+ "boolean",
716
+ "null"
717
+ ];
718
+ var JsonLdJsonPrimitiveSchema = {
719
+ type: type$6
720
+ };
721
+
722
+ var anyOf$3 = [
723
+ {
724
+ $ref: "https://schema.twindev.org/json-ld/JsonLdJsonPrimitive"
725
+ },
726
+ {
727
+ $ref: "https://schema.twindev.org/json-ld/JsonLdJsonArray"
728
+ },
729
+ {
730
+ $ref: "https://schema.twindev.org/json-ld/JsonLdJsonObject"
731
+ }
732
+ ];
733
+ var JsonLdJsonValueSchema = {
734
+ anyOf: anyOf$3
735
+ };
736
+
737
+ var type$5 = "object";
738
+ var properties$3 = {
739
+ "@base": {
740
+ type: [
741
+ "string",
742
+ "null"
743
+ ]
744
+ },
745
+ "@container": {
746
+ anyOf: [
747
+ {
748
+ type: "string",
749
+ "const": "@list"
750
+ },
751
+ {
752
+ type: "string",
753
+ "const": "@set"
754
+ },
755
+ {
756
+ $ref: "https://schema.twindev.org/json-ld/JsonLdContainerType"
757
+ },
758
+ {
759
+ type: "array",
760
+ items: {
761
+ anyOf: [
762
+ {
763
+ type: "string",
764
+ "const": "@list"
765
+ },
766
+ {
767
+ type: "string",
768
+ "const": "@set"
769
+ },
770
+ {
771
+ $ref: "https://schema.twindev.org/json-ld/JsonLdContainerType"
772
+ }
773
+ ]
774
+ }
775
+ },
776
+ {
777
+ $ref: "https://schema.twindev.org/json-ld/JsonLdContainerTypeArray"
778
+ },
779
+ {
780
+ type: "null"
781
+ }
782
+ ]
783
+ },
784
+ "@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
+ ]
812
+ },
813
+ "@direction": {
814
+ type: [
815
+ "string",
816
+ "null"
817
+ ],
818
+ "enum": [
819
+ "ltr",
820
+ "rtl",
821
+ null
822
+ ]
823
+ },
824
+ "@graph": {
825
+ anyOf: [
826
+ {
827
+ $ref: "https://schema.twindev.org/json-ld/JsonLdValueObject"
828
+ },
829
+ {
830
+ $ref: "https://schema.twindev.org/json-ld/JsonLdNodeObject"
831
+ },
832
+ {
833
+ type: "array",
834
+ items: {
835
+ anyOf: [
836
+ {
837
+ $ref: "https://schema.twindev.org/json-ld/JsonLdValueObject"
838
+ },
839
+ {
840
+ $ref: "https://schema.twindev.org/json-ld/JsonLdNodeObject"
841
+ }
842
+ ]
843
+ }
844
+ }
845
+ ]
846
+ },
847
+ "@id": {
848
+ anyOf: [
849
+ {
850
+ type: "string"
851
+ },
852
+ {
853
+ type: "array",
854
+ items: {
855
+ type: "string"
856
+ }
857
+ }
858
+ ]
859
+ },
860
+ "@import": {
861
+ type: "string"
862
+ },
863
+ "@included": {
864
+ $ref: "https://schema.twindev.org/json-ld/JsonLdIncludedBlock"
865
+ },
866
+ "@index": {
867
+ type: "string"
868
+ },
869
+ "@json": {
870
+ type: "string",
871
+ "const": "@json"
872
+ },
873
+ "@language": {
874
+ type: "string"
875
+ },
876
+ "@list": {
877
+ anyOf: [
878
+ {
879
+ $ref: "https://schema.twindev.org/json-ld/JsonLdListOrSetItem"
880
+ },
881
+ {
882
+ type: "array",
883
+ items: {
884
+ $ref: "https://schema.twindev.org/json-ld/JsonLdListOrSetItem"
885
+ }
886
+ }
887
+ ]
888
+ },
889
+ "@nest": {
890
+ type: "object"
891
+ },
892
+ "@none": {
893
+ type: "string",
894
+ "const": "@none"
895
+ },
896
+ "@prefix": {
897
+ type: "boolean"
898
+ },
899
+ "@propagate": {
900
+ type: "boolean"
901
+ },
902
+ "@protected": {
903
+ type: "boolean"
904
+ },
905
+ "@reverse": {
906
+ type: "string"
907
+ },
908
+ "@set": {
909
+ anyOf: [
910
+ {
911
+ $ref: "https://schema.twindev.org/json-ld/JsonLdListOrSetItem"
912
+ },
913
+ {
914
+ type: "array",
915
+ items: {
916
+ $ref: "https://schema.twindev.org/json-ld/JsonLdListOrSetItem"
917
+ }
918
+ }
919
+ ]
920
+ },
921
+ "@type": {
922
+ type: "string"
923
+ },
924
+ "@value": {
925
+ type: [
926
+ "null",
927
+ "boolean",
928
+ "number",
929
+ "string"
930
+ ]
931
+ },
932
+ "@version": {
933
+ type: "string",
934
+ "const": "1.1"
935
+ },
936
+ "@vocab": {
937
+ type: [
938
+ "string",
939
+ "null"
940
+ ]
941
+ }
942
+ };
943
+ var required$2 = [
944
+ "@base",
945
+ "@container",
946
+ "@context",
947
+ "@direction",
948
+ "@graph",
949
+ "@id",
950
+ "@import",
951
+ "@included",
952
+ "@index",
953
+ "@json",
954
+ "@language",
955
+ "@list",
956
+ "@nest",
957
+ "@none",
958
+ "@prefix",
959
+ "@propagate",
960
+ "@protected",
961
+ "@reverse",
962
+ "@set",
963
+ "@type",
964
+ "@value",
965
+ "@version",
966
+ "@vocab"
967
+ ];
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.";
970
+ var JsonLdKeywordSchema = {
971
+ type: type$5,
972
+ properties: properties$3,
973
+ required: required$2,
974
+ additionalProperties: additionalProperties$5,
975
+ description: description$8
976
+ };
977
+
978
+ var type$4 = "object";
979
+ var additionalProperties$4 = {
980
+ anyOf: [
981
+ {
982
+ type: "null"
983
+ },
984
+ {
985
+ type: "string"
986
+ },
987
+ {
988
+ type: "array",
989
+ items: {
990
+ type: "string"
991
+ }
992
+ }
993
+ ]
994
+ };
995
+ var description$7 = "A language map is used to associate a language with a value in a way that allows easy programmatic access.";
996
+ var JsonLdLanguageMapSchema = {
997
+ type: type$4,
998
+ additionalProperties: additionalProperties$4,
999
+ description: description$7
1000
+ };
1001
+
1002
+ var type$3 = "object";
1003
+ var properties$2 = {
1004
+ "@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
+ ]
1016
+ },
1017
+ "@index": {
1018
+ type: "string"
1019
+ }
1020
+ };
1021
+ var required$1 = [
1022
+ "@list"
1023
+ ];
1024
+ var additionalProperties$3 = false;
1025
+ var description$6 = "A list represents an ordered set of values.";
1026
+ var JsonLdListObjectSchema = {
1027
+ type: type$3,
1028
+ properties: properties$2,
1029
+ required: required$1,
1030
+ additionalProperties: additionalProperties$3,
1031
+ description: description$6
1032
+ };
1033
+
1034
+ var anyOf$2 = [
1035
+ {
1036
+ type: "null"
1037
+ },
1038
+ {
1039
+ type: "boolean"
1040
+ },
1041
+ {
1042
+ type: "number"
1043
+ },
1044
+ {
1045
+ type: "string"
1046
+ },
1047
+ {
1048
+ $ref: "https://schema.twindev.org/json-ld/JsonLdNodeObject"
1049
+ },
1050
+ {
1051
+ $ref: "https://schema.twindev.org/json-ld/JsonLdValueObject"
1052
+ }
1053
+ ];
1054
+ var description$5 = "A list or set item can be a null, boolean, number, string, node object, or value object.";
1055
+ var JsonLdListOrSetItemSchema = {
1056
+ anyOf: anyOf$2,
1057
+ description: description$5
1058
+ };
1059
+
1060
+ var type$2 = "object";
1061
+ var properties$1 = {
1062
+ "@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
+ ]
1090
+ },
1091
+ "@id": {
1092
+ anyOf: [
1093
+ {
1094
+ type: "string"
1095
+ },
1096
+ {
1097
+ type: "array",
1098
+ items: {
1099
+ type: "string"
1100
+ }
1101
+ }
1102
+ ]
1103
+ },
1104
+ "@included": {
1105
+ $ref: "https://schema.twindev.org/json-ld/JsonLdIncludedBlock"
1106
+ },
1107
+ "@graph": {
1108
+ anyOf: [
1109
+ {
1110
+ $ref: "https://schema.twindev.org/json-ld/JsonLdNodeObject"
1111
+ },
1112
+ {
1113
+ type: "array",
1114
+ items: {
1115
+ $ref: "https://schema.twindev.org/json-ld/JsonLdNodeObject"
1116
+ }
1117
+ }
1118
+ ]
1119
+ },
1120
+ "@nest": {
1121
+ anyOf: [
1122
+ {
1123
+ $ref: "https://schema.twindev.org/json-ld/JsonLdJsonObject"
1124
+ },
1125
+ {
1126
+ type: "array",
1127
+ items: {
1128
+ $ref: "https://schema.twindev.org/json-ld/JsonLdJsonObject"
1129
+ }
1130
+ }
1131
+ ]
1132
+ },
1133
+ "@type": {
1134
+ anyOf: [
1135
+ {
1136
+ type: "string"
1137
+ },
1138
+ {
1139
+ type: "array",
1140
+ items: {
1141
+ type: "string"
1142
+ }
1143
+ }
1144
+ ]
1145
+ },
1146
+ "@reverse": {
1147
+ type: "object",
1148
+ additionalProperties: {
1149
+ type: "string"
1150
+ }
1151
+ },
1152
+ "@index": {
1153
+ type: "string"
1154
+ }
1155
+ };
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.";
1185
+ var JsonLdNodeObjectSchema = {
1186
+ type: type$2,
1187
+ properties: properties$1,
1188
+ additionalProperties: additionalProperties$2,
1189
+ description: description$4
1190
+ };
1191
+
1192
+ var anyOf$1 = [
1193
+ {
1194
+ type: "null"
1195
+ },
1196
+ {
1197
+ type: "boolean"
1198
+ },
1199
+ {
1200
+ type: "number"
1201
+ },
1202
+ {
1203
+ type: "string"
1204
+ },
1205
+ {
1206
+ $ref: "https://schema.twindev.org/json-ld/JsonLdNodeObject"
1207
+ },
1208
+ {
1209
+ $ref: "https://schema.twindev.org/json-ld/JsonLdGraphObject"
1210
+ },
1211
+ {
1212
+ $ref: "https://schema.twindev.org/json-ld/JsonLdValueObject"
1213
+ },
1214
+ {
1215
+ $ref: "https://schema.twindev.org/json-ld/JsonLdListObject"
1216
+ },
1217
+ {
1218
+ $ref: "https://schema.twindev.org/json-ld/JsonLdSetObject"
1219
+ }
1220
+ ];
1221
+ var description$3 = "A node primitive is a JSON-LD value which is not one of the defined NodeObject properties.";
1222
+ var JsonLdNodePrimitiveSchema = {
1223
+ anyOf: anyOf$1,
1224
+ description: description$3
1225
+ };
1226
+
1227
+ var type$1 = "object";
1228
+ var properties = {
1229
+ "@set": {
1230
+ anyOf: [
1231
+ {
1232
+ $ref: "https://schema.twindev.org/json-ld/JsonLdListOrSetItem"
1233
+ },
1234
+ {
1235
+ type: "array",
1236
+ items: {
1237
+ $ref: "https://schema.twindev.org/json-ld/JsonLdListOrSetItem"
1238
+ }
1239
+ }
1240
+ ]
1241
+ },
1242
+ "@index": {
1243
+ type: "string"
1244
+ }
1245
+ };
1246
+ var required = [
1247
+ "@set"
1248
+ ];
1249
+ var additionalProperties$1 = false;
1250
+ var description$2 = "A set represents an unordered set of values.";
1251
+ var JsonLdSetObjectSchema = {
1252
+ type: type$1,
1253
+ properties: properties,
1254
+ required: required,
1255
+ additionalProperties: additionalProperties$1,
1256
+ description: description$2
1257
+ };
1258
+
1259
+ var type = "object";
1260
+ var additionalProperties = {
1261
+ anyOf: [
1262
+ {
1263
+ type: "string"
1264
+ },
1265
+ {
1266
+ $ref: "https://schema.twindev.org/json-ld/JsonLdNodeObject"
1267
+ }
1268
+ ]
1269
+ };
1270
+ var description$1 = "A type map is used to associate an IRI with a value that allows easy programmatic access.";
1271
+ var JsonLdTypeMapSchema = {
1272
+ type: type,
1273
+ additionalProperties: additionalProperties,
1274
+ description: description$1
1275
+ };
1276
+
1277
+ var anyOf = [
1278
+ {
1279
+ type: "object",
1280
+ additionalProperties: false,
1281
+ properties: {
1282
+ "@value": {
1283
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
1284
+ },
1285
+ "@language": {
1286
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
1287
+ },
1288
+ "@direction": {
1289
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
1290
+ },
1291
+ "@index": {
1292
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
1293
+ },
1294
+ "@context": {
1295
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
1296
+ }
1297
+ },
1298
+ required: [
1299
+ "@value"
1300
+ ]
1301
+ },
1302
+ {
1303
+ type: "object",
1304
+ additionalProperties: false,
1305
+ properties: {
1306
+ "@value": {
1307
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
1308
+ },
1309
+ "@type": {
1310
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
1311
+ },
1312
+ "@index": {
1313
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
1314
+ },
1315
+ "@context": {
1316
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
1317
+ }
1318
+ },
1319
+ required: [
1320
+ "@type",
1321
+ "@value"
1322
+ ]
1323
+ },
1324
+ {
1325
+ type: "object",
1326
+ additionalProperties: false,
1327
+ properties: {
1328
+ "@value": {
1329
+ anyOf: [
1330
+ {
1331
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
1332
+ },
1333
+ {
1334
+ $ref: "https://schema.twindev.org/json-ld/JsonLdJsonObject"
1335
+ },
1336
+ {
1337
+ $ref: "https://schema.twindev.org/json-ld/JsonLdJsonArray"
1338
+ }
1339
+ ]
1340
+ },
1341
+ "@type": {
1342
+ type: "string",
1343
+ "const": "@json"
1344
+ },
1345
+ "@index": {
1346
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
1347
+ },
1348
+ "@context": {
1349
+ $ref: "https://schema.twindev.org/json-ld/JsonLdKeyword"
1350
+ }
1351
+ },
1352
+ required: [
1353
+ "@type",
1354
+ "@value"
1355
+ ]
1356
+ }
1357
+ ];
1358
+ var description = "A value object is used to explicitly associate a type or a language with a value to create a typed value or a language-tagged string and possibly associate a base direction.";
1359
+ var JsonLdValueObjectSchema = {
1360
+ anyOf: anyOf,
1361
+ description: description
1362
+ };
1363
+
1364
+ // Copyright 2024 IOTA Stiftung.
1365
+ // SPDX-License-Identifier: Apache-2.0.
1366
+ /**
1367
+ * Handle all the data types for JSON-LD.
1368
+ */
1369
+ class JsonLdDataTypes {
1370
+ /**
1371
+ * Register all the data types.
1372
+ */
1373
+ static registerTypes() {
1374
+ DataTypeHandlerFactory.register(JsonLdTypes.Document, () => ({
1375
+ type: JsonLdTypes.Document,
1376
+ jsonSchema: async () => JsonLdDocumentSchema
1377
+ }));
1378
+ DataTypeHandlerFactory.register(JsonLdTypes.NodeObject, () => ({
1379
+ type: JsonLdTypes.NodeObject,
1380
+ jsonSchema: async () => JsonLdNodeObjectSchema
1381
+ }));
1382
+ DataTypeHandlerFactory.register(JsonLdTypes.NodePrimitive, () => ({
1383
+ type: JsonLdTypes.NodePrimitive,
1384
+ jsonSchema: async () => JsonLdNodePrimitiveSchema
1385
+ }));
1386
+ DataTypeHandlerFactory.register(JsonLdTypes.GraphObject, () => ({
1387
+ type: JsonLdTypes.GraphObject,
1388
+ jsonSchema: async () => JsonLdGraphObjectSchema
1389
+ }));
1390
+ DataTypeHandlerFactory.register(JsonLdTypes.ValueObject, () => ({
1391
+ type: JsonLdTypes.ValueObject,
1392
+ jsonSchema: async () => JsonLdValueObjectSchema
1393
+ }));
1394
+ DataTypeHandlerFactory.register(JsonLdTypes.ListObject, () => ({
1395
+ type: JsonLdTypes.ListObject,
1396
+ jsonSchema: async () => JsonLdListObjectSchema
1397
+ }));
1398
+ DataTypeHandlerFactory.register(JsonLdTypes.ListObject, () => ({
1399
+ type: JsonLdTypes.ListObject,
1400
+ jsonSchema: async () => JsonLdListObjectSchema
1401
+ }));
1402
+ DataTypeHandlerFactory.register(JsonLdTypes.SetObject, () => ({
1403
+ type: JsonLdTypes.SetObject,
1404
+ jsonSchema: async () => JsonLdSetObjectSchema
1405
+ }));
1406
+ DataTypeHandlerFactory.register(JsonLdTypes.LanguageMap, () => ({
1407
+ type: JsonLdTypes.LanguageMap,
1408
+ jsonSchema: async () => JsonLdLanguageMapSchema
1409
+ }));
1410
+ DataTypeHandlerFactory.register(JsonLdTypes.IndexMap, () => ({
1411
+ type: JsonLdTypes.IndexMap,
1412
+ jsonSchema: async () => JsonLdIndexMapSchema
1413
+ }));
1414
+ DataTypeHandlerFactory.register(JsonLdTypes.IndexMapItem, () => ({
1415
+ type: JsonLdTypes.IndexMapItem,
1416
+ jsonSchema: async () => JsonLdIndexMapItemSchema
1417
+ }));
1418
+ DataTypeHandlerFactory.register(JsonLdTypes.IdMap, () => ({
1419
+ type: JsonLdTypes.IdMap,
1420
+ jsonSchema: async () => JsonLdIdMapSchema
1421
+ }));
1422
+ DataTypeHandlerFactory.register(JsonLdTypes.TypeMap, () => ({
1423
+ type: JsonLdTypes.TypeMap,
1424
+ jsonSchema: async () => JsonLdTypeMapSchema
1425
+ }));
1426
+ DataTypeHandlerFactory.register(JsonLdTypes.IncludedBlock, () => ({
1427
+ type: JsonLdTypes.IncludedBlock,
1428
+ jsonSchema: async () => JsonLdIncludedBlockSchema
1429
+ }));
1430
+ DataTypeHandlerFactory.register(JsonLdTypes.ContextDefinition, () => ({
1431
+ type: JsonLdTypes.ContextDefinition,
1432
+ jsonSchema: async () => JsonLdContextDefinitionSchema
1433
+ }));
1434
+ DataTypeHandlerFactory.register(JsonLdTypes.ExpandedTermDefinition, () => ({
1435
+ type: JsonLdTypes.ExpandedTermDefinition,
1436
+ jsonSchema: async () => JsonLdExpandedTermDefinitionSchema
1437
+ }));
1438
+ DataTypeHandlerFactory.register(JsonLdTypes.Keyword, () => ({
1439
+ type: JsonLdTypes.Keyword,
1440
+ jsonSchema: async () => JsonLdKeywordSchema
1441
+ }));
1442
+ DataTypeHandlerFactory.register(JsonLdTypes.ListOrSetItem, () => ({
1443
+ type: JsonLdTypes.ListOrSetItem,
1444
+ jsonSchema: async () => JsonLdListOrSetItemSchema
1445
+ }));
1446
+ DataTypeHandlerFactory.register(JsonLdTypes.ContainerType, () => ({
1447
+ type: JsonLdTypes.ContainerType,
1448
+ jsonSchema: async () => JsonLdContainerTypeSchema
1449
+ }));
1450
+ DataTypeHandlerFactory.register(JsonLdTypes.ContainerTypeArray, () => ({
1451
+ type: JsonLdTypes.ContainerTypeArray,
1452
+ jsonSchema: async () => JsonLdContainerTypeArraySchema
1453
+ }));
1454
+ DataTypeHandlerFactory.register(JsonLdTypes.JsonPrimitive, () => ({
1455
+ type: JsonLdTypes.JsonPrimitive,
1456
+ jsonSchema: async () => JsonLdJsonPrimitiveSchema
1457
+ }));
1458
+ DataTypeHandlerFactory.register(JsonLdTypes.JsonArray, () => ({
1459
+ type: JsonLdTypes.JsonArray,
1460
+ jsonSchema: async () => JsonLdJsonArraySchema
1461
+ }));
1462
+ DataTypeHandlerFactory.register(JsonLdTypes.JsonObject, () => ({
1463
+ type: JsonLdTypes.JsonObject,
1464
+ jsonSchema: async () => JsonLdJsonObjectSchema
1465
+ }));
1466
+ DataTypeHandlerFactory.register(JsonLdTypes.JsonValue, () => ({
1467
+ type: JsonLdTypes.JsonValue,
1468
+ jsonSchema: async () => JsonLdJsonValueSchema
1469
+ }));
1470
+ }
1471
+ }
1472
+
1473
+ // Copyright 2024 IOTA Stiftung.
1474
+ // SPDX-License-Identifier: Apache-2.0.
1475
+ /**
1476
+ * Class to help with JSON LD.
1477
+ */
1478
+ class JsonLdHelper {
1479
+ /**
1480
+ * Validate a JSON-LD document.
1481
+ * @param document The JSON-LD document to validate.
1482
+ * @param validationFailures The list of validation failures to add to.
1483
+ * @param validationMode The validation mode to use, defaults to either.
1484
+ * @returns True if the document was valid.
1485
+ */
1486
+ static async validate(document, validationFailures, validationMode) {
1487
+ if (Is.array(document)) {
1488
+ // If the document is an array of nodes, validate each node
1489
+ for (const node of document) {
1490
+ await JsonLdHelper.validate(node, validationFailures, validationMode);
1491
+ }
1492
+ }
1493
+ else if (Is.array(document["@graph"])) {
1494
+ // If the graph is an array of nodes, validate each node
1495
+ for (const node of document["@graph"]) {
1496
+ await JsonLdHelper.validate(node, validationFailures, validationMode);
1497
+ }
1498
+ }
1499
+ else if (Is.object(document)) {
1500
+ // If the graph is a single node, then use the validate the node schema
1501
+ const dataType = document["@type"];
1502
+ if (Is.stringValue(dataType)) {
1503
+ await DataTypeHelper.validate("document", dataType, document, validationFailures, validationMode);
1504
+ }
1505
+ }
1506
+ return validationFailures.length === 0;
1507
+ }
1508
+ }
1509
+
1510
+ // Copyright 2024 IOTA Stiftung.
1511
+ // SPDX-License-Identifier: Apache-2.0.
1512
+ /**
1513
+ * JSON-LD Processor.
1514
+ */
1515
+ class JsonLdProcessor {
1516
+ /**
1517
+ * The class name.
1518
+ * @internal
1519
+ */
1520
+ static _CLASS_NAME = "JsonLdProcessor";
1521
+ /**
1522
+ * Redirects to use during document resolution.
1523
+ */
1524
+ static _redirects = [];
1525
+ /**
1526
+ * The document loader to use.
1527
+ */
1528
+ static DOCUMENT_LOADER = async (url) => JsonLdProcessor.documentLoader(url);
1529
+ /**
1530
+ * Compact a document according to a particular context.
1531
+ * @param document The JSON-LD document to compact.
1532
+ * @param context The context to compact the document to.
1533
+ * @returns The compacted JSON-LD document.
1534
+ */
1535
+ static async compact(document, context) {
1536
+ try {
1537
+ return jsonLd.compact(document, context ?? {}, {
1538
+ documentLoader: JsonLdProcessor.DOCUMENT_LOADER
1539
+ });
1540
+ }
1541
+ catch (err) {
1542
+ throw new GeneralError(JsonLdProcessor._CLASS_NAME, "compact", undefined, err);
1543
+ }
1544
+ }
1545
+ /**
1546
+ * Expand a document, removing its context.
1547
+ * @param compacted The compacted JSON-LD document to expand.
1548
+ * @returns The expanded JSON-LD document.
1549
+ */
1550
+ static async expand(compacted) {
1551
+ try {
1552
+ return jsonLd.expand(compacted, {
1553
+ documentLoader: JsonLdProcessor.DOCUMENT_LOADER
1554
+ });
1555
+ }
1556
+ catch (err) {
1557
+ throw new GeneralError(JsonLdProcessor._CLASS_NAME, "expand", undefined, err);
1558
+ }
1559
+ }
1560
+ /**
1561
+ * Add a redirect to use during document resolution.
1562
+ * @param from The URL to redirect from.
1563
+ * @param to The URL to redirect to.
1564
+ */
1565
+ static addRedirect(from, to) {
1566
+ if (!this._redirects.some(r => r.from === from)) {
1567
+ this._redirects.push({ from, to });
1568
+ }
1569
+ }
1570
+ /**
1571
+ * Document loader which uses a caching mechanism.
1572
+ * @param url The document url to load.
1573
+ * @returns The document.
1574
+ * @internal
1575
+ */
1576
+ static async documentLoader(url) {
1577
+ for (const redirect of JsonLdProcessor._redirects) {
1578
+ if (redirect.from.test(url)) {
1579
+ url = redirect.to;
1580
+ break;
1581
+ }
1582
+ }
1583
+ // Cache the results for an hour
1584
+ const response = await FetchHelper.fetchJson(JsonLdProcessor._CLASS_NAME, url, HttpMethod.GET, undefined, {
1585
+ cacheTtlMs: 3600000,
1586
+ headers: {
1587
+ Accept: `${MimeTypes.JsonLd},${MimeTypes.Json}`
1588
+ }
1589
+ });
1590
+ return {
1591
+ documentUrl: url,
1592
+ document: response
1593
+ };
1594
+ }
1595
+ }
1596
+
1597
+ export { JsonLdDataTypes, JsonLdHelper, JsonLdProcessor, JsonLdTypes };