@jfdevelops/multi-step-form-core 1.0.0-alpha.14 → 1.0.0-alpha.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/internals/step-schema.cjs +80 -29
- 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 +80 -29
- package/dist/internals/step-schema.mjs.map +1 -1
- package/dist/steps/schema.cjs.map +1 -1
- package/dist/steps/schema.d.cts +1 -1
- package/dist/steps/schema.d.cts.map +1 -1
- package/dist/steps/schema.d.mts +1 -1
- package/dist/steps/schema.d.mts.map +1 -1
- package/dist/steps/schema.mjs.map +1 -1
- package/dist/steps/types.cjs.map +1 -1
- package/dist/steps/types.d.cts +60 -8
- package/dist/steps/types.d.cts.map +1 -1
- package/dist/steps/types.d.mts +60 -8
- 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/path.cjs +61 -2
- package/dist/utils/path.cjs.map +1 -1
- package/dist/utils/path.d.cts +9 -1
- package/dist/utils/path.d.cts.map +1 -1
- package/dist/utils/path.d.mts +9 -1
- package/dist/utils/path.d.mts.map +1 -1
- package/dist/utils/path.mjs +61 -2
- package/dist/utils/path.mjs.map +1 -1
- package/dist/utils/types.d.cts +3 -1
- package/dist/utils/types.d.cts.map +1 -1
- package/dist/utils/types.d.mts +3 -1
- package/dist/utils/types.d.mts.map +1 -1
- package/dist/utils/validator.d.mts.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DEFAULT_STORAGE_KEY, DefaultStorageKey, MultiStepFormStorage, StorageConfig } from "./storage.cjs";
|
|
2
|
-
import { Constrain, DeepKeys, DeepValue, Expand, Join, Override, SetDefaultString, Split, objectHelpers, unionHelpers } from "./utils/types.cjs";
|
|
2
|
+
import { Constrain, DeepKeys, DeepPartial, DeepValue, Expand, Join, Override, SetDefaultString, Split, objectHelpers, unionHelpers } from "./utils/types.cjs";
|
|
3
3
|
import { CASING_TYPES, CapitalizeWord, CasingType, ChangeCasing, ChangeObjectCasing, DEFAULT_CASING, DefaultCasing, ToLower, changeCasing, isCasingValid, quote, setCasingType } from "./utils/casing.cjs";
|
|
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";
|
|
@@ -11,4 +11,4 @@ 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, 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 };
|
|
14
|
+
export { AnyResolvedStep, AnyStep, AnyStepField, AnyStepFieldOption, AsFunction, AsFunctionReturn, AsType, AsTypeMap, CASING_TYPES, CapitalizeWord, CasingType, ChangeCasing, ChangeObjectCasing, ClampTo0to10, Constrain, CreateHelperFunctionOptionsBase, CreateHelperFunctionOptionsWithCustomCtxOptions, CreateHelperFunctionOptionsWithValidator, CreateHelperFunctionOptionsWithoutValidator, CreateStepHelperFn, CreatedHelperFnInput, CreatedHelperFnWithInput, CreatedHelperFnWithoutInput, CtxDataSelector, DEFAULT_CASING, DEFAULT_FIELD_TYPE, DEFAULT_LOGGER_PREFIX, DEFAULT_STORAGE_KEY, DeepKeys, DeepPartial, DeepValue, DefaultCasing, DefaultFieldType, DefaultStorageKey, Expand, ExtractStepFromKey, FIELD_TYPES, FieldType, FirstStep, GeneralHelperFn, GetCurrentStep, GetDefaultCasingTransformation, GetFieldsForStep, GreaterThan, 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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DEFAULT_STORAGE_KEY, DefaultStorageKey, MultiStepFormStorage, StorageConfig } from "./storage.mjs";
|
|
2
|
-
import { Constrain, DeepKeys, DeepValue, Expand, Join, Override, SetDefaultString, Split, objectHelpers, unionHelpers } from "./utils/types.mjs";
|
|
2
|
+
import { Constrain, DeepKeys, DeepPartial, DeepValue, Expand, Join, Override, SetDefaultString, Split, objectHelpers, unionHelpers } from "./utils/types.mjs";
|
|
3
3
|
import { CASING_TYPES, CapitalizeWord, CasingType, ChangeCasing, ChangeObjectCasing, DEFAULT_CASING, DefaultCasing, ToLower, changeCasing, isCasingValid, quote, setCasingType } from "./utils/casing.mjs";
|
|
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";
|
|
@@ -11,4 +11,4 @@ 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, 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 };
|
|
14
|
+
export { AnyResolvedStep, AnyStep, AnyStepField, AnyStepFieldOption, AsFunction, AsFunctionReturn, AsType, AsTypeMap, CASING_TYPES, CapitalizeWord, CasingType, ChangeCasing, ChangeObjectCasing, ClampTo0to10, Constrain, CreateHelperFunctionOptionsBase, CreateHelperFunctionOptionsWithCustomCtxOptions, CreateHelperFunctionOptionsWithValidator, CreateHelperFunctionOptionsWithoutValidator, CreateStepHelperFn, CreatedHelperFnInput, CreatedHelperFnWithInput, CreatedHelperFnWithoutInput, CtxDataSelector, DEFAULT_CASING, DEFAULT_FIELD_TYPE, DEFAULT_LOGGER_PREFIX, DEFAULT_STORAGE_KEY, DeepKeys, DeepPartial, DeepValue, DefaultCasing, DefaultFieldType, DefaultStorageKey, Expand, ExtractStepFromKey, FIELD_TYPES, FieldType, FirstStep, GeneralHelperFn, GetCurrentStep, GetDefaultCasingTransformation, GetFieldsForStep, GreaterThan, 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 };
|
|
@@ -9,6 +9,21 @@ const require_types = require('../steps/types.cjs');
|
|
|
9
9
|
require('../steps/index.cjs');
|
|
10
10
|
|
|
11
11
|
//#region src/internals/step-schema.ts
|
|
12
|
+
function verifyUpdate(options) {
|
|
13
|
+
const { strict, partial, actual, obj, paths, silenceErrors } = options;
|
|
14
|
+
const { mismatches, ok } = require_path.path.equalsAtPaths(obj, paths, actual);
|
|
15
|
+
let isValid = true;
|
|
16
|
+
if (strict) isValid = ok && mismatches.length === 0;
|
|
17
|
+
if (partial) {
|
|
18
|
+
const mismatchesWithoutMissingKey = mismatches.filter(({ reason }) => reason !== "missing-key");
|
|
19
|
+
if (strict) isValid = mismatchesWithoutMissingKey.length === 0;
|
|
20
|
+
else isValid = mismatchesWithoutMissingKey.filter(({ reason }) => reason !== "extra-key").length === 0;
|
|
21
|
+
}
|
|
22
|
+
if (!silenceErrors) require_invariant.invariant(isValid, `[update]: found value mismatches in ${require_path.path.printMismatches({
|
|
23
|
+
ok,
|
|
24
|
+
mismatches
|
|
25
|
+
})}`);
|
|
26
|
+
}
|
|
12
27
|
var MultiStepFormStepSchemaInternal = class {
|
|
13
28
|
#originalValue;
|
|
14
29
|
#additionalEnrichedProps;
|
|
@@ -27,8 +42,21 @@ var MultiStepFormStepSchemaInternal = class {
|
|
|
27
42
|
handlePostUpdate(value) {
|
|
28
43
|
this.#setValue(this.enrichValues(value));
|
|
29
44
|
}
|
|
45
|
+
buildCtxData(options) {
|
|
46
|
+
const { logger, values, ctxData } = options;
|
|
47
|
+
require_invariant.invariant(typeof ctxData === "function", "[update]: \"ctxData\" must be a function");
|
|
48
|
+
logger.info("Custom \"ctx\" will be used");
|
|
49
|
+
const additionalCtx = ctxData({ ctx: values });
|
|
50
|
+
require_invariant.invariant(typeof additionalCtx === "object" && Object.keys(additionalCtx).length > 0, "[update]: \"ctxData\" must return an object with keys");
|
|
51
|
+
logger.info(`Custom "ctx" consists of the following keys: ${new Intl.ListFormat("en", {
|
|
52
|
+
style: "long",
|
|
53
|
+
type: "conjunction"
|
|
54
|
+
}).format(Object.keys(additionalCtx))}`);
|
|
55
|
+
return additionalCtx;
|
|
56
|
+
}
|
|
30
57
|
createStepUpdaterFnImpl(options) {
|
|
31
|
-
const { targetStep, ctxData, fields = "all", debug } = options;
|
|
58
|
+
const { targetStep, ctxData, fields = "all", debug, partial = false, strict = true, silentErrors } = options;
|
|
59
|
+
const silenceErrors = silentErrors ?? (partial || !strict);
|
|
32
60
|
const logger = new require_logger.MultiStepFormLogger({
|
|
33
61
|
debug,
|
|
34
62
|
prefix: (value) => `${value}:update${targetStep}`
|
|
@@ -41,14 +69,11 @@ var MultiStepFormStepSchemaInternal = class {
|
|
|
41
69
|
let updatedValue = { ...this.value };
|
|
42
70
|
let ctx = require_utils.createCtx(updatedValue, [targetStep]);
|
|
43
71
|
if (ctxData) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
style: "long",
|
|
50
|
-
type: "conjunction"
|
|
51
|
-
}).format(Object.keys(additionalCtx))}`);
|
|
72
|
+
const additionalCtx = this.buildCtxData({
|
|
73
|
+
values,
|
|
74
|
+
ctxData,
|
|
75
|
+
logger
|
|
76
|
+
});
|
|
52
77
|
ctx = {
|
|
53
78
|
...ctx,
|
|
54
79
|
...additionalCtx
|
|
@@ -91,16 +116,22 @@ var MultiStepFormStepSchemaInternal = class {
|
|
|
91
116
|
...updated,
|
|
92
117
|
...functions
|
|
93
118
|
};
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
119
|
+
verifyUpdate({
|
|
120
|
+
strict,
|
|
121
|
+
partial,
|
|
122
|
+
silenceErrors,
|
|
123
|
+
obj,
|
|
124
|
+
paths,
|
|
125
|
+
actual
|
|
100
126
|
});
|
|
101
127
|
logger.info("The entire step will be updated");
|
|
102
128
|
const currentUpdatedValue = updatedValue[stepKey];
|
|
103
|
-
const updatedAtPath = require_path.path.updateAt(
|
|
129
|
+
const updatedAtPath = require_path.path.updateAt({
|
|
130
|
+
obj: currentUpdatedValue,
|
|
131
|
+
paths,
|
|
132
|
+
value: actual,
|
|
133
|
+
partial
|
|
134
|
+
});
|
|
104
135
|
updatedValue = {
|
|
105
136
|
...updatedValue,
|
|
106
137
|
[targetStep]: updatedAtPath
|
|
@@ -114,18 +145,26 @@ var MultiStepFormStepSchemaInternal = class {
|
|
|
114
145
|
if (Array.isArray(fields)) {
|
|
115
146
|
const compareResult = require_helpers.comparePartialArray(currentStepDeepKeys, fields);
|
|
116
147
|
require_invariant.invariant(compareResult.status === "success", `[update]: Found errors with the provided fields\n${compareResult.status === "error" ? require_helpers.printErrors(compareResult.errors) : ""}`);
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
148
|
+
verifyUpdate({
|
|
149
|
+
strict,
|
|
150
|
+
partial,
|
|
151
|
+
silenceErrors,
|
|
152
|
+
obj: currentStep,
|
|
153
|
+
paths: fields,
|
|
154
|
+
actual: updated
|
|
155
|
+
});
|
|
122
156
|
logger.info(`The following fields will be updated: ${new Intl.ListFormat("en", {
|
|
123
157
|
type: "conjunction",
|
|
124
158
|
style: "long"
|
|
125
159
|
}).format(fields)}`);
|
|
126
160
|
updatedValue = {
|
|
127
161
|
...updatedValue,
|
|
128
|
-
[targetStep]: require_path.path.updateAt(
|
|
162
|
+
[targetStep]: require_path.path.updateAt({
|
|
163
|
+
obj: currentStep,
|
|
164
|
+
paths: fields,
|
|
165
|
+
value: updated,
|
|
166
|
+
partial
|
|
167
|
+
})
|
|
129
168
|
};
|
|
130
169
|
this.handlePostUpdate(updatedValue);
|
|
131
170
|
logger.info(`The new value is: ${JSON.stringify(updatedValue, null, 2)}`);
|
|
@@ -135,14 +174,22 @@ var MultiStepFormStepSchemaInternal = class {
|
|
|
135
174
|
const keys = require_path.path.createDeep(fields);
|
|
136
175
|
const compareResult = require_helpers.comparePartialArray(currentStepDeepKeys, keys);
|
|
137
176
|
require_invariant.invariant(compareResult.status === "success", `[update]: Found errors with the provided fields\n${compareResult.status === "error" ? require_helpers.printErrors(compareResult.errors) : ""}`);
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
177
|
+
verifyUpdate({
|
|
178
|
+
strict,
|
|
179
|
+
partial,
|
|
180
|
+
silenceErrors,
|
|
181
|
+
obj: currentStep,
|
|
182
|
+
paths: keys,
|
|
183
|
+
actual: updated
|
|
184
|
+
});
|
|
143
185
|
updatedValue = {
|
|
144
186
|
...updatedValue,
|
|
145
|
-
[targetStep]: require_path.path.updateAt(
|
|
187
|
+
[targetStep]: require_path.path.updateAt({
|
|
188
|
+
obj: currentStep,
|
|
189
|
+
paths: keys,
|
|
190
|
+
value: updated,
|
|
191
|
+
partial
|
|
192
|
+
})
|
|
146
193
|
};
|
|
147
194
|
logger.info(`The following fields will be updated: ${new Intl.ListFormat("en", {
|
|
148
195
|
type: "conjunction",
|
|
@@ -173,7 +220,11 @@ var MultiStepFormStepSchemaInternal = class {
|
|
|
173
220
|
const picked = require_path.path.pickBy(values, ...resolvedFields);
|
|
174
221
|
config.updatedValues = {
|
|
175
222
|
...config.updatedValues,
|
|
176
|
-
...require_path.path.updateAt(
|
|
223
|
+
...require_path.path.updateAt({
|
|
224
|
+
obj: values,
|
|
225
|
+
paths: resolvedFields,
|
|
226
|
+
value: picked
|
|
227
|
+
})
|
|
177
228
|
};
|
|
178
229
|
const message = `${new Intl.ListFormat("en", {
|
|
179
230
|
style: "long",
|
|
@@ -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 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,kC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,MAAM,GAAG,iBAAiB,GAAG,GAAG,WAAW,KAAK;AAEhD,oBAAc;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
|
+
{"version":3,"file":"step-schema.cjs","names":["path","#originalValue","#additionalEnrichedProps","#getValue","#setValue","MultiStepFormLogger","isValidStepKey","createCtx","functionalUpdate","currentStep","actual: Record<string, unknown>","comparePartialArray","printErrors","createStep","isTupleNotation","HelperFnChosenSteps","typedObjectKeys"],"sources":["../../src/internals/step-schema.ts"],"sourcesContent":["import {\n createCtx,\n HelperFnChosenSteps,\n type AnyResolvedStep,\n type CreatedHelperFnInput,\n type CreateHelperFunctionOptionsWithoutValidator,\n type CreateHelperFunctionOptionsWithValidator,\n type CtxDataSelector,\n type HelperFnCtx,\n type helperFnResetFn,\n type HelperFnResetFn,\n type helperFnUpdateFn,\n type HelperFnUpdateFn,\n type HelperFnWithoutValidator,\n type HelperFnWithValidator,\n type InferStepOptions,\n type ResetFn,\n type Step,\n type StepNumbers,\n type UpdateFn,\n type ValidStepKey,\n} from '@/steps';\nimport { functionalUpdate } from '@/steps/utils';\nimport {\n invariant,\n MultiStepFormLogger,\n type CasingType,\n type DeepKeys,\n} from '@/utils';\nimport {\n comparePartialArray,\n printErrors,\n typedObjectKeys,\n} from '@/utils/helpers';\nimport { path } from '@/utils/path';\nimport {\n runStandardValidation,\n type StandardSchemaValidator,\n} from '@/utils/validator';\nimport { createStep, isTupleNotation, isValidStepKey } from './utils';\n\nexport type InternalOptions<\n TStep extends Step<TCasing>,\n TCasing extends CasingType,\n TResolvedStep extends AnyResolvedStep,\n additionalEnrichedProps extends Record<string, unknown>\n> = {\n originalValue: InferStepOptions<TStep>;\n additionalEnrichedProps?: (step: number) => additionalEnrichedProps;\n /**\n * The resolved multi step form values.\n */\n getValue: () => TResolvedStep;\n /**\n * A function used for setting the `value`. It is called after the\n * `value` is updated successfully.\n * @param value The updated and enriched multi step form values.\n * @returns\n */\n setValue: (value: TResolvedStep) => void;\n};\n\nfunction verifyUpdate<def, paths extends DeepKeys<def>>(options: {\n strict: boolean;\n partial: boolean;\n silenceErrors: boolean;\n obj: def;\n paths: paths[];\n actual: path.pickBy<def, paths>;\n}) {\n const { strict, partial, actual, obj, paths, silenceErrors } = options;\n\n // Define the logic for when the update is considered valid\n const { mismatches, ok } = path.equalsAtPaths(obj, paths, actual);\n\n let isValid = true;\n\n if (strict) {\n isValid = ok && mismatches.length === 0;\n }\n\n if (partial) {\n const mismatchesWithoutMissingKey = mismatches.filter(\n ({ reason }) => reason !== 'missing-key'\n );\n\n if (strict) {\n isValid = mismatchesWithoutMissingKey.length === 0;\n } else {\n const withoutExtraKey = mismatchesWithoutMissingKey.filter(\n ({ reason }) => reason !== 'extra-key'\n );\n\n isValid = withoutExtraKey.length === 0;\n }\n }\n\n if (!silenceErrors) {\n invariant(\n isValid,\n `[update]: found value mismatches in ${path.printMismatches({\n ok,\n mismatches,\n })}`\n );\n }\n}\n\nexport class MultiStepFormStepSchemaInternal<\n step extends Step<casing>,\n casing extends CasingType,\n resolvedStep extends AnyResolvedStep,\n stepNumbers extends StepNumbers<resolvedStep>,\n additionalEnrichedProps extends Record<string, unknown> = {}\n> {\n readonly #originalValue: InferStepOptions<step>;\n readonly #additionalEnrichedProps?: (step: number) => additionalEnrichedProps;\n readonly #getValue: () => resolvedStep;\n readonly #setValue: (value: resolvedStep) => void;\n\n private get value() {\n return this.#getValue();\n }\n\n constructor(\n options: InternalOptions<\n step,\n casing,\n resolvedStep,\n additionalEnrichedProps\n >\n ) {\n const { getValue, setValue, originalValue, additionalEnrichedProps } =\n options;\n\n this.#originalValue = originalValue;\n this.#getValue = getValue;\n this.#setValue = setValue;\n this.#additionalEnrichedProps = additionalEnrichedProps;\n }\n\n private handlePostUpdate(value: resolvedStep) {\n this.#setValue(this.enrichValues(value));\n }\n\n private buildCtxData<\n targetStep extends ValidStepKey<stepNumbers>,\n additionalCtx extends Record<string, unknown>\n >(\n options: Required<\n CtxDataSelector<resolvedStep, stepNumbers, [targetStep], additionalCtx>\n > & {\n values: Omit<resolvedStep, targetStep>;\n logger: MultiStepFormLogger;\n }\n ) {\n const { logger, values, ctxData } = options;\n invariant(\n typeof ctxData === 'function',\n '[update]: \"ctxData\" must be a function'\n );\n logger.info('Custom \"ctx\" will be used');\n\n const additionalCtx = ctxData({ ctx: values as never });\n\n invariant(\n typeof additionalCtx === 'object' &&\n Object.keys(additionalCtx).length > 0,\n '[update]: \"ctxData\" must return an object with keys'\n );\n\n logger.info(\n `Custom \"ctx\" consists of the following keys: ${new Intl.ListFormat(\n 'en',\n {\n style: 'long',\n type: 'conjunction',\n }\n ).format(Object.keys(additionalCtx))}`\n );\n\n return additionalCtx;\n }\n\n private createStepUpdaterFnImpl<\n targetStep extends ValidStepKey<stepNumbers>,\n fields extends UpdateFn.chosenFields<\n UpdateFn.resolvedStep<resolvedStep, stepNumbers, targetStep>\n >,\n strict extends boolean,\n partial extends boolean,\n additionalCtx extends Record<string, unknown>,\n additionalUpdaterData extends UpdateFn.additionalUpdaterData\n >(\n options: UpdateFn.options<\n resolvedStep,\n stepNumbers,\n targetStep,\n fields,\n strict,\n partial,\n additionalCtx,\n additionalUpdaterData\n >\n ) {\n const {\n targetStep,\n ctxData,\n fields = 'all',\n debug,\n partial = false,\n strict = true,\n silentErrors,\n } = options;\n const silenceErrors = silentErrors ?? (partial || !strict);\n const logger = new MultiStepFormLogger({\n debug,\n prefix: (value) => `${value}:update${targetStep}`,\n });\n\n logger.info(`${targetStep} will be updated`);\n invariant(\n isValidStepKey(this.value, targetStep),\n `[update]: The target step ${targetStep} isn't a valid step. Please select a valid step`\n );\n\n const { [targetStep]: currentStep, ...values } = this.value;\n\n invariant(\n 'updater' in options,\n '[update]: No \"updater\" was found. Please provide a value to the \"updater\" property'\n );\n\n const updater = options.updater;\n let updatedValue = { ...this.value };\n\n let ctx = createCtx(updatedValue, [targetStep]);\n\n // Build the `ctx` first\n if (ctxData) {\n const additionalCtx = this.buildCtxData({\n values,\n ctxData,\n logger,\n });\n\n ctx = {\n ...ctx,\n ...additionalCtx,\n };\n }\n\n const updated = functionalUpdate(updater, {\n ctx: ctx as never,\n update: this.createHelperFnInputUpdate([targetStep]),\n reset: this.createHelperFnInputReset([targetStep]),\n });\n logger.info(`The updated data is ${JSON.stringify(updated, null, 2)}`);\n\n // TODO validate `updater` - will have to be done in each case (I think)\n\n // default case: updating all fields for the current step\n if (fields === 'all') {\n invariant(\n typeof updated === 'object',\n '[update]: \"updater\" must be an object or a function that returns an object'\n );\n\n const functionKeys = new Set(['update', 'reset', 'createHelperFn']);\n const stepKeys = Object.keys(this.value);\n const updaterResultKeys = Object.keys(\n updated as Record<string, unknown>\n ).filter((value) => !functionKeys.has(value));\n const missingKeys = stepKeys.filter(\n (key) => !updaterResultKeys.includes(key)\n );\n\n for (const stepKey of stepKeys) {\n const { update, reset, createHelperFn, ...currentStep } = this.value[\n stepKey\n ] as resolvedStep[keyof resolvedStep];\n\n invariant(\n updaterResultKeys.length === Object.keys(currentStep).length,\n (formatter) => {\n return `[update]: \"updater\" is missing keys ${formatter.format(\n missingKeys\n )}`;\n }\n );\n const functions = { update, reset, createHelperFn };\n const obj = { ...currentStep, update, reset, createHelperFn };\n const paths = path.createDeep(obj);\n const actual: Record<string, unknown> = {\n ...updated,\n ...functions,\n };\n\n verifyUpdate({\n strict,\n partial,\n silenceErrors,\n obj,\n paths,\n actual: actual as never,\n });\n\n logger.info('The entire step will be updated');\n\n const currentUpdatedValue = updatedValue[stepKey] as Record<\n string,\n unknown\n >;\n const updatedAtPath = path.updateAt({\n obj: currentUpdatedValue,\n paths,\n value: actual as never,\n partial,\n });\n\n updatedValue = {\n ...updatedValue,\n [targetStep]: updatedAtPath,\n };\n\n this.handlePostUpdate(updatedValue);\n logger.info(\n `The new value is: ${JSON.stringify(updatedValue, null, 2)}`\n );\n }\n\n return;\n }\n\n const currentStepDeepKeys = path.createDeep(currentStep);\n\n if (Array.isArray(fields)) {\n const compareResult = comparePartialArray(currentStepDeepKeys, fields);\n\n invariant(\n compareResult.status === 'success',\n `[update]: Found errors with the provided fields\\n${\n compareResult.status === 'error'\n ? printErrors(compareResult.errors)\n : ''\n }`\n );\n\n verifyUpdate({\n strict,\n partial,\n silenceErrors,\n obj: currentStep,\n paths: fields,\n actual: updated as never,\n });\n\n logger.info(\n `The following fields will be updated: ${new Intl.ListFormat('en', {\n type: 'conjunction',\n style: 'long',\n }).format(fields)}`\n );\n\n updatedValue = {\n ...updatedValue,\n [targetStep]: path.updateAt({\n obj: currentStep,\n paths: fields,\n value: updated as never,\n partial,\n }),\n };\n\n this.handlePostUpdate(updatedValue);\n logger.info(`The new value is: ${JSON.stringify(updatedValue, null, 2)}`);\n\n return;\n }\n\n if (typeof fields === 'object' && Object.keys(fields).length > 0) {\n const keys = path.createDeep(fields);\n const compareResult = comparePartialArray(\n currentStepDeepKeys,\n keys as never\n );\n\n invariant(\n compareResult.status === 'success',\n `[update]: Found errors with the provided fields\\n${\n compareResult.status === 'error'\n ? printErrors(compareResult.errors)\n : ''\n }`\n );\n\n // TODO validate all values (deepest) are `true`\n verifyUpdate({\n strict,\n partial,\n silenceErrors,\n obj: currentStep,\n paths: keys as never,\n actual: updated as never,\n });\n\n updatedValue = {\n ...updatedValue,\n [targetStep]: path.updateAt({\n obj: currentStep,\n paths: keys as never,\n value: updated as never,\n partial,\n }),\n };\n\n logger.info(\n `The following fields will be updated: ${new Intl.ListFormat('en', {\n type: 'conjunction',\n style: 'long',\n }).format(Object.keys(fields))}`\n );\n this.handlePostUpdate(updatedValue);\n logger.info(`The new value is: ${JSON.stringify(updatedValue, null, 2)}`);\n\n return;\n }\n\n logger.error('Unsupported value for the \"fields\" option');\n throw new TypeError(\n `[update]: property \"fields\" must be set to one of the following: \"all\", an array of deep paths to update, or an object of paths. Was ${typeof updater}`,\n { cause: updater }\n );\n }\n\n createStepUpdaterFn<targetStep extends ValidStepKey<stepNumbers>>(\n targetStep: targetStep\n ): UpdateFn.stepSpecific<resolvedStep, stepNumbers, targetStep> {\n return (options) => {\n this.createStepUpdaterFnImpl({ targetStep, ...options });\n };\n }\n\n update<\n targetStep extends ValidStepKey<stepNumbers>,\n field extends UpdateFn.chosenFields<\n UpdateFn.resolvedStep<resolvedStep, stepNumbers, targetStep>\n > = 'all',\n strict extends boolean = true,\n partial extends boolean = false,\n additionalCtx extends Record<string, unknown> = {},\n additionalUpdaterData extends UpdateFn.additionalUpdaterData = never\n >(\n options: UpdateFn.options<\n resolvedStep,\n stepNumbers,\n targetStep,\n field,\n strict,\n partial,\n additionalCtx,\n additionalUpdaterData\n >\n ) {\n return this.createStepUpdaterFnImpl(options);\n }\n\n private resetFields<\n targetStep extends ValidStepKey<stepNumbers>,\n currentStep extends UpdateFn.resolvedStep<\n resolvedStep,\n stepNumbers,\n targetStep\n >\n >(config: {\n targetStep: targetStep;\n values: AnyResolvedStep;\n updatedValues: AnyResolvedStep;\n logger: MultiStepFormLogger;\n }) {\n return <\n fields extends HelperFnChosenSteps.tupleNotation<DeepKeys<currentStep>>\n >(\n fields: fields\n ) => {\n const { targetStep, logger, values } = config;\n const resolvedFields = fields.map((value) => `${targetStep}.${value}`);\n const picked = path.pickBy<resolvedStep, DeepKeys<resolvedStep>>(\n values,\n ...(resolvedFields as any)\n );\n\n config.updatedValues = {\n ...config.updatedValues,\n ...path.updateAt({\n obj: values,\n paths: resolvedFields,\n value: picked,\n }),\n };\n\n const formatter = new Intl.ListFormat('en', {\n style: 'long',\n type: 'conjunction',\n });\n const message = `${formatter.format(fields)} for ${targetStep}`;\n\n logger.info(`Resetting ${message}`);\n this.handlePostUpdate(config.updatedValues);\n logger.info(`Reset ${message}`);\n };\n }\n\n private createStepResetterFnImpl<\n targetStep extends ValidStepKey<stepNumbers>,\n fields extends UpdateFn.chosenFields<currentStep>,\n currentStep extends UpdateFn.resolvedStep<\n resolvedStep,\n stepNumbers,\n targetStep\n >\n >(\n options: ResetFn.Options<\n resolvedStep,\n stepNumbers,\n targetStep,\n fields,\n currentStep\n >\n ) {\n const { fields = 'all', targetStep, debug } = options;\n const logger = new MultiStepFormLogger({\n debug,\n prefix: (value) => `${value}:reset${targetStep}`,\n });\n invariant(\n fields,\n '[update]: \"fields\" must have a value when \"type\" is \"reset\"'\n );\n\n const originalValues = createStep(this.#originalValue);\n const enrichedOriginalValues = this.enrichValues<\n resolvedStep,\n additionalEnrichedProps\n >(originalValues as never, this.#additionalEnrichedProps);\n\n if (fields === 'all') {\n logger.info(`Resetting all fields for ${targetStep}`);\n this.handlePostUpdate(enrichedOriginalValues);\n logger.info(`Reset all fields for ${targetStep}`);\n }\n\n let updatedValues = { ...enrichedOriginalValues };\n const reset = this.resetFields<targetStep, currentStep>({\n logger,\n targetStep,\n updatedValues,\n values: enrichedOriginalValues,\n });\n\n if (isTupleNotation<DeepKeys<currentStep>>(fields)) {\n reset(fields);\n }\n\n if (typeof fields === 'object' && Object.keys(fields).length > 0) {\n const keys = path.createDeep(fields);\n\n reset(keys as never);\n }\n }\n\n createStepResetterFn<targetStep extends ValidStepKey<stepNumbers>>(\n targetStep: targetStep\n ): ResetFn.stepSpecific<resolvedStep, stepNumbers, targetStep> {\n return (options) => {\n return this.createStepResetterFnImpl({\n targetStep,\n fields: options?.fields ?? 'all',\n debug: options?.debug ?? false,\n });\n };\n }\n\n reset<\n targetStep extends ValidStepKey<stepNumbers>,\n fields extends UpdateFn.chosenFields<currentStep>,\n currentStep extends UpdateFn.resolvedStep<\n resolvedStep,\n stepNumbers,\n targetStep\n >\n >(\n options: ResetFn.Options<\n resolvedStep,\n stepNumbers,\n targetStep,\n fields,\n currentStep\n >\n ) {\n this.createStepResetterFnImpl(options);\n }\n\n createHelperFnInputUpdate<\n chosenSteps extends HelperFnChosenSteps<resolvedStep, stepNumbers>\n >(chosenSteps: chosenSteps) {\n if (HelperFnChosenSteps.isAll(chosenSteps)) {\n const stepSpecificUpdateFn = typedObjectKeys<\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":";;;;;;;;;;;AA8DA,SAAS,aAA+C,SAOrD;CACD,MAAM,EAAE,QAAQ,SAAS,QAAQ,KAAK,OAAO,kBAAkB;CAG/D,MAAM,EAAE,YAAY,OAAOA,kB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;AAGH,SAAO"}
|
|
@@ -22,9 +22,10 @@ declare class MultiStepFormStepSchemaInternal<step extends Step<casing>, casing
|
|
|
22
22
|
private get value();
|
|
23
23
|
constructor(options: InternalOptions<step, casing, resolvedStep, additionalEnrichedProps>);
|
|
24
24
|
private handlePostUpdate;
|
|
25
|
+
private buildCtxData;
|
|
25
26
|
private createStepUpdaterFnImpl;
|
|
26
27
|
createStepUpdaterFn<targetStep extends ValidStepKey<stepNumbers>>(targetStep: targetStep): UpdateFn.stepSpecific<resolvedStep, stepNumbers, targetStep>;
|
|
27
|
-
update<targetStep extends ValidStepKey<stepNumbers>, field extends UpdateFn.chosenFields<UpdateFn.resolvedStep<resolvedStep, stepNumbers, targetStep>> = 'all', additionalCtx extends Record<string, unknown> = {}>(options: UpdateFn.options<resolvedStep, stepNumbers, targetStep, field, additionalCtx>): void;
|
|
28
|
+
update<targetStep extends ValidStepKey<stepNumbers>, field extends UpdateFn.chosenFields<UpdateFn.resolvedStep<resolvedStep, stepNumbers, targetStep>> = 'all', strict extends boolean = true, partial extends boolean = false, additionalCtx extends Record<string, unknown> = {}, additionalUpdaterData extends UpdateFn.additionalUpdaterData = never>(options: UpdateFn.options<resolvedStep, stepNumbers, targetStep, field, strict, partial, additionalCtx, additionalUpdaterData>): void;
|
|
28
29
|
private resetFields;
|
|
29
30
|
private createStepResetterFnImpl;
|
|
30
31
|
createStepResetterFn<targetStep extends ValidStepKey<stepNumbers>>(targetStep: targetStep): ResetFn.stepSpecific<resolvedStep, stepNumbers, targetStep>;
|
|
@@ -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":";;;;KAyCY,8BACI,KAAK,0BACH,kCACM,iDACU;iBAEjB,iBAAiB;EANtB,uBAAe,CAAA,EAAA,CAAA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AAA,CAAA,CAAA,iBAAA,EA2RjB,IA3RiB,CA4Rf,wCA5Re,CA6Rb,YA7Ra,EA8Rb,WA9Ra,EA+Rb,WA/Ra,EAgSb,SAhSa,EAiSb,aAjSa,CAAA,EAAA,UAAA,CAAA,GAqSjB,IArSiB,CAsSf,2CAtSe,CAuSb,YAvSa,EAwSb,WAxSa,EAySb,WAzSa,CAAA,EAAA,UAAA,CAAA,GA6SjB,wBA7SiB,CA8Sf,YA9Se,EA+Sf,WA/Se,EAgTf,WAhTe,EAiTf,aAjTe,EAkTf,QAlTe,CAAA,EAAA,EAAA,EAqTjB,qBArTiB,CAsTf,YAtTe,EAuTf,WAvTe,EAwTf,WAxTe,EAyTf,SAzTe,EA0Tf,aA1Te,EA2Tf,QA3Te,CAAA,GA6TjB,wBA7TiB,CA8Tf,YA9Te,EA+Tf,WA/Te,EAgUf,WAhUe,EAiUf,aAjUe,EAkUf,QAlUe,CAAA,EAAA,GAAA,CAAA,GAAA,GAAA,GAAA,CAAA,GAAA,CAAA,CAAA,KAAA,CAAA,EAyVH,oBAzVG,CAyVkB,SAzVlB,CAAA,EAAA,GAyV4B,QAzV5B,CAAA;EAAc,QAAA,kBAAA;EAAa,YAAA,CAAA,eAqanC,eAramC,EAAA,wBAsa1B,MAta0B,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA,CAAA,MAAA,EAua1C,MAva0C,EAAA,eAAA,CAAA,EAAA,CAAA,IAAA,EAAA,MAAA,EAAA,GAuaE,eAvaF,CAAA,EAuaiB,MAvajB"}
|
|
@@ -22,9 +22,10 @@ declare class MultiStepFormStepSchemaInternal<step extends Step<casing>, casing
|
|
|
22
22
|
private get value();
|
|
23
23
|
constructor(options: InternalOptions<step, casing, resolvedStep, additionalEnrichedProps>);
|
|
24
24
|
private handlePostUpdate;
|
|
25
|
+
private buildCtxData;
|
|
25
26
|
private createStepUpdaterFnImpl;
|
|
26
27
|
createStepUpdaterFn<targetStep extends ValidStepKey<stepNumbers>>(targetStep: targetStep): UpdateFn.stepSpecific<resolvedStep, stepNumbers, targetStep>;
|
|
27
|
-
update<targetStep extends ValidStepKey<stepNumbers>, field extends UpdateFn.chosenFields<UpdateFn.resolvedStep<resolvedStep, stepNumbers, targetStep>> = 'all', additionalCtx extends Record<string, unknown> = {}>(options: UpdateFn.options<resolvedStep, stepNumbers, targetStep, field, additionalCtx>): void;
|
|
28
|
+
update<targetStep extends ValidStepKey<stepNumbers>, field extends UpdateFn.chosenFields<UpdateFn.resolvedStep<resolvedStep, stepNumbers, targetStep>> = 'all', strict extends boolean = true, partial extends boolean = false, additionalCtx extends Record<string, unknown> = {}, additionalUpdaterData extends UpdateFn.additionalUpdaterData = never>(options: UpdateFn.options<resolvedStep, stepNumbers, targetStep, field, strict, partial, additionalCtx, additionalUpdaterData>): void;
|
|
28
29
|
private resetFields;
|
|
29
30
|
private createStepResetterFnImpl;
|
|
30
31
|
createStepResetterFn<targetStep extends ValidStepKey<stepNumbers>>(targetStep: targetStep): ResetFn.stepSpecific<resolvedStep, stepNumbers, targetStep>;
|
|
@@ -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":";;;;KAyCY,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;AAiDjC,CAAA;AACoB,cADP,+BACO,CAAA,aAAL,IAAK,CAAA,MAAA,CAAA,EAAA,eACH,UADG,EAAA,qBAEG,eAFH,EAAA,oBAGE,WAHF,CAGc,YAHd,CAAA,EAAA,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,WA/Se,EAgTf,WAhTe,EAiTf,aAjTe,EAkTf,QAlTe,CAAA,EAAA,EAAA,EAqTjB,qBArTiB,CAsTf,YAtTe,EAuTf,WAvTe,EAwTf,WAxTe,EAyTf,SAzTe,EA0Tf,aA1Te,EA2Tf,QA3Te,CAAA,GA6TjB,wBA7TiB,CA8Tf,YA9Te,EA+Tf,WA/Te,EAgUf,WAhUe,EAiUf,aAjUe,EAkUf,QAlUe,CAAA,EAAA,GAAA,CAAA,GAAA,GAAA,GAAA,CAAA,GAAA,CAAA,CAAA,KAAA,CAAA,EAyVH,oBAzVG,CAyVkB,SAzVlB,CAAA,EAAA,GAyV4B,QAzV5B,CAAA;EAAc,QAAA,kBAAA;EAAa,YAAA,CAAA,eAqanC,eAramC,EAAA,wBAsa1B,MAta0B,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA,CAAA,MAAA,EAua1C,MAva0C,EAAA,eAAA,CAAA,EAAA,CAAA,IAAA,EAAA,MAAA,EAAA,GAuaE,eAvaF,CAAA,EAuaiB,MAvajB"}
|
|
@@ -9,6 +9,21 @@ import { HelperFnChosenSteps } from "../steps/types.mjs";
|
|
|
9
9
|
import "../steps/index.mjs";
|
|
10
10
|
|
|
11
11
|
//#region src/internals/step-schema.ts
|
|
12
|
+
function verifyUpdate(options) {
|
|
13
|
+
const { strict, partial, actual, obj, paths, silenceErrors } = options;
|
|
14
|
+
const { mismatches, ok } = path.equalsAtPaths(obj, paths, actual);
|
|
15
|
+
let isValid = true;
|
|
16
|
+
if (strict) isValid = ok && mismatches.length === 0;
|
|
17
|
+
if (partial) {
|
|
18
|
+
const mismatchesWithoutMissingKey = mismatches.filter(({ reason }) => reason !== "missing-key");
|
|
19
|
+
if (strict) isValid = mismatchesWithoutMissingKey.length === 0;
|
|
20
|
+
else isValid = mismatchesWithoutMissingKey.filter(({ reason }) => reason !== "extra-key").length === 0;
|
|
21
|
+
}
|
|
22
|
+
if (!silenceErrors) invariant(isValid, `[update]: found value mismatches in ${path.printMismatches({
|
|
23
|
+
ok,
|
|
24
|
+
mismatches
|
|
25
|
+
})}`);
|
|
26
|
+
}
|
|
12
27
|
var MultiStepFormStepSchemaInternal = class {
|
|
13
28
|
#originalValue;
|
|
14
29
|
#additionalEnrichedProps;
|
|
@@ -27,8 +42,21 @@ var MultiStepFormStepSchemaInternal = class {
|
|
|
27
42
|
handlePostUpdate(value) {
|
|
28
43
|
this.#setValue(this.enrichValues(value));
|
|
29
44
|
}
|
|
45
|
+
buildCtxData(options) {
|
|
46
|
+
const { logger, values, ctxData } = options;
|
|
47
|
+
invariant(typeof ctxData === "function", "[update]: \"ctxData\" must be a function");
|
|
48
|
+
logger.info("Custom \"ctx\" will be used");
|
|
49
|
+
const additionalCtx = ctxData({ ctx: values });
|
|
50
|
+
invariant(typeof additionalCtx === "object" && Object.keys(additionalCtx).length > 0, "[update]: \"ctxData\" must return an object with keys");
|
|
51
|
+
logger.info(`Custom "ctx" consists of the following keys: ${new Intl.ListFormat("en", {
|
|
52
|
+
style: "long",
|
|
53
|
+
type: "conjunction"
|
|
54
|
+
}).format(Object.keys(additionalCtx))}`);
|
|
55
|
+
return additionalCtx;
|
|
56
|
+
}
|
|
30
57
|
createStepUpdaterFnImpl(options) {
|
|
31
|
-
const { targetStep, ctxData, fields = "all", debug } = options;
|
|
58
|
+
const { targetStep, ctxData, fields = "all", debug, partial = false, strict = true, silentErrors } = options;
|
|
59
|
+
const silenceErrors = silentErrors ?? (partial || !strict);
|
|
32
60
|
const logger = new MultiStepFormLogger({
|
|
33
61
|
debug,
|
|
34
62
|
prefix: (value) => `${value}:update${targetStep}`
|
|
@@ -41,14 +69,11 @@ var MultiStepFormStepSchemaInternal = class {
|
|
|
41
69
|
let updatedValue = { ...this.value };
|
|
42
70
|
let ctx = createCtx(updatedValue, [targetStep]);
|
|
43
71
|
if (ctxData) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
style: "long",
|
|
50
|
-
type: "conjunction"
|
|
51
|
-
}).format(Object.keys(additionalCtx))}`);
|
|
72
|
+
const additionalCtx = this.buildCtxData({
|
|
73
|
+
values,
|
|
74
|
+
ctxData,
|
|
75
|
+
logger
|
|
76
|
+
});
|
|
52
77
|
ctx = {
|
|
53
78
|
...ctx,
|
|
54
79
|
...additionalCtx
|
|
@@ -91,16 +116,22 @@ var MultiStepFormStepSchemaInternal = class {
|
|
|
91
116
|
...updated,
|
|
92
117
|
...functions
|
|
93
118
|
};
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
119
|
+
verifyUpdate({
|
|
120
|
+
strict,
|
|
121
|
+
partial,
|
|
122
|
+
silenceErrors,
|
|
123
|
+
obj,
|
|
124
|
+
paths,
|
|
125
|
+
actual
|
|
100
126
|
});
|
|
101
127
|
logger.info("The entire step will be updated");
|
|
102
128
|
const currentUpdatedValue = updatedValue[stepKey];
|
|
103
|
-
const updatedAtPath = path.updateAt(
|
|
129
|
+
const updatedAtPath = path.updateAt({
|
|
130
|
+
obj: currentUpdatedValue,
|
|
131
|
+
paths,
|
|
132
|
+
value: actual,
|
|
133
|
+
partial
|
|
134
|
+
});
|
|
104
135
|
updatedValue = {
|
|
105
136
|
...updatedValue,
|
|
106
137
|
[targetStep]: updatedAtPath
|
|
@@ -114,18 +145,26 @@ var MultiStepFormStepSchemaInternal = class {
|
|
|
114
145
|
if (Array.isArray(fields)) {
|
|
115
146
|
const compareResult = comparePartialArray(currentStepDeepKeys, fields);
|
|
116
147
|
invariant(compareResult.status === "success", `[update]: Found errors with the provided fields\n${compareResult.status === "error" ? printErrors(compareResult.errors) : ""}`);
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
148
|
+
verifyUpdate({
|
|
149
|
+
strict,
|
|
150
|
+
partial,
|
|
151
|
+
silenceErrors,
|
|
152
|
+
obj: currentStep,
|
|
153
|
+
paths: fields,
|
|
154
|
+
actual: updated
|
|
155
|
+
});
|
|
122
156
|
logger.info(`The following fields will be updated: ${new Intl.ListFormat("en", {
|
|
123
157
|
type: "conjunction",
|
|
124
158
|
style: "long"
|
|
125
159
|
}).format(fields)}`);
|
|
126
160
|
updatedValue = {
|
|
127
161
|
...updatedValue,
|
|
128
|
-
[targetStep]: path.updateAt(
|
|
162
|
+
[targetStep]: path.updateAt({
|
|
163
|
+
obj: currentStep,
|
|
164
|
+
paths: fields,
|
|
165
|
+
value: updated,
|
|
166
|
+
partial
|
|
167
|
+
})
|
|
129
168
|
};
|
|
130
169
|
this.handlePostUpdate(updatedValue);
|
|
131
170
|
logger.info(`The new value is: ${JSON.stringify(updatedValue, null, 2)}`);
|
|
@@ -135,14 +174,22 @@ var MultiStepFormStepSchemaInternal = class {
|
|
|
135
174
|
const keys = path.createDeep(fields);
|
|
136
175
|
const compareResult = comparePartialArray(currentStepDeepKeys, keys);
|
|
137
176
|
invariant(compareResult.status === "success", `[update]: Found errors with the provided fields\n${compareResult.status === "error" ? printErrors(compareResult.errors) : ""}`);
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
177
|
+
verifyUpdate({
|
|
178
|
+
strict,
|
|
179
|
+
partial,
|
|
180
|
+
silenceErrors,
|
|
181
|
+
obj: currentStep,
|
|
182
|
+
paths: keys,
|
|
183
|
+
actual: updated
|
|
184
|
+
});
|
|
143
185
|
updatedValue = {
|
|
144
186
|
...updatedValue,
|
|
145
|
-
[targetStep]: path.updateAt(
|
|
187
|
+
[targetStep]: path.updateAt({
|
|
188
|
+
obj: currentStep,
|
|
189
|
+
paths: keys,
|
|
190
|
+
value: updated,
|
|
191
|
+
partial
|
|
192
|
+
})
|
|
146
193
|
};
|
|
147
194
|
logger.info(`The following fields will be updated: ${new Intl.ListFormat("en", {
|
|
148
195
|
type: "conjunction",
|
|
@@ -173,7 +220,11 @@ var MultiStepFormStepSchemaInternal = class {
|
|
|
173
220
|
const picked = path.pickBy(values, ...resolvedFields);
|
|
174
221
|
config.updatedValues = {
|
|
175
222
|
...config.updatedValues,
|
|
176
|
-
...path.updateAt(
|
|
223
|
+
...path.updateAt({
|
|
224
|
+
obj: values,
|
|
225
|
+
paths: resolvedFields,
|
|
226
|
+
value: picked
|
|
227
|
+
})
|
|
177
228
|
};
|
|
178
229
|
const message = `${new Intl.ListFormat("en", {
|
|
179
230
|
style: "long",
|