@contractkit/plugin-typescript 0.25.3 → 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.3",
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",
@@ -29,8 +29,8 @@
29
29
  "@contractkit/core": "0.20.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",
@@ -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' });`);
@@ -773,6 +777,12 @@ function fileNeedsSignature(root: OpRootNode): boolean {
773
777
  return root.routes.some(route => route.operations.some(op => !!op.signature));
774
778
  }
775
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
+
776
786
  function isValidIdentifier(name: string): boolean {
777
787
  return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
778
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