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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/dist/cjs/index.cjs +613 -350
  2. package/dist/esm/index.mjs +615 -353
  3. package/dist/types/index.d.ts +26 -0
  4. package/dist/types/models/IJsonLdContainerType.d.ts +8 -0
  5. package/dist/types/models/IJsonLdContainerTypeArray.d.ts +9 -0
  6. package/dist/types/models/IJsonLdContextDefinition.d.ts +25 -0
  7. package/dist/types/models/IJsonLdContextDefinitionElement.d.ts +9 -0
  8. package/dist/types/models/IJsonLdContextDefinitionRoot.d.ts +9 -0
  9. package/dist/types/models/IJsonLdDocument.d.ts +2 -189
  10. package/dist/types/models/IJsonLdExpandedTermDefinition.d.ts +28 -0
  11. package/dist/types/models/IJsonLdGraphObject.d.ts +16 -0
  12. package/dist/types/models/IJsonLdIdMap.d.ts +12 -0
  13. package/dist/types/models/IJsonLdIncludedBlock.d.ts +10 -0
  14. package/dist/types/models/IJsonLdIndexMap.d.ts +13 -0
  15. package/dist/types/models/IJsonLdIndexMapItem.d.ts +12 -0
  16. package/dist/types/models/IJsonLdJsonArray.d.ts +9 -0
  17. package/dist/types/models/IJsonLdJsonObject.d.ts +11 -0
  18. package/dist/types/models/IJsonLdJsonPrimitive.d.ts +8 -0
  19. package/dist/types/models/IJsonLdJsonValue.d.ts +11 -0
  20. package/dist/types/models/IJsonLdKeyword.d.ts +42 -0
  21. package/dist/types/models/IJsonLdLanguageMap.d.ts +11 -0
  22. package/dist/types/models/IJsonLdListObject.d.ts +13 -0
  23. package/dist/types/models/IJsonLdListOrSetItem.d.ts +10 -0
  24. package/dist/types/models/IJsonLdNodeObject.d.ts +19 -0
  25. package/dist/types/models/IJsonLdNodePrimitive.d.ts +13 -0
  26. package/dist/types/models/IJsonLdObject.d.ts +24 -0
  27. package/dist/types/models/IJsonLdSetObject.d.ts +13 -0
  28. package/dist/types/models/IJsonLdTypeMap.d.ts +12 -0
  29. package/dist/types/models/IJsonLdValueObject.d.ts +26 -0
  30. package/dist/types/models/jsonLdContexts.d.ts +13 -0
  31. package/dist/types/models/jsonLdTypes.d.ts +27 -23
  32. package/dist/types/utils/jsonLdProcessor.d.ts +82 -8
  33. package/docs/changelog.md +29 -1
  34. package/docs/reference/classes/JsonLdDataTypes.md +3 -3
  35. package/docs/reference/classes/JsonLdHelper.md +16 -8
  36. package/docs/reference/classes/JsonLdProcessor.md +312 -16
  37. package/docs/reference/index.md +20 -15
  38. package/docs/reference/interfaces/IJsonLdContextDefinition.md +1 -1
  39. package/docs/reference/interfaces/IJsonLdGraphObject.md +1 -1
  40. package/docs/reference/interfaces/IJsonLdIdMap.md +1 -1
  41. package/docs/reference/interfaces/IJsonLdIndexMap.md +1 -1
  42. package/docs/reference/interfaces/IJsonLdJsonObject.md +3 -1
  43. package/docs/reference/interfaces/IJsonLdLanguageMap.md +1 -1
  44. package/docs/reference/interfaces/IJsonLdNodeObject.md +40 -4
  45. package/docs/reference/interfaces/IJsonLdObject.md +64 -0
  46. package/docs/reference/interfaces/IJsonLdTypeMap.md +1 -1
  47. package/docs/reference/type-aliases/IJsonLdContainerType.md +3 -1
  48. package/docs/reference/type-aliases/IJsonLdContainerTypeArray.md +3 -1
  49. package/docs/reference/type-aliases/IJsonLdContextDefinitionElement.md +5 -0
  50. package/docs/reference/type-aliases/IJsonLdContextDefinitionRoot.md +5 -0
  51. package/docs/reference/type-aliases/IJsonLdDocument.md +1 -1
  52. package/docs/reference/type-aliases/IJsonLdExpandedTermDefinition.md +1 -1
  53. package/docs/reference/type-aliases/IJsonLdIncludedBlock.md +1 -1
  54. package/docs/reference/type-aliases/IJsonLdIndexMapItem.md +1 -1
  55. package/docs/reference/type-aliases/IJsonLdJsonArray.md +3 -1
  56. package/docs/reference/type-aliases/IJsonLdJsonPrimitive.md +3 -1
  57. package/docs/reference/type-aliases/IJsonLdJsonValue.md +3 -1
  58. package/docs/reference/type-aliases/IJsonLdKeyword.md +51 -7
  59. package/docs/reference/type-aliases/IJsonLdListOrSetItem.md +1 -1
  60. package/docs/reference/type-aliases/IJsonLdNodePrimitive.md +1 -1
  61. package/docs/reference/type-aliases/IJsonLdValueObject.md +1 -1
  62. package/docs/reference/type-aliases/JsonLdContexts.md +5 -0
  63. package/docs/reference/type-aliases/JsonLdTypes.md +1 -1
  64. package/docs/reference/variables/JsonLdContexts.md +13 -0
  65. package/docs/reference/variables/JsonLdTypes.md +29 -23
  66. package/locales/en.json +8 -3
  67. package/package.json +7 -37
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The contexts of JSON-LD data.
3
+ */
4
+ export declare const JsonLdContexts: {
5
+ /**
6
+ * Context Root.
7
+ */
8
+ readonly ContextRoot: "https://schema.twindev.org/json-ld/";
9
+ };
10
+ /**
11
+ * The contexts of JSON-LD data.
12
+ */
13
+ export type JsonLdContexts = (typeof JsonLdContexts)[keyof typeof JsonLdContexts];
@@ -5,95 +5,99 @@ export declare const JsonLdTypes: {
5
5
  /**
6
6
  * Represents JSON-LD Document.
7
7
  */
8
- readonly Document: "https://schema.twindev.org/json-ld/JsonLdDocument";
8
+ readonly Document: "JsonLdDocument";
9
+ /**
10
+ * Represents JSON-LD Object.
11
+ */
12
+ readonly Object: "JsonLdObject";
9
13
  /**
10
14
  * Represents JSON-LD Node Object.
11
15
  */
12
- readonly NodeObject: "https://schema.twindev.org/json-ld/JsonLdNodeObject";
16
+ readonly NodeObject: "JsonLdNodeObject";
13
17
  /**
14
18
  * Represents JSON-LD Node Primitive.
15
19
  */
16
- readonly NodePrimitive: "https://schema.twindev.org/json-ld/JsonLdNodePrimitive";
20
+ readonly NodePrimitive: "JsonLdNodePrimitive";
17
21
  /**
18
22
  * Represents JSON-LD Graph Object.
19
23
  */
20
- readonly GraphObject: "https://schema.twindev.org/json-ld/JsonLdGraphObject";
24
+ readonly GraphObject: "JsonLdGraphObject";
21
25
  /**
22
26
  * Represents JSON-LD Value Object.
23
27
  */
24
- readonly ValueObject: "https://schema.twindev.org/json-ld/JsonLdValueObject";
28
+ readonly ValueObject: "JsonLdValueObject";
25
29
  /**
26
30
  * Represents JSON-LD List Object.
27
31
  */
28
- readonly ListObject: "https://schema.twindev.org/json-ld/JsonLdListObject";
32
+ readonly ListObject: "JsonLdListObject";
29
33
  /**
30
34
  * Represents JSON-LD Set Object.
31
35
  */
32
- readonly SetObject: "https://schema.twindev.org/json-ld/JsonLdSetObject";
36
+ readonly SetObject: "JsonLdSetObject";
33
37
  /**
34
38
  * Represents JSON-LD Language Map.
35
39
  */
36
- readonly LanguageMap: "https://schema.twindev.org/json-ld/JsonLdLanguageMap";
40
+ readonly LanguageMap: "JsonLdLanguageMap";
37
41
  /**
38
42
  * Represents JSON-LD Index Map.
39
43
  */
40
- readonly IndexMap: "https://schema.twindev.org/json-ld/JsonLdIndexMap";
44
+ readonly IndexMap: "JsonLdIndexMap";
41
45
  /**
42
46
  * Represents JSON-LD Index Map Item.
43
47
  */
44
- readonly IndexMapItem: "https://schema.twindev.org/json-ld/JsonLdIndexMapItem";
48
+ readonly IndexMapItem: "JsonLdIndexMapItem";
45
49
  /**
46
50
  * Represents JSON-LD Id Map.
47
51
  */
48
- readonly IdMap: "https://schema.twindev.org/json-ld/JsonLdIdMap";
52
+ readonly IdMap: "JsonLdIdMap";
49
53
  /**
50
54
  * Represents JSON-LD Type Map.
51
55
  */
52
- readonly TypeMap: "https://schema.twindev.org/json-ld/JsonLdTypeMap";
56
+ readonly TypeMap: "JsonLdTypeMap";
53
57
  /**
54
58
  * Represents JSON-LD Included block.
55
59
  */
56
- readonly IncludedBlock: "https://schema.twindev.org/json-ld/JsonLdIncludedBlock";
60
+ readonly IncludedBlock: "JsonLdIncludedBlock";
57
61
  /**
58
62
  * Represents JSON-LD Context Definition.
59
63
  */
60
- readonly ContextDefinition: "https://schema.twindev.org/json-ld/JsonLdContextDefinition";
64
+ readonly ContextDefinition: "JsonLdContextDefinition";
61
65
  /**
62
66
  * Represents JSON-LD Expanded Term Definition.
63
67
  */
64
- readonly ExpandedTermDefinition: "https://schema.twindev.org/json-ld/JsonLdExpandedTermDefinition";
68
+ readonly ExpandedTermDefinition: "JsonLdExpandedTermDefinition";
65
69
  /**
66
70
  * Represents JSON-LD Keyword.
67
71
  */
68
- readonly Keyword: "https://schema.twindev.org/json-ld/JsonLdKeyword";
72
+ readonly Keyword: "JsonLdKeyword";
69
73
  /**
70
74
  * Represents JSON-LD List or Set Item.
71
75
  */
72
- readonly ListOrSetItem: "https://schema.twindev.org/json-ld/JsonLdListOrSetItem";
76
+ readonly ListOrSetItem: "JsonLdListOrSetItem";
73
77
  /**
74
78
  * Represents JSON-LD Container Type.
75
79
  */
76
- readonly ContainerType: "https://schema.twindev.org/json-ld/JsonLdContainerType";
80
+ readonly ContainerType: "JsonLdContainerType";
77
81
  /**
78
82
  * Represents JSON-LD Container Type Array.
79
83
  */
80
- readonly ContainerTypeArray: "https://schema.twindev.org/json-ld/JsonLdContainerTypeArray";
84
+ readonly ContainerTypeArray: "JsonLdContainerTypeArray";
81
85
  /**
82
86
  * Represents JSON-LD JSON Primitive.
83
87
  */
84
- readonly JsonPrimitive: "https://schema.twindev.org/json-ld/JsonLdJsonPrimitive";
88
+ readonly JsonPrimitive: "JsonLdJsonPrimitive";
85
89
  /**
86
90
  * Represents JSON-LD JSON Array.
87
91
  */
88
- readonly JsonArray: "https://schema.twindev.org/json-ld/JsonLdJsonArray";
92
+ readonly JsonArray: "JsonLdJsonArray";
89
93
  /**
90
94
  * Represents JSON-LD JSON Object.
91
95
  */
92
- readonly JsonObject: "https://schema.twindev.org/json-ld/JsonLdJsonObject";
96
+ readonly JsonObject: "JsonLdJsonObject";
93
97
  /**
94
98
  * Represents JSON-LD JSON Value.
95
99
  */
96
- readonly JsonValue: "https://schema.twindev.org/json-ld/JsonLdJsonValue";
100
+ readonly JsonValue: "JsonLdJsonValue";
97
101
  };
98
102
  /**
99
103
  * The types of JSON-LD data.
@@ -1,34 +1,108 @@
1
1
  import type { RemoteDocument, Url } from "jsonld/jsonld-spec";
2
- import type { IJsonLdContextDefinition, IJsonLdDocument } from "../models/IJsonLdDocument";
2
+ import type { IJsonLdContextDefinitionElement } from "../models/IJsonLdContextDefinitionElement";
3
+ import type { IJsonLdContextDefinitionRoot } from "../models/IJsonLdContextDefinitionRoot";
4
+ import type { IJsonLdNodeObject } from "../models/IJsonLdNodeObject";
3
5
  /**
4
6
  * JSON-LD Processor.
5
7
  */
6
8
  export declare class JsonLdProcessor {
7
9
  /**
8
- * Redirects to use during document resolution.
10
+ * The document loader to use.
11
+ * @param documentLoader The document loader to use.
9
12
  */
10
- private static readonly _redirects;
13
+ static setDocumentLoader(documentLoader: (url: Url) => Promise<RemoteDocument>): void;
11
14
  /**
12
- * The document loader to use.
15
+ * The document loader to use for retrieving JSON-LD documents.
16
+ * @returns The document loader.
17
+ */
18
+ static getDocumentLoader(): (url: Url) => Promise<RemoteDocument>;
19
+ /**
20
+ * Set the cache time limit for documents.
21
+ * @param cacheLimitMs The cache limit in milliseconds.
22
+ */
23
+ static setCacheLimit(cacheLimitMs: number): void;
24
+ /**
25
+ * Get the cache limit for documents.
26
+ * @returns The document loader.
13
27
  */
14
- static DOCUMENT_LOADER: (url: Url) => Promise<RemoteDocument>;
28
+ static getCacheLimit(): number;
29
+ /**
30
+ * Set the global redirects for JSON-LD, use addRedirect for default handling.
31
+ * @param redirects The redirects to use.
32
+ */
33
+ static setRedirects(redirects: {
34
+ from: RegExp;
35
+ to: string;
36
+ }[]): void;
37
+ /**
38
+ * Get the global redirects for JSON-LD.
39
+ * @returns The registered redirects.
40
+ */
41
+ static getRedirects(): {
42
+ from: RegExp;
43
+ to: string;
44
+ }[];
15
45
  /**
16
46
  * Compact a document according to a particular context.
17
47
  * @param document The JSON-LD document to compact.
18
- * @param context The context to compact the document to.
48
+ * @param context The context to compact the document to, if not provided will try and gather from the object.
19
49
  * @returns The compacted JSON-LD document.
20
50
  */
21
- static compact(document: IJsonLdDocument, context?: IJsonLdContextDefinition): Promise<IJsonLdDocument>;
51
+ static compact<T>(document: T, context?: IJsonLdContextDefinitionRoot): Promise<T>;
22
52
  /**
23
53
  * Expand a document, removing its context.
24
54
  * @param compacted The compacted JSON-LD document to expand.
25
55
  * @returns The expanded JSON-LD document.
26
56
  */
27
- static expand(compacted: IJsonLdDocument): Promise<IJsonLdDocument>;
57
+ static expand<T>(compacted: T): Promise<IJsonLdNodeObject[]>;
58
+ /**
59
+ * Canonize a document.
60
+ * @param document The document to canonize.
61
+ * @param options The options for canonization.
62
+ * @param options.algorithm The algorithm to use for canonization, defaults to URDNA2015.
63
+ * @returns The canonized document.
64
+ */
65
+ static canonize<T extends IJsonLdNodeObject>(document: T, options?: {
66
+ algorithm?: "URDNA2015" | "URGNA2012" | undefined;
67
+ }): Promise<string>;
28
68
  /**
29
69
  * Add a redirect to use during document resolution.
30
70
  * @param from The URL to redirect from.
31
71
  * @param to The URL to redirect to.
32
72
  */
33
73
  static addRedirect(from: RegExp, to: string): void;
74
+ /**
75
+ * Combine contexts.
76
+ * @param context1 The first JSON-LD context to combine.
77
+ * @param context2 The second JSON-LD context to combine.
78
+ * @returns The combined context.
79
+ */
80
+ static combineContexts(context1: IJsonLdContextDefinitionRoot | undefined, context2: IJsonLdContextDefinitionRoot | undefined): IJsonLdContextDefinitionRoot | undefined;
81
+ /**
82
+ * Gather all the contexts from the element and it's children.
83
+ * @param element The element to gather the contexts from.
84
+ * @param initial The initial context.
85
+ * @returns The combined contexts.
86
+ */
87
+ static gatherContexts<T>(element: T, initial?: IJsonLdContextDefinitionRoot): IJsonLdContextDefinitionRoot | undefined;
88
+ /**
89
+ * Remove all the contexts that match the pattern.
90
+ * @param context The context to remove the entries from.
91
+ * @param match The element to try and match.
92
+ * @returns The updated contexts.
93
+ */
94
+ static removeContexts(context: IJsonLdContextDefinitionRoot | undefined, match?: IJsonLdContextDefinitionElement[]): IJsonLdContextDefinitionRoot | undefined;
95
+ /**
96
+ * Add a context directly to the document loader cache.
97
+ * @param url The url the ld context is for.
98
+ * @param ldContext The context to add.
99
+ * @returns Nothing.
100
+ */
101
+ static documentCacheAdd(url: string, ldContext: unknown): Promise<void>;
102
+ /**
103
+ * Remove a context from the document loader cache.
104
+ * @param url The url the ld context is for.
105
+ * @returns Nothing.
106
+ */
107
+ static documentCacheRemove(url: string): Promise<void>;
34
108
  }
package/docs/changelog.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # @twin.org/data-json-ld - Changelog
2
2
 
3
- ## v0.0.1-next.3
3
+ ## [0.0.1-next.30](https://github.com/twinfoundation/data/compare/data-json-ld-v0.0.1-next.29...data-json-ld-v0.0.1-next.30) (2025-04-17)
4
+
5
+
6
+ ### Features
7
+
8
+ * use shared store mechanism ([#3](https://github.com/twinfoundation/data/issues/3)) ([33eb221](https://github.com/twinfoundation/data/commit/33eb221ccec2b4a79549c06e9a04225009b93a46))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/data-core bumped from 0.0.1-next.29 to 0.0.1-next.30
16
+
17
+ ## [0.0.1-next.29](https://github.com/twinfoundation/data/compare/data-json-ld-v0.0.1-next.28...data-json-ld-v0.0.1-next.29) (2025-03-28)
18
+
19
+
20
+ ### Features
21
+
22
+ * add document cache access methods ([dbf1e36](https://github.com/twinfoundation/data/commit/dbf1e36d176c5f428f8c52628fb5a1ff7a6a174a))
23
+
24
+
25
+ ### Dependencies
26
+
27
+ * The following workspace dependencies were updated
28
+ * dependencies
29
+ * @twin.org/data-core bumped from 0.0.1-next.28 to 0.0.1-next.29
30
+
31
+ ## v0.0.1-next.28
4
32
 
5
33
  - Initial Release
@@ -4,13 +4,13 @@ Handle all the data types for JSON-LD.
4
4
 
5
5
  ## Constructors
6
6
 
7
- ### new JsonLdDataTypes()
7
+ ### Constructor
8
8
 
9
- > **new JsonLdDataTypes**(): [`JsonLdDataTypes`](JsonLdDataTypes.md)
9
+ > **new JsonLdDataTypes**(): `JsonLdDataTypes`
10
10
 
11
11
  #### Returns
12
12
 
13
- [`JsonLdDataTypes`](JsonLdDataTypes.md)
13
+ `JsonLdDataTypes`
14
14
 
15
15
  ## Methods
16
16
 
@@ -4,37 +4,45 @@ Class to help with JSON LD.
4
4
 
5
5
  ## Constructors
6
6
 
7
- ### new JsonLdHelper()
7
+ ### Constructor
8
8
 
9
- > **new JsonLdHelper**(): [`JsonLdHelper`](JsonLdHelper.md)
9
+ > **new JsonLdHelper**(): `JsonLdHelper`
10
10
 
11
11
  #### Returns
12
12
 
13
- [`JsonLdHelper`](JsonLdHelper.md)
13
+ `JsonLdHelper`
14
14
 
15
15
  ## Methods
16
16
 
17
17
  ### validate()
18
18
 
19
- > `static` **validate**\<`T`\>(`document`, `validationFailures`, `validationMode`?): `Promise`\<`boolean`\>
19
+ > `static` **validate**\<`T`\>(`document`, `validationFailures`, `validationMode?`): `Promise`\<`boolean`\>
20
20
 
21
21
  Validate a JSON-LD document.
22
22
 
23
23
  #### Type Parameters
24
24
 
25
- **T** *extends* [`IJsonLdDocument`](../type-aliases/IJsonLdDocument.md) = [`IJsonLdDocument`](../type-aliases/IJsonLdDocument.md)
25
+ ##### T
26
+
27
+ `T` *extends* [`IJsonLdDocument`](../type-aliases/IJsonLdDocument.md) = [`IJsonLdDocument`](../type-aliases/IJsonLdDocument.md)
26
28
 
27
29
  #### Parameters
28
30
 
29
- **document**: `T`
31
+ ##### document
32
+
33
+ `T`
30
34
 
31
35
  The JSON-LD document to validate.
32
36
 
33
- **validationFailures**: `IValidationFailure`[]
37
+ ##### validationFailures
38
+
39
+ `IValidationFailure`[]
34
40
 
35
41
  The list of validation failures to add to.
36
42
 
37
- **validationMode?**: `ValidationMode`
43
+ ##### validationMode?
44
+
45
+ `ValidationMode`
38
46
 
39
47
  The validation mode to use, defaults to either.
40
48