@atscript/core 0.1.34 → 0.1.35
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/LICENSE +1 -1
- package/dist/index.cjs +1458 -214
- package/dist/index.d.ts +140 -16
- package/dist/index.mjs +1443 -215
- package/package.json +3 -3
- package/skills/atscript-core/annotations.md +1 -1
package/dist/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { readFile, readdir } from "node:fs/promises";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { pathToFileURL } from "node:url";
|
|
5
5
|
import { rolldown } from "rolldown";
|
|
6
|
-
import {
|
|
6
|
+
import { Node, printTree } from "@prostojs/parser";
|
|
7
7
|
import path$1 from "path";
|
|
8
8
|
import { URL } from "url";
|
|
9
9
|
import { defu } from "defu";
|
|
@@ -11,7 +11,7 @@ import { mkdir, writeFile } from "fs/promises";
|
|
|
11
11
|
import { glob } from "glob";
|
|
12
12
|
|
|
13
13
|
//#region packages/core/src/parser/nodes/semantic-node.ts
|
|
14
|
-
function _define_property$
|
|
14
|
+
function _define_property$16(obj, key, value) {
|
|
15
15
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
16
16
|
value,
|
|
17
17
|
enumerable: true,
|
|
@@ -122,15 +122,15 @@ else this.annotationsCounter.set(name, 1);
|
|
|
122
122
|
return this.definition;
|
|
123
123
|
}
|
|
124
124
|
constructor(entity) {
|
|
125
|
-
_define_property$
|
|
126
|
-
_define_property$
|
|
127
|
-
_define_property$
|
|
128
|
-
_define_property$
|
|
129
|
-
_define_property$
|
|
130
|
-
_define_property$
|
|
131
|
-
_define_property$
|
|
132
|
-
_define_property$
|
|
133
|
-
_define_property$
|
|
125
|
+
_define_property$16(this, "entity", void 0);
|
|
126
|
+
_define_property$16(this, "tokens", void 0);
|
|
127
|
+
_define_property$16(this, "isGroup", void 0);
|
|
128
|
+
_define_property$16(this, "definition", void 0);
|
|
129
|
+
_define_property$16(this, "annotations", void 0);
|
|
130
|
+
_define_property$16(this, "annotationsCounter", void 0);
|
|
131
|
+
_define_property$16(this, "__typeId", void 0);
|
|
132
|
+
_define_property$16(this, "ownerNode", void 0);
|
|
133
|
+
_define_property$16(this, "_documentation", void 0);
|
|
134
134
|
this.entity = entity;
|
|
135
135
|
this.isGroup = false;
|
|
136
136
|
}
|
|
@@ -227,7 +227,7 @@ var SemanticConstNode = class extends SemanticNode {
|
|
|
227
227
|
|
|
228
228
|
//#endregion
|
|
229
229
|
//#region packages/core/src/parser/nodes/group-node.ts
|
|
230
|
-
function _define_property$
|
|
230
|
+
function _define_property$15(obj, key, value) {
|
|
231
231
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
232
232
|
value,
|
|
233
233
|
enumerable: true,
|
|
@@ -272,7 +272,7 @@ var SemanticGroup = class extends SemanticNode {
|
|
|
272
272
|
return s;
|
|
273
273
|
}
|
|
274
274
|
constructor(nodes = [], operator) {
|
|
275
|
-
super("group"), _define_property$
|
|
275
|
+
super("group"), _define_property$15(this, "nodes", void 0), _define_property$15(this, "operator", void 0), _define_property$15(this, "isGroup", void 0), this.nodes = nodes, this.operator = operator, this.isGroup = true;
|
|
276
276
|
}
|
|
277
277
|
};
|
|
278
278
|
|
|
@@ -294,7 +294,7 @@ var SemanticImportNode = class extends SemanticNode {
|
|
|
294
294
|
|
|
295
295
|
//#endregion
|
|
296
296
|
//#region packages/core/src/parser/nodes/interface-node.ts
|
|
297
|
-
function _define_property$
|
|
297
|
+
function _define_property$14(obj, key, value) {
|
|
298
298
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
299
299
|
value,
|
|
300
300
|
enumerable: true,
|
|
@@ -342,13 +342,13 @@ var SemanticInterfaceNode = class extends SemanticNode {
|
|
|
342
342
|
return s;
|
|
343
343
|
}
|
|
344
344
|
constructor() {
|
|
345
|
-
super("interface"), _define_property$
|
|
345
|
+
super("interface"), _define_property$14(this, "_extendsTokens", []);
|
|
346
346
|
}
|
|
347
347
|
};
|
|
348
348
|
|
|
349
349
|
//#endregion
|
|
350
350
|
//#region packages/core/src/parser/token.ts
|
|
351
|
-
function _define_property$
|
|
351
|
+
function _define_property$13(obj, key, value) {
|
|
352
352
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
353
353
|
value,
|
|
354
354
|
enumerable: true,
|
|
@@ -394,43 +394,46 @@ var Token = class Token {
|
|
|
394
394
|
return this._data.type === "annotation";
|
|
395
395
|
}
|
|
396
396
|
constructor(_data) {
|
|
397
|
-
_define_property$
|
|
397
|
+
_define_property$13(this, "_data", void 0);
|
|
398
398
|
/**
|
|
399
399
|
* Set this to file path (e.g. "./src/file.as") for path token in import statement
|
|
400
|
-
*/ _define_property$
|
|
400
|
+
*/ _define_property$13(this, "fromPath", void 0);
|
|
401
401
|
/**
|
|
402
402
|
* All definitions that exported must be marked with this flag
|
|
403
|
-
*/ _define_property$
|
|
403
|
+
*/ _define_property$13(this, "exported", void 0);
|
|
404
404
|
/**
|
|
405
405
|
* All the definitions must be marked with this flag
|
|
406
|
-
*/ _define_property$
|
|
406
|
+
*/ _define_property$13(this, "isDefinition", void 0);
|
|
407
407
|
/**
|
|
408
408
|
* All the references must be marked with this flag
|
|
409
|
-
*/ _define_property$
|
|
409
|
+
*/ _define_property$13(this, "isReference", void 0);
|
|
410
410
|
/**
|
|
411
411
|
* All the import tokens must be marked with this flag
|
|
412
|
-
*/ _define_property$
|
|
412
|
+
*/ _define_property$13(this, "imported", void 0);
|
|
413
413
|
/**
|
|
414
414
|
* Refs chained via . or ["propName"] are marked with this flag
|
|
415
|
-
*/ _define_property$
|
|
415
|
+
*/ _define_property$13(this, "isChain", void 0);
|
|
416
416
|
/**
|
|
417
417
|
* Prop patterns ([*] or [regexp]) are storing patterns here
|
|
418
|
-
*/ _define_property$
|
|
419
|
-
_define_property$
|
|
418
|
+
*/ _define_property$13(this, "pattern", void 0);
|
|
419
|
+
_define_property$13(this, "parentNode", void 0);
|
|
420
420
|
/**
|
|
421
421
|
* Only for annotation arguments: reference to their annotation token
|
|
422
|
-
*/ _define_property$
|
|
423
|
-
_define_property$
|
|
422
|
+
*/ _define_property$13(this, "annotationRef", void 0);
|
|
423
|
+
_define_property$13(this, "index", void 0);
|
|
424
424
|
/**
|
|
425
425
|
* Block type
|
|
426
|
-
*/ _define_property$
|
|
426
|
+
*/ _define_property$13(this, "blockType", void 0);
|
|
427
|
+
/**
|
|
428
|
+
* Parsed query expression tree (for query-type annotation arguments)
|
|
429
|
+
*/ _define_property$13(this, "queryNode", void 0);
|
|
427
430
|
this._data = _data;
|
|
428
431
|
}
|
|
429
432
|
};
|
|
430
433
|
|
|
431
434
|
//#endregion
|
|
432
435
|
//#region packages/core/src/parser/nodes/primitive-node.ts
|
|
433
|
-
function _define_property$
|
|
436
|
+
function _define_property$12(obj, key, value) {
|
|
434
437
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
435
438
|
value,
|
|
436
439
|
enumerable: true,
|
|
@@ -479,7 +482,7 @@ else if (value.length > 0) this.annotations.push(toAnnotationTokens(name, value[
|
|
|
479
482
|
return indent + s.split("\n").join(`\n${indent}`);
|
|
480
483
|
}
|
|
481
484
|
constructor(_id, config, parentKey = "", annotationTree) {
|
|
482
|
-
super("primitive"), _define_property$
|
|
485
|
+
super("primitive"), _define_property$12(this, "_id", void 0), _define_property$12(this, "config", void 0), _define_property$12(this, "parentKey", void 0), _define_property$12(this, "annotationTree", void 0), _define_property$12(this, "type", void 0), _define_property$12(this, "props", void 0), _define_property$12(this, "tags", void 0), this._id = _id, this.config = config, this.parentKey = parentKey, this.annotationTree = annotationTree;
|
|
483
486
|
this.props = new Map();
|
|
484
487
|
this.tags = new Set([_id, ...config?.tags || []]);
|
|
485
488
|
for (const [ext, def] of Object.entries(config.extensions || {})) {
|
|
@@ -600,7 +603,7 @@ var SemanticPropNode = class extends SemanticNode {
|
|
|
600
603
|
|
|
601
604
|
//#endregion
|
|
602
605
|
//#region packages/core/src/parser/nodes/ref-node.ts
|
|
603
|
-
function _define_property$
|
|
606
|
+
function _define_property$11(obj, key, value) {
|
|
604
607
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
605
608
|
value,
|
|
606
609
|
enumerable: true,
|
|
@@ -652,13 +655,13 @@ var SemanticRefNode = class extends SemanticNode {
|
|
|
652
655
|
return indent + s.split("\n").join(`\n${indent}`);
|
|
653
656
|
}
|
|
654
657
|
constructor() {
|
|
655
|
-
super("ref"), _define_property$
|
|
658
|
+
super("ref"), _define_property$11(this, "_chain", []), _define_property$11(this, "_dots", []);
|
|
656
659
|
}
|
|
657
660
|
};
|
|
658
661
|
|
|
659
662
|
//#endregion
|
|
660
663
|
//#region packages/core/src/parser/nodes/structure-node.ts
|
|
661
|
-
function _define_property$
|
|
664
|
+
function _define_property$10(obj, key, value) {
|
|
662
665
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
663
666
|
value,
|
|
664
667
|
enumerable: true,
|
|
@@ -737,7 +740,7 @@ var SemanticStructureNode = class extends SemanticGroup {
|
|
|
737
740
|
this.props.set(opts.name, prop);
|
|
738
741
|
}
|
|
739
742
|
constructor() {
|
|
740
|
-
super(), _define_property$
|
|
743
|
+
super(), _define_property$10(this, "props", new Map());
|
|
741
744
|
this.entity = "structure";
|
|
742
745
|
}
|
|
743
746
|
};
|
|
@@ -770,6 +773,84 @@ var SemanticTypeNode = class extends SemanticNode {
|
|
|
770
773
|
}
|
|
771
774
|
};
|
|
772
775
|
|
|
776
|
+
//#endregion
|
|
777
|
+
//#region packages/core/src/parser/nodes/query-nodes.ts
|
|
778
|
+
function _define_property$9(obj, key, value) {
|
|
779
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
780
|
+
value,
|
|
781
|
+
enumerable: true,
|
|
782
|
+
configurable: true,
|
|
783
|
+
writable: true
|
|
784
|
+
});
|
|
785
|
+
else obj[key] = value;
|
|
786
|
+
return obj;
|
|
787
|
+
}
|
|
788
|
+
var SemanticQueryNode = class extends SemanticNode {
|
|
789
|
+
registerAtDocument(doc) {
|
|
790
|
+
this.propagateQueryArgToken(this.expression);
|
|
791
|
+
this.expression.registerAtDocument(doc);
|
|
792
|
+
}
|
|
793
|
+
propagateQueryArgToken(expr) {
|
|
794
|
+
if ("left" in expr) {
|
|
795
|
+
expr.left.queryArgToken = this.sourceToken;
|
|
796
|
+
const right = expr.right;
|
|
797
|
+
if (right && "fieldRef" in right) right.queryArgToken = this.sourceToken;
|
|
798
|
+
} else if ("operands" in expr) for (const operand of expr.operands) this.propagateQueryArgToken(operand);
|
|
799
|
+
}
|
|
800
|
+
constructor() {
|
|
801
|
+
super("query"), _define_property$9(this, "expression", void 0), _define_property$9(this, "sourceToken", void 0);
|
|
802
|
+
}
|
|
803
|
+
};
|
|
804
|
+
var SemanticQueryLogicalNode = class extends SemanticNode {
|
|
805
|
+
registerAtDocument(doc) {
|
|
806
|
+
for (const operand of this.operands) operand.registerAtDocument(doc);
|
|
807
|
+
}
|
|
808
|
+
constructor() {
|
|
809
|
+
super("query-logical"), _define_property$9(this, "operator", void 0), _define_property$9(this, "operands", void 0);
|
|
810
|
+
}
|
|
811
|
+
};
|
|
812
|
+
var SemanticQueryComparisonNode = class extends SemanticNode {
|
|
813
|
+
registerAtDocument(doc) {
|
|
814
|
+
this.left.registerAtDocument(doc);
|
|
815
|
+
this.right?.registerAtDocument(doc);
|
|
816
|
+
}
|
|
817
|
+
constructor() {
|
|
818
|
+
super("query-comparison"), _define_property$9(this, "left", void 0), _define_property$9(this, "operator", void 0), _define_property$9(this, "right", void 0);
|
|
819
|
+
}
|
|
820
|
+
};
|
|
821
|
+
var SemanticQueryFieldRefNode = class extends SemanticNode {
|
|
822
|
+
registerAtDocument(doc) {
|
|
823
|
+
if (this.typeRef) {
|
|
824
|
+
this.typeRef.isReference = true;
|
|
825
|
+
this.typeRef.parentNode = this;
|
|
826
|
+
doc.referred.push(this.typeRef);
|
|
827
|
+
doc.tokensIndex.add(this.typeRef);
|
|
828
|
+
}
|
|
829
|
+
this.fieldRef.parentNode = this;
|
|
830
|
+
doc.tokensIndex.add(this.fieldRef);
|
|
831
|
+
doc.queryFieldRefs.push(this);
|
|
832
|
+
}
|
|
833
|
+
constructor() {
|
|
834
|
+
super("query-field-ref"), _define_property$9(this, "typeRef", void 0), _define_property$9(this, "fieldRef", void 0), _define_property$9(this, "queryArgToken", void 0);
|
|
835
|
+
}
|
|
836
|
+
};
|
|
837
|
+
var SemanticQueryValueNode = class extends SemanticNode {
|
|
838
|
+
registerAtDocument(doc) {
|
|
839
|
+
doc.tokensIndex.add(this.valueToken);
|
|
840
|
+
}
|
|
841
|
+
constructor() {
|
|
842
|
+
super("query-value"), _define_property$9(this, "valueToken", void 0);
|
|
843
|
+
}
|
|
844
|
+
};
|
|
845
|
+
var SemanticQueryValueListNode = class extends SemanticNode {
|
|
846
|
+
registerAtDocument(doc) {
|
|
847
|
+
for (const v of this.values) v.registerAtDocument(doc);
|
|
848
|
+
}
|
|
849
|
+
constructor() {
|
|
850
|
+
super("query-value-list"), _define_property$9(this, "values", void 0);
|
|
851
|
+
}
|
|
852
|
+
};
|
|
853
|
+
|
|
773
854
|
//#endregion
|
|
774
855
|
//#region packages/core/src/parser/nodes/index.ts
|
|
775
856
|
const $n = {
|
|
@@ -822,6 +903,15 @@ function isPrimitive(node) {
|
|
|
822
903
|
function isAnnotate(node) {
|
|
823
904
|
return node?.entity === "annotate";
|
|
824
905
|
}
|
|
906
|
+
function isQueryLogical(node) {
|
|
907
|
+
return node?.operands !== undefined;
|
|
908
|
+
}
|
|
909
|
+
function isQueryComparison(node) {
|
|
910
|
+
return node?.left !== undefined;
|
|
911
|
+
}
|
|
912
|
+
function isQueryFieldRef(node) {
|
|
913
|
+
return node?.fieldRef !== undefined;
|
|
914
|
+
}
|
|
825
915
|
|
|
826
916
|
//#endregion
|
|
827
917
|
//#region packages/core/src/annotations/annotation-spec.ts
|
|
@@ -845,7 +935,7 @@ var AnnotationSpec = class {
|
|
|
845
935
|
return this.arguments.map((arg, index) => {
|
|
846
936
|
const placeholderIndex = index + 1;
|
|
847
937
|
const defaultValue = this.getDefaultValueForType(arg.name, arg.type);
|
|
848
|
-
const quote = arg.type === "string" ? `'` : "";
|
|
938
|
+
const quote = arg.type === "string" ? `'` : arg.type === "query" ? "`" : "";
|
|
849
939
|
return `${quote}\${${placeholderIndex}:${defaultValue}}${quote}`;
|
|
850
940
|
}).join(", ");
|
|
851
941
|
}
|
|
@@ -854,6 +944,8 @@ var AnnotationSpec = class {
|
|
|
854
944
|
case "string": return tokenType === "text" ? undefined : "string expected.";
|
|
855
945
|
case "number": return tokenType === "number" ? undefined : "number expected.";
|
|
856
946
|
case "boolean": return tokenType === "identifier" ? undefined : "boolean expected.";
|
|
947
|
+
case "ref": return tokenType === "identifier" ? undefined : "type reference expected.";
|
|
948
|
+
case "query": return tokenType === "query" ? undefined : "query expression expected (use backticks).";
|
|
857
949
|
default: return `unknown type "${type$1}".`;
|
|
858
950
|
}
|
|
859
951
|
}
|
|
@@ -946,6 +1038,8 @@ else if (isGroup(def) && def.entity !== "tuple") defEntity = def.op === "&" ? "i
|
|
|
946
1038
|
case "string": return name;
|
|
947
1039
|
case "number": return "0";
|
|
948
1040
|
case "boolean": return "true";
|
|
1041
|
+
case "ref": return "TypeName";
|
|
1042
|
+
case "query": return "field = value";
|
|
949
1043
|
default: return "";
|
|
950
1044
|
}
|
|
951
1045
|
}
|
|
@@ -963,10 +1057,13 @@ function resolveAnnotation(name, annotationsTree) {
|
|
|
963
1057
|
const parts = name.split(".");
|
|
964
1058
|
let current = annotationsTree;
|
|
965
1059
|
for (const part of parts) {
|
|
1060
|
+
if (part === "$self") return undefined;
|
|
966
1061
|
if (!current || isAnnotationSpec(current)) return undefined;
|
|
967
1062
|
current = current[part];
|
|
968
1063
|
}
|
|
969
|
-
|
|
1064
|
+
if (isAnnotationSpec(current)) return current;
|
|
1065
|
+
if (current && !isAnnotationSpec(current) && current.$self) return current.$self;
|
|
1066
|
+
return undefined;
|
|
970
1067
|
}
|
|
971
1068
|
|
|
972
1069
|
//#endregion
|
|
@@ -1083,6 +1180,204 @@ else if (SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) {
|
|
|
1083
1180
|
}
|
|
1084
1181
|
}
|
|
1085
1182
|
|
|
1183
|
+
//#endregion
|
|
1184
|
+
//#region packages/core/src/defaults/db-query-lsp.ts
|
|
1185
|
+
function getQueryScope(queryArgToken, doc) {
|
|
1186
|
+
const annotationRef = queryArgToken.annotationRef;
|
|
1187
|
+
if (!annotationRef) return undefined;
|
|
1188
|
+
const owner = queryArgToken.parentNode;
|
|
1189
|
+
if (!owner) return undefined;
|
|
1190
|
+
const annotationName = annotationRef.text.slice(1);
|
|
1191
|
+
if (annotationName === "db.view.filter") return getViewFilterScope(owner);
|
|
1192
|
+
if (annotationName === "db.view.joins") return getViewJoinsScope(owner, queryArgToken);
|
|
1193
|
+
if (annotationName === "db.rel.filter") return getRelFilterScope(owner);
|
|
1194
|
+
return undefined;
|
|
1195
|
+
}
|
|
1196
|
+
function getViewFilterScope(owner) {
|
|
1197
|
+
const forAnnotations = owner.annotations?.filter((a) => a.name === "db.view.for");
|
|
1198
|
+
const entryTypeName = forAnnotations?.[0]?.args[0]?.text;
|
|
1199
|
+
if (!entryTypeName) return undefined;
|
|
1200
|
+
const allowedTypes = [entryTypeName];
|
|
1201
|
+
const joinsAnnotations = owner.annotations?.filter((a) => a.name === "db.view.joins");
|
|
1202
|
+
if (joinsAnnotations) {
|
|
1203
|
+
for (const join of joinsAnnotations) if (join.args[0]) allowedTypes.push(join.args[0].text);
|
|
1204
|
+
}
|
|
1205
|
+
return {
|
|
1206
|
+
allowedTypes,
|
|
1207
|
+
unqualifiedTarget: entryTypeName
|
|
1208
|
+
};
|
|
1209
|
+
}
|
|
1210
|
+
function getViewJoinsScope(owner, queryArgToken) {
|
|
1211
|
+
const forAnnotations = owner.annotations?.filter((a) => a.name === "db.view.for");
|
|
1212
|
+
const entryTypeName = forAnnotations?.[0]?.args[0]?.text;
|
|
1213
|
+
if (!entryTypeName) return undefined;
|
|
1214
|
+
const joinsAnnotation = owner.annotations?.find((a) => a.name === "db.view.joins" && a.args.includes(queryArgToken));
|
|
1215
|
+
const joinTargetName = joinsAnnotation?.args[0]?.text;
|
|
1216
|
+
if (!joinTargetName) return undefined;
|
|
1217
|
+
return {
|
|
1218
|
+
allowedTypes: [joinTargetName, entryTypeName],
|
|
1219
|
+
unqualifiedTarget: entryTypeName
|
|
1220
|
+
};
|
|
1221
|
+
}
|
|
1222
|
+
function getRelFilterScope(owner) {
|
|
1223
|
+
let def = owner.getDefinition();
|
|
1224
|
+
if (isArray(def)) def = def?.getDefinition();
|
|
1225
|
+
if (!isRef(def)) return undefined;
|
|
1226
|
+
const targetTypeName = def.id;
|
|
1227
|
+
const allowedTypes = [targetTypeName];
|
|
1228
|
+
const viaAnnotation = owner.annotations?.find((a) => a.name === "db.rel.via");
|
|
1229
|
+
if (viaAnnotation?.args[0]) allowedTypes.push(viaAnnotation.args[0].text);
|
|
1230
|
+
return {
|
|
1231
|
+
allowedTypes,
|
|
1232
|
+
unqualifiedTarget: targetTypeName
|
|
1233
|
+
};
|
|
1234
|
+
}
|
|
1235
|
+
function resolveQueryFieldRef(fieldRefNode, doc, scope) {
|
|
1236
|
+
const typeName = fieldRefNode.typeRef?.text ?? scope.unqualifiedTarget;
|
|
1237
|
+
if (!typeName) return undefined;
|
|
1238
|
+
const fieldPath = fieldRefNode.fieldRef.text;
|
|
1239
|
+
const chain = fieldPath.split(".");
|
|
1240
|
+
const parentChain = chain.slice(0, -1);
|
|
1241
|
+
const parentUnwound = doc.unwindType(typeName, parentChain);
|
|
1242
|
+
if (!parentUnwound?.def) return undefined;
|
|
1243
|
+
const unwound = doc.unwindType(typeName, chain);
|
|
1244
|
+
if (!unwound?.node) return undefined;
|
|
1245
|
+
const prop = unwound.node;
|
|
1246
|
+
return {
|
|
1247
|
+
targetUri: parentUnwound.doc.id,
|
|
1248
|
+
doc: parentUnwound.doc,
|
|
1249
|
+
prop
|
|
1250
|
+
};
|
|
1251
|
+
}
|
|
1252
|
+
function getFieldsForType(doc, typeName) {
|
|
1253
|
+
const unwound = doc.unwindType(typeName);
|
|
1254
|
+
if (!unwound?.def) return [];
|
|
1255
|
+
let def = doc.mergeIntersection(unwound.def);
|
|
1256
|
+
if (isInterface(def)) {
|
|
1257
|
+
const resolved = doc.resolveInterfaceExtends(def);
|
|
1258
|
+
if (resolved) def = resolved;
|
|
1259
|
+
else def = def.getDefinition() || def;
|
|
1260
|
+
}
|
|
1261
|
+
if (isStructure(def) || isInterface(def)) return Array.from(def.props.values());
|
|
1262
|
+
return [];
|
|
1263
|
+
}
|
|
1264
|
+
function getQueryCompletionScope(queryArgToken, doc) {
|
|
1265
|
+
const scope = getQueryScope(queryArgToken, doc);
|
|
1266
|
+
if (!scope) return undefined;
|
|
1267
|
+
return {
|
|
1268
|
+
typeNames: scope.allowedTypes,
|
|
1269
|
+
unqualifiedTarget: scope.unqualifiedTarget,
|
|
1270
|
+
getFields: (typeName) => getFieldsForType(doc, typeName)
|
|
1271
|
+
};
|
|
1272
|
+
}
|
|
1273
|
+
const SYMBOLIC_OPS$1 = new Set([
|
|
1274
|
+
"=",
|
|
1275
|
+
"!=",
|
|
1276
|
+
">",
|
|
1277
|
+
">=",
|
|
1278
|
+
"<",
|
|
1279
|
+
"<="
|
|
1280
|
+
]);
|
|
1281
|
+
const KEYWORD_OPS = new Set([
|
|
1282
|
+
"in",
|
|
1283
|
+
"matches",
|
|
1284
|
+
"exists"
|
|
1285
|
+
]);
|
|
1286
|
+
const LOGICAL_KEYWORDS = new Set([
|
|
1287
|
+
"and",
|
|
1288
|
+
"or",
|
|
1289
|
+
"not"
|
|
1290
|
+
]);
|
|
1291
|
+
const VALUE_KEYWORDS$1 = new Set([
|
|
1292
|
+
"true",
|
|
1293
|
+
"false",
|
|
1294
|
+
"null",
|
|
1295
|
+
"undefined"
|
|
1296
|
+
]);
|
|
1297
|
+
function analyzeQueryCursorContext(textBeforeCursor) {
|
|
1298
|
+
const trimmed = textBeforeCursor.trimEnd();
|
|
1299
|
+
const hasTrailingSpace = textBeforeCursor.length > trimmed.length;
|
|
1300
|
+
if (trimmed.length === 0) return { type: "field-start" };
|
|
1301
|
+
if (trimmed.endsWith(".")) {
|
|
1302
|
+
const before = trimmed.slice(0, -1).trimEnd();
|
|
1303
|
+
const match = /(\w+)$/u.exec(before);
|
|
1304
|
+
if (match) return {
|
|
1305
|
+
type: "after-dot",
|
|
1306
|
+
typeName: match[1]
|
|
1307
|
+
};
|
|
1308
|
+
return { type: "field-start" };
|
|
1309
|
+
}
|
|
1310
|
+
const tokens$1 = tokenizeQueryText(trimmed);
|
|
1311
|
+
if (tokens$1.length === 0) return { type: "field-start" };
|
|
1312
|
+
const last = tokens$1[tokens$1.length - 1];
|
|
1313
|
+
if (LOGICAL_KEYWORDS.has(last) || last === "(") return { type: "field-start" };
|
|
1314
|
+
if (SYMBOLIC_OPS$1.has(last)) return { type: "after-operator" };
|
|
1315
|
+
if (last === "in" || last === "matches") return { type: "after-operator" };
|
|
1316
|
+
if (last === "exists") return { type: "after-comparison" };
|
|
1317
|
+
if (VALUE_KEYWORDS$1.has(last)) return { type: "after-comparison" };
|
|
1318
|
+
if (/^['"]/.test(last) || /^\d/.test(last)) return { type: "after-comparison" };
|
|
1319
|
+
if (tokens$1.length >= 2) {
|
|
1320
|
+
const prev = tokens$1[tokens$1.length - 2];
|
|
1321
|
+
if (SYMBOLIC_OPS$1.has(prev) || KEYWORD_OPS.has(prev)) return { type: "after-comparison" };
|
|
1322
|
+
}
|
|
1323
|
+
if (/^\w+$/u.test(last)) {
|
|
1324
|
+
if (!hasTrailingSpace) return { type: "field-start" };
|
|
1325
|
+
return { type: "after-field" };
|
|
1326
|
+
}
|
|
1327
|
+
return { type: "field-start" };
|
|
1328
|
+
}
|
|
1329
|
+
/**
|
|
1330
|
+
* Simple tokenizer for query text — splits into identifiers, operators, and punctuation.
|
|
1331
|
+
* Does NOT need to handle all edge cases; just enough for cursor context analysis.
|
|
1332
|
+
*/ function tokenizeQueryText(text$2) {
|
|
1333
|
+
const tokens$1 = [];
|
|
1334
|
+
let i = 0;
|
|
1335
|
+
while (i < text$2.length) {
|
|
1336
|
+
if (/\s/.test(text$2[i])) {
|
|
1337
|
+
i++;
|
|
1338
|
+
continue;
|
|
1339
|
+
}
|
|
1340
|
+
if (text$2[i] === "'" || text$2[i] === "\"") {
|
|
1341
|
+
const quote = text$2[i];
|
|
1342
|
+
let j = i + 1;
|
|
1343
|
+
while (j < text$2.length && text$2[j] !== quote) {
|
|
1344
|
+
if (text$2[j] === "\\") j++;
|
|
1345
|
+
j++;
|
|
1346
|
+
}
|
|
1347
|
+
tokens$1.push(text$2.slice(i, j + 1));
|
|
1348
|
+
i = j + 1;
|
|
1349
|
+
continue;
|
|
1350
|
+
}
|
|
1351
|
+
if (i + 1 < text$2.length) {
|
|
1352
|
+
const two = text$2.slice(i, i + 2);
|
|
1353
|
+
if (two === "!=" || two === ">=" || two === "<=") {
|
|
1354
|
+
tokens$1.push(two);
|
|
1355
|
+
i += 2;
|
|
1356
|
+
continue;
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
if ("=><(),".includes(text$2[i])) {
|
|
1360
|
+
tokens$1.push(text$2[i]);
|
|
1361
|
+
i++;
|
|
1362
|
+
continue;
|
|
1363
|
+
}
|
|
1364
|
+
if (text$2[i] === ".") {
|
|
1365
|
+
tokens$1.push(".");
|
|
1366
|
+
i++;
|
|
1367
|
+
continue;
|
|
1368
|
+
}
|
|
1369
|
+
if (/[\w]/u.test(text$2[i])) {
|
|
1370
|
+
let j = i;
|
|
1371
|
+
while (j < text$2.length && /[\w]/u.test(text$2[j])) j++;
|
|
1372
|
+
tokens$1.push(text$2.slice(i, j));
|
|
1373
|
+
i = j;
|
|
1374
|
+
continue;
|
|
1375
|
+
}
|
|
1376
|
+
i++;
|
|
1377
|
+
}
|
|
1378
|
+
return tokens$1;
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1086
1381
|
//#endregion
|
|
1087
1382
|
//#region packages/core/src/parser/id-registry.ts
|
|
1088
1383
|
function _define_property$7(obj, key, value) {
|
|
@@ -1273,40 +1568,21 @@ var NodeIterator = class NodeIterator {
|
|
|
1273
1568
|
}
|
|
1274
1569
|
};
|
|
1275
1570
|
|
|
1276
|
-
//#endregion
|
|
1277
|
-
//#region packages/core/src/parser/utils.ts
|
|
1278
|
-
function toVsCodeRange(start, end, startOffset = 0, endOffset = 0) {
|
|
1279
|
-
return {
|
|
1280
|
-
start: {
|
|
1281
|
-
line: start.row - 1,
|
|
1282
|
-
character: start.col + startOffset
|
|
1283
|
-
},
|
|
1284
|
-
end: {
|
|
1285
|
-
line: end.row - 1,
|
|
1286
|
-
character: end.col + endOffset
|
|
1287
|
-
}
|
|
1288
|
-
};
|
|
1289
|
-
}
|
|
1290
|
-
function resolveAtscriptFromPath(from, id) {
|
|
1291
|
-
return `file://${path$1.join(id.slice(7).split("/").slice(0, -1).join("/"), from)}.as`;
|
|
1292
|
-
}
|
|
1293
|
-
function getRelPath(fromUri, toUri) {
|
|
1294
|
-
const fromPath = new URL(fromUri).pathname;
|
|
1295
|
-
const toPath = new URL(toUri).pathname;
|
|
1296
|
-
const relPath = path$1.relative(path$1.dirname(fromPath), toPath);
|
|
1297
|
-
const { dir, name } = path$1.parse(relPath);
|
|
1298
|
-
const prefix = dir.startsWith("..") ? "" : "./";
|
|
1299
|
-
return `${prefix}${dir ? `${dir}/` : ""}${name}`;
|
|
1300
|
-
}
|
|
1301
|
-
|
|
1302
1571
|
//#endregion
|
|
1303
1572
|
//#region packages/core/src/tokenizer/tokens/a-identifier.token.ts
|
|
1304
|
-
const AIdentifierToken = new
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1573
|
+
const AIdentifierToken = new Node({
|
|
1574
|
+
name: "annotation",
|
|
1575
|
+
start: { token: RegExp("@[\\p{ID_Continue}$.]*", "u") },
|
|
1576
|
+
end: {
|
|
1577
|
+
token: RegExp("[^\\p{ID_Continue}$.]", "u"),
|
|
1578
|
+
eject: true
|
|
1579
|
+
},
|
|
1580
|
+
eofClose: true,
|
|
1581
|
+
data: {
|
|
1582
|
+
type: "annotation",
|
|
1583
|
+
text: ""
|
|
1584
|
+
},
|
|
1585
|
+
mapContent: "text"
|
|
1310
1586
|
});
|
|
1311
1587
|
|
|
1312
1588
|
//#endregion
|
|
@@ -1316,33 +1592,59 @@ const pairs = {
|
|
|
1316
1592
|
"(": ")",
|
|
1317
1593
|
"[": "]"
|
|
1318
1594
|
};
|
|
1319
|
-
const BlockToken = new
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1595
|
+
const BlockToken = new Node({
|
|
1596
|
+
name: "block",
|
|
1597
|
+
start: {
|
|
1598
|
+
token: RegExp("(?<text>[([{])", "u"),
|
|
1599
|
+
omit: true
|
|
1600
|
+
},
|
|
1601
|
+
end: {
|
|
1602
|
+
token: (ctx) => pairs[ctx.node.data.text] || "",
|
|
1603
|
+
omit: true
|
|
1604
|
+
},
|
|
1605
|
+
skip: /\s/u,
|
|
1606
|
+
eofClose: true,
|
|
1607
|
+
data: {
|
|
1608
|
+
type: "block",
|
|
1609
|
+
text: ""
|
|
1610
|
+
}
|
|
1327
1611
|
});
|
|
1328
1612
|
|
|
1329
1613
|
//#endregion
|
|
1330
1614
|
//#region packages/core/src/tokenizer/tokens/comment.token.ts
|
|
1331
|
-
const inline = new
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
}
|
|
1337
|
-
|
|
1615
|
+
const inline = new Node({
|
|
1616
|
+
name: "inline-comment",
|
|
1617
|
+
start: {
|
|
1618
|
+
token: "//",
|
|
1619
|
+
omit: true
|
|
1620
|
+
},
|
|
1621
|
+
end: {
|
|
1622
|
+
token: /$/mu,
|
|
1623
|
+
omit: true
|
|
1624
|
+
},
|
|
1625
|
+
eofClose: true,
|
|
1626
|
+
data: {
|
|
1627
|
+
type: "comment",
|
|
1628
|
+
text: ""
|
|
1629
|
+
},
|
|
1630
|
+
mapContent: "text"
|
|
1338
1631
|
});
|
|
1339
|
-
const block$1 = new
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
}
|
|
1345
|
-
|
|
1632
|
+
const block$1 = new Node({
|
|
1633
|
+
name: "block-comment",
|
|
1634
|
+
start: {
|
|
1635
|
+
token: "/*",
|
|
1636
|
+
omit: true
|
|
1637
|
+
},
|
|
1638
|
+
end: {
|
|
1639
|
+
token: "*/",
|
|
1640
|
+
omit: true
|
|
1641
|
+
},
|
|
1642
|
+
eofClose: true,
|
|
1643
|
+
data: {
|
|
1644
|
+
type: "comment",
|
|
1645
|
+
text: ""
|
|
1646
|
+
},
|
|
1647
|
+
mapContent: "text"
|
|
1346
1648
|
});
|
|
1347
1649
|
const commentNodes = {
|
|
1348
1650
|
inline,
|
|
@@ -1352,58 +1654,141 @@ const commentNodes = {
|
|
|
1352
1654
|
|
|
1353
1655
|
//#endregion
|
|
1354
1656
|
//#region packages/core/src/tokenizer/tokens/identifier.token.ts
|
|
1355
|
-
const IdentifierToken = new
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1657
|
+
const IdentifierToken = new Node({
|
|
1658
|
+
name: "identifier",
|
|
1659
|
+
start: { token: RegExp("[\\p{ID_Start}$_][\\p{ID_Continue}$]*", "u") },
|
|
1660
|
+
end: {
|
|
1661
|
+
token: RegExp("[^\\p{ID_Continue}$]", "u"),
|
|
1662
|
+
eject: true
|
|
1663
|
+
},
|
|
1664
|
+
eofClose: true,
|
|
1665
|
+
data: {
|
|
1666
|
+
type: "identifier",
|
|
1667
|
+
text: ""
|
|
1668
|
+
},
|
|
1669
|
+
mapContent: "text"
|
|
1361
1670
|
});
|
|
1362
1671
|
|
|
1363
1672
|
//#endregion
|
|
1364
1673
|
//#region packages/core/src/tokenizer/tokens/number.token.ts
|
|
1365
|
-
const NumberToken = new
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1674
|
+
const NumberToken = new Node({
|
|
1675
|
+
name: "number",
|
|
1676
|
+
start: { token: /[-+]?(?:\d*\.\d+|\d+)(?:[eE][-+]?\d+)?/u },
|
|
1677
|
+
end: {
|
|
1678
|
+
token: /[^\d]/u,
|
|
1679
|
+
eject: true
|
|
1680
|
+
},
|
|
1681
|
+
eofClose: true,
|
|
1682
|
+
data: {
|
|
1683
|
+
type: "number",
|
|
1684
|
+
text: ""
|
|
1685
|
+
},
|
|
1686
|
+
mapContent: "text"
|
|
1371
1687
|
});
|
|
1372
1688
|
|
|
1373
1689
|
//#endregion
|
|
1374
1690
|
//#region packages/core/src/tokenizer/tokens/punctuation.token.ts
|
|
1375
|
-
const PunctuationToken = new
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1691
|
+
const PunctuationToken = new Node({
|
|
1692
|
+
name: "punctuation",
|
|
1693
|
+
start: {
|
|
1694
|
+
token: RegExp("(?<text>[\\n!&+,./:;=?|])", "u"),
|
|
1695
|
+
omit: true
|
|
1696
|
+
},
|
|
1697
|
+
end: {
|
|
1698
|
+
token: "",
|
|
1699
|
+
omit: true
|
|
1700
|
+
},
|
|
1701
|
+
eofClose: true,
|
|
1702
|
+
data: {
|
|
1703
|
+
type: "punctuation",
|
|
1704
|
+
text: ""
|
|
1705
|
+
}
|
|
1706
|
+
});
|
|
1707
|
+
|
|
1708
|
+
//#endregion
|
|
1709
|
+
//#region packages/core/src/tokenizer/tokens/query-operator.token.ts
|
|
1710
|
+
const QueryOperatorToken = new Node({
|
|
1711
|
+
name: "punctuation",
|
|
1712
|
+
start: {
|
|
1713
|
+
token: RegExp("(?<text>!=|>=|<=|[=><])", "u"),
|
|
1714
|
+
omit: true
|
|
1715
|
+
},
|
|
1716
|
+
end: {
|
|
1717
|
+
token: "",
|
|
1718
|
+
omit: true
|
|
1719
|
+
},
|
|
1720
|
+
eofClose: true,
|
|
1721
|
+
data: {
|
|
1722
|
+
type: "punctuation",
|
|
1723
|
+
text: ""
|
|
1724
|
+
}
|
|
1725
|
+
});
|
|
1726
|
+
|
|
1727
|
+
//#endregion
|
|
1728
|
+
//#region packages/core/src/tokenizer/tokens/query.token.ts
|
|
1729
|
+
const QueryToken = new Node({
|
|
1730
|
+
name: "query",
|
|
1731
|
+
start: {
|
|
1732
|
+
token: /`/u,
|
|
1733
|
+
omit: true
|
|
1734
|
+
},
|
|
1735
|
+
end: {
|
|
1736
|
+
token: /`/u,
|
|
1737
|
+
omit: true
|
|
1738
|
+
},
|
|
1739
|
+
skip: /\s/u,
|
|
1740
|
+
eofClose: true,
|
|
1741
|
+
data: {
|
|
1742
|
+
type: "query",
|
|
1743
|
+
text: ""
|
|
1744
|
+
}
|
|
1381
1745
|
});
|
|
1382
1746
|
|
|
1383
1747
|
//#endregion
|
|
1384
1748
|
//#region packages/core/src/tokenizer/tokens/regexp.token.ts
|
|
1385
1749
|
const REGEXP_LITERAL_RE = /\/(?![/*])(?:\\.|\[.*?]|[^/\\\n\r[])*\/[dgimsuy]*/;
|
|
1386
|
-
const RegExpToken = new
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
}
|
|
1392
|
-
|
|
1393
|
-
|
|
1750
|
+
const RegExpToken = new Node({
|
|
1751
|
+
name: "regexp",
|
|
1752
|
+
start: {
|
|
1753
|
+
token: REGEXP_LITERAL_RE,
|
|
1754
|
+
omit: true
|
|
1755
|
+
},
|
|
1756
|
+
end: {
|
|
1757
|
+
token: "",
|
|
1758
|
+
omit: true
|
|
1759
|
+
},
|
|
1760
|
+
eofClose: true,
|
|
1761
|
+
data: {
|
|
1762
|
+
type: "regexp",
|
|
1763
|
+
text: ""
|
|
1764
|
+
}
|
|
1765
|
+
}).onOpen((node, match) => {
|
|
1766
|
+
node.data.text = match?.text ?? "";
|
|
1394
1767
|
});
|
|
1395
1768
|
|
|
1396
1769
|
//#endregion
|
|
1397
1770
|
//#region packages/core/src/tokenizer/tokens/text.node.ts
|
|
1398
|
-
const TextToken = new
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
}
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1771
|
+
const TextToken = new Node({
|
|
1772
|
+
name: "text",
|
|
1773
|
+
start: {
|
|
1774
|
+
token: RegExp("(?<quote>[\"'])", "u"),
|
|
1775
|
+
omit: true
|
|
1776
|
+
},
|
|
1777
|
+
end: {
|
|
1778
|
+
token: (ctx) => new RegExp(`(?<end>${ctx.node.data.quote || ""}|\\n)`),
|
|
1779
|
+
omit: true,
|
|
1780
|
+
backslash: true
|
|
1781
|
+
},
|
|
1782
|
+
eofClose: true,
|
|
1783
|
+
data: {
|
|
1784
|
+
type: "text",
|
|
1785
|
+
quote: "",
|
|
1786
|
+
end: "",
|
|
1787
|
+
text: ""
|
|
1788
|
+
},
|
|
1789
|
+
mapContent: "text"
|
|
1790
|
+
}).onClose((node) => {
|
|
1791
|
+
node.data.multiline = node.data.end === "\n";
|
|
1407
1792
|
});
|
|
1408
1793
|
|
|
1409
1794
|
//#endregion
|
|
@@ -1419,31 +1804,55 @@ const tokens = {
|
|
|
1419
1804
|
number: NumberToken,
|
|
1420
1805
|
text: TextToken,
|
|
1421
1806
|
regexp: RegExpToken,
|
|
1807
|
+
query: QueryToken,
|
|
1422
1808
|
root: undefined
|
|
1423
1809
|
};
|
|
1424
|
-
const root = new
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1810
|
+
const root = new Node({
|
|
1811
|
+
name: "root",
|
|
1812
|
+
skip: /\s/u,
|
|
1813
|
+
eofClose: true,
|
|
1814
|
+
recognizes: [
|
|
1815
|
+
...commentNodes.all,
|
|
1816
|
+
BlockToken,
|
|
1817
|
+
QueryToken,
|
|
1818
|
+
AIdentifierToken,
|
|
1819
|
+
IdentifierToken,
|
|
1820
|
+
TextToken,
|
|
1821
|
+
NumberToken,
|
|
1822
|
+
PunctuationToken
|
|
1823
|
+
]
|
|
1438
1824
|
});
|
|
1439
|
-
|
|
1825
|
+
tokens.root = root;
|
|
1826
|
+
BlockToken.recognize(RegExpToken, ...commentNodes.all, BlockToken, QueryToken, AIdentifierToken, IdentifierToken, TextToken, NumberToken, PunctuationToken);
|
|
1827
|
+
QueryToken.recognize(RegExpToken, QueryOperatorToken, BlockToken, IdentifierToken, TextToken, NumberToken, PunctuationToken);
|
|
1828
|
+
function extractTokens(node) {
|
|
1829
|
+
return node.content.map((item) => {
|
|
1830
|
+
if (typeof item === "string") return {
|
|
1831
|
+
type: "unknown",
|
|
1832
|
+
text: item
|
|
1833
|
+
};
|
|
1834
|
+
const data = item.data;
|
|
1835
|
+
data.getRange = () => ({
|
|
1836
|
+
start: {
|
|
1837
|
+
line: item.start.line - 1,
|
|
1838
|
+
character: item.start.column - 1 + (data.startOffset ?? 0)
|
|
1839
|
+
},
|
|
1840
|
+
end: {
|
|
1841
|
+
line: item.end.line - 1,
|
|
1842
|
+
character: item.end.column - 1 + (data.endOffset ?? 0)
|
|
1843
|
+
}
|
|
1844
|
+
});
|
|
1845
|
+
data.children = extractTokens(item);
|
|
1846
|
+
return data;
|
|
1847
|
+
});
|
|
1848
|
+
}
|
|
1440
1849
|
|
|
1441
1850
|
//#endregion
|
|
1442
1851
|
//#region packages/core/src/tokenizer/index.ts
|
|
1443
1852
|
function tokenize(source, debug = false) {
|
|
1444
|
-
const
|
|
1445
|
-
if (debug) console.log(
|
|
1446
|
-
return
|
|
1853
|
+
const result = root.parse(source);
|
|
1854
|
+
if (debug) console.log(printTree(result));
|
|
1855
|
+
return extractTokens(result);
|
|
1447
1856
|
}
|
|
1448
1857
|
|
|
1449
1858
|
//#endregion
|
|
@@ -1698,6 +2107,298 @@ else if (isOperator && !(node instanceof Token)) throw new Error(`Unexpected tok
|
|
|
1698
2107
|
return output.length === 1 ? output.first : output;
|
|
1699
2108
|
}
|
|
1700
2109
|
|
|
2110
|
+
//#endregion
|
|
2111
|
+
//#region packages/core/src/parser/pipes/query.pipe.ts
|
|
2112
|
+
const SYMBOLIC_OPS = new Set([
|
|
2113
|
+
"=",
|
|
2114
|
+
"!=",
|
|
2115
|
+
">",
|
|
2116
|
+
">=",
|
|
2117
|
+
"<",
|
|
2118
|
+
"<="
|
|
2119
|
+
]);
|
|
2120
|
+
const VALUE_KEYWORDS = new Set([
|
|
2121
|
+
"true",
|
|
2122
|
+
"false",
|
|
2123
|
+
"null",
|
|
2124
|
+
"undefined"
|
|
2125
|
+
]);
|
|
2126
|
+
function parseQueryExpression(children, messages, sourceToken) {
|
|
2127
|
+
if (children.length === 0) return undefined;
|
|
2128
|
+
const ni = new NodeIterator(children, messages);
|
|
2129
|
+
ni.move();
|
|
2130
|
+
const expr = parseOrExpr(ni, messages);
|
|
2131
|
+
if (!expr) return undefined;
|
|
2132
|
+
if (ni.$) messages.push({
|
|
2133
|
+
severity: 1,
|
|
2134
|
+
message: `Unexpected token in query expression: "${ni.$.text}"`,
|
|
2135
|
+
range: ni.$.getRange?.() ?? {
|
|
2136
|
+
start: {
|
|
2137
|
+
line: 0,
|
|
2138
|
+
character: 0
|
|
2139
|
+
},
|
|
2140
|
+
end: {
|
|
2141
|
+
line: 0,
|
|
2142
|
+
character: 0
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
});
|
|
2146
|
+
const node = new SemanticQueryNode();
|
|
2147
|
+
node.expression = expr;
|
|
2148
|
+
node.sourceToken = sourceToken;
|
|
2149
|
+
return node;
|
|
2150
|
+
}
|
|
2151
|
+
function parseOrExpr(ni, messages) {
|
|
2152
|
+
const left = parseAndExpr(ni, messages);
|
|
2153
|
+
if (!left) return undefined;
|
|
2154
|
+
const operands = [left];
|
|
2155
|
+
while (ni.$?.type === "identifier" && ni.$.text === "or") {
|
|
2156
|
+
ni.move();
|
|
2157
|
+
const right = parseAndExpr(ni, messages);
|
|
2158
|
+
if (!right) {
|
|
2159
|
+
pushError(ni, messages, "Expected expression after \"or\"");
|
|
2160
|
+
break;
|
|
2161
|
+
}
|
|
2162
|
+
operands.push(right);
|
|
2163
|
+
}
|
|
2164
|
+
if (operands.length === 1) return operands[0];
|
|
2165
|
+
const node = new SemanticQueryLogicalNode();
|
|
2166
|
+
node.operator = "or";
|
|
2167
|
+
node.operands = operands;
|
|
2168
|
+
return node;
|
|
2169
|
+
}
|
|
2170
|
+
function parseAndExpr(ni, messages) {
|
|
2171
|
+
const left = parseUnaryExpr(ni, messages);
|
|
2172
|
+
if (!left) return undefined;
|
|
2173
|
+
const operands = [left];
|
|
2174
|
+
while (ni.$?.type === "identifier" && ni.$.text === "and") {
|
|
2175
|
+
ni.move();
|
|
2176
|
+
const right = parseUnaryExpr(ni, messages);
|
|
2177
|
+
if (!right) {
|
|
2178
|
+
pushError(ni, messages, "Expected expression after \"and\"");
|
|
2179
|
+
break;
|
|
2180
|
+
}
|
|
2181
|
+
operands.push(right);
|
|
2182
|
+
}
|
|
2183
|
+
if (operands.length === 1) return operands[0];
|
|
2184
|
+
const node = new SemanticQueryLogicalNode();
|
|
2185
|
+
node.operator = "and";
|
|
2186
|
+
node.operands = operands;
|
|
2187
|
+
return node;
|
|
2188
|
+
}
|
|
2189
|
+
function parseUnaryExpr(ni, messages) {
|
|
2190
|
+
if (ni.$?.type === "identifier" && ni.$.text === "not") {
|
|
2191
|
+
ni.move();
|
|
2192
|
+
const operand = parseUnaryExpr(ni, messages);
|
|
2193
|
+
if (!operand) {
|
|
2194
|
+
pushError(ni, messages, "Expected expression after \"not\"");
|
|
2195
|
+
return undefined;
|
|
2196
|
+
}
|
|
2197
|
+
const node = new SemanticQueryLogicalNode();
|
|
2198
|
+
node.operator = "not";
|
|
2199
|
+
node.operands = [operand];
|
|
2200
|
+
return node;
|
|
2201
|
+
}
|
|
2202
|
+
if (ni.$?.type === "block" && ni.$.text === "(") {
|
|
2203
|
+
const blockChildren = ni.$.children || [];
|
|
2204
|
+
ni.move();
|
|
2205
|
+
if (blockChildren.length === 0) {
|
|
2206
|
+
pushError(ni, messages, "Empty parenthesized expression");
|
|
2207
|
+
return undefined;
|
|
2208
|
+
}
|
|
2209
|
+
const subNi = new NodeIterator(blockChildren, messages);
|
|
2210
|
+
subNi.move();
|
|
2211
|
+
const expr = parseOrExpr(subNi, messages);
|
|
2212
|
+
if (subNi.$) pushError(subNi, messages, `Unexpected token in parenthesized expression: "${subNi.$.text}"`);
|
|
2213
|
+
return expr;
|
|
2214
|
+
}
|
|
2215
|
+
return parseComparison(ni, messages);
|
|
2216
|
+
}
|
|
2217
|
+
function parseComparison(ni, messages) {
|
|
2218
|
+
const left = parseFieldRef(ni, messages);
|
|
2219
|
+
if (!left) return undefined;
|
|
2220
|
+
if (ni.$?.type === "punctuation" && SYMBOLIC_OPS.has(ni.$.text)) {
|
|
2221
|
+
const opText = ni.$.text;
|
|
2222
|
+
ni.move();
|
|
2223
|
+
const right = parseValueOrFieldRef(ni, messages);
|
|
2224
|
+
if (!right) {
|
|
2225
|
+
pushError(ni, messages, `Expected value or field reference after "${opText}"`);
|
|
2226
|
+
return undefined;
|
|
2227
|
+
}
|
|
2228
|
+
const node = new SemanticQueryComparisonNode();
|
|
2229
|
+
node.left = left;
|
|
2230
|
+
node.operator = opText;
|
|
2231
|
+
node.right = right;
|
|
2232
|
+
return node;
|
|
2233
|
+
}
|
|
2234
|
+
if (ni.$?.type === "identifier") {
|
|
2235
|
+
const opText = ni.$.text;
|
|
2236
|
+
if (opText === "in") {
|
|
2237
|
+
ni.move();
|
|
2238
|
+
const right = parseValueList(ni, messages);
|
|
2239
|
+
if (!right) return undefined;
|
|
2240
|
+
const node = new SemanticQueryComparisonNode();
|
|
2241
|
+
node.left = left;
|
|
2242
|
+
node.operator = "in";
|
|
2243
|
+
node.right = right;
|
|
2244
|
+
return node;
|
|
2245
|
+
}
|
|
2246
|
+
if (opText === "matches") {
|
|
2247
|
+
ni.move();
|
|
2248
|
+
const right = parseValueOrFieldRef(ni, messages);
|
|
2249
|
+
if (!right) {
|
|
2250
|
+
pushError(ni, messages, "Expected value after \"matches\"");
|
|
2251
|
+
return undefined;
|
|
2252
|
+
}
|
|
2253
|
+
const node = new SemanticQueryComparisonNode();
|
|
2254
|
+
node.left = left;
|
|
2255
|
+
node.operator = "matches";
|
|
2256
|
+
node.right = right;
|
|
2257
|
+
return node;
|
|
2258
|
+
}
|
|
2259
|
+
if (opText === "exists") {
|
|
2260
|
+
ni.move();
|
|
2261
|
+
const node = new SemanticQueryComparisonNode();
|
|
2262
|
+
node.left = left;
|
|
2263
|
+
node.operator = "exists";
|
|
2264
|
+
return node;
|
|
2265
|
+
}
|
|
2266
|
+
if (opText === "not") return parseNotComparison(ni, messages, left);
|
|
2267
|
+
pushError(ni, messages, `Unknown operator "${opText}"`);
|
|
2268
|
+
return undefined;
|
|
2269
|
+
}
|
|
2270
|
+
pushError(ni, messages, "Expected operator after field reference");
|
|
2271
|
+
return undefined;
|
|
2272
|
+
}
|
|
2273
|
+
function parseNotComparison(ni, messages, left) {
|
|
2274
|
+
ni.move();
|
|
2275
|
+
if (ni.$?.type === "identifier" && ni.$.text === "in") {
|
|
2276
|
+
ni.move();
|
|
2277
|
+
const right = parseValueList(ni, messages);
|
|
2278
|
+
if (!right) return undefined;
|
|
2279
|
+
const node = new SemanticQueryComparisonNode();
|
|
2280
|
+
node.left = left;
|
|
2281
|
+
node.operator = "not in";
|
|
2282
|
+
node.right = right;
|
|
2283
|
+
return node;
|
|
2284
|
+
}
|
|
2285
|
+
if (ni.$?.type === "identifier" && ni.$.text === "exists") {
|
|
2286
|
+
ni.move();
|
|
2287
|
+
const node = new SemanticQueryComparisonNode();
|
|
2288
|
+
node.left = left;
|
|
2289
|
+
node.operator = "not exists";
|
|
2290
|
+
return node;
|
|
2291
|
+
}
|
|
2292
|
+
pushError(ni, messages, "Expected \"in\" or \"exists\" after \"not\"");
|
|
2293
|
+
return undefined;
|
|
2294
|
+
}
|
|
2295
|
+
function parseFieldRef(ni, messages) {
|
|
2296
|
+
if (ni.$?.type !== "identifier") {
|
|
2297
|
+
pushError(ni, messages, "Expected field reference");
|
|
2298
|
+
return undefined;
|
|
2299
|
+
}
|
|
2300
|
+
const firstToken = new Token(ni.$);
|
|
2301
|
+
ni.move();
|
|
2302
|
+
if (ni.$?.type === "punctuation" && ni.$.text === ".") {
|
|
2303
|
+
ni.move();
|
|
2304
|
+
if (ni.$?.type === "identifier") {
|
|
2305
|
+
const secondToken = new Token(ni.$);
|
|
2306
|
+
ni.move();
|
|
2307
|
+
let fieldText = secondToken.text;
|
|
2308
|
+
while (ni.$?.type === "punctuation" && ni.$.text === ".") {
|
|
2309
|
+
ni.move();
|
|
2310
|
+
if (ni.$?.type === "identifier") {
|
|
2311
|
+
fieldText += `.${ni.$.text}`;
|
|
2312
|
+
ni.move();
|
|
2313
|
+
} else {
|
|
2314
|
+
pushError(ni, messages, "Expected identifier after \".\"");
|
|
2315
|
+
break;
|
|
2316
|
+
}
|
|
2317
|
+
}
|
|
2318
|
+
const node$2 = new SemanticQueryFieldRefNode();
|
|
2319
|
+
node$2.typeRef = firstToken;
|
|
2320
|
+
if (fieldText !== secondToken.text) node$2.fieldRef = secondToken.clone({ text: fieldText });
|
|
2321
|
+
else node$2.fieldRef = secondToken;
|
|
2322
|
+
return node$2;
|
|
2323
|
+
}
|
|
2324
|
+
pushError(ni, messages, "Expected identifier after \".\"");
|
|
2325
|
+
const node$1 = new SemanticQueryFieldRefNode();
|
|
2326
|
+
node$1.fieldRef = firstToken;
|
|
2327
|
+
return node$1;
|
|
2328
|
+
}
|
|
2329
|
+
const node = new SemanticQueryFieldRefNode();
|
|
2330
|
+
node.fieldRef = firstToken;
|
|
2331
|
+
return node;
|
|
2332
|
+
}
|
|
2333
|
+
function parseValueOrFieldRef(ni, messages) {
|
|
2334
|
+
if (!ni.$) return undefined;
|
|
2335
|
+
if (ni.$.type === "text" || ni.$.type === "number" || ni.$.type === "regexp") return parseValue(ni, messages);
|
|
2336
|
+
if (ni.$.type === "identifier") {
|
|
2337
|
+
if (VALUE_KEYWORDS.has(ni.$.text)) return parseValue(ni, messages);
|
|
2338
|
+
return parseFieldRef(ni, messages);
|
|
2339
|
+
}
|
|
2340
|
+
pushError(ni, messages, "Expected value or field reference");
|
|
2341
|
+
return undefined;
|
|
2342
|
+
}
|
|
2343
|
+
function parseValue(ni, messages) {
|
|
2344
|
+
if (!ni.$) {
|
|
2345
|
+
pushError(ni, messages, "Expected value");
|
|
2346
|
+
return undefined;
|
|
2347
|
+
}
|
|
2348
|
+
const token = ni.$;
|
|
2349
|
+
if (token.type === "text" || token.type === "number" || token.type === "regexp" || token.type === "identifier" && VALUE_KEYWORDS.has(token.text)) {
|
|
2350
|
+
const node = new SemanticQueryValueNode();
|
|
2351
|
+
node.valueToken = new Token(token);
|
|
2352
|
+
ni.move();
|
|
2353
|
+
return node;
|
|
2354
|
+
}
|
|
2355
|
+
pushError(ni, messages, `Unexpected token "${token.text}" where value expected`);
|
|
2356
|
+
return undefined;
|
|
2357
|
+
}
|
|
2358
|
+
function parseValueList(ni, messages) {
|
|
2359
|
+
if (ni.$?.type === "block" && ni.$.text === "(") {
|
|
2360
|
+
const blockChildren = ni.$.children || [];
|
|
2361
|
+
ni.move();
|
|
2362
|
+
const values = [];
|
|
2363
|
+
if (blockChildren.length === 0) {
|
|
2364
|
+
pushError(ni, messages, "Empty value list in \"in\" expression");
|
|
2365
|
+
return undefined;
|
|
2366
|
+
}
|
|
2367
|
+
const subNi = new NodeIterator(blockChildren, messages);
|
|
2368
|
+
subNi.move();
|
|
2369
|
+
const first = parseValue(subNi, messages);
|
|
2370
|
+
if (first) values.push(first);
|
|
2371
|
+
while (subNi.$?.type === "punctuation" && subNi.$.text === ",") {
|
|
2372
|
+
subNi.move();
|
|
2373
|
+
const v = parseValue(subNi, messages);
|
|
2374
|
+
if (v) values.push(v);
|
|
2375
|
+
}
|
|
2376
|
+
if (subNi.$) pushError(subNi, messages, `Unexpected token in value list: "${subNi.$.text}"`);
|
|
2377
|
+
const node = new SemanticQueryValueListNode();
|
|
2378
|
+
node.values = values;
|
|
2379
|
+
return node;
|
|
2380
|
+
}
|
|
2381
|
+
pushError(ni, messages, "Expected parenthesized value list after \"in\"");
|
|
2382
|
+
return undefined;
|
|
2383
|
+
}
|
|
2384
|
+
function pushError(ni, messages, message) {
|
|
2385
|
+
const range = ni.$?.getRange?.() ?? {
|
|
2386
|
+
start: {
|
|
2387
|
+
line: 0,
|
|
2388
|
+
character: 0
|
|
2389
|
+
},
|
|
2390
|
+
end: {
|
|
2391
|
+
line: 0,
|
|
2392
|
+
character: 0
|
|
2393
|
+
}
|
|
2394
|
+
};
|
|
2395
|
+
messages.push({
|
|
2396
|
+
severity: 1,
|
|
2397
|
+
message,
|
|
2398
|
+
range
|
|
2399
|
+
});
|
|
2400
|
+
}
|
|
2401
|
+
|
|
1701
2402
|
//#endregion
|
|
1702
2403
|
//#region packages/core/src/parser/pipes/special.pipe.ts
|
|
1703
2404
|
function refWithChain() {
|
|
@@ -1776,15 +2477,25 @@ else {
|
|
|
1776
2477
|
function annotations() {
|
|
1777
2478
|
const opts = {
|
|
1778
2479
|
annotation: { node: "annotation" },
|
|
1779
|
-
argument: [
|
|
1780
|
-
node: "
|
|
1781
|
-
|
|
1782
|
-
"
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
2480
|
+
argument: [
|
|
2481
|
+
{ node: ["number", "text"] },
|
|
2482
|
+
{
|
|
2483
|
+
node: "identifier",
|
|
2484
|
+
text: [
|
|
2485
|
+
"true",
|
|
2486
|
+
"false",
|
|
2487
|
+
"undefined",
|
|
2488
|
+
"null"
|
|
2489
|
+
]
|
|
2490
|
+
},
|
|
2491
|
+
{ node: "identifier" },
|
|
2492
|
+
{ node: "query" }
|
|
2493
|
+
],
|
|
2494
|
+
dot: {
|
|
2495
|
+
node: "punctuation",
|
|
2496
|
+
text: "."
|
|
2497
|
+
},
|
|
2498
|
+
ident: { node: "identifier" },
|
|
1788
2499
|
comma: {
|
|
1789
2500
|
node: "punctuation",
|
|
1790
2501
|
text: ","
|
|
@@ -1806,9 +2517,30 @@ function annotations() {
|
|
|
1806
2517
|
ni.move();
|
|
1807
2518
|
}
|
|
1808
2519
|
while (ni.satisfies(...opts.argument)) {
|
|
1809
|
-
|
|
2520
|
+
let argToken = new Token(ni.$);
|
|
1810
2521
|
ni.accepted();
|
|
1811
2522
|
ni.move();
|
|
2523
|
+
if (argToken.type === "identifier" && ![
|
|
2524
|
+
"true",
|
|
2525
|
+
"false",
|
|
2526
|
+
"undefined",
|
|
2527
|
+
"null"
|
|
2528
|
+
].includes(argToken.text)) {
|
|
2529
|
+
let chainText = argToken.text;
|
|
2530
|
+
while (ni.satisfies(opts.dot) && ni.next()?.satisfies(opts.ident)) {
|
|
2531
|
+
ni.accepted();
|
|
2532
|
+
ni.move();
|
|
2533
|
+
chainText += `.${ni.$.text}`;
|
|
2534
|
+
ni.accepted();
|
|
2535
|
+
ni.move();
|
|
2536
|
+
}
|
|
2537
|
+
if (chainText !== argToken.text) argToken = argToken.clone({ text: chainText });
|
|
2538
|
+
}
|
|
2539
|
+
if (argToken.type === "query") {
|
|
2540
|
+
const queryNode = parseQueryExpression(argToken.children, ni.messages, argToken);
|
|
2541
|
+
if (queryNode) argToken.queryNode = queryNode;
|
|
2542
|
+
}
|
|
2543
|
+
addArgument(argToken);
|
|
1812
2544
|
if (ni.satisfies(opts.comma)) {
|
|
1813
2545
|
ni.accepted();
|
|
1814
2546
|
ni.move();
|
|
@@ -2139,6 +2871,20 @@ var TSeverity = /*#__PURE__*/ function(TSeverity$1) {
|
|
|
2139
2871
|
return TSeverity$1;
|
|
2140
2872
|
}({});
|
|
2141
2873
|
|
|
2874
|
+
//#endregion
|
|
2875
|
+
//#region packages/core/src/parser/utils.ts
|
|
2876
|
+
function resolveAtscriptFromPath(from, id) {
|
|
2877
|
+
return `file://${path$1.join(id.slice(7).split("/").slice(0, -1).join("/"), from)}.as`;
|
|
2878
|
+
}
|
|
2879
|
+
function getRelPath(fromUri, toUri) {
|
|
2880
|
+
const fromPath = new URL(fromUri).pathname;
|
|
2881
|
+
const toPath = new URL(toUri).pathname;
|
|
2882
|
+
const relPath = path$1.relative(path$1.dirname(fromPath), toPath);
|
|
2883
|
+
const { dir, name } = path$1.parse(relPath);
|
|
2884
|
+
const prefix = dir.startsWith("..") ? "" : "./";
|
|
2885
|
+
return `${prefix}${dir ? `${dir}/` : ""}${name}`;
|
|
2886
|
+
}
|
|
2887
|
+
|
|
2142
2888
|
//#endregion
|
|
2143
2889
|
//#region packages/core/src/token-index/blocks-index.ts
|
|
2144
2890
|
function _define_property$5(obj, key, value) {
|
|
@@ -2261,7 +3007,11 @@ var TokensIndex = class {
|
|
|
2261
3007
|
*/ at(line, character) {
|
|
2262
3008
|
const tokens$1 = this.tokensMap[line];
|
|
2263
3009
|
if (!tokens$1) return undefined;
|
|
2264
|
-
|
|
3010
|
+
let best;
|
|
3011
|
+
for (const t of tokens$1) if (t.range.start.character <= character && t.range.end.character >= character) {
|
|
3012
|
+
if (!best || t.range.start.character > best.range.start.character || t.range.start.character === best.range.start.character && t.range.end.character < best.range.end.character) best = t;
|
|
3013
|
+
}
|
|
3014
|
+
return best;
|
|
2265
3015
|
}
|
|
2266
3016
|
/**
|
|
2267
3017
|
* Retrieves either the token at the specified (line, character), or if none exists,
|
|
@@ -2363,6 +3113,7 @@ var AtscriptDoc = class {
|
|
|
2363
3113
|
this.importedDefs.clear();
|
|
2364
3114
|
this.messages = [];
|
|
2365
3115
|
this.referred = [];
|
|
3116
|
+
this.queryFieldRefs = [];
|
|
2366
3117
|
this.imports.clear();
|
|
2367
3118
|
this._allMessages = undefined;
|
|
2368
3119
|
this.tokensIndex = new TokensIndex();
|
|
@@ -2391,6 +3142,23 @@ var AtscriptDoc = class {
|
|
|
2391
3142
|
this.registerMessages(annotationSpec.validate(mainToken, args || [], this));
|
|
2392
3143
|
annotationSpec.modify(mainToken, args || [], this);
|
|
2393
3144
|
this.resolvedAnnotations.push(mainToken);
|
|
3145
|
+
const specArgs = annotationSpec.arguments;
|
|
3146
|
+
for (let i = 0; i < (args?.length ?? 0); i++) {
|
|
3147
|
+
const argSpec = specArgs[i];
|
|
3148
|
+
if (argSpec?.type === "ref" && args?.[i]) {
|
|
3149
|
+
const refToken = args[i];
|
|
3150
|
+
const dotIdx = refToken.text.indexOf(".");
|
|
3151
|
+
if (dotIdx > 0) {
|
|
3152
|
+
const typeToken = refToken.clone({ text: refToken.text.slice(0, dotIdx) });
|
|
3153
|
+
typeToken.isReference = true;
|
|
3154
|
+
this.referred.push(typeToken);
|
|
3155
|
+
} else {
|
|
3156
|
+
refToken.isReference = true;
|
|
3157
|
+
this.referred.push(refToken);
|
|
3158
|
+
}
|
|
3159
|
+
}
|
|
3160
|
+
if (argSpec?.type === "query" && args?.[i]?.queryNode) args[i].queryNode.registerAtDocument(this);
|
|
3161
|
+
}
|
|
2394
3162
|
} else {
|
|
2395
3163
|
let severity = 0;
|
|
2396
3164
|
switch (this.config.unknownAnnotation) {
|
|
@@ -2598,6 +3366,17 @@ else {
|
|
|
2598
3366
|
});
|
|
2599
3367
|
}
|
|
2600
3368
|
}
|
|
3369
|
+
for (const qfr of doc.queryFieldRefs) {
|
|
3370
|
+
if (!qfr.queryArgToken || qfr.fieldRef.text !== propName$1) continue;
|
|
3371
|
+
const scope = getQueryScope(qfr.queryArgToken, doc);
|
|
3372
|
+
if (!scope) continue;
|
|
3373
|
+
const resolvedTypeName = qfr.typeRef?.text ?? scope.unqualifiedTarget;
|
|
3374
|
+
if (resolvedTypeName === parentName) refs.push({
|
|
3375
|
+
uri,
|
|
3376
|
+
range: qfr.fieldRef.range,
|
|
3377
|
+
token: qfr.fieldRef
|
|
3378
|
+
});
|
|
3379
|
+
}
|
|
2601
3380
|
};
|
|
2602
3381
|
searchDoc(this, this.id);
|
|
2603
3382
|
const parentDefToken = this.registry.definitions.get(parentName);
|
|
@@ -2609,7 +3388,23 @@ else {
|
|
|
2609
3388
|
}
|
|
2610
3389
|
}
|
|
2611
3390
|
return refs;
|
|
2612
|
-
}
|
|
3391
|
+
}
|
|
3392
|
+
if (isQueryFieldRef(token.parentNode) && token === token.parentNode.fieldRef) {
|
|
3393
|
+
const fieldRefNode = token.parentNode;
|
|
3394
|
+
const queryArgToken = fieldRefNode.queryArgToken;
|
|
3395
|
+
if (queryArgToken) {
|
|
3396
|
+
const scope = getQueryScope(queryArgToken, this);
|
|
3397
|
+
if (scope) {
|
|
3398
|
+
const resolved = resolveQueryFieldRef(fieldRefNode, this, scope);
|
|
3399
|
+
if (resolved?.prop) {
|
|
3400
|
+
const propToken = resolved.prop.token("identifier");
|
|
3401
|
+
if (propToken) return resolved.doc.usageListFor(propToken);
|
|
3402
|
+
}
|
|
3403
|
+
}
|
|
3404
|
+
}
|
|
3405
|
+
return undefined;
|
|
3406
|
+
}
|
|
3407
|
+
{
|
|
2613
3408
|
const defForToken = this.getDefinitionFor(token);
|
|
2614
3409
|
if (defForToken?.token?.isDefinition && defForToken.doc) return defForToken.doc.usageListFor(defForToken.token);
|
|
2615
3410
|
}
|
|
@@ -2683,6 +3478,37 @@ else {
|
|
|
2683
3478
|
}];
|
|
2684
3479
|
return undefined;
|
|
2685
3480
|
}
|
|
3481
|
+
if (isQueryFieldRef(token.parentNode)) {
|
|
3482
|
+
const fieldRefNode = token.parentNode;
|
|
3483
|
+
const queryArgToken = fieldRefNode.queryArgToken;
|
|
3484
|
+
if (queryArgToken) {
|
|
3485
|
+
const scope = getQueryScope(queryArgToken, this);
|
|
3486
|
+
if (scope) {
|
|
3487
|
+
if (token === fieldRefNode.typeRef) {
|
|
3488
|
+
const result = this.getDefinitionFor(token);
|
|
3489
|
+
return result ? [{
|
|
3490
|
+
targetUri: result.uri,
|
|
3491
|
+
targetRange: result.token?.range ?? zeroRange,
|
|
3492
|
+
targetSelectionRange: result.token?.range ?? zeroRange,
|
|
3493
|
+
originSelectionRange: token.range
|
|
3494
|
+
}] : undefined;
|
|
3495
|
+
}
|
|
3496
|
+
if (token === fieldRefNode.fieldRef) {
|
|
3497
|
+
const resolved = resolveQueryFieldRef(fieldRefNode, this, scope);
|
|
3498
|
+
if (resolved?.prop) {
|
|
3499
|
+
const propToken = resolved.prop.token("identifier");
|
|
3500
|
+
return [{
|
|
3501
|
+
targetUri: resolved.targetUri,
|
|
3502
|
+
targetRange: propToken?.range ?? zeroRange,
|
|
3503
|
+
targetSelectionRange: propToken?.range ?? zeroRange,
|
|
3504
|
+
originSelectionRange: token.range
|
|
3505
|
+
}];
|
|
3506
|
+
}
|
|
3507
|
+
}
|
|
3508
|
+
}
|
|
3509
|
+
}
|
|
3510
|
+
return undefined;
|
|
3511
|
+
}
|
|
2686
3512
|
if (isProp(token.parentNode)) return [{
|
|
2687
3513
|
targetUri: this.id,
|
|
2688
3514
|
targetRange: token.range,
|
|
@@ -3139,6 +3965,9 @@ else {
|
|
|
3139
3965
|
* List of tokens that refer to some type or interface
|
|
3140
3966
|
*/ _define_property$3(this, "referred", void 0);
|
|
3141
3967
|
/**
|
|
3968
|
+
* List of query field ref nodes (for find-references support)
|
|
3969
|
+
*/ _define_property$3(this, "queryFieldRefs", void 0);
|
|
3970
|
+
/**
|
|
3142
3971
|
* Map of dependencies (documents) by URI
|
|
3143
3972
|
*/ _define_property$3(this, "dependenciesMap", void 0);
|
|
3144
3973
|
_define_property$3(this, "nodes", void 0);
|
|
@@ -3160,6 +3989,7 @@ else {
|
|
|
3160
3989
|
this.dependencies = new Set();
|
|
3161
3990
|
this.dependants = new Set();
|
|
3162
3991
|
this.referred = [];
|
|
3992
|
+
this.queryFieldRefs = [];
|
|
3163
3993
|
this.dependenciesMap = new Map();
|
|
3164
3994
|
this.nodes = [];
|
|
3165
3995
|
this._text = "";
|
|
@@ -3192,6 +4022,42 @@ function createSyntheticRef(name) {
|
|
|
3192
4022
|
|
|
3193
4023
|
//#endregion
|
|
3194
4024
|
//#region packages/core/src/defaults/db-utils.ts
|
|
4025
|
+
function validateRefArgument(token, doc, options) {
|
|
4026
|
+
const messages = [];
|
|
4027
|
+
const text$2 = token.text;
|
|
4028
|
+
const [typeName, ...chain] = text$2.split(".");
|
|
4029
|
+
const decl = doc.getDeclarationOwnerNode(typeName);
|
|
4030
|
+
if (!decl) {
|
|
4031
|
+
const regDef = doc.registry.definitions.get(typeName);
|
|
4032
|
+
if (regDef?.imported) return messages;
|
|
4033
|
+
messages.push({
|
|
4034
|
+
severity: 1,
|
|
4035
|
+
message: `Unknown type '${typeName}'.`,
|
|
4036
|
+
range: token.range
|
|
4037
|
+
});
|
|
4038
|
+
return messages;
|
|
4039
|
+
}
|
|
4040
|
+
if (chain.length > 0) {
|
|
4041
|
+
const unwound = doc.unwindType(typeName, chain);
|
|
4042
|
+
if (!unwound) {
|
|
4043
|
+
messages.push({
|
|
4044
|
+
severity: 1,
|
|
4045
|
+
message: `Field '${chain.join(".")}' does not exist on type '${typeName}'.`,
|
|
4046
|
+
range: token.range
|
|
4047
|
+
});
|
|
4048
|
+
return messages;
|
|
4049
|
+
}
|
|
4050
|
+
}
|
|
4051
|
+
if (options?.requireDbTable && decl.node) {
|
|
4052
|
+
const hasDbTable = decl.node.countAnnotations("db.table") > 0;
|
|
4053
|
+
if (!hasDbTable) messages.push({
|
|
4054
|
+
severity: 1,
|
|
4055
|
+
message: `Type '${typeName}' must have @db.table annotation.`,
|
|
4056
|
+
range: token.range
|
|
4057
|
+
});
|
|
4058
|
+
}
|
|
4059
|
+
return messages;
|
|
4060
|
+
}
|
|
3195
4061
|
function findFKFieldsPointingTo(doc, iface, targetTypeName, alias) {
|
|
3196
4062
|
const results = [];
|
|
3197
4063
|
let struct;
|
|
@@ -3226,6 +4092,58 @@ function findFKFieldsPointingTo(doc, iface, targetTypeName, alias) {
|
|
|
3226
4092
|
}
|
|
3227
4093
|
return results;
|
|
3228
4094
|
}
|
|
4095
|
+
const viewAnnotationNames = [
|
|
4096
|
+
"db.view",
|
|
4097
|
+
"db.view.for",
|
|
4098
|
+
"db.view.joins",
|
|
4099
|
+
"db.view.filter",
|
|
4100
|
+
"db.view.materialized"
|
|
4101
|
+
];
|
|
4102
|
+
function hasAnyViewAnnotation(node) {
|
|
4103
|
+
return viewAnnotationNames.some((name) => node.countAnnotations(name) > 0);
|
|
4104
|
+
}
|
|
4105
|
+
function validateQueryScope(queryToken, allowedTypes, unqualifiedTarget, doc) {
|
|
4106
|
+
const errors = [];
|
|
4107
|
+
const queryNode = queryToken.queryNode;
|
|
4108
|
+
if (!queryNode) return errors;
|
|
4109
|
+
function walkFieldRef(ref$1) {
|
|
4110
|
+
if (ref$1.typeRef) {
|
|
4111
|
+
const typeName = ref$1.typeRef.text;
|
|
4112
|
+
if (!allowedTypes.includes(typeName)) errors.push({
|
|
4113
|
+
message: `Query references '${typeName}' which is not in scope — expected ${allowedTypes.map((t) => `'${t}'`).join(" or ")}`,
|
|
4114
|
+
severity: 1,
|
|
4115
|
+
range: ref$1.typeRef.range
|
|
4116
|
+
});
|
|
4117
|
+
} else if (unqualifiedTarget === null) errors.push({
|
|
4118
|
+
message: `Unqualified field reference '${ref$1.fieldRef.text}' — use qualified form (e.g., Type.${ref$1.fieldRef.text})`,
|
|
4119
|
+
severity: 1,
|
|
4120
|
+
range: ref$1.fieldRef.range
|
|
4121
|
+
});
|
|
4122
|
+
else {
|
|
4123
|
+
const unwound = doc.unwindType(unqualifiedTarget);
|
|
4124
|
+
if (unwound) {
|
|
4125
|
+
const targetDef = unwound.def;
|
|
4126
|
+
if (isInterface(targetDef) || isStructure(targetDef)) {
|
|
4127
|
+
const struct = isInterface(targetDef) ? targetDef.getDefinition() : targetDef;
|
|
4128
|
+
if (struct && isStructure(struct) && !struct.props.has(ref$1.fieldRef.text)) errors.push({
|
|
4129
|
+
message: `Field '${ref$1.fieldRef.text}' does not exist on '${unqualifiedTarget}'`,
|
|
4130
|
+
severity: 1,
|
|
4131
|
+
range: ref$1.fieldRef.range
|
|
4132
|
+
});
|
|
4133
|
+
}
|
|
4134
|
+
}
|
|
4135
|
+
}
|
|
4136
|
+
}
|
|
4137
|
+
function walkExpr(expr) {
|
|
4138
|
+
if (isQueryLogical(expr)) for (const operand of expr.operands) walkExpr(operand);
|
|
4139
|
+
else if (isQueryComparison(expr)) {
|
|
4140
|
+
walkFieldRef(expr.left);
|
|
4141
|
+
if (expr.right && "fieldRef" in expr.right) walkFieldRef(expr.right);
|
|
4142
|
+
}
|
|
4143
|
+
}
|
|
4144
|
+
walkExpr(queryNode.expression);
|
|
4145
|
+
return errors;
|
|
4146
|
+
}
|
|
3229
4147
|
|
|
3230
4148
|
//#endregion
|
|
3231
4149
|
//#region packages/core/src/defaults/db-annotations.ts
|
|
@@ -3304,7 +4222,7 @@ function findFKFieldsPointingTo(doc, iface, targetTypeName, alias) {
|
|
|
3304
4222
|
severity: 1,
|
|
3305
4223
|
range: token.range
|
|
3306
4224
|
});
|
|
3307
|
-
if (action === "setDefault" && field.countAnnotations("db.default
|
|
4225
|
+
if (action === "setDefault" && field.countAnnotations("db.default") === 0 && field.countAnnotations("db.default.fn") === 0) errors.push({
|
|
3308
4226
|
message: `@db.rel.${name} "setDefault" but no @db.default.* annotation — field will have no fallback value`,
|
|
3309
4227
|
severity: 2,
|
|
3310
4228
|
range: token.range
|
|
@@ -3362,16 +4280,47 @@ const dbAnnotations = {
|
|
|
3362
4280
|
return errors;
|
|
3363
4281
|
}
|
|
3364
4282
|
}) },
|
|
3365
|
-
table:
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
4283
|
+
table: {
|
|
4284
|
+
$self: new AnnotationSpec({
|
|
4285
|
+
description: "Marks an interface as a database-persisted entity (table in SQL, collection in MongoDB). If the name argument is omitted, the adapter derives the table name from the interface name.\n\n**Example:**\n```atscript\n@db.table \"users\"\nexport interface User { ... }\n```\n",
|
|
4286
|
+
nodeType: ["interface"],
|
|
4287
|
+
argument: {
|
|
4288
|
+
optional: true,
|
|
4289
|
+
name: "name",
|
|
4290
|
+
type: "string",
|
|
4291
|
+
description: "Table/collection name. If omitted, derived from interface name."
|
|
4292
|
+
},
|
|
4293
|
+
validate(token, _args, _doc) {
|
|
4294
|
+
const errors = [];
|
|
4295
|
+
const owner = token.parentNode;
|
|
4296
|
+
if (hasAnyViewAnnotation(owner)) errors.push({
|
|
4297
|
+
message: "An interface cannot be both a @db.table and a @db.view",
|
|
4298
|
+
severity: 1,
|
|
4299
|
+
range: token.range
|
|
4300
|
+
});
|
|
4301
|
+
return errors;
|
|
4302
|
+
}
|
|
4303
|
+
}),
|
|
4304
|
+
renamed: new AnnotationSpec({
|
|
4305
|
+
description: "Specifies the previous table name for table rename migration. The sync engine generates ALTER TABLE RENAME instead of drop+create.\n\n**Example:**\n```atscript\n@db.table \"app_users\"\n@db.table.renamed \"users\"\nexport interface User { ... }\n```\n",
|
|
4306
|
+
nodeType: ["interface"],
|
|
4307
|
+
argument: {
|
|
4308
|
+
name: "oldName",
|
|
4309
|
+
type: "string",
|
|
4310
|
+
description: "The previous table/collection name."
|
|
4311
|
+
},
|
|
4312
|
+
validate(token, _args, _doc) {
|
|
4313
|
+
const errors = [];
|
|
4314
|
+
const owner = token.parentNode;
|
|
4315
|
+
if (owner.countAnnotations("db.table") === 0) errors.push({
|
|
4316
|
+
message: "@db.table.renamed requires @db.table on the same interface",
|
|
4317
|
+
severity: 1,
|
|
4318
|
+
range: token.range
|
|
4319
|
+
});
|
|
4320
|
+
return errors;
|
|
4321
|
+
}
|
|
4322
|
+
})
|
|
4323
|
+
},
|
|
3375
4324
|
schema: new AnnotationSpec({
|
|
3376
4325
|
description: "Assigns the entity to a database schema/namespace.\n\n**Example:**\n```atscript\n@db.table \"users\"\n@db.schema \"auth\"\nexport interface User { ... }\n```\n",
|
|
3377
4326
|
nodeType: ["interface"],
|
|
@@ -3430,18 +4379,29 @@ const dbAnnotations = {
|
|
|
3430
4379
|
}]
|
|
3431
4380
|
})
|
|
3432
4381
|
},
|
|
3433
|
-
column:
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
4382
|
+
column: {
|
|
4383
|
+
$self: new AnnotationSpec({
|
|
4384
|
+
description: "Overrides the physical column name in the database. For nested (flattened) fields, the parent prefix is still prepended automatically.\n\n**Example:**\n```atscript\n@db.column \"first_name\"\nfirstName: string\n// → physical column: first_name\n\n// Nested:\naddress: {\n @db.column \"zip_code\"\n zip: string\n}\n// → physical column: address__zip_code\n```\n",
|
|
4385
|
+
nodeType: ["prop"],
|
|
4386
|
+
argument: {
|
|
4387
|
+
name: "name",
|
|
4388
|
+
type: "string",
|
|
4389
|
+
description: "The column/field name (without parent prefix for nested fields)."
|
|
4390
|
+
}
|
|
4391
|
+
}),
|
|
4392
|
+
renamed: new AnnotationSpec({
|
|
4393
|
+
description: "Specifies the previous local field name for column rename migration. The sync engine generates ALTER TABLE RENAME COLUMN instead of drop+add.\n\n**Example:**\n```atscript\n@db.column.renamed \"zip\"\npostalCode: string\n// Renames address__zip → address__postalCode\n```\n",
|
|
4394
|
+
nodeType: ["prop"],
|
|
4395
|
+
argument: {
|
|
4396
|
+
name: "oldName",
|
|
4397
|
+
type: "string",
|
|
4398
|
+
description: "The old local field name (parent prefix is reconstructed automatically)."
|
|
4399
|
+
}
|
|
4400
|
+
})
|
|
4401
|
+
},
|
|
3442
4402
|
default: {
|
|
3443
|
-
|
|
3444
|
-
description: "Sets a static DB-level default value (used in DDL DEFAULT clause). For string fields the value is used as-is; for other types it is parsed as JSON.\n\n**Example:**\n```atscript\n@db.default
|
|
4403
|
+
$self: new AnnotationSpec({
|
|
4404
|
+
description: "Sets a static DB-level default value (used in DDL DEFAULT clause). For string fields the value is used as-is; for other types it is parsed as JSON.\n\n**Example:**\n```atscript\n@db.default \"active\"\nstatus: string\n```\n",
|
|
3445
4405
|
nodeType: ["prop"],
|
|
3446
4406
|
argument: {
|
|
3447
4407
|
name: "value",
|
|
@@ -3536,6 +4496,16 @@ else if (fnName === "now" && !["number", "string"].includes(baseType)) errors.pu
|
|
|
3536
4496
|
return errors;
|
|
3537
4497
|
}
|
|
3538
4498
|
}),
|
|
4499
|
+
sync: { method: new AnnotationSpec({
|
|
4500
|
+
description: "Controls how the sync engine handles structural changes that cannot be applied via ALTER TABLE.\n\n- `\"recreate\"` — lossless: create temp table, copy data, drop old, rename.\n- `\"drop\"` — lossy: drop table entirely and create from scratch.\n\nWithout this annotation, structural changes fail with an error requiring manual intervention.\n\n**Example:**\n```atscript\n@db.sync.method \"drop\"\ninterface Logs { ... }\n```\n",
|
|
4501
|
+
nodeType: ["interface"],
|
|
4502
|
+
argument: {
|
|
4503
|
+
name: "method",
|
|
4504
|
+
type: "string",
|
|
4505
|
+
description: "Sync method: \"drop\" (lossy) or \"recreate\" (lossless with data copy).",
|
|
4506
|
+
values: ["drop", "recreate"]
|
|
4507
|
+
}
|
|
4508
|
+
}) },
|
|
3539
4509
|
rel: {
|
|
3540
4510
|
FK: new AnnotationSpec({
|
|
3541
4511
|
description: "Declares a foreign key constraint on this field. The field must use a chain reference type (e.g., `User.id`) to specify the FK target.\n\n**Example:**\n```atscript\n@db.rel.FK\nauthorId: User.id\n\n// With alias (required when multiple FKs point to the same type)\n@db.rel.FK \"author\"\nauthorId: User.id\n```\n",
|
|
@@ -3804,7 +4774,258 @@ else if (matches.length > 1) errors.push({
|
|
|
3804
4774
|
}
|
|
3805
4775
|
}),
|
|
3806
4776
|
onDelete: refActionAnnotation("onDelete"),
|
|
3807
|
-
onUpdate: refActionAnnotation("onUpdate")
|
|
4777
|
+
onUpdate: refActionAnnotation("onUpdate"),
|
|
4778
|
+
via: new AnnotationSpec({
|
|
4779
|
+
description: "Declares a many-to-many navigational property through an explicit junction table. `@db.rel.via` is self-sufficient — no `@db.rel.from` pairing is needed.\n\n**Example:**\n```atscript\n@db.rel.via PostTag\ntags: Tag[]\n```\n",
|
|
4780
|
+
nodeType: ["prop"],
|
|
4781
|
+
argument: {
|
|
4782
|
+
name: "junction",
|
|
4783
|
+
type: "ref",
|
|
4784
|
+
description: "The junction table type (must have @db.table and @db.rel.FK fields pointing to both sides)."
|
|
4785
|
+
},
|
|
4786
|
+
validate(token, args, doc) {
|
|
4787
|
+
const errors = [];
|
|
4788
|
+
const field = token.parentNode;
|
|
4789
|
+
if (field.countAnnotations("db.rel.to") > 0 || field.countAnnotations("db.rel.from") > 0) errors.push({
|
|
4790
|
+
message: "@db.rel.via is self-sufficient — cannot be combined with @db.rel.to or @db.rel.from",
|
|
4791
|
+
severity: 1,
|
|
4792
|
+
range: token.range
|
|
4793
|
+
});
|
|
4794
|
+
const definition$1 = field.getDefinition();
|
|
4795
|
+
if (!isArray(definition$1)) errors.push({
|
|
4796
|
+
message: "@db.rel.via requires an array type (e.g. Tag[])",
|
|
4797
|
+
severity: 1,
|
|
4798
|
+
range: token.range
|
|
4799
|
+
});
|
|
4800
|
+
if (!args[0]) return errors;
|
|
4801
|
+
const junctionName = args[0].text;
|
|
4802
|
+
errors.push(...validateRefArgument(args[0], doc, { requireDbTable: true }));
|
|
4803
|
+
if (errors.length > 0) return errors;
|
|
4804
|
+
const junctionUnwound = doc.unwindType(junctionName);
|
|
4805
|
+
if (!junctionUnwound) return errors;
|
|
4806
|
+
const junctionDef = junctionUnwound.def;
|
|
4807
|
+
if (!isInterface(junctionDef)) return errors;
|
|
4808
|
+
const thisTypeName = getParentTypeName(token);
|
|
4809
|
+
const targetTypeName = getNavTargetTypeName(field);
|
|
4810
|
+
if (!thisTypeName || !targetTypeName) return errors;
|
|
4811
|
+
const fksToThis = findFKFieldsPointingTo(junctionUnwound.doc, junctionDef, thisTypeName);
|
|
4812
|
+
if (fksToThis.length === 0) errors.push({
|
|
4813
|
+
message: `Junction '${junctionName}' has no @db.rel.FK pointing to '${thisTypeName}'`,
|
|
4814
|
+
severity: 1,
|
|
4815
|
+
range: args[0].range
|
|
4816
|
+
});
|
|
4817
|
+
else if (fksToThis.length > 1) errors.push({
|
|
4818
|
+
message: `Junction '${junctionName}' has multiple @db.rel.FK pointing to '${thisTypeName}' — not supported`,
|
|
4819
|
+
severity: 1,
|
|
4820
|
+
range: args[0].range
|
|
4821
|
+
});
|
|
4822
|
+
if (targetTypeName !== thisTypeName) {
|
|
4823
|
+
const fksToTarget = findFKFieldsPointingTo(junctionUnwound.doc, junctionDef, targetTypeName);
|
|
4824
|
+
if (fksToTarget.length === 0) errors.push({
|
|
4825
|
+
message: `Junction '${junctionName}' has no @db.rel.FK pointing to '${targetTypeName}'`,
|
|
4826
|
+
severity: 1,
|
|
4827
|
+
range: args[0].range
|
|
4828
|
+
});
|
|
4829
|
+
else if (fksToTarget.length > 1) errors.push({
|
|
4830
|
+
message: `Junction '${junctionName}' has multiple @db.rel.FK pointing to '${targetTypeName}' — not supported`,
|
|
4831
|
+
severity: 1,
|
|
4832
|
+
range: args[0].range
|
|
4833
|
+
});
|
|
4834
|
+
}
|
|
4835
|
+
return errors;
|
|
4836
|
+
}
|
|
4837
|
+
}),
|
|
4838
|
+
filter: new AnnotationSpec({
|
|
4839
|
+
description: "Applies a filter to a navigational property, restricting which related records are loaded.\n\n**Example:**\n```atscript\n@db.rel.from\n@db.rel.filter `Post.published = true`\npublishedPosts: Post[]\n```\n",
|
|
4840
|
+
nodeType: ["prop"],
|
|
4841
|
+
argument: {
|
|
4842
|
+
name: "condition",
|
|
4843
|
+
type: "query",
|
|
4844
|
+
description: "Filter expression restricting which related records are loaded."
|
|
4845
|
+
},
|
|
4846
|
+
validate(token, args, doc) {
|
|
4847
|
+
const errors = [];
|
|
4848
|
+
const field = token.parentNode;
|
|
4849
|
+
const hasTo = field.countAnnotations("db.rel.to") > 0;
|
|
4850
|
+
const hasFrom = field.countAnnotations("db.rel.from") > 0;
|
|
4851
|
+
const hasVia = field.countAnnotations("db.rel.via") > 0;
|
|
4852
|
+
if (!hasTo && !hasFrom && !hasVia) {
|
|
4853
|
+
errors.push({
|
|
4854
|
+
message: "@db.rel.filter is only valid on navigational fields (@db.rel.to, @db.rel.from, or @db.rel.via)",
|
|
4855
|
+
severity: 1,
|
|
4856
|
+
range: token.range
|
|
4857
|
+
});
|
|
4858
|
+
return errors;
|
|
4859
|
+
}
|
|
4860
|
+
if (!args[0]?.queryNode) return errors;
|
|
4861
|
+
const targetTypeName = getNavTargetTypeName(field);
|
|
4862
|
+
if (!targetTypeName) return errors;
|
|
4863
|
+
const allowedTypes = [targetTypeName];
|
|
4864
|
+
if (hasVia) {
|
|
4865
|
+
const viaAnnotations = field.annotations?.filter((a) => a.name === "db.rel.via");
|
|
4866
|
+
if (viaAnnotations?.[0]?.args[0]) allowedTypes.push(viaAnnotations[0].args[0].text);
|
|
4867
|
+
}
|
|
4868
|
+
errors.push(...validateQueryScope(args[0], allowedTypes, targetTypeName, doc));
|
|
4869
|
+
return errors;
|
|
4870
|
+
}
|
|
4871
|
+
})
|
|
4872
|
+
},
|
|
4873
|
+
view: {
|
|
4874
|
+
$self: new AnnotationSpec({
|
|
4875
|
+
description: "Marks an interface as a **database view**. Optionally takes a view name argument.\n\n**Example:**\n```atscript\n@db.view \"active_premium_users\"\n@db.view.for User\nexport interface ActivePremiumUser { ... }\n```\n",
|
|
4876
|
+
nodeType: ["interface"],
|
|
4877
|
+
argument: {
|
|
4878
|
+
optional: true,
|
|
4879
|
+
name: "name",
|
|
4880
|
+
type: "string",
|
|
4881
|
+
description: "The view name in the database. If omitted, derived from the interface name."
|
|
4882
|
+
},
|
|
4883
|
+
validate(token, _args, _doc) {
|
|
4884
|
+
const errors = [];
|
|
4885
|
+
const owner = token.parentNode;
|
|
4886
|
+
if (owner.countAnnotations("db.table") > 0) errors.push({
|
|
4887
|
+
message: "An interface cannot be both a @db.table and a @db.view",
|
|
4888
|
+
severity: 1,
|
|
4889
|
+
range: token.range
|
|
4890
|
+
});
|
|
4891
|
+
return errors;
|
|
4892
|
+
}
|
|
4893
|
+
}),
|
|
4894
|
+
for: new AnnotationSpec({
|
|
4895
|
+
description: "Specifies the entry/primary table for a computed view. Required for views that map fields via chain refs.\n\n**Example:**\n```atscript\n@db.view.for Order\n@db.view.filter `Order.status = 'active'`\nexport interface ActiveOrderDetails { ... }\n```\n",
|
|
4896
|
+
nodeType: ["interface"],
|
|
4897
|
+
argument: {
|
|
4898
|
+
name: "entry",
|
|
4899
|
+
type: "ref",
|
|
4900
|
+
description: "The primary/entry table type (must have @db.table)."
|
|
4901
|
+
},
|
|
4902
|
+
validate(token, args, doc) {
|
|
4903
|
+
const errors = [];
|
|
4904
|
+
const owner = token.parentNode;
|
|
4905
|
+
if (owner.countAnnotations("db.table") > 0) errors.push({
|
|
4906
|
+
message: "An interface cannot be both a @db.table and a @db.view",
|
|
4907
|
+
severity: 1,
|
|
4908
|
+
range: token.range
|
|
4909
|
+
});
|
|
4910
|
+
if (args[0]) errors.push(...validateRefArgument(args[0], doc, { requireDbTable: true }));
|
|
4911
|
+
return errors;
|
|
4912
|
+
}
|
|
4913
|
+
}),
|
|
4914
|
+
joins: new AnnotationSpec({
|
|
4915
|
+
description: "Declares an explicit join for a view. Use when no `@db.rel.*` path exists between the entry table and the target.\n\n**Example:**\n```atscript\n@db.view.for Order\n@db.view.joins Warehouse, `Warehouse.regionId = Order.regionId`\nexport interface OrderWarehouse { ... }\n```\n",
|
|
4916
|
+
nodeType: ["interface"],
|
|
4917
|
+
multiple: true,
|
|
4918
|
+
mergeStrategy: "append",
|
|
4919
|
+
argument: [{
|
|
4920
|
+
name: "target",
|
|
4921
|
+
type: "ref",
|
|
4922
|
+
description: "The table type to join (must have @db.table)."
|
|
4923
|
+
}, {
|
|
4924
|
+
name: "condition",
|
|
4925
|
+
type: "query",
|
|
4926
|
+
description: "Join condition expression."
|
|
4927
|
+
}],
|
|
4928
|
+
validate(token, args, doc) {
|
|
4929
|
+
const errors = [];
|
|
4930
|
+
const owner = token.parentNode;
|
|
4931
|
+
if (!hasAnyViewAnnotation(owner) && !args[0]) {
|
|
4932
|
+
errors.push({
|
|
4933
|
+
message: "@db.view.joins is only valid on @db.view interfaces",
|
|
4934
|
+
severity: 1,
|
|
4935
|
+
range: token.range
|
|
4936
|
+
});
|
|
4937
|
+
return errors;
|
|
4938
|
+
}
|
|
4939
|
+
if (args[0]) errors.push(...validateRefArgument(args[0], doc, { requireDbTable: true }));
|
|
4940
|
+
const forAnnotations = owner.annotations?.filter((a) => a.name === "db.view.for");
|
|
4941
|
+
const entryTypeName = forAnnotations?.[0]?.args[0]?.text;
|
|
4942
|
+
if (!entryTypeName) {
|
|
4943
|
+
errors.push({
|
|
4944
|
+
message: "@db.view.joins requires @db.view.for to identify the entry table",
|
|
4945
|
+
severity: 1,
|
|
4946
|
+
range: token.range
|
|
4947
|
+
});
|
|
4948
|
+
return errors;
|
|
4949
|
+
}
|
|
4950
|
+
if (args[1]?.queryNode && args[0]) {
|
|
4951
|
+
const joinTargetName = args[0].text;
|
|
4952
|
+
errors.push(...validateQueryScope(args[1], [joinTargetName, entryTypeName], entryTypeName, doc));
|
|
4953
|
+
}
|
|
4954
|
+
return errors;
|
|
4955
|
+
}
|
|
4956
|
+
}),
|
|
4957
|
+
filter: new AnnotationSpec({
|
|
4958
|
+
description: "WHERE clause for a view, filtering which rows are included.\n\n**Example:**\n```atscript\n@db.view.for User\n@db.view.filter `User.status = 'active' and User.age >= 18`\nexport interface ActiveUser { ... }\n```\n",
|
|
4959
|
+
nodeType: ["interface"],
|
|
4960
|
+
argument: {
|
|
4961
|
+
name: "condition",
|
|
4962
|
+
type: "query",
|
|
4963
|
+
description: "Filter expression for the view WHERE clause."
|
|
4964
|
+
},
|
|
4965
|
+
validate(token, args, doc) {
|
|
4966
|
+
const errors = [];
|
|
4967
|
+
const owner = token.parentNode;
|
|
4968
|
+
if (!hasAnyViewAnnotation(owner) && !args[0]) {
|
|
4969
|
+
errors.push({
|
|
4970
|
+
message: "@db.view.filter is only valid on @db.view interfaces",
|
|
4971
|
+
severity: 1,
|
|
4972
|
+
range: token.range
|
|
4973
|
+
});
|
|
4974
|
+
return errors;
|
|
4975
|
+
}
|
|
4976
|
+
if (!args[0]?.queryNode) return errors;
|
|
4977
|
+
const forAnnotations = owner.annotations?.filter((a) => a.name === "db.view.for");
|
|
4978
|
+
const entryTypeName = forAnnotations?.[0]?.args[0]?.text;
|
|
4979
|
+
if (!entryTypeName) {
|
|
4980
|
+
errors.push({
|
|
4981
|
+
message: "@db.view.filter requires @db.view.for to identify the entry table",
|
|
4982
|
+
severity: 1,
|
|
4983
|
+
range: token.range
|
|
4984
|
+
});
|
|
4985
|
+
return errors;
|
|
4986
|
+
}
|
|
4987
|
+
const allowedTypes = [entryTypeName];
|
|
4988
|
+
const joinsAnnotations = owner.annotations?.filter((a) => a.name === "db.view.joins");
|
|
4989
|
+
if (joinsAnnotations) {
|
|
4990
|
+
for (const join of joinsAnnotations) if (join.args[0]) allowedTypes.push(join.args[0].text);
|
|
4991
|
+
}
|
|
4992
|
+
errors.push(...validateQueryScope(args[0], allowedTypes, entryTypeName, doc));
|
|
4993
|
+
return errors;
|
|
4994
|
+
}
|
|
4995
|
+
}),
|
|
4996
|
+
materialized: new AnnotationSpec({
|
|
4997
|
+
description: "Marks a view as materialized (precomputed, stored on disk). Supported by PostgreSQL, CockroachDB, Oracle, SQL Server (indexed views), Snowflake. MongoDB supports on-demand materialized views via $merge/$out. Not applicable to MySQL or SQLite.\n\n**Example:**\n```atscript\n@db.view.materialized\n@db.view.for User\n@db.view.filter `User.status = 'active'`\nexport interface ActiveUsers { ... }\n```\n",
|
|
4998
|
+
nodeType: ["interface"],
|
|
4999
|
+
validate(token, _args, _doc) {
|
|
5000
|
+
const errors = [];
|
|
5001
|
+
const owner = token.parentNode;
|
|
5002
|
+
if (!hasAnyViewAnnotation(owner)) errors.push({
|
|
5003
|
+
message: "@db.view.materialized is only valid on @db.view interfaces",
|
|
5004
|
+
severity: 1,
|
|
5005
|
+
range: token.range
|
|
5006
|
+
});
|
|
5007
|
+
return errors;
|
|
5008
|
+
}
|
|
5009
|
+
}),
|
|
5010
|
+
renamed: new AnnotationSpec({
|
|
5011
|
+
description: "Specifies the previous view name for view rename migration. The sync engine drops the old view and creates the new one.\n\n**Example:**\n```atscript\n@db.view \"active_premium_users\"\n@db.view.renamed \"active_users\"\n@db.view.for User\nexport interface ActivePremiumUser { ... }\n```\n",
|
|
5012
|
+
nodeType: ["interface"],
|
|
5013
|
+
argument: {
|
|
5014
|
+
name: "oldName",
|
|
5015
|
+
type: "string",
|
|
5016
|
+
description: "The previous view name."
|
|
5017
|
+
},
|
|
5018
|
+
validate(token, _args, _doc) {
|
|
5019
|
+
const errors = [];
|
|
5020
|
+
const owner = token.parentNode;
|
|
5021
|
+
if (!hasAnyViewAnnotation(owner)) errors.push({
|
|
5022
|
+
message: "@db.view.renamed requires @db.view on the same interface",
|
|
5023
|
+
severity: 1,
|
|
5024
|
+
range: token.range
|
|
5025
|
+
});
|
|
5026
|
+
return errors;
|
|
5027
|
+
}
|
|
5028
|
+
})
|
|
3808
5029
|
}
|
|
3809
5030
|
};
|
|
3810
5031
|
|
|
@@ -4504,8 +5725,12 @@ var PluginManager = class {
|
|
|
4504
5725
|
return this._loopInAnnotationsSpec(annotations$1, cb);
|
|
4505
5726
|
}
|
|
4506
5727
|
_loopInAnnotationsSpec(annotations$1, cb, prefix) {
|
|
4507
|
-
|
|
5728
|
+
if (annotations$1.$self && prefix) cb(prefix, annotations$1.$self);
|
|
5729
|
+
for (const [key, value] of Object.entries(annotations$1)) {
|
|
5730
|
+
if (key === "$self") continue;
|
|
5731
|
+
if (isAnnotationSpec(value)) cb(prefix ? `${prefix}.${key}` : key, value);
|
|
4508
5732
|
else this._loopInAnnotationsSpec(value, cb, prefix ? `${prefix}.${key}` : key);
|
|
5733
|
+
}
|
|
4509
5734
|
}
|
|
4510
5735
|
constructor(cfg) {
|
|
4511
5736
|
_define_property$2(this, "cfg", void 0);
|
|
@@ -4544,6 +5769,11 @@ var AtscriptRepo = class {
|
|
|
4544
5769
|
return new Set(tags);
|
|
4545
5770
|
}
|
|
4546
5771
|
async getUsedAnnotations() {
|
|
5772
|
+
const ANNOTATION_TYPE_MAP = {
|
|
5773
|
+
ref: "import(\"@atscript/typescript/utils\").AtscriptRef",
|
|
5774
|
+
query: "import(\"@atscript/typescript/utils\").AtscriptQueryNode"
|
|
5775
|
+
};
|
|
5776
|
+
const mapArgType = (t) => ANNOTATION_TYPE_MAP[t] || t;
|
|
4547
5777
|
const manager = await this.getSharedPluginManager();
|
|
4548
5778
|
const annotations$1 = {};
|
|
4549
5779
|
if (manager) await manager.loopInAnnotationsSpec((name, spec) => {
|
|
@@ -4555,12 +5785,12 @@ var AtscriptRepo = class {
|
|
|
4555
5785
|
props: {}
|
|
4556
5786
|
};
|
|
4557
5787
|
for (const a of spec.arguments) o.props[a.name] = {
|
|
4558
|
-
type: a.type,
|
|
5788
|
+
type: mapArgType(a.type),
|
|
4559
5789
|
optional: a.optional
|
|
4560
5790
|
};
|
|
4561
5791
|
types.push(o);
|
|
4562
5792
|
} else if (spec.config.argument) types.push({
|
|
4563
|
-
type: spec.config.argument.type,
|
|
5793
|
+
type: mapArgType(spec.config.argument.type),
|
|
4564
5794
|
optional: spec.config.argument.optional
|
|
4565
5795
|
});
|
|
4566
5796
|
else types.push({ type: "boolean" });
|
|
@@ -4701,34 +5931,28 @@ else types.push({ type: "boolean" });
|
|
|
4701
5931
|
async checkImport(atscript, from, imports, checked) {
|
|
4702
5932
|
const forId = resolveAtscriptFromPath(from.text, atscript.id);
|
|
4703
5933
|
if (forId === atscript.id) {
|
|
4704
|
-
|
|
4705
|
-
messages.push({
|
|
5934
|
+
atscript.registerMessages([{
|
|
4706
5935
|
severity: 1,
|
|
4707
5936
|
message: "\"import\" cannot import itself",
|
|
4708
5937
|
range: from.range
|
|
4709
|
-
});
|
|
5938
|
+
}]);
|
|
4710
5939
|
return;
|
|
4711
5940
|
}
|
|
4712
|
-
const errors = [];
|
|
4713
5941
|
let external;
|
|
4714
5942
|
try {
|
|
4715
5943
|
external = await this.openDocument(forId);
|
|
4716
5944
|
await this.checkImports(external, checked);
|
|
4717
|
-
for (const token of imports) if (!external.exports.has(token.text))
|
|
5945
|
+
for (const token of imports) if (!external.exports.has(token.text)) atscript.registerMessages([{
|
|
4718
5946
|
severity: 1,
|
|
4719
5947
|
message: `"${from.text}" has no exported member "${token.text}"`,
|
|
4720
5948
|
range: token.range
|
|
4721
|
-
});
|
|
5949
|
+
}]);
|
|
4722
5950
|
} catch (error) {
|
|
4723
|
-
|
|
5951
|
+
atscript.registerMessages([{
|
|
4724
5952
|
severity: 1,
|
|
4725
5953
|
message: `"${from.text}" not found`,
|
|
4726
5954
|
range: from.range
|
|
4727
|
-
});
|
|
4728
|
-
}
|
|
4729
|
-
if (errors.length > 0) {
|
|
4730
|
-
const messages = atscript.getDiagMessages();
|
|
4731
|
-
messages.push(...errors);
|
|
5955
|
+
}]);
|
|
4732
5956
|
}
|
|
4733
5957
|
return external;
|
|
4734
5958
|
}
|
|
@@ -4789,7 +6013,9 @@ else {
|
|
|
4789
6013
|
}
|
|
4790
6014
|
const documents = [];
|
|
4791
6015
|
for (const entry of entries) documents.push(await repo.openDocument(`file://${entry}`));
|
|
4792
|
-
|
|
6016
|
+
const docs = documents.filter(Boolean);
|
|
6017
|
+
for (const doc of docs) await repo.checkDoc(doc);
|
|
6018
|
+
return new BuildRepo(rootDir, repo, docs);
|
|
4793
6019
|
}
|
|
4794
6020
|
var BuildRepo = class {
|
|
4795
6021
|
getDoc(id) {
|
|
@@ -4797,10 +6023,7 @@ var BuildRepo = class {
|
|
|
4797
6023
|
}
|
|
4798
6024
|
async diagnostics() {
|
|
4799
6025
|
const docMessages = new Map();
|
|
4800
|
-
for (const document of this.docs)
|
|
4801
|
-
await this.repo.checkDoc(document);
|
|
4802
|
-
docMessages.set(document.id, document.getDiagMessages());
|
|
4803
|
-
}
|
|
6026
|
+
for (const document of this.docs) docMessages.set(document.id, document.getDiagMessages());
|
|
4804
6027
|
return docMessages;
|
|
4805
6028
|
}
|
|
4806
6029
|
async generate(config, docs = this.docs) {
|
|
@@ -4843,14 +6066,14 @@ var BuildRepo = class {
|
|
|
4843
6066
|
|
|
4844
6067
|
//#endregion
|
|
4845
6068
|
//#region packages/core/src/flatten.ts
|
|
4846
|
-
function flattenInterfaceNode(doc, node) {
|
|
6069
|
+
function flattenInterfaceNode(doc, node, options) {
|
|
4847
6070
|
const flatMap = new Map();
|
|
4848
6071
|
const stack = new Set();
|
|
4849
6072
|
let struct;
|
|
4850
6073
|
if (node.hasExtends) struct = doc.resolveInterfaceExtends(node);
|
|
4851
6074
|
if (!struct) struct = node.getDefinition();
|
|
4852
6075
|
if (!struct || !isStructure(struct)) return flatMap;
|
|
4853
|
-
walkStructure(doc, struct, "", false, flatMap, stack);
|
|
6076
|
+
walkStructure(doc, struct, "", false, flatMap, stack, options);
|
|
4854
6077
|
return flatMap;
|
|
4855
6078
|
}
|
|
4856
6079
|
/**
|
|
@@ -4865,6 +6088,10 @@ function flattenInterfaceNode(doc, node) {
|
|
|
4865
6088
|
if (!prop.annotations) return false;
|
|
4866
6089
|
return prop.annotations.some((a) => a.name === "db.json");
|
|
4867
6090
|
}
|
|
6091
|
+
function hasNavPropAnnotation(prop) {
|
|
6092
|
+
if (!prop.annotations) return false;
|
|
6093
|
+
return prop.annotations.some((a) => a.name === "db.rel.to" || a.name === "db.rel.from" || a.name === "db.rel.via");
|
|
6094
|
+
}
|
|
4868
6095
|
function isPhantomNode(doc, def) {
|
|
4869
6096
|
if (!def) return false;
|
|
4870
6097
|
if (isPrimitive(def) && def.config.type === "phantom") return true;
|
|
@@ -4913,11 +6140,12 @@ function addToFlatMap(flatMap, path$2, descriptor) {
|
|
|
4913
6140
|
});
|
|
4914
6141
|
} else flatMap.set(path$2, descriptor);
|
|
4915
6142
|
}
|
|
4916
|
-
function walkStructure(doc, struct, prefix, parentOptional, flatMap, stack) {
|
|
6143
|
+
function walkStructure(doc, struct, prefix, parentOptional, flatMap, stack, options) {
|
|
4917
6144
|
for (const [name, prop] of struct.props) {
|
|
4918
6145
|
if (prop.token("identifier")?.pattern) continue;
|
|
4919
6146
|
const propDef = prop.getDefinition();
|
|
4920
6147
|
if (isPhantomNode(doc, propDef)) continue;
|
|
6148
|
+
if (options?.skipNavProps && hasNavPropAnnotation(prop)) continue;
|
|
4921
6149
|
const path$2 = prefix ? `${prefix}.${name}` : name;
|
|
4922
6150
|
const optional = parentOptional || !!prop.token("optional");
|
|
4923
6151
|
const dbJson = hasDbJsonAnnotation(prop);
|
|
@@ -4950,10 +6178,10 @@ function walkStructure(doc, struct, prefix, parentOptional, flatMap, stack) {
|
|
|
4950
6178
|
});
|
|
4951
6179
|
continue;
|
|
4952
6180
|
}
|
|
4953
|
-
walkNode(resolved.doc, resolved.def, path$2, optional, prop, flatMap, stack);
|
|
6181
|
+
walkNode(resolved.doc, resolved.def, path$2, optional, prop, flatMap, stack, options);
|
|
4954
6182
|
}
|
|
4955
6183
|
}
|
|
4956
|
-
function walkNode(doc, def, path$2, optional, propNode, flatMap, stack) {
|
|
6184
|
+
function walkNode(doc, def, path$2, optional, propNode, flatMap, stack, options) {
|
|
4957
6185
|
if (stack.has(def)) {
|
|
4958
6186
|
addToFlatMap(flatMap, path$2, {
|
|
4959
6187
|
def,
|
|
@@ -4973,7 +6201,7 @@ function walkNode(doc, def, path$2, optional, propNode, flatMap, stack) {
|
|
|
4973
6201
|
propNode,
|
|
4974
6202
|
intermediate: true
|
|
4975
6203
|
});
|
|
4976
|
-
walkStructure(doc, def, path$2, optional, flatMap, stack);
|
|
6204
|
+
walkStructure(doc, def, path$2, optional, flatMap, stack, options);
|
|
4977
6205
|
} else if (isArray(def)) {
|
|
4978
6206
|
const elementDef = def.getDefinition();
|
|
4979
6207
|
const resolvedElement = elementDef ? resolveNode(doc, elementDef) : undefined;
|
|
@@ -4986,7 +6214,7 @@ function walkNode(doc, def, path$2, optional, propNode, flatMap, stack) {
|
|
|
4986
6214
|
propNode,
|
|
4987
6215
|
intermediate: true
|
|
4988
6216
|
});
|
|
4989
|
-
walkArrayElement(doc, def, path$2, optional, flatMap, stack);
|
|
6217
|
+
walkArrayElement(doc, def, path$2, optional, flatMap, stack, options);
|
|
4990
6218
|
} else addToFlatMap(flatMap, path$2, {
|
|
4991
6219
|
def,
|
|
4992
6220
|
doc,
|
|
@@ -5005,7 +6233,7 @@ function walkNode(doc, def, path$2, optional, propNode, flatMap, stack) {
|
|
|
5005
6233
|
propNode,
|
|
5006
6234
|
intermediate: true
|
|
5007
6235
|
});
|
|
5008
|
-
walkStructure(doc, merged, path$2, optional, flatMap, stack);
|
|
6236
|
+
walkStructure(doc, merged, path$2, optional, flatMap, stack, options);
|
|
5009
6237
|
} else addToFlatMap(flatMap, path$2, {
|
|
5010
6238
|
def,
|
|
5011
6239
|
doc,
|
|
@@ -5037,7 +6265,7 @@ else addToFlatMap(flatMap, path$2, {
|
|
|
5037
6265
|
});
|
|
5038
6266
|
for (const branch of branches) {
|
|
5039
6267
|
const resolved = resolveNode(doc, branch);
|
|
5040
|
-
if (resolved) walkBranch(resolved.doc, resolved.def, path$2, optional, flatMap, stack);
|
|
6268
|
+
if (resolved) walkBranch(resolved.doc, resolved.def, path$2, optional, flatMap, stack, options);
|
|
5041
6269
|
}
|
|
5042
6270
|
} else addToFlatMap(flatMap, path$2, {
|
|
5043
6271
|
def,
|
|
@@ -5061,30 +6289,30 @@ else addToFlatMap(flatMap, path$2, {
|
|
|
5061
6289
|
stack.delete(def);
|
|
5062
6290
|
}
|
|
5063
6291
|
}
|
|
5064
|
-
function walkArrayElement(doc, arrayNode, prefix, parentOptional, flatMap, stack) {
|
|
6292
|
+
function walkArrayElement(doc, arrayNode, prefix, parentOptional, flatMap, stack, options) {
|
|
5065
6293
|
const elementDef = arrayNode.getDefinition();
|
|
5066
6294
|
if (!elementDef) return;
|
|
5067
6295
|
const resolved = resolveNode(doc, elementDef);
|
|
5068
6296
|
if (!resolved) return;
|
|
5069
|
-
walkBranch(resolved.doc, resolved.def, prefix, parentOptional, flatMap, stack);
|
|
6297
|
+
walkBranch(resolved.doc, resolved.def, prefix, parentOptional, flatMap, stack, options);
|
|
5070
6298
|
}
|
|
5071
6299
|
/**
|
|
5072
6300
|
* Walks a branch (union branch or array element) to collect sub-paths.
|
|
5073
6301
|
* Does NOT add an entry for the branch itself — the parent already did that.
|
|
5074
|
-
*/ function walkBranch(doc, def, prefix, parentOptional, flatMap, stack) {
|
|
5075
|
-
if (isStructure(def)) walkStructure(doc, def, prefix, parentOptional, flatMap, stack);
|
|
5076
|
-
else if (isArray(def)) walkArrayElement(doc, def, prefix, parentOptional, flatMap, stack);
|
|
6302
|
+
*/ function walkBranch(doc, def, prefix, parentOptional, flatMap, stack, options) {
|
|
6303
|
+
if (isStructure(def)) walkStructure(doc, def, prefix, parentOptional, flatMap, stack, options);
|
|
6304
|
+
else if (isArray(def)) walkArrayElement(doc, def, prefix, parentOptional, flatMap, stack, options);
|
|
5077
6305
|
else if (isGroup(def) && def.entity !== "structure") {
|
|
5078
6306
|
const group$1 = def;
|
|
5079
6307
|
if (group$1.op === "&") {
|
|
5080
6308
|
const merged = doc.mergeIntersection(def);
|
|
5081
|
-
if (isStructure(merged)) walkStructure(doc, merged, prefix, parentOptional, flatMap, stack);
|
|
6309
|
+
if (isStructure(merged)) walkStructure(doc, merged, prefix, parentOptional, flatMap, stack, options);
|
|
5082
6310
|
} else if (group$1.op === "|") for (const branch of group$1.unwrap()) {
|
|
5083
6311
|
const resolved = resolveNode(doc, branch);
|
|
5084
|
-
if (resolved) walkBranch(resolved.doc, resolved.def, prefix, parentOptional, flatMap, stack);
|
|
6312
|
+
if (resolved) walkBranch(resolved.doc, resolved.def, prefix, parentOptional, flatMap, stack, options);
|
|
5085
6313
|
}
|
|
5086
6314
|
}
|
|
5087
6315
|
}
|
|
5088
6316
|
|
|
5089
6317
|
//#endregion
|
|
5090
|
-
export { $n, AnnotationSpec, AtscriptDoc, AtscriptRepo, BuildRepo, DEFAULT_FORMAT, PluginManager, SemanticAnnotateNode, SemanticArrayNode, SemanticConstNode, SemanticGroup, SemanticImportNode, SemanticInterfaceNode, SemanticNode, SemanticPrimitiveNode, SemanticPropNode, SemanticRefNode, SemanticStructureNode, SemanticTupleNode, SemanticTypeNode, Token, build, createAtscriptPlugin, defineConfig, findFKFieldsPointingTo, flattenInterfaceNode, getRelPath, isAnnotate, isAnnotationSpec, isArray, isConst, isGroup, isImport, isInterface, isPhantomNode, isPrimitive, isProp, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, resolveAnnotation, resolveAtscriptFromPath, resolveConfigFile };
|
|
6318
|
+
export { $n, AnnotationSpec, AtscriptDoc, AtscriptRepo, BuildRepo, DEFAULT_FORMAT, PluginManager, SemanticAnnotateNode, SemanticArrayNode, SemanticConstNode, SemanticGroup, SemanticImportNode, SemanticInterfaceNode, SemanticNode, SemanticPrimitiveNode, SemanticPropNode, SemanticQueryComparisonNode, SemanticQueryFieldRefNode, SemanticQueryLogicalNode, SemanticQueryNode, SemanticQueryValueListNode, SemanticQueryValueNode, SemanticRefNode, SemanticStructureNode, SemanticTupleNode, SemanticTypeNode, Token, analyzeQueryCursorContext, build, createAtscriptPlugin, defineConfig, findFKFieldsPointingTo, flattenInterfaceNode, getFieldsForType, getQueryCompletionScope, getQueryScope, getRelPath, hasNavPropAnnotation, isAnnotate, isAnnotationSpec, isArray, isConst, isGroup, isImport, isInterface, isPhantomNode, isPrimitive, isProp, isQueryComparison, isQueryFieldRef, isQueryLogical, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, resolveAnnotation, resolveAtscriptFromPath, resolveConfigFile, resolveQueryFieldRef, validateRefArgument };
|