@auto-engineer/server-generator-apollo-emmett 0.10.3 → 0.10.5

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 (70) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/src/codegen/extract/events.d.ts +2 -2
  3. package/dist/src/codegen/extract/events.d.ts.map +1 -1
  4. package/dist/src/codegen/extract/events.js +16 -6
  5. package/dist/src/codegen/extract/events.js.map +1 -1
  6. package/dist/src/codegen/extract/gwt.js +7 -22
  7. package/dist/src/codegen/extract/gwt.js.map +1 -1
  8. package/dist/src/codegen/extract/imports.d.ts +29 -0
  9. package/dist/src/codegen/extract/imports.d.ts.map +1 -0
  10. package/dist/src/codegen/extract/imports.js +55 -0
  11. package/dist/src/codegen/extract/imports.js.map +1 -0
  12. package/dist/src/codegen/extract/index.d.ts +1 -0
  13. package/dist/src/codegen/extract/index.d.ts.map +1 -1
  14. package/dist/src/codegen/extract/index.js +1 -0
  15. package/dist/src/codegen/extract/index.js.map +1 -1
  16. package/dist/src/codegen/extract/messages.d.ts.map +1 -1
  17. package/dist/src/codegen/extract/messages.js +33 -7
  18. package/dist/src/codegen/extract/messages.js.map +1 -1
  19. package/dist/src/codegen/extract/query.d.ts +3 -1
  20. package/dist/src/codegen/extract/query.d.ts.map +1 -1
  21. package/dist/src/codegen/extract/query.js +12 -12
  22. package/dist/src/codegen/extract/query.js.map +1 -1
  23. package/dist/src/codegen/scaffoldFromSchema.d.ts.map +1 -1
  24. package/dist/src/codegen/scaffoldFromSchema.js +9 -1
  25. package/dist/src/codegen/scaffoldFromSchema.js.map +1 -1
  26. package/dist/src/codegen/templates/command/decide.specs.specs.ts +235 -8
  27. package/dist/src/codegen/templates/command/decide.specs.ts +8 -8
  28. package/dist/src/codegen/templates/command/decide.specs.ts.ejs +95 -30
  29. package/dist/src/codegen/templates/command/decide.ts.ejs +2 -2
  30. package/dist/src/codegen/templates/command/events.ts.ejs +2 -2
  31. package/dist/src/codegen/templates/command/evolve.ts.ejs +3 -3
  32. package/dist/src/codegen/templates/command/handle.specs.ts +6 -6
  33. package/dist/src/codegen/templates/command/handle.ts.ejs +3 -3
  34. package/dist/src/codegen/templates/query/projection.specs.specs.ts +623 -0
  35. package/dist/src/codegen/templates/query/projection.specs.ts.ejs +174 -52
  36. package/dist/src/codegen/templates/query/projection.ts.ejs +30 -29
  37. package/dist/src/codegen/templates/react/react.specs.specs.ts +7 -4
  38. package/dist/src/codegen/templates/react/react.specs.ts.ejs +118 -67
  39. package/dist/src/codegen/types.d.ts +2 -0
  40. package/dist/src/codegen/types.d.ts.map +1 -1
  41. package/dist/tsconfig.tsbuildinfo +1 -1
  42. package/package.json +4 -4
  43. package/src/codegen/extract/events.ts +20 -3
  44. package/src/codegen/extract/gwt.ts +10 -26
  45. package/src/codegen/extract/imports.ts +71 -0
  46. package/src/codegen/extract/index.ts +1 -0
  47. package/src/codegen/extract/messages.ts +34 -7
  48. package/src/codegen/extract/query.ts +17 -19
  49. package/src/codegen/scaffoldFromSchema.ts +13 -0
  50. package/src/codegen/templates/command/decide.specs.specs.ts +235 -8
  51. package/src/codegen/templates/command/decide.specs.ts +8 -8
  52. package/src/codegen/templates/command/decide.specs.ts.ejs +95 -30
  53. package/src/codegen/templates/command/decide.ts.ejs +2 -2
  54. package/src/codegen/templates/command/events.ts.ejs +2 -2
  55. package/src/codegen/templates/command/evolve.ts.ejs +3 -3
  56. package/src/codegen/templates/command/handle.specs.ts +6 -6
  57. package/src/codegen/templates/command/handle.ts.ejs +3 -3
  58. package/src/codegen/templates/query/projection.specs.specs.ts +623 -0
  59. package/src/codegen/templates/query/projection.specs.ts.ejs +174 -52
  60. package/src/codegen/templates/query/projection.ts.ejs +30 -29
  61. package/src/codegen/templates/react/react.specs.specs.ts +7 -4
  62. package/src/codegen/templates/react/react.specs.ts.ejs +118 -67
  63. package/src/codegen/types.ts +2 -0
  64. package/dist/src/codegen/scaffoldFromSchema.query-slice-register.specs.d.ts +0 -2
  65. package/dist/src/codegen/scaffoldFromSchema.query-slice-register.specs.d.ts.map +0 -1
  66. package/dist/src/codegen/scaffoldFromSchema.query-slice-register.specs.js +0 -168
  67. package/dist/src/codegen/scaffoldFromSchema.query-slice-register.specs.js.map +0 -1
  68. package/dist/src/codegen/templates/query/projection.specs.specs..ts +0 -296
  69. package/src/codegen/scaffoldFromSchema.query-slice-register.specs.ts +0 -179
  70. 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
- });