ts-procedures 8.5.0 → 9.0.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/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 +35 -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-index.js +13 -0
- package/build/codegen/emit-index.js.map +1 -1
- package/build/codegen/emit-index.test.js +25 -0
- package/build/codegen/emit-index.test.js.map +1 -1
- package/build/codegen/emit-scope.d.ts +13 -30
- package/build/codegen/emit-scope.js +15 -807
- package/build/codegen/emit-scope.js.map +1 -1
- package/build/codegen/emit-scope.test.js +86 -4
- 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} +13 -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 +182 -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 +4 -4
- package/docs/client-error-handling.md +92 -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 +83 -6
- package/docs/migration-v8-to-v9.md +192 -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 +23 -47
- 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/__fixtures__/users-envelope.json +9 -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 +102 -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-index.test.ts +34 -0
- package/src/codegen/emit-index.ts +19 -0
- package/src/codegen/emit-scope.test.ts +96 -6
- package/src/codegen/emit-scope.ts +15 -1003
- 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/__fixtures__/users-golden.kt +6 -0
- 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/__fixtures__/users-golden.swift +6 -0
- 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} +15 -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 +195 -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/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/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/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,39 @@
|
|
|
1
|
+
import type { Context, Hono } from 'hono'
|
|
2
|
+
import type { TProcedureRegistration } from '../../../core/types.js'
|
|
3
|
+
import type { RPCConfig } from '../../../server/types.js'
|
|
4
|
+
import { dispatchPreStreamError } from '../../../server/errors/dispatch.js'
|
|
5
|
+
import { buildRpcRouteDoc } from '../../../server/docs/rpc-doc.js'
|
|
6
|
+
import { resolveFactoryContext } from '../../../server/context.js'
|
|
7
|
+
import { respondToDispatch } from '../request.js'
|
|
8
|
+
import { preStreamErrorConfig } from '../types.js'
|
|
9
|
+
import type { DocAccumulator, HonoAppBuilderConfig, HonoFactoryItem } from '../types.js'
|
|
10
|
+
|
|
11
|
+
export function installRpcRoute(params: {
|
|
12
|
+
app: Hono
|
|
13
|
+
procedure: TProcedureRegistration<any, RPCConfig>
|
|
14
|
+
factoryItem: HonoFactoryItem
|
|
15
|
+
cfg: HonoAppBuilderConfig
|
|
16
|
+
docs: DocAccumulator
|
|
17
|
+
}): void {
|
|
18
|
+
const { app, procedure, factoryItem, cfg, docs } = params
|
|
19
|
+
|
|
20
|
+
const route = buildRpcRouteDoc(procedure, cfg.pathPrefix, factoryItem.extendProcedureDoc as any)
|
|
21
|
+
docs.push(route)
|
|
22
|
+
|
|
23
|
+
app.post(route.path, async (c: Context) => {
|
|
24
|
+
try {
|
|
25
|
+
const context = await resolveFactoryContext(factoryItem.factoryContext, c)
|
|
26
|
+
const body = await c.req.json().catch(() => ({}))
|
|
27
|
+
const result = await procedure.handler({ ...context, signal: c.req.raw.signal }, body)
|
|
28
|
+
|
|
29
|
+
cfg.rpc?.onSuccess?.(procedure, c)
|
|
30
|
+
|
|
31
|
+
return c.json(result)
|
|
32
|
+
} catch (error) {
|
|
33
|
+
return respondToDispatch(
|
|
34
|
+
c,
|
|
35
|
+
await dispatchPreStreamError({ err: error, procedure, raw: c, cfg: preStreamErrorConfig(cfg) }),
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { describe, expect, test, vi } from 'vitest'
|
|
2
2
|
import { Hono } from 'hono'
|
|
3
3
|
import { Type } from 'typebox'
|
|
4
|
-
import { Procedures } from '
|
|
5
|
-
import type { RPCConfig } from '../../../types.js'
|
|
6
|
-
import {
|
|
4
|
+
import { Procedures } from '../../../core/procedures.js'
|
|
5
|
+
import type { RPCConfig } from '../../../server/types.js'
|
|
6
|
+
import { sse } from '../../../server/sse.js'
|
|
7
|
+
import { installRpcStreamRoute } from './stream.js'
|
|
7
8
|
|
|
8
9
|
function buildApp(setup: (P: ReturnType<typeof Procedures<{ uid: string }, RPCConfig>>) => void, cfg: any = {}) {
|
|
9
10
|
const P = Procedures<{ uid: string }, RPCConfig>()
|
|
@@ -1,38 +1,16 @@
|
|
|
1
1
|
import type { Context, Hono } from 'hono'
|
|
2
2
|
import { streamSSE, streamText } from 'hono/streaming'
|
|
3
|
-
import type { TStreamProcedureRegistration } from '
|
|
4
|
-
import type { RPCConfig, StreamMode } from '../../../types.js'
|
|
5
|
-
import { ProcedureValidationError } from '
|
|
6
|
-
import { dispatchMidStreamError, dispatchPreStreamError } from '
|
|
7
|
-
import { buildStreamRouteDoc } from '
|
|
3
|
+
import type { TStreamProcedureRegistration } from '../../../core/types.js'
|
|
4
|
+
import type { RPCConfig, StreamMode } from '../../../server/types.js'
|
|
5
|
+
import { ProcedureValidationError } from '../../../core/errors.js'
|
|
6
|
+
import { dispatchMidStreamError, dispatchPreStreamError } from '../../../server/errors/dispatch.js'
|
|
7
|
+
import { buildStreamRouteDoc } from '../../../server/docs/stream-doc.js'
|
|
8
|
+
import { resolveFactoryContext } from '../../../server/context.js'
|
|
9
|
+
import { SseEventSequencer } from '../../../server/sse.js'
|
|
10
|
+
import { respondToDispatch } from '../request.js'
|
|
11
|
+
import { midStreamErrorConfig, preStreamErrorConfig } from '../types.js'
|
|
8
12
|
import type { DocAccumulator, HonoAppBuilderConfig, HonoFactoryItem } from '../types.js'
|
|
9
13
|
|
|
10
|
-
export type SSEOptions = {
|
|
11
|
-
event?: string
|
|
12
|
-
id?: string
|
|
13
|
-
retry?: number
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const sseMetadata = new WeakMap<object, SSEOptions>()
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Marks an object yield as an SSE event with custom metadata. Stream handlers
|
|
20
|
-
* read this metadata to set the SSE `event:`, `id:`, and `retry:` fields.
|
|
21
|
-
*/
|
|
22
|
-
export function sse<T extends object>(data: T, options?: SSEOptions): T {
|
|
23
|
-
sseMetadata.set(data, options ?? {})
|
|
24
|
-
return data
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function getSSEMeta(value: unknown): SSEOptions | undefined {
|
|
28
|
-
if (typeof value === 'object' && value !== null) {
|
|
29
|
-
return sseMetadata.get(value as object)
|
|
30
|
-
}
|
|
31
|
-
return undefined
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export type { MidStreamErrorResult } from '../../error-dispatch.js'
|
|
35
|
-
|
|
36
14
|
export function installRpcStreamRoute(params: {
|
|
37
15
|
app: Hono
|
|
38
16
|
procedure: TStreamProcedureRegistration<any, RPCConfig>
|
|
@@ -53,10 +31,7 @@ export function installRpcStreamRoute(params: {
|
|
|
53
31
|
|
|
54
32
|
const handler = async (c: Context) => {
|
|
55
33
|
try {
|
|
56
|
-
const context =
|
|
57
|
-
typeof factoryItem.factoryContext === 'function'
|
|
58
|
-
? await (factoryItem.factoryContext as (c: Context) => any)(c)
|
|
59
|
-
: factoryItem.factoryContext
|
|
34
|
+
const context = await resolveFactoryContext(factoryItem.factoryContext, c)
|
|
60
35
|
|
|
61
36
|
const reqParams =
|
|
62
37
|
c.req.method === 'GET'
|
|
@@ -81,17 +56,10 @@ export function installRpcStreamRoute(params: {
|
|
|
81
56
|
? handleSSE(procedure, context, reqParams, c, cfg)
|
|
82
57
|
: handleText(procedure, context, reqParams, c, cfg)
|
|
83
58
|
} catch (error) {
|
|
84
|
-
return
|
|
85
|
-
|
|
86
|
-
procedure,
|
|
87
|
-
|
|
88
|
-
cfg: {
|
|
89
|
-
errors: cfg.errors,
|
|
90
|
-
unknownError: cfg.unknownError,
|
|
91
|
-
onError: cfg.onError,
|
|
92
|
-
onRequestError: cfg.onRequestError,
|
|
93
|
-
},
|
|
94
|
-
})
|
|
59
|
+
return respondToDispatch(
|
|
60
|
+
c,
|
|
61
|
+
await dispatchPreStreamError({ err: error, procedure, raw: c, cfg: preStreamErrorConfig(cfg) }),
|
|
62
|
+
)
|
|
95
63
|
}
|
|
96
64
|
}
|
|
97
65
|
|
|
@@ -113,53 +81,17 @@ function handleSSE(
|
|
|
113
81
|
)
|
|
114
82
|
stream.onAbort(async () => { await generator.return(undefined) })
|
|
115
83
|
|
|
116
|
-
|
|
84
|
+
const events = new SseEventSequencer((e) => stream.writeSSE(e), procedure.name)
|
|
117
85
|
try {
|
|
118
|
-
|
|
119
|
-
let it = await iterator.next()
|
|
120
|
-
|
|
121
|
-
while (!it.done) {
|
|
122
|
-
const value = it.value
|
|
123
|
-
const meta = getSSEMeta(value)
|
|
124
|
-
const data =
|
|
125
|
-
typeof value === 'string' ? value
|
|
126
|
-
: value != null ? JSON.stringify(value)
|
|
127
|
-
: ''
|
|
128
|
-
|
|
129
|
-
await stream.writeSSE({
|
|
130
|
-
data,
|
|
131
|
-
event: meta?.event ?? procedure.name,
|
|
132
|
-
id: meta?.id ?? String(eventId++),
|
|
133
|
-
...(meta?.retry !== undefined && { retry: meta.retry }),
|
|
134
|
-
})
|
|
135
|
-
it = await iterator.next()
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
if (it.value !== undefined) {
|
|
139
|
-
const data = typeof it.value === 'string' ? it.value : JSON.stringify(it.value)
|
|
140
|
-
await stream.writeSSE({ data, event: 'return', id: String(eventId++) })
|
|
141
|
-
}
|
|
86
|
+
await events.pump(generator[Symbol.asyncIterator]())
|
|
142
87
|
} catch (error) {
|
|
143
88
|
const dispatched = await dispatchMidStreamError({
|
|
144
89
|
err: error,
|
|
145
90
|
procedure,
|
|
146
91
|
raw: c,
|
|
147
|
-
cfg:
|
|
148
|
-
errors: cfg.errors,
|
|
149
|
-
unknownError: cfg.unknownError,
|
|
150
|
-
onMidStreamError: cfg.stream?.onMidStreamError,
|
|
151
|
-
onRequestError: cfg.onRequestError,
|
|
152
|
-
},
|
|
92
|
+
cfg: midStreamErrorConfig(cfg),
|
|
153
93
|
})
|
|
154
|
-
|
|
155
|
-
const meta = getSSEMeta(dispatched.data)
|
|
156
|
-
await stream.writeSSE({
|
|
157
|
-
data: typeof dispatched.data === 'string' ? dispatched.data : JSON.stringify(dispatched.data),
|
|
158
|
-
event: meta?.event ?? dispatched.sseEvent ?? 'error',
|
|
159
|
-
id: meta?.id ?? String(eventId++),
|
|
160
|
-
...(meta?.retry !== undefined && { retry: meta.retry }),
|
|
161
|
-
})
|
|
162
|
-
|
|
94
|
+
await events.writeError(dispatched)
|
|
163
95
|
if (dispatched.runOnCatch) await dispatched.runOnCatch()
|
|
164
96
|
} finally {
|
|
165
97
|
cfg.stream?.onStreamEnd?.(procedure, c, 'sse')
|
|
@@ -191,12 +123,7 @@ function handleText(
|
|
|
191
123
|
err: error,
|
|
192
124
|
procedure,
|
|
193
125
|
raw: c,
|
|
194
|
-
cfg:
|
|
195
|
-
errors: cfg.errors,
|
|
196
|
-
unknownError: cfg.unknownError,
|
|
197
|
-
onMidStreamError: cfg.stream?.onMidStreamError,
|
|
198
|
-
onRequestError: cfg.onRequestError,
|
|
199
|
-
},
|
|
126
|
+
cfg: midStreamErrorConfig(cfg),
|
|
200
127
|
})
|
|
201
128
|
await stream.writeln(JSON.stringify(dispatched.data))
|
|
202
129
|
if (dispatched.runOnCatch) await dispatched.runOnCatch()
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { describe, expect, test, vi } from 'vitest'
|
|
2
2
|
import { Hono } from 'hono'
|
|
3
3
|
import { Type } from 'typebox'
|
|
4
|
-
import { Procedures } from '
|
|
5
|
-
import type { RPCConfig } from '../../types.js'
|
|
6
|
-
import { HonoAppBuilder } from './index.js'
|
|
7
|
-
import { defineErrorTaxonomy } from '../error-taxonomy.js'
|
|
8
|
-
import { DocRegistry } from '../doc-registry.js'
|
|
4
|
+
import { Procedures } from '../../core/procedures.js'
|
|
5
|
+
import type { RPCConfig } from '../../server/types.js'
|
|
6
|
+
import { HonoAppBuilder, defineErrorTaxonomy, DocRegistry } from './index.js'
|
|
9
7
|
|
|
10
8
|
describe('HonoAppBuilder — public surface', () => {
|
|
11
9
|
test('constructor with no args', () => {
|
|
@@ -23,14 +21,14 @@ describe('HonoAppBuilder — public surface', () => {
|
|
|
23
21
|
|
|
24
22
|
test('register is chainable', () => {
|
|
25
23
|
const b = new HonoAppBuilder()
|
|
26
|
-
const P = Procedures<
|
|
24
|
+
const P = Procedures<object, RPCConfig>()
|
|
27
25
|
const result = b.register(P, () => ({}))
|
|
28
26
|
expect(result).toBe(b)
|
|
29
27
|
})
|
|
30
28
|
|
|
31
29
|
test('docs is lazily computed before build()', () => {
|
|
32
30
|
const b = new HonoAppBuilder()
|
|
33
|
-
const P = Procedures<
|
|
31
|
+
const P = Procedures<object, RPCConfig>()
|
|
34
32
|
P.Create('A', { scope: 's', version: 1 }, async () => ({}))
|
|
35
33
|
b.register(P, () => ({}))
|
|
36
34
|
|
|
@@ -43,7 +41,7 @@ describe('HonoAppBuilder — public surface', () => {
|
|
|
43
41
|
|
|
44
42
|
test('docs reads after build() return the same content', () => {
|
|
45
43
|
const b = new HonoAppBuilder()
|
|
46
|
-
const P = Procedures<
|
|
44
|
+
const P = Procedures<object, RPCConfig>()
|
|
47
45
|
P.Create('A', { scope: 's', version: 1 }, async () => ({}))
|
|
48
46
|
b.register(P, () => ({}))
|
|
49
47
|
b.build()
|
|
@@ -89,7 +87,7 @@ describe('HonoAppBuilder — mixed-kind dispatch', () => {
|
|
|
89
87
|
})
|
|
90
88
|
|
|
91
89
|
test('toDocEnvelope produces same shape as DocRegistry.toJSON', () => {
|
|
92
|
-
const P = Procedures<
|
|
90
|
+
const P = Procedures<object, RPCConfig>()
|
|
93
91
|
P.Create('Echo', { scope: 'e', version: 1 }, async () => ({}))
|
|
94
92
|
|
|
95
93
|
const errors = defineErrorTaxonomy({})
|
|
@@ -106,7 +104,7 @@ describe('HonoAppBuilder — mixed-kind dispatch', () => {
|
|
|
106
104
|
})
|
|
107
105
|
|
|
108
106
|
test('toDocEnvelope filter and transform options work', () => {
|
|
109
|
-
const P = Procedures<
|
|
107
|
+
const P = Procedures<object, RPCConfig>()
|
|
110
108
|
P.Create('A', { scope: 's', version: 1 }, async () => ({}))
|
|
111
109
|
P.Create('B', { scope: 's', version: 1 }, async () => ({}))
|
|
112
110
|
|
|
@@ -122,7 +120,7 @@ describe('HonoAppBuilder — mixed-kind dispatch', () => {
|
|
|
122
120
|
})
|
|
123
121
|
|
|
124
122
|
test('makeRoutePath static is exposed', () => {
|
|
125
|
-
const P = Procedures<
|
|
123
|
+
const P = Procedures<object, RPCConfig>()
|
|
126
124
|
P.Create('GetUser', { scope: 'users', version: 1 }, async () => ({}))
|
|
127
125
|
const proc = P.getProcedure('GetUser')!
|
|
128
126
|
expect(HonoAppBuilder.makeRoutePath({ procedure: proc as any })).toBe('/users/get-user/1')
|
|
@@ -219,7 +217,7 @@ describe('HonoAppBuilder — extendProcedureDoc discriminated union per kind', (
|
|
|
219
217
|
summary: `RPC: ${base.kind}`,
|
|
220
218
|
tags: ['rpc'],
|
|
221
219
|
}))
|
|
222
|
-
const P = Procedures<
|
|
220
|
+
const P = Procedures<object, RPCConfig>()
|
|
223
221
|
P.Create('GetUser', { scope: 'users', version: 1 }, async () => ({}))
|
|
224
222
|
|
|
225
223
|
const builder = new HonoAppBuilder().register(P, () => ({}), { extendProcedureDoc: extend })
|
|
@@ -237,7 +235,7 @@ describe('HonoAppBuilder — extendProcedureDoc discriminated union per kind', (
|
|
|
237
235
|
summary: `API: ${base.kind}`,
|
|
238
236
|
tags: ['api'],
|
|
239
237
|
}))
|
|
240
|
-
const P = Procedures<
|
|
238
|
+
const P = Procedures<object>()
|
|
241
239
|
P.CreateHttp(
|
|
242
240
|
'GetUser',
|
|
243
241
|
{
|
|
@@ -266,7 +264,7 @@ describe('HonoAppBuilder — extendProcedureDoc discriminated union per kind', (
|
|
|
266
264
|
summary: `Stream: ${base.kind}`,
|
|
267
265
|
tags: ['stream'],
|
|
268
266
|
}))
|
|
269
|
-
const P = Procedures<
|
|
267
|
+
const P = Procedures<object, RPCConfig>()
|
|
270
268
|
P.CreateStream('Tail', { scope: 'rpc', version: 1 }, async function* () {
|
|
271
269
|
yield 1
|
|
272
270
|
})
|
|
@@ -286,7 +284,7 @@ describe('HonoAppBuilder — extendProcedureDoc discriminated union per kind', (
|
|
|
286
284
|
summary: `HTTP-Stream: ${base.kind}`,
|
|
287
285
|
tags: ['http-stream'],
|
|
288
286
|
}))
|
|
289
|
-
const P = Procedures<
|
|
287
|
+
const P = Procedures<object>()
|
|
290
288
|
P.CreateHttpStream(
|
|
291
289
|
'Watch',
|
|
292
290
|
{ path: '/watch', method: 'get', schema: { yield: Type.String() } },
|
|
@@ -308,7 +306,7 @@ describe('HonoAppBuilder — extendProcedureDoc discriminated union per kind', (
|
|
|
308
306
|
|
|
309
307
|
describe('HonoAppBuilder — per-factory streamMode override', () => {
|
|
310
308
|
test('register options.streamMode overrides stream.defaultStreamMode', async () => {
|
|
311
|
-
const P = Procedures<
|
|
309
|
+
const P = Procedures<object, RPCConfig>()
|
|
312
310
|
P.CreateStream('Test', { scope: 'test', version: 1 }, async function* () {
|
|
313
311
|
yield { ok: true }
|
|
314
312
|
})
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Context} from 'hono';
|
|
2
1
|
import { Hono } from 'hono'
|
|
3
2
|
import type {
|
|
4
3
|
AnyHttpRouteDoc,
|
|
@@ -8,34 +7,42 @@ import type {
|
|
|
8
7
|
DocEnvelope,
|
|
9
8
|
ErrorDoc,
|
|
10
9
|
HeaderDoc,
|
|
11
|
-
} from '../../types.js'
|
|
12
|
-
import {
|
|
13
|
-
import
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
10
|
+
} from '../../server/types.js'
|
|
11
|
+
import type { AnyProcedureRegistration } from '../../core/types.js'
|
|
12
|
+
import { DocRegistry } from '../../server/doc-registry.js'
|
|
13
|
+
import type { ErrorTaxonomy } from '../../server/errors/taxonomy.js'
|
|
14
|
+
import type { FactoryContextInit } from '../../server/context.js'
|
|
15
|
+
import { buildRpcRouteDoc } from '../../server/docs/rpc-doc.js'
|
|
16
|
+
import { buildStreamRouteDoc } from '../../server/docs/stream-doc.js'
|
|
17
|
+
import { buildHttpRouteDoc } from '../../server/docs/http-doc.js'
|
|
18
|
+
import { buildHttpStreamRouteDoc } from '../../server/docs/http-stream-doc.js'
|
|
19
|
+
import { makeRoutePath as _makeRoutePath } from '../../server/paths.js'
|
|
18
20
|
import { installRpcRoute } from './handlers/rpc.js'
|
|
19
21
|
import { installRpcStreamRoute } from './handlers/stream.js'
|
|
20
22
|
import { installHttpRoute } from './handlers/http.js'
|
|
21
23
|
import { installHttpStreamRoute } from './handlers/http-stream.js'
|
|
22
|
-
import {
|
|
23
|
-
import type {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
} from '
|
|
30
|
-
|
|
31
|
-
export type {
|
|
32
|
-
export
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
24
|
+
import type { Context } from 'hono'
|
|
25
|
+
import type { HonoAppBuilderConfig, HonoFactoryItem, ExtendProcedureDoc } from './types.js'
|
|
26
|
+
|
|
27
|
+
export type { HonoAppBuilderConfig, ExtendProcedureDoc, QueryParser } from './types.js'
|
|
28
|
+
export type { OnRequestErrorContext } from './types.js'
|
|
29
|
+
export { sse } from '../../server/sse.js'
|
|
30
|
+
export type { SSEOptions } from '../../server/sse.js'
|
|
31
|
+
export type { MidStreamErrorResult } from '../../server/errors/dispatch.js'
|
|
32
|
+
export { defineErrorTaxonomy } from '../../server/errors/taxonomy.js'
|
|
33
|
+
export type { ErrorTaxonomy, ErrorTaxonomyEntry, UnknownErrorConfig } from '../../server/errors/taxonomy.js'
|
|
34
|
+
export { DocRegistry } from '../../server/doc-registry.js'
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Serves every procedure kind (`rpc`, `rpc-stream`, `http`, `http-stream`)
|
|
38
|
+
* from registered factories on a single Hono app.
|
|
39
|
+
*
|
|
40
|
+
* This adapter is deliberately thin: route docs, error taxonomy dispatch,
|
|
41
|
+
* request channel extraction, and SSE semantics all live in the
|
|
42
|
+
* transport-agnostic `ts-procedures/server` layer; the handlers here only
|
|
43
|
+
* translate between Hono's request/response/streaming primitives and that
|
|
44
|
+
* layer. Use it as the blueprint for adapters to other frameworks.
|
|
45
|
+
*/
|
|
39
46
|
export class HonoAppBuilder<TStreamErrorData = unknown> {
|
|
40
47
|
private readonly _app: Hono
|
|
41
48
|
private readonly factories: HonoFactoryItem<any>[] = []
|
|
@@ -81,9 +88,7 @@ export class HonoAppBuilder<TStreamErrorData = unknown> {
|
|
|
81
88
|
|
|
82
89
|
register<TFactory extends ProceduresFactory>(
|
|
83
90
|
factory: TFactory,
|
|
84
|
-
factoryContext:
|
|
85
|
-
| ExtractContext<TFactory>
|
|
86
|
-
| ((c: Context) => ExtractContext<TFactory> | Promise<ExtractContext<TFactory>>),
|
|
91
|
+
factoryContext: FactoryContextInit<ExtractContext<TFactory>, Context>,
|
|
87
92
|
options?: {
|
|
88
93
|
streamMode?: StreamMode
|
|
89
94
|
extendProcedureDoc?: ExtendProcedureDoc
|
|
@@ -105,7 +110,7 @@ export class HonoAppBuilder<TStreamErrorData = unknown> {
|
|
|
105
110
|
const skipped: { name: string; reason: string }[] = []
|
|
106
111
|
|
|
107
112
|
for (const item of this.factories) {
|
|
108
|
-
for (const procedure of item.factory.getProcedures().values() as Iterable<AnyProcedureRegistration
|
|
113
|
+
for (const procedure of item.factory.getProcedures().values() as Iterable<AnyProcedureRegistration<any, any>>) {
|
|
109
114
|
const prefix = this.config?.pathPrefix
|
|
110
115
|
switch (procedure.kind) {
|
|
111
116
|
case 'rpc':
|
|
@@ -150,7 +155,7 @@ export class HonoAppBuilder<TStreamErrorData = unknown> {
|
|
|
150
155
|
const cfg = this.config ?? {}
|
|
151
156
|
|
|
152
157
|
for (const item of this.factories) {
|
|
153
|
-
for (const procedure of item.factory.getProcedures().values() as Iterable<AnyProcedureRegistration
|
|
158
|
+
for (const procedure of item.factory.getProcedures().values() as Iterable<AnyProcedureRegistration<any, any>>) {
|
|
154
159
|
switch (procedure.kind) {
|
|
155
160
|
case 'rpc':
|
|
156
161
|
installRpcRoute({ app: this._app, procedure: procedure as any, factoryItem: item, cfg, docs })
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import { describe, expect, test, vi } from 'vitest'
|
|
15
15
|
import { Type } from 'typebox'
|
|
16
|
-
import { Procedures } from '../../
|
|
17
|
-
import type { RPCConfig } from '
|
|
18
|
-
import { HonoAppBuilder } from './
|
|
16
|
+
import { Procedures } from '../../core/procedures.js'
|
|
17
|
+
import type { RPCConfig } from '../../server/types.js'
|
|
18
|
+
import { HonoAppBuilder } from './index.js'
|
|
19
19
|
|
|
20
20
|
describe('onRequestError — HonoAppBuilder (rpc kind)', () => {
|
|
21
21
|
function boomApp(config: ConstructorParameters<typeof HonoAppBuilder>[0]) {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Context } from 'hono'
|
|
2
|
+
import type { RequestSource } from '../../server/request/params.js'
|
|
3
|
+
import type { PreStreamDispatchResult } from '../../server/errors/dispatch.js'
|
|
4
|
+
|
|
5
|
+
/** Adapts a Hono `Context` to the server layer's {@link RequestSource}. */
|
|
6
|
+
export function honoRequestSource(c: Context): RequestSource {
|
|
7
|
+
return {
|
|
8
|
+
pathParams: () => c.req.param(),
|
|
9
|
+
url: () => c.req.url,
|
|
10
|
+
json: () => c.req.json(),
|
|
11
|
+
headers: () => {
|
|
12
|
+
const obj: Record<string, string> = {}
|
|
13
|
+
c.req.raw.headers.forEach((v, k) => {
|
|
14
|
+
obj[k] = v
|
|
15
|
+
})
|
|
16
|
+
return obj
|
|
17
|
+
},
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Translates a pre-stream dispatch result into a Hono response. */
|
|
22
|
+
export function respondToDispatch(
|
|
23
|
+
c: Context,
|
|
24
|
+
result: PreStreamDispatchResult<Response>,
|
|
25
|
+
): Response {
|
|
26
|
+
if (result.type === 'response') return result.response
|
|
27
|
+
return c.json(result.body, result.statusCode as never)
|
|
28
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-empty-object-type */
|
|
2
2
|
import { describe, expect, test } from 'vitest'
|
|
3
3
|
import { Type } from 'typebox'
|
|
4
|
-
import { Procedures } from '../../
|
|
5
|
-
import type { APIConfig, RPCConfig } from '
|
|
6
|
-
import { HonoAppBuilder } from './
|
|
7
|
-
import { DocRegistry } from '
|
|
8
|
-
import { defineErrorTaxonomy } from '
|
|
4
|
+
import { Procedures } from '../../core/procedures.js'
|
|
5
|
+
import type { APIConfig, RPCConfig } from '../../server/types.js'
|
|
6
|
+
import { HonoAppBuilder } from './index.js'
|
|
7
|
+
import { DocRegistry } from '../../server/doc-registry.js'
|
|
8
|
+
import { defineErrorTaxonomy } from '../../server/errors/taxonomy.js'
|
|
9
9
|
|
|
10
10
|
class UseCaseError extends Error {
|
|
11
11
|
constructor(readonly externalMsg: string) {
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import type { Context, Hono } from 'hono'
|
|
2
|
-
import type { ErrorTaxonomy, UnknownErrorConfig } from '
|
|
2
|
+
import type { ErrorTaxonomy, UnknownErrorConfig } from '../../server/errors/taxonomy.js'
|
|
3
3
|
import type {
|
|
4
|
-
AnyProcedureRegistration,
|
|
5
4
|
OnRequestErrorObserver,
|
|
6
5
|
OnMidStreamError,
|
|
7
6
|
PreStreamOnError,
|
|
8
|
-
|
|
7
|
+
PreStreamErrorConfig,
|
|
8
|
+
MidStreamErrorConfig,
|
|
9
|
+
} from '../../server/errors/dispatch.js'
|
|
10
|
+
import type { QueryParser } from '../../server/request/query.js'
|
|
11
|
+
import type { FactoryContextInit } from '../../server/context.js'
|
|
9
12
|
import type {
|
|
10
13
|
ProceduresFactory,
|
|
11
14
|
ExtractContext,
|
|
@@ -15,35 +18,31 @@ import type {
|
|
|
15
18
|
APIHttpRouteDoc,
|
|
16
19
|
StreamHttpRouteDoc,
|
|
17
20
|
HttpStreamRouteDoc,
|
|
18
|
-
} from '../../types.js'
|
|
21
|
+
} from '../../server/types.js'
|
|
19
22
|
import type {
|
|
23
|
+
AnyProcedureRegistration,
|
|
20
24
|
TProcedureRegistration,
|
|
21
25
|
TStreamProcedureRegistration,
|
|
22
26
|
THttpProcedureRegistration,
|
|
23
27
|
THttpStreamProcedureRegistration,
|
|
24
|
-
} from '
|
|
25
|
-
|
|
26
|
-
export type { AnyProcedureRegistration } from '../error-dispatch.js'
|
|
28
|
+
} from '../../core/types.js'
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
export type QueryParser = (queryString: string) => Record<string, unknown>
|
|
30
|
+
export type { QueryParser } from '../../server/request/query.js'
|
|
30
31
|
|
|
31
32
|
export type OnRequestErrorContext = {
|
|
32
33
|
err: unknown
|
|
33
|
-
procedure: AnyProcedureRegistration
|
|
34
|
+
procedure: AnyProcedureRegistration<any, any>
|
|
34
35
|
raw: Context
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
export type ExtendProcedureDoc = (params: {
|
|
38
39
|
base: RPCHttpRouteDoc | APIHttpRouteDoc | StreamHttpRouteDoc | HttpStreamRouteDoc
|
|
39
|
-
procedure: AnyProcedureRegistration
|
|
40
|
+
procedure: AnyProcedureRegistration<any, any>
|
|
40
41
|
}) => Record<string, unknown>
|
|
41
42
|
|
|
42
43
|
export type HonoFactoryItem<TFactory extends ProceduresFactory = ProceduresFactory> = {
|
|
43
44
|
factory: TFactory
|
|
44
|
-
factoryContext:
|
|
45
|
-
| ExtractContext<TFactory>
|
|
46
|
-
| ((c: Context) => ExtractContext<TFactory> | Promise<ExtractContext<TFactory>>)
|
|
45
|
+
factoryContext: FactoryContextInit<ExtractContext<TFactory>, Context>
|
|
47
46
|
streamMode?: StreamMode
|
|
48
47
|
extendProcedureDoc?: ExtendProcedureDoc
|
|
49
48
|
}
|
|
@@ -57,9 +56,9 @@ export type HonoAppBuilderConfig<TStreamErrorData = unknown> = {
|
|
|
57
56
|
// Error handling — peers
|
|
58
57
|
errors?: ErrorTaxonomy
|
|
59
58
|
unknownError?: UnknownErrorConfig
|
|
60
|
-
onError?: PreStreamOnError
|
|
59
|
+
onError?: PreStreamOnError<Context, Response>
|
|
61
60
|
/** Cross-cutting observer — fires for every caught error before dispatch. */
|
|
62
|
-
onRequestError?: OnRequestErrorObserver
|
|
61
|
+
onRequestError?: OnRequestErrorObserver<Context>
|
|
63
62
|
|
|
64
63
|
// Lifecycle (every kind)
|
|
65
64
|
onRequestStart?: (c: Context) => void
|
|
@@ -67,7 +66,7 @@ export type HonoAppBuilderConfig<TStreamErrorData = unknown> = {
|
|
|
67
66
|
|
|
68
67
|
// Kind-specific blocks
|
|
69
68
|
rpc?: {
|
|
70
|
-
onSuccess?: (procedure: TProcedureRegistration, c: Context) => void
|
|
69
|
+
onSuccess?: (procedure: TProcedureRegistration<any, any>, c: Context) => void
|
|
71
70
|
}
|
|
72
71
|
api?: {
|
|
73
72
|
queryParser?: QueryParser
|
|
@@ -77,17 +76,41 @@ export type HonoAppBuilderConfig<TStreamErrorData = unknown> = {
|
|
|
77
76
|
/** Default for both rpc-stream and http-stream. */
|
|
78
77
|
defaultStreamMode?: StreamMode
|
|
79
78
|
onStreamStart?: (
|
|
80
|
-
procedure: TStreamProcedureRegistration | THttpStreamProcedureRegistration<any>,
|
|
79
|
+
procedure: TStreamProcedureRegistration<any, any> | THttpStreamProcedureRegistration<any>,
|
|
81
80
|
c: Context,
|
|
82
81
|
streamMode: StreamMode,
|
|
83
82
|
) => void
|
|
84
83
|
onStreamEnd?: (
|
|
85
|
-
procedure: TStreamProcedureRegistration | THttpStreamProcedureRegistration<any>,
|
|
84
|
+
procedure: TStreamProcedureRegistration<any, any> | THttpStreamProcedureRegistration<any>,
|
|
86
85
|
c: Context,
|
|
87
86
|
streamMode: StreamMode,
|
|
88
87
|
) => void
|
|
89
|
-
onMidStreamError?: OnMidStreamError<TStreamErrorData>
|
|
88
|
+
onMidStreamError?: OnMidStreamError<TStreamErrorData, Context>
|
|
90
89
|
}
|
|
91
90
|
}
|
|
92
91
|
|
|
93
92
|
export type DocAccumulator = AnyHttpRouteDoc[]
|
|
93
|
+
|
|
94
|
+
/** The pre-stream slice of the builder config, passed to dispatch. */
|
|
95
|
+
export function preStreamErrorConfig(
|
|
96
|
+
cfg: HonoAppBuilderConfig<any>,
|
|
97
|
+
): PreStreamErrorConfig<Context, Response> {
|
|
98
|
+
return {
|
|
99
|
+
errors: cfg.errors,
|
|
100
|
+
unknownError: cfg.unknownError,
|
|
101
|
+
onError: cfg.onError,
|
|
102
|
+
onRequestError: cfg.onRequestError,
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** The mid-stream slice of the builder config, passed to dispatch. */
|
|
107
|
+
export function midStreamErrorConfig<TStreamErrorData>(
|
|
108
|
+
cfg: HonoAppBuilderConfig<TStreamErrorData>,
|
|
109
|
+
): MidStreamErrorConfig<TStreamErrorData, Context> {
|
|
110
|
+
return {
|
|
111
|
+
errors: cfg.errors,
|
|
112
|
+
unknownError: cfg.unknownError,
|
|
113
|
+
onMidStreamError: cfg.stream?.onMidStreamError,
|
|
114
|
+
onRequestError: cfg.onRequestError,
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import { readFile } from 'node:fs/promises'
|
|
3
|
+
import { dirname, resolve } from 'node:path'
|
|
4
|
+
import { fileURLToPath } from 'node:url'
|
|
5
|
+
import { describe, expect, it } from 'vitest'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The client runtime is CONTENT-FROZEN for v9.
|
|
9
|
+
*
|
|
10
|
+
* Self-contained codegen (the default) bundles these source files verbatim
|
|
11
|
+
* (imports stripped) into the generated `_client.ts` / `_types.ts`. The v9
|
|
12
|
+
* hard requirement is byte-identical generated output vs v8.6.0, so these
|
|
13
|
+
* files must not change. If you intentionally change one, you are changing
|
|
14
|
+
* generated output for every downstream app: re-capture the codegen goldens,
|
|
15
|
+
* verify the diff is wanted, and update the hash here.
|
|
16
|
+
*
|
|
17
|
+
* Hashes recorded from v8.6.0 `src/client/*.ts`.
|
|
18
|
+
*/
|
|
19
|
+
const FROZEN_FILES: ReadonlyArray<readonly [file: string, sha256: string]> = [
|
|
20
|
+
['errors.ts', 'abcdee64e22e748d870efdac68f03a05cd0666c65ec3f3b5217acd9c22f72a4d'],
|
|
21
|
+
['classify-error.ts', '28062fdc3be39461eeec4cc96e3edcf46377922bac6fb3cc7b54111b42199773'],
|
|
22
|
+
['error-dispatch.ts', '1bdd89319239e8aca0f186714c15b77ae5f4a9ac2c257416ddaf36d965dbe141'],
|
|
23
|
+
['request-builder.ts', 'ac15485e6786de00386e6c4a425dbab503589bc012af6ef6515b1c3e4176a51e'],
|
|
24
|
+
['resolve-options.ts', 'a0e6d745a630176696c0221f5166958bfc5255e50168e5f3cf021bbf4a8aaffc'],
|
|
25
|
+
['hooks.ts', '15d67ba827dbb6e38407af606c05a459ec27e3b1e738aac868233d0f10478aa7'],
|
|
26
|
+
['call.ts', 'b7afeadb3b338cb45ab09273a1729c25ea0f6429670664d197d91ee47cc0a3dc'],
|
|
27
|
+
['stream.ts', '655af96f789150e3fedb7b345aae70d58b1d3b3cad9eb8b341d5a4780d5760ce'],
|
|
28
|
+
['fetch-adapter.ts', 'c5a6ebdeecac3a5efc3d77f346135609e23c5eebc671a08456175901106655a2'],
|
|
29
|
+
['index.ts', '8e33080aba85ba9af52f8b7232c01c82fae167742facb250f5d6800d51544d65'],
|
|
30
|
+
['types.ts', 'e236213020290fd187a80cdf060fcb3d67e734e94aa060c736f142cbefd4ced7'],
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
const clientDir = dirname(fileURLToPath(import.meta.url))
|
|
34
|
+
|
|
35
|
+
describe('client runtime freeze (codegen bundling contract)', () => {
|
|
36
|
+
it.each(FROZEN_FILES)('%s matches its v8.6.0 content hash', async (file, expected) => {
|
|
37
|
+
const content = await readFile(resolve(clientDir, file), 'utf-8')
|
|
38
|
+
const actual = createHash('sha256').update(content).digest('hex')
|
|
39
|
+
expect(actual, `${file} diverged from the frozen v8.6.0 content — this changes generated _client.ts/_types.ts output`).toBe(expected)
|
|
40
|
+
})
|
|
41
|
+
})
|