@builder.io/sdk-qwik 0.5.3-3 → 0.5.3-4

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.
@@ -1,75 +0,0 @@
1
- import { l as logger, s as set } from "./index.70b4317c.js";
2
- import Interpreter from "js-interpreter";
3
- import "@builder.io/qwik";
4
- import "@builder.io/qwik/jsx-runtime";
5
- const processCode = (code) => {
6
- return code.split("\n").map((line) => {
7
- const trimmed = line.trim();
8
- if (line.includes("__awaiter"))
9
- return void 0;
10
- const isStateSetter = trimmed.startsWith("state.");
11
- if (!isStateSetter)
12
- return line;
13
- const [lhs, rhs] = trimmed.split("=");
14
- const setStr = lhs.replace("state.", "").trim();
15
- const setExpr = `setRootState('${setStr}', ${rhs.trim()})`;
16
- return `
17
- ${line}
18
- ${setExpr}
19
- `;
20
- }).filter(Boolean).join("\n");
21
- };
22
- const getJSONValName = (val) => val + "JSON";
23
- const runInNonNode = ({ builder, context, event, rootState, localState, rootSetState, useCode }) => {
24
- const state = {
25
- ...rootState,
26
- ...localState
27
- };
28
- const properties = {
29
- state,
30
- Builder: builder,
31
- builder,
32
- context,
33
- event
34
- };
35
- const prependedCode = Object.keys(properties).map((key) => `var ${key} = JSON.parse(${getJSONValName(key)});`).join("\n");
36
- const cleanedCode = processCode(useCode);
37
- if (cleanedCode === "") {
38
- logger.warn("Skipping evaluation of empty code block.");
39
- return;
40
- }
41
- const transformed = `
42
- function theFunction() {
43
- ${prependedCode}
44
-
45
- ${cleanedCode}
46
- }
47
- theFunction();
48
- `;
49
- const setRootState = (prop, value) => {
50
- const newState = set(state, prop, value);
51
- rootSetState?.(newState);
52
- };
53
- const initFunc = function(interpreter, globalObject) {
54
- Object.keys(properties).forEach((key) => {
55
- const val = properties[key] || {};
56
- const jsonVal = JSON.stringify(val);
57
- interpreter.setProperty(globalObject, getJSONValName(key), jsonVal);
58
- });
59
- interpreter.setProperty(globalObject, "setRootState", interpreter.createNativeFunction(setRootState));
60
- };
61
- try {
62
- const myInterpreter = new Interpreter(transformed, initFunc);
63
- myInterpreter.run();
64
- const output = myInterpreter.pseudoToNative(myInterpreter.value);
65
- return output;
66
- } catch (e) {
67
- logger.warn("Custom code error in non-node runtime. SDK can only execute ES5 JavaScript.", {
68
- e
69
- });
70
- return;
71
- }
72
- };
73
- export {
74
- runInNonNode
75
- };
@@ -1,77 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const index = require("./index.fd3df238.cjs");
4
- const Interpreter = require("js-interpreter");
5
- require("@builder.io/qwik");
6
- require("@builder.io/qwik/jsx-runtime");
7
- const _interopDefaultLegacy = (e) => e && typeof e === "object" && "default" in e ? e : { default: e };
8
- const Interpreter__default = /* @__PURE__ */ _interopDefaultLegacy(Interpreter);
9
- const processCode = (code) => {
10
- return code.split("\n").map((line) => {
11
- const trimmed = line.trim();
12
- if (line.includes("__awaiter"))
13
- return void 0;
14
- const isStateSetter = trimmed.startsWith("state.");
15
- if (!isStateSetter)
16
- return line;
17
- const [lhs, rhs] = trimmed.split("=");
18
- const setStr = lhs.replace("state.", "").trim();
19
- const setExpr = `setRootState('${setStr}', ${rhs.trim()})`;
20
- return `
21
- ${line}
22
- ${setExpr}
23
- `;
24
- }).filter(Boolean).join("\n");
25
- };
26
- const getJSONValName = (val) => val + "JSON";
27
- const runInNonNode = ({ builder, context, event, rootState, localState, rootSetState, useCode }) => {
28
- const state = {
29
- ...rootState,
30
- ...localState
31
- };
32
- const properties = {
33
- state,
34
- Builder: builder,
35
- builder,
36
- context,
37
- event
38
- };
39
- const prependedCode = Object.keys(properties).map((key) => `var ${key} = JSON.parse(${getJSONValName(key)});`).join("\n");
40
- const cleanedCode = processCode(useCode);
41
- if (cleanedCode === "") {
42
- index.logger.warn("Skipping evaluation of empty code block.");
43
- return;
44
- }
45
- const transformed = `
46
- function theFunction() {
47
- ${prependedCode}
48
-
49
- ${cleanedCode}
50
- }
51
- theFunction();
52
- `;
53
- const setRootState = (prop, value) => {
54
- const newState = index.set(state, prop, value);
55
- rootSetState?.(newState);
56
- };
57
- const initFunc = function(interpreter, globalObject) {
58
- Object.keys(properties).forEach((key) => {
59
- const val = properties[key] || {};
60
- const jsonVal = JSON.stringify(val);
61
- interpreter.setProperty(globalObject, getJSONValName(key), jsonVal);
62
- });
63
- interpreter.setProperty(globalObject, "setRootState", interpreter.createNativeFunction(setRootState));
64
- };
65
- try {
66
- const myInterpreter = new Interpreter__default.default(transformed, initFunc);
67
- myInterpreter.run();
68
- const output = myInterpreter.pseudoToNative(myInterpreter.value);
69
- return output;
70
- } catch (e) {
71
- index.logger.warn("Custom code error in non-node runtime. SDK can only execute ES5 JavaScript.", {
72
- e
73
- });
74
- return;
75
- }
76
- };
77
- exports.runInNonNode = runInNonNode;