@atscript/typescript 0.2.2 → 0.2.4

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 CHANGED
@@ -186,7 +186,7 @@ var BaseRenderer = class extends CodePrinter {
186
186
  renderType(node) {}
187
187
  renderAnnotate(node) {}
188
188
  transformFromPath(path) {
189
- return `${path}.as`;
189
+ return `${(0, _atscript_core.withoutAsExtension)(path)}.as`;
190
190
  }
191
191
  renderImport(node) {
192
192
  const def = node.getDefinition();
@@ -786,11 +786,14 @@ var TypeRenderer = class TypeRenderer extends BaseRenderer {
786
786
  const written = only?.prop.getDefinition();
787
787
  return written && !((0, _atscript_core.isGroup)(only.def) && only.def !== written) ? written : only?.def;
788
788
  }
789
+ /** The TypeScript type of a final primitive type (`any`, the `unknown` primitive: `unknown`). */ function finalTsType(t) {
790
+ return t === "void" ? "undefined" : t === "any" ? "unknown" : t;
791
+ }
789
792
  function renderPrimitiveTypeDef(def) {
790
793
  if (!def) return "unknown";
791
- if (typeof def === "string") return def === "void" ? "undefined" : def;
794
+ if (typeof def === "string") return finalTsType(def);
792
795
  switch (def.kind) {
793
- case "final": return def.value === "void" ? "undefined" : def.value;
796
+ case "final": return finalTsType(def.value);
794
797
  case "union": return def.items.map(renderPrimitiveTypeDef).join(" | ");
795
798
  case "intersection": return def.items.map((item) => typeof item === "object" && item.kind === "union" ? `(${renderPrimitiveTypeDef(item)})` : renderPrimitiveTypeDef(item)).join(" & ");
796
799
  case "tuple": return `[${def.items.map(renderPrimitiveTypeDef).join(", ")}]`;
@@ -875,7 +878,8 @@ const CHECKS_IMPORT_MARKER = "/*@@atscript-compiled-checks-import@@*/";
875
878
  bundledSchemaOf: "$jbm",
876
879
  $ps: "$ps",
877
880
  $ak: "$ak",
878
- $nr: "$nk"
881
+ $nr: "$nk",
882
+ $ut: "$ut"
879
883
  };
880
884
  const LITERAL_IDENTIFIERS = new Set([
881
885
  "true",
@@ -929,7 +933,8 @@ var JsRenderer = class extends BaseRenderer {
929
933
  /**
930
934
  * Relative imports get the configured `moduleExtension`; bare specifiers
931
935
  * always keep `.as` — they resolve through the package's `exports` map.
932
- */ transformFromPath(path) {
936
+ */ transformFromPath(written) {
937
+ const path = (0, _atscript_core.withoutAsExtension)(written);
933
938
  return (0, _atscript_core.isBareSpecifier)(path) ? `${path}.as` : `${path}${this.opts?.moduleExtension ?? ".as"}`;
934
939
  }
935
940
  /**
@@ -1331,12 +1336,16 @@ var JsRenderer = class extends BaseRenderer {
1331
1336
  if (dotIdx === -1) return `() => ${this.annotationTypeName(text, origin)}`;
1332
1337
  return `{ type: () => ${this.annotationTypeName(text.slice(0, dotIdx), origin)}, field: "${escapeQuotes(text.slice(dotIdx + 1))}" }`;
1333
1338
  }
1334
- emitArgValue(aSpec, argToken, origin) {
1339
+ emitArgValue(aSpec, argToken, origin, mainToken) {
1335
1340
  if (aSpec.type === "ref") return this.emitRefValue(argToken.text, origin);
1336
1341
  if (aSpec.type === "query" && argToken.queryNode) return this.emitQueryTree(argToken.queryNode, origin);
1337
1342
  if (aSpec.type === "expr" && argToken.exprNode) return this.emitExprNode(argToken.exprNode.expression, origin);
1338
1343
  if (aSpec.type === "order" && argToken.orderNode) return `[${argToken.orderNode.items.map((item) => `{ ref: ${this.emitQueryFieldRef(item.ref, origin)}${item.desc ? ", desc: true" : ""} }`).join(", ")}]`;
1339
- return aSpec.type === "string" ? `"${escapeQuotes(argToken.text)}"` : argToken.text;
1344
+ return aSpec.type === "string" || aSpec.type === "value" && (argToken.type === "text" || argToken.type === "number" && this.decimalField(mainToken, origin)) ? `"${escapeQuotes(argToken.text)}"` : argToken.text;
1345
+ }
1346
+ /** Whether annotation `mainToken` is written on a `decimal` field (not one that holds numbers). */ decimalField(mainToken, origin) {
1347
+ const kinds = (0, _atscript_core.annotatedValueKinds)(mainToken, origin ?? this.doc);
1348
+ return !!kinds?.has("decimal") && !kinds.has("number") && !kinds.has("unknown");
1340
1349
  }
1341
1350
  emitExprNode(node, origin) {
1342
1351
  switch (node.entity) {
@@ -1416,13 +1425,13 @@ var JsRenderer = class extends BaseRenderer {
1416
1425
  targetValue = "{ ";
1417
1426
  let i = 0;
1418
1427
  for (const aSpec of spec.arguments) {
1419
- if (an.args[i]) targetValue += `${wrapProp(aSpec.name)}: ${this.emitArgValue(aSpec, an.args[i], origin)}${i === length - 1 ? "" : ", "} `;
1428
+ if (an.args[i]) targetValue += `${wrapProp(aSpec.name)}: ${this.emitArgValue(aSpec, an.args[i], origin, an.token)}${i === length - 1 ? "" : ", "} `;
1420
1429
  i++;
1421
1430
  }
1422
1431
  targetValue += "}";
1423
1432
  } else if (an.args[0]) {
1424
1433
  const aSpec = spec.arguments[0];
1425
- targetValue = this.emitArgValue(aSpec, an.args[0], origin);
1434
+ targetValue = this.emitArgValue(aSpec, an.args[0], origin, an.token);
1426
1435
  }
1427
1436
  }
1428
1437
  } else {
@@ -1494,8 +1503,11 @@ const tsPlugin = (opts) => {
1494
1503
  for (const [key, val] of Object.entries(annotations)) {
1495
1504
  const multiple = val.multiple;
1496
1505
  const typeLine = Array.from(val.types).map((t) => {
1497
- if (t.type === "object" && "props" in t) return `{ ${Object.entries(t.props).map(([k, v]) => `${wrapProp(k)}${v.optional ? "?" : ""}: ${v.type}`).join(", ")} }`;
1498
- else return "optional" in t && t.optional ? `${t.type} | true` : t.type;
1506
+ if (t.type === "object" && "props" in t) {
1507
+ const props = Object.entries(t.props);
1508
+ const object = `{ ${props.map(([k, v]) => `${wrapProp(k)}${v.optional ? "?" : ""}: ${v.type}`).join(", ")} }`;
1509
+ return props.length === 1 && props[0][1].optional ? `${object} | true` : object;
1510
+ } else return "optional" in t && t.optional ? `${t.type} | true` : t.type;
1499
1511
  }).join(" | ");
1500
1512
  rendered.push(`${wrapProp(key)}: ${multiple ? "(" : ""}${typeLine}${multiple ? ")[]" : ""}`);
1501
1513
  }
@@ -1532,6 +1544,7 @@ const tsPlugin = (opts) => {
1532
1544
  "expect.maxLength",
1533
1545
  "expect.array.uniqueItems"
1534
1546
  ];
1547
+ /** Annotations of an object node, in check order (before its props). */ const OBJECT_KEYS = ["expect.minKeys", "expect.maxKeys"];
1535
1548
  /**
1536
1549
  * Every annotation key the validator pre-check reads. The order is the bit order of
1537
1550
  * compiled-check layouts: changing it changes the layout format.
@@ -1545,7 +1558,9 @@ const tsPlugin = (opts) => {
1545
1558
  "expect.max",
1546
1559
  "expect.exclusiveMin",
1547
1560
  "expect.exclusiveMax",
1548
- "expect.array.uniqueItems"
1561
+ "expect.array.uniqueItems",
1562
+ "expect.minKeys",
1563
+ "expect.maxKeys"
1549
1564
  ];
1550
1565
 
1551
1566
  //#endregion
@@ -1578,6 +1593,9 @@ const mapSet = Map.prototype.set;
1578
1593
  /** The number of metadata writes so far (see `metadataWrites`). */ function metadataWriteCount() {
1579
1594
  return metadataWrites;
1580
1595
  }
1596
+ /** Records a write of a node's metadata the maps do not see: the node's map replaced. */ function metadataReplaced() {
1597
+ metadataWrites++;
1598
+ }
1581
1599
  /**
1582
1600
  * Metadata map of runtime type nodes: a `Map` whose writes to validator annotation keys
1583
1601
  * are tracked (see {@link invalidateCompiledValidators}). Reads are the builtin ones.
@@ -1643,6 +1661,15 @@ const notReferred = (key) => ((FLAGS.get(key) ?? 0) & NOT_REFERRED) !== 0;
1643
1661
  * (`string.required` → `meta.required`) are part of the type, so they pass every reference layer
1644
1662
  * although their key is `passedWhenReferred: false` (0.1.110).
1645
1663
  */ const INTRINSIC = /* @__PURE__ */ new WeakMap();
1664
+ /**
1665
+ * Keys a map hides from its bases (`@annotate.reset`): read as if no base had them. Kept per map
1666
+ * (as `INTRINSIC`), moved with it when a node's map is replaced; `hiding`: some map hides a key
1667
+ * (until then the reads skip the lookup).
1668
+ */ const HIDDEN = /* @__PURE__ */ new WeakMap();
1669
+ let hiding = false;
1670
+ /** Whether map `m` hides `key` from its bases (see {@link HIDDEN}). */ function hides(m, key) {
1671
+ return hiding && HIDDEN.get(m)?.has(key) === true;
1672
+ }
1646
1673
  const MISS = Symbol("miss");
1647
1674
  /** The view of a layered map without effective entries (never written: views stay internal). */ const NO_ENTRIES = new AnnotationMap();
1648
1675
  const mapGet = Map.prototype.get;
@@ -1676,6 +1703,7 @@ let _Symbol_iterator = Symbol.iterator;
1676
1703
  const v = mapGet.call(this, key);
1677
1704
  if (v !== void 0 || mapHas.call(this, key)) return v;
1678
1705
  }
1706
+ if (hiding && hides(this, key)) return MISS;
1679
1707
  if (nr && this.r) {
1680
1708
  for (const n of this.b) {
1681
1709
  const x = intrinsicLookup(n.metadata, key);
@@ -1706,10 +1734,14 @@ let _Symbol_iterator = Symbol.iterator;
1706
1734
  }
1707
1735
  has(key) {
1708
1736
  const view = this.view();
1709
- return view === void 0 ? this.lookup(key, notReferred(key)) !== MISS : mapHas.call(view, key);
1737
+ return view === void 0 ? this.liveHas(key) : mapHas.call(view, key);
1738
+ }
1739
+ /** `has` read through the layers (see the file comment). */ liveHas(key) {
1740
+ return this.lookup(key, notReferred(key)) !== MISS;
1710
1741
  }
1711
1742
  /** An append key: the bases' values (lowest priority first), then the own ones. */ append(key) {
1712
1743
  const own = mapGet.call(this, key);
1744
+ if (hiding && hides(this, key)) return own;
1713
1745
  if (this.r && notReferred(key)) {
1714
1746
  const parts = [];
1715
1747
  const acc = {
@@ -1746,8 +1778,20 @@ let _Symbol_iterator = Symbol.iterator;
1746
1778
  }
1747
1779
  liveKeys() {
1748
1780
  const out = /* @__PURE__ */ new Set();
1749
- keysOf(this, false, out, /* @__PURE__ */ new Map());
1750
- return [...out];
1781
+ return keysOf(this, false, out, /* @__PURE__ */ new Map()) ? [...out].filter((k) => this.liveHas(k)) : [...out];
1782
+ }
1783
+ /** Deletes the own value of `key`; a key hidden from the bases (`hideKey`) shows them again. */ delete(key) {
1784
+ const deleted = super.delete(key);
1785
+ if ((hiding ? HIDDEN.get(this) : void 0)?.delete(key)) {
1786
+ touched(this);
1787
+ metadataReplaced();
1788
+ return true;
1789
+ }
1790
+ return deleted;
1791
+ }
1792
+ /** Deletes the own values; the keys hidden from the bases (`hideKey`) show them again. */ clear() {
1793
+ super.clear();
1794
+ HIDDEN.delete(this);
1751
1795
  }
1752
1796
  keys() {
1753
1797
  return this.effectiveKeys()[Symbol.iterator]();
@@ -1798,7 +1842,7 @@ Object.defineProperty(LayerMap.prototype, "size", {
1798
1842
  if (m instanceof LayerMap ? mapHas.call(m, key) : m.has(key)) return m instanceof LayerMap ? mapGet.call(m, key) : m.get(key);
1799
1843
  }
1800
1844
  const b = m.b;
1801
- if (b !== void 0) for (const n of b) {
1845
+ if (b !== void 0 && !hides(m, key)) for (const n of b) {
1802
1846
  const x = intrinsicLookup(n.metadata, key);
1803
1847
  if (x !== MISS) return x;
1804
1848
  }
@@ -1823,7 +1867,7 @@ Object.defineProperty(LayerMap.prototype, "size", {
1823
1867
  const was = acc.seen.get(m);
1824
1868
  if (!visit(m, filtered, acc.seen)) return;
1825
1869
  const layer = m instanceof LayerMap ? m : void 0;
1826
- if (layer) {
1870
+ if (layer && !hides(layer, key)) {
1827
1871
  const below = filtered || layer.r && notReferred(key);
1828
1872
  for (let i = layer.b.length - 1; i >= 0; i--) collect(layer.b[i].metadata, key, acc, below);
1829
1873
  }
@@ -1832,14 +1876,16 @@ Object.defineProperty(LayerMap.prototype, "size", {
1832
1876
  }
1833
1877
  /**
1834
1878
  * The keys of `m` (own first, then its bases'), each map once (see {@link visit}). `filtered`:
1835
- * reached through a reference layer.
1879
+ * reached through a reference layer. Returns whether a map visited hides keys from its bases.
1836
1880
  */ function keysOf(m, filtered, out, seen) {
1837
- if (!visit(m, filtered, seen)) return;
1881
+ if (!visit(m, filtered, seen)) return false;
1882
+ let hid = hiding && (HIDDEN.get(m)?.size ?? 0) > 0;
1838
1883
  const layer = m instanceof LayerMap ? m : void 0;
1839
1884
  const own = layer ? Map.prototype.keys.call(m) : m.keys();
1840
1885
  const intrinsic = INTRINSIC.get(m);
1841
1886
  for (const k of own) if (!filtered || !notReferred(k) || intrinsic?.has(k)) out.add(k);
1842
- if (layer) for (const n of layer.b) keysOf(n.metadata, filtered || layer.r, out, seen);
1887
+ if (layer) for (const n of layer.b) hid = keysOf(n.metadata, filtered || layer.r, out, seen) || hid;
1888
+ return hid;
1843
1889
  }
1844
1890
  /**
1845
1891
  * `m` has no entry (own or through its bases): the validators' `metadata.size === 0` fast path,
@@ -1959,11 +2005,14 @@ const B_MAX = bit("expect.max");
1959
2005
  const B_EX_MIN = bit("expect.exclusiveMin");
1960
2006
  const B_EX_MAX = bit("expect.exclusiveMax");
1961
2007
  const B_UNIQUE = bit("expect.array.uniqueItems");
2008
+ const B_MIN_KEYS = bit("expect.minKeys");
2009
+ const B_MAX_KEYS = bit("expect.maxKeys");
1962
2010
  /** Annotations the pre-check reads per kind of value (see validator-keys.ts). */ const STRING_BITS = bitsOf(STRING_KEYS);
1963
2011
  const NUMBER_BITS = bitsOf(NUMBER_KEYS);
1964
2012
  const ARRAY_BITS = bitsOf(ARRAY_KEYS);
2013
+ const OBJECT_BITS = bitsOf(OBJECT_KEYS);
1965
2014
  const BOOLEAN_BITS = bitsOf(BOOLEAN_KEYS);
1966
- /** Keys whose value the compiled code reads (one K slot each). */ const VALUE_BITS = B_MIN_LENGTH | B_MAX_LENGTH | B_MIN | B_MAX | B_EX_MIN | B_EX_MAX;
2015
+ /** Keys whose value the compiled code reads (one K slot each). */ const VALUE_BITS = B_MIN_LENGTH | B_MAX_LENGTH | B_MIN | B_MAX | B_EX_MIN | B_EX_MAX | B_MIN_KEYS | B_MAX_KEYS;
1967
2016
  const FLAG_BITS = B_REQUIRED | B_INT | B_UNIQUE;
1968
2017
  const ALL_BITS = (1 << VALIDATOR_KEYS.length) - 1;
1969
2018
  /** The field holding the bound of each value key's object form. */ const BOUND_FIELDS = {
@@ -1972,13 +2021,89 @@ const ALL_BITS = (1 << VALIDATOR_KEYS.length) - 1;
1972
2021
  [B_MIN]: "minValue",
1973
2022
  [B_MAX]: "maxValue",
1974
2023
  [B_EX_MIN]: "exclusiveMinValue",
1975
- [B_EX_MAX]: "exclusiveMaxValue"
2024
+ [B_EX_MAX]: "exclusiveMaxValue",
2025
+ [B_MIN_KEYS]: "count",
2026
+ [B_MAX_KEYS]: "count"
1976
2027
  };
1977
2028
 
1978
2029
  //#endregion
1979
2030
  //#region packages/typescript/src/runtime/validator-fast-check.ts
1980
2031
  /** Shared placeholder for the per-kind arrays of plans that don't use them. */ const EMPTY = Object.freeze([]);
1981
2032
 
2033
+ //#endregion
2034
+ //#region packages/typescript/src/runtime/validator-messages.ts
2035
+ /**
2036
+ * Validator error codes, their default English templates and the translation helpers.
2037
+ *
2038
+ * The validator is locale-agnostic: every error it reports carries a stable `code` and the
2039
+ * `params` its message needs, and its `message` is the default English text (the code's
2040
+ * template filled with the params) or the app's own text from an annotation (`custom: true`).
2041
+ * Translate after the fact with {@link localizeErrors}, or per validator with the `translate`
2042
+ * option.
2043
+ */ /**
2044
+ * Default English templates of the built-in error codes. `{name}` is replaced with
2045
+ * `params.name` (see {@link formatValidatorMessage}).
2046
+ */ const VALIDATOR_MESSAGES = Object.freeze({
2047
+ REQUIRED: "Must not be empty",
2048
+ REQUIRED_CHECKED: "Must be checked",
2049
+ TYPE: "Expected {expected}, got {actual}",
2050
+ TYPE_ARRAY: "Expected array",
2051
+ TYPE_OBJECT: "Expected object",
2052
+ TYPE_DECIMAL: "Expected string (decimal), got {actual}",
2053
+ NOT_FINITE: "Expected finite number, got {actual}",
2054
+ DECIMAL_FORMAT: "Invalid decimal format: \"{value}\"",
2055
+ NEVER: "This type is impossible, must be an internal problem",
2056
+ LITERAL: "Expected {expected}, got {actual}",
2057
+ UNION: "Value does not match any of the allowed types: {expected}",
2058
+ UNION_DISCRIMINATOR: "Expected one of {allowed}, got {actual}",
2059
+ UNEXPECTED_PROPERTY: "Unexpected property",
2060
+ TUPLE_LENGTH: "Expected array of length {length}",
2061
+ MIN_LENGTH: "Expected minimum length of {min} characters, got {actual} characters",
2062
+ MAX_LENGTH: "Expected maximum length of {max} characters, got {actual} characters",
2063
+ MIN_ITEMS: "Expected minimum length of {min} items, got {actual} items",
2064
+ MAX_ITEMS: "Expected maximum length of {max} items, got {actual} items",
2065
+ UNIQUE_ITEMS: "Duplicate items are not allowed",
2066
+ MIN_KEYS: "Expected at least {min} properties, got {actual}",
2067
+ MAX_KEYS: "Expected at most {max} properties, got {actual}",
2068
+ PATTERN: "Value is expected to match pattern \"{pattern}\"",
2069
+ INT: "Expected integer, got {actual}",
2070
+ MIN: "Expected minimum {min}, got {actual}",
2071
+ MAX: "Expected maximum {max}, got {actual}",
2072
+ EXCLUSIVE_MIN: "Expected greater than {min}, got {actual}",
2073
+ EXCLUSIVE_MAX: "Expected less than {max}, got {actual}",
2074
+ EMAIL: "Invalid email format.",
2075
+ PHONE: "Invalid phone number format.",
2076
+ DATE: "Invalid date format.",
2077
+ ISO_DATE: "Invalid ISO date format.",
2078
+ UUID: "Invalid UUID format.",
2079
+ URL: "Invalid URL format.",
2080
+ IPV4: "Invalid IPv4 address.",
2081
+ IPV6: "Invalid IPv6 address.",
2082
+ IP: "Invalid IP address."
2083
+ });
2084
+ /**
2085
+ * The built-in validator error codes by name (`VALIDATOR_ERROR_CODES.MIN_LENGTH === 'MIN_LENGTH'`).
2086
+ * `CUSTOM` is the code of an error a validator plugin reports without a code of its own.
2087
+ */ const VALIDATOR_ERROR_CODES = Object.freeze(Object.fromEntries([...Object.keys(VALIDATOR_MESSAGES), "CUSTOM"].map((code) => [code, code])));
2088
+ /**
2089
+ * Codes of the format messages built into the `string.*` primitives, by their English text
2090
+ * (the primitives' `@expect.pattern` message).
2091
+ */ const FORMAT_CODES = new Map([
2092
+ "EMAIL",
2093
+ "PHONE",
2094
+ "DATE",
2095
+ "ISO_DATE",
2096
+ "UUID",
2097
+ "URL",
2098
+ "IPV4",
2099
+ "IPV6",
2100
+ "IP"
2101
+ ].map((code) => [VALIDATOR_MESSAGES[code], code]));
2102
+ /**
2103
+ * The {@link VALIDATOR_MESSAGES} templates with placeholders, split at them: text, name, text,
2104
+ * name, …, text (`'a {b} c'.split(/\{(\w+)\}/)`).
2105
+ */ const BUILTIN_PARTS = new Map(Object.values(VALIDATOR_MESSAGES).filter((template) => template.includes("{")).map((template) => [template, template.split(/\{(\w+)\}/)]));
2106
+
1982
2107
  //#endregion
1983
2108
  //#region packages/typescript/src/runtime/annotated-type.ts
1984
2109
  /**
@@ -2006,6 +2131,36 @@ var _globalThis$1, _Symbol_for$1;
2006
2131
  return path.flatMap(([, kind], j) => kind !== 0 || j === path.length - 1 ? [j] : []);
2007
2132
  }
2008
2133
 
2134
+ //#endregion
2135
+ //#region packages/typescript/src/runtime/user-text.ts
2136
+ /**
2137
+ * The annotations holding user-facing text (labels, descriptions, error messages): the arguments
2138
+ * their specs flag `userText`. Core's are known from the start ({@link CORE_USER_TEXT}); a plugin's
2139
+ * are registered by the generated modules that write them (`$ut`), or by the plugin itself
2140
+ * ({@link registerUserText}), so a translator finds them at runtime without the specs.
2141
+ */ /** `true`: the value itself is the text; a list: those fields of the value object are. */ /**
2142
+ * The user-facing text of `@atscript/core`'s annotations (its specs' `userText` arguments; a test
2143
+ * keeps them equal).
2144
+ */ const CORE_USER_TEXT = new Map([
2145
+ ["meta.label", true],
2146
+ ["meta.description", true],
2147
+ ["meta.required", ["message"]],
2148
+ ["expect.minLength", ["message"]],
2149
+ ["expect.maxLength", ["message"]],
2150
+ ["expect.min", ["message"]],
2151
+ ["expect.max", ["message"]],
2152
+ ["expect.exclusiveMin", ["message"]],
2153
+ ["expect.exclusiveMax", ["message"]],
2154
+ ["expect.int", ["message"]],
2155
+ ["expect.minKeys", ["message"]],
2156
+ ["expect.maxKeys", ["message"]],
2157
+ ["expect.message", true],
2158
+ ["expect.pattern", ["message"]],
2159
+ ["expect.array.uniqueItems", ["message"]],
2160
+ ["expect.array.key", ["message"]]
2161
+ ]);
2162
+ const USER_TEXT = new Map(CORE_USER_TEXT);
2163
+
2009
2164
  //#endregion
2010
2165
  //#region packages/typescript/src/codegen/import-cycles.ts
2011
2166
  /** The strongly connected component of each document's imports (see {@link sccOf}). */ const componentMemo = /* @__PURE__ */ new WeakMap();
@@ -2511,7 +2666,13 @@ var JsNextRenderer = class extends JsRenderer {
2511
2666
  }
2512
2667
  /** `$a(P.metadata, …)` writes of a class's own annotations (after its `$alias`). */ annotateCalls(name, node) {
2513
2668
  let out = "";
2669
+ const resets = (node.annotations ?? []).filter((an) => an.name === _atscript_core.ANNOTATE_RESET);
2670
+ if (resets.length > 0) {
2671
+ const data = this.blockAnnotationsData(node, resets);
2672
+ out += `\n${this.util("$blk")}(null, -1, ${name}, [[[${data.join(", ")}], []]])`;
2673
+ }
2514
2674
  for (const an of node.annotations ?? []) {
2675
+ if (an.name === _atscript_core.ANNOTATE_RESET) continue;
2515
2676
  const { value, multiple } = this.computeAnnotationValue(node, an);
2516
2677
  out += `\n${this.util("annotate")}(${name}.metadata, ${str(an.name)}, ${value}${multiple ? ", true" : ""})`;
2517
2678
  }
@@ -3452,19 +3613,21 @@ var JsNextRenderer = class extends JsRenderer {
3452
3613
  * The statement needs what the paths go through built (`$f` guards, needs).
3453
3614
  */ entriesData(b, reads) {
3454
3615
  const entries = [];
3455
- const annotationsOf = (node) => (node.annotations ?? []).map((an) => {
3456
- const { value, multiple } = this.computeAnnotationValue(node, an);
3457
- return `[${str(an.name)}, ${value}${multiple ? ", 1" : ""}]`;
3458
- });
3459
- if (b.rank && b.node.annotations?.length) entries.push(`[[${annotationsOf(b.node).join(", ")}], []]`);
3616
+ if (b.rank && b.node.annotations?.length) entries.push(`[[${this.blockAnnotationsData(b.node).join(", ")}], []]`);
3460
3617
  for (const en of b.entries) {
3461
3618
  if (en.error || en.paths.length === 0) continue;
3462
3619
  const copy = reads !== b.target;
3463
3620
  const paths = en.paths.map((p, i) => `[${stepsText(this.stepsData(reads, p, en.kinds[i], false, copy))}]`);
3464
- entries.push(`[[${annotationsOf(en.ref).join(", ")}], ${paths.join(", ")}]`);
3621
+ entries.push(`[[${this.blockAnnotationsData(en.ref).join(", ")}], ${paths.join(", ")}]`);
3465
3622
  }
3466
3623
  return entries.length > 0 ? `[\n ${entries.join(",\n ")},\n]` : "";
3467
3624
  }
3625
+ /** Annotations `anns` of `node` as `$blk` entry data: `[name, value]`, `, 1` for a `multiple`. */ blockAnnotationsData(node, anns = node.annotations ?? []) {
3626
+ return anns.map((an) => {
3627
+ const { value, multiple } = this.computeAnnotationValue(node, an);
3628
+ return `[${str(an.name)}, ${value}${multiple ? ", 1" : ""}]`;
3629
+ });
3630
+ }
3468
3631
  /**
3469
3632
  * The runtime `[step, kind]`s of model path `p` of `reads` (an `as` copy's: its target's
3470
3633
  * structure), and its needs: the classes it walks are built first (a shell def clones a built
@@ -3952,14 +4115,33 @@ var JsNextRenderer = class extends JsRenderer {
3952
4115
  const rank = blocks[0].rank;
3953
4116
  return `const ${R} = [${rank.depth}, ${str(rank.id)}]`;
3954
4117
  }
3955
- /** The layer registries (`$ak`, `$nr`: how layers read those keys), before any statement. */ registries() {
4118
+ /**
4119
+ * The registries (`$ak`, `$nr`: how layers read those keys; `$ut`: the keys holding user-facing
4120
+ * text), before any statement.
4121
+ */ registries() {
3956
4122
  const { append, notReferred } = flagKeys(this.doc.config.annotations);
3957
4123
  const out = [];
3958
4124
  if (append.length > 0) out.push(`${this.util("$ak")}(${append.map(str).join(", ")})`);
3959
4125
  if (notReferred.length > 0) out.push(`${this.util("$nr")}(${notReferred.map(str).join(", ")})`);
4126
+ const userText = this.moduleUserText();
4127
+ if (userText.length > 0) out.push(`${this.util("$ut")}(${userText.map(str).join(", ")})`);
3960
4128
  return out;
3961
4129
  }
3962
4130
  /**
4131
+ * The plugin annotations holding user-facing text this module writes (`$ut` entries: `key`, or
4132
+ * `key:field`); core's are known to the runtime from the start (`CORE_USER_TEXT`).
4133
+ */ moduleUserText() {
4134
+ const out = /* @__PURE__ */ new Set();
4135
+ for (const name of new Set(this.doc.annotations.map((a) => a.name))) {
4136
+ if (CORE_USER_TEXT.has(name)) continue;
4137
+ const spec = this.doc.resolveAnnotation(name);
4138
+ const fields = spec && (0, _atscript_core.userTextFields)(spec);
4139
+ if (fields === true) out.add(name);
4140
+ else if (fields) for (const f of fields) out.add(`${name}:${f}`);
4141
+ }
4142
+ return [...out].sort();
4143
+ }
4144
+ /**
3963
4145
  * The runtime steps of a model path: a `X | null` union the model passes through is a union
3964
4146
  * node at runtime (its non-null item: `|i`, own when the union's holder is, else shelled).
3965
4147
  */ runtimeSteps(d, steps, kinds, { copy = false, items: withItems = false, pure = false } = {}) {
package/dist/index.cjs CHANGED
@@ -1,11 +1,11 @@
1
1
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
- const require_plugin = require('./plugin-oUSsb3Ri.cjs');
3
- const require_unique_name = require('./unique-name-xWd9uO-k.cjs');
2
+ const require_plugin = require('./plugin-Cqao46Gt.cjs');
3
+ const require_user_text = require('./user-text-BddKk8EU.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;
7
7
  exports.default = require_plugin.tsPlugin;
8
8
  exports.importCycle = require_plugin.importCycle;
9
- exports.invalidateCompiledValidators = require_unique_name.invalidateCompiledValidators;
9
+ exports.invalidateCompiledValidators = require_user_text.invalidateCompiledValidators;
10
10
  exports.tsPlugin = require_plugin.tsPlugin;
11
11
  exports.withLoadCheck = require_plugin.withLoadCheck;
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-DhesoKce.mjs";
2
- import { I as invalidateCompiledValidators } from "./unique-name-hg1CyPIs.mjs";
1
+ import { a as withLoadCheck, i as importCycle, n as JS_INTERPRETED_FORMAT, r as tsPlugin, t as JS_COMPILED_FORMAT } from "./plugin-Ct9Ko5JG.mjs";
2
+ import { q as invalidateCompiledValidators } from "./user-text-qL59indq.mjs";
3
3
 
4
4
  export { JS_COMPILED_FORMAT, JS_INTERPRETED_FORMAT, tsPlugin as default, tsPlugin, importCycle, invalidateCompiledValidators, withLoadCheck };