@pikku/cli 0.11.1 → 0.11.3
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/.pikku/channel/pikku-channel-types.gen.ts +73 -17
- package/.pikku/channel/pikku-channels-map.gen.d.ts +11 -11
- package/.pikku/channel/pikku-channels-meta.gen.json +1 -0
- package/.pikku/channel/pikku-channels-meta.gen.ts +4 -2
- package/.pikku/channel/pikku-channels.gen.ts +1 -1
- package/.pikku/cli/pikku-cli-channel.ts +2 -2
- package/.pikku/cli/pikku-cli-client.gen.ts +1 -3
- package/.pikku/cli/pikku-cli-types.gen.ts +3 -3
- package/.pikku/cli/pikku-cli-wirings-meta.gen.json +147 -0
- package/.pikku/cli/pikku-cli-wirings-meta.gen.ts +4 -157
- package/.pikku/cli/pikku-cli-wirings.gen.ts +3 -3
- package/.pikku/cli/pikku-cli.gen.ts +3 -3
- package/.pikku/forge/pikku-forge-types.gen.ts +83 -0
- package/.pikku/function/pikku-function-types.gen.ts +223 -91
- package/.pikku/function/pikku-functions-meta-verbose.gen.json +1030 -0
- package/.pikku/function/pikku-functions-meta.gen.json +656 -0
- package/.pikku/function/pikku-functions-meta.gen.ts +4 -970
- package/.pikku/http/pikku-http-types.gen.ts +20 -4
- package/.pikku/http/pikku-http-wirings-map.gen.d.ts +11 -11
- package/.pikku/http/pikku-http-wirings-meta.gen.json +9 -0
- package/.pikku/http/pikku-http-wirings-meta.gen.ts +4 -10
- package/.pikku/http/pikku-http-wirings.gen.ts +1 -1
- package/.pikku/mcp/pikku-mcp-types.gen.ts +72 -20
- package/.pikku/mcp/pikku-mcp-wirings-meta.gen.json +5 -0
- package/.pikku/mcp/pikku-mcp-wirings-meta.gen.ts +6 -4
- package/.pikku/mcp/pikku-mcp-wirings.gen.ts +1 -1
- package/.pikku/pikku-bootstrap.gen.ts +7 -12
- package/.pikku/pikku-services.gen.ts +6 -7
- package/.pikku/pikku-types.gen.ts +4 -1
- package/.pikku/pikku-websocket.gen.ts +1 -1
- package/.pikku/queue/pikku-queue-types.gen.ts +2 -2
- package/.pikku/queue/pikku-queue-workers-wirings-map.gen.d.ts +11 -11
- package/.pikku/queue/pikku-queue-workers-wirings-meta.gen.json +1 -0
- package/.pikku/queue/pikku-queue-workers-wirings-meta.gen.ts +5 -7
- package/.pikku/queue/pikku-queue-workers-wirings.gen.ts +1 -1
- package/.pikku/rpc/pikku-remote-rpc-workers.gen.ts +5 -2
- package/.pikku/rpc/pikku-rpc-wirings-map.gen.d.ts +19 -14
- package/.pikku/rpc/pikku-rpc-wirings-map.internal.gen.d.ts +46 -39
- package/.pikku/scheduler/pikku-scheduler-types.gen.ts +2 -2
- package/.pikku/scheduler/pikku-schedulers-wirings-meta.gen.json +1 -0
- package/.pikku/scheduler/pikku-schedulers-wirings-meta.gen.ts +5 -2
- package/.pikku/scheduler/pikku-schedulers-wirings.gen.ts +1 -1
- package/.pikku/schemas/register.gen.ts +31 -23
- package/.pikku/schemas/schemas/PikkuCLIConfig.schema.json +1 -1
- package/.pikku/schemas/schemas/PikkuCLIOutput.schema.json +1 -1
- package/.pikku/schemas/schemas/PikkuChannelsOutput.schema.json +1 -1
- package/.pikku/schemas/schemas/PikkuForgeNodesOutput.schema.json +1 -0
- package/.pikku/schemas/schemas/PikkuFunctionsOutput.schema.json +1 -1
- package/.pikku/schemas/schemas/PikkuHTTPOutput.schema.json +1 -1
- package/.pikku/schemas/schemas/PikkuMCPOutput.schema.json +1 -1
- package/.pikku/schemas/schemas/PikkuMiddlewareOutput.schema.json +1 -1
- package/.pikku/schemas/schemas/PikkuPackageOutput.schema.json +1 -0
- package/.pikku/schemas/schemas/PikkuPermissionsOutput.schema.json +1 -1
- package/.pikku/schemas/schemas/PikkuPublicRPCOutput.schema.json +1 -1
- package/.pikku/schemas/schemas/PikkuQueueOutput.schema.json +1 -1
- package/.pikku/schemas/schemas/PikkuRPCOutput.schema.json +1 -1
- package/.pikku/schemas/schemas/PikkuRemoteRPCOutput.schema.json +1 -1
- package/.pikku/schemas/schemas/PikkuSchedulerOutput.schema.json +1 -1
- package/.pikku/schemas/schemas/PikkuSchemasOutput.schema.json +1 -1
- package/.pikku/schemas/schemas/PikkuWorkflowOutput.schema.json +1 -1
- package/.pikku/services/config.gen.json +104 -0
- package/.pikku/services/getInspectorState.gen.json +10 -0
- package/.pikku/services/jwt.gen.json +13 -0
- package/.pikku/services/logger.gen.json +25 -0
- package/.pikku/services/queueService.gen.json +14 -0
- package/.pikku/services/schedulerService.gen.json +17 -0
- package/.pikku/services/schema.gen.json +14 -0
- package/.pikku/services/secrets.gen.json +13 -0
- package/.pikku/services/variables.gen.json +13 -0
- package/.pikku/services/workflowService.gen.json +31 -0
- package/.pikku/workflow/pikku-workflow-map.gen.d.ts +2 -36
- package/.pikku/workflow/pikku-workflow-types.gen.ts +305 -48
- package/.pikku/workflow/pikku-workflow-wirings-meta.gen.ts +6 -2
- package/.pikku/workflow/pikku-workflow-wirings.gen.ts +1 -2
- package/CHANGELOG.md +44 -1
- package/bin/pikku.ts +6 -32
- package/build.sh +53 -31
- package/cli.schema.json +1 -1
- package/dist/.pikku/channel/pikku-channel-types.gen.d.ts +51 -10
- package/dist/.pikku/channel/pikku-channel-types.gen.js +3 -13
- package/dist/.pikku/channel/pikku-channels-meta.gen.js +3 -2
- package/dist/.pikku/channel/pikku-channels-meta.gen.json +1 -0
- package/dist/.pikku/channel/pikku-channels.gen.d.ts +1 -1
- package/dist/.pikku/channel/pikku-channels.gen.js +1 -1
- package/dist/.pikku/cli/pikku-cli-channel.js +2 -2
- package/dist/.pikku/cli/pikku-cli-client.gen.d.ts +1 -1
- package/dist/.pikku/cli/pikku-cli-client.gen.js +1 -3
- package/dist/.pikku/cli/pikku-cli-types.gen.d.ts +3 -3
- package/dist/.pikku/cli/pikku-cli-types.gen.js +1 -1
- package/dist/.pikku/cli/pikku-cli-wirings-meta.gen.js +3 -157
- package/dist/.pikku/cli/pikku-cli-wirings-meta.gen.json +147 -0
- package/dist/.pikku/cli/pikku-cli-wirings.gen.d.ts +2 -2
- package/dist/.pikku/cli/pikku-cli-wirings.gen.js +2 -2
- package/dist/.pikku/cli/pikku-cli.gen.d.ts +1 -1
- package/dist/.pikku/cli/pikku-cli.gen.js +3 -3
- package/dist/.pikku/forge/pikku-forge-types.gen.d.ts +72 -0
- package/dist/.pikku/forge/pikku-forge-types.gen.js +55 -0
- package/dist/.pikku/function/pikku-function-types.gen.d.ts +141 -99
- package/dist/.pikku/function/pikku-function-types.gen.js +52 -62
- package/dist/.pikku/function/pikku-functions-meta.gen.js +3 -969
- package/dist/.pikku/function/pikku-functions-meta.gen.json +656 -0
- package/dist/.pikku/http/pikku-http-types.gen.d.ts +19 -4
- package/dist/.pikku/http/pikku-http-types.gen.js +1 -1
- package/dist/.pikku/http/pikku-http-wirings-meta.gen.js +3 -10
- package/dist/.pikku/http/pikku-http-wirings-meta.gen.json +9 -0
- package/dist/.pikku/http/pikku-http-wirings.gen.d.ts +1 -1
- package/dist/.pikku/http/pikku-http-wirings.gen.js +1 -1
- package/dist/.pikku/mcp/pikku-mcp-types.gen.d.ts +57 -17
- package/dist/.pikku/mcp/pikku-mcp-types.gen.js +7 -31
- package/dist/.pikku/mcp/pikku-mcp-wirings-meta.gen.js +5 -4
- package/dist/.pikku/mcp/pikku-mcp-wirings-meta.gen.json +5 -0
- package/dist/.pikku/mcp/pikku-mcp-wirings.gen.d.ts +1 -1
- package/dist/.pikku/mcp/pikku-mcp-wirings.gen.js +1 -1
- package/dist/.pikku/pikku-bootstrap.gen.d.ts +7 -12
- package/dist/.pikku/pikku-bootstrap.gen.js +7 -12
- package/dist/.pikku/pikku-services.gen.d.ts +5 -7
- package/dist/.pikku/pikku-services.gen.js +3 -5
- package/dist/.pikku/pikku-types.gen.d.ts +2 -1
- package/dist/.pikku/pikku-types.gen.js +3 -1
- package/dist/.pikku/pikku-websocket.gen.d.ts +1 -1
- package/dist/.pikku/pikku-websocket.gen.js +1 -1
- package/dist/.pikku/queue/pikku-queue-types.gen.d.ts +2 -2
- package/dist/.pikku/queue/pikku-queue-types.gen.js +1 -1
- package/dist/.pikku/queue/pikku-queue-workers-wirings-meta.gen.js +3 -7
- package/dist/.pikku/queue/pikku-queue-workers-wirings-meta.gen.json +1 -0
- package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.d.ts +1 -1
- package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.js +1 -1
- package/dist/.pikku/rpc/pikku-remote-rpc-workers.gen.d.ts +9 -9
- package/dist/.pikku/rpc/pikku-remote-rpc-workers.gen.js +5 -2
- package/dist/.pikku/scheduler/pikku-scheduler-types.gen.d.ts +2 -2
- package/dist/.pikku/scheduler/pikku-scheduler-types.gen.js +1 -1
- package/dist/.pikku/scheduler/pikku-schedulers-wirings-meta.gen.js +3 -2
- package/dist/.pikku/scheduler/pikku-schedulers-wirings-meta.gen.json +1 -0
- package/dist/.pikku/scheduler/pikku-schedulers-wirings.gen.d.ts +1 -1
- package/dist/.pikku/scheduler/pikku-schedulers-wirings.gen.js +1 -1
- package/dist/.pikku/schemas/register.gen.js +19 -15
- package/dist/.pikku/schemas/schemas/PikkuCLIConfig.schema.json +1 -1
- package/dist/.pikku/schemas/schemas/PikkuCLIOutput.schema.json +1 -1
- package/dist/.pikku/schemas/schemas/PikkuChannelsOutput.schema.json +1 -1
- package/dist/.pikku/schemas/schemas/PikkuForgeNodesOutput.schema.json +1 -0
- package/dist/.pikku/schemas/schemas/PikkuFunctionsOutput.schema.json +1 -1
- package/dist/.pikku/schemas/schemas/PikkuHTTPOutput.schema.json +1 -1
- package/dist/.pikku/schemas/schemas/PikkuMCPOutput.schema.json +1 -1
- package/dist/.pikku/schemas/schemas/PikkuMiddlewareOutput.schema.json +1 -1
- package/dist/.pikku/schemas/schemas/PikkuPackageOutput.schema.json +1 -0
- package/dist/.pikku/schemas/schemas/PikkuPermissionsOutput.schema.json +1 -1
- package/dist/.pikku/schemas/schemas/PikkuPublicRPCOutput.schema.json +1 -1
- package/dist/.pikku/schemas/schemas/PikkuQueueOutput.schema.json +1 -1
- package/dist/.pikku/schemas/schemas/PikkuRPCOutput.schema.json +1 -1
- package/dist/.pikku/schemas/schemas/PikkuRemoteRPCOutput.schema.json +1 -1
- package/dist/.pikku/schemas/schemas/PikkuSchedulerOutput.schema.json +1 -1
- package/dist/.pikku/schemas/schemas/PikkuSchemasOutput.schema.json +1 -1
- package/dist/.pikku/schemas/schemas/PikkuWorkflowOutput.schema.json +1 -1
- package/dist/.pikku/workflow/pikku-workflow-types.gen.d.ts +213 -39
- package/dist/.pikku/workflow/pikku-workflow-types.gen.js +106 -16
- package/dist/.pikku/workflow/pikku-workflow-wirings-meta.gen.js +3 -2
- package/dist/.pikku/workflow/pikku-workflow-wirings.gen.d.ts +1 -1
- package/dist/.pikku/workflow/pikku-workflow-wirings.gen.js +1 -2
- package/dist/bin/pikku.js +5 -26
- package/dist/src/cli.wiring.js +4 -4
- package/dist/src/functions/commands/all.js +172 -94
- package/dist/src/functions/commands/bootstrap.js +21 -16
- package/dist/src/functions/commands/watch.js +6 -3
- package/dist/src/functions/runtimes/nextjs/pikku-command-nextjs.js +12 -8
- package/dist/src/functions/runtimes/nextjs/serialize-nextjs-backend-wrapper.d.ts +1 -1
- package/dist/src/functions/runtimes/nextjs/serialize-nextjs-backend-wrapper.js +74 -22
- package/dist/src/functions/runtimes/nextjs/serialize-nextjs-http-wrapper.d.ts +1 -1
- package/dist/src/functions/runtimes/nextjs/serialize-nextjs-http-wrapper.js +72 -20
- package/dist/src/functions/wirings/channels/pikku-channels.js +9 -2
- package/dist/src/functions/wirings/channels/pikku-command-channels.js +18 -2
- package/dist/src/functions/wirings/channels/serialize-channel-types.js +72 -16
- package/dist/src/functions/wirings/channels/serialize-typed-channel-map.js +1 -2
- package/dist/src/functions/wirings/cli/pikku-command-cli-entry.js +4 -4
- package/dist/src/functions/wirings/cli/pikku-command-cli-types.js +1 -1
- package/dist/src/functions/wirings/cli/pikku-command-cli.js +17 -3
- package/dist/src/functions/wirings/cli/serialize-channel-cli.js +1 -1
- package/dist/src/functions/wirings/cli/serialize-cli-types.js +2 -2
- package/dist/src/functions/wirings/cli/serialize-local-cli-bootstrap.d.ts +1 -1
- package/dist/src/functions/wirings/cli/serialize-local-cli-bootstrap.js +4 -4
- package/dist/src/functions/wirings/forge/pikku-command-forge-nodes.d.ts +1 -0
- package/dist/src/functions/wirings/forge/pikku-command-forge-nodes.js +90 -0
- package/dist/src/functions/wirings/forge/pikku-command-forge-types.d.ts +1 -0
- package/dist/src/functions/wirings/forge/pikku-command-forge-types.js +26 -0
- package/dist/src/functions/wirings/forge/serialize-forge-types.d.ts +4 -0
- package/dist/src/functions/wirings/forge/serialize-forge-types.js +90 -0
- package/dist/src/functions/wirings/functions/pikku-command-function-types-split.js +4 -4
- package/dist/src/functions/wirings/functions/pikku-command-function-types.js +7 -2
- package/dist/src/functions/wirings/functions/pikku-command-functions.js +35 -10
- package/dist/src/functions/wirings/functions/pikku-command-services.d.ts +1 -1
- package/dist/src/functions/wirings/functions/pikku-command-services.js +24 -24
- package/dist/src/functions/wirings/functions/pikku-function-types.js +2 -2
- package/dist/src/functions/wirings/functions/schemas.d.ts +1 -1
- package/dist/src/functions/wirings/functions/schemas.js +5 -4
- package/dist/src/functions/wirings/functions/serialize-function-imports.d.ts +3 -1
- package/dist/src/functions/wirings/functions/serialize-function-imports.js +7 -3
- package/dist/src/functions/wirings/functions/serialize-function-types.d.ts +1 -1
- package/dist/src/functions/wirings/functions/serialize-function-types.js +224 -91
- package/dist/src/functions/wirings/functions/serialize-pikku-types-hub.d.ts +1 -1
- package/dist/src/functions/wirings/functions/serialize-pikku-types-hub.js +19 -21
- package/dist/src/functions/wirings/http/openapi-spec-generator.js +5 -5
- package/dist/src/functions/wirings/http/pikku-command-http-routes.js +18 -2
- package/dist/src/functions/wirings/http/pikku-command-openapi.js +2 -2
- package/dist/src/functions/wirings/http/pikku-http-routes.js +9 -2
- package/dist/src/functions/wirings/http/serialize-http-types.js +19 -3
- package/dist/src/functions/wirings/http/serialize-typed-http-map.js +33 -8
- package/dist/src/functions/wirings/mcp/pikku-command-mcp.js +29 -6
- package/dist/src/functions/wirings/mcp/serialize-mcp-json.js +3 -2
- package/dist/src/functions/wirings/mcp/serialize-mcp-types.js +71 -19
- package/dist/src/functions/wirings/middleware/pikku-command-middleware.js +29 -2
- package/dist/src/functions/wirings/middleware/serialize-middleware-groups-meta.d.ts +5 -2
- package/dist/src/functions/wirings/middleware/serialize-middleware-groups-meta.js +5 -13
- package/dist/src/functions/wirings/package/pikku-command-package.d.ts +1 -0
- package/dist/src/functions/wirings/package/pikku-command-package.js +58 -0
- package/dist/src/functions/wirings/package/serialize-package.d.ts +5 -0
- package/dist/src/functions/wirings/package/serialize-package.js +32 -0
- package/dist/src/functions/wirings/queue/pikku-command-queue.js +17 -3
- package/dist/src/functions/wirings/queue/pikku-queue.js +9 -11
- package/dist/src/functions/wirings/queue/serialize-queue-map.js +20 -3
- package/dist/src/functions/wirings/queue/serialize-queue-meta.d.ts +2 -1
- package/dist/src/functions/wirings/queue/serialize-queue-meta.js +10 -1
- package/dist/src/functions/wirings/queue/serialize-queue-types.js +1 -1
- package/dist/src/functions/wirings/rpc/pikku-command-rpc-map.js +4 -4
- package/dist/src/functions/wirings/rpc/pikku-command-rpc.js +9 -2
- package/dist/src/functions/wirings/rpc/serialize-public-rpc.js +11 -4
- package/dist/src/functions/wirings/rpc/serialize-remote-rpc.js +4 -1
- package/dist/src/functions/wirings/rpc/serialize-rpc-wrapper.js +3 -3
- package/dist/src/functions/wirings/rpc/serialize-typed-rpc-map.d.ts +1 -1
- package/dist/src/functions/wirings/rpc/serialize-typed-rpc-map.js +54 -8
- package/dist/src/functions/wirings/scheduler/pikku-command-scheduler.js +15 -3
- package/dist/src/functions/wirings/scheduler/serialize-scheduler-meta.d.ts +2 -1
- package/dist/src/functions/wirings/scheduler/serialize-scheduler-meta.js +11 -1
- package/dist/src/functions/wirings/scheduler/serialize-scheduler-types.js +1 -1
- package/dist/src/functions/wirings/services/pikku-command-service-metadata.d.ts +1 -0
- package/dist/src/functions/wirings/services/pikku-command-service-metadata.js +22 -0
- package/dist/src/functions/wirings/workflow/pikku-command-workflow.js +58 -16
- package/dist/src/functions/wirings/workflow/serialize-workflow-map.d.ts +3 -0
- package/dist/src/functions/wirings/workflow/serialize-workflow-map.js +30 -32
- package/dist/src/functions/wirings/workflow/serialize-workflow-meta.d.ts +1 -2
- package/dist/src/functions/wirings/workflow/serialize-workflow-meta.js +43 -8
- package/dist/src/functions/wirings/workflow/serialize-workflow-registration.d.ts +7 -0
- package/dist/src/functions/wirings/workflow/serialize-workflow-registration.js +53 -0
- package/dist/src/functions/wirings/workflow/serialize-workflow-types.d.ts +4 -2
- package/dist/src/functions/wirings/workflow/serialize-workflow-types.js +308 -49
- package/dist/src/functions/wirings/workflow/serialize-workflow-workers.d.ts +1 -1
- package/dist/src/functions/wirings/workflow/serialize-workflow-workers.js +16 -29
- package/dist/src/middleware/log-command-info-and-time.d.ts +2 -2
- package/dist/src/middleware/log-command-info-and-time.js +1 -4
- package/dist/src/services/cli-logger-forwarder.service.js +1 -1
- package/dist/src/services.d.ts +2 -7
- package/dist/src/services.js +18 -13
- package/dist/src/utils/check-required-types.d.ts +2 -2
- package/dist/src/utils/check-required-types.js +2 -3
- package/dist/src/utils/command-summary.d.ts +2 -0
- package/dist/src/utils/command-summary.js +2 -0
- package/dist/src/utils/custom-types-generator.js +13 -15
- package/dist/src/utils/generate-bootstrap-file.js +1 -1
- package/dist/src/utils/pikku-cli-config.js +65 -4
- package/dist/src/utils/pikku-files-and-methods.d.ts +2 -2
- package/dist/src/utils/pikku-files-and-methods.js +4 -4
- package/dist/src/utils/schema-generator.d.ts +4 -3
- package/dist/src/utils/schema-generator.js +135 -15
- package/dist/src/utils/strip-verbose-meta.d.ts +43 -0
- package/dist/src/utils/strip-verbose-meta.js +210 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +11 -9
- package/src/cli.wiring.ts +4 -4
- package/src/functions/commands/all.ts +203 -107
- package/src/functions/commands/bootstrap.ts +23 -16
- package/src/functions/commands/watch.ts +6 -3
- package/src/functions/runtimes/nextjs/pikku-command-nextjs.ts +26 -6
- package/src/functions/runtimes/nextjs/serialize-nextjs-backend-wrapper.ts +75 -22
- package/src/functions/runtimes/nextjs/serialize-nextjs-http-wrapper.ts +72 -19
- package/src/functions/wirings/channels/pikku-channels.ts +27 -3
- package/src/functions/wirings/channels/pikku-command-channels.ts +46 -3
- package/src/functions/wirings/channels/serialize-channel-types.ts +72 -16
- package/src/functions/wirings/channels/serialize-typed-channel-map.ts +3 -2
- package/src/functions/wirings/cli/pikku-command-cli-entry.ts +4 -4
- package/src/functions/wirings/cli/pikku-command-cli-types.ts +1 -1
- package/src/functions/wirings/cli/pikku-command-cli.ts +45 -3
- package/src/functions/wirings/cli/serialize-channel-cli.ts +1 -1
- package/src/functions/wirings/cli/serialize-cli-types.ts +2 -2
- package/src/functions/wirings/cli/serialize-local-cli-bootstrap.ts +5 -5
- package/src/functions/wirings/forge/pikku-command-forge-nodes.ts +135 -0
- package/src/functions/wirings/forge/pikku-command-forge-types.ts +38 -0
- package/src/functions/wirings/forge/serialize-forge-types.ts +94 -0
- package/src/functions/wirings/functions/pikku-command-function-types-split.ts +9 -8
- package/src/functions/wirings/functions/pikku-command-function-types.ts +17 -10
- package/src/functions/wirings/functions/pikku-command-functions.ts +59 -14
- package/src/functions/wirings/functions/pikku-command-services.ts +26 -26
- package/src/functions/wirings/functions/pikku-function-types.ts +3 -1
- package/src/functions/wirings/functions/schemas.ts +14 -4
- package/src/functions/wirings/functions/serialize-function-imports.ts +12 -3
- package/src/functions/wirings/functions/serialize-function-types.ts +227 -93
- package/src/functions/wirings/functions/serialize-pikku-types-hub.ts +27 -26
- package/src/functions/wirings/http/openapi-spec-generator.ts +15 -6
- package/src/functions/wirings/http/pikku-command-http-routes.ts +46 -2
- package/src/functions/wirings/http/pikku-command-openapi.ts +3 -2
- package/src/functions/wirings/http/pikku-http-routes.ts +28 -2
- package/src/functions/wirings/http/serialize-http-types.ts +19 -3
- package/src/functions/wirings/http/serialize-typed-http-map.ts +32 -8
- package/src/functions/wirings/mcp/pikku-command-mcp.ts +58 -10
- package/src/functions/wirings/mcp/serialize-mcp-json.ts +8 -6
- package/src/functions/wirings/mcp/serialize-mcp-types.ts +71 -19
- package/src/functions/wirings/middleware/pikku-command-middleware.ts +39 -2
- package/src/functions/wirings/middleware/serialize-middleware-groups-meta.ts +4 -19
- package/src/functions/wirings/package/pikku-command-package.ts +81 -0
- package/src/functions/wirings/package/serialize-package.ts +69 -0
- package/src/functions/wirings/permissions/pikku-command-permissions.ts +2 -2
- package/src/functions/wirings/queue/pikku-command-queue.ts +47 -2
- package/src/functions/wirings/queue/pikku-queue.ts +26 -10
- package/src/functions/wirings/queue/serialize-queue-map.ts +18 -3
- package/src/functions/wirings/queue/serialize-queue-meta.ts +15 -1
- package/src/functions/wirings/queue/serialize-queue-types.ts +1 -1
- package/src/functions/wirings/rpc/pikku-command-rpc-map.ts +7 -4
- package/src/functions/wirings/rpc/pikku-command-rpc.ts +25 -2
- package/src/functions/wirings/rpc/serialize-public-rpc.ts +11 -4
- package/src/functions/wirings/rpc/serialize-remote-rpc.ts +4 -1
- package/src/functions/wirings/rpc/serialize-rpc-wrapper.ts +3 -3
- package/src/functions/wirings/rpc/serialize-typed-rpc-map.ts +74 -8
- package/src/functions/wirings/scheduler/pikku-command-scheduler.ts +51 -4
- package/src/functions/wirings/scheduler/serialize-scheduler-meta.ts +20 -1
- package/src/functions/wirings/scheduler/serialize-scheduler-types.ts +1 -1
- package/src/functions/wirings/services/pikku-command-service-metadata.ts +25 -0
- package/src/functions/wirings/workflow/pikku-command-workflow.ts +114 -19
- package/src/functions/wirings/workflow/serialize-workflow-map.ts +38 -40
- package/src/functions/wirings/workflow/serialize-workflow-meta.ts +68 -11
- package/src/functions/wirings/workflow/serialize-workflow-registration.ts +83 -0
- package/src/functions/wirings/workflow/serialize-workflow-types.ts +311 -49
- package/src/functions/wirings/workflow/serialize-workflow-workers.ts +16 -29
- package/src/middleware/log-command-info-and-time.ts +3 -6
- package/src/services/cli-logger-forwarder.service.ts +1 -1
- package/src/services.ts +23 -16
- package/src/utils/check-required-types.ts +4 -7
- package/src/utils/command-summary.ts +4 -0
- package/src/utils/custom-types-generator.ts +15 -15
- package/src/utils/generate-bootstrap-file.ts +1 -1
- package/src/utils/pikku-cli-config.ts +105 -5
- package/src/utils/pikku-files-and-methods.ts +10 -13
- package/src/utils/schema-generator.ts +185 -22
- package/src/utils/strip-verbose-meta.ts +254 -0
- package/types/application-types.d.ts +1 -1
- package/types/config.d.ts +47 -2
- package/.pikku/function/pikku-functions-meta.min.gen.ts +0 -211
- package/.pikku/function/pikku-functions.gen.ts +0 -84
- package/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.ts +0 -47
- package/dist/.pikku/function/pikku-functions-meta.min.gen.d.ts +0 -1
- package/dist/.pikku/function/pikku-functions-meta.min.gen.js +0 -211
- package/dist/.pikku/function/pikku-functions.gen.d.ts +0 -1
- package/dist/.pikku/function/pikku-functions.gen.js +0 -83
- package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.d.ts +0 -1
- package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.js +0 -47
- package/dist/.pikku/schemas/schemas/PikkuRemoteInternalRPCInput.schema.json +0 -1
- package/dist/src/functions/wirings/workflow/pikku-command-workflow-map.d.ts +0 -1
- package/dist/src/functions/wirings/workflow/pikku-command-workflow-map.js +0 -12
- package/dist/src/functions/wirings/workflow/pikku-command-workflow-types.d.ts +0 -1
- package/dist/src/functions/wirings/workflow/pikku-command-workflow-types.js +0 -11
- package/src/functions/wirings/workflow/pikku-command-workflow-map.ts +0 -24
- package/src/functions/wirings/workflow/pikku-command-workflow-types.ts +0 -22
|
@@ -1,32 +1,35 @@
|
|
|
1
1
|
import { TypesMap } from '@pikku/inspector'
|
|
2
2
|
|
|
3
|
+
// Sanitize a type name to be a valid TypeScript identifier
|
|
4
|
+
function sanitizeTypeName(name: string): string {
|
|
5
|
+
// Replace hyphens with underscores
|
|
6
|
+
return name.replace(/-/g, '_')
|
|
7
|
+
}
|
|
8
|
+
|
|
3
9
|
export function generateCustomTypes(
|
|
4
10
|
typesMap: TypesMap,
|
|
5
11
|
requiredTypes: Set<string>
|
|
6
12
|
) {
|
|
7
13
|
return `
|
|
8
|
-
// Custom types are those that are defined directly within generics
|
|
9
|
-
// or are broken into simpler types
|
|
10
14
|
${Array.from(typesMap.customTypes.entries())
|
|
11
|
-
.
|
|
15
|
+
.filter(([_name, { type }]) => {
|
|
16
|
+
const hasUndefinedGeneric =
|
|
17
|
+
/\b(Name|In|Out|Key)\b/.test(type) && /\[.*\]/.test(type)
|
|
18
|
+
return !hasUndefinedGeneric
|
|
19
|
+
})
|
|
20
|
+
.map(([originalName, { type, references }]) => {
|
|
21
|
+
const name = sanitizeTypeName(originalName)
|
|
12
22
|
references.forEach((refName) => {
|
|
13
|
-
// Skip __object types (including those with suffixes like __object_abc123)
|
|
14
|
-
// These are placeholder types created by the inspector for invalid/broken functions
|
|
15
|
-
// (e.g., functions with type errors or missing return statements). Attempting to
|
|
16
|
-
// import these would fail since the source files don't actually export __object.
|
|
17
23
|
if (refName !== '__object' && !refName.startsWith('__object_')) {
|
|
18
24
|
requiredTypes.add(refName)
|
|
19
25
|
}
|
|
20
26
|
})
|
|
21
27
|
|
|
22
|
-
// Extract type names from the type string that might not be in references
|
|
23
28
|
const typeString = type
|
|
24
|
-
// Use regex to extract potential type names (PascalCase identifiers)
|
|
25
29
|
const typeNameRegex = /\b[A-Z][a-zA-Z0-9]*\b/g
|
|
26
30
|
const potentialTypes = typeString.match(typeNameRegex) || []
|
|
27
31
|
|
|
28
32
|
potentialTypes.forEach((typeName) => {
|
|
29
|
-
// Skip string literals and common keywords
|
|
30
33
|
if (
|
|
31
34
|
typeString.includes(`"${typeName}"`) ||
|
|
32
35
|
['Pick', 'Omit', 'Partial', 'Required', 'Record', 'Readonly'].includes(
|
|
@@ -36,16 +39,13 @@ ${Array.from(typesMap.customTypes.entries())
|
|
|
36
39
|
return
|
|
37
40
|
}
|
|
38
41
|
|
|
39
|
-
// Try to find this type in the typesMap and add it if found
|
|
40
42
|
try {
|
|
41
43
|
const typeMeta = typesMap.getTypeMeta(typeName)
|
|
42
44
|
if (typeMeta.path) {
|
|
43
|
-
// Add originalName to preserve canonical import name
|
|
44
45
|
requiredTypes.add(typeMeta.originalName)
|
|
45
46
|
}
|
|
46
|
-
} catch
|
|
47
|
-
// Type not found in map (ambient/builtin type)
|
|
48
|
-
// Do NOT add to requiredTypes to avoid crashes in serializeImportMap
|
|
47
|
+
} catch {
|
|
48
|
+
// Type not found in map (ambient/builtin type)
|
|
49
49
|
}
|
|
50
50
|
})
|
|
51
51
|
|
|
@@ -19,7 +19,7 @@ export const generateBootstrapFile = async (
|
|
|
19
19
|
commonImports.push(config.middlewareFile)
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
commonImports.push(config.
|
|
22
|
+
commonImports.push(config.functionsMetaFile, config.functionsFile)
|
|
23
23
|
|
|
24
24
|
// Add schema if it exists
|
|
25
25
|
if (schemas) {
|
|
@@ -64,6 +64,10 @@ const _getPikkuCLIConfig = async (
|
|
|
64
64
|
...extendedConfig.packageMappings,
|
|
65
65
|
...config.packageMappings,
|
|
66
66
|
},
|
|
67
|
+
externalPackages: {
|
|
68
|
+
...extendedConfig.externalPackages,
|
|
69
|
+
...config.externalPackages,
|
|
70
|
+
},
|
|
67
71
|
ignoreFiles: config.ignoreFiles ??
|
|
68
72
|
extendedConfig.ignoreFiles ?? [
|
|
69
73
|
'**/*.test.ts',
|
|
@@ -73,7 +77,7 @@ const _getPikkuCLIConfig = async (
|
|
|
73
77
|
],
|
|
74
78
|
schema: {
|
|
75
79
|
additionalProperties: false,
|
|
76
|
-
supportsImportAttributes:
|
|
80
|
+
supportsImportAttributes: true,
|
|
77
81
|
...extendedConfig.schema,
|
|
78
82
|
...config.schema,
|
|
79
83
|
},
|
|
@@ -83,6 +87,7 @@ const _getPikkuCLIConfig = async (
|
|
|
83
87
|
...config,
|
|
84
88
|
configDir,
|
|
85
89
|
packageMappings: config.packageMappings || {},
|
|
90
|
+
externalPackages: config.externalPackages || {},
|
|
86
91
|
rootDir: config.rootDir
|
|
87
92
|
? resolve(configDir, config.rootDir)
|
|
88
93
|
: configDir,
|
|
@@ -94,7 +99,7 @@ const _getPikkuCLIConfig = async (
|
|
|
94
99
|
],
|
|
95
100
|
schema: {
|
|
96
101
|
additionalProperties: false,
|
|
97
|
-
supportsImportAttributes:
|
|
102
|
+
supportsImportAttributes: true,
|
|
98
103
|
...config.schema,
|
|
99
104
|
},
|
|
100
105
|
}
|
|
@@ -128,10 +133,10 @@ const _getPikkuCLIConfig = async (
|
|
|
128
133
|
'pikku-functions-meta.gen.ts'
|
|
129
134
|
)
|
|
130
135
|
}
|
|
131
|
-
if (!result.
|
|
132
|
-
result.
|
|
136
|
+
if (!result.functionsMetaJsonFile) {
|
|
137
|
+
result.functionsMetaJsonFile = join(
|
|
133
138
|
functionDir,
|
|
134
|
-
'pikku-functions-meta.
|
|
139
|
+
'pikku-functions-meta.gen.json'
|
|
135
140
|
)
|
|
136
141
|
}
|
|
137
142
|
if (!result.functionTypesFile) {
|
|
@@ -154,6 +159,12 @@ const _getPikkuCLIConfig = async (
|
|
|
154
159
|
'pikku-http-wirings-meta.gen.ts'
|
|
155
160
|
)
|
|
156
161
|
}
|
|
162
|
+
if (!result.httpWiringMetaJsonFile) {
|
|
163
|
+
result.httpWiringMetaJsonFile = join(
|
|
164
|
+
httpDir,
|
|
165
|
+
'pikku-http-wirings-meta.gen.json'
|
|
166
|
+
)
|
|
167
|
+
}
|
|
157
168
|
if (!result.httpMapDeclarationFile) {
|
|
158
169
|
result.httpMapDeclarationFile = join(
|
|
159
170
|
httpDir,
|
|
@@ -174,6 +185,12 @@ const _getPikkuCLIConfig = async (
|
|
|
174
185
|
'pikku-channels-meta.gen.ts'
|
|
175
186
|
)
|
|
176
187
|
}
|
|
188
|
+
if (!result.channelsWiringMetaJsonFile) {
|
|
189
|
+
result.channelsWiringMetaJsonFile = join(
|
|
190
|
+
channelDir,
|
|
191
|
+
'pikku-channels-meta.gen.json'
|
|
192
|
+
)
|
|
193
|
+
}
|
|
177
194
|
if (!result.channelsMapDeclarationFile) {
|
|
178
195
|
result.channelsMapDeclarationFile = join(
|
|
179
196
|
channelDir,
|
|
@@ -192,6 +209,13 @@ const _getPikkuCLIConfig = async (
|
|
|
192
209
|
)
|
|
193
210
|
}
|
|
194
211
|
|
|
212
|
+
if (!result.rpcInternalWiringMetaJsonFile) {
|
|
213
|
+
result.rpcInternalWiringMetaJsonFile = join(
|
|
214
|
+
rpcDir,
|
|
215
|
+
'pikku-rpc-wirings-meta.internal.gen.json'
|
|
216
|
+
)
|
|
217
|
+
}
|
|
218
|
+
|
|
195
219
|
if (!result.rpcInternalMapDeclarationFile) {
|
|
196
220
|
result.rpcInternalMapDeclarationFile = join(
|
|
197
221
|
rpcDir,
|
|
@@ -230,6 +254,12 @@ const _getPikkuCLIConfig = async (
|
|
|
230
254
|
'pikku-schedulers-wirings-meta.gen.ts'
|
|
231
255
|
)
|
|
232
256
|
}
|
|
257
|
+
if (!result.schedulersWiringMetaJsonFile) {
|
|
258
|
+
result.schedulersWiringMetaJsonFile = join(
|
|
259
|
+
schedulerDir,
|
|
260
|
+
'pikku-schedulers-wirings-meta.gen.json'
|
|
261
|
+
)
|
|
262
|
+
}
|
|
233
263
|
if (!result.schedulersTypesFile) {
|
|
234
264
|
result.schedulersTypesFile = join(
|
|
235
265
|
schedulerDir,
|
|
@@ -250,6 +280,12 @@ const _getPikkuCLIConfig = async (
|
|
|
250
280
|
'pikku-queue-workers-wirings-meta.gen.ts'
|
|
251
281
|
)
|
|
252
282
|
}
|
|
283
|
+
if (!result.queueWorkersWiringMetaJsonFile) {
|
|
284
|
+
result.queueWorkersWiringMetaJsonFile = join(
|
|
285
|
+
queueDir,
|
|
286
|
+
'pikku-queue-workers-wirings-meta.gen.json'
|
|
287
|
+
)
|
|
288
|
+
}
|
|
253
289
|
if (!result.queueMapDeclarationFile) {
|
|
254
290
|
result.queueMapDeclarationFile = join(
|
|
255
291
|
queueDir,
|
|
@@ -292,6 +328,11 @@ const _getPikkuCLIConfig = async (
|
|
|
292
328
|
)
|
|
293
329
|
}
|
|
294
330
|
|
|
331
|
+
// Workflow meta directory (individual JSON files for each workflow)
|
|
332
|
+
if (!result.workflowMetaDir) {
|
|
333
|
+
result.workflowMetaDir = join(workflowDir, 'meta')
|
|
334
|
+
}
|
|
335
|
+
|
|
295
336
|
// Services
|
|
296
337
|
if (!result.servicesFile) {
|
|
297
338
|
result.servicesFile = join(result.outDir, 'pikku-services.gen.ts')
|
|
@@ -307,6 +348,12 @@ const _getPikkuCLIConfig = async (
|
|
|
307
348
|
'pikku-middleware-groups-meta.gen.ts'
|
|
308
349
|
)
|
|
309
350
|
}
|
|
351
|
+
if (!result.middlewareGroupsMetaJsonFile) {
|
|
352
|
+
result.middlewareGroupsMetaJsonFile = join(
|
|
353
|
+
middlewareDir,
|
|
354
|
+
'pikku-middleware-groups-meta.gen.json'
|
|
355
|
+
)
|
|
356
|
+
}
|
|
310
357
|
|
|
311
358
|
// Permissions
|
|
312
359
|
const permissionsDir = join(result.outDir, 'permissions')
|
|
@@ -319,10 +366,21 @@ const _getPikkuCLIConfig = async (
|
|
|
319
366
|
result.bootstrapFile = join(result.outDir, 'pikku-bootstrap.gen.ts')
|
|
320
367
|
}
|
|
321
368
|
|
|
369
|
+
// Package service factories (for external packages)
|
|
370
|
+
if (!result.packageFile) {
|
|
371
|
+
result.packageFile = join(result.outDir, 'pikku-package.gen.ts')
|
|
372
|
+
}
|
|
373
|
+
|
|
322
374
|
// MCP
|
|
323
375
|
if (!result.mcpWiringsMetaFile) {
|
|
324
376
|
result.mcpWiringsMetaFile = join(mcpDir, 'pikku-mcp-wirings-meta.gen.ts')
|
|
325
377
|
}
|
|
378
|
+
if (!result.mcpWiringsMetaJsonFile) {
|
|
379
|
+
result.mcpWiringsMetaJsonFile = join(
|
|
380
|
+
mcpDir,
|
|
381
|
+
'pikku-mcp-wirings-meta.gen.json'
|
|
382
|
+
)
|
|
383
|
+
}
|
|
326
384
|
if (!result.mcpWiringsFile) {
|
|
327
385
|
result.mcpWiringsFile = join(mcpDir, 'pikku-mcp-wirings.gen.ts')
|
|
328
386
|
}
|
|
@@ -340,6 +398,12 @@ const _getPikkuCLIConfig = async (
|
|
|
340
398
|
if (!result.cliWiringMetaFile) {
|
|
341
399
|
result.cliWiringMetaFile = join(cliDir, 'pikku-cli-wirings-meta.gen.ts')
|
|
342
400
|
}
|
|
401
|
+
if (!result.cliWiringMetaJsonFile) {
|
|
402
|
+
result.cliWiringMetaJsonFile = join(
|
|
403
|
+
cliDir,
|
|
404
|
+
'pikku-cli-wirings-meta.gen.json'
|
|
405
|
+
)
|
|
406
|
+
}
|
|
343
407
|
if (!result.cliBootstrapFile) {
|
|
344
408
|
result.cliBootstrapFile = join(cliDir, 'pikku-cli-bootstrap.gen.ts')
|
|
345
409
|
}
|
|
@@ -347,6 +411,18 @@ const _getPikkuCLIConfig = async (
|
|
|
347
411
|
result.cliTypesFile = join(cliDir, 'pikku-cli-types.gen.ts')
|
|
348
412
|
}
|
|
349
413
|
|
|
414
|
+
// Forge
|
|
415
|
+
const forgeDir = join(result.outDir, 'forge')
|
|
416
|
+
if (!result.forgeNodesMetaJsonFile) {
|
|
417
|
+
result.forgeNodesMetaJsonFile = join(
|
|
418
|
+
forgeDir,
|
|
419
|
+
'pikku-forge-nodes-meta.gen.json'
|
|
420
|
+
)
|
|
421
|
+
}
|
|
422
|
+
if (!result.forgeTypesFile) {
|
|
423
|
+
result.forgeTypesFile = join(forgeDir, 'pikku-forge-types.gen.ts')
|
|
424
|
+
}
|
|
425
|
+
|
|
350
426
|
if (requiredFields.length > 0) {
|
|
351
427
|
validateCLIConfig(result, requiredFields)
|
|
352
428
|
}
|
|
@@ -369,6 +445,30 @@ const _getPikkuCLIConfig = async (
|
|
|
369
445
|
result.tsconfig = join(result.rootDir, result.tsconfig)
|
|
370
446
|
}
|
|
371
447
|
|
|
448
|
+
if (result.externalPackage) {
|
|
449
|
+
const packageJsonPath = join(result.rootDir, 'package.json')
|
|
450
|
+
try {
|
|
451
|
+
const packageJsonContent = await readFile(packageJsonPath, 'utf-8')
|
|
452
|
+
const packageJson = JSON.parse(packageJsonContent)
|
|
453
|
+
|
|
454
|
+
if (
|
|
455
|
+
!packageJson.name ||
|
|
456
|
+
typeof packageJson.name !== 'string' ||
|
|
457
|
+
packageJson.name.trim() === ''
|
|
458
|
+
) {
|
|
459
|
+
throw new Error(
|
|
460
|
+
`package.json at ${packageJsonPath} is missing a valid "name" field`
|
|
461
|
+
)
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
result.externalPackageName = packageJson.name
|
|
465
|
+
} catch (e: any) {
|
|
466
|
+
throw new Error(
|
|
467
|
+
`externalPackage is true but could not read or parse package.json at ${packageJsonPath}: ${e.message}`
|
|
468
|
+
)
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
|
|
372
472
|
return result
|
|
373
473
|
} catch (e: any) {
|
|
374
474
|
logger.error(e)
|
|
@@ -14,11 +14,11 @@ interface Meta {
|
|
|
14
14
|
|
|
15
15
|
export type FilesAndMethods = {
|
|
16
16
|
userSessionType: Meta
|
|
17
|
-
|
|
17
|
+
wireServicesType: Meta
|
|
18
18
|
singletonServicesType: Meta
|
|
19
19
|
pikkuConfigFactory: Meta
|
|
20
20
|
singletonServicesFactory: Meta
|
|
21
|
-
|
|
21
|
+
wireServicesFactory: Meta
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
const getMetaTypes = (
|
|
@@ -85,9 +85,9 @@ export const getPikkuFilesAndMethods = async (
|
|
|
85
85
|
): Promise<FilesAndMethods> => {
|
|
86
86
|
const {
|
|
87
87
|
singletonServicesTypeImportMap,
|
|
88
|
-
|
|
88
|
+
wireServicesTypeImportMap,
|
|
89
89
|
userSessionTypeImportMap,
|
|
90
|
-
|
|
90
|
+
wireServicesFactories,
|
|
91
91
|
singletonServicesFactories,
|
|
92
92
|
configFactories,
|
|
93
93
|
} = state
|
|
@@ -96,7 +96,7 @@ export const getPikkuFilesAndMethods = async (
|
|
|
96
96
|
configFileType,
|
|
97
97
|
userSessionType,
|
|
98
98
|
singletonServicesFactoryType,
|
|
99
|
-
|
|
99
|
+
wireServicesFactoryType,
|
|
100
100
|
} = options
|
|
101
101
|
let errors = new Map<string, PathToNameAndType>()
|
|
102
102
|
|
|
@@ -110,10 +110,7 @@ export const getPikkuFilesAndMethods = async (
|
|
|
110
110
|
'CoreSingletonServices',
|
|
111
111
|
singletonServicesTypeImportMap
|
|
112
112
|
),
|
|
113
|
-
|
|
114
|
-
'CoreServices',
|
|
115
|
-
sessionServicesTypeImportMap
|
|
116
|
-
),
|
|
113
|
+
wireServicesType: getMetaTypes('CoreServices', wireServicesTypeImportMap),
|
|
117
114
|
pikkuConfigFactory: getMetaTypes(
|
|
118
115
|
'CoreConfig',
|
|
119
116
|
configFactories,
|
|
@@ -124,10 +121,10 @@ export const getPikkuFilesAndMethods = async (
|
|
|
124
121
|
singletonServicesFactories,
|
|
125
122
|
singletonServicesFactoryType
|
|
126
123
|
),
|
|
127
|
-
|
|
128
|
-
'
|
|
129
|
-
|
|
130
|
-
|
|
124
|
+
wireServicesFactory: getMetaTypes(
|
|
125
|
+
'CreateWireServices',
|
|
126
|
+
wireServicesFactories,
|
|
127
|
+
wireServicesFactoryType
|
|
131
128
|
),
|
|
132
129
|
}
|
|
133
130
|
|
|
@@ -3,8 +3,88 @@ import { writeFileInDir } from './file-writer.js'
|
|
|
3
3
|
import { mkdir, writeFile } from 'fs/promises'
|
|
4
4
|
import { FunctionsMeta, JSONValue } from '@pikku/core'
|
|
5
5
|
import { HTTPWiringsMeta } from '@pikku/core/http'
|
|
6
|
-
import { TypesMap, ErrorCode } from '@pikku/inspector'
|
|
6
|
+
import { TypesMap, ErrorCode, ZodSchemaRef } from '@pikku/inspector'
|
|
7
7
|
import { CLILogger } from '../services/cli-logger.service.js'
|
|
8
|
+
import { tsImport } from 'tsx/esm/api'
|
|
9
|
+
import * as z from 'zod'
|
|
10
|
+
import { zodToTs, createAuxiliaryTypeStore } from 'zod-to-ts'
|
|
11
|
+
import {
|
|
12
|
+
createPrinter,
|
|
13
|
+
createSourceFile,
|
|
14
|
+
EmitHint,
|
|
15
|
+
ScriptKind,
|
|
16
|
+
ScriptTarget,
|
|
17
|
+
} from 'typescript'
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Convert a name to a valid JavaScript identifier.
|
|
21
|
+
* Replaces hyphens and other invalid characters with underscores.
|
|
22
|
+
*/
|
|
23
|
+
function toValidIdentifier(name: string): string {
|
|
24
|
+
let result = name.replace(/[-./]/g, '_')
|
|
25
|
+
if (/^\d/.test(result)) {
|
|
26
|
+
result = '_' + result
|
|
27
|
+
}
|
|
28
|
+
return result
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const PRIMITIVE_TYPES = new Set([
|
|
32
|
+
'boolean',
|
|
33
|
+
'string',
|
|
34
|
+
'number',
|
|
35
|
+
'null',
|
|
36
|
+
'undefined',
|
|
37
|
+
'void',
|
|
38
|
+
'any',
|
|
39
|
+
'unknown',
|
|
40
|
+
'never',
|
|
41
|
+
])
|
|
42
|
+
|
|
43
|
+
/** Map TypeScript type strings to JSON Schema. Returns null if no schema should be generated. */
|
|
44
|
+
function primitiveTypeToSchema(typeStr: string): JSONValue | null {
|
|
45
|
+
const normalized = typeStr.trim()
|
|
46
|
+
|
|
47
|
+
// void/undefined/never mean no data - don't generate a schema
|
|
48
|
+
if (
|
|
49
|
+
normalized === 'void' ||
|
|
50
|
+
normalized === 'undefined' ||
|
|
51
|
+
normalized === 'never'
|
|
52
|
+
) {
|
|
53
|
+
return null
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Handle boolean literals
|
|
57
|
+
if (
|
|
58
|
+
normalized === 'boolean' ||
|
|
59
|
+
normalized === 'false | true' ||
|
|
60
|
+
normalized === 'true | false'
|
|
61
|
+
) {
|
|
62
|
+
return { type: 'boolean' }
|
|
63
|
+
}
|
|
64
|
+
if (normalized === 'true') {
|
|
65
|
+
return { const: true }
|
|
66
|
+
}
|
|
67
|
+
if (normalized === 'false') {
|
|
68
|
+
return { const: false }
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Handle string
|
|
72
|
+
if (normalized === 'string') {
|
|
73
|
+
return { type: 'string' }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Handle number
|
|
77
|
+
if (normalized === 'number') {
|
|
78
|
+
return { type: 'number' }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Handle null
|
|
82
|
+
if (normalized === 'null') {
|
|
83
|
+
return { type: 'null' }
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return null
|
|
87
|
+
}
|
|
8
88
|
|
|
9
89
|
export async function generateSchemas(
|
|
10
90
|
logger: CLILogger,
|
|
@@ -13,7 +93,8 @@ export async function generateSchemas(
|
|
|
13
93
|
functionMeta: FunctionsMeta,
|
|
14
94
|
httpWiringsMeta: HTTPWiringsMeta,
|
|
15
95
|
additionalTypes?: string[],
|
|
16
|
-
additionalProperties: boolean = false
|
|
96
|
+
additionalProperties: boolean = false,
|
|
97
|
+
zodLookup?: Map<string, ZodSchemaRef>
|
|
17
98
|
): Promise<Record<string, JSONValue>> {
|
|
18
99
|
const schemasSet = new Set(typesMap.customTypes.keys())
|
|
19
100
|
for (const { inputs, outputs } of Object.values(functionMeta)) {
|
|
@@ -44,7 +125,6 @@ export async function generateSchemas(
|
|
|
44
125
|
}
|
|
45
126
|
}
|
|
46
127
|
|
|
47
|
-
// Add additional types from schemasFromTypes config
|
|
48
128
|
if (additionalTypes) {
|
|
49
129
|
for (const type of additionalTypes) {
|
|
50
130
|
schemasSet.add(type)
|
|
@@ -66,18 +146,28 @@ export async function generateSchemas(
|
|
|
66
146
|
const schemas: Record<string, JSONValue> = {}
|
|
67
147
|
|
|
68
148
|
schemasSet.forEach((schema) => {
|
|
149
|
+
if (PRIMITIVE_TYPES.has(schema)) {
|
|
150
|
+
return
|
|
151
|
+
}
|
|
152
|
+
if (zodLookup?.has(schema)) {
|
|
153
|
+
return
|
|
154
|
+
}
|
|
69
155
|
try {
|
|
70
156
|
schemas[schema] = generator.createSchema(schema) as JSONValue
|
|
71
157
|
} catch (e) {
|
|
72
|
-
// Ignore rootless errors
|
|
73
158
|
if (e instanceof RootlessError) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
159
|
+
const customType = typesMap.customTypes.get(schema)
|
|
160
|
+
if (customType) {
|
|
161
|
+
const primitiveSchema = primitiveTypeToSchema(customType.type)
|
|
162
|
+
if (primitiveSchema) {
|
|
163
|
+
schemas[schema] = primitiveSchema
|
|
164
|
+
}
|
|
165
|
+
}
|
|
77
166
|
return
|
|
78
167
|
}
|
|
168
|
+
const customType = typesMap.customTypes.get(schema)
|
|
79
169
|
logger.error(
|
|
80
|
-
`[${ErrorCode.SCHEMA_GENERATION_ERROR}] Error generating schema: ${schema}. Message: ${e.message}`
|
|
170
|
+
`[${ErrorCode.SCHEMA_GENERATION_ERROR}] Error generating schema: ${schema}. Message: ${e.message}. Type info: ${customType ? `type=${customType.type}` : 'not in typesMap'}`
|
|
81
171
|
)
|
|
82
172
|
}
|
|
83
173
|
})
|
|
@@ -85,14 +175,78 @@ export async function generateSchemas(
|
|
|
85
175
|
return schemas
|
|
86
176
|
}
|
|
87
177
|
|
|
178
|
+
export async function generateZodSchemas(
|
|
179
|
+
logger: CLILogger,
|
|
180
|
+
zodLookup: Map<string, ZodSchemaRef>,
|
|
181
|
+
typesMap: TypesMap
|
|
182
|
+
): Promise<Record<string, JSONValue>> {
|
|
183
|
+
const schemas: Record<string, JSONValue> = {}
|
|
184
|
+
const auxiliaryTypeStore = createAuxiliaryTypeStore()
|
|
185
|
+
const printer = createPrinter()
|
|
186
|
+
const fakeSourceFile = createSourceFile(
|
|
187
|
+
'zod-types.ts',
|
|
188
|
+
'',
|
|
189
|
+
ScriptTarget.ESNext,
|
|
190
|
+
false,
|
|
191
|
+
ScriptKind.TS
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
for (const [schemaName, ref] of zodLookup.entries()) {
|
|
195
|
+
try {
|
|
196
|
+
const module = await tsImport(ref.sourceFile, import.meta.url)
|
|
197
|
+
const zodSchema = module[ref.variableName]
|
|
198
|
+
if (!zodSchema) {
|
|
199
|
+
logger.warn(
|
|
200
|
+
`Could not find exported schema '${ref.variableName}' in ${ref.sourceFile} for ${schemaName}. Available exports: ${Object.keys(module).join(', ')}`
|
|
201
|
+
)
|
|
202
|
+
continue
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const schema = z.toJSONSchema(zodSchema) as any
|
|
206
|
+
|
|
207
|
+
// Remove fields with defaults from the required array
|
|
208
|
+
// Fields with defaults are semantically optional in input validation
|
|
209
|
+
if (schema.required && schema.properties) {
|
|
210
|
+
schema.required = schema.required.filter((fieldName: string) => {
|
|
211
|
+
const prop = schema.properties[fieldName]
|
|
212
|
+
return prop && prop.default === undefined
|
|
213
|
+
})
|
|
214
|
+
if (schema.required.length === 0) {
|
|
215
|
+
delete schema.required
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
schemas[schemaName] = schema
|
|
220
|
+
const { node: tsType } = zodToTs(zodSchema, { auxiliaryTypeStore })
|
|
221
|
+
|
|
222
|
+
const typeText = printer.printNode(
|
|
223
|
+
EmitHint.Unspecified,
|
|
224
|
+
tsType,
|
|
225
|
+
fakeSourceFile
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
typesMap.addCustomType(schemaName, typeText, [])
|
|
229
|
+
logger.info(`• Generated schema from Zod: ${schemaName}`)
|
|
230
|
+
} catch (e) {
|
|
231
|
+
logger.warn(
|
|
232
|
+
`Could not convert Zod schema '${schemaName}': ${e instanceof Error ? e.message : e}`
|
|
233
|
+
)
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return schemas
|
|
238
|
+
}
|
|
239
|
+
|
|
88
240
|
export async function saveSchemas(
|
|
89
241
|
logger: CLILogger,
|
|
90
242
|
schemaParentDir: string,
|
|
91
243
|
schemas: Record<string, JSONValue>,
|
|
92
244
|
typesMap: TypesMap,
|
|
93
245
|
functionsMeta: FunctionsMeta,
|
|
246
|
+
supportsImportAttributes: boolean,
|
|
94
247
|
additionalTypes?: string[],
|
|
95
|
-
|
|
248
|
+
zodLookup?: Map<string, ZodSchemaRef>,
|
|
249
|
+
packageName?: string | null
|
|
96
250
|
) {
|
|
97
251
|
await writeFileInDir(
|
|
98
252
|
logger,
|
|
@@ -108,26 +262,25 @@ export async function saveSchemas(
|
|
|
108
262
|
try {
|
|
109
263
|
types.push(typesMap.getUniqueName(inputs[0]))
|
|
110
264
|
} catch {
|
|
111
|
-
// Skip types not in typesMap
|
|
265
|
+
// Skip types not in typesMap - might be a zod schema name
|
|
266
|
+
types.push(inputs[0])
|
|
112
267
|
}
|
|
113
268
|
}
|
|
114
269
|
if (outputs?.[0]) {
|
|
115
270
|
try {
|
|
116
271
|
types.push(typesMap.getUniqueName(outputs[0]))
|
|
117
272
|
} catch {
|
|
118
|
-
// Skip types not in typesMap
|
|
273
|
+
// Skip types not in typesMap - might be a zod schema name
|
|
274
|
+
types.push(outputs[0])
|
|
119
275
|
}
|
|
120
276
|
}
|
|
121
277
|
return types
|
|
122
278
|
})
|
|
123
279
|
.flat()
|
|
124
|
-
.filter(
|
|
125
|
-
(s): s is string =>
|
|
126
|
-
!!s &&
|
|
127
|
-
!['boolean', 'string', 'number', 'null', 'undefined'].includes(s)
|
|
128
|
-
),
|
|
280
|
+
.filter((s): s is string => !!s && !PRIMITIVE_TYPES.has(s)),
|
|
129
281
|
...typesMap.customTypes.keys(),
|
|
130
282
|
...(additionalTypes || []),
|
|
283
|
+
...(zodLookup ? Array.from(zodLookup.keys()) : []),
|
|
131
284
|
])
|
|
132
285
|
|
|
133
286
|
if (desiredSchemas.size === 0) {
|
|
@@ -153,19 +306,29 @@ export async function saveSchemas(
|
|
|
153
306
|
(schema) => schemas[schema]
|
|
154
307
|
)
|
|
155
308
|
|
|
309
|
+
// Generate the packageName argument for addSchema calls
|
|
310
|
+
const packageNameArg = packageName ? `, '${packageName}'` : ''
|
|
311
|
+
|
|
156
312
|
const schemaImports = availableSchemas
|
|
157
|
-
.map(
|
|
158
|
-
(schema)
|
|
159
|
-
|
|
160
|
-
|
|
313
|
+
.map((schema) => {
|
|
314
|
+
const identifier = toValidIdentifier(schema)
|
|
315
|
+
return `
|
|
316
|
+
import * as ${identifier} from './schemas/${schema}.schema.json' ${supportsImportAttributes ? `with { type: 'json' }` : ''}
|
|
317
|
+
addSchema('${schema}', ${identifier}${packageNameArg})
|
|
161
318
|
`
|
|
162
|
-
)
|
|
319
|
+
})
|
|
163
320
|
.join('\n')
|
|
164
321
|
|
|
322
|
+
// Only import addSchema if there are schemas to register
|
|
323
|
+
const importStatement =
|
|
324
|
+
availableSchemas.length > 0
|
|
325
|
+
? `import { addSchema } from '@pikku/core/schema'`
|
|
326
|
+
: '// No schemas to register'
|
|
327
|
+
|
|
165
328
|
await writeFileInDir(
|
|
166
329
|
logger,
|
|
167
330
|
`${schemaParentDir}/register.gen.ts`,
|
|
168
|
-
|
|
331
|
+
`${importStatement}
|
|
169
332
|
${schemaImports}`,
|
|
170
333
|
{ logWrite: true }
|
|
171
334
|
)
|