@auto-engineer/narrative 1.5.5 → 1.7.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/package.json CHANGED
@@ -23,9 +23,9 @@
23
23
  "typescript": "^5.9.2",
24
24
  "zod": "^3.22.4",
25
25
  "zod-to-json-schema": "^3.22.3",
26
- "@auto-engineer/file-store": "1.5.5",
27
- "@auto-engineer/message-bus": "1.5.5",
28
- "@auto-engineer/id": "1.5.5"
26
+ "@auto-engineer/file-store": "1.7.0",
27
+ "@auto-engineer/id": "1.7.0",
28
+ "@auto-engineer/message-bus": "1.7.0"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/node": "^20.0.0",
@@ -35,7 +35,7 @@
35
35
  "publishConfig": {
36
36
  "access": "public"
37
37
  },
38
- "version": "1.5.5",
38
+ "version": "1.7.0",
39
39
  "scripts": {
40
40
  "build": "tsx scripts/build.ts",
41
41
  "test": "vitest run --reporter=dot",
package/src/index.ts CHANGED
@@ -74,6 +74,8 @@ export {
74
74
  ExampleSchema,
75
75
  ExperienceSliceSchema,
76
76
  IntegrationSchema,
77
+ MappingEntrySchema,
78
+ MappingFieldRefSchema,
77
79
  MessageFieldSchema,
78
80
  MessageRefSchema,
79
81
  MessageSchema,
@@ -105,6 +107,8 @@ import type {
105
107
  CommandSliceSchema,
106
108
  ExampleSchema,
107
109
  ExperienceSliceSchema,
110
+ MappingEntrySchema,
111
+ MappingFieldRefSchema,
108
112
  MessageFieldSchema,
109
113
  MessageRefSchema,
110
114
  MessageSchema,
@@ -133,6 +137,8 @@ export type Spec = z.infer<typeof SpecSchema>;
133
137
  export type Step = z.infer<typeof StepSchema>;
134
138
  export type Module = z.infer<typeof ModuleSchema>;
135
139
  export type MessageRef = z.infer<typeof MessageRefSchema>;
140
+ export type MappingFieldRef = z.infer<typeof MappingFieldRefSchema>;
141
+ export type MappingEntry = z.infer<typeof MappingEntrySchema>;
136
142
 
137
143
  // ID assignment utilities
138
144
  export { addAutoIds, hasAllIds } from './id';
@@ -2,39 +2,59 @@ import { describe, expect, it } from 'vitest';
2
2
  import { CommandSliceSchema, QuerySliceSchema } from './schema';
3
3
 
4
4
  describe('CommandSliceSchema', () => {
5
- it('should accept optional mappings field', () => {
5
+ it('should accept optional mappings field with structured entries', () => {
6
6
  const slice = {
7
7
  type: 'command' as const,
8
8
  name: 'Create User',
9
9
  client: { specs: [] },
10
10
  server: { description: 'Creates a user', specs: [] },
11
- mappings: 'userId -> user.id',
11
+ mappings: [
12
+ {
13
+ source: { type: 'Command' as const, name: 'CreateUser', field: 'userId' },
14
+ target: { type: 'Event' as const, name: 'UserCreated', field: 'id' },
15
+ },
16
+ ],
12
17
  };
13
18
 
14
19
  const result = CommandSliceSchema.safeParse(slice);
15
20
 
16
21
  expect(result.success).toBe(true);
17
22
  if (result.success) {
18
- expect(result.data.mappings).toBe('userId -> user.id');
23
+ expect(result.data.mappings).toEqual([
24
+ {
25
+ source: { type: 'Command', name: 'CreateUser', field: 'userId' },
26
+ target: { type: 'Event', name: 'UserCreated', field: 'id' },
27
+ },
28
+ ]);
19
29
  }
20
30
  });
21
31
  });
22
32
 
23
33
  describe('QuerySliceSchema', () => {
24
- it('should accept optional mappings field', () => {
34
+ it('should accept optional mappings field with structured entries', () => {
25
35
  const slice = {
26
36
  type: 'query' as const,
27
37
  name: 'Get Users',
28
38
  client: { specs: [] },
29
39
  server: { description: 'Gets users', specs: [] },
30
- mappings: 'users -> response.data',
40
+ mappings: [
41
+ {
42
+ source: { type: 'State' as const, name: 'UsersProjection', field: 'users' },
43
+ target: { type: 'Query' as const, name: 'GetUsers', field: 'data' },
44
+ },
45
+ ],
31
46
  };
32
47
 
33
48
  const result = QuerySliceSchema.safeParse(slice);
34
49
 
35
50
  expect(result.success).toBe(true);
36
51
  if (result.success) {
37
- expect(result.data.mappings).toBe('users -> response.data');
52
+ expect(result.data.mappings).toEqual([
53
+ {
54
+ source: { type: 'State', name: 'UsersProjection', field: 'users' },
55
+ target: { type: 'Query', name: 'GetUsers', field: 'data' },
56
+ },
57
+ ]);
38
58
  }
39
59
  });
40
60
  });
package/src/schema.ts CHANGED
@@ -180,6 +180,21 @@ const QuerySchema = BaseMessageSchema.extend({
180
180
 
181
181
  const MessageSchema = z.discriminatedUnion('type', [CommandSchema, EventSchema, StateSchema, QuerySchema]);
182
182
 
183
+ export const MappingFieldRefSchema = z
184
+ .object({
185
+ type: z.enum(['Command', 'Event', 'State', 'Query']).describe('Message kind'),
186
+ name: z.string().describe('Message name'),
187
+ field: z.string().describe('Field name within the message'),
188
+ })
189
+ .describe('Reference to a specific field within a message type');
190
+
191
+ export const MappingEntrySchema = z
192
+ .object({
193
+ source: MappingFieldRefSchema.describe('Source field reference'),
194
+ target: MappingFieldRefSchema.describe('Target field reference'),
195
+ })
196
+ .describe('Mapping entry linking a source field to a target field');
197
+
183
198
  const BaseSliceSchema = z
184
199
  .object({
185
200
  name: z.string(),
@@ -270,7 +285,7 @@ const CommandSliceSchema = BaseSliceSchema.extend({
270
285
  specs: ClientSpecSchema,
271
286
  }),
272
287
  request: z.string().describe('Command request (GraphQL, REST endpoint, or other query format)').optional(),
273
- mappings: z.string().describe('Field mappings between Command/Event/State messages').optional(),
288
+ mappings: z.array(MappingEntrySchema).optional().describe('Field mappings between Command/Event/State messages'),
274
289
  server: z.object({
275
290
  description: z.string(),
276
291
  data: DataSchema.optional().describe('Data configuration for command slices'),
@@ -284,7 +299,7 @@ const QuerySliceSchema = BaseSliceSchema.extend({
284
299
  specs: ClientSpecSchema,
285
300
  }),
286
301
  request: z.string().describe('Query request (GraphQL, REST endpoint, or other query format)').optional(),
287
- mappings: z.string().describe('Field mappings between Command/Event/State messages').optional(),
302
+ mappings: z.array(MappingEntrySchema).optional().describe('Field mappings between Command/Event/State messages'),
288
303
  server: z.object({
289
304
  description: z.string(),
290
305
  data: DataSchema.optional().describe('Data configuration for query slices'),