validup 0.5.1 → 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 +18 -0
- package/dist/index.d.mts +282 -27
- package/dist/index.mjs +519 -265
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -223,6 +223,7 @@ interface IBuilder<T extends Record<string, any>, C = unknown> {
|
|
|
223
223
|
oneOf(): IBuilder<T, C>;
|
|
224
224
|
pathsToInclude(...paths: (keyof T & string)[]): IBuilder<T, C>;
|
|
225
225
|
pathsToExclude(...paths: (keyof T & string)[]): IBuilder<T, C>;
|
|
226
|
+
pathsStrict(strict?: boolean): IBuilder<T, C>;
|
|
226
227
|
build(): Container<T, C>;
|
|
227
228
|
}
|
|
228
229
|
```
|
|
@@ -490,6 +491,20 @@ await container.run(input, { pathsToExclude: ['password'] }); // skip the
|
|
|
490
491
|
|
|
491
492
|
The same options can be set at the container level via `new Container({ pathsToInclude: [...] })`. Run-time options take precedence.
|
|
492
493
|
|
|
494
|
+
By default a filter path that matches no mount is silently ignored. Add `pathsStrict: true` to **fail loud** instead — the run throws a structural `PathsStrictViolationError` (caught with `isPathsStrictViolation`, re-thrown by `safeRun`/`safeRunSync`) listing the unmatched paths, so a renamed mount key can't make a scoped validation silently disappear:
|
|
495
|
+
|
|
496
|
+
```typescript
|
|
497
|
+
import { isPathsStrictViolation } from 'validup';
|
|
498
|
+
|
|
499
|
+
try {
|
|
500
|
+
await container.run(input, { pathsToInclude: ['clientId'], pathsStrict: true });
|
|
501
|
+
} catch (e) {
|
|
502
|
+
if (isPathsStrictViolation(e)) {
|
|
503
|
+
e.pathsToInclude; // → ['clientId'] (no mount matched)
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
```
|
|
507
|
+
|
|
493
508
|
## Defaults
|
|
494
509
|
|
|
495
510
|
Provide fallback values for keys that end up missing or `undefined` after validation:
|
|
@@ -634,6 +649,8 @@ const out = container.runSync(input); // returns T directly, not Promise<T>
|
|
|
634
649
|
|
|
635
650
|
`runSync()` throws synchronously if a validator returns a Promise or if a nested container does not implement `runSync` — those are *structural* failures (not validation outcomes), so they're surfaced verbatim and never wrapped into `Result.failure` by `safeRunSync`. Use the async `run()` for any graph that mixes sync and async validators.
|
|
636
651
|
|
|
652
|
+
`run()` and `runSync()` are **not two implementations**. Both drive one shared mount-resolution body, so every mount option (groups, `optional` / `optionalValue` / `optionalAs`, path filters, `defaults`, `pathsStrict`, `cache`) resolves identically in both — a sync run can't silently drift from its async twin. The only differences are the two structural probes above.
|
|
653
|
+
|
|
637
654
|
## Localized Messages
|
|
638
655
|
|
|
639
656
|
`Issue.message` is rendered eagerly in English at construction time. For i18n / custom locales, every issue also carries a structured `data?: Record<string, unknown>` field (populated by the runtime where the message references a non-trivial value — e.g. `{ name: 'email' }` on the wrapping group at a failing mount). Pair it with `formatIssue` and a `code → template` map to render at the consumer side:
|
|
@@ -817,6 +834,7 @@ class Container<
|
|
|
817
834
|
| `oneOf` | `ContainerOptions` | Succeed when any mount succeeds |
|
|
818
835
|
| `pathsToInclude` | `ContainerOptions`, `ContainerRunOptions` | Only mount paths in this list are executed |
|
|
819
836
|
| `pathsToExclude` | `ContainerOptions`, `ContainerRunOptions` | Mount paths in this list are skipped |
|
|
837
|
+
| `pathsStrict` | `ContainerOptions`, `ContainerRunOptions` | Throw `PathsStrictViolationError` when an include/exclude path matches no mount |
|
|
820
838
|
| `defaults` | `ContainerRunOptions` | Fallback values for missing/`undefined` keys |
|
|
821
839
|
| `context` | `ContainerRunOptions` | Caller-supplied value surfaced on `ValidatorContext.context` |
|
|
822
840
|
| `signal` | `ContainerRunOptions` | `AbortSignal` — checked between mounts and forwarded to `ctx.signal` |
|
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.
|
|
@@ -176,32 +175,53 @@ declare enum OptionalValue {
|
|
|
176
175
|
* placeholders being present (`{{min}}`, `{{max}}`, `{{other}}`, etc.).
|
|
177
176
|
*/
|
|
178
177
|
declare const IssueCode: {
|
|
179
|
-
/** Generic fallback when no more-specific code applies. `data`: — */
|
|
180
|
-
readonly
|
|
181
|
-
|
|
182
|
-
readonly
|
|
183
|
-
|
|
184
|
-
readonly
|
|
185
|
-
|
|
186
|
-
readonly
|
|
187
|
-
|
|
188
|
-
readonly
|
|
189
|
-
|
|
190
|
-
readonly
|
|
191
|
-
|
|
192
|
-
readonly
|
|
193
|
-
|
|
194
|
-
readonly
|
|
195
|
-
|
|
196
|
-
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`: — */
|
|
197
215
|
readonly DATE: "date";
|
|
198
216
|
/**
|
|
199
217
|
* Value does not match the expected regex pattern. `data`:
|
|
200
218
|
* `{ pattern: string }` — source of the regex without flags so
|
|
201
219
|
* catalogs can quote it in human-readable form.
|
|
202
220
|
*/
|
|
203
|
-
readonly PATTERN: "pattern";
|
|
204
|
-
|
|
221
|
+
readonly PATTERN: "pattern";
|
|
222
|
+
/** Value is not valid JSON. `data`: — */
|
|
223
|
+
readonly JSON: "json";
|
|
224
|
+
/** Value is not valid base64. `data`: — */
|
|
205
225
|
readonly BASE64: "base64";
|
|
206
226
|
/**
|
|
207
227
|
* Value does not meet the configured strong-password rules. `data`:
|
|
@@ -397,7 +417,7 @@ interface IssueItemCommon extends IssueBase {
|
|
|
397
417
|
type IssueItemTyped = { [K in ParameterizedIssueCode]: IssueItemCommon & {
|
|
398
418
|
code: K;
|
|
399
419
|
data: IssueDataByCode[K];
|
|
400
|
-
} }[ParameterizedIssueCode];
|
|
420
|
+
}; }[ParameterizedIssueCode];
|
|
401
421
|
/**
|
|
402
422
|
* Bare-data branch — one variant per `BareIssueCode`. `data` must be
|
|
403
423
|
* absent (or explicitly `undefined`).
|
|
@@ -409,7 +429,7 @@ type IssueItemTyped = { [K in ParameterizedIssueCode]: IssueItemCommon & {
|
|
|
409
429
|
type IssueItemBare = { [K in BareIssueCode]: IssueItemCommon & {
|
|
410
430
|
code: K;
|
|
411
431
|
data?: undefined;
|
|
412
|
-
} }[BareIssueCode];
|
|
432
|
+
}; }[BareIssueCode];
|
|
413
433
|
/**
|
|
414
434
|
* Escape-hatch branch — ad-hoc / project-specific codes outside the
|
|
415
435
|
* shipped vocabulary. `code: string & {}` keeps autocomplete on the
|
|
@@ -702,6 +722,32 @@ type ContainerOptions<T> = {
|
|
|
702
722
|
* be considered for execution.
|
|
703
723
|
*/
|
|
704
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;
|
|
705
751
|
/**
|
|
706
752
|
* Container-wide default for `MountOptions.optionalValue`. Applied
|
|
707
753
|
* to mounts in this container that declare `optional: true` (or a
|
|
@@ -729,7 +775,7 @@ type ContainerRunOptions<T extends Record<string, any> = Record<string, any>, C
|
|
|
729
775
|
* only the paths you want to backfill. When the validated output is missing
|
|
730
776
|
* a key (or holds `undefined`), the matching entry from `defaults` is used.
|
|
731
777
|
*/
|
|
732
|
-
defaults?: { [Key in Path<T>]?: any };
|
|
778
|
+
defaults?: { [Key in Path<T>]?: any; };
|
|
733
779
|
/**
|
|
734
780
|
* Group to execute.
|
|
735
781
|
*/
|
|
@@ -754,6 +800,15 @@ type ContainerRunOptions<T extends Record<string, any> = Record<string, any>, C
|
|
|
754
800
|
* be considered for execution.
|
|
755
801
|
*/
|
|
756
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;
|
|
757
812
|
/**
|
|
758
813
|
* Caller-supplied context surfaced on `ValidatorContext.context`. Forwarded
|
|
759
814
|
* unchanged into nested container `run()` calls so the entire tree shares
|
|
@@ -1352,12 +1407,65 @@ declare class Container<T extends Record<string, any> = Record<string, any>, C =
|
|
|
1352
1407
|
* already-aborted run — re-raised as-is rather than wrapped.
|
|
1353
1408
|
*/
|
|
1354
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;
|
|
1355
1435
|
/**
|
|
1356
1436
|
* Parallel-execution variant of `run()`. All mounts kick off their
|
|
1357
1437
|
* promises eagerly and the results are merged after `Promise.allSettled`.
|
|
1358
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.
|
|
1359
1445
|
*/
|
|
1360
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;
|
|
1361
1469
|
safeRun(input?: ContainerInput<T>, options?: ContainerRunOptions<T, C>): Promise<Result<T>>;
|
|
1362
1470
|
/**
|
|
1363
1471
|
* Synchronous variant of {@link Container.run}. Use it for purely
|
|
@@ -1390,6 +1498,76 @@ declare class Container<T extends Record<string, any> = Record<string, any>, C =
|
|
|
1390
1498
|
*/
|
|
1391
1499
|
runSync(data?: ContainerInput<T>, options?: ContainerRunOptions<T, C>): T;
|
|
1392
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;
|
|
1393
1571
|
/**
|
|
1394
1572
|
* Lookup helper for the per-mount result cache.
|
|
1395
1573
|
*
|
|
@@ -1421,6 +1599,38 @@ declare class Container<T extends Record<string, any> = Record<string, any>, C =
|
|
|
1421
1599
|
*/
|
|
1422
1600
|
private writeCachedOutcome;
|
|
1423
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;
|
|
1424
1634
|
/**
|
|
1425
1635
|
* Prepend `keyParts` to a child issue's `path` and — when the child is
|
|
1426
1636
|
* an `IssueGroup` — recurse into its nested issues so every leaf carries
|
|
@@ -1486,12 +1696,50 @@ declare class Container<T extends Record<string, any> = Record<string, any>, C =
|
|
|
1486
1696
|
protected initialize(): void;
|
|
1487
1697
|
}
|
|
1488
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
|
|
1489
1737
|
//#region src/builder/types.d.ts
|
|
1490
1738
|
/**
|
|
1491
1739
|
* Cosmetic helper — flattens an intersection so editors render
|
|
1492
1740
|
* `{ foo: string; bar: number }` instead of `{ foo: string } & { bar: number }`.
|
|
1493
1741
|
*/
|
|
1494
|
-
type Spread<T> = { [K in keyof T]: T[K] };
|
|
1742
|
+
type Spread<T> = { [K in keyof T]: T[K]; };
|
|
1495
1743
|
/**
|
|
1496
1744
|
* Anything that can be mounted under a key on a `Builder`: a leaf validator,
|
|
1497
1745
|
* a nested builder (auto-`.build()`-ed), or an existing `Container`.
|
|
@@ -1519,7 +1767,7 @@ type IsOptional<O> = O extends {
|
|
|
1519
1767
|
* matching the runtime behavior that an optional mount may be skipped, leaving
|
|
1520
1768
|
* the key absent from the output.
|
|
1521
1769
|
*/
|
|
1522
|
-
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;
|
|
1523
1771
|
/**
|
|
1524
1772
|
* Compile-time-typed schema builder. `mount(...)` accumulates the resolved
|
|
1525
1773
|
* field type into `T`, so `build()` returns a `Container<T, C>` whose static
|
|
@@ -1550,6 +1798,12 @@ interface IBuilder<T extends Record<string, any>, C = unknown> {
|
|
|
1550
1798
|
pathsToInclude(...paths: (keyof T & string)[]): IBuilder<T, C>;
|
|
1551
1799
|
/** Restrict the resulting container's `pathsToExclude`. */
|
|
1552
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>;
|
|
1553
1807
|
/** Materialize a `Container<T, C>` and replay every accumulated mount. */
|
|
1554
1808
|
build(): Container<T, C>;
|
|
1555
1809
|
}
|
|
@@ -1576,6 +1830,7 @@ declare class Builder<T extends Record<string, any>, C> implements IBuilder<T, C
|
|
|
1576
1830
|
oneOf(): IBuilder<T, C>;
|
|
1577
1831
|
pathsToInclude(...paths: (keyof T & string)[]): IBuilder<T, C>;
|
|
1578
1832
|
pathsToExclude(...paths: (keyof T & string)[]): IBuilder<T, C>;
|
|
1833
|
+
pathsStrict(strict?: boolean): IBuilder<T, C>;
|
|
1579
1834
|
build(): Container<T, C>;
|
|
1580
1835
|
}
|
|
1581
1836
|
/**
|
|
@@ -1595,5 +1850,5 @@ declare function hasOwnProperty<X extends {}, Y extends PropertyKey>(obj: X, pro
|
|
|
1595
1850
|
//#region src/utils/object.d.ts
|
|
1596
1851
|
declare function isObject(input: unknown): input is Record<string, any>;
|
|
1597
1852
|
//#endregion
|
|
1598
|
-
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, 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 };
|
|
1599
1854
|
//# sourceMappingURL=index.d.mts.map
|