@atscript/typescript 0.1.87 → 0.1.89

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,14 +871,14 @@ 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) {
878
+ if ((0, _atscript_core.isInterface)(def)) if (def.hasExtends) {
884
879
  const resolved = unwound.doc.resolveInterfaceExtends(def);
885
880
  if (resolved) def = resolved;
886
- else def = def.getDefinition() || def;
881
+ else def = def.getDefinition() || def;
887
882
  } else def = def.getDefinition() || def;
888
883
  this._adHocAnnotations = this.buildAdHocMap([annotateNode]);
889
884
  this.annotateType(def, node.id);
@@ -896,7 +891,7 @@ else def = def.getDefinition() || def;
896
891
  }
897
892
  } else {
898
893
  let def = node.getDefinition();
899
- if ((0, __atscript_core.isInterface)(node) && node.hasExtends) {
894
+ if ((0, _atscript_core.isInterface)(node) && node.hasExtends) {
900
895
  const resolved = this.doc.resolveInterfaceExtends(node);
901
896
  if (resolved) def = resolved;
902
897
  }
@@ -944,8 +939,7 @@ else def = def.getDefinition() || def;
944
939
  }
945
940
  renderJsonSchemaMethod(node) {
946
941
  const mode = resolveJsonSchemaMode(this.opts);
947
- const hasAnnotation = node.countAnnotations("emit.jsonSchema") > 0;
948
- if (hasAnnotation || mode === "bundle") {
942
+ if (node.countAnnotations("emit.jsonSchema") > 0 || mode === "bundle") {
949
943
  const schema = JSON.stringify(require_json_schema.buildJsonSchema(this.toAnnotatedType(node)));
950
944
  this.writeln("static toJsonSchema() {");
951
945
  this.indent().writeln(`return ${schema}`).unindent();
@@ -968,13 +962,13 @@ else def = def.getDefinition() || def;
968
962
  }
969
963
  }
970
964
  renderDimMeasure(node) {
971
- if (!(0, __atscript_core.isInterface)(node)) return;
965
+ if (!(0, _atscript_core.isInterface)(node)) return;
972
966
  const interfaceNode = node;
973
967
  if (!interfaceNode.annotations?.some((a) => a.name === "db.table" || a.name === "db.view" || a.name === "db.view.for")) return;
974
968
  let struct;
975
969
  if (interfaceNode.hasExtends) struct = this.doc.resolveInterfaceExtends(interfaceNode);
976
970
  if (!struct) struct = interfaceNode.getDefinition();
977
- if (!struct || !(0, __atscript_core.isStructure)(struct)) return;
971
+ if (!struct || !(0, _atscript_core.isStructure)(struct)) return;
978
972
  const structNode = struct;
979
973
  const dims = [];
980
974
  const measures = [];
@@ -995,12 +989,12 @@ else def = def.getDefinition() || def;
995
989
  case "interface":
996
990
  case "type": {
997
991
  let def = node.getDefinition();
998
- if ((0, __atscript_core.isInterface)(node) && node.hasExtends) {
992
+ if ((0, _atscript_core.isInterface)(node) && node.hasExtends) {
999
993
  const resolved = this.doc.resolveInterfaceExtends(node);
1000
994
  if (resolved) def = resolved;
1001
995
  }
1002
996
  const handle = this.toAnnotatedHandle(def, true);
1003
- const typeId = this.typeIds.get(node) ?? (node.__typeId !== null && node.__typeId !== undefined ? node.id : undefined);
997
+ const typeId = this.typeIds.get(node) ?? (node.__typeId !== null && node.__typeId !== void 0 ? node.id : void 0);
1004
998
  if (typeId) handle.id(typeId);
1005
999
  return skipAnnotations ? handle : this.applyExpectAnnotations(handle, this.doc.evalAnnotationsForNode(node));
1006
1000
  }
@@ -1042,14 +1036,13 @@ else def = def.getDefinition() || def;
1042
1036
  const propHandle = this.toAnnotatedHandle(prop);
1043
1037
  const pattern = prop.token("identifier")?.pattern;
1044
1038
  if (pattern) handle.propPattern(pattern, propHandle.$type);
1045
- else handle.prop(prop.id, propHandle.$type);
1039
+ else handle.prop(prop.id, propHandle.$type);
1046
1040
  }
1047
1041
  return skipAnnotations ? handle : this.applyExpectAnnotations(handle, this.doc.evalAnnotationsForNode(node));
1048
1042
  }
1049
1043
  case "group": {
1050
1044
  const group = node;
1051
- const kind = group.op === "|" ? "union" : "intersection";
1052
- const handle = require_json_schema.defineAnnotatedType(kind);
1045
+ const handle = require_json_schema.defineAnnotatedType(group.op === "|" ? "union" : "intersection");
1053
1046
  for (const item of group.unwrap()) handle.item(this.toAnnotatedHandle(item).$type);
1054
1047
  return skipAnnotations ? handle : this.applyExpectAnnotations(handle, this.doc.evalAnnotationsForNode(node));
1055
1048
  }
@@ -1075,44 +1068,38 @@ else handle.prop(prop.id, propHandle.$type);
1075
1068
  annotations?.forEach((a) => {
1076
1069
  switch (a.name) {
1077
1070
  case "expect.minLength":
1078
- case "expect.maxLength": {
1071
+ case "expect.maxLength":
1079
1072
  if (a.args[0]) handle.annotate(a.name, {
1080
1073
  length: Number(a.args[0].text),
1081
1074
  message: a.args[1]?.text
1082
1075
  });
1083
1076
  break;
1084
- }
1085
- case "expect.min": {
1077
+ case "expect.min":
1086
1078
  if (a.args[0]) handle.annotate(a.name, {
1087
1079
  minValue: Number(a.args[0].text),
1088
1080
  message: a.args[1]?.text
1089
1081
  });
1090
1082
  break;
1091
- }
1092
- case "expect.max": {
1083
+ case "expect.max":
1093
1084
  if (a.args[0]) handle.annotate(a.name, {
1094
1085
  maxValue: Number(a.args[0].text),
1095
1086
  message: a.args[1]?.text
1096
1087
  });
1097
1088
  break;
1098
- }
1099
- case "expect.pattern": {
1089
+ case "expect.pattern":
1100
1090
  handle.annotate(a.name, {
1101
1091
  pattern: a.args[0]?.text || "",
1102
1092
  flags: a.args[1]?.text,
1103
1093
  message: a.args[2]?.text
1104
1094
  }, true);
1105
1095
  break;
1106
- }
1107
- case "expect.int": {
1096
+ case "expect.int":
1108
1097
  handle.annotate(a.name, true);
1109
1098
  break;
1110
- }
1111
1099
  case "expect.array.uniqueItems":
1112
- case "expect.array.key": {
1100
+ case "expect.array.key":
1113
1101
  handle.annotate(a.name, { message: a.args[0]?.text });
1114
1102
  break;
1115
- }
1116
1103
  default:
1117
1104
  }
1118
1105
  });
@@ -1126,16 +1113,16 @@ else handle.prop(prop.id, propHandle.$type);
1126
1113
  case "ref": {
1127
1114
  const ref = node;
1128
1115
  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") {
1116
+ if ((0, _atscript_core.isPrimitive)(decl)) {
1117
+ const ownerDecl = this.resolveOwner(this.doc, ref.id);
1118
+ if (!ownerDecl?.node || ownerDecl.node.entity !== "type" && ownerDecl.node.entity !== "interface") {
1132
1119
  this.annotateType(decl, name);
1133
1120
  return this;
1134
1121
  }
1135
1122
  }
1136
1123
  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;
1124
+ let resolved = decl ? this.doc.mergeIntersection(decl) : void 0;
1125
+ if (resolved && (0, _atscript_core.isInterface)(resolved)) resolved = resolved.getDefinition() || resolved;
1139
1126
  if (resolved) {
1140
1127
  this.annotateType(resolved, name);
1141
1128
  return this;
@@ -1148,45 +1135,35 @@ else handle.prop(prop.id, propHandle.$type);
1148
1135
  node: synth.ownerNode
1149
1136
  } : this.resolveOwner(this.doc, ref.id);
1150
1137
  const refName = synth?.alias ?? ref.id;
1151
- const isImported = !!synth || (ownerDecl ? ownerDecl.doc !== this.doc : false);
1152
- const refExpr = isImported ? `() => ${refName}` : refName;
1138
+ const refExpr = !!synth || (ownerDecl ? ownerDecl.doc !== this.doc : false) ? `() => ${refName}` : refName;
1153
1139
  this.writeln(`$(${name ? `"", ${name}` : ""})`).indent().writeln(`.refTo(${refExpr}${chain})`);
1154
1140
  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
- }
1141
+ if (ownerDecl?.node) ownerDecl.doc.filterPassedWhenReferred(ownerDecl.doc.evalAnnotationsForNode(ownerDecl.node))?.forEach((an) => {
1142
+ this.resolveAnnotationValue(ownerDecl.node, an);
1143
+ });
1161
1144
  }
1162
1145
  this.unindent();
1163
1146
  return this;
1164
1147
  }
1165
- case "primitive": {
1148
+ case "primitive":
1166
1149
  this.definePrimitive(node, name);
1167
1150
  return this;
1168
- }
1169
- case "const": {
1151
+ case "const":
1170
1152
  this.writeln(`$(${name ? `"", ${name}` : ""})`).indent().defineConst(node).unindent();
1171
1153
  return this;
1172
- }
1173
- case "structure": {
1154
+ case "structure":
1174
1155
  this.writeln(`$("object"${name ? `, ${name}` : ""})`).indent().defineObject(node).unindent();
1175
1156
  return this;
1176
- }
1177
- case "group": {
1157
+ case "group":
1178
1158
  kind = node.op === "|" ? "union" : "intersection";
1179
1159
  this.writeln(`$("${kind}"${name ? `, ${name}` : ""})`).indent().defineGroup(node).unindent();
1180
1160
  return this;
1181
- }
1182
- case "tuple": {
1161
+ case "tuple":
1183
1162
  this.writeln(`$("tuple"${name ? `, ${name}` : ""})`).indent().defineGroup(node).unindent();
1184
1163
  return this;
1185
- }
1186
- case "array": {
1164
+ case "array":
1187
1165
  this.writeln(`$("array"${name ? `, ${name}` : ""})`).indent().defineArray(node).unindent();
1188
1166
  return this;
1189
- }
1190
1167
  default: return this;
1191
1168
  }
1192
1169
  }
@@ -1210,7 +1187,7 @@ else handle.prop(prop.id, propHandle.$type);
1210
1187
  case "final": return this.writeln(`$(${d()}).designType("${def.value === "void" ? "undefined" : def.value}")`);
1211
1188
  case "union":
1212
1189
  case "intersection":
1213
- case "tuple": {
1190
+ case "tuple":
1214
1191
  this.writeln(`$(${d(def.kind)})`);
1215
1192
  this.indent();
1216
1193
  for (const itemDef of def.items) {
@@ -1223,8 +1200,7 @@ else handle.prop(prop.id, propHandle.$type);
1223
1200
  }
1224
1201
  this.unindent();
1225
1202
  return;
1226
- }
1227
- case "array": {
1203
+ case "array":
1228
1204
  this.writeln(`$(${d("array")})`);
1229
1205
  this.indent();
1230
1206
  this.write(".of(");
@@ -1235,8 +1211,7 @@ else handle.prop(prop.id, propHandle.$type);
1235
1211
  this.writeln(`)`);
1236
1212
  this.unindent();
1237
1213
  return;
1238
- }
1239
- case "object": {
1214
+ case "object":
1240
1215
  this.writeln(`$(${d("object")})`);
1241
1216
  this.indent();
1242
1217
  for (const [key, propDef] of Object.entries(def.props)) {
@@ -1263,7 +1238,6 @@ else handle.prop(prop.id, propHandle.$type);
1263
1238
  }
1264
1239
  this.unindent();
1265
1240
  return;
1266
- }
1267
1241
  default: return this.writeln(`$(${d()}).designType("any")`);
1268
1242
  }
1269
1243
  }
@@ -1305,21 +1279,21 @@ else handle.prop(prop.id, propHandle.$type);
1305
1279
  defineMetadata(node) {
1306
1280
  let annotations;
1307
1281
  const nodeDef = node.getDefinition?.();
1308
- if (nodeDef && (0, __atscript_core.isRef)(nodeDef)) {
1282
+ if (nodeDef && (0, _atscript_core.isRef)(nodeDef)) {
1309
1283
  const refNode = nodeDef;
1310
1284
  if (!refNode.hasChain) {
1311
1285
  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)) {
1286
+ if (resolved && !(0, _atscript_core.isPrimitive)(resolved)) annotations = node.annotations ?? [];
1287
+ else if (resolved && (0, _atscript_core.isPrimitive)(resolved)) {
1314
1288
  const ownerDecl = this.doc.getDeclarationOwnerNode(refNode.id);
1315
1289
  if (ownerDecl?.node && (ownerDecl.node.entity === "type" || ownerDecl.node.entity === "interface")) annotations = node.annotations ?? [];
1316
1290
  }
1317
1291
  }
1318
1292
  }
1319
- if (annotations === undefined) annotations = this.doc.evalAnnotationsForNode(node);
1293
+ if (annotations === void 0) annotations = this.doc.evalAnnotationsForNode(node);
1320
1294
  if (this._adHocAnnotations && this._propPath.length > 0) {
1321
- const path$2 = this._propPath.join(".");
1322
- const adHoc = this._adHocAnnotations.get(path$2);
1295
+ const path = this._propPath.join(".");
1296
+ const adHoc = this._adHocAnnotations.get(path);
1323
1297
  if (adHoc) annotations = this.doc.mergeNodesAnnotations(annotations, adHoc);
1324
1298
  }
1325
1299
  annotations?.forEach((an) => {
@@ -1333,9 +1307,8 @@ else if (resolved && (0, __atscript_core.isPrimitive)(resolved)) {
1333
1307
  */ defineMetadataForAnnotateAlias(annotateNode) {
1334
1308
  const annotateAnnotations = this.doc.evalAnnotationsForNode(annotateNode);
1335
1309
  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) => {
1310
+ const targetAnnotations = targetDecl?.node ? targetDecl.doc.evalAnnotationsForNode(targetDecl.node) : void 0;
1311
+ this.doc.mergeNodesAnnotations(targetAnnotations, annotateAnnotations).forEach((an) => {
1339
1312
  this.resolveAnnotationValue(annotateNode, an);
1340
1313
  });
1341
1314
  return this;
@@ -1343,14 +1316,12 @@ else if (resolved && (0, __atscript_core.isPrimitive)(resolved)) {
1343
1316
  resolveAnnotationValue(node, an) {
1344
1317
  const { value, multiple } = this.computeAnnotationValue(node, an);
1345
1318
  if (multiple) this.writeln(`.annotate("${escapeQuotes(an.name)}", ${value}, true)`);
1346
- else this.writeln(`.annotate("${escapeQuotes(an.name)}", ${value})`);
1319
+ else this.writeln(`.annotate("${escapeQuotes(an.name)}", ${value})`);
1347
1320
  }
1348
1321
  emitRefValue(text) {
1349
1322
  const dotIdx = text.indexOf(".");
1350
1323
  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)}" }`;
1324
+ return `{ type: () => ${text.slice(0, dotIdx)}, field: "${escapeQuotes(text.slice(dotIdx + 1))}" }`;
1354
1325
  }
1355
1326
  emitArgValue(aSpec, argToken) {
1356
1327
  if (aSpec.type === "ref") return this.emitRefValue(argToken.text);
@@ -1361,14 +1332,12 @@ else this.writeln(`.annotate("${escapeQuotes(an.name)}", ${value})`);
1361
1332
  return this.emitQueryExpr(queryNode.expression);
1362
1333
  }
1363
1334
  emitQueryExpr(node) {
1364
- if ((0, __atscript_core.isQueryLogical)(node)) return this.emitQueryLogical(node);
1335
+ if ((0, _atscript_core.isQueryLogical)(node)) return this.emitQueryLogical(node);
1365
1336
  return this.emitQueryComparison(node);
1366
1337
  }
1367
1338
  emitQueryLogical(node) {
1368
1339
  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}] }`;
1340
+ return `{ "${node.operator === "and" ? "$and" : "$or"}": [${node.operands.map((op) => this.emitQueryExpr(op)).join(", ")}] }`;
1372
1341
  }
1373
1342
  emitQueryComparison(node) {
1374
1343
  const left = this.emitQueryFieldRef(node.left);
@@ -1376,12 +1345,12 @@ else this.writeln(`.annotate("${escapeQuotes(an.name)}", ${value})`);
1376
1345
  const parts = [`left: ${left}`, `op: "${mappedOp}"`];
1377
1346
  if (node.right) {
1378
1347
  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) {
1348
+ else if ("values" in node.right && node.right.values) {
1380
1349
  const values = node.right.values.map((v) => this.emitQueryLiteral(v)).join(", ");
1381
1350
  parts.push(`right: [${values}]`);
1382
1351
  } else if ("valueToken" in node.right) parts.push(`right: ${this.emitQueryLiteral(node.right)}`);
1383
1352
  } else if (node.operator === "exists") parts.push("right: true");
1384
- else if (node.operator === "not exists") parts.push("right: false");
1353
+ else if (node.operator === "not exists") parts.push("right: false");
1385
1354
  return `{ ${parts.join(", ")} }`;
1386
1355
  }
1387
1356
  emitQueryFieldRef(node) {
@@ -1399,11 +1368,10 @@ else if (node.operator === "not exists") parts.push("right: false");
1399
1368
  const match = /^\/(.*)\/[a-z]*$/.exec(token.text);
1400
1369
  return `"${escapeQuotes(match ? match[1] : token.text)}"`;
1401
1370
  }
1402
- case "identifier": {
1371
+ case "identifier":
1403
1372
  if (token.text === "true" || token.text === "false") return token.text;
1404
1373
  if (token.text === "null" || token.text === "undefined") return "null";
1405
1374
  return token.text;
1406
- }
1407
1375
  default: return token.text;
1408
1376
  }
1409
1377
  }
@@ -1425,7 +1393,7 @@ else if (node.operator === "not exists") parts.push("right: false");
1425
1393
  } else {
1426
1394
  const aSpec = spec.arguments[0];
1427
1395
  if (an.args[0]) targetValue = this.emitArgValue(aSpec, an.args[0]);
1428
- else targetValue = "true";
1396
+ else targetValue = "true";
1429
1397
  }
1430
1398
  } else {
1431
1399
  multiple = node.countAnnotations(an.name) > 1 || an.args.length > 1;
@@ -1453,7 +1421,7 @@ else targetValue = "true";
1453
1421
  accessors
1454
1422
  });
1455
1423
  }
1456
- const cloneKeys = new Set();
1424
+ const cloneKeys = /* @__PURE__ */ new Set();
1457
1425
  for (const clone of allClones) {
1458
1426
  const key = `${clone.parentPath}|${clone.propName}`;
1459
1427
  if (!cloneKeys.has(key)) {
@@ -1467,7 +1435,7 @@ else targetValue = "true";
1467
1435
  this.writeln();
1468
1436
  }
1469
1437
  emitMutatingAnnotations(node, annotations, accessor) {
1470
- const cleared = new Set();
1438
+ const cleared = /* @__PURE__ */ new Set();
1471
1439
  for (const an of annotations) {
1472
1440
  const { value, multiple } = this.computeAnnotationValue(node, an);
1473
1441
  if (multiple) {
@@ -1482,9 +1450,9 @@ else targetValue = "true";
1482
1450
  }
1483
1451
  resolveTargetDef(targetName) {
1484
1452
  const unwound = this.doc.unwindType(targetName);
1485
- if (!unwound?.def) return undefined;
1453
+ if (!unwound?.def) return;
1486
1454
  let def = unwound.def;
1487
- if ((0, __atscript_core.isInterface)(def)) def = def.getDefinition() || def;
1455
+ if ((0, _atscript_core.isInterface)(def)) def = def.getDefinition() || def;
1488
1456
  return def;
1489
1457
  }
1490
1458
  /**
@@ -1503,7 +1471,7 @@ else targetValue = "true";
1503
1471
  for (const { prefix, def } of accessors) {
1504
1472
  const results = this.buildPropPaths(def, parts[i]);
1505
1473
  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({
1474
+ if (result.propDef && (0, _atscript_core.isRef)(result.propDef)) clones.push({
1507
1475
  parentPath: prefix,
1508
1476
  propName: parts[i]
1509
1477
  });
@@ -1515,11 +1483,11 @@ else targetValue = "true";
1515
1483
  prefix: `${prefix}${result.path}?`,
1516
1484
  def: result.propDef
1517
1485
  });
1518
- else {
1486
+ else {
1519
1487
  const suffix = `.props.get("${escapeQuotes(parts[i])}")${i < parts.length - 1 ? "?.type" : "?"}`;
1520
1488
  nextAccessors.push({
1521
1489
  prefix: `${prefix}${suffix}`,
1522
- def: undefined
1490
+ def: void 0
1523
1491
  });
1524
1492
  }
1525
1493
  }
@@ -1537,13 +1505,13 @@ else {
1537
1505
  */ buildPropPaths(def, propName) {
1538
1506
  if (!def) return [];
1539
1507
  def = this.doc.mergeIntersection(def);
1540
- if ((0, __atscript_core.isRef)(def)) {
1508
+ if ((0, _atscript_core.isRef)(def)) {
1541
1509
  const ref = def;
1542
1510
  const unwound = this.doc.unwindType(ref.id, ref.chain)?.def;
1543
1511
  return this.buildPropPaths(unwound, propName);
1544
1512
  }
1545
- if ((0, __atscript_core.isInterface)(def)) return this.buildPropPaths(def.getDefinition(), propName);
1546
- if ((0, __atscript_core.isStructure)(def)) {
1513
+ if ((0, _atscript_core.isInterface)(def)) return this.buildPropPaths(def.getDefinition(), propName);
1514
+ if ((0, _atscript_core.isStructure)(def)) {
1547
1515
  const prop = def.props.get(propName);
1548
1516
  if (prop) return [{
1549
1517
  path: `.props.get("${escapeQuotes(propName)}")`,
@@ -1551,9 +1519,8 @@ else {
1551
1519
  }];
1552
1520
  return [];
1553
1521
  }
1554
- if ((0, __atscript_core.isGroup)(def)) {
1555
- const group = def;
1556
- const items = group.unwrap();
1522
+ if ((0, _atscript_core.isGroup)(def)) {
1523
+ const items = def.unwrap();
1557
1524
  const results = [];
1558
1525
  for (let i = 0; i < items.length; i++) for (const result of this.buildPropPaths(items[i], propName)) results.push({
1559
1526
  path: `.items[${i}].type${result.path}`,
@@ -1564,21 +1531,23 @@ else {
1564
1531
  return [];
1565
1532
  }
1566
1533
  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();
1534
+ 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
1535
  }
1569
1536
  };
1570
1537
 
1571
1538
  //#endregion
1572
1539
  //#region packages/typescript/src/plugin.ts
1573
- function resolveJsonSchemaMode(opts) {
1574
- if (opts?.jsonSchema !== undefined) return opts.jsonSchema;
1540
+ /**
1541
+ * Resolves the effective JSON schema mode from plugin options.
1542
+ */ function resolveJsonSchemaMode(opts) {
1543
+ if (opts?.jsonSchema !== void 0) return opts.jsonSchema;
1575
1544
  return false;
1576
1545
  }
1577
1546
  const tsPlugin = (opts) => {
1578
1547
  return {
1579
1548
  name: "typescript",
1580
1549
  render(doc, format) {
1581
- if (format === "dts" || format === __atscript_core.DEFAULT_FORMAT) return [{
1550
+ if (format === "dts" || format === _atscript_core.DEFAULT_FORMAT) return [{
1582
1551
  fileName: `${doc.name}.d.ts`,
1583
1552
  content: new TypeRenderer(doc, opts).render()
1584
1553
  }];
@@ -1588,21 +1557,21 @@ const tsPlugin = (opts) => {
1588
1557
  }];
1589
1558
  },
1590
1559
  async buildEnd(output, format, repo) {
1591
- if (format === "dts" || format === __atscript_core.DEFAULT_FORMAT) {
1560
+ if (format === "dts" || format === _atscript_core.DEFAULT_FORMAT) {
1592
1561
  const annotations = await repo.getUsedAnnotations();
1593
- const tags = await repo.getPrimitivesTags() || new Set();
1562
+ const tags = await repo.getPrimitivesTags() || /* @__PURE__ */ new Set();
1594
1563
  const rendered = [];
1595
1564
  for (const [key, val] of Object.entries(annotations)) {
1596
1565
  const multiple = val.multiple;
1597
1566
  const typeLine = Array.from(val.types).map((t) => {
1598
1567
  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;
1568
+ else return "optional" in t && t.optional ? `${t.type} | true` : t.type;
1600
1569
  }).join(" | ");
1601
1570
  rendered.push(`${wrapProp(key)}: ${multiple ? "(" : ""}${typeLine}${multiple ? ")[]" : ""}`);
1602
1571
  }
1603
1572
  const renderedTags = Array.from(tags).map((f) => `"${escapeQuotes(f)}"`).join(" | ");
1604
1573
  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",
1574
+ 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
1575
  fileName: "atscript.d.ts",
1607
1576
  source: "",
1608
1577
  target: path.default.join(repo.root, "atscript.d.ts")