@auto-engineer/server-generator-apollo-emmett 0.10.4 → 0.11.0
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 +6 -0
- package/.turbo/turbo-format.log +5 -0
- package/.turbo/turbo-lint.log +4 -0
- package/.turbo/turbo-test.log +22 -0
- package/.turbo/turbo-type-check.log +5 -0
- package/CHANGELOG.md +20 -0
- package/dist/src/codegen/extract/events.d.ts +2 -2
- package/dist/src/codegen/extract/events.d.ts.map +1 -1
- package/dist/src/codegen/extract/events.js +16 -6
- package/dist/src/codegen/extract/events.js.map +1 -1
- package/dist/src/codegen/extract/gwt.js +7 -22
- package/dist/src/codegen/extract/gwt.js.map +1 -1
- 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 +1 -0
- package/dist/src/codegen/extract/index.d.ts.map +1 -1
- package/dist/src/codegen/extract/index.js +1 -0
- package/dist/src/codegen/extract/index.js.map +1 -1
- package/dist/src/codegen/extract/messages.d.ts.map +1 -1
- package/dist/src/codegen/extract/messages.js +33 -7
- package/dist/src/codegen/extract/messages.js.map +1 -1
- package/dist/src/codegen/extract/query.d.ts +3 -1
- package/dist/src/codegen/extract/query.d.ts.map +1 -1
- package/dist/src/codegen/extract/query.js +12 -12
- package/dist/src/codegen/extract/query.js.map +1 -1
- package/dist/src/codegen/scaffoldFromSchema.d.ts.map +1 -1
- package/dist/src/codegen/scaffoldFromSchema.js +9 -1
- package/dist/src/codegen/scaffoldFromSchema.js.map +1 -1
- package/dist/src/codegen/templates/command/decide.specs.specs.ts +235 -8
- package/dist/src/codegen/templates/command/decide.specs.ts +8 -8
- package/dist/src/codegen/templates/command/decide.specs.ts.ejs +95 -30
- package/dist/src/codegen/templates/command/decide.ts.ejs +2 -2
- package/dist/src/codegen/templates/command/events.ts.ejs +2 -2
- package/dist/src/codegen/templates/command/evolve.ts.ejs +3 -3
- package/dist/src/codegen/templates/command/handle.specs.ts +6 -6
- package/dist/src/codegen/templates/command/handle.ts.ejs +3 -3
- package/dist/src/codegen/templates/query/projection.specs.specs.ts +623 -0
- package/dist/src/codegen/templates/query/projection.specs.ts +1 -1
- package/dist/src/codegen/templates/query/projection.specs.ts.ejs +176 -52
- package/dist/src/codegen/templates/query/projection.ts.ejs +30 -29
- package/dist/src/codegen/templates/query/query.resolver.specs.ts +190 -5
- package/dist/src/codegen/templates/query/query.resolver.ts.ejs +31 -9
- package/dist/src/codegen/templates/react/react.specs.specs.ts +8 -5
- package/dist/src/codegen/templates/react/react.specs.ts +4 -4
- package/dist/src/codegen/templates/react/react.specs.ts.ejs +118 -67
- package/dist/src/codegen/templates/react/react.ts.ejs +4 -4
- package/dist/src/codegen/templates/react/register.specs.ts +2 -2
- package/dist/src/codegen/templates/react/register.ts.ejs +2 -2
- package/dist/src/codegen/types.d.ts +2 -0
- package/dist/src/codegen/types.d.ts.map +1 -1
- package/dist/src/commands/generate-server.d.ts.map +1 -1
- package/dist/src/commands/generate-server.js +3 -0
- package/dist/src/commands/generate-server.js.map +1 -1
- package/dist/src/domain/shared/ReadModel.d.ts +2 -2
- package/dist/src/domain/shared/ReadModel.d.ts.map +1 -1
- package/dist/src/domain/shared/ReadModel.js +2 -2
- package/dist/src/domain/shared/ReadModel.js.map +1 -1
- package/dist/src/domain/shared/ReadModel.ts +3 -3
- package/dist/src/domain/shared/types.d.ts +5 -3
- package/dist/src/domain/shared/types.d.ts.map +1 -1
- package/dist/src/domain/shared/types.js.map +1 -1
- package/dist/src/domain/shared/types.ts +5 -3
- package/dist/src/server.js +54 -7
- package/dist/src/server.js.map +1 -1
- package/dist/src/server.ts +53 -15
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -5
- package/src/codegen/extract/events.ts +20 -3
- package/src/codegen/extract/gwt.ts +10 -26
- package/src/codegen/extract/imports.ts +71 -0
- package/src/codegen/extract/index.ts +1 -0
- package/src/codegen/extract/messages.ts +34 -7
- package/src/codegen/extract/query.ts +17 -19
- package/src/codegen/scaffoldFromSchema.ts +13 -0
- package/src/codegen/templates/command/decide.specs.specs.ts +235 -8
- package/src/codegen/templates/command/decide.specs.ts +8 -8
- package/src/codegen/templates/command/decide.specs.ts.ejs +95 -30
- package/src/codegen/templates/command/decide.ts.ejs +2 -2
- package/src/codegen/templates/command/events.ts.ejs +2 -2
- package/src/codegen/templates/command/evolve.ts.ejs +3 -3
- package/src/codegen/templates/command/handle.specs.ts +6 -6
- package/src/codegen/templates/command/handle.ts.ejs +3 -3
- package/src/codegen/templates/query/projection.specs.specs.ts +623 -0
- package/src/codegen/templates/query/projection.specs.ts +1 -1
- package/src/codegen/templates/query/projection.specs.ts.ejs +176 -52
- package/src/codegen/templates/query/projection.ts.ejs +30 -29
- package/src/codegen/templates/query/query.resolver.specs.ts +190 -5
- package/src/codegen/templates/query/query.resolver.ts.ejs +31 -9
- package/src/codegen/templates/react/react.specs.specs.ts +8 -5
- package/src/codegen/templates/react/react.specs.ts +4 -4
- package/src/codegen/templates/react/react.specs.ts.ejs +118 -67
- package/src/codegen/templates/react/react.ts.ejs +4 -4
- package/src/codegen/templates/react/register.specs.ts +2 -2
- package/src/codegen/templates/react/register.ts.ejs +2 -2
- package/src/codegen/types.ts +2 -0
- package/src/commands/generate-server.ts +3 -0
- package/src/domain/shared/ReadModel.ts +3 -3
- package/src/domain/shared/types.ts +5 -3
- package/src/server.ts +53 -15
- package/dist/src/codegen/templates/query/projection.specs.specs..ts +0 -296
- package/src/codegen/scaffoldFromSchema.query-slice-register.specs.ts +0 -179
- package/src/codegen/templates/query/projection.specs.specs..ts +0 -296
|
@@ -81,7 +81,7 @@ describe('decide.ts.ejs', () => {
|
|
|
81
81
|
import type { CreateListing } from './commands';
|
|
82
82
|
import type { ListingCreated } from './events';
|
|
83
83
|
|
|
84
|
-
export const decide = (command: CreateListing,
|
|
84
|
+
export const decide = (command: CreateListing, _state: State): ListingCreated => {
|
|
85
85
|
switch (command.type) {
|
|
86
86
|
case 'CreateListing': {
|
|
87
87
|
/**
|
|
@@ -106,7 +106,7 @@ describe('decide.ts.ejs', () => {
|
|
|
106
106
|
throw new IllegalStateError('Not yet implemented: ' + command.type);
|
|
107
107
|
}
|
|
108
108
|
default:
|
|
109
|
-
throw new IllegalStateError(
|
|
109
|
+
throw new IllegalStateError(\`Unexpected command type: \${String(command.type)}\`);
|
|
110
110
|
}
|
|
111
111
|
};
|
|
112
112
|
"
|
|
@@ -206,7 +206,7 @@ describe('decide.ts.ejs', () => {
|
|
|
206
206
|
import type { RemoveListing } from './commands';
|
|
207
207
|
import type { ListingRemoved } from './events';
|
|
208
208
|
|
|
209
|
-
export const decide = (command: RemoveListing,
|
|
209
|
+
export const decide = (command: RemoveListing, _state: State): ListingRemoved => {
|
|
210
210
|
switch (command.type) {
|
|
211
211
|
case 'RemoveListing': {
|
|
212
212
|
/**
|
|
@@ -231,7 +231,7 @@ describe('decide.ts.ejs', () => {
|
|
|
231
231
|
throw new IllegalStateError('Not yet implemented: ' + command.type);
|
|
232
232
|
}
|
|
233
233
|
default:
|
|
234
|
-
throw new IllegalStateError(
|
|
234
|
+
throw new IllegalStateError(\`Unexpected command type: \${String(command.type)}\`);
|
|
235
235
|
}
|
|
236
236
|
};
|
|
237
237
|
"
|
|
@@ -346,7 +346,7 @@ describe('decide.ts.ejs', () => {
|
|
|
346
346
|
import type { CreateListing } from './commands';
|
|
347
347
|
import type { ListingCreated } from './events';
|
|
348
348
|
|
|
349
|
-
export const decide = (command: CreateListing,
|
|
349
|
+
export const decide = (command: CreateListing, _state: State): ListingCreated => {
|
|
350
350
|
switch (command.type) {
|
|
351
351
|
case 'CreateListing': {
|
|
352
352
|
/**
|
|
@@ -375,7 +375,7 @@ describe('decide.ts.ejs', () => {
|
|
|
375
375
|
throw new IllegalStateError('Not yet implemented: ' + command.type);
|
|
376
376
|
}
|
|
377
377
|
default:
|
|
378
|
-
throw new IllegalStateError(
|
|
378
|
+
throw new IllegalStateError(\`Unexpected command type: \${String(command.type)}\`);
|
|
379
379
|
}
|
|
380
380
|
};
|
|
381
381
|
"
|
|
@@ -532,7 +532,7 @@ describe('decide.ts.ejs', () => {
|
|
|
532
532
|
import type { ItemsSuggested } from './events';
|
|
533
533
|
import type { Products } from '@auto-engineer/product-catalogue-integration';
|
|
534
534
|
|
|
535
|
-
export const decide = (command: SuggestItems,
|
|
535
|
+
export const decide = (command: SuggestItems, _state: State, products?: Products): ItemsSuggested => {
|
|
536
536
|
switch (command.type) {
|
|
537
537
|
case 'SuggestItems': {
|
|
538
538
|
/**
|
|
@@ -566,7 +566,7 @@ describe('decide.ts.ejs', () => {
|
|
|
566
566
|
throw new IllegalStateError('Not yet implemented: ' + command.type);
|
|
567
567
|
}
|
|
568
568
|
default:
|
|
569
|
-
throw new IllegalStateError(
|
|
569
|
+
throw new IllegalStateError(\`Unexpected command type: \${String(command.type)}\`);
|
|
570
570
|
}
|
|
571
571
|
};
|
|
572
572
|
"
|
|
@@ -1,51 +1,116 @@
|
|
|
1
|
+
<%
|
|
2
|
+
const allEvents = [];
|
|
3
|
+
const ruleGroups = new Map();
|
|
4
|
+
for (const commandName in gwtMapping) {
|
|
5
|
+
const cases = gwtMapping[commandName];
|
|
6
|
+
for (const gwt of cases) {
|
|
7
|
+
const ruleDescription = gwt.ruleDescription || `${flowName} | ${sliceName}`;
|
|
8
|
+
if (!ruleGroups.has(ruleDescription)) {
|
|
9
|
+
ruleGroups.set(ruleDescription, []);
|
|
10
|
+
}
|
|
11
|
+
ruleGroups.get(ruleDescription).push({ commandName, gwt });
|
|
12
|
+
if (gwt.given && gwt.given.length) {
|
|
13
|
+
for (const g of gwt.given) {
|
|
14
|
+
if (g.eventRef) {
|
|
15
|
+
const event = events.find(e => e.type === g.eventRef);
|
|
16
|
+
if (event) allEvents.push(event);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (gwt.then) {
|
|
21
|
+
for (const t of gwt.then) {
|
|
22
|
+
if (t.eventRef) {
|
|
23
|
+
const event = events.find(e => e.type === t.eventRef);
|
|
24
|
+
if (event) allEvents.push(event);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const testEventImportGroups = [];
|
|
32
|
+
const testEventsByPath = new Map();
|
|
33
|
+
|
|
34
|
+
for (const event of allEvents) {
|
|
35
|
+
if (!event.type) continue;
|
|
36
|
+
const importGroup = eventImportGroups.find(group =>
|
|
37
|
+
group.eventTypes.includes(event.type)
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
if (importGroup) {
|
|
41
|
+
const path = importGroup.importPath;
|
|
42
|
+
if (!testEventsByPath.has(path)) {
|
|
43
|
+
testEventsByPath.set(path, []);
|
|
44
|
+
}
|
|
45
|
+
if (!testEventsByPath.get(path).includes(event.type)) {
|
|
46
|
+
testEventsByPath.get(path).push(event.type);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
for (const [importPath, eventTypes] of testEventsByPath.entries()) {
|
|
52
|
+
testEventImportGroups.push({ importPath, eventTypes: eventTypes.sort() });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const uniqueEventTypes = Array.from(new Set(allEvents.map(e => e?.type).filter(Boolean))).sort();
|
|
56
|
+
_%>
|
|
1
57
|
import { describe, it } from 'vitest';
|
|
2
58
|
import { DeciderSpecification } from '@event-driven-io/emmett';
|
|
3
59
|
import { decide } from './decide';
|
|
4
60
|
import { evolve } from './evolve';
|
|
5
|
-
import { initialState } from './state';
|
|
61
|
+
import { initialState, State } from './state';
|
|
62
|
+
<% for (const group of testEventImportGroups) { -%>
|
|
63
|
+
import type { <%= group.eventTypes.join(', ') %> } from '<%= group.importPath %>';
|
|
64
|
+
<% } -%>
|
|
65
|
+
import type { <%= Object.keys(commandSchemasByName).join(', ') %> } from './commands';
|
|
66
|
+
<% for (const [ruleDescription, ruleGwts] of ruleGroups.entries()) { %>
|
|
67
|
+
describe('<%= ruleDescription %>', () => {
|
|
6
68
|
|
|
7
|
-
|
|
8
|
-
const given = DeciderSpecification.for({
|
|
9
|
-
decide,
|
|
10
|
-
evolve,
|
|
11
|
-
initialState,
|
|
12
|
-
});
|
|
69
|
+
type Events = <%= uniqueEventTypes.length > 0 ? uniqueEventTypes.join(' | ') : 'never' %>;
|
|
13
70
|
|
|
14
|
-
|
|
15
|
-
|
|
71
|
+
const given = DeciderSpecification.for<<%= Object.keys(commandSchemasByName).length === 1 ? Object.keys(commandSchemasByName)[0] : `(${Object.keys(commandSchemasByName).join(' | ')})` %>, Events, State>({
|
|
72
|
+
decide,
|
|
73
|
+
evolve,
|
|
74
|
+
initialState,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
<% for (const { commandName, gwt } of ruleGwts) {
|
|
16
78
|
const schema = commandSchemasByName[commandName];
|
|
17
|
-
for (const [i, gwt] of cases.entries()) {
|
|
18
79
|
const example = gwt.when;
|
|
19
80
|
const eventResults = gwt.then.filter(t => 'eventRef' in t);
|
|
20
81
|
const errorResult = gwt.then.find(t => 'errorType' in t);
|
|
21
|
-
|
|
82
|
+
|
|
83
|
+
const testDescription = gwt.description ||
|
|
84
|
+
(errorResult
|
|
22
85
|
? `should throw ${errorResult.errorType} when ${gwt.failingFields?.join(', ') || 'invalid input'}`
|
|
23
|
-
: `should emit ${eventResults.map(e => e.eventRef).join(', ')} for valid ${commandName}
|
|
86
|
+
: `should emit ${eventResults.map(e => e.eventRef).join(', ')} for valid ${commandName}`);
|
|
24
87
|
%>
|
|
25
|
-
it('
|
|
26
|
-
given([
|
|
88
|
+
it('<%= testDescription %>', () => {
|
|
89
|
+
given([
|
|
27
90
|
<%_ if (gwt.given && gwt.given.length) { _%>
|
|
28
|
-
|
|
91
|
+
<%- gwt.given.map(g => `{
|
|
29
92
|
type: '${g.eventRef}',
|
|
30
93
|
data: ${formatDataObject(g.exampleData, events.find(e => e.type === g.eventRef))}
|
|
31
94
|
}`).join(',\n ') %>
|
|
32
95
|
<%_ } _%>
|
|
33
|
-
])
|
|
34
|
-
.when({
|
|
35
|
-
type: '<%= example.commandRef %>',
|
|
36
|
-
data: <%- formatDataObject(example.exampleData, schema) %>,
|
|
37
|
-
metadata: { now: new Date() }
|
|
38
|
-
})
|
|
96
|
+
])
|
|
97
|
+
.when({
|
|
98
|
+
type: '<%= example.commandRef %>',
|
|
99
|
+
data: <%- formatDataObject(example.exampleData, schema) %>,
|
|
100
|
+
metadata: { now: new Date() },
|
|
101
|
+
})
|
|
39
102
|
<% if (errorResult) { %>
|
|
40
|
-
|
|
103
|
+
.thenThrows((err) => err instanceof <%= errorResult.errorType %> && err.message === '<%= errorResult.message || '' %>');
|
|
41
104
|
<% } else { %>
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
105
|
+
|
|
106
|
+
.then([
|
|
107
|
+
<%- eventResults.map(e => `{
|
|
108
|
+
type: '${e.eventRef}',
|
|
109
|
+
data: ${formatDataObject(e.exampleData, events.find(evt => evt.type === e.eventRef))}
|
|
110
|
+
}`).join(',\n ') %>
|
|
111
|
+
]);
|
|
112
|
+
<% } %>
|
|
113
|
+
});
|
|
48
114
|
<% } %>
|
|
49
115
|
});
|
|
50
|
-
<% }
|
|
51
|
-
});
|
|
116
|
+
<% } %>
|
|
@@ -45,7 +45,7 @@ function formatFieldDocLine(field) {
|
|
|
45
45
|
|
|
46
46
|
export const decide = (
|
|
47
47
|
command: <%= Object.keys(gwtMapping).map(pascalCase).join(' | ') %>,
|
|
48
|
-
|
|
48
|
+
_state: State<%= integrationReturnType ? `,\n ${camelCase(integrationReturnType)}?: ${integrationReturnType}` : '' %>
|
|
49
49
|
): <%= uniqueEventTypes.length === 0
|
|
50
50
|
? 'never'
|
|
51
51
|
: uniqueEventTypes.length === 1
|
|
@@ -102,6 +102,6 @@ throw new IllegalStateError('Not yet implemented: ' + command.type);
|
|
|
102
102
|
}
|
|
103
103
|
<% } -%>
|
|
104
104
|
default:
|
|
105
|
-
throw new IllegalStateError(
|
|
105
|
+
throw new IllegalStateError(`Unexpected command type: ${String(command.type)}`);
|
|
106
106
|
}
|
|
107
107
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
<% if (
|
|
1
|
+
<% if (localEvents.length) { -%>
|
|
2
2
|
import type { Event } from '@event-driven-io/emmett';
|
|
3
3
|
|
|
4
|
-
<% for (const event of
|
|
4
|
+
<% for (const event of localEvents) { -%>
|
|
5
5
|
export type <%= pascalCase(event.type) %> = Event<
|
|
6
6
|
'<%= event.type %>',
|
|
7
7
|
{
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<% if (events.length) { -%>
|
|
2
2
|
import type { State } from './state';
|
|
3
|
-
<%
|
|
4
|
-
import type { <%= pascalCase(
|
|
5
|
-
<% }
|
|
3
|
+
<% for (const group of eventImportGroups) { -%>
|
|
4
|
+
import type { <%= group.eventTypes.map(name => pascalCase(name)).join(', ') %> } from '<%= group.importPath %>';
|
|
5
|
+
<% } -%>
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* ## IMPLEMENTATION INSTRUCTIONS ##
|
|
@@ -117,11 +117,11 @@ describe('generateScaffoldFilePlans', () => {
|
|
|
117
117
|
|
|
118
118
|
try {
|
|
119
119
|
await handler(eventStore, streamId, (state) => decide(command, state));
|
|
120
|
-
return; // success
|
|
121
|
-
} catch (error:
|
|
120
|
+
return undefined; // success
|
|
121
|
+
} catch (error: unknown) {
|
|
122
122
|
return {
|
|
123
123
|
type: 'SKIP',
|
|
124
|
-
reason: \`Command failed: \${error
|
|
124
|
+
reason: \`Command failed: \${error instanceof Error ? error.message : 'Unknown'}\`,
|
|
125
125
|
};
|
|
126
126
|
}
|
|
127
127
|
};
|
|
@@ -315,11 +315,11 @@ describe('generateScaffoldFilePlans', () => {
|
|
|
315
315
|
// TODO: add products as a parameter to decide once implemented above
|
|
316
316
|
decide(command, state /* products */),
|
|
317
317
|
);
|
|
318
|
-
return; // success
|
|
319
|
-
} catch (error:
|
|
318
|
+
return undefined; // success
|
|
319
|
+
} catch (error: unknown) {
|
|
320
320
|
return {
|
|
321
321
|
type: 'SKIP',
|
|
322
|
-
reason: \`Command failed: \${error
|
|
322
|
+
reason: \`Command failed: \${error instanceof Error ? error.message : 'Unknown'}\`,
|
|
323
323
|
};
|
|
324
324
|
}
|
|
325
325
|
};
|
|
@@ -101,11 +101,11 @@ command: <%= commands.map(c => pascalCase(c.type)).join(' | ') %>
|
|
|
101
101
|
? ` // TODO: add ${resultVarName} as a parameter to decide once implemented above\n decide(command, state, /* ${resultVarName} */)`
|
|
102
102
|
: ` decide(command, state)` %>
|
|
103
103
|
);
|
|
104
|
-
return; // success
|
|
105
|
-
} catch (error:
|
|
104
|
+
return undefined; // success
|
|
105
|
+
} catch (error: unknown) {
|
|
106
106
|
return {
|
|
107
107
|
type: 'SKIP',
|
|
108
|
-
reason: `Command failed: ${error
|
|
108
|
+
reason: `Command failed: ${error instanceof Error ? error.message : 'Unknown'}`,
|
|
109
109
|
};
|
|
110
110
|
}
|
|
111
111
|
};
|