validup 0.5.0 → 1.0.0
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/README.md +58 -12
- package/dist/index.d.mts +410 -47
- package/dist/index.mjs +571 -266
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { BaseError, interpolate } from "@ebec/core";
|
|
2
2
|
import { Path } from "pathtrace";
|
|
3
|
-
|
|
4
3
|
//#region src/cache/types.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* The three context fields that determine a cached validator's output.
|
|
@@ -109,24 +108,35 @@ declare class ResultCache implements IResultCache {
|
|
|
109
108
|
declare enum GroupKey {
|
|
110
109
|
WILDCARD = "*"
|
|
111
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Atomic vocabulary for `MountOptions.optionalValue`. Each atom matches
|
|
113
|
+
* exactly one runtime value (the exception is `FALSY`, which stays as a
|
|
114
|
+
* composite shortcut). Compose multiple atoms by passing an array:
|
|
115
|
+
* `optionalValue: ['undefined', 'null', 'empty_string']`.
|
|
116
|
+
*/
|
|
112
117
|
declare enum OptionalValue {
|
|
113
118
|
/**
|
|
114
|
-
*
|
|
119
|
+
* `value === undefined`. **Default** when `optionalValue` is not set,
|
|
120
|
+
* so the core stays conservative — `0` / `''` / `false` are real
|
|
121
|
+
* values and reach the validator unless the caller opts in.
|
|
115
122
|
*/
|
|
116
123
|
UNDEFINED = "undefined",
|
|
117
|
-
/**
|
|
118
|
-
* Treats `null` and `undefined` as optional.
|
|
119
|
-
*/
|
|
124
|
+
/** `value === null` (does **not** include `undefined`). */
|
|
120
125
|
NULL = "null",
|
|
121
|
-
/**
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
126
|
+
/** `value === ''`. */
|
|
127
|
+
EMPTY_STRING = "empty_string",
|
|
128
|
+
/** `value === 0` (also matches `-0`). */
|
|
129
|
+
ZERO = "zero",
|
|
130
|
+
/** `value === false`. */
|
|
131
|
+
FALSE = "false",
|
|
132
|
+
/** `Number.isNaN(value)`. */
|
|
133
|
+
NAN = "nan",
|
|
134
|
+
/**
|
|
135
|
+
* Composite shortcut — any JS falsy value
|
|
136
|
+
* (`undefined`, `null`, `''`, `0`, `false`, `NaN`). Use when you
|
|
137
|
+
* really mean "any of the JS falsy sentinels"; otherwise pick
|
|
138
|
+
* specific atoms (or compose an array) so a `0` / `false` / `''`
|
|
139
|
+
* with a meaningful semantic isn't silently swallowed.
|
|
130
140
|
*/
|
|
131
141
|
FALSY = "falsy"
|
|
132
142
|
}
|
|
@@ -165,32 +175,53 @@ declare enum OptionalValue {
|
|
|
165
175
|
* placeholders being present (`{{min}}`, `{{max}}`, `{{other}}`, etc.).
|
|
166
176
|
*/
|
|
167
177
|
declare const IssueCode: {
|
|
168
|
-
/** Generic fallback when no more-specific code applies. `data`: — */
|
|
169
|
-
readonly
|
|
170
|
-
|
|
171
|
-
readonly
|
|
172
|
-
|
|
173
|
-
readonly
|
|
174
|
-
|
|
175
|
-
readonly
|
|
176
|
-
|
|
177
|
-
readonly
|
|
178
|
-
|
|
179
|
-
readonly
|
|
180
|
-
|
|
181
|
-
readonly
|
|
182
|
-
|
|
183
|
-
readonly
|
|
184
|
-
|
|
185
|
-
readonly
|
|
178
|
+
/** Generic fallback when no more-specific code applies. `data`: — */
|
|
179
|
+
readonly VALUE_INVALID: "value_invalid";
|
|
180
|
+
/** Every branch of a `oneOf` container failed. `data`: — */
|
|
181
|
+
readonly ONE_OF_FAILED: "one_of_failed";
|
|
182
|
+
/** Value is missing, `undefined`, `null`, or empty per the validator's semantics. `data`: — */
|
|
183
|
+
readonly REQUIRED: "required";
|
|
184
|
+
/** Value contains characters outside the alphabetical set. `data`: — */
|
|
185
|
+
readonly ALPHA: "alpha";
|
|
186
|
+
/** Value contains characters outside the alphanumeric set. `data`: — */
|
|
187
|
+
readonly ALPHA_NUM: "alpha_num";
|
|
188
|
+
/** Value is not a number. `data`: — */
|
|
189
|
+
readonly NUMERIC: "numeric";
|
|
190
|
+
/** Value is not an integer. `data`: — */
|
|
191
|
+
readonly INTEGER: "integer";
|
|
192
|
+
/** Value is not a decimal number. `data`: — */
|
|
193
|
+
readonly DECIMAL: "decimal";
|
|
194
|
+
/** Value is shorter than the configured minimum. `data`: `{ min: number }` */
|
|
195
|
+
readonly MIN_LENGTH: "min_length";
|
|
196
|
+
/** Value is longer than the configured maximum. `data`: `{ max: number }` */
|
|
197
|
+
readonly MAX_LENGTH: "max_length";
|
|
198
|
+
/** Numeric value is below the configured minimum. `data`: `{ min: number }` */
|
|
199
|
+
readonly MIN_VALUE: "min_value";
|
|
200
|
+
/** Numeric value is above the configured maximum. `data`: `{ max: number }` */
|
|
201
|
+
readonly MAX_VALUE: "max_value";
|
|
202
|
+
/** Numeric value falls outside the configured `[min, max]` range. `data`: `{ min: number, max: number }` */
|
|
203
|
+
readonly BETWEEN: "between";
|
|
204
|
+
/** Value is not a valid email address. `data`: — */
|
|
205
|
+
readonly EMAIL: "email";
|
|
206
|
+
/** Value is not a valid URL. `data`: — */
|
|
207
|
+
readonly URL: "url";
|
|
208
|
+
/** Value is not a valid IP address. `data`: — */
|
|
209
|
+
readonly IP_ADDRESS: "ip_address";
|
|
210
|
+
/** Value is not a valid MAC address. `data`: — */
|
|
211
|
+
readonly MAC_ADDRESS: "mac_address";
|
|
212
|
+
/** Value is not a valid UUID. `data`: — */
|
|
213
|
+
readonly UUID: "uuid";
|
|
214
|
+
/** Value is not a valid date / cannot be parsed as a date. `data`: — */
|
|
186
215
|
readonly DATE: "date";
|
|
187
216
|
/**
|
|
188
217
|
* Value does not match the expected regex pattern. `data`:
|
|
189
218
|
* `{ pattern: string }` — source of the regex without flags so
|
|
190
219
|
* catalogs can quote it in human-readable form.
|
|
191
220
|
*/
|
|
192
|
-
readonly PATTERN: "pattern";
|
|
193
|
-
|
|
221
|
+
readonly PATTERN: "pattern";
|
|
222
|
+
/** Value is not valid JSON. `data`: — */
|
|
223
|
+
readonly JSON: "json";
|
|
224
|
+
/** Value is not valid base64. `data`: — */
|
|
194
225
|
readonly BASE64: "base64";
|
|
195
226
|
/**
|
|
196
227
|
* Value does not meet the configured strong-password rules. `data`:
|
|
@@ -386,7 +417,7 @@ interface IssueItemCommon extends IssueBase {
|
|
|
386
417
|
type IssueItemTyped = { [K in ParameterizedIssueCode]: IssueItemCommon & {
|
|
387
418
|
code: K;
|
|
388
419
|
data: IssueDataByCode[K];
|
|
389
|
-
} }[ParameterizedIssueCode];
|
|
420
|
+
}; }[ParameterizedIssueCode];
|
|
390
421
|
/**
|
|
391
422
|
* Bare-data branch — one variant per `BareIssueCode`. `data` must be
|
|
392
423
|
* absent (or explicitly `undefined`).
|
|
@@ -398,7 +429,7 @@ type IssueItemTyped = { [K in ParameterizedIssueCode]: IssueItemCommon & {
|
|
|
398
429
|
type IssueItemBare = { [K in BareIssueCode]: IssueItemCommon & {
|
|
399
430
|
code: K;
|
|
400
431
|
data?: undefined;
|
|
401
|
-
} }[BareIssueCode];
|
|
432
|
+
}; }[BareIssueCode];
|
|
402
433
|
/**
|
|
403
434
|
* Escape-hatch branch — ad-hoc / project-specific codes outside the
|
|
404
435
|
* shipped vocabulary. `code: string & {}` keeps autocomplete on the
|
|
@@ -691,6 +722,52 @@ type ContainerOptions<T> = {
|
|
|
691
722
|
* be considered for execution.
|
|
692
723
|
*/
|
|
693
724
|
pathsToExclude?: Path<T>[];
|
|
725
|
+
/**
|
|
726
|
+
* Fail loud when a `pathsToInclude` / `pathsToExclude` entry matches no
|
|
727
|
+
* mount. By default, an include/exclude path that addresses nothing is
|
|
728
|
+
* silently ignored (the run just executes fewer mounts) — so if a shared
|
|
729
|
+
* validator renames a mounted key out from under a caller's static path
|
|
730
|
+
* list, the scoped validation for that field silently disappears instead
|
|
731
|
+
* of failing.
|
|
732
|
+
*
|
|
733
|
+
* With `pathsStrict: true`, each container verifies — before running any
|
|
734
|
+
* validator — that every include/exclude entry is satisfied locally
|
|
735
|
+
* (exact key match, or prefix descent into a container mount). Any entry
|
|
736
|
+
* that isn't throws a structural {@link PathsStrictViolationError} listing
|
|
737
|
+
* the unmatched (absolute) paths. Nested containers self-check the
|
|
738
|
+
* forwarded remainder because the flag threads into child `run()` calls
|
|
739
|
+
* alongside the already-stripped filter lists.
|
|
740
|
+
*
|
|
741
|
+
* Group filtering stays orthogonal — a mount excluded from the active
|
|
742
|
+
* group still counts as "existing", so a valid path targeting it does not
|
|
743
|
+
* trip strict mode.
|
|
744
|
+
*
|
|
745
|
+
* Precedence: `ContainerRunOptions.pathsStrict` (per-run) wins over
|
|
746
|
+
* `ContainerOptions.pathsStrict` (container-wide).
|
|
747
|
+
*
|
|
748
|
+
* default: false
|
|
749
|
+
*/
|
|
750
|
+
pathsStrict?: boolean;
|
|
751
|
+
/**
|
|
752
|
+
* Container-wide default for `MountOptions.optionalValue`. Applied
|
|
753
|
+
* to mounts in this container that declare `optional: true` (or a
|
|
754
|
+
* truthy predicate) without setting their own `optionalValue`.
|
|
755
|
+
*
|
|
756
|
+
* Precedence (highest → lowest): `MountOptions` → `ContainerRunOptions`
|
|
757
|
+
* → `ContainerOptions` → core default (`'undefined'`).
|
|
758
|
+
*/
|
|
759
|
+
optionalValue?: `${OptionalValue}` | readonly `${OptionalValue}`[];
|
|
760
|
+
/**
|
|
761
|
+
* Container-wide default for `MountOptions.optionalAs`. Applied to
|
|
762
|
+
* mounts in this container that qualify as optional without setting
|
|
763
|
+
* their own `optionalAs`. Presence (not value) activates the
|
|
764
|
+
* directive — `{ optionalAs: undefined }` means "emit `undefined`",
|
|
765
|
+
* which differs from omitting the option.
|
|
766
|
+
*
|
|
767
|
+
* Precedence (highest → lowest): `MountOptions` → `ContainerRunOptions`
|
|
768
|
+
* → `ContainerOptions`.
|
|
769
|
+
*/
|
|
770
|
+
optionalAs?: unknown;
|
|
694
771
|
};
|
|
695
772
|
type ContainerRunOptions<T extends Record<string, any> = Record<string, any>, C = unknown> = {
|
|
696
773
|
/**
|
|
@@ -698,7 +775,7 @@ type ContainerRunOptions<T extends Record<string, any> = Record<string, any>, C
|
|
|
698
775
|
* only the paths you want to backfill. When the validated output is missing
|
|
699
776
|
* a key (or holds `undefined`), the matching entry from `defaults` is used.
|
|
700
777
|
*/
|
|
701
|
-
defaults?: { [Key in Path<T>]?: any };
|
|
778
|
+
defaults?: { [Key in Path<T>]?: any; };
|
|
702
779
|
/**
|
|
703
780
|
* Group to execute.
|
|
704
781
|
*/
|
|
@@ -723,6 +800,15 @@ type ContainerRunOptions<T extends Record<string, any> = Record<string, any>, C
|
|
|
723
800
|
* be considered for execution.
|
|
724
801
|
*/
|
|
725
802
|
pathsToExclude?: Path<T>[];
|
|
803
|
+
/**
|
|
804
|
+
* Fail loud when a `pathsToInclude` / `pathsToExclude` entry matches no
|
|
805
|
+
* mount. Per-run counterpart of `ContainerOptions.pathsStrict` (and wins
|
|
806
|
+
* over it). See that field for the full semantics. Forwarded unchanged
|
|
807
|
+
* into nested container `run()` calls so the entire tree is checked.
|
|
808
|
+
*
|
|
809
|
+
* default: false
|
|
810
|
+
*/
|
|
811
|
+
pathsStrict?: boolean;
|
|
726
812
|
/**
|
|
727
813
|
* Caller-supplied context surfaced on `ValidatorContext.context`. Forwarded
|
|
728
814
|
* unchanged into nested container `run()` calls so the entire tree shares
|
|
@@ -770,6 +856,42 @@ type ContainerRunOptions<T extends Record<string, any> = Record<string, any>, C
|
|
|
770
856
|
* runs every time, regardless of any `sideEffect` declaration.
|
|
771
857
|
*/
|
|
772
858
|
cache?: IResultCache;
|
|
859
|
+
/**
|
|
860
|
+
* Run-level fallback for `MountOptions.optionalValue`. When a mount
|
|
861
|
+
* declares `optional: true` but does NOT set its own `optionalValue`,
|
|
862
|
+
* this value decides what counts as "absent". Per-mount setting
|
|
863
|
+
* wins; this is only the fallback.
|
|
864
|
+
*
|
|
865
|
+
* Predicate-form `optional: (value) => boolean` does not consult
|
|
866
|
+
* `optionalValue` at all — the predicate decides directly.
|
|
867
|
+
*
|
|
868
|
+
* Forwarded into nested container `run()` calls so the entire
|
|
869
|
+
* sub-tree shares the same default unless a child mount overrides.
|
|
870
|
+
*
|
|
871
|
+
* Hosts that know their idiom set this once — e.g. an app using
|
|
872
|
+
* `@validup/vue` can `app.use(createValidup({ optionalValue:
|
|
873
|
+
* ['undefined', 'empty_string'] }))` to make untouched `<input>`
|
|
874
|
+
* fields (`v-model` holds `''`) count as missing across every form.
|
|
875
|
+
* Server / CLI callers typically leave it unset and let the
|
|
876
|
+
* conservative core default (`'undefined'`) apply.
|
|
877
|
+
*
|
|
878
|
+
* Precedence (highest → lowest): `MountOptions` → `ContainerRunOptions`
|
|
879
|
+
* → `ContainerOptions` → core default.
|
|
880
|
+
*/
|
|
881
|
+
optionalValue?: `${OptionalValue}` | readonly `${OptionalValue}`[];
|
|
882
|
+
/**
|
|
883
|
+
* Run-level fallback for `MountOptions.optionalAs`. When a mount
|
|
884
|
+
* qualifies as optional without setting its own `optionalAs`, this
|
|
885
|
+
* value is written to the output. Presence (not value) activates
|
|
886
|
+
* the directive — `{ optionalAs: undefined }` is meaningful
|
|
887
|
+
* ("emit `undefined`") and differs from omitting the option.
|
|
888
|
+
*
|
|
889
|
+
* Forwarded into nested container `run()` calls.
|
|
890
|
+
*
|
|
891
|
+
* Precedence (highest → lowest): `MountOptions` → `ContainerRunOptions`
|
|
892
|
+
* → `ContainerOptions`.
|
|
893
|
+
*/
|
|
894
|
+
optionalAs?: unknown;
|
|
773
895
|
};
|
|
774
896
|
type MountOptions = {
|
|
775
897
|
/**
|
|
@@ -788,18 +910,50 @@ type MountOptions = {
|
|
|
788
910
|
*/
|
|
789
911
|
optional?: boolean | ((value: unknown) => boolean);
|
|
790
912
|
/**
|
|
791
|
-
* Which values are considered optional.
|
|
792
|
-
*
|
|
913
|
+
* Which values are considered optional. Pass a single atom
|
|
914
|
+
* (`'undefined'` / `'null'` / `'empty_string'` / `'zero'` / `'false'`
|
|
915
|
+
* / `'nan'`) for a one-value match, the composite shortcut `'falsy'`
|
|
916
|
+
* for any JS falsy value, or an array of atoms to compose a custom
|
|
917
|
+
* set (e.g. `['undefined', 'null', 'empty_string']` for the common
|
|
918
|
+
* "missing or blank" intent).
|
|
919
|
+
*
|
|
920
|
+
* Atoms match exactly one runtime value — `'null'` does NOT also
|
|
921
|
+
* include `undefined`. Pass `['null', 'undefined']` explicitly when
|
|
922
|
+
* both should qualify.
|
|
793
923
|
*
|
|
794
924
|
* default: 'undefined'
|
|
795
925
|
*/
|
|
796
|
-
optionalValue?: `${OptionalValue}
|
|
926
|
+
optionalValue?: `${OptionalValue}` | readonly `${OptionalValue}`[];
|
|
797
927
|
/**
|
|
798
928
|
* Include optional value as property in output.
|
|
799
929
|
*
|
|
800
930
|
* default: false
|
|
801
931
|
*/
|
|
802
932
|
optionalInclude?: boolean;
|
|
933
|
+
/**
|
|
934
|
+
* Canonical value written to the output when the mount qualifies
|
|
935
|
+
* as optional. Useful for normalizing multiple "missing" sentinels
|
|
936
|
+
* (`undefined` / `null` / `''`) into a single shape the consumer
|
|
937
|
+
* expects (e.g. always `null` when posting to a backend).
|
|
938
|
+
*
|
|
939
|
+
* When set, the runtime ignores `optionalInclude` and writes
|
|
940
|
+
* `optionalAs` regardless of the input value. Property presence
|
|
941
|
+
* matters (not "is undefined"): `{ optionalAs: undefined }` is a
|
|
942
|
+
* meaningful directive ("emit `undefined` for this key") and
|
|
943
|
+
* differs from omitting the option entirely.
|
|
944
|
+
*
|
|
945
|
+
* @example
|
|
946
|
+
* container.mount('description', {
|
|
947
|
+
* optional: true,
|
|
948
|
+
* optionalValue: ['undefined', 'null', 'empty_string'],
|
|
949
|
+
* optionalAs: null,
|
|
950
|
+
* }, isString);
|
|
951
|
+
*
|
|
952
|
+
* await container.run({ description: '' }); // → { description: null }
|
|
953
|
+
* await container.run({ description: undefined }); // → { description: null }
|
|
954
|
+
* await container.run({ description: null }); // → { description: null }
|
|
955
|
+
*/
|
|
956
|
+
optionalAs?: unknown;
|
|
803
957
|
};
|
|
804
958
|
type ResultSuccess<T> = {
|
|
805
959
|
success: true;
|
|
@@ -1165,13 +1319,22 @@ type BuildOneOfFailedGroupOptions = {
|
|
|
1165
1319
|
declare function buildOneOfFailedGroup(branchIssues: Issue[], options?: BuildOneOfFailedGroupOptions): IssueGroup;
|
|
1166
1320
|
//#endregion
|
|
1167
1321
|
//#region src/helpers/optional-value.d.ts
|
|
1322
|
+
type OptionalValueInput = `${OptionalValue}` | readonly `${OptionalValue}`[];
|
|
1168
1323
|
/**
|
|
1169
|
-
* Check
|
|
1324
|
+
* Check whether `value` qualifies as "optional" under the supplied
|
|
1325
|
+
* `optionalValue` definition.
|
|
1326
|
+
*
|
|
1327
|
+
* The definition can be a single atom (`'undefined'`, `'null'`, `'empty_string'`,
|
|
1328
|
+
* `'zero'`, `'false'`, `'nan'`, `'falsy'`) or an array of atoms — in array form
|
|
1329
|
+
* the value is optional iff **any** atom matches. Atoms match exactly one
|
|
1330
|
+
* runtime value (the only exception is `'falsy'`, which stays as a composite
|
|
1331
|
+
* shortcut for "any JS falsy value"). To skip on `null` *or* `undefined`,
|
|
1332
|
+
* pass `['null', 'undefined']` explicitly.
|
|
1170
1333
|
*
|
|
1171
|
-
*
|
|
1172
|
-
*
|
|
1334
|
+
* Default is `'undefined'` so the core stays conservative — `0` / `''` /
|
|
1335
|
+
* `false` reach the validator unless the caller explicitly opts in.
|
|
1173
1336
|
*/
|
|
1174
|
-
declare function isOptionalValue(value: unknown, optionalValue?:
|
|
1337
|
+
declare function isOptionalValue(value: unknown, optionalValue?: OptionalValueInput): boolean;
|
|
1175
1338
|
//#endregion
|
|
1176
1339
|
//#region src/helpers/path-filter.d.ts
|
|
1177
1340
|
type PathFilterResolution = {
|
|
@@ -1244,12 +1407,65 @@ declare class Container<T extends Record<string, any> = Record<string, any>, C =
|
|
|
1244
1407
|
* already-aborted run — re-raised as-is rather than wrapped.
|
|
1245
1408
|
*/
|
|
1246
1409
|
run(data?: ContainerInput<T>, options?: ContainerRunOptions<T, C>): Promise<T>;
|
|
1410
|
+
/**
|
|
1411
|
+
* The single mount-resolution loop behind {@link Container.run} and
|
|
1412
|
+
* {@link Container.runSync}.
|
|
1413
|
+
*
|
|
1414
|
+
* Written as a **twin body** (the `twinop` package): the two impure edges,
|
|
1415
|
+
* invoking a validator and descending into a nested container, are yielded
|
|
1416
|
+
* as `op(asyncThunk, syncThunk)` pairs, and the driver chosen by the public
|
|
1417
|
+
* method (`runTwinAsync` / `runTwinSync`) executes the matching side. Effect
|
|
1418
|
+
* errors are thrown back in at the `yield` site, so the cache-write and
|
|
1419
|
+
* issue-collection `try`/`catch` blocks below run identically in both
|
|
1420
|
+
* variants, with no second copy of the loop to keep in lockstep.
|
|
1421
|
+
*
|
|
1422
|
+
* The sync thunks own the two structural probes that only `runSync` needs:
|
|
1423
|
+
* a nested container that doesn't implement `runSync`, and a validator that
|
|
1424
|
+
* returned a thenable. Both throw `RunSyncViolationError`, which the async
|
|
1425
|
+
* side cannot produce.
|
|
1426
|
+
*
|
|
1427
|
+
* `runParallel` deliberately does NOT share this body — a generator is
|
|
1428
|
+
* sequential by construction, and expressing "launch every mount, then
|
|
1429
|
+
* settle" through it would mean yielding batches and giving up the
|
|
1430
|
+
* chain-read. It shares the extracted per-key helpers instead
|
|
1431
|
+
* (`prepareMountKey` / `resolveOptionalDirective` / `buildChildRunOptions` /
|
|
1432
|
+
* `buildValidatorContext`).
|
|
1433
|
+
*/
|
|
1434
|
+
private runBody;
|
|
1247
1435
|
/**
|
|
1248
1436
|
* Parallel-execution variant of `run()`. All mounts kick off their
|
|
1249
1437
|
* promises eagerly and the results are merged after `Promise.allSettled`.
|
|
1250
1438
|
* See `ContainerRunOptions.parallel` for the trade-off note.
|
|
1439
|
+
*
|
|
1440
|
+
* Shares every per-key helper with the sequential twin body
|
|
1441
|
+
* (`prepareMountKey` / `resolveOptionalDirective` / `buildChildRunOptions` /
|
|
1442
|
+
* `buildValidatorContext` / the cache pair) but keeps its own scheduling
|
|
1443
|
+
* loop — see the note on {@link Container.runBody} for why it can't be a
|
|
1444
|
+
* third twin driver.
|
|
1251
1445
|
*/
|
|
1252
1446
|
private runParallel;
|
|
1447
|
+
/**
|
|
1448
|
+
* Claim ownership of a scheduled mount's rejection.
|
|
1449
|
+
*
|
|
1450
|
+
* `runParallel` creates every mount's promise eagerly and only attaches
|
|
1451
|
+
* `Promise.allSettled` after the whole scheduling loop has run. Any
|
|
1452
|
+
* rejection settling in that window — or, worse, any throw that escapes
|
|
1453
|
+
* the loop before `allSettled` is reached at all — is unowned, and Node's
|
|
1454
|
+
* default `--unhandled-rejections=throw` (this package requires Node >=
|
|
1455
|
+
* 24) terminates the process.
|
|
1456
|
+
*
|
|
1457
|
+
* The no-op subscriber below is a *second* consumer, discarded
|
|
1458
|
+
* immediately; the original promise is returned unchanged, so
|
|
1459
|
+
* `Promise.allSettled` still observes the real settlement and no outcome
|
|
1460
|
+
* is swallowed.
|
|
1461
|
+
*/
|
|
1462
|
+
private ownRejection;
|
|
1463
|
+
/**
|
|
1464
|
+
* Create the in-flight promise for one scheduled mount. Extracted from
|
|
1465
|
+
* `runParallel`'s scheduling loop so the loop body reads as
|
|
1466
|
+
* "resolve, gate, dispatch" and the pre-dispatch `try` stays legible.
|
|
1467
|
+
*/
|
|
1468
|
+
private dispatchParallelMount;
|
|
1253
1469
|
safeRun(input?: ContainerInput<T>, options?: ContainerRunOptions<T, C>): Promise<Result<T>>;
|
|
1254
1470
|
/**
|
|
1255
1471
|
* Synchronous variant of {@link Container.run}. Use it for purely
|
|
@@ -1282,6 +1498,76 @@ declare class Container<T extends Record<string, any> = Record<string, any>, C =
|
|
|
1282
1498
|
*/
|
|
1283
1499
|
runSync(data?: ContainerInput<T>, options?: ContainerRunOptions<T, C>): T;
|
|
1284
1500
|
safeRunSync(input?: ContainerInput<T>, options?: ContainerRunOptions<T, C>): Result<T>;
|
|
1501
|
+
/**
|
|
1502
|
+
* Resolve everything a single `(mount, expanded key)` pair needs before
|
|
1503
|
+
* dispatch: the split path parts, the absolute path handed to validators
|
|
1504
|
+
* and child containers, and the include/exclude verdict.
|
|
1505
|
+
*
|
|
1506
|
+
* Shared verbatim by the twin body and `runParallel`. The mount's input
|
|
1507
|
+
* `value` is deliberately NOT read here — see {@link MountKeyPlan}.
|
|
1508
|
+
*/
|
|
1509
|
+
private prepareMountKey;
|
|
1510
|
+
/**
|
|
1511
|
+
* Resolve the optional gate and — when it fires — what (if anything) the
|
|
1512
|
+
* skipped key contributes to the output.
|
|
1513
|
+
*
|
|
1514
|
+
* `optional` is the gate ("may this mount be skipped?"); `optionalValue` is
|
|
1515
|
+
* the definition of absent, resolved mount → run → container. A predicate
|
|
1516
|
+
* `optional` wins over the atom vocabulary entirely.
|
|
1517
|
+
*
|
|
1518
|
+
* The write directive follows the same three layers, but keys off
|
|
1519
|
+
* `optionalAs` **presence** rather than its value — `{ optionalAs:
|
|
1520
|
+
* undefined }` at any layer is a deliberate "emit `undefined`". Only when
|
|
1521
|
+
* no layer declares `optionalAs` does the mount-level `optionalInclude`
|
|
1522
|
+
* fallback (copy the input through) apply.
|
|
1523
|
+
*/
|
|
1524
|
+
private resolveOptionalDirective;
|
|
1525
|
+
/**
|
|
1526
|
+
* Re-resolve a mount's `optional` declaration for the `meta.optional`
|
|
1527
|
+
* stamp applied by {@link Container.collectExecutionFailure}.
|
|
1528
|
+
*
|
|
1529
|
+
* Split out from `resolveOptionalDirective` because the two calls answer
|
|
1530
|
+
* different questions at different times: the directive decides whether to
|
|
1531
|
+
* *run* the mount, this decides whether to *tag* the mount's issues. The
|
|
1532
|
+
* split is what lets this one contain a throw the gate cannot.
|
|
1533
|
+
*
|
|
1534
|
+
* A predicate that throws degrades to `false` (don't tag) rather than
|
|
1535
|
+
* propagating. This is load-bearing, not defensive: the caller is a
|
|
1536
|
+
* `catch` handler with no `try` above it inside the run loop, and the very
|
|
1537
|
+
* throw it is folding may be the predicate's own. Re-raising here escapes
|
|
1538
|
+
* the error path entirely, discarding **every issue collected so far** and
|
|
1539
|
+
* replacing them with one path-less item — so a mainstream idiom like
|
|
1540
|
+
* `optional: (v) => v.trim().length === 0` would, on the first absent
|
|
1541
|
+
* field, wipe out every other field's validation error.
|
|
1542
|
+
*
|
|
1543
|
+
* `false` is the conservative fallback: the mount's issues surface at full
|
|
1544
|
+
* severity instead of being downgraded to a warning by consumers such as
|
|
1545
|
+
* `@validup/vue`'s `getSeverity`. The predicate's failure is not swallowed
|
|
1546
|
+
* — it is already being folded into an issue by the caller.
|
|
1547
|
+
*/
|
|
1548
|
+
private resolveOptionalStamp;
|
|
1549
|
+
/**
|
|
1550
|
+
* Attribution fallback for a throw raised before a {@link MountKeyPlan}
|
|
1551
|
+
* exists — path expansion, key preparation, or the mount's value read.
|
|
1552
|
+
*
|
|
1553
|
+
* Produces the same `keyParts` / `pathRelative` pair `prepareMountKey`
|
|
1554
|
+
* would have, so a pre-dispatch failure is attributed to the mount that
|
|
1555
|
+
* caused it rather than surfacing path-less. For an item-level failure
|
|
1556
|
+
* (path expansion) the caller passes the *unexpanded* mount path, so a
|
|
1557
|
+
* glob mount is identified by its literal pattern (`items.*.name`) — the
|
|
1558
|
+
* keys it would have expanded to are precisely what could not be computed.
|
|
1559
|
+
*/
|
|
1560
|
+
private describeKey;
|
|
1561
|
+
/**
|
|
1562
|
+
* Build the option bag forwarded into a nested container's `run` /
|
|
1563
|
+
* `runSync`. Single source of truth for what a child inherits, so a new
|
|
1564
|
+
* run option is threaded downward in one place instead of three.
|
|
1565
|
+
*/
|
|
1566
|
+
private buildChildRunOptions;
|
|
1567
|
+
/**
|
|
1568
|
+
* Build the context object handed to a mounted validator.
|
|
1569
|
+
*/
|
|
1570
|
+
private buildValidatorContext;
|
|
1285
1571
|
/**
|
|
1286
1572
|
* Lookup helper for the per-mount result cache.
|
|
1287
1573
|
*
|
|
@@ -1313,6 +1599,38 @@ declare class Container<T extends Record<string, any> = Record<string, any>, C =
|
|
|
1313
1599
|
*/
|
|
1314
1600
|
private writeCachedOutcome;
|
|
1315
1601
|
private resolveContainerFilters;
|
|
1602
|
+
/**
|
|
1603
|
+
* Resolve the effective `pathsStrict` flag. Run-level wins over
|
|
1604
|
+
* container-level; unset anywhere is `false` (the silent, back-compatible
|
|
1605
|
+
* default).
|
|
1606
|
+
*/
|
|
1607
|
+
private resolvePathsStrict;
|
|
1608
|
+
/**
|
|
1609
|
+
* Structural pre-flight for `pathsStrict`. Verifies every resolved
|
|
1610
|
+
* `pathsToInclude` / `pathsToExclude` entry is satisfied by *this*
|
|
1611
|
+
* container — either an exact match against an expanded mount key, or a
|
|
1612
|
+
* prefix descent into a container mount (whose child re-checks the
|
|
1613
|
+
* forwarded remainder, since `pathsStrict` threads downward). Anything
|
|
1614
|
+
* unmatched throws {@link PathsStrictViolationError} with absolute paths.
|
|
1615
|
+
*
|
|
1616
|
+
* No-ops unless strict is on AND at least one filter list is present, so
|
|
1617
|
+
* the overhead on the common (non-strict) path is a single `??` chain.
|
|
1618
|
+
*
|
|
1619
|
+
* Notes on the match rules (kept in lockstep with `resolvePathFilter`):
|
|
1620
|
+
* - Keyless container mounts share the parent namespace and receive the
|
|
1621
|
+
* filter list verbatim, so a path could be owned by the keyless child
|
|
1622
|
+
* OR by a keyed sibling here — the parent can't tell without recursing.
|
|
1623
|
+
* To avoid false positives it treats every entry as satisfied when any
|
|
1624
|
+
* keyless container is present, and `pathsStrict` is NOT forwarded into
|
|
1625
|
+
* keyless children (that would throw for parent-sibling paths). Net:
|
|
1626
|
+
* keyless subtrees are a strict blind spot ("out of scope" per the issue).
|
|
1627
|
+
* - Group filtering is intentionally ignored: a mount excluded from the
|
|
1628
|
+
* active group still exists, so a path targeting it is not "stale".
|
|
1629
|
+
* - Expansion uses the same `expandPath(data, item.path)` the run loop
|
|
1630
|
+
* uses, so glob mounts are matched against the keys they actually
|
|
1631
|
+
* expand to for the given `data`.
|
|
1632
|
+
*/
|
|
1633
|
+
private assertPathsStrict;
|
|
1316
1634
|
/**
|
|
1317
1635
|
* Prepend `keyParts` to a child issue's `path` and — when the child is
|
|
1318
1636
|
* an `IssueGroup` — recurse into its nested issues so every leaf carries
|
|
@@ -1378,12 +1696,50 @@ declare class Container<T extends Record<string, any> = Record<string, any>, C =
|
|
|
1378
1696
|
protected initialize(): void;
|
|
1379
1697
|
}
|
|
1380
1698
|
//#endregion
|
|
1699
|
+
//#region src/container/paths-strict-violation.d.ts
|
|
1700
|
+
type PathsStrictViolationInput = {
|
|
1701
|
+
pathsToInclude?: string[];
|
|
1702
|
+
pathsToExclude?: string[];
|
|
1703
|
+
};
|
|
1704
|
+
/**
|
|
1705
|
+
* Thrown by a `Container` run (all variants) when `pathsStrict` is enabled and
|
|
1706
|
+
* one or more `pathsToInclude` / `pathsToExclude` entries matched **no mount** —
|
|
1707
|
+
* neither an exact key match nor a prefix descent into a container mount. It
|
|
1708
|
+
* signals a misconfigured validator graph (typically a mount key that was
|
|
1709
|
+
* renamed out from under a caller's static path list), NOT a validation failure
|
|
1710
|
+
* of the input.
|
|
1711
|
+
*
|
|
1712
|
+
* Like `RunSyncViolationError` it is structural, so the per-mount catch and
|
|
1713
|
+
* `safeRun` / `safeRunSync` re-throw it verbatim instead of folding it into the
|
|
1714
|
+
* issue list or a `Result.failure`. Unlike `RunSyncViolationError` it IS
|
|
1715
|
+
* exported from the package barrel — the whole point is that consumers catch it,
|
|
1716
|
+
* read `pathsToInclude` / `pathsToExclude`, and surface which paths went stale.
|
|
1717
|
+
*
|
|
1718
|
+
* The reported paths are **absolute** (prefixed with the owning container's
|
|
1719
|
+
* `path` when the violation happens inside a nested container), so a caller sees
|
|
1720
|
+
* `user.email` rather than the child-local `email`.
|
|
1721
|
+
*/
|
|
1722
|
+
declare class PathsStrictViolationError extends Error {
|
|
1723
|
+
readonly name = "PathsStrictViolationError";
|
|
1724
|
+
/** Absolute `pathsToInclude` entries that matched no mount. */
|
|
1725
|
+
readonly pathsToInclude: string[];
|
|
1726
|
+
/** Absolute `pathsToExclude` entries that matched no mount. */
|
|
1727
|
+
readonly pathsToExclude: string[];
|
|
1728
|
+
constructor(input: PathsStrictViolationInput);
|
|
1729
|
+
}
|
|
1730
|
+
/**
|
|
1731
|
+
* Duck-typed check — robust against `instanceof` mismatches when a duplicate
|
|
1732
|
+
* copy of the package exists in the dependency tree, or when the throw crosses
|
|
1733
|
+
* a realm boundary. Mirrors the `isValidupError` / `isRunSyncViolation` pattern.
|
|
1734
|
+
*/
|
|
1735
|
+
declare function isPathsStrictViolation(e: unknown): e is PathsStrictViolationError;
|
|
1736
|
+
//#endregion
|
|
1381
1737
|
//#region src/builder/types.d.ts
|
|
1382
1738
|
/**
|
|
1383
1739
|
* Cosmetic helper — flattens an intersection so editors render
|
|
1384
1740
|
* `{ foo: string; bar: number }` instead of `{ foo: string } & { bar: number }`.
|
|
1385
1741
|
*/
|
|
1386
|
-
type Spread<T> = { [K in keyof T]: T[K] };
|
|
1742
|
+
type Spread<T> = { [K in keyof T]: T[K]; };
|
|
1387
1743
|
/**
|
|
1388
1744
|
* Anything that can be mounted under a key on a `Builder`: a leaf validator,
|
|
1389
1745
|
* a nested builder (auto-`.build()`-ed), or an existing `Container`.
|
|
@@ -1411,7 +1767,7 @@ type IsOptional<O> = O extends {
|
|
|
1411
1767
|
* matching the runtime behavior that an optional mount may be skipped, leaving
|
|
1412
1768
|
* the key absent from the output.
|
|
1413
1769
|
*/
|
|
1414
|
-
type Mounted<K extends string, V, O> = V extends IBuilder<infer U, any> ? IsOptional<O> extends true ? { [P in K]?: U } : { [P in K]: U } : V extends IContainer<infer U, any> ? IsOptional<O> extends true ? { [P in K]?: U } : { [P in K]: U } : V extends Validator<any, infer Out> ? IsOptional<O> extends true ? { [P in K]?: Awaited<Out
|
|
1770
|
+
type Mounted<K extends string, V, O> = V extends IBuilder<infer U, any> ? IsOptional<O> extends true ? { [P in K]?: U; } : { [P in K]: U; } : V extends IContainer<infer U, any> ? IsOptional<O> extends true ? { [P in K]?: U; } : { [P in K]: U; } : V extends Validator<any, infer Out> ? IsOptional<O> extends true ? { [P in K]?: Awaited<Out>; } : { [P in K]: Awaited<Out>; } : never;
|
|
1415
1771
|
/**
|
|
1416
1772
|
* Compile-time-typed schema builder. `mount(...)` accumulates the resolved
|
|
1417
1773
|
* field type into `T`, so `build()` returns a `Container<T, C>` whose static
|
|
@@ -1442,6 +1798,12 @@ interface IBuilder<T extends Record<string, any>, C = unknown> {
|
|
|
1442
1798
|
pathsToInclude(...paths: (keyof T & string)[]): IBuilder<T, C>;
|
|
1443
1799
|
/** Restrict the resulting container's `pathsToExclude`. */
|
|
1444
1800
|
pathsToExclude(...paths: (keyof T & string)[]): IBuilder<T, C>;
|
|
1801
|
+
/**
|
|
1802
|
+
* Set the resulting container's `pathsStrict` flag (defaults to `true`) —
|
|
1803
|
+
* fail loud when a `pathsToInclude` / `pathsToExclude` entry matches no
|
|
1804
|
+
* mount.
|
|
1805
|
+
*/
|
|
1806
|
+
pathsStrict(strict?: boolean): IBuilder<T, C>;
|
|
1445
1807
|
/** Materialize a `Container<T, C>` and replay every accumulated mount. */
|
|
1446
1808
|
build(): Container<T, C>;
|
|
1447
1809
|
}
|
|
@@ -1468,6 +1830,7 @@ declare class Builder<T extends Record<string, any>, C> implements IBuilder<T, C
|
|
|
1468
1830
|
oneOf(): IBuilder<T, C>;
|
|
1469
1831
|
pathsToInclude(...paths: (keyof T & string)[]): IBuilder<T, C>;
|
|
1470
1832
|
pathsToExclude(...paths: (keyof T & string)[]): IBuilder<T, C>;
|
|
1833
|
+
pathsStrict(strict?: boolean): IBuilder<T, C>;
|
|
1471
1834
|
build(): Container<T, C>;
|
|
1472
1835
|
}
|
|
1473
1836
|
/**
|
|
@@ -1487,5 +1850,5 @@ declare function hasOwnProperty<X extends {}, Y extends PropertyKey>(obj: X, pro
|
|
|
1487
1850
|
//#region src/utils/object.d.ts
|
|
1488
1851
|
declare function isObject(input: unknown): input is Record<string, any>;
|
|
1489
1852
|
//#endregion
|
|
1490
|
-
export { BareIssueCode, BaseMount, BuildOneOfFailedGroupOptions, Builder, ComposeElement, ComposeOptions, Container, ContainerInput, ContainerMount, ContainerOptions, ContainerRunOptions, ErrorToIssuesOptions, GroupKey, IBuilder, IContainer, IResultCache, IsOptional, Issue, IssueBase, IssueCode, IssueDataByCode, IssueGroup, IssueItem, IssueItemBare, IssueItemRaw, IssueItemTyped, IssueMessageTemplates, Mount, MountOptions, MountTarget, Mounted, ObjectLiteral, OptionalValue, ParameterizedIssueCode, PathFilterResolution, ResolveIssueCode, Result, ResultCache, ResultCacheEntry, ResultCacheOutcome, ResultCacheSnapshot, ResultFailure, ResultSuccess, Spread, Validator, ValidatorContext, ValidatorDescriptor, ValidatorMount, ValidupError, buildErrorMessageForAttribute, buildErrorMessageForAttributes, buildOneOfFailedGroup, compose, composeOneOf, createValidupError, defineIssueGroup, defineIssueItem, defineSchema, defineValidator, errorToIssues, flattenIssueGroups, flattenIssueItems, formatIssue, hasOwnProperty, interpolate, isContainer, isError, isIssue, isIssueGroup, isIssueItem, isObject, isOptionalValue, isResultCache, isValidatorDescriptor, isValidupError, resolveDefaults, resolvePathFilter, stringifyPath };
|
|
1853
|
+
export { BareIssueCode, BaseMount, BuildOneOfFailedGroupOptions, Builder, ComposeElement, ComposeOptions, Container, ContainerInput, ContainerMount, ContainerOptions, ContainerRunOptions, ErrorToIssuesOptions, GroupKey, IBuilder, IContainer, IResultCache, IsOptional, Issue, IssueBase, IssueCode, IssueDataByCode, IssueGroup, IssueItem, IssueItemBare, IssueItemRaw, IssueItemTyped, IssueMessageTemplates, Mount, MountOptions, MountTarget, Mounted, ObjectLiteral, OptionalValue, OptionalValueInput, ParameterizedIssueCode, PathFilterResolution, PathsStrictViolationError, PathsStrictViolationInput, ResolveIssueCode, Result, ResultCache, ResultCacheEntry, ResultCacheOutcome, ResultCacheSnapshot, ResultFailure, ResultSuccess, Spread, Validator, ValidatorContext, ValidatorDescriptor, ValidatorMount, ValidupError, buildErrorMessageForAttribute, buildErrorMessageForAttributes, buildOneOfFailedGroup, compose, composeOneOf, createValidupError, defineIssueGroup, defineIssueItem, defineSchema, defineValidator, errorToIssues, flattenIssueGroups, flattenIssueItems, formatIssue, hasOwnProperty, interpolate, isContainer, isError, isIssue, isIssueGroup, isIssueItem, isObject, isOptionalValue, isPathsStrictViolation, isResultCache, isValidatorDescriptor, isValidupError, resolveDefaults, resolvePathFilter, stringifyPath };
|
|
1491
1854
|
//# sourceMappingURL=index.d.mts.map
|