@atscript/typescript 0.1.88 → 0.1.90
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +664 -434
- package/dist/index.cjs +4 -5
- package/dist/index.mjs +1 -2
- package/dist/{json-schema-3mti4G4J.cjs → json-schema-DXEiCfe1.cjs} +206 -97
- package/dist/{json-schema-B64qclVa.mjs → json-schema-DycaD0Rm.mjs} +207 -98
- package/dist/{plugin-CZ5g5D9I.cjs → plugin-Cs9mKJ8h.cjs} +180 -215
- package/dist/{plugin-CYzZm3rk.mjs → plugin-DHhdrTs8.mjs} +118 -157
- package/dist/test-utils.cjs +16 -9
- package/dist/test-utils.mjs +9 -3
- package/dist/utils.cjs +176 -106
- package/dist/utils.mjs +153 -83
- package/package.json +4 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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
|
|
135
|
-
return `${path
|
|
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
|
|
145
|
-
refs.push(node
|
|
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
|
-
|
|
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
|
|
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
|
|
459
|
-
this.write(`"${escapeQuotes(path
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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 ===
|
|
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
|
-
|
|
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(
|
|
797
|
-
if (!ownerDoc.id.startsWith("file://")) return
|
|
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 !==
|
|
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
|
|
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
|
|
826
|
+
const existing = map.get(path);
|
|
836
827
|
if (existing) existing.push(...anns);
|
|
837
|
-
else map.set(path
|
|
828
|
+
else map.set(path, [...anns]);
|
|
838
829
|
}
|
|
839
830
|
}
|
|
840
831
|
return map.size > 0 ? map : null;
|
|
@@ -852,15 +843,12 @@ 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
|
-
if (isInterface(def)) if (def.hasExtends)
|
|
860
|
-
|
|
861
|
-
if (resolved) def = resolved;
|
|
862
|
-
else def = def.getDefinition() || def;
|
|
863
|
-
} else def = def.getDefinition() || def;
|
|
850
|
+
if (isInterface(def)) if (def.hasExtends) def = unwound.doc.resolveInterfaceExtends(def) || def.getDefinition() || def;
|
|
851
|
+
else def = def.getDefinition() || def;
|
|
864
852
|
this._adHocAnnotations = this.buildAdHocMap([annotateNode]);
|
|
865
853
|
this.annotateType(def, node.id);
|
|
866
854
|
this._adHocAnnotations = null;
|
|
@@ -920,8 +908,7 @@ else def = def.getDefinition() || def;
|
|
|
920
908
|
}
|
|
921
909
|
renderJsonSchemaMethod(node) {
|
|
922
910
|
const mode = resolveJsonSchemaMode(this.opts);
|
|
923
|
-
|
|
924
|
-
if (hasAnnotation || mode === "bundle") {
|
|
911
|
+
if (node.countAnnotations("emit.jsonSchema") > 0 || mode === "bundle") {
|
|
925
912
|
const schema = JSON.stringify(buildJsonSchema(this.toAnnotatedType(node)));
|
|
926
913
|
this.writeln("static toJsonSchema() {");
|
|
927
914
|
this.indent().writeln(`return ${schema}`).unindent();
|
|
@@ -976,7 +963,7 @@ else def = def.getDefinition() || def;
|
|
|
976
963
|
if (resolved) def = resolved;
|
|
977
964
|
}
|
|
978
965
|
const handle = this.toAnnotatedHandle(def, true);
|
|
979
|
-
const typeId = this.typeIds.get(node) ?? (node.__typeId !== null && node.__typeId !==
|
|
966
|
+
const typeId = this.typeIds.get(node) ?? (node.__typeId !== null && node.__typeId !== void 0 ? node.id : void 0);
|
|
980
967
|
if (typeId) handle.id(typeId);
|
|
981
968
|
return skipAnnotations ? handle : this.applyExpectAnnotations(handle, this.doc.evalAnnotationsForNode(node));
|
|
982
969
|
}
|
|
@@ -1018,14 +1005,13 @@ else def = def.getDefinition() || def;
|
|
|
1018
1005
|
const propHandle = this.toAnnotatedHandle(prop);
|
|
1019
1006
|
const pattern = prop.token("identifier")?.pattern;
|
|
1020
1007
|
if (pattern) handle.propPattern(pattern, propHandle.$type);
|
|
1021
|
-
else handle.prop(prop.id, propHandle.$type);
|
|
1008
|
+
else handle.prop(prop.id, propHandle.$type);
|
|
1022
1009
|
}
|
|
1023
1010
|
return skipAnnotations ? handle : this.applyExpectAnnotations(handle, this.doc.evalAnnotationsForNode(node));
|
|
1024
1011
|
}
|
|
1025
1012
|
case "group": {
|
|
1026
1013
|
const group = node;
|
|
1027
|
-
const
|
|
1028
|
-
const handle = defineAnnotatedType(kind);
|
|
1014
|
+
const handle = defineAnnotatedType(group.op === "|" ? "union" : "intersection");
|
|
1029
1015
|
for (const item of group.unwrap()) handle.item(this.toAnnotatedHandle(item).$type);
|
|
1030
1016
|
return skipAnnotations ? handle : this.applyExpectAnnotations(handle, this.doc.evalAnnotationsForNode(node));
|
|
1031
1017
|
}
|
|
@@ -1051,44 +1037,38 @@ else handle.prop(prop.id, propHandle.$type);
|
|
|
1051
1037
|
annotations?.forEach((a) => {
|
|
1052
1038
|
switch (a.name) {
|
|
1053
1039
|
case "expect.minLength":
|
|
1054
|
-
case "expect.maxLength":
|
|
1040
|
+
case "expect.maxLength":
|
|
1055
1041
|
if (a.args[0]) handle.annotate(a.name, {
|
|
1056
1042
|
length: Number(a.args[0].text),
|
|
1057
1043
|
message: a.args[1]?.text
|
|
1058
1044
|
});
|
|
1059
1045
|
break;
|
|
1060
|
-
|
|
1061
|
-
case "expect.min": {
|
|
1046
|
+
case "expect.min":
|
|
1062
1047
|
if (a.args[0]) handle.annotate(a.name, {
|
|
1063
1048
|
minValue: Number(a.args[0].text),
|
|
1064
1049
|
message: a.args[1]?.text
|
|
1065
1050
|
});
|
|
1066
1051
|
break;
|
|
1067
|
-
|
|
1068
|
-
case "expect.max": {
|
|
1052
|
+
case "expect.max":
|
|
1069
1053
|
if (a.args[0]) handle.annotate(a.name, {
|
|
1070
1054
|
maxValue: Number(a.args[0].text),
|
|
1071
1055
|
message: a.args[1]?.text
|
|
1072
1056
|
});
|
|
1073
1057
|
break;
|
|
1074
|
-
|
|
1075
|
-
case "expect.pattern": {
|
|
1058
|
+
case "expect.pattern":
|
|
1076
1059
|
handle.annotate(a.name, {
|
|
1077
1060
|
pattern: a.args[0]?.text || "",
|
|
1078
1061
|
flags: a.args[1]?.text,
|
|
1079
1062
|
message: a.args[2]?.text
|
|
1080
1063
|
}, true);
|
|
1081
1064
|
break;
|
|
1082
|
-
|
|
1083
|
-
case "expect.int": {
|
|
1065
|
+
case "expect.int":
|
|
1084
1066
|
handle.annotate(a.name, true);
|
|
1085
1067
|
break;
|
|
1086
|
-
}
|
|
1087
1068
|
case "expect.array.uniqueItems":
|
|
1088
|
-
case "expect.array.key":
|
|
1069
|
+
case "expect.array.key":
|
|
1089
1070
|
handle.annotate(a.name, { message: a.args[0]?.text });
|
|
1090
1071
|
break;
|
|
1091
|
-
}
|
|
1092
1072
|
default:
|
|
1093
1073
|
}
|
|
1094
1074
|
});
|
|
@@ -1103,14 +1083,14 @@ else handle.prop(prop.id, propHandle.$type);
|
|
|
1103
1083
|
const ref = node;
|
|
1104
1084
|
const decl = this.doc.unwindType(ref.id, ref.chain)?.def;
|
|
1105
1085
|
if (isPrimitive(decl)) {
|
|
1106
|
-
const ownerDecl
|
|
1107
|
-
if (!ownerDecl
|
|
1086
|
+
const ownerDecl = this.resolveOwner(this.doc, ref.id);
|
|
1087
|
+
if (!ownerDecl?.node || ownerDecl.node.entity !== "type" && ownerDecl.node.entity !== "interface") {
|
|
1108
1088
|
this.annotateType(decl, name);
|
|
1109
1089
|
return this;
|
|
1110
1090
|
}
|
|
1111
1091
|
}
|
|
1112
1092
|
if (this._adHocAnnotations && this.hasAdHocAnnotationsThroughRef()) {
|
|
1113
|
-
let resolved = decl ? this.doc.mergeIntersection(decl) :
|
|
1093
|
+
let resolved = decl ? this.doc.mergeIntersection(decl) : void 0;
|
|
1114
1094
|
if (resolved && isInterface(resolved)) resolved = resolved.getDefinition() || resolved;
|
|
1115
1095
|
if (resolved) {
|
|
1116
1096
|
this.annotateType(resolved, name);
|
|
@@ -1124,45 +1104,35 @@ else handle.prop(prop.id, propHandle.$type);
|
|
|
1124
1104
|
node: synth.ownerNode
|
|
1125
1105
|
} : this.resolveOwner(this.doc, ref.id);
|
|
1126
1106
|
const refName = synth?.alias ?? ref.id;
|
|
1127
|
-
const
|
|
1128
|
-
const refExpr = isImported ? `() => ${refName}` : refName;
|
|
1107
|
+
const refExpr = !!synth || (ownerDecl ? ownerDecl.doc !== this.doc : false) ? `() => ${refName}` : refName;
|
|
1129
1108
|
this.writeln(`$(${name ? `"", ${name}` : ""})`).indent().writeln(`.refTo(${refExpr}${chain})`);
|
|
1130
1109
|
if (!ref.hasChain) {
|
|
1131
|
-
if (ownerDecl?.node) {
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
this.resolveAnnotationValue(ownerDecl.node, an);
|
|
1135
|
-
});
|
|
1136
|
-
}
|
|
1110
|
+
if (ownerDecl?.node) ownerDecl.doc.filterPassedWhenReferred(ownerDecl.doc.evalAnnotationsForNode(ownerDecl.node))?.forEach((an) => {
|
|
1111
|
+
this.resolveAnnotationValue(ownerDecl.node, an);
|
|
1112
|
+
});
|
|
1137
1113
|
}
|
|
1138
1114
|
this.unindent();
|
|
1139
1115
|
return this;
|
|
1140
1116
|
}
|
|
1141
|
-
case "primitive":
|
|
1117
|
+
case "primitive":
|
|
1142
1118
|
this.definePrimitive(node, name);
|
|
1143
1119
|
return this;
|
|
1144
|
-
|
|
1145
|
-
case "const": {
|
|
1120
|
+
case "const":
|
|
1146
1121
|
this.writeln(`$(${name ? `"", ${name}` : ""})`).indent().defineConst(node).unindent();
|
|
1147
1122
|
return this;
|
|
1148
|
-
|
|
1149
|
-
case "structure": {
|
|
1123
|
+
case "structure":
|
|
1150
1124
|
this.writeln(`$("object"${name ? `, ${name}` : ""})`).indent().defineObject(node).unindent();
|
|
1151
1125
|
return this;
|
|
1152
|
-
|
|
1153
|
-
case "group": {
|
|
1126
|
+
case "group":
|
|
1154
1127
|
kind = node.op === "|" ? "union" : "intersection";
|
|
1155
1128
|
this.writeln(`$("${kind}"${name ? `, ${name}` : ""})`).indent().defineGroup(node).unindent();
|
|
1156
1129
|
return this;
|
|
1157
|
-
|
|
1158
|
-
case "tuple": {
|
|
1130
|
+
case "tuple":
|
|
1159
1131
|
this.writeln(`$("tuple"${name ? `, ${name}` : ""})`).indent().defineGroup(node).unindent();
|
|
1160
1132
|
return this;
|
|
1161
|
-
|
|
1162
|
-
case "array": {
|
|
1133
|
+
case "array":
|
|
1163
1134
|
this.writeln(`$("array"${name ? `, ${name}` : ""})`).indent().defineArray(node).unindent();
|
|
1164
1135
|
return this;
|
|
1165
|
-
}
|
|
1166
1136
|
default: return this;
|
|
1167
1137
|
}
|
|
1168
1138
|
}
|
|
@@ -1186,7 +1156,7 @@ else handle.prop(prop.id, propHandle.$type);
|
|
|
1186
1156
|
case "final": return this.writeln(`$(${d()}).designType("${def.value === "void" ? "undefined" : def.value}")`);
|
|
1187
1157
|
case "union":
|
|
1188
1158
|
case "intersection":
|
|
1189
|
-
case "tuple":
|
|
1159
|
+
case "tuple":
|
|
1190
1160
|
this.writeln(`$(${d(def.kind)})`);
|
|
1191
1161
|
this.indent();
|
|
1192
1162
|
for (const itemDef of def.items) {
|
|
@@ -1199,8 +1169,7 @@ else handle.prop(prop.id, propHandle.$type);
|
|
|
1199
1169
|
}
|
|
1200
1170
|
this.unindent();
|
|
1201
1171
|
return;
|
|
1202
|
-
|
|
1203
|
-
case "array": {
|
|
1172
|
+
case "array":
|
|
1204
1173
|
this.writeln(`$(${d("array")})`);
|
|
1205
1174
|
this.indent();
|
|
1206
1175
|
this.write(".of(");
|
|
@@ -1211,8 +1180,7 @@ else handle.prop(prop.id, propHandle.$type);
|
|
|
1211
1180
|
this.writeln(`)`);
|
|
1212
1181
|
this.unindent();
|
|
1213
1182
|
return;
|
|
1214
|
-
|
|
1215
|
-
case "object": {
|
|
1183
|
+
case "object":
|
|
1216
1184
|
this.writeln(`$(${d("object")})`);
|
|
1217
1185
|
this.indent();
|
|
1218
1186
|
for (const [key, propDef] of Object.entries(def.props)) {
|
|
@@ -1239,7 +1207,6 @@ else handle.prop(prop.id, propHandle.$type);
|
|
|
1239
1207
|
}
|
|
1240
1208
|
this.unindent();
|
|
1241
1209
|
return;
|
|
1242
|
-
}
|
|
1243
1210
|
default: return this.writeln(`$(${d()}).designType("any")`);
|
|
1244
1211
|
}
|
|
1245
1212
|
}
|
|
@@ -1286,16 +1253,16 @@ else handle.prop(prop.id, propHandle.$type);
|
|
|
1286
1253
|
if (!refNode.hasChain) {
|
|
1287
1254
|
const resolved = this.doc.unwindType(refNode.id, refNode.chain)?.def;
|
|
1288
1255
|
if (resolved && !isPrimitive(resolved)) annotations = node.annotations ?? [];
|
|
1289
|
-
else if (resolved && isPrimitive(resolved)) {
|
|
1256
|
+
else if (resolved && isPrimitive(resolved)) {
|
|
1290
1257
|
const ownerDecl = this.doc.getDeclarationOwnerNode(refNode.id);
|
|
1291
1258
|
if (ownerDecl?.node && (ownerDecl.node.entity === "type" || ownerDecl.node.entity === "interface")) annotations = node.annotations ?? [];
|
|
1292
1259
|
}
|
|
1293
1260
|
}
|
|
1294
1261
|
}
|
|
1295
|
-
if (annotations ===
|
|
1262
|
+
if (annotations === void 0) annotations = this.doc.evalAnnotationsForNode(node);
|
|
1296
1263
|
if (this._adHocAnnotations && this._propPath.length > 0) {
|
|
1297
|
-
const path
|
|
1298
|
-
const adHoc = this._adHocAnnotations.get(path
|
|
1264
|
+
const path = this._propPath.join(".");
|
|
1265
|
+
const adHoc = this._adHocAnnotations.get(path);
|
|
1299
1266
|
if (adHoc) annotations = this.doc.mergeNodesAnnotations(annotations, adHoc);
|
|
1300
1267
|
}
|
|
1301
1268
|
annotations?.forEach((an) => {
|
|
@@ -1309,9 +1276,8 @@ else if (resolved && isPrimitive(resolved)) {
|
|
|
1309
1276
|
*/ defineMetadataForAnnotateAlias(annotateNode) {
|
|
1310
1277
|
const annotateAnnotations = this.doc.evalAnnotationsForNode(annotateNode);
|
|
1311
1278
|
const targetDecl = this.doc.getDeclarationOwnerNode(annotateNode.targetName);
|
|
1312
|
-
const targetAnnotations = targetDecl?.node ? targetDecl.doc.evalAnnotationsForNode(targetDecl.node) :
|
|
1313
|
-
|
|
1314
|
-
merged.forEach((an) => {
|
|
1279
|
+
const targetAnnotations = targetDecl?.node ? targetDecl.doc.evalAnnotationsForNode(targetDecl.node) : void 0;
|
|
1280
|
+
this.doc.mergeNodesAnnotations(targetAnnotations, annotateAnnotations).forEach((an) => {
|
|
1315
1281
|
this.resolveAnnotationValue(annotateNode, an);
|
|
1316
1282
|
});
|
|
1317
1283
|
return this;
|
|
@@ -1319,14 +1285,12 @@ else if (resolved && isPrimitive(resolved)) {
|
|
|
1319
1285
|
resolveAnnotationValue(node, an) {
|
|
1320
1286
|
const { value, multiple } = this.computeAnnotationValue(node, an);
|
|
1321
1287
|
if (multiple) this.writeln(`.annotate("${escapeQuotes(an.name)}", ${value}, true)`);
|
|
1322
|
-
else this.writeln(`.annotate("${escapeQuotes(an.name)}", ${value})`);
|
|
1288
|
+
else this.writeln(`.annotate("${escapeQuotes(an.name)}", ${value})`);
|
|
1323
1289
|
}
|
|
1324
1290
|
emitRefValue(text) {
|
|
1325
1291
|
const dotIdx = text.indexOf(".");
|
|
1326
1292
|
if (dotIdx === -1) return `() => ${text}`;
|
|
1327
|
-
|
|
1328
|
-
const field = text.slice(dotIdx + 1);
|
|
1329
|
-
return `{ type: () => ${typeName}, field: "${escapeQuotes(field)}" }`;
|
|
1293
|
+
return `{ type: () => ${text.slice(0, dotIdx)}, field: "${escapeQuotes(text.slice(dotIdx + 1))}" }`;
|
|
1330
1294
|
}
|
|
1331
1295
|
emitArgValue(aSpec, argToken) {
|
|
1332
1296
|
if (aSpec.type === "ref") return this.emitRefValue(argToken.text);
|
|
@@ -1342,9 +1306,7 @@ else this.writeln(`.annotate("${escapeQuotes(an.name)}", ${value})`);
|
|
|
1342
1306
|
}
|
|
1343
1307
|
emitQueryLogical(node) {
|
|
1344
1308
|
if (node.operator === "not") return `{ "$not": ${this.emitQueryExpr(node.operands[0])} }`;
|
|
1345
|
-
|
|
1346
|
-
const items = node.operands.map((op) => this.emitQueryExpr(op)).join(", ");
|
|
1347
|
-
return `{ "${key}": [${items}] }`;
|
|
1309
|
+
return `{ "${node.operator === "and" ? "$and" : "$or"}": [${node.operands.map((op) => this.emitQueryExpr(op)).join(", ")}] }`;
|
|
1348
1310
|
}
|
|
1349
1311
|
emitQueryComparison(node) {
|
|
1350
1312
|
const left = this.emitQueryFieldRef(node.left);
|
|
@@ -1352,12 +1314,12 @@ else this.writeln(`.annotate("${escapeQuotes(an.name)}", ${value})`);
|
|
|
1352
1314
|
const parts = [`left: ${left}`, `op: "${mappedOp}"`];
|
|
1353
1315
|
if (node.right) {
|
|
1354
1316
|
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) {
|
|
1317
|
+
else if ("values" in node.right && node.right.values) {
|
|
1356
1318
|
const values = node.right.values.map((v) => this.emitQueryLiteral(v)).join(", ");
|
|
1357
1319
|
parts.push(`right: [${values}]`);
|
|
1358
1320
|
} else if ("valueToken" in node.right) parts.push(`right: ${this.emitQueryLiteral(node.right)}`);
|
|
1359
1321
|
} else if (node.operator === "exists") parts.push("right: true");
|
|
1360
|
-
else if (node.operator === "not exists") parts.push("right: false");
|
|
1322
|
+
else if (node.operator === "not exists") parts.push("right: false");
|
|
1361
1323
|
return `{ ${parts.join(", ")} }`;
|
|
1362
1324
|
}
|
|
1363
1325
|
emitQueryFieldRef(node) {
|
|
@@ -1375,11 +1337,10 @@ else if (node.operator === "not exists") parts.push("right: false");
|
|
|
1375
1337
|
const match = /^\/(.*)\/[a-z]*$/.exec(token.text);
|
|
1376
1338
|
return `"${escapeQuotes(match ? match[1] : token.text)}"`;
|
|
1377
1339
|
}
|
|
1378
|
-
case "identifier":
|
|
1340
|
+
case "identifier":
|
|
1379
1341
|
if (token.text === "true" || token.text === "false") return token.text;
|
|
1380
1342
|
if (token.text === "null" || token.text === "undefined") return "null";
|
|
1381
1343
|
return token.text;
|
|
1382
|
-
}
|
|
1383
1344
|
default: return token.text;
|
|
1384
1345
|
}
|
|
1385
1346
|
}
|
|
@@ -1400,8 +1361,7 @@ else if (node.operator === "not exists") parts.push("right: false");
|
|
|
1400
1361
|
targetValue += "}";
|
|
1401
1362
|
} else {
|
|
1402
1363
|
const aSpec = spec.arguments[0];
|
|
1403
|
-
|
|
1404
|
-
else targetValue = "true";
|
|
1364
|
+
targetValue = an.args[0] ? this.emitArgValue(aSpec, an.args[0]) : "true";
|
|
1405
1365
|
}
|
|
1406
1366
|
} else {
|
|
1407
1367
|
multiple = node.countAnnotations(an.name) > 1 || an.args.length > 1;
|
|
@@ -1429,7 +1389,7 @@ else targetValue = "true";
|
|
|
1429
1389
|
accessors
|
|
1430
1390
|
});
|
|
1431
1391
|
}
|
|
1432
|
-
const cloneKeys = new Set();
|
|
1392
|
+
const cloneKeys = /* @__PURE__ */ new Set();
|
|
1433
1393
|
for (const clone of allClones) {
|
|
1434
1394
|
const key = `${clone.parentPath}|${clone.propName}`;
|
|
1435
1395
|
if (!cloneKeys.has(key)) {
|
|
@@ -1443,7 +1403,7 @@ else targetValue = "true";
|
|
|
1443
1403
|
this.writeln();
|
|
1444
1404
|
}
|
|
1445
1405
|
emitMutatingAnnotations(node, annotations, accessor) {
|
|
1446
|
-
const cleared = new Set();
|
|
1406
|
+
const cleared = /* @__PURE__ */ new Set();
|
|
1447
1407
|
for (const an of annotations) {
|
|
1448
1408
|
const { value, multiple } = this.computeAnnotationValue(node, an);
|
|
1449
1409
|
if (multiple) {
|
|
@@ -1458,7 +1418,7 @@ else targetValue = "true";
|
|
|
1458
1418
|
}
|
|
1459
1419
|
resolveTargetDef(targetName) {
|
|
1460
1420
|
const unwound = this.doc.unwindType(targetName);
|
|
1461
|
-
if (!unwound?.def) return
|
|
1421
|
+
if (!unwound?.def) return;
|
|
1462
1422
|
let def = unwound.def;
|
|
1463
1423
|
if (isInterface(def)) def = def.getDefinition() || def;
|
|
1464
1424
|
return def;
|
|
@@ -1491,11 +1451,11 @@ else targetValue = "true";
|
|
|
1491
1451
|
prefix: `${prefix}${result.path}?`,
|
|
1492
1452
|
def: result.propDef
|
|
1493
1453
|
});
|
|
1494
|
-
else {
|
|
1454
|
+
else {
|
|
1495
1455
|
const suffix = `.props.get("${escapeQuotes(parts[i])}")${i < parts.length - 1 ? "?.type" : "?"}`;
|
|
1496
1456
|
nextAccessors.push({
|
|
1497
1457
|
prefix: `${prefix}${suffix}`,
|
|
1498
|
-
def:
|
|
1458
|
+
def: void 0
|
|
1499
1459
|
});
|
|
1500
1460
|
}
|
|
1501
1461
|
}
|
|
@@ -1528,8 +1488,7 @@ else {
|
|
|
1528
1488
|
return [];
|
|
1529
1489
|
}
|
|
1530
1490
|
if (isGroup(def)) {
|
|
1531
|
-
const
|
|
1532
|
-
const items = group.unwrap();
|
|
1491
|
+
const items = def.unwrap();
|
|
1533
1492
|
const results = [];
|
|
1534
1493
|
for (let i = 0; i < items.length; i++) for (const result of this.buildPropPaths(items[i], propName)) results.push({
|
|
1535
1494
|
path: `.items[${i}].type${result.path}`,
|
|
@@ -1540,14 +1499,16 @@ else {
|
|
|
1540
1499
|
return [];
|
|
1541
1500
|
}
|
|
1542
1501
|
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();
|
|
1502
|
+
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
1503
|
}
|
|
1545
1504
|
};
|
|
1546
1505
|
|
|
1547
1506
|
//#endregion
|
|
1548
1507
|
//#region packages/typescript/src/plugin.ts
|
|
1549
|
-
|
|
1550
|
-
|
|
1508
|
+
/**
|
|
1509
|
+
* Resolves the effective JSON schema mode from plugin options.
|
|
1510
|
+
*/ function resolveJsonSchemaMode(opts) {
|
|
1511
|
+
if (opts?.jsonSchema !== void 0) return opts.jsonSchema;
|
|
1551
1512
|
return false;
|
|
1552
1513
|
}
|
|
1553
1514
|
const tsPlugin = (opts) => {
|
|
@@ -1566,19 +1527,19 @@ const tsPlugin = (opts) => {
|
|
|
1566
1527
|
async buildEnd(output, format, repo) {
|
|
1567
1528
|
if (format === "dts" || format === DEFAULT_FORMAT) {
|
|
1568
1529
|
const annotations = await repo.getUsedAnnotations();
|
|
1569
|
-
const tags = await repo.getPrimitivesTags() || new Set();
|
|
1530
|
+
const tags = await repo.getPrimitivesTags() || /* @__PURE__ */ new Set();
|
|
1570
1531
|
const rendered = [];
|
|
1571
1532
|
for (const [key, val] of Object.entries(annotations)) {
|
|
1572
1533
|
const multiple = val.multiple;
|
|
1573
1534
|
const typeLine = Array.from(val.types).map((t) => {
|
|
1574
1535
|
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;
|
|
1536
|
+
else return "optional" in t && t.optional ? `${t.type} | true` : t.type;
|
|
1576
1537
|
}).join(" | ");
|
|
1577
1538
|
rendered.push(`${wrapProp(key)}: ${multiple ? "(" : ""}${typeLine}${multiple ? ")[]" : ""}`);
|
|
1578
1539
|
}
|
|
1579
1540
|
const renderedTags = Array.from(tags).map((f) => `"${escapeQuotes(f)}"`).join(" | ");
|
|
1580
1541
|
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
|
|
1542
|
+
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
1543
|
fileName: "atscript.d.ts",
|
|
1583
1544
|
source: "",
|
|
1584
1545
|
target: path.join(repo.root, "atscript.d.ts")
|
|
@@ -1589,4 +1550,4 @@ else return "optional" in t && t.optional ? `${t.type} | true` : t.type;
|
|
|
1589
1550
|
};
|
|
1590
1551
|
|
|
1591
1552
|
//#endregion
|
|
1592
|
-
export { tsPlugin };
|
|
1553
|
+
export { tsPlugin as t };
|