@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
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
HTTPRouteConfig,
|
|
3
|
+
HTTPRouteMap,
|
|
4
|
+
HTTPRouteContract,
|
|
5
|
+
HTTPRoutesGroupConfig,
|
|
6
|
+
WireHTTPRoutesConfig,
|
|
7
|
+
} from './http.types.js'
|
|
8
|
+
import { wireHTTP } from './http-runner.js'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Type-safe helper for defining route contracts that can be composed.
|
|
12
|
+
* Supports optional group-level config that cascades to all routes.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // Simple routes without group config
|
|
17
|
+
* export const todosRoutes = defineHTTPRoutes({
|
|
18
|
+
* list: { method: 'get', route: '/todos', func: listTodos },
|
|
19
|
+
* get: { method: 'get', route: '/todos/:id', func: getTodo },
|
|
20
|
+
* })
|
|
21
|
+
*
|
|
22
|
+
* // Routes with group-level config
|
|
23
|
+
* export const todosRoutes = defineHTTPRoutes({
|
|
24
|
+
* auth: true,
|
|
25
|
+
* tags: ['todos'],
|
|
26
|
+
* routes: {
|
|
27
|
+
* list: { method: 'get', route: '/todos', func: listTodos },
|
|
28
|
+
* get: { method: 'get', route: '/todos/:id', func: getTodo },
|
|
29
|
+
* }
|
|
30
|
+
* })
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export function defineHTTPRoutes<T extends HTTPRouteMap>(
|
|
34
|
+
routes: T
|
|
35
|
+
): HTTPRouteContract<T>
|
|
36
|
+
export function defineHTTPRoutes<T extends HTTPRouteMap>(
|
|
37
|
+
config: HTTPRoutesGroupConfig & { routes: T }
|
|
38
|
+
): HTTPRouteContract<T>
|
|
39
|
+
export function defineHTTPRoutes<T extends HTTPRouteMap>(
|
|
40
|
+
configOrRoutes: T | (HTTPRoutesGroupConfig & { routes: T })
|
|
41
|
+
): HTTPRouteContract<T> {
|
|
42
|
+
// If it has a 'routes' property and contains a map (not a route config), it's config + routes
|
|
43
|
+
if (
|
|
44
|
+
'routes' in configOrRoutes &&
|
|
45
|
+
typeof configOrRoutes.routes === 'object' &&
|
|
46
|
+
!isRouteConfig(configOrRoutes.routes)
|
|
47
|
+
) {
|
|
48
|
+
return configOrRoutes as HTTPRouteContract<T>
|
|
49
|
+
}
|
|
50
|
+
// Otherwise it's just routes
|
|
51
|
+
return { routes: configOrRoutes as T }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Wires multiple HTTP routes from a nested map or array configuration.
|
|
56
|
+
* Inspired by ts-rest's contract pattern, provides a single place to wire an entire API.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* // Nested object format
|
|
61
|
+
* wireHTTPRoutes({
|
|
62
|
+
* basePath: '/api/v1',
|
|
63
|
+
* tags: ['api'],
|
|
64
|
+
* routes: {
|
|
65
|
+
* todos: {
|
|
66
|
+
* list: { method: 'get', route: '/todos', func: listTodos },
|
|
67
|
+
* get: { method: 'get', route: '/todos/:id', func: getTodo },
|
|
68
|
+
* },
|
|
69
|
+
* auth: {
|
|
70
|
+
* login: { method: 'post', route: '/auth/login', func: login, auth: false },
|
|
71
|
+
* },
|
|
72
|
+
* },
|
|
73
|
+
* })
|
|
74
|
+
*
|
|
75
|
+
* // Flat array format
|
|
76
|
+
* wireHTTPRoutes({
|
|
77
|
+
* basePath: '/api',
|
|
78
|
+
* routes: [
|
|
79
|
+
* { method: 'get', route: '/todos', func: listTodos },
|
|
80
|
+
* { method: 'post', route: '/todos', func: createTodo },
|
|
81
|
+
* ],
|
|
82
|
+
* })
|
|
83
|
+
*
|
|
84
|
+
* // Composing route contracts
|
|
85
|
+
* wireHTTPRoutes({
|
|
86
|
+
* basePath: '/api/v1',
|
|
87
|
+
* routes: {
|
|
88
|
+
* todos: todosRoutes, // from defineHTTPRoutes()
|
|
89
|
+
* auth: authRoutes, // from defineHTTPRoutes()
|
|
90
|
+
* },
|
|
91
|
+
* })
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export const wireHTTPRoutes = (config: WireHTTPRoutesConfig): void => {
|
|
95
|
+
const { routes, ...groupConfig } = config
|
|
96
|
+
|
|
97
|
+
if (Array.isArray(routes)) {
|
|
98
|
+
routes.forEach((route) => registerRoute(route, groupConfig))
|
|
99
|
+
} else {
|
|
100
|
+
processRouteMap(routes, groupConfig)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Recursively processes a route map, handling nested maps and contracts
|
|
106
|
+
*/
|
|
107
|
+
function processRouteMap(
|
|
108
|
+
map: HTTPRouteMap,
|
|
109
|
+
parentConfig: HTTPRoutesGroupConfig
|
|
110
|
+
): void {
|
|
111
|
+
for (const [_key, value] of Object.entries(map)) {
|
|
112
|
+
if (isRouteConfig(value)) {
|
|
113
|
+
registerRoute(value, parentConfig)
|
|
114
|
+
} else if (isRouteContract(value)) {
|
|
115
|
+
// Merge parent config with contract config, then process routes
|
|
116
|
+
const mergedConfig = mergeGroupConfig(parentConfig, value)
|
|
117
|
+
processRouteMap(value.routes, mergedConfig)
|
|
118
|
+
} else {
|
|
119
|
+
// Nested map without config
|
|
120
|
+
processRouteMap(value as HTTPRouteMap, parentConfig)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Merge group configs with proper cascading behavior:
|
|
127
|
+
* - basePath: Concatenates
|
|
128
|
+
* - tags: Merges (parent + child)
|
|
129
|
+
* - middleware: Merges (parent runs first)
|
|
130
|
+
* - auth: Inner overrides outer
|
|
131
|
+
* - permissions: Inner overrides outer
|
|
132
|
+
*/
|
|
133
|
+
function mergeGroupConfig(
|
|
134
|
+
parent: HTTPRoutesGroupConfig,
|
|
135
|
+
child: HTTPRoutesGroupConfig
|
|
136
|
+
): HTTPRoutesGroupConfig {
|
|
137
|
+
return {
|
|
138
|
+
basePath: (parent.basePath || '') + (child.basePath || ''),
|
|
139
|
+
tags: [...(parent.tags || []), ...(child.tags || [])],
|
|
140
|
+
middleware: [...(parent.middleware || []), ...(child.middleware || [])],
|
|
141
|
+
auth: child.auth ?? parent.auth,
|
|
142
|
+
permissions: child.permissions ?? parent.permissions,
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Registers a single route by calling wireHTTP with merged configuration
|
|
148
|
+
*/
|
|
149
|
+
function registerRoute(
|
|
150
|
+
route: HTTPRouteConfig,
|
|
151
|
+
groupConfig: HTTPRoutesGroupConfig
|
|
152
|
+
): void {
|
|
153
|
+
const fullRoute = (groupConfig.basePath || '') + route.route
|
|
154
|
+
|
|
155
|
+
wireHTTP({
|
|
156
|
+
method: route.method,
|
|
157
|
+
route: fullRoute,
|
|
158
|
+
func: route.func,
|
|
159
|
+
auth: route.auth ?? groupConfig.auth,
|
|
160
|
+
tags: [...(groupConfig.tags || []), ...(route.tags || [])],
|
|
161
|
+
middleware: [
|
|
162
|
+
...(groupConfig.middleware || []),
|
|
163
|
+
...(route.middleware || []),
|
|
164
|
+
],
|
|
165
|
+
permissions: route.permissions ?? groupConfig.permissions,
|
|
166
|
+
contentType: route.contentType,
|
|
167
|
+
timeout: route.timeout,
|
|
168
|
+
headers: route.headers,
|
|
169
|
+
docs: route.docs,
|
|
170
|
+
sse: route.sse,
|
|
171
|
+
} as any)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Type guard to check if a value is an individual route config
|
|
176
|
+
*/
|
|
177
|
+
function isRouteConfig(value: unknown): value is HTTPRouteConfig {
|
|
178
|
+
return (
|
|
179
|
+
typeof value === 'object' &&
|
|
180
|
+
value !== null &&
|
|
181
|
+
'method' in value &&
|
|
182
|
+
'func' in value &&
|
|
183
|
+
'route' in value
|
|
184
|
+
)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Type guard to check if a value is a route contract (has routes property but is not a route config)
|
|
189
|
+
*/
|
|
190
|
+
function isRouteContract(value: unknown): value is HTTPRouteContract {
|
|
191
|
+
return (
|
|
192
|
+
typeof value === 'object' &&
|
|
193
|
+
value !== null &&
|
|
194
|
+
'routes' in value &&
|
|
195
|
+
!('method' in value) &&
|
|
196
|
+
!('func' in value)
|
|
197
|
+
)
|
|
198
|
+
}
|
|
@@ -12,21 +12,21 @@ import { addFunction } from '../../function/function-runner.js'
|
|
|
12
12
|
import { httpRouter } from './routers/http-router.js'
|
|
13
13
|
|
|
14
14
|
const sessionMiddleware: CorePikkuMiddleware = async (services, wire, next) => {
|
|
15
|
-
wire.
|
|
15
|
+
wire.setSession?.({ userId: 'test' } as any)
|
|
16
16
|
await next()
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
const setHTTPFunctionMap = (func: any) => {
|
|
20
|
-
pikkuState('function', 'meta', {
|
|
20
|
+
pikkuState(null, 'function', 'meta', {
|
|
21
21
|
pikku_func_name: {
|
|
22
|
-
|
|
22
|
+
pikkuFuncId: 'pikku_func_name',
|
|
23
23
|
services: ['userSession'],
|
|
24
24
|
},
|
|
25
25
|
} as any)
|
|
26
|
-
pikkuState('http', 'meta', {
|
|
26
|
+
pikkuState(null, 'http', 'meta', {
|
|
27
27
|
get: {
|
|
28
28
|
test: {
|
|
29
|
-
|
|
29
|
+
pikkuFuncId: 'pikku_func_name',
|
|
30
30
|
route: 'test',
|
|
31
31
|
method: 'get',
|
|
32
32
|
},
|
|
@@ -22,13 +22,16 @@ import {
|
|
|
22
22
|
PikkuWire,
|
|
23
23
|
PikkuWiringTypes,
|
|
24
24
|
} from '../../types/core.types.js'
|
|
25
|
-
import { NotFoundError } from '../../errors/errors.js'
|
|
25
|
+
import { NotFoundError, PikkuMissingMetaError } from '../../errors/errors.js'
|
|
26
26
|
import {
|
|
27
27
|
closeWireServices,
|
|
28
28
|
createWeakUID,
|
|
29
29
|
isSerializable,
|
|
30
30
|
} from '../../utils.js'
|
|
31
|
-
import {
|
|
31
|
+
import {
|
|
32
|
+
PikkuSessionService,
|
|
33
|
+
createMiddlewareSessionWireProps,
|
|
34
|
+
} from '../../services/user-session-service.js'
|
|
32
35
|
import { handleHTTPError } from '../../handle-error.js'
|
|
33
36
|
import { pikkuState } from '../../pikku-state.js'
|
|
34
37
|
import { PikkuFetchHTTPResponse } from './pikku-fetch-http-response.js'
|
|
@@ -36,6 +39,24 @@ import { PikkuFetchHTTPRequest } from './pikku-fetch-http-request.js'
|
|
|
36
39
|
import { PikkuChannel } from '../channel/channel.types.js'
|
|
37
40
|
import { addFunction, runPikkuFunc } from '../../function/function-runner.js'
|
|
38
41
|
import { httpRouter } from './routers/http-router.js'
|
|
42
|
+
import { validateSchema } from '../../schema.js'
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Extract headers from a PikkuHTTPRequest based on the schema keys
|
|
46
|
+
*/
|
|
47
|
+
function extractHeadersFromRequest(
|
|
48
|
+
request: PikkuHTTPRequest,
|
|
49
|
+
headerKeys: string[]
|
|
50
|
+
): Record<string, string | string[] | undefined> {
|
|
51
|
+
const headers: Record<string, string | string[] | undefined> = {}
|
|
52
|
+
for (const headerName of headerKeys) {
|
|
53
|
+
const value = request.header(headerName)
|
|
54
|
+
if (value !== null) {
|
|
55
|
+
headers[headerName] = value
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return headers
|
|
59
|
+
}
|
|
39
60
|
|
|
40
61
|
/**
|
|
41
62
|
* Registers HTTP middleware for a specific route pattern.
|
|
@@ -68,9 +89,10 @@ import { httpRouter } from './routers/http-router.js'
|
|
|
68
89
|
*/
|
|
69
90
|
export const addHTTPMiddleware = <PikkuMiddleware extends CorePikkuMiddleware>(
|
|
70
91
|
pattern: string,
|
|
71
|
-
middleware: CorePikkuMiddlewareGroup
|
|
92
|
+
middleware: CorePikkuMiddlewareGroup,
|
|
93
|
+
packageName: string | null = null
|
|
72
94
|
): CorePikkuMiddlewareGroup => {
|
|
73
|
-
const httpGroups = pikkuState('middleware', 'httpGroup')
|
|
95
|
+
const httpGroups = pikkuState(packageName, 'middleware', 'httpGroup')
|
|
74
96
|
httpGroups[pattern] = middleware
|
|
75
97
|
return middleware
|
|
76
98
|
}
|
|
@@ -106,9 +128,10 @@ export const addHTTPMiddleware = <PikkuMiddleware extends CorePikkuMiddleware>(
|
|
|
106
128
|
*/
|
|
107
129
|
export const addHTTPPermission = <PikkuPermission extends CorePikkuPermission>(
|
|
108
130
|
pattern: string,
|
|
109
|
-
permissions: CorePermissionGroup | CorePikkuPermission[]
|
|
131
|
+
permissions: CorePermissionGroup | CorePikkuPermission[],
|
|
132
|
+
packageName: string | null = null
|
|
110
133
|
): CorePermissionGroup | CorePikkuPermission[] => {
|
|
111
|
-
const httpGroups = pikkuState('permissions', 'httpGroup')
|
|
134
|
+
const httpGroups = pikkuState(packageName, 'permissions', 'httpGroup')
|
|
112
135
|
httpGroups[pattern] = permissions
|
|
113
136
|
return permissions
|
|
114
137
|
}
|
|
@@ -151,17 +174,21 @@ export const wireHTTP = <
|
|
|
151
174
|
PikkuMiddleware
|
|
152
175
|
>
|
|
153
176
|
) => {
|
|
154
|
-
const httpMeta = pikkuState('http', 'meta')
|
|
177
|
+
const httpMeta = pikkuState(null, 'http', 'meta')
|
|
155
178
|
const routeMeta = httpMeta[httpWiring.method][httpWiring.route]
|
|
156
179
|
if (!routeMeta) {
|
|
157
|
-
throw new
|
|
180
|
+
throw new PikkuMissingMetaError(
|
|
181
|
+
`Missing generated metadata for HTTP route '${httpWiring.method.toUpperCase()} ${httpWiring.route}'`
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
|
+
if (httpWiring.func) {
|
|
185
|
+
addFunction(routeMeta.pikkuFuncId, httpWiring.func)
|
|
158
186
|
}
|
|
159
|
-
|
|
160
|
-
const routes = pikkuState('http', 'routes')
|
|
187
|
+
const routes = pikkuState(null, 'http', 'routes')
|
|
161
188
|
if (!routes.has(httpWiring.method)) {
|
|
162
189
|
routes.set(httpWiring.method, new Map())
|
|
163
190
|
}
|
|
164
|
-
pikkuState('http', 'routes')
|
|
191
|
+
pikkuState(null, 'http', 'routes')
|
|
165
192
|
.get(httpWiring.method)
|
|
166
193
|
?.set(httpWiring.route, httpWiring as any)
|
|
167
194
|
}
|
|
@@ -184,10 +211,10 @@ const getMatchingRoute = (requestType: string, requestPath: string) => {
|
|
|
184
211
|
)
|
|
185
212
|
|
|
186
213
|
if (matchedPath) {
|
|
187
|
-
const route = pikkuState('http', 'routes')
|
|
214
|
+
const route = pikkuState(null, 'http', 'routes')
|
|
188
215
|
.get(requestType.toLowerCase() as HTTPMethod)!
|
|
189
216
|
.get(matchedPath.route)!
|
|
190
|
-
const meta = pikkuState('http', 'meta')[
|
|
217
|
+
const meta = pikkuState(null, 'http', 'meta')[
|
|
191
218
|
requestType.toLowerCase() as PikkuWiringTypes
|
|
192
219
|
][route.route]
|
|
193
220
|
|
|
@@ -273,13 +300,27 @@ const executeRoute = async (
|
|
|
273
300
|
const { singletonServices, createWireServices, skipUserSession, requestId } =
|
|
274
301
|
services
|
|
275
302
|
|
|
303
|
+
// Attach URL parameters to the request object
|
|
304
|
+
http?.request?.setParams(params)
|
|
305
|
+
|
|
306
|
+
// Validate request headers if schema is defined
|
|
307
|
+
if (meta.headersSchemaName && http.request && singletonServices.schema) {
|
|
308
|
+
const headerKeys = singletonServices.schema.getSchemaKeys(
|
|
309
|
+
meta.headersSchemaName
|
|
310
|
+
)
|
|
311
|
+
const rawHeaders = extractHeadersFromRequest(http.request, headerKeys)
|
|
312
|
+
await validateSchema(
|
|
313
|
+
singletonServices.logger,
|
|
314
|
+
singletonServices.schema,
|
|
315
|
+
meta.headersSchemaName,
|
|
316
|
+
rawHeaders
|
|
317
|
+
)
|
|
318
|
+
}
|
|
319
|
+
|
|
276
320
|
const requiresSession = route.auth !== false
|
|
277
321
|
let wireServices: any
|
|
278
322
|
let result: any
|
|
279
323
|
|
|
280
|
-
// Attach URL parameters to the request object
|
|
281
|
-
http?.request?.setParams(params)
|
|
282
|
-
|
|
283
324
|
singletonServices.logger.info(
|
|
284
325
|
`Matched route: ${route.route} | method: ${route.method.toUpperCase()} | auth: ${requiresSession.toString()}`
|
|
285
326
|
)
|
|
@@ -289,7 +330,13 @@ const executeRoute = async (
|
|
|
289
330
|
throw new Error("Can't skip trying to get user session if auth is required")
|
|
290
331
|
}
|
|
291
332
|
|
|
292
|
-
|
|
333
|
+
let cachedData: unknown | undefined
|
|
334
|
+
const data = async () => {
|
|
335
|
+
if (cachedData === undefined) {
|
|
336
|
+
cachedData = await http.request!.data()
|
|
337
|
+
}
|
|
338
|
+
return cachedData
|
|
339
|
+
}
|
|
293
340
|
let channel: PikkuChannel<unknown, unknown> | undefined
|
|
294
341
|
|
|
295
342
|
if (matchedRoute.route.sse) {
|
|
@@ -319,12 +366,16 @@ const executeRoute = async (
|
|
|
319
366
|
}
|
|
320
367
|
}
|
|
321
368
|
|
|
322
|
-
const wire: PikkuWire = {
|
|
369
|
+
const wire: PikkuWire = {
|
|
370
|
+
http,
|
|
371
|
+
channel,
|
|
372
|
+
...createMiddlewareSessionWireProps(userSession),
|
|
373
|
+
}
|
|
323
374
|
|
|
324
375
|
result = await runPikkuFunc(
|
|
325
376
|
'http',
|
|
326
377
|
`${meta.method}:${meta.route}`,
|
|
327
|
-
meta.
|
|
378
|
+
meta.pikkuFuncId,
|
|
328
379
|
{
|
|
329
380
|
singletonServices,
|
|
330
381
|
createWireServices,
|
|
@@ -337,20 +388,20 @@ const executeRoute = async (
|
|
|
337
388
|
coerceDataFromSchema: options.coerceDataFromSchema,
|
|
338
389
|
tags: route.tags,
|
|
339
390
|
wire,
|
|
391
|
+
sessionService: userSession,
|
|
340
392
|
}
|
|
341
393
|
)
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
394
|
+
if (!matchedRoute.route.sse) {
|
|
395
|
+
if (result === undefined || result === null) {
|
|
396
|
+
http?.response?.status(204)
|
|
397
|
+
} else if (route.returnsJSON === false) {
|
|
398
|
+
http?.response?.arrayBuffer(result)
|
|
399
|
+
} else {
|
|
400
|
+
http?.response?.status(200)
|
|
401
|
+
http?.response?.json(result)
|
|
402
|
+
}
|
|
348
403
|
}
|
|
349
404
|
|
|
350
|
-
http?.response?.status(200)
|
|
351
|
-
// TODO: Evaluate if the response stream should be explicitly ended.
|
|
352
|
-
// http?.response?.end()
|
|
353
|
-
|
|
354
405
|
return wireServices ? { result, wireServices } : { result }
|
|
355
406
|
}
|
|
356
407
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { SerializeOptions } from 'cookie'
|
|
2
|
-
import type {
|
|
2
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec'
|
|
3
|
+
import { PikkuError } from '../../errors/error-handler.js'
|
|
3
4
|
import type {
|
|
4
5
|
CoreServices,
|
|
5
6
|
CoreSingletonServices,
|
|
@@ -44,7 +45,7 @@ export type RunHTTPWiringOptions = Partial<{
|
|
|
44
45
|
|
|
45
46
|
export type RunHTTPWiringParams = {
|
|
46
47
|
singletonServices: CoreSingletonServices
|
|
47
|
-
createWireServices
|
|
48
|
+
createWireServices?: CreateWireServices<
|
|
48
49
|
CoreSingletonServices,
|
|
49
50
|
CoreServices<CoreSingletonServices>,
|
|
50
51
|
CoreUserSession
|
|
@@ -53,7 +54,7 @@ export type RunHTTPWiringParams = {
|
|
|
53
54
|
|
|
54
55
|
/**
|
|
55
56
|
* Represents the HTTP methods supported for API HTTP wirings.
|
|
56
|
-
|
|
57
|
+
*/
|
|
57
58
|
export type HTTPMethod =
|
|
58
59
|
| 'post'
|
|
59
60
|
| 'get'
|
|
@@ -64,21 +65,41 @@ export type HTTPMethod =
|
|
|
64
65
|
| 'options'
|
|
65
66
|
|
|
66
67
|
/**
|
|
67
|
-
*
|
|
68
|
+
* Header schema type for request header validation.
|
|
69
|
+
* Uses Standard Schema interface - works with Zod, Valibot, ArkType, Effect Schema, etc.
|
|
68
70
|
*/
|
|
69
|
-
export type
|
|
71
|
+
export type HTTPHeadersSchema = StandardSchemaV1<
|
|
72
|
+
Record<string, string | string[] | undefined>
|
|
73
|
+
>
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Documentation config for OpenAPI generation
|
|
77
|
+
*/
|
|
78
|
+
export type HTTPRouteDocsConfig = {
|
|
79
|
+
description?: string
|
|
80
|
+
response?: string
|
|
81
|
+
errors?: Array<typeof PikkuError>
|
|
82
|
+
tags?: string[]
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Common HTTP route configuration shared between wireHTTP and wireHTTPRoutes
|
|
87
|
+
*/
|
|
88
|
+
export type HTTPRouteBaseConfig = {
|
|
70
89
|
contentType?: 'xml' | 'json'
|
|
90
|
+
timeout?: number
|
|
91
|
+
tags?: string[]
|
|
92
|
+
headers?: HTTPHeadersSchema
|
|
93
|
+
docs?: HTTPRouteDocsConfig
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Represents an API HTTP wiring without a function, including metadata such as content type, route, and timeout settings.
|
|
98
|
+
*/
|
|
99
|
+
export type CoreHTTPFunction = HTTPRouteBaseConfig & {
|
|
71
100
|
route: string
|
|
72
101
|
eventChannel?: false
|
|
73
102
|
returnsJSON?: false
|
|
74
|
-
timeout?: number
|
|
75
|
-
tags?: string[]
|
|
76
|
-
docs?: Partial<{
|
|
77
|
-
description: string
|
|
78
|
-
response: string
|
|
79
|
-
errors: Array<typeof PikkuError>
|
|
80
|
-
tags: string[]
|
|
81
|
-
}>
|
|
82
103
|
}
|
|
83
104
|
/**
|
|
84
105
|
* Represents a http wire within Pikku, including a request and response.
|
|
@@ -121,12 +142,14 @@ export type CoreHTTPFunctionWiring<
|
|
|
121
142
|
In,
|
|
122
143
|
Out,
|
|
123
144
|
any,
|
|
145
|
+
any,
|
|
124
146
|
any
|
|
125
147
|
> = CorePikkuFunction<In, Out>,
|
|
126
148
|
PikkuFunctionSessionless extends CorePikkuFunctionSessionless<
|
|
127
149
|
In,
|
|
128
150
|
Out,
|
|
129
151
|
any,
|
|
152
|
+
any,
|
|
130
153
|
any
|
|
131
154
|
> = CorePikkuFunctionSessionless<In, Out>,
|
|
132
155
|
PikkuPermission extends CorePikkuPermission<
|
|
@@ -149,7 +172,6 @@ export type CoreHTTPFunctionWiring<
|
|
|
149
172
|
>
|
|
150
173
|
permissions?: CorePermissionGroup<PikkuPermission>
|
|
151
174
|
auth?: true
|
|
152
|
-
tags?: string[]
|
|
153
175
|
middleware?: PikkuMiddleware[]
|
|
154
176
|
sse?: undefined
|
|
155
177
|
})
|
|
@@ -163,7 +185,6 @@ export type CoreHTTPFunctionWiring<
|
|
|
163
185
|
>
|
|
164
186
|
permissions?: undefined
|
|
165
187
|
auth?: false
|
|
166
|
-
tags?: string[]
|
|
167
188
|
middleware?: PikkuMiddleware[]
|
|
168
189
|
sse?: undefined
|
|
169
190
|
})
|
|
@@ -177,9 +198,8 @@ export type CoreHTTPFunctionWiring<
|
|
|
177
198
|
>
|
|
178
199
|
permissions?: CorePermissionGroup<PikkuPermission>
|
|
179
200
|
auth?: true
|
|
180
|
-
sse?: boolean
|
|
181
|
-
tags?: string[]
|
|
182
201
|
middleware?: PikkuMiddleware[]
|
|
202
|
+
sse?: boolean
|
|
183
203
|
})
|
|
184
204
|
| (CoreHTTPFunction & {
|
|
185
205
|
route: R
|
|
@@ -191,9 +211,8 @@ export type CoreHTTPFunctionWiring<
|
|
|
191
211
|
>
|
|
192
212
|
permissions?: undefined
|
|
193
213
|
auth?: false
|
|
194
|
-
sse?: boolean
|
|
195
|
-
tags?: string[]
|
|
196
214
|
middleware?: PikkuMiddleware[]
|
|
215
|
+
sse?: boolean
|
|
197
216
|
})
|
|
198
217
|
| (CoreHTTPFunction & {
|
|
199
218
|
route: R
|
|
@@ -205,9 +224,8 @@ export type CoreHTTPFunctionWiring<
|
|
|
205
224
|
>
|
|
206
225
|
permissions?: CorePermissionGroup<PikkuPermission>
|
|
207
226
|
auth?: true
|
|
208
|
-
query?: Array<keyof In>
|
|
209
|
-
tags?: string[]
|
|
210
227
|
middleware?: PikkuMiddleware[]
|
|
228
|
+
query?: Array<keyof In>
|
|
211
229
|
sse?: undefined
|
|
212
230
|
})
|
|
213
231
|
| (CoreHTTPFunction & {
|
|
@@ -220,9 +238,8 @@ export type CoreHTTPFunctionWiring<
|
|
|
220
238
|
>
|
|
221
239
|
permissions?: undefined
|
|
222
240
|
auth?: false
|
|
223
|
-
query?: Array<keyof In>
|
|
224
|
-
tags?: string[]
|
|
225
241
|
middleware?: PikkuMiddleware[]
|
|
242
|
+
query?: Array<keyof In>
|
|
226
243
|
sse?: undefined
|
|
227
244
|
})
|
|
228
245
|
|
|
@@ -244,7 +261,9 @@ export type HTTPWiringMeta = CommonWireMeta & {
|
|
|
244
261
|
params?: string[]
|
|
245
262
|
query?: string[]
|
|
246
263
|
inputTypes?: HTTPFunctionMetaInputTypes
|
|
264
|
+
headersSchemaName?: string
|
|
247
265
|
sse?: true
|
|
266
|
+
groupBasePath?: string
|
|
248
267
|
}
|
|
249
268
|
export type HTTPWiringsMeta = Record<HTTPMethod, Record<string, HTTPWiringMeta>>
|
|
250
269
|
|
|
@@ -291,3 +310,82 @@ export interface PikkuHTTPResponse<Out = unknown> {
|
|
|
291
310
|
close?: () => void
|
|
292
311
|
setMode?: (mode: 'stream') => void
|
|
293
312
|
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Single route configuration - supports all wireHTTP options
|
|
316
|
+
*/
|
|
317
|
+
export type HTTPRouteConfig<
|
|
318
|
+
PikkuFunction extends
|
|
319
|
+
| CorePikkuFunction<any, any, any, any, any>
|
|
320
|
+
| CorePikkuFunctionSessionless<any, any, any, any, any> =
|
|
321
|
+
| CorePikkuFunction<any, any, any, any, any>
|
|
322
|
+
| CorePikkuFunctionSessionless<any, any, any, any, any>,
|
|
323
|
+
PikkuPermission extends CorePikkuPermission<
|
|
324
|
+
any,
|
|
325
|
+
any,
|
|
326
|
+
any
|
|
327
|
+
> = CorePikkuPermission<any>,
|
|
328
|
+
PikkuMiddleware extends CorePikkuMiddleware<any, any> = CorePikkuMiddleware<
|
|
329
|
+
any,
|
|
330
|
+
any
|
|
331
|
+
>,
|
|
332
|
+
> = HTTPRouteBaseConfig & {
|
|
333
|
+
// Required
|
|
334
|
+
method: HTTPMethod
|
|
335
|
+
route: string
|
|
336
|
+
func: CorePikkuFunctionConfig<PikkuFunction, PikkuPermission, PikkuMiddleware>
|
|
337
|
+
|
|
338
|
+
// Auth & permissions
|
|
339
|
+
auth?: boolean
|
|
340
|
+
permissions?: CorePermissionGroup<PikkuPermission>
|
|
341
|
+
|
|
342
|
+
// Middleware
|
|
343
|
+
middleware?: PikkuMiddleware[]
|
|
344
|
+
|
|
345
|
+
// SSE support
|
|
346
|
+
sse?: boolean
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Group-level configuration applied to all routes
|
|
351
|
+
*/
|
|
352
|
+
export type HTTPRoutesGroupConfig<
|
|
353
|
+
PikkuPermission extends CorePikkuPermission<
|
|
354
|
+
any,
|
|
355
|
+
any,
|
|
356
|
+
any
|
|
357
|
+
> = CorePikkuPermission<any>,
|
|
358
|
+
PikkuMiddleware extends CorePikkuMiddleware<any, any> = CorePikkuMiddleware<
|
|
359
|
+
any,
|
|
360
|
+
any
|
|
361
|
+
>,
|
|
362
|
+
> = {
|
|
363
|
+
basePath?: string
|
|
364
|
+
tags?: string[]
|
|
365
|
+
auth?: boolean
|
|
366
|
+
middleware?: PikkuMiddleware[]
|
|
367
|
+
permissions?: CorePermissionGroup<PikkuPermission>
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Nested route map - allows hierarchical organization
|
|
372
|
+
* Can contain individual routes, nested maps, or contracts with config
|
|
373
|
+
*/
|
|
374
|
+
export type HTTPRouteMap = {
|
|
375
|
+
[key: string]: HTTPRouteConfig | HTTPRouteMap | HTTPRouteContract
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* A route contract with optional group config (returned by defineRoutes)
|
|
380
|
+
*/
|
|
381
|
+
export type HTTPRouteContract<T extends HTTPRouteMap = HTTPRouteMap> =
|
|
382
|
+
HTTPRoutesGroupConfig & {
|
|
383
|
+
routes: T
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Full configuration for wireHTTPRoutes
|
|
388
|
+
*/
|
|
389
|
+
export type WireHTTPRoutesConfig = HTTPRoutesGroupConfig & {
|
|
390
|
+
routes: HTTPRouteMap | HTTPRouteConfig[]
|
|
391
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export { PikkuFetchHTTPRequest } from './pikku-fetch-http-request.js'
|
|
2
|
+
export { PikkuFetchHTTPResponse } from './pikku-fetch-http-response.js'
|
|
3
|
+
export { logRoutes } from './log-http-routes.js'
|
|
4
4
|
|
|
5
5
|
export {
|
|
6
6
|
fetch,
|
|
@@ -10,4 +10,16 @@ export {
|
|
|
10
10
|
addHTTPPermission,
|
|
11
11
|
} from './http-runner.js'
|
|
12
12
|
|
|
13
|
-
export
|
|
13
|
+
export { wireHTTPRoutes, defineHTTPRoutes } from './http-routes.js'
|
|
14
|
+
|
|
15
|
+
export type {
|
|
16
|
+
AssertHTTPWiringParams,
|
|
17
|
+
CoreHTTPFunctionWiring,
|
|
18
|
+
HTTPMethod,
|
|
19
|
+
HTTPRouteBaseConfig,
|
|
20
|
+
HTTPWiringsMeta,
|
|
21
|
+
PikkuHTTPRequest,
|
|
22
|
+
PikkuHTTPResponse,
|
|
23
|
+
PikkuQuery,
|
|
24
|
+
RunHTTPWiringOptions,
|
|
25
|
+
} from './http.types.js'
|