@contractkit/plugin-typescript 0.25.2 → 0.25.4

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.25.2",
3
+ "version": "0.25.4",
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",
@@ -160,6 +160,10 @@ export function generateOp(root: OpRootNode, options: OpCodegenOptions = {}): st
160
160
  body.push(`import { parseAndValidate } from '@maroonedsoftware/zod';`);
161
161
  }
162
162
 
163
+ if (fileUsesMultipart(root)) {
164
+ body.push(`import { MultipartBody } from '@maroonedsoftware/multipart';`);
165
+ }
166
+
163
167
  const helpers: string[] = [];
164
168
  if (opNeedsScalar(root, 'binary')) {
165
169
  helpers.push(`const _ZodBinary = z.custom<Buffer>((val) => Buffer.isBuffer(val), { error: 'Must be binary data' });`);
@@ -354,8 +358,6 @@ function generateHandler(route: OpRouteNode, op: OpOperationNode, root: OpRootNo
354
358
  lines.push(` ctx.body = ${hasRespHeaders ? 'result.body' : 'result'};`);
355
359
  }
356
360
 
357
- lines.push('');
358
- lines.push(` await next();`);
359
361
  lines.push(`});`);
360
362
 
361
363
  return lines;
@@ -775,6 +777,12 @@ function fileNeedsSignature(root: OpRootNode): boolean {
775
777
  return root.routes.some(route => route.operations.some(op => !!op.signature));
776
778
  }
777
779
 
780
+ function fileUsesMultipart(root: OpRootNode): boolean {
781
+ return root.routes.some(route =>
782
+ route.operations.some(op => (op.request?.bodies ?? []).some(b => b.contentType === 'multipart/form-data')),
783
+ );
784
+ }
785
+
778
786
  function isValidIdentifier(name: string): boolean {
779
787
  return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
780
788
  }
@@ -193,6 +193,7 @@ describe('generateOperation', () => {
193
193
  expect(output).toContain("case 'multipart/form-data':");
194
194
  expect(output).toContain('body = ctx.body as MultipartBody;');
195
195
  expect(output).toContain('body = await parseAndValidate(ctx.body, UploadMeta)');
196
+ expect(output).toContain("import { MultipartBody } from '@maroonedsoftware/multipart';");
196
197
  });
197
198
  });
198
199
 
@@ -471,6 +472,7 @@ describe('generateOperation', () => {
471
472
  const output = generateOp(root);
472
473
  expect(output).toContain("bodyParserMiddleware(['multipart'])");
473
474
  expect(output).toContain('ctx.body as MultipartBody');
475
+ expect(output).toContain("import { MultipartBody } from '@maroonedsoftware/multipart';");
474
476
  });
475
477
  });
476
478