@jfdevelops/multi-step-form-core 1.0.0-alpha.13 → 1.0.0-alpha.14
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/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/internals/step-schema.cjs +34 -5
- package/dist/internals/step-schema.cjs.map +1 -1
- package/dist/internals/step-schema.d.cts +2 -1
- package/dist/internals/step-schema.d.cts.map +1 -1
- package/dist/internals/step-schema.d.mts +2 -1
- package/dist/internals/step-schema.d.mts.map +1 -1
- package/dist/internals/step-schema.mjs +34 -5
- package/dist/internals/step-schema.mjs.map +1 -1
- package/dist/steps/types.cjs.map +1 -1
- package/dist/steps/types.d.cts +10 -1
- package/dist/steps/types.d.cts.map +1 -1
- package/dist/steps/types.d.mts +10 -1
- package/dist/steps/types.d.mts.map +1 -1
- package/dist/steps/types.mjs.map +1 -1
- package/dist/utils/casing.d.cts +1 -1
- package/dist/utils/casing.d.cts.map +1 -1
- package/dist/utils/casing.d.mts +1 -1
- package/dist/utils/casing.d.mts.map +1 -1
- package/dist/utils/validator.d.mts.map +1 -1
- package/package.json +3 -2
package/dist/index.d.cts
CHANGED
|
@@ -4,11 +4,11 @@ import { CASING_TYPES, CapitalizeWord, CasingType, ChangeCasing, ChangeObjectCas
|
|
|
4
4
|
import { DEFAULT_FIELD_TYPE, DefaultFieldType, FIELD_TYPES, FieldType, isFieldType } from "./utils/field-types.cjs";
|
|
5
5
|
import { DEFAULT_LOGGER_PREFIX, MultiStepFormLogger } from "./utils/logger.cjs";
|
|
6
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, HelperFnChosenSteps, HelperFnCtx, HelperFnInputBase, HelperFnInputWithValidator, HelperFnInputWithoutValidator, 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, helperFnUpdateFn } from "./steps/types.cjs";
|
|
7
|
+
import { AnyResolvedStep, AnyStep, AnyStepField, AnyStepFieldOption, ClampTo0to10, CreateHelperFunctionOptionsBase, CreateHelperFunctionOptionsWithCustomCtxOptions, CreateHelperFunctionOptionsWithValidator, CreateHelperFunctionOptionsWithoutValidator, CreateStepHelperFn, CreatedHelperFnInput, CreatedHelperFnWithInput, CreatedHelperFnWithoutInput, CtxDataSelector, ExtractStepFromKey, FirstStep, GeneralHelperFn, GetCurrentStep, GetDefaultCasingTransformation, GetFieldsForStep, GreaterThan, 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
8
|
import { VALIDATED_STEP_REGEX, createStep, isValidStepKey } from "./internals/utils.cjs";
|
|
9
9
|
import { fields } from "./steps/fields.cjs";
|
|
10
10
|
import { createCtx } from "./steps/utils.cjs";
|
|
11
11
|
import { AsFunction, AsFunctionReturn, AsType, AsTypeMap, MultiStepFormStepSchema, MultiStepFormStepSchemaFunctions, MultiStepFormStepSchemaListener, MultiStepFormStepStepsConfig } from "./steps/schema.cjs";
|
|
12
12
|
import { MultiStepFormSchema, MultiStepFormSchemaListener, MultiStepFormSchemaOptions, createMultiStepFormSchema } from "./schema.cjs";
|
|
13
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, DeepValue, DefaultCasing, DefaultFieldType, DefaultStorageKey, Expand, ExtractStepFromKey, FIELD_TYPES, FieldType, FirstStep, GeneralHelperFn, GetCurrentStep, GetDefaultCasingTransformation, GetFieldsForStep, GreaterThan, HelperFnChosenSteps, HelperFnCtx, HelperFnInputBase, HelperFnInputWithValidator, HelperFnInputWithoutValidator, 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, helperFnUpdateFn, invariant, isCasingValid, isFieldType, isValidStepKey, objectHelpers, quote, setCasingType, unionHelpers };
|
|
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, DeepValue, DefaultCasing, DefaultFieldType, DefaultStorageKey, Expand, ExtractStepFromKey, FIELD_TYPES, FieldType, FirstStep, GeneralHelperFn, GetCurrentStep, GetDefaultCasingTransformation, GetFieldsForStep, GreaterThan, 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
CHANGED
|
@@ -4,11 +4,11 @@ import { CASING_TYPES, CapitalizeWord, CasingType, ChangeCasing, ChangeObjectCas
|
|
|
4
4
|
import { DEFAULT_FIELD_TYPE, DefaultFieldType, FIELD_TYPES, FieldType, isFieldType } from "./utils/field-types.mjs";
|
|
5
5
|
import { DEFAULT_LOGGER_PREFIX, MultiStepFormLogger } from "./utils/logger.mjs";
|
|
6
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, HelperFnChosenSteps, HelperFnCtx, HelperFnInputBase, HelperFnInputWithValidator, HelperFnInputWithoutValidator, 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, helperFnUpdateFn } from "./steps/types.mjs";
|
|
7
|
+
import { AnyResolvedStep, AnyStep, AnyStepField, AnyStepFieldOption, ClampTo0to10, CreateHelperFunctionOptionsBase, CreateHelperFunctionOptionsWithCustomCtxOptions, CreateHelperFunctionOptionsWithValidator, CreateHelperFunctionOptionsWithoutValidator, CreateStepHelperFn, CreatedHelperFnInput, CreatedHelperFnWithInput, CreatedHelperFnWithoutInput, CtxDataSelector, ExtractStepFromKey, FirstStep, GeneralHelperFn, GetCurrentStep, GetDefaultCasingTransformation, GetFieldsForStep, GreaterThan, 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
8
|
import { VALIDATED_STEP_REGEX, createStep, isValidStepKey } from "./internals/utils.mjs";
|
|
9
9
|
import { fields } from "./steps/fields.mjs";
|
|
10
10
|
import { createCtx } from "./steps/utils.mjs";
|
|
11
11
|
import { AsFunction, AsFunctionReturn, AsType, AsTypeMap, MultiStepFormStepSchema, MultiStepFormStepSchemaFunctions, MultiStepFormStepSchemaListener, MultiStepFormStepStepsConfig } from "./steps/schema.mjs";
|
|
12
12
|
import { MultiStepFormSchema, MultiStepFormSchemaListener, MultiStepFormSchemaOptions, createMultiStepFormSchema } from "./schema.mjs";
|
|
13
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, DeepValue, DefaultCasing, DefaultFieldType, DefaultStorageKey, Expand, ExtractStepFromKey, FIELD_TYPES, FieldType, FirstStep, GeneralHelperFn, GetCurrentStep, GetDefaultCasingTransformation, GetFieldsForStep, GreaterThan, HelperFnChosenSteps, HelperFnCtx, HelperFnInputBase, HelperFnInputWithValidator, HelperFnInputWithoutValidator, 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, helperFnUpdateFn, invariant, isCasingValid, isFieldType, isValidStepKey, objectHelpers, quote, setCasingType, unionHelpers };
|
|
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, DeepValue, DefaultCasing, DefaultFieldType, DefaultStorageKey, Expand, ExtractStepFromKey, FIELD_TYPES, FieldType, FirstStep, GeneralHelperFn, GetCurrentStep, GetDefaultCasingTransformation, GetFieldsForStep, GreaterThan, 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 };
|
|
@@ -56,7 +56,8 @@ var MultiStepFormStepSchemaInternal = class {
|
|
|
56
56
|
}
|
|
57
57
|
const updated = require_utils.functionalUpdate(updater, {
|
|
58
58
|
ctx,
|
|
59
|
-
update: this.createHelperFnInputUpdate([targetStep])
|
|
59
|
+
update: this.createHelperFnInputUpdate([targetStep]),
|
|
60
|
+
reset: this.createHelperFnInputReset([targetStep])
|
|
60
61
|
});
|
|
61
62
|
logger.info(`The updated data is ${JSON.stringify(updated, null, 2)}`);
|
|
62
63
|
if (fields === "all") {
|
|
@@ -244,13 +245,41 @@ var MultiStepFormStepSchemaInternal = class {
|
|
|
244
245
|
}
|
|
245
246
|
throw new TypeError(`[update]: ${require_types.HelperFnChosenSteps.CATCH_ALL_MESSAGE}`);
|
|
246
247
|
}
|
|
248
|
+
createHelperFnInputReset(chosenSteps) {
|
|
249
|
+
if (require_types.HelperFnChosenSteps.isAll(chosenSteps)) {
|
|
250
|
+
const stepSpecificUpdateFn = require_helpers.typedObjectKeys(this.value).reduce((acc, key) => {
|
|
251
|
+
acc[key] = this.createStepResetterFn(key);
|
|
252
|
+
return acc;
|
|
253
|
+
}, {});
|
|
254
|
+
return Object.assign(this.reset, stepSpecificUpdateFn);
|
|
255
|
+
}
|
|
256
|
+
const validKeys = Object.keys(this.value);
|
|
257
|
+
if (require_types.HelperFnChosenSteps.isTuple(chosenSteps, validKeys)) {
|
|
258
|
+
const stepSpecificUpdateFn = chosenSteps.reduce((acc, step) => {
|
|
259
|
+
acc[step] = this.createStepResetterFn(step);
|
|
260
|
+
return acc;
|
|
261
|
+
}, {});
|
|
262
|
+
return Object.assign(this.reset, stepSpecificUpdateFn);
|
|
263
|
+
}
|
|
264
|
+
if (require_types.HelperFnChosenSteps.isObject(chosenSteps, validKeys)) {
|
|
265
|
+
const stepSpecificUpdateFn = require_helpers.typedObjectKeys(chosenSteps).reduce((acc, key) => {
|
|
266
|
+
acc[key] = this.createStepResetterFn(key);
|
|
267
|
+
return acc;
|
|
268
|
+
}, {});
|
|
269
|
+
return Object.assign(this.reset, stepSpecificUpdateFn);
|
|
270
|
+
}
|
|
271
|
+
throw new TypeError(`[update]: ${require_types.HelperFnChosenSteps.CATCH_ALL_MESSAGE}`);
|
|
272
|
+
}
|
|
247
273
|
createStepHelperFn(stepData) {
|
|
248
274
|
return (optionsOrFunction, fn) => {
|
|
249
|
-
const
|
|
275
|
+
const functions = {
|
|
276
|
+
update: this.createHelperFnInputUpdate(stepData),
|
|
277
|
+
reset: this.createHelperFnInputReset(stepData)
|
|
278
|
+
};
|
|
250
279
|
if (typeof optionsOrFunction === "function") return () => {
|
|
251
280
|
return optionsOrFunction({
|
|
252
281
|
ctx: require_utils.createCtx(this.value, stepData),
|
|
253
|
-
|
|
282
|
+
...functions
|
|
254
283
|
});
|
|
255
284
|
};
|
|
256
285
|
if (typeof optionsOrFunction === "object") return (input) => {
|
|
@@ -269,13 +298,13 @@ var MultiStepFormStepSchemaInternal = class {
|
|
|
269
298
|
}
|
|
270
299
|
return fn({
|
|
271
300
|
ctx: resolvedCtx,
|
|
272
|
-
|
|
301
|
+
...functions,
|
|
273
302
|
...input
|
|
274
303
|
});
|
|
275
304
|
}
|
|
276
305
|
return fn({
|
|
277
306
|
ctx,
|
|
278
|
-
|
|
307
|
+
...functions
|
|
279
308
|
});
|
|
280
309
|
};
|
|
281
310
|
throw new Error(`The first argument must be a function or an object, (was ${typeof optionsOrFunction})`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"step-schema.cjs","names":["#originalValue","#additionalEnrichedProps","#getValue","#setValue","MultiStepFormLogger","isValidStepKey","createCtx","functionalUpdate","currentStep","path","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 HelperFnCtx,\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\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 createStepUpdaterFnImpl<\n targetStep extends ValidStepKey<stepNumbers>,\n fields extends UpdateFn.chosenFields<currentStep>,\n additionalCtx extends Record<string, unknown>,\n currentStep extends UpdateFn.resolvedStep<\n resolvedStep,\n stepNumbers,\n targetStep\n >\n >(\n options: UpdateFn.options<\n resolvedStep,\n stepNumbers,\n targetStep,\n fields,\n additionalCtx,\n currentStep\n >\n ) {\n const { targetStep, ctxData, fields = 'all', debug } = options;\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 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 ctx = {\n ...ctx,\n ...additionalCtx,\n };\n }\n\n const updated = functionalUpdate(updater, {\n ctx: ctx as never,\n update: this.createHelperFnInputUpdate([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 const { mismatches, ok } = path.equalsAtPaths(\n obj,\n paths,\n actual as never\n );\n\n invariant(ok && mismatches.length === 0, () => {\n const formatted = path.formatMismatches({ mismatches, ok });\n\n return `[update]: found value mismatches in ${formatted}`;\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 currentUpdatedValue,\n paths,\n actual as never\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 const { mismatches, ok } = path.equalsAtPaths(\n currentStep,\n fields,\n updated as never\n );\n\n invariant(\n ok && mismatches.length === 0,\n `[update]: found value mismatches in ${path.printMismatches({\n ok,\n mismatches,\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(fields)}`\n );\n\n updatedValue = {\n ...updatedValue,\n [targetStep]: path.updateAt(currentStep, fields, updated as never),\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 const { mismatches, ok } = path.equalsAtPaths(\n currentStep,\n keys as never,\n updated as never\n );\n\n invariant(\n ok && mismatches.length === 0,\n `[update]: found value mismatches in ${path.printMismatches({\n ok,\n mismatches,\n })}`\n );\n\n updatedValue = {\n ...updatedValue,\n [targetStep]: path.updateAt(\n currentStep,\n keys as never,\n updated as never\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 additionalCtx extends Record<string, unknown> = {}\n >(\n options: UpdateFn.options<\n resolvedStep,\n stepNumbers,\n targetStep,\n field,\n additionalCtx\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(values, fields, picked),\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<\n resolvedStep,\n ValidStepKey<stepNumbers>\n >(this.value).reduce((acc, key) => {\n acc[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 const validKeys = Object.keys(this.value);\n\n if (HelperFnChosenSteps.isTuple<stepNumbers>(chosenSteps, validKeys)) {\n const stepSpecificUpdateFn = chosenSteps.reduce((acc, step) => {\n acc[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[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 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 createInputUpdateFn = this.createHelperFnInputUpdate(\n stepData\n ) as HelperFnUpdateFn<resolvedStep, stepNumbers, chosenSteps>;\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 update: createInputUpdateFn,\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 update: createInputUpdateFn,\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 update: createInputUpdateFn,\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":";;;;;;;;;;;AA2DA,IAAa,kCAAb,MAME;CACA,CAASA;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,wBAUN,SAQA;EACA,MAAM,EAAE,YAAY,SAAS,SAAS,OAAO,UAAU;EACvD,MAAM,SAAS,IAAIC,mCAAoB;GACrC;GACA,SAAS,UAAU,GAAG,MAAM,SAAS;GACtC,CAAC;AAEF,SAAO,KAAK,GAAG,WAAW,kBAAkB;AAC5C,8BACEC,+BAAe,KAAK,OAAO,WAAW,EACtC,6BAA6B,WAAW,iDACzC;E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;KACA;KACA,QAAQ;KACT,CAAC;;AAIN,SAAM,IAAI,MACR,4DAA4D,OAAO,kBAAkB,GACtF;;;CAIL,AAAQ,mBAAmB,KAAa;EACtC,MAAM,CAAC,cAAc,CAAC,IAAI;AAK1B,SAAO;GAAE;GAAY,MAFR,OAAO,SAAS,WAAW,QAAQ,QAAQ,GAAG,CAAC;GAEjC;;CAG7B,aAGE,QAAgB,iBAAqD;EACrE,IAAI,WAAW,EAAE,GAAG,QAAQ;AAE5B,OAAK,MAAM,CAAC,KAAK,cAAc,OAAO,QAAQ,SAAS,EAAE;GACvD,MAAM,EAAE,MAAM,eAAe,KAAK,mBAAmB,IAAI;AAEzD,YAAS,cAAc;IACrB,GAAG;IACH,QAAQ,KAAK,oBAAoB,WAAW;IAC5C,OAAO,KAAK,qBAAqB,WAAW;IAC5C,gBAAgB,KAAK,mBAAmB,CAAC,WAAW,CAAC;IACrD,GAAG,kBAAkB,KAAK;IAC3B;;AAGH,SAAO"}
|
|
1
|
+
{"version":3,"file":"step-schema.cjs","names":["#originalValue","#additionalEnrichedProps","#getValue","#setValue","MultiStepFormLogger","isValidStepKey","createCtx","functionalUpdate","currentStep","path","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 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\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 createStepUpdaterFnImpl<\n targetStep extends ValidStepKey<stepNumbers>,\n fields extends UpdateFn.chosenFields<currentStep>,\n additionalCtx extends Record<string, unknown>,\n currentStep extends UpdateFn.resolvedStep<\n resolvedStep,\n stepNumbers,\n targetStep\n >\n >(\n options: UpdateFn.options<\n resolvedStep,\n stepNumbers,\n targetStep,\n fields,\n additionalCtx,\n currentStep\n >\n ) {\n const { targetStep, ctxData, fields = 'all', debug } = options;\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 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 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 const { mismatches, ok } = path.equalsAtPaths(\n obj,\n paths,\n actual as never\n );\n\n invariant(ok && mismatches.length === 0, () => {\n const formatted = path.formatMismatches({ mismatches, ok });\n\n return `[update]: found value mismatches in ${formatted}`;\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 currentUpdatedValue,\n paths,\n actual as never\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 const { mismatches, ok } = path.equalsAtPaths(\n currentStep,\n fields,\n updated as never\n );\n\n invariant(\n ok && mismatches.length === 0,\n `[update]: found value mismatches in ${path.printMismatches({\n ok,\n mismatches,\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(fields)}`\n );\n\n updatedValue = {\n ...updatedValue,\n [targetStep]: path.updateAt(currentStep, fields, updated as never),\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 const { mismatches, ok } = path.equalsAtPaths(\n currentStep,\n keys as never,\n updated as never\n );\n\n invariant(\n ok && mismatches.length === 0,\n `[update]: found value mismatches in ${path.printMismatches({\n ok,\n mismatches,\n })}`\n );\n\n updatedValue = {\n ...updatedValue,\n [targetStep]: path.updateAt(\n currentStep,\n keys as never,\n updated as never\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 additionalCtx extends Record<string, unknown> = {}\n >(\n options: UpdateFn.options<\n resolvedStep,\n stepNumbers,\n targetStep,\n field,\n additionalCtx\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(values, fields, picked),\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<\n resolvedStep,\n ValidStepKey<stepNumbers>\n >(this.value).reduce((acc, key) => {\n acc[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 const validKeys = Object.keys(this.value);\n\n if (HelperFnChosenSteps.isTuple<stepNumbers>(chosenSteps, validKeys)) {\n const stepSpecificUpdateFn = chosenSteps.reduce((acc, step) => {\n acc[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[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[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[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[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":";;;;;;;;;;;AA6DA,IAAa,kCAAb,MAME;CACA,CAASA;CACT,CAASC;CACT,CAASC;CACT,CAASC;CA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AAc;OACZ,GAAG;OACH,GAAG,kBAAkB,QAAQ,EAAE,KAAK,QAAiB,CAAC;OACvD;;AAGH,YAAO,GAAG;MACR,KAAK;MACL,GAAG;MACH,GAAG;MACJ,CAAC;;AAGJ,WACE,GAOA;KACA;KACA,GAAG;KACJ,CAAC;;AAIN,SAAM,IAAI,MACR,4DAA4D,OAAO,kBAAkB,GACtF;;;CAIL,AAAQ,mBAAmB,KAAa;EACtC,MAAM,CAAC,cAAc,CAAC,IAAI;AAK1B,SAAO;GAAE;GAAY,MAFR,OAAO,SAAS,WAAW,QAAQ,QAAQ,GAAG,CAAC;GAEjC;;CAG7B,aAGE,QAAgB,iBAAqD;EACrE,IAAI,WAAW,EAAE,GAAG,QAAQ;AAE5B,OAAK,MAAM,CAAC,KAAK,cAAc,OAAO,QAAQ,SAAS,EAAE;GACvD,MAAM,EAAE,MAAM,eAAe,KAAK,mBAAmB,IAAI;AAEzD,YAAS,cAAc;IACrB,GAAG;IACH,QAAQ,KAAK,oBAAoB,WAAW;IAC5C,OAAO,KAAK,qBAAqB,WAAW;IAC5C,gBAAgB,KAAK,mBAAmB,CAAC,WAAW,CAAC;IACrD,GAAG,kBAAkB,KAAK;IAC3B;;AAGH,SAAO"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CasingType } from "../utils/casing.cjs";
|
|
2
|
-
import { AnyResolvedStep, CreateHelperFunctionOptionsWithValidator, CreateHelperFunctionOptionsWithoutValidator, CreatedHelperFnInput, HelperFnChosenSteps, HelperFnUpdateFn, HelperFnWithValidator, HelperFnWithoutValidator, InferStepOptions, ResetFn, Step, StepNumbers, UpdateFn, ValidStepKey } from "../steps/types.cjs";
|
|
2
|
+
import { AnyResolvedStep, CreateHelperFunctionOptionsWithValidator, CreateHelperFunctionOptionsWithoutValidator, CreatedHelperFnInput, HelperFnChosenSteps, HelperFnResetFn, HelperFnUpdateFn, HelperFnWithValidator, HelperFnWithoutValidator, InferStepOptions, ResetFn, Step, StepNumbers, UpdateFn, ValidStepKey } from "../steps/types.cjs";
|
|
3
3
|
|
|
4
4
|
//#region src/internals/step-schema.d.ts
|
|
5
5
|
type InternalOptions<TStep extends Step<TCasing>, TCasing extends CasingType, TResolvedStep extends AnyResolvedStep, additionalEnrichedProps extends Record<string, unknown>> = {
|
|
@@ -30,6 +30,7 @@ declare class MultiStepFormStepSchemaInternal<step extends Step<casing>, casing
|
|
|
30
30
|
createStepResetterFn<targetStep extends ValidStepKey<stepNumbers>>(targetStep: targetStep): ResetFn.stepSpecific<resolvedStep, stepNumbers, targetStep>;
|
|
31
31
|
reset<targetStep extends ValidStepKey<stepNumbers>, fields extends UpdateFn.chosenFields<currentStep>, currentStep extends UpdateFn.resolvedStep<resolvedStep, stepNumbers, targetStep>>(options: ResetFn.Options<resolvedStep, stepNumbers, targetStep, fields, currentStep>): void;
|
|
32
32
|
createHelperFnInputUpdate<chosenSteps extends HelperFnChosenSteps<resolvedStep, stepNumbers>>(chosenSteps: chosenSteps): HelperFnUpdateFn<resolvedStep, stepNumbers, chosenSteps>;
|
|
33
|
+
createHelperFnInputReset<chosenSteps extends HelperFnChosenSteps<resolvedStep, stepNumbers>>(chosenSteps: chosenSteps): HelperFnResetFn<resolvedStep, stepNumbers, chosenSteps>;
|
|
33
34
|
createStepHelperFn<chosenSteps extends HelperFnChosenSteps<resolvedStep, stepNumbers>>(stepData: chosenSteps): <validator, additionalCtx extends Record<string, unknown>, response>(optionsOrFunction: Omit<CreateHelperFunctionOptionsWithValidator<resolvedStep, stepNumbers, chosenSteps, validator, additionalCtx>, "stepData"> | Omit<CreateHelperFunctionOptionsWithoutValidator<resolvedStep, stepNumbers, chosenSteps>, "stepData"> | HelperFnWithoutValidator<resolvedStep, stepNumbers, chosenSteps, additionalCtx, response>, fn: HelperFnWithValidator<resolvedStep, stepNumbers, chosenSteps, validator, additionalCtx, response> | HelperFnWithoutValidator<resolvedStep, stepNumbers, chosenSteps, additionalCtx, response>) => (() => any) | ((input?: CreatedHelperFnInput<validator>) => response);
|
|
34
35
|
private extractStepFromKey;
|
|
35
36
|
enrichValues<values extends AnyResolvedStep, additionalProps extends Record<string, unknown>>(values: values, additionalProps?: (step: number) => additionalProps): values;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"step-schema.d.cts","names":[],"sources":["../../src/internals/step-schema.ts"],"sourcesContent":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"step-schema.d.cts","names":[],"sources":["../../src/internals/step-schema.ts"],"sourcesContent":[],"mappings":";;;;KAwCY,8BACI,KAAK,0BACH,kCACM,iDACU;iBAEjB,iBAAiB;EANtB,uBAAe,CAAA,EAAA,CAAA,IAAA,EAAA,MAAA,EAAA,GAOmB,uBAPnB;EACN;;;EAEG,QAAA,EAAA,GAAA,GAQN,aARM;EACU;;;;;;EAcD,QAAA,EAAA,CAAA,KAAA,EAAb,aAAa,EAAA,GAAA,IAAA;AAGjC,CAAA;AACoB,cADP,+BACO,CAAA,aAAL,IAAK,CAAA,MAAA,CAAA,EAAA,eACH,UADG,EAAA,qBAEG,eAFH,EAAA,oBAGE,WAHF,CAGc,YAHd,CAAA,EAAA,gCAIc,MAJd,CAAA,MAAA,EAAA,OAAA,CAAA,GAAA,CAAA,CAAA,CAAA,CAAA;EAAL,CAAA,OAAA;EACE,YAAA,KAAA,CAAA;EACM,WAAA,CAAA,OAAA,EAcV,eAdU,CAejB,IAfiB,EAgBjB,MAhBiB,EAiBjB,YAjBiB,EAkBjB,uBAlBiB,CAAA;EACW,QAAA,gBAAA;EAAZ,QAAA,uBAAA;EACY,mBAAA,CAAA,mBAwSO,YAxSP,CAwSoB,WAxSpB,CAAA,CAAA,CAAA,UAAA,EAySlB,UAzSkB,CAAA,EA0S7B,QAAA,CAAS,YA1SoB,CA0SP,YA1SO,EA0SO,WA1SP,EA0SoB,UA1SpB,CAAA;EAa5B,MAAA,CAAA,mBAoSiB,YApSjB,CAoS8B,WApS9B,CAAA,EAAA,cAqSY,QAAA,CAAS,YArSrB,CA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{ AnyResolvedStep, CreateHelperFunctionOptionsWithValidator, CreateHelperFunctionOptionsWithoutValidator, CreatedHelperFnInput, HelperFnChosenSteps, HelperFnUpdateFn, HelperFnWithValidator, HelperFnWithoutValidator, InferStepOptions, ResetFn, Step, StepNumbers, UpdateFn, ValidStepKey } from "../steps/types.mjs";
|
|
2
|
+
import { AnyResolvedStep, CreateHelperFunctionOptionsWithValidator, CreateHelperFunctionOptionsWithoutValidator, CreatedHelperFnInput, HelperFnChosenSteps, HelperFnResetFn, HelperFnUpdateFn, HelperFnWithValidator, HelperFnWithoutValidator, InferStepOptions, ResetFn, Step, StepNumbers, UpdateFn, ValidStepKey } from "../steps/types.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/internals/step-schema.d.ts
|
|
5
5
|
type InternalOptions<TStep extends Step<TCasing>, TCasing extends CasingType, TResolvedStep extends AnyResolvedStep, additionalEnrichedProps extends Record<string, unknown>> = {
|
|
@@ -30,6 +30,7 @@ declare class MultiStepFormStepSchemaInternal<step extends Step<casing>, casing
|
|
|
30
30
|
createStepResetterFn<targetStep extends ValidStepKey<stepNumbers>>(targetStep: targetStep): ResetFn.stepSpecific<resolvedStep, stepNumbers, targetStep>;
|
|
31
31
|
reset<targetStep extends ValidStepKey<stepNumbers>, fields extends UpdateFn.chosenFields<currentStep>, currentStep extends UpdateFn.resolvedStep<resolvedStep, stepNumbers, targetStep>>(options: ResetFn.Options<resolvedStep, stepNumbers, targetStep, fields, currentStep>): void;
|
|
32
32
|
createHelperFnInputUpdate<chosenSteps extends HelperFnChosenSteps<resolvedStep, stepNumbers>>(chosenSteps: chosenSteps): HelperFnUpdateFn<resolvedStep, stepNumbers, chosenSteps>;
|
|
33
|
+
createHelperFnInputReset<chosenSteps extends HelperFnChosenSteps<resolvedStep, stepNumbers>>(chosenSteps: chosenSteps): HelperFnResetFn<resolvedStep, stepNumbers, chosenSteps>;
|
|
33
34
|
createStepHelperFn<chosenSteps extends HelperFnChosenSteps<resolvedStep, stepNumbers>>(stepData: chosenSteps): <validator, additionalCtx extends Record<string, unknown>, response>(optionsOrFunction: Omit<CreateHelperFunctionOptionsWithValidator<resolvedStep, stepNumbers, chosenSteps, validator, additionalCtx>, "stepData"> | Omit<CreateHelperFunctionOptionsWithoutValidator<resolvedStep, stepNumbers, chosenSteps>, "stepData"> | HelperFnWithoutValidator<resolvedStep, stepNumbers, chosenSteps, additionalCtx, response>, fn: HelperFnWithValidator<resolvedStep, stepNumbers, chosenSteps, validator, additionalCtx, response> | HelperFnWithoutValidator<resolvedStep, stepNumbers, chosenSteps, additionalCtx, response>) => (() => any) | ((input?: CreatedHelperFnInput<validator>) => response);
|
|
34
35
|
private extractStepFromKey;
|
|
35
36
|
enrichValues<values extends AnyResolvedStep, additionalProps extends Record<string, unknown>>(values: values, additionalProps?: (step: number) => additionalProps): values;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"step-schema.d.mts","names":[],"sources":["../../src/internals/step-schema.ts"],"sourcesContent":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"step-schema.d.mts","names":[],"sources":["../../src/internals/step-schema.ts"],"sourcesContent":[],"mappings":";;;;KAwCY,8BACI,KAAK,0BACH,kCACM,iDACU;iBAEjB,iBAAiB;EANtB,uBAAe,CAAA,EAAA,CAAA,IAAA,EAAA,MAAA,EAAA,GAOmB,uBAPnB;EACN;;;EAEG,QAAA,EAAA,GAAA,GAQN,aARM;EACU;;;;;;EAcD,QAAA,EAAA,CAAA,KAAA,EAAb,aAAa,EAAA,GAAA,IAAA;AAGjC,CAAA;AACoB,cADP,+BACO,CAAA,aAAL,IAAK,CAAA,MAAA,CAAA,EAAA,eACH,UADG,EAAA,qBAEG,eAFH,EAAA,oBAGE,WAHF,CAGc,YAHd,CAAA,EAAA,gCAIc,MAJd,CAAA,MAAA,EAAA,OAAA,CAAA,GAAA,CAAA,CAAA,CAAA,CAAA;EAAL,CAAA,OAAA;EACE,YAAA,KAAA,CAAA;EACM,WAAA,CAAA,OAAA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A,EAgVQ,oBAhVR,CAgV6B,SAhV7B,CAAA,EAAA,GAgVuC,QAhVvC,CAAA;EACW,QAAA,kBAAA;EAAc,YAAA,CAAA,eA2ZtB,eA3ZsB,EAAA,wBA4Zb,MA5Za,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA,CAAA,MAAA,EA6Z7B,MA7Z6B,EAAA,eAAA,CAAA,EAAA,CAAA,IAAA,EAAA,MAAA,EAAA,GA6Ze,eA7Zf,CAAA,EA6Z8B,MA7Z9B"}
|
|
@@ -56,7 +56,8 @@ var MultiStepFormStepSchemaInternal = class {
|
|
|
56
56
|
}
|
|
57
57
|
const updated = functionalUpdate(updater, {
|
|
58
58
|
ctx,
|
|
59
|
-
update: this.createHelperFnInputUpdate([targetStep])
|
|
59
|
+
update: this.createHelperFnInputUpdate([targetStep]),
|
|
60
|
+
reset: this.createHelperFnInputReset([targetStep])
|
|
60
61
|
});
|
|
61
62
|
logger.info(`The updated data is ${JSON.stringify(updated, null, 2)}`);
|
|
62
63
|
if (fields === "all") {
|
|
@@ -244,13 +245,41 @@ var MultiStepFormStepSchemaInternal = class {
|
|
|
244
245
|
}
|
|
245
246
|
throw new TypeError(`[update]: ${HelperFnChosenSteps.CATCH_ALL_MESSAGE}`);
|
|
246
247
|
}
|
|
248
|
+
createHelperFnInputReset(chosenSteps) {
|
|
249
|
+
if (HelperFnChosenSteps.isAll(chosenSteps)) {
|
|
250
|
+
const stepSpecificUpdateFn = typedObjectKeys(this.value).reduce((acc, key) => {
|
|
251
|
+
acc[key] = this.createStepResetterFn(key);
|
|
252
|
+
return acc;
|
|
253
|
+
}, {});
|
|
254
|
+
return Object.assign(this.reset, stepSpecificUpdateFn);
|
|
255
|
+
}
|
|
256
|
+
const validKeys = Object.keys(this.value);
|
|
257
|
+
if (HelperFnChosenSteps.isTuple(chosenSteps, validKeys)) {
|
|
258
|
+
const stepSpecificUpdateFn = chosenSteps.reduce((acc, step) => {
|
|
259
|
+
acc[step] = this.createStepResetterFn(step);
|
|
260
|
+
return acc;
|
|
261
|
+
}, {});
|
|
262
|
+
return Object.assign(this.reset, stepSpecificUpdateFn);
|
|
263
|
+
}
|
|
264
|
+
if (HelperFnChosenSteps.isObject(chosenSteps, validKeys)) {
|
|
265
|
+
const stepSpecificUpdateFn = typedObjectKeys(chosenSteps).reduce((acc, key) => {
|
|
266
|
+
acc[key] = this.createStepResetterFn(key);
|
|
267
|
+
return acc;
|
|
268
|
+
}, {});
|
|
269
|
+
return Object.assign(this.reset, stepSpecificUpdateFn);
|
|
270
|
+
}
|
|
271
|
+
throw new TypeError(`[update]: ${HelperFnChosenSteps.CATCH_ALL_MESSAGE}`);
|
|
272
|
+
}
|
|
247
273
|
createStepHelperFn(stepData) {
|
|
248
274
|
return (optionsOrFunction, fn) => {
|
|
249
|
-
const
|
|
275
|
+
const functions = {
|
|
276
|
+
update: this.createHelperFnInputUpdate(stepData),
|
|
277
|
+
reset: this.createHelperFnInputReset(stepData)
|
|
278
|
+
};
|
|
250
279
|
if (typeof optionsOrFunction === "function") return () => {
|
|
251
280
|
return optionsOrFunction({
|
|
252
281
|
ctx: createCtx(this.value, stepData),
|
|
253
|
-
|
|
282
|
+
...functions
|
|
254
283
|
});
|
|
255
284
|
};
|
|
256
285
|
if (typeof optionsOrFunction === "object") return (input) => {
|
|
@@ -269,13 +298,13 @@ var MultiStepFormStepSchemaInternal = class {
|
|
|
269
298
|
}
|
|
270
299
|
return fn({
|
|
271
300
|
ctx: resolvedCtx,
|
|
272
|
-
|
|
301
|
+
...functions,
|
|
273
302
|
...input
|
|
274
303
|
});
|
|
275
304
|
}
|
|
276
305
|
return fn({
|
|
277
306
|
ctx,
|
|
278
|
-
|
|
307
|
+
...functions
|
|
279
308
|
});
|
|
280
309
|
};
|
|
281
310
|
throw new Error(`The first argument must be a function or an object, (was ${typeof optionsOrFunction})`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"step-schema.mjs","names":["#originalValue","#additionalEnrichedProps","#getValue","#setValue","currentStep","actual: Record<string, unknown>"],"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 HelperFnCtx,\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\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 createStepUpdaterFnImpl<\n targetStep extends ValidStepKey<stepNumbers>,\n fields extends UpdateFn.chosenFields<currentStep>,\n additionalCtx extends Record<string, unknown>,\n currentStep extends UpdateFn.resolvedStep<\n resolvedStep,\n stepNumbers,\n targetStep\n >\n >(\n options: UpdateFn.options<\n resolvedStep,\n stepNumbers,\n targetStep,\n fields,\n additionalCtx,\n currentStep\n >\n ) {\n const { targetStep, ctxData, fields = 'all', debug } = options;\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 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 ctx = {\n ...ctx,\n ...additionalCtx,\n };\n }\n\n const updated = functionalUpdate(updater, {\n ctx: ctx as never,\n update: this.createHelperFnInputUpdate([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 const { mismatches, ok } = path.equalsAtPaths(\n obj,\n paths,\n actual as never\n );\n\n invariant(ok && mismatches.length === 0, () => {\n const formatted = path.formatMismatches({ mismatches, ok });\n\n return `[update]: found value mismatches in ${formatted}`;\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 currentUpdatedValue,\n paths,\n actual as never\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 const { mismatches, ok } = path.equalsAtPaths(\n currentStep,\n fields,\n updated as never\n );\n\n invariant(\n ok && mismatches.length === 0,\n `[update]: found value mismatches in ${path.printMismatches({\n ok,\n mismatches,\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(fields)}`\n );\n\n updatedValue = {\n ...updatedValue,\n [targetStep]: path.updateAt(currentStep, fields, updated as never),\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 const { mismatches, ok } = path.equalsAtPaths(\n currentStep,\n keys as never,\n updated as never\n );\n\n invariant(\n ok && mismatches.length === 0,\n `[update]: found value mismatches in ${path.printMismatches({\n ok,\n mismatches,\n })}`\n );\n\n updatedValue = {\n ...updatedValue,\n [targetStep]: path.updateAt(\n currentStep,\n keys as never,\n updated as never\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 additionalCtx extends Record<string, unknown> = {}\n >(\n options: UpdateFn.options<\n resolvedStep,\n stepNumbers,\n targetStep,\n field,\n additionalCtx\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(values, fields, picked),\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<\n resolvedStep,\n ValidStepKey<stepNumbers>\n >(this.value).reduce((acc, key) => {\n acc[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 const validKeys = Object.keys(this.value);\n\n if (HelperFnChosenSteps.isTuple<stepNumbers>(chosenSteps, validKeys)) {\n const stepSpecificUpdateFn = chosenSteps.reduce((acc, step) => {\n acc[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[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 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 createInputUpdateFn = this.createHelperFnInputUpdate(\n stepData\n ) as HelperFnUpdateFn<resolvedStep, stepNumbers, chosenSteps>;\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 update: createInputUpdateFn,\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 update: createInputUpdateFn,\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 update: createInputUpdateFn,\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":";;;;;;;;;;;AA2DA,IAAa,kCAAb,MAME;CACA,CAASA;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,wBAUN,SAQA;EACA,MAAM,EAAE,YAAY,SAAS,SAAS,OAAO,UAAU;EACvD,MAAM,SAAS,IAAI,oBAAoB;GACrC;GACA,SAAS,UAAU,GAAG,MAAM,SAAS;GACtC,CAAC;AAEF,SAAO,KAAK,GAAG,WAAW,kBAAkB;AAC5C,YACE,eAAe,KAAK,OAAO,WAAW,EACtC,6BAA6B,WAAW,iDACzC;EAED,MAAM,GAAG,aAAa,aAAa,GAAG,WAAW,KAAK;AAEtD,YACE,aAAa,SACb,yFACD;EAED,MAAM,UAAU,QAAQ;EACxB,IAAI,eAAe,EAAE,GAAG,KAAK,OAAO;EAEpC,I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GAEjC;;CAG7B,aAGE,QAAgB,iBAAqD;EACrE,IAAI,WAAW,EAAE,GAAG,QAAQ;AAE5B,OAAK,MAAM,CAAC,KAAK,cAAc,OAAO,QAAQ,SAAS,EAAE;GACvD,MAAM,EAAE,MAAM,eAAe,KAAK,mBAAmB,IAAI;AAEzD,YAAS,cAAc;IACrB,GAAG;IACH,QAAQ,KAAK,oBAAoB,WAAW;IAC5C,OAAO,KAAK,qBAAqB,WAAW;IAC5C,gBAAgB,KAAK,mBAAmB,CAAC,WAAW,CAAC;IACrD,GAAG,kBAAkB,KAAK;IAC3B;;AAGH,SAAO"}
|
|
1
|
+
{"version":3,"file":"step-schema.mjs","names":["#originalValue","#additionalEnrichedProps","#getValue","#setValue","currentStep","actual: Record<string, unknown>"],"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 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\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 createStepUpdaterFnImpl<\n targetStep extends ValidStepKey<stepNumbers>,\n fields extends UpdateFn.chosenFields<currentStep>,\n additionalCtx extends Record<string, unknown>,\n currentStep extends UpdateFn.resolvedStep<\n resolvedStep,\n stepNumbers,\n targetStep\n >\n >(\n options: UpdateFn.options<\n resolvedStep,\n stepNumbers,\n targetStep,\n fields,\n additionalCtx,\n currentStep\n >\n ) {\n const { targetStep, ctxData, fields = 'all', debug } = options;\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 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 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 const { mismatches, ok } = path.equalsAtPaths(\n obj,\n paths,\n actual as never\n );\n\n invariant(ok && mismatches.length === 0, () => {\n const formatted = path.formatMismatches({ mismatches, ok });\n\n return `[update]: found value mismatches in ${formatted}`;\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 currentUpdatedValue,\n paths,\n actual as never\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 const { mismatches, ok } = path.equalsAtPaths(\n currentStep,\n fields,\n updated as never\n );\n\n invariant(\n ok && mismatches.length === 0,\n `[update]: found value mismatches in ${path.printMismatches({\n ok,\n mismatches,\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(fields)}`\n );\n\n updatedValue = {\n ...updatedValue,\n [targetStep]: path.updateAt(currentStep, fields, updated as never),\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 const { mismatches, ok } = path.equalsAtPaths(\n currentStep,\n keys as never,\n updated as never\n );\n\n invariant(\n ok && mismatches.length === 0,\n `[update]: found value mismatches in ${path.printMismatches({\n ok,\n mismatches,\n })}`\n );\n\n updatedValue = {\n ...updatedValue,\n [targetStep]: path.updateAt(\n currentStep,\n keys as never,\n updated as never\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 additionalCtx extends Record<string, unknown> = {}\n >(\n options: UpdateFn.options<\n resolvedStep,\n stepNumbers,\n targetStep,\n field,\n additionalCtx\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(values, fields, picked),\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<\n resolvedStep,\n ValidStepKey<stepNumbers>\n >(this.value).reduce((acc, key) => {\n acc[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 const validKeys = Object.keys(this.value);\n\n if (HelperFnChosenSteps.isTuple<stepNumbers>(chosenSteps, validKeys)) {\n const stepSpecificUpdateFn = chosenSteps.reduce((acc, step) => {\n acc[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[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[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[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[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":";;;;;;;;;;;AA6DA,IAAa,kCAAb,MAME;CACA,CAASA;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,wBAUN,SAQA;EACA,MAAM,EAAE,YAAY,SAAS,SA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