@auto-engineer/server-generator-apollo-emmett 0.8.14 → 0.9.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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +20 -0
- package/dist/src/codegen/extract/data-sink.d.ts.map +1 -1
- package/dist/src/codegen/extract/data-sink.js +4 -0
- package/dist/src/codegen/extract/data-sink.js.map +1 -1
- package/dist/src/codegen/extract/gwt.d.ts.map +1 -1
- package/dist/src/codegen/extract/gwt.js +2 -0
- package/dist/src/codegen/extract/gwt.js.map +1 -1
- package/dist/src/codegen/extract/projection.d.ts.map +1 -1
- package/dist/src/codegen/extract/projection.js +2 -0
- package/dist/src/codegen/extract/projection.js.map +1 -1
- package/dist/src/codegen/extract/query.js +1 -1
- package/dist/src/codegen/extract/query.js.map +1 -1
- package/dist/src/codegen/extract/states.d.ts.map +1 -1
- package/dist/src/codegen/extract/states.js +5 -2
- package/dist/src/codegen/extract/states.js.map +1 -1
- package/dist/src/codegen/scaffoldFromSchema.d.ts.map +1 -1
- package/dist/src/codegen/scaffoldFromSchema.js +22 -11
- package/dist/src/codegen/scaffoldFromSchema.js.map +1 -1
- package/dist/src/codegen/scaffoldFromSchema.query-slice-register.specs.d.ts +2 -0
- package/dist/src/codegen/scaffoldFromSchema.query-slice-register.specs.d.ts.map +1 -0
- package/dist/src/codegen/scaffoldFromSchema.query-slice-register.specs.js +168 -0
- package/dist/src/codegen/scaffoldFromSchema.query-slice-register.specs.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/codegen/extract/data-sink.ts +2 -0
- package/src/codegen/extract/gwt.ts +3 -2
- package/src/codegen/extract/projection.ts +1 -0
- package/src/codegen/extract/query.ts +1 -1
- package/src/codegen/extract/states.ts +6 -2
- package/src/codegen/scaffoldFromSchema.query-slice-register.specs.ts +179 -0
- package/src/codegen/scaffoldFromSchema.ts +33 -14
- package/.turbo/turbo-format.log +0 -4
- package/.turbo/turbo-lint.log +0 -4
- package/.turbo/turbo-test.log +0 -14
- package/.turbo/turbo-type-check.log +0 -4
package/package.json
CHANGED
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"graphql-type-json": "^0.3.2",
|
|
29
29
|
"uuid": "^10.0.0",
|
|
30
30
|
"web-streams-polyfill": "^4.1.0",
|
|
31
|
-
"@auto-engineer/
|
|
32
|
-
"@auto-engineer/
|
|
31
|
+
"@auto-engineer/message-bus": "0.9.1",
|
|
32
|
+
"@auto-engineer/flow": "0.9.1"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public"
|
|
@@ -37,9 +37,9 @@
|
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/ejs": "^3.1.5",
|
|
39
39
|
"@types/fs-extra": "^11.0.4",
|
|
40
|
-
"@auto-engineer/cli": "0.
|
|
40
|
+
"@auto-engineer/cli": "0.9.1"
|
|
41
41
|
},
|
|
42
|
-
"version": "0.
|
|
42
|
+
"version": "0.9.1",
|
|
43
43
|
"scripts": {
|
|
44
44
|
"generate:server": "tsx src/cli/index.ts",
|
|
45
45
|
"build": "tsc && tsx ../../scripts/fix-esm-imports.ts && rm -rf dist/src/codegen/templates && mkdir -p dist/src/codegen && cp -r src/codegen/templates dist/src/codegen/templates && cp src/server.ts dist/src && cp -r src/utils dist/src && cp -r src/domain dist/src",
|
|
@@ -50,6 +50,7 @@ function extractExampleDataFromSpecs(
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
function extractGwtSpecs(slice: Slice) {
|
|
53
|
+
if (!('server' in slice)) return [];
|
|
53
54
|
const specs = slice.server?.specs;
|
|
54
55
|
const rules = specs?.rules;
|
|
55
56
|
return Array.isArray(rules) && rules.length > 0
|
|
@@ -89,6 +90,7 @@ function processStreamSink(item: unknown, exampleData: Record<string, unknown>)
|
|
|
89
90
|
}
|
|
90
91
|
|
|
91
92
|
export function getStreamFromSink(slice: Slice): { streamPattern?: string; streamId?: string } {
|
|
93
|
+
if (!('server' in slice)) return {};
|
|
92
94
|
const gwtSpecs = extractGwtSpecs(slice);
|
|
93
95
|
const exampleData = extractExampleDataFromSpecs(slice, gwtSpecs);
|
|
94
96
|
const serverData = slice.server?.data;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Slice, CommandExample, EventExample, StateExample } from '@auto-engineer/flow';
|
|
1
|
+
import { Slice, CommandExample, EventExample, StateExample, Example } from '@auto-engineer/flow';
|
|
2
2
|
import { GwtCondition } from '../types';
|
|
3
3
|
|
|
4
4
|
export function buildCommandGwtMapping(slice: Slice): Record<string, (GwtCondition & { failingFields?: string[] })[]> {
|
|
@@ -12,11 +12,12 @@ export function buildCommandGwtMapping(slice: Slice): Record<string, (GwtConditi
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
function extractGwtSpecs(slice: Slice) {
|
|
15
|
+
if (!('server' in slice)) return [];
|
|
15
16
|
const specs = slice.server?.specs;
|
|
16
17
|
const rules = specs?.rules;
|
|
17
18
|
return Array.isArray(rules) && rules.length > 0
|
|
18
19
|
? rules.flatMap((rule) =>
|
|
19
|
-
rule.examples.map((example) => ({
|
|
20
|
+
rule.examples.map((example: Example) => ({
|
|
20
21
|
given: example.given,
|
|
21
22
|
when: example.when,
|
|
22
23
|
then: example.then,
|
|
@@ -24,6 +24,7 @@ function isProjectionOrigin(origin: unknown): origin is ProjectionOrigin {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
function extractProjectionField<K extends keyof ProjectionOrigin>(slice: Slice, fieldName: K): string | undefined {
|
|
27
|
+
if (!('server' in slice)) return undefined;
|
|
27
28
|
const dataSource = slice.server?.data?.[0];
|
|
28
29
|
if (!hasOrigin(dataSource)) return undefined;
|
|
29
30
|
|
|
@@ -23,7 +23,7 @@ export function buildQueryGwtMapping(slice: Slice): QueryGwtCondition[] {
|
|
|
23
23
|
: [];
|
|
24
24
|
|
|
25
25
|
return gwtSpecs.map((gwt) => ({
|
|
26
|
-
given: gwt.given,
|
|
26
|
+
given: gwt.given.filter((item): item is EventExample => 'eventRef' in item),
|
|
27
27
|
then: gwt.then.filter(
|
|
28
28
|
(item): item is { stateRef: string; exampleData: Record<string, unknown> } => 'stateRef' in item,
|
|
29
29
|
),
|
|
@@ -10,14 +10,18 @@ function createStateMessage(stateName: string, allMessages: MessageDefinition[])
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export function extractStatesFromTarget(slice: Slice, allMessages: MessageDefinition[]): Message[] {
|
|
13
|
-
|
|
13
|
+
if (!('server' in slice) || !slice.server?.data) {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const targets = slice.server.data.map((d) => d.target?.name).filter((name): name is string => Boolean(name));
|
|
14
18
|
const uniqueTargets = Array.from(new Set(targets));
|
|
15
19
|
|
|
16
20
|
return uniqueTargets.map((name) => createStateMessage(name, allMessages));
|
|
17
21
|
}
|
|
18
22
|
|
|
19
23
|
export function extractStatesFromData(slice: Slice, allMessages: MessageDefinition[]): Message[] {
|
|
20
|
-
if (!slice.server?.data) {
|
|
24
|
+
if (!('server' in slice) || !slice.server?.data) {
|
|
21
25
|
return [];
|
|
22
26
|
}
|
|
23
27
|
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { generateScaffoldFilePlans } from './scaffoldFromSchema';
|
|
3
|
+
import type { Model } from '@auto-engineer/flow';
|
|
4
|
+
|
|
5
|
+
describe('Query slice register file generation', () => {
|
|
6
|
+
it('should not generate register.ts for query slices with data projections', async () => {
|
|
7
|
+
// Create a minimal model with a query slice that has data projections
|
|
8
|
+
const model: Model = {
|
|
9
|
+
variant: 'specs',
|
|
10
|
+
messages: [], // Empty messages array to avoid undefined error
|
|
11
|
+
flows: [
|
|
12
|
+
{
|
|
13
|
+
id: 'flow-1',
|
|
14
|
+
name: 'Questionnaire Flow',
|
|
15
|
+
slices: [
|
|
16
|
+
{
|
|
17
|
+
id: 'AUTO-V7n8Rq5M',
|
|
18
|
+
type: 'query',
|
|
19
|
+
name: 'views the questionnaire',
|
|
20
|
+
client: {
|
|
21
|
+
description: 'Client for viewing questionnaire',
|
|
22
|
+
},
|
|
23
|
+
server: {
|
|
24
|
+
description: 'Views questionnaire progress',
|
|
25
|
+
specs: {
|
|
26
|
+
name: 'questionnaire progress specs',
|
|
27
|
+
rules: [
|
|
28
|
+
{
|
|
29
|
+
id: 'AUTO-r1A3Bp9W',
|
|
30
|
+
description: 'questionnaires show current progress',
|
|
31
|
+
examples: [
|
|
32
|
+
{
|
|
33
|
+
description: 'a question has already been answered',
|
|
34
|
+
given: [
|
|
35
|
+
{
|
|
36
|
+
eventRef: 'QuestionnaireLinkSent',
|
|
37
|
+
exampleData: {
|
|
38
|
+
questionnaireId: 'q-001',
|
|
39
|
+
participantId: 'participant-abc',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
when: {
|
|
44
|
+
eventRef: 'ViewQuestionnaire',
|
|
45
|
+
exampleData: { questionnaireId: 'q-001' },
|
|
46
|
+
},
|
|
47
|
+
then: [
|
|
48
|
+
{
|
|
49
|
+
stateRef: 'QuestionnaireProgress',
|
|
50
|
+
exampleData: {
|
|
51
|
+
questionnaireId: 'q-001',
|
|
52
|
+
participantId: 'participant-abc',
|
|
53
|
+
status: 'in_progress',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
data: [
|
|
63
|
+
{
|
|
64
|
+
target: {
|
|
65
|
+
type: 'State',
|
|
66
|
+
name: 'QuestionnaireProgress',
|
|
67
|
+
},
|
|
68
|
+
origin: {
|
|
69
|
+
type: 'projection',
|
|
70
|
+
name: 'Questionnaires',
|
|
71
|
+
idField: 'questionnaireId',
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// Generate scaffold plans for the model
|
|
83
|
+
const plans = await generateScaffoldFilePlans(model.flows, model.messages, model.integrations, '/tmp/test');
|
|
84
|
+
|
|
85
|
+
// Extract just the filenames from the generated files
|
|
86
|
+
const generatedFileNames = plans.map((plan) => {
|
|
87
|
+
const parts = plan.outputPath.split('/');
|
|
88
|
+
return parts[parts.length - 1];
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// Query slices should NOT generate register.ts files
|
|
92
|
+
expect(generatedFileNames).not.toContain('register.ts');
|
|
93
|
+
|
|
94
|
+
// Query slices should generate projection-related files
|
|
95
|
+
expect(generatedFileNames).toContain('projection.ts');
|
|
96
|
+
expect(generatedFileNames).toContain('query.resolver.ts');
|
|
97
|
+
|
|
98
|
+
// Query slices should NOT generate command-related files
|
|
99
|
+
expect(generatedFileNames).not.toContain('commands.ts');
|
|
100
|
+
expect(generatedFileNames).not.toContain('handle.ts');
|
|
101
|
+
expect(generatedFileNames).not.toContain('decide.ts');
|
|
102
|
+
expect(generatedFileNames).not.toContain('mutation.resolver.ts');
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('should generate register.ts for command slices', async () => {
|
|
106
|
+
// Create a minimal model with a command slice
|
|
107
|
+
const model: Model = {
|
|
108
|
+
variant: 'specs',
|
|
109
|
+
messages: [], // Empty messages array to avoid undefined error
|
|
110
|
+
flows: [
|
|
111
|
+
{
|
|
112
|
+
id: 'flow-2',
|
|
113
|
+
name: 'Command Flow',
|
|
114
|
+
slices: [
|
|
115
|
+
{
|
|
116
|
+
id: 'AUTO-CMD123',
|
|
117
|
+
type: 'command',
|
|
118
|
+
name: 'submit answer',
|
|
119
|
+
client: {
|
|
120
|
+
description: 'Submit answer client',
|
|
121
|
+
},
|
|
122
|
+
server: {
|
|
123
|
+
description: 'Submits an answer',
|
|
124
|
+
specs: {
|
|
125
|
+
name: 'submit answer specs',
|
|
126
|
+
rules: [
|
|
127
|
+
{
|
|
128
|
+
id: 'AUTO-rule123',
|
|
129
|
+
description: 'should accept valid answers',
|
|
130
|
+
examples: [
|
|
131
|
+
{
|
|
132
|
+
description: 'valid answer submission',
|
|
133
|
+
when: {
|
|
134
|
+
commandRef: 'AnswerQuestion',
|
|
135
|
+
exampleData: {
|
|
136
|
+
questionnaireId: 'q-001',
|
|
137
|
+
answer: 'Yes',
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
then: [
|
|
141
|
+
{
|
|
142
|
+
eventRef: 'QuestionAnswered',
|
|
143
|
+
exampleData: {
|
|
144
|
+
questionnaireId: 'q-001',
|
|
145
|
+
answer: 'Yes',
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
],
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
// Generate scaffold plans for the model
|
|
162
|
+
const plans = await generateScaffoldFilePlans(model.flows, model.messages, model.integrations, '/tmp/test');
|
|
163
|
+
|
|
164
|
+
// Extract just the filenames from the generated files
|
|
165
|
+
const generatedFileNames = plans.map((plan) => {
|
|
166
|
+
const parts = plan.outputPath.split('/');
|
|
167
|
+
return parts[parts.length - 1];
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// Command slices SHOULD generate register.ts files
|
|
171
|
+
expect(generatedFileNames).toContain('register.ts');
|
|
172
|
+
|
|
173
|
+
// Command slices should generate command-related files
|
|
174
|
+
expect(generatedFileNames).toContain('commands.ts');
|
|
175
|
+
expect(generatedFileNames).toContain('handle.ts');
|
|
176
|
+
expect(generatedFileNames).toContain('decide.ts');
|
|
177
|
+
expect(generatedFileNames).toContain('mutation.resolver.ts');
|
|
178
|
+
});
|
|
179
|
+
});
|
|
@@ -22,6 +22,21 @@ import {
|
|
|
22
22
|
extractMessagesFromSpecs,
|
|
23
23
|
extractProjectionName,
|
|
24
24
|
} from './extract';
|
|
25
|
+
|
|
26
|
+
function extractGwtSpecs(slice: Slice) {
|
|
27
|
+
if (!('server' in slice)) return [];
|
|
28
|
+
const specs = slice.server?.specs;
|
|
29
|
+
const rules = specs?.rules;
|
|
30
|
+
return Array.isArray(rules) && rules.length > 0
|
|
31
|
+
? rules.flatMap((rule) =>
|
|
32
|
+
rule.examples.map((example) => ({
|
|
33
|
+
given: example.given,
|
|
34
|
+
when: example.when,
|
|
35
|
+
then: example.then,
|
|
36
|
+
})),
|
|
37
|
+
)
|
|
38
|
+
: [];
|
|
39
|
+
}
|
|
25
40
|
import { Message, MessageDefinition, GwtCondition } from './types';
|
|
26
41
|
import { parseGraphQlRequest } from './extract/graphql';
|
|
27
42
|
import { getStreamFromSink } from './extract/data-sink';
|
|
@@ -298,30 +313,34 @@ function annotateEventSources(
|
|
|
298
313
|
}
|
|
299
314
|
}
|
|
300
315
|
|
|
316
|
+
function hasEventInGwtSpecs(gwtSpecs: ReturnType<typeof extractGwtSpecs>, eventType: string): boolean {
|
|
317
|
+
return gwtSpecs.some((g) =>
|
|
318
|
+
g.then.some(
|
|
319
|
+
(t) =>
|
|
320
|
+
typeof t === 'object' && t !== null && 'eventRef' in t && (t as { eventRef: string }).eventRef === eventType,
|
|
321
|
+
),
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function canSliceProduceEvent(slice: Slice): boolean {
|
|
326
|
+
return ['command', 'react'].includes(slice.type) && 'server' in slice && Boolean(slice.server?.specs);
|
|
327
|
+
}
|
|
328
|
+
|
|
301
329
|
function findEventSource(flows: Flow[], eventType: string): { flowName: string; sliceName: string } | null {
|
|
302
330
|
debugSlice('Finding source for event: %s', eventType);
|
|
331
|
+
|
|
303
332
|
for (const flow of flows) {
|
|
304
333
|
for (const slice of flow.slices) {
|
|
305
|
-
if (!
|
|
334
|
+
if (!canSliceProduceEvent(slice)) continue;
|
|
306
335
|
|
|
307
|
-
const
|
|
308
|
-
|
|
309
|
-
const gwtSpecs =
|
|
310
|
-
Array.isArray(rules) && rules.length > 0
|
|
311
|
-
? rules.flatMap((rule) =>
|
|
312
|
-
rule.examples.map((example) => ({
|
|
313
|
-
given: example.given,
|
|
314
|
-
when: example.when,
|
|
315
|
-
then: example.then,
|
|
316
|
-
})),
|
|
317
|
-
)
|
|
318
|
-
: [];
|
|
319
|
-
if (gwtSpecs.some((g) => g.then.some((t) => 'eventRef' in t && t.eventRef === eventType))) {
|
|
336
|
+
const gwtSpecs = extractGwtSpecs(slice);
|
|
337
|
+
if (hasEventInGwtSpecs(gwtSpecs, eventType)) {
|
|
320
338
|
debugSlice(' Found event source in flow: %s, slice: %s', flow.name, slice.name);
|
|
321
339
|
return { flowName: flow.name, sliceName: slice.name };
|
|
322
340
|
}
|
|
323
341
|
}
|
|
324
342
|
}
|
|
343
|
+
|
|
325
344
|
debugSlice(' No source found for event: %s', eventType);
|
|
326
345
|
return null;
|
|
327
346
|
}
|
package/.turbo/turbo-format.log
DELETED
package/.turbo/turbo-lint.log
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
> @auto-engineer/server-generator-apollo-emmett@0.8.13 lint /Users/sam/WebstormProjects/top/auto-engineer/packages/server-generator-apollo-emmett
|
|
3
|
-
> eslint 'src/**/*.ts' --ignore-pattern '**/*.specs.ts' --ignore-pattern '**/.tmp/**' --max-warnings 0 --config ../../eslint.config.ts
|
|
4
|
-
|
package/.turbo/turbo-test.log
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
> @auto-engineer/server-generator-apollo-emmett@0.8.14 test /Users/sam/WebstormProjects/top/auto-engineer/packages/server-generator-apollo-emmett
|
|
3
|
-
> vitest run --reporter=dot
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
RUN v3.2.4 /Users/sam/WebstormProjects/top/auto-engineer/packages/server-generator-apollo-emmett
|
|
7
|
-
|
|
8
|
-
·························-
|
|
9
|
-
|
|
10
|
-
Test Files 15 passed | 1 skipped (16)
|
|
11
|
-
Tests 25 passed | 1 skipped (26)
|
|
12
|
-
Start at 18:28:14
|
|
13
|
-
Duration 1.66s (transform 406ms, setup 0ms, collect 4.50s, tests 3.69s, environment 1ms, prepare 2.77s)
|
|
14
|
-
|