@pikku/core 0.11.2 → 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 +33 -2
- package/dist/crypto-utils.d.ts +2 -0
- package/dist/crypto-utils.js +78 -0
- 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 +7 -1
- package/dist/function/function-runner.js +82 -23
- package/dist/function/functions.types.d.ts +31 -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.js +1 -10
- package/dist/index.d.ts +28 -26
- package/dist/index.js +18 -29
- package/dist/middleware/auth-apikey.d.ts +2 -2
- package/dist/middleware/auth-apikey.js +3 -3
- package/dist/middleware/auth-bearer.d.ts +2 -2
- package/dist/middleware/auth-bearer.js +3 -6
- package/dist/middleware/auth-cookie.d.ts +2 -2
- 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 +2 -2
- package/dist/middleware-runner.js +8 -10
- package/dist/permissions.js +11 -15
- package/dist/pikku-state.d.ts +1 -0
- package/dist/pikku-state.js +18 -8
- package/dist/schema.js +12 -11
- 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 +9 -4
- package/dist/types/core.types.d.ts +48 -12
- package/dist/types/core.types.js +8 -1
- package/dist/types/state.types.d.ts +43 -51
- package/dist/utils.d.ts +3 -2
- package/dist/utils.js +15 -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 +12 -3
- 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 +7 -7
- 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/serverless/index.d.ts +1 -1
- package/dist/wirings/channel/serverless/index.js +1 -1
- package/dist/wirings/channel/serverless/serverless-channel-runner.js +15 -4
- 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 +12 -8
- package/dist/wirings/cli/cli.types.d.ts +6 -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.js +49 -23
- package/dist/wirings/http/http.types.d.ts +78 -38
- package/dist/wirings/http/index.d.ts +5 -4
- package/dist/wirings/http/index.js +4 -3
- 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 +25 -39
- 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 +17 -6
- 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 +33 -5
- package/dist/wirings/rpc/rpc-runner.js +134 -16
- package/dist/wirings/rpc/rpc-types.d.ts +8 -4
- package/dist/wirings/scheduler/index.d.ts +3 -3
- package/dist/wirings/scheduler/index.js +2 -3
- package/dist/wirings/scheduler/scheduler-runner.d.ts +5 -0
- package/dist/wirings/scheduler/scheduler-runner.js +23 -5
- 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 +26 -0
- package/dist/wirings/trigger/pikku-trigger-service.js +75 -0
- package/dist/wirings/trigger/trigger-runner.d.ts +21 -8
- package/dist/wirings/trigger/trigger-runner.js +46 -18
- 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 +28 -14
- package/dist/wirings/workflow/pikku-workflow-service.js +200 -56
- 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 -23
- package/dist/wirings/workflow/workflow-utils.js +1 -66
- package/dist/wirings/workflow/workflow.types.d.ts +40 -93
- package/package.json +13 -15
- package/run-tests.sh +4 -1
- package/src/crypto-utils.ts +99 -0
- 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 +4 -11
- package/src/function/function-runner.ts +114 -29
- package/src/function/functions.types.ts +62 -132
- package/src/function/index.ts +5 -2
- package/src/handle-error.ts +2 -10
- package/src/index.ts +99 -25
- 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 +12 -12
- package/src/permissions.test.ts +81 -7
- package/src/permissions.ts +15 -17
- package/src/pikku-state.ts +20 -8
- package/src/run-tests-script.test.ts +49 -0
- package/src/schema.ts +18 -15
- 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 +22 -2
- package/src/types/core.types.ts +76 -11
- package/src/types/state.types.ts +37 -63
- package/src/utils.ts +20 -6
- 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 +17 -4
- package/src/wirings/channel/channel-middleware-runner.ts +119 -0
- package/src/wirings/channel/channel-runner.ts +9 -10
- 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 +44 -1
- package/src/wirings/channel/local/local-channel-runner.ts +22 -6
- package/src/wirings/channel/serverless/index.ts +5 -1
- package/src/wirings/channel/serverless/serverless-channel-runner.ts +20 -4
- package/src/wirings/cli/channel/index.ts +1 -1
- package/src/wirings/cli/cli-runner.test.ts +9 -9
- package/src/wirings/cli/cli-runner.ts +17 -10
- package/src/wirings/cli/cli.types.ts +11 -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 +3 -3
- package/src/wirings/http/http-runner.ts +63 -29
- package/src/wirings/http/http.types.ts +121 -37
- package/src/wirings/http/index.ts +16 -4
- 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 +39 -50
- 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 +97 -55
- package/src/wirings/queue/queue-runner.ts +33 -7
- package/src/wirings/queue/queue.types.ts +12 -2
- package/src/wirings/rpc/index.ts +1 -1
- package/src/wirings/rpc/rpc-runner.ts +187 -17
- package/src/wirings/rpc/rpc-types.ts +13 -4
- package/src/wirings/scheduler/index.ts +7 -4
- package/src/wirings/scheduler/scheduler-runner.test.ts +70 -26
- package/src/wirings/scheduler/scheduler-runner.ts +45 -5
- 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 -2
- package/src/wirings/trigger/pikku-trigger-service.ts +134 -0
- package/src/wirings/trigger/trigger-runner.ts +80 -38
- package/src/wirings/trigger/trigger.types.ts +144 -22
- 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 +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 +495 -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.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 +212 -0
- package/src/wirings/workflow/pikku-workflow-service.ts +285 -66
- package/src/wirings/workflow/workflow-helpers.ts +79 -0
- package/src/wirings/workflow/workflow-utils.ts +0 -120
- package/src/wirings/workflow/workflow.types.ts +45 -90
- 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/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
|
@@ -1,8 +1,23 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export
|
|
8
|
-
export
|
|
1
|
+
export { wireChannel, openChannel } from './channel-runner.js'
|
|
2
|
+
export {
|
|
3
|
+
addChannelMiddleware,
|
|
4
|
+
combineChannelMiddleware,
|
|
5
|
+
wrapChannelWithMiddleware,
|
|
6
|
+
} from './channel-middleware-runner.js'
|
|
7
|
+
export { logChannels } from './log-channels.js'
|
|
8
|
+
export { PikkuAbstractChannelHandler } from './pikku-abstract-channel-handler.js'
|
|
9
|
+
export type { EventHubService } from './eventhub-service.js'
|
|
10
|
+
export { ChannelStore } from './channel-store.js'
|
|
11
|
+
export type { Channel } from './channel-store.js'
|
|
12
|
+
export { EventHubStore } from './eventhub-store.js'
|
|
13
|
+
export type {
|
|
14
|
+
ChannelsMeta,
|
|
15
|
+
CoreChannel,
|
|
16
|
+
CorePikkuChannelMiddleware,
|
|
17
|
+
CorePikkuChannelMiddlewareFactory,
|
|
18
|
+
ChannelMessageMeta,
|
|
19
|
+
ChannelMeta,
|
|
20
|
+
PikkuChannel,
|
|
21
|
+
PikkuChannelHandlerFactory,
|
|
22
|
+
} from './channel.types.js'
|
|
23
|
+
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'
|
|
@@ -160,6 +160,49 @@ test('runChannel should return a channel handler if channel matches and no auth
|
|
|
160
160
|
|
|
161
161
|
// Simulate opening the channel
|
|
162
162
|
result.open()
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
test('runChannel should close wire services once when channel closes', async () => {
|
|
166
|
+
resetPikkuState()
|
|
167
|
+
let closeCount = 0
|
|
168
|
+
|
|
169
|
+
pikkuState(null, 'channel', 'meta', {
|
|
170
|
+
test: {
|
|
171
|
+
name: 'test',
|
|
172
|
+
route: '/test-channel',
|
|
173
|
+
},
|
|
174
|
+
} as any)
|
|
175
|
+
wireChannel({
|
|
176
|
+
name: 'test',
|
|
177
|
+
route: '/test-channel',
|
|
178
|
+
auth: false,
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
httpRouter.initialize()
|
|
182
|
+
|
|
183
|
+
const result = await runLocalChannel({
|
|
184
|
+
singletonServices: mockSingletonServices,
|
|
185
|
+
channelId: 'test-channel-id',
|
|
186
|
+
request: new PikkuMockRequest('/test-channel', 'get'),
|
|
187
|
+
response: new PikkuMockResponse(),
|
|
188
|
+
route: '/test-channel',
|
|
189
|
+
createWireServices: async () => ({
|
|
190
|
+
tracked: {
|
|
191
|
+
close: async () => {
|
|
192
|
+
closeCount += 1
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
}),
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
assert.ok(result)
|
|
199
|
+
assert.equal(closeCount, 0)
|
|
200
|
+
|
|
201
|
+
result.close()
|
|
202
|
+
await new Promise((resolve) => setTimeout(resolve, 0))
|
|
203
|
+
assert.equal(closeCount, 1)
|
|
163
204
|
|
|
164
|
-
|
|
205
|
+
result.close()
|
|
206
|
+
await new Promise((resolve) => setTimeout(resolve, 0))
|
|
207
|
+
assert.equal(closeCount, 1)
|
|
165
208
|
})
|
|
@@ -10,7 +10,10 @@ import {
|
|
|
10
10
|
import { PikkuLocalChannelHandler } from './local-channel-handler.js'
|
|
11
11
|
import { PikkuWire, WireServices } from '../../../types/core.types.js'
|
|
12
12
|
import { handleHTTPError } from '../../../handle-error.js'
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
PikkuSessionService,
|
|
15
|
+
createMiddlewareSessionWireProps,
|
|
16
|
+
} from '../../../services/user-session-service.js'
|
|
14
17
|
import { PikkuHTTP } from '../../http/http.types.js'
|
|
15
18
|
import { runChannelLifecycleWithMiddleware } from '../channel-common.js'
|
|
16
19
|
|
|
@@ -30,6 +33,7 @@ export const runLocalChannel = async ({
|
|
|
30
33
|
RunChannelOptions &
|
|
31
34
|
RunChannelParams<unknown>): Promise<PikkuLocalChannelHandler | void> => {
|
|
32
35
|
let wireServices: WireServices<typeof singletonServices> | undefined
|
|
36
|
+
let closedWireServices = false
|
|
33
37
|
|
|
34
38
|
let channelHandler: PikkuLocalChannelHandler | undefined
|
|
35
39
|
const userSession = new PikkuSessionService()
|
|
@@ -75,12 +79,23 @@ export const runLocalChannel = async ({
|
|
|
75
79
|
openingData
|
|
76
80
|
)
|
|
77
81
|
const channel = channelHandler.getChannel()
|
|
78
|
-
const wire: PikkuWire = {
|
|
82
|
+
const wire: PikkuWire = {
|
|
83
|
+
channel,
|
|
84
|
+
...createMiddlewareSessionWireProps(userSession),
|
|
85
|
+
}
|
|
79
86
|
|
|
80
87
|
if (createWireServices) {
|
|
81
88
|
wireServices = await createWireServices(singletonServices, wire)
|
|
82
89
|
}
|
|
83
90
|
|
|
91
|
+
const closeServices = async () => {
|
|
92
|
+
if (!wireServices || closedWireServices) {
|
|
93
|
+
return
|
|
94
|
+
}
|
|
95
|
+
closedWireServices = true
|
|
96
|
+
await closeWireServices(singletonServices.logger, wireServices)
|
|
97
|
+
}
|
|
98
|
+
|
|
84
99
|
const services = { ...singletonServices, ...wireServices }
|
|
85
100
|
|
|
86
101
|
channelHandler.registerOnOpen(async () => {
|
|
@@ -94,6 +109,7 @@ export const runLocalChannel = async ({
|
|
|
94
109
|
services,
|
|
95
110
|
channel,
|
|
96
111
|
data: openingData,
|
|
112
|
+
channelMiddlewareMeta: meta.channelMiddleware,
|
|
97
113
|
})
|
|
98
114
|
if (result !== undefined) {
|
|
99
115
|
await channel.send(result)
|
|
@@ -115,6 +131,7 @@ export const runLocalChannel = async ({
|
|
|
115
131
|
lifecycleType: 'disconnect',
|
|
116
132
|
services,
|
|
117
133
|
channel,
|
|
134
|
+
channelMiddlewareMeta: meta.channelMiddleware,
|
|
118
135
|
})
|
|
119
136
|
} catch (e) {
|
|
120
137
|
singletonServices.logger.error(`Error handling onDisconnect: ${e}`)
|
|
@@ -122,9 +139,7 @@ export const runLocalChannel = async ({
|
|
|
122
139
|
}
|
|
123
140
|
}
|
|
124
141
|
|
|
125
|
-
|
|
126
|
-
await closeWireServices(singletonServices.logger, wireServices)
|
|
127
|
-
}
|
|
142
|
+
await closeServices()
|
|
128
143
|
})
|
|
129
144
|
|
|
130
145
|
const onMessage = processMessageHandlers(
|
|
@@ -153,7 +168,8 @@ export const runLocalChannel = async ({
|
|
|
153
168
|
bubbleErrors
|
|
154
169
|
)
|
|
155
170
|
} finally {
|
|
156
|
-
if (wireServices) {
|
|
171
|
+
if (!channelHandler && wireServices && !closedWireServices) {
|
|
172
|
+
closedWireServices = true
|
|
157
173
|
await closeWireServices(singletonServices.logger, wireServices)
|
|
158
174
|
}
|
|
159
175
|
}
|
|
@@ -11,7 +11,10 @@ import type {
|
|
|
11
11
|
import { createHTTPWire } from '../../http/http-runner.js'
|
|
12
12
|
import { ChannelStore } from '../channel-store.js'
|
|
13
13
|
import { handleHTTPError } from '../../../handle-error.js'
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
PikkuSessionService,
|
|
16
|
+
createMiddlewareSessionWireProps,
|
|
17
|
+
} from '../../../services/user-session-service.js'
|
|
15
18
|
import { pikkuState } from '../../../pikku-state.js'
|
|
16
19
|
import { PikkuFetchHTTPRequest } from '../../http/pikku-fetch-http-request.js'
|
|
17
20
|
import { PikkuHTTP } from '../../http/http.types.js'
|
|
@@ -107,7 +110,10 @@ export const runChannelConnect = async ({
|
|
|
107
110
|
channelName: channelConfig.name,
|
|
108
111
|
})
|
|
109
112
|
|
|
110
|
-
const wire: PikkuWire = {
|
|
113
|
+
const wire: PikkuWire = {
|
|
114
|
+
channel,
|
|
115
|
+
...createMiddlewareSessionWireProps(userSession),
|
|
116
|
+
}
|
|
111
117
|
|
|
112
118
|
if (createWireServices) {
|
|
113
119
|
wireServices = await createWireServices(singletonServices, wire)
|
|
@@ -127,6 +133,7 @@ export const runChannelConnect = async ({
|
|
|
127
133
|
services,
|
|
128
134
|
channel,
|
|
129
135
|
data: openingData,
|
|
136
|
+
channelMiddlewareMeta: meta.channelMiddleware,
|
|
130
137
|
})
|
|
131
138
|
}
|
|
132
139
|
http?.response?.status(101)
|
|
@@ -175,12 +182,16 @@ export const runChannelDisconnect = async ({
|
|
|
175
182
|
openingData,
|
|
176
183
|
channelName,
|
|
177
184
|
})
|
|
185
|
+
|
|
178
186
|
const userSession = new PikkuSessionService(
|
|
179
187
|
params.channelStore,
|
|
180
188
|
params.channelId
|
|
181
189
|
)
|
|
182
190
|
userSession.setInitial(session)
|
|
183
|
-
const wire: PikkuWire = {
|
|
191
|
+
const wire: PikkuWire = {
|
|
192
|
+
channel,
|
|
193
|
+
...createMiddlewareSessionWireProps(userSession),
|
|
194
|
+
}
|
|
184
195
|
|
|
185
196
|
if (!wireServices && params.createWireServices) {
|
|
186
197
|
wireServices = await params.createWireServices(singletonServices, wire)
|
|
@@ -200,6 +211,7 @@ export const runChannelDisconnect = async ({
|
|
|
200
211
|
lifecycleType: 'disconnect',
|
|
201
212
|
services,
|
|
202
213
|
channel,
|
|
214
|
+
channelMiddlewareMeta: meta.channelMiddleware,
|
|
203
215
|
})
|
|
204
216
|
} catch (e: any) {
|
|
205
217
|
singletonServices.logger.error(
|
|
@@ -226,12 +238,16 @@ export const runChannelMessage = async (
|
|
|
226
238
|
openingData,
|
|
227
239
|
channelName,
|
|
228
240
|
})
|
|
241
|
+
|
|
229
242
|
const userSession = new PikkuSessionService(
|
|
230
243
|
params.channelStore,
|
|
231
244
|
params.channelId
|
|
232
245
|
)
|
|
233
246
|
userSession.setInitial(session)
|
|
234
|
-
const wire: PikkuWire = {
|
|
247
|
+
const wire: PikkuWire = {
|
|
248
|
+
channel,
|
|
249
|
+
...createMiddlewareSessionWireProps(userSession),
|
|
250
|
+
}
|
|
235
251
|
|
|
236
252
|
if (params.createWireServices) {
|
|
237
253
|
wireServices = await params.createWireServices(singletonServices, wire)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { executeCLIViaChannel } from './cli-channel-runner.js'
|
|
@@ -91,7 +91,7 @@ describe('CLI Runner', () => {
|
|
|
91
91
|
commands: {
|
|
92
92
|
greet: {
|
|
93
93
|
command: 'greet <name>',
|
|
94
|
-
|
|
94
|
+
pikkuFuncId: 'greetFunc',
|
|
95
95
|
positionals: [{ name: 'name', required: true }],
|
|
96
96
|
options: {},
|
|
97
97
|
},
|
|
@@ -112,7 +112,7 @@ describe('CLI Runner', () => {
|
|
|
112
112
|
|
|
113
113
|
pikkuState(null, 'function', 'meta', {
|
|
114
114
|
greetFunc: {
|
|
115
|
-
|
|
115
|
+
pikkuFuncId: 'greetFunc',
|
|
116
116
|
inputSchemaName: null,
|
|
117
117
|
outputSchemaName: null,
|
|
118
118
|
},
|
|
@@ -155,7 +155,7 @@ describe('CLI Runner', () => {
|
|
|
155
155
|
commands: {
|
|
156
156
|
test: {
|
|
157
157
|
command: 'test',
|
|
158
|
-
|
|
158
|
+
pikkuFuncId: 'testFunc',
|
|
159
159
|
positionals: [],
|
|
160
160
|
options: {},
|
|
161
161
|
},
|
|
@@ -176,7 +176,7 @@ describe('CLI Runner', () => {
|
|
|
176
176
|
|
|
177
177
|
pikkuState(null, 'function', 'meta', {
|
|
178
178
|
testFunc: {
|
|
179
|
-
|
|
179
|
+
pikkuFuncId: 'testFunc',
|
|
180
180
|
inputSchemaName: null,
|
|
181
181
|
outputSchemaName: null,
|
|
182
182
|
},
|
|
@@ -215,7 +215,7 @@ describe('CLI Runner', () => {
|
|
|
215
215
|
commands: {
|
|
216
216
|
greet: {
|
|
217
217
|
command: 'greet <name>',
|
|
218
|
-
|
|
218
|
+
pikkuFuncId: 'greetFunc',
|
|
219
219
|
positionals: [{ name: 'name', required: true }],
|
|
220
220
|
options: {},
|
|
221
221
|
},
|
|
@@ -236,7 +236,7 @@ describe('CLI Runner', () => {
|
|
|
236
236
|
|
|
237
237
|
pikkuState(null, 'function', 'meta', {
|
|
238
238
|
greetFunc: {
|
|
239
|
-
|
|
239
|
+
pikkuFuncId: 'greetFunc',
|
|
240
240
|
inputSchemaName: null,
|
|
241
241
|
outputSchemaName: null,
|
|
242
242
|
},
|
|
@@ -267,7 +267,7 @@ describe('CLI Runner', () => {
|
|
|
267
267
|
commands: {
|
|
268
268
|
secure: {
|
|
269
269
|
command: 'secure',
|
|
270
|
-
|
|
270
|
+
pikkuFuncId: 'secureFunc',
|
|
271
271
|
positionals: [],
|
|
272
272
|
options: {},
|
|
273
273
|
},
|
|
@@ -280,7 +280,7 @@ describe('CLI Runner', () => {
|
|
|
280
280
|
|
|
281
281
|
pikkuState(null, 'function', 'meta', {
|
|
282
282
|
secureFunc: {
|
|
283
|
-
|
|
283
|
+
pikkuFuncId: 'secureFunc',
|
|
284
284
|
inputSchemaName: null,
|
|
285
285
|
outputSchemaName: null,
|
|
286
286
|
},
|
|
@@ -313,7 +313,7 @@ describe('CLI Runner', () => {
|
|
|
313
313
|
commands: {
|
|
314
314
|
greet: {
|
|
315
315
|
command: 'greet <name>',
|
|
316
|
-
|
|
316
|
+
pikkuFuncId: 'greetFunc',
|
|
317
317
|
positionals: [{ name: 'name', required: true }],
|
|
318
318
|
options: {
|
|
319
319
|
loud: {
|
|
@@ -1,4 +1,4 @@
|
|
|
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
4
|
import { CorePikkuMiddleware, CoreUserSession } from '../../types/core.types.js'
|
|
@@ -20,7 +20,10 @@ import type {
|
|
|
20
20
|
CreateSingletonServices,
|
|
21
21
|
} from '../../types/core.types.js'
|
|
22
22
|
import { PikkuChannel } from '../channel/channel.types.js'
|
|
23
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
PikkuSessionService,
|
|
25
|
+
createMiddlewareSessionWireProps,
|
|
26
|
+
} from '../../services/user-session-service.js'
|
|
24
27
|
import { LocalVariablesService } from '../../services/local-variables.js'
|
|
25
28
|
import { generateCommandHelp, parseCLIArguments } from './command-parser.js'
|
|
26
29
|
|
|
@@ -60,8 +63,8 @@ export const wireCLI = <
|
|
|
60
63
|
const cliMeta = pikkuState(null, 'cli', 'meta') || {}
|
|
61
64
|
|
|
62
65
|
if (!cliMeta.programs?.[cli.program]) {
|
|
63
|
-
throw new
|
|
64
|
-
`CLI metadata not found for program '${cli.program}'
|
|
66
|
+
throw new PikkuMissingMetaError(
|
|
67
|
+
`CLI metadata not found for program '${cli.program}'`
|
|
65
68
|
)
|
|
66
69
|
}
|
|
67
70
|
|
|
@@ -141,7 +144,7 @@ function registerCLICommands(
|
|
|
141
144
|
for (let i = 1; i < fullPath.length; i++) {
|
|
142
145
|
currentMeta = currentMeta?.subcommands?.[fullPath[i]]
|
|
143
146
|
}
|
|
144
|
-
const funcName = currentMeta?.
|
|
147
|
+
const funcName = currentMeta?.pikkuFuncId
|
|
145
148
|
|
|
146
149
|
// Skip if no function name (could be a command group)
|
|
147
150
|
if (!funcName) {
|
|
@@ -272,7 +275,7 @@ export async function runCLICommand({
|
|
|
272
275
|
currentCommand = currentCommand.subcommands[commandPath[i]]
|
|
273
276
|
}
|
|
274
277
|
|
|
275
|
-
const funcName = currentCommand.
|
|
278
|
+
const funcName = currentCommand.pikkuFuncId
|
|
276
279
|
|
|
277
280
|
// Get program-specific data
|
|
278
281
|
const programs: Record<string, CLIProgramState> =
|
|
@@ -332,7 +335,7 @@ export async function runCLICommand({
|
|
|
332
335
|
data: pluckedData,
|
|
333
336
|
channel,
|
|
334
337
|
},
|
|
335
|
-
|
|
338
|
+
...createMiddlewareSessionWireProps(userSession),
|
|
336
339
|
}
|
|
337
340
|
|
|
338
341
|
try {
|
|
@@ -347,10 +350,12 @@ export async function runCLICommand({
|
|
|
347
350
|
wirePermissions: undefined,
|
|
348
351
|
tags: programData?.tags,
|
|
349
352
|
wire,
|
|
353
|
+
sessionService: userSession,
|
|
350
354
|
})
|
|
351
355
|
|
|
352
356
|
// Apply renderer one final time with the final output (if renderer exists)
|
|
353
|
-
if (
|
|
357
|
+
// Skip if result is undefined (void functions handle their own output)
|
|
358
|
+
if (renderer && result !== undefined) {
|
|
354
359
|
await Promise.resolve(
|
|
355
360
|
renderer(singletonServices, result, userSession.get())
|
|
356
361
|
)
|
|
@@ -395,7 +400,7 @@ export async function executeCLI({
|
|
|
395
400
|
}: {
|
|
396
401
|
programName: string
|
|
397
402
|
args?: string[]
|
|
398
|
-
createConfig
|
|
403
|
+
createConfig?: CreateConfig<any, any>
|
|
399
404
|
createSingletonServices: CreateSingletonServices<any, any>
|
|
400
405
|
createWireServices?: CreateWireServices<any, any, any>
|
|
401
406
|
}): Promise<void> {
|
|
@@ -470,7 +475,9 @@ export async function executeCLI({
|
|
|
470
475
|
const data = { ...parsed.positionals, ...parsed.options }
|
|
471
476
|
|
|
472
477
|
// Create config (pass data in case it needs to use any parsed options)
|
|
473
|
-
const config =
|
|
478
|
+
const config = createConfig
|
|
479
|
+
? await createConfig(new LocalVariablesService(), data)
|
|
480
|
+
: ({} as any)
|
|
474
481
|
|
|
475
482
|
// Create services with config
|
|
476
483
|
const singletonServices = await createSingletonServices(config)
|
|
@@ -69,7 +69,7 @@ export interface CLIProgramState {
|
|
|
69
69
|
*/
|
|
70
70
|
export interface CLICommandMeta {
|
|
71
71
|
parameters?: string
|
|
72
|
-
|
|
72
|
+
pikkuFuncId: string
|
|
73
73
|
positionals: CLIPositional[]
|
|
74
74
|
options: Record<string, CLIOption>
|
|
75
75
|
renderName?: string
|
|
@@ -131,8 +131,8 @@ export type CorePikkuCLIRender<
|
|
|
131
131
|
export type ExtractFunctionInput<Func> =
|
|
132
132
|
Func extends CorePikkuFunctionConfig<infer FuncType, any, any>
|
|
133
133
|
? FuncType extends
|
|
134
|
-
| CorePikkuFunction<infer Input, any, any, any>
|
|
135
|
-
| CorePikkuFunctionSessionless<infer Input, any, any, any>
|
|
134
|
+
| CorePikkuFunction<infer Input, any, any, any, any>
|
|
135
|
+
| CorePikkuFunctionSessionless<infer Input, any, any, any, any>
|
|
136
136
|
? Input
|
|
137
137
|
: never
|
|
138
138
|
: never
|
|
@@ -198,8 +198,8 @@ export type ValidateParameters<Params extends string, Input> =
|
|
|
198
198
|
export type ExtractFunctionOutput<Func> =
|
|
199
199
|
Func extends CorePikkuFunctionConfig<infer FuncType, any, any>
|
|
200
200
|
? FuncType extends
|
|
201
|
-
| CorePikkuFunction<any, infer Output, any, any>
|
|
202
|
-
| CorePikkuFunctionSessionless<any, infer Output, any, any>
|
|
201
|
+
| CorePikkuFunction<any, infer Output, any, any, any>
|
|
202
|
+
| CorePikkuFunctionSessionless<any, infer Output, any, any, any>
|
|
203
203
|
? Output
|
|
204
204
|
: never
|
|
205
205
|
: never
|
|
@@ -249,8 +249,8 @@ export interface CoreCLICommand<
|
|
|
249
249
|
In,
|
|
250
250
|
Out,
|
|
251
251
|
PikkuFunctionConfig extends CorePikkuFunctionConfig<
|
|
252
|
-
| CorePikkuFunction<In, Out, any, any>
|
|
253
|
-
| CorePikkuFunctionSessionless<In, Out, any, any>
|
|
252
|
+
| CorePikkuFunction<In, Out, any, any, any>
|
|
253
|
+
| CorePikkuFunctionSessionless<In, Out, any, any, any>
|
|
254
254
|
>,
|
|
255
255
|
PikkuPermission extends CorePikkuPermission<any, any, any>,
|
|
256
256
|
PikkuMiddleware extends CorePikkuMiddleware,
|
|
@@ -282,8 +282,8 @@ export type CLICommandShorthand<
|
|
|
282
282
|
In,
|
|
283
283
|
Out,
|
|
284
284
|
PikkuFunctionConfig extends CorePikkuFunctionConfig<
|
|
285
|
-
| CorePikkuFunction<In, Out, any, any>
|
|
286
|
-
| CorePikkuFunctionSessionless<In, Out, any, any>
|
|
285
|
+
| CorePikkuFunction<In, Out, any, any, any>
|
|
286
|
+
| CorePikkuFunctionSessionless<In, Out, any, any, any>
|
|
287
287
|
>,
|
|
288
288
|
> = PikkuFunctionConfig
|
|
289
289
|
|
|
@@ -294,8 +294,8 @@ export type CLICommandDefinition<
|
|
|
294
294
|
In,
|
|
295
295
|
Out,
|
|
296
296
|
PikkuFunctionConfig extends CorePikkuFunctionConfig<
|
|
297
|
-
| CorePikkuFunction<In, Out, any, any>
|
|
298
|
-
| CorePikkuFunctionSessionless<In, Out, any, any>
|
|
297
|
+
| CorePikkuFunction<In, Out, any, any, any>
|
|
298
|
+
| CorePikkuFunctionSessionless<In, Out, any, any, any>
|
|
299
299
|
>,
|
|
300
300
|
PikkuPermission extends CorePikkuPermission<any, any, any>,
|
|
301
301
|
PikkuMiddleware extends CorePikkuMiddleware,
|
|
@@ -17,7 +17,7 @@ const testMeta: CLIMeta = {
|
|
|
17
17
|
commands: {
|
|
18
18
|
greet: {
|
|
19
19
|
parameters: '<name>',
|
|
20
|
-
|
|
20
|
+
pikkuFuncId: 'greetFunc',
|
|
21
21
|
positionals: [{ name: 'name', required: true }],
|
|
22
22
|
options: {
|
|
23
23
|
loud: {
|
|
@@ -28,13 +28,13 @@ const testMeta: CLIMeta = {
|
|
|
28
28
|
},
|
|
29
29
|
},
|
|
30
30
|
user: {
|
|
31
|
-
|
|
31
|
+
pikkuFuncId: '',
|
|
32
32
|
positionals: [],
|
|
33
33
|
options: {},
|
|
34
34
|
subcommands: {
|
|
35
35
|
create: {
|
|
36
36
|
parameters: '<name> <email>',
|
|
37
|
-
|
|
37
|
+
pikkuFuncId: 'createUserFunc',
|
|
38
38
|
positionals: [
|
|
39
39
|
{ name: 'name', required: true },
|
|
40
40
|
{ name: 'email', required: true },
|
|
@@ -50,7 +50,7 @@ const testMeta: CLIMeta = {
|
|
|
50
50
|
},
|
|
51
51
|
delete: {
|
|
52
52
|
parameters: '<id>',
|
|
53
|
-
|
|
53
|
+
pikkuFuncId: 'deleteUserFunc',
|
|
54
54
|
positionals: [{ name: 'id', required: true }],
|
|
55
55
|
options: {
|
|
56
56
|
force: {
|
|
@@ -64,13 +64,13 @@ const testMeta: CLIMeta = {
|
|
|
64
64
|
},
|
|
65
65
|
files: {
|
|
66
66
|
parameters: '<paths...>',
|
|
67
|
-
|
|
67
|
+
pikkuFuncId: 'filesFunc',
|
|
68
68
|
positionals: [{ name: 'paths', required: true, variadic: true }],
|
|
69
69
|
options: {},
|
|
70
70
|
},
|
|
71
71
|
optional: {
|
|
72
72
|
parameters: '[name]',
|
|
73
|
-
|
|
73
|
+
pikkuFuncId: 'optionalFunc',
|
|
74
74
|
positionals: [{ name: 'name', required: false }],
|
|
75
75
|
options: {},
|
|
76
76
|
},
|
|
@@ -299,7 +299,7 @@ describe('Command Parser', () => {
|
|
|
299
299
|
options: {},
|
|
300
300
|
commands: {
|
|
301
301
|
test: {
|
|
302
|
-
|
|
302
|
+
pikkuFuncId: 'testFunc',
|
|
303
303
|
positionals: [],
|
|
304
304
|
options: {
|
|
305
305
|
port: {
|
|
@@ -380,7 +380,7 @@ describe('Command Parser', () => {
|
|
|
380
380
|
commands: {
|
|
381
381
|
greet: {
|
|
382
382
|
parameters: '<name>',
|
|
383
|
-
|
|
383
|
+
pikkuFuncId: 'greetFunc',
|
|
384
384
|
description: 'Greet a user',
|
|
385
385
|
positionals: [{ name: 'name', required: true }],
|
|
386
386
|
options: {},
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { CoreCLICommandConfig } from './cli.types.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Type-safe helper for defining CLI commands that can be composed.
|
|
5
|
+
* Returns the commands record as-is (identity function) for use with `wireCLI`.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* export const chatCommands = defineCLICommands({
|
|
10
|
+
* chat: pikkuCLICommand({ func: chatFunc }),
|
|
11
|
+
* 'chat:history': pikkuCLICommand({ func: historyFunc }),
|
|
12
|
+
* })
|
|
13
|
+
*
|
|
14
|
+
* wireCLI({
|
|
15
|
+
* program: 'my-app',
|
|
16
|
+
* commands: { ...chatCommands, other: pikkuCLICommand({ func: otherFunc }) }
|
|
17
|
+
* })
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export function defineCLICommands<
|
|
21
|
+
T extends Record<string, CoreCLICommandConfig<any, any, any, any>>,
|
|
22
|
+
>(commands: T): T {
|
|
23
|
+
return commands
|
|
24
|
+
}
|
package/src/wirings/cli/index.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
export * from './cli.types.js'
|
|
2
|
-
export * from './cli-runner.js'
|
|
3
|
-
export * from './command-parser.js'
|
|
4
|
-
|
|
5
1
|
export {
|
|
6
2
|
wireCLI,
|
|
7
3
|
runCLICommand,
|
|
@@ -11,3 +7,13 @@ export {
|
|
|
11
7
|
} from './cli-runner.js'
|
|
12
8
|
|
|
13
9
|
export { parseCLIArguments, generateCommandHelp } from './command-parser.js'
|
|
10
|
+
|
|
11
|
+
export { defineCLICommands } from './define-cli-commands.js'
|
|
12
|
+
export type {
|
|
13
|
+
CLIMeta,
|
|
14
|
+
CLICommandMeta,
|
|
15
|
+
CLIProgramMeta,
|
|
16
|
+
CoreCLI,
|
|
17
|
+
CoreCLICommandConfig,
|
|
18
|
+
CorePikkuCLIRender,
|
|
19
|
+
} from './cli.types.js'
|