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

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,3 +1,5 @@
1
+ const KILOBYTE = 1e3;
2
+ const MEGABYTE = KILOBYTE * 1e3;
1
3
  const HTML_ENTITY_MAP = {
2
4
  "&": "&",
3
5
  "<": "&lt;",
@@ -9,5 +11,7 @@ const HTML_ENTITY_MAP = {
9
11
  "=": "&#x3D;"
10
12
  };
11
13
  export {
12
- HTML_ENTITY_MAP
14
+ HTML_ENTITY_MAP,
15
+ KILOBYTE,
16
+ MEGABYTE
13
17
  };
@@ -0,0 +1,21 @@
1
+ import { MongoClient } from "mongodb";
2
+ import { MEGABYTE } from "../lib/constants.js";
3
+ const connectMongoDB = async () => {
4
+ const client = new MongoClient("mongodb://localhost:27017");
5
+ const db = client.db("push");
6
+ await db.collection("logs").drop();
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
+ };
17
+ };
18
+ var connectMongoDB_default = connectMongoDB;
19
+ export {
20
+ connectMongoDB_default as default
21
+ };
@@ -1,7 +1,5 @@
1
- import { MongoClient } from "mongodb";
2
1
  import timestamps from "../../lib/timestamps";
3
- const KILOBYTE = 1e3;
4
- const MEGABYTE = KILOBYTE * 1e3;
2
+ import connectMongoDB from "../connectMongoDB.js";
5
3
  const captureLog = (callback = null) => {
6
4
  process.stdout.write = (data) => {
7
5
  if (callback) {
@@ -24,22 +22,8 @@ const captureLog = (callback = null) => {
24
22
  }
25
23
  });
26
24
  };
27
- const connectMongoDB = async () => {
28
- const client = new MongoClient("mongodb://localhost:27017");
29
- const db = client.db("push");
30
- try {
31
- await db.createCollection("logs", { capped: true, size: MEGABYTE * 50, max: 1e3 });
32
- await db.createCollection("metrics", { capped: true, size: MEGABYTE * 50, max: 1e3 });
33
- } catch {
34
- }
35
- await client.connect();
36
- return {
37
- client,
38
- db
39
- };
40
- };
41
- const writeLogsToDisk = () => {
42
- captureLog(async (source = "", data = "") => {
25
+ var logs_default = () => {
26
+ return captureLog(async (source = "", data = "") => {
43
27
  const mongodb = await connectMongoDB();
44
28
  switch (source) {
45
29
  case "stdout":
@@ -65,9 +49,6 @@ const writeLogsToDisk = () => {
65
49
  }
66
50
  });
67
51
  };
68
- var logs_default = () => {
69
- return writeLogsToDisk();
70
- };
71
52
  export {
72
53
  logs_default as default
73
54
  };
@@ -4,10 +4,10 @@ var websockets_default = (serverName = "") => {
4
4
  return {
5
5
  send: (payload = {}, uniqueConnectionId = "") => {
6
6
  const emitterName = uniqueConnectionId ? `${serverName}_${uniqueConnectionId}` : serverName;
7
+ emitWebsocketEvent(emitterName, "message", payload);
7
8
  trackFunctionCall(`node.websockets.${serverName}.send`, [
8
9
  payload
9
10
  ]);
10
- emitWebsocketEvent(emitterName, "message", payload);
11
11
  }
12
12
  };
13
13
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joystick.js/node-canary",
3
- "version": "0.0.0-canary.344",
3
+ "version": "0.0.0-canary.345",
4
4
  "type": "module",
5
5
  "description": "A Node.js framework for building web apps.",
6
6
  "main": "./dist/index.js",