@postxl/generator 0.53.0 → 0.53.2

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.
@@ -27,7 +27,7 @@ import { DbService } from '@backend/db'
27
27
 
28
28
  ${imports.generate()}
29
29
 
30
- import { ActionExecutionFactory, IActionExecution } from './actionExecution'
30
+ import { ActionExecutionFactory, IActionExecution } from './execution'
31
31
  import { Action, ResultOfAction } from './actions.types'
32
32
 
33
33
 
@@ -145,26 +145,26 @@ export class ${meta.importExport.importService.name} {
145
145
  getDelta: ({ item, existingItem }: { item: Model; existingItem: Model }) => ${delta_Fields}<Model, ID>
146
146
  }): Promise<Delta_Result<Model, ID>> {
147
147
  if (item.id === undefined || item.id === '') {
148
- return Promise.resolve({ type: '${create.discriminant}' })
148
+ return { type: '${create.discriminant}' }
149
149
  }
150
150
  const existingItem = await getId(item.id)
151
151
 
152
152
  if (!existingItem) {
153
- return Promise.resolve({ type: '${create.discriminant}' })
153
+ return { type: '${create.discriminant}' }
154
154
  }
155
155
 
156
156
  const delta = getDelta({ item, existingItem })
157
157
 
158
158
  if (Object.keys(delta).length > 0) {
159
- return Promise.resolve({ type: '${update.discriminant}', delta, existingItem })
159
+ return { type: '${update.discriminant}', delta, existingItem }
160
160
  }
161
161
 
162
162
  // We do not have a default logic to identify deletions. Implement it here, e.g. using a
163
163
  // custom "Action" field in the Excel table. If it is set to "Delete", we can handle the delete here.
164
- // return Promise.resolve({type: '${delta_Model.delete.discriminant}', existingItem})
164
+ // return {type: '${delta_Model.delete.discriminant}', existingItem}
165
165
 
166
166
  // If we reach this point, we assume the item has not changed
167
- return Promise.resolve({ type: '${unchanged.discriminant}' })
167
+ return { type: '${unchanged.discriminant}' }
168
168
  }
169
169
 
170
170
  private getDelta<Model extends ${dto.genericModel}<ID>, ID extends ${dto.idType}>({
@@ -206,7 +206,7 @@ export class ${meta.importExport.importService.name} {
206
206
  const upsertResult: Delta_Model<Model, ID, ModelErrors>[] = []
207
207
 
208
208
  if (items === undefined || items.length === 0) {
209
- return Promise.resolve(upsertResult)
209
+ return upsertResult
210
210
  }
211
211
 
212
212
  for (const item of items) {
@@ -258,7 +258,7 @@ export class ${meta.importExport.importService.name} {
258
258
  }
259
259
  }
260
260
 
261
- return Promise.resolve(upsertResult)
261
+ return upsertResult
262
262
  }
263
263
 
264
264
  /**
@@ -565,13 +565,11 @@ private async detect${modelMeta.internalSingularNameCapitalized}Delta(
565
565
  properties: [${fieldNames.join(',')}],
566
566
  }),
567
567
  validateCreate: async ({ item }) =>
568
- Promise.resolve(
569
- this.keepErrors([
570
- ${requiredFieldsValidation}
571
- ...(await sharedValidations(item)),
572
- ]),
573
- ),
574
- validateUpdate: async ({ item }) => Promise.resolve(this.keepErrors(await sharedValidations(item))),
568
+ this.keepErrors([
569
+ ${requiredFieldsValidation}
570
+ ...(await sharedValidations(item)),
571
+ ]),
572
+ validateUpdate: async ({ item }) => this.keepErrors(await sharedValidations(item)),
575
573
  validateDelete: ${validateDelete},
576
574
  })
577
575
  }`;
@@ -120,19 +120,25 @@ export class ${meta.data.repository.className} implements Repository<${model.typ
120
120
 
121
121
  ${mainBlocks.userRepositorySpecificBlocks.rootUserInitializeBlock}
122
122
 
123
+ // NOTE: The current implementation is synchronous, but it needs to be async to conform to the interface.
124
+ // eslint-disable-next-line @typescript-eslint/require-await
123
125
  public async get(id: ${model.brandedIdType} | null): Promise<${model.typeName} | null> {
124
126
  if (id === null) {
125
- return Promise.resolve(null)
127
+ return null
126
128
  }
127
- return Promise.resolve(this.data.get(id) ?? null)
129
+ return this.data.get(id) ?? null
128
130
  }
129
131
 
132
+ // NOTE: The current implementation is synchronous, but it needs to be async to conform to the interface.
133
+ // eslint-disable-next-line @typescript-eslint/require-await
130
134
  public async getAll(): Promise<Map<${model.brandedIdType}, ${model.typeName}>> {
131
- return Promise.resolve(new Map(this.data))
135
+ return new Map(this.data)
132
136
  }
133
137
 
138
+ // NOTE: The current implementation is synchronous, but it needs to be async to conform to the interface.
139
+ // eslint-disable-next-line @typescript-eslint/require-await
134
140
  public async getAllAsArray(): Promise<${model.typeName}[]> {
135
- return Promise.resolve(Array.from(this.data.values()))
141
+ return Array.from(this.data.values())
136
142
  }
137
143
 
138
144
  ${indexBlocks.getterFunctions.join('\n')}
@@ -147,8 +153,10 @@ export class ${meta.data.repository.className} implements Repository<${model.typ
147
153
  return (await this.getAllAsArray()).find(predicate) ?? null
148
154
  }
149
155
 
156
+ // NOTE: The current implementation is synchronous, but it needs to be async to conform to the interface.
157
+ // eslint-disable-next-line @typescript-eslint/require-await
150
158
  public async count(): Promise<number> {
151
- return Promise.resolve(this.data.size)
159
+ return this.data.size
152
160
  }
153
161
 
154
162
  ${mainBlocks.createCode}
@@ -229,6 +237,8 @@ function _generateMainBuildingBlocks_InMemoryOnly({ model, meta, schemaMeta, imp
229
237
  constructorCode: '',
230
238
  userRepositorySpecificBlocks,
231
239
  initCode: `
240
+ // NOTE: The current implementation is synchronous, but it needs to be async to conform to the interface.
241
+ // eslint-disable-next-line @typescript-eslint/require-await
232
242
  public async init() {
233
243
  this.data.clear()
234
244
 
@@ -238,8 +248,6 @@ function _generateMainBuildingBlocks_InMemoryOnly({ model, meta, schemaMeta, imp
238
248
  ${blocks.indexBlocks.initCode.join('\n')}
239
249
 
240
250
  ${userRepositorySpecificBlocks.initCall}
241
-
242
- return Promise.resolve()
243
251
  }`,
244
252
  reInitCode: `
245
253
  public async reInit({items, execution}: ${methodTypeSignatures.createMany.parameters[0]}): Promise<void> {
@@ -291,7 +299,7 @@ function _generateMainBuildingBlocks_InMemoryOnly({ model, meta, schemaMeta, imp
291
299
  })
292
300
 
293
301
  try {
294
- const newItem = await Promise.resolve(this.verifyItem(item))
302
+ const newItem = this.verifyItem(item)
295
303
 
296
304
  this.set(newItem)
297
305
  await execution.finishCreateMutation({ mutationId, createdObject: newItem, entityId: newItem.id })
@@ -314,8 +322,6 @@ function _generateMainBuildingBlocks_InMemoryOnly({ model, meta, schemaMeta, imp
314
322
  try {
315
323
  const newItems = items.map((item) => this.verifyItem(item))
316
324
 
317
- await Promise.resolve()
318
-
319
325
  for (const item of newItems) {
320
326
  this.set(item)
321
327
  }
@@ -352,7 +358,7 @@ function _generateMainBuildingBlocks_InMemoryOnly({ model, meta, schemaMeta, imp
352
358
 
353
359
  ${blocks.uniqueStringFieldsBlocks.updateCode.join('\n')}
354
360
 
355
- const newItem = await Promise.resolve({ ...existingItem, ...removeUndefinedProperties(item) })
361
+ const newItem = { ...existingItem, ...removeUndefinedProperties(item) }
356
362
  ${model.updatedAtField ? `newItem.${model.updatedAtField.name} = new Date()` : ''}
357
363
 
358
364
  this.remove(existingItem)
@@ -424,8 +430,6 @@ function _generateMainBuildingBlocks_InMemoryOnly({ model, meta, schemaMeta, imp
424
430
  sourceObject: existingItem,
425
431
  })
426
432
  try {
427
- await Promise.resolve()
428
-
429
433
  this.remove(existingItem)
430
434
  await execution.finishDeleteMutation({ mutationId })
431
435
  return id
@@ -1159,8 +1163,10 @@ function generateUniqueFieldsBlocks({ model }) {
1159
1163
  for (const f of fields) {
1160
1164
  result.mapDeclarations.push(`'${f.name}': new Map<string, ${model.typeName}>()`);
1161
1165
  result.getByFunctions.push(`
1166
+ // NOTE: The current implementation is synchronous, but it needs to be async to conform to the interface.
1167
+ // eslint-disable-next-line @typescript-eslint/require-await
1162
1168
  public async getBy${(0, string_1.toPascalCase)(f.name)}(${f.name}: string): Promise<${model.typeName} | undefined> {
1163
- return Promise.resolve(this.uniqueIds.${f.name}.get(${(0, string_1.toCamelCase)(f.name)}))
1169
+ return this.uniqueIds.${f.name}.get(${(0, string_1.toCamelCase)(f.name)})
1164
1170
  }`);
1165
1171
  result.clearCode.push(`this.uniqueIds.${f.name}.clear()`);
1166
1172
  result.verifyCode.push(`this.${getEnsureUniqueFnName(f)}(item)`);
@@ -1336,28 +1342,32 @@ function generateRelationsBlocks({ model, imports, }) {
1336
1342
  /**
1337
1343
  * Function to retrieve all ${(0, string_1.pluralize)(model.name)} that are related to a ${r.name}
1338
1344
  */
1345
+ // NOTE: The current implementation is synchronous, but it needs to be async to conform to the interface.
1346
+ // eslint-disable-next-line @typescript-eslint/require-await
1339
1347
  public async ${fieldMeta.getByForeignKeyMethodFnName}(
1340
1348
  id: ${relationModelMeta.types.brandedIdType}
1341
1349
  ): Promise<Map<${model.brandedIdType}, ${model.typeName}>> {
1342
1350
  const result = this.${r.name}Map.get(id)
1343
1351
  if (!result) {
1344
- return Promise.resolve(new Map<${model.brandedIdType}, ${model.typeName}>())
1352
+ return new Map<${model.brandedIdType}, ${model.typeName}>()
1345
1353
  }
1346
- return Promise.resolve(new Map(result))
1354
+ return new Map(result)
1347
1355
  }
1348
1356
 
1349
1357
  /**
1350
1358
  * Function to retrieve all ${model.brandedIdType}s that are related to a ${r.name}
1351
1359
  */
1360
+ // NOTE: The current implementation is synchronous, but it needs to be async to conform to the interface.
1361
+ // eslint-disable-next-line @typescript-eslint/require-await
1352
1362
  public async ${fieldMeta.getByForeignKeyIdsMethodFnName}(
1353
1363
  id: ${relationModelMeta.types.brandedIdType}
1354
1364
  ): Promise<${model.brandedIdType}[]> {
1355
1365
  const s = this.${r.name}Map.get(id)
1356
1366
  if (!s) {
1357
- return Promise.resolve([])
1367
+ return []
1358
1368
  }
1359
1369
 
1360
- return Promise.resolve(Array.from(s.keys()))
1370
+ return Array.from(s.keys())
1361
1371
  }`);
1362
1372
  result.setCode.push(`
1363
1373
  ${!r.isRequired ? `if (item.${r.name}) {` : ''}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@postxl/generator",
3
- "version": "0.53.0",
3
+ "version": "0.53.2",
4
4
  "main": "./dist/generator.js",
5
5
  "typings": "./dist/generator.d.ts",
6
6
  "bin": {