@postxl/generator 0.66.0 → 0.67.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.
@@ -302,10 +302,22 @@ function generateDeleteManyFn({ imports, model, meta, m, }) {
302
302
  function generateCloneFn({ model, meta, m }) {
303
303
  const inputFields = model.fields.map((f) => {
304
304
  const type = (0, typescript_1.getFieldType)(f);
305
- if (f.kind === 'id' || f.isUnique) {
305
+ // NOTE: ID field is always required to resolve the source.
306
+ if (f.kind === 'id') {
306
307
  return `${f.name}: ${type}`;
307
308
  }
308
- return `${f.name}?: ${type}`;
309
+ if (f.isUnique) {
310
+ // NOTE: `unique` fields require a new value.
311
+ if (f.isRequired) {
312
+ return `${f.name}: ${type}`;
313
+ }
314
+ return `${f.name}: ${type} | null`;
315
+ }
316
+ // NOTE: Non-unique fields can be copied from the source.
317
+ if (f.isRequired) {
318
+ return `${f.name}?: ${type}`;
319
+ }
320
+ return `${f.name}?: ${type} | null`;
309
321
  });
310
322
  return `
311
323
  ${(0, jsdoc_1.toJsDocComment)([`Creates a new ${meta.userFriendlyName} deep clone and returns it.`])}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@postxl/generator",
3
- "version": "0.66.0",
3
+ "version": "0.67.0",
4
4
  "main": "./dist/generator.js",
5
5
  "typings": "./dist/generator.d.ts",
6
6
  "bin": {