@auto-engineer/server-generator-nestjs 0.11.16
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/.turbo/turbo-build.log +5 -0
- package/LICENSE +10 -0
- package/README.md +290 -0
- package/dist/src/codegen/entity-consolidation.d.ts +19 -0
- package/dist/src/codegen/entity-consolidation.d.ts.map +1 -0
- package/dist/src/codegen/entity-consolidation.js +134 -0
- package/dist/src/codegen/entity-consolidation.js.map +1 -0
- package/dist/src/codegen/extract/commands.d.ts +25 -0
- package/dist/src/codegen/extract/commands.d.ts.map +1 -0
- package/dist/src/codegen/extract/commands.js +67 -0
- package/dist/src/codegen/extract/commands.js.map +1 -0
- package/dist/src/codegen/extract/data-sink.d.ts +6 -0
- package/dist/src/codegen/extract/data-sink.d.ts.map +1 -0
- package/dist/src/codegen/extract/data-sink.js +78 -0
- package/dist/src/codegen/extract/data-sink.js.map +1 -0
- package/dist/src/codegen/extract/events.d.ts +10 -0
- package/dist/src/codegen/extract/events.d.ts.map +1 -0
- package/dist/src/codegen/extract/events.js +42 -0
- package/dist/src/codegen/extract/events.js.map +1 -0
- package/dist/src/codegen/extract/fields.d.ts +3 -0
- package/dist/src/codegen/extract/fields.d.ts.map +1 -0
- package/dist/src/codegen/extract/fields.js +9 -0
- package/dist/src/codegen/extract/fields.js.map +1 -0
- package/dist/src/codegen/extract/graphql.d.ts +14 -0
- package/dist/src/codegen/extract/graphql.d.ts.map +1 -0
- package/dist/src/codegen/extract/graphql.js +81 -0
- package/dist/src/codegen/extract/graphql.js.map +1 -0
- package/dist/src/codegen/extract/gwt.d.ts +6 -0
- package/dist/src/codegen/extract/gwt.d.ts.map +1 -0
- package/dist/src/codegen/extract/gwt.js +64 -0
- package/dist/src/codegen/extract/gwt.js.map +1 -0
- package/dist/src/codegen/extract/imports.d.ts +29 -0
- package/dist/src/codegen/extract/imports.d.ts.map +1 -0
- package/dist/src/codegen/extract/imports.js +55 -0
- package/dist/src/codegen/extract/imports.js.map +1 -0
- package/dist/src/codegen/extract/index.d.ts +10 -0
- package/dist/src/codegen/extract/index.d.ts.map +1 -0
- package/dist/src/codegen/extract/index.js +10 -0
- package/dist/src/codegen/extract/index.js.map +1 -0
- package/dist/src/codegen/extract/messages.d.ts +17 -0
- package/dist/src/codegen/extract/messages.d.ts.map +1 -0
- package/dist/src/codegen/extract/messages.js +172 -0
- package/dist/src/codegen/extract/messages.js.map +1 -0
- package/dist/src/codegen/extract/projection.d.ts +5 -0
- package/dist/src/codegen/extract/projection.d.ts.map +1 -0
- package/dist/src/codegen/extract/projection.js +44 -0
- package/dist/src/codegen/extract/projection.js.map +1 -0
- package/dist/src/codegen/extract/query.d.ts +14 -0
- package/dist/src/codegen/extract/query.d.ts.map +1 -0
- package/dist/src/codegen/extract/query.js +17 -0
- package/dist/src/codegen/extract/query.js.map +1 -0
- package/dist/src/codegen/extract/states.d.ts +5 -0
- package/dist/src/codegen/extract/states.d.ts.map +1 -0
- package/dist/src/codegen/extract/states.js +48 -0
- package/dist/src/codegen/extract/states.js.map +1 -0
- package/dist/src/codegen/extract/step-converter.d.ts +17 -0
- package/dist/src/codegen/extract/step-converter.d.ts.map +1 -0
- package/dist/src/codegen/extract/step-converter.js +82 -0
- package/dist/src/codegen/extract/step-converter.js.map +1 -0
- package/dist/src/codegen/extract/step-types.d.ts +29 -0
- package/dist/src/codegen/extract/step-types.d.ts.map +1 -0
- package/dist/src/codegen/extract/step-types.js +16 -0
- package/dist/src/codegen/extract/step-types.js.map +1 -0
- package/dist/src/codegen/extract/type-helpers.d.ts +13 -0
- package/dist/src/codegen/extract/type-helpers.d.ts.map +1 -0
- package/dist/src/codegen/extract/type-helpers.js +98 -0
- package/dist/src/codegen/extract/type-helpers.js.map +1 -0
- package/dist/src/codegen/scaffoldFromSchema.d.ts +9 -0
- package/dist/src/codegen/scaffoldFromSchema.d.ts.map +1 -0
- package/dist/src/codegen/scaffoldFromSchema.js +389 -0
- package/dist/src/codegen/scaffoldFromSchema.js.map +1 -0
- package/dist/src/codegen/templates/command/command.ts.ejs +16 -0
- package/dist/src/codegen/templates/command/handler.specs.ts.ejs +50 -0
- package/dist/src/codegen/templates/command/handler.ts.ejs +30 -0
- package/dist/src/codegen/templates/command/input.ts.ejs +23 -0
- package/dist/src/codegen/templates/command/resolver.ts.ejs +56 -0
- package/dist/src/codegen/templates/entity/entity.ts.ejs +35 -0
- package/dist/src/codegen/templates/entity/index.ts.ejs +6 -0
- package/dist/src/codegen/templates/module/app-module.ts.ejs +65 -0
- package/dist/src/codegen/templates/module/domain-module.ts.ejs +46 -0
- package/dist/src/codegen/templates/query/handler.ts.ejs +25 -0
- package/dist/src/codegen/templates/query/query.ts.ejs +1 -0
- package/dist/src/codegen/templates/query/resolver.ts.ejs +20 -0
- package/dist/src/codegen/templates/query/type.ts.ejs +24 -0
- package/dist/src/codegen/types.d.ts +38 -0
- package/dist/src/codegen/types.d.ts.map +1 -0
- package/dist/src/codegen/types.js +2 -0
- package/dist/src/codegen/types.js.map +1 -0
- package/dist/src/codegen/utils/path.d.ts +4 -0
- package/dist/src/codegen/utils/path.d.ts.map +1 -0
- package/dist/src/codegen/utils/path.js +18 -0
- package/dist/src/codegen/utils/path.js.map +1 -0
- package/dist/src/commands/generate-server.d.ts +28 -0
- package/dist/src/commands/generate-server.d.ts.map +1 -0
- package/dist/src/commands/generate-server.js +421 -0
- package/dist/src/commands/generate-server.js.map +1 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +3 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/shared/graphql-types.ts +19 -0
- package/dist/src/shared/main.ts +27 -0
- package/dist/src/shared/mikro-orm.config.ts +18 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +70 -0
- package/src/codegen/entity-consolidation.ts +213 -0
- package/src/codegen/extract/commands.ts +108 -0
- package/src/codegen/extract/data-sink.ts +93 -0
- package/src/codegen/extract/events.ts +63 -0
- package/src/codegen/extract/fields.ts +17 -0
- package/src/codegen/extract/graphql.ts +103 -0
- package/src/codegen/extract/gwt.ts +79 -0
- package/src/codegen/extract/imports.ts +71 -0
- package/src/codegen/extract/index.ts +9 -0
- package/src/codegen/extract/messages.ts +232 -0
- package/src/codegen/extract/projection.ts +62 -0
- package/src/codegen/extract/query.ts +28 -0
- package/src/codegen/extract/states.ts +69 -0
- package/src/codegen/extract/step-converter.ts +124 -0
- package/src/codegen/extract/step-types.ts +51 -0
- package/src/codegen/extract/type-helpers.ts +102 -0
- package/src/codegen/scaffoldFromSchema.ts +559 -0
- package/src/codegen/templates/command/command.ts.ejs +16 -0
- package/src/codegen/templates/command/handler.specs.ts.ejs +50 -0
- package/src/codegen/templates/command/handler.ts.ejs +30 -0
- package/src/codegen/templates/command/input.ts.ejs +23 -0
- package/src/codegen/templates/command/resolver.ts.ejs +56 -0
- package/src/codegen/templates/entity/entity.ts.ejs +35 -0
- package/src/codegen/templates/entity/index.ts.ejs +6 -0
- package/src/codegen/templates/module/app-module.ts.ejs +65 -0
- package/src/codegen/templates/module/domain-module.ts.ejs +46 -0
- package/src/codegen/templates/query/handler.ts.ejs +25 -0
- package/src/codegen/templates/query/query.ts.ejs +1 -0
- package/src/codegen/templates/query/resolver.ts.ejs +20 -0
- package/src/codegen/templates/query/type.ts.ejs +24 -0
- package/src/codegen/types.ts +39 -0
- package/src/codegen/utils/path.ts +20 -0
- package/src/commands/generate-server.ts +551 -0
- package/src/index.ts +10 -0
- package/src/shared/graphql-types.ts +19 -0
- package/src/shared/main.ts +27 -0
- package/src/shared/mikro-orm.config.ts +18 -0
- package/tsconfig.json +12 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
<%
|
|
2
|
+
const command = commands[0];
|
|
3
|
+
if (!command) return '';
|
|
4
|
+
const mutationName = camelCase(sliceName);
|
|
5
|
+
%>import { Mutation, Resolver, Args } from '@nestjs/graphql';
|
|
6
|
+
import { Logger, Injectable } from '@nestjs/common';
|
|
7
|
+
import { CommandBus } from '@nestjs/cqrs';
|
|
8
|
+
import { <%= pascalCase(command.type) %>Command } from './<%= toKebabCase(sliceName) %>.command';
|
|
9
|
+
import { <%= pascalCase(command.type) %>Input } from './<%= toKebabCase(sliceName) %>.input';
|
|
10
|
+
import { MutationResponse } from '../../shared/graphql-types';
|
|
11
|
+
|
|
12
|
+
@Injectable()
|
|
13
|
+
@Resolver()
|
|
14
|
+
export class <%= pascalCase(command.type) %>Resolver {
|
|
15
|
+
private readonly logger = new Logger(<%= pascalCase(command.type) %>Resolver.name);
|
|
16
|
+
|
|
17
|
+
constructor(private readonly commandBus: CommandBus) {}
|
|
18
|
+
|
|
19
|
+
@Mutation(() => MutationResponse)
|
|
20
|
+
async <%= mutationName %>(
|
|
21
|
+
@Args({ name: 'input', type: () => <%= pascalCase(command.type) %>Input })
|
|
22
|
+
input: <%= pascalCase(command.type) %>Input
|
|
23
|
+
): Promise<MutationResponse> {
|
|
24
|
+
try {
|
|
25
|
+
await this.commandBus.execute(
|
|
26
|
+
new <%= pascalCase(command.type) %>Command(
|
|
27
|
+
<% for (let i = 0; i < command.fields.length; i++) { const field = command.fields[i]; -%>
|
|
28
|
+
input.<%= field.name %>,
|
|
29
|
+
<% } -%>
|
|
30
|
+
)
|
|
31
|
+
);
|
|
32
|
+
this.logger.log(`Successfully executed: <%= mutationName %>`);
|
|
33
|
+
return { success: true };
|
|
34
|
+
} catch (error: unknown) {
|
|
35
|
+
if (error instanceof Error) {
|
|
36
|
+
this.logger.error(`Failed to execute <%= mutationName %>: ${error.message}`, error.stack);
|
|
37
|
+
return {
|
|
38
|
+
success: false,
|
|
39
|
+
error: {
|
|
40
|
+
type: error.name,
|
|
41
|
+
message: error.message,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
this.logger.error('Failed to execute <%= mutationName %>: Unknown error');
|
|
47
|
+
return {
|
|
48
|
+
success: false,
|
|
49
|
+
error: {
|
|
50
|
+
type: 'UnknownError',
|
|
51
|
+
message: 'An unexpected error occurred',
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<%
|
|
2
|
+
function getOrmType(field) {
|
|
3
|
+
const cleanType = field.tsType.replace(/\s*\|\s*null\b/g, '').trim();
|
|
4
|
+
if (cleanType === 'string') return 'string';
|
|
5
|
+
if (cleanType === 'number') return 'number';
|
|
6
|
+
if (cleanType === 'boolean') return 'boolean';
|
|
7
|
+
if (cleanType === 'Date') return 'Date';
|
|
8
|
+
return 'string';
|
|
9
|
+
}
|
|
10
|
+
%>import { Entity, PrimaryKey, Property, Enum, Index } from '@mikro-orm/core';
|
|
11
|
+
<% if (entity.enumImports.length > 0) { -%>
|
|
12
|
+
import { <%= entity.enumImports.join(', ') %> } from '.';
|
|
13
|
+
<% } -%>
|
|
14
|
+
|
|
15
|
+
@Entity({ tableName: '<%= entity.tableName %>' })
|
|
16
|
+
export class <%= entity.entityName %> {
|
|
17
|
+
<% for (const field of entity.fields) { -%>
|
|
18
|
+
<% if (field.isPrimary) { -%>
|
|
19
|
+
@PrimaryKey({ type: '<%= getOrmType(field) %>' })
|
|
20
|
+
<%= field.name %>!: <%= toTsFieldType(field.tsType) %>;
|
|
21
|
+
|
|
22
|
+
<% } else if (field.isEnum && field.enumName) { -%>
|
|
23
|
+
@Enum(() => <%= field.enumName %>)
|
|
24
|
+
<% if (field.indexed) { -%>
|
|
25
|
+
@Index()
|
|
26
|
+
<% } -%>
|
|
27
|
+
<%= field.name %>!: <%= field.enumName %>;
|
|
28
|
+
|
|
29
|
+
<% } else { -%>
|
|
30
|
+
@Property({ type: '<%= getOrmType(field) %>'<%= field.nullable ? ', nullable: true' : '' %> })
|
|
31
|
+
<%= field.name %><%= field.nullable ? '?' : '!' %>: <%= toTsFieldType(field.tsType) %><%= field.nullable ? ' | null' : '' %>;
|
|
32
|
+
|
|
33
|
+
<% } -%>
|
|
34
|
+
<% } -%>
|
|
35
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Module, Logger } from '@nestjs/common';
|
|
2
|
+
import { CqrsModule } from '@nestjs/cqrs';
|
|
3
|
+
import { GraphQLModule } from '@nestjs/graphql';
|
|
4
|
+
import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo';
|
|
5
|
+
import { MikroOrmModule } from '@mikro-orm/nestjs';
|
|
6
|
+
import { SqliteDriver } from '@mikro-orm/sqlite';
|
|
7
|
+
import { Migrator } from '@mikro-orm/migrations';
|
|
8
|
+
import { join } from 'path';
|
|
9
|
+
import { ApolloServerPluginLandingPageLocalDefault } from '@apollo/server/plugin/landingPage/default';
|
|
10
|
+
|
|
11
|
+
<% for (const flow of flows) { -%>
|
|
12
|
+
import { <%= pascalCase(flow.name) %>Module } from './domain/<%= toKebabCase(flow.name) %>/<%= toKebabCase(flow.name) %>.module';
|
|
13
|
+
import { <%= pascalCase(flow.name) %>Entity } from './domain/<%= toKebabCase(flow.name) %>/entities';
|
|
14
|
+
<% } -%>
|
|
15
|
+
|
|
16
|
+
const domainModules = [
|
|
17
|
+
<% for (const flow of flows) { -%>
|
|
18
|
+
<%= pascalCase(flow.name) %>Module,
|
|
19
|
+
<% } -%>
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
const entities = [
|
|
23
|
+
<% for (const flow of flows) { -%>
|
|
24
|
+
<%= pascalCase(flow.name) %>Entity,
|
|
25
|
+
<% } -%>
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
@Module({
|
|
29
|
+
imports: [
|
|
30
|
+
...domainModules,
|
|
31
|
+
MikroOrmModule.forRoot({
|
|
32
|
+
entities,
|
|
33
|
+
dbName: process.env.NODE_ENV === 'test' ? ':memory:' : './db.sqlite',
|
|
34
|
+
driver: SqliteDriver,
|
|
35
|
+
allowGlobalContext: true,
|
|
36
|
+
debug: process.env.NODE_ENV !== 'production',
|
|
37
|
+
ensureDatabase: true,
|
|
38
|
+
extensions: [Migrator],
|
|
39
|
+
migrations: {
|
|
40
|
+
path: join(__dirname, 'migrations'),
|
|
41
|
+
glob: '!(*.d).{js,ts}',
|
|
42
|
+
transactional: true,
|
|
43
|
+
disableForeignKeys: false,
|
|
44
|
+
emit: 'ts',
|
|
45
|
+
},
|
|
46
|
+
}),
|
|
47
|
+
CqrsModule.forRoot(),
|
|
48
|
+
GraphQLModule.forRoot<ApolloDriverConfig>({
|
|
49
|
+
driver: ApolloDriver,
|
|
50
|
+
autoSchemaFile: join(process.cwd(), 'src/schema.gql'),
|
|
51
|
+
sortSchema: true,
|
|
52
|
+
playground: false,
|
|
53
|
+
introspection: true,
|
|
54
|
+
csrfPrevention: false,
|
|
55
|
+
plugins: [ApolloServerPluginLandingPageLocalDefault()],
|
|
56
|
+
}),
|
|
57
|
+
],
|
|
58
|
+
})
|
|
59
|
+
export class AppModule {
|
|
60
|
+
private readonly logger = new Logger(AppModule.name);
|
|
61
|
+
|
|
62
|
+
constructor() {
|
|
63
|
+
this.logger.log('✅ Application module initialized');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
<%
|
|
2
|
+
const moduleName = pascalCase(flowName) + 'Module';
|
|
3
|
+
const entityName = pascalCase(flowName) + 'Entity';
|
|
4
|
+
%>import { Module } from '@nestjs/common';
|
|
5
|
+
import { CqrsModule } from '@nestjs/cqrs';
|
|
6
|
+
import { MikroOrmModule } from '@mikro-orm/nestjs';
|
|
7
|
+
import { <%= entityName %> } from './entities/<%= toKebabCase(entityName) %>.entity';
|
|
8
|
+
<% for (const slice of slices) { -%>
|
|
9
|
+
<% if (slice.type === 'command') { -%>
|
|
10
|
+
import { <%= pascalCase(slice.name) %>Handler } from './<%= toKebabCase(slice.name) %>/<%= toKebabCase(slice.name) %>.handler';
|
|
11
|
+
import { <%= pascalCase(slice.name) %>Resolver } from './<%= toKebabCase(slice.name) %>/<%= toKebabCase(slice.name) %>.resolver';
|
|
12
|
+
<% } else if (slice.type === 'query') { -%>
|
|
13
|
+
import { <%= pascalCase(slice.name) %>Handler } from './<%= toKebabCase(slice.name) %>/<%= toKebabCase(slice.name) %>.handler';
|
|
14
|
+
import { <%= pascalCase(slice.name) %>Resolver } from './<%= toKebabCase(slice.name) %>/<%= toKebabCase(slice.name) %>.resolver';
|
|
15
|
+
<% } -%>
|
|
16
|
+
<% } -%>
|
|
17
|
+
|
|
18
|
+
const CommandHandlers = [
|
|
19
|
+
<% for (const slice of slices) { -%>
|
|
20
|
+
<% if (slice.type === 'command') { -%>
|
|
21
|
+
<%= pascalCase(slice.name) %>Handler,
|
|
22
|
+
<% } -%>
|
|
23
|
+
<% } -%>
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
const QueryHandlers = [
|
|
27
|
+
<% for (const slice of slices) { -%>
|
|
28
|
+
<% if (slice.type === 'query') { -%>
|
|
29
|
+
<%= pascalCase(slice.name) %>Handler,
|
|
30
|
+
<% } -%>
|
|
31
|
+
<% } -%>
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
const Resolvers = [
|
|
35
|
+
<% for (const slice of slices) { -%>
|
|
36
|
+
<% if (slice.type === 'command' || slice.type === 'query') { -%>
|
|
37
|
+
<%= pascalCase(slice.name) %>Resolver,
|
|
38
|
+
<% } -%>
|
|
39
|
+
<% } -%>
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
@Module({
|
|
43
|
+
imports: [CqrsModule, MikroOrmModule.forFeature([<%= entityName %>])],
|
|
44
|
+
providers: [...CommandHandlers, ...QueryHandlers, ...Resolvers],
|
|
45
|
+
})
|
|
46
|
+
export class <%= moduleName %> {}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<%
|
|
2
|
+
const entityName = pascalCase(flowName) + 'Entity';
|
|
3
|
+
const typeName = projectionType || pascalCase(sliceName) + 'State';
|
|
4
|
+
const isSingleton = projectionSingleton === true;
|
|
5
|
+
%>import { QueryHandler, IQueryHandler } from '@nestjs/cqrs';
|
|
6
|
+
import { InjectRepository } from '@mikro-orm/nestjs';
|
|
7
|
+
import { EntityRepository } from '@mikro-orm/core';
|
|
8
|
+
import { <%= pascalCase(sliceName) %>Query } from './<%= toKebabCase(sliceName) %>.query';
|
|
9
|
+
import { <%= entityName %> } from '../entities/<%= toKebabCase(entityName) %>.entity';
|
|
10
|
+
|
|
11
|
+
@QueryHandler(<%= pascalCase(sliceName) %>Query)
|
|
12
|
+
export class <%= pascalCase(sliceName) %>Handler implements IQueryHandler<<%= pascalCase(sliceName) %>Query> {
|
|
13
|
+
constructor(
|
|
14
|
+
@InjectRepository(<%= entityName %>)
|
|
15
|
+
private readonly repository: EntityRepository<<%= entityName %>>,
|
|
16
|
+
) {}
|
|
17
|
+
|
|
18
|
+
async execute(): Promise<<%= entityName %><%= isSingleton ? ' | null' : '[]' %>> {
|
|
19
|
+
<% if (isSingleton) { -%>
|
|
20
|
+
return this.repository.findOne({});
|
|
21
|
+
<% } else { -%>
|
|
22
|
+
return this.repository.findAll();
|
|
23
|
+
<% } -%>
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export class <%= pascalCase(sliceName) %>Query {}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<%
|
|
2
|
+
const typeName = projectionType || pascalCase(sliceName) + 'State';
|
|
3
|
+
const queryName = camelCase(projectionName || sliceName);
|
|
4
|
+
const isSingleton = projectionSingleton === true;
|
|
5
|
+
%>import { Query, Resolver } from '@nestjs/graphql';
|
|
6
|
+
import { Injectable } from '@nestjs/common';
|
|
7
|
+
import { QueryBus } from '@nestjs/cqrs';
|
|
8
|
+
import { <%= pascalCase(sliceName) %>Query } from './<%= toKebabCase(sliceName) %>.query';
|
|
9
|
+
import { <%= typeName %> } from './<%= toKebabCase(sliceName) %>.type';
|
|
10
|
+
|
|
11
|
+
@Injectable()
|
|
12
|
+
@Resolver()
|
|
13
|
+
export class <%= pascalCase(sliceName) %>Resolver {
|
|
14
|
+
constructor(private readonly queryBus: QueryBus) {}
|
|
15
|
+
|
|
16
|
+
@Query(() => <%= isSingleton ? typeName : `[${typeName}]` %>)
|
|
17
|
+
async <%= queryName %>(): Promise<<%= typeName %><%= isSingleton ? ' | null' : '[]' %>> {
|
|
18
|
+
return this.queryBus.execute(new <%= pascalCase(sliceName) %>Query());
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<%
|
|
2
|
+
const state = states[0] || message;
|
|
3
|
+
if (!state || !state.fields) return '';
|
|
4
|
+
const usesID = state.fields.some(f => graphqlType(f.tsType) === 'ID');
|
|
5
|
+
const usesFloat = state.fields.some(f => fieldUsesFloat(f.tsType));
|
|
6
|
+
const usesJSON = state.fields.some(f => fieldUsesJSON(f.tsType));
|
|
7
|
+
const enumList = collectEnumNames(state.fields);
|
|
8
|
+
const typeName = projectionType || pascalCase(sliceName) + 'State';
|
|
9
|
+
%>import { ObjectType, Field<% if (usesID) { %>, ID<% } %><% if (usesFloat) { %>, Float<% } %> } from '@nestjs/graphql';
|
|
10
|
+
<% if (usesJSON) { -%>
|
|
11
|
+
import GraphQLJSON from 'graphql-type-json';
|
|
12
|
+
<% } -%>
|
|
13
|
+
<% if (enumList.length > 0) { -%>
|
|
14
|
+
import { <%= enumList.join(', ') %> } from '../entities';
|
|
15
|
+
<% } -%>
|
|
16
|
+
|
|
17
|
+
@ObjectType()
|
|
18
|
+
export class <%= typeName %> {
|
|
19
|
+
<% for (const field of state.fields) { -%>
|
|
20
|
+
@Field(() => <%= graphqlType(field.tsType) %><%= isNullable(field.tsType) ? ', { nullable: true }' : '' %>)
|
|
21
|
+
<%= field.name %><%= isNullable(field.tsType) ? '?' : '!' %>: <%= toTsFieldType(field.tsType) %><%= isNullable(field.tsType) ? ' | null' : '' %>;
|
|
22
|
+
|
|
23
|
+
<% } -%>
|
|
24
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { CommandExample, ErrorRef, EventExample, StateExample } from './extract/step-types';
|
|
2
|
+
|
|
3
|
+
export type { CommandExample, ErrorRef, EventExample, StateExample };
|
|
4
|
+
|
|
5
|
+
export interface Message {
|
|
6
|
+
type: string;
|
|
7
|
+
fields: Field[];
|
|
8
|
+
source?: 'when' | 'given' | 'then';
|
|
9
|
+
sourceFlowName?: string;
|
|
10
|
+
sourceSliceName?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface Field {
|
|
14
|
+
name: string;
|
|
15
|
+
tsType: string;
|
|
16
|
+
required: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface MessageDefinition {
|
|
20
|
+
type: 'command' | 'event' | 'state';
|
|
21
|
+
name: string;
|
|
22
|
+
fields?: Array<{
|
|
23
|
+
name: string;
|
|
24
|
+
type: string;
|
|
25
|
+
required?: boolean;
|
|
26
|
+
description?: string;
|
|
27
|
+
defaultValue?: unknown;
|
|
28
|
+
}>;
|
|
29
|
+
metadata?: unknown;
|
|
30
|
+
description?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface GwtCondition {
|
|
34
|
+
given?: Array<EventExample | StateExample>;
|
|
35
|
+
when: CommandExample | EventExample[];
|
|
36
|
+
then: Array<EventExample | StateExample | CommandExample | { errorType: string; message?: string }>;
|
|
37
|
+
description?: string;
|
|
38
|
+
ruleDescription?: string;
|
|
39
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { existsSync } from 'fs';
|
|
2
|
+
import { mkdir } from 'fs/promises';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
export function toKebabCase(str: string): string {
|
|
6
|
+
return str
|
|
7
|
+
.replace(/([a-z])([A-Z])/g, '$1-$2')
|
|
8
|
+
.replace(/\s+/g, '-')
|
|
9
|
+
.toLowerCase();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function ensureDirPath(...segments: string[]): string {
|
|
13
|
+
return path.join(...segments);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function ensureDirExists(dirPath: string): Promise<void> {
|
|
17
|
+
if (!existsSync(dirPath)) {
|
|
18
|
+
await mkdir(dirPath, { recursive: true });
|
|
19
|
+
}
|
|
20
|
+
}
|