@joystick.js/node-canary 0.0.0-canary.352 → 0.0.0-canary.354

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.
@@ -2,6 +2,7 @@ import fs from "fs";
2
2
  import importFile from "../../lib/importFile.js";
3
3
  import { isObject } from "../../validation/lib/typeValidators.js";
4
4
  import settings from "../../settings/index.js";
5
+ const { readdir } = fs.promises;
5
6
  const getTranslationsFile = async (languageFilePath = "", paths = "") => {
6
7
  const languageFile = await importFile(`${paths.build}/i18n/${languageFilePath}`);
7
8
  const isValidLanguageFile = languageFile && isObject(languageFile);
@@ -44,7 +45,7 @@ const parseBrowserLanguages = (languages = "") => {
44
45
  return rawLanguages?.map((rawLanguage) => rawLanguage.split(";")[0]);
45
46
  };
46
47
  var getTranslations_default = async (paths = {}, req = {}) => {
47
- const languageFiles = fs.readdirSync(`${paths.build}/i18n`);
48
+ const languageFiles = await readdir(`${paths.build}/i18n`);
48
49
  const browserLanguages = parseBrowserLanguages(req?.headers["accept-language"]);
49
50
  const languagePreferences = getLanguagePreferenceRegexes(req?.context?.user?.language, browserLanguages);
50
51
  let matchingFile = null;
@@ -17,6 +17,7 @@ import replaceFileProtocol from "../../lib/replaceFileProtocol.js";
17
17
  import getBuildPath from "../../lib/getBuildPath.js";
18
18
  import session from "./session.js";
19
19
  import csp from "./csp.js";
20
+ const { readFile } = fs.promises;
20
21
  const cwd = replaceFileProtocol(replaceBackslashesWithForwardSlashes(process.cwd()));
21
22
  const faviconPath = "public/favicon.ico";
22
23
  var middleware_default = ({
@@ -52,9 +53,9 @@ var middleware_default = ({
52
53
  app.use("/_joystick/heartbeat", (_req, res) => {
53
54
  res.status(200).send("<3");
54
55
  });
55
- app.use("/_joystick/utils/process.js", (_req, res) => {
56
+ app.use("/_joystick/utils/process.js", async (_req, res) => {
56
57
  res.set("Content-Type", "text/javascript");
57
- const processPolyfill = fs.readFileSync(`${__package}/app/utils/process.js`, "utf-8");
58
+ const processPolyfill = await readFile(`${__package}/app/utils/process.js`, "utf-8");
58
59
  res.send(processPolyfill.replace("${NODE_ENV}", process.env.NODE_ENV));
59
60
  });
60
61
  app.use("/_joystick/index.client.js", express.static(`${buildPath}index.client.js`, {
@@ -63,9 +64,9 @@ var middleware_default = ({
63
64
  }));
64
65
  app.use("/_joystick/index.css", express.static(`${buildPath}index.css`, { eTag: false, maxAge: "0" }));
65
66
  app.use("/_joystick/ui", express.static(`${buildPath}ui`, { eTag: false, maxAge: "0" }));
66
- app.use("/_joystick/hmr/client.js", (_req, res) => {
67
+ app.use("/_joystick/hmr/client.js", async (_req, res) => {
67
68
  res.set("Content-Type", "text/javascript");
68
- const hmrClient = fs.readFileSync(`${__package}/app/middleware/hmr/client.js`, "utf-8");
69
+ const hmrClient = await readFile(`${__package}/app/middleware/hmr/client.js`, "utf-8");
69
70
  res.send(hmrClient.replace("${process.env.PORT}", parseInt(process.env.PORT, 10) + 1));
70
71
  });
71
72
  app.use(favicon(faviconPath));
@@ -12,6 +12,7 @@ import escapeHTML from "../../lib/escapeHTML.js";
12
12
  import escapeKeyValuePair from "../../lib/escapeKeyValuePair.js";
13
13
  import importFile from "../../lib/importFile.js";
14
14
  import getTranslations from "./getTranslations.js";
15
+ import path_exists from "../../lib/path_exists.js";
15
16
  const generateHash = (input = "") => {
16
17
  return crypto.createHash("sha256").update(input).digest("hex");
17
18
  };
@@ -85,7 +86,7 @@ var render_default = (req, res, next, appInstance = {}) => {
85
86
  const pagePathParts = `${buildPathForEnvironment}${path}`?.split("/")?.filter((part) => !!part);
86
87
  const cachePath = pagePathParts?.slice(0, pagePathParts.length - 1)?.join("/");
87
88
  let currentDiff;
88
- if (!fs.existsSync(pagePath)) {
89
+ if (!await path_exists(pagePath)) {
89
90
  return res.status(404).send(generateErrorPage({
90
91
  type: "pageNotFound",
91
92
  path: `res.render('${path}')`,
@@ -93,7 +94,7 @@ var render_default = (req, res, next, appInstance = {}) => {
93
94
  stack: `A page component at the path ${path} could not be found.`
94
95
  }));
95
96
  }
96
- if (layoutPath && !fs.existsSync(layoutPath)) {
97
+ if (layoutPath && !await path_exists(layoutPath)) {
97
98
  return res.status(404).send(generateErrorPage({
98
99
  type: "layoutNotFound",
99
100
  path: `res.render('${path}', { layout: '${options.layout}' })`,
@@ -0,0 +1,12 @@
1
+ import fs from "fs";
2
+ const path_exists = (path = "") => {
3
+ return new Promise((resolve) => {
4
+ fs.access(path, fs.constants.F_OK, (error) => {
5
+ resolve(!error);
6
+ });
7
+ });
8
+ };
9
+ var path_exists_default = path_exists;
10
+ export {
11
+ path_exists_default as default
12
+ };
@@ -4,24 +4,15 @@ const connect_mongodb = async () => {
4
4
  const client = await MongoClient.connect("mongodb://localhost:27017");
5
5
  const db = client.db("push");
6
6
  await db.collection("logs").drop();
7
- await db.collection("metrics").drop();
8
7
  const existing_collections = (await db.listCollections().toArray())?.map((collection) => collection?.name);
9
8
  const has_logs_collection = existing_collections?.includes("logs");
10
- const has_metrics_collection = existing_collections?.includes("metrics");
11
9
  if (!has_logs_collection) {
12
10
  await db.createCollection("logs", { capped: true, size: MEGABYTE * 50, max: 1e3 });
13
11
  }
14
- if (!has_metrics_collection) {
15
- await db.createCollection("metrics", { capped: true, size: MEGABYTE * 50, max: 1e3 });
16
- }
17
12
  const logs_index = (await db.collection("logs").listIndexes().toArray())?.find((index) => index?.name === "timestamp_1");
18
- const metrics_index = (await db.collection("metrics").listIndexes().toArray())?.find((index) => index?.name === "timestamp_1");
19
13
  if (!logs_index) {
20
14
  await db.collection("logs").createIndex({ timestamp: 1 });
21
15
  }
22
- if (!metrics_index) {
23
- await db.collection("metrics").createIndex({ timestamp: 1 });
24
- }
25
16
  return db;
26
17
  };
27
18
  var connectMongoDB_default = connect_mongodb;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joystick.js/node-canary",
3
- "version": "0.0.0-canary.352",
3
+ "version": "0.0.0-canary.354",
4
4
  "type": "module",
5
5
  "description": "A Node.js framework for building web apps.",
6
6
  "main": "./dist/index.js",