@auto-engineer/server-generator-apollo-emmett 0.1.4 → 0.8.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.
Files changed (132) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.turbo/turbo-test.log +14 -171
  3. package/.turbo/turbo-type-check.log +4 -5
  4. package/CHANGELOG.md +19 -0
  5. package/dist/codegen/extract/commands.d.ts +11 -5
  6. package/dist/codegen/extract/commands.d.ts.map +1 -1
  7. package/dist/codegen/extract/commands.js +27 -12
  8. package/dist/codegen/extract/commands.js.map +1 -1
  9. package/dist/codegen/extract/data-sink.d.ts.map +1 -1
  10. package/dist/codegen/extract/data-sink.js +52 -28
  11. package/dist/codegen/extract/data-sink.js.map +1 -1
  12. package/dist/codegen/extract/gwt.d.ts.map +1 -1
  13. package/dist/codegen/extract/gwt.js +37 -6
  14. package/dist/codegen/extract/gwt.js.map +1 -1
  15. package/dist/codegen/extract/messages.d.ts.map +1 -1
  16. package/dist/codegen/extract/messages.js +38 -6
  17. package/dist/codegen/extract/messages.js.map +1 -1
  18. package/dist/codegen/extract/query.d.ts.map +1 -1
  19. package/dist/codegen/extract/query.js +9 -2
  20. package/dist/codegen/extract/query.js.map +1 -1
  21. package/dist/codegen/scaffoldFromSchema.d.ts.map +1 -1
  22. package/dist/codegen/scaffoldFromSchema.js +21 -6
  23. package/dist/codegen/scaffoldFromSchema.js.map +1 -1
  24. package/dist/codegen/templates/command/commands.specs.ts +28 -19
  25. package/dist/codegen/templates/command/decide.specs.specs.ts +75 -57
  26. package/dist/codegen/templates/command/decide.specs.ts +147 -110
  27. package/dist/codegen/templates/command/events.specs.ts +38 -29
  28. package/dist/codegen/templates/command/evolve.specs.ts +33 -24
  29. package/dist/codegen/templates/command/handle.specs.ts +61 -43
  30. package/dist/codegen/templates/command/mutation.resolver.specs.ts +28 -19
  31. package/dist/codegen/templates/command/register.specs.ts +34 -25
  32. package/dist/codegen/templates/command/state.specs.ts +34 -25
  33. package/dist/codegen/templates/query/projection.specs.specs..ts +100 -80
  34. package/dist/codegen/templates/query/projection.specs.ts +101 -81
  35. package/dist/codegen/templates/query/query.resolver.specs.ts +2 -2
  36. package/dist/codegen/templates/query/state.specs.ts +1 -1
  37. package/dist/codegen/templates/react/react.specs.specs.ts +86 -68
  38. package/dist/codegen/templates/react/react.specs.ts +123 -96
  39. package/dist/codegen/templates/react/react.specs.ts.ejs +9 -1
  40. package/dist/codegen/templates/react/react.ts.ejs +8 -1
  41. package/dist/codegen/templates/react/register.specs.ts +123 -96
  42. package/dist/codegen/templates/react/register.ts.ejs +8 -1
  43. package/dist/codegen/test-data/specVariant1.d.ts.map +1 -1
  44. package/dist/codegen/test-data/specVariant1.js +92 -65
  45. package/dist/codegen/test-data/specVariant1.js.map +1 -1
  46. package/dist/codegen/types.d.ts +4 -4
  47. package/dist/codegen/types.d.ts.map +1 -1
  48. package/dist/commands/generate-server.d.ts +11 -45
  49. package/dist/commands/generate-server.d.ts.map +1 -1
  50. package/dist/commands/generate-server.js +29 -24
  51. package/dist/commands/generate-server.js.map +1 -1
  52. package/dist/index.d.ts +11 -2
  53. package/dist/index.d.ts.map +1 -1
  54. package/dist/index.js +2 -2
  55. package/dist/index.js.map +1 -1
  56. package/package.json +9 -9
  57. package/src/codegen/extract/commands.ts +48 -19
  58. package/src/codegen/extract/data-sink.ts +68 -31
  59. package/src/codegen/extract/gwt.ts +45 -10
  60. package/src/codegen/extract/messages.ts +49 -7
  61. package/src/codegen/extract/query.ts +15 -2
  62. package/src/codegen/scaffoldFromSchema.ts +27 -6
  63. package/src/codegen/templates/command/commands.specs.ts +28 -19
  64. package/src/codegen/templates/command/decide.specs.specs.ts +75 -57
  65. package/src/codegen/templates/command/decide.specs.ts +147 -110
  66. package/src/codegen/templates/command/events.specs.ts +38 -29
  67. package/src/codegen/templates/command/evolve.specs.ts +33 -24
  68. package/src/codegen/templates/command/handle.specs.ts +61 -43
  69. package/src/codegen/templates/command/mutation.resolver.specs.ts +28 -19
  70. package/src/codegen/templates/command/register.specs.ts +34 -25
  71. package/src/codegen/templates/command/state.specs.ts +34 -25
  72. package/src/codegen/templates/query/projection.specs.specs..ts +100 -80
  73. package/src/codegen/templates/query/projection.specs.ts +101 -81
  74. package/src/codegen/templates/query/query.resolver.specs.ts +2 -2
  75. package/src/codegen/templates/query/state.specs.ts +1 -1
  76. package/src/codegen/templates/react/react.specs.specs.ts +86 -68
  77. package/src/codegen/templates/react/react.specs.ts +123 -96
  78. package/src/codegen/templates/react/react.specs.ts.ejs +9 -1
  79. package/src/codegen/templates/react/react.ts.ejs +8 -1
  80. package/src/codegen/templates/react/register.specs.ts +123 -96
  81. package/src/codegen/templates/react/register.ts.ejs +8 -1
  82. package/src/codegen/test-data/specVariant1.ts +92 -65
  83. package/src/codegen/types.ts +4 -4
  84. package/src/commands/generate-server.ts +29 -28
  85. package/src/index.ts +8 -2
  86. package/tsconfig.tsbuildinfo +1 -1
  87. package/.tmp/server-test-output/server/package.json +0 -26
  88. package/.tmp/server-test-output/server/scripts/generate-schema.ts +0 -31
  89. package/.tmp/server-test-output/server/src/domain/flows/add-item/create-item/commands.ts +0 -8
  90. package/.tmp/server-test-output/server/src/domain/flows/add-item/create-item/decide.specs.ts +0 -36
  91. package/.tmp/server-test-output/server/src/domain/flows/add-item/create-item/decide.ts +0 -33
  92. package/.tmp/server-test-output/server/src/domain/flows/add-item/create-item/events.ts +0 -10
  93. package/.tmp/server-test-output/server/src/domain/flows/add-item/create-item/evolve.ts +0 -28
  94. package/.tmp/server-test-output/server/src/domain/flows/add-item/create-item/handle.ts +0 -24
  95. package/.tmp/server-test-output/server/src/domain/flows/add-item/create-item/mutation.resolver.ts +0 -25
  96. package/.tmp/server-test-output/server/src/domain/flows/add-item/create-item/register.ts +0 -7
  97. package/.tmp/server-test-output/server/src/domain/flows/add-item/create-item/state.ts +0 -47
  98. package/.tmp/server-test-output/server/src/domain/flows/add-item/get-available-items/projection.specs.ts +0 -46
  99. package/.tmp/server-test-output/server/src/domain/flows/add-item/get-available-items/projection.ts +0 -38
  100. package/.tmp/server-test-output/server/src/domain/flows/add-item/get-available-items/query.resolver.ts +0 -39
  101. package/.tmp/server-test-output/server/src/domain/flows/add-item/get-available-items/state.ts +0 -5
  102. package/.tmp/server-test-output/server/src/domain/flows/add-item/notify-new-item/commands.ts +0 -8
  103. package/.tmp/server-test-output/server/src/domain/flows/add-item/notify-new-item/decide.specs.ts +0 -36
  104. package/.tmp/server-test-output/server/src/domain/flows/add-item/notify-new-item/decide.ts +0 -33
  105. package/.tmp/server-test-output/server/src/domain/flows/add-item/notify-new-item/events.ts +0 -3
  106. package/.tmp/server-test-output/server/src/domain/flows/add-item/notify-new-item/evolve.ts +0 -28
  107. package/.tmp/server-test-output/server/src/domain/flows/add-item/notify-new-item/handle.ts +0 -24
  108. package/.tmp/server-test-output/server/src/domain/flows/add-item/notify-new-item/mutation.resolver.ts +0 -25
  109. package/.tmp/server-test-output/server/src/domain/flows/add-item/notify-new-item/register.ts +0 -7
  110. package/.tmp/server-test-output/server/src/domain/flows/add-item/notify-new-item/state.ts +0 -47
  111. package/.tmp/server-test-output/server/src/domain/flows/add-item/notify-on-new-item/react.specs.ts +0 -49
  112. package/.tmp/server-test-output/server/src/domain/flows/add-item/notify-on-new-item/react.ts +0 -43
  113. package/.tmp/server-test-output/server/src/domain/flows/add-item/notify-on-new-item/register.ts +0 -24
  114. package/.tmp/server-test-output/server/src/domain/shared/ReadModel.ts +0 -26
  115. package/.tmp/server-test-output/server/src/domain/shared/index.ts +0 -4
  116. package/.tmp/server-test-output/server/src/domain/shared/reactorSpecification.ts +0 -257
  117. package/.tmp/server-test-output/server/src/domain/shared/sendCommand.ts +0 -21
  118. package/.tmp/server-test-output/server/src/domain/shared/types.ts +0 -31
  119. package/.tmp/server-test-output/server/src/server.ts +0 -43
  120. package/.tmp/server-test-output/server/src/utils/index.ts +0 -3
  121. package/.tmp/server-test-output/server/src/utils/loadProjections.ts +0 -30
  122. package/.tmp/server-test-output/server/src/utils/loadRegisterFiles.ts +0 -41
  123. package/.tmp/server-test-output/server/src/utils/loadResolvers.ts +0 -36
  124. package/.tmp/server-test-output/server/tsconfig.json +0 -19
  125. package/.tmp/server-test-output/server/vitest.config.ts +0 -7
  126. package/.turbo/turbo-format.log +0 -57
  127. package/.turbo/turbo-lint.log +0 -5
  128. package/dist/cli-manifest.d.ts +0 -3
  129. package/dist/cli-manifest.d.ts.map +0 -1
  130. package/dist/cli-manifest.js +0 -35
  131. package/dist/cli-manifest.js.map +0 -1
  132. package/src/cli-manifest.ts +0 -37
@@ -1,5 +1,13 @@
1
1
  <%
2
- const gwtList = slice.server?.gwt ?? [];
2
+ // Extract all examples from specs/rules structure
3
+ const specs = slice.server?.specs;
4
+ const gwtList = specs?.rules?.flatMap(rule =>
5
+ rule.examples.map(example => ({
6
+ given: example.given,
7
+ when: example.when,
8
+ then: example.then
9
+ }))
10
+ ) ?? [];
3
11
  const firstGwt = gwtList[0];
4
12
  const firstWhen = Array.isArray(firstGwt?.when) ? firstGwt.when[0] : firstGwt?.when;
5
13
  const firstThen = Array.isArray(firstGwt?.then) ? firstGwt.then[0] : firstGwt?.then;
@@ -1,5 +1,12 @@
1
1
  <%
2
- const gwt = slice.server?.gwt?.[0];
2
+ // Extract the first example from specs/rules structure
3
+ const specs = slice.server?.specs;
4
+ const firstExample = specs?.rules?.flatMap(rule => rule.examples)[0] ?? null;
5
+ const gwt = firstExample ? {
6
+ given: firstExample.given,
7
+ when: firstExample.when,
8
+ then: firstExample.then
9
+ } : null;
3
10
  const when = Array.isArray(gwt?.when) ? gwt.when[0] : gwt?.when;
4
11
  const then = Array.isArray(gwt?.then) ? gwt.then[0] : gwt?.then;
5
12
 
@@ -16,41 +16,50 @@ describe('register.ts.ejs (react slice)', () => {
16
16
  client: { description: '', specs: [] },
17
17
  server: {
18
18
  description: '',
19
- gwt: [
20
- {
21
- when: {
22
- commandRef: 'RequestBooking',
23
- exampleData: {
24
- propertyId: 'listing_123',
25
- hostId: 'host_123',
26
- guestId: 'guest_456',
27
- checkIn: '2025-07-15',
28
- checkOut: '2025-07-18',
29
- guests: 2,
30
- message: 'Looking forward to my stay!',
31
- metadata: { now: 'bar', bookingId: '123' },
32
- },
33
- },
34
- then: [
35
- {
36
- eventRef: 'BookingRequested',
37
- exampleData: {
38
- bookingId: 'book_xyz789',
39
- hostId: 'host_123',
40
- propertyId: 'prop_789',
41
- guestId: 'guest_456',
42
- checkIn: '2025-07-15',
43
- checkOut: '2025-07-18',
44
- guests: 2,
45
- message: 'Hey',
46
- status: 'pending_host_approval',
47
- requestedAt: '2025-06-10T16:30:00.000Z',
48
- expiresAt: '2025-06-11T16:30:00.000Z',
19
+ specs: {
20
+ name: 'Guest submits booking request command',
21
+ rules: [
22
+ {
23
+ description: 'Should handle booking request successfully',
24
+ examples: [
25
+ {
26
+ description: 'User submits booking request successfully',
27
+ when: {
28
+ commandRef: 'RequestBooking',
29
+ exampleData: {
30
+ propertyId: 'listing_123',
31
+ hostId: 'host_123',
32
+ guestId: 'guest_456',
33
+ checkIn: '2025-07-15',
34
+ checkOut: '2025-07-18',
35
+ guests: 2,
36
+ message: 'Looking forward to my stay!',
37
+ metadata: { now: 'bar', bookingId: '123' },
38
+ },
39
+ },
40
+ then: [
41
+ {
42
+ eventRef: 'BookingRequested',
43
+ exampleData: {
44
+ bookingId: 'book_xyz789',
45
+ hostId: 'host_123',
46
+ propertyId: 'prop_789',
47
+ guestId: 'guest_456',
48
+ checkIn: '2025-07-15',
49
+ checkOut: '2025-07-18',
50
+ guests: 2,
51
+ message: 'Hey',
52
+ status: 'pending_host_approval',
53
+ requestedAt: '2025-06-10T16:30:00.000Z',
54
+ expiresAt: '2025-06-11T16:30:00.000Z',
55
+ },
56
+ },
57
+ ],
49
58
  },
50
- },
51
- ],
52
- },
53
- ],
59
+ ],
60
+ },
61
+ ],
62
+ },
54
63
  },
55
64
  },
56
65
  {
@@ -58,41 +67,50 @@ describe('register.ts.ejs (react slice)', () => {
58
67
  name: 'Send notification to host',
59
68
  server: {
60
69
  description: 'Sends a host notification command in response to BookingRequested',
61
- gwt: [
62
- {
63
- when: [
64
- {
65
- eventRef: 'BookingRequested',
66
- exampleData: {
67
- bookingId: 'book_xyz789',
68
- hostId: 'host_123',
69
- propertyId: 'prop_789',
70
- guestId: 'guest_456',
71
- checkIn: '2025-07-15',
72
- checkOut: '2025-07-18',
73
- guests: 2,
74
- message: 'Hey',
75
- status: 'pending_host_approval',
76
- requestedAt: '2025-06-10T16:30:00.000Z',
77
- expiresAt: '2025-06-11T16:30:00.000Z',
78
- },
79
- },
80
- ],
81
- then: [
82
- {
83
- commandRef: 'NotifyHost',
84
- exampleData: {
85
- hostId: 'host_123',
86
- notificationType: 'booking_request',
87
- priority: 'high',
88
- channels: ['email', 'push'],
89
- message: 'A guest has requested to book your place.',
90
- actionRequired: true,
70
+ specs: {
71
+ name: 'Send notification to host reaction',
72
+ rules: [
73
+ {
74
+ description: 'Should send host notification on booking request',
75
+ examples: [
76
+ {
77
+ description: 'Booking request triggers host notification',
78
+ when: [
79
+ {
80
+ eventRef: 'BookingRequested',
81
+ exampleData: {
82
+ bookingId: 'book_xyz789',
83
+ hostId: 'host_123',
84
+ propertyId: 'prop_789',
85
+ guestId: 'guest_456',
86
+ checkIn: '2025-07-15',
87
+ checkOut: '2025-07-18',
88
+ guests: 2,
89
+ message: 'Hey',
90
+ status: 'pending_host_approval',
91
+ requestedAt: '2025-06-10T16:30:00.000Z',
92
+ expiresAt: '2025-06-11T16:30:00.000Z',
93
+ },
94
+ },
95
+ ],
96
+ then: [
97
+ {
98
+ commandRef: 'NotifyHost',
99
+ exampleData: {
100
+ hostId: 'host_123',
101
+ notificationType: 'booking_request',
102
+ priority: 'high',
103
+ channels: ['email', 'push'],
104
+ message: 'A guest has requested to book your place.',
105
+ actionRequired: true,
106
+ },
107
+ },
108
+ ],
91
109
  },
92
- },
93
- ],
94
- },
95
- ],
110
+ ],
111
+ },
112
+ ],
113
+ },
96
114
  },
97
115
  },
98
116
  {
@@ -101,35 +119,44 @@ describe('register.ts.ejs (react slice)', () => {
101
119
  client: { description: '', specs: [] },
102
120
  server: {
103
121
  description: '',
104
- gwt: [
105
- {
106
- when: {
107
- commandRef: 'NotifyHost',
108
- exampleData: {
109
- hostId: 'host_123',
110
- notificationType: 'booking_request',
111
- priority: 'high',
112
- channels: ['email', 'push'],
113
- message: 'A guest has requested to book your place.',
114
- actionRequired: true,
115
- },
116
- },
117
- then: [
118
- {
119
- eventRef: 'HostNotified',
120
- exampleData: {
121
- bookingId: 'book_xyz789',
122
- hostId: 'host_123',
123
- notificationType: 'booking_request',
124
- channels: ['email', 'push'],
125
- message: 'hi.',
126
- notifiedAt: '2025-06-10T16:30:00.000Z',
127
- actionRequired: true,
122
+ specs: {
123
+ name: 'Notify host command',
124
+ rules: [
125
+ {
126
+ description: 'Should notify host successfully',
127
+ examples: [
128
+ {
129
+ description: 'Host notification sent successfully',
130
+ when: {
131
+ commandRef: 'NotifyHost',
132
+ exampleData: {
133
+ hostId: 'host_123',
134
+ notificationType: 'booking_request',
135
+ priority: 'high',
136
+ channels: ['email', 'push'],
137
+ message: 'A guest has requested to book your place.',
138
+ actionRequired: true,
139
+ },
140
+ },
141
+ then: [
142
+ {
143
+ eventRef: 'HostNotified',
144
+ exampleData: {
145
+ bookingId: 'book_xyz789',
146
+ hostId: 'host_123',
147
+ notificationType: 'booking_request',
148
+ channels: ['email', 'push'],
149
+ message: 'hi.',
150
+ notifiedAt: '2025-06-10T16:30:00.000Z',
151
+ actionRequired: true,
152
+ },
153
+ },
154
+ ],
128
155
  },
129
- },
130
- ],
131
- },
132
- ],
156
+ ],
157
+ },
158
+ ],
159
+ },
133
160
  },
134
161
  },
135
162
  ],
@@ -1,5 +1,12 @@
1
1
  <%
2
- const gwt = slice.server?.gwt?.[0];
2
+ // Extract the first example from specs/rules structure
3
+ const specs = slice.server?.specs;
4
+ const firstExample = specs?.rules?.flatMap(rule => rule.examples)[0] ?? null;
5
+ const gwt = firstExample ? {
6
+ given: firstExample.given,
7
+ when: firstExample.when,
8
+ then: firstExample.then
9
+ } : null;
3
10
  const when = Array.isArray(gwt?.when) ? gwt.when[0] : gwt?.when;
4
11
  const then = Array.isArray(gwt?.then) ? gwt.then[0] : gwt?.then;
5
12
 
@@ -19,27 +19,36 @@ const specVariant1: SpecsSchema = {
19
19
 
20
20
  server: {
21
21
  description: 'Handles creation logic',
22
- gwt: [
23
- {
24
- when: {
25
- commandRef: 'CreateItem',
26
- exampleData: {
27
- itemId: 'item_123',
28
- description: 'A new item',
29
- },
30
- },
31
- then: [
32
- {
33
- eventRef: 'ItemCreated',
34
- exampleData: {
35
- id: 'item_123',
36
- description: 'A new item',
37
- addedAt: '2024-01-15T10:00:00.000Z',
22
+ specs: {
23
+ name: 'User can create an item',
24
+ rules: [
25
+ {
26
+ description: 'Valid item data should create item successfully',
27
+ examples: [
28
+ {
29
+ description: 'User creates a new item with valid data',
30
+ when: {
31
+ commandRef: 'CreateItem',
32
+ exampleData: {
33
+ itemId: 'item_123',
34
+ description: 'A new item',
35
+ },
36
+ },
37
+ then: [
38
+ {
39
+ eventRef: 'ItemCreated',
40
+ exampleData: {
41
+ id: 'item_123',
42
+ description: 'A new item',
43
+ addedAt: '2024-01-15T10:00:00.000Z',
44
+ },
45
+ },
46
+ ],
38
47
  },
39
- },
40
- ],
41
- },
42
- ],
48
+ ],
49
+ },
50
+ ],
51
+ },
43
52
  },
44
53
  },
45
54
  {
@@ -70,30 +79,39 @@ const specVariant1: SpecsSchema = {
70
79
  },
71
80
  },
72
81
  ],
73
- gwt: [
74
- {
75
- given: [
76
- {
77
- eventRef: 'ItemCreated',
78
- exampleData: {
79
- id: 'item_123',
80
- description: 'A new item',
81
- addedAt: '2024-01-15T10:00:00.000Z',
82
+ specs: {
83
+ name: 'Items are available for viewing',
84
+ rules: [
85
+ {
86
+ description: 'Item becomes available after creation event',
87
+ examples: [
88
+ {
89
+ description: 'ItemCreated event makes item available',
90
+ when: [
91
+ {
92
+ eventRef: 'ItemCreated',
93
+ exampleData: {
94
+ id: 'item_123',
95
+ description: 'A new item',
96
+ addedAt: '2024-01-15T10:00:00.000Z',
97
+ },
98
+ },
99
+ ],
100
+ then: [
101
+ {
102
+ stateRef: 'AvailableItems',
103
+ exampleData: {
104
+ id: 'item_123',
105
+ description: 'A new item',
106
+ addedAt: '2024-01-15T10:00:00.000Z',
107
+ },
108
+ },
109
+ ],
82
110
  },
83
- },
84
- ],
85
- then: [
86
- {
87
- stateRef: 'AvailableItems',
88
- exampleData: {
89
- id: 'item_123',
90
- description: 'A new item',
91
- addedAt: '2024-01-15T10:00:00.000Z',
92
- },
93
- },
94
- ],
95
- },
96
- ],
111
+ ],
112
+ },
113
+ ],
114
+ },
97
115
  },
98
116
  },
99
117
  {
@@ -102,29 +120,38 @@ const specVariant1: SpecsSchema = {
102
120
  description: 'Sends a notification command when a new item is created',
103
121
  server: {
104
122
  description: 'Triggers NotifyNewItem command in response to ItemCreated',
105
- gwt: [
106
- {
107
- when: [
108
- {
109
- eventRef: 'ItemCreated',
110
- exampleData: {
111
- id: 'item_123',
112
- description: 'A new item',
113
- addedAt: '2024-01-15T10:00:00.000Z',
114
- },
115
- },
116
- ],
117
- then: [
118
- {
119
- commandRef: 'NotifyNewItem',
120
- exampleData: {
121
- itemId: 'item_123',
122
- message: 'A new item was added to the system.',
123
+ specs: {
124
+ name: 'Notify on new item creation',
125
+ rules: [
126
+ {
127
+ description: 'Should send notification when item is created',
128
+ examples: [
129
+ {
130
+ description: 'ItemCreated event triggers notification command',
131
+ when: [
132
+ {
133
+ eventRef: 'ItemCreated',
134
+ exampleData: {
135
+ id: 'item_123',
136
+ description: 'A new item',
137
+ addedAt: '2024-01-15T10:00:00.000Z',
138
+ },
139
+ },
140
+ ],
141
+ then: [
142
+ {
143
+ commandRef: 'NotifyNewItem',
144
+ exampleData: {
145
+ itemId: 'item_123',
146
+ message: 'A new item was added to the system.',
147
+ },
148
+ },
149
+ ],
123
150
  },
124
- },
125
- ],
126
- },
127
- ],
151
+ ],
152
+ },
153
+ ],
154
+ },
128
155
  },
129
156
  },
130
157
  ],
@@ -1,4 +1,4 @@
1
- import { CommandExample, EventExample } from '@auto-engineer/flow';
1
+ import { CommandExample, EventExample, StateExample } from '@auto-engineer/flow';
2
2
 
3
3
  export interface Message {
4
4
  type: string;
@@ -29,7 +29,7 @@ export interface MessageDefinition {
29
29
  }
30
30
 
31
31
  export interface GwtCondition {
32
- given?: EventExample[];
33
- when: CommandExample;
34
- then: Array<EventExample | { errorType: string; message?: string }>;
32
+ given?: Array<EventExample | StateExample>;
33
+ when: CommandExample | EventExample[];
34
+ then: Array<EventExample | StateExample | CommandExample | { errorType: string; message?: string }>;
35
35
  }
@@ -11,6 +11,7 @@ import { fileURLToPath } from 'url';
11
11
  import { dirname } from 'path';
12
12
  import { execa } from 'execa';
13
13
  import createDebug from 'debug';
14
+ import { defineCommandHandler } from '@auto-engineer/message-bus';
14
15
 
15
16
  const debug = createDebug('emmett:generate-server');
16
17
  const debugSchema = createDebug('emmett:generate-server:schema');
@@ -18,17 +19,6 @@ const debugFiles = createDebug('emmett:generate-server:files');
18
19
  const debugDeps = createDebug('emmett:generate-server:deps');
19
20
  const debugScaffold = createDebug('emmett:generate-server:scaffold');
20
21
 
21
- export const generateServerManifest = {
22
- handler: () => Promise.resolve({ default: generateServerCommandHandler }),
23
- description: 'Generate server from schema.json',
24
- usage: 'generate:server <schema> <dest>',
25
- examples: ['$ auto generate:server .context/schema.json .'],
26
- args: [
27
- { name: 'schema', description: 'Path to schema.json file', required: true },
28
- { name: 'dest', description: 'Destination directory for generated server', required: true },
29
- ],
30
- };
31
-
32
22
  type DefaultRecord = Record<string, unknown>;
33
23
  export type Command<CommandType extends string = string, CommandData extends DefaultRecord = DefaultRecord> = Readonly<{
34
24
  type: CommandType;
@@ -79,6 +69,33 @@ export type ServerGenerationFailedEvent = Event<
79
69
  }
80
70
  >;
81
71
 
72
+ export const commandHandler = defineCommandHandler<GenerateServerCommand>({
73
+ name: 'GenerateServer',
74
+ alias: 'generate:server',
75
+ description: 'Generate server from schema.json',
76
+ category: 'generate',
77
+ fields: {
78
+ schemaPath: {
79
+ description: 'Path to schema.json file',
80
+ required: true,
81
+ },
82
+ destination: {
83
+ description: 'Destination directory for generated server',
84
+ required: true,
85
+ },
86
+ },
87
+ examples: ['$ auto generate:server --schema-path=.context/schema.json --destination=.'],
88
+ handle: async (command: GenerateServerCommand): Promise<ServerGeneratedEvent | ServerGenerationFailedEvent> => {
89
+ const result = await handleGenerateServerCommandInternal(command);
90
+ if (result.type === 'ServerGenerated') {
91
+ debug('Server generated at %s', result.data.serverDir);
92
+ } else {
93
+ debug('Failed to generate server: %s', result.data.error);
94
+ }
95
+ return result;
96
+ },
97
+ });
98
+
82
99
  async function validateSchemaFile(
83
100
  absSchema: string,
84
101
  command: GenerateServerCommand,
@@ -267,22 +284,6 @@ async function handleGenerateServerCommandInternal(
267
284
  }
268
285
  }
269
286
 
270
- export const generateServerCommandHandler: CommandHandler<
271
- GenerateServerCommand,
272
- ServerGeneratedEvent | ServerGenerationFailedEvent
273
- > = {
274
- name: 'GenerateServer',
275
- handle: async (command: GenerateServerCommand): Promise<ServerGeneratedEvent | ServerGenerationFailedEvent> => {
276
- const result = await handleGenerateServerCommandInternal(command);
277
- if (result.type === 'ServerGenerated') {
278
- debug('Server generated at %s', result.data.serverDir);
279
- } else {
280
- debug('Failed to generate server: %s', result.data.error);
281
- }
282
- return result;
283
- },
284
- };
285
-
286
287
  async function copyRootFilesFromSrc(from: string, to: string): Promise<void> {
287
288
  debugFiles('copyRootFilesFromSrc: from=%s, to=%s', from, to);
288
289
 
@@ -514,4 +515,4 @@ async function installDependenciesAndGenerateSchema(serverDir: string, workingDi
514
515
  }
515
516
 
516
517
  // Default export is the command handler
517
- export default generateServerCommandHandler;
518
+ export default commandHandler;
package/src/index.ts CHANGED
@@ -1,2 +1,8 @@
1
- export * from './commands/generate-server';
2
- export { CLI_MANIFEST } from './cli-manifest';
1
+ import { commandHandler as generateServerHandler } from './commands/generate-server';
2
+
3
+ export const COMMANDS = [generateServerHandler];
4
+ export {
5
+ type GenerateServerCommand,
6
+ type ServerGeneratedEvent,
7
+ type ServerGenerationFailedEvent,
8
+ } from './commands/generate-server';