@domain.js/main 0.5.2 → 0.6.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/dist/http/defines.d.ts +2 -0
- package/dist/http/router.js +11 -1
- package/dist/http/socket.d.ts +1 -1
- package/dist/http/socket.js +9 -11
- package/dist/http/utils.js +1 -0
- package/package.json +1 -1
package/dist/http/defines.d.ts
CHANGED
package/dist/http/router.js
CHANGED
|
@@ -90,6 +90,16 @@ 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) => {
|
|
94
|
+
if ("pipe" in results) {
|
|
95
|
+
if (isEventStream)
|
|
96
|
+
res.setHeader("Content-Type", "text/event-stream");
|
|
97
|
+
results.pipe(res);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
res.send(code, results);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
93
103
|
server[verb](route, async (req, res, next) => {
|
|
94
104
|
const profile = makeProfile(req, methodPath, makeProfileHook);
|
|
95
105
|
if (resource)
|
|
@@ -129,7 +139,7 @@ function Router(deps) {
|
|
|
129
139
|
}
|
|
130
140
|
}
|
|
131
141
|
else {
|
|
132
|
-
|
|
142
|
+
send(res, code !== 204 && results, req.header("response-event-stream") === "yes");
|
|
133
143
|
}
|
|
134
144
|
}
|
|
135
145
|
catch (e) {
|
package/dist/http/socket.d.ts
CHANGED
|
@@ -15,6 +15,6 @@ export declare type Client = Socket<DefaultEventsMap, DefaultEventsMap, DefaultE
|
|
|
15
15
|
quit?: Function;
|
|
16
16
|
entranceOpts?: any[];
|
|
17
17
|
};
|
|
18
|
-
declare const makeProfile: (client: Client, type: string | undefined, auth: string | Signature, extra?: Profile["extra"]) => Profile;
|
|
18
|
+
declare const makeProfile: (client: Client, type: string | undefined, auth: string | Signature | undefined, extra?: Profile["extra"]) => Profile;
|
|
19
19
|
export declare function BridgeSocket(io: Server, domain: Domain): void;
|
|
20
20
|
export {};
|
package/dist/http/socket.js
CHANGED
|
@@ -58,13 +58,15 @@ const makeProfile = (client, type = "user", auth, extra = {}) => {
|
|
|
58
58
|
if (extra.uuid)
|
|
59
59
|
obj.uuid = extra.uuid;
|
|
60
60
|
}
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
if (auth) {
|
|
62
|
+
if (typeof auth === "string") {
|
|
63
|
+
obj.token = auth;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
obj.sign = auth;
|
|
67
|
+
obj.sign.uri = "/socket.io";
|
|
68
|
+
obj.sign.method = "socket.init";
|
|
69
|
+
}
|
|
68
70
|
}
|
|
69
71
|
return obj;
|
|
70
72
|
};
|
|
@@ -88,10 +90,6 @@ function BridgeSocket(io, domain) {
|
|
|
88
90
|
console.log("[%s] connection: client.id: %s", new Date(), client.id);
|
|
89
91
|
client.on("init", async (type, auth, extra = {}) => {
|
|
90
92
|
console.log("[%s] socket.init: client.id: %s", new Date(), client.id);
|
|
91
|
-
if (!auth) {
|
|
92
|
-
client.emit("initError", "auth info lost");
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
93
|
try {
|
|
96
94
|
Object.assign(client, { profile: makeProfile(client, type, auth, extra) });
|
|
97
95
|
if (!client.profile)
|
package/dist/http/utils.js
CHANGED