@dnax/core 0.76.0 → 0.76.2
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/define/index.ts +6 -0
- package/lib/router.ts +36 -0
- package/package.json +2 -2
- package/types/index.ts +1 -0
package/define/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type {
|
|
|
2
2
|
Collection,
|
|
3
3
|
Config,
|
|
4
4
|
Endpoint,
|
|
5
|
+
Router,
|
|
5
6
|
Service,
|
|
6
7
|
Socket,
|
|
7
8
|
accessCtx,
|
|
@@ -62,6 +63,10 @@ function Endpoint(config: Endpoint) {
|
|
|
62
63
|
return config;
|
|
63
64
|
}
|
|
64
65
|
|
|
66
|
+
function Router(config: Router) {
|
|
67
|
+
return config;
|
|
68
|
+
}
|
|
69
|
+
|
|
65
70
|
function Script(config: Script) {
|
|
66
71
|
config.ok = true;
|
|
67
72
|
return config;
|
|
@@ -140,6 +145,7 @@ const define = {
|
|
|
140
145
|
Permission,
|
|
141
146
|
Api,
|
|
142
147
|
Access,
|
|
148
|
+
Router,
|
|
143
149
|
Route,
|
|
144
150
|
Script,
|
|
145
151
|
TimeSeriesCollection,
|
package/lib/router.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { omit } from "radash";
|
|
2
|
+
import type { Collection, Endpoint, Field } from "./../types/index";
|
|
3
|
+
import { Glob } from "bun";
|
|
4
|
+
import { Cfg } from "../config";
|
|
5
|
+
import { cleanPath, resolvePath } from "../utils";
|
|
6
|
+
import path from "path";
|
|
7
|
+
import { useRest } from "../driver/mongo/rest";
|
|
8
|
+
|
|
9
|
+
async function loadRouters() {
|
|
10
|
+
let endpoints: Endpoint[] = [];
|
|
11
|
+
if (Cfg.tenants) {
|
|
12
|
+
for await (let t of Cfg.tenants) {
|
|
13
|
+
let tenantPath = `${t.dir}/routers/**/**.router.{ts,js}`;
|
|
14
|
+
const glob = new Glob(tenantPath);
|
|
15
|
+
for await (let file of glob.scan({
|
|
16
|
+
cwd: Cfg.cwd,
|
|
17
|
+
})) {
|
|
18
|
+
let fullPathFile = path.join(Cfg.cwd || "", file);
|
|
19
|
+
await import(fullPathFile)
|
|
20
|
+
.then((inject) => {
|
|
21
|
+
endpoints.push({
|
|
22
|
+
...inject?.default,
|
|
23
|
+
tenant_id: t.id,
|
|
24
|
+
});
|
|
25
|
+
})
|
|
26
|
+
.catch((err) => {
|
|
27
|
+
console.error(err);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
Cfg.endpoints = endpoints;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { loadRouters };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dnax/core",
|
|
3
|
-
"version": "0.76.
|
|
3
|
+
"version": "0.76.2",
|
|
4
4
|
"module": "index.ts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {},
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"dot-object": "2.1.5",
|
|
35
35
|
"fs-extra": "^11.2.0",
|
|
36
36
|
"generate-unique-id": "^2.0.3",
|
|
37
|
-
"hono": "4.10.
|
|
37
|
+
"hono": "4.10.4",
|
|
38
38
|
"joi": "17.13.3",
|
|
39
39
|
"json-joy": "16.8.0",
|
|
40
40
|
"jsonwebtoken": "^9.0.2",
|