@plitzi/sdk-shared 0.37.2 → 0.37.3

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.
Files changed (184) hide show
  1. package/CHANGELOG.md +1146 -0
  2. package/dist/actions/access.d.ts +12 -0
  3. package/dist/actions/access.mjs +13 -0
  4. package/dist/actions/functions.d.ts +27 -0
  5. package/dist/actions/functions.mjs +18 -0
  6. package/dist/actions/index.d.ts +4 -0
  7. package/dist/actions/index.mjs +9 -7
  8. package/dist/auth/index.d.ts +2 -0
  9. package/dist/auth/index.mjs +2 -1
  10. package/dist/auth/visitorRoles.d.ts +27 -0
  11. package/dist/auth/visitorRoles.mjs +48 -0
  12. package/dist/authoring/builder.mjs +1 -0
  13. package/dist/authoring/declare.d.ts +53 -0
  14. package/dist/authoring/declare.mjs +2 -2
  15. package/dist/authoring/index.mjs +5 -5
  16. package/dist/authoring/paramSpec.d.ts +1 -1
  17. package/dist/authoring/paramSpec.mjs +1 -0
  18. package/dist/authoring/spaceCallbacks.mjs +2 -2
  19. package/dist/dataSource/computed.d.ts +21 -0
  20. package/dist/dataSource/computed.mjs +45 -0
  21. package/dist/dataSource/getBindingsDetails.mjs +35 -34
  22. package/dist/dataSource/index.d.ts +1 -0
  23. package/dist/dataSource/index.mjs +7 -6
  24. package/dist/dataSource/utility/not.mjs +4 -7
  25. package/dist/dataSource/utility/stringToArray.mjs +1 -1
  26. package/dist/dataSource/utility/truthiness.d.ts +1 -0
  27. package/dist/dataSource/utility/truthiness.mjs +8 -0
  28. package/dist/dataSource/utility/twigTemplate.d.ts +2 -1
  29. package/dist/dataSource/utility/twigTemplate.mjs +29 -17
  30. package/dist/devTools/utils/PlitziConsole.mjs +22 -22
  31. package/dist/helpers/cookies.d.ts +10 -0
  32. package/dist/helpers/cookies.mjs +19 -0
  33. package/dist/helpers/fetchManifest.d.ts +9 -0
  34. package/dist/helpers/fetchManifest.mjs +3 -6
  35. package/dist/helpers/formatDate.d.ts +5 -3
  36. package/dist/helpers/formatDate.mjs +34 -36
  37. package/dist/helpers/index.d.ts +2 -0
  38. package/dist/helpers/index.mjs +18 -14
  39. package/dist/helpers/isDate.d.ts +7 -0
  40. package/dist/helpers/isDate.mjs +15 -0
  41. package/dist/helpers/keys.d.ts +42 -0
  42. package/dist/helpers/keys.mjs +91 -0
  43. package/dist/helpers/twigWrapper/AST.d.ts +2 -2
  44. package/dist/helpers/twigWrapper/Evaluator/Evaluator.d.ts +12 -2
  45. package/dist/helpers/twigWrapper/Evaluator/Evaluator.mjs +57 -34
  46. package/dist/helpers/twigWrapper/Evaluator/index.d.ts +1 -1
  47. package/dist/helpers/twigWrapper/Evaluator/index.mjs +2 -2
  48. package/dist/helpers/twigWrapper/Parser/ExpressionParser.d.ts +2 -2
  49. package/dist/helpers/twigWrapper/Parser/ExpressionParser.mjs +147 -34
  50. package/dist/helpers/twigWrapper/Parser/Parser.d.ts +2 -1
  51. package/dist/helpers/twigWrapper/Parser/Parser.mjs +21 -20
  52. package/dist/helpers/twigWrapper/filters/filters.mjs +130 -112
  53. package/dist/helpers/twigWrapper/index.d.ts +5 -2
  54. package/dist/helpers/twigWrapper/index.mjs +7 -5
  55. package/dist/helpers/twigWrapper/inspectTemplate.d.ts +23 -0
  56. package/dist/helpers/twigWrapper/inspectTemplate.mjs +110 -0
  57. package/dist/helpers/twigWrapper/processTwig/helpers.d.ts +7 -0
  58. package/dist/helpers/twigWrapper/processTwig/helpers.mjs +2 -1
  59. package/dist/helpers/twigWrapper/processTwig/index.d.ts +2 -1
  60. package/dist/helpers/twigWrapper/processTwig/index.mjs +3 -2
  61. package/dist/helpers/twigWrapper/processTwig/processTwig.d.ts +28 -0
  62. package/dist/helpers/twigWrapper/processTwig/processTwig.mjs +73 -16
  63. package/dist/helpers/twigWrapper/processTwig/resolveStepParam.d.ts +17 -0
  64. package/dist/helpers/twigWrapper/processTwig/resolveStepParam.mjs +14 -0
  65. package/dist/helpers/twigWrapper/templateRoots.d.ts +11 -0
  66. package/dist/helpers/twigWrapper/templateRoots.mjs +4 -4
  67. package/dist/helpers/twigWrapper/tokens/hasTemplateSyntax.d.ts +1 -1
  68. package/dist/history/describe.d.ts +29 -0
  69. package/dist/history/describe.mjs +93 -0
  70. package/dist/history/diff.d.ts +33 -0
  71. package/dist/history/diff.mjs +73 -0
  72. package/dist/history/index.d.ts +3 -0
  73. package/dist/history/index.mjs +3 -0
  74. package/dist/history/types.d.ts +48 -0
  75. package/dist/history/types.mjs +0 -0
  76. package/dist/index.d.ts +1 -0
  77. package/dist/index.mjs +77 -66
  78. package/dist/navigation/index.d.ts +1 -1
  79. package/dist/navigation/index.mjs +2 -2
  80. package/dist/navigation/routes.d.ts +11 -1
  81. package/dist/navigation/routes.mjs +15 -10
  82. package/dist/network/graphql/builder/Mutations/Space/SpaceFixIssuesMutation.d.ts +14 -0
  83. package/dist/network/graphql/builder/Mutations/Space/SpaceFixIssuesMutation.mjs +16 -0
  84. package/dist/network/graphql/builder/Mutations/Space/SpaceUpdatePluginMutation.d.ts +4 -0
  85. package/dist/network/graphql/builder/Mutations/Space/SpaceUpdatePluginMutation.mjs +2 -2
  86. package/dist/network/graphql/builder/Mutations/Space/actions/SpaceRunActionMutation.mjs +1 -0
  87. package/dist/network/graphql/builder/Mutations/Space/functions/SpaceRemoveFunctionsMutation.d.ts +3 -0
  88. package/dist/network/graphql/builder/Mutations/Space/functions/SpaceRemoveFunctionsMutation.mjs +9 -0
  89. package/dist/network/graphql/builder/Mutations/Space/functions/SpaceSaveFunctionsMutation.d.ts +11 -0
  90. package/dist/network/graphql/builder/Mutations/Space/functions/SpaceSaveFunctionsMutation.mjs +24 -0
  91. package/dist/network/graphql/builder/Mutations/Space/functions/SpaceTryFunctionMutation.d.ts +4 -0
  92. package/dist/network/graphql/builder/Mutations/Space/functions/SpaceTryFunctionMutation.mjs +15 -0
  93. package/dist/network/graphql/builder/Mutations/Space/runtime/SpaceRemoveRuntimeMutation.d.ts +2 -0
  94. package/dist/network/graphql/builder/Mutations/Space/runtime/SpaceRemoveRuntimeMutation.mjs +9 -0
  95. package/dist/network/graphql/builder/Mutations/Space/runtime/SpaceRemoveRuntimeVariableMutation.d.ts +2 -0
  96. package/dist/network/graphql/builder/Mutations/Space/runtime/SpaceRemoveRuntimeVariableMutation.mjs +9 -0
  97. package/dist/network/graphql/builder/Mutations/Space/runtime/SpaceSetRuntimeSizeMutation.d.ts +2 -0
  98. package/dist/network/graphql/builder/Mutations/Space/runtime/SpaceSetRuntimeSizeMutation.mjs +9 -0
  99. package/dist/network/graphql/builder/Mutations/Space/runtime/SpaceSetRuntimeVariableMutation.d.ts +2 -0
  100. package/dist/network/graphql/builder/Mutations/Space/runtime/SpaceSetRuntimeVariableMutation.mjs +9 -0
  101. package/dist/network/graphql/builder/Mutations/Space/runtime/SpaceStartRuntimeMutation.d.ts +2 -0
  102. package/dist/network/graphql/builder/Mutations/Space/runtime/SpaceStartRuntimeMutation.mjs +9 -0
  103. package/dist/network/graphql/builder/Mutations/Space/runtime/SpaceStopRuntimeMutation.d.ts +2 -0
  104. package/dist/network/graphql/builder/Mutations/Space/runtime/SpaceStopRuntimeMutation.mjs +9 -0
  105. package/dist/network/graphql/builder/Mutations/Space/visitors/SpaceAddVisitorMutation.d.ts +2 -0
  106. package/dist/network/graphql/builder/Mutations/Space/visitors/SpaceAddVisitorMutation.mjs +11 -0
  107. package/dist/network/graphql/builder/Mutations/Space/visitors/SpaceRemoveVisitorMutation.d.ts +2 -0
  108. package/dist/network/graphql/builder/Mutations/Space/visitors/SpaceRemoveVisitorMutation.mjs +11 -0
  109. package/dist/network/graphql/builder/Mutations/index.d.ts +28 -0
  110. package/dist/network/graphql/builder/Mutations/index.mjs +108 -84
  111. package/dist/network/graphql/builder/Queries/Space/SpaceChangesQuery.d.ts +23 -0
  112. package/dist/network/graphql/builder/Queries/Space/SpaceChangesQuery.mjs +49 -0
  113. package/dist/network/graphql/builder/Queries/Space/SpaceFunctionsQuery.d.ts +6 -0
  114. package/dist/network/graphql/builder/Queries/Space/SpaceFunctionsQuery.mjs +13 -0
  115. package/dist/network/graphql/builder/Queries/Space/SpaceIssuesQuery.d.ts +17 -0
  116. package/dist/network/graphql/builder/Queries/Space/SpaceIssuesQuery.mjs +22 -0
  117. package/dist/network/graphql/builder/Queries/Space/SpaceRuntimeQuery.d.ts +6 -0
  118. package/dist/network/graphql/builder/Queries/Space/SpaceRuntimeQuery.mjs +32 -0
  119. package/dist/network/graphql/builder/Queries/Space/SpaceVisitorsQuery.d.ts +6 -0
  120. package/dist/network/graphql/builder/Queries/Space/SpaceVisitorsQuery.mjs +16 -0
  121. package/dist/network/graphql/builder/Queries/index.d.ts +17 -3
  122. package/dist/network/graphql/builder/Queries/index.mjs +30 -22
  123. package/dist/network/graphql/sdk/Mutations/index.d.ts +1 -1
  124. package/dist/network/graphql/sdk/Queries/InitQuery.d.ts +1 -1
  125. package/dist/network/graphql/sdk/Queries/InitQuery.mjs +2 -91
  126. package/dist/network/graphql/sdk/Queries/Segment/SegmentQuery.d.ts +1 -1
  127. package/dist/network/graphql/sdk/Queries/Segment/SegmentQuery.mjs +2 -44
  128. package/dist/network/graphql/sdk/Queries/Segment/SegmentsQuery.d.ts +1 -1
  129. package/dist/network/graphql/sdk/Queries/Segment/SegmentsQuery.mjs +2 -55
  130. package/dist/network/graphql/sdk/Queries/index.d.ts +1 -5
  131. package/dist/network/index.mjs +7 -7
  132. package/dist/network/spaceEvents.d.ts +33 -3
  133. package/dist/network/spaceEvents.mjs +102 -89
  134. package/dist/realtime/client.d.ts +46 -0
  135. package/dist/realtime/client.mjs +192 -0
  136. package/dist/realtime/index.d.ts +6 -0
  137. package/dist/realtime/index.mjs +4 -0
  138. package/dist/realtime/presence.d.ts +38 -0
  139. package/dist/realtime/presence.mjs +70 -0
  140. package/dist/realtime/topics.d.ts +36 -0
  141. package/dist/realtime/topics.mjs +25 -0
  142. package/dist/server/actions/useRealtimeSync.d.ts +9 -0
  143. package/dist/server/actions/useRealtimeSync.mjs +7 -0
  144. package/dist/state/index.d.ts +1 -0
  145. package/dist/state/index.mjs +3 -2
  146. package/dist/state/paintedState.d.ts +52 -0
  147. package/dist/state/paintedState.mjs +37 -0
  148. package/dist/state/runtimeStatePersist.d.ts +8 -1
  149. package/dist/state/runtimeStatePersist.mjs +79 -29
  150. package/dist/store/index.d.ts +45 -45
  151. package/dist/store/renderSettings.d.ts +6 -3
  152. package/dist/store/tracing/index.d.ts +1 -0
  153. package/dist/store/tracing/tracingCollector.d.ts +17 -1
  154. package/dist/store/tracing/tracingCollector.mjs +5 -0
  155. package/dist/style/index.d.ts +1 -0
  156. package/dist/style/index.mjs +3 -2
  157. package/dist/style/runtimeStyle.d.ts +29 -0
  158. package/dist/style/runtimeStyle.mjs +7 -0
  159. package/dist/style/styleConstants.d.ts +3 -2
  160. package/dist/style/styleConstants.mjs +2 -0
  161. package/dist/style/styleStates.d.ts +14 -1
  162. package/dist/style/styleStates.mjs +10 -7
  163. package/dist/theme/ThemeProvider.mjs +35 -29
  164. package/dist/theme/themeCookie.mjs +11 -15
  165. package/dist/types/ActionTypes.d.ts +4 -0
  166. package/dist/types/AuthTypes.d.ts +11 -1
  167. package/dist/types/CommonTypes.d.ts +6 -0
  168. package/dist/types/FunctionTypes.d.ts +52 -0
  169. package/dist/types/FunctionTypes.mjs +0 -0
  170. package/dist/types/PluginTypes.d.ts +0 -1
  171. package/dist/types/RealtimeTypes.d.ts +94 -0
  172. package/dist/types/RealtimeTypes.mjs +0 -0
  173. package/dist/types/SchemaTypes.d.ts +54 -0
  174. package/dist/types/SchemaTypes.mjs +8 -0
  175. package/dist/types/ServerTypes.d.ts +259 -15
  176. package/dist/types/SpaceTypes.d.ts +53 -0
  177. package/dist/types/StateTypes.d.ts +6 -0
  178. package/dist/types/StoreTypes.d.ts +11 -0
  179. package/dist/types/index.d.ts +2 -0
  180. package/dist/types/index.mjs +3 -2
  181. package/package.json +172 -11
  182. package/vite.config.ts +0 -12
  183. package/dist/network/graphql/builder/Queries/PluginsQuery.d.ts +0 -9
  184. package/dist/network/graphql/builder/Queries/PluginsQuery.mjs +0 -54
@@ -1,7 +1,8 @@
1
1
  import { isTruthy as e, resolveCollection as t, resolveObjectEntries as n, valueIn as r } from "./helpers.mjs";
2
2
  import { ARROW_PARAMS as i, filters as a, isRawMarker as o, unwrapRaw as s } from "../filters/filters.mjs";
3
+ import { serializeValue as c } from "../processTwig/helpers.mjs";
3
4
  //#region src/helpers/twigWrapper/Evaluator/Evaluator.ts
4
- var c = {
5
+ var l = {
5
6
  defined: (e) => e !== void 0,
6
7
  null: (e) => e == null,
7
8
  none: (e) => e == null,
@@ -9,21 +10,24 @@ var c = {
9
10
  iterable: (e) => Array.isArray(e) || typeof e == "object" && !!e,
10
11
  even: (e) => typeof e == "number" && e % 2 == 0,
11
12
  odd: (e) => typeof e == "number" && Math.abs(e % 2) === 1
12
- }, l = (e) => e.type === "path" || e.type === "filter" && l(e.subject), u = (e, t) => t == null || t === "" && l(e), d = [], f = (e, t, n = !1) => {
13
- let r = new p(t, n);
13
+ }, u = (e) => e.type === "path" || e.type === "filter" && u(e.subject), d = (e, t) => t == null || t === "" && u(e), f = (e) => e.type === "path" && e.segments.length === 1 ? e.segments[0] : e.type === "literal" && e.value === null ? "null" : void 0, p = [], m = (e, t, n = !1, r = !1) => {
14
+ let i = new g(t, n, r);
14
15
  return {
15
- output: r.evalNodes(e),
16
- variables: r.variables,
17
- hasSet: r.hasSet
16
+ output: i.evalNodes(e),
17
+ variables: i.variables,
18
+ hasSet: i.hasSet
18
19
  };
19
- }, p = class l {
20
+ }, h = (e, t) => new g(t).evalExpression(e), g = class u {
20
21
  variables;
21
22
  keepEmptyTokens;
23
+ jsonStrings;
24
+ inString = !1;
25
+ escaping = !1;
22
26
  breakFlag = !1;
23
27
  continueFlag = !1;
24
28
  hasSet = !1;
25
- constructor(e, t = !1) {
26
- this.variables = { ...e }, this.keepEmptyTokens = t;
29
+ constructor(e, t = !1, n = !1) {
30
+ this.variables = { ...e }, this.keepEmptyTokens = t, this.jsonStrings = n;
27
31
  }
28
32
  evalNodes(e) {
29
33
  let t = e.length;
@@ -35,8 +39,8 @@ var c = {
35
39
  }
36
40
  evalNode(e) {
37
41
  switch (e.type) {
38
- case "text": return e.value;
39
- case "variable": return this.evalVariable(e);
42
+ case "text": return this.jsonStrings && this.followQuotes(e.value), e.value;
43
+ case "variable": return this.jsonStrings && this.inString ? JSON.stringify(this.evalVariable(e)).slice(1, -1) : this.evalVariable(e);
40
44
  case "if": return this.evalIf(e);
41
45
  case "for": return this.evalFor(e);
42
46
  case "set": return this.evalSet(e);
@@ -47,7 +51,13 @@ var c = {
47
51
  }
48
52
  evalVariable(e) {
49
53
  let t = this.evalExpression(e.expression);
50
- return this.keepEmptyTokens && u(e.expression, t) ? e.source : o(t) ? String(s(t)) : typeof t == "function" ? "" : t != null && typeof t != "object" ? String(t) : e.raw ? t == null ? "" : String(t) : typeof t == "object" && t ? JSON.stringify(t) : "";
54
+ return this.keepEmptyTokens && d(e.expression, t) ? e.source : o(t) ? String(s(t)) : typeof t == "function" ? "" : t != null && typeof t != "object" ? String(t) : e.raw ? t == null ? "" : String(t) : typeof t == "object" && t ? JSON.stringify(t) : "";
55
+ }
56
+ followQuotes(e) {
57
+ for (let t = 0; t < e.length; t++) {
58
+ let n = e[t];
59
+ this.escaping ? this.escaping = !1 : this.inString && n === "\\" ? this.escaping = !0 : n === "\"" && (this.inString = !this.inString);
60
+ }
51
61
  }
52
62
  evalIf(t) {
53
63
  if (e(this.evalExpression(t.condition))) return this.evalNodes(t.body);
@@ -102,7 +112,7 @@ var c = {
102
112
  let n = e;
103
113
  for (let e of t) {
104
114
  let t = a[e.name];
105
- t !== void 0 && (n = t(n, e.args.length === 0 ? d : this.evalArgs(e.args)));
115
+ t !== void 0 && (n = t(n, e.args.length === 0 ? p : this.evalArgs(e.args)));
106
116
  }
107
117
  return n;
108
118
  }
@@ -143,13 +153,16 @@ var c = {
143
153
  case "unary": return t.operator === "-" ? -Number(this.evalExpression(t.operand)) : !e(this.evalExpression(t.operand));
144
154
  case "binary": return this.evalBinary(t.operator, t.left, t.right);
145
155
  case "default": return this.evalExpression(t.value) ?? this.evalExpression(t.defaultExpr);
146
- case "ternary": return e(this.evalExpression(t.condition)) ? this.evalExpression(t.trueExpr) : this.evalExpression(t.falseExpr);
156
+ case "ternary": {
157
+ let n = this.evalExpression(t.condition);
158
+ return e(n) ? t.trueExpr ? this.evalExpression(t.trueExpr) : n : this.evalExpression(t.falseExpr);
159
+ }
147
160
  case "arrow": return this.createArrowFunction(t.params, t.body);
148
161
  }
149
162
  }
150
163
  createArrowFunction(e, t) {
151
164
  let n = { ...this.variables }, r = this.keepEmptyTokens, a = (...i) => {
152
- let a = new l(n, r);
165
+ let a = new u(n, r);
153
166
  for (let t = 0; t < e.length; t++) a.variables[e[t]] = i[t];
154
167
  return a.evalExpression(t);
155
168
  };
@@ -208,8 +221,9 @@ var c = {
208
221
  return a;
209
222
  }
210
223
  evalBinary(t, n, i) {
211
- if ((t === "is" || t === "is not") && i.type === "path" && i.segments.length === 1) {
212
- let e = c[i.segments[0]];
224
+ let a = f(i);
225
+ if ((t === "is" || t === "is not") && a !== void 0) {
226
+ let e = l[a];
213
227
  if (e) {
214
228
  let r = e(this.evalExpression(n));
215
229
  return t === "is" ? r : !r;
@@ -217,26 +231,35 @@ var c = {
217
231
  }
218
232
  if (t === "or") return e(this.evalExpression(n)) || e(this.evalExpression(i));
219
233
  if (t === "and") return e(this.evalExpression(n)) && e(this.evalExpression(i));
220
- let a = this.evalExpression(n), o = this.evalExpression(i), s = typeof a == "number" && typeof o == "number";
234
+ let o = this.evalExpression(n), s = this.evalExpression(i), u = typeof o == "number" && typeof s == "number";
221
235
  switch (t) {
222
- case "+": return s ? a + o : Number(a) + Number(o);
223
- case "-": return s ? a - o : Number(a) - Number(o);
224
- case "*": return s ? a * o : Number(a) * Number(o);
225
- case "/": return s ? a / o : Number(a) / Number(o);
226
- case "%": return s ? a % o : Number(a) % Number(o);
227
- case "==": return a === o || String(a) === String(o);
228
- case "!=": return a !== o && String(a) !== String(o);
229
- case ">": return s ? a > o : Number(a) > Number(o);
230
- case "<": return s ? a < o : Number(a) < Number(o);
231
- case ">=": return s ? a >= o : Number(a) >= Number(o);
232
- case "<=": return s ? a <= o : Number(a) <= Number(o);
233
- case "in": return r(a, o);
234
- case "not in": return !r(a, o);
235
- case "is": return a === o;
236
- case "is not": return a !== o;
236
+ case "+": return u ? o + s : Number(o) + Number(s);
237
+ case "-": return u ? o - s : Number(o) - Number(s);
238
+ case "*": return u ? o * s : Number(o) * Number(s);
239
+ case "/": return u ? o / s : Number(o) / Number(s);
240
+ case "//": return Math.floor(Number(o) / Number(s));
241
+ case "**": return Number(o) ** Number(s);
242
+ case "starts with": return typeof o == "string" && o.startsWith(c(s));
243
+ case "ends with": return typeof o == "string" && o.endsWith(c(s));
244
+ case "%": return u ? o % s : Number(o) % Number(s);
245
+ case "==": return o === s || String(o) === String(s);
246
+ case "!=": return o !== s && String(o) !== String(s);
247
+ case ">": return u ? o > s : Number(o) > Number(s);
248
+ case "<": return u ? o < s : Number(o) < Number(s);
249
+ case ">=": return u ? o >= s : Number(o) >= Number(s);
250
+ case "<=": return u ? o <= s : Number(o) <= Number(s);
251
+ case "in": return r(o, s);
252
+ case "not in": return !r(o, s);
253
+ case "same as": return o === s;
254
+ case "divisible by": {
255
+ let e = Number(s);
256
+ return e !== 0 && Number.isFinite(e) && Number(o) % e === 0;
257
+ }
258
+ case "is": return o === s;
259
+ case "is not": return o !== s;
237
260
  default: return !1;
238
261
  }
239
262
  }
240
263
  };
241
264
  //#endregion
242
- export { f as evaluate };
265
+ export { m as evaluate, h as evaluateExpression };
@@ -1,2 +1,2 @@
1
- export { evaluate } from './Evaluator';
1
+ export { evaluate, evaluateExpression } from './Evaluator';
2
2
  export type { EvalResult } from './Evaluator';
@@ -1,2 +1,2 @@
1
- import { evaluate as e } from "./Evaluator.mjs";
2
- export { e as evaluate };
1
+ import { evaluate as e, evaluateExpression as t } from "./Evaluator.mjs";
2
+ export { e as evaluate, t as evaluateExpression };
@@ -1,3 +1,3 @@
1
1
  import { Expression, FilterCall } from '../AST';
2
- export declare const parseExpression: (expr: string) => Expression;
3
- export declare const parseApplyFilters: (expr: string) => FilterCall[];
2
+ export declare const parseExpression: (expr: string, issues?: string[]) => Expression;
3
+ export declare const parseApplyFilters: (expr: string, issues?: string[]) => FilterCall[];
@@ -1,20 +1,54 @@
1
1
  import { Char as e, isDigit as t } from "../charClass.mjs";
2
2
  import { Cursor as n } from "./Cursor.mjs";
3
3
  //#region src/helpers/twigWrapper/Parser/ExpressionParser.ts
4
- var r = (e) => new a(e).parseTernary(), i = (e) => new a(e).parseApplyChain(), a = class extends n {
4
+ var r = (e, t) => {
5
+ let n = new s(e, t), r = n.parseTernary();
6
+ return n.expectEnd(), r;
7
+ }, i = (e, t) => {
8
+ let n = new s(e, t), r = n.parseApplyChain();
9
+ return n.expectEnd(), r;
10
+ }, a = ["same as", "divisible by"], o = "`matches` is not supported: templates evaluate no regular expressions. Use `starts with`, `ends with` or `in`.", s = class extends n {
11
+ issues;
12
+ constructor(e, t) {
13
+ super(e), this.issues = t;
14
+ }
15
+ report(e) {
16
+ this.issues?.push(e);
17
+ }
18
+ expectEnd() {
19
+ this.skipWs(), this.eof() || this.report(`Unexpected "${this.src.slice(this.pos).trim()}" in "${this.src.trim()}"`);
20
+ }
21
+ expectChar(e, t) {
22
+ if (this.skipWs(), this.peek() === e) {
23
+ this.pos++;
24
+ return;
25
+ }
26
+ this.report(`Missing ${t} in "${this.src.trim()}"`);
27
+ }
5
28
  parseTernary() {
6
29
  let t = this.parseOr();
7
- if (this.skipWs(), this.peek() === e.Question) {
8
- this.pos++, this.skipWs();
9
- let n = this.parseOr();
10
- if (this.skipWs(), this.peek() === e.Colon) return this.pos++, this.skipWs(), {
11
- type: "ternary",
12
- condition: t,
13
- trueExpr: n,
14
- falseExpr: this.parseTernary()
15
- };
16
- }
17
- return t;
30
+ if (this.skipWs(), this.peek() !== e.Question) return t;
31
+ if (this.pos++, this.skipWs(), this.peek() === e.Colon) return this.pos++, this.skipWs(), {
32
+ type: "ternary",
33
+ condition: t,
34
+ trueExpr: null,
35
+ falseExpr: this.parseTernary()
36
+ };
37
+ let n = this.parseOr();
38
+ return this.skipWs(), this.peek() === e.Colon ? (this.pos++, this.skipWs(), {
39
+ type: "ternary",
40
+ condition: t,
41
+ trueExpr: n,
42
+ falseExpr: this.parseTernary()
43
+ }) : {
44
+ type: "ternary",
45
+ condition: t,
46
+ trueExpr: n,
47
+ falseExpr: {
48
+ type: "literal",
49
+ value: ""
50
+ }
51
+ };
18
52
  }
19
53
  parseOr() {
20
54
  let e = this.parseAnd();
@@ -47,9 +81,27 @@ var r = (e) => new a(e).parseTernary(), i = (e) => new a(e).parseApplyChain(), a
47
81
  let e = this.parseConcat();
48
82
  for (this.skipWs(); !this.eof();) {
49
83
  if (this.matchKeyword("is")) {
50
- this.skipWs(), e = {
84
+ this.skipWs();
85
+ let t = this.matchKeyword("not");
86
+ this.skipWs();
87
+ let n = this.matchWordedTest();
88
+ if (n) {
89
+ let r = {
90
+ type: "binary",
91
+ operator: n,
92
+ left: e,
93
+ right: this.parseConcat()
94
+ };
95
+ e = t ? {
96
+ type: "unary",
97
+ operator: "not",
98
+ operand: r
99
+ } : r, this.skipWs();
100
+ continue;
101
+ }
102
+ e = {
51
103
  type: "binary",
52
- operator: this.matchKeyword("not") ? "is not" : "is",
104
+ operator: t ? "is not" : "is",
53
105
  left: e,
54
106
  right: this.parseConcat()
55
107
  }, this.skipWs();
@@ -69,7 +121,7 @@ var r = (e) => new a(e).parseTernary(), i = (e) => new a(e).parseApplyChain(), a
69
121
  return this.pos = this.src.length, {
70
122
  type: "unary",
71
123
  operator: "not",
72
- operand: r(t)
124
+ operand: r(t, this.issues)
73
125
  };
74
126
  }
75
127
  if (this.matchKeyword("in")) {
@@ -81,7 +133,7 @@ var r = (e) => new a(e).parseTernary(), i = (e) => new a(e).parseApplyChain(), a
81
133
  }, this.skipWs();
82
134
  continue;
83
135
  }
84
- let t = this.matchBinaryOp();
136
+ let t = this.matchAffixTest();
85
137
  if (t) {
86
138
  e = {
87
139
  type: "binary",
@@ -91,10 +143,48 @@ var r = (e) => new a(e).parseTernary(), i = (e) => new a(e).parseApplyChain(), a
91
143
  }, this.skipWs();
92
144
  continue;
93
145
  }
146
+ if (this.matchKeyword("matches")) {
147
+ this.report(o), e = {
148
+ type: "binary",
149
+ operator: "matches",
150
+ left: e,
151
+ right: this.parseConcat()
152
+ }, this.skipWs();
153
+ continue;
154
+ }
155
+ let n = this.matchBinaryOp();
156
+ if (n) {
157
+ e = {
158
+ type: "binary",
159
+ operator: n,
160
+ left: e,
161
+ right: this.parseConcat()
162
+ }, this.skipWs();
163
+ continue;
164
+ }
94
165
  break;
95
166
  }
96
167
  return e;
97
168
  }
169
+ matchWordedTest() {
170
+ let e = this.pos;
171
+ for (let t of a) {
172
+ let [n, r] = t.split(" ");
173
+ if (this.matchKeyword(n)) {
174
+ if (this.skipWs(), this.matchKeyword(r)) return t;
175
+ this.pos = e;
176
+ }
177
+ }
178
+ return null;
179
+ }
180
+ matchAffixTest() {
181
+ let e = this.pos;
182
+ for (let t of ["starts", "ends"]) if (this.matchKeyword(t)) {
183
+ if (this.matchKeyword("with")) return t === "starts" ? "starts with" : "ends with";
184
+ this.pos = e;
185
+ }
186
+ return null;
187
+ }
98
188
  parseConcat() {
99
189
  let t = this.parseAdditive();
100
190
  for (this.skipWs(); this.peek() === e.Tilde;) {
@@ -122,15 +212,27 @@ var r = (e) => new a(e).parseTernary(), i = (e) => new a(e).parseApplyChain(), a
122
212
  return t;
123
213
  }
124
214
  parseMultiplicative() {
125
- let t = this.parseDefault();
215
+ let t = this.parsePower();
126
216
  this.skipWs();
127
- for (let n = this.peek(); n === e.Star || n === e.Slash || n === e.Percent; n = this.peek()) this.pos++, t = {
217
+ for (let n = this.peek(); (n === e.Star || n === e.Slash || n === e.Percent) && (n !== e.Star || this.at(1) !== e.Star); n = this.peek()) {
218
+ let r = n === e.Slash && this.at(1) === e.Slash;
219
+ this.pos += r ? 2 : 1, t = {
220
+ type: "binary",
221
+ operator: r ? "//" : n === e.Star ? "*" : n === e.Slash ? "/" : "%",
222
+ left: t,
223
+ right: this.parsePower()
224
+ }, this.skipWs();
225
+ }
226
+ return t;
227
+ }
228
+ parsePower() {
229
+ let t = this.parseDefault();
230
+ return this.skipWs(), this.peek() !== e.Star || this.at(1) !== e.Star ? t : (this.pos += 2, {
128
231
  type: "binary",
129
- operator: n === e.Star ? "*" : n === e.Slash ? "/" : "%",
232
+ operator: "**",
130
233
  left: t,
131
- right: this.parseDefault()
132
- }, this.skipWs();
133
- return t;
234
+ right: this.parsePower()
235
+ });
134
236
  }
135
237
  parseDefault() {
136
238
  if (this.skipWs(), this.peek() === e.Minus && t(this.at(1))) return this.maybeTrailingFilters({
@@ -163,18 +265,25 @@ var r = (e) => new a(e).parseTernary(), i = (e) => new a(e).parseApplyChain(), a
163
265
  });
164
266
  this.pos = t;
165
267
  let r = this.parseTernary();
166
- return this.skipWs(), this.peek() === e.RParen && this.pos++, this.maybeTrailingFilters(this.parseAccessChain(r, null));
268
+ return this.expectChar(e.RParen, "a closing \")\""), this.maybeTrailingFilters(this.parseAccessChain(r, null));
167
269
  }
168
- return n === e.SingleQuote || n === e.DoubleQuote ? this.maybeTrailingFilters({
270
+ if (n === e.SingleQuote || n === e.DoubleQuote) return this.maybeTrailingFilters({
169
271
  type: "literal",
170
272
  value: this.scanStringLiteral()
171
- }) : t(n) ? this.maybeTrailingFilters({
273
+ });
274
+ if (t(n)) return this.maybeTrailingFilters({
172
275
  type: "literal",
173
276
  value: this.scanNumber()
174
- }) : n === e.LBracket ? (this.pos++, this.maybeTrailingFilters({
175
- type: "array",
176
- elements: this.parseArgList(e.RBracket)
177
- })) : n === e.LBrace ? (this.pos++, this.maybeTrailingFilters(this.parseObjectLiteral())) : this.parsePathOrFunctionOrArrow();
277
+ });
278
+ if (n === e.LBracket) {
279
+ this.pos++;
280
+ let t = {
281
+ type: "array",
282
+ elements: this.parseArgList(e.RBracket)
283
+ };
284
+ return this.maybeTrailingFilters(this.parseAccessChain(t, null));
285
+ }
286
+ return n === e.LBrace ? (this.pos++, this.maybeTrailingFilters(this.parseAccessChain(this.parseObjectLiteral(), null))) : this.parsePathOrFunctionOrArrow();
178
287
  }
179
288
  tryParseArrowParams() {
180
289
  let t = this.pos, n = [];
@@ -191,7 +300,7 @@ var r = (e) => new a(e).parseTernary(), i = (e) => new a(e).parseApplyChain(), a
191
300
  }
192
301
  parsePathOrFunctionOrArrow() {
193
302
  let t = this.scanName();
194
- if (!t) return this.pos++, {
303
+ if (!t) return this.report(this.eof() ? `Missing a value at the end of "${this.src.trim()}"` : `Unexpected "${this.src.slice(this.pos).trim()}" in "${this.src.trim()}"`), this.pos++, {
195
304
  type: "literal",
196
305
  value: ""
197
306
  };
@@ -199,6 +308,10 @@ var r = (e) => new a(e).parseTernary(), i = (e) => new a(e).parseApplyChain(), a
199
308
  type: "literal",
200
309
  value: t === "true"
201
310
  });
311
+ if (t === "null" || t === "none") return this.maybeTrailingFilters({
312
+ type: "literal",
313
+ value: null
314
+ });
202
315
  if (this.skipWs(), this.peek() === e.Equals && this.at(1) === e.Greater) return this.pos += 2, this.maybeTrailingFilters({
203
316
  type: "arrow",
204
317
  params: [t],
@@ -244,7 +357,7 @@ var r = (e) => new a(e).parseTernary(), i = (e) => new a(e).parseApplyChain(), a
244
357
  if (t !== e.LBracket) break;
245
358
  this.pos++;
246
359
  let n = this.parseTernary();
247
- if (this.skipWs(), this.peek() === e.RBracket && this.pos++, i && n.type === "literal" && typeof n.value != "boolean") {
360
+ if (this.expectChar(e.RBracket, "a closing \"]\""), i && n.type === "literal" && (typeof n.value == "string" || typeof n.value == "number")) {
248
361
  i.push(String(n.value));
249
362
  continue;
250
363
  }
@@ -278,7 +391,7 @@ var r = (e) => new a(e).parseTernary(), i = (e) => new a(e).parseApplyChain(), a
278
391
  value: this.parseTernary()
279
392
  }), this.skipWs(), this.peek() === e.Comma && (this.pos++, this.skipWs());
280
393
  }
281
- return this.peek() === e.RBrace && this.pos++, {
394
+ return this.expectChar(e.RBrace, "a closing \"}\""), {
282
395
  type: "object",
283
396
  entries: t
284
397
  };
@@ -306,7 +419,7 @@ var r = (e) => new a(e).parseTernary(), i = (e) => new a(e).parseApplyChain(), a
306
419
  parseArgList(t) {
307
420
  let n = [];
308
421
  for (this.skipWs(); !this.eof() && this.peek() !== t;) n.push(this.parseTernary()), this.skipWs(), this.peek() === e.Comma && (this.pos++, this.skipWs());
309
- return this.peek() === t && this.pos++, n;
422
+ return this.expectChar(t, t === e.RParen ? "a closing \")\"" : "a closing \"]\""), n;
310
423
  }
311
424
  parseTrailingFilters() {
312
425
  let t = [];
@@ -321,7 +434,7 @@ var r = (e) => new a(e).parseTernary(), i = (e) => new a(e).parseApplyChain(), a
321
434
  }
322
435
  readFilter() {
323
436
  let t = this.scanName();
324
- return this.skipWs(), this.peek() === e.LParen ? (this.pos++, {
437
+ return t || this.report(`A "|" with no filter name after it in "${this.src.trim()}"`), this.skipWs(), this.peek() === e.LParen ? (this.pos++, {
325
438
  name: t,
326
439
  args: this.parseArgList(e.RParen)
327
440
  }) : {
@@ -1,3 +1,4 @@
1
1
  import { Token } from '../Lexer';
2
2
  import { ParseResult } from './types';
3
- export declare const parse: (tokens: readonly Token[], keepEmptyTokens?: boolean) => ParseResult;
3
+ /** `issues`, when given, collects what the expression grammar read past rather than understood — see `inspectTemplate`. */
4
+ export declare const parse: (tokens: readonly Token[], keepEmptyTokens?: boolean, issues?: string[]) => ParseResult;
@@ -3,18 +3,18 @@ import { reconstructSource as n, reconstructToken as r } from "../Lexer/types.mj
3
3
  import { parseApplyFilters as i, parseExpression as a } from "./ExpressionParser.mjs";
4
4
  import { extractFirstWord as o, splitRange as s } from "./helpers.mjs";
5
5
  //#region src/helpers/twigWrapper/Parser/Parser.ts
6
- var c = (e, t = !1) => {
7
- let n = new f(e, t), r = n.parseBody();
8
- if (!n.error) {
9
- let e = n.peek();
6
+ var c = (e, t = !1, n) => {
7
+ let r = new f(e, t, n), i = r.parseBody();
8
+ if (!r.error) {
9
+ let e = r.peek();
10
10
  if (e && e.type === "tag") {
11
11
  let t = o(e.content.trim());
12
- l.has(t) && (n.error = `Orphan closing tag: {% ${t} %} without matching opening tag`);
12
+ l.has(t) && (r.error = `Orphan closing tag: {% ${t} %} without matching opening tag`);
13
13
  }
14
14
  }
15
15
  return {
16
- nodes: r,
17
- error: n.error
16
+ nodes: i,
17
+ error: r.error
18
18
  };
19
19
  }, l = /* @__PURE__ */ new Set([
20
20
  "endif",
@@ -45,10 +45,11 @@ var c = (e, t = !1) => {
45
45
  }), f = class {
46
46
  tokens;
47
47
  keepEmptyTokens;
48
+ issues;
48
49
  pos = 0;
49
50
  error = null;
50
- constructor(e, t = !1) {
51
- this.tokens = e, this.keepEmptyTokens = t;
51
+ constructor(e, t = !1, n) {
52
+ this.tokens = e, this.keepEmptyTokens = t, this.issues = n;
52
53
  }
53
54
  peek() {
54
55
  return this.tokens[this.pos];
@@ -101,7 +102,7 @@ var c = (e, t = !1) => {
101
102
  },
102
103
  source: i
103
104
  };
104
- let o = a(r);
105
+ let o = a(r, this.issues);
105
106
  return {
106
107
  type: "variable",
107
108
  raw: t.raw,
@@ -112,15 +113,15 @@ var c = (e, t = !1) => {
112
113
  parseTag() {
113
114
  let e = this.peek();
114
115
  if (!e || e.type !== "tag") return null;
115
- let t = e.content.trim();
116
- switch (o(t)) {
116
+ let t = e.content.trim(), n = o(t);
117
+ switch (n) {
117
118
  case "if": return this.parseIf();
118
119
  case "for": return this.parseFor();
119
120
  case "set": return this.parseSet();
120
121
  case "apply": return this.parseApply();
121
122
  case "break": return this.advance(), { type: "break" };
122
123
  case "continue": return this.advance(), { type: "continue" };
123
- default: return this.advance(), null;
124
+ default: return this.issues?.push(`Unknown tag {% ${n} %}: the tags are if, for, set, apply, break and continue`), this.advance(), null;
124
125
  }
125
126
  }
126
127
  parseIf() {
@@ -129,14 +130,14 @@ var c = (e, t = !1) => {
129
130
  if (e.type !== "tag") return this.error = "Malformed {% if %} tag", u();
130
131
  let t = e.content.trim(), n = t.indexOf(" ") === -1 ? "" : t.slice(t.indexOf(" ") + 1).trim();
131
132
  if (!n) return this.error = "Malformed {% if %} tag: missing condition", u();
132
- let r = a(n), i = this.parseBody(), s = [], c = null, l = !1;
133
+ let r = a(n, this.issues), i = this.parseBody(), s = [], c = null, l = !1;
133
134
  for (; this.peek();) {
134
135
  let e = this.peek();
135
136
  if (!e || e.type !== "tag") break;
136
137
  let t = o(e.content.trim());
137
138
  if (t === "elseif") {
138
139
  this.advance();
139
- let t = e.content.trim(), n = t.slice(t.indexOf(" ") + 1).trim(), r = a(n), i = this.parseBody();
140
+ let t = e.content.trim(), n = t.slice(t.indexOf(" ") + 1).trim(), r = a(n, this.issues), i = this.parseBody();
140
141
  s.push({
141
142
  condition: r,
142
143
  body: i
@@ -164,9 +165,9 @@ var c = (e, t = !1) => {
164
165
  if (!c) return this.error = "Invalid {% for %} syntax: missing the `in` keyword", d();
165
166
  let l = i.slice(0, c.index).trim(), u = i.slice(c.index + c[0].length).trim(), f = s(u), p = f ? {
166
167
  type: "range",
167
- start: a(f[0]),
168
- end: a(f[1])
169
- } : a(u), m = l.indexOf(","), h = m === -1 ? null : l.slice(0, m).trim(), g = m === -1 ? l : l.slice(m + 1).trim();
168
+ start: a(f[0], this.issues),
169
+ end: a(f[1], this.issues)
170
+ } : a(u, this.issues), m = l.indexOf(","), h = m === -1 ? null : l.slice(0, m).trim(), g = m === -1 ? l : l.slice(m + 1).trim();
170
171
  if (!t(g)) return this.error = `Invalid {% for %} variable name: "${g}"`, d();
171
172
  if (h !== null && !t(h)) return this.error = `Invalid {% for %} key variable name: "${h}"`, d();
172
173
  let _ = this.parseBody(), v = null;
@@ -216,7 +217,7 @@ var c = (e, t = !1) => {
216
217
  return {
217
218
  type: "set",
218
219
  name: i,
219
- value: a(o)
220
+ value: a(o, this.issues)
220
221
  };
221
222
  }
222
223
  parseApply() {
@@ -227,7 +228,7 @@ var c = (e, t = !1) => {
227
228
  filters: [],
228
229
  body: []
229
230
  };
230
- let t = e.content.trim(), n = t.slice(t.indexOf(" ") + 1).trim(), r = i(n), a = this.parseBody(), o = this.peek();
231
+ let t = e.content.trim(), n = t.slice(t.indexOf(" ") + 1).trim(), r = i(n, this.issues), a = this.parseBody(), o = this.peek();
231
232
  return o && o.type === "tag" && this.advance(), {
232
233
  type: "apply",
233
234
  filters: r,