@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contractkit/plugin-typescript",
3
- "version": "0.23.0",
3
+ "version": "0.23.1",
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",
@@ -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
- lines.push(` ${quoteKey(outputKey)}: data.${inputKey},`);
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
  });