@domain.js/main 0.5.3 → 0.6.1
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/dist/bin/server.d.ts +1 -0
- package/dist/bin/server.js +52 -0
- package/dist/http/defines.d.ts +2 -0
- package/dist/http/router.js +23 -5
- package/dist/http/utils.js +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const stream_1 = require("stream");
|
|
4
|
+
const http_1 = require("../http");
|
|
5
|
+
(async () => {
|
|
6
|
+
const services = {
|
|
7
|
+
"home.index": {
|
|
8
|
+
profile: {},
|
|
9
|
+
params: {},
|
|
10
|
+
method: async (profile, params) => {
|
|
11
|
+
return { profile, params };
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
stream: {
|
|
15
|
+
profile: {},
|
|
16
|
+
params: {},
|
|
17
|
+
method: async (profile, params) => {
|
|
18
|
+
class TimeStream extends stream_1.Readable {
|
|
19
|
+
constructor(options = {}) {
|
|
20
|
+
super(options);
|
|
21
|
+
this.count = 0;
|
|
22
|
+
this.timer = setInterval(() => {
|
|
23
|
+
this.push(new Date().toISOString() + "\n");
|
|
24
|
+
this.count++;
|
|
25
|
+
if (this.count === 5) {
|
|
26
|
+
clearInterval(this.timer);
|
|
27
|
+
this.push(null);
|
|
28
|
+
}
|
|
29
|
+
}, 1000);
|
|
30
|
+
}
|
|
31
|
+
_read() { }
|
|
32
|
+
}
|
|
33
|
+
const timeStream = new TimeStream();
|
|
34
|
+
timeStream.pipe(process.stdout);
|
|
35
|
+
return timeStream;
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
const routers = (r) => {
|
|
40
|
+
r.get("/", "home.index");
|
|
41
|
+
r.get("/stream", "stream");
|
|
42
|
+
};
|
|
43
|
+
const Start = (0, http_1.Main)({
|
|
44
|
+
port: 3009,
|
|
45
|
+
}, {
|
|
46
|
+
domain: services,
|
|
47
|
+
httpCodes: {},
|
|
48
|
+
routers,
|
|
49
|
+
});
|
|
50
|
+
const server = Start();
|
|
51
|
+
server.server.setTimeout(1000 * 60 * 5);
|
|
52
|
+
})();
|
package/dist/http/defines.d.ts
CHANGED
package/dist/http/router.js
CHANGED
|
@@ -90,7 +90,27 @@ function Router(deps) {
|
|
|
90
90
|
if (!method || !lodash_1.default.isFunction(method)) {
|
|
91
91
|
throw Error(`Missing domain method: ${methodPath}`);
|
|
92
92
|
}
|
|
93
|
-
|
|
93
|
+
const send = async (res, results, isEventStream = false) => {
|
|
94
|
+
if ("pipe" in results) {
|
|
95
|
+
if (isEventStream) {
|
|
96
|
+
res.setHeader("Content-Type", "text/event-stream");
|
|
97
|
+
await new Promise((resolve) => {
|
|
98
|
+
results.on("data", (chunk) => {
|
|
99
|
+
res.write(chunk);
|
|
100
|
+
});
|
|
101
|
+
results.on("end", resolve);
|
|
102
|
+
});
|
|
103
|
+
res.end();
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
results.pipe(res);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
res.send(code, results);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
server[verb](route, async (req, res) => {
|
|
94
114
|
const profile = makeProfile(req, methodPath, makeProfileHook);
|
|
95
115
|
if (resource)
|
|
96
116
|
profile.resource = resource;
|
|
@@ -129,15 +149,13 @@ function Router(deps) {
|
|
|
129
149
|
}
|
|
130
150
|
}
|
|
131
151
|
else {
|
|
132
|
-
|
|
152
|
+
await send(res, code !== 204 && results, req.header("response-event-stream") === "yes");
|
|
133
153
|
}
|
|
134
154
|
}
|
|
135
155
|
catch (e) {
|
|
136
156
|
res.header("X-ConsumedTime", Date.now() - profile.startedAt.valueOf());
|
|
137
|
-
|
|
138
|
-
return;
|
|
157
|
+
throw error2httpError(e);
|
|
139
158
|
}
|
|
140
|
-
next();
|
|
141
159
|
});
|
|
142
160
|
}
|
|
143
161
|
function RouterVerbFn(verb) {
|
package/dist/http/utils.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domain.js/main",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "DDD framework",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"lru-cache": "^6.0.0",
|
|
77
77
|
"moment": "^2.29.1",
|
|
78
78
|
"mysql2": "^2.3.3",
|
|
79
|
-
"restify": "^
|
|
79
|
+
"restify": "^11.1.0",
|
|
80
80
|
"restify-errors": "^8.0.2",
|
|
81
81
|
"sequelize": "^6.16.1",
|
|
82
82
|
"socket.io": "^4.4.1",
|