@auto-engineer/narrative 0.13.0 → 0.13.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 (89) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +11 -0
  3. package/dist/src/commands/export-schema-runner.js +1 -1
  4. package/dist/src/commands/export-schema-runner.js.map +1 -1
  5. package/dist/src/fluent-builder.js +3 -3
  6. package/dist/src/fluent-builder.js.map +1 -1
  7. package/dist/src/getNarratives.specs.js +149 -153
  8. package/dist/src/getNarratives.specs.js.map +1 -1
  9. package/dist/src/id/addAutoIds.d.ts.map +1 -1
  10. package/dist/src/id/addAutoIds.js +23 -10
  11. package/dist/src/id/addAutoIds.js.map +1 -1
  12. package/dist/src/id/addAutoIds.specs.js +54 -45
  13. package/dist/src/id/addAutoIds.specs.js.map +1 -1
  14. package/dist/src/id/hasAllIds.d.ts.map +1 -1
  15. package/dist/src/id/hasAllIds.js +8 -3
  16. package/dist/src/id/hasAllIds.js.map +1 -1
  17. package/dist/src/id/hasAllIds.specs.js +142 -215
  18. package/dist/src/id/hasAllIds.specs.js.map +1 -1
  19. package/dist/src/index.d.ts +6 -8
  20. package/dist/src/index.d.ts.map +1 -1
  21. package/dist/src/index.js +3 -3
  22. package/dist/src/index.js.map +1 -1
  23. package/dist/src/loader/graph.d.ts.map +1 -1
  24. package/dist/src/loader/graph.js +13 -6
  25. package/dist/src/loader/graph.js.map +1 -1
  26. package/dist/src/loader/ts-utils.d.ts +1 -0
  27. package/dist/src/loader/ts-utils.d.ts.map +1 -1
  28. package/dist/src/loader/ts-utils.js +95 -16
  29. package/dist/src/loader/ts-utils.js.map +1 -1
  30. package/dist/src/model-to-narrative.specs.js +531 -449
  31. package/dist/src/model-to-narrative.specs.js.map +1 -1
  32. package/dist/src/narrative-context.d.ts +8 -8
  33. package/dist/src/narrative-context.d.ts.map +1 -1
  34. package/dist/src/narrative-context.js +111 -301
  35. package/dist/src/narrative-context.js.map +1 -1
  36. package/dist/src/narrative-context.specs.js +15 -55
  37. package/dist/src/narrative-context.specs.js.map +1 -1
  38. package/dist/src/narrative.d.ts +19 -22
  39. package/dist/src/narrative.d.ts.map +1 -1
  40. package/dist/src/narrative.js +42 -71
  41. package/dist/src/narrative.js.map +1 -1
  42. package/dist/src/samples/test-with-ids.narrative.js +13 -29
  43. package/dist/src/samples/test-with-ids.narrative.js.map +1 -1
  44. package/dist/src/schema.d.ts +2704 -8293
  45. package/dist/src/schema.d.ts.map +1 -1
  46. package/dist/src/schema.js +26 -47
  47. package/dist/src/schema.js.map +1 -1
  48. package/dist/src/slice-builder.js +3 -3
  49. package/dist/src/slice-builder.js.map +1 -1
  50. package/dist/src/transformers/model-to-narrative/generators/flow.d.ts.map +1 -1
  51. package/dist/src/transformers/model-to-narrative/generators/flow.js +118 -74
  52. package/dist/src/transformers/model-to-narrative/generators/flow.js.map +1 -1
  53. package/dist/src/transformers/model-to-narrative/generators/gwt.d.ts +9 -1
  54. package/dist/src/transformers/model-to-narrative/generators/gwt.d.ts.map +1 -1
  55. package/dist/src/transformers/model-to-narrative/generators/gwt.js +112 -112
  56. package/dist/src/transformers/model-to-narrative/generators/gwt.js.map +1 -1
  57. package/dist/src/transformers/model-to-narrative/generators/imports.d.ts +1 -1
  58. package/dist/src/transformers/model-to-narrative/generators/imports.d.ts.map +1 -1
  59. package/dist/src/transformers/model-to-narrative/generators/imports.js +13 -9
  60. package/dist/src/transformers/model-to-narrative/generators/imports.js.map +1 -1
  61. package/dist/src/transformers/narrative-to-model/index.d.ts.map +1 -1
  62. package/dist/src/transformers/narrative-to-model/index.js +50 -23
  63. package/dist/src/transformers/narrative-to-model/index.js.map +1 -1
  64. package/dist/src/transformers/narrative-to-model/type-inference.specs.js +100 -90
  65. package/dist/src/transformers/narrative-to-model/type-inference.specs.js.map +1 -1
  66. package/dist/tsconfig.tsbuildinfo +1 -1
  67. package/package.json +5 -5
  68. package/src/commands/export-schema-runner.ts +3 -1
  69. package/src/fluent-builder.ts +3 -3
  70. package/src/getNarratives.specs.ts +168 -176
  71. package/src/id/addAutoIds.specs.ts +54 -47
  72. package/src/id/addAutoIds.ts +28 -11
  73. package/src/id/hasAllIds.specs.ts +147 -245
  74. package/src/id/hasAllIds.ts +11 -4
  75. package/src/index.ts +9 -12
  76. package/src/loader/graph.ts +23 -6
  77. package/src/loader/ts-utils.ts +169 -26
  78. package/src/model-to-narrative.specs.ts +531 -449
  79. package/src/narrative-context.specs.ts +73 -116
  80. package/src/narrative-context.ts +127 -374
  81. package/src/narrative.ts +70 -120
  82. package/src/samples/test-with-ids.narrative.ts +23 -31
  83. package/src/schema.ts +33 -52
  84. package/src/slice-builder.ts +3 -3
  85. package/src/transformers/model-to-narrative/generators/flow.ts +191 -85
  86. package/src/transformers/model-to-narrative/generators/gwt.ts +195 -178
  87. package/src/transformers/model-to-narrative/generators/imports.ts +13 -9
  88. package/src/transformers/narrative-to-model/index.ts +87 -26
  89. package/src/transformers/narrative-to-model/type-inference.specs.ts +100 -90
@@ -1,56 +1,59 @@
1
1
  import { describe, it, expect, beforeEach } from 'vitest';
2
2
  import { flow, example, rule, specs } from './narrative';
3
3
  import { command } from './fluent-builder';
4
+ import { type Event, type State } from './types';
4
5
 
5
- interface QuestionnaireLinkSent {
6
- questionnaireId: string;
7
- participantId: string;
8
- link: string;
9
- sentAt: Date;
10
- }
6
+ type QuestionnaireLinkSent = Event<
7
+ 'QuestionnaireLinkSent',
8
+ {
9
+ questionnaireId: string;
10
+ participantId: string;
11
+ link: string;
12
+ sentAt: Date;
13
+ }
14
+ >;
11
15
 
12
- interface QuestionAnswered {
13
- questionnaireId: string;
14
- participantId: string;
15
- questionId: string;
16
- answer: string;
17
- savedAt: Date;
18
- }
16
+ type QuestionAnswered = Event<
17
+ 'QuestionAnswered',
18
+ {
19
+ questionnaireId: string;
20
+ participantId: string;
21
+ questionId: string;
22
+ answer: string;
23
+ savedAt: Date;
24
+ }
25
+ >;
19
26
 
20
- interface QuestionnaireProgress {
21
- questionnaireId: string;
22
- participantId: string;
23
- status: string;
24
- currentQuestionId: string;
25
- remainingQuestions: string[];
26
- answers: { questionId: string; value: string }[];
27
- }
27
+ type QuestionnaireProgress = State<
28
+ 'QuestionnaireProgress',
29
+ {
30
+ questionnaireId: string;
31
+ participantId: string;
32
+ status: string;
33
+ currentQuestionId: string;
34
+ remainingQuestions: string[];
35
+ answers: { questionId: string; value: string }[];
36
+ }
37
+ >;
28
38
 
29
- describe('Context Parameter Support', () => {
39
+ describe('Narrative DSL', () => {
30
40
  beforeEach(async () => {
31
41
  // Clean test state before each test
32
42
  });
33
43
 
34
- it('should support context parameter in given() method', () => {
44
+ it('should support given() method in builder', () => {
35
45
  expect(() => {
36
- flow('test flow with context', () => {
46
+ flow('test flow with given', () => {
37
47
  command('test command').server(() => {
38
48
  specs(() => {
39
- rule('test rule with context', () => {
40
- example('given with context')
41
- .given<QuestionnaireLinkSent>(
42
- {
43
- questionnaireId: 'q-001',
44
- participantId: 'participant-abc',
45
- link: 'https://app.example.com/q/q-001?participant=participant-abc',
46
- sentAt: new Date('2030-01-01T09:00:00Z'),
47
- },
48
- {
49
- sentAt: 'comes from the system clock',
50
- questionnaireId: 'must be a valid questionnaire ID',
51
- link: 'generated based on questionnaire and participant',
52
- },
53
- )
49
+ rule('test rule with given', () => {
50
+ example('given test')
51
+ .given<QuestionnaireLinkSent>({
52
+ questionnaireId: 'q-001',
53
+ participantId: 'participant-abc',
54
+ link: 'https://app.example.com/q/q-001?participant=participant-abc',
55
+ sentAt: new Date('2030-01-01T09:00:00Z'),
56
+ })
54
57
  .when<QuestionAnswered>({
55
58
  questionnaireId: 'q-001',
56
59
  participantId: 'participant-abc',
@@ -73,32 +76,26 @@ describe('Context Parameter Support', () => {
73
76
  }).not.toThrow();
74
77
  });
75
78
 
76
- it('should support context parameter in when() method', () => {
79
+ it('should support when() method in builder', () => {
77
80
  expect(() => {
78
- flow('test flow with when context', () => {
81
+ flow('test flow with when', () => {
79
82
  command('test command').server(() => {
80
83
  specs(() => {
81
84
  rule('test rule', () => {
82
- example('when with context')
85
+ example('when test')
83
86
  .given<QuestionnaireLinkSent>({
84
87
  questionnaireId: 'q-001',
85
88
  participantId: 'participant-abc',
86
89
  link: 'https://app.example.com/q/q-001?participant=participant-abc',
87
90
  sentAt: new Date('2030-01-01T09:00:00Z'),
88
91
  })
89
- .when<QuestionAnswered>(
90
- {
91
- questionnaireId: 'q-001',
92
- participantId: 'participant-abc',
93
- questionId: 'q1',
94
- answer: 'Yes',
95
- savedAt: new Date('2030-01-01T09:05:00Z'),
96
- },
97
- {
98
- answer: 'must be validated according to the question type',
99
- savedAt: 'timestamp when the answer was saved',
100
- },
101
- )
92
+ .when<QuestionAnswered>({
93
+ questionnaireId: 'q-001',
94
+ participantId: 'participant-abc',
95
+ questionId: 'q1',
96
+ answer: 'Yes',
97
+ savedAt: new Date('2030-01-01T09:05:00Z'),
98
+ })
102
99
  .then<QuestionnaireProgress>({
103
100
  questionnaireId: 'q-001',
104
101
  participantId: 'participant-abc',
@@ -114,13 +111,13 @@ describe('Context Parameter Support', () => {
114
111
  }).not.toThrow();
115
112
  });
116
113
 
117
- it('should support context parameter in then() method', () => {
114
+ it('should support then() method in builder', () => {
118
115
  expect(() => {
119
- flow('test flow with then context', () => {
116
+ flow('test flow with then', () => {
120
117
  command('test command').server(() => {
121
118
  specs(() => {
122
119
  rule('test rule', () => {
123
- example('then with context')
120
+ example('then test')
124
121
  .given<QuestionnaireLinkSent>({
125
122
  questionnaireId: 'q-001',
126
123
  participantId: 'participant-abc',
@@ -134,21 +131,14 @@ describe('Context Parameter Support', () => {
134
131
  answer: 'Yes',
135
132
  savedAt: new Date('2030-01-01T09:05:00Z'),
136
133
  })
137
- .then<QuestionnaireProgress>(
138
- {
139
- questionnaireId: 'q-001',
140
- participantId: 'participant-abc',
141
- status: 'in_progress',
142
- currentQuestionId: 'q2',
143
- remainingQuestions: ['q2'],
144
- answers: [{ questionId: 'q1', value: 'Yes' }],
145
- },
146
- {
147
- answers: 'computed from the answered questions',
148
- status: 'calculated based on completed questions',
149
- currentQuestionId: 'next question to be answered',
150
- },
151
- );
134
+ .then<QuestionnaireProgress>({
135
+ questionnaireId: 'q-001',
136
+ participantId: 'participant-abc',
137
+ status: 'in_progress',
138
+ currentQuestionId: 'q2',
139
+ remainingQuestions: ['q2'],
140
+ answers: [{ questionId: 'q1', value: 'Yes' }],
141
+ });
152
142
  });
153
143
  });
154
144
  });
@@ -156,27 +146,19 @@ describe('Context Parameter Support', () => {
156
146
  }).not.toThrow();
157
147
  });
158
148
 
159
- it('should preserve context data in schema output', async () => {
160
- // This test would require a proper file system setup to work with getNarratives
161
- // For now, we'll just test that the methods accept context parameters
149
+ it('should support full narrative DSL flow', () => {
162
150
  expect(() => {
163
- flow('test context preservation', () => {
151
+ flow('test full DSL flow', () => {
164
152
  command('test preservation').server(() => {
165
153
  specs(() => {
166
- rule('context preservation rule', () => {
167
- example('context should be preserved')
168
- .given<QuestionnaireLinkSent>(
169
- {
170
- questionnaireId: 'q-001',
171
- participantId: 'participant-abc',
172
- link: 'https://app.example.com/q/q-001?participant=participant-abc',
173
- sentAt: new Date('2030-01-01T09:00:00Z'),
174
- },
175
- {
176
- sentAt: 'comes from the system clock',
177
- questionnaireId: 'validated questionnaire identifier',
178
- },
179
- )
154
+ rule('full flow rule', () => {
155
+ example('full flow test')
156
+ .given<QuestionnaireLinkSent>({
157
+ questionnaireId: 'q-001',
158
+ participantId: 'participant-abc',
159
+ link: 'https://app.example.com/q/q-001?participant=participant-abc',
160
+ sentAt: new Date('2030-01-01T09:00:00Z'),
161
+ })
180
162
  .when<QuestionAnswered>({
181
163
  questionnaireId: 'q-001',
182
164
  participantId: 'participant-abc',
@@ -198,29 +180,4 @@ describe('Context Parameter Support', () => {
198
180
  });
199
181
  }).not.toThrow();
200
182
  });
201
-
202
- // These tests should fail with TypeScript compilation errors
203
- // Commenting out for now - they will be used to verify strict typing works
204
- /*
205
- it('should reject invalid context fields (compilation test)', () => {
206
- // This should cause a TypeScript error - invalidField is not in QuestionnaireLinkSent
207
- flow('invalid context test', () => {
208
- command('test').server(() => {
209
- specs(() => {
210
- rule('test rule', () => {
211
- example('invalid context')
212
- .given<QuestionnaireLinkSent>({
213
- questionnaireId: 'q-001',
214
- participantId: 'participant-abc',
215
- link: 'https://app.example.com',
216
- sentAt: new Date(),
217
- }, {
218
- invalidField: 'this should cause a type error' // TypeScript error expected
219
- });
220
- });
221
- });
222
- });
223
- });
224
- });
225
- */
226
183
  });