@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.cjs
CHANGED
|
@@ -35,7 +35,7 @@ const fs_promises = __toESM(require("fs/promises"));
|
|
|
35
35
|
const glob = __toESM(require("glob"));
|
|
36
36
|
|
|
37
37
|
//#region packages/core/src/parser/nodes/semantic-node.ts
|
|
38
|
-
function _define_property$
|
|
38
|
+
function _define_property$16(obj, key, value) {
|
|
39
39
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
40
40
|
value,
|
|
41
41
|
enumerable: true,
|
|
@@ -146,15 +146,15 @@ else this.annotationsCounter.set(name, 1);
|
|
|
146
146
|
return this.definition;
|
|
147
147
|
}
|
|
148
148
|
constructor(entity) {
|
|
149
|
-
_define_property$
|
|
150
|
-
_define_property$
|
|
151
|
-
_define_property$
|
|
152
|
-
_define_property$
|
|
153
|
-
_define_property$
|
|
154
|
-
_define_property$
|
|
155
|
-
_define_property$
|
|
156
|
-
_define_property$
|
|
157
|
-
_define_property$
|
|
149
|
+
_define_property$16(this, "entity", void 0);
|
|
150
|
+
_define_property$16(this, "tokens", void 0);
|
|
151
|
+
_define_property$16(this, "isGroup", void 0);
|
|
152
|
+
_define_property$16(this, "definition", void 0);
|
|
153
|
+
_define_property$16(this, "annotations", void 0);
|
|
154
|
+
_define_property$16(this, "annotationsCounter", void 0);
|
|
155
|
+
_define_property$16(this, "__typeId", void 0);
|
|
156
|
+
_define_property$16(this, "ownerNode", void 0);
|
|
157
|
+
_define_property$16(this, "_documentation", void 0);
|
|
158
158
|
this.entity = entity;
|
|
159
159
|
this.isGroup = false;
|
|
160
160
|
}
|
|
@@ -251,7 +251,7 @@ var SemanticConstNode = class extends SemanticNode {
|
|
|
251
251
|
|
|
252
252
|
//#endregion
|
|
253
253
|
//#region packages/core/src/parser/nodes/group-node.ts
|
|
254
|
-
function _define_property$
|
|
254
|
+
function _define_property$15(obj, key, value) {
|
|
255
255
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
256
256
|
value,
|
|
257
257
|
enumerable: true,
|
|
@@ -296,7 +296,7 @@ var SemanticGroup = class extends SemanticNode {
|
|
|
296
296
|
return s;
|
|
297
297
|
}
|
|
298
298
|
constructor(nodes = [], operator) {
|
|
299
|
-
super("group"), _define_property$
|
|
299
|
+
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;
|
|
300
300
|
}
|
|
301
301
|
};
|
|
302
302
|
|
|
@@ -318,7 +318,7 @@ var SemanticImportNode = class extends SemanticNode {
|
|
|
318
318
|
|
|
319
319
|
//#endregion
|
|
320
320
|
//#region packages/core/src/parser/nodes/interface-node.ts
|
|
321
|
-
function _define_property$
|
|
321
|
+
function _define_property$14(obj, key, value) {
|
|
322
322
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
323
323
|
value,
|
|
324
324
|
enumerable: true,
|
|
@@ -366,13 +366,13 @@ var SemanticInterfaceNode = class extends SemanticNode {
|
|
|
366
366
|
return s;
|
|
367
367
|
}
|
|
368
368
|
constructor() {
|
|
369
|
-
super("interface"), _define_property$
|
|
369
|
+
super("interface"), _define_property$14(this, "_extendsTokens", []);
|
|
370
370
|
}
|
|
371
371
|
};
|
|
372
372
|
|
|
373
373
|
//#endregion
|
|
374
374
|
//#region packages/core/src/parser/token.ts
|
|
375
|
-
function _define_property$
|
|
375
|
+
function _define_property$13(obj, key, value) {
|
|
376
376
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
377
377
|
value,
|
|
378
378
|
enumerable: true,
|
|
@@ -418,43 +418,46 @@ var Token = class Token {
|
|
|
418
418
|
return this._data.type === "annotation";
|
|
419
419
|
}
|
|
420
420
|
constructor(_data) {
|
|
421
|
-
_define_property$
|
|
421
|
+
_define_property$13(this, "_data", void 0);
|
|
422
422
|
/**
|
|
423
423
|
* Set this to file path (e.g. "./src/file.as") for path token in import statement
|
|
424
|
-
*/ _define_property$
|
|
424
|
+
*/ _define_property$13(this, "fromPath", void 0);
|
|
425
425
|
/**
|
|
426
426
|
* All definitions that exported must be marked with this flag
|
|
427
|
-
*/ _define_property$
|
|
427
|
+
*/ _define_property$13(this, "exported", void 0);
|
|
428
428
|
/**
|
|
429
429
|
* All the definitions must be marked with this flag
|
|
430
|
-
*/ _define_property$
|
|
430
|
+
*/ _define_property$13(this, "isDefinition", void 0);
|
|
431
431
|
/**
|
|
432
432
|
* All the references must be marked with this flag
|
|
433
|
-
*/ _define_property$
|
|
433
|
+
*/ _define_property$13(this, "isReference", void 0);
|
|
434
434
|
/**
|
|
435
435
|
* All the import tokens must be marked with this flag
|
|
436
|
-
*/ _define_property$
|
|
436
|
+
*/ _define_property$13(this, "imported", void 0);
|
|
437
437
|
/**
|
|
438
438
|
* Refs chained via . or ["propName"] are marked with this flag
|
|
439
|
-
*/ _define_property$
|
|
439
|
+
*/ _define_property$13(this, "isChain", void 0);
|
|
440
440
|
/**
|
|
441
441
|
* Prop patterns ([*] or [regexp]) are storing patterns here
|
|
442
|
-
*/ _define_property$
|
|
443
|
-
_define_property$
|
|
442
|
+
*/ _define_property$13(this, "pattern", void 0);
|
|
443
|
+
_define_property$13(this, "parentNode", void 0);
|
|
444
444
|
/**
|
|
445
445
|
* Only for annotation arguments: reference to their annotation token
|
|
446
|
-
*/ _define_property$
|
|
447
|
-
_define_property$
|
|
446
|
+
*/ _define_property$13(this, "annotationRef", void 0);
|
|
447
|
+
_define_property$13(this, "index", void 0);
|
|
448
448
|
/**
|
|
449
449
|
* Block type
|
|
450
|
-
*/ _define_property$
|
|
450
|
+
*/ _define_property$13(this, "blockType", void 0);
|
|
451
|
+
/**
|
|
452
|
+
* Parsed query expression tree (for query-type annotation arguments)
|
|
453
|
+
*/ _define_property$13(this, "queryNode", void 0);
|
|
451
454
|
this._data = _data;
|
|
452
455
|
}
|
|
453
456
|
};
|
|
454
457
|
|
|
455
458
|
//#endregion
|
|
456
459
|
//#region packages/core/src/parser/nodes/primitive-node.ts
|
|
457
|
-
function _define_property$
|
|
460
|
+
function _define_property$12(obj, key, value) {
|
|
458
461
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
459
462
|
value,
|
|
460
463
|
enumerable: true,
|
|
@@ -503,7 +506,7 @@ else if (value.length > 0) this.annotations.push(toAnnotationTokens(name, value[
|
|
|
503
506
|
return indent + s.split("\n").join(`\n${indent}`);
|
|
504
507
|
}
|
|
505
508
|
constructor(_id, config, parentKey = "", annotationTree) {
|
|
506
|
-
super("primitive"), _define_property$
|
|
509
|
+
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;
|
|
507
510
|
this.props = new Map();
|
|
508
511
|
this.tags = new Set([_id, ...config?.tags || []]);
|
|
509
512
|
for (const [ext, def] of Object.entries(config.extensions || {})) {
|
|
@@ -624,7 +627,7 @@ var SemanticPropNode = class extends SemanticNode {
|
|
|
624
627
|
|
|
625
628
|
//#endregion
|
|
626
629
|
//#region packages/core/src/parser/nodes/ref-node.ts
|
|
627
|
-
function _define_property$
|
|
630
|
+
function _define_property$11(obj, key, value) {
|
|
628
631
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
629
632
|
value,
|
|
630
633
|
enumerable: true,
|
|
@@ -676,13 +679,13 @@ var SemanticRefNode = class extends SemanticNode {
|
|
|
676
679
|
return indent + s.split("\n").join(`\n${indent}`);
|
|
677
680
|
}
|
|
678
681
|
constructor() {
|
|
679
|
-
super("ref"), _define_property$
|
|
682
|
+
super("ref"), _define_property$11(this, "_chain", []), _define_property$11(this, "_dots", []);
|
|
680
683
|
}
|
|
681
684
|
};
|
|
682
685
|
|
|
683
686
|
//#endregion
|
|
684
687
|
//#region packages/core/src/parser/nodes/structure-node.ts
|
|
685
|
-
function _define_property$
|
|
688
|
+
function _define_property$10(obj, key, value) {
|
|
686
689
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
687
690
|
value,
|
|
688
691
|
enumerable: true,
|
|
@@ -761,7 +764,7 @@ var SemanticStructureNode = class extends SemanticGroup {
|
|
|
761
764
|
this.props.set(opts.name, prop);
|
|
762
765
|
}
|
|
763
766
|
constructor() {
|
|
764
|
-
super(), _define_property$
|
|
767
|
+
super(), _define_property$10(this, "props", new Map());
|
|
765
768
|
this.entity = "structure";
|
|
766
769
|
}
|
|
767
770
|
};
|
|
@@ -794,6 +797,84 @@ var SemanticTypeNode = class extends SemanticNode {
|
|
|
794
797
|
}
|
|
795
798
|
};
|
|
796
799
|
|
|
800
|
+
//#endregion
|
|
801
|
+
//#region packages/core/src/parser/nodes/query-nodes.ts
|
|
802
|
+
function _define_property$9(obj, key, value) {
|
|
803
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
804
|
+
value,
|
|
805
|
+
enumerable: true,
|
|
806
|
+
configurable: true,
|
|
807
|
+
writable: true
|
|
808
|
+
});
|
|
809
|
+
else obj[key] = value;
|
|
810
|
+
return obj;
|
|
811
|
+
}
|
|
812
|
+
var SemanticQueryNode = class extends SemanticNode {
|
|
813
|
+
registerAtDocument(doc) {
|
|
814
|
+
this.propagateQueryArgToken(this.expression);
|
|
815
|
+
this.expression.registerAtDocument(doc);
|
|
816
|
+
}
|
|
817
|
+
propagateQueryArgToken(expr) {
|
|
818
|
+
if ("left" in expr) {
|
|
819
|
+
expr.left.queryArgToken = this.sourceToken;
|
|
820
|
+
const right = expr.right;
|
|
821
|
+
if (right && "fieldRef" in right) right.queryArgToken = this.sourceToken;
|
|
822
|
+
} else if ("operands" in expr) for (const operand of expr.operands) this.propagateQueryArgToken(operand);
|
|
823
|
+
}
|
|
824
|
+
constructor() {
|
|
825
|
+
super("query"), _define_property$9(this, "expression", void 0), _define_property$9(this, "sourceToken", void 0);
|
|
826
|
+
}
|
|
827
|
+
};
|
|
828
|
+
var SemanticQueryLogicalNode = class extends SemanticNode {
|
|
829
|
+
registerAtDocument(doc) {
|
|
830
|
+
for (const operand of this.operands) operand.registerAtDocument(doc);
|
|
831
|
+
}
|
|
832
|
+
constructor() {
|
|
833
|
+
super("query-logical"), _define_property$9(this, "operator", void 0), _define_property$9(this, "operands", void 0);
|
|
834
|
+
}
|
|
835
|
+
};
|
|
836
|
+
var SemanticQueryComparisonNode = class extends SemanticNode {
|
|
837
|
+
registerAtDocument(doc) {
|
|
838
|
+
this.left.registerAtDocument(doc);
|
|
839
|
+
this.right?.registerAtDocument(doc);
|
|
840
|
+
}
|
|
841
|
+
constructor() {
|
|
842
|
+
super("query-comparison"), _define_property$9(this, "left", void 0), _define_property$9(this, "operator", void 0), _define_property$9(this, "right", void 0);
|
|
843
|
+
}
|
|
844
|
+
};
|
|
845
|
+
var SemanticQueryFieldRefNode = class extends SemanticNode {
|
|
846
|
+
registerAtDocument(doc) {
|
|
847
|
+
if (this.typeRef) {
|
|
848
|
+
this.typeRef.isReference = true;
|
|
849
|
+
this.typeRef.parentNode = this;
|
|
850
|
+
doc.referred.push(this.typeRef);
|
|
851
|
+
doc.tokensIndex.add(this.typeRef);
|
|
852
|
+
}
|
|
853
|
+
this.fieldRef.parentNode = this;
|
|
854
|
+
doc.tokensIndex.add(this.fieldRef);
|
|
855
|
+
doc.queryFieldRefs.push(this);
|
|
856
|
+
}
|
|
857
|
+
constructor() {
|
|
858
|
+
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);
|
|
859
|
+
}
|
|
860
|
+
};
|
|
861
|
+
var SemanticQueryValueNode = class extends SemanticNode {
|
|
862
|
+
registerAtDocument(doc) {
|
|
863
|
+
doc.tokensIndex.add(this.valueToken);
|
|
864
|
+
}
|
|
865
|
+
constructor() {
|
|
866
|
+
super("query-value"), _define_property$9(this, "valueToken", void 0);
|
|
867
|
+
}
|
|
868
|
+
};
|
|
869
|
+
var SemanticQueryValueListNode = class extends SemanticNode {
|
|
870
|
+
registerAtDocument(doc) {
|
|
871
|
+
for (const v of this.values) v.registerAtDocument(doc);
|
|
872
|
+
}
|
|
873
|
+
constructor() {
|
|
874
|
+
super("query-value-list"), _define_property$9(this, "values", void 0);
|
|
875
|
+
}
|
|
876
|
+
};
|
|
877
|
+
|
|
797
878
|
//#endregion
|
|
798
879
|
//#region packages/core/src/parser/nodes/index.ts
|
|
799
880
|
const $n = {
|
|
@@ -846,6 +927,15 @@ function isPrimitive(node) {
|
|
|
846
927
|
function isAnnotate(node) {
|
|
847
928
|
return node?.entity === "annotate";
|
|
848
929
|
}
|
|
930
|
+
function isQueryLogical(node) {
|
|
931
|
+
return node?.operands !== undefined;
|
|
932
|
+
}
|
|
933
|
+
function isQueryComparison(node) {
|
|
934
|
+
return node?.left !== undefined;
|
|
935
|
+
}
|
|
936
|
+
function isQueryFieldRef(node) {
|
|
937
|
+
return node?.fieldRef !== undefined;
|
|
938
|
+
}
|
|
849
939
|
|
|
850
940
|
//#endregion
|
|
851
941
|
//#region packages/core/src/annotations/annotation-spec.ts
|
|
@@ -869,7 +959,7 @@ var AnnotationSpec = class {
|
|
|
869
959
|
return this.arguments.map((arg, index) => {
|
|
870
960
|
const placeholderIndex = index + 1;
|
|
871
961
|
const defaultValue = this.getDefaultValueForType(arg.name, arg.type);
|
|
872
|
-
const quote = arg.type === "string" ? `'` : "";
|
|
962
|
+
const quote = arg.type === "string" ? `'` : arg.type === "query" ? "`" : "";
|
|
873
963
|
return `${quote}\${${placeholderIndex}:${defaultValue}}${quote}`;
|
|
874
964
|
}).join(", ");
|
|
875
965
|
}
|
|
@@ -878,6 +968,8 @@ var AnnotationSpec = class {
|
|
|
878
968
|
case "string": return tokenType === "text" ? undefined : "string expected.";
|
|
879
969
|
case "number": return tokenType === "number" ? undefined : "number expected.";
|
|
880
970
|
case "boolean": return tokenType === "identifier" ? undefined : "boolean expected.";
|
|
971
|
+
case "ref": return tokenType === "identifier" ? undefined : "type reference expected.";
|
|
972
|
+
case "query": return tokenType === "query" ? undefined : "query expression expected (use backticks).";
|
|
881
973
|
default: return `unknown type "${type$1}".`;
|
|
882
974
|
}
|
|
883
975
|
}
|
|
@@ -970,6 +1062,8 @@ else if (isGroup(def) && def.entity !== "tuple") defEntity = def.op === "&" ? "i
|
|
|
970
1062
|
case "string": return name;
|
|
971
1063
|
case "number": return "0";
|
|
972
1064
|
case "boolean": return "true";
|
|
1065
|
+
case "ref": return "TypeName";
|
|
1066
|
+
case "query": return "field = value";
|
|
973
1067
|
default: return "";
|
|
974
1068
|
}
|
|
975
1069
|
}
|
|
@@ -987,10 +1081,13 @@ function resolveAnnotation(name, annotationsTree) {
|
|
|
987
1081
|
const parts = name.split(".");
|
|
988
1082
|
let current = annotationsTree;
|
|
989
1083
|
for (const part of parts) {
|
|
1084
|
+
if (part === "$self") return undefined;
|
|
990
1085
|
if (!current || isAnnotationSpec(current)) return undefined;
|
|
991
1086
|
current = current[part];
|
|
992
1087
|
}
|
|
993
|
-
|
|
1088
|
+
if (isAnnotationSpec(current)) return current;
|
|
1089
|
+
if (current && !isAnnotationSpec(current) && current.$self) return current.$self;
|
|
1090
|
+
return undefined;
|
|
994
1091
|
}
|
|
995
1092
|
|
|
996
1093
|
//#endregion
|
|
@@ -1107,6 +1204,204 @@ else if (SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) {
|
|
|
1107
1204
|
}
|
|
1108
1205
|
}
|
|
1109
1206
|
|
|
1207
|
+
//#endregion
|
|
1208
|
+
//#region packages/core/src/defaults/db-query-lsp.ts
|
|
1209
|
+
function getQueryScope(queryArgToken, doc) {
|
|
1210
|
+
const annotationRef = queryArgToken.annotationRef;
|
|
1211
|
+
if (!annotationRef) return undefined;
|
|
1212
|
+
const owner = queryArgToken.parentNode;
|
|
1213
|
+
if (!owner) return undefined;
|
|
1214
|
+
const annotationName = annotationRef.text.slice(1);
|
|
1215
|
+
if (annotationName === "db.view.filter") return getViewFilterScope(owner);
|
|
1216
|
+
if (annotationName === "db.view.joins") return getViewJoinsScope(owner, queryArgToken);
|
|
1217
|
+
if (annotationName === "db.rel.filter") return getRelFilterScope(owner);
|
|
1218
|
+
return undefined;
|
|
1219
|
+
}
|
|
1220
|
+
function getViewFilterScope(owner) {
|
|
1221
|
+
const forAnnotations = owner.annotations?.filter((a) => a.name === "db.view.for");
|
|
1222
|
+
const entryTypeName = forAnnotations?.[0]?.args[0]?.text;
|
|
1223
|
+
if (!entryTypeName) return undefined;
|
|
1224
|
+
const allowedTypes = [entryTypeName];
|
|
1225
|
+
const joinsAnnotations = owner.annotations?.filter((a) => a.name === "db.view.joins");
|
|
1226
|
+
if (joinsAnnotations) {
|
|
1227
|
+
for (const join of joinsAnnotations) if (join.args[0]) allowedTypes.push(join.args[0].text);
|
|
1228
|
+
}
|
|
1229
|
+
return {
|
|
1230
|
+
allowedTypes,
|
|
1231
|
+
unqualifiedTarget: entryTypeName
|
|
1232
|
+
};
|
|
1233
|
+
}
|
|
1234
|
+
function getViewJoinsScope(owner, queryArgToken) {
|
|
1235
|
+
const forAnnotations = owner.annotations?.filter((a) => a.name === "db.view.for");
|
|
1236
|
+
const entryTypeName = forAnnotations?.[0]?.args[0]?.text;
|
|
1237
|
+
if (!entryTypeName) return undefined;
|
|
1238
|
+
const joinsAnnotation = owner.annotations?.find((a) => a.name === "db.view.joins" && a.args.includes(queryArgToken));
|
|
1239
|
+
const joinTargetName = joinsAnnotation?.args[0]?.text;
|
|
1240
|
+
if (!joinTargetName) return undefined;
|
|
1241
|
+
return {
|
|
1242
|
+
allowedTypes: [joinTargetName, entryTypeName],
|
|
1243
|
+
unqualifiedTarget: entryTypeName
|
|
1244
|
+
};
|
|
1245
|
+
}
|
|
1246
|
+
function getRelFilterScope(owner) {
|
|
1247
|
+
let def = owner.getDefinition();
|
|
1248
|
+
if (isArray(def)) def = def?.getDefinition();
|
|
1249
|
+
if (!isRef(def)) return undefined;
|
|
1250
|
+
const targetTypeName = def.id;
|
|
1251
|
+
const allowedTypes = [targetTypeName];
|
|
1252
|
+
const viaAnnotation = owner.annotations?.find((a) => a.name === "db.rel.via");
|
|
1253
|
+
if (viaAnnotation?.args[0]) allowedTypes.push(viaAnnotation.args[0].text);
|
|
1254
|
+
return {
|
|
1255
|
+
allowedTypes,
|
|
1256
|
+
unqualifiedTarget: targetTypeName
|
|
1257
|
+
};
|
|
1258
|
+
}
|
|
1259
|
+
function resolveQueryFieldRef(fieldRefNode, doc, scope) {
|
|
1260
|
+
const typeName = fieldRefNode.typeRef?.text ?? scope.unqualifiedTarget;
|
|
1261
|
+
if (!typeName) return undefined;
|
|
1262
|
+
const fieldPath = fieldRefNode.fieldRef.text;
|
|
1263
|
+
const chain = fieldPath.split(".");
|
|
1264
|
+
const parentChain = chain.slice(0, -1);
|
|
1265
|
+
const parentUnwound = doc.unwindType(typeName, parentChain);
|
|
1266
|
+
if (!parentUnwound?.def) return undefined;
|
|
1267
|
+
const unwound = doc.unwindType(typeName, chain);
|
|
1268
|
+
if (!unwound?.node) return undefined;
|
|
1269
|
+
const prop = unwound.node;
|
|
1270
|
+
return {
|
|
1271
|
+
targetUri: parentUnwound.doc.id,
|
|
1272
|
+
doc: parentUnwound.doc,
|
|
1273
|
+
prop
|
|
1274
|
+
};
|
|
1275
|
+
}
|
|
1276
|
+
function getFieldsForType(doc, typeName) {
|
|
1277
|
+
const unwound = doc.unwindType(typeName);
|
|
1278
|
+
if (!unwound?.def) return [];
|
|
1279
|
+
let def = doc.mergeIntersection(unwound.def);
|
|
1280
|
+
if (isInterface(def)) {
|
|
1281
|
+
const resolved = doc.resolveInterfaceExtends(def);
|
|
1282
|
+
if (resolved) def = resolved;
|
|
1283
|
+
else def = def.getDefinition() || def;
|
|
1284
|
+
}
|
|
1285
|
+
if (isStructure(def) || isInterface(def)) return Array.from(def.props.values());
|
|
1286
|
+
return [];
|
|
1287
|
+
}
|
|
1288
|
+
function getQueryCompletionScope(queryArgToken, doc) {
|
|
1289
|
+
const scope = getQueryScope(queryArgToken, doc);
|
|
1290
|
+
if (!scope) return undefined;
|
|
1291
|
+
return {
|
|
1292
|
+
typeNames: scope.allowedTypes,
|
|
1293
|
+
unqualifiedTarget: scope.unqualifiedTarget,
|
|
1294
|
+
getFields: (typeName) => getFieldsForType(doc, typeName)
|
|
1295
|
+
};
|
|
1296
|
+
}
|
|
1297
|
+
const SYMBOLIC_OPS$1 = new Set([
|
|
1298
|
+
"=",
|
|
1299
|
+
"!=",
|
|
1300
|
+
">",
|
|
1301
|
+
">=",
|
|
1302
|
+
"<",
|
|
1303
|
+
"<="
|
|
1304
|
+
]);
|
|
1305
|
+
const KEYWORD_OPS = new Set([
|
|
1306
|
+
"in",
|
|
1307
|
+
"matches",
|
|
1308
|
+
"exists"
|
|
1309
|
+
]);
|
|
1310
|
+
const LOGICAL_KEYWORDS = new Set([
|
|
1311
|
+
"and",
|
|
1312
|
+
"or",
|
|
1313
|
+
"not"
|
|
1314
|
+
]);
|
|
1315
|
+
const VALUE_KEYWORDS$1 = new Set([
|
|
1316
|
+
"true",
|
|
1317
|
+
"false",
|
|
1318
|
+
"null",
|
|
1319
|
+
"undefined"
|
|
1320
|
+
]);
|
|
1321
|
+
function analyzeQueryCursorContext(textBeforeCursor) {
|
|
1322
|
+
const trimmed = textBeforeCursor.trimEnd();
|
|
1323
|
+
const hasTrailingSpace = textBeforeCursor.length > trimmed.length;
|
|
1324
|
+
if (trimmed.length === 0) return { type: "field-start" };
|
|
1325
|
+
if (trimmed.endsWith(".")) {
|
|
1326
|
+
const before = trimmed.slice(0, -1).trimEnd();
|
|
1327
|
+
const match = /(\w+)$/u.exec(before);
|
|
1328
|
+
if (match) return {
|
|
1329
|
+
type: "after-dot",
|
|
1330
|
+
typeName: match[1]
|
|
1331
|
+
};
|
|
1332
|
+
return { type: "field-start" };
|
|
1333
|
+
}
|
|
1334
|
+
const tokens$1 = tokenizeQueryText(trimmed);
|
|
1335
|
+
if (tokens$1.length === 0) return { type: "field-start" };
|
|
1336
|
+
const last = tokens$1[tokens$1.length - 1];
|
|
1337
|
+
if (LOGICAL_KEYWORDS.has(last) || last === "(") return { type: "field-start" };
|
|
1338
|
+
if (SYMBOLIC_OPS$1.has(last)) return { type: "after-operator" };
|
|
1339
|
+
if (last === "in" || last === "matches") return { type: "after-operator" };
|
|
1340
|
+
if (last === "exists") return { type: "after-comparison" };
|
|
1341
|
+
if (VALUE_KEYWORDS$1.has(last)) return { type: "after-comparison" };
|
|
1342
|
+
if (/^['"]/.test(last) || /^\d/.test(last)) return { type: "after-comparison" };
|
|
1343
|
+
if (tokens$1.length >= 2) {
|
|
1344
|
+
const prev = tokens$1[tokens$1.length - 2];
|
|
1345
|
+
if (SYMBOLIC_OPS$1.has(prev) || KEYWORD_OPS.has(prev)) return { type: "after-comparison" };
|
|
1346
|
+
}
|
|
1347
|
+
if (/^\w+$/u.test(last)) {
|
|
1348
|
+
if (!hasTrailingSpace) return { type: "field-start" };
|
|
1349
|
+
return { type: "after-field" };
|
|
1350
|
+
}
|
|
1351
|
+
return { type: "field-start" };
|
|
1352
|
+
}
|
|
1353
|
+
/**
|
|
1354
|
+
* Simple tokenizer for query text — splits into identifiers, operators, and punctuation.
|
|
1355
|
+
* Does NOT need to handle all edge cases; just enough for cursor context analysis.
|
|
1356
|
+
*/ function tokenizeQueryText(text$2) {
|
|
1357
|
+
const tokens$1 = [];
|
|
1358
|
+
let i = 0;
|
|
1359
|
+
while (i < text$2.length) {
|
|
1360
|
+
if (/\s/.test(text$2[i])) {
|
|
1361
|
+
i++;
|
|
1362
|
+
continue;
|
|
1363
|
+
}
|
|
1364
|
+
if (text$2[i] === "'" || text$2[i] === "\"") {
|
|
1365
|
+
const quote = text$2[i];
|
|
1366
|
+
let j = i + 1;
|
|
1367
|
+
while (j < text$2.length && text$2[j] !== quote) {
|
|
1368
|
+
if (text$2[j] === "\\") j++;
|
|
1369
|
+
j++;
|
|
1370
|
+
}
|
|
1371
|
+
tokens$1.push(text$2.slice(i, j + 1));
|
|
1372
|
+
i = j + 1;
|
|
1373
|
+
continue;
|
|
1374
|
+
}
|
|
1375
|
+
if (i + 1 < text$2.length) {
|
|
1376
|
+
const two = text$2.slice(i, i + 2);
|
|
1377
|
+
if (two === "!=" || two === ">=" || two === "<=") {
|
|
1378
|
+
tokens$1.push(two);
|
|
1379
|
+
i += 2;
|
|
1380
|
+
continue;
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
if ("=><(),".includes(text$2[i])) {
|
|
1384
|
+
tokens$1.push(text$2[i]);
|
|
1385
|
+
i++;
|
|
1386
|
+
continue;
|
|
1387
|
+
}
|
|
1388
|
+
if (text$2[i] === ".") {
|
|
1389
|
+
tokens$1.push(".");
|
|
1390
|
+
i++;
|
|
1391
|
+
continue;
|
|
1392
|
+
}
|
|
1393
|
+
if (/[\w]/u.test(text$2[i])) {
|
|
1394
|
+
let j = i;
|
|
1395
|
+
while (j < text$2.length && /[\w]/u.test(text$2[j])) j++;
|
|
1396
|
+
tokens$1.push(text$2.slice(i, j));
|
|
1397
|
+
i = j;
|
|
1398
|
+
continue;
|
|
1399
|
+
}
|
|
1400
|
+
i++;
|
|
1401
|
+
}
|
|
1402
|
+
return tokens$1;
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1110
1405
|
//#endregion
|
|
1111
1406
|
//#region packages/core/src/parser/id-registry.ts
|
|
1112
1407
|
function _define_property$7(obj, key, value) {
|
|
@@ -1297,40 +1592,21 @@ var NodeIterator = class NodeIterator {
|
|
|
1297
1592
|
}
|
|
1298
1593
|
};
|
|
1299
1594
|
|
|
1300
|
-
//#endregion
|
|
1301
|
-
//#region packages/core/src/parser/utils.ts
|
|
1302
|
-
function toVsCodeRange(start, end, startOffset = 0, endOffset = 0) {
|
|
1303
|
-
return {
|
|
1304
|
-
start: {
|
|
1305
|
-
line: start.row - 1,
|
|
1306
|
-
character: start.col + startOffset
|
|
1307
|
-
},
|
|
1308
|
-
end: {
|
|
1309
|
-
line: end.row - 1,
|
|
1310
|
-
character: end.col + endOffset
|
|
1311
|
-
}
|
|
1312
|
-
};
|
|
1313
|
-
}
|
|
1314
|
-
function resolveAtscriptFromPath(from, id) {
|
|
1315
|
-
return `file://${path.default.join(id.slice(7).split("/").slice(0, -1).join("/"), from)}.as`;
|
|
1316
|
-
}
|
|
1317
|
-
function getRelPath(fromUri, toUri) {
|
|
1318
|
-
const fromPath = new url.URL(fromUri).pathname;
|
|
1319
|
-
const toPath = new url.URL(toUri).pathname;
|
|
1320
|
-
const relPath = path.default.relative(path.default.dirname(fromPath), toPath);
|
|
1321
|
-
const { dir, name } = path.default.parse(relPath);
|
|
1322
|
-
const prefix = dir.startsWith("..") ? "" : "./";
|
|
1323
|
-
return `${prefix}${dir ? `${dir}/` : ""}${name}`;
|
|
1324
|
-
}
|
|
1325
|
-
|
|
1326
1595
|
//#endregion
|
|
1327
1596
|
//#region packages/core/src/tokenizer/tokens/a-identifier.token.ts
|
|
1328
|
-
const AIdentifierToken = new __prostojs_parser.
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1597
|
+
const AIdentifierToken = new __prostojs_parser.Node({
|
|
1598
|
+
name: "annotation",
|
|
1599
|
+
start: { token: RegExp("@[\\p{ID_Continue}$.]*", "u") },
|
|
1600
|
+
end: {
|
|
1601
|
+
token: RegExp("[^\\p{ID_Continue}$.]", "u"),
|
|
1602
|
+
eject: true
|
|
1603
|
+
},
|
|
1604
|
+
eofClose: true,
|
|
1605
|
+
data: {
|
|
1606
|
+
type: "annotation",
|
|
1607
|
+
text: ""
|
|
1608
|
+
},
|
|
1609
|
+
mapContent: "text"
|
|
1334
1610
|
});
|
|
1335
1611
|
|
|
1336
1612
|
//#endregion
|
|
@@ -1340,33 +1616,59 @@ const pairs = {
|
|
|
1340
1616
|
"(": ")",
|
|
1341
1617
|
"[": "]"
|
|
1342
1618
|
};
|
|
1343
|
-
const BlockToken = new __prostojs_parser.
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1619
|
+
const BlockToken = new __prostojs_parser.Node({
|
|
1620
|
+
name: "block",
|
|
1621
|
+
start: {
|
|
1622
|
+
token: RegExp("(?<text>[([{])", "u"),
|
|
1623
|
+
omit: true
|
|
1624
|
+
},
|
|
1625
|
+
end: {
|
|
1626
|
+
token: (ctx) => pairs[ctx.node.data.text] || "",
|
|
1627
|
+
omit: true
|
|
1628
|
+
},
|
|
1629
|
+
skip: /\s/u,
|
|
1630
|
+
eofClose: true,
|
|
1631
|
+
data: {
|
|
1632
|
+
type: "block",
|
|
1633
|
+
text: ""
|
|
1634
|
+
}
|
|
1351
1635
|
});
|
|
1352
1636
|
|
|
1353
1637
|
//#endregion
|
|
1354
1638
|
//#region packages/core/src/tokenizer/tokens/comment.token.ts
|
|
1355
|
-
const inline = new __prostojs_parser.
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
}
|
|
1361
|
-
|
|
1639
|
+
const inline = new __prostojs_parser.Node({
|
|
1640
|
+
name: "inline-comment",
|
|
1641
|
+
start: {
|
|
1642
|
+
token: "//",
|
|
1643
|
+
omit: true
|
|
1644
|
+
},
|
|
1645
|
+
end: {
|
|
1646
|
+
token: /$/mu,
|
|
1647
|
+
omit: true
|
|
1648
|
+
},
|
|
1649
|
+
eofClose: true,
|
|
1650
|
+
data: {
|
|
1651
|
+
type: "comment",
|
|
1652
|
+
text: ""
|
|
1653
|
+
},
|
|
1654
|
+
mapContent: "text"
|
|
1362
1655
|
});
|
|
1363
|
-
const block$1 = new __prostojs_parser.
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
}
|
|
1369
|
-
|
|
1656
|
+
const block$1 = new __prostojs_parser.Node({
|
|
1657
|
+
name: "block-comment",
|
|
1658
|
+
start: {
|
|
1659
|
+
token: "/*",
|
|
1660
|
+
omit: true
|
|
1661
|
+
},
|
|
1662
|
+
end: {
|
|
1663
|
+
token: "*/",
|
|
1664
|
+
omit: true
|
|
1665
|
+
},
|
|
1666
|
+
eofClose: true,
|
|
1667
|
+
data: {
|
|
1668
|
+
type: "comment",
|
|
1669
|
+
text: ""
|
|
1670
|
+
},
|
|
1671
|
+
mapContent: "text"
|
|
1370
1672
|
});
|
|
1371
1673
|
const commentNodes = {
|
|
1372
1674
|
inline,
|
|
@@ -1376,58 +1678,141 @@ const commentNodes = {
|
|
|
1376
1678
|
|
|
1377
1679
|
//#endregion
|
|
1378
1680
|
//#region packages/core/src/tokenizer/tokens/identifier.token.ts
|
|
1379
|
-
const IdentifierToken = new __prostojs_parser.
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1681
|
+
const IdentifierToken = new __prostojs_parser.Node({
|
|
1682
|
+
name: "identifier",
|
|
1683
|
+
start: { token: RegExp("[\\p{ID_Start}$_][\\p{ID_Continue}$]*", "u") },
|
|
1684
|
+
end: {
|
|
1685
|
+
token: RegExp("[^\\p{ID_Continue}$]", "u"),
|
|
1686
|
+
eject: true
|
|
1687
|
+
},
|
|
1688
|
+
eofClose: true,
|
|
1689
|
+
data: {
|
|
1690
|
+
type: "identifier",
|
|
1691
|
+
text: ""
|
|
1692
|
+
},
|
|
1693
|
+
mapContent: "text"
|
|
1385
1694
|
});
|
|
1386
1695
|
|
|
1387
1696
|
//#endregion
|
|
1388
1697
|
//#region packages/core/src/tokenizer/tokens/number.token.ts
|
|
1389
|
-
const NumberToken = new __prostojs_parser.
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1698
|
+
const NumberToken = new __prostojs_parser.Node({
|
|
1699
|
+
name: "number",
|
|
1700
|
+
start: { token: /[-+]?(?:\d*\.\d+|\d+)(?:[eE][-+]?\d+)?/u },
|
|
1701
|
+
end: {
|
|
1702
|
+
token: /[^\d]/u,
|
|
1703
|
+
eject: true
|
|
1704
|
+
},
|
|
1705
|
+
eofClose: true,
|
|
1706
|
+
data: {
|
|
1707
|
+
type: "number",
|
|
1708
|
+
text: ""
|
|
1709
|
+
},
|
|
1710
|
+
mapContent: "text"
|
|
1395
1711
|
});
|
|
1396
1712
|
|
|
1397
1713
|
//#endregion
|
|
1398
1714
|
//#region packages/core/src/tokenizer/tokens/punctuation.token.ts
|
|
1399
|
-
const PunctuationToken = new __prostojs_parser.
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1715
|
+
const PunctuationToken = new __prostojs_parser.Node({
|
|
1716
|
+
name: "punctuation",
|
|
1717
|
+
start: {
|
|
1718
|
+
token: RegExp("(?<text>[\\n!&+,./:;=?|])", "u"),
|
|
1719
|
+
omit: true
|
|
1720
|
+
},
|
|
1721
|
+
end: {
|
|
1722
|
+
token: "",
|
|
1723
|
+
omit: true
|
|
1724
|
+
},
|
|
1725
|
+
eofClose: true,
|
|
1726
|
+
data: {
|
|
1727
|
+
type: "punctuation",
|
|
1728
|
+
text: ""
|
|
1729
|
+
}
|
|
1730
|
+
});
|
|
1731
|
+
|
|
1732
|
+
//#endregion
|
|
1733
|
+
//#region packages/core/src/tokenizer/tokens/query-operator.token.ts
|
|
1734
|
+
const QueryOperatorToken = new __prostojs_parser.Node({
|
|
1735
|
+
name: "punctuation",
|
|
1736
|
+
start: {
|
|
1737
|
+
token: RegExp("(?<text>!=|>=|<=|[=><])", "u"),
|
|
1738
|
+
omit: true
|
|
1739
|
+
},
|
|
1740
|
+
end: {
|
|
1741
|
+
token: "",
|
|
1742
|
+
omit: true
|
|
1743
|
+
},
|
|
1744
|
+
eofClose: true,
|
|
1745
|
+
data: {
|
|
1746
|
+
type: "punctuation",
|
|
1747
|
+
text: ""
|
|
1748
|
+
}
|
|
1749
|
+
});
|
|
1750
|
+
|
|
1751
|
+
//#endregion
|
|
1752
|
+
//#region packages/core/src/tokenizer/tokens/query.token.ts
|
|
1753
|
+
const QueryToken = new __prostojs_parser.Node({
|
|
1754
|
+
name: "query",
|
|
1755
|
+
start: {
|
|
1756
|
+
token: /`/u,
|
|
1757
|
+
omit: true
|
|
1758
|
+
},
|
|
1759
|
+
end: {
|
|
1760
|
+
token: /`/u,
|
|
1761
|
+
omit: true
|
|
1762
|
+
},
|
|
1763
|
+
skip: /\s/u,
|
|
1764
|
+
eofClose: true,
|
|
1765
|
+
data: {
|
|
1766
|
+
type: "query",
|
|
1767
|
+
text: ""
|
|
1768
|
+
}
|
|
1405
1769
|
});
|
|
1406
1770
|
|
|
1407
1771
|
//#endregion
|
|
1408
1772
|
//#region packages/core/src/tokenizer/tokens/regexp.token.ts
|
|
1409
1773
|
const REGEXP_LITERAL_RE = /\/(?![/*])(?:\\.|\[.*?]|[^/\\\n\r[])*\/[dgimsuy]*/;
|
|
1410
|
-
const RegExpToken = new __prostojs_parser.
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
}
|
|
1416
|
-
|
|
1417
|
-
|
|
1774
|
+
const RegExpToken = new __prostojs_parser.Node({
|
|
1775
|
+
name: "regexp",
|
|
1776
|
+
start: {
|
|
1777
|
+
token: REGEXP_LITERAL_RE,
|
|
1778
|
+
omit: true
|
|
1779
|
+
},
|
|
1780
|
+
end: {
|
|
1781
|
+
token: "",
|
|
1782
|
+
omit: true
|
|
1783
|
+
},
|
|
1784
|
+
eofClose: true,
|
|
1785
|
+
data: {
|
|
1786
|
+
type: "regexp",
|
|
1787
|
+
text: ""
|
|
1788
|
+
}
|
|
1789
|
+
}).onOpen((node, match) => {
|
|
1790
|
+
node.data.text = match?.text ?? "";
|
|
1418
1791
|
});
|
|
1419
1792
|
|
|
1420
1793
|
//#endregion
|
|
1421
1794
|
//#region packages/core/src/tokenizer/tokens/text.node.ts
|
|
1422
|
-
const TextToken = new __prostojs_parser.
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
}
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1795
|
+
const TextToken = new __prostojs_parser.Node({
|
|
1796
|
+
name: "text",
|
|
1797
|
+
start: {
|
|
1798
|
+
token: RegExp("(?<quote>[\"'])", "u"),
|
|
1799
|
+
omit: true
|
|
1800
|
+
},
|
|
1801
|
+
end: {
|
|
1802
|
+
token: (ctx) => new RegExp(`(?<end>${ctx.node.data.quote || ""}|\\n)`),
|
|
1803
|
+
omit: true,
|
|
1804
|
+
backslash: true
|
|
1805
|
+
},
|
|
1806
|
+
eofClose: true,
|
|
1807
|
+
data: {
|
|
1808
|
+
type: "text",
|
|
1809
|
+
quote: "",
|
|
1810
|
+
end: "",
|
|
1811
|
+
text: ""
|
|
1812
|
+
},
|
|
1813
|
+
mapContent: "text"
|
|
1814
|
+
}).onClose((node) => {
|
|
1815
|
+
node.data.multiline = node.data.end === "\n";
|
|
1431
1816
|
});
|
|
1432
1817
|
|
|
1433
1818
|
//#endregion
|
|
@@ -1443,31 +1828,55 @@ const tokens = {
|
|
|
1443
1828
|
number: NumberToken,
|
|
1444
1829
|
text: TextToken,
|
|
1445
1830
|
regexp: RegExpToken,
|
|
1831
|
+
query: QueryToken,
|
|
1446
1832
|
root: undefined
|
|
1447
1833
|
};
|
|
1448
|
-
const root = new __prostojs_parser.
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1834
|
+
const root = new __prostojs_parser.Node({
|
|
1835
|
+
name: "root",
|
|
1836
|
+
skip: /\s/u,
|
|
1837
|
+
eofClose: true,
|
|
1838
|
+
recognizes: [
|
|
1839
|
+
...commentNodes.all,
|
|
1840
|
+
BlockToken,
|
|
1841
|
+
QueryToken,
|
|
1842
|
+
AIdentifierToken,
|
|
1843
|
+
IdentifierToken,
|
|
1844
|
+
TextToken,
|
|
1845
|
+
NumberToken,
|
|
1846
|
+
PunctuationToken
|
|
1847
|
+
]
|
|
1462
1848
|
});
|
|
1463
|
-
|
|
1849
|
+
tokens.root = root;
|
|
1850
|
+
BlockToken.recognize(RegExpToken, ...commentNodes.all, BlockToken, QueryToken, AIdentifierToken, IdentifierToken, TextToken, NumberToken, PunctuationToken);
|
|
1851
|
+
QueryToken.recognize(RegExpToken, QueryOperatorToken, BlockToken, IdentifierToken, TextToken, NumberToken, PunctuationToken);
|
|
1852
|
+
function extractTokens(node) {
|
|
1853
|
+
return node.content.map((item) => {
|
|
1854
|
+
if (typeof item === "string") return {
|
|
1855
|
+
type: "unknown",
|
|
1856
|
+
text: item
|
|
1857
|
+
};
|
|
1858
|
+
const data = item.data;
|
|
1859
|
+
data.getRange = () => ({
|
|
1860
|
+
start: {
|
|
1861
|
+
line: item.start.line - 1,
|
|
1862
|
+
character: item.start.column - 1 + (data.startOffset ?? 0)
|
|
1863
|
+
},
|
|
1864
|
+
end: {
|
|
1865
|
+
line: item.end.line - 1,
|
|
1866
|
+
character: item.end.column - 1 + (data.endOffset ?? 0)
|
|
1867
|
+
}
|
|
1868
|
+
});
|
|
1869
|
+
data.children = extractTokens(item);
|
|
1870
|
+
return data;
|
|
1871
|
+
});
|
|
1872
|
+
}
|
|
1464
1873
|
|
|
1465
1874
|
//#endregion
|
|
1466
1875
|
//#region packages/core/src/tokenizer/index.ts
|
|
1467
1876
|
function tokenize(source, debug = false) {
|
|
1468
|
-
const
|
|
1469
|
-
if (debug) console.log(
|
|
1470
|
-
return
|
|
1877
|
+
const result = root.parse(source);
|
|
1878
|
+
if (debug) console.log((0, __prostojs_parser.printTree)(result));
|
|
1879
|
+
return extractTokens(result);
|
|
1471
1880
|
}
|
|
1472
1881
|
|
|
1473
1882
|
//#endregion
|
|
@@ -1722,6 +2131,298 @@ else if (isOperator && !(node instanceof Token)) throw new Error(`Unexpected tok
|
|
|
1722
2131
|
return output.length === 1 ? output.first : output;
|
|
1723
2132
|
}
|
|
1724
2133
|
|
|
2134
|
+
//#endregion
|
|
2135
|
+
//#region packages/core/src/parser/pipes/query.pipe.ts
|
|
2136
|
+
const SYMBOLIC_OPS = new Set([
|
|
2137
|
+
"=",
|
|
2138
|
+
"!=",
|
|
2139
|
+
">",
|
|
2140
|
+
">=",
|
|
2141
|
+
"<",
|
|
2142
|
+
"<="
|
|
2143
|
+
]);
|
|
2144
|
+
const VALUE_KEYWORDS = new Set([
|
|
2145
|
+
"true",
|
|
2146
|
+
"false",
|
|
2147
|
+
"null",
|
|
2148
|
+
"undefined"
|
|
2149
|
+
]);
|
|
2150
|
+
function parseQueryExpression(children, messages, sourceToken) {
|
|
2151
|
+
if (children.length === 0) return undefined;
|
|
2152
|
+
const ni = new NodeIterator(children, messages);
|
|
2153
|
+
ni.move();
|
|
2154
|
+
const expr = parseOrExpr(ni, messages);
|
|
2155
|
+
if (!expr) return undefined;
|
|
2156
|
+
if (ni.$) messages.push({
|
|
2157
|
+
severity: 1,
|
|
2158
|
+
message: `Unexpected token in query expression: "${ni.$.text}"`,
|
|
2159
|
+
range: ni.$.getRange?.() ?? {
|
|
2160
|
+
start: {
|
|
2161
|
+
line: 0,
|
|
2162
|
+
character: 0
|
|
2163
|
+
},
|
|
2164
|
+
end: {
|
|
2165
|
+
line: 0,
|
|
2166
|
+
character: 0
|
|
2167
|
+
}
|
|
2168
|
+
}
|
|
2169
|
+
});
|
|
2170
|
+
const node = new SemanticQueryNode();
|
|
2171
|
+
node.expression = expr;
|
|
2172
|
+
node.sourceToken = sourceToken;
|
|
2173
|
+
return node;
|
|
2174
|
+
}
|
|
2175
|
+
function parseOrExpr(ni, messages) {
|
|
2176
|
+
const left = parseAndExpr(ni, messages);
|
|
2177
|
+
if (!left) return undefined;
|
|
2178
|
+
const operands = [left];
|
|
2179
|
+
while (ni.$?.type === "identifier" && ni.$.text === "or") {
|
|
2180
|
+
ni.move();
|
|
2181
|
+
const right = parseAndExpr(ni, messages);
|
|
2182
|
+
if (!right) {
|
|
2183
|
+
pushError(ni, messages, "Expected expression after \"or\"");
|
|
2184
|
+
break;
|
|
2185
|
+
}
|
|
2186
|
+
operands.push(right);
|
|
2187
|
+
}
|
|
2188
|
+
if (operands.length === 1) return operands[0];
|
|
2189
|
+
const node = new SemanticQueryLogicalNode();
|
|
2190
|
+
node.operator = "or";
|
|
2191
|
+
node.operands = operands;
|
|
2192
|
+
return node;
|
|
2193
|
+
}
|
|
2194
|
+
function parseAndExpr(ni, messages) {
|
|
2195
|
+
const left = parseUnaryExpr(ni, messages);
|
|
2196
|
+
if (!left) return undefined;
|
|
2197
|
+
const operands = [left];
|
|
2198
|
+
while (ni.$?.type === "identifier" && ni.$.text === "and") {
|
|
2199
|
+
ni.move();
|
|
2200
|
+
const right = parseUnaryExpr(ni, messages);
|
|
2201
|
+
if (!right) {
|
|
2202
|
+
pushError(ni, messages, "Expected expression after \"and\"");
|
|
2203
|
+
break;
|
|
2204
|
+
}
|
|
2205
|
+
operands.push(right);
|
|
2206
|
+
}
|
|
2207
|
+
if (operands.length === 1) return operands[0];
|
|
2208
|
+
const node = new SemanticQueryLogicalNode();
|
|
2209
|
+
node.operator = "and";
|
|
2210
|
+
node.operands = operands;
|
|
2211
|
+
return node;
|
|
2212
|
+
}
|
|
2213
|
+
function parseUnaryExpr(ni, messages) {
|
|
2214
|
+
if (ni.$?.type === "identifier" && ni.$.text === "not") {
|
|
2215
|
+
ni.move();
|
|
2216
|
+
const operand = parseUnaryExpr(ni, messages);
|
|
2217
|
+
if (!operand) {
|
|
2218
|
+
pushError(ni, messages, "Expected expression after \"not\"");
|
|
2219
|
+
return undefined;
|
|
2220
|
+
}
|
|
2221
|
+
const node = new SemanticQueryLogicalNode();
|
|
2222
|
+
node.operator = "not";
|
|
2223
|
+
node.operands = [operand];
|
|
2224
|
+
return node;
|
|
2225
|
+
}
|
|
2226
|
+
if (ni.$?.type === "block" && ni.$.text === "(") {
|
|
2227
|
+
const blockChildren = ni.$.children || [];
|
|
2228
|
+
ni.move();
|
|
2229
|
+
if (blockChildren.length === 0) {
|
|
2230
|
+
pushError(ni, messages, "Empty parenthesized expression");
|
|
2231
|
+
return undefined;
|
|
2232
|
+
}
|
|
2233
|
+
const subNi = new NodeIterator(blockChildren, messages);
|
|
2234
|
+
subNi.move();
|
|
2235
|
+
const expr = parseOrExpr(subNi, messages);
|
|
2236
|
+
if (subNi.$) pushError(subNi, messages, `Unexpected token in parenthesized expression: "${subNi.$.text}"`);
|
|
2237
|
+
return expr;
|
|
2238
|
+
}
|
|
2239
|
+
return parseComparison(ni, messages);
|
|
2240
|
+
}
|
|
2241
|
+
function parseComparison(ni, messages) {
|
|
2242
|
+
const left = parseFieldRef(ni, messages);
|
|
2243
|
+
if (!left) return undefined;
|
|
2244
|
+
if (ni.$?.type === "punctuation" && SYMBOLIC_OPS.has(ni.$.text)) {
|
|
2245
|
+
const opText = ni.$.text;
|
|
2246
|
+
ni.move();
|
|
2247
|
+
const right = parseValueOrFieldRef(ni, messages);
|
|
2248
|
+
if (!right) {
|
|
2249
|
+
pushError(ni, messages, `Expected value or field reference after "${opText}"`);
|
|
2250
|
+
return undefined;
|
|
2251
|
+
}
|
|
2252
|
+
const node = new SemanticQueryComparisonNode();
|
|
2253
|
+
node.left = left;
|
|
2254
|
+
node.operator = opText;
|
|
2255
|
+
node.right = right;
|
|
2256
|
+
return node;
|
|
2257
|
+
}
|
|
2258
|
+
if (ni.$?.type === "identifier") {
|
|
2259
|
+
const opText = ni.$.text;
|
|
2260
|
+
if (opText === "in") {
|
|
2261
|
+
ni.move();
|
|
2262
|
+
const right = parseValueList(ni, messages);
|
|
2263
|
+
if (!right) return undefined;
|
|
2264
|
+
const node = new SemanticQueryComparisonNode();
|
|
2265
|
+
node.left = left;
|
|
2266
|
+
node.operator = "in";
|
|
2267
|
+
node.right = right;
|
|
2268
|
+
return node;
|
|
2269
|
+
}
|
|
2270
|
+
if (opText === "matches") {
|
|
2271
|
+
ni.move();
|
|
2272
|
+
const right = parseValueOrFieldRef(ni, messages);
|
|
2273
|
+
if (!right) {
|
|
2274
|
+
pushError(ni, messages, "Expected value after \"matches\"");
|
|
2275
|
+
return undefined;
|
|
2276
|
+
}
|
|
2277
|
+
const node = new SemanticQueryComparisonNode();
|
|
2278
|
+
node.left = left;
|
|
2279
|
+
node.operator = "matches";
|
|
2280
|
+
node.right = right;
|
|
2281
|
+
return node;
|
|
2282
|
+
}
|
|
2283
|
+
if (opText === "exists") {
|
|
2284
|
+
ni.move();
|
|
2285
|
+
const node = new SemanticQueryComparisonNode();
|
|
2286
|
+
node.left = left;
|
|
2287
|
+
node.operator = "exists";
|
|
2288
|
+
return node;
|
|
2289
|
+
}
|
|
2290
|
+
if (opText === "not") return parseNotComparison(ni, messages, left);
|
|
2291
|
+
pushError(ni, messages, `Unknown operator "${opText}"`);
|
|
2292
|
+
return undefined;
|
|
2293
|
+
}
|
|
2294
|
+
pushError(ni, messages, "Expected operator after field reference");
|
|
2295
|
+
return undefined;
|
|
2296
|
+
}
|
|
2297
|
+
function parseNotComparison(ni, messages, left) {
|
|
2298
|
+
ni.move();
|
|
2299
|
+
if (ni.$?.type === "identifier" && ni.$.text === "in") {
|
|
2300
|
+
ni.move();
|
|
2301
|
+
const right = parseValueList(ni, messages);
|
|
2302
|
+
if (!right) return undefined;
|
|
2303
|
+
const node = new SemanticQueryComparisonNode();
|
|
2304
|
+
node.left = left;
|
|
2305
|
+
node.operator = "not in";
|
|
2306
|
+
node.right = right;
|
|
2307
|
+
return node;
|
|
2308
|
+
}
|
|
2309
|
+
if (ni.$?.type === "identifier" && ni.$.text === "exists") {
|
|
2310
|
+
ni.move();
|
|
2311
|
+
const node = new SemanticQueryComparisonNode();
|
|
2312
|
+
node.left = left;
|
|
2313
|
+
node.operator = "not exists";
|
|
2314
|
+
return node;
|
|
2315
|
+
}
|
|
2316
|
+
pushError(ni, messages, "Expected \"in\" or \"exists\" after \"not\"");
|
|
2317
|
+
return undefined;
|
|
2318
|
+
}
|
|
2319
|
+
function parseFieldRef(ni, messages) {
|
|
2320
|
+
if (ni.$?.type !== "identifier") {
|
|
2321
|
+
pushError(ni, messages, "Expected field reference");
|
|
2322
|
+
return undefined;
|
|
2323
|
+
}
|
|
2324
|
+
const firstToken = new Token(ni.$);
|
|
2325
|
+
ni.move();
|
|
2326
|
+
if (ni.$?.type === "punctuation" && ni.$.text === ".") {
|
|
2327
|
+
ni.move();
|
|
2328
|
+
if (ni.$?.type === "identifier") {
|
|
2329
|
+
const secondToken = new Token(ni.$);
|
|
2330
|
+
ni.move();
|
|
2331
|
+
let fieldText = secondToken.text;
|
|
2332
|
+
while (ni.$?.type === "punctuation" && ni.$.text === ".") {
|
|
2333
|
+
ni.move();
|
|
2334
|
+
if (ni.$?.type === "identifier") {
|
|
2335
|
+
fieldText += `.${ni.$.text}`;
|
|
2336
|
+
ni.move();
|
|
2337
|
+
} else {
|
|
2338
|
+
pushError(ni, messages, "Expected identifier after \".\"");
|
|
2339
|
+
break;
|
|
2340
|
+
}
|
|
2341
|
+
}
|
|
2342
|
+
const node$2 = new SemanticQueryFieldRefNode();
|
|
2343
|
+
node$2.typeRef = firstToken;
|
|
2344
|
+
if (fieldText !== secondToken.text) node$2.fieldRef = secondToken.clone({ text: fieldText });
|
|
2345
|
+
else node$2.fieldRef = secondToken;
|
|
2346
|
+
return node$2;
|
|
2347
|
+
}
|
|
2348
|
+
pushError(ni, messages, "Expected identifier after \".\"");
|
|
2349
|
+
const node$1 = new SemanticQueryFieldRefNode();
|
|
2350
|
+
node$1.fieldRef = firstToken;
|
|
2351
|
+
return node$1;
|
|
2352
|
+
}
|
|
2353
|
+
const node = new SemanticQueryFieldRefNode();
|
|
2354
|
+
node.fieldRef = firstToken;
|
|
2355
|
+
return node;
|
|
2356
|
+
}
|
|
2357
|
+
function parseValueOrFieldRef(ni, messages) {
|
|
2358
|
+
if (!ni.$) return undefined;
|
|
2359
|
+
if (ni.$.type === "text" || ni.$.type === "number" || ni.$.type === "regexp") return parseValue(ni, messages);
|
|
2360
|
+
if (ni.$.type === "identifier") {
|
|
2361
|
+
if (VALUE_KEYWORDS.has(ni.$.text)) return parseValue(ni, messages);
|
|
2362
|
+
return parseFieldRef(ni, messages);
|
|
2363
|
+
}
|
|
2364
|
+
pushError(ni, messages, "Expected value or field reference");
|
|
2365
|
+
return undefined;
|
|
2366
|
+
}
|
|
2367
|
+
function parseValue(ni, messages) {
|
|
2368
|
+
if (!ni.$) {
|
|
2369
|
+
pushError(ni, messages, "Expected value");
|
|
2370
|
+
return undefined;
|
|
2371
|
+
}
|
|
2372
|
+
const token = ni.$;
|
|
2373
|
+
if (token.type === "text" || token.type === "number" || token.type === "regexp" || token.type === "identifier" && VALUE_KEYWORDS.has(token.text)) {
|
|
2374
|
+
const node = new SemanticQueryValueNode();
|
|
2375
|
+
node.valueToken = new Token(token);
|
|
2376
|
+
ni.move();
|
|
2377
|
+
return node;
|
|
2378
|
+
}
|
|
2379
|
+
pushError(ni, messages, `Unexpected token "${token.text}" where value expected`);
|
|
2380
|
+
return undefined;
|
|
2381
|
+
}
|
|
2382
|
+
function parseValueList(ni, messages) {
|
|
2383
|
+
if (ni.$?.type === "block" && ni.$.text === "(") {
|
|
2384
|
+
const blockChildren = ni.$.children || [];
|
|
2385
|
+
ni.move();
|
|
2386
|
+
const values = [];
|
|
2387
|
+
if (blockChildren.length === 0) {
|
|
2388
|
+
pushError(ni, messages, "Empty value list in \"in\" expression");
|
|
2389
|
+
return undefined;
|
|
2390
|
+
}
|
|
2391
|
+
const subNi = new NodeIterator(blockChildren, messages);
|
|
2392
|
+
subNi.move();
|
|
2393
|
+
const first = parseValue(subNi, messages);
|
|
2394
|
+
if (first) values.push(first);
|
|
2395
|
+
while (subNi.$?.type === "punctuation" && subNi.$.text === ",") {
|
|
2396
|
+
subNi.move();
|
|
2397
|
+
const v = parseValue(subNi, messages);
|
|
2398
|
+
if (v) values.push(v);
|
|
2399
|
+
}
|
|
2400
|
+
if (subNi.$) pushError(subNi, messages, `Unexpected token in value list: "${subNi.$.text}"`);
|
|
2401
|
+
const node = new SemanticQueryValueListNode();
|
|
2402
|
+
node.values = values;
|
|
2403
|
+
return node;
|
|
2404
|
+
}
|
|
2405
|
+
pushError(ni, messages, "Expected parenthesized value list after \"in\"");
|
|
2406
|
+
return undefined;
|
|
2407
|
+
}
|
|
2408
|
+
function pushError(ni, messages, message) {
|
|
2409
|
+
const range = ni.$?.getRange?.() ?? {
|
|
2410
|
+
start: {
|
|
2411
|
+
line: 0,
|
|
2412
|
+
character: 0
|
|
2413
|
+
},
|
|
2414
|
+
end: {
|
|
2415
|
+
line: 0,
|
|
2416
|
+
character: 0
|
|
2417
|
+
}
|
|
2418
|
+
};
|
|
2419
|
+
messages.push({
|
|
2420
|
+
severity: 1,
|
|
2421
|
+
message,
|
|
2422
|
+
range
|
|
2423
|
+
});
|
|
2424
|
+
}
|
|
2425
|
+
|
|
1725
2426
|
//#endregion
|
|
1726
2427
|
//#region packages/core/src/parser/pipes/special.pipe.ts
|
|
1727
2428
|
function refWithChain() {
|
|
@@ -1800,15 +2501,25 @@ else {
|
|
|
1800
2501
|
function annotations() {
|
|
1801
2502
|
const opts = {
|
|
1802
2503
|
annotation: { node: "annotation" },
|
|
1803
|
-
argument: [
|
|
1804
|
-
node: "
|
|
1805
|
-
|
|
1806
|
-
"
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
2504
|
+
argument: [
|
|
2505
|
+
{ node: ["number", "text"] },
|
|
2506
|
+
{
|
|
2507
|
+
node: "identifier",
|
|
2508
|
+
text: [
|
|
2509
|
+
"true",
|
|
2510
|
+
"false",
|
|
2511
|
+
"undefined",
|
|
2512
|
+
"null"
|
|
2513
|
+
]
|
|
2514
|
+
},
|
|
2515
|
+
{ node: "identifier" },
|
|
2516
|
+
{ node: "query" }
|
|
2517
|
+
],
|
|
2518
|
+
dot: {
|
|
2519
|
+
node: "punctuation",
|
|
2520
|
+
text: "."
|
|
2521
|
+
},
|
|
2522
|
+
ident: { node: "identifier" },
|
|
1812
2523
|
comma: {
|
|
1813
2524
|
node: "punctuation",
|
|
1814
2525
|
text: ","
|
|
@@ -1830,9 +2541,30 @@ function annotations() {
|
|
|
1830
2541
|
ni.move();
|
|
1831
2542
|
}
|
|
1832
2543
|
while (ni.satisfies(...opts.argument)) {
|
|
1833
|
-
|
|
2544
|
+
let argToken = new Token(ni.$);
|
|
1834
2545
|
ni.accepted();
|
|
1835
2546
|
ni.move();
|
|
2547
|
+
if (argToken.type === "identifier" && ![
|
|
2548
|
+
"true",
|
|
2549
|
+
"false",
|
|
2550
|
+
"undefined",
|
|
2551
|
+
"null"
|
|
2552
|
+
].includes(argToken.text)) {
|
|
2553
|
+
let chainText = argToken.text;
|
|
2554
|
+
while (ni.satisfies(opts.dot) && ni.next()?.satisfies(opts.ident)) {
|
|
2555
|
+
ni.accepted();
|
|
2556
|
+
ni.move();
|
|
2557
|
+
chainText += `.${ni.$.text}`;
|
|
2558
|
+
ni.accepted();
|
|
2559
|
+
ni.move();
|
|
2560
|
+
}
|
|
2561
|
+
if (chainText !== argToken.text) argToken = argToken.clone({ text: chainText });
|
|
2562
|
+
}
|
|
2563
|
+
if (argToken.type === "query") {
|
|
2564
|
+
const queryNode = parseQueryExpression(argToken.children, ni.messages, argToken);
|
|
2565
|
+
if (queryNode) argToken.queryNode = queryNode;
|
|
2566
|
+
}
|
|
2567
|
+
addArgument(argToken);
|
|
1836
2568
|
if (ni.satisfies(opts.comma)) {
|
|
1837
2569
|
ni.accepted();
|
|
1838
2570
|
ni.move();
|
|
@@ -2163,6 +2895,20 @@ var TSeverity = /*#__PURE__*/ function(TSeverity$1) {
|
|
|
2163
2895
|
return TSeverity$1;
|
|
2164
2896
|
}({});
|
|
2165
2897
|
|
|
2898
|
+
//#endregion
|
|
2899
|
+
//#region packages/core/src/parser/utils.ts
|
|
2900
|
+
function resolveAtscriptFromPath(from, id) {
|
|
2901
|
+
return `file://${path.default.join(id.slice(7).split("/").slice(0, -1).join("/"), from)}.as`;
|
|
2902
|
+
}
|
|
2903
|
+
function getRelPath(fromUri, toUri) {
|
|
2904
|
+
const fromPath = new url.URL(fromUri).pathname;
|
|
2905
|
+
const toPath = new url.URL(toUri).pathname;
|
|
2906
|
+
const relPath = path.default.relative(path.default.dirname(fromPath), toPath);
|
|
2907
|
+
const { dir, name } = path.default.parse(relPath);
|
|
2908
|
+
const prefix = dir.startsWith("..") ? "" : "./";
|
|
2909
|
+
return `${prefix}${dir ? `${dir}/` : ""}${name}`;
|
|
2910
|
+
}
|
|
2911
|
+
|
|
2166
2912
|
//#endregion
|
|
2167
2913
|
//#region packages/core/src/token-index/blocks-index.ts
|
|
2168
2914
|
function _define_property$5(obj, key, value) {
|
|
@@ -2285,7 +3031,11 @@ var TokensIndex = class {
|
|
|
2285
3031
|
*/ at(line, character) {
|
|
2286
3032
|
const tokens$1 = this.tokensMap[line];
|
|
2287
3033
|
if (!tokens$1) return undefined;
|
|
2288
|
-
|
|
3034
|
+
let best;
|
|
3035
|
+
for (const t of tokens$1) if (t.range.start.character <= character && t.range.end.character >= character) {
|
|
3036
|
+
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;
|
|
3037
|
+
}
|
|
3038
|
+
return best;
|
|
2289
3039
|
}
|
|
2290
3040
|
/**
|
|
2291
3041
|
* Retrieves either the token at the specified (line, character), or if none exists,
|
|
@@ -2387,6 +3137,7 @@ var AtscriptDoc = class {
|
|
|
2387
3137
|
this.importedDefs.clear();
|
|
2388
3138
|
this.messages = [];
|
|
2389
3139
|
this.referred = [];
|
|
3140
|
+
this.queryFieldRefs = [];
|
|
2390
3141
|
this.imports.clear();
|
|
2391
3142
|
this._allMessages = undefined;
|
|
2392
3143
|
this.tokensIndex = new TokensIndex();
|
|
@@ -2415,6 +3166,23 @@ var AtscriptDoc = class {
|
|
|
2415
3166
|
this.registerMessages(annotationSpec.validate(mainToken, args || [], this));
|
|
2416
3167
|
annotationSpec.modify(mainToken, args || [], this);
|
|
2417
3168
|
this.resolvedAnnotations.push(mainToken);
|
|
3169
|
+
const specArgs = annotationSpec.arguments;
|
|
3170
|
+
for (let i = 0; i < (args?.length ?? 0); i++) {
|
|
3171
|
+
const argSpec = specArgs[i];
|
|
3172
|
+
if (argSpec?.type === "ref" && args?.[i]) {
|
|
3173
|
+
const refToken = args[i];
|
|
3174
|
+
const dotIdx = refToken.text.indexOf(".");
|
|
3175
|
+
if (dotIdx > 0) {
|
|
3176
|
+
const typeToken = refToken.clone({ text: refToken.text.slice(0, dotIdx) });
|
|
3177
|
+
typeToken.isReference = true;
|
|
3178
|
+
this.referred.push(typeToken);
|
|
3179
|
+
} else {
|
|
3180
|
+
refToken.isReference = true;
|
|
3181
|
+
this.referred.push(refToken);
|
|
3182
|
+
}
|
|
3183
|
+
}
|
|
3184
|
+
if (argSpec?.type === "query" && args?.[i]?.queryNode) args[i].queryNode.registerAtDocument(this);
|
|
3185
|
+
}
|
|
2418
3186
|
} else {
|
|
2419
3187
|
let severity = 0;
|
|
2420
3188
|
switch (this.config.unknownAnnotation) {
|
|
@@ -2622,6 +3390,17 @@ else {
|
|
|
2622
3390
|
});
|
|
2623
3391
|
}
|
|
2624
3392
|
}
|
|
3393
|
+
for (const qfr of doc.queryFieldRefs) {
|
|
3394
|
+
if (!qfr.queryArgToken || qfr.fieldRef.text !== propName$1) continue;
|
|
3395
|
+
const scope = getQueryScope(qfr.queryArgToken, doc);
|
|
3396
|
+
if (!scope) continue;
|
|
3397
|
+
const resolvedTypeName = qfr.typeRef?.text ?? scope.unqualifiedTarget;
|
|
3398
|
+
if (resolvedTypeName === parentName) refs.push({
|
|
3399
|
+
uri,
|
|
3400
|
+
range: qfr.fieldRef.range,
|
|
3401
|
+
token: qfr.fieldRef
|
|
3402
|
+
});
|
|
3403
|
+
}
|
|
2625
3404
|
};
|
|
2626
3405
|
searchDoc(this, this.id);
|
|
2627
3406
|
const parentDefToken = this.registry.definitions.get(parentName);
|
|
@@ -2633,7 +3412,23 @@ else {
|
|
|
2633
3412
|
}
|
|
2634
3413
|
}
|
|
2635
3414
|
return refs;
|
|
2636
|
-
}
|
|
3415
|
+
}
|
|
3416
|
+
if (isQueryFieldRef(token.parentNode) && token === token.parentNode.fieldRef) {
|
|
3417
|
+
const fieldRefNode = token.parentNode;
|
|
3418
|
+
const queryArgToken = fieldRefNode.queryArgToken;
|
|
3419
|
+
if (queryArgToken) {
|
|
3420
|
+
const scope = getQueryScope(queryArgToken, this);
|
|
3421
|
+
if (scope) {
|
|
3422
|
+
const resolved = resolveQueryFieldRef(fieldRefNode, this, scope);
|
|
3423
|
+
if (resolved?.prop) {
|
|
3424
|
+
const propToken = resolved.prop.token("identifier");
|
|
3425
|
+
if (propToken) return resolved.doc.usageListFor(propToken);
|
|
3426
|
+
}
|
|
3427
|
+
}
|
|
3428
|
+
}
|
|
3429
|
+
return undefined;
|
|
3430
|
+
}
|
|
3431
|
+
{
|
|
2637
3432
|
const defForToken = this.getDefinitionFor(token);
|
|
2638
3433
|
if (defForToken?.token?.isDefinition && defForToken.doc) return defForToken.doc.usageListFor(defForToken.token);
|
|
2639
3434
|
}
|
|
@@ -2707,6 +3502,37 @@ else {
|
|
|
2707
3502
|
}];
|
|
2708
3503
|
return undefined;
|
|
2709
3504
|
}
|
|
3505
|
+
if (isQueryFieldRef(token.parentNode)) {
|
|
3506
|
+
const fieldRefNode = token.parentNode;
|
|
3507
|
+
const queryArgToken = fieldRefNode.queryArgToken;
|
|
3508
|
+
if (queryArgToken) {
|
|
3509
|
+
const scope = getQueryScope(queryArgToken, this);
|
|
3510
|
+
if (scope) {
|
|
3511
|
+
if (token === fieldRefNode.typeRef) {
|
|
3512
|
+
const result = this.getDefinitionFor(token);
|
|
3513
|
+
return result ? [{
|
|
3514
|
+
targetUri: result.uri,
|
|
3515
|
+
targetRange: result.token?.range ?? zeroRange,
|
|
3516
|
+
targetSelectionRange: result.token?.range ?? zeroRange,
|
|
3517
|
+
originSelectionRange: token.range
|
|
3518
|
+
}] : undefined;
|
|
3519
|
+
}
|
|
3520
|
+
if (token === fieldRefNode.fieldRef) {
|
|
3521
|
+
const resolved = resolveQueryFieldRef(fieldRefNode, this, scope);
|
|
3522
|
+
if (resolved?.prop) {
|
|
3523
|
+
const propToken = resolved.prop.token("identifier");
|
|
3524
|
+
return [{
|
|
3525
|
+
targetUri: resolved.targetUri,
|
|
3526
|
+
targetRange: propToken?.range ?? zeroRange,
|
|
3527
|
+
targetSelectionRange: propToken?.range ?? zeroRange,
|
|
3528
|
+
originSelectionRange: token.range
|
|
3529
|
+
}];
|
|
3530
|
+
}
|
|
3531
|
+
}
|
|
3532
|
+
}
|
|
3533
|
+
}
|
|
3534
|
+
return undefined;
|
|
3535
|
+
}
|
|
2710
3536
|
if (isProp(token.parentNode)) return [{
|
|
2711
3537
|
targetUri: this.id,
|
|
2712
3538
|
targetRange: token.range,
|
|
@@ -3163,6 +3989,9 @@ else {
|
|
|
3163
3989
|
* List of tokens that refer to some type or interface
|
|
3164
3990
|
*/ _define_property$3(this, "referred", void 0);
|
|
3165
3991
|
/**
|
|
3992
|
+
* List of query field ref nodes (for find-references support)
|
|
3993
|
+
*/ _define_property$3(this, "queryFieldRefs", void 0);
|
|
3994
|
+
/**
|
|
3166
3995
|
* Map of dependencies (documents) by URI
|
|
3167
3996
|
*/ _define_property$3(this, "dependenciesMap", void 0);
|
|
3168
3997
|
_define_property$3(this, "nodes", void 0);
|
|
@@ -3184,6 +4013,7 @@ else {
|
|
|
3184
4013
|
this.dependencies = new Set();
|
|
3185
4014
|
this.dependants = new Set();
|
|
3186
4015
|
this.referred = [];
|
|
4016
|
+
this.queryFieldRefs = [];
|
|
3187
4017
|
this.dependenciesMap = new Map();
|
|
3188
4018
|
this.nodes = [];
|
|
3189
4019
|
this._text = "";
|
|
@@ -3216,6 +4046,42 @@ function createSyntheticRef(name) {
|
|
|
3216
4046
|
|
|
3217
4047
|
//#endregion
|
|
3218
4048
|
//#region packages/core/src/defaults/db-utils.ts
|
|
4049
|
+
function validateRefArgument(token, doc, options) {
|
|
4050
|
+
const messages = [];
|
|
4051
|
+
const text$2 = token.text;
|
|
4052
|
+
const [typeName, ...chain] = text$2.split(".");
|
|
4053
|
+
const decl = doc.getDeclarationOwnerNode(typeName);
|
|
4054
|
+
if (!decl) {
|
|
4055
|
+
const regDef = doc.registry.definitions.get(typeName);
|
|
4056
|
+
if (regDef?.imported) return messages;
|
|
4057
|
+
messages.push({
|
|
4058
|
+
severity: 1,
|
|
4059
|
+
message: `Unknown type '${typeName}'.`,
|
|
4060
|
+
range: token.range
|
|
4061
|
+
});
|
|
4062
|
+
return messages;
|
|
4063
|
+
}
|
|
4064
|
+
if (chain.length > 0) {
|
|
4065
|
+
const unwound = doc.unwindType(typeName, chain);
|
|
4066
|
+
if (!unwound) {
|
|
4067
|
+
messages.push({
|
|
4068
|
+
severity: 1,
|
|
4069
|
+
message: `Field '${chain.join(".")}' does not exist on type '${typeName}'.`,
|
|
4070
|
+
range: token.range
|
|
4071
|
+
});
|
|
4072
|
+
return messages;
|
|
4073
|
+
}
|
|
4074
|
+
}
|
|
4075
|
+
if (options?.requireDbTable && decl.node) {
|
|
4076
|
+
const hasDbTable = decl.node.countAnnotations("db.table") > 0;
|
|
4077
|
+
if (!hasDbTable) messages.push({
|
|
4078
|
+
severity: 1,
|
|
4079
|
+
message: `Type '${typeName}' must have @db.table annotation.`,
|
|
4080
|
+
range: token.range
|
|
4081
|
+
});
|
|
4082
|
+
}
|
|
4083
|
+
return messages;
|
|
4084
|
+
}
|
|
3219
4085
|
function findFKFieldsPointingTo(doc, iface, targetTypeName, alias) {
|
|
3220
4086
|
const results = [];
|
|
3221
4087
|
let struct;
|
|
@@ -3250,6 +4116,58 @@ function findFKFieldsPointingTo(doc, iface, targetTypeName, alias) {
|
|
|
3250
4116
|
}
|
|
3251
4117
|
return results;
|
|
3252
4118
|
}
|
|
4119
|
+
const viewAnnotationNames = [
|
|
4120
|
+
"db.view",
|
|
4121
|
+
"db.view.for",
|
|
4122
|
+
"db.view.joins",
|
|
4123
|
+
"db.view.filter",
|
|
4124
|
+
"db.view.materialized"
|
|
4125
|
+
];
|
|
4126
|
+
function hasAnyViewAnnotation(node) {
|
|
4127
|
+
return viewAnnotationNames.some((name) => node.countAnnotations(name) > 0);
|
|
4128
|
+
}
|
|
4129
|
+
function validateQueryScope(queryToken, allowedTypes, unqualifiedTarget, doc) {
|
|
4130
|
+
const errors = [];
|
|
4131
|
+
const queryNode = queryToken.queryNode;
|
|
4132
|
+
if (!queryNode) return errors;
|
|
4133
|
+
function walkFieldRef(ref$1) {
|
|
4134
|
+
if (ref$1.typeRef) {
|
|
4135
|
+
const typeName = ref$1.typeRef.text;
|
|
4136
|
+
if (!allowedTypes.includes(typeName)) errors.push({
|
|
4137
|
+
message: `Query references '${typeName}' which is not in scope — expected ${allowedTypes.map((t) => `'${t}'`).join(" or ")}`,
|
|
4138
|
+
severity: 1,
|
|
4139
|
+
range: ref$1.typeRef.range
|
|
4140
|
+
});
|
|
4141
|
+
} else if (unqualifiedTarget === null) errors.push({
|
|
4142
|
+
message: `Unqualified field reference '${ref$1.fieldRef.text}' — use qualified form (e.g., Type.${ref$1.fieldRef.text})`,
|
|
4143
|
+
severity: 1,
|
|
4144
|
+
range: ref$1.fieldRef.range
|
|
4145
|
+
});
|
|
4146
|
+
else {
|
|
4147
|
+
const unwound = doc.unwindType(unqualifiedTarget);
|
|
4148
|
+
if (unwound) {
|
|
4149
|
+
const targetDef = unwound.def;
|
|
4150
|
+
if (isInterface(targetDef) || isStructure(targetDef)) {
|
|
4151
|
+
const struct = isInterface(targetDef) ? targetDef.getDefinition() : targetDef;
|
|
4152
|
+
if (struct && isStructure(struct) && !struct.props.has(ref$1.fieldRef.text)) errors.push({
|
|
4153
|
+
message: `Field '${ref$1.fieldRef.text}' does not exist on '${unqualifiedTarget}'`,
|
|
4154
|
+
severity: 1,
|
|
4155
|
+
range: ref$1.fieldRef.range
|
|
4156
|
+
});
|
|
4157
|
+
}
|
|
4158
|
+
}
|
|
4159
|
+
}
|
|
4160
|
+
}
|
|
4161
|
+
function walkExpr(expr) {
|
|
4162
|
+
if (isQueryLogical(expr)) for (const operand of expr.operands) walkExpr(operand);
|
|
4163
|
+
else if (isQueryComparison(expr)) {
|
|
4164
|
+
walkFieldRef(expr.left);
|
|
4165
|
+
if (expr.right && "fieldRef" in expr.right) walkFieldRef(expr.right);
|
|
4166
|
+
}
|
|
4167
|
+
}
|
|
4168
|
+
walkExpr(queryNode.expression);
|
|
4169
|
+
return errors;
|
|
4170
|
+
}
|
|
3253
4171
|
|
|
3254
4172
|
//#endregion
|
|
3255
4173
|
//#region packages/core/src/defaults/db-annotations.ts
|
|
@@ -3328,7 +4246,7 @@ function findFKFieldsPointingTo(doc, iface, targetTypeName, alias) {
|
|
|
3328
4246
|
severity: 1,
|
|
3329
4247
|
range: token.range
|
|
3330
4248
|
});
|
|
3331
|
-
if (action === "setDefault" && field.countAnnotations("db.default
|
|
4249
|
+
if (action === "setDefault" && field.countAnnotations("db.default") === 0 && field.countAnnotations("db.default.fn") === 0) errors.push({
|
|
3332
4250
|
message: `@db.rel.${name} "setDefault" but no @db.default.* annotation — field will have no fallback value`,
|
|
3333
4251
|
severity: 2,
|
|
3334
4252
|
range: token.range
|
|
@@ -3386,16 +4304,47 @@ const dbAnnotations = {
|
|
|
3386
4304
|
return errors;
|
|
3387
4305
|
}
|
|
3388
4306
|
}) },
|
|
3389
|
-
table:
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
4307
|
+
table: {
|
|
4308
|
+
$self: new AnnotationSpec({
|
|
4309
|
+
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",
|
|
4310
|
+
nodeType: ["interface"],
|
|
4311
|
+
argument: {
|
|
4312
|
+
optional: true,
|
|
4313
|
+
name: "name",
|
|
4314
|
+
type: "string",
|
|
4315
|
+
description: "Table/collection name. If omitted, derived from interface name."
|
|
4316
|
+
},
|
|
4317
|
+
validate(token, _args, _doc) {
|
|
4318
|
+
const errors = [];
|
|
4319
|
+
const owner = token.parentNode;
|
|
4320
|
+
if (hasAnyViewAnnotation(owner)) errors.push({
|
|
4321
|
+
message: "An interface cannot be both a @db.table and a @db.view",
|
|
4322
|
+
severity: 1,
|
|
4323
|
+
range: token.range
|
|
4324
|
+
});
|
|
4325
|
+
return errors;
|
|
4326
|
+
}
|
|
4327
|
+
}),
|
|
4328
|
+
renamed: new AnnotationSpec({
|
|
4329
|
+
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",
|
|
4330
|
+
nodeType: ["interface"],
|
|
4331
|
+
argument: {
|
|
4332
|
+
name: "oldName",
|
|
4333
|
+
type: "string",
|
|
4334
|
+
description: "The previous table/collection name."
|
|
4335
|
+
},
|
|
4336
|
+
validate(token, _args, _doc) {
|
|
4337
|
+
const errors = [];
|
|
4338
|
+
const owner = token.parentNode;
|
|
4339
|
+
if (owner.countAnnotations("db.table") === 0) errors.push({
|
|
4340
|
+
message: "@db.table.renamed requires @db.table on the same interface",
|
|
4341
|
+
severity: 1,
|
|
4342
|
+
range: token.range
|
|
4343
|
+
});
|
|
4344
|
+
return errors;
|
|
4345
|
+
}
|
|
4346
|
+
})
|
|
4347
|
+
},
|
|
3399
4348
|
schema: new AnnotationSpec({
|
|
3400
4349
|
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",
|
|
3401
4350
|
nodeType: ["interface"],
|
|
@@ -3454,18 +4403,29 @@ const dbAnnotations = {
|
|
|
3454
4403
|
}]
|
|
3455
4404
|
})
|
|
3456
4405
|
},
|
|
3457
|
-
column:
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
4406
|
+
column: {
|
|
4407
|
+
$self: new AnnotationSpec({
|
|
4408
|
+
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",
|
|
4409
|
+
nodeType: ["prop"],
|
|
4410
|
+
argument: {
|
|
4411
|
+
name: "name",
|
|
4412
|
+
type: "string",
|
|
4413
|
+
description: "The column/field name (without parent prefix for nested fields)."
|
|
4414
|
+
}
|
|
4415
|
+
}),
|
|
4416
|
+
renamed: new AnnotationSpec({
|
|
4417
|
+
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",
|
|
4418
|
+
nodeType: ["prop"],
|
|
4419
|
+
argument: {
|
|
4420
|
+
name: "oldName",
|
|
4421
|
+
type: "string",
|
|
4422
|
+
description: "The old local field name (parent prefix is reconstructed automatically)."
|
|
4423
|
+
}
|
|
4424
|
+
})
|
|
4425
|
+
},
|
|
3466
4426
|
default: {
|
|
3467
|
-
|
|
3468
|
-
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
|
|
4427
|
+
$self: new AnnotationSpec({
|
|
4428
|
+
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",
|
|
3469
4429
|
nodeType: ["prop"],
|
|
3470
4430
|
argument: {
|
|
3471
4431
|
name: "value",
|
|
@@ -3560,6 +4520,16 @@ else if (fnName === "now" && !["number", "string"].includes(baseType)) errors.pu
|
|
|
3560
4520
|
return errors;
|
|
3561
4521
|
}
|
|
3562
4522
|
}),
|
|
4523
|
+
sync: { method: new AnnotationSpec({
|
|
4524
|
+
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",
|
|
4525
|
+
nodeType: ["interface"],
|
|
4526
|
+
argument: {
|
|
4527
|
+
name: "method",
|
|
4528
|
+
type: "string",
|
|
4529
|
+
description: "Sync method: \"drop\" (lossy) or \"recreate\" (lossless with data copy).",
|
|
4530
|
+
values: ["drop", "recreate"]
|
|
4531
|
+
}
|
|
4532
|
+
}) },
|
|
3563
4533
|
rel: {
|
|
3564
4534
|
FK: new AnnotationSpec({
|
|
3565
4535
|
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",
|
|
@@ -3828,7 +4798,258 @@ else if (matches.length > 1) errors.push({
|
|
|
3828
4798
|
}
|
|
3829
4799
|
}),
|
|
3830
4800
|
onDelete: refActionAnnotation("onDelete"),
|
|
3831
|
-
onUpdate: refActionAnnotation("onUpdate")
|
|
4801
|
+
onUpdate: refActionAnnotation("onUpdate"),
|
|
4802
|
+
via: new AnnotationSpec({
|
|
4803
|
+
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",
|
|
4804
|
+
nodeType: ["prop"],
|
|
4805
|
+
argument: {
|
|
4806
|
+
name: "junction",
|
|
4807
|
+
type: "ref",
|
|
4808
|
+
description: "The junction table type (must have @db.table and @db.rel.FK fields pointing to both sides)."
|
|
4809
|
+
},
|
|
4810
|
+
validate(token, args, doc) {
|
|
4811
|
+
const errors = [];
|
|
4812
|
+
const field = token.parentNode;
|
|
4813
|
+
if (field.countAnnotations("db.rel.to") > 0 || field.countAnnotations("db.rel.from") > 0) errors.push({
|
|
4814
|
+
message: "@db.rel.via is self-sufficient — cannot be combined with @db.rel.to or @db.rel.from",
|
|
4815
|
+
severity: 1,
|
|
4816
|
+
range: token.range
|
|
4817
|
+
});
|
|
4818
|
+
const definition$1 = field.getDefinition();
|
|
4819
|
+
if (!isArray(definition$1)) errors.push({
|
|
4820
|
+
message: "@db.rel.via requires an array type (e.g. Tag[])",
|
|
4821
|
+
severity: 1,
|
|
4822
|
+
range: token.range
|
|
4823
|
+
});
|
|
4824
|
+
if (!args[0]) return errors;
|
|
4825
|
+
const junctionName = args[0].text;
|
|
4826
|
+
errors.push(...validateRefArgument(args[0], doc, { requireDbTable: true }));
|
|
4827
|
+
if (errors.length > 0) return errors;
|
|
4828
|
+
const junctionUnwound = doc.unwindType(junctionName);
|
|
4829
|
+
if (!junctionUnwound) return errors;
|
|
4830
|
+
const junctionDef = junctionUnwound.def;
|
|
4831
|
+
if (!isInterface(junctionDef)) return errors;
|
|
4832
|
+
const thisTypeName = getParentTypeName(token);
|
|
4833
|
+
const targetTypeName = getNavTargetTypeName(field);
|
|
4834
|
+
if (!thisTypeName || !targetTypeName) return errors;
|
|
4835
|
+
const fksToThis = findFKFieldsPointingTo(junctionUnwound.doc, junctionDef, thisTypeName);
|
|
4836
|
+
if (fksToThis.length === 0) errors.push({
|
|
4837
|
+
message: `Junction '${junctionName}' has no @db.rel.FK pointing to '${thisTypeName}'`,
|
|
4838
|
+
severity: 1,
|
|
4839
|
+
range: args[0].range
|
|
4840
|
+
});
|
|
4841
|
+
else if (fksToThis.length > 1) errors.push({
|
|
4842
|
+
message: `Junction '${junctionName}' has multiple @db.rel.FK pointing to '${thisTypeName}' — not supported`,
|
|
4843
|
+
severity: 1,
|
|
4844
|
+
range: args[0].range
|
|
4845
|
+
});
|
|
4846
|
+
if (targetTypeName !== thisTypeName) {
|
|
4847
|
+
const fksToTarget = findFKFieldsPointingTo(junctionUnwound.doc, junctionDef, targetTypeName);
|
|
4848
|
+
if (fksToTarget.length === 0) errors.push({
|
|
4849
|
+
message: `Junction '${junctionName}' has no @db.rel.FK pointing to '${targetTypeName}'`,
|
|
4850
|
+
severity: 1,
|
|
4851
|
+
range: args[0].range
|
|
4852
|
+
});
|
|
4853
|
+
else if (fksToTarget.length > 1) errors.push({
|
|
4854
|
+
message: `Junction '${junctionName}' has multiple @db.rel.FK pointing to '${targetTypeName}' — not supported`,
|
|
4855
|
+
severity: 1,
|
|
4856
|
+
range: args[0].range
|
|
4857
|
+
});
|
|
4858
|
+
}
|
|
4859
|
+
return errors;
|
|
4860
|
+
}
|
|
4861
|
+
}),
|
|
4862
|
+
filter: new AnnotationSpec({
|
|
4863
|
+
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",
|
|
4864
|
+
nodeType: ["prop"],
|
|
4865
|
+
argument: {
|
|
4866
|
+
name: "condition",
|
|
4867
|
+
type: "query",
|
|
4868
|
+
description: "Filter expression restricting which related records are loaded."
|
|
4869
|
+
},
|
|
4870
|
+
validate(token, args, doc) {
|
|
4871
|
+
const errors = [];
|
|
4872
|
+
const field = token.parentNode;
|
|
4873
|
+
const hasTo = field.countAnnotations("db.rel.to") > 0;
|
|
4874
|
+
const hasFrom = field.countAnnotations("db.rel.from") > 0;
|
|
4875
|
+
const hasVia = field.countAnnotations("db.rel.via") > 0;
|
|
4876
|
+
if (!hasTo && !hasFrom && !hasVia) {
|
|
4877
|
+
errors.push({
|
|
4878
|
+
message: "@db.rel.filter is only valid on navigational fields (@db.rel.to, @db.rel.from, or @db.rel.via)",
|
|
4879
|
+
severity: 1,
|
|
4880
|
+
range: token.range
|
|
4881
|
+
});
|
|
4882
|
+
return errors;
|
|
4883
|
+
}
|
|
4884
|
+
if (!args[0]?.queryNode) return errors;
|
|
4885
|
+
const targetTypeName = getNavTargetTypeName(field);
|
|
4886
|
+
if (!targetTypeName) return errors;
|
|
4887
|
+
const allowedTypes = [targetTypeName];
|
|
4888
|
+
if (hasVia) {
|
|
4889
|
+
const viaAnnotations = field.annotations?.filter((a) => a.name === "db.rel.via");
|
|
4890
|
+
if (viaAnnotations?.[0]?.args[0]) allowedTypes.push(viaAnnotations[0].args[0].text);
|
|
4891
|
+
}
|
|
4892
|
+
errors.push(...validateQueryScope(args[0], allowedTypes, targetTypeName, doc));
|
|
4893
|
+
return errors;
|
|
4894
|
+
}
|
|
4895
|
+
})
|
|
4896
|
+
},
|
|
4897
|
+
view: {
|
|
4898
|
+
$self: new AnnotationSpec({
|
|
4899
|
+
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",
|
|
4900
|
+
nodeType: ["interface"],
|
|
4901
|
+
argument: {
|
|
4902
|
+
optional: true,
|
|
4903
|
+
name: "name",
|
|
4904
|
+
type: "string",
|
|
4905
|
+
description: "The view name in the database. If omitted, derived from the interface name."
|
|
4906
|
+
},
|
|
4907
|
+
validate(token, _args, _doc) {
|
|
4908
|
+
const errors = [];
|
|
4909
|
+
const owner = token.parentNode;
|
|
4910
|
+
if (owner.countAnnotations("db.table") > 0) errors.push({
|
|
4911
|
+
message: "An interface cannot be both a @db.table and a @db.view",
|
|
4912
|
+
severity: 1,
|
|
4913
|
+
range: token.range
|
|
4914
|
+
});
|
|
4915
|
+
return errors;
|
|
4916
|
+
}
|
|
4917
|
+
}),
|
|
4918
|
+
for: new AnnotationSpec({
|
|
4919
|
+
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",
|
|
4920
|
+
nodeType: ["interface"],
|
|
4921
|
+
argument: {
|
|
4922
|
+
name: "entry",
|
|
4923
|
+
type: "ref",
|
|
4924
|
+
description: "The primary/entry table type (must have @db.table)."
|
|
4925
|
+
},
|
|
4926
|
+
validate(token, args, doc) {
|
|
4927
|
+
const errors = [];
|
|
4928
|
+
const owner = token.parentNode;
|
|
4929
|
+
if (owner.countAnnotations("db.table") > 0) errors.push({
|
|
4930
|
+
message: "An interface cannot be both a @db.table and a @db.view",
|
|
4931
|
+
severity: 1,
|
|
4932
|
+
range: token.range
|
|
4933
|
+
});
|
|
4934
|
+
if (args[0]) errors.push(...validateRefArgument(args[0], doc, { requireDbTable: true }));
|
|
4935
|
+
return errors;
|
|
4936
|
+
}
|
|
4937
|
+
}),
|
|
4938
|
+
joins: new AnnotationSpec({
|
|
4939
|
+
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",
|
|
4940
|
+
nodeType: ["interface"],
|
|
4941
|
+
multiple: true,
|
|
4942
|
+
mergeStrategy: "append",
|
|
4943
|
+
argument: [{
|
|
4944
|
+
name: "target",
|
|
4945
|
+
type: "ref",
|
|
4946
|
+
description: "The table type to join (must have @db.table)."
|
|
4947
|
+
}, {
|
|
4948
|
+
name: "condition",
|
|
4949
|
+
type: "query",
|
|
4950
|
+
description: "Join condition expression."
|
|
4951
|
+
}],
|
|
4952
|
+
validate(token, args, doc) {
|
|
4953
|
+
const errors = [];
|
|
4954
|
+
const owner = token.parentNode;
|
|
4955
|
+
if (!hasAnyViewAnnotation(owner) && !args[0]) {
|
|
4956
|
+
errors.push({
|
|
4957
|
+
message: "@db.view.joins is only valid on @db.view interfaces",
|
|
4958
|
+
severity: 1,
|
|
4959
|
+
range: token.range
|
|
4960
|
+
});
|
|
4961
|
+
return errors;
|
|
4962
|
+
}
|
|
4963
|
+
if (args[0]) errors.push(...validateRefArgument(args[0], doc, { requireDbTable: true }));
|
|
4964
|
+
const forAnnotations = owner.annotations?.filter((a) => a.name === "db.view.for");
|
|
4965
|
+
const entryTypeName = forAnnotations?.[0]?.args[0]?.text;
|
|
4966
|
+
if (!entryTypeName) {
|
|
4967
|
+
errors.push({
|
|
4968
|
+
message: "@db.view.joins requires @db.view.for to identify the entry table",
|
|
4969
|
+
severity: 1,
|
|
4970
|
+
range: token.range
|
|
4971
|
+
});
|
|
4972
|
+
return errors;
|
|
4973
|
+
}
|
|
4974
|
+
if (args[1]?.queryNode && args[0]) {
|
|
4975
|
+
const joinTargetName = args[0].text;
|
|
4976
|
+
errors.push(...validateQueryScope(args[1], [joinTargetName, entryTypeName], entryTypeName, doc));
|
|
4977
|
+
}
|
|
4978
|
+
return errors;
|
|
4979
|
+
}
|
|
4980
|
+
}),
|
|
4981
|
+
filter: new AnnotationSpec({
|
|
4982
|
+
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",
|
|
4983
|
+
nodeType: ["interface"],
|
|
4984
|
+
argument: {
|
|
4985
|
+
name: "condition",
|
|
4986
|
+
type: "query",
|
|
4987
|
+
description: "Filter expression for the view WHERE clause."
|
|
4988
|
+
},
|
|
4989
|
+
validate(token, args, doc) {
|
|
4990
|
+
const errors = [];
|
|
4991
|
+
const owner = token.parentNode;
|
|
4992
|
+
if (!hasAnyViewAnnotation(owner) && !args[0]) {
|
|
4993
|
+
errors.push({
|
|
4994
|
+
message: "@db.view.filter is only valid on @db.view interfaces",
|
|
4995
|
+
severity: 1,
|
|
4996
|
+
range: token.range
|
|
4997
|
+
});
|
|
4998
|
+
return errors;
|
|
4999
|
+
}
|
|
5000
|
+
if (!args[0]?.queryNode) return errors;
|
|
5001
|
+
const forAnnotations = owner.annotations?.filter((a) => a.name === "db.view.for");
|
|
5002
|
+
const entryTypeName = forAnnotations?.[0]?.args[0]?.text;
|
|
5003
|
+
if (!entryTypeName) {
|
|
5004
|
+
errors.push({
|
|
5005
|
+
message: "@db.view.filter requires @db.view.for to identify the entry table",
|
|
5006
|
+
severity: 1,
|
|
5007
|
+
range: token.range
|
|
5008
|
+
});
|
|
5009
|
+
return errors;
|
|
5010
|
+
}
|
|
5011
|
+
const allowedTypes = [entryTypeName];
|
|
5012
|
+
const joinsAnnotations = owner.annotations?.filter((a) => a.name === "db.view.joins");
|
|
5013
|
+
if (joinsAnnotations) {
|
|
5014
|
+
for (const join of joinsAnnotations) if (join.args[0]) allowedTypes.push(join.args[0].text);
|
|
5015
|
+
}
|
|
5016
|
+
errors.push(...validateQueryScope(args[0], allowedTypes, entryTypeName, doc));
|
|
5017
|
+
return errors;
|
|
5018
|
+
}
|
|
5019
|
+
}),
|
|
5020
|
+
materialized: new AnnotationSpec({
|
|
5021
|
+
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",
|
|
5022
|
+
nodeType: ["interface"],
|
|
5023
|
+
validate(token, _args, _doc) {
|
|
5024
|
+
const errors = [];
|
|
5025
|
+
const owner = token.parentNode;
|
|
5026
|
+
if (!hasAnyViewAnnotation(owner)) errors.push({
|
|
5027
|
+
message: "@db.view.materialized is only valid on @db.view interfaces",
|
|
5028
|
+
severity: 1,
|
|
5029
|
+
range: token.range
|
|
5030
|
+
});
|
|
5031
|
+
return errors;
|
|
5032
|
+
}
|
|
5033
|
+
}),
|
|
5034
|
+
renamed: new AnnotationSpec({
|
|
5035
|
+
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",
|
|
5036
|
+
nodeType: ["interface"],
|
|
5037
|
+
argument: {
|
|
5038
|
+
name: "oldName",
|
|
5039
|
+
type: "string",
|
|
5040
|
+
description: "The previous view name."
|
|
5041
|
+
},
|
|
5042
|
+
validate(token, _args, _doc) {
|
|
5043
|
+
const errors = [];
|
|
5044
|
+
const owner = token.parentNode;
|
|
5045
|
+
if (!hasAnyViewAnnotation(owner)) errors.push({
|
|
5046
|
+
message: "@db.view.renamed requires @db.view on the same interface",
|
|
5047
|
+
severity: 1,
|
|
5048
|
+
range: token.range
|
|
5049
|
+
});
|
|
5050
|
+
return errors;
|
|
5051
|
+
}
|
|
5052
|
+
})
|
|
3832
5053
|
}
|
|
3833
5054
|
};
|
|
3834
5055
|
|
|
@@ -4528,8 +5749,12 @@ var PluginManager = class {
|
|
|
4528
5749
|
return this._loopInAnnotationsSpec(annotations$1, cb);
|
|
4529
5750
|
}
|
|
4530
5751
|
_loopInAnnotationsSpec(annotations$1, cb, prefix) {
|
|
4531
|
-
|
|
5752
|
+
if (annotations$1.$self && prefix) cb(prefix, annotations$1.$self);
|
|
5753
|
+
for (const [key, value] of Object.entries(annotations$1)) {
|
|
5754
|
+
if (key === "$self") continue;
|
|
5755
|
+
if (isAnnotationSpec(value)) cb(prefix ? `${prefix}.${key}` : key, value);
|
|
4532
5756
|
else this._loopInAnnotationsSpec(value, cb, prefix ? `${prefix}.${key}` : key);
|
|
5757
|
+
}
|
|
4533
5758
|
}
|
|
4534
5759
|
constructor(cfg) {
|
|
4535
5760
|
_define_property$2(this, "cfg", void 0);
|
|
@@ -4568,6 +5793,11 @@ var AtscriptRepo = class {
|
|
|
4568
5793
|
return new Set(tags);
|
|
4569
5794
|
}
|
|
4570
5795
|
async getUsedAnnotations() {
|
|
5796
|
+
const ANNOTATION_TYPE_MAP = {
|
|
5797
|
+
ref: "import(\"@atscript/typescript/utils\").AtscriptRef",
|
|
5798
|
+
query: "import(\"@atscript/typescript/utils\").AtscriptQueryNode"
|
|
5799
|
+
};
|
|
5800
|
+
const mapArgType = (t) => ANNOTATION_TYPE_MAP[t] || t;
|
|
4571
5801
|
const manager = await this.getSharedPluginManager();
|
|
4572
5802
|
const annotations$1 = {};
|
|
4573
5803
|
if (manager) await manager.loopInAnnotationsSpec((name, spec) => {
|
|
@@ -4579,12 +5809,12 @@ var AtscriptRepo = class {
|
|
|
4579
5809
|
props: {}
|
|
4580
5810
|
};
|
|
4581
5811
|
for (const a of spec.arguments) o.props[a.name] = {
|
|
4582
|
-
type: a.type,
|
|
5812
|
+
type: mapArgType(a.type),
|
|
4583
5813
|
optional: a.optional
|
|
4584
5814
|
};
|
|
4585
5815
|
types.push(o);
|
|
4586
5816
|
} else if (spec.config.argument) types.push({
|
|
4587
|
-
type: spec.config.argument.type,
|
|
5817
|
+
type: mapArgType(spec.config.argument.type),
|
|
4588
5818
|
optional: spec.config.argument.optional
|
|
4589
5819
|
});
|
|
4590
5820
|
else types.push({ type: "boolean" });
|
|
@@ -4725,34 +5955,28 @@ else types.push({ type: "boolean" });
|
|
|
4725
5955
|
async checkImport(atscript, from, imports, checked) {
|
|
4726
5956
|
const forId = resolveAtscriptFromPath(from.text, atscript.id);
|
|
4727
5957
|
if (forId === atscript.id) {
|
|
4728
|
-
|
|
4729
|
-
messages.push({
|
|
5958
|
+
atscript.registerMessages([{
|
|
4730
5959
|
severity: 1,
|
|
4731
5960
|
message: "\"import\" cannot import itself",
|
|
4732
5961
|
range: from.range
|
|
4733
|
-
});
|
|
5962
|
+
}]);
|
|
4734
5963
|
return;
|
|
4735
5964
|
}
|
|
4736
|
-
const errors = [];
|
|
4737
5965
|
let external;
|
|
4738
5966
|
try {
|
|
4739
5967
|
external = await this.openDocument(forId);
|
|
4740
5968
|
await this.checkImports(external, checked);
|
|
4741
|
-
for (const token of imports) if (!external.exports.has(token.text))
|
|
5969
|
+
for (const token of imports) if (!external.exports.has(token.text)) atscript.registerMessages([{
|
|
4742
5970
|
severity: 1,
|
|
4743
5971
|
message: `"${from.text}" has no exported member "${token.text}"`,
|
|
4744
5972
|
range: token.range
|
|
4745
|
-
});
|
|
5973
|
+
}]);
|
|
4746
5974
|
} catch (error) {
|
|
4747
|
-
|
|
5975
|
+
atscript.registerMessages([{
|
|
4748
5976
|
severity: 1,
|
|
4749
5977
|
message: `"${from.text}" not found`,
|
|
4750
5978
|
range: from.range
|
|
4751
|
-
});
|
|
4752
|
-
}
|
|
4753
|
-
if (errors.length > 0) {
|
|
4754
|
-
const messages = atscript.getDiagMessages();
|
|
4755
|
-
messages.push(...errors);
|
|
5979
|
+
}]);
|
|
4756
5980
|
}
|
|
4757
5981
|
return external;
|
|
4758
5982
|
}
|
|
@@ -4813,7 +6037,9 @@ else {
|
|
|
4813
6037
|
}
|
|
4814
6038
|
const documents = [];
|
|
4815
6039
|
for (const entry of entries) documents.push(await repo.openDocument(`file://${entry}`));
|
|
4816
|
-
|
|
6040
|
+
const docs = documents.filter(Boolean);
|
|
6041
|
+
for (const doc of docs) await repo.checkDoc(doc);
|
|
6042
|
+
return new BuildRepo(rootDir, repo, docs);
|
|
4817
6043
|
}
|
|
4818
6044
|
var BuildRepo = class {
|
|
4819
6045
|
getDoc(id) {
|
|
@@ -4821,10 +6047,7 @@ var BuildRepo = class {
|
|
|
4821
6047
|
}
|
|
4822
6048
|
async diagnostics() {
|
|
4823
6049
|
const docMessages = new Map();
|
|
4824
|
-
for (const document of this.docs)
|
|
4825
|
-
await this.repo.checkDoc(document);
|
|
4826
|
-
docMessages.set(document.id, document.getDiagMessages());
|
|
4827
|
-
}
|
|
6050
|
+
for (const document of this.docs) docMessages.set(document.id, document.getDiagMessages());
|
|
4828
6051
|
return docMessages;
|
|
4829
6052
|
}
|
|
4830
6053
|
async generate(config, docs = this.docs) {
|
|
@@ -4867,14 +6090,14 @@ var BuildRepo = class {
|
|
|
4867
6090
|
|
|
4868
6091
|
//#endregion
|
|
4869
6092
|
//#region packages/core/src/flatten.ts
|
|
4870
|
-
function flattenInterfaceNode(doc, node) {
|
|
6093
|
+
function flattenInterfaceNode(doc, node, options) {
|
|
4871
6094
|
const flatMap = new Map();
|
|
4872
6095
|
const stack = new Set();
|
|
4873
6096
|
let struct;
|
|
4874
6097
|
if (node.hasExtends) struct = doc.resolveInterfaceExtends(node);
|
|
4875
6098
|
if (!struct) struct = node.getDefinition();
|
|
4876
6099
|
if (!struct || !isStructure(struct)) return flatMap;
|
|
4877
|
-
walkStructure(doc, struct, "", false, flatMap, stack);
|
|
6100
|
+
walkStructure(doc, struct, "", false, flatMap, stack, options);
|
|
4878
6101
|
return flatMap;
|
|
4879
6102
|
}
|
|
4880
6103
|
/**
|
|
@@ -4889,6 +6112,10 @@ function flattenInterfaceNode(doc, node) {
|
|
|
4889
6112
|
if (!prop.annotations) return false;
|
|
4890
6113
|
return prop.annotations.some((a) => a.name === "db.json");
|
|
4891
6114
|
}
|
|
6115
|
+
function hasNavPropAnnotation(prop) {
|
|
6116
|
+
if (!prop.annotations) return false;
|
|
6117
|
+
return prop.annotations.some((a) => a.name === "db.rel.to" || a.name === "db.rel.from" || a.name === "db.rel.via");
|
|
6118
|
+
}
|
|
4892
6119
|
function isPhantomNode(doc, def) {
|
|
4893
6120
|
if (!def) return false;
|
|
4894
6121
|
if (isPrimitive(def) && def.config.type === "phantom") return true;
|
|
@@ -4937,11 +6164,12 @@ function addToFlatMap(flatMap, path$5, descriptor) {
|
|
|
4937
6164
|
});
|
|
4938
6165
|
} else flatMap.set(path$5, descriptor);
|
|
4939
6166
|
}
|
|
4940
|
-
function walkStructure(doc, struct, prefix, parentOptional, flatMap, stack) {
|
|
6167
|
+
function walkStructure(doc, struct, prefix, parentOptional, flatMap, stack, options) {
|
|
4941
6168
|
for (const [name, prop] of struct.props) {
|
|
4942
6169
|
if (prop.token("identifier")?.pattern) continue;
|
|
4943
6170
|
const propDef = prop.getDefinition();
|
|
4944
6171
|
if (isPhantomNode(doc, propDef)) continue;
|
|
6172
|
+
if (options?.skipNavProps && hasNavPropAnnotation(prop)) continue;
|
|
4945
6173
|
const path$5 = prefix ? `${prefix}.${name}` : name;
|
|
4946
6174
|
const optional = parentOptional || !!prop.token("optional");
|
|
4947
6175
|
const dbJson = hasDbJsonAnnotation(prop);
|
|
@@ -4974,10 +6202,10 @@ function walkStructure(doc, struct, prefix, parentOptional, flatMap, stack) {
|
|
|
4974
6202
|
});
|
|
4975
6203
|
continue;
|
|
4976
6204
|
}
|
|
4977
|
-
walkNode(resolved.doc, resolved.def, path$5, optional, prop, flatMap, stack);
|
|
6205
|
+
walkNode(resolved.doc, resolved.def, path$5, optional, prop, flatMap, stack, options);
|
|
4978
6206
|
}
|
|
4979
6207
|
}
|
|
4980
|
-
function walkNode(doc, def, path$5, optional, propNode, flatMap, stack) {
|
|
6208
|
+
function walkNode(doc, def, path$5, optional, propNode, flatMap, stack, options) {
|
|
4981
6209
|
if (stack.has(def)) {
|
|
4982
6210
|
addToFlatMap(flatMap, path$5, {
|
|
4983
6211
|
def,
|
|
@@ -4997,7 +6225,7 @@ function walkNode(doc, def, path$5, optional, propNode, flatMap, stack) {
|
|
|
4997
6225
|
propNode,
|
|
4998
6226
|
intermediate: true
|
|
4999
6227
|
});
|
|
5000
|
-
walkStructure(doc, def, path$5, optional, flatMap, stack);
|
|
6228
|
+
walkStructure(doc, def, path$5, optional, flatMap, stack, options);
|
|
5001
6229
|
} else if (isArray(def)) {
|
|
5002
6230
|
const elementDef = def.getDefinition();
|
|
5003
6231
|
const resolvedElement = elementDef ? resolveNode(doc, elementDef) : undefined;
|
|
@@ -5010,7 +6238,7 @@ function walkNode(doc, def, path$5, optional, propNode, flatMap, stack) {
|
|
|
5010
6238
|
propNode,
|
|
5011
6239
|
intermediate: true
|
|
5012
6240
|
});
|
|
5013
|
-
walkArrayElement(doc, def, path$5, optional, flatMap, stack);
|
|
6241
|
+
walkArrayElement(doc, def, path$5, optional, flatMap, stack, options);
|
|
5014
6242
|
} else addToFlatMap(flatMap, path$5, {
|
|
5015
6243
|
def,
|
|
5016
6244
|
doc,
|
|
@@ -5029,7 +6257,7 @@ function walkNode(doc, def, path$5, optional, propNode, flatMap, stack) {
|
|
|
5029
6257
|
propNode,
|
|
5030
6258
|
intermediate: true
|
|
5031
6259
|
});
|
|
5032
|
-
walkStructure(doc, merged, path$5, optional, flatMap, stack);
|
|
6260
|
+
walkStructure(doc, merged, path$5, optional, flatMap, stack, options);
|
|
5033
6261
|
} else addToFlatMap(flatMap, path$5, {
|
|
5034
6262
|
def,
|
|
5035
6263
|
doc,
|
|
@@ -5061,7 +6289,7 @@ else addToFlatMap(flatMap, path$5, {
|
|
|
5061
6289
|
});
|
|
5062
6290
|
for (const branch of branches) {
|
|
5063
6291
|
const resolved = resolveNode(doc, branch);
|
|
5064
|
-
if (resolved) walkBranch(resolved.doc, resolved.def, path$5, optional, flatMap, stack);
|
|
6292
|
+
if (resolved) walkBranch(resolved.doc, resolved.def, path$5, optional, flatMap, stack, options);
|
|
5065
6293
|
}
|
|
5066
6294
|
} else addToFlatMap(flatMap, path$5, {
|
|
5067
6295
|
def,
|
|
@@ -5085,27 +6313,27 @@ else addToFlatMap(flatMap, path$5, {
|
|
|
5085
6313
|
stack.delete(def);
|
|
5086
6314
|
}
|
|
5087
6315
|
}
|
|
5088
|
-
function walkArrayElement(doc, arrayNode, prefix, parentOptional, flatMap, stack) {
|
|
6316
|
+
function walkArrayElement(doc, arrayNode, prefix, parentOptional, flatMap, stack, options) {
|
|
5089
6317
|
const elementDef = arrayNode.getDefinition();
|
|
5090
6318
|
if (!elementDef) return;
|
|
5091
6319
|
const resolved = resolveNode(doc, elementDef);
|
|
5092
6320
|
if (!resolved) return;
|
|
5093
|
-
walkBranch(resolved.doc, resolved.def, prefix, parentOptional, flatMap, stack);
|
|
6321
|
+
walkBranch(resolved.doc, resolved.def, prefix, parentOptional, flatMap, stack, options);
|
|
5094
6322
|
}
|
|
5095
6323
|
/**
|
|
5096
6324
|
* Walks a branch (union branch or array element) to collect sub-paths.
|
|
5097
6325
|
* Does NOT add an entry for the branch itself — the parent already did that.
|
|
5098
|
-
*/ function walkBranch(doc, def, prefix, parentOptional, flatMap, stack) {
|
|
5099
|
-
if (isStructure(def)) walkStructure(doc, def, prefix, parentOptional, flatMap, stack);
|
|
5100
|
-
else if (isArray(def)) walkArrayElement(doc, def, prefix, parentOptional, flatMap, stack);
|
|
6326
|
+
*/ function walkBranch(doc, def, prefix, parentOptional, flatMap, stack, options) {
|
|
6327
|
+
if (isStructure(def)) walkStructure(doc, def, prefix, parentOptional, flatMap, stack, options);
|
|
6328
|
+
else if (isArray(def)) walkArrayElement(doc, def, prefix, parentOptional, flatMap, stack, options);
|
|
5101
6329
|
else if (isGroup(def) && def.entity !== "structure") {
|
|
5102
6330
|
const group$1 = def;
|
|
5103
6331
|
if (group$1.op === "&") {
|
|
5104
6332
|
const merged = doc.mergeIntersection(def);
|
|
5105
|
-
if (isStructure(merged)) walkStructure(doc, merged, prefix, parentOptional, flatMap, stack);
|
|
6333
|
+
if (isStructure(merged)) walkStructure(doc, merged, prefix, parentOptional, flatMap, stack, options);
|
|
5106
6334
|
} else if (group$1.op === "|") for (const branch of group$1.unwrap()) {
|
|
5107
6335
|
const resolved = resolveNode(doc, branch);
|
|
5108
|
-
if (resolved) walkBranch(resolved.doc, resolved.def, prefix, parentOptional, flatMap, stack);
|
|
6336
|
+
if (resolved) walkBranch(resolved.doc, resolved.def, prefix, parentOptional, flatMap, stack, options);
|
|
5109
6337
|
}
|
|
5110
6338
|
}
|
|
5111
6339
|
}
|
|
@@ -5127,17 +6355,28 @@ exports.SemanticInterfaceNode = SemanticInterfaceNode
|
|
|
5127
6355
|
exports.SemanticNode = SemanticNode
|
|
5128
6356
|
exports.SemanticPrimitiveNode = SemanticPrimitiveNode
|
|
5129
6357
|
exports.SemanticPropNode = SemanticPropNode
|
|
6358
|
+
exports.SemanticQueryComparisonNode = SemanticQueryComparisonNode
|
|
6359
|
+
exports.SemanticQueryFieldRefNode = SemanticQueryFieldRefNode
|
|
6360
|
+
exports.SemanticQueryLogicalNode = SemanticQueryLogicalNode
|
|
6361
|
+
exports.SemanticQueryNode = SemanticQueryNode
|
|
6362
|
+
exports.SemanticQueryValueListNode = SemanticQueryValueListNode
|
|
6363
|
+
exports.SemanticQueryValueNode = SemanticQueryValueNode
|
|
5130
6364
|
exports.SemanticRefNode = SemanticRefNode
|
|
5131
6365
|
exports.SemanticStructureNode = SemanticStructureNode
|
|
5132
6366
|
exports.SemanticTupleNode = SemanticTupleNode
|
|
5133
6367
|
exports.SemanticTypeNode = SemanticTypeNode
|
|
5134
6368
|
exports.Token = Token
|
|
6369
|
+
exports.analyzeQueryCursorContext = analyzeQueryCursorContext
|
|
5135
6370
|
exports.build = build
|
|
5136
6371
|
exports.createAtscriptPlugin = createAtscriptPlugin
|
|
5137
6372
|
exports.defineConfig = defineConfig
|
|
5138
6373
|
exports.findFKFieldsPointingTo = findFKFieldsPointingTo
|
|
5139
6374
|
exports.flattenInterfaceNode = flattenInterfaceNode
|
|
6375
|
+
exports.getFieldsForType = getFieldsForType
|
|
6376
|
+
exports.getQueryCompletionScope = getQueryCompletionScope
|
|
6377
|
+
exports.getQueryScope = getQueryScope
|
|
5140
6378
|
exports.getRelPath = getRelPath
|
|
6379
|
+
exports.hasNavPropAnnotation = hasNavPropAnnotation
|
|
5141
6380
|
exports.isAnnotate = isAnnotate
|
|
5142
6381
|
exports.isAnnotationSpec = isAnnotationSpec
|
|
5143
6382
|
exports.isArray = isArray
|
|
@@ -5148,6 +6387,9 @@ exports.isInterface = isInterface
|
|
|
5148
6387
|
exports.isPhantomNode = isPhantomNode
|
|
5149
6388
|
exports.isPrimitive = isPrimitive
|
|
5150
6389
|
exports.isProp = isProp
|
|
6390
|
+
exports.isQueryComparison = isQueryComparison
|
|
6391
|
+
exports.isQueryFieldRef = isQueryFieldRef
|
|
6392
|
+
exports.isQueryLogical = isQueryLogical
|
|
5151
6393
|
exports.isRef = isRef
|
|
5152
6394
|
exports.isStructure = isStructure
|
|
5153
6395
|
exports.isTuple = isTuple
|
|
@@ -5156,4 +6398,6 @@ exports.loadConfig = loadConfig
|
|
|
5156
6398
|
exports.loadTsConfig = loadTsConfig
|
|
5157
6399
|
exports.resolveAnnotation = resolveAnnotation
|
|
5158
6400
|
exports.resolveAtscriptFromPath = resolveAtscriptFromPath
|
|
5159
|
-
exports.resolveConfigFile = resolveConfigFile
|
|
6401
|
+
exports.resolveConfigFile = resolveConfigFile
|
|
6402
|
+
exports.resolveQueryFieldRef = resolveQueryFieldRef
|
|
6403
|
+
exports.validateRefArgument = validateRefArgument
|