@openforis/arena-core 2.4.3 → 2.4.4
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/error/SystemError.d.ts +8 -1
- package/dist/error/SystemError.js +7 -2
- package/dist/error/SystemError.js.map +1 -1
- package/dist/esm/error/SystemError.js +7 -2
- package/dist/esm/error/SystemError.js.map +1 -1
- package/dist/esm/record/recordNodesUpdater/recordNodesDependentsUpdaterCommons.js +1 -1
- package/dist/esm/record/recordNodesUpdater/recordNodesDependentsUpdaterCommons.js.map +1 -1
- package/dist/esm/record/recordUpdater.js +1 -1
- package/dist/esm/record/recordUpdater.js.map +1 -1
- package/dist/record/recordNodesUpdater/recordNodesDependentsUpdaterCommons.js +1 -1
- package/dist/record/recordNodesUpdater/recordNodesDependentsUpdaterCommons.js.map +1 -1
- package/dist/record/recordUpdater.js +1 -1
- package/dist/record/recordUpdater.js.map +1 -1
- package/package.json +1 -1
|
@@ -2,7 +2,14 @@ import { Dictionary } from '../common';
|
|
|
2
2
|
export declare class SystemError extends Error {
|
|
3
3
|
private readonly _key;
|
|
4
4
|
private readonly _params;
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* @param key - Error key (translatable).
|
|
7
|
+
* @param params - Parameters of the error message.
|
|
8
|
+
* @param options - Error options: `cause` is the original error (kept with its stack trace).
|
|
9
|
+
*/
|
|
10
|
+
constructor(key: string, params?: Dictionary<any>, options?: {
|
|
11
|
+
cause?: unknown;
|
|
12
|
+
});
|
|
6
13
|
get key(): string;
|
|
7
14
|
get params(): Dictionary<any>;
|
|
8
15
|
toJSON(): {
|
|
@@ -2,8 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SystemError = void 0;
|
|
4
4
|
class SystemError extends Error {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
/**
|
|
6
|
+
* @param key - Error key (translatable).
|
|
7
|
+
* @param params - Parameters of the error message.
|
|
8
|
+
* @param options - Error options: `cause` is the original error (kept with its stack trace).
|
|
9
|
+
*/
|
|
10
|
+
constructor(key, params, options) {
|
|
11
|
+
super(key, options);
|
|
7
12
|
this.name = 'SystemError';
|
|
8
13
|
this._key = key;
|
|
9
14
|
this._params = params !== null && params !== void 0 ? params : {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SystemError.js","sourceRoot":"","sources":["../../src/error/SystemError.ts"],"names":[],"mappings":";;;AAEA,iBAAyB,SAAQ,KAAK;IAIpC,YAAY,GAAW,EAAE,MAAwB;
|
|
1
|
+
{"version":3,"file":"SystemError.js","sourceRoot":"","sources":["../../src/error/SystemError.ts"],"names":[],"mappings":";;;AAEA,iBAAyB,SAAQ,KAAK;IAIpC;;;;OAIG;IACH,YAAY,GAAW,EAAE,MAAwB,EAAE,OAA6B;QAC9E,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;QAEnB,IAAI,CAAC,IAAI,GAAG,aAAa,CAAA;QAEzB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAA;QACf,IAAI,CAAC,OAAO,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAA;QAE3B,sDAAsD;QACtD,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC5B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,WAAW,CAAC,CAAA;QAC5C,CAAC;IACH,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,IAAI,CAAA;IAClB,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAA;IACrB,CAAC;IAED,MAAM;QACJ,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,CAAA;QAC5B,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAA;QAC3C,MAAM,cAAc,GAClB,WAAW,IAAI,WAAW,YAAY,WAAW,CAAC,CAAC,iCAAM,MAAM,KAAE,KAAK,EAAE,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,MAAM,EAAE,IAAG,CAAC,CAAC,MAAM,CAAA;QAC1G,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,cAAc,EAAE,CAAA;IACxC,CAAC;CACF","sourcesContent":["import { Dictionary } from '../common'\n\nexport class SystemError extends Error {\n private readonly _key: string\n private readonly _params: Dictionary<any>\n\n /**\n * @param key - Error key (translatable).\n * @param params - Parameters of the error message.\n * @param options - Error options: `cause` is the original error (kept with its stack trace).\n */\n constructor(key: string, params?: Dictionary<any>, options?: { cause?: unknown }) {\n super(key, options)\n\n this.name = 'SystemError'\n\n this._key = key\n this._params = params ?? {}\n\n // Maintains proper stack trace (only available on V8)\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, SystemError)\n }\n }\n\n get key(): string {\n return this._key\n }\n\n get params(): Dictionary<any> {\n return this._params\n }\n\n toJSON() {\n const { key, params } = this\n const { error: nestedError } = params ?? {}\n const paramsAdjusted: Dictionary<any> =\n nestedError && nestedError instanceof SystemError ? { ...params, error: nestedError?.toJSON() } : params\n return { key, params: paramsAdjusted }\n }\n}\n"]}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
export class SystemError extends Error {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* @param key - Error key (translatable).
|
|
4
|
+
* @param params - Parameters of the error message.
|
|
5
|
+
* @param options - Error options: `cause` is the original error (kept with its stack trace).
|
|
6
|
+
*/
|
|
7
|
+
constructor(key, params, options) {
|
|
8
|
+
super(key, options);
|
|
4
9
|
this.name = 'SystemError';
|
|
5
10
|
this._key = key;
|
|
6
11
|
this._params = params !== null && params !== void 0 ? params : {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SystemError.js","sourceRoot":"","sources":["../../../src/error/SystemError.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,WAAY,SAAQ,KAAK;IAIpC,YAAY,GAAW,EAAE,MAAwB;
|
|
1
|
+
{"version":3,"file":"SystemError.js","sourceRoot":"","sources":["../../../src/error/SystemError.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,WAAY,SAAQ,KAAK;IAIpC;;;;OAIG;IACH,YAAY,GAAW,EAAE,MAAwB,EAAE,OAA6B;QAC9E,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;QAEnB,IAAI,CAAC,IAAI,GAAG,aAAa,CAAA;QAEzB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAA;QACf,IAAI,CAAC,OAAO,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAA;QAE3B,sDAAsD;QACtD,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC5B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,WAAW,CAAC,CAAA;QAC5C,CAAC;IACH,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,IAAI,CAAA;IAClB,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAA;IACrB,CAAC;IAED,MAAM;QACJ,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,CAAA;QAC5B,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAA;QAC3C,MAAM,cAAc,GAClB,WAAW,IAAI,WAAW,YAAY,WAAW,CAAC,CAAC,iCAAM,MAAM,KAAE,KAAK,EAAE,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,MAAM,EAAE,IAAG,CAAC,CAAC,MAAM,CAAA;QAC1G,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,cAAc,EAAE,CAAA;IACxC,CAAC;CACF","sourcesContent":["import { Dictionary } from '../common'\n\nexport class SystemError extends Error {\n private readonly _key: string\n private readonly _params: Dictionary<any>\n\n /**\n * @param key - Error key (translatable).\n * @param params - Parameters of the error message.\n * @param options - Error options: `cause` is the original error (kept with its stack trace).\n */\n constructor(key: string, params?: Dictionary<any>, options?: { cause?: unknown }) {\n super(key, options)\n\n this.name = 'SystemError'\n\n this._key = key\n this._params = params ?? {}\n\n // Maintains proper stack trace (only available on V8)\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, SystemError)\n }\n }\n\n get key(): string {\n return this._key\n }\n\n get params(): Dictionary<any> {\n return this._params\n }\n\n toJSON() {\n const { key, params } = this\n const { error: nestedError } = params ?? {}\n const paramsAdjusted: Dictionary<any> =\n nestedError && nestedError instanceof SystemError ? { ...params, error: nestedError?.toJSON() } : params\n return { key, params: paramsAdjusted }\n }\n}\n"]}
|
|
@@ -13,7 +13,7 @@ export const throwError = (params) => {
|
|
|
13
13
|
expressionsString,
|
|
14
14
|
error: error.toString(),
|
|
15
15
|
errorJson: error instanceof SystemError ? error.toJSON() : null,
|
|
16
|
-
});
|
|
16
|
+
}, { cause: error });
|
|
17
17
|
};
|
|
18
18
|
const addPointerIfAccepted = (params) => {
|
|
19
19
|
const { nodePointers, pointer, filterFn } = params;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recordNodesDependentsUpdaterCommons.js","sourceRoot":"","sources":["../../../../src/record/recordNodesUpdater/recordNodesDependentsUpdaterCommons.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEzC,OAAO,EAAyD,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC/F,OAAO,EAAgC,OAAO,EAAE,MAAM,cAAc,CAAA;AAEpE,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEpC,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,MAO1B,EAAE,EAAE;IACH,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,qBAAqB,EAAE,GAAG,MAAM,CAAA;IAC1F,MAAM,WAAW,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAA;IACtC,MAAM,iBAAiB,GAAG,IAAI,CAAC,SAAS,CAAC,qBAAqB,CAAC,CAAA;IAE/D,MAAM,IAAI,WAAW,
|
|
1
|
+
{"version":3,"file":"recordNodesDependentsUpdaterCommons.js","sourceRoot":"","sources":["../../../../src/record/recordNodesUpdater/recordNodesDependentsUpdaterCommons.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEzC,OAAO,EAAyD,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC/F,OAAO,EAAgC,OAAO,EAAE,MAAM,cAAc,CAAA;AAEpE,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEpC,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,MAO1B,EAAE,EAAE;IACH,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,qBAAqB,EAAE,GAAG,MAAM,CAAA;IAC1F,MAAM,WAAW,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAA;IACtC,MAAM,iBAAiB,GAAG,IAAI,CAAC,SAAS,CAAC,qBAAqB,CAAC,CAAA;IAE/D,MAAM,IAAI,WAAW,CACnB,QAAQ,EACR;QACE,UAAU,EAAE,MAAM,CAAC,KAAK,CAAC,IAAI;QAC7B,WAAW;QACX,cAAc;QACd,iBAAiB;QACjB,KAAK,EAAE,KAAK,CAAC,QAAQ,EAAE;QACvB,SAAS,EAAE,KAAK,YAAY,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,IAAI;KAChE,EACD,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB,CAAA;AACH,CAAC,CAAA;AAED,MAAM,oBAAoB,GAAG,CAAC,MAI7B,EAAE,EAAE;IACH,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,MAAM,C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,MAAM,8BAA8B,GAAG,CAAC,MAS9C,EAAiB,EAAE;IAClB,MAAM,EACJ,MAAM,EACN,MAAM,EACN,IAAI,EACJ,cAAc,EACd,gCAAgC,GAAG,KAAK,EACxC,oBAAoB,GAAG,KAAK,EAC5B,6BAA6B,GAAG,KAAK,EACrC,QAAQ,GACT,GAAG,MAAM,CAAA;IAEV,MAAM,aAAa,GAAG,OAAO,CAAC,gBAAgB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,CAAA;IAClF,MAAM,WAAW,GAAG,gCAAgC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAA;IAEzF,MAAM,YAAY,GAAG,OAAO,CAAC,wBAAwB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,CAAA;IAEtH,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QACvD,OAAO,YAAY,CAAA;IACrB,CAAC;IAED,0EAA0E;IAC1E,IAAI,oBAAoB,EAAE,CAAC;QACzB,uBAAuB,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,CAAA;IAC1F,CAAC;IAED,uGAAuG;IACvG,IAAI,6BAA6B,EAAE,CAAC;QAClC,iCAAiC,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,CAAA;IAC5F,CAAC;IAED,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA","sourcesContent":["import { SystemError } from '../../error'\nimport { ArenaRecordNode, NodePointer } from '../../node'\nimport { NodeDef, NodeDefExpression, NodeDefProps, NodeDefType, NodeDefs } from '../../nodeDef'\nimport { Survey, SurveyDependencyType, Surveys } from '../../survey'\nimport { ArenaRecord } from '../record'\nimport { Records } from '../records'\n\nexport const throwError = (params: {\n error: any\n errorKey: string\n expressionType: SurveyDependencyType\n survey: Survey\n nodeDef: NodeDef<NodeDefType, NodeDefProps>\n expressionsToEvaluate: NodeDefExpression[]\n}) => {\n const { error, errorKey, expressionType, survey, nodeDef, expressionsToEvaluate } = params\n const nodeDefName = nodeDef.props.name\n const expressionsString = JSON.stringify(expressionsToEvaluate)\n\n throw new SystemError(\n errorKey,\n {\n surveyName: survey.props.name,\n nodeDefName,\n expressionType,\n expressionsString,\n error: error.toString(),\n errorJson: error instanceof SystemError ? error.toJSON() : null,\n },\n { cause: error }\n )\n}\n\nconst addPointerIfAccepted = (params: {\n nodePointers: NodePointer[]\n pointer: NodePointer\n filterFn?: (nodePointer: NodePointer) => boolean\n}) => {\n const { nodePointers, pointer, filterFn } = params\n if (!filterFn || filterFn(pointer)) {\n nodePointers.push(pointer)\n }\n}\n\nconst addNewEntitySelfPointer = (params: {\n nodePointers: NodePointer[]\n survey: Survey\n record: ArenaRecord\n node: ArenaRecordNode\n sourceNodeDef: NodeDef<NodeDefType, NodeDefProps>\n filterFn?: (nodePointer: NodePointer) => boolean\n}) => {\n const { nodePointers, record, node, sourceNodeDef, filterFn } = params\n if (!node.parentUuid) {\n return\n }\n const parentNode = Records.getNodeByUuid({ uuid: node.parentUuid })(record)\n if (!parentNode) {\n return\n }\n addPointerIfAccepted({\n nodePointers,\n pointer: { nodeCtx: parentNode, nodeDef: sourceNodeDef },\n filterFn,\n })\n}\n\nconst addNewEntityChildMultiplePointers = (params: {\n nodePointers: NodePointer[]\n survey: Survey\n node: ArenaRecordNode\n sourceNodeDef: NodeDef<NodeDefType, NodeDefProps>\n filterFn?: (nodePointer: NodePointer) => boolean\n}) => {\n const { nodePointers, survey, node, sourceNodeDef, filterFn } = params\n const multipleNodeDefs = Surveys.getNodeDefChildren({ survey, nodeDef: sourceNodeDef }).filter(NodeDefs.isMultiple)\n\n for (const childDef of multipleNodeDefs) {\n addPointerIfAccepted({\n nodePointers,\n pointer: { nodeCtx: node, nodeDef: childDef },\n filterFn,\n })\n }\n}\n\nexport const getDependentNodePointersByType = (params: {\n survey: Survey\n record: ArenaRecord\n node: ArenaRecordNode\n dependencyType: SurveyDependencyType\n includeSelfWhenSourceIsAttribute?: boolean\n includeNewEntitySelf?: boolean\n includeNewEntityChildPointers?: boolean\n filterFn?: (nodePointer: NodePointer) => boolean\n}): NodePointer[] => {\n const {\n survey,\n record,\n node,\n dependencyType,\n includeSelfWhenSourceIsAttribute = false,\n includeNewEntitySelf = false,\n includeNewEntityChildPointers = false,\n filterFn,\n } = params\n\n const sourceNodeDef = Surveys.getNodeDefByUuid({ survey, uuid: node.nodeDefUuid })\n const includeSelf = includeSelfWhenSourceIsAttribute && !NodeDefs.isEntity(sourceNodeDef)\n\n const nodePointers = Records.getDependentNodePointers({ survey, node, dependencyType, includeSelf, filterFn })(record)\n\n if (!NodeDefs.isEntity(sourceNodeDef) || !node.created) {\n return nodePointers\n }\n\n // For newly created entities, include a self-pointer for the source node.\n if (includeNewEntitySelf) {\n addNewEntitySelfPointer({ nodePointers, survey, record, node, sourceNodeDef, filterFn })\n }\n\n // For new entities, include child multiple nodes so their dependency metadata/status gets updated too.\n if (includeNewEntityChildPointers) {\n addNewEntityChildMultiplePointers({ nodePointers, survey, node, sourceNodeDef, filterFn })\n }\n\n return nodePointers\n}\n"]}
|
|
@@ -81,7 +81,7 @@ const updateAttributeValue = (params) => __awaiter(void 0, void 0, void 0, funct
|
|
|
81
81
|
const { attributeUuid, record, value, dateModified = Dates.nowFormattedForStorage(), sideEffect = false } = params;
|
|
82
82
|
const attribute = Records.getNodeByUuid({ uuid: attributeUuid })(record);
|
|
83
83
|
if (!attribute)
|
|
84
|
-
throw new SystemError('record.nodeNotFound');
|
|
84
|
+
throw new SystemError('record.nodeNotFound', { uuid: attributeUuid });
|
|
85
85
|
let attributeUpdated = sideEffect ? attribute : Object.assign({}, attribute);
|
|
86
86
|
attributeUpdated.value = value;
|
|
87
87
|
attributeUpdated.dateModified = dateModified;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recordUpdater.js","sourceRoot":"","sources":["../../../src/record/recordUpdater.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAEtC,OAAO,EAAU,oBAAoB,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACjE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C,OAAO,EAAE,kBAAkB,EAAsB,MAAM,sBAAsB,CAAA;AAE7E,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAEnD,MAAM,yBAAyB,GAAG;IAChC,oBAAoB,CAAC,WAAW;IAChC,oBAAoB,CAAC,QAAQ;IAC7B,oBAAoB,CAAC,QAAQ;CAC9B,CAAA;AAED,MAAM,kCAAkC,GAAG,CAAC,MAI3C,EAAiB,EAAE;IAClB,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAA;IACxC,MAAM,mBAAmB,GAAG,IAAI,GAAG,EAAuB,CAAA;IAC1D,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QACxC,KAAK,MAAM,cAAc,IAAI,yBAAyB,EAAE,CAAC;YACvD,MAAM,YAAY,GAAG,OAAO,CAAC,wBAAwB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC,CAAC,MAAM,CAAC,CAAA;YAC/F,KAAK,MAAM,OAAO,IAAI,YAAY,EAAE,CAAC;gBACnC,MAAM,WAAW,GAAG,OAA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,UAAU,GAAG,KAAK,EAAE,GAAG,MAAM,CAAA;IAEjE,MAAM,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,SAAS,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC,OAAO,CAAC,CAAA;IAC5E,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,YAAY,CAAA;IAE7C,MAAM,MAAM,GAAG,MAAM,4BAA4B,iCAAM,MAAM,KAAE,MAAM,EAAE,KAAK,EAAE,YAAY,IAAG,CAAA;IAC7F,MAAM,CAAC,YAAY,GAAG,YAAY,CAAA;IAClC,OAAO,MAAM,CAAA;AACf,CAAC,CAAA,CAAA;AAED,MAAM,UAAU,GAAG,CAAO,MAAgD,EAA+B,EAAE;IACzG,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAA;IAC3B,OAAO,WAAW,iCAAM,MAAM,KAAE,SAAS,EAAE,CAAC,QAAQ,CAAC,IAAG,CAAA;AAC1D,CAAC,CAAA,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,iBAAiB;IACjB,wBAAwB;IACxB,gBAAgB;IAChB,oBAAoB;IACpB,UAAU;IACV,WAAW;CACZ,CAAA","sourcesContent":["import { Dictionary } from '../common'\nimport { SystemError } from '../error'\nimport { ArenaRecordNode, NodePointer, NodesMap } from '../node'\nimport { Survey, SurveyDependencyType, Surveys } from '../survey'\nimport { Dates, Objects } from '../utils'\nimport { Validations } from '../validation/validations'\nimport { NodePointers } from './nodePointers'\nimport { ArenaRecord } from './record'\nimport { RecordNodesUpdater, RecordUpdateResult } from './recordNodesUpdater'\nimport { NodeCreateParams, NodesUpdateParams } from './recordNodesUpdater/recordNodesCreator'\nimport { Records } from './records'\nimport { RecordValidator } from './recordValidator'\n\nconst validationDependencyTypes = [\n SurveyDependencyType.validations,\n SurveyDependencyType.minCount,\n SurveyDependencyType.maxCount,\n]\n\nconst getDependentValidationNodePointers = (params: {\n survey: Survey\n record: ArenaRecord\n nodes: NodesMap\n}): NodePointer[] => {\n const { survey, record, nodes } = params\n const uniquePointersByKey = new Map<string, NodePointer>()\n for (const node of Object.values(nodes)) {\n for (const dependencyType of validationDependencyTypes) {\n const nodePointers = Records.getDependentNodePointers({ survey, node, dependencyType })(record)\n for (const pointer of nodePointers) {\n const nodeCtxUuid = pointer.nodeCtx.uuid\n const nodeDefUuid = pointer.nodeDef.uuid\n const key = `${nodeCtxUuid ?? ''}:${nodeDefUuid ?? ''}`\n if (!uniquePointersByKey.has(key)) {\n uniquePointersByKey.set(key, pointer)\n }\n }\n }\n }\n return Array.from(uniquePointersByKey.values())\n}\n\nconst _onRecordNodesCreateOrUpdate = async (\n params: NodesUpdateParams & { nodes: Dictionary<ArenaRecordNode> }\n): Promise<RecordUpdateResult> => {\n const { user, survey, dateModified = Dates.nowFormattedForStorage() } = params\n\n const updateResult = await RecordNodesUpdater.updateNodesDependents(params)\n const { nodes: updatedNodes, record: updatedRecord } = updateResult\n\n const dependentValidationNodePointers = getDependentValidationNodePointers({\n survey,\n record: updatedRecord,\n nodes: updatedNodes,\n })\n\n const dependentValidationNodes = NodePointers.getNodesMapFromNodePointers({\n record: updatedRecord,\n nodePointers: dependentValidationNodePointers,\n })\n\n const nodesToValidate = { ...updatedNodes, ...dependentValidationNodes }\n\n const validationUpdatedNodes = await RecordValidator.validateNodes({\n user,\n survey,\n record: updatedRecord,\n nodes: nodesToValidate,\n })\n\n const validation = Validations.mergeValidations(validationUpdatedNodes)(Validations.getValidation(updatedRecord))\n updatedRecord.validation = validation\n updatedRecord.dateModified = dateModified\n\n updateResult.validation = validation\n\n return updateResult\n}\n\nconst createDescendants = async (params: NodeCreateParams): Promise<RecordUpdateResult> => {\n const { record: updatedRecord, nodes: createdNodes } = await RecordNodesUpdater.createDescendants(params)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: updatedRecord, nodes: createdNodes })\n}\n\nconst _createNodeAndDescendants = async (params: NodeCreateParams): Promise<RecordUpdateResult> => {\n const { record: updatedRecord, nodes: createdNodes } = await RecordNodesUpdater.createNodeAndDescendants(params)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: updatedRecord, nodes: createdNodes })\n}\n\nconst createNodeAndDescendants = async (params: NodeCreateParams): Promise<RecordUpdateResult> =>\n _createNodeAndDescendants(params)\n\nconst createRootEntity = async (\n params: NodesUpdateParams & {\n createMultipleEntities?: boolean\n }\n): Promise<RecordUpdateResult> => {\n const { survey, createMultipleEntities = true } = params\n\n return _createNodeAndDescendants({ ...params, nodeDef: Surveys.getNodeDefRoot({ survey }), createMultipleEntities })\n}\n\nconst updateAttributeValue = async (\n params: NodesUpdateParams & {\n attributeUuid: string\n value: any\n }\n): Promise<RecordUpdateResult> => {\n const { attributeUuid, record, value, dateModified = Dates.nowFormattedForStorage(), sideEffect = false } = params\n const attribute = Records.getNodeByUuid({ uuid: attributeUuid })(record)\n if (!attribute) throw new SystemError('record.nodeNotFound')\n\n let attributeUpdated = sideEffect ? attribute : { ...attribute }\n attributeUpdated.value = value\n attributeUpdated.dateModified = dateModified\n // reset defaultValueApplied flag\n attributeUpdated = Objects.dissocPath({ obj: attributeUpdated, path: ['meta', 'defaultValueApplied'], sideEffect })\n\n const nodesUpdated = { [attributeUuid]: attributeUpdated }\n\n const _record = Records.addNode(attributeUpdated, { sideEffect })(record)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: _record, nodes: nodesUpdated })\n}\n\nconst deleteNodes = async (\n params: NodesUpdateParams & {\n nodeUuids: string[]\n }\n): Promise<RecordUpdateResult> => {\n const { nodeUuids, record: _record, sideEffect = false } = params\n\n const updateResult = Records.deleteNodes(nodeUuids, { sideEffect })(_record)\n const { record, nodesDeleted } = updateResult\n\n const result = await _onRecordNodesCreateOrUpdate({ ...params, record, nodes: nodesDeleted })\n result.nodesDeleted = nodesDeleted\n return result\n}\n\nconst deleteNode = async (params: NodesUpdateParams & { nodeUuid: string }): Promise<RecordUpdateResult> => {\n const { nodeUuid } = params\n return deleteNodes({ ...params, nodeUuids: [nodeUuid] })\n}\n\nexport const RecordUpdater = {\n createDescendants,\n createNodeAndDescendants,\n createRootEntity,\n updateAttributeValue,\n deleteNode,\n deleteNodes,\n}\n"]}
|
|
1
|
+
{"version":3,"file":"recordUpdater.js","sourceRoot":"","sources":["../../../src/record/recordUpdater.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAEtC,OAAO,EAAU,oBAAoB,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACjE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C,OAAO,EAAE,kBAAkB,EAAsB,MAAM,sBAAsB,CAAA;AAE7E,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAEnD,MAAM,yBAAyB,GAAG;IAChC,oBAAoB,CAAC,WAAW;IAChC,oBAAoB,CAAC,QAAQ;IAC7B,oBAAoB,CAAC,QAAQ;CAC9B,CAAA;AAED,MAAM,kCAAkC,GAAG,CAAC,MAI3C,EAAiB,EAAE;IAClB,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAA;IACxC,MAAM,mBAAmB,GAAG,IAAI,GAAG,EAAuB,CAAA;IAC1D,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QACxC,KAAK,MAAM,cAAc,IAAI,yBAAyB,EAAE,CAAC;YACvD,MAAM,YAAY,GAAG,OAAO,CAAC,wBAAwB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC,CAAC,MAAM,CAAC,CAAA;YAC/F,KAAK,MAAM,OAAO,IAAI,YAAY,EAAE,CAAC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C4B,EAAE;IAC/B,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,KAAK,EAAE,GAAG,MAAM,CAAA;IAEjE,MAAM,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,SAAS,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC,OAAO,CAAC,CAAA;IAC5E,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,YAAY,CAAA;IAE7C,MAAM,MAAM,GAAG,MAAM,4BAA4B,iCAAM,MAAM,KAAE,MAAM,EAAE,KAAK,EAAE,YAAY,IAAG,CAAA;IAC7F,MAAM,CAAC,YAAY,GAAG,YAAY,CAAA;IAClC,OAAO,MAAM,CAAA;AACf,CAAC,CAAA,CAAA;AAED,MAAM,UAAU,GAAG,CAAO,MAAgD,EAA+B,EAAE;IACzG,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAA;IAC3B,OAAO,WAAW,iCAAM,MAAM,KAAE,SAAS,EAAE,CAAC,QAAQ,CAAC,IAAG,CAAA;AAC1D,CAAC,CAAA,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,iBAAiB;IACjB,wBAAwB;IACxB,gBAAgB;IAChB,oBAAoB;IACpB,UAAU;IACV,WAAW;CACZ,CAAA","sourcesContent":["import { Dictionary } from '../common'\nimport { SystemError } from '../error'\nimport { ArenaRecordNode, NodePointer, NodesMap } from '../node'\nimport { Survey, SurveyDependencyType, Surveys } from '../survey'\nimport { Dates, Objects } from '../utils'\nimport { Validations } from '../validation/validations'\nimport { NodePointers } from './nodePointers'\nimport { ArenaRecord } from './record'\nimport { RecordNodesUpdater, RecordUpdateResult } from './recordNodesUpdater'\nimport { NodeCreateParams, NodesUpdateParams } from './recordNodesUpdater/recordNodesCreator'\nimport { Records } from './records'\nimport { RecordValidator } from './recordValidator'\n\nconst validationDependencyTypes = [\n SurveyDependencyType.validations,\n SurveyDependencyType.minCount,\n SurveyDependencyType.maxCount,\n]\n\nconst getDependentValidationNodePointers = (params: {\n survey: Survey\n record: ArenaRecord\n nodes: NodesMap\n}): NodePointer[] => {\n const { survey, record, nodes } = params\n const uniquePointersByKey = new Map<string, NodePointer>()\n for (const node of Object.values(nodes)) {\n for (const dependencyType of validationDependencyTypes) {\n const nodePointers = Records.getDependentNodePointers({ survey, node, dependencyType })(record)\n for (const pointer of nodePointers) {\n const nodeCtxUuid = pointer.nodeCtx.uuid\n const nodeDefUuid = pointer.nodeDef.uuid\n const key = `${nodeCtxUuid ?? ''}:${nodeDefUuid ?? ''}`\n if (!uniquePointersByKey.has(key)) {\n uniquePointersByKey.set(key, pointer)\n }\n }\n }\n }\n return Array.from(uniquePointersByKey.values())\n}\n\nconst _onRecordNodesCreateOrUpdate = async (\n params: NodesUpdateParams & { nodes: Dictionary<ArenaRecordNode> }\n): Promise<RecordUpdateResult> => {\n const { user, survey, dateModified = Dates.nowFormattedForStorage() } = params\n\n const updateResult = await RecordNodesUpdater.updateNodesDependents(params)\n const { nodes: updatedNodes, record: updatedRecord } = updateResult\n\n const dependentValidationNodePointers = getDependentValidationNodePointers({\n survey,\n record: updatedRecord,\n nodes: updatedNodes,\n })\n\n const dependentValidationNodes = NodePointers.getNodesMapFromNodePointers({\n record: updatedRecord,\n nodePointers: dependentValidationNodePointers,\n })\n\n const nodesToValidate = { ...updatedNodes, ...dependentValidationNodes }\n\n const validationUpdatedNodes = await RecordValidator.validateNodes({\n user,\n survey,\n record: updatedRecord,\n nodes: nodesToValidate,\n })\n\n const validation = Validations.mergeValidations(validationUpdatedNodes)(Validations.getValidation(updatedRecord))\n updatedRecord.validation = validation\n updatedRecord.dateModified = dateModified\n\n updateResult.validation = validation\n\n return updateResult\n}\n\nconst createDescendants = async (params: NodeCreateParams): Promise<RecordUpdateResult> => {\n const { record: updatedRecord, nodes: createdNodes } = await RecordNodesUpdater.createDescendants(params)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: updatedRecord, nodes: createdNodes })\n}\n\nconst _createNodeAndDescendants = async (params: NodeCreateParams): Promise<RecordUpdateResult> => {\n const { record: updatedRecord, nodes: createdNodes } = await RecordNodesUpdater.createNodeAndDescendants(params)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: updatedRecord, nodes: createdNodes })\n}\n\nconst createNodeAndDescendants = async (params: NodeCreateParams): Promise<RecordUpdateResult> =>\n _createNodeAndDescendants(params)\n\nconst createRootEntity = async (\n params: NodesUpdateParams & {\n createMultipleEntities?: boolean\n }\n): Promise<RecordUpdateResult> => {\n const { survey, createMultipleEntities = true } = params\n\n return _createNodeAndDescendants({ ...params, nodeDef: Surveys.getNodeDefRoot({ survey }), createMultipleEntities })\n}\n\nconst updateAttributeValue = async (\n params: NodesUpdateParams & {\n attributeUuid: string\n value: any\n }\n): Promise<RecordUpdateResult> => {\n const { attributeUuid, record, value, dateModified = Dates.nowFormattedForStorage(), sideEffect = false } = params\n const attribute = Records.getNodeByUuid({ uuid: attributeUuid })(record)\n if (!attribute) throw new SystemError('record.nodeNotFound', { uuid: attributeUuid })\n\n let attributeUpdated = sideEffect ? attribute : { ...attribute }\n attributeUpdated.value = value\n attributeUpdated.dateModified = dateModified\n // reset defaultValueApplied flag\n attributeUpdated = Objects.dissocPath({ obj: attributeUpdated, path: ['meta', 'defaultValueApplied'], sideEffect })\n\n const nodesUpdated = { [attributeUuid]: attributeUpdated }\n\n const _record = Records.addNode(attributeUpdated, { sideEffect })(record)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: _record, nodes: nodesUpdated })\n}\n\nconst deleteNodes = async (\n params: NodesUpdateParams & {\n nodeUuids: string[]\n }\n): Promise<RecordUpdateResult> => {\n const { nodeUuids, record: _record, sideEffect = false } = params\n\n const updateResult = Records.deleteNodes(nodeUuids, { sideEffect })(_record)\n const { record, nodesDeleted } = updateResult\n\n const result = await _onRecordNodesCreateOrUpdate({ ...params, record, nodes: nodesDeleted })\n result.nodesDeleted = nodesDeleted\n return result\n}\n\nconst deleteNode = async (params: NodesUpdateParams & { nodeUuid: string }): Promise<RecordUpdateResult> => {\n const { nodeUuid } = params\n return deleteNodes({ ...params, nodeUuids: [nodeUuid] })\n}\n\nexport const RecordUpdater = {\n createDescendants,\n createNodeAndDescendants,\n createRootEntity,\n updateAttributeValue,\n deleteNode,\n deleteNodes,\n}\n"]}
|
|
@@ -16,7 +16,7 @@ const throwError = (params) => {
|
|
|
16
16
|
expressionsString,
|
|
17
17
|
error: error.toString(),
|
|
18
18
|
errorJson: error instanceof error_1.SystemError ? error.toJSON() : null,
|
|
19
|
-
});
|
|
19
|
+
}, { cause: error });
|
|
20
20
|
};
|
|
21
21
|
exports.throwError = throwError;
|
|
22
22
|
const addPointerIfAccepted = (params) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recordNodesDependentsUpdaterCommons.js","sourceRoot":"","sources":["../../../src/record/recordNodesUpdater/recordNodesDependentsUpdaterCommons.ts"],"names":[],"mappings":";;;AAAA,uCAAyC;AAEzC,2CAA+F;AAC/F,yCAAoE;AAEpE,wCAAoC;AAE7B,MAAM,UAAU,GAAG,CAAC,MAO1B,EAAE,EAAE;IACH,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,qBAAqB,EAAE,GAAG,MAAM,CAAA;IAC1F,MAAM,WAAW,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAA;IACtC,MAAM,iBAAiB,GAAG,IAAI,CAAC,SAAS,CAAC,qBAAqB,CAAC,CAAA;IAE/D,MAAM,IAAI,mBAAW,
|
|
1
|
+
{"version":3,"file":"recordNodesDependentsUpdaterCommons.js","sourceRoot":"","sources":["../../../src/record/recordNodesUpdater/recordNodesDependentsUpdaterCommons.ts"],"names":[],"mappings":";;;AAAA,uCAAyC;AAEzC,2CAA+F;AAC/F,yCAAoE;AAEpE,wCAAoC;AAE7B,MAAM,UAAU,GAAG,CAAC,MAO1B,EAAE,EAAE;IACH,MAAM,EAAE,KAAK,EAAE,Q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,WAAW,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,CAAA;IAEtH,IAAI,CAAC,kBAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QACvD,OAAO,YAAY,CAAA;IACrB,CAAC;IAED,0EAA0E;IAC1E,IAAI,oBAAoB,EAAE,CAAC;QACzB,uBAAuB,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,CAAA;IAC1F,CAAC;IAED,uGAAuG;IACvG,IAAI,6BAA6B,EAAE,CAAC;QAClC,iCAAiC,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,CAAA;IAC5F,CAAC;IAED,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA;AAzCY,QAAA,8BAA8B,GAA9B,8BAA8B,CAyC1C","sourcesContent":["import { SystemError } from '../../error'\nimport { ArenaRecordNode, NodePointer } from '../../node'\nimport { NodeDef, NodeDefExpression, NodeDefProps, NodeDefType, NodeDefs } from '../../nodeDef'\nimport { Survey, SurveyDependencyType, Surveys } from '../../survey'\nimport { ArenaRecord } from '../record'\nimport { Records } from '../records'\n\nexport const throwError = (params: {\n error: any\n errorKey: string\n expressionType: SurveyDependencyType\n survey: Survey\n nodeDef: NodeDef<NodeDefType, NodeDefProps>\n expressionsToEvaluate: NodeDefExpression[]\n}) => {\n const { error, errorKey, expressionType, survey, nodeDef, expressionsToEvaluate } = params\n const nodeDefName = nodeDef.props.name\n const expressionsString = JSON.stringify(expressionsToEvaluate)\n\n throw new SystemError(\n errorKey,\n {\n surveyName: survey.props.name,\n nodeDefName,\n expressionType,\n expressionsString,\n error: error.toString(),\n errorJson: error instanceof SystemError ? error.toJSON() : null,\n },\n { cause: error }\n )\n}\n\nconst addPointerIfAccepted = (params: {\n nodePointers: NodePointer[]\n pointer: NodePointer\n filterFn?: (nodePointer: NodePointer) => boolean\n}) => {\n const { nodePointers, pointer, filterFn } = params\n if (!filterFn || filterFn(pointer)) {\n nodePointers.push(pointer)\n }\n}\n\nconst addNewEntitySelfPointer = (params: {\n nodePointers: NodePointer[]\n survey: Survey\n record: ArenaRecord\n node: ArenaRecordNode\n sourceNodeDef: NodeDef<NodeDefType, NodeDefProps>\n filterFn?: (nodePointer: NodePointer) => boolean\n}) => {\n const { nodePointers, record, node, sourceNodeDef, filterFn } = params\n if (!node.parentUuid) {\n return\n }\n const parentNode = Records.getNodeByUuid({ uuid: node.parentUuid })(record)\n if (!parentNode) {\n return\n }\n addPointerIfAccepted({\n nodePointers,\n pointer: { nodeCtx: parentNode, nodeDef: sourceNodeDef },\n filterFn,\n })\n}\n\nconst addNewEntityChildMultiplePointers = (params: {\n nodePointers: NodePointer[]\n survey: Survey\n node: ArenaRecordNode\n sourceNodeDef: NodeDef<NodeDefType, NodeDefProps>\n filterFn?: (nodePointer: NodePointer) => boolean\n}) => {\n const { nodePointers, survey, node, sourceNodeDef, filterFn } = params\n const multipleNodeDefs = Surveys.getNodeDefChildren({ survey, nodeDef: sourceNodeDef }).filter(NodeDefs.isMultiple)\n\n for (const childDef of multipleNodeDefs) {\n addPointerIfAccepted({\n nodePointers,\n pointer: { nodeCtx: node, nodeDef: childDef },\n filterFn,\n })\n }\n}\n\nexport const getDependentNodePointersByType = (params: {\n survey: Survey\n record: ArenaRecord\n node: ArenaRecordNode\n dependencyType: SurveyDependencyType\n includeSelfWhenSourceIsAttribute?: boolean\n includeNewEntitySelf?: boolean\n includeNewEntityChildPointers?: boolean\n filterFn?: (nodePointer: NodePointer) => boolean\n}): NodePointer[] => {\n const {\n survey,\n record,\n node,\n dependencyType,\n includeSelfWhenSourceIsAttribute = false,\n includeNewEntitySelf = false,\n includeNewEntityChildPointers = false,\n filterFn,\n } = params\n\n const sourceNodeDef = Surveys.getNodeDefByUuid({ survey, uuid: node.nodeDefUuid })\n const includeSelf = includeSelfWhenSourceIsAttribute && !NodeDefs.isEntity(sourceNodeDef)\n\n const nodePointers = Records.getDependentNodePointers({ survey, node, dependencyType, includeSelf, filterFn })(record)\n\n if (!NodeDefs.isEntity(sourceNodeDef) || !node.created) {\n return nodePointers\n }\n\n // For newly created entities, include a self-pointer for the source node.\n if (includeNewEntitySelf) {\n addNewEntitySelfPointer({ nodePointers, survey, record, node, sourceNodeDef, filterFn })\n }\n\n // For new entities, include child multiple nodes so their dependency metadata/status gets updated too.\n if (includeNewEntityChildPointers) {\n addNewEntityChildMultiplePointers({ nodePointers, survey, node, sourceNodeDef, filterFn })\n }\n\n return nodePointers\n}\n"]}
|
|
@@ -84,7 +84,7 @@ const updateAttributeValue = (params) => __awaiter(void 0, void 0, void 0, funct
|
|
|
84
84
|
const { attributeUuid, record, value, dateModified = utils_1.Dates.nowFormattedForStorage(), sideEffect = false } = params;
|
|
85
85
|
const attribute = records_1.Records.getNodeByUuid({ uuid: attributeUuid })(record);
|
|
86
86
|
if (!attribute)
|
|
87
|
-
throw new error_1.SystemError('record.nodeNotFound');
|
|
87
|
+
throw new error_1.SystemError('record.nodeNotFound', { uuid: attributeUuid });
|
|
88
88
|
let attributeUpdated = sideEffect ? attribute : Object.assign({}, attribute);
|
|
89
89
|
attributeUpdated.value = value;
|
|
90
90
|
attributeUpdated.dateModified = dateModified;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recordUpdater.js","sourceRoot":"","sources":["../../src/record/recordUpdater.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,oCAAsC;AAEtC,sCAAiE;AACjE,oCAAyC;AACzC,2DAAuD;AACvD,iDAA6C;AAE7C,6DAA6E;AAE7E,uCAAmC;AACnC,uDAAmD;AAEnD,MAAM,yBAAyB,GAAG;IAChC,6BAAoB,CAAC,WAAW;IAChC,6BAAoB,CAAC,QAAQ;IAC7B,6BAAoB,CAAC,QAAQ;CAC9B,CAAA;AAED,MAAM,kCAAkC,GAAG,CAAC,MA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} from '../common'\nimport { SystemError } from '../error'\nimport { ArenaRecordNode, NodePointer, NodesMap } from '../node'\nimport { Survey, SurveyDependencyType, Surveys } from '../survey'\nimport { Dates, Objects } from '../utils'\nimport { Validations } from '../validation/validations'\nimport { NodePointers } from './nodePointers'\nimport { ArenaRecord } from './record'\nimport { RecordNodesUpdater, RecordUpdateResult } from './recordNodesUpdater'\nimport { NodeCreateParams, NodesUpdateParams } from './recordNodesUpdater/recordNodesCreator'\nimport { Records } from './records'\nimport { RecordValidator } from './recordValidator'\n\nconst validationDependencyTypes = [\n SurveyDependencyType.validations,\n SurveyDependencyType.minCount,\n SurveyDependencyType.maxCount,\n]\n\nconst getDependentValidationNodePointers = (params: {\n survey: Survey\n record: ArenaRecord\n nodes: NodesMap\n}): NodePointer[] => {\n const { survey, record, nodes } = params\n const uniquePointersByKey = new Map<string, NodePointer>()\n for (const node of Object.values(nodes)) {\n for (const dependencyType of validationDependencyTypes) {\n const nodePointers = Records.getDependentNodePointers({ survey, node, dependencyType })(record)\n for (const pointer of nodePointers) {\n const nodeCtxUuid = pointer.nodeCtx.uuid\n const nodeDefUuid = pointer.nodeDef.uuid\n const key = `${nodeCtxUuid ?? ''}:${nodeDefUuid ?? ''}`\n if (!uniquePointersByKey.has(key)) {\n uniquePointersByKey.set(key, pointer)\n }\n }\n }\n }\n return Array.from(uniquePointersByKey.values())\n}\n\nconst _onRecordNodesCreateOrUpdate = async (\n params: NodesUpdateParams & { nodes: Dictionary<ArenaRecordNode> }\n): Promise<RecordUpdateResult> => {\n const { user, survey, dateModified = Dates.nowFormattedForStorage() } = params\n\n const updateResult = await RecordNodesUpdater.updateNodesDependents(params)\n const { nodes: updatedNodes, record: updatedRecord } = updateResult\n\n const dependentValidationNodePointers = getDependentValidationNodePointers({\n survey,\n record: updatedRecord,\n nodes: updatedNodes,\n })\n\n const dependentValidationNodes = NodePointers.getNodesMapFromNodePointers({\n record: updatedRecord,\n nodePointers: dependentValidationNodePointers,\n })\n\n const nodesToValidate = { ...updatedNodes, ...dependentValidationNodes }\n\n const validationUpdatedNodes = await RecordValidator.validateNodes({\n user,\n survey,\n record: updatedRecord,\n nodes: nodesToValidate,\n })\n\n const validation = Validations.mergeValidations(validationUpdatedNodes)(Validations.getValidation(updatedRecord))\n updatedRecord.validation = validation\n updatedRecord.dateModified = dateModified\n\n updateResult.validation = validation\n\n return updateResult\n}\n\nconst createDescendants = async (params: NodeCreateParams): Promise<RecordUpdateResult> => {\n const { record: updatedRecord, nodes: createdNodes } = await RecordNodesUpdater.createDescendants(params)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: updatedRecord, nodes: createdNodes })\n}\n\nconst _createNodeAndDescendants = async (params: NodeCreateParams): Promise<RecordUpdateResult> => {\n const { record: updatedRecord, nodes: createdNodes } = await RecordNodesUpdater.createNodeAndDescendants(params)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: updatedRecord, nodes: createdNodes })\n}\n\nconst createNodeAndDescendants = async (params: NodeCreateParams): Promise<RecordUpdateResult> =>\n _createNodeAndDescendants(params)\n\nconst createRootEntity = async (\n params: NodesUpdateParams & {\n createMultipleEntities?: boolean\n }\n): Promise<RecordUpdateResult> => {\n const { survey, createMultipleEntities = true } = params\n\n return _createNodeAndDescendants({ ...params, nodeDef: Surveys.getNodeDefRoot({ survey }), createMultipleEntities })\n}\n\nconst updateAttributeValue = async (\n params: NodesUpdateParams & {\n attributeUuid: string\n value: any\n }\n): Promise<RecordUpdateResult> => {\n const { attributeUuid, record, value, dateModified = Dates.nowFormattedForStorage(), sideEffect = false } = params\n const attribute = Records.getNodeByUuid({ uuid: attributeUuid })(record)\n if (!attribute) throw new SystemError('record.nodeNotFound')\n\n let attributeUpdated = sideEffect ? attribute : { ...attribute }\n attributeUpdated.value = value\n attributeUpdated.dateModified = dateModified\n // reset defaultValueApplied flag\n attributeUpdated = Objects.dissocPath({ obj: attributeUpdated, path: ['meta', 'defaultValueApplied'], sideEffect })\n\n const nodesUpdated = { [attributeUuid]: attributeUpdated }\n\n const _record = Records.addNode(attributeUpdated, { sideEffect })(record)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: _record, nodes: nodesUpdated })\n}\n\nconst deleteNodes = async (\n params: NodesUpdateParams & {\n nodeUuids: string[]\n }\n): Promise<RecordUpdateResult> => {\n const { nodeUuids, record: _record, sideEffect = false } = params\n\n const updateResult = Records.deleteNodes(nodeUuids, { sideEffect })(_record)\n const { record, nodesDeleted } = updateResult\n\n const result = await _onRecordNodesCreateOrUpdate({ ...params, record, nodes: nodesDeleted })\n result.nodesDeleted = nodesDeleted\n return result\n}\n\nconst deleteNode = async (params: NodesUpdateParams & { nodeUuid: string }): Promise<RecordUpdateResult> => {\n const { nodeUuid } = params\n return deleteNodes({ ...params, nodeUuids: [nodeUuid] })\n}\n\nexport const RecordUpdater = {\n createDescendants,\n createNodeAndDescendants,\n createRootEntity,\n updateAttributeValue,\n deleteNode,\n deleteNodes,\n}\n"]}
|
|
1
|
+
{"version":3,"file":"recordUpdater.js","sourceRoot":"","sources":["../../src/record/recordUpdater.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,oCAAsC;AAEtC,sCAAiE;AACjE,oCAAyC;AACzC,2DAAuD;AACvD,iDAA6C;AAE7C,6DAA6E;AAE7E,uCAAmC;AACnC,uDAAmD;AAEnD,MAAM,yBAAyB,GAAG;IAChC,6BAAoB,CAAC,WAAW;IAChC,6BAAoB,CAAC,QAAQ;IAC7B,6BAAoB,CAAC,QAAQ;CAC9B,CAAA;AAED,MAAM,kCAAkC,GAAG,CAAC,MAI3C,EAAiB,EAAE;IAClB,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAA;IACxC,MAAM,mBAAmB,GAAG,IAAI,GAAG,EAAuB,CAAA;IAC1D,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QACxC,KAAK,MAAM,cAAc,IAAI,yBAAyB,EAAE,CAAC;YACv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C,MAAM,CAAC,CAAA;IAEzE,OAAO,4BAA4B,iCAAM,MAAM,KAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,IAAG,CAAA;AAC1F,CAAC,CAAA,CAAA;AAED,MAAM,WAAW,GAAG,CAClB,MAEC,EAC4B,EAAE;IAC/B,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,KAAK,EAAE,GAAG,MAAM,CAAA;IAEjE,MAAM,YAAY,GAAG,iBAAO,CAAC,WAAW,CAAC,SAAS,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC,OAAO,CAAC,CAAA;IAC5E,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,YAAY,CAAA;IAE7C,MAAM,MAAM,GAAG,MAAM,4BAA4B,iCAAM,MAAM,KAAE,MAAM,EAAE,KAAK,EAAE,YAAY,IAAG,CAAA;IAC7F,MAAM,CAAC,YAAY,GAAG,YAAY,CAAA;IAClC,OAAO,MAAM,CAAA;AACf,CAAC,CAAA,CAAA;AAED,MAAM,UAAU,GAAG,CAAO,MAAgD,EAA+B,EAAE;IACzG,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAA;IAC3B,OAAO,WAAW,iCAAM,MAAM,KAAE,SAAS,EAAE,CAAC,QAAQ,CAAC,IAAG,CAAA;AAC1D,CAAC,CAAA,CAAA;AAEY,QAAA,aAAa,GAAG;IAC3B,iBAAiB;IACjB,wBAAwB;IACxB,gBAAgB;IAChB,oBAAoB;IACpB,UAAU;IACV,WAAW;CACZ,CAAA","sourcesContent":["import { Dictionary } from '../common'\nimport { SystemError } from '../error'\nimport { ArenaRecordNode, NodePointer, NodesMap } from '../node'\nimport { Survey, SurveyDependencyType, Surveys } from '../survey'\nimport { Dates, Objects } from '../utils'\nimport { Validations } from '../validation/validations'\nimport { NodePointers } from './nodePointers'\nimport { ArenaRecord } from './record'\nimport { RecordNodesUpdater, RecordUpdateResult } from './recordNodesUpdater'\nimport { NodeCreateParams, NodesUpdateParams } from './recordNodesUpdater/recordNodesCreator'\nimport { Records } from './records'\nimport { RecordValidator } from './recordValidator'\n\nconst validationDependencyTypes = [\n SurveyDependencyType.validations,\n SurveyDependencyType.minCount,\n SurveyDependencyType.maxCount,\n]\n\nconst getDependentValidationNodePointers = (params: {\n survey: Survey\n record: ArenaRecord\n nodes: NodesMap\n}): NodePointer[] => {\n const { survey, record, nodes } = params\n const uniquePointersByKey = new Map<string, NodePointer>()\n for (const node of Object.values(nodes)) {\n for (const dependencyType of validationDependencyTypes) {\n const nodePointers = Records.getDependentNodePointers({ survey, node, dependencyType })(record)\n for (const pointer of nodePointers) {\n const nodeCtxUuid = pointer.nodeCtx.uuid\n const nodeDefUuid = pointer.nodeDef.uuid\n const key = `${nodeCtxUuid ?? ''}:${nodeDefUuid ?? ''}`\n if (!uniquePointersByKey.has(key)) {\n uniquePointersByKey.set(key, pointer)\n }\n }\n }\n }\n return Array.from(uniquePointersByKey.values())\n}\n\nconst _onRecordNodesCreateOrUpdate = async (\n params: NodesUpdateParams & { nodes: Dictionary<ArenaRecordNode> }\n): Promise<RecordUpdateResult> => {\n const { user, survey, dateModified = Dates.nowFormattedForStorage() } = params\n\n const updateResult = await RecordNodesUpdater.updateNodesDependents(params)\n const { nodes: updatedNodes, record: updatedRecord } = updateResult\n\n const dependentValidationNodePointers = getDependentValidationNodePointers({\n survey,\n record: updatedRecord,\n nodes: updatedNodes,\n })\n\n const dependentValidationNodes = NodePointers.getNodesMapFromNodePointers({\n record: updatedRecord,\n nodePointers: dependentValidationNodePointers,\n })\n\n const nodesToValidate = { ...updatedNodes, ...dependentValidationNodes }\n\n const validationUpdatedNodes = await RecordValidator.validateNodes({\n user,\n survey,\n record: updatedRecord,\n nodes: nodesToValidate,\n })\n\n const validation = Validations.mergeValidations(validationUpdatedNodes)(Validations.getValidation(updatedRecord))\n updatedRecord.validation = validation\n updatedRecord.dateModified = dateModified\n\n updateResult.validation = validation\n\n return updateResult\n}\n\nconst createDescendants = async (params: NodeCreateParams): Promise<RecordUpdateResult> => {\n const { record: updatedRecord, nodes: createdNodes } = await RecordNodesUpdater.createDescendants(params)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: updatedRecord, nodes: createdNodes })\n}\n\nconst _createNodeAndDescendants = async (params: NodeCreateParams): Promise<RecordUpdateResult> => {\n const { record: updatedRecord, nodes: createdNodes } = await RecordNodesUpdater.createNodeAndDescendants(params)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: updatedRecord, nodes: createdNodes })\n}\n\nconst createNodeAndDescendants = async (params: NodeCreateParams): Promise<RecordUpdateResult> =>\n _createNodeAndDescendants(params)\n\nconst createRootEntity = async (\n params: NodesUpdateParams & {\n createMultipleEntities?: boolean\n }\n): Promise<RecordUpdateResult> => {\n const { survey, createMultipleEntities = true } = params\n\n return _createNodeAndDescendants({ ...params, nodeDef: Surveys.getNodeDefRoot({ survey }), createMultipleEntities })\n}\n\nconst updateAttributeValue = async (\n params: NodesUpdateParams & {\n attributeUuid: string\n value: any\n }\n): Promise<RecordUpdateResult> => {\n const { attributeUuid, record, value, dateModified = Dates.nowFormattedForStorage(), sideEffect = false } = params\n const attribute = Records.getNodeByUuid({ uuid: attributeUuid })(record)\n if (!attribute) throw new SystemError('record.nodeNotFound', { uuid: attributeUuid })\n\n let attributeUpdated = sideEffect ? attribute : { ...attribute }\n attributeUpdated.value = value\n attributeUpdated.dateModified = dateModified\n // reset defaultValueApplied flag\n attributeUpdated = Objects.dissocPath({ obj: attributeUpdated, path: ['meta', 'defaultValueApplied'], sideEffect })\n\n const nodesUpdated = { [attributeUuid]: attributeUpdated }\n\n const _record = Records.addNode(attributeUpdated, { sideEffect })(record)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: _record, nodes: nodesUpdated })\n}\n\nconst deleteNodes = async (\n params: NodesUpdateParams & {\n nodeUuids: string[]\n }\n): Promise<RecordUpdateResult> => {\n const { nodeUuids, record: _record, sideEffect = false } = params\n\n const updateResult = Records.deleteNodes(nodeUuids, { sideEffect })(_record)\n const { record, nodesDeleted } = updateResult\n\n const result = await _onRecordNodesCreateOrUpdate({ ...params, record, nodes: nodesDeleted })\n result.nodesDeleted = nodesDeleted\n return result\n}\n\nconst deleteNode = async (params: NodesUpdateParams & { nodeUuid: string }): Promise<RecordUpdateResult> => {\n const { nodeUuid } = params\n return deleteNodes({ ...params, nodeUuids: [nodeUuid] })\n}\n\nexport const RecordUpdater = {\n createDescendants,\n createNodeAndDescendants,\n createRootEntity,\n updateAttributeValue,\n deleteNode,\n deleteNodes,\n}\n"]}
|