@twin.org/data-json-ld 0.0.2-next.3 → 0.0.3-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/dataTypes/jsonLdDataTypes.js +171 -0
- package/dist/es/dataTypes/jsonLdDataTypes.js.map +1 -0
- package/dist/es/index.js +33 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/models/IJsonLdContainerType.js +4 -0
- package/dist/es/models/IJsonLdContainerType.js.map +1 -0
- package/dist/es/models/IJsonLdContainerTypeArray.js +2 -0
- package/dist/es/models/IJsonLdContainerTypeArray.js.map +1 -0
- package/dist/es/models/IJsonLdContextDefinition.js +2 -0
- package/dist/es/models/IJsonLdContextDefinition.js.map +1 -0
- package/dist/es/models/IJsonLdContextDefinitionElement.js +2 -0
- package/dist/es/models/IJsonLdContextDefinitionElement.js.map +1 -0
- package/dist/es/models/IJsonLdContextDefinitionRoot.js +2 -0
- package/dist/es/models/IJsonLdContextDefinitionRoot.js.map +1 -0
- package/dist/es/models/IJsonLdDocument.js +2 -0
- package/dist/es/models/IJsonLdDocument.js.map +1 -0
- package/dist/es/models/IJsonLdExpandedTermDefinition.js +2 -0
- package/dist/es/models/IJsonLdExpandedTermDefinition.js.map +1 -0
- package/dist/es/models/IJsonLdGraphObject.js +2 -0
- package/dist/es/models/IJsonLdGraphObject.js.map +1 -0
- package/dist/es/models/IJsonLdIdMap.js +2 -0
- package/dist/es/models/IJsonLdIdMap.js.map +1 -0
- package/dist/es/models/IJsonLdIncludedBlock.js +2 -0
- package/dist/es/models/IJsonLdIncludedBlock.js.map +1 -0
- package/dist/es/models/IJsonLdIndexMap.js +2 -0
- package/dist/es/models/IJsonLdIndexMap.js.map +1 -0
- package/dist/es/models/IJsonLdIndexMapItem.js +2 -0
- package/dist/es/models/IJsonLdIndexMapItem.js.map +1 -0
- package/dist/es/models/IJsonLdJsonArray.js +2 -0
- package/dist/es/models/IJsonLdJsonArray.js.map +1 -0
- package/dist/es/models/IJsonLdJsonObject.js +2 -0
- package/dist/es/models/IJsonLdJsonObject.js.map +1 -0
- package/dist/es/models/IJsonLdJsonPrimitive.js +4 -0
- package/dist/es/models/IJsonLdJsonPrimitive.js.map +1 -0
- package/dist/es/models/IJsonLdJsonValue.js +2 -0
- package/dist/es/models/IJsonLdJsonValue.js.map +1 -0
- package/dist/es/models/IJsonLdLanguageMap.js +4 -0
- package/dist/es/models/IJsonLdLanguageMap.js.map +1 -0
- package/dist/es/models/IJsonLdListObject.js +2 -0
- package/dist/es/models/IJsonLdListObject.js.map +1 -0
- package/dist/es/models/IJsonLdListOrSetItem.js +2 -0
- package/dist/es/models/IJsonLdListOrSetItem.js.map +1 -0
- package/dist/es/models/IJsonLdNodeObject.js +2 -0
- package/dist/es/models/IJsonLdNodeObject.js.map +1 -0
- package/dist/es/models/IJsonLdNodePrimitive.js +2 -0
- package/dist/es/models/IJsonLdNodePrimitive.js.map +1 -0
- package/dist/es/models/IJsonLdObject.js +2 -0
- package/dist/es/models/IJsonLdObject.js.map +1 -0
- package/dist/es/models/IJsonLdSetObject.js +2 -0
- package/dist/es/models/IJsonLdSetObject.js.map +1 -0
- package/dist/es/models/IJsonLdTypeMap.js +2 -0
- package/dist/es/models/IJsonLdTypeMap.js.map +1 -0
- package/dist/es/models/IJsonLdValueObject.js +2 -0
- package/dist/es/models/IJsonLdValueObject.js.map +1 -0
- package/dist/es/models/jsonLdContexts.js +13 -0
- package/dist/es/models/jsonLdContexts.js.map +1 -0
- package/dist/es/models/jsonLdTypes.js +113 -0
- package/dist/es/models/jsonLdTypes.js.map +1 -0
- package/dist/es/schemas/JsonLdContainerType.json +13 -0
- package/dist/es/schemas/JsonLdContainerTypeArray.json +179 -0
- package/dist/es/schemas/JsonLdContextDefinition.json +76 -0
- package/dist/es/schemas/JsonLdContextDefinitionElement.json +16 -0
- package/dist/es/schemas/JsonLdContextDefinitionRoot.json +16 -0
- package/dist/es/schemas/JsonLdDocument.json +48 -0
- package/dist/es/schemas/JsonLdExpandedTermDefinition.json +136 -0
- package/dist/es/schemas/JsonLdGraphObject.json +44 -0
- package/dist/es/schemas/JsonLdIdMap.json +9 -0
- package/dist/es/schemas/JsonLdIncludedBlock.json +16 -0
- package/dist/es/schemas/JsonLdIndexMap.json +19 -0
- package/dist/es/schemas/JsonLdIndexMapItem.json +31 -0
- package/dist/es/schemas/JsonLdJsonArray.json +9 -0
- package/dist/es/schemas/JsonLdJsonObject.json +16 -0
- package/dist/es/schemas/JsonLdJsonPrimitive.json +11 -0
- package/dist/es/schemas/JsonLdJsonValue.json +16 -0
- package/dist/es/schemas/JsonLdLanguageMap.json +22 -0
- package/dist/es/schemas/JsonLdListObject.json +28 -0
- package/dist/es/schemas/JsonLdListOrSetItem.json +25 -0
- package/dist/es/schemas/JsonLdNodeObject.json +100 -0
- package/dist/es/schemas/JsonLdNodePrimitive.json +34 -0
- package/dist/es/schemas/JsonLdObject.json +76 -0
- package/dist/es/schemas/JsonLdSetObject.json +28 -0
- package/dist/es/schemas/JsonLdTypeMap.json +16 -0
- package/dist/es/schemas/JsonLdValueObject.json +113 -0
- package/dist/es/utils/jsonLdHelper.js +79 -0
- package/dist/es/utils/jsonLdHelper.js.map +1 -0
- package/dist/es/utils/jsonLdProcessor.js +375 -0
- package/dist/es/utils/jsonLdProcessor.js.map +1 -0
- package/dist/types/index.d.ts +30 -30
- package/dist/types/models/IJsonLdContainerTypeArray.d.ts +1 -1
- package/dist/types/models/IJsonLdContextDefinition.d.ts +1 -1
- package/dist/types/models/IJsonLdContextDefinitionElement.d.ts +1 -1
- package/dist/types/models/IJsonLdContextDefinitionRoot.d.ts +1 -1
- package/dist/types/models/IJsonLdDocument.d.ts +3 -3
- package/dist/types/models/IJsonLdExpandedTermDefinition.d.ts +3 -3
- package/dist/types/models/IJsonLdGraphObject.d.ts +2 -2
- package/dist/types/models/IJsonLdIdMap.d.ts +1 -1
- package/dist/types/models/IJsonLdIncludedBlock.d.ts +1 -1
- package/dist/types/models/IJsonLdIndexMap.d.ts +1 -1
- package/dist/types/models/IJsonLdIndexMapItem.d.ts +4 -4
- package/dist/types/models/IJsonLdJsonArray.d.ts +1 -1
- package/dist/types/models/IJsonLdJsonObject.d.ts +1 -1
- package/dist/types/models/IJsonLdJsonValue.d.ts +3 -3
- package/dist/types/models/IJsonLdListObject.d.ts +1 -1
- package/dist/types/models/IJsonLdListOrSetItem.d.ts +2 -2
- package/dist/types/models/IJsonLdNodeObject.d.ts +7 -7
- package/dist/types/models/IJsonLdNodePrimitive.d.ts +5 -5
- package/dist/types/models/IJsonLdObject.d.ts +4 -4
- package/dist/types/models/IJsonLdSetObject.d.ts +1 -1
- package/dist/types/models/IJsonLdTypeMap.d.ts +1 -1
- package/dist/types/models/IJsonLdValueObject.d.ts +3 -3
- package/dist/types/utils/jsonLdHelper.d.ts +8 -1
- package/dist/types/utils/jsonLdProcessor.d.ts +4 -4
- package/docs/changelog.md +45 -0
- package/docs/reference/classes/JsonLdHelper.md +28 -0
- package/docs/reference/classes/JsonLdProcessor.md +9 -9
- package/docs/reference/interfaces/IJsonLdContextDefinition.md +4 -4
- package/docs/reference/interfaces/IJsonLdJsonObject.md +1 -1
- package/docs/reference/interfaces/IJsonLdLanguageMap.md +1 -1
- package/docs/reference/interfaces/IJsonLdNodeObject.md +1 -1
- package/locales/.validate-ignore +1 -0
- package/package.json +19 -9
- package/dist/cjs/index.cjs +0 -2017
- package/dist/esm/index.mjs +0 -2011
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://schema.twindev.org/json-ld/JsonLdIndexMap",
|
|
4
|
+
"description": "An index map allows keys that have no semantic meaning, but should be preserved regardless, to be used in JSON-LD documents.",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"additionalProperties": {
|
|
7
|
+
"anyOf": [
|
|
8
|
+
{
|
|
9
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdIndexMapItem"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"type": "array",
|
|
13
|
+
"items": {
|
|
14
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdIndexMapItem"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://schema.twindev.org/json-ld/JsonLdIndexMapItem",
|
|
4
|
+
"description": "The items that can be stored in an index map.",
|
|
5
|
+
"anyOf": [
|
|
6
|
+
{
|
|
7
|
+
"type": "null"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"type": "boolean"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"type": "number"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"type": "string"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdNodeObject"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdValueObject"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdListObject"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdSetObject"
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://schema.twindev.org/json-ld/JsonLdJsonArray",
|
|
4
|
+
"description": "JSON Type for array.",
|
|
5
|
+
"type": "array",
|
|
6
|
+
"items": {
|
|
7
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdJsonValue"
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://schema.twindev.org/json-ld/JsonLdJsonObject",
|
|
4
|
+
"description": "JSON Type for object.",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"additionalProperties": {
|
|
7
|
+
"anyOf": [
|
|
8
|
+
{
|
|
9
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdJsonValue"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"not": {}
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://schema.twindev.org/json-ld/JsonLdJsonValue",
|
|
4
|
+
"description": "JSON Value.",
|
|
5
|
+
"anyOf": [
|
|
6
|
+
{
|
|
7
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdJsonPrimitive"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdJsonArray"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdJsonObject"
|
|
14
|
+
}
|
|
15
|
+
]
|
|
16
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://schema.twindev.org/json-ld/JsonLdLanguageMap",
|
|
4
|
+
"description": "A language map is used to associate a language with a value in a way that allows easy programmatic access.",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"additionalProperties": {
|
|
7
|
+
"anyOf": [
|
|
8
|
+
{
|
|
9
|
+
"type": "null"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"type": "string"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"type": "array",
|
|
16
|
+
"items": {
|
|
17
|
+
"type": "string"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://schema.twindev.org/json-ld/JsonLdListObject",
|
|
4
|
+
"description": "A list represents an ordered set of values.",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"@list": {
|
|
8
|
+
"anyOf": [
|
|
9
|
+
{
|
|
10
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdListOrSetItem"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"type": "array",
|
|
14
|
+
"items": {
|
|
15
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdListOrSetItem"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
},
|
|
20
|
+
"@index": {
|
|
21
|
+
"type": "string"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"required": [
|
|
25
|
+
"@list"
|
|
26
|
+
],
|
|
27
|
+
"additionalProperties": false
|
|
28
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://schema.twindev.org/json-ld/JsonLdListOrSetItem",
|
|
4
|
+
"description": "A list or set item can be a null, boolean, number, string, node object, or value object.",
|
|
5
|
+
"anyOf": [
|
|
6
|
+
{
|
|
7
|
+
"type": "null"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"type": "boolean"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"type": "number"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"type": "string"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdNodeObject"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdValueObject"
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://schema.twindev.org/json-ld/JsonLdNodeObject",
|
|
4
|
+
"description": "A node object represents zero or more properties of a node in the graph serialized by the JSON-LD document.",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"additionalProperties": {
|
|
7
|
+
"anyOf": [
|
|
8
|
+
{
|
|
9
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdNodePrimitive"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdLanguageMap"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdIndexMap"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdIncludedBlock"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdIdMap"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdTypeMap"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"type": "array"
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
},
|
|
31
|
+
"properties": {
|
|
32
|
+
"@context": {
|
|
33
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdContextDefinitionRoot"
|
|
34
|
+
},
|
|
35
|
+
"@id": {
|
|
36
|
+
"anyOf": [
|
|
37
|
+
{
|
|
38
|
+
"type": "string"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"type": "array",
|
|
42
|
+
"items": {
|
|
43
|
+
"type": "string"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
"@included": {
|
|
49
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdIncludedBlock"
|
|
50
|
+
},
|
|
51
|
+
"@graph": {
|
|
52
|
+
"anyOf": [
|
|
53
|
+
{
|
|
54
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdNodeObject"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"type": "array",
|
|
58
|
+
"items": {
|
|
59
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdNodeObject"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
]
|
|
63
|
+
},
|
|
64
|
+
"@nest": {
|
|
65
|
+
"anyOf": [
|
|
66
|
+
{
|
|
67
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdJsonObject"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"type": "array",
|
|
71
|
+
"items": {
|
|
72
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdJsonObject"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
"@type": {
|
|
78
|
+
"anyOf": [
|
|
79
|
+
{
|
|
80
|
+
"type": "string"
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"type": "array",
|
|
84
|
+
"items": {
|
|
85
|
+
"type": "string"
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
},
|
|
90
|
+
"@reverse": {
|
|
91
|
+
"type": "object",
|
|
92
|
+
"additionalProperties": {
|
|
93
|
+
"type": "string"
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
"@index": {
|
|
97
|
+
"type": "string"
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://schema.twindev.org/json-ld/JsonLdNodePrimitive",
|
|
4
|
+
"description": "A node primitive is a JSON-LD value which is not one of the defined NodeObject properties.",
|
|
5
|
+
"anyOf": [
|
|
6
|
+
{
|
|
7
|
+
"type": "null"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"type": "boolean"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"type": "number"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"type": "string"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdNodeObject"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdGraphObject"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdValueObject"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdListObject"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdSetObject"
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://schema.twindev.org/json-ld/JsonLdObject",
|
|
4
|
+
"description": "An object represents the pre-defined properties of the node object in the graph serialized by the JSON-LD document.",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"@context": {
|
|
8
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdContextDefinitionRoot"
|
|
9
|
+
},
|
|
10
|
+
"@id": {
|
|
11
|
+
"anyOf": [
|
|
12
|
+
{
|
|
13
|
+
"type": "string"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"type": "array",
|
|
17
|
+
"items": {
|
|
18
|
+
"type": "string"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
},
|
|
23
|
+
"@included": {
|
|
24
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdIncludedBlock"
|
|
25
|
+
},
|
|
26
|
+
"@graph": {
|
|
27
|
+
"anyOf": [
|
|
28
|
+
{
|
|
29
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdNodeObject"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"type": "array",
|
|
33
|
+
"items": {
|
|
34
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdNodeObject"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
},
|
|
39
|
+
"@nest": {
|
|
40
|
+
"anyOf": [
|
|
41
|
+
{
|
|
42
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdJsonObject"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"type": "array",
|
|
46
|
+
"items": {
|
|
47
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdJsonObject"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
"@type": {
|
|
53
|
+
"anyOf": [
|
|
54
|
+
{
|
|
55
|
+
"type": "string"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"type": "array",
|
|
59
|
+
"items": {
|
|
60
|
+
"type": "string"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
},
|
|
65
|
+
"@reverse": {
|
|
66
|
+
"type": "object",
|
|
67
|
+
"additionalProperties": {
|
|
68
|
+
"type": "string"
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"@index": {
|
|
72
|
+
"type": "string"
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
"additionalProperties": false
|
|
76
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://schema.twindev.org/json-ld/JsonLdSetObject",
|
|
4
|
+
"description": "A set represents an unordered set of values.",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"@set": {
|
|
8
|
+
"anyOf": [
|
|
9
|
+
{
|
|
10
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdListOrSetItem"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"type": "array",
|
|
14
|
+
"items": {
|
|
15
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdListOrSetItem"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
},
|
|
20
|
+
"@index": {
|
|
21
|
+
"type": "string"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"required": [
|
|
25
|
+
"@set"
|
|
26
|
+
],
|
|
27
|
+
"additionalProperties": false
|
|
28
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://schema.twindev.org/json-ld/JsonLdTypeMap",
|
|
4
|
+
"description": "A type map is used to associate an IRI with a value that allows easy programmatic access.",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"additionalProperties": {
|
|
7
|
+
"anyOf": [
|
|
8
|
+
{
|
|
9
|
+
"type": "string"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdNodeObject"
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://schema.twindev.org/json-ld/JsonLdValueObject",
|
|
4
|
+
"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.",
|
|
5
|
+
"anyOf": [
|
|
6
|
+
{
|
|
7
|
+
"type": "object",
|
|
8
|
+
"additionalProperties": false,
|
|
9
|
+
"properties": {
|
|
10
|
+
"@value": {
|
|
11
|
+
"type": [
|
|
12
|
+
"null",
|
|
13
|
+
"boolean",
|
|
14
|
+
"number",
|
|
15
|
+
"string"
|
|
16
|
+
]
|
|
17
|
+
},
|
|
18
|
+
"@language": {
|
|
19
|
+
"type": "string"
|
|
20
|
+
},
|
|
21
|
+
"@direction": {
|
|
22
|
+
"type": [
|
|
23
|
+
"string",
|
|
24
|
+
"null"
|
|
25
|
+
],
|
|
26
|
+
"enum": [
|
|
27
|
+
"ltr",
|
|
28
|
+
"rtl",
|
|
29
|
+
null
|
|
30
|
+
]
|
|
31
|
+
},
|
|
32
|
+
"@index": {
|
|
33
|
+
"type": "string"
|
|
34
|
+
},
|
|
35
|
+
"@context": {
|
|
36
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdContextDefinitionRoot"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"required": [
|
|
40
|
+
"@value"
|
|
41
|
+
]
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"type": "object",
|
|
45
|
+
"additionalProperties": false,
|
|
46
|
+
"properties": {
|
|
47
|
+
"@value": {
|
|
48
|
+
"type": [
|
|
49
|
+
"null",
|
|
50
|
+
"boolean",
|
|
51
|
+
"number",
|
|
52
|
+
"string"
|
|
53
|
+
]
|
|
54
|
+
},
|
|
55
|
+
"@type": {
|
|
56
|
+
"type": "string"
|
|
57
|
+
},
|
|
58
|
+
"@index": {
|
|
59
|
+
"type": "string"
|
|
60
|
+
},
|
|
61
|
+
"@context": {
|
|
62
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdContextDefinitionRoot"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"required": [
|
|
66
|
+
"@type",
|
|
67
|
+
"@value"
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"type": "object",
|
|
72
|
+
"additionalProperties": false,
|
|
73
|
+
"properties": {
|
|
74
|
+
"@value": {
|
|
75
|
+
"anyOf": [
|
|
76
|
+
{
|
|
77
|
+
"type": "null"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"type": "boolean"
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"type": "number"
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"type": "string"
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdJsonObject"
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdJsonArray"
|
|
93
|
+
}
|
|
94
|
+
]
|
|
95
|
+
},
|
|
96
|
+
"@type": {
|
|
97
|
+
"type": "string",
|
|
98
|
+
"const": "@json"
|
|
99
|
+
},
|
|
100
|
+
"@index": {
|
|
101
|
+
"type": "string"
|
|
102
|
+
},
|
|
103
|
+
"@context": {
|
|
104
|
+
"$ref": "https://schema.twindev.org/json-ld/JsonLdContextDefinitionRoot"
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
"required": [
|
|
108
|
+
"@type",
|
|
109
|
+
"@value"
|
|
110
|
+
]
|
|
111
|
+
}
|
|
112
|
+
]
|
|
113
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { ArrayHelper, Guards, Is } from "@twin.org/core";
|
|
4
|
+
import { DataTypeHelper } from "@twin.org/data-core";
|
|
5
|
+
import { JsonLdProcessor } from "./jsonLdProcessor.js";
|
|
6
|
+
/**
|
|
7
|
+
* Class to help with JSON LD.
|
|
8
|
+
*/
|
|
9
|
+
export class JsonLdHelper {
|
|
10
|
+
/**
|
|
11
|
+
* The class name.
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
static CLASS_NAME = "JsonLdHelper";
|
|
15
|
+
/**
|
|
16
|
+
* Validate a JSON-LD document.
|
|
17
|
+
* @param document The JSON-LD document to validate.
|
|
18
|
+
* @param validationFailures The list of validation failures to add to.
|
|
19
|
+
* @param options Optional options for validation.
|
|
20
|
+
* @param options.failOnMissingType If true, will fail validation if the data type is missing, defaults to false.
|
|
21
|
+
* @param options.validationMode The validation mode to use, defaults to either.
|
|
22
|
+
* @returns True if the document was valid.
|
|
23
|
+
*/
|
|
24
|
+
static async validate(document, validationFailures, options) {
|
|
25
|
+
if (Is.array(document)) {
|
|
26
|
+
// If the document is an array of nodes, validate each node
|
|
27
|
+
for (const node of document) {
|
|
28
|
+
await JsonLdHelper.validate(node, validationFailures, options);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else if (Is.array(document["@graph"])) {
|
|
32
|
+
// If the graph is an array of nodes, validate each node
|
|
33
|
+
for (const node of document["@graph"]) {
|
|
34
|
+
await JsonLdHelper.validate(node, validationFailures, options);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else if (Is.object(document)) {
|
|
38
|
+
// Expand the document to ensure we have the full context for types
|
|
39
|
+
// As the data types in the factories are always fully qualified
|
|
40
|
+
const expandedDocs = await JsonLdProcessor.expand(document);
|
|
41
|
+
if (Is.arrayValue(expandedDocs)) {
|
|
42
|
+
for (const expandedDoc of expandedDocs) {
|
|
43
|
+
const expandedDataTypes = ArrayHelper.fromObjectOrArray(expandedDoc["@type"]);
|
|
44
|
+
if (Is.arrayValue(expandedDataTypes)) {
|
|
45
|
+
for (const expandedDataType of expandedDataTypes) {
|
|
46
|
+
await DataTypeHelper.validate("document", expandedDataType, document, validationFailures, options);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return validationFailures.length === 0;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Expand the JSON-LD document and check if it is of a specific type.
|
|
56
|
+
* @param document The JSON-LD document to check.
|
|
57
|
+
* @param type The type to check for.
|
|
58
|
+
* @returns True if the document is of the specified type.
|
|
59
|
+
*/
|
|
60
|
+
static async isType(document, type) {
|
|
61
|
+
Guards.object(JsonLdHelper.CLASS_NAME, "document", document);
|
|
62
|
+
Guards.arrayValue(JsonLdHelper.CLASS_NAME, "type", type);
|
|
63
|
+
const expanded = await JsonLdProcessor.expand(document);
|
|
64
|
+
if (Is.arrayValue(expanded)) {
|
|
65
|
+
for (const item of expanded) {
|
|
66
|
+
const types = ArrayHelper.fromObjectOrArray(item["@type"]);
|
|
67
|
+
if (Is.arrayValue(types)) {
|
|
68
|
+
// All required types must be present in this item's @type array
|
|
69
|
+
const itemTypes = new Set(types);
|
|
70
|
+
if (type.every(t => itemTypes.has(t))) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=jsonLdHelper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonLdHelper.js","sourceRoot":"","sources":["../../../src/utils/jsonLdHelper.ts"],"names":[],"mappings":"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","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ArrayHelper, Guards, Is, type IValidationFailure } from \"@twin.org/core\";\nimport { DataTypeHelper, type ValidationMode } from \"@twin.org/data-core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { JsonLdProcessor } from \"./jsonLdProcessor.js\";\nimport type { IJsonLdDocument } from \"../models/IJsonLdDocument.js\";\nimport type { IJsonLdNodeObject } from \"../models/IJsonLdNodeObject.js\";\n\n/**\n * Class to help with JSON LD.\n */\nexport class JsonLdHelper {\n\t/**\n\t * The class name.\n\t * @internal\n\t */\n\tpublic static readonly CLASS_NAME = nameof<JsonLdHelper>();\n\n\t/**\n\t * Validate a JSON-LD document.\n\t * @param document The JSON-LD document to validate.\n\t * @param validationFailures The list of validation failures to add to.\n\t * @param options Optional options for validation.\n\t * @param options.failOnMissingType If true, will fail validation if the data type is missing, defaults to false.\n\t * @param options.validationMode The validation mode to use, defaults to either.\n\t * @returns True if the document was valid.\n\t */\n\tpublic static async validate<T extends IJsonLdDocument = IJsonLdDocument>(\n\t\tdocument: T,\n\t\tvalidationFailures: IValidationFailure[],\n\t\toptions?: {\n\t\t\tvalidationMode?: ValidationMode;\n\t\t\tfailOnMissingType?: boolean;\n\t\t}\n\t): Promise<boolean> {\n\t\tif (Is.array<IJsonLdNodeObject>(document)) {\n\t\t\t// If the document is an array of nodes, validate each node\n\t\t\tfor (const node of document) {\n\t\t\t\tawait JsonLdHelper.validate(node, validationFailures, options);\n\t\t\t}\n\t\t} else if (Is.array<IJsonLdNodeObject>(document[\"@graph\"])) {\n\t\t\t// If the graph is an array of nodes, validate each node\n\t\t\tfor (const node of document[\"@graph\"]) {\n\t\t\t\tawait JsonLdHelper.validate(node, validationFailures, options);\n\t\t\t}\n\t\t} else if (Is.object<IJsonLdNodeObject>(document)) {\n\t\t\t// Expand the document to ensure we have the full context for types\n\t\t\t// As the data types in the factories are always fully qualified\n\t\t\tconst expandedDocs = await JsonLdProcessor.expand(document);\n\t\t\tif (Is.arrayValue(expandedDocs)) {\n\t\t\t\tfor (const expandedDoc of expandedDocs) {\n\t\t\t\t\tconst expandedDataTypes = ArrayHelper.fromObjectOrArray(expandedDoc[\"@type\"]);\n\t\t\t\t\tif (Is.arrayValue(expandedDataTypes)) {\n\t\t\t\t\t\tfor (const expandedDataType of expandedDataTypes) {\n\t\t\t\t\t\t\tawait DataTypeHelper.validate(\n\t\t\t\t\t\t\t\t\"document\",\n\t\t\t\t\t\t\t\texpandedDataType,\n\t\t\t\t\t\t\t\tdocument,\n\t\t\t\t\t\t\t\tvalidationFailures,\n\t\t\t\t\t\t\t\toptions\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn validationFailures.length === 0;\n\t}\n\n\t/**\n\t * Expand the JSON-LD document and check if it is of a specific type.\n\t * @param document The JSON-LD document to check.\n\t * @param type The type to check for.\n\t * @returns True if the document is of the specified type.\n\t */\n\tpublic static async isType(document: IJsonLdDocument, type: string[]): Promise<boolean> {\n\t\tGuards.object<IJsonLdDocument>(JsonLdHelper.CLASS_NAME, nameof(document), document);\n\t\tGuards.arrayValue(JsonLdHelper.CLASS_NAME, nameof(type), type);\n\n\t\tconst expanded = await JsonLdProcessor.expand(document);\n\n\t\tif (Is.arrayValue(expanded)) {\n\t\t\tfor (const item of expanded) {\n\t\t\t\tconst types = ArrayHelper.fromObjectOrArray(item[\"@type\"]);\n\t\t\t\tif (Is.arrayValue(types)) {\n\t\t\t\t\t// All required types must be present in this item's @type array\n\t\t\t\t\tconst itemTypes = new Set(types);\n\t\t\t\t\tif (type.every(t => itemTypes.has(t))) {\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn false;\n\t}\n}\n"]}
|