@jfdevelops/multi-step-form-core 1.0.0-alpha.17 → 1.0.0-alpha.18
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/dist/_internals.cjs +14 -0
- package/dist/_internals.d.cts +4 -0
- package/dist/_internals.d.mts +4 -0
- package/dist/_internals.mjs +5 -0
- package/dist/index.cjs +49 -0
- package/dist/index.d.cts +14 -0
- package/dist/index.d.mts +14 -0
- package/dist/index.mjs +16 -0
- package/dist/internals/step-schema.cjs +389 -0
- package/dist/internals/step-schema.cjs.map +1 -0
- package/dist/internals/step-schema.d.cts +41 -0
- package/dist/internals/step-schema.d.cts.map +1 -0
- package/dist/internals/step-schema.d.mts +41 -0
- package/dist/internals/step-schema.d.mts.map +1 -0
- package/dist/internals/step-schema.mjs +389 -0
- package/dist/internals/step-schema.mjs.map +1 -0
- package/dist/internals/utils.cjs +94 -0
- package/dist/internals/utils.cjs.map +1 -0
- package/dist/internals/utils.d.cts +27 -0
- package/dist/internals/utils.d.cts.map +1 -0
- package/dist/internals/utils.d.mts +27 -0
- package/dist/internals/utils.d.mts.map +1 -0
- package/dist/internals/utils.mjs +91 -0
- package/dist/internals/utils.mjs.map +1 -0
- package/dist/observable.cjs +44 -0
- package/dist/observable.cjs.map +1 -0
- package/dist/observable.d.cts +26 -0
- package/dist/observable.d.cts.map +1 -0
- package/dist/observable.d.mts +26 -0
- package/dist/observable.d.mts.map +1 -0
- package/dist/observable.mjs +44 -0
- package/dist/observable.mjs.map +1 -0
- package/dist/schema.cjs +68 -0
- package/dist/schema.cjs.map +1 -0
- package/dist/schema.d.cts +28 -0
- package/dist/schema.d.cts.map +1 -0
- package/dist/schema.d.mts +28 -0
- package/dist/schema.d.mts.map +1 -0
- package/dist/schema.mjs +67 -0
- package/dist/schema.mjs.map +1 -0
- package/dist/steps/fields.cjs +23 -0
- package/dist/steps/fields.cjs.map +1 -0
- package/dist/steps/fields.d.cts +18 -0
- package/dist/steps/fields.d.cts.map +1 -0
- package/dist/steps/fields.d.mts +18 -0
- package/dist/steps/fields.d.mts.map +1 -0
- package/dist/steps/fields.mjs +18 -0
- package/dist/steps/fields.mjs.map +1 -0
- package/dist/steps/index.cjs +4 -0
- package/dist/steps/index.mjs +6 -0
- package/dist/steps/schema.cjs +194 -0
- package/dist/steps/schema.cjs.map +1 -0
- package/dist/steps/schema.d.cts +124 -0
- package/dist/steps/schema.d.cts.map +1 -0
- package/dist/steps/schema.d.mts +124 -0
- package/dist/steps/schema.d.mts.map +1 -0
- package/dist/steps/schema.mjs +194 -0
- package/dist/steps/schema.mjs.map +1 -0
- package/dist/steps/types.cjs +33 -0
- package/dist/steps/types.cjs.map +1 -0
- package/dist/steps/types.d.cts +332 -0
- package/dist/steps/types.d.cts.map +1 -0
- package/dist/steps/types.d.mts +332 -0
- package/dist/steps/types.d.mts.map +1 -0
- package/dist/steps/types.mjs +27 -0
- package/dist/steps/types.mjs.map +1 -0
- package/dist/steps/utils.cjs +96 -0
- package/dist/steps/utils.cjs.map +1 -0
- package/dist/steps/utils.d.cts +10 -0
- package/dist/steps/utils.d.cts.map +1 -0
- package/dist/steps/utils.d.mts +10 -0
- package/dist/steps/utils.d.mts.map +1 -0
- package/dist/steps/utils.mjs +94 -0
- package/dist/steps/utils.mjs.map +1 -0
- package/dist/storage.cjs +68 -0
- package/dist/storage.cjs.map +1 -0
- package/dist/storage.d.cts +33 -0
- package/dist/storage.d.cts.map +1 -0
- package/dist/storage.d.mts +33 -0
- package/dist/storage.d.mts.map +1 -0
- package/dist/storage.mjs +67 -0
- package/dist/storage.mjs.map +1 -0
- package/dist/subscribable.cjs +25 -0
- package/dist/subscribable.cjs.map +1 -0
- package/dist/subscribable.d.cts +14 -0
- package/dist/subscribable.d.cts.map +1 -0
- package/dist/subscribable.d.mts +14 -0
- package/dist/subscribable.d.mts.map +1 -0
- package/dist/subscribable.mjs +24 -0
- package/dist/subscribable.mjs.map +1 -0
- package/dist/utils/casing.cjs +63 -0
- package/dist/utils/casing.cjs.map +1 -0
- package/dist/utils/casing.d.cts +40 -0
- package/dist/utils/casing.d.cts.map +1 -0
- package/dist/utils/casing.d.mts +40 -0
- package/dist/utils/casing.d.mts.map +1 -0
- package/dist/utils/casing.mjs +57 -0
- package/dist/utils/casing.mjs.map +1 -0
- package/dist/utils/field-types.cjs +23 -0
- package/dist/utils/field-types.cjs.map +1 -0
- package/dist/utils/field-types.d.cts +11 -0
- package/dist/utils/field-types.d.cts.map +1 -0
- package/dist/utils/field-types.d.mts +11 -0
- package/dist/utils/field-types.d.mts.map +1 -0
- package/dist/utils/field-types.mjs +20 -0
- package/dist/utils/field-types.mjs.map +1 -0
- package/dist/utils/helpers.cjs +30 -0
- package/dist/utils/helpers.cjs.map +1 -0
- package/dist/utils/helpers.mjs +27 -0
- package/dist/utils/helpers.mjs.map +1 -0
- package/dist/utils/invariant.cjs +18 -0
- package/dist/utils/invariant.cjs.map +1 -0
- package/dist/utils/invariant.d.cts +5 -0
- package/dist/utils/invariant.d.cts.map +1 -0
- package/dist/utils/invariant.d.mts +5 -0
- package/dist/utils/invariant.d.mts.map +1 -0
- package/dist/utils/invariant.mjs +17 -0
- package/dist/utils/invariant.mjs.map +1 -0
- package/dist/utils/logger.cjs +58 -0
- package/dist/utils/logger.cjs.map +1 -0
- package/dist/utils/logger.d.cts +53 -0
- package/dist/utils/logger.d.cts.map +1 -0
- package/dist/utils/logger.d.mts +53 -0
- package/dist/utils/logger.d.mts.map +1 -0
- package/dist/utils/logger.mjs +56 -0
- package/dist/utils/logger.mjs.map +1 -0
- package/dist/utils/path.cjs +331 -0
- package/dist/utils/path.cjs.map +1 -0
- package/dist/utils/path.d.cts +139 -0
- package/dist/utils/path.d.cts.map +1 -0
- package/dist/utils/path.d.mts +139 -0
- package/dist/utils/path.d.mts.map +1 -0
- package/dist/utils/path.mjs +325 -0
- package/dist/utils/path.mjs.map +1 -0
- package/dist/utils/types.d.cts +25 -0
- package/dist/utils/types.d.cts.map +1 -0
- package/dist/utils/types.d.mts +25 -0
- package/dist/utils/types.d.mts.map +1 -0
- package/dist/utils/validator.cjs +12 -0
- package/dist/utils/validator.cjs.map +1 -0
- package/dist/utils/validator.d.cts +77 -0
- package/dist/utils/validator.d.cts.map +1 -0
- package/dist/utils/validator.d.mts +77 -0
- package/dist/utils/validator.d.mts.map +1 -0
- package/dist/utils/validator.mjs +11 -0
- package/dist/utils/validator.mjs.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const require_path = require('./utils/path.cjs');
|
|
2
|
+
const require_utils = require('./internals/utils.cjs');
|
|
3
|
+
const require_step_schema = require('./internals/step-schema.cjs');
|
|
4
|
+
|
|
5
|
+
exports.MultiStepFormStepSchemaInternal = require_step_schema.MultiStepFormStepSchemaInternal;
|
|
6
|
+
exports.VALIDATED_STEP_REGEX = require_utils.VALIDATED_STEP_REGEX;
|
|
7
|
+
exports.createStep = require_utils.createStep;
|
|
8
|
+
exports.isValidStepKey = require_utils.isValidStepKey;
|
|
9
|
+
Object.defineProperty(exports, 'path', {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return require_path.path;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { path } from "./utils/path.cjs";
|
|
2
|
+
import { InternalOptions, MultiStepFormStepSchemaInternal } from "./internals/step-schema.cjs";
|
|
3
|
+
import { VALIDATED_STEP_REGEX, createStep, isValidStepKey } from "./internals/utils.cjs";
|
|
4
|
+
export { InternalOptions, MultiStepFormStepSchemaInternal, VALIDATED_STEP_REGEX, createStep, isValidStepKey, path };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { path } from "./utils/path.mjs";
|
|
2
|
+
import { InternalOptions, MultiStepFormStepSchemaInternal } from "./internals/step-schema.mjs";
|
|
3
|
+
import { VALIDATED_STEP_REGEX, createStep, isValidStepKey } from "./internals/utils.mjs";
|
|
4
|
+
export { InternalOptions, MultiStepFormStepSchemaInternal, VALIDATED_STEP_REGEX, createStep, isValidStepKey, path };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { path } from "./utils/path.mjs";
|
|
2
|
+
import { VALIDATED_STEP_REGEX, createStep, isValidStepKey } from "./internals/utils.mjs";
|
|
3
|
+
import { MultiStepFormStepSchemaInternal } from "./internals/step-schema.mjs";
|
|
4
|
+
|
|
5
|
+
export { MultiStepFormStepSchemaInternal, VALIDATED_STEP_REGEX, createStep, isValidStepKey, path };
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const require_invariant = require('./utils/invariant.cjs');
|
|
2
|
+
const require_utils = require('./steps/utils.cjs');
|
|
3
|
+
const require_casing = require('./utils/casing.cjs');
|
|
4
|
+
const require_field_types = require('./utils/field-types.cjs');
|
|
5
|
+
const require_logger = require('./utils/logger.cjs');
|
|
6
|
+
const require_utils$1 = require('./internals/utils.cjs');
|
|
7
|
+
const require_storage = require('./storage.cjs');
|
|
8
|
+
require('./_internals.cjs');
|
|
9
|
+
const require_fields = require('./steps/fields.cjs');
|
|
10
|
+
const require_schema = require('./steps/schema.cjs');
|
|
11
|
+
const require_types = require('./steps/types.cjs');
|
|
12
|
+
require('./steps/index.cjs');
|
|
13
|
+
const require_schema$1 = require('./schema.cjs');
|
|
14
|
+
const require_observable = require('./observable.cjs');
|
|
15
|
+
|
|
16
|
+
exports.CASING_TYPES = require_casing.CASING_TYPES;
|
|
17
|
+
exports.DEFAULT_CASING = require_casing.DEFAULT_CASING;
|
|
18
|
+
exports.DEFAULT_FIELD_TYPE = require_field_types.DEFAULT_FIELD_TYPE;
|
|
19
|
+
exports.DEFAULT_LOGGER_PREFIX = require_logger.DEFAULT_LOGGER_PREFIX;
|
|
20
|
+
exports.DEFAULT_STORAGE_KEY = require_storage.DEFAULT_STORAGE_KEY;
|
|
21
|
+
exports.FIELD_TYPES = require_field_types.FIELD_TYPES;
|
|
22
|
+
Object.defineProperty(exports, 'HelperFnChosenSteps', {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function () {
|
|
25
|
+
return require_types.HelperFnChosenSteps;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
exports.MultiStepFormLogger = require_logger.MultiStepFormLogger;
|
|
29
|
+
exports.MultiStepFormObserver = require_observable.MultiStepFormObserver;
|
|
30
|
+
exports.MultiStepFormSchema = require_schema$1.MultiStepFormSchema;
|
|
31
|
+
exports.MultiStepFormStepSchema = require_schema.MultiStepFormStepSchema;
|
|
32
|
+
exports.MultiStepFormStorage = require_storage.MultiStepFormStorage;
|
|
33
|
+
exports.VALIDATED_STEP_REGEX = require_utils$1.VALIDATED_STEP_REGEX;
|
|
34
|
+
exports.changeCasing = require_casing.changeCasing;
|
|
35
|
+
exports.createCtx = require_utils.createCtx;
|
|
36
|
+
exports.createMultiStepFormSchema = require_schema$1.createMultiStepFormSchema;
|
|
37
|
+
exports.createStep = require_utils$1.createStep;
|
|
38
|
+
Object.defineProperty(exports, 'fields', {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
get: function () {
|
|
41
|
+
return require_fields.fields;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
exports.invariant = require_invariant.invariant;
|
|
45
|
+
exports.isCasingValid = require_casing.isCasingValid;
|
|
46
|
+
exports.isFieldType = require_field_types.isFieldType;
|
|
47
|
+
exports.isValidStepKey = require_utils$1.isValidStepKey;
|
|
48
|
+
exports.quote = require_casing.quote;
|
|
49
|
+
exports.setCasingType = require_casing.setCasingType;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DEFAULT_STORAGE_KEY, DefaultStorageKey, MultiStepFormStorage, StorageConfig } from "./storage.cjs";
|
|
2
|
+
import { Constrain, DeepKeys, DeepPartial, DeepValue, Expand, Join, Override, SetDefaultString, Split, objectHelpers, unionHelpers } from "./utils/types.cjs";
|
|
3
|
+
import { CASING_TYPES, CapitalizeWord, CasingType, ChangeCasing, ChangeObjectCasing, DEFAULT_CASING, DefaultCasing, ToLower, changeCasing, isCasingValid, quote, setCasingType } from "./utils/casing.cjs";
|
|
4
|
+
import { DEFAULT_FIELD_TYPE, DefaultFieldType, FIELD_TYPES, FieldType, isFieldType } from "./utils/field-types.cjs";
|
|
5
|
+
import { DEFAULT_LOGGER_PREFIX, MultiStepFormLogger } from "./utils/logger.cjs";
|
|
6
|
+
import { invariant } from "./utils/invariant.cjs";
|
|
7
|
+
import { AnyResolvedStep, AnyStep, AnyStepField, AnyStepFieldOption, ClampTo0to10, CreateHelperFunctionOptionsBase, CreateHelperFunctionOptionsWithCustomCtxOptions, CreateHelperFunctionOptionsWithValidator, CreateHelperFunctionOptionsWithoutValidator, CreateStepHelperFn, CreatedHelperFnInput, CreatedHelperFnWithInput, CreatedHelperFnWithoutInput, CtxDataSelector, ExtractStepFromKey, FirstStep, GeneralHelperFn, GetCurrentStep, GetDefaultCasingTransformation, GetFieldsForStep, GreaterThan, HelperFn, HelperFnChosenSteps, HelperFnCtx, HelperFnInputBase, HelperFnInputWithValidator, HelperFnInputWithoutValidator, HelperFnResetFn, HelperFnUpdateFn, HelperFnWithValidator, HelperFnWithoutValidator, InferStepOptions, LastStep, Max, Min, MultiStepFormSchemaStepConfig, NameTransformCasingOptions, Range, Relaxed, RequireAtLeastOne, ResetFn, ResolvedFields, ResolvedStep, ResolvedStepBuilder, SetDefault, Step, StepData, StepFieldOptions, StepNumbers, StepOptions, StepSpecificHelperFn, StepSpecificHelperFns, StrippedResolvedStep, Tuple, UnionToTuple, UpdateFn, Updater, ValidStepKey, helperFnResetFn, helperFnUpdateFn } from "./steps/types.cjs";
|
|
8
|
+
import { VALIDATED_STEP_REGEX, createStep, isValidStepKey } from "./internals/utils.cjs";
|
|
9
|
+
import { fields } from "./steps/fields.cjs";
|
|
10
|
+
import { createCtx } from "./steps/utils.cjs";
|
|
11
|
+
import { AsFunction, AsFunctionReturn, AsType, AsTypeMap, MultiStepFormStepSchema, MultiStepFormStepSchemaFunctions, MultiStepFormStepSchemaListener, MultiStepFormStepStepsConfig } from "./steps/schema.cjs";
|
|
12
|
+
import { MultiStepFormSchema, MultiStepFormSchemaListener, MultiStepFormSchemaOptions, createMultiStepFormSchema } from "./schema.cjs";
|
|
13
|
+
import { MultiStepFormObserver, ObserverListener, ObserverOptions } from "./observable.cjs";
|
|
14
|
+
export { AnyResolvedStep, AnyStep, AnyStepField, AnyStepFieldOption, AsFunction, AsFunctionReturn, AsType, AsTypeMap, CASING_TYPES, CapitalizeWord, CasingType, ChangeCasing, ChangeObjectCasing, ClampTo0to10, Constrain, CreateHelperFunctionOptionsBase, CreateHelperFunctionOptionsWithCustomCtxOptions, CreateHelperFunctionOptionsWithValidator, CreateHelperFunctionOptionsWithoutValidator, CreateStepHelperFn, CreatedHelperFnInput, CreatedHelperFnWithInput, CreatedHelperFnWithoutInput, CtxDataSelector, DEFAULT_CASING, DEFAULT_FIELD_TYPE, DEFAULT_LOGGER_PREFIX, DEFAULT_STORAGE_KEY, DeepKeys, DeepPartial, DeepValue, DefaultCasing, DefaultFieldType, DefaultStorageKey, Expand, ExtractStepFromKey, FIELD_TYPES, FieldType, FirstStep, GeneralHelperFn, GetCurrentStep, GetDefaultCasingTransformation, GetFieldsForStep, GreaterThan, HelperFn, HelperFnChosenSteps, HelperFnCtx, HelperFnInputBase, HelperFnInputWithValidator, HelperFnInputWithoutValidator, HelperFnResetFn, HelperFnUpdateFn, HelperFnWithValidator, HelperFnWithoutValidator, InferStepOptions, Join, LastStep, Max, Min, MultiStepFormLogger, MultiStepFormObserver, MultiStepFormSchema, MultiStepFormSchemaListener, MultiStepFormSchemaOptions, MultiStepFormSchemaStepConfig, MultiStepFormStepSchema, MultiStepFormStepSchemaFunctions, MultiStepFormStepSchemaListener, MultiStepFormStepStepsConfig, MultiStepFormStorage, NameTransformCasingOptions, ObserverListener, ObserverOptions, Override, Range, Relaxed, RequireAtLeastOne, ResetFn, ResolvedFields, ResolvedStep, ResolvedStepBuilder, SetDefault, SetDefaultString, Split, Step, StepData, StepFieldOptions, StepNumbers, StepOptions, StepSpecificHelperFn, StepSpecificHelperFns, StorageConfig, StrippedResolvedStep, ToLower, Tuple, UnionToTuple, UpdateFn, Updater, VALIDATED_STEP_REGEX, ValidStepKey, changeCasing, createCtx, createMultiStepFormSchema, createStep, fields, helperFnResetFn, helperFnUpdateFn, invariant, isCasingValid, isFieldType, isValidStepKey, objectHelpers, quote, setCasingType, unionHelpers };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DEFAULT_STORAGE_KEY, DefaultStorageKey, MultiStepFormStorage, StorageConfig } from "./storage.mjs";
|
|
2
|
+
import { Constrain, DeepKeys, DeepPartial, DeepValue, Expand, Join, Override, SetDefaultString, Split, objectHelpers, unionHelpers } from "./utils/types.mjs";
|
|
3
|
+
import { CASING_TYPES, CapitalizeWord, CasingType, ChangeCasing, ChangeObjectCasing, DEFAULT_CASING, DefaultCasing, ToLower, changeCasing, isCasingValid, quote, setCasingType } from "./utils/casing.mjs";
|
|
4
|
+
import { DEFAULT_FIELD_TYPE, DefaultFieldType, FIELD_TYPES, FieldType, isFieldType } from "./utils/field-types.mjs";
|
|
5
|
+
import { DEFAULT_LOGGER_PREFIX, MultiStepFormLogger } from "./utils/logger.mjs";
|
|
6
|
+
import { invariant } from "./utils/invariant.mjs";
|
|
7
|
+
import { AnyResolvedStep, AnyStep, AnyStepField, AnyStepFieldOption, ClampTo0to10, CreateHelperFunctionOptionsBase, CreateHelperFunctionOptionsWithCustomCtxOptions, CreateHelperFunctionOptionsWithValidator, CreateHelperFunctionOptionsWithoutValidator, CreateStepHelperFn, CreatedHelperFnInput, CreatedHelperFnWithInput, CreatedHelperFnWithoutInput, CtxDataSelector, ExtractStepFromKey, FirstStep, GeneralHelperFn, GetCurrentStep, GetDefaultCasingTransformation, GetFieldsForStep, GreaterThan, HelperFn, HelperFnChosenSteps, HelperFnCtx, HelperFnInputBase, HelperFnInputWithValidator, HelperFnInputWithoutValidator, HelperFnResetFn, HelperFnUpdateFn, HelperFnWithValidator, HelperFnWithoutValidator, InferStepOptions, LastStep, Max, Min, MultiStepFormSchemaStepConfig, NameTransformCasingOptions, Range, Relaxed, RequireAtLeastOne, ResetFn, ResolvedFields, ResolvedStep, ResolvedStepBuilder, SetDefault, Step, StepData, StepFieldOptions, StepNumbers, StepOptions, StepSpecificHelperFn, StepSpecificHelperFns, StrippedResolvedStep, Tuple, UnionToTuple, UpdateFn, Updater, ValidStepKey, helperFnResetFn, helperFnUpdateFn } from "./steps/types.mjs";
|
|
8
|
+
import { VALIDATED_STEP_REGEX, createStep, isValidStepKey } from "./internals/utils.mjs";
|
|
9
|
+
import { fields } from "./steps/fields.mjs";
|
|
10
|
+
import { createCtx } from "./steps/utils.mjs";
|
|
11
|
+
import { AsFunction, AsFunctionReturn, AsType, AsTypeMap, MultiStepFormStepSchema, MultiStepFormStepSchemaFunctions, MultiStepFormStepSchemaListener, MultiStepFormStepStepsConfig } from "./steps/schema.mjs";
|
|
12
|
+
import { MultiStepFormSchema, MultiStepFormSchemaListener, MultiStepFormSchemaOptions, createMultiStepFormSchema } from "./schema.mjs";
|
|
13
|
+
import { MultiStepFormObserver, ObserverListener, ObserverOptions } from "./observable.mjs";
|
|
14
|
+
export { AnyResolvedStep, AnyStep, AnyStepField, AnyStepFieldOption, AsFunction, AsFunctionReturn, AsType, AsTypeMap, CASING_TYPES, CapitalizeWord, CasingType, ChangeCasing, ChangeObjectCasing, ClampTo0to10, Constrain, CreateHelperFunctionOptionsBase, CreateHelperFunctionOptionsWithCustomCtxOptions, CreateHelperFunctionOptionsWithValidator, CreateHelperFunctionOptionsWithoutValidator, CreateStepHelperFn, CreatedHelperFnInput, CreatedHelperFnWithInput, CreatedHelperFnWithoutInput, CtxDataSelector, DEFAULT_CASING, DEFAULT_FIELD_TYPE, DEFAULT_LOGGER_PREFIX, DEFAULT_STORAGE_KEY, DeepKeys, DeepPartial, DeepValue, DefaultCasing, DefaultFieldType, DefaultStorageKey, Expand, ExtractStepFromKey, FIELD_TYPES, FieldType, FirstStep, GeneralHelperFn, GetCurrentStep, GetDefaultCasingTransformation, GetFieldsForStep, GreaterThan, HelperFn, HelperFnChosenSteps, HelperFnCtx, HelperFnInputBase, HelperFnInputWithValidator, HelperFnInputWithoutValidator, HelperFnResetFn, HelperFnUpdateFn, HelperFnWithValidator, HelperFnWithoutValidator, InferStepOptions, Join, LastStep, Max, Min, MultiStepFormLogger, MultiStepFormObserver, MultiStepFormSchema, MultiStepFormSchemaListener, MultiStepFormSchemaOptions, MultiStepFormSchemaStepConfig, MultiStepFormStepSchema, MultiStepFormStepSchemaFunctions, MultiStepFormStepSchemaListener, MultiStepFormStepStepsConfig, MultiStepFormStorage, NameTransformCasingOptions, ObserverListener, ObserverOptions, Override, Range, Relaxed, RequireAtLeastOne, ResetFn, ResolvedFields, ResolvedStep, ResolvedStepBuilder, SetDefault, SetDefaultString, Split, Step, StepData, StepFieldOptions, StepNumbers, StepOptions, StepSpecificHelperFn, StepSpecificHelperFns, StorageConfig, StrippedResolvedStep, ToLower, Tuple, UnionToTuple, UpdateFn, Updater, VALIDATED_STEP_REGEX, ValidStepKey, changeCasing, createCtx, createMultiStepFormSchema, createStep, fields, helperFnResetFn, helperFnUpdateFn, invariant, isCasingValid, isFieldType, isValidStepKey, objectHelpers, quote, setCasingType, unionHelpers };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { invariant } from "./utils/invariant.mjs";
|
|
2
|
+
import { createCtx } from "./steps/utils.mjs";
|
|
3
|
+
import { CASING_TYPES, DEFAULT_CASING, changeCasing, isCasingValid, quote, setCasingType } from "./utils/casing.mjs";
|
|
4
|
+
import { DEFAULT_FIELD_TYPE, FIELD_TYPES, isFieldType } from "./utils/field-types.mjs";
|
|
5
|
+
import { DEFAULT_LOGGER_PREFIX, MultiStepFormLogger } from "./utils/logger.mjs";
|
|
6
|
+
import { VALIDATED_STEP_REGEX, createStep, isValidStepKey } from "./internals/utils.mjs";
|
|
7
|
+
import { DEFAULT_STORAGE_KEY, MultiStepFormStorage } from "./storage.mjs";
|
|
8
|
+
import "./_internals.mjs";
|
|
9
|
+
import { fields } from "./steps/fields.mjs";
|
|
10
|
+
import { MultiStepFormStepSchema } from "./steps/schema.mjs";
|
|
11
|
+
import { HelperFnChosenSteps } from "./steps/types.mjs";
|
|
12
|
+
import "./steps/index.mjs";
|
|
13
|
+
import { MultiStepFormSchema, createMultiStepFormSchema } from "./schema.mjs";
|
|
14
|
+
import { MultiStepFormObserver } from "./observable.mjs";
|
|
15
|
+
|
|
16
|
+
export { CASING_TYPES, DEFAULT_CASING, DEFAULT_FIELD_TYPE, DEFAULT_LOGGER_PREFIX, DEFAULT_STORAGE_KEY, FIELD_TYPES, HelperFnChosenSteps, MultiStepFormLogger, MultiStepFormObserver, MultiStepFormSchema, MultiStepFormStepSchema, MultiStepFormStorage, VALIDATED_STEP_REGEX, changeCasing, createCtx, createMultiStepFormSchema, createStep, fields, invariant, isCasingValid, isFieldType, isValidStepKey, quote, setCasingType };
|
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
const require_helpers = require('../utils/helpers.cjs');
|
|
2
|
+
const require_invariant = require('../utils/invariant.cjs');
|
|
3
|
+
const require_utils = require('../steps/utils.cjs');
|
|
4
|
+
const require_logger = require('../utils/logger.cjs');
|
|
5
|
+
const require_path = require('../utils/path.cjs');
|
|
6
|
+
const require_validator = require('../utils/validator.cjs');
|
|
7
|
+
const require_utils$1 = require('./utils.cjs');
|
|
8
|
+
const require_types = require('../steps/types.cjs');
|
|
9
|
+
require('../steps/index.cjs');
|
|
10
|
+
|
|
11
|
+
//#region src/internals/step-schema.ts
|
|
12
|
+
function verifyUpdate(options) {
|
|
13
|
+
const { strict, partial, actual, obj, paths, silenceErrors } = options;
|
|
14
|
+
const { mismatches, ok } = require_path.path.equalsAtPaths(obj, paths, actual);
|
|
15
|
+
let isValid = true;
|
|
16
|
+
if (strict) isValid = ok && mismatches.length === 0;
|
|
17
|
+
if (partial) {
|
|
18
|
+
const mismatchesWithoutMissingKey = mismatches.filter(({ reason }) => reason !== "missing-key");
|
|
19
|
+
if (strict) isValid = mismatchesWithoutMissingKey.length === 0;
|
|
20
|
+
else isValid = mismatchesWithoutMissingKey.filter(({ reason }) => reason !== "extra-key").length === 0;
|
|
21
|
+
}
|
|
22
|
+
if (!silenceErrors) require_invariant.invariant(isValid, `[update]: found value mismatches in ${require_path.path.printMismatches({
|
|
23
|
+
ok,
|
|
24
|
+
mismatches
|
|
25
|
+
})}`);
|
|
26
|
+
}
|
|
27
|
+
var MultiStepFormStepSchemaInternal = class {
|
|
28
|
+
#originalValue;
|
|
29
|
+
#additionalEnrichedProps;
|
|
30
|
+
#getValue;
|
|
31
|
+
#setValue;
|
|
32
|
+
get value() {
|
|
33
|
+
return this.#getValue();
|
|
34
|
+
}
|
|
35
|
+
constructor(options) {
|
|
36
|
+
const { getValue, setValue, originalValue, additionalEnrichedProps } = options;
|
|
37
|
+
this.#originalValue = originalValue;
|
|
38
|
+
this.#getValue = getValue;
|
|
39
|
+
this.#setValue = setValue;
|
|
40
|
+
this.#additionalEnrichedProps = additionalEnrichedProps;
|
|
41
|
+
}
|
|
42
|
+
handlePostUpdate(value) {
|
|
43
|
+
this.#setValue(this.enrichValues(value));
|
|
44
|
+
}
|
|
45
|
+
buildCtxData(options) {
|
|
46
|
+
const { logger, values, ctxData } = options;
|
|
47
|
+
require_invariant.invariant(typeof ctxData === "function", "[update]: \"ctxData\" must be a function");
|
|
48
|
+
logger.info("Custom \"ctx\" will be used");
|
|
49
|
+
const additionalCtx = ctxData({ ctx: values });
|
|
50
|
+
require_invariant.invariant(typeof additionalCtx === "object" && Object.keys(additionalCtx).length > 0, "[update]: \"ctxData\" must return an object with keys");
|
|
51
|
+
logger.info(`Custom "ctx" consists of the following keys: ${new Intl.ListFormat("en", {
|
|
52
|
+
style: "long",
|
|
53
|
+
type: "conjunction"
|
|
54
|
+
}).format(Object.keys(additionalCtx))}`);
|
|
55
|
+
return additionalCtx;
|
|
56
|
+
}
|
|
57
|
+
createStepUpdaterFnImpl(options) {
|
|
58
|
+
const { targetStep, ctxData, fields = "all", debug, partial = false, strict = true, silentErrors } = options;
|
|
59
|
+
const silenceErrors = silentErrors ?? (partial || !strict);
|
|
60
|
+
const logger = new require_logger.MultiStepFormLogger({
|
|
61
|
+
debug,
|
|
62
|
+
prefix: (value) => `${value}:update${targetStep}`
|
|
63
|
+
});
|
|
64
|
+
logger.info(`${targetStep} will be updated`);
|
|
65
|
+
require_invariant.invariant(require_utils$1.isValidStepKey(this.value, targetStep), `[update]: The target step ${targetStep} isn't a valid step. Please select a valid step`);
|
|
66
|
+
const { [targetStep]: currentStep, ...values } = this.value;
|
|
67
|
+
require_invariant.invariant("updater" in options, "[update]: No \"updater\" was found. Please provide a value to the \"updater\" property");
|
|
68
|
+
const updater = options.updater;
|
|
69
|
+
let updatedValue = { ...this.value };
|
|
70
|
+
let ctx = require_utils.createCtx(updatedValue, [targetStep]);
|
|
71
|
+
if (ctxData) {
|
|
72
|
+
const additionalCtx = this.buildCtxData({
|
|
73
|
+
values,
|
|
74
|
+
ctxData,
|
|
75
|
+
logger
|
|
76
|
+
});
|
|
77
|
+
ctx = {
|
|
78
|
+
...ctx,
|
|
79
|
+
...additionalCtx
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
const updated = require_utils.functionalUpdate(updater, {
|
|
83
|
+
ctx,
|
|
84
|
+
update: this.createHelperFnInputUpdate([targetStep]),
|
|
85
|
+
reset: this.createHelperFnInputReset([targetStep])
|
|
86
|
+
});
|
|
87
|
+
logger.info(`The updated data is ${JSON.stringify(updated, null, 2)}`);
|
|
88
|
+
if (fields === "all") {
|
|
89
|
+
require_invariant.invariant(typeof updated === "object", "[update]: \"updater\" must be an object or a function that returns an object");
|
|
90
|
+
const functionKeys = new Set([
|
|
91
|
+
"update",
|
|
92
|
+
"reset",
|
|
93
|
+
"createHelperFn"
|
|
94
|
+
]);
|
|
95
|
+
const stepKeys = Object.keys(this.value);
|
|
96
|
+
const updaterResultKeys = Object.keys(updated).filter((value) => !functionKeys.has(value));
|
|
97
|
+
const missingKeys = stepKeys.filter((key) => !updaterResultKeys.includes(key));
|
|
98
|
+
for (const stepKey of stepKeys) {
|
|
99
|
+
const { update, reset, createHelperFn, ...currentStep$1 } = this.value[stepKey];
|
|
100
|
+
require_invariant.invariant(updaterResultKeys.length === Object.keys(currentStep$1).length, (formatter) => {
|
|
101
|
+
return `[update]: "updater" is missing keys ${formatter.format(missingKeys)}`;
|
|
102
|
+
});
|
|
103
|
+
const functions = {
|
|
104
|
+
update,
|
|
105
|
+
reset,
|
|
106
|
+
createHelperFn
|
|
107
|
+
};
|
|
108
|
+
const obj = {
|
|
109
|
+
...currentStep$1,
|
|
110
|
+
update,
|
|
111
|
+
reset,
|
|
112
|
+
createHelperFn
|
|
113
|
+
};
|
|
114
|
+
const paths = require_path.path.createDeep(obj);
|
|
115
|
+
const actual = {
|
|
116
|
+
...updated,
|
|
117
|
+
...functions
|
|
118
|
+
};
|
|
119
|
+
verifyUpdate({
|
|
120
|
+
strict,
|
|
121
|
+
partial,
|
|
122
|
+
silenceErrors,
|
|
123
|
+
obj,
|
|
124
|
+
paths,
|
|
125
|
+
actual
|
|
126
|
+
});
|
|
127
|
+
logger.info("The entire step will be updated");
|
|
128
|
+
const currentUpdatedValue = updatedValue[stepKey];
|
|
129
|
+
const updatedAtPath = require_path.path.updateAt({
|
|
130
|
+
obj: currentUpdatedValue,
|
|
131
|
+
paths,
|
|
132
|
+
value: actual,
|
|
133
|
+
partial
|
|
134
|
+
});
|
|
135
|
+
updatedValue = {
|
|
136
|
+
...updatedValue,
|
|
137
|
+
[targetStep]: updatedAtPath
|
|
138
|
+
};
|
|
139
|
+
this.handlePostUpdate(updatedValue);
|
|
140
|
+
logger.info(`The new value is: ${JSON.stringify(updatedValue, null, 2)}`);
|
|
141
|
+
}
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const currentStepDeepKeys = require_path.path.createDeep(currentStep);
|
|
145
|
+
if (Array.isArray(fields)) {
|
|
146
|
+
const compareResult = require_helpers.comparePartialArray(currentStepDeepKeys, fields);
|
|
147
|
+
require_invariant.invariant(compareResult.status === "success", `[update]: Found errors with the provided fields\n${compareResult.status === "error" ? require_helpers.printErrors(compareResult.errors) : ""}`);
|
|
148
|
+
verifyUpdate({
|
|
149
|
+
strict,
|
|
150
|
+
partial,
|
|
151
|
+
silenceErrors,
|
|
152
|
+
obj: currentStep,
|
|
153
|
+
paths: fields,
|
|
154
|
+
actual: updated
|
|
155
|
+
});
|
|
156
|
+
logger.info(`The following fields will be updated: ${new Intl.ListFormat("en", {
|
|
157
|
+
type: "conjunction",
|
|
158
|
+
style: "long"
|
|
159
|
+
}).format(fields)}`);
|
|
160
|
+
updatedValue = {
|
|
161
|
+
...updatedValue,
|
|
162
|
+
[targetStep]: require_path.path.updateAt({
|
|
163
|
+
obj: currentStep,
|
|
164
|
+
paths: fields,
|
|
165
|
+
value: updated,
|
|
166
|
+
partial
|
|
167
|
+
})
|
|
168
|
+
};
|
|
169
|
+
this.handlePostUpdate(updatedValue);
|
|
170
|
+
logger.info(`The new value is: ${JSON.stringify(updatedValue, null, 2)}`);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
if (typeof fields === "object" && Object.keys(fields).length > 0) {
|
|
174
|
+
const keys = require_path.path.createDeep(fields);
|
|
175
|
+
const compareResult = require_helpers.comparePartialArray(currentStepDeepKeys, keys);
|
|
176
|
+
require_invariant.invariant(compareResult.status === "success", `[update]: Found errors with the provided fields\n${compareResult.status === "error" ? require_helpers.printErrors(compareResult.errors) : ""}`);
|
|
177
|
+
verifyUpdate({
|
|
178
|
+
strict,
|
|
179
|
+
partial,
|
|
180
|
+
silenceErrors,
|
|
181
|
+
obj: currentStep,
|
|
182
|
+
paths: keys,
|
|
183
|
+
actual: updated
|
|
184
|
+
});
|
|
185
|
+
updatedValue = {
|
|
186
|
+
...updatedValue,
|
|
187
|
+
[targetStep]: require_path.path.updateAt({
|
|
188
|
+
obj: currentStep,
|
|
189
|
+
paths: keys,
|
|
190
|
+
value: updated,
|
|
191
|
+
partial
|
|
192
|
+
})
|
|
193
|
+
};
|
|
194
|
+
logger.info(`The following fields will be updated: ${new Intl.ListFormat("en", {
|
|
195
|
+
type: "conjunction",
|
|
196
|
+
style: "long"
|
|
197
|
+
}).format(Object.keys(fields))}`);
|
|
198
|
+
this.handlePostUpdate(updatedValue);
|
|
199
|
+
logger.info(`The new value is: ${JSON.stringify(updatedValue, null, 2)}`);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
logger.error("Unsupported value for the \"fields\" option");
|
|
203
|
+
throw new TypeError(`[update]: property "fields" must be set to one of the following: "all", an array of deep paths to update, or an object of paths. Was ${typeof updater}`, { cause: updater });
|
|
204
|
+
}
|
|
205
|
+
createStepUpdaterFn(targetStep) {
|
|
206
|
+
return (options) => {
|
|
207
|
+
this.createStepUpdaterFnImpl({
|
|
208
|
+
targetStep,
|
|
209
|
+
...options
|
|
210
|
+
});
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
update(options) {
|
|
214
|
+
return this.createStepUpdaterFnImpl(options);
|
|
215
|
+
}
|
|
216
|
+
resetFields(config) {
|
|
217
|
+
return (fields) => {
|
|
218
|
+
const { targetStep, logger, values } = config;
|
|
219
|
+
const resolvedFields = fields.map((value) => `${targetStep}.${value}`);
|
|
220
|
+
const picked = require_path.path.pickBy(values, ...resolvedFields);
|
|
221
|
+
config.updatedValues = {
|
|
222
|
+
...config.updatedValues,
|
|
223
|
+
...require_path.path.updateAt({
|
|
224
|
+
obj: values,
|
|
225
|
+
paths: resolvedFields,
|
|
226
|
+
value: picked
|
|
227
|
+
})
|
|
228
|
+
};
|
|
229
|
+
const message = `${new Intl.ListFormat("en", {
|
|
230
|
+
style: "long",
|
|
231
|
+
type: "conjunction"
|
|
232
|
+
}).format(fields)} for ${targetStep}`;
|
|
233
|
+
logger.info(`Resetting ${message}`);
|
|
234
|
+
this.handlePostUpdate(config.updatedValues);
|
|
235
|
+
logger.info(`Reset ${message}`);
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
createStepResetterFnImpl(options) {
|
|
239
|
+
const { fields = "all", targetStep, debug } = options;
|
|
240
|
+
const logger = new require_logger.MultiStepFormLogger({
|
|
241
|
+
debug,
|
|
242
|
+
prefix: (value) => `${value}:reset${targetStep}`
|
|
243
|
+
});
|
|
244
|
+
require_invariant.invariant(fields, "[update]: \"fields\" must have a value when \"type\" is \"reset\"");
|
|
245
|
+
const originalValues = require_utils$1.createStep(this.#originalValue);
|
|
246
|
+
const enrichedOriginalValues = this.enrichValues(originalValues, this.#additionalEnrichedProps);
|
|
247
|
+
if (fields === "all") {
|
|
248
|
+
logger.info(`Resetting all fields for ${targetStep}`);
|
|
249
|
+
this.handlePostUpdate(enrichedOriginalValues);
|
|
250
|
+
logger.info(`Reset all fields for ${targetStep}`);
|
|
251
|
+
}
|
|
252
|
+
let updatedValues = { ...enrichedOriginalValues };
|
|
253
|
+
const reset = this.resetFields({
|
|
254
|
+
logger,
|
|
255
|
+
targetStep,
|
|
256
|
+
updatedValues,
|
|
257
|
+
values: enrichedOriginalValues
|
|
258
|
+
});
|
|
259
|
+
if (require_utils$1.isTupleNotation(fields)) reset(fields);
|
|
260
|
+
if (typeof fields === "object" && Object.keys(fields).length > 0) reset(require_path.path.createDeep(fields));
|
|
261
|
+
}
|
|
262
|
+
createStepResetterFn(targetStep) {
|
|
263
|
+
return (options) => {
|
|
264
|
+
return this.createStepResetterFnImpl({
|
|
265
|
+
targetStep,
|
|
266
|
+
fields: options?.fields ?? "all",
|
|
267
|
+
debug: options?.debug ?? false
|
|
268
|
+
});
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
reset(options) {
|
|
272
|
+
this.createStepResetterFnImpl(options);
|
|
273
|
+
}
|
|
274
|
+
createHelperFnInputUpdate(chosenSteps) {
|
|
275
|
+
if (require_types.HelperFnChosenSteps.isAll(chosenSteps)) {
|
|
276
|
+
const stepSpecificUpdateFn = require_helpers.typedObjectKeys(this.value).reduce((acc, key) => {
|
|
277
|
+
acc[key] = this.createStepUpdaterFn(key);
|
|
278
|
+
return acc;
|
|
279
|
+
}, {});
|
|
280
|
+
return Object.assign(this.update, stepSpecificUpdateFn);
|
|
281
|
+
}
|
|
282
|
+
const validKeys = Object.keys(this.value);
|
|
283
|
+
if (require_types.HelperFnChosenSteps.isTuple(chosenSteps, validKeys)) {
|
|
284
|
+
const stepSpecificUpdateFn = chosenSteps.reduce((acc, step) => {
|
|
285
|
+
acc[step] = this.createStepUpdaterFn(step);
|
|
286
|
+
return acc;
|
|
287
|
+
}, {});
|
|
288
|
+
return Object.assign(this.update, stepSpecificUpdateFn);
|
|
289
|
+
}
|
|
290
|
+
if (require_types.HelperFnChosenSteps.isObject(chosenSteps, validKeys)) {
|
|
291
|
+
const stepSpecificUpdateFn = require_helpers.typedObjectKeys(chosenSteps).reduce((acc, key) => {
|
|
292
|
+
acc[key] = this.createStepUpdaterFn(key);
|
|
293
|
+
return acc;
|
|
294
|
+
}, {});
|
|
295
|
+
return Object.assign(this.update, stepSpecificUpdateFn);
|
|
296
|
+
}
|
|
297
|
+
throw new TypeError(`[update]: ${require_types.HelperFnChosenSteps.CATCH_ALL_MESSAGE}`);
|
|
298
|
+
}
|
|
299
|
+
createHelperFnInputReset(chosenSteps) {
|
|
300
|
+
if (require_types.HelperFnChosenSteps.isAll(chosenSteps)) {
|
|
301
|
+
const stepSpecificUpdateFn = require_helpers.typedObjectKeys(this.value).reduce((acc, key) => {
|
|
302
|
+
acc[key] = this.createStepResetterFn(key);
|
|
303
|
+
return acc;
|
|
304
|
+
}, {});
|
|
305
|
+
return Object.assign(this.reset, stepSpecificUpdateFn);
|
|
306
|
+
}
|
|
307
|
+
const validKeys = Object.keys(this.value);
|
|
308
|
+
if (require_types.HelperFnChosenSteps.isTuple(chosenSteps, validKeys)) {
|
|
309
|
+
const stepSpecificUpdateFn = chosenSteps.reduce((acc, step) => {
|
|
310
|
+
acc[step] = this.createStepResetterFn(step);
|
|
311
|
+
return acc;
|
|
312
|
+
}, {});
|
|
313
|
+
return Object.assign(this.reset, stepSpecificUpdateFn);
|
|
314
|
+
}
|
|
315
|
+
if (require_types.HelperFnChosenSteps.isObject(chosenSteps, validKeys)) {
|
|
316
|
+
const stepSpecificUpdateFn = require_helpers.typedObjectKeys(chosenSteps).reduce((acc, key) => {
|
|
317
|
+
acc[key] = this.createStepResetterFn(key);
|
|
318
|
+
return acc;
|
|
319
|
+
}, {});
|
|
320
|
+
return Object.assign(this.reset, stepSpecificUpdateFn);
|
|
321
|
+
}
|
|
322
|
+
throw new TypeError(`[update]: ${require_types.HelperFnChosenSteps.CATCH_ALL_MESSAGE}`);
|
|
323
|
+
}
|
|
324
|
+
createStepHelperFn(stepData) {
|
|
325
|
+
return (optionsOrFunction, fn) => {
|
|
326
|
+
const functions = {
|
|
327
|
+
update: this.createHelperFnInputUpdate(stepData),
|
|
328
|
+
reset: this.createHelperFnInputReset(stepData)
|
|
329
|
+
};
|
|
330
|
+
if (typeof optionsOrFunction === "function") return () => {
|
|
331
|
+
return optionsOrFunction({
|
|
332
|
+
ctx: require_utils.createCtx(this.value, stepData),
|
|
333
|
+
...functions
|
|
334
|
+
});
|
|
335
|
+
};
|
|
336
|
+
if (typeof optionsOrFunction === "object") return (input) => {
|
|
337
|
+
const ctx = require_utils.createCtx(this.value, stepData);
|
|
338
|
+
if ("validator" in optionsOrFunction) {
|
|
339
|
+
require_invariant.invariant(typeof input === "object", "An input is expected since you provided a validator");
|
|
340
|
+
require_validator.runStandardValidation(optionsOrFunction.validator, input.data);
|
|
341
|
+
let resolvedCtx = ctx;
|
|
342
|
+
if (optionsOrFunction.ctxData) {
|
|
343
|
+
const currentStepKey = stepData[0];
|
|
344
|
+
const { [currentStepKey]: _, ...values } = this.value;
|
|
345
|
+
resolvedCtx = {
|
|
346
|
+
...resolvedCtx,
|
|
347
|
+
...optionsOrFunction.ctxData({ ctx: values })
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
return fn({
|
|
351
|
+
ctx: resolvedCtx,
|
|
352
|
+
...functions,
|
|
353
|
+
...input
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
return fn({
|
|
357
|
+
ctx,
|
|
358
|
+
...functions
|
|
359
|
+
});
|
|
360
|
+
};
|
|
361
|
+
throw new Error(`The first argument must be a function or an object, (was ${typeof optionsOrFunction})`);
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
extractStepFromKey(key) {
|
|
365
|
+
const [targetStep] = [key];
|
|
366
|
+
return {
|
|
367
|
+
targetStep,
|
|
368
|
+
step: Number.parseInt(targetStep.replace("step", ""))
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
enrichValues(values, additionalProps) {
|
|
372
|
+
let enriched = { ...values };
|
|
373
|
+
for (const [key, stepValue] of Object.entries(enriched)) {
|
|
374
|
+
const { step, targetStep } = this.extractStepFromKey(key);
|
|
375
|
+
enriched[targetStep] = {
|
|
376
|
+
...stepValue,
|
|
377
|
+
update: this.createStepUpdaterFn(targetStep),
|
|
378
|
+
reset: this.createStepResetterFn(targetStep),
|
|
379
|
+
createHelperFn: this.createStepHelperFn([targetStep]),
|
|
380
|
+
...additionalProps?.(step)
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
return enriched;
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
//#endregion
|
|
388
|
+
exports.MultiStepFormStepSchemaInternal = MultiStepFormStepSchemaInternal;
|
|
389
|
+
//# sourceMappingURL=step-schema.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step-schema.cjs","names":["path","#originalValue","#additionalEnrichedProps","#getValue","#setValue","MultiStepFormLogger","isValidStepKey","createCtx","functionalUpdate","currentStep","actual: Record<string, unknown>","comparePartialArray","printErrors","createStep","isTupleNotation","HelperFnChosenSteps","typedObjectKeys"],"sources":["../../src/internals/step-schema.ts"],"sourcesContent":["import {\n createCtx,\n HelperFnChosenSteps,\n type AnyResolvedStep,\n type CreatedHelperFnInput,\n type CreateHelperFunctionOptionsWithoutValidator,\n type CreateHelperFunctionOptionsWithValidator,\n type CtxDataSelector,\n type HelperFnCtx,\n type helperFnResetFn,\n type HelperFnResetFn,\n type helperFnUpdateFn,\n type HelperFnUpdateFn,\n type HelperFnWithoutValidator,\n type HelperFnWithValidator,\n type InferStepOptions,\n type ResetFn,\n type Step,\n type StepNumbers,\n type UpdateFn,\n type ValidStepKey,\n} from '@/steps';\nimport { functionalUpdate } from '@/steps/utils';\nimport {\n invariant,\n MultiStepFormLogger,\n type CasingType,\n type DeepKeys,\n} from '@/utils';\nimport {\n comparePartialArray,\n printErrors,\n typedObjectKeys,\n} from '@/utils/helpers';\nimport { path } from '@/utils/path';\nimport {\n runStandardValidation,\n type StandardSchemaValidator,\n} from '@/utils/validator';\nimport { createStep, isTupleNotation, isValidStepKey } from './utils';\n\nexport type InternalOptions<\n TStep extends Step<TCasing>,\n TCasing extends CasingType,\n TResolvedStep extends AnyResolvedStep,\n additionalEnrichedProps extends Record<string, unknown>\n> = {\n originalValue: InferStepOptions<TStep>;\n additionalEnrichedProps?: (step: number) => additionalEnrichedProps;\n /**\n * The resolved multi step form values.\n */\n getValue: () => TResolvedStep;\n /**\n * A function used for setting the `value`. It is called after the\n * `value` is updated successfully.\n * @param value The updated and enriched multi step form values.\n * @returns\n */\n setValue: (value: TResolvedStep) => void;\n};\n\nfunction verifyUpdate<def, paths extends DeepKeys<def>>(options: {\n strict: boolean;\n partial: boolean;\n silenceErrors: boolean;\n obj: def;\n paths: paths[];\n actual: path.pickBy<def, paths>;\n}) {\n const { strict, partial, actual, obj, paths, silenceErrors } = options;\n\n // Define the logic for when the update is considered valid\n const { mismatches, ok } = path.equalsAtPaths(obj, paths, actual);\n\n let isValid = true;\n\n if (strict) {\n isValid = ok && mismatches.length === 0;\n }\n\n if (partial) {\n const mismatchesWithoutMissingKey = mismatches.filter(\n ({ reason }) => reason !== 'missing-key'\n );\n\n if (strict) {\n isValid = mismatchesWithoutMissingKey.length === 0;\n } else {\n const withoutExtraKey = mismatchesWithoutMissingKey.filter(\n ({ reason }) => reason !== 'extra-key'\n );\n\n isValid = withoutExtraKey.length === 0;\n }\n }\n\n if (!silenceErrors) {\n invariant(\n isValid,\n `[update]: found value mismatches in ${path.printMismatches({\n ok,\n mismatches,\n })}`\n );\n }\n}\n\nexport class MultiStepFormStepSchemaInternal<\n step extends Step<casing>,\n casing extends CasingType,\n resolvedStep extends AnyResolvedStep,\n stepNumbers extends StepNumbers<resolvedStep>,\n additionalEnrichedProps extends Record<string, unknown> = {}\n> {\n readonly #originalValue: InferStepOptions<step>;\n readonly #additionalEnrichedProps?: (step: number) => additionalEnrichedProps;\n readonly #getValue: () => resolvedStep;\n readonly #setValue: (value: resolvedStep) => void;\n\n private get value() {\n return this.#getValue();\n }\n\n constructor(\n options: InternalOptions<\n step,\n casing,\n resolvedStep,\n additionalEnrichedProps\n >\n ) {\n const { getValue, setValue, originalValue, additionalEnrichedProps } =\n options;\n\n this.#originalValue = originalValue;\n this.#getValue = getValue;\n this.#setValue = setValue;\n this.#additionalEnrichedProps = additionalEnrichedProps;\n }\n\n private handlePostUpdate(value: resolvedStep) {\n this.#setValue(this.enrichValues(value));\n }\n\n private buildCtxData<\n targetStep extends ValidStepKey<stepNumbers>,\n additionalCtx extends Record<string, unknown>\n >(\n options: Required<\n CtxDataSelector<resolvedStep, stepNumbers, [targetStep], additionalCtx>\n > & {\n values: Omit<resolvedStep, targetStep>;\n logger: MultiStepFormLogger;\n }\n ) {\n const { logger, values, ctxData } = options;\n invariant(\n typeof ctxData === 'function',\n '[update]: \"ctxData\" must be a function'\n );\n logger.info('Custom \"ctx\" will be used');\n\n const additionalCtx = ctxData({ ctx: values as never });\n\n invariant(\n typeof additionalCtx === 'object' &&\n Object.keys(additionalCtx).length > 0,\n '[update]: \"ctxData\" must return an object with keys'\n );\n\n logger.info(\n `Custom \"ctx\" consists of the following keys: ${new Intl.ListFormat(\n 'en',\n {\n style: 'long',\n type: 'conjunction',\n }\n ).format(Object.keys(additionalCtx))}`\n );\n\n return additionalCtx;\n }\n\n private createStepUpdaterFnImpl<\n targetStep extends ValidStepKey<stepNumbers>,\n fields extends UpdateFn.chosenFields<\n UpdateFn.resolvedStep<resolvedStep, stepNumbers, targetStep>\n >,\n strict extends boolean,\n partial extends boolean,\n additionalCtx extends Record<string, unknown>,\n additionalUpdaterData extends UpdateFn.additionalUpdaterData\n >(\n options: UpdateFn.options<\n resolvedStep,\n stepNumbers,\n targetStep,\n fields,\n strict,\n partial,\n additionalCtx,\n additionalUpdaterData\n >\n ) {\n const {\n targetStep,\n ctxData,\n fields = 'all',\n debug,\n partial = false,\n strict = true,\n silentErrors,\n } = options;\n const silenceErrors = silentErrors ?? (partial || !strict);\n const logger = new MultiStepFormLogger({\n debug,\n prefix: (value) => `${value}:update${targetStep}`,\n });\n\n logger.info(`${targetStep} will be updated`);\n invariant(\n isValidStepKey(this.value, targetStep),\n `[update]: The target step ${targetStep} isn't a valid step. Please select a valid step`\n );\n\n const { [targetStep]: currentStep, ...values } = this.value;\n\n invariant(\n 'updater' in options,\n '[update]: No \"updater\" was found. Please provide a value to the \"updater\" property'\n );\n\n const updater = options.updater;\n let updatedValue = { ...this.value };\n\n let ctx = createCtx(updatedValue, [targetStep]);\n\n // Build the `ctx` first\n if (ctxData) {\n const additionalCtx = this.buildCtxData({\n values,\n ctxData,\n logger,\n });\n\n ctx = {\n ...ctx,\n ...additionalCtx,\n };\n }\n\n const updated = functionalUpdate(updater, {\n ctx: ctx as never,\n update: this.createHelperFnInputUpdate([targetStep]),\n reset: this.createHelperFnInputReset([targetStep]),\n });\n logger.info(`The updated data is ${JSON.stringify(updated, null, 2)}`);\n\n // TODO validate `updater` - will have to be done in each case (I think)\n\n // default case: updating all fields for the current step\n if (fields === 'all') {\n invariant(\n typeof updated === 'object',\n '[update]: \"updater\" must be an object or a function that returns an object'\n );\n\n const functionKeys = new Set(['update', 'reset', 'createHelperFn']);\n const stepKeys = Object.keys(this.value);\n const updaterResultKeys = Object.keys(\n updated as Record<string, unknown>\n ).filter((value) => !functionKeys.has(value));\n const missingKeys = stepKeys.filter(\n (key) => !updaterResultKeys.includes(key)\n );\n\n for (const stepKey of stepKeys) {\n const { update, reset, createHelperFn, ...currentStep } = this.value[\n stepKey\n ] as resolvedStep[keyof resolvedStep];\n\n invariant(\n updaterResultKeys.length === Object.keys(currentStep).length,\n (formatter) => {\n return `[update]: \"updater\" is missing keys ${formatter.format(\n missingKeys\n )}`;\n }\n );\n const functions = { update, reset, createHelperFn };\n const obj = { ...currentStep, update, reset, createHelperFn };\n const paths = path.createDeep(obj);\n const actual: Record<string, unknown> = {\n ...updated,\n ...functions,\n };\n\n verifyUpdate({\n strict,\n partial,\n silenceErrors,\n obj,\n paths,\n actual: actual as never,\n });\n\n logger.info('The entire step will be updated');\n\n const currentUpdatedValue = updatedValue[stepKey] as Record<\n string,\n unknown\n >;\n const updatedAtPath = path.updateAt({\n obj: currentUpdatedValue,\n paths,\n value: actual as never,\n partial,\n });\n\n updatedValue = {\n ...updatedValue,\n [targetStep]: updatedAtPath,\n };\n\n this.handlePostUpdate(updatedValue);\n logger.info(\n `The new value is: ${JSON.stringify(updatedValue, null, 2)}`\n );\n }\n\n return;\n }\n\n const currentStepDeepKeys = path.createDeep(currentStep);\n\n if (Array.isArray(fields)) {\n const compareResult = comparePartialArray(currentStepDeepKeys, fields);\n\n invariant(\n compareResult.status === 'success',\n `[update]: Found errors with the provided fields\\n${\n compareResult.status === 'error'\n ? printErrors(compareResult.errors)\n : ''\n }`\n );\n\n verifyUpdate({\n strict,\n partial,\n silenceErrors,\n obj: currentStep,\n paths: fields,\n actual: updated as never,\n });\n\n logger.info(\n `The following fields will be updated: ${new Intl.ListFormat('en', {\n type: 'conjunction',\n style: 'long',\n }).format(fields)}`\n );\n\n updatedValue = {\n ...updatedValue,\n [targetStep]: path.updateAt({\n obj: currentStep,\n paths: fields,\n value: updated as never,\n partial,\n }),\n };\n\n this.handlePostUpdate(updatedValue);\n logger.info(`The new value is: ${JSON.stringify(updatedValue, null, 2)}`);\n\n return;\n }\n\n if (typeof fields === 'object' && Object.keys(fields).length > 0) {\n const keys = path.createDeep(fields);\n const compareResult = comparePartialArray(\n currentStepDeepKeys,\n keys as never\n );\n\n invariant(\n compareResult.status === 'success',\n `[update]: Found errors with the provided fields\\n${\n compareResult.status === 'error'\n ? printErrors(compareResult.errors)\n : ''\n }`\n );\n\n // TODO validate all values (deepest) are `true`\n verifyUpdate({\n strict,\n partial,\n silenceErrors,\n obj: currentStep,\n paths: keys as never,\n actual: updated as never,\n });\n\n updatedValue = {\n ...updatedValue,\n [targetStep]: path.updateAt({\n obj: currentStep,\n paths: keys as never,\n value: updated as never,\n partial,\n }),\n };\n\n logger.info(\n `The following fields will be updated: ${new Intl.ListFormat('en', {\n type: 'conjunction',\n style: 'long',\n }).format(Object.keys(fields))}`\n );\n this.handlePostUpdate(updatedValue);\n logger.info(`The new value is: ${JSON.stringify(updatedValue, null, 2)}`);\n\n return;\n }\n\n logger.error('Unsupported value for the \"fields\" option');\n throw new TypeError(\n `[update]: property \"fields\" must be set to one of the following: \"all\", an array of deep paths to update, or an object of paths. Was ${typeof updater}`,\n { cause: updater }\n );\n }\n\n createStepUpdaterFn<targetStep extends ValidStepKey<stepNumbers>>(\n targetStep: targetStep\n ): UpdateFn.stepSpecific<resolvedStep, stepNumbers, targetStep> {\n return (options) => {\n this.createStepUpdaterFnImpl({ targetStep, ...options });\n };\n }\n\n update<\n targetStep extends ValidStepKey<stepNumbers>,\n field extends UpdateFn.chosenFields<\n UpdateFn.resolvedStep<resolvedStep, stepNumbers, targetStep>\n > = 'all',\n strict extends boolean = true,\n partial extends boolean = false,\n additionalCtx extends Record<string, unknown> = {},\n additionalUpdaterData extends UpdateFn.additionalUpdaterData = never\n >(\n options: UpdateFn.options<\n resolvedStep,\n stepNumbers,\n targetStep,\n field,\n strict,\n partial,\n additionalCtx,\n additionalUpdaterData\n >\n ) {\n return this.createStepUpdaterFnImpl(options);\n }\n\n private resetFields<\n targetStep extends ValidStepKey<stepNumbers>,\n currentStep extends UpdateFn.resolvedStep<\n resolvedStep,\n stepNumbers,\n targetStep\n >\n >(config: {\n targetStep: targetStep;\n values: AnyResolvedStep;\n updatedValues: AnyResolvedStep;\n logger: MultiStepFormLogger;\n }) {\n return <\n fields extends HelperFnChosenSteps.tupleNotation<DeepKeys<currentStep>>\n >(\n fields: fields\n ) => {\n const { targetStep, logger, values } = config;\n const resolvedFields = fields.map((value) => `${targetStep}.${value}`);\n const picked = path.pickBy<resolvedStep, DeepKeys<resolvedStep>>(\n values,\n ...(resolvedFields as any)\n );\n\n config.updatedValues = {\n ...config.updatedValues,\n ...path.updateAt({\n obj: values,\n paths: resolvedFields,\n value: picked,\n }),\n };\n\n const formatter = new Intl.ListFormat('en', {\n style: 'long',\n type: 'conjunction',\n });\n const message = `${formatter.format(fields)} for ${targetStep}`;\n\n logger.info(`Resetting ${message}`);\n this.handlePostUpdate(config.updatedValues);\n logger.info(`Reset ${message}`);\n };\n }\n\n private createStepResetterFnImpl<\n targetStep extends ValidStepKey<stepNumbers>,\n fields extends UpdateFn.chosenFields<currentStep>,\n currentStep extends UpdateFn.resolvedStep<\n resolvedStep,\n stepNumbers,\n targetStep\n >\n >(\n options: ResetFn.Options<\n resolvedStep,\n stepNumbers,\n targetStep,\n fields,\n currentStep\n >\n ) {\n const { fields = 'all', targetStep, debug } = options;\n const logger = new MultiStepFormLogger({\n debug,\n prefix: (value) => `${value}:reset${targetStep}`,\n });\n invariant(\n fields,\n '[update]: \"fields\" must have a value when \"type\" is \"reset\"'\n );\n\n const originalValues = createStep(this.#originalValue);\n const enrichedOriginalValues = this.enrichValues<\n resolvedStep,\n additionalEnrichedProps\n >(originalValues as never, this.#additionalEnrichedProps);\n\n if (fields === 'all') {\n logger.info(`Resetting all fields for ${targetStep}`);\n this.handlePostUpdate(enrichedOriginalValues);\n logger.info(`Reset all fields for ${targetStep}`);\n }\n\n let updatedValues = { ...enrichedOriginalValues };\n const reset = this.resetFields<targetStep, currentStep>({\n logger,\n targetStep,\n updatedValues,\n values: enrichedOriginalValues,\n });\n\n if (isTupleNotation<DeepKeys<currentStep>>(fields)) {\n reset(fields);\n }\n\n if (typeof fields === 'object' && Object.keys(fields).length > 0) {\n const keys = path.createDeep(fields);\n\n reset(keys as never);\n }\n }\n\n createStepResetterFn<targetStep extends ValidStepKey<stepNumbers>>(\n targetStep: targetStep\n ): ResetFn.stepSpecific<resolvedStep, stepNumbers, targetStep> {\n return (options) => {\n return this.createStepResetterFnImpl({\n targetStep,\n fields: options?.fields ?? 'all',\n debug: options?.debug ?? false,\n });\n };\n }\n\n reset<\n targetStep extends ValidStepKey<stepNumbers>,\n fields extends UpdateFn.chosenFields<currentStep>,\n currentStep extends UpdateFn.resolvedStep<\n resolvedStep,\n stepNumbers,\n targetStep\n >\n >(\n options: ResetFn.Options<\n resolvedStep,\n stepNumbers,\n targetStep,\n fields,\n currentStep\n >\n ) {\n this.createStepResetterFnImpl(options);\n }\n\n createHelperFnInputUpdate<\n chosenSteps extends HelperFnChosenSteps<resolvedStep, stepNumbers>\n >(chosenSteps: chosenSteps) {\n if (HelperFnChosenSteps.isAll(chosenSteps)) {\n const stepSpecificUpdateFn = typedObjectKeys(this.value).reduce((acc, key) => {\n (acc as any)[key] = this.createStepUpdaterFn(key as never);\n\n return acc;\n }, {} as helperFnUpdateFn<resolvedStep, stepNumbers, ValidStepKey<stepNumbers>>);\n const update = Object.assign(\n this.update,\n stepSpecificUpdateFn\n ) as HelperFnUpdateFn<resolvedStep, stepNumbers, chosenSteps>;\n\n return update;\n }\n\n const validKeys = Object.keys(this.value);\n\n if (HelperFnChosenSteps.isTuple<stepNumbers>(chosenSteps, validKeys)) {\n const stepSpecificUpdateFn = chosenSteps.reduce((acc, step) => {\n (acc as any)[step] = this.createStepUpdaterFn(step);\n\n return acc;\n }, {} as helperFnUpdateFn<resolvedStep, stepNumbers, ValidStepKey<stepNumbers>>);\n const update = Object.assign(\n this.update,\n stepSpecificUpdateFn\n ) as HelperFnUpdateFn<resolvedStep, stepNumbers, chosenSteps>;\n\n return update;\n }\n\n if (HelperFnChosenSteps.isObject<stepNumbers>(chosenSteps, validKeys)) {\n const stepSpecificUpdateFn = typedObjectKeys<\n HelperFnChosenSteps.objectNotation<`step${stepNumbers}`>,\n ValidStepKey<stepNumbers>\n >(chosenSteps).reduce((acc, key) => {\n (acc as any)[key] = this.createStepUpdaterFn(key);\n\n return acc;\n }, {} as helperFnUpdateFn<resolvedStep, stepNumbers, ValidStepKey<stepNumbers>>);\n const update = Object.assign(\n this.update,\n stepSpecificUpdateFn\n ) as HelperFnUpdateFn<resolvedStep, stepNumbers, chosenSteps>;\n\n return update;\n }\n\n throw new TypeError(`[update]: ${HelperFnChosenSteps.CATCH_ALL_MESSAGE}`);\n }\n\n createHelperFnInputReset<\n chosenSteps extends HelperFnChosenSteps<resolvedStep, stepNumbers>\n >(chosenSteps: chosenSteps) {\n if (HelperFnChosenSteps.isAll(chosenSteps)) {\n const stepSpecificUpdateFn = typedObjectKeys<\n resolvedStep,\n ValidStepKey<stepNumbers>\n >(this.value).reduce((acc, key) => {\n (acc as any)[key] = this.createStepResetterFn(key);\n\n return acc;\n }, {} as helperFnResetFn<resolvedStep, stepNumbers, ValidStepKey<stepNumbers>>);\n const reset = Object.assign(\n this.reset,\n stepSpecificUpdateFn\n ) as HelperFnResetFn<resolvedStep, stepNumbers, chosenSteps>;\n\n return reset;\n }\n\n const validKeys = Object.keys(this.value);\n\n if (HelperFnChosenSteps.isTuple<stepNumbers>(chosenSteps, validKeys)) {\n const stepSpecificUpdateFn = chosenSteps.reduce((acc, step) => {\n (acc as any)[step] = this.createStepResetterFn(step);\n\n return acc;\n }, {} as helperFnResetFn<resolvedStep, stepNumbers, ValidStepKey<stepNumbers>>);\n const reset = Object.assign(\n this.reset,\n stepSpecificUpdateFn\n ) as HelperFnResetFn<resolvedStep, stepNumbers, chosenSteps>;\n\n return reset;\n }\n\n if (HelperFnChosenSteps.isObject<stepNumbers>(chosenSteps, validKeys)) {\n const stepSpecificUpdateFn = typedObjectKeys<\n HelperFnChosenSteps.objectNotation<`step${stepNumbers}`>,\n ValidStepKey<stepNumbers>\n >(chosenSteps).reduce((acc, key) => {\n (acc as any)[key] = this.createStepResetterFn(key);\n\n return acc;\n }, {} as helperFnResetFn<resolvedStep, stepNumbers, ValidStepKey<stepNumbers>>);\n const reset = Object.assign(\n this.reset,\n stepSpecificUpdateFn\n ) as HelperFnResetFn<resolvedStep, stepNumbers, chosenSteps>;\n\n return reset;\n }\n\n throw new TypeError(`[update]: ${HelperFnChosenSteps.CATCH_ALL_MESSAGE}`);\n }\n\n createStepHelperFn<\n chosenSteps extends HelperFnChosenSteps<resolvedStep, stepNumbers>\n >(stepData: chosenSteps) {\n return <validator, additionalCtx extends Record<string, unknown>, response>(\n optionsOrFunction:\n | Omit<\n CreateHelperFunctionOptionsWithValidator<\n resolvedStep,\n stepNumbers,\n chosenSteps,\n validator,\n additionalCtx\n >,\n 'stepData'\n >\n | Omit<\n CreateHelperFunctionOptionsWithoutValidator<\n resolvedStep,\n stepNumbers,\n chosenSteps\n >,\n 'stepData'\n >\n | HelperFnWithoutValidator<\n resolvedStep,\n stepNumbers,\n chosenSteps,\n additionalCtx,\n response\n >,\n fn:\n | HelperFnWithValidator<\n resolvedStep,\n stepNumbers,\n chosenSteps,\n validator,\n additionalCtx,\n response\n >\n | HelperFnWithoutValidator<\n resolvedStep,\n stepNumbers,\n chosenSteps,\n additionalCtx,\n response\n >\n ) => {\n const functions = {\n update: this.createHelperFnInputUpdate(stepData),\n reset: this.createHelperFnInputReset(stepData),\n };\n\n if (typeof optionsOrFunction === 'function') {\n return () => {\n // Create ctx fresh each time the function is called to ensure it has the latest this.value\n const ctx = createCtx<resolvedStep, stepNumbers, chosenSteps>(\n this.value,\n stepData\n ) as never;\n return optionsOrFunction({\n ctx,\n ...functions,\n });\n };\n }\n\n if (typeof optionsOrFunction === 'object') {\n return (input?: CreatedHelperFnInput<validator>) => {\n // Create ctx fresh each time the function is called to ensure it has the latest this.value\n const ctx = createCtx<resolvedStep, stepNumbers, chosenSteps>(\n this.value,\n stepData\n ) as never;\n\n if ('validator' in optionsOrFunction) {\n invariant(\n typeof input === 'object',\n 'An input is expected since you provided a validator'\n );\n\n runStandardValidation(\n optionsOrFunction.validator as StandardSchemaValidator,\n input.data\n );\n\n let resolvedCtx = ctx as HelperFnCtx<\n resolvedStep,\n stepNumbers,\n chosenSteps\n >;\n\n if (optionsOrFunction.ctxData) {\n const currentStepKey = (\n stepData as HelperFnChosenSteps.tupleNotation<\n ValidStepKey<stepNumbers>\n >\n )[0] as keyof resolvedStep;\n const { [currentStepKey]: _, ...values } = this.value;\n\n resolvedCtx = {\n ...resolvedCtx,\n ...optionsOrFunction.ctxData({ ctx: values as never }),\n };\n }\n\n return fn({\n ctx: resolvedCtx as never,\n ...functions,\n ...input,\n });\n }\n\n return (\n fn as HelperFnWithoutValidator<\n resolvedStep,\n stepNumbers,\n chosenSteps,\n additionalCtx,\n response\n >\n )({\n ctx,\n ...functions,\n });\n };\n }\n\n throw new Error(\n `The first argument must be a function or an object, (was ${typeof optionsOrFunction})`\n );\n };\n }\n\n private extractStepFromKey(key: string) {\n const [targetStep] = [key] as HelperFnChosenSteps.tupleNotation<\n ValidStepKey<stepNumbers>\n >;\n const step = Number.parseInt(targetStep.replace('step', '')) as stepNumbers;\n\n return { targetStep, step };\n }\n\n enrichValues<\n values extends AnyResolvedStep,\n additionalProps extends Record<string, unknown>\n >(values: values, additionalProps?: (step: number) => additionalProps) {\n let enriched = { ...values };\n\n for (const [key, stepValue] of Object.entries(enriched)) {\n const { step, targetStep } = this.extractStepFromKey(key);\n\n enriched[targetStep] = {\n ...stepValue,\n update: this.createStepUpdaterFn(targetStep),\n reset: this.createStepResetterFn(targetStep),\n createHelperFn: this.createStepHelperFn([targetStep]),\n ...additionalProps?.(step),\n };\n }\n\n return enriched;\n }\n}\n"],"mappings":";;;;;;;;;;;AA8DA,SAAS,aAA+C,SAOrD;CACD,MAAM,EAAE,QAAQ,SAAS,QAAQ,KAAK,OAAO,kBAAkB;CAG/D,MAAM,EAAE,YAAY,OAAOA,kBAAK,cAAc,KAAK,OAAO,OAAO;CAEjE,IAAI,UAAU;AAEd,KAAI,OACF,WAAU,MAAM,WAAW,WAAW;AAGxC,KAAI,SAAS;EACX,MAAM,8BAA8B,WAAW,QAC5C,EAAE,aAAa,WAAW,cAC5B;AAED,MAAI,OACF,WAAU,4BAA4B,WAAW;MAMjD,WAJwB,4BAA4B,QACjD,EAAE,aAAa,WAAW,YAC5B,CAEyB,WAAW;;AAIzC,KAAI,CAAC,cACH,6BACE,SACA,uCAAuCA,kBAAK,gBAAgB;EAC1D;EACA;EACD,CAAC,GACH;;AAIL,IAAa,kCAAb,MAME;CACA,CAASC;CACT,CAASC;CACT,CAASC;CACT,CAASC;CAET,IAAY,QAAQ;AAClB,SAAO,MAAKD,UAAW;;CAGzB,YACE,SAMA;EACA,MAAM,EAAE,UAAU,UAAU,eAAe,4BACzC;AAEF,QAAKF,gBAAiB;AACtB,QAAKE,WAAY;AACjB,QAAKC,WAAY;AACjB,QAAKF,0BAA2B;;CAGlC,AAAQ,iBAAiB,OAAqB;AAC5C,QAAKE,SAAU,KAAK,aAAa,MAAM,CAAC;;CAG1C,AAAQ,aAIN,SAMA;EACA,MAAM,EAAE,QAAQ,QAAQ,YAAY;AACpC,8BACE,OAAO,YAAY,YACnB,2CACD;AACD,SAAO,KAAK,8BAA4B;EAExC,MAAM,gBAAgB,QAAQ,EAAE,KAAK,QAAiB,CAAC;AAEvD,8BACE,OAAO,kBAAkB,YACvB,OAAO,KAAK,cAAc,CAAC,SAAS,GACtC,wDACD;AAED,SAAO,KACL,gD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