@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.
- package/lib/browser/blocks/text/text.qwik.cjs +1 -2
- package/lib/browser/blocks/text/text.qwik.mjs +1 -2
- package/lib/browser/components/block/block.helpers.qwik.cjs +1 -2
- package/lib/browser/components/block/block.helpers.qwik.mjs +1 -2
- package/lib/browser/components/content/components/enable-editor.qwik.cjs +1 -2
- package/lib/browser/components/content/components/enable-editor.qwik.mjs +1 -2
- package/lib/browser/components/content/content.qwik.cjs +1 -5
- package/lib/browser/components/content/content.qwik.mjs +1 -5
- package/lib/browser/constants/sdk-version.qwik.cjs +1 -1
- package/lib/browser/constants/sdk-version.qwik.mjs +1 -1
- package/lib/browser/functions/evaluate/evaluate.qwik.cjs +16 -38
- package/lib/browser/functions/evaluate/evaluate.qwik.mjs +17 -39
- package/lib/browser/functions/get-block-actions-handler.qwik.cjs +1 -2
- package/lib/browser/functions/get-block-actions-handler.qwik.mjs +1 -2
- package/lib/browser/functions/get-processed-block.qwik.cjs +1 -2
- package/lib/browser/functions/get-processed-block.qwik.mjs +1 -2
- package/lib/edge/blocks/text/text.qwik.cjs +1 -2
- package/lib/edge/blocks/text/text.qwik.mjs +1 -2
- package/lib/edge/components/block/block.helpers.qwik.cjs +1 -2
- package/lib/edge/components/block/block.helpers.qwik.mjs +1 -2
- package/lib/edge/components/content/components/enable-editor.qwik.cjs +1 -2
- package/lib/edge/components/content/components/enable-editor.qwik.mjs +1 -2
- package/lib/edge/components/content/content.qwik.cjs +1 -5
- package/lib/edge/components/content/content.qwik.mjs +1 -5
- package/lib/edge/constants/sdk-version.qwik.cjs +1 -1
- package/lib/edge/constants/sdk-version.qwik.mjs +1 -1
- package/lib/edge/functions/evaluate/evaluate.qwik.cjs +16 -38
- package/lib/edge/functions/evaluate/evaluate.qwik.mjs +17 -39
- package/lib/edge/functions/get-block-actions-handler.qwik.cjs +1 -2
- package/lib/edge/functions/get-block-actions-handler.qwik.mjs +1 -2
- package/lib/edge/functions/get-processed-block.qwik.cjs +1 -2
- package/lib/edge/functions/get-processed-block.qwik.mjs +1 -2
- package/lib/node/blocks/text/text.qwik.cjs +1 -2
- package/lib/node/blocks/text/text.qwik.mjs +1 -2
- package/lib/node/components/block/block.helpers.qwik.cjs +1 -2
- package/lib/node/components/block/block.helpers.qwik.mjs +1 -2
- package/lib/node/components/content/components/enable-editor.qwik.cjs +1 -2
- package/lib/node/components/content/components/enable-editor.qwik.mjs +1 -2
- package/lib/node/components/content/content.qwik.cjs +1 -5
- package/lib/node/components/content/content.qwik.mjs +1 -5
- package/lib/node/constants/sdk-version.qwik.cjs +1 -1
- package/lib/node/constants/sdk-version.qwik.mjs +1 -1
- package/lib/node/functions/evaluate/evaluate.qwik.cjs +16 -38
- package/lib/node/functions/evaluate/evaluate.qwik.mjs +17 -39
- package/lib/node/functions/get-block-actions-handler.qwik.cjs +1 -2
- package/lib/node/functions/get-block-actions-handler.qwik.mjs +1 -2
- package/lib/node/functions/get-processed-block.qwik.cjs +1 -2
- package/lib/node/functions/get-processed-block.qwik.mjs +1 -2
- package/package.json +1 -1
- package/types/src/constants/sdk-version.d.ts +1 -1
- package/types/src/functions/evaluate/evaluate.d.ts +2 -1
- package/types/src/functions/evaluate/helpers.d.ts +0 -1
|
@@ -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,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
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
30
|
-
|
|
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
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
28
|
-
|
|
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
|
};
|
|
@@ -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,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
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
30
|
-
|
|
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
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
28
|
-
|
|
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
|
};
|
|
@@ -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,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
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
30
|
-
|
|
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
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
28
|
-
|
|
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
|
};
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.16.
|
|
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
|
|
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 {};
|