@rpcbase/api 0.15.0 → 0.16.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/api",
3
- "version": "0.15.0",
3
+ "version": "0.16.0",
4
4
  "type": "module",
5
5
  "main": "./src/index.ts",
6
6
  "scripts": {
package/src/initApi.ts CHANGED
@@ -69,10 +69,22 @@ export const initApi = async (app: Application) => {
69
69
 
70
70
  const routeEntries = Object.entries(routes) as RouteModule[]
71
71
 
72
- const loadRoute = async([routePath, loadFn]: RouteModule) => {
72
+ const loadRoute = async ([routePath, loadFn]: RouteModule) => {
73
73
  const routeModule = await loadFn()
74
74
  routeModule.default(api)
75
- console.log("loaded api route", routePath)
75
+
76
+ let loggedPath = routePath.startsWith("../../")
77
+ ? routePath.replace("../../", "@rpcbase/")
78
+ : routePath
79
+
80
+ // Colorize output: gray for @rpcbase paths, default (white) otherwise
81
+ const GRAY = "\x1b[90m"
82
+ const RESET = "\x1b[0m"
83
+ const coloredPath = loggedPath.startsWith("@rpcbase/")
84
+ ? `${GRAY}${loggedPath}${RESET}`
85
+ : loggedPath
86
+
87
+ console.log("loaded api route", coloredPath)
76
88
  }
77
89
 
78
90
  await BBPromise.map(routeEntries, loadRoute)
package/src/loadModel.ts CHANGED
@@ -2,7 +2,7 @@ import assert from "assert"
2
2
  import mongoose from "mongoose"
3
3
  import { Ctx } from "./types"
4
4
 
5
- const { APP_NAME, DB_NAME } = process.env
5
+ const { APP_NAME, MONGO_PORT } = process.env
6
6
  const connections: Record<string, mongoose.Connection> = {}
7
7
 
8
8
  // @ts-ignore: Property 'glob' does not exist on type 'ImportMeta'.
@@ -39,10 +39,10 @@ export const loadModel = async (modelName: string, ctx: Ctx) => {
39
39
  assert(tenantId, "Tenant ID is missing from session")
40
40
 
41
41
  const dbName = ["User", "Tenant"].includes(modelName)
42
- ? `${APP_NAME}-users-${DB_NAME}`
43
- : `${APP_NAME}-${tenantId}-${DB_NAME}`
42
+ ? `${APP_NAME}-users-db`
43
+ : `${APP_NAME}-${tenantId}-db`
44
44
 
45
- const connectionString = `mongodb://localhost:27017/${dbName}`
45
+ const connectionString = `mongodb://localhost:${MONGO_PORT}/${dbName}`
46
46
 
47
47
  if (!connections[dbName]) {
48
48
  const connection = mongoose.createConnection(connectionString, {