ts-procedures 5.9.1 → 5.10.2
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 +1 -1
- package/agent_config/bin/postinstall.mjs +3 -3
- package/agent_config/bin/setup.mjs +22 -11
- package/agent_config/claude-code/agents/ts-procedures-architect.md +46 -101
- package/agent_config/claude-code/skills/{guide → ts-procedures}/SKILL.md +50 -35
- package/agent_config/claude-code/skills/{guide → ts-procedures}/anti-patterns.md +6 -5
- package/agent_config/claude-code/skills/{guide → ts-procedures}/api-reference.md +60 -49
- package/agent_config/claude-code/skills/ts-procedures-review/SKILL.md +48 -0
- package/agent_config/claude-code/skills/{scaffold → ts-procedures-scaffold}/SKILL.md +19 -24
- package/agent_config/claude-code/skills/ts-procedures-scaffold/templates/client.md +115 -0
- package/agent_config/lib/install-claude.mjs +35 -87
- package/build/src/client/call.d.ts +14 -0
- package/build/src/client/call.js +47 -0
- package/build/src/client/call.js.map +1 -0
- package/build/src/client/call.test.d.ts +1 -0
- package/build/src/client/call.test.js +124 -0
- package/build/src/client/call.test.js.map +1 -0
- package/build/src/client/errors.d.ts +25 -0
- package/build/src/client/errors.js +33 -0
- package/build/src/client/errors.js.map +1 -0
- package/build/src/client/errors.test.d.ts +1 -0
- package/build/src/client/errors.test.js +41 -0
- package/build/src/client/errors.test.js.map +1 -0
- package/build/src/client/fetch-adapter.d.ts +12 -0
- package/build/src/client/fetch-adapter.js +156 -0
- package/build/src/client/fetch-adapter.js.map +1 -0
- package/build/src/client/fetch-adapter.test.d.ts +1 -0
- package/build/src/client/fetch-adapter.test.js +271 -0
- package/build/src/client/fetch-adapter.test.js.map +1 -0
- package/build/src/client/hooks.d.ts +17 -0
- package/build/src/client/hooks.js +40 -0
- package/build/src/client/hooks.js.map +1 -0
- package/build/src/client/hooks.test.d.ts +1 -0
- package/build/src/client/hooks.test.js +163 -0
- package/build/src/client/hooks.test.js.map +1 -0
- package/build/src/client/index.d.ts +22 -0
- package/build/src/client/index.js +67 -0
- package/build/src/client/index.js.map +1 -0
- package/build/src/client/index.test.d.ts +1 -0
- package/build/src/client/index.test.js +231 -0
- package/build/src/client/index.test.js.map +1 -0
- package/build/src/client/request-builder.d.ts +13 -0
- package/build/src/client/request-builder.js +53 -0
- package/build/src/client/request-builder.js.map +1 -0
- package/build/src/client/request-builder.test.d.ts +1 -0
- package/build/src/client/request-builder.test.js +160 -0
- package/build/src/client/request-builder.test.js.map +1 -0
- package/build/src/client/stream.d.ts +27 -0
- package/build/src/client/stream.js +118 -0
- package/build/src/client/stream.js.map +1 -0
- package/build/src/client/stream.test.d.ts +1 -0
- package/build/src/client/stream.test.js +228 -0
- package/build/src/client/stream.test.js.map +1 -0
- package/build/src/client/types.d.ts +78 -0
- package/build/src/client/types.js +3 -0
- package/build/src/client/types.js.map +1 -0
- package/build/src/codegen/bin/cli.d.ts +45 -0
- package/build/src/codegen/bin/cli.js +246 -0
- package/build/src/codegen/bin/cli.js.map +1 -0
- package/build/src/codegen/bin/cli.test.d.ts +1 -0
- package/build/src/codegen/bin/cli.test.js +220 -0
- package/build/src/codegen/bin/cli.test.js.map +1 -0
- package/build/src/codegen/constants.d.ts +1 -0
- package/build/src/codegen/constants.js +2 -0
- package/build/src/codegen/constants.js.map +1 -0
- package/build/src/codegen/e2e.test.d.ts +1 -0
- package/build/src/codegen/e2e.test.js +464 -0
- package/build/src/codegen/e2e.test.js.map +1 -0
- package/build/src/codegen/emit-client-runtime.d.ts +9 -0
- package/build/src/codegen/emit-client-runtime.js +99 -0
- package/build/src/codegen/emit-client-runtime.js.map +1 -0
- package/build/src/codegen/emit-client-runtime.test.d.ts +1 -0
- package/build/src/codegen/emit-client-runtime.test.js +78 -0
- package/build/src/codegen/emit-client-runtime.test.js.map +1 -0
- package/build/src/codegen/emit-client-types.d.ts +8 -0
- package/build/src/codegen/emit-client-types.js +25 -0
- package/build/src/codegen/emit-client-types.js.map +1 -0
- package/build/src/codegen/emit-client-types.test.d.ts +1 -0
- package/build/src/codegen/emit-client-types.test.js +33 -0
- package/build/src/codegen/emit-client-types.test.js.map +1 -0
- package/build/src/codegen/emit-errors.d.ts +19 -0
- package/build/src/codegen/emit-errors.js +59 -0
- package/build/src/codegen/emit-errors.js.map +1 -0
- package/build/src/codegen/emit-errors.test.d.ts +1 -0
- package/build/src/codegen/emit-errors.test.js +175 -0
- package/build/src/codegen/emit-errors.test.js.map +1 -0
- package/build/src/codegen/emit-index.d.ts +12 -0
- package/build/src/codegen/emit-index.js +41 -0
- package/build/src/codegen/emit-index.js.map +1 -0
- package/build/src/codegen/emit-index.test.d.ts +1 -0
- package/build/src/codegen/emit-index.test.js +106 -0
- package/build/src/codegen/emit-index.test.js.map +1 -0
- package/build/src/codegen/emit-scope.d.ts +15 -0
- package/build/src/codegen/emit-scope.js +299 -0
- package/build/src/codegen/emit-scope.js.map +1 -0
- package/build/src/codegen/emit-scope.test.d.ts +1 -0
- package/build/src/codegen/emit-scope.test.js +559 -0
- package/build/src/codegen/emit-scope.test.js.map +1 -0
- package/build/src/codegen/emit-types.d.ts +43 -0
- package/build/src/codegen/emit-types.js +111 -0
- package/build/src/codegen/emit-types.js.map +1 -0
- package/build/src/codegen/emit-types.test.d.ts +1 -0
- package/build/src/codegen/emit-types.test.js +184 -0
- package/build/src/codegen/emit-types.test.js.map +1 -0
- package/build/src/codegen/group-routes.d.ts +23 -0
- package/build/src/codegen/group-routes.js +46 -0
- package/build/src/codegen/group-routes.js.map +1 -0
- package/build/src/codegen/group-routes.test.d.ts +1 -0
- package/build/src/codegen/group-routes.test.js +131 -0
- package/build/src/codegen/group-routes.test.js.map +1 -0
- package/build/src/codegen/index.d.ts +15 -0
- package/build/src/codegen/index.js +16 -0
- package/build/src/codegen/index.js.map +1 -0
- package/build/src/codegen/naming.d.ts +7 -0
- package/build/src/codegen/naming.js +21 -0
- package/build/src/codegen/naming.js.map +1 -0
- package/build/src/codegen/naming.test.d.ts +1 -0
- package/build/src/codegen/naming.test.js +40 -0
- package/build/src/codegen/naming.test.js.map +1 -0
- package/build/src/codegen/pipeline.d.ts +17 -0
- package/build/src/codegen/pipeline.js +78 -0
- package/build/src/codegen/pipeline.js.map +1 -0
- package/build/src/codegen/pipeline.test.d.ts +1 -0
- package/build/src/codegen/pipeline.test.js +269 -0
- package/build/src/codegen/pipeline.test.js.map +1 -0
- package/build/src/codegen/resolve-envelope.d.ts +7 -0
- package/build/src/codegen/resolve-envelope.js +46 -0
- package/build/src/codegen/resolve-envelope.js.map +1 -0
- package/build/src/codegen/resolve-envelope.test.d.ts +1 -0
- package/build/src/codegen/resolve-envelope.test.js +69 -0
- package/build/src/codegen/resolve-envelope.test.js.map +1 -0
- package/build/src/errors.d.ts +33 -0
- package/build/src/errors.js +91 -0
- package/build/src/errors.js.map +1 -0
- package/build/src/errors.test.d.ts +1 -0
- package/build/src/errors.test.js +122 -0
- package/build/src/errors.test.js.map +1 -0
- package/build/src/exports.d.ts +7 -0
- package/build/src/exports.js +8 -0
- package/build/src/exports.js.map +1 -0
- package/build/src/implementations/http/doc-registry.d.ts +12 -0
- package/build/src/implementations/http/doc-registry.js +114 -0
- package/build/src/implementations/http/doc-registry.js.map +1 -0
- package/build/src/implementations/http/doc-registry.test.d.ts +1 -0
- package/build/src/implementations/http/doc-registry.test.js +347 -0
- package/build/src/implementations/http/doc-registry.test.js.map +1 -0
- package/build/src/implementations/http/express-rpc/index.d.ts +94 -0
- package/build/src/implementations/http/express-rpc/index.js +185 -0
- package/build/src/implementations/http/express-rpc/index.js.map +1 -0
- package/build/src/implementations/http/express-rpc/index.test.d.ts +1 -0
- package/build/src/implementations/http/express-rpc/index.test.js +684 -0
- package/build/src/implementations/http/express-rpc/index.test.js.map +1 -0
- package/build/src/implementations/http/express-rpc/types.d.ts +11 -0
- package/build/src/implementations/http/express-rpc/types.js +2 -0
- package/build/src/implementations/http/express-rpc/types.js.map +1 -0
- package/build/src/implementations/http/hono-api/index.d.ts +102 -0
- package/build/src/implementations/http/hono-api/index.js +341 -0
- package/build/src/implementations/http/hono-api/index.js.map +1 -0
- package/build/src/implementations/http/hono-api/index.test.d.ts +1 -0
- package/build/src/implementations/http/hono-api/index.test.js +992 -0
- package/build/src/implementations/http/hono-api/index.test.js.map +1 -0
- package/build/src/implementations/http/hono-api/types.d.ts +13 -0
- package/build/src/implementations/http/hono-api/types.js +2 -0
- package/build/src/implementations/http/hono-api/types.js.map +1 -0
- package/build/src/implementations/http/hono-rpc/index.d.ts +92 -0
- package/build/src/implementations/http/hono-rpc/index.js +161 -0
- package/build/src/implementations/http/hono-rpc/index.js.map +1 -0
- package/build/src/implementations/http/hono-rpc/index.test.d.ts +1 -0
- package/build/src/implementations/http/hono-rpc/index.test.js +803 -0
- package/build/src/implementations/http/hono-rpc/index.test.js.map +1 -0
- package/build/src/implementations/http/hono-rpc/types.d.ts +11 -0
- package/build/src/implementations/http/hono-rpc/types.js +2 -0
- package/build/src/implementations/http/hono-rpc/types.js.map +1 -0
- package/build/src/implementations/http/hono-stream/index.d.ts +120 -0
- package/build/src/implementations/http/hono-stream/index.js +309 -0
- package/build/src/implementations/http/hono-stream/index.js.map +1 -0
- package/build/src/implementations/http/hono-stream/index.test.d.ts +1 -0
- package/build/src/implementations/http/hono-stream/index.test.js +1356 -0
- package/build/src/implementations/http/hono-stream/index.test.js.map +1 -0
- package/build/src/implementations/http/hono-stream/types.d.ts +15 -0
- package/build/src/implementations/http/hono-stream/types.js +2 -0
- package/build/src/implementations/http/hono-stream/types.js.map +1 -0
- package/build/src/implementations/types.d.ts +142 -0
- package/build/src/implementations/types.js +2 -0
- package/build/src/implementations/types.js.map +1 -0
- package/build/src/index.d.ts +165 -0
- package/build/src/index.js +253 -0
- package/build/src/index.js.map +1 -0
- package/build/src/index.test.d.ts +1 -0
- package/build/src/index.test.js +890 -0
- package/build/src/index.test.js.map +1 -0
- package/build/src/schema/compute-schema.d.ts +35 -0
- package/build/src/schema/compute-schema.js +41 -0
- package/build/src/schema/compute-schema.js.map +1 -0
- package/build/src/schema/compute-schema.test.d.ts +1 -0
- package/build/src/schema/compute-schema.test.js +107 -0
- package/build/src/schema/compute-schema.test.js.map +1 -0
- package/build/src/schema/extract-json-schema.d.ts +2 -0
- package/build/src/schema/extract-json-schema.js +12 -0
- package/build/src/schema/extract-json-schema.js.map +1 -0
- package/build/src/schema/extract-json-schema.test.d.ts +1 -0
- package/build/src/schema/extract-json-schema.test.js +23 -0
- package/build/src/schema/extract-json-schema.test.js.map +1 -0
- package/build/src/schema/parser.d.ts +28 -0
- package/build/src/schema/parser.js +170 -0
- package/build/src/schema/parser.js.map +1 -0
- package/build/src/schema/parser.test.d.ts +1 -0
- package/build/src/schema/parser.test.js +120 -0
- package/build/src/schema/parser.test.js.map +1 -0
- package/build/src/schema/resolve-schema-lib.d.ts +12 -0
- package/build/src/schema/resolve-schema-lib.js +11 -0
- package/build/src/schema/resolve-schema-lib.js.map +1 -0
- package/build/src/schema/resolve-schema-lib.test.d.ts +1 -0
- package/build/src/schema/resolve-schema-lib.test.js +17 -0
- package/build/src/schema/resolve-schema-lib.test.js.map +1 -0
- package/build/src/schema/types.d.ts +8 -0
- package/build/src/schema/types.js +2 -0
- package/build/src/schema/types.js.map +1 -0
- package/build/src/stack-utils.d.ts +25 -0
- package/build/src/stack-utils.js +95 -0
- package/build/src/stack-utils.js.map +1 -0
- package/build/src/stack-utils.test.d.ts +1 -0
- package/build/src/stack-utils.test.js +80 -0
- package/build/src/stack-utils.test.js.map +1 -0
- package/docs/ai-agent-setup.md +7 -6
- package/docs/core.md +5 -9
- package/docs/streaming.md +9 -9
- package/package.json +2 -13
- package/src/client/call.test.ts +162 -0
- package/src/client/errors.test.ts +43 -0
- package/src/client/fetch-adapter.test.ts +340 -0
- package/src/client/hooks.test.ts +191 -0
- package/src/client/index.test.ts +290 -0
- package/src/client/request-builder.test.ts +184 -0
- package/src/client/stream.test.ts +331 -0
- package/src/codegen/bin/cli.test.ts +260 -0
- package/src/codegen/bin/cli.ts +282 -0
- package/src/codegen/constants.ts +1 -0
- package/src/codegen/e2e.test.ts +565 -0
- package/src/codegen/emit-client-runtime.test.ts +93 -0
- package/src/codegen/emit-client-runtime.ts +114 -0
- package/src/codegen/emit-client-types.test.ts +39 -0
- package/src/codegen/emit-client-types.ts +27 -0
- package/src/codegen/emit-errors.test.ts +202 -0
- package/src/codegen/emit-errors.ts +80 -0
- package/src/codegen/emit-index.test.ts +127 -0
- package/src/codegen/emit-index.ts +58 -0
- package/src/codegen/emit-scope.test.ts +624 -0
- package/src/codegen/emit-scope.ts +389 -0
- package/src/codegen/emit-types.test.ts +205 -0
- package/src/codegen/emit-types.ts +158 -0
- package/src/codegen/group-routes.test.ts +159 -0
- package/src/codegen/group-routes.ts +61 -0
- package/src/codegen/index.ts +30 -0
- package/src/codegen/naming.test.ts +50 -0
- package/src/codegen/naming.ts +25 -0
- package/src/codegen/pipeline.test.ts +316 -0
- package/src/codegen/pipeline.ts +108 -0
- package/src/codegen/resolve-envelope.test.ts +76 -0
- package/src/codegen/resolve-envelope.ts +61 -0
- package/src/errors.test.ts +163 -0
- package/src/errors.ts +107 -0
- package/src/exports.ts +7 -0
- package/src/implementations/http/doc-registry.test.ts +415 -0
- package/src/implementations/http/doc-registry.ts +143 -0
- package/src/implementations/http/express-rpc/README.md +6 -6
- package/src/implementations/http/express-rpc/index.test.ts +957 -0
- package/src/implementations/http/express-rpc/index.ts +266 -0
- package/src/implementations/http/express-rpc/types.ts +16 -0
- package/src/implementations/http/hono-api/index.test.ts +1341 -0
- package/src/implementations/http/hono-api/index.ts +463 -0
- package/src/implementations/http/hono-api/types.ts +16 -0
- package/src/implementations/http/hono-rpc/README.md +6 -6
- package/src/implementations/http/hono-rpc/index.test.ts +1075 -0
- package/src/implementations/http/hono-rpc/index.ts +238 -0
- package/src/implementations/http/hono-rpc/types.ts +16 -0
- package/src/implementations/http/hono-stream/README.md +12 -12
- package/src/implementations/http/hono-stream/index.test.ts +1768 -0
- package/src/implementations/http/hono-stream/index.ts +456 -0
- package/src/implementations/http/hono-stream/types.ts +20 -0
- package/src/implementations/types.ts +174 -0
- package/src/index.test.ts +1185 -0
- package/src/index.ts +522 -0
- package/src/schema/compute-schema.test.ts +128 -0
- package/src/schema/compute-schema.ts +88 -0
- package/src/schema/extract-json-schema.test.ts +25 -0
- package/src/schema/extract-json-schema.ts +15 -0
- package/src/schema/parser.test.ts +182 -0
- package/src/schema/parser.ts +215 -0
- package/src/schema/resolve-schema-lib.test.ts +19 -0
- package/src/schema/resolve-schema-lib.ts +29 -0
- package/src/schema/types.ts +20 -0
- package/src/stack-utils.test.ts +94 -0
- package/src/stack-utils.ts +129 -0
- package/agent_config/claude-code/skills/review/SKILL.md +0 -53
- package/docs/superpowers/plans/2026-03-30-client-codegen.md +0 -2833
- package/docs/superpowers/specs/2026-03-30-client-codegen-design.md +0 -632
- /package/agent_config/claude-code/skills/{guide → ts-procedures}/patterns.md +0 -0
- /package/agent_config/claude-code/skills/{review → ts-procedures-review}/checklist.md +0 -0
- /package/agent_config/claude-code/skills/{scaffold → ts-procedures-scaffold}/templates/express-rpc.md +0 -0
- /package/agent_config/claude-code/skills/{scaffold → ts-procedures-scaffold}/templates/hono-api.md +0 -0
- /package/agent_config/claude-code/skills/{scaffold → ts-procedures-scaffold}/templates/hono-rpc.md +0 -0
- /package/agent_config/claude-code/skills/{scaffold → ts-procedures-scaffold}/templates/hono-stream.md +0 -0
- /package/agent_config/claude-code/skills/{scaffold → ts-procedures-scaffold}/templates/procedure.md +0 -0
- /package/agent_config/claude-code/skills/{scaffold → ts-procedures-scaffold}/templates/stream-procedure.md +0 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,522 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ProcedureError,
|
|
3
|
+
ProcedureValidationError,
|
|
4
|
+
ProcedureYieldValidationError,
|
|
5
|
+
} from './errors.js'
|
|
6
|
+
import { computeSchema } from './schema/compute-schema.js'
|
|
7
|
+
import { Prettify, TJSONSchema, TSchemaLib } from './schema/types.js'
|
|
8
|
+
import { captureDefinitionInfo } from './stack-utils.js'
|
|
9
|
+
|
|
10
|
+
export type TNoContextProvided = unknown
|
|
11
|
+
|
|
12
|
+
export type TLocalContext = {
|
|
13
|
+
error: (message: string, meta?: object) => ProcedureError
|
|
14
|
+
signal?: AbortSignal
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type TStreamContext = TLocalContext & {
|
|
18
|
+
signal: AbortSignal
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type TProcedureRegistration<TContext = unknown, TExtendedConfig = unknown> = {
|
|
22
|
+
name: string
|
|
23
|
+
isStream?: false
|
|
24
|
+
config: {
|
|
25
|
+
description?: string
|
|
26
|
+
schema?: {
|
|
27
|
+
params?: TJSONSchema
|
|
28
|
+
returnType?: TJSONSchema
|
|
29
|
+
input?: Record<string, TJSONSchema>
|
|
30
|
+
}
|
|
31
|
+
validation?: {
|
|
32
|
+
params?: (params: any) => { errors?: any[] }
|
|
33
|
+
input?: Record<string, (value: any) => { errors?: any[] }>
|
|
34
|
+
}
|
|
35
|
+
} & TExtendedConfig
|
|
36
|
+
|
|
37
|
+
handler: (ctx: TContext, params?: any) => Promise<any>
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type TStreamProcedureRegistration<TContext = unknown, TExtendedConfig = unknown> = {
|
|
41
|
+
name: string
|
|
42
|
+
isStream: true
|
|
43
|
+
config: {
|
|
44
|
+
description?: string
|
|
45
|
+
schema?: {
|
|
46
|
+
params?: TJSONSchema
|
|
47
|
+
yieldType?: TJSONSchema
|
|
48
|
+
returnType?: TJSONSchema
|
|
49
|
+
input?: Record<string, TJSONSchema>
|
|
50
|
+
}
|
|
51
|
+
validation?: {
|
|
52
|
+
params?: (params: any) => { errors?: any[] }
|
|
53
|
+
yield?: (value: any) => { errors?: any[] }
|
|
54
|
+
input?: Record<string, (value: any) => { errors?: any[] }>
|
|
55
|
+
}
|
|
56
|
+
} & TExtendedConfig
|
|
57
|
+
|
|
58
|
+
handler: (ctx: TContext, params?: any) => AsyncGenerator<any, any, unknown>
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function Procedures<TContext = TNoContextProvided, TExtendedConfig = unknown>(
|
|
62
|
+
/**
|
|
63
|
+
* Optionally provided builder to register Procedures
|
|
64
|
+
*/
|
|
65
|
+
builder?: {
|
|
66
|
+
onCreate?: (
|
|
67
|
+
procedure: Prettify<{
|
|
68
|
+
name: string
|
|
69
|
+
isStream?: boolean
|
|
70
|
+
handler:
|
|
71
|
+
| ((ctx: Prettify<TContext>, params?: any) => Promise<any>)
|
|
72
|
+
| ((ctx: Prettify<TContext>, params?: any) => AsyncGenerator<any, any, unknown>)
|
|
73
|
+
config: Prettify<
|
|
74
|
+
{
|
|
75
|
+
description?: string
|
|
76
|
+
schema?: {
|
|
77
|
+
params?: TJSONSchema
|
|
78
|
+
yieldType?: TJSONSchema
|
|
79
|
+
returnType?: TJSONSchema
|
|
80
|
+
input?: Record<string, TJSONSchema>
|
|
81
|
+
}
|
|
82
|
+
validation?: {
|
|
83
|
+
params?: (params: any) => { errors?: any[] }
|
|
84
|
+
yield?: (value: any) => { errors?: any[] }
|
|
85
|
+
input?: Record<string, (value: any) => { errors?: any[] }>
|
|
86
|
+
}
|
|
87
|
+
} & TExtendedConfig
|
|
88
|
+
>
|
|
89
|
+
}>
|
|
90
|
+
) => void
|
|
91
|
+
}
|
|
92
|
+
) {
|
|
93
|
+
const procedures: Map<
|
|
94
|
+
string,
|
|
95
|
+
| TProcedureRegistration<TContext, TExtendedConfig>
|
|
96
|
+
| TStreamProcedureRegistration<TContext, TExtendedConfig>
|
|
97
|
+
> = new Map()
|
|
98
|
+
|
|
99
|
+
function Create<
|
|
100
|
+
TName extends string,
|
|
101
|
+
TParams,
|
|
102
|
+
TReturnType,
|
|
103
|
+
TInput extends Record<string, unknown> | undefined = undefined,
|
|
104
|
+
>(
|
|
105
|
+
name: TName,
|
|
106
|
+
config: {
|
|
107
|
+
description?: string
|
|
108
|
+
schema?: {
|
|
109
|
+
params?: TParams
|
|
110
|
+
returnType?: TReturnType
|
|
111
|
+
input?: TInput
|
|
112
|
+
}
|
|
113
|
+
} & TExtendedConfig,
|
|
114
|
+
handler: (
|
|
115
|
+
ctx: Prettify<TContext & TLocalContext>,
|
|
116
|
+
params: TInput extends Record<string, unknown>
|
|
117
|
+
? Prettify<{ [K in keyof TInput]: TSchemaLib<TInput[K]> }>
|
|
118
|
+
: TSchemaLib<TParams>
|
|
119
|
+
) => Promise<TSchemaLib<TReturnType>>
|
|
120
|
+
) {
|
|
121
|
+
// Capture definition location as first action
|
|
122
|
+
const definitionInfo = captureDefinitionInfo()
|
|
123
|
+
|
|
124
|
+
// BEFORE computeSchema - fail fast on duplicate
|
|
125
|
+
if (procedures.has(name)) {
|
|
126
|
+
throw new Error(`Procedure with name ${name} is already registered`)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const { jsonSchema, validations } = computeSchema(name, config.schema, definitionInfo)
|
|
130
|
+
|
|
131
|
+
// Create error factory once at registration time (outside handler)
|
|
132
|
+
const errorFactory = (message: string, meta?: object) => {
|
|
133
|
+
return new ProcedureError(name, message, meta, definitionInfo)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const registeredProcedure = {
|
|
137
|
+
name,
|
|
138
|
+
config: {
|
|
139
|
+
// ctx: config.hook, ??? why was this here
|
|
140
|
+
...config,
|
|
141
|
+
description: config.description,
|
|
142
|
+
schema: jsonSchema,
|
|
143
|
+
validation: {
|
|
144
|
+
params: validations.params,
|
|
145
|
+
...(validations.input && { input: validations.input }),
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
|
|
149
|
+
handler: async (ctx: Prettify<TContext>, params: TSchemaLib<TParams>) => {
|
|
150
|
+
try {
|
|
151
|
+
// Skip validation if caller has already validated (e.g., HonoStreamAppBuilder)
|
|
152
|
+
const isPrevalidated = (ctx as { isPrevalidated?: boolean }).isPrevalidated
|
|
153
|
+
if (validations?.params && !isPrevalidated) {
|
|
154
|
+
const { errors } = validations.params(params)
|
|
155
|
+
|
|
156
|
+
if (errors) {
|
|
157
|
+
throw new ProcedureValidationError(
|
|
158
|
+
name,
|
|
159
|
+
`Validation error for ${name}`,
|
|
160
|
+
errors,
|
|
161
|
+
definitionInfo
|
|
162
|
+
)
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Validate each input channel independently for better error messages.
|
|
167
|
+
// Double validation (per-channel + merged) is intentional for developer experience;
|
|
168
|
+
// the cost is negligible — revisit if validation becomes a performance bottleneck.
|
|
169
|
+
if (validations?.input && !isPrevalidated) {
|
|
170
|
+
for (const [channel, validator] of Object.entries(validations.input)) {
|
|
171
|
+
const channelValue = (params as Record<string, unknown>)?.[channel]
|
|
172
|
+
const { errors } = validator(channelValue)
|
|
173
|
+
|
|
174
|
+
if (errors) {
|
|
175
|
+
throw new ProcedureValidationError(
|
|
176
|
+
name,
|
|
177
|
+
`Validation error for ${name} in input.${channel}`,
|
|
178
|
+
errors,
|
|
179
|
+
definitionInfo
|
|
180
|
+
)
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const localCtx: TLocalContext = {
|
|
186
|
+
error: errorFactory, // Reuse pre-created factory
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// params is correctly typed at the public API boundary via conditional type;
|
|
190
|
+
// cast here because TS cannot narrow conditional generics inside implementations
|
|
191
|
+
return await handler(
|
|
192
|
+
{
|
|
193
|
+
...ctx,
|
|
194
|
+
...localCtx,
|
|
195
|
+
} as Prettify<TContext & TLocalContext>,
|
|
196
|
+
params as any
|
|
197
|
+
)
|
|
198
|
+
} catch (error: any) {
|
|
199
|
+
if (error instanceof ProcedureError) {
|
|
200
|
+
throw error
|
|
201
|
+
} else {
|
|
202
|
+
const err = new ProcedureError(
|
|
203
|
+
name,
|
|
204
|
+
`Error in handler for ${name} - ${error?.message}`,
|
|
205
|
+
undefined,
|
|
206
|
+
definitionInfo
|
|
207
|
+
)
|
|
208
|
+
err.cause = error // Preserve original error
|
|
209
|
+
// Preserve original stack but append definition info
|
|
210
|
+
if (error.stack && definitionInfo.definedAt) {
|
|
211
|
+
const { file, line, column } = definitionInfo.definedAt
|
|
212
|
+
err.stack =
|
|
213
|
+
error.stack +
|
|
214
|
+
`\n--- Procedure "${name}" defined at ---\n at ${file}:${line}:${column}`
|
|
215
|
+
} else if (error.stack) {
|
|
216
|
+
err.stack = error.stack
|
|
217
|
+
}
|
|
218
|
+
throw err
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
procedures.set(name, registeredProcedure)
|
|
225
|
+
|
|
226
|
+
if (builder?.onCreate) {
|
|
227
|
+
builder.onCreate(registeredProcedure)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const info = {
|
|
231
|
+
name,
|
|
232
|
+
...registeredProcedure.config,
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// return so can be called directly (ie: int/unit tests)
|
|
236
|
+
return {
|
|
237
|
+
[name]: registeredProcedure.handler,
|
|
238
|
+
procedure: registeredProcedure.handler,
|
|
239
|
+
info,
|
|
240
|
+
} as {
|
|
241
|
+
[K in TName]: (
|
|
242
|
+
ctx: Prettify<TContext>,
|
|
243
|
+
params: TInput extends Record<string, unknown>
|
|
244
|
+
? Prettify<{ [K in keyof TInput]: TSchemaLib<TInput[K]> }>
|
|
245
|
+
: TSchemaLib<TParams>
|
|
246
|
+
) => Promise<TSchemaLib<TReturnType>>
|
|
247
|
+
} & {
|
|
248
|
+
procedure: (
|
|
249
|
+
ctx: Prettify<TContext>,
|
|
250
|
+
params: TInput extends Record<string, unknown>
|
|
251
|
+
? Prettify<{ [K in keyof TInput]: TSchemaLib<TInput[K]> }>
|
|
252
|
+
: TSchemaLib<TParams>
|
|
253
|
+
) => Promise<TSchemaLib<TReturnType>>
|
|
254
|
+
info: {
|
|
255
|
+
name: TName
|
|
256
|
+
description?: string
|
|
257
|
+
schema: {
|
|
258
|
+
params?: TParams
|
|
259
|
+
returnType?: TReturnType
|
|
260
|
+
input?: TInput
|
|
261
|
+
}
|
|
262
|
+
validation?: {
|
|
263
|
+
params?: (params: any) => { errors?: any[] }
|
|
264
|
+
input?: Record<string, (value: any) => { errors?: any[] }>
|
|
265
|
+
}
|
|
266
|
+
} & TExtendedConfig
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function CreateStream<
|
|
271
|
+
TName extends string,
|
|
272
|
+
TParams,
|
|
273
|
+
TYieldType,
|
|
274
|
+
TReturnType = void,
|
|
275
|
+
TInput extends Record<string, unknown> | undefined = undefined,
|
|
276
|
+
>(
|
|
277
|
+
name: TName,
|
|
278
|
+
config: {
|
|
279
|
+
description?: string
|
|
280
|
+
schema?: {
|
|
281
|
+
params?: TParams
|
|
282
|
+
yieldType?: TYieldType
|
|
283
|
+
returnType?: TReturnType
|
|
284
|
+
input?: TInput
|
|
285
|
+
}
|
|
286
|
+
validateYields?: boolean
|
|
287
|
+
} & TExtendedConfig,
|
|
288
|
+
handler: (
|
|
289
|
+
ctx: Prettify<TContext & TStreamContext>,
|
|
290
|
+
params: TInput extends Record<string, unknown>
|
|
291
|
+
? Prettify<{ [K in keyof TInput]: TSchemaLib<TInput[K]> }>
|
|
292
|
+
: TSchemaLib<TParams>
|
|
293
|
+
) => AsyncGenerator<TSchemaLib<TYieldType>, TSchemaLib<TReturnType> | void, unknown>
|
|
294
|
+
) {
|
|
295
|
+
// Capture definition location as first action
|
|
296
|
+
const definitionInfo = captureDefinitionInfo()
|
|
297
|
+
|
|
298
|
+
// BEFORE computeSchema - fail fast on duplicate
|
|
299
|
+
if (procedures.has(name)) {
|
|
300
|
+
throw new Error(`Procedure with name ${name} is already registered`)
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const { jsonSchema, validations } = computeSchema(name, config.schema, definitionInfo)
|
|
304
|
+
|
|
305
|
+
// Create error factory once at registration time (outside handler)
|
|
306
|
+
const errorFactory = (message: string, meta?: object) => {
|
|
307
|
+
return new ProcedureError(name, message, meta, definitionInfo)
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const validateYields = config.validateYields ?? false
|
|
311
|
+
|
|
312
|
+
const registeredProcedure: TStreamProcedureRegistration<TContext, TExtendedConfig> = {
|
|
313
|
+
name,
|
|
314
|
+
isStream: true,
|
|
315
|
+
config: {
|
|
316
|
+
...config,
|
|
317
|
+
description: config.description,
|
|
318
|
+
schema: jsonSchema,
|
|
319
|
+
validation: {
|
|
320
|
+
params: validations.params,
|
|
321
|
+
yield: validations.yield,
|
|
322
|
+
...(validations.input && { input: validations.input }),
|
|
323
|
+
},
|
|
324
|
+
},
|
|
325
|
+
|
|
326
|
+
handler: async function* wrappedHandler(
|
|
327
|
+
ctx: Prettify<TContext>,
|
|
328
|
+
params: TSchemaLib<TParams>
|
|
329
|
+
) {
|
|
330
|
+
// Create abort controller for this stream
|
|
331
|
+
const abortController = new AbortController()
|
|
332
|
+
|
|
333
|
+
// Skip validation if caller has already validated (e.g., HonoStreamAppBuilder)
|
|
334
|
+
const isPrevalidated = (ctx as { isPrevalidated?: boolean }).isPrevalidated
|
|
335
|
+
if (validations?.params && !isPrevalidated) {
|
|
336
|
+
const { errors } = validations.params(params)
|
|
337
|
+
|
|
338
|
+
if (errors) {
|
|
339
|
+
throw new ProcedureValidationError(
|
|
340
|
+
name,
|
|
341
|
+
`Validation error for ${name}`,
|
|
342
|
+
errors,
|
|
343
|
+
definitionInfo
|
|
344
|
+
)
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// Validate each input channel independently (see Create for rationale)
|
|
349
|
+
if (validations?.input && !isPrevalidated) {
|
|
350
|
+
for (const [channel, validator] of Object.entries(validations.input)) {
|
|
351
|
+
const channelValue = (params as Record<string, unknown>)?.[channel]
|
|
352
|
+
const { errors } = validator(channelValue)
|
|
353
|
+
|
|
354
|
+
if (errors) {
|
|
355
|
+
throw new ProcedureValidationError(
|
|
356
|
+
name,
|
|
357
|
+
`Validation error for ${name} in input.${channel}`,
|
|
358
|
+
errors,
|
|
359
|
+
definitionInfo
|
|
360
|
+
)
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// Combine with external signal (e.g., from HTTP request) if provided
|
|
366
|
+
const incomingSignal = (ctx as { signal?: AbortSignal }).signal
|
|
367
|
+
const signal = incomingSignal
|
|
368
|
+
? AbortSignal.any([incomingSignal, abortController.signal])
|
|
369
|
+
: abortController.signal
|
|
370
|
+
|
|
371
|
+
const streamCtx: TStreamContext = {
|
|
372
|
+
error: errorFactory,
|
|
373
|
+
signal,
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// params is correctly typed at the public API boundary via conditional type;
|
|
377
|
+
// cast here because TS cannot narrow conditional generics inside implementations
|
|
378
|
+
const userGenerator = handler(
|
|
379
|
+
{
|
|
380
|
+
...ctx,
|
|
381
|
+
...streamCtx,
|
|
382
|
+
} as Prettify<TContext & TStreamContext>,
|
|
383
|
+
params as any
|
|
384
|
+
)
|
|
385
|
+
|
|
386
|
+
try {
|
|
387
|
+
const userIterator = userGenerator[Symbol.asyncIterator]()
|
|
388
|
+
let userIterResult = await userIterator.next()
|
|
389
|
+
|
|
390
|
+
while (!userIterResult.done) {
|
|
391
|
+
const value = userIterResult.value
|
|
392
|
+
|
|
393
|
+
// Only validate if explicitly enabled via validateYields: true
|
|
394
|
+
if (validateYields && validations.yield) {
|
|
395
|
+
const { errors } = validations.yield(value)
|
|
396
|
+
if (errors) {
|
|
397
|
+
throw new ProcedureYieldValidationError(
|
|
398
|
+
name,
|
|
399
|
+
`Yield validation error for ${name}`,
|
|
400
|
+
errors,
|
|
401
|
+
definitionInfo
|
|
402
|
+
)
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
yield value
|
|
407
|
+
userIterResult = await userIterator.next()
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// Propagate the generator's return value so consumers (e.g. HonoStreamAppBuilder)
|
|
411
|
+
// can send it as a special 'return' SSE event
|
|
412
|
+
return userIterResult.value
|
|
413
|
+
} catch (error: any) {
|
|
414
|
+
if (error instanceof ProcedureError) {
|
|
415
|
+
throw error
|
|
416
|
+
} else {
|
|
417
|
+
const err = new ProcedureError(
|
|
418
|
+
name,
|
|
419
|
+
`Error in streaming handler for ${name} - ${error?.message}`,
|
|
420
|
+
undefined,
|
|
421
|
+
definitionInfo
|
|
422
|
+
)
|
|
423
|
+
err.cause = error
|
|
424
|
+
if (error.stack && definitionInfo.definedAt) {
|
|
425
|
+
const { file, line, column } = definitionInfo.definedAt
|
|
426
|
+
err.stack =
|
|
427
|
+
error.stack +
|
|
428
|
+
`\n--- Procedure "${name}" defined at ---\n at ${file}:${line}:${column}`
|
|
429
|
+
} else if (error.stack) {
|
|
430
|
+
err.stack = error.stack
|
|
431
|
+
}
|
|
432
|
+
throw err
|
|
433
|
+
}
|
|
434
|
+
} finally {
|
|
435
|
+
abortController.abort('stream-completed')
|
|
436
|
+
}
|
|
437
|
+
} as (ctx: TContext, params?: any) => AsyncGenerator<any, any, unknown>,
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
procedures.set(name, registeredProcedure)
|
|
441
|
+
|
|
442
|
+
if (builder?.onCreate) {
|
|
443
|
+
builder.onCreate(registeredProcedure)
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
const info = {
|
|
447
|
+
name,
|
|
448
|
+
isStream: true as const,
|
|
449
|
+
...registeredProcedure.config,
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// return so can be called directly (ie: int/unit tests)
|
|
453
|
+
return {
|
|
454
|
+
[name]: registeredProcedure.handler,
|
|
455
|
+
procedure: registeredProcedure.handler,
|
|
456
|
+
info,
|
|
457
|
+
} as {
|
|
458
|
+
[K in TName]: (
|
|
459
|
+
ctx: Prettify<TContext>,
|
|
460
|
+
params: TInput extends Record<string, unknown>
|
|
461
|
+
? Prettify<{ [K in keyof TInput]: TSchemaLib<TInput[K]> }>
|
|
462
|
+
: TSchemaLib<TParams>
|
|
463
|
+
) => AsyncGenerator<TSchemaLib<TYieldType>, TSchemaLib<TReturnType> | void, unknown>
|
|
464
|
+
} & {
|
|
465
|
+
procedure: (
|
|
466
|
+
ctx: Prettify<TContext>,
|
|
467
|
+
params: TInput extends Record<string, unknown>
|
|
468
|
+
? Prettify<{ [K in keyof TInput]: TSchemaLib<TInput[K]> }>
|
|
469
|
+
: TSchemaLib<TParams>
|
|
470
|
+
) => AsyncGenerator<TSchemaLib<TYieldType>, TSchemaLib<TReturnType> | void, unknown>
|
|
471
|
+
info: {
|
|
472
|
+
name: TName
|
|
473
|
+
isStream: true
|
|
474
|
+
description?: string
|
|
475
|
+
schema: {
|
|
476
|
+
params?: TParams
|
|
477
|
+
yieldType?: TYieldType
|
|
478
|
+
returnType?: TReturnType
|
|
479
|
+
input?: TInput
|
|
480
|
+
}
|
|
481
|
+
validation?: {
|
|
482
|
+
params?: (params: any) => { errors?: any[] }
|
|
483
|
+
yield?: (value: any) => { errors?: any[] }
|
|
484
|
+
input?: Record<string, (value: any) => { errors?: any[] }>
|
|
485
|
+
}
|
|
486
|
+
} & TExtendedConfig
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
return {
|
|
491
|
+
/**
|
|
492
|
+
* Get all registered procedures
|
|
493
|
+
*/
|
|
494
|
+
getProcedures: () => {
|
|
495
|
+
return Array.from(procedures.values())
|
|
496
|
+
},
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* Get a specific procedure by name
|
|
500
|
+
*/
|
|
501
|
+
getProcedure: (name: string) => {
|
|
502
|
+
return procedures.get(name)
|
|
503
|
+
},
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* Remove a procedure by name
|
|
507
|
+
*/
|
|
508
|
+
removeProcedure: (name: string) => {
|
|
509
|
+
return procedures.delete(name)
|
|
510
|
+
},
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Clear all registered procedures
|
|
514
|
+
*/
|
|
515
|
+
clear: () => {
|
|
516
|
+
procedures.clear()
|
|
517
|
+
},
|
|
518
|
+
|
|
519
|
+
Create,
|
|
520
|
+
CreateStream,
|
|
521
|
+
}
|
|
522
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { Type } from 'typebox'
|
|
3
|
+
import { v } from 'suretype'
|
|
4
|
+
import { computeSchema } from './compute-schema.js'
|
|
5
|
+
import { ProcedureRegistrationError } from '../errors.js'
|
|
6
|
+
|
|
7
|
+
describe('computeSchema', () => {
|
|
8
|
+
it('should return empty schema and validations when no schema provided', () => {
|
|
9
|
+
const result = computeSchema('test-procedure')
|
|
10
|
+
|
|
11
|
+
expect(result).toEqual({
|
|
12
|
+
jsonSchema: { params: undefined, returnType: undefined },
|
|
13
|
+
validations: {}
|
|
14
|
+
})
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
describe('with Typebox schema', () => {
|
|
18
|
+
it('should correctly process params schema', () => {
|
|
19
|
+
const schema = {
|
|
20
|
+
params: Type.Object({
|
|
21
|
+
name: Type.String(),
|
|
22
|
+
age: Type.Number()
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const result = computeSchema('test-procedure', schema)
|
|
27
|
+
|
|
28
|
+
expect(result.jsonSchema.params).toBeDefined()
|
|
29
|
+
expect(result.validations.params).toBeDefined()
|
|
30
|
+
|
|
31
|
+
// Test validation function
|
|
32
|
+
const validInput = { name: 'John', age: 30 }
|
|
33
|
+
expect(result.validations.params?.(validInput).errors).toBeUndefined()
|
|
34
|
+
|
|
35
|
+
// Test invalid input
|
|
36
|
+
const invalidInput = { name: 123, age: 'invalid' }
|
|
37
|
+
expect(result.validations.params?.(invalidInput).errors).toBeDefined()
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('should correctly process returnType schema', () => {
|
|
41
|
+
const schema = {
|
|
42
|
+
returnType: Type.Object({
|
|
43
|
+
result: Type.Boolean()
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const result = computeSchema('test-procedure', schema)
|
|
48
|
+
|
|
49
|
+
expect(result.jsonSchema.returnType).toBeDefined()
|
|
50
|
+
expect(result.validations.params).toBeUndefined()
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
describe('with Suretype schema', () => {
|
|
55
|
+
it('should correctly process params schema', () => {
|
|
56
|
+
const schema = {
|
|
57
|
+
params: v.object({
|
|
58
|
+
name: v.string(),
|
|
59
|
+
age: v.number()
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const result = computeSchema('test-procedure', schema)
|
|
64
|
+
|
|
65
|
+
expect(result.jsonSchema.params).toBeDefined()
|
|
66
|
+
expect(result.validations.params).toBeDefined()
|
|
67
|
+
|
|
68
|
+
// Test validation function
|
|
69
|
+
const validInput = { name: 'John', age: 30 }
|
|
70
|
+
expect(result.validations.params?.(validInput).errors).toBeUndefined()
|
|
71
|
+
|
|
72
|
+
// Test invalid input
|
|
73
|
+
const invalidInput = { name: 123, age: 'invalid' }
|
|
74
|
+
expect(result.validations.params?.(invalidInput).errors).toBeDefined()
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
describe('error handling', () => {
|
|
79
|
+
it('should throw ProcedureRegistrationError for invalid schema', () => {
|
|
80
|
+
const invalidSchema = {
|
|
81
|
+
params: {
|
|
82
|
+
type: 'invalid-schema-type'
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
expect(() => computeSchema('test-procedure', invalidSchema))
|
|
87
|
+
.toThrow(ProcedureRegistrationError)
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
it('should include procedure name in error message', () => {
|
|
91
|
+
const invalidSchema = {
|
|
92
|
+
params: {
|
|
93
|
+
type: 'invalid-schema-type'
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
computeSchema('test-procedure', invalidSchema)
|
|
99
|
+
} catch (error: any) {
|
|
100
|
+
expect(error instanceof ProcedureRegistrationError).toBe(true)
|
|
101
|
+
expect(error.message).toContain('test-procedure')
|
|
102
|
+
}
|
|
103
|
+
})
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
describe('combined schemas', () => {
|
|
107
|
+
it('should handle both params and returnType schemas', () => {
|
|
108
|
+
const schema = {
|
|
109
|
+
params: Type.Object({
|
|
110
|
+
input: Type.String()
|
|
111
|
+
}),
|
|
112
|
+
returnType: Type.Object({
|
|
113
|
+
output: Type.Boolean()
|
|
114
|
+
})
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const result = computeSchema('test-procedure', schema)
|
|
118
|
+
|
|
119
|
+
expect(result.jsonSchema.params).toBeDefined()
|
|
120
|
+
expect(result.jsonSchema.returnType).toBeDefined()
|
|
121
|
+
expect(result.validations.params).toBeDefined()
|
|
122
|
+
|
|
123
|
+
// Test params validation
|
|
124
|
+
const validInput = { input: 'test' }
|
|
125
|
+
expect(result.validations.params?.(validInput).errors).toBeUndefined()
|
|
126
|
+
})
|
|
127
|
+
})
|
|
128
|
+
})
|