@joystick.js/node-canary 0.0.0-canary.51 → 0.0.0-canary.53

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/dist/app/index.js CHANGED
@@ -32,6 +32,7 @@ import Queue from "./queues/index.js";
32
32
  import readDirectory from "../lib/readDirectory.js";
33
33
  import getBuildPath from "../lib/getBuildPath.js";
34
34
  import generateMachineId from "../lib/generateMachineId.js";
35
+ import importFile from "../lib/importFile.js.js";
35
36
  import emitWebsocketEvent from "../websockets/emitWebsocketEvent.js";
36
37
  import getTargetDatabaseConnection from "./databases/getTargetDatabaseConnection.js";
37
38
  process.setMaxListeners(0);
@@ -162,6 +163,11 @@ class App {
162
163
  initTests() {
163
164
  if (process.env.NODE_ENV === "test") {
164
165
  this.express.app.get("/api/_test/bootstrap", async (req, res) => {
166
+ const Component = req?.query?.pathToComponent ? await importFile(`./.joystick/build/${req?.query?.pathToComponent}`) : null;
167
+ if (Component) {
168
+ const componentInstance = Component();
169
+ console.log(componentInstance);
170
+ }
165
171
  res.status(200).send({
166
172
  ping: "pong",
167
173
  query: req?.query
@@ -10,6 +10,7 @@ import replaceBackslashesWithForwardSlashes from "../../lib/replaceBackslashesWi
10
10
  import getBuildPath from "../../lib/getBuildPath.js";
11
11
  import escapeHTML from "../../lib/escapeHTML.js";
12
12
  import escapeKeyValuePair from "../../lib/escapeKeyValuePair.js";
13
+ import importFile from "../../lib/importFile.js.js";
13
14
  const generateHash = (input = "") => {
14
15
  return crypto.createHash("sha256").update(input).digest("hex");
15
16
  };
@@ -73,12 +74,8 @@ const getUrl = (request = {}) => {
73
74
  path: escapeHTML(path)
74
75
  };
75
76
  };
76
- const getFile = async (buildPath = "") => {
77
- const file = await import(buildPath);
78
- return file.default;
79
- };
80
77
  const getTranslationsFile = async (languageFilePath = "", paths = "") => {
81
- const languageFile = await getFile(`${paths.build}/i18n/${languageFilePath}`);
78
+ const languageFile = await importFile(`${paths.build}/i18n/${languageFilePath}`);
82
79
  const isValidLanguageFile = languageFile && isObject(languageFile);
83
80
  if (isValidLanguageFile) {
84
81
  const translationsForPage = languageFile[paths.page];
@@ -169,9 +166,9 @@ var render_default = (req, res, next, appInstance = {}) => {
169
166
  return res.send(cachedHTML);
170
167
  }
171
168
  }
172
- const pageFile = await getFile(pagePath);
169
+ const pageFile = await importFile(pagePath);
173
170
  const Page = pageFile;
174
- const layoutFile = layoutPath ? await getFile(layoutPath) : null;
171
+ const layoutFile = layoutPath ? await importFile(layoutPath) : null;
175
172
  const Layout = layoutFile;
176
173
  const browserLanguages = parseBrowserLanguages(req?.headers["accept-language"]);
177
174
  const languagePreferenceRegexes = getLanguagePreferenceRegexes(req?.context?.user?.language, browserLanguages);
@@ -0,0 +1,7 @@
1
+ var importFile_default = async (buildPath = "") => {
2
+ const file = await import(buildPath);
3
+ return file?.default;
4
+ };
5
+ export {
6
+ importFile_default as default
7
+ };
@@ -0,0 +1,14 @@
1
+ var getDataFromComponent_default = async (componentInstance = {}, api = {}, browserSafeRequest = {}) => {
2
+ try {
3
+ const data = await componentInstance.handleFetchData(api, browserSafeRequest, {}, componentInstance);
4
+ return {
5
+ componentId: componentInstance?.id,
6
+ data
7
+ };
8
+ } catch (exception) {
9
+ throw new Error(`[ssr.getDataFromComponent] ${exception.message}`);
10
+ }
11
+ };
12
+ export {
13
+ getDataFromComponent_default as default
14
+ };
package/dist/ssr/index.js CHANGED
@@ -8,6 +8,7 @@ import getCSSFromTree from "./getCSSFromTree";
8
8
  import replaceWhenTags from "./replaceWhenTags";
9
9
  import setHeadTagsInHTML from "./setHeadTagsInHTML";
10
10
  import { parseHTML } from "linkedom";
11
+ import getDataFromComponent from "./getDataFromComponent.js";
11
12
  const injectCSSIntoHTML = (html, baseCSS = "", css = "") => {
12
13
  try {
13
14
  return html.replace("${css}", css).replace("${globalCSS}", `<style>${baseCSS || ""}</style>`).replace("${componentCSS}", css);
@@ -290,17 +291,6 @@ const buildTreeForComponent = (componentInstance = {}, ssrTree = {}, translation
290
291
  throw new Error(`[ssr.buildTreeForComponent] ${exception.message}`);
291
292
  }
292
293
  };
293
- const getDataFromComponent = async (componentInstance = {}, api = {}, browserSafeRequest = {}) => {
294
- try {
295
- const data = await componentInstance.handleFetchData(api, browserSafeRequest, {}, componentInstance);
296
- return {
297
- componentId: componentInstance?.id,
298
- data
299
- };
300
- } catch (exception) {
301
- throw new Error(`[ssr.getDataFromComponent] ${exception.message}`);
302
- }
303
- };
304
294
  const getTreeForSSR = (componentInstance = {}) => {
305
295
  try {
306
296
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joystick.js/node-canary",
3
- "version": "0.0.0-canary.51",
3
+ "version": "0.0.0-canary.53",
4
4
  "type": "module",
5
5
  "description": "A Node.js framework for building web apps.",
6
6
  "main": "./dist/index.js",