@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/.turbo/turbo-build$colon$ci.log +4 -4
- package/.turbo/turbo-test$colon$ci.log +11 -11
- package/CHANGELOG.md +12 -0
- package/coverage/clover.xml +306 -304
- package/coverage/coverage-final.json +1 -1
- package/coverage/index.html +18 -18
- package/coverage/src/codegen-contract.ts.html +1 -1
- package/coverage/src/codegen-operation.ts.html +38 -14
- package/coverage/src/codegen-plain-types.ts.html +1 -1
- package/coverage/src/codegen-sdk.ts.html +1 -1
- package/coverage/src/index.html +18 -18
- package/coverage/src/index.ts.html +1 -1
- package/coverage/src/path-utils.ts.html +1 -1
- package/coverage/src/ts-render.ts.html +1 -1
- package/coverage/tests/helpers.ts.html +1 -1
- package/coverage/tests/index.html +1 -1
- package/dist/codegen-operation.d.ts.map +1 -1
- package/dist/index.js +7 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/codegen-operation.ts +10 -2
- package/tests/codegen-operation.test.ts +2 -0
package/package.json
CHANGED
package/src/codegen-operation.ts
CHANGED
|
@@ -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
|
|