@postxl/generator 0.19.0 → 0.21.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.
@@ -63,7 +63,7 @@ function generateDataMockModule({ models, meta }) {
63
63
  }`)
64
64
  .join(', ');
65
65
  return `
66
- import { DynamicModule } from '@nestjs/common'
66
+ import { DynamicModule } from '@pxl/common'
67
67
  import { DbModule } from '@${meta.config.project}/db'
68
68
 
69
69
  ${imports.generate()}
@@ -49,12 +49,9 @@ function generateDataModule({ models, meta }) {
49
49
  }
50
50
  const moduleName = meta.data.moduleName;
51
51
  return `
52
- import { Provider } from '@nestjs/common'
53
52
  import { DynamicModule } from '@${meta.config.project}/common'
54
53
  import { DbModule } from '@${meta.config.project}/db'
55
54
 
56
- import { Repository } from './repository.type'
57
-
58
55
  ${imports.generate()}
59
56
 
60
57
  export class ${moduleName} {
@@ -103,7 +103,12 @@ export class ${meta.data.repositoryClassName} implements Repository<
103
103
  `)
104
104
  .join('\n')}
105
105
 
106
- ${model.defaultField ? `public defaultValue!: ${model.typeName}` : ''}
106
+ ${model.defaultField
107
+ ? `
108
+ // We can safely skip the assignment here as this is done in the init function
109
+ public defaultValue!: ${model.typeName}
110
+ `
111
+ : ''}
107
112
 
108
113
  ${isGenerated
109
114
  ? `
@@ -136,7 +141,14 @@ export class ${meta.data.repositoryClassName} implements Repository<
136
141
  this.data.clear()
137
142
 
138
143
  ${uniqueStringFields.map((f) => `this.uniqueIds.${f.name}.clear()`).join('\n')}
139
-
144
+ ${model.defaultField
145
+ ? `
146
+ // We re-initialize the default value to undefined so the check for exactly one item does not fail upon re-initialization
147
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
148
+ this.defaultValue = undefined!
149
+ `
150
+ : ''}
151
+
140
152
  ${indexes.map((i) => `this.${i.name}.clear()`).join('\n')}
141
153
 
142
154
  ${model.attributes.inMemoryOnly
@@ -18,10 +18,12 @@ function generateSeedModel({ model, itemCount, meta, }) {
18
18
  });
19
19
  for (const relation of (0, fields_1.getRelationFields)(model)) {
20
20
  const depMeta = (0, meta_1.getModelMetadata)({ model: relation.relationToModel });
21
- imports.addImport({
22
- items: [depMeta.types.toBrandedIdTypeFnName],
23
- from: depMeta.types.importPath,
24
- });
21
+ if (relation.isRequired) {
22
+ imports.addImport({
23
+ items: [depMeta.types.toBrandedIdTypeFnName],
24
+ from: depMeta.types.importPath,
25
+ });
26
+ }
25
27
  }
26
28
  const mode = getExampleMode({ model, maxItemCount: itemCount });
27
29
  const examples = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@postxl/generator",
3
- "version": "0.19.0",
3
+ "version": "0.21.0",
4
4
  "main": "./dist/generator.js",
5
5
  "typings": "./dist/generator.d.ts",
6
6
  "bin": {