@auto-engineer/server-generator-apollo-emmett 1.36.3 → 1.37.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 +1 -1
- package/.turbo/turbo-test.log +6 -6
- package/.turbo/turbo-type-check.log +1 -1
- package/CHANGELOG.md +26 -0
- package/dist/src/codegen/extract/messages.d.ts.map +1 -1
- package/dist/src/codegen/extract/messages.js +29 -3
- package/dist/src/codegen/extract/messages.js.map +1 -1
- package/dist/src/codegen/scaffoldFromSchema.d.ts +4 -0
- package/dist/src/codegen/scaffoldFromSchema.d.ts.map +1 -1
- package/dist/src/codegen/scaffoldFromSchema.js +16 -8
- package/dist/src/codegen/scaffoldFromSchema.js.map +1 -1
- package/dist/src/codegen/templates/query/projection.specs.specs.ts +126 -0
- package/dist/src/codegen/templates/query/projection.specs.ts.ejs +8 -0
- package/dist/src/codegen/templates/react/events.ts.ejs +17 -0
- package/dist/src/codegen/templates/react/react.ts.specs.ts +126 -0
- package/dist/src/codegen/templates/react/register.ts.ejs +3 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/ketchup-plan.md +6 -7
- package/package.json +4 -4
- package/src/codegen/extract/messages.specs.ts +273 -0
- package/src/codegen/extract/messages.ts +33 -3
- package/src/codegen/findEventSource.specs.ts +117 -0
- package/src/codegen/scaffoldFromSchema.ts +16 -8
- package/src/codegen/templates/query/projection.specs.specs.ts +126 -0
- package/src/codegen/templates/query/projection.specs.ts.ejs +8 -0
- package/src/codegen/templates/react/events.ts.ejs +17 -0
- package/src/codegen/templates/react/react.ts.specs.ts +126 -0
- package/src/codegen/templates/react/register.ts.ejs +3 -0
|
@@ -191,4 +191,130 @@ describe('react.ts.ejs', () => {
|
|
|
191
191
|
expect(reactFile?.contents).toContain('// Event (OrderPlaced) fields:');
|
|
192
192
|
expect(reactFile?.contents).toContain('// Command (SendConfirmation) fields:');
|
|
193
193
|
});
|
|
194
|
+
|
|
195
|
+
it('should generate events.ts for react slice with data target events', async () => {
|
|
196
|
+
const spec: SpecsSchema = {
|
|
197
|
+
variant: 'specs',
|
|
198
|
+
narratives: [
|
|
199
|
+
{
|
|
200
|
+
name: 'booking flow',
|
|
201
|
+
slices: [
|
|
202
|
+
{
|
|
203
|
+
type: 'command',
|
|
204
|
+
name: 'book appointment',
|
|
205
|
+
server: {
|
|
206
|
+
description: '',
|
|
207
|
+
specs: [
|
|
208
|
+
{
|
|
209
|
+
type: 'gherkin',
|
|
210
|
+
feature: 'Book appointment',
|
|
211
|
+
rules: [
|
|
212
|
+
{
|
|
213
|
+
name: 'Should book',
|
|
214
|
+
examples: [
|
|
215
|
+
{
|
|
216
|
+
name: 'Appointment booked',
|
|
217
|
+
steps: [
|
|
218
|
+
{ keyword: 'When', text: 'BookAppointment', docString: { appointmentId: 'a1' } },
|
|
219
|
+
{ keyword: 'Then', text: 'AppointmentBooked', docString: { appointmentId: 'a1' } },
|
|
220
|
+
],
|
|
221
|
+
},
|
|
222
|
+
],
|
|
223
|
+
},
|
|
224
|
+
],
|
|
225
|
+
},
|
|
226
|
+
],
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
type: 'react',
|
|
231
|
+
name: 'notify barber of new booking',
|
|
232
|
+
server: {
|
|
233
|
+
description: 'Notifies barber after booking',
|
|
234
|
+
data: {
|
|
235
|
+
items: [
|
|
236
|
+
{
|
|
237
|
+
target: { type: 'Event', name: 'BarberNotified' },
|
|
238
|
+
destination: { type: 'stream', pattern: 'barber-${barberId}' },
|
|
239
|
+
},
|
|
240
|
+
],
|
|
241
|
+
},
|
|
242
|
+
specs: [
|
|
243
|
+
{
|
|
244
|
+
type: 'gherkin',
|
|
245
|
+
feature: 'Notify barber',
|
|
246
|
+
rules: [
|
|
247
|
+
{
|
|
248
|
+
name: 'Should notify',
|
|
249
|
+
examples: [
|
|
250
|
+
{
|
|
251
|
+
name: 'Barber notified',
|
|
252
|
+
steps: [
|
|
253
|
+
{
|
|
254
|
+
keyword: 'When',
|
|
255
|
+
text: 'AppointmentBooked',
|
|
256
|
+
docString: { appointmentId: 'a1' },
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
keyword: 'Then',
|
|
260
|
+
text: 'NotifyBarber',
|
|
261
|
+
docString: { barberId: 'b1' },
|
|
262
|
+
},
|
|
263
|
+
],
|
|
264
|
+
},
|
|
265
|
+
],
|
|
266
|
+
},
|
|
267
|
+
],
|
|
268
|
+
},
|
|
269
|
+
],
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
],
|
|
273
|
+
},
|
|
274
|
+
],
|
|
275
|
+
messages: [
|
|
276
|
+
{
|
|
277
|
+
type: 'command',
|
|
278
|
+
name: 'BookAppointment',
|
|
279
|
+
fields: [{ name: 'appointmentId', type: 'string', required: true }],
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
type: 'event',
|
|
283
|
+
name: 'AppointmentBooked',
|
|
284
|
+
source: 'internal',
|
|
285
|
+
fields: [{ name: 'appointmentId', type: 'string', required: true }],
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
type: 'event',
|
|
289
|
+
name: 'BarberNotified',
|
|
290
|
+
source: 'internal',
|
|
291
|
+
fields: [
|
|
292
|
+
{ name: 'barberId', type: 'string', required: true },
|
|
293
|
+
{ name: 'notifiedAt', type: 'Date', required: true },
|
|
294
|
+
],
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
type: 'command',
|
|
298
|
+
name: 'NotifyBarber',
|
|
299
|
+
fields: [{ name: 'barberId', type: 'string', required: true }],
|
|
300
|
+
},
|
|
301
|
+
],
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
const plans = await generateScaffoldFilePlans(spec.narratives, spec.messages, undefined, 'src/domain/flows');
|
|
305
|
+
const eventsFile = plans.find((p) => p.outputPath.endsWith('notify-barber-of-new-booking/events.ts'));
|
|
306
|
+
|
|
307
|
+
expect(eventsFile?.contents).toMatchInlineSnapshot(`
|
|
308
|
+
"import type { Event } from '@event-driven-io/emmett';
|
|
309
|
+
|
|
310
|
+
export type BarberNotified = Event<
|
|
311
|
+
'BarberNotified',
|
|
312
|
+
{
|
|
313
|
+
barberId: string;
|
|
314
|
+
notifiedAt: Date;
|
|
315
|
+
}
|
|
316
|
+
>;
|
|
317
|
+
"
|
|
318
|
+
`);
|
|
319
|
+
});
|
|
194
320
|
});
|
|
@@ -11,6 +11,9 @@ const then = Array.isArray(gwt?.then) ? gwt.then[0] : gwt?.then;
|
|
|
11
11
|
|
|
12
12
|
const eventType = when?.eventRef;
|
|
13
13
|
const commandType = then?.commandRef;
|
|
14
|
+
if (!eventType) throw new Error(
|
|
15
|
+
`register.ts.ejs: slice "${slice.name}" has no event in .when() — check specs`
|
|
16
|
+
);
|
|
14
17
|
const event = events.find(e => e.type === eventType);
|
|
15
18
|
const isCrossFlow = event?.sourceFlowName && event.sourceFlowName !== flowName;
|
|
16
19
|
const eventImportBase = isCrossFlow
|