@builder.io/sdk-qwik 0.7.1-3 → 0.7.1-5
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/index.qwik.cjs +42 -16
- package/lib/browser/index.qwik.mjs +42 -16
- package/lib/edge/index.qwik.cjs +79 -26
- package/lib/edge/index.qwik.mjs +79 -26
- package/lib/index.qwik.js +7609 -0
- package/lib/node/index.qwik.cjs +151 -24
- package/lib/node/index.qwik.mjs +151 -24
- package/lib/node/node-evaluate-15fe5e77.js +10 -0
- package/lib/node/node-evaluate-fc9f27d1.cjs +8 -0
- package/package.json +2 -1
- package/types/src/constants/sdk-version.d.ts +1 -1
- package/types/src/functions/evaluate/choose-eval.d.ts +6 -0
- package/types/src/functions/evaluate/evaluate.d.ts +1 -5
- package/types/src/functions/evaluate/helpers.d.ts +7 -1
- package/types/src/functions/evaluate/node-runtime/index.d.ts +1 -1
- package/types/src/functions/evaluate/node-runtime/node-runtime.d.ts +1 -1
- package/types/src/functions/evaluate/node-runtime/safeDynamicRequire.d.ts +7 -0
- package/types/src/functions/get-content/types.d.ts +94 -3
- package/types/src/functions/is-node-runtime.d.ts +4 -0
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const qwik = require("@builder.io/qwik");
|
|
4
4
|
const jsxRuntime = require("@builder.io/qwik/jsx-runtime");
|
|
5
|
+
const build = require("@builder.io/qwik/build");
|
|
5
6
|
const Button = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlinedQrl((props) => {
|
|
6
7
|
qwik.useStylesScopedQrl(/* @__PURE__ */ qwik.inlinedQrl(STYLES$3, "Button_component_useStylesScoped_a1JZ0Q0Q2Oc"));
|
|
7
8
|
return /* @__PURE__ */ qwik._jsxC(jsxRuntime.Fragment, {
|
|
@@ -120,6 +121,20 @@ const getFunctionArguments = ({ builder, context, event, state }) => {
|
|
|
120
121
|
event
|
|
121
122
|
});
|
|
122
123
|
};
|
|
124
|
+
const getBuilderGlobals = () => ({
|
|
125
|
+
isEditing: isEditing(),
|
|
126
|
+
isBrowser: isBrowser(),
|
|
127
|
+
isServer: !isBrowser(),
|
|
128
|
+
getUserAttributes: () => getUserAttributes()
|
|
129
|
+
});
|
|
130
|
+
const parseCode = (code, { isExpression = true }) => {
|
|
131
|
+
const useReturn = (
|
|
132
|
+
// we disable this for cases where we definitely don't want a return
|
|
133
|
+
isExpression && !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "))
|
|
134
|
+
);
|
|
135
|
+
const useCode = useReturn ? `return (${code});` : code;
|
|
136
|
+
return useCode;
|
|
137
|
+
};
|
|
123
138
|
const runInBrowser = ({ code, builder, context, event, localState, rootSetState, rootState }) => {
|
|
124
139
|
const functionArgs = getFunctionArguments({
|
|
125
140
|
builder,
|
|
@@ -147,25 +162,17 @@ function flattenState(rootState, localState, rootSetState) {
|
|
|
147
162
|
}
|
|
148
163
|
});
|
|
149
164
|
}
|
|
165
|
+
const chooseBrowserOrServerEval = (args) => !build.isServer ? runInBrowser(args) : runInBrowser(args);
|
|
150
166
|
function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true }) {
|
|
151
167
|
if (code === "") {
|
|
152
168
|
logger.warn("Skipping evaluation of empty code block.");
|
|
153
169
|
return;
|
|
154
170
|
}
|
|
155
|
-
const builder = {
|
|
156
|
-
isEditing: isEditing(),
|
|
157
|
-
isBrowser: isBrowser(),
|
|
158
|
-
isServer: !isBrowser(),
|
|
159
|
-
getUserAttributes: () => getUserAttributes()
|
|
160
|
-
};
|
|
161
|
-
const useReturn = (
|
|
162
|
-
// we disable this for cases where we definitely don't want a return
|
|
163
|
-
isExpression && !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "))
|
|
164
|
-
);
|
|
165
|
-
const useCode = useReturn ? `return (${code});` : code;
|
|
166
171
|
const args = {
|
|
167
|
-
code:
|
|
168
|
-
|
|
172
|
+
code: parseCode(code, {
|
|
173
|
+
isExpression
|
|
174
|
+
}),
|
|
175
|
+
builder: getBuilderGlobals(),
|
|
169
176
|
context,
|
|
170
177
|
event,
|
|
171
178
|
rootSetState,
|
|
@@ -173,7 +180,7 @@ function evaluate({ code, context, localState, rootState, rootSetState, event, i
|
|
|
173
180
|
localState
|
|
174
181
|
};
|
|
175
182
|
try {
|
|
176
|
-
return
|
|
183
|
+
return chooseBrowserOrServerEval(args);
|
|
177
184
|
} catch (e) {
|
|
178
185
|
logger.error("Failed code evaluation: " + e.message, {
|
|
179
186
|
code
|
|
@@ -2809,9 +2816,10 @@ const getBuilderSearchParamsFromWindow = () => {
|
|
|
2809
2816
|
};
|
|
2810
2817
|
const normalizeSearchParams = (searchParams) => searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams;
|
|
2811
2818
|
const DEFAULT_API_VERSION = "v3";
|
|
2819
|
+
const isPositiveNumber = (thing) => typeof thing === "number" && !isNaN(thing) && thing >= 0;
|
|
2812
2820
|
const generateContentUrl = (options) => {
|
|
2813
2821
|
let { noTraverse = false } = options;
|
|
2814
|
-
const { limit = 30, userAttributes, query, model, apiKey, includeRefs = true, enrich, locale, apiVersion = DEFAULT_API_VERSION } = options;
|
|
2822
|
+
const { limit = 30, userAttributes, query, model, apiKey, includeRefs = true, enrich, locale, apiVersion = DEFAULT_API_VERSION, fields, omit, offset, cacheSeconds, staleCacheSeconds, sort, includeUnpublished } = options;
|
|
2815
2823
|
if (!apiKey)
|
|
2816
2824
|
throw new Error("Missing API key");
|
|
2817
2825
|
if (![
|
|
@@ -2822,6 +2830,24 @@ const generateContentUrl = (options) => {
|
|
|
2822
2830
|
if ((options.limit === void 0 || options.limit > 1) && !("noTraverse" in options))
|
|
2823
2831
|
noTraverse = true;
|
|
2824
2832
|
const url = new URL(`https://cdn.builder.io/api/${apiVersion}/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}${locale ? `&locale=${locale}` : ""}${enrich ? `&enrich=${enrich}` : ""}`);
|
|
2833
|
+
url.searchParams.set("omit", omit || "meta.componentsUsed");
|
|
2834
|
+
if (fields)
|
|
2835
|
+
url.searchParams.set("fields", fields);
|
|
2836
|
+
if (Number.isFinite(offset) && offset > -1)
|
|
2837
|
+
url.searchParams.set("offset", String(Math.floor(offset)));
|
|
2838
|
+
if (typeof includeUnpublished === "boolean")
|
|
2839
|
+
url.searchParams.set("includeUnpublished", String(includeUnpublished));
|
|
2840
|
+
if (cacheSeconds && isPositiveNumber(cacheSeconds))
|
|
2841
|
+
url.searchParams.set("cacheSeconds", String(cacheSeconds));
|
|
2842
|
+
if (staleCacheSeconds && isPositiveNumber(staleCacheSeconds))
|
|
2843
|
+
url.searchParams.set("staleCacheSeconds", String(staleCacheSeconds));
|
|
2844
|
+
if (sort) {
|
|
2845
|
+
const flattened2 = flatten({
|
|
2846
|
+
sort
|
|
2847
|
+
});
|
|
2848
|
+
for (const key in flattened2)
|
|
2849
|
+
url.searchParams.set(key, JSON.stringify(flattened2[key]));
|
|
2850
|
+
}
|
|
2825
2851
|
const queryOptions = {
|
|
2826
2852
|
...getBuilderSearchParamsFromWindow(),
|
|
2827
2853
|
...normalizeSearchParams(options.options || {})
|
|
@@ -3095,7 +3121,7 @@ const getInteractionPropertiesForEvent = (event) => {
|
|
|
3095
3121
|
}
|
|
3096
3122
|
};
|
|
3097
3123
|
};
|
|
3098
|
-
const SDK_VERSION = "0.7.1-
|
|
3124
|
+
const SDK_VERSION = "0.7.1-4";
|
|
3099
3125
|
const registry = {};
|
|
3100
3126
|
function register(type, info) {
|
|
3101
3127
|
let typeList = registry[type];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { componentQrl, inlinedQrl, useStylesScopedQrl, _jsxC, _jsxS, _fnSignal, createContextId, _jsxQ, _jsxBranch, useComputedQrl, useLexicalScope, _IMMUTABLE, Slot, useStore, useContextProvider, _wrapProp, useContext, createElement, Fragment as Fragment$1, useSignal, useTaskQrl, useOn } from "@builder.io/qwik";
|
|
2
2
|
import { Fragment } from "@builder.io/qwik/jsx-runtime";
|
|
3
|
+
import { isServer } from "@builder.io/qwik/build";
|
|
3
4
|
const Button = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((props) => {
|
|
4
5
|
useStylesScopedQrl(/* @__PURE__ */ inlinedQrl(STYLES$3, "Button_component_useStylesScoped_a1JZ0Q0Q2Oc"));
|
|
5
6
|
return /* @__PURE__ */ _jsxC(Fragment, {
|
|
@@ -118,6 +119,20 @@ const getFunctionArguments = ({ builder, context, event, state }) => {
|
|
|
118
119
|
event
|
|
119
120
|
});
|
|
120
121
|
};
|
|
122
|
+
const getBuilderGlobals = () => ({
|
|
123
|
+
isEditing: isEditing(),
|
|
124
|
+
isBrowser: isBrowser(),
|
|
125
|
+
isServer: !isBrowser(),
|
|
126
|
+
getUserAttributes: () => getUserAttributes()
|
|
127
|
+
});
|
|
128
|
+
const parseCode = (code, { isExpression = true }) => {
|
|
129
|
+
const useReturn = (
|
|
130
|
+
// we disable this for cases where we definitely don't want a return
|
|
131
|
+
isExpression && !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "))
|
|
132
|
+
);
|
|
133
|
+
const useCode = useReturn ? `return (${code});` : code;
|
|
134
|
+
return useCode;
|
|
135
|
+
};
|
|
121
136
|
const runInBrowser = ({ code, builder, context, event, localState, rootSetState, rootState }) => {
|
|
122
137
|
const functionArgs = getFunctionArguments({
|
|
123
138
|
builder,
|
|
@@ -145,25 +160,17 @@ function flattenState(rootState, localState, rootSetState) {
|
|
|
145
160
|
}
|
|
146
161
|
});
|
|
147
162
|
}
|
|
163
|
+
const chooseBrowserOrServerEval = (args) => !isServer ? runInBrowser(args) : runInBrowser(args);
|
|
148
164
|
function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true }) {
|
|
149
165
|
if (code === "") {
|
|
150
166
|
logger.warn("Skipping evaluation of empty code block.");
|
|
151
167
|
return;
|
|
152
168
|
}
|
|
153
|
-
const builder = {
|
|
154
|
-
isEditing: isEditing(),
|
|
155
|
-
isBrowser: isBrowser(),
|
|
156
|
-
isServer: !isBrowser(),
|
|
157
|
-
getUserAttributes: () => getUserAttributes()
|
|
158
|
-
};
|
|
159
|
-
const useReturn = (
|
|
160
|
-
// we disable this for cases where we definitely don't want a return
|
|
161
|
-
isExpression && !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "))
|
|
162
|
-
);
|
|
163
|
-
const useCode = useReturn ? `return (${code});` : code;
|
|
164
169
|
const args = {
|
|
165
|
-
code:
|
|
166
|
-
|
|
170
|
+
code: parseCode(code, {
|
|
171
|
+
isExpression
|
|
172
|
+
}),
|
|
173
|
+
builder: getBuilderGlobals(),
|
|
167
174
|
context,
|
|
168
175
|
event,
|
|
169
176
|
rootSetState,
|
|
@@ -171,7 +178,7 @@ function evaluate({ code, context, localState, rootState, rootSetState, event, i
|
|
|
171
178
|
localState
|
|
172
179
|
};
|
|
173
180
|
try {
|
|
174
|
-
return
|
|
181
|
+
return chooseBrowserOrServerEval(args);
|
|
175
182
|
} catch (e) {
|
|
176
183
|
logger.error("Failed code evaluation: " + e.message, {
|
|
177
184
|
code
|
|
@@ -2807,9 +2814,10 @@ const getBuilderSearchParamsFromWindow = () => {
|
|
|
2807
2814
|
};
|
|
2808
2815
|
const normalizeSearchParams = (searchParams) => searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams;
|
|
2809
2816
|
const DEFAULT_API_VERSION = "v3";
|
|
2817
|
+
const isPositiveNumber = (thing) => typeof thing === "number" && !isNaN(thing) && thing >= 0;
|
|
2810
2818
|
const generateContentUrl = (options) => {
|
|
2811
2819
|
let { noTraverse = false } = options;
|
|
2812
|
-
const { limit = 30, userAttributes, query, model, apiKey, includeRefs = true, enrich, locale, apiVersion = DEFAULT_API_VERSION } = options;
|
|
2820
|
+
const { limit = 30, userAttributes, query, model, apiKey, includeRefs = true, enrich, locale, apiVersion = DEFAULT_API_VERSION, fields, omit, offset, cacheSeconds, staleCacheSeconds, sort, includeUnpublished } = options;
|
|
2813
2821
|
if (!apiKey)
|
|
2814
2822
|
throw new Error("Missing API key");
|
|
2815
2823
|
if (![
|
|
@@ -2820,6 +2828,24 @@ const generateContentUrl = (options) => {
|
|
|
2820
2828
|
if ((options.limit === void 0 || options.limit > 1) && !("noTraverse" in options))
|
|
2821
2829
|
noTraverse = true;
|
|
2822
2830
|
const url = new URL(`https://cdn.builder.io/api/${apiVersion}/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}${locale ? `&locale=${locale}` : ""}${enrich ? `&enrich=${enrich}` : ""}`);
|
|
2831
|
+
url.searchParams.set("omit", omit || "meta.componentsUsed");
|
|
2832
|
+
if (fields)
|
|
2833
|
+
url.searchParams.set("fields", fields);
|
|
2834
|
+
if (Number.isFinite(offset) && offset > -1)
|
|
2835
|
+
url.searchParams.set("offset", String(Math.floor(offset)));
|
|
2836
|
+
if (typeof includeUnpublished === "boolean")
|
|
2837
|
+
url.searchParams.set("includeUnpublished", String(includeUnpublished));
|
|
2838
|
+
if (cacheSeconds && isPositiveNumber(cacheSeconds))
|
|
2839
|
+
url.searchParams.set("cacheSeconds", String(cacheSeconds));
|
|
2840
|
+
if (staleCacheSeconds && isPositiveNumber(staleCacheSeconds))
|
|
2841
|
+
url.searchParams.set("staleCacheSeconds", String(staleCacheSeconds));
|
|
2842
|
+
if (sort) {
|
|
2843
|
+
const flattened2 = flatten({
|
|
2844
|
+
sort
|
|
2845
|
+
});
|
|
2846
|
+
for (const key in flattened2)
|
|
2847
|
+
url.searchParams.set(key, JSON.stringify(flattened2[key]));
|
|
2848
|
+
}
|
|
2823
2849
|
const queryOptions = {
|
|
2824
2850
|
...getBuilderSearchParamsFromWindow(),
|
|
2825
2851
|
...normalizeSearchParams(options.options || {})
|
|
@@ -3093,7 +3119,7 @@ const getInteractionPropertiesForEvent = (event) => {
|
|
|
3093
3119
|
}
|
|
3094
3120
|
};
|
|
3095
3121
|
};
|
|
3096
|
-
const SDK_VERSION = "0.7.1-
|
|
3122
|
+
const SDK_VERSION = "0.7.1-4";
|
|
3097
3123
|
const registry = {};
|
|
3098
3124
|
function register(type, info) {
|
|
3099
3125
|
let typeList = registry[type];
|
package/lib/edge/index.qwik.cjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const qwik = require("@builder.io/qwik");
|
|
4
4
|
const jsxRuntime = require("@builder.io/qwik/jsx-runtime");
|
|
5
|
+
const build = require("@builder.io/qwik/build");
|
|
5
6
|
const Button = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlinedQrl((props) => {
|
|
6
7
|
qwik.useStylesScopedQrl(/* @__PURE__ */ qwik.inlinedQrl(STYLES$3, "Button_component_useStylesScoped_a1JZ0Q0Q2Oc"));
|
|
7
8
|
return /* @__PURE__ */ qwik._jsxC(jsxRuntime.Fragment, {
|
|
@@ -110,6 +111,30 @@ const getUserAttributes = () => {
|
|
|
110
111
|
device: isTablet ? "tablet" : isMobile.any() ? "mobile" : "desktop"
|
|
111
112
|
};
|
|
112
113
|
};
|
|
114
|
+
const getFunctionArguments = ({ builder, context, event, state }) => {
|
|
115
|
+
return Object.entries({
|
|
116
|
+
state,
|
|
117
|
+
Builder: builder,
|
|
118
|
+
// legacy
|
|
119
|
+
builder,
|
|
120
|
+
context,
|
|
121
|
+
event
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
const getBuilderGlobals = () => ({
|
|
125
|
+
isEditing: isEditing(),
|
|
126
|
+
isBrowser: isBrowser(),
|
|
127
|
+
isServer: !isBrowser(),
|
|
128
|
+
getUserAttributes: () => getUserAttributes()
|
|
129
|
+
});
|
|
130
|
+
const parseCode = (code, { isExpression = true }) => {
|
|
131
|
+
const useReturn = (
|
|
132
|
+
// we disable this for cases where we definitely don't want a return
|
|
133
|
+
isExpression && !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "))
|
|
134
|
+
);
|
|
135
|
+
const useCode = useReturn ? `return (${code});` : code;
|
|
136
|
+
return useCode;
|
|
137
|
+
};
|
|
113
138
|
const set = (obj, _path, value) => {
|
|
114
139
|
if (Object(obj) !== obj)
|
|
115
140
|
return obj;
|
|
@@ -3279,16 +3304,6 @@ t.prototype.getGlobalScope = t.prototype.Xb;
|
|
|
3279
3304
|
t.prototype.getStateStack = t.prototype.Yb;
|
|
3280
3305
|
t.prototype.setStateStack = t.prototype.ec;
|
|
3281
3306
|
t.VALUE_IN_DESCRIPTOR = Ia;
|
|
3282
|
-
const getFunctionArguments = ({ builder, context, event, state }) => {
|
|
3283
|
-
return Object.entries({
|
|
3284
|
-
state,
|
|
3285
|
-
Builder: builder,
|
|
3286
|
-
// legacy
|
|
3287
|
-
builder,
|
|
3288
|
-
context,
|
|
3289
|
-
event
|
|
3290
|
-
});
|
|
3291
|
-
};
|
|
3292
3307
|
const processCode = (code) => {
|
|
3293
3308
|
return code.split("\n").map((line) => {
|
|
3294
3309
|
const trimmed = line.trim();
|
|
@@ -3358,25 +3373,44 @@ theFunction();
|
|
|
3358
3373
|
return;
|
|
3359
3374
|
}
|
|
3360
3375
|
};
|
|
3376
|
+
const runInBrowser = ({ code, builder, context, event, localState, rootSetState, rootState }) => {
|
|
3377
|
+
const functionArgs = getFunctionArguments({
|
|
3378
|
+
builder,
|
|
3379
|
+
context,
|
|
3380
|
+
event,
|
|
3381
|
+
state: flattenState(rootState, localState, rootSetState)
|
|
3382
|
+
});
|
|
3383
|
+
return new Function(...functionArgs.map(([name]) => name), code)(...functionArgs.map(([, value]) => value));
|
|
3384
|
+
};
|
|
3385
|
+
function flattenState(rootState, localState, rootSetState) {
|
|
3386
|
+
if (rootState === localState)
|
|
3387
|
+
throw new Error("rootState === localState");
|
|
3388
|
+
return new Proxy(rootState, {
|
|
3389
|
+
get: (_, prop) => {
|
|
3390
|
+
if (localState && prop in localState)
|
|
3391
|
+
return localState[prop];
|
|
3392
|
+
return rootState[prop];
|
|
3393
|
+
},
|
|
3394
|
+
set: (_, prop, value) => {
|
|
3395
|
+
if (localState && prop in localState)
|
|
3396
|
+
throw new Error("Writing to local state is not allowed as it is read-only.");
|
|
3397
|
+
rootState[prop] = value;
|
|
3398
|
+
rootSetState == null ? void 0 : rootSetState(rootState);
|
|
3399
|
+
return true;
|
|
3400
|
+
}
|
|
3401
|
+
});
|
|
3402
|
+
}
|
|
3403
|
+
const chooseBrowserOrServerEval = (args) => !build.isServer ? runInBrowser(args) : runInEdge(args);
|
|
3361
3404
|
function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true }) {
|
|
3362
3405
|
if (code === "") {
|
|
3363
3406
|
logger.warn("Skipping evaluation of empty code block.");
|
|
3364
3407
|
return;
|
|
3365
3408
|
}
|
|
3366
|
-
const builder = {
|
|
3367
|
-
isEditing: isEditing(),
|
|
3368
|
-
isBrowser: isBrowser(),
|
|
3369
|
-
isServer: !isBrowser(),
|
|
3370
|
-
getUserAttributes: () => getUserAttributes()
|
|
3371
|
-
};
|
|
3372
|
-
const useReturn = (
|
|
3373
|
-
// we disable this for cases where we definitely don't want a return
|
|
3374
|
-
isExpression && !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "))
|
|
3375
|
-
);
|
|
3376
|
-
const useCode = useReturn ? `return (${code});` : code;
|
|
3377
3409
|
const args = {
|
|
3378
|
-
code:
|
|
3379
|
-
|
|
3410
|
+
code: parseCode(code, {
|
|
3411
|
+
isExpression
|
|
3412
|
+
}),
|
|
3413
|
+
builder: getBuilderGlobals(),
|
|
3380
3414
|
context,
|
|
3381
3415
|
event,
|
|
3382
3416
|
rootSetState,
|
|
@@ -3384,7 +3418,7 @@ function evaluate({ code, context, localState, rootState, rootSetState, event, i
|
|
|
3384
3418
|
localState
|
|
3385
3419
|
};
|
|
3386
3420
|
try {
|
|
3387
|
-
return
|
|
3421
|
+
return chooseBrowserOrServerEval(args);
|
|
3388
3422
|
} catch (e) {
|
|
3389
3423
|
logger.error("Failed code evaluation: " + e.message, {
|
|
3390
3424
|
code
|
|
@@ -6013,9 +6047,10 @@ const getBuilderSearchParamsFromWindow = () => {
|
|
|
6013
6047
|
};
|
|
6014
6048
|
const normalizeSearchParams = (searchParams) => searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams;
|
|
6015
6049
|
const DEFAULT_API_VERSION = "v3";
|
|
6050
|
+
const isPositiveNumber = (thing) => typeof thing === "number" && !isNaN(thing) && thing >= 0;
|
|
6016
6051
|
const generateContentUrl = (options) => {
|
|
6017
6052
|
let { noTraverse = false } = options;
|
|
6018
|
-
const { limit = 30, userAttributes, query, model, apiKey, includeRefs = true, enrich, locale, apiVersion = DEFAULT_API_VERSION } = options;
|
|
6053
|
+
const { limit = 30, userAttributes, query, model, apiKey, includeRefs = true, enrich, locale, apiVersion = DEFAULT_API_VERSION, fields, omit, offset, cacheSeconds, staleCacheSeconds, sort, includeUnpublished } = options;
|
|
6019
6054
|
if (!apiKey)
|
|
6020
6055
|
throw new Error("Missing API key");
|
|
6021
6056
|
if (![
|
|
@@ -6026,6 +6061,24 @@ const generateContentUrl = (options) => {
|
|
|
6026
6061
|
if ((options.limit === void 0 || options.limit > 1) && !("noTraverse" in options))
|
|
6027
6062
|
noTraverse = true;
|
|
6028
6063
|
const url = new URL(`https://cdn.builder.io/api/${apiVersion}/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}${locale ? `&locale=${locale}` : ""}${enrich ? `&enrich=${enrich}` : ""}`);
|
|
6064
|
+
url.searchParams.set("omit", omit || "meta.componentsUsed");
|
|
6065
|
+
if (fields)
|
|
6066
|
+
url.searchParams.set("fields", fields);
|
|
6067
|
+
if (Number.isFinite(offset) && offset > -1)
|
|
6068
|
+
url.searchParams.set("offset", String(Math.floor(offset)));
|
|
6069
|
+
if (typeof includeUnpublished === "boolean")
|
|
6070
|
+
url.searchParams.set("includeUnpublished", String(includeUnpublished));
|
|
6071
|
+
if (cacheSeconds && isPositiveNumber(cacheSeconds))
|
|
6072
|
+
url.searchParams.set("cacheSeconds", String(cacheSeconds));
|
|
6073
|
+
if (staleCacheSeconds && isPositiveNumber(staleCacheSeconds))
|
|
6074
|
+
url.searchParams.set("staleCacheSeconds", String(staleCacheSeconds));
|
|
6075
|
+
if (sort) {
|
|
6076
|
+
const flattened2 = flatten({
|
|
6077
|
+
sort
|
|
6078
|
+
});
|
|
6079
|
+
for (const key in flattened2)
|
|
6080
|
+
url.searchParams.set(key, JSON.stringify(flattened2[key]));
|
|
6081
|
+
}
|
|
6029
6082
|
const queryOptions = {
|
|
6030
6083
|
...getBuilderSearchParamsFromWindow(),
|
|
6031
6084
|
...normalizeSearchParams(options.options || {})
|
|
@@ -6299,7 +6352,7 @@ const getInteractionPropertiesForEvent = (event) => {
|
|
|
6299
6352
|
}
|
|
6300
6353
|
};
|
|
6301
6354
|
};
|
|
6302
|
-
const SDK_VERSION = "0.7.1-
|
|
6355
|
+
const SDK_VERSION = "0.7.1-4";
|
|
6303
6356
|
const registry = {};
|
|
6304
6357
|
function register(type, info) {
|
|
6305
6358
|
let typeList = registry[type];
|
package/lib/edge/index.qwik.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { componentQrl, inlinedQrl, useStylesScopedQrl, _jsxC, _jsxS, _fnSignal, createContextId, _jsxQ, _jsxBranch, useComputedQrl, useLexicalScope, _IMMUTABLE, Slot, useStore, useContextProvider, _wrapProp, useContext, createElement, Fragment as Fragment$1, useSignal, useTaskQrl, useOn } from "@builder.io/qwik";
|
|
2
2
|
import { Fragment } from "@builder.io/qwik/jsx-runtime";
|
|
3
|
+
import { isServer } from "@builder.io/qwik/build";
|
|
3
4
|
const Button = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((props) => {
|
|
4
5
|
useStylesScopedQrl(/* @__PURE__ */ inlinedQrl(STYLES$3, "Button_component_useStylesScoped_a1JZ0Q0Q2Oc"));
|
|
5
6
|
return /* @__PURE__ */ _jsxC(Fragment, {
|
|
@@ -108,6 +109,30 @@ const getUserAttributes = () => {
|
|
|
108
109
|
device: isTablet ? "tablet" : isMobile.any() ? "mobile" : "desktop"
|
|
109
110
|
};
|
|
110
111
|
};
|
|
112
|
+
const getFunctionArguments = ({ builder, context, event, state }) => {
|
|
113
|
+
return Object.entries({
|
|
114
|
+
state,
|
|
115
|
+
Builder: builder,
|
|
116
|
+
// legacy
|
|
117
|
+
builder,
|
|
118
|
+
context,
|
|
119
|
+
event
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
const getBuilderGlobals = () => ({
|
|
123
|
+
isEditing: isEditing(),
|
|
124
|
+
isBrowser: isBrowser(),
|
|
125
|
+
isServer: !isBrowser(),
|
|
126
|
+
getUserAttributes: () => getUserAttributes()
|
|
127
|
+
});
|
|
128
|
+
const parseCode = (code, { isExpression = true }) => {
|
|
129
|
+
const useReturn = (
|
|
130
|
+
// we disable this for cases where we definitely don't want a return
|
|
131
|
+
isExpression && !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "))
|
|
132
|
+
);
|
|
133
|
+
const useCode = useReturn ? `return (${code});` : code;
|
|
134
|
+
return useCode;
|
|
135
|
+
};
|
|
111
136
|
const set = (obj, _path, value) => {
|
|
112
137
|
if (Object(obj) !== obj)
|
|
113
138
|
return obj;
|
|
@@ -3277,16 +3302,6 @@ t.prototype.getGlobalScope = t.prototype.Xb;
|
|
|
3277
3302
|
t.prototype.getStateStack = t.prototype.Yb;
|
|
3278
3303
|
t.prototype.setStateStack = t.prototype.ec;
|
|
3279
3304
|
t.VALUE_IN_DESCRIPTOR = Ia;
|
|
3280
|
-
const getFunctionArguments = ({ builder, context, event, state }) => {
|
|
3281
|
-
return Object.entries({
|
|
3282
|
-
state,
|
|
3283
|
-
Builder: builder,
|
|
3284
|
-
// legacy
|
|
3285
|
-
builder,
|
|
3286
|
-
context,
|
|
3287
|
-
event
|
|
3288
|
-
});
|
|
3289
|
-
};
|
|
3290
3305
|
const processCode = (code) => {
|
|
3291
3306
|
return code.split("\n").map((line) => {
|
|
3292
3307
|
const trimmed = line.trim();
|
|
@@ -3356,25 +3371,44 @@ theFunction();
|
|
|
3356
3371
|
return;
|
|
3357
3372
|
}
|
|
3358
3373
|
};
|
|
3374
|
+
const runInBrowser = ({ code, builder, context, event, localState, rootSetState, rootState }) => {
|
|
3375
|
+
const functionArgs = getFunctionArguments({
|
|
3376
|
+
builder,
|
|
3377
|
+
context,
|
|
3378
|
+
event,
|
|
3379
|
+
state: flattenState(rootState, localState, rootSetState)
|
|
3380
|
+
});
|
|
3381
|
+
return new Function(...functionArgs.map(([name]) => name), code)(...functionArgs.map(([, value]) => value));
|
|
3382
|
+
};
|
|
3383
|
+
function flattenState(rootState, localState, rootSetState) {
|
|
3384
|
+
if (rootState === localState)
|
|
3385
|
+
throw new Error("rootState === localState");
|
|
3386
|
+
return new Proxy(rootState, {
|
|
3387
|
+
get: (_, prop) => {
|
|
3388
|
+
if (localState && prop in localState)
|
|
3389
|
+
return localState[prop];
|
|
3390
|
+
return rootState[prop];
|
|
3391
|
+
},
|
|
3392
|
+
set: (_, prop, value) => {
|
|
3393
|
+
if (localState && prop in localState)
|
|
3394
|
+
throw new Error("Writing to local state is not allowed as it is read-only.");
|
|
3395
|
+
rootState[prop] = value;
|
|
3396
|
+
rootSetState == null ? void 0 : rootSetState(rootState);
|
|
3397
|
+
return true;
|
|
3398
|
+
}
|
|
3399
|
+
});
|
|
3400
|
+
}
|
|
3401
|
+
const chooseBrowserOrServerEval = (args) => !isServer ? runInBrowser(args) : runInEdge(args);
|
|
3359
3402
|
function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true }) {
|
|
3360
3403
|
if (code === "") {
|
|
3361
3404
|
logger.warn("Skipping evaluation of empty code block.");
|
|
3362
3405
|
return;
|
|
3363
3406
|
}
|
|
3364
|
-
const builder = {
|
|
3365
|
-
isEditing: isEditing(),
|
|
3366
|
-
isBrowser: isBrowser(),
|
|
3367
|
-
isServer: !isBrowser(),
|
|
3368
|
-
getUserAttributes: () => getUserAttributes()
|
|
3369
|
-
};
|
|
3370
|
-
const useReturn = (
|
|
3371
|
-
// we disable this for cases where we definitely don't want a return
|
|
3372
|
-
isExpression && !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "))
|
|
3373
|
-
);
|
|
3374
|
-
const useCode = useReturn ? `return (${code});` : code;
|
|
3375
3407
|
const args = {
|
|
3376
|
-
code:
|
|
3377
|
-
|
|
3408
|
+
code: parseCode(code, {
|
|
3409
|
+
isExpression
|
|
3410
|
+
}),
|
|
3411
|
+
builder: getBuilderGlobals(),
|
|
3378
3412
|
context,
|
|
3379
3413
|
event,
|
|
3380
3414
|
rootSetState,
|
|
@@ -3382,7 +3416,7 @@ function evaluate({ code, context, localState, rootState, rootSetState, event, i
|
|
|
3382
3416
|
localState
|
|
3383
3417
|
};
|
|
3384
3418
|
try {
|
|
3385
|
-
return
|
|
3419
|
+
return chooseBrowserOrServerEval(args);
|
|
3386
3420
|
} catch (e) {
|
|
3387
3421
|
logger.error("Failed code evaluation: " + e.message, {
|
|
3388
3422
|
code
|
|
@@ -6011,9 +6045,10 @@ const getBuilderSearchParamsFromWindow = () => {
|
|
|
6011
6045
|
};
|
|
6012
6046
|
const normalizeSearchParams = (searchParams) => searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams;
|
|
6013
6047
|
const DEFAULT_API_VERSION = "v3";
|
|
6048
|
+
const isPositiveNumber = (thing) => typeof thing === "number" && !isNaN(thing) && thing >= 0;
|
|
6014
6049
|
const generateContentUrl = (options) => {
|
|
6015
6050
|
let { noTraverse = false } = options;
|
|
6016
|
-
const { limit = 30, userAttributes, query, model, apiKey, includeRefs = true, enrich, locale, apiVersion = DEFAULT_API_VERSION } = options;
|
|
6051
|
+
const { limit = 30, userAttributes, query, model, apiKey, includeRefs = true, enrich, locale, apiVersion = DEFAULT_API_VERSION, fields, omit, offset, cacheSeconds, staleCacheSeconds, sort, includeUnpublished } = options;
|
|
6017
6052
|
if (!apiKey)
|
|
6018
6053
|
throw new Error("Missing API key");
|
|
6019
6054
|
if (![
|
|
@@ -6024,6 +6059,24 @@ const generateContentUrl = (options) => {
|
|
|
6024
6059
|
if ((options.limit === void 0 || options.limit > 1) && !("noTraverse" in options))
|
|
6025
6060
|
noTraverse = true;
|
|
6026
6061
|
const url = new URL(`https://cdn.builder.io/api/${apiVersion}/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}${locale ? `&locale=${locale}` : ""}${enrich ? `&enrich=${enrich}` : ""}`);
|
|
6062
|
+
url.searchParams.set("omit", omit || "meta.componentsUsed");
|
|
6063
|
+
if (fields)
|
|
6064
|
+
url.searchParams.set("fields", fields);
|
|
6065
|
+
if (Number.isFinite(offset) && offset > -1)
|
|
6066
|
+
url.searchParams.set("offset", String(Math.floor(offset)));
|
|
6067
|
+
if (typeof includeUnpublished === "boolean")
|
|
6068
|
+
url.searchParams.set("includeUnpublished", String(includeUnpublished));
|
|
6069
|
+
if (cacheSeconds && isPositiveNumber(cacheSeconds))
|
|
6070
|
+
url.searchParams.set("cacheSeconds", String(cacheSeconds));
|
|
6071
|
+
if (staleCacheSeconds && isPositiveNumber(staleCacheSeconds))
|
|
6072
|
+
url.searchParams.set("staleCacheSeconds", String(staleCacheSeconds));
|
|
6073
|
+
if (sort) {
|
|
6074
|
+
const flattened2 = flatten({
|
|
6075
|
+
sort
|
|
6076
|
+
});
|
|
6077
|
+
for (const key in flattened2)
|
|
6078
|
+
url.searchParams.set(key, JSON.stringify(flattened2[key]));
|
|
6079
|
+
}
|
|
6027
6080
|
const queryOptions = {
|
|
6028
6081
|
...getBuilderSearchParamsFromWindow(),
|
|
6029
6082
|
...normalizeSearchParams(options.options || {})
|
|
@@ -6297,7 +6350,7 @@ const getInteractionPropertiesForEvent = (event) => {
|
|
|
6297
6350
|
}
|
|
6298
6351
|
};
|
|
6299
6352
|
};
|
|
6300
|
-
const SDK_VERSION = "0.7.1-
|
|
6353
|
+
const SDK_VERSION = "0.7.1-4";
|
|
6301
6354
|
const registry = {};
|
|
6302
6355
|
function register(type, info) {
|
|
6303
6356
|
let typeList = registry[type];
|