@joystick.js/node-canary 0.0.0-canary.345 → 0.0.0-canary.347

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.
@@ -6,7 +6,7 @@ var sessions_default = {
6
6
  await process.databases._sessions?.collection("sessions").insertOne({
7
7
  _id: session_id,
8
8
  csrf: generateId(32),
9
- createdAt: new Date().toISOString()
9
+ createdAt: new Date(new Date().toISOString())
10
10
  });
11
11
  return session_id;
12
12
  },
@@ -131,7 +131,6 @@ var queues_default = {
131
131
  CREATE TABLE IF NOT EXISTS queue_${this.queue.name} (
132
132
  _id text PRIMARY KEY,
133
133
  status text,
134
- environment text,
135
134
  job text,
136
135
  payload text,
137
136
  next_run_at text,
@@ -140,16 +139,17 @@ var queues_default = {
140
139
  completed_at text,
141
140
  failed_at text,
142
141
  error text,
142
+ environment text,
143
143
  attempts smallint
144
144
  )
145
145
  `);
146
- db?.query(`ALTER TABLE queue_${this.queue.name} ADD COLUMN IF NOT EXISTS attempts smallint`);
147
- db?.query(`ALTER TABLE queue_${this.queue.name} ADD COLUMN IF NOT EXISTS environment text`);
148
- db?.query(`CREATE INDEX IF NOT EXISTS status_index ON queue_${this.queue.name} (status)`);
149
- db?.query(`CREATE INDEX IF NOT EXISTS status_nextRunAt_index ON queue_${this.queue.name} (status, next_run_at)`);
150
- db?.query(`CREATE INDEX IF NOT EXISTS nextJob_index ON queue_${this.queue.name} (status, environment, next_run_at, locked_by)`);
151
- db?.query(`CREATE INDEX IF NOT EXISTS completedAt_index ON queue_${this.queue.name} (completed_at)`);
152
- db?.query(`CREATE INDEX IF NOT EXISTS failedAt_index ON queue_${this.queue.name} (failed_at)`);
146
+ await db?.query(`ALTER TABLE queue_${this.queue.name} ADD COLUMN IF NOT EXISTS environment text`);
147
+ await db?.query(`ALTER TABLE queue_${this.queue.name} ADD COLUMN IF NOT EXISTS attempts smallint`);
148
+ await db?.query(`CREATE INDEX IF NOT EXISTS status_index ON queue_${this.queue.name} (status)`);
149
+ await db?.query(`CREATE INDEX IF NOT EXISTS status_nextRunAt_index ON queue_${this.queue.name} (status, next_run_at)`);
150
+ await db?.query(`CREATE INDEX IF NOT EXISTS nextJob_index ON queue_${this.queue.name} (status, environment, next_run_at, locked_by)`);
151
+ await db?.query(`CREATE INDEX IF NOT EXISTS completedAt_index ON queue_${this.queue.name} (completed_at)`);
152
+ await db?.query(`CREATE INDEX IF NOT EXISTS failedAt_index ON queue_${this.queue.name} (failed_at)`);
153
153
  if (this.queue.options?.cleanup?.completedAfterSeconds) {
154
154
  cron.schedule("*/30 * * * * *", () => {
155
155
  handleCleanupQueues({
package/dist/index.js CHANGED
@@ -17,9 +17,7 @@ import pushLogs from "./push/logs/index.js";
17
17
  import nodeUrlPolyfills from "./lib/nodeUrlPolyfills.js";
18
18
  import sendEmail from "./email/send";
19
19
  const { readFile } = fs.promises;
20
- if (process.env.NODE_ENV !== "development" && process.env.IS_PUSH_DEPLOYED) {
21
- pushLogs();
22
- }
20
+ await pushLogs();
23
21
  const generate_sql_from_object = _generate_sql_from_object;
24
22
  const accounts = _accounts;
25
23
  const action = _action;
@@ -1,21 +1,30 @@
1
1
  import { MongoClient } from "mongodb";
2
2
  import { MEGABYTE } from "../lib/constants.js";
3
- const connectMongoDB = async () => {
3
+ const connect_mongodb = async () => {
4
4
  const client = new MongoClient("mongodb://localhost:27017");
5
5
  const db = client.db("push");
6
6
  await db.collection("logs").drop();
7
7
  await db.collection("metrics").drop();
8
- await db.createCollection("logs", { capped: true, size: MEGABYTE * 50, max: 1e3 });
9
- await db.createCollection("metrics", { capped: true, size: MEGABYTE * 50, max: 1e3 });
10
- await db.collection("logs").createIndex({ timestamp: 1 });
11
- await db.collection("metrics").createIndex({ timestamp: 1 });
12
- await client.connect();
13
- return {
14
- client,
15
- db
16
- };
8
+ const existing_collections = (await db.listCollections().toArray())?.map((collection) => collection?.name);
9
+ const has_logs_collection = existing_collections?.includes("logs");
10
+ const has_metrics_collection = existing_collections?.includes("metrics");
11
+ if (!has_logs_collection) {
12
+ await db.createCollection("logs", { capped: true, size: MEGABYTE * 50, max: 1e3 });
13
+ }
14
+ if (!has_metrics_collection) {
15
+ await db.createCollection("metrics", { capped: true, size: MEGABYTE * 50, max: 1e3 });
16
+ }
17
+ 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
+ if (!logs_index) {
20
+ await db.collection("logs").createIndex({ timestamp: 1 });
21
+ }
22
+ if (!metrics_index) {
23
+ await db.collection("metrics").createIndex({ timestamp: 1 });
24
+ }
25
+ return db;
17
26
  };
18
- var connectMongoDB_default = connectMongoDB;
27
+ var connectMongoDB_default = connect_mongodb;
19
28
  export {
20
29
  connectMongoDB_default as default
21
30
  };
@@ -22,28 +22,26 @@ const captureLog = (callback = null) => {
22
22
  }
23
23
  });
24
24
  };
25
- var logs_default = () => {
25
+ var logs_default = async () => {
26
+ const mongodb = await connectMongoDB();
26
27
  return captureLog(async (source = "", data = "") => {
27
- const mongodb = await connectMongoDB();
28
28
  switch (source) {
29
29
  case "stdout":
30
- await mongodb.db.collection("logs").insertOne({
30
+ await mongodb.collection("logs").insertOne({
31
31
  error: false,
32
32
  timestamp: timestamps.get_current_time(),
33
33
  process_id: process.pid,
34
34
  data
35
35
  });
36
- return mongodb.client.close();
37
36
  case "stderr":
38
37
  case "uncaughtException":
39
38
  case "unhandledRejection":
40
- await mongodb.db.collection("logs").insertOne({
39
+ await mongodb.collection("logs").insertOne({
41
40
  error: true,
42
41
  timestamp: timestamps.get_current_time(),
43
42
  process_id: process.pid,
44
43
  data
45
44
  });
46
- return mongodb.client.close();
47
45
  default:
48
46
  return;
49
47
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joystick.js/node-canary",
3
- "version": "0.0.0-canary.345",
3
+ "version": "0.0.0-canary.347",
4
4
  "type": "module",
5
5
  "description": "A Node.js framework for building web apps.",
6
6
  "main": "./dist/index.js",