@contractkit/plugin-typescript 0.23.0 → 0.23.1
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 +6 -6
- package/.turbo/turbo-test$colon$ci.log +13 -13
- package/CHANGELOG.md +6 -0
- package/coverage/clover.xml +478 -477
- package/coverage/coverage-final.json +2 -2
- package/coverage/index.html +12 -12
- package/coverage/src/codegen-contract.ts.html +170 -167
- package/coverage/src/codegen-operation.ts.html +1 -1
- package/coverage/src/codegen-plain-types.ts.html +1 -1
- package/coverage/src/codegen-sdk.ts.html +1 -1
- package/coverage/src/index.html +13 -13
- 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 +6 -6
- package/coverage/tests/index.html +1 -1
- package/dist/codegen-contract.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/codegen-contract.ts +2 -1
- package/tests/codegen-contract.test.ts +15 -1
package/package.json
CHANGED
package/src/codegen-contract.ts
CHANGED
|
@@ -300,7 +300,8 @@ function generateSimpleModel(model: ModelNode, outPath?: string): string[] {
|
|
|
300
300
|
for (const field of model.fields) {
|
|
301
301
|
const inputKey = applyCase(field.name, inputCase);
|
|
302
302
|
const outputKey = applyCase(field.name, outputCase);
|
|
303
|
-
|
|
303
|
+
const val = field.optional ? `data.${inputKey} ?? undefined` : `data.${inputKey}`;
|
|
304
|
+
lines.push(` ${quoteKey(outputKey)}: ${val},`);
|
|
304
305
|
}
|
|
305
306
|
lines.push(`}));`);
|
|
306
307
|
// When only outputCase is set, the developer-facing type is the schema's
|
|
@@ -1060,9 +1060,23 @@ describe('generateContract', () => {
|
|
|
1060
1060
|
/export const Child = z\.strictObject\(\{[\s\S]*grant_type:[\s\S]*client_id:[\s\S]*client_secret:[\s\S]*\}\)\.transform/,
|
|
1061
1061
|
);
|
|
1062
1062
|
expect(output).toContain('grantType: data.grant_type');
|
|
1063
|
-
expect(output).toContain('clientId: data.client_id');
|
|
1063
|
+
expect(output).toContain('clientId: data.client_id ?? undefined');
|
|
1064
1064
|
expect(output).toContain('clientSecret: data.client_secret');
|
|
1065
1065
|
expect(output).toContain('export type Child = z.output<typeof Child>');
|
|
1066
1066
|
});
|
|
1067
|
+
|
|
1068
|
+
it('input=snake: optional fields coerce null → undefined in the transform', () => {
|
|
1069
|
+
const root = contractRoot([
|
|
1070
|
+
model(
|
|
1071
|
+
'User',
|
|
1072
|
+
[field('firstName', scalarType('string')), field('clientId', scalarType('uuid'), { optional: true })],
|
|
1073
|
+
{ inputCase: 'snake' },
|
|
1074
|
+
),
|
|
1075
|
+
]);
|
|
1076
|
+
const output = generateContract(root);
|
|
1077
|
+
expect(output).toContain('client_id: z.uuid().nullish()');
|
|
1078
|
+
expect(output).toContain('firstName: data.first_name,');
|
|
1079
|
+
expect(output).toContain('clientId: data.client_id ?? undefined,');
|
|
1080
|
+
});
|
|
1067
1081
|
});
|
|
1068
1082
|
});
|