@auto-engineer/narrative 0.12.1 → 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.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +24 -0
- package/dist/src/commands/export-schema-runner.js +1 -1
- package/dist/src/commands/export-schema-runner.js.map +1 -1
- package/dist/src/fluent-builder.js +3 -3
- package/dist/src/fluent-builder.js.map +1 -1
- package/dist/src/getNarratives.specs.js +157 -161
- package/dist/src/getNarratives.specs.js.map +1 -1
- package/dist/src/id/addAutoIds.d.ts.map +1 -1
- package/dist/src/id/addAutoIds.js +23 -10
- package/dist/src/id/addAutoIds.js.map +1 -1
- package/dist/src/id/addAutoIds.specs.js +55 -46
- package/dist/src/id/addAutoIds.specs.js.map +1 -1
- package/dist/src/id/generators.js +1 -1
- package/dist/src/id/generators.js.map +1 -1
- package/dist/src/id/hasAllIds.d.ts.map +1 -1
- package/dist/src/id/hasAllIds.js +8 -3
- package/dist/src/id/hasAllIds.js.map +1 -1
- package/dist/src/id/hasAllIds.specs.js +142 -215
- package/dist/src/id/hasAllIds.specs.js.map +1 -1
- package/dist/src/index.d.ts +7 -8
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -3
- package/dist/src/index.js.map +1 -1
- package/dist/src/loader/graph.d.ts.map +1 -1
- package/dist/src/loader/graph.js +13 -6
- package/dist/src/loader/graph.js.map +1 -1
- package/dist/src/loader/ts-utils.d.ts +1 -0
- package/dist/src/loader/ts-utils.d.ts.map +1 -1
- package/dist/src/loader/ts-utils.js +95 -16
- package/dist/src/loader/ts-utils.js.map +1 -1
- package/dist/src/model-to-narrative.specs.js +548 -466
- package/dist/src/model-to-narrative.specs.js.map +1 -1
- package/dist/src/narrative-context.d.ts +8 -8
- package/dist/src/narrative-context.d.ts.map +1 -1
- package/dist/src/narrative-context.js +111 -301
- package/dist/src/narrative-context.js.map +1 -1
- package/dist/src/narrative-context.specs.js +15 -55
- package/dist/src/narrative-context.specs.js.map +1 -1
- package/dist/src/narrative.d.ts +19 -22
- package/dist/src/narrative.d.ts.map +1 -1
- package/dist/src/narrative.js +42 -71
- package/dist/src/narrative.js.map +1 -1
- package/dist/src/samples/questionnaires.narrative.js +10 -10
- package/dist/src/samples/questionnaires.narrative.js.map +1 -1
- package/dist/src/samples/test-with-ids.narrative.js +13 -29
- package/dist/src/samples/test-with-ids.narrative.js.map +1 -1
- package/dist/src/schema.d.ts +2704 -8293
- package/dist/src/schema.d.ts.map +1 -1
- package/dist/src/schema.js +26 -47
- package/dist/src/schema.js.map +1 -1
- package/dist/src/slice-builder.js +3 -3
- package/dist/src/slice-builder.js.map +1 -1
- package/dist/src/transformers/model-to-narrative/generators/flow.d.ts.map +1 -1
- package/dist/src/transformers/model-to-narrative/generators/flow.js +118 -74
- package/dist/src/transformers/model-to-narrative/generators/flow.js.map +1 -1
- package/dist/src/transformers/model-to-narrative/generators/gwt.d.ts +9 -1
- package/dist/src/transformers/model-to-narrative/generators/gwt.d.ts.map +1 -1
- package/dist/src/transformers/model-to-narrative/generators/gwt.js +112 -112
- package/dist/src/transformers/model-to-narrative/generators/gwt.js.map +1 -1
- package/dist/src/transformers/model-to-narrative/generators/imports.d.ts +1 -1
- package/dist/src/transformers/model-to-narrative/generators/imports.d.ts.map +1 -1
- package/dist/src/transformers/model-to-narrative/generators/imports.js +13 -9
- package/dist/src/transformers/model-to-narrative/generators/imports.js.map +1 -1
- package/dist/src/transformers/narrative-to-model/index.d.ts.map +1 -1
- package/dist/src/transformers/narrative-to-model/index.js +50 -23
- package/dist/src/transformers/narrative-to-model/index.js.map +1 -1
- package/dist/src/transformers/narrative-to-model/type-inference.specs.js +100 -90
- package/dist/src/transformers/narrative-to-model/type-inference.specs.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/src/commands/export-schema-runner.ts +3 -1
- package/src/fluent-builder.ts +3 -3
- package/src/getNarratives.specs.ts +176 -184
- package/src/id/addAutoIds.specs.ts +55 -48
- package/src/id/addAutoIds.ts +28 -11
- package/src/id/generators.ts +1 -1
- package/src/id/hasAllIds.specs.ts +147 -245
- package/src/id/hasAllIds.ts +11 -4
- package/src/index.ts +11 -12
- package/src/loader/graph.ts +23 -6
- package/src/loader/ts-utils.ts +169 -26
- package/src/model-to-narrative.specs.ts +548 -466
- package/src/narrative-context.specs.ts +73 -116
- package/src/narrative-context.ts +127 -374
- package/src/narrative.ts +70 -120
- package/src/samples/questionnaires.narrative.ts +10 -10
- package/src/samples/test-with-ids.narrative.ts +23 -31
- package/src/schema.ts +33 -52
- package/src/slice-builder.ts +3 -3
- package/src/transformers/model-to-narrative/generators/flow.ts +191 -85
- package/src/transformers/model-to-narrative/generators/gwt.ts +195 -178
- package/src/transformers/model-to-narrative/generators/imports.ts +13 -9
- package/src/transformers/narrative-to-model/index.ts +87 -26
- 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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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('
|
|
39
|
+
describe('Narrative DSL', () => {
|
|
30
40
|
beforeEach(async () => {
|
|
31
41
|
// Clean test state before each test
|
|
32
42
|
});
|
|
33
43
|
|
|
34
|
-
it('should support
|
|
44
|
+
it('should support given() method in builder', () => {
|
|
35
45
|
expect(() => {
|
|
36
|
-
flow('test flow with
|
|
46
|
+
flow('test flow with given', () => {
|
|
37
47
|
command('test command').server(() => {
|
|
38
48
|
specs(() => {
|
|
39
|
-
rule('test rule with
|
|
40
|
-
example('given
|
|
41
|
-
.given<QuestionnaireLinkSent>(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
|
79
|
+
it('should support when() method in builder', () => {
|
|
77
80
|
expect(() => {
|
|
78
|
-
flow('test flow with when
|
|
81
|
+
flow('test flow with when', () => {
|
|
79
82
|
command('test command').server(() => {
|
|
80
83
|
specs(() => {
|
|
81
84
|
rule('test rule', () => {
|
|
82
|
-
example('when
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
|
114
|
+
it('should support then() method in builder', () => {
|
|
118
115
|
expect(() => {
|
|
119
|
-
flow('test flow with then
|
|
116
|
+
flow('test flow with then', () => {
|
|
120
117
|
command('test command').server(() => {
|
|
121
118
|
specs(() => {
|
|
122
119
|
rule('test rule', () => {
|
|
123
|
-
example('then
|
|
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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
|
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
|
|
151
|
+
flow('test full DSL flow', () => {
|
|
164
152
|
command('test preservation').server(() => {
|
|
165
153
|
specs(() => {
|
|
166
|
-
rule('
|
|
167
|
-
example('
|
|
168
|
-
.given<QuestionnaireLinkSent>(
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
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
|
});
|