@domain.js/main 0.6.0 → 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.
@@ -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
+ })();
@@ -90,17 +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
- const send = (res, results, isEventStream = false) => {
93
+ const send = async (res, results, isEventStream = false) => {
94
94
  if ("pipe" in results) {
95
- if (isEventStream)
95
+ if (isEventStream) {
96
96
  res.setHeader("Content-Type", "text/event-stream");
97
- results.pipe(res);
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
+ }
98
108
  }
99
109
  else {
100
110
  res.send(code, results);
101
111
  }
102
112
  };
103
- server[verb](route, async (req, res, next) => {
113
+ server[verb](route, async (req, res) => {
104
114
  const profile = makeProfile(req, methodPath, makeProfileHook);
105
115
  if (resource)
106
116
  profile.resource = resource;
@@ -139,15 +149,13 @@ function Router(deps) {
139
149
  }
140
150
  }
141
151
  else {
142
- send(res, code !== 204 && results, req.header("response-event-stream") === "yes");
152
+ await send(res, code !== 204 && results, req.header("response-event-stream") === "yes");
143
153
  }
144
154
  }
145
155
  catch (e) {
146
156
  res.header("X-ConsumedTime", Date.now() - profile.startedAt.valueOf());
147
- next(error2httpError(e));
148
- return;
157
+ throw error2httpError(e);
149
158
  }
150
- next();
151
159
  });
152
160
  }
153
161
  function RouterVerbFn(verb) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domain.js/main",
3
- "version": "0.6.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": "^8.6.0",
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",