mcpgraph 0.1.15 → 0.1.16
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/README.md +26 -1
- package/dist/api.d.ts +13 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +40 -0
- package/dist/api.js.map +1 -1
- package/dist/config/expression-validator.d.ts +12 -0
- package/dist/config/expression-validator.d.ts.map +1 -0
- package/dist/config/expression-validator.js +77 -0
- package/dist/config/expression-validator.js.map +1 -0
- package/dist/config/parser.d.ts.map +1 -1
- package/dist/config/parser.js +9 -0
- package/dist/config/parser.js.map +1 -1
- package/dist/execution/context.d.ts +27 -3
- package/dist/execution/context.d.ts.map +1 -1
- package/dist/execution/context.js +52 -9
- package/dist/execution/context.js.map +1 -1
- package/dist/execution/executor.d.ts.map +1 -1
- package/dist/execution/executor.js +11 -12
- package/dist/execution/executor.js.map +1 -1
- package/dist/execution/nodes/entry-executor.d.ts.map +1 -1
- package/dist/execution/nodes/entry-executor.js +1 -2
- package/dist/execution/nodes/entry-executor.js.map +1 -1
- package/dist/execution/nodes/exit-executor.d.ts +1 -1
- package/dist/execution/nodes/exit-executor.d.ts.map +1 -1
- package/dist/execution/nodes/exit-executor.js +9 -7
- package/dist/execution/nodes/exit-executor.js.map +1 -1
- package/dist/execution/nodes/mcp-tool-executor.d.ts +1 -1
- package/dist/execution/nodes/mcp-tool-executor.d.ts.map +1 -1
- package/dist/execution/nodes/mcp-tool-executor.js +5 -4
- package/dist/execution/nodes/mcp-tool-executor.js.map +1 -1
- package/dist/execution/nodes/switch-executor.d.ts +1 -1
- package/dist/execution/nodes/switch-executor.d.ts.map +1 -1
- package/dist/execution/nodes/switch-executor.js +13 -8
- package/dist/execution/nodes/switch-executor.js.map +1 -1
- package/dist/execution/nodes/transform-executor.d.ts +1 -1
- package/dist/execution/nodes/transform-executor.d.ts.map +1 -1
- package/dist/execution/nodes/transform-executor.js +5 -4
- package/dist/execution/nodes/transform-executor.js.map +1 -1
- package/dist/expressions/json-logic.d.ts +11 -2
- package/dist/expressions/json-logic.d.ts.map +1 -1
- package/dist/expressions/json-logic.js +98 -16
- package/dist/expressions/json-logic.js.map +1 -1
- package/dist/expressions/jsonata-extensions.d.ts +10 -0
- package/dist/expressions/jsonata-extensions.d.ts.map +1 -0
- package/dist/expressions/jsonata-extensions.js +69 -0
- package/dist/expressions/jsonata-extensions.js.map +1 -0
- package/dist/expressions/jsonata.d.ts +8 -1
- package/dist/expressions/jsonata.d.ts.map +1 -1
- package/dist/expressions/jsonata.js +72 -12
- package/dist/expressions/jsonata.js.map +1 -1
- package/dist/types/execution.d.ts +1 -1
- package/dist/types/execution.d.ts.map +1 -1
- package/docs/design.md +5 -0
- package/docs/execution-context-redesign.md +284 -0
- package/docs/introspection-debugging.md +28 -1
- package/examples/api-usage.ts +54 -1
- package/examples/loop_example.yaml +84 -0
- package/package.json +1 -1
|
@@ -2,14 +2,16 @@
|
|
|
2
2
|
* Exit node executor
|
|
3
3
|
*/
|
|
4
4
|
import { logger } from "../../logger.js";
|
|
5
|
-
export function executeExitNode(node, context,
|
|
5
|
+
export function executeExitNode(node, context, startTime) {
|
|
6
6
|
logger.debug(`Executing exit node: ${node.id}`);
|
|
7
|
-
const
|
|
7
|
+
const history = context.getHistory();
|
|
8
|
+
const currentIndex = history.length; // This will be the index after we add this execution
|
|
8
9
|
let output;
|
|
9
|
-
if (
|
|
10
|
-
//
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
if (currentIndex > 0) {
|
|
11
|
+
// Get the previous node's output from history
|
|
12
|
+
const previousRecord = history[currentIndex - 1];
|
|
13
|
+
output = previousRecord.output || {};
|
|
14
|
+
logger.debug(`Exit node using output from previous node: ${previousRecord.nodeId}`);
|
|
13
15
|
}
|
|
14
16
|
else {
|
|
15
17
|
// No previous node (shouldn't happen in normal execution, but handle gracefully)
|
|
@@ -17,7 +19,7 @@ export function executeExitNode(node, context, previousNodeId, startTime) {
|
|
|
17
19
|
output = {};
|
|
18
20
|
}
|
|
19
21
|
const endTime = Date.now();
|
|
20
|
-
context.addHistory(node.id, "exit",
|
|
22
|
+
context.addHistory(node.id, "exit", output, startTime, endTime);
|
|
21
23
|
return {
|
|
22
24
|
output,
|
|
23
25
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exit-executor.js","sourceRoot":"","sources":["../../../src/execution/nodes/exit-executor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,MAAM,UAAU,eAAe,CAC7B,IAAc,EACd,OAAyB,EACzB,
|
|
1
|
+
{"version":3,"file":"exit-executor.js","sourceRoot":"","sources":["../../../src/execution/nodes/exit-executor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,MAAM,UAAU,eAAe,CAC7B,IAAc,EACd,OAAyB,EACzB,SAAiB;IAEjB,MAAM,CAAC,KAAK,CAAC,wBAAwB,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;IAEhD,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IACrC,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,qDAAqD;IAE1F,IAAI,MAAe,CAAC;IAEpB,IAAI,YAAY,GAAG,CAAC,EAAE,CAAC;QACrB,8CAA8C;QAC9C,MAAM,cAAc,GAAG,OAAO,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC;QACjD,MAAM,GAAG,cAAc,CAAC,MAAM,IAAI,EAAE,CAAC;QACrC,MAAM,CAAC,KAAK,CAAC,8CAA8C,cAAc,CAAC,MAAM,EAAE,CAAC,CAAC;IACtF,CAAC;SAAM,CAAC;QACN,iFAAiF;QACjF,MAAM,CAAC,IAAI,CAAC,aAAa,IAAI,CAAC,EAAE,+CAA+C,CAAC,CAAC;QACjF,MAAM,GAAG,EAAE,CAAC;IACd,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAE3B,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IAEhE,OAAO;QACL,MAAM;KACP,CAAC;AACJ,CAAC"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import type { McpNode, ServerConfig } from "../../types/config.js";
|
|
5
5
|
import type { ExecutionContext } from "../context.js";
|
|
6
6
|
import type { McpClientManager } from "../../mcp/client-manager.js";
|
|
7
|
-
export declare function executeMcpToolNode(node: McpNode, context: ExecutionContext, clientManager: McpClientManager, serverConfig: ServerConfig,
|
|
7
|
+
export declare function executeMcpToolNode(node: McpNode, context: ExecutionContext, clientManager: McpClientManager, serverConfig: ServerConfig, startTime: number): Promise<{
|
|
8
8
|
output: unknown;
|
|
9
9
|
nextNode: string;
|
|
10
10
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-tool-executor.d.ts","sourceRoot":"","sources":["../../../src/execution/nodes/mcp-tool-executor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAGpE,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,gBAAgB,EACzB,aAAa,EAAE,gBAAgB,EAC/B,YAAY,EAAE,YAAY,EAC1B,
|
|
1
|
+
{"version":3,"file":"mcp-tool-executor.d.ts","sourceRoot":"","sources":["../../../src/execution/nodes/mcp-tool-executor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAGpE,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,gBAAgB,EACzB,aAAa,EAAE,gBAAgB,EAC/B,YAAY,EAAE,YAAY,EAC1B,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAmEhD"}
|
|
@@ -3,15 +3,17 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { evaluateJsonata } from "../../expressions/jsonata.js";
|
|
5
5
|
import { logger } from "../../logger.js";
|
|
6
|
-
export async function executeMcpToolNode(node, context, clientManager, serverConfig,
|
|
6
|
+
export async function executeMcpToolNode(node, context, clientManager, serverConfig, startTime) {
|
|
7
7
|
logger.debug(`Executing MCP tool node: ${node.id} (${node.server}.${node.tool})`);
|
|
8
8
|
const exprContext = context.getData();
|
|
9
|
+
const history = context.getHistory();
|
|
10
|
+
const currentIndex = history.length; // This will be the index after we add this execution
|
|
9
11
|
// Pre-transform: Apply JSONata to format tool arguments
|
|
10
12
|
const transformedArgs = {};
|
|
11
13
|
for (const [key, value] of Object.entries(node.args)) {
|
|
12
14
|
if (typeof value === "string" && value.startsWith("$")) {
|
|
13
15
|
// JSONata expression
|
|
14
|
-
const evaluated = await evaluateJsonata(value, exprContext,
|
|
16
|
+
const evaluated = await evaluateJsonata(value, exprContext, history, currentIndex);
|
|
15
17
|
transformedArgs[key] = evaluated;
|
|
16
18
|
logger.debug(`JSONata "${value}" evaluated to: ${JSON.stringify(evaluated)}`);
|
|
17
19
|
}
|
|
@@ -55,8 +57,7 @@ export async function executeMcpToolNode(node, context, clientManager, serverCon
|
|
|
55
57
|
logger.debug(`MCP tool output: ${JSON.stringify(toolOutput, null, 2)}`);
|
|
56
58
|
const output = toolOutput;
|
|
57
59
|
const endTime = Date.now();
|
|
58
|
-
context.
|
|
59
|
-
context.addHistory(node.id, "mcp", transformedArgs, output, startTime, endTime);
|
|
60
|
+
context.addHistory(node.id, "mcp", output, startTime, endTime);
|
|
60
61
|
return {
|
|
61
62
|
output,
|
|
62
63
|
nextNode: node.next,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-tool-executor.js","sourceRoot":"","sources":["../../../src/execution/nodes/mcp-tool-executor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAE/D,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,IAAa,EACb,OAAyB,EACzB,aAA+B,EAC/B,YAA0B,EAC1B,
|
|
1
|
+
{"version":3,"file":"mcp-tool-executor.js","sourceRoot":"","sources":["../../../src/execution/nodes/mcp-tool-executor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAE/D,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,IAAa,EACb,OAAyB,EACzB,aAA+B,EAC/B,YAA0B,EAC1B,SAAiB;IAEjB,MAAM,CAAC,KAAK,CAAC,4BAA4B,IAAI,CAAC,EAAE,KAAK,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;IAElF,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IACtC,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IACrC,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,qDAAqD;IAE1F,wDAAwD;IACxD,MAAM,eAAe,GAA4B,EAAE,CAAC;IACpD,KAAK,MAAM,CA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C;IAC5E,CAAC;IAED,yBAAyB;IACzB,MAAM,OAAO,GAAG,MAAM,CAAC,OAA6C,CAAC;IACrE,IAAI,UAAmB,CAAC;IAExB,IAAI,OAAO,CAAC,CAAC,CAAC,IAAI,OAAO,OAAO,CAAC,CAAC,CAAC,KAAK,QAAQ,IAAI,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;QACzE,MAAM,WAAW,GAAI,OAAO,CAAC,CAAC,CAAuB,CAAC,IAAI,CAAC;QAC3D,IAAI,WAAW,EAAE,CAAC;YAChB,IAAI,CAAC;gBACH,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;YACvC,CAAC;YAAC,MAAM,CAAC;gBACP,UAAU,GAAG,WAAW,CAAC;YAC3B,CAAC;QACH,CAAC;aAAM,CAAC;YACN,UAAU,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;SAAM,CAAC;QACN,UAAU,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAC1B,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,oBAAoB,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;IAExE,MAAM,MAAM,GAAG,UAAU,CAAC;IAC1B,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAE3B,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IAE/D,OAAO;QACL,MAAM;QACN,QAAQ,EAAE,IAAI,CAAC,IAAI;KACpB,CAAC;AACJ,CAAC"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import type { SwitchNode } from "../../types/config.js";
|
|
5
5
|
import type { ExecutionContext } from "../context.js";
|
|
6
|
-
export declare function executeSwitchNode(node: SwitchNode, context: ExecutionContext,
|
|
6
|
+
export declare function executeSwitchNode(node: SwitchNode, context: ExecutionContext, startTime: number): Promise<{
|
|
7
7
|
output: unknown;
|
|
8
8
|
nextNode: string;
|
|
9
9
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"switch-executor.d.ts","sourceRoot":"","sources":["../../../src/execution/nodes/switch-executor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAItD,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE,gBAAgB,EACzB,
|
|
1
|
+
{"version":3,"file":"switch-executor.d.ts","sourceRoot":"","sources":["../../../src/execution/nodes/switch-executor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAItD,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE,gBAAgB,EACzB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CA0ChD"}
|
|
@@ -3,35 +3,40 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { evaluateJsonLogic } from "../../expressions/json-logic.js";
|
|
5
5
|
import { logger } from "../../logger.js";
|
|
6
|
-
export async function executeSwitchNode(node, context,
|
|
6
|
+
export async function executeSwitchNode(node, context, startTime) {
|
|
7
7
|
logger.debug(`Executing switch node: ${node.id}`);
|
|
8
8
|
const exprContext = context.getData();
|
|
9
|
+
const history = context.getHistory();
|
|
10
|
+
const currentIndex = history.length; // This will be the index after we add this execution
|
|
9
11
|
const endTime = Date.now();
|
|
10
12
|
// Evaluate conditions in order
|
|
11
|
-
for (
|
|
13
|
+
for (let i = 0; i < node.conditions.length; i++) {
|
|
14
|
+
const condition = node.conditions[i];
|
|
12
15
|
// If no rule is specified, this is a default/fallback case
|
|
13
16
|
if (condition.rule === undefined || condition.rule === null) {
|
|
14
17
|
logger.debug(`Switch node ${node.id}: Using default/fallback target: ${condition.target}`);
|
|
15
|
-
|
|
18
|
+
const output = condition.target; // Output the target node ID
|
|
19
|
+
context.addHistory(node.id, "switch", output, startTime, endTime);
|
|
16
20
|
return {
|
|
17
|
-
output
|
|
21
|
+
output,
|
|
18
22
|
nextNode: condition.target,
|
|
19
23
|
};
|
|
20
24
|
}
|
|
21
25
|
// Evaluate the JSON Logic rule (now uses JSONata for var operations)
|
|
22
|
-
const ruleResult = await evaluateJsonLogic(condition.rule, exprContext,
|
|
26
|
+
const ruleResult = await evaluateJsonLogic(condition.rule, exprContext, history, currentIndex);
|
|
23
27
|
if (ruleResult) {
|
|
24
28
|
logger.debug(`Switch node ${node.id}: Condition matched, routing to: ${condition.target}`);
|
|
25
|
-
|
|
29
|
+
const output = condition.target; // Output the target node ID
|
|
30
|
+
context.addHistory(node.id, "switch", output, startTime, endTime);
|
|
26
31
|
return {
|
|
27
|
-
output
|
|
32
|
+
output,
|
|
28
33
|
nextNode: condition.target,
|
|
29
34
|
};
|
|
30
35
|
}
|
|
31
36
|
}
|
|
32
37
|
// No conditions matched and no default case
|
|
33
38
|
const error = new Error(`Switch node ${node.id}: No conditions matched and no default case provided`);
|
|
34
|
-
context.addHistory(node.id, "switch",
|
|
39
|
+
context.addHistory(node.id, "switch", null, startTime, endTime, error);
|
|
35
40
|
throw error;
|
|
36
41
|
}
|
|
37
42
|
//# sourceMappingURL=switch-executor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"switch-executor.js","sourceRoot":"","sources":["../../../src/execution/nodes/switch-executor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,iBAAiB,EAAE,MAAM,i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C,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;YAClE,OAAO;gBACL,MAAM;gBACN,QAAQ,EAAE,SAAS,CAAC,MAAM;aAC3B,CAAC;QACJ,CAAC;QAED,qEAAqE;QACrE,MAAM,UAAU,GAAG,MAAM,iBAAiB,CAAC,SAAS,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;QAE/F,IAAI,UAAU,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,eAAe,IAAI,CAAC,EAAE,oCAAoC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;YAC3F,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,4BAA4B;YAC7D,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;YAClE,OAAO;gBACL,MAAM;gBACN,QAAQ,EAAE,SAAS,CAAC,MAAM;aAC3B,CAAC;QACJ,CAAC;IACH,CAAC;IAED,4CAA4C;IAC5C,MAAM,KAAK,GAAG,IAAI,KAAK,CACrB,eAAe,IAAI,CAAC,EAAE,sDAAsD,CAC7E,CAAC;IACF,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;IACvE,MAAM,KAAK,CAAC;AACd,CAAC"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import type { TransformNode } from "../../types/config.js";
|
|
5
5
|
import type { ExecutionContext } from "../context.js";
|
|
6
|
-
export declare function executeTransformNode(node: TransformNode, context: ExecutionContext,
|
|
6
|
+
export declare function executeTransformNode(node: TransformNode, context: ExecutionContext, startTime: number): Promise<{
|
|
7
7
|
output: unknown;
|
|
8
8
|
nextNode: string;
|
|
9
9
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform-executor.d.ts","sourceRoot":"","sources":["../../../src/execution/nodes/transform-executor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAItD,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,aAAa,EACnB,OAAO,EAAE,gBAAgB,EACzB,
|
|
1
|
+
{"version":3,"file":"transform-executor.d.ts","sourceRoot":"","sources":["../../../src/execution/nodes/transform-executor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAItD,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,aAAa,EACnB,OAAO,EAAE,gBAAgB,EACzB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAqBhD"}
|
|
@@ -3,16 +3,17 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { evaluateJsonata } from "../../expressions/jsonata.js";
|
|
5
5
|
import { logger } from "../../logger.js";
|
|
6
|
-
export async function executeTransformNode(node, context,
|
|
6
|
+
export async function executeTransformNode(node, context, startTime) {
|
|
7
7
|
logger.debug(`Executing transform node: ${node.id}`);
|
|
8
8
|
logger.debug(`Transform expression: ${node.transform.expr}`);
|
|
9
9
|
const exprContext = context.getData();
|
|
10
10
|
logger.debug(`Transform context: ${JSON.stringify(exprContext, null, 2)}`);
|
|
11
|
-
const
|
|
11
|
+
const history = context.getHistory();
|
|
12
|
+
const currentIndex = history.length; // This will be the index after we add this execution
|
|
13
|
+
const output = await evaluateJsonata(node.transform.expr, exprContext, history, currentIndex);
|
|
12
14
|
const endTime = Date.now();
|
|
13
15
|
logger.debug(`Transform output: ${JSON.stringify(output, null, 2)}`);
|
|
14
|
-
context.
|
|
15
|
-
context.addHistory(node.id, "transform", exprContext, output, startTime, endTime);
|
|
16
|
+
context.addHistory(node.id, "transform", output, startTime, endTime);
|
|
16
17
|
return {
|
|
17
18
|
output,
|
|
18
19
|
nextNode: node.next,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform-executor.js","sourceRoot":"","sources":["../../../src/execution/nodes/transform-executor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,IAAmB,EACnB,OAAyB,EACzB,
|
|
1
|
+
{"version":3,"file":"transform-executor.js","sourceRoot":"","sources":["../../../src/execution/nodes/transform-executor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,IAAmB,EACnB,OAAyB,EACzB,SAAiB;IAEjB,MAAM,CAAC,KAAK,CAAC,6BAA6B,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;IACrD,MAAM,CAAC,KAAK,CAAC,yBAAyB,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC;IAE7D,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IACtC,MAAM,CAAC,KAAK,CAAC,sBAAsB,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;IAE3E,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IACrC,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,qDAAqD;IAE1F,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;IAC9F,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAE3B,MAAM,CAAC,KAAK,CAAC,qBAAqB,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;IAErE,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IAErE,OAAO;QACL,MAAM;QACN,QAAQ,EAAE,IAAI,CAAC,IAAI;KACpB,CAAC;AACJ,CAAC"}
|
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* JSON Logic expression evaluation
|
|
3
3
|
*/
|
|
4
|
+
import type { NodeExecutionRecord } from "../types/execution.js";
|
|
4
5
|
/**
|
|
5
6
|
* Evaluate a JSON Logic rule with the given context data
|
|
6
7
|
* @param rule - JSON Logic rule (can be any valid JSON Logic structure)
|
|
7
8
|
* @param context - Context data object to evaluate the rule against
|
|
8
|
-
* @param
|
|
9
|
+
* @param history - Execution history for history functions
|
|
10
|
+
* @param currentIndex - Current execution index for history functions
|
|
9
11
|
* @returns Boolean result of the rule evaluation
|
|
10
12
|
*/
|
|
11
|
-
export declare function evaluateJsonLogic(rule: unknown, context: Record<string, unknown>,
|
|
13
|
+
export declare function evaluateJsonLogic(rule: unknown, context: Record<string, unknown>, history: NodeExecutionRecord[], currentIndex: number): Promise<boolean>;
|
|
14
|
+
/**
|
|
15
|
+
* Validate JSON Logic rule syntax without evaluating it
|
|
16
|
+
* Validates rule structure and any JSONata expressions in var operations
|
|
17
|
+
* @param rule - JSON Logic rule to validate
|
|
18
|
+
* @throws Error if syntax is invalid
|
|
19
|
+
*/
|
|
20
|
+
export declare function validateJsonLogicSyntax(rule: unknown): void;
|
|
12
21
|
//# sourceMappingURL=json-logic.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-logic.d.ts","sourceRoot":"","sources":["../../src/expressions/json-logic.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"json-logic.d.ts","sourceRoot":"","sources":["../../src/expressions/json-logic.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAIjE;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,OAAO,EAAE,mBAAmB,EAAE,EAC9B,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,OAAO,CAAC,CA2ClB;AAkDD;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAS3D"}
|
|
@@ -5,19 +5,22 @@
|
|
|
5
5
|
import jsonLogic from "json-logic-js";
|
|
6
6
|
import jsonata from "jsonata";
|
|
7
7
|
import { logger } from "../logger.js";
|
|
8
|
+
import { registerHistoryFunctions } from "./jsonata-extensions.js";
|
|
9
|
+
import { validateJsonataSyntax } from "./jsonata.js";
|
|
8
10
|
/**
|
|
9
11
|
* Evaluate a JSON Logic rule with the given context data
|
|
10
12
|
* @param rule - JSON Logic rule (can be any valid JSON Logic structure)
|
|
11
13
|
* @param context - Context data object to evaluate the rule against
|
|
12
|
-
* @param
|
|
14
|
+
* @param history - Execution history for history functions
|
|
15
|
+
* @param currentIndex - Current execution index for history functions
|
|
13
16
|
* @returns Boolean result of the rule evaluation
|
|
14
17
|
*/
|
|
15
|
-
export async function evaluateJsonLogic(rule, context,
|
|
18
|
+
export async function evaluateJsonLogic(rule, context, history, currentIndex) {
|
|
16
19
|
try {
|
|
17
20
|
logger.debug(`Evaluating JSON Logic rule: ${JSON.stringify(rule)}`);
|
|
18
21
|
logger.debug(`Context keys: ${Object.keys(context).join(", ")}`);
|
|
19
22
|
// Pre-process the rule: replace all var operations with their JSONata-evaluated values
|
|
20
|
-
const processedRule = await preprocessJsonLogicRule(rule, context,
|
|
23
|
+
const processedRule = await preprocessJsonLogicRule(rule, context, history, currentIndex);
|
|
21
24
|
// Now apply the processed rule (all var operations have been replaced with values)
|
|
22
25
|
const result = jsonLogic.apply(processedRule, context);
|
|
23
26
|
logger.debug(`JSON Logic result: ${result}`);
|
|
@@ -25,28 +28,47 @@ export async function evaluateJsonLogic(rule, context, previousNodeId) {
|
|
|
25
28
|
return Boolean(result);
|
|
26
29
|
}
|
|
27
30
|
catch (error) {
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
// Extract detailed error message
|
|
32
|
+
let errorMessage;
|
|
33
|
+
if (error instanceof Error) {
|
|
34
|
+
errorMessage = error.message || error.toString();
|
|
35
|
+
if (errorMessage === '[object Object]' || !errorMessage) {
|
|
36
|
+
errorMessage = error.toString();
|
|
37
|
+
if (error.stack) {
|
|
38
|
+
errorMessage = error.stack.split('\n')[0] || errorMessage;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else if (error && typeof error === 'object') {
|
|
43
|
+
const errorObj = error;
|
|
44
|
+
if (errorObj.message && typeof errorObj.message === 'string') {
|
|
45
|
+
errorMessage = errorObj.message;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
errorMessage = JSON.stringify(error, null, 2);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
errorMessage = String(error);
|
|
53
|
+
}
|
|
54
|
+
logger.error(`JSON Logic evaluation error: ${errorMessage}`);
|
|
55
|
+
logger.error(`Rule: ${JSON.stringify(rule, null, 2)}`);
|
|
56
|
+
logger.error(`Context keys: ${Object.keys(context).join(', ')}`);
|
|
57
|
+
throw new Error(`JSON Logic evaluation failed: ${errorMessage}\nRule: ${JSON.stringify(rule, null, 2)}`);
|
|
30
58
|
}
|
|
31
59
|
}
|
|
32
60
|
/**
|
|
33
61
|
* Recursively pre-process JSON Logic rule, replacing var operations with JSONata-evaluated values
|
|
34
62
|
*/
|
|
35
|
-
async function preprocessJsonLogicRule(rule, context,
|
|
63
|
+
async function preprocessJsonLogicRule(rule, context, history, currentIndex) {
|
|
36
64
|
// If rule is a var operation, evaluate it with JSONata and return the value
|
|
37
65
|
if (typeof rule === "object" && rule !== null && "var" in rule && Object.keys(rule).length === 1) {
|
|
38
66
|
const path = rule.var;
|
|
39
67
|
logger.debug(`Evaluating var operation: "${path}" as JSONata expression`);
|
|
40
68
|
try {
|
|
41
69
|
const expr = jsonata(path);
|
|
42
|
-
// Register
|
|
43
|
-
|
|
44
|
-
expr.registerFunction("previousNode", () => {
|
|
45
|
-
const previousOutput = context[previousNodeId];
|
|
46
|
-
logger.debug(`$previousNode() returning output from node: ${previousNodeId}`);
|
|
47
|
-
return previousOutput !== undefined ? previousOutput : null;
|
|
48
|
-
}, "<:o>");
|
|
49
|
-
}
|
|
70
|
+
// Register history access functions
|
|
71
|
+
registerHistoryFunctions(expr, history, currentIndex);
|
|
50
72
|
const result = await expr.evaluate(context);
|
|
51
73
|
logger.debug(`JSONata evaluation result: ${JSON.stringify(result)}`);
|
|
52
74
|
return result;
|
|
@@ -58,17 +80,77 @@ async function preprocessJsonLogicRule(rule, context, previousNodeId) {
|
|
|
58
80
|
}
|
|
59
81
|
// If rule is an array, recursively process each element
|
|
60
82
|
if (Array.isArray(rule)) {
|
|
61
|
-
return Promise.all(rule.map(item => preprocessJsonLogicRule(item, context,
|
|
83
|
+
return Promise.all(rule.map(item => preprocessJsonLogicRule(item, context, history, currentIndex)));
|
|
62
84
|
}
|
|
63
85
|
// If rule is an object, recursively process each property
|
|
64
86
|
if (typeof rule === "object" && rule !== null) {
|
|
65
87
|
const result = {};
|
|
66
88
|
for (const [key, value] of Object.entries(rule)) {
|
|
67
|
-
result[key] = await preprocessJsonLogicRule(value, context,
|
|
89
|
+
result[key] = await preprocessJsonLogicRule(value, context, history, currentIndex);
|
|
68
90
|
}
|
|
69
91
|
return result;
|
|
70
92
|
}
|
|
71
93
|
// Primitive value, return as-is
|
|
72
94
|
return rule;
|
|
73
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Validate JSON Logic rule syntax without evaluating it
|
|
98
|
+
* Validates rule structure and any JSONata expressions in var operations
|
|
99
|
+
* @param rule - JSON Logic rule to validate
|
|
100
|
+
* @throws Error if syntax is invalid
|
|
101
|
+
*/
|
|
102
|
+
export function validateJsonLogicSyntax(rule) {
|
|
103
|
+
try {
|
|
104
|
+
validateJsonLogicRuleRecursive(rule);
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
if (error instanceof Error) {
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
throw new Error(`Invalid JSON Logic syntax: ${String(error)}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Recursively validate JSON Logic rule structure and JSONata in var operations
|
|
115
|
+
*/
|
|
116
|
+
function validateJsonLogicRuleRecursive(rule) {
|
|
117
|
+
// If rule is a var operation, validate the JSONata expression
|
|
118
|
+
if (typeof rule === "object" && rule !== null && "var" in rule && Object.keys(rule).length === 1) {
|
|
119
|
+
const path = rule.var;
|
|
120
|
+
if (typeof path !== "string") {
|
|
121
|
+
throw new Error(`JSON Logic var operation must have a string value, got ${typeof path}`);
|
|
122
|
+
}
|
|
123
|
+
// If the var value looks like a JSONata expression (starts with $), validate it
|
|
124
|
+
if (path.startsWith("$")) {
|
|
125
|
+
try {
|
|
126
|
+
validateJsonataSyntax(path);
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
if (error instanceof Error) {
|
|
130
|
+
throw new Error(`Invalid JSONata in JSON Logic var operation "${path}": ${error.message}`);
|
|
131
|
+
}
|
|
132
|
+
throw error;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// If it's not a JSONata expression, it's just a path reference (valid)
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
// If rule is an array, recursively validate each element
|
|
139
|
+
if (Array.isArray(rule)) {
|
|
140
|
+
for (const item of rule) {
|
|
141
|
+
validateJsonLogicRuleRecursive(item);
|
|
142
|
+
}
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
// If rule is an object, recursively validate each property
|
|
146
|
+
if (typeof rule === "object" && rule !== null) {
|
|
147
|
+
for (const value of Object.values(rule)) {
|
|
148
|
+
validateJsonLogicRuleRecursive(value);
|
|
149
|
+
}
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
// Primitive values are valid
|
|
153
|
+
// Note: We can't fully validate JSON Logic operators without context,
|
|
154
|
+
// but we've validated the structure and any JSONata expressions
|
|
155
|
+
}
|
|
74
156
|
//# sourceMappingURL=json-logic.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-logic.js","sourceRoot":"","sources":["../../src/expressions/json-logic.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,2DAA2D;AAC3D,OAAO,SAAS,MAAM,eAAe,CAAC;AACtC,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC
|
|
1
|
+
{"version":3,"file":"json-logic.js","sourceRoot":"","sources":["../../src/expressions/json-logic.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,2DAA2D;AAC3D,OAAO,SAAS,MAAM,eAAe,CAAC;AACtC,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAErD;;;;;;;GAOG;AACH,MAAM,CAAC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AAC;YACxB,8BAA8B,CAAC,IAAI,CAAC,CAAC;QACvC,CAAC;QACD,OAAO;IACT,CAAC;IAED,2DAA2D;IAC3D,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAC9C,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YACxC,8BAA8B,CAAC,KAAK,CAAC,CAAC;QACxC,CAAC;QACD,OAAO;IACT,CAAC;IAED,6BAA6B;IAC7B,sEAAsE;IACtE,gEAAgE;AAClE,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSONata extensions for execution history access
|
|
3
|
+
*/
|
|
4
|
+
import jsonata from "jsonata";
|
|
5
|
+
import type { NodeExecutionRecord } from "../types/execution.js";
|
|
6
|
+
/**
|
|
7
|
+
* Register custom JSONata functions for history access
|
|
8
|
+
*/
|
|
9
|
+
export declare function registerHistoryFunctions(expr: jsonata.Expression, history: NodeExecutionRecord[], currentIndex: number): void;
|
|
10
|
+
//# sourceMappingURL=jsonata-extensions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonata-extensions.d.ts","sourceRoot":"","sources":["../../src/expressions/jsonata-extensions.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAEjE;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,OAAO,CAAC,UAAU,EACxB,OAAO,EAAE,mBAAmB,EAAE,EAC9B,YAAY,EAAE,MAAM,GACnB,IAAI,CAiFN"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSONata extensions for execution history access
|
|
3
|
+
*/
|
|
4
|
+
import { logger } from "../logger.js";
|
|
5
|
+
/**
|
|
6
|
+
* Register custom JSONata functions for history access
|
|
7
|
+
*/
|
|
8
|
+
export function registerHistoryFunctions(expr, history, currentIndex) {
|
|
9
|
+
// $previousNode() - returns previous node's output
|
|
10
|
+
// $previousNode(index) - returns node that executed N steps before current
|
|
11
|
+
expr.registerFunction("previousNode", (offset) => {
|
|
12
|
+
const stepsBack = offset !== undefined ? offset : 1;
|
|
13
|
+
const targetIndex = currentIndex - stepsBack;
|
|
14
|
+
if (targetIndex < 0 || targetIndex >= history.length) {
|
|
15
|
+
logger.debug(`$previousNode(${stepsBack}): No node at index ${targetIndex}`);
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const record = history[targetIndex];
|
|
19
|
+
logger.debug(`$previousNode(${stepsBack}) returning output from node: ${record.nodeId} (index ${targetIndex})`);
|
|
20
|
+
return record.output;
|
|
21
|
+
}, "<n?:o>" // Optional number argument, returns object
|
|
22
|
+
);
|
|
23
|
+
// $executionCount(nodeName) - count of executions for a node
|
|
24
|
+
expr.registerFunction("executionCount", (nodeName) => {
|
|
25
|
+
if (typeof nodeName !== "string") {
|
|
26
|
+
return 0;
|
|
27
|
+
}
|
|
28
|
+
const count = history.filter(r => r.nodeId === nodeName).length;
|
|
29
|
+
logger.debug(`$executionCount("${nodeName}") = ${count}`);
|
|
30
|
+
return count;
|
|
31
|
+
}, "<s:n>" // String argument, returns number
|
|
32
|
+
);
|
|
33
|
+
// $nodeExecution(nodeName, index) - specific execution by index (0 = first, -1 = last)
|
|
34
|
+
expr.registerFunction("nodeExecution", (nodeName, index) => {
|
|
35
|
+
if (typeof nodeName !== "string" || typeof index !== "number") {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
const executions = history.filter(r => r.nodeId === nodeName);
|
|
39
|
+
if (executions.length === 0) {
|
|
40
|
+
logger.debug(`$nodeExecution("${nodeName}", ${index}): No executions found`);
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
// Handle negative indices (from end)
|
|
44
|
+
let actualIndex = index;
|
|
45
|
+
if (index < 0) {
|
|
46
|
+
actualIndex = executions.length + index;
|
|
47
|
+
}
|
|
48
|
+
if (actualIndex < 0 || actualIndex >= executions.length) {
|
|
49
|
+
logger.debug(`$nodeExecution("${nodeName}", ${index}): Index ${actualIndex} out of range`);
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
const record = executions[actualIndex];
|
|
53
|
+
logger.debug(`$nodeExecution("${nodeName}", ${index}) = execution at index ${actualIndex}`);
|
|
54
|
+
return record.output;
|
|
55
|
+
}, "<s-n:o>" // String and number arguments, returns object
|
|
56
|
+
);
|
|
57
|
+
// $nodeExecutions(nodeName) - array of all executions for a node
|
|
58
|
+
expr.registerFunction("nodeExecutions", (nodeName) => {
|
|
59
|
+
if (typeof nodeName !== "string") {
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
const executions = history.filter(r => r.nodeId === nodeName);
|
|
63
|
+
const outputs = executions.map(r => r.output);
|
|
64
|
+
logger.debug(`$nodeExecutions("${nodeName}") = ${executions.length} executions`);
|
|
65
|
+
return outputs;
|
|
66
|
+
}, "<s:a>" // String argument, returns array
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=jsonata-extensions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonata-extensions.js","sourceRoot":"","sources":["../../src/expressions/jsonata-extensions.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGtC;;GAEG;AACH,MAAM,UAAU,wBAAwB,CACtC,IAAwB,EACxB,OAA8B,EAC9B,YAAoB;IAEpB,mDAAmD;IACnD,2EAA2E;IAC3E,IAAI,CAAC,gBAAgB,CACnB,cAAc,EACd,CAAC,MAAe,EAAE,EAAE;QAClB,MAAM,SAAS,GAAG,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;QACpD,MAAM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,MAAM,aAAa,CAAC,CAAC;QACjF,OAAO,OAAO,CAAC;IACjB,CAAC,EACD,OAAO,CAAC,iCAAiC;KAC1C,CAAC;AACJ,CAAC"}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* JSONata expression evaluation
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
import type { NodeExecutionRecord } from "../types/execution.js";
|
|
5
|
+
/**
|
|
6
|
+
* Validate JSONata expression syntax without evaluating it
|
|
7
|
+
* @param expression - JSONata expression string to validate
|
|
8
|
+
* @throws Error if syntax is invalid
|
|
9
|
+
*/
|
|
10
|
+
export declare function validateJsonataSyntax(expression: string): void;
|
|
11
|
+
export declare function evaluateJsonata(expression: string, context: Record<string, unknown>, history: NodeExecutionRecord[], currentIndex: number): Promise<unknown>;
|
|
5
12
|
//# sourceMappingURL=jsonata.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonata.d.ts","sourceRoot":"","sources":["../../src/expressions/jsonata.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"jsonata.d.ts","sourceRoot":"","sources":["../../src/expressions/jsonata.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAGjE;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CA2B9D;AAED,wBAAsB,eAAe,CACnC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,OAAO,EAAE,mBAAmB,EAAE,EAC9B,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,OAAO,CAAC,CAqDlB"}
|