quidproquo-actionprocessor-node 0.0.261 → 0.0.263
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/lib/commonjs/actionProcessor/core/index.d.ts +2 -0
- package/lib/commonjs/actionProcessor/core/index.js +5 -1
- package/lib/commonjs/actionProcessor/core/inlineFunction/getInlineFunctionExecuteActionProcessor.d.ts +2 -0
- package/lib/commonjs/actionProcessor/core/inlineFunction/getInlineFunctionExecuteActionProcessor.js +46 -0
- package/lib/commonjs/actionProcessor/core/inlineFunction/index.d.ts +2 -0
- package/lib/commonjs/actionProcessor/core/inlineFunction/index.js +17 -0
- package/lib/commonjs/actionProcessor/core/network/getNetworkRequestActionProcessor.js +3 -0
- package/lib/commonjs/actionProcessor/core/stream/getStreamCloseActionProcessor.d.ts +2 -0
- package/lib/commonjs/actionProcessor/core/stream/getStreamCloseActionProcessor.js +25 -0
- package/lib/commonjs/actionProcessor/core/stream/getStreamReadActionProcessor.d.ts +2 -0
- package/lib/commonjs/actionProcessor/core/stream/getStreamReadActionProcessor.js +25 -0
- package/lib/commonjs/actionProcessor/core/stream/index.d.ts +2 -0
- package/lib/commonjs/actionProcessor/core/stream/index.js +18 -0
- package/lib/commonjs/actionProcessor/core/system/getSystemBatchActionProcessor.js +2 -2
- package/lib/commonjs/dynamicActionProcessor/file/getFileStreamOpenActionProcessor.d.ts +3 -0
- package/lib/commonjs/dynamicActionProcessor/file/getFileStreamOpenActionProcessor.js +136 -0
- package/lib/commonjs/dynamicActionProcessor/file/index.js +2 -1
- package/lib/esm/actionProcessor/core/index.d.ts +2 -0
- package/lib/esm/actionProcessor/core/index.js +6 -0
- package/lib/esm/actionProcessor/core/inlineFunction/getInlineFunctionExecuteActionProcessor.d.ts +2 -0
- package/lib/esm/actionProcessor/core/inlineFunction/getInlineFunctionExecuteActionProcessor.js +31 -0
- package/lib/esm/actionProcessor/core/inlineFunction/index.d.ts +2 -0
- package/lib/esm/actionProcessor/core/inlineFunction/index.js +4 -0
- package/lib/esm/actionProcessor/core/network/getNetworkRequestActionProcessor.js +3 -0
- package/lib/esm/actionProcessor/core/stream/getStreamCloseActionProcessor.d.ts +2 -0
- package/lib/esm/actionProcessor/core/stream/getStreamCloseActionProcessor.js +10 -0
- package/lib/esm/actionProcessor/core/stream/getStreamReadActionProcessor.d.ts +2 -0
- package/lib/esm/actionProcessor/core/stream/getStreamReadActionProcessor.js +10 -0
- package/lib/esm/actionProcessor/core/stream/index.d.ts +2 -0
- package/lib/esm/actionProcessor/core/stream/index.js +6 -0
- package/lib/esm/actionProcessor/core/system/getSystemBatchActionProcessor.js +2 -2
- package/lib/esm/dynamicActionProcessor/file/getFileStreamOpenActionProcessor.d.ts +3 -0
- package/lib/esm/dynamicActionProcessor/file/getFileStreamOpenActionProcessor.js +38 -0
- package/lib/esm/dynamicActionProcessor/file/index.js +2 -0
- package/package.json +4 -4
|
@@ -5,10 +5,12 @@ export * from './context';
|
|
|
5
5
|
export * from './date';
|
|
6
6
|
export * from './error';
|
|
7
7
|
export * from './guid';
|
|
8
|
+
export * from './inlineFunction';
|
|
8
9
|
export * from './log';
|
|
9
10
|
export * from './math';
|
|
10
11
|
export * from './network';
|
|
11
12
|
export * from './platform';
|
|
13
|
+
export * from './stream';
|
|
12
14
|
export * from './system';
|
|
13
15
|
export * from './customActions';
|
|
14
16
|
export declare const getCoreActionProcessor: ActionProcessorListResolver;
|
|
@@ -30,10 +30,12 @@ const context_1 = require("./context");
|
|
|
30
30
|
const date_1 = require("./date");
|
|
31
31
|
const error_1 = require("./error");
|
|
32
32
|
const guid_1 = require("./guid");
|
|
33
|
+
const inlineFunction_1 = require("./inlineFunction");
|
|
33
34
|
const log_1 = require("./log");
|
|
34
35
|
const math_1 = require("./math");
|
|
35
36
|
const network_1 = require("./network");
|
|
36
37
|
const platform_1 = require("./platform");
|
|
38
|
+
const stream_1 = require("./stream");
|
|
37
39
|
const system_1 = require("./system");
|
|
38
40
|
__exportStar(require("./claudeAi"), exports);
|
|
39
41
|
__exportStar(require("./config"), exports);
|
|
@@ -41,14 +43,16 @@ __exportStar(require("./context"), exports);
|
|
|
41
43
|
__exportStar(require("./date"), exports);
|
|
42
44
|
__exportStar(require("./error"), exports);
|
|
43
45
|
__exportStar(require("./guid"), exports);
|
|
46
|
+
__exportStar(require("./inlineFunction"), exports);
|
|
44
47
|
__exportStar(require("./log"), exports);
|
|
45
48
|
__exportStar(require("./math"), exports);
|
|
46
49
|
__exportStar(require("./network"), exports);
|
|
47
50
|
__exportStar(require("./platform"), exports);
|
|
51
|
+
__exportStar(require("./stream"), exports);
|
|
48
52
|
__exportStar(require("./system"), exports);
|
|
49
53
|
// Custom actions is not done here, as it has to be done last after all
|
|
50
54
|
__exportStar(require("./customActions"), exports);
|
|
51
55
|
const getCoreActionProcessor = (qpqConfig, dynamicModuleLoader) => __awaiter(void 0, void 0, void 0, function* () {
|
|
52
|
-
return (Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (yield (0, config_1.getConfigActionProcessor)(qpqConfig, dynamicModuleLoader))), (yield (0, context_1.getContextActionProcessor)(qpqConfig, dynamicModuleLoader))), (yield (0, claudeAi_1.getClaudeAiActionProcessor)(qpqConfig, dynamicModuleLoader))), (yield (0, date_1.getDateActionProcessor)(qpqConfig, dynamicModuleLoader))), (yield (0, error_1.getErrorActionProcessor)(qpqConfig, dynamicModuleLoader))), (yield (0, guid_1.getGuidProcessor)(qpqConfig, dynamicModuleLoader))), (yield (0, log_1.getLogActionProcessor)(qpqConfig, dynamicModuleLoader))), (yield (0, math_1.getMathActionProcessor)(qpqConfig, dynamicModuleLoader))), (yield (0, network_1.getNetworkActionProcessor)(qpqConfig, dynamicModuleLoader))), (yield (0, platform_1.getPlatformActionProcessor)(qpqConfig, dynamicModuleLoader))), (yield (0, system_1.getSystemActionProcessor)(qpqConfig, dynamicModuleLoader))));
|
|
56
|
+
return (Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (yield (0, config_1.getConfigActionProcessor)(qpqConfig, dynamicModuleLoader))), (yield (0, context_1.getContextActionProcessor)(qpqConfig, dynamicModuleLoader))), (yield (0, claudeAi_1.getClaudeAiActionProcessor)(qpqConfig, dynamicModuleLoader))), (yield (0, date_1.getDateActionProcessor)(qpqConfig, dynamicModuleLoader))), (yield (0, error_1.getErrorActionProcessor)(qpqConfig, dynamicModuleLoader))), (yield (0, guid_1.getGuidProcessor)(qpqConfig, dynamicModuleLoader))), (yield (0, log_1.getLogActionProcessor)(qpqConfig, dynamicModuleLoader))), (yield (0, math_1.getMathActionProcessor)(qpqConfig, dynamicModuleLoader))), (yield (0, network_1.getNetworkActionProcessor)(qpqConfig, dynamicModuleLoader))), (yield (0, platform_1.getPlatformActionProcessor)(qpqConfig, dynamicModuleLoader))), (yield (0, stream_1.getStreamActionProcessor)(qpqConfig, dynamicModuleLoader))), (yield (0, system_1.getSystemActionProcessor)(qpqConfig, dynamicModuleLoader))), (yield (0, inlineFunction_1.getInlineFunctionActionProcessor)(qpqConfig, dynamicModuleLoader))));
|
|
53
57
|
});
|
|
54
58
|
exports.getCoreActionProcessor = getCoreActionProcessor;
|
package/lib/commonjs/actionProcessor/core/inlineFunction/getInlineFunctionExecuteActionProcessor.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getInlineFunctionExecuteActionProcessor = void 0;
|
|
13
|
+
const quidproquo_core_1 = require("quidproquo-core");
|
|
14
|
+
const crypto_1 = require("crypto");
|
|
15
|
+
const getDateNow = () => new Date().toISOString();
|
|
16
|
+
const getProcessExecute = (qpqConfig) => {
|
|
17
|
+
const moduleName = quidproquo_core_1.qpqCoreUtils.getApplicationModuleName(qpqConfig);
|
|
18
|
+
return (payload, session, actionProcessors, logger, updateSession, dynamicModuleLoader, streamRegistry) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
const inlineFunctions = quidproquo_core_1.qpqCoreUtils.getAllInlineFunctions(qpqConfig);
|
|
20
|
+
const inlineFunction = inlineFunctions.find((f) => f.functionName === payload.functionName);
|
|
21
|
+
if (!inlineFunction) {
|
|
22
|
+
return (0, quidproquo_core_1.actionResultError)(quidproquo_core_1.ErrorTypeEnum.NotFound, `Inline function not found: [${payload.functionName}]`);
|
|
23
|
+
}
|
|
24
|
+
const story = yield dynamicModuleLoader(inlineFunction.runtime);
|
|
25
|
+
if (!story) {
|
|
26
|
+
return (0, quidproquo_core_1.actionResultError)(quidproquo_core_1.ErrorTypeEnum.NotFound, `Unable to dynamically load inline function: [${payload.functionName}]`);
|
|
27
|
+
}
|
|
28
|
+
const resolveStory = (0, quidproquo_core_1.createRuntime)(qpqConfig, {
|
|
29
|
+
context: session.context,
|
|
30
|
+
depth: (session.depth || 0) + 1,
|
|
31
|
+
decodedAccessToken: session.decodedAccessToken,
|
|
32
|
+
correlation: session.correlation,
|
|
33
|
+
}, () => __awaiter(void 0, void 0, void 0, function* () { return actionProcessors; }), getDateNow, logger, `${moduleName}::${(0, crypto_1.randomUUID)()}`, quidproquo_core_1.QpqRuntimeType.EXECUTE_STORY, dynamicModuleLoader, inlineFunction.runtime, [], streamRegistry);
|
|
34
|
+
const storyResult = yield resolveStory(story, [payload.payload]);
|
|
35
|
+
if (storyResult.error) {
|
|
36
|
+
return (0, quidproquo_core_1.actionResultError)(storyResult.error.errorType, storyResult.error.errorText, storyResult.error.errorStack ? `${payload.functionName} -> [${storyResult.error.errorStack}]` : payload.functionName);
|
|
37
|
+
}
|
|
38
|
+
return (0, quidproquo_core_1.actionResult)(storyResult.result);
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
const getInlineFunctionExecuteActionProcessor = (qpqConfig) => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
+
return ({
|
|
43
|
+
[quidproquo_core_1.InlineFunctionActionType.Execute]: getProcessExecute(qpqConfig),
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
exports.getInlineFunctionExecuteActionProcessor = getInlineFunctionExecuteActionProcessor;
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getInlineFunctionActionProcessor = void 0;
|
|
13
|
+
const getInlineFunctionExecuteActionProcessor_1 = require("./getInlineFunctionExecuteActionProcessor");
|
|
14
|
+
const getInlineFunctionActionProcessor = (qpqConfig, dynamicModuleLoader) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
return (Object.assign({}, (yield (0, getInlineFunctionExecuteActionProcessor_1.getInlineFunctionExecuteActionProcessor)(qpqConfig, dynamicModuleLoader))));
|
|
16
|
+
});
|
|
17
|
+
exports.getInlineFunctionActionProcessor = getInlineFunctionActionProcessor;
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getStreamCloseActionProcessor = void 0;
|
|
13
|
+
const quidproquo_core_1 = require("quidproquo-core");
|
|
14
|
+
const getProcessStreamClose = (qpqConfig) => {
|
|
15
|
+
return (_a, session_1, actionProcessors_1, logger_1, updateSession_1, dynamicModuleLoader_1, streamRegistry_1) => __awaiter(void 0, [_a, session_1, actionProcessors_1, logger_1, updateSession_1, dynamicModuleLoader_1, streamRegistry_1], void 0, function* ({ streamId }, session, actionProcessors, logger, updateSession, dynamicModuleLoader, streamRegistry) {
|
|
16
|
+
streamRegistry.close(streamId);
|
|
17
|
+
return (0, quidproquo_core_1.actionResult)(undefined);
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
const getStreamCloseActionProcessor = (qpqConfig) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
return ({
|
|
22
|
+
[quidproquo_core_1.StreamActionType.Close]: getProcessStreamClose(qpqConfig),
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
exports.getStreamCloseActionProcessor = getStreamCloseActionProcessor;
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getStreamReadActionProcessor = void 0;
|
|
13
|
+
const quidproquo_core_1 = require("quidproquo-core");
|
|
14
|
+
const getProcessStreamRead = (qpqConfig) => {
|
|
15
|
+
return (_a, session_1, actionProcessors_1, logger_1, updateSession_1, dynamicModuleLoader_1, streamRegistry_1) => __awaiter(void 0, [_a, session_1, actionProcessors_1, logger_1, updateSession_1, dynamicModuleLoader_1, streamRegistry_1], void 0, function* ({ streamId, noWait }, session, actionProcessors, logger, updateSession, dynamicModuleLoader, streamRegistry) {
|
|
16
|
+
const chunk = yield streamRegistry.read(streamId, noWait);
|
|
17
|
+
return (0, quidproquo_core_1.actionResult)(chunk);
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
const getStreamReadActionProcessor = (qpqConfig) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
return ({
|
|
22
|
+
[quidproquo_core_1.StreamActionType.Read]: getProcessStreamRead(qpqConfig),
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
exports.getStreamReadActionProcessor = getStreamReadActionProcessor;
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getStreamActionProcessor = void 0;
|
|
13
|
+
const getStreamCloseActionProcessor_1 = require("./getStreamCloseActionProcessor");
|
|
14
|
+
const getStreamReadActionProcessor_1 = require("./getStreamReadActionProcessor");
|
|
15
|
+
const getStreamActionProcessor = (qpqConfig, dynamicModuleLoader) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
return (Object.assign(Object.assign({}, (yield (0, getStreamCloseActionProcessor_1.getStreamCloseActionProcessor)(qpqConfig, dynamicModuleLoader))), (yield (0, getStreamReadActionProcessor_1.getStreamReadActionProcessor)(qpqConfig, dynamicModuleLoader))));
|
|
17
|
+
});
|
|
18
|
+
exports.getStreamActionProcessor = getStreamActionProcessor;
|
|
@@ -12,9 +12,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.getSystemBatchActionProcessor = void 0;
|
|
13
13
|
const quidproquo_core_1 = require("quidproquo-core");
|
|
14
14
|
const getProcessSystemBatch = (qpqConfig) => {
|
|
15
|
-
return (payload, session, actionProcessors, logger, updateSession, dynamicModuleLoader) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
return (payload, session, actionProcessors, logger, updateSession, dynamicModuleLoader, streamRegistry) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
16
|
// console.log('~~~~~~~~~~~ RUNNING BATCH ~~~~~~~~~: ', payload);
|
|
17
|
-
const batchRes = yield Promise.all(payload.actions.map((a) => (0, quidproquo_core_1.processAction)(a, actionProcessors, session, logger, updateSession, dynamicModuleLoader)));
|
|
17
|
+
const batchRes = yield Promise.all(payload.actions.map((a) => (0, quidproquo_core_1.processAction)(a, actionProcessors, session, logger, updateSession, dynamicModuleLoader, streamRegistry)));
|
|
18
18
|
// console.log('~~~~~~~~~~~ RESULT BATCH ~~~~~~~~~: ', batchRes);
|
|
19
19
|
// If there was an error, that does not want to be returned, throw that error back
|
|
20
20
|
const erroredBatchItem = batchRes.find((br, i) => (0, quidproquo_core_1.isErroredActionResult)(br) && !payload.actions[i].returnErrors);
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
45
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
46
|
+
var m = o[Symbol.asyncIterator], i;
|
|
47
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
48
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
49
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
50
|
+
};
|
|
51
|
+
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
52
|
+
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
53
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
54
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
55
|
+
return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
56
|
+
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
57
|
+
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
58
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
59
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
60
|
+
function fulfill(value) { resume("next", value); }
|
|
61
|
+
function reject(value) { resume("throw", value); }
|
|
62
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
63
|
+
};
|
|
64
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
+
exports.getFileStreamOpenActionProcessor = void 0;
|
|
66
|
+
const quidproquo_core_1 = require("quidproquo-core");
|
|
67
|
+
const fs = __importStar(require("fs"));
|
|
68
|
+
const utils_1 = require("./utils");
|
|
69
|
+
function textStreamIterator(stream) {
|
|
70
|
+
return __asyncGenerator(this, arguments, function* textStreamIterator_1() {
|
|
71
|
+
var _a, e_1, _b, _c;
|
|
72
|
+
try {
|
|
73
|
+
for (var _d = true, stream_1 = __asyncValues(stream), stream_1_1; stream_1_1 = yield __await(stream_1.next()), _a = stream_1_1.done, !_a; _d = true) {
|
|
74
|
+
_c = stream_1_1.value;
|
|
75
|
+
_d = false;
|
|
76
|
+
const chunk = _c;
|
|
77
|
+
yield yield __await(typeof chunk === 'string' ? chunk : chunk.toString('utf8'));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
81
|
+
finally {
|
|
82
|
+
try {
|
|
83
|
+
if (!_d && !_a && (_b = stream_1.return)) yield __await(_b.call(stream_1));
|
|
84
|
+
}
|
|
85
|
+
finally { if (e_1) throw e_1.error; }
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function binaryStreamIterator(stream) {
|
|
90
|
+
return __asyncGenerator(this, arguments, function* binaryStreamIterator_1() {
|
|
91
|
+
var _a, e_2, _b, _c;
|
|
92
|
+
try {
|
|
93
|
+
for (var _d = true, stream_2 = __asyncValues(stream), stream_2_1; stream_2_1 = yield __await(stream_2.next()), _a = stream_2_1.done, !_a; _d = true) {
|
|
94
|
+
_c = stream_2_1.value;
|
|
95
|
+
_d = false;
|
|
96
|
+
const chunk = _c;
|
|
97
|
+
const buffer = typeof chunk === 'string' ? Buffer.from(chunk) : chunk;
|
|
98
|
+
yield yield __await(buffer.toString('base64'));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
102
|
+
finally {
|
|
103
|
+
try {
|
|
104
|
+
if (!_d && !_a && (_b = stream_2.return)) yield __await(_b.call(stream_2));
|
|
105
|
+
}
|
|
106
|
+
finally { if (e_2) throw e_2.error; }
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
const getProcessFileStreamOpen = (qpqConfig, config) => {
|
|
111
|
+
const serviceName = quidproquo_core_1.qpqCoreUtils.getApplicationModuleName(qpqConfig);
|
|
112
|
+
return (_a, session_1, actionProcessors_1, logger_1, updateSession_1, dynamicModuleLoader_1, streamRegistry_1) => __awaiter(void 0, [_a, session_1, actionProcessors_1, logger_1, updateSession_1, dynamicModuleLoader_1, streamRegistry_1], void 0, function* ({ drive, filepath, encoding, chunkSize }, session, actionProcessors, logger, updateSession, dynamicModuleLoader, streamRegistry) {
|
|
113
|
+
try {
|
|
114
|
+
const fullPath = (0, utils_1.resolveFilePath)(config, serviceName, drive, filepath);
|
|
115
|
+
const isText = encoding === 'text';
|
|
116
|
+
const highWaterMark = chunkSize !== null && chunkSize !== void 0 ? chunkSize : 65536;
|
|
117
|
+
const readStream = fs.createReadStream(fullPath, isText ? { encoding: 'utf8', highWaterMark } : { highWaterMark });
|
|
118
|
+
const streamId = `file-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
119
|
+
const iterator = isText ? textStreamIterator(readStream) : binaryStreamIterator(readStream);
|
|
120
|
+
streamRegistry.register(streamId, iterator);
|
|
121
|
+
return (0, quidproquo_core_1.actionResult)({ id: streamId, encoding });
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
if (error.code === 'ENOENT') {
|
|
125
|
+
return (0, quidproquo_core_1.actionResultError)(quidproquo_core_1.ErrorTypeEnum.NotFound, `File not found: ${filepath}`);
|
|
126
|
+
}
|
|
127
|
+
return (0, quidproquo_core_1.actionResultError)(quidproquo_core_1.ErrorTypeEnum.GenericError, `Error opening file stream: ${error.message}`);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
const getFileStreamOpenActionProcessor = (config) => (qpqConfig) => __awaiter(void 0, void 0, void 0, function* () {
|
|
132
|
+
return ({
|
|
133
|
+
[quidproquo_core_1.FileActionType.StreamOpen]: getProcessFileStreamOpen(qpqConfig, config),
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
exports.getFileStreamOpenActionProcessor = getFileStreamOpenActionProcessor;
|
|
@@ -33,6 +33,7 @@ const getFileListDirectoryActionProcessor_1 = require("./getFileListDirectoryAct
|
|
|
33
33
|
const getFileReadBinaryContentsActionProcessor_1 = require("./getFileReadBinaryContentsActionProcessor");
|
|
34
34
|
const getFileReadObjectJsonActionProcessor_1 = require("./getFileReadObjectJsonActionProcessor");
|
|
35
35
|
const getFileReadTextContentsActionProcessor_1 = require("./getFileReadTextContentsActionProcessor");
|
|
36
|
+
const getFileStreamOpenActionProcessor_1 = require("./getFileStreamOpenActionProcessor");
|
|
36
37
|
const getFileWriteBinaryContentsActionProcessor_1 = require("./getFileWriteBinaryContentsActionProcessor");
|
|
37
38
|
const getFileWriteObjectJsonActionProcessor_1 = require("./getFileWriteObjectJsonActionProcessor");
|
|
38
39
|
const getFileWriteTextContentsActionProcessor_1 = require("./getFileWriteTextContentsActionProcessor");
|
|
@@ -40,7 +41,7 @@ __exportStar(require("./types"), exports);
|
|
|
40
41
|
// Main export that accepts configuration
|
|
41
42
|
const getFileActionProcessor = (fileStorageConfig) => {
|
|
42
43
|
return (qpqConfig, dynamicModuleLoader) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
-
return (Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (yield (0, getFileReadTextContentsActionProcessor_1.getFileReadTextContentsActionProcessor)(fileStorageConfig)(qpqConfig, dynamicModuleLoader))), (yield (0, getFileWriteTextContentsActionProcessor_1.getFileWriteTextContentsActionProcessor)(fileStorageConfig)(qpqConfig, dynamicModuleLoader))), (yield (0, getFileReadObjectJsonActionProcessor_1.getFileReadObjectJsonActionProcessor)(fileStorageConfig)(qpqConfig, dynamicModuleLoader))), (yield (0, getFileWriteObjectJsonActionProcessor_1.getFileWriteObjectJsonActionProcessor)(fileStorageConfig)(qpqConfig, dynamicModuleLoader))), (yield (0, getFileReadBinaryContentsActionProcessor_1.getFileReadBinaryContentsActionProcessor)(fileStorageConfig)(qpqConfig, dynamicModuleLoader))), (yield (0, getFileWriteBinaryContentsActionProcessor_1.getFileWriteBinaryContentsActionProcessor)(fileStorageConfig)(qpqConfig, dynamicModuleLoader))), (yield (0, getFileListDirectoryActionProcessor_1.getFileListDirectoryActionProcessor)(fileStorageConfig)(qpqConfig, dynamicModuleLoader))), (yield (0, getFileExistsActionProcessor_1.getFileExistsActionProcessor)(fileStorageConfig)(qpqConfig, dynamicModuleLoader))), (yield (0, getFileDeleteActionProcessor_1.getFileDeleteActionProcessor)(fileStorageConfig)(qpqConfig, dynamicModuleLoader))), (yield (0, getFileGenerateTemporarySecureUrlActionProcessor_1.getFileGenerateTemporarySecureUrlActionProcessor)(fileStorageConfig)(qpqConfig, dynamicModuleLoader))), (yield (0, getFileGenerateTemporaryUploadSecureUrlActionProcessor_1.getFileGenerateTemporaryUploadSecureUrlActionProcessor)(fileStorageConfig)(qpqConfig, dynamicModuleLoader))), (yield (0, getFileIsColdStorageActionProcessor_1.getFileIsColdStorageActionProcessor)(fileStorageConfig)(qpqConfig, dynamicModuleLoader))));
|
|
44
|
+
return (Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (yield (0, getFileReadTextContentsActionProcessor_1.getFileReadTextContentsActionProcessor)(fileStorageConfig)(qpqConfig, dynamicModuleLoader))), (yield (0, getFileWriteTextContentsActionProcessor_1.getFileWriteTextContentsActionProcessor)(fileStorageConfig)(qpqConfig, dynamicModuleLoader))), (yield (0, getFileReadObjectJsonActionProcessor_1.getFileReadObjectJsonActionProcessor)(fileStorageConfig)(qpqConfig, dynamicModuleLoader))), (yield (0, getFileWriteObjectJsonActionProcessor_1.getFileWriteObjectJsonActionProcessor)(fileStorageConfig)(qpqConfig, dynamicModuleLoader))), (yield (0, getFileReadBinaryContentsActionProcessor_1.getFileReadBinaryContentsActionProcessor)(fileStorageConfig)(qpqConfig, dynamicModuleLoader))), (yield (0, getFileWriteBinaryContentsActionProcessor_1.getFileWriteBinaryContentsActionProcessor)(fileStorageConfig)(qpqConfig, dynamicModuleLoader))), (yield (0, getFileListDirectoryActionProcessor_1.getFileListDirectoryActionProcessor)(fileStorageConfig)(qpqConfig, dynamicModuleLoader))), (yield (0, getFileExistsActionProcessor_1.getFileExistsActionProcessor)(fileStorageConfig)(qpqConfig, dynamicModuleLoader))), (yield (0, getFileDeleteActionProcessor_1.getFileDeleteActionProcessor)(fileStorageConfig)(qpqConfig, dynamicModuleLoader))), (yield (0, getFileGenerateTemporarySecureUrlActionProcessor_1.getFileGenerateTemporarySecureUrlActionProcessor)(fileStorageConfig)(qpqConfig, dynamicModuleLoader))), (yield (0, getFileGenerateTemporaryUploadSecureUrlActionProcessor_1.getFileGenerateTemporaryUploadSecureUrlActionProcessor)(fileStorageConfig)(qpqConfig, dynamicModuleLoader))), (yield (0, getFileIsColdStorageActionProcessor_1.getFileIsColdStorageActionProcessor)(fileStorageConfig)(qpqConfig, dynamicModuleLoader))), (yield (0, getFileStreamOpenActionProcessor_1.getFileStreamOpenActionProcessor)(fileStorageConfig)(qpqConfig, dynamicModuleLoader))));
|
|
44
45
|
});
|
|
45
46
|
};
|
|
46
47
|
exports.getFileActionProcessor = getFileActionProcessor;
|
|
@@ -5,10 +5,12 @@ export * from './context';
|
|
|
5
5
|
export * from './date';
|
|
6
6
|
export * from './error';
|
|
7
7
|
export * from './guid';
|
|
8
|
+
export * from './inlineFunction';
|
|
8
9
|
export * from './log';
|
|
9
10
|
export * from './math';
|
|
10
11
|
export * from './network';
|
|
11
12
|
export * from './platform';
|
|
13
|
+
export * from './stream';
|
|
12
14
|
export * from './system';
|
|
13
15
|
export * from './customActions';
|
|
14
16
|
export declare const getCoreActionProcessor: ActionProcessorListResolver;
|
|
@@ -4,10 +4,12 @@ import { getContextActionProcessor } from './context';
|
|
|
4
4
|
import { getDateActionProcessor } from './date';
|
|
5
5
|
import { getErrorActionProcessor } from './error';
|
|
6
6
|
import { getGuidProcessor } from './guid';
|
|
7
|
+
import { getInlineFunctionActionProcessor } from './inlineFunction';
|
|
7
8
|
import { getLogActionProcessor } from './log';
|
|
8
9
|
import { getMathActionProcessor } from './math';
|
|
9
10
|
import { getNetworkActionProcessor } from './network';
|
|
10
11
|
import { getPlatformActionProcessor } from './platform';
|
|
12
|
+
import { getStreamActionProcessor } from './stream';
|
|
11
13
|
import { getSystemActionProcessor } from './system';
|
|
12
14
|
export * from './claudeAi';
|
|
13
15
|
export * from './config';
|
|
@@ -15,10 +17,12 @@ export * from './context';
|
|
|
15
17
|
export * from './date';
|
|
16
18
|
export * from './error';
|
|
17
19
|
export * from './guid';
|
|
20
|
+
export * from './inlineFunction';
|
|
18
21
|
export * from './log';
|
|
19
22
|
export * from './math';
|
|
20
23
|
export * from './network';
|
|
21
24
|
export * from './platform';
|
|
25
|
+
export * from './stream';
|
|
22
26
|
export * from './system';
|
|
23
27
|
// Custom actions is not done here, as it has to be done last after all
|
|
24
28
|
export * from './customActions';
|
|
@@ -33,5 +37,7 @@ export const getCoreActionProcessor = async (qpqConfig, dynamicModuleLoader) =>
|
|
|
33
37
|
...(await getMathActionProcessor(qpqConfig, dynamicModuleLoader)),
|
|
34
38
|
...(await getNetworkActionProcessor(qpqConfig, dynamicModuleLoader)),
|
|
35
39
|
...(await getPlatformActionProcessor(qpqConfig, dynamicModuleLoader)),
|
|
40
|
+
...(await getStreamActionProcessor(qpqConfig, dynamicModuleLoader)),
|
|
36
41
|
...(await getSystemActionProcessor(qpqConfig, dynamicModuleLoader)),
|
|
42
|
+
...(await getInlineFunctionActionProcessor(qpqConfig, dynamicModuleLoader)),
|
|
37
43
|
});
|
package/lib/esm/actionProcessor/core/inlineFunction/getInlineFunctionExecuteActionProcessor.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { actionResult, actionResultError, createRuntime, ErrorTypeEnum, InlineFunctionActionType, qpqCoreUtils, QpqRuntimeType, } from 'quidproquo-core';
|
|
2
|
+
import { randomUUID } from 'crypto';
|
|
3
|
+
const getDateNow = () => new Date().toISOString();
|
|
4
|
+
const getProcessExecute = (qpqConfig) => {
|
|
5
|
+
const moduleName = qpqCoreUtils.getApplicationModuleName(qpqConfig);
|
|
6
|
+
return async (payload, session, actionProcessors, logger, updateSession, dynamicModuleLoader, streamRegistry) => {
|
|
7
|
+
const inlineFunctions = qpqCoreUtils.getAllInlineFunctions(qpqConfig);
|
|
8
|
+
const inlineFunction = inlineFunctions.find((f) => f.functionName === payload.functionName);
|
|
9
|
+
if (!inlineFunction) {
|
|
10
|
+
return actionResultError(ErrorTypeEnum.NotFound, `Inline function not found: [${payload.functionName}]`);
|
|
11
|
+
}
|
|
12
|
+
const story = await dynamicModuleLoader(inlineFunction.runtime);
|
|
13
|
+
if (!story) {
|
|
14
|
+
return actionResultError(ErrorTypeEnum.NotFound, `Unable to dynamically load inline function: [${payload.functionName}]`);
|
|
15
|
+
}
|
|
16
|
+
const resolveStory = createRuntime(qpqConfig, {
|
|
17
|
+
context: session.context,
|
|
18
|
+
depth: (session.depth || 0) + 1,
|
|
19
|
+
decodedAccessToken: session.decodedAccessToken,
|
|
20
|
+
correlation: session.correlation,
|
|
21
|
+
}, async () => actionProcessors, getDateNow, logger, `${moduleName}::${randomUUID()}`, QpqRuntimeType.EXECUTE_STORY, dynamicModuleLoader, inlineFunction.runtime, [], streamRegistry);
|
|
22
|
+
const storyResult = await resolveStory(story, [payload.payload]);
|
|
23
|
+
if (storyResult.error) {
|
|
24
|
+
return actionResultError(storyResult.error.errorType, storyResult.error.errorText, storyResult.error.errorStack ? `${payload.functionName} -> [${storyResult.error.errorStack}]` : payload.functionName);
|
|
25
|
+
}
|
|
26
|
+
return actionResult(storyResult.result);
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export const getInlineFunctionExecuteActionProcessor = async (qpqConfig) => ({
|
|
30
|
+
[InlineFunctionActionType.Execute]: getProcessExecute(qpqConfig),
|
|
31
|
+
});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { getInlineFunctionExecuteActionProcessor } from './getInlineFunctionExecuteActionProcessor';
|
|
2
|
+
export const getInlineFunctionActionProcessor = async (qpqConfig, dynamicModuleLoader) => ({
|
|
3
|
+
...(await getInlineFunctionExecuteActionProcessor(qpqConfig, dynamicModuleLoader)),
|
|
4
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { actionResult, StreamActionType, } from 'quidproquo-core';
|
|
2
|
+
const getProcessStreamClose = (qpqConfig) => {
|
|
3
|
+
return async ({ streamId }, session, actionProcessors, logger, updateSession, dynamicModuleLoader, streamRegistry) => {
|
|
4
|
+
streamRegistry.close(streamId);
|
|
5
|
+
return actionResult(undefined);
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export const getStreamCloseActionProcessor = async (qpqConfig) => ({
|
|
9
|
+
[StreamActionType.Close]: getProcessStreamClose(qpqConfig),
|
|
10
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { actionResult, StreamActionType, } from 'quidproquo-core';
|
|
2
|
+
const getProcessStreamRead = (qpqConfig) => {
|
|
3
|
+
return async ({ streamId, noWait }, session, actionProcessors, logger, updateSession, dynamicModuleLoader, streamRegistry) => {
|
|
4
|
+
const chunk = await streamRegistry.read(streamId, noWait);
|
|
5
|
+
return actionResult(chunk);
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export const getStreamReadActionProcessor = async (qpqConfig) => ({
|
|
9
|
+
[StreamActionType.Read]: getProcessStreamRead(qpqConfig),
|
|
10
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { getStreamCloseActionProcessor } from './getStreamCloseActionProcessor';
|
|
2
|
+
import { getStreamReadActionProcessor } from './getStreamReadActionProcessor';
|
|
3
|
+
export const getStreamActionProcessor = async (qpqConfig, dynamicModuleLoader) => ({
|
|
4
|
+
...(await getStreamCloseActionProcessor(qpqConfig, dynamicModuleLoader)),
|
|
5
|
+
...(await getStreamReadActionProcessor(qpqConfig, dynamicModuleLoader)),
|
|
6
|
+
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { actionResult, actionResultError, isErroredActionResult, processAction, resolveActionResult, resolveActionResultError, SystemActionType, } from 'quidproquo-core';
|
|
2
2
|
const getProcessSystemBatch = (qpqConfig) => {
|
|
3
|
-
return async (payload, session, actionProcessors, logger, updateSession, dynamicModuleLoader) => {
|
|
3
|
+
return async (payload, session, actionProcessors, logger, updateSession, dynamicModuleLoader, streamRegistry) => {
|
|
4
4
|
// console.log('~~~~~~~~~~~ RUNNING BATCH ~~~~~~~~~: ', payload);
|
|
5
|
-
const batchRes = await Promise.all(payload.actions.map((a) => processAction(a, actionProcessors, session, logger, updateSession, dynamicModuleLoader)));
|
|
5
|
+
const batchRes = await Promise.all(payload.actions.map((a) => processAction(a, actionProcessors, session, logger, updateSession, dynamicModuleLoader, streamRegistry)));
|
|
6
6
|
// console.log('~~~~~~~~~~~ RESULT BATCH ~~~~~~~~~: ', batchRes);
|
|
7
7
|
// If there was an error, that does not want to be returned, throw that error back
|
|
8
8
|
const erroredBatchItem = batchRes.find((br, i) => isErroredActionResult(br) && !payload.actions[i].returnErrors);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { actionResult, actionResultError, ErrorTypeEnum, FileActionType, qpqCoreUtils, } from 'quidproquo-core';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import { resolveFilePath } from './utils';
|
|
4
|
+
async function* textStreamIterator(stream) {
|
|
5
|
+
for await (const chunk of stream) {
|
|
6
|
+
yield typeof chunk === 'string' ? chunk : chunk.toString('utf8');
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
async function* binaryStreamIterator(stream) {
|
|
10
|
+
for await (const chunk of stream) {
|
|
11
|
+
const buffer = typeof chunk === 'string' ? Buffer.from(chunk) : chunk;
|
|
12
|
+
yield buffer.toString('base64');
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const getProcessFileStreamOpen = (qpqConfig, config) => {
|
|
16
|
+
const serviceName = qpqCoreUtils.getApplicationModuleName(qpqConfig);
|
|
17
|
+
return async ({ drive, filepath, encoding, chunkSize }, session, actionProcessors, logger, updateSession, dynamicModuleLoader, streamRegistry) => {
|
|
18
|
+
try {
|
|
19
|
+
const fullPath = resolveFilePath(config, serviceName, drive, filepath);
|
|
20
|
+
const isText = encoding === 'text';
|
|
21
|
+
const highWaterMark = chunkSize ?? 65536;
|
|
22
|
+
const readStream = fs.createReadStream(fullPath, isText ? { encoding: 'utf8', highWaterMark } : { highWaterMark });
|
|
23
|
+
const streamId = `file-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
24
|
+
const iterator = isText ? textStreamIterator(readStream) : binaryStreamIterator(readStream);
|
|
25
|
+
streamRegistry.register(streamId, iterator);
|
|
26
|
+
return actionResult({ id: streamId, encoding });
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
if (error.code === 'ENOENT') {
|
|
30
|
+
return actionResultError(ErrorTypeEnum.NotFound, `File not found: ${filepath}`);
|
|
31
|
+
}
|
|
32
|
+
return actionResultError(ErrorTypeEnum.GenericError, `Error opening file stream: ${error.message}`);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export const getFileStreamOpenActionProcessor = (config) => async (qpqConfig) => ({
|
|
37
|
+
[FileActionType.StreamOpen]: getProcessFileStreamOpen(qpqConfig, config),
|
|
38
|
+
});
|
|
@@ -7,6 +7,7 @@ import { getFileListDirectoryActionProcessor } from './getFileListDirectoryActio
|
|
|
7
7
|
import { getFileReadBinaryContentsActionProcessor } from './getFileReadBinaryContentsActionProcessor';
|
|
8
8
|
import { getFileReadObjectJsonActionProcessor } from './getFileReadObjectJsonActionProcessor';
|
|
9
9
|
import { getFileReadTextContentsActionProcessor } from './getFileReadTextContentsActionProcessor';
|
|
10
|
+
import { getFileStreamOpenActionProcessor } from './getFileStreamOpenActionProcessor';
|
|
10
11
|
import { getFileWriteBinaryContentsActionProcessor } from './getFileWriteBinaryContentsActionProcessor';
|
|
11
12
|
import { getFileWriteObjectJsonActionProcessor } from './getFileWriteObjectJsonActionProcessor';
|
|
12
13
|
import { getFileWriteTextContentsActionProcessor } from './getFileWriteTextContentsActionProcessor';
|
|
@@ -26,6 +27,7 @@ export const getFileActionProcessor = (fileStorageConfig) => {
|
|
|
26
27
|
...(await getFileGenerateTemporarySecureUrlActionProcessor(fileStorageConfig)(qpqConfig, dynamicModuleLoader)),
|
|
27
28
|
...(await getFileGenerateTemporaryUploadSecureUrlActionProcessor(fileStorageConfig)(qpqConfig, dynamicModuleLoader)),
|
|
28
29
|
...(await getFileIsColdStorageActionProcessor(fileStorageConfig)(qpqConfig, dynamicModuleLoader)),
|
|
30
|
+
...(await getFileStreamOpenActionProcessor(fileStorageConfig)(qpqConfig, dynamicModuleLoader)),
|
|
29
31
|
});
|
|
30
32
|
};
|
|
31
33
|
export * from "./secureUrlUtils";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "quidproquo-actionprocessor-node",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.263",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./lib/commonjs/index.js",
|
|
6
6
|
"module": "./lib/esm/index.js",
|
|
@@ -35,15 +35,15 @@
|
|
|
35
35
|
"@anthropic-ai/sdk": "^0.19.1",
|
|
36
36
|
"axios": "^1.2.1",
|
|
37
37
|
"mime-types": "^2.1.35",
|
|
38
|
-
"quidproquo-core": "0.0.
|
|
39
|
-
"quidproquo-webserver": "0.0.
|
|
38
|
+
"quidproquo-core": "0.0.263",
|
|
39
|
+
"quidproquo-webserver": "0.0.263",
|
|
40
40
|
"uuid": "^9.0.0",
|
|
41
41
|
"uuidv7": "^1.0.1"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/mime-types": "^2.1.1",
|
|
45
45
|
"@types/uuid": "^9.0.0",
|
|
46
|
-
"quidproquo-tsconfig": "0.0.
|
|
46
|
+
"quidproquo-tsconfig": "0.0.263",
|
|
47
47
|
"typescript": "^5.8.2"
|
|
48
48
|
}
|
|
49
49
|
}
|