quidproquo-actionprocessor-node 0.0.206 → 0.0.208
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.
|
@@ -10,16 +10,35 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const quidproquo_core_1 = require("quidproquo-core");
|
|
13
|
-
const processBatch = (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
const processBatch = (payload, session, actionProcessors, logger, updateSession) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
// console.log('~~~~~~~~~~~ RUNNING BATCH ~~~~~~~~~: ', payload);
|
|
15
|
+
const batchRes = yield Promise.all(payload.actions.map((a) => (0, quidproquo_core_1.processAction)(a, actionProcessors, session, logger, updateSession)));
|
|
16
|
+
// console.log('~~~~~~~~~~~ RESULT BATCH ~~~~~~~~~: ', batchRes);
|
|
17
|
+
// If there was an error, that does not want to be returned, throw that error back
|
|
18
|
+
const erroredBatchItem = batchRes.find((br, i) => (0, quidproquo_core_1.isErroredActionResult)(br) && !payload.actions[i].returnErrors);
|
|
17
19
|
if (erroredBatchItem) {
|
|
18
20
|
const error = (0, quidproquo_core_1.resolveActionResultError)(erroredBatchItem);
|
|
19
21
|
return (0, quidproquo_core_1.actionResultError)(quidproquo_core_1.ErrorTypeEnum.GenericError, error.errorText, error.errorStack);
|
|
20
22
|
}
|
|
21
23
|
// unwrap the values
|
|
22
|
-
return (0, quidproquo_core_1.actionResult)(batchRes.map((br) =>
|
|
24
|
+
return (0, quidproquo_core_1.actionResult)(batchRes.map((br, i) => {
|
|
25
|
+
// If we want to return errors, return the either result.
|
|
26
|
+
if (payload.actions[i].returnErrors) {
|
|
27
|
+
const isSuccess = !(0, quidproquo_core_1.isErroredActionResult)(br);
|
|
28
|
+
const result = isSuccess
|
|
29
|
+
? {
|
|
30
|
+
success: true,
|
|
31
|
+
result: (0, quidproquo_core_1.resolveActionResult)(br),
|
|
32
|
+
}
|
|
33
|
+
: {
|
|
34
|
+
success: false,
|
|
35
|
+
error: (0, quidproquo_core_1.resolveActionResultError)(br),
|
|
36
|
+
};
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
// return the resolved result
|
|
40
|
+
return (0, quidproquo_core_1.resolveActionResult)(br);
|
|
41
|
+
}));
|
|
23
42
|
});
|
|
24
43
|
exports.default = {
|
|
25
44
|
[quidproquo_core_1.SystemActionType.Batch]: processBatch,
|
|
@@ -1,14 +1,33 @@
|
|
|
1
1
|
import { ErrorTypeEnum, SystemActionType, actionResult, actionResultError, isErroredActionResult, processAction, resolveActionResult, resolveActionResultError, } from 'quidproquo-core';
|
|
2
|
-
const processBatch = async (
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
const processBatch = async (payload, session, actionProcessors, logger, updateSession) => {
|
|
3
|
+
// console.log('~~~~~~~~~~~ RUNNING BATCH ~~~~~~~~~: ', payload);
|
|
4
|
+
const batchRes = await Promise.all(payload.actions.map((a) => processAction(a, actionProcessors, session, logger, updateSession)));
|
|
5
|
+
// console.log('~~~~~~~~~~~ RESULT BATCH ~~~~~~~~~: ', batchRes);
|
|
6
|
+
// If there was an error, that does not want to be returned, throw that error back
|
|
7
|
+
const erroredBatchItem = batchRes.find((br, i) => isErroredActionResult(br) && !payload.actions[i].returnErrors);
|
|
6
8
|
if (erroredBatchItem) {
|
|
7
9
|
const error = resolveActionResultError(erroredBatchItem);
|
|
8
10
|
return actionResultError(ErrorTypeEnum.GenericError, error.errorText, error.errorStack);
|
|
9
11
|
}
|
|
10
12
|
// unwrap the values
|
|
11
|
-
return actionResult(batchRes.map((br) =>
|
|
13
|
+
return actionResult(batchRes.map((br, i) => {
|
|
14
|
+
// If we want to return errors, return the either result.
|
|
15
|
+
if (payload.actions[i].returnErrors) {
|
|
16
|
+
const isSuccess = !isErroredActionResult(br);
|
|
17
|
+
const result = isSuccess
|
|
18
|
+
? {
|
|
19
|
+
success: true,
|
|
20
|
+
result: resolveActionResult(br),
|
|
21
|
+
}
|
|
22
|
+
: {
|
|
23
|
+
success: false,
|
|
24
|
+
error: resolveActionResultError(br),
|
|
25
|
+
};
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
// return the resolved result
|
|
29
|
+
return resolveActionResult(br);
|
|
30
|
+
}));
|
|
12
31
|
};
|
|
13
32
|
export default {
|
|
14
33
|
[SystemActionType.Batch]: processBatch,
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "quidproquo-actionprocessor-node",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.208",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./lib/commonjs/index.js",
|
|
6
6
|
"module": "./lib/esm/index.js",
|
|
7
|
-
"types": "./lib/
|
|
7
|
+
"types": "./lib/commonjs/index.d.ts",
|
|
8
8
|
"sideEffects": false,
|
|
9
9
|
"files": [
|
|
10
10
|
"lib/**/*"
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
14
14
|
"clean": "npx rimraf lib && npx rimraf node_modules",
|
|
15
15
|
"build": "npm run clean && npm run build:esm && npm run build:cjs",
|
|
16
|
-
"watch": "tsc -p tsconfig.
|
|
16
|
+
"watch": "tsc -p tsconfig.commonjs.json -w",
|
|
17
17
|
"build:cjs": "tsc -p tsconfig.commonjs.json",
|
|
18
18
|
"build:esm": "tsc -p tsconfig.esm.json"
|
|
19
19
|
},
|
|
@@ -32,13 +32,13 @@
|
|
|
32
32
|
"@anthropic-ai/sdk": "^0.19.1",
|
|
33
33
|
"axios": "^1.2.1",
|
|
34
34
|
"mime-types": "^2.1.35",
|
|
35
|
-
"quidproquo-core": "0.0.
|
|
35
|
+
"quidproquo-core": "0.0.208",
|
|
36
36
|
"uuid": "^9.0.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/mime-types": "^2.1.1",
|
|
40
40
|
"@types/uuid": "^9.0.0",
|
|
41
|
-
"quidproquo-tsconfig": "0.0.
|
|
41
|
+
"quidproquo-tsconfig": "0.0.208",
|
|
42
42
|
"typescript": "^4.9.3"
|
|
43
43
|
}
|
|
44
44
|
}
|