typespeed 2.3.6 → 2.4.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/app/src/config-development.json +3 -2
- package/app/src/test-socket.class.ts +56 -0
- package/app/src/views/socket.html +23 -0
- package/dist/introduction/decorator/example-import.class.js +17 -0
- package/dist/introduction/decorator/main-app.js +14 -0
- package/dist/introduction/decorator/main-decorator.js +127 -0
- package/dist/introduction/decorator/main-import.js +1 -0
- package/dist/introduction/decorator/main-reflect.js +38 -0
- package/dist/introduction/web-services/db-init.js +33 -0
- package/dist/introduction/web-services/db-singleton.js +49 -0
- package/dist/introduction/web-services/http-if.js +12 -0
- package/dist/introduction/web-services/http-init.js +7 -0
- package/dist/introduction/web-services/http-router.js +23 -0
- package/dist/{database.decorator.js → src/database.decorator.js} +2 -4
- package/dist/{default → src/default}/express-server.class.js +20 -5
- package/dist/{default → src/default}/rabbitmq.class.js +3 -3
- package/dist/{default → src/default}/redis.class.js +1 -1
- package/dist/src/default/socket-io.class.js +64 -0
- package/dist/{typespeed.js → src/typespeed.js} +6 -3
- package/dist/typespeed.d.ts +19 -1
- package/package.json +8 -8
- package/src/database.decorator.ts +2 -4
- package/src/default/express-server.class.ts +18 -7
- package/src/default/rabbitmq.class.ts +3 -3
- package/src/default/redis.class.ts +1 -1
- package/src/default/socket-io.class.ts +68 -0
- package/src/factory/server-factory.class.ts +1 -1
- package/src/typespeed.d.ts +19 -1
- package/src/typespeed.ts +7 -4
- package/test/socket.test.ts +60 -0
- package/tsconfig.json +2 -1
- package/app/node_modules/.package-lock.json +0 -134
- package/app/node_modules/@types/body-parser/LICENSE +0 -21
- package/app/node_modules/@types/body-parser/README.md +0 -16
- package/app/node_modules/@types/body-parser/index.d.ts +0 -107
- package/app/node_modules/@types/body-parser/package.json +0 -58
- package/app/node_modules/@types/connect/LICENSE +0 -21
- package/app/node_modules/@types/connect/README.md +0 -16
- package/app/node_modules/@types/connect/index.d.ts +0 -93
- package/app/node_modules/@types/connect/package.json +0 -32
- package/app/node_modules/@types/express/LICENSE +0 -21
- package/app/node_modules/@types/express/README.md +0 -16
- package/app/node_modules/@types/express/index.d.ts +0 -136
- package/app/node_modules/@types/express/package.json +0 -45
- package/app/node_modules/@types/express-serve-static-core/LICENSE +0 -21
- package/app/node_modules/@types/express-serve-static-core/README.md +0 -16
- package/app/node_modules/@types/express-serve-static-core/index.d.ts +0 -1281
- package/app/node_modules/@types/express-serve-static-core/package.json +0 -55
- package/app/node_modules/@types/mime/LICENSE +0 -21
- package/app/node_modules/@types/mime/Mime.d.ts +0 -10
- package/app/node_modules/@types/mime/README.md +0 -16
- package/app/node_modules/@types/mime/index.d.ts +0 -35
- package/app/node_modules/@types/mime/lite.d.ts +0 -7
- package/app/node_modules/@types/mime/package.json +0 -29
- package/app/node_modules/@types/node/LICENSE +0 -21
- package/app/node_modules/@types/node/README.md +0 -16
- package/app/node_modules/@types/node/assert/strict.d.ts +0 -8
- package/app/node_modules/@types/node/assert.d.ts +0 -961
- package/app/node_modules/@types/node/async_hooks.d.ts +0 -518
- package/app/node_modules/@types/node/buffer.d.ts +0 -2323
- package/app/node_modules/@types/node/child_process.d.ts +0 -1399
- package/app/node_modules/@types/node/cluster.d.ts +0 -410
- package/app/node_modules/@types/node/console.d.ts +0 -412
- package/app/node_modules/@types/node/constants.d.ts +0 -18
- package/app/node_modules/@types/node/crypto.d.ts +0 -3973
- package/app/node_modules/@types/node/dgram.d.ts +0 -545
- package/app/node_modules/@types/node/diagnostics_channel.d.ts +0 -192
- package/app/node_modules/@types/node/dns/promises.d.ts +0 -370
- package/app/node_modules/@types/node/dns.d.ts +0 -660
- package/app/node_modules/@types/node/dom-events.d.ts +0 -126
- package/app/node_modules/@types/node/domain.d.ts +0 -170
- package/app/node_modules/@types/node/events.d.ts +0 -682
- package/app/node_modules/@types/node/fs/promises.d.ts +0 -1159
- package/app/node_modules/@types/node/fs.d.ts +0 -3976
- package/app/node_modules/@types/node/globals.d.ts +0 -303
- package/app/node_modules/@types/node/globals.global.d.ts +0 -1
- package/app/node_modules/@types/node/http.d.ts +0 -1714
- package/app/node_modules/@types/node/http2.d.ts +0 -2133
- package/app/node_modules/@types/node/https.d.ts +0 -542
- package/app/node_modules/@types/node/index.d.ts +0 -134
- package/app/node_modules/@types/node/inspector.d.ts +0 -2741
- package/app/node_modules/@types/node/module.d.ts +0 -115
- package/app/node_modules/@types/node/net.d.ts +0 -883
- package/app/node_modules/@types/node/os.d.ts +0 -473
- package/app/node_modules/@types/node/package.json +0 -237
- package/app/node_modules/@types/node/path.d.ts +0 -191
- package/app/node_modules/@types/node/perf_hooks.d.ts +0 -625
- package/app/node_modules/@types/node/process.d.ts +0 -1488
- package/app/node_modules/@types/node/punycode.d.ts +0 -117
- package/app/node_modules/@types/node/querystring.d.ts +0 -131
- package/app/node_modules/@types/node/readline/promises.d.ts +0 -143
- package/app/node_modules/@types/node/readline.d.ts +0 -653
- package/app/node_modules/@types/node/repl.d.ts +0 -424
- package/app/node_modules/@types/node/stream/consumers.d.ts +0 -12
- package/app/node_modules/@types/node/stream/promises.d.ts +0 -42
- package/app/node_modules/@types/node/stream/web.d.ts +0 -330
- package/app/node_modules/@types/node/stream.d.ts +0 -1440
- package/app/node_modules/@types/node/string_decoder.d.ts +0 -67
- package/app/node_modules/@types/node/test.d.ts +0 -783
- package/app/node_modules/@types/node/timers/promises.d.ts +0 -93
- package/app/node_modules/@types/node/timers.d.ts +0 -101
- package/app/node_modules/@types/node/tls.d.ts +0 -1111
- package/app/node_modules/@types/node/trace_events.d.ts +0 -171
- package/app/node_modules/@types/node/ts4.8/assert/strict.d.ts +0 -8
- package/app/node_modules/@types/node/ts4.8/assert.d.ts +0 -961
- package/app/node_modules/@types/node/ts4.8/async_hooks.d.ts +0 -518
- package/app/node_modules/@types/node/ts4.8/buffer.d.ts +0 -2323
- package/app/node_modules/@types/node/ts4.8/child_process.d.ts +0 -1399
- package/app/node_modules/@types/node/ts4.8/cluster.d.ts +0 -410
- package/app/node_modules/@types/node/ts4.8/console.d.ts +0 -412
- package/app/node_modules/@types/node/ts4.8/constants.d.ts +0 -18
- package/app/node_modules/@types/node/ts4.8/crypto.d.ts +0 -3972
- package/app/node_modules/@types/node/ts4.8/dgram.d.ts +0 -545
- package/app/node_modules/@types/node/ts4.8/diagnostics_channel.d.ts +0 -192
- package/app/node_modules/@types/node/ts4.8/dns/promises.d.ts +0 -370
- package/app/node_modules/@types/node/ts4.8/dns.d.ts +0 -660
- package/app/node_modules/@types/node/ts4.8/dom-events.d.ts +0 -126
- package/app/node_modules/@types/node/ts4.8/domain.d.ts +0 -170
- package/app/node_modules/@types/node/ts4.8/events.d.ts +0 -682
- package/app/node_modules/@types/node/ts4.8/fs/promises.d.ts +0 -1138
- package/app/node_modules/@types/node/ts4.8/fs.d.ts +0 -3875
- package/app/node_modules/@types/node/ts4.8/globals.d.ts +0 -302
- package/app/node_modules/@types/node/ts4.8/globals.global.d.ts +0 -1
- package/app/node_modules/@types/node/ts4.8/http.d.ts +0 -1651
- package/app/node_modules/@types/node/ts4.8/http2.d.ts +0 -2133
- package/app/node_modules/@types/node/ts4.8/https.d.ts +0 -542
- package/app/node_modules/@types/node/ts4.8/index.d.ts +0 -88
- package/app/node_modules/@types/node/ts4.8/inspector.d.ts +0 -2741
- package/app/node_modules/@types/node/ts4.8/module.d.ts +0 -115
- package/app/node_modules/@types/node/ts4.8/net.d.ts +0 -883
- package/app/node_modules/@types/node/ts4.8/os.d.ts +0 -473
- package/app/node_modules/@types/node/ts4.8/path.d.ts +0 -191
- package/app/node_modules/@types/node/ts4.8/perf_hooks.d.ts +0 -625
- package/app/node_modules/@types/node/ts4.8/process.d.ts +0 -1488
- package/app/node_modules/@types/node/ts4.8/punycode.d.ts +0 -117
- package/app/node_modules/@types/node/ts4.8/querystring.d.ts +0 -131
- package/app/node_modules/@types/node/ts4.8/readline/promises.d.ts +0 -143
- package/app/node_modules/@types/node/ts4.8/readline.d.ts +0 -653
- package/app/node_modules/@types/node/ts4.8/repl.d.ts +0 -424
- package/app/node_modules/@types/node/ts4.8/stream/consumers.d.ts +0 -12
- package/app/node_modules/@types/node/ts4.8/stream/promises.d.ts +0 -42
- package/app/node_modules/@types/node/ts4.8/stream/web.d.ts +0 -330
- package/app/node_modules/@types/node/ts4.8/stream.d.ts +0 -1440
- package/app/node_modules/@types/node/ts4.8/string_decoder.d.ts +0 -67
- package/app/node_modules/@types/node/ts4.8/test.d.ts +0 -784
- package/app/node_modules/@types/node/ts4.8/timers/promises.d.ts +0 -93
- package/app/node_modules/@types/node/ts4.8/timers.d.ts +0 -94
- package/app/node_modules/@types/node/ts4.8/tls.d.ts +0 -1111
- package/app/node_modules/@types/node/ts4.8/trace_events.d.ts +0 -171
- package/app/node_modules/@types/node/ts4.8/tty.d.ts +0 -206
- package/app/node_modules/@types/node/ts4.8/url.d.ts +0 -902
- package/app/node_modules/@types/node/ts4.8/util.d.ts +0 -2017
- package/app/node_modules/@types/node/ts4.8/v8.d.ts +0 -541
- package/app/node_modules/@types/node/ts4.8/vm.d.ts +0 -644
- package/app/node_modules/@types/node/ts4.8/wasi.d.ts +0 -158
- package/app/node_modules/@types/node/ts4.8/worker_threads.d.ts +0 -695
- package/app/node_modules/@types/node/ts4.8/zlib.d.ts +0 -517
- package/app/node_modules/@types/node/tty.d.ts +0 -206
- package/app/node_modules/@types/node/url.d.ts +0 -902
- package/app/node_modules/@types/node/util.d.ts +0 -2017
- package/app/node_modules/@types/node/v8.d.ts +0 -541
- package/app/node_modules/@types/node/vm.d.ts +0 -644
- package/app/node_modules/@types/node/wasi.d.ts +0 -158
- package/app/node_modules/@types/node/worker_threads.d.ts +0 -695
- package/app/node_modules/@types/node/zlib.d.ts +0 -517
- package/app/node_modules/@types/qs/LICENSE +0 -21
- package/app/node_modules/@types/qs/README.md +0 -16
- package/app/node_modules/@types/qs/index.d.ts +0 -62
- package/app/node_modules/@types/qs/package.json +0 -65
- package/app/node_modules/@types/range-parser/LICENSE +0 -21
- package/app/node_modules/@types/range-parser/README.md +0 -55
- package/app/node_modules/@types/range-parser/index.d.ts +0 -35
- package/app/node_modules/@types/range-parser/package.json +0 -25
- package/app/node_modules/@types/send/LICENSE +0 -21
- package/app/node_modules/@types/send/README.md +0 -16
- package/app/node_modules/@types/send/index.d.ts +0 -231
- package/app/node_modules/@types/send/package.json +0 -33
- package/app/node_modules/@types/serve-static/LICENSE +0 -21
- package/app/node_modules/@types/serve-static/README.md +0 -16
- package/app/node_modules/@types/serve-static/index.d.ts +0 -113
- package/app/node_modules/@types/serve-static/package.json +0 -38
- package/app/node_modules/colors/LICENSE +0 -25
- package/app/node_modules/colors/README.md +0 -221
- package/app/node_modules/colors/examples/normal-usage.js +0 -82
- package/app/node_modules/colors/examples/safe-string.js +0 -79
- package/app/node_modules/colors/index.d.ts +0 -136
- package/app/node_modules/colors/lib/colors.js +0 -211
- package/app/node_modules/colors/lib/custom/trap.js +0 -46
- package/app/node_modules/colors/lib/custom/zalgo.js +0 -110
- package/app/node_modules/colors/lib/extendStringPrototype.js +0 -110
- package/app/node_modules/colors/lib/index.js +0 -13
- package/app/node_modules/colors/lib/maps/america.js +0 -10
- package/app/node_modules/colors/lib/maps/rainbow.js +0 -12
- package/app/node_modules/colors/lib/maps/random.js +0 -11
- package/app/node_modules/colors/lib/maps/zebra.js +0 -5
- package/app/node_modules/colors/lib/styles.js +0 -95
- package/app/node_modules/colors/lib/system/has-flag.js +0 -35
- package/app/node_modules/colors/lib/system/supports-colors.js +0 -151
- package/app/node_modules/colors/package.json +0 -45
- package/app/node_modules/colors/safe.d.ts +0 -48
- package/app/node_modules/colors/safe.js +0 -10
- package/app/node_modules/colors/themes/generic-logging.js +0 -12
- package/app/node_modules/dateformat/LICENSE +0 -20
- package/app/node_modules/dateformat/Readme.md +0 -204
- package/app/node_modules/dateformat/lib/dateformat.js +0 -1
- package/app/node_modules/dateformat/package.json +0 -38
- package/app/node_modules/mkdirp/CHANGELOG.md +0 -15
- package/app/node_modules/mkdirp/LICENSE +0 -21
- package/app/node_modules/mkdirp/bin/cmd.js +0 -68
- package/app/node_modules/mkdirp/index.js +0 -31
- package/app/node_modules/mkdirp/lib/find-made.js +0 -29
- package/app/node_modules/mkdirp/lib/mkdirp-manual.js +0 -64
- package/app/node_modules/mkdirp/lib/mkdirp-native.js +0 -39
- package/app/node_modules/mkdirp/lib/opts-arg.js +0 -23
- package/app/node_modules/mkdirp/lib/path-arg.js +0 -29
- package/app/node_modules/mkdirp/lib/use-native.js +0 -10
- package/app/node_modules/mkdirp/package.json +0 -44
- package/app/node_modules/mkdirp/readme.markdown +0 -266
- package/app/node_modules/tinytim/.travis.yml +0 -5
- package/app/node_modules/tinytim/README.md +0 -212
- package/app/node_modules/tinytim/index.js +0 -1
- package/app/node_modules/tinytim/lib/index.js +0 -55
- package/app/node_modules/tinytim/lib/tinytim.js +0 -50
- package/app/node_modules/tinytim/package.json +0 -24
- package/app/node_modules/tinytim/test/files/html.tim +0 -1
- package/app/node_modules/tinytim/test/files/string.tim +0 -1
- package/app/node_modules/tinytim/test/files/string2.tim +0 -1
- package/app/node_modules/tinytim/test/render-file-replace.js +0 -39
- package/app/node_modules/tinytim/test/render-replace.js +0 -94
- package/app/node_modules/tinytim/test/tim-replace.js +0 -95
- package/app/node_modules/tracer/README.md +0 -747
- package/app/node_modules/tracer/lib/color_console.js +0 -15
- package/app/node_modules/tracer/lib/console.js +0 -165
- package/app/node_modules/tracer/lib/dailyfile.js +0 -92
- package/app/node_modules/tracer/lib/index.js +0 -10
- package/app/node_modules/tracer/lib/settings.js +0 -25
- package/app/node_modules/tracer/lib/utils.js +0 -58
- package/app/node_modules/tracer/package.json +0 -53
- package/app/node_modules/tracer/types/index.d.ts +0 -189
- package/dist/scaffold/templates/front-page.class.ts.tpl +0 -12
- package/dist/scaffold/templates/main.ts.tpl +0 -13
- package/dist/scaffold/templates/nodemon.json.tpl +0 -7
- package/dist/scaffold/templates/package.json.tpl +0 -16
- package/dist/scaffold/templates/tsconfig.json.tpl +0 -20
- /package/dist/{core.decorator.js → src/core.decorator.js} +0 -0
- /package/dist/{default → src/default}/default-authentication.class.js +0 -0
- /package/dist/{default → src/default}/log-default.class.js +0 -0
- /package/dist/{default → src/default}/node-cache.class.js +0 -0
- /package/dist/{default → src/default}/pages/404.html +0 -0
- /package/dist/{default → src/default}/pages/500.html +0 -0
- /package/dist/{default → src/default}/read-write-db.class.js +0 -0
- /package/dist/{factory → src/factory}/authentication-factory.class.js +0 -0
- /package/dist/{factory → src/factory}/cache-factory.class.js +0 -0
- /package/dist/{factory → src/factory}/data-source-factory.class.js +0 -0
- /package/dist/{factory → src/factory}/log-factory.class.js +0 -0
- /package/dist/{factory → src/factory}/server-factory.class.js +0 -0
- /package/dist/{route.decorator.js → src/route.decorator.js} +0 -0
- /package/dist/{scaffold → src/scaffold}/command.js +0 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { SocketIo, getMapping, component, io } from "../../src/typespeed";
|
|
2
|
+
|
|
3
|
+
@component
|
|
4
|
+
export default class TestSocket {
|
|
5
|
+
|
|
6
|
+
static names = ["LiLei", "HanMeiMei"];
|
|
7
|
+
|
|
8
|
+
static loginUsers: Map<string, string> = new Map<string, string>();
|
|
9
|
+
|
|
10
|
+
@SocketIo.onConnected
|
|
11
|
+
public connected(socket, next) {
|
|
12
|
+
// 从 names 里面取出一个名字
|
|
13
|
+
let name = TestSocket.names.pop();
|
|
14
|
+
TestSocket.loginUsers.set(socket.id, name);
|
|
15
|
+
//io.sockets.emit("all", "We have a new member: " + name);
|
|
16
|
+
//console.log(socket.handshake);
|
|
17
|
+
//console.log(socket.id);
|
|
18
|
+
//next(new Error("test-error"));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@SocketIo.onDisconnect
|
|
22
|
+
public disconnet(socket, reason) {
|
|
23
|
+
io.sockets.emit("all", "We lost a member by: " + reason);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@SocketIo.onEvent("test-error")
|
|
27
|
+
public testError(socket, message) {
|
|
28
|
+
throw new Error("test-error");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@SocketIo.onError
|
|
32
|
+
public error(socket, err) {
|
|
33
|
+
io.sockets.emit("all", "We have a problem!");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@SocketIo.onEvent("say")
|
|
37
|
+
public say(socket, message) {
|
|
38
|
+
io.sockets.emit("all", TestSocket.loginUsers.get(socket.id) + " said: " + message);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@SocketIo.onEvent("join")
|
|
42
|
+
public join(socket, message) {
|
|
43
|
+
socket.join("private-room");
|
|
44
|
+
io.to("private-room").emit("all", TestSocket.loginUsers.get(socket.id) + " joined private-room");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@SocketIo.onEvent("say-inroom")
|
|
48
|
+
public sayInRoom(socket, message) {
|
|
49
|
+
io.to("private-room").emit("all", TestSocket.loginUsers.get(socket.id) + " said in Room: " + message);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@getMapping("/socketIo")
|
|
53
|
+
public socketIoPage(req, res) {
|
|
54
|
+
res.render("socket");
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<html>
|
|
2
|
+
|
|
3
|
+
<head>
|
|
4
|
+
<title>Socket Test</title>
|
|
5
|
+
<script src="https://cdn.socket.io/4.7.1/socket.io.min.js"></script>
|
|
6
|
+
<script>
|
|
7
|
+
var socket = io('http://localhost:8081');
|
|
8
|
+
socket.on('connect', function() {
|
|
9
|
+
console.log('connected');
|
|
10
|
+
});
|
|
11
|
+
socket.on('all', function(data) {
|
|
12
|
+
console.log(data);
|
|
13
|
+
});
|
|
14
|
+
</script>
|
|
15
|
+
</head>
|
|
16
|
+
<body>
|
|
17
|
+
<button onclick="socket.emit('say', 'I say some thing')">TestSay</button>
|
|
18
|
+
<button onclick="socket.emit('join', 'I want to join the room')">Join</button>
|
|
19
|
+
<button onclick="socket.emit('say-inroom', 'say some in room')">InRoom</button>
|
|
20
|
+
<button onclick="socket.emit('test-error', 'this is a error')">Test Error</button>
|
|
21
|
+
<button onclick="socket.close()">Close</button>
|
|
22
|
+
</body>
|
|
23
|
+
</html>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
let ExampleImport = class ExampleImport {
|
|
10
|
+
};
|
|
11
|
+
ExampleImport = __decorate([
|
|
12
|
+
app
|
|
13
|
+
], ExampleImport);
|
|
14
|
+
exports.default = ExampleImport;
|
|
15
|
+
function app(target) {
|
|
16
|
+
console.log("import 载入 ExampleImport 类的 @app 类装饰器。");
|
|
17
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
let MainApp = class MainApp {
|
|
8
|
+
};
|
|
9
|
+
MainApp = __decorate([
|
|
10
|
+
app
|
|
11
|
+
], MainApp);
|
|
12
|
+
function app(target) {
|
|
13
|
+
console.log("执行 @app 类装饰器");
|
|
14
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
require("reflect-metadata");
|
|
16
|
+
let SecondClass = class SecondClass {
|
|
17
|
+
};
|
|
18
|
+
SecondClass = __decorate([
|
|
19
|
+
atClassWithArgs(1, 2, 3)
|
|
20
|
+
], SecondClass);
|
|
21
|
+
let FirstClass = class FirstClass {
|
|
22
|
+
get newname() {
|
|
23
|
+
return this.name;
|
|
24
|
+
}
|
|
25
|
+
changeName(name) {
|
|
26
|
+
this.name = name;
|
|
27
|
+
return new SecondClass();
|
|
28
|
+
}
|
|
29
|
+
change(name, age) {
|
|
30
|
+
this.age = age;
|
|
31
|
+
this.name = name;
|
|
32
|
+
}
|
|
33
|
+
getName() {
|
|
34
|
+
return this.name;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
__decorate([
|
|
38
|
+
atPropertyWithArgs("Li", "Mei"),
|
|
39
|
+
__metadata("design:type", String)
|
|
40
|
+
], FirstClass.prototype, "name", void 0);
|
|
41
|
+
__decorate([
|
|
42
|
+
atProperty,
|
|
43
|
+
__metadata("design:type", Number)
|
|
44
|
+
], FirstClass.prototype, "age", void 0);
|
|
45
|
+
__decorate([
|
|
46
|
+
atAccessor,
|
|
47
|
+
__metadata("design:type", String),
|
|
48
|
+
__metadata("design:paramtypes", [])
|
|
49
|
+
], FirstClass.prototype, "newname", null);
|
|
50
|
+
__decorate([
|
|
51
|
+
atMethod,
|
|
52
|
+
__metadata("design:type", Function),
|
|
53
|
+
__metadata("design:paramtypes", [String]),
|
|
54
|
+
__metadata("design:returntype", SecondClass)
|
|
55
|
+
], FirstClass.prototype, "changeName", null);
|
|
56
|
+
__decorate([
|
|
57
|
+
atMethodWithArgs("New", "Type"),
|
|
58
|
+
__param(1, atParameter),
|
|
59
|
+
__metadata("design:type", Function),
|
|
60
|
+
__metadata("design:paramtypes", [String, Number]),
|
|
61
|
+
__metadata("design:returntype", void 0)
|
|
62
|
+
], FirstClass.prototype, "change", null);
|
|
63
|
+
FirstClass = __decorate([
|
|
64
|
+
atClass
|
|
65
|
+
], FirstClass);
|
|
66
|
+
exports.default = FirstClass;
|
|
67
|
+
const obj = new FirstClass();
|
|
68
|
+
console.log("FirstClass对象调用getName()取得装饰器赋值:", obj.getName());
|
|
69
|
+
// 类装饰器
|
|
70
|
+
function atClass(target) {
|
|
71
|
+
console.log("类装饰器,类名是:", target.name);
|
|
72
|
+
}
|
|
73
|
+
// 类装饰器,带参数
|
|
74
|
+
function atClassWithArgs(...args) {
|
|
75
|
+
return function (target) {
|
|
76
|
+
console.log("类装饰器有参数,参数值:", args.join(","));
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
// 方法装饰器
|
|
80
|
+
function atMethod(target, propertyKey) {
|
|
81
|
+
const returnType = Reflect.getMetadata("design:returntype", target, propertyKey);
|
|
82
|
+
console.log("方法装饰器,获得返回类型:", returnType.name);
|
|
83
|
+
}
|
|
84
|
+
// 方法装饰器,带参数
|
|
85
|
+
function atMethodWithArgs(...args) {
|
|
86
|
+
return function (target, propertyKey) {
|
|
87
|
+
console.log("方法装饰器有参数,参数值:", args.join(","));
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
// 成员变量装饰器
|
|
91
|
+
function atProperty(target, propertyKey) {
|
|
92
|
+
const propertyType = Reflect.getMetadata("design:type", target, propertyKey);
|
|
93
|
+
console.log("变量装饰器,获得变量类型:", propertyType.name);
|
|
94
|
+
}
|
|
95
|
+
// 成员变量装饰器,带参数
|
|
96
|
+
function atPropertyWithArgs(...args) {
|
|
97
|
+
return function (target, propertyKey) {
|
|
98
|
+
console.log("变量装饰器有参数,参数值:", args.join(","));
|
|
99
|
+
Object.defineProperty(target, propertyKey, {
|
|
100
|
+
get: () => {
|
|
101
|
+
return args;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
// 访问器装饰器
|
|
107
|
+
function atAccessor(target, propertyKey, descriptor) {
|
|
108
|
+
const returnType = Reflect.getMetadata("design:type", target, propertyKey);
|
|
109
|
+
console.log("访问器装饰器,访问器类型是:", returnType, ",值是:", target[propertyKey]);
|
|
110
|
+
}
|
|
111
|
+
// 访问器装饰器,带参数
|
|
112
|
+
function atAccessorWithArgs(...args) {
|
|
113
|
+
return function (target, propertyKey, descriptor) {
|
|
114
|
+
console.log("访问器装饰器,参数值:", args.join(","));
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
// 参数装饰器
|
|
118
|
+
function atParameter(target, propertyKey, parameterIndex) {
|
|
119
|
+
const parameterType = Reflect.getMetadata("design:paramtypes", target, propertyKey);
|
|
120
|
+
console.log("参数装饰器,参数位置在:", parameterIndex, "参数类型是:", parameterType[parameterIndex].name);
|
|
121
|
+
}
|
|
122
|
+
// 参数装饰器,带参数
|
|
123
|
+
function atParameterWithArgs(...args) {
|
|
124
|
+
return function (target, propertyKey, parameterIndex) {
|
|
125
|
+
console.log("参数装饰器有参数,参数值:", args.join(","));
|
|
126
|
+
};
|
|
127
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Promise.resolve().then(() => require("./example-import.class"));
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
require("reflect-metadata");
|
|
13
|
+
class MainReflect {
|
|
14
|
+
getAge() {
|
|
15
|
+
return this.age;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
__decorate([
|
|
19
|
+
injectAge(10),
|
|
20
|
+
__metadata("design:type", Number)
|
|
21
|
+
], MainReflect.prototype, "age", void 0);
|
|
22
|
+
__decorate([
|
|
23
|
+
findReturn,
|
|
24
|
+
__metadata("design:type", Function),
|
|
25
|
+
__metadata("design:paramtypes", []),
|
|
26
|
+
__metadata("design:returntype", Number)
|
|
27
|
+
], MainReflect.prototype, "getAge", null);
|
|
28
|
+
const mainReflect = new MainReflect();
|
|
29
|
+
console.log("获得Age值:", mainReflect.getAge());
|
|
30
|
+
function injectAge(arg) {
|
|
31
|
+
return function (target, propertyKey) {
|
|
32
|
+
Object.defineProperty(target, propertyKey, { get: () => { return arg; } });
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function findReturn(target, propertyKey) {
|
|
36
|
+
const returnType = Reflect.getMetadata("design:returntype", target, propertyKey);
|
|
37
|
+
console.log(target[propertyKey].name, "的返回类型是:", returnType.name);
|
|
38
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const http_1 = require("http");
|
|
4
|
+
const mysql2_1 = require("mysql2");
|
|
5
|
+
class First {
|
|
6
|
+
page(response) {
|
|
7
|
+
response.end("I am first page.");
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
class User {
|
|
11
|
+
page(response) {
|
|
12
|
+
const connection = (0, mysql2_1.createConnection)({ host: 'localhost', user: 'root', "password": "qwer1234", database: 'test' });
|
|
13
|
+
connection.query('SELECT * FROM `user`', (err, results) => {
|
|
14
|
+
response.end(JSON.stringify(results));
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
class Root {
|
|
19
|
+
page(response) {
|
|
20
|
+
response.end("I am main page.");
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const router = new Map();
|
|
24
|
+
router.set("/first", new First());
|
|
25
|
+
router.set("/main", new Root());
|
|
26
|
+
router.set("/user", new User());
|
|
27
|
+
const server = (0, http_1.createServer)((request, response) => {
|
|
28
|
+
let page = router.get(request.url === undefined ? "" : request.url);
|
|
29
|
+
if (page === undefined) {
|
|
30
|
+
page = new Root();
|
|
31
|
+
}
|
|
32
|
+
page.page(response);
|
|
33
|
+
}).listen(3000);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const http_1 = require("http");
|
|
4
|
+
const mysql2_1 = require("mysql2");
|
|
5
|
+
class First {
|
|
6
|
+
page(response) {
|
|
7
|
+
response.end("I am first page.");
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
class User {
|
|
11
|
+
page(response) {
|
|
12
|
+
const database = Database.getInstance();
|
|
13
|
+
const databaseCopy = Database.getInstance();
|
|
14
|
+
console.log("两个对象是否一致:", database === databaseCopy);
|
|
15
|
+
database.query('SELECT * FROM `user`', (err, results) => {
|
|
16
|
+
response.end(JSON.stringify(results));
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
class Root {
|
|
21
|
+
page(response) {
|
|
22
|
+
response.end("I am main page.");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
class Database {
|
|
26
|
+
constructor(connection) {
|
|
27
|
+
this.connection = connection;
|
|
28
|
+
}
|
|
29
|
+
static getInstance() {
|
|
30
|
+
if (!Database.instance) {
|
|
31
|
+
Database.instance = new Database((0, mysql2_1.createConnection)({ host: 'localhost', user: 'root', "password": "qwer1234", database: 'test' }));
|
|
32
|
+
}
|
|
33
|
+
return Database.instance;
|
|
34
|
+
}
|
|
35
|
+
query(sql, callback) {
|
|
36
|
+
this.connection.query('SELECT * FROM `user`', callback);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const router = new Map();
|
|
40
|
+
router.set("/first", new First());
|
|
41
|
+
router.set("/main", new Root());
|
|
42
|
+
router.set("/user", new User());
|
|
43
|
+
const server = (0, http_1.createServer)((request, response) => {
|
|
44
|
+
let page = router.get(request.url === undefined ? "" : request.url);
|
|
45
|
+
if (page === undefined) {
|
|
46
|
+
page = new Root();
|
|
47
|
+
}
|
|
48
|
+
page.page(response);
|
|
49
|
+
}).listen(3000);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const http_1 = require("http");
|
|
4
|
+
// 使用 IF 语句来判断请求的 URL
|
|
5
|
+
const server = (0, http_1.createServer)((request, response) => {
|
|
6
|
+
if (request.url === "/first") {
|
|
7
|
+
response.end("I am first page.");
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
response.end("I am main page.");
|
|
11
|
+
}
|
|
12
|
+
}).listen(3000);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const http_1 = require("http");
|
|
4
|
+
class First {
|
|
5
|
+
page(response) {
|
|
6
|
+
response.end("I am first page.");
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
class Root {
|
|
10
|
+
page(response) {
|
|
11
|
+
response.end("I am main page.");
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const router = new Map();
|
|
15
|
+
router.set("/first", new First());
|
|
16
|
+
router.set("/main", new Root());
|
|
17
|
+
const server = (0, http_1.createServer)((request, response) => {
|
|
18
|
+
let page = router.get(request.url === undefined ? "" : request.url);
|
|
19
|
+
if (page === undefined) {
|
|
20
|
+
page = new Root();
|
|
21
|
+
}
|
|
22
|
+
page.page(response);
|
|
23
|
+
}).listen(3000);
|
|
@@ -305,13 +305,11 @@ class Model {
|
|
|
305
305
|
}
|
|
306
306
|
else {
|
|
307
307
|
const operatorTemplate = { $lt: "<", $lte: "<=", $gt: ">", $gte: ">=", $ne: "!=", $like: "LIKE" };
|
|
308
|
-
|
|
309
|
-
Object.keys(conditions[field]).map((operator) => {
|
|
308
|
+
Object.keys(conditions[field]).map((operator, index) => {
|
|
310
309
|
if (operatorTemplate[operator]) {
|
|
311
310
|
const operatorValue = operatorTemplate[operator];
|
|
312
|
-
result["sql"] +=
|
|
311
|
+
result["sql"] += (index ? " AND " : "") + ` ${field} ${operatorValue} ? `;
|
|
313
312
|
result["values"].push(conditions[field][operator]);
|
|
314
|
-
firstCondition = false;
|
|
315
313
|
}
|
|
316
314
|
});
|
|
317
315
|
}
|
|
@@ -19,6 +19,7 @@ const expressSession = require("express-session");
|
|
|
19
19
|
const connectRedis = require("connect-redis");
|
|
20
20
|
const server_factory_class_1 = require("../factory/server-factory.class");
|
|
21
21
|
const route_decorator_1 = require("../route.decorator");
|
|
22
|
+
const socket_io_class_1 = require("../default/socket-io.class");
|
|
22
23
|
const typespeed_1 = require("../typespeed");
|
|
23
24
|
const core_decorator_1 = require("../core.decorator");
|
|
24
25
|
const redis_class_1 = require("./redis.class");
|
|
@@ -32,12 +33,18 @@ class ExpressServer extends server_factory_class_1.default {
|
|
|
32
33
|
setMiddleware(middleware) {
|
|
33
34
|
this.middlewareList.push(middleware);
|
|
34
35
|
}
|
|
35
|
-
start(port
|
|
36
|
+
start(port) {
|
|
36
37
|
this.middlewareList.forEach(middleware => {
|
|
37
38
|
this.app.use(middleware);
|
|
38
39
|
});
|
|
39
40
|
this.setDefaultMiddleware();
|
|
40
|
-
|
|
41
|
+
if (this.socketIoConfig) {
|
|
42
|
+
const newSocketApp = socket_io_class_1.SocketIo.setIoServer(this.app, this.socketIoConfig);
|
|
43
|
+
return newSocketApp.listen(port);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
return this.app.listen(port);
|
|
47
|
+
}
|
|
41
48
|
}
|
|
42
49
|
setDefaultMiddleware() {
|
|
43
50
|
this.app.use(express.urlencoded({ extended: true }));
|
|
@@ -46,7 +53,7 @@ class ExpressServer extends server_factory_class_1.default {
|
|
|
46
53
|
const viewConfig = this.view;
|
|
47
54
|
this.app.engine(viewConfig["suffix"], consolidate[viewConfig["engine"]]);
|
|
48
55
|
this.app.set('view engine', viewConfig["suffix"]);
|
|
49
|
-
this.app.set('views',
|
|
56
|
+
this.app.set('views', this.mainPath + viewConfig["path"]);
|
|
50
57
|
}
|
|
51
58
|
if (this.session) {
|
|
52
59
|
const sessionConfig = this.session;
|
|
@@ -60,7 +67,7 @@ class ExpressServer extends server_factory_class_1.default {
|
|
|
60
67
|
this.app.use(expressSession(sessionConfig));
|
|
61
68
|
}
|
|
62
69
|
if (this.favicon) {
|
|
63
|
-
const faviconPath =
|
|
70
|
+
const faviconPath = this.mainPath + this.favicon;
|
|
64
71
|
this.app.use(serveFavicon(faviconPath));
|
|
65
72
|
}
|
|
66
73
|
if (this.compression) {
|
|
@@ -71,7 +78,7 @@ class ExpressServer extends server_factory_class_1.default {
|
|
|
71
78
|
}
|
|
72
79
|
this.app.use(this.authentication.preHandle);
|
|
73
80
|
if (this.static) {
|
|
74
|
-
const staticPath =
|
|
81
|
+
const staticPath = this.mainPath + this.static;
|
|
75
82
|
this.app.use(express.static(staticPath));
|
|
76
83
|
}
|
|
77
84
|
(0, route_decorator_1.setRouter)(this.app);
|
|
@@ -136,6 +143,14 @@ __decorate([
|
|
|
136
143
|
(0, typespeed_1.value)("redis"),
|
|
137
144
|
__metadata("design:type", Object)
|
|
138
145
|
], ExpressServer.prototype, "redisConfig", void 0);
|
|
146
|
+
__decorate([
|
|
147
|
+
(0, typespeed_1.value)("socket"),
|
|
148
|
+
__metadata("design:type", Object)
|
|
149
|
+
], ExpressServer.prototype, "socketIoConfig", void 0);
|
|
150
|
+
__decorate([
|
|
151
|
+
(0, typespeed_1.value)("MAIN_PATH"),
|
|
152
|
+
__metadata("design:type", String)
|
|
153
|
+
], ExpressServer.prototype, "mainPath", void 0);
|
|
139
154
|
__decorate([
|
|
140
155
|
core_decorator_1.autoware,
|
|
141
156
|
__metadata("design:type", redis_class_1.Redis)
|
|
@@ -23,13 +23,13 @@ class RabbitMQ {
|
|
|
23
23
|
}
|
|
24
24
|
async publishMessageToExchange(exchange, routingKey, message) {
|
|
25
25
|
const channel = await getChannel();
|
|
26
|
-
await channel.
|
|
26
|
+
await channel.assertExchange(exchange);
|
|
27
27
|
channel.publish(exchange, routingKey, Buffer.from(message));
|
|
28
28
|
await channel.close();
|
|
29
29
|
}
|
|
30
30
|
async sendMessageToQueue(queue, message) {
|
|
31
31
|
const channel = await getChannel();
|
|
32
|
-
await channel.
|
|
32
|
+
await channel.accertQueue(queue);
|
|
33
33
|
channel.sendToQueue(queue, Buffer.from(message));
|
|
34
34
|
await channel.close();
|
|
35
35
|
}
|
|
@@ -61,7 +61,7 @@ function rabbitListener(queue) {
|
|
|
61
61
|
return (target, propertyKey) => {
|
|
62
62
|
(async function () {
|
|
63
63
|
const channel = await getChannel();
|
|
64
|
-
await channel.
|
|
64
|
+
await channel.assertQueue(queue);
|
|
65
65
|
await channel.consume(queue, target[propertyKey], { noAck: true });
|
|
66
66
|
}());
|
|
67
67
|
};
|
|
@@ -14,7 +14,7 @@ const core_decorator_1 = require("../core.decorator");
|
|
|
14
14
|
const ioredis_1 = require("ioredis");
|
|
15
15
|
const typespeed_1 = require("../typespeed");
|
|
16
16
|
const redisSubscribers = {};
|
|
17
|
-
class Redis extends ioredis_1.
|
|
17
|
+
class Redis extends ioredis_1.default {
|
|
18
18
|
getRedis() {
|
|
19
19
|
return Redis.getInstanceOfRedis("pub");
|
|
20
20
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.io = exports.SocketIo = void 0;
|
|
4
|
+
const socket_io_1 = require("socket.io");
|
|
5
|
+
const http_1 = require("http");
|
|
6
|
+
let io = null;
|
|
7
|
+
exports.io = io;
|
|
8
|
+
const listeners = { "event": [], "disconnect": null, "error": null, "connected": null };
|
|
9
|
+
class SocketIo {
|
|
10
|
+
static setIoServer(app, ioSocketConfig) {
|
|
11
|
+
const httpServer = (0, http_1.createServer)(app);
|
|
12
|
+
exports.io = io = new socket_io_1.Server(httpServer, ioSocketConfig);
|
|
13
|
+
io.use((socket, next) => {
|
|
14
|
+
if (listeners["connected"] !== null) {
|
|
15
|
+
listeners["connected"](socket, async (err) => {
|
|
16
|
+
if (listeners["error"] !== null && err) {
|
|
17
|
+
await listeners["error"](socket, err);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
next();
|
|
22
|
+
});
|
|
23
|
+
io.on("connection", (socket) => {
|
|
24
|
+
if (listeners["disconnect"] !== null) {
|
|
25
|
+
socket.on("disconnect", async (reason) => {
|
|
26
|
+
await listeners["disconnect"](socket, reason);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
socket.use(async ([event, ...args], next) => {
|
|
30
|
+
try {
|
|
31
|
+
for (let listener of listeners["event"]) {
|
|
32
|
+
if (listener[1] === event) {
|
|
33
|
+
await listener[0](socket, ...args);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
next(err);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
if (listeners["error"] !== null) {
|
|
42
|
+
socket.on("error", async (err) => {
|
|
43
|
+
await listeners["error"](socket, err);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return httpServer;
|
|
48
|
+
}
|
|
49
|
+
static onEvent(event) {
|
|
50
|
+
return (target, propertyKey) => {
|
|
51
|
+
listeners["event"].push([target[propertyKey], event]);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
static onError(target, propertyKey) {
|
|
55
|
+
listeners["error"] = target[propertyKey];
|
|
56
|
+
}
|
|
57
|
+
static onDisconnect(target, propertyKey) {
|
|
58
|
+
listeners["disconnect"] = target[propertyKey];
|
|
59
|
+
}
|
|
60
|
+
static onConnected(target, propertyKey) {
|
|
61
|
+
listeners["connected"] = target[propertyKey];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.SocketIo = SocketIo;
|
|
@@ -20,7 +20,7 @@ const fs = require("fs");
|
|
|
20
20
|
const path = require("path");
|
|
21
21
|
const walkSync = require("walk-sync");
|
|
22
22
|
let globalConfig = {};
|
|
23
|
-
const
|
|
23
|
+
const corePath = __dirname;
|
|
24
24
|
const mainPath = path.dirname(getRootPath(new Error().stack.split("\n")) || process.argv[1]);
|
|
25
25
|
const configFile = mainPath + "/config.json";
|
|
26
26
|
if (fs.existsSync(configFile)) {
|
|
@@ -31,15 +31,17 @@ if (fs.existsSync(configFile)) {
|
|
|
31
31
|
globalConfig = Object.assign(globalConfig, JSON.parse(fs.readFileSync(envConfigFile, "utf-8")));
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
+
globalConfig["MAIN_PATH"] = mainPath;
|
|
35
|
+
globalConfig["CORE_PATH"] = corePath;
|
|
34
36
|
function app(constructor) {
|
|
35
|
-
const coreFiles = walkSync(
|
|
37
|
+
const coreFiles = walkSync(corePath, { globs: ['**/*.ts'], ignore: ['**/*.d.ts', 'scaffold/**'] });
|
|
36
38
|
const mainFiles = walkSync(mainPath, { globs: ['**/*.ts'] });
|
|
37
39
|
(async function () {
|
|
38
40
|
var _a, _b;
|
|
39
41
|
try {
|
|
40
42
|
for (let p of coreFiles) {
|
|
41
43
|
let moduleName = p.replace(".d.ts", "").replace(".ts", "");
|
|
42
|
-
await (_a =
|
|
44
|
+
await (_a = corePath + "/" + moduleName, Promise.resolve().then(() => require(_a)));
|
|
43
45
|
}
|
|
44
46
|
for (let p of mainFiles) {
|
|
45
47
|
let moduleName = p.replace(".d.ts", "").replace(".ts", "");
|
|
@@ -124,3 +126,4 @@ Object.defineProperty(exports, "redisSubscriber", { enumerable: true, get: funct
|
|
|
124
126
|
var read_write_db_class_1 = require("./default/read-write-db.class");
|
|
125
127
|
Object.defineProperty(exports, "ReadWriteDb", { enumerable: true, get: function () { return read_write_db_class_1.default; } });
|
|
126
128
|
__exportStar(require("./default/rabbitmq.class"), exports);
|
|
129
|
+
__exportStar(require("./default/socket-io.class"), exports);
|