@xano/xanoscript-language-server 11.8.3 → 11.8.4
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/lexer/db.js +10 -1
- package/package.json +1 -1
- package/parser/table_trigger_parser.js +21 -0
- package/parser/table_trigger_parser.spec.js +29 -0
package/lexer/db.js
CHANGED
|
@@ -13,6 +13,12 @@ export const QueryToken = createTokenByName("query", {
|
|
|
13
13
|
categories: [Identifier],
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
+
// where
|
|
17
|
+
export const WhereToken = createTokenByName("where", {
|
|
18
|
+
longer_alt: Identifier,
|
|
19
|
+
categories: [Identifier],
|
|
20
|
+
});
|
|
21
|
+
|
|
16
22
|
// get
|
|
17
23
|
export const GetToken = createTokenByName("get", {
|
|
18
24
|
longer_alt: Identifier,
|
|
@@ -156,6 +162,7 @@ export const DbTokens = [
|
|
|
156
162
|
MysqlToken,
|
|
157
163
|
PostgresToken,
|
|
158
164
|
OracleToken,
|
|
165
|
+
WhereToken,
|
|
159
166
|
];
|
|
160
167
|
|
|
161
168
|
export function mapTokenToType(token) {
|
|
@@ -183,7 +190,9 @@ export function mapTokenToType(token) {
|
|
|
183
190
|
case TruncateToken.name:
|
|
184
191
|
case DirectQueryToken.name:
|
|
185
192
|
case SetDatasourceToken.name:
|
|
186
|
-
return "
|
|
193
|
+
return "variable";
|
|
194
|
+
case WhereToken.name:
|
|
195
|
+
return;
|
|
187
196
|
default:
|
|
188
197
|
return null;
|
|
189
198
|
}
|
package/package.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EqualToken, LCurly, RCurly } from "../lexer/control.js";
|
|
2
|
+
import { WhereToken } from "../lexer/db.js";
|
|
2
3
|
import { StringLiteral } from "../lexer/literal.js";
|
|
3
4
|
import {
|
|
4
5
|
ActionsToken,
|
|
@@ -20,6 +21,7 @@ export function tableTriggerDeclaration($) {
|
|
|
20
21
|
let hasInput = false;
|
|
21
22
|
let hasStack = false;
|
|
22
23
|
let hasTags = false;
|
|
24
|
+
let hasWhere = false;
|
|
23
25
|
|
|
24
26
|
// @TODO: search
|
|
25
27
|
|
|
@@ -127,6 +129,25 @@ export function tableTriggerDeclaration($) {
|
|
|
127
129
|
$.SUBRULE($.tagsAttribute);
|
|
128
130
|
},
|
|
129
131
|
},
|
|
132
|
+
{
|
|
133
|
+
GATE: () => !hasWhere,
|
|
134
|
+
ALT: () => {
|
|
135
|
+
hasWhere = true;
|
|
136
|
+
const token = $.CONSUME(WhereToken, { LABEL: "where" });
|
|
137
|
+
$.CONSUME1(EqualToken);
|
|
138
|
+
$.SUBRULE($.expressionFn, {
|
|
139
|
+
ARGS: [
|
|
140
|
+
token,
|
|
141
|
+
{
|
|
142
|
+
allowQueryExpression: true,
|
|
143
|
+
allowVariable: true,
|
|
144
|
+
allowExpression: false,
|
|
145
|
+
allowComparison: true,
|
|
146
|
+
},
|
|
147
|
+
],
|
|
148
|
+
});
|
|
149
|
+
},
|
|
150
|
+
},
|
|
130
151
|
]);
|
|
131
152
|
});
|
|
132
153
|
|
|
@@ -121,6 +121,35 @@ describe("table_trigger", () => {
|
|
|
121
121
|
expect(parser.errors).to.be.empty;
|
|
122
122
|
});
|
|
123
123
|
|
|
124
|
+
it("should accept a where clause in actions", () => {
|
|
125
|
+
const parser =
|
|
126
|
+
xanoscriptParser(`// Sends a Slack notification when a conversation's markdown is updated
|
|
127
|
+
table_trigger conversation_slack_notification {
|
|
128
|
+
table = "conversations"
|
|
129
|
+
|
|
130
|
+
input {
|
|
131
|
+
json new
|
|
132
|
+
json old
|
|
133
|
+
enum action {
|
|
134
|
+
values = ["insert", "update", "delete", "truncate"]
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
text datasource
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
stack {
|
|
141
|
+
function.run "notifications/send_conversation_slack_notification" {
|
|
142
|
+
input = {id: $input.new.id}
|
|
143
|
+
} as $slack_result
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
where = $db.NEW.markdown != null
|
|
147
|
+
actions = {insert: true, update: true}
|
|
148
|
+
history = 100
|
|
149
|
+
}`);
|
|
150
|
+
expect(parser.errors).to.be.empty;
|
|
151
|
+
});
|
|
152
|
+
|
|
124
153
|
it("should parse actions with fields in any order", () => {
|
|
125
154
|
const parser = xanoscriptParser(`table_trigger foo {
|
|
126
155
|
table = "blah"
|