@atscript/typescript 0.2.4 → 0.2.5

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.
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_plugin = require('./plugin-Cqao46Gt.cjs');
3
- const require_user_text = require('./user-text-BddKk8EU.cjs');
2
+ const require_plugin = require('./plugin-JJ9MJ6AF.cjs');
3
+ const require_user_text = require('./user-text-Dl8FNKLL.cjs');
4
4
  let path = require("path");
5
5
  path = require_plugin.__toESM(path);
6
6
  let _atscript_core = require("@atscript/core");
@@ -1,162 +1,5 @@
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 and the `defineAnnotatedType()` handle.
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`).
48
- *
49
- * Off (the default), only types annotated with `@emit.compiledValidator` get a compiled
50
- * check. The `'js:compiled'` render format compiles every type; `'js:interpreted'`
51
- * compiles none, ignoring `@emit.compiledValidator` (see {@link JS_INTERPRETED_FORMAT}).
52
- * *(default: `false`)*
53
- */
54
- compileValidators?: boolean;
55
- }
56
-
57
- /** Type definition for union, intersection, or tuple types. */
58
- interface TAtscriptTypeComplex<DataType = unknown> {
59
- kind: 'union' | 'intersection' | 'tuple';
60
- items: TAtscriptAnnotatedType[];
61
- tags: Set<AtscriptPrimitiveTags>;
62
- /** @internal phantom — carries the DataType at the type level, never set at runtime */
63
- __dataType?: DataType;
64
- }
65
- /** Type definition for array types. */
66
- interface TAtscriptTypeArray<DataType = unknown[]> {
67
- kind: 'array';
68
- of: TAtscriptAnnotatedType;
69
- tags: Set<AtscriptPrimitiveTags>;
70
- /** @internal phantom — carries the DataType at the type level, never set at runtime */
71
- __dataType?: DataType;
72
- }
73
- /** Type definition for object types with named and pattern-matched properties. */
74
- interface TAtscriptTypeObject<K extends string = string, DataType = Record<K, unknown>> {
75
- kind: 'object';
76
- props: Map<K, TAtscriptAnnotatedType>;
77
- propsPatterns: Array<{
78
- pattern: RegExp;
79
- def: TAtscriptAnnotatedType;
80
- }>;
81
- tags: Set<AtscriptPrimitiveTags>;
82
- /** @internal phantom — carries the DataType at the type level, never set at runtime */
83
- __dataType?: DataType;
84
- }
85
- /** Type definition for primitive/literal types (string, number, boolean, null, etc.). */
86
- interface TAtscriptTypeFinal<DataType = unknown> {
87
- kind: '';
88
- /**
89
- * design type
90
- */
91
- designType: 'string' | 'number' | 'boolean' | 'undefined' | 'null' | 'object' | 'any' | 'never' | 'phantom' | 'decimal';
92
- /**
93
- * value for literals
94
- */
95
- value?: string | number | boolean;
96
- tags: Set<AtscriptPrimitiveTags>;
97
- /** @internal phantom — carries the DataType at the type level, never set at runtime */
98
- __dataType?: DataType;
99
- }
100
- /**
101
- * Extract DataType from a type def's phantom generic
102
- */
103
- type InferDataType<T> = T extends {
104
- __dataType?: infer D;
105
- } ? D : unknown;
106
- /**
107
- * Extract the DataType from a {@link TAtscriptAnnotatedType}.
108
- *
109
- * Resolves the phantom `__dataType` carried by the type definition.
110
- * When `__dataType` is `unknown` (unset), falls back to the constructor
111
- * instance type if `T` is also a class (i.e. a generated interface).
112
- *
113
- * @example
114
- * ```ts
115
- * import type { TAtscriptDataType } from '@atscript/typescript/utils'
116
- * import MyInterface from './my-interface.as'
117
- *
118
- * type Data = TAtscriptDataType<typeof MyInterface>
119
- * ```
120
- */
121
- type TAtscriptDataType<T extends TAtscriptAnnotatedType = TAtscriptAnnotatedType> = T extends {
122
- type: {
123
- __dataType?: infer D;
124
- };
125
- } ? unknown extends D ? T extends new (...args: any[]) => infer I ? I : unknown : D : unknown;
126
- /** Union of all possible type definition shapes. */
127
- type TAtscriptTypeDef<DataType = unknown> = TAtscriptTypeComplex<DataType> | TAtscriptTypeFinal<DataType> | TAtscriptTypeArray<DataType> | TAtscriptTypeObject<string, DataType>;
128
- /**
129
- * Core annotated type — wraps a type definition with metadata and a validator factory.
130
- *
131
- * Generated `.as` files produce classes/namespaces that conform to this interface.
132
- * The `DataType` phantom generic carries the TypeScript data shape for type-safe validation.
133
- *
134
- * @typeParam T - The underlying type definition (e.g. {@link TAtscriptTypeObject}).
135
- * @typeParam DataType - The TypeScript type the validated data narrows to (auto-inferred from `T`).
136
- */
137
- interface TAtscriptAnnotatedType<T extends TAtscriptTypeDef = TAtscriptTypeDef, DataType = InferDataType<T>> {
138
- __is_atscript_annotated_type: true;
139
- type: T;
140
- validator(opts?: Partial<TValidatorOptions>): Validator<this, DataType>;
141
- metadata: TMetadataMap<AtscriptMetadata>;
142
- optional?: boolean;
143
- id?: string;
144
- ref?: {
145
- type: () => TAtscriptAnnotatedType;
146
- field: string;
147
- };
148
- }
149
- /**
150
- * Atscript Metadata Map with typed setters/getters
151
- */
152
- interface TMetadataMap<O extends object> extends Map<keyof O, O[keyof O]> {
153
- get<K extends keyof O>(key: K): O[K] | undefined;
154
- get(key: string): unknown;
155
- set<K extends keyof O>(key: K, value: O[K]): this;
156
- has<K extends keyof O>(key: K): boolean;
157
- has(key: string): boolean;
158
- }
159
-
160
3
  /**
161
4
  * Validator error codes, their default English templates and the translation helpers.
162
5
  *
@@ -522,6 +365,191 @@ declare class Validator<T extends TAtscriptAnnotatedType = TAtscriptAnnotatedTyp
522
365
  private keptKeyCount;
523
366
  }
524
367
 
368
+ /** Type definition for union, intersection, or tuple types. */
369
+ interface TAtscriptTypeComplex<DataType = unknown> {
370
+ kind: 'union' | 'intersection' | 'tuple';
371
+ items: TAtscriptAnnotatedType[];
372
+ tags: Set<AtscriptPrimitiveTags>;
373
+ /** @internal phantom — carries the DataType at the type level, never set at runtime */
374
+ __dataType?: DataType;
375
+ }
376
+ /** Type definition for array types. */
377
+ interface TAtscriptTypeArray<DataType = unknown[]> {
378
+ kind: 'array';
379
+ of: TAtscriptAnnotatedType;
380
+ tags: Set<AtscriptPrimitiveTags>;
381
+ /** @internal phantom — carries the DataType at the type level, never set at runtime */
382
+ __dataType?: DataType;
383
+ }
384
+ /** Type definition for object types with named and pattern-matched properties. */
385
+ interface TAtscriptTypeObject<K extends string = string, DataType = Record<K, unknown>> {
386
+ kind: 'object';
387
+ props: Map<K, TAtscriptAnnotatedType>;
388
+ propsPatterns: Array<{
389
+ pattern: RegExp;
390
+ def: TAtscriptAnnotatedType;
391
+ }>;
392
+ tags: Set<AtscriptPrimitiveTags>;
393
+ /** @internal phantom — carries the DataType at the type level, never set at runtime */
394
+ __dataType?: DataType;
395
+ }
396
+ /** Type definition for primitive/literal types (string, number, boolean, null, etc.). */
397
+ interface TAtscriptTypeFinal<DataType = unknown> {
398
+ kind: '';
399
+ /**
400
+ * design type
401
+ */
402
+ designType: 'string' | 'number' | 'boolean' | 'undefined' | 'null' | 'object' | 'any' | 'never' | 'phantom' | 'decimal';
403
+ /**
404
+ * value for literals
405
+ */
406
+ value?: string | number | boolean;
407
+ tags: Set<AtscriptPrimitiveTags>;
408
+ /** @internal phantom — carries the DataType at the type level, never set at runtime */
409
+ __dataType?: DataType;
410
+ }
411
+ /**
412
+ * Extract DataType from a type def's phantom generic
413
+ */
414
+ type InferDataType<T> = T extends {
415
+ __dataType?: infer D;
416
+ } ? D : unknown;
417
+ /**
418
+ * Extract the DataType from a {@link TAtscriptAnnotatedType}.
419
+ *
420
+ * Resolves the phantom `__dataType` carried by the type definition.
421
+ * When `__dataType` is `unknown` (unset), falls back to the constructor
422
+ * instance type if `T` is also a class (i.e. a generated interface).
423
+ *
424
+ * @example
425
+ * ```ts
426
+ * import type { TAtscriptDataType } from '@atscript/typescript/utils'
427
+ * import MyInterface from './my-interface.as'
428
+ *
429
+ * type Data = TAtscriptDataType<typeof MyInterface>
430
+ * ```
431
+ */
432
+ type TAtscriptDataType<T extends TAtscriptAnnotatedType = TAtscriptAnnotatedType> = T extends {
433
+ type: {
434
+ __dataType?: infer D;
435
+ };
436
+ } ? unknown extends D ? T extends new (...args: any[]) => infer I ? I : unknown : D : unknown;
437
+ /** Union of all possible type definition shapes. */
438
+ type TAtscriptTypeDef<DataType = unknown> = TAtscriptTypeComplex<DataType> | TAtscriptTypeFinal<DataType> | TAtscriptTypeArray<DataType> | TAtscriptTypeObject<string, DataType>;
439
+ /**
440
+ * Core annotated type — wraps a type definition with metadata and a validator factory.
441
+ *
442
+ * Generated `.as` files produce classes/namespaces that conform to this interface.
443
+ * The `DataType` phantom generic carries the TypeScript data shape for type-safe validation.
444
+ *
445
+ * @typeParam T - The underlying type definition (e.g. {@link TAtscriptTypeObject}).
446
+ * @typeParam DataType - The TypeScript type the validated data narrows to (auto-inferred from `T`).
447
+ */
448
+ interface TAtscriptAnnotatedType<T extends TAtscriptTypeDef = TAtscriptTypeDef, DataType = InferDataType<T>> {
449
+ __is_atscript_annotated_type: true;
450
+ type: T;
451
+ validator(opts?: Partial<TValidatorOptions>): Validator<this, DataType>;
452
+ metadata: TMetadataMap<AtscriptMetadata>;
453
+ optional?: boolean;
454
+ id?: string;
455
+ ref?: {
456
+ type: () => TAtscriptAnnotatedType;
457
+ field: string;
458
+ };
459
+ }
460
+ /**
461
+ * Atscript Metadata Map with typed setters/getters
462
+ */
463
+ interface TMetadataMap<O extends object> extends Map<keyof O, O[keyof O]> {
464
+ get<K extends keyof O>(key: K): O[K] | undefined;
465
+ get(key: string): unknown;
466
+ set<K extends keyof O>(key: K, value: O[K]): this;
467
+ has<K extends keyof O>(key: K): boolean;
468
+ has(key: string): boolean;
469
+ }
470
+
471
+ /** Options of {@link buildJsonSchema} (and of the `jsonSchemaOptions` plugin option). */
472
+ interface TJsonSchemaOptions {
473
+ /**
474
+ * `additionalProperties: false` on every object schema: the schema rejects keys the type does
475
+ * not declare, as the validator does with its default `unknownProps: 'error'`.
476
+ * *(default: `false`)*
477
+ */
478
+ closed?: boolean;
479
+ /**
480
+ * `@meta.description` → `description` and `@meta.label` → `title`, on the schema of the
481
+ * type or field that carries them. *(default: `true`)*
482
+ */
483
+ annotations?: boolean;
484
+ /**
485
+ * A union of literals (`'a' | 'b'`, also with `null`) → `{ type, enum }` instead of an
486
+ * `anyOf` of `const` schemas. *(default: `true`)*
487
+ */
488
+ enums?: boolean;
489
+ }
490
+
491
+ interface TTsPluginOptions {
492
+ /**
493
+ * JSON Schema support mode:
494
+ * - `false` — No support. `toJsonSchema()` throws at runtime. No `buildJsonSchema` import. *(default)*
495
+ * - `'lazy'` — Import `buildJsonSchema`, compute on demand, cache in type object.
496
+ * - `'bundle'` — Pre-compute at build time, embed static JSON in output. No import.
497
+ *
498
+ * Individual interfaces can override this with `@emit.jsonSchema` annotation
499
+ * to force build-time embedding regardless of this setting.
500
+ */
501
+ jsonSchema?: false | 'lazy' | 'bundle';
502
+ /**
503
+ * Options of the generated `toJsonSchema()` (`'lazy'`, `'bundle'` and `@emit.jsonSchema`
504
+ * alike): the same schema `buildJsonSchema(type, jsonSchemaOptions)` builds at runtime.
505
+ * `closed` (`additionalProperties: false`, default `false`), `annotations` (`description` /
506
+ * `title` from `@meta.description` / `@meta.label`, default `true`), `enums` (a union of
507
+ * literals as `enum`, default `true`).
508
+ */
509
+ jsonSchemaOptions?: TJsonSchemaOptions;
510
+ /**
511
+ * Example data support:
512
+ * - `false` — No support. `toExampleData` is not rendered. *(default)*
513
+ * - `true` — Import `createDataFromAnnotatedType`, create example data on each call.
514
+ */
515
+ exampleData?: boolean;
516
+ /**
517
+ * Extension the emitted JS uses for **relative** `.as` imports
518
+ * (`./user` → `./user.as` by default). Bare specifiers (packages, e.g.
519
+ * `some-pkg/models/user.as`) always keep `.as` because they resolve through
520
+ * the package's `exports` map.
521
+ *
522
+ * `.as.mjs` is what `asc db sync` uses to load the compiled models straight
523
+ * from Node. *(default: `'.as'`)*
524
+ */
525
+ moduleExtension?: '.as' | '.as.js' | '.as.mjs';
526
+ /**
527
+ * Emit a build-time compiled validator check per type into the `.as.js` output.
528
+ *
529
+ * `validate()` then runs the type's compiled check instead of the interpreted pre-check
530
+ * (results and errors are identical; only speed differs). The check binds to the live
531
+ * type on first use and re-binds after mutations made through `annotate()`, the
532
+ * metadata / props `Map` methods and the `defineAnnotatedType()` handle.
533
+ * Raw writes need `invalidateCompiledValidators()`: property writes (`node.optional = …`,
534
+ * `type.items.push(…)`, …) and in-place edits of annotation values (mutating a constraint
535
+ * object, pushing onto an `@expect.pattern` array directly) — the check keeps the values
536
+ * it bound until then. Any runtime mutation of a type a check has bound to makes the
537
+ * checks re-bind once on next use: cheap at startup, but avoid it per request. Types it
538
+ * cannot bind to, and types not built from generated modules (deserialised,
539
+ * JSON-schema-built, flattened, hand-built), are validated by the interpreted path as
540
+ * before.
541
+ *
542
+ * Adds code to every `.as.js`: meant for backend builds — leave it off for bundles
543
+ * shipped to browsers (the code is CSP-safe: no `eval` / `new Function`).
544
+ *
545
+ * Off (the default), only types annotated with `@emit.compiledValidator` get a compiled
546
+ * check. The `'js:compiled'` render format compiles every type; `'js:interpreted'`
547
+ * compiles none, ignoring `@emit.compiledValidator` (see {@link JS_INTERPRETED_FORMAT}).
548
+ * *(default: `false`)*
549
+ */
550
+ compileValidators?: boolean;
551
+ }
552
+
525
553
  interface PrepareFixturesOptions {
526
554
  /** Absolute directory containing the `.as` fixture files. */
527
555
  rootDir: string;
@@ -1,5 +1,5 @@
1
- import { r as tsPlugin } from "./plugin-Ct9Ko5JG.mjs";
2
- import { j as Validator } from "./user-text-qL59indq.mjs";
1
+ import { r as tsPlugin } from "./plugin-Bx7j-vWf.mjs";
2
+ import { j as Validator } from "./user-text-BOf56N4d.mjs";
3
3
  import path from "path";
4
4
  import { build } from "@atscript/core";
5
5
  import { readFileSync, writeFileSync } from "fs";
@@ -990,7 +990,7 @@ function caseVariants(ch, unicode) {
990
990
  let result = null;
991
991
  for (const candidate of candidates) {
992
992
  const values = /* @__PURE__ */ new Set();
993
- const indexMapping = {};
993
+ const indexMapping = Object.create(null);
994
994
  let valid = true;
995
995
  for (let i = 0; i < items.length; i++) {
996
996
  const prop = items[i].type.props.get(candidate);
@@ -3159,8 +3159,8 @@ function _define_property(obj, key, value) {
3159
3159
  return typeof annotation === "object" && annotation !== null ? annotation.message || void 0 : void 0;
3160
3160
  }
3161
3161
  /**
3162
- * Decided discriminators, by union `items` (reported errors only: a union's discriminator is
3163
- * looked for once its value failed). An entry is reused while the items, their type defs and the
3162
+ * Decided discriminators, by union `items` (the validator's reported errors, the branch
3163
+ * `normalizeForType` takes). An entry is reused while the items, their type defs and the
3164
3164
  * discriminator props are the same objects.
3165
3165
  */ const discCache = /* @__PURE__ */ new WeakMap();
3166
3166
  /**
@@ -3956,7 +3956,11 @@ const queue = [];
3956
3956
  * their specs flag `userText`. Core's are known from the start ({@link CORE_USER_TEXT}); a plugin's
3957
3957
  * are registered by the generated modules that write them (`$ut`), or by the plugin itself
3958
3958
  * ({@link registerUserText}), so a translator finds them at runtime without the specs.
3959
- */ /** `true`: the value itself is the text; a list: those fields of the value object are. */ /**
3959
+ */ /**
3960
+ * `true`: the value itself is the text; `'expression'`: the value is the source of a function the
3961
+ * client evaluates, its string literals the texts; a list: those fields of the value object are
3962
+ * (a name ending in `()`: that field is an expression).
3963
+ */ /**
3960
3964
  * The user-facing text of `@atscript/core`'s annotations (its specs' `userText` arguments; a test
3961
3965
  * keeps them equal).
3962
3966
  */ const CORE_USER_TEXT = new Map([
@@ -3979,33 +3983,36 @@ const queue = [];
3979
3983
  ]);
3980
3984
  const USER_TEXT = new Map(CORE_USER_TEXT);
3981
3985
  /**
3982
- * Registers metadata key `key` as holding user-facing text: `true` (default) — its value is the
3983
- * text; a list of field names — those fields of its value object are. Fields add up across calls.
3986
+ * Registers metadata key `key` as holding user-facing text (see {@link TUserTextFields}; `true` by
3987
+ * default). Fields add up across calls; a whole-value kind replaces a field list, and an
3988
+ * expression wins over text (`name()` over `name`), whatever the order of the calls.
3984
3989
  * For plugins that write such metadata at runtime; generated modules register what they write.
3985
3990
  */ function registerUserText(key, fields = true) {
3986
3991
  const known = USER_TEXT.get(key);
3987
- if (known === true || fields === true) {
3988
- USER_TEXT.set(key, true);
3992
+ if (known === "expression" || known === true && typeof fields === "object") return;
3993
+ if (typeof fields !== "object") {
3994
+ USER_TEXT.set(key, fields);
3989
3995
  return;
3990
3996
  }
3991
- const added = fields.filter((f) => !known?.includes(f));
3992
- if (added.length > 0 || !known) USER_TEXT.set(key, [...known ?? [], ...added]);
3997
+ const all = new Set([...typeof known === "object" ? known : [], ...fields]);
3998
+ USER_TEXT.set(key, [...all].filter((f) => !all.has(`${f}()`)));
3993
3999
  }
3994
4000
  /**
3995
4001
  * Registers user-text keys written by a generated module (see {@link registerUserText}): `key` —
3996
- * the value itself; `key:field` — that field of the value object.
4002
+ * the value itself; `key()` — the value is an expression; `key:field` — that field of the value
4003
+ * object; `key:field()` — that field is an expression.
3997
4004
  */ function $ut(...entries) {
3998
4005
  for (const entry of entries) {
3999
4006
  const at = entry.indexOf(":");
4000
- if (at === -1) registerUserText(entry);
4001
- else registerUserText(entry.slice(0, at), [entry.slice(at + 1)]);
4007
+ if (at !== -1) registerUserText(entry.slice(0, at), [entry.slice(at + 1)]);
4008
+ else if (entry.endsWith("()")) registerUserText(entry.slice(0, -2), "expression");
4009
+ else registerUserText(entry);
4002
4010
  }
4003
4011
  }
4004
4012
  /**
4005
- * Where metadata key `key` holds user-facing text: `true` — its value is the text (a string; for
4006
- * a `multiple` annotation, each item of the list); a list of field names — those fields of its
4007
- * value object (each item's, for a list); `undefined` — no user-facing text. Core keys are known
4008
- * from the start; a plugin's once a module writing them is loaded (or the plugin registered them).
4013
+ * Where metadata key `key` holds user-facing text (see {@link TUserTextFields}; for a `multiple`
4014
+ * annotation, each item of its list), `undefined` when it holds none. Core keys are known from the
4015
+ * start; a plugin's once a module writing them is loaded (or the plugin registered them).
4009
4016
  */ function userTextOf(key) {
4010
4017
  return USER_TEXT.get(key);
4011
4018
  }
@@ -4014,4 +4021,4 @@ const USER_TEXT = new Map(CORE_USER_TEXT);
4014
4021
  }
4015
4022
 
4016
4023
  //#endregion
4017
- export { boundOf as $, propAtChain as A, jsonSchemaPattern as B, createAnnotatedTypeNode as C, isAnnotatedType as D, defineAnnotatedType as E, formatValidatorMessage as F, metaEmpty as G, $ak as H, localizeErrors as I, metadataWriteCount as J, watchLayer as K, messagesTranslator as L, ValidatorError as M, VALIDATOR_ERROR_CODES as N, isAnnotatedTypeOfPrimitive as O, VALIDATOR_MESSAGES as P, arrayKeyProps as Q, registerCompiledCheck as R, annotate as S, createObjectTypeDef as T, $nr as U, statelessRegExp as V, LayerMap as W, DECIMAL_RE as X, touched as Y, VALIDATOR_KEYS as Z, pendingStatements as _, userTextOf as a, cutKey as b, $blk as c, $fc as d, $ft as f, appliedBlockModules as g, $sh as h, userTextKeys as i, Validator as j, isPhantomType as k, $end as l, $q as m, CORE_USER_TEXT as n, uniqueName as o, $ps as p, invalidateCompiledValidators as q, registerUserText as r, $alias as s, $ut as t, $f as u, stageEnds as v, createMetadataMap as w, enterCut as x, cutAs as y, detectDiscriminator as z };
4024
+ export { DECIMAL_RE as $, propAtChain as A, registerCompiledCheck as B, createAnnotatedTypeNode as C, isAnnotatedType as D, defineAnnotatedType as E, VALIDATOR_MESSAGES as F, $nr as G, jsonSchemaPattern as H, formatCodeOf as I, watchLayer as J, LayerMap as K, formatValidatorMessage as L, ValidatorError as M, unionDiscriminator as N, isAnnotatedTypeOfPrimitive as O, VALIDATOR_ERROR_CODES as P, touched as Q, localizeErrors as R, annotate as S, createObjectTypeDef as T, statelessRegExp as U, detectDiscriminator as V, $ak as W, invalidateCompiledValidators as X, currentEpoch as Y, metadataWriteCount as Z, pendingStatements as _, userTextOf as a, cutKey as b, $blk as c, $fc as d, VALIDATOR_KEYS as et, $ft as f, appliedBlockModules as g, $sh as h, userTextKeys as i, Validator as j, isPhantomType as k, $end as l, $q as m, CORE_USER_TEXT as n, boundOf as nt, uniqueName as o, $ps as p, metaEmpty as q, registerUserText as r, $alias as s, $ut as t, arrayKeyProps as tt, $f as u, stageEnds as v, createMetadataMap as w, enterCut as x, cutAs as y, messagesTranslator as z };
@@ -991,7 +991,7 @@ function caseVariants(ch, unicode) {
991
991
  let result = null;
992
992
  for (const candidate of candidates) {
993
993
  const values = /* @__PURE__ */ new Set();
994
- const indexMapping = {};
994
+ const indexMapping = Object.create(null);
995
995
  let valid = true;
996
996
  for (let i = 0; i < items.length; i++) {
997
997
  const prop = items[i].type.props.get(candidate);
@@ -3160,8 +3160,8 @@ function _define_property(obj, key, value) {
3160
3160
  return typeof annotation === "object" && annotation !== null ? annotation.message || void 0 : void 0;
3161
3161
  }
3162
3162
  /**
3163
- * Decided discriminators, by union `items` (reported errors only: a union's discriminator is
3164
- * looked for once its value failed). An entry is reused while the items, their type defs and the
3163
+ * Decided discriminators, by union `items` (the validator's reported errors, the branch
3164
+ * `normalizeForType` takes). An entry is reused while the items, their type defs and the
3165
3165
  * discriminator props are the same objects.
3166
3166
  */ const discCache = /* @__PURE__ */ new WeakMap();
3167
3167
  /**
@@ -3957,7 +3957,11 @@ const queue = [];
3957
3957
  * their specs flag `userText`. Core's are known from the start ({@link CORE_USER_TEXT}); a plugin's
3958
3958
  * are registered by the generated modules that write them (`$ut`), or by the plugin itself
3959
3959
  * ({@link registerUserText}), so a translator finds them at runtime without the specs.
3960
- */ /** `true`: the value itself is the text; a list: those fields of the value object are. */ /**
3960
+ */ /**
3961
+ * `true`: the value itself is the text; `'expression'`: the value is the source of a function the
3962
+ * client evaluates, its string literals the texts; a list: those fields of the value object are
3963
+ * (a name ending in `()`: that field is an expression).
3964
+ */ /**
3961
3965
  * The user-facing text of `@atscript/core`'s annotations (its specs' `userText` arguments; a test
3962
3966
  * keeps them equal).
3963
3967
  */ const CORE_USER_TEXT = new Map([
@@ -3980,33 +3984,36 @@ const queue = [];
3980
3984
  ]);
3981
3985
  const USER_TEXT = new Map(CORE_USER_TEXT);
3982
3986
  /**
3983
- * Registers metadata key `key` as holding user-facing text: `true` (default) — its value is the
3984
- * text; a list of field names — those fields of its value object are. Fields add up across calls.
3987
+ * Registers metadata key `key` as holding user-facing text (see {@link TUserTextFields}; `true` by
3988
+ * default). Fields add up across calls; a whole-value kind replaces a field list, and an
3989
+ * expression wins over text (`name()` over `name`), whatever the order of the calls.
3985
3990
  * For plugins that write such metadata at runtime; generated modules register what they write.
3986
3991
  */ function registerUserText(key, fields = true) {
3987
3992
  const known = USER_TEXT.get(key);
3988
- if (known === true || fields === true) {
3989
- USER_TEXT.set(key, true);
3993
+ if (known === "expression" || known === true && typeof fields === "object") return;
3994
+ if (typeof fields !== "object") {
3995
+ USER_TEXT.set(key, fields);
3990
3996
  return;
3991
3997
  }
3992
- const added = fields.filter((f) => !known?.includes(f));
3993
- if (added.length > 0 || !known) USER_TEXT.set(key, [...known ?? [], ...added]);
3998
+ const all = new Set([...typeof known === "object" ? known : [], ...fields]);
3999
+ USER_TEXT.set(key, [...all].filter((f) => !all.has(`${f}()`)));
3994
4000
  }
3995
4001
  /**
3996
4002
  * Registers user-text keys written by a generated module (see {@link registerUserText}): `key` —
3997
- * the value itself; `key:field` — that field of the value object.
4003
+ * the value itself; `key()` — the value is an expression; `key:field` — that field of the value
4004
+ * object; `key:field()` — that field is an expression.
3998
4005
  */ function $ut(...entries) {
3999
4006
  for (const entry of entries) {
4000
4007
  const at = entry.indexOf(":");
4001
- if (at === -1) registerUserText(entry);
4002
- else registerUserText(entry.slice(0, at), [entry.slice(at + 1)]);
4008
+ if (at !== -1) registerUserText(entry.slice(0, at), [entry.slice(at + 1)]);
4009
+ else if (entry.endsWith("()")) registerUserText(entry.slice(0, -2), "expression");
4010
+ else registerUserText(entry);
4003
4011
  }
4004
4012
  }
4005
4013
  /**
4006
- * Where metadata key `key` holds user-facing text: `true` — its value is the text (a string; for
4007
- * a `multiple` annotation, each item of the list); a list of field names — those fields of its
4008
- * value object (each item's, for a list); `undefined` — no user-facing text. Core keys are known
4009
- * from the start; a plugin's once a module writing them is loaded (or the plugin registered them).
4014
+ * Where metadata key `key` holds user-facing text (see {@link TUserTextFields}; for a `multiple`
4015
+ * annotation, each item of its list), `undefined` when it holds none. Core keys are known from the
4016
+ * start; a plugin's once a module writing them is loaded (or the plugin registered them).
4010
4017
  */ function userTextOf(key) {
4011
4018
  return USER_TEXT.get(key);
4012
4019
  }
@@ -4177,6 +4184,12 @@ Object.defineProperty(exports, 'createObjectTypeDef', {
4177
4184
  return createObjectTypeDef;
4178
4185
  }
4179
4186
  });
4187
+ Object.defineProperty(exports, 'currentEpoch', {
4188
+ enumerable: true,
4189
+ get: function () {
4190
+ return currentEpoch;
4191
+ }
4192
+ });
4180
4193
  Object.defineProperty(exports, 'cutAs', {
4181
4194
  enumerable: true,
4182
4195
  get: function () {
@@ -4207,6 +4220,12 @@ Object.defineProperty(exports, 'enterCut', {
4207
4220
  return enterCut;
4208
4221
  }
4209
4222
  });
4223
+ Object.defineProperty(exports, 'formatCodeOf', {
4224
+ enumerable: true,
4225
+ get: function () {
4226
+ return formatCodeOf;
4227
+ }
4228
+ });
4210
4229
  Object.defineProperty(exports, 'formatValidatorMessage', {
4211
4230
  enumerable: true,
4212
4231
  get: function () {
@@ -4309,6 +4328,12 @@ Object.defineProperty(exports, 'touched', {
4309
4328
  return touched;
4310
4329
  }
4311
4330
  });
4331
+ Object.defineProperty(exports, 'unionDiscriminator', {
4332
+ enumerable: true,
4333
+ get: function () {
4334
+ return unionDiscriminator;
4335
+ }
4336
+ });
4312
4337
  Object.defineProperty(exports, 'uniqueName', {
4313
4338
  enumerable: true,
4314
4339
  get: function () {