@twin.org/data-json-ld 0.0.3-next.9 → 0.9.0

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 (151) hide show
  1. package/README.md +1 -1
  2. package/dist/es/helpers/jsonLdAliasKey.js +4 -0
  3. package/dist/es/helpers/jsonLdAliasKey.js.map +1 -0
  4. package/dist/es/helpers/jsonLdExistingProperty.js +4 -0
  5. package/dist/es/helpers/jsonLdExistingProperty.js.map +1 -0
  6. package/dist/es/helpers/jsonLdExistingPropertyEither.js +2 -0
  7. package/dist/es/helpers/jsonLdExistingPropertyEither.js.map +1 -0
  8. package/dist/es/helpers/jsonLdKeys.js +4 -0
  9. package/dist/es/helpers/jsonLdKeys.js.map +1 -0
  10. package/dist/es/helpers/jsonLdObjectWithAliases.js +2 -0
  11. package/dist/es/helpers/jsonLdObjectWithAliases.js.map +1 -0
  12. package/dist/es/helpers/jsonLdObjectWithAtId.js +2 -0
  13. package/dist/es/helpers/jsonLdObjectWithAtId.js.map +1 -0
  14. package/dist/es/helpers/jsonLdObjectWithAtType.js +2 -0
  15. package/dist/es/helpers/jsonLdObjectWithAtType.js.map +1 -0
  16. package/dist/es/helpers/jsonLdObjectWithContext.js +2 -0
  17. package/dist/es/helpers/jsonLdObjectWithContext.js.map +1 -0
  18. package/dist/es/helpers/jsonLdObjectWithId.js +2 -0
  19. package/dist/es/helpers/jsonLdObjectWithId.js.map +1 -0
  20. package/dist/es/helpers/jsonLdObjectWithNoAtId.js +4 -0
  21. package/dist/es/helpers/jsonLdObjectWithNoAtId.js.map +1 -0
  22. package/dist/es/helpers/jsonLdObjectWithNoAtType.js +4 -0
  23. package/dist/es/helpers/jsonLdObjectWithNoAtType.js.map +1 -0
  24. package/dist/es/helpers/jsonLdObjectWithNoContext.js +4 -0
  25. package/dist/es/helpers/jsonLdObjectWithNoContext.js.map +1 -0
  26. package/dist/es/helpers/jsonLdObjectWithNoId.js +4 -0
  27. package/dist/es/helpers/jsonLdObjectWithNoId.js.map +1 -0
  28. package/dist/es/helpers/jsonLdObjectWithNoType.js +4 -0
  29. package/dist/es/helpers/jsonLdObjectWithNoType.js.map +1 -0
  30. package/dist/es/helpers/jsonLdObjectWithOptionalAtId.js +2 -0
  31. package/dist/es/helpers/jsonLdObjectWithOptionalAtId.js.map +1 -0
  32. package/dist/es/helpers/jsonLdObjectWithOptionalAtType.js +2 -0
  33. package/dist/es/helpers/jsonLdObjectWithOptionalAtType.js.map +1 -0
  34. package/dist/es/helpers/jsonLdObjectWithOptionalContext.js +2 -0
  35. package/dist/es/helpers/jsonLdObjectWithOptionalContext.js.map +1 -0
  36. package/dist/es/helpers/jsonLdObjectWithOptionalId.js +2 -0
  37. package/dist/es/helpers/jsonLdObjectWithOptionalId.js.map +1 -0
  38. package/dist/es/helpers/jsonLdObjectWithOptionalType.js +2 -0
  39. package/dist/es/helpers/jsonLdObjectWithOptionalType.js.map +1 -0
  40. package/dist/es/helpers/jsonLdObjectWithType.js +2 -0
  41. package/dist/es/helpers/jsonLdObjectWithType.js.map +1 -0
  42. package/dist/es/helpers/jsonLdOptionalKeys.js +4 -0
  43. package/dist/es/helpers/jsonLdOptionalKeys.js.map +1 -0
  44. package/dist/es/helpers/jsonLdRequiredKeys.js +2 -0
  45. package/dist/es/helpers/jsonLdRequiredKeys.js.map +1 -0
  46. package/dist/es/helpers/jsonLdWithAliases.js +2 -0
  47. package/dist/es/helpers/jsonLdWithAliases.js.map +1 -0
  48. package/dist/es/index.js +23 -0
  49. package/dist/es/index.js.map +1 -1
  50. package/dist/es/models/IJsonLdDocument.js.map +1 -1
  51. package/dist/es/schemas/JsonLdContainerType.json +17 -7
  52. package/dist/es/schemas/JsonLdContainerTypeArray.json +129 -142
  53. package/dist/es/schemas/JsonLdContextDefinition.json +76 -18
  54. package/dist/es/schemas/JsonLdContextDefinitionElement.json +1 -0
  55. package/dist/es/schemas/JsonLdContextDefinitionRoot.json +1 -0
  56. package/dist/es/schemas/JsonLdDocument.json +3 -3
  57. package/dist/es/schemas/JsonLdExpandedTermDefinition.json +101 -89
  58. package/dist/es/schemas/JsonLdGraphObject.json +2 -2
  59. package/dist/es/schemas/JsonLdIdMap.json +1 -0
  60. package/dist/es/schemas/JsonLdIncludedBlock.json +1 -0
  61. package/dist/es/schemas/JsonLdIndexMap.json +2 -1
  62. package/dist/es/schemas/JsonLdIndexMapItem.json +1 -0
  63. package/dist/es/schemas/JsonLdJsonArray.json +1 -0
  64. package/dist/es/schemas/JsonLdJsonObject.json +2 -8
  65. package/dist/es/schemas/JsonLdJsonPrimitive.json +14 -5
  66. package/dist/es/schemas/JsonLdJsonValue.json +1 -0
  67. package/dist/es/schemas/JsonLdLanguageMap.json +1 -0
  68. package/dist/es/schemas/JsonLdListObject.json +2 -2
  69. package/dist/es/schemas/JsonLdListOrSetItem.json +1 -0
  70. package/dist/es/schemas/JsonLdNodeObject.json +12 -72
  71. package/dist/es/schemas/JsonLdNodePrimitive.json +1 -0
  72. package/dist/es/schemas/JsonLdObject.json +3 -3
  73. package/dist/es/schemas/JsonLdSetObject.json +2 -2
  74. package/dist/es/schemas/JsonLdTypeMap.json +1 -0
  75. package/dist/es/schemas/JsonLdValueObject.json +99 -87
  76. package/dist/es/utils/jsonLdHelper.js +85 -11
  77. package/dist/es/utils/jsonLdHelper.js.map +1 -1
  78. package/dist/es/utils/jsonLdProcessor.js +134 -40
  79. package/dist/es/utils/jsonLdProcessor.js.map +1 -1
  80. package/dist/types/helpers/jsonLdAliasKey.d.ts +4 -0
  81. package/dist/types/helpers/jsonLdExistingProperty.d.ts +6 -0
  82. package/dist/types/helpers/jsonLdExistingPropertyEither.d.ts +6 -0
  83. package/dist/types/helpers/jsonLdKeys.d.ts +4 -0
  84. package/dist/types/helpers/jsonLdObjectWithAliases.d.ts +7 -0
  85. package/dist/types/helpers/jsonLdObjectWithAtId.d.ts +7 -0
  86. package/dist/types/helpers/jsonLdObjectWithAtType.d.ts +7 -0
  87. package/dist/types/helpers/jsonLdObjectWithContext.d.ts +7 -0
  88. package/dist/types/helpers/jsonLdObjectWithId.d.ts +7 -0
  89. package/dist/types/helpers/jsonLdObjectWithNoAtId.d.ts +4 -0
  90. package/dist/types/helpers/jsonLdObjectWithNoAtType.d.ts +4 -0
  91. package/dist/types/helpers/jsonLdObjectWithNoContext.d.ts +5 -0
  92. package/dist/types/helpers/jsonLdObjectWithNoId.d.ts +4 -0
  93. package/dist/types/helpers/jsonLdObjectWithNoType.d.ts +4 -0
  94. package/dist/types/helpers/jsonLdObjectWithOptionalAtId.d.ts +7 -0
  95. package/dist/types/helpers/jsonLdObjectWithOptionalAtType.d.ts +7 -0
  96. package/dist/types/helpers/jsonLdObjectWithOptionalContext.d.ts +9 -0
  97. package/dist/types/helpers/jsonLdObjectWithOptionalId.d.ts +7 -0
  98. package/dist/types/helpers/jsonLdObjectWithOptionalType.d.ts +7 -0
  99. package/dist/types/helpers/jsonLdObjectWithType.d.ts +7 -0
  100. package/dist/types/helpers/jsonLdOptionalKeys.d.ts +6 -0
  101. package/dist/types/helpers/jsonLdRequiredKeys.d.ts +5 -0
  102. package/dist/types/helpers/jsonLdWithAliases.d.ts +13 -0
  103. package/dist/types/index.d.ts +23 -0
  104. package/dist/types/models/IJsonLdDocument.d.ts +0 -4
  105. package/dist/types/utils/jsonLdHelper.d.ts +31 -4
  106. package/dist/types/utils/jsonLdProcessor.d.ts +16 -13
  107. package/docs/changelog.md +401 -74
  108. package/docs/examples.md +214 -1
  109. package/docs/reference/classes/JsonLdDataTypes.md +1 -1
  110. package/docs/reference/classes/JsonLdHelper.md +130 -12
  111. package/docs/reference/classes/JsonLdProcessor.md +57 -64
  112. package/docs/reference/index.md +23 -0
  113. package/docs/reference/interfaces/IJsonLdContextDefinition.md +20 -20
  114. package/docs/reference/interfaces/IJsonLdGraphObject.md +7 -7
  115. package/docs/reference/interfaces/IJsonLdIdMap.md +1 -1
  116. package/docs/reference/interfaces/IJsonLdIndexMap.md +1 -1
  117. package/docs/reference/interfaces/IJsonLdJsonObject.md +1 -1
  118. package/docs/reference/interfaces/IJsonLdLanguageMap.md +1 -1
  119. package/docs/reference/interfaces/IJsonLdListObject.md +3 -3
  120. package/docs/reference/interfaces/IJsonLdNodeObject.md +17 -17
  121. package/docs/reference/interfaces/IJsonLdObject.md +16 -16
  122. package/docs/reference/interfaces/IJsonLdSetObject.md +3 -3
  123. package/docs/reference/interfaces/IJsonLdTypeMap.md +1 -1
  124. package/docs/reference/type-aliases/IJsonLdExpandedTermDefinition.md +7 -7
  125. package/docs/reference/type-aliases/IJsonLdValueObject.md +2 -2
  126. package/docs/reference/type-aliases/JsonLdAliasKey.md +15 -0
  127. package/docs/reference/type-aliases/JsonLdExistingProperty.md +19 -0
  128. package/docs/reference/type-aliases/JsonLdExistingPropertyEither.md +24 -0
  129. package/docs/reference/type-aliases/JsonLdKeys.md +11 -0
  130. package/docs/reference/type-aliases/JsonLdObjectWithAliases.md +16 -0
  131. package/docs/reference/type-aliases/JsonLdObjectWithAtId.md +21 -0
  132. package/docs/reference/type-aliases/JsonLdObjectWithAtType.md +21 -0
  133. package/docs/reference/type-aliases/JsonLdObjectWithContext.md +21 -0
  134. package/docs/reference/type-aliases/JsonLdObjectWithId.md +21 -0
  135. package/docs/reference/type-aliases/JsonLdObjectWithNoAtId.md +11 -0
  136. package/docs/reference/type-aliases/JsonLdObjectWithNoAtType.md +11 -0
  137. package/docs/reference/type-aliases/JsonLdObjectWithNoContext.md +12 -0
  138. package/docs/reference/type-aliases/JsonLdObjectWithNoId.md +11 -0
  139. package/docs/reference/type-aliases/JsonLdObjectWithNoType.md +11 -0
  140. package/docs/reference/type-aliases/JsonLdObjectWithOptionalAtId.md +21 -0
  141. package/docs/reference/type-aliases/JsonLdObjectWithOptionalAtType.md +21 -0
  142. package/docs/reference/type-aliases/JsonLdObjectWithOptionalContext.md +22 -0
  143. package/docs/reference/type-aliases/JsonLdObjectWithOptionalId.md +21 -0
  144. package/docs/reference/type-aliases/JsonLdObjectWithOptionalType.md +21 -0
  145. package/docs/reference/type-aliases/JsonLdObjectWithType.md +21 -0
  146. package/docs/reference/type-aliases/JsonLdOptionalKeys.md +11 -0
  147. package/docs/reference/type-aliases/JsonLdRequiredKeys.md +11 -0
  148. package/docs/reference/type-aliases/JsonLdWithAliases.md +17 -0
  149. package/docs/reference/variables/JsonLdContexts.md +3 -3
  150. package/docs/reference/variables/JsonLdTypes.md +26 -26
  151. package/package.json +10 -10
@@ -21,11 +21,17 @@ export declare class JsonLdHelper {
21
21
  failOnMissingType?: boolean;
22
22
  }): Promise<boolean>;
23
23
  /**
24
- * Expand an object to a JSON-LD node object.
25
- * @param object The object to expand.
26
- * @returns The expanded JSON-LD node object.
24
+ * Convert an object to a JSON-LD node object.
25
+ * @param object The object to convert.
26
+ * @returns The JSON-LD node object.
27
27
  */
28
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;
29
35
  /**
30
36
  * Expand the JSON-LD document.
31
37
  * @param document The JSON-LD document to expand.
@@ -48,9 +54,10 @@ export declare class JsonLdHelper {
48
54
  /**
49
55
  * Get the id from the document.
50
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".
51
58
  * @returns The id extracted from the document.
52
59
  */
53
- static getId(documentOrExpanded: IJsonLdDocument | IJsonLdNodeObject[]): Promise<string | undefined>;
60
+ static getId(documentOrExpanded: IJsonLdDocument | IJsonLdNodeObject[], additionalIdProperties?: string[]): Promise<string | undefined>;
54
61
  /**
55
62
  * Get property values by a single full expanded property name.
56
63
  * @param documentOrExpanded The JSON-LD document to get the property from or already expanded document.
@@ -67,4 +74,24 @@ export declare class JsonLdHelper {
67
74
  * @returns Matching property values for each input property, in the same index order.
68
75
  */
69
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;
70
97
  }
@@ -7,13 +7,13 @@ import type { IJsonLdNodeObject } from "../models/IJsonLdNodeObject.js";
7
7
  */
8
8
  export declare class JsonLdProcessor {
9
9
  /**
10
- * The document loader to use.
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
- * The document loader to use for retrieving JSON-LD documents.
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 document loader.
26
+ * @returns The cache limit in milliseconds.
27
27
  */
28
28
  static getCacheLimit(): number;
29
29
  /**
30
- * Set the global redirects for JSON-LD, use addRedirect for default handling.
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 Nothing.
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 Nothing.
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
  }