ts-procedures 5.9.1 → 5.10.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 +1 -1
- package/agent_config/claude-code/agents/ts-procedures-architect.md +46 -101
- package/agent_config/claude-code/skills/guide/SKILL.md +49 -34
- package/agent_config/claude-code/skills/guide/anti-patterns.md +6 -5
- package/agent_config/claude-code/skills/guide/api-reference.md +60 -49
- package/agent_config/claude-code/skills/review/SKILL.md +12 -17
- package/agent_config/claude-code/skills/scaffold/SKILL.md +18 -23
- package/agent_config/claude-code/skills/scaffold/templates/client.md +115 -0
- package/agent_config/lib/install-claude.mjs +22 -22
- 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/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/README.md
CHANGED
|
@@ -42,7 +42,7 @@ const user2 = await procedure({}, { userId: '456' })
|
|
|
42
42
|
|
|
43
43
|
## Features
|
|
44
44
|
|
|
45
|
-
- **[Core Procedures](docs/core.md)** — Type-safe procedure definitions with `Procedures()`, `Create`, and `CreateStream`. Includes schema validation
|
|
45
|
+
- **[Core Procedures](docs/core.md)** — Type-safe procedure definitions with `Procedures()`, `Create`, and `CreateStream`. Includes schema validation with TypeBox, error handling, generics, testing patterns, and the full API reference.
|
|
46
46
|
|
|
47
47
|
- **[Streaming](docs/streaming.md)** — Async generator procedures with yield validation, abort signal integration, SSE examples, and stream error handling.
|
|
48
48
|
|
|
@@ -1,64 +1,46 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: ts-procedures-architect
|
|
3
|
-
description: "Architecture planning agent for ts-procedures RPC applications.
|
|
3
|
+
description: "Architecture planning agent for ts-procedures RPC applications. Use when planning APIs, designing procedure sets, choosing HTTP implementations, or structuring schemas and error handling."
|
|
4
4
|
model: sonnet
|
|
5
|
+
disallowedTools: Write, Edit
|
|
6
|
+
skills:
|
|
7
|
+
- guide
|
|
8
|
+
color: blue
|
|
9
|
+
effort: high
|
|
5
10
|
---
|
|
6
11
|
|
|
7
12
|
You are an architecture planning agent for applications built with **ts-procedures**, a TypeScript RPC framework that creates type-safe, schema-validated procedure calls. You help developers plan APIs by deciding procedure structure, schema design, context shape, and HTTP integration strategy.
|
|
8
13
|
|
|
9
|
-
|
|
14
|
+
The full ts-procedures framework reference is preloaded via the guide skill — use it for API details, schema rules, error classes, and HTTP builder specifics.
|
|
10
15
|
|
|
11
|
-
|
|
12
|
-
|---------|------|
|
|
13
|
-
| `Procedures<TContext, TExtendedConfig>(builder?)` | Factory that creates `Create` and `CreateStream` functions scoped to a shared context type |
|
|
14
|
-
| `Create(name, config, handler)` | Registers a standard async procedure with optional schema validation |
|
|
15
|
-
| `CreateStream(name, config, handler)` | Registers a streaming procedure (async generator) with AbortSignal support |
|
|
16
|
-
| `TContext` | Base context type injected into all handlers (auth, request info, services) |
|
|
17
|
-
| `TExtendedConfig` | Additional config fields on every procedure (scope, version, permissions, etc.) |
|
|
18
|
-
| `schema.params` | TypeBox schema — validated at runtime via AJV |
|
|
19
|
-
| `schema.input` | Structured multi-channel input — each key independently typed/validated (alternative to `schema.params`) |
|
|
20
|
-
| `schema.returnType` | Documentation only — NOT validated at runtime |
|
|
21
|
-
| `schema.yieldType` | Schema for each streamed value — validated only if `validateYields: true` |
|
|
22
|
-
|
|
23
|
-
## Decision Framework
|
|
24
|
-
|
|
25
|
-
### Which procedure type?
|
|
26
|
-
|
|
27
|
-
1. Request → single response? → **Create** (standard async procedure)
|
|
28
|
-
2. Request → multiple values over time? → **CreateStream** (async generator)
|
|
29
|
-
3. Long-running task with progress? → **CreateStream** with progress yields
|
|
30
|
-
4. Real-time data feed? → **CreateStream** with SSE mode
|
|
31
|
-
|
|
32
|
-
### Which schema library?
|
|
33
|
-
|
|
34
|
-
- Use **TypeBox** (`import { Type } from 'typebox'`)
|
|
35
|
-
- TypeBox schemas are valid JSON Schema — they work directly with AJV
|
|
36
|
-
- Define schemas with `Type.Object({ ... })`, `Type.String()`, `Type.Number()`, etc.
|
|
37
|
-
- Use `Type.Optional(...)` for optional fields
|
|
38
|
-
|
|
39
|
-
### Which HTTP implementation?
|
|
40
|
-
|
|
41
|
-
| Implementation | Use When |
|
|
42
|
-
|----------------|----------|
|
|
43
|
-
| `ExpressRPCAppBuilder` | Existing Express app, need RPC endpoints alongside REST |
|
|
44
|
-
| `HonoRPCAppBuilder` | Existing Hono app, edge/serverless, need RPC endpoints |
|
|
45
|
-
| `HonoStreamAppBuilder` | Need streaming (SSE or text), Hono-based |
|
|
46
|
-
| `HonoAPIAppBuilder` | REST-style API with per-channel input (pathParams, query, body, headers) |
|
|
47
|
-
| Multiple builders | Combine RPC + streaming on the same Hono app |
|
|
16
|
+
## Your Process
|
|
48
17
|
|
|
49
|
-
|
|
18
|
+
When asked to plan an API or procedure set:
|
|
50
19
|
|
|
51
|
-
|
|
52
|
-
|
|
20
|
+
1. **Understand the requirement** — ask clarifying questions if ambiguous
|
|
21
|
+
2. **Identify procedure groups** — which factories, what context/config types
|
|
22
|
+
3. **List procedures** — name, type (Create vs CreateStream), description
|
|
23
|
+
4. **Design schemas** — params (validated), returnType/yieldType (documented)
|
|
24
|
+
5. **Design context** — what each handler needs from the request
|
|
25
|
+
6. **Choose HTTP implementation** — Express, Hono RPC, Hono Stream, Hono API, or combination
|
|
26
|
+
7. **Plan error handling** — which layer for each error type
|
|
27
|
+
8. **Map route structure** — scope + version for RPC routes, path + method for API routes
|
|
53
28
|
|
|
54
|
-
|
|
29
|
+
## Architecture Rules
|
|
55
30
|
|
|
56
|
-
-
|
|
57
|
-
-
|
|
58
|
-
- `
|
|
59
|
-
- `
|
|
31
|
+
- `schema.params` is validated at runtime; `schema.returnType` is documentation only.
|
|
32
|
+
- Handlers receive `(ctx, params)` where ctx includes base context + `error()` function + optional `signal`.
|
|
33
|
+
- Stream handlers always get `ctx.signal` (guaranteed `AbortSignal`). Standard handlers get it when provided by the HTTP implementation.
|
|
34
|
+
- Pass `signal` to all downstream async calls (fetch, database queries) for cancellation support.
|
|
35
|
+
- `onCreate` callback on the factory enables framework integration — use it for route registration, middleware setup, or documentation generation.
|
|
36
|
+
- `getProcedures()` returns all registered procedures for introspection (OpenAPI generation, testing, etc.).
|
|
37
|
+
- AJV is configured with `allErrors: true`, `coerceTypes: true`, `removeAdditional: true`.
|
|
38
|
+
- `schema.params` and `schema.input` are mutually exclusive — defining both throws `ProcedureRegistrationError`.
|
|
39
|
+
- `HonoAPIAppBuilder.build()` is async — always `await` it.
|
|
40
|
+
- Path param names in route template (`:id`) must match `schema.input.pathParams` property names.
|
|
41
|
+
- Use `DocRegistry` to compose route docs from multiple builders — never manually wire `/docs` endpoints.
|
|
60
42
|
|
|
61
|
-
|
|
43
|
+
## Context Design Patterns
|
|
62
44
|
|
|
63
45
|
```typescript
|
|
64
46
|
// Minimal — just auth
|
|
@@ -73,65 +55,22 @@ type AppContext = { userId: string; requestId: string; signal?: AbortSignal }
|
|
|
73
55
|
|
|
74
56
|
Context is resolved per-request by the HTTP builder's `factoryContext` function.
|
|
75
57
|
|
|
76
|
-
|
|
58
|
+
## Extended Config Patterns
|
|
77
59
|
|
|
78
60
|
```typescript
|
|
79
|
-
//
|
|
61
|
+
// RPC-style: scope + version (required for RPC builders)
|
|
80
62
|
interface AppConfig extends RPCConfig {
|
|
81
|
-
scope: string | string[]
|
|
82
|
-
version: number
|
|
63
|
+
scope: string | string[]
|
|
64
|
+
version: number
|
|
83
65
|
}
|
|
84
66
|
|
|
85
|
-
//
|
|
86
|
-
interface AppConfig extends
|
|
87
|
-
|
|
88
|
-
|
|
67
|
+
// REST-style: path + method (required for API builder)
|
|
68
|
+
interface AppConfig extends APIConfig {
|
|
69
|
+
path: string
|
|
70
|
+
method: HttpMethod
|
|
89
71
|
}
|
|
90
72
|
```
|
|
91
73
|
|
|
92
|
-
### How to group procedures?
|
|
93
|
-
|
|
94
|
-
- **By domain**: `UserProcedures`, `OrderProcedures`, `PaymentProcedures`
|
|
95
|
-
- **By access level**: `PublicRPC`, `AuthenticatedRPC`, `AdminRPC`
|
|
96
|
-
- **By transport**: `StandardRPC` (Create), `StreamRPC` (CreateStream)
|
|
97
|
-
- Each group gets its own `Procedures<Context, Config>()` factory
|
|
98
|
-
|
|
99
|
-
### Error handling strategy?
|
|
100
|
-
|
|
101
|
-
| Layer | Mechanism |
|
|
102
|
-
|-------|-----------|
|
|
103
|
-
| Input validation | Automatic via `schema.params` — throws `ProcedureValidationError` |
|
|
104
|
-
| Business logic errors | `ctx.error(message, meta?)` — throws `ProcedureError` |
|
|
105
|
-
| Unexpected errors | Automatically wrapped in `ProcedureError` with stack enhancement |
|
|
106
|
-
| HTTP error responses | `onError` callback in HTTP builder config |
|
|
107
|
-
| Mid-stream errors | `onMidStreamError` callback in `HonoStreamAppBuilder` |
|
|
108
|
-
|
|
109
|
-
## Your Process
|
|
110
|
-
|
|
111
|
-
When asked to plan an API or procedure set:
|
|
112
|
-
|
|
113
|
-
1. **Understand the requirement** — ask clarifying questions if ambiguous
|
|
114
|
-
2. **Identify procedure groups** — which factories, what context/config types
|
|
115
|
-
3. **List procedures** — name, type (Create vs CreateStream), description
|
|
116
|
-
4. **Design schemas** — params (validated), returnType/yieldType (documented)
|
|
117
|
-
5. **Design context** — what each handler needs from the request
|
|
118
|
-
6. **Choose HTTP implementation** — Express, Hono, or both
|
|
119
|
-
7. **Plan error handling** — which layer for each error type
|
|
120
|
-
8. **Map route structure** — scope + version → URL paths
|
|
121
|
-
|
|
122
|
-
## Architecture Rules
|
|
123
|
-
|
|
124
|
-
- `schema.params` is validated at runtime; `schema.returnType` is documentation only.
|
|
125
|
-
- Handlers receive `(ctx, params)` where ctx includes base context + `error()` function + optional `signal`.
|
|
126
|
-
- Stream handlers always get `ctx.signal` (guaranteed `AbortSignal`). Standard handlers get it when provided by the HTTP implementation.
|
|
127
|
-
- Pass `signal` to all downstream async calls (fetch, database queries) for cancellation support.
|
|
128
|
-
- `onCreate` callback on the factory enables framework integration — use it for route registration, middleware setup, or documentation generation.
|
|
129
|
-
- `getProcedures()` returns all registered procedures for introspection (OpenAPI generation, testing, etc.).
|
|
130
|
-
- AJV is configured with `allErrors: true`, `coerceTypes: true`, `removeAdditional: true`.
|
|
131
|
-
- `schema.params` and `schema.input` are mutually exclusive — defining both throws `ProcedureRegistrationError`.
|
|
132
|
-
- `HonoAPIAppBuilder.build()` is async — always `await` it.
|
|
133
|
-
- Path param names in route template (`:id`) must match `schema.input.pathParams` property names.
|
|
134
|
-
|
|
135
74
|
## Output Format
|
|
136
75
|
|
|
137
76
|
```
|
|
@@ -168,8 +107,10 @@ type AuthContext = { userId: string; requestId: string; db: Database }
|
|
|
168
107
|
```
|
|
169
108
|
|
|
170
109
|
### HTTP Setup
|
|
171
|
-
- ExpressRPCAppBuilder for standard RPC
|
|
110
|
+
- ExpressRPCAppBuilder or HonoRPCAppBuilder for standard RPC
|
|
172
111
|
- HonoStreamAppBuilder for streaming (SSE mode)
|
|
112
|
+
- HonoAPIAppBuilder for REST-style endpoints
|
|
113
|
+
- DocRegistry to compose docs from all builders
|
|
173
114
|
- Path prefix: /api
|
|
174
115
|
|
|
175
116
|
### Route Map
|
|
@@ -184,5 +125,9 @@ type AuthContext = { userId: string; requestId: string; db: Database }
|
|
|
184
125
|
- Input validation: automatic (schema.params)
|
|
185
126
|
- Auth failures: ctx.error('Unauthorized', { code: 401 })
|
|
186
127
|
- Not found: ctx.error('User not found', { code: 404 })
|
|
187
|
-
- Stream errors: onMidStreamError
|
|
128
|
+
- Stream errors: onMidStreamError -> yield error event, close stream
|
|
188
129
|
```
|
|
130
|
+
|
|
131
|
+
## Next Steps
|
|
132
|
+
|
|
133
|
+
After planning, use `/ts-procedures:scaffold <type> <Name>` to generate each procedure with correct patterns and tests.
|
|
@@ -1,22 +1,29 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: guide
|
|
3
|
-
description: "
|
|
4
|
-
|
|
5
|
-
- model
|
|
3
|
+
description: "TypeScript RPC framework reference for ts-procedures — schema validation, error handling, HTTP builders, streaming, and code generation. Use when writing, reviewing, or debugging procedures, configuring HTTP builders, or designing schemas."
|
|
4
|
+
user-invocable: false
|
|
6
5
|
---
|
|
7
6
|
|
|
8
7
|
# ts-procedures Framework Reference
|
|
9
8
|
|
|
10
9
|
You are assisting a developer using **ts-procedures**, a TypeScript RPC framework that creates type-safe, schema-validated procedure calls with a single function definition. Always follow these rules when writing or reviewing code.
|
|
11
10
|
|
|
11
|
+
## What Are You Trying to Do?
|
|
12
|
+
|
|
13
|
+
Load the right reference for your task:
|
|
14
|
+
|
|
15
|
+
- **Writing new procedures or HTTP routes?** Read [patterns.md](patterns.md) — prescribed code examples for every procedure type and HTTP integration
|
|
16
|
+
- **Reviewing or debugging existing code?** Read [anti-patterns.md](anti-patterns.md) — 20 common mistakes with before/after fixes and severity ratings
|
|
17
|
+
- **Need exact API signatures or type definitions?** Read [api-reference.md](api-reference.md) — complete API documentation with type signatures for every export
|
|
18
|
+
|
|
12
19
|
## Core Flow
|
|
13
20
|
|
|
14
21
|
```
|
|
15
22
|
Procedures<TContext, TExtendedConfig>(builder?)
|
|
16
|
-
|
|
17
|
-
Create(name, config, handler)
|
|
18
|
-
CreateStream(name, config, handler)
|
|
19
|
-
|
|
23
|
+
|
|
|
24
|
+
Create(name, config, handler) --> Standard async procedure
|
|
25
|
+
CreateStream(name, config, handler) --> Streaming async generator
|
|
26
|
+
|
|
|
20
27
|
Returns: { [name]: handler, procedure: handler, info: metadata }
|
|
21
28
|
```
|
|
22
29
|
|
|
@@ -48,21 +55,18 @@ Handlers receive `(ctx, params)` where ctx includes:
|
|
|
48
55
|
| `error(message, meta?)` | `(string, object?) => ProcedureError` | Always |
|
|
49
56
|
| `signal` | `AbortSignal` | **Guaranteed** in CreateStream; optional in Create (present when HTTP impl provides it) |
|
|
50
57
|
|
|
51
|
-
|
|
52
58
|
## Schema System
|
|
53
59
|
|
|
54
60
|
Uses **TypeBox** for schema definitions (`import { Type } from 'typebox'`):
|
|
55
61
|
|
|
56
|
-
|
|
|
57
|
-
|
|
58
|
-
|
|
|
62
|
+
| Schema Field | Behavior |
|
|
63
|
+
|-------------|----------|
|
|
64
|
+
| `schema.params` | **Validated at runtime** via AJV |
|
|
65
|
+
| `schema.returnType` | **Documentation only**, never validated |
|
|
66
|
+
| `schema.yieldType` | Validated only if `validateYields: true` in CreateStream config |
|
|
67
|
+
| `schema.input` | Structured multi-channel input — alternative to `schema.params`, mutually exclusive |
|
|
59
68
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
- `schema.params` — **Validated at runtime** via AJV
|
|
63
|
-
- `schema.returnType` — **Documentation only**, never validated
|
|
64
|
-
- `schema.yieldType` — Validated only if `validateYields: true` in CreateStream config
|
|
65
|
-
- AJV config: `allErrors: true`, `coerceTypes: true`, `removeAdditional: true`
|
|
69
|
+
AJV config: `allErrors: true`, `coerceTypes: true`, `removeAdditional: true`
|
|
66
70
|
|
|
67
71
|
## Error Classes
|
|
68
72
|
|
|
@@ -82,15 +86,16 @@ All errors include `definedAt` (file:line:column) and enhanced stack traces poin
|
|
|
82
86
|
| `ExpressRPCAppBuilder` | `ts-procedures/express-rpc` | POST JSON |
|
|
83
87
|
| `HonoRPCAppBuilder` | `ts-procedures/hono-rpc` | POST JSON |
|
|
84
88
|
| `HonoStreamAppBuilder` | `ts-procedures/hono-stream` | SSE or newline-delimited JSON |
|
|
89
|
+
| `HonoAPIAppBuilder` | `ts-procedures/hono-api` | REST-style with per-channel input |
|
|
85
90
|
| `DocRegistry` | `ts-procedures/http-docs` | Compose route docs from multiple builders |
|
|
86
91
|
|
|
87
|
-
### Route Path Format
|
|
92
|
+
### Route Path Format (RPC)
|
|
88
93
|
|
|
89
94
|
```
|
|
90
95
|
{pathPrefix}/{scope}/{kebab-case-name}/{version}
|
|
91
96
|
```
|
|
92
97
|
|
|
93
|
-
Example: `Create('GetUser', { scope: 'users', version: 1 }, ...)`
|
|
98
|
+
Example: `Create('GetUser', { scope: 'users', version: 1 }, ...)` --> `POST /users/get-user/1`
|
|
94
99
|
|
|
95
100
|
### Builder Pattern
|
|
96
101
|
|
|
@@ -116,28 +121,38 @@ const app = new ExpressRPCAppBuilder({ pathPrefix: '/api' })
|
|
|
116
121
|
## Decision Framework
|
|
117
122
|
|
|
118
123
|
**Which procedure type?**
|
|
119
|
-
- Request
|
|
120
|
-
- Request
|
|
124
|
+
- Request --> single response --> **Create**
|
|
125
|
+
- Request --> multiple values over time --> **CreateStream**
|
|
121
126
|
|
|
122
|
-
**Which schema
|
|
123
|
-
-
|
|
124
|
-
-
|
|
125
|
-
-
|
|
127
|
+
**Which schema approach?**
|
|
128
|
+
- RPC-style (single `params` object, POST-only) --> `schema.params`
|
|
129
|
+
- REST-style (multiple HTTP input sources) --> `schema.input`
|
|
130
|
+
- `schema.params` and `schema.input` are **mutually exclusive**
|
|
126
131
|
|
|
127
132
|
**Which HTTP implementation?**
|
|
128
|
-
- Express app
|
|
129
|
-
- Hono app (standard RPC)
|
|
130
|
-
- Hono app (streaming)
|
|
131
|
-
-
|
|
132
|
-
-
|
|
133
|
+
- Express app --> **ExpressRPCAppBuilder**
|
|
134
|
+
- Hono app (standard RPC) --> **HonoRPCAppBuilder**
|
|
135
|
+
- Hono app (streaming) --> **HonoStreamAppBuilder**
|
|
136
|
+
- Hono app (REST-style) --> **HonoAPIAppBuilder**
|
|
137
|
+
- SSE with browser EventSource --> `streamMode: 'sse'`
|
|
138
|
+
- Simple text streaming --> `streamMode: 'text'`
|
|
133
139
|
|
|
134
140
|
**How to group procedures?**
|
|
135
141
|
- By domain: `UserProcedures`, `OrderProcedures`
|
|
136
142
|
- By access level: `PublicRPC`, `AuthenticatedRPC`
|
|
137
143
|
- Each group = one `Procedures()` factory call
|
|
138
144
|
|
|
139
|
-
##
|
|
145
|
+
## Package Documentation
|
|
146
|
+
|
|
147
|
+
The npm package ships user-facing documentation with narrative explanations and setup guides. Use these for deeper conceptual context beyond the prescriptive skill files above. Find them relative to the package root (e.g., `node_modules/ts-procedures/docs/`):
|
|
148
|
+
|
|
149
|
+
| File | Covers |
|
|
150
|
+
|------|--------|
|
|
151
|
+
| `docs/core.md` | Procedures factory, Create, CreateStream, schema.input, error handling |
|
|
152
|
+
| `docs/streaming.md` | Streaming procedures, AbortSignal, SSE patterns |
|
|
153
|
+
| `docs/http-integrations.md` | Express RPC, Hono RPC/Stream/API builders, DocRegistry |
|
|
154
|
+
| `docs/client-and-codegen.md` | Client code generation, createClient, CLI options |
|
|
155
|
+
|
|
156
|
+
## Workflow
|
|
140
157
|
|
|
141
|
-
|
|
142
|
-
For prescribed patterns with code examples, see `patterns.md`.
|
|
143
|
-
For common mistakes to avoid, see `anti-patterns.md`.
|
|
158
|
+
After planning with the **ts-procedures-architect** agent, use `/ts-procedures:scaffold <type> <Name>` to generate implementations. Use `/ts-procedures:review <path>` to validate existing code.
|
|
@@ -634,8 +634,9 @@ const app = await new HonoAPIAppBuilder()
|
|
|
634
634
|
| 12 | Create with HonoStreamAppBuilder | Procedures silently ignored | CRITICAL |
|
|
635
635
|
| 13 | Plain JSON Schema objects instead of TypeBox | ProcedureRegistrationError | CRITICAL |
|
|
636
636
|
| 14 | Wrong error handler for streams | Unhandled errors or wrong response format | WARNING |
|
|
637
|
-
| 15 | Manual doc building | Fragile, incomplete documentation | SUGGESTION |
|
|
638
|
-
| 16 |
|
|
639
|
-
| 17 |
|
|
640
|
-
| 18 |
|
|
641
|
-
| 19 |
|
|
637
|
+
| 15 | Manual doc building instead of extendProcedureDoc | Fragile, incomplete documentation | SUGGESTION |
|
|
638
|
+
| 16 | Manual /docs endpoint instead of DocRegistry | Duplicated boilerplate, missing error schemas | SUGGESTION |
|
|
639
|
+
| 17 | Unhandled async context factory | Request crashes | WARNING |
|
|
640
|
+
| 18 | Both schema.params and schema.input | ProcedureRegistrationError at startup | CRITICAL |
|
|
641
|
+
| 19 | Mismatched path param names | Build-time error or confusing validation failures | CRITICAL |
|
|
642
|
+
| 20 | Not awaiting HonoAPIAppBuilder.build() | Using unresolved Promise as app | CRITICAL |
|
|
@@ -1,54 +1,5 @@
|
|
|
1
1
|
# ts-procedures API Reference
|
|
2
2
|
|
|
3
|
-
## Imports
|
|
4
|
-
|
|
5
|
-
```typescript
|
|
6
|
-
// Core
|
|
7
|
-
import { Procedures } from 'ts-procedures'
|
|
8
|
-
import type {
|
|
9
|
-
TLocalContext,
|
|
10
|
-
TStreamContext,
|
|
11
|
-
TProcedureRegistration,
|
|
12
|
-
TStreamProcedureRegistration,
|
|
13
|
-
} from 'ts-procedures'
|
|
14
|
-
|
|
15
|
-
// Errors
|
|
16
|
-
import {
|
|
17
|
-
ProcedureError,
|
|
18
|
-
ProcedureValidationError,
|
|
19
|
-
ProcedureYieldValidationError,
|
|
20
|
-
ProcedureRegistrationError,
|
|
21
|
-
} from 'ts-procedures'
|
|
22
|
-
|
|
23
|
-
// Schema utilities
|
|
24
|
-
import { extractJsonSchema } from 'ts-procedures'
|
|
25
|
-
import { schemaParser } from 'ts-procedures'
|
|
26
|
-
import { isTypeboxSchema } from 'ts-procedures'
|
|
27
|
-
import type { TSchemaLib, TSchemaLibGenerator, TJSONSchema, TSchemaParsed, TSchemaValidationError } from 'ts-procedures'
|
|
28
|
-
|
|
29
|
-
// Stack utilities
|
|
30
|
-
import { captureDefinitionInfo, formatDefinitionInfo } from 'ts-procedures'
|
|
31
|
-
import type { DefinitionLocation, DefinitionInfo } from 'ts-procedures'
|
|
32
|
-
|
|
33
|
-
// HTTP types (types only, no runtime)
|
|
34
|
-
import type { RPCConfig, RPCHttpRouteDoc, StreamHttpRouteDoc, StreamMode, APIConfig, APIHttpRouteDoc, APIInput, HttpMethod } from 'ts-procedures/http'
|
|
35
|
-
|
|
36
|
-
// Express RPC
|
|
37
|
-
import { ExpressRPCAppBuilder } from 'ts-procedures/express-rpc'
|
|
38
|
-
|
|
39
|
-
// Hono RPC
|
|
40
|
-
import { HonoRPCAppBuilder } from 'ts-procedures/hono-rpc'
|
|
41
|
-
|
|
42
|
-
// Hono Streaming
|
|
43
|
-
import { HonoStreamAppBuilder, sse } from 'ts-procedures/hono-stream'
|
|
44
|
-
|
|
45
|
-
// Hono API (REST-style)
|
|
46
|
-
import { HonoAPIAppBuilder } from 'ts-procedures/hono-api'
|
|
47
|
-
import type { APIConfig, APIHttpRouteDoc, APIInput, HttpMethod } from 'ts-procedures/hono-api'
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
---
|
|
51
|
-
|
|
52
3
|
## Procedures\<TContext, TExtendedConfig\>(builder?)
|
|
53
4
|
|
|
54
5
|
Factory function that creates a scoped procedure registration system.
|
|
@@ -985,3 +936,63 @@ type DefinitionInfo = {
|
|
|
985
936
|
definitionStack?: string
|
|
986
937
|
}
|
|
987
938
|
```
|
|
939
|
+
|
|
940
|
+
---
|
|
941
|
+
|
|
942
|
+
## Imports
|
|
943
|
+
|
|
944
|
+
```typescript
|
|
945
|
+
// Core
|
|
946
|
+
import { Procedures } from 'ts-procedures'
|
|
947
|
+
import type {
|
|
948
|
+
TLocalContext,
|
|
949
|
+
TStreamContext,
|
|
950
|
+
TProcedureRegistration,
|
|
951
|
+
TStreamProcedureRegistration,
|
|
952
|
+
} from 'ts-procedures'
|
|
953
|
+
|
|
954
|
+
// Errors
|
|
955
|
+
import {
|
|
956
|
+
ProcedureError,
|
|
957
|
+
ProcedureValidationError,
|
|
958
|
+
ProcedureYieldValidationError,
|
|
959
|
+
ProcedureRegistrationError,
|
|
960
|
+
} from 'ts-procedures'
|
|
961
|
+
|
|
962
|
+
// Schema utilities
|
|
963
|
+
import { extractJsonSchema } from 'ts-procedures'
|
|
964
|
+
import { schemaParser } from 'ts-procedures'
|
|
965
|
+
import { isTypeboxSchema } from 'ts-procedures'
|
|
966
|
+
import type { TSchemaLib, TSchemaLibGenerator, TJSONSchema, TSchemaParsed, TSchemaValidationError } from 'ts-procedures'
|
|
967
|
+
|
|
968
|
+
// Stack utilities
|
|
969
|
+
import { captureDefinitionInfo, formatDefinitionInfo } from 'ts-procedures'
|
|
970
|
+
import type { DefinitionLocation, DefinitionInfo } from 'ts-procedures'
|
|
971
|
+
|
|
972
|
+
// HTTP types (types only, no runtime)
|
|
973
|
+
import type { RPCConfig, RPCHttpRouteDoc, StreamHttpRouteDoc, StreamMode, APIConfig, APIHttpRouteDoc, APIInput, HttpMethod } from 'ts-procedures/http'
|
|
974
|
+
|
|
975
|
+
// Express RPC
|
|
976
|
+
import { ExpressRPCAppBuilder } from 'ts-procedures/express-rpc'
|
|
977
|
+
|
|
978
|
+
// Hono RPC
|
|
979
|
+
import { HonoRPCAppBuilder } from 'ts-procedures/hono-rpc'
|
|
980
|
+
|
|
981
|
+
// Hono Streaming
|
|
982
|
+
import { HonoStreamAppBuilder, sse } from 'ts-procedures/hono-stream'
|
|
983
|
+
|
|
984
|
+
// Hono API (REST-style)
|
|
985
|
+
import { HonoAPIAppBuilder } from 'ts-procedures/hono-api'
|
|
986
|
+
import type { APIConfig, APIHttpRouteDoc, APIInput, HttpMethod } from 'ts-procedures/hono-api'
|
|
987
|
+
|
|
988
|
+
// Client
|
|
989
|
+
import { createClient, createFetchAdapter } from 'ts-procedures/client'
|
|
990
|
+
import type { ClientAdapter, ClientHooks, ClientInstance, TypedStream } from 'ts-procedures/client'
|
|
991
|
+
|
|
992
|
+
// Code generation
|
|
993
|
+
import { generateClient } from 'ts-procedures/codegen'
|
|
994
|
+
|
|
995
|
+
// Documentation
|
|
996
|
+
import { DocRegistry } from 'ts-procedures/http-docs'
|
|
997
|
+
import type { DocEnvelope, DocSource, HeaderDoc, ErrorDoc } from 'ts-procedures/http-docs'
|
|
998
|
+
```
|
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: review
|
|
3
|
-
description: "Review code for
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Usage: /ts-procedures:review <path>
|
|
9
|
-
|
|
10
|
-
Reviews files at the given path for ts-procedures pattern adherence.
|
|
11
|
-
Accepts a file path or directory.
|
|
12
|
-
|
|
13
|
-
Examples:
|
|
14
|
-
/ts-procedures:review src/procedures/
|
|
15
|
-
/ts-procedures:review src/procedures/GetUser.procedure.ts
|
|
3
|
+
description: "Review ts-procedures code for pattern adherence, schema correctness, error handling, and signal propagation."
|
|
4
|
+
argument-hint: "<path>"
|
|
5
|
+
allowed-tools: Read Grep Glob
|
|
6
|
+
context: fork
|
|
7
|
+
effort: high
|
|
16
8
|
---
|
|
17
9
|
|
|
18
10
|
# Review ts-procedures Code
|
|
@@ -22,9 +14,10 @@ Parse `$ARGUMENTS` as a file or directory path. If a directory, review all `.ts`
|
|
|
22
14
|
## Instructions
|
|
23
15
|
|
|
24
16
|
1. Read the target file(s).
|
|
25
|
-
2. Identify ts-procedures imports (`ts-procedures`, `ts-procedures/express-rpc`, `ts-procedures/hono-rpc`, `ts-procedures/hono-stream`, `ts-procedures/http`) to determine file types.
|
|
26
|
-
3. Check each file against the categorized checklist in
|
|
27
|
-
4.
|
|
17
|
+
2. Identify ts-procedures imports (`ts-procedures`, `ts-procedures/express-rpc`, `ts-procedures/hono-rpc`, `ts-procedures/hono-stream`, `ts-procedures/hono-api`, `ts-procedures/http`, `ts-procedures/http-docs`) to determine file types.
|
|
18
|
+
3. Check each file against the categorized checklist in [checklist.md](checklist.md).
|
|
19
|
+
4. For detailed code examples of each violation pattern, reference [anti-patterns.md](../guide/anti-patterns.md) — it shows 20 common mistakes with before/after code fixes and severity ratings.
|
|
20
|
+
5. Output findings grouped by severity.
|
|
28
21
|
|
|
29
22
|
## Output Format
|
|
30
23
|
|
|
@@ -47,7 +40,9 @@ After individual findings, provide:
|
|
|
47
40
|
- Total findings by severity
|
|
48
41
|
- Overall assessment (healthy / needs attention / significant issues)
|
|
49
42
|
- Top 3 priorities to address
|
|
43
|
+
- If structural issues found, suggest `/ts-procedures:scaffold <type> <Name>` to generate correct implementations
|
|
50
44
|
|
|
51
45
|
## Reference
|
|
52
46
|
|
|
53
|
-
See
|
|
47
|
+
See [checklist.md](checklist.md) for the complete categorized checklist by file type.
|
|
48
|
+
See [anti-patterns.md](../guide/anti-patterns.md) for detailed code examples of each violation.
|
|
@@ -1,38 +1,28 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: scaffold
|
|
3
|
-
description: "
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
- model
|
|
7
|
-
user_instructions: |
|
|
8
|
-
Usage: /ts-procedures:scaffold <type> <Name>
|
|
9
|
-
|
|
10
|
-
Types: procedure, stream-procedure, express-rpc, hono-rpc, hono-stream, hono-api
|
|
11
|
-
|
|
12
|
-
Examples:
|
|
13
|
-
/ts-procedures:scaffold procedure GetUser
|
|
14
|
-
/ts-procedures:scaffold stream-procedure StreamActivity
|
|
15
|
-
/ts-procedures:scaffold express-rpc UserApi
|
|
16
|
-
/ts-procedures:scaffold hono-rpc OrderApi
|
|
17
|
-
/ts-procedures:scaffold hono-stream LiveFeed
|
|
18
|
-
/ts-procedures:scaffold hono-api ProductApi
|
|
3
|
+
description: "Generate ts-procedures implementations with correct patterns — procedures, streams, Express RPC, Hono RPC, Hono streaming, REST APIs, and client setup."
|
|
4
|
+
argument-hint: "<type> <Name>"
|
|
5
|
+
allowed-tools: Read Write
|
|
19
6
|
---
|
|
20
7
|
|
|
21
8
|
# Scaffold ts-procedures Code
|
|
22
9
|
|
|
23
|
-
|
|
10
|
+
Scaffold a `$0` ts-procedures implementation named `$1`.
|
|
11
|
+
|
|
12
|
+
If either argument is missing, ask the user for `<type>` and `<Name>`.
|
|
24
13
|
|
|
25
14
|
## Instructions
|
|
26
15
|
|
|
27
|
-
1.
|
|
28
|
-
2.
|
|
16
|
+
1. Validate `$0` is a recognized type (see table below). Case-insensitive.
|
|
17
|
+
2. Validate `$1` is PascalCase (e.g., `UserProfile`).
|
|
18
|
+
3. Derive placeholder variants from the provided PascalCase Name:
|
|
29
19
|
- `{{Name}}` — PascalCase as given (e.g., `UserProfile`)
|
|
30
20
|
- `{{name}}` — camelCase (e.g., `userProfile`)
|
|
31
21
|
- For URL scopes and file paths, use kebab-case (e.g., `user-profile`)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
22
|
+
4. Read the template file from `${CLAUDE_SKILL_DIR}/templates/$0.md`.
|
|
23
|
+
5. Replace all `{{Name}}` and `{{name}}` placeholders with the appropriate variants.
|
|
24
|
+
6. Generate the implementation file(s) following the template exactly.
|
|
25
|
+
7. Also generate a colocated test file following ts-procedures test conventions.
|
|
36
26
|
|
|
37
27
|
## Valid Types
|
|
38
28
|
|
|
@@ -44,6 +34,7 @@ Parse `$ARGUMENTS` as `<type> <Name>` (case-insensitive type, PascalCase Name).
|
|
|
44
34
|
| `hono-rpc` | `templates/hono-rpc.md` | `{{Name}}.rpc.ts`, `{{Name}}.rpc.test.ts` |
|
|
45
35
|
| `hono-stream` | `templates/hono-stream.md` | `{{Name}}.stream-rpc.ts`, `{{Name}}.stream-rpc.test.ts` |
|
|
46
36
|
| `hono-api` | `templates/hono-api.md` | `{{Name}}.api.ts`, `{{Name}}.api.test.ts` |
|
|
37
|
+
| `client` | `templates/client.md` | `{{Name}}.client.ts`, `{{Name}}.client.test.ts` |
|
|
47
38
|
|
|
48
39
|
## Rules
|
|
49
40
|
|
|
@@ -54,3 +45,7 @@ Parse `$ARGUMENTS` as `<type> <Name>` (case-insensitive type, PascalCase Name).
|
|
|
54
45
|
- Use TypeBox for schema definitions (`import { Type } from 'typebox'`).
|
|
55
46
|
- AJV config: `allErrors: true`, `coerceTypes: true`, `removeAdditional: true`.
|
|
56
47
|
- Test files use `describe`/`test` from vitest.
|
|
48
|
+
|
|
49
|
+
## Workflow
|
|
50
|
+
|
|
51
|
+
Use the **ts-procedures-architect** agent to plan your API structure first, then scaffold each procedure. After scaffolding, use `/ts-procedures:review <path>` to validate the implementation.
|