@atscript/typescript 0.1.109 → 0.1.110
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 +1587 -189
- package/dist/index.cjs +5 -2
- package/dist/index.d.ts +53 -1
- package/dist/index.mjs +3 -3
- package/dist/{json-schema-CioBVi6F.mjs → json-schema-B3iAqkGQ.cjs} +919 -37
- package/dist/{json-schema-9OBvrg9D.cjs → json-schema-BG1SEcjI.mjs} +618 -120
- package/dist/{plugin-D3_BnRrI.mjs → plugin-DpzE8aJr.mjs} +955 -116
- package/dist/{plugin-6r27w6rG.cjs → plugin-mzTvme4k.cjs} +966 -115
- package/dist/test-utils.cjs +4 -4
- package/dist/test-utils.d.ts +53 -0
- package/dist/test-utils.mjs +4 -4
- package/dist/utils.cjs +14 -26
- package/dist/utils.d.ts +81 -2
- package/dist/utils.mjs +13 -27
- package/package.json +3 -3
package/dist/test-utils.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_plugin = require('./plugin-
|
|
3
|
-
require('./json-schema-
|
|
2
|
+
const require_plugin = require('./plugin-mzTvme4k.cjs');
|
|
3
|
+
require('./json-schema-B3iAqkGQ.cjs');
|
|
4
4
|
let path = require("path");
|
|
5
5
|
path = require_plugin.__toESM(path);
|
|
6
6
|
let _atscript_core = require("@atscript/core");
|
|
@@ -15,10 +15,10 @@ let fs = require("fs");
|
|
|
15
15
|
* Files are only written when their content changed, so repeat runs
|
|
16
16
|
* don't touch mtimes of up-to-date artifacts.
|
|
17
17
|
*/ async function prepareFixtures(options) {
|
|
18
|
-
const { rootDir, plugins = [], entries, include, formats = ["js", "dts"] } = options;
|
|
18
|
+
const { rootDir, plugins = [], entries, include, formats = ["js", "dts"], tsPluginOptions } = options;
|
|
19
19
|
const repo = await (0, _atscript_core.build)({
|
|
20
20
|
rootDir,
|
|
21
|
-
plugins: [require_plugin.tsPlugin(), ...plugins],
|
|
21
|
+
plugins: [require_plugin.tsPlugin(tsPluginOptions), ...plugins],
|
|
22
22
|
...entries ? { entries } : { include: include ?? ["**/*.as"] }
|
|
23
23
|
});
|
|
24
24
|
const results = await Promise.all(formats.map((format) => repo.generate({
|
package/dist/test-utils.d.ts
CHANGED
|
@@ -1,5 +1,56 @@
|
|
|
1
1
|
import { TAtscriptPlugin } from '@atscript/core';
|
|
2
2
|
|
|
3
|
+
interface TTsPluginOptions {
|
|
4
|
+
/**
|
|
5
|
+
* JSON Schema support mode:
|
|
6
|
+
* - `false` — No support. `toJsonSchema()` throws at runtime. No `buildJsonSchema` import. *(default)*
|
|
7
|
+
* - `'lazy'` — Import `buildJsonSchema`, compute on demand, cache in type object.
|
|
8
|
+
* - `'bundle'` — Pre-compute at build time, embed static JSON in output. No import.
|
|
9
|
+
*
|
|
10
|
+
* Individual interfaces can override this with `@emit.jsonSchema` annotation
|
|
11
|
+
* to force build-time embedding regardless of this setting.
|
|
12
|
+
*/
|
|
13
|
+
jsonSchema?: false | 'lazy' | 'bundle';
|
|
14
|
+
/**
|
|
15
|
+
* Example data support:
|
|
16
|
+
* - `false` — No support. `toExampleData` is not rendered. *(default)*
|
|
17
|
+
* - `true` — Import `createDataFromAnnotatedType`, create example data on each call.
|
|
18
|
+
*/
|
|
19
|
+
exampleData?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Extension the emitted JS uses for **relative** `.as` imports
|
|
22
|
+
* (`./user` → `./user.as` by default). Bare specifiers (packages, e.g.
|
|
23
|
+
* `some-pkg/models/user.as`) always keep `.as` because they resolve through
|
|
24
|
+
* the package's `exports` map.
|
|
25
|
+
*
|
|
26
|
+
* `.as.mjs` is what `asc db sync` uses to load the compiled models straight
|
|
27
|
+
* from Node. *(default: `'.as'`)*
|
|
28
|
+
*/
|
|
29
|
+
moduleExtension?: '.as' | '.as.js' | '.as.mjs';
|
|
30
|
+
/**
|
|
31
|
+
* Emit a build-time compiled validator check per type into the `.as.js` output.
|
|
32
|
+
*
|
|
33
|
+
* `validate()` then runs the type's compiled check instead of the interpreted pre-check
|
|
34
|
+
* (results and errors are identical; only speed differs). The check binds to the live
|
|
35
|
+
* type on first use and re-binds after mutations made through `annotate()`, the
|
|
36
|
+
* metadata / props `Map` methods, the `defineAnnotatedType()` handle and `cloneRefProp()`.
|
|
37
|
+
* Raw writes need `invalidateCompiledValidators()`: property writes (`node.optional = …`,
|
|
38
|
+
* `type.items.push(…)`, …) and in-place edits of annotation values (mutating a constraint
|
|
39
|
+
* object, pushing onto an `@expect.pattern` array directly) — the check keeps the values
|
|
40
|
+
* it bound until then. Any runtime mutation of a type a check has bound to makes the
|
|
41
|
+
* checks re-bind once on next use: cheap at startup, but avoid it per request. Types it
|
|
42
|
+
* cannot bind to, and types not built from generated modules (deserialised,
|
|
43
|
+
* JSON-schema-built, flattened, hand-built), are validated by the interpreted path as
|
|
44
|
+
* before.
|
|
45
|
+
*
|
|
46
|
+
* Adds code to every `.as.js`: meant for backend builds — leave it off for bundles
|
|
47
|
+
* shipped to browsers (the code is CSP-safe: no `eval` / `new Function`). The
|
|
48
|
+
* `'js:compiled'` / `'js:interpreted'` render formats force it on / off per render.
|
|
49
|
+
* *(default: `false`)*
|
|
50
|
+
*/
|
|
51
|
+
compileValidators?: boolean;
|
|
52
|
+
}
|
|
53
|
+
|
|
3
54
|
interface PrepareFixturesOptions {
|
|
4
55
|
/** Absolute directory containing the `.as` fixture files. */
|
|
5
56
|
rootDir: string;
|
|
@@ -11,6 +62,8 @@ interface PrepareFixturesOptions {
|
|
|
11
62
|
entries?: string[];
|
|
12
63
|
/** Output formats to generate; defaults to `['js', 'dts']`. */
|
|
13
64
|
formats?: Array<'js' | 'dts'>;
|
|
65
|
+
/** Options of the auto-injected `tsPlugin()` (e.g. `{ compileValidators: true }`). */
|
|
66
|
+
tsPluginOptions?: TTsPluginOptions;
|
|
14
67
|
}
|
|
15
68
|
/**
|
|
16
69
|
* Compiles `.as` fixture files under `rootDir` and writes the generated
|
package/dist/test-utils.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "./json-schema-
|
|
1
|
+
import { r as tsPlugin } from "./plugin-DpzE8aJr.mjs";
|
|
2
|
+
import "./json-schema-BG1SEcjI.mjs";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import { build } from "@atscript/core";
|
|
5
5
|
import { readFileSync, writeFileSync } from "fs";
|
|
@@ -13,10 +13,10 @@ import { readFileSync, writeFileSync } from "fs";
|
|
|
13
13
|
* Files are only written when their content changed, so repeat runs
|
|
14
14
|
* don't touch mtimes of up-to-date artifacts.
|
|
15
15
|
*/ async function prepareFixtures(options) {
|
|
16
|
-
const { rootDir, plugins = [], entries, include, formats = ["js", "dts"] } = options;
|
|
16
|
+
const { rootDir, plugins = [], entries, include, formats = ["js", "dts"], tsPluginOptions } = options;
|
|
17
17
|
const repo = await build({
|
|
18
18
|
rootDir,
|
|
19
|
-
plugins: [tsPlugin(), ...plugins],
|
|
19
|
+
plugins: [tsPlugin(tsPluginOptions), ...plugins],
|
|
20
20
|
...entries ? { entries } : { include: include ?? ["**/*.as"] }
|
|
21
21
|
});
|
|
22
22
|
const results = await Promise.all(formats.map((format) => repo.generate({
|
package/dist/utils.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_json_schema = require('./json-schema-
|
|
2
|
+
const require_json_schema = require('./json-schema-B3iAqkGQ.cjs');
|
|
3
3
|
|
|
4
4
|
//#region packages/typescript/src/runtime/coerce.ts
|
|
5
5
|
/**
|
|
@@ -741,15 +741,10 @@ function serializeMetadata(owner, site, options, state) {
|
|
|
741
741
|
return deserializeNode(data, /* @__PURE__ */ new Map());
|
|
742
742
|
}
|
|
743
743
|
function emptyObjectTypeDef() {
|
|
744
|
-
return
|
|
745
|
-
kind: "object",
|
|
746
|
-
props: /* @__PURE__ */ new Map(),
|
|
747
|
-
propsPatterns: [],
|
|
748
|
-
tags: /* @__PURE__ */ new Set()
|
|
749
|
-
};
|
|
744
|
+
return require_json_schema.createObjectTypeDef();
|
|
750
745
|
}
|
|
751
746
|
function toMetadataMap(record) {
|
|
752
|
-
return
|
|
747
|
+
return require_json_schema.createMetadataMap(Object.entries(record));
|
|
753
748
|
}
|
|
754
749
|
function deserializeRef(data, resolved) {
|
|
755
750
|
if (!data.ref) return;
|
|
@@ -771,7 +766,7 @@ function deserializeNode(data, resolved) {
|
|
|
771
766
|
if (data.type.kind === "$ref") {
|
|
772
767
|
const { id: refId, own } = data.type;
|
|
773
768
|
const target = resolved.get(refId);
|
|
774
|
-
if (!own) return target || require_json_schema.createAnnotatedTypeNode(emptyObjectTypeDef(),
|
|
769
|
+
if (!own) return target || require_json_schema.createAnnotatedTypeNode(emptyObjectTypeDef(), require_json_schema.createMetadataMap(), { id: refId });
|
|
775
770
|
const node = require_json_schema.createAnnotatedTypeNode(target?.type ?? emptyObjectTypeDef(), toMetadataMap(data.metadata), {
|
|
776
771
|
id: refId,
|
|
777
772
|
optional: data.optional || void 0,
|
|
@@ -824,17 +819,13 @@ function deserializeTypeDef(t, resolved) {
|
|
|
824
819
|
return result;
|
|
825
820
|
}
|
|
826
821
|
case "object": {
|
|
827
|
-
const
|
|
828
|
-
for (const [key, val] of Object.entries(t.props)) props.set(key, deserializeNode(val, resolved));
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
def: deserializeNode(pp.def, resolved)
|
|
835
|
-
})),
|
|
836
|
-
tags
|
|
837
|
-
};
|
|
822
|
+
const def = require_json_schema.createObjectTypeDef(tags);
|
|
823
|
+
for (const [key, val] of Object.entries(t.props)) def.props.set(key, deserializeNode(val, resolved));
|
|
824
|
+
def.propsPatterns = t.propsPatterns.map((pp) => ({
|
|
825
|
+
pattern: new RegExp(pp.pattern.source, pp.pattern.flags),
|
|
826
|
+
def: deserializeNode(pp.def, resolved)
|
|
827
|
+
}));
|
|
828
|
+
return def;
|
|
838
829
|
}
|
|
839
830
|
case "array": return {
|
|
840
831
|
kind: "array",
|
|
@@ -851,12 +842,7 @@ function deserializeTypeDef(t, resolved) {
|
|
|
851
842
|
case "$ref": {
|
|
852
843
|
const existing = resolved.get(t.id);
|
|
853
844
|
if (existing) return existing.type;
|
|
854
|
-
return
|
|
855
|
-
kind: "object",
|
|
856
|
-
props: /* @__PURE__ */ new Map(),
|
|
857
|
-
propsPatterns: [],
|
|
858
|
-
tags
|
|
859
|
-
};
|
|
845
|
+
return require_json_schema.createObjectTypeDef(tags);
|
|
860
846
|
}
|
|
861
847
|
default: throw new Error(`Unknown serialized type kind "${t.kind}"`);
|
|
862
848
|
}
|
|
@@ -879,9 +865,11 @@ exports.detectDiscriminator = require_json_schema.detectDiscriminator;
|
|
|
879
865
|
exports.flattenAnnotatedType = flattenAnnotatedType;
|
|
880
866
|
exports.forAnnotatedType = require_json_schema.forAnnotatedType;
|
|
881
867
|
exports.fromJsonSchema = require_json_schema.fromJsonSchema;
|
|
868
|
+
exports.invalidateCompiledValidators = require_json_schema.invalidateCompiledValidators;
|
|
882
869
|
exports.isAnnotatedType = require_json_schema.isAnnotatedType;
|
|
883
870
|
exports.isAnnotatedTypeOfPrimitive = require_json_schema.isAnnotatedTypeOfPrimitive;
|
|
884
871
|
exports.isPhantomType = require_json_schema.isPhantomType;
|
|
885
872
|
exports.mergeJsonSchemas = require_json_schema.mergeJsonSchemas;
|
|
873
|
+
exports.registerCompiledCheck = require_json_schema.registerCompiledCheck;
|
|
886
874
|
exports.serializeAnnotatedType = serializeAnnotatedType;
|
|
887
875
|
exports.throwFeatureDisabled = throwFeatureDisabled;
|
package/dist/utils.d.ts
CHANGED
|
@@ -133,8 +133,13 @@ declare class ValidatorError extends Error {
|
|
|
133
133
|
/**
|
|
134
134
|
* Creates a minimal annotated type node from a type def and metadata map.
|
|
135
135
|
* Centralises the shape so callers never duplicate the boilerplate.
|
|
136
|
+
*
|
|
137
|
+
* `metadata` is used as-is (the node keeps the caller's map, so later writes through it
|
|
138
|
+
* apply). When omitted, the node gets a new, tracked metadata map. Compiled validator
|
|
139
|
+
* checks only bind to nodes whose metadata is tracked; nodes built over a caller-supplied
|
|
140
|
+
* `Map` are always validated by the interpreted validator.
|
|
136
141
|
*/
|
|
137
|
-
declare function createAnnotatedTypeNode(type: TAtscriptTypeDef, metadata
|
|
142
|
+
declare function createAnnotatedTypeNode(type: TAtscriptTypeDef, metadata?: Map<string, unknown> | TMetadataMap<AtscriptMetadata>, opts?: {
|
|
138
143
|
id?: string;
|
|
139
144
|
optional?: boolean;
|
|
140
145
|
ref?: {
|
|
@@ -497,6 +502,80 @@ declare function createDataFromAnnotatedType(type: TAtscriptAnnotatedType, opts?
|
|
|
497
502
|
*/
|
|
498
503
|
declare function throwFeatureDisabled(feature: string, option: string, annotation: string): never;
|
|
499
504
|
|
|
505
|
+
type TSite = [optional: number, mask: number, def: number, shape: string, slot: number];
|
|
506
|
+
type TDef = Array<string | number | boolean | string[] | TSite | TSite[]>;
|
|
507
|
+
type TLayout = [defs: TDef[], root: TSite, slotCount: number];
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* Runtime registry and binder of build-time compiled validator checks.
|
|
511
|
+
*
|
|
512
|
+
* Generated `.as.js` modules (built with `tsPlugin({ compileValidators: true })`) call
|
|
513
|
+
* {@link registerCompiledCheck} once per class with the class's layout and a factory of
|
|
514
|
+
* its check. On first use, and again after each mutation epoch (see tracking.ts), the
|
|
515
|
+
* entry is bound: `bindLayout` verifies the live type tree against the layout and collects
|
|
516
|
+
* the constraint values into `K`; the factory turns `K` into the check function. A tree
|
|
517
|
+
* that no longer matches leaves the entry unbound for that epoch, so the interpreted
|
|
518
|
+
* pre-check runs instead — always correct, never stale.
|
|
519
|
+
*
|
|
520
|
+
* A registered entry is also a template: a node referencing a class of another module
|
|
521
|
+
* (an `EXT` site) binds that class's layout against itself — its own annotations feed `K`
|
|
522
|
+
* — so cross-module references, aliases of imported types and cloned imported props run
|
|
523
|
+
* compiled code whenever their tree matches the referenced type's structure.
|
|
524
|
+
*
|
|
525
|
+
* The registry is module-local: classes registered with another copy of this runtime
|
|
526
|
+
* (dual ESM / CJS loads, duplicate installs) and subclasses of registered classes are
|
|
527
|
+
* simply validated by the interpreted pre-check.
|
|
528
|
+
*/
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* A compiled check: `(value, flags, opts) → 0 FAIL | 1 PASS | 2 BAIL` (the pre-check
|
|
532
|
+
* contract; `flags` carries the TOP / IN_UNION bits and the option bits, see
|
|
533
|
+
* {@link optionFlags}).
|
|
534
|
+
*/
|
|
535
|
+
type TCompiledCheck = (value: unknown, flags: number, opts: TValidatorOptions) => number;
|
|
536
|
+
/** Factory emitted per class: builds the check from the bound annotation values. */
|
|
537
|
+
type TCompiledFactory = (K: unknown[], H: TCompiledHelpers) => TCompiledCheck;
|
|
538
|
+
/** Runtime helpers the emitted factories use. */
|
|
539
|
+
interface TCompiledHelpers {
|
|
540
|
+
/** Pending top-level strips (shared with the interpreted pre-check). */
|
|
541
|
+
pk: string[];
|
|
542
|
+
/** `Object.prototype.hasOwnProperty`. */
|
|
543
|
+
ho: (this: object, key: PropertyKey) => boolean;
|
|
544
|
+
/** Decimal-string regex. */
|
|
545
|
+
dec: RegExp;
|
|
546
|
+
/** `rejectsNullAsRequired` (read live: it depends on the node's whole subtree). */
|
|
547
|
+
rn: (def: TAtscriptAnnotatedType) => boolean;
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Registers the build-time compiled validator check of a generated class (emitted into
|
|
551
|
+
* `.as.js` by `tsPlugin({ compileValidators: true })`; not meant to be called by hand).
|
|
552
|
+
* A layout of another format version is ignored, so the class stays interpreted.
|
|
553
|
+
*/
|
|
554
|
+
declare function registerCompiledCheck(cls: TAtscriptAnnotatedType, version: number, layout: TLayout, factory: TCompiledFactory): void;
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* Makes every compiled validator check re-verify the type tree it was compiled for before
|
|
558
|
+
* its next use.
|
|
559
|
+
*
|
|
560
|
+
* Compiled checks (emitted with `tsPlugin({ compileValidators: true })`) see mutations made
|
|
561
|
+
* through `annotate()`, the metadata / props `Map` methods, the `defineAnnotatedType()`
|
|
562
|
+
* handle methods and `cloneRefProp()` automatically. Call this after changing a type tree
|
|
563
|
+
* any other way:
|
|
564
|
+
* - a raw property write: `node.optional = …`, `node.type = …`, `node.metadata = …`,
|
|
565
|
+
* `type.items.push(…)`, `type.of = …`, `type.propsPatterns.push(…)`;
|
|
566
|
+
* - an in-place edit of an annotation value: mutating a constraint object
|
|
567
|
+
* (`metadata.get('expect.min').minValue = 5`), editing or pushing onto an
|
|
568
|
+
* `@expect.pattern` array directly (use `annotate(metadata, key, value, true)` instead).
|
|
569
|
+
*
|
|
570
|
+
* Without it the compiled check may keep validating against the old shape or values.
|
|
571
|
+
* Types without compiled checks are always read live and never need it.
|
|
572
|
+
*
|
|
573
|
+
* Any mutation of a type a compiled check has bound to (tracked or invalidated) makes every
|
|
574
|
+
* compiled check re-bind once on its next use: cheap during startup / configuration, but
|
|
575
|
+
* avoid mutating validated types per request.
|
|
576
|
+
*/
|
|
577
|
+
declare function invalidateCompiledValidators(): void;
|
|
578
|
+
|
|
500
579
|
/**
|
|
501
580
|
* Options for controlling the flattening process.
|
|
502
581
|
*/
|
|
@@ -749,5 +828,5 @@ type NavPropsOf<T> = T extends {
|
|
|
749
828
|
__navProps: infer N extends Record<string, unknown>;
|
|
750
829
|
} ? N : Record<string, never>;
|
|
751
830
|
|
|
752
|
-
export { SERIALIZE_VERSION, Validator, ValidatorError, annotate, buildJsonSchema, cloneRefProp, coerceForType, coerceScalar, createAnnotatedTypeNode, createDataFromAnnotatedType, defineAnnotatedType, deserializeAnnotatedType, detectDiscriminator, flattenAnnotatedType, forAnnotatedType, fromJsonSchema, isAnnotatedType, isAnnotatedTypeOfPrimitive, isPhantomType, mergeJsonSchemas, serializeAnnotatedType, throwFeatureDisabled };
|
|
831
|
+
export { SERIALIZE_VERSION, Validator, ValidatorError, annotate, buildJsonSchema, cloneRefProp, coerceForType, coerceScalar, createAnnotatedTypeNode, createDataFromAnnotatedType, defineAnnotatedType, deserializeAnnotatedType, detectDiscriminator, flattenAnnotatedType, forAnnotatedType, fromJsonSchema, invalidateCompiledValidators, isAnnotatedType, isAnnotatedTypeOfPrimitive, isPhantomType, mergeJsonSchemas, registerCompiledCheck, serializeAnnotatedType, throwFeatureDisabled };
|
|
753
832
|
export type { AtscriptExprNode, AtscriptOrderItem, AtscriptQueryComparison, AtscriptQueryFieldRef, AtscriptQueryNode, AtscriptRef, FlatOf, InferDataType, NavPropsOf, OwnPropsOf, PrimaryKeyOf, TAnnotatedTypeHandle, TAtscriptAnnotatedType, TAtscriptAnnotatedTypeConstructor, TAtscriptDataType, TAtscriptTypeArray, TAtscriptTypeComplex, TAtscriptTypeDef, TAtscriptTypeFinal, TAtscriptTypeObject, TCreateDataOptions, TFlattenOptions, TJsonSchema, TMetadataMap, TProcessAnnotationContext, TSerializeOptions, TSerializedAnnotatedType, TSerializedAnnotatedTypeInner, TSerializedTypeArray, TSerializedTypeComplex, TSerializedTypeDef, TSerializedTypeFinal, TSerializedTypeObject, TUnionDiscriminator, TValidatorOptions, TValidatorPlugin, TValidatorPluginContext, TValueResolver };
|
package/dist/utils.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as forAnnotatedType, c as createAnnotatedTypeNode, d as
|
|
1
|
+
import { Y as invalidateCompiledValidators, a as forAnnotatedType, c as createAnnotatedTypeNode, d as defineAnnotatedType, f as isAnnotatedType, g as ValidatorError, h as Validator, i as mergeJsonSchemas, l as createMetadataMap, m as isPhantomType, n as detectDiscriminator, o as annotate, p as isAnnotatedTypeOfPrimitive, r as fromJsonSchema, s as cloneRefProp, t as buildJsonSchema, u as createObjectTypeDef, v as registerCompiledCheck } from "./json-schema-BG1SEcjI.mjs";
|
|
2
2
|
|
|
3
3
|
//#region packages/typescript/src/runtime/coerce.ts
|
|
4
4
|
/**
|
|
@@ -740,15 +740,10 @@ function serializeMetadata(owner, site, options, state) {
|
|
|
740
740
|
return deserializeNode(data, /* @__PURE__ */ new Map());
|
|
741
741
|
}
|
|
742
742
|
function emptyObjectTypeDef() {
|
|
743
|
-
return
|
|
744
|
-
kind: "object",
|
|
745
|
-
props: /* @__PURE__ */ new Map(),
|
|
746
|
-
propsPatterns: [],
|
|
747
|
-
tags: /* @__PURE__ */ new Set()
|
|
748
|
-
};
|
|
743
|
+
return createObjectTypeDef();
|
|
749
744
|
}
|
|
750
745
|
function toMetadataMap(record) {
|
|
751
|
-
return
|
|
746
|
+
return createMetadataMap(Object.entries(record));
|
|
752
747
|
}
|
|
753
748
|
function deserializeRef(data, resolved) {
|
|
754
749
|
if (!data.ref) return;
|
|
@@ -770,7 +765,7 @@ function deserializeNode(data, resolved) {
|
|
|
770
765
|
if (data.type.kind === "$ref") {
|
|
771
766
|
const { id: refId, own } = data.type;
|
|
772
767
|
const target = resolved.get(refId);
|
|
773
|
-
if (!own) return target || createAnnotatedTypeNode(emptyObjectTypeDef(),
|
|
768
|
+
if (!own) return target || createAnnotatedTypeNode(emptyObjectTypeDef(), createMetadataMap(), { id: refId });
|
|
774
769
|
const node = createAnnotatedTypeNode(target?.type ?? emptyObjectTypeDef(), toMetadataMap(data.metadata), {
|
|
775
770
|
id: refId,
|
|
776
771
|
optional: data.optional || void 0,
|
|
@@ -823,17 +818,13 @@ function deserializeTypeDef(t, resolved) {
|
|
|
823
818
|
return result;
|
|
824
819
|
}
|
|
825
820
|
case "object": {
|
|
826
|
-
const
|
|
827
|
-
for (const [key, val] of Object.entries(t.props)) props.set(key, deserializeNode(val, resolved));
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
def: deserializeNode(pp.def, resolved)
|
|
834
|
-
})),
|
|
835
|
-
tags
|
|
836
|
-
};
|
|
821
|
+
const def = createObjectTypeDef(tags);
|
|
822
|
+
for (const [key, val] of Object.entries(t.props)) def.props.set(key, deserializeNode(val, resolved));
|
|
823
|
+
def.propsPatterns = t.propsPatterns.map((pp) => ({
|
|
824
|
+
pattern: new RegExp(pp.pattern.source, pp.pattern.flags),
|
|
825
|
+
def: deserializeNode(pp.def, resolved)
|
|
826
|
+
}));
|
|
827
|
+
return def;
|
|
837
828
|
}
|
|
838
829
|
case "array": return {
|
|
839
830
|
kind: "array",
|
|
@@ -850,16 +841,11 @@ function deserializeTypeDef(t, resolved) {
|
|
|
850
841
|
case "$ref": {
|
|
851
842
|
const existing = resolved.get(t.id);
|
|
852
843
|
if (existing) return existing.type;
|
|
853
|
-
return
|
|
854
|
-
kind: "object",
|
|
855
|
-
props: /* @__PURE__ */ new Map(),
|
|
856
|
-
propsPatterns: [],
|
|
857
|
-
tags
|
|
858
|
-
};
|
|
844
|
+
return createObjectTypeDef(tags);
|
|
859
845
|
}
|
|
860
846
|
default: throw new Error(`Unknown serialized type kind "${t.kind}"`);
|
|
861
847
|
}
|
|
862
848
|
}
|
|
863
849
|
|
|
864
850
|
//#endregion
|
|
865
|
-
export { SERIALIZE_VERSION, Validator, ValidatorError, annotate, buildJsonSchema, cloneRefProp, coerceForType, coerceScalar, createAnnotatedTypeNode, createDataFromAnnotatedType, defineAnnotatedType, deserializeAnnotatedType, detectDiscriminator, flattenAnnotatedType, forAnnotatedType, fromJsonSchema, isAnnotatedType, isAnnotatedTypeOfPrimitive, isPhantomType, mergeJsonSchemas, serializeAnnotatedType, throwFeatureDisabled };
|
|
851
|
+
export { SERIALIZE_VERSION, Validator, ValidatorError, annotate, buildJsonSchema, cloneRefProp, coerceForType, coerceScalar, createAnnotatedTypeNode, createDataFromAnnotatedType, defineAnnotatedType, deserializeAnnotatedType, detectDiscriminator, flattenAnnotatedType, forAnnotatedType, fromJsonSchema, invalidateCompiledValidators, isAnnotatedType, isAnnotatedTypeOfPrimitive, isPhantomType, mergeJsonSchemas, registerCompiledCheck, serializeAnnotatedType, throwFeatureDisabled };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/typescript",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.110",
|
|
4
4
|
"description": "Atscript: typescript-gen support.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"annotations",
|
|
@@ -67,13 +67,13 @@
|
|
|
67
67
|
"moost": "^0.6.53"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
|
-
"@atscript/db": "^0.1.
|
|
70
|
+
"@atscript/db": "^0.1.164",
|
|
71
71
|
"@uniqu/core": "^0.1.15",
|
|
72
72
|
"vitest": "3.2.7"
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|
|
75
75
|
"@atscript/db": "^0.1.159",
|
|
76
|
-
"@atscript/core": "^0.1.
|
|
76
|
+
"@atscript/core": "^0.1.110"
|
|
77
77
|
},
|
|
78
78
|
"peerDependenciesMeta": {
|
|
79
79
|
"@atscript/db": {
|