@contractkit/plugin-typescript 0.27.0 → 0.28.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contractkit/plugin-typescript",
3
- "version": "0.27.0",
3
+ "version": "0.28.0",
4
4
  "description": "ContractKit built-in plugin: TypeScript codegen (SDK clients, Koa routers, Zod schemas, plain types)",
5
5
  "author": {
6
6
  "name": "Marooned Software",
@@ -29,8 +29,8 @@
29
29
  "@contractkit/core": "0.22.0"
30
30
  },
31
31
  "devDependencies": {
32
- "@repo/config-typescript": "0.1.0",
33
- "@repo/config-eslint": "0.3.1"
32
+ "@repo/config-eslint": "0.3.1",
33
+ "@repo/config-typescript": "0.1.0"
34
34
  },
35
35
  "scripts": {
36
36
  "build": "tsup src/index.ts --format esm --sourcemap --dts && tsc --emitDeclarationOnly --declaration",
@@ -277,14 +277,14 @@ function generateHandler(route: OpRouteNode, op: OpOperationNode, root: OpRootNo
277
277
  // Body validation (request-side — use Input variants)
278
278
  if (hasBody && op.request) {
279
279
  if (isSingleMultipart) {
280
- lines.push(` const multipartBody = ctx.body as MultipartBody;`);
280
+ lines.push(` const multipartBody = ctx.parsedBody as MultipartBody;`);
281
281
  lines.push('');
282
282
  } else if (bodies.length === 1) {
283
- lines.push(` const body = await parseAndValidate(ctx.body, ${renderInputType(bodies[0]!.bodyType, modelsWithInput)});`);
283
+ lines.push(` const body = await parseAndValidate(ctx.parsedBody, ${renderInputType(bodies[0]!.bodyType, modelsWithInput)});`);
284
284
  lines.push('');
285
285
  } else if (bodies.every(b => bodyTypesStructurallyEqual(b.bodyType, bodies[0]!.bodyType))) {
286
286
  // All declared MIMEs share the same body shape — single validation suffices
287
- lines.push(` const body = await parseAndValidate(ctx.body, ${renderInputType(bodies[0]!.bodyType, modelsWithInput)});`);
287
+ lines.push(` const body = await parseAndValidate(ctx.parsedBody, ${renderInputType(bodies[0]!.bodyType, modelsWithInput)});`);
288
288
  lines.push('');
289
289
  } else {
290
290
  // Different body types per MIME — dispatch on Content-Type
@@ -298,9 +298,9 @@ function generateHandler(route: OpRouteNode, op: OpOperationNode, root: OpRootNo
298
298
  for (const b of bodies) {
299
299
  lines.push(` case '${b.contentType}':`);
300
300
  if (b.contentType === 'multipart/form-data') {
301
- lines.push(` body = ctx.body as MultipartBody;`);
301
+ lines.push(` body = ctx.parsedBody as MultipartBody;`);
302
302
  } else {
303
- lines.push(` body = await parseAndValidate(ctx.body, ${renderInputType(b.bodyType, modelsWithInput)});`);
303
+ lines.push(` body = await parseAndValidate(ctx.parsedBody, ${renderInputType(b.bodyType, modelsWithInput)});`);
304
304
  }
305
305
  lines.push(` break;`);
306
306
  }
@@ -132,7 +132,7 @@ describe('generateOperation', () => {
132
132
  it('generates body validation with parseAndValidate', () => {
133
133
  const root = opRoot([opRoute('/users', [opOperation('post', { request: opRequest('CreateUser') })])]);
134
134
  const output = generateOp(root);
135
- expect(output).toContain('parseAndValidate(ctx.body, CreateUser)');
135
+ expect(output).toContain('parseAndValidate(ctx.parsedBody, CreateUser)');
136
136
  });
137
137
 
138
138
  it('generates create service method for POST', () => {
@@ -172,7 +172,7 @@ describe('generateOperation', () => {
172
172
  ]),
173
173
  ]);
174
174
  const output = generateOp(root);
175
- expect(output).toContain('const body = await parseAndValidate(ctx.body, AuthRequest)');
175
+ expect(output).toContain('const body = await parseAndValidate(ctx.parsedBody, AuthRequest)');
176
176
  expect(output).not.toContain('switch (ctx.request.type)');
177
177
  });
178
178
 
@@ -191,8 +191,8 @@ describe('generateOperation', () => {
191
191
  expect(output).toContain('switch (ctx.request.type)');
192
192
  expect(output).toContain("case 'application/json':");
193
193
  expect(output).toContain("case 'multipart/form-data':");
194
- expect(output).toContain('body = ctx.body as MultipartBody;');
195
- expect(output).toContain('body = await parseAndValidate(ctx.body, UploadMeta)');
194
+ expect(output).toContain('body = ctx.parsedBody as MultipartBody;');
195
+ expect(output).toContain('body = await parseAndValidate(ctx.parsedBody, UploadMeta)');
196
196
  expect(output).toContain("import { MultipartBody } from '@maroonedsoftware/multipart';");
197
197
  });
198
198
  });
@@ -471,7 +471,7 @@ describe('generateOperation', () => {
471
471
  const root = opRoot([opRoute('/uploads', [opOperation('post', { request: opRequest('Upload', 'multipart/form-data') })])]);
472
472
  const output = generateOp(root);
473
473
  expect(output).toContain("bodyParserMiddleware(['multipart'])");
474
- expect(output).toContain('ctx.body as MultipartBody');
474
+ expect(output).toContain('ctx.parsedBody as MultipartBody');
475
475
  expect(output).toContain("import { MultipartBody } from '@maroonedsoftware/multipart';");
476
476
  });
477
477
  });