@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.
Files changed (104) hide show
  1. package/.turbo/turbo-build.log +6 -0
  2. package/.turbo/turbo-format.log +5 -0
  3. package/.turbo/turbo-lint.log +4 -0
  4. package/.turbo/turbo-test.log +22 -0
  5. package/.turbo/turbo-type-check.log +5 -0
  6. package/CHANGELOG.md +20 -0
  7. package/dist/src/codegen/extract/events.d.ts +2 -2
  8. package/dist/src/codegen/extract/events.d.ts.map +1 -1
  9. package/dist/src/codegen/extract/events.js +16 -6
  10. package/dist/src/codegen/extract/events.js.map +1 -1
  11. package/dist/src/codegen/extract/gwt.js +7 -22
  12. package/dist/src/codegen/extract/gwt.js.map +1 -1
  13. package/dist/src/codegen/extract/imports.d.ts +29 -0
  14. package/dist/src/codegen/extract/imports.d.ts.map +1 -0
  15. package/dist/src/codegen/extract/imports.js +55 -0
  16. package/dist/src/codegen/extract/imports.js.map +1 -0
  17. package/dist/src/codegen/extract/index.d.ts +1 -0
  18. package/dist/src/codegen/extract/index.d.ts.map +1 -1
  19. package/dist/src/codegen/extract/index.js +1 -0
  20. package/dist/src/codegen/extract/index.js.map +1 -1
  21. package/dist/src/codegen/extract/messages.d.ts.map +1 -1
  22. package/dist/src/codegen/extract/messages.js +33 -7
  23. package/dist/src/codegen/extract/messages.js.map +1 -1
  24. package/dist/src/codegen/extract/query.d.ts +3 -1
  25. package/dist/src/codegen/extract/query.d.ts.map +1 -1
  26. package/dist/src/codegen/extract/query.js +12 -12
  27. package/dist/src/codegen/extract/query.js.map +1 -1
  28. package/dist/src/codegen/scaffoldFromSchema.d.ts.map +1 -1
  29. package/dist/src/codegen/scaffoldFromSchema.js +9 -1
  30. package/dist/src/codegen/scaffoldFromSchema.js.map +1 -1
  31. package/dist/src/codegen/templates/command/decide.specs.specs.ts +235 -8
  32. package/dist/src/codegen/templates/command/decide.specs.ts +8 -8
  33. package/dist/src/codegen/templates/command/decide.specs.ts.ejs +95 -30
  34. package/dist/src/codegen/templates/command/decide.ts.ejs +2 -2
  35. package/dist/src/codegen/templates/command/events.ts.ejs +2 -2
  36. package/dist/src/codegen/templates/command/evolve.ts.ejs +3 -3
  37. package/dist/src/codegen/templates/command/handle.specs.ts +6 -6
  38. package/dist/src/codegen/templates/command/handle.ts.ejs +3 -3
  39. package/dist/src/codegen/templates/query/projection.specs.specs.ts +623 -0
  40. package/dist/src/codegen/templates/query/projection.specs.ts +1 -1
  41. package/dist/src/codegen/templates/query/projection.specs.ts.ejs +176 -52
  42. package/dist/src/codegen/templates/query/projection.ts.ejs +30 -29
  43. package/dist/src/codegen/templates/query/query.resolver.specs.ts +190 -5
  44. package/dist/src/codegen/templates/query/query.resolver.ts.ejs +31 -9
  45. package/dist/src/codegen/templates/react/react.specs.specs.ts +8 -5
  46. package/dist/src/codegen/templates/react/react.specs.ts +4 -4
  47. package/dist/src/codegen/templates/react/react.specs.ts.ejs +118 -67
  48. package/dist/src/codegen/templates/react/react.ts.ejs +4 -4
  49. package/dist/src/codegen/templates/react/register.specs.ts +2 -2
  50. package/dist/src/codegen/templates/react/register.ts.ejs +2 -2
  51. package/dist/src/codegen/types.d.ts +2 -0
  52. package/dist/src/codegen/types.d.ts.map +1 -1
  53. package/dist/src/commands/generate-server.d.ts.map +1 -1
  54. package/dist/src/commands/generate-server.js +3 -0
  55. package/dist/src/commands/generate-server.js.map +1 -1
  56. package/dist/src/domain/shared/ReadModel.d.ts +2 -2
  57. package/dist/src/domain/shared/ReadModel.d.ts.map +1 -1
  58. package/dist/src/domain/shared/ReadModel.js +2 -2
  59. package/dist/src/domain/shared/ReadModel.js.map +1 -1
  60. package/dist/src/domain/shared/ReadModel.ts +3 -3
  61. package/dist/src/domain/shared/types.d.ts +5 -3
  62. package/dist/src/domain/shared/types.d.ts.map +1 -1
  63. package/dist/src/domain/shared/types.js.map +1 -1
  64. package/dist/src/domain/shared/types.ts +5 -3
  65. package/dist/src/server.js +54 -7
  66. package/dist/src/server.js.map +1 -1
  67. package/dist/src/server.ts +53 -15
  68. package/dist/tsconfig.tsbuildinfo +1 -1
  69. package/package.json +8 -5
  70. package/src/codegen/extract/events.ts +20 -3
  71. package/src/codegen/extract/gwt.ts +10 -26
  72. package/src/codegen/extract/imports.ts +71 -0
  73. package/src/codegen/extract/index.ts +1 -0
  74. package/src/codegen/extract/messages.ts +34 -7
  75. package/src/codegen/extract/query.ts +17 -19
  76. package/src/codegen/scaffoldFromSchema.ts +13 -0
  77. package/src/codegen/templates/command/decide.specs.specs.ts +235 -8
  78. package/src/codegen/templates/command/decide.specs.ts +8 -8
  79. package/src/codegen/templates/command/decide.specs.ts.ejs +95 -30
  80. package/src/codegen/templates/command/decide.ts.ejs +2 -2
  81. package/src/codegen/templates/command/events.ts.ejs +2 -2
  82. package/src/codegen/templates/command/evolve.ts.ejs +3 -3
  83. package/src/codegen/templates/command/handle.specs.ts +6 -6
  84. package/src/codegen/templates/command/handle.ts.ejs +3 -3
  85. package/src/codegen/templates/query/projection.specs.specs.ts +623 -0
  86. package/src/codegen/templates/query/projection.specs.ts +1 -1
  87. package/src/codegen/templates/query/projection.specs.ts.ejs +176 -52
  88. package/src/codegen/templates/query/projection.ts.ejs +30 -29
  89. package/src/codegen/templates/query/query.resolver.specs.ts +190 -5
  90. package/src/codegen/templates/query/query.resolver.ts.ejs +31 -9
  91. package/src/codegen/templates/react/react.specs.specs.ts +8 -5
  92. package/src/codegen/templates/react/react.specs.ts +4 -4
  93. package/src/codegen/templates/react/react.specs.ts.ejs +118 -67
  94. package/src/codegen/templates/react/react.ts.ejs +4 -4
  95. package/src/codegen/templates/react/register.specs.ts +2 -2
  96. package/src/codegen/templates/react/register.ts.ejs +2 -2
  97. package/src/codegen/types.ts +2 -0
  98. package/src/commands/generate-server.ts +3 -0
  99. package/src/domain/shared/ReadModel.ts +3 -3
  100. package/src/domain/shared/types.ts +5 -3
  101. package/src/server.ts +53 -15
  102. package/dist/src/codegen/templates/query/projection.specs.specs..ts +0 -296
  103. package/src/codegen/scaffoldFromSchema.query-slice-register.specs.ts +0 -179
  104. package/src/codegen/templates/query/projection.specs.specs..ts +0 -296
@@ -1,296 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { generateScaffoldFilePlans } from '../../scaffoldFromSchema';
3
- import { Model as SpecsSchema } from '@auto-engineer/flow';
4
-
5
- describe('projection.specs.ts.ejs', () => {
6
- it('should generate a valid test spec for a query slice projection', async () => {
7
- const spec: SpecsSchema = {
8
- variant: 'specs',
9
- flows: [
10
- {
11
- name: 'listing-flow',
12
- slices: [
13
- {
14
- type: 'command',
15
- name: 'CreateListing',
16
- stream: 'listing-${propertyId}',
17
- client: { description: '' },
18
- server: {
19
- description: '',
20
- specs: {
21
- name: 'CreateListing command',
22
- rules: [
23
- {
24
- description: 'Should handle listing operations',
25
- examples: [
26
- {
27
- description: 'User creates listing successfully',
28
- when: {
29
- commandRef: 'CreateListing',
30
- exampleData: {
31
- propertyId: 'listing_123',
32
- title: 'Sea View Flat',
33
- pricePerNight: 120,
34
- location: 'Brighton',
35
- maxGuests: 4,
36
- },
37
- },
38
- then: [
39
- {
40
- eventRef: 'ListingCreated',
41
- exampleData: {
42
- propertyId: 'listing_123',
43
- title: 'Sea View Flat',
44
- pricePerNight: 120,
45
- location: 'Brighton',
46
- maxGuests: 4,
47
- },
48
- },
49
- ],
50
- },
51
- {
52
- description: 'User removes listing successfully',
53
- when: {
54
- commandRef: 'RemoveListing',
55
- exampleData: {
56
- propertyId: 'listing_123',
57
- },
58
- },
59
- then: [
60
- {
61
- eventRef: 'ListingRemoved',
62
- exampleData: {},
63
- },
64
- ],
65
- },
66
- ],
67
- },
68
- ],
69
- },
70
- },
71
- },
72
- {
73
- type: 'query',
74
- name: 'search-listings',
75
- stream: 'listings',
76
- client: { description: '' },
77
- server: {
78
- description: '',
79
- data: [
80
- {
81
- origin: {
82
- type: 'projection',
83
- idField: 'propertyId',
84
- name: 'AvailablePropertiesProjection',
85
- },
86
- target: {
87
- type: 'State',
88
- name: 'AvailableListings',
89
- },
90
- },
91
- ],
92
- specs: {
93
- name: 'Search listings query',
94
- rules: [
95
- {
96
- description: 'Should project listings correctly',
97
- examples: [
98
- {
99
- description: 'Listing created shows in search results',
100
- when: [
101
- {
102
- eventRef: 'ListingCreated',
103
- exampleData: {
104
- propertyId: 'listing_123',
105
- title: 'Sea View Flat',
106
- pricePerNight: 120,
107
- location: 'Brighton',
108
- maxGuests: 4,
109
- },
110
- },
111
- ],
112
- then: [
113
- {
114
- stateRef: 'AvailableListings',
115
- exampleData: {
116
- propertyId: 'listing_123',
117
- title: 'Sea View Flat',
118
- pricePerNight: 120,
119
- location: 'Brighton',
120
- maxGuests: 4,
121
- },
122
- },
123
- ],
124
- },
125
- {
126
- description: 'Listing removed disappears from search results',
127
- when: [
128
- {
129
- eventRef: 'ListingRemoved',
130
- exampleData: {
131
- propertyId: 'listing_123',
132
- },
133
- },
134
- ],
135
- then: [
136
- {
137
- stateRef: 'AvailableListings',
138
- exampleData: {},
139
- },
140
- ],
141
- },
142
- ],
143
- },
144
- ],
145
- },
146
- },
147
- },
148
- ],
149
- },
150
- ],
151
- messages: [
152
- {
153
- type: 'command',
154
- name: 'CreateListing',
155
- fields: [
156
- { name: 'propertyId', type: 'string', required: true },
157
- { name: 'title', type: 'string', required: true },
158
- { name: 'pricePerNight', type: 'number', required: true },
159
- { name: 'location', type: 'string', required: true },
160
- { name: 'maxGuests', type: 'number', required: true },
161
- ],
162
- },
163
- {
164
- type: 'command',
165
- name: 'RemoveListing',
166
- fields: [{ name: 'propertyId', type: 'string', required: true }],
167
- },
168
- {
169
- type: 'event',
170
- name: 'ListingCreated',
171
- source: 'internal',
172
- fields: [
173
- { name: 'propertyId', type: 'string', required: true },
174
- { name: 'title', type: 'string', required: true },
175
- { name: 'pricePerNight', type: 'number', required: true },
176
- { name: 'location', type: 'string', required: true },
177
- { name: 'maxGuests', type: 'number', required: true },
178
- ],
179
- },
180
- {
181
- type: 'event',
182
- name: 'ListingRemoved',
183
- source: 'internal',
184
- fields: [{ name: 'propertyId', type: 'string', required: true }],
185
- },
186
- {
187
- type: 'state',
188
- name: 'AvailableListings',
189
- fields: [
190
- { name: 'propertyId', type: 'string', required: true },
191
- { name: 'title', type: 'string', required: true },
192
- { name: 'pricePerNight', type: 'number', required: true },
193
- { name: 'location', type: 'string', required: true },
194
- { name: 'maxGuests', type: 'number', required: true },
195
- ],
196
- },
197
- ],
198
- };
199
-
200
- const plans = await generateScaffoldFilePlans(spec.flows, spec.messages, undefined, 'src/domain/flows');
201
- const specFile = plans.find((p) => p.outputPath.endsWith('projection.spec.ts'));
202
-
203
- expect(specFile?.contents).toMatchInlineSnapshot(`
204
- "import { describe, it, beforeEach, expect } from 'vitest';
205
- import { v4 as uuid } from 'uuid';
206
- import {
207
- InMemoryProjectionSpec,
208
- eventsInStream,
209
- newEventsInStream
210
- } from '@event-driven-io/emmett';
211
- import { projection } from './projection';
212
-
213
- import type { ListingCreated, ListingRemoved } from '../create-listing/events';
214
- import type { AvailableListings } from './state';
215
-
216
- type AllEvents = ListingCreated | ListingRemoved;
217
-
218
- describe('AvailableListings projection', () => {
219
- let given: InMemoryProjectionSpec<AllEvents>;
220
- let propertyId: string;
221
-
222
- beforeEach(() => {
223
- propertyId = \`listing-\${uuid()}\`;
224
- given = InMemoryProjectionSpec.for({ projection });
225
- });
226
-
227
- it('handles ListingCreated', () =>
228
- given([])
229
- .when([
230
- {
231
- type: 'ListingCreated',
232
- data: {
233
- propertyId,
234
- title: 'Sea View Flat',
235
- pricePerNight: 120,
236
- location: 'Brighton',
237
- maxGuests: 4
238
- },
239
- metadata: {
240
- streamName: propertyId,
241
- streamPosition: 1n,
242
- globalPosition: 1n
243
- }
244
- }
245
- ])
246
- .then(async (state) => {
247
- const document = await state.database
248
- .collection<AvailableListings>('available-properties-projection')
249
- .findOne((doc) => doc.propertyId === propertyId);
250
-
251
- const expected: AvailableListings = {
252
- propertyId,
253
- title: 'Sea View Flat',
254
- pricePerNight: 120,
255
- location: 'Brighton',
256
- maxGuests: 4
257
- };
258
-
259
- expect(document).toMatchObject(expected);
260
- }));
261
-
262
- it('handles ListingRemoved', () =>
263
- given(
264
- eventsInStream(propertyId, [
265
- {
266
- type: 'ListingCreated',
267
- data: {
268
- propertyId,
269
- title: 'Sea View Flat',
270
- pricePerNight: 120,
271
- location: 'Brighton',
272
- maxGuests: 4
273
- }
274
- }
275
- ])
276
- )
277
- .when(
278
- newEventsInStream(propertyId, [
279
- {
280
- type: 'ListingRemoved',
281
- data: {
282
- propertyId
283
- }
284
- }
285
- ])
286
- )
287
- .then(async (state) => {
288
- const document = await state.database
289
- .collection<AvailableListings>('available-properties-projection')
290
- .findOne((doc) => doc.propertyId === propertyId);
291
- expect(document).toBeNull();
292
- }));
293
- });
294
- `);
295
- });
296
- });
@@ -1,179 +0,0 @@
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
- });