validup 0.5.1 → 2.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/dist/index.d.mts CHANGED
@@ -1,6 +1,5 @@
1
- import { BaseError, interpolate } from "@ebec/core";
1
+ import { BareIssueCode, BaseError, Issue, IssueCode, IssueDataByCode, IssueGroup, ParameterizedIssueCode, ResolveIssueCode } 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.
@@ -142,400 +141,6 @@ declare enum OptionalValue {
142
141
  FALSY = "falsy"
143
142
  }
144
143
  //#endregion
145
- //#region src/issue/constants.d.ts
146
- /**
147
- * Vocabulary of well-known issue codes. Adapter packages map foreign
148
- * validator codes onto these so consumer-side translation catalogs
149
- * (e.g. `@ilingo/validup`) can ship one localized message per code
150
- * instead of falling back to a generic "invalid value" fallback.
151
- *
152
- * Tracks the common ground between vuelidate, zod, joi, and yup. The
153
- * core lifts from vuelidate's catalog (snake_cased to match validup's
154
- * convention); modern format codes (`PATTERN`, `UUID`, `DATE`,
155
- * `JSON`, `BASE64`, `STRONG_PASSWORD`, …) cover ground vuelidate
156
- * predates. Every format code names the format positively (`UUID`,
157
- * `EMAIL`, `URL`, …) rather than the failure mode (`NOT_UUID`,
158
- * `INVALID_EMAIL`) so the registry reads consistently.
159
- *
160
- * Ad-hoc / project-specific codes still work — `IssueItem.code` is
161
- * widened to `IssueCode | (string & {})`, so `defineIssueItem({ code:
162
- * 'email_taken', ... })` is valid. If you want a typed const for your
163
- * own codes, define one alongside this one:
164
- *
165
- * ```ts
166
- * import { IssueCode } from 'validup';
167
- *
168
- * export const AppCode = {
169
- * ...IssueCode,
170
- * EMAIL_TAKEN: 'email_taken',
171
- * } as const;
172
- * ```
173
- *
174
- * Each entry's JSDoc documents the structured `data` adapters should
175
- * attach when constructing the issue — templates can rely on those
176
- * placeholders being present (`{{min}}`, `{{max}}`, `{{other}}`, etc.).
177
- */
178
- declare const IssueCode: {
179
- /** Generic fallback when no more-specific code applies. `data`: — */readonly VALUE_INVALID: "value_invalid"; /** Every branch of a `oneOf` container failed. `data`: — */
180
- readonly ONE_OF_FAILED: "one_of_failed"; /** Value is missing, `undefined`, `null`, or empty per the validator's semantics. `data`: — */
181
- readonly REQUIRED: "required"; /** Value contains characters outside the alphabetical set. `data`: — */
182
- readonly ALPHA: "alpha"; /** Value contains characters outside the alphanumeric set. `data`: — */
183
- readonly ALPHA_NUM: "alpha_num"; /** Value is not a number. `data`: — */
184
- readonly NUMERIC: "numeric"; /** Value is not an integer. `data`: — */
185
- readonly INTEGER: "integer"; /** Value is not a decimal number. `data`: — */
186
- readonly DECIMAL: "decimal"; /** Value is shorter than the configured minimum. `data`: `{ min: number }` */
187
- readonly MIN_LENGTH: "min_length"; /** Value is longer than the configured maximum. `data`: `{ max: number }` */
188
- readonly MAX_LENGTH: "max_length"; /** Numeric value is below the configured minimum. `data`: `{ min: number }` */
189
- readonly MIN_VALUE: "min_value"; /** Numeric value is above the configured maximum. `data`: `{ max: number }` */
190
- readonly MAX_VALUE: "max_value"; /** Numeric value falls outside the configured `[min, max]` range. `data`: `{ min: number, max: number }` */
191
- readonly BETWEEN: "between"; /** Value is not a valid email address. `data`: — */
192
- readonly EMAIL: "email"; /** Value is not a valid URL. `data`: — */
193
- readonly URL: "url"; /** Value is not a valid IP address. `data`: — */
194
- readonly IP_ADDRESS: "ip_address"; /** Value is not a valid MAC address. `data`: — */
195
- readonly MAC_ADDRESS: "mac_address"; /** Value is not a valid UUID. `data`: — */
196
- readonly UUID: "uuid"; /** Value is not a valid date / cannot be parsed as a date. `data`: — */
197
- readonly DATE: "date";
198
- /**
199
- * Value does not match the expected regex pattern. `data`:
200
- * `{ pattern: string }` — source of the regex without flags so
201
- * catalogs can quote it in human-readable form.
202
- */
203
- readonly PATTERN: "pattern"; /** Value is not valid JSON. `data`: — */
204
- readonly JSON: "json"; /** Value is not valid base64. `data`: — */
205
- readonly BASE64: "base64";
206
- /**
207
- * Value does not meet the configured strong-password rules. `data`:
208
- * `{ minLength?: number, minLowercase?: number, minUppercase?: number,
209
- * minNumbers?: number, minSymbols?: number }` — only the keys the
210
- * adapter chose to surface; missing keys mean "the default for that
211
- * setting wasn't configured."
212
- */
213
- readonly STRONG_PASSWORD: "strong_password";
214
- /**
215
- * Value must equal another named field's value (sibling-field assertion,
216
- * e.g. password-confirm). `data`: `{ other: string }` — the name of
217
- * the field being compared against.
218
- */
219
- readonly SAME_AS: "same_as";
220
- };
221
- type IssueCode = typeof IssueCode[keyof typeof IssueCode];
222
- /**
223
- * Per-code `data` contract for the well-known vocabulary. Producers
224
- * (`defineIssueItem`, `createValidupError`, adapter `error.ts` modules)
225
- * thread this through their type signatures so TS rejects mismatched
226
- * payloads at compile time — e.g. `STRONG_PASSWORD` with `data:
227
- * { pointsPerUnique: 5 }` (a validator.js scoring weight, not a strength
228
- * requirement) fails to type-check. Codes absent from this map carry no
229
- * `data`; ad-hoc string codes fall back to the open
230
- * `Record<string, unknown>` shape on the raw `IssueItem` branch.
231
- *
232
- * Extensible via TypeScript declaration merging — third-party adapters
233
- * and apps that want typed data for their own codes can augment this
234
- * interface, and the producer-side gatekeep (`defineIssueItem`,
235
- * `createValidupError`) will type-check their payloads too:
236
- *
237
- * ```ts
238
- * // In a third-party package or app:
239
- * declare module 'validup' {
240
- * interface IssueDataByCode {
241
- * email_taken: { existingUserId: string };
242
- * }
243
- * }
244
- *
245
- * defineIssueItem({
246
- * code: 'email_taken',
247
- * path: ['email'],
248
- * message: 'Already in use',
249
- * data: { existingUserId: 'u_42' }, // typed and required
250
- * });
251
- * ```
252
- *
253
- * Keep entries here in lockstep with the JSDoc on the corresponding
254
- * `IssueCode` entry — the type-level enforcement and the documentation
255
- * are two views of the same contract.
256
- */
257
- interface IssueDataByCode {
258
- min_length: {
259
- min: number;
260
- };
261
- max_length: {
262
- max: number;
263
- };
264
- min_value: {
265
- min: number;
266
- };
267
- max_value: {
268
- max: number;
269
- };
270
- between: {
271
- min: number;
272
- max: number;
273
- };
274
- pattern: {
275
- pattern: string;
276
- };
277
- strong_password: {
278
- minLength?: number;
279
- minLowercase?: number;
280
- minUppercase?: number;
281
- minNumbers?: number;
282
- minSymbols?: number;
283
- };
284
- same_as: {
285
- other: string;
286
- };
287
- }
288
- /**
289
- * `IssueCode` values that carry a documented `data` payload — keys of
290
- * {@link IssueDataByCode}. Producers using one of these codes must
291
- * supply the matching `data` shape.
292
- */
293
- type ParameterizedIssueCode = keyof IssueDataByCode;
294
- /**
295
- * `IssueCode` values that carry no `data` (`VALUE_INVALID`, `EMAIL`,
296
- * `REQUIRED`, …). Producers using one of these codes must omit `data`
297
- * (or pass `undefined`).
298
- */
299
- type BareIssueCode = Exclude<IssueCode, ParameterizedIssueCode>;
300
- //#endregion
301
- //#region src/issue/types.d.ts
302
- /**
303
- * Resolve a possibly-`undefined` `code` to its effective vocabulary entry.
304
- * When a producer (`defineIssueItem`, `createValidupError`) is called
305
- * without a `code`, the runtime defaults to `IssueCode.VALUE_INVALID`;
306
- * this helper reflects that at the type level so the conditional-type
307
- * signatures pick the bare-data branch instead of the raw catch-all.
308
- *
309
- * `[C] extends [undefined]` is the standard idiom for testing the whole
310
- * `C` against `undefined` *without* distributing over union members.
311
- */
312
- type ResolveIssueCode<C> = [C] extends [undefined] ? typeof IssueCode.VALUE_INVALID : C & string;
313
- interface IssueBase {
314
- /**
315
- * Out-of-band provenance about how this issue came to exist — context the
316
- * consumer cannot reconstruct from `path` + the container's mount config.
317
- *
318
- * Library-owned keys (stable, semver-protected):
319
- *
320
- * - `optional?: true` — set by the runtime when the originating mount's
321
- * `optional` declaration resolves truthy for the current value:
322
- *
323
- * - `optional: true` → tagged
324
- * - `optional: false` → not tagged (matches the runtime's truthy filter)
325
- * - `optional: (v) => boolean` → predicate is invoked with the current
326
- * value; tagged iff it returns truthy. In practice the run loop only
327
- * enters the error path when the predicate has already returned
328
- * false (otherwise the validator would have been skipped), so
329
- * predicate-optional issues effectively never carry the flag today.
330
- * - `optional: undefined` → not tagged
331
- *
332
- * Reflects only the most-local mount, never inherited from a parent:
333
- * a leaf inside an optional child container does NOT carry the flag
334
- * unless its own mount also evaluated truthy. Set on direct leaf
335
- * emissions and on the wrapping `IssueGroup` produced for the mount
336
- * itself; never set on issues that bubbled up unchanged through
337
- * `prefixIssuePath`.
338
- * - `external?: true` — set by frameworks that inject server-side issues
339
- * (e.g. `@validup/vue`'s `setExternalIssues`). Distinguishes
340
- * server-supplied from validator-supplied so consumers can render the
341
- * distinction.
342
- *
343
- * Apps and third-party validators may add their own keys (e.g.
344
- * `app.componentId`) — the open-shape `Record<string, unknown>` is
345
- * intentional. New library-owned keys must pass the bar above:
346
- * provenance, not derivable from path + container config. Presentation
347
- * tokens (e.g. `severity`) do not qualify and live in consumer code.
348
- */
349
- meta?: Record<string, unknown>;
350
- /**
351
- * Issue path.
352
- */
353
- path: PropertyKey[];
354
- /**
355
- * Default-rendered message (eager, English). Use `formatIssue` with a
356
- * `code → template` map for localized re-rendering at the consumer side.
357
- */
358
- message: string;
359
- /**
360
- * Structured parameters used by the default `message` rendering and
361
- * available to consumer-side formatters (i18n, custom locales). The
362
- * concrete shape depends on the discriminating `code` — see the
363
- * `IssueItem` union below for the per-code contract.
364
- */
365
- data?: Record<string, unknown>;
366
- }
367
- /**
368
- * Shared shape for every `IssueItem` branch — the discriminant (`type:
369
- * 'item'`) plus the vendor-passthrough fields. The `code` and `data`
370
- * fields are intentionally absent here; each branch in the discriminated
371
- * union below pins them to the right pair.
372
- */
373
- interface IssueItemCommon extends IssueBase {
374
- /**
375
- * Issue Type
376
- */
377
- type: 'item';
378
- /**
379
- * Received input value.
380
- */
381
- received?: unknown;
382
- /**
383
- * Expected input value.
384
- */
385
- expected?: unknown;
386
- }
387
- /**
388
- * Typed-data branch — one variant per `ParameterizedIssueCode`. The
389
- * `data` shape is locked to the documented contract via
390
- * {@link IssueDataByCode}.
391
- *
392
- * Distributed (rather than written as a single `code: ParameterizedIssueCode`
393
- * member) so that `Extract<IssueItem, { code: 'min_length' }>` and structural
394
- * narrowing on `issue.code === IssueCode.MIN_LENGTH` resolve to the right
395
- * concrete variant with `data: { min: number }`, not the joined union.
396
- */
397
- type IssueItemTyped = { [K in ParameterizedIssueCode]: IssueItemCommon & {
398
- code: K;
399
- data: IssueDataByCode[K];
400
- } }[ParameterizedIssueCode];
401
- /**
402
- * Bare-data branch — one variant per `BareIssueCode`. `data` must be
403
- * absent (or explicitly `undefined`).
404
- *
405
- * Distributed for the same reason as {@link IssueItemTyped} — so
406
- * `Extract<IssueItem, { code: 'email' }>` resolves to the single
407
- * `code: 'email'` variant.
408
- */
409
- type IssueItemBare = { [K in BareIssueCode]: IssueItemCommon & {
410
- code: K;
411
- data?: undefined;
412
- } }[BareIssueCode];
413
- /**
414
- * Escape-hatch branch — ad-hoc / project-specific codes outside the
415
- * shipped vocabulary. `code: string & {}` keeps autocomplete on the
416
- * `IssueCode` literals while permitting strings the typed branches don't
417
- * cover; `data` is fully open.
418
- *
419
- * Note: because `string & {}` accepts any string at the type level,
420
- * narrowing on `issue.code === IssueCode.MIN_LENGTH` still pulls this
421
- * branch in alongside the matching `IssueItemTyped` variant. The
422
- * producer-side `defineIssueItem` / `createValidupError` signatures
423
- * gatekeep this so emission is always correct; consumers needing a
424
- * clean narrow should cast `issue.data` after the code check.
425
- */
426
- interface IssueItemRaw extends IssueItemCommon {
427
- code: string & {};
428
- data?: Record<string, unknown>;
429
- }
430
- /**
431
- * Discriminated union over `IssueItem`'s three branches:
432
- *
433
- * - {@link IssueItemTyped} — known parameterized codes (`MIN_LENGTH`,
434
- * `PATTERN`, `STRONG_PASSWORD`, …); `data` is required and typed.
435
- * - {@link IssueItemBare} — known param-less codes (`EMAIL`, `REQUIRED`,
436
- * …); `data` must be absent.
437
- * - {@link IssueItemRaw} — ad-hoc string codes; `data` is open.
438
- *
439
- * The discriminant is `code`. Build issues with `defineIssueItem` (typed
440
- * overloads enforce the per-branch contract) rather than constructing
441
- * literals by hand.
442
- */
443
- type IssueItem = IssueItemTyped | IssueItemBare | IssueItemRaw;
444
- interface IssueGroup extends IssueBase {
445
- /**
446
- * Code identifying the issue. See `IssueItem.code` for the
447
- * vocabulary + ad-hoc widening conventions.
448
- */
449
- code?: IssueCode | (string & {});
450
- /**
451
- * Issue Type
452
- */
453
- type: 'group';
454
- /**
455
- * Child issues
456
- */
457
- issues: Issue[];
458
- }
459
- type Issue = IssueGroup | IssueItem;
460
- //#endregion
461
- //#region src/issue/check.d.ts
462
- declare function isIssueItem(input: unknown): input is IssueItem;
463
- declare function isIssueGroup(input: unknown): input is IssueGroup;
464
- declare function isIssue(input: unknown): input is Issue;
465
- //#endregion
466
- //#region src/issue/define.d.ts
467
- interface DefineIssueItemCommon extends Omit<IssueBase, 'data'> {
468
- received?: unknown;
469
- expected?: unknown;
470
- }
471
- /**
472
- * Per-call `data` shape for {@link defineIssueItem}. The `data`
473
- * requirement is selected from the resolved `code`:
474
- *
475
- * - Parameterized code → `data` required, typed per {@link IssueDataByCode}.
476
- * - Bare code (incl. omitted, which resolves to `VALUE_INVALID`)
477
- * → `data` must be absent / `undefined`.
478
- * - Ad-hoc string code → `data` optional `Record`.
479
- */
480
- type DefineIssueItemData<C> = DefineIssueItemCommon & {
481
- code?: C;
482
- } & (ResolveIssueCode<C> extends ParameterizedIssueCode ? {
483
- data: IssueDataByCode[ResolveIssueCode<C> & ParameterizedIssueCode];
484
- } : ResolveIssueCode<C> extends BareIssueCode ? {
485
- data?: undefined;
486
- } : {
487
- data?: Record<string, unknown>;
488
- });
489
- /**
490
- * Return type for {@link defineIssueItem} — picks the concrete `IssueItem`
491
- * variant matching the resolved `code`.
492
- */
493
- type DefineIssueItemReturn<C> = ResolveIssueCode<C> extends ParameterizedIssueCode ? Extract<IssueItemTyped, {
494
- code: ResolveIssueCode<C>;
495
- }> : ResolveIssueCode<C> extends BareIssueCode ? Extract<IssueItemBare, {
496
- code: ResolveIssueCode<C>;
497
- }> : IssueItemRaw;
498
- /**
499
- * Build an `IssueItem`. TS uses the supplied `code` to pick the right
500
- * `data` requirement at the call site — passing `MIN_LENGTH` without
501
- * `data: { min }` is a compile error; passing `STRONG_PASSWORD` with
502
- * `data: { pointsPerUnique: 5 }` is a compile error.
503
- *
504
- * `code` may be omitted (defaults to `IssueCode.VALUE_INVALID` — bare,
505
- * no data).
506
- */
507
- declare function defineIssueItem<C extends string | undefined = undefined>(data: DefineIssueItemData<C>): DefineIssueItemReturn<C>;
508
- declare function defineIssueGroup(data: Omit<IssueGroup, 'type'>): IssueGroup;
509
- //#endregion
510
- //#region src/issue/flatten.d.ts
511
- declare function flattenIssueItems(issues: Issue[]): IssueItem[];
512
- declare function flattenIssueGroups(issues: Issue[]): IssueGroup[];
513
- //#endregion
514
- //#region src/issue/format.d.ts
515
- /**
516
- * Map of issue `code` → message template. Templates use `{name}` placeholders
517
- * — the same syntax `@ebec/core`'s `interpolate` understands — and are
518
- * resolved against `Issue.data` at format time.
519
- *
520
- * ```ts
521
- * const de: IssueMessageTemplates = {
522
- * value_invalid: 'Wert ist ungültig',
523
- * one_of_failed: 'Keine der Varianten war erfolgreich',
524
- * };
525
- * ```
526
- */
527
- type IssueMessageTemplates = Partial<Record<IssueCode, string>> & Record<string, string>;
528
- /**
529
- * Render an issue's user-facing message.
530
- *
531
- * Resolution order:
532
- * 1. If `templates[code]` exists, return `interpolate(template, issue.data)`.
533
- * 2. Else return `issue.message` (the default English rendering set at
534
- * construction time).
535
- * 3. Else return `fallback`.
536
- */
537
- declare function formatIssue(issue: Issue, templates?: IssueMessageTemplates, fallback?: string): string;
538
- //#endregion
539
144
  //#region src/error/base.d.ts
540
145
  declare class ValidupError extends BaseError {
541
146
  readonly issues: Issue[];
@@ -702,6 +307,32 @@ type ContainerOptions<T> = {
702
307
  * be considered for execution.
703
308
  */
704
309
  pathsToExclude?: Path<T>[];
310
+ /**
311
+ * Fail loud when a `pathsToInclude` / `pathsToExclude` entry matches no
312
+ * mount. By default, an include/exclude path that addresses nothing is
313
+ * silently ignored (the run just executes fewer mounts) — so if a shared
314
+ * validator renames a mounted key out from under a caller's static path
315
+ * list, the scoped validation for that field silently disappears instead
316
+ * of failing.
317
+ *
318
+ * With `pathsStrict: true`, each container verifies — before running any
319
+ * validator — that every include/exclude entry is satisfied locally
320
+ * (exact key match, or prefix descent into a container mount). Any entry
321
+ * that isn't throws a structural {@link PathsStrictViolationError} listing
322
+ * the unmatched (absolute) paths. Nested containers self-check the
323
+ * forwarded remainder because the flag threads into child `run()` calls
324
+ * alongside the already-stripped filter lists.
325
+ *
326
+ * Group filtering stays orthogonal — a mount excluded from the active
327
+ * group still counts as "existing", so a valid path targeting it does not
328
+ * trip strict mode.
329
+ *
330
+ * Precedence: `ContainerRunOptions.pathsStrict` (per-run) wins over
331
+ * `ContainerOptions.pathsStrict` (container-wide).
332
+ *
333
+ * default: false
334
+ */
335
+ pathsStrict?: boolean;
705
336
  /**
706
337
  * Container-wide default for `MountOptions.optionalValue`. Applied
707
338
  * to mounts in this container that declare `optional: true` (or a
@@ -729,7 +360,7 @@ type ContainerRunOptions<T extends Record<string, any> = Record<string, any>, C
729
360
  * only the paths you want to backfill. When the validated output is missing
730
361
  * a key (or holds `undefined`), the matching entry from `defaults` is used.
731
362
  */
732
- defaults?: { [Key in Path<T>]?: any };
363
+ defaults?: { [Key in Path<T>]?: any; };
733
364
  /**
734
365
  * Group to execute.
735
366
  */
@@ -754,6 +385,15 @@ type ContainerRunOptions<T extends Record<string, any> = Record<string, any>, C
754
385
  * be considered for execution.
755
386
  */
756
387
  pathsToExclude?: Path<T>[];
388
+ /**
389
+ * Fail loud when a `pathsToInclude` / `pathsToExclude` entry matches no
390
+ * mount. Per-run counterpart of `ContainerOptions.pathsStrict` (and wins
391
+ * over it). See that field for the full semantics. Forwarded unchanged
392
+ * into nested container `run()` calls so the entire tree is checked.
393
+ *
394
+ * default: false
395
+ */
396
+ pathsStrict?: boolean;
757
397
  /**
758
398
  * Caller-supplied context surfaced on `ValidatorContext.context`. Forwarded
759
399
  * unchanged into nested container `run()` calls so the entire tree shares
@@ -1352,12 +992,65 @@ declare class Container<T extends Record<string, any> = Record<string, any>, C =
1352
992
  * already-aborted run — re-raised as-is rather than wrapped.
1353
993
  */
1354
994
  run(data?: ContainerInput<T>, options?: ContainerRunOptions<T, C>): Promise<T>;
995
+ /**
996
+ * The single mount-resolution loop behind {@link Container.run} and
997
+ * {@link Container.runSync}.
998
+ *
999
+ * Written as a **twin body** (the `twinop` package): the two impure edges,
1000
+ * invoking a validator and descending into a nested container, are yielded
1001
+ * as `op(asyncThunk, syncThunk)` pairs, and the driver chosen by the public
1002
+ * method (`runTwinAsync` / `runTwinSync`) executes the matching side. Effect
1003
+ * errors are thrown back in at the `yield` site, so the cache-write and
1004
+ * issue-collection `try`/`catch` blocks below run identically in both
1005
+ * variants, with no second copy of the loop to keep in lockstep.
1006
+ *
1007
+ * The sync thunks own the two structural probes that only `runSync` needs:
1008
+ * a nested container that doesn't implement `runSync`, and a validator that
1009
+ * returned a thenable. Both throw `RunSyncViolationError`, which the async
1010
+ * side cannot produce.
1011
+ *
1012
+ * `runParallel` deliberately does NOT share this body — a generator is
1013
+ * sequential by construction, and expressing "launch every mount, then
1014
+ * settle" through it would mean yielding batches and giving up the
1015
+ * chain-read. It shares the extracted per-key helpers instead
1016
+ * (`prepareMountKey` / `resolveOptionalDirective` / `buildChildRunOptions` /
1017
+ * `buildValidatorContext`).
1018
+ */
1019
+ private runBody;
1355
1020
  /**
1356
1021
  * Parallel-execution variant of `run()`. All mounts kick off their
1357
1022
  * promises eagerly and the results are merged after `Promise.allSettled`.
1358
1023
  * See `ContainerRunOptions.parallel` for the trade-off note.
1024
+ *
1025
+ * Shares every per-key helper with the sequential twin body
1026
+ * (`prepareMountKey` / `resolveOptionalDirective` / `buildChildRunOptions` /
1027
+ * `buildValidatorContext` / the cache pair) but keeps its own scheduling
1028
+ * loop — see the note on {@link Container.runBody} for why it can't be a
1029
+ * third twin driver.
1359
1030
  */
1360
1031
  private runParallel;
1032
+ /**
1033
+ * Claim ownership of a scheduled mount's rejection.
1034
+ *
1035
+ * `runParallel` creates every mount's promise eagerly and only attaches
1036
+ * `Promise.allSettled` after the whole scheduling loop has run. Any
1037
+ * rejection settling in that window — or, worse, any throw that escapes
1038
+ * the loop before `allSettled` is reached at all — is unowned, and Node's
1039
+ * default `--unhandled-rejections=throw` (this package requires Node >=
1040
+ * 24) terminates the process.
1041
+ *
1042
+ * The no-op subscriber below is a *second* consumer, discarded
1043
+ * immediately; the original promise is returned unchanged, so
1044
+ * `Promise.allSettled` still observes the real settlement and no outcome
1045
+ * is swallowed.
1046
+ */
1047
+ private ownRejection;
1048
+ /**
1049
+ * Create the in-flight promise for one scheduled mount. Extracted from
1050
+ * `runParallel`'s scheduling loop so the loop body reads as
1051
+ * "resolve, gate, dispatch" and the pre-dispatch `try` stays legible.
1052
+ */
1053
+ private dispatchParallelMount;
1361
1054
  safeRun(input?: ContainerInput<T>, options?: ContainerRunOptions<T, C>): Promise<Result<T>>;
1362
1055
  /**
1363
1056
  * Synchronous variant of {@link Container.run}. Use it for purely
@@ -1390,6 +1083,76 @@ declare class Container<T extends Record<string, any> = Record<string, any>, C =
1390
1083
  */
1391
1084
  runSync(data?: ContainerInput<T>, options?: ContainerRunOptions<T, C>): T;
1392
1085
  safeRunSync(input?: ContainerInput<T>, options?: ContainerRunOptions<T, C>): Result<T>;
1086
+ /**
1087
+ * Resolve everything a single `(mount, expanded key)` pair needs before
1088
+ * dispatch: the split path parts, the absolute path handed to validators
1089
+ * and child containers, and the include/exclude verdict.
1090
+ *
1091
+ * Shared verbatim by the twin body and `runParallel`. The mount's input
1092
+ * `value` is deliberately NOT read here — see {@link MountKeyPlan}.
1093
+ */
1094
+ private prepareMountKey;
1095
+ /**
1096
+ * Resolve the optional gate and — when it fires — what (if anything) the
1097
+ * skipped key contributes to the output.
1098
+ *
1099
+ * `optional` is the gate ("may this mount be skipped?"); `optionalValue` is
1100
+ * the definition of absent, resolved mount → run → container. A predicate
1101
+ * `optional` wins over the atom vocabulary entirely.
1102
+ *
1103
+ * The write directive follows the same three layers, but keys off
1104
+ * `optionalAs` **presence** rather than its value — `{ optionalAs:
1105
+ * undefined }` at any layer is a deliberate "emit `undefined`". Only when
1106
+ * no layer declares `optionalAs` does the mount-level `optionalInclude`
1107
+ * fallback (copy the input through) apply.
1108
+ */
1109
+ private resolveOptionalDirective;
1110
+ /**
1111
+ * Re-resolve a mount's `optional` declaration for the `meta.optional`
1112
+ * stamp applied by {@link Container.collectExecutionFailure}.
1113
+ *
1114
+ * Split out from `resolveOptionalDirective` because the two calls answer
1115
+ * different questions at different times: the directive decides whether to
1116
+ * *run* the mount, this decides whether to *tag* the mount's issues. The
1117
+ * split is what lets this one contain a throw the gate cannot.
1118
+ *
1119
+ * A predicate that throws degrades to `false` (don't tag) rather than
1120
+ * propagating. This is load-bearing, not defensive: the caller is a
1121
+ * `catch` handler with no `try` above it inside the run loop, and the very
1122
+ * throw it is folding may be the predicate's own. Re-raising here escapes
1123
+ * the error path entirely, discarding **every issue collected so far** and
1124
+ * replacing them with one path-less item — so a mainstream idiom like
1125
+ * `optional: (v) => v.trim().length === 0` would, on the first absent
1126
+ * field, wipe out every other field's validation error.
1127
+ *
1128
+ * `false` is the conservative fallback: the mount's issues surface at full
1129
+ * severity instead of being downgraded to a warning by consumers such as
1130
+ * `@validup/vue`'s `getSeverity`. The predicate's failure is not swallowed
1131
+ * — it is already being folded into an issue by the caller.
1132
+ */
1133
+ private resolveOptionalStamp;
1134
+ /**
1135
+ * Attribution fallback for a throw raised before a {@link MountKeyPlan}
1136
+ * exists — path expansion, key preparation, or the mount's value read.
1137
+ *
1138
+ * Produces the same `keyParts` / `pathRelative` pair `prepareMountKey`
1139
+ * would have, so a pre-dispatch failure is attributed to the mount that
1140
+ * caused it rather than surfacing path-less. For an item-level failure
1141
+ * (path expansion) the caller passes the *unexpanded* mount path, so a
1142
+ * glob mount is identified by its literal pattern (`items.*.name`) — the
1143
+ * keys it would have expanded to are precisely what could not be computed.
1144
+ */
1145
+ private describeKey;
1146
+ /**
1147
+ * Build the option bag forwarded into a nested container's `run` /
1148
+ * `runSync`. Single source of truth for what a child inherits, so a new
1149
+ * run option is threaded downward in one place instead of three.
1150
+ */
1151
+ private buildChildRunOptions;
1152
+ /**
1153
+ * Build the context object handed to a mounted validator.
1154
+ */
1155
+ private buildValidatorContext;
1393
1156
  /**
1394
1157
  * Lookup helper for the per-mount result cache.
1395
1158
  *
@@ -1422,15 +1185,37 @@ declare class Container<T extends Record<string, any> = Record<string, any>, C =
1422
1185
  private writeCachedOutcome;
1423
1186
  private resolveContainerFilters;
1424
1187
  /**
1425
- * Prepend `keyParts` to a child issue's `path` and — when the child is
1426
- * an `IssueGroup` — recurse into its nested issues so every leaf carries
1427
- * the parent prefix. Without recursion, a child container that already
1428
- * wrapped its own multi-issue mount in a group (or a `oneOf` child) would
1429
- * surface inner items with paths missing the parent segment, breaking
1430
- * downstream consumers that rely on `flattenIssueItems` for per-field
1431
- * lookup (e.g. `@validup/vue`).
1188
+ * Resolve the effective `pathsStrict` flag. Run-level wins over
1189
+ * container-level; unset anywhere is `false` (the silent, back-compatible
1190
+ * default).
1432
1191
  */
1433
- private prefixIssuePath;
1192
+ private resolvePathsStrict;
1193
+ /**
1194
+ * Structural pre-flight for `pathsStrict`. Verifies every resolved
1195
+ * `pathsToInclude` / `pathsToExclude` entry is satisfied by *this*
1196
+ * container — either an exact match against an expanded mount key, or a
1197
+ * prefix descent into a container mount (whose child re-checks the
1198
+ * forwarded remainder, since `pathsStrict` threads downward). Anything
1199
+ * unmatched throws {@link PathsStrictViolationError} with absolute paths.
1200
+ *
1201
+ * No-ops unless strict is on AND at least one filter list is present, so
1202
+ * the overhead on the common (non-strict) path is a single `??` chain.
1203
+ *
1204
+ * Notes on the match rules (kept in lockstep with `resolvePathFilter`):
1205
+ * - Keyless container mounts share the parent namespace and receive the
1206
+ * filter list verbatim, so a path could be owned by the keyless child
1207
+ * OR by a keyed sibling here — the parent can't tell without recursing.
1208
+ * To avoid false positives it treats every entry as satisfied when any
1209
+ * keyless container is present, and `pathsStrict` is NOT forwarded into
1210
+ * keyless children (that would throw for parent-sibling paths). Net:
1211
+ * keyless subtrees are a strict blind spot ("out of scope" per the issue).
1212
+ * - Group filtering is intentionally ignored: a mount excluded from the
1213
+ * active group still exists, so a path targeting it is not "stale".
1214
+ * - Expansion uses the same `expandPath(data, item.path)` the run loop
1215
+ * uses, so glob mounts are matched against the keys they actually
1216
+ * expand to for the given `data`.
1217
+ */
1218
+ private assertPathsStrict;
1434
1219
  /**
1435
1220
  * Translate a throw raised by one execution step (one validator or
1436
1221
  * nested-container invocation, from the surrounding `run` loop) into
@@ -1486,12 +1271,50 @@ declare class Container<T extends Record<string, any> = Record<string, any>, C =
1486
1271
  protected initialize(): void;
1487
1272
  }
1488
1273
  //#endregion
1274
+ //#region src/container/paths-strict-violation.d.ts
1275
+ type PathsStrictViolationInput = {
1276
+ pathsToInclude?: string[];
1277
+ pathsToExclude?: string[];
1278
+ };
1279
+ /**
1280
+ * Thrown by a `Container` run (all variants) when `pathsStrict` is enabled and
1281
+ * one or more `pathsToInclude` / `pathsToExclude` entries matched **no mount** —
1282
+ * neither an exact key match nor a prefix descent into a container mount. It
1283
+ * signals a misconfigured validator graph (typically a mount key that was
1284
+ * renamed out from under a caller's static path list), NOT a validation failure
1285
+ * of the input.
1286
+ *
1287
+ * Like `RunSyncViolationError` it is structural, so the per-mount catch and
1288
+ * `safeRun` / `safeRunSync` re-throw it verbatim instead of folding it into the
1289
+ * issue list or a `Result.failure`. Unlike `RunSyncViolationError` it IS
1290
+ * exported from the package barrel — the whole point is that consumers catch it,
1291
+ * read `pathsToInclude` / `pathsToExclude`, and surface which paths went stale.
1292
+ *
1293
+ * The reported paths are **absolute** (prefixed with the owning container's
1294
+ * `path` when the violation happens inside a nested container), so a caller sees
1295
+ * `user.email` rather than the child-local `email`.
1296
+ */
1297
+ declare class PathsStrictViolationError extends Error {
1298
+ readonly name = "PathsStrictViolationError";
1299
+ /** Absolute `pathsToInclude` entries that matched no mount. */
1300
+ readonly pathsToInclude: string[];
1301
+ /** Absolute `pathsToExclude` entries that matched no mount. */
1302
+ readonly pathsToExclude: string[];
1303
+ constructor(input: PathsStrictViolationInput);
1304
+ }
1305
+ /**
1306
+ * Duck-typed check — robust against `instanceof` mismatches when a duplicate
1307
+ * copy of the package exists in the dependency tree, or when the throw crosses
1308
+ * a realm boundary. Mirrors the `isValidupError` / `isRunSyncViolation` pattern.
1309
+ */
1310
+ declare function isPathsStrictViolation(e: unknown): e is PathsStrictViolationError;
1311
+ //#endregion
1489
1312
  //#region src/builder/types.d.ts
1490
1313
  /**
1491
1314
  * Cosmetic helper — flattens an intersection so editors render
1492
1315
  * `{ foo: string; bar: number }` instead of `{ foo: string } & { bar: number }`.
1493
1316
  */
1494
- type Spread<T> = { [K in keyof T]: T[K] };
1317
+ type Spread<T> = { [K in keyof T]: T[K]; };
1495
1318
  /**
1496
1319
  * Anything that can be mounted under a key on a `Builder`: a leaf validator,
1497
1320
  * a nested builder (auto-`.build()`-ed), or an existing `Container`.
@@ -1519,7 +1342,7 @@ type IsOptional<O> = O extends {
1519
1342
  * matching the runtime behavior that an optional mount may be skipped, leaving
1520
1343
  * the key absent from the output.
1521
1344
  */
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> } : { [P in K]: Awaited<Out> } : never;
1345
+ 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
1346
  /**
1524
1347
  * Compile-time-typed schema builder. `mount(...)` accumulates the resolved
1525
1348
  * field type into `T`, so `build()` returns a `Container<T, C>` whose static
@@ -1550,6 +1373,12 @@ interface IBuilder<T extends Record<string, any>, C = unknown> {
1550
1373
  pathsToInclude(...paths: (keyof T & string)[]): IBuilder<T, C>;
1551
1374
  /** Restrict the resulting container's `pathsToExclude`. */
1552
1375
  pathsToExclude(...paths: (keyof T & string)[]): IBuilder<T, C>;
1376
+ /**
1377
+ * Set the resulting container's `pathsStrict` flag (defaults to `true`) —
1378
+ * fail loud when a `pathsToInclude` / `pathsToExclude` entry matches no
1379
+ * mount.
1380
+ */
1381
+ pathsStrict(strict?: boolean): IBuilder<T, C>;
1553
1382
  /** Materialize a `Container<T, C>` and replay every accumulated mount. */
1554
1383
  build(): Container<T, C>;
1555
1384
  }
@@ -1576,6 +1405,7 @@ declare class Builder<T extends Record<string, any>, C> implements IBuilder<T, C
1576
1405
  oneOf(): IBuilder<T, C>;
1577
1406
  pathsToInclude(...paths: (keyof T & string)[]): IBuilder<T, C>;
1578
1407
  pathsToExclude(...paths: (keyof T & string)[]): IBuilder<T, C>;
1408
+ pathsStrict(strict?: boolean): IBuilder<T, C>;
1579
1409
  build(): Container<T, C>;
1580
1410
  }
1581
1411
  /**
@@ -1595,5 +1425,5 @@ declare function hasOwnProperty<X extends {}, Y extends PropertyKey>(obj: X, pro
1595
1425
  //#region src/utils/object.d.ts
1596
1426
  declare function isObject(input: unknown): input is Record<string, any>;
1597
1427
  //#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 };
1428
+ export { BaseMount, BuildOneOfFailedGroupOptions, Builder, ComposeElement, ComposeOptions, Container, ContainerInput, ContainerMount, ContainerOptions, ContainerRunOptions, ErrorToIssuesOptions, GroupKey, IBuilder, IContainer, IResultCache, IsOptional, Mount, MountOptions, MountTarget, Mounted, ObjectLiteral, OptionalValue, OptionalValueInput, PathFilterResolution, PathsStrictViolationError, PathsStrictViolationInput, Result, ResultCache, ResultCacheEntry, ResultCacheOutcome, ResultCacheSnapshot, ResultFailure, ResultSuccess, Spread, Validator, ValidatorContext, ValidatorDescriptor, ValidatorMount, ValidupError, buildErrorMessageForAttribute, buildErrorMessageForAttributes, buildOneOfFailedGroup, compose, composeOneOf, createValidupError, defineSchema, defineValidator, errorToIssues, hasOwnProperty, isContainer, isError, isObject, isOptionalValue, isPathsStrictViolation, isResultCache, isValidatorDescriptor, isValidupError, resolveDefaults, resolvePathFilter, stringifyPath };
1599
1429
  //# sourceMappingURL=index.d.mts.map