@currentjs/gen 0.5.5 → 0.5.7

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.
@@ -45,6 +45,7 @@ const typeUtils_1 = require("../utils/typeUtils");
45
45
  class ServiceGenerator {
46
46
  constructor() {
47
47
  this.availableAggregates = new Map();
48
+ this.identifiers = 'numeric';
48
49
  }
49
50
  mapType(yamlType) {
50
51
  return (0, typeUtils_1.mapType)(yamlType, this.availableAggregates);
@@ -177,8 +178,9 @@ class ServiceGenerator {
177
178
  }
178
179
  generateListHandler(modelName, storeName, hasPagination) {
179
180
  const returnType = `{ items: ${modelName}[]; total: number; page: number; limit: number }`;
181
+ const idTs = (0, configTypes_1.idTsType)(this.identifiers);
180
182
  if (hasPagination) {
181
- return ` async list(page: number = 1, limit: number = 20, ownerId?: number): Promise<${returnType}> {
183
+ return ` async list(page: number = 1, limit: number = 20, ownerId?: ${idTs}): Promise<${returnType}> {
182
184
  const [items, total] = await Promise.all([
183
185
  this.${storeName}.getPaginated(page, limit, ownerId),
184
186
  this.${storeName}.count(ownerId)
@@ -186,13 +188,14 @@ class ServiceGenerator {
186
188
  return { items, total, page, limit };
187
189
  }`;
188
190
  }
189
- return ` async list(ownerId?: number): Promise<${returnType}> {
191
+ return ` async list(ownerId?: ${idTs}): Promise<${returnType}> {
190
192
  const items = await this.${storeName}.getAll(ownerId);
191
193
  return { items, total: items.length, page: 1, limit: items.length };
192
194
  }`;
193
195
  }
194
196
  generateGetHandler(modelName, storeName, entityLower) {
195
- return ` async get(id: number): Promise<${modelName}> {
197
+ const idTs = (0, configTypes_1.idTsType)(this.identifiers);
198
+ return ` async get(id: ${idTs}): Promise<${modelName}> {
196
199
  const ${entityLower} = await this.${storeName}.getById(id);
197
200
  if (!${entityLower}) {
198
201
  throw new Error('${modelName} not found');
@@ -227,12 +230,14 @@ class ServiceGenerator {
227
230
  return `input.${fieldName}`;
228
231
  }).join(', ');
229
232
  const constructorArgs = `input.${firstArgField}, ${fieldArgs}`;
233
+ const idPlaceholder = this.identifiers === 'numeric' ? '0' : "''";
230
234
  return ` async create(input: ${inputType}): Promise<${modelName}> {
231
- const ${entityLower} = new ${modelName}(0, ${constructorArgs});
235
+ const ${entityLower} = new ${modelName}(${idPlaceholder}, ${constructorArgs});
232
236
  return await this.${storeName}.insert(${entityLower});
233
237
  }`;
234
238
  }
235
- generateUpdateHandler(modelName, storeName, aggregateConfig, inputType, dtoFields) {
239
+ generateUpdateHandler(modelName, storeName, aggregateConfig, inputType, dtoFields, _identifiers) {
240
+ const idTs = (0, configTypes_1.idTsType)(this.identifiers);
236
241
  const setterCalls = Object.entries(aggregateConfig.fields)
237
242
  .filter(([fieldName, fieldConfig]) => !fieldConfig.auto && fieldName !== 'id' && dtoFields.has(fieldName))
238
243
  .map(([fieldName, fieldConfig]) => {
@@ -253,7 +258,7 @@ class ServiceGenerator {
253
258
  }`;
254
259
  })
255
260
  .join('\n');
256
- return ` async update(id: number, input: ${inputType}): Promise<${modelName}> {
261
+ return ` async update(id: ${idTs}, input: ${inputType}): Promise<${modelName}> {
257
262
  const existing${modelName} = await this.${storeName}.getById(id);
258
263
  if (!existing${modelName}) {
259
264
  throw new Error('${modelName} not found');
@@ -265,7 +270,8 @@ ${setterCalls}
265
270
  }`;
266
271
  }
267
272
  generateDeleteHandler(modelName, storeName) {
268
- return ` async delete(id: number): Promise<{ success: boolean; message: string }> {
273
+ const idTs = (0, configTypes_1.idTsType)(this.identifiers);
274
+ return ` async delete(id: ${idTs}): Promise<{ success: boolean; message: string }> {
269
275
  const success = await this.${storeName}.softDelete(id);
270
276
  if (!success) {
271
277
  throw new Error('${modelName} not found or could not be deleted');
@@ -316,19 +322,21 @@ ${setterCalls}
316
322
  if (!childInfo)
317
323
  return '';
318
324
  const storeVar = `${modelName.toLowerCase()}Store`;
325
+ const idTs = (0, configTypes_1.idTsType)(this.identifiers);
319
326
  return `
320
- async listByParent(parentId: number): Promise<${modelName}[]> {
327
+ async listByParent(parentId: ${idTs}): Promise<${modelName}[]> {
321
328
  return await this.${storeVar}.getByParentId(parentId);
322
329
  }`;
323
330
  }
324
331
  generateGetResourceOwnerMethod(modelName) {
325
332
  const storeVar = `${modelName.toLowerCase()}Store`;
333
+ const idTs = (0, configTypes_1.idTsType)(this.identifiers);
326
334
  return `
327
335
  /**
328
336
  * Get the owner ID of a resource by its ID.
329
337
  * Used for pre-mutation authorization checks.
330
338
  */
331
- async getResourceOwner(id: number): Promise<number | null> {
339
+ async getResourceOwner(id: ${idTs}): Promise<${idTs} | null> {
332
340
  return await this.${storeVar}.getResourceOwner(id);
333
341
  }`;
334
342
  }
@@ -411,8 +419,9 @@ export class ${serviceName} {
411
419
  ${methods.join('\n\n')}
412
420
  }`;
413
421
  }
414
- generateFromConfig(config) {
422
+ generateFromConfig(config, identifiers = 'numeric') {
415
423
  const result = {};
424
+ this.identifiers = identifiers;
416
425
  // Collect all aggregates
417
426
  if (config.domain.aggregates) {
418
427
  Object.entries(config.domain.aggregates).forEach(([name, aggConfig]) => {
@@ -432,16 +441,16 @@ ${methods.join('\n\n')}
432
441
  });
433
442
  return result;
434
443
  }
435
- generateFromYamlFile(yamlFilePath) {
444
+ generateFromYamlFile(yamlFilePath, identifiers = 'numeric') {
436
445
  const yamlContent = fs.readFileSync(yamlFilePath, 'utf8');
437
446
  const config = (0, yaml_1.parse)(yamlContent);
438
447
  if (!(0, configTypes_1.isValidModuleConfig)(config)) {
439
448
  throw new Error('Configuration does not match new module format. Expected useCases structure.');
440
449
  }
441
- return this.generateFromConfig(config);
450
+ return this.generateFromConfig(config, identifiers);
442
451
  }
443
- async generateAndSaveFiles(yamlFilePath, moduleDir, opts) {
444
- const servicesByModel = this.generateFromYamlFile(yamlFilePath);
452
+ async generateAndSaveFiles(yamlFilePath, moduleDir, opts, identifiers = 'numeric') {
453
+ const servicesByModel = this.generateFromYamlFile(yamlFilePath, identifiers);
445
454
  const servicesDir = path.join(moduleDir, 'application', 'services');
446
455
  fs.mkdirSync(servicesDir, { recursive: true });
447
456
  for (const [modelName, code] of Object.entries(servicesByModel)) {
@@ -1,7 +1,8 @@
1
- import { ModuleConfig } from '../types/configTypes';
1
+ import { ModuleConfig, IdentifierType } from '../types/configTypes';
2
2
  export declare class StoreGenerator {
3
3
  private availableValueObjects;
4
4
  private availableAggregates;
5
+ private identifiers;
5
6
  private isAggregateField;
6
7
  private isValueObjectType;
7
8
  private isArrayVoType;
@@ -51,11 +52,17 @@ export declare class StoreGenerator {
51
52
  private generateListMethods;
52
53
  private generateGetByParentIdMethod;
53
54
  private generateGetResourceOwnerMethod;
55
+ private generateIdHelpers;
56
+ private generateInsertIdVariables;
57
+ private generateWhereIdExpr;
58
+ private generateIdParamExpr;
59
+ private generateRowIdExpr;
60
+ private generateCryptoImport;
54
61
  private generateStore;
55
- generateFromConfig(config: ModuleConfig): Record<string, string>;
56
- generateFromYamlFile(yamlFilePath: string): Record<string, string>;
62
+ generateFromConfig(config: ModuleConfig, identifiers?: IdentifierType): Record<string, string>;
63
+ generateFromYamlFile(yamlFilePath: string, identifiers?: IdentifierType): Record<string, string>;
57
64
  generateAndSaveFiles(yamlFilePath: string, moduleDir: string, opts?: {
58
65
  force?: boolean;
59
66
  skipOnConflict?: boolean;
60
- }): Promise<void>;
67
+ }, identifiers?: IdentifierType): Promise<void>;
61
68
  }
@@ -47,6 +47,7 @@ class StoreGenerator {
47
47
  constructor() {
48
48
  this.availableValueObjects = new Map();
49
49
  this.availableAggregates = new Set();
50
+ this.identifiers = 'numeric';
50
51
  }
51
52
  isAggregateField(fieldConfig) {
52
53
  return (0, typeUtils_1.isAggregateReference)(fieldConfig.type, this.availableAggregates);
@@ -200,11 +201,12 @@ class StoreGenerator {
200
201
  }
201
202
  generateRowFields(fields, childInfo) {
202
203
  const result = [];
204
+ const idTs = (0, configTypes_1.idTsType)(this.identifiers);
203
205
  const ownerOrParentField = childInfo ? childInfo.parentIdField : 'ownerId';
204
- result.push(` ${ownerOrParentField}: number;`);
206
+ result.push(` ${ownerOrParentField}: ${idTs};`);
205
207
  fields.forEach(([fieldName, fieldConfig]) => {
206
208
  if (this.isAggregateField(fieldConfig)) {
207
- result.push(` ${fieldName}Id?: number;`);
209
+ result.push(` ${fieldName}Id?: ${idTs};`);
208
210
  return;
209
211
  }
210
212
  const tsType = this.mapTypeToRowType(fieldConfig.type);
@@ -214,10 +216,27 @@ class StoreGenerator {
214
216
  return result.join('\n');
215
217
  }
216
218
  generateFieldNamesStr(fields, childInfo) {
217
- const fieldNames = ['id'];
218
- fieldNames.push(childInfo ? childInfo.parentIdField : 'ownerId');
219
- fieldNames.push(...fields.map(([name, config]) => this.isAggregateField(config) ? `${name}Id` : name));
220
- return fieldNames.map(f => `\\\`${f}\\\``).join(', ');
219
+ const isUuid = this.identifiers === 'uuid';
220
+ const ownerOrParentField = childInfo ? childInfo.parentIdField : 'ownerId';
221
+ const allFields = [
222
+ 'id',
223
+ ownerOrParentField,
224
+ ...fields.map(([name, config]) => this.isAggregateField(config) ? `${name}Id` : name)
225
+ ];
226
+ if (!isUuid) {
227
+ return allFields.map(f => `\\\`${f}\\\``).join(', ');
228
+ }
229
+ // For UUID: id-type columns need BIN_TO_UUID wrapping in SELECT
230
+ const idFields = new Set(['id', ownerOrParentField]);
231
+ fields.forEach(([name, config]) => {
232
+ if (this.isAggregateField(config))
233
+ idFields.add(`${name}Id`);
234
+ });
235
+ return allFields.map(f => {
236
+ if (idFields.has(f))
237
+ return `BIN_TO_UUID(\\\`${f}\\\`, 1) as \\\`${f}\\\``;
238
+ return `\\\`${f}\\\``;
239
+ }).join(', ');
221
240
  }
222
241
  generateRowToModelMapping(modelName, fields, childInfo) {
223
242
  const result = [];
@@ -411,9 +430,15 @@ class StoreGenerator {
411
430
  }
412
431
  generateListMethods(modelName, fieldNamesStr, childInfo) {
413
432
  const isRoot = !childInfo;
414
- const ownerParam = isRoot ? ', ownerId?: number' : '';
433
+ const isUuid = this.identifiers === 'uuid';
434
+ const idTs = (0, configTypes_1.idTsType)(this.identifiers);
435
+ const ownerParam = isRoot ? `, ownerId?: ${idTs}` : '';
436
+ // UUID_TO_BIN(:ownerId, 1) — the ", 1" is a SQL literal inside the query string, not a JS param key
437
+ const ownerFilterExpr = isUuid
438
+ ? `' AND \\\`ownerId\\\` = UUID_TO_BIN(:ownerId, 1)'`
439
+ : `' AND \\\`ownerId\\\` = :ownerId'`;
415
440
  const ownerFilter = isRoot
416
- ? `\n const ownerFilter = ownerId != null ? ' AND \\\`ownerId\\\` = :ownerId' : '';`
441
+ ? `\n const ownerFilter = ownerId != null ? ${ownerFilterExpr} : '';`
417
442
  : '';
418
443
  const ownerFilterRef = isRoot ? '\${ownerFilter}' : '';
419
444
  const ownerParamsSetup = isRoot
@@ -432,7 +457,7 @@ class StoreGenerator {
432
457
  }
433
458
  return [];
434
459
  }`;
435
- const getAll = ` async getAll(${isRoot ? 'ownerId?: number' : ''}): Promise<${modelName}[]> {${ownerFilter}
460
+ const getAll = ` async getAll(${isRoot ? `ownerId?: ${idTs}` : ''}): Promise<${modelName}[]> {${ownerFilter}
436
461
  const params: Record<string, any> = {};${ownerParamsSetup}
437
462
  const result = await this.db.query(
438
463
  \`SELECT ${fieldNamesStr} FROM \\\`\${this.tableName}\\\` WHERE deletedAt IS NULL${ownerFilterRef}\`,
@@ -444,7 +469,7 @@ class StoreGenerator {
444
469
  }
445
470
  return [];
446
471
  }`;
447
- const count = ` async count(${isRoot ? 'ownerId?: number' : ''}): Promise<number> {${ownerFilter}
472
+ const count = ` async count(${isRoot ? `ownerId?: ${idTs}` : ''}): Promise<number> {${ownerFilter}
448
473
  const params: Record<string, any> = {};${ownerParamsSetup}
449
474
  const result = await this.db.query(
450
475
  \`SELECT COUNT(*) as count FROM \\\`\${this.tableName}\\\` WHERE deletedAt IS NULL${ownerFilterRef}\`,
@@ -461,13 +486,26 @@ class StoreGenerator {
461
486
  generateGetByParentIdMethod(modelName, fields, childInfo) {
462
487
  if (!childInfo)
463
488
  return '';
464
- const fieldList = ['id', childInfo.parentIdField, ...fields.map(([name, config]) => this.isAggregateField(config) ? `${name}Id` : name)].map(f => '\\`' + f + '\\`').join(', ');
489
+ const isUuid = this.identifiers === 'uuid';
490
+ const idTs = (0, configTypes_1.idTsType)(this.identifiers);
465
491
  const parentIdField = childInfo.parentIdField;
492
+ // Build field list for SELECT (reuse the same UUID-aware logic)
493
+ const idFields = new Set(['id', parentIdField]);
494
+ fields.forEach(([name, config]) => {
495
+ if (this.isAggregateField(config))
496
+ idFields.add(`${name}Id`);
497
+ });
498
+ const rawFields = ['id', parentIdField, ...fields.map(([name, config]) => this.isAggregateField(config) ? `${name}Id` : name)];
499
+ const bt = '\\`';
500
+ const fieldList = isUuid
501
+ ? rawFields.map(f => idFields.has(f) ? `BIN_TO_UUID(${bt}${f}${bt}, 1) as ${bt}${f}${bt}` : `${bt}${f}${bt}`).join(', ')
502
+ : rawFields.map(f => `${bt}${f}${bt}`).join(', ');
503
+ const whereExpr = isUuid ? `\\\`${parentIdField}\\\` = UUID_TO_BIN(:parentId, 1)` : `\\\`${parentIdField}\\\` = :parentId`;
466
504
  return `
467
505
 
468
- async getByParentId(parentId: number): Promise<${modelName}[]> {
506
+ async getByParentId(parentId: ${idTs}): Promise<${modelName}[]> {
469
507
  const result = await this.db.query(
470
- \`SELECT ${fieldList} FROM \\\`\${this.tableName}\\\` WHERE \\\`${parentIdField}\\\` = :parentId AND deletedAt IS NULL\`,
508
+ \`SELECT ${fieldList} FROM \\\`\${this.tableName}\\\` WHERE ${whereExpr} AND deletedAt IS NULL\`,
471
509
  { parentId }
472
510
  );
473
511
 
@@ -478,23 +516,32 @@ class StoreGenerator {
478
516
  }`;
479
517
  }
480
518
  generateGetResourceOwnerMethod(childInfo) {
519
+ const isUuid = this.identifiers === 'uuid';
520
+ const idTs = (0, configTypes_1.idTsType)(this.identifiers);
521
+ const whereExpr = isUuid ? 'id = UUID_TO_BIN(:id, 1)' : 'id = :id';
522
+ const ownerSelect = isUuid ? 'BIN_TO_UUID(p.ownerId, 1) as ownerId' : 'p.ownerId';
523
+ const ownerSelectSimple = isUuid ? 'BIN_TO_UUID(ownerId, 1) as ownerId' : 'ownerId';
481
524
  if (childInfo) {
482
525
  const parentTable = childInfo.parentTableName;
483
526
  const parentIdField = childInfo.parentIdField;
527
+ const joinExpr = isUuid
528
+ ? `p.id = UUID_TO_BIN(c.\\\`${parentIdField}\\\`, 1)`
529
+ : `p.id = c.\\\`${parentIdField}\\\``;
530
+ const cWhereExpr = isUuid ? 'c.id = UUID_TO_BIN(:id, 1)' : 'c.id = :id';
484
531
  return `
485
532
 
486
533
  /**
487
534
  * Get the owner ID of a resource by its ID (via parent entity).
488
535
  * Used for pre-mutation authorization checks.
489
536
  */
490
- async getResourceOwner(id: number): Promise<number | null> {
537
+ async getResourceOwner(id: ${idTs}): Promise<${idTs} | null> {
491
538
  const result = await this.db.query(
492
- \`SELECT p.ownerId FROM \\\`\${this.tableName}\\\` c INNER JOIN \\\`${parentTable}\\\` p ON p.id = c.\\\`${parentIdField}\\\` WHERE c.id = :id AND c.deletedAt IS NULL\`,
539
+ \`SELECT ${ownerSelect} FROM \\\`\${this.tableName}\\\` c INNER JOIN \\\`${parentTable}\\\` p ON ${joinExpr} WHERE ${cWhereExpr} AND c.deletedAt IS NULL\`,
493
540
  { id }
494
541
  );
495
542
 
496
543
  if (result.success && result.data && result.data.length > 0) {
497
- return result.data[0].ownerId as number;
544
+ return result.data[0].ownerId as ${idTs};
498
545
  }
499
546
  return null;
500
547
  }`;
@@ -505,35 +552,109 @@ class StoreGenerator {
505
552
  * Get the owner ID of a resource by its ID.
506
553
  * Used for pre-mutation authorization checks.
507
554
  */
508
- async getResourceOwner(id: number): Promise<number | null> {
555
+ async getResourceOwner(id: ${idTs}): Promise<${idTs} | null> {
509
556
  const result = await this.db.query(
510
- \`SELECT ownerId FROM \\\`\${this.tableName}\\\` WHERE id = :id AND deletedAt IS NULL\`,
557
+ \`SELECT ${ownerSelectSimple} FROM \\\`\${this.tableName}\\\` WHERE ${whereExpr} AND deletedAt IS NULL\`,
511
558
  { id }
512
559
  );
513
560
 
514
561
  if (result.success && result.data && result.data.length > 0) {
515
- return result.data[0].ownerId as number;
562
+ return result.data[0].ownerId as ${idTs};
516
563
  }
517
564
  return null;
518
565
  }`;
519
566
  }
567
+ generateIdHelpers() {
568
+ if (this.identifiers === 'nanoid') {
569
+ return `
570
+ private generateNanoId(size = 21): string {
571
+ const alphabet = "useABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";
572
+ let id = "";
573
+ const bytes = randomBytes(size);
574
+
575
+ for (let i = 0; i < size; i++) {
576
+ // We use a bitwise AND with 63 because 63 is 00111111 in binary.
577
+ // This maps any byte to a value between 0 and 63.
578
+ id += alphabet[bytes[i] & 63];
579
+ }
580
+
581
+ return id;
582
+ }
583
+ `;
584
+ }
585
+ return '';
586
+ }
587
+ generateInsertIdVariables() {
588
+ switch (this.identifiers) {
589
+ case 'uuid':
590
+ return {
591
+ preLine: ' const newId = randomUUID();',
592
+ dataLine: ' id: newId,\n',
593
+ successCond: '',
594
+ getId: ''
595
+ };
596
+ case 'nanoid':
597
+ return {
598
+ preLine: ' const newId = this.generateNanoId();',
599
+ dataLine: ' id: newId,\n',
600
+ successCond: '',
601
+ getId: ''
602
+ };
603
+ default:
604
+ return {
605
+ preLine: '',
606
+ dataLine: '',
607
+ successCond: ' && result.insertId',
608
+ getId: 'const newId = typeof result.insertId === \'string\' ? parseInt(result.insertId, 10) : result.insertId;'
609
+ };
610
+ }
611
+ }
612
+ generateWhereIdExpr() {
613
+ return this.identifiers === 'uuid' ? 'id = UUID_TO_BIN(:id, 1)' : 'id = :id';
614
+ }
615
+ generateIdParamExpr() {
616
+ // The ", 1" in UUID_TO_BIN(:id, 1) is a literal in the SQL string, NOT a JS params key.
617
+ // The params object always uses just { id }, so this expression is always empty.
618
+ return '';
619
+ }
620
+ generateRowIdExpr() {
621
+ return this.identifiers === 'uuid' ? 'row.id' : 'row.id';
622
+ }
623
+ generateCryptoImport() {
624
+ if (this.identifiers === 'uuid')
625
+ return `\nimport { randomUUID } from 'crypto';`;
626
+ if (this.identifiers === 'nanoid')
627
+ return `\nimport { randomBytes } from 'crypto';`;
628
+ return '';
629
+ }
520
630
  generateStore(modelName, aggregateConfig, childInfo) {
521
631
  const tableName = modelName.toLowerCase();
522
632
  const fields = Object.entries(aggregateConfig.fields);
523
633
  // Sort fields for rowToModel to match entity constructor order (required first, optional second)
524
634
  const sortedFields = this.sortFieldsForConstructor(fields);
525
635
  const fieldNamesStr = this.generateFieldNamesStr(fields, childInfo);
636
+ const idVars = this.generateInsertIdVariables();
637
+ const idTs = (0, configTypes_1.idTsType)(this.identifiers);
526
638
  const variables = {
527
639
  ENTITY_NAME: modelName,
528
640
  TABLE_NAME: tableName,
641
+ ID_TYPE: idTs,
529
642
  ROW_FIELDS: this.generateRowFields(fields, childInfo),
530
643
  FIELD_NAMES: fieldNamesStr,
644
+ ROW_ID_EXPR: this.generateRowIdExpr(),
645
+ WHERE_ID_EXPR: this.generateWhereIdExpr(),
646
+ ID_PARAM_EXPR: this.generateIdParamExpr(),
531
647
  ROW_TO_MODEL_MAPPING: this.generateRowToModelMapping(modelName, sortedFields, childInfo),
648
+ INSERT_ID_PRE_LOGIC: idVars.preLine,
649
+ INSERT_ID_DATA: idVars.dataLine,
532
650
  INSERT_DATA_MAPPING: this.generateInsertDataMapping(fields, childInfo),
651
+ INSERT_SUCCESS_COND: idVars.successCond,
652
+ INSERT_GET_ID: idVars.getId,
533
653
  UPDATE_DATA_MAPPING: this.generateUpdateDataMapping(fields),
534
654
  UPDATE_FIELDS_ARRAY: this.generateUpdateFieldsArray(fields),
535
655
  VALUE_OBJECT_IMPORTS: this.generateValueObjectImports(fields),
536
656
  AGGREGATE_REF_IMPORTS: this.generateAggregateRefImports(modelName, fields),
657
+ ID_HELPERS: this.generateIdHelpers(),
537
658
  LIST_METHODS: this.generateListMethods(modelName, fieldNamesStr, childInfo),
538
659
  GET_BY_PARENT_ID_METHOD: this.generateGetByParentIdMethod(modelName, fields, childInfo),
539
660
  GET_RESOURCE_OWNER_METHOD: this.generateGetResourceOwnerMethod(childInfo)
@@ -552,12 +673,14 @@ class StoreGenerator {
552
673
  ENTITY_IMPORT_ITEMS: entityImportItems.join(', '),
553
674
  ROW_INTERFACE: rowInterface,
554
675
  STORE_CLASS: storeClass,
676
+ CRYPTO_IMPORT: this.generateCryptoImport(),
555
677
  VALUE_OBJECT_IMPORTS: variables.VALUE_OBJECT_IMPORTS,
556
678
  AGGREGATE_REF_IMPORTS: variables.AGGREGATE_REF_IMPORTS
557
679
  });
558
680
  }
559
- generateFromConfig(config) {
681
+ generateFromConfig(config, identifiers = 'numeric') {
560
682
  const result = {};
683
+ this.identifiers = identifiers;
561
684
  // First, collect all value object names and configs
562
685
  this.availableValueObjects.clear();
563
686
  if (config.domain.valueObjects) {
@@ -582,16 +705,16 @@ class StoreGenerator {
582
705
  }
583
706
  return result;
584
707
  }
585
- generateFromYamlFile(yamlFilePath) {
708
+ generateFromYamlFile(yamlFilePath, identifiers = 'numeric') {
586
709
  const yamlContent = fs.readFileSync(yamlFilePath, 'utf8');
587
710
  const config = (0, yaml_1.parse)(yamlContent);
588
711
  if (!(0, configTypes_1.isValidModuleConfig)(config)) {
589
712
  throw new Error('Configuration does not match new module format. Expected domain.aggregates structure.');
590
713
  }
591
- return this.generateFromConfig(config);
714
+ return this.generateFromConfig(config, identifiers);
592
715
  }
593
- async generateAndSaveFiles(yamlFilePath, moduleDir, opts) {
594
- const storesByModel = this.generateFromYamlFile(yamlFilePath);
716
+ async generateAndSaveFiles(yamlFilePath, moduleDir, opts, identifiers = 'numeric') {
717
+ const storesByModel = this.generateFromYamlFile(yamlFilePath, identifiers);
595
718
  const storesDir = path.join(moduleDir, 'infrastructure', 'stores');
596
719
  fs.mkdirSync(storesDir, { recursive: true });
597
720
  for (const [modelName, code] of Object.entries(storesByModel)) {
@@ -3,5 +3,5 @@ providers:
3
3
  config:
4
4
  database: mysql
5
5
  styling: bootstrap
6
- identifiers: id
6
+ identifiers: numeric
7
7
  modules: {}
@@ -2,4 +2,4 @@ export declare const storeTemplates: {
2
2
  rowInterface: string;
3
3
  storeClass: string;
4
4
  };
5
- export declare const storeFileTemplate = "import { Injectable } from '../../../../system';\nimport { {{ENTITY_IMPORT_ITEMS}} } from '../../domain/entities/{{ENTITY_NAME}}';\nimport type { ISqlProvider } from '@currentjs/provider-mysql';{{VALUE_OBJECT_IMPORTS}}{{AGGREGATE_REF_IMPORTS}}\n\n{{ROW_INTERFACE}}\n\n{{STORE_CLASS}}\n";
5
+ export declare const storeFileTemplate = "import { Injectable } from '../../../../system';\nimport { {{ENTITY_IMPORT_ITEMS}} } from '../../domain/entities/{{ENTITY_NAME}}';\nimport type { ISqlProvider } from '@currentjs/provider-mysql';{{CRYPTO_IMPORT}}{{VALUE_OBJECT_IMPORTS}}{{AGGREGATE_REF_IMPORTS}}\n\n{{ROW_INTERFACE}}\n\n{{STORE_CLASS}}\n";
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.storeFileTemplate = exports.storeTemplates = void 0;
4
4
  exports.storeTemplates = {
5
5
  rowInterface: `export interface {{ENTITY_NAME}}Row {
6
- id: number;
6
+ id: {{ID_TYPE}};
7
7
  {{ROW_FIELDS}}
8
8
  createdAt: string;
9
9
  updatedAt: string;
@@ -25,20 +25,20 @@ export class {{ENTITY_NAME}}Store {
25
25
  private ensureParsed(value: any): any {
26
26
  return typeof value === 'string' ? JSON.parse(value) : value;
27
27
  }
28
-
28
+ {{ID_HELPERS}}
29
29
  private rowToModel(row: {{ENTITY_NAME}}Row): {{ENTITY_NAME}} {
30
30
  return new {{ENTITY_NAME}}(
31
- row.id,
31
+ {{ROW_ID_EXPR}},
32
32
  {{ROW_TO_MODEL_MAPPING}}
33
33
  );
34
34
  }
35
35
 
36
36
  {{LIST_METHODS}}
37
37
 
38
- async getById(id: number): Promise<{{ENTITY_NAME}} | null> {
38
+ async getById(id: {{ID_TYPE}}): Promise<{{ENTITY_NAME}} | null> {
39
39
  const result = await this.db.query(
40
- \`SELECT {{FIELD_NAMES}} FROM \\\`\${this.tableName}\\\` WHERE id = :id AND deletedAt IS NULL\`,
41
- { id }
40
+ \`SELECT {{FIELD_NAMES}} FROM \\\`\${this.tableName}\\\` WHERE {{WHERE_ID_EXPR}} AND deletedAt IS NULL\`,
41
+ { id{{ID_PARAM_EXPR}} }
42
42
  );
43
43
 
44
44
  if (result.success && result.data && result.data.length > 0) {
@@ -49,8 +49,9 @@ export class {{ENTITY_NAME}}Store {
49
49
 
50
50
  async insert(entity: {{ENTITY_NAME}}): Promise<{{ENTITY_NAME}}> {
51
51
  const now = new Date();
52
+ {{INSERT_ID_PRE_LOGIC}}
52
53
  const data: Partial<{{ENTITY_NAME}}Row> = {
53
- {{INSERT_DATA_MAPPING}},
54
+ {{INSERT_ID_DATA}}{{INSERT_DATA_MAPPING}},
54
55
  createdAt: this.toMySQLDatetime(now),
55
56
  updatedAt: this.toMySQLDatetime(now)
56
57
  };
@@ -64,15 +65,15 @@ export class {{ENTITY_NAME}}Store {
64
65
  cleanData
65
66
  );
66
67
 
67
- if (result.success && result.insertId) {
68
- const newId = typeof result.insertId === 'string' ? parseInt(result.insertId, 10) : result.insertId;
68
+ if (result.success{{INSERT_SUCCESS_COND}}) {
69
+ {{INSERT_GET_ID}}
69
70
  return this.getById(newId) as Promise<{{ENTITY_NAME}}>;
70
71
  }
71
72
 
72
73
  throw new Error('Failed to insert {{ENTITY_NAME}}');
73
74
  }
74
75
 
75
- async update(id: number, entity: {{ENTITY_NAME}}): Promise<{{ENTITY_NAME}}> {
76
+ async update(id: {{ID_TYPE}}, entity: {{ENTITY_NAME}}): Promise<{{ENTITY_NAME}}> {
76
77
  const now = new Date();
77
78
  const rawData: Partial<{{ENTITY_NAME}}Row> = {
78
79
  {{UPDATE_DATA_MAPPING}},
@@ -85,8 +86,8 @@ export class {{ENTITY_NAME}}Store {
85
86
  .map(f => \`\\\`\${f}\\\` = :\${f}\`).join(', ');
86
87
 
87
88
  const result = await this.db.query(
88
- \`UPDATE \\\`\${this.tableName}\\\` SET \${updateFields}, updatedAt = :updatedAt WHERE id = :id\`,
89
- { ...cleanData, id }
89
+ \`UPDATE \\\`\${this.tableName}\\\` SET \${updateFields}, updatedAt = :updatedAt WHERE {{WHERE_ID_EXPR}}\`,
90
+ { ...cleanData, id{{ID_PARAM_EXPR}} }
90
91
  );
91
92
 
92
93
  if (result.success) {
@@ -96,20 +97,20 @@ export class {{ENTITY_NAME}}Store {
96
97
  throw new Error('Failed to update {{ENTITY_NAME}}');
97
98
  }
98
99
 
99
- async softDelete(id: number): Promise<boolean> {
100
+ async softDelete(id: {{ID_TYPE}}): Promise<boolean> {
100
101
  const now = new Date();
101
102
  const result = await this.db.query(
102
- \`UPDATE \\\`\${this.tableName}\\\` SET deletedAt = :deletedAt WHERE id = :id\`,
103
- { deletedAt: this.toMySQLDatetime(now), id }
103
+ \`UPDATE \\\`\${this.tableName}\\\` SET deletedAt = :deletedAt WHERE {{WHERE_ID_EXPR}}\`,
104
+ { deletedAt: this.toMySQLDatetime(now), id{{ID_PARAM_EXPR}} }
104
105
  );
105
106
 
106
107
  return result.success;
107
108
  }
108
109
 
109
- async hardDelete(id: number): Promise<boolean> {
110
+ async hardDelete(id: {{ID_TYPE}}): Promise<boolean> {
110
111
  const result = await this.db.query(
111
- \`DELETE FROM \\\`\${this.tableName}\\\` WHERE id = :id\`,
112
- { id }
112
+ \`DELETE FROM \\\`\${this.tableName}\\\` WHERE {{WHERE_ID_EXPR}}\`,
113
+ { id{{ID_PARAM_EXPR}} }
113
114
  );
114
115
 
115
116
  return result.success;
@@ -119,7 +120,7 @@ export class {{ENTITY_NAME}}Store {
119
120
  };
120
121
  exports.storeFileTemplate = `import { Injectable } from '../../../../system';
121
122
  import { {{ENTITY_IMPORT_ITEMS}} } from '../../domain/entities/{{ENTITY_NAME}}';
122
- import type { ISqlProvider } from '@currentjs/provider-mysql';{{VALUE_OBJECT_IMPORTS}}{{AGGREGATE_REF_IMPORTS}}
123
+ import type { ISqlProvider } from '@currentjs/provider-mysql';{{CRYPTO_IMPORT}}{{VALUE_OBJECT_IMPORTS}}{{AGGREGATE_REF_IMPORTS}}
123
124
 
124
125
  {{ROW_INTERFACE}}
125
126
 
@@ -1,13 +1,14 @@
1
- import { ModuleConfig } from '../types/configTypes';
1
+ import { ModuleConfig, IdentifierType } from '../types/configTypes';
2
2
  export declare class UseCaseGenerator {
3
3
  private availableAggregates;
4
+ private identifiers;
4
5
  private generateUseCaseMethod;
5
6
  private generateGetResourceOwnerMethod;
6
7
  private generateUseCase;
7
- generateFromConfig(config: ModuleConfig): Record<string, string>;
8
- generateFromYamlFile(yamlFilePath: string): Record<string, string>;
8
+ generateFromConfig(config: ModuleConfig, identifiers?: IdentifierType): Record<string, string>;
9
+ generateFromYamlFile(yamlFilePath: string, identifiers?: IdentifierType): Record<string, string>;
9
10
  generateAndSaveFiles(yamlFilePath: string, moduleDir: string, opts?: {
10
11
  force?: boolean;
11
12
  skipOnConflict?: boolean;
12
- }): Promise<void>;
13
+ }, identifiers?: IdentifierType): Promise<void>;
13
14
  }