@everneed/worker 1.0.1 → 1.1.0

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.
Files changed (2) hide show
  1. package/index.js +20 -1
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import postgres from "postgres"
2
2
  import mongoose from "mongoose"
3
3
  import { createClient } from "redis"
4
+ import { io } from "socket.io-client"
4
5
 
5
6
  import rabbitmq from "./worker/rabbitmq.js"
6
7
  import pseudoEnv from "./pseudoenv.js"
@@ -32,7 +33,7 @@ import pseudoEnv from "./pseudoenv.js"
32
33
  }
33
34
  /* mongoose */
34
35
  let mongooseInstance = ()=>{}
35
- mongooseInstance.config = (object)=>{
36
+ mongooseInstance.config = async (object)=>{
36
37
  // config({
37
38
  // ENV: value,
38
39
  // ...
@@ -68,8 +69,26 @@ import pseudoEnv from "./pseudoenv.js"
68
69
  .on("error", err => console.log("Redis Client Error", err))
69
70
  // .connect()
70
71
  }
72
+ /* Socketio */
73
+ let socketioInstance = ()=>{}
74
+ socketioInstance.config = (object)=>{
75
+ // config({
76
+ // ENV: value,
77
+ // ...
78
+ // })
79
+ /* Param Validation */
80
+ const allowed = new Set(["WEBSOCKET_HOST", "WEBSOCKET_PORT"])
81
+ if(new Set(Object.keys(object)).difference(allowed).size){
82
+ throw `illegal key on socketio.config(): Only ${Array.from(allowed).join(", ")} are allowed`
83
+ }
84
+ /* Env Add Process */
85
+ pseudoEnv.config(object)
86
+ /* Refresh Instance (force re-export) */
87
+ socketioInstance = io(`ws://${pseudoEnv.process.env.WEBSOCKET_HOST}:${pseudoEnv.process.env.WEBSOCKET_PORT}/`)
88
+ }
71
89
 
72
90
  export { rabbitmq } // preserve seperate-dir for example
73
91
  export { postgresInstance as postgres }
74
92
  // export { mongooseInstance as mongoose }
75
93
  export { redisInstance as redis }
94
+ export { socketioInstance as socketio }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@everneed/worker",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"