@atscript/typescript 0.2.5 → 0.2.6

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/utils.d.ts CHANGED
@@ -667,9 +667,19 @@ declare function isAnnotatedTypeOfPrimitive(t: TAtscriptAnnotatedType): boolean;
667
667
  * - Strings targeting `number` are trimmed and parsed via `Number()`; only
668
668
  * finite results are accepted.
669
669
  * - Strings targeting `boolean` accept `"true"/"1"` and `"false"/"0"`.
670
- * - Unions try each branch in declared order; the first successful parse wins.
670
+ * - Unions pick one branch and coerce the value against it only (linear, no
671
+ * backtracking). A scalar branch takes what it parses; an object (tuple)
672
+ * branch takes a plain object (an array of its length) unless a literal
673
+ * property (item) — `kind: 'cat'`, `kind: 'cat' | null` — holds a value that
674
+ * does not coerce to it, a string compared after the normalizers of the
675
+ * literal and of the unions it is in. An object takes the branch its
676
+ * discriminator names (as the validator does: the literal itself first, else
677
+ * `"2"` names a `2` literal), else the first whose shape it has (required
678
+ * props present, no undeclared key), else the first that takes it. When no
679
+ * branch takes the value, it is returned untouched.
671
680
  * - Objects recurse into props when the input is a plain object (covers
672
- * `@Query()` DTOs where every field arrives as a string).
681
+ * `@Query()` DTOs where every field arrives as a string), whatever their
682
+ * literal props hold unless tried as a union branch.
673
683
  * - Arrays and tuples coerce items; intersections apply each member in order.
674
684
  * - `string` / `decimal` targets never change string input.
675
685
  *
@@ -707,9 +717,11 @@ declare function coerceScalar(designType: TAtscriptTypeFinal['designType'], valu
707
717
  * `detectDiscriminator`) uses the branch the value's discriminator names;
708
718
  * - otherwise every branch that can take the value is tried (a literal branch can take a string
709
719
  * only when the normalized string equals its literal): when they all give the same result it
710
- * is used; when they differ, the branches whose result their own validator accepts (default
711
- * options) are kept, and the result is used when they agree; else the value is returned
712
- * untouched (ambiguous).
720
+ * is used; when they differ, the branches whose result their own validator accepts are kept,
721
+ * and the result is used when they agree; else the value is returned untouched (ambiguous).
722
+ * The branch validators take `opts` — pass the options the result will be validated with
723
+ * (`partial`, `unknownProps`, …) so a branch is judged as the validator will judge it; default
724
+ * options when omitted. (`unknownProps: 'strip'` judges as `'ignore'`: nothing is stripped.)
713
725
  *
714
726
  * The intended flow is `coerceForType` → `normalizeForType` → `validate`.
715
727
  *
@@ -717,9 +729,11 @@ declare function coerceScalar(designType: TAtscriptTypeFinal['designType'], valu
717
729
  * ```ts
718
730
  * // @normalize.trim @normalize.lowercase email: string.email
719
731
  * normalizeForType(User, { email: ' Ann@Example.COM ' }) // → { email: 'ann@example.com' }
732
+ * // judged as a partial update will be validated
733
+ * normalizeForType(Patch, body, { partial: true })
720
734
  * ```
721
735
  */
722
- declare function normalizeForType<T = unknown>(def: TAtscriptAnnotatedType, value: T): T;
736
+ declare function normalizeForType<T = unknown>(def: TAtscriptAnnotatedType, value: T, opts?: Partial<TValidatorOptions>): T;
723
737
 
724
738
  /** A JSON Schema object (draft-compatible). */
725
739
  type TJsonSchema = Record<string, any>;
@@ -896,9 +910,9 @@ declare function throwFeatureDisabled(feature: string, option: string, annotatio
896
910
 
897
911
  /**
898
912
  * The JSON schema of `type` built by the runtime (`jsonSchema: 'lazy'`): built once, again after
899
- * a metadata write (a block, a runtime edit: see `metadataWrites`). Called by generated code
900
- * (`static toJsonSchema()`), with the `jsonSchemaOptions` of the build (the same for every call
901
- * of a type).
913
+ * a type tree write (a block, a runtime edit of metadata or shape: see `typeWrites`). Called by
914
+ * generated code (`static toJsonSchema()`), with the `jsonSchemaOptions` of the build (the same
915
+ * for every call of a type).
902
916
  */
903
917
  declare function lazyJsonSchema(type: TAtscriptAnnotatedType, opts?: TJsonSchemaOptions): TJsonSchema;
904
918
  /**
@@ -1313,7 +1327,7 @@ declare function translateServed<T>(json: T, t: (text: string) => string | undef
1313
1327
  * a base shows through every layer over it.
1314
1328
  *
1315
1329
  * Reads go through a flattened view of the effective entries, rebuilt on the first read after any
1316
- * metadata write (one global write counter: `metadataWriteCount`). The view is used only while
1330
+ * type tree write (one global write counter: `typeWriteCount`). The view is used only while
1317
1331
  * every map below is tracked (an `AnnotationMap` or a `LayerMap`, whose writes the counter
1318
1332
  * sees); otherwise the reads are live. A raw write the counter does not see (a node's map swapped,
1319
1333
  * `node.metadata = X`, or edited in place) must be followed by `invalidateCompiledValidators()`,
@@ -1338,11 +1352,11 @@ declare class LayerMap<K = unknown, V = unknown> extends AnnotationMap<K, V> {
1338
1352
  r: boolean;
1339
1353
  /**
1340
1354
  * The flattened view: every effective entry (as the layered reads give it, in their order),
1341
- * built on the first read after a metadata write (`w` ≠ `metadataWrites`); `undefined` while a
1355
+ * built on the first read after a type tree write (`w` ≠ `typeWrites`); `undefined` while a
1342
1356
  * map below is not tracked (a plain `Map` or a subclass: its writes are not counted, read live).
1343
1357
  */
1344
1358
  private f;
1345
- /** `metadataWrites` when {@link f} was built (`-1`: not built). */
1359
+ /** `typeWrites` when {@link f} was built (`-1`: not built). */
1346
1360
  private w;
1347
1361
  constructor(bases: TLayerNode[], reference?: boolean, own?: Iterable<readonly [K, V]> | null);
1348
1362
  /**