@paralect/hive 0.1.20 → 0.1.21
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
package/starter/src/db.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import _ from "lodash";
|
|
3
|
-
import requireDir from "require-dir";
|
|
4
3
|
import getSchemas from "helpers/getSchemas";
|
|
5
4
|
import getResources from "helpers/getResources";
|
|
5
|
+
import importHandlers from "helpers/importHandlers";
|
|
6
6
|
import config from "app-config";
|
|
7
7
|
import { connect } from "lib/node-mongo";
|
|
8
8
|
|
|
@@ -28,7 +28,7 @@ db.init = async () => {
|
|
|
28
28
|
}
|
|
29
29
|
db.schemas[schemaName] = schema;
|
|
30
30
|
db.services[schemaName] = db.createService(`${resourceName}`, {
|
|
31
|
-
validate: (obj) => {
|
|
31
|
+
validate: (obj) => {
|
|
32
32
|
return { value: schema.passthrough().parse(obj) };
|
|
33
33
|
},
|
|
34
34
|
});
|
|
@@ -37,15 +37,13 @@ db.init = async () => {
|
|
|
37
37
|
));
|
|
38
38
|
|
|
39
39
|
const resourcePaths = await getResources();
|
|
40
|
-
|
|
40
|
+
|
|
41
41
|
setTimeout(() => {
|
|
42
|
-
_.each(resourcePaths, ({
|
|
43
|
-
|
|
44
|
-
requireDir(`${dir}/handlers`);
|
|
45
|
-
}
|
|
42
|
+
_.each(resourcePaths, ({ name }) => {
|
|
43
|
+
importHandlers(name)
|
|
46
44
|
});
|
|
47
45
|
}, 0);
|
|
48
|
-
|
|
46
|
+
|
|
49
47
|
(await import("autoMap/addHandlers")).default();
|
|
50
48
|
(await import("autoMap/mapSchema")).default();
|
|
51
49
|
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import _ from 'lodash';
|
|
3
|
+
import requireDir from "require-dir";
|
|
4
|
+
|
|
5
|
+
export default (resourceName) => {
|
|
6
|
+
if (fs.existsSync(`${process.env.HIVE_SRC}/resources/${resourceName}/handlers`)) {
|
|
7
|
+
requireDir(`${process.env.HIVE_SRC}/resources/${resourceName}/handlers`, {
|
|
8
|
+
mapValue: (handler, handlerName) => {
|
|
9
|
+
console.log(
|
|
10
|
+
`[handlers] Registering handler ${handlerName}`
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
return handler;
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (fs.existsSync(`${__dirname}/../resources/${resourceName}/handlers`)) {
|
|
19
|
+
requireDir(`${__dirname}/../resources/${resourceName}/handlers`, {
|
|
20
|
+
mapValue: (handler, handlerName) => {
|
|
21
|
+
console.log(
|
|
22
|
+
`[handlers] Registering handler ${handlerName}`
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
return handler;
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
console.log('hello from handler');
|
|
@@ -96,6 +96,7 @@ export default async (app) => {
|
|
|
96
96
|
|
|
97
97
|
endpoints.forEach(({ endpoint, requestSchema, middlewares = [], handler }) => {
|
|
98
98
|
let targetRouter;
|
|
99
|
+
console.log('[routes] Register endpoint', resourceName, endpoint?.method || 'GET', endpoint?.url);
|
|
99
100
|
|
|
100
101
|
let url = endpoint.absoluteUrl || endpoint.url;
|
|
101
102
|
|