@step-forge/step-forge 0.0.14 → 0.0.16

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.
@@ -8,6 +8,31 @@ type EmptyDependencies = {
8
8
  then: EmptyObject;
9
9
  };
10
10
  //#endregion
11
+ //#region src/parsers.d.ts
12
+ /**
13
+ * A Parser maps a Cucumber expression placeholder to a typed value.
14
+ *
15
+ * `gherkin` is the Cucumber Expression placeholder used when registering the
16
+ * step (e.g. `{int}`). `parse` converts the raw value Cucumber captures into
17
+ * the desired TypeScript type.
18
+ *
19
+ * Note: Cucumber Expressions already transform `{int}`/`{float}` captures into
20
+ * JS numbers before the step function runs, so `parse` receives an `unknown`
21
+ * and must tolerate both the pre-transformed value and a raw string.
22
+ */
23
+ type Parser<T> = {
24
+ parse: (value: unknown) => T;
25
+ gherkin: string;
26
+ };
27
+ /** Matches a quoted string (`{string}`) and passes the unquoted contents through. */
28
+ declare const stringParser: Parser<string>;
29
+ /** Matches an unquoted integer (`{int}`). */
30
+ declare const intParser: Parser<number>;
31
+ /** Matches an unquoted floating point number (`{float}`). */
32
+ declare const numberParser: Parser<number>;
33
+ /** Matches an unquoted `true`/`false` word (`{word}`) and parses it to a boolean. */
34
+ declare const booleanParser: Parser<boolean>;
35
+ //#endregion
11
36
  //#region src/given.d.ts
12
37
  declare const givenBuilder: <GivenState>() => {
13
38
  statement: <Statement extends ((...args: [...any]) => string) | string>(statement: Statement) => {
@@ -21,6 +46,7 @@ declare const givenBuilder: <GivenState>() => {
21
46
  then: never;
22
47
  }) => Partial<GivenState> | Promise<Partial<GivenState>>) => {
23
48
  statement: Statement extends string ? () => string : Statement;
49
+ expression: string;
24
50
  dependencies: {
25
51
  given: GivenDeps;
26
52
  } & {
@@ -36,6 +62,7 @@ declare const givenBuilder: <GivenState>() => {
36
62
  }) => Partial<GivenState> | Promise<Partial<GivenState>>;
37
63
  register: () => {
38
64
  stepType: "given";
65
+ expression: string;
39
66
  dependencies: {
40
67
  given: GivenDeps;
41
68
  } & {
@@ -52,6 +79,80 @@ declare const givenBuilder: <GivenState>() => {
52
79
  };
53
80
  };
54
81
  };
82
+ parsers: <Parsers extends ((Statement extends string ? [] : GetFunctionArgs<Statement>) extends infer T ? { [K in keyof T]: Parser<(Statement extends string ? [] : GetFunctionArgs<Statement>)[K]> } : never)>(parsers: Parsers) => {
83
+ dependencies: <GivenDeps extends RequiredOrOptional<GivenState>>(dependencies: {
84
+ given: GivenDeps;
85
+ }) => {
86
+ step: (stepFunction: (input: {
87
+ variables: Statement extends string ? [] : GetFunctionArgs<Statement>;
88
+ given: { [K_1 in keyof GivenState as K_1 extends keyof GivenDeps ? K_1 : never]: GivenDeps[K_1] extends "optional" ? GivenState[K_1] | undefined : GivenState[K_1] };
89
+ when: never;
90
+ then: never;
91
+ }) => Partial<GivenState> | Promise<Partial<GivenState>>) => {
92
+ statement: Statement extends string ? () => string : Statement;
93
+ expression: string;
94
+ dependencies: {
95
+ given: GivenDeps;
96
+ } & {
97
+ when: EmptyObject;
98
+ then: EmptyObject;
99
+ };
100
+ stepType: "given";
101
+ stepFunction: (input: {
102
+ variables: Statement extends string ? [] : GetFunctionArgs<Statement>;
103
+ given: { [K_1 in keyof GivenState as K_1 extends keyof GivenDeps ? K_1 : never]: GivenDeps[K_1] extends "optional" ? GivenState[K_1] | undefined : GivenState[K_1] };
104
+ when: never;
105
+ then: never;
106
+ }) => Partial<GivenState> | Promise<Partial<GivenState>>;
107
+ register: () => {
108
+ stepType: "given";
109
+ expression: string;
110
+ dependencies: {
111
+ given: GivenDeps;
112
+ } & {
113
+ when: EmptyObject;
114
+ then: EmptyObject;
115
+ };
116
+ statement: Statement extends string ? () => string : Statement;
117
+ stepFunction: (input: {
118
+ variables: Statement extends string ? [] : GetFunctionArgs<Statement>;
119
+ given: { [K_1 in keyof GivenState as K_1 extends keyof GivenDeps ? K_1 : never]: GivenDeps[K_1] extends "optional" ? GivenState[K_1] | undefined : GivenState[K_1] };
120
+ when: never;
121
+ then: never;
122
+ }) => Partial<GivenState> | Promise<Partial<GivenState>>;
123
+ };
124
+ };
125
+ };
126
+ step: (stepFunction: (input: {
127
+ variables: Statement extends string ? [] : GetFunctionArgs<Statement>;
128
+ given: never;
129
+ when: never;
130
+ then: never;
131
+ }) => Partial<GivenState> | Promise<Partial<GivenState>>) => {
132
+ statement: Statement extends string ? () => string : Statement;
133
+ expression: string;
134
+ dependencies: EmptyDependencies;
135
+ stepType: "given";
136
+ stepFunction: (input: {
137
+ variables: Statement extends string ? [] : GetFunctionArgs<Statement>;
138
+ given: never;
139
+ when: never;
140
+ then: never;
141
+ }) => Partial<GivenState> | Promise<Partial<GivenState>>;
142
+ register: () => {
143
+ stepType: "given";
144
+ expression: string;
145
+ dependencies: EmptyDependencies;
146
+ statement: Statement extends string ? () => string : Statement;
147
+ stepFunction: (input: {
148
+ variables: Statement extends string ? [] : GetFunctionArgs<Statement>;
149
+ given: never;
150
+ when: never;
151
+ then: never;
152
+ }) => Partial<GivenState> | Promise<Partial<GivenState>>;
153
+ };
154
+ };
155
+ };
55
156
  step: (stepFunction: (input: {
56
157
  variables: Statement extends string ? [] : GetFunctionArgs<Statement>;
57
158
  given: never;
@@ -59,6 +160,7 @@ declare const givenBuilder: <GivenState>() => {
59
160
  then: never;
60
161
  }) => Partial<GivenState> | Promise<Partial<GivenState>>) => {
61
162
  statement: Statement extends string ? () => string : Statement;
163
+ expression: string;
62
164
  dependencies: EmptyDependencies;
63
165
  stepType: "given";
64
166
  stepFunction: (input: {
@@ -69,6 +171,7 @@ declare const givenBuilder: <GivenState>() => {
69
171
  }) => Partial<GivenState> | Promise<Partial<GivenState>>;
70
172
  register: () => {
71
173
  stepType: "given";
174
+ expression: string;
72
175
  dependencies: EmptyDependencies;
73
176
  statement: Statement extends string ? () => string : Statement;
74
177
  stepFunction: (input: {
@@ -96,6 +199,7 @@ declare const whenBuilder: <GivenState, WhenState>() => {
96
199
  then: never;
97
200
  }) => Partial<WhenState> | Promise<Partial<WhenState>>) => {
98
201
  statement: Statement extends string ? () => string : Statement;
202
+ expression: string;
99
203
  dependencies: {
100
204
  given: GivenDeps;
101
205
  when: WhenDeps;
@@ -110,6 +214,7 @@ declare const whenBuilder: <GivenState, WhenState>() => {
110
214
  }) => Partial<WhenState> | Promise<Partial<WhenState>>;
111
215
  register: () => {
112
216
  stepType: "when";
217
+ expression: string;
113
218
  dependencies: {
114
219
  given: GivenDeps;
115
220
  when: WhenDeps;
@@ -125,6 +230,79 @@ declare const whenBuilder: <GivenState, WhenState>() => {
125
230
  };
126
231
  };
127
232
  };
233
+ parsers: <Parsers extends ((Statement extends string ? [] : GetFunctionArgs<Statement>) extends infer T ? { [K in keyof T]: Parser<(Statement extends string ? [] : GetFunctionArgs<Statement>)[K]> } : never)>(parsers: Parsers) => {
234
+ dependencies: <GivenDeps extends RequiredOrOptional<GivenState>, WhenDeps extends RequiredOrOptional<WhenState>>(dependencies: {
235
+ given?: GivenDeps | undefined;
236
+ when?: WhenDeps | undefined;
237
+ }) => {
238
+ step: (stepFunction: (input: {
239
+ variables: Statement extends string ? [] : GetFunctionArgs<Statement>;
240
+ given: { [K_1 in keyof GivenState as K_1 extends keyof GivenDeps ? K_1 : never]: GivenDeps[K_1] extends "optional" ? GivenState[K_1] | undefined : GivenState[K_1] };
241
+ when: { [K_2 in keyof WhenState as K_2 extends keyof WhenDeps ? K_2 : never]: WhenDeps[K_2] extends "optional" ? WhenState[K_2] | undefined : WhenState[K_2] };
242
+ then: never;
243
+ }) => Partial<WhenState> | Promise<Partial<WhenState>>) => {
244
+ statement: Statement extends string ? () => string : Statement;
245
+ expression: string;
246
+ dependencies: {
247
+ given: GivenDeps;
248
+ when: WhenDeps;
249
+ then: EmptyObject;
250
+ };
251
+ stepType: "when";
252
+ stepFunction: (input: {
253
+ variables: Statement extends string ? [] : GetFunctionArgs<Statement>;
254
+ given: { [K_1 in keyof GivenState as K_1 extends keyof GivenDeps ? K_1 : never]: GivenDeps[K_1] extends "optional" ? GivenState[K_1] | undefined : GivenState[K_1] };
255
+ when: { [K_2 in keyof WhenState as K_2 extends keyof WhenDeps ? K_2 : never]: WhenDeps[K_2] extends "optional" ? WhenState[K_2] | undefined : WhenState[K_2] };
256
+ then: never;
257
+ }) => Partial<WhenState> | Promise<Partial<WhenState>>;
258
+ register: () => {
259
+ stepType: "when";
260
+ expression: string;
261
+ dependencies: {
262
+ given: GivenDeps;
263
+ when: WhenDeps;
264
+ then: EmptyObject;
265
+ };
266
+ statement: Statement extends string ? () => string : Statement;
267
+ stepFunction: (input: {
268
+ variables: Statement extends string ? [] : GetFunctionArgs<Statement>;
269
+ given: { [K_1 in keyof GivenState as K_1 extends keyof GivenDeps ? K_1 : never]: GivenDeps[K_1] extends "optional" ? GivenState[K_1] | undefined : GivenState[K_1] };
270
+ when: { [K_2 in keyof WhenState as K_2 extends keyof WhenDeps ? K_2 : never]: WhenDeps[K_2] extends "optional" ? WhenState[K_2] | undefined : WhenState[K_2] };
271
+ then: never;
272
+ }) => Partial<WhenState> | Promise<Partial<WhenState>>;
273
+ };
274
+ };
275
+ };
276
+ step: (stepFunction: (input: {
277
+ variables: Statement extends string ? [] : GetFunctionArgs<Statement>;
278
+ given: never;
279
+ when: never;
280
+ then: never;
281
+ }) => Partial<WhenState> | Promise<Partial<WhenState>>) => {
282
+ statement: Statement extends string ? () => string : Statement;
283
+ expression: string;
284
+ dependencies: EmptyDependencies;
285
+ stepType: "when";
286
+ stepFunction: (input: {
287
+ variables: Statement extends string ? [] : GetFunctionArgs<Statement>;
288
+ given: never;
289
+ when: never;
290
+ then: never;
291
+ }) => Partial<WhenState> | Promise<Partial<WhenState>>;
292
+ register: () => {
293
+ stepType: "when";
294
+ expression: string;
295
+ dependencies: EmptyDependencies;
296
+ statement: Statement extends string ? () => string : Statement;
297
+ stepFunction: (input: {
298
+ variables: Statement extends string ? [] : GetFunctionArgs<Statement>;
299
+ given: never;
300
+ when: never;
301
+ then: never;
302
+ }) => Partial<WhenState> | Promise<Partial<WhenState>>;
303
+ };
304
+ };
305
+ };
128
306
  step: (stepFunction: (input: {
129
307
  variables: Statement extends string ? [] : GetFunctionArgs<Statement>;
130
308
  given: never;
@@ -132,6 +310,7 @@ declare const whenBuilder: <GivenState, WhenState>() => {
132
310
  then: never;
133
311
  }) => Partial<WhenState> | Promise<Partial<WhenState>>) => {
134
312
  statement: Statement extends string ? () => string : Statement;
313
+ expression: string;
135
314
  dependencies: EmptyDependencies;
136
315
  stepType: "when";
137
316
  stepFunction: (input: {
@@ -142,6 +321,7 @@ declare const whenBuilder: <GivenState, WhenState>() => {
142
321
  }) => Partial<WhenState> | Promise<Partial<WhenState>>;
143
322
  register: () => {
144
323
  stepType: "when";
324
+ expression: string;
145
325
  dependencies: EmptyDependencies;
146
326
  statement: Statement extends string ? () => string : Statement;
147
327
  stepFunction: (input: {
@@ -168,8 +348,9 @@ declare const thenBuilder: <GivenState, WhenState, ThenState>() => {
168
348
  given: { [K in keyof GivenState as K extends keyof GivenDeps ? K : never]: GivenDeps[K] extends "optional" ? GivenState[K] | undefined : GivenState[K] };
169
349
  when: { [K_1 in keyof WhenState as K_1 extends keyof WhenDeps ? K_1 : never]: WhenDeps[K_1] extends "optional" ? WhenState[K_1] | undefined : WhenState[K_1] };
170
350
  then: { [K_2 in keyof ThenState as K_2 extends keyof ThenDeps ? K_2 : never]: ThenDeps[K_2] extends "optional" ? ThenState[K_2] | undefined : ThenState[K_2] };
171
- }) => void | Partial<ThenState> | Promise<Partial<ThenState>>) => {
351
+ }) => void | Promise<void> | Partial<ThenState> | Promise<Partial<ThenState>>) => {
172
352
  statement: Statement extends string ? () => string : Statement;
353
+ expression: string;
173
354
  dependencies: {
174
355
  given: GivenDeps;
175
356
  when: WhenDeps;
@@ -181,9 +362,10 @@ declare const thenBuilder: <GivenState, WhenState, ThenState>() => {
181
362
  given: { [K in keyof GivenState as K extends keyof GivenDeps ? K : never]: GivenDeps[K] extends "optional" ? GivenState[K] | undefined : GivenState[K] };
182
363
  when: { [K_1 in keyof WhenState as K_1 extends keyof WhenDeps ? K_1 : never]: WhenDeps[K_1] extends "optional" ? WhenState[K_1] | undefined : WhenState[K_1] };
183
364
  then: { [K_2 in keyof ThenState as K_2 extends keyof ThenDeps ? K_2 : never]: ThenDeps[K_2] extends "optional" ? ThenState[K_2] | undefined : ThenState[K_2] };
184
- }) => void | Partial<ThenState> | Promise<Partial<ThenState>>;
365
+ }) => void | Promise<void> | Partial<ThenState> | Promise<Partial<ThenState>>;
185
366
  register: () => {
186
367
  stepType: "then";
368
+ expression: string;
187
369
  dependencies: {
188
370
  given: GivenDeps;
189
371
  when: WhenDeps;
@@ -195,7 +377,81 @@ declare const thenBuilder: <GivenState, WhenState, ThenState>() => {
195
377
  given: { [K in keyof GivenState as K extends keyof GivenDeps ? K : never]: GivenDeps[K] extends "optional" ? GivenState[K] | undefined : GivenState[K] };
196
378
  when: { [K_1 in keyof WhenState as K_1 extends keyof WhenDeps ? K_1 : never]: WhenDeps[K_1] extends "optional" ? WhenState[K_1] | undefined : WhenState[K_1] };
197
379
  then: { [K_2 in keyof ThenState as K_2 extends keyof ThenDeps ? K_2 : never]: ThenDeps[K_2] extends "optional" ? ThenState[K_2] | undefined : ThenState[K_2] };
198
- }) => void | Partial<ThenState> | Promise<Partial<ThenState>>;
380
+ }) => void | Promise<void> | Partial<ThenState> | Promise<Partial<ThenState>>;
381
+ };
382
+ };
383
+ };
384
+ parsers: <Parsers extends ((Statement extends string ? [] : GetFunctionArgs<Statement>) extends infer T ? { [K in keyof T]: Parser<(Statement extends string ? [] : GetFunctionArgs<Statement>)[K]> } : never)>(parsers: Parsers) => {
385
+ dependencies: <GivenDeps extends RequiredOrOptional<GivenState>, WhenDeps extends RequiredOrOptional<WhenState>, ThenDeps extends RequiredOrOptional<ThenState>>(dependencies: {
386
+ given?: GivenDeps | undefined;
387
+ when?: WhenDeps | undefined;
388
+ then?: ThenDeps | undefined;
389
+ }) => {
390
+ step: (stepFunction: (input: {
391
+ variables: Statement extends string ? [] : GetFunctionArgs<Statement>;
392
+ given: { [K_1 in keyof GivenState as K_1 extends keyof GivenDeps ? K_1 : never]: GivenDeps[K_1] extends "optional" ? GivenState[K_1] | undefined : GivenState[K_1] };
393
+ when: { [K_2 in keyof WhenState as K_2 extends keyof WhenDeps ? K_2 : never]: WhenDeps[K_2] extends "optional" ? WhenState[K_2] | undefined : WhenState[K_2] };
394
+ then: { [K_3 in keyof ThenState as K_3 extends keyof ThenDeps ? K_3 : never]: ThenDeps[K_3] extends "optional" ? ThenState[K_3] | undefined : ThenState[K_3] };
395
+ }) => void | Promise<void> | Partial<ThenState> | Promise<Partial<ThenState>>) => {
396
+ statement: Statement extends string ? () => string : Statement;
397
+ expression: string;
398
+ dependencies: {
399
+ given: GivenDeps;
400
+ when: WhenDeps;
401
+ then: ThenDeps;
402
+ };
403
+ stepType: "then";
404
+ stepFunction: (input: {
405
+ variables: Statement extends string ? [] : GetFunctionArgs<Statement>;
406
+ given: { [K_1 in keyof GivenState as K_1 extends keyof GivenDeps ? K_1 : never]: GivenDeps[K_1] extends "optional" ? GivenState[K_1] | undefined : GivenState[K_1] };
407
+ when: { [K_2 in keyof WhenState as K_2 extends keyof WhenDeps ? K_2 : never]: WhenDeps[K_2] extends "optional" ? WhenState[K_2] | undefined : WhenState[K_2] };
408
+ then: { [K_3 in keyof ThenState as K_3 extends keyof ThenDeps ? K_3 : never]: ThenDeps[K_3] extends "optional" ? ThenState[K_3] | undefined : ThenState[K_3] };
409
+ }) => void | Promise<void> | Partial<ThenState> | Promise<Partial<ThenState>>;
410
+ register: () => {
411
+ stepType: "then";
412
+ expression: string;
413
+ dependencies: {
414
+ given: GivenDeps;
415
+ when: WhenDeps;
416
+ then: ThenDeps;
417
+ };
418
+ statement: Statement extends string ? () => string : Statement;
419
+ stepFunction: (input: {
420
+ variables: Statement extends string ? [] : GetFunctionArgs<Statement>;
421
+ given: { [K_1 in keyof GivenState as K_1 extends keyof GivenDeps ? K_1 : never]: GivenDeps[K_1] extends "optional" ? GivenState[K_1] | undefined : GivenState[K_1] };
422
+ when: { [K_2 in keyof WhenState as K_2 extends keyof WhenDeps ? K_2 : never]: WhenDeps[K_2] extends "optional" ? WhenState[K_2] | undefined : WhenState[K_2] };
423
+ then: { [K_3 in keyof ThenState as K_3 extends keyof ThenDeps ? K_3 : never]: ThenDeps[K_3] extends "optional" ? ThenState[K_3] | undefined : ThenState[K_3] };
424
+ }) => void | Promise<void> | Partial<ThenState> | Promise<Partial<ThenState>>;
425
+ };
426
+ };
427
+ };
428
+ step: (stepFunction: (input: {
429
+ variables: Statement extends string ? [] : GetFunctionArgs<Statement>;
430
+ given: never;
431
+ when: never;
432
+ then: never;
433
+ }) => void | Promise<void> | Partial<ThenState> | Promise<Partial<ThenState>>) => {
434
+ statement: Statement extends string ? () => string : Statement;
435
+ expression: string;
436
+ dependencies: EmptyDependencies;
437
+ stepType: "then";
438
+ stepFunction: (input: {
439
+ variables: Statement extends string ? [] : GetFunctionArgs<Statement>;
440
+ given: never;
441
+ when: never;
442
+ then: never;
443
+ }) => void | Promise<void> | Partial<ThenState> | Promise<Partial<ThenState>>;
444
+ register: () => {
445
+ stepType: "then";
446
+ expression: string;
447
+ dependencies: EmptyDependencies;
448
+ statement: Statement extends string ? () => string : Statement;
449
+ stepFunction: (input: {
450
+ variables: Statement extends string ? [] : GetFunctionArgs<Statement>;
451
+ given: never;
452
+ when: never;
453
+ then: never;
454
+ }) => void | Promise<void> | Partial<ThenState> | Promise<Partial<ThenState>>;
199
455
  };
200
456
  };
201
457
  };
@@ -204,8 +460,9 @@ declare const thenBuilder: <GivenState, WhenState, ThenState>() => {
204
460
  given: never;
205
461
  when: never;
206
462
  then: never;
207
- }) => void | Partial<ThenState> | Promise<Partial<ThenState>>) => {
463
+ }) => void | Promise<void> | Partial<ThenState> | Promise<Partial<ThenState>>) => {
208
464
  statement: Statement extends string ? () => string : Statement;
465
+ expression: string;
209
466
  dependencies: EmptyDependencies;
210
467
  stepType: "then";
211
468
  stepFunction: (input: {
@@ -213,9 +470,10 @@ declare const thenBuilder: <GivenState, WhenState, ThenState>() => {
213
470
  given: never;
214
471
  when: never;
215
472
  then: never;
216
- }) => void | Partial<ThenState> | Promise<Partial<ThenState>>;
473
+ }) => void | Promise<void> | Partial<ThenState> | Promise<Partial<ThenState>>;
217
474
  register: () => {
218
475
  stepType: "then";
476
+ expression: string;
219
477
  dependencies: EmptyDependencies;
220
478
  statement: Statement extends string ? () => string : Statement;
221
479
  stepFunction: (input: {
@@ -223,7 +481,7 @@ declare const thenBuilder: <GivenState, WhenState, ThenState>() => {
223
481
  given: never;
224
482
  when: never;
225
483
  then: never;
226
- }) => void | Partial<ThenState> | Promise<Partial<ThenState>>;
484
+ }) => void | Promise<void> | Partial<ThenState> | Promise<Partial<ThenState>>;
227
485
  };
228
486
  };
229
487
  };
@@ -322,5 +580,5 @@ declare const analyzer: {
322
580
  defaultRules: AnalysisRule[];
323
581
  };
324
582
  //#endregion
325
- export { type AnalysisRule, type AnalyzeOptions, type AnalyzerConfig, BasicWorld, type Diagnostic, type MatchedStep, type ParsedScenario, type ParsedStep, type StepDefinitionMeta, analyzer, givenBuilder, thenBuilder, whenBuilder };
583
+ export { type AnalysisRule, type AnalyzeOptions, type AnalyzerConfig, BasicWorld, type Diagnostic, type MatchedStep, type ParsedScenario, type ParsedStep, type Parser, type StepDefinitionMeta, analyzer, booleanParser, givenBuilder, intParser, numberParser, stringParser, thenBuilder, whenBuilder };
326
584
  //# sourceMappingURL=step-forge.d.ts.map
@@ -9,6 +9,28 @@ import * as messages from "@cucumber/messages";
9
9
  //#region src/builderTypeUtils.ts
10
10
  const isString = (statement) => typeof statement === "string";
11
11
  //#endregion
12
+ //#region src/parsers.ts
13
+ /** Matches a quoted string (`{string}`) and passes the unquoted contents through. */
14
+ const stringParser = {
15
+ parse: (value) => String(value),
16
+ gherkin: "{string}"
17
+ };
18
+ /** Matches an unquoted integer (`{int}`). */
19
+ const intParser = {
20
+ parse: (value) => typeof value === "number" ? value : parseInt(String(value), 10),
21
+ gherkin: "{int}"
22
+ };
23
+ /** Matches an unquoted floating point number (`{float}`). */
24
+ const numberParser = {
25
+ parse: (value) => typeof value === "number" ? value : parseFloat(String(value)),
26
+ gherkin: "{float}"
27
+ };
28
+ /** Matches an unquoted `true`/`false` word (`{word}`) and parses it to a boolean. */
29
+ const booleanParser = {
30
+ parse: (value) => value === true || value === "true",
31
+ gherkin: "{word}"
32
+ };
33
+ //#endregion
12
34
  //#region src/utils.ts
13
35
  const requireFromGiven = (keys, world) => {
14
36
  keys.forEach((key) => {
@@ -43,13 +65,6 @@ const requireFromThen = (keys, world) => {
43
65
  };
44
66
  }, {});
45
67
  };
46
- const typeCoercer = (value) => {
47
- const numberValue = parseInt(value, 10);
48
- if (!isNaN(numberValue)) return numberValue;
49
- if (value === "true") return true;
50
- if (value === "false") return false;
51
- return value;
52
- };
53
68
  //#endregion
54
69
  //#region src/common.ts
55
70
  const cucFunctionMap = {
@@ -61,19 +76,21 @@ const addStep = (statement, stepType, dependencies = {
61
76
  given: {},
62
77
  when: {},
63
78
  then: {}
64
- }) => (stepFunction) => {
79
+ }, declaredParsers) => (stepFunction) => {
65
80
  const statementFunction = statement;
66
81
  const { given: givenDependencies, when: whenDependencies, then: thenDependencies } = dependencies;
82
+ const argCount = statementFunction.length;
83
+ const parsers = declaredParsers ?? Array.from({ length: argCount }, () => stringParser);
84
+ const expression = statementFunction(...parsers.map((parser) => parser.gherkin));
67
85
  return {
68
86
  statement,
87
+ expression,
69
88
  dependencies,
70
89
  stepType,
71
90
  stepFunction,
72
91
  register: () => {
73
- const argCount = statementFunction.length;
74
- const statement = statementFunction(...Array.from({ length: argCount }, () => "{string}"));
75
92
  const cucStepFunction = Object.defineProperty(async function(...args) {
76
- const coercedArgs = args.map(typeCoercer);
93
+ const coercedArgs = parsers.map((parser, index) => parser.parse(args[index]));
77
94
  const ensuredGivenValues = requireFromGiven(Object.entries(givenDependencies ?? {}).filter(([, value]) => value === "required").map(([key]) => key), this);
78
95
  const narrowedGiven = {
79
96
  ..._.pick(this.given, Object.keys(givenDependencies ?? {})),
@@ -100,9 +117,10 @@ const addStep = (statement, stepType, dependencies = {
100
117
  configurable: true
101
118
  });
102
119
  const cucStep = cucFunctionMap[stepType];
103
- cucStep(statement, cucStepFunction);
120
+ cucStep(expression, cucStepFunction);
104
121
  return {
105
122
  stepType,
123
+ expression,
106
124
  dependencies,
107
125
  statement: statementFunction,
108
126
  stepFunction
@@ -112,12 +130,18 @@ const addStep = (statement, stepType, dependencies = {
112
130
  };
113
131
  //#endregion
114
132
  //#region src/given.ts
115
- const givenDependencies = (statement, stepType) => (dependencies) => {
133
+ const givenDependencies = (statement, stepType, parsers) => (dependencies) => {
116
134
  return { step: addStep(statement, stepType, {
117
135
  ...dependencies,
118
136
  when: {},
119
137
  then: {}
120
- }) };
138
+ }, parsers) };
139
+ };
140
+ const givenParsers = (statement, stepType) => (parsers) => {
141
+ return {
142
+ dependencies: givenDependencies(statement, stepType, parsers),
143
+ step: addStep(statement, stepType, void 0, parsers)
144
+ };
121
145
  };
122
146
  const givenStatement = (stepType) => (statement) => {
123
147
  let normalizedStatement;
@@ -125,6 +149,7 @@ const givenStatement = (stepType) => (statement) => {
125
149
  else normalizedStatement = statement;
126
150
  return {
127
151
  dependencies: givenDependencies(normalizedStatement, stepType),
152
+ parsers: givenParsers(normalizedStatement, stepType),
128
153
  step: addStep(normalizedStatement, stepType)
129
154
  };
130
155
  };
@@ -133,12 +158,18 @@ const givenBuilder = () => {
133
158
  };
134
159
  //#endregion
135
160
  //#region src/when.ts
136
- const whenDependencies = (statement, stepType) => (dependencies) => {
161
+ const whenDependencies = (statement, stepType, parsers) => (dependencies) => {
137
162
  return { step: addStep(statement, stepType, {
138
163
  given: dependencies.given ?? {},
139
164
  when: dependencies.when ?? {},
140
165
  then: {}
141
- }) };
166
+ }, parsers) };
167
+ };
168
+ const whenParsers = (statement, stepType) => (parsers) => {
169
+ return {
170
+ dependencies: whenDependencies(statement, stepType, parsers),
171
+ step: addStep(statement, stepType, void 0, parsers)
172
+ };
142
173
  };
143
174
  const whenStatement = (stepType) => (statement) => {
144
175
  let normalizedStatement;
@@ -146,6 +177,7 @@ const whenStatement = (stepType) => (statement) => {
146
177
  else normalizedStatement = statement;
147
178
  return {
148
179
  dependencies: whenDependencies(normalizedStatement, stepType),
180
+ parsers: whenParsers(normalizedStatement, stepType),
149
181
  step: addStep(normalizedStatement, stepType)
150
182
  };
151
183
  };
@@ -154,12 +186,18 @@ const whenBuilder = () => {
154
186
  };
155
187
  //#endregion
156
188
  //#region src/then.ts
157
- const thenDependencies = (statement, stepType) => (dependencies) => {
189
+ const thenDependencies = (statement, stepType, parsers) => (dependencies) => {
158
190
  return { step: addStep(statement, stepType, {
159
191
  given: dependencies.given ?? {},
160
192
  when: dependencies.when ?? {},
161
193
  then: dependencies.then ?? {}
162
- }) };
194
+ }, parsers) };
195
+ };
196
+ const thenParsers = (statement, stepType) => (parsers) => {
197
+ return {
198
+ dependencies: thenDependencies(statement, stepType, parsers),
199
+ step: addStep(statement, stepType, void 0, parsers)
200
+ };
163
201
  };
164
202
  const thenStatement = (stepType) => (statement) => {
165
203
  let normalizedStatement;
@@ -167,6 +205,7 @@ const thenStatement = (stepType) => (statement) => {
167
205
  else normalizedStatement = statement;
168
206
  return {
169
207
  dependencies: thenDependencies(normalizedStatement, stepType),
208
+ parsers: thenParsers(normalizedStatement, stepType),
170
209
  step: addStep(normalizedStatement, stepType)
171
210
  };
172
211
  };
@@ -690,6 +729,6 @@ const analyzer = {
690
729
  defaultRules
691
730
  };
692
731
  //#endregion
693
- export { BasicWorld, analyzer, givenBuilder, thenBuilder, whenBuilder };
732
+ export { BasicWorld, analyzer, booleanParser, givenBuilder, intParser, numberParser, stringParser, thenBuilder, whenBuilder };
694
733
 
695
734
  //# sourceMappingURL=step-forge.js.map