@xano/xanoscript-language-server 12.5.0 → 12.6.0

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.
@@ -0,0 +1,57 @@
1
+ import { DebugLogToken } from "./debug.js";
2
+ import { Identifier } from "./identifier.js";
3
+ import { createTokenByName } from "./utils.js";
4
+
5
+ // datadog
6
+ export const DatadogToken = createTokenByName("datadog", {
7
+ longer_alt: Identifier,
8
+ categories: [Identifier],
9
+ });
10
+
11
+ // datadog.log reuses the existing "log" token from debug
12
+ export { DebugLogToken as DatadogLogToken };
13
+
14
+ // datadog.log_bulk
15
+ export const DatadogLogBulkToken = createTokenByName("log_bulk", {
16
+ longer_alt: Identifier,
17
+ categories: [Identifier],
18
+ });
19
+
20
+ // datadog.metric
21
+ export const DatadogMetricToken = createTokenByName("metric", {
22
+ longer_alt: Identifier,
23
+ categories: [Identifier],
24
+ });
25
+
26
+ // datadog.metric_bulk
27
+ export const DatadogMetricBulkToken = createTokenByName("metric_bulk", {
28
+ longer_alt: Identifier,
29
+ categories: [Identifier],
30
+ });
31
+
32
+ // Order matters: longer patterns must come before shorter prefixes
33
+ // (e.g. metric_bulk before metric) so the lexer matches them correctly.
34
+ // Note: `log_bulk` ordering vs the reused `log` token depends on
35
+ // DatadogTokens being registered before DebugTokens in lexer/tokens.js.
36
+ export const DatadogTokens = [
37
+ DatadogToken,
38
+ DatadogLogBulkToken,
39
+ DatadogMetricBulkToken,
40
+ DatadogMetricToken,
41
+ ];
42
+
43
+ /**
44
+ * Maps a token name to a type
45
+ * @param {string} token the token name
46
+ */
47
+ export function mapTokenToType(token) {
48
+ switch (token) {
49
+ case DatadogToken.name:
50
+ case DatadogLogBulkToken.name:
51
+ case DatadogMetricToken.name:
52
+ case DatadogMetricBulkToken.name:
53
+ return "function";
54
+ default:
55
+ return null;
56
+ }
57
+ }
package/lexer/tokens.js CHANGED
@@ -52,6 +52,10 @@ import {
52
52
  ControlTokens,
53
53
  mapTokenToType as mapControlsTokenToType,
54
54
  } from "./control.js";
55
+ import {
56
+ DatadogTokens,
57
+ mapTokenToType as mapDatadogTokenToType,
58
+ } from "./datadog.js";
55
59
  import { DbTokens, mapTokenToType as mapDbTokenToType } from "./db.js";
56
60
  import { DebugTokens, mapTokenToType as mapDebugTokenToType } from "./debug.js";
57
61
  import {
@@ -417,6 +421,7 @@ export const allTokens = uniq([
417
421
  ...RunTokens,
418
422
  ...ObjectTokens,
419
423
  ...StreamTokens,
424
+ ...DatadogTokens,
420
425
  ...DebugTokens,
421
426
  ...ExpectFnTokens,
422
427
  ...VarTokens,
@@ -449,6 +454,7 @@ const tokenMappers = [
449
454
  mapColumnTokenToType,
450
455
  mapCommentTokenToType,
451
456
  mapControlsTokenToType,
457
+ mapDatadogTokenToType,
452
458
  mapDbTokenToType,
453
459
  mapDebugTokenToType,
454
460
  mapErrorTriggerTokenToType,
@@ -2831,6 +2831,119 @@ Reduces the array to a single value using the code block to combine each element
2831
2831
 
2832
2832
  Result: `25`
2833
2833
 
2834
+ # lambda_map
2835
+
2836
+ Like `map`, but the transform is written as a string of JS/TS code instead of an inline XanoScript expression. An optional final argument sets a timeout (in seconds).
2837
+
2838
+ ```xs
2839
+ [1,2,3]|lambda_map:"return $this * 2":10
2840
+ ```
2841
+
2842
+ Result: `[2,4,6]`
2843
+
2844
+ Context variables:
2845
+
2846
+ - `$this` - the element of the array being processed.
2847
+ - `$index` - the numerical index of the element of the array being processed.
2848
+ - `$parent` - the entire array with all of its elements.
2849
+
2850
+ # lambda_filter
2851
+
2852
+ Like `filter`, but the predicate is written as a string of JS/TS code. Return a truthy value to keep the element. An optional final argument sets a timeout (in seconds).
2853
+
2854
+ ```xs
2855
+ [1,2,3,4]|lambda_filter:"return $this % 2":10
2856
+ ```
2857
+
2858
+ Result: `[1,3]`
2859
+
2860
+ Context variables:
2861
+
2862
+ - `$this` - the element of the array being processed.
2863
+ - `$index` - the numerical index of the element of the array being processed.
2864
+ - `$parent` - the entire array with all of its elements.
2865
+
2866
+ # lambda_some
2867
+
2868
+ Like `some`, but the predicate is written as a string of JS/TS code. An optional final argument sets a timeout (in seconds).
2869
+
2870
+ ```xs
2871
+ [1,2,3]|lambda_some:"return $this > 2":10
2872
+ ```
2873
+
2874
+ Result: `true`
2875
+
2876
+ Context variables:
2877
+
2878
+ - `$this` - the element of the array being processed.
2879
+ - `$index` - the numerical index of the element of the array being processed.
2880
+ - `$parent` - the entire array with all of its elements.
2881
+
2882
+ # lambda_every
2883
+
2884
+ Like `every`, but the predicate is written as a string of JS/TS code. An optional final argument sets a timeout (in seconds).
2885
+
2886
+ ```xs
2887
+ [2,4,6]|lambda_every:"return $this % 2 === 0":10
2888
+ ```
2889
+
2890
+ Result: `true`
2891
+
2892
+ Context variables:
2893
+
2894
+ - `$this` - the element of the array being processed.
2895
+ - `$index` - the numerical index of the element of the array being processed.
2896
+ - `$parent` - the entire array with all of its elements.
2897
+
2898
+ # lambda_find
2899
+
2900
+ Like `find`, but the predicate is written as a string of JS/TS code. An optional final argument sets a timeout (in seconds).
2901
+
2902
+ ```xs
2903
+ [1,2,3,8,9]|lambda_find:"return $this === 8":10
2904
+ ```
2905
+
2906
+ Result: `8`
2907
+
2908
+ Context variables:
2909
+
2910
+ - `$this` - the element of the array being processed.
2911
+ - `$index` - the numerical index of the element of the array being processed.
2912
+ - `$parent` - the entire array with all of its elements.
2913
+
2914
+ # lambda_findIndex
2915
+
2916
+ Like `findIndex`, but the predicate is written as a string of JS/TS code. An optional final argument sets a timeout (in seconds).
2917
+
2918
+ ```xs
2919
+ [1,2,3,8,9]|lambda_findIndex:"return $this === 8":10
2920
+ ```
2921
+
2922
+ Result: `3`
2923
+
2924
+ Context variables:
2925
+
2926
+ - `$this` - the element of the array being processed.
2927
+ - `$index` - the numerical index of the element of the array being processed.
2928
+ - `$parent` - the entire array with all of its elements.
2929
+
2930
+ # lambda_reduce
2931
+
2932
+ Like `reduce`, but the reducer is written as a string of JS/TS code. Takes an initial value before the code block, and an optional final argument that sets a timeout (in seconds).
2933
+
2934
+ ```xs
2935
+ [1,2,3,4,5]|lambda_reduce:[]:"return [...$result, $this + 1];":10
2936
+ ```
2937
+
2938
+ Result: `[2,3,4,5,6]`
2939
+
2940
+ Context variables:
2941
+
2942
+ - `$this` - the element of the array being processed.
2943
+ - `$index` - the numerical index of the element of the array being processed.
2944
+ - `$parent` - the entire array with all of its elements.
2945
+ - `$result` - the result of the previous iteration, or the initial value on the first iteration.
2946
+
2834
2947
  # pick
2835
2948
 
2836
2949
  Pick keys from the object to create a new object of just those keys.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xano/xanoscript-language-server",
3
- "version": "12.5.0",
3
+ "version": "12.6.0",
4
4
  "description": "Language Server Protocol implementation for XanoScript",
5
5
  "type": "module",
6
6
  "main": "server.js",
@@ -44,6 +44,7 @@ export function nakedStackFn($) {
44
44
  { ALT: () => $.SUBRULE($.redisFn) },
45
45
  { ALT: () => $.SUBRULE($.controlFn, { ARGS: [options] }) },
46
46
  { ALT: () => $.SUBRULE($.debugFn) },
47
+ { ALT: () => $.SUBRULE($.datadogFn) },
47
48
  { ALT: () => $.SUBRULE($.storageFn) },
48
49
  { ALT: () => $.SUBRULE($.streamFn) },
49
50
  { ALT: () => $.SUBRULE($.actionCallFn) },
@@ -0,0 +1,21 @@
1
+ import { DatadogLogBulkToken } from "../../../lexer/datadog.js";
2
+
3
+ /**
4
+ * datadog.log_bulk {
5
+ * entries = $entries
6
+ * }
7
+ * @param {import('../../base_parser.js').XanoBaseParser} $
8
+ */
9
+ export function datadogLogBulkFn($) {
10
+ const requiredAttrs = ["entries"];
11
+ const optionalAttrs = ["description", "disabled"];
12
+
13
+ return () => {
14
+ $.sectionStack.push("datadogLogBulk");
15
+ const tokenFn = $.CONSUME(DatadogLogBulkToken); // log_bulk
16
+ $.SUBRULE($.functionAttrReq, {
17
+ ARGS: [tokenFn, requiredAttrs, optionalAttrs],
18
+ });
19
+ $.sectionStack.pop();
20
+ };
21
+ }
@@ -0,0 +1,36 @@
1
+ import { DatadogLogToken } from "../../../lexer/datadog.js";
2
+
3
+ /**
4
+ * datadog.log {
5
+ * message = "hi"
6
+ * status = "info"
7
+ * attributes = '{"A":"B"}'|json_decode
8
+ * }
9
+ * @param {import('../../base_parser.js').XanoBaseParser} $
10
+ */
11
+ export function datadogLogFn($) {
12
+ const requiredAttrs = ["message"];
13
+ const optionalAttrs = [
14
+ "status",
15
+ "attributes",
16
+ "service",
17
+ "source",
18
+ "env",
19
+ "hostname",
20
+ "ddtags",
21
+ "tags",
22
+ "timestamp",
23
+ "connection",
24
+ "description",
25
+ "disabled",
26
+ ];
27
+
28
+ return () => {
29
+ $.sectionStack.push("datadogLog");
30
+ const tokenFn = $.CONSUME(DatadogLogToken); // log
31
+ $.SUBRULE($.functionAttrReq, {
32
+ ARGS: [tokenFn, requiredAttrs, optionalAttrs],
33
+ });
34
+ $.sectionStack.pop();
35
+ };
36
+ }
@@ -0,0 +1,21 @@
1
+ import { DatadogMetricBulkToken } from "../../../lexer/datadog.js";
2
+
3
+ /**
4
+ * datadog.metric_bulk {
5
+ * entries = $entries
6
+ * }
7
+ * @param {import('../../base_parser.js').XanoBaseParser} $
8
+ */
9
+ export function datadogMetricBulkFn($) {
10
+ const requiredAttrs = ["entries"];
11
+ const optionalAttrs = ["description", "disabled"];
12
+
13
+ return () => {
14
+ $.sectionStack.push("datadogMetricBulk");
15
+ const tokenFn = $.CONSUME(DatadogMetricBulkToken); // metric_bulk
16
+ $.SUBRULE($.functionAttrReq, {
17
+ ARGS: [tokenFn, requiredAttrs, optionalAttrs],
18
+ });
19
+ $.sectionStack.pop();
20
+ };
21
+ }
@@ -0,0 +1,36 @@
1
+ import { DatadogMetricToken } from "../../../lexer/datadog.js";
2
+
3
+ /**
4
+ * datadog.metric {
5
+ * metric = "requests.count"
6
+ * value = 1
7
+ * type = "count"
8
+ * tags = '{"env":"prod"}'|json_decode
9
+ * }
10
+ * @param {import('../../base_parser.js').XanoBaseParser} $
11
+ */
12
+ export function datadogMetricFn($) {
13
+ const requiredAttrs = ["metric", "value"];
14
+ const optionalAttrs = [
15
+ "type",
16
+ "tags",
17
+ "service",
18
+ "source",
19
+ "env",
20
+ "hostname",
21
+ "ddtags",
22
+ "timestamp",
23
+ "connection",
24
+ "description",
25
+ "disabled",
26
+ ];
27
+
28
+ return () => {
29
+ $.sectionStack.push("datadogMetric");
30
+ const tokenFn = $.CONSUME(DatadogMetricToken); // metric
31
+ $.SUBRULE($.functionAttrReq, {
32
+ ARGS: [tokenFn, requiredAttrs, optionalAttrs],
33
+ });
34
+ $.sectionStack.pop();
35
+ };
36
+ }
@@ -0,0 +1,18 @@
1
+ import { datadogLogBulkFn } from "./datadogLogBulkFn.js";
2
+ import { datadogLogFn } from "./datadogLogFn.js";
3
+ import { datadogMetricBulkFn } from "./datadogMetricBulkFn.js";
4
+ import { datadogMetricFn } from "./datadogMetricFn.js";
5
+
6
+ /**
7
+ * Registers all the parsers in this folder
8
+ * @param {import('../base_parser.js').XanoBaseParser} $
9
+ */
10
+ export const register = ($) => {
11
+ $.datadogLogFn = $.RULE("datadogLogFn", datadogLogFn($));
12
+ $.datadogLogBulkFn = $.RULE("datadogLogBulkFn", datadogLogBulkFn($));
13
+ $.datadogMetricFn = $.RULE("datadogMetricFn", datadogMetricFn($));
14
+ $.datadogMetricBulkFn = $.RULE(
15
+ "datadogMetricBulkFn",
16
+ datadogMetricBulkFn($)
17
+ );
18
+ };
@@ -0,0 +1,20 @@
1
+ import { DatadogToken } from "../../lexer/datadog.js";
2
+ import { DotToken } from "../../lexer/tokens.js";
3
+
4
+ /**
5
+ * @param {import('../base_parser.js').XanoBaseParser} $
6
+ */
7
+ export function datadogFn($) {
8
+ return () => {
9
+ $.sectionStack.push("datadog");
10
+ $.CONSUME(DatadogToken); // "datadog"
11
+ $.CONSUME(DotToken); // "."
12
+ $.OR([
13
+ { ALT: () => $.SUBRULE($.datadogLogBulkFn) }, // datadog.log_bulk
14
+ { ALT: () => $.SUBRULE($.datadogLogFn) }, // datadog.log
15
+ { ALT: () => $.SUBRULE($.datadogMetricBulkFn) }, // datadog.metric_bulk
16
+ { ALT: () => $.SUBRULE($.datadogMetricFn) }, // datadog.metric
17
+ ]);
18
+ $.sectionStack.pop();
19
+ };
20
+ }
@@ -10,6 +10,8 @@ import { register as register_cloud } from "./cloud/register.js";
10
10
  import { cloudFn } from "./cloudFn.js";
11
11
  import { controlFn } from "./controlFn.js";
12
12
  import { register as register_controls } from "./controls/register.js";
13
+ import { register as register_datadog } from "./datadog/register.js";
14
+ import { datadogFn } from "./datadogFn.js";
13
15
  import { register as register_db } from "./db/register.js";
14
16
  import { dbFn } from "./dbFn.js";
15
17
  import { register as register_debug } from "./debug/register.js";
@@ -56,6 +58,7 @@ export const register = ($) => {
56
58
  $.arrayFn = $.RULE("arrayFn", arrayFn($));
57
59
  $.cloudFn = $.RULE("cloudFn", cloudFn($));
58
60
  $.controlFn = $.RULE("controlFn", controlFn($));
61
+ $.datadogFn = $.RULE("datadogFn", datadogFn($));
59
62
  $.dbFn = $.RULE("dbFn", dbFn($));
60
63
  $.debugFn = $.RULE("debugFn", debugFn($));
61
64
  $.mathFn = $.RULE("mathFn", mathFn($));
@@ -78,6 +81,7 @@ export const register = ($) => {
78
81
  register_array($);
79
82
  register_cloud($);
80
83
  register_controls($);
84
+ register_datadog($);
81
85
  register_db($);
82
86
  register_debug($);
83
87
  register_math($);
@@ -279,6 +279,17 @@ export const filterNames = [
279
279
  "find",
280
280
  "findIndex",
281
281
  "reduce",
282
+ // Lambda variants of the array filters above. Instead of an inline XanoScript
283
+ // expression, they take a string of JS/TS code, e.g.
284
+ // $set|lambda_map:"return $this * 2"
285
+ // $set|lambda_reduce:[]:"return [...$result, $this + 1];":10
286
+ "lambda_map",
287
+ "lambda_filter",
288
+ "lambda_some",
289
+ "lambda_every",
290
+ "lambda_find",
291
+ "lambda_findIndex",
292
+ "lambda_reduce",
282
293
  "pick",
283
294
  "unpick",
284
295
  "text_unescape",