@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/cli.cjs +20 -22
- package/dist/index.cjs +2 -2
- package/dist/index.mjs +2 -2
- package/dist/{plugin-Bx7j-vWf.mjs → plugin-DUInOy5v.mjs} +1 -1
- package/dist/{plugin-JJ9MJ6AF.cjs → plugin-lDfE9qm8.cjs} +1 -1
- package/dist/realm-runtime.js +339 -177
- package/dist/test-utils.cjs +2 -2
- package/dist/test-utils.mjs +2 -2
- package/dist/{user-text-Dl8FNKLL.cjs → user-text-BvyErcKK.cjs} +29 -35
- package/dist/{user-text-BOf56N4d.mjs → user-text-DZR5hfLa.mjs} +24 -24
- package/dist/utils.cjs +317 -155
- package/dist/utils.d.ts +26 -12
- package/dist/utils.mjs +317 -155
- package/package.json +2 -2
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
|
|
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
|
|
711
|
-
*
|
|
712
|
-
*
|
|
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
|
|
900
|
-
* (`static toJsonSchema()`), with the `jsonSchemaOptions` of the build (the same
|
|
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
|
-
*
|
|
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
|
|
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
|
-
/** `
|
|
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
|
/**
|