@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/.turbo/turbo-build$colon$ci.log +4 -4
- package/.turbo/turbo-test$colon$ci.log +8 -8
- package/CHANGELOG.md +6 -0
- package/coverage/clover.xml +2 -2
- package/coverage/index.html +1 -1
- package/coverage/src/codegen-contract.ts.html +1 -1
- package/coverage/src/codegen-operation.ts.html +6 -6
- package/coverage/src/codegen-plain-types.ts.html +1 -1
- package/coverage/src/codegen-sdk.ts.html +1 -1
- package/coverage/src/index.html +1 -1
- 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/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/codegen-operation.ts +5 -5
- package/tests/codegen-operation.test.ts +5 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contractkit/plugin-typescript",
|
|
3
|
-
"version": "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-
|
|
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
|
@@ -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.
|
|
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.
|
|
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.
|
|
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.
|
|
301
|
+
lines.push(` body = ctx.parsedBody as MultipartBody;`);
|
|
302
302
|
} else {
|
|
303
|
-
lines.push(` body = await parseAndValidate(ctx.
|
|
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.
|
|
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.
|
|
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.
|
|
195
|
-
expect(output).toContain('body = await parseAndValidate(ctx.
|
|
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.
|
|
474
|
+
expect(output).toContain('ctx.parsedBody as MultipartBody');
|
|
475
475
|
expect(output).toContain("import { MultipartBody } from '@maroonedsoftware/multipart';");
|
|
476
476
|
});
|
|
477
477
|
});
|