@twin.org/core 0.9.2-next.7 → 0.9.2-next.8

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.
@@ -1,6 +1,7 @@
1
1
  import { JsonHelper } from "./jsonHelper.js";
2
2
  import { GeneralError } from "../errors/generalError.js";
3
3
  import { Converter } from "../utils/converter.js";
4
+ import { Guards } from "../utils/guards.js";
4
5
  import { Is } from "../utils/is.js";
5
6
  /**
6
7
  * Class to help with objects.
@@ -94,13 +95,15 @@ export class ObjectHelper {
94
95
  }
95
96
  /**
96
97
  * Get the property of an unknown object.
97
- * @param obj The object to get the property from.
98
+ * @param object The object to get the property from.
98
99
  * @param property The property to get, can be separated by dots for nested path.
99
100
  * @returns The property.
100
101
  */
101
- static propertyGet(obj, property) {
102
+ static propertyGet(object, property) {
103
+ Guards.object(ObjectHelper.CLASS_NAME, "object", object);
104
+ Guards.stringValue(ObjectHelper.CLASS_NAME, "property", property);
102
105
  const pathParts = property.split(".");
103
- let pathValue = obj;
106
+ let pathValue = object;
104
107
  for (const pathPart of pathParts) {
105
108
  // Is the path part numeric i.e. an array index.
106
109
  const arrayMatch = /^(\d+)$/.exec(pathPart);
@@ -127,14 +130,16 @@ export class ObjectHelper {
127
130
  }
128
131
  /**
129
132
  * Set the property of an unknown object.
130
- * @param obj The object to set the property from.
133
+ * @param object The object to set the property from.
131
134
  * @param property The property to set.
132
135
  * @param value The value to set.
133
136
  * @throws GeneralError if the property target is not an object.
134
137
  */
135
- static propertySet(obj, property, value) {
138
+ static propertySet(object, property, value) {
139
+ Guards.object(ObjectHelper.CLASS_NAME, "object", object);
140
+ Guards.stringValue(ObjectHelper.CLASS_NAME, "property", property);
136
141
  const pathParts = property.split(".");
137
- let pathValue = obj;
142
+ let pathValue = object;
138
143
  let parentObj;
139
144
  for (let i = 0; i < pathParts.length; i++) {
140
145
  const pathPart = pathParts[i];
@@ -193,12 +198,14 @@ export class ObjectHelper {
193
198
  }
194
199
  /**
195
200
  * Delete the property of an unknown object.
196
- * @param obj The object to delete the property from.
201
+ * @param object The object to delete the property from.
197
202
  * @param property The property to delete.
198
203
  */
199
- static propertyDelete(obj, property) {
200
- if (Is.object(obj)) {
201
- delete obj[property];
204
+ static propertyDelete(object, property) {
205
+ Guards.object(ObjectHelper.CLASS_NAME, "object", object);
206
+ Guards.stringValue(ObjectHelper.CLASS_NAME, "property", property);
207
+ if (Is.object(object)) {
208
+ delete object[property];
202
209
  }
203
210
  }
204
211
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"objectHelper.js","sourceRoot":"","sources":["../../../src/helpers/objectHelper.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAEpC;;GAEG;AACH,MAAM,OAAO,YAAY;IACxB;;OAEG;IACI,MAAM,CAAU,UAAU,kBAAkC;IAEnE;;;;;OAKG;IACI,MAAM,CAAC,OAAO,CAAI,GAAkB,EAAE,SAAkB,KAAK;QACnE,IAAI,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;YACvB,OAAO,IAAI,UAAU,EAAE,CAAC;QACzB,CAAC;QACD,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QAEjF,OAAO,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,SAAS,CAAI,KAAoC;QAC9D,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KA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OG;IACI,MAAM,CAAC,qBAAqB,CAClC,GAAM,EACN,OAA6D;QAE7D,IAAI,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;YACpB,MAAM,eAAe,GAAG,OAAO,EAAE,eAAe,IAAI,IAAI,CAAC;YACzD,MAAM,UAAU,GAAG,OAAO,EAAE,UAAU,IAAI,KAAK,CAAC;YAChD,MAAM,MAAM,GAA8B,EAAE,CAAC;YAC7C,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC9B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;gBACxB,IAAI,CAAC,CAAC,CAAC,eAAe,IAAI,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,IAAI,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;oBACzF,MAAM,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,qBAAqB,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC;gBACrE,CAAC;YACF,CAAC;YACD,OAAO,MAAW,CAAC;QACpB,CAAC;aAAM,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;YAC1B,MAAM,GAAG,GAAG,EAAE,CAAC;YACf,KAAK,MAAM,OAAO,IAAI,GAAG,EAAE,CAAC;gBAC3B,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,qBAAqB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;YAChE,CAAC;YACD,OAAO,GAAQ,CAAC;QACjB,CAAC;QACD,OAAO,GAAG,CAAC;IACZ,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { nameof } from \"@twin.org/nameof\";\nimport { JsonHelper } from \"./jsonHelper.js\";\nimport { GeneralError } from \"../errors/generalError.js\";\nimport { Converter } from \"../utils/converter.js\";\nimport { Is } from \"../utils/is.js\";\n\n/**\n * Class to help with objects.\n */\nexport class ObjectHelper {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<ObjectHelper>();\n\n\t/**\n\t * Convert an object to bytes.\n\t * @param obj The object to convert.\n\t * @param format Format the JSON content.\n\t * @returns The object as bytes.\n\t */\n\tpublic static toBytes<T>(obj: T | undefined, format: boolean = false): Uint8Array {\n\t\tif (Is.undefined(obj)) {\n\t\t\treturn new Uint8Array();\n\t\t}\n\t\tconst json = format ? JSON.stringify(obj, undefined, \"\\t\") : JSON.stringify(obj);\n\n\t\treturn Converter.utf8ToBytes(json);\n\t}\n\n\t/**\n\t * Convert a bytes to an object.\n\t * @param bytes The bytes to convert to an object.\n\t * @returns The object.\n\t * @throws GeneralError if there was an error parsing the JSON.\n\t */\n\tpublic static fromBytes<T>(bytes: Uint8Array | undefined | null): T {\n\t\tif (Is.empty(bytes) || bytes.length === 0) {\n\t\t\treturn undefined as unknown as T;\n\t\t}\n\t\ttry {\n\t\t\tconst utf8 = Converter.bytesToUtf8(bytes);\n\t\t\treturn JSON.parse(utf8) as T;\n\t\t} catch (err) {\n\t\t\tthrow new GeneralError(ObjectHelper.CLASS_NAME, \"failedBytesToJSON\", undefined, err);\n\t\t}\n\t}\n\n\t/**\n\t * Make a deep clone of an object.\n\t * @param obj The object to clone.\n\t * @returns The objects clone.\n\t */\n\tpublic static clone<T>(obj: T): T;\n\t/**\n\t * Make a deep clone of an object.\n\t * @param obj The object to clone.\n\t * @returns The objects clone, or undefined if the input was undefined.\n\t */\n\tpublic static clone<T>(obj: T | undefined): T | undefined {\n\t\tif (Is.undefined(obj)) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn structuredClone(obj);\n\t}\n\n\t/**\n\t * Deep merge objects.\n\t * @param obj1 The first object to merge.\n\t * @param obj2 The second object to merge.\n\t * @returns The combined deep merge of the objects.\n\t */\n\tpublic static merge<T = unknown, U = unknown>(obj1: T, obj2: U): T & U {\n\t\tif (Is.empty(obj1)) {\n\t\t\treturn ObjectHelper.clone(obj2) as T & U;\n\t\t}\n\t\tif (Is.empty(obj2)) {\n\t\t\treturn ObjectHelper.clone(obj1) as T & U;\n\t\t}\n\n\t\tconst obj1Clone = ObjectHelper.clone(obj1);\n\n\t\tif (Is.object(obj1Clone) && Is.object(obj2)) {\n\t\t\tconst keys = Object.keys(obj2);\n\t\t\tfor (const key of keys) {\n\t\t\t\tif (Is.object(obj1Clone[key]) && Is.object(obj2[key])) {\n\t\t\t\t\tObjectHelper.propertySet(obj1Clone, key, ObjectHelper.merge(obj1Clone[key], obj2[key]));\n\t\t\t\t} else {\n\t\t\t\t\tObjectHelper.propertySet(obj1Clone, key, obj2[key]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn obj1Clone as T & U;\n\t}\n\n\t/**\n\t * Does one object equal another.\n\t * @param obj1 The first object to compare.\n\t * @param obj2 The second object to compare.\n\t * @param strictPropertyOrder Should the properties be in the same order, defaults to true.\n\t * @returns True is the objects are equal.\n\t */\n\tpublic static equal<T>(obj1: T, obj2: T, strictPropertyOrder?: boolean): boolean {\n\t\tif (strictPropertyOrder ?? true) {\n\t\t\treturn JSON.stringify(obj1) === JSON.stringify(obj2);\n\t\t}\n\t\treturn JsonHelper.canonicalize(obj1) === JsonHelper.canonicalize(obj2);\n\t}\n\n\t/**\n\t * Get the property of an unknown object.\n\t * @param obj The object to get the property from.\n\t * @param property The property to get, can be separated by dots for nested path.\n\t * @returns The property.\n\t */\n\tpublic static propertyGet<T = unknown>(obj: unknown, property: string): T | undefined {\n\t\tconst pathParts = property.split(\".\");\n\n\t\tlet pathValue: unknown = obj;\n\t\tfor (const pathPart of pathParts) {\n\t\t\t// Is the path part numeric i.e. an array index.\n\t\t\tconst arrayMatch = /^(\\d+)$/.exec(pathPart);\n\n\t\t\tif (arrayMatch) {\n\t\t\t\tconst arrayIndex = Number.parseInt(arrayMatch[1], 10);\n\n\t\t\t\tif (Is.arrayValue(pathValue) && arrayIndex < pathValue.length) {\n\t\t\t\t\t// There is no prop name so this is a direct array index on the current object\n\t\t\t\t\tpathValue = pathValue[arrayIndex];\n\t\t\t\t} else {\n\t\t\t\t\t// Array index for non array object so return\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\t\t\t} else if (Is.object(pathValue)) {\n\t\t\t\t// No array part in path so assume object sub property\n\t\t\t\tpathValue = pathValue[pathPart];\n\t\t\t} else {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t}\n\n\t\treturn pathValue as T;\n\t}\n\n\t/**\n\t * Set the property of an unknown object.\n\t * @param obj The object to set the property from.\n\t * @param property The property to set.\n\t * @param value The value to set.\n\t * @throws GeneralError if the property target is not an object.\n\t */\n\tpublic static propertySet(obj: unknown, property: string, value: unknown): void {\n\t\tconst pathParts = property.split(\".\");\n\n\t\tlet pathValue: unknown = obj;\n\t\tlet parentObj: unknown;\n\t\tfor (let i = 0; i < pathParts.length; i++) {\n\t\t\tconst pathPart = pathParts[i];\n\n\t\t\t// Is the path part numeric i.e. an array index.\n\t\t\tconst arrayMatch = /^(\\d+)$/.exec(pathPart);\n\t\t\tconst arrayIndex = arrayMatch ? Number.parseInt(arrayMatch[1], 10) : -1;\n\n\t\t\tif (i === pathParts.length - 1) {\n\t\t\t\t// Last part of path so set the value\n\t\t\t\tif (arrayIndex >= 0) {\n\t\t\t\t\tif (Is.array(pathValue)) {\n\t\t\t\t\t\tpathValue[arrayIndex] = value;\n\t\t\t\t\t} else if (Is.object(pathValue)) {\n\t\t\t\t\t\tpathValue[arrayIndex] = value;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new GeneralError(ObjectHelper.CLASS_NAME, \"cannotSetArrayIndex\", {\n\t\t\t\t\t\t\tproperty,\n\t\t\t\t\t\t\tindex: arrayIndex\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t} else if (Is.object(pathValue)) {\n\t\t\t\t\tpathValue[pathPart] = value;\n\t\t\t\t} else {\n\t\t\t\t\tthrow new GeneralError(ObjectHelper.CLASS_NAME, \"cannotSetProperty\", { property });\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tparentObj = pathValue;\n\t\t\t\tif (Is.object(pathValue)) {\n\t\t\t\t\tpathValue = pathValue[pathPart];\n\t\t\t\t} else if (Is.array(pathValue)) {\n\t\t\t\t\tpathValue = pathValue[arrayIndex];\n\t\t\t\t}\n\n\t\t\t\tif (Is.empty(pathValue)) {\n\t\t\t\t\tconst nextArrayMatch = /^(\\d+)$/.exec(pathParts[i + 1]);\n\t\t\t\t\tconst nextArrayIndex = nextArrayMatch ? Number.parseInt(nextArrayMatch[1], 10) : -1;\n\n\t\t\t\t\tif (nextArrayIndex >= 0) {\n\t\t\t\t\t\tpathValue = [];\n\t\t\t\t\t} else {\n\t\t\t\t\t\tpathValue = {};\n\t\t\t\t\t}\n\n\t\t\t\t\tif (Is.object(parentObj)) {\n\t\t\t\t\t\tparentObj[pathPart] = pathValue;\n\t\t\t\t\t} else if (Is.array(parentObj)) {\n\t\t\t\t\t\tparentObj[arrayIndex] = pathValue;\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 * Delete the property of an unknown object.\n\t * @param obj The object to delete the property from.\n\t * @param property The property to delete.\n\t */\n\tpublic static propertyDelete(obj: unknown, property: string): void {\n\t\tif (Is.object(obj)) {\n\t\t\tdelete obj[property];\n\t\t}\n\t}\n\n\t/**\n\t * Extract a property from the object, providing alternative names.\n\t * @param obj The object to extract from.\n\t * @param propertyNames The possible names for the property.\n\t * @param removeProperties Remove the properties from the object, defaults to true.\n\t * @returns The property if available.\n\t */\n\tpublic static extractProperty<T>(\n\t\tobj: unknown,\n\t\tpropertyNames: string | string[],\n\t\tremoveProperties: boolean = true\n\t): T | undefined {\n\t\tlet retVal: T | undefined;\n\n\t\tif (Is.object(obj)) {\n\t\t\tconst names = Is.string(propertyNames) ? [propertyNames] : propertyNames;\n\n\t\t\tfor (const prop of names) {\n\t\t\t\tretVal ??= ObjectHelper.propertyGet<T>(obj, prop);\n\t\t\t\tif (removeProperties) {\n\t\t\t\t\tObjectHelper.propertyDelete(obj, prop);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn retVal;\n\t}\n\n\t/**\n\t * Pick a subset of properties from an object.\n\t * @param obj The object to pick the properties from.\n\t * @param keys The property keys to pick.\n\t * @returns The picked object.\n\t */\n\tpublic static pick<T, K extends keyof T>(obj: T, keys?: K[]): Pick<T, K>;\n\t/**\n\t * Pick a subset of properties from an object.\n\t * @param obj The object to pick the properties from.\n\t * @param keys The property keys to pick.\n\t * @returns The picked object, or undefined if the input was undefined.\n\t */\n\tpublic static pick<T, K extends keyof T>(obj: T | undefined, keys?: K[]): Pick<T, K> | undefined;\n\t/**\n\t * Pick a subset of properties from an object.\n\t * @param obj The object to pick the properties from.\n\t * @param keys The property keys to pick.\n\t * @returns The picked object, or undefined if the input was undefined.\n\t */\n\tpublic static pick<T, K extends keyof T>(obj: T | undefined, keys?: K[]): Pick<T, K> | undefined {\n\t\tif (Is.object(obj)) {\n\t\t\tconst result = {} as Pick<T, K>;\n\t\t\tif (Is.arrayValue(keys)) {\n\t\t\t\tfor (const key of keys) {\n\t\t\t\t\tresult[key] = obj[key];\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Omit a subset of properties from an object.\n\t * @param obj The object to omit the properties from.\n\t * @param keys The property keys to omit.\n\t * @returns The object without the omitted keys.\n\t */\n\tpublic static omit<T, K extends keyof T>(obj: T, keys?: K[]): Omit<T, K>;\n\t/**\n\t * Omit a subset of properties from an object.\n\t * @param obj The object to omit the properties from.\n\t * @param keys The property keys to omit.\n\t * @returns The object without the omitted keys, or undefined if the input was undefined.\n\t */\n\tpublic static omit<T, K extends keyof T>(obj: T | undefined, keys?: K[]): Omit<T, K> | undefined;\n\t/**\n\t * Omit a subset of properties from an object.\n\t * @param obj The object to omit the properties from.\n\t * @param keys The property keys to omit.\n\t * @returns The object without the omitted keys, or undefined if the input was undefined.\n\t */\n\tpublic static omit<T, K extends keyof T>(obj: T | undefined, keys?: K[]): Omit<T, K> {\n\t\tif (Is.object(obj) && Is.arrayValue(keys)) {\n\t\t\tconst result = ObjectHelper.clone(obj);\n\t\t\tfor (const key of keys) {\n\t\t\t\tdelete result[key];\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\treturn obj as Omit<T, K>;\n\t}\n\n\t/**\n\t * Convert the non JSON primitives to extended types.\n\t * @param obj The object to convert.\n\t * @returns The object with extended properties.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic static toExtended(obj: any): any {\n\t\tconst jsonExtended = JsonHelper.stringifyEx(obj);\n\t\treturn JSON.parse(jsonExtended);\n\t}\n\n\t/**\n\t * Convert the extended types to non JSON primitives.\n\t * @param obj The object to convert.\n\t * @returns The object with regular properties.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic static fromExtended(obj: any): any {\n\t\tconst jsonExtended = JsonHelper.stringifyEx(obj);\n\t\treturn JsonHelper.parseEx(jsonExtended);\n\t}\n\n\t/**\n\t * Remove empty properties from an object.\n\t * @param obj The object to remove the empty properties from.\n\t * @param options The options for the removal.\n\t * @param options.removeUndefined Remove undefined properties, defaults to true.\n\t * @param options.removeNull Remove null properties, defaults to false.\n\t * @returns The object with empty properties removed.\n\t */\n\tpublic static removeEmptyProperties<T = unknown>(\n\t\tobj: T,\n\t\toptions?: { removeUndefined?: boolean; removeNull?: boolean }\n\t): T {\n\t\tif (Is.object(obj)) {\n\t\t\tconst removeUndefined = options?.removeUndefined ?? true;\n\t\t\tconst removeNull = options?.removeNull ?? false;\n\t\t\tconst newObj: { [id: string]: unknown } = {};\n\t\t\tconst keys = Object.keys(obj);\n\t\t\tfor (const key of keys) {\n\t\t\t\tif (!((removeUndefined && Is.undefined(obj[key])) || (removeNull && Is.null(obj[key])))) {\n\t\t\t\t\tnewObj[key] = ObjectHelper.removeEmptyProperties(obj[key], options);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn newObj as T;\n\t\t} else if (Is.array(obj)) {\n\t\t\tconst arr = [];\n\t\t\tfor (const element of obj) {\n\t\t\t\tarr.push(ObjectHelper.removeEmptyProperties(element, options));\n\t\t\t}\n\t\t\treturn arr as T;\n\t\t}\n\t\treturn obj;\n\t}\n}\n"]}
1
+ {"version":3,"file":"objectHelper.js","sourceRoot":"","sources":["../../../src/helpers/objectHelper.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAEpC;;GAEG;AACH,MAAM,OAAO,YAAY;IACxB;;OAEG;IACI,MAAM,CAAU,UAAU,kBAAkC;IAEnE;;;;;OAKG;IACI,MAAM,CAAC,OAAO,CAAI,GAAkB,EAAE,SAAkB,KAAK;QACnE,IAAI,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;YACvB,OAAO,IAAI,UAAU,EAAE,CAAC;QACzB,CAAC;QACD,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QAEjF,OAAO,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,SAAS,CAAI,KAAoC;QAC9D,IAAI,EAAE,CAAC,KAAK,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MAAW,CAAC;QACpB,CAAC;aAAM,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;YAC1B,MAAM,GAAG,GAAG,EAAE,CAAC;YACf,KAAK,MAAM,OAAO,IAAI,GAAG,EAAE,CAAC;gBAC3B,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,qBAAqB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;YAChE,CAAC;YACD,OAAO,GAAQ,CAAC;QACjB,CAAC;QACD,OAAO,GAAG,CAAC;IACZ,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { nameof } from \"@twin.org/nameof\";\nimport { JsonHelper } from \"./jsonHelper.js\";\nimport { GeneralError } from \"../errors/generalError.js\";\nimport { Converter } from \"../utils/converter.js\";\nimport { Guards } from \"../utils/guards.js\";\nimport { Is } from \"../utils/is.js\";\n\n/**\n * Class to help with objects.\n */\nexport class ObjectHelper {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<ObjectHelper>();\n\n\t/**\n\t * Convert an object to bytes.\n\t * @param obj The object to convert.\n\t * @param format Format the JSON content.\n\t * @returns The object as bytes.\n\t */\n\tpublic static toBytes<T>(obj: T | undefined, format: boolean = false): Uint8Array {\n\t\tif (Is.undefined(obj)) {\n\t\t\treturn new Uint8Array();\n\t\t}\n\t\tconst json = format ? JSON.stringify(obj, undefined, \"\\t\") : JSON.stringify(obj);\n\n\t\treturn Converter.utf8ToBytes(json);\n\t}\n\n\t/**\n\t * Convert a bytes to an object.\n\t * @param bytes The bytes to convert to an object.\n\t * @returns The object.\n\t * @throws GeneralError if there was an error parsing the JSON.\n\t */\n\tpublic static fromBytes<T>(bytes: Uint8Array | undefined | null): T {\n\t\tif (Is.empty(bytes) || bytes.length === 0) {\n\t\t\treturn undefined as unknown as T;\n\t\t}\n\t\ttry {\n\t\t\tconst utf8 = Converter.bytesToUtf8(bytes);\n\t\t\treturn JSON.parse(utf8) as T;\n\t\t} catch (err) {\n\t\t\tthrow new GeneralError(ObjectHelper.CLASS_NAME, \"failedBytesToJSON\", undefined, err);\n\t\t}\n\t}\n\n\t/**\n\t * Make a deep clone of an object.\n\t * @param obj The object to clone.\n\t * @returns The objects clone.\n\t */\n\tpublic static clone<T>(obj: T): T;\n\t/**\n\t * Make a deep clone of an object.\n\t * @param obj The object to clone.\n\t * @returns The objects clone, or undefined if the input was undefined.\n\t */\n\tpublic static clone<T>(obj: T | undefined): T | undefined {\n\t\tif (Is.undefined(obj)) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn structuredClone(obj);\n\t}\n\n\t/**\n\t * Deep merge objects.\n\t * @param obj1 The first object to merge.\n\t * @param obj2 The second object to merge.\n\t * @returns The combined deep merge of the objects.\n\t */\n\tpublic static merge<T = unknown, U = unknown>(obj1: T, obj2: U): T & U {\n\t\tif (Is.empty(obj1)) {\n\t\t\treturn ObjectHelper.clone(obj2) as T & U;\n\t\t}\n\t\tif (Is.empty(obj2)) {\n\t\t\treturn ObjectHelper.clone(obj1) as T & U;\n\t\t}\n\n\t\tconst obj1Clone = ObjectHelper.clone(obj1);\n\n\t\tif (Is.object(obj1Clone) && Is.object(obj2)) {\n\t\t\tconst keys = Object.keys(obj2);\n\t\t\tfor (const key of keys) {\n\t\t\t\tif (Is.object(obj1Clone[key]) && Is.object(obj2[key])) {\n\t\t\t\t\tObjectHelper.propertySet(obj1Clone, key, ObjectHelper.merge(obj1Clone[key], obj2[key]));\n\t\t\t\t} else {\n\t\t\t\t\tObjectHelper.propertySet(obj1Clone, key, obj2[key]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn obj1Clone as T & U;\n\t}\n\n\t/**\n\t * Does one object equal another.\n\t * @param obj1 The first object to compare.\n\t * @param obj2 The second object to compare.\n\t * @param strictPropertyOrder Should the properties be in the same order, defaults to true.\n\t * @returns True is the objects are equal.\n\t */\n\tpublic static equal<T>(obj1: T, obj2: T, strictPropertyOrder?: boolean): boolean {\n\t\tif (strictPropertyOrder ?? true) {\n\t\t\treturn JSON.stringify(obj1) === JSON.stringify(obj2);\n\t\t}\n\t\treturn JsonHelper.canonicalize(obj1) === JsonHelper.canonicalize(obj2);\n\t}\n\n\t/**\n\t * Get the property of an unknown object.\n\t * @param object The object to get the property from.\n\t * @param property The property to get, can be separated by dots for nested path.\n\t * @returns The property.\n\t */\n\tpublic static propertyGet<T = unknown>(object: unknown, property: string): T | undefined {\n\t\tGuards.object(ObjectHelper.CLASS_NAME, nameof(object), object);\n\t\tGuards.stringValue(ObjectHelper.CLASS_NAME, nameof(property), property);\n\n\t\tconst pathParts = property.split(\".\");\n\n\t\tlet pathValue: unknown = object;\n\t\tfor (const pathPart of pathParts) {\n\t\t\t// Is the path part numeric i.e. an array index.\n\t\t\tconst arrayMatch = /^(\\d+)$/.exec(pathPart);\n\n\t\t\tif (arrayMatch) {\n\t\t\t\tconst arrayIndex = Number.parseInt(arrayMatch[1], 10);\n\n\t\t\t\tif (Is.arrayValue(pathValue) && arrayIndex < pathValue.length) {\n\t\t\t\t\t// There is no prop name so this is a direct array index on the current object\n\t\t\t\t\tpathValue = pathValue[arrayIndex];\n\t\t\t\t} else {\n\t\t\t\t\t// Array index for non array object so return\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\t\t\t} else if (Is.object(pathValue)) {\n\t\t\t\t// No array part in path so assume object sub property\n\t\t\t\tpathValue = pathValue[pathPart];\n\t\t\t} else {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t}\n\n\t\treturn pathValue as T;\n\t}\n\n\t/**\n\t * Set the property of an unknown object.\n\t * @param object The object to set the property from.\n\t * @param property The property to set.\n\t * @param value The value to set.\n\t * @throws GeneralError if the property target is not an object.\n\t */\n\tpublic static propertySet(object: unknown, property: string, value: unknown): void {\n\t\tGuards.object(ObjectHelper.CLASS_NAME, nameof(object), object);\n\t\tGuards.stringValue(ObjectHelper.CLASS_NAME, nameof(property), property);\n\n\t\tconst pathParts = property.split(\".\");\n\n\t\tlet pathValue: unknown = object;\n\t\tlet parentObj: unknown;\n\t\tfor (let i = 0; i < pathParts.length; i++) {\n\t\t\tconst pathPart = pathParts[i];\n\n\t\t\t// Is the path part numeric i.e. an array index.\n\t\t\tconst arrayMatch = /^(\\d+)$/.exec(pathPart);\n\t\t\tconst arrayIndex = arrayMatch ? Number.parseInt(arrayMatch[1], 10) : -1;\n\n\t\t\tif (i === pathParts.length - 1) {\n\t\t\t\t// Last part of path so set the value\n\t\t\t\tif (arrayIndex >= 0) {\n\t\t\t\t\tif (Is.array(pathValue)) {\n\t\t\t\t\t\tpathValue[arrayIndex] = value;\n\t\t\t\t\t} else if (Is.object(pathValue)) {\n\t\t\t\t\t\tpathValue[arrayIndex] = value;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new GeneralError(ObjectHelper.CLASS_NAME, \"cannotSetArrayIndex\", {\n\t\t\t\t\t\t\tproperty,\n\t\t\t\t\t\t\tindex: arrayIndex\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t} else if (Is.object(pathValue)) {\n\t\t\t\t\tpathValue[pathPart] = value;\n\t\t\t\t} else {\n\t\t\t\t\tthrow new GeneralError(ObjectHelper.CLASS_NAME, \"cannotSetProperty\", { property });\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tparentObj = pathValue;\n\t\t\t\tif (Is.object(pathValue)) {\n\t\t\t\t\tpathValue = pathValue[pathPart];\n\t\t\t\t} else if (Is.array(pathValue)) {\n\t\t\t\t\tpathValue = pathValue[arrayIndex];\n\t\t\t\t}\n\n\t\t\t\tif (Is.empty(pathValue)) {\n\t\t\t\t\tconst nextArrayMatch = /^(\\d+)$/.exec(pathParts[i + 1]);\n\t\t\t\t\tconst nextArrayIndex = nextArrayMatch ? Number.parseInt(nextArrayMatch[1], 10) : -1;\n\n\t\t\t\t\tif (nextArrayIndex >= 0) {\n\t\t\t\t\t\tpathValue = [];\n\t\t\t\t\t} else {\n\t\t\t\t\t\tpathValue = {};\n\t\t\t\t\t}\n\n\t\t\t\t\tif (Is.object(parentObj)) {\n\t\t\t\t\t\tparentObj[pathPart] = pathValue;\n\t\t\t\t\t} else if (Is.array(parentObj)) {\n\t\t\t\t\t\tparentObj[arrayIndex] = pathValue;\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 * Delete the property of an unknown object.\n\t * @param object The object to delete the property from.\n\t * @param property The property to delete.\n\t */\n\tpublic static propertyDelete(object: unknown, property: string): void {\n\t\tGuards.object(ObjectHelper.CLASS_NAME, nameof(object), object);\n\t\tGuards.stringValue(ObjectHelper.CLASS_NAME, nameof(property), property);\n\t\tif (Is.object(object)) {\n\t\t\tdelete object[property];\n\t\t}\n\t}\n\n\t/**\n\t * Extract a property from the object, providing alternative names.\n\t * @param obj The object to extract from.\n\t * @param propertyNames The possible names for the property.\n\t * @param removeProperties Remove the properties from the object, defaults to true.\n\t * @returns The property if available.\n\t */\n\tpublic static extractProperty<T>(\n\t\tobj: unknown,\n\t\tpropertyNames: string | string[],\n\t\tremoveProperties: boolean = true\n\t): T | undefined {\n\t\tlet retVal: T | undefined;\n\n\t\tif (Is.object(obj)) {\n\t\t\tconst names = Is.string(propertyNames) ? [propertyNames] : propertyNames;\n\n\t\t\tfor (const prop of names) {\n\t\t\t\tretVal ??= ObjectHelper.propertyGet<T>(obj, prop);\n\t\t\t\tif (removeProperties) {\n\t\t\t\t\tObjectHelper.propertyDelete(obj, prop);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn retVal;\n\t}\n\n\t/**\n\t * Pick a subset of properties from an object.\n\t * @param obj The object to pick the properties from.\n\t * @param keys The property keys to pick.\n\t * @returns The picked object.\n\t */\n\tpublic static pick<T, K extends keyof T>(obj: T, keys?: K[]): Pick<T, K>;\n\t/**\n\t * Pick a subset of properties from an object.\n\t * @param obj The object to pick the properties from.\n\t * @param keys The property keys to pick.\n\t * @returns The picked object, or undefined if the input was undefined.\n\t */\n\tpublic static pick<T, K extends keyof T>(obj: T | undefined, keys?: K[]): Pick<T, K> | undefined;\n\t/**\n\t * Pick a subset of properties from an object.\n\t * @param obj The object to pick the properties from.\n\t * @param keys The property keys to pick.\n\t * @returns The picked object, or undefined if the input was undefined.\n\t */\n\tpublic static pick<T, K extends keyof T>(obj: T | undefined, keys?: K[]): Pick<T, K> | undefined {\n\t\tif (Is.object(obj)) {\n\t\t\tconst result = {} as Pick<T, K>;\n\t\t\tif (Is.arrayValue(keys)) {\n\t\t\t\tfor (const key of keys) {\n\t\t\t\t\tresult[key] = obj[key];\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Omit a subset of properties from an object.\n\t * @param obj The object to omit the properties from.\n\t * @param keys The property keys to omit.\n\t * @returns The object without the omitted keys.\n\t */\n\tpublic static omit<T, K extends keyof T>(obj: T, keys?: K[]): Omit<T, K>;\n\t/**\n\t * Omit a subset of properties from an object.\n\t * @param obj The object to omit the properties from.\n\t * @param keys The property keys to omit.\n\t * @returns The object without the omitted keys, or undefined if the input was undefined.\n\t */\n\tpublic static omit<T, K extends keyof T>(obj: T | undefined, keys?: K[]): Omit<T, K> | undefined;\n\t/**\n\t * Omit a subset of properties from an object.\n\t * @param obj The object to omit the properties from.\n\t * @param keys The property keys to omit.\n\t * @returns The object without the omitted keys, or undefined if the input was undefined.\n\t */\n\tpublic static omit<T, K extends keyof T>(obj: T | undefined, keys?: K[]): Omit<T, K> {\n\t\tif (Is.object(obj) && Is.arrayValue(keys)) {\n\t\t\tconst result = ObjectHelper.clone(obj);\n\t\t\tfor (const key of keys) {\n\t\t\t\tdelete result[key];\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\treturn obj as Omit<T, K>;\n\t}\n\n\t/**\n\t * Convert the non JSON primitives to extended types.\n\t * @param obj The object to convert.\n\t * @returns The object with extended properties.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic static toExtended(obj: any): any {\n\t\tconst jsonExtended = JsonHelper.stringifyEx(obj);\n\t\treturn JSON.parse(jsonExtended);\n\t}\n\n\t/**\n\t * Convert the extended types to non JSON primitives.\n\t * @param obj The object to convert.\n\t * @returns The object with regular properties.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic static fromExtended(obj: any): any {\n\t\tconst jsonExtended = JsonHelper.stringifyEx(obj);\n\t\treturn JsonHelper.parseEx(jsonExtended);\n\t}\n\n\t/**\n\t * Remove empty properties from an object.\n\t * @param obj The object to remove the empty properties from.\n\t * @param options The options for the removal.\n\t * @param options.removeUndefined Remove undefined properties, defaults to true.\n\t * @param options.removeNull Remove null properties, defaults to false.\n\t * @returns The object with empty properties removed.\n\t */\n\tpublic static removeEmptyProperties<T = unknown>(\n\t\tobj: T,\n\t\toptions?: { removeUndefined?: boolean; removeNull?: boolean }\n\t): T {\n\t\tif (Is.object(obj)) {\n\t\t\tconst removeUndefined = options?.removeUndefined ?? true;\n\t\t\tconst removeNull = options?.removeNull ?? false;\n\t\t\tconst newObj: { [id: string]: unknown } = {};\n\t\t\tconst keys = Object.keys(obj);\n\t\t\tfor (const key of keys) {\n\t\t\t\tif (!((removeUndefined && Is.undefined(obj[key])) || (removeNull && Is.null(obj[key])))) {\n\t\t\t\t\tnewObj[key] = ObjectHelper.removeEmptyProperties(obj[key], options);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn newObj as T;\n\t\t} else if (Is.array(obj)) {\n\t\t\tconst arr = [];\n\t\t\tfor (const element of obj) {\n\t\t\t\tarr.push(ObjectHelper.removeEmptyProperties(element, options));\n\t\t\t}\n\t\t\treturn arr as T;\n\t\t}\n\t\treturn obj;\n\t}\n}\n"]}
@@ -43,25 +43,25 @@ export declare class ObjectHelper {
43
43
  static equal<T>(obj1: T, obj2: T, strictPropertyOrder?: boolean): boolean;
44
44
  /**
45
45
  * Get the property of an unknown object.
46
- * @param obj The object to get the property from.
46
+ * @param object The object to get the property from.
47
47
  * @param property The property to get, can be separated by dots for nested path.
48
48
  * @returns The property.
49
49
  */
50
- static propertyGet<T = unknown>(obj: unknown, property: string): T | undefined;
50
+ static propertyGet<T = unknown>(object: unknown, property: string): T | undefined;
51
51
  /**
52
52
  * Set the property of an unknown object.
53
- * @param obj The object to set the property from.
53
+ * @param object The object to set the property from.
54
54
  * @param property The property to set.
55
55
  * @param value The value to set.
56
56
  * @throws GeneralError if the property target is not an object.
57
57
  */
58
- static propertySet(obj: unknown, property: string, value: unknown): void;
58
+ static propertySet(object: unknown, property: string, value: unknown): void;
59
59
  /**
60
60
  * Delete the property of an unknown object.
61
- * @param obj The object to delete the property from.
61
+ * @param object The object to delete the property from.
62
62
  * @param property The property to delete.
63
63
  */
64
- static propertyDelete(obj: unknown, property: string): void;
64
+ static propertyDelete(object: unknown, property: string): void;
65
65
  /**
66
66
  * Extract a property from the object, providing alternative names.
67
67
  * @param obj The object to extract from.
package/docs/changelog.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.9.2-next.8](https://github.com/iotaledger/twin-framework/compare/core-v0.9.2-next.7...core-v0.9.2-next.8) (2026-08-10)
4
+
5
+
6
+ ### Features
7
+
8
+ * optimistic locking version property for schemas ([#443](https://github.com/iotaledger/twin-framework/issues/443)) ([1b90987](https://github.com/iotaledger/twin-framework/commit/1b909875dc915a0ec133d8424d013ae7e4ddfb48))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/nameof bumped from 0.9.2-next.7 to 0.9.2-next.8
16
+ * devDependencies
17
+ * @twin.org/nameof-transformer bumped from 0.9.2-next.7 to 0.9.2-next.8
18
+ * @twin.org/nameof-vitest-plugin bumped from 0.9.2-next.7 to 0.9.2-next.8
19
+
3
20
  ## [0.9.2-next.7](https://github.com/iotaledger/twin-framework/compare/core-v0.9.2-next.6...core-v0.9.2-next.7) (2026-08-07)
4
21
 
5
22
 
@@ -196,7 +196,7 @@ True is the objects are equal.
196
196
 
197
197
  ### propertyGet() {#propertyget}
198
198
 
199
- > `static` **propertyGet**\<`T`\>(`obj`, `property`): `T` \| `undefined`
199
+ > `static` **propertyGet**\<`T`\>(`object`, `property`): `T` \| `undefined`
200
200
 
201
201
  Get the property of an unknown object.
202
202
 
@@ -208,7 +208,7 @@ Get the property of an unknown object.
208
208
 
209
209
  #### Parameters
210
210
 
211
- ##### obj
211
+ ##### object
212
212
 
213
213
  `unknown`
214
214
 
@@ -230,13 +230,13 @@ The property.
230
230
 
231
231
  ### propertySet() {#propertyset}
232
232
 
233
- > `static` **propertySet**(`obj`, `property`, `value`): `void`
233
+ > `static` **propertySet**(`object`, `property`, `value`): `void`
234
234
 
235
235
  Set the property of an unknown object.
236
236
 
237
237
  #### Parameters
238
238
 
239
- ##### obj
239
+ ##### object
240
240
 
241
241
  `unknown`
242
242
 
@@ -266,13 +266,13 @@ GeneralError if the property target is not an object.
266
266
 
267
267
  ### propertyDelete() {#propertydelete}
268
268
 
269
- > `static` **propertyDelete**(`obj`, `property`): `void`
269
+ > `static` **propertyDelete**(`object`, `property`): `void`
270
270
 
271
271
  Delete the property of an unknown object.
272
272
 
273
273
  #### Parameters
274
274
 
275
- ##### obj
275
+ ##### object
276
276
 
277
277
  `unknown`
278
278
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/core",
3
- "version": "0.9.2-next.7",
3
+ "version": "0.9.2-next.8",
4
4
  "description": "Helper methods/classes for data type checking/validation/guarding/error handling",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,7 +14,7 @@
14
14
  "node": ">=24.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@twin.org/nameof": "0.9.2-next.7",
17
+ "@twin.org/nameof": "0.9.2-next.8",
18
18
  "intl-messageformat": "11.2.13",
19
19
  "rfc6902": "5.3.0"
20
20
  },