@domain-first/project-structure 1.2.0 → 2.0.1
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/dist/index.cjs +163 -175
- package/dist/index.js +163 -175
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -282,41 +282,26 @@ export class ${naming.ClassName}${aggregateNaming.ClassName}Repository implement
|
|
|
282
282
|
}
|
|
283
283
|
|
|
284
284
|
`.trim());
|
|
285
|
-
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
|
|
286
|
-
const wiringFolder = boundedContextFolder.subitem([
|
|
287
|
-
'wiring',
|
|
288
|
-
'infrastructure',
|
|
289
|
-
'repositories',
|
|
290
|
-
naming.fileName
|
|
291
|
-
]);
|
|
292
|
-
wiringFolder.createFile(`wire-${naming.fileName}-${aggregateNaming.fileName}-repository.ts`, `
|
|
293
|
-
import { wireClass } from '@domain-first/wire'
|
|
294
|
-
import { ${naming.ClassName}${aggregateNaming.ClassName}Repository } from '../../../../infrastructure/repositories/${naming.fileName}/${naming.fileName}-${aggregateNaming.fileName}-repository'
|
|
295
|
-
|
|
296
|
-
export const wire${naming.ClassName}${aggregateNaming.ClassName}Repository = wireClass(
|
|
297
|
-
${naming.ClassName}${aggregateNaming.ClassName}Repository,
|
|
298
|
-
[]
|
|
299
|
-
)
|
|
300
|
-
`.trim());
|
|
301
|
-
}
|
|
302
285
|
}
|
|
303
286
|
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
|
|
304
287
|
const implementationNaming = new UnknownFormatNaming(infrastructureImplementationType);
|
|
305
288
|
const testImplementationNaming = new UnknownFormatNaming(testImplementationType);
|
|
306
289
|
boundedContextFolder.subitem([
|
|
307
290
|
'wiring',
|
|
308
|
-
'domain',
|
|
309
291
|
'repositories'
|
|
310
292
|
]).createFile(`wire-${aggregateNaming.fileName}-repository.ts`, `
|
|
311
|
-
import {
|
|
312
|
-
|
|
293
|
+
import { wireClass } from '@domain-first/wire'
|
|
294
|
+
import { envBranchedWire } from '../../../../shared/wiring/env-branched-wire'
|
|
295
|
+
${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName, fileName })=>`import { ${ClassName}${aggregateNaming.ClassName}Repository } from '../../infrastructure/repositories/${fileName}/${fileName}-${aggregateNaming.fileName}-repository'`).join('\n')}
|
|
296
|
+
|
|
297
|
+
${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName })=>`const wire${ClassName}Implementation = wireClass(${ClassName}${aggregateNaming.ClassName}Repository, [])`).join('\n\n')}
|
|
313
298
|
|
|
314
299
|
export const wire${aggregateNaming.ClassName}Repository = envBranchedWire({
|
|
315
|
-
test: wire${addTestImplementation ? testImplementationNaming.ClassName : implementationNaming.ClassName}
|
|
316
|
-
development: wire${implementationNaming.ClassName}
|
|
317
|
-
production: wire${implementationNaming.ClassName}
|
|
300
|
+
test: wire${addTestImplementation ? testImplementationNaming.ClassName : implementationNaming.ClassName}Implementation,
|
|
301
|
+
development: wire${implementationNaming.ClassName}Implementation,
|
|
302
|
+
production: wire${implementationNaming.ClassName}Implementation
|
|
318
303
|
})
|
|
319
|
-
`.trim());
|
|
304
|
+
`.trim());
|
|
320
305
|
}
|
|
321
306
|
}
|
|
322
307
|
};
|
|
@@ -327,14 +312,8 @@ const scaffoldNewApplicationPort = async (boundedContextFolder)=>{
|
|
|
327
312
|
const naming = new UnknownFormatNaming(name);
|
|
328
313
|
const wiringFolder = boundedContextFolder.subitem([
|
|
329
314
|
'wiring',
|
|
330
|
-
'application',
|
|
331
315
|
'ports'
|
|
332
316
|
]);
|
|
333
|
-
const infraFolder = boundedContextFolder.subitem([
|
|
334
|
-
'wiring',
|
|
335
|
-
'infrastructure',
|
|
336
|
-
'application-ports'
|
|
337
|
-
]);
|
|
338
317
|
const applicationPortsFolder = boundedContextFolder.subitem([
|
|
339
318
|
'application',
|
|
340
319
|
'ports'
|
|
@@ -374,29 +353,24 @@ export class ${currentNaming.ClassName} extends ${naming.ClassName} {
|
|
|
374
353
|
|
|
375
354
|
}
|
|
376
355
|
`);
|
|
377
|
-
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) infraFolder.subitem([
|
|
378
|
-
implementation
|
|
379
|
-
]).createFile(`wire-${currentNaming.fileName}.ts`, `
|
|
380
|
-
import { wireClass } from '@domain-first/wire'
|
|
381
|
-
import { ${currentNaming.ClassName} } from '../../../../infrastructure/application-adapters/${implementation}/${currentNaming.fileName}'
|
|
382
|
-
|
|
383
|
-
export const wire${currentNaming.ClassName} = wireClass(
|
|
384
|
-
${currentNaming.ClassName},
|
|
385
|
-
[]
|
|
386
|
-
)
|
|
387
|
-
`.trim());
|
|
388
356
|
}
|
|
389
357
|
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) wiringFolder.createFile(`wire-${naming.fileName}.ts`, `
|
|
390
|
-
import {
|
|
358
|
+
import { wireClass } from '@domain-first/wire'
|
|
359
|
+
import { envBranchedWire } from '../../../${'shared' === boundedContextFolder.name ? '' : '../'}shared/wiring/env-branched-wire'
|
|
391
360
|
${implementationTypes.map((x)=>({
|
|
392
361
|
naming: new UnknownFormatNaming(`${x}-${naming.fileName}`),
|
|
393
362
|
implementation: x
|
|
394
|
-
})).map(({ naming: { ClassName, fileName }, implementation })=>`import {
|
|
363
|
+
})).map(({ naming: { ClassName, fileName }, implementation })=>`import { ${ClassName} } from '../../infrastructure/application-adapters/${implementation}/${fileName}'`).join('\n')}
|
|
364
|
+
|
|
365
|
+
${implementationTypes.map((x)=>({
|
|
366
|
+
naming: new UnknownFormatNaming(`${x}-${naming.fileName}`),
|
|
367
|
+
implementation: x
|
|
368
|
+
})).map(({ naming: { ClassName }, implementation })=>`const wire${new UnknownFormatNaming(implementation).ClassName}Implementation = wireClass(${ClassName}, [])`).join('\n\n')}
|
|
395
369
|
|
|
396
370
|
export const wire${naming.ClassName} = envBranchedWire({
|
|
397
|
-
test: wire${new UnknownFormatNaming(`${implementationTypes.at(-1)}
|
|
398
|
-
development: wire${new UnknownFormatNaming(`${implementationTypes.at(0)}
|
|
399
|
-
production: wire${new UnknownFormatNaming(`${implementationTypes.at(0)}
|
|
371
|
+
test: wire${new UnknownFormatNaming(`${implementationTypes.at(-1)}-implementation`).ClassName},
|
|
372
|
+
development: wire${new UnknownFormatNaming(`${implementationTypes.at(0)}-implementation`).ClassName},
|
|
373
|
+
production: wire${new UnknownFormatNaming(`${implementationTypes.at(0)}-implementation`).ClassName}
|
|
400
374
|
})
|
|
401
375
|
|
|
402
376
|
`.trim());
|
|
@@ -436,9 +410,14 @@ const scaffoldNewCommand = async (boundedContextFolder)=>{
|
|
|
436
410
|
message: 'Name: '
|
|
437
411
|
});
|
|
438
412
|
const naming = new UnknownFormatNaming(commandName);
|
|
439
|
-
const
|
|
440
|
-
|
|
413
|
+
const commandType = await (0, prompts_namespaceObject.select)({
|
|
414
|
+
choices: [
|
|
415
|
+
'Execution (with infrastructure implementation)',
|
|
416
|
+
'Orchestrator (no infrastructure implementation)'
|
|
417
|
+
],
|
|
418
|
+
message: 'Command type'
|
|
441
419
|
});
|
|
420
|
+
const isOrchestrator = 'Orchestrator (no infrastructure implementation)' === commandType;
|
|
442
421
|
if (!isOrchestrator) {
|
|
443
422
|
const implementationType = await (0, prompts_namespaceObject.input)({
|
|
444
423
|
message: 'Command infrastructure implementation type:',
|
|
@@ -462,81 +441,73 @@ const scaffoldNewCommand = async (boundedContextFolder)=>{
|
|
|
462
441
|
infrastructureFolder.subitem([
|
|
463
442
|
formatNaming.fileName
|
|
464
443
|
]).createFile(`${formatNaming.fileName}-${naming.fileName}-command.ts`, ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers') ? `
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
export class ${formatNaming.ClassName}${naming.ClassName}Command implements ${naming.ClassName}Command {
|
|
469
|
-
constructor() {}
|
|
444
|
+
import { defineHandler } from '@domain-first/handlers'
|
|
445
|
+
import { ${naming.ClassName}Command } from '../../../application/commands/execution/${naming.fileName}-command'
|
|
470
446
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
handler: async (input) => {
|
|
475
|
-
return {}
|
|
476
|
-
}
|
|
477
|
-
})
|
|
447
|
+
export class ${formatNaming.ClassName}${naming.ClassName}Command extends ${naming.ClassName}Command {
|
|
448
|
+
constructor() {
|
|
449
|
+
super()
|
|
478
450
|
}
|
|
479
|
-
`.trim() : `
|
|
480
|
-
import { ${naming.ClassName}Command } from '../../../domain/commands/${naming.fileName}-command'
|
|
481
451
|
|
|
482
|
-
|
|
452
|
+
handle = defineHandler({
|
|
453
|
+
inputSchema: ${naming.ClassName}Command.inputSchema,
|
|
454
|
+
outputSchema: ${naming.ClassName}Command.outputSchema,
|
|
455
|
+
handler: async (input) => {
|
|
456
|
+
return {}
|
|
457
|
+
}
|
|
458
|
+
})
|
|
459
|
+
}
|
|
460
|
+
`.trim() : `
|
|
461
|
+
import { ${naming.ClassName}Command } from '../../../domain/commands/${naming.fileName}-command'
|
|
483
462
|
|
|
463
|
+
export class ${formatNaming.ClassName}${naming.ClassName}Command extends ${naming.ClassName}Command {
|
|
464
|
+
constructor() {
|
|
465
|
+
super()
|
|
484
466
|
}
|
|
467
|
+
}
|
|
485
468
|
`.trim());
|
|
486
|
-
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
|
|
487
|
-
const wiringFolder = boundedContextFolder.subitem([
|
|
488
|
-
'wiring',
|
|
489
|
-
'infrastructure',
|
|
490
|
-
'commands',
|
|
491
|
-
formatNaming.fileName
|
|
492
|
-
]);
|
|
493
|
-
wiringFolder.createFile(`wire-${formatNaming.fileName}-${naming.fileName}-command.ts`, `
|
|
494
|
-
import { wireClass } from '@domain-first/wire'
|
|
495
|
-
import { ${formatNaming.ClassName}${naming.ClassName}Command } from '../../../../infrastructure/commands/${formatNaming.fileName}/${formatNaming.fileName}-${naming.fileName}-command'
|
|
496
|
-
|
|
497
|
-
export const wire${formatNaming.ClassName}${naming.ClassName}Command = wireClass(
|
|
498
|
-
${formatNaming.ClassName}${naming.ClassName}Command,
|
|
499
|
-
[]
|
|
500
|
-
)
|
|
501
|
-
|
|
502
|
-
`.trim());
|
|
503
|
-
}
|
|
504
469
|
}
|
|
505
|
-
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers')) commandsFolder.
|
|
506
|
-
|
|
470
|
+
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers')) commandsFolder.subitem([
|
|
471
|
+
'execution'
|
|
472
|
+
]).createFile(`${naming.fileName}-command.ts`, `
|
|
473
|
+
import type { Handler } from '@domain-first/handlers'
|
|
507
474
|
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
475
|
+
export abstract class ${naming.ClassName}Command {
|
|
476
|
+
static inputSchema = {}
|
|
477
|
+
static outputSchema = {}
|
|
511
478
|
|
|
512
|
-
|
|
513
|
-
|
|
479
|
+
abstract handle: Handler<typeof ${naming.ClassName}Command.inputSchema, typeof ${naming.ClassName}Command.outputSchema>
|
|
480
|
+
}
|
|
514
481
|
`.trim());
|
|
515
482
|
else commandsFolder.createFile(`${naming.fileName}-command.ts`, `
|
|
516
|
-
|
|
483
|
+
export abstract class ${naming.ClassName}Command {
|
|
517
484
|
|
|
518
|
-
|
|
485
|
+
}`.trim());
|
|
519
486
|
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
|
|
520
487
|
const implementationNaming = new UnknownFormatNaming(implementationType);
|
|
521
488
|
const testImplementationNaming = new UnknownFormatNaming(testImplementationType);
|
|
522
489
|
boundedContextFolder.subitem([
|
|
523
490
|
'wiring',
|
|
524
|
-
'application',
|
|
525
491
|
'commands'
|
|
526
492
|
]).createFile(`wire-${naming.fileName}-command.ts`, `
|
|
527
|
-
|
|
528
|
-
|
|
493
|
+
import { wireClass } from '@domain-first/wire'
|
|
494
|
+
import { envBranchedWire } from '../../../../shared/wiring/env-branched-wire'
|
|
495
|
+
${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName, fileName })=>`import { ${ClassName}${naming.ClassName}Command } from '../../infrastructure/commands/${fileName}/${fileName}-${naming.fileName}-command'`).join('\n')}
|
|
529
496
|
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
}
|
|
497
|
+
${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName })=>`const wire${ClassName}Implementation = wireClass(${ClassName}${naming.ClassName}Command, [])`).join('\n\n')}
|
|
498
|
+
|
|
499
|
+
export const wire${naming.ClassName}Command = envBranchedWire({
|
|
500
|
+
test: wire${addTestImplementation ? testImplementationNaming.ClassName : implementationNaming.ClassName}Implementation,
|
|
501
|
+
development: wire${implementationNaming.ClassName}Implementation,
|
|
502
|
+
production: wire${implementationNaming.ClassName}Implementation
|
|
503
|
+
})
|
|
535
504
|
`.trim());
|
|
536
505
|
}
|
|
537
506
|
return;
|
|
538
507
|
}
|
|
539
|
-
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers')) commandsFolder.
|
|
508
|
+
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers')) commandsFolder.subitem([
|
|
509
|
+
'orchestration'
|
|
510
|
+
]).createFile(`${naming.fileName}-command.ts`, `
|
|
540
511
|
import { defineHandler } from '@domain-first/handlers'
|
|
541
512
|
|
|
542
513
|
export class ${naming.ClassName}Command {
|
|
@@ -552,7 +523,9 @@ export class ${naming.ClassName}Command {
|
|
|
552
523
|
})
|
|
553
524
|
}
|
|
554
525
|
`.trim());
|
|
555
|
-
else commandsFolder.
|
|
526
|
+
else commandsFolder.subitem([
|
|
527
|
+
'orchestration'
|
|
528
|
+
]).createFile(`${naming.fileName}-command.ts`, `
|
|
556
529
|
export class ${naming.ClassName}Command {
|
|
557
530
|
|
|
558
531
|
}`.trim());
|
|
@@ -562,7 +535,7 @@ export class ${naming.ClassName}Command {
|
|
|
562
535
|
'commands'
|
|
563
536
|
]).createFile(`wire-${naming.fileName}-command.ts`, `
|
|
564
537
|
import { wireClass } from '@domain-first/wire'
|
|
565
|
-
import { ${naming.ClassName}Command } from '../../../application/commands/${naming.fileName}-command'
|
|
538
|
+
import { ${naming.ClassName}Command } from '../../../application/commands/orchestration/${naming.fileName}-command'
|
|
566
539
|
|
|
567
540
|
export const wire${naming.ClassName}Command = wireClass(${naming.ClassName}Command, [])
|
|
568
541
|
`.trim());
|
|
@@ -614,7 +587,7 @@ const scaffoldNewErrorUseCase = async (boundedContextFolder)=>{
|
|
|
614
587
|
message: 'Error name:'
|
|
615
588
|
});
|
|
616
589
|
const naming = new UnknownFormatNaming(errorName);
|
|
617
|
-
currentErrorFolder.file('index.ts').addLine(`export const ${naming.ClassName}Error = ${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Errors.define('${naming.fileName}')`, '\n\n');
|
|
590
|
+
currentErrorFolder.file('index.ts').addLine(`export const ${naming.ClassName}${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Error = ${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Errors.define('${naming.fileName}')`, '\n\n');
|
|
618
591
|
return;
|
|
619
592
|
}
|
|
620
593
|
if ('New namespace' === selectedVariant) {
|
|
@@ -625,17 +598,18 @@ const scaffoldNewErrorUseCase = async (boundedContextFolder)=>{
|
|
|
625
598
|
currentErrorFolder.createFile(`${fileName}.ts`, `
|
|
626
599
|
import { errorNamespace } from '@domain-first/errors'
|
|
627
600
|
|
|
628
|
-
const ${ClassName}Errors = errorNamespace('${boundedContextFolder.name}').subnamespace('${fileName}')
|
|
601
|
+
export const ${ClassName}${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Errors = errorNamespace('${boundedContextFolder.name}').subnamespace('${fileName}')
|
|
629
602
|
`);
|
|
630
|
-
currentErrorFolder.file('index.ts').addLine(`export * from './${fileName}'
|
|
603
|
+
currentErrorFolder.file('index.ts').addLine(`export * from './${fileName}'`, '\n\n');
|
|
631
604
|
return;
|
|
632
605
|
}
|
|
633
606
|
const namespace = selectedVariant.substring(23);
|
|
607
|
+
const namespaceNaming = new UnknownFormatNaming(namespace);
|
|
634
608
|
const errorName = await (0, prompts_namespaceObject.input)({
|
|
635
609
|
message: 'Error name:'
|
|
636
610
|
});
|
|
637
611
|
const { ClassName, fileName } = new UnknownFormatNaming(errorName);
|
|
638
|
-
currentErrorFolder.file(`${namespace}.ts`).addLine(`export const ${ClassName}Error = ${new UnknownFormatNaming(
|
|
612
|
+
currentErrorFolder.file(`${namespace}.ts`).addLine(`export const ${ClassName}${namespaceNaming.ClassName}${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Error = ${namespaceNaming.ClassName}${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Errors.define('${fileName}')`, '\n\n');
|
|
639
613
|
};
|
|
640
614
|
const scaffoldNewHandlersRestEndpoint = async (boundedContextFolder)=>{
|
|
641
615
|
const restPresentationFolder = boundedContextFolder.subitem([
|
|
@@ -654,11 +628,27 @@ const scaffoldNewHandlersRestEndpoint = async (boundedContextFolder)=>{
|
|
|
654
628
|
controller = await (0, prompts_namespaceObject.input)({
|
|
655
629
|
message: 'Name: '
|
|
656
630
|
});
|
|
657
|
-
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire'))
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
631
|
+
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
|
|
632
|
+
boundedContextFolder.subitem([
|
|
633
|
+
'wiring',
|
|
634
|
+
'presentation',
|
|
635
|
+
'rest'
|
|
636
|
+
]).file('index.ts').addLine(`export * from './${controller}'`);
|
|
637
|
+
const sharedRestFolder = boundedContextFolder.subitem([
|
|
638
|
+
'..',
|
|
639
|
+
'..',
|
|
640
|
+
'presentation',
|
|
641
|
+
'rest'
|
|
642
|
+
]);
|
|
643
|
+
sharedRestFolder.file('wires.ts').addLine(`export * from '../../bounded-contexts/${boundedContextFolder.name}/wiring/presentation/rest/${controller}'`);
|
|
644
|
+
if (!sharedRestFolder.file('index.ts').exists) sharedRestFolder.createFile('index.ts', `
|
|
645
|
+
import * as wires from './wires'
|
|
646
|
+
|
|
647
|
+
const restWires = Object.values(wires)
|
|
648
|
+
|
|
649
|
+
export const restHandlers = restWires.map(x => x().handle)
|
|
650
|
+
`.trim());
|
|
651
|
+
}
|
|
662
652
|
}
|
|
663
653
|
const method = await (0, prompts_namespaceObject.select)({
|
|
664
654
|
message: 'Method:',
|
|
@@ -676,25 +666,24 @@ const scaffoldNewHandlersRestEndpoint = async (boundedContextFolder)=>{
|
|
|
676
666
|
const controllerFolder = restPresentationFolder.subitem([
|
|
677
667
|
controller
|
|
678
668
|
]);
|
|
669
|
+
const endpointFolder = controllerFolder.subitem(path);
|
|
679
670
|
const nameBase = `${controller}-${path.length ? `${path.join('-')}-` : ''}${method}-endpoint`;
|
|
680
671
|
const endpointNaming = new UnknownFormatNaming(nameBase);
|
|
681
|
-
|
|
672
|
+
endpointFolder.createFile(`${method.toUpperCase()}.ts`, `
|
|
682
673
|
import { EndpointGenerator } from '@domain-first/handlers-rest'
|
|
683
674
|
|
|
684
675
|
export class ${endpointNaming.ClassName} {
|
|
685
|
-
constructor(
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
}
|
|
676
|
+
constructor(
|
|
677
|
+
private readonly endpointGenerator: EndpointGenerator,
|
|
678
|
+
private readonly handler: never
|
|
679
|
+
) {}
|
|
690
680
|
|
|
691
681
|
get handle() {
|
|
692
|
-
return this.endpointGenerator(this.
|
|
682
|
+
return this.endpointGenerator(this.handler.handle, {
|
|
693
683
|
route: { method: '${method}', path: ['${boundedContextFolder.name}', '${controller}'${path.length ? `, ${path.map((x)=>`'${x}'`).join(', ')}` : ''}] },
|
|
694
684
|
tags: ['${boundedContextFolder.name}: ${controller}'],
|
|
695
685
|
})
|
|
696
686
|
}
|
|
697
|
-
|
|
698
687
|
}
|
|
699
688
|
`.trim());
|
|
700
689
|
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
|
|
@@ -708,7 +697,7 @@ export class ${endpointNaming.ClassName} {
|
|
|
708
697
|
const wireNaming = new UnknownFormatNaming(wireNameBase);
|
|
709
698
|
wiringFolder.createFile(`${wireNaming.fileName}.ts`, `
|
|
710
699
|
import { wireClass } from '@domain-first/wire'
|
|
711
|
-
import { ${endpointNaming.ClassName} } from '../../../../presentation/rest/${controller}/${
|
|
700
|
+
import { ${endpointNaming.ClassName} } from '../../../../presentation/rest/${controller}/${path.length ? `${path.join('/')}/` : ''}${method.toUpperCase()}'
|
|
712
701
|
|
|
713
702
|
export const wire${endpointNaming.ClassName} = wireClass(
|
|
714
703
|
${endpointNaming.ClassName},
|
|
@@ -731,9 +720,14 @@ const scaffoldNewQuery = async (boundedContextFolder)=>{
|
|
|
731
720
|
message: 'Name: '
|
|
732
721
|
});
|
|
733
722
|
const naming = new UnknownFormatNaming(queryName);
|
|
734
|
-
const
|
|
735
|
-
|
|
723
|
+
const queryType = await (0, prompts_namespaceObject.select)({
|
|
724
|
+
choices: [
|
|
725
|
+
'Execution (with infrastructure implementation)',
|
|
726
|
+
'Orchestrator (no infrastructure implementation)'
|
|
727
|
+
],
|
|
728
|
+
message: 'Query type'
|
|
736
729
|
});
|
|
730
|
+
const isOrchestrator = 'Orchestrator (no infrastructure implementation)' === queryType;
|
|
737
731
|
if (!isOrchestrator) {
|
|
738
732
|
const implementationType = await (0, prompts_namespaceObject.input)({
|
|
739
733
|
message: 'Query infrastructure implementation type:',
|
|
@@ -757,80 +751,73 @@ const scaffoldNewQuery = async (boundedContextFolder)=>{
|
|
|
757
751
|
infrastructureFolder.subitem([
|
|
758
752
|
formatNaming.fileName
|
|
759
753
|
]).createFile(`${formatNaming.fileName}-${naming.fileName}-query.ts`, ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers') ? `
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
export class ${formatNaming.ClassName}${naming.ClassName}Query implements ${naming.ClassName}Query {
|
|
764
|
-
constructor() {}
|
|
754
|
+
import { defineHandler } from '@domain-first/handlers'
|
|
755
|
+
import { ${naming.ClassName}Query } from '../../../application/queries/execution/${naming.fileName}-query'
|
|
765
756
|
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
handler: async (input) => {
|
|
770
|
-
return {}
|
|
771
|
-
}
|
|
772
|
-
})
|
|
757
|
+
export class ${formatNaming.ClassName}${naming.ClassName}Query extends ${naming.ClassName}Query {
|
|
758
|
+
constructor() {
|
|
759
|
+
super()
|
|
773
760
|
}
|
|
774
|
-
`.trim() : `
|
|
775
|
-
import { ${naming.ClassName}Query } from '../../../domain/queries/${naming.fileName}-query'
|
|
776
761
|
|
|
777
|
-
|
|
762
|
+
handle = defineHandler({
|
|
763
|
+
inputSchema: ${naming.ClassName}Query.inputSchema,
|
|
764
|
+
outputSchema: ${naming.ClassName}Query.outputSchema,
|
|
765
|
+
handler: async (input) => {
|
|
766
|
+
return {}
|
|
767
|
+
}
|
|
768
|
+
})
|
|
769
|
+
}
|
|
770
|
+
`.trim() : `
|
|
771
|
+
import { ${naming.ClassName}Query } from '../../../domain/queries/${naming.fileName}-query'
|
|
778
772
|
|
|
773
|
+
export class ${formatNaming.ClassName}${naming.ClassName}Query extends ${naming.ClassName}Query {
|
|
774
|
+
constructor() {
|
|
775
|
+
super()
|
|
779
776
|
}
|
|
777
|
+
}
|
|
780
778
|
`.trim());
|
|
781
|
-
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
|
|
782
|
-
const wiringFolder = boundedContextFolder.subitem([
|
|
783
|
-
'wiring',
|
|
784
|
-
'infrastructure',
|
|
785
|
-
'queries',
|
|
786
|
-
formatNaming.fileName
|
|
787
|
-
]);
|
|
788
|
-
wiringFolder.createFile(`wire-${formatNaming.fileName}-${naming.fileName}-query.ts`, `
|
|
789
|
-
import { wireClass } from '@domain-first/wire'
|
|
790
|
-
import { ${formatNaming.ClassName}${naming.ClassName}Query } from '../../../../infrastructure/queries/${formatNaming.fileName}/${formatNaming.fileName}-${naming.fileName}-query'
|
|
791
|
-
|
|
792
|
-
export const wire${formatNaming.ClassName}${naming.ClassName}Query = wireClass(
|
|
793
|
-
${formatNaming.ClassName}${naming.ClassName}Query,
|
|
794
|
-
[]
|
|
795
|
-
)
|
|
796
|
-
`.trim());
|
|
797
|
-
}
|
|
798
779
|
}
|
|
799
|
-
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers')) queriesFolder.
|
|
800
|
-
|
|
780
|
+
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers')) queriesFolder.subitem([
|
|
781
|
+
'execution'
|
|
782
|
+
]).createFile(`${naming.fileName}-query.ts`, `
|
|
783
|
+
import type { Handler } from '@domain-first/handlers'
|
|
801
784
|
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
785
|
+
export abstract class ${naming.ClassName}Query {
|
|
786
|
+
static inputSchema = {}
|
|
787
|
+
static outputSchema = {}
|
|
805
788
|
|
|
806
|
-
|
|
807
|
-
|
|
789
|
+
abstract handle: Handler<typeof ${naming.ClassName}Query.inputSchema, typeof ${naming.ClassName}Query.outputSchema>
|
|
790
|
+
}
|
|
808
791
|
`.trim());
|
|
809
792
|
else queriesFolder.createFile(`${naming.fileName}-query.ts`, `
|
|
810
|
-
|
|
793
|
+
export abstract class ${naming.ClassName}Query {
|
|
811
794
|
|
|
812
|
-
|
|
795
|
+
}`.trim());
|
|
813
796
|
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
|
|
814
797
|
const implementationNaming = new UnknownFormatNaming(implementationType);
|
|
815
798
|
const testImplementationNaming = new UnknownFormatNaming(testImplementationType);
|
|
816
799
|
boundedContextFolder.subitem([
|
|
817
800
|
'wiring',
|
|
818
|
-
'application',
|
|
819
801
|
'queries'
|
|
820
802
|
]).createFile(`wire-${naming.fileName}-query.ts`, `
|
|
821
|
-
|
|
822
|
-
|
|
803
|
+
import { wireClass } from '@domain-first/wire'
|
|
804
|
+
import { envBranchedWire } from '../../../../shared/wiring/env-branched-wire'
|
|
805
|
+
${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName, fileName })=>`import { ${ClassName}${naming.ClassName}Query } from '../../infrastructure/queries/${fileName}/${fileName}-${naming.fileName}-query'`).join('\n')}
|
|
823
806
|
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
}
|
|
807
|
+
${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName })=>`const wire${ClassName}Implementation = wireClass(${ClassName}${naming.ClassName}Query, [])`).join('\n\n')}
|
|
808
|
+
|
|
809
|
+
export const wire${naming.ClassName}Query = envBranchedWire({
|
|
810
|
+
test: wire${addTestImplementation ? testImplementationNaming.ClassName : implementationNaming.ClassName}Implementation,
|
|
811
|
+
development: wire${implementationNaming.ClassName}Implementation,
|
|
812
|
+
production: wire${implementationNaming.ClassName}Implementation
|
|
813
|
+
})
|
|
829
814
|
`.trim());
|
|
830
815
|
}
|
|
831
816
|
return;
|
|
832
817
|
}
|
|
833
|
-
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers')) queriesFolder.
|
|
818
|
+
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers')) queriesFolder.subitem([
|
|
819
|
+
'orchestration'
|
|
820
|
+
]).createFile(`${naming.fileName}-query.ts`, `
|
|
834
821
|
import { defineHandler } from '@domain-first/handlers'
|
|
835
822
|
|
|
836
823
|
export class ${naming.ClassName}Query {
|
|
@@ -846,7 +833,9 @@ export class ${naming.ClassName}Query {
|
|
|
846
833
|
})
|
|
847
834
|
}
|
|
848
835
|
`.trim());
|
|
849
|
-
else queriesFolder.
|
|
836
|
+
else queriesFolder.subitem([
|
|
837
|
+
'orchestration'
|
|
838
|
+
]).createFile(`${naming.fileName}-query.ts`, `
|
|
850
839
|
export class ${naming.ClassName}Query {
|
|
851
840
|
|
|
852
841
|
}`.trim());
|
|
@@ -856,7 +845,7 @@ export class ${naming.ClassName}Query {
|
|
|
856
845
|
'queries'
|
|
857
846
|
]).createFile(`wire-${naming.fileName}-query.ts`, `
|
|
858
847
|
import { wireClass } from '@domain-first/wire'
|
|
859
|
-
import { ${naming.ClassName}Query } from '../../../application/queries/${naming.fileName}-query'
|
|
848
|
+
import { ${naming.ClassName}Query } from '../../../application/queries/orchestration/${naming.fileName}-query'
|
|
860
849
|
|
|
861
850
|
export const wire${naming.ClassName}Query = wireClass(${naming.ClassName}Query, [])
|
|
862
851
|
`.trim());
|
|
@@ -894,11 +883,10 @@ export class ${naming.ClassName}UseCase {
|
|
|
894
883
|
`.trim());
|
|
895
884
|
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) boundedContextFolder.subitem([
|
|
896
885
|
'wiring',
|
|
897
|
-
'application',
|
|
898
886
|
'use-cases'
|
|
899
887
|
]).createFile(`wire-${naming.fileName}-use-case.ts`, `
|
|
900
888
|
import { wireClass } from '@domain-first/wire'
|
|
901
|
-
import { ${naming.ClassName}UseCase } from '
|
|
889
|
+
import { ${naming.ClassName}UseCase } from '../../application/use-cases/${naming.fileName}-use-case'
|
|
902
890
|
|
|
903
891
|
export const wire${naming.ClassName}UseCase = wireClass(
|
|
904
892
|
${naming.ClassName}UseCase,
|
package/dist/index.js
CHANGED
|
@@ -252,41 +252,26 @@ export class ${naming.ClassName}${aggregateNaming.ClassName}Repository implement
|
|
|
252
252
|
}
|
|
253
253
|
|
|
254
254
|
`.trim());
|
|
255
|
-
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
|
|
256
|
-
const wiringFolder = boundedContextFolder.subitem([
|
|
257
|
-
'wiring',
|
|
258
|
-
'infrastructure',
|
|
259
|
-
'repositories',
|
|
260
|
-
naming.fileName
|
|
261
|
-
]);
|
|
262
|
-
wiringFolder.createFile(`wire-${naming.fileName}-${aggregateNaming.fileName}-repository.ts`, `
|
|
263
|
-
import { wireClass } from '@domain-first/wire'
|
|
264
|
-
import { ${naming.ClassName}${aggregateNaming.ClassName}Repository } from '../../../../infrastructure/repositories/${naming.fileName}/${naming.fileName}-${aggregateNaming.fileName}-repository'
|
|
265
|
-
|
|
266
|
-
export const wire${naming.ClassName}${aggregateNaming.ClassName}Repository = wireClass(
|
|
267
|
-
${naming.ClassName}${aggregateNaming.ClassName}Repository,
|
|
268
|
-
[]
|
|
269
|
-
)
|
|
270
|
-
`.trim());
|
|
271
|
-
}
|
|
272
255
|
}
|
|
273
256
|
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
|
|
274
257
|
const implementationNaming = new UnknownFormatNaming(infrastructureImplementationType);
|
|
275
258
|
const testImplementationNaming = new UnknownFormatNaming(testImplementationType);
|
|
276
259
|
boundedContextFolder.subitem([
|
|
277
260
|
'wiring',
|
|
278
|
-
'domain',
|
|
279
261
|
'repositories'
|
|
280
262
|
]).createFile(`wire-${aggregateNaming.fileName}-repository.ts`, `
|
|
281
|
-
import {
|
|
282
|
-
|
|
263
|
+
import { wireClass } from '@domain-first/wire'
|
|
264
|
+
import { envBranchedWire } from '../../../../shared/wiring/env-branched-wire'
|
|
265
|
+
${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName, fileName })=>`import { ${ClassName}${aggregateNaming.ClassName}Repository } from '../../infrastructure/repositories/${fileName}/${fileName}-${aggregateNaming.fileName}-repository'`).join('\n')}
|
|
266
|
+
|
|
267
|
+
${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName })=>`const wire${ClassName}Implementation = wireClass(${ClassName}${aggregateNaming.ClassName}Repository, [])`).join('\n\n')}
|
|
283
268
|
|
|
284
269
|
export const wire${aggregateNaming.ClassName}Repository = envBranchedWire({
|
|
285
|
-
test: wire${addTestImplementation ? testImplementationNaming.ClassName : implementationNaming.ClassName}
|
|
286
|
-
development: wire${implementationNaming.ClassName}
|
|
287
|
-
production: wire${implementationNaming.ClassName}
|
|
270
|
+
test: wire${addTestImplementation ? testImplementationNaming.ClassName : implementationNaming.ClassName}Implementation,
|
|
271
|
+
development: wire${implementationNaming.ClassName}Implementation,
|
|
272
|
+
production: wire${implementationNaming.ClassName}Implementation
|
|
288
273
|
})
|
|
289
|
-
`.trim());
|
|
274
|
+
`.trim());
|
|
290
275
|
}
|
|
291
276
|
}
|
|
292
277
|
};
|
|
@@ -297,14 +282,8 @@ const scaffoldNewApplicationPort = async (boundedContextFolder)=>{
|
|
|
297
282
|
const naming = new UnknownFormatNaming(name);
|
|
298
283
|
const wiringFolder = boundedContextFolder.subitem([
|
|
299
284
|
'wiring',
|
|
300
|
-
'application',
|
|
301
285
|
'ports'
|
|
302
286
|
]);
|
|
303
|
-
const infraFolder = boundedContextFolder.subitem([
|
|
304
|
-
'wiring',
|
|
305
|
-
'infrastructure',
|
|
306
|
-
'application-ports'
|
|
307
|
-
]);
|
|
308
287
|
const applicationPortsFolder = boundedContextFolder.subitem([
|
|
309
288
|
'application',
|
|
310
289
|
'ports'
|
|
@@ -344,29 +323,24 @@ export class ${currentNaming.ClassName} extends ${naming.ClassName} {
|
|
|
344
323
|
|
|
345
324
|
}
|
|
346
325
|
`);
|
|
347
|
-
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) infraFolder.subitem([
|
|
348
|
-
implementation
|
|
349
|
-
]).createFile(`wire-${currentNaming.fileName}.ts`, `
|
|
350
|
-
import { wireClass } from '@domain-first/wire'
|
|
351
|
-
import { ${currentNaming.ClassName} } from '../../../../infrastructure/application-adapters/${implementation}/${currentNaming.fileName}'
|
|
352
|
-
|
|
353
|
-
export const wire${currentNaming.ClassName} = wireClass(
|
|
354
|
-
${currentNaming.ClassName},
|
|
355
|
-
[]
|
|
356
|
-
)
|
|
357
|
-
`.trim());
|
|
358
326
|
}
|
|
359
327
|
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) wiringFolder.createFile(`wire-${naming.fileName}.ts`, `
|
|
360
|
-
import {
|
|
328
|
+
import { wireClass } from '@domain-first/wire'
|
|
329
|
+
import { envBranchedWire } from '../../../${'shared' === boundedContextFolder.name ? '' : '../'}shared/wiring/env-branched-wire'
|
|
361
330
|
${implementationTypes.map((x)=>({
|
|
362
331
|
naming: new UnknownFormatNaming(`${x}-${naming.fileName}`),
|
|
363
332
|
implementation: x
|
|
364
|
-
})).map(({ naming: { ClassName, fileName }, implementation })=>`import {
|
|
333
|
+
})).map(({ naming: { ClassName, fileName }, implementation })=>`import { ${ClassName} } from '../../infrastructure/application-adapters/${implementation}/${fileName}'`).join('\n')}
|
|
334
|
+
|
|
335
|
+
${implementationTypes.map((x)=>({
|
|
336
|
+
naming: new UnknownFormatNaming(`${x}-${naming.fileName}`),
|
|
337
|
+
implementation: x
|
|
338
|
+
})).map(({ naming: { ClassName }, implementation })=>`const wire${new UnknownFormatNaming(implementation).ClassName}Implementation = wireClass(${ClassName}, [])`).join('\n\n')}
|
|
365
339
|
|
|
366
340
|
export const wire${naming.ClassName} = envBranchedWire({
|
|
367
|
-
test: wire${new UnknownFormatNaming(`${implementationTypes.at(-1)}
|
|
368
|
-
development: wire${new UnknownFormatNaming(`${implementationTypes.at(0)}
|
|
369
|
-
production: wire${new UnknownFormatNaming(`${implementationTypes.at(0)}
|
|
341
|
+
test: wire${new UnknownFormatNaming(`${implementationTypes.at(-1)}-implementation`).ClassName},
|
|
342
|
+
development: wire${new UnknownFormatNaming(`${implementationTypes.at(0)}-implementation`).ClassName},
|
|
343
|
+
production: wire${new UnknownFormatNaming(`${implementationTypes.at(0)}-implementation`).ClassName}
|
|
370
344
|
})
|
|
371
345
|
|
|
372
346
|
`.trim());
|
|
@@ -406,9 +380,14 @@ const scaffoldNewCommand = async (boundedContextFolder)=>{
|
|
|
406
380
|
message: 'Name: '
|
|
407
381
|
});
|
|
408
382
|
const naming = new UnknownFormatNaming(commandName);
|
|
409
|
-
const
|
|
410
|
-
|
|
383
|
+
const commandType = await prompts_select({
|
|
384
|
+
choices: [
|
|
385
|
+
'Execution (with infrastructure implementation)',
|
|
386
|
+
'Orchestrator (no infrastructure implementation)'
|
|
387
|
+
],
|
|
388
|
+
message: 'Command type'
|
|
411
389
|
});
|
|
390
|
+
const isOrchestrator = 'Orchestrator (no infrastructure implementation)' === commandType;
|
|
412
391
|
if (!isOrchestrator) {
|
|
413
392
|
const implementationType = await input({
|
|
414
393
|
message: 'Command infrastructure implementation type:',
|
|
@@ -432,81 +411,73 @@ const scaffoldNewCommand = async (boundedContextFolder)=>{
|
|
|
432
411
|
infrastructureFolder.subitem([
|
|
433
412
|
formatNaming.fileName
|
|
434
413
|
]).createFile(`${formatNaming.fileName}-${naming.fileName}-command.ts`, ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers') ? `
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
export class ${formatNaming.ClassName}${naming.ClassName}Command implements ${naming.ClassName}Command {
|
|
439
|
-
constructor() {}
|
|
414
|
+
import { defineHandler } from '@domain-first/handlers'
|
|
415
|
+
import { ${naming.ClassName}Command } from '../../../application/commands/execution/${naming.fileName}-command'
|
|
440
416
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
handler: async (input) => {
|
|
445
|
-
return {}
|
|
446
|
-
}
|
|
447
|
-
})
|
|
417
|
+
export class ${formatNaming.ClassName}${naming.ClassName}Command extends ${naming.ClassName}Command {
|
|
418
|
+
constructor() {
|
|
419
|
+
super()
|
|
448
420
|
}
|
|
449
|
-
`.trim() : `
|
|
450
|
-
import { ${naming.ClassName}Command } from '../../../domain/commands/${naming.fileName}-command'
|
|
451
421
|
|
|
452
|
-
|
|
422
|
+
handle = defineHandler({
|
|
423
|
+
inputSchema: ${naming.ClassName}Command.inputSchema,
|
|
424
|
+
outputSchema: ${naming.ClassName}Command.outputSchema,
|
|
425
|
+
handler: async (input) => {
|
|
426
|
+
return {}
|
|
427
|
+
}
|
|
428
|
+
})
|
|
429
|
+
}
|
|
430
|
+
`.trim() : `
|
|
431
|
+
import { ${naming.ClassName}Command } from '../../../domain/commands/${naming.fileName}-command'
|
|
453
432
|
|
|
433
|
+
export class ${formatNaming.ClassName}${naming.ClassName}Command extends ${naming.ClassName}Command {
|
|
434
|
+
constructor() {
|
|
435
|
+
super()
|
|
454
436
|
}
|
|
437
|
+
}
|
|
455
438
|
`.trim());
|
|
456
|
-
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
|
|
457
|
-
const wiringFolder = boundedContextFolder.subitem([
|
|
458
|
-
'wiring',
|
|
459
|
-
'infrastructure',
|
|
460
|
-
'commands',
|
|
461
|
-
formatNaming.fileName
|
|
462
|
-
]);
|
|
463
|
-
wiringFolder.createFile(`wire-${formatNaming.fileName}-${naming.fileName}-command.ts`, `
|
|
464
|
-
import { wireClass } from '@domain-first/wire'
|
|
465
|
-
import { ${formatNaming.ClassName}${naming.ClassName}Command } from '../../../../infrastructure/commands/${formatNaming.fileName}/${formatNaming.fileName}-${naming.fileName}-command'
|
|
466
|
-
|
|
467
|
-
export const wire${formatNaming.ClassName}${naming.ClassName}Command = wireClass(
|
|
468
|
-
${formatNaming.ClassName}${naming.ClassName}Command,
|
|
469
|
-
[]
|
|
470
|
-
)
|
|
471
|
-
|
|
472
|
-
`.trim());
|
|
473
|
-
}
|
|
474
439
|
}
|
|
475
|
-
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers')) commandsFolder.
|
|
476
|
-
|
|
440
|
+
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers')) commandsFolder.subitem([
|
|
441
|
+
'execution'
|
|
442
|
+
]).createFile(`${naming.fileName}-command.ts`, `
|
|
443
|
+
import type { Handler } from '@domain-first/handlers'
|
|
477
444
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
445
|
+
export abstract class ${naming.ClassName}Command {
|
|
446
|
+
static inputSchema = {}
|
|
447
|
+
static outputSchema = {}
|
|
481
448
|
|
|
482
|
-
|
|
483
|
-
|
|
449
|
+
abstract handle: Handler<typeof ${naming.ClassName}Command.inputSchema, typeof ${naming.ClassName}Command.outputSchema>
|
|
450
|
+
}
|
|
484
451
|
`.trim());
|
|
485
452
|
else commandsFolder.createFile(`${naming.fileName}-command.ts`, `
|
|
486
|
-
|
|
453
|
+
export abstract class ${naming.ClassName}Command {
|
|
487
454
|
|
|
488
|
-
|
|
455
|
+
}`.trim());
|
|
489
456
|
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
|
|
490
457
|
const implementationNaming = new UnknownFormatNaming(implementationType);
|
|
491
458
|
const testImplementationNaming = new UnknownFormatNaming(testImplementationType);
|
|
492
459
|
boundedContextFolder.subitem([
|
|
493
460
|
'wiring',
|
|
494
|
-
'application',
|
|
495
461
|
'commands'
|
|
496
462
|
]).createFile(`wire-${naming.fileName}-command.ts`, `
|
|
497
|
-
|
|
498
|
-
|
|
463
|
+
import { wireClass } from '@domain-first/wire'
|
|
464
|
+
import { envBranchedWire } from '../../../../shared/wiring/env-branched-wire'
|
|
465
|
+
${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName, fileName })=>`import { ${ClassName}${naming.ClassName}Command } from '../../infrastructure/commands/${fileName}/${fileName}-${naming.fileName}-command'`).join('\n')}
|
|
499
466
|
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
}
|
|
467
|
+
${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName })=>`const wire${ClassName}Implementation = wireClass(${ClassName}${naming.ClassName}Command, [])`).join('\n\n')}
|
|
468
|
+
|
|
469
|
+
export const wire${naming.ClassName}Command = envBranchedWire({
|
|
470
|
+
test: wire${addTestImplementation ? testImplementationNaming.ClassName : implementationNaming.ClassName}Implementation,
|
|
471
|
+
development: wire${implementationNaming.ClassName}Implementation,
|
|
472
|
+
production: wire${implementationNaming.ClassName}Implementation
|
|
473
|
+
})
|
|
505
474
|
`.trim());
|
|
506
475
|
}
|
|
507
476
|
return;
|
|
508
477
|
}
|
|
509
|
-
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers')) commandsFolder.
|
|
478
|
+
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers')) commandsFolder.subitem([
|
|
479
|
+
'orchestration'
|
|
480
|
+
]).createFile(`${naming.fileName}-command.ts`, `
|
|
510
481
|
import { defineHandler } from '@domain-first/handlers'
|
|
511
482
|
|
|
512
483
|
export class ${naming.ClassName}Command {
|
|
@@ -522,7 +493,9 @@ export class ${naming.ClassName}Command {
|
|
|
522
493
|
})
|
|
523
494
|
}
|
|
524
495
|
`.trim());
|
|
525
|
-
else commandsFolder.
|
|
496
|
+
else commandsFolder.subitem([
|
|
497
|
+
'orchestration'
|
|
498
|
+
]).createFile(`${naming.fileName}-command.ts`, `
|
|
526
499
|
export class ${naming.ClassName}Command {
|
|
527
500
|
|
|
528
501
|
}`.trim());
|
|
@@ -532,7 +505,7 @@ export class ${naming.ClassName}Command {
|
|
|
532
505
|
'commands'
|
|
533
506
|
]).createFile(`wire-${naming.fileName}-command.ts`, `
|
|
534
507
|
import { wireClass } from '@domain-first/wire'
|
|
535
|
-
import { ${naming.ClassName}Command } from '../../../application/commands/${naming.fileName}-command'
|
|
508
|
+
import { ${naming.ClassName}Command } from '../../../application/commands/orchestration/${naming.fileName}-command'
|
|
536
509
|
|
|
537
510
|
export const wire${naming.ClassName}Command = wireClass(${naming.ClassName}Command, [])
|
|
538
511
|
`.trim());
|
|
@@ -584,7 +557,7 @@ const scaffoldNewErrorUseCase = async (boundedContextFolder)=>{
|
|
|
584
557
|
message: 'Error name:'
|
|
585
558
|
});
|
|
586
559
|
const naming = new UnknownFormatNaming(errorName);
|
|
587
|
-
currentErrorFolder.file('index.ts').addLine(`export const ${naming.ClassName}Error = ${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Errors.define('${naming.fileName}')`, '\n\n');
|
|
560
|
+
currentErrorFolder.file('index.ts').addLine(`export const ${naming.ClassName}${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Error = ${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Errors.define('${naming.fileName}')`, '\n\n');
|
|
588
561
|
return;
|
|
589
562
|
}
|
|
590
563
|
if ('New namespace' === selectedVariant) {
|
|
@@ -595,17 +568,18 @@ const scaffoldNewErrorUseCase = async (boundedContextFolder)=>{
|
|
|
595
568
|
currentErrorFolder.createFile(`${fileName}.ts`, `
|
|
596
569
|
import { errorNamespace } from '@domain-first/errors'
|
|
597
570
|
|
|
598
|
-
const ${ClassName}Errors = errorNamespace('${boundedContextFolder.name}').subnamespace('${fileName}')
|
|
571
|
+
export const ${ClassName}${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Errors = errorNamespace('${boundedContextFolder.name}').subnamespace('${fileName}')
|
|
599
572
|
`);
|
|
600
|
-
currentErrorFolder.file('index.ts').addLine(`export * from './${fileName}'
|
|
573
|
+
currentErrorFolder.file('index.ts').addLine(`export * from './${fileName}'`, '\n\n');
|
|
601
574
|
return;
|
|
602
575
|
}
|
|
603
576
|
const namespace = selectedVariant.substring(23);
|
|
577
|
+
const namespaceNaming = new UnknownFormatNaming(namespace);
|
|
604
578
|
const errorName = await input({
|
|
605
579
|
message: 'Error name:'
|
|
606
580
|
});
|
|
607
581
|
const { ClassName, fileName } = new UnknownFormatNaming(errorName);
|
|
608
|
-
currentErrorFolder.file(`${namespace}.ts`).addLine(`export const ${ClassName}Error = ${new UnknownFormatNaming(
|
|
582
|
+
currentErrorFolder.file(`${namespace}.ts`).addLine(`export const ${ClassName}${namespaceNaming.ClassName}${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Error = ${namespaceNaming.ClassName}${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Errors.define('${fileName}')`, '\n\n');
|
|
609
583
|
};
|
|
610
584
|
const scaffoldNewHandlersRestEndpoint = async (boundedContextFolder)=>{
|
|
611
585
|
const restPresentationFolder = boundedContextFolder.subitem([
|
|
@@ -624,11 +598,27 @@ const scaffoldNewHandlersRestEndpoint = async (boundedContextFolder)=>{
|
|
|
624
598
|
controller = await input({
|
|
625
599
|
message: 'Name: '
|
|
626
600
|
});
|
|
627
|
-
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire'))
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
601
|
+
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
|
|
602
|
+
boundedContextFolder.subitem([
|
|
603
|
+
'wiring',
|
|
604
|
+
'presentation',
|
|
605
|
+
'rest'
|
|
606
|
+
]).file('index.ts').addLine(`export * from './${controller}'`);
|
|
607
|
+
const sharedRestFolder = boundedContextFolder.subitem([
|
|
608
|
+
'..',
|
|
609
|
+
'..',
|
|
610
|
+
'presentation',
|
|
611
|
+
'rest'
|
|
612
|
+
]);
|
|
613
|
+
sharedRestFolder.file('wires.ts').addLine(`export * from '../../bounded-contexts/${boundedContextFolder.name}/wiring/presentation/rest/${controller}'`);
|
|
614
|
+
if (!sharedRestFolder.file('index.ts').exists) sharedRestFolder.createFile('index.ts', `
|
|
615
|
+
import * as wires from './wires'
|
|
616
|
+
|
|
617
|
+
const restWires = Object.values(wires)
|
|
618
|
+
|
|
619
|
+
export const restHandlers = restWires.map(x => x().handle)
|
|
620
|
+
`.trim());
|
|
621
|
+
}
|
|
632
622
|
}
|
|
633
623
|
const method = await prompts_select({
|
|
634
624
|
message: 'Method:',
|
|
@@ -646,25 +636,24 @@ const scaffoldNewHandlersRestEndpoint = async (boundedContextFolder)=>{
|
|
|
646
636
|
const controllerFolder = restPresentationFolder.subitem([
|
|
647
637
|
controller
|
|
648
638
|
]);
|
|
639
|
+
const endpointFolder = controllerFolder.subitem(path);
|
|
649
640
|
const nameBase = `${controller}-${path.length ? `${path.join('-')}-` : ''}${method}-endpoint`;
|
|
650
641
|
const endpointNaming = new UnknownFormatNaming(nameBase);
|
|
651
|
-
|
|
642
|
+
endpointFolder.createFile(`${method.toUpperCase()}.ts`, `
|
|
652
643
|
import { EndpointGenerator } from '@domain-first/handlers-rest'
|
|
653
644
|
|
|
654
645
|
export class ${endpointNaming.ClassName} {
|
|
655
|
-
constructor(
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
}
|
|
646
|
+
constructor(
|
|
647
|
+
private readonly endpointGenerator: EndpointGenerator,
|
|
648
|
+
private readonly handler: never
|
|
649
|
+
) {}
|
|
660
650
|
|
|
661
651
|
get handle() {
|
|
662
|
-
return this.endpointGenerator(this.
|
|
652
|
+
return this.endpointGenerator(this.handler.handle, {
|
|
663
653
|
route: { method: '${method}', path: ['${boundedContextFolder.name}', '${controller}'${path.length ? `, ${path.map((x)=>`'${x}'`).join(', ')}` : ''}] },
|
|
664
654
|
tags: ['${boundedContextFolder.name}: ${controller}'],
|
|
665
655
|
})
|
|
666
656
|
}
|
|
667
|
-
|
|
668
657
|
}
|
|
669
658
|
`.trim());
|
|
670
659
|
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
|
|
@@ -678,7 +667,7 @@ export class ${endpointNaming.ClassName} {
|
|
|
678
667
|
const wireNaming = new UnknownFormatNaming(wireNameBase);
|
|
679
668
|
wiringFolder.createFile(`${wireNaming.fileName}.ts`, `
|
|
680
669
|
import { wireClass } from '@domain-first/wire'
|
|
681
|
-
import { ${endpointNaming.ClassName} } from '../../../../presentation/rest/${controller}/${
|
|
670
|
+
import { ${endpointNaming.ClassName} } from '../../../../presentation/rest/${controller}/${path.length ? `${path.join('/')}/` : ''}${method.toUpperCase()}'
|
|
682
671
|
|
|
683
672
|
export const wire${endpointNaming.ClassName} = wireClass(
|
|
684
673
|
${endpointNaming.ClassName},
|
|
@@ -701,9 +690,14 @@ const scaffoldNewQuery = async (boundedContextFolder)=>{
|
|
|
701
690
|
message: 'Name: '
|
|
702
691
|
});
|
|
703
692
|
const naming = new UnknownFormatNaming(queryName);
|
|
704
|
-
const
|
|
705
|
-
|
|
693
|
+
const queryType = await prompts_select({
|
|
694
|
+
choices: [
|
|
695
|
+
'Execution (with infrastructure implementation)',
|
|
696
|
+
'Orchestrator (no infrastructure implementation)'
|
|
697
|
+
],
|
|
698
|
+
message: 'Query type'
|
|
706
699
|
});
|
|
700
|
+
const isOrchestrator = 'Orchestrator (no infrastructure implementation)' === queryType;
|
|
707
701
|
if (!isOrchestrator) {
|
|
708
702
|
const implementationType = await input({
|
|
709
703
|
message: 'Query infrastructure implementation type:',
|
|
@@ -727,80 +721,73 @@ const scaffoldNewQuery = async (boundedContextFolder)=>{
|
|
|
727
721
|
infrastructureFolder.subitem([
|
|
728
722
|
formatNaming.fileName
|
|
729
723
|
]).createFile(`${formatNaming.fileName}-${naming.fileName}-query.ts`, ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers') ? `
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
export class ${formatNaming.ClassName}${naming.ClassName}Query implements ${naming.ClassName}Query {
|
|
734
|
-
constructor() {}
|
|
724
|
+
import { defineHandler } from '@domain-first/handlers'
|
|
725
|
+
import { ${naming.ClassName}Query } from '../../../application/queries/execution/${naming.fileName}-query'
|
|
735
726
|
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
handler: async (input) => {
|
|
740
|
-
return {}
|
|
741
|
-
}
|
|
742
|
-
})
|
|
727
|
+
export class ${formatNaming.ClassName}${naming.ClassName}Query extends ${naming.ClassName}Query {
|
|
728
|
+
constructor() {
|
|
729
|
+
super()
|
|
743
730
|
}
|
|
744
|
-
`.trim() : `
|
|
745
|
-
import { ${naming.ClassName}Query } from '../../../domain/queries/${naming.fileName}-query'
|
|
746
731
|
|
|
747
|
-
|
|
732
|
+
handle = defineHandler({
|
|
733
|
+
inputSchema: ${naming.ClassName}Query.inputSchema,
|
|
734
|
+
outputSchema: ${naming.ClassName}Query.outputSchema,
|
|
735
|
+
handler: async (input) => {
|
|
736
|
+
return {}
|
|
737
|
+
}
|
|
738
|
+
})
|
|
739
|
+
}
|
|
740
|
+
`.trim() : `
|
|
741
|
+
import { ${naming.ClassName}Query } from '../../../domain/queries/${naming.fileName}-query'
|
|
748
742
|
|
|
743
|
+
export class ${formatNaming.ClassName}${naming.ClassName}Query extends ${naming.ClassName}Query {
|
|
744
|
+
constructor() {
|
|
745
|
+
super()
|
|
749
746
|
}
|
|
747
|
+
}
|
|
750
748
|
`.trim());
|
|
751
|
-
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
|
|
752
|
-
const wiringFolder = boundedContextFolder.subitem([
|
|
753
|
-
'wiring',
|
|
754
|
-
'infrastructure',
|
|
755
|
-
'queries',
|
|
756
|
-
formatNaming.fileName
|
|
757
|
-
]);
|
|
758
|
-
wiringFolder.createFile(`wire-${formatNaming.fileName}-${naming.fileName}-query.ts`, `
|
|
759
|
-
import { wireClass } from '@domain-first/wire'
|
|
760
|
-
import { ${formatNaming.ClassName}${naming.ClassName}Query } from '../../../../infrastructure/queries/${formatNaming.fileName}/${formatNaming.fileName}-${naming.fileName}-query'
|
|
761
|
-
|
|
762
|
-
export const wire${formatNaming.ClassName}${naming.ClassName}Query = wireClass(
|
|
763
|
-
${formatNaming.ClassName}${naming.ClassName}Query,
|
|
764
|
-
[]
|
|
765
|
-
)
|
|
766
|
-
`.trim());
|
|
767
|
-
}
|
|
768
749
|
}
|
|
769
|
-
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers')) queriesFolder.
|
|
770
|
-
|
|
750
|
+
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers')) queriesFolder.subitem([
|
|
751
|
+
'execution'
|
|
752
|
+
]).createFile(`${naming.fileName}-query.ts`, `
|
|
753
|
+
import type { Handler } from '@domain-first/handlers'
|
|
771
754
|
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
755
|
+
export abstract class ${naming.ClassName}Query {
|
|
756
|
+
static inputSchema = {}
|
|
757
|
+
static outputSchema = {}
|
|
775
758
|
|
|
776
|
-
|
|
777
|
-
|
|
759
|
+
abstract handle: Handler<typeof ${naming.ClassName}Query.inputSchema, typeof ${naming.ClassName}Query.outputSchema>
|
|
760
|
+
}
|
|
778
761
|
`.trim());
|
|
779
762
|
else queriesFolder.createFile(`${naming.fileName}-query.ts`, `
|
|
780
|
-
|
|
763
|
+
export abstract class ${naming.ClassName}Query {
|
|
781
764
|
|
|
782
|
-
|
|
765
|
+
}`.trim());
|
|
783
766
|
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
|
|
784
767
|
const implementationNaming = new UnknownFormatNaming(implementationType);
|
|
785
768
|
const testImplementationNaming = new UnknownFormatNaming(testImplementationType);
|
|
786
769
|
boundedContextFolder.subitem([
|
|
787
770
|
'wiring',
|
|
788
|
-
'application',
|
|
789
771
|
'queries'
|
|
790
772
|
]).createFile(`wire-${naming.fileName}-query.ts`, `
|
|
791
|
-
|
|
792
|
-
|
|
773
|
+
import { wireClass } from '@domain-first/wire'
|
|
774
|
+
import { envBranchedWire } from '../../../../shared/wiring/env-branched-wire'
|
|
775
|
+
${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName, fileName })=>`import { ${ClassName}${naming.ClassName}Query } from '../../infrastructure/queries/${fileName}/${fileName}-${naming.fileName}-query'`).join('\n')}
|
|
793
776
|
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
}
|
|
777
|
+
${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName })=>`const wire${ClassName}Implementation = wireClass(${ClassName}${naming.ClassName}Query, [])`).join('\n\n')}
|
|
778
|
+
|
|
779
|
+
export const wire${naming.ClassName}Query = envBranchedWire({
|
|
780
|
+
test: wire${addTestImplementation ? testImplementationNaming.ClassName : implementationNaming.ClassName}Implementation,
|
|
781
|
+
development: wire${implementationNaming.ClassName}Implementation,
|
|
782
|
+
production: wire${implementationNaming.ClassName}Implementation
|
|
783
|
+
})
|
|
799
784
|
`.trim());
|
|
800
785
|
}
|
|
801
786
|
return;
|
|
802
787
|
}
|
|
803
|
-
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers')) queriesFolder.
|
|
788
|
+
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers')) queriesFolder.subitem([
|
|
789
|
+
'orchestration'
|
|
790
|
+
]).createFile(`${naming.fileName}-query.ts`, `
|
|
804
791
|
import { defineHandler } from '@domain-first/handlers'
|
|
805
792
|
|
|
806
793
|
export class ${naming.ClassName}Query {
|
|
@@ -816,7 +803,9 @@ export class ${naming.ClassName}Query {
|
|
|
816
803
|
})
|
|
817
804
|
}
|
|
818
805
|
`.trim());
|
|
819
|
-
else queriesFolder.
|
|
806
|
+
else queriesFolder.subitem([
|
|
807
|
+
'orchestration'
|
|
808
|
+
]).createFile(`${naming.fileName}-query.ts`, `
|
|
820
809
|
export class ${naming.ClassName}Query {
|
|
821
810
|
|
|
822
811
|
}`.trim());
|
|
@@ -826,7 +815,7 @@ export class ${naming.ClassName}Query {
|
|
|
826
815
|
'queries'
|
|
827
816
|
]).createFile(`wire-${naming.fileName}-query.ts`, `
|
|
828
817
|
import { wireClass } from '@domain-first/wire'
|
|
829
|
-
import { ${naming.ClassName}Query } from '../../../application/queries/${naming.fileName}-query'
|
|
818
|
+
import { ${naming.ClassName}Query } from '../../../application/queries/orchestration/${naming.fileName}-query'
|
|
830
819
|
|
|
831
820
|
export const wire${naming.ClassName}Query = wireClass(${naming.ClassName}Query, [])
|
|
832
821
|
`.trim());
|
|
@@ -864,11 +853,10 @@ export class ${naming.ClassName}UseCase {
|
|
|
864
853
|
`.trim());
|
|
865
854
|
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) boundedContextFolder.subitem([
|
|
866
855
|
'wiring',
|
|
867
|
-
'application',
|
|
868
856
|
'use-cases'
|
|
869
857
|
]).createFile(`wire-${naming.fileName}-use-case.ts`, `
|
|
870
858
|
import { wireClass } from '@domain-first/wire'
|
|
871
|
-
import { ${naming.ClassName}UseCase } from '
|
|
859
|
+
import { ${naming.ClassName}UseCase } from '../../application/use-cases/${naming.fileName}-use-case'
|
|
872
860
|
|
|
873
861
|
export const wire${naming.ClassName}UseCase = wireClass(
|
|
874
862
|
${naming.ClassName}UseCase,
|