ts-workflow-engine-lite 2.1.0
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/LICENSE +21 -0
- package/README.md +352 -0
- package/dist/src/api/ConsoleWebSocketManager.d.ts +57 -0
- package/dist/src/api/ConsoleWebSocketManager.js +206 -0
- package/dist/src/api/ConsoleWebSocketManager.js.map +1 -0
- package/dist/src/api/ErrorHandler.d.ts +52 -0
- package/dist/src/api/ErrorHandler.js +115 -0
- package/dist/src/api/ErrorHandler.js.map +1 -0
- package/dist/src/api/EventHistory.d.ts +73 -0
- package/dist/src/api/EventHistory.js +309 -0
- package/dist/src/api/EventHistory.js.map +1 -0
- package/dist/src/api/WebhookManager.d.ts +67 -0
- package/dist/src/api/WebhookManager.js +568 -0
- package/dist/src/api/WebhookManager.js.map +1 -0
- package/dist/src/api/docsPage.d.ts +1 -0
- package/dist/src/api/docsPage.js +321 -0
- package/dist/src/api/docsPage.js.map +1 -0
- package/dist/src/api/index.d.ts +8 -0
- package/dist/src/api/index.js +8 -0
- package/dist/src/api/index.js.map +1 -0
- package/dist/src/api/middleware/auth.d.ts +19 -0
- package/dist/src/api/middleware/auth.js +122 -0
- package/dist/src/api/middleware/auth.js.map +1 -0
- package/dist/src/api/middleware/index.d.ts +3 -0
- package/dist/src/api/middleware/index.js +3 -0
- package/dist/src/api/middleware/index.js.map +1 -0
- package/dist/src/api/middleware/rateLimit.d.ts +6 -0
- package/dist/src/api/middleware/rateLimit.js +69 -0
- package/dist/src/api/middleware/rateLimit.js.map +1 -0
- package/dist/src/api/middleware/rateLimitStore.d.ts +14 -0
- package/dist/src/api/middleware/rateLimitStore.js +44 -0
- package/dist/src/api/middleware/rateLimitStore.js.map +1 -0
- package/dist/src/api/middleware/rbac.d.ts +12 -0
- package/dist/src/api/middleware/rbac.js +120 -0
- package/dist/src/api/middleware/rbac.js.map +1 -0
- package/dist/src/api/openapi.d.ts +1917 -0
- package/dist/src/api/openapi.js +1758 -0
- package/dist/src/api/openapi.js.map +1 -0
- package/dist/src/api/playgroundPage.d.ts +1 -0
- package/dist/src/api/playgroundPage.js +765 -0
- package/dist/src/api/playgroundPage.js.map +1 -0
- package/dist/src/api/response.d.ts +22 -0
- package/dist/src/api/response.js +119 -0
- package/dist/src/api/response.js.map +1 -0
- package/dist/src/api/router.d.ts +17 -0
- package/dist/src/api/router.js +94 -0
- package/dist/src/api/router.js.map +1 -0
- package/dist/src/api/routes/analytics.d.ts +10 -0
- package/dist/src/api/routes/analytics.js +144 -0
- package/dist/src/api/routes/analytics.js.map +1 -0
- package/dist/src/api/routes/dlq.d.ts +3 -0
- package/dist/src/api/routes/dlq.js +248 -0
- package/dist/src/api/routes/dlq.js.map +1 -0
- package/dist/src/api/routes/eventHistory.d.ts +3 -0
- package/dist/src/api/routes/eventHistory.js +48 -0
- package/dist/src/api/routes/eventHistory.js.map +1 -0
- package/dist/src/api/routes/events.d.ts +3 -0
- package/dist/src/api/routes/events.js +205 -0
- package/dist/src/api/routes/events.js.map +1 -0
- package/dist/src/api/routes/functions.d.ts +3 -0
- package/dist/src/api/routes/functions.js +85 -0
- package/dist/src/api/routes/functions.js.map +1 -0
- package/dist/src/api/routes/instances.d.ts +3 -0
- package/dist/src/api/routes/instances.js +790 -0
- package/dist/src/api/routes/instances.js.map +1 -0
- package/dist/src/api/routes/templates.d.ts +3 -0
- package/dist/src/api/routes/templates.js +195 -0
- package/dist/src/api/routes/templates.js.map +1 -0
- package/dist/src/api/routes/webhooks.d.ts +3 -0
- package/dist/src/api/routes/webhooks.js +263 -0
- package/dist/src/api/routes/webhooks.js.map +1 -0
- package/dist/src/api/routes/workflows/analysis.d.ts +2 -0
- package/dist/src/api/routes/workflows/analysis.js +112 -0
- package/dist/src/api/routes/workflows/analysis.js.map +1 -0
- package/dist/src/api/routes/workflows/crud.d.ts +2 -0
- package/dist/src/api/routes/workflows/crud.js +140 -0
- package/dist/src/api/routes/workflows/crud.js.map +1 -0
- package/dist/src/api/routes/workflows/execution.d.ts +2 -0
- package/dist/src/api/routes/workflows/execution.js +204 -0
- package/dist/src/api/routes/workflows/execution.js.map +1 -0
- package/dist/src/api/routes/workflows/graph.d.ts +2 -0
- package/dist/src/api/routes/workflows/graph.js +51 -0
- package/dist/src/api/routes/workflows/graph.js.map +1 -0
- package/dist/src/api/routes/workflows/import.d.ts +2 -0
- package/dist/src/api/routes/workflows/import.js +238 -0
- package/dist/src/api/routes/workflows/import.js.map +1 -0
- package/dist/src/api/routes/workflows/index.d.ts +3 -0
- package/dist/src/api/routes/workflows/index.js +18 -0
- package/dist/src/api/routes/workflows/index.js.map +1 -0
- package/dist/src/api/routes/workflows/shared.d.ts +64 -0
- package/dist/src/api/routes/workflows/shared.js +304 -0
- package/dist/src/api/routes/workflows/shared.js.map +1 -0
- package/dist/src/api/routes/workflows/variables.d.ts +2 -0
- package/dist/src/api/routes/workflows/variables.js +34 -0
- package/dist/src/api/routes/workflows/variables.js.map +1 -0
- package/dist/src/api/routes/workflows/versioning.d.ts +2 -0
- package/dist/src/api/routes/workflows/versioning.js +235 -0
- package/dist/src/api/routes/workflows/versioning.js.map +1 -0
- package/dist/src/api/server.d.ts +13 -0
- package/dist/src/api/server.js +311 -0
- package/dist/src/api/server.js.map +1 -0
- package/dist/src/api/services/InstanceApplicationService.d.ts +74 -0
- package/dist/src/api/services/InstanceApplicationService.js +215 -0
- package/dist/src/api/services/InstanceApplicationService.js.map +1 -0
- package/dist/src/api/services/WorkflowApplicationService.d.ts +92 -0
- package/dist/src/api/services/WorkflowApplicationService.js +282 -0
- package/dist/src/api/services/WorkflowApplicationService.js.map +1 -0
- package/dist/src/api/services/index.d.ts +4 -0
- package/dist/src/api/services/index.js +3 -0
- package/dist/src/api/services/index.js.map +1 -0
- package/dist/src/api/types.d.ts +118 -0
- package/dist/src/api/types.js +2 -0
- package/dist/src/api/types.js.map +1 -0
- package/dist/src/api/utils/IdempotencyStore.d.ts +36 -0
- package/dist/src/api/utils/IdempotencyStore.js +121 -0
- package/dist/src/api/utils/IdempotencyStore.js.map +1 -0
- package/dist/src/api/utils/authConfig.d.ts +2 -0
- package/dist/src/api/utils/authConfig.js +25 -0
- package/dist/src/api/utils/authConfig.js.map +1 -0
- package/dist/src/api/utils/requestContext.d.ts +14 -0
- package/dist/src/api/utils/requestContext.js +31 -0
- package/dist/src/api/utils/requestContext.js.map +1 -0
- package/dist/src/api/utils/routeHelper.d.ts +25 -0
- package/dist/src/api/utils/routeHelper.js +30 -0
- package/dist/src/api/utils/routeHelper.js.map +1 -0
- package/dist/src/api/welcomePage.d.ts +1 -0
- package/dist/src/api/welcomePage.js +259 -0
- package/dist/src/api/welcomePage.js.map +1 -0
- package/dist/src/bootstrap.d.ts +20 -0
- package/dist/src/bootstrap.js +128 -0
- package/dist/src/bootstrap.js.map +1 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +32 -0
- package/dist/src/cli.js.map +1 -0
- package/dist/src/config/AppConfig.d.ts +102 -0
- package/dist/src/config/AppConfig.js +452 -0
- package/dist/src/config/AppConfig.js.map +1 -0
- package/dist/src/config/redis.config.d.ts +6 -0
- package/dist/src/config/redis.config.js +9 -0
- package/dist/src/config/redis.config.js.map +1 -0
- package/dist/src/container.d.ts +29 -0
- package/dist/src/container.js +62 -0
- package/dist/src/container.js.map +1 -0
- package/dist/src/debug/BreakpointManager.d.ts +17 -0
- package/dist/src/debug/BreakpointManager.js +59 -0
- package/dist/src/debug/BreakpointManager.js.map +1 -0
- package/dist/src/debug/WorkflowDebugger.d.ts +34 -0
- package/dist/src/debug/WorkflowDebugger.js +117 -0
- package/dist/src/debug/WorkflowDebugger.js.map +1 -0
- package/dist/src/debug/index.d.ts +2 -0
- package/dist/src/debug/index.js +3 -0
- package/dist/src/debug/index.js.map +1 -0
- package/dist/src/demo/demoWorkflow.d.ts +3 -0
- package/dist/src/demo/demoWorkflow.js +82 -0
- package/dist/src/demo/demoWorkflow.js.map +1 -0
- package/dist/src/demo/exampleWorkflow.d.ts +36 -0
- package/dist/src/demo/exampleWorkflow.js +184 -0
- package/dist/src/demo/exampleWorkflow.js.map +1 -0
- package/dist/src/demo/index.d.ts +2 -0
- package/dist/src/demo/index.js +3 -0
- package/dist/src/demo/index.js.map +1 -0
- package/dist/src/dlq/DeadLetterQueue.d.ts +62 -0
- package/dist/src/dlq/DeadLetterQueue.js +342 -0
- package/dist/src/dlq/DeadLetterQueue.js.map +1 -0
- package/dist/src/dlq/index.d.ts +2 -0
- package/dist/src/dlq/index.js +2 -0
- package/dist/src/dlq/index.js.map +1 -0
- package/dist/src/dsl/DSLParser.d.ts +7 -0
- package/dist/src/dsl/DSLParser.js +252 -0
- package/dist/src/dsl/DSLParser.js.map +1 -0
- package/dist/src/dsl/WorkflowDSL.d.ts +40 -0
- package/dist/src/dsl/WorkflowDSL.js +2 -0
- package/dist/src/dsl/WorkflowDSL.js.map +1 -0
- package/dist/src/engine/CanaryReleaseManager.d.ts +39 -0
- package/dist/src/engine/CanaryReleaseManager.js +192 -0
- package/dist/src/engine/CanaryReleaseManager.js.map +1 -0
- package/dist/src/engine/ConcurrencyControl.d.ts +38 -0
- package/dist/src/engine/ConcurrencyControl.js +181 -0
- package/dist/src/engine/ConcurrencyControl.js.map +1 -0
- package/dist/src/engine/ContinueAsNewManager.d.ts +18 -0
- package/dist/src/engine/ContinueAsNewManager.js +29 -0
- package/dist/src/engine/ContinueAsNewManager.js.map +1 -0
- package/dist/src/engine/DataValidator.d.ts +15 -0
- package/dist/src/engine/DataValidator.js +121 -0
- package/dist/src/engine/DataValidator.js.map +1 -0
- package/dist/src/engine/DryRunExecutor.d.ts +48 -0
- package/dist/src/engine/DryRunExecutor.js +256 -0
- package/dist/src/engine/DryRunExecutor.js.map +1 -0
- package/dist/src/engine/ExecutionOrchestrator.d.ts +19 -0
- package/dist/src/engine/ExecutionOrchestrator.js +579 -0
- package/dist/src/engine/ExecutionOrchestrator.js.map +1 -0
- package/dist/src/engine/ExpressionEvaluator.d.ts +44 -0
- package/dist/src/engine/ExpressionEvaluator.js +1046 -0
- package/dist/src/engine/ExpressionEvaluator.js.map +1 -0
- package/dist/src/engine/HeartbeatManager.d.ts +42 -0
- package/dist/src/engine/HeartbeatManager.js +209 -0
- package/dist/src/engine/HeartbeatManager.js.map +1 -0
- package/dist/src/engine/InstanceManager.d.ts +21 -0
- package/dist/src/engine/InstanceManager.js +165 -0
- package/dist/src/engine/InstanceManager.js.map +1 -0
- package/dist/src/engine/InstanceSearch.d.ts +30 -0
- package/dist/src/engine/InstanceSearch.js +119 -0
- package/dist/src/engine/InstanceSearch.js.map +1 -0
- package/dist/src/engine/LifecycleManager.d.ts +18 -0
- package/dist/src/engine/LifecycleManager.js +82 -0
- package/dist/src/engine/LifecycleManager.js.map +1 -0
- package/dist/src/engine/ParallelExecutor.d.ts +26 -0
- package/dist/src/engine/ParallelExecutor.js +138 -0
- package/dist/src/engine/ParallelExecutor.js.map +1 -0
- package/dist/src/engine/SandboxEvaluator.d.ts +18 -0
- package/dist/src/engine/SandboxEvaluator.js +200 -0
- package/dist/src/engine/SandboxEvaluator.js.map +1 -0
- package/dist/src/engine/SchemaValidator.d.ts +30 -0
- package/dist/src/engine/SchemaValidator.js +630 -0
- package/dist/src/engine/SchemaValidator.js.map +1 -0
- package/dist/src/engine/SearchAttributeManager.d.ts +48 -0
- package/dist/src/engine/SearchAttributeManager.js +119 -0
- package/dist/src/engine/SearchAttributeManager.js.map +1 -0
- package/dist/src/engine/StateMachine.d.ts +13 -0
- package/dist/src/engine/StateMachine.js +66 -0
- package/dist/src/engine/StateMachine.js.map +1 -0
- package/dist/src/engine/StickyExecutionManager.d.ts +34 -0
- package/dist/src/engine/StickyExecutionManager.js +163 -0
- package/dist/src/engine/StickyExecutionManager.js.map +1 -0
- package/dist/src/engine/SubworkflowExecutor.d.ts +17 -0
- package/dist/src/engine/SubworkflowExecutor.js +157 -0
- package/dist/src/engine/SubworkflowExecutor.js.map +1 -0
- package/dist/src/engine/TaskExecutor.d.ts +12 -0
- package/dist/src/engine/TaskExecutor.js +124 -0
- package/dist/src/engine/TaskExecutor.js.map +1 -0
- package/dist/src/engine/TaskQueueManager.d.ts +42 -0
- package/dist/src/engine/TaskQueueManager.js +175 -0
- package/dist/src/engine/TaskQueueManager.js.map +1 -0
- package/dist/src/engine/WorkflowEngine.d.ts +117 -0
- package/dist/src/engine/WorkflowEngine.js +443 -0
- package/dist/src/engine/WorkflowEngine.js.map +1 -0
- package/dist/src/engine/WorkflowInstanceControl.d.ts +21 -0
- package/dist/src/engine/WorkflowInstanceControl.js +306 -0
- package/dist/src/engine/WorkflowInstanceControl.js.map +1 -0
- package/dist/src/engine/WorkflowPersistenceCoordinator.d.ts +12 -0
- package/dist/src/engine/WorkflowPersistenceCoordinator.js +93 -0
- package/dist/src/engine/WorkflowPersistenceCoordinator.js.map +1 -0
- package/dist/src/engine/WorkflowRegistry.d.ts +38 -0
- package/dist/src/engine/WorkflowRegistry.js +130 -0
- package/dist/src/engine/WorkflowRegistry.js.map +1 -0
- package/dist/src/engine/WorkflowVersionManager.d.ts +24 -0
- package/dist/src/engine/WorkflowVersionManager.js +121 -0
- package/dist/src/engine/WorkflowVersionManager.js.map +1 -0
- package/dist/src/engine/createEngine.d.ts +8 -0
- package/dist/src/engine/createEngine.js +21 -0
- package/dist/src/engine/createEngine.js.map +1 -0
- package/dist/src/engine/errors.d.ts +18 -0
- package/dist/src/engine/errors.js +37 -0
- package/dist/src/engine/errors.js.map +1 -0
- package/dist/src/engine/executors/ApprovalNodeExecutor.d.ts +12 -0
- package/dist/src/engine/executors/ApprovalNodeExecutor.js +68 -0
- package/dist/src/engine/executors/ApprovalNodeExecutor.js.map +1 -0
- package/dist/src/engine/executors/ConditionNodeExecutor.d.ts +16 -0
- package/dist/src/engine/executors/ConditionNodeExecutor.js +63 -0
- package/dist/src/engine/executors/ConditionNodeExecutor.js.map +1 -0
- package/dist/src/engine/executors/HttpNodeExecutor.d.ts +27 -0
- package/dist/src/engine/executors/HttpNodeExecutor.js +179 -0
- package/dist/src/engine/executors/HttpNodeExecutor.js.map +1 -0
- package/dist/src/engine/executors/JoinNodeExecutor.d.ts +13 -0
- package/dist/src/engine/executors/JoinNodeExecutor.js +37 -0
- package/dist/src/engine/executors/JoinNodeExecutor.js.map +1 -0
- package/dist/src/engine/executors/LoopNodeExecutor.d.ts +20 -0
- package/dist/src/engine/executors/LoopNodeExecutor.js +165 -0
- package/dist/src/engine/executors/LoopNodeExecutor.js.map +1 -0
- package/dist/src/engine/executors/NotificationNodeExecutor.d.ts +8 -0
- package/dist/src/engine/executors/NotificationNodeExecutor.js +33 -0
- package/dist/src/engine/executors/NotificationNodeExecutor.js.map +1 -0
- package/dist/src/engine/executors/QueueNodeExecutor.d.ts +23 -0
- package/dist/src/engine/executors/QueueNodeExecutor.js +87 -0
- package/dist/src/engine/executors/QueueNodeExecutor.js.map +1 -0
- package/dist/src/engine/executors/RouterNodeExecutor.d.ts +20 -0
- package/dist/src/engine/executors/RouterNodeExecutor.js +82 -0
- package/dist/src/engine/executors/RouterNodeExecutor.js.map +1 -0
- package/dist/src/engine/executors/SqlNodeExecutor.d.ts +27 -0
- package/dist/src/engine/executors/SqlNodeExecutor.js +74 -0
- package/dist/src/engine/executors/SqlNodeExecutor.js.map +1 -0
- package/dist/src/engine/executors/TransformNodeExecutor.d.ts +9 -0
- package/dist/src/engine/executors/TransformNodeExecutor.js +44 -0
- package/dist/src/engine/executors/TransformNodeExecutor.js.map +1 -0
- package/dist/src/engine/functions/collectionFunctions.d.ts +2 -0
- package/dist/src/engine/functions/collectionFunctions.js +129 -0
- package/dist/src/engine/functions/collectionFunctions.js.map +1 -0
- package/dist/src/engine/functions/customFunctions.d.ts +11 -0
- package/dist/src/engine/functions/customFunctions.js +42 -0
- package/dist/src/engine/functions/customFunctions.js.map +1 -0
- package/dist/src/engine/functions/dateFunctions.d.ts +2 -0
- package/dist/src/engine/functions/dateFunctions.js +71 -0
- package/dist/src/engine/functions/dateFunctions.js.map +1 -0
- package/dist/src/engine/functions/index.d.ts +14 -0
- package/dist/src/engine/functions/index.js +35 -0
- package/dist/src/engine/functions/index.js.map +1 -0
- package/dist/src/engine/functions/stringFunctions.d.ts +2 -0
- package/dist/src/engine/functions/stringFunctions.js +66 -0
- package/dist/src/engine/functions/stringFunctions.js.map +1 -0
- package/dist/src/engine/functions/typeFunctions.d.ts +2 -0
- package/dist/src/engine/functions/typeFunctions.js +70 -0
- package/dist/src/engine/functions/typeFunctions.js.map +1 -0
- package/dist/src/engine/functions/types.d.ts +6 -0
- package/dist/src/engine/functions/types.js +2 -0
- package/dist/src/engine/functions/types.js.map +1 -0
- package/dist/src/engine/index.d.ts +21 -0
- package/dist/src/engine/index.js +18 -0
- package/dist/src/engine/index.js.map +1 -0
- package/dist/src/engine/nodeDispatch/controlNodes.d.ts +2 -0
- package/dist/src/engine/nodeDispatch/controlNodes.js +208 -0
- package/dist/src/engine/nodeDispatch/controlNodes.js.map +1 -0
- package/dist/src/engine/nodeDispatch/helpers.d.ts +27 -0
- package/dist/src/engine/nodeDispatch/helpers.js +185 -0
- package/dist/src/engine/nodeDispatch/helpers.js.map +1 -0
- package/dist/src/engine/nodeDispatch/ioNodes.d.ts +2 -0
- package/dist/src/engine/nodeDispatch/ioNodes.js +89 -0
- package/dist/src/engine/nodeDispatch/ioNodes.js.map +1 -0
- package/dist/src/engine/nodeDispatch/types.d.ts +13 -0
- package/dist/src/engine/nodeDispatch/types.js +2 -0
- package/dist/src/engine/nodeDispatch/types.js.map +1 -0
- package/dist/src/engine/nodeDispatch/workflowNodes.d.ts +2 -0
- package/dist/src/engine/nodeDispatch/workflowNodes.js +33 -0
- package/dist/src/engine/nodeDispatch/workflowNodes.js.map +1 -0
- package/dist/src/engine/worker/ActionSandboxMessage.d.ts +29 -0
- package/dist/src/engine/worker/ActionSandboxMessage.js +7 -0
- package/dist/src/engine/worker/ActionSandboxMessage.js.map +1 -0
- package/dist/src/engine/worker/ActionSandboxPool.d.ts +34 -0
- package/dist/src/engine/worker/ActionSandboxPool.js +204 -0
- package/dist/src/engine/worker/ActionSandboxPool.js.map +1 -0
- package/dist/src/engine/worker/ActionSandboxWorker.d.ts +1 -0
- package/dist/src/engine/worker/ActionSandboxWorker.js +25 -0
- package/dist/src/engine/worker/ActionSandboxWorker.js.map +1 -0
- package/dist/src/engine/worker/WorkerMessage.d.ts +35 -0
- package/dist/src/engine/worker/WorkerMessage.js +7 -0
- package/dist/src/engine/worker/WorkerMessage.js.map +1 -0
- package/dist/src/engine/worker/WorkerPool.d.ts +42 -0
- package/dist/src/engine/worker/WorkerPool.js +273 -0
- package/dist/src/engine/worker/WorkerPool.js.map +1 -0
- package/dist/src/engine/worker/WorkerProcess.d.ts +1 -0
- package/dist/src/engine/worker/WorkerProcess.js +76 -0
- package/dist/src/engine/worker/WorkerProcess.js.map +1 -0
- package/dist/src/event/EventBus.d.ts +11 -0
- package/dist/src/event/EventBus.js +44 -0
- package/dist/src/event/EventBus.js.map +1 -0
- package/dist/src/event/EventCoordinator.d.ts +26 -0
- package/dist/src/event/EventCoordinator.js +205 -0
- package/dist/src/event/EventCoordinator.js.map +1 -0
- package/dist/src/event/EventDeduplicator.d.ts +31 -0
- package/dist/src/event/EventDeduplicator.js +100 -0
- package/dist/src/event/EventDeduplicator.js.map +1 -0
- package/dist/src/event/HookManager.d.ts +31 -0
- package/dist/src/event/HookManager.js +88 -0
- package/dist/src/event/HookManager.js.map +1 -0
- package/dist/src/event/MessageBus.d.ts +39 -0
- package/dist/src/event/MessageBus.js +131 -0
- package/dist/src/event/MessageBus.js.map +1 -0
- package/dist/src/event/index.d.ts +3 -0
- package/dist/src/event/index.js +4 -0
- package/dist/src/event/index.js.map +1 -0
- package/dist/src/index.d.ts +40 -0
- package/dist/src/index.js +33 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/lifecycle.d.ts +17 -0
- package/dist/src/lifecycle.js +84 -0
- package/dist/src/lifecycle.js.map +1 -0
- package/dist/src/metrics/AnalyticsCollector.d.ts +57 -0
- package/dist/src/metrics/AnalyticsCollector.js +140 -0
- package/dist/src/metrics/AnalyticsCollector.js.map +1 -0
- package/dist/src/metrics/AnomalyDetector.d.ts +21 -0
- package/dist/src/metrics/AnomalyDetector.js +120 -0
- package/dist/src/metrics/AnomalyDetector.js.map +1 -0
- package/dist/src/metrics/MetricsAggregator.d.ts +43 -0
- package/dist/src/metrics/MetricsAggregator.js +243 -0
- package/dist/src/metrics/MetricsAggregator.js.map +1 -0
- package/dist/src/metrics/SlaMonitor.d.ts +48 -0
- package/dist/src/metrics/SlaMonitor.js +130 -0
- package/dist/src/metrics/SlaMonitor.js.map +1 -0
- package/dist/src/metrics/index.d.ts +75 -0
- package/dist/src/metrics/index.js +293 -0
- package/dist/src/metrics/index.js.map +1 -0
- package/dist/src/model/Instance.d.ts +38 -0
- package/dist/src/model/Instance.js +12 -0
- package/dist/src/model/Instance.js.map +1 -0
- package/dist/src/model/RetryPolicy.d.ts +11 -0
- package/dist/src/model/RetryPolicy.js +30 -0
- package/dist/src/model/RetryPolicy.js.map +1 -0
- package/dist/src/model/Schedule.d.ts +34 -0
- package/dist/src/model/Schedule.js +50 -0
- package/dist/src/model/Schedule.js.map +1 -0
- package/dist/src/model/Workflow.d.ts +73 -0
- package/dist/src/model/Workflow.js +2 -0
- package/dist/src/model/Workflow.js.map +1 -0
- package/dist/src/model/WorkflowGraph.d.ts +32 -0
- package/dist/src/model/WorkflowGraph.js +267 -0
- package/dist/src/model/WorkflowGraph.js.map +1 -0
- package/dist/src/model/WorkflowSchema.d.ts +154 -0
- package/dist/src/model/WorkflowSchema.js +233 -0
- package/dist/src/model/WorkflowSchema.js.map +1 -0
- package/dist/src/model/WorkflowVariables.d.ts +15 -0
- package/dist/src/model/WorkflowVariables.js +77 -0
- package/dist/src/model/WorkflowVariables.js.map +1 -0
- package/dist/src/notification/NotificationChannel.d.ts +19 -0
- package/dist/src/notification/NotificationChannel.js +2 -0
- package/dist/src/notification/NotificationChannel.js.map +1 -0
- package/dist/src/notification/NotificationManager.d.ts +20 -0
- package/dist/src/notification/NotificationManager.js +59 -0
- package/dist/src/notification/NotificationManager.js.map +1 -0
- package/dist/src/notification/channels/DingtalkChannel.d.ts +7 -0
- package/dist/src/notification/channels/DingtalkChannel.js +18 -0
- package/dist/src/notification/channels/DingtalkChannel.js.map +1 -0
- package/dist/src/notification/channels/EmailChannel.d.ts +21 -0
- package/dist/src/notification/channels/EmailChannel.js +32 -0
- package/dist/src/notification/channels/EmailChannel.js.map +1 -0
- package/dist/src/notification/channels/FeishuChannel.d.ts +7 -0
- package/dist/src/notification/channels/FeishuChannel.js +18 -0
- package/dist/src/notification/channels/FeishuChannel.js.map +1 -0
- package/dist/src/notification/channels/SlackChannel.d.ts +7 -0
- package/dist/src/notification/channels/SlackChannel.js +18 -0
- package/dist/src/notification/channels/SlackChannel.js.map +1 -0
- package/dist/src/notification/channels/SmsChannel.d.ts +24 -0
- package/dist/src/notification/channels/SmsChannel.js +37 -0
- package/dist/src/notification/channels/SmsChannel.js.map +1 -0
- package/dist/src/notification/channels/WebhookChannel.d.ts +17 -0
- package/dist/src/notification/channels/WebhookChannel.js +61 -0
- package/dist/src/notification/channels/WebhookChannel.js.map +1 -0
- package/dist/src/notification/index.d.ts +24 -0
- package/dist/src/notification/index.js +61 -0
- package/dist/src/notification/index.js.map +1 -0
- package/dist/src/scheduler/CronScheduler.d.ts +20 -0
- package/dist/src/scheduler/CronScheduler.js +82 -0
- package/dist/src/scheduler/CronScheduler.js.map +1 -0
- package/dist/src/scheduler/EnhancedCronScheduler.d.ts +27 -0
- package/dist/src/scheduler/EnhancedCronScheduler.js +177 -0
- package/dist/src/scheduler/EnhancedCronScheduler.js.map +1 -0
- package/dist/src/storage/ArchiveManager.d.ts +21 -0
- package/dist/src/storage/ArchiveManager.js +140 -0
- package/dist/src/storage/ArchiveManager.js.map +1 -0
- package/dist/src/storage/LocalFileStorage.d.ts +64 -0
- package/dist/src/storage/LocalFileStorage.js +470 -0
- package/dist/src/storage/LocalFileStorage.js.map +1 -0
- package/dist/src/storage/MemoryStorage.d.ts +65 -0
- package/dist/src/storage/MemoryStorage.js +422 -0
- package/dist/src/storage/MemoryStorage.js.map +1 -0
- package/dist/src/storage/StorageProvider.d.ts +223 -0
- package/dist/src/storage/StorageProvider.js +2 -0
- package/dist/src/storage/StorageProvider.js.map +1 -0
- package/dist/src/storage/builtin-adapters.d.ts +1 -0
- package/dist/src/storage/builtin-adapters.js +20 -0
- package/dist/src/storage/builtin-adapters.js.map +1 -0
- package/dist/src/storage/index.d.ts +17 -0
- package/dist/src/storage/index.js +52 -0
- package/dist/src/storage/index.js.map +1 -0
- package/dist/src/storage/registry.d.ts +6 -0
- package/dist/src/storage/registry.js +23 -0
- package/dist/src/storage/registry.js.map +1 -0
- package/dist/src/telemetry/index.d.ts +53 -0
- package/dist/src/telemetry/index.js +73 -0
- package/dist/src/telemetry/index.js.map +1 -0
- package/dist/src/telemetry/spanRegistry.d.ts +9 -0
- package/dist/src/telemetry/spanRegistry.js +14 -0
- package/dist/src/telemetry/spanRegistry.js.map +1 -0
- package/dist/src/templates/AutoExtract.d.ts +2 -0
- package/dist/src/templates/AutoExtract.js +124 -0
- package/dist/src/templates/AutoExtract.js.map +1 -0
- package/dist/src/templates/TemplateGallery.d.ts +54 -0
- package/dist/src/templates/TemplateGallery.js +139 -0
- package/dist/src/templates/TemplateGallery.js.map +1 -0
- package/dist/src/templates/TemplateRegistry.d.ts +16 -0
- package/dist/src/templates/TemplateRegistry.js +92 -0
- package/dist/src/templates/TemplateRegistry.js.map +1 -0
- package/dist/src/templates/WorkflowTemplate.d.ts +24 -0
- package/dist/src/templates/WorkflowTemplate.js +2 -0
- package/dist/src/templates/WorkflowTemplate.js.map +1 -0
- package/dist/src/templates/builtin/HttpCallbackTemplate.d.ts +2 -0
- package/dist/src/templates/builtin/HttpCallbackTemplate.js +47 -0
- package/dist/src/templates/builtin/HttpCallbackTemplate.js.map +1 -0
- package/dist/src/templates/builtin/index.d.ts +3 -0
- package/dist/src/templates/builtin/index.js +11 -0
- package/dist/src/templates/builtin/index.js.map +1 -0
- package/dist/src/templates/index.d.ts +3 -0
- package/dist/src/templates/index.js +3 -0
- package/dist/src/templates/index.js.map +1 -0
- package/dist/src/testing/MutationTester.d.ts +27 -0
- package/dist/src/testing/MutationTester.js +157 -0
- package/dist/src/testing/MutationTester.js.map +1 -0
- package/dist/src/testing/TestGenerator.d.ts +31 -0
- package/dist/src/testing/TestGenerator.js +345 -0
- package/dist/src/testing/TestGenerator.js.map +1 -0
- package/dist/src/testing/index.d.ts +2 -0
- package/dist/src/testing/index.js +3 -0
- package/dist/src/testing/index.js.map +1 -0
- package/dist/src/testing/testWorkflow.d.ts +51 -0
- package/dist/src/testing/testWorkflow.js +167 -0
- package/dist/src/testing/testWorkflow.js.map +1 -0
- package/dist/src/utils/AuditLogger.d.ts +36 -0
- package/dist/src/utils/AuditLogger.js +148 -0
- package/dist/src/utils/AuditLogger.js.map +1 -0
- package/dist/src/utils/BoundedMap.d.ts +34 -0
- package/dist/src/utils/BoundedMap.js +125 -0
- package/dist/src/utils/BoundedMap.js.map +1 -0
- package/dist/src/utils/LeaseStore.d.ts +7 -0
- package/dist/src/utils/LeaseStore.js +102 -0
- package/dist/src/utils/LeaseStore.js.map +1 -0
- package/dist/src/utils/Logger.d.ts +26 -0
- package/dist/src/utils/Logger.js +279 -0
- package/dist/src/utils/Logger.js.map +1 -0
- package/dist/src/utils/SecretManager.d.ts +41 -0
- package/dist/src/utils/SecretManager.js +139 -0
- package/dist/src/utils/SecretManager.js.map +1 -0
- package/dist/src/utils/StructuredLogger.d.ts +45 -0
- package/dist/src/utils/StructuredLogger.js +118 -0
- package/dist/src/utils/StructuredLogger.js.map +1 -0
- package/dist/src/utils/concurrency.d.ts +3 -0
- package/dist/src/utils/concurrency.js +22 -0
- package/dist/src/utils/concurrency.js.map +1 -0
- package/dist/src/utils/env.d.ts +5 -0
- package/dist/src/utils/env.js +15 -0
- package/dist/src/utils/env.js.map +1 -0
- package/dist/src/utils/index.d.ts +5 -0
- package/dist/src/utils/index.js +4 -0
- package/dist/src/utils/index.js.map +1 -0
- package/dist/src/utils/secrets.d.ts +5 -0
- package/dist/src/utils/secrets.js +27 -0
- package/dist/src/utils/secrets.js.map +1 -0
- package/package.json +159 -0
|
@@ -0,0 +1,1046 @@
|
|
|
1
|
+
import { Logger } from "../utils/Logger.js";
|
|
2
|
+
import { registerFunctionLibrary } from "./functions/index.js";
|
|
3
|
+
let traceEnabled = false;
|
|
4
|
+
let expressionTraces = [];
|
|
5
|
+
export async function withExpressionTrace(fn) {
|
|
6
|
+
const previousEnabled = traceEnabled;
|
|
7
|
+
const previousTraces = expressionTraces;
|
|
8
|
+
traceEnabled = true;
|
|
9
|
+
expressionTraces = [];
|
|
10
|
+
try {
|
|
11
|
+
return await fn();
|
|
12
|
+
}
|
|
13
|
+
finally {
|
|
14
|
+
traceEnabled = previousEnabled;
|
|
15
|
+
if (!previousEnabled) {
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
expressionTraces = previousTraces;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export function getExpressionTraces() {
|
|
23
|
+
return [...expressionTraces];
|
|
24
|
+
}
|
|
25
|
+
var TokenType;
|
|
26
|
+
(function (TokenType) {
|
|
27
|
+
TokenType["NUMBER"] = "NUMBER";
|
|
28
|
+
TokenType["STRING"] = "STRING";
|
|
29
|
+
TokenType["BOOLEAN"] = "BOOLEAN";
|
|
30
|
+
TokenType["NULL"] = "NULL";
|
|
31
|
+
TokenType["IDENTIFIER"] = "IDENTIFIER";
|
|
32
|
+
TokenType["OPERATOR"] = "OPERATOR";
|
|
33
|
+
TokenType["LPAREN"] = "LPAREN";
|
|
34
|
+
TokenType["RPAREN"] = "RPAREN";
|
|
35
|
+
TokenType["LBRACKET"] = "LBRACKET";
|
|
36
|
+
TokenType["RBRACKET"] = "RBRACKET";
|
|
37
|
+
TokenType["COMMA"] = "COMMA";
|
|
38
|
+
TokenType["ARROW"] = "ARROW";
|
|
39
|
+
TokenType["DOT"] = "DOT";
|
|
40
|
+
TokenType["EOF"] = "EOF";
|
|
41
|
+
})(TokenType || (TokenType = {}));
|
|
42
|
+
const OPERATORS = {
|
|
43
|
+
"|": {
|
|
44
|
+
precedence: 0,
|
|
45
|
+
associativity: "left",
|
|
46
|
+
fn: (_a, _b) => {
|
|
47
|
+
throw new Error("Pipe operator should be handled by the parser");
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
"||": {
|
|
51
|
+
precedence: 1,
|
|
52
|
+
associativity: "left",
|
|
53
|
+
fn: (a, b) => Boolean(a) || Boolean(b),
|
|
54
|
+
},
|
|
55
|
+
"&&": {
|
|
56
|
+
precedence: 2,
|
|
57
|
+
associativity: "left",
|
|
58
|
+
fn: (a, b) => Boolean(a) && Boolean(b),
|
|
59
|
+
},
|
|
60
|
+
"==": {
|
|
61
|
+
precedence: 3,
|
|
62
|
+
associativity: "left",
|
|
63
|
+
fn: (a, b) => a === b,
|
|
64
|
+
},
|
|
65
|
+
"!=": {
|
|
66
|
+
precedence: 3,
|
|
67
|
+
associativity: "left",
|
|
68
|
+
fn: (a, b) => a !== b,
|
|
69
|
+
},
|
|
70
|
+
"===": {
|
|
71
|
+
precedence: 3,
|
|
72
|
+
associativity: "left",
|
|
73
|
+
fn: (a, b) => a === b,
|
|
74
|
+
},
|
|
75
|
+
"!==": {
|
|
76
|
+
precedence: 3,
|
|
77
|
+
associativity: "left",
|
|
78
|
+
fn: (a, b) => a !== b,
|
|
79
|
+
},
|
|
80
|
+
"<": {
|
|
81
|
+
precedence: 4,
|
|
82
|
+
associativity: "left",
|
|
83
|
+
fn: (a, b) => a < b,
|
|
84
|
+
},
|
|
85
|
+
">": {
|
|
86
|
+
precedence: 4,
|
|
87
|
+
associativity: "left",
|
|
88
|
+
fn: (a, b) => a > b,
|
|
89
|
+
},
|
|
90
|
+
"<=": {
|
|
91
|
+
precedence: 4,
|
|
92
|
+
associativity: "left",
|
|
93
|
+
fn: (a, b) => a <= b,
|
|
94
|
+
},
|
|
95
|
+
">=": {
|
|
96
|
+
precedence: 4,
|
|
97
|
+
associativity: "left",
|
|
98
|
+
fn: (a, b) => a >= b,
|
|
99
|
+
},
|
|
100
|
+
"+": {
|
|
101
|
+
precedence: 5,
|
|
102
|
+
associativity: "left",
|
|
103
|
+
fn: (a, b) => a + b,
|
|
104
|
+
},
|
|
105
|
+
"-": {
|
|
106
|
+
precedence: 5,
|
|
107
|
+
associativity: "left",
|
|
108
|
+
fn: (a, b) => a - b,
|
|
109
|
+
},
|
|
110
|
+
"*": {
|
|
111
|
+
precedence: 6,
|
|
112
|
+
associativity: "left",
|
|
113
|
+
fn: (a, b) => a * b,
|
|
114
|
+
},
|
|
115
|
+
"/": {
|
|
116
|
+
precedence: 6,
|
|
117
|
+
associativity: "left",
|
|
118
|
+
fn: (a, b) => a / b,
|
|
119
|
+
},
|
|
120
|
+
"%": {
|
|
121
|
+
precedence: 6,
|
|
122
|
+
associativity: "left",
|
|
123
|
+
fn: (a, b) => a % b,
|
|
124
|
+
},
|
|
125
|
+
"**": {
|
|
126
|
+
precedence: 7,
|
|
127
|
+
associativity: "right",
|
|
128
|
+
fn: (a, b) => a ** b,
|
|
129
|
+
},
|
|
130
|
+
"!": {
|
|
131
|
+
precedence: 8,
|
|
132
|
+
associativity: "right",
|
|
133
|
+
unary: true,
|
|
134
|
+
fn: (a) => !a,
|
|
135
|
+
},
|
|
136
|
+
"u-": {
|
|
137
|
+
precedence: 8,
|
|
138
|
+
associativity: "right",
|
|
139
|
+
unary: true,
|
|
140
|
+
fn: (a) => -a,
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
const FUNCTIONS = {};
|
|
144
|
+
export function registerFunction(name, fn) {
|
|
145
|
+
FUNCTIONS[name] = fn;
|
|
146
|
+
}
|
|
147
|
+
function initializeBuiltInFunctions() {
|
|
148
|
+
registerFunction("abs", (x) => Math.abs(x));
|
|
149
|
+
registerFunction("ceil", (x) => Math.ceil(x));
|
|
150
|
+
registerFunction("floor", (x) => Math.floor(x));
|
|
151
|
+
registerFunction("round", (x, decimals = 0) => {
|
|
152
|
+
if (decimals === 0)
|
|
153
|
+
return Math.round(x);
|
|
154
|
+
const factor = 10 ** decimals;
|
|
155
|
+
return Math.round(x * factor) / factor;
|
|
156
|
+
});
|
|
157
|
+
registerFunction("min", (...args) => Math.min(...args));
|
|
158
|
+
registerFunction("max", (...args) => Math.max(...args));
|
|
159
|
+
registerFunction("sqrt", (x) => Math.sqrt(x));
|
|
160
|
+
registerFunction("pow", (x, y) => x ** y);
|
|
161
|
+
registerFunction("length", (s) => {
|
|
162
|
+
if (typeof s === "string")
|
|
163
|
+
return s.length;
|
|
164
|
+
if (Array.isArray(s))
|
|
165
|
+
return s.length;
|
|
166
|
+
return 0;
|
|
167
|
+
});
|
|
168
|
+
registerFunction("substring", (s, start, end) => {
|
|
169
|
+
return s.substring(start, end);
|
|
170
|
+
});
|
|
171
|
+
registerFunction("toLowerCase", (s) => s.toLowerCase());
|
|
172
|
+
registerFunction("toUpperCase", (s) => s.toUpperCase());
|
|
173
|
+
registerFunction("trim", (s) => s.trim());
|
|
174
|
+
registerFunction("concat", (...args) => args.join(""));
|
|
175
|
+
registerFunction("includes", (s, search) => {
|
|
176
|
+
if (typeof s === "string")
|
|
177
|
+
return s.includes(String(search));
|
|
178
|
+
if (Array.isArray(s))
|
|
179
|
+
return s.includes(search);
|
|
180
|
+
return false;
|
|
181
|
+
});
|
|
182
|
+
registerFunction("startsWith", (s, prefix) => s.startsWith(prefix));
|
|
183
|
+
registerFunction("endsWith", (s, suffix) => s.endsWith(suffix));
|
|
184
|
+
registerFunction("now", () => Date.now());
|
|
185
|
+
registerFunction("parse", (s) => Date.parse(s));
|
|
186
|
+
registerFunction("format", (timestamp, format) => {
|
|
187
|
+
const date = new Date(timestamp);
|
|
188
|
+
if (!format)
|
|
189
|
+
return date.toISOString();
|
|
190
|
+
return date.toISOString();
|
|
191
|
+
});
|
|
192
|
+
registerFunction("addDays", (timestamp, days) => {
|
|
193
|
+
return timestamp + days * 24 * 60 * 60 * 1000;
|
|
194
|
+
});
|
|
195
|
+
registerFunction("addHours", (timestamp, hours) => {
|
|
196
|
+
return timestamp + hours * 60 * 60 * 1000;
|
|
197
|
+
});
|
|
198
|
+
registerFunction("diff", (timestamp1, timestamp2, unit = "ms") => {
|
|
199
|
+
const diff = timestamp1 - timestamp2;
|
|
200
|
+
switch (unit) {
|
|
201
|
+
case "ms":
|
|
202
|
+
return diff;
|
|
203
|
+
case "s":
|
|
204
|
+
return diff / 1000;
|
|
205
|
+
case "m":
|
|
206
|
+
return diff / (1000 * 60);
|
|
207
|
+
case "h":
|
|
208
|
+
return diff / (1000 * 60 * 60);
|
|
209
|
+
case "d":
|
|
210
|
+
return diff / (1000 * 60 * 60 * 24);
|
|
211
|
+
default:
|
|
212
|
+
return diff;
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
registerFunction("join", (arr, separator = ",") => {
|
|
216
|
+
if (!Array.isArray(arr))
|
|
217
|
+
return String(arr);
|
|
218
|
+
return arr.join(separator);
|
|
219
|
+
});
|
|
220
|
+
registerFunction("map", (arr, fn) => {
|
|
221
|
+
if (!Array.isArray(arr))
|
|
222
|
+
return [];
|
|
223
|
+
if (typeof fn === "function")
|
|
224
|
+
return arr.map(fn);
|
|
225
|
+
return arr;
|
|
226
|
+
});
|
|
227
|
+
registerFunction("filter", (arr, fn) => {
|
|
228
|
+
if (!Array.isArray(arr))
|
|
229
|
+
return [];
|
|
230
|
+
if (typeof fn === "function")
|
|
231
|
+
return arr.filter(fn);
|
|
232
|
+
return arr;
|
|
233
|
+
});
|
|
234
|
+
registerFunction("reduce", (arr, fn, initial) => {
|
|
235
|
+
if (!Array.isArray(arr))
|
|
236
|
+
return initial;
|
|
237
|
+
if (typeof fn === "function") {
|
|
238
|
+
return initial !== undefined ? arr.reduce(fn, initial) : arr.reduce(fn);
|
|
239
|
+
}
|
|
240
|
+
return initial;
|
|
241
|
+
});
|
|
242
|
+
registerFunction("find", (arr, fn) => {
|
|
243
|
+
if (!Array.isArray(arr))
|
|
244
|
+
return undefined;
|
|
245
|
+
if (typeof fn === "function")
|
|
246
|
+
return arr.find(fn);
|
|
247
|
+
return undefined;
|
|
248
|
+
});
|
|
249
|
+
registerFunction("some", (arr, fn) => {
|
|
250
|
+
if (!Array.isArray(arr))
|
|
251
|
+
return false;
|
|
252
|
+
if (typeof fn === "function")
|
|
253
|
+
return arr.some(fn);
|
|
254
|
+
return false;
|
|
255
|
+
});
|
|
256
|
+
registerFunction("every", (arr, fn) => {
|
|
257
|
+
if (!Array.isArray(arr))
|
|
258
|
+
return false;
|
|
259
|
+
if (typeof fn === "function")
|
|
260
|
+
return arr.every(fn);
|
|
261
|
+
return false;
|
|
262
|
+
});
|
|
263
|
+
registerFunction("flat", (arr, depth = 1) => {
|
|
264
|
+
if (!Array.isArray(arr))
|
|
265
|
+
return [];
|
|
266
|
+
return arr.flat(depth);
|
|
267
|
+
});
|
|
268
|
+
registerFunction("flatMap", (arr, fn) => {
|
|
269
|
+
if (!Array.isArray(arr))
|
|
270
|
+
return [];
|
|
271
|
+
if (typeof fn === "function")
|
|
272
|
+
return arr.flatMap(fn);
|
|
273
|
+
return arr;
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
initializeBuiltInFunctions();
|
|
277
|
+
registerFunctionLibrary(registerFunction, (name) => name in FUNCTIONS);
|
|
278
|
+
class Tokenizer {
|
|
279
|
+
expression;
|
|
280
|
+
position = 0;
|
|
281
|
+
current;
|
|
282
|
+
constructor(expression) {
|
|
283
|
+
this.expression = expression;
|
|
284
|
+
this.current = expression[0] || "";
|
|
285
|
+
}
|
|
286
|
+
advance() {
|
|
287
|
+
this.position++;
|
|
288
|
+
this.current =
|
|
289
|
+
this.position < this.expression.length
|
|
290
|
+
? this.expression[this.position]
|
|
291
|
+
: "";
|
|
292
|
+
}
|
|
293
|
+
peek(offset = 1) {
|
|
294
|
+
const pos = this.position + offset;
|
|
295
|
+
return pos < this.expression.length ? this.expression[pos] : "";
|
|
296
|
+
}
|
|
297
|
+
skipWhitespace() {
|
|
298
|
+
while (this.current && /\s/.test(this.current)) {
|
|
299
|
+
this.advance();
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
readNumber() {
|
|
303
|
+
const start = this.position;
|
|
304
|
+
let value = "";
|
|
305
|
+
while (this.current && /[\d.]/.test(this.current)) {
|
|
306
|
+
value += this.current;
|
|
307
|
+
this.advance();
|
|
308
|
+
}
|
|
309
|
+
return {
|
|
310
|
+
type: TokenType.NUMBER,
|
|
311
|
+
value: Number.parseFloat(value),
|
|
312
|
+
position: start,
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
readString(quote) {
|
|
316
|
+
const start = this.position;
|
|
317
|
+
let value = "";
|
|
318
|
+
this.advance();
|
|
319
|
+
while (this.current && this.current !== quote) {
|
|
320
|
+
if (this.current === "\\") {
|
|
321
|
+
this.advance();
|
|
322
|
+
const ch = this.current;
|
|
323
|
+
if (ch === "n") {
|
|
324
|
+
value += "\n";
|
|
325
|
+
}
|
|
326
|
+
else if (ch === "t") {
|
|
327
|
+
value += "\t";
|
|
328
|
+
}
|
|
329
|
+
else if (ch === "r") {
|
|
330
|
+
value += "\r";
|
|
331
|
+
}
|
|
332
|
+
else if (ch === "\\") {
|
|
333
|
+
value += "\\";
|
|
334
|
+
}
|
|
335
|
+
else if (ch === quote) {
|
|
336
|
+
value += quote;
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
value += ch;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
value += this.current;
|
|
344
|
+
}
|
|
345
|
+
this.advance();
|
|
346
|
+
}
|
|
347
|
+
if (this.current === quote) {
|
|
348
|
+
this.advance();
|
|
349
|
+
}
|
|
350
|
+
return {
|
|
351
|
+
type: TokenType.STRING,
|
|
352
|
+
value,
|
|
353
|
+
position: start,
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
readIdentifier() {
|
|
357
|
+
const start = this.position;
|
|
358
|
+
let value = "";
|
|
359
|
+
while (this.current && /[a-zA-Z0-9_.]/.test(this.current)) {
|
|
360
|
+
value += this.current;
|
|
361
|
+
this.advance();
|
|
362
|
+
}
|
|
363
|
+
if (value === "true") {
|
|
364
|
+
return { type: TokenType.BOOLEAN, value: true, position: start };
|
|
365
|
+
}
|
|
366
|
+
if (value === "false") {
|
|
367
|
+
return { type: TokenType.BOOLEAN, value: false, position: start };
|
|
368
|
+
}
|
|
369
|
+
if (value === "null") {
|
|
370
|
+
return { type: TokenType.NULL, value: null, position: start };
|
|
371
|
+
}
|
|
372
|
+
return {
|
|
373
|
+
type: TokenType.IDENTIFIER,
|
|
374
|
+
value,
|
|
375
|
+
position: start,
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
readOperator() {
|
|
379
|
+
const start = this.position;
|
|
380
|
+
const threeChar = this.current + this.peek() + this.peek(2);
|
|
381
|
+
if (["===", "!=="].includes(threeChar)) {
|
|
382
|
+
this.advance();
|
|
383
|
+
this.advance();
|
|
384
|
+
this.advance();
|
|
385
|
+
return {
|
|
386
|
+
type: TokenType.OPERATOR,
|
|
387
|
+
value: threeChar,
|
|
388
|
+
position: start,
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
if (this.current === "=" && this.peek() === ">") {
|
|
392
|
+
this.advance();
|
|
393
|
+
this.advance();
|
|
394
|
+
return { type: TokenType.ARROW, value: "=>", position: start };
|
|
395
|
+
}
|
|
396
|
+
const twoChar = this.current + this.peek();
|
|
397
|
+
if (["==", "!=", "<=", ">=", "&&", "||", "**"].includes(twoChar)) {
|
|
398
|
+
this.advance();
|
|
399
|
+
this.advance();
|
|
400
|
+
return {
|
|
401
|
+
type: TokenType.OPERATOR,
|
|
402
|
+
value: twoChar,
|
|
403
|
+
position: start,
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
if (this.current === ".") {
|
|
407
|
+
this.advance();
|
|
408
|
+
return { type: TokenType.DOT, value: ".", position: start };
|
|
409
|
+
}
|
|
410
|
+
if (this.current === "[") {
|
|
411
|
+
this.advance();
|
|
412
|
+
return { type: TokenType.LBRACKET, value: "[", position: start };
|
|
413
|
+
}
|
|
414
|
+
if (this.current === "]") {
|
|
415
|
+
this.advance();
|
|
416
|
+
return { type: TokenType.RBRACKET, value: "]", position: start };
|
|
417
|
+
}
|
|
418
|
+
const oneChar = this.current;
|
|
419
|
+
this.advance();
|
|
420
|
+
return {
|
|
421
|
+
type: TokenType.OPERATOR,
|
|
422
|
+
value: oneChar,
|
|
423
|
+
position: start,
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
nextToken() {
|
|
427
|
+
this.skipWhitespace();
|
|
428
|
+
if (!this.current) {
|
|
429
|
+
return { type: TokenType.EOF, value: null, position: this.position };
|
|
430
|
+
}
|
|
431
|
+
if (/\d/.test(this.current)) {
|
|
432
|
+
return this.readNumber();
|
|
433
|
+
}
|
|
434
|
+
if (this.current === '"' || this.current === "'") {
|
|
435
|
+
return this.readString(this.current);
|
|
436
|
+
}
|
|
437
|
+
if (/[a-zA-Z_]/.test(this.current)) {
|
|
438
|
+
return this.readIdentifier();
|
|
439
|
+
}
|
|
440
|
+
if (this.current === "(") {
|
|
441
|
+
const token = {
|
|
442
|
+
type: TokenType.LPAREN,
|
|
443
|
+
value: "(",
|
|
444
|
+
position: this.position,
|
|
445
|
+
};
|
|
446
|
+
this.advance();
|
|
447
|
+
return token;
|
|
448
|
+
}
|
|
449
|
+
if (this.current === ")") {
|
|
450
|
+
const token = {
|
|
451
|
+
type: TokenType.RPAREN,
|
|
452
|
+
value: ")",
|
|
453
|
+
position: this.position,
|
|
454
|
+
};
|
|
455
|
+
this.advance();
|
|
456
|
+
return token;
|
|
457
|
+
}
|
|
458
|
+
if (this.current === ",") {
|
|
459
|
+
const token = {
|
|
460
|
+
type: TokenType.COMMA,
|
|
461
|
+
value: ",",
|
|
462
|
+
position: this.position,
|
|
463
|
+
};
|
|
464
|
+
this.advance();
|
|
465
|
+
return token;
|
|
466
|
+
}
|
|
467
|
+
if ("+-*/%<>=!&|".includes(this.current)) {
|
|
468
|
+
return this.readOperator();
|
|
469
|
+
}
|
|
470
|
+
throw new Error(`Unexpected character '${this.current}' at position ${this.position}`);
|
|
471
|
+
}
|
|
472
|
+
tokenize() {
|
|
473
|
+
const tokens = [];
|
|
474
|
+
let token = this.nextToken();
|
|
475
|
+
while (token.type !== TokenType.EOF) {
|
|
476
|
+
tokens.push(token);
|
|
477
|
+
token = this.nextToken();
|
|
478
|
+
}
|
|
479
|
+
tokens.push(token);
|
|
480
|
+
return tokens;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
const TOKEN_CACHE_MAX_SIZE = 2000;
|
|
484
|
+
const TOKEN_CACHE_MAX_EXPRESSION_LENGTH = 4000;
|
|
485
|
+
const tokenCache = new Map();
|
|
486
|
+
function tokenizeCached(expression) {
|
|
487
|
+
if (expression.length > TOKEN_CACHE_MAX_EXPRESSION_LENGTH) {
|
|
488
|
+
return new Tokenizer(expression).tokenize();
|
|
489
|
+
}
|
|
490
|
+
const cached = tokenCache.get(expression);
|
|
491
|
+
if (cached)
|
|
492
|
+
return cached;
|
|
493
|
+
const tokens = new Tokenizer(expression).tokenize();
|
|
494
|
+
if (tokenCache.size >= TOKEN_CACHE_MAX_SIZE) {
|
|
495
|
+
const oldest = tokenCache.keys().next().value;
|
|
496
|
+
if (oldest !== undefined)
|
|
497
|
+
tokenCache.delete(oldest);
|
|
498
|
+
}
|
|
499
|
+
tokenCache.set(expression, tokens);
|
|
500
|
+
return tokens;
|
|
501
|
+
}
|
|
502
|
+
export function clearExpressionCache() {
|
|
503
|
+
tokenCache.clear();
|
|
504
|
+
}
|
|
505
|
+
export function getExpressionCacheStats() {
|
|
506
|
+
return { size: tokenCache.size, maxSize: TOKEN_CACHE_MAX_SIZE };
|
|
507
|
+
}
|
|
508
|
+
class ExpressionParser {
|
|
509
|
+
tokens;
|
|
510
|
+
position = 0;
|
|
511
|
+
context;
|
|
512
|
+
constructor(tokens, context) {
|
|
513
|
+
this.tokens = tokens;
|
|
514
|
+
this.context = context;
|
|
515
|
+
}
|
|
516
|
+
currentToken() {
|
|
517
|
+
return (this.tokens[this.position] || {
|
|
518
|
+
type: TokenType.EOF,
|
|
519
|
+
value: null,
|
|
520
|
+
position: -1,
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
advance() {
|
|
524
|
+
this.position++;
|
|
525
|
+
}
|
|
526
|
+
tryParseLambda() {
|
|
527
|
+
const saved = this.position;
|
|
528
|
+
const paramNames = [];
|
|
529
|
+
if (this.currentToken().type === TokenType.LPAREN) {
|
|
530
|
+
this.advance();
|
|
531
|
+
while (this.currentToken().type === TokenType.IDENTIFIER) {
|
|
532
|
+
paramNames.push(this.currentToken().value);
|
|
533
|
+
this.advance();
|
|
534
|
+
if (this.currentToken().type === TokenType.COMMA) {
|
|
535
|
+
this.advance();
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
if (this.currentToken().type !== TokenType.RPAREN) {
|
|
539
|
+
this.position = saved;
|
|
540
|
+
return null;
|
|
541
|
+
}
|
|
542
|
+
this.advance();
|
|
543
|
+
}
|
|
544
|
+
else if (this.currentToken().type === TokenType.IDENTIFIER) {
|
|
545
|
+
paramNames.push(this.currentToken().value);
|
|
546
|
+
this.advance();
|
|
547
|
+
}
|
|
548
|
+
else {
|
|
549
|
+
return null;
|
|
550
|
+
}
|
|
551
|
+
if (this.currentToken().type !== TokenType.ARROW) {
|
|
552
|
+
this.position = saved;
|
|
553
|
+
return null;
|
|
554
|
+
}
|
|
555
|
+
this.advance();
|
|
556
|
+
const bodyStart = this.position;
|
|
557
|
+
this.parseExpression(true, true, true);
|
|
558
|
+
const bodyEnd = this.position;
|
|
559
|
+
const lambda = (...args) => {
|
|
560
|
+
const paramContext = { ...this.context };
|
|
561
|
+
for (let i = 0; i < paramNames.length; i++) {
|
|
562
|
+
paramContext[paramNames[i]] = args[i];
|
|
563
|
+
}
|
|
564
|
+
const bodyTokens = this.tokens.slice(bodyStart, bodyEnd);
|
|
565
|
+
const parser = new ExpressionParser(bodyTokens, paramContext);
|
|
566
|
+
return parser.parse();
|
|
567
|
+
};
|
|
568
|
+
return lambda;
|
|
569
|
+
}
|
|
570
|
+
parseExpression(stopAtComma = false, stopAtRParen = false, stopAtRBracket = false) {
|
|
571
|
+
const outputQueue = [];
|
|
572
|
+
const operatorStack = [];
|
|
573
|
+
let expectOperand = true;
|
|
574
|
+
while (this.currentToken().type !== TokenType.EOF &&
|
|
575
|
+
!(stopAtComma && this.currentToken().type === TokenType.COMMA) &&
|
|
576
|
+
!(stopAtRParen && this.currentToken().type === TokenType.RPAREN) &&
|
|
577
|
+
!(stopAtRBracket && this.currentToken().type === TokenType.RBRACKET)) {
|
|
578
|
+
const token = this.currentToken();
|
|
579
|
+
if (token.type === TokenType.NUMBER ||
|
|
580
|
+
token.type === TokenType.STRING ||
|
|
581
|
+
token.type === TokenType.BOOLEAN ||
|
|
582
|
+
token.type === TokenType.NULL) {
|
|
583
|
+
outputQueue.push(token.value);
|
|
584
|
+
this.advance();
|
|
585
|
+
expectOperand = false;
|
|
586
|
+
}
|
|
587
|
+
else if (token.type === TokenType.IDENTIFIER) {
|
|
588
|
+
if (expectOperand) {
|
|
589
|
+
const lambda = this.tryParseLambda();
|
|
590
|
+
if (lambda) {
|
|
591
|
+
outputQueue.push(lambda);
|
|
592
|
+
expectOperand = false;
|
|
593
|
+
continue;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
this.advance();
|
|
597
|
+
if (this.currentToken().type === TokenType.LPAREN) {
|
|
598
|
+
const funcName = token.value;
|
|
599
|
+
this.advance();
|
|
600
|
+
const args = [];
|
|
601
|
+
if (this.currentToken().type !== TokenType.RPAREN) {
|
|
602
|
+
const lambda = this.tryParseLambda();
|
|
603
|
+
if (lambda) {
|
|
604
|
+
args.push(lambda);
|
|
605
|
+
}
|
|
606
|
+
else {
|
|
607
|
+
args.push(this.parseExpression(true, true, false));
|
|
608
|
+
}
|
|
609
|
+
while (this.currentToken().type === TokenType.COMMA) {
|
|
610
|
+
this.advance();
|
|
611
|
+
const lambdaArg = this.tryParseLambda();
|
|
612
|
+
if (lambdaArg) {
|
|
613
|
+
args.push(lambdaArg);
|
|
614
|
+
}
|
|
615
|
+
else {
|
|
616
|
+
args.push(this.parseExpression(true, true, false));
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
if (this.currentToken().type !== TokenType.RPAREN) {
|
|
621
|
+
throw new Error(`Expected ')' after function arguments`);
|
|
622
|
+
}
|
|
623
|
+
this.advance();
|
|
624
|
+
const func = FUNCTIONS[funcName];
|
|
625
|
+
if (!func) {
|
|
626
|
+
throw new Error(`Unknown function: ${funcName}`);
|
|
627
|
+
}
|
|
628
|
+
const result = func(...args);
|
|
629
|
+
outputQueue.push(result);
|
|
630
|
+
while (this.currentToken().type === TokenType.DOT) {
|
|
631
|
+
this.advance();
|
|
632
|
+
if (this.currentToken().type !== TokenType.IDENTIFIER) {
|
|
633
|
+
throw new Error(`Expected method name after '.'`);
|
|
634
|
+
}
|
|
635
|
+
const methodName = this.currentToken().value;
|
|
636
|
+
this.advance();
|
|
637
|
+
if (this.currentToken().type !== TokenType.LPAREN) {
|
|
638
|
+
throw new Error(`Expected '(' after method name '${methodName}'`);
|
|
639
|
+
}
|
|
640
|
+
this.advance();
|
|
641
|
+
const methodArgs = [outputQueue.pop()];
|
|
642
|
+
if (this.currentToken().type !== TokenType.RPAREN) {
|
|
643
|
+
const lambdaArg = this.tryParseLambda();
|
|
644
|
+
if (lambdaArg) {
|
|
645
|
+
methodArgs.push(lambdaArg);
|
|
646
|
+
}
|
|
647
|
+
else {
|
|
648
|
+
methodArgs.push(this.parseExpression(true, true, false));
|
|
649
|
+
}
|
|
650
|
+
while (this.currentToken().type === TokenType.COMMA) {
|
|
651
|
+
this.advance();
|
|
652
|
+
const la = this.tryParseLambda();
|
|
653
|
+
if (la) {
|
|
654
|
+
methodArgs.push(la);
|
|
655
|
+
}
|
|
656
|
+
else {
|
|
657
|
+
methodArgs.push(this.parseExpression(true, true, false));
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
if (this.currentToken().type !== TokenType.RPAREN) {
|
|
662
|
+
throw new Error(`Expected ')' after method arguments`);
|
|
663
|
+
}
|
|
664
|
+
this.advance();
|
|
665
|
+
const method = FUNCTIONS[methodName];
|
|
666
|
+
if (!method) {
|
|
667
|
+
throw new Error(`Unknown function: ${methodName}`);
|
|
668
|
+
}
|
|
669
|
+
outputQueue.push(method(...methodArgs));
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
else {
|
|
673
|
+
let value = getNestedValue(this.context, token.value);
|
|
674
|
+
while (this.currentToken().type === TokenType.DOT) {
|
|
675
|
+
this.advance();
|
|
676
|
+
if (this.currentToken().type !== TokenType.IDENTIFIER) {
|
|
677
|
+
throw new Error(`Expected method name after '.'`);
|
|
678
|
+
}
|
|
679
|
+
const methodName = this.currentToken().value;
|
|
680
|
+
this.advance();
|
|
681
|
+
if (this.currentToken().type !== TokenType.LPAREN) {
|
|
682
|
+
value = getNestedValue(value ?? {}, methodName);
|
|
683
|
+
continue;
|
|
684
|
+
}
|
|
685
|
+
this.advance();
|
|
686
|
+
const methodArgs = [value];
|
|
687
|
+
if (this.currentToken().type !== TokenType.RPAREN) {
|
|
688
|
+
const lambdaArg = this.tryParseLambda();
|
|
689
|
+
if (lambdaArg) {
|
|
690
|
+
methodArgs.push(lambdaArg);
|
|
691
|
+
}
|
|
692
|
+
else {
|
|
693
|
+
methodArgs.push(this.parseExpression(true, true, false));
|
|
694
|
+
}
|
|
695
|
+
while (this.currentToken().type === TokenType.COMMA) {
|
|
696
|
+
this.advance();
|
|
697
|
+
const la = this.tryParseLambda();
|
|
698
|
+
if (la) {
|
|
699
|
+
methodArgs.push(la);
|
|
700
|
+
}
|
|
701
|
+
else {
|
|
702
|
+
methodArgs.push(this.parseExpression(true, true, false));
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
if (this.currentToken().type !== TokenType.RPAREN) {
|
|
707
|
+
throw new Error(`Expected ')' after method arguments`);
|
|
708
|
+
}
|
|
709
|
+
this.advance();
|
|
710
|
+
const method = FUNCTIONS[methodName];
|
|
711
|
+
if (!method) {
|
|
712
|
+
throw new Error(`Unknown function: ${methodName}`);
|
|
713
|
+
}
|
|
714
|
+
value = method(...methodArgs);
|
|
715
|
+
}
|
|
716
|
+
outputQueue.push(value);
|
|
717
|
+
}
|
|
718
|
+
expectOperand = false;
|
|
719
|
+
}
|
|
720
|
+
else if (token.type === TokenType.OPERATOR) {
|
|
721
|
+
let op = token.value;
|
|
722
|
+
if (op === "-" && expectOperand) {
|
|
723
|
+
op = "u-";
|
|
724
|
+
}
|
|
725
|
+
const opDef = OPERATORS[op];
|
|
726
|
+
if (!opDef) {
|
|
727
|
+
throw new Error(`Unknown operator: ${op}`);
|
|
728
|
+
}
|
|
729
|
+
if (op === "|") {
|
|
730
|
+
while (operatorStack.length > 0) {
|
|
731
|
+
const topToken = operatorStack[operatorStack.length - 1];
|
|
732
|
+
if (topToken.type !== TokenType.OPERATOR)
|
|
733
|
+
break;
|
|
734
|
+
const topOp = OPERATORS[topToken.value];
|
|
735
|
+
if (!topOp)
|
|
736
|
+
break;
|
|
737
|
+
if (topOp.precedence <= opDef.precedence)
|
|
738
|
+
break;
|
|
739
|
+
outputQueue.push(operatorStack.pop());
|
|
740
|
+
}
|
|
741
|
+
const leftValue = this.evaluateRPN([...outputQueue]);
|
|
742
|
+
outputQueue.length = 0;
|
|
743
|
+
operatorStack.length = 0;
|
|
744
|
+
this.advance();
|
|
745
|
+
const rightValue = this.parseExpression(true, true, false);
|
|
746
|
+
if (typeof rightValue === "function") {
|
|
747
|
+
outputQueue.push(rightValue(leftValue));
|
|
748
|
+
}
|
|
749
|
+
else {
|
|
750
|
+
throw new Error("Pipe operator expects a function on the right side");
|
|
751
|
+
}
|
|
752
|
+
expectOperand = false;
|
|
753
|
+
continue;
|
|
754
|
+
}
|
|
755
|
+
if (opDef.unary) {
|
|
756
|
+
operatorStack.push({ ...token, value: op });
|
|
757
|
+
this.advance();
|
|
758
|
+
expectOperand = true;
|
|
759
|
+
continue;
|
|
760
|
+
}
|
|
761
|
+
while (operatorStack.length > 0) {
|
|
762
|
+
const topToken = operatorStack[operatorStack.length - 1];
|
|
763
|
+
if (topToken.type !== TokenType.OPERATOR)
|
|
764
|
+
break;
|
|
765
|
+
const topOp = OPERATORS[topToken.value];
|
|
766
|
+
if (!topOp)
|
|
767
|
+
break;
|
|
768
|
+
const shouldPop = (opDef.associativity === "left" &&
|
|
769
|
+
opDef.precedence <= topOp.precedence) ||
|
|
770
|
+
(opDef.associativity === "right" &&
|
|
771
|
+
opDef.precedence < topOp.precedence);
|
|
772
|
+
if (!shouldPop)
|
|
773
|
+
break;
|
|
774
|
+
outputQueue.push(operatorStack.pop());
|
|
775
|
+
}
|
|
776
|
+
operatorStack.push({ ...token, value: op });
|
|
777
|
+
this.advance();
|
|
778
|
+
expectOperand = true;
|
|
779
|
+
}
|
|
780
|
+
else if (token.type === TokenType.LPAREN) {
|
|
781
|
+
operatorStack.push(token);
|
|
782
|
+
this.advance();
|
|
783
|
+
expectOperand = true;
|
|
784
|
+
}
|
|
785
|
+
else if (token.type === TokenType.RPAREN) {
|
|
786
|
+
while (operatorStack.length > 0 &&
|
|
787
|
+
operatorStack[operatorStack.length - 1].type !== TokenType.LPAREN) {
|
|
788
|
+
outputQueue.push(operatorStack.pop());
|
|
789
|
+
}
|
|
790
|
+
if (operatorStack.length === 0 ||
|
|
791
|
+
operatorStack[operatorStack.length - 1].type !== TokenType.LPAREN) {
|
|
792
|
+
throw new Error("Mismatched parentheses");
|
|
793
|
+
}
|
|
794
|
+
operatorStack.pop();
|
|
795
|
+
this.advance();
|
|
796
|
+
expectOperand = false;
|
|
797
|
+
}
|
|
798
|
+
else if (token.type === TokenType.LBRACKET) {
|
|
799
|
+
this.advance();
|
|
800
|
+
const elements = [];
|
|
801
|
+
if (this.currentToken().type !== TokenType.RBRACKET) {
|
|
802
|
+
elements.push(this.parseExpression(true, false, true));
|
|
803
|
+
while (this.currentToken().type === TokenType.COMMA) {
|
|
804
|
+
this.advance();
|
|
805
|
+
elements.push(this.parseExpression(true, false, true));
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
if (this.currentToken().type !== TokenType.RBRACKET) {
|
|
809
|
+
throw new Error(`Expected ']' after array elements`);
|
|
810
|
+
}
|
|
811
|
+
this.advance();
|
|
812
|
+
outputQueue.push(elements);
|
|
813
|
+
expectOperand = false;
|
|
814
|
+
}
|
|
815
|
+
else if (token.type === TokenType.RBRACKET) {
|
|
816
|
+
break;
|
|
817
|
+
}
|
|
818
|
+
else if (token.type === TokenType.ARROW) {
|
|
819
|
+
throw new Error(`Unexpected '=>' — arrow operator must follow a parameter`);
|
|
820
|
+
}
|
|
821
|
+
else {
|
|
822
|
+
throw new Error(`Unexpected token: ${token.type}`);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
while (operatorStack.length > 0) {
|
|
826
|
+
const token = operatorStack.pop();
|
|
827
|
+
if (token.type === TokenType.LPAREN || token.type === TokenType.RPAREN) {
|
|
828
|
+
throw new Error("Mismatched parentheses");
|
|
829
|
+
}
|
|
830
|
+
outputQueue.push(token);
|
|
831
|
+
}
|
|
832
|
+
return this.evaluateRPN(outputQueue);
|
|
833
|
+
}
|
|
834
|
+
evaluateRPN(queue) {
|
|
835
|
+
const stack = [];
|
|
836
|
+
for (const item of queue) {
|
|
837
|
+
if (item &&
|
|
838
|
+
typeof item === "object" &&
|
|
839
|
+
item.type === TokenType.OPERATOR) {
|
|
840
|
+
const opDef = OPERATORS[item.value];
|
|
841
|
+
if (opDef.unary) {
|
|
842
|
+
if (stack.length < 1) {
|
|
843
|
+
throw new Error(`Not enough operands for unary operator ${item.value}`);
|
|
844
|
+
}
|
|
845
|
+
const operand = stack.pop();
|
|
846
|
+
stack.push(opDef.fn(operand));
|
|
847
|
+
}
|
|
848
|
+
else {
|
|
849
|
+
if (stack.length < 2) {
|
|
850
|
+
throw new Error(`Not enough operands for operator ${item.value}`);
|
|
851
|
+
}
|
|
852
|
+
const right = stack.pop();
|
|
853
|
+
const left = stack.pop();
|
|
854
|
+
stack.push(opDef.fn(left, right));
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
else {
|
|
858
|
+
stack.push(item);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
if (stack.length !== 1) {
|
|
862
|
+
throw new Error("Invalid expression");
|
|
863
|
+
}
|
|
864
|
+
return stack[0];
|
|
865
|
+
}
|
|
866
|
+
parse() {
|
|
867
|
+
return this.parseExpression();
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
export function evaluate(expression, context = {}) {
|
|
871
|
+
const startTime = Date.now();
|
|
872
|
+
try {
|
|
873
|
+
const tokens = tokenizeCached(expression);
|
|
874
|
+
const parser = new ExpressionParser(tokens, context);
|
|
875
|
+
const result = parser.parse();
|
|
876
|
+
if (traceEnabled) {
|
|
877
|
+
expressionTraces.push({
|
|
878
|
+
expression,
|
|
879
|
+
result,
|
|
880
|
+
context: { ...context },
|
|
881
|
+
duration: Date.now() - startTime,
|
|
882
|
+
});
|
|
883
|
+
}
|
|
884
|
+
return result;
|
|
885
|
+
}
|
|
886
|
+
catch (error) {
|
|
887
|
+
Logger.error("system", "expression", `Error evaluating expression: ${expression}`, error instanceof Error ? error.stack : String(error));
|
|
888
|
+
throw error;
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
export function getNestedValue(obj, path) {
|
|
892
|
+
const parts = path.split(".");
|
|
893
|
+
let current = obj;
|
|
894
|
+
for (const part of parts) {
|
|
895
|
+
if (current === null || current === undefined) {
|
|
896
|
+
return undefined;
|
|
897
|
+
}
|
|
898
|
+
const arrayMatch = part.match(/^(\w+)\[(\d+)\]$/);
|
|
899
|
+
if (arrayMatch) {
|
|
900
|
+
current = current[arrayMatch[1]];
|
|
901
|
+
if (Array.isArray(current)) {
|
|
902
|
+
current = current[Number.parseInt(arrayMatch[2], 10)];
|
|
903
|
+
}
|
|
904
|
+
else {
|
|
905
|
+
return undefined;
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
else {
|
|
909
|
+
current = current[part];
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
return current;
|
|
913
|
+
}
|
|
914
|
+
export function evaluateCondition(expression, context) {
|
|
915
|
+
try {
|
|
916
|
+
return Boolean(evaluate(expression, context));
|
|
917
|
+
}
|
|
918
|
+
catch (error) {
|
|
919
|
+
Logger.error("system", "expression", `Error evaluating expression: ${expression}`, error instanceof Error ? error.stack : String(error));
|
|
920
|
+
return false;
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
export function validateExpression(expression) {
|
|
924
|
+
try {
|
|
925
|
+
const dangerousPatterns = [
|
|
926
|
+
/\beval\b/,
|
|
927
|
+
/\bFunction\b/,
|
|
928
|
+
/\bimport\b/,
|
|
929
|
+
/\brequire\b/,
|
|
930
|
+
/\bprocess\b/,
|
|
931
|
+
/\bglobal\b/,
|
|
932
|
+
/\bwindow\b/,
|
|
933
|
+
/\bdocument\b/,
|
|
934
|
+
];
|
|
935
|
+
for (const pattern of dangerousPatterns) {
|
|
936
|
+
if (pattern.test(expression)) {
|
|
937
|
+
return {
|
|
938
|
+
valid: false,
|
|
939
|
+
error: "Expression contains forbidden patterns",
|
|
940
|
+
};
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
const tokens = tokenizeCached(expression);
|
|
944
|
+
const parser = new ExpressionParser(tokens, {});
|
|
945
|
+
parser.parse();
|
|
946
|
+
return { valid: true };
|
|
947
|
+
}
|
|
948
|
+
catch (error) {
|
|
949
|
+
const msg = error instanceof Error ? error.message : "Unknown error";
|
|
950
|
+
if (msg.startsWith("Unknown function: ") && expression.includes("=>")) {
|
|
951
|
+
return { valid: true };
|
|
952
|
+
}
|
|
953
|
+
return {
|
|
954
|
+
valid: false,
|
|
955
|
+
error: msg,
|
|
956
|
+
};
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
export function resolveConditionalNext(conditionalNext, defaultNext, context) {
|
|
960
|
+
for (const branch of conditionalNext) {
|
|
961
|
+
if (evaluateCondition(branch.condition, context)) {
|
|
962
|
+
Logger.debug("system", "expression", `Condition matched: ${branch.condition} -> ${branch.target}`);
|
|
963
|
+
return branch.target;
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
if (defaultNext) {
|
|
967
|
+
Logger.debug("system", "expression", `Using default branch: ${defaultNext}`);
|
|
968
|
+
return defaultNext;
|
|
969
|
+
}
|
|
970
|
+
return null;
|
|
971
|
+
}
|
|
972
|
+
export function resolveNodeOutput(nodeId, path, state) {
|
|
973
|
+
if (!state?.nodes?.[nodeId]) {
|
|
974
|
+
Logger.warn("system", "expression", `Node output not found: ${nodeId}`);
|
|
975
|
+
return undefined;
|
|
976
|
+
}
|
|
977
|
+
const nodeState = state.nodes[nodeId];
|
|
978
|
+
if (nodeState.output === undefined) {
|
|
979
|
+
Logger.warn("system", "expression", `Node ${nodeId} has no output`);
|
|
980
|
+
return undefined;
|
|
981
|
+
}
|
|
982
|
+
if (!path) {
|
|
983
|
+
return nodeState.output;
|
|
984
|
+
}
|
|
985
|
+
if (typeof nodeState.output === "object" && nodeState.output !== null) {
|
|
986
|
+
return getNestedValue(nodeState.output, path);
|
|
987
|
+
}
|
|
988
|
+
Logger.warn("system", "expression", `Cannot access path ${path} on non-object output of node ${nodeId}`);
|
|
989
|
+
return undefined;
|
|
990
|
+
}
|
|
991
|
+
const NODE_OUTPUT_PATTERN = /\$\{(\w+)\.output(?:\.([\w.]+))?\}/g;
|
|
992
|
+
const CONTEXT_PATTERN = /\$\{([\w.]+)\}/g;
|
|
993
|
+
export function interpolateExpressions(template, context, state) {
|
|
994
|
+
let result = template.replace(NODE_OUTPUT_PATTERN, (match, nodeId, path) => {
|
|
995
|
+
const value = resolveNodeOutput(nodeId, path, state);
|
|
996
|
+
return value !== undefined ? String(value) : match;
|
|
997
|
+
});
|
|
998
|
+
result = result.replace(CONTEXT_PATTERN, (match, path) => {
|
|
999
|
+
if (path.includes(".output")) {
|
|
1000
|
+
return match;
|
|
1001
|
+
}
|
|
1002
|
+
const value = getNestedValue(context, path);
|
|
1003
|
+
return value !== undefined ? String(value) : match;
|
|
1004
|
+
});
|
|
1005
|
+
return result;
|
|
1006
|
+
}
|
|
1007
|
+
export const MAX_INTERPOLATION_DEPTH = 100;
|
|
1008
|
+
export class InterpolationDepthError extends Error {
|
|
1009
|
+
constructor(message) {
|
|
1010
|
+
super(message);
|
|
1011
|
+
this.name = "InterpolationDepthError";
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
export function interpolateObject(obj, context, state) {
|
|
1015
|
+
return interpolateObjectInternal(obj, context, state, 0, new WeakSet());
|
|
1016
|
+
}
|
|
1017
|
+
function interpolateObjectInternal(obj, context, state, depth, seen) {
|
|
1018
|
+
if (typeof obj === "string") {
|
|
1019
|
+
return interpolateExpressions(obj, context, state);
|
|
1020
|
+
}
|
|
1021
|
+
if (obj === null || typeof obj !== "object") {
|
|
1022
|
+
return obj;
|
|
1023
|
+
}
|
|
1024
|
+
if (depth >= MAX_INTERPOLATION_DEPTH) {
|
|
1025
|
+
throw new InterpolationDepthError(`Interpolation exceeded maximum depth of ${MAX_INTERPOLATION_DEPTH}; ` +
|
|
1026
|
+
"the value is nested too deeply or contains a cycle");
|
|
1027
|
+
}
|
|
1028
|
+
if (seen.has(obj)) {
|
|
1029
|
+
throw new InterpolationDepthError("Interpolation encountered a circular reference");
|
|
1030
|
+
}
|
|
1031
|
+
seen.add(obj);
|
|
1032
|
+
try {
|
|
1033
|
+
if (Array.isArray(obj)) {
|
|
1034
|
+
return obj.map((item) => interpolateObjectInternal(item, context, state, depth + 1, seen));
|
|
1035
|
+
}
|
|
1036
|
+
const result = {};
|
|
1037
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
1038
|
+
result[key] = interpolateObjectInternal(value, context, state, depth + 1, seen);
|
|
1039
|
+
}
|
|
1040
|
+
return result;
|
|
1041
|
+
}
|
|
1042
|
+
finally {
|
|
1043
|
+
seen.delete(obj);
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
//# sourceMappingURL=ExpressionEvaluator.js.map
|