@twin.org/data-json-ld 0.0.1-next.10
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/LICENSE +201 -0
- package/README.md +21 -0
- package/dist/cjs/index.cjs +1750 -0
- package/dist/esm/index.mjs +1745 -0
- package/dist/types/dataTypes/jsonLdDataTypes.d.ts +9 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/models/IJsonLdDocument.d.ts +222 -0
- package/dist/types/models/jsonLdTypes.d.ts +109 -0
- package/dist/types/utils/jsonLdHelper.d.ts +16 -0
- package/dist/types/utils/jsonLdProcessor.d.ts +65 -0
- package/docs/changelog.md +5 -0
- package/docs/examples.md +1 -0
- package/docs/reference/classes/JsonLdDataTypes.md +25 -0
- package/docs/reference/classes/JsonLdHelper.md +45 -0
- package/docs/reference/classes/JsonLdProcessor.md +199 -0
- package/docs/reference/index.md +44 -0
- package/docs/reference/interfaces/IJsonLdContextDefinition.md +73 -0
- package/docs/reference/interfaces/IJsonLdGraphObject.md +31 -0
- package/docs/reference/interfaces/IJsonLdIdMap.md +11 -0
- package/docs/reference/interfaces/IJsonLdIndexMap.md +12 -0
- package/docs/reference/interfaces/IJsonLdJsonObject.md +5 -0
- package/docs/reference/interfaces/IJsonLdLanguageMap.md +11 -0
- package/docs/reference/interfaces/IJsonLdListObject.md +19 -0
- package/docs/reference/interfaces/IJsonLdNodeObject.md +100 -0
- package/docs/reference/interfaces/IJsonLdObject.md +64 -0
- package/docs/reference/interfaces/IJsonLdSetObject.md +19 -0
- package/docs/reference/interfaces/IJsonLdTypeMap.md +11 -0
- package/docs/reference/type-aliases/IJsonLdContainerType.md +3 -0
- package/docs/reference/type-aliases/IJsonLdContainerTypeArray.md +3 -0
- package/docs/reference/type-aliases/IJsonLdContextDefinitionElement.md +5 -0
- package/docs/reference/type-aliases/IJsonLdContextDefinitionRoot.md +5 -0
- package/docs/reference/type-aliases/IJsonLdDocument.md +11 -0
- package/docs/reference/type-aliases/IJsonLdExpandedTermDefinition.md +41 -0
- package/docs/reference/type-aliases/IJsonLdIncludedBlock.md +9 -0
- package/docs/reference/type-aliases/IJsonLdIndexMapItem.md +5 -0
- package/docs/reference/type-aliases/IJsonLdJsonArray.md +3 -0
- package/docs/reference/type-aliases/IJsonLdJsonPrimitive.md +3 -0
- package/docs/reference/type-aliases/IJsonLdJsonValue.md +3 -0
- package/docs/reference/type-aliases/IJsonLdKeyword.md +105 -0
- package/docs/reference/type-aliases/IJsonLdListOrSetItem.md +5 -0
- package/docs/reference/type-aliases/IJsonLdNodePrimitive.md +5 -0
- package/docs/reference/type-aliases/IJsonLdValueObject.md +20 -0
- package/docs/reference/type-aliases/JsonLdTypes.md +5 -0
- package/docs/reference/variables/JsonLdTypes.md +157 -0
- package/locales/en.json +7 -0
- package/package.json +44 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is a copy of the types from the npm jsonld package. This is necessary as the JSON schema generators
|
|
3
|
+
* that are used in other packages cannot understand some of the types e.g. OrArray
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Types from the jsonld Specification:
|
|
7
|
+
* https://www.w3.org/TR/json-ld11/
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* A JSON-LD document MUST be valid JSON text as described in [RFC8259],
|
|
11
|
+
* or some format that can be represented in the JSON-LD internal representation
|
|
12
|
+
* that is equivalent to valid JSON text.
|
|
13
|
+
* @see https://www.w3.org/TR/json-ld11/#json-ld-grammar
|
|
14
|
+
*/
|
|
15
|
+
export type IJsonLdDocument = IJsonLdNodeObject | IJsonLdNodeObject[] | {
|
|
16
|
+
"@context"?: IJsonLdKeyword["@context"] | undefined;
|
|
17
|
+
"@graph"?: IJsonLdKeyword["@graph"] | undefined;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* A node object represents zero or more properties of a node
|
|
21
|
+
* in the graph serialized by the JSON-LD document.
|
|
22
|
+
* @see https://www.w3.org/TR/json-ld11/#node-objects
|
|
23
|
+
*/
|
|
24
|
+
export interface IJsonLdNodeObject extends IJsonLdObject {
|
|
25
|
+
[key: string]: IJsonLdNodePrimitive | IJsonLdNodePrimitive[] | IJsonLdLanguageMap | IJsonLdIndexMap | IJsonLdIncludedBlock | IJsonLdIdMap | IJsonLdTypeMap | IJsonLdNodeObject[keyof IJsonLdNodeObject];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* An object represents the pre-defined properties of the node object
|
|
29
|
+
* in the graph serialized by the JSON-LD document.
|
|
30
|
+
* @see https://www.w3.org/TR/json-ld11/#node-objects
|
|
31
|
+
*/
|
|
32
|
+
export interface IJsonLdObject {
|
|
33
|
+
"@context"?: IJsonLdKeyword["@context"] | undefined;
|
|
34
|
+
"@id"?: IJsonLdKeyword["@id"] | undefined;
|
|
35
|
+
"@included"?: IJsonLdKeyword["@included"] | undefined;
|
|
36
|
+
"@graph"?: IJsonLdNodeObject | IJsonLdNodeObject[] | undefined;
|
|
37
|
+
"@nest"?: IJsonLdJsonObject | IJsonLdJsonObject[] | undefined;
|
|
38
|
+
"@type"?: IJsonLdKeyword["@type"] | IJsonLdKeyword["@type"][] | undefined;
|
|
39
|
+
"@reverse"?: {
|
|
40
|
+
[key: string]: IJsonLdKeyword["@reverse"];
|
|
41
|
+
} | undefined;
|
|
42
|
+
"@index"?: IJsonLdKeyword["@index"] | undefined;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* A node primitive is a JSON-LD value which is not one of the defined NodeObject properties.
|
|
46
|
+
*/
|
|
47
|
+
export type IJsonLdNodePrimitive = null | boolean | number | string | IJsonLdNodeObject | IJsonLdGraphObject | IJsonLdValueObject | IJsonLdListObject | IJsonLdSetObject;
|
|
48
|
+
/**
|
|
49
|
+
* A graph object represents a named graph, which MAY include an explicit graph name.
|
|
50
|
+
* @see https://www.w3.org/TR/json-ld11/#graph-objects
|
|
51
|
+
*/
|
|
52
|
+
export interface IJsonLdGraphObject {
|
|
53
|
+
"@graph": IJsonLdNodeObject | IJsonLdNodeObject[];
|
|
54
|
+
"@index"?: IJsonLdKeyword["@index"] | undefined;
|
|
55
|
+
"@id"?: IJsonLdKeyword["@id"] | undefined;
|
|
56
|
+
"@context"?: IJsonLdKeyword["@context"] | undefined;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* A value object is used to explicitly associate a type or a language with a value
|
|
60
|
+
* to create a typed value or a language-tagged string and possibly associate a base direction.
|
|
61
|
+
* @see https://www.w3.org/TR/json-ld11/#value-objects
|
|
62
|
+
*/
|
|
63
|
+
export type IJsonLdValueObject = {
|
|
64
|
+
"@index"?: IJsonLdKeyword["@index"] | undefined;
|
|
65
|
+
"@context"?: IJsonLdKeyword["@context"] | undefined;
|
|
66
|
+
} & ({
|
|
67
|
+
"@value": IJsonLdKeyword["@value"];
|
|
68
|
+
"@language"?: IJsonLdKeyword["@language"] | undefined;
|
|
69
|
+
"@direction"?: IJsonLdKeyword["@direction"] | undefined;
|
|
70
|
+
} | {
|
|
71
|
+
"@value": IJsonLdKeyword["@value"];
|
|
72
|
+
"@type": IJsonLdKeyword["@type"];
|
|
73
|
+
} | {
|
|
74
|
+
"@value": IJsonLdKeyword["@value"] | IJsonLdJsonObject | IJsonLdJsonArray;
|
|
75
|
+
"@type": "@json";
|
|
76
|
+
});
|
|
77
|
+
/**
|
|
78
|
+
* A list represents an ordered set of values.
|
|
79
|
+
* @see https://www.w3.org/TR/json-ld11/#lists-and-sets
|
|
80
|
+
*/
|
|
81
|
+
export interface IJsonLdListObject {
|
|
82
|
+
"@list": IJsonLdKeyword["@list"];
|
|
83
|
+
"@index"?: IJsonLdKeyword["@index"] | undefined;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* A set represents an unordered set of values.
|
|
87
|
+
* @see https://www.w3.org/TR/json-ld11/#lists-and-sets
|
|
88
|
+
*/
|
|
89
|
+
export interface IJsonLdSetObject {
|
|
90
|
+
"@set": IJsonLdKeyword["@set"];
|
|
91
|
+
"@index"?: IJsonLdKeyword["@index"] | undefined;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* A language map is used to associate a language with a value in a way that allows easy programmatic access.
|
|
95
|
+
* @see https://www.w3.org/TR/json-ld11/#language-maps
|
|
96
|
+
*/
|
|
97
|
+
export interface IJsonLdLanguageMap {
|
|
98
|
+
[key: string]: null | string | string[];
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* An index map allows keys that have no semantic meaning, but should be preserved regardless,
|
|
102
|
+
* to be used in JSON-LD documents.
|
|
103
|
+
* @see https://www.w3.org/TR/json-ld11/#index-maps
|
|
104
|
+
*/
|
|
105
|
+
export interface IJsonLdIndexMap {
|
|
106
|
+
[key: string]: IJsonLdIndexMapItem | IJsonLdIndexMapItem[];
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The items that can be stored in an index map.
|
|
110
|
+
*/
|
|
111
|
+
export type IJsonLdIndexMapItem = null | boolean | number | string | IJsonLdNodeObject | IJsonLdValueObject | IJsonLdListObject | IJsonLdSetObject;
|
|
112
|
+
/**
|
|
113
|
+
* An id map is used to associate an IRI with a value that allows easy programmatic access.
|
|
114
|
+
* @see https://www.w3.org/TR/json-ld11/#id-maps
|
|
115
|
+
*/
|
|
116
|
+
export interface IJsonLdIdMap {
|
|
117
|
+
[key: string]: IJsonLdNodeObject;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* A type map is used to associate an IRI with a value that allows easy programmatic access.
|
|
121
|
+
* @see https://www.w3.org/TR/json-ld11/#type-maps
|
|
122
|
+
*/
|
|
123
|
+
export interface IJsonLdTypeMap {
|
|
124
|
+
[key: string]: string | IJsonLdNodeObject;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* An included block is used to provide a set of node objects.
|
|
128
|
+
* @see https://www.w3.org/TR/json-ld11/#included-blocks
|
|
129
|
+
*/
|
|
130
|
+
export type IJsonLdIncludedBlock = IJsonLdNodeObject | IJsonLdNodeObject[];
|
|
131
|
+
/**
|
|
132
|
+
* A context definition defines a local context in a node object.
|
|
133
|
+
* @see https://www.w3.org/TR/json-ld11/#context-definitions
|
|
134
|
+
*/
|
|
135
|
+
export interface IJsonLdContextDefinition {
|
|
136
|
+
[key: string]: null | string | IJsonLdExpandedTermDefinition | IJsonLdContextDefinition[keyof IJsonLdContextDefinition];
|
|
137
|
+
"@base"?: IJsonLdKeyword["@base"] | undefined;
|
|
138
|
+
"@direction"?: IJsonLdKeyword["@direction"] | undefined;
|
|
139
|
+
"@import"?: IJsonLdKeyword["@import"] | undefined;
|
|
140
|
+
"@language"?: IJsonLdKeyword["@language"] | undefined;
|
|
141
|
+
"@propagate"?: IJsonLdKeyword["@propagate"] | undefined;
|
|
142
|
+
"@protected"?: IJsonLdKeyword["@protected"] | undefined;
|
|
143
|
+
"@type"?: {
|
|
144
|
+
"@container": "@set";
|
|
145
|
+
"@protected"?: IJsonLdKeyword["@protected"] | undefined;
|
|
146
|
+
} | undefined;
|
|
147
|
+
"@version"?: IJsonLdKeyword["@version"] | undefined;
|
|
148
|
+
"@vocab"?: IJsonLdKeyword["@vocab"] | undefined;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* A context definition element is used to define the types of a context definition.
|
|
152
|
+
*/
|
|
153
|
+
export type IJsonLdContextDefinitionElement = null | string | IJsonLdContextDefinition;
|
|
154
|
+
/**
|
|
155
|
+
* A context definition root is used to define the root of a context definition.
|
|
156
|
+
*/
|
|
157
|
+
export type IJsonLdContextDefinitionRoot = IJsonLdContextDefinitionElement | IJsonLdContextDefinitionElement[];
|
|
158
|
+
/**
|
|
159
|
+
* An expanded term definition is used to describe the mapping between a term
|
|
160
|
+
* and its expanded identifier, as well as other properties of the value
|
|
161
|
+
* associated with the term when it is used as key in a node object.
|
|
162
|
+
* @see https://www.w3.org/TR/json-ld11/#expanded-term-definition
|
|
163
|
+
*/
|
|
164
|
+
export type IJsonLdExpandedTermDefinition = {
|
|
165
|
+
"@type"?: "@id" | "@json" | "@none" | "@vocab" | string | undefined;
|
|
166
|
+
"@language"?: IJsonLdKeyword["@language"] | undefined;
|
|
167
|
+
"@index"?: IJsonLdKeyword["@index"] | undefined;
|
|
168
|
+
"@context"?: IJsonLdContextDefinition | undefined;
|
|
169
|
+
"@prefix"?: IJsonLdKeyword["@prefix"] | undefined;
|
|
170
|
+
"@propagate"?: IJsonLdKeyword["@propagate"] | undefined;
|
|
171
|
+
"@protected"?: IJsonLdKeyword["@protected"] | undefined;
|
|
172
|
+
} & ({
|
|
173
|
+
"@id"?: IJsonLdKeyword["@id"] | null | undefined;
|
|
174
|
+
"@nest"?: "@nest" | string | undefined;
|
|
175
|
+
"@container"?: IJsonLdKeyword["@container"] | undefined;
|
|
176
|
+
} | {
|
|
177
|
+
"@reverse": IJsonLdKeyword["@reverse"];
|
|
178
|
+
"@container"?: "@set" | "@index" | null | undefined;
|
|
179
|
+
});
|
|
180
|
+
/**
|
|
181
|
+
* A list of keywords and their types.
|
|
182
|
+
* Only used for internal reference; not an actual interface.
|
|
183
|
+
* Not for export.
|
|
184
|
+
* @see https://www.w3.org/TR/json-ld/#keywords
|
|
185
|
+
*/
|
|
186
|
+
export type IJsonLdKeyword = {
|
|
187
|
+
"@base": string | null;
|
|
188
|
+
"@container": ("@list" | "@set" | IJsonLdContainerType) | ("@list" | "@set" | IJsonLdContainerType)[] | IJsonLdContainerTypeArray | null;
|
|
189
|
+
"@context": IJsonLdContextDefinitionRoot;
|
|
190
|
+
"@direction": "ltr" | "rtl" | null;
|
|
191
|
+
"@graph": IJsonLdValueObject | IJsonLdNodeObject | (IJsonLdValueObject | IJsonLdNodeObject)[];
|
|
192
|
+
"@id": string | string[];
|
|
193
|
+
"@import": string;
|
|
194
|
+
"@included": IJsonLdIncludedBlock;
|
|
195
|
+
"@index": string;
|
|
196
|
+
"@json": "@json";
|
|
197
|
+
"@language": string;
|
|
198
|
+
"@list": IJsonLdListOrSetItem | IJsonLdListOrSetItem[];
|
|
199
|
+
"@nest": object;
|
|
200
|
+
"@none": "@none";
|
|
201
|
+
"@prefix": boolean;
|
|
202
|
+
"@propagate": boolean;
|
|
203
|
+
"@protected": boolean;
|
|
204
|
+
"@reverse": string;
|
|
205
|
+
"@set": IJsonLdListOrSetItem | IJsonLdListOrSetItem[];
|
|
206
|
+
"@type": string;
|
|
207
|
+
"@value": null | boolean | number | string;
|
|
208
|
+
"@version": "1.1";
|
|
209
|
+
"@vocab": string | null;
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* A list or set item can be a null, boolean, number, string, node object, or value object.
|
|
213
|
+
*/
|
|
214
|
+
export type IJsonLdListOrSetItem = null | boolean | number | string | IJsonLdNodeObject | IJsonLdValueObject;
|
|
215
|
+
export type IJsonLdContainerType = "@language" | "@index" | "@id" | "@graph" | "@type";
|
|
216
|
+
export type IJsonLdContainerTypeArray = ["@graph", "@id"] | ["@id", "@graph"] | ["@set", "@graph", "@id"] | ["@set", "@id", "@graph"] | ["@graph", "@set", "@id"] | ["@id", "@set", "@graph"] | ["@graph", "@id", "@set"] | ["@id", "@graph", "@set"] | ["@set", IJsonLdContainerType] | [IJsonLdContainerType, "@set"];
|
|
217
|
+
export type IJsonLdJsonPrimitive = string | number | boolean | null;
|
|
218
|
+
export type IJsonLdJsonArray = IJsonLdJsonValue[];
|
|
219
|
+
export interface IJsonLdJsonObject {
|
|
220
|
+
[key: string]: IJsonLdJsonValue | undefined;
|
|
221
|
+
}
|
|
222
|
+
export type IJsonLdJsonValue = IJsonLdJsonPrimitive | IJsonLdJsonArray | IJsonLdJsonObject;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The types of JSON-LD data.
|
|
3
|
+
*/
|
|
4
|
+
export declare const JsonLdTypes: {
|
|
5
|
+
/**
|
|
6
|
+
* Context Root.
|
|
7
|
+
*/
|
|
8
|
+
readonly ContextRoot: "https://schema.twindev.org/json-ld/";
|
|
9
|
+
/**
|
|
10
|
+
* Represents JSON-LD Document.
|
|
11
|
+
*/
|
|
12
|
+
readonly Document: "https://schema.twindev.org/json-ld/JsonLdDocument";
|
|
13
|
+
/**
|
|
14
|
+
* Represents JSON-LD Object.
|
|
15
|
+
*/
|
|
16
|
+
readonly Object: "https://schema.twindev.org/json-ld/JsonLdObject";
|
|
17
|
+
/**
|
|
18
|
+
* Represents JSON-LD Node Object.
|
|
19
|
+
*/
|
|
20
|
+
readonly NodeObject: "https://schema.twindev.org/json-ld/JsonLdNodeObject";
|
|
21
|
+
/**
|
|
22
|
+
* Represents JSON-LD Node Primitive.
|
|
23
|
+
*/
|
|
24
|
+
readonly NodePrimitive: "https://schema.twindev.org/json-ld/JsonLdNodePrimitive";
|
|
25
|
+
/**
|
|
26
|
+
* Represents JSON-LD Graph Object.
|
|
27
|
+
*/
|
|
28
|
+
readonly GraphObject: "https://schema.twindev.org/json-ld/JsonLdGraphObject";
|
|
29
|
+
/**
|
|
30
|
+
* Represents JSON-LD Value Object.
|
|
31
|
+
*/
|
|
32
|
+
readonly ValueObject: "https://schema.twindev.org/json-ld/JsonLdValueObject";
|
|
33
|
+
/**
|
|
34
|
+
* Represents JSON-LD List Object.
|
|
35
|
+
*/
|
|
36
|
+
readonly ListObject: "https://schema.twindev.org/json-ld/JsonLdListObject";
|
|
37
|
+
/**
|
|
38
|
+
* Represents JSON-LD Set Object.
|
|
39
|
+
*/
|
|
40
|
+
readonly SetObject: "https://schema.twindev.org/json-ld/JsonLdSetObject";
|
|
41
|
+
/**
|
|
42
|
+
* Represents JSON-LD Language Map.
|
|
43
|
+
*/
|
|
44
|
+
readonly LanguageMap: "https://schema.twindev.org/json-ld/JsonLdLanguageMap";
|
|
45
|
+
/**
|
|
46
|
+
* Represents JSON-LD Index Map.
|
|
47
|
+
*/
|
|
48
|
+
readonly IndexMap: "https://schema.twindev.org/json-ld/JsonLdIndexMap";
|
|
49
|
+
/**
|
|
50
|
+
* Represents JSON-LD Index Map Item.
|
|
51
|
+
*/
|
|
52
|
+
readonly IndexMapItem: "https://schema.twindev.org/json-ld/JsonLdIndexMapItem";
|
|
53
|
+
/**
|
|
54
|
+
* Represents JSON-LD Id Map.
|
|
55
|
+
*/
|
|
56
|
+
readonly IdMap: "https://schema.twindev.org/json-ld/JsonLdIdMap";
|
|
57
|
+
/**
|
|
58
|
+
* Represents JSON-LD Type Map.
|
|
59
|
+
*/
|
|
60
|
+
readonly TypeMap: "https://schema.twindev.org/json-ld/JsonLdTypeMap";
|
|
61
|
+
/**
|
|
62
|
+
* Represents JSON-LD Included block.
|
|
63
|
+
*/
|
|
64
|
+
readonly IncludedBlock: "https://schema.twindev.org/json-ld/JsonLdIncludedBlock";
|
|
65
|
+
/**
|
|
66
|
+
* Represents JSON-LD Context Definition.
|
|
67
|
+
*/
|
|
68
|
+
readonly ContextDefinition: "https://schema.twindev.org/json-ld/JsonLdContextDefinition";
|
|
69
|
+
/**
|
|
70
|
+
* Represents JSON-LD Expanded Term Definition.
|
|
71
|
+
*/
|
|
72
|
+
readonly ExpandedTermDefinition: "https://schema.twindev.org/json-ld/JsonLdExpandedTermDefinition";
|
|
73
|
+
/**
|
|
74
|
+
* Represents JSON-LD Keyword.
|
|
75
|
+
*/
|
|
76
|
+
readonly Keyword: "https://schema.twindev.org/json-ld/JsonLdKeyword";
|
|
77
|
+
/**
|
|
78
|
+
* Represents JSON-LD List or Set Item.
|
|
79
|
+
*/
|
|
80
|
+
readonly ListOrSetItem: "https://schema.twindev.org/json-ld/JsonLdListOrSetItem";
|
|
81
|
+
/**
|
|
82
|
+
* Represents JSON-LD Container Type.
|
|
83
|
+
*/
|
|
84
|
+
readonly ContainerType: "https://schema.twindev.org/json-ld/JsonLdContainerType";
|
|
85
|
+
/**
|
|
86
|
+
* Represents JSON-LD Container Type Array.
|
|
87
|
+
*/
|
|
88
|
+
readonly ContainerTypeArray: "https://schema.twindev.org/json-ld/JsonLdContainerTypeArray";
|
|
89
|
+
/**
|
|
90
|
+
* Represents JSON-LD JSON Primitive.
|
|
91
|
+
*/
|
|
92
|
+
readonly JsonPrimitive: "https://schema.twindev.org/json-ld/JsonLdJsonPrimitive";
|
|
93
|
+
/**
|
|
94
|
+
* Represents JSON-LD JSON Array.
|
|
95
|
+
*/
|
|
96
|
+
readonly JsonArray: "https://schema.twindev.org/json-ld/JsonLdJsonArray";
|
|
97
|
+
/**
|
|
98
|
+
* Represents JSON-LD JSON Object.
|
|
99
|
+
*/
|
|
100
|
+
readonly JsonObject: "https://schema.twindev.org/json-ld/JsonLdJsonObject";
|
|
101
|
+
/**
|
|
102
|
+
* Represents JSON-LD JSON Value.
|
|
103
|
+
*/
|
|
104
|
+
readonly JsonValue: "https://schema.twindev.org/json-ld/JsonLdJsonValue";
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* The types of JSON-LD data.
|
|
108
|
+
*/
|
|
109
|
+
export type JsonLdTypes = (typeof JsonLdTypes)[keyof typeof JsonLdTypes];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type IValidationFailure } from "@twin.org/core";
|
|
2
|
+
import { type ValidationMode } from "@twin.org/data-core";
|
|
3
|
+
import type { IJsonLdDocument } from "../models/IJsonLdDocument";
|
|
4
|
+
/**
|
|
5
|
+
* Class to help with JSON LD.
|
|
6
|
+
*/
|
|
7
|
+
export declare class JsonLdHelper {
|
|
8
|
+
/**
|
|
9
|
+
* Validate a JSON-LD document.
|
|
10
|
+
* @param document The JSON-LD document to validate.
|
|
11
|
+
* @param validationFailures The list of validation failures to add to.
|
|
12
|
+
* @param validationMode The validation mode to use, defaults to either.
|
|
13
|
+
* @returns True if the document was valid.
|
|
14
|
+
*/
|
|
15
|
+
static validate<T extends IJsonLdDocument = IJsonLdDocument>(document: T, validationFailures: IValidationFailure[], validationMode?: ValidationMode): Promise<boolean>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { RemoteDocument, Url } from "jsonld/jsonld-spec";
|
|
2
|
+
import type { IJsonLdContextDefinitionElement, IJsonLdContextDefinitionRoot, IJsonLdDocument, IJsonLdNodeObject } from "../models/IJsonLdDocument";
|
|
3
|
+
/**
|
|
4
|
+
* JSON-LD Processor.
|
|
5
|
+
*/
|
|
6
|
+
export declare class JsonLdProcessor {
|
|
7
|
+
/**
|
|
8
|
+
* Redirects to use during document resolution.
|
|
9
|
+
*/
|
|
10
|
+
private static readonly _redirects;
|
|
11
|
+
/**
|
|
12
|
+
* The document loader to use.
|
|
13
|
+
*/
|
|
14
|
+
static DOCUMENT_LOADER: (url: Url) => Promise<RemoteDocument>;
|
|
15
|
+
/**
|
|
16
|
+
* Compact a document according to a particular context.
|
|
17
|
+
* @param document The JSON-LD document to compact.
|
|
18
|
+
* @param context The context to compact the document to, if not provided will try and gather from the object.
|
|
19
|
+
* @returns The compacted JSON-LD document.
|
|
20
|
+
*/
|
|
21
|
+
static compact(document: IJsonLdDocument, context?: IJsonLdContextDefinitionRoot): Promise<IJsonLdDocument>;
|
|
22
|
+
/**
|
|
23
|
+
* Expand a document, removing its context.
|
|
24
|
+
* @param compacted The compacted JSON-LD document to expand.
|
|
25
|
+
* @returns The expanded JSON-LD document.
|
|
26
|
+
*/
|
|
27
|
+
static expand(compacted: IJsonLdDocument): Promise<IJsonLdDocument>;
|
|
28
|
+
/**
|
|
29
|
+
* Add a redirect to use during document resolution.
|
|
30
|
+
* @param from The URL to redirect from.
|
|
31
|
+
* @param to The URL to redirect to.
|
|
32
|
+
*/
|
|
33
|
+
static addRedirect(from: RegExp, to: string): void;
|
|
34
|
+
/**
|
|
35
|
+
* Extract a property from the JSON-LD.
|
|
36
|
+
* @param nodeObject The JSON-LD node object to extract from.
|
|
37
|
+
* @param propertyNames The possible names for the property.
|
|
38
|
+
* @param deleteProperty Delete the property from the object, defaults to true.
|
|
39
|
+
* @returns The properties if available.
|
|
40
|
+
*/
|
|
41
|
+
static extractProperty<T>(nodeObject: IJsonLdNodeObject, propertyNames: string[], deleteProperty?: boolean): T | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Combine contexts.
|
|
44
|
+
* @param context1 The first JSON-LD context to combine.
|
|
45
|
+
* @param context2 The second JSON-LD context to combine.
|
|
46
|
+
* @returns The combined context.
|
|
47
|
+
*/
|
|
48
|
+
static combineContexts(context1: IJsonLdContextDefinitionRoot | undefined, context2: IJsonLdContextDefinitionRoot | undefined): IJsonLdContextDefinitionRoot | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Gather all the contexts from the element and it's children.
|
|
51
|
+
* @param element The element to gather the contexts from.
|
|
52
|
+
* @param initial The initial context.
|
|
53
|
+
* @returns The combined contexts.
|
|
54
|
+
*/
|
|
55
|
+
static gatherContexts(element: {
|
|
56
|
+
[id: string]: unknown;
|
|
57
|
+
}, initial?: IJsonLdContextDefinitionRoot): IJsonLdContextDefinitionRoot | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Remove all the contexts that match the pattern.
|
|
60
|
+
* @param context The context to remove the entries from.
|
|
61
|
+
* @param match The element to try and match.
|
|
62
|
+
* @returns The updated contexts.
|
|
63
|
+
*/
|
|
64
|
+
static removeContexts(context: IJsonLdContextDefinitionRoot | undefined, match?: IJsonLdContextDefinitionElement[]): IJsonLdContextDefinitionRoot | undefined;
|
|
65
|
+
}
|
package/docs/examples.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @twin.org/data-json-ld - Examples
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Class: JsonLdDataTypes
|
|
2
|
+
|
|
3
|
+
Handle all the data types for JSON-LD.
|
|
4
|
+
|
|
5
|
+
## Constructors
|
|
6
|
+
|
|
7
|
+
### new JsonLdDataTypes()
|
|
8
|
+
|
|
9
|
+
> **new JsonLdDataTypes**(): [`JsonLdDataTypes`](JsonLdDataTypes.md)
|
|
10
|
+
|
|
11
|
+
#### Returns
|
|
12
|
+
|
|
13
|
+
[`JsonLdDataTypes`](JsonLdDataTypes.md)
|
|
14
|
+
|
|
15
|
+
## Methods
|
|
16
|
+
|
|
17
|
+
### registerTypes()
|
|
18
|
+
|
|
19
|
+
> `static` **registerTypes**(): `void`
|
|
20
|
+
|
|
21
|
+
Register all the data types.
|
|
22
|
+
|
|
23
|
+
#### Returns
|
|
24
|
+
|
|
25
|
+
`void`
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Class: JsonLdHelper
|
|
2
|
+
|
|
3
|
+
Class to help with JSON LD.
|
|
4
|
+
|
|
5
|
+
## Constructors
|
|
6
|
+
|
|
7
|
+
### new JsonLdHelper()
|
|
8
|
+
|
|
9
|
+
> **new JsonLdHelper**(): [`JsonLdHelper`](JsonLdHelper.md)
|
|
10
|
+
|
|
11
|
+
#### Returns
|
|
12
|
+
|
|
13
|
+
[`JsonLdHelper`](JsonLdHelper.md)
|
|
14
|
+
|
|
15
|
+
## Methods
|
|
16
|
+
|
|
17
|
+
### validate()
|
|
18
|
+
|
|
19
|
+
> `static` **validate**\<`T`\>(`document`, `validationFailures`, `validationMode`?): `Promise`\<`boolean`\>
|
|
20
|
+
|
|
21
|
+
Validate a JSON-LD document.
|
|
22
|
+
|
|
23
|
+
#### Type Parameters
|
|
24
|
+
|
|
25
|
+
• **T** *extends* [`IJsonLdDocument`](../type-aliases/IJsonLdDocument.md) = [`IJsonLdDocument`](../type-aliases/IJsonLdDocument.md)
|
|
26
|
+
|
|
27
|
+
#### Parameters
|
|
28
|
+
|
|
29
|
+
• **document**: `T`
|
|
30
|
+
|
|
31
|
+
The JSON-LD document to validate.
|
|
32
|
+
|
|
33
|
+
• **validationFailures**: `IValidationFailure`[]
|
|
34
|
+
|
|
35
|
+
The list of validation failures to add to.
|
|
36
|
+
|
|
37
|
+
• **validationMode?**: `ValidationMode`
|
|
38
|
+
|
|
39
|
+
The validation mode to use, defaults to either.
|
|
40
|
+
|
|
41
|
+
#### Returns
|
|
42
|
+
|
|
43
|
+
`Promise`\<`boolean`\>
|
|
44
|
+
|
|
45
|
+
True if the document was valid.
|