ts-procedures 8.6.0 → 9.1.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 +540 -0
- package/README.md +166 -101
- package/agent_config/claude-code/.claude-plugin/plugin.json +1 -1
- package/agent_config/claude-code/agents/ts-procedures-architect.md +11 -10
- package/agent_config/claude-code/skills/ts-procedures/SKILL.md +25 -12
- package/agent_config/claude-code/skills/ts-procedures/anti-patterns.md +10 -12
- package/agent_config/claude-code/skills/ts-procedures/api-reference.md +141 -45
- package/agent_config/claude-code/skills/ts-procedures/checklist.md +7 -6
- package/agent_config/claude-code/skills/ts-procedures/patterns.md +45 -6
- package/agent_config/claude-code/skills/ts-procedures/templates/client.md +1 -1
- package/agent_config/claude-code/skills/ts-procedures/templates/hono.md +1 -1
- package/agent_config/copilot/copilot-instructions.md +50 -33
- package/agent_config/cursor/cursorrules +50 -33
- package/build/adapters/astro/astro-context.js.map +1 -0
- package/build/adapters/astro/create-handler.js.map +1 -0
- package/build/adapters/astro/index.js.map +1 -0
- package/build/{implementations/http → adapters}/astro/index.test.js +1 -1
- package/build/adapters/astro/index.test.js.map +1 -0
- package/build/adapters/astro/rewrite-request.js.map +1 -0
- package/build/adapters/hono/envelope-parity.test.js +98 -0
- package/build/adapters/hono/envelope-parity.test.js.map +1 -0
- package/build/{implementations/http → adapters}/hono/handlers/http-stream.d.ts +1 -1
- package/build/adapters/hono/handlers/http-stream.js +55 -0
- package/build/adapters/hono/handlers/http-stream.js.map +1 -0
- package/build/{implementations/http → adapters}/hono/handlers/http-stream.test.js +1 -1
- package/build/adapters/hono/handlers/http-stream.test.js.map +1 -0
- package/build/{implementations/http → adapters}/hono/handlers/http.d.ts +1 -1
- package/build/adapters/hono/handlers/http.js +50 -0
- package/build/adapters/hono/handlers/http.js.map +1 -0
- package/build/{implementations/http → adapters}/hono/handlers/http.test.js +1 -1
- package/build/adapters/hono/handlers/http.test.js.map +1 -0
- package/build/{implementations/http → adapters}/hono/handlers/rpc.d.ts +2 -2
- package/build/adapters/hono/handlers/rpc.js +23 -0
- package/build/adapters/hono/handlers/rpc.js.map +1 -0
- package/build/{implementations/http → adapters}/hono/handlers/rpc.test.js +1 -1
- package/build/adapters/hono/handlers/rpc.test.js.map +1 -0
- package/build/adapters/hono/handlers/stream.d.ts +12 -0
- package/build/adapters/hono/handlers/stream.js +89 -0
- package/build/adapters/hono/handlers/stream.js.map +1 -0
- package/build/{implementations/http → adapters}/hono/handlers/stream.test.js +3 -2
- package/build/adapters/hono/handlers/stream.test.js.map +1 -0
- package/build/{implementations/http → adapters}/hono/index.d.ts +24 -12
- package/build/{implementations/http → adapters}/hono/index.js +19 -8
- package/build/adapters/hono/index.js.map +1 -0
- package/build/{implementations/http → adapters}/hono/index.test.js +2 -4
- package/build/adapters/hono/index.test.js.map +1 -0
- package/build/{implementations/http → adapters/hono}/on-request-error.test.js +2 -2
- package/build/adapters/hono/on-request-error.test.js.map +1 -0
- package/build/adapters/hono/request.d.ts +7 -0
- package/build/adapters/hono/request.js +22 -0
- package/build/adapters/hono/request.js.map +1 -0
- package/build/{implementations/http → adapters/hono}/route-errors.test.js +4 -4
- package/build/adapters/hono/route-errors.test.js.map +1 -0
- package/build/adapters/hono/types.d.ts +55 -0
- package/build/adapters/hono/types.js +19 -0
- package/build/adapters/hono/types.js.map +1 -0
- package/build/client/freeze.test.js +39 -0
- package/build/client/freeze.test.js.map +1 -0
- package/build/client/typed-error-dispatch.test.js +2 -2
- package/build/client/typed-error-dispatch.test.js.map +1 -1
- package/build/codegen/__fixtures__/make-envelope.d.ts +1 -1
- package/build/codegen/bin/cli.d.ts +5 -0
- package/build/codegen/bin/cli.js +139 -182
- package/build/codegen/bin/cli.js.map +1 -1
- package/build/codegen/bin/cli.test.js +12 -2
- package/build/codegen/bin/cli.test.js.map +1 -1
- package/build/codegen/bin/flag-specs.d.ts +9 -0
- package/build/codegen/bin/flag-specs.js +33 -31
- package/build/codegen/bin/flag-specs.js.map +1 -1
- package/build/codegen/bin/flag-specs.test.js +14 -1
- package/build/codegen/bin/flag-specs.test.js.map +1 -1
- package/build/codegen/collect-models.d.ts +1 -1
- package/build/codegen/emit/api-route.d.ts +8 -0
- package/build/codegen/emit/api-route.js +156 -0
- package/build/codegen/emit/api-route.js.map +1 -0
- package/build/codegen/emit/context.d.ts +30 -0
- package/build/codegen/emit/context.js +2 -0
- package/build/codegen/emit/context.js.map +1 -0
- package/build/codegen/emit/declarations.d.ts +24 -0
- package/build/codegen/emit/declarations.js +48 -0
- package/build/codegen/emit/declarations.js.map +1 -0
- package/build/codegen/emit/format-types.d.ts +61 -0
- package/build/codegen/emit/format-types.js +188 -0
- package/build/codegen/emit/format-types.js.map +1 -0
- package/build/codegen/emit/http-stream-route.d.ts +7 -0
- package/build/codegen/emit/http-stream-route.js +138 -0
- package/build/codegen/emit/http-stream-route.js.map +1 -0
- package/build/codegen/emit/route-shared.d.ts +37 -0
- package/build/codegen/emit/route-shared.js +88 -0
- package/build/codegen/emit/route-shared.js.map +1 -0
- package/build/codegen/emit/rpc-route.d.ts +7 -0
- package/build/codegen/emit/rpc-route.js +37 -0
- package/build/codegen/emit/rpc-route.js.map +1 -0
- package/build/codegen/emit/scope-file.d.ts +39 -0
- package/build/codegen/emit/scope-file.js +166 -0
- package/build/codegen/emit/scope-file.js.map +1 -0
- package/build/codegen/emit/stream-route.d.ts +7 -0
- package/build/codegen/emit/stream-route.js +62 -0
- package/build/codegen/emit/stream-route.js.map +1 -0
- package/build/codegen/emit-errors.d.ts +1 -1
- package/build/codegen/emit-errors.integration.test.js +1 -1
- package/build/codegen/emit-errors.integration.test.js.map +1 -1
- package/build/codegen/emit-scope.d.ts +13 -30
- package/build/codegen/emit-scope.js +15 -844
- package/build/codegen/emit-scope.js.map +1 -1
- package/build/codegen/emit-scope.test.js +67 -0
- package/build/codegen/emit-scope.test.js.map +1 -1
- package/build/codegen/goldens.test.js +69 -0
- package/build/codegen/goldens.test.js.map +1 -0
- package/build/codegen/group-routes.d.ts +1 -1
- package/build/codegen/pipeline.d.ts +1 -1
- package/build/codegen/resolve-envelope.d.ts +1 -1
- package/build/codegen/targets/_shared/error-schemas.d.ts +1 -1
- package/build/codegen/targets/_shared/route-slots.d.ts +1 -1
- package/build/codegen/targets/_shared/target-run.d.ts +1 -1
- package/build/codegen/targets/kotlin/emit-route-kotlin.d.ts +1 -1
- package/build/codegen/targets/swift/emit-route-swift.d.ts +1 -1
- package/build/core/create-http-stream.d.ts +50 -0
- package/build/core/create-http-stream.js +108 -0
- package/build/core/create-http-stream.js.map +1 -0
- package/build/{create-http-stream.test.js → core/create-http-stream.test.js} +1 -1
- package/build/core/create-http-stream.test.js.map +1 -0
- package/build/core/create-http.d.ts +51 -0
- package/build/core/create-http.js +65 -0
- package/build/core/create-http.js.map +1 -0
- package/build/{create-http.test.js → core/create-http.test.js} +27 -4
- package/build/core/create-http.test.js.map +1 -0
- package/build/core/create-stream.d.ts +26 -0
- package/build/core/create-stream.js +80 -0
- package/build/core/create-stream.js.map +1 -0
- package/build/{create-stream.test.js → core/create-stream.test.js} +23 -28
- package/build/core/create-stream.test.js.map +1 -0
- package/build/core/create.d.ts +22 -0
- package/build/core/create.js +71 -0
- package/build/core/create.js.map +1 -0
- package/build/{create.test.js → core/create.test.js} +25 -46
- package/build/core/create.test.js.map +1 -0
- package/build/core/definition-site.d.ts +24 -0
- package/build/{stack-utils.js → core/definition-site.js} +20 -20
- package/build/core/definition-site.js.map +1 -0
- package/build/{stack-utils.test.js → core/definition-site.test.js} +12 -3
- package/build/core/definition-site.test.js.map +1 -0
- package/build/{errors.d.ts → core/errors.d.ts} +19 -8
- package/build/{errors.js → core/errors.js} +21 -26
- package/build/core/errors.js.map +1 -0
- package/build/core/errors.test.js.map +1 -0
- package/build/core/factory-options.test.js +82 -0
- package/build/core/factory-options.test.js.map +1 -0
- package/build/core/http-route.d.ts +13 -0
- package/build/core/http-route.js +54 -0
- package/build/core/http-route.js.map +1 -0
- package/build/core/internal.d.ts +72 -0
- package/build/core/internal.js +128 -0
- package/build/core/internal.js.map +1 -0
- package/build/{migration.test.js → core/migration.test.js} +17 -1
- package/build/core/migration.test.js.map +1 -0
- package/build/core/procedures.d.ts +143 -0
- package/build/core/procedures.js +64 -0
- package/build/core/procedures.js.map +1 -0
- package/build/{index.test.js → core/procedures.test.js} +14 -11
- package/build/core/procedures.test.js.map +1 -0
- package/build/core/types.d.ts +183 -0
- package/build/{schema → core}/types.js.map +1 -1
- package/build/exports.d.ts +31 -11
- package/build/exports.js +23 -8
- package/build/exports.js.map +1 -1
- package/build/schema/adapter.d.ts +35 -0
- package/build/schema/adapter.js +13 -0
- package/build/schema/adapter.js.map +1 -0
- package/build/schema/adapter.test.js +53 -0
- package/build/schema/adapter.test.js.map +1 -0
- package/build/schema/compile.d.ts +37 -0
- package/build/schema/compile.js +38 -0
- package/build/schema/compile.js.map +1 -0
- package/build/schema/compile.test.js +78 -0
- package/build/schema/compile.test.js.map +1 -0
- package/build/schema/compute-schema.d.ts +47 -37
- package/build/schema/compute-schema.js +86 -29
- package/build/schema/compute-schema.js.map +1 -1
- package/build/schema/compute-schema.test.js +158 -40
- package/build/schema/compute-schema.test.js.map +1 -1
- package/build/schema/json-schema.d.ts +17 -0
- package/build/schema/json-schema.js +2 -0
- package/build/schema/json-schema.js.map +1 -0
- package/build/schema/typebox.d.ts +11 -0
- package/build/schema/typebox.js +24 -0
- package/build/schema/typebox.js.map +1 -0
- package/build/schema/typebox.test.js +34 -0
- package/build/schema/typebox.test.js.map +1 -0
- package/build/server/context.d.ts +8 -0
- package/build/server/context.js +7 -0
- package/build/server/context.js.map +1 -0
- package/build/server/context.test.js +16 -0
- package/build/server/context.test.js.map +1 -0
- package/build/{doc-envelope.d.ts → server/doc-envelope.d.ts} +1 -1
- package/build/server/doc-envelope.js.map +1 -0
- package/build/server/doc-envelope.test.d.ts +1 -0
- package/build/server/doc-envelope.test.js.map +1 -0
- package/build/{implementations/http → server}/doc-registry.d.ts +7 -2
- package/build/{implementations/http → server}/doc-registry.js +9 -5
- package/build/server/doc-registry.js.map +1 -0
- package/build/server/doc-registry.test.d.ts +1 -0
- package/build/{implementations/http → server}/doc-registry.test.js +27 -24
- package/build/server/doc-registry.test.js.map +1 -0
- package/build/server/docs/docs.test.d.ts +1 -0
- package/build/server/docs/docs.test.js +237 -0
- package/build/server/docs/docs.test.js.map +1 -0
- package/build/{implementations/http/hono → server}/docs/http-doc.d.ts +2 -2
- package/build/{implementations/http/hono → server}/docs/http-doc.js +1 -1
- package/build/server/docs/http-doc.js.map +1 -0
- package/build/{implementations/http/hono → server}/docs/http-stream-doc.d.ts +2 -2
- package/build/{implementations/http/hono → server}/docs/http-stream-doc.js +1 -1
- package/build/server/docs/http-stream-doc.js.map +1 -0
- package/build/{implementations/http/hono → server}/docs/rpc-doc.d.ts +2 -2
- package/build/{implementations/http/hono → server}/docs/rpc-doc.js +1 -1
- package/build/server/docs/rpc-doc.js.map +1 -0
- package/build/{implementations/http/hono → server}/docs/stream-doc.d.ts +2 -2
- package/build/{implementations/http/hono → server}/docs/stream-doc.js +1 -1
- package/build/server/docs/stream-doc.js.map +1 -0
- package/build/server/errors/dispatch.d.ts +96 -0
- package/build/{implementations/http/error-dispatch.js → server/errors/dispatch.js} +20 -10
- package/build/server/errors/dispatch.js.map +1 -0
- package/build/server/errors/dispatch.test.d.ts +1 -0
- package/build/server/errors/dispatch.test.js +418 -0
- package/build/server/errors/dispatch.test.js.map +1 -0
- package/build/{implementations/http/error-taxonomy.d.ts → server/errors/taxonomy.d.ts} +8 -17
- package/build/{implementations/http/error-taxonomy.js → server/errors/taxonomy.js} +6 -15
- package/build/server/errors/taxonomy.js.map +1 -0
- package/build/server/errors/taxonomy.test.d.ts +1 -0
- package/build/{implementations/http/error-taxonomy.test.js → server/errors/taxonomy.test.js} +45 -39
- package/build/server/errors/taxonomy.test.js.map +1 -0
- package/build/server/index.d.ts +29 -0
- package/build/server/index.js +27 -0
- package/build/server/index.js.map +1 -0
- package/build/server/no-framework-imports.test.d.ts +1 -0
- package/build/server/no-framework-imports.test.js +40 -0
- package/build/server/no-framework-imports.test.js.map +1 -0
- package/build/{implementations/http/hono/path.d.ts → server/paths.d.ts} +2 -3
- package/build/{implementations/http/hono/path.js → server/paths.js} +1 -1
- package/build/server/paths.js.map +1 -0
- package/build/server/paths.test.d.ts +1 -0
- package/build/server/paths.test.js +111 -0
- package/build/server/paths.test.js.map +1 -0
- package/build/server/request/params.d.ts +29 -0
- package/build/server/request/params.js +43 -0
- package/build/server/request/params.js.map +1 -0
- package/build/server/request/params.test.d.ts +1 -0
- package/build/server/request/params.test.js +91 -0
- package/build/server/request/params.test.js.map +1 -0
- package/build/server/request/query.d.ts +9 -0
- package/build/server/request/query.js +22 -0
- package/build/server/request/query.js.map +1 -0
- package/build/server/request/query.test.d.ts +1 -0
- package/build/server/request/query.test.js +60 -0
- package/build/server/request/query.test.js.map +1 -0
- package/build/server/sse.d.ts +70 -0
- package/build/server/sse.js +94 -0
- package/build/server/sse.js.map +1 -0
- package/build/server/sse.test.d.ts +1 -0
- package/build/server/sse.test.js +98 -0
- package/build/server/sse.test.js.map +1 -0
- package/build/{implementations → server}/types.d.ts +17 -15
- package/build/{implementations → server}/types.js.map +1 -1
- package/docs/astro-adapter.md +8 -9
- package/docs/client-and-codegen.md +10 -4
- package/docs/client-error-handling.md +5 -5
- package/docs/codegen-kotlin.md +2 -3
- package/docs/codegen-swift.md +1 -2
- package/docs/core.md +135 -54
- package/docs/http-integrations.md +58 -6
- package/docs/migration-v8-to-v9.md +200 -0
- package/docs/plans/2026-06-09-v9-rewrite.md +130 -0
- package/docs/specs/2026-06-09-v9-rewrite-design.md +221 -0
- package/docs/streaming.md +12 -0
- package/package.json +25 -48
- package/src/{implementations/http → adapters}/astro/index.test.ts +2 -2
- package/src/adapters/hono/__fixtures__/parity-envelope.json +389 -0
- package/src/adapters/hono/envelope-parity.test.ts +126 -0
- package/src/{implementations/http → adapters}/hono/handlers/http-stream.test.ts +1 -1
- package/src/adapters/hono/handlers/http-stream.ts +73 -0
- package/src/{implementations/http → adapters}/hono/handlers/http.test.ts +1 -1
- package/src/adapters/hono/handlers/http.ts +70 -0
- package/src/{implementations/http → adapters}/hono/handlers/rpc.test.ts +2 -2
- package/src/adapters/hono/handlers/rpc.ts +39 -0
- package/src/{implementations/http → adapters}/hono/handlers/stream.test.ts +4 -3
- package/src/{implementations/http → adapters}/hono/handlers/stream.ts +19 -92
- package/src/{implementations/http → adapters}/hono/index.test.ts +14 -16
- package/src/{implementations/http → adapters}/hono/index.ts +35 -30
- package/src/{implementations/http → adapters/hono}/on-request-error.test.ts +3 -3
- package/src/adapters/hono/request.ts +28 -0
- package/src/{implementations/http → adapters/hono}/route-errors.test.ts +5 -5
- package/src/{implementations/http → adapters}/hono/types.ts +43 -20
- package/src/client/freeze.test.ts +41 -0
- package/src/client/typed-error-dispatch.test.ts +3 -3
- package/src/codegen/__fixtures__/make-envelope.ts +1 -1
- package/src/codegen/__fixtures__/models-envelope.json +310 -0
- package/src/codegen/__goldens__/MANIFEST.json +85 -0
- package/src/codegen/__goldens__/kotlin-default--models/Billing.kt +112 -0
- package/src/codegen/__goldens__/kotlin-default--models/BillingReports.kt +26 -0
- package/src/codegen/__goldens__/kotlin-default--models/Orders.kt +88 -0
- package/src/codegen/__goldens__/kotlin-default--users/Users.kt +189 -0
- package/src/codegen/__goldens__/swift-default--models/Billing.swift +97 -0
- package/src/codegen/__goldens__/swift-default--models/BillingReports.swift +20 -0
- package/src/codegen/__goldens__/swift-default--models/Orders.swift +81 -0
- package/src/codegen/__goldens__/swift-default--users/Users.swift +204 -0
- package/src/codegen/__goldens__/ts-default--models/_client.ts +1319 -0
- package/src/codegen/__goldens__/ts-default--models/_errors.ts +90 -0
- package/src/codegen/__goldens__/ts-default--models/_models.ts +10 -0
- package/src/codegen/__goldens__/ts-default--models/_types.ts +502 -0
- package/src/codegen/__goldens__/ts-default--models/billing-reports.ts +29 -0
- package/src/codegen/__goldens__/ts-default--models/billing.ts +67 -0
- package/src/codegen/__goldens__/ts-default--models/index.ts +48 -0
- package/src/codegen/__goldens__/ts-default--models/orders.ts +80 -0
- package/src/codegen/__goldens__/ts-default--users/_client.ts +1319 -0
- package/src/codegen/__goldens__/ts-default--users/_errors.ts +90 -0
- package/src/codegen/__goldens__/ts-default--users/_types.ts +502 -0
- package/src/codegen/__goldens__/ts-default--users/index.ts +38 -0
- package/src/codegen/__goldens__/ts-default--users/users.ts +169 -0
- package/src/codegen/__goldens__/ts-external-runtime--models/_errors.ts +90 -0
- package/src/codegen/__goldens__/ts-external-runtime--models/_models.ts +10 -0
- package/src/codegen/__goldens__/ts-external-runtime--models/billing-reports.ts +29 -0
- package/src/codegen/__goldens__/ts-external-runtime--models/billing.ts +67 -0
- package/src/codegen/__goldens__/ts-external-runtime--models/index.ts +48 -0
- package/src/codegen/__goldens__/ts-external-runtime--models/orders.ts +80 -0
- package/src/codegen/__goldens__/ts-external-runtime--users/_errors.ts +90 -0
- package/src/codegen/__goldens__/ts-external-runtime--users/index.ts +38 -0
- package/src/codegen/__goldens__/ts-external-runtime--users/users.ts +169 -0
- package/src/codegen/__goldens__/ts-flat--models/_client.ts +1319 -0
- package/src/codegen/__goldens__/ts-flat--models/_errors.ts +87 -0
- package/src/codegen/__goldens__/ts-flat--models/_models.ts +10 -0
- package/src/codegen/__goldens__/ts-flat--models/_types.ts +502 -0
- package/src/codegen/__goldens__/ts-flat--models/billing-reports.ts +28 -0
- package/src/codegen/__goldens__/ts-flat--models/billing.ts +51 -0
- package/src/codegen/__goldens__/ts-flat--models/index.ts +42 -0
- package/src/codegen/__goldens__/ts-flat--models/orders.ts +73 -0
- package/src/codegen/__goldens__/ts-flat--users/_client.ts +1319 -0
- package/src/codegen/__goldens__/ts-flat--users/_errors.ts +87 -0
- package/src/codegen/__goldens__/ts-flat--users/_types.ts +502 -0
- package/src/codegen/__goldens__/ts-flat--users/index.ts +34 -0
- package/src/codegen/__goldens__/ts-flat--users/users.ts +126 -0
- package/src/codegen/__goldens__/ts-no-share-models--models/_client.ts +1319 -0
- package/src/codegen/__goldens__/ts-no-share-models--models/_errors.ts +90 -0
- package/src/codegen/__goldens__/ts-no-share-models--models/_types.ts +502 -0
- package/src/codegen/__goldens__/ts-no-share-models--models/billing-reports.ts +29 -0
- package/src/codegen/__goldens__/ts-no-share-models--models/billing.ts +111 -0
- package/src/codegen/__goldens__/ts-no-share-models--models/index.ts +48 -0
- package/src/codegen/__goldens__/ts-no-share-models--models/orders.ts +112 -0
- package/src/codegen/__goldens__/ts-no-share-models--users/_client.ts +1319 -0
- package/src/codegen/__goldens__/ts-no-share-models--users/_errors.ts +90 -0
- package/src/codegen/__goldens__/ts-no-share-models--users/_types.ts +502 -0
- package/src/codegen/__goldens__/ts-no-share-models--users/index.ts +38 -0
- package/src/codegen/__goldens__/ts-no-share-models--users/users.ts +169 -0
- package/src/codegen/__goldens__/ts-shared-models-module--models/_client.ts +1319 -0
- package/src/codegen/__goldens__/ts-shared-models-module--models/_errors.ts +90 -0
- package/src/codegen/__goldens__/ts-shared-models-module--models/_models.ts +7 -0
- package/src/codegen/__goldens__/ts-shared-models-module--models/_types.ts +502 -0
- package/src/codegen/__goldens__/ts-shared-models-module--models/billing-reports.ts +29 -0
- package/src/codegen/__goldens__/ts-shared-models-module--models/billing.ts +67 -0
- package/src/codegen/__goldens__/ts-shared-models-module--models/index.ts +48 -0
- package/src/codegen/__goldens__/ts-shared-models-module--models/orders.ts +80 -0
- package/src/codegen/bin/cli.test.ts +13 -2
- package/src/codegen/bin/cli.ts +181 -144
- package/src/codegen/bin/flag-specs.test.ts +16 -1
- package/src/codegen/bin/flag-specs.ts +43 -31
- package/src/codegen/bundle-size.test.ts +1 -1
- package/src/codegen/collect-models.ts +1 -1
- package/src/codegen/e2e.test.ts +1 -1
- package/src/codegen/emit/api-route.ts +184 -0
- package/src/codegen/emit/context.ts +32 -0
- package/src/codegen/emit/declarations.ts +49 -0
- package/src/codegen/emit/format-types.ts +232 -0
- package/src/codegen/emit/http-stream-route.ts +162 -0
- package/src/codegen/emit/route-shared.ts +104 -0
- package/src/codegen/emit/rpc-route.ts +49 -0
- package/src/codegen/emit/scope-file.ts +226 -0
- package/src/codegen/emit/stream-route.ts +81 -0
- package/src/codegen/emit-errors.integration.test.ts +2 -2
- package/src/codegen/emit-errors.test.ts +1 -1
- package/src/codegen/emit-errors.ts +1 -1
- package/src/codegen/emit-scope.test.ts +75 -2
- package/src/codegen/emit-scope.ts +15 -1048
- package/src/codegen/goldens.test.ts +89 -0
- package/src/codegen/group-routes.test.ts +1 -1
- package/src/codegen/group-routes.ts +1 -1
- package/src/codegen/pipeline.test.ts +1 -1
- package/src/codegen/pipeline.ts +1 -1
- package/src/codegen/resolve-envelope.test.ts +1 -1
- package/src/codegen/resolve-envelope.ts +1 -1
- package/src/codegen/targets/_shared/error-schemas.test.ts +1 -1
- package/src/codegen/targets/_shared/error-schemas.ts +1 -1
- package/src/codegen/targets/_shared/route-slots.test.ts +1 -1
- package/src/codegen/targets/_shared/route-slots.ts +1 -1
- package/src/codegen/targets/_shared/target-run.ts +1 -1
- package/src/codegen/targets/kotlin/emit-route-kotlin.test.ts +1 -1
- package/src/codegen/targets/kotlin/emit-route-kotlin.ts +1 -1
- package/src/codegen/targets/kotlin/emit-scope-kotlin.test.ts +1 -1
- package/src/codegen/targets/swift/access-level.test.ts +1 -1
- package/src/codegen/targets/swift/emit-route-swift.test.ts +1 -1
- package/src/codegen/targets/swift/emit-route-swift.ts +1 -1
- package/src/codegen/targets/swift/emit-scope-swift.test.ts +1 -1
- package/src/codegen/targets/ts/shared-models.test.ts +1 -1
- package/src/{create-http-stream.test.ts → core/create-http-stream.test.ts} +1 -1
- package/src/core/create-http-stream.ts +207 -0
- package/src/{create-http.test.ts → core/create-http.test.ts} +31 -4
- package/src/core/create-http.ts +126 -0
- package/src/{create-stream.test.ts → core/create-stream.test.ts} +28 -31
- package/src/core/create-stream.ts +142 -0
- package/src/{create.test.ts → core/create.test.ts} +25 -57
- package/src/core/create.ts +121 -0
- package/src/{stack-utils.test.ts → core/definition-site.test.ts} +14 -3
- package/src/{stack-utils.ts → core/definition-site.ts} +20 -23
- package/src/{errors.test.ts → core/errors.test.ts} +1 -1
- package/src/{errors.ts → core/errors.ts} +30 -28
- package/src/core/factory-options.test.ts +112 -0
- package/src/core/http-route.ts +73 -0
- package/src/core/internal.ts +203 -0
- package/src/{migration.test.ts → core/migration.test.ts} +23 -1
- package/src/{index.test.ts → core/procedures.test.ts} +13 -11
- package/src/core/procedures.ts +75 -0
- package/src/core/types.ts +196 -0
- package/src/exports.ts +60 -11
- package/src/schema/adapter.test.ts +58 -0
- package/src/schema/adapter.ts +45 -0
- package/src/schema/compile.test.ts +95 -0
- package/src/schema/compile.ts +64 -0
- package/src/schema/compute-schema.test.ts +222 -41
- package/src/schema/compute-schema.ts +145 -71
- package/src/schema/json-schema.ts +21 -0
- package/src/schema/typebox.test.ts +40 -0
- package/src/schema/typebox.ts +27 -0
- package/src/server/context.test.ts +22 -0
- package/src/server/context.ts +18 -0
- package/src/{doc-envelope.test.ts → server/doc-envelope.test.ts} +2 -2
- package/src/{doc-envelope.ts → server/doc-envelope.ts} +1 -1
- package/src/{implementations/http → server}/doc-registry.test.ts +32 -26
- package/src/{implementations/http → server}/doc-registry.ts +11 -7
- package/src/server/docs/docs.test.ts +287 -0
- package/src/{implementations/http/hono → server}/docs/http-doc.ts +3 -3
- package/src/{implementations/http/hono → server}/docs/http-stream-doc.ts +3 -3
- package/src/{implementations/http/hono → server}/docs/rpc-doc.ts +3 -3
- package/src/{implementations/http/hono → server}/docs/stream-doc.ts +3 -3
- package/src/server/errors/dispatch.test.ts +450 -0
- package/src/server/errors/dispatch.ts +189 -0
- package/src/{implementations/http/error-taxonomy.test.ts → server/errors/taxonomy.test.ts} +45 -39
- package/src/{implementations/http/error-taxonomy.ts → server/errors/taxonomy.ts} +8 -17
- package/src/server/index.ts +29 -0
- package/src/server/no-framework-imports.test.ts +43 -0
- package/src/server/paths.test.ts +141 -0
- package/src/{implementations/http/hono/path.ts → server/paths.ts} +2 -13
- package/src/server/request/params.test.ts +143 -0
- package/src/server/request/params.ts +68 -0
- package/src/server/request/query.test.ts +70 -0
- package/src/server/request/query.ts +24 -0
- package/src/server/sse.test.ts +113 -0
- package/src/server/sse.ts +117 -0
- package/src/{implementations → server}/types.ts +17 -16
- package/build/create-http-stream.d.ts +0 -58
- package/build/create-http-stream.js +0 -122
- package/build/create-http-stream.js.map +0 -1
- package/build/create-http-stream.test.js.map +0 -1
- package/build/create-http.d.ts +0 -49
- package/build/create-http.js +0 -108
- package/build/create-http.js.map +0 -1
- package/build/create-http.test.js.map +0 -1
- package/build/create-stream.d.ts +0 -35
- package/build/create-stream.js +0 -123
- package/build/create-stream.js.map +0 -1
- package/build/create-stream.test.js.map +0 -1
- package/build/create.d.ts +0 -28
- package/build/create.js +0 -82
- package/build/create.js.map +0 -1
- package/build/create.test.js.map +0 -1
- package/build/doc-envelope.js.map +0 -1
- package/build/doc-envelope.test.js.map +0 -1
- package/build/errors.js.map +0 -1
- package/build/errors.test.js.map +0 -1
- package/build/implementations/http/astro/astro-context.js.map +0 -1
- package/build/implementations/http/astro/create-handler.js.map +0 -1
- package/build/implementations/http/astro/index.js.map +0 -1
- package/build/implementations/http/astro/index.test.js.map +0 -1
- package/build/implementations/http/astro/rewrite-request.js.map +0 -1
- package/build/implementations/http/doc-registry.js.map +0 -1
- package/build/implementations/http/doc-registry.test.js.map +0 -1
- package/build/implementations/http/error-dispatch.d.ts +0 -76
- package/build/implementations/http/error-dispatch.js.map +0 -1
- package/build/implementations/http/error-dispatch.test.js +0 -254
- package/build/implementations/http/error-dispatch.test.js.map +0 -1
- package/build/implementations/http/error-taxonomy.js.map +0 -1
- package/build/implementations/http/error-taxonomy.test.js.map +0 -1
- package/build/implementations/http/hono/docs/http-doc.js.map +0 -1
- package/build/implementations/http/hono/docs/http-stream-doc.js.map +0 -1
- package/build/implementations/http/hono/docs/rpc-doc.js.map +0 -1
- package/build/implementations/http/hono/docs/stream-doc.js.map +0 -1
- package/build/implementations/http/hono/handlers/http-stream.js +0 -123
- package/build/implementations/http/hono/handlers/http-stream.js.map +0 -1
- package/build/implementations/http/hono/handlers/http-stream.test.js.map +0 -1
- package/build/implementations/http/hono/handlers/http.js +0 -110
- package/build/implementations/http/hono/handlers/http.js.map +0 -1
- package/build/implementations/http/hono/handlers/http.test.js.map +0 -1
- package/build/implementations/http/hono/handlers/rpc.js +0 -32
- package/build/implementations/http/hono/handlers/rpc.js.map +0 -1
- package/build/implementations/http/hono/handlers/rpc.test.js.map +0 -1
- package/build/implementations/http/hono/handlers/stream.d.ts +0 -23
- package/build/implementations/http/hono/handlers/stream.js +0 -147
- package/build/implementations/http/hono/handlers/stream.js.map +0 -1
- package/build/implementations/http/hono/handlers/stream.test.js.map +0 -1
- package/build/implementations/http/hono/index.js.map +0 -1
- package/build/implementations/http/hono/index.test.js.map +0 -1
- package/build/implementations/http/hono/path.js.map +0 -1
- package/build/implementations/http/hono/path.test.js +0 -83
- package/build/implementations/http/hono/path.test.js.map +0 -1
- package/build/implementations/http/hono/types.d.ts +0 -51
- package/build/implementations/http/hono/types.js.map +0 -1
- package/build/implementations/http/on-request-error.test.js.map +0 -1
- package/build/implementations/http/route-errors.test.js.map +0 -1
- package/build/index.d.ts +0 -175
- package/build/index.js +0 -47
- package/build/index.js.map +0 -1
- package/build/index.test.js.map +0 -1
- package/build/migration.test.js.map +0 -1
- package/build/schema/extract-json-schema.d.ts +0 -2
- package/build/schema/extract-json-schema.js +0 -12
- package/build/schema/extract-json-schema.js.map +0 -1
- package/build/schema/extract-json-schema.test.js +0 -23
- package/build/schema/extract-json-schema.test.js.map +0 -1
- package/build/schema/parser.d.ts +0 -36
- package/build/schema/parser.js +0 -210
- package/build/schema/parser.js.map +0 -1
- package/build/schema/parser.test.js +0 -120
- package/build/schema/parser.test.js.map +0 -1
- package/build/schema/resolve-schema-lib.d.ts +0 -12
- package/build/schema/resolve-schema-lib.js +0 -11
- package/build/schema/resolve-schema-lib.js.map +0 -1
- package/build/schema/resolve-schema-lib.test.js +0 -17
- package/build/schema/resolve-schema-lib.test.js.map +0 -1
- package/build/schema/types.d.ts +0 -8
- package/build/schema/types.js +0 -2
- package/build/stack-utils.d.ts +0 -25
- package/build/stack-utils.js.map +0 -1
- package/build/stack-utils.test.js.map +0 -1
- package/build/types.d.ts +0 -142
- package/build/types.js +0 -2
- package/build/types.js.map +0 -1
- package/docs/decisions/2026-06-02-monorepo-split-evaluation.md +0 -80
- package/docs/handoffs/2026-06-08-dx-round2-declines.md +0 -45
- package/docs/handoffs/ajsc-named-type-collision.md +0 -134
- package/docs/handoffs/ajsc-named-type-support.md +0 -181
- package/docs/handoffs/shared-models-auto-resolve-response.md +0 -181
- package/docs/npm-workspaces-migration-plan.md +0 -611
- package/docs/superpowers/plans/2026-04-24-doc-registry-simplification.md +0 -886
- package/docs/superpowers/plans/2026-04-24-kotlin-codegen-target.md +0 -1265
- package/docs/superpowers/plans/2026-04-25-ajsc-v7-kotlin-polish.md +0 -1993
- package/docs/superpowers/plans/2026-04-29-safe-result-api.md +0 -2293
- package/docs/superpowers/plans/2026-05-07-astro-adapter.md +0 -1391
- package/docs/superpowers/plans/2026-05-08-create-http.md +0 -3355
- package/docs/superpowers/plans/2026-05-08-hono-app-builder-convergence.md +0 -3365
- package/docs/superpowers/plans/2026-06-05-dx-feedback-round.md +0 -1292
- package/docs/superpowers/plans/2026-06-06-shared-models-convention-and-diagnostics.md +0 -659
- package/docs/superpowers/plans/2026-06-08-codegen-dx-surfacing.md +0 -428
- package/docs/superpowers/specs/2026-04-24-kotlin-swift-codegen-design.md +0 -401
- package/docs/superpowers/specs/2026-04-25-ajsc-v7-kotlin-polish-design.md +0 -314
- package/docs/superpowers/specs/2026-04-25-swift-codegen-design.md +0 -264
- package/docs/superpowers/specs/2026-04-29-safe-result-api-design.md +0 -324
- package/docs/superpowers/specs/2026-05-07-astro-adapter-design.md +0 -252
- package/docs/superpowers/specs/2026-05-08-create-http-design.md +0 -409
- package/docs/superpowers/specs/2026-05-08-hono-app-builder-convergence-design.md +0 -411
- package/docs/superpowers/specs/2026-06-05-dx-feedback-round-design.md +0 -285
- package/docs/superpowers/specs/2026-06-08-dx-feedback-round-2-design.md +0 -376
- package/src/create-http-stream.ts +0 -191
- package/src/create-http.ts +0 -210
- package/src/create-stream.ts +0 -228
- package/src/create.ts +0 -172
- package/src/implementations/http/README.md +0 -390
- package/src/implementations/http/error-dispatch.test.ts +0 -283
- package/src/implementations/http/error-dispatch.ts +0 -176
- package/src/implementations/http/hono/handlers/http-stream.ts +0 -152
- package/src/implementations/http/hono/handlers/http.ts +0 -145
- package/src/implementations/http/hono/handlers/rpc.ts +0 -54
- package/src/implementations/http/hono/path.test.ts +0 -96
- package/src/index.ts +0 -101
- package/src/schema/extract-json-schema.test.ts +0 -25
- package/src/schema/extract-json-schema.ts +0 -15
- package/src/schema/parser.test.ts +0 -182
- package/src/schema/parser.ts +0 -265
- package/src/schema/resolve-schema-lib.test.ts +0 -19
- package/src/schema/resolve-schema-lib.ts +0 -29
- package/src/schema/types.ts +0 -20
- package/src/types.ts +0 -133
- /package/build/{implementations/http → adapters}/astro/astro-context.d.ts +0 -0
- /package/build/{implementations/http → adapters}/astro/astro-context.js +0 -0
- /package/build/{implementations/http → adapters}/astro/create-handler.d.ts +0 -0
- /package/build/{implementations/http → adapters}/astro/create-handler.js +0 -0
- /package/build/{implementations/http → adapters}/astro/index.d.ts +0 -0
- /package/build/{implementations/http → adapters}/astro/index.js +0 -0
- /package/build/{implementations/http → adapters}/astro/index.test.d.ts +0 -0
- /package/build/{implementations/http → adapters}/astro/rewrite-request.d.ts +0 -0
- /package/build/{implementations/http → adapters}/astro/rewrite-request.js +0 -0
- /package/build/{create-http-stream.test.d.ts → adapters/hono/envelope-parity.test.d.ts} +0 -0
- /package/build/{implementations/http → adapters}/hono/handlers/http-stream.test.d.ts +0 -0
- /package/build/{implementations/http → adapters}/hono/handlers/http.test.d.ts +0 -0
- /package/build/{implementations/http → adapters}/hono/handlers/rpc.test.d.ts +0 -0
- /package/build/{implementations/http → adapters}/hono/handlers/stream.test.d.ts +0 -0
- /package/build/{implementations/http → adapters}/hono/index.test.d.ts +0 -0
- /package/build/{implementations/http → adapters/hono}/on-request-error.test.d.ts +0 -0
- /package/build/{implementations/http → adapters/hono}/route-errors.test.d.ts +0 -0
- /package/build/{create-http.test.d.ts → client/freeze.test.d.ts} +0 -0
- /package/build/{create-stream.test.d.ts → codegen/goldens.test.d.ts} +0 -0
- /package/build/{create.test.d.ts → core/create-http-stream.test.d.ts} +0 -0
- /package/build/{doc-envelope.test.d.ts → core/create-http.test.d.ts} +0 -0
- /package/build/{errors.test.d.ts → core/create-stream.test.d.ts} +0 -0
- /package/build/{implementations/http/doc-registry.test.d.ts → core/create.test.d.ts} +0 -0
- /package/build/{implementations/http/error-dispatch.test.d.ts → core/definition-site.test.d.ts} +0 -0
- /package/build/{implementations/http/error-taxonomy.test.d.ts → core/errors.test.d.ts} +0 -0
- /package/build/{errors.test.js → core/errors.test.js} +0 -0
- /package/build/{implementations/http/hono/path.test.d.ts → core/factory-options.test.d.ts} +0 -0
- /package/build/{migration.test.d.ts → core/migration.test.d.ts} +0 -0
- /package/build/{index.test.d.ts → core/procedures.test.d.ts} +0 -0
- /package/build/{implementations/http/hono → core}/types.js +0 -0
- /package/build/schema/{extract-json-schema.test.d.ts → adapter.test.d.ts} +0 -0
- /package/build/schema/{parser.test.d.ts → compile.test.d.ts} +0 -0
- /package/build/schema/{resolve-schema-lib.test.d.ts → typebox.test.d.ts} +0 -0
- /package/build/{stack-utils.test.d.ts → server/context.test.d.ts} +0 -0
- /package/build/{doc-envelope.js → server/doc-envelope.js} +0 -0
- /package/build/{doc-envelope.test.js → server/doc-envelope.test.js} +0 -0
- /package/build/{implementations → server}/types.js +0 -0
- /package/src/{implementations/http → adapters}/astro/README.md +0 -0
- /package/src/{implementations/http → adapters}/astro/astro-context.ts +0 -0
- /package/src/{implementations/http → adapters}/astro/create-handler.ts +0 -0
- /package/src/{implementations/http → adapters}/astro/index.ts +0 -0
- /package/src/{implementations/http → adapters}/astro/rewrite-request.ts +0 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { mkdtemp, readFile, readdir, rm } from 'node:fs/promises'
|
|
2
|
+
import { tmpdir } from 'node:os'
|
|
3
|
+
import { dirname, join, resolve } from 'node:path'
|
|
4
|
+
import { fileURLToPath } from 'node:url'
|
|
5
|
+
import { afterAll, describe, expect, it } from 'vitest'
|
|
6
|
+
import { generateClient } from './index.js'
|
|
7
|
+
import { resolveProductionKotlinEmitter } from './targets/kotlin/ajsc-adapter.js'
|
|
8
|
+
import { resolveProductionSwiftEmitter } from './targets/swift/ajsc-adapter.js'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* THE acceptance gate for v9 codegen: every generated file must be
|
|
12
|
+
* byte-identical to the v8.6.0 baselines captured by
|
|
13
|
+
* `tools/capture-goldens.mjs` into `__goldens__/`.
|
|
14
|
+
*
|
|
15
|
+
* The case matrix is read from `__goldens__/MANIFEST.json`, which the capture
|
|
16
|
+
* script writes alongside the baselines — one source of truth for both sides.
|
|
17
|
+
* (Kotlin/Swift emitters can't be serialized; they are re-resolved here from
|
|
18
|
+
* each case's `target`.)
|
|
19
|
+
*
|
|
20
|
+
* The only normalization applied on both sides is the package version inside
|
|
21
|
+
* the TS `CODEGEN_HEADER` line (`ts-procedures-codegen (v8.6.0)` vs `(v9.x)`),
|
|
22
|
+
* because the header intentionally records the producing version. Everything
|
|
23
|
+
* else — including the envelope-hash line — must match exactly (both sides
|
|
24
|
+
* hash the same fixture envelopes).
|
|
25
|
+
*/
|
|
26
|
+
const here = dirname(fileURLToPath(import.meta.url))
|
|
27
|
+
const fixturesDir = resolve(here, '__fixtures__')
|
|
28
|
+
const goldensDir = resolve(here, '__goldens__')
|
|
29
|
+
|
|
30
|
+
type Manifest = {
|
|
31
|
+
capturedFrom: string
|
|
32
|
+
cases: Array<{ name: string; envelopes: string[]; options: Record<string, unknown> }>
|
|
33
|
+
cliDefaults: Record<string, unknown>
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const manifest: Manifest = JSON.parse(await readFile(resolve(goldensDir, 'MANIFEST.json'), 'utf-8'))
|
|
37
|
+
|
|
38
|
+
function normalizeVersion(content: string): string {
|
|
39
|
+
return content.replace(
|
|
40
|
+
/ts-procedures-codegen \(v[^)]+\)/,
|
|
41
|
+
'ts-procedures-codegen (<VERSION>)',
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const tempDirs: string[] = []
|
|
46
|
+
afterAll(async () => {
|
|
47
|
+
await Promise.all(tempDirs.map((dir) => rm(dir, { recursive: true, force: true })))
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
describe(`codegen golden parity with ${manifest.capturedFrom}`, () => {
|
|
51
|
+
for (const c of manifest.cases) {
|
|
52
|
+
for (const envelopeName of c.envelopes) {
|
|
53
|
+
it(`${c.name}--${envelopeName} is byte-identical`, async () => {
|
|
54
|
+
const envelope = JSON.parse(
|
|
55
|
+
await readFile(resolve(fixturesDir, `${envelopeName}-envelope.json`), 'utf-8'),
|
|
56
|
+
)
|
|
57
|
+
const outDir = await mkdtemp(join(tmpdir(), 'v9-goldens-'))
|
|
58
|
+
tempDirs.push(outDir)
|
|
59
|
+
|
|
60
|
+
const options: Record<string, unknown> = {
|
|
61
|
+
envelope,
|
|
62
|
+
outDir,
|
|
63
|
+
...manifest.cliDefaults,
|
|
64
|
+
...c.options,
|
|
65
|
+
}
|
|
66
|
+
if (options.target === 'kotlin') {
|
|
67
|
+
options.kotlinEmitter = await resolveProductionKotlinEmitter()
|
|
68
|
+
}
|
|
69
|
+
if (options.target === 'swift') {
|
|
70
|
+
options.swiftEmitter = await resolveProductionSwiftEmitter()
|
|
71
|
+
}
|
|
72
|
+
await generateClient(options as unknown as Parameters<typeof generateClient>[0])
|
|
73
|
+
|
|
74
|
+
const goldenCaseDir = resolve(goldensDir, `${c.name}--${envelopeName}`)
|
|
75
|
+
const goldenFiles = (await readdir(goldenCaseDir)).sort()
|
|
76
|
+
const actualFiles = (await readdir(outDir)).sort()
|
|
77
|
+
expect(actualFiles, 'generated file set must match the v8 baseline').toEqual(goldenFiles)
|
|
78
|
+
|
|
79
|
+
for (const file of goldenFiles) {
|
|
80
|
+
const golden = await readFile(resolve(goldenCaseDir, file), 'utf-8')
|
|
81
|
+
const actual = await readFile(resolve(outDir, file), 'utf-8')
|
|
82
|
+
expect(normalizeVersion(actual), `${c.name}--${envelopeName}/${file}`).toBe(
|
|
83
|
+
normalizeVersion(golden),
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest'
|
|
2
2
|
import { normalizeScope, scopeToCamelCase, groupRoutesByScope } from './group-routes.js'
|
|
3
|
-
import type { AnyHttpRouteDoc } from '../
|
|
3
|
+
import type { AnyHttpRouteDoc } from '../server/types.js'
|
|
4
4
|
|
|
5
5
|
// ---------------------------------------------------------------------------
|
|
6
6
|
// Fixtures
|
|
@@ -6,7 +6,7 @@ import type { KotlinEmitOptions } from './targets/kotlin/ajsc-adapter.js'
|
|
|
6
6
|
import { mkdirSync, rmSync, readFileSync, existsSync, writeFileSync } from 'node:fs'
|
|
7
7
|
import { join } from 'node:path'
|
|
8
8
|
import { tmpdir } from 'node:os'
|
|
9
|
-
import type { DocEnvelope } from '../
|
|
9
|
+
import type { DocEnvelope } from '../server/types.js'
|
|
10
10
|
import { CODEGEN_HEADER } from './constants.js'
|
|
11
11
|
|
|
12
12
|
// ---------------------------------------------------------------------------
|
package/src/codegen/pipeline.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto'
|
|
2
|
-
import type { DocEnvelope } from '../
|
|
2
|
+
import type { DocEnvelope } from '../server/types.js'
|
|
3
3
|
import type { AjscOptions } from './emit-types.js'
|
|
4
4
|
import { groupRoutesByScope } from './group-routes.js'
|
|
5
5
|
import type { SharedTypesImportMap } from './collect-models.js'
|
|
@@ -3,7 +3,7 @@ import { writeFile, mkdtemp, rm } from 'node:fs/promises'
|
|
|
3
3
|
import { tmpdir } from 'node:os'
|
|
4
4
|
import { join } from 'node:path'
|
|
5
5
|
import { resolveEnvelope } from './resolve-envelope.js'
|
|
6
|
-
import type { DocEnvelope } from '../
|
|
6
|
+
import type { DocEnvelope } from '../server/types.js'
|
|
7
7
|
|
|
8
8
|
// ---------------------------------------------------------------------------
|
|
9
9
|
// Fixtures
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
2
|
import { buildErrorSchemasMap } from './error-schemas.js'
|
|
3
|
-
import type { ErrorDoc } from '../../../
|
|
3
|
+
import type { ErrorDoc } from '../../../server/types.js'
|
|
4
4
|
|
|
5
5
|
describe('buildErrorSchemasMap', () => {
|
|
6
6
|
it('returns an empty map when there are no errors', () => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
2
|
import { extractRouteSlots } from './route-slots.js'
|
|
3
|
-
import type { AnyHttpRouteDoc } from '../../../
|
|
3
|
+
import type { AnyHttpRouteDoc } from '../../../server/types.js'
|
|
4
4
|
|
|
5
5
|
// Helpers for constructing minimal route docs per kind
|
|
6
6
|
function apiRoute(jsonSchema: Record<string, unknown>): AnyHttpRouteDoc {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DocEnvelope } from '../../../
|
|
1
|
+
import type { DocEnvelope } from '../../../server/types.js'
|
|
2
2
|
import type { ScopeGroup } from '../../group-routes.js'
|
|
3
3
|
import type { AjscOptions } from '../../emit-types.js'
|
|
4
4
|
import type { SharedTypesImportMap } from '../../collect-models.js'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import type { AnyHttpRouteDoc } from '../../../
|
|
2
|
+
import type { AnyHttpRouteDoc } from '../../../server/types.js'
|
|
3
3
|
import { emitKotlinRoute } from './emit-route-kotlin.js'
|
|
4
4
|
import { createStubKotlinEmitter, type KotlinEmitOptions, type KotlinEmitResult } from './ajsc-adapter.js'
|
|
5
5
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AnyHttpRouteDoc } from '../../../
|
|
1
|
+
import type { AnyHttpRouteDoc } from '../../../server/types.js'
|
|
2
2
|
import type { KotlinEmitter, KotlinEmitOptions } from './ajsc-adapter.js'
|
|
3
3
|
import { indent } from '../_shared/indent.js'
|
|
4
4
|
import { pickDefined } from '../_shared/pick-defined.js'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import type { AnyHttpRouteDoc } from '../../../
|
|
2
|
+
import type { AnyHttpRouteDoc } from '../../../server/types.js'
|
|
3
3
|
import type { ScopeGroup } from '../../group-routes.js'
|
|
4
4
|
import { emitKotlinScope } from './emit-scope-kotlin.js'
|
|
5
5
|
import { createStubKotlinEmitter, type KotlinEmitOptions, type KotlinEmitResult } from './ajsc-adapter.js'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import type { DocEnvelope } from '../../../
|
|
2
|
+
import type { DocEnvelope } from '../../../server/types.js'
|
|
3
3
|
import { runPipeline } from '../../pipeline.js'
|
|
4
4
|
import { resolveProductionSwiftEmitter } from './ajsc-adapter.js'
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import type { AnyHttpRouteDoc } from '../../../
|
|
2
|
+
import type { AnyHttpRouteDoc } from '../../../server/types.js'
|
|
3
3
|
import { emitSwiftRoute } from './emit-route-swift.js'
|
|
4
4
|
import { createStubSwiftEmitter, type SwiftEmitOptions, type SwiftEmitResult } from './ajsc-adapter.js'
|
|
5
5
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AnyHttpRouteDoc } from '../../../
|
|
1
|
+
import type { AnyHttpRouteDoc } from '../../../server/types.js'
|
|
2
2
|
import type { SwiftEmitter, SwiftEmitOptions } from './ajsc-adapter.js'
|
|
3
3
|
import { indent } from '../_shared/indent.js'
|
|
4
4
|
import { pickDefined } from '../_shared/pick-defined.js'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import type { AnyHttpRouteDoc } from '../../../
|
|
2
|
+
import type { AnyHttpRouteDoc } from '../../../server/types.js'
|
|
3
3
|
import type { ScopeGroup } from '../../group-routes.js'
|
|
4
4
|
import { emitSwiftScope } from './emit-scope-swift.js'
|
|
5
5
|
import { createStubSwiftEmitter, type SwiftEmitOptions, type SwiftEmitResult } from './ajsc-adapter.js'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, it, expect, vi } from 'vitest'
|
|
2
2
|
import { runPipeline } from '../../pipeline.js'
|
|
3
|
-
import type { DocEnvelope } from '../../../
|
|
3
|
+
import type { DocEnvelope } from '../../../server/types.js'
|
|
4
4
|
import type { GeneratedFile } from '../_shared/write-files.js'
|
|
5
5
|
import { makeApiRoute, makeEnvelope } from '../../__fixtures__/make-envelope.js'
|
|
6
6
|
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { ProcedureError, ProcedureRegistrationError } from './errors.js'
|
|
2
|
+
import { computeSchema } from '../schema/compute-schema.js'
|
|
3
|
+
import type { Infer, Prettify } from '../schema/json-schema.js'
|
|
4
|
+
import { captureDefinitionInfo } from './definition-site.js'
|
|
5
|
+
import { applyPathPrefix, checkPathParamConsistency } from './http-route.js'
|
|
6
|
+
import {
|
|
7
|
+
assertNotDuplicate,
|
|
8
|
+
combineSignals,
|
|
9
|
+
iterateWithGuards,
|
|
10
|
+
shouldSkipValidation,
|
|
11
|
+
validateReqChannels,
|
|
12
|
+
} from './internal.js'
|
|
13
|
+
import type { FactoryRuntime } from './internal.js'
|
|
14
|
+
import type { HttpMethod, ProcedureResult, TStreamContext, THttpStreamProcedureRegistration } from './types.js'
|
|
15
|
+
|
|
16
|
+
type HttpReq<TReq> = TReq extends Record<string, unknown>
|
|
17
|
+
? Prettify<{ [K in keyof TReq]: Infer<TReq[K]> }>
|
|
18
|
+
: undefined
|
|
19
|
+
|
|
20
|
+
export function makeCreateHttpStream<TContext>(runtime: FactoryRuntime<TContext, any>) {
|
|
21
|
+
/**
|
|
22
|
+
* Defines a streaming HTTP procedure (SSE over a REST-shaped route).
|
|
23
|
+
*
|
|
24
|
+
* The handler either:
|
|
25
|
+
* - returns an async generator directly, or
|
|
26
|
+
* - (with `schema.res.headers` declared) returns
|
|
27
|
+
* `Promise<{ headers, stream }>` so initial response headers can be set
|
|
28
|
+
* before the stream opens.
|
|
29
|
+
*/
|
|
30
|
+
return function CreateHttpStream<
|
|
31
|
+
TName extends string,
|
|
32
|
+
TReq extends Record<string, unknown> | undefined,
|
|
33
|
+
TYieldType,
|
|
34
|
+
TReturnType = void,
|
|
35
|
+
TResHeaders = undefined,
|
|
36
|
+
TErrorKey extends string = string,
|
|
37
|
+
>(
|
|
38
|
+
name: TName,
|
|
39
|
+
config: {
|
|
40
|
+
path: string
|
|
41
|
+
method: HttpMethod
|
|
42
|
+
scope?: string
|
|
43
|
+
errors?: TErrorKey[]
|
|
44
|
+
description?: string
|
|
45
|
+
schema: {
|
|
46
|
+
req?: TReq
|
|
47
|
+
yield?: TYieldType
|
|
48
|
+
returnType?: TReturnType
|
|
49
|
+
res?: TResHeaders extends undefined ? undefined : { headers: TResHeaders }
|
|
50
|
+
}
|
|
51
|
+
validateYields?: boolean
|
|
52
|
+
},
|
|
53
|
+
handler: TResHeaders extends undefined
|
|
54
|
+
? (
|
|
55
|
+
ctx: Prettify<TContext & TStreamContext>,
|
|
56
|
+
req: HttpReq<TReq>,
|
|
57
|
+
) => AsyncGenerator<Infer<TYieldType>, Infer<TReturnType> | void, unknown>
|
|
58
|
+
: (
|
|
59
|
+
ctx: Prettify<TContext & TStreamContext>,
|
|
60
|
+
req: HttpReq<TReq>,
|
|
61
|
+
) => Promise<{
|
|
62
|
+
headers: Infer<TResHeaders>
|
|
63
|
+
stream: AsyncGenerator<Infer<TYieldType>, Infer<TReturnType> | void, unknown>
|
|
64
|
+
}>,
|
|
65
|
+
) {
|
|
66
|
+
const definitionInfo = captureDefinitionInfo()
|
|
67
|
+
|
|
68
|
+
assertNotDuplicate(runtime.registry, name, definitionInfo)
|
|
69
|
+
if ((config.schema as any)?.params) {
|
|
70
|
+
throw new ProcedureRegistrationError(
|
|
71
|
+
name,
|
|
72
|
+
`Use schema.req.body (or schema.req.query) instead of schema.params on CreateHttpStream. Procedure: "${name}".`,
|
|
73
|
+
definitionInfo,
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const { jsonSchema, validations } = computeSchema(
|
|
78
|
+
name,
|
|
79
|
+
{
|
|
80
|
+
req: config.schema.req as Record<string, unknown> | undefined,
|
|
81
|
+
yieldType: config.schema.yield,
|
|
82
|
+
returnType: config.schema.returnType,
|
|
83
|
+
res: config.schema.res as { headers?: unknown } | undefined,
|
|
84
|
+
},
|
|
85
|
+
{ adapters: runtime.adapters, compile: runtime.compile, definitionInfo },
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
const path = applyPathPrefix(runtime.httpDefaults?.pathPrefix, config.path)
|
|
89
|
+
const scope = config.scope ?? runtime.httpDefaults?.scope
|
|
90
|
+
|
|
91
|
+
const pathParamsSchema = (jsonSchema.req as Record<string, unknown> | undefined)?.pathParams
|
|
92
|
+
checkPathParamConsistency(
|
|
93
|
+
name,
|
|
94
|
+
path,
|
|
95
|
+
pathParamsSchema as Record<string, unknown> | undefined,
|
|
96
|
+
definitionInfo,
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
const errorFactory = (message: string, meta?: object) =>
|
|
100
|
+
new ProcedureError(name, message, meta, definitionInfo)
|
|
101
|
+
const validateYields = config.validateYields ?? false
|
|
102
|
+
|
|
103
|
+
const wrappedHandler = async (
|
|
104
|
+
ctx: TContext,
|
|
105
|
+
req: any,
|
|
106
|
+
): Promise<{ stream: AsyncGenerator<any, any, unknown>; initialHeaders?: Record<string, string> }> => {
|
|
107
|
+
const abortController = new AbortController()
|
|
108
|
+
|
|
109
|
+
if (!shouldSkipValidation(ctx, runtime)) {
|
|
110
|
+
validateReqChannels(name, validations.req, req, definitionInfo)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const incomingSignal = (ctx as { signal?: AbortSignal }).signal
|
|
114
|
+
const streamCtx: TStreamContext = {
|
|
115
|
+
error: errorFactory,
|
|
116
|
+
signal: combineSignals(incomingSignal, abortController.signal),
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const handlerResult: any = (handler as any)({ ...ctx, ...streamCtx }, req)
|
|
120
|
+
const guardOptions = {
|
|
121
|
+
name,
|
|
122
|
+
validateYields,
|
|
123
|
+
validateYield: validations.yield,
|
|
124
|
+
abortController,
|
|
125
|
+
definitionInfo,
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (typeof handlerResult?.[Symbol.asyncIterator] === 'function') {
|
|
129
|
+
// Plain async generator from user
|
|
130
|
+
const userIterator = (handlerResult as AsyncGenerator<any, any, unknown>)[Symbol.asyncIterator]()
|
|
131
|
+
return { stream: iterateWithGuards(userIterator, guardOptions) }
|
|
132
|
+
} else if (typeof handlerResult?.then === 'function') {
|
|
133
|
+
// Async preamble: Promise<{ headers, stream }>
|
|
134
|
+
const resolved = await handlerResult
|
|
135
|
+
if (!resolved || typeof resolved !== 'object' || !('stream' in resolved)) {
|
|
136
|
+
throw new ProcedureError(
|
|
137
|
+
name,
|
|
138
|
+
`CreateHttpStream handler returned a Promise that did not resolve to { headers, stream }. Got: ${JSON.stringify(resolved)}`,
|
|
139
|
+
undefined,
|
|
140
|
+
definitionInfo,
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
const userIterator = (resolved.stream as AsyncGenerator<any, any, unknown>)[Symbol.asyncIterator]()
|
|
144
|
+
return {
|
|
145
|
+
stream: iterateWithGuards(userIterator, guardOptions),
|
|
146
|
+
initialHeaders: resolved.headers,
|
|
147
|
+
}
|
|
148
|
+
} else {
|
|
149
|
+
throw new ProcedureError(
|
|
150
|
+
name,
|
|
151
|
+
`CreateHttpStream handler must return an AsyncGenerator or Promise<{ headers, stream }>.`,
|
|
152
|
+
undefined,
|
|
153
|
+
definitionInfo,
|
|
154
|
+
)
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// The registration's schema uses the SAME keys the route-doc builder and
|
|
159
|
+
// THttpStreamProcedureRegistration declare (`yield`, `res.headers`) — v8
|
|
160
|
+
// stored computeSchema's `yieldType` key and omitted `res` entirely, so
|
|
161
|
+
// live envelopes silently dropped both from http-stream route docs.
|
|
162
|
+
const registrationSchema = {
|
|
163
|
+
...(jsonSchema.req !== undefined && { req: jsonSchema.req }),
|
|
164
|
+
...(jsonSchema.res?.headers !== undefined && { res: { headers: jsonSchema.res.headers } }),
|
|
165
|
+
...(jsonSchema.yieldType !== undefined && { yield: jsonSchema.yieldType }),
|
|
166
|
+
...(jsonSchema.returnType !== undefined && { returnType: jsonSchema.returnType }),
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const registeredProcedure: THttpStreamProcedureRegistration<TContext> = {
|
|
170
|
+
name,
|
|
171
|
+
kind: 'http-stream',
|
|
172
|
+
config: {
|
|
173
|
+
path,
|
|
174
|
+
method: config.method,
|
|
175
|
+
scope,
|
|
176
|
+
errors: config.errors as string[] | undefined,
|
|
177
|
+
description: config.description,
|
|
178
|
+
schema: registrationSchema,
|
|
179
|
+
validation: { req: validations.req, yield: validations.yield },
|
|
180
|
+
validateYields,
|
|
181
|
+
},
|
|
182
|
+
handler: wrappedHandler as any,
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
runtime.registry.set(name, registeredProcedure as any)
|
|
186
|
+
runtime.onCreate?.(registeredProcedure as any)
|
|
187
|
+
|
|
188
|
+
const info = { name, kind: 'http-stream' as const, ...registeredProcedure.config }
|
|
189
|
+
|
|
190
|
+
// Explicit handler type — preserves TReq/TYieldType/TReturnType through the
|
|
191
|
+
// public callable. Do NOT use `typeof registeredProcedure.handler` — that
|
|
192
|
+
// erases generics to `any`.
|
|
193
|
+
type Handler = (
|
|
194
|
+
ctx: Prettify<TContext>,
|
|
195
|
+
req: HttpReq<TReq>,
|
|
196
|
+
) => Promise<{
|
|
197
|
+
stream: AsyncGenerator<Infer<TYieldType>, Infer<TReturnType> | void, unknown>
|
|
198
|
+
initialHeaders?: Record<string, string>
|
|
199
|
+
}>
|
|
200
|
+
|
|
201
|
+
return {
|
|
202
|
+
[name]: registeredProcedure.handler,
|
|
203
|
+
procedure: registeredProcedure.handler,
|
|
204
|
+
info,
|
|
205
|
+
} as ProcedureResult<TName, Handler, typeof info>
|
|
206
|
+
}
|
|
207
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, it, expect, expectTypeOf } from 'vitest'
|
|
2
|
-
import { Procedures } from './
|
|
3
|
-
import {
|
|
2
|
+
import { Procedures } from './procedures.js'
|
|
3
|
+
import { ProcedureValidationError } from './errors.js'
|
|
4
4
|
import { Type } from 'typebox'
|
|
5
5
|
|
|
6
6
|
describe('CreateHttp registration', () => {
|
|
@@ -101,10 +101,10 @@ describe('CreateHttp conditional return shape', () => {
|
|
|
101
101
|
schema: {
|
|
102
102
|
res: { headers: Type.Object({ 'x-version': Type.String() }) },
|
|
103
103
|
},
|
|
104
|
-
}, async () => ({ headers: { 'x-version': '
|
|
104
|
+
}, async () => ({ headers: { 'x-version': '9.0.0' } }))
|
|
105
105
|
|
|
106
106
|
const result = await Healthcheck({} as any, undefined)
|
|
107
|
-
expect(result).toEqual({ headers: { 'x-version': '
|
|
107
|
+
expect(result).toEqual({ headers: { 'x-version': '9.0.0' } })
|
|
108
108
|
})
|
|
109
109
|
|
|
110
110
|
it('no res → returns void', async () => {
|
|
@@ -160,4 +160,31 @@ describe('CreateHttp req channel validation', () => {
|
|
|
160
160
|
query: { limit: 'not-a-number' as any },
|
|
161
161
|
})).rejects.toThrow(/req\.query/)
|
|
162
162
|
})
|
|
163
|
+
|
|
164
|
+
it('skips req channel validation when factory has validation: false', async () => {
|
|
165
|
+
const procs = Procedures({ validation: false })
|
|
166
|
+
const { Echo } = procs.CreateHttp('Echo', {
|
|
167
|
+
path: '/echo', method: 'post',
|
|
168
|
+
schema: { req: { body: Type.Object({ name: Type.String() }) } },
|
|
169
|
+
}, async () => undefined)
|
|
170
|
+
|
|
171
|
+
// Missing required `name` would normally throw ProcedureValidationError
|
|
172
|
+
await expect(Echo({} as any, { body: {} as any })).resolves.toBeUndefined()
|
|
173
|
+
})
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
describe('CreateHttp without schema (DX #6 landmine)', () => {
|
|
177
|
+
it('registers and runs a no-input route with schema omitted entirely', async () => {
|
|
178
|
+
const procs = Procedures()
|
|
179
|
+
const { procedure } = procs.CreateHttp('Logout', {
|
|
180
|
+
path: '/logout',
|
|
181
|
+
method: 'post',
|
|
182
|
+
successStatus: 204,
|
|
183
|
+
errors: ['Unauthorized'],
|
|
184
|
+
}, async () => undefined)
|
|
185
|
+
|
|
186
|
+
const reg = procs.getProcedure('Logout')
|
|
187
|
+
expect(reg?.kind).toBe('http')
|
|
188
|
+
await expect(procedure({} as any, undefined)).resolves.toBeUndefined()
|
|
189
|
+
})
|
|
163
190
|
})
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { ProcedureError, ProcedureRegistrationError } from './errors.js'
|
|
2
|
+
import { computeSchema } from '../schema/compute-schema.js'
|
|
3
|
+
import type { Infer, Prettify } from '../schema/json-schema.js'
|
|
4
|
+
import { captureDefinitionInfo } from './definition-site.js'
|
|
5
|
+
import { applyPathPrefix, checkPathParamConsistency } from './http-route.js'
|
|
6
|
+
import {
|
|
7
|
+
assertNotDuplicate,
|
|
8
|
+
shouldSkipValidation,
|
|
9
|
+
toProcedureError,
|
|
10
|
+
validateReqChannels,
|
|
11
|
+
} from './internal.js'
|
|
12
|
+
import type { FactoryRuntime } from './internal.js'
|
|
13
|
+
import type { ProcedureResult, TCreateHttpConfig, TLocalContext, THttpProcedureRegistration } from './types.js'
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The handler return shape is gated by the DECLARED response schema, not by
|
|
17
|
+
* duck-typing the returned value — so domain objects that happen to have
|
|
18
|
+
* `body`/`headers` keys round-trip unchanged:
|
|
19
|
+
* - `schema.res.headers` declared → handler returns `{ body?, headers }`
|
|
20
|
+
* - only `schema.res.body` declared → handler returns the body itself
|
|
21
|
+
* - no `schema.res` → `void` (204-style)
|
|
22
|
+
*/
|
|
23
|
+
export type HttpReturn<TRes> =
|
|
24
|
+
TRes extends { body: infer B; headers: infer H } ? { body: Infer<B>; headers: Infer<H> }
|
|
25
|
+
: TRes extends { headers: infer H } ? { headers: Infer<H> }
|
|
26
|
+
: TRes extends { body: infer B } ? Infer<B>
|
|
27
|
+
: void
|
|
28
|
+
|
|
29
|
+
type HttpReq<TReq> = TReq extends Record<string, unknown>
|
|
30
|
+
? Prettify<{ [K in keyof TReq]: Infer<TReq[K]> }>
|
|
31
|
+
: undefined
|
|
32
|
+
|
|
33
|
+
export function makeCreateHttp<TContext>(runtime: FactoryRuntime<TContext, any>) {
|
|
34
|
+
/**
|
|
35
|
+
* Defines a REST-shaped HTTP procedure with per-channel input validation
|
|
36
|
+
* (`schema.req.{pathParams,query,body,headers}`).
|
|
37
|
+
*
|
|
38
|
+
* Factory-level `http.pathPrefix` / `http.scope` defaults apply here;
|
|
39
|
+
* the per-route config always wins.
|
|
40
|
+
*/
|
|
41
|
+
return function CreateHttp<
|
|
42
|
+
TName extends string,
|
|
43
|
+
TReq extends Record<string, unknown> | undefined = undefined,
|
|
44
|
+
TRes extends { body?: unknown; headers?: unknown } | undefined = undefined,
|
|
45
|
+
TErrorKey extends string = string,
|
|
46
|
+
>(
|
|
47
|
+
name: TName,
|
|
48
|
+
config: TCreateHttpConfig<TReq, TRes, TErrorKey>,
|
|
49
|
+
handler: (ctx: Prettify<TContext & TLocalContext>, req: HttpReq<TReq>) => Promise<HttpReturn<TRes>>,
|
|
50
|
+
) {
|
|
51
|
+
const definitionInfo = captureDefinitionInfo()
|
|
52
|
+
|
|
53
|
+
assertNotDuplicate(runtime.registry, name, definitionInfo)
|
|
54
|
+
|
|
55
|
+
if ((config.schema as any)?.params) {
|
|
56
|
+
throw new ProcedureRegistrationError(
|
|
57
|
+
name,
|
|
58
|
+
`Use schema.req.body (or schema.req.query) instead of schema.params on CreateHttp. Procedure: "${name}".`,
|
|
59
|
+
definitionInfo,
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const { jsonSchema, validations } = computeSchema(
|
|
64
|
+
name,
|
|
65
|
+
{
|
|
66
|
+
req: config.schema?.req as Record<string, unknown> | undefined,
|
|
67
|
+
res: config.schema?.res as { body?: unknown; headers?: unknown } | undefined,
|
|
68
|
+
},
|
|
69
|
+
{ adapters: runtime.adapters, compile: runtime.compile, definitionInfo },
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
const path = applyPathPrefix(runtime.httpDefaults?.pathPrefix, config.path)
|
|
73
|
+
const scope = config.scope ?? runtime.httpDefaults?.scope
|
|
74
|
+
|
|
75
|
+
const pathParamsSchema = (jsonSchema.req as Record<string, unknown> | undefined)?.pathParams
|
|
76
|
+
checkPathParamConsistency(
|
|
77
|
+
name,
|
|
78
|
+
path,
|
|
79
|
+
pathParamsSchema as Record<string, unknown> | undefined,
|
|
80
|
+
definitionInfo,
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
const errorFactory = (message: string, meta?: object) =>
|
|
84
|
+
new ProcedureError(name, message, meta, definitionInfo)
|
|
85
|
+
|
|
86
|
+
const registeredProcedure: THttpProcedureRegistration<TContext> = {
|
|
87
|
+
name,
|
|
88
|
+
kind: 'http',
|
|
89
|
+
config: {
|
|
90
|
+
path,
|
|
91
|
+
method: config.method,
|
|
92
|
+
successStatus: config.successStatus,
|
|
93
|
+
scope,
|
|
94
|
+
errors: config.errors as string[] | undefined,
|
|
95
|
+
description: config.description,
|
|
96
|
+
schema: jsonSchema as any,
|
|
97
|
+
validation: { req: validations.req },
|
|
98
|
+
},
|
|
99
|
+
handler: async (ctx: TContext, req: any) => {
|
|
100
|
+
try {
|
|
101
|
+
if (!shouldSkipValidation(ctx, runtime)) {
|
|
102
|
+
validateReqChannels(name, validations.req, req, definitionInfo)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const localCtx: TLocalContext = { error: errorFactory }
|
|
106
|
+
return await handler({ ...ctx, ...localCtx } as any, req)
|
|
107
|
+
} catch (error: any) {
|
|
108
|
+
throw toProcedureError(name, definitionInfo, error)
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
runtime.registry.set(name, registeredProcedure as any)
|
|
114
|
+
runtime.onCreate?.(registeredProcedure as any)
|
|
115
|
+
|
|
116
|
+
const info = { name, kind: 'http' as const, ...registeredProcedure.config }
|
|
117
|
+
|
|
118
|
+
type Handler = (ctx: Prettify<TContext>, req: HttpReq<TReq>) => Promise<HttpReturn<TRes>>
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
[name]: registeredProcedure.handler,
|
|
122
|
+
procedure: registeredProcedure.handler,
|
|
123
|
+
info,
|
|
124
|
+
} as ProcedureResult<TName, Handler, typeof info>
|
|
125
|
+
}
|
|
126
|
+
}
|