@twin.org/context 0.9.1 → 0.9.2-next.10
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/dist/es/helpers/contextIdHelper.js +33 -0
- package/dist/es/helpers/contextIdHelper.js.map +1 -1
- package/dist/es/models/IContextIdHandler.js.map +1 -1
- package/dist/types/helpers/contextIdHelper.d.ts +15 -0
- package/dist/types/models/IContextIdHandler.d.ts +6 -0
- package/docs/changelog.md +203 -0
- package/docs/reference/classes/ContextIdHelper.md +60 -0
- package/docs/reference/interfaces/IContextIdHandler.md +22 -18
- package/package.json +3 -3
|
@@ -60,6 +60,39 @@ export class ContextIdHelper {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Gets the long version of a context ID, expanding from a short form if a handler is registered.
|
|
65
|
+
* @param contextIds The context IDs to get the long version from.
|
|
66
|
+
* @param key The context ID key to get the long version for.
|
|
67
|
+
* @returns The long version of the context ID.
|
|
68
|
+
* @throws Guard error if the value is invalid.
|
|
69
|
+
*/
|
|
70
|
+
static long(contextIds, key) {
|
|
71
|
+
Guards.stringValue(ContextIdHelper.CLASS_NAME, "key", key);
|
|
72
|
+
if (Is.undefined(contextIds?.[key])) {
|
|
73
|
+
throw new GeneralError(ContextIdHelper.CLASS_NAME, "contextIdMissing", { key });
|
|
74
|
+
}
|
|
75
|
+
const handler = ContextIdHandlerFactory.getIfExists(key);
|
|
76
|
+
if (handler?.long) {
|
|
77
|
+
return handler.long(contextIds[key]);
|
|
78
|
+
}
|
|
79
|
+
return contextIds[key];
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Gets the long versions of multiple context IDs.
|
|
83
|
+
* @param contextIds The context IDs to get the long versions from.
|
|
84
|
+
* @param keys The context ID keys to get the long versions for.
|
|
85
|
+
* @returns The long versions of the context IDs.
|
|
86
|
+
*/
|
|
87
|
+
static longAll(contextIds, keys) {
|
|
88
|
+
const long = {};
|
|
89
|
+
if (Is.arrayValue(keys)) {
|
|
90
|
+
for (const key of keys) {
|
|
91
|
+
long[key] = ContextIdHelper.long(contextIds, key);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return long;
|
|
95
|
+
}
|
|
63
96
|
/**
|
|
64
97
|
* Gets the short versions of multiple context IDs.
|
|
65
98
|
* @param contextIds The context IDs to get the short versions from.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contextIdHelper.js","sourceRoot":"","sources":["../../../src/helpers/contextIdHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAE1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAGlF;;GAEG;AACH,MAAM,OAAO,eAAe;IAC3B;;OAEG;IACI,MAAM,CAAU,UAAU,qBAAqC;IAEtE;;;;;OAKG;IACI,MAAM,CAAC,KAAK,CAClB,UAAyB,EACzB,GAAM;QAEN,MAAM,CAAC,WAAW,CAAC,eAAe,CAAC,UAAU,SAAe,GAAG,CAAC,CAAC;QAEjE,IAAI,EAAE,CAAC,SAAS,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;YACrC,MAAM,IAAI,YAAY,CAAC,eAAe,CAAC,UAAU,EAAE,kBAAkB,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;QACjF,CAAC;QAED,MAAM,OAAO,GAAG,uBAAuB,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;QACzD,IAAI,OAAO,EAAE,KAAK,EAAE,CAAC;YACpB,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;QAChC,CAAC;aAAM,CAAC;YACP,MAAM,CAAC,WAAW,CAAC,eAAe,CAAC,UAAU,EAAE,cAAc,GAAG,EAAE,EAAE,UAAU,CAAC,GAAG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;OAMG;IACI,MAAM,CAAC,kBAAkB,CAC/B,UAAmC,EACnC,IAA0B,EAC1B,YAAoB,GAAG;QAEvB,eAAe,CAAC,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QAE3C,MAAM,KAAK,GAAG,eAAe,CAAC,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QAEzD,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACrC,OAAO,SAAS,CAAC;QAClB,CAAC;QAED,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC7C,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,qBAAqB,CAAC,aAAwB,EAAE,WAAsB;QACnF,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;YAClE,OAAO,EAAE,CAAC;QACX,CAAC;QAED,OAAO,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/D,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { GeneralError, Guards, Is } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { ContextIdHandlerFactory } from \"../factories/contextIdHandlerFactory.js\";\nimport type { IContextIds } from \"../models/IContextIds.js\";\n\n/**\n * Class to help with context IDs.\n */\nexport class ContextIdHelper {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<ContextIdHelper>();\n\n\t/**\n\t * Perform a runtime guard on the provided context ID value.\n\t * @param contextIds The context IDs to guard.\n\t * @param key The context ID key to guard.\n\t * @throws Guard error if the value is invalid.\n\t */\n\tpublic static guard<T extends { [k: string]: string | undefined }, K extends string>(\n\t\tcontextIds: T | undefined,\n\t\tkey: K\n\t): asserts contextIds is T & { [P in K]: string } {\n\t\tGuards.stringValue(ContextIdHelper.CLASS_NAME, nameof(key), key);\n\n\t\tif (Is.undefined(contextIds?.[key])) {\n\t\t\tthrow new GeneralError(ContextIdHelper.CLASS_NAME, \"contextIdMissing\", { key });\n\t\t}\n\n\t\tconst handler = ContextIdHandlerFactory.getIfExists(key);\n\t\tif (handler?.guard) {\n\t\t\thandler.guard(contextIds[key]);\n\t\t} else {\n\t\t\tGuards.stringValue(ContextIdHelper.CLASS_NAME, `contextIds.${key}`, contextIds[key]);\n\t\t}\n\t}\n\n\t/**\n\t * Gets the short version of a context ID.\n\t * @param contextIds The context IDs to get the short version from.\n\t * @param key The context ID key to get the short version for.\n\t * @returns The short version of the context ID.\n\t * @throws Guard error if the value is invalid.\n\t */\n\tpublic static short(contextIds: IContextIds | undefined, key: string): string {\n\t\tGuards.stringValue(ContextIdHelper.CLASS_NAME, nameof(key), key);\n\t\tif (Is.undefined(contextIds?.[key])) {\n\t\t\tthrow new GeneralError(ContextIdHelper.CLASS_NAME, \"contextIdMissing\", { key });\n\t\t}\n\n\t\tconst handler = ContextIdHandlerFactory.getIfExists(key);\n\t\tif (handler?.short) {\n\t\t\treturn handler.short(contextIds[key]);\n\t\t}\n\t\treturn contextIds[key];\n\t}\n\n\t/**\n\t * Perform a runtime guard on the provided context ID values.\n\t * @param contextIds The context IDs to guard.\n\t * @param keys The context ID keys to guard.\n\t * @throws Guard error if the value is invalid.\n\t */\n\tpublic static guardAll<T extends { [k: string]: string | undefined }, K extends string>(\n\t\tcontextIds: T | undefined,\n\t\tkeys: readonly K[] | undefined\n\t): asserts contextIds is T & { [P in K]: string } {\n\t\tif (Is.arrayValue(keys)) {\n\t\t\tfor (const key of keys) {\n\t\t\t\tContextIdHelper.guard(contextIds, key);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Gets the short versions of multiple context IDs.\n\t * @param contextIds The context IDs to get the short versions from.\n\t * @param keys The context ID keys to get the short versions for.\n\t * @returns The short versions of the context IDs.\n\t */\n\tpublic static shortAll(\n\t\tcontextIds: IContextIds | undefined,\n\t\tkeys: string[] | undefined\n\t): IContextIds {\n\t\tconst short: IContextIds = {};\n\t\tif (Is.arrayValue(keys)) {\n\t\t\tfor (const key of keys) {\n\t\t\t\tshort[key] = ContextIdHelper.short(contextIds, key);\n\t\t\t}\n\t\t}\n\t\treturn short;\n\t}\n\n\t/**\n\t * Gets the combined short version.\n\t * @param contextIds The context IDs to get the short versions from.\n\t * @param keys The context ID keys to get the short versions for.\n\t * @param separator The separator to use between parts.\n\t * @returns The short version combined.\n\t */\n\tpublic static shortCombined(\n\t\tcontextIds: IContextIds | undefined,\n\t\tkeys: string[] | undefined,\n\t\tseparator: string = \"/\"\n\t): string | undefined {\n\t\tconst short = ContextIdHelper.shortAll(contextIds, keys);\n\t\tif (Object.keys(short).length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn Object.values(short).join(separator);\n\t}\n\n\t/**\n\t * Split a combined short version in to the separate context IDs.\n\t * @param keys The context ID keys to get the short versions for.\n\t * @param combined The combined short version to separate.\n\t * @param separator The separator used between parts.\n\t * @returns The short version combined.\n\t * @throws GeneralError if the number of parts does not match the number of keys.\n\t */\n\tpublic static shortSplit(keys: string[], combined: string, separator: string = \"/\"): IContextIds {\n\t\tGuards.arrayValue<string>(ContextIdHelper.CLASS_NAME, nameof(keys), keys);\n\t\tGuards.stringValue(ContextIdHelper.CLASS_NAME, nameof(combined), combined);\n\n\t\tconst parts = combined.split(separator);\n\t\tconst result: IContextIds = {};\n\n\t\tif (parts.length !== keys.length) {\n\t\t\tthrow new GeneralError(ContextIdHelper.CLASS_NAME, \"contextIdSplitMismatch\", {\n\t\t\t\texpected: keys.length,\n\t\t\t\tactual: parts.length\n\t\t\t});\n\t\t}\n\n\t\tfor (let i = 0; i < keys.length; i++) {\n\t\t\tresult[keys[i]] = parts[i];\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t/**\n\t * Create a combined key.\n\t * @param contextIds The context IDs to create the combined key for.\n\t * @param keys The context ID keys to get the short versions for.\n\t * @param separator The separator to use between parts.\n\t * @returns The short version combined.\n\t */\n\tpublic static combinedContextKey(\n\t\tcontextIds: IContextIds | undefined,\n\t\tkeys: string[] | undefined,\n\t\tseparator: string = \"/\"\n\t): string | undefined {\n\t\tContextIdHelper.guardAll(contextIds, keys);\n\n\t\tconst short = ContextIdHelper.shortAll(contextIds, keys);\n\n\t\tif (Object.keys(short).length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn Object.values(short).join(separator);\n\t}\n\n\t/**\n\t * Pick only the desired keys from the available keys.\n\t * @param availableKeys The available keys to pick from.\n\t * @param desiredKeys The desired keys to pick.\n\t * @returns The picked keys.\n\t */\n\tpublic static pickKeysFromAvailable(availableKeys?: string[], desiredKeys?: string[]): string[] {\n\t\tif (!Is.arrayValue(availableKeys) || !Is.arrayValue(desiredKeys)) {\n\t\t\treturn [];\n\t\t}\n\n\t\treturn desiredKeys.filter(key => availableKeys.includes(key));\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"contextIdHelper.js","sourceRoot":"","sources":["../../../src/helpers/contextIdHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAE1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAGlF;;GAEG;AACH,MAAM,OAAO,eAAe;IAC3B;;OAEG;IACI,MAAM,CAAU,UAAU,qBAAqC;IAEtE;;;;;OAKG;IACI,MAAM,CAAC,KAAK,CAClB,UAAyB,EACzB,GAAM;QAEN,MAAM,CAAC,WAAW,CAAC,eAAe,CAAC,UAAU,SAAe,GAAG,CAAC,CAAC;QAEjE,IAAI,EAAE,CAAC,SAAS,CAAC,UAAU,EAAE,CAA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AC;YACtC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QAC5B,CAAC;QAED,OAAO,MAAM,CAAC;IACf,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,kBAAkB,CAC/B,UAAmC,EACnC,IAA0B,EAC1B,YAAoB,GAAG;QAEvB,eAAe,CAAC,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QAE3C,MAAM,KAAK,GAAG,eAAe,CAAC,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QAEzD,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACrC,OAAO,SAAS,CAAC;QAClB,CAAC;QAED,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC7C,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,qBAAqB,CAAC,aAAwB,EAAE,WAAsB;QACnF,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;YAClE,OAAO,EAAE,CAAC;QACX,CAAC;QAED,OAAO,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/D,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { GeneralError, Guards, Is } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { ContextIdHandlerFactory } from \"../factories/contextIdHandlerFactory.js\";\nimport type { IContextIds } from \"../models/IContextIds.js\";\n\n/**\n * Class to help with context IDs.\n */\nexport class ContextIdHelper {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<ContextIdHelper>();\n\n\t/**\n\t * Perform a runtime guard on the provided context ID value.\n\t * @param contextIds The context IDs to guard.\n\t * @param key The context ID key to guard.\n\t * @throws Guard error if the value is invalid.\n\t */\n\tpublic static guard<T extends { [k: string]: string | undefined }, K extends string>(\n\t\tcontextIds: T | undefined,\n\t\tkey: K\n\t): asserts contextIds is T & { [P in K]: string } {\n\t\tGuards.stringValue(ContextIdHelper.CLASS_NAME, nameof(key), key);\n\n\t\tif (Is.undefined(contextIds?.[key])) {\n\t\t\tthrow new GeneralError(ContextIdHelper.CLASS_NAME, \"contextIdMissing\", { key });\n\t\t}\n\n\t\tconst handler = ContextIdHandlerFactory.getIfExists(key);\n\t\tif (handler?.guard) {\n\t\t\thandler.guard(contextIds[key]);\n\t\t} else {\n\t\t\tGuards.stringValue(ContextIdHelper.CLASS_NAME, `contextIds.${key}`, contextIds[key]);\n\t\t}\n\t}\n\n\t/**\n\t * Gets the short version of a context ID.\n\t * @param contextIds The context IDs to get the short version from.\n\t * @param key The context ID key to get the short version for.\n\t * @returns The short version of the context ID.\n\t * @throws Guard error if the value is invalid.\n\t */\n\tpublic static short(contextIds: IContextIds | undefined, key: string): string {\n\t\tGuards.stringValue(ContextIdHelper.CLASS_NAME, nameof(key), key);\n\t\tif (Is.undefined(contextIds?.[key])) {\n\t\t\tthrow new GeneralError(ContextIdHelper.CLASS_NAME, \"contextIdMissing\", { key });\n\t\t}\n\n\t\tconst handler = ContextIdHandlerFactory.getIfExists(key);\n\t\tif (handler?.short) {\n\t\t\treturn handler.short(contextIds[key]);\n\t\t}\n\t\treturn contextIds[key];\n\t}\n\n\t/**\n\t * Perform a runtime guard on the provided context ID values.\n\t * @param contextIds The context IDs to guard.\n\t * @param keys The context ID keys to guard.\n\t * @throws Guard error if the value is invalid.\n\t */\n\tpublic static guardAll<T extends { [k: string]: string | undefined }, K extends string>(\n\t\tcontextIds: T | undefined,\n\t\tkeys: readonly K[] | undefined\n\t): asserts contextIds is T & { [P in K]: string } {\n\t\tif (Is.arrayValue(keys)) {\n\t\t\tfor (const key of keys) {\n\t\t\t\tContextIdHelper.guard(contextIds, key);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Gets the long version of a context ID, expanding from a short form if a handler is registered.\n\t * @param contextIds The context IDs to get the long version from.\n\t * @param key The context ID key to get the long version for.\n\t * @returns The long version of the context ID.\n\t * @throws Guard error if the value is invalid.\n\t */\n\tpublic static long(contextIds: IContextIds | undefined, key: string): string {\n\t\tGuards.stringValue(ContextIdHelper.CLASS_NAME, nameof(key), key);\n\t\tif (Is.undefined(contextIds?.[key])) {\n\t\t\tthrow new GeneralError(ContextIdHelper.CLASS_NAME, \"contextIdMissing\", { key });\n\t\t}\n\n\t\tconst handler = ContextIdHandlerFactory.getIfExists(key);\n\t\tif (handler?.long) {\n\t\t\treturn handler.long(contextIds[key]);\n\t\t}\n\t\treturn contextIds[key];\n\t}\n\n\t/**\n\t * Gets the long versions of multiple context IDs.\n\t * @param contextIds The context IDs to get the long versions from.\n\t * @param keys The context ID keys to get the long versions for.\n\t * @returns The long versions of the context IDs.\n\t */\n\tpublic static longAll(\n\t\tcontextIds: IContextIds | undefined,\n\t\tkeys: string[] | undefined\n\t): IContextIds {\n\t\tconst long: IContextIds = {};\n\t\tif (Is.arrayValue(keys)) {\n\t\t\tfor (const key of keys) {\n\t\t\t\tlong[key] = ContextIdHelper.long(contextIds, key);\n\t\t\t}\n\t\t}\n\t\treturn long;\n\t}\n\n\t/**\n\t * Gets the short versions of multiple context IDs.\n\t * @param contextIds The context IDs to get the short versions from.\n\t * @param keys The context ID keys to get the short versions for.\n\t * @returns The short versions of the context IDs.\n\t */\n\tpublic static shortAll(\n\t\tcontextIds: IContextIds | undefined,\n\t\tkeys: string[] | undefined\n\t): IContextIds {\n\t\tconst short: IContextIds = {};\n\t\tif (Is.arrayValue(keys)) {\n\t\t\tfor (const key of keys) {\n\t\t\t\tshort[key] = ContextIdHelper.short(contextIds, key);\n\t\t\t}\n\t\t}\n\t\treturn short;\n\t}\n\n\t/**\n\t * Gets the combined short version.\n\t * @param contextIds The context IDs to get the short versions from.\n\t * @param keys The context ID keys to get the short versions for.\n\t * @param separator The separator to use between parts.\n\t * @returns The short version combined.\n\t */\n\tpublic static shortCombined(\n\t\tcontextIds: IContextIds | undefined,\n\t\tkeys: string[] | undefined,\n\t\tseparator: string = \"/\"\n\t): string | undefined {\n\t\tconst short = ContextIdHelper.shortAll(contextIds, keys);\n\t\tif (Object.keys(short).length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn Object.values(short).join(separator);\n\t}\n\n\t/**\n\t * Split a combined short version in to the separate context IDs.\n\t * @param keys The context ID keys to get the short versions for.\n\t * @param combined The combined short version to separate.\n\t * @param separator The separator used between parts.\n\t * @returns The short version combined.\n\t * @throws GeneralError if the number of parts does not match the number of keys.\n\t */\n\tpublic static shortSplit(keys: string[], combined: string, separator: string = \"/\"): IContextIds {\n\t\tGuards.arrayValue<string>(ContextIdHelper.CLASS_NAME, nameof(keys), keys);\n\t\tGuards.stringValue(ContextIdHelper.CLASS_NAME, nameof(combined), combined);\n\n\t\tconst parts = combined.split(separator);\n\t\tconst result: IContextIds = {};\n\n\t\tif (parts.length !== keys.length) {\n\t\t\tthrow new GeneralError(ContextIdHelper.CLASS_NAME, \"contextIdSplitMismatch\", {\n\t\t\t\texpected: keys.length,\n\t\t\t\tactual: parts.length\n\t\t\t});\n\t\t}\n\n\t\tfor (let i = 0; i < keys.length; i++) {\n\t\t\tresult[keys[i]] = parts[i];\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t/**\n\t * Create a combined key.\n\t * @param contextIds The context IDs to create the combined key for.\n\t * @param keys The context ID keys to get the short versions for.\n\t * @param separator The separator to use between parts.\n\t * @returns The short version combined.\n\t */\n\tpublic static combinedContextKey(\n\t\tcontextIds: IContextIds | undefined,\n\t\tkeys: string[] | undefined,\n\t\tseparator: string = \"/\"\n\t): string | undefined {\n\t\tContextIdHelper.guardAll(contextIds, keys);\n\n\t\tconst short = ContextIdHelper.shortAll(contextIds, keys);\n\n\t\tif (Object.keys(short).length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn Object.values(short).join(separator);\n\t}\n\n\t/**\n\t * Pick only the desired keys from the available keys.\n\t * @param availableKeys The available keys to pick from.\n\t * @param desiredKeys The desired keys to pick.\n\t * @returns The picked keys.\n\t */\n\tpublic static pickKeysFromAvailable(availableKeys?: string[], desiredKeys?: string[]): string[] {\n\t\tif (!Is.arrayValue(availableKeys) || !Is.arrayValue(desiredKeys)) {\n\t\t\treturn [];\n\t\t}\n\n\t\treturn desiredKeys.filter(key => availableKeys.includes(key));\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IContextIdHandler.js","sourceRoot":"","sources":["../../../src/models/IContextIdHandler.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IComponent } from \"@twin.org/core\";\n\n/**\n * Interface describing a context ID handler.\n */\nexport interface IContextIdHandler extends IComponent {\n\t/**\n\t * The short form version of the context ID, should be unique enough to partition data.\n\t * @param value The full context ID value.\n\t * @returns The short form version of the context ID.\n\t */\n\tshort?(value: string): string;\n\n\t/**\n\t * Performs a runtime guard on the provided context ID value.\n\t * @param value The context ID value to guard.\n\t * @throws Guard error if the value is invalid.\n\t */\n\tguard?(value: string): void;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"IContextIdHandler.js","sourceRoot":"","sources":["../../../src/models/IContextIdHandler.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IComponent } from \"@twin.org/core\";\n\n/**\n * Interface describing a context ID handler.\n */\nexport interface IContextIdHandler extends IComponent {\n\t/**\n\t * The short form version of the context ID, should be unique enough to partition data.\n\t * @param value The full context ID value.\n\t * @returns The short form version of the context ID.\n\t */\n\tshort?(value: string): string;\n\n\t/**\n\t * The long form version of the context ID, expanded from a short version.\n\t * @param value The short form context ID value.\n\t * @returns The long form version of the context ID.\n\t */\n\tlong?(value: string): string;\n\n\t/**\n\t * Performs a runtime guard on the provided context ID value.\n\t * @param value The context ID value to guard.\n\t * @throws Guard error if the value is invalid.\n\t */\n\tguard?(value: string): void;\n}\n"]}
|
|
@@ -37,6 +37,21 @@ export declare class ContextIdHelper {
|
|
|
37
37
|
}, K extends string>(contextIds: T | undefined, keys: readonly K[] | undefined): asserts contextIds is T & {
|
|
38
38
|
[P in K]: string;
|
|
39
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* Gets the long version of a context ID, expanding from a short form if a handler is registered.
|
|
42
|
+
* @param contextIds The context IDs to get the long version from.
|
|
43
|
+
* @param key The context ID key to get the long version for.
|
|
44
|
+
* @returns The long version of the context ID.
|
|
45
|
+
* @throws Guard error if the value is invalid.
|
|
46
|
+
*/
|
|
47
|
+
static long(contextIds: IContextIds | undefined, key: string): string;
|
|
48
|
+
/**
|
|
49
|
+
* Gets the long versions of multiple context IDs.
|
|
50
|
+
* @param contextIds The context IDs to get the long versions from.
|
|
51
|
+
* @param keys The context ID keys to get the long versions for.
|
|
52
|
+
* @returns The long versions of the context IDs.
|
|
53
|
+
*/
|
|
54
|
+
static longAll(contextIds: IContextIds | undefined, keys: string[] | undefined): IContextIds;
|
|
40
55
|
/**
|
|
41
56
|
* Gets the short versions of multiple context IDs.
|
|
42
57
|
* @param contextIds The context IDs to get the short versions from.
|
|
@@ -9,6 +9,12 @@ export interface IContextIdHandler extends IComponent {
|
|
|
9
9
|
* @returns The short form version of the context ID.
|
|
10
10
|
*/
|
|
11
11
|
short?(value: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* The long form version of the context ID, expanded from a short version.
|
|
14
|
+
* @param value The short form context ID value.
|
|
15
|
+
* @returns The long form version of the context ID.
|
|
16
|
+
*/
|
|
17
|
+
long?(value: string): string;
|
|
12
18
|
/**
|
|
13
19
|
* Performs a runtime guard on the provided context ID value.
|
|
14
20
|
* @param value The context ID value to guard.
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,208 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.9.2-next.10](https://github.com/iotaledger/twin-framework/compare/context-v0.9.2-next.9...context-v0.9.2-next.10) (2026-08-11)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Miscellaneous Chores
|
|
7
|
+
|
|
8
|
+
* **context:** Synchronize repo versions
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @twin.org/core bumped from 0.9.2-next.9 to 0.9.2-next.10
|
|
16
|
+
* @twin.org/nameof bumped from 0.9.2-next.9 to 0.9.2-next.10
|
|
17
|
+
* devDependencies
|
|
18
|
+
* @twin.org/nameof-transformer bumped from 0.9.2-next.9 to 0.9.2-next.10
|
|
19
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.9.2-next.9 to 0.9.2-next.10
|
|
20
|
+
* @twin.org/validate-locales bumped from 0.9.2-next.9 to 0.9.2-next.10
|
|
21
|
+
|
|
22
|
+
## [0.9.2-next.9](https://github.com/iotaledger/twin-framework/compare/context-v0.9.2-next.8...context-v0.9.2-next.9) (2026-08-10)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Miscellaneous Chores
|
|
26
|
+
|
|
27
|
+
* **context:** Synchronize repo versions
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### Dependencies
|
|
31
|
+
|
|
32
|
+
* The following workspace dependencies were updated
|
|
33
|
+
* dependencies
|
|
34
|
+
* @twin.org/core bumped from 0.9.2-next.8 to 0.9.2-next.9
|
|
35
|
+
* @twin.org/nameof bumped from 0.9.2-next.8 to 0.9.2-next.9
|
|
36
|
+
* devDependencies
|
|
37
|
+
* @twin.org/nameof-transformer bumped from 0.9.2-next.8 to 0.9.2-next.9
|
|
38
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.9.2-next.8 to 0.9.2-next.9
|
|
39
|
+
* @twin.org/validate-locales bumped from 0.9.2-next.8 to 0.9.2-next.9
|
|
40
|
+
|
|
41
|
+
## [0.9.2-next.8](https://github.com/iotaledger/twin-framework/compare/context-v0.9.2-next.7...context-v0.9.2-next.8) (2026-08-10)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
### Miscellaneous Chores
|
|
45
|
+
|
|
46
|
+
* **context:** Synchronize repo versions
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
### Dependencies
|
|
50
|
+
|
|
51
|
+
* The following workspace dependencies were updated
|
|
52
|
+
* dependencies
|
|
53
|
+
* @twin.org/core bumped from 0.9.2-next.7 to 0.9.2-next.8
|
|
54
|
+
* @twin.org/nameof bumped from 0.9.2-next.7 to 0.9.2-next.8
|
|
55
|
+
* devDependencies
|
|
56
|
+
* @twin.org/nameof-transformer bumped from 0.9.2-next.7 to 0.9.2-next.8
|
|
57
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.9.2-next.7 to 0.9.2-next.8
|
|
58
|
+
* @twin.org/validate-locales bumped from 0.9.2-next.7 to 0.9.2-next.8
|
|
59
|
+
|
|
60
|
+
## [0.9.2-next.7](https://github.com/iotaledger/twin-framework/compare/context-v0.9.2-next.6...context-v0.9.2-next.7) (2026-08-07)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
### Features
|
|
64
|
+
|
|
65
|
+
* linting and dependency update ([676b4e9](https://github.com/iotaledger/twin-framework/commit/676b4e9d9bce158065200bbf875bb31da81d166d))
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
### Dependencies
|
|
69
|
+
|
|
70
|
+
* The following workspace dependencies were updated
|
|
71
|
+
* dependencies
|
|
72
|
+
* @twin.org/core bumped from 0.9.2-next.6 to 0.9.2-next.7
|
|
73
|
+
* @twin.org/nameof bumped from 0.9.2-next.6 to 0.9.2-next.7
|
|
74
|
+
* devDependencies
|
|
75
|
+
* @twin.org/nameof-transformer bumped from 0.9.2-next.6 to 0.9.2-next.7
|
|
76
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.9.2-next.6 to 0.9.2-next.7
|
|
77
|
+
* @twin.org/validate-locales bumped from 0.9.2-next.6 to 0.9.2-next.7
|
|
78
|
+
|
|
79
|
+
## [0.9.2-next.6](https://github.com/iotaledger/twin-framework/compare/context-v0.9.2-next.5...context-v0.9.2-next.6) (2026-08-04)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
### Miscellaneous Chores
|
|
83
|
+
|
|
84
|
+
* **context:** Synchronize repo versions
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
### Dependencies
|
|
88
|
+
|
|
89
|
+
* The following workspace dependencies were updated
|
|
90
|
+
* dependencies
|
|
91
|
+
* @twin.org/core bumped from 0.9.2-next.5 to 0.9.2-next.6
|
|
92
|
+
* @twin.org/nameof bumped from 0.9.2-next.5 to 0.9.2-next.6
|
|
93
|
+
* devDependencies
|
|
94
|
+
* @twin.org/nameof-transformer bumped from 0.9.2-next.5 to 0.9.2-next.6
|
|
95
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.9.2-next.5 to 0.9.2-next.6
|
|
96
|
+
* @twin.org/validate-locales bumped from 0.9.2-next.5 to 0.9.2-next.6
|
|
97
|
+
|
|
98
|
+
## [0.9.2-next.5](https://github.com/iotaledger/twin-framework/compare/context-v0.9.2-next.4...context-v0.9.2-next.5) (2026-08-03)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
### Miscellaneous Chores
|
|
102
|
+
|
|
103
|
+
* **context:** Synchronize repo versions
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
### Dependencies
|
|
107
|
+
|
|
108
|
+
* The following workspace dependencies were updated
|
|
109
|
+
* dependencies
|
|
110
|
+
* @twin.org/core bumped from 0.9.2-next.4 to 0.9.2-next.5
|
|
111
|
+
* @twin.org/nameof bumped from 0.9.2-next.4 to 0.9.2-next.5
|
|
112
|
+
* devDependencies
|
|
113
|
+
* @twin.org/nameof-transformer bumped from 0.9.2-next.4 to 0.9.2-next.5
|
|
114
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.9.2-next.4 to 0.9.2-next.5
|
|
115
|
+
* @twin.org/validate-locales bumped from 0.9.2-next.4 to 0.9.2-next.5
|
|
116
|
+
|
|
117
|
+
## [0.9.2-next.4](https://github.com/iotaledger/twin-framework/compare/context-v0.9.2-next.3...context-v0.9.2-next.4) (2026-07-31)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
### Miscellaneous Chores
|
|
121
|
+
|
|
122
|
+
* **context:** Synchronize repo versions
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
### Dependencies
|
|
126
|
+
|
|
127
|
+
* The following workspace dependencies were updated
|
|
128
|
+
* dependencies
|
|
129
|
+
* @twin.org/core bumped from 0.9.2-next.3 to 0.9.2-next.4
|
|
130
|
+
* @twin.org/nameof bumped from 0.9.2-next.3 to 0.9.2-next.4
|
|
131
|
+
* devDependencies
|
|
132
|
+
* @twin.org/nameof-transformer bumped from 0.9.2-next.3 to 0.9.2-next.4
|
|
133
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.9.2-next.3 to 0.9.2-next.4
|
|
134
|
+
* @twin.org/validate-locales bumped from 0.9.2-next.3 to 0.9.2-next.4
|
|
135
|
+
|
|
136
|
+
## [0.9.2-next.3](https://github.com/iotaledger/twin-framework/compare/context-v0.9.2-next.2...context-v0.9.2-next.3) (2026-07-30)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
### Miscellaneous Chores
|
|
140
|
+
|
|
141
|
+
* **context:** Synchronize repo versions
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
### Dependencies
|
|
145
|
+
|
|
146
|
+
* The following workspace dependencies were updated
|
|
147
|
+
* dependencies
|
|
148
|
+
* @twin.org/core bumped from 0.9.2-next.2 to 0.9.2-next.3
|
|
149
|
+
* @twin.org/nameof bumped from 0.9.2-next.2 to 0.9.2-next.3
|
|
150
|
+
* devDependencies
|
|
151
|
+
* @twin.org/nameof-transformer bumped from 0.9.2-next.2 to 0.9.2-next.3
|
|
152
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.9.2-next.2 to 0.9.2-next.3
|
|
153
|
+
* @twin.org/validate-locales bumped from 0.9.2-next.2 to 0.9.2-next.3
|
|
154
|
+
|
|
155
|
+
## [0.9.2-next.2](https://github.com/iotaledger/twin-framework/compare/context-v0.9.2-next.1...context-v0.9.2-next.2) (2026-07-29)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
### Features
|
|
159
|
+
|
|
160
|
+
* context id long method ([#423](https://github.com/iotaledger/twin-framework/issues/423)) ([70a7384](https://github.com/iotaledger/twin-framework/commit/70a7384f201ea5dafdff5de34fb90308d5e80338))
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
### Dependencies
|
|
164
|
+
|
|
165
|
+
* The following workspace dependencies were updated
|
|
166
|
+
* dependencies
|
|
167
|
+
* @twin.org/core bumped from 0.9.2-next.1 to 0.9.2-next.2
|
|
168
|
+
* @twin.org/nameof bumped from 0.9.2-next.1 to 0.9.2-next.2
|
|
169
|
+
* devDependencies
|
|
170
|
+
* @twin.org/nameof-transformer bumped from 0.9.2-next.1 to 0.9.2-next.2
|
|
171
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.9.2-next.1 to 0.9.2-next.2
|
|
172
|
+
* @twin.org/validate-locales bumped from 0.9.2-next.1 to 0.9.2-next.2
|
|
173
|
+
|
|
174
|
+
## [0.9.2-next.1](https://github.com/iotaledger/twin-framework/compare/context-v0.9.2-next.0...context-v0.9.2-next.1) (2026-07-28)
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
### Features
|
|
178
|
+
|
|
179
|
+
* add context id features ([#206](https://github.com/iotaledger/twin-framework/issues/206)) ([ef0d4ee](https://github.com/iotaledger/twin-framework/commit/ef0d4ee11a4f5fc6cc6f52a4958ce905c04ee13b))
|
|
180
|
+
* add user organization context key ([a3da436](https://github.com/iotaledger/twin-framework/commit/a3da4360451860052a508bdc147255a0b9ca8410))
|
|
181
|
+
* concurrency in SharedStore ([#388](https://github.com/iotaledger/twin-framework/issues/388)) ([0610198](https://github.com/iotaledger/twin-framework/commit/0610198ba482273c3f6ba918e34f5875a3659571))
|
|
182
|
+
* context id handler derives from component ([c868ec2](https://github.com/iotaledger/twin-framework/commit/c868ec21d3a576d4faa222bf130270a21936e50e))
|
|
183
|
+
* typescript 6 update ([1d10f31](https://github.com/iotaledger/twin-framework/commit/1d10f31e6516ec622773f45e88af82fe749b384a))
|
|
184
|
+
* update dependencies ([4da77ab](https://github.com/iotaledger/twin-framework/commit/4da77ab30f499e52825ac5a76f51436ceb59c26e))
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
### Bug Fixes
|
|
188
|
+
|
|
189
|
+
* context id backwards compatibility ([#406](https://github.com/iotaledger/twin-framework/issues/406)) ([afab5fa](https://github.com/iotaledger/twin-framework/commit/afab5fa2a876b01736e117e4992536627837afde))
|
|
190
|
+
* ensure __decorate is defined for decorators ([103a563](https://github.com/iotaledger/twin-framework/commit/103a563ce01ebdef6240d2e590e7b026e8692684))
|
|
191
|
+
* use singleton pattern for context storage ([c69f358](https://github.com/iotaledger/twin-framework/commit/c69f358e45361b45d4e46f19846cd5b8c99b0ccd))
|
|
192
|
+
* use singleton pattern for context storage ([5cc706a](https://github.com/iotaledger/twin-framework/commit/5cc706a2bbfc601fa3d00f3efd8b764052e9f91d))
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
### Dependencies
|
|
196
|
+
|
|
197
|
+
* The following workspace dependencies were updated
|
|
198
|
+
* dependencies
|
|
199
|
+
* @twin.org/core bumped from 0.9.2-next.0 to 0.9.2-next.1
|
|
200
|
+
* @twin.org/nameof bumped from 0.9.2-next.0 to 0.9.2-next.1
|
|
201
|
+
* devDependencies
|
|
202
|
+
* @twin.org/nameof-transformer bumped from 0.9.2-next.0 to 0.9.2-next.1
|
|
203
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.9.2-next.0 to 0.9.2-next.1
|
|
204
|
+
* @twin.org/validate-locales bumped from 0.9.2-next.0 to 0.9.2-next.1
|
|
205
|
+
|
|
3
206
|
## [0.9.1](https://github.com/iotaledger/twin-framework/compare/context-v0.9.1...context-v0.9.1) (2026-07-26)
|
|
4
207
|
|
|
5
208
|
|
|
@@ -134,6 +134,66 @@ Guard error if the value is invalid.
|
|
|
134
134
|
|
|
135
135
|
***
|
|
136
136
|
|
|
137
|
+
### long() {#long}
|
|
138
|
+
|
|
139
|
+
> `static` **long**(`contextIds`, `key`): `string`
|
|
140
|
+
|
|
141
|
+
Gets the long version of a context ID, expanding from a short form if a handler is registered.
|
|
142
|
+
|
|
143
|
+
#### Parameters
|
|
144
|
+
|
|
145
|
+
##### contextIds
|
|
146
|
+
|
|
147
|
+
[`IContextIds`](../interfaces/IContextIds.md) \| `undefined`
|
|
148
|
+
|
|
149
|
+
The context IDs to get the long version from.
|
|
150
|
+
|
|
151
|
+
##### key
|
|
152
|
+
|
|
153
|
+
`string`
|
|
154
|
+
|
|
155
|
+
The context ID key to get the long version for.
|
|
156
|
+
|
|
157
|
+
#### Returns
|
|
158
|
+
|
|
159
|
+
`string`
|
|
160
|
+
|
|
161
|
+
The long version of the context ID.
|
|
162
|
+
|
|
163
|
+
#### Throws
|
|
164
|
+
|
|
165
|
+
Guard error if the value is invalid.
|
|
166
|
+
|
|
167
|
+
***
|
|
168
|
+
|
|
169
|
+
### longAll() {#longall}
|
|
170
|
+
|
|
171
|
+
> `static` **longAll**(`contextIds`, `keys`): [`IContextIds`](../interfaces/IContextIds.md)
|
|
172
|
+
|
|
173
|
+
Gets the long versions of multiple context IDs.
|
|
174
|
+
|
|
175
|
+
#### Parameters
|
|
176
|
+
|
|
177
|
+
##### contextIds
|
|
178
|
+
|
|
179
|
+
[`IContextIds`](../interfaces/IContextIds.md) \| `undefined`
|
|
180
|
+
|
|
181
|
+
The context IDs to get the long versions from.
|
|
182
|
+
|
|
183
|
+
##### keys
|
|
184
|
+
|
|
185
|
+
`string`[] \| `undefined`
|
|
186
|
+
|
|
187
|
+
The context ID keys to get the long versions for.
|
|
188
|
+
|
|
189
|
+
#### Returns
|
|
190
|
+
|
|
191
|
+
[`IContextIds`](../interfaces/IContextIds.md)
|
|
192
|
+
|
|
193
|
+
The long versions of the context IDs.
|
|
194
|
+
|
|
195
|
+
***
|
|
196
|
+
|
|
137
197
|
### shortAll() {#shortall}
|
|
138
198
|
|
|
139
199
|
> `static` **shortAll**(`contextIds`, `keys`): [`IContextIds`](../interfaces/IContextIds.md)
|
|
@@ -30,6 +30,28 @@ The short form version of the context ID.
|
|
|
30
30
|
|
|
31
31
|
***
|
|
32
32
|
|
|
33
|
+
### long()? {#long}
|
|
34
|
+
|
|
35
|
+
> `optional` **long**(`value`): `string`
|
|
36
|
+
|
|
37
|
+
The long form version of the context ID, expanded from a short version.
|
|
38
|
+
|
|
39
|
+
#### Parameters
|
|
40
|
+
|
|
41
|
+
##### value
|
|
42
|
+
|
|
43
|
+
`string`
|
|
44
|
+
|
|
45
|
+
The short form context ID value.
|
|
46
|
+
|
|
47
|
+
#### Returns
|
|
48
|
+
|
|
49
|
+
`string`
|
|
50
|
+
|
|
51
|
+
The long form version of the context ID.
|
|
52
|
+
|
|
53
|
+
***
|
|
54
|
+
|
|
33
55
|
### guard()? {#guard}
|
|
34
56
|
|
|
35
57
|
> `optional` **guard**(`value`): `void`
|
|
@@ -173,21 +195,3 @@ A promise that resolves when the component has stopped.
|
|
|
173
195
|
#### Inherited from
|
|
174
196
|
|
|
175
197
|
`IComponent.stop`
|
|
176
|
-
|
|
177
|
-
***
|
|
178
|
-
|
|
179
|
-
### health()? {#health}
|
|
180
|
-
|
|
181
|
-
> `optional` **health**(): `Promise`\<`IHealth`[]\>
|
|
182
|
-
|
|
183
|
-
Returns the health status of the component.
|
|
184
|
-
|
|
185
|
-
#### Returns
|
|
186
|
-
|
|
187
|
-
`Promise`\<`IHealth`[]\>
|
|
188
|
-
|
|
189
|
-
The health status of the component, can return multiple entries for elements within the component.
|
|
190
|
-
|
|
191
|
-
#### Inherited from
|
|
192
|
-
|
|
193
|
-
`IComponent.health`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/context",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2-next.10",
|
|
4
4
|
"description": "Helper methods/classes for context handling",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"node": ">=24.0.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@twin.org/core": "
|
|
18
|
-
"@twin.org/nameof": "
|
|
17
|
+
"@twin.org/core": "0.9.2-next.10",
|
|
18
|
+
"@twin.org/nameof": "0.9.2-next.10"
|
|
19
19
|
},
|
|
20
20
|
"main": "./dist/es/index.js",
|
|
21
21
|
"types": "./dist/types/index.d.ts",
|