summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2024-02-25 05:01:00 -0300
committerEuAndreh <eu@euandre.org>2024-02-25 05:01:00 -0300
commit458bf0fc628d9bcf6a59a0efb898045266dab6ba (patch)
treebb538753668dad5abc7eec4a65bf4f233b34d93a /src
parentNormalize how modules import and name each other (diff)
downloadpapod-458bf0fc628d9bcf6a59a0efb898045266dab6ba.tar.gz
papod-458bf0fc628d9bcf6a59a0efb898045266dab6ba.tar.xz
Explicit import from "node:process"; move log() to hero.mjs
Diffstat (limited to 'src')
-rw-r--r--src/accretion.mjs6
-rw-r--r--src/api.mjs2
-rw-r--r--src/db.mjs13
-rw-r--r--src/hero.mjs15
-rw-r--r--src/utils.mjs2
5 files changed, 21 insertions, 17 deletions
diff --git a/src/accretion.mjs b/src/accretion.mjs
index a9adb97..1c70162 100644
--- a/src/accretion.mjs
+++ b/src/accretion.mjs
@@ -9,9 +9,9 @@ import * as u from "./utils.mjs";
const DIRNAME = path.dirname(url.fileURLToPath(import.meta.url));
-const MIGRATIONS_DIR = DIRNAME + "/sql/migrations/";
+export const MIGRATIONS_DIR = DIRNAME + "/sql/migrations/";
-export const runMigrations = async db => {
+export const runMigrations = async (logFn, db) => {
assert(db);
await db.exec(`
@@ -30,7 +30,7 @@ export const runMigrations = async db => {
.sort((a, b) => a.localeCompare(b, "POSIX"));
for (const filename of sortedPending) {
- u.log({ log: "exec-migration", filename });
+ logFn({ log: "exec-migration", filename });
const sql = fs.readFileSync(MIGRATIONS_DIR + filename, "UTF-8");
await db.exec("BEGIN TRANSACTION;");
await db.exec(sql);
diff --git a/src/api.mjs b/src/api.mjs
index 2ec7cbf..fb62adc 100644
--- a/src/api.mjs
+++ b/src/api.mjs
@@ -1,3 +1,5 @@
+import process from "node:process";
+
import * as ircd from "./ircd.mjs";
import * as web from "./web.mjs";
diff --git a/src/db.mjs b/src/db.mjs
index 6bb2634..b82cb18 100644
--- a/src/db.mjs
+++ b/src/db.mjs
@@ -1,7 +1,8 @@
-import assert from "node:assert/strict";
-import fs from "node:fs";
-import path from "node:path";
-import url from "node:url";
+import assert from "node:assert/strict";
+import fs from "node:fs";
+import path from "node:path";
+import process from "node:process";
+import url from "node:url";
import sqlite from "./sqlite.cjs";
@@ -49,7 +50,7 @@ export const open = (...args) =>
export let handle = null;
-export const init = async (dbName = process.env.PAPO_DB_PATH || ":memory:") => {
+export const init = async (logFn, dbName = process.env.PAPO_DB_PATH || ":memory:") => {
handle = await open(dbName);
- await accretion.runMigrations(handle);
+ await accretion.runMigrations(logFn, handle);
};
diff --git a/src/hero.mjs b/src/hero.mjs
index aa4a5a4..899e3fb 100644
--- a/src/hero.mjs
+++ b/src/hero.mjs
@@ -1,6 +1,7 @@
-import assert from "node:assert/strict";
-import crypto from "node:crypto";
-import http from "node:http";
+import assert from "node:assert/strict";
+import crypto from "node:crypto";
+import http from "node:http";
+import process from "node:process";
import * as u from "./utils.mjs";
@@ -121,7 +122,7 @@ export const handleRequest = async (table, method, url) => {
if (!handler) {
return {
status: 404,
- body: "Not Found",
+ body: "Not Found\n",
};
}
@@ -144,12 +145,14 @@ export const makeRequestListener = table => async (req, res) => {
res.end(response.body);
};
+export const log = o => console.error(JSON.stringify(o));
+
export const interceptorsFn = ({
uuidFn,
logger,
} = {
uuidFn: crypto.randomUUID,
- logger: u.log,
+ logger: log,
}) => ({
requestId: (req, next) => next({ ...req, id: uuidFn() }),
logged: async (req, next) => {
@@ -197,7 +200,7 @@ export const interceptorsFn = ({
});
return {
status: 500,
- body: "Internal Server Error",
+ body: "Internal Server Error\n",
};
}
},
diff --git a/src/utils.mjs b/src/utils.mjs
index 8ce9076..f2e09e4 100644
--- a/src/utils.mjs
+++ b/src/utils.mjs
@@ -73,8 +73,6 @@ export const first = (arr, fn) => {
return null;
};
-export const log = o => console.error(JSON.stringify(o));
-
export const promisify = fn => (...args) =>
new Promise((resolve, reject) =>
fn(...args, (err, data) => err ? reject(err) : resolve(data)));