@twin.org/data-json-ld 0.0.3-next.8 → 0.9.0-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/README.md +1 -1
- package/dist/es/helpers/jsonLdAliasKey.js +4 -0
- package/dist/es/helpers/jsonLdAliasKey.js.map +1 -0
- package/dist/es/helpers/jsonLdExistingProperty.js +4 -0
- package/dist/es/helpers/jsonLdExistingProperty.js.map +1 -0
- package/dist/es/helpers/jsonLdExistingPropertyEither.js +2 -0
- package/dist/es/helpers/jsonLdExistingPropertyEither.js.map +1 -0
- package/dist/es/helpers/jsonLdKeys.js +4 -0
- package/dist/es/helpers/jsonLdKeys.js.map +1 -0
- package/dist/es/helpers/jsonLdObjectWithAliases.js +2 -0
- package/dist/es/helpers/jsonLdObjectWithAliases.js.map +1 -0
- package/dist/es/helpers/jsonLdObjectWithAtId.js +2 -0
- package/dist/es/helpers/jsonLdObjectWithAtId.js.map +1 -0
- package/dist/es/helpers/jsonLdObjectWithAtType.js +2 -0
- package/dist/es/helpers/jsonLdObjectWithAtType.js.map +1 -0
- package/dist/es/helpers/jsonLdObjectWithContext.js +2 -0
- package/dist/es/helpers/jsonLdObjectWithContext.js.map +1 -0
- package/dist/es/helpers/jsonLdObjectWithId.js +2 -0
- package/dist/es/helpers/jsonLdObjectWithId.js.map +1 -0
- package/dist/es/helpers/jsonLdObjectWithNoAtId.js +4 -0
- package/dist/es/helpers/jsonLdObjectWithNoAtId.js.map +1 -0
- package/dist/es/helpers/jsonLdObjectWithNoAtType.js +4 -0
- package/dist/es/helpers/jsonLdObjectWithNoAtType.js.map +1 -0
- package/dist/es/helpers/jsonLdObjectWithNoContext.js +4 -0
- package/dist/es/helpers/jsonLdObjectWithNoContext.js.map +1 -0
- package/dist/es/helpers/jsonLdObjectWithNoId.js +4 -0
- package/dist/es/helpers/jsonLdObjectWithNoId.js.map +1 -0
- package/dist/es/helpers/jsonLdObjectWithNoType.js +4 -0
- package/dist/es/helpers/jsonLdObjectWithNoType.js.map +1 -0
- package/dist/es/helpers/jsonLdObjectWithOptionalAtId.js +2 -0
- package/dist/es/helpers/jsonLdObjectWithOptionalAtId.js.map +1 -0
- package/dist/es/helpers/jsonLdObjectWithOptionalAtType.js +2 -0
- package/dist/es/helpers/jsonLdObjectWithOptionalAtType.js.map +1 -0
- package/dist/es/helpers/jsonLdObjectWithOptionalContext.js +2 -0
- package/dist/es/helpers/jsonLdObjectWithOptionalContext.js.map +1 -0
- package/dist/es/helpers/jsonLdObjectWithOptionalId.js +2 -0
- package/dist/es/helpers/jsonLdObjectWithOptionalId.js.map +1 -0
- package/dist/es/helpers/jsonLdObjectWithOptionalType.js +2 -0
- package/dist/es/helpers/jsonLdObjectWithOptionalType.js.map +1 -0
- package/dist/es/helpers/jsonLdObjectWithType.js +2 -0
- package/dist/es/helpers/jsonLdObjectWithType.js.map +1 -0
- package/dist/es/helpers/jsonLdOptionalKeys.js +4 -0
- package/dist/es/helpers/jsonLdOptionalKeys.js.map +1 -0
- package/dist/es/helpers/jsonLdRequiredKeys.js +2 -0
- package/dist/es/helpers/jsonLdRequiredKeys.js.map +1 -0
- package/dist/es/helpers/jsonLdWithAliases.js +2 -0
- package/dist/es/helpers/jsonLdWithAliases.js.map +1 -0
- package/dist/es/index.js +23 -0
- package/dist/es/index.js.map +1 -1
- package/dist/es/models/IJsonLdDocument.js.map +1 -1
- package/dist/es/schemas/JsonLdContainerType.json +17 -7
- package/dist/es/schemas/JsonLdContainerTypeArray.json +129 -142
- package/dist/es/schemas/JsonLdContextDefinition.json +76 -18
- package/dist/es/schemas/JsonLdContextDefinitionElement.json +1 -0
- package/dist/es/schemas/JsonLdContextDefinitionRoot.json +1 -0
- package/dist/es/schemas/JsonLdDocument.json +3 -3
- package/dist/es/schemas/JsonLdExpandedTermDefinition.json +101 -89
- package/dist/es/schemas/JsonLdGraphObject.json +2 -2
- package/dist/es/schemas/JsonLdIdMap.json +1 -0
- package/dist/es/schemas/JsonLdIncludedBlock.json +1 -0
- package/dist/es/schemas/JsonLdIndexMap.json +2 -1
- package/dist/es/schemas/JsonLdIndexMapItem.json +1 -0
- package/dist/es/schemas/JsonLdJsonArray.json +1 -0
- package/dist/es/schemas/JsonLdJsonObject.json +2 -8
- package/dist/es/schemas/JsonLdJsonPrimitive.json +14 -5
- package/dist/es/schemas/JsonLdJsonValue.json +1 -0
- package/dist/es/schemas/JsonLdLanguageMap.json +1 -0
- package/dist/es/schemas/JsonLdListObject.json +2 -2
- package/dist/es/schemas/JsonLdListOrSetItem.json +1 -0
- package/dist/es/schemas/JsonLdNodeObject.json +12 -72
- package/dist/es/schemas/JsonLdNodePrimitive.json +1 -0
- package/dist/es/schemas/JsonLdObject.json +3 -3
- package/dist/es/schemas/JsonLdSetObject.json +2 -2
- package/dist/es/schemas/JsonLdTypeMap.json +1 -0
- package/dist/es/schemas/JsonLdValueObject.json +99 -87
- package/dist/es/utils/jsonLdHelper.js +185 -24
- package/dist/es/utils/jsonLdHelper.js.map +1 -1
- package/dist/es/utils/jsonLdProcessor.js +134 -40
- package/dist/es/utils/jsonLdProcessor.js.map +1 -1
- package/dist/types/helpers/jsonLdAliasKey.d.ts +4 -0
- package/dist/types/helpers/jsonLdExistingProperty.d.ts +6 -0
- package/dist/types/helpers/jsonLdExistingPropertyEither.d.ts +6 -0
- package/dist/types/helpers/jsonLdKeys.d.ts +4 -0
- package/dist/types/helpers/jsonLdObjectWithAliases.d.ts +7 -0
- package/dist/types/helpers/jsonLdObjectWithAtId.d.ts +7 -0
- package/dist/types/helpers/jsonLdObjectWithAtType.d.ts +7 -0
- package/dist/types/helpers/jsonLdObjectWithContext.d.ts +7 -0
- package/dist/types/helpers/jsonLdObjectWithId.d.ts +7 -0
- package/dist/types/helpers/jsonLdObjectWithNoAtId.d.ts +4 -0
- package/dist/types/helpers/jsonLdObjectWithNoAtType.d.ts +4 -0
- package/dist/types/helpers/jsonLdObjectWithNoContext.d.ts +5 -0
- package/dist/types/helpers/jsonLdObjectWithNoId.d.ts +4 -0
- package/dist/types/helpers/jsonLdObjectWithNoType.d.ts +4 -0
- package/dist/types/helpers/jsonLdObjectWithOptionalAtId.d.ts +7 -0
- package/dist/types/helpers/jsonLdObjectWithOptionalAtType.d.ts +7 -0
- package/dist/types/helpers/jsonLdObjectWithOptionalContext.d.ts +9 -0
- package/dist/types/helpers/jsonLdObjectWithOptionalId.d.ts +7 -0
- package/dist/types/helpers/jsonLdObjectWithOptionalType.d.ts +7 -0
- package/dist/types/helpers/jsonLdObjectWithType.d.ts +7 -0
- package/dist/types/helpers/jsonLdOptionalKeys.d.ts +6 -0
- package/dist/types/helpers/jsonLdRequiredKeys.d.ts +5 -0
- package/dist/types/helpers/jsonLdWithAliases.d.ts +13 -0
- package/dist/types/index.d.ts +23 -0
- package/dist/types/models/IJsonLdDocument.d.ts +0 -4
- package/dist/types/utils/jsonLdHelper.d.ts +60 -10
- package/dist/types/utils/jsonLdProcessor.d.ts +16 -13
- package/docs/changelog.md +393 -72
- package/docs/examples.md +214 -1
- package/docs/reference/classes/JsonLdDataTypes.md +1 -1
- package/docs/reference/classes/JsonLdHelper.md +233 -19
- package/docs/reference/classes/JsonLdProcessor.md +57 -64
- package/docs/reference/index.md +23 -0
- package/docs/reference/interfaces/IJsonLdContextDefinition.md +20 -20
- package/docs/reference/interfaces/IJsonLdGraphObject.md +7 -7
- package/docs/reference/interfaces/IJsonLdIdMap.md +1 -1
- package/docs/reference/interfaces/IJsonLdIndexMap.md +1 -1
- package/docs/reference/interfaces/IJsonLdJsonObject.md +1 -1
- package/docs/reference/interfaces/IJsonLdLanguageMap.md +1 -1
- package/docs/reference/interfaces/IJsonLdListObject.md +3 -3
- package/docs/reference/interfaces/IJsonLdNodeObject.md +17 -17
- package/docs/reference/interfaces/IJsonLdObject.md +16 -16
- package/docs/reference/interfaces/IJsonLdSetObject.md +3 -3
- package/docs/reference/interfaces/IJsonLdTypeMap.md +1 -1
- package/docs/reference/type-aliases/IJsonLdExpandedTermDefinition.md +7 -7
- package/docs/reference/type-aliases/IJsonLdValueObject.md +2 -2
- package/docs/reference/type-aliases/JsonLdAliasKey.md +15 -0
- package/docs/reference/type-aliases/JsonLdExistingProperty.md +19 -0
- package/docs/reference/type-aliases/JsonLdExistingPropertyEither.md +24 -0
- package/docs/reference/type-aliases/JsonLdKeys.md +11 -0
- package/docs/reference/type-aliases/JsonLdObjectWithAliases.md +16 -0
- package/docs/reference/type-aliases/JsonLdObjectWithAtId.md +21 -0
- package/docs/reference/type-aliases/JsonLdObjectWithAtType.md +21 -0
- package/docs/reference/type-aliases/JsonLdObjectWithContext.md +21 -0
- package/docs/reference/type-aliases/JsonLdObjectWithId.md +21 -0
- package/docs/reference/type-aliases/JsonLdObjectWithNoAtId.md +11 -0
- package/docs/reference/type-aliases/JsonLdObjectWithNoAtType.md +11 -0
- package/docs/reference/type-aliases/JsonLdObjectWithNoContext.md +12 -0
- package/docs/reference/type-aliases/JsonLdObjectWithNoId.md +11 -0
- package/docs/reference/type-aliases/JsonLdObjectWithNoType.md +11 -0
- package/docs/reference/type-aliases/JsonLdObjectWithOptionalAtId.md +21 -0
- package/docs/reference/type-aliases/JsonLdObjectWithOptionalAtType.md +21 -0
- package/docs/reference/type-aliases/JsonLdObjectWithOptionalContext.md +22 -0
- package/docs/reference/type-aliases/JsonLdObjectWithOptionalId.md +21 -0
- package/docs/reference/type-aliases/JsonLdObjectWithOptionalType.md +21 -0
- package/docs/reference/type-aliases/JsonLdObjectWithType.md +21 -0
- package/docs/reference/type-aliases/JsonLdOptionalKeys.md +11 -0
- package/docs/reference/type-aliases/JsonLdRequiredKeys.md +11 -0
- package/docs/reference/type-aliases/JsonLdWithAliases.md +17 -0
- package/docs/reference/variables/JsonLdContexts.md +3 -3
- package/docs/reference/variables/JsonLdTypes.md +26 -26
- package/package.json +10 -10
|
@@ -2,6 +2,7 @@ import { type IValidationFailure } from "@twin.org/core";
|
|
|
2
2
|
import { type ValidationMode } from "@twin.org/data-core";
|
|
3
3
|
import type { IJsonLdDocument } from "../models/IJsonLdDocument.js";
|
|
4
4
|
import type { IJsonLdNodeObject } from "../models/IJsonLdNodeObject.js";
|
|
5
|
+
import type { IJsonLdNodePrimitive } from "../models/IJsonLdNodePrimitive.js";
|
|
5
6
|
/**
|
|
6
7
|
* Class to help with JSON LD.
|
|
7
8
|
*/
|
|
@@ -20,28 +21,77 @@ export declare class JsonLdHelper {
|
|
|
20
21
|
failOnMissingType?: boolean;
|
|
21
22
|
}): Promise<boolean>;
|
|
22
23
|
/**
|
|
23
|
-
*
|
|
24
|
-
* @param object The object to
|
|
25
|
-
* @returns The
|
|
24
|
+
* Convert an object to a JSON-LD node object.
|
|
25
|
+
* @param object The object to convert.
|
|
26
|
+
* @returns The JSON-LD node object.
|
|
26
27
|
*/
|
|
27
|
-
static toNodeObject(object:
|
|
28
|
+
static toNodeObject<T = unknown>(object: T): T & IJsonLdNodeObject;
|
|
29
|
+
/**
|
|
30
|
+
* Convert the JSON-LD node object to a structured object.
|
|
31
|
+
* @param nodeObject The JSON-LD node object to convert.
|
|
32
|
+
* @returns The structured object.
|
|
33
|
+
*/
|
|
34
|
+
static toStructuredObject<T = unknown>(nodeObject: IJsonLdNodeObject): T;
|
|
35
|
+
/**
|
|
36
|
+
* Expand the JSON-LD document.
|
|
37
|
+
* @param document The JSON-LD document to expand.
|
|
38
|
+
* @returns The expanded JSON-LD document.
|
|
39
|
+
*/
|
|
40
|
+
static expand(document: IJsonLdDocument): Promise<IJsonLdNodeObject[]>;
|
|
28
41
|
/**
|
|
29
42
|
* Expand the JSON-LD document and check if it is of a specific type.
|
|
30
|
-
* @param
|
|
43
|
+
* @param documentOrExpanded The JSON-LD document to check or already expanded document.
|
|
31
44
|
* @param type The type to check for.
|
|
32
45
|
* @returns True if the document is of the specified type.
|
|
33
46
|
*/
|
|
34
|
-
static isType(
|
|
47
|
+
static isType(documentOrExpanded: IJsonLdDocument | IJsonLdNodeObject[], type: string[]): Promise<boolean>;
|
|
35
48
|
/**
|
|
36
49
|
* Get the types from the document.
|
|
37
|
-
* @param
|
|
50
|
+
* @param documentOrExpanded The JSON-LD document to check or already expanded document.
|
|
38
51
|
* @returns The type(s) extracted from the document.
|
|
39
52
|
*/
|
|
40
|
-
static getType(
|
|
53
|
+
static getType(documentOrExpanded: IJsonLdDocument | IJsonLdNodeObject[]): Promise<string[]>;
|
|
41
54
|
/**
|
|
42
55
|
* Get the id from the document.
|
|
43
|
-
* @param
|
|
56
|
+
* @param documentOrExpanded The JSON-LD document to get the id from or already expanded document.
|
|
57
|
+
* @param additionalIdProperties Optional additional properties to check for the id, in addition to "@id" and "id".
|
|
44
58
|
* @returns The id extracted from the document.
|
|
45
59
|
*/
|
|
46
|
-
static getId(
|
|
60
|
+
static getId(documentOrExpanded: IJsonLdDocument | IJsonLdNodeObject[], additionalIdProperties?: string[]): Promise<string | undefined>;
|
|
61
|
+
/**
|
|
62
|
+
* Get property values by a single full expanded property name.
|
|
63
|
+
* @param documentOrExpanded The JSON-LD document to get the property from or already expanded document.
|
|
64
|
+
* @param propertyFullName The full expanded property name.
|
|
65
|
+
* @param language Optional filter values by their language property.
|
|
66
|
+
* @returns Matching property values for the input property.
|
|
67
|
+
*/
|
|
68
|
+
static getPropertyValue(documentOrExpanded: IJsonLdDocument | IJsonLdNodeObject[], propertyFullName: string, language?: string): Promise<IJsonLdNodePrimitive[] | undefined>;
|
|
69
|
+
/**
|
|
70
|
+
* Get property values by their full expanded property names.
|
|
71
|
+
* @param documentOrExpanded The JSON-LD document to get the property from or already expanded document.
|
|
72
|
+
* @param propertyFullNames The full expanded property names.
|
|
73
|
+
* @param language Optional filter values by their language property.
|
|
74
|
+
* @returns Matching property values for each input property, in the same index order.
|
|
75
|
+
*/
|
|
76
|
+
static getPropertyValues(documentOrExpanded: IJsonLdDocument | IJsonLdNodeObject[], propertyFullNames: string[], language?: string): Promise<(IJsonLdNodePrimitive[] | undefined)[]>;
|
|
77
|
+
/**
|
|
78
|
+
* Prefix all properties in the document with the provided prefix, except for JSON-LD properties.
|
|
79
|
+
* This is useful for ensuring that all properties are fully qualified with a namespace.
|
|
80
|
+
* For example, if the prefix is "ex" and the document has a property "name", it will be transformed to "ex:name".
|
|
81
|
+
* @param nodeObject The JSON-LD node object to prefix properties on.
|
|
82
|
+
* @param prefix The prefix to add to the properties.
|
|
83
|
+
* @param properties Optional list of properties to prefix. If not provided, all properties except for JSON-LD properties.
|
|
84
|
+
* @returns A new JSON-LD node object with the properties prefixed.
|
|
85
|
+
*/
|
|
86
|
+
static prefixProperties<T extends IJsonLdNodeObject>(nodeObject: T, prefix: string, properties?: string[]): IJsonLdNodeObject;
|
|
87
|
+
/**
|
|
88
|
+
* Strip a prefix from properties in the document, except for JSON-LD properties.
|
|
89
|
+
* This is useful for converting fully qualified namespaced properties back to local names.
|
|
90
|
+
* For example, if the prefix is "ex" and the document has a property "ex:name", it will be transformed to "name".
|
|
91
|
+
* @param nodeObject The JSON-LD node object to strip prefixed properties from.
|
|
92
|
+
* @param prefix The prefix to remove from the properties.
|
|
93
|
+
* @param properties Optional list of unprefixed properties to strip. If not provided, all matching prefixed properties.
|
|
94
|
+
* @returns A new JSON-LD node object with the prefix stripped from matching properties.
|
|
95
|
+
*/
|
|
96
|
+
static stripPrefixProperties<T extends IJsonLdNodeObject>(nodeObject: T, prefix: string, properties?: string[]): IJsonLdNodeObject;
|
|
47
97
|
}
|
|
@@ -7,13 +7,13 @@ import type { IJsonLdNodeObject } from "../models/IJsonLdNodeObject.js";
|
|
|
7
7
|
*/
|
|
8
8
|
export declare class JsonLdProcessor {
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Set the document loader used for retrieving JSON-LD documents.
|
|
11
11
|
* @param documentLoader The document loader to use.
|
|
12
12
|
*/
|
|
13
13
|
static setDocumentLoader(documentLoader: (url: Url) => Promise<RemoteDocument>): void;
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
* @returns The document loader.
|
|
15
|
+
* Get the document loader used for retrieving JSON-LD documents.
|
|
16
|
+
* @returns The active document loader function.
|
|
17
17
|
*/
|
|
18
18
|
static getDocumentLoader(): (url: Url) => Promise<RemoteDocument>;
|
|
19
19
|
/**
|
|
@@ -23,11 +23,12 @@ export declare class JsonLdProcessor {
|
|
|
23
23
|
static setCacheLimit(cacheLimitMs: number): void;
|
|
24
24
|
/**
|
|
25
25
|
* Get the cache limit for documents.
|
|
26
|
-
* @returns The
|
|
26
|
+
* @returns The cache limit in milliseconds.
|
|
27
27
|
*/
|
|
28
28
|
static getCacheLimit(): number;
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
30
|
+
* Replace the global redirect list (use {@link JsonLdProcessor.addRedirect} to append without replacing).
|
|
31
|
+
* Redirects run before any HTTP GET or `Link` discovery; use them for stable overrides, tests, or hosts that do not expose a suitable `Link` header.
|
|
31
32
|
* @param redirects The redirects to use.
|
|
32
33
|
*/
|
|
33
34
|
static setRedirects(redirects: {
|
|
@@ -42,6 +43,14 @@ export declare class JsonLdProcessor {
|
|
|
42
43
|
from: RegExp;
|
|
43
44
|
to: string;
|
|
44
45
|
}[];
|
|
46
|
+
/**
|
|
47
|
+
* Append a redirect rule (ignored if the same `RegExp.source` is already registered).
|
|
48
|
+
* Optional when the vocabulary URL supports HTTP `Link` discovery (`rel` includes `alternate`, `type` is `application/ld+json`) via the default document loader.
|
|
49
|
+
* Standards packages often expose `registerRedirects()` helpers that call this method; those are optional for the same reason.
|
|
50
|
+
* @param from The URL to redirect from.
|
|
51
|
+
* @param to The URL to redirect to.
|
|
52
|
+
*/
|
|
53
|
+
static addRedirect(from: RegExp, to: string): void;
|
|
45
54
|
/**
|
|
46
55
|
* Compact a document according to a particular context.
|
|
47
56
|
* @param document The JSON-LD document to compact.
|
|
@@ -69,12 +78,6 @@ export declare class JsonLdProcessor {
|
|
|
69
78
|
static canonize<T extends IJsonLdNodeObject>(document: T, options?: {
|
|
70
79
|
algorithm?: "URDNA2015" | "URGNA2012" | undefined;
|
|
71
80
|
}): Promise<string>;
|
|
72
|
-
/**
|
|
73
|
-
* Add a redirect to use during document resolution.
|
|
74
|
-
* @param from The URL to redirect from.
|
|
75
|
-
* @param to The URL to redirect to.
|
|
76
|
-
*/
|
|
77
|
-
static addRedirect(from: RegExp, to: string): void;
|
|
78
81
|
/**
|
|
79
82
|
* Combine contexts.
|
|
80
83
|
* @param context1 The first JSON-LD context to combine.
|
|
@@ -100,13 +103,13 @@ export declare class JsonLdProcessor {
|
|
|
100
103
|
* Add a context directly to the document loader cache.
|
|
101
104
|
* @param url The url the ld context is for.
|
|
102
105
|
* @param ldContext The context to add.
|
|
103
|
-
* @returns
|
|
106
|
+
* @returns A promise that resolves when the entry has been stored in the cache.
|
|
104
107
|
*/
|
|
105
108
|
static documentCacheAdd(url: string, ldContext: unknown): Promise<void>;
|
|
106
109
|
/**
|
|
107
110
|
* Remove a context from the document loader cache.
|
|
108
111
|
* @param url The url the ld context is for.
|
|
109
|
-
* @returns
|
|
112
|
+
* @returns A promise that resolves when the entry has been removed from the cache.
|
|
110
113
|
*/
|
|
111
114
|
static documentCacheRemove(url: string): Promise<void>;
|
|
112
115
|
}
|