@xano/xanoscript-language-server 11.8.2 → 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 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 "function";
193
+ return "variable";
194
+ case WhereToken.name:
195
+ return;
187
196
  default:
188
197
  return null;
189
198
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xano/xanoscript-language-server",
3
- "version": "11.8.2",
3
+ "version": "11.8.4",
4
4
  "description": "Language Server Protocol implementation for XanoScript",
5
5
  "type": "module",
6
6
  "main": "server.js",
@@ -34,6 +34,15 @@ describe("dbQueryFn", () => {
34
34
  expect(parser.errors).to.be.empty;
35
35
  });
36
36
 
37
+ it("dbQueryFn where can split line on binary operators", () => {
38
+ const parser = parse(`query user {
39
+ where = $db.user.visa_work_permit_end_date != null &&
40
+ $db.user.visa_work_permit_end_date <= $input.next_120_days && $db.bug_test_candidate.candidate_status == "mediated" && ($db.user.billing_end_date > now || $db.user.billing_end_date == null)
41
+ return = {type: "list"}
42
+ } as $results`);
43
+ expect(parser.errors).to.be.empty;
44
+ });
45
+
37
46
  it("dbQueryFn accepts a description", () => {
38
47
  const parser = parse(`query user {
39
48
  where = $db.array_columns @> $db.array_columns.id
@@ -354,6 +354,7 @@ export function expressionTestFn($) {
354
354
  DEF: () => $.CONSUME1(Question), // "?"
355
355
  });
356
356
 
357
+ $.OPTION1(() => $.CONSUME(NewlineToken));
357
358
  $.SUBRULE($.expressionFn, { ARGS: [token, options] });
358
359
  };
359
360
  }
@@ -107,6 +107,13 @@ describe("expressionFn", () => {
107
107
  expect(parser.errors).to.be.empty;
108
108
  });
109
109
 
110
+ it("expressionFn can split on multiple lines on binary operators", () => {
111
+ let parser = parse(`$var.value == "test" &&
112
+ $var.other_value != "example" ||
113
+ $var.another_value > 10`);
114
+ expect(parser.errors).to.be.empty;
115
+ });
116
+
110
117
  it("expressionFn accepts modulus symbol in expression", () => {
111
118
  const parser = parse("$this % 2 == 1");
112
119
  expect(parser.errors).to.be.empty;
@@ -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"