@rpcbase/server 0.335.0 → 0.337.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.
package/boot/server.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // MUST COME FIRST!
3
3
  require("./shared")
4
4
  //
5
- const rb_server_plugin = require("rb-server-plugin")
5
+ const rb_server_plugin = require("rb-plugin-server")
6
6
 
7
7
  const http = require("http")
8
8
 
@@ -10,8 +10,6 @@ const {rpc_router, client_router, express} = require("../")
10
10
 
11
11
  const realtime_state = require("../rts")
12
12
 
13
- require("./register_server_tasks")
14
-
15
13
  const {SERVER_PORT} = process.env
16
14
 
17
15
  const app = express()
@@ -19,7 +17,7 @@ const server = http.createServer(app)
19
17
 
20
18
  realtime_state(server)
21
19
 
22
- rb_server_plugin(app)
20
+ rb_server_plugin.default(app)
23
21
 
24
22
  server.listen(SERVER_PORT, "0.0.0.0", () => {
25
23
  console.log(`listening on 0.0.0.0:${SERVER_PORT}`)
package/boot/shared.js CHANGED
@@ -1,12 +1,17 @@
1
1
  /* @flow */
2
+ if (typeof __RB_IS_WEBPACK__ === "undefined") {
3
+ throw new Error("cannot run outside of webpack bundling")
4
+ }
5
+
2
6
  require("./setup_env")
3
7
 
4
8
  require("../extend-expect")
5
9
 
6
10
  const mongoose = require("../mongoose")
7
- require("../src/access-control")(mongoose)
8
11
 
9
- // require("./load_models")
12
+ require("../src/models")
13
+
14
+ require("../src/access-control")(mongoose)
10
15
 
11
16
  const {database, firebase} = require("../")
12
17
 
package/boot/worker.js CHANGED
@@ -1,9 +1,7 @@
1
1
  /* @flow */
2
2
  require("./shared")
3
3
 
4
- require("./load_models")
5
-
6
- require("./register_worker_tasks")
4
+ require("rb-plugin-worker")
7
5
 
8
6
  const register_queue_listener = require("../queue/register_queue_listener")
9
7
 
@@ -1,22 +1,13 @@
1
1
  /* @flow */
2
2
  const get_dev_watcher = require("./get_dev_watcher")
3
3
 
4
-
5
- console.trace("DEV SERVER LINKED")
6
-
7
4
  const run_dev_server = (args) => {
8
5
 
9
6
  const watcher = get_dev_watcher({
10
- script: "build/server.js",
11
- ignore: [
12
- ],
7
+ script: "./build/server.js",
8
+ ignore: [],
13
9
  watch: [
14
- "./server.js",
15
- "build/",
16
- "src/",
17
- "../../../pms/plugin/",
18
- "../../../../rpcbase/rpcbase/pkg/access-control/",
19
- "../../../../rpcbase/rpcbase/pkg/server/"
10
+ "./build/server.js",
20
11
  ],
21
12
  delay: "500ms"
22
13
  })
@@ -4,19 +4,14 @@ const get_dev_watcher = require("./get_dev_watcher")
4
4
  const run_dev_worker = (args) => {
5
5
 
6
6
  const watcher = get_dev_watcher({
7
- script: "worker.js",
8
- ignore: [
9
- ],
7
+ script: "./build/worker.js",
8
+ ignore: [],
10
9
  watch: [
11
- "./worker.js",
12
- "build/",
13
- "src/",
14
- "../../../pms/plugin/",
15
- "../../../../rpcbase/rpcbase/pkg/access-control/",
16
- "../../../../rpcbase/rpcbase/pkg/server/"
10
+ "./build/worker.js",
17
11
  ],
18
12
  delay: "500ms"
19
13
  })
14
+
20
15
  }
21
16
 
22
17
  module.exports = run_dev_worker
package/index.js CHANGED
@@ -4,7 +4,6 @@ const queue = require("./queue")
4
4
  const express = require("./express")
5
5
  const firebase = require("./firebase")
6
6
  const client_router = require("./src/client/client_router")
7
- const rpc_router = require("./src/rpc/rpc_router")
8
7
  const sign_up = require("./src/auth/sign_up")
9
8
 
10
9
 
@@ -14,6 +13,5 @@ module.exports = {
14
13
  express,
15
14
  firebase,
16
15
  client_router,
17
- rpc_router,
18
16
  sign_up,
19
17
  }
package/mongoose.js CHANGED
@@ -5,4 +5,5 @@ const mongoose = require("mongoose")
5
5
  // https://mongoosejs.com/docs/migrating_to_7.html#strictquery
6
6
  mongoose.set("strictQuery", false)
7
7
 
8
+
8
9
  module.exports = mongoose
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/server",
3
- "version": "0.335.0",
3
+ "version": "0.337.0",
4
4
  "license": "SSPL-1.0",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -63,7 +63,6 @@
63
63
  }
64
64
  },
65
65
  "dependencies": {
66
- "@rpcbase/agent": "0.36.0",
67
66
  "@rpcbase/std": "0.13.0",
68
67
  "@sentry/node": "7.94.1",
69
68
  "bluebird": "3.7.2",
@@ -0,0 +1,5 @@
1
+ /* @flow */
2
+ require("./Invite")
3
+ require("./ResetPasswordToken")
4
+ require("./User")
5
+ require("./UserStoredValues")
@@ -1,23 +0,0 @@
1
- /* @flow */
2
- const glob = require("glob")
3
- const path = require("path")
4
-
5
-
6
- const is_pascal_case = (str) => /^[A-Z][a-zA-Z0-9]*$/.test(str)
7
-
8
-
9
- const load_models = () => {
10
- const wd = process.cwd()
11
-
12
- const models_dir = path.join(wd, "./src/models")
13
-
14
- const files = glob.sync(path.join(models_dir, "./**/*.js"))
15
-
16
- files
17
- .filter((f) => !path.dirname(f).endsWith("/helpers"))
18
- .filter((f) => is_pascal_case(path.basename(f, ".js")))
19
- .forEach((f) => require(f))
20
-
21
- }
22
-
23
- load_models()
@@ -1,21 +0,0 @@
1
- /* @flow */
2
- const path = require("path")
3
- const queue = require("@rpcbase/server/queue")
4
-
5
-
6
- const no_impl_server_task = () => {
7
- throw new Error("cannot run worker task on the server!")
8
- }
9
-
10
- const register_server_tasks = () => {
11
- const wd = process.cwd()
12
-
13
- const tasks_map = require(path.join(wd, "./src/tasks/index.js"))
14
-
15
- for (const [task_name, task_path] of Object.entries(tasks_map)) {
16
- queue.register_task(task_name, no_impl_server_task)
17
- }
18
-
19
- }
20
-
21
- register_server_tasks()
@@ -1,19 +0,0 @@
1
- /* @flow */
2
- const path = require("path")
3
- const queue = require("@rpcbase/server/queue")
4
-
5
-
6
- const register_worker_tasks = () => {
7
- const wd = process.cwd()
8
- const tasks_dir = path.join(wd, "./src/tasks/")
9
-
10
- const tasks_map = require(tasks_dir, "./index.js")
11
-
12
- for (const [task_name, task_path] of Object.entries(tasks_map)) {
13
- const task_fn = require(path.join(tasks_dir, task_path))
14
- queue.register_task(task_name, task_fn)
15
- }
16
-
17
- }
18
-
19
- register_worker_tasks()
@@ -1,73 +0,0 @@
1
- /* @flow */
2
- const fs = require("fs")
3
- const path = require("path")
4
- const glob = require("glob")
5
- const debug = require("debug")
6
-
7
-
8
- const log = debug("rb:rpc")
9
-
10
- const server_src_dir = path.join(process.cwd(), "./src/")
11
- const build_dir = path.join(process.cwd(), "build/")
12
- const client_dir = path.join(process.cwd(), "../../client/")
13
-
14
- const is_production = process.env.NODE_ENV === "production"
15
-
16
-
17
- const setup_prod_rpc_routes = (app) => {
18
- // the difference with the dev router is that routes are loaded at startup time, whereas in dev mode routes are resolved on each request
19
- const rpc_routes = glob.sync(path.join(build_dir, "./client/rpc/*"))
20
-
21
- rpc_routes.forEach((file_path) => {
22
- const basename = path.basename(file_path)
23
- const route_path = basename.replace(/__slash__/g, "/")
24
- const module_path = path.join(server_src_dir, `${route_path}.js`)
25
-
26
- // if module not found, remove created route file
27
- if (!fs.existsSync(module_path)) {
28
- fs.unlinkSync(file_path)
29
- console.log("removed inexistant rpc route", basename, "with module path", module_path)
30
- }
31
-
32
- const rpc_fn = require(module_path)
33
- app.post(`/rpc/${route_path}`, async(req, res) => {
34
-
35
- log(`POST /rpc/${route_path}`)
36
-
37
- // TODO: add jaegerclient / opentelemetry
38
- const result = await rpc_fn(req.body, {req, res})
39
- res.json(result)
40
- })
41
- })
42
- }
43
-
44
-
45
- const setup_dev_rpc_routes = (app) => {
46
- const rpc_routes = glob.sync(path.join(client_dir, "./build/rpc/*"))
47
-
48
- app.post("/rpc/*", async(req, res) => {
49
- const route_path = req.params[0]
50
-
51
- const module_path = path.join(server_src_dir, `${route_path}.js`)
52
-
53
- const rpc_fn = require(module_path)
54
- log(`POST /rpc/${route_path}`)
55
-
56
- // TODO: add jaegerclient / opentelemetry
57
- const result = await rpc_fn(req.body, {req, res})
58
- res.json(result)
59
- })
60
- }
61
-
62
-
63
- const rpc_router = (app) => {
64
-
65
- if (is_production) {
66
- setup_prod_rpc_routes(app)
67
- } else {
68
- setup_dev_rpc_routes(app)
69
- }
70
-
71
- }
72
-
73
- module.exports = rpc_router