@pikku/core 0.11.1 → 0.12.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/CHANGELOG.md +55 -0
- package/dist/crypto-utils.d.ts +2 -0
- package/dist/crypto-utils.js +78 -0
- package/dist/errors/error-handler.js +3 -3
- package/dist/errors/errors.d.ts +8 -0
- package/dist/errors/errors.js +16 -0
- package/dist/errors/index.d.ts +0 -1
- package/dist/errors/index.js +0 -1
- package/dist/function/function-runner.d.ts +10 -3
- package/dist/function/function-runner.js +136 -31
- package/dist/function/functions.types.d.ts +35 -12
- package/dist/function/functions.types.js +16 -6
- package/dist/function/index.d.ts +2 -2
- package/dist/function/index.js +1 -2
- package/dist/handle-error.js +1 -10
- package/dist/index.d.ts +30 -24
- package/dist/index.js +19 -27
- package/dist/middleware/auth-apikey.d.ts +1 -1
- package/dist/middleware/auth-apikey.js +3 -3
- package/dist/middleware/auth-bearer.d.ts +1 -1
- package/dist/middleware/auth-bearer.js +3 -6
- package/dist/middleware/auth-cookie.d.ts +1 -1
- package/dist/middleware/auth-cookie.js +6 -8
- package/dist/middleware/cors.d.ts +46 -0
- package/dist/middleware/cors.js +73 -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 +1 -1
- package/dist/middleware-runner.d.ts +3 -14
- package/dist/middleware-runner.js +14 -16
- package/dist/permissions.d.ts +3 -86
- package/dist/permissions.js +20 -80
- package/dist/pikku-state.d.ts +33 -104
- package/dist/pikku-state.js +150 -66
- package/dist/schema.d.ts +8 -6
- package/dist/schema.js +31 -18
- package/dist/services/ai-agent-runner-service.d.ts +24 -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/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 +94 -0
- package/dist/services/in-memory-trigger-service.d.ts +23 -0
- package/dist/services/in-memory-trigger-service.js +50 -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 +25 -11
- package/dist/services/index.js +10 -13
- package/dist/services/local-secrets.d.ts +23 -0
- package/dist/services/local-secrets.js +45 -0
- package/dist/services/local-variables.d.ts +5 -0
- package/dist/services/local-variables.js +18 -0
- package/dist/services/scheduler-service.d.ts +21 -1
- package/dist/services/scheduler-service.js +14 -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 +23 -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 +13 -0
- 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 +43 -0
- package/dist/services/workflow-service.js +1 -0
- package/dist/types/core.types.d.ts +54 -10
- package/dist/types/core.types.js +7 -0
- package/dist/types/state.types.d.ts +127 -0
- package/dist/types/state.types.js +1 -0
- package/dist/utils.d.ts +10 -1
- package/dist/utils.js +60 -3
- package/dist/version.d.ts +6 -0
- package/dist/version.js +19 -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 +60 -0
- package/dist/wirings/ai-agent/ai-agent-prepare.js +312 -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 +96 -0
- package/dist/wirings/ai-agent/ai-agent-stream.d.ts +11 -0
- package/dist/wirings/ai-agent/ai-agent-stream.js +503 -0
- package/dist/wirings/ai-agent/ai-agent.types.d.ts +254 -0
- package/dist/wirings/ai-agent/ai-agent.types.js +1 -0
- package/dist/wirings/ai-agent/index.d.ts +5 -0
- package/dist/wirings/ai-agent/index.js +4 -0
- package/dist/wirings/channel/channel-common.d.ts +7 -4
- package/dist/wirings/channel/channel-common.js +15 -8
- package/dist/wirings/channel/channel-handler.js +13 -4
- 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.js +12 -12
- package/dist/wirings/channel/channel.types.d.ts +5 -1
- 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.js +18 -6
- package/dist/wirings/channel/log-channels.js +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.js +17 -6
- package/dist/wirings/cli/channel/cli-channel-runner.js +3 -2
- 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 +1 -1
- package/dist/wirings/cli/cli-runner.js +22 -18
- package/dist/wirings/cli/cli.types.d.ts +7 -6
- 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 +2 -2
- package/dist/wirings/http/http-runner.js +62 -27
- package/dist/wirings/http/http.types.d.ts +77 -24
- package/dist/wirings/http/index.d.ts +5 -4
- package/dist/wirings/http/index.js +4 -3
- package/dist/wirings/http/log-http-routes.js +1 -1
- package/dist/wirings/http/routers/path-to-regex.js +2 -2
- package/dist/wirings/mcp/index.d.ts +4 -3
- package/dist/wirings/mcp/index.js +3 -3
- package/dist/wirings/mcp/mcp-runner.d.ts +1 -3
- package/dist/wirings/mcp/mcp-runner.js +42 -56
- package/dist/wirings/mcp/mcp.types.d.ts +3 -3
- 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 +2 -2
- package/dist/wirings/queue/index.js +1 -1
- package/dist/wirings/queue/queue-runner.d.ts +7 -0
- package/dist/wirings/queue/queue-runner.js +23 -12
- package/dist/wirings/queue/queue.types.d.ts +8 -2
- package/dist/wirings/rpc/index.d.ts +1 -1
- package/dist/wirings/rpc/index.js +1 -1
- package/dist/wirings/rpc/rpc-runner.d.ts +40 -13
- package/dist/wirings/rpc/rpc-runner.js +191 -25
- package/dist/wirings/rpc/rpc-types.d.ts +15 -4
- package/dist/wirings/scheduler/index.d.ts +3 -3
- package/dist/wirings/scheduler/index.js +2 -3
- package/dist/wirings/scheduler/log-schedulers.js +1 -1
- package/dist/wirings/scheduler/scheduler-runner.d.ts +5 -0
- package/dist/wirings/scheduler/scheduler-runner.js +28 -10
- 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 -0
- package/dist/wirings/trigger/index.js +2 -0
- package/dist/wirings/trigger/pikku-trigger-service.d.ts +26 -0
- package/dist/wirings/trigger/pikku-trigger-service.js +75 -0
- package/dist/wirings/trigger/trigger-runner.d.ts +42 -0
- package/dist/wirings/trigger/trigger-runner.js +85 -0
- package/dist/wirings/trigger/trigger.types.d.ts +130 -0
- package/dist/wirings/trigger/trigger.types.js +40 -0
- 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 +5 -0
- package/dist/wirings/workflow/dsl/index.js +4 -0
- package/dist/wirings/workflow/dsl/workflow-dsl.types.d.ts +292 -0
- package/dist/wirings/workflow/dsl/workflow-dsl.types.js +5 -0
- package/dist/wirings/workflow/dsl/workflow-runner.d.ts +5 -0
- package/dist/wirings/workflow/dsl/workflow-runner.js +23 -0
- package/dist/wirings/workflow/graph/graph-node.d.ts +117 -0
- package/dist/wirings/workflow/graph/graph-node.js +58 -0
- package/dist/wirings/workflow/graph/graph-runner.d.ts +9 -0
- package/dist/wirings/workflow/graph/graph-runner.js +540 -0
- package/dist/wirings/workflow/graph/index.d.ts +4 -0
- package/dist/wirings/workflow/graph/index.js +3 -0
- 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 +82 -0
- package/dist/wirings/workflow/graph/workflow-graph.types.js +15 -0
- package/dist/wirings/workflow/index.d.ts +7 -12
- package/dist/wirings/workflow/index.js +8 -11
- package/dist/wirings/workflow/pikku-workflow-service.d.ts +114 -10
- package/dist/wirings/workflow/pikku-workflow-service.js +386 -115
- package/dist/wirings/workflow/workflow-helpers.d.ts +36 -0
- package/dist/wirings/workflow/workflow-helpers.js +38 -0
- package/dist/wirings/workflow/workflow-utils.d.ts +1 -0
- package/dist/wirings/workflow/workflow-utils.js +1 -0
- package/dist/wirings/workflow/workflow.types.d.ts +83 -214
- package/package.json +13 -6
- package/run-tests.sh +4 -1
- package/src/crypto-utils.ts +99 -0
- package/src/errors/error-handler.ts +3 -3
- package/src/errors/errors.ts +17 -0
- package/src/errors/index.ts +0 -1
- package/src/factory-functions.test.ts +42 -2
- package/src/function/function-runner.test.ts +5 -12
- package/src/function/function-runner.ts +195 -40
- package/src/function/functions.types.ts +66 -14
- package/src/function/index.ts +5 -2
- package/src/handle-error.ts +2 -10
- package/src/index.ts +106 -27
- package/src/middleware/auth-apikey.test.ts +15 -12
- package/src/middleware/auth-apikey.ts +3 -3
- package/src/middleware/auth-bearer.test.ts +17 -14
- package/src/middleware/auth-bearer.ts +25 -27
- package/src/middleware/auth-cookie.test.ts +16 -13
- package/src/middleware/auth-cookie.ts +6 -8
- package/src/middleware/cors.ts +96 -0
- package/src/middleware/index.ts +5 -3
- package/src/middleware/remote-auth.ts +68 -0
- package/src/middleware-runner.test.ts +122 -0
- package/src/middleware-runner.ts +24 -17
- package/src/permissions.test.ts +102 -86
- package/src/permissions.ts +32 -93
- package/src/pikku-state.ts +168 -201
- package/src/run-tests-script.test.ts +49 -0
- package/src/schema.ts +50 -18
- package/src/services/ai-agent-runner-service.ts +29 -0
- package/src/services/ai-run-state-service.ts +20 -0
- package/src/services/ai-storage-service.ts +39 -0
- package/src/services/deployment-service.ts +22 -0
- package/src/services/gopass-secrets.ts +95 -0
- package/src/services/in-memory-trigger-service.ts +68 -0
- package/src/services/in-memory-workflow-service.ts +395 -0
- package/src/services/index.ts +49 -14
- package/src/services/local-secrets.ts +51 -0
- package/src/services/local-variables.ts +22 -0
- package/src/services/scheduler-service.ts +29 -1
- package/src/services/schema-service.ts +7 -0
- package/src/services/scoped-secret-service.ts +41 -0
- package/src/services/secret-service.ts +25 -4
- package/src/services/trigger-service.ts +38 -0
- package/src/services/typed-secret-service.ts +70 -0
- package/src/services/typed-variables-service.ts +81 -0
- package/src/services/user-session-service.ts +23 -0
- package/src/services/variables-service.ts +5 -0
- package/src/services/workflow-service.ts +94 -0
- package/src/types/core.types.ts +82 -8
- package/src/types/state.types.ts +169 -0
- package/src/utils.ts +74 -5
- package/src/version.test.ts +80 -0
- package/src/version.ts +25 -0
- package/src/wirings/ai-agent/ai-agent-memory.ts +300 -0
- package/src/wirings/ai-agent/ai-agent-model-config.ts +43 -0
- package/src/wirings/ai-agent/ai-agent-prepare.ts +470 -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 +75 -0
- package/src/wirings/ai-agent/ai-agent-runner.ts +137 -0
- package/src/wirings/ai-agent/ai-agent-stream.test.ts +246 -0
- package/src/wirings/ai-agent/ai-agent-stream.ts +774 -0
- package/src/wirings/ai-agent/ai-agent.types.ts +273 -0
- package/src/wirings/ai-agent/index.ts +28 -0
- package/src/wirings/channel/channel-common.ts +32 -19
- package/src/wirings/channel/channel-handler.ts +18 -5
- package/src/wirings/channel/channel-middleware-runner.ts +119 -0
- package/src/wirings/channel/channel-runner.ts +14 -15
- package/src/wirings/channel/channel.types.ts +17 -1
- 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 +47 -2
- package/src/wirings/channel/local/local-channel-runner.ts +22 -6
- package/src/wirings/channel/log-channels.ts +1 -1
- package/src/wirings/channel/serverless/index.ts +5 -1
- package/src/wirings/channel/serverless/serverless-channel-runner.ts +22 -6
- package/src/wirings/cli/channel/cli-channel-runner.ts +4 -3
- package/src/wirings/cli/channel/index.ts +1 -1
- package/src/wirings/cli/cli-runner.test.ts +28 -28
- package/src/wirings/cli/cli-runner.ts +27 -19
- package/src/wirings/cli/cli.types.ts +12 -11
- package/src/wirings/cli/command-parser.test.ts +8 -8
- 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 +5 -5
- package/src/wirings/http/http-runner.ts +80 -29
- package/src/wirings/http/http.types.ts +121 -23
- package/src/wirings/http/index.ts +16 -4
- package/src/wirings/http/log-http-routes.ts +1 -1
- package/src/wirings/http/routers/path-to-regex.test.ts +30 -19
- package/src/wirings/http/routers/path-to-regex.ts +2 -2
- package/src/wirings/mcp/index.ts +27 -3
- package/src/wirings/mcp/mcp-endpoint-registry.test.ts +3 -3
- package/src/wirings/mcp/mcp-runner.ts +56 -67
- package/src/wirings/mcp/mcp.types.ts +3 -3
- 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 +14 -2
- package/src/wirings/queue/queue-runner.test.ts +115 -73
- package/src/wirings/queue/queue-runner.ts +39 -13
- package/src/wirings/queue/queue.types.ts +12 -2
- package/src/wirings/rpc/index.ts +1 -1
- package/src/wirings/rpc/rpc-runner.ts +270 -34
- package/src/wirings/rpc/rpc-types.ts +21 -4
- package/src/wirings/scheduler/index.ts +7 -4
- package/src/wirings/scheduler/log-schedulers.ts +1 -1
- package/src/wirings/scheduler/scheduler-runner.test.ts +97 -53
- package/src/wirings/scheduler/scheduler-runner.ts +50 -10
- package/src/wirings/secret/index.ts +9 -0
- package/src/wirings/secret/secret.types.ts +32 -0
- package/src/wirings/secret/validate-secret-definitions.ts +82 -0
- package/src/wirings/trigger/index.ts +10 -0
- package/src/wirings/trigger/pikku-trigger-service.ts +134 -0
- package/src/wirings/trigger/trigger-runner.ts +138 -0
- package/src/wirings/trigger/trigger.types.ts +178 -0
- package/src/wirings/variable/index.ts +8 -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 +31 -0
- package/src/wirings/workflow/dsl/workflow-dsl.types.ts +320 -0
- package/src/wirings/workflow/dsl/workflow-runner.ts +28 -0
- package/src/wirings/workflow/graph/graph-node.ts +222 -0
- package/src/wirings/workflow/graph/graph-runner.test.ts +495 -0
- package/src/wirings/workflow/graph/graph-runner.ts +816 -0
- package/src/wirings/workflow/graph/index.ts +14 -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 +104 -0
- package/src/wirings/workflow/index.ts +64 -26
- package/src/wirings/workflow/pikku-workflow-service.test.ts +212 -0
- package/src/wirings/workflow/pikku-workflow-service.ts +571 -136
- package/src/wirings/workflow/workflow-helpers.ts +79 -0
- package/src/wirings/workflow/workflow-utils.ts +0 -0
- package/src/wirings/workflow/workflow.types.ts +123 -279
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/wirings/workflow/workflow-runner.d.ts +0 -34
- package/dist/wirings/workflow/workflow-runner.js +0 -65
- package/src/function/function-runner.ts.bak +0 -188
- package/src/wirings/workflow/workflow-runner.ts +0 -72
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export * from './eventhub-store.js';
|
|
1
|
+
export { wireChannel, openChannel } from './channel-runner.js';
|
|
2
|
+
export { addChannelMiddleware, combineChannelMiddleware, wrapChannelWithMiddleware, } from './channel-middleware-runner.js';
|
|
3
|
+
export { logChannels } from './log-channels.js';
|
|
4
|
+
export { PikkuAbstractChannelHandler } from './pikku-abstract-channel-handler.js';
|
|
5
|
+
export { ChannelStore } from './channel-store.js';
|
|
6
|
+
export { EventHubStore } from './eventhub-store.js';
|
|
7
|
+
export { defineChannelRoutes } from './define-channel-routes.js';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export { PikkuLocalChannelHandler } from './local-channel-handler.js';
|
|
2
|
+
export { runLocalChannel } from './local-channel-runner.js';
|
|
3
|
+
export { LocalEventHubService } from './local-eventhub-service.js';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export { PikkuLocalChannelHandler } from './local-channel-handler.js';
|
|
2
|
+
export { runLocalChannel } from './local-channel-runner.js';
|
|
3
|
+
export { LocalEventHubService } from './local-eventhub-service.js';
|
|
@@ -4,10 +4,11 @@ import { closeWireServices } from '../../../utils.js';
|
|
|
4
4
|
import { processMessageHandlers } from '../channel-handler.js';
|
|
5
5
|
import { PikkuLocalChannelHandler } from './local-channel-handler.js';
|
|
6
6
|
import { handleHTTPError } from '../../../handle-error.js';
|
|
7
|
-
import { PikkuSessionService } from '../../../services/user-session-service.js';
|
|
7
|
+
import { PikkuSessionService, createMiddlewareSessionWireProps, } from '../../../services/user-session-service.js';
|
|
8
8
|
import { runChannelLifecycleWithMiddleware } from '../channel-common.js';
|
|
9
9
|
export const runLocalChannel = async ({ singletonServices, channelId, request, response, route, createWireServices, skipUserSession = false, respondWith404 = true, coerceDataFromSchema = true, logWarningsForStatusCodes = [], bubbleErrors = false, }) => {
|
|
10
10
|
let wireServices;
|
|
11
|
+
let closedWireServices = false;
|
|
11
12
|
let channelHandler;
|
|
12
13
|
const userSession = new PikkuSessionService();
|
|
13
14
|
let http;
|
|
@@ -39,10 +40,20 @@ export const runLocalChannel = async ({ singletonServices, channelId, request, r
|
|
|
39
40
|
try {
|
|
40
41
|
channelHandler = new PikkuLocalChannelHandler(channelId, channelConfig.name, openingData);
|
|
41
42
|
const channel = channelHandler.getChannel();
|
|
42
|
-
const wire = {
|
|
43
|
+
const wire = {
|
|
44
|
+
channel,
|
|
45
|
+
...createMiddlewareSessionWireProps(userSession),
|
|
46
|
+
};
|
|
43
47
|
if (createWireServices) {
|
|
44
48
|
wireServices = await createWireServices(singletonServices, wire);
|
|
45
49
|
}
|
|
50
|
+
const closeServices = async () => {
|
|
51
|
+
if (!wireServices || closedWireServices) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
closedWireServices = true;
|
|
55
|
+
await closeWireServices(singletonServices.logger, wireServices);
|
|
56
|
+
};
|
|
46
57
|
const services = { ...singletonServices, ...wireServices };
|
|
47
58
|
channelHandler.registerOnOpen(async () => {
|
|
48
59
|
if (channelConfig.onConnect && meta.connect) {
|
|
@@ -55,6 +66,7 @@ export const runLocalChannel = async ({ singletonServices, channelId, request, r
|
|
|
55
66
|
services,
|
|
56
67
|
channel,
|
|
57
68
|
data: openingData,
|
|
69
|
+
channelMiddlewareMeta: meta.channelMiddleware,
|
|
58
70
|
});
|
|
59
71
|
if (result !== undefined) {
|
|
60
72
|
await channel.send(result);
|
|
@@ -76,6 +88,7 @@ export const runLocalChannel = async ({ singletonServices, channelId, request, r
|
|
|
76
88
|
lifecycleType: 'disconnect',
|
|
77
89
|
services,
|
|
78
90
|
channel,
|
|
91
|
+
channelMiddlewareMeta: meta.channelMiddleware,
|
|
79
92
|
});
|
|
80
93
|
}
|
|
81
94
|
catch (e) {
|
|
@@ -83,9 +96,7 @@ export const runLocalChannel = async ({ singletonServices, channelId, request, r
|
|
|
83
96
|
channel.send({ error: e.message || 'Unknown error' });
|
|
84
97
|
}
|
|
85
98
|
}
|
|
86
|
-
|
|
87
|
-
await closeWireServices(singletonServices.logger, wireServices);
|
|
88
|
-
}
|
|
99
|
+
await closeServices();
|
|
89
100
|
});
|
|
90
101
|
const onMessage = processMessageHandlers(services, channelConfig, channelHandler, userSession);
|
|
91
102
|
channelHandler.registerOnMessage(async (data) => {
|
|
@@ -103,7 +114,8 @@ export const runLocalChannel = async ({ singletonServices, channelId, request, r
|
|
|
103
114
|
handleHTTPError(e, http, channelId, singletonServices.logger, logWarningsForStatusCodes, respondWith404, bubbleErrors);
|
|
104
115
|
}
|
|
105
116
|
finally {
|
|
106
|
-
if (wireServices) {
|
|
117
|
+
if (!channelHandler && wireServices && !closedWireServices) {
|
|
118
|
+
closedWireServices = true;
|
|
107
119
|
await closeWireServices(singletonServices.logger, wireServices);
|
|
108
120
|
}
|
|
109
121
|
}
|
|
@@ -4,7 +4,7 @@ import { pikkuState } from '../../pikku-state.js';
|
|
|
4
4
|
* @param logger - A logger for logging information.
|
|
5
5
|
*/
|
|
6
6
|
export const logChannels = (logger) => {
|
|
7
|
-
const channels = pikkuState('channel', 'channels');
|
|
7
|
+
const channels = pikkuState(null, 'channel', 'channels');
|
|
8
8
|
if (channels.size === 0) {
|
|
9
9
|
logger.info('No channels added');
|
|
10
10
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { runChannelConnect, runChannelDisconnect, runChannelMessage, } from './serverless-channel-runner.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { runChannelConnect, runChannelDisconnect, runChannelMessage, } from './serverless-channel-runner.js';
|
|
@@ -3,14 +3,14 @@ import { processMessageHandlers } from '../channel-handler.js';
|
|
|
3
3
|
import { openChannel } from '../channel-runner.js';
|
|
4
4
|
import { createHTTPWire } from '../../http/http-runner.js';
|
|
5
5
|
import { handleHTTPError } from '../../../handle-error.js';
|
|
6
|
-
import { PikkuSessionService } from '../../../services/user-session-service.js';
|
|
6
|
+
import { PikkuSessionService, createMiddlewareSessionWireProps, } from '../../../services/user-session-service.js';
|
|
7
7
|
import { pikkuState } from '../../../pikku-state.js';
|
|
8
8
|
import { PikkuFetchHTTPRequest } from '../../http/pikku-fetch-http-request.js';
|
|
9
9
|
import { runChannelLifecycleWithMiddleware } from '../channel-common.js';
|
|
10
10
|
const getVariablesForChannel = ({ channelId, channelName, channelHandlerFactory, openingData, }) => {
|
|
11
|
-
const channels = pikkuState('channel', 'channels');
|
|
11
|
+
const channels = pikkuState(null, 'channel', 'channels');
|
|
12
12
|
const channelConfig = channels.get(channelName);
|
|
13
|
-
const channelsMeta = pikkuState('channel', 'meta');
|
|
13
|
+
const channelsMeta = pikkuState(null, 'channel', 'meta');
|
|
14
14
|
const meta = channelsMeta[channelName];
|
|
15
15
|
if (!channelConfig) {
|
|
16
16
|
throw new Error(`Channel not found: ${channelName}`);
|
|
@@ -54,7 +54,10 @@ export const runChannelConnect = async ({ singletonServices, channelId, channelO
|
|
|
54
54
|
channelHandlerFactory,
|
|
55
55
|
channelName: channelConfig.name,
|
|
56
56
|
});
|
|
57
|
-
const wire = {
|
|
57
|
+
const wire = {
|
|
58
|
+
channel,
|
|
59
|
+
...createMiddlewareSessionWireProps(userSession),
|
|
60
|
+
};
|
|
58
61
|
if (createWireServices) {
|
|
59
62
|
wireServices = await createWireServices(singletonServices, wire);
|
|
60
63
|
}
|
|
@@ -71,6 +74,7 @@ export const runChannelConnect = async ({ singletonServices, channelId, channelO
|
|
|
71
74
|
services,
|
|
72
75
|
channel,
|
|
73
76
|
data: openingData,
|
|
77
|
+
channelMiddlewareMeta: meta.channelMiddleware,
|
|
74
78
|
});
|
|
75
79
|
}
|
|
76
80
|
http?.response?.status(101);
|
|
@@ -106,7 +110,10 @@ export const runChannelDisconnect = async ({ singletonServices, ...params }) =>
|
|
|
106
110
|
});
|
|
107
111
|
const userSession = new PikkuSessionService(params.channelStore, params.channelId);
|
|
108
112
|
userSession.setInitial(session);
|
|
109
|
-
const wire = {
|
|
113
|
+
const wire = {
|
|
114
|
+
channel,
|
|
115
|
+
...createMiddlewareSessionWireProps(userSession),
|
|
116
|
+
};
|
|
110
117
|
if (!wireServices && params.createWireServices) {
|
|
111
118
|
wireServices = await params.createWireServices(singletonServices, wire);
|
|
112
119
|
}
|
|
@@ -123,6 +130,7 @@ export const runChannelDisconnect = async ({ singletonServices, ...params }) =>
|
|
|
123
130
|
lifecycleType: 'disconnect',
|
|
124
131
|
services,
|
|
125
132
|
channel,
|
|
133
|
+
channelMiddlewareMeta: meta.channelMiddleware,
|
|
126
134
|
});
|
|
127
135
|
}
|
|
128
136
|
catch (e) {
|
|
@@ -144,7 +152,10 @@ export const runChannelMessage = async ({ singletonServices, ...params }, data)
|
|
|
144
152
|
});
|
|
145
153
|
const userSession = new PikkuSessionService(params.channelStore, params.channelId);
|
|
146
154
|
userSession.setInitial(session);
|
|
147
|
-
const wire = {
|
|
155
|
+
const wire = {
|
|
156
|
+
channel,
|
|
157
|
+
...createMiddlewareSessionWireProps(userSession),
|
|
158
|
+
};
|
|
148
159
|
if (params.createWireServices) {
|
|
149
160
|
wireServices = await params.createWireServices(singletonServices, wire);
|
|
150
161
|
}
|
|
@@ -12,10 +12,11 @@ const defaultJSONRenderer = (_services, data) => {
|
|
|
12
12
|
*/
|
|
13
13
|
export async function executeCLIViaChannel({ programName, pikkuWS, args = process.argv.slice(2), renderers = {}, defaultRenderer, }) {
|
|
14
14
|
// Get CLI metadata from state
|
|
15
|
-
const
|
|
16
|
-
if (!
|
|
15
|
+
const cliMeta = pikkuState(null, 'cli', 'meta');
|
|
16
|
+
if (!cliMeta || !('programs' in cliMeta)) {
|
|
17
17
|
throw new Error('[PKU342] CLI metadata not found. No CLI wirings were registered. See https://pikku.dev/docs/pikku-cli/errors/pku342 for more information.');
|
|
18
18
|
}
|
|
19
|
+
const allCLIMeta = cliMeta;
|
|
19
20
|
const programMeta = allCLIMeta.programs[programName];
|
|
20
21
|
if (!programMeta) {
|
|
21
22
|
console.error(`Error: CLI program "${programName}" not found`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { executeCLIViaChannel } from './cli-channel-runner.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { executeCLIViaChannel } from './cli-channel-runner.js';
|
|
@@ -36,7 +36,7 @@ export declare const pikkuCLIRender: <Data, Services extends CoreSingletonServic
|
|
|
36
36
|
export declare function executeCLI({ programName, args, createConfig, createSingletonServices, createWireServices, }: {
|
|
37
37
|
programName: string;
|
|
38
38
|
args?: string[];
|
|
39
|
-
createConfig
|
|
39
|
+
createConfig?: CreateConfig<any, any>;
|
|
40
40
|
createSingletonServices: CreateSingletonServices<any, any>;
|
|
41
41
|
createWireServices?: CreateWireServices<any, any, any>;
|
|
42
42
|
}): Promise<void>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { NotFoundError } from '../../errors/errors.js';
|
|
1
|
+
import { NotFoundError, PikkuMissingMetaError } from '../../errors/errors.js';
|
|
2
2
|
import { addFunction, runPikkuFunc } from '../../function/function-runner.js';
|
|
3
3
|
import { pikkuState } from '../../pikku-state.js';
|
|
4
|
-
import { PikkuSessionService } from '../../services/user-session-service.js';
|
|
4
|
+
import { PikkuSessionService, createMiddlewareSessionWireProps, } from '../../services/user-session-service.js';
|
|
5
5
|
import { LocalVariablesService } from '../../services/local-variables.js';
|
|
6
6
|
import { generateCommandHelp, parseCLIArguments } from './command-parser.js';
|
|
7
7
|
/**
|
|
@@ -27,12 +27,12 @@ const defaultJSONRenderer = (_services, data) => {
|
|
|
27
27
|
*/
|
|
28
28
|
export const wireCLI = (cli) => {
|
|
29
29
|
// Get the existing metadata that was generated during inspection
|
|
30
|
-
const cliMeta = pikkuState('cli', 'meta') || {};
|
|
30
|
+
const cliMeta = pikkuState(null, 'cli', 'meta') || {};
|
|
31
31
|
if (!cliMeta.programs?.[cli.program]) {
|
|
32
|
-
throw new
|
|
32
|
+
throw new PikkuMissingMetaError(`CLI metadata not found for program '${cli.program}'`);
|
|
33
33
|
}
|
|
34
34
|
// Get existing programs state and add this program
|
|
35
|
-
const programs = pikkuState('cli', 'programs') || {};
|
|
35
|
+
const programs = pikkuState(null, 'cli', 'programs') || {};
|
|
36
36
|
programs[cli.program] = {
|
|
37
37
|
defaultRenderer: (cli.render ||
|
|
38
38
|
defaultJSONRenderer),
|
|
@@ -40,7 +40,7 @@ export const wireCLI = (cli) => {
|
|
|
40
40
|
renderers: {},
|
|
41
41
|
tags: cli.tags,
|
|
42
42
|
};
|
|
43
|
-
pikkuState('cli', 'programs', programs);
|
|
43
|
+
pikkuState(null, 'cli', 'programs', programs);
|
|
44
44
|
// Register all command functions recursively
|
|
45
45
|
registerCLICommands(cli.commands, [], cli.options || {}, cli.program);
|
|
46
46
|
};
|
|
@@ -72,7 +72,7 @@ function unwrapFunc(command) {
|
|
|
72
72
|
*/
|
|
73
73
|
function registerCLICommands(commands, path = [], inheritedOptions = {}, program) {
|
|
74
74
|
// Get the CLI metadata to find actual function names
|
|
75
|
-
const cliMeta = pikkuState('cli', 'meta').programs[program];
|
|
75
|
+
const cliMeta = pikkuState(null, 'cli', 'meta').programs[program];
|
|
76
76
|
for (const [name, command] of Object.entries(commands)) {
|
|
77
77
|
const fullPath = [...path, name];
|
|
78
78
|
const commandId = fullPath.join('.');
|
|
@@ -81,7 +81,7 @@ function registerCLICommands(commands, path = [], inheritedOptions = {}, program
|
|
|
81
81
|
for (let i = 1; i < fullPath.length; i++) {
|
|
82
82
|
currentMeta = currentMeta?.subcommands?.[fullPath[i]];
|
|
83
83
|
}
|
|
84
|
-
const funcName = currentMeta?.
|
|
84
|
+
const funcName = currentMeta?.pikkuFuncId;
|
|
85
85
|
// Skip if no function name (could be a command group)
|
|
86
86
|
if (!funcName) {
|
|
87
87
|
// Recursively register subcommands if they exist
|
|
@@ -96,7 +96,7 @@ function registerCLICommands(commands, path = [], inheritedOptions = {}, program
|
|
|
96
96
|
const commandOptions = typeof command === 'object' ? command.options || {} : {};
|
|
97
97
|
const mergedOptions = { ...inheritedOptions, ...commandOptions };
|
|
98
98
|
// Store the options and middleware in program state for use during execution
|
|
99
|
-
const programs = pikkuState('cli', 'programs');
|
|
99
|
+
const programs = pikkuState(null, 'cli', 'programs');
|
|
100
100
|
if (programs[program]) {
|
|
101
101
|
if (!programs[program].commandOptions) {
|
|
102
102
|
programs[program].commandOptions = {};
|
|
@@ -127,10 +127,10 @@ function registerCLICommands(commands, path = [], inheritedOptions = {}, program
|
|
|
127
127
|
* Plucks only the data that the function expects based on its schema
|
|
128
128
|
*/
|
|
129
129
|
function pluckCLIData(mergedData, funcName, availableOptions) {
|
|
130
|
-
const funcMeta = pikkuState('function', 'meta')[funcName];
|
|
130
|
+
const funcMeta = pikkuState(null, 'function', 'meta')[funcName];
|
|
131
131
|
const schemaName = funcMeta?.inputSchemaName;
|
|
132
132
|
const schema = schemaName
|
|
133
|
-
? pikkuState('misc', 'schemas').get(schemaName)
|
|
133
|
+
? pikkuState(null, 'misc', 'schemas').get(schemaName)
|
|
134
134
|
: null;
|
|
135
135
|
if (schema && schema.properties) {
|
|
136
136
|
// If we have a schema, only include fields that are in the schema
|
|
@@ -156,7 +156,7 @@ function pluckCLIData(mergedData, funcName, availableOptions) {
|
|
|
156
156
|
*/
|
|
157
157
|
export async function runCLICommand({ program, commandPath, data, singletonServices, createWireServices, }) {
|
|
158
158
|
// Get the command metadata to find the function name
|
|
159
|
-
const cliMeta = pikkuState('cli', 'meta');
|
|
159
|
+
const cliMeta = pikkuState(null, 'cli', 'meta');
|
|
160
160
|
const programMeta = cliMeta.programs?.[program];
|
|
161
161
|
if (!programMeta) {
|
|
162
162
|
throw new NotFoundError(`Program not found: ${program}`);
|
|
@@ -173,9 +173,9 @@ export async function runCLICommand({ program, commandPath, data, singletonServi
|
|
|
173
173
|
}
|
|
174
174
|
currentCommand = currentCommand.subcommands[commandPath[i]];
|
|
175
175
|
}
|
|
176
|
-
const funcName = currentCommand.
|
|
176
|
+
const funcName = currentCommand.pikkuFuncId;
|
|
177
177
|
// Get program-specific data
|
|
178
|
-
const programs = pikkuState('cli', 'programs') || {};
|
|
178
|
+
const programs = pikkuState(null, 'cli', 'programs') || {};
|
|
179
179
|
const programData = programs[program];
|
|
180
180
|
// Combine program middleware + command middleware from the hierarchy
|
|
181
181
|
const allWireMiddleware = [
|
|
@@ -222,7 +222,7 @@ export async function runCLICommand({ program, commandPath, data, singletonServi
|
|
|
222
222
|
data: pluckedData,
|
|
223
223
|
channel,
|
|
224
224
|
},
|
|
225
|
-
|
|
225
|
+
...createMiddlewareSessionWireProps(userSession),
|
|
226
226
|
};
|
|
227
227
|
try {
|
|
228
228
|
const result = await runPikkuFunc('cli', commandId, funcName, {
|
|
@@ -236,9 +236,11 @@ export async function runCLICommand({ program, commandPath, data, singletonServi
|
|
|
236
236
|
wirePermissions: undefined,
|
|
237
237
|
tags: programData?.tags,
|
|
238
238
|
wire,
|
|
239
|
+
sessionService: userSession,
|
|
239
240
|
});
|
|
240
241
|
// Apply renderer one final time with the final output (if renderer exists)
|
|
241
|
-
if (
|
|
242
|
+
// Skip if result is undefined (void functions handle their own output)
|
|
243
|
+
if (renderer && result !== undefined) {
|
|
242
244
|
await Promise.resolve(renderer(singletonServices, result, userSession.get()));
|
|
243
245
|
}
|
|
244
246
|
return result;
|
|
@@ -266,7 +268,7 @@ export async function executeCLI({ programName, args, createConfig, createSingle
|
|
|
266
268
|
}
|
|
267
269
|
try {
|
|
268
270
|
// Get CLI metadata from state
|
|
269
|
-
const allCLIMeta = pikkuState('cli', 'meta');
|
|
271
|
+
const allCLIMeta = pikkuState(null, 'cli', 'meta');
|
|
270
272
|
if (!allCLIMeta) {
|
|
271
273
|
throw new Error('[PKU342] CLI metadata not found. No CLI wirings were registered. See https://pikku.dev/docs/pikku-cli/errors/pku342 for more information.');
|
|
272
274
|
}
|
|
@@ -306,7 +308,9 @@ export async function executeCLI({ programName, args, createConfig, createSingle
|
|
|
306
308
|
// Merge positionals and options into single data object
|
|
307
309
|
const data = { ...parsed.positionals, ...parsed.options };
|
|
308
310
|
// Create config (pass data in case it needs to use any parsed options)
|
|
309
|
-
const config =
|
|
311
|
+
const config = createConfig
|
|
312
|
+
? await createConfig(new LocalVariablesService(), data)
|
|
313
|
+
: {};
|
|
310
314
|
// Create services with config
|
|
311
315
|
const singletonServices = await createSingletonServices(config);
|
|
312
316
|
// Execute the command
|
|
@@ -51,7 +51,7 @@ export interface CLIProgramState {
|
|
|
51
51
|
*/
|
|
52
52
|
export interface CLICommandMeta {
|
|
53
53
|
parameters?: string;
|
|
54
|
-
|
|
54
|
+
pikkuFuncId: string;
|
|
55
55
|
positionals: CLIPositional[];
|
|
56
56
|
options: Record<string, CLIOption>;
|
|
57
57
|
renderName?: string;
|
|
@@ -100,7 +100,7 @@ export type CorePikkuCLIRender<Data, Services extends CoreSingletonServices = Co
|
|
|
100
100
|
/**
|
|
101
101
|
* Extract input parameters from a Pikku function config type
|
|
102
102
|
*/
|
|
103
|
-
export type ExtractFunctionInput<Func> = Func extends CorePikkuFunctionConfig<infer FuncType, any, any> ? FuncType extends CorePikkuFunction<infer Input, any, any, any> | CorePikkuFunctionSessionless<infer Input, any, any, any> ? Input : never : never;
|
|
103
|
+
export type ExtractFunctionInput<Func> = Func extends CorePikkuFunctionConfig<infer FuncType, any, any> ? FuncType extends CorePikkuFunction<infer Input, any, any, any, any> | CorePikkuFunctionSessionless<infer Input, any, any, any, any> ? Input : never : never;
|
|
104
104
|
/**
|
|
105
105
|
* Strip < > [ ] characters from a string
|
|
106
106
|
*/
|
|
@@ -132,7 +132,7 @@ export type ValidateParameters<Params extends string, Input> = AllParamsValid<Ex
|
|
|
132
132
|
/**
|
|
133
133
|
* Extract output type from a Pikku function config type
|
|
134
134
|
*/
|
|
135
|
-
export type ExtractFunctionOutput<Func> = Func extends CorePikkuFunctionConfig<infer FuncType, any, any> ? FuncType extends CorePikkuFunction<any, infer Output, any, any> | CorePikkuFunctionSessionless<any, infer Output, any, any> ? Output : never : never;
|
|
135
|
+
export type ExtractFunctionOutput<Func> = Func extends CorePikkuFunctionConfig<infer FuncType, any, any> ? FuncType extends CorePikkuFunction<any, infer Output, any, any, any> | CorePikkuFunctionSessionless<any, infer Output, any, any, any> ? Output : never : never;
|
|
136
136
|
/**
|
|
137
137
|
* CLI command configuration that infers options from function input type.
|
|
138
138
|
* This is a helper type for creating type-safe CLI commands.
|
|
@@ -140,6 +140,7 @@ export type ExtractFunctionOutput<Func> = Func extends CorePikkuFunctionConfig<i
|
|
|
140
140
|
export type CoreCLICommandConfig<FuncConfig, PikkuMiddleware extends CorePikkuMiddleware<any, any> = CorePikkuMiddleware<any, any>, PikkuCLIRender extends CorePikkuCLIRender<any, any, any> = CorePikkuCLIRender<any, any>, Params extends string = string> = {
|
|
141
141
|
parameters?: ValidateParameters<Params, ExtractFunctionInput<FuncConfig>>;
|
|
142
142
|
func?: FuncConfig;
|
|
143
|
+
title?: string;
|
|
143
144
|
description?: string;
|
|
144
145
|
render?: PikkuCLIRender;
|
|
145
146
|
options?: {
|
|
@@ -158,7 +159,7 @@ export type CoreCLICommandConfig<FuncConfig, PikkuMiddleware extends CorePikkuMi
|
|
|
158
159
|
/**
|
|
159
160
|
* CLI command definition
|
|
160
161
|
*/
|
|
161
|
-
export interface CoreCLICommand<In, Out, PikkuFunctionConfig extends CorePikkuFunctionConfig<CorePikkuFunction<In, Out, any, any> | CorePikkuFunctionSessionless<In, Out, any, any>>, PikkuPermission extends CorePikkuPermission<any, any, any>, PikkuMiddleware extends CorePikkuMiddleware, Options = any, Subcommands extends Record<string, CoreCLICommandConfig<any, any, any>> = Record<string, CoreCLICommandConfig<any, any, any>>> {
|
|
162
|
+
export interface CoreCLICommand<In, Out, PikkuFunctionConfig extends CorePikkuFunctionConfig<CorePikkuFunction<In, Out, any, any, any> | CorePikkuFunctionSessionless<In, Out, any, any, any>>, PikkuPermission extends CorePikkuPermission<any, any, any>, PikkuMiddleware extends CorePikkuMiddleware, Options = any, Subcommands extends Record<string, CoreCLICommandConfig<any, any, any>> = Record<string, CoreCLICommandConfig<any, any, any>>> {
|
|
162
163
|
parameters?: string;
|
|
163
164
|
func: PikkuFunctionConfig;
|
|
164
165
|
render?: CorePikkuCLIRender<Out>;
|
|
@@ -176,11 +177,11 @@ export interface CoreCLICommand<In, Out, PikkuFunctionConfig extends CorePikkuFu
|
|
|
176
177
|
/**
|
|
177
178
|
* Shorthand command definition (just a function)
|
|
178
179
|
*/
|
|
179
|
-
export type CLICommandShorthand<In, Out, PikkuFunctionConfig extends CorePikkuFunctionConfig<CorePikkuFunction<In, Out, any, any> | CorePikkuFunctionSessionless<In, Out, any, any>>> = PikkuFunctionConfig;
|
|
180
|
+
export type CLICommandShorthand<In, Out, PikkuFunctionConfig extends CorePikkuFunctionConfig<CorePikkuFunction<In, Out, any, any, any> | CorePikkuFunctionSessionless<In, Out, any, any, any>>> = PikkuFunctionConfig;
|
|
180
181
|
/**
|
|
181
182
|
* Command definition (either full or shorthand)
|
|
182
183
|
*/
|
|
183
|
-
export type CLICommandDefinition<In, Out, PikkuFunctionConfig extends CorePikkuFunctionConfig<CorePikkuFunction<In, Out, any, any> | CorePikkuFunctionSessionless<In, Out, any, any>>, PikkuPermission extends CorePikkuPermission<any, any, any>, PikkuMiddleware extends CorePikkuMiddleware, Options = any, Subcommands extends Record<string, CoreCLICommandConfig<any, any, any>> = Record<string, CoreCLICommandConfig<any, any, any>>> = CoreCLICommand<In, Out, PikkuFunctionConfig, PikkuPermission, PikkuMiddleware, Options, Subcommands> | CLICommandShorthand<In, Out, PikkuFunctionConfig>;
|
|
184
|
+
export type CLICommandDefinition<In, Out, PikkuFunctionConfig extends CorePikkuFunctionConfig<CorePikkuFunction<In, Out, any, any, any> | CorePikkuFunctionSessionless<In, Out, any, any, any>>, PikkuPermission extends CorePikkuPermission<any, any, any>, PikkuMiddleware extends CorePikkuMiddleware, Options = any, Subcommands extends Record<string, CoreCLICommandConfig<any, any, any>> = Record<string, CoreCLICommandConfig<any, any, any>>> = CoreCLICommand<In, Out, PikkuFunctionConfig, PikkuPermission, PikkuMiddleware, Options, Subcommands> | CLICommandShorthand<In, Out, PikkuFunctionConfig>;
|
|
184
185
|
/**
|
|
185
186
|
* CLI wiring configuration
|
|
186
187
|
*/
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CoreCLICommandConfig } from './cli.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Type-safe helper for defining CLI commands that can be composed.
|
|
4
|
+
* Returns the commands record as-is (identity function) for use with `wireCLI`.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* export const chatCommands = defineCLICommands({
|
|
9
|
+
* chat: pikkuCLICommand({ func: chatFunc }),
|
|
10
|
+
* 'chat:history': pikkuCLICommand({ func: historyFunc }),
|
|
11
|
+
* })
|
|
12
|
+
*
|
|
13
|
+
* wireCLI({
|
|
14
|
+
* program: 'my-app',
|
|
15
|
+
* commands: { ...chatCommands, other: pikkuCLICommand({ func: otherFunc }) }
|
|
16
|
+
* })
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function defineCLICommands<T extends Record<string, CoreCLICommandConfig<any, any, any, any>>>(commands: T): T;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-safe helper for defining CLI commands that can be composed.
|
|
3
|
+
* Returns the commands record as-is (identity function) for use with `wireCLI`.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* export const chatCommands = defineCLICommands({
|
|
8
|
+
* chat: pikkuCLICommand({ func: chatFunc }),
|
|
9
|
+
* 'chat:history': pikkuCLICommand({ func: historyFunc }),
|
|
10
|
+
* })
|
|
11
|
+
*
|
|
12
|
+
* wireCLI({
|
|
13
|
+
* program: 'my-app',
|
|
14
|
+
* commands: { ...chatCommands, other: pikkuCLICommand({ func: otherFunc }) }
|
|
15
|
+
* })
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export function defineCLICommands(commands) {
|
|
19
|
+
return commands;
|
|
20
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export * from './cli.types.js';
|
|
2
|
-
export * from './cli-runner.js';
|
|
3
|
-
export * from './command-parser.js';
|
|
4
1
|
export { wireCLI, runCLICommand, pikkuCLIRender, executeCLI, CLIError, } from './cli-runner.js';
|
|
5
2
|
export { parseCLIArguments, generateCommandHelp } from './command-parser.js';
|
|
3
|
+
export { defineCLICommands } from './define-cli-commands.js';
|
|
4
|
+
export type { CLIMeta, CLICommandMeta, CLIProgramMeta, CoreCLI, CoreCLICommandConfig, CorePikkuCLIRender, } from './cli.types.js';
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export * from './cli.types.js';
|
|
2
|
-
export * from './cli-runner.js';
|
|
3
|
-
export * from './command-parser.js';
|
|
4
1
|
export { wireCLI, runCLICommand, pikkuCLIRender, executeCLI, CLIError, } from './cli-runner.js';
|
|
5
2
|
export { parseCLIArguments, generateCommandHelp } from './command-parser.js';
|
|
3
|
+
export { defineCLICommands } from './define-cli-commands.js';
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { HTTPRouteMap, HTTPRouteContract, HTTPRoutesGroupConfig, WireHTTPRoutesConfig } from './http.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Type-safe helper for defining route contracts that can be composed.
|
|
4
|
+
* Supports optional group-level config that cascades to all routes.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* // Simple routes without group config
|
|
9
|
+
* export const todosRoutes = defineHTTPRoutes({
|
|
10
|
+
* list: { method: 'get', route: '/todos', func: listTodos },
|
|
11
|
+
* get: { method: 'get', route: '/todos/:id', func: getTodo },
|
|
12
|
+
* })
|
|
13
|
+
*
|
|
14
|
+
* // Routes with group-level config
|
|
15
|
+
* export const todosRoutes = defineHTTPRoutes({
|
|
16
|
+
* auth: true,
|
|
17
|
+
* tags: ['todos'],
|
|
18
|
+
* routes: {
|
|
19
|
+
* list: { method: 'get', route: '/todos', func: listTodos },
|
|
20
|
+
* get: { method: 'get', route: '/todos/:id', func: getTodo },
|
|
21
|
+
* }
|
|
22
|
+
* })
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function defineHTTPRoutes<T extends HTTPRouteMap>(routes: T): HTTPRouteContract<T>;
|
|
26
|
+
export declare function defineHTTPRoutes<T extends HTTPRouteMap>(config: HTTPRoutesGroupConfig & {
|
|
27
|
+
routes: T;
|
|
28
|
+
}): HTTPRouteContract<T>;
|
|
29
|
+
/**
|
|
30
|
+
* Wires multiple HTTP routes from a nested map or array configuration.
|
|
31
|
+
* Inspired by ts-rest's contract pattern, provides a single place to wire an entire API.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* // Nested object format
|
|
36
|
+
* wireHTTPRoutes({
|
|
37
|
+
* basePath: '/api/v1',
|
|
38
|
+
* tags: ['api'],
|
|
39
|
+
* routes: {
|
|
40
|
+
* todos: {
|
|
41
|
+
* list: { method: 'get', route: '/todos', func: listTodos },
|
|
42
|
+
* get: { method: 'get', route: '/todos/:id', func: getTodo },
|
|
43
|
+
* },
|
|
44
|
+
* auth: {
|
|
45
|
+
* login: { method: 'post', route: '/auth/login', func: login, auth: false },
|
|
46
|
+
* },
|
|
47
|
+
* },
|
|
48
|
+
* })
|
|
49
|
+
*
|
|
50
|
+
* // Flat array format
|
|
51
|
+
* wireHTTPRoutes({
|
|
52
|
+
* basePath: '/api',
|
|
53
|
+
* routes: [
|
|
54
|
+
* { method: 'get', route: '/todos', func: listTodos },
|
|
55
|
+
* { method: 'post', route: '/todos', func: createTodo },
|
|
56
|
+
* ],
|
|
57
|
+
* })
|
|
58
|
+
*
|
|
59
|
+
* // Composing route contracts
|
|
60
|
+
* wireHTTPRoutes({
|
|
61
|
+
* basePath: '/api/v1',
|
|
62
|
+
* routes: {
|
|
63
|
+
* todos: todosRoutes, // from defineHTTPRoutes()
|
|
64
|
+
* auth: authRoutes, // from defineHTTPRoutes()
|
|
65
|
+
* },
|
|
66
|
+
* })
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare const wireHTTPRoutes: (config: WireHTTPRoutesConfig) => void;
|