ts-procedures 5.16.0 → 6.0.1

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.
Files changed (147) hide show
  1. package/README.md +2 -0
  2. package/agent_config/claude-code/agents/ts-procedures-architect.md +13 -6
  3. package/agent_config/claude-code/skills/ts-procedures/SKILL.md +26 -4
  4. package/agent_config/claude-code/skills/ts-procedures/anti-patterns.md +87 -19
  5. package/agent_config/claude-code/skills/ts-procedures/api-reference.md +162 -16
  6. package/agent_config/claude-code/skills/ts-procedures/patterns.md +179 -16
  7. package/agent_config/claude-code/skills/ts-procedures-review/SKILL.md +1 -1
  8. package/agent_config/claude-code/skills/ts-procedures-review/checklist.md +20 -12
  9. package/agent_config/claude-code/skills/ts-procedures-scaffold/SKILL.md +2 -1
  10. package/agent_config/claude-code/skills/ts-procedures-scaffold/templates/client.md +22 -15
  11. package/agent_config/claude-code/skills/ts-procedures-scaffold/templates/express-rpc.md +20 -17
  12. package/agent_config/claude-code/skills/ts-procedures-scaffold/templates/hono-api.md +20 -16
  13. package/agent_config/claude-code/skills/ts-procedures-scaffold/templates/hono-rpc.md +20 -17
  14. package/agent_config/claude-code/skills/ts-procedures-scaffold/templates/hono-stream.md +16 -3
  15. package/agent_config/copilot/copilot-instructions.md +78 -12
  16. package/agent_config/cursor/cursorrules +78 -12
  17. package/build/client/call.d.ts +2 -1
  18. package/build/client/call.js +9 -1
  19. package/build/client/call.js.map +1 -1
  20. package/build/client/error-dispatch.d.ts +13 -0
  21. package/build/client/error-dispatch.js +26 -0
  22. package/build/client/error-dispatch.js.map +1 -0
  23. package/build/client/error-dispatch.test.d.ts +1 -0
  24. package/build/client/error-dispatch.test.js +56 -0
  25. package/build/client/error-dispatch.test.js.map +1 -0
  26. package/build/client/fetch-adapter.js +10 -4
  27. package/build/client/fetch-adapter.js.map +1 -1
  28. package/build/client/index.d.ts +2 -1
  29. package/build/client/index.js +5 -1
  30. package/build/client/index.js.map +1 -1
  31. package/build/client/stream.d.ts +2 -1
  32. package/build/client/stream.js +13 -3
  33. package/build/client/stream.js.map +1 -1
  34. package/build/client/typed-error-dispatch.test.d.ts +1 -0
  35. package/build/client/typed-error-dispatch.test.js +168 -0
  36. package/build/client/typed-error-dispatch.test.js.map +1 -0
  37. package/build/client/types.d.ts +37 -0
  38. package/build/codegen/e2e.test.js +9 -4
  39. package/build/codegen/e2e.test.js.map +1 -1
  40. package/build/codegen/emit-client-runtime.js +4 -0
  41. package/build/codegen/emit-client-runtime.js.map +1 -1
  42. package/build/codegen/emit-errors.d.ts +17 -6
  43. package/build/codegen/emit-errors.integration.test.d.ts +1 -0
  44. package/build/codegen/emit-errors.integration.test.js +162 -0
  45. package/build/codegen/emit-errors.integration.test.js.map +1 -0
  46. package/build/codegen/emit-errors.js +50 -39
  47. package/build/codegen/emit-errors.js.map +1 -1
  48. package/build/codegen/emit-errors.test.js +75 -78
  49. package/build/codegen/emit-errors.test.js.map +1 -1
  50. package/build/codegen/emit-index.d.ts +7 -0
  51. package/build/codegen/emit-index.js +26 -4
  52. package/build/codegen/emit-index.js.map +1 -1
  53. package/build/codegen/emit-index.test.js +55 -23
  54. package/build/codegen/emit-index.test.js.map +1 -1
  55. package/build/codegen/emit-scope.d.ts +8 -0
  56. package/build/codegen/emit-scope.js +82 -7
  57. package/build/codegen/emit-scope.js.map +1 -1
  58. package/build/codegen/pipeline.js +22 -2
  59. package/build/codegen/pipeline.js.map +1 -1
  60. package/build/implementations/http/doc-registry.d.ts +17 -1
  61. package/build/implementations/http/doc-registry.js +47 -79
  62. package/build/implementations/http/doc-registry.js.map +1 -1
  63. package/build/implementations/http/doc-registry.test.js +149 -16
  64. package/build/implementations/http/doc-registry.test.js.map +1 -1
  65. package/build/implementations/http/error-taxonomy.d.ts +249 -0
  66. package/build/implementations/http/error-taxonomy.js +252 -0
  67. package/build/implementations/http/error-taxonomy.js.map +1 -0
  68. package/build/implementations/http/error-taxonomy.test.d.ts +1 -0
  69. package/build/implementations/http/error-taxonomy.test.js +399 -0
  70. package/build/implementations/http/error-taxonomy.test.js.map +1 -0
  71. package/build/implementations/http/express-rpc/error-taxonomy.test.d.ts +1 -0
  72. package/build/implementations/http/express-rpc/error-taxonomy.test.js +83 -0
  73. package/build/implementations/http/express-rpc/error-taxonomy.test.js.map +1 -0
  74. package/build/implementations/http/express-rpc/index.d.ts +39 -8
  75. package/build/implementations/http/express-rpc/index.js +39 -8
  76. package/build/implementations/http/express-rpc/index.js.map +1 -1
  77. package/build/implementations/http/hono-api/error-taxonomy.test.d.ts +1 -0
  78. package/build/implementations/http/hono-api/error-taxonomy.test.js +137 -0
  79. package/build/implementations/http/hono-api/error-taxonomy.test.js.map +1 -0
  80. package/build/implementations/http/hono-api/index.d.ts +38 -1
  81. package/build/implementations/http/hono-api/index.js +32 -0
  82. package/build/implementations/http/hono-api/index.js.map +1 -1
  83. package/build/implementations/http/hono-rpc/error-taxonomy.test.d.ts +1 -0
  84. package/build/implementations/http/hono-rpc/error-taxonomy.test.js +64 -0
  85. package/build/implementations/http/hono-rpc/error-taxonomy.test.js.map +1 -0
  86. package/build/implementations/http/hono-rpc/index.d.ts +34 -7
  87. package/build/implementations/http/hono-rpc/index.js +31 -4
  88. package/build/implementations/http/hono-rpc/index.js.map +1 -1
  89. package/build/implementations/http/hono-stream/error-taxonomy.test.d.ts +1 -0
  90. package/build/implementations/http/hono-stream/error-taxonomy.test.js +87 -0
  91. package/build/implementations/http/hono-stream/error-taxonomy.test.js.map +1 -0
  92. package/build/implementations/http/hono-stream/index.d.ts +40 -3
  93. package/build/implementations/http/hono-stream/index.js +37 -10
  94. package/build/implementations/http/hono-stream/index.js.map +1 -1
  95. package/build/implementations/http/hono-stream/index.test.js +45 -18
  96. package/build/implementations/http/hono-stream/index.test.js.map +1 -1
  97. package/build/implementations/http/on-request-error.test.d.ts +1 -0
  98. package/build/implementations/http/on-request-error.test.js +173 -0
  99. package/build/implementations/http/on-request-error.test.js.map +1 -0
  100. package/build/implementations/http/route-errors.test.d.ts +1 -0
  101. package/build/implementations/http/route-errors.test.js +139 -0
  102. package/build/implementations/http/route-errors.test.js.map +1 -0
  103. package/build/implementations/types.d.ts +43 -3
  104. package/docs/client-and-codegen.md +105 -12
  105. package/docs/core.md +14 -5
  106. package/docs/http-integrations.md +138 -5
  107. package/docs/streaming.md +3 -1
  108. package/docs/superpowers/plans/2026-04-24-doc-registry-simplification.md +886 -0
  109. package/package.json +7 -2
  110. package/src/client/call.ts +10 -1
  111. package/src/client/error-dispatch.test.ts +72 -0
  112. package/src/client/error-dispatch.ts +27 -0
  113. package/src/client/fetch-adapter.ts +11 -5
  114. package/src/client/index.ts +9 -0
  115. package/src/client/stream.ts +14 -3
  116. package/src/client/typed-error-dispatch.test.ts +211 -0
  117. package/src/client/types.ts +42 -0
  118. package/src/codegen/e2e.test.ts +9 -4
  119. package/src/codegen/emit-client-runtime.ts +4 -0
  120. package/src/codegen/emit-errors.integration.test.ts +183 -0
  121. package/src/codegen/emit-errors.test.ts +91 -87
  122. package/src/codegen/emit-errors.ts +123 -41
  123. package/src/codegen/emit-index.test.ts +68 -24
  124. package/src/codegen/emit-index.ts +66 -4
  125. package/src/codegen/emit-scope.ts +124 -7
  126. package/src/codegen/pipeline.ts +25 -2
  127. package/src/implementations/http/README.md +21 -7
  128. package/src/implementations/http/doc-registry.test.ts +164 -16
  129. package/src/implementations/http/doc-registry.ts +58 -82
  130. package/src/implementations/http/error-taxonomy.test.ts +438 -0
  131. package/src/implementations/http/error-taxonomy.ts +361 -0
  132. package/src/implementations/http/express-rpc/README.md +23 -24
  133. package/src/implementations/http/express-rpc/error-taxonomy.test.ts +103 -0
  134. package/src/implementations/http/express-rpc/index.ts +75 -14
  135. package/src/implementations/http/hono-api/README.md +284 -0
  136. package/src/implementations/http/hono-api/error-taxonomy.test.ts +179 -0
  137. package/src/implementations/http/hono-api/index.ts +76 -1
  138. package/src/implementations/http/hono-rpc/README.md +20 -21
  139. package/src/implementations/http/hono-rpc/error-taxonomy.test.ts +82 -0
  140. package/src/implementations/http/hono-rpc/index.ts +65 -9
  141. package/src/implementations/http/hono-stream/README.md +44 -25
  142. package/src/implementations/http/hono-stream/error-taxonomy.test.ts +98 -0
  143. package/src/implementations/http/hono-stream/index.test.ts +54 -18
  144. package/src/implementations/http/hono-stream/index.ts +83 -13
  145. package/src/implementations/http/on-request-error.test.ts +201 -0
  146. package/src/implementations/http/route-errors.test.ts +176 -0
  147. package/src/implementations/types.ts +43 -3
@@ -1,59 +1,70 @@
1
- import { jsonSchemaToTypeString, jsonSchemaToExtractedTypes } from './emit-types.js';
1
+ import { jsonSchemaToTypeBody } from './emit-types.js';
2
2
  import { CODEGEN_HEADER } from './constants.js';
3
3
  import { toPascalCase } from './naming.js';
4
4
  /**
5
- * Generates a TypeScript file with error type declarations from the DocEnvelope.errors array.
5
+ * Generates a TypeScript file with runtime error classes (plus a registry
6
+ * object for dispatch) derived from `DocEnvelope.errors`.
6
7
  *
7
- * Only errors with a `schema` property are included. If no errors have schemas,
8
- * returns `undefined` (no file generated).
8
+ * For each error with a schema, emits:
9
+ * - `interface <Name>Body { ... }` typed response body
10
+ * - `class <Name> extends <ServiceName>ProcedureError<<Name>Body>` with
11
+ * constructor + static `fromResponse(body, meta)`
9
12
  *
10
- * When `namespaceTypes` is true, wraps in `export namespace Errors { ... }`
11
- * (or `${ServiceName}Errors` with `serviceName`). The union type is similarly
12
- * prefixed: `ProcedureErrorUnion` `${ServiceName}ProcedureErrorUnion`.
13
+ * The shared base `<ServiceName>ProcedureError` is emitted so consumers can
14
+ * `catch (e) { if (e instanceof ApiErrors.ApiProcedureError) ... }` to handle
15
+ * any service error in one block. `instanceof` works across bundler boundaries
16
+ * because the generated file holds the sole class definition at runtime.
17
+ *
18
+ * The registry `<ServiceName>ErrorRegistry` maps body `name` values to
19
+ * classes, consumed by the client's `dispatchTypedError` to produce typed
20
+ * errors instead of generic `ClientRequestError` instances.
21
+ *
22
+ * When `namespaceTypes` is on, everything is wrapped in `export namespace
23
+ * <ServiceName>Errors { ... }`. Returns `undefined` if no errors have schemas.
13
24
  */
14
25
  export async function emitErrorsFile(errors, options) {
15
26
  const { ajsc: ajscOpts, namespaceTypes = false, serviceName } = options ?? {};
16
27
  const servicePrefix = serviceName ? toPascalCase(serviceName) : '';
17
28
  const namespaceName = servicePrefix ? `${servicePrefix}Errors` : 'Errors';
29
+ const baseClassName = servicePrefix ? `${servicePrefix}ProcedureError` : 'ProcedureErrorBase';
18
30
  const unionName = servicePrefix ? `${servicePrefix}ProcedureErrorUnion` : 'ProcedureErrorUnion';
19
- // Filter to only errors that have a schema
31
+ const registryName = servicePrefix ? `${servicePrefix}ErrorRegistry` : 'ErrorRegistry';
20
32
  const errorsWithSchema = errors.filter((e) => e.schema != null);
21
33
  if (errorsWithSchema.length === 0) {
22
34
  return undefined;
23
35
  }
24
- const typeLines = [];
36
+ // Compute the typed body for each error by converting its schema to a TS type.
37
+ const entries = [];
38
+ for (const doc of errorsWithSchema) {
39
+ const bodyType = await jsonSchemaToTypeBody(doc.schema, ajscOpts);
40
+ entries.push({ doc, bodyType: bodyType ?? 'unknown' });
41
+ }
42
+ const lines = [];
43
+ const indent = namespaceTypes ? ' ' : '';
25
44
  if (namespaceTypes) {
26
- typeLines.push(`export namespace ${namespaceName} {`);
27
- for (const error of errorsWithSchema) {
28
- const result = await jsonSchemaToExtractedTypes(error.schema, ajscOpts);
29
- if (result != null) {
30
- typeLines.push(` /** ${error.description} (HTTP ${error.statusCode}) */`);
31
- for (const decl of result.declarations) {
32
- typeLines.push(` ${decl}`);
33
- }
34
- typeLines.push(` export type ${error.name} = ${result.body}`);
35
- typeLines.push('');
36
- }
37
- }
38
- const unionMembers = errorsWithSchema.map((e) => e.name).join(' | ');
39
- typeLines.push(` export type ${unionName} = ${unionMembers}`);
40
- typeLines.push('}');
41
- typeLines.push('');
45
+ lines.push(`export namespace ${namespaceName} {`);
42
46
  }
43
- else {
44
- for (const error of errorsWithSchema) {
45
- const typeDecl = await jsonSchemaToTypeString(error.name, error.schema, ajscOpts);
46
- if (typeDecl != null) {
47
- typeLines.push(`/** ${error.description} (HTTP ${error.statusCode}) */`);
48
- typeLines.push(typeDecl);
49
- typeLines.push('');
50
- }
51
- }
52
- const unionMembers = errorsWithSchema.map((e) => e.name).join(' | ');
53
- typeLines.push(`export type ${unionName} = ${unionMembers}`);
54
- typeLines.push('');
47
+ // Shared base class — lets consumers catch any service error with one check.
48
+ lines.push(`${indent}/** Base class for every generated error in this service. Catch with \`instanceof\`. */`, `${indent}export class ${baseClassName}<TBody = unknown> extends Error {`, `${indent} readonly status: number`, `${indent} readonly procedureName: string`, `${indent} readonly scope: string`, `${indent} readonly body: TBody`, `${indent} constructor(args: {`, `${indent} name: string`, `${indent} message: string`, `${indent} status: number`, `${indent} procedureName: string`, `${indent} scope: string`, `${indent} body: TBody`, `${indent} }) {`, `${indent} super(args.message)`, `${indent} this.name = args.name`, `${indent} this.status = args.status`, `${indent} this.procedureName = args.procedureName`, `${indent} this.scope = args.scope`, `${indent} this.body = args.body`, `${indent} Object.setPrototypeOf(this, new.target.prototype)`, `${indent} }`, `${indent}}`, '');
49
+ // Per-error body interface + class with fromResponse static factory.
50
+ for (const { doc, bodyType } of entries) {
51
+ const bodyInterfaceName = `${doc.name}Body`;
52
+ lines.push(`${indent}/** Response body for ${doc.name}. */`, `${indent}export type ${bodyInterfaceName} = ${bodyType}`, '');
53
+ const statusLiteral = doc.statusCode;
54
+ const descLine = doc.description
55
+ ? `${indent}/** ${doc.description} (HTTP ${statusLiteral}) */`
56
+ : `${indent}/** HTTP ${statusLiteral} */`;
57
+ lines.push(descLine, `${indent}export class ${doc.name} extends ${baseClassName}<${bodyInterfaceName}> {`, `${indent} static readonly errorName = '${doc.name}' as const`, `${indent} static readonly statusCode = ${statusLiteral}`, `${indent} static fromResponse(`, `${indent} body: ${bodyInterfaceName},`, `${indent} meta: { status: number; procedureName: string; scope: string }`, `${indent} ): ${doc.name} {`, `${indent} const message =`, `${indent} body && typeof (body as { message?: unknown }).message === 'string'`, `${indent} ? (body as { message: string }).message`, `${indent} : '${doc.name}'`, `${indent} return new ${doc.name}({`, `${indent} name: '${doc.name}',`, `${indent} message,`, `${indent} status: meta.status,`, `${indent} procedureName: meta.procedureName,`, `${indent} scope: meta.scope,`, `${indent} body,`, `${indent} })`, `${indent} }`, `${indent}}`, '');
58
+ }
59
+ // Union type — every generated error class instance.
60
+ const unionMembers = entries.map((e) => e.doc.name).join(' | ');
61
+ lines.push(`${indent}/** Union of every generated error in this service. */`, `${indent}export type ${unionName} = ${unionMembers}`, '');
62
+ // Registry for runtime dispatch — keyed by body.name.
63
+ lines.push(`${indent}/** Runtime registry consumed by the client to dispatch by \`body.name\`. */`, `${indent}export const ${registryName} = {`, ...entries.map((e) => `${indent} ${e.doc.name},`), `${indent}} as const`, '');
64
+ if (namespaceTypes) {
65
+ lines.push('}');
66
+ lines.push('');
55
67
  }
56
- const body = typeLines.join('\n');
57
- return [CODEGEN_HEADER, '', body].join('\n');
68
+ return [CODEGEN_HEADER, '', lines.join('\n')].join('\n');
58
69
  }
59
70
  //# sourceMappingURL=emit-errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"emit-errors.js","sourceRoot":"","sources":["../../src/codegen/emit-errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,0BAA0B,EAAoB,MAAM,iBAAiB,CAAA;AAEtG,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAS1C;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,MAAkB,EAClB,OAA2B;IAE3B,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,GAAG,KAAK,EAAE,WAAW,EAAE,GAAG,OAAO,IAAI,EAAE,CAAA;IAC7E,MAAM,aAAa,GAAG,WAAW,CAAC,CAAC,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC,CAA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AAE,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAC/D,KAAK,CAAC,IAAI,CACR,GAAG,MAAM,wDAAwD,EACjE,GAAG,MAAM,eAAe,SAAS,MAAM,YAAY,EAAE,EACrD,EAAE,CACH,CAAA;IAED,sDAAsD;IACtD,KAAK,CAAC,IAAI,CACR,GAAG,MAAM,8EAA8E,EACvF,GAAG,MAAM,gBAAgB,YAAY,MAAM,EAC3C,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,MAAM,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,EAClD,GAAG,MAAM,YAAY,EACrB,EAAE,CACH,CAAA;IAED,IAAI,cAAc,EAAE,CAAC;QACnB,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QACf,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAChB,CAAC;IAED,OAAO,CAAC,cAAc,EAAE,EAAE,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAC1D,CAAC"}
@@ -42,133 +42,130 @@ const errorDocWithoutSchema = {
42
42
  // Tests
43
43
  // ---------------------------------------------------------------------------
44
44
  describe('emitErrorsFile', () => {
45
- it('generates types for errors with schemas', async () => {
45
+ it('generates a runtime class per error with schema', async () => {
46
46
  const result = await emitErrorsFile([procedureErrorDoc, validationErrorDoc]);
47
47
  expect(result).toBeDefined();
48
- expect(result).toContain('export type ProcedureError =');
49
- expect(result).toContain('export type ProcedureValidationError =');
48
+ expect(result).toContain('export class ProcedureError');
49
+ expect(result).toContain('export class ProcedureValidationError');
50
50
  });
51
- it('generates ProcedureErrorUnion discriminated union', async () => {
52
- const result = await emitErrorsFile([procedureErrorDoc, validationErrorDoc]);
51
+ it('emits a body type for each class', async () => {
52
+ const result = await emitErrorsFile([procedureErrorDoc]);
53
+ expect(result).toContain('export type ProcedureErrorBody =');
54
+ });
55
+ it('each class has a static fromResponse factory', async () => {
56
+ const result = await emitErrorsFile([procedureErrorDoc]);
57
+ expect(result).toContain('static fromResponse(');
58
+ expect(result).toContain("name: 'ProcedureError'");
59
+ });
60
+ it('emits a shared base class the errors extend', async () => {
61
+ const result = await emitErrorsFile([procedureErrorDoc]);
53
62
  expect(result).toBeDefined();
63
+ expect(result).toMatch(/export class ProcedureErrorBase<TBody = unknown> extends Error/);
64
+ expect(result).toContain('extends ProcedureErrorBase<ProcedureErrorBody>');
65
+ });
66
+ it('emits a discriminated union type', async () => {
67
+ const result = await emitErrorsFile([procedureErrorDoc, validationErrorDoc]);
54
68
  expect(result).toContain('export type ProcedureErrorUnion = ProcedureError | ProcedureValidationError');
55
69
  });
70
+ it('emits a runtime registry keyed by class name', async () => {
71
+ const result = await emitErrorsFile([procedureErrorDoc, validationErrorDoc]);
72
+ expect(result).toContain('export const ErrorRegistry = {');
73
+ expect(result).toMatch(/ProcedureError,/);
74
+ expect(result).toMatch(/ProcedureValidationError,/);
75
+ });
56
76
  it('includes JSDoc with statusCode and description', async () => {
57
77
  const result = await emitErrorsFile([procedureErrorDoc]);
58
- expect(result).toBeDefined();
59
78
  expect(result).toContain('/** An error thrown from within a procedure handler via ctx.error(). (HTTP 500) */');
60
79
  });
61
- it('includes JSDoc before the type declaration', async () => {
80
+ it('includes JSDoc before the concrete class declaration', async () => {
62
81
  const result = await emitErrorsFile([procedureErrorDoc]);
63
- expect(result).toBeDefined();
64
82
  const jsdocIdx = result.indexOf('/** An error thrown from within a procedure handler via ctx.error().');
65
- const typeIdx = result.indexOf('export type ProcedureError =');
66
- expect(jsdocIdx).toBeLessThan(typeIdx);
83
+ // Match only the concrete class (ProcedureError), not the base class
84
+ // (ProcedureErrorBase which is a prefix-collision).
85
+ const concreteClassIdx = result.indexOf('export class ProcedureError extends');
86
+ expect(jsdocIdx).toBeGreaterThan(-1);
87
+ expect(concreteClassIdx).toBeGreaterThan(jsdocIdx);
67
88
  });
68
89
  it('includes the auto-generated header comment', async () => {
69
90
  const result = await emitErrorsFile([procedureErrorDoc]);
70
- expect(result).toBeDefined();
71
91
  expect(result).toContain('// Auto-generated by ts-procedures-codegen — do not edit');
72
92
  });
73
93
  it('returns undefined when no errors have schemas', async () => {
74
94
  const result = await emitErrorsFile([errorDocWithoutSchema]);
75
95
  expect(result).toBeUndefined();
76
96
  });
77
- it('returns undefined for empty errors array', async () => {
97
+ it('returns undefined for an empty errors array', async () => {
78
98
  const result = await emitErrorsFile([]);
79
99
  expect(result).toBeUndefined();
80
100
  });
81
- it('skips errors without schema, includes those with schema', async () => {
82
- const result = await emitErrorsFile([procedureErrorDoc, errorDocWithoutSchema, validationErrorDoc]);
83
- expect(result).toBeDefined();
84
- expect(result).toContain('export type ProcedureError =');
85
- expect(result).toContain('export type ProcedureValidationError =');
86
- // UnknownError has no schema, so it should not appear as a type
87
- expect(result).not.toContain('export type UnknownError =');
88
- // But the union should only include the ones with schemas
89
- expect(result).toContain('ProcedureError | ProcedureValidationError');
90
- expect(result).not.toContain('UnknownError');
91
- });
92
- it('union type has single type when only one error has schema', async () => {
93
- const result = await emitErrorsFile([procedureErrorDoc]);
94
- expect(result).toBeDefined();
95
- expect(result).toContain('export type ProcedureErrorUnion = ProcedureError');
96
- });
97
- it('union type does not include errros without schemas', async () => {
98
- const result = await emitErrorsFile([procedureErrorDoc, errorDocWithoutSchema]);
99
- expect(result).toBeDefined();
101
+ it('skips errors without schema, emits classes for the rest', async () => {
102
+ const result = await emitErrorsFile([
103
+ procedureErrorDoc,
104
+ errorDocWithoutSchema,
105
+ validationErrorDoc,
106
+ ]);
107
+ expect(result).toContain('export class ProcedureError');
108
+ expect(result).toContain('export class ProcedureValidationError');
109
+ expect(result).not.toContain('export class UnknownError');
100
110
  expect(result).not.toContain('UnknownError');
101
- expect(result).toContain('export type ProcedureErrorUnion = ProcedureError');
102
111
  });
103
- it('respects ajscOpts passed to jsonSchemaToTypeString', async () => {
104
- // Just verify it does not crash when options are passed — behavior is tested in emit-types.test.ts
112
+ it('accepts ajsc options without crashing', async () => {
105
113
  const result = await emitErrorsFile([procedureErrorDoc], { ajsc: { enumStyle: 'union' } });
106
114
  expect(result).toBeDefined();
107
- expect(result).toContain('export type ProcedureError =');
115
+ expect(result).toContain('export class ProcedureError');
108
116
  });
109
117
  describe('serviceName', () => {
110
- it('uses Errors namespace by default', async () => {
111
- const result = await emitErrorsFile([procedureErrorDoc, validationErrorDoc], { namespaceTypes: true });
118
+ it('uses Errors namespace by default in namespace mode', async () => {
119
+ const result = await emitErrorsFile([procedureErrorDoc], { namespaceTypes: true });
112
120
  expect(result).toContain('export namespace Errors {');
113
121
  });
114
- it('prefixes namespace with serviceName when provided', async () => {
115
- const result = await emitErrorsFile([procedureErrorDoc, validationErrorDoc], { namespaceTypes: true, serviceName: 'Auth' });
122
+ it('prefixes namespace with serviceName', async () => {
123
+ const result = await emitErrorsFile([procedureErrorDoc], {
124
+ namespaceTypes: true,
125
+ serviceName: 'Auth',
126
+ });
116
127
  expect(result).toContain('export namespace AuthErrors {');
117
128
  expect(result).not.toContain('export namespace Errors {');
118
129
  });
119
- it('PascalCases a kebab-case serviceName for namespace', async () => {
120
- const result = await emitErrorsFile([procedureErrorDoc], { namespaceTypes: true, serviceName: 'user-service' });
130
+ it('PascalCases a kebab-case serviceName', async () => {
131
+ const result = await emitErrorsFile([procedureErrorDoc], {
132
+ namespaceTypes: true,
133
+ serviceName: 'user-service',
134
+ });
121
135
  expect(result).toContain('export namespace UserServiceErrors {');
122
136
  });
123
- it('does not affect namespace when namespaceTypes is false', async () => {
124
- const result = await emitErrorsFile([procedureErrorDoc], { namespaceTypes: false, serviceName: 'Auth' });
125
- expect(result).toBeDefined();
126
- expect(result).not.toContain('namespace');
127
- });
128
- it('prefixes ProcedureErrorUnion in flat mode when serviceName is set', async () => {
129
- const result = await emitErrorsFile([procedureErrorDoc, validationErrorDoc], { namespaceTypes: false, serviceName: 'Auth' });
130
- expect(result).toBeDefined();
137
+ it('prefixes base class, union, and registry when serviceName is set', async () => {
138
+ const result = await emitErrorsFile([procedureErrorDoc, validationErrorDoc], {
139
+ serviceName: 'Auth',
140
+ });
141
+ expect(result).toMatch(/export class AuthProcedureError<TBody = unknown> extends Error/);
131
142
  expect(result).toContain('export type AuthProcedureErrorUnion = ProcedureError | ProcedureValidationError');
132
- expect(result).not.toContain('export type ProcedureErrorUnion =');
143
+ expect(result).toContain('export const AuthErrorRegistry = {');
133
144
  });
134
- it('prefixes ProcedureErrorUnion inside namespace when serviceName is set', async () => {
135
- const result = await emitErrorsFile([procedureErrorDoc], { namespaceTypes: true, serviceName: 'Auth' });
136
- expect(result).toBeDefined();
137
- expect(result).toContain('AuthProcedureErrorUnion');
138
- expect(result).not.toMatch(/\bexport type ProcedureErrorUnion\b/);
139
- });
140
- it('leaves ProcedureErrorUnion unprefixed when no serviceName', async () => {
141
- const result = await emitErrorsFile([procedureErrorDoc], { namespaceTypes: false });
142
- expect(result).toBeDefined();
145
+ it('leaves names unprefixed when no serviceName', async () => {
146
+ const result = await emitErrorsFile([procedureErrorDoc]);
147
+ expect(result).toMatch(/export class ProcedureErrorBase<TBody = unknown> extends Error/);
143
148
  expect(result).toContain('export type ProcedureErrorUnion = ProcedureError');
149
+ expect(result).toContain('export const ErrorRegistry = {');
144
150
  });
145
151
  });
146
152
  describe('namespaceTypes', () => {
147
- it('wraps error types in export namespace Errors', async () => {
148
- const result = await emitErrorsFile([procedureErrorDoc, validationErrorDoc], { namespaceTypes: true });
149
- expect(result).toBeDefined();
153
+ it('wraps classes and registry in export namespace', async () => {
154
+ const result = await emitErrorsFile([procedureErrorDoc, validationErrorDoc], {
155
+ namespaceTypes: true,
156
+ });
150
157
  expect(result).toContain('export namespace Errors {');
151
- expect(result).toContain('export type ProcedureError =');
152
- expect(result).toContain('export type ProcedureValidationError =');
153
- });
154
- it('places union inside the namespace', async () => {
155
- const result = await emitErrorsFile([procedureErrorDoc, validationErrorDoc], { namespaceTypes: true });
156
- expect(result).toBeDefined();
157
- expect(result).toContain('export type ProcedureErrorUnion = ProcedureError | ProcedureValidationError');
158
- // Union should be inside the namespace (indented)
159
- const lines = result.split('\n');
160
- const unionLine = lines.find((l) => l.includes('ProcedureErrorUnion'));
161
- expect(unionLine).toMatch(/^\s+export type ProcedureErrorUnion/);
158
+ expect(result).toContain('export class ProcedureError');
159
+ expect(result).toContain('export const ErrorRegistry = {');
162
160
  });
163
- it('includes JSDoc inside namespace', async () => {
161
+ it('contents are indented inside the namespace block', async () => {
164
162
  const result = await emitErrorsFile([procedureErrorDoc], { namespaceTypes: true });
165
- expect(result).toBeDefined();
166
- expect(result).toContain('(HTTP 500)');
163
+ const classLine = result.split('\n').find((l) => l.includes('export class ProcedureError'));
164
+ expect(classLine).toMatch(/^\s{2}export class ProcedureError/);
167
165
  });
168
166
  it('flat mode does not wrap in namespace', async () => {
169
167
  const result = await emitErrorsFile([procedureErrorDoc], { namespaceTypes: false });
170
- expect(result).toBeDefined();
171
- expect(result).not.toContain('export namespace Errors');
168
+ expect(result).not.toContain('export namespace');
172
169
  });
173
170
  });
174
171
  });
@@ -1 +1 @@
1
- {"version":3,"file":"emit-errors.test.js","sourceRoot":"","sources":["../../src/codegen/emit-errors.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAGjD,8EAA8E;AAC9E,WAAW;AACX,8EAA8E;AAE9E,MAAM,iBAAiB,GAAa;IAClC,IAAI,EAAE,gBAAgB;IACtB,UAAU,EAAE,GAAG;IACf,WAAW,EAAE,kEAAkE;IAC/E,MAAM,EAAE;QACN,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,gBAAgB,EAAE;YACjD,aAAa,E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CAAC,SAAS,CAAC,2BAA2B,CAAC,CAAA;YACrD,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,6BAA6B,CAAC,CAAA;YACvD,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,gCAAgC,CAAC,CAAA;QAC5D,CAAC,CAAC,CAAA;QAEF,EAAE,CAAC,kDAAkD,EAAE,KAAK,IAAI,EAAE;YAChE,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,CAAC,iBAAiB,CAAC,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,CAAA;YAClF,MAAM,SAAS,GAAG,MAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,6BAA6B,CAAC,CAAC,CAAA;YAC5F,MAAM,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,mCAAmC,CAAC,CAAA;QAChE,CAAC,CAAC,CAAA;QAEF,EAAE,CAAC,sCAAsC,EAAE,KAAK,IAAI,EAAE;YACpD,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,CAAC,iBAAiB,CAAC,EAAE,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC,CAAA;YACnF,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAA;QAClD,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -1,6 +1,13 @@
1
1
  import type { ScopeGroup } from './group-routes.js';
2
2
  export interface EmitIndexOptions {
3
+ /** Import specifier for types (`ClientInstance`, `CreateClientConfig`). */
3
4
  clientImportPath?: string;
5
+ /**
6
+ * Import specifier for runtime values (`createClient`). Defaults to
7
+ * `clientImportPath`. In self-contained mode the pipeline sets this to
8
+ * `./_client` while `clientImportPath` points at `./_types`.
9
+ */
10
+ clientRuntimeImportPath?: string;
4
11
  hasErrors?: boolean;
5
12
  namespaceTypes?: boolean;
6
13
  serviceName?: string;
@@ -11,16 +11,21 @@ const ERRORS_MODULE_ALIAS = '_errorsModule';
11
11
  */
12
12
  export function emitIndexFile(groups, options) {
13
13
  const { clientImportPath = 'ts-procedures/client', hasErrors = false, namespaceTypes = false, serviceName = 'Api', } = options ?? {};
14
+ const clientRuntimeImportPath = options?.clientRuntimeImportPath ?? clientImportPath;
14
15
  const servicePascal = toPascalCase(serviceName);
15
16
  const factoryName = `create${servicePascal}Bindings`;
17
+ const clientFactoryName = `create${servicePascal}Client`;
16
18
  const errorsExportedName = `${servicePascal}Errors`;
19
+ const registryName = `${servicePascal}ErrorRegistry`;
17
20
  // Underscore-prefix the local module alias so scope names that collide with
18
21
  // TypeScript reserved words (e.g. `public`, `default`, `class`) compile.
19
22
  const localAlias = (camelCase) => `_${camelCase}`;
20
23
  const scopeImports = groups
21
24
  .map((g) => `import * as ${localAlias(g.camelCase)} from './${g.scopeKey}'`)
22
25
  .join('\n');
23
- const errorsImport = namespaceTypes && hasErrors
26
+ // `_errors` is imported as a value (not `import type`) when errors exist, so
27
+ // the runtime registry is reachable for `createApiClient`.
28
+ const errorsImport = hasErrors
24
29
  ? `import * as ${ERRORS_MODULE_ALIAS} from './_errors'`
25
30
  : '';
26
31
  const importsBlock = [scopeImports, errorsImport].filter(Boolean).join('\n');
@@ -40,9 +45,10 @@ export function emitIndexFile(groups, options) {
40
45
  const scopeBindings = groups
41
46
  .map((g) => ` ${g.camelCase}: ${localAlias(g.camelCase)}.bind${toPascalCase(g.camelCase)}Scope(client),`)
42
47
  .join('\n');
43
- return [
48
+ const pieces = [
44
49
  CODEGEN_HEADER,
45
- `import type { ClientInstance } from '${clientImportPath}'`,
50
+ `import { createClient } from '${clientRuntimeImportPath}'`,
51
+ `import type { ClientInstance, CreateClientConfig } from '${clientImportPath}'`,
46
52
  importsBlock,
47
53
  '',
48
54
  namespaceBlock,
@@ -52,6 +58,22 @@ export function emitIndexFile(groups, options) {
52
58
  ' }',
53
59
  '}',
54
60
  '',
55
- ].join('\n');
61
+ ];
62
+ // `createApiClient` is a convenience wrapper that wires `createClient` with
63
+ // the generated error registry baked in, then invokes the bindings factory.
64
+ // Consumers that want manual control over `createClient` still use the
65
+ // factory above.
66
+ if (hasErrors) {
67
+ // In namespace mode, classes + registry live inside `${Service}Errors`;
68
+ // in flat mode they're at the module's top level.
69
+ const registryPath = namespaceTypes
70
+ ? `${ERRORS_MODULE_ALIAS}.${errorsExportedName}.${registryName}`
71
+ : `${ERRORS_MODULE_ALIAS}.${registryName}`;
72
+ pieces.push(`/**`, ` * Creates a typed client for this service with the generated error`, ` * registry pre-configured. Non-2xx responses whose body \`name\` matches`, ` * a registered error are thrown as typed class instances instead of`, ` * generic \`ClientRequestError\`s.`, ` */`, `export function ${clientFactoryName}(`, ` config: Omit<CreateClientConfig<ReturnType<typeof ${factoryName}>>, 'scopes' | 'errorRegistry'>`, `) {`, ` return createClient({`, ` ...config,`, ` errorRegistry: ${registryPath},`, ` scopes: (client) => ${factoryName}(client),`, ` })`, `}`, '');
73
+ }
74
+ else {
75
+ pieces.push(`/**`, ` * Creates a typed client for this service. No error registry is`, ` * attached because the DocEnvelope contained no typed errors.`, ` */`, `export function ${clientFactoryName}(`, ` config: Omit<CreateClientConfig<ReturnType<typeof ${factoryName}>>, 'scopes'>`, `) {`, ` return createClient({`, ` ...config,`, ` scopes: (client) => ${factoryName}(client),`, ` })`, `}`, '');
76
+ }
77
+ return pieces.join('\n');
56
78
  }
57
79
  //# sourceMappingURL=emit-index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"emit-index.js","sourceRoot":"","sources":["../../src/codegen/emit-index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C,MAAM,mBAAmB,GAAG,eAAe,CAAA;AAa3C;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAC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