@atscript/typescript 0.1.88 → 0.1.90

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,5 +1,4 @@
1
- "use strict";
2
- //#region rolldown:runtime
1
+ //#region \0rolldown/runtime.js
3
2
  var __create = Object.create;
4
3
  var __defProp = Object.defineProperty;
5
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -7,12 +6,16 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
7
6
  var __getProtoOf = Object.getPrototypeOf;
8
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
8
  var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
- key = keys[i];
12
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
- get: ((k) => from[k]).bind(null, key),
14
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
- });
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
16
19
  }
17
20
  return to;
18
21
  };
@@ -22,9 +25,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
22
25
  }) : target, mod));
23
26
 
24
27
  //#endregion
25
- const require_json_schema = require('./json-schema-3mti4G4J.cjs');
26
- const path = __toESM(require("path"));
27
- const __atscript_core = __toESM(require("@atscript/core"));
28
+ const require_json_schema = require('./json-schema-DXEiCfe1.cjs');
29
+ let path = require("path");
30
+ path = __toESM(path);
31
+ let _atscript_core = require("@atscript/core");
28
32
 
29
33
  //#region packages/typescript/src/codegen/code-printer.ts
30
34
  function _define_property$3(obj, key, value) {
@@ -34,7 +38,7 @@ function _define_property$3(obj, key, value) {
34
38
  configurable: true,
35
39
  writable: true
36
40
  });
37
- else obj[key] = value;
41
+ else obj[key] = value;
38
42
  return obj;
39
43
  }
40
44
  var CodePrinter = class {
@@ -95,7 +99,7 @@ var CodePrinter = class {
95
99
  * Return the entire code as a string. Removes any half-finished current line if empty.
96
100
  */ toString() {
97
101
  if (this.currentLine.trim() !== "") this.lines.push(this.currentLine);
98
- else if (this.currentLine.length > 0) this.lines.push(this.currentLine);
102
+ else if (this.currentLine.length > 0) this.lines.push(this.currentLine);
99
103
  return this.lines.join("\n");
100
104
  }
101
105
  doBlock(pair, withNewLine) {
@@ -113,7 +117,7 @@ else if (this.currentLine.length > 0) this.lines.push(this.currentLine);
113
117
  const closing = this.blockStack.pop();
114
118
  this.unindent();
115
119
  if (withNewLine) this.writeln(closing);
116
- else this.write(closing);
120
+ else this.write(closing);
117
121
  return this;
118
122
  }
119
123
  indentString() {
@@ -137,7 +141,7 @@ function _define_property$2(obj, key, value) {
137
141
  configurable: true,
138
142
  writable: true
139
143
  });
140
- else obj[key] = value;
144
+ else obj[key] = value;
141
145
  return obj;
142
146
  }
143
147
  var BaseRenderer = class extends CodePrinter {
@@ -155,21 +159,21 @@ var BaseRenderer = class extends CodePrinter {
155
159
  renderInterface(node) {}
156
160
  renderType(node) {}
157
161
  renderAnnotate(node) {}
158
- transformFromPath(path$2) {
159
- return `${path$2}.as`;
162
+ transformFromPath(path) {
163
+ return `${path}.as`;
160
164
  }
161
165
  renderImport(node) {
162
166
  const def = node.getDefinition();
163
167
  const refs = [];
164
168
  const from = this.transformFromPath(node.token("path").text);
165
169
  let isUnusedImport = true;
166
- if ((0, __atscript_core.isGroup)(def)) {
167
- for (const child of def.unwrap()) if ((0, __atscript_core.isRef)(child) && !this.unused.has(child.id)) {
168
- const node$1 = child;
169
- refs.push(node$1.id);
170
+ if ((0, _atscript_core.isGroup)(def)) {
171
+ for (const child of def.unwrap()) if ((0, _atscript_core.isRef)(child) && !this.unused.has(child.id)) {
172
+ const node = child;
173
+ refs.push(node.id);
170
174
  isUnusedImport = false;
171
175
  }
172
- } else if ((0, __atscript_core.isRef)(def) && !this.unused.has(def.id)) {
176
+ } else if ((0, _atscript_core.isRef)(def) && !this.unused.has(def.id)) {
173
177
  refs.push(def.id);
174
178
  isUnusedImport = false;
175
179
  }
@@ -177,22 +181,18 @@ var BaseRenderer = class extends CodePrinter {
177
181
  }
178
182
  renderNode(node) {
179
183
  switch (node.entity) {
180
- case "interface": {
184
+ case "interface":
181
185
  this.renderInterface(node);
182
186
  break;
183
- }
184
- case "type": {
187
+ case "type":
185
188
  this.renderType(node);
186
189
  break;
187
- }
188
- case "import": {
190
+ case "import":
189
191
  this.renderImport(node);
190
192
  break;
191
- }
192
- case "annotate": {
193
+ case "annotate":
193
194
  this.renderAnnotate(node);
194
195
  break;
195
- }
196
196
  default: break;
197
197
  }
198
198
  }
@@ -204,7 +204,13 @@ var BaseRenderer = class extends CodePrinter {
204
204
  //#endregion
205
205
  //#region packages/typescript/src/codegen/utils.ts
206
206
  const validIdentifier = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
207
- function wrapProp(name) {
207
+ /**
208
+ * Wraps a property name in double quotes if it's not a valid identifier (contains special chars, etc.).
209
+ *
210
+ * Examples:
211
+ * - "validName" => "validName"
212
+ * - "some-prop" => "\"some-prop\""
213
+ */ function wrapProp(name) {
208
214
  if (!validIdentifier.test(name)) return `"${escapeQuotes(name)}"`;
209
215
  return name;
210
216
  }
@@ -221,7 +227,7 @@ function _define_property$1(obj, key, value) {
221
227
  configurable: true,
222
228
  writable: true
223
229
  });
224
- else obj[key] = value;
230
+ else obj[key] = value;
225
231
  return obj;
226
232
  }
227
233
  var TypeRenderer = class TypeRenderer extends BaseRenderer {
@@ -250,8 +256,8 @@ var TypeRenderer = class TypeRenderer extends BaseRenderer {
250
256
  this.write("unknown");
251
257
  return;
252
258
  }
253
- if ((0, __atscript_core.isStructure)(def)) return this.renderStructure(def);
254
- if ((0, __atscript_core.isGroup)(def)) {
259
+ if ((0, _atscript_core.isStructure)(def)) return this.renderStructure(def);
260
+ if ((0, _atscript_core.isGroup)(def)) {
255
261
  const tuple = def.entity === "tuple";
256
262
  const operator = tuple ? ", " : ` ${def.op} `;
257
263
  const children = def.unwrap();
@@ -264,14 +270,14 @@ var TypeRenderer = class TypeRenderer extends BaseRenderer {
264
270
  }
265
271
  return this.write(tuple ? "]" : hasSubgroup ? ")" : "");
266
272
  }
267
- if ((0, __atscript_core.isConst)(def)) {
273
+ if ((0, _atscript_core.isConst)(def)) {
268
274
  const name = def.token("identifier")?.type === "number" ? def.id : `"${escapeQuotes(def.id)}"`;
269
275
  return this.write(name);
270
276
  }
271
- if ((0, __atscript_core.isRef)(def)) {
277
+ if ((0, _atscript_core.isRef)(def)) {
272
278
  const node = def;
273
279
  const unwound = this.doc.unwindType(node.id, node.chain);
274
- if ((0, __atscript_core.isPrimitive)(unwound?.def)) {
280
+ if ((0, _atscript_core.isPrimitive)(unwound?.def)) {
275
281
  this.write(renderPrimitiveTypeDef(unwound.def.config.type));
276
282
  if (node.hasChain) this.write(` /* ${node.chain.map((c) => c.text).join(".")} */`);
277
283
  return;
@@ -280,21 +286,20 @@ var TypeRenderer = class TypeRenderer extends BaseRenderer {
280
286
  for (const c of node.chain) name += `["${escapeQuotes(c.text)}"]`;
281
287
  return this.write(name);
282
288
  }
283
- if ((0, __atscript_core.isArray)(def)) {
284
- const node = def;
285
- const def2 = node.getDefinition();
289
+ if ((0, _atscript_core.isArray)(def)) {
290
+ const def2 = def.getDefinition();
286
291
  const isGrp = def2?.entity === "group";
287
292
  if (isGrp) this.write("(");
288
293
  this.renderTypeDef(def2);
289
294
  if (isGrp) this.write(")");
290
295
  return this.write("[]");
291
296
  }
292
- if ((0, __atscript_core.isPrimitive)(def)) return this.write(renderPrimitiveTypeDef(def.config.type));
297
+ if ((0, _atscript_core.isPrimitive)(def)) return this.write(renderPrimitiveTypeDef(def.config.type));
293
298
  }
294
299
  renderStructure(struct, asClass, interfaceNode, filterProps) {
295
300
  this.blockln("{}");
296
301
  const patterns = [];
297
- const propsDefs = new Set();
302
+ const propsDefs = /* @__PURE__ */ new Set();
298
303
  for (const prop of struct.props.values()) {
299
304
  if (filterProps?.has(prop.id)) continue;
300
305
  if (prop.token("identifier")?.pattern) {
@@ -361,14 +366,14 @@ var TypeRenderer = class TypeRenderer extends BaseRenderer {
361
366
  let firstParentProps;
362
367
  if (firstParentUnwound?.def) {
363
368
  let fpDef = firstParentUnwound.def;
364
- if ((0, __atscript_core.isInterface)(fpDef)) {
369
+ if ((0, _atscript_core.isInterface)(fpDef)) {
365
370
  if (fpDef.hasExtends) {
366
371
  const fpResolved = firstParentUnwound.doc.resolveInterfaceExtends(fpDef);
367
- if (fpResolved && (0, __atscript_core.isStructure)(fpResolved)) firstParentProps = fpResolved.props;
372
+ if (fpResolved && (0, _atscript_core.isStructure)(fpResolved)) firstParentProps = fpResolved.props;
368
373
  }
369
374
  if (!firstParentProps) fpDef = fpDef.getDefinition() || fpDef;
370
375
  }
371
- if (!firstParentProps && (0, __atscript_core.isStructure)(fpDef)) firstParentProps = fpDef.props;
376
+ if (!firstParentProps && (0, _atscript_core.isStructure)(fpDef)) firstParentProps = fpDef.props;
372
377
  }
373
378
  this.renderStructure(resolved, node.id, node, firstParentProps);
374
379
  } else this.writeln("{}");
@@ -376,7 +381,7 @@ var TypeRenderer = class TypeRenderer extends BaseRenderer {
376
381
  this.write(`class ${node.id} `);
377
382
  const struct = node.getDefinition();
378
383
  if (struct?.entity === "structure") this.renderStructure(struct, node.id, node);
379
- else this.writeln("{}");
384
+ else this.writeln("{}");
380
385
  }
381
386
  this.writeln();
382
387
  }
@@ -416,12 +421,12 @@ else this.writeln("{}");
416
421
  let typeDef = "TAtscriptTypeDef";
417
422
  if (inputDef) {
418
423
  let realDef = inputDef;
419
- if ((0, __atscript_core.isRef)(inputDef)) realDef = this.doc.unwindType(inputDef.id, inputDef.chain)?.def || realDef;
424
+ if ((0, _atscript_core.isRef)(inputDef)) realDef = this.doc.unwindType(inputDef.id, inputDef.chain)?.def || realDef;
420
425
  realDef = this.doc.mergeIntersection(realDef);
421
- if ((0, __atscript_core.isStructure)(realDef) || (0, __atscript_core.isInterface)(realDef)) typeDef = `TAtscriptTypeObject<keyof ${name}, ${name}>`;
422
- else if ((0, __atscript_core.isGroup)(realDef)) typeDef = `TAtscriptTypeComplex<${name}>`;
423
- else if ((0, __atscript_core.isArray)(realDef)) typeDef = `TAtscriptTypeArray<${name}>`;
424
- else if ((0, __atscript_core.isPrimitive)(realDef)) typeDef = `TAtscriptTypeFinal<${name}>`;
426
+ if ((0, _atscript_core.isStructure)(realDef) || (0, _atscript_core.isInterface)(realDef)) typeDef = `TAtscriptTypeObject<keyof ${name}, ${name}>`;
427
+ else if ((0, _atscript_core.isGroup)(realDef)) typeDef = `TAtscriptTypeComplex<${name}>`;
428
+ else if ((0, _atscript_core.isArray)(realDef)) typeDef = `TAtscriptTypeArray<${name}>`;
429
+ else if ((0, _atscript_core.isPrimitive)(realDef)) typeDef = `TAtscriptTypeFinal<${name}>`;
425
430
  }
426
431
  this.writeln(`const __is_atscript_annotated_type: true`);
427
432
  this.writeln(`const type: ${typeDef}`);
@@ -457,12 +462,12 @@ else if ((0, __atscript_core.isPrimitive)(realDef)) typeDef = `TAtscriptTypeFina
457
462
  * not individually queryable)
458
463
  * - **Leaf fields** → their original TypeScript type
459
464
  */ renderFlat(node) {
460
- this.renderFlatMap("__flat", (0, __atscript_core.flattenInterfaceNode)(this.doc, node));
465
+ this.renderFlatMap("__flat", (0, _atscript_core.flattenInterfaceNode)(this.doc, node));
461
466
  }
462
467
  /**
463
468
  * Renders the `static __ownProps` property — table-owned fields only (no nav props).
464
469
  */ renderOwnProps(node) {
465
- this.renderFlatMap("__ownProps", (0, __atscript_core.flattenInterfaceNode)(this.doc, node, { skipNavProps: true }), {
470
+ this.renderFlatMap("__ownProps", (0, _atscript_core.flattenInterfaceNode)(this.doc, node, { skipNavProps: true }), {
466
471
  leadingNewline: true,
467
472
  trailingNewline: true
468
473
  });
@@ -479,21 +484,20 @@ else if ((0, __atscript_core.isPrimitive)(realDef)) typeDef = `TAtscriptTypeFina
479
484
  if (opts?.leadingNewline) this.writeln();
480
485
  this.write(`static ${propName}: `);
481
486
  this.blockln("{}");
482
- for (const [path$2, descriptor] of flatMap) {
483
- this.write(`"${escapeQuotes(path$2)}"`);
487
+ for (const [path, descriptor] of flatMap) {
488
+ this.write(`"${escapeQuotes(path)}"`);
484
489
  if (descriptor.optional) this.write("?");
485
490
  this.write(": ");
486
491
  if (descriptor.intermediate) this.writeln("never");
487
- else if (descriptor.dbJson) this.writeln("string");
488
- else {
492
+ else if (descriptor.dbJson) this.writeln("string");
493
+ else {
489
494
  const originalDef = descriptor.propNode?.getDefinition();
490
- const defToRender = originalDef && !((0, __atscript_core.isGroup)(descriptor.def) && descriptor.def !== originalDef) ? originalDef : descriptor.def;
491
- const renderedDef = this.renderTypeDefString(defToRender);
492
- renderedDef.split("\n").forEach((l) => this.writeln(l));
495
+ const defToRender = originalDef && !((0, _atscript_core.isGroup)(descriptor.def) && descriptor.def !== originalDef) ? originalDef : descriptor.def;
496
+ this.renderTypeDefString(defToRender).split("\n").forEach((l) => this.writeln(l));
493
497
  }
494
498
  }
495
499
  if (opts?.trailingNewline) this.popln();
496
- else this.pop();
500
+ else this.pop();
497
501
  }
498
502
  /**
499
503
  * Renders the `static __navProps` property — a map of navigation property names
@@ -505,12 +509,12 @@ else this.pop();
505
509
  let struct;
506
510
  if (node.hasExtends) struct = this.doc.resolveInterfaceExtends(node);
507
511
  if (!struct) struct = node.getDefinition();
508
- if (!struct || !(0, __atscript_core.isStructure)(struct)) return;
512
+ if (!struct || !(0, _atscript_core.isStructure)(struct)) return;
509
513
  const structNode = struct;
510
514
  const navProps = [];
511
515
  for (const [name, prop] of structNode.props) {
512
516
  if (prop.token("identifier")?.pattern) continue;
513
- if ((0, __atscript_core.hasNavPropAnnotation)(prop)) navProps.push({
517
+ if ((0, _atscript_core.hasNavPropAnnotation)(prop)) navProps.push({
514
518
  name,
515
519
  prop
516
520
  });
@@ -524,10 +528,8 @@ else this.pop();
524
528
  if (prop.token("optional")) this.write("?");
525
529
  this.write(": ");
526
530
  const propDef = prop.getDefinition();
527
- if (propDef) {
528
- const renderedDef = this.renderTypeDefString(propDef);
529
- renderedDef.split("\n").forEach((l) => this.writeln(l));
530
- } else this.writeln("unknown");
531
+ if (propDef) this.renderTypeDefString(propDef).split("\n").forEach((l) => this.writeln(l));
532
+ else this.writeln("unknown");
531
533
  }
532
534
  this.popln();
533
535
  }
@@ -536,10 +538,10 @@ else this.pop();
536
538
  let struct;
537
539
  if (node.hasExtends) struct = this.doc.resolveInterfaceExtends(node);
538
540
  if (!struct) struct = node.getDefinition();
539
- if (!struct || !(0, __atscript_core.isStructure)(struct)) return;
541
+ if (!struct || !(0, _atscript_core.isStructure)(struct)) return;
540
542
  const structNode = struct;
541
543
  const pkProps = [];
542
- const uniqueByIndex = new Map();
544
+ const uniqueByIndex = /* @__PURE__ */ new Map();
543
545
  for (const [name, prop] of structNode.props) {
544
546
  if (prop.token("identifier")?.pattern) continue;
545
547
  if (isMongoCollection && name === "_id") continue;
@@ -573,7 +575,7 @@ else this.pop();
573
575
  mongoIdType ?? (mongoIdType = "string");
574
576
  }
575
577
  const uniqueTypes = [];
576
- const seenTypes = new Set();
578
+ const seenTypes = /* @__PURE__ */ new Set();
577
579
  for (const { prop } of uniqueProps) {
578
580
  const rendered = this.renderTypeDefString(prop.getDefinition()).trim();
579
581
  if (!seenTypes.has(rendered)) {
@@ -584,8 +586,8 @@ else this.pop();
584
586
  this.writeln();
585
587
  const uniqueSuffix = uniqueTypes.length > 0 ? ` | ${uniqueTypes.join(" | ")}` : "";
586
588
  if (pkProps.length === 0 && !isMongoCollection) this.writeln(`static __pk: ${uniqueTypes.join(" | ")}`);
587
- else if (pkProps.length === 0) this.writeln(`static __pk: ${mongoIdType}${uniqueSuffix}`);
588
- else if (pkProps.length === 1) {
589
+ else if (pkProps.length === 0) this.writeln(`static __pk: ${mongoIdType}${uniqueSuffix}`);
590
+ else if (pkProps.length === 1) {
589
591
  this.write("static __pk: ");
590
592
  if (isMongoCollection) this.write(`${mongoIdType} | `);
591
593
  const renderedDef = this.renderTypeDefString(pkProps[0].prop.getDefinition()).trim();
@@ -596,8 +598,7 @@ else if (pkProps.length === 1) {
596
598
  this.blockln("{}");
597
599
  for (const { name, prop } of pkProps) {
598
600
  this.write(wrapProp(name), ": ");
599
- const renderedDef = this.renderTypeDefString(prop.getDefinition());
600
- renderedDef.split("\n").forEach((l) => this.writeln(l));
601
+ this.renderTypeDefString(prop.getDefinition()).split("\n").forEach((l) => this.writeln(l));
601
602
  }
602
603
  this.pop();
603
604
  this.writeln(uniqueSuffix);
@@ -607,7 +608,7 @@ else if (pkProps.length === 1) {
607
608
  let struct;
608
609
  if (node.hasExtends) struct = this.doc.resolveInterfaceExtends(node);
609
610
  if (!struct) struct = node.getDefinition();
610
- if (!struct || !(0, __atscript_core.isStructure)(struct)) return;
611
+ if (!struct || !(0, _atscript_core.isStructure)(struct)) return;
611
612
  const structNode = struct;
612
613
  const dims = [];
613
614
  const measures = [];
@@ -622,18 +623,16 @@ else if (pkProps.length === 1) {
622
623
  if (measures.length > 0) this.writeln(`static __measure: ${measures.map((m) => `"${escapeQuotes(m)}"`).join(" | ")}`);
623
624
  }
624
625
  phantomPropType(def) {
625
- if (!def) return undefined;
626
- if ((0, __atscript_core.isPrimitive)(def) && def.config.type === "phantom") return def.id;
627
- if ((0, __atscript_core.isRef)(def)) {
626
+ if (!def) return;
627
+ if ((0, _atscript_core.isPrimitive)(def) && def.config.type === "phantom") return def.id;
628
+ if ((0, _atscript_core.isRef)(def)) {
628
629
  const ref = def;
629
630
  const unwound = this.doc.unwindType(ref.id, ref.chain)?.def;
630
- if ((0, __atscript_core.isPrimitive)(unwound) && unwound.config.type === "phantom") return ref.hasChain ? `${ref.id}.${ref.chain.map((c) => c.text).join(".")}` : ref.id;
631
+ if ((0, _atscript_core.isPrimitive)(unwound) && unwound.config.type === "phantom") return ref.hasChain ? `${ref.id}.${ref.chain.map((c) => c.text).join(".")}` : ref.id;
631
632
  }
632
- return undefined;
633
633
  }
634
634
  isTypeTarget(name, doc) {
635
- const d = doc || this.doc;
636
- const decl = d.getDeclarationOwnerNode(name);
635
+ const decl = (doc || this.doc).getDeclarationOwnerNode(name);
637
636
  if (!decl?.node) return false;
638
637
  if (decl.node.entity === "type") return true;
639
638
  if (decl.node.entity === "interface") return false;
@@ -661,10 +660,7 @@ function renderPrimitiveTypeDef(def) {
661
660
  case "intersection": return def.items.map(renderPrimitiveTypeDef).join(" & ");
662
661
  case "tuple": return `[${def.items.map(renderPrimitiveTypeDef).join(", ")}]`;
663
662
  case "array": return `${renderPrimitiveTypeDef(def.of)}[]`;
664
- case "object": {
665
- const props = Object.entries(def.props).map(([key, val]) => `${wrapProp(key)}${typeof val === "object" && val.optional ? "?" : ""}: ${renderPrimitiveTypeDef(val)}`).join("; ");
666
- return `{ ${props} }`;
667
- }
663
+ case "object": return `{ ${Object.entries(def.props).map(([key, val]) => `${wrapProp(key)}${typeof val === "object" && val.optional ? "?" : ""}: ${renderPrimitiveTypeDef(val)}`).join("; ")} }`;
668
664
  default: return "unknown";
669
665
  }
670
666
  }
@@ -678,7 +674,7 @@ function _define_property(obj, key, value) {
678
674
  configurable: true,
679
675
  writable: true
680
676
  });
681
- else obj[key] = value;
677
+ else obj[key] = value;
682
678
  return obj;
683
679
  }
684
680
  const QUERY_OP_MAP = {
@@ -707,31 +703,31 @@ var JsRenderer = class extends BaseRenderer {
707
703
  }
708
704
  getExtendsRefs() {
709
705
  if (this._extendsRefs) return this._extendsRefs;
710
- const out = new Map();
711
- const visitedInterfaces = new Set();
712
- for (const node of this.doc.nodes) if ((0, __atscript_core.isInterface)(node) && node.hasExtends) this.walkExtendsParents(node, this.doc, out, visitedInterfaces);
706
+ const out = /* @__PURE__ */ new Map();
707
+ const visitedInterfaces = /* @__PURE__ */ new Set();
708
+ for (const node of this.doc.nodes) if ((0, _atscript_core.isInterface)(node) && node.hasExtends) this.walkExtendsParents(node, this.doc, out, visitedInterfaces);
713
709
  return this._extendsRefs = out;
714
710
  }
715
711
  walkRefs(node, visited, visit) {
716
712
  if (!node || visited.has(node)) return;
717
713
  visited.add(node);
718
- if ((0, __atscript_core.isRef)(node)) {
714
+ if ((0, _atscript_core.isRef)(node)) {
719
715
  visit(node);
720
716
  return;
721
717
  }
722
- if ((0, __atscript_core.isGroup)(node)) {
718
+ if ((0, _atscript_core.isGroup)(node)) {
723
719
  for (const item of node.unwrap()) this.walkRefs(item, visited, visit);
724
720
  return;
725
721
  }
726
- if ((0, __atscript_core.isArray)(node) || (0, __atscript_core.isProp)(node)) this.walkRefs(node.getDefinition(), visited, visit);
722
+ if ((0, _atscript_core.isArray)(node) || (0, _atscript_core.isProp)(node)) this.walkRefs(node.getDefinition(), visited, visit);
727
723
  }
728
724
  walkExtendsParents(iface, doc, out, visited) {
729
725
  if (visited.has(iface)) return;
730
726
  visited.add(iface);
731
- const visitedNodes = new Set();
727
+ const visitedNodes = /* @__PURE__ */ new Set();
732
728
  for (const token of iface.extendsTokens) {
733
729
  const unwound = doc.unwindType(token.text);
734
- if (!unwound?.def || !(0, __atscript_core.isInterface)(unwound.def)) continue;
730
+ if (!unwound?.def || !(0, _atscript_core.isInterface)(unwound.def)) continue;
735
731
  const parentInterface = unwound.def;
736
732
  const parentDoc = unwound.doc;
737
733
  this.walkRefs(parentInterface.getDefinition(), visitedNodes, (ref) => {
@@ -746,18 +742,18 @@ var JsRenderer = class extends BaseRenderer {
746
742
  const refToOriginDoc = this.getExtendsRefs();
747
743
  if (refToOriginDoc.size === 0) return;
748
744
  const taken = new Set(this.doc.registry.definitions.keys());
749
- const allocated = new Map();
750
- const synthPathCache = new Map();
745
+ const allocated = /* @__PURE__ */ new Map();
746
+ const synthPathCache = /* @__PURE__ */ new Map();
751
747
  for (const [refNode, originDoc] of refToOriginDoc) {
752
748
  const refId = refNode.id;
753
749
  if (!refId) continue;
754
750
  const ownerInfo = this.resolveOwner(originDoc, refId);
755
751
  if (!ownerInfo?.doc || ownerInfo.doc === this.doc) continue;
756
- if (ownerInfo.node && (0, __atscript_core.isPrimitive)(ownerInfo.node)) continue;
752
+ if (ownerInfo.node && (0, _atscript_core.isPrimitive)(ownerInfo.node)) continue;
757
753
  const ownerDoc = ownerInfo.doc;
758
754
  let synthPath;
759
755
  if (synthPathCache.has(ownerDoc)) synthPath = synthPathCache.get(ownerDoc);
760
- else {
756
+ else {
761
757
  synthPath = this.computeSynthPath(ownerDoc);
762
758
  synthPathCache.set(ownerDoc, synthPath);
763
759
  }
@@ -774,7 +770,7 @@ else {
774
770
  resolveOwner(fromDoc, refId) {
775
771
  const key = `${fromDoc.id}::${refId}`;
776
772
  let v = this._ownerCache.get(key);
777
- if (v === undefined && !this._ownerCache.has(key)) {
773
+ if (v === void 0 && !this._ownerCache.has(key)) {
778
774
  v = fromDoc.getDeclarationOwnerNode(refId);
779
775
  this._ownerCache.set(key, v);
780
776
  }
@@ -783,8 +779,7 @@ else {
783
779
  allocateSynthInfo(refId, synthPath, ownerInfo, taken) {
784
780
  const ownerDoc = ownerInfo.doc;
785
781
  const ownerNode = ownerInfo.node;
786
- const existing = this.doc.importedDefs.get(refId);
787
- if (existing?.text === synthPath) return {
782
+ if (this.doc.importedDefs.get(refId)?.text === synthPath) return {
788
783
  alias: refId,
789
784
  ownerDoc,
790
785
  ownerNode
@@ -817,26 +812,26 @@ else {
817
812
  return alias;
818
813
  }
819
814
  computeSynthPath(ownerDoc) {
820
- if ((0, __atscript_core.isBareId)(ownerDoc.id)) return ownerDoc.id.slice("bare:".length, -".as".length);
821
- if (!ownerDoc.id.startsWith("file://")) return undefined;
822
- return (0, __atscript_core.getRelPath)(this.doc.id, ownerDoc.id);
815
+ if ((0, _atscript_core.isBareId)(ownerDoc.id)) return ownerDoc.id.slice(5, -3);
816
+ if (!ownerDoc.id.startsWith("file://")) return;
817
+ return (0, _atscript_core.getRelPath)(this.doc.id, ownerDoc.id);
823
818
  }
824
819
  pre() {
825
820
  this.writeln("// prettier-ignore-start");
826
821
  this.writeln("/* eslint-disable */");
827
822
  this.writeln("/* oxlint-disable */");
828
823
  let hasMutatingAnnotate = false;
829
- const nodesByName = new Map();
824
+ const nodesByName = /* @__PURE__ */ new Map();
830
825
  for (const node of this.doc.nodes) {
831
826
  if (node.entity === "annotate" && node.isMutating) hasMutatingAnnotate = true;
832
- if (node.__typeId !== null && node.__typeId !== undefined && node.id) {
827
+ if (node.__typeId !== null && node.__typeId !== void 0 && node.id) {
833
828
  const name = node.id;
834
829
  if (!nodesByName.has(name)) nodesByName.set(name, []);
835
830
  nodesByName.get(name).push(node);
836
831
  }
837
832
  }
838
833
  for (const [name, nodes] of nodesByName) if (nodes.length === 1) this.typeIds.set(nodes[0], name);
839
- else for (let i = 0; i < nodes.length; i++) this.typeIds.set(nodes[i], `${name}__${i + 1}`);
834
+ else for (let i = 0; i < nodes.length; i++) this.typeIds.set(nodes[i], `${name}__${i + 1}`);
840
835
  const imports = ["defineAnnotatedType as $", "annotate as $a"];
841
836
  if (hasMutatingAnnotate) imports.push("cloneRefProp as $c");
842
837
  const jsonSchemaMode = resolveJsonSchemaMode(this.opts);
@@ -851,14 +846,14 @@ else for (let i = 0; i < nodes.length; i++) this.typeIds.set(nodes[i], `${name}_
851
846
  }
852
847
  }
853
848
  buildAdHocMap(annotateNodes) {
854
- const map = new Map();
849
+ const map = /* @__PURE__ */ new Map();
855
850
  for (const annotateNode of annotateNodes) for (const entry of annotateNode.entries) {
856
- const path$2 = entry.hasChain ? [entry.id, ...entry.chain.map((c) => c.text)].join(".") : entry.id;
851
+ const path = entry.hasChain ? [entry.id, ...entry.chain.map((c) => c.text)].join(".") : entry.id;
857
852
  const anns = entry.annotations || [];
858
853
  if (anns.length > 0) {
859
- const existing = map.get(path$2);
854
+ const existing = map.get(path);
860
855
  if (existing) existing.push(...anns);
861
- else map.set(path$2, [...anns]);
856
+ else map.set(path, [...anns]);
862
857
  }
863
858
  }
864
859
  return map.size > 0 ? map : null;
@@ -876,15 +871,12 @@ else map.set(path$2, [...anns]);
876
871
  for (const node of this.postAnnotate) if (node.entity === "annotate") {
877
872
  const annotateNode = node;
878
873
  if (annotateNode.isMutating) this.renderMutatingAnnotateNode(annotateNode);
879
- else {
874
+ else {
880
875
  const unwound = this.doc.unwindType(annotateNode.targetName);
881
876
  if (unwound?.def) {
882
877
  let def = this.doc.mergeIntersection(unwound.def);
883
- if ((0, __atscript_core.isInterface)(def)) if (def.hasExtends) {
884
- const resolved = unwound.doc.resolveInterfaceExtends(def);
885
- if (resolved) def = resolved;
886
- else def = def.getDefinition() || def;
887
- } else def = def.getDefinition() || def;
878
+ if ((0, _atscript_core.isInterface)(def)) if (def.hasExtends) def = unwound.doc.resolveInterfaceExtends(def) || def.getDefinition() || def;
879
+ else def = def.getDefinition() || def;
888
880
  this._adHocAnnotations = this.buildAdHocMap([annotateNode]);
889
881
  this.annotateType(def, node.id);
890
882
  this._adHocAnnotations = null;
@@ -896,7 +888,7 @@ else def = def.getDefinition() || def;
896
888
  }
897
889
  } else {
898
890
  let def = node.getDefinition();
899
- if ((0, __atscript_core.isInterface)(node) && node.hasExtends) {
891
+ if ((0, _atscript_core.isInterface)(node) && node.hasExtends) {
900
892
  const resolved = this.doc.resolveInterfaceExtends(node);
901
893
  if (resolved) def = resolved;
902
894
  }
@@ -944,8 +936,7 @@ else def = def.getDefinition() || def;
944
936
  }
945
937
  renderJsonSchemaMethod(node) {
946
938
  const mode = resolveJsonSchemaMode(this.opts);
947
- const hasAnnotation = node.countAnnotations("emit.jsonSchema") > 0;
948
- if (hasAnnotation || mode === "bundle") {
939
+ if (node.countAnnotations("emit.jsonSchema") > 0 || mode === "bundle") {
949
940
  const schema = JSON.stringify(require_json_schema.buildJsonSchema(this.toAnnotatedType(node)));
950
941
  this.writeln("static toJsonSchema() {");
951
942
  this.indent().writeln(`return ${schema}`).unindent();
@@ -968,13 +959,13 @@ else def = def.getDefinition() || def;
968
959
  }
969
960
  }
970
961
  renderDimMeasure(node) {
971
- if (!(0, __atscript_core.isInterface)(node)) return;
962
+ if (!(0, _atscript_core.isInterface)(node)) return;
972
963
  const interfaceNode = node;
973
964
  if (!interfaceNode.annotations?.some((a) => a.name === "db.table" || a.name === "db.view" || a.name === "db.view.for")) return;
974
965
  let struct;
975
966
  if (interfaceNode.hasExtends) struct = this.doc.resolveInterfaceExtends(interfaceNode);
976
967
  if (!struct) struct = interfaceNode.getDefinition();
977
- if (!struct || !(0, __atscript_core.isStructure)(struct)) return;
968
+ if (!struct || !(0, _atscript_core.isStructure)(struct)) return;
978
969
  const structNode = struct;
979
970
  const dims = [];
980
971
  const measures = [];
@@ -995,12 +986,12 @@ else def = def.getDefinition() || def;
995
986
  case "interface":
996
987
  case "type": {
997
988
  let def = node.getDefinition();
998
- if ((0, __atscript_core.isInterface)(node) && node.hasExtends) {
989
+ if ((0, _atscript_core.isInterface)(node) && node.hasExtends) {
999
990
  const resolved = this.doc.resolveInterfaceExtends(node);
1000
991
  if (resolved) def = resolved;
1001
992
  }
1002
993
  const handle = this.toAnnotatedHandle(def, true);
1003
- const typeId = this.typeIds.get(node) ?? (node.__typeId !== null && node.__typeId !== undefined ? node.id : undefined);
994
+ const typeId = this.typeIds.get(node) ?? (node.__typeId !== null && node.__typeId !== void 0 ? node.id : void 0);
1004
995
  if (typeId) handle.id(typeId);
1005
996
  return skipAnnotations ? handle : this.applyExpectAnnotations(handle, this.doc.evalAnnotationsForNode(node));
1006
997
  }
@@ -1042,14 +1033,13 @@ else def = def.getDefinition() || def;
1042
1033
  const propHandle = this.toAnnotatedHandle(prop);
1043
1034
  const pattern = prop.token("identifier")?.pattern;
1044
1035
  if (pattern) handle.propPattern(pattern, propHandle.$type);
1045
- else handle.prop(prop.id, propHandle.$type);
1036
+ else handle.prop(prop.id, propHandle.$type);
1046
1037
  }
1047
1038
  return skipAnnotations ? handle : this.applyExpectAnnotations(handle, this.doc.evalAnnotationsForNode(node));
1048
1039
  }
1049
1040
  case "group": {
1050
1041
  const group = node;
1051
- const kind = group.op === "|" ? "union" : "intersection";
1052
- const handle = require_json_schema.defineAnnotatedType(kind);
1042
+ const handle = require_json_schema.defineAnnotatedType(group.op === "|" ? "union" : "intersection");
1053
1043
  for (const item of group.unwrap()) handle.item(this.toAnnotatedHandle(item).$type);
1054
1044
  return skipAnnotations ? handle : this.applyExpectAnnotations(handle, this.doc.evalAnnotationsForNode(node));
1055
1045
  }
@@ -1075,44 +1065,38 @@ else handle.prop(prop.id, propHandle.$type);
1075
1065
  annotations?.forEach((a) => {
1076
1066
  switch (a.name) {
1077
1067
  case "expect.minLength":
1078
- case "expect.maxLength": {
1068
+ case "expect.maxLength":
1079
1069
  if (a.args[0]) handle.annotate(a.name, {
1080
1070
  length: Number(a.args[0].text),
1081
1071
  message: a.args[1]?.text
1082
1072
  });
1083
1073
  break;
1084
- }
1085
- case "expect.min": {
1074
+ case "expect.min":
1086
1075
  if (a.args[0]) handle.annotate(a.name, {
1087
1076
  minValue: Number(a.args[0].text),
1088
1077
  message: a.args[1]?.text
1089
1078
  });
1090
1079
  break;
1091
- }
1092
- case "expect.max": {
1080
+ case "expect.max":
1093
1081
  if (a.args[0]) handle.annotate(a.name, {
1094
1082
  maxValue: Number(a.args[0].text),
1095
1083
  message: a.args[1]?.text
1096
1084
  });
1097
1085
  break;
1098
- }
1099
- case "expect.pattern": {
1086
+ case "expect.pattern":
1100
1087
  handle.annotate(a.name, {
1101
1088
  pattern: a.args[0]?.text || "",
1102
1089
  flags: a.args[1]?.text,
1103
1090
  message: a.args[2]?.text
1104
1091
  }, true);
1105
1092
  break;
1106
- }
1107
- case "expect.int": {
1093
+ case "expect.int":
1108
1094
  handle.annotate(a.name, true);
1109
1095
  break;
1110
- }
1111
1096
  case "expect.array.uniqueItems":
1112
- case "expect.array.key": {
1097
+ case "expect.array.key":
1113
1098
  handle.annotate(a.name, { message: a.args[0]?.text });
1114
1099
  break;
1115
- }
1116
1100
  default:
1117
1101
  }
1118
1102
  });
@@ -1126,16 +1110,16 @@ else handle.prop(prop.id, propHandle.$type);
1126
1110
  case "ref": {
1127
1111
  const ref = node;
1128
1112
  const decl = this.doc.unwindType(ref.id, ref.chain)?.def;
1129
- if ((0, __atscript_core.isPrimitive)(decl)) {
1130
- const ownerDecl$1 = this.resolveOwner(this.doc, ref.id);
1131
- if (!ownerDecl$1?.node || ownerDecl$1.node.entity !== "type" && ownerDecl$1.node.entity !== "interface") {
1113
+ if ((0, _atscript_core.isPrimitive)(decl)) {
1114
+ const ownerDecl = this.resolveOwner(this.doc, ref.id);
1115
+ if (!ownerDecl?.node || ownerDecl.node.entity !== "type" && ownerDecl.node.entity !== "interface") {
1132
1116
  this.annotateType(decl, name);
1133
1117
  return this;
1134
1118
  }
1135
1119
  }
1136
1120
  if (this._adHocAnnotations && this.hasAdHocAnnotationsThroughRef()) {
1137
- let resolved = decl ? this.doc.mergeIntersection(decl) : undefined;
1138
- if (resolved && (0, __atscript_core.isInterface)(resolved)) resolved = resolved.getDefinition() || resolved;
1121
+ let resolved = decl ? this.doc.mergeIntersection(decl) : void 0;
1122
+ if (resolved && (0, _atscript_core.isInterface)(resolved)) resolved = resolved.getDefinition() || resolved;
1139
1123
  if (resolved) {
1140
1124
  this.annotateType(resolved, name);
1141
1125
  return this;
@@ -1148,45 +1132,35 @@ else handle.prop(prop.id, propHandle.$type);
1148
1132
  node: synth.ownerNode
1149
1133
  } : this.resolveOwner(this.doc, ref.id);
1150
1134
  const refName = synth?.alias ?? ref.id;
1151
- const isImported = !!synth || (ownerDecl ? ownerDecl.doc !== this.doc : false);
1152
- const refExpr = isImported ? `() => ${refName}` : refName;
1135
+ const refExpr = !!synth || (ownerDecl ? ownerDecl.doc !== this.doc : false) ? `() => ${refName}` : refName;
1153
1136
  this.writeln(`$(${name ? `"", ${name}` : ""})`).indent().writeln(`.refTo(${refExpr}${chain})`);
1154
1137
  if (!ref.hasChain) {
1155
- if (ownerDecl?.node) {
1156
- const typeAnnotations = ownerDecl.doc.filterPassedWhenReferred(ownerDecl.doc.evalAnnotationsForNode(ownerDecl.node));
1157
- typeAnnotations?.forEach((an) => {
1158
- this.resolveAnnotationValue(ownerDecl.node, an);
1159
- });
1160
- }
1138
+ if (ownerDecl?.node) ownerDecl.doc.filterPassedWhenReferred(ownerDecl.doc.evalAnnotationsForNode(ownerDecl.node))?.forEach((an) => {
1139
+ this.resolveAnnotationValue(ownerDecl.node, an);
1140
+ });
1161
1141
  }
1162
1142
  this.unindent();
1163
1143
  return this;
1164
1144
  }
1165
- case "primitive": {
1145
+ case "primitive":
1166
1146
  this.definePrimitive(node, name);
1167
1147
  return this;
1168
- }
1169
- case "const": {
1148
+ case "const":
1170
1149
  this.writeln(`$(${name ? `"", ${name}` : ""})`).indent().defineConst(node).unindent();
1171
1150
  return this;
1172
- }
1173
- case "structure": {
1151
+ case "structure":
1174
1152
  this.writeln(`$("object"${name ? `, ${name}` : ""})`).indent().defineObject(node).unindent();
1175
1153
  return this;
1176
- }
1177
- case "group": {
1154
+ case "group":
1178
1155
  kind = node.op === "|" ? "union" : "intersection";
1179
1156
  this.writeln(`$("${kind}"${name ? `, ${name}` : ""})`).indent().defineGroup(node).unindent();
1180
1157
  return this;
1181
- }
1182
- case "tuple": {
1158
+ case "tuple":
1183
1159
  this.writeln(`$("tuple"${name ? `, ${name}` : ""})`).indent().defineGroup(node).unindent();
1184
1160
  return this;
1185
- }
1186
- case "array": {
1161
+ case "array":
1187
1162
  this.writeln(`$("array"${name ? `, ${name}` : ""})`).indent().defineArray(node).unindent();
1188
1163
  return this;
1189
- }
1190
1164
  default: return this;
1191
1165
  }
1192
1166
  }
@@ -1210,7 +1184,7 @@ else handle.prop(prop.id, propHandle.$type);
1210
1184
  case "final": return this.writeln(`$(${d()}).designType("${def.value === "void" ? "undefined" : def.value}")`);
1211
1185
  case "union":
1212
1186
  case "intersection":
1213
- case "tuple": {
1187
+ case "tuple":
1214
1188
  this.writeln(`$(${d(def.kind)})`);
1215
1189
  this.indent();
1216
1190
  for (const itemDef of def.items) {
@@ -1223,8 +1197,7 @@ else handle.prop(prop.id, propHandle.$type);
1223
1197
  }
1224
1198
  this.unindent();
1225
1199
  return;
1226
- }
1227
- case "array": {
1200
+ case "array":
1228
1201
  this.writeln(`$(${d("array")})`);
1229
1202
  this.indent();
1230
1203
  this.write(".of(");
@@ -1235,8 +1208,7 @@ else handle.prop(prop.id, propHandle.$type);
1235
1208
  this.writeln(`)`);
1236
1209
  this.unindent();
1237
1210
  return;
1238
- }
1239
- case "object": {
1211
+ case "object":
1240
1212
  this.writeln(`$(${d("object")})`);
1241
1213
  this.indent();
1242
1214
  for (const [key, propDef] of Object.entries(def.props)) {
@@ -1263,7 +1235,6 @@ else handle.prop(prop.id, propHandle.$type);
1263
1235
  }
1264
1236
  this.unindent();
1265
1237
  return;
1266
- }
1267
1238
  default: return this.writeln(`$(${d()}).designType("any")`);
1268
1239
  }
1269
1240
  }
@@ -1305,21 +1276,21 @@ else handle.prop(prop.id, propHandle.$type);
1305
1276
  defineMetadata(node) {
1306
1277
  let annotations;
1307
1278
  const nodeDef = node.getDefinition?.();
1308
- if (nodeDef && (0, __atscript_core.isRef)(nodeDef)) {
1279
+ if (nodeDef && (0, _atscript_core.isRef)(nodeDef)) {
1309
1280
  const refNode = nodeDef;
1310
1281
  if (!refNode.hasChain) {
1311
1282
  const resolved = this.doc.unwindType(refNode.id, refNode.chain)?.def;
1312
- if (resolved && !(0, __atscript_core.isPrimitive)(resolved)) annotations = node.annotations ?? [];
1313
- else if (resolved && (0, __atscript_core.isPrimitive)(resolved)) {
1283
+ if (resolved && !(0, _atscript_core.isPrimitive)(resolved)) annotations = node.annotations ?? [];
1284
+ else if (resolved && (0, _atscript_core.isPrimitive)(resolved)) {
1314
1285
  const ownerDecl = this.doc.getDeclarationOwnerNode(refNode.id);
1315
1286
  if (ownerDecl?.node && (ownerDecl.node.entity === "type" || ownerDecl.node.entity === "interface")) annotations = node.annotations ?? [];
1316
1287
  }
1317
1288
  }
1318
1289
  }
1319
- if (annotations === undefined) annotations = this.doc.evalAnnotationsForNode(node);
1290
+ if (annotations === void 0) annotations = this.doc.evalAnnotationsForNode(node);
1320
1291
  if (this._adHocAnnotations && this._propPath.length > 0) {
1321
- const path$2 = this._propPath.join(".");
1322
- const adHoc = this._adHocAnnotations.get(path$2);
1292
+ const path = this._propPath.join(".");
1293
+ const adHoc = this._adHocAnnotations.get(path);
1323
1294
  if (adHoc) annotations = this.doc.mergeNodesAnnotations(annotations, adHoc);
1324
1295
  }
1325
1296
  annotations?.forEach((an) => {
@@ -1333,9 +1304,8 @@ else if (resolved && (0, __atscript_core.isPrimitive)(resolved)) {
1333
1304
  */ defineMetadataForAnnotateAlias(annotateNode) {
1334
1305
  const annotateAnnotations = this.doc.evalAnnotationsForNode(annotateNode);
1335
1306
  const targetDecl = this.doc.getDeclarationOwnerNode(annotateNode.targetName);
1336
- const targetAnnotations = targetDecl?.node ? targetDecl.doc.evalAnnotationsForNode(targetDecl.node) : undefined;
1337
- const merged = this.doc.mergeNodesAnnotations(targetAnnotations, annotateAnnotations);
1338
- merged.forEach((an) => {
1307
+ const targetAnnotations = targetDecl?.node ? targetDecl.doc.evalAnnotationsForNode(targetDecl.node) : void 0;
1308
+ this.doc.mergeNodesAnnotations(targetAnnotations, annotateAnnotations).forEach((an) => {
1339
1309
  this.resolveAnnotationValue(annotateNode, an);
1340
1310
  });
1341
1311
  return this;
@@ -1343,14 +1313,12 @@ else if (resolved && (0, __atscript_core.isPrimitive)(resolved)) {
1343
1313
  resolveAnnotationValue(node, an) {
1344
1314
  const { value, multiple } = this.computeAnnotationValue(node, an);
1345
1315
  if (multiple) this.writeln(`.annotate("${escapeQuotes(an.name)}", ${value}, true)`);
1346
- else this.writeln(`.annotate("${escapeQuotes(an.name)}", ${value})`);
1316
+ else this.writeln(`.annotate("${escapeQuotes(an.name)}", ${value})`);
1347
1317
  }
1348
1318
  emitRefValue(text) {
1349
1319
  const dotIdx = text.indexOf(".");
1350
1320
  if (dotIdx === -1) return `() => ${text}`;
1351
- const typeName = text.slice(0, dotIdx);
1352
- const field = text.slice(dotIdx + 1);
1353
- return `{ type: () => ${typeName}, field: "${escapeQuotes(field)}" }`;
1321
+ return `{ type: () => ${text.slice(0, dotIdx)}, field: "${escapeQuotes(text.slice(dotIdx + 1))}" }`;
1354
1322
  }
1355
1323
  emitArgValue(aSpec, argToken) {
1356
1324
  if (aSpec.type === "ref") return this.emitRefValue(argToken.text);
@@ -1361,14 +1329,12 @@ else this.writeln(`.annotate("${escapeQuotes(an.name)}", ${value})`);
1361
1329
  return this.emitQueryExpr(queryNode.expression);
1362
1330
  }
1363
1331
  emitQueryExpr(node) {
1364
- if ((0, __atscript_core.isQueryLogical)(node)) return this.emitQueryLogical(node);
1332
+ if ((0, _atscript_core.isQueryLogical)(node)) return this.emitQueryLogical(node);
1365
1333
  return this.emitQueryComparison(node);
1366
1334
  }
1367
1335
  emitQueryLogical(node) {
1368
1336
  if (node.operator === "not") return `{ "$not": ${this.emitQueryExpr(node.operands[0])} }`;
1369
- const key = node.operator === "and" ? "$and" : "$or";
1370
- const items = node.operands.map((op) => this.emitQueryExpr(op)).join(", ");
1371
- return `{ "${key}": [${items}] }`;
1337
+ return `{ "${node.operator === "and" ? "$and" : "$or"}": [${node.operands.map((op) => this.emitQueryExpr(op)).join(", ")}] }`;
1372
1338
  }
1373
1339
  emitQueryComparison(node) {
1374
1340
  const left = this.emitQueryFieldRef(node.left);
@@ -1376,12 +1342,12 @@ else this.writeln(`.annotate("${escapeQuotes(an.name)}", ${value})`);
1376
1342
  const parts = [`left: ${left}`, `op: "${mappedOp}"`];
1377
1343
  if (node.right) {
1378
1344
  if ("fieldRef" in node.right && node.right.fieldRef) parts.push(`right: ${this.emitQueryFieldRef(node.right)}`);
1379
- else if ("values" in node.right && node.right.values) {
1345
+ else if ("values" in node.right && node.right.values) {
1380
1346
  const values = node.right.values.map((v) => this.emitQueryLiteral(v)).join(", ");
1381
1347
  parts.push(`right: [${values}]`);
1382
1348
  } else if ("valueToken" in node.right) parts.push(`right: ${this.emitQueryLiteral(node.right)}`);
1383
1349
  } else if (node.operator === "exists") parts.push("right: true");
1384
- else if (node.operator === "not exists") parts.push("right: false");
1350
+ else if (node.operator === "not exists") parts.push("right: false");
1385
1351
  return `{ ${parts.join(", ")} }`;
1386
1352
  }
1387
1353
  emitQueryFieldRef(node) {
@@ -1399,11 +1365,10 @@ else if (node.operator === "not exists") parts.push("right: false");
1399
1365
  const match = /^\/(.*)\/[a-z]*$/.exec(token.text);
1400
1366
  return `"${escapeQuotes(match ? match[1] : token.text)}"`;
1401
1367
  }
1402
- case "identifier": {
1368
+ case "identifier":
1403
1369
  if (token.text === "true" || token.text === "false") return token.text;
1404
1370
  if (token.text === "null" || token.text === "undefined") return "null";
1405
1371
  return token.text;
1406
- }
1407
1372
  default: return token.text;
1408
1373
  }
1409
1374
  }
@@ -1424,8 +1389,7 @@ else if (node.operator === "not exists") parts.push("right: false");
1424
1389
  targetValue += "}";
1425
1390
  } else {
1426
1391
  const aSpec = spec.arguments[0];
1427
- if (an.args[0]) targetValue = this.emitArgValue(aSpec, an.args[0]);
1428
- else targetValue = "true";
1392
+ targetValue = an.args[0] ? this.emitArgValue(aSpec, an.args[0]) : "true";
1429
1393
  }
1430
1394
  } else {
1431
1395
  multiple = node.countAnnotations(an.name) > 1 || an.args.length > 1;
@@ -1453,7 +1417,7 @@ else targetValue = "true";
1453
1417
  accessors
1454
1418
  });
1455
1419
  }
1456
- const cloneKeys = new Set();
1420
+ const cloneKeys = /* @__PURE__ */ new Set();
1457
1421
  for (const clone of allClones) {
1458
1422
  const key = `${clone.parentPath}|${clone.propName}`;
1459
1423
  if (!cloneKeys.has(key)) {
@@ -1467,7 +1431,7 @@ else targetValue = "true";
1467
1431
  this.writeln();
1468
1432
  }
1469
1433
  emitMutatingAnnotations(node, annotations, accessor) {
1470
- const cleared = new Set();
1434
+ const cleared = /* @__PURE__ */ new Set();
1471
1435
  for (const an of annotations) {
1472
1436
  const { value, multiple } = this.computeAnnotationValue(node, an);
1473
1437
  if (multiple) {
@@ -1482,9 +1446,9 @@ else targetValue = "true";
1482
1446
  }
1483
1447
  resolveTargetDef(targetName) {
1484
1448
  const unwound = this.doc.unwindType(targetName);
1485
- if (!unwound?.def) return undefined;
1449
+ if (!unwound?.def) return;
1486
1450
  let def = unwound.def;
1487
- if ((0, __atscript_core.isInterface)(def)) def = def.getDefinition() || def;
1451
+ if ((0, _atscript_core.isInterface)(def)) def = def.getDefinition() || def;
1488
1452
  return def;
1489
1453
  }
1490
1454
  /**
@@ -1503,7 +1467,7 @@ else targetValue = "true";
1503
1467
  for (const { prefix, def } of accessors) {
1504
1468
  const results = this.buildPropPaths(def, parts[i]);
1505
1469
  if (results.length > 0) for (const result of results) if (i < parts.length - 1) {
1506
- if (result.propDef && (0, __atscript_core.isRef)(result.propDef)) clones.push({
1470
+ if (result.propDef && (0, _atscript_core.isRef)(result.propDef)) clones.push({
1507
1471
  parentPath: prefix,
1508
1472
  propName: parts[i]
1509
1473
  });
@@ -1515,11 +1479,11 @@ else targetValue = "true";
1515
1479
  prefix: `${prefix}${result.path}?`,
1516
1480
  def: result.propDef
1517
1481
  });
1518
- else {
1482
+ else {
1519
1483
  const suffix = `.props.get("${escapeQuotes(parts[i])}")${i < parts.length - 1 ? "?.type" : "?"}`;
1520
1484
  nextAccessors.push({
1521
1485
  prefix: `${prefix}${suffix}`,
1522
- def: undefined
1486
+ def: void 0
1523
1487
  });
1524
1488
  }
1525
1489
  }
@@ -1537,13 +1501,13 @@ else {
1537
1501
  */ buildPropPaths(def, propName) {
1538
1502
  if (!def) return [];
1539
1503
  def = this.doc.mergeIntersection(def);
1540
- if ((0, __atscript_core.isRef)(def)) {
1504
+ if ((0, _atscript_core.isRef)(def)) {
1541
1505
  const ref = def;
1542
1506
  const unwound = this.doc.unwindType(ref.id, ref.chain)?.def;
1543
1507
  return this.buildPropPaths(unwound, propName);
1544
1508
  }
1545
- if ((0, __atscript_core.isInterface)(def)) return this.buildPropPaths(def.getDefinition(), propName);
1546
- if ((0, __atscript_core.isStructure)(def)) {
1509
+ if ((0, _atscript_core.isInterface)(def)) return this.buildPropPaths(def.getDefinition(), propName);
1510
+ if ((0, _atscript_core.isStructure)(def)) {
1547
1511
  const prop = def.props.get(propName);
1548
1512
  if (prop) return [{
1549
1513
  path: `.props.get("${escapeQuotes(propName)}")`,
@@ -1551,9 +1515,8 @@ else {
1551
1515
  }];
1552
1516
  return [];
1553
1517
  }
1554
- if ((0, __atscript_core.isGroup)(def)) {
1555
- const group = def;
1556
- const items = group.unwrap();
1518
+ if ((0, _atscript_core.isGroup)(def)) {
1519
+ const items = def.unwrap();
1557
1520
  const results = [];
1558
1521
  for (let i = 0; i < items.length; i++) for (const result of this.buildPropPaths(items[i], propName)) results.push({
1559
1522
  path: `.items[${i}].type${result.path}`,
@@ -1564,21 +1527,23 @@ else {
1564
1527
  return [];
1565
1528
  }
1566
1529
  constructor(doc, opts) {
1567
- super(doc), _define_property(this, "opts", void 0), _define_property(this, "postAnnotate", void 0), _define_property(this, "_adHocAnnotations", void 0), _define_property(this, "_propPath", void 0), _define_property(this, "typeIds", void 0), _define_property(this, "_unusedJs", void 0), _define_property(this, "_extendsRefs", void 0), _define_property(this, "_refSynthInfo", void 0), _define_property(this, "_synthImports", void 0), _define_property(this, "_synthComputed", void 0), _define_property(this, "_ownerCache", void 0), this.opts = opts, this.postAnnotate = [], this._adHocAnnotations = null, this._propPath = [], this.typeIds = new Map(), this._refSynthInfo = new Map(), this._synthImports = new Map(), this._synthComputed = false, this._ownerCache = new Map();
1530
+ super(doc), _define_property(this, "opts", void 0), _define_property(this, "postAnnotate", void 0), _define_property(this, "_adHocAnnotations", void 0), _define_property(this, "_propPath", void 0), _define_property(this, "typeIds", void 0), _define_property(this, "_unusedJs", void 0), _define_property(this, "_extendsRefs", void 0), _define_property(this, "_refSynthInfo", void 0), _define_property(this, "_synthImports", void 0), _define_property(this, "_synthComputed", void 0), _define_property(this, "_ownerCache", void 0), this.opts = opts, this.postAnnotate = [], this._adHocAnnotations = null, this._propPath = [], this.typeIds = /* @__PURE__ */ new Map(), this._refSynthInfo = /* @__PURE__ */ new Map(), this._synthImports = /* @__PURE__ */ new Map(), this._synthComputed = false, this._ownerCache = /* @__PURE__ */ new Map();
1568
1531
  }
1569
1532
  };
1570
1533
 
1571
1534
  //#endregion
1572
1535
  //#region packages/typescript/src/plugin.ts
1573
- function resolveJsonSchemaMode(opts) {
1574
- if (opts?.jsonSchema !== undefined) return opts.jsonSchema;
1536
+ /**
1537
+ * Resolves the effective JSON schema mode from plugin options.
1538
+ */ function resolveJsonSchemaMode(opts) {
1539
+ if (opts?.jsonSchema !== void 0) return opts.jsonSchema;
1575
1540
  return false;
1576
1541
  }
1577
1542
  const tsPlugin = (opts) => {
1578
1543
  return {
1579
1544
  name: "typescript",
1580
1545
  render(doc, format) {
1581
- if (format === "dts" || format === __atscript_core.DEFAULT_FORMAT) return [{
1546
+ if (format === "dts" || format === _atscript_core.DEFAULT_FORMAT) return [{
1582
1547
  fileName: `${doc.name}.d.ts`,
1583
1548
  content: new TypeRenderer(doc, opts).render()
1584
1549
  }];
@@ -1588,21 +1553,21 @@ const tsPlugin = (opts) => {
1588
1553
  }];
1589
1554
  },
1590
1555
  async buildEnd(output, format, repo) {
1591
- if (format === "dts" || format === __atscript_core.DEFAULT_FORMAT) {
1556
+ if (format === "dts" || format === _atscript_core.DEFAULT_FORMAT) {
1592
1557
  const annotations = await repo.getUsedAnnotations();
1593
- const tags = await repo.getPrimitivesTags() || new Set();
1558
+ const tags = await repo.getPrimitivesTags() || /* @__PURE__ */ new Set();
1594
1559
  const rendered = [];
1595
1560
  for (const [key, val] of Object.entries(annotations)) {
1596
1561
  const multiple = val.multiple;
1597
1562
  const typeLine = Array.from(val.types).map((t) => {
1598
1563
  if (t.type === "object" && "props" in t) return `{ ${Object.entries(t.props).map(([k, v]) => `${wrapProp(k)}${v.optional ? "?" : ""}: ${v.type}`).join(", ")} }`;
1599
- else return "optional" in t && t.optional ? `${t.type} | true` : t.type;
1564
+ else return "optional" in t && t.optional ? `${t.type} | true` : t.type;
1600
1565
  }).join(" | ");
1601
1566
  rendered.push(`${wrapProp(key)}: ${multiple ? "(" : ""}${typeLine}${multiple ? ")[]" : ""}`);
1602
1567
  }
1603
1568
  const renderedTags = Array.from(tags).map((f) => `"${escapeQuotes(f)}"`).join(" | ");
1604
1569
  output.push({
1605
- content: "// prettier-ignore-start\n/* eslint-disable */\n/* oxlint-disable */\n/**\n * 🪄 This file was generated by Atscript\n * It is generated based on annotations used in this project\n * Do not edit this file!\n *\n * Use `npx asc -f dts` command to re-generate this file\n */\nexport {}\n\ndeclare global {\n interface AtscriptMetadata {\n " + rendered.join("\n ") + "\n }\n" + " type AtscriptPrimitiveTags = " + renderedTags + "\n" + "}\n" + "// prettier-ignore-end",
1570
+ content: "// prettier-ignore-start\n/* eslint-disable */\n/* oxlint-disable */\n/**\n * 🪄 This file was generated by Atscript\n * It is generated based on annotations used in this project\n * Do not edit this file!\n *\n * Use `npx asc -f dts` command to re-generate this file\n */\nexport {}\n\ndeclare global {\n interface AtscriptMetadata {\n " + rendered.join("\n ") + "\n }\n type AtscriptPrimitiveTags = " + renderedTags + "\n}\n// prettier-ignore-end",
1606
1571
  fileName: "atscript.d.ts",
1607
1572
  source: "",
1608
1573
  target: path.default.join(repo.root, "atscript.d.ts")