@atscript/typescript 0.2.4 → 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 +45 -28
- package/dist/index.cjs +2 -2
- package/dist/index.d.ts +29 -1
- package/dist/index.mjs +2 -2
- package/dist/{plugin-Ct9Ko5JG.mjs → plugin-DUInOy5v.mjs} +21 -6
- package/dist/{plugin-Cqao46Gt.cjs → plugin-lDfE9qm8.cjs} +21 -6
- package/dist/realm-runtime.js +986 -191
- package/dist/test-utils.cjs +2 -2
- package/dist/test-utils.d.ts +185 -157
- package/dist/test-utils.mjs +2 -2
- package/dist/{user-text-BddKk8EU.cjs → user-text-BvyErcKK.cjs} +65 -46
- package/dist/{user-text-qL59indq.mjs → user-text-DZR5hfLa.mjs} +48 -41
- package/dist/utils.cjs +885 -97
- package/dist/utils.d.ts +158 -24
- package/dist/utils.mjs +883 -98
- package/package.json +4 -4
package/dist/cli.cjs
CHANGED
|
@@ -1079,6 +1079,7 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
1079
1079
|
const text = this.compiles ? this.spliceCompiledChecks(module.text, realm) : module.text;
|
|
1080
1080
|
if (this.bundledSchemas.length === 0) return text;
|
|
1081
1081
|
const views = /* @__PURE__ */ new Map();
|
|
1082
|
+
const options = jsonSchemaOptionsArg(this.opts);
|
|
1082
1083
|
const viewOf = (id) => {
|
|
1083
1084
|
let view = views.get(id);
|
|
1084
1085
|
if (!view) {
|
|
@@ -1086,12 +1087,12 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
1086
1087
|
let accounted = [REALM_FAILED];
|
|
1087
1088
|
try {
|
|
1088
1089
|
const type = realm.classOf(this.doc, id);
|
|
1089
|
-
schema = JSON.stringify(realm.rt.buildJsonSchema(type));
|
|
1090
|
+
schema = JSON.stringify(realm.rt.buildJsonSchema(type, this.opts?.jsonSchemaOptions));
|
|
1090
1091
|
accounted = this.accountedFor(realm, type);
|
|
1091
1092
|
} catch {}
|
|
1092
1093
|
view = {
|
|
1093
1094
|
schema,
|
|
1094
|
-
accounted: accounted.length > 0 ? `, ${JSON.stringify(accounted)}` : ""
|
|
1095
|
+
accounted: accounted.length > 0 || options ? `, ${JSON.stringify(accounted)}${options ? `, ${options}` : ""}` : ""
|
|
1095
1096
|
};
|
|
1096
1097
|
views.set(id, view);
|
|
1097
1098
|
}
|
|
@@ -1195,7 +1196,8 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
1195
1196
|
*/ renderJsonSchemaMethod(_node) {
|
|
1196
1197
|
if (this.jsonSchemaMode === "lazy") {
|
|
1197
1198
|
this.writeln("static toJsonSchema() {");
|
|
1198
|
-
|
|
1199
|
+
const options = jsonSchemaOptionsArg(this.opts);
|
|
1200
|
+
this.indent().writeln(`return ${this.util("lazyJsonSchema")}(this${options ? `, ${options}` : ""})`);
|
|
1199
1201
|
this.unindent();
|
|
1200
1202
|
this.writeln("}");
|
|
1201
1203
|
} else {
|
|
@@ -1477,6 +1479,17 @@ const JS_INTERPRETED_FORMAT = "js:interpreted";
|
|
|
1477
1479
|
if (opts?.jsonSchema !== void 0) return opts.jsonSchema;
|
|
1478
1480
|
return false;
|
|
1479
1481
|
}
|
|
1482
|
+
/**
|
|
1483
|
+
* The `jsonSchemaOptions` argument the generated `toJsonSchema()` passes to the runtime: a JS
|
|
1484
|
+
* literal of the options that differ from the defaults, `undefined` when none do.
|
|
1485
|
+
*/ function jsonSchemaOptionsArg(opts) {
|
|
1486
|
+
const o = opts?.jsonSchemaOptions;
|
|
1487
|
+
const set = {};
|
|
1488
|
+
if (o?.closed === true) set.closed = true;
|
|
1489
|
+
if (o?.annotations === false) set.annotations = false;
|
|
1490
|
+
if (o?.enums === false) set.enums = false;
|
|
1491
|
+
return Object.keys(set).length > 0 ? JSON.stringify(set) : void 0;
|
|
1492
|
+
}
|
|
1480
1493
|
/** A generated JS module of `doc`, checked to load in a build (see `assertLoads`). */ function renderJs(doc, opts, mode, loadCheck) {
|
|
1481
1494
|
const content = rendererOf(doc, opts, mode).render();
|
|
1482
1495
|
assertLoads(doc, opts, mode, loadCheck);
|
|
@@ -1581,20 +1594,22 @@ const tsPlugin = (opts) => {
|
|
|
1581
1594
|
const mapSet = Map.prototype.set;
|
|
1582
1595
|
/** Global mutation epoch: compiled checks bound in an older epoch re-bind before use. */ let epoch = 0;
|
|
1583
1596
|
/**
|
|
1584
|
-
* Writes of
|
|
1585
|
-
* replaced, a layer flag or intrinsic mark registered)
|
|
1586
|
-
*
|
|
1587
|
-
|
|
1597
|
+
* Writes of type trees so far, watched or not: of metadata (any map, any key: `annotate()`, the
|
|
1598
|
+
* `Map` methods, a node's map replaced, a layer flag or intrinsic mark registered) and of shape
|
|
1599
|
+
* (every {@link touched} mutation, `invalidateCompiledValidators()`). What is derived from a type
|
|
1600
|
+
* tree before the last write is derived again (`lazyJsonSchema`, `LayerMap`, `normalizeForType`).
|
|
1601
|
+
*/ let typeWrites = 0;
|
|
1588
1602
|
/** Some bind has watched an object (until then no mutation can affect a compiled check). */ let tracking = false;
|
|
1589
1603
|
/** Objects (nodes, type defs, metadata / props maps) read by some compiled-check bind. */ const watched = /* @__PURE__ */ new WeakSet();
|
|
1590
|
-
/**
|
|
1604
|
+
/**
|
|
1605
|
+
* Records a tracked mutation of `obj`: a type tree write (see `typeWrites`); compiled checks
|
|
1606
|
+
* re-bind when some bind has read it.
|
|
1607
|
+
*/ function touched(obj) {
|
|
1608
|
+
typeWrites++;
|
|
1591
1609
|
if (tracking && watched.has(obj)) epoch++;
|
|
1592
1610
|
}
|
|
1593
|
-
/** The number of
|
|
1594
|
-
return
|
|
1595
|
-
}
|
|
1596
|
-
/** Records a write of a node's metadata the maps do not see: the node's map replaced. */ function metadataReplaced() {
|
|
1597
|
-
metadataWrites++;
|
|
1611
|
+
/** The number of type tree writes so far (see `typeWrites`). */ function typeWriteCount() {
|
|
1612
|
+
return typeWrites;
|
|
1598
1613
|
}
|
|
1599
1614
|
/**
|
|
1600
1615
|
* Metadata map of runtime type nodes: a `Map` whose writes to validator annotation keys
|
|
@@ -1603,21 +1618,18 @@ const mapSet = Map.prototype.set;
|
|
|
1603
1618
|
set(key, value) {
|
|
1604
1619
|
super.set(key, value);
|
|
1605
1620
|
if (tracking && VALIDATOR_KEY_SET.has(key)) touched(this);
|
|
1606
|
-
|
|
1621
|
+
else typeWrites++;
|
|
1607
1622
|
return this;
|
|
1608
1623
|
}
|
|
1609
1624
|
delete(key) {
|
|
1610
1625
|
const deleted = super.delete(key);
|
|
1611
|
-
if (deleted)
|
|
1612
|
-
|
|
1613
|
-
metadataWrites++;
|
|
1614
|
-
}
|
|
1626
|
+
if (deleted) if (tracking && VALIDATOR_KEY_SET.has(key)) touched(this);
|
|
1627
|
+
else typeWrites++;
|
|
1615
1628
|
return deleted;
|
|
1616
1629
|
}
|
|
1617
1630
|
clear() {
|
|
1618
1631
|
super.clear();
|
|
1619
1632
|
touched(this);
|
|
1620
|
-
metadataWrites++;
|
|
1621
1633
|
}
|
|
1622
1634
|
/** A new map holding `entries`: no write (a new map is in no compiled check nor schema). */ constructor(entries) {
|
|
1623
1635
|
super();
|
|
@@ -1637,7 +1649,7 @@ const mapSet = Map.prototype.set;
|
|
|
1637
1649
|
* a base shows through every layer over it.
|
|
1638
1650
|
*
|
|
1639
1651
|
* Reads go through a flattened view of the effective entries, rebuilt on the first read after any
|
|
1640
|
-
*
|
|
1652
|
+
* type tree write (one global write counter: `typeWriteCount`). The view is used only while
|
|
1641
1653
|
* every map below is tracked (an `AnnotationMap` or a `LayerMap`, whose writes the counter
|
|
1642
1654
|
* sees); otherwise the reads are live. A raw write the counter does not see (a node's map swapped,
|
|
1643
1655
|
* `node.metadata = X`, or edited in place) must be followed by `invalidateCompiledValidators()`,
|
|
@@ -1685,7 +1697,7 @@ let _Symbol_iterator = Symbol.iterator;
|
|
|
1685
1697
|
* The flattened view (built again after a metadata write), `undefined`: read live. Internal:
|
|
1686
1698
|
* this module's readers and the validators read it (`readable`, `filledMeta`), never write.
|
|
1687
1699
|
*/ view() {
|
|
1688
|
-
return this.w ===
|
|
1700
|
+
return this.w === typeWriteCount() ? this.f : this.flatten();
|
|
1689
1701
|
}
|
|
1690
1702
|
flatten() {
|
|
1691
1703
|
this.w = -1;
|
|
@@ -1695,7 +1707,7 @@ let _Symbol_iterator = Symbol.iterator;
|
|
|
1695
1707
|
f = keys.length === 0 ? NO_ENTRIES : new AnnotationMap(keys.map((k) => [k, this.liveGet(k)]));
|
|
1696
1708
|
}
|
|
1697
1709
|
this.f = f;
|
|
1698
|
-
this.w =
|
|
1710
|
+
this.w = typeWriteCount();
|
|
1699
1711
|
return f;
|
|
1700
1712
|
}
|
|
1701
1713
|
/** The value of `key` (not concatenated), or `MISS`; `nr`: a `passedWhenReferred:false` key. */ lookup(key, nr) {
|
|
@@ -1723,7 +1735,7 @@ let _Symbol_iterator = Symbol.iterator;
|
|
|
1723
1735
|
return MISS;
|
|
1724
1736
|
}
|
|
1725
1737
|
get(key) {
|
|
1726
|
-
const view = this.w ===
|
|
1738
|
+
const view = this.w === typeWriteCount() ? this.f : this.flatten();
|
|
1727
1739
|
return view === void 0 ? this.liveGet(key) : mapGet.call(view, key);
|
|
1728
1740
|
}
|
|
1729
1741
|
/** `get` read through the layers (see the file comment). */ liveGet(key) {
|
|
@@ -1784,7 +1796,6 @@ let _Symbol_iterator = Symbol.iterator;
|
|
|
1784
1796
|
const deleted = super.delete(key);
|
|
1785
1797
|
if ((hiding ? HIDDEN.get(this) : void 0)?.delete(key)) {
|
|
1786
1798
|
touched(this);
|
|
1787
|
-
metadataReplaced();
|
|
1788
1799
|
return true;
|
|
1789
1800
|
}
|
|
1790
1801
|
return deleted;
|
|
@@ -1826,7 +1837,7 @@ Object.defineProperty(LayerMap.prototype, "size", {
|
|
|
1826
1837
|
});
|
|
1827
1838
|
/**
|
|
1828
1839
|
* Every map of `m`'s layers is tracked (an `AnnotationMap` or a `LayerMap`, whose writes count in
|
|
1829
|
-
* `
|
|
1840
|
+
* `typeWrites`), so a flattened view of `m` stays right until the next write.
|
|
1830
1841
|
*/ function tracked(m, seen) {
|
|
1831
1842
|
const p = Object.getPrototypeOf(m);
|
|
1832
1843
|
if (p !== AnnotationMap.prototype && p !== LayerMap.prototype) return false;
|
|
@@ -2138,7 +2149,11 @@ var _globalThis$1, _Symbol_for$1;
|
|
|
2138
2149
|
* their specs flag `userText`. Core's are known from the start ({@link CORE_USER_TEXT}); a plugin's
|
|
2139
2150
|
* are registered by the generated modules that write them (`$ut`), or by the plugin itself
|
|
2140
2151
|
* ({@link registerUserText}), so a translator finds them at runtime without the specs.
|
|
2141
|
-
*/ /**
|
|
2152
|
+
*/ /**
|
|
2153
|
+
* `true`: the value itself is the text; `'expression'`: the value is the source of a function the
|
|
2154
|
+
* client evaluates, its string literals the texts; a list: those fields of the value object are
|
|
2155
|
+
* (a name ending in `()`: that field is an expression).
|
|
2156
|
+
*/ /**
|
|
2142
2157
|
* The user-facing text of `@atscript/core`'s annotations (its specs' `userText` arguments; a test
|
|
2143
2158
|
* keeps them equal).
|
|
2144
2159
|
*/ const CORE_USER_TEXT = new Map([
|
|
@@ -4128,8 +4143,9 @@ var JsNextRenderer = class extends JsRenderer {
|
|
|
4128
4143
|
return out;
|
|
4129
4144
|
}
|
|
4130
4145
|
/**
|
|
4131
|
-
* The plugin annotations holding user-facing text this module writes (`$ut` entries: `key`,
|
|
4132
|
-
* `key:field`); core's are known to the runtime from
|
|
4146
|
+
* The plugin annotations holding user-facing text this module writes (`$ut` entries: `key`,
|
|
4147
|
+
* `key()` for an expression, `key:field`, `key:field()`); core's are known to the runtime from
|
|
4148
|
+
* the start (`CORE_USER_TEXT`).
|
|
4133
4149
|
*/ moduleUserText() {
|
|
4134
4150
|
const out = /* @__PURE__ */ new Set();
|
|
4135
4151
|
for (const name of new Set(this.doc.annotations.map((a) => a.name))) {
|
|
@@ -4137,6 +4153,7 @@ var JsNextRenderer = class extends JsRenderer {
|
|
|
4137
4153
|
const spec = this.doc.resolveAnnotation(name);
|
|
4138
4154
|
const fields = spec && (0, _atscript_core.userTextFields)(spec);
|
|
4139
4155
|
if (fields === true) out.add(name);
|
|
4156
|
+
else if (fields === "expression") out.add(`${name}()`);
|
|
4140
4157
|
else if (fields) for (const f of fields) out.add(`${name}:${f}`);
|
|
4141
4158
|
}
|
|
4142
4159
|
return [...out].sort();
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
2
|
-
const require_plugin = require('./plugin-
|
|
3
|
-
const require_user_text = require('./user-text-
|
|
2
|
+
const require_plugin = require('./plugin-lDfE9qm8.cjs');
|
|
3
|
+
const require_user_text = require('./user-text-BvyErcKK.cjs');
|
|
4
4
|
|
|
5
5
|
exports.JS_COMPILED_FORMAT = require_plugin.JS_COMPILED_FORMAT;
|
|
6
6
|
exports.JS_INTERPRETED_FORMAT = require_plugin.JS_INTERPRETED_FORMAT;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
import { TAtscriptPlugin, AtscriptDoc } from '@atscript/core';
|
|
2
2
|
|
|
3
|
+
/** Options of {@link buildJsonSchema} (and of the `jsonSchemaOptions` plugin option). */
|
|
4
|
+
interface TJsonSchemaOptions {
|
|
5
|
+
/**
|
|
6
|
+
* `additionalProperties: false` on every object schema: the schema rejects keys the type does
|
|
7
|
+
* not declare, as the validator does with its default `unknownProps: 'error'`.
|
|
8
|
+
* *(default: `false`)*
|
|
9
|
+
*/
|
|
10
|
+
closed?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* `@meta.description` → `description` and `@meta.label` → `title`, on the schema of the
|
|
13
|
+
* type or field that carries them. *(default: `true`)*
|
|
14
|
+
*/
|
|
15
|
+
annotations?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* A union of literals (`'a' | 'b'`, also with `null`) → `{ type, enum }` instead of an
|
|
18
|
+
* `anyOf` of `const` schemas. *(default: `true`)*
|
|
19
|
+
*/
|
|
20
|
+
enums?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
3
23
|
interface TTsPluginOptions {
|
|
4
24
|
/**
|
|
5
25
|
* JSON Schema support mode:
|
|
@@ -11,6 +31,14 @@ interface TTsPluginOptions {
|
|
|
11
31
|
* to force build-time embedding regardless of this setting.
|
|
12
32
|
*/
|
|
13
33
|
jsonSchema?: false | 'lazy' | 'bundle';
|
|
34
|
+
/**
|
|
35
|
+
* Options of the generated `toJsonSchema()` (`'lazy'`, `'bundle'` and `@emit.jsonSchema`
|
|
36
|
+
* alike): the same schema `buildJsonSchema(type, jsonSchemaOptions)` builds at runtime.
|
|
37
|
+
* `closed` (`additionalProperties: false`, default `false`), `annotations` (`description` /
|
|
38
|
+
* `title` from `@meta.description` / `@meta.label`, default `true`), `enums` (a union of
|
|
39
|
+
* literals as `enum`, default `true`).
|
|
40
|
+
*/
|
|
41
|
+
jsonSchemaOptions?: TJsonSchemaOptions;
|
|
14
42
|
/**
|
|
15
43
|
* Example data support:
|
|
16
44
|
* - `false` — No support. `toExampleData` is not rendered. *(default)*
|
|
@@ -102,4 +130,4 @@ declare function withLoadCheck<T>(fn: () => T): T;
|
|
|
102
130
|
declare function importCycle(doc: AtscriptDoc): boolean;
|
|
103
131
|
|
|
104
132
|
export { JS_COMPILED_FORMAT, JS_INTERPRETED_FORMAT, tsPlugin as default, importCycle, invalidateCompiledValidators, tsPlugin, withLoadCheck };
|
|
105
|
-
export type { TTsPluginOptions };
|
|
133
|
+
export type { TJsonSchemaOptions, TTsPluginOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as withLoadCheck, i as importCycle, n as JS_INTERPRETED_FORMAT, r as tsPlugin, t as JS_COMPILED_FORMAT } from "./plugin-
|
|
2
|
-
import {
|
|
1
|
+
import { a as withLoadCheck, i as importCycle, n as JS_INTERPRETED_FORMAT, r as tsPlugin, t as JS_COMPILED_FORMAT } from "./plugin-DUInOy5v.mjs";
|
|
2
|
+
import { Y as invalidateCompiledValidators } from "./user-text-DZR5hfLa.mjs";
|
|
3
3
|
|
|
4
4
|
export { JS_COMPILED_FORMAT, JS_INTERPRETED_FORMAT, tsPlugin as default, tsPlugin, importCycle, invalidateCompiledValidators, withLoadCheck };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as CORE_USER_TEXT, o as uniqueName, v as stageEnds } from "./user-text-
|
|
1
|
+
import { n as CORE_USER_TEXT, o as uniqueName, v as stageEnds } from "./user-text-DZR5hfLa.mjs";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { ANNOTATE_RESET, DEFAULT_FORMAT, MERGE_TOO_COMPLEX, NAV_PROP_ANNOTATIONS, SemanticGroup, andExprs, annotatedValueKinds, componentOf, components, defPosition, documentsEpoch, entryParts, flatDefinitions, forEachAnnotationSpec, getRelPath, hasMutatingAnnotates, hasNavPropAnnotation, isAnnotate, isArray, isAsView, isBareId, isBareSpecifier, isConst, isDbEntityNode, isGroup, isInterface, isNull, isPhantomNode, isPrimitive, isQueryLogical, isRef, isStructure, isTuple, moduleId, pastViews, resolveAtscriptFromPath, unshell, userTextFields, withoutAsExtension } from "@atscript/core";
|
|
4
4
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
@@ -553,6 +553,7 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
553
553
|
const text = this.compiles ? this.spliceCompiledChecks(module.text, realm) : module.text;
|
|
554
554
|
if (this.bundledSchemas.length === 0) return text;
|
|
555
555
|
const views = /* @__PURE__ */ new Map();
|
|
556
|
+
const options = jsonSchemaOptionsArg(this.opts);
|
|
556
557
|
const viewOf = (id) => {
|
|
557
558
|
let view = views.get(id);
|
|
558
559
|
if (!view) {
|
|
@@ -560,12 +561,12 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
560
561
|
let accounted = [REALM_FAILED];
|
|
561
562
|
try {
|
|
562
563
|
const type = realm.classOf(this.doc, id);
|
|
563
|
-
schema = JSON.stringify(realm.rt.buildJsonSchema(type));
|
|
564
|
+
schema = JSON.stringify(realm.rt.buildJsonSchema(type, this.opts?.jsonSchemaOptions));
|
|
564
565
|
accounted = this.accountedFor(realm, type);
|
|
565
566
|
} catch {}
|
|
566
567
|
view = {
|
|
567
568
|
schema,
|
|
568
|
-
accounted: accounted.length > 0 ? `, ${JSON.stringify(accounted)}` : ""
|
|
569
|
+
accounted: accounted.length > 0 || options ? `, ${JSON.stringify(accounted)}${options ? `, ${options}` : ""}` : ""
|
|
569
570
|
};
|
|
570
571
|
views.set(id, view);
|
|
571
572
|
}
|
|
@@ -669,7 +670,8 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
669
670
|
*/ renderJsonSchemaMethod(_node) {
|
|
670
671
|
if (this.jsonSchemaMode === "lazy") {
|
|
671
672
|
this.writeln("static toJsonSchema() {");
|
|
672
|
-
|
|
673
|
+
const options = jsonSchemaOptionsArg(this.opts);
|
|
674
|
+
this.indent().writeln(`return ${this.util("lazyJsonSchema")}(this${options ? `, ${options}` : ""})`);
|
|
673
675
|
this.unindent();
|
|
674
676
|
this.writeln("}");
|
|
675
677
|
} else {
|
|
@@ -2870,8 +2872,9 @@ var JsNextRenderer = class extends JsRenderer {
|
|
|
2870
2872
|
return out;
|
|
2871
2873
|
}
|
|
2872
2874
|
/**
|
|
2873
|
-
* The plugin annotations holding user-facing text this module writes (`$ut` entries: `key`,
|
|
2874
|
-
* `key:field`); core's are known to the runtime from
|
|
2875
|
+
* The plugin annotations holding user-facing text this module writes (`$ut` entries: `key`,
|
|
2876
|
+
* `key()` for an expression, `key:field`, `key:field()`); core's are known to the runtime from
|
|
2877
|
+
* the start (`CORE_USER_TEXT`).
|
|
2875
2878
|
*/ moduleUserText() {
|
|
2876
2879
|
const out = /* @__PURE__ */ new Set();
|
|
2877
2880
|
for (const name of new Set(this.doc.annotations.map((a) => a.name))) {
|
|
@@ -2879,6 +2882,7 @@ var JsNextRenderer = class extends JsRenderer {
|
|
|
2879
2882
|
const spec = this.doc.resolveAnnotation(name);
|
|
2880
2883
|
const fields = spec && userTextFields(spec);
|
|
2881
2884
|
if (fields === true) out.add(name);
|
|
2885
|
+
else if (fields === "expression") out.add(`${name}()`);
|
|
2882
2886
|
else if (fields) for (const f of fields) out.add(`${name}:${f}`);
|
|
2883
2887
|
}
|
|
2884
2888
|
return [...out].sort();
|
|
@@ -3706,6 +3710,17 @@ const JS_INTERPRETED_FORMAT = "js:interpreted";
|
|
|
3706
3710
|
if (opts?.jsonSchema !== void 0) return opts.jsonSchema;
|
|
3707
3711
|
return false;
|
|
3708
3712
|
}
|
|
3713
|
+
/**
|
|
3714
|
+
* The `jsonSchemaOptions` argument the generated `toJsonSchema()` passes to the runtime: a JS
|
|
3715
|
+
* literal of the options that differ from the defaults, `undefined` when none do.
|
|
3716
|
+
*/ function jsonSchemaOptionsArg(opts) {
|
|
3717
|
+
const o = opts?.jsonSchemaOptions;
|
|
3718
|
+
const set = {};
|
|
3719
|
+
if (o?.closed === true) set.closed = true;
|
|
3720
|
+
if (o?.annotations === false) set.annotations = false;
|
|
3721
|
+
if (o?.enums === false) set.enums = false;
|
|
3722
|
+
return Object.keys(set).length > 0 ? JSON.stringify(set) : void 0;
|
|
3723
|
+
}
|
|
3709
3724
|
/** A generated JS module of `doc`, checked to load in a build (see `assertLoads`). */ function renderJs(doc, opts, mode, loadCheck) {
|
|
3710
3725
|
const content = rendererOf(doc, opts, mode).render();
|
|
3711
3726
|
assertLoads(doc, opts, mode, loadCheck);
|
|
@@ -25,7 +25,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
25
|
}) : target, mod));
|
|
26
26
|
|
|
27
27
|
//#endregion
|
|
28
|
-
const require_user_text = require('./user-text-
|
|
28
|
+
const require_user_text = require('./user-text-BvyErcKK.cjs');
|
|
29
29
|
let path = require("path");
|
|
30
30
|
path = __toESM(path);
|
|
31
31
|
let _atscript_core = require("@atscript/core");
|
|
@@ -581,6 +581,7 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
581
581
|
const text = this.compiles ? this.spliceCompiledChecks(module.text, realm) : module.text;
|
|
582
582
|
if (this.bundledSchemas.length === 0) return text;
|
|
583
583
|
const views = /* @__PURE__ */ new Map();
|
|
584
|
+
const options = jsonSchemaOptionsArg(this.opts);
|
|
584
585
|
const viewOf = (id) => {
|
|
585
586
|
let view = views.get(id);
|
|
586
587
|
if (!view) {
|
|
@@ -588,12 +589,12 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
588
589
|
let accounted = [REALM_FAILED];
|
|
589
590
|
try {
|
|
590
591
|
const type = realm.classOf(this.doc, id);
|
|
591
|
-
schema = JSON.stringify(realm.rt.buildJsonSchema(type));
|
|
592
|
+
schema = JSON.stringify(realm.rt.buildJsonSchema(type, this.opts?.jsonSchemaOptions));
|
|
592
593
|
accounted = this.accountedFor(realm, type);
|
|
593
594
|
} catch {}
|
|
594
595
|
view = {
|
|
595
596
|
schema,
|
|
596
|
-
accounted: accounted.length > 0 ? `, ${JSON.stringify(accounted)}` : ""
|
|
597
|
+
accounted: accounted.length > 0 || options ? `, ${JSON.stringify(accounted)}${options ? `, ${options}` : ""}` : ""
|
|
597
598
|
};
|
|
598
599
|
views.set(id, view);
|
|
599
600
|
}
|
|
@@ -697,7 +698,8 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
697
698
|
*/ renderJsonSchemaMethod(_node) {
|
|
698
699
|
if (this.jsonSchemaMode === "lazy") {
|
|
699
700
|
this.writeln("static toJsonSchema() {");
|
|
700
|
-
|
|
701
|
+
const options = jsonSchemaOptionsArg(this.opts);
|
|
702
|
+
this.indent().writeln(`return ${this.util("lazyJsonSchema")}(this${options ? `, ${options}` : ""})`);
|
|
701
703
|
this.unindent();
|
|
702
704
|
this.writeln("}");
|
|
703
705
|
} else {
|
|
@@ -2898,8 +2900,9 @@ var JsNextRenderer = class extends JsRenderer {
|
|
|
2898
2900
|
return out;
|
|
2899
2901
|
}
|
|
2900
2902
|
/**
|
|
2901
|
-
* The plugin annotations holding user-facing text this module writes (`$ut` entries: `key`,
|
|
2902
|
-
* `key:field`); core's are known to the runtime from
|
|
2903
|
+
* The plugin annotations holding user-facing text this module writes (`$ut` entries: `key`,
|
|
2904
|
+
* `key()` for an expression, `key:field`, `key:field()`); core's are known to the runtime from
|
|
2905
|
+
* the start (`CORE_USER_TEXT`).
|
|
2903
2906
|
*/ moduleUserText() {
|
|
2904
2907
|
const out = /* @__PURE__ */ new Set();
|
|
2905
2908
|
for (const name of new Set(this.doc.annotations.map((a) => a.name))) {
|
|
@@ -2907,6 +2910,7 @@ var JsNextRenderer = class extends JsRenderer {
|
|
|
2907
2910
|
const spec = this.doc.resolveAnnotation(name);
|
|
2908
2911
|
const fields = spec && (0, _atscript_core.userTextFields)(spec);
|
|
2909
2912
|
if (fields === true) out.add(name);
|
|
2913
|
+
else if (fields === "expression") out.add(`${name}()`);
|
|
2910
2914
|
else if (fields) for (const f of fields) out.add(`${name}:${f}`);
|
|
2911
2915
|
}
|
|
2912
2916
|
return [...out].sort();
|
|
@@ -3734,6 +3738,17 @@ const JS_INTERPRETED_FORMAT = "js:interpreted";
|
|
|
3734
3738
|
if (opts?.jsonSchema !== void 0) return opts.jsonSchema;
|
|
3735
3739
|
return false;
|
|
3736
3740
|
}
|
|
3741
|
+
/**
|
|
3742
|
+
* The `jsonSchemaOptions` argument the generated `toJsonSchema()` passes to the runtime: a JS
|
|
3743
|
+
* literal of the options that differ from the defaults, `undefined` when none do.
|
|
3744
|
+
*/ function jsonSchemaOptionsArg(opts) {
|
|
3745
|
+
const o = opts?.jsonSchemaOptions;
|
|
3746
|
+
const set = {};
|
|
3747
|
+
if (o?.closed === true) set.closed = true;
|
|
3748
|
+
if (o?.annotations === false) set.annotations = false;
|
|
3749
|
+
if (o?.enums === false) set.enums = false;
|
|
3750
|
+
return Object.keys(set).length > 0 ? JSON.stringify(set) : void 0;
|
|
3751
|
+
}
|
|
3737
3752
|
/** A generated JS module of `doc`, checked to load in a build (see `assertLoads`). */ function renderJs(doc, opts, mode, loadCheck) {
|
|
3738
3753
|
const content = rendererOf(doc, opts, mode).render();
|
|
3739
3754
|
assertLoads(doc, opts, mode, loadCheck);
|