@twin.org/data-json-ld 0.0.3-next.10 → 0.0.3-next.11

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.
@@ -121,11 +121,12 @@ export class JsonLdHelper {
121
121
  /**
122
122
  * Get the id from the document.
123
123
  * @param documentOrExpanded The JSON-LD document to get the id from or already expanded document.
124
+ * @param additionalIdProperties Optional additional properties to check for the id, in addition to "@id" and "id".
124
125
  * @returns The id extracted from the document.
125
126
  */
126
- static async getId(documentOrExpanded) {
127
+ static async getId(documentOrExpanded, additionalIdProperties) {
127
128
  const expanded = await JsonLdHelper.getExpandedDocument(documentOrExpanded);
128
- const props = ["@id", "id"];
129
+ const props = ["@id", "id", ...(additionalIdProperties ?? [])];
129
130
  for (const expandedDoc of expanded) {
130
131
  for (const prop of props) {
131
132
  const expandedProps = ArrayHelper.fromObjectOrArray(expandedDoc[prop]);
@@ -1 +1 @@
1
- {"version":3,"file":"jsonLdHelper.js","sourceRoot":"","sources":["../../../src/utils/jsonLdHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE,EAA2B,MAAM,gBAAgB,CAAC;AAClF,OAAO,EAAE,cAAc,EAAuB,MAAM,qBAAqB,CAAC;AAE1E,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAKvD;;GAEG;AACH,MAAM,OAAO,YAAY;IACxB;;;OAGG;IACI,MAAM,CAAU,UAAU,kBAA0B;IAE3D;;;;;;;;OAQG;IACI,MAAM,CAAC,KAAK,CAAC,QAAQ,CAC3B,QAAW,EACX,kBAAwC,EACxC,OAGC;QAED,IAAI,EAAE,CAAC,KAAK,CAAoB,QAAQ,CAAC,EAAE,CAAC;YAC3C,2DAA2D;YAC3D,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;gBAC7B,MAAM,YAAY,CAAC,QAAQ,CAAC,IAAI,EAAE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AAG,KAAK,CAAC;gBACjC,CAAC;YACF,CAAC;iBAAM,CAAC;gBACP,kBAAkB,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YACjC,CAAC;QACF,CAAC;QAED,OAAO,kBAAkB,CAAC;IAC3B,CAAC;IAED;;;;;OAKG;IACK,MAAM,CAAC,KAAK,CAAC,mBAAmB,CACvC,kBAAyD;QAEzD,IAAI,EAAE,CAAC,KAAK,CAAoB,kBAAkB,CAAC,EAAE,CAAC;YACrD,MAAM,CAAC,KAAK,CACX,YAAY,CAAC,UAAU,wBAEvB,kBAAkB,CAClB,CAAC;YAEF,OAAO,kBAAkB,CAAC;QAC3B,CAAC;QAED,MAAM,CAAC,MAAM,CACZ,YAAY,CAAC,UAAU,wBAEvB,kBAAkB,CAClB,CAAC;QAEF,OAAO,eAAe,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;IACnD,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ArrayHelper, Guards, Is, type IValidationFailure } from \"@twin.org/core\";\nimport { DataTypeHelper, type ValidationMode } from \"@twin.org/data-core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { JsonLdProcessor } from \"./jsonLdProcessor.js\";\nimport type { IJsonLdDocument } from \"../models/IJsonLdDocument.js\";\nimport type { IJsonLdNodeObject } from \"../models/IJsonLdNodeObject.js\";\nimport type { IJsonLdNodePrimitive } from \"../models/IJsonLdNodePrimitive.js\";\n\n/**\n * Class to help with JSON LD.\n */\nexport class JsonLdHelper {\n\t/**\n\t * The class name.\n\t * @internal\n\t */\n\tpublic static readonly CLASS_NAME = nameof<JsonLdHelper>();\n\n\t/**\n\t * Validate a JSON-LD document.\n\t * @param document The JSON-LD document to validate.\n\t * @param validationFailures The list of validation failures to add to.\n\t * @param options Optional options for validation.\n\t * @param options.failOnMissingType If true, will fail validation if the data type is missing, defaults to false.\n\t * @param options.validationMode The validation mode to use, defaults to either.\n\t * @returns True if the document was valid.\n\t */\n\tpublic static async validate<T extends IJsonLdDocument = IJsonLdDocument>(\n\t\tdocument: T,\n\t\tvalidationFailures: IValidationFailure[],\n\t\toptions?: {\n\t\t\tvalidationMode?: ValidationMode;\n\t\t\tfailOnMissingType?: boolean;\n\t\t}\n\t): Promise<boolean> {\n\t\tif (Is.array<IJsonLdNodeObject>(document)) {\n\t\t\t// If the document is an array of nodes, validate each node\n\t\t\tfor (const node of document) {\n\t\t\t\tawait JsonLdHelper.validate(node, validationFailures, options);\n\t\t\t}\n\t\t} else if (Is.array<IJsonLdNodeObject>(document[\"@graph\"])) {\n\t\t\t// If the graph is an array of nodes, validate each node\n\t\t\tfor (const node of document[\"@graph\"]) {\n\t\t\t\tawait JsonLdHelper.validate(node, validationFailures, options);\n\t\t\t}\n\t\t} else if (Is.object<IJsonLdNodeObject>(document)) {\n\t\t\t// Expand the document to ensure we have the full context for types\n\t\t\t// As the data types in the factories are always fully qualified\n\t\t\tconst expandedDocs = await JsonLdProcessor.expand(document);\n\t\t\tif (Is.arrayValue(expandedDocs)) {\n\t\t\t\tfor (const expandedDoc of expandedDocs) {\n\t\t\t\t\tconst expandedDataTypes = ArrayHelper.fromObjectOrArray(expandedDoc[\"@type\"]);\n\t\t\t\t\tif (Is.arrayValue(expandedDataTypes)) {\n\t\t\t\t\t\tfor (const expandedDataType of expandedDataTypes) {\n\t\t\t\t\t\t\tawait DataTypeHelper.validate(\n\t\t\t\t\t\t\t\t\"document\",\n\t\t\t\t\t\t\t\texpandedDataType,\n\t\t\t\t\t\t\t\tdocument,\n\t\t\t\t\t\t\t\tvalidationFailures,\n\t\t\t\t\t\t\t\toptions\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn validationFailures.length === 0;\n\t}\n\n\t/**\n\t * Expand an object to a JSON-LD node object.\n\t * @param object The object to expand.\n\t * @returns The expanded JSON-LD node object.\n\t */\n\tpublic static toNodeObject<T = unknown>(object: T): T & IJsonLdNodeObject {\n\t\tGuards.object<T>(JsonLdHelper.CLASS_NAME, nameof(object), object);\n\t\treturn object as T & IJsonLdNodeObject;\n\t}\n\n\t/**\n\t * Expand the JSON-LD document.\n\t * @param document The JSON-LD document to expand.\n\t * @returns The expanded JSON-LD document.\n\t */\n\tpublic static async expand(document: IJsonLdDocument): Promise<IJsonLdNodeObject[]> {\n\t\tGuards.object<IJsonLdDocument>(JsonLdHelper.CLASS_NAME, nameof(document), document);\n\t\treturn JsonLdProcessor.expand(document);\n\t}\n\n\t/**\n\t * Expand the JSON-LD document and check if it is of a specific type.\n\t * @param documentOrExpanded The JSON-LD document to check or already expanded document.\n\t * @param type The type to check for.\n\t * @returns True if the document is of the specified type.\n\t */\n\tpublic static async isType(\n\t\tdocumentOrExpanded: IJsonLdDocument | IJsonLdNodeObject[],\n\t\ttype: string[]\n\t): Promise<boolean> {\n\t\tconst expanded = await JsonLdHelper.getExpandedDocument(documentOrExpanded);\n\t\tGuards.arrayValue(JsonLdHelper.CLASS_NAME, nameof(type), type);\n\n\t\tif (Is.arrayValue(expanded)) {\n\t\t\tfor (const item of expanded) {\n\t\t\t\tconst types = ArrayHelper.fromObjectOrArray(item[\"@type\"]);\n\t\t\t\tif (Is.arrayValue(types)) {\n\t\t\t\t\t// All required types must be present in this item's @type array\n\t\t\t\t\tconst itemTypes = new Set(types);\n\t\t\t\t\tif (type.every(t => itemTypes.has(t))) {\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn false;\n\t}\n\n\t/**\n\t * Get the types from the document.\n\t * @param documentOrExpanded The JSON-LD document to check or already expanded document.\n\t * @returns The type(s) extracted from the document.\n\t */\n\tpublic static async getType(\n\t\tdocumentOrExpanded: IJsonLdDocument | IJsonLdNodeObject[]\n\t): Promise<string[]> {\n\t\tconst expanded = await JsonLdHelper.getExpandedDocument(documentOrExpanded);\n\n\t\tconst types: Set<string> = new Set<string>();\n\t\tconst props = [\"@type\", \"type\"];\n\n\t\tfor (const expandedDoc of expanded) {\n\t\t\tfor (const prop of props) {\n\t\t\t\tconst expandedProps = ArrayHelper.fromObjectOrArray(expandedDoc[prop]);\n\t\t\t\tif (Is.arrayValue(expandedProps)) {\n\t\t\t\t\tfor (const expandedProp of expandedProps) {\n\t\t\t\t\t\tconst arr = ArrayHelper.fromObjectOrArray(expandedProp);\n\t\t\t\t\t\tfor (const arrValue of arr) {\n\t\t\t\t\t\t\tif (Is.stringValue(arrValue)) {\n\t\t\t\t\t\t\t\ttypes.add(arrValue);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn Array.from(types);\n\t}\n\n\t/**\n\t * Get the id from the document.\n\t * @param documentOrExpanded The JSON-LD document to get the id from or already expanded document.\n\t * @returns The id extracted from the document.\n\t */\n\tpublic static async getId(\n\t\tdocumentOrExpanded: IJsonLdDocument | IJsonLdNodeObject[]\n\t): Promise<string | undefined> {\n\t\tconst expanded = await JsonLdHelper.getExpandedDocument(documentOrExpanded);\n\n\t\tconst props = [\"@id\", \"id\"];\n\n\t\tfor (const expandedDoc of expanded) {\n\t\t\tfor (const prop of props) {\n\t\t\t\tconst expandedProps = ArrayHelper.fromObjectOrArray(expandedDoc[prop]);\n\t\t\t\tif (Is.arrayValue(expandedProps)) {\n\t\t\t\t\tfor (const expandedProp of expandedProps) {\n\t\t\t\t\t\tconst arr = ArrayHelper.fromObjectOrArray(expandedProp);\n\t\t\t\t\t\tfor (const arrValue of arr) {\n\t\t\t\t\t\t\tif (Is.stringValue(arrValue)) {\n\t\t\t\t\t\t\t\treturn arrValue;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Get property values by a single full expanded property name.\n\t * @param documentOrExpanded The JSON-LD document to get the property from or already expanded document.\n\t * @param propertyFullName The full expanded property name.\n\t * @param language Optional filter values by their language property.\n\t * @returns Matching property values for the input property.\n\t */\n\tpublic static async getPropertyValue(\n\t\tdocumentOrExpanded: IJsonLdDocument | IJsonLdNodeObject[],\n\t\tpropertyFullName: string,\n\t\tlanguage?: string\n\t): Promise<IJsonLdNodePrimitive[] | undefined> {\n\t\tconst results = await JsonLdHelper.getPropertyValues(\n\t\t\tdocumentOrExpanded,\n\t\t\t[propertyFullName],\n\t\t\tlanguage\n\t\t);\n\n\t\treturn results[0];\n\t}\n\n\t/**\n\t * Get property values by their full expanded property names.\n\t * @param documentOrExpanded The JSON-LD document to get the property from or already expanded document.\n\t * @param propertyFullNames The full expanded property names.\n\t * @param language Optional filter values by their language property.\n\t * @returns Matching property values for each input property, in the same index order.\n\t */\n\tpublic static async getPropertyValues(\n\t\tdocumentOrExpanded: IJsonLdDocument | IJsonLdNodeObject[],\n\t\tpropertyFullNames: string[],\n\t\tlanguage?: string\n\t): Promise<(IJsonLdNodePrimitive[] | undefined)[]> {\n\t\tconst expanded = await JsonLdHelper.getExpandedDocument(documentOrExpanded);\n\n\t\tGuards.arrayValue(JsonLdHelper.CLASS_NAME, nameof(propertyFullNames), propertyFullNames);\n\t\tif (Is.stringValue(language)) {\n\t\t\tGuards.stringValue(JsonLdHelper.CLASS_NAME, nameof(language), language);\n\t\t}\n\t\tconst languageLower = Is.stringValue(language) ? language.toLowerCase() : undefined;\n\t\tconst result: (IJsonLdNodePrimitive[] | undefined)[] = [];\n\n\t\tfor (const propertyFullName of propertyFullNames) {\n\t\t\tGuards.stringValue(JsonLdHelper.CLASS_NAME, nameof(propertyFullName), propertyFullName);\n\t\t\tconst values: IJsonLdNodePrimitive[] = [];\n\n\t\t\tfor (const expandedDoc of expanded) {\n\t\t\t\tconst propValue = expandedDoc[propertyFullName];\n\t\t\t\tif (!Is.empty(propValue)) {\n\t\t\t\t\tconst expandedProps = ArrayHelper.fromObjectOrArray(propValue);\n\t\t\t\t\tif (Is.arrayValue(expandedProps)) {\n\t\t\t\t\t\tfor (const expandedProp of expandedProps) {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tIs.object<{ \"@value\"?: IJsonLdNodePrimitive; \"@language\"?: string }>(expandedProp)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tif (!Is.empty(expandedProp[\"@value\"])) {\n\t\t\t\t\t\t\t\t\tlet shouldAdd = true;\n\t\t\t\t\t\t\t\t\tif (Is.stringValue(languageLower)) {\n\t\t\t\t\t\t\t\t\t\tconst itemLanguage = Is.stringValue(expandedProp[\"@language\"])\n\t\t\t\t\t\t\t\t\t\t\t? expandedProp[\"@language\"].toLowerCase()\n\t\t\t\t\t\t\t\t\t\t\t: undefined;\n\t\t\t\t\t\t\t\t\t\tshouldAdd = itemLanguage === languageLower;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif (shouldAdd) {\n\t\t\t\t\t\t\t\t\t\tvalues.push(expandedProp[\"@value\"]);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} else if (!Is.stringValue(languageLower)) {\n\t\t\t\t\t\t\t\t\tvalues.push(expandedProp);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\t\tIs.stringValue(expandedProp) ||\n\t\t\t\t\t\t\t\tIs.boolean(expandedProp) ||\n\t\t\t\t\t\t\t\tIs.number(expandedProp)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tif (!Is.stringValue(languageLower)) {\n\t\t\t\t\t\t\t\t\tvalues.push(expandedProp);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tresult.push(values.length > 0 ? values : undefined);\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t/**\n\t * Prefix all properties in the document with the provided prefix, except for JSON-LD properties.\n\t * This is useful for ensuring that all properties are fully qualified with a namespace.\n\t * For example, if the prefix is \"ex\" and the document has a property \"name\", it will be transformed to \"ex:name\".\n\t * @param nodeObject The JSON-LD node object to prefix properties on.\n\t * @param prefix The prefix to add to the properties.\n\t * @param properties Optional list of properties to prefix. If not provided, all properties except for JSON-LD properties.\n\t * @returns A new JSON-LD node object with the properties prefixed.\n\t */\n\tpublic static prefixProperties<T extends IJsonLdNodeObject>(\n\t\tnodeObject: T,\n\t\tprefix: string,\n\t\tproperties?: string[]\n\t): IJsonLdNodeObject {\n\t\tGuards.object<IJsonLdNodeObject>(JsonLdHelper.CLASS_NAME, nameof(nodeObject), nodeObject);\n\t\tGuards.stringValue(JsonLdHelper.CLASS_NAME, nameof(prefix), prefix);\n\t\tconst normalizedPrefix = prefix.endsWith(\":\") ? prefix.slice(0, -1) : prefix;\n\t\tconst hasNoPropertiesFilter = !Is.arrayValue(properties);\n\n\t\tconst prefixedNodeObject: IJsonLdNodeObject = {};\n\n\t\tfor (const key in nodeObject) {\n\t\t\tconst value = nodeObject[key];\n\t\t\tif (\n\t\t\t\tIs.stringValue(key) &&\n\t\t\t\t!key.startsWith(\"@\") &&\n\t\t\t\t(hasNoPropertiesFilter || properties.includes(key))\n\t\t\t) {\n\t\t\t\tprefixedNodeObject[`${normalizedPrefix}:${key}`] = value;\n\t\t\t} else {\n\t\t\t\tprefixedNodeObject[key] = value;\n\t\t\t}\n\t\t}\n\n\t\treturn prefixedNodeObject;\n\t}\n\n\t/**\n\t * Strip a prefix from properties in the document, except for JSON-LD properties.\n\t * This is useful for converting fully qualified namespaced properties back to local names.\n\t * For example, if the prefix is \"ex\" and the document has a property \"ex:name\", it will be transformed to \"name\".\n\t * @param nodeObject The JSON-LD node object to strip prefixed properties from.\n\t * @param prefix The prefix to remove from the properties.\n\t * @param properties Optional list of unprefixed properties to strip. If not provided, all matching prefixed properties.\n\t * @returns A new JSON-LD node object with the prefix stripped from matching properties.\n\t */\n\tpublic static stripPrefixProperties<T extends IJsonLdNodeObject>(\n\t\tnodeObject: T,\n\t\tprefix: string,\n\t\tproperties?: string[]\n\t): IJsonLdNodeObject {\n\t\tGuards.object<IJsonLdNodeObject>(JsonLdHelper.CLASS_NAME, nameof(nodeObject), nodeObject);\n\t\tGuards.stringValue(JsonLdHelper.CLASS_NAME, nameof(prefix), prefix);\n\t\tconst normalizedPrefix = prefix.endsWith(\":\") ? prefix.slice(0, -1) : prefix;\n\t\tconst hasNoPropertiesFilter = !Is.arrayValue(properties);\n\n\t\tconst strippedNodeObject: IJsonLdNodeObject = {};\n\n\t\tfor (const key in nodeObject) {\n\t\t\tconst value = nodeObject[key];\n\t\t\tif (Is.stringValue(key) && !key.startsWith(\"@\") && key.startsWith(`${normalizedPrefix}:`)) {\n\t\t\t\tconst strippedKey = key.slice(normalizedPrefix.length + 1);\n\t\t\t\tif (hasNoPropertiesFilter || properties.includes(strippedKey)) {\n\t\t\t\t\tstrippedNodeObject[strippedKey] = value;\n\t\t\t\t} else {\n\t\t\t\t\tstrippedNodeObject[key] = value;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstrippedNodeObject[key] = value;\n\t\t\t}\n\t\t}\n\n\t\treturn strippedNodeObject;\n\t}\n\n\t/**\n\t * Get an expanded JSON-LD document from either compact or expanded input.\n\t * @param documentOrExpanded The JSON-LD document or expanded document.\n\t * @returns The expanded JSON-LD document.\n\t * @internal\n\t */\n\tprivate static async getExpandedDocument(\n\t\tdocumentOrExpanded: IJsonLdDocument | IJsonLdNodeObject[]\n\t): Promise<IJsonLdNodeObject[]> {\n\t\tif (Is.array<IJsonLdNodeObject>(documentOrExpanded)) {\n\t\t\tGuards.array<IJsonLdNodeObject>(\n\t\t\t\tJsonLdHelper.CLASS_NAME,\n\t\t\t\tnameof(documentOrExpanded),\n\t\t\t\tdocumentOrExpanded\n\t\t\t);\n\n\t\t\treturn documentOrExpanded;\n\t\t}\n\n\t\tGuards.object<IJsonLdDocument>(\n\t\t\tJsonLdHelper.CLASS_NAME,\n\t\t\tnameof(documentOrExpanded),\n\t\t\tdocumentOrExpanded\n\t\t);\n\n\t\treturn JsonLdProcessor.expand(documentOrExpanded);\n\t}\n}\n"]}
1
+ {"version":3,"file":"jsonLdHelper.js","sourceRoot":"","sources":["../../../src/utils/jsonLdHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE,EAA2B,MAAM,gBAAgB,CAAC;AAClF,OAAO,EAAE,cAAc,EAAuB,MAAM,qBAAqB,CAAC;AAE1E,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAKvD;;GAEG;AACH,MAAM,OAAO,YAAY;IACxB;;;OAGG;IACI,MAAM,CAAU,UAAU,kBAA0B;IAE3D;;;;;;;;OAQG;IACI,MAAM,CAAC,KAAK,CAAC,QAAQ,CAC3B,QAAW,EACX,kBAAwC,EACxC,OAGC;QAED,IAAI,EAAE,CAAC,KAAK,CAAoB,QAAQ,CAAC,EAAE,CAAC;YAC3C,2DAA2D;YAC3D,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;gBAC7B,MAAM,YAAY,CAAC,QAAQ,CAAC,IAAI,EAAE,kBAAkB,EAAE,OAAO,CAAC,CAAC;YAChE,CAAC;QACF,CAAC;aAAM,IAAI,EAAE,CAAC,KAAK,CAAoB,QAAQ,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;YAC5D,wDAAwD;YACxD,KAAK,MAAM,IAAI,IAAI,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACvC,MAAM,YAAY,CAAC,QAAQ,CAAC,IAAI,EAAE,kBAAkB,EAAE,OAAO,CAAC,CAAC;YAChE,CAAC;QACF,CAAC;aAAM,IAAI,EAAE,CAAC,MAAM,CAAoB,QAAQ,CAAC,EAAE,CAAC;YACnD,mEAAmE;YACnE,gEAAgE;YAChE,MAAM,YAAY,GAAG,MAAM,eAAe,CAAC,MAAM,CAAC,Q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AED,MAAM,CAAC,MAAM,CACZ,YAAY,CAAC,UAAU,wBAEvB,kBAAkB,CAClB,CAAC;QAEF,OAAO,eAAe,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;IACnD,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ArrayHelper, Guards, Is, type IValidationFailure } from \"@twin.org/core\";\nimport { DataTypeHelper, type ValidationMode } from \"@twin.org/data-core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { JsonLdProcessor } from \"./jsonLdProcessor.js\";\nimport type { IJsonLdDocument } from \"../models/IJsonLdDocument.js\";\nimport type { IJsonLdNodeObject } from \"../models/IJsonLdNodeObject.js\";\nimport type { IJsonLdNodePrimitive } from \"../models/IJsonLdNodePrimitive.js\";\n\n/**\n * Class to help with JSON LD.\n */\nexport class JsonLdHelper {\n\t/**\n\t * The class name.\n\t * @internal\n\t */\n\tpublic static readonly CLASS_NAME = nameof<JsonLdHelper>();\n\n\t/**\n\t * Validate a JSON-LD document.\n\t * @param document The JSON-LD document to validate.\n\t * @param validationFailures The list of validation failures to add to.\n\t * @param options Optional options for validation.\n\t * @param options.failOnMissingType If true, will fail validation if the data type is missing, defaults to false.\n\t * @param options.validationMode The validation mode to use, defaults to either.\n\t * @returns True if the document was valid.\n\t */\n\tpublic static async validate<T extends IJsonLdDocument = IJsonLdDocument>(\n\t\tdocument: T,\n\t\tvalidationFailures: IValidationFailure[],\n\t\toptions?: {\n\t\t\tvalidationMode?: ValidationMode;\n\t\t\tfailOnMissingType?: boolean;\n\t\t}\n\t): Promise<boolean> {\n\t\tif (Is.array<IJsonLdNodeObject>(document)) {\n\t\t\t// If the document is an array of nodes, validate each node\n\t\t\tfor (const node of document) {\n\t\t\t\tawait JsonLdHelper.validate(node, validationFailures, options);\n\t\t\t}\n\t\t} else if (Is.array<IJsonLdNodeObject>(document[\"@graph\"])) {\n\t\t\t// If the graph is an array of nodes, validate each node\n\t\t\tfor (const node of document[\"@graph\"]) {\n\t\t\t\tawait JsonLdHelper.validate(node, validationFailures, options);\n\t\t\t}\n\t\t} else if (Is.object<IJsonLdNodeObject>(document)) {\n\t\t\t// Expand the document to ensure we have the full context for types\n\t\t\t// As the data types in the factories are always fully qualified\n\t\t\tconst expandedDocs = await JsonLdProcessor.expand(document);\n\t\t\tif (Is.arrayValue(expandedDocs)) {\n\t\t\t\tfor (const expandedDoc of expandedDocs) {\n\t\t\t\t\tconst expandedDataTypes = ArrayHelper.fromObjectOrArray(expandedDoc[\"@type\"]);\n\t\t\t\t\tif (Is.arrayValue(expandedDataTypes)) {\n\t\t\t\t\t\tfor (const expandedDataType of expandedDataTypes) {\n\t\t\t\t\t\t\tawait DataTypeHelper.validate(\n\t\t\t\t\t\t\t\t\"document\",\n\t\t\t\t\t\t\t\texpandedDataType,\n\t\t\t\t\t\t\t\tdocument,\n\t\t\t\t\t\t\t\tvalidationFailures,\n\t\t\t\t\t\t\t\toptions\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn validationFailures.length === 0;\n\t}\n\n\t/**\n\t * Expand an object to a JSON-LD node object.\n\t * @param object The object to expand.\n\t * @returns The expanded JSON-LD node object.\n\t */\n\tpublic static toNodeObject<T = unknown>(object: T): T & IJsonLdNodeObject {\n\t\tGuards.object<T>(JsonLdHelper.CLASS_NAME, nameof(object), object);\n\t\treturn object as T & IJsonLdNodeObject;\n\t}\n\n\t/**\n\t * Expand the JSON-LD document.\n\t * @param document The JSON-LD document to expand.\n\t * @returns The expanded JSON-LD document.\n\t */\n\tpublic static async expand(document: IJsonLdDocument): Promise<IJsonLdNodeObject[]> {\n\t\tGuards.object<IJsonLdDocument>(JsonLdHelper.CLASS_NAME, nameof(document), document);\n\t\treturn JsonLdProcessor.expand(document);\n\t}\n\n\t/**\n\t * Expand the JSON-LD document and check if it is of a specific type.\n\t * @param documentOrExpanded The JSON-LD document to check or already expanded document.\n\t * @param type The type to check for.\n\t * @returns True if the document is of the specified type.\n\t */\n\tpublic static async isType(\n\t\tdocumentOrExpanded: IJsonLdDocument | IJsonLdNodeObject[],\n\t\ttype: string[]\n\t): Promise<boolean> {\n\t\tconst expanded = await JsonLdHelper.getExpandedDocument(documentOrExpanded);\n\t\tGuards.arrayValue(JsonLdHelper.CLASS_NAME, nameof(type), type);\n\n\t\tif (Is.arrayValue(expanded)) {\n\t\t\tfor (const item of expanded) {\n\t\t\t\tconst types = ArrayHelper.fromObjectOrArray(item[\"@type\"]);\n\t\t\t\tif (Is.arrayValue(types)) {\n\t\t\t\t\t// All required types must be present in this item's @type array\n\t\t\t\t\tconst itemTypes = new Set(types);\n\t\t\t\t\tif (type.every(t => itemTypes.has(t))) {\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn false;\n\t}\n\n\t/**\n\t * Get the types from the document.\n\t * @param documentOrExpanded The JSON-LD document to check or already expanded document.\n\t * @returns The type(s) extracted from the document.\n\t */\n\tpublic static async getType(\n\t\tdocumentOrExpanded: IJsonLdDocument | IJsonLdNodeObject[]\n\t): Promise<string[]> {\n\t\tconst expanded = await JsonLdHelper.getExpandedDocument(documentOrExpanded);\n\n\t\tconst types: Set<string> = new Set<string>();\n\t\tconst props = [\"@type\", \"type\"];\n\n\t\tfor (const expandedDoc of expanded) {\n\t\t\tfor (const prop of props) {\n\t\t\t\tconst expandedProps = ArrayHelper.fromObjectOrArray(expandedDoc[prop]);\n\t\t\t\tif (Is.arrayValue(expandedProps)) {\n\t\t\t\t\tfor (const expandedProp of expandedProps) {\n\t\t\t\t\t\tconst arr = ArrayHelper.fromObjectOrArray(expandedProp);\n\t\t\t\t\t\tfor (const arrValue of arr) {\n\t\t\t\t\t\t\tif (Is.stringValue(arrValue)) {\n\t\t\t\t\t\t\t\ttypes.add(arrValue);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn Array.from(types);\n\t}\n\n\t/**\n\t * Get the id from the document.\n\t * @param documentOrExpanded The JSON-LD document to get the id from or already expanded document.\n\t * @param additionalIdProperties Optional additional properties to check for the id, in addition to \"@id\" and \"id\".\n\t * @returns The id extracted from the document.\n\t */\n\tpublic static async getId(\n\t\tdocumentOrExpanded: IJsonLdDocument | IJsonLdNodeObject[],\n\t\tadditionalIdProperties?: string[]\n\t): Promise<string | undefined> {\n\t\tconst expanded = await JsonLdHelper.getExpandedDocument(documentOrExpanded);\n\n\t\tconst props = [\"@id\", \"id\", ...(additionalIdProperties ?? [])];\n\n\t\tfor (const expandedDoc of expanded) {\n\t\t\tfor (const prop of props) {\n\t\t\t\tconst expandedProps = ArrayHelper.fromObjectOrArray(expandedDoc[prop]);\n\t\t\t\tif (Is.arrayValue(expandedProps)) {\n\t\t\t\t\tfor (const expandedProp of expandedProps) {\n\t\t\t\t\t\tconst arr = ArrayHelper.fromObjectOrArray(expandedProp);\n\t\t\t\t\t\tfor (const arrValue of arr) {\n\t\t\t\t\t\t\tif (Is.stringValue(arrValue)) {\n\t\t\t\t\t\t\t\treturn arrValue;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Get property values by a single full expanded property name.\n\t * @param documentOrExpanded The JSON-LD document to get the property from or already expanded document.\n\t * @param propertyFullName The full expanded property name.\n\t * @param language Optional filter values by their language property.\n\t * @returns Matching property values for the input property.\n\t */\n\tpublic static async getPropertyValue(\n\t\tdocumentOrExpanded: IJsonLdDocument | IJsonLdNodeObject[],\n\t\tpropertyFullName: string,\n\t\tlanguage?: string\n\t): Promise<IJsonLdNodePrimitive[] | undefined> {\n\t\tconst results = await JsonLdHelper.getPropertyValues(\n\t\t\tdocumentOrExpanded,\n\t\t\t[propertyFullName],\n\t\t\tlanguage\n\t\t);\n\n\t\treturn results[0];\n\t}\n\n\t/**\n\t * Get property values by their full expanded property names.\n\t * @param documentOrExpanded The JSON-LD document to get the property from or already expanded document.\n\t * @param propertyFullNames The full expanded property names.\n\t * @param language Optional filter values by their language property.\n\t * @returns Matching property values for each input property, in the same index order.\n\t */\n\tpublic static async getPropertyValues(\n\t\tdocumentOrExpanded: IJsonLdDocument | IJsonLdNodeObject[],\n\t\tpropertyFullNames: string[],\n\t\tlanguage?: string\n\t): Promise<(IJsonLdNodePrimitive[] | undefined)[]> {\n\t\tconst expanded = await JsonLdHelper.getExpandedDocument(documentOrExpanded);\n\n\t\tGuards.arrayValue(JsonLdHelper.CLASS_NAME, nameof(propertyFullNames), propertyFullNames);\n\t\tif (Is.stringValue(language)) {\n\t\t\tGuards.stringValue(JsonLdHelper.CLASS_NAME, nameof(language), language);\n\t\t}\n\t\tconst languageLower = Is.stringValue(language) ? language.toLowerCase() : undefined;\n\t\tconst result: (IJsonLdNodePrimitive[] | undefined)[] = [];\n\n\t\tfor (const propertyFullName of propertyFullNames) {\n\t\t\tGuards.stringValue(JsonLdHelper.CLASS_NAME, nameof(propertyFullName), propertyFullName);\n\t\t\tconst values: IJsonLdNodePrimitive[] = [];\n\n\t\t\tfor (const expandedDoc of expanded) {\n\t\t\t\tconst propValue = expandedDoc[propertyFullName];\n\t\t\t\tif (!Is.empty(propValue)) {\n\t\t\t\t\tconst expandedProps = ArrayHelper.fromObjectOrArray(propValue);\n\t\t\t\t\tif (Is.arrayValue(expandedProps)) {\n\t\t\t\t\t\tfor (const expandedProp of expandedProps) {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tIs.object<{ \"@value\"?: IJsonLdNodePrimitive; \"@language\"?: string }>(expandedProp)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tif (!Is.empty(expandedProp[\"@value\"])) {\n\t\t\t\t\t\t\t\t\tlet shouldAdd = true;\n\t\t\t\t\t\t\t\t\tif (Is.stringValue(languageLower)) {\n\t\t\t\t\t\t\t\t\t\tconst itemLanguage = Is.stringValue(expandedProp[\"@language\"])\n\t\t\t\t\t\t\t\t\t\t\t? expandedProp[\"@language\"].toLowerCase()\n\t\t\t\t\t\t\t\t\t\t\t: undefined;\n\t\t\t\t\t\t\t\t\t\tshouldAdd = itemLanguage === languageLower;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif (shouldAdd) {\n\t\t\t\t\t\t\t\t\t\tvalues.push(expandedProp[\"@value\"]);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} else if (!Is.stringValue(languageLower)) {\n\t\t\t\t\t\t\t\t\tvalues.push(expandedProp);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\t\tIs.stringValue(expandedProp) ||\n\t\t\t\t\t\t\t\tIs.boolean(expandedProp) ||\n\t\t\t\t\t\t\t\tIs.number(expandedProp)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tif (!Is.stringValue(languageLower)) {\n\t\t\t\t\t\t\t\t\tvalues.push(expandedProp);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tresult.push(values.length > 0 ? values : undefined);\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t/**\n\t * Prefix all properties in the document with the provided prefix, except for JSON-LD properties.\n\t * This is useful for ensuring that all properties are fully qualified with a namespace.\n\t * For example, if the prefix is \"ex\" and the document has a property \"name\", it will be transformed to \"ex:name\".\n\t * @param nodeObject The JSON-LD node object to prefix properties on.\n\t * @param prefix The prefix to add to the properties.\n\t * @param properties Optional list of properties to prefix. If not provided, all properties except for JSON-LD properties.\n\t * @returns A new JSON-LD node object with the properties prefixed.\n\t */\n\tpublic static prefixProperties<T extends IJsonLdNodeObject>(\n\t\tnodeObject: T,\n\t\tprefix: string,\n\t\tproperties?: string[]\n\t): IJsonLdNodeObject {\n\t\tGuards.object<IJsonLdNodeObject>(JsonLdHelper.CLASS_NAME, nameof(nodeObject), nodeObject);\n\t\tGuards.stringValue(JsonLdHelper.CLASS_NAME, nameof(prefix), prefix);\n\t\tconst normalizedPrefix = prefix.endsWith(\":\") ? prefix.slice(0, -1) : prefix;\n\t\tconst hasNoPropertiesFilter = !Is.arrayValue(properties);\n\n\t\tconst prefixedNodeObject: IJsonLdNodeObject = {};\n\n\t\tfor (const key in nodeObject) {\n\t\t\tconst value = nodeObject[key];\n\t\t\tif (\n\t\t\t\tIs.stringValue(key) &&\n\t\t\t\t!key.startsWith(\"@\") &&\n\t\t\t\t(hasNoPropertiesFilter || properties.includes(key))\n\t\t\t) {\n\t\t\t\tprefixedNodeObject[`${normalizedPrefix}:${key}`] = value;\n\t\t\t} else {\n\t\t\t\tprefixedNodeObject[key] = value;\n\t\t\t}\n\t\t}\n\n\t\treturn prefixedNodeObject;\n\t}\n\n\t/**\n\t * Strip a prefix from properties in the document, except for JSON-LD properties.\n\t * This is useful for converting fully qualified namespaced properties back to local names.\n\t * For example, if the prefix is \"ex\" and the document has a property \"ex:name\", it will be transformed to \"name\".\n\t * @param nodeObject The JSON-LD node object to strip prefixed properties from.\n\t * @param prefix The prefix to remove from the properties.\n\t * @param properties Optional list of unprefixed properties to strip. If not provided, all matching prefixed properties.\n\t * @returns A new JSON-LD node object with the prefix stripped from matching properties.\n\t */\n\tpublic static stripPrefixProperties<T extends IJsonLdNodeObject>(\n\t\tnodeObject: T,\n\t\tprefix: string,\n\t\tproperties?: string[]\n\t): IJsonLdNodeObject {\n\t\tGuards.object<IJsonLdNodeObject>(JsonLdHelper.CLASS_NAME, nameof(nodeObject), nodeObject);\n\t\tGuards.stringValue(JsonLdHelper.CLASS_NAME, nameof(prefix), prefix);\n\t\tconst normalizedPrefix = prefix.endsWith(\":\") ? prefix.slice(0, -1) : prefix;\n\t\tconst hasNoPropertiesFilter = !Is.arrayValue(properties);\n\n\t\tconst strippedNodeObject: IJsonLdNodeObject = {};\n\n\t\tfor (const key in nodeObject) {\n\t\t\tconst value = nodeObject[key];\n\t\t\tif (Is.stringValue(key) && !key.startsWith(\"@\") && key.startsWith(`${normalizedPrefix}:`)) {\n\t\t\t\tconst strippedKey = key.slice(normalizedPrefix.length + 1);\n\t\t\t\tif (hasNoPropertiesFilter || properties.includes(strippedKey)) {\n\t\t\t\t\tstrippedNodeObject[strippedKey] = value;\n\t\t\t\t} else {\n\t\t\t\t\tstrippedNodeObject[key] = value;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstrippedNodeObject[key] = value;\n\t\t\t}\n\t\t}\n\n\t\treturn strippedNodeObject;\n\t}\n\n\t/**\n\t * Get an expanded JSON-LD document from either compact or expanded input.\n\t * @param documentOrExpanded The JSON-LD document or expanded document.\n\t * @returns The expanded JSON-LD document.\n\t * @internal\n\t */\n\tprivate static async getExpandedDocument(\n\t\tdocumentOrExpanded: IJsonLdDocument | IJsonLdNodeObject[]\n\t): Promise<IJsonLdNodeObject[]> {\n\t\tif (Is.array<IJsonLdNodeObject>(documentOrExpanded)) {\n\t\t\tGuards.array<IJsonLdNodeObject>(\n\t\t\t\tJsonLdHelper.CLASS_NAME,\n\t\t\t\tnameof(documentOrExpanded),\n\t\t\t\tdocumentOrExpanded\n\t\t\t);\n\n\t\t\treturn documentOrExpanded;\n\t\t}\n\n\t\tGuards.object<IJsonLdDocument>(\n\t\t\tJsonLdHelper.CLASS_NAME,\n\t\t\tnameof(documentOrExpanded),\n\t\t\tdocumentOrExpanded\n\t\t);\n\n\t\treturn JsonLdProcessor.expand(documentOrExpanded);\n\t}\n}\n"]}
@@ -48,9 +48,10 @@ export declare class JsonLdHelper {
48
48
  /**
49
49
  * Get the id from the document.
50
50
  * @param documentOrExpanded The JSON-LD document to get the id from or already expanded document.
51
+ * @param additionalIdProperties Optional additional properties to check for the id, in addition to "@id" and "id".
51
52
  * @returns The id extracted from the document.
52
53
  */
53
- static getId(documentOrExpanded: IJsonLdDocument | IJsonLdNodeObject[]): Promise<string | undefined>;
54
+ static getId(documentOrExpanded: IJsonLdDocument | IJsonLdNodeObject[], additionalIdProperties?: string[]): Promise<string | undefined>;
54
55
  /**
55
56
  * Get property values by a single full expanded property name.
56
57
  * @param documentOrExpanded The JSON-LD document to get the property from or already expanded document.
package/docs/changelog.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @twin.org/data-json-ld - Changelog
2
2
 
3
+ ## [0.0.3-next.11](https://github.com/twinfoundation/data/compare/data-json-ld-v0.0.3-next.10...data-json-ld-v0.0.3-next.11) (2026-02-25)
4
+
5
+
6
+ ### Features
7
+
8
+ * expand JsonLdHelper.getId with custom properties names ([8ec4dcf](https://github.com/twinfoundation/data/commit/8ec4dcf807a6dc416b2df2a77749f841a60be05f))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/data-core bumped from 0.0.3-next.10 to 0.0.3-next.11
16
+
3
17
  ## [0.0.3-next.10](https://github.com/twinfoundation/data/compare/data-json-ld-v0.0.3-next.9...data-json-ld-v0.0.3-next.10) (2026-02-24)
4
18
 
5
19
 
@@ -166,7 +166,7 @@ The type(s) extracted from the document.
166
166
 
167
167
  ### getId()
168
168
 
169
- > `static` **getId**(`documentOrExpanded`): `Promise`\<`string` \| `undefined`\>
169
+ > `static` **getId**(`documentOrExpanded`, `additionalIdProperties?`): `Promise`\<`string` \| `undefined`\>
170
170
 
171
171
  Get the id from the document.
172
172
 
@@ -178,6 +178,12 @@ Get the id from the document.
178
178
 
179
179
  The JSON-LD document to get the id from or already expanded document.
180
180
 
181
+ ##### additionalIdProperties?
182
+
183
+ `string`[]
184
+
185
+ Optional additional properties to check for the id, in addition to "@id" and "id".
186
+
181
187
  #### Returns
182
188
 
183
189
  `Promise`\<`string` \| `undefined`\>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/data-json-ld",
3
- "version": "0.0.3-next.10",
3
+ "version": "0.0.3-next.11",
4
4
  "description": "Models which define the structure of JSON LD",
5
5
  "repository": {
6
6
  "type": "git",
@@ -15,7 +15,7 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "@twin.org/core": "next",
18
- "@twin.org/data-core": "0.0.3-next.10",
18
+ "@twin.org/data-core": "0.0.3-next.11",
19
19
  "@twin.org/entity": "next",
20
20
  "@twin.org/nameof": "next",
21
21
  "@twin.org/web": "next",