@postxl/generator 0.0.1 → 0.0.3
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/changelog.md +23 -0
- package/dist/src/generators/models/repository.generator.js +30 -18
- package/dist/src/lib/attributes.d.ts +5 -0
- package/dist/src/prisma/attributes.js +8 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -2
- package/tests/schemas/la/la.prisma +862 -0
- package/tests/schemas/mca/mca.prisma +527 -0
package/changelog.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.0.3
|
|
4
|
+
|
|
5
|
+
### Removed
|
|
6
|
+
|
|
7
|
+
- 🔇 Removed debug output attribute parser
|
|
8
|
+
|
|
9
|
+
## 0.0.2
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- Field attribute: maxLength attribute - this is now enforced in the repository
|
|
14
|
+
- `createMany` generated by repository generator
|
|
15
|
+
- Internal: added sample schemas for testing
|
|
16
|
+
|
|
17
|
+
### Removed
|
|
18
|
+
|
|
19
|
+
- `get` method of repositories does not accept unbranded ids anymore
|
|
20
|
+
|
|
21
|
+
### Fixed
|
|
22
|
+
|
|
23
|
+
- `unique` field attribute is now generated correctly
|
|
@@ -72,7 +72,7 @@ export class ${meta.data.repositoryClassName} implements Repository<
|
|
|
72
72
|
this.data.set(item.id, item)
|
|
73
73
|
|
|
74
74
|
${model.defaultField ? defaultValueInitFn : ''}
|
|
75
|
-
${uniqueStringFields.map((f) => `this.uniqueIds.${f}.set(item.${f}, item)`).join('\n')}
|
|
75
|
+
${uniqueStringFields.map((f) => `this.uniqueIds.${f.name}.set(item.${f.name}, item)`).join('\n')}
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
${isGenerated ? idIntInitFn : ''}
|
|
@@ -93,7 +93,7 @@ export class ${meta.data.repositoryClassName} implements Repository<
|
|
|
93
93
|
return this.init()
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
public get(id: ${model.brandedIdType}
|
|
96
|
+
public get(id: ${model.brandedIdType} | null): ${model.typeName} | null {
|
|
97
97
|
if (id === null) return null
|
|
98
98
|
return this.data.get(${meta.types.toBrandedIdTypeFnName}(id)) ?? null
|
|
99
99
|
}
|
|
@@ -177,6 +177,15 @@ export class ${meta.data.repositoryClassName} implements Repository<
|
|
|
177
177
|
return newItem
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
+
public async createMany(items: Omit<${model.typeName}, 'id' | 'createdAt' | 'updatedAt'>[]): Promise<${model.typeName}[]> {
|
|
181
|
+
const result: ${model.typeName}[] = []
|
|
182
|
+
for (const item of items) {
|
|
183
|
+
const i = await this.create(item)
|
|
184
|
+
result.push(i)
|
|
185
|
+
}
|
|
186
|
+
return result
|
|
187
|
+
}
|
|
188
|
+
|
|
180
189
|
public async update(item: Partial<${model.typeName}> & {
|
|
181
190
|
id: ${model.brandedIdType} | ${idField.unbrandedTypeName}
|
|
182
191
|
}): Promise<${model.typeName}> {
|
|
@@ -190,7 +199,7 @@ export class ${meta.data.repositoryClassName} implements Repository<
|
|
|
190
199
|
${uniqueStringFields
|
|
191
200
|
.map((f) => {
|
|
192
201
|
return `
|
|
193
|
-
if (item.${f.name} !== undefined && existingItem.${f} !== item.${f}) {
|
|
202
|
+
if (item.${f.name} !== undefined && existingItem.${f.name} !== item.${f.name}) {
|
|
194
203
|
this.${getEnsureUniqueFnName(f)}(item)
|
|
195
204
|
}
|
|
196
205
|
`;
|
|
@@ -247,22 +256,25 @@ export class ${meta.data.repositoryClassName} implements Repository<
|
|
|
247
256
|
|
|
248
257
|
${uniqueStringFields
|
|
249
258
|
.map((f) => {
|
|
250
|
-
const fName = f.name;
|
|
251
259
|
return `
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
260
|
+
/**
|
|
261
|
+
* Utility function that ensures that the ${f.name} field is unique
|
|
262
|
+
*/
|
|
263
|
+
private ${getEnsureUniqueFnName(f)}(item: { ${f.name}?: string }) {
|
|
264
|
+
if (!item.${f.name}) return
|
|
265
|
+
if (!this.uniqueIds.${f.name}.has(item.${f.name})) return
|
|
266
|
+
let counter = 1
|
|
267
|
+
|
|
268
|
+
let ${f.name}: string
|
|
269
|
+
const source${f.name} =${!f.attributes.maxLength ? `item.${f.name}` : `item.${f.name}.substring(0, ${f.attributes.maxLength - 5})`}
|
|
270
|
+
|
|
271
|
+
do {
|
|
272
|
+
${f.name} = \`\${source${f.name}} (\${++counter})\`
|
|
273
|
+
} while (this.uniqueIds.${f.name}.has(${f.name}))
|
|
274
|
+
|
|
275
|
+
this.logger.log(\`Asset ${f.name} \${item.${f.name}} already exists. Renaming to \${${f.name}})\`)
|
|
276
|
+
item.${f.name} = ${f.name}
|
|
277
|
+
}
|
|
266
278
|
`;
|
|
267
279
|
})
|
|
268
280
|
.join('\n\n')}
|
|
@@ -69,12 +69,19 @@ function getFieldAttributes(field) {
|
|
|
69
69
|
// we handle this the same way as our custom "ignore" attribute
|
|
70
70
|
ignore: field.isIgnored || Object.hasOwn(attributes, 'ignore'),
|
|
71
71
|
description: attributes.description && (0, remeda_1.isString)(attributes.description) ? attributes.description : undefined,
|
|
72
|
-
isDefaultField: Object.hasOwn(attributes, '
|
|
72
|
+
isDefaultField: Object.hasOwn(attributes, 'isDefault'),
|
|
73
73
|
examples: !attributes.examples
|
|
74
74
|
? undefined
|
|
75
75
|
: Array.isArray(attributes.examples)
|
|
76
76
|
? attributes.examples
|
|
77
77
|
: [attributes.examples],
|
|
78
|
+
maxLength: Object.hasOwn(attributes, 'maxLength')
|
|
79
|
+
? (0, remeda_1.isString)(attributes.maxLength)
|
|
80
|
+
? parseInt(attributes.maxLength, 10)
|
|
81
|
+
: (0, remeda_1.isNumber)(attributes.maxLength)
|
|
82
|
+
? attributes.maxLength
|
|
83
|
+
: undefined
|
|
84
|
+
: undefined,
|
|
78
85
|
};
|
|
79
86
|
}
|
|
80
87
|
exports.getFieldAttributes = getFieldAttributes;
|