@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/.turbo/turbo-build$colon$ci.log +4 -4
- package/.turbo/turbo-test$colon$ci.log +11 -11
- package/CHANGELOG.md +6 -0
- package/coverage/clover.xml +315 -311
- 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 +40 -10
- 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 -0
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/codegen-operation.ts +10 -0
- package/tests/codegen-operation.test.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contractkit/plugin-typescript",
|
|
3
|
-
"version": "0.25.
|
|
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-
|
|
33
|
-
"@repo/config-
|
|
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",
|
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' });`);
|
|
@@ -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
|
|