@openforis/arena-core 2.18.18 → 2.18.20

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.
@@ -24,8 +24,12 @@ export const addNodes = (nodes, options = RecordUpdateOptionsDefaults) => (recor
24
24
  else {
25
25
  recordUpdated.nodes = Object.assign(Object.assign({}, recordNodes), nodes);
26
26
  }
27
- if (updateNodesIndex && Object.keys(nodesToIndex).length > 0) {
28
- recordUpdated._nodesIndex = RecordNodesIndexUpdater.addNodes(nodesToIndex, { sideEffect, sortNodes })(index);
27
+ if (updateNodesIndex) {
28
+ // store the index even with no nodes to add: it could have just been built, avoid building it again
29
+ recordUpdated._nodesIndex =
30
+ Object.keys(nodesToIndex).length > 0
31
+ ? RecordNodesIndexUpdater.addNodes(nodesToIndex, { sideEffect, sortNodes })(index)
32
+ : index;
29
33
  }
30
34
  return recordUpdated;
31
35
  };
@@ -1 +1 @@
1
- {"version":3,"file":"recordUpdater.js","sourceRoot":"","sources":["../../../../src/record/_records/recordUpdater.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,aAAa,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAA;AACnE,OAAO,EAAuB,2BAA2B,EAAE,MAAM,uBAAuB,CAAA;AAExF,MAAM,CAAC,MAAM,QAAQ,GACnB,CAAC,KAAyC,EAAE,OAAO,GAAwB,2BAA2B,EAAE,EAAE,CAC1G,CAAC,MAAmB,EAAe,EAAE;IACnC,MAAM,EAAE,UAAU,EAAE,gBAAgB,EAAE,SAAS,EAAE,mCAAQ,2BAA2B,GAAK,OAAO,CAAE,CAAA;IAElG,MAAM,aAAa,GAAG,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,mBAAM,MAAM,CAAE,CAAA;IACzD,MAAM,WAAW,GAAG,aAAa,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAA;IACzD,iGAAiG;IACjG,MAAM,KAAK,GAAG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,EAAE,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC,CAAA","sourcesContent":["import { ArenaRecordNode } from '../../node'\nimport { ArenaRecord } from '../record'\nimport * as RecordGetters from './recordGetters'\nimport { RecordNodesIndexUpdater } from './recordNodesIndexUpdater'\nimport { RecordUpdateOptions, RecordUpdateOptionsDefaults } from './recordUpdateOptions'\n\nexport const addNodes =\n (nodes: { [key: string]: ArenaRecordNode }, options: RecordUpdateOptions = RecordUpdateOptionsDefaults) =>\n (record: ArenaRecord): ArenaRecord => {\n const { sideEffect, updateNodesIndex, sortNodes } = { ...RecordUpdateOptionsDefaults, ...options }\n\n const recordUpdated = sideEffect ? record : { ...record }\n const recordNodes = RecordGetters.getNodes(recordUpdated)\n // index got before adding the new nodes (a missing index is built from the current record nodes)\n const index = updateNodesIndex ? RecordGetters.getNodesIndexOrBuild(recordUpdated) : {}\n\n // index only the nodes not already indexed with the same parent, node def and hierarchy code\n // (e.g. nodes with only an updated value don't need any index change)\n const nodesToIndex: { [key: string]: ArenaRecordNode } = {}\n if (updateNodesIndex) {\n for (const [nodeUuid, node] of Object.entries(nodes)) {\n const nodePrev = recordNodes[nodeUuid]\n if (!RecordNodesIndexUpdater.isNodeIndexUnchanged({ index, node, nodePrev })) {\n nodesToIndex[nodeUuid] = node\n }\n }\n }\n\n if (sideEffect) {\n recordUpdated.nodes = Object.assign(recordNodes, nodes)\n } else {\n recordUpdated.nodes = { ...recordNodes, ...nodes }\n }\n if (updateNodesIndex && Object.keys(nodesToIndex).length > 0) {\n recordUpdated._nodesIndex = RecordNodesIndexUpdater.addNodes(nodesToIndex, { sideEffect, sortNodes })(index)\n }\n return recordUpdated\n }\n\nexport const addNode =\n (node: ArenaRecordNode, options: RecordUpdateOptions = RecordUpdateOptionsDefaults) =>\n (record: ArenaRecord) =>\n addNodes({ [node.uuid]: node }, options)(record)\n"]}
1
+ {"version":3,"file":"recordUpdater.js","sourceRoot":"","sources":["../../../../src/record/_records/recordUpdater.ts"],"names":[],"m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CAAA;IACzD,CAAC;SAAM,CAAC;QACN,aAAa,CAAC,KAAK,mCAAQ,WAAW,GAAK,KAAK,CAAE,CAAA;IACpD,CAAC;IACD,IAAI,gBAAgB,EAAE,CAAC;QACrB,oGAAoG;QACpG,aAAa,CAAC,WAAW;YACvB,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,MAAM,GAAG,CAAC;gBAClC,CAAC,CAAC,uBAAuB,CAAC,QAAQ,CAAC,YAAY,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC;gBAClF,CAAC,CAAC,KAAK,CAAA;IACb,CAAC;IACD,OAAO,aAAa,CAAA;AACtB,CAAC,CAAA;AAEH,MAAM,CAAC,MAAM,OAAO,GAClB,CAAC,IAAqB,EAAE,OAAO,GAAwB,2BAA2B,EAAE,EAAE,CACtF,CAAC,MAAmB,EAAE,EAAE,CACtB,QAAQ,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC,CAAA","sourcesContent":["import { ArenaRecordNode } from '../../node'\nimport { ArenaRecord } from '../record'\nimport * as RecordGetters from './recordGetters'\nimport { RecordNodesIndexUpdater } from './recordNodesIndexUpdater'\nimport { RecordUpdateOptions, RecordUpdateOptionsDefaults } from './recordUpdateOptions'\n\nexport const addNodes =\n (nodes: { [key: string]: ArenaRecordNode }, options: RecordUpdateOptions = RecordUpdateOptionsDefaults) =>\n (record: ArenaRecord): ArenaRecord => {\n const { sideEffect, updateNodesIndex, sortNodes } = { ...RecordUpdateOptionsDefaults, ...options }\n\n const recordUpdated = sideEffect ? record : { ...record }\n const recordNodes = RecordGetters.getNodes(recordUpdated)\n // index got before adding the new nodes (a missing index is built from the current record nodes)\n const index = updateNodesIndex ? RecordGetters.getNodesIndexOrBuild(recordUpdated) : {}\n\n // index only the nodes not already indexed with the same parent, node def and hierarchy code\n // (e.g. nodes with only an updated value don't need any index change)\n const nodesToIndex: { [key: string]: ArenaRecordNode } = {}\n if (updateNodesIndex) {\n for (const [nodeUuid, node] of Object.entries(nodes)) {\n const nodePrev = recordNodes[nodeUuid]\n if (!RecordNodesIndexUpdater.isNodeIndexUnchanged({ index, node, nodePrev })) {\n nodesToIndex[nodeUuid] = node\n }\n }\n }\n\n if (sideEffect) {\n recordUpdated.nodes = Object.assign(recordNodes, nodes)\n } else {\n recordUpdated.nodes = { ...recordNodes, ...nodes }\n }\n if (updateNodesIndex) {\n // store the index even with no nodes to add: it could have just been built, avoid building it again\n recordUpdated._nodesIndex =\n Object.keys(nodesToIndex).length > 0\n ? RecordNodesIndexUpdater.addNodes(nodesToIndex, { sideEffect, sortNodes })(index)\n : index\n }\n return recordUpdated\n }\n\nexport const addNode =\n (node: ArenaRecordNode, options: RecordUpdateOptions = RecordUpdateOptionsDefaults) =>\n (record: ArenaRecord) =>\n addNodes({ [node.uuid]: node }, options)(record)\n"]}
@@ -1,6 +1,7 @@
1
+ import { shallowCopy } from './shallowCopy';
1
2
  const _assocPath = (obj, path, pathIndex, value, sideEffect) => {
2
3
  // only one copy per path level (when sideEffect is false)
3
- const objUpdated = sideEffect ? obj : Object.assign({}, obj);
4
+ const objUpdated = sideEffect ? obj : shallowCopy(obj);
4
5
  if (pathIndex >= path.length)
5
6
  return objUpdated;
6
7
  const pathPart = path[pathIndex];
@@ -1 +1 @@
1
- {"version":3,"file":"assocPath.js","sourceRoot":"","sources":["../../../../src/utils/_objects/assocPath.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,GAAG,CAAC,GAAQ,EAAE,IAAc,EAAE,SAAiB,EAAE,KAAU,EAAE,UAAmB,EAAO,EAAE;IACvG,0DAA0D;IAC1D,MAAM,UAAU,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,mBAAM,GAAG,CAAE,CAAA;IAChD,IAAI,SAAS,IAAI,IAAI,CAAC,MAAM;QAAE,OAAO,UAAU,CAAA;IAE/C,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,CAAA;IAChC,UAAU,CAAC,QAAQ,CAAC;QAClB,SAAS,KAAK,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAG,QAAQ,CAAC,KAAI,EAAE,EAAE,IAAI,EAAE,SAAS,GAAG,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,CAAA;IACnH,OAAO,UAAU,CAAA;AACnB,CAAC,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAmB,MAK3C,EAAK,EAAE;IACN,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,GAAG,KAAK,EAAE,GAAG,MAAM,CAAA;IACvD,OAAO,UAAU,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,CAAA;AACpD,CAAC,CAAA","sourcesContent":["const _assocPath = (obj: any, path: string[], pathIndex: number, value: any, sideEffect: boolean): any => {\n // only one copy per path level (when sideEffect is false)\n const objUpdated = sideEffect ? obj : { ...obj }\n if (pathIndex >= path.length) return objUpdated\n\n const pathPart = path[pathIndex]\n objUpdated[pathPart] =\n pathIndex === path.length - 1 ? value : _assocPath(obj?.[pathPart] || {}, path, pathIndex + 1, value, sideEffect)\n return objUpdated\n}\n\n/**\n * Sets the value at the specified path, creating the missing intermediate objects.\n * Returns a copy of the object (with one copy per path level), or the object itself when sideEffect is true.\n */\nexport const assocPath = <T extends object>(params: {\n obj: T\n path: string[]\n value: unknown\n sideEffect?: boolean\n}): T => {\n const { obj, path, value, sideEffect = false } = params\n return _assocPath(obj, path, 0, value, sideEffect)\n}\n"]}
1
+ {"version":3,"file":"assocPath.js","sourceRoot":"","sources":["../../../../src/utils/_objects/assocPath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE3C,MAAM,UAAU,GAAG,CAAC,GAAQ,EAAE,IAAc,EAAE,SAAiB,EAAE,KAAU,EAAE,UAAmB,EAAO,EAAE;IACvG,0DAA0D;IAC1D,MAAM,UAAU,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;IACtD,IAAI,SAAS,IAAI,IAAI,CAAC,MAAM;QAAE,OAAO,UAAU,CAAA;IAE/C,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,CAAA;IAChC,UAAU,CAAC,QAAQ,CAAC;QAClB,SAAS,KAAK,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAG,QAAQ,CAAC,KAAI,EAAE,EAAE,IAAI,EAAE,SAAS,GAAG,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,CAAA;IACnH,OAAO,UAAU,CAAA;AACnB,CAAC,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAmB,MAK3C,EAAK,EAAE;IACN,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,GAAG,KAAK,EAAE,GAAG,MAAM,CAAA;IACvD,OAAO,UAAU,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,CAAA;AACpD,CAAC,CAAA","sourcesContent":["import { shallowCopy } from './shallowCopy'\n\nconst _assocPath = (obj: any, path: string[], pathIndex: number, value: any, sideEffect: boolean): any => {\n // only one copy per path level (when sideEffect is false)\n const objUpdated = sideEffect ? obj : shallowCopy(obj)\n if (pathIndex >= path.length) return objUpdated\n\n const pathPart = path[pathIndex]\n objUpdated[pathPart] =\n pathIndex === path.length - 1 ? value : _assocPath(obj?.[pathPart] || {}, path, pathIndex + 1, value, sideEffect)\n return objUpdated\n}\n\n/**\n * Sets the value at the specified path, creating the missing intermediate objects.\n * Returns a copy of the object (with one copy per path level), or the object itself when sideEffect is true.\n */\nexport const assocPath = <T extends object>(params: {\n obj: T\n path: string[]\n value: unknown\n sideEffect?: boolean\n}): T => {\n const { obj, path, value, sideEffect = false } = params\n return _assocPath(obj, path, 0, value, sideEffect)\n}\n"]}
@@ -1,7 +1,8 @@
1
1
  import { isEmpty } from './isEmpty';
2
+ import { shallowCopy } from './shallowCopy';
2
3
  export const dissocPath = (params) => {
3
4
  const { obj, path, sideEffect = false } = params;
4
- const objUpdated = sideEffect ? obj : Object.assign({}, obj);
5
+ const objUpdated = sideEffect ? obj : shallowCopy(obj);
5
6
  if (path.length === 0) {
6
7
  return objUpdated;
7
8
  }
@@ -1 +1 @@
1
- {"version":3,"file":"dissocPath.js","sourceRoot":"","sources":["../../../../src/utils/_objects/dissocPath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,MAAM,CAAC,MAAM,UAAU,GAAG,CAAmB,MAAwD,EAAK,EAAE;IAC1G,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,GAAG,KAAK,EAAE,GAAG,MAAM,CAAA;IAChD,MAAM,UAAU,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,mBAAM,GAAG,CAAE,CAAA;IAEhD,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,OAAO,UAAU,CAAA;IACnB,CAAC;IAED,MAAM,CAAC,mBAAmB,EAAE,GAAG,cAAc,CAAC,GAAG,IAAI,CAAA;IACrD,MAAM,aAAa,GAAG,mBAA8C,CAAA;IAEpE,MAAM,OAAO,GAAQ,UAAU,CAAC,aAAa,CAAC,CAAA;IAE9C,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACpD,OAAO,UAAU,CAAC,aAAa,CAAC,CAAA;QAChC,OAAO,UAAU,CAAA;IACnB,CAAC;IAED,oEAAoE;IACpE,MAAM,cAAc,GAAG,UAAU,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,UAAU,EAAE,CAAC,CAAA;IAErF,IAAI,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC;QAC5B,OAAO,UAAU,CAAC,aAAa,CAAC,CAAA;QAChC,OAAO,UAAU,CAAA;IACnB,CAAC;IAED,UAAU,CAAC,aAAa,CAAC,GAAG,cAAc,CAAA;IAC1C,OAAO,UAAU,CAAA;AACnB,CAAC,CAAA","sourcesContent":["import { isEmpty } from './isEmpty'\n\nexport const dissocPath = <T extends object>(params: { obj: T; path: string[]; sideEffect?: boolean }): T => {\n const { obj, path, sideEffect = false } = params\n const objUpdated = sideEffect ? obj : { ...obj }\n\n if (path.length === 0) {\n return objUpdated\n }\n\n const [firstPathPartString, ...otherPathParts] = path\n const firstPathPart = firstPathPartString as keyof typeof objUpdated\n\n const objPart: any = objUpdated[firstPathPart]\n\n if (otherPathParts.length === 0 || isEmpty(objPart)) {\n delete objUpdated[firstPathPart]\n return objUpdated\n }\n\n // objPart is copied by dissocPath itself (when sideEffect is false)\n const objPartUpdated = dissocPath({ obj: objPart, path: otherPathParts, sideEffect })\n\n if (isEmpty(objPartUpdated)) {\n delete objUpdated[firstPathPart]\n return objUpdated\n }\n\n objUpdated[firstPathPart] = objPartUpdated\n return objUpdated\n}\n"]}
1
+ {"version":3,"file":"dissocPath.js","sourceRoot":"","sources":["../../../../src/utils/_objects/dissocPath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE3C,MAAM,CAAC,MAAM,UAAU,GAAG,CAAmB,MAAwD,EAAK,EAAE;IAC1G,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,GAAG,KAAK,EAAE,GAAG,MAAM,CAAA;IAChD,MAAM,UAAU,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;IAEtD,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,OAAO,UAAU,CAAA;IACnB,CAAC;IAED,MAAM,CAAC,mBAAmB,EAAE,GAAG,cAAc,CAAC,GAAG,IAAI,CAAA;IACrD,MAAM,aAAa,GAAG,mBAA8C,CAAA;IAEpE,MAAM,OAAO,GAAQ,UAAU,CAAC,aAAa,CAAC,CAAA;IAE9C,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACpD,OAAO,UAAU,CAAC,aAAa,CAAC,CAAA;QAChC,OAAO,UAAU,CAAA;IACnB,CAAC;IAED,oEAAoE;IACpE,MAAM,cAAc,GAAG,UAAU,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,UAAU,EAAE,CAAC,CAAA;IAErF,IAAI,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC;QAC5B,OAAO,UAAU,CAAC,aAAa,CAAC,CAAA;QAChC,OAAO,UAAU,CAAA;IACnB,CAAC;IAED,UAAU,CAAC,aAAa,CAAC,GAAG,cAAc,CAAA;IAC1C,OAAO,UAAU,CAAA;AACnB,CAAC,CAAA","sourcesContent":["import { isEmpty } from './isEmpty'\nimport { shallowCopy } from './shallowCopy'\n\nexport const dissocPath = <T extends object>(params: { obj: T; path: string[]; sideEffect?: boolean }): T => {\n const { obj, path, sideEffect = false } = params\n const objUpdated = sideEffect ? obj : shallowCopy(obj)\n\n if (path.length === 0) {\n return objUpdated\n }\n\n const [firstPathPartString, ...otherPathParts] = path\n const firstPathPart = firstPathPartString as keyof typeof objUpdated\n\n const objPart: any = objUpdated[firstPathPart]\n\n if (otherPathParts.length === 0 || isEmpty(objPart)) {\n delete objUpdated[firstPathPart]\n return objUpdated\n }\n\n // objPart is copied by dissocPath itself (when sideEffect is false)\n const objPartUpdated = dissocPath({ obj: objPart, path: otherPathParts, sideEffect })\n\n if (isEmpty(objPartUpdated)) {\n delete objUpdated[firstPathPart]\n return objUpdated\n }\n\n objUpdated[firstPathPart] = objPartUpdated\n return objUpdated\n}\n"]}
@@ -1,6 +1,7 @@
1
1
  import { isEmpty } from './isEmpty';
2
2
  /**
3
- * Sets the value at the specified path in the object itself (side effect), creating the missing intermediate objects.
3
+ * Sets the value at the specified path in the object itself (side effect), creating the missing intermediate objects
4
+ * (null or non-object intermediate values are replaced with new objects).
4
5
  * When excludeEmpty is true, empty values are not set.
5
6
  */
6
7
  export const setInPath = (params) => {
@@ -12,7 +13,9 @@ export const setInPath = (params) => {
12
13
  objCurrent[pathPart] = value;
13
14
  }
14
15
  else {
15
- if (!Object.hasOwn(objCurrent, pathPart)) {
16
+ const valueCurrent = Object.hasOwn(objCurrent, pathPart) ? objCurrent[pathPart] : undefined;
17
+ if (valueCurrent === null || (typeof valueCurrent !== 'object' && typeof valueCurrent !== 'function')) {
18
+ // missing, null or primitive intermediate value: replace it with a new object
16
19
  objCurrent[pathPart] = {};
17
20
  }
18
21
  objCurrent = objCurrent[pathPart];
@@ -1 +1 @@
1
- {"version":3,"file":"setInPath.js","sourceRoot":"","sources":["../../../../src/utils/_objects/setInPath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAmB,MAK3C,EAAK,EAAE;IACN,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,YAAY,EAAE,GAAG,MAAM,CAAA;IACjD,IAAI,CAAC,YAAY,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACrC,IAAI,UAAU,GAAQ,GAAG,CAAA;QACzB,IAAI,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE;YAC3B,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC1B,UAAU,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAA;YAC9B,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,EAAE,CAAC;oBACzC,UAAU,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAA;gBAC3B,CAAC;gBACD,UAAU,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAA;YACnC,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA","sourcesContent":["import { isEmpty } from './isEmpty'\n\n/**\n * Sets the value at the specified path in the object itself (side effect), creating the missing intermediate objects.\n * When excludeEmpty is true, empty values are not set.\n */\nexport const setInPath = <T extends object>(params: {\n obj: T\n path: string[]\n value: unknown\n excludeEmpty?: boolean\n}): T => {\n const { obj, path, value, excludeEmpty } = params\n if (!excludeEmpty || !isEmpty(value)) {\n let objCurrent: any = obj\n path.forEach((pathPart, i) => {\n if (i === path.length - 1) {\n objCurrent[pathPart] = value\n } else {\n if (!Object.hasOwn(objCurrent, pathPart)) {\n objCurrent[pathPart] = {}\n }\n objCurrent = objCurrent[pathPart]\n }\n })\n }\n return obj\n}\n"]}
1
+ {"version":3,"file":"setInPath.js","sourceRoot":"","sources":["../../../../src/utils/_objects/setInPath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAmB,MAK3C,EAAK,EAAE;IACN,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,YAAY,EAAE,GAAG,MAAM,CAAA;IACjD,IAAI,CAAC,YAAY,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACrC,IAAI,UAAU,GAAQ,GAAG,CAAA;QACzB,IAAI,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE;YAC3B,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC1B,UAAU,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAA;YAC9B,CAAC;iBAAM,CAAC;gBACN,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;gBAC3F,IAAI,YAAY,KAAK,IAAI,IAAI,CAAC,OAAO,YAAY,KAAK,QAAQ,IAAI,OAAO,YAAY,KAAK,UAAU,CAAC,EAAE,CAAC;oBACtG,8EAA8E;oBAC9E,UAAU,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAA;gBAC3B,CAAC;gBACD,UAAU,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAA;YACnC,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA","sourcesContent":["import { isEmpty } from './isEmpty'\n\n/**\n * Sets the value at the specified path in the object itself (side effect), creating the missing intermediate objects\n * (null or non-object intermediate values are replaced with new objects).\n * When excludeEmpty is true, empty values are not set.\n */\nexport const setInPath = <T extends object>(params: {\n obj: T\n path: string[]\n value: unknown\n excludeEmpty?: boolean\n}): T => {\n const { obj, path, value, excludeEmpty } = params\n if (!excludeEmpty || !isEmpty(value)) {\n let objCurrent: any = obj\n path.forEach((pathPart, i) => {\n if (i === path.length - 1) {\n objCurrent[pathPart] = value\n } else {\n const valueCurrent = Object.hasOwn(objCurrent, pathPart) ? objCurrent[pathPart] : undefined\n if (valueCurrent === null || (typeof valueCurrent !== 'object' && typeof valueCurrent !== 'function')) {\n // missing, null or primitive intermediate value: replace it with a new object\n objCurrent[pathPart] = {}\n }\n objCurrent = objCurrent[pathPart]\n }\n })\n }\n return obj\n}\n"]}
@@ -0,0 +1,3 @@
1
+ // arrays are copied as arrays
2
+ export const shallowCopy = (obj) => (Array.isArray(obj) ? [...obj] : Object.assign({}, obj));
3
+ //# sourceMappingURL=shallowCopy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shallowCopy.js","sourceRoot":"","sources":["../../../../src/utils/_objects/shallowCopy.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,MAAM,CAAC,MAAM,WAAW,GAAG,CAAmB,GAAM,EAAK,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,mBAAM,GAAG,CAAE,CAAM,CAAA","sourcesContent":["// arrays are copied as arrays\nexport const shallowCopy = <T extends object>(obj: T): T => (Array.isArray(obj) ? [...obj] : { ...obj }) as T\n"]}
@@ -60,8 +60,12 @@ const addNodes = (nodes, options = recordUpdateOptions_1.RecordUpdateOptionsDefa
60
60
  else {
61
61
  recordUpdated.nodes = Object.assign(Object.assign({}, recordNodes), nodes);
62
62
  }
63
- if (updateNodesIndex && Object.keys(nodesToIndex).length > 0) {
64
- recordUpdated._nodesIndex = recordNodesIndexUpdater_1.RecordNodesIndexUpdater.addNodes(nodesToIndex, { sideEffect, sortNodes })(index);
63
+ if (updateNodesIndex) {
64
+ // store the index even with no nodes to add: it could have just been built, avoid building it again
65
+ recordUpdated._nodesIndex =
66
+ Object.keys(nodesToIndex).length > 0
67
+ ? recordNodesIndexUpdater_1.RecordNodesIndexUpdater.addNodes(nodesToIndex, { sideEffect, sortNodes })(index)
68
+ : index;
65
69
  }
66
70
  return recordUpdated;
67
71
  };
@@ -1 +1 @@
1
- {"version":3,"file":"recordUpdater.js","sourceRoot":"","sources":["../../../src/record/_records/recordUpdater.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,MAA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,IAAI,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7D,aAAa,CAAC,WAAW,GAAG,iDAAuB,CAAC,QAAQ,CAAC,YAAY,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,CAAA;IAC9G,CAAC;IACD,OAAO,aAAa,CAAA;AACtB,CAAC,CAAA;AA/BU,QAAA,QAAQ,GAAR,QAAQ,CA+BlB;AAEI,MAAM,OAAO,GAClB,CAAC,IAAqB,EAAE,OAAO,GAAwB,iDAA2B,EAAE,EAAE,CACtF,CAAC,MAAmB,EAAE,EAAE,CACtB,IAAA,QAAA,QAAQ,EAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC,CAAA;AAHvC,QAAA,OAAO,GAAP,OAAO,CAGgC","sourcesContent":["import { ArenaRecordNode } from '../../node'\nimport { ArenaRecord } from '../record'\nimport * as RecordGetters from './recordGetters'\nimport { RecordNodesIndexUpdater } from './recordNodesIndexUpdater'\nimport { RecordUpdateOptions, RecordUpdateOptionsDefaults } from './recordUpdateOptions'\n\nexport const addNodes =\n (nodes: { [key: string]: ArenaRecordNode }, options: RecordUpdateOptions = RecordUpdateOptionsDefaults) =>\n (record: ArenaRecord): ArenaRecord => {\n const { sideEffect, updateNodesIndex, sortNodes } = { ...RecordUpdateOptionsDefaults, ...options }\n\n const recordUpdated = sideEffect ? record : { ...record }\n const recordNodes = RecordGetters.getNodes(recordUpdated)\n // index got before adding the new nodes (a missing index is built from the current record nodes)\n const index = updateNodesIndex ? RecordGetters.getNodesIndexOrBuild(recordUpdated) : {}\n\n // index only the nodes not already indexed with the same parent, node def and hierarchy code\n // (e.g. nodes with only an updated value don't need any index change)\n const nodesToIndex: { [key: string]: ArenaRecordNode } = {}\n if (updateNodesIndex) {\n for (const [nodeUuid, node] of Object.entries(nodes)) {\n const nodePrev = recordNodes[nodeUuid]\n if (!RecordNodesIndexUpdater.isNodeIndexUnchanged({ index, node, nodePrev })) {\n nodesToIndex[nodeUuid] = node\n }\n }\n }\n\n if (sideEffect) {\n recordUpdated.nodes = Object.assign(recordNodes, nodes)\n } else {\n recordUpdated.nodes = { ...recordNodes, ...nodes }\n }\n if (updateNodesIndex && Object.keys(nodesToIndex).length > 0) {\n recordUpdated._nodesIndex = RecordNodesIndexUpdater.addNodes(nodesToIndex, { sideEffect, sortNodes })(index)\n }\n return recordUpdated\n }\n\nexport const addNode =\n (node: ArenaRecordNode, options: RecordUpdateOptions = RecordUpdateOptionsDefaults) =>\n (record: ArenaRecord) =>\n addNodes({ [node.uuid]: node }, options)(record)\n"]}
1
+ {"version":3,"file":"recordUpdater.js","sourceRoot":"","sources":["../../../src/record/_records/recordUpdater.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,MAAY,aAAa,4CAAuB;AAChD,uEAAmE;AACnE,+DAAwF;AAEjF,MAAM,QAAQ,GACnB,CAAC,KAAyC,EAAE,OAAO,GAAwB,iDAA2B,EAAE,EAAE,CAC1G,CAAC,MAAmB,EAAe,EAAE;IACnC,MAAM,EAAE,UAAU,EAAE,gBAAgB,EAAE,SAAS,EAAE,mCAAQ,iDAA2B,GAAK,OAAO,CAAE,CAAA;IAElG,MAAM,aAAa,GAAG,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,mBAAM,MAAM,CAAE,CAAA;IACzD,MAAM,WAAW,GAAG,aAAa,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAA;IACzD,iGAAiG;IACjG,MAAM,KAAK,GAAG,gBAAgB,CAAC,CAAC,CAAC,aAAa,CAAC,oBAAoB,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IAEvF,6FAA6F;IAC7F,sEAAsE;IACtE,MAAM,YAAY,GAAuC,EAAE,CAAA;IAC3D,IAAI,gBAAgB,EAAE,C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aRecordNode } from '../../node'\nimport { ArenaRecord } from '../record'\nimport * as RecordGetters from './recordGetters'\nimport { RecordNodesIndexUpdater } from './recordNodesIndexUpdater'\nimport { RecordUpdateOptions, RecordUpdateOptionsDefaults } from './recordUpdateOptions'\n\nexport const addNodes =\n (nodes: { [key: string]: ArenaRecordNode }, options: RecordUpdateOptions = RecordUpdateOptionsDefaults) =>\n (record: ArenaRecord): ArenaRecord => {\n const { sideEffect, updateNodesIndex, sortNodes } = { ...RecordUpdateOptionsDefaults, ...options }\n\n const recordUpdated = sideEffect ? record : { ...record }\n const recordNodes = RecordGetters.getNodes(recordUpdated)\n // index got before adding the new nodes (a missing index is built from the current record nodes)\n const index = updateNodesIndex ? RecordGetters.getNodesIndexOrBuild(recordUpdated) : {}\n\n // index only the nodes not already indexed with the same parent, node def and hierarchy code\n // (e.g. nodes with only an updated value don't need any index change)\n const nodesToIndex: { [key: string]: ArenaRecordNode } = {}\n if (updateNodesIndex) {\n for (const [nodeUuid, node] of Object.entries(nodes)) {\n const nodePrev = recordNodes[nodeUuid]\n if (!RecordNodesIndexUpdater.isNodeIndexUnchanged({ index, node, nodePrev })) {\n nodesToIndex[nodeUuid] = node\n }\n }\n }\n\n if (sideEffect) {\n recordUpdated.nodes = Object.assign(recordNodes, nodes)\n } else {\n recordUpdated.nodes = { ...recordNodes, ...nodes }\n }\n if (updateNodesIndex) {\n // store the index even with no nodes to add: it could have just been built, avoid building it again\n recordUpdated._nodesIndex =\n Object.keys(nodesToIndex).length > 0\n ? RecordNodesIndexUpdater.addNodes(nodesToIndex, { sideEffect, sortNodes })(index)\n : index\n }\n return recordUpdated\n }\n\nexport const addNode =\n (node: ArenaRecordNode, options: RecordUpdateOptions = RecordUpdateOptionsDefaults) =>\n (record: ArenaRecord) =>\n addNodes({ [node.uuid]: node }, options)(record)\n"]}
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.assocPath = void 0;
4
+ const shallowCopy_1 = require("./shallowCopy");
4
5
  const _assocPath = (obj, path, pathIndex, value, sideEffect) => {
5
6
  // only one copy per path level (when sideEffect is false)
6
- const objUpdated = sideEffect ? obj : Object.assign({}, obj);
7
+ const objUpdated = sideEffect ? obj : (0, shallowCopy_1.shallowCopy)(obj);
7
8
  if (pathIndex >= path.length)
8
9
  return objUpdated;
9
10
  const pathPart = path[pathIndex];
@@ -1 +1 @@
1
- {"version":3,"file":"assocPath.js","sourceRoot":"","sources":["../../../src/utils/_objects/assocPath.ts"],"names":[],"mappings":";;;AAAA,MAAM,UAAU,GAAG,CAAC,GAAQ,EAAE,IAAc,EAAE,SAAiB,EAAE,KAAU,EAAE,UAAmB,EAAO,EAAE;IACvG,0DAA0D;IAC1D,MAAM,UAAU,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,mBAAM,GAAG,CAAE,CAAA;IAChD,IAAI,SAAS,IAAI,IAAI,CAAC,MAAM;QAAE,OAAO,UAAU,CAAA;IAE/C,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,CAAA;IAChC,UAAU,CAAC,QAAQ,CAAC;QAClB,SAAS,KAAK,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAG,QAAQ,CAAC,KAAI,EAAE,EAAE,IAAI,EAAE,SAAS,GAAG,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,CAAA;IACnH,OAAO,UAAU,CAAA;AACnB,CAAC,CAAA;AAED;;;GAGG;AACI,MAAM,SAAS,GAAG,CAAmB,MAK3C,EAAK,EAAE;IACN,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,GAAG,KAAK,EAAE,GAAG,MAAM,CAAA;IACvD,OAAO,UAAU,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,CAAA;AACpD,CAAC,CAAA;AARY,QAAA,SAAS,GAAT,SAAS,CAQrB","sourcesContent":["const _assocPath = (obj: any, path: string[], pathIndex: number, value: any, sideEffect: boolean): any => {\n // only one copy per path level (when sideEffect is false)\n const objUpdated = sideEffect ? obj : { ...obj }\n if (pathIndex >= path.length) return objUpdated\n\n const pathPart = path[pathIndex]\n objUpdated[pathPart] =\n pathIndex === path.length - 1 ? value : _assocPath(obj?.[pathPart] || {}, path, pathIndex + 1, value, sideEffect)\n return objUpdated\n}\n\n/**\n * Sets the value at the specified path, creating the missing intermediate objects.\n * Returns a copy of the object (with one copy per path level), or the object itself when sideEffect is true.\n */\nexport const assocPath = <T extends object>(params: {\n obj: T\n path: string[]\n value: unknown\n sideEffect?: boolean\n}): T => {\n const { obj, path, value, sideEffect = false } = params\n return _assocPath(obj, path, 0, value, sideEffect)\n}\n"]}
1
+ {"version":3,"file":"assocPath.js","sourceRoot":"","sources":["../../../src/utils/_objects/assocPath.ts"],"names":[],"mappings":";;;AAAA,+CAA2C;AAE3C,MAAM,UAAU,GAAG,CAAC,GAAQ,EAAE,IAAc,EAAE,SAAiB,EAAE,KAAU,EAAE,UAAmB,EAAO,EAAE;IACvG,0DAA0D;IAC1D,MAAM,UAAU,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAA,yBAAW,EAAC,GAAG,CAAC,CAAA;IACtD,IAAI,SAAS,IAAI,IAAI,CAAC,MAAM;QAAE,OAAO,UAAU,CAAA;IAE/C,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,CAAA;IAChC,UAAU,CAAC,QAAQ,CAAC;QAClB,SAAS,KAAK,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAG,QAAQ,CAAC,KAAI,EAAE,EAAE,IAAI,EAAE,SAAS,GAAG,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,CAAA;IACnH,OAAO,UAAU,CAAA;AACnB,CAAC,CAAA;AAED;;;GAGG;AACI,MAAM,SAAS,GAAG,CAAmB,MAK3C,EAAK,EAAE;IACN,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,GAAG,KAAK,EAAE,GAAG,MAAM,CAAA;IACvD,OAAO,UAAU,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,CAAA;AACpD,CAAC,CAAA;AARY,QAAA,SAAS,GAAT,SAAS,CAQrB","sourcesContent":["import { shallowCopy } from './shallowCopy'\n\nconst _assocPath = (obj: any, path: string[], pathIndex: number, value: any, sideEffect: boolean): any => {\n // only one copy per path level (when sideEffect is false)\n const objUpdated = sideEffect ? obj : shallowCopy(obj)\n if (pathIndex >= path.length) return objUpdated\n\n const pathPart = path[pathIndex]\n objUpdated[pathPart] =\n pathIndex === path.length - 1 ? value : _assocPath(obj?.[pathPart] || {}, path, pathIndex + 1, value, sideEffect)\n return objUpdated\n}\n\n/**\n * Sets the value at the specified path, creating the missing intermediate objects.\n * Returns a copy of the object (with one copy per path level), or the object itself when sideEffect is true.\n */\nexport const assocPath = <T extends object>(params: {\n obj: T\n path: string[]\n value: unknown\n sideEffect?: boolean\n}): T => {\n const { obj, path, value, sideEffect = false } = params\n return _assocPath(obj, path, 0, value, sideEffect)\n}\n"]}
@@ -2,9 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.dissocPath = void 0;
4
4
  const isEmpty_1 = require("./isEmpty");
5
+ const shallowCopy_1 = require("./shallowCopy");
5
6
  const dissocPath = (params) => {
6
7
  const { obj, path, sideEffect = false } = params;
7
- const objUpdated = sideEffect ? obj : Object.assign({}, obj);
8
+ const objUpdated = sideEffect ? obj : (0, shallowCopy_1.shallowCopy)(obj);
8
9
  if (path.length === 0) {
9
10
  return objUpdated;
10
11
  }
@@ -1 +1 @@
1
- {"version":3,"file":"dissocPath.js","sourceRoot":"","sources":["../../../src/utils/_objects/dissocPath.ts"],"names":[],"mappings":";;;AAAA,uCAAmC;AAE5B,MAAM,UAAU,GAAG,CAAmB,MAAwD,EAAK,EAAE;IAC1G,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,GAAG,KAAK,EAAE,GAAG,MAAM,CAAA;IAChD,MAAM,UAAU,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,mBAAM,GAAG,CAAE,CAAA;IAEhD,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,OAAO,UAAU,CAAA;IACnB,CAAC;IAED,MAAM,CAAC,mBAAmB,EAAE,GAAG,cAAc,CAAC,GAAG,IAAI,CAAA;IACrD,MAAM,aAAa,GAAG,mBAA8C,CAAA;IAEpE,MAAM,OAAO,GAAQ,UAAU,CAAC,aAAa,CAAC,CAAA;IAE9C,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,IAAI,IAAA,iBAAO,EAAC,OAAO,CAAC,EAAE,CAAC;QACpD,OAAO,UAAU,CAAC,aAAa,CAAC,CAAA;QAChC,OAAO,UAAU,CAAA;IACnB,CAAC;IAED,oEAAoE;IACpE,MAAM,cAAc,GAAG,IAAA,QAAA,UAAU,EAAC,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,UAAU,EAAE,CAAC,CAAA;IAErF,IAAI,IAAA,iBAAO,EAAC,cAAc,CAAC,EAAE,CAAC;QAC5B,OAAO,UAAU,CAAC,aAAa,CAAC,CAAA;QAChC,OAAO,UAAU,CAAA;IACnB,CAAC;IAED,UAAU,CAAC,aAAa,CAAC,GAAG,cAAc,CAAA;IAC1C,OAAO,UAAU,CAAA;AACnB,CAAC,CAAA;AA5BY,QAAA,UAAU,GAAV,UAAU,CA4BtB","sourcesContent":["import { isEmpty } from './isEmpty'\n\nexport const dissocPath = <T extends object>(params: { obj: T; path: string[]; sideEffect?: boolean }): T => {\n const { obj, path, sideEffect = false } = params\n const objUpdated = sideEffect ? obj : { ...obj }\n\n if (path.length === 0) {\n return objUpdated\n }\n\n const [firstPathPartString, ...otherPathParts] = path\n const firstPathPart = firstPathPartString as keyof typeof objUpdated\n\n const objPart: any = objUpdated[firstPathPart]\n\n if (otherPathParts.length === 0 || isEmpty(objPart)) {\n delete objUpdated[firstPathPart]\n return objUpdated\n }\n\n // objPart is copied by dissocPath itself (when sideEffect is false)\n const objPartUpdated = dissocPath({ obj: objPart, path: otherPathParts, sideEffect })\n\n if (isEmpty(objPartUpdated)) {\n delete objUpdated[firstPathPart]\n return objUpdated\n }\n\n objUpdated[firstPathPart] = objPartUpdated\n return objUpdated\n}\n"]}
1
+ {"version":3,"file":"dissocPath.js","sourceRoot":"","sources":["../../../src/utils/_objects/dissocPath.ts"],"names":[],"mappings":";;;AAAA,uCAAmC;AACnC,+CAA2C;AAEpC,MAAM,UAAU,GAAG,CAAmB,MAAwD,EAAK,EAAE;IAC1G,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,GAAG,KAAK,EAAE,GAAG,MAAM,CAAA;IAChD,MAAM,UAAU,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAA,yBAAW,EAAC,GAAG,CAAC,CAAA;IAEtD,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,OAAO,UAAU,CAAA;IACnB,CAAC;IAED,MAAM,CAAC,mBAAmB,EAAE,GAAG,cAAc,CAAC,GAAG,IAAI,CAAA;IACrD,MAAM,aAAa,GAAG,mBAA8C,CAAA;IAEpE,MAAM,OAAO,GAAQ,UAAU,CAAC,aAAa,CAAC,CAAA;IAE9C,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,IAAI,IAAA,iBAAO,EAAC,OAAO,CAAC,EAAE,CAAC;QACpD,OAAO,UAAU,CAAC,aAAa,CAAC,CAAA;QAChC,OAAO,UAAU,CAAA;IACnB,CAAC;IAED,oEAAoE;IACpE,MAAM,cAAc,GAAG,IAAA,QAAA,UAAU,EAAC,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,UAAU,EAAE,CAAC,CAAA;IAErF,IAAI,IAAA,iBAAO,EAAC,cAAc,CAAC,EAAE,CAAC;QAC5B,OAAO,UAAU,CAAC,aAAa,CAAC,CAAA;QAChC,OAAO,UAAU,CAAA;IACnB,CAAC;IAED,UAAU,CAAC,aAAa,CAAC,GAAG,cAAc,CAAA;IAC1C,OAAO,UAAU,CAAA;AACnB,CAAC,CAAA;AA5BY,QAAA,UAAU,GAAV,UAAU,CA4BtB","sourcesContent":["import { isEmpty } from './isEmpty'\nimport { shallowCopy } from './shallowCopy'\n\nexport const dissocPath = <T extends object>(params: { obj: T; path: string[]; sideEffect?: boolean }): T => {\n const { obj, path, sideEffect = false } = params\n const objUpdated = sideEffect ? obj : shallowCopy(obj)\n\n if (path.length === 0) {\n return objUpdated\n }\n\n const [firstPathPartString, ...otherPathParts] = path\n const firstPathPart = firstPathPartString as keyof typeof objUpdated\n\n const objPart: any = objUpdated[firstPathPart]\n\n if (otherPathParts.length === 0 || isEmpty(objPart)) {\n delete objUpdated[firstPathPart]\n return objUpdated\n }\n\n // objPart is copied by dissocPath itself (when sideEffect is false)\n const objPartUpdated = dissocPath({ obj: objPart, path: otherPathParts, sideEffect })\n\n if (isEmpty(objPartUpdated)) {\n delete objUpdated[firstPathPart]\n return objUpdated\n }\n\n objUpdated[firstPathPart] = objPartUpdated\n return objUpdated\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  /**
2
- * Sets the value at the specified path in the object itself (side effect), creating the missing intermediate objects.
2
+ * Sets the value at the specified path in the object itself (side effect), creating the missing intermediate objects
3
+ * (null or non-object intermediate values are replaced with new objects).
3
4
  * When excludeEmpty is true, empty values are not set.
4
5
  */
5
6
  export declare const setInPath: <T extends object>(params: {
@@ -3,7 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.setInPath = void 0;
4
4
  const isEmpty_1 = require("./isEmpty");
5
5
  /**
6
- * Sets the value at the specified path in the object itself (side effect), creating the missing intermediate objects.
6
+ * Sets the value at the specified path in the object itself (side effect), creating the missing intermediate objects
7
+ * (null or non-object intermediate values are replaced with new objects).
7
8
  * When excludeEmpty is true, empty values are not set.
8
9
  */
9
10
  const setInPath = (params) => {
@@ -15,7 +16,9 @@ const setInPath = (params) => {
15
16
  objCurrent[pathPart] = value;
16
17
  }
17
18
  else {
18
- if (!Object.hasOwn(objCurrent, pathPart)) {
19
+ const valueCurrent = Object.hasOwn(objCurrent, pathPart) ? objCurrent[pathPart] : undefined;
20
+ if (valueCurrent === null || (typeof valueCurrent !== 'object' && typeof valueCurrent !== 'function')) {
21
+ // missing, null or primitive intermediate value: replace it with a new object
19
22
  objCurrent[pathPart] = {};
20
23
  }
21
24
  objCurrent = objCurrent[pathPart];
@@ -1 +1 @@
1
- {"version":3,"file":"setInPath.js","sourceRoot":"","sources":["../../../src/utils/_objects/setInPath.ts"],"names":[],"mappings":";;;AAAA,uCAAmC;AAEnC;;;GAGG;AACI,MAAM,SAAS,GAAG,CAAmB,MAK3C,EAAK,EAAE;IACN,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,YAAY,EAAE,GAAG,MAAM,CAAA;IACjD,IAAI,CAAC,YAAY,IAAI,CAAC,IAAA,iBAAO,EAAC,KAAK,CAAC,EAAE,CAAC;QACrC,IAAI,UAAU,GAAQ,GAAG,CAAA;QACzB,IAAI,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE;YAC3B,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC1B,UAAU,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAA;YAC9B,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,EAAE,CAAC;oBACzC,UAAU,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAA;gBAC3B,CAAC;gBACD,UAAU,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAA;YACnC,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA;AArBY,QAAA,SAAS,GAAT,SAAS,CAqBrB","sourcesContent":["import { isEmpty } from './isEmpty'\n\n/**\n * Sets the value at the specified path in the object itself (side effect), creating the missing intermediate objects.\n * When excludeEmpty is true, empty values are not set.\n */\nexport const setInPath = <T extends object>(params: {\n obj: T\n path: string[]\n value: unknown\n excludeEmpty?: boolean\n}): T => {\n const { obj, path, value, excludeEmpty } = params\n if (!excludeEmpty || !isEmpty(value)) {\n let objCurrent: any = obj\n path.forEach((pathPart, i) => {\n if (i === path.length - 1) {\n objCurrent[pathPart] = value\n } else {\n if (!Object.hasOwn(objCurrent, pathPart)) {\n objCurrent[pathPart] = {}\n }\n objCurrent = objCurrent[pathPart]\n }\n })\n }\n return obj\n}\n"]}
1
+ {"version":3,"file":"setInPath.js","sourceRoot":"","sources":["../../../src/utils/_objects/setInPath.ts"],"names":[],"mappings":";;;AAAA,uCAAmC;AAEnC;;;;GAIG;AACI,MAAM,SAAS,GAAG,CAAmB,MAK3C,EAAK,EAAE;IACN,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,YAAY,EAAE,GAAG,MAAM,CAAA;IACjD,IAAI,CAAC,YAAY,IAAI,CAAC,IAAA,iBAAO,EAAC,KAAK,CAAC,EAAE,CAAC;QACrC,IAAI,UAAU,GAAQ,GAAG,CAAA;QACzB,IAAI,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE;YAC3B,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC1B,UAAU,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAA;YAC9B,CAAC;iBAAM,CAAC;gBACN,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;gBAC3F,IAAI,YAAY,KAAK,IAAI,IAAI,CAAC,OAAO,YAAY,KAAK,QAAQ,IAAI,OAAO,YAAY,KAAK,UAAU,CAAC,EAAE,CAAC;oBACtG,8EAA8E;oBAC9E,UAAU,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAA;gBAC3B,CAAC;gBACD,UAAU,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAA;YACnC,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA;AAvBY,QAAA,SAAS,GAAT,SAAS,CAuBrB","sourcesContent":["import { isEmpty } from './isEmpty'\n\n/**\n * Sets the value at the specified path in the object itself (side effect), creating the missing intermediate objects\n * (null or non-object intermediate values are replaced with new objects).\n * When excludeEmpty is true, empty values are not set.\n */\nexport const setInPath = <T extends object>(params: {\n obj: T\n path: string[]\n value: unknown\n excludeEmpty?: boolean\n}): T => {\n const { obj, path, value, excludeEmpty } = params\n if (!excludeEmpty || !isEmpty(value)) {\n let objCurrent: any = obj\n path.forEach((pathPart, i) => {\n if (i === path.length - 1) {\n objCurrent[pathPart] = value\n } else {\n const valueCurrent = Object.hasOwn(objCurrent, pathPart) ? objCurrent[pathPart] : undefined\n if (valueCurrent === null || (typeof valueCurrent !== 'object' && typeof valueCurrent !== 'function')) {\n // missing, null or primitive intermediate value: replace it with a new object\n objCurrent[pathPart] = {}\n }\n objCurrent = objCurrent[pathPart]\n }\n })\n }\n return obj\n}\n"]}
@@ -0,0 +1 @@
1
+ export declare const shallowCopy: <T extends object>(obj: T) => T;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.shallowCopy = void 0;
4
+ // arrays are copied as arrays
5
+ const shallowCopy = (obj) => (Array.isArray(obj) ? [...obj] : Object.assign({}, obj));
6
+ exports.shallowCopy = shallowCopy;
7
+ //# sourceMappingURL=shallowCopy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shallowCopy.js","sourceRoot":"","sources":["../../../src/utils/_objects/shallowCopy.ts"],"names":[],"mappings":";;;AAAA,8BAA8B;AACvB,MAAM,WAAW,GAAG,CAAmB,GAAM,EAAK,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,mBAAM,GAAG,CAAE,CAAM,CAAA;AAAhG,QAAA,WAAW,GAAX,WAAW,CAAqF","sourcesContent":["// arrays are copied as arrays\nexport const shallowCopy = <T extends object>(obj: T): T => (Array.isArray(obj) ? [...obj] : { ...obj }) as T\n"]}
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "name": "OpenForis",
5
5
  "email": "openforis.arena@gmail.com"
6
6
  },
7
- "version": "2.18.18",
7
+ "version": "2.18.20",
8
8
  "description": "Arena core module",
9
9
  "repository": {
10
10
  "type": "git",