72flow-nodejs 1.0.0 → 1.0.2
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/index.cjs +30 -7
- package/dist/index.js +30 -7
- package/package.json +1 -2
package/dist/index.cjs
CHANGED
|
@@ -321,6 +321,18 @@ var StartExecutor = class {
|
|
|
321
321
|
};
|
|
322
322
|
var EndExecutor = class {
|
|
323
323
|
static execute(node, context) {
|
|
324
|
+
const cfg = node.config;
|
|
325
|
+
const sourceNodeCode = cfg?.outputResult?.sourceCode || cfg?.sourceCode || cfg?.end?.sourceCode;
|
|
326
|
+
if (sourceNodeCode) {
|
|
327
|
+
const allOutputs = context.getNodeOutputs();
|
|
328
|
+
const targetOutput = allOutputs[sourceNodeCode];
|
|
329
|
+
if (targetOutput !== void 0) {
|
|
330
|
+
log2.info(`END \u8282\u70B9 [${node.id}] \u5339\u914D\u5230 sourceCode=${sourceNodeCode}\uFF0C\u8FD4\u56DE\u6307\u5B9A\u8282\u70B9\u8F93\u51FA`);
|
|
331
|
+
return { success: true, data: targetOutput };
|
|
332
|
+
} else {
|
|
333
|
+
log2.warn(`END \u8282\u70B9 [${node.id}] sourceCode=${sourceNodeCode} \u672A\u627E\u5230\u76EE\u6807\u8282\u70B9\u8F93\u51FA\uFF0C\u56DE\u9000\u5230\u5168\u91CF\u53D8\u91CF`);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
324
336
|
return { success: true, data: context.getVariables() };
|
|
325
337
|
}
|
|
326
338
|
};
|
|
@@ -328,7 +340,7 @@ var ScriptExecutor = class {
|
|
|
328
340
|
static execute(node, context) {
|
|
329
341
|
const cfg = node.config;
|
|
330
342
|
const scriptCfg = cfg?.script ?? {};
|
|
331
|
-
const scriptCode = typeof scriptCfg === "string" ? scriptCfg : scriptCfg?.scriptCode ?? scriptCfg?.code;
|
|
343
|
+
const scriptCode = typeof scriptCfg === "string" ? scriptCfg : scriptCfg?.scriptCode ?? scriptCfg?.code ?? cfg?.scriptCode ?? cfg?.code;
|
|
332
344
|
const scriptType = String(scriptCfg?.scriptType ?? "javascript").toLowerCase();
|
|
333
345
|
if (scriptType === "groovy") {
|
|
334
346
|
log2.warn(`SCRIPT \u8282\u70B9 [${node.id}] \u4F7F\u7528 Groovy \u8BED\u6CD5\uFF0C\u6D4F\u89C8\u5668\u5F15\u64CE\u4E0D\u652F\u6301\uFF0C\u8BF7\u5207\u6362\u5230 Java \u6267\u884C\u6A21\u5F0F`);
|
|
@@ -358,11 +370,15 @@ var ScriptExecutor = class {
|
|
|
358
370
|
// with(){} 需要 has 返回 true
|
|
359
371
|
});
|
|
360
372
|
const fn = new Function("__vars", `with(__vars) { ${scriptCode} }`);
|
|
361
|
-
fn(proxy);
|
|
373
|
+
const scriptResult = fn(proxy);
|
|
362
374
|
for (const [k, v] of Object.entries(writes)) {
|
|
363
375
|
context.setVariable(k, v);
|
|
364
376
|
}
|
|
365
|
-
|
|
377
|
+
const resultData = { ...writes };
|
|
378
|
+
if (scriptResult !== void 0) {
|
|
379
|
+
resultData.scriptResult = scriptResult;
|
|
380
|
+
}
|
|
381
|
+
return { success: true, data: Object.keys(resultData).length > 0 ? resultData : null };
|
|
366
382
|
} catch (e) {
|
|
367
383
|
log2.error(`SCRIPT \u8282\u70B9 [${node.id}] \u6267\u884C\u5931\u8D25: ${e.message}`);
|
|
368
384
|
return { success: false, message: e.message };
|
|
@@ -914,10 +930,12 @@ var FlowEngine = class extends SimpleEmitter {
|
|
|
914
930
|
}
|
|
915
931
|
// ─── 结果构建 ─────────────────────────────────────────
|
|
916
932
|
buildResult(context) {
|
|
917
|
-
const
|
|
918
|
-
const
|
|
919
|
-
|
|
920
|
-
|
|
933
|
+
const traces = context.getTraces();
|
|
934
|
+
const endTrace = [...traces].reverse().find((t) => {
|
|
935
|
+
const node = context.getNode(t.nodeId);
|
|
936
|
+
return (node?.type?.toUpperCase() === "END" || t.code?.startsWith("END")) && t.status === "COMPLETED" /* COMPLETED */;
|
|
937
|
+
});
|
|
938
|
+
const endOutput = endTrace ? endTrace.data : void 0;
|
|
921
939
|
return {
|
|
922
940
|
executionId: context.getExecutionId(),
|
|
923
941
|
status: context.getStatus(),
|
|
@@ -996,6 +1014,11 @@ var X6Parser = class {
|
|
|
996
1014
|
cfg.api = this.normalizeApiField(cfg.api, "params");
|
|
997
1015
|
cfg.api = this.normalizeApiField(cfg.api, "headers");
|
|
998
1016
|
}
|
|
1017
|
+
if (type === "SCRIPT") {
|
|
1018
|
+
if (!cfg.script && cfg.scriptCode) {
|
|
1019
|
+
cfg.script = { scriptCode: cfg.scriptCode, scriptType: cfg.scriptType ?? "javascript" };
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
999
1022
|
return cfg;
|
|
1000
1023
|
}
|
|
1001
1024
|
normalizeApiField(api, field) {
|
package/dist/index.js
CHANGED
|
@@ -288,6 +288,18 @@ var StartExecutor = class {
|
|
|
288
288
|
};
|
|
289
289
|
var EndExecutor = class {
|
|
290
290
|
static execute(node, context) {
|
|
291
|
+
const cfg = node.config;
|
|
292
|
+
const sourceNodeCode = cfg?.outputResult?.sourceCode || cfg?.sourceCode || cfg?.end?.sourceCode;
|
|
293
|
+
if (sourceNodeCode) {
|
|
294
|
+
const allOutputs = context.getNodeOutputs();
|
|
295
|
+
const targetOutput = allOutputs[sourceNodeCode];
|
|
296
|
+
if (targetOutput !== void 0) {
|
|
297
|
+
log2.info(`END \u8282\u70B9 [${node.id}] \u5339\u914D\u5230 sourceCode=${sourceNodeCode}\uFF0C\u8FD4\u56DE\u6307\u5B9A\u8282\u70B9\u8F93\u51FA`);
|
|
298
|
+
return { success: true, data: targetOutput };
|
|
299
|
+
} else {
|
|
300
|
+
log2.warn(`END \u8282\u70B9 [${node.id}] sourceCode=${sourceNodeCode} \u672A\u627E\u5230\u76EE\u6807\u8282\u70B9\u8F93\u51FA\uFF0C\u56DE\u9000\u5230\u5168\u91CF\u53D8\u91CF`);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
291
303
|
return { success: true, data: context.getVariables() };
|
|
292
304
|
}
|
|
293
305
|
};
|
|
@@ -295,7 +307,7 @@ var ScriptExecutor = class {
|
|
|
295
307
|
static execute(node, context) {
|
|
296
308
|
const cfg = node.config;
|
|
297
309
|
const scriptCfg = cfg?.script ?? {};
|
|
298
|
-
const scriptCode = typeof scriptCfg === "string" ? scriptCfg : scriptCfg?.scriptCode ?? scriptCfg?.code;
|
|
310
|
+
const scriptCode = typeof scriptCfg === "string" ? scriptCfg : scriptCfg?.scriptCode ?? scriptCfg?.code ?? cfg?.scriptCode ?? cfg?.code;
|
|
299
311
|
const scriptType = String(scriptCfg?.scriptType ?? "javascript").toLowerCase();
|
|
300
312
|
if (scriptType === "groovy") {
|
|
301
313
|
log2.warn(`SCRIPT \u8282\u70B9 [${node.id}] \u4F7F\u7528 Groovy \u8BED\u6CD5\uFF0C\u6D4F\u89C8\u5668\u5F15\u64CE\u4E0D\u652F\u6301\uFF0C\u8BF7\u5207\u6362\u5230 Java \u6267\u884C\u6A21\u5F0F`);
|
|
@@ -325,11 +337,15 @@ var ScriptExecutor = class {
|
|
|
325
337
|
// with(){} 需要 has 返回 true
|
|
326
338
|
});
|
|
327
339
|
const fn = new Function("__vars", `with(__vars) { ${scriptCode} }`);
|
|
328
|
-
fn(proxy);
|
|
340
|
+
const scriptResult = fn(proxy);
|
|
329
341
|
for (const [k, v] of Object.entries(writes)) {
|
|
330
342
|
context.setVariable(k, v);
|
|
331
343
|
}
|
|
332
|
-
|
|
344
|
+
const resultData = { ...writes };
|
|
345
|
+
if (scriptResult !== void 0) {
|
|
346
|
+
resultData.scriptResult = scriptResult;
|
|
347
|
+
}
|
|
348
|
+
return { success: true, data: Object.keys(resultData).length > 0 ? resultData : null };
|
|
333
349
|
} catch (e) {
|
|
334
350
|
log2.error(`SCRIPT \u8282\u70B9 [${node.id}] \u6267\u884C\u5931\u8D25: ${e.message}`);
|
|
335
351
|
return { success: false, message: e.message };
|
|
@@ -881,10 +897,12 @@ var FlowEngine = class extends SimpleEmitter {
|
|
|
881
897
|
}
|
|
882
898
|
// ─── 结果构建 ─────────────────────────────────────────
|
|
883
899
|
buildResult(context) {
|
|
884
|
-
const
|
|
885
|
-
const
|
|
886
|
-
|
|
887
|
-
|
|
900
|
+
const traces = context.getTraces();
|
|
901
|
+
const endTrace = [...traces].reverse().find((t) => {
|
|
902
|
+
const node = context.getNode(t.nodeId);
|
|
903
|
+
return (node?.type?.toUpperCase() === "END" || t.code?.startsWith("END")) && t.status === "COMPLETED" /* COMPLETED */;
|
|
904
|
+
});
|
|
905
|
+
const endOutput = endTrace ? endTrace.data : void 0;
|
|
888
906
|
return {
|
|
889
907
|
executionId: context.getExecutionId(),
|
|
890
908
|
status: context.getStatus(),
|
|
@@ -963,6 +981,11 @@ var X6Parser = class {
|
|
|
963
981
|
cfg.api = this.normalizeApiField(cfg.api, "params");
|
|
964
982
|
cfg.api = this.normalizeApiField(cfg.api, "headers");
|
|
965
983
|
}
|
|
984
|
+
if (type === "SCRIPT") {
|
|
985
|
+
if (!cfg.script && cfg.scriptCode) {
|
|
986
|
+
cfg.script = { scriptCode: cfg.scriptCode, scriptType: cfg.scriptType ?? "javascript" };
|
|
987
|
+
}
|
|
988
|
+
}
|
|
966
989
|
return cfg;
|
|
967
990
|
}
|
|
968
991
|
normalizeApiField(api, field) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "72flow-nodejs",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Node.js / browser implementation of the 72flow orchestration engine",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -52,4 +52,3 @@
|
|
|
52
52
|
"lodash-es": "^4.18.1"
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
|