@auto-engineer/server-generator-apollo-emmett 0.8.5 → 0.8.7
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 +2 -2
- package/CHANGELOG.md +16 -0
- package/dist/src/codegen/scaffoldFromSchema.d.ts +3 -3
- package/dist/src/codegen/scaffoldFromSchema.d.ts.map +1 -1
- package/dist/src/codegen/scaffoldFromSchema.js +54 -18
- package/dist/src/codegen/scaffoldFromSchema.js.map +1 -1
- package/dist/{codegen → src/codegen}/templates/command/commands.specs.ts +1 -2
- package/dist/{codegen → src/codegen}/templates/command/decide.specs.specs.ts +3 -3
- package/dist/{codegen → src/codegen}/templates/command/decide.specs.ts +1 -5
- package/dist/{codegen → src/codegen}/templates/command/events.specs.ts +1 -2
- package/dist/{codegen → src/codegen}/templates/command/evolve.specs.ts +1 -2
- package/dist/{codegen → src/codegen}/templates/command/handle.specs.ts +1 -3
- package/dist/src/codegen/templates/command/mutation.resolver.specs.ts +363 -0
- package/dist/src/codegen/templates/command/mutation.resolver.ts.ejs +99 -0
- package/dist/{codegen → src/codegen}/templates/command/register.specs.ts +1 -2
- package/dist/{codegen → src/codegen}/templates/command/state.specs.ts +1 -2
- package/dist/{codegen → src/codegen}/templates/query/projection.specs.specs..ts +3 -3
- package/dist/{codegen → src/codegen}/templates/query/projection.specs.ts +5 -9
- package/dist/{codegen → src/codegen}/templates/query/query.resolver.specs.ts +194 -23
- package/dist/src/codegen/templates/query/query.resolver.ts.ejs +137 -0
- package/dist/{codegen → src/codegen}/templates/query/state.specs.ts +1 -2
- package/dist/{codegen → src/codegen}/templates/react/react.specs.specs.ts +2 -2
- package/dist/{codegen → src/codegen}/templates/react/react.specs.ts +3 -3
- package/dist/{codegen → src/codegen}/templates/react/register.specs.ts +3 -3
- package/dist/src/codegen/test-data/specVariant1.d.ts +1 -1
- package/dist/src/codegen/test-data/specVariant1.d.ts.map +1 -1
- package/dist/src/codegen/test-data/specVariant1.js +4 -2
- package/dist/src/codegen/test-data/specVariant1.js.map +1 -1
- package/dist/src/commands/generate-server.d.ts.map +1 -1
- package/dist/src/commands/generate-server.js +34 -24
- package/dist/src/commands/generate-server.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -7
- package/src/codegen/scaffoldFromSchema.ts +52 -20
- package/src/codegen/templates/command/commands.specs.ts +1 -2
- package/src/codegen/templates/command/decide.specs.specs.ts +3 -3
- package/src/codegen/templates/command/decide.specs.ts +1 -5
- package/src/codegen/templates/command/events.specs.ts +1 -2
- package/src/codegen/templates/command/evolve.specs.ts +1 -2
- package/src/codegen/templates/command/handle.specs.ts +1 -3
- package/src/codegen/templates/command/mutation.resolver.specs.ts +247 -8
- package/src/codegen/templates/command/mutation.resolver.ts.ejs +86 -12
- package/src/codegen/templates/command/register.specs.ts +1 -2
- package/src/codegen/templates/command/state.specs.ts +1 -2
- package/src/codegen/templates/query/projection.specs.specs..ts +3 -3
- package/src/codegen/templates/query/projection.specs.ts +5 -9
- package/src/codegen/templates/query/query.resolver.specs.ts +194 -23
- package/src/codegen/templates/query/query.resolver.ts.ejs +84 -45
- package/src/codegen/templates/query/state.specs.ts +1 -2
- package/src/codegen/templates/react/react.specs.specs.ts +2 -2
- package/src/codegen/templates/react/react.specs.ts +3 -3
- package/src/codegen/templates/react/register.specs.ts +3 -3
- package/src/codegen/test-data/specVariant1.ts +5 -3
- package/src/commands/generate-server.ts +38 -30
- package/tsconfig.test.json +9 -0
- package/.turbo/turbo-test.log +0 -14
- package/.turbo/turbo-type-check.log +0 -4
- package/dist/codegen/templates/command/mutation.resolver.specs.ts +0 -124
- package/dist/codegen/templates/command/mutation.resolver.ts.ejs +0 -25
- package/dist/codegen/templates/query/query.resolver.ts.ejs +0 -98
- package/dist/src/codegen/templates/command/commands.specs.d.ts +0 -2
- package/dist/src/codegen/templates/command/commands.specs.d.ts.map +0 -1
- package/dist/src/codegen/templates/command/commands.specs.js +0 -96
- package/dist/src/codegen/templates/command/commands.specs.js.map +0 -1
- package/dist/src/codegen/templates/command/decide.specs.d.ts +0 -2
- package/dist/src/codegen/templates/command/decide.specs.d.ts.map +0 -1
- package/dist/src/codegen/templates/command/decide.specs.js +0 -567
- package/dist/src/codegen/templates/command/decide.specs.js.map +0 -1
- package/dist/src/codegen/templates/command/decide.specs.specs.d.ts +0 -2
- package/dist/src/codegen/templates/command/decide.specs.specs.d.ts.map +0 -1
- package/dist/src/codegen/templates/command/decide.specs.specs.js +0 -278
- package/dist/src/codegen/templates/command/decide.specs.specs.js.map +0 -1
- package/dist/src/codegen/templates/command/events.specs.d.ts +0 -2
- package/dist/src/codegen/templates/command/events.specs.d.ts.map +0 -1
- package/dist/src/codegen/templates/command/events.specs.js +0 -112
- package/dist/src/codegen/templates/command/events.specs.js.map +0 -1
- package/dist/src/codegen/templates/command/evolve.specs.d.ts +0 -2
- package/dist/src/codegen/templates/command/evolve.specs.d.ts.map +0 -1
- package/dist/src/codegen/templates/command/evolve.specs.js +0 -108
- package/dist/src/codegen/templates/command/evolve.specs.js.map +0 -1
- package/dist/src/codegen/templates/command/handle.specs.d.ts +0 -2
- package/dist/src/codegen/templates/command/handle.specs.d.ts.map +0 -1
- package/dist/src/codegen/templates/command/handle.specs.js +0 -326
- package/dist/src/codegen/templates/command/handle.specs.js.map +0 -1
- package/dist/src/codegen/templates/command/mutation.resolver.specs.d.ts +0 -2
- package/dist/src/codegen/templates/command/mutation.resolver.specs.d.ts.map +0 -1
- package/dist/src/codegen/templates/command/mutation.resolver.specs.js +0 -121
- package/dist/src/codegen/templates/command/mutation.resolver.specs.js.map +0 -1
- package/dist/src/codegen/templates/command/register.specs.d.ts +0 -2
- package/dist/src/codegen/templates/command/register.specs.d.ts.map +0 -1
- package/dist/src/codegen/templates/command/register.specs.js +0 -113
- package/dist/src/codegen/templates/command/register.specs.js.map +0 -1
- package/dist/src/codegen/templates/command/state.specs.d.ts +0 -2
- package/dist/src/codegen/templates/command/state.specs.d.ts.map +0 -1
- package/dist/src/codegen/templates/command/state.specs.js +0 -133
- package/dist/src/codegen/templates/command/state.specs.js.map +0 -1
- package/dist/src/codegen/templates/query/projection.specs.d.ts +0 -2
- package/dist/src/codegen/templates/query/projection.specs.d.ts.map +0 -1
- package/dist/src/codegen/templates/query/projection.specs.js +0 -363
- package/dist/src/codegen/templates/query/projection.specs.js.map +0 -1
- package/dist/src/codegen/templates/query/projection.specs.specs..d.ts +0 -2
- package/dist/src/codegen/templates/query/projection.specs.specs..d.ts.map +0 -1
- package/dist/src/codegen/templates/query/projection.specs.specs..js +0 -293
- package/dist/src/codegen/templates/query/projection.specs.specs..js.map +0 -1
- package/dist/src/codegen/templates/query/query.resolver.specs.d.ts +0 -2
- package/dist/src/codegen/templates/query/query.resolver.specs.d.ts.map +0 -1
- package/dist/src/codegen/templates/query/query.resolver.specs.js +0 -249
- package/dist/src/codegen/templates/query/query.resolver.specs.js.map +0 -1
- package/dist/src/codegen/templates/query/state.specs.d.ts +0 -2
- package/dist/src/codegen/templates/query/state.specs.d.ts.map +0 -1
- package/dist/src/codegen/templates/query/state.specs.js +0 -67
- package/dist/src/codegen/templates/query/state.specs.js.map +0 -1
- package/dist/src/codegen/templates/react/react.specs.d.ts +0 -2
- package/dist/src/codegen/templates/react/react.specs.d.ts.map +0 -1
- package/dist/src/codegen/templates/react/react.specs.js +0 -265
- package/dist/src/codegen/templates/react/react.specs.js.map +0 -1
- package/dist/src/codegen/templates/react/react.specs.specs.d.ts +0 -2
- package/dist/src/codegen/templates/react/react.specs.specs.d.ts.map +0 -1
- package/dist/src/codegen/templates/react/react.specs.specs.js +0 -229
- package/dist/src/codegen/templates/react/react.specs.specs.js.map +0 -1
- package/dist/src/codegen/templates/react/register.specs.d.ts +0 -2
- package/dist/src/codegen/templates/react/register.specs.d.ts.map +0 -1
- package/dist/src/codegen/templates/react/register.specs.js +0 -246
- package/dist/src/codegen/templates/react/register.specs.js.map +0 -1
- /package/dist/{codegen → src/codegen}/templates/command/commands.ts.ejs +0 -0
- /package/dist/{codegen → src/codegen}/templates/command/decide.specs.ts.ejs +0 -0
- /package/dist/{codegen → src/codegen}/templates/command/decide.ts.ejs +0 -0
- /package/dist/{codegen → src/codegen}/templates/command/events.ts.ejs +0 -0
- /package/dist/{codegen → src/codegen}/templates/command/evolve.ts.ejs +0 -0
- /package/dist/{codegen → src/codegen}/templates/command/handle.ts.ejs +0 -0
- /package/dist/{codegen → src/codegen}/templates/command/register.ts.ejs +0 -0
- /package/dist/{codegen → src/codegen}/templates/command/state.ts.ejs +0 -0
- /package/dist/{codegen → src/codegen}/templates/query/projection.specs.ts.ejs +0 -0
- /package/dist/{codegen → src/codegen}/templates/query/projection.ts.ejs +0 -0
- /package/dist/{codegen → src/codegen}/templates/query/state.ts.ejs +0 -0
- /package/dist/{codegen → src/codegen}/templates/react/react.specs.ts.ejs +0 -0
- /package/dist/{codegen → src/codegen}/templates/react/react.ts.ejs +0 -0
- /package/dist/{codegen → src/codegen}/templates/react/register.ts.ejs +0 -0
- /package/dist/{domain → src/domain}/shared/ReadModel.ts +0 -0
- /package/dist/{domain → src/domain}/shared/index.ts +0 -0
- /package/dist/{domain → src/domain}/shared/reactorSpecification.ts +0 -0
- /package/dist/{domain → src/domain}/shared/sendCommand.ts +0 -0
- /package/dist/{domain → src/domain}/shared/types.ts +0 -0
- /package/dist/{server.ts → src/server.ts} +0 -0
- /package/dist/{utils → src/utils}/index.ts +0 -0
- /package/dist/{utils → src/utils}/loadProjections.ts +0 -0
- /package/dist/{utils → src/utils}/loadRegisterFiles.ts +0 -0
- /package/dist/{utils → src/utils}/loadResolvers.ts +0 -0
|
@@ -1,326 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { generateScaffoldFilePlans } from '../../scaffoldFromSchema.js';
|
|
3
|
-
describe('generateScaffoldFilePlans', () => {
|
|
4
|
-
it('should generate a valid handle file', async () => {
|
|
5
|
-
const spec = {
|
|
6
|
-
variant: 'specs',
|
|
7
|
-
flows: [
|
|
8
|
-
{
|
|
9
|
-
name: 'Host creates a listing',
|
|
10
|
-
slices: [
|
|
11
|
-
{
|
|
12
|
-
type: 'command',
|
|
13
|
-
name: 'Create listing',
|
|
14
|
-
stream: 'listing-${propertyId}',
|
|
15
|
-
client: {
|
|
16
|
-
description: 'test',
|
|
17
|
-
specs: [],
|
|
18
|
-
},
|
|
19
|
-
server: {
|
|
20
|
-
description: 'test',
|
|
21
|
-
specs: {
|
|
22
|
-
name: 'Create listing command',
|
|
23
|
-
rules: [
|
|
24
|
-
{
|
|
25
|
-
description: 'Should create listing successfully',
|
|
26
|
-
examples: [
|
|
27
|
-
{
|
|
28
|
-
description: 'User creates listing with valid data',
|
|
29
|
-
when: {
|
|
30
|
-
commandRef: 'CreateListing',
|
|
31
|
-
exampleData: {
|
|
32
|
-
propertyId: 'listing_123',
|
|
33
|
-
title: 'Modern Downtown Apartment',
|
|
34
|
-
listedAt: '2024-01-15T10:00:00Z',
|
|
35
|
-
rating: 4.8,
|
|
36
|
-
metadata: { foo: 'bar' },
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
then: [
|
|
40
|
-
{
|
|
41
|
-
eventRef: 'ListingCreated',
|
|
42
|
-
exampleData: {
|
|
43
|
-
propertyId: 'listing_123',
|
|
44
|
-
listedAt: '2024-01-15T10:00:00Z',
|
|
45
|
-
rating: 4.8,
|
|
46
|
-
metadata: { foo: 'bar' },
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
],
|
|
50
|
-
},
|
|
51
|
-
],
|
|
52
|
-
},
|
|
53
|
-
],
|
|
54
|
-
},
|
|
55
|
-
data: [
|
|
56
|
-
{
|
|
57
|
-
target: {
|
|
58
|
-
type: 'Event',
|
|
59
|
-
name: 'ListingCreated',
|
|
60
|
-
},
|
|
61
|
-
destination: {
|
|
62
|
-
type: 'stream',
|
|
63
|
-
pattern: 'listings-${propertyId}',
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
],
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
],
|
|
70
|
-
},
|
|
71
|
-
],
|
|
72
|
-
messages: [
|
|
73
|
-
{
|
|
74
|
-
type: 'command',
|
|
75
|
-
name: 'CreateListing',
|
|
76
|
-
fields: [
|
|
77
|
-
{ name: 'propertyId', type: 'string', required: true },
|
|
78
|
-
{ name: 'title', type: 'string', required: true },
|
|
79
|
-
{ name: 'listedAt', type: 'Date', required: true },
|
|
80
|
-
{ name: 'rating', type: 'number', required: true },
|
|
81
|
-
{ name: 'metadata', type: 'object', required: true },
|
|
82
|
-
],
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
type: 'event',
|
|
86
|
-
name: 'ListingCreated',
|
|
87
|
-
source: 'internal',
|
|
88
|
-
fields: [
|
|
89
|
-
{ name: 'propertyId', type: 'string', required: true },
|
|
90
|
-
{ name: 'title', type: 'string', required: true },
|
|
91
|
-
{ name: 'listedAt', type: 'Date', required: true },
|
|
92
|
-
{ name: 'rating', type: 'number', required: true },
|
|
93
|
-
{ name: 'metadata', type: 'object', required: true },
|
|
94
|
-
],
|
|
95
|
-
},
|
|
96
|
-
],
|
|
97
|
-
};
|
|
98
|
-
const plans = await generateScaffoldFilePlans(spec.flows, spec.messages, undefined, 'src/domain/flows');
|
|
99
|
-
const handleFile = plans.find((p) => p.outputPath.endsWith('handle.ts'));
|
|
100
|
-
expect(handleFile?.contents).toMatchInlineSnapshot(`
|
|
101
|
-
"import { CommandHandler, type EventStore, type MessageHandlerResult } from '@event-driven-io/emmett';
|
|
102
|
-
import { evolve } from './evolve.js';
|
|
103
|
-
import { initialState } from './state.js';
|
|
104
|
-
import { decide } from './decide.js';
|
|
105
|
-
import type { CreateListing } from './commands.js';
|
|
106
|
-
|
|
107
|
-
const handler = CommandHandler({
|
|
108
|
-
evolve,
|
|
109
|
-
initialState,
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
export const handle = async (eventStore: EventStore, command: CreateListing): Promise<MessageHandlerResult> => {
|
|
113
|
-
const streamId = \`listings-\${command.data.propertyId}\`;
|
|
114
|
-
|
|
115
|
-
try {
|
|
116
|
-
await handler(eventStore, streamId, (state) => decide(command, state));
|
|
117
|
-
return; // success (returns void)
|
|
118
|
-
} catch (error: any) {
|
|
119
|
-
return {
|
|
120
|
-
type: 'SKIP',
|
|
121
|
-
reason: \`Command failed: \${error?.message ?? 'Unknown'}\`,
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
"
|
|
126
|
-
`);
|
|
127
|
-
});
|
|
128
|
-
it('should generate a valid handle file with integration', async () => {
|
|
129
|
-
const spec = {
|
|
130
|
-
variant: 'specs',
|
|
131
|
-
flows: [
|
|
132
|
-
{
|
|
133
|
-
name: 'Assistant suggests items',
|
|
134
|
-
slices: [
|
|
135
|
-
{
|
|
136
|
-
type: 'command',
|
|
137
|
-
name: 'Suggest Items',
|
|
138
|
-
stream: 'session-${sessionId}',
|
|
139
|
-
client: {
|
|
140
|
-
description: 'test',
|
|
141
|
-
specs: [],
|
|
142
|
-
},
|
|
143
|
-
server: {
|
|
144
|
-
description: '',
|
|
145
|
-
data: [
|
|
146
|
-
{
|
|
147
|
-
target: {
|
|
148
|
-
type: 'Command',
|
|
149
|
-
name: 'SuggestItems',
|
|
150
|
-
},
|
|
151
|
-
destination: {
|
|
152
|
-
type: 'integration',
|
|
153
|
-
systems: ['AI'],
|
|
154
|
-
message: {
|
|
155
|
-
name: 'DoChat',
|
|
156
|
-
type: 'command',
|
|
157
|
-
},
|
|
158
|
-
},
|
|
159
|
-
_additionalInstructions: 'Ensure systemPrompt includes product catalogue guidance',
|
|
160
|
-
_withState: {
|
|
161
|
-
target: {
|
|
162
|
-
type: 'State',
|
|
163
|
-
name: 'Products',
|
|
164
|
-
},
|
|
165
|
-
origin: {
|
|
166
|
-
type: 'integration',
|
|
167
|
-
systems: ['product-catalog'],
|
|
168
|
-
},
|
|
169
|
-
},
|
|
170
|
-
},
|
|
171
|
-
{
|
|
172
|
-
target: {
|
|
173
|
-
type: 'Event',
|
|
174
|
-
name: 'ItemsSuggested',
|
|
175
|
-
},
|
|
176
|
-
destination: {
|
|
177
|
-
type: 'stream',
|
|
178
|
-
pattern: 'session-${sessionId}',
|
|
179
|
-
},
|
|
180
|
-
},
|
|
181
|
-
],
|
|
182
|
-
specs: {
|
|
183
|
-
name: 'Suggest items command',
|
|
184
|
-
rules: [
|
|
185
|
-
{
|
|
186
|
-
description: 'Should suggest items successfully',
|
|
187
|
-
examples: [
|
|
188
|
-
{
|
|
189
|
-
description: 'User requests item suggestions',
|
|
190
|
-
when: {
|
|
191
|
-
commandRef: 'SuggestItems',
|
|
192
|
-
exampleData: {
|
|
193
|
-
sessionId: 'session-123',
|
|
194
|
-
prompt: 'What should I buy?',
|
|
195
|
-
},
|
|
196
|
-
},
|
|
197
|
-
then: [
|
|
198
|
-
{
|
|
199
|
-
eventRef: 'ItemsSuggested',
|
|
200
|
-
exampleData: {
|
|
201
|
-
sessionId: 'session-123',
|
|
202
|
-
items: [],
|
|
203
|
-
},
|
|
204
|
-
},
|
|
205
|
-
],
|
|
206
|
-
},
|
|
207
|
-
],
|
|
208
|
-
},
|
|
209
|
-
],
|
|
210
|
-
},
|
|
211
|
-
},
|
|
212
|
-
},
|
|
213
|
-
],
|
|
214
|
-
},
|
|
215
|
-
],
|
|
216
|
-
messages: [
|
|
217
|
-
{
|
|
218
|
-
type: 'command',
|
|
219
|
-
name: 'SuggestItems',
|
|
220
|
-
fields: [
|
|
221
|
-
{ name: 'sessionId', type: 'string', required: true },
|
|
222
|
-
{ name: 'prompt', type: 'string', required: true },
|
|
223
|
-
],
|
|
224
|
-
},
|
|
225
|
-
{
|
|
226
|
-
type: 'command',
|
|
227
|
-
name: 'DoChat',
|
|
228
|
-
fields: [
|
|
229
|
-
{ name: 'sessionId', type: 'string', required: true },
|
|
230
|
-
{ name: 'prompt', type: 'string', required: true },
|
|
231
|
-
{ name: 'systemPrompt', type: 'string', required: false },
|
|
232
|
-
],
|
|
233
|
-
},
|
|
234
|
-
{
|
|
235
|
-
type: 'event',
|
|
236
|
-
name: 'ItemsSuggested',
|
|
237
|
-
source: 'internal',
|
|
238
|
-
fields: [
|
|
239
|
-
{ name: 'sessionId', type: 'string', required: true },
|
|
240
|
-
{ name: 'items', type: 'Array<object>', required: true },
|
|
241
|
-
],
|
|
242
|
-
},
|
|
243
|
-
{
|
|
244
|
-
type: 'state',
|
|
245
|
-
name: 'Products',
|
|
246
|
-
fields: [
|
|
247
|
-
{
|
|
248
|
-
name: 'products',
|
|
249
|
-
type: 'Array<{ id: string, name: string }>',
|
|
250
|
-
required: true,
|
|
251
|
-
},
|
|
252
|
-
],
|
|
253
|
-
},
|
|
254
|
-
],
|
|
255
|
-
integrations: [
|
|
256
|
-
{
|
|
257
|
-
name: 'AI',
|
|
258
|
-
source: '@auto-engineer/ai-integration',
|
|
259
|
-
description: '',
|
|
260
|
-
},
|
|
261
|
-
{
|
|
262
|
-
name: 'product-catalog',
|
|
263
|
-
source: '@auto-engineer/product-catalogue-integration',
|
|
264
|
-
description: '',
|
|
265
|
-
},
|
|
266
|
-
],
|
|
267
|
-
};
|
|
268
|
-
const plans = await generateScaffoldFilePlans(spec.flows, spec.messages, spec.integrations, 'src/domain/flows');
|
|
269
|
-
const handleFile = plans.find((p) => p.outputPath.endsWith('handle.ts'));
|
|
270
|
-
expect(handleFile?.contents).toMatchInlineSnapshot(`
|
|
271
|
-
"import '@auto-engineer/product-catalogue-integration';
|
|
272
|
-
|
|
273
|
-
import { AI } from '@auto-engineer/ai-integration';
|
|
274
|
-
|
|
275
|
-
import { Products } from '@auto-engineer/product-catalogue-integration';
|
|
276
|
-
|
|
277
|
-
import { CommandHandler, type EventStore, type MessageHandlerResult } from '@event-driven-io/emmett';
|
|
278
|
-
import { evolve } from './evolve.js';
|
|
279
|
-
import { initialState } from './state.js';
|
|
280
|
-
import { decide } from './decide.js';
|
|
281
|
-
import type { SuggestItems } from './commands.js';
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* ## IMPLEMENTATION INSTRUCTIONS ##
|
|
285
|
-
* Ensure systemPrompt includes product catalogue guidance
|
|
286
|
-
*/
|
|
287
|
-
|
|
288
|
-
const handler = CommandHandler({
|
|
289
|
-
evolve,
|
|
290
|
-
initialState,
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
export const handle = async (eventStore: EventStore, command: SuggestItems): Promise<MessageHandlerResult> => {
|
|
294
|
-
const streamId = \`session-\${command.data.sessionId}\`;
|
|
295
|
-
|
|
296
|
-
try {
|
|
297
|
-
// TODO: Map fields from the incoming command to this integration input.
|
|
298
|
-
// - Use relevant fields from \`command.data\` to populate the required inputs below.
|
|
299
|
-
// - Some fields may require transformation or enrichment.
|
|
300
|
-
// - If additional context is needed, construct it here.
|
|
301
|
-
// const products: Products | undefined = await AI.Commands?.DoChat<Products>({
|
|
302
|
-
// type: 'DoChat',
|
|
303
|
-
// data: {
|
|
304
|
-
// // sessionId: ???
|
|
305
|
-
// prompt: ???
|
|
306
|
-
// systemPrompt: ???
|
|
307
|
-
// },
|
|
308
|
-
// });
|
|
309
|
-
|
|
310
|
-
await handler(eventStore, streamId, (state) =>
|
|
311
|
-
// TODO: add products as a parameter to decide once implemented above
|
|
312
|
-
decide(command, state /* products */),
|
|
313
|
-
);
|
|
314
|
-
return; // success (returns void)
|
|
315
|
-
} catch (error: any) {
|
|
316
|
-
return {
|
|
317
|
-
type: 'SKIP',
|
|
318
|
-
reason: \`Command failed: \${error?.message ?? 'Unknown'}\`,
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
};
|
|
322
|
-
"
|
|
323
|
-
`);
|
|
324
|
-
});
|
|
325
|
-
});
|
|
326
|
-
//# sourceMappingURL=handle.specs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"handle.specs.js","sourceRoot":"","sources":["../../../../../src/codegen/templates/command/handle.specs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ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AC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mutation.resolver.specs.d.ts","sourceRoot":"","sources":["../../../../../src/codegen/templates/command/mutation.resolver.specs.ts"],"names":[],"mappings":""}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { generateScaffoldFilePlans } from '../../scaffoldFromSchema.js';
|
|
3
|
-
describe('mutation.resolver.ts.ejs', () => {
|
|
4
|
-
it('should generate a valid mutation resolver file', async () => {
|
|
5
|
-
const spec = {
|
|
6
|
-
variant: 'specs',
|
|
7
|
-
flows: [
|
|
8
|
-
{
|
|
9
|
-
name: 'Host creates a listing',
|
|
10
|
-
slices: [
|
|
11
|
-
{
|
|
12
|
-
type: 'command',
|
|
13
|
-
name: 'Create listing',
|
|
14
|
-
client: {
|
|
15
|
-
description: 'A form that allows users to add a new listing',
|
|
16
|
-
specs: [],
|
|
17
|
-
},
|
|
18
|
-
server: {
|
|
19
|
-
description: 'Handles listing creation',
|
|
20
|
-
specs: {
|
|
21
|
-
name: 'Create listing command',
|
|
22
|
-
rules: [
|
|
23
|
-
{
|
|
24
|
-
description: 'Should create listing successfully',
|
|
25
|
-
examples: [
|
|
26
|
-
{
|
|
27
|
-
description: 'User creates listing with valid data',
|
|
28
|
-
when: {
|
|
29
|
-
commandRef: 'CreateListing',
|
|
30
|
-
exampleData: {
|
|
31
|
-
propertyId: 'listing_123',
|
|
32
|
-
title: 'Modern Downtown Apartment',
|
|
33
|
-
pricePerNight: 250,
|
|
34
|
-
maxGuests: 4,
|
|
35
|
-
amenities: ['wifi', 'kitchen'],
|
|
36
|
-
available: true,
|
|
37
|
-
tags: ['sea view', 'balcony'],
|
|
38
|
-
rating: 4.8,
|
|
39
|
-
metadata: { petsAllowed: true },
|
|
40
|
-
listedAt: '2024-01-15T10:00:00Z',
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
then: [],
|
|
44
|
-
},
|
|
45
|
-
],
|
|
46
|
-
},
|
|
47
|
-
],
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
],
|
|
52
|
-
},
|
|
53
|
-
],
|
|
54
|
-
messages: [
|
|
55
|
-
{
|
|
56
|
-
type: 'command',
|
|
57
|
-
name: 'CreateListing',
|
|
58
|
-
fields: [
|
|
59
|
-
{ name: 'propertyId', type: 'string', required: true },
|
|
60
|
-
{ name: 'title', type: 'string', required: true },
|
|
61
|
-
{ name: 'pricePerNight', type: 'number', required: true },
|
|
62
|
-
{ name: 'maxGuests', type: 'number', required: true },
|
|
63
|
-
{ name: 'amenities', type: 'string[]', required: true },
|
|
64
|
-
{ name: 'available', type: 'boolean', required: true },
|
|
65
|
-
{ name: 'tags', type: 'string[]', required: true },
|
|
66
|
-
{ name: 'rating', type: 'number', required: true },
|
|
67
|
-
{ name: 'metadata', type: 'object', required: true },
|
|
68
|
-
{ name: 'listedAt', type: 'Date', required: true },
|
|
69
|
-
],
|
|
70
|
-
},
|
|
71
|
-
],
|
|
72
|
-
};
|
|
73
|
-
const plans = await generateScaffoldFilePlans(spec.flows, spec.messages, undefined, 'src/domain/flows');
|
|
74
|
-
const mutationFile = plans.find((p) => p.outputPath.endsWith('mutation.resolver.ts'));
|
|
75
|
-
expect(mutationFile?.contents).toMatchInlineSnapshot(`
|
|
76
|
-
"import { Mutation, Resolver, Arg, Ctx, Field, InputType } from 'type-graphql';
|
|
77
|
-
import { type GraphQLContext, sendCommand, MutationResponse } from '../../../shared.js';
|
|
78
|
-
|
|
79
|
-
@InputType()
|
|
80
|
-
export class CreateListingInput {
|
|
81
|
-
@Field(() => String)
|
|
82
|
-
propertyId!: string;
|
|
83
|
-
@Field(() => String)
|
|
84
|
-
title!: string;
|
|
85
|
-
@Field(() => Number)
|
|
86
|
-
pricePerNight!: number;
|
|
87
|
-
@Field(() => Number)
|
|
88
|
-
maxGuests!: number;
|
|
89
|
-
@Field(() => [String])
|
|
90
|
-
amenities!: string[];
|
|
91
|
-
@Field(() => Boolean)
|
|
92
|
-
available!: boolean;
|
|
93
|
-
@Field(() => [String])
|
|
94
|
-
tags!: string[];
|
|
95
|
-
@Field(() => Number)
|
|
96
|
-
rating!: number;
|
|
97
|
-
@Field(() => Object)
|
|
98
|
-
metadata!: object;
|
|
99
|
-
@Field(() => Date)
|
|
100
|
-
listedAt!: Date;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
@Resolver()
|
|
104
|
-
export class CreateListingResolver {
|
|
105
|
-
@Mutation(() => MutationResponse)
|
|
106
|
-
async createListing(
|
|
107
|
-
@Arg('input', () => CreateListingInput) input: CreateListingInput,
|
|
108
|
-
@Ctx() ctx: GraphQLContext,
|
|
109
|
-
): Promise<MutationResponse> {
|
|
110
|
-
return await sendCommand(ctx.messageBus, {
|
|
111
|
-
type: 'CreateListing',
|
|
112
|
-
kind: 'Command',
|
|
113
|
-
data: { ...input },
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
"
|
|
118
|
-
`);
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
//# sourceMappingURL=mutation.resolver.specs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mutation.resolver.specs.js","sourceRoot":"","sources":["../../../../../src/codegen/templates/command/mutation.resolver.specs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAGrE,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;IACxC,EAAE,CAAC,gDAAgD,EAAE,KAAK,IAAI,EAAE;QAC9D,MAAM,IAAI,GAAgB;YACxB,OAAO,EAAE,OAAO;YAChB,KAAK,EAAE;gBACL;oBACE,IAAI,EAAE,wBAAwB;oBAC9B,MAAM,EAAE;wBACN;4BACE,IAAI,EA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,IAAI,EAAE;wBACrD,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE;wBACvD,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE;wBACtD,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE;wBAClD,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE;wBAClD,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE;wBACpD,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;qBACnD;iBACF;aACF;SACF,CAAC;QAEF,MAAM,KAAK,GAAG,MAAM,yBAAyB,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,EAAE,SAAS,EAAE,kBAAkB,CAAC,CAAC;QACxG,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,sBAAsB,CAAC,CAAC,CAAC;QAEtF,MAAM,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA2CpD,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"register.specs.d.ts","sourceRoot":"","sources":["../../../../../src/codegen/templates/command/register.specs.ts"],"names":[],"mappings":""}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { generateScaffoldFilePlans } from '../../scaffoldFromSchema.js';
|
|
3
|
-
describe('generateScaffoldFilePlans', () => {
|
|
4
|
-
it('should generate a valid register file', async () => {
|
|
5
|
-
const spec = {
|
|
6
|
-
variant: 'specs',
|
|
7
|
-
flows: [
|
|
8
|
-
{
|
|
9
|
-
name: 'Host creates a listing',
|
|
10
|
-
slices: [
|
|
11
|
-
{
|
|
12
|
-
type: 'command',
|
|
13
|
-
name: 'Create listing',
|
|
14
|
-
stream: 'listings-${propertyId}',
|
|
15
|
-
client: {
|
|
16
|
-
description: 'test',
|
|
17
|
-
specs: [],
|
|
18
|
-
},
|
|
19
|
-
server: {
|
|
20
|
-
description: 'test',
|
|
21
|
-
specs: {
|
|
22
|
-
name: 'Create listing command',
|
|
23
|
-
rules: [
|
|
24
|
-
{
|
|
25
|
-
description: 'Should create listing successfully',
|
|
26
|
-
examples: [
|
|
27
|
-
{
|
|
28
|
-
description: 'User creates listing with valid data',
|
|
29
|
-
when: {
|
|
30
|
-
commandRef: 'CreateListing',
|
|
31
|
-
exampleData: {
|
|
32
|
-
propertyId: 'listing_123',
|
|
33
|
-
title: 'Modern Downtown Apartment',
|
|
34
|
-
listedAt: '2024-01-15T10:00:00Z',
|
|
35
|
-
rating: 4.8,
|
|
36
|
-
metadata: { foo: 'bar' },
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
then: [
|
|
40
|
-
{
|
|
41
|
-
eventRef: 'ListingCreated',
|
|
42
|
-
exampleData: {
|
|
43
|
-
propertyId: 'listing_123',
|
|
44
|
-
title: 'Modern Downtown Apartment',
|
|
45
|
-
listedAt: '2024-01-15T10:00:00Z',
|
|
46
|
-
rating: 4.8,
|
|
47
|
-
metadata: { foo: 'bar' },
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
],
|
|
51
|
-
},
|
|
52
|
-
],
|
|
53
|
-
},
|
|
54
|
-
],
|
|
55
|
-
},
|
|
56
|
-
data: [
|
|
57
|
-
{
|
|
58
|
-
target: {
|
|
59
|
-
type: 'Event',
|
|
60
|
-
name: 'ListingCreated',
|
|
61
|
-
},
|
|
62
|
-
destination: {
|
|
63
|
-
type: 'stream',
|
|
64
|
-
pattern: 'listings-${propertyId}',
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
],
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
],
|
|
71
|
-
},
|
|
72
|
-
],
|
|
73
|
-
messages: [
|
|
74
|
-
{
|
|
75
|
-
type: 'command',
|
|
76
|
-
name: 'CreateListing',
|
|
77
|
-
fields: [
|
|
78
|
-
{ name: 'propertyId', type: 'string', required: true },
|
|
79
|
-
{ name: 'title', type: 'string', required: true },
|
|
80
|
-
{ name: 'listedAt', type: 'Date', required: true },
|
|
81
|
-
{ name: 'rating', type: 'number', required: true },
|
|
82
|
-
{ name: 'metadata', type: 'object', required: true },
|
|
83
|
-
],
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
type: 'event',
|
|
87
|
-
name: 'ListingCreated',
|
|
88
|
-
source: 'internal',
|
|
89
|
-
fields: [
|
|
90
|
-
{ name: 'propertyId', type: 'string', required: true },
|
|
91
|
-
{ name: 'title', type: 'string', required: true },
|
|
92
|
-
{ name: 'listedAt', type: 'Date', required: true },
|
|
93
|
-
{ name: 'rating', type: 'number', required: true },
|
|
94
|
-
{ name: 'metadata', type: 'object', required: true },
|
|
95
|
-
],
|
|
96
|
-
},
|
|
97
|
-
],
|
|
98
|
-
};
|
|
99
|
-
const plans = await generateScaffoldFilePlans(spec.flows, spec.messages, undefined, 'src/domain/flows');
|
|
100
|
-
const registerFile = plans.find((p) => p.outputPath.endsWith('register.ts'));
|
|
101
|
-
expect(registerFile?.contents).toMatchInlineSnapshot(`
|
|
102
|
-
"import type { CommandProcessor, EventStore } from '@event-driven-io/emmett';
|
|
103
|
-
import { handle } from './handle.js';
|
|
104
|
-
import type { CreateListing } from './commands.js';
|
|
105
|
-
|
|
106
|
-
export function register(messageBus: CommandProcessor, eventStore: EventStore) {
|
|
107
|
-
messageBus.handle((command: CreateListing) => handle(eventStore, command), 'CreateListing');
|
|
108
|
-
}
|
|
109
|
-
"
|
|
110
|
-
`);
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
//# sourceMappingURL=register.specs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"register.specs.js","sourceRoot":"","sources":["../../../../../src/codegen/templates/command/register.specs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAGrE,QAAQ,CAAC,2BAA2B,EAAE,GAAG,EAAE;IACzC,EAAE,CAAC,uCAAuC,EAAE,KAAK,IAAI,EAAE;QACrD,MAAM,IAAI,GAAgB;YACxB,OAAO,EAAE,OAAO;YAChB,KAAK,EAAE;gBACL;oBACE,IAAI,EAAE,wBAAwB;oBAC9B,MAAM,EAAE;wBACN;4BACE,IAAI,EAAE,SAAS;4BACf,IAAI,EAAE,gBAAgB;4BACtB,MAAM,EAAE,wBAAwB;4BAChC,MAAM,EAAE;gCACN,WAAW,EAAE,MAAM;gCACnB,KAAK,EAAE,EAAE;6BACV;4BACD,MAAM,EAAE;gCACN,WAAW,EAAE,MAAM;gCACnB,KAAK,EAAE;oCACL,IAAI,EAAE,wBAAwB;oCAC9B,KAAK,EAAE;wCACL;4CACE,WAAW,EAAE,oCAAoC;4CACjD,QAAQ,EAAE;gDACR;oDACE,WAAW,EAAE,sCAAsC;oDACnD,IAAI,EAAE;wDACJ,UAAU,EAAE,eAAe;wDAC3B,WAAW,EAAE;4DACX,UAAU,EAAE,aAAa;4DACzB,KAAK,EAAE,2BAA2B;4DAClC,QAAQ,EAAE,sBAAsB;4DAChC,MAAM,EAAE,GAAG;4DACX,QAAQ,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE;yDACzB;qDACF;oDACD,IAAI,EAAE;wDACJ;4D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