ts-procedures 7.2.0 → 8.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 +65 -3
- package/agent_config/claude-code/agents/ts-procedures-architect.md +6 -8
- package/agent_config/claude-code/skills/ts-procedures/SKILL.md +30 -33
- package/agent_config/claude-code/skills/ts-procedures/anti-patterns.md +139 -53
- package/agent_config/claude-code/skills/ts-procedures/api-reference.md +208 -231
- package/agent_config/claude-code/skills/ts-procedures/patterns.md +80 -153
- package/agent_config/claude-code/skills/ts-procedures-review/SKILL.md +1 -1
- package/agent_config/claude-code/skills/ts-procedures-review/checklist.md +4 -5
- package/agent_config/claude-code/skills/ts-procedures-scaffold/SKILL.md +4 -7
- package/agent_config/claude-code/skills/ts-procedures-scaffold/templates/hono.md +223 -0
- package/agent_config/copilot/copilot-instructions.md +36 -48
- package/agent_config/cursor/cursorrules +36 -48
- package/build/client/call.js +4 -1
- package/build/client/call.js.map +1 -1
- package/build/client/call.test.js +23 -0
- package/build/client/call.test.js.map +1 -1
- package/build/client/fetch-adapter.js +3 -1
- package/build/client/fetch-adapter.js.map +1 -1
- package/build/client/fetch-adapter.test.js +11 -1
- package/build/client/fetch-adapter.test.js.map +1 -1
- package/build/client/index.test.js +7 -7
- package/build/client/index.test.js.map +1 -1
- package/build/client/request-builder.d.ts +1 -1
- package/build/client/request-builder.js +2 -2
- package/build/client/request-builder.js.map +1 -1
- package/build/client/stream.js +13 -2
- package/build/client/stream.js.map +1 -1
- package/build/client/stream.test.js +32 -7
- package/build/client/stream.test.js.map +1 -1
- package/build/client/typed-error-dispatch.test.js +8 -92
- package/build/client/typed-error-dispatch.test.js.map +1 -1
- package/build/client/types.d.ts +21 -3
- package/build/codegen/bin/cli.js +0 -0
- package/build/codegen/e2e.test.js +87 -23
- package/build/codegen/e2e.test.js.map +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.js +308 -47
- package/build/codegen/emit-scope.js.map +1 -1
- package/build/codegen/emit-scope.test.js +363 -110
- package/build/codegen/emit-scope.test.js.map +1 -1
- package/build/codegen/pipeline.test.js +7 -7
- package/build/codegen/pipeline.test.js.map +1 -1
- package/build/codegen/resolve-envelope.js +1 -1
- package/build/codegen/resolve-envelope.js.map +1 -1
- package/build/codegen/resolve-envelope.test.js +5 -5
- package/build/codegen/resolve-envelope.test.js.map +1 -1
- package/build/codegen/targets/_shared/route-slots.d.ts +8 -3
- package/build/codegen/targets/_shared/route-slots.js +49 -8
- package/build/codegen/targets/_shared/route-slots.js.map +1 -1
- package/build/codegen/targets/_shared/route-slots.test.js +99 -26
- package/build/codegen/targets/_shared/route-slots.test.js.map +1 -1
- package/build/codegen/targets/kotlin/emit-route-kotlin.test.js +88 -17
- package/build/codegen/targets/kotlin/emit-route-kotlin.test.js.map +1 -1
- package/build/codegen/targets/kotlin/emit-scope-kotlin.test.js +9 -6
- package/build/codegen/targets/kotlin/emit-scope-kotlin.test.js.map +1 -1
- package/build/codegen/targets/kotlin/integration.test.js +6 -0
- package/build/codegen/targets/kotlin/integration.test.js.map +1 -1
- package/build/codegen/targets/swift/access-level.test.js +8 -11
- package/build/codegen/targets/swift/access-level.test.js.map +1 -1
- package/build/codegen/targets/swift/emit-route-swift.test.js +91 -20
- package/build/codegen/targets/swift/emit-route-swift.test.js.map +1 -1
- package/build/codegen/targets/swift/emit-scope-swift.test.js +12 -9
- package/build/codegen/targets/swift/emit-scope-swift.test.js.map +1 -1
- package/build/codegen/targets/swift/integration.test.js +6 -0
- package/build/codegen/targets/swift/integration.test.js.map +1 -1
- package/build/create-http-stream.d.ts +58 -0
- package/build/create-http-stream.js +122 -0
- package/build/create-http-stream.js.map +1 -0
- package/build/create-http-stream.test.js +88 -0
- package/build/create-http-stream.test.js.map +1 -0
- package/build/create-http.d.ts +49 -0
- package/build/create-http.js +108 -0
- package/build/create-http.js.map +1 -0
- package/build/create-http.test.js +137 -0
- package/build/create-http.test.js.map +1 -0
- package/build/create-stream.d.ts +35 -0
- package/build/create-stream.js +123 -0
- package/build/create-stream.js.map +1 -0
- package/build/create-stream.test.js +428 -0
- package/build/create-stream.test.js.map +1 -0
- package/build/create.d.ts +28 -0
- package/build/create.js +82 -0
- package/build/create.js.map +1 -0
- package/build/create.test.js +483 -0
- package/build/create.test.js.map +1 -0
- package/build/exports.d.ts +2 -0
- package/build/implementations/http/astro/index.test.js +20 -12
- package/build/implementations/http/astro/index.test.js.map +1 -1
- package/build/implementations/http/doc-registry.js +1 -1
- package/build/implementations/http/doc-registry.js.map +1 -1
- package/build/implementations/http/doc-registry.test.js +36 -5
- package/build/implementations/http/doc-registry.test.js.map +1 -1
- package/build/implementations/http/error-dispatch.d.ts +76 -0
- package/build/implementations/http/error-dispatch.js +77 -0
- package/build/implementations/http/error-dispatch.js.map +1 -0
- package/build/implementations/http/error-dispatch.test.js +254 -0
- package/build/implementations/http/error-dispatch.test.js.map +1 -0
- package/build/implementations/http/error-taxonomy.d.ts +5 -5
- package/build/implementations/http/hono/docs/http-doc.d.ts +6 -0
- package/build/implementations/http/hono/docs/http-doc.js +42 -0
- package/build/implementations/http/hono/docs/http-doc.js.map +1 -0
- package/build/implementations/http/hono/docs/http-stream-doc.d.ts +6 -0
- package/build/implementations/http/hono/docs/http-stream-doc.js +40 -0
- package/build/implementations/http/hono/docs/http-stream-doc.js.map +1 -0
- package/build/implementations/http/hono/docs/rpc-doc.d.ts +6 -0
- package/build/implementations/http/hono/docs/rpc-doc.js +24 -0
- package/build/implementations/http/hono/docs/rpc-doc.js.map +1 -0
- package/build/implementations/http/hono/docs/stream-doc.d.ts +6 -0
- package/build/implementations/http/hono/docs/stream-doc.js +42 -0
- package/build/implementations/http/hono/docs/stream-doc.js.map +1 -0
- package/build/implementations/http/hono/handlers/http-stream.d.ts +10 -0
- package/build/implementations/http/hono/handlers/http-stream.js +123 -0
- package/build/implementations/http/hono/handlers/http-stream.js.map +1 -0
- package/build/implementations/http/hono/handlers/http-stream.test.js +128 -0
- package/build/implementations/http/hono/handlers/http-stream.test.js.map +1 -0
- package/build/implementations/http/hono/handlers/http.d.ts +10 -0
- package/build/implementations/http/hono/handlers/http.js +115 -0
- package/build/implementations/http/hono/handlers/http.js.map +1 -0
- package/build/implementations/http/hono/handlers/http.test.js +118 -0
- package/build/implementations/http/hono/handlers/http.test.js.map +1 -0
- package/build/implementations/http/hono/handlers/rpc.d.ts +11 -0
- package/build/implementations/http/hono/handlers/rpc.js +32 -0
- package/build/implementations/http/hono/handlers/rpc.js.map +1 -0
- package/build/implementations/http/hono/handlers/rpc.test.js +73 -0
- package/build/implementations/http/hono/handlers/rpc.test.js.map +1 -0
- package/build/implementations/http/hono/handlers/stream.d.ts +23 -0
- package/build/implementations/http/hono/handlers/stream.js +147 -0
- package/build/implementations/http/hono/handlers/stream.js.map +1 -0
- package/build/implementations/http/hono/handlers/stream.test.d.ts +1 -0
- package/build/implementations/http/hono/handlers/stream.test.js +177 -0
- package/build/implementations/http/hono/handlers/stream.test.js.map +1 -0
- package/build/implementations/http/hono/index.d.ts +57 -0
- package/build/implementations/http/hono/index.js +149 -0
- package/build/implementations/http/hono/index.js.map +1 -0
- package/build/implementations/http/hono/index.test.d.ts +1 -0
- package/build/implementations/http/hono/index.test.js +274 -0
- package/build/implementations/http/hono/index.test.js.map +1 -0
- package/build/implementations/http/hono/path.d.ts +17 -0
- package/build/implementations/http/hono/path.js +39 -0
- package/build/implementations/http/hono/path.js.map +1 -0
- package/build/implementations/http/hono/path.test.d.ts +1 -0
- package/build/implementations/http/hono/path.test.js +83 -0
- package/build/implementations/http/hono/path.test.js.map +1 -0
- package/build/implementations/http/hono/types.d.ts +51 -0
- package/build/implementations/http/hono/types.js.map +1 -0
- package/build/implementations/http/on-request-error.test.js +6 -96
- package/build/implementations/http/on-request-error.test.js.map +1 -1
- package/build/implementations/http/route-errors.test.js +11 -59
- package/build/implementations/http/route-errors.test.js.map +1 -1
- package/build/implementations/types.d.ts +43 -9
- package/build/index.d.ts +125 -115
- package/build/index.js +10 -222
- package/build/index.js.map +1 -1
- package/build/index.test.js +30 -822
- package/build/index.test.js.map +1 -1
- package/build/migration.test.d.ts +1 -0
- package/build/migration.test.js +34 -0
- package/build/migration.test.js.map +1 -0
- package/build/schema/compute-schema.d.ts +11 -3
- package/build/schema/compute-schema.js +13 -7
- package/build/schema/compute-schema.js.map +1 -1
- package/build/schema/parser.d.ts +11 -3
- package/build/schema/parser.js +49 -9
- package/build/schema/parser.js.map +1 -1
- package/build/stack-utils.js +8 -0
- package/build/stack-utils.js.map +1 -1
- package/build/types.d.ts +142 -0
- package/build/types.js.map +1 -0
- package/docs/astro-adapter.md +5 -5
- package/docs/core.md +34 -17
- package/docs/http-integrations.md +83 -170
- package/docs/streaming.md +3 -60
- package/docs/superpowers/plans/2026-05-07-astro-adapter.md +2 -7
- package/docs/superpowers/plans/2026-05-08-create-http.md +3355 -0
- package/docs/superpowers/plans/2026-05-08-hono-app-builder-convergence.md +3365 -0
- package/docs/superpowers/specs/2026-05-07-astro-adapter-design.md +1 -3
- package/docs/superpowers/specs/2026-05-08-create-http-design.md +409 -0
- package/docs/superpowers/specs/2026-05-08-hono-app-builder-convergence-design.md +411 -0
- package/package.json +4 -22
- package/src/client/call.test.ts +26 -0
- package/src/client/call.ts +4 -1
- package/src/client/fetch-adapter.test.ts +14 -1
- package/src/client/fetch-adapter.ts +3 -1
- package/src/client/index.test.ts +7 -7
- package/src/client/request-builder.ts +2 -2
- package/src/client/stream.test.ts +39 -7
- package/src/client/stream.ts +16 -2
- package/src/client/typed-error-dispatch.test.ts +7 -97
- package/src/client/types.ts +21 -3
- package/src/codegen/__fixtures__/users-envelope.json +119 -38
- package/src/codegen/e2e.test.ts +98 -24
- package/src/codegen/emit-errors.integration.test.ts +1 -1
- package/src/codegen/emit-scope.test.ts +395 -110
- package/src/codegen/emit-scope.ts +350 -55
- package/src/codegen/pipeline.test.ts +7 -7
- package/src/codegen/resolve-envelope.test.ts +5 -5
- package/src/codegen/resolve-envelope.ts +1 -1
- package/src/codegen/targets/_shared/route-slots.test.ts +109 -26
- package/src/codegen/targets/_shared/route-slots.ts +48 -11
- package/src/codegen/targets/kotlin/__fixtures__/users-golden.kt +73 -0
- package/src/codegen/targets/kotlin/emit-route-kotlin.test.ts +100 -17
- package/src/codegen/targets/kotlin/emit-scope-kotlin.test.ts +9 -6
- package/src/codegen/targets/kotlin/integration.test.ts +19 -0
- package/src/codegen/targets/swift/__fixtures__/users-golden.swift +79 -0
- package/src/codegen/targets/swift/access-level.test.ts +8 -11
- package/src/codegen/targets/swift/emit-route-swift.test.ts +103 -20
- package/src/codegen/targets/swift/emit-scope-swift.test.ts +12 -9
- package/src/codegen/targets/swift/integration.test.ts +17 -0
- package/src/create-http-stream.test.ts +97 -0
- package/src/create-http-stream.ts +191 -0
- package/src/create-http.test.ts +163 -0
- package/src/create-http.ts +211 -0
- package/src/create-stream.test.ts +565 -0
- package/src/create-stream.ts +228 -0
- package/src/create.test.ts +658 -0
- package/src/create.ts +172 -0
- package/src/exports.ts +2 -0
- package/src/implementations/http/README.md +135 -95
- package/src/implementations/http/astro/README.md +4 -5
- package/src/implementations/http/astro/index.test.ts +25 -18
- package/src/implementations/http/doc-registry.test.ts +42 -5
- package/src/implementations/http/doc-registry.ts +1 -1
- package/src/implementations/http/error-dispatch.test.ts +283 -0
- package/src/implementations/http/error-dispatch.ts +176 -0
- package/src/implementations/http/error-taxonomy.ts +5 -5
- package/src/implementations/http/hono/docs/http-doc.ts +43 -0
- package/src/implementations/http/hono/docs/http-stream-doc.ts +44 -0
- package/src/implementations/http/hono/docs/rpc-doc.ts +34 -0
- package/src/implementations/http/hono/docs/stream-doc.ts +53 -0
- package/src/implementations/http/hono/handlers/http-stream.test.ts +150 -0
- package/src/implementations/http/hono/handlers/http-stream.ts +152 -0
- package/src/implementations/http/hono/handlers/http.test.ts +130 -0
- package/src/implementations/http/hono/handlers/http.ts +147 -0
- package/src/implementations/http/hono/handlers/rpc.test.ts +81 -0
- package/src/implementations/http/hono/handlers/rpc.ts +54 -0
- package/src/implementations/http/hono/handlers/stream.test.ts +198 -0
- package/src/implementations/http/hono/handlers/stream.ts +208 -0
- package/src/implementations/http/hono/index.test.ts +329 -0
- package/src/implementations/http/hono/index.ts +204 -0
- package/src/implementations/http/hono/path.test.ts +96 -0
- package/src/implementations/http/hono/path.ts +59 -0
- package/src/implementations/http/hono/types.ts +93 -0
- package/src/implementations/http/on-request-error.test.ts +10 -116
- package/src/implementations/http/route-errors.test.ts +11 -77
- package/src/implementations/types.ts +44 -9
- package/src/index.test.ts +35 -1091
- package/src/index.ts +50 -474
- package/src/migration.test.ts +48 -0
- package/src/schema/compute-schema.ts +26 -12
- package/src/schema/parser.ts +62 -12
- package/src/stack-utils.ts +8 -0
- package/src/types.ts +133 -0
- package/agent_config/claude-code/skills/ts-procedures-scaffold/templates/express-rpc.md +0 -137
- package/agent_config/claude-code/skills/ts-procedures-scaffold/templates/hono-api.md +0 -173
- package/agent_config/claude-code/skills/ts-procedures-scaffold/templates/hono-rpc.md +0 -142
- package/agent_config/claude-code/skills/ts-procedures-scaffold/templates/hono-stream.md +0 -147
- package/build/implementations/http/express-rpc/error-taxonomy.test.js +0 -83
- package/build/implementations/http/express-rpc/error-taxonomy.test.js.map +0 -1
- package/build/implementations/http/express-rpc/index.d.ts +0 -125
- package/build/implementations/http/express-rpc/index.js +0 -216
- package/build/implementations/http/express-rpc/index.js.map +0 -1
- package/build/implementations/http/express-rpc/index.test.js +0 -684
- package/build/implementations/http/express-rpc/index.test.js.map +0 -1
- package/build/implementations/http/express-rpc/types.d.ts +0 -11
- package/build/implementations/http/express-rpc/types.js.map +0 -1
- package/build/implementations/http/hono-api/error-taxonomy.test.js +0 -137
- package/build/implementations/http/hono-api/error-taxonomy.test.js.map +0 -1
- package/build/implementations/http/hono-api/index.d.ts +0 -151
- package/build/implementations/http/hono-api/index.js +0 -344
- package/build/implementations/http/hono-api/index.js.map +0 -1
- package/build/implementations/http/hono-api/index.test.js +0 -992
- package/build/implementations/http/hono-api/index.test.js.map +0 -1
- package/build/implementations/http/hono-api/types.d.ts +0 -13
- package/build/implementations/http/hono-api/types.js.map +0 -1
- package/build/implementations/http/hono-rpc/error-taxonomy.test.js +0 -64
- package/build/implementations/http/hono-rpc/error-taxonomy.test.js.map +0 -1
- package/build/implementations/http/hono-rpc/index.d.ts +0 -130
- package/build/implementations/http/hono-rpc/index.js +0 -209
- package/build/implementations/http/hono-rpc/index.js.map +0 -1
- package/build/implementations/http/hono-rpc/index.test.js +0 -828
- package/build/implementations/http/hono-rpc/index.test.js.map +0 -1
- package/build/implementations/http/hono-rpc/types.d.ts +0 -11
- package/build/implementations/http/hono-rpc/types.js +0 -2
- package/build/implementations/http/hono-rpc/types.js.map +0 -1
- package/build/implementations/http/hono-stream/error-taxonomy.test.js +0 -159
- package/build/implementations/http/hono-stream/error-taxonomy.test.js.map +0 -1
- package/build/implementations/http/hono-stream/index.d.ts +0 -171
- package/build/implementations/http/hono-stream/index.js +0 -415
- package/build/implementations/http/hono-stream/index.js.map +0 -1
- package/build/implementations/http/hono-stream/index.test.js +0 -1383
- package/build/implementations/http/hono-stream/index.test.js.map +0 -1
- package/build/implementations/http/hono-stream/types.d.ts +0 -15
- package/build/implementations/http/hono-stream/types.js +0 -2
- package/build/implementations/http/hono-stream/types.js.map +0 -1
- package/src/implementations/http/express-rpc/README.md +0 -280
- package/src/implementations/http/express-rpc/error-taxonomy.test.ts +0 -103
- package/src/implementations/http/express-rpc/index.test.ts +0 -957
- package/src/implementations/http/express-rpc/index.ts +0 -327
- package/src/implementations/http/express-rpc/types.ts +0 -16
- package/src/implementations/http/hono-api/README.md +0 -284
- package/src/implementations/http/hono-api/error-taxonomy.test.ts +0 -179
- package/src/implementations/http/hono-api/index.test.ts +0 -1341
- package/src/implementations/http/hono-api/index.ts +0 -519
- package/src/implementations/http/hono-api/types.ts +0 -16
- package/src/implementations/http/hono-rpc/README.md +0 -357
- package/src/implementations/http/hono-rpc/error-taxonomy.test.ts +0 -82
- package/src/implementations/http/hono-rpc/index.test.ts +0 -1107
- package/src/implementations/http/hono-rpc/index.ts +0 -320
- package/src/implementations/http/hono-rpc/types.ts +0 -16
- package/src/implementations/http/hono-stream/README.md +0 -559
- package/src/implementations/http/hono-stream/error-taxonomy.test.ts +0 -178
- package/src/implementations/http/hono-stream/index.test.ts +0 -1804
- package/src/implementations/http/hono-stream/index.ts +0 -622
- package/src/implementations/http/hono-stream/types.ts +0 -20
- /package/build/{implementations/http/express-rpc/error-taxonomy.test.d.ts → create-http-stream.test.d.ts} +0 -0
- /package/build/{implementations/http/express-rpc/index.test.d.ts → create-http.test.d.ts} +0 -0
- /package/build/{implementations/http/hono-api/error-taxonomy.test.d.ts → create-stream.test.d.ts} +0 -0
- /package/build/{implementations/http/hono-api/index.test.d.ts → create.test.d.ts} +0 -0
- /package/build/implementations/http/{hono-rpc/error-taxonomy.test.d.ts → error-dispatch.test.d.ts} +0 -0
- /package/build/implementations/http/{hono-rpc/index.test.d.ts → hono/handlers/http-stream.test.d.ts} +0 -0
- /package/build/implementations/http/{hono-stream/error-taxonomy.test.d.ts → hono/handlers/http.test.d.ts} +0 -0
- /package/build/implementations/http/{hono-stream/index.test.d.ts → hono/handlers/rpc.test.d.ts} +0 -0
- /package/build/implementations/http/{express-rpc → hono}/types.js +0 -0
- /package/build/{implementations/http/hono-api/types.js → types.js} +0 -0
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { ProcedureError, ProcedureRegistrationError, ProcedureValidationError, ProcedureYieldValidationError } from './errors.js'
|
|
2
|
+
import { computeSchema } from './schema/compute-schema.js'
|
|
3
|
+
import { Prettify, TSchemaLib } from './schema/types.js'
|
|
4
|
+
import { captureDefinitionInfo } from './stack-utils.js'
|
|
5
|
+
import {
|
|
6
|
+
TBuilderConfig,
|
|
7
|
+
THttpProcedureRegistration,
|
|
8
|
+
THttpStreamProcedureRegistration,
|
|
9
|
+
TStreamContext,
|
|
10
|
+
TProcedureRegistration,
|
|
11
|
+
TStreamProcedureRegistration,
|
|
12
|
+
} from './types.js'
|
|
13
|
+
|
|
14
|
+
export type CreateStreamBuilderArg<TContext, TExtendedConfig> = {
|
|
15
|
+
config?: TBuilderConfig
|
|
16
|
+
onCreate?: (
|
|
17
|
+
procedure:
|
|
18
|
+
| TProcedureRegistration<TContext, TExtendedConfig>
|
|
19
|
+
| TStreamProcedureRegistration<TContext, TExtendedConfig>
|
|
20
|
+
) => void
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function makeCreateStream<TContext, TExtendedConfig>(
|
|
24
|
+
procedures: Map<
|
|
25
|
+
string,
|
|
26
|
+
| TProcedureRegistration<TContext, TExtendedConfig>
|
|
27
|
+
| TStreamProcedureRegistration<TContext, TExtendedConfig>
|
|
28
|
+
| THttpProcedureRegistration<TContext>
|
|
29
|
+
| THttpStreamProcedureRegistration<TContext>
|
|
30
|
+
>,
|
|
31
|
+
builder?: CreateStreamBuilderArg<TContext, TExtendedConfig>
|
|
32
|
+
) {
|
|
33
|
+
return function CreateStream<TName extends string, TParams, TYieldType, TReturnType = void>(
|
|
34
|
+
name: TName,
|
|
35
|
+
config: {
|
|
36
|
+
description?: string
|
|
37
|
+
schema?: {
|
|
38
|
+
params?: TParams
|
|
39
|
+
yieldType?: TYieldType
|
|
40
|
+
returnType?: TReturnType
|
|
41
|
+
}
|
|
42
|
+
validateYields?: boolean
|
|
43
|
+
} & TExtendedConfig,
|
|
44
|
+
handler: (
|
|
45
|
+
ctx: Prettify<TContext & TStreamContext>,
|
|
46
|
+
params: TSchemaLib<TParams>
|
|
47
|
+
) => AsyncGenerator<TSchemaLib<TYieldType>, TSchemaLib<TReturnType> | void, unknown>
|
|
48
|
+
) {
|
|
49
|
+
// Capture definition location as first action
|
|
50
|
+
const definitionInfo = captureDefinitionInfo()
|
|
51
|
+
|
|
52
|
+
const HTTP_FIELDS = ['path', 'method', 'req', 'res', 'successStatus'] as const
|
|
53
|
+
const presentHttpFields = HTTP_FIELDS.filter((f) => (config as any)[f] !== undefined)
|
|
54
|
+
if (presentHttpFields.length > 0) {
|
|
55
|
+
throw new ProcedureRegistrationError(
|
|
56
|
+
name,
|
|
57
|
+
`HTTP fields require CreateHttp / CreateHttpStream. Procedure "${name}" has [${presentHttpFields.join(', ')}] which are not valid on CreateStream.`,
|
|
58
|
+
definitionInfo,
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// BEFORE computeSchema - fail fast on duplicate
|
|
63
|
+
if (procedures.has(name)) {
|
|
64
|
+
throw new Error(`Procedure with name ${name} is already registered`)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const { jsonSchema, validations } = computeSchema(name, config.schema, definitionInfo)
|
|
68
|
+
|
|
69
|
+
// Create error factory once at registration time (outside handler)
|
|
70
|
+
const errorFactory = (message: string, meta?: object) => {
|
|
71
|
+
return new ProcedureError(name, message, meta, definitionInfo)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const validateYields = config.validateYields ?? false
|
|
75
|
+
|
|
76
|
+
const registeredProcedure: TStreamProcedureRegistration<TContext, TExtendedConfig> = {
|
|
77
|
+
name,
|
|
78
|
+
kind: 'rpc-stream',
|
|
79
|
+
isStream: true,
|
|
80
|
+
config: {
|
|
81
|
+
...config,
|
|
82
|
+
description: config.description,
|
|
83
|
+
schema: jsonSchema,
|
|
84
|
+
validation: {
|
|
85
|
+
params: validations.params,
|
|
86
|
+
yield: validations.yield,
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
handler: async function* wrappedHandler(
|
|
91
|
+
ctx: Prettify<TContext>,
|
|
92
|
+
params: TSchemaLib<TParams>
|
|
93
|
+
) {
|
|
94
|
+
// Create abort controller for this stream
|
|
95
|
+
const abortController = new AbortController()
|
|
96
|
+
|
|
97
|
+
// Skip validation if caller has already validated (e.g., HonoAppBuilder) or if builder config dictates noRuntimeValidation
|
|
98
|
+
const skipValidation =
|
|
99
|
+
(ctx as { isPrevalidated?: boolean }).isPrevalidated ||
|
|
100
|
+
builder?.config?.noRuntimeValidation
|
|
101
|
+
|
|
102
|
+
if (validations?.params && !skipValidation) {
|
|
103
|
+
const { errors } = validations.params(params)
|
|
104
|
+
|
|
105
|
+
if (errors) {
|
|
106
|
+
throw new ProcedureValidationError(
|
|
107
|
+
name,
|
|
108
|
+
`Validation error for ${name}`,
|
|
109
|
+
errors,
|
|
110
|
+
definitionInfo
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Combine with external signal (e.g., from HTTP request) if provided
|
|
116
|
+
const incomingSignal = (ctx as { signal?: AbortSignal }).signal
|
|
117
|
+
const signal = incomingSignal
|
|
118
|
+
? AbortSignal.any([incomingSignal, abortController.signal])
|
|
119
|
+
: abortController.signal
|
|
120
|
+
|
|
121
|
+
const streamCtx: TStreamContext = {
|
|
122
|
+
error: errorFactory,
|
|
123
|
+
signal,
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// params is correctly typed at the public API boundary via conditional type;
|
|
127
|
+
// cast here because TS cannot narrow conditional generics inside implementations
|
|
128
|
+
const userGenerator = handler(
|
|
129
|
+
{
|
|
130
|
+
...ctx,
|
|
131
|
+
...streamCtx,
|
|
132
|
+
} as Prettify<TContext & TStreamContext>,
|
|
133
|
+
params as any
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
const userIterator = userGenerator[Symbol.asyncIterator]()
|
|
137
|
+
try {
|
|
138
|
+
let userIterResult = await userIterator.next()
|
|
139
|
+
|
|
140
|
+
while (!userIterResult.done) {
|
|
141
|
+
const value = userIterResult.value
|
|
142
|
+
|
|
143
|
+
// Only validate if explicitly enabled via validateYields: true
|
|
144
|
+
if (validateYields && validations.yield) {
|
|
145
|
+
const { errors } = validations.yield(value)
|
|
146
|
+
if (errors) {
|
|
147
|
+
throw new ProcedureYieldValidationError(
|
|
148
|
+
name,
|
|
149
|
+
`Yield validation error for ${name}`,
|
|
150
|
+
errors,
|
|
151
|
+
definitionInfo
|
|
152
|
+
)
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
yield value
|
|
157
|
+
userIterResult = await userIterator.next()
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Propagate the generator's return value so consumers (e.g. HonoAppBuilder)
|
|
161
|
+
// can send it as a special 'return' SSE event
|
|
162
|
+
return userIterResult.value
|
|
163
|
+
} catch (error: any) {
|
|
164
|
+
// Preserve the original error class so HTTP builders' taxonomies and
|
|
165
|
+
// `onMidStreamError` callbacks see the actual thrown type — boxing
|
|
166
|
+
// user-defined errors inside ProcedureError defeats route-declared
|
|
167
|
+
// typed-error dispatch on the client. Augment the stack trace in
|
|
168
|
+
// place with the procedure's definition site when available.
|
|
169
|
+
if (definitionInfo.definedAt && error && typeof error.stack === 'string') {
|
|
170
|
+
const { file, line, column } = definitionInfo.definedAt
|
|
171
|
+
error.stack = `${error.stack}\n--- Procedure "${name}" defined at ---\n at ${file}:${line}:${column}`
|
|
172
|
+
}
|
|
173
|
+
throw error
|
|
174
|
+
} finally {
|
|
175
|
+
// Propagate `.return()` to the user generator so its `finally`
|
|
176
|
+
// blocks (and any `signal`-driven cleanup) run when the consumer
|
|
177
|
+
// closes the stream early. No-op when iteration already completed.
|
|
178
|
+
try {
|
|
179
|
+
await userIterator.return?.(undefined)
|
|
180
|
+
} catch {
|
|
181
|
+
// Swallow — cleanup must not mask the primary error path
|
|
182
|
+
}
|
|
183
|
+
abortController.abort('stream-completed')
|
|
184
|
+
}
|
|
185
|
+
} as (ctx: TContext, params?: any) => AsyncGenerator<any, any, unknown>,
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
procedures.set(name, registeredProcedure)
|
|
189
|
+
builder?.onCreate?.(registeredProcedure)
|
|
190
|
+
|
|
191
|
+
const info = {
|
|
192
|
+
name,
|
|
193
|
+
isStream: true as const,
|
|
194
|
+
...registeredProcedure.config,
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// return so can be called directly (ie: int/unit tests)
|
|
198
|
+
return {
|
|
199
|
+
[name]: registeredProcedure.handler,
|
|
200
|
+
procedure: registeredProcedure.handler,
|
|
201
|
+
info,
|
|
202
|
+
} as {
|
|
203
|
+
[K in TName]: (
|
|
204
|
+
ctx: Prettify<TContext>,
|
|
205
|
+
params: TSchemaLib<TParams>
|
|
206
|
+
) => AsyncGenerator<TSchemaLib<TYieldType>, TSchemaLib<TReturnType> | void, unknown>
|
|
207
|
+
} & {
|
|
208
|
+
procedure: (
|
|
209
|
+
ctx: Prettify<TContext>,
|
|
210
|
+
params: TSchemaLib<TParams>
|
|
211
|
+
) => AsyncGenerator<TSchemaLib<TYieldType>, TSchemaLib<TReturnType> | void, unknown>
|
|
212
|
+
info: {
|
|
213
|
+
name: TName
|
|
214
|
+
isStream: true
|
|
215
|
+
description?: string
|
|
216
|
+
schema: {
|
|
217
|
+
params?: TParams
|
|
218
|
+
yieldType?: TYieldType
|
|
219
|
+
returnType?: TReturnType
|
|
220
|
+
}
|
|
221
|
+
validation?: {
|
|
222
|
+
params?: (params: any) => { errors?: any[] }
|
|
223
|
+
yield?: (value: any) => { errors?: any[] }
|
|
224
|
+
}
|
|
225
|
+
} & TExtendedConfig
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|