@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.
- package/LICENSE +201 -0
- package/README.md +21 -0
- package/dist/cjs/index.cjs +1602 -0
- package/dist/esm/index.mjs +1597 -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 +207 -0
- package/dist/types/models/jsonLdTypes.d.ts +101 -0
- package/dist/types/utils/jsonLdHelper.d.ts +16 -0
- package/dist/types/utils/jsonLdProcessor.d.ts +34 -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 +95 -0
- package/docs/reference/index.md +41 -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 +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/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 +145 -0
- package/locales/en.json +6 -0
- package/package.json +74 -0
|
@@ -0,0 +1,207 @@
|
|
|
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 {
|
|
25
|
+
[key: string]: IJsonLdNodePrimitive | IJsonLdNodePrimitive[] | IJsonLdLanguageMap | IJsonLdIndexMap | IJsonLdIncludedBlock | IJsonLdIdMap | IJsonLdTypeMap | IJsonLdNodeObject[keyof IJsonLdNodeObject];
|
|
26
|
+
"@context"?: IJsonLdKeyword["@context"] | undefined;
|
|
27
|
+
"@id"?: IJsonLdKeyword["@id"] | undefined;
|
|
28
|
+
"@included"?: IJsonLdKeyword["@included"] | undefined;
|
|
29
|
+
"@graph"?: IJsonLdNodeObject | IJsonLdNodeObject[] | undefined;
|
|
30
|
+
"@nest"?: IJsonLdJsonObject | IJsonLdJsonObject[] | undefined;
|
|
31
|
+
"@type"?: IJsonLdKeyword["@type"] | IJsonLdKeyword["@type"][] | undefined;
|
|
32
|
+
"@reverse"?: {
|
|
33
|
+
[key: string]: IJsonLdKeyword["@reverse"];
|
|
34
|
+
} | undefined;
|
|
35
|
+
"@index"?: IJsonLdKeyword["@index"] | undefined;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A node primitive is a JSON-LD value which is not one of the defined NodeObject properties.
|
|
39
|
+
*/
|
|
40
|
+
export type IJsonLdNodePrimitive = null | boolean | number | string | IJsonLdNodeObject | IJsonLdGraphObject | IJsonLdValueObject | IJsonLdListObject | IJsonLdSetObject;
|
|
41
|
+
/**
|
|
42
|
+
* A graph object represents a named graph, which MAY include an explicit graph name.
|
|
43
|
+
* @see https://www.w3.org/TR/json-ld11/#graph-objects
|
|
44
|
+
*/
|
|
45
|
+
export interface IJsonLdGraphObject {
|
|
46
|
+
"@graph": IJsonLdNodeObject | IJsonLdNodeObject[];
|
|
47
|
+
"@index"?: IJsonLdKeyword["@index"] | undefined;
|
|
48
|
+
"@id"?: IJsonLdKeyword["@id"] | undefined;
|
|
49
|
+
"@context"?: IJsonLdKeyword["@context"] | undefined;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* A value object is used to explicitly associate a type or a language with a value
|
|
53
|
+
* to create a typed value or a language-tagged string and possibly associate a base direction.
|
|
54
|
+
* @see https://www.w3.org/TR/json-ld11/#value-objects
|
|
55
|
+
*/
|
|
56
|
+
export type IJsonLdValueObject = {
|
|
57
|
+
"@index"?: IJsonLdKeyword["@index"] | undefined;
|
|
58
|
+
"@context"?: IJsonLdKeyword["@context"] | undefined;
|
|
59
|
+
} & ({
|
|
60
|
+
"@value": IJsonLdKeyword["@value"];
|
|
61
|
+
"@language"?: IJsonLdKeyword["@language"] | undefined;
|
|
62
|
+
"@direction"?: IJsonLdKeyword["@direction"] | undefined;
|
|
63
|
+
} | {
|
|
64
|
+
"@value": IJsonLdKeyword["@value"];
|
|
65
|
+
"@type": IJsonLdKeyword["@type"];
|
|
66
|
+
} | {
|
|
67
|
+
"@value": IJsonLdKeyword["@value"] | IJsonLdJsonObject | IJsonLdJsonArray;
|
|
68
|
+
"@type": "@json";
|
|
69
|
+
});
|
|
70
|
+
/**
|
|
71
|
+
* A list represents an ordered set of values.
|
|
72
|
+
* @see https://www.w3.org/TR/json-ld11/#lists-and-sets
|
|
73
|
+
*/
|
|
74
|
+
export interface IJsonLdListObject {
|
|
75
|
+
"@list": IJsonLdKeyword["@list"];
|
|
76
|
+
"@index"?: IJsonLdKeyword["@index"] | undefined;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* A set represents an unordered set of values.
|
|
80
|
+
* @see https://www.w3.org/TR/json-ld11/#lists-and-sets
|
|
81
|
+
*/
|
|
82
|
+
export interface IJsonLdSetObject {
|
|
83
|
+
"@set": IJsonLdKeyword["@set"];
|
|
84
|
+
"@index"?: IJsonLdKeyword["@index"] | undefined;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* A language map is used to associate a language with a value in a way that allows easy programmatic access.
|
|
88
|
+
* @see https://www.w3.org/TR/json-ld11/#language-maps
|
|
89
|
+
*/
|
|
90
|
+
export interface IJsonLdLanguageMap {
|
|
91
|
+
[key: string]: null | string | string[];
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* An index map allows keys that have no semantic meaning, but should be preserved regardless,
|
|
95
|
+
* to be used in JSON-LD documents.
|
|
96
|
+
* @see https://www.w3.org/TR/json-ld11/#index-maps
|
|
97
|
+
*/
|
|
98
|
+
export interface IJsonLdIndexMap {
|
|
99
|
+
[key: string]: IJsonLdIndexMapItem | IJsonLdIndexMapItem[];
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The items that can be stored in an index map.
|
|
103
|
+
*/
|
|
104
|
+
export type IJsonLdIndexMapItem = null | boolean | number | string | IJsonLdNodeObject | IJsonLdValueObject | IJsonLdListObject | IJsonLdSetObject;
|
|
105
|
+
/**
|
|
106
|
+
* An id map is used to associate an IRI with a value that allows easy programmatic access.
|
|
107
|
+
* @see https://www.w3.org/TR/json-ld11/#id-maps
|
|
108
|
+
*/
|
|
109
|
+
export interface IJsonLdIdMap {
|
|
110
|
+
[key: string]: IJsonLdNodeObject;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* A type map is used to associate an IRI with a value that allows easy programmatic access.
|
|
114
|
+
* @see https://www.w3.org/TR/json-ld11/#type-maps
|
|
115
|
+
*/
|
|
116
|
+
export interface IJsonLdTypeMap {
|
|
117
|
+
[key: string]: string | IJsonLdNodeObject;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* An included block is used to provide a set of node objects.
|
|
121
|
+
* @see https://www.w3.org/TR/json-ld11/#included-blocks
|
|
122
|
+
*/
|
|
123
|
+
export type IJsonLdIncludedBlock = IJsonLdNodeObject | IJsonLdNodeObject[];
|
|
124
|
+
/**
|
|
125
|
+
* A context definition defines a local context in a node object.
|
|
126
|
+
* @see https://www.w3.org/TR/json-ld11/#context-definitions
|
|
127
|
+
*/
|
|
128
|
+
export interface IJsonLdContextDefinition {
|
|
129
|
+
[key: string]: null | string | IJsonLdExpandedTermDefinition | IJsonLdContextDefinition[keyof IJsonLdContextDefinition];
|
|
130
|
+
"@base"?: IJsonLdKeyword["@base"] | undefined;
|
|
131
|
+
"@direction"?: IJsonLdKeyword["@direction"] | undefined;
|
|
132
|
+
"@import"?: IJsonLdKeyword["@import"] | undefined;
|
|
133
|
+
"@language"?: IJsonLdKeyword["@language"] | undefined;
|
|
134
|
+
"@propagate"?: IJsonLdKeyword["@propagate"] | undefined;
|
|
135
|
+
"@protected"?: IJsonLdKeyword["@protected"] | undefined;
|
|
136
|
+
"@type"?: {
|
|
137
|
+
"@container": "@set";
|
|
138
|
+
"@protected"?: IJsonLdKeyword["@protected"] | undefined;
|
|
139
|
+
} | undefined;
|
|
140
|
+
"@version"?: IJsonLdKeyword["@version"] | undefined;
|
|
141
|
+
"@vocab"?: IJsonLdKeyword["@vocab"] | undefined;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* An expanded term definition is used to describe the mapping between a term
|
|
145
|
+
* and its expanded identifier, as well as other properties of the value
|
|
146
|
+
* associated with the term when it is used as key in a node object.
|
|
147
|
+
* @see https://www.w3.org/TR/json-ld11/#expanded-term-definition
|
|
148
|
+
*/
|
|
149
|
+
export type IJsonLdExpandedTermDefinition = {
|
|
150
|
+
"@type"?: "@id" | "@json" | "@none" | "@vocab" | string | undefined;
|
|
151
|
+
"@language"?: IJsonLdKeyword["@language"] | undefined;
|
|
152
|
+
"@index"?: IJsonLdKeyword["@index"] | undefined;
|
|
153
|
+
"@context"?: IJsonLdContextDefinition | undefined;
|
|
154
|
+
"@prefix"?: IJsonLdKeyword["@prefix"] | undefined;
|
|
155
|
+
"@propagate"?: IJsonLdKeyword["@propagate"] | undefined;
|
|
156
|
+
"@protected"?: IJsonLdKeyword["@protected"] | undefined;
|
|
157
|
+
} & ({
|
|
158
|
+
"@id"?: IJsonLdKeyword["@id"] | null | undefined;
|
|
159
|
+
"@nest"?: "@nest" | string | undefined;
|
|
160
|
+
"@container"?: IJsonLdKeyword["@container"] | undefined;
|
|
161
|
+
} | {
|
|
162
|
+
"@reverse": IJsonLdKeyword["@reverse"];
|
|
163
|
+
"@container"?: "@set" | "@index" | null | undefined;
|
|
164
|
+
});
|
|
165
|
+
/**
|
|
166
|
+
* A list of keywords and their types.
|
|
167
|
+
* Only used for internal reference; not an actual interface.
|
|
168
|
+
* Not for export.
|
|
169
|
+
* @see https://www.w3.org/TR/json-ld/#keywords
|
|
170
|
+
*/
|
|
171
|
+
export type IJsonLdKeyword = {
|
|
172
|
+
"@base": string | null;
|
|
173
|
+
"@container": ("@list" | "@set" | IJsonLdContainerType) | ("@list" | "@set" | IJsonLdContainerType)[] | IJsonLdContainerTypeArray | null;
|
|
174
|
+
"@context": null | string | IJsonLdContextDefinition | (null | string | IJsonLdContextDefinition)[];
|
|
175
|
+
"@direction": "ltr" | "rtl" | null;
|
|
176
|
+
"@graph": IJsonLdValueObject | IJsonLdNodeObject | (IJsonLdValueObject | IJsonLdNodeObject)[];
|
|
177
|
+
"@id": string | string[];
|
|
178
|
+
"@import": string;
|
|
179
|
+
"@included": IJsonLdIncludedBlock;
|
|
180
|
+
"@index": string;
|
|
181
|
+
"@json": "@json";
|
|
182
|
+
"@language": string;
|
|
183
|
+
"@list": IJsonLdListOrSetItem | IJsonLdListOrSetItem[];
|
|
184
|
+
"@nest": object;
|
|
185
|
+
"@none": "@none";
|
|
186
|
+
"@prefix": boolean;
|
|
187
|
+
"@propagate": boolean;
|
|
188
|
+
"@protected": boolean;
|
|
189
|
+
"@reverse": string;
|
|
190
|
+
"@set": IJsonLdListOrSetItem | IJsonLdListOrSetItem[];
|
|
191
|
+
"@type": string;
|
|
192
|
+
"@value": null | boolean | number | string;
|
|
193
|
+
"@version": "1.1";
|
|
194
|
+
"@vocab": string | null;
|
|
195
|
+
};
|
|
196
|
+
/**
|
|
197
|
+
* A list or set item can be a null, boolean, number, string, node object, or value object.
|
|
198
|
+
*/
|
|
199
|
+
export type IJsonLdListOrSetItem = null | boolean | number | string | IJsonLdNodeObject | IJsonLdValueObject;
|
|
200
|
+
export type IJsonLdContainerType = "@language" | "@index" | "@id" | "@graph" | "@type";
|
|
201
|
+
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"];
|
|
202
|
+
export type IJsonLdJsonPrimitive = string | number | boolean | null;
|
|
203
|
+
export type IJsonLdJsonArray = IJsonLdJsonValue[];
|
|
204
|
+
export interface IJsonLdJsonObject {
|
|
205
|
+
[key: string]: IJsonLdJsonValue | undefined;
|
|
206
|
+
}
|
|
207
|
+
export type IJsonLdJsonValue = IJsonLdJsonPrimitive | IJsonLdJsonArray | IJsonLdJsonObject;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The types of JSON-LD data.
|
|
3
|
+
*/
|
|
4
|
+
export declare const JsonLdTypes: {
|
|
5
|
+
/**
|
|
6
|
+
* Represents JSON-LD Document.
|
|
7
|
+
*/
|
|
8
|
+
readonly Document: "https://schema.twindev.org/json-ld/JsonLdDocument";
|
|
9
|
+
/**
|
|
10
|
+
* Represents JSON-LD Node Object.
|
|
11
|
+
*/
|
|
12
|
+
readonly NodeObject: "https://schema.twindev.org/json-ld/JsonLdNodeObject";
|
|
13
|
+
/**
|
|
14
|
+
* Represents JSON-LD Node Primitive.
|
|
15
|
+
*/
|
|
16
|
+
readonly NodePrimitive: "https://schema.twindev.org/json-ld/JsonLdNodePrimitive";
|
|
17
|
+
/**
|
|
18
|
+
* Represents JSON-LD Graph Object.
|
|
19
|
+
*/
|
|
20
|
+
readonly GraphObject: "https://schema.twindev.org/json-ld/JsonLdGraphObject";
|
|
21
|
+
/**
|
|
22
|
+
* Represents JSON-LD Value Object.
|
|
23
|
+
*/
|
|
24
|
+
readonly ValueObject: "https://schema.twindev.org/json-ld/JsonLdValueObject";
|
|
25
|
+
/**
|
|
26
|
+
* Represents JSON-LD List Object.
|
|
27
|
+
*/
|
|
28
|
+
readonly ListObject: "https://schema.twindev.org/json-ld/JsonLdListObject";
|
|
29
|
+
/**
|
|
30
|
+
* Represents JSON-LD Set Object.
|
|
31
|
+
*/
|
|
32
|
+
readonly SetObject: "https://schema.twindev.org/json-ld/JsonLdSetObject";
|
|
33
|
+
/**
|
|
34
|
+
* Represents JSON-LD Language Map.
|
|
35
|
+
*/
|
|
36
|
+
readonly LanguageMap: "https://schema.twindev.org/json-ld/JsonLdLanguageMap";
|
|
37
|
+
/**
|
|
38
|
+
* Represents JSON-LD Index Map.
|
|
39
|
+
*/
|
|
40
|
+
readonly IndexMap: "https://schema.twindev.org/json-ld/JsonLdIndexMap";
|
|
41
|
+
/**
|
|
42
|
+
* Represents JSON-LD Index Map Item.
|
|
43
|
+
*/
|
|
44
|
+
readonly IndexMapItem: "https://schema.twindev.org/json-ld/JsonLdIndexMapItem";
|
|
45
|
+
/**
|
|
46
|
+
* Represents JSON-LD Id Map.
|
|
47
|
+
*/
|
|
48
|
+
readonly IdMap: "https://schema.twindev.org/json-ld/JsonLdIdMap";
|
|
49
|
+
/**
|
|
50
|
+
* Represents JSON-LD Type Map.
|
|
51
|
+
*/
|
|
52
|
+
readonly TypeMap: "https://schema.twindev.org/json-ld/JsonLdTypeMap";
|
|
53
|
+
/**
|
|
54
|
+
* Represents JSON-LD Included block.
|
|
55
|
+
*/
|
|
56
|
+
readonly IncludedBlock: "https://schema.twindev.org/json-ld/JsonLdIncludedBlock";
|
|
57
|
+
/**
|
|
58
|
+
* Represents JSON-LD Context Definition.
|
|
59
|
+
*/
|
|
60
|
+
readonly ContextDefinition: "https://schema.twindev.org/json-ld/JsonLdContextDefinition";
|
|
61
|
+
/**
|
|
62
|
+
* Represents JSON-LD Expanded Term Definition.
|
|
63
|
+
*/
|
|
64
|
+
readonly ExpandedTermDefinition: "https://schema.twindev.org/json-ld/JsonLdExpandedTermDefinition";
|
|
65
|
+
/**
|
|
66
|
+
* Represents JSON-LD Keyword.
|
|
67
|
+
*/
|
|
68
|
+
readonly Keyword: "https://schema.twindev.org/json-ld/JsonLdKeyword";
|
|
69
|
+
/**
|
|
70
|
+
* Represents JSON-LD List or Set Item.
|
|
71
|
+
*/
|
|
72
|
+
readonly ListOrSetItem: "https://schema.twindev.org/json-ld/JsonLdListOrSetItem";
|
|
73
|
+
/**
|
|
74
|
+
* Represents JSON-LD Container Type.
|
|
75
|
+
*/
|
|
76
|
+
readonly ContainerType: "https://schema.twindev.org/json-ld/JsonLdContainerType";
|
|
77
|
+
/**
|
|
78
|
+
* Represents JSON-LD Container Type Array.
|
|
79
|
+
*/
|
|
80
|
+
readonly ContainerTypeArray: "https://schema.twindev.org/json-ld/JsonLdContainerTypeArray";
|
|
81
|
+
/**
|
|
82
|
+
* Represents JSON-LD JSON Primitive.
|
|
83
|
+
*/
|
|
84
|
+
readonly JsonPrimitive: "https://schema.twindev.org/json-ld/JsonLdJsonPrimitive";
|
|
85
|
+
/**
|
|
86
|
+
* Represents JSON-LD JSON Array.
|
|
87
|
+
*/
|
|
88
|
+
readonly JsonArray: "https://schema.twindev.org/json-ld/JsonLdJsonArray";
|
|
89
|
+
/**
|
|
90
|
+
* Represents JSON-LD JSON Object.
|
|
91
|
+
*/
|
|
92
|
+
readonly JsonObject: "https://schema.twindev.org/json-ld/JsonLdJsonObject";
|
|
93
|
+
/**
|
|
94
|
+
* Represents JSON-LD JSON Value.
|
|
95
|
+
*/
|
|
96
|
+
readonly JsonValue: "https://schema.twindev.org/json-ld/JsonLdJsonValue";
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* The types of JSON-LD data.
|
|
100
|
+
*/
|
|
101
|
+
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,34 @@
|
|
|
1
|
+
import type { RemoteDocument, Url } from "jsonld/jsonld-spec";
|
|
2
|
+
import type { IJsonLdContextDefinition, IJsonLdDocument } 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.
|
|
19
|
+
* @returns The compacted JSON-LD document.
|
|
20
|
+
*/
|
|
21
|
+
static compact(document: IJsonLdDocument, context?: IJsonLdContextDefinition): 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
|
+
}
|
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.
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Class: JsonLdProcessor
|
|
2
|
+
|
|
3
|
+
JSON-LD Processor.
|
|
4
|
+
|
|
5
|
+
## Constructors
|
|
6
|
+
|
|
7
|
+
### new JsonLdProcessor()
|
|
8
|
+
|
|
9
|
+
> **new JsonLdProcessor**(): [`JsonLdProcessor`](JsonLdProcessor.md)
|
|
10
|
+
|
|
11
|
+
#### Returns
|
|
12
|
+
|
|
13
|
+
[`JsonLdProcessor`](JsonLdProcessor.md)
|
|
14
|
+
|
|
15
|
+
## Methods
|
|
16
|
+
|
|
17
|
+
### DOCUMENT\_LOADER()
|
|
18
|
+
|
|
19
|
+
> `static` **DOCUMENT\_LOADER**(`url`): `Promise`\<`RemoteDocument`\>
|
|
20
|
+
|
|
21
|
+
The document loader to use.
|
|
22
|
+
|
|
23
|
+
#### Parameters
|
|
24
|
+
|
|
25
|
+
• **url**: `string`
|
|
26
|
+
|
|
27
|
+
#### Returns
|
|
28
|
+
|
|
29
|
+
`Promise`\<`RemoteDocument`\>
|
|
30
|
+
|
|
31
|
+
***
|
|
32
|
+
|
|
33
|
+
### compact()
|
|
34
|
+
|
|
35
|
+
> `static` **compact**(`document`, `context`?): `Promise`\<[`IJsonLdDocument`](../type-aliases/IJsonLdDocument.md)\>
|
|
36
|
+
|
|
37
|
+
Compact a document according to a particular context.
|
|
38
|
+
|
|
39
|
+
#### Parameters
|
|
40
|
+
|
|
41
|
+
• **document**: [`IJsonLdDocument`](../type-aliases/IJsonLdDocument.md)
|
|
42
|
+
|
|
43
|
+
The JSON-LD document to compact.
|
|
44
|
+
|
|
45
|
+
• **context?**: [`IJsonLdContextDefinition`](../interfaces/IJsonLdContextDefinition.md)
|
|
46
|
+
|
|
47
|
+
The context to compact the document to.
|
|
48
|
+
|
|
49
|
+
#### Returns
|
|
50
|
+
|
|
51
|
+
`Promise`\<[`IJsonLdDocument`](../type-aliases/IJsonLdDocument.md)\>
|
|
52
|
+
|
|
53
|
+
The compacted JSON-LD document.
|
|
54
|
+
|
|
55
|
+
***
|
|
56
|
+
|
|
57
|
+
### expand()
|
|
58
|
+
|
|
59
|
+
> `static` **expand**(`compacted`): `Promise`\<[`IJsonLdDocument`](../type-aliases/IJsonLdDocument.md)\>
|
|
60
|
+
|
|
61
|
+
Expand a document, removing its context.
|
|
62
|
+
|
|
63
|
+
#### Parameters
|
|
64
|
+
|
|
65
|
+
• **compacted**: [`IJsonLdDocument`](../type-aliases/IJsonLdDocument.md)
|
|
66
|
+
|
|
67
|
+
The compacted JSON-LD document to expand.
|
|
68
|
+
|
|
69
|
+
#### Returns
|
|
70
|
+
|
|
71
|
+
`Promise`\<[`IJsonLdDocument`](../type-aliases/IJsonLdDocument.md)\>
|
|
72
|
+
|
|
73
|
+
The expanded JSON-LD document.
|
|
74
|
+
|
|
75
|
+
***
|
|
76
|
+
|
|
77
|
+
### addRedirect()
|
|
78
|
+
|
|
79
|
+
> `static` **addRedirect**(`from`, `to`): `void`
|
|
80
|
+
|
|
81
|
+
Add a redirect to use during document resolution.
|
|
82
|
+
|
|
83
|
+
#### Parameters
|
|
84
|
+
|
|
85
|
+
• **from**: `RegExp`
|
|
86
|
+
|
|
87
|
+
The URL to redirect from.
|
|
88
|
+
|
|
89
|
+
• **to**: `string`
|
|
90
|
+
|
|
91
|
+
The URL to redirect to.
|
|
92
|
+
|
|
93
|
+
#### Returns
|
|
94
|
+
|
|
95
|
+
`void`
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# @twin.org/data-json-ld
|
|
2
|
+
|
|
3
|
+
## Classes
|
|
4
|
+
|
|
5
|
+
- [JsonLdDataTypes](classes/JsonLdDataTypes.md)
|
|
6
|
+
- [JsonLdHelper](classes/JsonLdHelper.md)
|
|
7
|
+
- [JsonLdProcessor](classes/JsonLdProcessor.md)
|
|
8
|
+
|
|
9
|
+
## Interfaces
|
|
10
|
+
|
|
11
|
+
- [IJsonLdNodeObject](interfaces/IJsonLdNodeObject.md)
|
|
12
|
+
- [IJsonLdGraphObject](interfaces/IJsonLdGraphObject.md)
|
|
13
|
+
- [IJsonLdListObject](interfaces/IJsonLdListObject.md)
|
|
14
|
+
- [IJsonLdSetObject](interfaces/IJsonLdSetObject.md)
|
|
15
|
+
- [IJsonLdLanguageMap](interfaces/IJsonLdLanguageMap.md)
|
|
16
|
+
- [IJsonLdIndexMap](interfaces/IJsonLdIndexMap.md)
|
|
17
|
+
- [IJsonLdIdMap](interfaces/IJsonLdIdMap.md)
|
|
18
|
+
- [IJsonLdTypeMap](interfaces/IJsonLdTypeMap.md)
|
|
19
|
+
- [IJsonLdContextDefinition](interfaces/IJsonLdContextDefinition.md)
|
|
20
|
+
- [IJsonLdJsonObject](interfaces/IJsonLdJsonObject.md)
|
|
21
|
+
|
|
22
|
+
## Type Aliases
|
|
23
|
+
|
|
24
|
+
- [IJsonLdDocument](type-aliases/IJsonLdDocument.md)
|
|
25
|
+
- [IJsonLdNodePrimitive](type-aliases/IJsonLdNodePrimitive.md)
|
|
26
|
+
- [IJsonLdValueObject](type-aliases/IJsonLdValueObject.md)
|
|
27
|
+
- [IJsonLdIndexMapItem](type-aliases/IJsonLdIndexMapItem.md)
|
|
28
|
+
- [IJsonLdIncludedBlock](type-aliases/IJsonLdIncludedBlock.md)
|
|
29
|
+
- [IJsonLdExpandedTermDefinition](type-aliases/IJsonLdExpandedTermDefinition.md)
|
|
30
|
+
- [IJsonLdKeyword](type-aliases/IJsonLdKeyword.md)
|
|
31
|
+
- [IJsonLdListOrSetItem](type-aliases/IJsonLdListOrSetItem.md)
|
|
32
|
+
- [IJsonLdContainerType](type-aliases/IJsonLdContainerType.md)
|
|
33
|
+
- [IJsonLdContainerTypeArray](type-aliases/IJsonLdContainerTypeArray.md)
|
|
34
|
+
- [IJsonLdJsonPrimitive](type-aliases/IJsonLdJsonPrimitive.md)
|
|
35
|
+
- [IJsonLdJsonArray](type-aliases/IJsonLdJsonArray.md)
|
|
36
|
+
- [IJsonLdJsonValue](type-aliases/IJsonLdJsonValue.md)
|
|
37
|
+
- [JsonLdTypes](type-aliases/JsonLdTypes.md)
|
|
38
|
+
|
|
39
|
+
## Variables
|
|
40
|
+
|
|
41
|
+
- [JsonLdTypes](variables/JsonLdTypes.md)
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Interface: IJsonLdContextDefinition
|
|
2
|
+
|
|
3
|
+
A context definition defines a local context in a node object.
|
|
4
|
+
|
|
5
|
+
## See
|
|
6
|
+
|
|
7
|
+
https://www.w3.org/TR/json-ld11/#context-definitions
|
|
8
|
+
|
|
9
|
+
## Indexable
|
|
10
|
+
|
|
11
|
+
\[`key`: `string`\]: `null` \| `string` \| [`IJsonLdExpandedTermDefinition`](../type-aliases/IJsonLdExpandedTermDefinition.md) \| [`IJsonLdContextDefinition`](IJsonLdContextDefinition.md)\[keyof [`IJsonLdContextDefinition`](IJsonLdContextDefinition.md)\]
|
|
12
|
+
|
|
13
|
+
## Properties
|
|
14
|
+
|
|
15
|
+
### @base?
|
|
16
|
+
|
|
17
|
+
> `optional` **@base**: `null` \| `string`
|
|
18
|
+
|
|
19
|
+
***
|
|
20
|
+
|
|
21
|
+
### @direction?
|
|
22
|
+
|
|
23
|
+
> `optional` **@direction**: `null` \| `"ltr"` \| `"rtl"`
|
|
24
|
+
|
|
25
|
+
***
|
|
26
|
+
|
|
27
|
+
### @import?
|
|
28
|
+
|
|
29
|
+
> `optional` **@import**: `string`
|
|
30
|
+
|
|
31
|
+
***
|
|
32
|
+
|
|
33
|
+
### @language?
|
|
34
|
+
|
|
35
|
+
> `optional` **@language**: `string`
|
|
36
|
+
|
|
37
|
+
***
|
|
38
|
+
|
|
39
|
+
### @propagate?
|
|
40
|
+
|
|
41
|
+
> `optional` **@propagate**: `boolean`
|
|
42
|
+
|
|
43
|
+
***
|
|
44
|
+
|
|
45
|
+
### @protected?
|
|
46
|
+
|
|
47
|
+
> `optional` **@protected**: `boolean`
|
|
48
|
+
|
|
49
|
+
***
|
|
50
|
+
|
|
51
|
+
### @type?
|
|
52
|
+
|
|
53
|
+
> `optional` **@type**: `object`
|
|
54
|
+
|
|
55
|
+
#### @container
|
|
56
|
+
|
|
57
|
+
> **@container**: `"@set"`
|
|
58
|
+
|
|
59
|
+
#### @protected?
|
|
60
|
+
|
|
61
|
+
> `optional` **@protected**: `boolean`
|
|
62
|
+
|
|
63
|
+
***
|
|
64
|
+
|
|
65
|
+
### @version?
|
|
66
|
+
|
|
67
|
+
> `optional` **@version**: `"1.1"`
|
|
68
|
+
|
|
69
|
+
***
|
|
70
|
+
|
|
71
|
+
### @vocab?
|
|
72
|
+
|
|
73
|
+
> `optional` **@vocab**: `null` \| `string`
|