@builder.io/sdk-qwik 0.16.15 → 0.16.16

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 (52) hide show
  1. package/lib/browser/blocks/text/text.qwik.cjs +1 -2
  2. package/lib/browser/blocks/text/text.qwik.mjs +1 -2
  3. package/lib/browser/components/block/block.helpers.qwik.cjs +1 -2
  4. package/lib/browser/components/block/block.helpers.qwik.mjs +1 -2
  5. package/lib/browser/components/content/components/enable-editor.qwik.cjs +1 -2
  6. package/lib/browser/components/content/components/enable-editor.qwik.mjs +1 -2
  7. package/lib/browser/components/content/content.qwik.cjs +1 -5
  8. package/lib/browser/components/content/content.qwik.mjs +1 -5
  9. package/lib/browser/constants/sdk-version.qwik.cjs +1 -1
  10. package/lib/browser/constants/sdk-version.qwik.mjs +1 -1
  11. package/lib/browser/functions/evaluate/evaluate.qwik.cjs +16 -38
  12. package/lib/browser/functions/evaluate/evaluate.qwik.mjs +17 -39
  13. package/lib/browser/functions/get-block-actions-handler.qwik.cjs +1 -2
  14. package/lib/browser/functions/get-block-actions-handler.qwik.mjs +1 -2
  15. package/lib/browser/functions/get-processed-block.qwik.cjs +1 -2
  16. package/lib/browser/functions/get-processed-block.qwik.mjs +1 -2
  17. package/lib/edge/blocks/text/text.qwik.cjs +1 -2
  18. package/lib/edge/blocks/text/text.qwik.mjs +1 -2
  19. package/lib/edge/components/block/block.helpers.qwik.cjs +1 -2
  20. package/lib/edge/components/block/block.helpers.qwik.mjs +1 -2
  21. package/lib/edge/components/content/components/enable-editor.qwik.cjs +1 -2
  22. package/lib/edge/components/content/components/enable-editor.qwik.mjs +1 -2
  23. package/lib/edge/components/content/content.qwik.cjs +1 -5
  24. package/lib/edge/components/content/content.qwik.mjs +1 -5
  25. package/lib/edge/constants/sdk-version.qwik.cjs +1 -1
  26. package/lib/edge/constants/sdk-version.qwik.mjs +1 -1
  27. package/lib/edge/functions/evaluate/evaluate.qwik.cjs +16 -38
  28. package/lib/edge/functions/evaluate/evaluate.qwik.mjs +17 -39
  29. package/lib/edge/functions/get-block-actions-handler.qwik.cjs +1 -2
  30. package/lib/edge/functions/get-block-actions-handler.qwik.mjs +1 -2
  31. package/lib/edge/functions/get-processed-block.qwik.cjs +1 -2
  32. package/lib/edge/functions/get-processed-block.qwik.mjs +1 -2
  33. package/lib/node/blocks/text/text.qwik.cjs +1 -2
  34. package/lib/node/blocks/text/text.qwik.mjs +1 -2
  35. package/lib/node/components/block/block.helpers.qwik.cjs +1 -2
  36. package/lib/node/components/block/block.helpers.qwik.mjs +1 -2
  37. package/lib/node/components/content/components/enable-editor.qwik.cjs +1 -2
  38. package/lib/node/components/content/components/enable-editor.qwik.mjs +1 -2
  39. package/lib/node/components/content/content.qwik.cjs +1 -5
  40. package/lib/node/components/content/content.qwik.mjs +1 -5
  41. package/lib/node/constants/sdk-version.qwik.cjs +1 -1
  42. package/lib/node/constants/sdk-version.qwik.mjs +1 -1
  43. package/lib/node/functions/evaluate/evaluate.qwik.cjs +16 -38
  44. package/lib/node/functions/evaluate/evaluate.qwik.mjs +17 -39
  45. package/lib/node/functions/get-block-actions-handler.qwik.cjs +1 -2
  46. package/lib/node/functions/get-block-actions-handler.qwik.mjs +1 -2
  47. package/lib/node/functions/get-processed-block.qwik.cjs +1 -2
  48. package/lib/node/functions/get-processed-block.qwik.mjs +1 -2
  49. package/package.json +1 -1
  50. package/types/src/constants/sdk-version.d.ts +1 -1
  51. package/types/src/functions/evaluate/evaluate.d.ts +2 -1
  52. package/types/src/functions/evaluate/helpers.d.ts +0 -1
@@ -13,8 +13,7 @@ const Text = qwik.component$((props) => {
13
13
  context: contextContext,
14
14
  localState,
15
15
  rootState,
16
- rootSetState,
17
- enableCache: false
16
+ rootSetState
18
17
  }));
19
18
  });
20
19
  return /* @__PURE__ */ jsxRuntime.jsx("div", {
@@ -11,8 +11,7 @@ const Text = component$((props) => {
11
11
  context: contextContext,
12
12
  localState,
13
13
  rootState,
14
- rootSetState,
15
- enableCache: false
14
+ rootSetState
16
15
  }));
17
16
  });
18
17
  return /* @__PURE__ */ jsx("div", {
@@ -27,8 +27,7 @@ const getRepeatItemData = ({ block, context }) => {
27
27
  localState: context.localState,
28
28
  rootState: context.rootState,
29
29
  rootSetState: context.rootSetState,
30
- context: context.context,
31
- enableCache: true
30
+ context: context.context
32
31
  });
33
32
  if (!Array.isArray(itemsArray)) {
34
33
  return void 0;
@@ -25,8 +25,7 @@ const getRepeatItemData = ({ block, context }) => {
25
25
  localState: context.localState,
26
26
  rootState: context.rootState,
27
27
  rootSetState: context.rootSetState,
28
- context: context.context,
29
- enableCache: true
28
+ context: context.context
30
29
  });
31
30
  if (!Array.isArray(itemsArray)) {
32
31
  return void 0;
@@ -109,8 +109,7 @@ const runHttpRequests = function runHttpRequests2(props, state, showContentProps
109
109
  context: props.context || {},
110
110
  localState: void 0,
111
111
  rootState: props.builderContextSignal.rootState,
112
- rootSetState: props.builderContextSignal.rootSetState,
113
- enableCache: true
112
+ rootSetState: props.builderContextSignal.rootSetState
114
113
  })));
115
114
  fetch(evaluatedUrl).then((response) => response.json()).then((json) => {
116
115
  mergeNewRootState(props, state, showContentProps, elementRef, {
@@ -107,8 +107,7 @@ const runHttpRequests = function runHttpRequests2(props, state, showContentProps
107
107
  context: props.context || {},
108
108
  localState: void 0,
109
109
  rootState: props.builderContextSignal.rootState,
110
- rootSetState: props.builderContextSignal.rootSetState,
111
- enableCache: true
110
+ rootSetState: props.builderContextSignal.rootSetState
112
111
  })));
113
112
  fetch(evaluatedUrl).then((response) => response.json()).then((json) => {
114
113
  mergeNewRootState(props, state, showContentProps, elementRef, {
@@ -94,11 +94,7 @@ const ContentComponent = qwik.component$((props) => {
94
94
  var _a3, _b3;
95
95
  (_b3 = (_a3 = state.builderContextSignal).rootSetState) == null ? void 0 : _b3.call(_a3, newState);
96
96
  },
97
- isExpression: false,
98
- /**
99
- * We don't want to cache the result of the JS code, since it's arbitrary side effect code.
100
- */
101
- enableCache: false
97
+ isExpression: false
102
98
  });
103
99
  }
104
100
  });
@@ -92,11 +92,7 @@ const ContentComponent = component$((props) => {
92
92
  var _a3, _b3;
93
93
  (_b3 = (_a3 = state.builderContextSignal).rootSetState) == null ? void 0 : _b3.call(_a3, newState);
94
94
  },
95
- isExpression: false,
96
- /**
97
- * We don't want to cache the result of the JS code, since it's arbitrary side effect code.
98
- */
99
- enableCache: false
95
+ isExpression: false
100
96
  });
101
97
  }
102
98
  });
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const SDK_VERSION = "0.16.15";
3
+ const SDK_VERSION = "0.16.16";
4
4
  exports.SDK_VERSION = SDK_VERSION;
@@ -1,4 +1,4 @@
1
- const SDK_VERSION = "0.16.15";
1
+ const SDK_VERSION = "0.16.16";
2
2
  export {
3
3
  SDK_VERSION
4
4
  };
@@ -1,38 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const logger = require("../../helpers/logger.qwik.cjs");
4
+ const get = require("../get.qwik.cjs");
4
5
  const chooseEval = require("./choose-eval.qwik.cjs");
5
6
  const helpers = require("./helpers.qwik.cjs");
6
- const DISABLE_CACHE = true;
7
- const _EvalCache = class _EvalCache2 {
8
- static getCacheKey(args) {
9
- return JSON.stringify({
10
- ...args,
11
- // replace the event with a random number to break cache
12
- // thats because we can't serialize the event object due to circular refs in DOM node refs.
13
- event: args.event ? Math.random() : void 0
14
- });
15
- }
16
- static getCachedValue(key) {
17
- const cachedVal = _EvalCache2.cache.get(key);
18
- return cachedVal;
19
- }
20
- static setCachedValue(key, value) {
21
- if (_EvalCache2.cache.size > 20) {
22
- _EvalCache2.cache.delete(_EvalCache2.cache.keys().next().value);
23
- }
24
- _EvalCache2.cache.set(key, {
25
- value
26
- });
27
- }
7
+ const STATE_GETTER_REGEX = /^(return )?(\s*)?state(?<getPath>(\.\w+)+)(\s*);?$/;
8
+ const VIRTUAL_INDEX_REGEX = /(\s)*var(\s)+_virtual_index(\s)*=(\s)*state(?<getPath>(\.\w+)+)(\s*);?(\s)*return(\s)*_virtual_index(\s)*/;
9
+ const getSimpleExpressionGetPath = (code) => {
10
+ var _a, _b, _c, _d, _e, _f;
11
+ return ((_c = (_b = (_a = STATE_GETTER_REGEX.exec(code.trim())) == null ? void 0 : _a.groups) == null ? void 0 : _b.getPath) == null ? void 0 : _c.slice(1)) || ((_f = (_e = (_d = VIRTUAL_INDEX_REGEX.exec(code.trim())) == null ? void 0 : _d.groups) == null ? void 0 : _e.getPath) == null ? void 0 : _f.slice(1));
28
12
  };
29
- _EvalCache.cacheLimit = 20;
30
- _EvalCache.cache = /* @__PURE__ */ new Map();
31
- let EvalCache = _EvalCache;
32
- function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true, enableCache }) {
33
- if (code === "") {
13
+ function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true }) {
14
+ if (code.trim() === "") {
34
15
  return void 0;
35
16
  }
17
+ const getPath = getSimpleExpressionGetPath(code.trim());
18
+ if (getPath) {
19
+ return get.get({
20
+ ...rootState,
21
+ ...localState
22
+ }, getPath);
23
+ }
36
24
  const args = {
37
25
  code: helpers.parseCode(code, {
38
26
  isExpression
@@ -44,19 +32,8 @@ function evaluate({ code, context, localState, rootState, rootSetState, event, i
44
32
  rootState,
45
33
  localState
46
34
  };
47
- if (enableCache && !DISABLE_CACHE) {
48
- const cacheKey = EvalCache.getCacheKey(args);
49
- const cachedValue = EvalCache.getCachedValue(cacheKey);
50
- if (cachedValue) {
51
- return cachedValue.value;
52
- }
53
- }
54
35
  try {
55
36
  const newEval = chooseEval.chooseBrowserOrServerEval(args);
56
- if (enableCache) {
57
- const cacheKey = EvalCache.getCacheKey(args);
58
- EvalCache.setCachedValue(cacheKey, newEval);
59
- }
60
37
  return newEval;
61
38
  } catch (e) {
62
39
  logger.logger.error("Failed code evaluation: " + e.message, {
@@ -66,3 +43,4 @@ function evaluate({ code, context, localState, rootState, rootSetState, event, i
66
43
  }
67
44
  }
68
45
  exports.evaluate = evaluate;
46
+ exports.getSimpleExpressionGetPath = getSimpleExpressionGetPath;
@@ -1,36 +1,24 @@
1
1
  import { logger } from "../../helpers/logger.qwik.mjs";
2
+ import { get } from "../get.qwik.mjs";
2
3
  import { chooseBrowserOrServerEval } from "./choose-eval.qwik.mjs";
3
4
  import { parseCode, getBuilderGlobals } from "./helpers.qwik.mjs";
4
- const DISABLE_CACHE = true;
5
- const _EvalCache = class _EvalCache2 {
6
- static getCacheKey(args) {
7
- return JSON.stringify({
8
- ...args,
9
- // replace the event with a random number to break cache
10
- // thats because we can't serialize the event object due to circular refs in DOM node refs.
11
- event: args.event ? Math.random() : void 0
12
- });
13
- }
14
- static getCachedValue(key) {
15
- const cachedVal = _EvalCache2.cache.get(key);
16
- return cachedVal;
17
- }
18
- static setCachedValue(key, value) {
19
- if (_EvalCache2.cache.size > 20) {
20
- _EvalCache2.cache.delete(_EvalCache2.cache.keys().next().value);
21
- }
22
- _EvalCache2.cache.set(key, {
23
- value
24
- });
25
- }
5
+ const STATE_GETTER_REGEX = /^(return )?(\s*)?state(?<getPath>(\.\w+)+)(\s*);?$/;
6
+ const VIRTUAL_INDEX_REGEX = /(\s)*var(\s)+_virtual_index(\s)*=(\s)*state(?<getPath>(\.\w+)+)(\s*);?(\s)*return(\s)*_virtual_index(\s)*/;
7
+ const getSimpleExpressionGetPath = (code) => {
8
+ var _a, _b, _c, _d, _e, _f;
9
+ return ((_c = (_b = (_a = STATE_GETTER_REGEX.exec(code.trim())) == null ? void 0 : _a.groups) == null ? void 0 : _b.getPath) == null ? void 0 : _c.slice(1)) || ((_f = (_e = (_d = VIRTUAL_INDEX_REGEX.exec(code.trim())) == null ? void 0 : _d.groups) == null ? void 0 : _e.getPath) == null ? void 0 : _f.slice(1));
26
10
  };
27
- _EvalCache.cacheLimit = 20;
28
- _EvalCache.cache = /* @__PURE__ */ new Map();
29
- let EvalCache = _EvalCache;
30
- function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true, enableCache }) {
31
- if (code === "") {
11
+ function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true }) {
12
+ if (code.trim() === "") {
32
13
  return void 0;
33
14
  }
15
+ const getPath = getSimpleExpressionGetPath(code.trim());
16
+ if (getPath) {
17
+ return get({
18
+ ...rootState,
19
+ ...localState
20
+ }, getPath);
21
+ }
34
22
  const args = {
35
23
  code: parseCode(code, {
36
24
  isExpression
@@ -42,19 +30,8 @@ function evaluate({ code, context, localState, rootState, rootSetState, event, i
42
30
  rootState,
43
31
  localState
44
32
  };
45
- if (enableCache && !DISABLE_CACHE) {
46
- const cacheKey = EvalCache.getCacheKey(args);
47
- const cachedValue = EvalCache.getCachedValue(cacheKey);
48
- if (cachedValue) {
49
- return cachedValue.value;
50
- }
51
- }
52
33
  try {
53
34
  const newEval = chooseBrowserOrServerEval(args);
54
- if (enableCache) {
55
- const cacheKey = EvalCache.getCacheKey(args);
56
- EvalCache.setCachedValue(cacheKey, newEval);
57
- }
58
35
  return newEval;
59
36
  } catch (e) {
60
37
  logger.error("Failed code evaluation: " + e.message, {
@@ -64,5 +41,6 @@ function evaluate({ code, context, localState, rootState, rootSetState, event, i
64
41
  }
65
42
  }
66
43
  export {
67
- evaluate
44
+ evaluate,
45
+ getSimpleExpressionGetPath
68
46
  };
@@ -9,8 +9,7 @@ function createEventHandler(value, options) {
9
9
  localState: options.localState,
10
10
  rootState: options.rootState,
11
11
  rootSetState: options.rootSetState,
12
- event,
13
- enableCache: true
12
+ event
14
13
  }));
15
14
  }
16
15
  exports.createEventHandler = createEventHandler;
@@ -7,8 +7,7 @@ function createEventHandler(value, options) {
7
7
  localState: options.localState,
8
8
  rootState: options.rootState,
9
9
  rootSetState: options.rootSetState,
10
- event,
11
- enableCache: true
10
+ event
12
11
  }));
13
12
  }
14
13
  export {
@@ -71,8 +71,7 @@ const evaluateBindings = ({ block, context, localState, rootState, rootSetState
71
71
  localState,
72
72
  rootState,
73
73
  rootSetState,
74
- context,
75
- enableCache: true
74
+ context
76
75
  });
77
76
  set.set(copied, binding, value);
78
77
  }
@@ -69,8 +69,7 @@ const evaluateBindings = ({ block, context, localState, rootState, rootSetState
69
69
  localState,
70
70
  rootState,
71
71
  rootSetState,
72
- context,
73
- enableCache: true
72
+ context
74
73
  });
75
74
  set(copied, binding, value);
76
75
  }
@@ -13,8 +13,7 @@ const Text = qwik.component$((props) => {
13
13
  context: contextContext,
14
14
  localState,
15
15
  rootState,
16
- rootSetState,
17
- enableCache: false
16
+ rootSetState
18
17
  }));
19
18
  });
20
19
  return /* @__PURE__ */ jsxRuntime.jsx("div", {
@@ -11,8 +11,7 @@ const Text = component$((props) => {
11
11
  context: contextContext,
12
12
  localState,
13
13
  rootState,
14
- rootSetState,
15
- enableCache: false
14
+ rootSetState
16
15
  }));
17
16
  });
18
17
  return /* @__PURE__ */ jsx("div", {
@@ -27,8 +27,7 @@ const getRepeatItemData = ({ block, context }) => {
27
27
  localState: context.localState,
28
28
  rootState: context.rootState,
29
29
  rootSetState: context.rootSetState,
30
- context: context.context,
31
- enableCache: true
30
+ context: context.context
32
31
  });
33
32
  if (!Array.isArray(itemsArray)) {
34
33
  return void 0;
@@ -25,8 +25,7 @@ const getRepeatItemData = ({ block, context }) => {
25
25
  localState: context.localState,
26
26
  rootState: context.rootState,
27
27
  rootSetState: context.rootSetState,
28
- context: context.context,
29
- enableCache: true
28
+ context: context.context
30
29
  });
31
30
  if (!Array.isArray(itemsArray)) {
32
31
  return void 0;
@@ -109,8 +109,7 @@ const runHttpRequests = function runHttpRequests2(props, state, showContentProps
109
109
  context: props.context || {},
110
110
  localState: void 0,
111
111
  rootState: props.builderContextSignal.rootState,
112
- rootSetState: props.builderContextSignal.rootSetState,
113
- enableCache: true
112
+ rootSetState: props.builderContextSignal.rootSetState
114
113
  })));
115
114
  fetch(evaluatedUrl).then((response) => response.json()).then((json) => {
116
115
  mergeNewRootState(props, state, showContentProps, elementRef, {
@@ -107,8 +107,7 @@ const runHttpRequests = function runHttpRequests2(props, state, showContentProps
107
107
  context: props.context || {},
108
108
  localState: void 0,
109
109
  rootState: props.builderContextSignal.rootState,
110
- rootSetState: props.builderContextSignal.rootSetState,
111
- enableCache: true
110
+ rootSetState: props.builderContextSignal.rootSetState
112
111
  })));
113
112
  fetch(evaluatedUrl).then((response) => response.json()).then((json) => {
114
113
  mergeNewRootState(props, state, showContentProps, elementRef, {
@@ -94,11 +94,7 @@ const ContentComponent = qwik.component$((props) => {
94
94
  var _a3, _b3;
95
95
  (_b3 = (_a3 = state.builderContextSignal).rootSetState) == null ? void 0 : _b3.call(_a3, newState);
96
96
  },
97
- isExpression: false,
98
- /**
99
- * We don't want to cache the result of the JS code, since it's arbitrary side effect code.
100
- */
101
- enableCache: false
97
+ isExpression: false
102
98
  });
103
99
  }
104
100
  });
@@ -92,11 +92,7 @@ const ContentComponent = component$((props) => {
92
92
  var _a3, _b3;
93
93
  (_b3 = (_a3 = state.builderContextSignal).rootSetState) == null ? void 0 : _b3.call(_a3, newState);
94
94
  },
95
- isExpression: false,
96
- /**
97
- * We don't want to cache the result of the JS code, since it's arbitrary side effect code.
98
- */
99
- enableCache: false
95
+ isExpression: false
100
96
  });
101
97
  }
102
98
  });
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const SDK_VERSION = "0.16.15";
3
+ const SDK_VERSION = "0.16.16";
4
4
  exports.SDK_VERSION = SDK_VERSION;
@@ -1,4 +1,4 @@
1
- const SDK_VERSION = "0.16.15";
1
+ const SDK_VERSION = "0.16.16";
2
2
  export {
3
3
  SDK_VERSION
4
4
  };
@@ -1,38 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const logger = require("../../helpers/logger.qwik.cjs");
4
+ const get = require("../get.qwik.cjs");
4
5
  const chooseEval = require("./choose-eval.qwik.cjs");
5
6
  const helpers = require("./helpers.qwik.cjs");
6
- const DISABLE_CACHE = true;
7
- const _EvalCache = class _EvalCache2 {
8
- static getCacheKey(args) {
9
- return JSON.stringify({
10
- ...args,
11
- // replace the event with a random number to break cache
12
- // thats because we can't serialize the event object due to circular refs in DOM node refs.
13
- event: args.event ? Math.random() : void 0
14
- });
15
- }
16
- static getCachedValue(key) {
17
- const cachedVal = _EvalCache2.cache.get(key);
18
- return cachedVal;
19
- }
20
- static setCachedValue(key, value) {
21
- if (_EvalCache2.cache.size > 20) {
22
- _EvalCache2.cache.delete(_EvalCache2.cache.keys().next().value);
23
- }
24
- _EvalCache2.cache.set(key, {
25
- value
26
- });
27
- }
7
+ const STATE_GETTER_REGEX = /^(return )?(\s*)?state(?<getPath>(\.\w+)+)(\s*);?$/;
8
+ const VIRTUAL_INDEX_REGEX = /(\s)*var(\s)+_virtual_index(\s)*=(\s)*state(?<getPath>(\.\w+)+)(\s*);?(\s)*return(\s)*_virtual_index(\s)*/;
9
+ const getSimpleExpressionGetPath = (code) => {
10
+ var _a, _b, _c, _d, _e, _f;
11
+ return ((_c = (_b = (_a = STATE_GETTER_REGEX.exec(code.trim())) == null ? void 0 : _a.groups) == null ? void 0 : _b.getPath) == null ? void 0 : _c.slice(1)) || ((_f = (_e = (_d = VIRTUAL_INDEX_REGEX.exec(code.trim())) == null ? void 0 : _d.groups) == null ? void 0 : _e.getPath) == null ? void 0 : _f.slice(1));
28
12
  };
29
- _EvalCache.cacheLimit = 20;
30
- _EvalCache.cache = /* @__PURE__ */ new Map();
31
- let EvalCache = _EvalCache;
32
- function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true, enableCache }) {
33
- if (code === "") {
13
+ function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true }) {
14
+ if (code.trim() === "") {
34
15
  return void 0;
35
16
  }
17
+ const getPath = getSimpleExpressionGetPath(code.trim());
18
+ if (getPath) {
19
+ return get.get({
20
+ ...rootState,
21
+ ...localState
22
+ }, getPath);
23
+ }
36
24
  const args = {
37
25
  code: helpers.parseCode(code, {
38
26
  isExpression
@@ -44,19 +32,8 @@ function evaluate({ code, context, localState, rootState, rootSetState, event, i
44
32
  rootState,
45
33
  localState
46
34
  };
47
- if (enableCache && !DISABLE_CACHE) {
48
- const cacheKey = EvalCache.getCacheKey(args);
49
- const cachedValue = EvalCache.getCachedValue(cacheKey);
50
- if (cachedValue) {
51
- return cachedValue.value;
52
- }
53
- }
54
35
  try {
55
36
  const newEval = chooseEval.chooseBrowserOrServerEval(args);
56
- if (enableCache) {
57
- const cacheKey = EvalCache.getCacheKey(args);
58
- EvalCache.setCachedValue(cacheKey, newEval);
59
- }
60
37
  return newEval;
61
38
  } catch (e) {
62
39
  logger.logger.error("Failed code evaluation: " + e.message, {
@@ -66,3 +43,4 @@ function evaluate({ code, context, localState, rootState, rootSetState, event, i
66
43
  }
67
44
  }
68
45
  exports.evaluate = evaluate;
46
+ exports.getSimpleExpressionGetPath = getSimpleExpressionGetPath;
@@ -1,36 +1,24 @@
1
1
  import { logger } from "../../helpers/logger.qwik.mjs";
2
+ import { get } from "../get.qwik.mjs";
2
3
  import { chooseBrowserOrServerEval } from "./choose-eval.qwik.mjs";
3
4
  import { parseCode, getBuilderGlobals } from "./helpers.qwik.mjs";
4
- const DISABLE_CACHE = true;
5
- const _EvalCache = class _EvalCache2 {
6
- static getCacheKey(args) {
7
- return JSON.stringify({
8
- ...args,
9
- // replace the event with a random number to break cache
10
- // thats because we can't serialize the event object due to circular refs in DOM node refs.
11
- event: args.event ? Math.random() : void 0
12
- });
13
- }
14
- static getCachedValue(key) {
15
- const cachedVal = _EvalCache2.cache.get(key);
16
- return cachedVal;
17
- }
18
- static setCachedValue(key, value) {
19
- if (_EvalCache2.cache.size > 20) {
20
- _EvalCache2.cache.delete(_EvalCache2.cache.keys().next().value);
21
- }
22
- _EvalCache2.cache.set(key, {
23
- value
24
- });
25
- }
5
+ const STATE_GETTER_REGEX = /^(return )?(\s*)?state(?<getPath>(\.\w+)+)(\s*);?$/;
6
+ const VIRTUAL_INDEX_REGEX = /(\s)*var(\s)+_virtual_index(\s)*=(\s)*state(?<getPath>(\.\w+)+)(\s*);?(\s)*return(\s)*_virtual_index(\s)*/;
7
+ const getSimpleExpressionGetPath = (code) => {
8
+ var _a, _b, _c, _d, _e, _f;
9
+ return ((_c = (_b = (_a = STATE_GETTER_REGEX.exec(code.trim())) == null ? void 0 : _a.groups) == null ? void 0 : _b.getPath) == null ? void 0 : _c.slice(1)) || ((_f = (_e = (_d = VIRTUAL_INDEX_REGEX.exec(code.trim())) == null ? void 0 : _d.groups) == null ? void 0 : _e.getPath) == null ? void 0 : _f.slice(1));
26
10
  };
27
- _EvalCache.cacheLimit = 20;
28
- _EvalCache.cache = /* @__PURE__ */ new Map();
29
- let EvalCache = _EvalCache;
30
- function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true, enableCache }) {
31
- if (code === "") {
11
+ function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true }) {
12
+ if (code.trim() === "") {
32
13
  return void 0;
33
14
  }
15
+ const getPath = getSimpleExpressionGetPath(code.trim());
16
+ if (getPath) {
17
+ return get({
18
+ ...rootState,
19
+ ...localState
20
+ }, getPath);
21
+ }
34
22
  const args = {
35
23
  code: parseCode(code, {
36
24
  isExpression
@@ -42,19 +30,8 @@ function evaluate({ code, context, localState, rootState, rootSetState, event, i
42
30
  rootState,
43
31
  localState
44
32
  };
45
- if (enableCache && !DISABLE_CACHE) {
46
- const cacheKey = EvalCache.getCacheKey(args);
47
- const cachedValue = EvalCache.getCachedValue(cacheKey);
48
- if (cachedValue) {
49
- return cachedValue.value;
50
- }
51
- }
52
33
  try {
53
34
  const newEval = chooseBrowserOrServerEval(args);
54
- if (enableCache) {
55
- const cacheKey = EvalCache.getCacheKey(args);
56
- EvalCache.setCachedValue(cacheKey, newEval);
57
- }
58
35
  return newEval;
59
36
  } catch (e) {
60
37
  logger.error("Failed code evaluation: " + e.message, {
@@ -64,5 +41,6 @@ function evaluate({ code, context, localState, rootState, rootSetState, event, i
64
41
  }
65
42
  }
66
43
  export {
67
- evaluate
44
+ evaluate,
45
+ getSimpleExpressionGetPath
68
46
  };
@@ -9,8 +9,7 @@ function createEventHandler(value, options) {
9
9
  localState: options.localState,
10
10
  rootState: options.rootState,
11
11
  rootSetState: options.rootSetState,
12
- event,
13
- enableCache: true
12
+ event
14
13
  }));
15
14
  }
16
15
  exports.createEventHandler = createEventHandler;
@@ -7,8 +7,7 @@ function createEventHandler(value, options) {
7
7
  localState: options.localState,
8
8
  rootState: options.rootState,
9
9
  rootSetState: options.rootSetState,
10
- event,
11
- enableCache: true
10
+ event
12
11
  }));
13
12
  }
14
13
  export {
@@ -71,8 +71,7 @@ const evaluateBindings = ({ block, context, localState, rootState, rootSetState
71
71
  localState,
72
72
  rootState,
73
73
  rootSetState,
74
- context,
75
- enableCache: true
74
+ context
76
75
  });
77
76
  set.set(copied, binding, value);
78
77
  }
@@ -69,8 +69,7 @@ const evaluateBindings = ({ block, context, localState, rootState, rootSetState
69
69
  localState,
70
70
  rootState,
71
71
  rootSetState,
72
- context,
73
- enableCache: true
72
+ context
74
73
  });
75
74
  set(copied, binding, value);
76
75
  }
@@ -13,8 +13,7 @@ const Text = qwik.component$((props) => {
13
13
  context: contextContext,
14
14
  localState,
15
15
  rootState,
16
- rootSetState,
17
- enableCache: false
16
+ rootSetState
18
17
  }));
19
18
  });
20
19
  return /* @__PURE__ */ jsxRuntime.jsx("div", {
@@ -11,8 +11,7 @@ const Text = component$((props) => {
11
11
  context: contextContext,
12
12
  localState,
13
13
  rootState,
14
- rootSetState,
15
- enableCache: false
14
+ rootSetState
16
15
  }));
17
16
  });
18
17
  return /* @__PURE__ */ jsx("div", {
@@ -27,8 +27,7 @@ const getRepeatItemData = ({ block, context }) => {
27
27
  localState: context.localState,
28
28
  rootState: context.rootState,
29
29
  rootSetState: context.rootSetState,
30
- context: context.context,
31
- enableCache: true
30
+ context: context.context
32
31
  });
33
32
  if (!Array.isArray(itemsArray)) {
34
33
  return void 0;
@@ -25,8 +25,7 @@ const getRepeatItemData = ({ block, context }) => {
25
25
  localState: context.localState,
26
26
  rootState: context.rootState,
27
27
  rootSetState: context.rootSetState,
28
- context: context.context,
29
- enableCache: true
28
+ context: context.context
30
29
  });
31
30
  if (!Array.isArray(itemsArray)) {
32
31
  return void 0;
@@ -109,8 +109,7 @@ const runHttpRequests = function runHttpRequests2(props, state, showContentProps
109
109
  context: props.context || {},
110
110
  localState: void 0,
111
111
  rootState: props.builderContextSignal.rootState,
112
- rootSetState: props.builderContextSignal.rootSetState,
113
- enableCache: true
112
+ rootSetState: props.builderContextSignal.rootSetState
114
113
  })));
115
114
  fetch(evaluatedUrl).then((response) => response.json()).then((json) => {
116
115
  mergeNewRootState(props, state, showContentProps, elementRef, {
@@ -107,8 +107,7 @@ const runHttpRequests = function runHttpRequests2(props, state, showContentProps
107
107
  context: props.context || {},
108
108
  localState: void 0,
109
109
  rootState: props.builderContextSignal.rootState,
110
- rootSetState: props.builderContextSignal.rootSetState,
111
- enableCache: true
110
+ rootSetState: props.builderContextSignal.rootSetState
112
111
  })));
113
112
  fetch(evaluatedUrl).then((response) => response.json()).then((json) => {
114
113
  mergeNewRootState(props, state, showContentProps, elementRef, {
@@ -94,11 +94,7 @@ const ContentComponent = qwik.component$((props) => {
94
94
  var _a3, _b3;
95
95
  (_b3 = (_a3 = state.builderContextSignal).rootSetState) == null ? void 0 : _b3.call(_a3, newState);
96
96
  },
97
- isExpression: false,
98
- /**
99
- * We don't want to cache the result of the JS code, since it's arbitrary side effect code.
100
- */
101
- enableCache: false
97
+ isExpression: false
102
98
  });
103
99
  }
104
100
  });
@@ -92,11 +92,7 @@ const ContentComponent = component$((props) => {
92
92
  var _a3, _b3;
93
93
  (_b3 = (_a3 = state.builderContextSignal).rootSetState) == null ? void 0 : _b3.call(_a3, newState);
94
94
  },
95
- isExpression: false,
96
- /**
97
- * We don't want to cache the result of the JS code, since it's arbitrary side effect code.
98
- */
99
- enableCache: false
95
+ isExpression: false
100
96
  });
101
97
  }
102
98
  });
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const SDK_VERSION = "0.16.15";
3
+ const SDK_VERSION = "0.16.16";
4
4
  exports.SDK_VERSION = SDK_VERSION;
@@ -1,4 +1,4 @@
1
- const SDK_VERSION = "0.16.15";
1
+ const SDK_VERSION = "0.16.16";
2
2
  export {
3
3
  SDK_VERSION
4
4
  };
@@ -1,38 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const logger = require("../../helpers/logger.qwik.cjs");
4
+ const get = require("../get.qwik.cjs");
4
5
  const chooseEval = require("./choose-eval.qwik.cjs");
5
6
  const helpers = require("./helpers.qwik.cjs");
6
- const DISABLE_CACHE = true;
7
- const _EvalCache = class _EvalCache2 {
8
- static getCacheKey(args) {
9
- return JSON.stringify({
10
- ...args,
11
- // replace the event with a random number to break cache
12
- // thats because we can't serialize the event object due to circular refs in DOM node refs.
13
- event: args.event ? Math.random() : void 0
14
- });
15
- }
16
- static getCachedValue(key) {
17
- const cachedVal = _EvalCache2.cache.get(key);
18
- return cachedVal;
19
- }
20
- static setCachedValue(key, value) {
21
- if (_EvalCache2.cache.size > 20) {
22
- _EvalCache2.cache.delete(_EvalCache2.cache.keys().next().value);
23
- }
24
- _EvalCache2.cache.set(key, {
25
- value
26
- });
27
- }
7
+ const STATE_GETTER_REGEX = /^(return )?(\s*)?state(?<getPath>(\.\w+)+)(\s*);?$/;
8
+ const VIRTUAL_INDEX_REGEX = /(\s)*var(\s)+_virtual_index(\s)*=(\s)*state(?<getPath>(\.\w+)+)(\s*);?(\s)*return(\s)*_virtual_index(\s)*/;
9
+ const getSimpleExpressionGetPath = (code) => {
10
+ var _a, _b, _c, _d, _e, _f;
11
+ return ((_c = (_b = (_a = STATE_GETTER_REGEX.exec(code.trim())) == null ? void 0 : _a.groups) == null ? void 0 : _b.getPath) == null ? void 0 : _c.slice(1)) || ((_f = (_e = (_d = VIRTUAL_INDEX_REGEX.exec(code.trim())) == null ? void 0 : _d.groups) == null ? void 0 : _e.getPath) == null ? void 0 : _f.slice(1));
28
12
  };
29
- _EvalCache.cacheLimit = 20;
30
- _EvalCache.cache = /* @__PURE__ */ new Map();
31
- let EvalCache = _EvalCache;
32
- function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true, enableCache }) {
33
- if (code === "") {
13
+ function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true }) {
14
+ if (code.trim() === "") {
34
15
  return void 0;
35
16
  }
17
+ const getPath = getSimpleExpressionGetPath(code.trim());
18
+ if (getPath) {
19
+ return get.get({
20
+ ...rootState,
21
+ ...localState
22
+ }, getPath);
23
+ }
36
24
  const args = {
37
25
  code: helpers.parseCode(code, {
38
26
  isExpression
@@ -44,19 +32,8 @@ function evaluate({ code, context, localState, rootState, rootSetState, event, i
44
32
  rootState,
45
33
  localState
46
34
  };
47
- if (enableCache && !DISABLE_CACHE) {
48
- const cacheKey = EvalCache.getCacheKey(args);
49
- const cachedValue = EvalCache.getCachedValue(cacheKey);
50
- if (cachedValue) {
51
- return cachedValue.value;
52
- }
53
- }
54
35
  try {
55
36
  const newEval = chooseEval.chooseBrowserOrServerEval(args);
56
- if (enableCache) {
57
- const cacheKey = EvalCache.getCacheKey(args);
58
- EvalCache.setCachedValue(cacheKey, newEval);
59
- }
60
37
  return newEval;
61
38
  } catch (e) {
62
39
  logger.logger.error("Failed code evaluation: " + e.message, {
@@ -66,3 +43,4 @@ function evaluate({ code, context, localState, rootState, rootSetState, event, i
66
43
  }
67
44
  }
68
45
  exports.evaluate = evaluate;
46
+ exports.getSimpleExpressionGetPath = getSimpleExpressionGetPath;
@@ -1,36 +1,24 @@
1
1
  import { logger } from "../../helpers/logger.qwik.mjs";
2
+ import { get } from "../get.qwik.mjs";
2
3
  import { chooseBrowserOrServerEval } from "./choose-eval.qwik.mjs";
3
4
  import { parseCode, getBuilderGlobals } from "./helpers.qwik.mjs";
4
- const DISABLE_CACHE = true;
5
- const _EvalCache = class _EvalCache2 {
6
- static getCacheKey(args) {
7
- return JSON.stringify({
8
- ...args,
9
- // replace the event with a random number to break cache
10
- // thats because we can't serialize the event object due to circular refs in DOM node refs.
11
- event: args.event ? Math.random() : void 0
12
- });
13
- }
14
- static getCachedValue(key) {
15
- const cachedVal = _EvalCache2.cache.get(key);
16
- return cachedVal;
17
- }
18
- static setCachedValue(key, value) {
19
- if (_EvalCache2.cache.size > 20) {
20
- _EvalCache2.cache.delete(_EvalCache2.cache.keys().next().value);
21
- }
22
- _EvalCache2.cache.set(key, {
23
- value
24
- });
25
- }
5
+ const STATE_GETTER_REGEX = /^(return )?(\s*)?state(?<getPath>(\.\w+)+)(\s*);?$/;
6
+ const VIRTUAL_INDEX_REGEX = /(\s)*var(\s)+_virtual_index(\s)*=(\s)*state(?<getPath>(\.\w+)+)(\s*);?(\s)*return(\s)*_virtual_index(\s)*/;
7
+ const getSimpleExpressionGetPath = (code) => {
8
+ var _a, _b, _c, _d, _e, _f;
9
+ return ((_c = (_b = (_a = STATE_GETTER_REGEX.exec(code.trim())) == null ? void 0 : _a.groups) == null ? void 0 : _b.getPath) == null ? void 0 : _c.slice(1)) || ((_f = (_e = (_d = VIRTUAL_INDEX_REGEX.exec(code.trim())) == null ? void 0 : _d.groups) == null ? void 0 : _e.getPath) == null ? void 0 : _f.slice(1));
26
10
  };
27
- _EvalCache.cacheLimit = 20;
28
- _EvalCache.cache = /* @__PURE__ */ new Map();
29
- let EvalCache = _EvalCache;
30
- function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true, enableCache }) {
31
- if (code === "") {
11
+ function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true }) {
12
+ if (code.trim() === "") {
32
13
  return void 0;
33
14
  }
15
+ const getPath = getSimpleExpressionGetPath(code.trim());
16
+ if (getPath) {
17
+ return get({
18
+ ...rootState,
19
+ ...localState
20
+ }, getPath);
21
+ }
34
22
  const args = {
35
23
  code: parseCode(code, {
36
24
  isExpression
@@ -42,19 +30,8 @@ function evaluate({ code, context, localState, rootState, rootSetState, event, i
42
30
  rootState,
43
31
  localState
44
32
  };
45
- if (enableCache && !DISABLE_CACHE) {
46
- const cacheKey = EvalCache.getCacheKey(args);
47
- const cachedValue = EvalCache.getCachedValue(cacheKey);
48
- if (cachedValue) {
49
- return cachedValue.value;
50
- }
51
- }
52
33
  try {
53
34
  const newEval = chooseBrowserOrServerEval(args);
54
- if (enableCache) {
55
- const cacheKey = EvalCache.getCacheKey(args);
56
- EvalCache.setCachedValue(cacheKey, newEval);
57
- }
58
35
  return newEval;
59
36
  } catch (e) {
60
37
  logger.error("Failed code evaluation: " + e.message, {
@@ -64,5 +41,6 @@ function evaluate({ code, context, localState, rootState, rootSetState, event, i
64
41
  }
65
42
  }
66
43
  export {
67
- evaluate
44
+ evaluate,
45
+ getSimpleExpressionGetPath
68
46
  };
@@ -9,8 +9,7 @@ function createEventHandler(value, options) {
9
9
  localState: options.localState,
10
10
  rootState: options.rootState,
11
11
  rootSetState: options.rootSetState,
12
- event,
13
- enableCache: true
12
+ event
14
13
  }));
15
14
  }
16
15
  exports.createEventHandler = createEventHandler;
@@ -7,8 +7,7 @@ function createEventHandler(value, options) {
7
7
  localState: options.localState,
8
8
  rootState: options.rootState,
9
9
  rootSetState: options.rootSetState,
10
- event,
11
- enableCache: true
10
+ event
12
11
  }));
13
12
  }
14
13
  export {
@@ -71,8 +71,7 @@ const evaluateBindings = ({ block, context, localState, rootState, rootSetState
71
71
  localState,
72
72
  rootState,
73
73
  rootSetState,
74
- context,
75
- enableCache: true
74
+ context
76
75
  });
77
76
  set.set(copied, binding, value);
78
77
  }
@@ -69,8 +69,7 @@ const evaluateBindings = ({ block, context, localState, rootState, rootSetState
69
69
  localState,
70
70
  rootState,
71
71
  rootSetState,
72
- context,
73
- enableCache: true
72
+ context
74
73
  });
75
74
  set(copied, binding, value);
76
75
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-qwik",
3
- "version": "0.16.15",
3
+ "version": "0.16.16",
4
4
  "homepage": "https://github.com/BuilderIO/builder/tree/main/packages/sdks/output/qwik",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.16.15";
1
+ export declare const SDK_VERSION = "0.16.16";
@@ -1,4 +1,5 @@
1
1
  import type { EvaluatorArgs } from './helpers';
2
2
  type EvalValue = unknown;
3
- export declare function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression, enableCache }: EvaluatorArgs): EvalValue;
3
+ export declare const getSimpleExpressionGetPath: (code: string) => string | undefined;
4
+ export declare function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression }: EvaluatorArgs): EvalValue;
4
5
  export {};
@@ -3,7 +3,6 @@ import { getUserAttributes } from '../track/helpers';
3
3
  export type EvaluatorArgs = Omit<ExecutorArgs, 'builder' | 'event'> & {
4
4
  event?: Event;
5
5
  isExpression?: boolean;
6
- enableCache: boolean;
7
6
  };
8
7
  export type BuilderGlobals = {
9
8
  isEditing: boolean | undefined;