@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/test-utils.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, 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
|
let path = require("path");
|
|
5
5
|
path = require_plugin.__toESM(path);
|
|
6
6
|
let _atscript_core = require("@atscript/core");
|
package/dist/test-utils.d.ts
CHANGED
|
@@ -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;
|
package/dist/test-utils.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as tsPlugin } from "./plugin-
|
|
2
|
-
import { j as Validator } from "./user-text-
|
|
1
|
+
import { r as tsPlugin } from "./plugin-DUInOy5v.mjs";
|
|
2
|
+
import { j as Validator } from "./user-text-DZR5hfLa.mjs";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import { build } from "@atscript/core";
|
|
5
5
|
import { readFileSync, writeFileSync } from "fs";
|
|
@@ -73,10 +73,11 @@
|
|
|
73
73
|
const mapSet = Map.prototype.set;
|
|
74
74
|
/** Global mutation epoch: compiled checks bound in an older epoch re-bind before use. */ let epoch = 0;
|
|
75
75
|
/**
|
|
76
|
-
* Writes of
|
|
77
|
-
* replaced, a layer flag or intrinsic mark registered)
|
|
78
|
-
*
|
|
79
|
-
|
|
76
|
+
* Writes of type trees so far, watched or not: of metadata (any map, any key: `annotate()`, the
|
|
77
|
+
* `Map` methods, a node's map replaced, a layer flag or intrinsic mark registered) and of shape
|
|
78
|
+
* (every {@link touched} mutation, `invalidateCompiledValidators()`). What is derived from a type
|
|
79
|
+
* tree before the last write is derived again (`lazyJsonSchema`, `LayerMap`, `normalizeForType`).
|
|
80
|
+
*/ let typeWrites = 0;
|
|
80
81
|
/** Some bind has watched an object (until then no mutation can affect a compiled check). */ let tracking = false;
|
|
81
82
|
/** Objects (nodes, type defs, metadata / props maps) read by some compiled-check bind. */ const watched = /* @__PURE__ */ new WeakSet();
|
|
82
83
|
/** The current mutation epoch. */ function currentEpoch() {
|
|
@@ -86,7 +87,11 @@ const mapSet = Map.prototype.set;
|
|
|
86
87
|
tracking = true;
|
|
87
88
|
watched.add(obj);
|
|
88
89
|
}
|
|
89
|
-
/**
|
|
90
|
+
/**
|
|
91
|
+
* Records a tracked mutation of `obj`: a type tree write (see `typeWrites`); compiled checks
|
|
92
|
+
* re-bind when some bind has read it.
|
|
93
|
+
*/ function touched(obj) {
|
|
94
|
+
typeWrites++;
|
|
90
95
|
if (tracking && watched.has(obj)) epoch++;
|
|
91
96
|
}
|
|
92
97
|
/**
|
|
@@ -112,13 +117,13 @@ const mapSet = Map.prototype.set;
|
|
|
112
117
|
* avoid mutating validated types per request.
|
|
113
118
|
*/ function invalidateCompiledValidators() {
|
|
114
119
|
epoch++;
|
|
115
|
-
|
|
120
|
+
typeWrites++;
|
|
116
121
|
}
|
|
117
|
-
/** The number of
|
|
118
|
-
return
|
|
122
|
+
/** The number of type tree writes so far (see `typeWrites`). */ function typeWriteCount() {
|
|
123
|
+
return typeWrites;
|
|
119
124
|
}
|
|
120
125
|
/** Records a write of a node's metadata the maps do not see: the node's map replaced. */ function metadataReplaced() {
|
|
121
|
-
|
|
126
|
+
typeWrites++;
|
|
122
127
|
}
|
|
123
128
|
/**
|
|
124
129
|
* `annotate(m, key, value, true)` where map `m` holds `own` as its own value of `key`: appended in
|
|
@@ -127,7 +132,7 @@ const mapSet = Map.prototype.set;
|
|
|
127
132
|
if (Array.isArray(own)) {
|
|
128
133
|
own.push(value);
|
|
129
134
|
if (VALIDATOR_KEY_SET.has(key)) touched(m);
|
|
130
|
-
|
|
135
|
+
else typeWrites++;
|
|
131
136
|
} else m.set(key, [own, value]);
|
|
132
137
|
}
|
|
133
138
|
/**
|
|
@@ -137,21 +142,18 @@ const mapSet = Map.prototype.set;
|
|
|
137
142
|
set(key, value) {
|
|
138
143
|
super.set(key, value);
|
|
139
144
|
if (tracking && VALIDATOR_KEY_SET.has(key)) touched(this);
|
|
140
|
-
|
|
145
|
+
else typeWrites++;
|
|
141
146
|
return this;
|
|
142
147
|
}
|
|
143
148
|
delete(key) {
|
|
144
149
|
const deleted = super.delete(key);
|
|
145
|
-
if (deleted)
|
|
146
|
-
|
|
147
|
-
metadataWrites++;
|
|
148
|
-
}
|
|
150
|
+
if (deleted) if (tracking && VALIDATOR_KEY_SET.has(key)) touched(this);
|
|
151
|
+
else typeWrites++;
|
|
149
152
|
return deleted;
|
|
150
153
|
}
|
|
151
154
|
clear() {
|
|
152
155
|
super.clear();
|
|
153
156
|
touched(this);
|
|
154
|
-
metadataWrites++;
|
|
155
157
|
}
|
|
156
158
|
/** A new map holding `entries`: no write (a new map is in no compiled check nor schema). */ constructor(entries) {
|
|
157
159
|
super();
|
|
@@ -191,7 +193,7 @@ const mapSet = Map.prototype.set;
|
|
|
191
193
|
* a base shows through every layer over it.
|
|
192
194
|
*
|
|
193
195
|
* Reads go through a flattened view of the effective entries, rebuilt on the first read after any
|
|
194
|
-
*
|
|
196
|
+
* type tree write (one global write counter: `typeWriteCount`). The view is used only while
|
|
195
197
|
* every map below is tracked (an `AnnotationMap` or a `LayerMap`, whose writes the counter
|
|
196
198
|
* sees); otherwise the reads are live. A raw write the counter does not see (a node's map swapped,
|
|
197
199
|
* `node.metadata = X`, or edited in place) must be followed by `invalidateCompiledValidators()`,
|
|
@@ -261,7 +263,6 @@ let hiding = false;
|
|
|
261
263
|
s.add(key);
|
|
262
264
|
hiding = true;
|
|
263
265
|
touched(m);
|
|
264
|
-
metadataReplaced();
|
|
265
266
|
}
|
|
266
267
|
/** The keys map `m` hides from its bases (see {@link hideKey}), for a map replacing it. */ function moveHidden(from, to) {
|
|
267
268
|
const s = HIDDEN.get(from);
|
|
@@ -282,7 +283,7 @@ let _Symbol_iterator = Symbol.iterator;
|
|
|
282
283
|
* The flattened view (built again after a metadata write), `undefined`: read live. Internal:
|
|
283
284
|
* this module's readers and the validators read it (`readable`, `filledMeta`), never write.
|
|
284
285
|
*/ view() {
|
|
285
|
-
return this.w ===
|
|
286
|
+
return this.w === typeWriteCount() ? this.f : this.flatten();
|
|
286
287
|
}
|
|
287
288
|
flatten() {
|
|
288
289
|
this.w = -1;
|
|
@@ -292,7 +293,7 @@ let _Symbol_iterator = Symbol.iterator;
|
|
|
292
293
|
f = keys.length === 0 ? NO_ENTRIES : new AnnotationMap(keys.map((k) => [k, this.liveGet(k)]));
|
|
293
294
|
}
|
|
294
295
|
this.f = f;
|
|
295
|
-
this.w =
|
|
296
|
+
this.w = typeWriteCount();
|
|
296
297
|
return f;
|
|
297
298
|
}
|
|
298
299
|
/** The value of `key` (not concatenated), or `MISS`; `nr`: a `passedWhenReferred:false` key. */ lookup(key, nr) {
|
|
@@ -320,7 +321,7 @@ let _Symbol_iterator = Symbol.iterator;
|
|
|
320
321
|
return MISS;
|
|
321
322
|
}
|
|
322
323
|
get(key) {
|
|
323
|
-
const view = this.w ===
|
|
324
|
+
const view = this.w === typeWriteCount() ? this.f : this.flatten();
|
|
324
325
|
return view === void 0 ? this.liveGet(key) : mapGet.call(view, key);
|
|
325
326
|
}
|
|
326
327
|
/** `get` read through the layers (see the file comment). */ liveGet(key) {
|
|
@@ -381,7 +382,6 @@ let _Symbol_iterator = Symbol.iterator;
|
|
|
381
382
|
const deleted = super.delete(key);
|
|
382
383
|
if ((hiding ? HIDDEN.get(this) : void 0)?.delete(key)) {
|
|
383
384
|
touched(this);
|
|
384
|
-
metadataReplaced();
|
|
385
385
|
return true;
|
|
386
386
|
}
|
|
387
387
|
return deleted;
|
|
@@ -423,7 +423,7 @@ Object.defineProperty(LayerMap.prototype, "size", {
|
|
|
423
423
|
});
|
|
424
424
|
/**
|
|
425
425
|
* Every map of `m`'s layers is tracked (an `AnnotationMap` or a `LayerMap`, whose writes count in
|
|
426
|
-
* `
|
|
426
|
+
* `typeWrites`), so a flattened view of `m` stays right until the next write.
|
|
427
427
|
*/ function tracked(m, seen) {
|
|
428
428
|
const p = Object.getPrototypeOf(m);
|
|
429
429
|
if (p !== AnnotationMap.prototype && p !== LayerMap.prototype) return false;
|
|
@@ -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
|
|
3164
|
-
*
|
|
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
|
-
*/ /**
|
|
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
|
|
3984
|
-
*
|
|
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 ===
|
|
3989
|
-
|
|
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
|
|
3993
|
-
|
|
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
|
|
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
|
|
4002
|
-
else registerUserText(entry.slice(0,
|
|
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
|
|
4007
|
-
*
|
|
4008
|
-
*
|
|
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
|
}
|
|
@@ -4207,6 +4214,12 @@ Object.defineProperty(exports, 'enterCut', {
|
|
|
4207
4214
|
return enterCut;
|
|
4208
4215
|
}
|
|
4209
4216
|
});
|
|
4217
|
+
Object.defineProperty(exports, 'formatCodeOf', {
|
|
4218
|
+
enumerable: true,
|
|
4219
|
+
get: function () {
|
|
4220
|
+
return formatCodeOf;
|
|
4221
|
+
}
|
|
4222
|
+
});
|
|
4210
4223
|
Object.defineProperty(exports, 'formatValidatorMessage', {
|
|
4211
4224
|
enumerable: true,
|
|
4212
4225
|
get: function () {
|
|
@@ -4261,12 +4274,6 @@ Object.defineProperty(exports, 'metaEmpty', {
|
|
|
4261
4274
|
return metaEmpty;
|
|
4262
4275
|
}
|
|
4263
4276
|
});
|
|
4264
|
-
Object.defineProperty(exports, 'metadataWriteCount', {
|
|
4265
|
-
enumerable: true,
|
|
4266
|
-
get: function () {
|
|
4267
|
-
return metadataWriteCount;
|
|
4268
|
-
}
|
|
4269
|
-
});
|
|
4270
4277
|
Object.defineProperty(exports, 'pendingStatements', {
|
|
4271
4278
|
enumerable: true,
|
|
4272
4279
|
get: function () {
|
|
@@ -4309,6 +4316,18 @@ Object.defineProperty(exports, 'touched', {
|
|
|
4309
4316
|
return touched;
|
|
4310
4317
|
}
|
|
4311
4318
|
});
|
|
4319
|
+
Object.defineProperty(exports, 'typeWriteCount', {
|
|
4320
|
+
enumerable: true,
|
|
4321
|
+
get: function () {
|
|
4322
|
+
return typeWriteCount;
|
|
4323
|
+
}
|
|
4324
|
+
});
|
|
4325
|
+
Object.defineProperty(exports, 'unionDiscriminator', {
|
|
4326
|
+
enumerable: true,
|
|
4327
|
+
get: function () {
|
|
4328
|
+
return unionDiscriminator;
|
|
4329
|
+
}
|
|
4330
|
+
});
|
|
4312
4331
|
Object.defineProperty(exports, 'uniqueName', {
|
|
4313
4332
|
enumerable: true,
|
|
4314
4333
|
get: function () {
|