@atscript/typescript 0.1.88 → 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,4 +1,4 @@
1
- import { buildJsonSchema, defineAnnotatedType } from "./json-schema-B64qclVa.mjs";
1
+ import { l as defineAnnotatedType, t as buildJsonSchema } from "./json-schema-DycaD0Rm.mjs";
2
2
  import path from "path";
3
3
  import { DEFAULT_FORMAT, flattenInterfaceNode, getRelPath, hasNavPropAnnotation, isArray, isBareId, isConst, isGroup, isInterface, isPrimitive, isProp, isQueryLogical, isRef, isStructure } from "@atscript/core";
4
4
 
@@ -10,7 +10,7 @@ function _define_property$3(obj, key, value) {
10
10
  configurable: true,
11
11
  writable: true
12
12
  });
13
- else obj[key] = value;
13
+ else obj[key] = value;
14
14
  return obj;
15
15
  }
16
16
  var CodePrinter = class {
@@ -71,7 +71,7 @@ var CodePrinter = class {
71
71
  * Return the entire code as a string. Removes any half-finished current line if empty.
72
72
  */ toString() {
73
73
  if (this.currentLine.trim() !== "") this.lines.push(this.currentLine);
74
- else if (this.currentLine.length > 0) this.lines.push(this.currentLine);
74
+ else if (this.currentLine.length > 0) this.lines.push(this.currentLine);
75
75
  return this.lines.join("\n");
76
76
  }
77
77
  doBlock(pair, withNewLine) {
@@ -89,7 +89,7 @@ else if (this.currentLine.length > 0) this.lines.push(this.currentLine);
89
89
  const closing = this.blockStack.pop();
90
90
  this.unindent();
91
91
  if (withNewLine) this.writeln(closing);
92
- else this.write(closing);
92
+ else this.write(closing);
93
93
  return this;
94
94
  }
95
95
  indentString() {
@@ -113,7 +113,7 @@ function _define_property$2(obj, key, value) {
113
113
  configurable: true,
114
114
  writable: true
115
115
  });
116
- else obj[key] = value;
116
+ else obj[key] = value;
117
117
  return obj;
118
118
  }
119
119
  var BaseRenderer = class extends CodePrinter {
@@ -131,8 +131,8 @@ var BaseRenderer = class extends CodePrinter {
131
131
  renderInterface(node) {}
132
132
  renderType(node) {}
133
133
  renderAnnotate(node) {}
134
- transformFromPath(path$1) {
135
- return `${path$1}.as`;
134
+ transformFromPath(path) {
135
+ return `${path}.as`;
136
136
  }
137
137
  renderImport(node) {
138
138
  const def = node.getDefinition();
@@ -141,8 +141,8 @@ var BaseRenderer = class extends CodePrinter {
141
141
  let isUnusedImport = true;
142
142
  if (isGroup(def)) {
143
143
  for (const child of def.unwrap()) if (isRef(child) && !this.unused.has(child.id)) {
144
- const node$1 = child;
145
- refs.push(node$1.id);
144
+ const node = child;
145
+ refs.push(node.id);
146
146
  isUnusedImport = false;
147
147
  }
148
148
  } else if (isRef(def) && !this.unused.has(def.id)) {
@@ -153,22 +153,18 @@ var BaseRenderer = class extends CodePrinter {
153
153
  }
154
154
  renderNode(node) {
155
155
  switch (node.entity) {
156
- case "interface": {
156
+ case "interface":
157
157
  this.renderInterface(node);
158
158
  break;
159
- }
160
- case "type": {
159
+ case "type":
161
160
  this.renderType(node);
162
161
  break;
163
- }
164
- case "import": {
162
+ case "import":
165
163
  this.renderImport(node);
166
164
  break;
167
- }
168
- case "annotate": {
165
+ case "annotate":
169
166
  this.renderAnnotate(node);
170
167
  break;
171
- }
172
168
  default: break;
173
169
  }
174
170
  }
@@ -180,7 +176,13 @@ var BaseRenderer = class extends CodePrinter {
180
176
  //#endregion
181
177
  //#region packages/typescript/src/codegen/utils.ts
182
178
  const validIdentifier = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
183
- function wrapProp(name) {
179
+ /**
180
+ * Wraps a property name in double quotes if it's not a valid identifier (contains special chars, etc.).
181
+ *
182
+ * Examples:
183
+ * - "validName" => "validName"
184
+ * - "some-prop" => "\"some-prop\""
185
+ */ function wrapProp(name) {
184
186
  if (!validIdentifier.test(name)) return `"${escapeQuotes(name)}"`;
185
187
  return name;
186
188
  }
@@ -197,7 +199,7 @@ function _define_property$1(obj, key, value) {
197
199
  configurable: true,
198
200
  writable: true
199
201
  });
200
- else obj[key] = value;
202
+ else obj[key] = value;
201
203
  return obj;
202
204
  }
203
205
  var TypeRenderer = class TypeRenderer extends BaseRenderer {
@@ -257,8 +259,7 @@ var TypeRenderer = class TypeRenderer extends BaseRenderer {
257
259
  return this.write(name);
258
260
  }
259
261
  if (isArray(def)) {
260
- const node = def;
261
- const def2 = node.getDefinition();
262
+ const def2 = def.getDefinition();
262
263
  const isGrp = def2?.entity === "group";
263
264
  if (isGrp) this.write("(");
264
265
  this.renderTypeDef(def2);
@@ -270,7 +271,7 @@ var TypeRenderer = class TypeRenderer extends BaseRenderer {
270
271
  renderStructure(struct, asClass, interfaceNode, filterProps) {
271
272
  this.blockln("{}");
272
273
  const patterns = [];
273
- const propsDefs = new Set();
274
+ const propsDefs = /* @__PURE__ */ new Set();
274
275
  for (const prop of struct.props.values()) {
275
276
  if (filterProps?.has(prop.id)) continue;
276
277
  if (prop.token("identifier")?.pattern) {
@@ -352,7 +353,7 @@ var TypeRenderer = class TypeRenderer extends BaseRenderer {
352
353
  this.write(`class ${node.id} `);
353
354
  const struct = node.getDefinition();
354
355
  if (struct?.entity === "structure") this.renderStructure(struct, node.id, node);
355
- else this.writeln("{}");
356
+ else this.writeln("{}");
356
357
  }
357
358
  this.writeln();
358
359
  }
@@ -395,9 +396,9 @@ else this.writeln("{}");
395
396
  if (isRef(inputDef)) realDef = this.doc.unwindType(inputDef.id, inputDef.chain)?.def || realDef;
396
397
  realDef = this.doc.mergeIntersection(realDef);
397
398
  if (isStructure(realDef) || isInterface(realDef)) typeDef = `TAtscriptTypeObject<keyof ${name}, ${name}>`;
398
- else if (isGroup(realDef)) typeDef = `TAtscriptTypeComplex<${name}>`;
399
- else if (isArray(realDef)) typeDef = `TAtscriptTypeArray<${name}>`;
400
- else if (isPrimitive(realDef)) typeDef = `TAtscriptTypeFinal<${name}>`;
399
+ else if (isGroup(realDef)) typeDef = `TAtscriptTypeComplex<${name}>`;
400
+ else if (isArray(realDef)) typeDef = `TAtscriptTypeArray<${name}>`;
401
+ else if (isPrimitive(realDef)) typeDef = `TAtscriptTypeFinal<${name}>`;
401
402
  }
402
403
  this.writeln(`const __is_atscript_annotated_type: true`);
403
404
  this.writeln(`const type: ${typeDef}`);
@@ -455,21 +456,20 @@ else if (isPrimitive(realDef)) typeDef = `TAtscriptTypeFinal<${name}>`;
455
456
  if (opts?.leadingNewline) this.writeln();
456
457
  this.write(`static ${propName}: `);
457
458
  this.blockln("{}");
458
- for (const [path$1, descriptor] of flatMap) {
459
- this.write(`"${escapeQuotes(path$1)}"`);
459
+ for (const [path, descriptor] of flatMap) {
460
+ this.write(`"${escapeQuotes(path)}"`);
460
461
  if (descriptor.optional) this.write("?");
461
462
  this.write(": ");
462
463
  if (descriptor.intermediate) this.writeln("never");
463
- else if (descriptor.dbJson) this.writeln("string");
464
- else {
464
+ else if (descriptor.dbJson) this.writeln("string");
465
+ else {
465
466
  const originalDef = descriptor.propNode?.getDefinition();
466
467
  const defToRender = originalDef && !(isGroup(descriptor.def) && descriptor.def !== originalDef) ? originalDef : descriptor.def;
467
- const renderedDef = this.renderTypeDefString(defToRender);
468
- renderedDef.split("\n").forEach((l) => this.writeln(l));
468
+ this.renderTypeDefString(defToRender).split("\n").forEach((l) => this.writeln(l));
469
469
  }
470
470
  }
471
471
  if (opts?.trailingNewline) this.popln();
472
- else this.pop();
472
+ else this.pop();
473
473
  }
474
474
  /**
475
475
  * Renders the `static __navProps` property — a map of navigation property names
@@ -500,10 +500,8 @@ else this.pop();
500
500
  if (prop.token("optional")) this.write("?");
501
501
  this.write(": ");
502
502
  const propDef = prop.getDefinition();
503
- if (propDef) {
504
- const renderedDef = this.renderTypeDefString(propDef);
505
- renderedDef.split("\n").forEach((l) => this.writeln(l));
506
- } else this.writeln("unknown");
503
+ if (propDef) this.renderTypeDefString(propDef).split("\n").forEach((l) => this.writeln(l));
504
+ else this.writeln("unknown");
507
505
  }
508
506
  this.popln();
509
507
  }
@@ -515,7 +513,7 @@ else this.pop();
515
513
  if (!struct || !isStructure(struct)) return;
516
514
  const structNode = struct;
517
515
  const pkProps = [];
518
- const uniqueByIndex = new Map();
516
+ const uniqueByIndex = /* @__PURE__ */ new Map();
519
517
  for (const [name, prop] of structNode.props) {
520
518
  if (prop.token("identifier")?.pattern) continue;
521
519
  if (isMongoCollection && name === "_id") continue;
@@ -549,7 +547,7 @@ else this.pop();
549
547
  mongoIdType ?? (mongoIdType = "string");
550
548
  }
551
549
  const uniqueTypes = [];
552
- const seenTypes = new Set();
550
+ const seenTypes = /* @__PURE__ */ new Set();
553
551
  for (const { prop } of uniqueProps) {
554
552
  const rendered = this.renderTypeDefString(prop.getDefinition()).trim();
555
553
  if (!seenTypes.has(rendered)) {
@@ -560,8 +558,8 @@ else this.pop();
560
558
  this.writeln();
561
559
  const uniqueSuffix = uniqueTypes.length > 0 ? ` | ${uniqueTypes.join(" | ")}` : "";
562
560
  if (pkProps.length === 0 && !isMongoCollection) this.writeln(`static __pk: ${uniqueTypes.join(" | ")}`);
563
- else if (pkProps.length === 0) this.writeln(`static __pk: ${mongoIdType}${uniqueSuffix}`);
564
- else if (pkProps.length === 1) {
561
+ else if (pkProps.length === 0) this.writeln(`static __pk: ${mongoIdType}${uniqueSuffix}`);
562
+ else if (pkProps.length === 1) {
565
563
  this.write("static __pk: ");
566
564
  if (isMongoCollection) this.write(`${mongoIdType} | `);
567
565
  const renderedDef = this.renderTypeDefString(pkProps[0].prop.getDefinition()).trim();
@@ -572,8 +570,7 @@ else if (pkProps.length === 1) {
572
570
  this.blockln("{}");
573
571
  for (const { name, prop } of pkProps) {
574
572
  this.write(wrapProp(name), ": ");
575
- const renderedDef = this.renderTypeDefString(prop.getDefinition());
576
- renderedDef.split("\n").forEach((l) => this.writeln(l));
573
+ this.renderTypeDefString(prop.getDefinition()).split("\n").forEach((l) => this.writeln(l));
577
574
  }
578
575
  this.pop();
579
576
  this.writeln(uniqueSuffix);
@@ -598,18 +595,16 @@ else if (pkProps.length === 1) {
598
595
  if (measures.length > 0) this.writeln(`static __measure: ${measures.map((m) => `"${escapeQuotes(m)}"`).join(" | ")}`);
599
596
  }
600
597
  phantomPropType(def) {
601
- if (!def) return undefined;
598
+ if (!def) return;
602
599
  if (isPrimitive(def) && def.config.type === "phantom") return def.id;
603
600
  if (isRef(def)) {
604
601
  const ref = def;
605
602
  const unwound = this.doc.unwindType(ref.id, ref.chain)?.def;
606
603
  if (isPrimitive(unwound) && unwound.config.type === "phantom") return ref.hasChain ? `${ref.id}.${ref.chain.map((c) => c.text).join(".")}` : ref.id;
607
604
  }
608
- return undefined;
609
605
  }
610
606
  isTypeTarget(name, doc) {
611
- const d = doc || this.doc;
612
- const decl = d.getDeclarationOwnerNode(name);
607
+ const decl = (doc || this.doc).getDeclarationOwnerNode(name);
613
608
  if (!decl?.node) return false;
614
609
  if (decl.node.entity === "type") return true;
615
610
  if (decl.node.entity === "interface") return false;
@@ -637,10 +632,7 @@ function renderPrimitiveTypeDef(def) {
637
632
  case "intersection": return def.items.map(renderPrimitiveTypeDef).join(" & ");
638
633
  case "tuple": return `[${def.items.map(renderPrimitiveTypeDef).join(", ")}]`;
639
634
  case "array": return `${renderPrimitiveTypeDef(def.of)}[]`;
640
- case "object": {
641
- const props = Object.entries(def.props).map(([key, val]) => `${wrapProp(key)}${typeof val === "object" && val.optional ? "?" : ""}: ${renderPrimitiveTypeDef(val)}`).join("; ");
642
- return `{ ${props} }`;
643
- }
635
+ case "object": return `{ ${Object.entries(def.props).map(([key, val]) => `${wrapProp(key)}${typeof val === "object" && val.optional ? "?" : ""}: ${renderPrimitiveTypeDef(val)}`).join("; ")} }`;
644
636
  default: return "unknown";
645
637
  }
646
638
  }
@@ -654,7 +646,7 @@ function _define_property(obj, key, value) {
654
646
  configurable: true,
655
647
  writable: true
656
648
  });
657
- else obj[key] = value;
649
+ else obj[key] = value;
658
650
  return obj;
659
651
  }
660
652
  const QUERY_OP_MAP = {
@@ -683,8 +675,8 @@ var JsRenderer = class extends BaseRenderer {
683
675
  }
684
676
  getExtendsRefs() {
685
677
  if (this._extendsRefs) return this._extendsRefs;
686
- const out = new Map();
687
- const visitedInterfaces = new Set();
678
+ const out = /* @__PURE__ */ new Map();
679
+ const visitedInterfaces = /* @__PURE__ */ new Set();
688
680
  for (const node of this.doc.nodes) if (isInterface(node) && node.hasExtends) this.walkExtendsParents(node, this.doc, out, visitedInterfaces);
689
681
  return this._extendsRefs = out;
690
682
  }
@@ -704,7 +696,7 @@ var JsRenderer = class extends BaseRenderer {
704
696
  walkExtendsParents(iface, doc, out, visited) {
705
697
  if (visited.has(iface)) return;
706
698
  visited.add(iface);
707
- const visitedNodes = new Set();
699
+ const visitedNodes = /* @__PURE__ */ new Set();
708
700
  for (const token of iface.extendsTokens) {
709
701
  const unwound = doc.unwindType(token.text);
710
702
  if (!unwound?.def || !isInterface(unwound.def)) continue;
@@ -722,8 +714,8 @@ var JsRenderer = class extends BaseRenderer {
722
714
  const refToOriginDoc = this.getExtendsRefs();
723
715
  if (refToOriginDoc.size === 0) return;
724
716
  const taken = new Set(this.doc.registry.definitions.keys());
725
- const allocated = new Map();
726
- const synthPathCache = new Map();
717
+ const allocated = /* @__PURE__ */ new Map();
718
+ const synthPathCache = /* @__PURE__ */ new Map();
727
719
  for (const [refNode, originDoc] of refToOriginDoc) {
728
720
  const refId = refNode.id;
729
721
  if (!refId) continue;
@@ -733,7 +725,7 @@ var JsRenderer = class extends BaseRenderer {
733
725
  const ownerDoc = ownerInfo.doc;
734
726
  let synthPath;
735
727
  if (synthPathCache.has(ownerDoc)) synthPath = synthPathCache.get(ownerDoc);
736
- else {
728
+ else {
737
729
  synthPath = this.computeSynthPath(ownerDoc);
738
730
  synthPathCache.set(ownerDoc, synthPath);
739
731
  }
@@ -750,7 +742,7 @@ else {
750
742
  resolveOwner(fromDoc, refId) {
751
743
  const key = `${fromDoc.id}::${refId}`;
752
744
  let v = this._ownerCache.get(key);
753
- if (v === undefined && !this._ownerCache.has(key)) {
745
+ if (v === void 0 && !this._ownerCache.has(key)) {
754
746
  v = fromDoc.getDeclarationOwnerNode(refId);
755
747
  this._ownerCache.set(key, v);
756
748
  }
@@ -759,8 +751,7 @@ else {
759
751
  allocateSynthInfo(refId, synthPath, ownerInfo, taken) {
760
752
  const ownerDoc = ownerInfo.doc;
761
753
  const ownerNode = ownerInfo.node;
762
- const existing = this.doc.importedDefs.get(refId);
763
- if (existing?.text === synthPath) return {
754
+ if (this.doc.importedDefs.get(refId)?.text === synthPath) return {
764
755
  alias: refId,
765
756
  ownerDoc,
766
757
  ownerNode
@@ -793,8 +784,8 @@ else {
793
784
  return alias;
794
785
  }
795
786
  computeSynthPath(ownerDoc) {
796
- if (isBareId(ownerDoc.id)) return ownerDoc.id.slice("bare:".length, -".as".length);
797
- if (!ownerDoc.id.startsWith("file://")) return undefined;
787
+ if (isBareId(ownerDoc.id)) return ownerDoc.id.slice(5, -3);
788
+ if (!ownerDoc.id.startsWith("file://")) return;
798
789
  return getRelPath(this.doc.id, ownerDoc.id);
799
790
  }
800
791
  pre() {
@@ -802,17 +793,17 @@ else {
802
793
  this.writeln("/* eslint-disable */");
803
794
  this.writeln("/* oxlint-disable */");
804
795
  let hasMutatingAnnotate = false;
805
- const nodesByName = new Map();
796
+ const nodesByName = /* @__PURE__ */ new Map();
806
797
  for (const node of this.doc.nodes) {
807
798
  if (node.entity === "annotate" && node.isMutating) hasMutatingAnnotate = true;
808
- if (node.__typeId !== null && node.__typeId !== undefined && node.id) {
799
+ if (node.__typeId !== null && node.__typeId !== void 0 && node.id) {
809
800
  const name = node.id;
810
801
  if (!nodesByName.has(name)) nodesByName.set(name, []);
811
802
  nodesByName.get(name).push(node);
812
803
  }
813
804
  }
814
805
  for (const [name, nodes] of nodesByName) if (nodes.length === 1) this.typeIds.set(nodes[0], name);
815
- else for (let i = 0; i < nodes.length; i++) this.typeIds.set(nodes[i], `${name}__${i + 1}`);
806
+ else for (let i = 0; i < nodes.length; i++) this.typeIds.set(nodes[i], `${name}__${i + 1}`);
816
807
  const imports = ["defineAnnotatedType as $", "annotate as $a"];
817
808
  if (hasMutatingAnnotate) imports.push("cloneRefProp as $c");
818
809
  const jsonSchemaMode = resolveJsonSchemaMode(this.opts);
@@ -827,14 +818,14 @@ else for (let i = 0; i < nodes.length; i++) this.typeIds.set(nodes[i], `${name}_
827
818
  }
828
819
  }
829
820
  buildAdHocMap(annotateNodes) {
830
- const map = new Map();
821
+ const map = /* @__PURE__ */ new Map();
831
822
  for (const annotateNode of annotateNodes) for (const entry of annotateNode.entries) {
832
- const path$1 = entry.hasChain ? [entry.id, ...entry.chain.map((c) => c.text)].join(".") : entry.id;
823
+ const path = entry.hasChain ? [entry.id, ...entry.chain.map((c) => c.text)].join(".") : entry.id;
833
824
  const anns = entry.annotations || [];
834
825
  if (anns.length > 0) {
835
- const existing = map.get(path$1);
826
+ const existing = map.get(path);
836
827
  if (existing) existing.push(...anns);
837
- else map.set(path$1, [...anns]);
828
+ else map.set(path, [...anns]);
838
829
  }
839
830
  }
840
831
  return map.size > 0 ? map : null;
@@ -852,14 +843,14 @@ else map.set(path$1, [...anns]);
852
843
  for (const node of this.postAnnotate) if (node.entity === "annotate") {
853
844
  const annotateNode = node;
854
845
  if (annotateNode.isMutating) this.renderMutatingAnnotateNode(annotateNode);
855
- else {
846
+ else {
856
847
  const unwound = this.doc.unwindType(annotateNode.targetName);
857
848
  if (unwound?.def) {
858
849
  let def = this.doc.mergeIntersection(unwound.def);
859
850
  if (isInterface(def)) if (def.hasExtends) {
860
851
  const resolved = unwound.doc.resolveInterfaceExtends(def);
861
852
  if (resolved) def = resolved;
862
- else def = def.getDefinition() || def;
853
+ else def = def.getDefinition() || def;
863
854
  } else def = def.getDefinition() || def;
864
855
  this._adHocAnnotations = this.buildAdHocMap([annotateNode]);
865
856
  this.annotateType(def, node.id);
@@ -920,8 +911,7 @@ else def = def.getDefinition() || def;
920
911
  }
921
912
  renderJsonSchemaMethod(node) {
922
913
  const mode = resolveJsonSchemaMode(this.opts);
923
- const hasAnnotation = node.countAnnotations("emit.jsonSchema") > 0;
924
- if (hasAnnotation || mode === "bundle") {
914
+ if (node.countAnnotations("emit.jsonSchema") > 0 || mode === "bundle") {
925
915
  const schema = JSON.stringify(buildJsonSchema(this.toAnnotatedType(node)));
926
916
  this.writeln("static toJsonSchema() {");
927
917
  this.indent().writeln(`return ${schema}`).unindent();
@@ -976,7 +966,7 @@ else def = def.getDefinition() || def;
976
966
  if (resolved) def = resolved;
977
967
  }
978
968
  const handle = this.toAnnotatedHandle(def, true);
979
- const typeId = this.typeIds.get(node) ?? (node.__typeId !== null && node.__typeId !== undefined ? node.id : undefined);
969
+ const typeId = this.typeIds.get(node) ?? (node.__typeId !== null && node.__typeId !== void 0 ? node.id : void 0);
980
970
  if (typeId) handle.id(typeId);
981
971
  return skipAnnotations ? handle : this.applyExpectAnnotations(handle, this.doc.evalAnnotationsForNode(node));
982
972
  }
@@ -1018,14 +1008,13 @@ else def = def.getDefinition() || def;
1018
1008
  const propHandle = this.toAnnotatedHandle(prop);
1019
1009
  const pattern = prop.token("identifier")?.pattern;
1020
1010
  if (pattern) handle.propPattern(pattern, propHandle.$type);
1021
- else handle.prop(prop.id, propHandle.$type);
1011
+ else handle.prop(prop.id, propHandle.$type);
1022
1012
  }
1023
1013
  return skipAnnotations ? handle : this.applyExpectAnnotations(handle, this.doc.evalAnnotationsForNode(node));
1024
1014
  }
1025
1015
  case "group": {
1026
1016
  const group = node;
1027
- const kind = group.op === "|" ? "union" : "intersection";
1028
- const handle = defineAnnotatedType(kind);
1017
+ const handle = defineAnnotatedType(group.op === "|" ? "union" : "intersection");
1029
1018
  for (const item of group.unwrap()) handle.item(this.toAnnotatedHandle(item).$type);
1030
1019
  return skipAnnotations ? handle : this.applyExpectAnnotations(handle, this.doc.evalAnnotationsForNode(node));
1031
1020
  }
@@ -1051,44 +1040,38 @@ else handle.prop(prop.id, propHandle.$type);
1051
1040
  annotations?.forEach((a) => {
1052
1041
  switch (a.name) {
1053
1042
  case "expect.minLength":
1054
- case "expect.maxLength": {
1043
+ case "expect.maxLength":
1055
1044
  if (a.args[0]) handle.annotate(a.name, {
1056
1045
  length: Number(a.args[0].text),
1057
1046
  message: a.args[1]?.text
1058
1047
  });
1059
1048
  break;
1060
- }
1061
- case "expect.min": {
1049
+ case "expect.min":
1062
1050
  if (a.args[0]) handle.annotate(a.name, {
1063
1051
  minValue: Number(a.args[0].text),
1064
1052
  message: a.args[1]?.text
1065
1053
  });
1066
1054
  break;
1067
- }
1068
- case "expect.max": {
1055
+ case "expect.max":
1069
1056
  if (a.args[0]) handle.annotate(a.name, {
1070
1057
  maxValue: Number(a.args[0].text),
1071
1058
  message: a.args[1]?.text
1072
1059
  });
1073
1060
  break;
1074
- }
1075
- case "expect.pattern": {
1061
+ case "expect.pattern":
1076
1062
  handle.annotate(a.name, {
1077
1063
  pattern: a.args[0]?.text || "",
1078
1064
  flags: a.args[1]?.text,
1079
1065
  message: a.args[2]?.text
1080
1066
  }, true);
1081
1067
  break;
1082
- }
1083
- case "expect.int": {
1068
+ case "expect.int":
1084
1069
  handle.annotate(a.name, true);
1085
1070
  break;
1086
- }
1087
1071
  case "expect.array.uniqueItems":
1088
- case "expect.array.key": {
1072
+ case "expect.array.key":
1089
1073
  handle.annotate(a.name, { message: a.args[0]?.text });
1090
1074
  break;
1091
- }
1092
1075
  default:
1093
1076
  }
1094
1077
  });
@@ -1103,14 +1086,14 @@ else handle.prop(prop.id, propHandle.$type);
1103
1086
  const ref = node;
1104
1087
  const decl = this.doc.unwindType(ref.id, ref.chain)?.def;
1105
1088
  if (isPrimitive(decl)) {
1106
- const ownerDecl$1 = this.resolveOwner(this.doc, ref.id);
1107
- if (!ownerDecl$1?.node || ownerDecl$1.node.entity !== "type" && ownerDecl$1.node.entity !== "interface") {
1089
+ const ownerDecl = this.resolveOwner(this.doc, ref.id);
1090
+ if (!ownerDecl?.node || ownerDecl.node.entity !== "type" && ownerDecl.node.entity !== "interface") {
1108
1091
  this.annotateType(decl, name);
1109
1092
  return this;
1110
1093
  }
1111
1094
  }
1112
1095
  if (this._adHocAnnotations && this.hasAdHocAnnotationsThroughRef()) {
1113
- let resolved = decl ? this.doc.mergeIntersection(decl) : undefined;
1096
+ let resolved = decl ? this.doc.mergeIntersection(decl) : void 0;
1114
1097
  if (resolved && isInterface(resolved)) resolved = resolved.getDefinition() || resolved;
1115
1098
  if (resolved) {
1116
1099
  this.annotateType(resolved, name);
@@ -1124,45 +1107,35 @@ else handle.prop(prop.id, propHandle.$type);
1124
1107
  node: synth.ownerNode
1125
1108
  } : this.resolveOwner(this.doc, ref.id);
1126
1109
  const refName = synth?.alias ?? ref.id;
1127
- const isImported = !!synth || (ownerDecl ? ownerDecl.doc !== this.doc : false);
1128
- const refExpr = isImported ? `() => ${refName}` : refName;
1110
+ const refExpr = !!synth || (ownerDecl ? ownerDecl.doc !== this.doc : false) ? `() => ${refName}` : refName;
1129
1111
  this.writeln(`$(${name ? `"", ${name}` : ""})`).indent().writeln(`.refTo(${refExpr}${chain})`);
1130
1112
  if (!ref.hasChain) {
1131
- if (ownerDecl?.node) {
1132
- const typeAnnotations = ownerDecl.doc.filterPassedWhenReferred(ownerDecl.doc.evalAnnotationsForNode(ownerDecl.node));
1133
- typeAnnotations?.forEach((an) => {
1134
- this.resolveAnnotationValue(ownerDecl.node, an);
1135
- });
1136
- }
1113
+ if (ownerDecl?.node) ownerDecl.doc.filterPassedWhenReferred(ownerDecl.doc.evalAnnotationsForNode(ownerDecl.node))?.forEach((an) => {
1114
+ this.resolveAnnotationValue(ownerDecl.node, an);
1115
+ });
1137
1116
  }
1138
1117
  this.unindent();
1139
1118
  return this;
1140
1119
  }
1141
- case "primitive": {
1120
+ case "primitive":
1142
1121
  this.definePrimitive(node, name);
1143
1122
  return this;
1144
- }
1145
- case "const": {
1123
+ case "const":
1146
1124
  this.writeln(`$(${name ? `"", ${name}` : ""})`).indent().defineConst(node).unindent();
1147
1125
  return this;
1148
- }
1149
- case "structure": {
1126
+ case "structure":
1150
1127
  this.writeln(`$("object"${name ? `, ${name}` : ""})`).indent().defineObject(node).unindent();
1151
1128
  return this;
1152
- }
1153
- case "group": {
1129
+ case "group":
1154
1130
  kind = node.op === "|" ? "union" : "intersection";
1155
1131
  this.writeln(`$("${kind}"${name ? `, ${name}` : ""})`).indent().defineGroup(node).unindent();
1156
1132
  return this;
1157
- }
1158
- case "tuple": {
1133
+ case "tuple":
1159
1134
  this.writeln(`$("tuple"${name ? `, ${name}` : ""})`).indent().defineGroup(node).unindent();
1160
1135
  return this;
1161
- }
1162
- case "array": {
1136
+ case "array":
1163
1137
  this.writeln(`$("array"${name ? `, ${name}` : ""})`).indent().defineArray(node).unindent();
1164
1138
  return this;
1165
- }
1166
1139
  default: return this;
1167
1140
  }
1168
1141
  }
@@ -1186,7 +1159,7 @@ else handle.prop(prop.id, propHandle.$type);
1186
1159
  case "final": return this.writeln(`$(${d()}).designType("${def.value === "void" ? "undefined" : def.value}")`);
1187
1160
  case "union":
1188
1161
  case "intersection":
1189
- case "tuple": {
1162
+ case "tuple":
1190
1163
  this.writeln(`$(${d(def.kind)})`);
1191
1164
  this.indent();
1192
1165
  for (const itemDef of def.items) {
@@ -1199,8 +1172,7 @@ else handle.prop(prop.id, propHandle.$type);
1199
1172
  }
1200
1173
  this.unindent();
1201
1174
  return;
1202
- }
1203
- case "array": {
1175
+ case "array":
1204
1176
  this.writeln(`$(${d("array")})`);
1205
1177
  this.indent();
1206
1178
  this.write(".of(");
@@ -1211,8 +1183,7 @@ else handle.prop(prop.id, propHandle.$type);
1211
1183
  this.writeln(`)`);
1212
1184
  this.unindent();
1213
1185
  return;
1214
- }
1215
- case "object": {
1186
+ case "object":
1216
1187
  this.writeln(`$(${d("object")})`);
1217
1188
  this.indent();
1218
1189
  for (const [key, propDef] of Object.entries(def.props)) {
@@ -1239,7 +1210,6 @@ else handle.prop(prop.id, propHandle.$type);
1239
1210
  }
1240
1211
  this.unindent();
1241
1212
  return;
1242
- }
1243
1213
  default: return this.writeln(`$(${d()}).designType("any")`);
1244
1214
  }
1245
1215
  }
@@ -1286,16 +1256,16 @@ else handle.prop(prop.id, propHandle.$type);
1286
1256
  if (!refNode.hasChain) {
1287
1257
  const resolved = this.doc.unwindType(refNode.id, refNode.chain)?.def;
1288
1258
  if (resolved && !isPrimitive(resolved)) annotations = node.annotations ?? [];
1289
- else if (resolved && isPrimitive(resolved)) {
1259
+ else if (resolved && isPrimitive(resolved)) {
1290
1260
  const ownerDecl = this.doc.getDeclarationOwnerNode(refNode.id);
1291
1261
  if (ownerDecl?.node && (ownerDecl.node.entity === "type" || ownerDecl.node.entity === "interface")) annotations = node.annotations ?? [];
1292
1262
  }
1293
1263
  }
1294
1264
  }
1295
- if (annotations === undefined) annotations = this.doc.evalAnnotationsForNode(node);
1265
+ if (annotations === void 0) annotations = this.doc.evalAnnotationsForNode(node);
1296
1266
  if (this._adHocAnnotations && this._propPath.length > 0) {
1297
- const path$1 = this._propPath.join(".");
1298
- const adHoc = this._adHocAnnotations.get(path$1);
1267
+ const path = this._propPath.join(".");
1268
+ const adHoc = this._adHocAnnotations.get(path);
1299
1269
  if (adHoc) annotations = this.doc.mergeNodesAnnotations(annotations, adHoc);
1300
1270
  }
1301
1271
  annotations?.forEach((an) => {
@@ -1309,9 +1279,8 @@ else if (resolved && isPrimitive(resolved)) {
1309
1279
  */ defineMetadataForAnnotateAlias(annotateNode) {
1310
1280
  const annotateAnnotations = this.doc.evalAnnotationsForNode(annotateNode);
1311
1281
  const targetDecl = this.doc.getDeclarationOwnerNode(annotateNode.targetName);
1312
- const targetAnnotations = targetDecl?.node ? targetDecl.doc.evalAnnotationsForNode(targetDecl.node) : undefined;
1313
- const merged = this.doc.mergeNodesAnnotations(targetAnnotations, annotateAnnotations);
1314
- merged.forEach((an) => {
1282
+ const targetAnnotations = targetDecl?.node ? targetDecl.doc.evalAnnotationsForNode(targetDecl.node) : void 0;
1283
+ this.doc.mergeNodesAnnotations(targetAnnotations, annotateAnnotations).forEach((an) => {
1315
1284
  this.resolveAnnotationValue(annotateNode, an);
1316
1285
  });
1317
1286
  return this;
@@ -1319,14 +1288,12 @@ else if (resolved && isPrimitive(resolved)) {
1319
1288
  resolveAnnotationValue(node, an) {
1320
1289
  const { value, multiple } = this.computeAnnotationValue(node, an);
1321
1290
  if (multiple) this.writeln(`.annotate("${escapeQuotes(an.name)}", ${value}, true)`);
1322
- else this.writeln(`.annotate("${escapeQuotes(an.name)}", ${value})`);
1291
+ else this.writeln(`.annotate("${escapeQuotes(an.name)}", ${value})`);
1323
1292
  }
1324
1293
  emitRefValue(text) {
1325
1294
  const dotIdx = text.indexOf(".");
1326
1295
  if (dotIdx === -1) return `() => ${text}`;
1327
- const typeName = text.slice(0, dotIdx);
1328
- const field = text.slice(dotIdx + 1);
1329
- return `{ type: () => ${typeName}, field: "${escapeQuotes(field)}" }`;
1296
+ return `{ type: () => ${text.slice(0, dotIdx)}, field: "${escapeQuotes(text.slice(dotIdx + 1))}" }`;
1330
1297
  }
1331
1298
  emitArgValue(aSpec, argToken) {
1332
1299
  if (aSpec.type === "ref") return this.emitRefValue(argToken.text);
@@ -1342,9 +1309,7 @@ else this.writeln(`.annotate("${escapeQuotes(an.name)}", ${value})`);
1342
1309
  }
1343
1310
  emitQueryLogical(node) {
1344
1311
  if (node.operator === "not") return `{ "$not": ${this.emitQueryExpr(node.operands[0])} }`;
1345
- const key = node.operator === "and" ? "$and" : "$or";
1346
- const items = node.operands.map((op) => this.emitQueryExpr(op)).join(", ");
1347
- return `{ "${key}": [${items}] }`;
1312
+ return `{ "${node.operator === "and" ? "$and" : "$or"}": [${node.operands.map((op) => this.emitQueryExpr(op)).join(", ")}] }`;
1348
1313
  }
1349
1314
  emitQueryComparison(node) {
1350
1315
  const left = this.emitQueryFieldRef(node.left);
@@ -1352,12 +1317,12 @@ else this.writeln(`.annotate("${escapeQuotes(an.name)}", ${value})`);
1352
1317
  const parts = [`left: ${left}`, `op: "${mappedOp}"`];
1353
1318
  if (node.right) {
1354
1319
  if ("fieldRef" in node.right && node.right.fieldRef) parts.push(`right: ${this.emitQueryFieldRef(node.right)}`);
1355
- else if ("values" in node.right && node.right.values) {
1320
+ else if ("values" in node.right && node.right.values) {
1356
1321
  const values = node.right.values.map((v) => this.emitQueryLiteral(v)).join(", ");
1357
1322
  parts.push(`right: [${values}]`);
1358
1323
  } else if ("valueToken" in node.right) parts.push(`right: ${this.emitQueryLiteral(node.right)}`);
1359
1324
  } else if (node.operator === "exists") parts.push("right: true");
1360
- else if (node.operator === "not exists") parts.push("right: false");
1325
+ else if (node.operator === "not exists") parts.push("right: false");
1361
1326
  return `{ ${parts.join(", ")} }`;
1362
1327
  }
1363
1328
  emitQueryFieldRef(node) {
@@ -1375,11 +1340,10 @@ else if (node.operator === "not exists") parts.push("right: false");
1375
1340
  const match = /^\/(.*)\/[a-z]*$/.exec(token.text);
1376
1341
  return `"${escapeQuotes(match ? match[1] : token.text)}"`;
1377
1342
  }
1378
- case "identifier": {
1343
+ case "identifier":
1379
1344
  if (token.text === "true" || token.text === "false") return token.text;
1380
1345
  if (token.text === "null" || token.text === "undefined") return "null";
1381
1346
  return token.text;
1382
- }
1383
1347
  default: return token.text;
1384
1348
  }
1385
1349
  }
@@ -1401,7 +1365,7 @@ else if (node.operator === "not exists") parts.push("right: false");
1401
1365
  } else {
1402
1366
  const aSpec = spec.arguments[0];
1403
1367
  if (an.args[0]) targetValue = this.emitArgValue(aSpec, an.args[0]);
1404
- else targetValue = "true";
1368
+ else targetValue = "true";
1405
1369
  }
1406
1370
  } else {
1407
1371
  multiple = node.countAnnotations(an.name) > 1 || an.args.length > 1;
@@ -1429,7 +1393,7 @@ else targetValue = "true";
1429
1393
  accessors
1430
1394
  });
1431
1395
  }
1432
- const cloneKeys = new Set();
1396
+ const cloneKeys = /* @__PURE__ */ new Set();
1433
1397
  for (const clone of allClones) {
1434
1398
  const key = `${clone.parentPath}|${clone.propName}`;
1435
1399
  if (!cloneKeys.has(key)) {
@@ -1443,7 +1407,7 @@ else targetValue = "true";
1443
1407
  this.writeln();
1444
1408
  }
1445
1409
  emitMutatingAnnotations(node, annotations, accessor) {
1446
- const cleared = new Set();
1410
+ const cleared = /* @__PURE__ */ new Set();
1447
1411
  for (const an of annotations) {
1448
1412
  const { value, multiple } = this.computeAnnotationValue(node, an);
1449
1413
  if (multiple) {
@@ -1458,7 +1422,7 @@ else targetValue = "true";
1458
1422
  }
1459
1423
  resolveTargetDef(targetName) {
1460
1424
  const unwound = this.doc.unwindType(targetName);
1461
- if (!unwound?.def) return undefined;
1425
+ if (!unwound?.def) return;
1462
1426
  let def = unwound.def;
1463
1427
  if (isInterface(def)) def = def.getDefinition() || def;
1464
1428
  return def;
@@ -1491,11 +1455,11 @@ else targetValue = "true";
1491
1455
  prefix: `${prefix}${result.path}?`,
1492
1456
  def: result.propDef
1493
1457
  });
1494
- else {
1458
+ else {
1495
1459
  const suffix = `.props.get("${escapeQuotes(parts[i])}")${i < parts.length - 1 ? "?.type" : "?"}`;
1496
1460
  nextAccessors.push({
1497
1461
  prefix: `${prefix}${suffix}`,
1498
- def: undefined
1462
+ def: void 0
1499
1463
  });
1500
1464
  }
1501
1465
  }
@@ -1528,8 +1492,7 @@ else {
1528
1492
  return [];
1529
1493
  }
1530
1494
  if (isGroup(def)) {
1531
- const group = def;
1532
- const items = group.unwrap();
1495
+ const items = def.unwrap();
1533
1496
  const results = [];
1534
1497
  for (let i = 0; i < items.length; i++) for (const result of this.buildPropPaths(items[i], propName)) results.push({
1535
1498
  path: `.items[${i}].type${result.path}`,
@@ -1540,14 +1503,16 @@ else {
1540
1503
  return [];
1541
1504
  }
1542
1505
  constructor(doc, opts) {
1543
- 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();
1506
+ 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();
1544
1507
  }
1545
1508
  };
1546
1509
 
1547
1510
  //#endregion
1548
1511
  //#region packages/typescript/src/plugin.ts
1549
- function resolveJsonSchemaMode(opts) {
1550
- if (opts?.jsonSchema !== undefined) return opts.jsonSchema;
1512
+ /**
1513
+ * Resolves the effective JSON schema mode from plugin options.
1514
+ */ function resolveJsonSchemaMode(opts) {
1515
+ if (opts?.jsonSchema !== void 0) return opts.jsonSchema;
1551
1516
  return false;
1552
1517
  }
1553
1518
  const tsPlugin = (opts) => {
@@ -1566,19 +1531,19 @@ const tsPlugin = (opts) => {
1566
1531
  async buildEnd(output, format, repo) {
1567
1532
  if (format === "dts" || format === DEFAULT_FORMAT) {
1568
1533
  const annotations = await repo.getUsedAnnotations();
1569
- const tags = await repo.getPrimitivesTags() || new Set();
1534
+ const tags = await repo.getPrimitivesTags() || /* @__PURE__ */ new Set();
1570
1535
  const rendered = [];
1571
1536
  for (const [key, val] of Object.entries(annotations)) {
1572
1537
  const multiple = val.multiple;
1573
1538
  const typeLine = Array.from(val.types).map((t) => {
1574
1539
  if (t.type === "object" && "props" in t) return `{ ${Object.entries(t.props).map(([k, v]) => `${wrapProp(k)}${v.optional ? "?" : ""}: ${v.type}`).join(", ")} }`;
1575
- else return "optional" in t && t.optional ? `${t.type} | true` : t.type;
1540
+ else return "optional" in t && t.optional ? `${t.type} | true` : t.type;
1576
1541
  }).join(" | ");
1577
1542
  rendered.push(`${wrapProp(key)}: ${multiple ? "(" : ""}${typeLine}${multiple ? ")[]" : ""}`);
1578
1543
  }
1579
1544
  const renderedTags = Array.from(tags).map((f) => `"${escapeQuotes(f)}"`).join(" | ");
1580
1545
  output.push({
1581
- 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",
1546
+ 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",
1582
1547
  fileName: "atscript.d.ts",
1583
1548
  source: "",
1584
1549
  target: path.join(repo.root, "atscript.d.ts")
@@ -1589,4 +1554,4 @@ else return "optional" in t && t.optional ? `${t.type} | true` : t.type;
1589
1554
  };
1590
1555
 
1591
1556
  //#endregion
1592
- export { tsPlugin };
1557
+ export { tsPlugin as t };