@jfdevelops/multi-step-form-core 1.0.0-alpha.22 → 1.0.0-alpha.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_internals.cjs +0 -4
- package/dist/_internals.d.cts +2 -3
- package/dist/_internals.d.mts +2 -3
- package/dist/_internals.mjs +1 -2
- package/dist/index.cjs +17 -17
- package/dist/index.d.cts +12 -11
- package/dist/index.d.mts +12 -11
- package/dist/index.mjs +8 -10
- package/dist/internals/step-schema.cjs +120 -71
- package/dist/internals/step-schema.cjs.map +1 -1
- package/dist/internals/step-schema.d.cts +47 -29
- package/dist/internals/step-schema.d.cts.map +1 -1
- package/dist/internals/step-schema.d.mts +47 -29
- package/dist/internals/step-schema.d.mts.map +1 -1
- package/dist/internals/step-schema.mjs +120 -71
- package/dist/internals/step-schema.mjs.map +1 -1
- package/dist/schema.cjs +14 -10
- package/dist/schema.cjs.map +1 -1
- package/dist/schema.d.cts +11 -13
- package/dist/schema.d.cts.map +1 -1
- package/dist/schema.d.mts +11 -13
- package/dist/schema.d.mts.map +1 -1
- package/dist/schema.mjs +14 -10
- package/dist/schema.mjs.map +1 -1
- package/dist/steps/fields.cjs +80 -0
- package/dist/steps/fields.cjs.map +1 -1
- package/dist/steps/fields.d.cts +117 -9
- package/dist/steps/fields.d.cts.map +1 -1
- package/dist/steps/fields.d.mts +117 -9
- package/dist/steps/fields.d.mts.map +1 -1
- package/dist/steps/fields.mjs +80 -0
- package/dist/steps/fields.mjs.map +1 -1
- package/dist/steps/fn-utils/helper-fn/index.cjs +81 -0
- package/dist/steps/fn-utils/helper-fn/index.cjs.map +1 -0
- package/dist/steps/fn-utils/helper-fn/index.d.cts +146 -0
- package/dist/steps/fn-utils/helper-fn/index.d.cts.map +1 -0
- package/dist/steps/fn-utils/helper-fn/index.d.mts +146 -0
- package/dist/steps/fn-utils/helper-fn/index.d.mts.map +1 -0
- package/dist/steps/fn-utils/helper-fn/index.mjs +75 -0
- package/dist/steps/fn-utils/helper-fn/index.mjs.map +1 -0
- package/dist/steps/fn-utils/helper-fn/utils.d.cts +81 -0
- package/dist/steps/fn-utils/helper-fn/utils.d.cts.map +1 -0
- package/dist/steps/fn-utils/helper-fn/utils.d.mts +81 -0
- package/dist/steps/fn-utils/helper-fn/utils.d.mts.map +1 -0
- package/dist/steps/fn-utils/index.cjs +1 -0
- package/dist/steps/fn-utils/index.mjs +3 -0
- package/dist/steps/fn-utils/reset-fn.d.cts +30 -0
- package/dist/steps/fn-utils/reset-fn.d.cts.map +1 -0
- package/dist/steps/fn-utils/reset-fn.d.mts +30 -0
- package/dist/steps/fn-utils/reset-fn.d.mts.map +1 -0
- package/dist/steps/fn-utils/update-fn.d.cts +121 -0
- package/dist/steps/fn-utils/update-fn.d.cts.map +1 -0
- package/dist/steps/fn-utils/update-fn.d.mts +121 -0
- package/dist/steps/fn-utils/update-fn.d.mts.map +1 -0
- package/dist/steps/index.cjs +4 -2
- package/dist/steps/index.mjs +5 -3
- package/dist/steps/schema.cjs +61 -84
- package/dist/steps/schema.cjs.map +1 -1
- package/dist/steps/schema.d.cts +66 -67
- package/dist/steps/schema.d.cts.map +1 -1
- package/dist/steps/schema.d.mts +66 -67
- package/dist/steps/schema.d.mts.map +1 -1
- package/dist/steps/schema.mjs +62 -86
- package/dist/steps/schema.mjs.map +1 -1
- package/dist/steps/steps.cjs +83 -0
- package/dist/steps/steps.cjs.map +1 -0
- package/dist/steps/steps.d.cts +81 -0
- package/dist/steps/steps.d.cts.map +1 -0
- package/dist/steps/steps.d.mts +81 -0
- package/dist/steps/steps.d.mts.map +1 -0
- package/dist/steps/steps.mjs +76 -0
- package/dist/steps/steps.mjs.map +1 -0
- package/dist/steps/utils.cjs +40 -30
- package/dist/steps/utils.cjs.map +1 -1
- package/dist/steps/utils.d.cts +8 -5
- package/dist/steps/utils.d.cts.map +1 -1
- package/dist/steps/utils.d.mts +8 -5
- package/dist/steps/utils.d.mts.map +1 -1
- package/dist/steps/utils.mjs +40 -31
- package/dist/steps/utils.mjs.map +1 -1
- package/dist/storage.cjs +1 -1
- package/dist/storage.cjs.map +1 -1
- package/dist/storage.d.cts +9 -7
- package/dist/storage.d.cts.map +1 -1
- package/dist/storage.d.mts +9 -7
- package/dist/storage.d.mts.map +1 -1
- package/dist/storage.mjs +1 -1
- package/dist/storage.mjs.map +1 -1
- package/dist/utils/casing.cjs +1 -1
- package/dist/utils/casing.cjs.map +1 -1
- package/dist/utils/casing.d.cts +27 -11
- package/dist/utils/casing.d.cts.map +1 -1
- package/dist/utils/casing.d.mts +27 -11
- package/dist/utils/casing.d.mts.map +1 -1
- package/dist/utils/casing.mjs +1 -1
- package/dist/utils/casing.mjs.map +1 -1
- package/dist/utils/helpers.cjs +8 -0
- package/dist/utils/helpers.cjs.map +1 -1
- package/dist/utils/helpers.mjs +7 -1
- package/dist/utils/helpers.mjs.map +1 -1
- package/dist/utils/index.cjs +3 -0
- package/dist/utils/index.mjs +5 -0
- package/dist/utils/invariant.cjs +28 -8
- package/dist/utils/invariant.cjs.map +1 -1
- package/dist/utils/invariant.d.cts +12 -2
- package/dist/utils/invariant.d.cts.map +1 -1
- package/dist/utils/invariant.d.mts +12 -2
- package/dist/utils/invariant.d.mts.map +1 -1
- package/dist/utils/invariant.mjs +28 -9
- package/dist/utils/invariant.mjs.map +1 -1
- package/dist/utils/types.d.cts +15 -3
- package/dist/utils/types.d.cts.map +1 -1
- package/dist/utils/types.d.mts +15 -3
- package/dist/utils/types.d.mts.map +1 -1
- package/dist/utils/validator.d.cts.map +1 -1
- package/dist/utils/validator.d.mts.map +1 -1
- package/package.json +1 -1
- package/dist/internals/utils.cjs +0 -94
- package/dist/internals/utils.cjs.map +0 -1
- package/dist/internals/utils.d.cts +0 -33
- package/dist/internals/utils.d.cts.map +0 -1
- package/dist/internals/utils.d.mts +0 -33
- package/dist/internals/utils.d.mts.map +0 -1
- package/dist/internals/utils.mjs +0 -91
- package/dist/internals/utils.mjs.map +0 -1
- package/dist/observable.cjs +0 -44
- package/dist/observable.cjs.map +0 -1
- package/dist/observable.d.cts +0 -26
- package/dist/observable.d.cts.map +0 -1
- package/dist/observable.d.mts +0 -26
- package/dist/observable.d.mts.map +0 -1
- package/dist/observable.mjs +0 -44
- package/dist/observable.mjs.map +0 -1
- package/dist/steps/types.cjs +0 -33
- package/dist/steps/types.cjs.map +0 -1
- package/dist/steps/types.d.cts +0 -354
- package/dist/steps/types.d.cts.map +0 -1
- package/dist/steps/types.d.mts +0 -354
- package/dist/steps/types.d.mts.map +0 -1
- package/dist/steps/types.mjs +0 -27
- package/dist/steps/types.mjs.map +0 -1
- package/dist/utils/field-types.cjs +0 -23
- package/dist/utils/field-types.cjs.map +0 -1
- package/dist/utils/field-types.d.cts +0 -39
- package/dist/utils/field-types.d.cts.map +0 -1
- package/dist/utils/field-types.d.mts +0 -39
- package/dist/utils/field-types.d.mts.map +0 -1
- package/dist/utils/field-types.mjs +0 -20
- package/dist/utils/field-types.mjs.map +0 -1
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { CASING_TYPES, DEFAULT_CASING, isCasingValid } from "../utils/casing.mjs";
|
|
2
|
+
import { createInvariant } from "../utils/invariant.mjs";
|
|
3
|
+
import "../utils/index.mjs";
|
|
4
|
+
import { fields } from "./fields.mjs";
|
|
5
|
+
|
|
6
|
+
//#region src/steps/steps.ts
|
|
7
|
+
const VALIDATED_STEP_REGEX = /^step\d+$/i;
|
|
8
|
+
let steps;
|
|
9
|
+
(function(_steps) {
|
|
10
|
+
function instantiate(def) {
|
|
11
|
+
const { steps: steps$1 } = def;
|
|
12
|
+
const invariant = createInvariant("[instantiateSteps]");
|
|
13
|
+
invariant(steps$1, "No steps were provided to the \"steps\" option.", TypeError);
|
|
14
|
+
invariant(typeof steps$1 === "object", "\"steps\" must be an object.", TypeError);
|
|
15
|
+
invariant(Object.keys(steps$1).length > 0, "\"steps\" must contain at least one step.", TypeError);
|
|
16
|
+
let resolvedSteps = {};
|
|
17
|
+
for (const [stepKey, stepValue] of Object.entries(steps$1)) {
|
|
18
|
+
const invariant$1 = createInvariant(`[instantiateSteps - ${stepKey}]`);
|
|
19
|
+
invariant$1(typeof stepKey === "string", `Each key for the step config must be a string. Key "${stepKey}" was ${typeof stepKey} `, TypeError);
|
|
20
|
+
invariant$1(VALIDATED_STEP_REGEX.test(stepKey), `The key "${stepKey}" isn't formatted properly. Each key in the step config must be the following format: "step{number}"`);
|
|
21
|
+
const { fields: fieldsDef, title, description, validateFields, nameTransformCasing = DEFAULT_CASING } = stepValue;
|
|
22
|
+
invariant$1(title, "A title must be provided for each step.", TypeError);
|
|
23
|
+
invariant$1(typeof title === "string", "The title must be a string.", TypeError);
|
|
24
|
+
if (description) invariant$1(typeof description === "string", "The description must be a string.", TypeError);
|
|
25
|
+
if (nameTransformCasing) {
|
|
26
|
+
invariant$1(typeof nameTransformCasing === "string", `The nameTransformCasing must be a string. Was ${typeof nameTransformCasing}`, TypeError);
|
|
27
|
+
invariant$1(isCasingValid(nameTransformCasing), (formatter) => `The nameTransformCasing is not a valid casing. Was ${nameTransformCasing}, must be one of ${formatter.format(CASING_TYPES)}`, TypeError);
|
|
28
|
+
}
|
|
29
|
+
const instantiatedFields = fields.instantiate({
|
|
30
|
+
fields: fieldsDef,
|
|
31
|
+
defaultCasing: nameTransformCasing,
|
|
32
|
+
validateFields
|
|
33
|
+
});
|
|
34
|
+
resolvedSteps[stepKey] = {
|
|
35
|
+
...resolvedSteps[stepKey],
|
|
36
|
+
title,
|
|
37
|
+
...typeof description === "string" ? { description } : {},
|
|
38
|
+
nameTransformCasing,
|
|
39
|
+
fields: instantiatedFields
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return resolvedSteps;
|
|
43
|
+
}
|
|
44
|
+
_steps.instantiate = instantiate;
|
|
45
|
+
function isValidStepValue(stepValue) {
|
|
46
|
+
if (stepValue === null || typeof stepValue !== "object") return false;
|
|
47
|
+
const step = stepValue;
|
|
48
|
+
if (!("title" in step) || typeof step.title !== "string") return false;
|
|
49
|
+
if ("description" in step) {
|
|
50
|
+
if (typeof step.description !== "string") return false;
|
|
51
|
+
}
|
|
52
|
+
if ("nameTransformCasing" in step) {
|
|
53
|
+
const casing = step.nameTransformCasing;
|
|
54
|
+
if (typeof casing !== "string" || !isCasingValid(casing)) return false;
|
|
55
|
+
}
|
|
56
|
+
if (!("fields" in step)) return false;
|
|
57
|
+
return fields.isValidFieldConfig(step.fields);
|
|
58
|
+
}
|
|
59
|
+
function isValidSteps(value) {
|
|
60
|
+
if (value === null || typeof value !== "object") return false;
|
|
61
|
+
const steps$1 = value;
|
|
62
|
+
if (Object.keys(steps$1).length === 0) return false;
|
|
63
|
+
for (const [stepKey, stepValue] of Object.entries(steps$1)) {
|
|
64
|
+
if (typeof stepKey !== "string") return false;
|
|
65
|
+
if (!VALIDATED_STEP_REGEX.test(stepKey)) return false;
|
|
66
|
+
if (!isValidStepValue(stepValue)) return false;
|
|
67
|
+
}
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
_steps.isValidSteps = isValidSteps;
|
|
71
|
+
})(steps || (steps = {}));
|
|
72
|
+
const instantiateSteps = steps.instantiate;
|
|
73
|
+
|
|
74
|
+
//#endregion
|
|
75
|
+
export { VALIDATED_STEP_REGEX, instantiateSteps, steps };
|
|
76
|
+
//# sourceMappingURL=steps.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"steps.mjs","names":["invariant: Invariant","steps","resolvedSteps: Record<string, unknown>"],"sources":["../../src/steps/steps.ts"],"sourcesContent":["import {\n CASING_TYPES,\n CasingType,\n Constrain,\n DEFAULT_CASING,\n DefaultCasing,\n isCasingValid,\n type Expand,\n type Show,\n} from '@/utils';\nimport { createInvariant, type Invariant } from '@/utils/invariant';\nimport type { AnyValidator, DefaultValidator } from '@/utils/validator';\nimport { fields } from './fields';\nimport type { StepSpecificHelperFn } from './fn-utils/helper-fn/utils';\nimport type { ResetFn } from './fn-utils/reset-fn';\nimport type { UpdateFn } from './fn-utils/update-fn';\n\nexport const VALIDATED_STEP_REGEX = /^step\\d+$/i;\n\nexport namespace steps {\n type ValidStepKey<N extends number = number> = `step${N}`;\n\n export interface Config<\n TCasing extends CasingType,\n TFields extends fields.FieldConfig<TCasing>,\n TValidator = unknown,\n > extends fields.NameTransformCasingOptions<TCasing> {\n title: string;\n description?: string;\n fields: TFields;\n validateFields?: Constrain<TValidator, AnyValidator, DefaultValidator>;\n }\n export type AnyConfig = Config<\n CasingType,\n fields.FieldConfig<CasingType>,\n AnyValidator\n >;\n export type config<\n TCasing extends CasingType = DefaultCasing,\n TFields extends fields.FieldConfig<TCasing> = fields.FieldConfig<TCasing>,\n TValidator = unknown,\n > = Record<ValidStepKey, Config<TCasing, TFields, TValidator>>;\n\n export type instantiateConfig<TMap extends config = config> = {\n /**\n * The steps that this multi step form will include.\n * @example\n * ```ts\n * {\n * step1: {\n * title: 'Step 1',\n * fields: {\n * name: {\n * defaultValue: '',\n * },\n * },\n * },\n * step2: {\n * title: 'Step 2',\n * fields: {\n * dateOfBirth: {\n * defaultValue: new Date(),\n * // `type` is automatically set to `date` if the defaultValue is a Date\n * },\n * },\n * },\n * }\n * ```\n */\n steps: TMap;\n };\n /**\n * Extended step specific properties for the step.\n */\n // @ts-expect-error - This is a placeholder for the extended step specific properties.\n export interface ExtendedStepSpecificProperties<t, key> {}\n export type _instantiateSteps<T = unknown> = [T] extends [object]\n ? T extends instantiateConfig\n ? {\n -readonly [key in keyof T['steps']]: Expand<\n {\n title: string;\n nameTransformCasing: fields.inferNameTransformCasing<\n T['steps'][key],\n DefaultCasing\n >;\n fields: fields.instantiateFields<\n T['steps'][key],\n fields.inferNameTransformCasing<T['steps'][key], DefaultCasing>\n >;\n } & (T['steps'][key] extends {\n description: infer description extends string;\n }\n ? { description: description }\n : {}) &\n ExtendedStepSpecificProperties<T, key>\n >;\n }\n : {}\n : {};\n /**\n * Extended step specific functions for the step.\n */\n export interface ExtendedStepSpecificFunctions<\n def,\n value,\n key extends StepNumbers<value>,\n > {}\n export type instantiateSteps<\n t = unknown,\n value = _instantiateSteps<t>,\n > = Expand<{\n [key in keyof value]: Show<\n value[key] &\n (value extends {}\n ? key extends StepNumbers<value>\n ? {\n update: UpdateFn.stepSpecific<value, key>;\n reset: ResetFn.stepSpecific<value, key>;\n createHelperFn: StepSpecificHelperFn<value, key>;\n } & ExtendedStepSpecificFunctions<t, value, key>\n : {}\n : {})\n >;\n }>;\n export type Any = instantiateSteps<instantiateConfig>;\n export type StepNumbers<T> = keyof T extends string ? keyof T : never;\n export type getCurrent<\n value extends instantiateSteps,\n stepNumbers extends StepNumbers<value>,\n > = value[stepNumbers];\n\n export function instantiate<\n const def extends instantiateConfig,\n inst = instantiateSteps<def>,\n >(def: def) {\n const { steps } = def;\n const invariant: Invariant = createInvariant('[instantiateSteps]');\n\n invariant(\n steps,\n 'No steps were provided to the \"steps\" option.',\n TypeError\n );\n invariant(\n typeof steps === 'object',\n '\"steps\" must be an object.',\n TypeError\n );\n invariant(\n Object.keys(steps).length > 0,\n '\"steps\" must contain at least one step.',\n TypeError\n );\n\n let resolvedSteps: Record<string, unknown> = {};\n\n for (const [stepKey, stepValue] of Object.entries(steps)) {\n const invariant: Invariant = createInvariant(\n `[instantiateSteps - ${stepKey}]`\n );\n\n invariant(\n typeof stepKey === 'string',\n `Each key for the step config must be a string. Key \"${stepKey}\" was ${typeof stepKey} `,\n TypeError\n );\n invariant(\n VALIDATED_STEP_REGEX.test(stepKey),\n `The key \"${stepKey}\" isn't formatted properly. Each key in the step config must be the following format: \"step{number}\"`\n );\n\n const {\n fields: fieldsDef,\n title,\n description,\n validateFields,\n nameTransformCasing = DEFAULT_CASING,\n } = stepValue;\n\n // title validation\n invariant(title, 'A title must be provided for each step.', TypeError);\n invariant(\n typeof title === 'string',\n 'The title must be a string.',\n TypeError\n );\n\n if (description) {\n invariant(\n typeof description === 'string',\n 'The description must be a string.',\n TypeError\n );\n }\n\n if (nameTransformCasing) {\n invariant(\n typeof nameTransformCasing === 'string',\n `The nameTransformCasing must be a string. Was ${typeof nameTransformCasing}`,\n TypeError\n );\n invariant(\n isCasingValid(nameTransformCasing),\n (formatter) =>\n `The nameTransformCasing is not a valid casing. Was ${nameTransformCasing}, must be one of ${formatter.format(\n CASING_TYPES\n )}`,\n TypeError\n );\n }\n\n const instantiatedFields = fields.instantiate({\n fields: fieldsDef,\n defaultCasing: nameTransformCasing,\n validateFields,\n });\n\n resolvedSteps[stepKey] = {\n ...(resolvedSteps[stepKey] as Record<string, unknown>),\n title,\n // Only add the description if it's defined\n ...(typeof description === 'string' ? { description } : {}),\n nameTransformCasing,\n fields: instantiatedFields,\n };\n }\n\n return resolvedSteps as inst;\n }\n\n function isValidStepValue(stepValue: unknown): stepValue is AnyConfig {\n if (stepValue === null || typeof stepValue !== 'object') {\n return false;\n }\n\n const step = stepValue as Record<string, unknown>;\n\n // Must have title\n if (!('title' in step) || typeof step.title !== 'string') {\n return false;\n }\n\n // If description is provided, it must be a string\n if ('description' in step) {\n if (typeof step.description !== 'string') {\n return false;\n }\n }\n\n // If nameTransformCasing is provided, it must be a valid casing\n if ('nameTransformCasing' in step) {\n const casing = step.nameTransformCasing;\n if (typeof casing !== 'string' || !isCasingValid(casing)) {\n return false;\n }\n }\n\n // Must have fields and it must be a valid field config\n if (!('fields' in step)) {\n return false;\n }\n\n return fields.isValidFieldConfig(step.fields);\n }\n\n export function isValidSteps(value: unknown): value is config {\n if (value === null || typeof value !== 'object') {\n return false;\n }\n\n const steps = value as Record<string, unknown>;\n\n // Check if steps has at least one key\n if (Object.keys(steps).length === 0) {\n return false;\n }\n\n // Validate each step\n for (const [stepKey, stepValue] of Object.entries(steps)) {\n // Each key must be a string\n if (typeof stepKey !== 'string') {\n return false;\n }\n\n // Each key must match the step regex pattern\n if (!VALIDATED_STEP_REGEX.test(stepKey)) {\n return false;\n }\n\n // Each value must be a valid step config\n if (!isValidStepValue(stepValue)) {\n return false;\n }\n }\n\n return true;\n }\n}\n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AE,WAAW,SAAS,OAAO,KAAK,UAAU,SAC9C,QAAO;AAIT,MAAI,iBAAiB,MACnB;OAAI,OAAO,KAAK,gBAAgB,SAC9B,QAAO;;AAKX,MAAI,yBAAyB,MAAM;GACjC,MAAM,SAAS,KAAK;AACpB,OAAI,OAAO,WAAW,YAAY,CAAC,cAAc,OAAO,CACtD,QAAO;;AAKX,MAAI,EAAE,YAAY,MAChB,QAAO;AAGT,SAAO,OAAO,mBAAmB,KAAK,OAAO;;CAGxC,SAAS,aAAa,OAAiC;AAC5D,MAAI,UAAU,QAAQ,OAAO,UAAU,SACrC,QAAO;EAGT,MAAMC,UAAQ;AAGd,MAAI,OAAO,KAAKA,QAAM,CAAC,WAAW,EAChC,QAAO;AAIT,OAAK,MAAM,CAAC,SAAS,cAAc,OAAO,QAAQA,QAAM,EAAE;AAExD,OAAI,OAAO,YAAY,SACrB,QAAO;AAIT,OAAI,CAAC,qBAAqB,KAAK,QAAQ,CACrC,QAAO;AAIT,OAAI,CAAC,iBAAiB,UAAU,CAC9B,QAAO;;AAIX,SAAO;;;;AAIX,MAAa,mBAAmB,MAAM"}
|
package/dist/steps/utils.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_index = require('./fn-utils/helper-fn/index.cjs');
|
|
2
2
|
const require_invariant = require('../utils/invariant.cjs');
|
|
3
|
+
const require_helpers = require('../utils/helpers.cjs');
|
|
3
4
|
|
|
4
5
|
//#region src/steps/utils.ts
|
|
5
6
|
/**
|
|
@@ -32,14 +33,16 @@ function getStep(resolvedStepValues) {
|
|
|
32
33
|
const { step } = options;
|
|
33
34
|
return {
|
|
34
35
|
step,
|
|
35
|
-
data: resolvedStepValues[
|
|
36
|
+
data: resolvedStepValues[step]
|
|
36
37
|
};
|
|
37
38
|
};
|
|
38
39
|
}
|
|
39
40
|
function createCtxHelper(values, data) {
|
|
41
|
+
const invariant$1 = require_invariant.createInvariant("[createCtxHelper]");
|
|
42
|
+
const getTargetStep = getStep(values);
|
|
40
43
|
return data.reduce((acc, curr) => {
|
|
41
|
-
const
|
|
42
|
-
|
|
44
|
+
const { data: data$1 } = getTargetStep({ step: curr });
|
|
45
|
+
invariant$1(data$1, `No data was found for ${curr}`, TypeError);
|
|
43
46
|
for (const [key, value] of Object.entries(data$1)) {
|
|
44
47
|
if (typeof value === "function" && key !== "update") continue;
|
|
45
48
|
data$1[key] = value;
|
|
@@ -57,40 +60,47 @@ function createCtx(values, stepData) {
|
|
|
57
60
|
const baseErrorMessage = () => {
|
|
58
61
|
return `"stepData" must be set to an array of available steps (${formatter.format(validStepKeys)})`;
|
|
59
62
|
};
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
63
|
+
return require_index.HelperFnChosenSteps.match({
|
|
64
|
+
validValues: () => validStepKeys,
|
|
65
|
+
all: () => {
|
|
66
|
+
return createCtxHelper(values, validStepKeys);
|
|
67
|
+
},
|
|
68
|
+
tuple: ({ chosenSteps }) => {
|
|
69
|
+
require_invariant.invariant(chosenSteps.every((step) => validStepKeys.includes(step)), () => {
|
|
70
|
+
const comparedResults = require_helpers.comparePartialArray(chosenSteps, validStepKeys.map((key) => extractNumber(key)), formatter);
|
|
71
|
+
if (comparedResults.status === "error") return `${baseErrorMessage()}. See errors:\n ${require_helpers.printErrors(comparedResults.errors)}`;
|
|
72
|
+
return baseErrorMessage();
|
|
73
|
+
});
|
|
74
|
+
return createCtxHelper(values, chosenSteps);
|
|
75
|
+
},
|
|
76
|
+
object: ({ chosenSteps }) => {
|
|
77
|
+
const keys = Object.keys(chosenSteps);
|
|
78
|
+
require_invariant.invariant(keys.every((key) => validStepKeys.includes(key)), () => {
|
|
79
|
+
const comparedResults = require_helpers.comparePartialArray(keys, validStepKeys, formatter);
|
|
80
|
+
if (comparedResults.status === "error") return `${baseErrorMessage()}. See errors:\n ${require_helpers.printErrors(comparedResults.errors)}`;
|
|
81
|
+
return baseErrorMessage();
|
|
82
|
+
});
|
|
83
|
+
return createCtxHelper(values, keys);
|
|
84
|
+
},
|
|
85
|
+
default: ({ errorMessage }) => {
|
|
86
|
+
throw new Error(`[createCtx]: ${errorMessage}`);
|
|
87
|
+
}
|
|
88
|
+
})(stepData);
|
|
86
89
|
}
|
|
87
90
|
function functionalUpdate(updater, input) {
|
|
88
91
|
if (typeof updater === "function") return updater(input);
|
|
89
92
|
return updater;
|
|
90
93
|
}
|
|
94
|
+
function omit(obj, keys) {
|
|
95
|
+
const keySet = new Set(keys);
|
|
96
|
+
const result = {};
|
|
97
|
+
for (const key in obj) if (!keySet.has(key)) result[key] = obj[key];
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
91
100
|
|
|
92
101
|
//#endregion
|
|
93
102
|
exports.createCtx = createCtx;
|
|
94
103
|
exports.functionalUpdate = functionalUpdate;
|
|
95
104
|
exports.getStep = getStep;
|
|
105
|
+
exports.omit = omit;
|
|
96
106
|
//# sourceMappingURL=utils.cjs.map
|
package/dist/steps/utils.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","names":["data","comparePartialArray","printErrors"],"sources":["../../src/steps/utils.ts"],"sourcesContent":["import { comparePartialArray, printErrors } from '@/utils/helpers';\nimport { invariant } from '@/utils/invariant';\nimport type {
|
|
1
|
+
{"version":3,"file":"utils.cjs","names":["invariant: Invariant","createInvariant","data","HelperFnChosenSteps","comparePartialArray","printErrors"],"sources":["../../src/steps/utils.ts"],"sourcesContent":["import { comparePartialArray, printErrors } from '@/utils/helpers';\nimport { createInvariant, invariant, type Invariant } from '@/utils/invariant';\nimport { HelperFn, HelperFnChosenSteps } from './fn-utils/helper-fn';\nimport type { steps } from './steps';\nimport type { Updater } from '@/utils/types';\n\nexport type GetStepOptions<\n value extends steps.instantiateSteps,\n stepNumbers extends steps.StepNumbers<value>,\n targetStep extends stepNumbers\n> = { step: targetStep };\nexport type ValidStepKey<N extends number = number> = `step${N}`;\nexport type ExtractStepFromKey<T> = T extends string\n ? T extends ValidStepKey<infer N>\n ? N\n : never\n : never;\n\n/**\n * Gets the step number from an input string.\n * @param input The input to extract the step number from.\n * @returns The extracted step number.\n */\nexport function extractNumber(input: string) {\n invariant(input.includes('step'), \"Can't extract a valid step number since\");\n\n const extracted = input.replace('step', '');\n\n invariant(/^\\d+$/.test(extracted), `Invalid step format: \"${input}\"`);\n\n return Number.parseInt(extracted, 10);\n}\n\n/**\n * A factory function to get the data of a specific step.\n * @param resolvedStepValues The resolved step values.\n * @returns A function to get specific step data from a target step.\n */\nexport function getStep<\n value extends steps.instantiateSteps,\n stepNumbers extends steps.StepNumbers<value>\n>(resolvedStepValues: value) {\n /**\n * Gets the step data associated with the target step number.\n *\n * @example\n * const result = getStep(resolvedStepValues)({ step: 1 });\n * // result: { step: 1, data: ... }\n *\n * @returns An object containing the `step` number and the associated step data.\n */\n return function <targetStep extends stepNumbers>(\n options: GetStepOptions<value, stepNumbers, targetStep>\n ) {\n const { step } = options;\n\n const data = resolvedStepValues[step] as steps.getCurrent<\n value,\n targetStep\n >;\n\n return { step, data };\n };\n}\n\nfunction createCtxHelper<\n value extends steps.instantiateSteps,\n stepNumbers extends steps.StepNumbers<value>,\n chosenSteps extends HelperFnChosenSteps.main<value, stepNumbers>\n>(values: value, data: string[]) {\n const invariant: Invariant = createInvariant('[createCtxHelper]');\n const getTargetStep = getStep(values);\n\n return data.reduce((acc, curr) => {\n const { data } = getTargetStep({\n step: curr as stepNumbers,\n });\n\n invariant(data, `No data was found for ${curr}`, TypeError);\n\n for (const [key, value] of Object.entries(data)) {\n // console.log({ [key]: value });\n // Remove the functions from the data to comply with `StrippedResolvedStep`\n if (typeof value === 'function' && key !== 'update') {\n continue;\n }\n\n data[key as keyof typeof data] = value as never;\n }\n\n acc[curr as keyof typeof acc] = data as never;\n\n return acc;\n }, {} as HelperFn.buildCtx<value, chosenSteps>);\n}\n\nexport function createCtx<\n value extends steps.instantiateSteps,\n stepNumbers extends steps.StepNumbers<value>,\n chosenSteps extends HelperFnChosenSteps.main<value, stepNumbers>\n>(values: value, stepData: chosenSteps) {\n const formatter = new Intl.ListFormat('en', {\n style: 'long',\n type: 'disjunction',\n });\n const validStepKeys = Object.keys(values);\n\n const baseErrorMessage = () => {\n return `\"stepData\" must be set to an array of available steps (${formatter.format(\n validStepKeys\n )})`;\n };\n const match = HelperFnChosenSteps.match({\n validValues: () => validStepKeys,\n all: () => {\n return createCtxHelper(values, validStepKeys);\n },\n tuple: ({ chosenSteps }) => {\n invariant(\n chosenSteps.every((step) => validStepKeys.includes(step)),\n () => {\n const comparedResults = comparePartialArray(\n chosenSteps,\n validStepKeys.map((key) => extractNumber(key)),\n formatter\n );\n\n if (comparedResults.status === 'error') {\n return `${baseErrorMessage()}. See errors:\\n ${printErrors(\n comparedResults.errors\n )}`;\n }\n\n return baseErrorMessage();\n }\n );\n\n return createCtxHelper(values, chosenSteps);\n },\n object: ({ chosenSteps }) => {\n const keys = Object.keys(chosenSteps);\n\n invariant(\n keys.every((key) => validStepKeys.includes(key)),\n () => {\n const comparedResults = comparePartialArray(\n keys,\n validStepKeys,\n formatter\n );\n\n if (comparedResults.status === 'error') {\n return `${baseErrorMessage()}. See errors:\\n ${printErrors(\n comparedResults.errors\n )}`;\n }\n\n return baseErrorMessage();\n }\n );\n\n return createCtxHelper(values, keys);\n },\n default: ({ errorMessage }) => {\n throw new Error(`[createCtx]: ${errorMessage}`);\n },\n });\n\n return match<value, chosenSteps>(stepData);\n}\n\nexport function functionalUpdate<TInput, TOutput>(\n updater: Updater<TInput, TOutput>,\n input: TInput\n) {\n if (typeof updater === 'function') {\n return (updater as (_: TInput) => TOutput)(input);\n }\n\n return updater;\n}\n\nexport function omit<T extends object, K extends (keyof T)[]>(\n obj: T,\n keys: K\n): Omit<T, K[number]> {\n const keySet = new Set<keyof T>(keys);\n\n const result = {} as Omit<T, K[number]>;\n\n for (const key in obj) {\n if (!keySet.has(key)) {\n result[key as unknown as Exclude<keyof T, K[number]>] = obj[key] as never;\n }\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;AAuBA,SAAgB,cAAc,OAAe;AAC3C,6BAAU,MAAM,SAAS,OAAO,EAAE,0CAA0C;CAE5E,MAAM,YAAY,MAAM,QAAQ,QAAQ,GAAG;AAE3C,6BAAU,QAAQ,KAAK,UAAU,EAAE,yBAAyB,MAAM,GAAG;AAErE,QAAO,OAAO,SAAS,WAAW,GAAG;;;;;;;AAQvC,SAAgB,QAGd,oBAA2B;;;;;;;;;;AAU3B,QAAO,SACL,SACA;EACA,MAAM,EAAE,SAAS;AAOjB,SAAO;GAAE;GAAM,MALF,mBAAmB;GAKX;;;AAIzB,SAAS,gBAIP,QAAe,MAAgB;CAC/B,MAAMA,cAAuBC,kCAAgB,oBAAoB;CACjE,MAAM,gBAAgB,QAAQ,OAAO;AAErC,QAAO,KAAK,QAAQ,KAAK,SAAS;EAChC,MAAM,EAAE,iBAAS,cAAc,EAC7B,MAAM,MACP,CAAC;AAEF,cAAUC,QAAM,yBAAyB,QAAQ,UAAU;AAE3D,OAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQA,OAAK,EAAE;AAG/C,OAAI,OAAO,UAAU,cAAc,QAAQ,SACzC;AAGF,UAAK,OAA4B;;AAGnC,MAAI,QAA4BA;AAEhC,SAAO;IACN,EAAE,CAA0C;;AAGjD,SAAgB,UAId,QAAe,UAAuB;CACtC,MAAM,YAAY,IAAI,KAAK,WAAW,MAAM;EAC1C,OAAO;EACP,MAAM;EACP,CAAC;CACF,MAAM,gBAAgB,OAAO,KAAK,OAAO;CAEzC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
|
|
|
1
|
-
import {
|
|
1
|
+
import { steps } from "./steps.cjs";
|
|
2
|
+
import { HelperFn, HelperFnChosenSteps } from "./fn-utils/helper-fn/index.cjs";
|
|
2
3
|
|
|
3
4
|
//#region src/steps/utils.d.ts
|
|
4
|
-
type GetStepOptions<
|
|
5
|
-
step:
|
|
5
|
+
type GetStepOptions<value extends steps.instantiateSteps, stepNumbers extends steps.StepNumbers<value>, targetStep extends stepNumbers> = {
|
|
6
|
+
step: targetStep;
|
|
6
7
|
};
|
|
7
|
-
|
|
8
|
+
type ValidStepKey<N extends number = number> = `step${N}`;
|
|
9
|
+
type ExtractStepFromKey<T> = T extends string ? T extends ValidStepKey<infer N> ? N : never : never;
|
|
10
|
+
declare function createCtx<value extends steps.instantiateSteps, stepNumbers extends steps.StepNumbers<value>, chosenSteps extends HelperFnChosenSteps.main<value, stepNumbers>>(values: value, stepData: chosenSteps): HelperFn.buildCtx<value, HelperFnChosenSteps.main<value, steps.StepNumbers<value>>, never>;
|
|
8
11
|
//#endregion
|
|
9
|
-
export { GetStepOptions, createCtx };
|
|
12
|
+
export { ExtractStepFromKey, GetStepOptions, createCtx };
|
|
10
13
|
//# sourceMappingURL=utils.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.cts","names":[],"sources":["../../src/steps/utils.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.cts","names":[],"sources":["../../src/steps/utils.ts"],"sourcesContent":[],"mappings":";;;;KAMY,6BACI,KAAA,CAAM,sCACA,KAAA,CAAM,YAAY,2BACnB;EAHT,IAAA,EAIA,UAJA;CACI;AACwB,KAG5B,YAH4B,CAAA,UAAA,MAAA,GAAA,MAAA,CAAA,GAAA,OAGqB,CAHrB,EAAA;AAAZ,KAIhB,kBAJgB,CAAA,CAAA,CAAA,GAIQ,CAJR,SAAA,MAAA,GAKxB,CALwB,SAKd,YALc,CAAA,KAAA,EAAA,CAAA,GAAA,CAAA,GAAA,KAAA,GAAA,KAAA;AA2FN,iBAHN,SAG0B,CAAA,cAF1B,KAAA,CAAM,gBAEoB,EAAA,oBADpB,KAAA,CAAM,WACc,CADF,KACE,CAAA,EAAA,oBAApB,mBAAA,CAAoB,IAAA,CAAK,KAAL,EAAY,WAAZ,CAAA,CAAA,CAAA,MAAA,EAChC,KADgC,EAAA,QAAA,EACf,WADe,CAAA,EACJ,QAAA,CAAA,QADI,CACJ,KADI,EACJ,mBAAA,CAAA,IADI,CACJ,KADI,EACJ,KAAA,CAAA,WADI,CACJ,KADI,CAAA,CAAA,EAAA,KAAA,CAAA"}
|
package/dist/steps/utils.d.mts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { steps } from "./steps.mjs";
|
|
2
|
+
import { HelperFn, HelperFnChosenSteps } from "./fn-utils/helper-fn/index.mjs";
|
|
2
3
|
|
|
3
4
|
//#region src/steps/utils.d.ts
|
|
4
|
-
type GetStepOptions<
|
|
5
|
-
step:
|
|
5
|
+
type GetStepOptions<value extends steps.instantiateSteps, stepNumbers extends steps.StepNumbers<value>, targetStep extends stepNumbers> = {
|
|
6
|
+
step: targetStep;
|
|
6
7
|
};
|
|
7
|
-
|
|
8
|
+
type ValidStepKey<N extends number = number> = `step${N}`;
|
|
9
|
+
type ExtractStepFromKey<T> = T extends string ? T extends ValidStepKey<infer N> ? N : never : never;
|
|
10
|
+
declare function createCtx<value extends steps.instantiateSteps, stepNumbers extends steps.StepNumbers<value>, chosenSteps extends HelperFnChosenSteps.main<value, stepNumbers>>(values: value, stepData: chosenSteps): HelperFn.buildCtx<value, HelperFnChosenSteps.main<value, steps.StepNumbers<value>>, never>;
|
|
8
11
|
//#endregion
|
|
9
|
-
export { GetStepOptions, createCtx };
|
|
12
|
+
export { ExtractStepFromKey, GetStepOptions, createCtx };
|
|
10
13
|
//# sourceMappingURL=utils.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.mts","names":[],"sources":["../../src/steps/utils.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.mts","names":[],"sources":["../../src/steps/utils.ts"],"sourcesContent":[],"mappings":";;;;KAMY,6BACI,KAAA,CAAM,sCACA,KAAA,CAAM,YAAY,2BACnB;EAHT,IAAA,EAIA,UAJA;CACI;AACwB,KAG5B,YAH4B,CAAA,UAAA,MAAA,GAAA,MAAA,CAAA,GAAA,OAGqB,CAHrB,EAAA;AAAZ,KAIhB,kBAJgB,CAAA,CAAA,CAAA,GAIQ,CAJR,SAAA,MAAA,GAKxB,CALwB,SAKd,YALc,CAAA,KAAA,EAAA,CAAA,GAAA,CAAA,GAAA,KAAA,GAAA,KAAA;AA2FN,iBAHN,SAG0B,CAAA,cAF1B,KAAA,CAAM,gBAEoB,EAAA,oBADpB,KAAA,CAAM,WACc,CADF,KACE,CAAA,EAAA,oBAApB,mBAAA,CAAoB,IAAA,CAAK,KAAL,EAAY,WAAZ,CAAA,CAAA,CAAA,MAAA,EAChC,KADgC,EAAA,QAAA,EACf,WADe,CAAA,EACJ,QAAA,CAAA,QADI,CACJ,KADI,EACJ,mBAAA,CAAA,IADI,CACJ,KADI,EACJ,KAAA,CAAA,WADI,CACJ,KADI,CAAA,CAAA,EAAA,KAAA,CAAA"}
|
package/dist/steps/utils.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { HelperFnChosenSteps } from "./fn-utils/helper-fn/index.mjs";
|
|
2
|
+
import { createInvariant, invariant } from "../utils/invariant.mjs";
|
|
1
3
|
import { comparePartialArray, printErrors } from "../utils/helpers.mjs";
|
|
2
|
-
import { invariant } from "../utils/invariant.mjs";
|
|
3
4
|
|
|
4
5
|
//#region src/steps/utils.ts
|
|
5
6
|
/**
|
|
@@ -32,14 +33,16 @@ function getStep(resolvedStepValues) {
|
|
|
32
33
|
const { step } = options;
|
|
33
34
|
return {
|
|
34
35
|
step,
|
|
35
|
-
data: resolvedStepValues[
|
|
36
|
+
data: resolvedStepValues[step]
|
|
36
37
|
};
|
|
37
38
|
};
|
|
38
39
|
}
|
|
39
40
|
function createCtxHelper(values, data) {
|
|
41
|
+
const invariant$1 = createInvariant("[createCtxHelper]");
|
|
42
|
+
const getTargetStep = getStep(values);
|
|
40
43
|
return data.reduce((acc, curr) => {
|
|
41
|
-
const
|
|
42
|
-
|
|
44
|
+
const { data: data$1 } = getTargetStep({ step: curr });
|
|
45
|
+
invariant$1(data$1, `No data was found for ${curr}`, TypeError);
|
|
43
46
|
for (const [key, value] of Object.entries(data$1)) {
|
|
44
47
|
if (typeof value === "function" && key !== "update") continue;
|
|
45
48
|
data$1[key] = value;
|
|
@@ -57,38 +60,44 @@ function createCtx(values, stepData) {
|
|
|
57
60
|
const baseErrorMessage = () => {
|
|
58
61
|
return `"stepData" must be set to an array of available steps (${formatter.format(validStepKeys)})`;
|
|
59
62
|
};
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
63
|
+
return HelperFnChosenSteps.match({
|
|
64
|
+
validValues: () => validStepKeys,
|
|
65
|
+
all: () => {
|
|
66
|
+
return createCtxHelper(values, validStepKeys);
|
|
67
|
+
},
|
|
68
|
+
tuple: ({ chosenSteps }) => {
|
|
69
|
+
invariant(chosenSteps.every((step) => validStepKeys.includes(step)), () => {
|
|
70
|
+
const comparedResults = comparePartialArray(chosenSteps, validStepKeys.map((key) => extractNumber(key)), formatter);
|
|
71
|
+
if (comparedResults.status === "error") return `${baseErrorMessage()}. See errors:\n ${printErrors(comparedResults.errors)}`;
|
|
72
|
+
return baseErrorMessage();
|
|
73
|
+
});
|
|
74
|
+
return createCtxHelper(values, chosenSteps);
|
|
75
|
+
},
|
|
76
|
+
object: ({ chosenSteps }) => {
|
|
77
|
+
const keys = Object.keys(chosenSteps);
|
|
78
|
+
invariant(keys.every((key) => validStepKeys.includes(key)), () => {
|
|
79
|
+
const comparedResults = comparePartialArray(keys, validStepKeys, formatter);
|
|
80
|
+
if (comparedResults.status === "error") return `${baseErrorMessage()}. See errors:\n ${printErrors(comparedResults.errors)}`;
|
|
81
|
+
return baseErrorMessage();
|
|
82
|
+
});
|
|
83
|
+
return createCtxHelper(values, keys);
|
|
84
|
+
},
|
|
85
|
+
default: ({ errorMessage }) => {
|
|
86
|
+
throw new Error(`[createCtx]: ${errorMessage}`);
|
|
87
|
+
}
|
|
88
|
+
})(stepData);
|
|
86
89
|
}
|
|
87
90
|
function functionalUpdate(updater, input) {
|
|
88
91
|
if (typeof updater === "function") return updater(input);
|
|
89
92
|
return updater;
|
|
90
93
|
}
|
|
94
|
+
function omit(obj, keys) {
|
|
95
|
+
const keySet = new Set(keys);
|
|
96
|
+
const result = {};
|
|
97
|
+
for (const key in obj) if (!keySet.has(key)) result[key] = obj[key];
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
91
100
|
|
|
92
101
|
//#endregion
|
|
93
|
-
export { createCtx, functionalUpdate, getStep };
|
|
102
|
+
export { createCtx, functionalUpdate, getStep, omit };
|
|
94
103
|
//# sourceMappingURL=utils.mjs.map
|
package/dist/steps/utils.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","names":["data"],"sources":["../../src/steps/utils.ts"],"sourcesContent":["import { comparePartialArray, printErrors } from '@/utils/helpers';\nimport { invariant } from '@/utils/invariant';\nimport type {
|
|
1
|
+
{"version":3,"file":"utils.mjs","names":["invariant: Invariant","data"],"sources":["../../src/steps/utils.ts"],"sourcesContent":["import { comparePartialArray, printErrors } from '@/utils/helpers';\nimport { createInvariant, invariant, type Invariant } from '@/utils/invariant';\nimport { HelperFn, HelperFnChosenSteps } from './fn-utils/helper-fn';\nimport type { steps } from './steps';\nimport type { Updater } from '@/utils/types';\n\nexport type GetStepOptions<\n value extends steps.instantiateSteps,\n stepNumbers extends steps.StepNumbers<value>,\n targetStep extends stepNumbers\n> = { step: targetStep };\nexport type ValidStepKey<N extends number = number> = `step${N}`;\nexport type ExtractStepFromKey<T> = T extends string\n ? T extends ValidStepKey<infer N>\n ? N\n : never\n : never;\n\n/**\n * Gets the step number from an input string.\n * @param input The input to extract the step number from.\n * @returns The extracted step number.\n */\nexport function extractNumber(input: string) {\n invariant(input.includes('step'), \"Can't extract a valid step number since\");\n\n const extracted = input.replace('step', '');\n\n invariant(/^\\d+$/.test(extracted), `Invalid step format: \"${input}\"`);\n\n return Number.parseInt(extracted, 10);\n}\n\n/**\n * A factory function to get the data of a specific step.\n * @param resolvedStepValues The resolved step values.\n * @returns A function to get specific step data from a target step.\n */\nexport function getStep<\n value extends steps.instantiateSteps,\n stepNumbers extends steps.StepNumbers<value>\n>(resolvedStepValues: value) {\n /**\n * Gets the step data associated with the target step number.\n *\n * @example\n * const result = getStep(resolvedStepValues)({ step: 1 });\n * // result: { step: 1, data: ... }\n *\n * @returns An object containing the `step` number and the associated step data.\n */\n return function <targetStep extends stepNumbers>(\n options: GetStepOptions<value, stepNumbers, targetStep>\n ) {\n const { step } = options;\n\n const data = resolvedStepValues[step] as steps.getCurrent<\n value,\n targetStep\n >;\n\n return { step, data };\n };\n}\n\nfunction createCtxHelper<\n value extends steps.instantiateSteps,\n stepNumbers extends steps.StepNumbers<value>,\n chosenSteps extends HelperFnChosenSteps.main<value, stepNumbers>\n>(values: value, data: string[]) {\n const invariant: Invariant = createInvariant('[createCtxHelper]');\n const getTargetStep = getStep(values);\n\n return data.reduce((acc, curr) => {\n const { data } = getTargetStep({\n step: curr as stepNumbers,\n });\n\n invariant(data, `No data was found for ${curr}`, TypeError);\n\n for (const [key, value] of Object.entries(data)) {\n // console.log({ [key]: value });\n // Remove the functions from the data to comply with `StrippedResolvedStep`\n if (typeof value === 'function' && key !== 'update') {\n continue;\n }\n\n data[key as keyof typeof data] = value as never;\n }\n\n acc[curr as keyof typeof acc] = data as never;\n\n return acc;\n }, {} as HelperFn.buildCtx<value, chosenSteps>);\n}\n\nexport function createCtx<\n value extends steps.instantiateSteps,\n stepNumbers extends steps.StepNumbers<value>,\n chosenSteps extends HelperFnChosenSteps.main<value, stepNumbers>\n>(values: value, stepData: chosenSteps) {\n const formatter = new Intl.ListFormat('en', {\n style: 'long',\n type: 'disjunction',\n });\n const validStepKeys = Object.keys(values);\n\n const baseErrorMessage = () => {\n return `\"stepData\" must be set to an array of available steps (${formatter.format(\n validStepKeys\n )})`;\n };\n const match = HelperFnChosenSteps.match({\n validValues: () => validStepKeys,\n all: () => {\n return createCtxHelper(values, validStepKeys);\n },\n tuple: ({ chosenSteps }) => {\n invariant(\n chosenSteps.every((step) => validStepKeys.includes(step)),\n () => {\n const comparedResults = comparePartialArray(\n chosenSteps,\n validStepKeys.map((key) => extractNumber(key)),\n formatter\n );\n\n if (comparedResults.status === 'error') {\n return `${baseErrorMessage()}. See errors:\\n ${printErrors(\n comparedResults.errors\n )}`;\n }\n\n return baseErrorMessage();\n }\n );\n\n return createCtxHelper(values, chosenSteps);\n },\n object: ({ chosenSteps }) => {\n const keys = Object.keys(chosenSteps);\n\n invariant(\n keys.every((key) => validStepKeys.includes(key)),\n () => {\n const comparedResults = comparePartialArray(\n keys,\n validStepKeys,\n formatter\n );\n\n if (comparedResults.status === 'error') {\n return `${baseErrorMessage()}. See errors:\\n ${printErrors(\n comparedResults.errors\n )}`;\n }\n\n return baseErrorMessage();\n }\n );\n\n return createCtxHelper(values, keys);\n },\n default: ({ errorMessage }) => {\n throw new Error(`[createCtx]: ${errorMessage}`);\n },\n });\n\n return match<value, chosenSteps>(stepData);\n}\n\nexport function functionalUpdate<TInput, TOutput>(\n updater: Updater<TInput, TOutput>,\n input: TInput\n) {\n if (typeof updater === 'function') {\n return (updater as (_: TInput) => TOutput)(input);\n }\n\n return updater;\n}\n\nexport function omit<T extends object, K extends (keyof T)[]>(\n obj: T,\n keys: K\n): Omit<T, K[number]> {\n const keySet = new Set<keyof T>(keys);\n\n const result = {} as Omit<T, K[number]>;\n\n for (const key in obj) {\n if (!keySet.has(key)) {\n result[key as unknown as Exclude<keyof T, K[number]>] = obj[key] as never;\n }\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;AAuBA,SAAgB,cAAc,OAAe;AAC3C,WAAU,MAAM,SAAS,OAAO,EAAE,0CAA0C;CAE5E,MAAM,YAAY,MAAM,QAAQ,QAAQ,GAAG;AAE3C,WAAU,QAAQ,KAAK,UAAU,EAAE,yBAAyB,MAAM,GAAG;AAErE,QAAO,OAAO,SAAS,WAAW,GAAG;;;;;;;AAQvC,SAAgB,QAGd,oBAA2B;;;;;;;;;;AAU3B,QAAO,SACL,SACA;EACA,MAAM,EAAE,SAAS;AAOjB,SAAO;GAAE;GAAM,MALF,mBAAmB;GAKX;;;AAIzB,SAAS,gBAIP,QAAe,MAAgB;CAC/B,MAAMA,cAAuB,gBAAgB,oBAAoB;CACjE,MAAM,gBAAgB,QAAQ,OAAO;AAErC,QAAO,KAAK,QAAQ,KAAK,SAAS;EAChC,MAAM,EAAE,iBAAS,cAAc,EAC7B,MAAM,MACP,CAAC;AAEF,cAAUC,QAAM,yBAAyB,QAAQ,UAAU;AAE3D,OAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQA,OAAK,EAAE;AAG/C,OAAI,OAAO,UAAU,cAAc,QAAQ,SACzC;AAGF,UAAK,OAA4B;;AAGnC,MAAI,QAA4BA;AAEhC,SAAO;IACN,EAAE,CAA0C;;AAGjD,SAAgB,UAId,QAAe,UAAuB;CACtC,MAAM,YAAY,IAAI,KAAK,WAAW,MAAM;EAC1C,OAAO;EACP,MAAM;EACP,CAAC;CACF,MAAM,gBAAgB,OAAO,KAAK,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|
|
1
|
-
const require_invariant = require('./utils/invariant.cjs');
|
|
2
1
|
const require_logger = require('./utils/logger.cjs');
|
|
2
|
+
const require_invariant = require('./utils/invariant.cjs');
|
|
3
3
|
|
|
4
4
|
//#region src/storage.ts
|
|
5
5
|
const WINDOW_UNDEFINED_MESSAGE = "\"window\" in undefined. No storage is available";
|
package/dist/storage.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.cjs","names":["MultiStepFormLogger"],"sources":["../src/storage.ts"],"sourcesContent":["import type { Updater } from '@/
|
|
1
|
+
{"version":3,"file":"storage.cjs","names":["MultiStepFormLogger"],"sources":["../src/storage.ts"],"sourcesContent":["import type { Updater } from '@/utils/types';\nimport { invariant } from '@/utils/invariant';\nimport { MultiStepFormLogger } from '@/utils/logger';\n\nexport type DefaultStorageKey = typeof DEFAULT_STORAGE_KEY;\nexport interface BaseStorageConfig<TKey extends string> {\n key: TKey;\n store?: Storage;\n /**\n * An extra option to throw an error when {@linkcode window} is `undefined`\n * @default false\n */\n throwWhenUndefined?: boolean;\n}\nexport type StorageConfig<\nTData,\nTKey extends string\n> = BaseStorageConfig<TKey> & {\n data: TData;\n};\n\nconst WINDOW_UNDEFINED_MESSAGE =\n'\"window\" in undefined. No storage is available';\nexport const DEFAULT_STORAGE_KEY = 'MultiStepForm';\n\n/**\n* Converts Date strings back to Date objects for fields with type: 'date'.\n*/\nfunction convertDateStringsToDates(parsed: unknown): unknown {\n if (!parsed || typeof parsed !== 'object') {\n return parsed;\n }\n\n const converted = Array.isArray(parsed) ? [...parsed] : { ...parsed };\n\n // Iterate through each step\n for (const [stepKey, stepValue] of Object.entries(converted)) {\n if (\n !stepValue ||\n typeof stepValue !== 'object' ||\n !('fields' in stepValue) ||\n typeof stepValue.fields !== 'object'\n ) {\n continue;\n }\n\n const fields = { ...(stepValue.fields as Record<string, unknown>) };\n let hasChanges = false;\n\n // Iterate through each field\n for (const [fieldName, fieldValue] of Object.entries(fields)) {\n if (\n !fieldValue ||\n typeof fieldValue !== 'object' ||\n !('type' in fieldValue) ||\n !('defaultValue' in fieldValue)\n ) {\n continue;\n }\n\n // Check if field has type: 'date' and defaultValue is a string\n if (\n fieldValue.type === 'date' &&\n typeof fieldValue.defaultValue === 'string'\n ) {\n // Convert string to Date\n const dateValue = new Date(fieldValue.defaultValue);\n\n // Only convert if it's a valid date\n if (!Number.isNaN(dateValue.getTime())) {\n fields[fieldName] = {\n ...fieldValue,\n defaultValue: dateValue,\n };\n hasChanges = true;\n }\n }\n }\n\n // Update the step with converted fields if there were changes\n if (hasChanges) {\n (converted as Record<string, unknown>)[stepKey] = {\n ...stepValue,\n fields,\n };\n }\n }\n\n return converted;\n}\n\nexport class MultiStepFormStorage<\ndata,\nkey extends string = DefaultStorageKey\n> {\n readonly key: key;\n readonly store!: Storage;\n readonly data: data;\n private readonly log: MultiStepFormLogger;\n private readonly shouldRunActions: boolean;\n private readonly throwWhenUndefined: boolean;\n\n constructor(config: StorageConfig<data, key>) {\n const { key, data, store, throwWhenUndefined = false } = config;\n\n this.log = new MultiStepFormLogger({\n prefix: DEFAULT_STORAGE_KEY,\n });\n this.key = key;\n this.data = data;\n this.throwWhenUndefined = throwWhenUndefined;\n\n if (store) {\n this.store = store;\n this.shouldRunActions = true;\n\n if (typeof window === 'undefined') {\n // this.shouldRunActions = false;\n this.log.warn(WINDOW_UNDEFINED_MESSAGE);\n }\n } else if (typeof window !== 'undefined') {\n this.store = window.localStorage;\n this.shouldRunActions = true;\n } else {\n this.shouldRunActions = false;\n this.log.warn(WINDOW_UNDEFINED_MESSAGE);\n }\n }\n\n private throwOnEmptyStore() {\n if (!this.throwWhenUndefined) {\n return;\n }\n\n invariant(this.store, () => {\n if (this.shouldRunActions) {\n return WINDOW_UNDEFINED_MESSAGE;\n }\n\n return 'No storage available';\n });\n }\n\n private resolveValue(value: Updater<data>) {\n if (typeof value === 'function') {\n return (value as (input: data) => data)(this.data);\n }\n\n return value;\n }\n\n hasKey() {\n return this.store.getItem(this.key) !== null;\n }\n\n get() {\n this.throwOnEmptyStore();\n\n if (!this.shouldRunActions) {\n return;\n }\n\n const item = this.store.getItem(this.key);\n\n if (item) {\n const parsed = JSON.parse(item);\n const converted = convertDateStringsToDates(parsed);\n\n return converted as data;\n }\n }\n\n remove() {\n this.throwOnEmptyStore();\n\n if (!this.shouldRunActions) {\n return;\n }\n\n this.store.removeItem(this.key);\n }\n\n add(value: Updater<data>) {\n this.throwOnEmptyStore();\n\n if (!this.shouldRunActions) {\n return;\n }\n\n const resolvedValue = JSON.stringify(this.resolveValue(value));\n\n this.store.setItem(this.key, resolvedValue);\n }\n}\n"],"mappings":";;;;AAqBA,MAAM,2BACN;AACA,MAAa,sBAAsB;;;;AAKnC,SAAS,0BAA0B,QAA0B;AAC3D,KAAI,CAAC,UAAU,OAAO,WAAW,SAC/B,QAAO;CAGT,MAAM,YAAY,MAAM,QAAQ,OAAO,GAAG,CAAC,GAAG,OAAO,GAAG,EAAE,GAAG,QAAQ;AAGrE,MAAK,MAAM,CAAC,SAAS,cAAc,OAAO,QAAQ,UAAU,EAAE;AAC5D,MACE,CAAC,aACD,OAAO,cAAc,YACrB,EAAE,YAAY,cACd,OAAO,UAAU,WAAW,SAE5B;EAGF,MAAM,SAAS,EAAE,GAAI,UAAU,QAAoC;EACnE,IAAI,aAAa;AAGjB,OAAK,MAAM,CAAC,WAAW,eAAe,OAAO,QAAQ,OAAO,EAAE;AAC5D,OACE,CAAC,cACD,OAAO,eAAe,YACtB,EAAE,UAAU,eACZ,EAAE,kBAAkB,YAEpB;AAIF,OACE,WAAW,SAAS,UACpB,OAAO,WAAW,iBAAiB,UACnC;IAEA,MAAM,YAAY,IAAI,KAAK,WAAW,aAAa;AAGnD,QAAI,CAAC,OAAO,MAAM,UAAU,SAAS,CAAC,EAAE;AACtC,YAAO,aAAa;MAClB,GAAG;MACH,cAAc;MACf;AACD,kBAAa;;;;AAMnB,MAAI,WACF,CAAC,UAAsC,WAAW;GAChD,GAA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AM,CAAC;AAE9D,OAAK,MAAM,QAAQ,KAAK,KAAK,cAAc"}
|
package/dist/storage.d.cts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import { Updater } from "./
|
|
1
|
+
import { Updater } from "./utils/types.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/storage.d.ts
|
|
4
4
|
type DefaultStorageKey = typeof DEFAULT_STORAGE_KEY;
|
|
5
|
-
|
|
5
|
+
interface BaseStorageConfig<TKey extends string> {
|
|
6
6
|
key: TKey;
|
|
7
|
-
data: TData;
|
|
8
7
|
store?: Storage;
|
|
9
8
|
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
* An extra option to throw an error when {@linkcode window} is `undefined`
|
|
10
|
+
* @default false
|
|
11
|
+
*/
|
|
13
12
|
throwWhenUndefined?: boolean;
|
|
13
|
+
}
|
|
14
|
+
type StorageConfig<TData, TKey extends string> = BaseStorageConfig<TKey> & {
|
|
15
|
+
data: TData;
|
|
14
16
|
};
|
|
15
17
|
declare const DEFAULT_STORAGE_KEY = "MultiStepForm";
|
|
16
18
|
declare class MultiStepFormStorage<data, key extends string = DefaultStorageKey> {
|
|
@@ -29,5 +31,5 @@ declare class MultiStepFormStorage<data, key extends string = DefaultStorageKey>
|
|
|
29
31
|
add(value: Updater<data>): void;
|
|
30
32
|
}
|
|
31
33
|
//#endregion
|
|
32
|
-
export { DEFAULT_STORAGE_KEY, DefaultStorageKey, MultiStepFormStorage, StorageConfig };
|
|
34
|
+
export { BaseStorageConfig, DEFAULT_STORAGE_KEY, DefaultStorageKey, MultiStepFormStorage, StorageConfig };
|
|
33
35
|
//# sourceMappingURL=storage.d.cts.map
|
package/dist/storage.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.d.cts","names":[],"sources":["../src/storage.ts"],"sourcesContent":[],"mappings":";;;KAIY,iBAAA,UAA2B;
|
|
1
|
+
{"version":3,"file":"storage.d.cts","names":[],"sources":["../src/storage.ts"],"sourcesContent":[],"mappings":";;;KAIY,iBAAA,UAA2B;UACtB;EADL,GAAA,EAEL,IAFK;EACK,KAAA,CAAA,EAEP,OAFO;EASL;;;;EAIC,kBAAA,CAAA,EAAA,OAAA;AAKb;AAoEa,KA7ED,aA6EC,CAAA,KAAoB,EAAA,aAAA,MAAA,CAAA,GA1E7B,iBA0E6B,CA1EX,IA0EW,CAAA,GAAA;EAEZ,IAAA,EA3Eb,KA2Ea;CAEL;AACG,cAzEN,mBAAA,GAyEM,eAAA;AACF,cANJ,oBAMI,CAAA,IAAA,EAAA,YAAA,MAAA,GAJI,iBAIJ,CAAA,CAAA;EAKmB,SAAA,GAAA,EAPpB,GAOoB;EAAM,SAAA,KAAA,EANvB,OAMuB;EAApB,SAAA,IAAA,EALL,IAKK;EAqDjB,iBAAA,GAAA;EA2BgB,iBAAA,gBAAA;EAAR,iBAAA,kBAAA;EAAO,WAAA,CAAA,MAAA,EAhFE,aAgFF,CAhFgB,IAgFhB,EAhFsB,GAgFtB,CAAA;;;;SA3Bf;;aA2BQ,QAAQ"}
|
package/dist/storage.d.mts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import { Updater } from "./
|
|
1
|
+
import { Updater } from "./utils/types.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/storage.d.ts
|
|
4
4
|
type DefaultStorageKey = typeof DEFAULT_STORAGE_KEY;
|
|
5
|
-
|
|
5
|
+
interface BaseStorageConfig<TKey extends string> {
|
|
6
6
|
key: TKey;
|
|
7
|
-
data: TData;
|
|
8
7
|
store?: Storage;
|
|
9
8
|
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
* An extra option to throw an error when {@linkcode window} is `undefined`
|
|
10
|
+
* @default false
|
|
11
|
+
*/
|
|
13
12
|
throwWhenUndefined?: boolean;
|
|
13
|
+
}
|
|
14
|
+
type StorageConfig<TData, TKey extends string> = BaseStorageConfig<TKey> & {
|
|
15
|
+
data: TData;
|
|
14
16
|
};
|
|
15
17
|
declare const DEFAULT_STORAGE_KEY = "MultiStepForm";
|
|
16
18
|
declare class MultiStepFormStorage<data, key extends string = DefaultStorageKey> {
|
|
@@ -29,5 +31,5 @@ declare class MultiStepFormStorage<data, key extends string = DefaultStorageKey>
|
|
|
29
31
|
add(value: Updater<data>): void;
|
|
30
32
|
}
|
|
31
33
|
//#endregion
|
|
32
|
-
export { DEFAULT_STORAGE_KEY, DefaultStorageKey, MultiStepFormStorage, StorageConfig };
|
|
34
|
+
export { BaseStorageConfig, DEFAULT_STORAGE_KEY, DefaultStorageKey, MultiStepFormStorage, StorageConfig };
|
|
33
35
|
//# sourceMappingURL=storage.d.mts.map
|
package/dist/storage.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.d.mts","names":[],"sources":["../src/storage.ts"],"sourcesContent":[],"mappings":";;;KAIY,iBAAA,UAA2B;
|
|
1
|
+
{"version":3,"file":"storage.d.mts","names":[],"sources":["../src/storage.ts"],"sourcesContent":[],"mappings":";;;KAIY,iBAAA,UAA2B;UACtB;EADL,GAAA,EAEL,IAFK;EACK,KAAA,CAAA,EAEP,OAFO;EASL;;;;EAIC,kBAAA,CAAA,EAAA,OAAA;AAKb;AAoEa,KA7ED,aA6EC,CAAA,KAAoB,EAAA,aAAA,MAAA,CAAA,GA1E7B,iBA0E6B,CA1EX,IA0EW,CAAA,GAAA;EAEZ,IAAA,EA3Eb,KA2Ea;CAEL;AACG,cAzEN,mBAAA,GAyEM,eAAA;AACF,cANJ,oBAMI,CAAA,IAAA,EAAA,YAAA,MAAA,GAJI,iBAIJ,CAAA,CAAA;EAKmB,SAAA,GAAA,EAPpB,GAOoB;EAAM,SAAA,KAAA,EANvB,OAMuB;EAApB,SAAA,IAAA,EALL,IAKK;EAqDjB,iBAAA,GAAA;EA2BgB,iBAAA,gBAAA;EAAR,iBAAA,kBAAA;EAAO,WAAA,CAAA,MAAA,EAhFE,aAgFF,CAhFgB,IAgFhB,EAhFsB,GAgFtB,CAAA;;;;SA3Bf;;aA2BQ,QAAQ"}
|
package/dist/storage.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { invariant } from "./utils/invariant.mjs";
|
|
2
1
|
import { MultiStepFormLogger } from "./utils/logger.mjs";
|
|
2
|
+
import { invariant } from "./utils/invariant.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/storage.ts
|
|
5
5
|
const WINDOW_UNDEFINED_MESSAGE = "\"window\" in undefined. No storage is available";
|