@openforis/arena-core 2.4.2 → 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/esm/utils/fileProcessor.js +10 -18
- package/dist/esm/utils/fileProcessor.js.map +1 -1
- package/dist/esm/utils/retryProcessor.js +29 -11
- package/dist/esm/utils/retryProcessor.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/dist/utils/fileProcessor.d.ts +7 -1
- package/dist/utils/fileProcessor.js +10 -18
- package/dist/utils/fileProcessor.js.map +1 -1
- package/dist/utils/retryProcessor.d.ts +9 -1
- package/dist/utils/retryProcessor.js +29 -11
- package/dist/utils/retryProcessor.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,C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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,IAA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AAO,CAAC,OAAO,CAAC,gBAAgB,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC,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,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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aAAa,CAAC,EAAE,gBAAgB,EAAE,CAAA;IAE1D,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,gBAAgB,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC,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,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"]}
|
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { RetryProcessor } from './retryProcessor';
|
|
11
2
|
export class FileProcessor {
|
|
12
|
-
constructor({ file, filePath, chunkProcessor, onError, onComplete, chunkSize = FileProcessor.defaultChunkSize, maxTryings = FileProcessor.defaultMaxTryings, }) {
|
|
3
|
+
constructor({ file, filePath, chunkProcessor, onError, onComplete, chunkSize = FileProcessor.defaultChunkSize, maxTryings = FileProcessor.defaultMaxTryings, retryDelay = FileProcessor.defaultRetryDelay, }) {
|
|
13
4
|
// State properties
|
|
14
5
|
this.totalFileSize = 0;
|
|
15
6
|
this.running = false;
|
|
@@ -23,6 +14,7 @@ export class FileProcessor {
|
|
|
23
14
|
this.chunkProcessor = chunkProcessor;
|
|
24
15
|
this.chunkSize = chunkSize;
|
|
25
16
|
this.maxTryings = maxTryings;
|
|
17
|
+
this.retryDelay = retryDelay;
|
|
26
18
|
this.onError = onError;
|
|
27
19
|
this.onComplete = onComplete;
|
|
28
20
|
if (!this.file && !this.filePath) {
|
|
@@ -55,18 +47,14 @@ export class FileProcessor {
|
|
|
55
47
|
return Promise.resolve(file.slice((currentChunkNumber - 1) * chunkSize, currentChunkNumber === totalChunks ? undefined : currentChunkNumber * chunkSize));
|
|
56
48
|
}
|
|
57
49
|
processNextChunk() {
|
|
58
|
-
const { chunkProcessor, currentChunkNumber, totalFileSize, totalChunks, maxTryings } = this;
|
|
50
|
+
const { chunkProcessor, currentChunkNumber, totalFileSize, totalChunks, maxTryings, retryDelay } = this;
|
|
59
51
|
this.processingChunk = true;
|
|
60
52
|
this.extractCurrentFileChunk()
|
|
61
53
|
.then((content) => {
|
|
62
54
|
const retryProcessor = new RetryProcessor({
|
|
63
|
-
processor: () =>
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
this.onComplete(chunkResult);
|
|
67
|
-
}
|
|
68
|
-
}),
|
|
69
|
-
onSuccess: () => {
|
|
55
|
+
processor: () => chunkProcessor({ chunk: currentChunkNumber, totalFileSize, totalChunks, content }),
|
|
56
|
+
onSuccess: (chunkResult) => {
|
|
57
|
+
var _a;
|
|
70
58
|
this.processingChunk = false;
|
|
71
59
|
if (this.currentChunkNumber < totalChunks) {
|
|
72
60
|
// move to the next chunk also when paused: resume will continue from it
|
|
@@ -78,6 +66,8 @@ export class FileProcessor {
|
|
|
78
66
|
else {
|
|
79
67
|
this.running = false;
|
|
80
68
|
this.completed = true;
|
|
69
|
+
// called outside the retried processor: if it throws, the last chunk is not processed again
|
|
70
|
+
(_a = this.onComplete) === null || _a === void 0 ? void 0 : _a.call(this, chunkResult);
|
|
81
71
|
}
|
|
82
72
|
},
|
|
83
73
|
onFail: (error) => {
|
|
@@ -86,6 +76,7 @@ export class FileProcessor {
|
|
|
86
76
|
this.running = false;
|
|
87
77
|
},
|
|
88
78
|
maxTryings,
|
|
79
|
+
retryDelay,
|
|
89
80
|
});
|
|
90
81
|
retryProcessor.start();
|
|
91
82
|
})
|
|
@@ -130,4 +121,5 @@ export class FileProcessor {
|
|
|
130
121
|
}
|
|
131
122
|
FileProcessor.defaultChunkSize = 1024 * 1024 * 10; // 10MB
|
|
132
123
|
FileProcessor.defaultMaxTryings = 5;
|
|
124
|
+
FileProcessor.defaultRetryDelay = 1000; // 1s, then 2s, 4s...
|
|
133
125
|
//# sourceMappingURL=fileProcessor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileProcessor.js","sourceRoot":"","sources":["../../../src/utils/fileProcessor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fileProcessor.js","sourceRoot":"","sources":["../../../src/utils/fileProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAuBjD,MAAM,OAAO,aAAa;IAuBxB,YAAY,EACV,IAAI,EACJ,QAAQ,EACR,cAAc,EACd,OAAO,EACP,UAAU,EACV,SAAS,GAAG,aAAa,CAAC,gBAAgB,EAC1C,UAAU,GAAG,aAAa,CAAC,iBAAiB,EAC5C,UAAU,GAAG,aAAa,CAAC,iBAAiB,GACf;QAlB/B,mBAAmB;QACT,kBAAa,GAAW,CAAC,CAAA;QACzB,YAAO,GAAY,KAAK,CAAA;QACxB,gBAAW,GAAW,CAAC,CAAA;QACvB,uBAAkB,GAAW,CAAC,CAAA;QACxC,0FAA0F;QAChF,oBAAe,GAAY,KAAK,CAAA;QAChC,cAAS,GAAY,KAAK,CAAA;QAYlC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,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,IAAI,IAAI,CAAC,SAAS;YAAE,OAAM;QAC1C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;QACnB,8EAA8E;QAC9E,IAAI,CAAC,IAAI,CAAC,eAAe,IAAI,IAAI,CAAC,WAAW,GAAG,CAAC,EAAE,CAAC;YAClD,IAAI,CAAC,gBAAgB,EAAE,CAAA;QACzB,CAAC;IACH,CAAC;CACF;AAxJiB,8BAAgB,GAAG,IAAI,GAAG,IAAI,GAAG,EAAE,AAAnB,CAAmB,CAAC,OAAO;AAC3C,+BAAiB,GAAG,CAAC,AAAJ,CAAI;AACrB,+BAAiB,GAAG,IAAI,AAAP,CAAO,CAAC,qBAAqB","sourcesContent":["import { RetryProcessor } from './retryProcessor'\n\ntype ChunkProcessor = (args: {\n chunk: number\n content: Blob | string | Uint8Array\n totalChunks: number\n totalFileSize: number\n}) => Promise<any>\n\nexport type FileProcessorConstructorArgs = {\n file?: File\n filePath?: string\n chunkProcessor: ChunkProcessor\n onError?: (error: Error) => void\n onComplete?: (result: any) => void\n chunkSize?: number\n maxTryings?: number\n /**\n * Delay (in milliseconds) before retrying a failed chunk, doubled at every further retry.\n */\n retryDelay?: number\n}\n\nexport class FileProcessor {\n static readonly defaultChunkSize = 1024 * 1024 * 10 // 10MB\n static readonly defaultMaxTryings = 5\n static readonly defaultRetryDelay = 1000 // 1s, then 2s, 4s...\n\n private readonly file?: File\n private readonly filePath?: string\n private readonly chunkProcessor: ChunkProcessor\n private readonly chunkSize: number\n private readonly maxTryings: number\n private readonly retryDelay: number\n private readonly onError?: (error: Error) => void\n private readonly onComplete?: (result?: any) => void\n\n // State properties\n protected totalFileSize: number = 0\n protected running: boolean = false\n protected totalChunks: number = 0\n protected currentChunkNumber: number = 0\n // true while a chunk is being processed (resume must not start a second processing chain)\n protected processingChunk: boolean = false\n protected completed: boolean = false\n\n constructor({\n file,\n filePath,\n chunkProcessor,\n onError,\n onComplete,\n chunkSize = FileProcessor.defaultChunkSize,\n maxTryings = FileProcessor.defaultMaxTryings,\n retryDelay = FileProcessor.defaultRetryDelay,\n }: FileProcessorConstructorArgs) {\n this.file = file\n this.filePath = filePath\n this.chunkProcessor = chunkProcessor\n this.chunkSize = chunkSize\n this.maxTryings = maxTryings\n this.retryDelay = retryDelay\n this.onError = onError\n this.onComplete = onComplete\n\n if (!this.file && !this.filePath) {\n throw new Error('File or filePath not specified')\n }\n\n this.reset()\n }\n\n protected reset(): void {\n this.running = false\n this.totalChunks = 0\n this.currentChunkNumber = 0\n this.totalFileSize = 0\n this.processingChunk = false\n this.completed = false\n }\n\n protected calculateFileSize(): Promise<number> {\n return Promise.resolve(this.file?.size ?? 0)\n }\n\n protected onFail(error: Error): void {\n this.onError?.(error)\n }\n\n protected extractCurrentFileChunk(): Promise<Blob | string | Uint8Array> {\n const { file, currentChunkNumber, totalChunks, chunkSize } = this\n if (!file) {\n return Promise.reject(new Error('File property not initialized'))\n }\n return Promise.resolve(\n file.slice(\n (currentChunkNumber - 1) * chunkSize,\n currentChunkNumber === totalChunks ? undefined : currentChunkNumber * chunkSize\n )\n )\n }\n\n protected processNextChunk(): void {\n const { chunkProcessor, currentChunkNumber, totalFileSize, totalChunks, maxTryings, retryDelay } = this\n\n this.processingChunk = true\n this.extractCurrentFileChunk()\n .then((content) => {\n const retryProcessor = new RetryProcessor<any>({\n processor: () => chunkProcessor({ chunk: currentChunkNumber, totalFileSize, totalChunks, content }),\n onSuccess: (chunkResult) => {\n this.processingChunk = false\n if (this.currentChunkNumber < totalChunks) {\n // move to the next chunk also when paused: resume will continue from it\n this.currentChunkNumber += 1\n if (this.running) {\n this.processNextChunk()\n }\n } else {\n this.running = false\n this.completed = true\n // called outside the retried processor: if it throws, the last chunk is not processed again\n this.onComplete?.(chunkResult)\n }\n },\n onFail: (error: Error) => {\n this.processingChunk = false\n this.onFail(error)\n this.running = false\n },\n maxTryings,\n retryDelay,\n })\n retryProcessor.start()\n })\n .catch((error) => {\n this.processingChunk = false\n this.onFail(error)\n this.running = false\n })\n }\n\n start(startFromChunk: number = 1): void {\n this.running = true\n this.completed = false\n this.currentChunkNumber = startFromChunk\n this.calculateFileSize()\n .then((fileSize) => {\n this.totalFileSize = fileSize\n this.totalChunks = Math.ceil(fileSize / this.chunkSize)\n if (this.totalChunks > 0) {\n this.processNextChunk()\n }\n })\n .catch((error) => {\n this.onFail(error)\n this.running = false\n })\n }\n\n stop(): void {\n this.reset()\n }\n\n pause(): void {\n this.running = false\n }\n\n resume(): void {\n if (this.running || this.completed) return\n this.running = true\n // if a chunk is still being processed, processing continues when it completes\n if (!this.processingChunk && this.totalChunks > 0) {\n this.processNextChunk()\n }\n }\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
const toError = (error) => (error instanceof Error ? error : new Error(String(error)));
|
|
1
2
|
export class RetryProcessor {
|
|
2
|
-
constructor({ processor, onSuccess, onFail, maxTryings = 2 }) {
|
|
3
|
+
constructor({ processor, onSuccess, onFail, maxTryings = 2, retryDelay = 0 }) {
|
|
3
4
|
// State properties
|
|
4
5
|
this.currentTrying = 0;
|
|
5
6
|
this.running = false;
|
|
@@ -7,6 +8,7 @@ export class RetryProcessor {
|
|
|
7
8
|
this.onSuccess = onSuccess;
|
|
8
9
|
this.onFail = onFail;
|
|
9
10
|
this.maxTryings = maxTryings;
|
|
11
|
+
this.retryDelay = retryDelay;
|
|
10
12
|
}
|
|
11
13
|
reset() {
|
|
12
14
|
this.currentTrying = 0;
|
|
@@ -14,20 +16,36 @@ export class RetryProcessor {
|
|
|
14
16
|
}
|
|
15
17
|
processNext() {
|
|
16
18
|
this.currentTrying += 1;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
// onSuccess runs outside the retried chain: if it throws, the processor must not run again
|
|
20
|
+
this.processor().then((result) => this.handleSuccess(result), (error) => this.handleProcessorError(toError(error)));
|
|
21
|
+
}
|
|
22
|
+
handleSuccess(result) {
|
|
23
|
+
try {
|
|
24
|
+
this.onSuccess(result);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
this.onFail(toError(error));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
handleProcessorError(error) {
|
|
31
|
+
if (!this.running || this.currentTrying >= this.maxTryings) {
|
|
32
|
+
// stopped or max attempts reached
|
|
33
|
+
this.onFail(error);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const delay = this.retryDelay * Math.pow(2, (this.currentTrying - 1));
|
|
37
|
+
if (delay <= 0) {
|
|
38
|
+
this.processNext();
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
setTimeout(() => {
|
|
42
|
+
if (this.running) {
|
|
43
|
+
this.processNext();
|
|
25
44
|
}
|
|
26
45
|
else {
|
|
27
|
-
// If we've stopped or exceeded max attempts, call the fail callback
|
|
28
46
|
this.onFail(error);
|
|
29
47
|
}
|
|
30
|
-
});
|
|
48
|
+
}, delay);
|
|
31
49
|
}
|
|
32
50
|
// Public methods
|
|
33
51
|
start() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retryProcessor.js","sourceRoot":"","sources":["../../../src/utils/retryProcessor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"retryProcessor.js","sourceRoot":"","sources":["../../../src/utils/retryProcessor.ts"],"names":[],"mappings":"AAYA,MAAM,OAAO,GAAG,CAAC,KAAc,EAAS,EAAE,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AAEtG,MAAM,OAAO,cAAc;IAWzB,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,GAAG,CAAC,EAAE,UAAU,GAAG,CAAC,EAAuC;QAJjH,mBAAmB;QACX,kBAAa,GAAW,CAAC,CAAA;QACzB,YAAO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AC,EAAE,CAAC;YACf,IAAI,CAAC,WAAW,EAAE,CAAA;YAClB,OAAM;QACR,CAAC;QACD,UAAU,CAAC,GAAG,EAAE;YACd,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;gBACjB,IAAI,CAAC,WAAW,EAAE,CAAA;YACpB,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;YACpB,CAAC;QACH,CAAC,EAAE,KAAK,CAAC,CAAA;IACX,CAAC;IAED,iBAAiB;IACjB,KAAK;QACH,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;QACnB,IAAI,CAAC,WAAW,EAAE,CAAA;IACpB,CAAC;IAED,IAAI;QACF,IAAI,CAAC,KAAK,EAAE,CAAA;IACd,CAAC;CACF","sourcesContent":["interface RetryProcessorArgs<ProcessorResult> {\n processor: () => Promise<ProcessorResult>\n onSuccess: (result: ProcessorResult) => void\n onFail: (error: Error) => void\n maxTryings?: number\n /**\n * Delay (in milliseconds) before the first retry, doubled at every further retry (exponential backoff).\n * Defaults to 0 (immediate retry).\n */\n retryDelay?: number\n}\n\nconst toError = (error: unknown): Error => (error instanceof Error ? error : new Error(String(error)))\n\nexport class RetryProcessor<ProcessorResult> {\n private readonly processor: () => Promise<ProcessorResult>\n private readonly onSuccess: (result: ProcessorResult) => void\n private readonly onFail: (error: Error) => void\n private readonly maxTryings: number\n private readonly retryDelay: number\n\n // State properties\n private currentTrying: number = 0\n private running: boolean = false\n\n constructor({ processor, onSuccess, onFail, maxTryings = 2, retryDelay = 0 }: RetryProcessorArgs<ProcessorResult>) {\n this.processor = processor\n this.onSuccess = onSuccess\n this.onFail = onFail\n this.maxTryings = maxTryings\n this.retryDelay = retryDelay\n }\n\n protected reset() {\n this.currentTrying = 0\n this.running = false\n }\n\n protected processNext(): void {\n this.currentTrying += 1\n\n // onSuccess runs outside the retried chain: if it throws, the processor must not run again\n this.processor().then(\n (result) => this.handleSuccess(result),\n (error) => this.handleProcessorError(toError(error))\n )\n }\n\n private handleSuccess(result: ProcessorResult): void {\n try {\n this.onSuccess(result)\n } catch (error) {\n this.onFail(toError(error))\n }\n }\n\n private handleProcessorError(error: Error): void {\n if (!this.running || this.currentTrying >= this.maxTryings) {\n // stopped or max attempts reached\n this.onFail(error)\n return\n }\n const delay = this.retryDelay * 2 ** (this.currentTrying - 1)\n if (delay <= 0) {\n this.processNext()\n return\n }\n setTimeout(() => {\n if (this.running) {\n this.processNext()\n } else {\n this.onFail(error)\n }\n }, delay)\n }\n\n // Public methods\n start(): void {\n this.running = true\n this.processNext()\n }\n\n stop(): void {\n this.reset()\n }\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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AAW,EAAE,CAAC,CAAA;IAClF,MAAM,WAAW,GAAG,gCAAgC,IAAI,CAAC,kBAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAA;IAEzF,MAAM,YAAY,GAAG,iBAAO,CAAC,wBAAwB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,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,iDAA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E,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')\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,EA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enaRecordNode, 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"]}
|
|
@@ -12,15 +12,21 @@ export type FileProcessorConstructorArgs = {
|
|
|
12
12
|
onComplete?: (result: any) => void;
|
|
13
13
|
chunkSize?: number;
|
|
14
14
|
maxTryings?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Delay (in milliseconds) before retrying a failed chunk, doubled at every further retry.
|
|
17
|
+
*/
|
|
18
|
+
retryDelay?: number;
|
|
15
19
|
};
|
|
16
20
|
export declare class FileProcessor {
|
|
17
21
|
static readonly defaultChunkSize: number;
|
|
18
22
|
static readonly defaultMaxTryings = 5;
|
|
23
|
+
static readonly defaultRetryDelay = 1000;
|
|
19
24
|
private readonly file?;
|
|
20
25
|
private readonly filePath?;
|
|
21
26
|
private readonly chunkProcessor;
|
|
22
27
|
private readonly chunkSize;
|
|
23
28
|
private readonly maxTryings;
|
|
29
|
+
private readonly retryDelay;
|
|
24
30
|
private readonly onError?;
|
|
25
31
|
private readonly onComplete?;
|
|
26
32
|
protected totalFileSize: number;
|
|
@@ -29,7 +35,7 @@ export declare class FileProcessor {
|
|
|
29
35
|
protected currentChunkNumber: number;
|
|
30
36
|
protected processingChunk: boolean;
|
|
31
37
|
protected completed: boolean;
|
|
32
|
-
constructor({ file, filePath, chunkProcessor, onError, onComplete, chunkSize, maxTryings, }: FileProcessorConstructorArgs);
|
|
38
|
+
constructor({ file, filePath, chunkProcessor, onError, onComplete, chunkSize, maxTryings, retryDelay, }: FileProcessorConstructorArgs);
|
|
33
39
|
protected reset(): void;
|
|
34
40
|
protected calculateFileSize(): Promise<number>;
|
|
35
41
|
protected onFail(error: Error): void;
|
|
@@ -1,18 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.FileProcessor = void 0;
|
|
13
4
|
const retryProcessor_1 = require("./retryProcessor");
|
|
14
5
|
class FileProcessor {
|
|
15
|
-
constructor({ file, filePath, chunkProcessor, onError, onComplete, chunkSize = FileProcessor.defaultChunkSize, maxTryings = FileProcessor.defaultMaxTryings, }) {
|
|
6
|
+
constructor({ file, filePath, chunkProcessor, onError, onComplete, chunkSize = FileProcessor.defaultChunkSize, maxTryings = FileProcessor.defaultMaxTryings, retryDelay = FileProcessor.defaultRetryDelay, }) {
|
|
16
7
|
// State properties
|
|
17
8
|
this.totalFileSize = 0;
|
|
18
9
|
this.running = false;
|
|
@@ -26,6 +17,7 @@ class FileProcessor {
|
|
|
26
17
|
this.chunkProcessor = chunkProcessor;
|
|
27
18
|
this.chunkSize = chunkSize;
|
|
28
19
|
this.maxTryings = maxTryings;
|
|
20
|
+
this.retryDelay = retryDelay;
|
|
29
21
|
this.onError = onError;
|
|
30
22
|
this.onComplete = onComplete;
|
|
31
23
|
if (!this.file && !this.filePath) {
|
|
@@ -58,18 +50,14 @@ class FileProcessor {
|
|
|
58
50
|
return Promise.resolve(file.slice((currentChunkNumber - 1) * chunkSize, currentChunkNumber === totalChunks ? undefined : currentChunkNumber * chunkSize));
|
|
59
51
|
}
|
|
60
52
|
processNextChunk() {
|
|
61
|
-
const { chunkProcessor, currentChunkNumber, totalFileSize, totalChunks, maxTryings } = this;
|
|
53
|
+
const { chunkProcessor, currentChunkNumber, totalFileSize, totalChunks, maxTryings, retryDelay } = this;
|
|
62
54
|
this.processingChunk = true;
|
|
63
55
|
this.extractCurrentFileChunk()
|
|
64
56
|
.then((content) => {
|
|
65
57
|
const retryProcessor = new retryProcessor_1.RetryProcessor({
|
|
66
|
-
processor: () =>
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
this.onComplete(chunkResult);
|
|
70
|
-
}
|
|
71
|
-
}),
|
|
72
|
-
onSuccess: () => {
|
|
58
|
+
processor: () => chunkProcessor({ chunk: currentChunkNumber, totalFileSize, totalChunks, content }),
|
|
59
|
+
onSuccess: (chunkResult) => {
|
|
60
|
+
var _a;
|
|
73
61
|
this.processingChunk = false;
|
|
74
62
|
if (this.currentChunkNumber < totalChunks) {
|
|
75
63
|
// move to the next chunk also when paused: resume will continue from it
|
|
@@ -81,6 +69,8 @@ class FileProcessor {
|
|
|
81
69
|
else {
|
|
82
70
|
this.running = false;
|
|
83
71
|
this.completed = true;
|
|
72
|
+
// called outside the retried processor: if it throws, the last chunk is not processed again
|
|
73
|
+
(_a = this.onComplete) === null || _a === void 0 ? void 0 : _a.call(this, chunkResult);
|
|
84
74
|
}
|
|
85
75
|
},
|
|
86
76
|
onFail: (error) => {
|
|
@@ -89,6 +79,7 @@ class FileProcessor {
|
|
|
89
79
|
this.running = false;
|
|
90
80
|
},
|
|
91
81
|
maxTryings,
|
|
82
|
+
retryDelay,
|
|
92
83
|
});
|
|
93
84
|
retryProcessor.start();
|
|
94
85
|
})
|
|
@@ -134,4 +125,5 @@ class FileProcessor {
|
|
|
134
125
|
exports.FileProcessor = FileProcessor;
|
|
135
126
|
FileProcessor.defaultChunkSize = 1024 * 1024 * 10; // 10MB
|
|
136
127
|
FileProcessor.defaultMaxTryings = 5;
|
|
128
|
+
FileProcessor.defaultRetryDelay = 1000; // 1s, then 2s, 4s...
|
|
137
129
|
//# sourceMappingURL=fileProcessor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileProcessor.js","sourceRoot":"","sources":["../../src/utils/fileProcessor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fileProcessor.js","sourceRoot":"","sources":["../../src/utils/fileProcessor.ts"],"names":[],"mappings":";;;AAAA,qDAAiD;AAuBjD;IAuBE,YAAY,EACV,IAAI,EACJ,QAAQ,EACR,cAAc,EACd,OAAO,EACP,UAAU,EACV,SAAS,GAAG,aAAa,CAAC,gBAAgB,EAC1C,UAAU,GAAG,aAAa,CAAC,iBAAiB,EAC5C,UAAU,GAAG,aAAa,CAAC,iBAAiB,GACf;QAlB/B,mBAAmB;QACT,kBAAa,GAAW,CAAC,CAAA;QACzB,YAAO,GAAY,KAAK,CAAA;QACxB,gBAAW,GAAW,CAAC,CAAA;QACvB,uBAAkB,GAAW,CAAC,CAAA;QACxC,0FAA0F;QAChF,oBAAe,GAAY,KAAK,CAAA;QAChC,cAAS,GAAY,KAAK,CAAA;QAYlC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,cAAc,GAAG,cAAc,CAAA;QACpC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,UA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,IAAI,IAAI,CAAC,WAAW,GAAG,CAAC,EAAE,CAAC;YAClD,IAAI,CAAC,gBAAgB,EAAE,CAAA;QACzB,CAAC;IACH,CAAC;CACF;;AAxJiB,8BAAgB,GAAG,IAAI,GAAG,IAAI,GAAG,EAAE,AAAnB,CAAmB,CAAC,OAAO;AAC3C,+BAAiB,GAAG,CAAC,AAAJ,CAAI;AACrB,+BAAiB,GAAG,IAAI,AAAP,CAAO,CAAC,qBAAqB","sourcesContent":["import { RetryProcessor } from './retryProcessor'\n\ntype ChunkProcessor = (args: {\n chunk: number\n content: Blob | string | Uint8Array\n totalChunks: number\n totalFileSize: number\n}) => Promise<any>\n\nexport type FileProcessorConstructorArgs = {\n file?: File\n filePath?: string\n chunkProcessor: ChunkProcessor\n onError?: (error: Error) => void\n onComplete?: (result: any) => void\n chunkSize?: number\n maxTryings?: number\n /**\n * Delay (in milliseconds) before retrying a failed chunk, doubled at every further retry.\n */\n retryDelay?: number\n}\n\nexport class FileProcessor {\n static readonly defaultChunkSize = 1024 * 1024 * 10 // 10MB\n static readonly defaultMaxTryings = 5\n static readonly defaultRetryDelay = 1000 // 1s, then 2s, 4s...\n\n private readonly file?: File\n private readonly filePath?: string\n private readonly chunkProcessor: ChunkProcessor\n private readonly chunkSize: number\n private readonly maxTryings: number\n private readonly retryDelay: number\n private readonly onError?: (error: Error) => void\n private readonly onComplete?: (result?: any) => void\n\n // State properties\n protected totalFileSize: number = 0\n protected running: boolean = false\n protected totalChunks: number = 0\n protected currentChunkNumber: number = 0\n // true while a chunk is being processed (resume must not start a second processing chain)\n protected processingChunk: boolean = false\n protected completed: boolean = false\n\n constructor({\n file,\n filePath,\n chunkProcessor,\n onError,\n onComplete,\n chunkSize = FileProcessor.defaultChunkSize,\n maxTryings = FileProcessor.defaultMaxTryings,\n retryDelay = FileProcessor.defaultRetryDelay,\n }: FileProcessorConstructorArgs) {\n this.file = file\n this.filePath = filePath\n this.chunkProcessor = chunkProcessor\n this.chunkSize = chunkSize\n this.maxTryings = maxTryings\n this.retryDelay = retryDelay\n this.onError = onError\n this.onComplete = onComplete\n\n if (!this.file && !this.filePath) {\n throw new Error('File or filePath not specified')\n }\n\n this.reset()\n }\n\n protected reset(): void {\n this.running = false\n this.totalChunks = 0\n this.currentChunkNumber = 0\n this.totalFileSize = 0\n this.processingChunk = false\n this.completed = false\n }\n\n protected calculateFileSize(): Promise<number> {\n return Promise.resolve(this.file?.size ?? 0)\n }\n\n protected onFail(error: Error): void {\n this.onError?.(error)\n }\n\n protected extractCurrentFileChunk(): Promise<Blob | string | Uint8Array> {\n const { file, currentChunkNumber, totalChunks, chunkSize } = this\n if (!file) {\n return Promise.reject(new Error('File property not initialized'))\n }\n return Promise.resolve(\n file.slice(\n (currentChunkNumber - 1) * chunkSize,\n currentChunkNumber === totalChunks ? undefined : currentChunkNumber * chunkSize\n )\n )\n }\n\n protected processNextChunk(): void {\n const { chunkProcessor, currentChunkNumber, totalFileSize, totalChunks, maxTryings, retryDelay } = this\n\n this.processingChunk = true\n this.extractCurrentFileChunk()\n .then((content) => {\n const retryProcessor = new RetryProcessor<any>({\n processor: () => chunkProcessor({ chunk: currentChunkNumber, totalFileSize, totalChunks, content }),\n onSuccess: (chunkResult) => {\n this.processingChunk = false\n if (this.currentChunkNumber < totalChunks) {\n // move to the next chunk also when paused: resume will continue from it\n this.currentChunkNumber += 1\n if (this.running) {\n this.processNextChunk()\n }\n } else {\n this.running = false\n this.completed = true\n // called outside the retried processor: if it throws, the last chunk is not processed again\n this.onComplete?.(chunkResult)\n }\n },\n onFail: (error: Error) => {\n this.processingChunk = false\n this.onFail(error)\n this.running = false\n },\n maxTryings,\n retryDelay,\n })\n retryProcessor.start()\n })\n .catch((error) => {\n this.processingChunk = false\n this.onFail(error)\n this.running = false\n })\n }\n\n start(startFromChunk: number = 1): void {\n this.running = true\n this.completed = false\n this.currentChunkNumber = startFromChunk\n this.calculateFileSize()\n .then((fileSize) => {\n this.totalFileSize = fileSize\n this.totalChunks = Math.ceil(fileSize / this.chunkSize)\n if (this.totalChunks > 0) {\n this.processNextChunk()\n }\n })\n .catch((error) => {\n this.onFail(error)\n this.running = false\n })\n }\n\n stop(): void {\n this.reset()\n }\n\n pause(): void {\n this.running = false\n }\n\n resume(): void {\n if (this.running || this.completed) return\n this.running = true\n // if a chunk is still being processed, processing continues when it completes\n if (!this.processingChunk && this.totalChunks > 0) {\n this.processNextChunk()\n }\n }\n}\n"]}
|
|
@@ -3,17 +3,25 @@ interface RetryProcessorArgs<ProcessorResult> {
|
|
|
3
3
|
onSuccess: (result: ProcessorResult) => void;
|
|
4
4
|
onFail: (error: Error) => void;
|
|
5
5
|
maxTryings?: number;
|
|
6
|
+
/**
|
|
7
|
+
* Delay (in milliseconds) before the first retry, doubled at every further retry (exponential backoff).
|
|
8
|
+
* Defaults to 0 (immediate retry).
|
|
9
|
+
*/
|
|
10
|
+
retryDelay?: number;
|
|
6
11
|
}
|
|
7
12
|
export declare class RetryProcessor<ProcessorResult> {
|
|
8
13
|
private readonly processor;
|
|
9
14
|
private readonly onSuccess;
|
|
10
15
|
private readonly onFail;
|
|
11
16
|
private readonly maxTryings;
|
|
17
|
+
private readonly retryDelay;
|
|
12
18
|
private currentTrying;
|
|
13
19
|
private running;
|
|
14
|
-
constructor({ processor, onSuccess, onFail, maxTryings }: RetryProcessorArgs<ProcessorResult>);
|
|
20
|
+
constructor({ processor, onSuccess, onFail, maxTryings, retryDelay }: RetryProcessorArgs<ProcessorResult>);
|
|
15
21
|
protected reset(): void;
|
|
16
22
|
protected processNext(): void;
|
|
23
|
+
private handleSuccess;
|
|
24
|
+
private handleProcessorError;
|
|
17
25
|
start(): void;
|
|
18
26
|
stop(): void;
|
|
19
27
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RetryProcessor = void 0;
|
|
4
|
+
const toError = (error) => (error instanceof Error ? error : new Error(String(error)));
|
|
4
5
|
class RetryProcessor {
|
|
5
|
-
constructor({ processor, onSuccess, onFail, maxTryings = 2 }) {
|
|
6
|
+
constructor({ processor, onSuccess, onFail, maxTryings = 2, retryDelay = 0 }) {
|
|
6
7
|
// State properties
|
|
7
8
|
this.currentTrying = 0;
|
|
8
9
|
this.running = false;
|
|
@@ -10,6 +11,7 @@ class RetryProcessor {
|
|
|
10
11
|
this.onSuccess = onSuccess;
|
|
11
12
|
this.onFail = onFail;
|
|
12
13
|
this.maxTryings = maxTryings;
|
|
14
|
+
this.retryDelay = retryDelay;
|
|
13
15
|
}
|
|
14
16
|
reset() {
|
|
15
17
|
this.currentTrying = 0;
|
|
@@ -17,20 +19,36 @@ class RetryProcessor {
|
|
|
17
19
|
}
|
|
18
20
|
processNext() {
|
|
19
21
|
this.currentTrying += 1;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
// onSuccess runs outside the retried chain: if it throws, the processor must not run again
|
|
23
|
+
this.processor().then((result) => this.handleSuccess(result), (error) => this.handleProcessorError(toError(error)));
|
|
24
|
+
}
|
|
25
|
+
handleSuccess(result) {
|
|
26
|
+
try {
|
|
27
|
+
this.onSuccess(result);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
this.onFail(toError(error));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
handleProcessorError(error) {
|
|
34
|
+
if (!this.running || this.currentTrying >= this.maxTryings) {
|
|
35
|
+
// stopped or max attempts reached
|
|
36
|
+
this.onFail(error);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const delay = this.retryDelay * Math.pow(2, (this.currentTrying - 1));
|
|
40
|
+
if (delay <= 0) {
|
|
41
|
+
this.processNext();
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
setTimeout(() => {
|
|
45
|
+
if (this.running) {
|
|
46
|
+
this.processNext();
|
|
28
47
|
}
|
|
29
48
|
else {
|
|
30
|
-
// If we've stopped or exceeded max attempts, call the fail callback
|
|
31
49
|
this.onFail(error);
|
|
32
50
|
}
|
|
33
|
-
});
|
|
51
|
+
}, delay);
|
|
34
52
|
}
|
|
35
53
|
// Public methods
|
|
36
54
|
start() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retryProcessor.js","sourceRoot":"","sources":["../../src/utils/retryProcessor.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"retryProcessor.js","sourceRoot":"","sources":["../../src/utils/retryProcessor.ts"],"names":[],"mappings":";;;AAYA,MAAM,OAAO,GAAG,CAAC,KAAc,EAAS,EAAE,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AAEtG;IAWE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,GAAG,CAAC,EAAE,UAAU,GAAG,CAAC,EAAuC;QAJjH,mBAAmB;QACX,kBAAa,GAAW,CAAC,CAAA;QACzB,YAAO,GAAY,KAAK,CAAA;QAG9B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;IAC9B,CAAC;IAES,KAAK;QACb,IAAI,CAAC,aAAa,GAAG,CAAC,CAAA;QACtB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAA;IACtB,CAAC;IAES,WAAW;QACnB,IAAI,CAAC,aAAa,IAAI,CAAC,CAAA;QAEvB,2FAA2F;QAC3F,IAAI,CAAC,SAAS,EAAE,CAAC,IAAI,CACnB,CAAC,MAAM,EAAE,EAAE,CAAC,I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ProcessorArgs<ProcessorResult> {\n processor: () => Promise<ProcessorResult>\n onSuccess: (result: ProcessorResult) => void\n onFail: (error: Error) => void\n maxTryings?: number\n /**\n * Delay (in milliseconds) before the first retry, doubled at every further retry (exponential backoff).\n * Defaults to 0 (immediate retry).\n */\n retryDelay?: number\n}\n\nconst toError = (error: unknown): Error => (error instanceof Error ? error : new Error(String(error)))\n\nexport class RetryProcessor<ProcessorResult> {\n private readonly processor: () => Promise<ProcessorResult>\n private readonly onSuccess: (result: ProcessorResult) => void\n private readonly onFail: (error: Error) => void\n private readonly maxTryings: number\n private readonly retryDelay: number\n\n // State properties\n private currentTrying: number = 0\n private running: boolean = false\n\n constructor({ processor, onSuccess, onFail, maxTryings = 2, retryDelay = 0 }: RetryProcessorArgs<ProcessorResult>) {\n this.processor = processor\n this.onSuccess = onSuccess\n this.onFail = onFail\n this.maxTryings = maxTryings\n this.retryDelay = retryDelay\n }\n\n protected reset() {\n this.currentTrying = 0\n this.running = false\n }\n\n protected processNext(): void {\n this.currentTrying += 1\n\n // onSuccess runs outside the retried chain: if it throws, the processor must not run again\n this.processor().then(\n (result) => this.handleSuccess(result),\n (error) => this.handleProcessorError(toError(error))\n )\n }\n\n private handleSuccess(result: ProcessorResult): void {\n try {\n this.onSuccess(result)\n } catch (error) {\n this.onFail(toError(error))\n }\n }\n\n private handleProcessorError(error: Error): void {\n if (!this.running || this.currentTrying >= this.maxTryings) {\n // stopped or max attempts reached\n this.onFail(error)\n return\n }\n const delay = this.retryDelay * 2 ** (this.currentTrying - 1)\n if (delay <= 0) {\n this.processNext()\n return\n }\n setTimeout(() => {\n if (this.running) {\n this.processNext()\n } else {\n this.onFail(error)\n }\n }, delay)\n }\n\n // Public methods\n start(): void {\n this.running = true\n this.processNext()\n }\n\n stop(): void {\n this.reset()\n }\n}\n"]}
|