@pikku/core 0.11.2 → 0.12.1
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/CHANGELOG.md +57 -2
- package/dist/crypto-utils.d.ts +2 -0
- package/dist/crypto-utils.js +78 -0
- package/dist/errors/errors.d.ts +14 -0
- package/dist/errors/errors.js +26 -0
- package/dist/errors/index.d.ts +1 -1
- package/dist/errors/index.js +1 -1
- package/dist/function/function-runner.d.ts +10 -4
- package/dist/function/function-runner.js +126 -45
- package/dist/function/functions.types.d.ts +32 -87
- package/dist/function/functions.types.js +16 -46
- package/dist/function/index.d.ts +2 -2
- package/dist/function/index.js +1 -2
- package/dist/handle-error.d.ts +2 -2
- package/dist/handle-error.js +3 -12
- package/dist/index.d.ts +30 -26
- package/dist/index.js +19 -29
- package/dist/internal.d.ts +3 -0
- package/dist/internal.js +2 -0
- package/dist/middleware/auth-apikey.d.ts +2 -2
- package/dist/middleware/auth-apikey.js +3 -3
- package/dist/middleware/auth-bearer.d.ts +3 -3
- package/dist/middleware/auth-bearer.js +4 -7
- package/dist/middleware/auth-cookie.d.ts +4 -4
- package/dist/middleware/auth-cookie.js +7 -9
- package/dist/middleware/cors.d.ts +46 -0
- package/dist/middleware/cors.js +81 -0
- package/dist/middleware/index.d.ts +5 -3
- package/dist/middleware/index.js +5 -3
- package/dist/middleware/remote-auth.d.ts +5 -0
- package/dist/middleware/remote-auth.js +55 -0
- package/dist/middleware/timeout.d.ts +2 -2
- package/dist/middleware-runner.d.ts +1 -1
- package/dist/middleware-runner.js +8 -10
- package/dist/permissions.d.ts +2 -2
- package/dist/permissions.js +11 -15
- package/dist/pikku-state.d.ts +10 -8
- package/dist/pikku-state.js +48 -25
- package/dist/schema.d.ts +4 -4
- package/dist/schema.js +20 -15
- package/dist/services/ai-agent-runner-service.d.ts +43 -0
- package/dist/services/ai-agent-runner-service.js +1 -0
- package/dist/services/ai-run-state-service.d.ts +13 -0
- package/dist/services/ai-run-state-service.js +1 -0
- package/dist/services/ai-storage-service.d.ts +18 -0
- package/dist/services/ai-storage-service.js +1 -0
- package/dist/services/content-service.d.ts +6 -0
- package/dist/services/deployment-service.d.ts +19 -0
- package/dist/services/deployment-service.js +1 -0
- package/dist/services/gopass-secrets.d.ts +47 -0
- package/dist/services/gopass-secrets.js +97 -0
- package/dist/services/in-memory-ai-run-state-service.d.ts +15 -0
- package/dist/services/in-memory-ai-run-state-service.js +44 -0
- package/dist/services/in-memory-trigger-service.d.ts +22 -0
- package/dist/services/in-memory-trigger-service.js +48 -0
- package/dist/services/in-memory-workflow-service.d.ts +59 -0
- package/dist/services/in-memory-workflow-service.js +287 -0
- package/dist/services/index.d.ts +26 -11
- package/dist/services/index.js +11 -13
- package/dist/services/local-content.d.ts +2 -1
- package/dist/services/local-content.js +6 -1
- package/dist/services/local-secrets.d.ts +25 -2
- package/dist/services/local-secrets.js +45 -0
- package/dist/services/local-variables.d.ts +6 -1
- package/dist/services/local-variables.js +18 -0
- package/dist/services/logger-console.d.ts +2 -1
- package/dist/services/scheduler-service.d.ts +9 -1
- package/dist/services/scheduler-service.js +8 -0
- package/dist/services/schema-service.d.ts +6 -0
- package/dist/services/scoped-secret-service.d.ts +16 -0
- package/dist/services/scoped-secret-service.js +35 -0
- package/dist/services/secret-service.d.ts +25 -4
- package/dist/services/trigger-service.d.ts +16 -0
- package/dist/services/trigger-service.js +1 -0
- package/dist/services/typed-secret-service.d.ts +30 -0
- package/dist/services/typed-secret-service.js +40 -0
- package/dist/services/typed-variables-service.d.ts +27 -0
- package/dist/services/typed-variables-service.js +46 -0
- package/dist/services/user-session-service.d.ts +15 -2
- package/dist/services/user-session-service.js +17 -0
- package/dist/services/variables-service.d.ts +5 -0
- package/dist/services/workflow-service.d.ts +9 -5
- package/dist/types/core.types.d.ts +67 -25
- package/dist/types/core.types.js +8 -1
- package/dist/types/state.types.d.ts +53 -59
- package/dist/utils.d.ts +7 -6
- package/dist/utils.js +27 -12
- package/dist/version.d.ts +6 -0
- package/dist/version.js +19 -0
- package/dist/wirings/ai-agent/ai-agent-assistant-ui.d.ts +5 -0
- package/dist/wirings/ai-agent/ai-agent-assistant-ui.js +146 -0
- package/dist/wirings/ai-agent/ai-agent-helpers.d.ts +28 -0
- package/dist/wirings/ai-agent/ai-agent-helpers.js +40 -0
- package/dist/wirings/ai-agent/ai-agent-memory.d.ts +29 -0
- package/dist/wirings/ai-agent/ai-agent-memory.js +199 -0
- package/dist/wirings/ai-agent/ai-agent-model-config.d.ts +9 -0
- package/dist/wirings/ai-agent/ai-agent-model-config.js +36 -0
- package/dist/wirings/ai-agent/ai-agent-prepare.d.ts +59 -0
- package/dist/wirings/ai-agent/ai-agent-prepare.js +348 -0
- package/dist/wirings/ai-agent/ai-agent-registry.d.ts +15 -0
- package/dist/wirings/ai-agent/ai-agent-registry.js +47 -0
- package/dist/wirings/ai-agent/ai-agent-runner.d.ts +3 -0
- package/dist/wirings/ai-agent/ai-agent-runner.js +195 -0
- package/dist/wirings/ai-agent/ai-agent-stream.d.ts +12 -0
- package/dist/wirings/ai-agent/ai-agent-stream.js +662 -0
- package/dist/wirings/ai-agent/ai-agent.types.d.ts +313 -0
- package/dist/wirings/ai-agent/ai-agent.types.js +1 -0
- package/dist/wirings/ai-agent/index.d.ts +7 -0
- package/dist/wirings/ai-agent/index.js +6 -0
- package/dist/wirings/channel/channel-common.d.ts +8 -5
- package/dist/wirings/channel/channel-common.js +15 -8
- package/dist/wirings/channel/channel-handler.d.ts +3 -3
- package/dist/wirings/channel/channel-handler.js +15 -6
- package/dist/wirings/channel/channel-middleware-runner.d.ts +9 -0
- package/dist/wirings/channel/channel-middleware-runner.js +73 -0
- package/dist/wirings/channel/channel-runner.d.ts +5 -5
- package/dist/wirings/channel/channel-runner.js +10 -9
- package/dist/wirings/channel/channel-store.d.ts +1 -1
- package/dist/wirings/channel/channel.types.d.ts +9 -7
- package/dist/wirings/channel/define-channel-routes.d.ts +21 -0
- package/dist/wirings/channel/define-channel-routes.js +23 -0
- package/dist/wirings/channel/index.d.ts +10 -8
- package/dist/wirings/channel/index.js +7 -8
- package/dist/wirings/channel/local/index.d.ts +3 -3
- package/dist/wirings/channel/local/index.js +3 -3
- package/dist/wirings/channel/local/local-channel-runner.d.ts +7 -2
- package/dist/wirings/channel/local/local-channel-runner.js +22 -9
- package/dist/wirings/channel/local/local-eventhub-service.d.ts +2 -2
- package/dist/wirings/channel/log-channels.d.ts +1 -1
- package/dist/wirings/channel/pikku-abstract-channel-handler.d.ts +1 -1
- package/dist/wirings/channel/serverless/index.d.ts +1 -1
- package/dist/wirings/channel/serverless/index.js +1 -1
- package/dist/wirings/channel/serverless/serverless-channel-runner.d.ts +4 -4
- package/dist/wirings/channel/serverless/serverless-channel-runner.js +40 -23
- package/dist/wirings/cli/channel/cli-channel-runner.d.ts +1 -1
- package/dist/wirings/cli/channel/index.d.ts +1 -1
- package/dist/wirings/cli/channel/index.js +1 -1
- package/dist/wirings/cli/cli-runner.d.ts +3 -3
- package/dist/wirings/cli/cli-runner.js +12 -8
- package/dist/wirings/cli/cli.types.d.ts +9 -9
- package/dist/wirings/cli/command-parser.d.ts +1 -1
- package/dist/wirings/cli/define-cli-commands.d.ts +19 -0
- package/dist/wirings/cli/define-cli-commands.js +20 -0
- package/dist/wirings/cli/index.d.ts +2 -3
- package/dist/wirings/cli/index.js +1 -3
- package/dist/wirings/http/http-routes.d.ts +69 -0
- package/dist/wirings/http/http-routes.js +139 -0
- package/dist/wirings/http/http-runner.d.ts +9 -9
- package/dist/wirings/http/http-runner.js +79 -34
- package/dist/wirings/http/http.types.d.ts +77 -41
- package/dist/wirings/http/index.d.ts +5 -4
- package/dist/wirings/http/index.js +4 -3
- package/dist/wirings/http/log-http-routes.d.ts +1 -1
- package/dist/wirings/http/pikku-fetch-http-request.d.ts +1 -1
- package/dist/wirings/http/pikku-fetch-http-response.d.ts +2 -2
- package/dist/wirings/http/pikku-fetch-http-response.js +6 -1
- package/dist/wirings/http/routers/http-router.d.ts +1 -1
- package/dist/wirings/http/routers/path-to-regex.d.ts +2 -2
- package/dist/wirings/mcp/index.d.ts +4 -3
- package/dist/wirings/mcp/index.js +3 -3
- package/dist/wirings/mcp/mcp-endpoint-registry.d.ts +1 -1
- package/dist/wirings/mcp/mcp-runner.d.ts +1 -6
- package/dist/wirings/mcp/mcp-runner.js +28 -40
- package/dist/wirings/mcp/mcp.types.d.ts +5 -5
- package/dist/wirings/node/index.d.ts +2 -0
- package/dist/wirings/node/index.js +1 -0
- package/dist/wirings/node/node.types.d.ts +20 -0
- package/dist/wirings/node/node.types.js +1 -0
- package/dist/wirings/oauth2/index.d.ts +3 -0
- package/dist/wirings/oauth2/index.js +2 -0
- package/dist/wirings/oauth2/oauth2-client.d.ts +47 -0
- package/dist/wirings/oauth2/oauth2-client.js +267 -0
- package/dist/wirings/oauth2/oauth2.types.d.ts +65 -0
- package/dist/wirings/oauth2/oauth2.types.js +4 -0
- package/dist/wirings/oauth2/wire-oauth2-credential.d.ts +20 -0
- package/dist/wirings/oauth2/wire-oauth2-credential.js +21 -0
- package/dist/wirings/queue/index.d.ts +1 -1
- package/dist/wirings/queue/queue-runner.d.ts +1 -5
- package/dist/wirings/queue/queue-runner.js +11 -8
- package/dist/wirings/queue/queue.types.d.ts +5 -5
- package/dist/wirings/queue/register-queue-helper.d.ts +2 -2
- package/dist/wirings/queue/register-queue-helper.js +1 -1
- package/dist/wirings/queue/validate-worker-config.d.ts +1 -1
- package/dist/wirings/rpc/index.d.ts +3 -1
- package/dist/wirings/rpc/index.js +2 -1
- package/dist/wirings/rpc/rpc-runner.d.ts +58 -8
- package/dist/wirings/rpc/rpc-runner.js +177 -31
- package/dist/wirings/rpc/rpc-types.d.ts +20 -4
- package/dist/wirings/rpc/wire-addon.d.ts +10 -0
- package/dist/wirings/rpc/wire-addon.js +9 -0
- package/dist/wirings/scheduler/index.d.ts +2 -2
- package/dist/wirings/scheduler/index.js +1 -2
- package/dist/wirings/scheduler/log-schedulers.d.ts +1 -1
- package/dist/wirings/scheduler/scheduler-runner.d.ts +3 -5
- package/dist/wirings/scheduler/scheduler-runner.js +11 -14
- package/dist/wirings/scheduler/scheduler.types.d.ts +2 -2
- package/dist/wirings/secret/index.d.ts +3 -0
- package/dist/wirings/secret/index.js +2 -0
- package/dist/wirings/secret/secret.types.d.ts +27 -0
- package/dist/wirings/secret/secret.types.js +1 -0
- package/dist/wirings/secret/validate-secret-definitions.d.ts +6 -0
- package/dist/wirings/secret/validate-secret-definitions.js +55 -0
- package/dist/wirings/trigger/index.d.ts +3 -2
- package/dist/wirings/trigger/index.js +2 -2
- package/dist/wirings/trigger/pikku-trigger-service.d.ts +22 -0
- package/dist/wirings/trigger/pikku-trigger-service.js +70 -0
- package/dist/wirings/trigger/trigger-runner.d.ts +18 -9
- package/dist/wirings/trigger/trigger-runner.js +48 -19
- package/dist/wirings/trigger/trigger.types.d.ts +99 -11
- package/dist/wirings/trigger/trigger.types.js +40 -1
- package/dist/wirings/variable/index.d.ts +3 -0
- package/dist/wirings/variable/index.js +2 -0
- package/dist/wirings/variable/validate-variable-definitions.d.ts +6 -0
- package/dist/wirings/variable/validate-variable-definitions.js +45 -0
- package/dist/wirings/variable/variable.types.d.ts +18 -0
- package/dist/wirings/variable/variable.types.js +1 -0
- package/dist/wirings/workflow/dsl/index.d.ts +1 -1
- package/dist/wirings/workflow/dsl/workflow-dsl.types.d.ts +7 -1
- package/dist/wirings/workflow/dsl/workflow-runner.js +3 -2
- package/dist/wirings/workflow/graph/graph-node.d.ts +1 -6
- package/dist/wirings/workflow/graph/graph-runner.d.ts +5 -31
- package/dist/wirings/workflow/graph/graph-runner.js +384 -296
- package/dist/wirings/workflow/graph/index.d.ts +4 -3
- package/dist/wirings/workflow/graph/index.js +3 -3
- package/dist/wirings/workflow/graph/template.d.ts +15 -0
- package/dist/wirings/workflow/graph/template.js +27 -0
- package/dist/wirings/workflow/graph/wire-workflow-graph.d.ts +15 -0
- package/dist/wirings/workflow/graph/wire-workflow-graph.js +8 -0
- package/dist/wirings/workflow/graph/workflow-graph.types.d.ts +0 -13
- package/dist/wirings/workflow/index.d.ts +6 -6
- package/dist/wirings/workflow/index.js +6 -4
- package/dist/wirings/workflow/pikku-workflow-service.d.ts +29 -19
- package/dist/wirings/workflow/pikku-workflow-service.js +217 -82
- package/dist/wirings/workflow/workflow-helpers.d.ts +36 -0
- package/dist/wirings/workflow/workflow-helpers.js +38 -0
- package/dist/wirings/workflow/workflow.types.d.ts +42 -95
- package/package.json +14 -15
- package/run-tests.sh +4 -1
- package/src/crypto-utils.test.ts +116 -0
- package/src/crypto-utils.ts +99 -0
- package/src/errors/error.test.ts +143 -2
- package/src/errors/errors.ts +27 -0
- package/src/errors/index.ts +1 -1
- package/src/factory-functions.test.ts +42 -2
- package/src/function/function-runner.test.ts +6 -13
- package/src/function/function-runner.ts +161 -53
- package/src/function/functions.types.ts +63 -132
- package/src/function/index.ts +5 -2
- package/src/handle-error.test.ts +361 -0
- package/src/handle-error.ts +6 -14
- package/src/index.ts +97 -30
- package/src/internal.ts +6 -0
- package/src/middleware/auth-apikey.test.ts +16 -13
- package/src/middleware/auth-apikey.ts +3 -3
- package/src/middleware/auth-bearer.test.ts +18 -15
- package/src/middleware/auth-bearer.ts +27 -32
- package/src/middleware/auth-cookie.test.ts +17 -14
- package/src/middleware/auth-cookie.ts +9 -13
- package/src/middleware/cors.test.ts +424 -0
- package/src/middleware/cors.ts +104 -0
- package/src/middleware/index.ts +5 -3
- package/src/middleware/remote-auth.test.ts +488 -0
- package/src/middleware/remote-auth.ts +68 -0
- package/src/middleware-runner.test.ts +123 -1
- package/src/middleware-runner.ts +13 -13
- package/src/permissions.test.ts +83 -9
- package/src/permissions.ts +17 -19
- package/src/pikku-state.test.ts +224 -0
- package/src/pikku-state.ts +59 -35
- package/src/run-tests-script.test.ts +49 -0
- package/src/schema.test.ts +198 -6
- package/src/schema.ts +28 -21
- package/src/services/ai-agent-runner-service.ts +41 -0
- package/src/services/ai-run-state-service.ts +20 -0
- package/src/services/ai-storage-service.ts +39 -0
- package/src/services/content-service.ts +7 -0
- package/src/services/deployment-service.ts +22 -0
- package/src/services/gopass-secrets.ts +98 -0
- package/src/services/in-memory-ai-run-state-service.ts +73 -0
- package/src/services/in-memory-trigger-service.ts +64 -0
- package/src/services/in-memory-workflow-service.test.ts +351 -0
- package/src/services/in-memory-workflow-service.ts +395 -0
- package/src/services/index.ts +50 -14
- package/src/services/local-content.ts +9 -3
- package/src/services/local-secrets.test.ts +80 -0
- package/src/services/local-secrets.ts +53 -2
- package/src/services/local-variables.test.ts +61 -0
- package/src/services/local-variables.ts +23 -1
- package/src/services/logger-console.test.ts +118 -0
- package/src/services/logger-console.ts +2 -1
- package/src/services/scheduler-service.ts +11 -1
- package/src/services/schema-service.ts +7 -0
- package/src/services/scoped-secret-service.test.ts +74 -0
- package/src/services/scoped-secret-service.ts +41 -0
- package/src/services/secret-service.ts +25 -4
- package/src/services/trigger-service.ts +17 -0
- package/src/services/typed-secret-service.test.ts +93 -0
- package/src/services/typed-secret-service.ts +70 -0
- package/src/services/typed-variables-service.test.ts +73 -0
- package/src/services/typed-variables-service.ts +81 -0
- package/src/services/user-session-service.test.ts +113 -0
- package/src/services/user-session-service.ts +25 -2
- package/src/services/variables-service.ts +5 -0
- package/src/services/workflow-service.ts +23 -13
- package/src/time-utils.test.ts +1 -1
- package/src/types/core.types.ts +95 -24
- package/src/types/state.types.ts +56 -73
- package/src/utils.test.ts +350 -0
- package/src/utils.ts +33 -18
- package/src/version.test.ts +80 -0
- package/src/version.ts +25 -0
- package/src/wirings/ai-agent/ai-agent-assistant-ui.test.ts +363 -0
- package/src/wirings/ai-agent/ai-agent-assistant-ui.ts +214 -0
- package/src/wirings/ai-agent/ai-agent-helpers.test.ts +152 -0
- package/src/wirings/ai-agent/ai-agent-helpers.ts +76 -0
- package/src/wirings/ai-agent/ai-agent-memory.ts +300 -0
- package/src/wirings/ai-agent/ai-agent-model-config.test.ts +115 -0
- package/src/wirings/ai-agent/ai-agent-model-config.ts +43 -0
- package/src/wirings/ai-agent/ai-agent-prepare.ts +504 -0
- package/src/wirings/ai-agent/ai-agent-registry.test.ts +37 -0
- package/src/wirings/ai-agent/ai-agent-registry.ts +82 -0
- package/src/wirings/ai-agent/ai-agent-runner.test.ts +317 -0
- package/src/wirings/ai-agent/ai-agent-runner.ts +251 -0
- package/src/wirings/ai-agent/ai-agent-stream.test.ts +652 -0
- package/src/wirings/ai-agent/ai-agent-stream.ts +1049 -0
- package/src/wirings/ai-agent/ai-agent.types.ts +328 -0
- package/src/wirings/ai-agent/index.ts +39 -0
- package/src/wirings/channel/channel-common.ts +33 -20
- package/src/wirings/channel/channel-handler.ts +26 -9
- package/src/wirings/channel/channel-middleware-runner.ts +119 -0
- package/src/wirings/channel/channel-runner.ts +15 -16
- package/src/wirings/channel/channel-store.ts +1 -1
- package/src/wirings/channel/channel.types.ts +21 -9
- package/src/wirings/channel/define-channel-routes.ts +25 -0
- package/src/wirings/channel/index.ts +23 -8
- package/src/wirings/channel/local/index.ts +3 -3
- package/src/wirings/channel/local/local-channel-runner.test.ts +57 -7
- package/src/wirings/channel/local/local-channel-runner.ts +40 -19
- package/src/wirings/channel/local/local-eventhub-service.test.ts +2 -2
- package/src/wirings/channel/local/local-eventhub-service.ts +2 -2
- package/src/wirings/channel/log-channels.ts +1 -1
- package/src/wirings/channel/pikku-abstract-channel-handler.ts +1 -1
- package/src/wirings/channel/serverless/index.ts +5 -1
- package/src/wirings/channel/serverless/serverless-channel-runner.ts +57 -36
- package/src/wirings/cli/channel/cli-channel-runner.ts +1 -1
- package/src/wirings/cli/channel/index.ts +1 -1
- package/src/wirings/cli/cli-runner.test.ts +10 -10
- package/src/wirings/cli/cli-runner.ts +28 -14
- package/src/wirings/cli/cli.types.ts +14 -14
- package/src/wirings/cli/command-parser.test.ts +9 -9
- package/src/wirings/cli/command-parser.ts +1 -1
- package/src/wirings/cli/define-cli-commands.ts +24 -0
- package/src/wirings/cli/index.ts +10 -4
- package/src/wirings/http/http-routes.test.ts +322 -0
- package/src/wirings/http/http-routes.ts +198 -0
- package/src/wirings/http/http-runner.test.ts +12 -20
- package/src/wirings/http/http-runner.ts +101 -51
- package/src/wirings/http/http.types.ts +119 -48
- package/src/wirings/http/index.ts +16 -4
- package/src/wirings/http/log-http-routes.ts +1 -1
- package/src/wirings/http/pikku-fetch-http-request.ts +1 -1
- package/src/wirings/http/pikku-fetch-http-response.ts +12 -5
- package/src/wirings/http/routers/http-router.ts +1 -1
- package/src/wirings/http/routers/path-to-regex.test.ts +1 -1
- package/src/wirings/http/routers/path-to-regex.ts +4 -3
- package/src/wirings/mcp/index.ts +27 -3
- package/src/wirings/mcp/mcp-endpoint-registry.test.ts +3 -3
- package/src/wirings/mcp/mcp-endpoint-registry.ts +5 -1
- package/src/wirings/mcp/mcp-runner.ts +48 -65
- package/src/wirings/mcp/mcp.types.ts +5 -5
- package/src/wirings/node/index.ts +2 -0
- package/src/wirings/node/node.types.ts +23 -0
- package/src/wirings/oauth2/index.ts +3 -0
- package/src/wirings/oauth2/oauth2-client.test.ts +929 -0
- package/src/wirings/oauth2/oauth2-client.ts +335 -0
- package/src/wirings/oauth2/oauth2.types.ts +69 -0
- package/src/wirings/oauth2/wire-oauth2-credential.ts +23 -0
- package/src/wirings/queue/index.ts +13 -2
- package/src/wirings/queue/queue-runner.test.ts +142 -73
- package/src/wirings/queue/queue-runner.ts +18 -14
- package/src/wirings/queue/queue.types.ts +5 -5
- package/src/wirings/queue/register-queue-helper.ts +3 -5
- package/src/wirings/queue/validate-worker-config.test.ts +108 -0
- package/src/wirings/queue/validate-worker-config.ts +4 -1
- package/src/wirings/rpc/index.ts +3 -1
- package/src/wirings/rpc/rpc-runner.ts +254 -41
- package/src/wirings/rpc/rpc-types.ts +28 -4
- package/src/wirings/rpc/wire-addon.ts +20 -0
- package/src/wirings/scheduler/index.ts +6 -4
- package/src/wirings/scheduler/log-schedulers.ts +1 -1
- package/src/wirings/scheduler/scheduler-runner.test.ts +78 -45
- package/src/wirings/scheduler/scheduler-runner.ts +20 -27
- package/src/wirings/scheduler/scheduler.types.ts +2 -2
- package/src/wirings/secret/index.ts +9 -0
- package/src/wirings/secret/secret.types.ts +32 -0
- package/src/wirings/secret/validate-secret-definitions.test.ts +140 -0
- package/src/wirings/secret/validate-secret-definitions.ts +82 -0
- package/src/wirings/trigger/index.ts +10 -2
- package/src/wirings/trigger/pikku-trigger-service.ts +112 -0
- package/src/wirings/trigger/trigger-runner.test.ts +79 -0
- package/src/wirings/trigger/trigger-runner.ts +80 -41
- package/src/wirings/trigger/trigger.types.ts +144 -22
- package/src/wirings/variable/index.ts +8 -0
- package/src/wirings/variable/validate-variable-definitions.test.ts +91 -0
- package/src/wirings/variable/validate-variable-definitions.ts +69 -0
- package/src/wirings/variable/variable.types.ts +22 -0
- package/src/wirings/workflow/dsl/index.ts +1 -0
- package/src/wirings/workflow/dsl/workflow-dsl.types.ts +9 -1
- package/src/wirings/workflow/dsl/workflow-runner.ts +4 -3
- package/src/wirings/workflow/graph/graph-node.ts +1 -6
- package/src/wirings/workflow/graph/graph-runner.test.ts +487 -0
- package/src/wirings/workflow/graph/graph-runner.ts +496 -374
- package/src/wirings/workflow/graph/index.ts +14 -3
- package/src/wirings/workflow/graph/template.test.ts +49 -0
- package/src/wirings/workflow/graph/template.ts +42 -0
- package/src/wirings/workflow/graph/wire-workflow-graph.ts +29 -0
- package/src/wirings/workflow/graph/workflow-graph.types.ts +0 -22
- package/src/wirings/workflow/index.ts +21 -10
- package/src/wirings/workflow/pikku-workflow-service.test.ts +200 -0
- package/src/wirings/workflow/pikku-workflow-service.ts +308 -105
- package/src/wirings/workflow/workflow-helpers.test.ts +129 -0
- package/src/wirings/workflow/workflow-helpers.ts +79 -0
- package/src/wirings/workflow/workflow.types.ts +47 -92
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/wirings/forge-node/forge-node.types.d.ts +0 -120
- package/dist/wirings/forge-node/forge-node.types.js +0 -38
- package/dist/wirings/forge-node/index.d.ts +0 -1
- package/dist/wirings/forge-node/index.js +0 -1
- package/dist/wirings/workflow/wire-workflow.d.ts +0 -42
- package/dist/wirings/workflow/wire-workflow.js +0 -53
- package/dist/wirings/workflow/workflow-utils.d.ts +0 -23
- package/dist/wirings/workflow/workflow-utils.js +0 -66
- package/src/wirings/forge-node/forge-node.types.ts +0 -135
- package/src/wirings/forge-node/index.ts +0 -1
- package/src/wirings/workflow/wire-workflow.ts +0 -94
- package/src/wirings/workflow/workflow-utils.ts +0 -120
package/src/middleware-runner.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
CoreSingletonServices,
|
|
3
3
|
PikkuWire,
|
|
4
4
|
CorePikkuMiddleware,
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
MiddlewareMetadata,
|
|
8
8
|
} from './types/core.types.js'
|
|
9
9
|
import { pikkuState } from './pikku-state.js'
|
|
10
|
-
import { freezeDedupe } from './utils.js'
|
|
10
|
+
import { freezeDedupe, getTagGroups } from './utils.js'
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Runs a chain of middleware functions in sequence before executing the main function.
|
|
@@ -96,7 +96,7 @@ export const addMiddleware = <PikkuMiddleware extends CorePikkuMiddleware>(
|
|
|
96
96
|
* This function looks up middleware that was registered with registerMiddleware.
|
|
97
97
|
* It's used internally by the framework to resolve middleware references in metadata.
|
|
98
98
|
*
|
|
99
|
-
* @param {string} name - The unique name (
|
|
99
|
+
* @param {string} name - The unique name (pikkuFuncId) of the middleware function.
|
|
100
100
|
* @returns {CorePikkuMiddleware | undefined} The middleware function, or undefined if not found.
|
|
101
101
|
*
|
|
102
102
|
* @internal
|
|
@@ -116,7 +116,9 @@ const middlewareCache: Record<
|
|
|
116
116
|
channel: {},
|
|
117
117
|
queue: {},
|
|
118
118
|
scheduler: {},
|
|
119
|
+
trigger: {},
|
|
119
120
|
mcp: {},
|
|
121
|
+
agent: {},
|
|
120
122
|
cli: {},
|
|
121
123
|
workflow: {},
|
|
122
124
|
}
|
|
@@ -179,12 +181,11 @@ export const combineMiddleware = (
|
|
|
179
181
|
resolved.push(...(group as CorePikkuMiddleware[]))
|
|
180
182
|
}
|
|
181
183
|
} else if (meta.type === 'tag') {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
+
const groups = getTagGroups(
|
|
185
|
+
pikkuState(packageName, 'middleware', 'tagGroup'),
|
|
184
186
|
meta.tag
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
// At runtime, all factories should be resolved to middleware
|
|
187
|
+
)
|
|
188
|
+
for (const group of groups) {
|
|
188
189
|
resolved.push(...(group as CorePikkuMiddleware[]))
|
|
189
190
|
}
|
|
190
191
|
} else if (meta.type === 'wire') {
|
|
@@ -206,12 +207,11 @@ export const combineMiddleware = (
|
|
|
206
207
|
if (funcInheritedMiddleware) {
|
|
207
208
|
for (const meta of funcInheritedMiddleware) {
|
|
208
209
|
if (meta.type === 'tag') {
|
|
209
|
-
|
|
210
|
-
|
|
210
|
+
const groups = getTagGroups(
|
|
211
|
+
pikkuState(packageName, 'middleware', 'tagGroup'),
|
|
211
212
|
meta.tag
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
// At runtime, all factories should be resolved to middleware
|
|
213
|
+
)
|
|
214
|
+
for (const group of groups) {
|
|
215
215
|
resolved.push(...(group as CorePikkuMiddleware[]))
|
|
216
216
|
}
|
|
217
217
|
}
|
package/src/permissions.test.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { describe, test, beforeEach } from 'node:test'
|
|
|
2
2
|
import * as assert from 'node:assert'
|
|
3
3
|
import { addPermission, runPermissions } from './permissions.js'
|
|
4
4
|
import { pikkuState, resetPikkuState } from './pikku-state.js'
|
|
5
|
-
import { CoreServices, CoreUserSession } from './types/core.types.js'
|
|
6
|
-
import {
|
|
5
|
+
import type { CoreServices, CoreUserSession } from './types/core.types.js'
|
|
6
|
+
import type {
|
|
7
7
|
CorePermissionGroup,
|
|
8
8
|
CorePikkuPermission,
|
|
9
9
|
} from './function/functions.types.js'
|
|
@@ -82,6 +82,85 @@ describe('addPermission', () => {
|
|
|
82
82
|
assert.equal(permissions[0], mockPermissionGroup)
|
|
83
83
|
})
|
|
84
84
|
|
|
85
|
+
test('should apply parent tag permission to namespaced tag via runPermissions', async () => {
|
|
86
|
+
const billingPermission = async () => true
|
|
87
|
+
|
|
88
|
+
addPermission('billing', [billingPermission])
|
|
89
|
+
|
|
90
|
+
await runPermissions('rpc', Math.random().toString(), {
|
|
91
|
+
wireInheritedPermissions: [{ type: 'tag', tag: 'billing:write' }],
|
|
92
|
+
services: mockServices,
|
|
93
|
+
wire: {},
|
|
94
|
+
data: {},
|
|
95
|
+
})
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
test('should apply both parent and exact tag permissions', async () => {
|
|
99
|
+
const executionOrder: string[] = []
|
|
100
|
+
const billingPermission = async () => {
|
|
101
|
+
executionOrder.push('billing')
|
|
102
|
+
return true
|
|
103
|
+
}
|
|
104
|
+
const billingReadPermission = async () => {
|
|
105
|
+
executionOrder.push('billing:read')
|
|
106
|
+
return true
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
addPermission('billing', [billingPermission])
|
|
110
|
+
addPermission('billing:read', [billingReadPermission])
|
|
111
|
+
|
|
112
|
+
await runPermissions('rpc', Math.random().toString(), {
|
|
113
|
+
wireInheritedPermissions: [{ type: 'tag', tag: 'billing:read' }],
|
|
114
|
+
services: mockServices,
|
|
115
|
+
wire: {},
|
|
116
|
+
data: {},
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
assert.deepEqual(executionOrder, ['billing:read'])
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
test('should resolve multi-level namespace permissions', async () => {
|
|
123
|
+
const executionOrder: string[] = []
|
|
124
|
+
const billingPermission = async () => {
|
|
125
|
+
executionOrder.push('billing')
|
|
126
|
+
return false
|
|
127
|
+
}
|
|
128
|
+
const billingReadPermission = async () => {
|
|
129
|
+
executionOrder.push('billing:read')
|
|
130
|
+
return false
|
|
131
|
+
}
|
|
132
|
+
const billingReadAdminPermission = async () => {
|
|
133
|
+
executionOrder.push('billing:read:admin')
|
|
134
|
+
return true
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
addPermission('billing', [billingPermission])
|
|
138
|
+
addPermission('billing:read', [billingReadPermission])
|
|
139
|
+
addPermission('billing:read:admin', [billingReadAdminPermission])
|
|
140
|
+
|
|
141
|
+
await runPermissions('rpc', Math.random().toString(), {
|
|
142
|
+
wireInheritedPermissions: [{ type: 'tag', tag: 'billing:read:admin' }],
|
|
143
|
+
services: mockServices,
|
|
144
|
+
wire: {},
|
|
145
|
+
data: {},
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
assert.deepEqual(executionOrder, ['billing:read:admin'])
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
test('should apply parent tag permission via funcInheritedPermissions', async () => {
|
|
152
|
+
const billingPermission = async () => true
|
|
153
|
+
|
|
154
|
+
addPermission('billing', [billingPermission])
|
|
155
|
+
|
|
156
|
+
await runPermissions('rpc', Math.random().toString(), {
|
|
157
|
+
funcInheritedPermissions: [{ type: 'tag', tag: 'billing:delete' }],
|
|
158
|
+
services: mockServices,
|
|
159
|
+
wire: {},
|
|
160
|
+
data: {},
|
|
161
|
+
})
|
|
162
|
+
})
|
|
163
|
+
|
|
85
164
|
test('should throw error when tag already exists', () => {
|
|
86
165
|
const mockPermission = async () => true
|
|
87
166
|
|
|
@@ -171,13 +250,8 @@ describe('runPermissions', () => {
|
|
|
171
250
|
data: {},
|
|
172
251
|
})
|
|
173
252
|
|
|
174
|
-
// Order: wireInheritedPermissions (wiringTag)
|
|
175
|
-
assert.deepEqual(executionOrder, [
|
|
176
|
-
'wiringTag',
|
|
177
|
-
'wiringPermission',
|
|
178
|
-
'funcTag',
|
|
179
|
-
'funcPermission',
|
|
180
|
-
])
|
|
253
|
+
// Order: wireInheritedPermissions (wiringTag) only (short-circuit on first passing group)
|
|
254
|
+
assert.deepEqual(executionOrder, ['wiringTag'])
|
|
181
255
|
})
|
|
182
256
|
|
|
183
257
|
test('should implement "at least one must pass" logic for tag permissions', async () => {
|
package/src/permissions.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
CoreServices,
|
|
3
3
|
PikkuWiringTypes,
|
|
4
4
|
PermissionMetadata,
|
|
5
5
|
PikkuWire,
|
|
6
6
|
} from './types/core.types.js'
|
|
7
|
-
import {
|
|
7
|
+
import type {
|
|
8
8
|
CorePermissionGroup,
|
|
9
9
|
CorePikkuPermission,
|
|
10
10
|
} from './function/functions.types.js'
|
|
11
11
|
import { pikkuState } from './pikku-state.js'
|
|
12
12
|
import { ForbiddenError } from './errors/errors.js'
|
|
13
|
-
import { freezeDedupe } from './utils.js'
|
|
13
|
+
import { freezeDedupe, getTagGroups } from './utils.js'
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* This function validates permissions by iterating over permission groups and executing the corresponding permission functions. If all functions in at least one group return true, the permission is considered valid.
|
|
@@ -59,7 +59,7 @@ const verifyPermissions = async <Out = any>(
|
|
|
59
59
|
* This function looks up permissions that was registered with registerPermission.
|
|
60
60
|
* It's used internally by the framework to resolve permission references in metadata.
|
|
61
61
|
*
|
|
62
|
-
* @param {string} name - The unique name (
|
|
62
|
+
* @param {string} name - The unique name (pikkuFuncId) of the permission function.
|
|
63
63
|
* @returns {CorePikkuPermission | undefined} The permission function, or undefined if not found.
|
|
64
64
|
*
|
|
65
65
|
* @internal
|
|
@@ -125,7 +125,9 @@ const combinedPermissionsCache: Record<
|
|
|
125
125
|
channel: {},
|
|
126
126
|
queue: {},
|
|
127
127
|
scheduler: {},
|
|
128
|
+
trigger: {},
|
|
128
129
|
mcp: {},
|
|
130
|
+
agent: {},
|
|
129
131
|
cli: {},
|
|
130
132
|
workflow: {},
|
|
131
133
|
}
|
|
@@ -193,11 +195,11 @@ const combinePermissions = (
|
|
|
193
195
|
}
|
|
194
196
|
}
|
|
195
197
|
} else if (meta.type === 'tag') {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
+
const groups = getTagGroups(
|
|
199
|
+
pikkuState(packageName, 'permissions', 'tagGroup'),
|
|
198
200
|
meta.tag
|
|
199
|
-
|
|
200
|
-
|
|
201
|
+
)
|
|
202
|
+
for (const group of groups) {
|
|
201
203
|
if (Array.isArray(group)) {
|
|
202
204
|
resolved.push(...group)
|
|
203
205
|
} else {
|
|
@@ -227,11 +229,11 @@ const combinePermissions = (
|
|
|
227
229
|
if (funcInheritedPermissions) {
|
|
228
230
|
for (const meta of funcInheritedPermissions) {
|
|
229
231
|
if (meta.type === 'tag') {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
+
const groups = getTagGroups(
|
|
233
|
+
pikkuState(packageName, 'permissions', 'tagGroup'),
|
|
232
234
|
meta.tag
|
|
233
|
-
|
|
234
|
-
|
|
235
|
+
)
|
|
236
|
+
for (const group of groups) {
|
|
235
237
|
if (Array.isArray(group)) {
|
|
236
238
|
resolved.push(...group)
|
|
237
239
|
} else {
|
|
@@ -299,7 +301,6 @@ export const runPermissions = async (
|
|
|
299
301
|
|
|
300
302
|
// Check all combined permissions - at least one must pass if any exist
|
|
301
303
|
if (allPermissions.length > 0) {
|
|
302
|
-
let permissioned = false
|
|
303
304
|
for (const permission of allPermissions) {
|
|
304
305
|
const result = await verifyPermissions(
|
|
305
306
|
typeof permission === 'function' ? { permission } : permission,
|
|
@@ -308,13 +309,10 @@ export const runPermissions = async (
|
|
|
308
309
|
wire
|
|
309
310
|
)
|
|
310
311
|
if (result) {
|
|
311
|
-
|
|
312
|
-
// Continue executing all permissions (don't break early)
|
|
312
|
+
return
|
|
313
313
|
}
|
|
314
314
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
throw new ForbiddenError('Permission denied')
|
|
318
|
-
}
|
|
315
|
+
services.logger.debug('Permission denied - combined permissions')
|
|
316
|
+
throw new ForbiddenError('Permission denied')
|
|
319
317
|
}
|
|
320
318
|
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { describe, test, beforeEach } from 'node:test'
|
|
2
|
+
import assert from 'node:assert'
|
|
3
|
+
import {
|
|
4
|
+
pikkuState,
|
|
5
|
+
resetPikkuState,
|
|
6
|
+
initializePikkuState,
|
|
7
|
+
getAllPackageStates,
|
|
8
|
+
getSingletonServices,
|
|
9
|
+
getCreateWireServices,
|
|
10
|
+
getPikkuMetaDir,
|
|
11
|
+
addPackageServiceFactories,
|
|
12
|
+
} from './pikku-state.js'
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
resetPikkuState()
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
describe('pikkuState', () => {
|
|
19
|
+
test('should get state for main package with null name', () => {
|
|
20
|
+
const functions = pikkuState(null, 'function', 'functions')
|
|
21
|
+
assert.ok(functions instanceof Map)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test('should get state for main package with __main__ name', () => {
|
|
25
|
+
const functions = pikkuState('__main__', 'function', 'functions')
|
|
26
|
+
assert.ok(functions instanceof Map)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('should set and get state values', () => {
|
|
30
|
+
const testMeta = { key: 'value' }
|
|
31
|
+
pikkuState(null, 'function', 'meta', testMeta as any)
|
|
32
|
+
const result = pikkuState(null, 'function', 'meta')
|
|
33
|
+
assert.deepStrictEqual(result, testMeta)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
test('should auto-initialize package state on first access', () => {
|
|
37
|
+
const states = getAllPackageStates()
|
|
38
|
+
assert.ok(!states.has('@test/package'))
|
|
39
|
+
|
|
40
|
+
pikkuState('@test/package', 'function', 'functions')
|
|
41
|
+
|
|
42
|
+
assert.ok(states.has('@test/package'))
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
test('should isolate state between packages', () => {
|
|
46
|
+
pikkuState(null, 'function', 'meta', { main: true } as any)
|
|
47
|
+
pikkuState('@addon/pkg', 'function', 'meta', { addon: true } as any)
|
|
48
|
+
|
|
49
|
+
assert.deepStrictEqual(pikkuState(null, 'function', 'meta'), { main: true })
|
|
50
|
+
assert.deepStrictEqual(pikkuState('@addon/pkg', 'function', 'meta'), {
|
|
51
|
+
addon: true,
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
test('should return correct state types', () => {
|
|
56
|
+
const httpRoutes = pikkuState(null, 'http', 'routes')
|
|
57
|
+
assert.ok(httpRoutes instanceof Map)
|
|
58
|
+
|
|
59
|
+
const schemas = pikkuState(null, 'misc', 'schemas')
|
|
60
|
+
assert.ok(schemas instanceof Map)
|
|
61
|
+
|
|
62
|
+
const errors = pikkuState(null, 'misc', 'errors')
|
|
63
|
+
assert.ok(errors instanceof Map)
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
describe('getAllPackageStates', () => {
|
|
68
|
+
test('should return a Map', () => {
|
|
69
|
+
const states = getAllPackageStates()
|
|
70
|
+
assert.ok(states instanceof Map)
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
test('should contain __main__ after reset', () => {
|
|
74
|
+
const states = getAllPackageStates()
|
|
75
|
+
assert.ok(states.has('__main__'))
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
test('should return same reference on multiple calls', () => {
|
|
79
|
+
const states1 = getAllPackageStates()
|
|
80
|
+
const states2 = getAllPackageStates()
|
|
81
|
+
assert.strictEqual(states1, states2)
|
|
82
|
+
})
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
describe('initializePikkuState', () => {
|
|
86
|
+
test('should create a new package state', () => {
|
|
87
|
+
const states = getAllPackageStates()
|
|
88
|
+
assert.ok(!states.has('@new/package'))
|
|
89
|
+
|
|
90
|
+
initializePikkuState('@new/package')
|
|
91
|
+
|
|
92
|
+
assert.ok(states.has('@new/package'))
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
test('should not overwrite existing package state', () => {
|
|
96
|
+
pikkuState('@existing/pkg', 'function', 'meta', { test: true } as any)
|
|
97
|
+
|
|
98
|
+
initializePikkuState('@existing/pkg')
|
|
99
|
+
|
|
100
|
+
const meta = pikkuState('@existing/pkg', 'function', 'meta')
|
|
101
|
+
assert.deepStrictEqual(meta, { test: true })
|
|
102
|
+
})
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
describe('resetPikkuState', () => {
|
|
106
|
+
test('should clear all package states', () => {
|
|
107
|
+
initializePikkuState('@addon/one')
|
|
108
|
+
initializePikkuState('@addon/two')
|
|
109
|
+
assert.ok(getAllPackageStates().has('@addon/one'))
|
|
110
|
+
|
|
111
|
+
resetPikkuState()
|
|
112
|
+
|
|
113
|
+
assert.ok(!getAllPackageStates().has('@addon/one'))
|
|
114
|
+
assert.ok(!getAllPackageStates().has('@addon/two'))
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
test('should preserve errors map from __main__', () => {
|
|
118
|
+
const errors = pikkuState(null, 'misc', 'errors')
|
|
119
|
+
errors.set('TestError', { status: 400, message: 'test' })
|
|
120
|
+
|
|
121
|
+
resetPikkuState()
|
|
122
|
+
|
|
123
|
+
const restoredErrors = pikkuState(null, 'misc', 'errors')
|
|
124
|
+
assert.strictEqual(restoredErrors.get('TestError')?.message, 'test')
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
test('should re-initialize __main__ package', () => {
|
|
128
|
+
resetPikkuState()
|
|
129
|
+
|
|
130
|
+
const states = getAllPackageStates()
|
|
131
|
+
assert.ok(states.has('__main__'))
|
|
132
|
+
assert.ok(pikkuState(null, 'function', 'functions') instanceof Map)
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
test('should create fresh state objects after reset', () => {
|
|
136
|
+
const functionsBefore = pikkuState(null, 'function', 'functions')
|
|
137
|
+
functionsBefore.set('testFunc', {} as any)
|
|
138
|
+
|
|
139
|
+
resetPikkuState()
|
|
140
|
+
|
|
141
|
+
const functionsAfter = pikkuState(null, 'function', 'functions')
|
|
142
|
+
assert.strictEqual(functionsAfter.size, 0)
|
|
143
|
+
})
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
describe('getSingletonServices', () => {
|
|
147
|
+
test('should throw when singleton services not initialized', () => {
|
|
148
|
+
assert.throws(() => getSingletonServices(), {
|
|
149
|
+
message: 'Singleton services not initialized',
|
|
150
|
+
})
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
test('should return services when initialized', () => {
|
|
154
|
+
const mockServices = { logger: { info: () => {} } }
|
|
155
|
+
pikkuState(null, 'package', 'singletonServices', mockServices as any)
|
|
156
|
+
|
|
157
|
+
const result = getSingletonServices()
|
|
158
|
+
assert.strictEqual(result, mockServices)
|
|
159
|
+
})
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
describe('getCreateWireServices', () => {
|
|
163
|
+
test('should return undefined when no factories set', () => {
|
|
164
|
+
const result = getCreateWireServices()
|
|
165
|
+
assert.strictEqual(result, undefined)
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
test('should return createWireServices when factories set', () => {
|
|
169
|
+
const mockCreateWire = async () => ({})
|
|
170
|
+
pikkuState(null, 'package', 'factories', {
|
|
171
|
+
createWireServices: mockCreateWire,
|
|
172
|
+
} as any)
|
|
173
|
+
|
|
174
|
+
const result = getCreateWireServices()
|
|
175
|
+
assert.strictEqual(result, mockCreateWire)
|
|
176
|
+
})
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
describe('getPikkuMetaDir', () => {
|
|
180
|
+
test('should return null by default', () => {
|
|
181
|
+
const result = getPikkuMetaDir()
|
|
182
|
+
assert.strictEqual(result, null)
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
test('should return metaDir when set', () => {
|
|
186
|
+
pikkuState(null, 'package', 'metaDir', '/some/path' as any)
|
|
187
|
+
const result = getPikkuMetaDir()
|
|
188
|
+
assert.strictEqual(result, '/some/path')
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
test('should return metaDir for specific package', () => {
|
|
192
|
+
pikkuState('@test/pkg', 'package', 'metaDir', '/addon/path' as any)
|
|
193
|
+
const result = getPikkuMetaDir('@test/pkg')
|
|
194
|
+
assert.strictEqual(result, '/addon/path')
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
test('should treat null packageName as main', () => {
|
|
198
|
+
pikkuState(null, 'package', 'metaDir', '/main/path' as any)
|
|
199
|
+
const result = getPikkuMetaDir(null)
|
|
200
|
+
assert.strictEqual(result, '/main/path')
|
|
201
|
+
})
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
describe('addPackageServiceFactories', () => {
|
|
205
|
+
test('should register factories for addon package', () => {
|
|
206
|
+
const mockFactories = {
|
|
207
|
+
createSingletonServices: async () => ({}),
|
|
208
|
+
createWireServices: async () => ({}),
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
addPackageServiceFactories('@addon/pkg', mockFactories as any)
|
|
212
|
+
|
|
213
|
+
const result = pikkuState('@addon/pkg', 'package', 'factories')
|
|
214
|
+
assert.strictEqual(result, mockFactories)
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
test('should not affect main package factories', () => {
|
|
218
|
+
const addonFactories = { createSingletonServices: async () => ({}) }
|
|
219
|
+
addPackageServiceFactories('@addon/pkg', addonFactories as any)
|
|
220
|
+
|
|
221
|
+
const mainFactories = pikkuState(null, 'package', 'factories')
|
|
222
|
+
assert.strictEqual(mainFactories, null)
|
|
223
|
+
})
|
|
224
|
+
})
|