@ddd-tool/domain-designer-generator 0.0.0-alpha.0 → 0.0.0-alpha.10

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/README.md CHANGED
@@ -0,0 +1,3 @@
1
+ # domain-designer-generator
2
+
3
+ 代码生成器
@@ -1,4 +1,4 @@
1
- import { DomainDesigner, DomainDesignInfo, DomainDesignInfoType, DomainDesignObject, DomainDesignReadModel, type DomainDesignAgg, type DomainDesignCommand, type DomainDesignEvent, type DomainDesignFacadeCommand, type DomainDesignInfoRecord } from '@ddd-tool/domain-designer-core';
1
+ import { DomainDesignInfo, DomainDesignInfoType, DomainDesignReadModel, type DomainDesignAgg, type DomainDesignCommand, type DomainDesignEvent, type DomainDesignFacadeCommand, type DomainDesignInfoRecord } from '@ddd-tool/domain-designer-core';
2
2
  export type DomainNode = DomainDesignCommand<DomainDesignInfoRecord> | DomainDesignFacadeCommand<DomainDesignInfoRecord> | DomainDesignAgg<DomainDesignInfoRecord> | DomainDesignEvent<DomainDesignInfoRecord> | DomainDesignReadModel<DomainDesignInfoRecord>;
3
3
  export declare function isStruct(o: object): o is DomainNode;
4
4
  export declare enum Language {
@@ -7,52 +7,81 @@ export declare enum Language {
7
7
  CSharp = "csharp",
8
8
  Go = "go"
9
9
  }
10
- export interface CodeFile {
11
- imports: Set<string>;
12
- dir: string;
13
- name: string;
14
- ext: string;
15
- content: string;
10
+ export declare class CodeFile {
11
+ private readonly imports;
12
+ private parentDir;
13
+ private name;
14
+ private content;
15
+ constructor(parentDir: string[], name: string);
16
+ addImport(imp: string): void;
17
+ addImports(imports: string[] | Set<string>): void;
18
+ getImports(): string[];
19
+ appendContent(content: string): void;
20
+ appendContentln(content: string): void;
21
+ getContent(): string;
22
+ getName(): string;
23
+ setName(name: string): void;
24
+ getParentDir(): string[];
25
+ setParentDir(parentDir: string[]): void;
16
26
  }
17
- export interface CodeSnippets {
27
+ export interface CodeSnippets<TYPE extends 'Info' | 'Agg' | 'AggImpl' | 'Command' | 'CommandHandler' | 'Event' | 'FacadeCommand' | 'ReadMode'> {
28
+ type: TYPE;
18
29
  imports: Set<string>;
19
30
  content: string;
20
31
  }
21
- export declare enum JavaGeneratorAddition {
22
- Lombok = "Lombok",
23
- LombokBuilder = "LombokBuilder",
24
- RecordVakueObject = "RecordVakueObject",
25
- CommandHandler = "CommandHandler",
26
- Jpa = "Jpa",
27
- Timezone = "Timezone"
28
- }
29
- export declare enum KotlinGeneratorAddition {
30
- }
31
- export declare enum CSharpGeneratorAddition {
32
- }
33
- export declare enum GoGeneratorAddition {
34
- }
35
- export type GeneratorAddition<LANG extends Language> = LANG extends 'java' ? JavaGeneratorAddition : LANG extends 'kotlin' ? KotlinGeneratorAddition : LANG extends 'csharp' ? CSharpGeneratorAddition : LANG extends 'go' ? GoGeneratorAddition : never;
36
- export declare abstract class GeneratorTemplate<LANG extends Language, ADDI = GeneratorAddition<LANG>> {
37
- protected readonly designer: DomainDesigner;
38
- protected namespace: string;
39
- protected moduleName: string;
40
- protected additions: Set<ADDI>;
41
- protected codeFiles: Record<string, CodeFile>;
42
- constructor(init: {
43
- designer: DomainDesigner;
44
- namespace: string;
45
- moduleName: string;
46
- additions: ADDI[];
47
- });
48
- getDomainObjectName(obj: DomainDesignObject): string;
49
- abstract inferType(imports: Set<string>, obj: DomainDesignObject): string;
50
- abstract getFileName(struct: DomainDesignObject): string;
51
- abstract getCommandCode(cmd: DomainDesignCommand<DomainDesignInfoRecord>): CodeSnippets;
52
- abstract getFacadeCommandCode(cmd: DomainDesignFacadeCommand<DomainDesignInfoRecord>): CodeSnippets;
53
- abstract getAggCode(agg: DomainDesignAgg<DomainDesignInfoRecord>): CodeSnippets;
54
- abstract getEventCode(event: DomainDesignEvent<DomainDesignInfoRecord>): CodeSnippets;
55
- abstract getInfoCode(info: DomainDesignInfo<DomainDesignInfoType, string>): CodeSnippets;
56
- abstract getReadModelCode(readModel: DomainDesignReadModel<DomainDesignInfoRecord>): CodeSnippets;
57
- abstract generate(): CodeFile[];
32
+ export declare namespace java {
33
+ enum JavaGeneratorAddition {
34
+ Lombok = "Lombok",
35
+ LombokBuilder = "LombokBuilder",
36
+ RecordVakueObject = "RecordVakueObject",
37
+ CommandHandler = "CommandHandler",
38
+ Jpa = "Jpa",
39
+ Timezone = "Timezone",
40
+ SpringFramework = "SpringFramework"
41
+ }
42
+ interface JavaContext extends GeneratorContext<Language.Java> {
43
+ nonNullAnnotation: string;
44
+ nullableAnnotation: string;
45
+ }
46
+ }
47
+ export declare namespace kotlin {
48
+ enum KotlinGeneratorAddition {
49
+ ValueClass = "ValueClass",
50
+ CommandHandler = "CommandHandler",
51
+ Timezone = "Timezone"
52
+ }
53
+ interface KotlinContext extends GeneratorContext<Language.Kotlin> {
54
+ }
55
+ }
56
+ export declare namespace csharp {
57
+ enum CSharpGeneratorAddition {
58
+ Timezone = "Timezone",
59
+ RecordStruct = "RecordStruct",
60
+ PrimaryConstructor = "PrimaryConstructor",
61
+ CommandHandlerInterface = "CommandHandlerInterface",
62
+ AggInterface = "AggInterface"
63
+ }
64
+ interface CSharpContext extends GeneratorContext<Language.CSharp> {
65
+ commandHandlerInterface?: string;
66
+ aggInterface?: string;
67
+ }
68
+ }
69
+ export declare namespace go {
70
+ enum GoGeneratorAddition {
71
+ SinglePackageEachDesigner = "SinglePackageEachDesigner"
72
+ }
73
+ interface GoContext extends GeneratorContext<Language.Go> {
74
+ }
75
+ }
76
+ export type GeneratorAddition<LANG extends Language> = LANG extends 'java' ? java.JavaGeneratorAddition : LANG extends 'kotlin' ? kotlin.KotlinGeneratorAddition : LANG extends 'csharp' ? csharp.CSharpGeneratorAddition : LANG extends 'go' ? go.GoGeneratorAddition : never;
77
+ export interface GeneratorContext<LANG extends Language> {
78
+ namespace: string;
79
+ moduleName: string;
80
+ additions: Set<GeneratorAddition<LANG>>;
58
81
  }
82
+ export type InfoCodeProvider = (info: DomainDesignInfo<DomainDesignInfoType, string>) => CodeSnippets<'Info'>[];
83
+ export type CommandCodeProvider = (cmd: DomainDesignCommand<DomainDesignInfoRecord>) => CodeSnippets<'Command' | 'CommandHandler'>[];
84
+ export type FacadeCommandCodeProvider = (cmd: DomainDesignFacadeCommand<DomainDesignInfoRecord>) => CodeSnippets<'FacadeCommand'>[];
85
+ export type AggCodeProvider = (agg: DomainDesignAgg<DomainDesignInfoRecord>) => CodeSnippets<'Agg' | 'AggImpl'>[];
86
+ export type EventCodeProvider = (event: DomainDesignEvent<DomainDesignInfoRecord>) => CodeSnippets<'Event'>[];
87
+ export type ReadModelCodeProvider = (readModel: DomainDesignReadModel<DomainDesignInfoRecord>) => CodeSnippets<'ReadMode'>[];