@contractkit/plugin-typescript 0.31.1 → 0.32.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 +5 -5
- package/.turbo/turbo-test$colon$ci.log +18 -18
- package/CHANGELOG.md +91 -0
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/codegen-operation.d.ts +12 -0
- package/dist/codegen-operation.d.ts.map +1 -1
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +73 -10
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
- package/src/codegen-operation.ts +109 -9
- package/src/index.ts +30 -0
- package/tests/codegen-operation.test.ts +252 -2
- package/tests/codegen-server.test.ts +48 -0
- package/tests/helpers.ts +5 -0
- package/tests/pipeline.test.ts +11 -2
package/tests/pipeline.test.ts
CHANGED
|
@@ -13,11 +13,11 @@ function compileContractSource(source: string) {
|
|
|
13
13
|
return { root: contract, output, diag };
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
function compileOpSource(source: string, file = 'users.ck') {
|
|
16
|
+
function compileOpSource(source: string, file = 'users.ck', options?: Parameters<typeof generateOp>[1]) {
|
|
17
17
|
const diag = new DiagnosticCollector();
|
|
18
18
|
const ck = parseCk(source, file, diag);
|
|
19
19
|
const { op } = decomposeCk(ck);
|
|
20
|
-
const output = generateOp(op);
|
|
20
|
+
const output = generateOp(op, options);
|
|
21
21
|
return { root: op, output, diag };
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -103,6 +103,15 @@ describe('OP pipeline (source -> parse -> codegen)', () => {
|
|
|
103
103
|
expect(output).toContain('ctx.status = 201');
|
|
104
104
|
});
|
|
105
105
|
|
|
106
|
+
it('validates response bodies end to end when validateResponses is on', () => {
|
|
107
|
+
const { output, diag } = compileOpSource(SIMPLE_USERS_OP, 'users.ck', { validateResponses: true });
|
|
108
|
+
expect(diag.hasErrors()).toBe(false);
|
|
109
|
+
// GET returns array(User), POST returns User — both re-parsed against their own schema.
|
|
110
|
+
expect(output).toContain('ctx.body = await parseAndValidate(result, z.array(User), 500);');
|
|
111
|
+
expect(output).toContain('ctx.body = await parseAndValidate(result, User, 500);');
|
|
112
|
+
expect(output).toContain("import { parseAndValidate } from '@maroonedsoftware/zod';");
|
|
113
|
+
});
|
|
114
|
+
|
|
106
115
|
it('compiles an operation with params, request, and response', () => {
|
|
107
116
|
const { output, diag } = compileOpSource(PARAMETERIZED_OP);
|
|
108
117
|
expect(diag.hasErrors()).toBe(false);
|