@step-forge/step-forge 0.0.6 → 0.0.7-beta

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 (54) hide show
  1. package/dist/types/src/builderTypeUtils.d.ts +14 -0
  2. package/dist/types/src/common.d.ts +32 -0
  3. package/dist/types/src/given.d.ts +73 -0
  4. package/{src/index.ts → dist/types/src/index.d.ts} +0 -1
  5. package/dist/types/src/then.d.ts +73 -0
  6. package/dist/types/src/utils.d.ts +5 -0
  7. package/dist/types/src/when.d.ts +72 -0
  8. package/dist/types/src/world.d.ts +21 -0
  9. package/package.json +9 -8
  10. package/.eslintignore +0 -6
  11. package/.eslintrc +0 -18
  12. package/.prettierignore +0 -6
  13. package/.prettierrc +0 -15
  14. package/CHANGELOG.md +0 -28
  15. package/cucumber.mjs +0 -38
  16. package/docs/assets/state_deps.gif +0 -0
  17. package/dts-bundle-generator.config.ts +0 -11
  18. package/features/basic.feature +0 -21
  19. package/features/exported.feature +0 -6
  20. package/features/steps/commonSteps.ts +0 -93
  21. package/features/steps/exportedSteps.ts +0 -42
  22. package/features/steps/world.ts +0 -29
  23. package/src/builderTypeUtils.js +0 -2
  24. package/src/builderTypeUtils.js.map +0 -1
  25. package/src/builderTypeUtils.ts +0 -27
  26. package/src/common.js +0 -73
  27. package/src/common.js.map +0 -1
  28. package/src/common.ts +0 -138
  29. package/src/given.js +0 -34
  30. package/src/given.js.map +0 -1
  31. package/src/given.ts +0 -102
  32. package/src/index.js +0 -6
  33. package/src/index.js.map +0 -1
  34. package/src/then.js +0 -34
  35. package/src/then.js.map +0 -1
  36. package/src/then.ts +0 -128
  37. package/src/utils.js +0 -54
  38. package/src/utils.js.map +0 -1
  39. package/src/utils.ts +0 -74
  40. package/src/vite-env.d.ts.old +0 -1
  41. package/src/when.js +0 -34
  42. package/src/when.js.map +0 -1
  43. package/src/when.ts +0 -118
  44. package/src/world.js +0 -51
  45. package/src/world.js.map +0 -1
  46. package/src/world.ts +0 -90
  47. package/test/givenCompilationTests.ts +0 -130
  48. package/test/testUtils.ts +0 -30
  49. package/test/thenCompilationTests.ts +0 -207
  50. package/test/whenCompilationTests.ts +0 -157
  51. package/ts-node-esm-register.js +0 -8
  52. package/tsconfig.cucumber.json +0 -23
  53. package/tsconfig.json +0 -28
  54. package/vite.config.ts +0 -36
@@ -1,2 +0,0 @@
1
- export const isString = (statement) => typeof statement === "string";
2
- //# sourceMappingURL=builderTypeUtils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"builderTypeUtils.js","sourceRoot":"","sources":["builderTypeUtils.ts"],"names":[],"mappings":"AAkBA,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,SAAmD,EAC9B,EAAE,CAAC,OAAO,SAAS,KAAK,QAAQ,CAAC"}
@@ -1,27 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- export type StepType = "given" | "when" | "then";
3
-
4
- export type InferAndReplace<T, U> = never extends T ? U : T;
5
-
6
- export type HasKeys<T> =
7
- T extends Record<any, any> ? (keyof T extends never ? never : T) : T;
8
-
9
- export type EmptyObject = Record<string, never>;
10
-
11
- export type RequiredOrOptional<T> = {
12
- [K in keyof T]?: "required" | "optional";
13
- };
14
-
15
- export type GetFunctionArgs<T> = T extends (...args: infer A) => any
16
- ? A
17
- : never;
18
-
19
- export const isString = (
20
- statement: string | ((...args: [...any]) => string)
21
- ): statement is string => typeof statement === "string";
22
-
23
- export type EmptyDependencies = {
24
- given: EmptyObject;
25
- when: EmptyObject;
26
- then: EmptyObject;
27
- };
package/src/common.js DELETED
@@ -1,73 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { Given as CucGiven, Then as CucThen, When as CucWhen, } from "@cucumber/cucumber";
3
- import _ from "lodash";
4
- import { requireFromGiven, requireFromThen, requireFromWhen, typeCoercer, } from "./utils";
5
- const cucFunctionMap = {
6
- given: CucGiven,
7
- when: CucWhen,
8
- then: CucThen,
9
- };
10
- export const addStep = (statement, stepType, dependencies = {
11
- given: {},
12
- when: {},
13
- then: {},
14
- }) => (stepFunction) => {
15
- const statementFunction = statement;
16
- const { given: givenDependencies, when: whenDependencies, then: thenDependencies, } = dependencies;
17
- return {
18
- statement,
19
- dependencies,
20
- stepType,
21
- stepFunction,
22
- register: () => {
23
- const argCount = statementFunction.length;
24
- const argMatchers = Array.from({ length: argCount }, () => "{string}");
25
- const statement = statementFunction(...argMatchers);
26
- const cucStepFunction = Object.defineProperty(async function (...args) {
27
- const coercedArgs = args.map(typeCoercer);
28
- const requiredGivenKeys = Object.entries(givenDependencies ?? {})
29
- .filter(([, value]) => value === "required")
30
- .map(([key]) => key);
31
- const ensuredGivenValues = requireFromGiven(requiredGivenKeys, this);
32
- const narrowedGiven = {
33
- ..._.pick(this.given, Object.keys(givenDependencies ?? {})),
34
- ...ensuredGivenValues,
35
- };
36
- const requiredWhenKeys = Object.entries(whenDependencies ?? {})
37
- .filter(([, value]) => value === "required")
38
- .map(([key]) => key);
39
- const ensuredWhenValues = requireFromWhen(requiredWhenKeys, this);
40
- const narrowedWhen = {
41
- ..._.pick(this.when, Object.keys(whenDependencies ?? {})),
42
- ...ensuredWhenValues,
43
- };
44
- const requiredThenKeys = Object.entries(thenDependencies ?? {})
45
- .filter(([, value]) => value === "required")
46
- .map(([key]) => key);
47
- const ensuredThenValues = requireFromThen(requiredThenKeys, this);
48
- const narrowedThen = {
49
- ..._.pick(this.then, Object.keys(thenDependencies ?? {})),
50
- ...ensuredThenValues,
51
- };
52
- const result = await stepFunction({
53
- variables: coercedArgs,
54
- given: narrowedGiven,
55
- when: narrowedWhen,
56
- then: narrowedThen,
57
- });
58
- this[stepType].merge({
59
- ...result,
60
- });
61
- }, "length", { value: argCount, configurable: true });
62
- const cucStep = cucFunctionMap[stepType];
63
- cucStep(statement, cucStepFunction);
64
- return {
65
- stepType,
66
- dependencies,
67
- statement: statementFunction,
68
- stepFunction,
69
- };
70
- },
71
- };
72
- };
73
- //# sourceMappingURL=common.js.map
package/src/common.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"common.js","sourceRoot":"","sources":["common.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,OAAO,EACL,KAAK,IAAI,QAAQ,EACjB,IAAI,IAAI,OAAO,EACf,IAAI,IAAI,OAAO,GAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,CAAC,MAAM,QAAQ,CAAC;AAGvB,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,WAAW,GACZ,MAAM,SAAS,CAAC;AAGjB,MAAM,cAAc,GAAG;IACrB,KAAK,EAAE,QAAQ;IACf,IAAI,EAAE,OAAO;IACb,IAAI,EAAE,OAAO;CACd,CAAC;AAEF,MAAM,CAAC,MAAM,OAAO,GAClB,CAgBE,SAAoB,EACpB,QAA0B,EAC1B,eAA6B;IAC3B,KAAK,EAAE,EAAE;IACT,IAAI,EAAE,EAAE;IACR,IAAI,EAAE,EAAE;CACO,EACjB,EAAE,CACJ,CACE,YAS+B,EAC/B,EAAE;IACF,MAAM,iBAAiB,GAAG,SAAS,CAAC;IACpC,MAAM,EACJ,KAAK,EAAE,iBAAiB,EACxB,IAAI,EAAE,gBAAgB,EACtB,IAAI,EAAE,gBAAgB,GACvB,GAAG,YAAY,CAAC;IACjB,OAAO;QACL,SAAS;QACT,YAAY;QACZ,QAAQ;QACR,YAAY;QACZ,QAAQ,EAAE,GAAG,EAAE;YACb,MAAM,QAAQ,GAAG,iBAAiB,CAAC,MAAM,CAAC;YAC1C,MAAM,WAAW,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,CAAC;YACvE,MAAM,SAAS,GAAG,iBAAiB,CAAC,GAAG,WAAW,CAAC,CAAC;YACpD,MAAM,eAAe,GAAG,MAAM,CAAC,cAAc,CAC3C,KAAK,WAEH,GAAG,IAAc;gBAEjB,MAAM,WAAW,GAAG,IAAI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AC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;gBACvB,MAAM,iBAAiB,GAAG,eAAe,CACvC,gBAAuC,EACvC,IAAI,CACL,CAAC;gBACF,MAAM,YAAY,GAAG;oBACnB,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,gBAAgB,IAAI,EAAE,CAAC,CAAC;oBACzD,GAAG,iBAAiB;iBACrB,CAAC;gBACF,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC;oBAChC,SAAS,EAAE,WAAwB;oBACnC,KAAK,EAAE,aAAqC;oBAC5C,IAAI,EAAE,YAAmC;oBACzC,IAAI,EAAE,YAAmC;iBAC1C,CAAC,CAAC;gBACH,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC;oBACnB,GAAI,MAAc;iBACnB,CAAC,CAAC;YACL,CAAC,EACD,QAAQ,EACR,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,CACxC,CAAC;YACF,MAAM,OAAO,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC;YACzC,OAAO,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;YACpC,OAAO;gBACL,QAAQ;gBACR,YAAY;gBACZ,SAAS,EAAE,iBAAiB;gBAC5B,YAAY;aACb,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
package/src/common.ts DELETED
@@ -1,138 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import {
3
- Given as CucGiven,
4
- Then as CucThen,
5
- When as CucWhen,
6
- } from "@cucumber/cucumber";
7
- import _ from "lodash";
8
-
9
- import { StepType } from "./builderTypeUtils";
10
- import {
11
- requireFromGiven,
12
- requireFromThen,
13
- requireFromWhen,
14
- typeCoercer,
15
- } from "./utils";
16
- import { MergeableWorld } from "./world";
17
-
18
- const cucFunctionMap = {
19
- given: CucGiven,
20
- when: CucWhen,
21
- then: CucThen,
22
- };
23
-
24
- export const addStep =
25
- <
26
- ResolvedStepType extends StepType,
27
- Statement extends (...args: any[]) => string,
28
- Dependencies extends {
29
- given: any;
30
- when: any;
31
- then: any;
32
- },
33
- Variables,
34
- GivenState,
35
- WhenState,
36
- ThenState,
37
- RestrictedGivenState,
38
- RestrictedWhenState,
39
- RestrictedThenState,
40
- >(
41
- statement: Statement,
42
- stepType: ResolvedStepType,
43
- dependencies: Dependencies = {
44
- given: {},
45
- when: {},
46
- then: {},
47
- } as Dependencies
48
- ) =>
49
- (
50
- stepFunction: (input: {
51
- variables: Variables;
52
- given: RestrictedGivenState;
53
- when: RestrictedWhenState;
54
- then: RestrictedThenState;
55
- }) => ResolvedStepType extends "given"
56
- ? Partial<GivenState>
57
- : ResolvedStepType extends "when"
58
- ? Partial<WhenState>
59
- : Partial<ThenState> | void
60
- ) => {
61
- const statementFunction = statement;
62
- const {
63
- given: givenDependencies,
64
- when: whenDependencies,
65
- then: thenDependencies,
66
- } = dependencies;
67
- return {
68
- statement,
69
- dependencies,
70
- stepType,
71
- stepFunction,
72
- register: () => {
73
- const argCount = statementFunction.length;
74
- const argMatchers = Array.from({ length: argCount }, () => "{string}");
75
- const statement = statementFunction(...argMatchers);
76
- const cucStepFunction = Object.defineProperty(
77
- async function (
78
- this: MergeableWorld<GivenState, WhenState, ThenState>,
79
- ...args: string[]
80
- ) {
81
- const coercedArgs = args.map(typeCoercer);
82
- const requiredGivenKeys = Object.entries(givenDependencies ?? {})
83
- .filter(([, value]) => value === "required")
84
- .map(([key]) => key);
85
- const ensuredGivenValues = requireFromGiven(
86
- requiredGivenKeys as (keyof GivenState)[],
87
- this
88
- );
89
- const narrowedGiven = {
90
- ..._.pick(this.given, Object.keys(givenDependencies ?? {})),
91
- ...ensuredGivenValues,
92
- };
93
- const requiredWhenKeys = Object.entries(whenDependencies ?? {})
94
- .filter(([, value]) => value === "required")
95
- .map(([key]) => key);
96
- const ensuredWhenValues = requireFromWhen(
97
- requiredWhenKeys as (keyof WhenState)[],
98
- this
99
- );
100
- const narrowedWhen = {
101
- ..._.pick(this.when, Object.keys(whenDependencies ?? {})),
102
- ...ensuredWhenValues,
103
- };
104
- const requiredThenKeys = Object.entries(thenDependencies ?? {})
105
- .filter(([, value]) => value === "required")
106
- .map(([key]) => key);
107
- const ensuredThenValues = requireFromThen(
108
- requiredThenKeys as (keyof ThenState)[],
109
- this
110
- );
111
- const narrowedThen = {
112
- ..._.pick(this.then, Object.keys(thenDependencies ?? {})),
113
- ...ensuredThenValues,
114
- };
115
- const result = await stepFunction({
116
- variables: coercedArgs as Variables,
117
- given: narrowedGiven as RestrictedGivenState,
118
- when: narrowedWhen as RestrictedWhenState,
119
- then: narrowedThen as RestrictedThenState,
120
- });
121
- this[stepType].merge({
122
- ...(result as any),
123
- });
124
- },
125
- "length",
126
- { value: argCount, configurable: true }
127
- );
128
- const cucStep = cucFunctionMap[stepType];
129
- cucStep(statement, cucStepFunction);
130
- return {
131
- stepType,
132
- dependencies,
133
- statement: statementFunction,
134
- stepFunction,
135
- };
136
- },
137
- };
138
- };
package/src/given.js DELETED
@@ -1,34 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { isString, } from "./builderTypeUtils";
3
- import { addStep } from "./common";
4
- const givenDependencies = (statement, stepType) => (dependencies) => {
5
- const fullDependencies = {
6
- ...dependencies,
7
- when: {},
8
- then: {},
9
- };
10
- return {
11
- step: addStep(statement, stepType, fullDependencies),
12
- };
13
- };
14
- const givenStatement = (stepType) => (statement) => {
15
- let normalizedStatement;
16
- if (isString(statement)) {
17
- normalizedStatement = (() => statement);
18
- }
19
- else {
20
- normalizedStatement = statement;
21
- }
22
- const dependencyFunc = givenDependencies(normalizedStatement, stepType);
23
- const stepFunc = addStep(normalizedStatement, stepType);
24
- return {
25
- dependencies: dependencyFunc,
26
- step: stepFunc,
27
- };
28
- };
29
- export const givenBuilder = () => {
30
- return {
31
- statement: givenStatement("given"),
32
- };
33
- };
34
- //# sourceMappingURL=given.js.map
package/src/given.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"given.js","sourceRoot":"","sources":["given.ts"],"names":[],"mappings":"AAAA,uDAAuD;AAEvD,OAAO,EAIL,QAAQ,GAGT,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEnC,MAAM,iBAAiB,GACrB,CAME,SAAoB,EACpB,QAA0B,EAC1B,EAAE,CACJ,CAAmD,YAElD,EAAE,EAAE;IAYH,MAAM,gBAAgB,GAAG;QACvB,GAAG,YAAY;QACf,IAAI,EAAE,EAAE;QACR,IAAI,EAAE,EAAE;KACT,CAAC;IACF,OAAO;QACL,IAAI,EAAE,OAAO,CAWX,SAAS,EAAE,QAAQ,EAAE,gBAAgB,CAAC;KACzC,CAAC;AACJ,CAAC,CAAC;AAEJ,MAAM,cAAc,GAClB,CAAgD,QAA0B,EAAE,EAAE,CAC9E,CACE,SAAoB,EACpB,EAAE;IACF,IAAI,mBAES,CAAC;IACd,IAAI,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;QACxB,mBAAmB,GAAG,CAAC,GAAG,EAAE,CAAC,SAAS,CAAQ,CAAC;IACjD,CAAC;SAAM,CAAC;QACN,mBAAmB,GAAG,SAAgB,CAAC;IACzC,CAAC;IAID,MAAM,cAAc,GAAG,iBAAiB,CAKtC,mBAAmB,EAAE,QAAQ,CAAC,CAAC;IACjC,MAAM,QAAQ,GAAG,OAAO,CAWtB,mBAAmB,EAAE,QAAQ,CAAC,CAAC;IACjC,OAAO;QACL,YAAY,EAAE,cAAc;QAC5B,IAAI,EAAE,QAAQ;KACf,CAAC;AACJ,CAAC,CAAC;AAEJ,MAAM,CAAC,MAAM,YAAY,GAAG,GAAe,EAAE;IAC3C,OAAO;QACL,SAAS,EAAE,cAAc,CAAsB,OAAO,CAAC;KACxD,CAAC;AACJ,CAAC,CAAC"}
package/src/given.ts DELETED
@@ -1,102 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
-
3
- import {
4
- EmptyDependencies,
5
- EmptyObject,
6
- GetFunctionArgs,
7
- isString,
8
- RequiredOrOptional,
9
- StepType,
10
- } from "./builderTypeUtils";
11
- import { addStep } from "./common";
12
-
13
- const givenDependencies =
14
- <
15
- Statement extends (...args: any[]) => string,
16
- ResolvedStepType extends StepType,
17
- Variables,
18
- GivenState,
19
- >(
20
- statement: Statement,
21
- stepType: ResolvedStepType
22
- ) =>
23
- <GivenDeps extends RequiredOrOptional<GivenState>>(dependencies: {
24
- given: GivenDeps;
25
- }) => {
26
- type RestrictedGivenState = {
27
- [K in keyof GivenState as K extends keyof GivenDeps
28
- ? K
29
- : never]: GivenDeps[K] extends "optional"
30
- ? GivenState[K] | undefined
31
- : GivenState[K];
32
- };
33
- type Dependencies = typeof dependencies & {
34
- when: EmptyObject;
35
- then: EmptyObject;
36
- };
37
- const fullDependencies = {
38
- ...dependencies,
39
- when: {},
40
- then: {},
41
- };
42
- return {
43
- step: addStep<
44
- ResolvedStepType,
45
- Statement,
46
- Dependencies,
47
- Variables,
48
- GivenState,
49
- never, // when state
50
- never, // then state
51
- RestrictedGivenState,
52
- never, // restricted when state
53
- never // restricted then state
54
- >(statement, stepType, fullDependencies),
55
- };
56
- };
57
-
58
- const givenStatement =
59
- <ResolvedStepType extends StepType, GivenState>(stepType: ResolvedStepType) =>
60
- <Statement extends ((...args: [...any]) => string) | string>(
61
- statement: Statement
62
- ) => {
63
- let normalizedStatement: Statement extends string
64
- ? () => string
65
- : Statement;
66
- if (isString(statement)) {
67
- normalizedStatement = (() => statement) as any;
68
- } else {
69
- normalizedStatement = statement as any;
70
- }
71
- type NormalizedStatement = typeof normalizedStatement;
72
-
73
- type Variables = Statement extends string ? [] : GetFunctionArgs<Statement>;
74
- const dependencyFunc = givenDependencies<
75
- NormalizedStatement,
76
- ResolvedStepType,
77
- Variables,
78
- GivenState
79
- >(normalizedStatement, stepType);
80
- const stepFunc = addStep<
81
- ResolvedStepType,
82
- NormalizedStatement,
83
- EmptyDependencies,
84
- Variables,
85
- GivenState,
86
- never,
87
- never,
88
- never,
89
- never,
90
- never
91
- >(normalizedStatement, stepType);
92
- return {
93
- dependencies: dependencyFunc,
94
- step: stepFunc,
95
- };
96
- };
97
-
98
- export const givenBuilder = <GivenState>() => {
99
- return {
100
- statement: givenStatement<"given", GivenState>("given"),
101
- };
102
- };
package/src/index.js DELETED
@@ -1,6 +0,0 @@
1
- import { givenBuilder } from "./given";
2
- import { whenBuilder } from "./when";
3
- import { thenBuilder } from "./then";
4
- import { BasicWorld } from "./world";
5
- export { givenBuilder, whenBuilder, thenBuilder, BasicWorld };
6
- //# sourceMappingURL=index.js.map
package/src/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC"}
package/src/then.js DELETED
@@ -1,34 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { isString, } from "./builderTypeUtils";
3
- import { addStep } from "./common";
4
- const thenDependencies = (statement, stepType) => (dependencies) => {
5
- const fullDependencies = {
6
- given: dependencies.given ?? {},
7
- when: dependencies.when ?? {},
8
- then: dependencies.then ?? {},
9
- };
10
- return {
11
- step: addStep(statement, stepType, fullDependencies),
12
- };
13
- };
14
- const thenStatement = (stepType) => (statement) => {
15
- let normalizedStatement;
16
- if (isString(statement)) {
17
- normalizedStatement = (() => statement);
18
- }
19
- else {
20
- normalizedStatement = statement;
21
- }
22
- const dependencyFunc = thenDependencies(normalizedStatement, stepType);
23
- const stepFunc = addStep(normalizedStatement, stepType);
24
- return {
25
- dependencies: dependencyFunc,
26
- step: stepFunc,
27
- };
28
- };
29
- export const thenBuilder = () => {
30
- return {
31
- statement: thenStatement("then"),
32
- };
33
- };
34
- //# sourceMappingURL=then.js.map
package/src/then.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"then.js","sourceRoot":"","sources":["then.ts"],"names":[],"mappings":"AAAA,uDAAuD;AAEvD,OAAO,EAGL,QAAQ,GAGT,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEnC,MAAM,gBAAgB,GACpB,CAQE,SAAoB,EACpB,QAA0B,EAC1B,EAAE,CACJ,CAIE,YAID,EAAE,EAAE;IA2BH,MAAM,gBAAgB,GAAiB;QACrC,KAAK,EAAE,YAAY,CAAC,KAAK,IAAK,EAAgB;QAC9C,IAAI,EAAE,YAAY,CAAC,IAAI,IAAK,EAAe;QAC3C,IAAI,EAAE,YAAY,CAAC,IAAI,IAAK,EAAe;KAC5C,CAAC;IACF,OAAO;QACL,IAAI,EAAE,OAAO,CAWX,SAAS,EAAE,QAAQ,EAAE,gBAAgB,CAAC;KACzC,CAAC;AACJ,CAAC,CAAC;AAEJ,MAAM,aAAa,GACjB,CACE,QAA0B,EAC1B,EAAE,CACJ,CACE,SAAoB,EACpB,EAAE;IACF,IAAI,mBAES,CAAC;IACd,IAAI,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;QACxB,mBAAmB,GAAG,CAAC,GAAG,EAAE,CAAC,SAAS,CAAQ,CAAC;IACjD,CAAC;SAAM,CAAC;QACN,mBAAmB,GAAG,SAAgB,CAAC;IACzC,CAAC;IAID,MAAM,cAAc,GAAG,gBAAgB,CAOrC,mBAAmB,EAAE,QAAQ,CAAC,CAAC;IACjC,MAAM,QAAQ,GAAG,OAAO,CAWtB,mBAAmB,EAAE,QAAQ,CAAC,CAAC;IACjC,OAAO;QACL,YAAY,EAAE,cAAc;QAC5B,IAAI,EAAE,QAAQ;KACf,CAAC;AACJ,CAAC,CAAC;AAEJ,MAAM,CAAC,MAAM,WAAW,GAAG,GAAqC,EAAE;IAChE,OAAO;QACL,SAAS,EAAE,aAAa,CAA2C,MAAM,CAAC;KAC3E,CAAC;AACJ,CAAC,CAAC"}
package/src/then.ts DELETED
@@ -1,128 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
-
3
- import {
4
- EmptyDependencies,
5
- GetFunctionArgs,
6
- isString,
7
- RequiredOrOptional,
8
- StepType,
9
- } from "./builderTypeUtils";
10
- import { addStep } from "./common";
11
-
12
- const thenDependencies =
13
- <
14
- Statement extends (...args: any[]) => string,
15
- ResolvedStepType extends StepType,
16
- Variables,
17
- GivenState,
18
- WhenState,
19
- ThenState,
20
- >(
21
- statement: Statement,
22
- stepType: ResolvedStepType
23
- ) =>
24
- <
25
- GivenDeps extends RequiredOrOptional<GivenState>,
26
- WhenDeps extends RequiredOrOptional<WhenState>,
27
- ThenDeps extends RequiredOrOptional<ThenState>,
28
- >(dependencies: {
29
- given?: GivenDeps;
30
- when?: WhenDeps;
31
- then?: ThenDeps;
32
- }) => {
33
- type RestrictedGivenState = {
34
- [K in keyof GivenState as K extends keyof GivenDeps
35
- ? K
36
- : never]: GivenDeps[K] extends "optional"
37
- ? GivenState[K] | undefined
38
- : GivenState[K];
39
- };
40
- type RestrictedWhenState = {
41
- [K in keyof WhenState as K extends keyof WhenDeps
42
- ? K
43
- : never]: WhenDeps[K] extends "optional"
44
- ? WhenState[K] | undefined
45
- : WhenState[K];
46
- };
47
- type RestrictedThenState = {
48
- [K in keyof ThenState as K extends keyof ThenDeps
49
- ? K
50
- : never]: ThenDeps[K] extends "optional"
51
- ? ThenState[K] | undefined
52
- : ThenState[K];
53
- };
54
- type Dependencies = {
55
- given: GivenDeps;
56
- when: WhenDeps;
57
- then: ThenDeps;
58
- };
59
- const fullDependencies: Dependencies = {
60
- given: dependencies.given ?? ({} as GivenDeps),
61
- when: dependencies.when ?? ({} as WhenDeps),
62
- then: dependencies.then ?? ({} as ThenDeps),
63
- };
64
- return {
65
- step: addStep<
66
- ResolvedStepType,
67
- Statement,
68
- Dependencies,
69
- Variables,
70
- GivenState,
71
- WhenState,
72
- ThenState,
73
- RestrictedGivenState,
74
- RestrictedWhenState,
75
- RestrictedThenState
76
- >(statement, stepType, fullDependencies),
77
- };
78
- };
79
-
80
- const thenStatement =
81
- <ResolvedStepType extends StepType, GivenState, WhenState, ThenState>(
82
- stepType: ResolvedStepType
83
- ) =>
84
- <Statement extends ((...args: [...any]) => string) | string>(
85
- statement: Statement
86
- ) => {
87
- let normalizedStatement: Statement extends string
88
- ? () => string
89
- : Statement;
90
- if (isString(statement)) {
91
- normalizedStatement = (() => statement) as any;
92
- } else {
93
- normalizedStatement = statement as any;
94
- }
95
- type NormalizedStatement = typeof normalizedStatement;
96
-
97
- type Variables = Statement extends string ? [] : GetFunctionArgs<Statement>;
98
- const dependencyFunc = thenDependencies<
99
- NormalizedStatement,
100
- ResolvedStepType,
101
- Variables,
102
- GivenState,
103
- WhenState,
104
- ThenState
105
- >(normalizedStatement, stepType);
106
- const stepFunc = addStep<
107
- ResolvedStepType,
108
- NormalizedStatement,
109
- EmptyDependencies,
110
- Variables,
111
- GivenState,
112
- WhenState,
113
- ThenState,
114
- never,
115
- never,
116
- never
117
- >(normalizedStatement, stepType);
118
- return {
119
- dependencies: dependencyFunc,
120
- step: stepFunc,
121
- };
122
- };
123
-
124
- export const thenBuilder = <GivenState, WhenState, ThenState>() => {
125
- return {
126
- statement: thenStatement<"then", GivenState, WhenState, ThenState>("then"),
127
- };
128
- };
package/src/utils.js DELETED
@@ -1,54 +0,0 @@
1
- export const requireFromGiven = (keys, world) => {
2
- keys.forEach(key => {
3
- if (!world.given[key]) {
4
- throw new Error(`Key ${String(key)} is required in given state`);
5
- }
6
- });
7
- return keys.reduce((acc, key) => {
8
- return {
9
- ...acc,
10
- [key]: world.given[key],
11
- };
12
- }, {});
13
- };
14
- export const requireFromWhen = (keys, world) => {
15
- keys.forEach(key => {
16
- if (!world.when[key]) {
17
- throw new Error(`Key ${String(key)} is required in when state`);
18
- }
19
- });
20
- return keys.reduce((acc, key) => {
21
- return {
22
- ...acc,
23
- [key]: world.when[key],
24
- };
25
- }, {});
26
- };
27
- export const requireFromThen = (keys, world) => {
28
- keys.forEach(key => {
29
- if (!world.then[key]) {
30
- throw new Error(`Key ${String(key)} is required in then state`);
31
- }
32
- });
33
- return keys.reduce((acc, key) => {
34
- return {
35
- ...acc,
36
- [key]: world.then[key],
37
- };
38
- }, {});
39
- };
40
- export const typeCoercer = (value) => {
41
- // Try to parse as integer first
42
- const numberValue = parseInt(value, 10);
43
- if (!isNaN(numberValue)) {
44
- return numberValue;
45
- }
46
- // Check for boolean values
47
- if (value === "true")
48
- return true;
49
- if (value === "false")
50
- return false;
51
- // Return original string if no other type matches
52
- return value;
53
- };
54
- //# sourceMappingURL=utils.js.map
package/src/utils.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["utils.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,IAAiB,EACjB,KAA0C,EAC1C,EAAE;IACF,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QACjB,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,OAAO,MAAM,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;QACnE,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,IAAI,CAAC,MAAM,CAChB,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QACX,OAAO;YACL,GAAG,GAAG;YACN,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC;SACxB,CAAC;IACJ,CAAC,EACD,EAAkC,CACnC,CAAC;AACJ,CAAC,C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