@postxl/generator 0.6.2 → 0.6.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.
|
@@ -185,12 +185,26 @@ export class ${meta.data.repositoryClassName} implements Repository<
|
|
|
185
185
|
return newItem
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
-
public async createMany(items: Omit<${model.typeName}, '
|
|
188
|
+
public async createMany(items: Omit<${model.typeName}, 'createdAt' | 'updatedAt'>[]): Promise<${model.typeName}[]> {
|
|
189
189
|
const result: ${model.typeName}[] = []
|
|
190
|
+
${uniqueStringFields.length > 0
|
|
191
|
+
? `
|
|
190
192
|
for (const item of items) {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
+
${uniqueStringFields.map((f) => `this.${getEnsureUniqueFnName(f)}(item)`).join('\n')}
|
|
194
|
+
}`
|
|
195
|
+
: ''}
|
|
196
|
+
|
|
197
|
+
await this.db.${meta.data.repository.getMethodFnName}.createMany({ data: items })
|
|
198
|
+
|
|
199
|
+
for (const item of items) {
|
|
200
|
+
const newItem = this.${decoder}(item)
|
|
201
|
+
this.data.set(newItem.id, newItem)
|
|
202
|
+
${isGenerated ? `if (item.id > this.currentMaxId) { this.currentMaxId = item.id }` : ''}
|
|
203
|
+
${uniqueStringFields.map((f) => `this.uniqueIds.${f.name}.set(newItem.${f.name}, newItem)`).join('\n')}
|
|
204
|
+
|
|
205
|
+
result.push(newItem)
|
|
193
206
|
}
|
|
207
|
+
|
|
194
208
|
return result
|
|
195
209
|
}
|
|
196
210
|
|
|
@@ -289,7 +303,7 @@ export class ${meta.data.repositoryClassName} implements Repository<
|
|
|
289
303
|
/**
|
|
290
304
|
* Utility function that converts a given Database object to a TypeScript model instance
|
|
291
305
|
*/
|
|
292
|
-
private ${decoder}(item: DbType): ${model.typeName} {
|
|
306
|
+
private ${decoder}(item: Omit<DbType, 'createdAt' | 'updatedAt'>): ${model.typeName} {
|
|
293
307
|
return ${meta.types.zodDecoderFnName}.parse({
|
|
294
308
|
${[...model.fields.values()].map((f) => `${f.name}: item.${f.sourceName}`).join(',\n')}
|
|
295
309
|
})
|
package/dist/lib/schema/zod.js
CHANGED
|
@@ -10,11 +10,11 @@ const getZodDecoderDefinition = ({ field, allowAnyOptionalField, }) => {
|
|
|
10
10
|
let definition = getZodTypeDefinition(field);
|
|
11
11
|
if (field.kind === 'id') {
|
|
12
12
|
const idModelMeta = (0, meta_1.getModelMetadata)({ model: field.model });
|
|
13
|
-
definition += `.transform(${idModelMeta.types.toBrandedIdTypeFnName})`;
|
|
13
|
+
definition += `.transform((x) => ${idModelMeta.types.toBrandedIdTypeFnName}(x))`;
|
|
14
14
|
}
|
|
15
15
|
if (field.kind === 'relation') {
|
|
16
16
|
const refModelMeta = (0, meta_1.getModelMetadata)({ model: field.relationToModel });
|
|
17
|
-
definition += `.transform(${refModelMeta.types.toBrandedIdTypeFnName})`;
|
|
17
|
+
definition += `.transform((x) => ${refModelMeta.types.toBrandedIdTypeFnName}(x))`;
|
|
18
18
|
}
|
|
19
19
|
if (!field.isRequired) {
|
|
20
20
|
definition += `.nullable()`;
|