tspace-spear 1.1.0 → 1.1.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/build/lib/core/decorators/context.js +25 -49
- package/build/lib/core/decorators/context.js.map +1 -1
- package/build/lib/core/decorators/headers.js +3 -14
- package/build/lib/core/decorators/headers.js.map +1 -1
- package/build/lib/core/decorators/statusCode.js +3 -14
- package/build/lib/core/decorators/statusCode.js.map +1 -1
- package/build/lib/core/decorators/swagger.js +4 -1
- package/build/lib/core/decorators/swagger.js.map +1 -1
- package/build/lib/core/server/index.d.ts +19 -16
- package/build/lib/core/server/index.js +257 -252
- package/build/lib/core/server/index.js.map +1 -1
- package/build/lib/core/server/parser-factory.js +81 -94
- package/build/lib/core/server/parser-factory.js.map +1 -1
- package/build/lib/core/server/router.js +1 -3
- package/build/lib/core/server/router.js.map +1 -1
- package/build/tests/benchmark.test.js +51 -71
- package/build/tests/benchmark.test.js.map +1 -1
- package/package.json +10 -8
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -27,71 +18,61 @@ connections = connections == null ? 100 : Number(connections);
|
|
|
27
18
|
pipelining = pipelining == null ? 10 : Number(pipelining);
|
|
28
19
|
duration = duration == null ? 10 : Number(duration);
|
|
29
20
|
function runExpress() {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
console.log(`Server 'Express' running at http://localhost:${port}`);
|
|
39
|
-
});
|
|
21
|
+
const port = 3000;
|
|
22
|
+
(0, express_1.default)()
|
|
23
|
+
.get('/', (req, res) => {
|
|
24
|
+
res.setHeader('Content-Type', 'text/plain');
|
|
25
|
+
return res.send(MESSAGE);
|
|
26
|
+
})
|
|
27
|
+
.listen(port, () => {
|
|
28
|
+
console.log(`Server 'Express' running at http://localhost:${port}`);
|
|
40
29
|
});
|
|
41
30
|
}
|
|
42
|
-
function
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
})
|
|
51
|
-
.listen({ port }, (err, address) => {
|
|
52
|
-
if (err)
|
|
53
|
-
throw err;
|
|
54
|
-
console.log(`server 'Fastify' running at : http://localhost:${port}`);
|
|
55
|
-
});
|
|
31
|
+
function runHttp() {
|
|
32
|
+
const port = 3001;
|
|
33
|
+
const server = http_1.default.createServer((req, res) => {
|
|
34
|
+
res.statusCode = 200;
|
|
35
|
+
res.setHeader('Content-Type', 'text/plain');
|
|
36
|
+
res.end(MESSAGE);
|
|
37
|
+
});
|
|
38
|
+
server.listen(port, () => {
|
|
39
|
+
console.log(`Server 'Http' running at http://localhost:${port}`);
|
|
56
40
|
});
|
|
57
41
|
}
|
|
58
|
-
function
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
42
|
+
function runFastify() {
|
|
43
|
+
const port = 3002;
|
|
44
|
+
(0, fastify_1.default)()
|
|
45
|
+
.get('/', (request, reply) => {
|
|
46
|
+
return reply
|
|
47
|
+
.header('Content-Type', 'text/plain')
|
|
48
|
+
.send(MESSAGE);
|
|
49
|
+
})
|
|
50
|
+
.listen({ port }, (err, address) => {
|
|
51
|
+
if (err)
|
|
52
|
+
throw err;
|
|
53
|
+
console.log(`server 'Fastify' running at : http://localhost:${port}`);
|
|
69
54
|
});
|
|
70
55
|
}
|
|
71
56
|
function runSpear() {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return res.end(MESSAGE);
|
|
77
|
-
})
|
|
78
|
-
.listen(port, () => console.log(`server 'Spear' running at : http://localhost:${port}`));
|
|
79
|
-
});
|
|
57
|
+
const port = 3999;
|
|
58
|
+
new lib_1.default()
|
|
59
|
+
.get('/', ({ res }) => MESSAGE)
|
|
60
|
+
.listen(port, () => console.log(`server 'Spear' running at : http://localhost:${port}`));
|
|
80
61
|
}
|
|
81
62
|
const url = (port) => `http://localhost:${port}`;
|
|
82
63
|
const urls = [
|
|
83
64
|
{ name: 'express', url: url(3000) },
|
|
84
|
-
{ name: '
|
|
85
|
-
{ name: '
|
|
86
|
-
{ name: 'tspace-spear', url: url(
|
|
65
|
+
{ name: 'http', url: url(3001) },
|
|
66
|
+
{ name: 'fastify', url: url(3002) },
|
|
67
|
+
{ name: 'tspace-spear', url: url(3999) }
|
|
87
68
|
];
|
|
88
69
|
const sleep = (ms) => {
|
|
89
70
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
90
71
|
};
|
|
91
|
-
const runBenchmark = () =>
|
|
72
|
+
const runBenchmark = async () => {
|
|
92
73
|
const results = [];
|
|
93
74
|
for (const { name, url } of urls) {
|
|
94
|
-
const result =
|
|
75
|
+
const result = await new Promise((resolve, reject) => {
|
|
95
76
|
(0, autocannon_1.default)({
|
|
96
77
|
url,
|
|
97
78
|
connections,
|
|
@@ -107,6 +88,7 @@ const runBenchmark = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
107
88
|
name,
|
|
108
89
|
url,
|
|
109
90
|
requests: result.requests.total,
|
|
91
|
+
['req/sec']: result.requests.total / duration,
|
|
110
92
|
average: result.latency.average
|
|
111
93
|
});
|
|
112
94
|
}
|
|
@@ -116,20 +98,18 @@ const runBenchmark = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
116
98
|
pipelining
|
|
117
99
|
});
|
|
118
100
|
console.table(results);
|
|
119
|
-
}
|
|
120
|
-
function runApps() {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
console.log('benchmarking done !!');
|
|
132
|
-
});
|
|
101
|
+
};
|
|
102
|
+
async function runApps() {
|
|
103
|
+
await Promise.all([
|
|
104
|
+
runSpear,
|
|
105
|
+
runFastify,
|
|
106
|
+
runExpress,
|
|
107
|
+
runHttp
|
|
108
|
+
].map(v => v()));
|
|
109
|
+
await sleep(3000);
|
|
110
|
+
console.log('benchmarking !!');
|
|
111
|
+
await runBenchmark();
|
|
112
|
+
console.log('benchmarking done !!');
|
|
133
113
|
}
|
|
134
114
|
runApps();
|
|
135
115
|
//# sourceMappingURL=benchmark.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"benchmark.test.js","sourceRoot":"","sources":["../../src/tests/benchmark.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"benchmark.test.js","sourceRoot":"","sources":["../../src/tests/benchmark.test.ts"],"names":[],"mappings":";;;;;AAAA,4DAAgD;AAChD,sDAA6B;AAC7B,sDAAoD;AACpD,gDAAuB;AACvB,kDAA0B;AAC1B,iDAA0B;AAE1B,MAAM,OAAO,GAAG,cAAc,CAAA;AAE9B,MAAM,EAAE,IAAI,EAAE,GAAwB,IAAA,eAAK,EAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;AAClE,I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CAAC,CAAA;AAED,KAAK,UAAU,OAAO;IAElB,MAAM,OAAO,CAAC,GAAG,CAAC;QACd,QAAQ;QACR,UAAU;QACV,UAAU;QACV,OAAO;KACV,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAEhB,MAAM,KAAK,CAAC,IAAI,CAAC,CAAA;IACjB,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAA;IAC9B,MAAM,YAAY,EAAE,CAAA;IAEpB,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAA;AACvC,CAAC;AAED,OAAO,EAAE,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tspace-spear",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "tspace-spear is a lightweight API framework for Node.js that is fast and highly focused on providing the best developer experience. It utilizes the native HTTP server",
|
|
5
5
|
"main": "./build/lib/index.js",
|
|
6
6
|
"types": "./build/lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
8
8
|
"build"
|
|
9
9
|
],
|
|
10
|
+
"type": "commonjs",
|
|
10
11
|
"repository": {
|
|
11
12
|
"type": "git",
|
|
12
13
|
"url": "https://github.com/thanathip41/tspace-spear.git"
|
|
@@ -14,9 +15,9 @@
|
|
|
14
15
|
"keywords": [
|
|
15
16
|
"tspace",
|
|
16
17
|
"tspace-spear",
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
18
|
+
"api",
|
|
19
|
+
"rest api",
|
|
20
|
+
"framework"
|
|
20
21
|
],
|
|
21
22
|
"author": "Thanathip (https://github.com/thanathip41)",
|
|
22
23
|
"license": "MIT",
|
|
@@ -28,13 +29,13 @@
|
|
|
28
29
|
"build": "tsc",
|
|
29
30
|
"prepare": "npm run build",
|
|
30
31
|
"release": "npm run build && npm publish",
|
|
31
|
-
"test": "
|
|
32
|
+
"test": "npm run build && node build/tests/benchmark.test.js",
|
|
32
33
|
"test:build": "node build/tests/benchmark.test.js",
|
|
33
|
-
"
|
|
34
|
+
"load": "autocannon -c 100 -d 40 -p 10 localhost:3000"
|
|
34
35
|
},
|
|
35
36
|
"dependencies": {
|
|
36
|
-
"find-my-way": "
|
|
37
|
-
"formidable": "
|
|
37
|
+
"find-my-way": "7.4.0",
|
|
38
|
+
"formidable": "2.1.2",
|
|
38
39
|
"mime-types": "2.1.35",
|
|
39
40
|
"on-finished": "2.4.1",
|
|
40
41
|
"reflect-metadata": "0.1.14",
|
|
@@ -53,6 +54,7 @@
|
|
|
53
54
|
"express": "^4.19.2",
|
|
54
55
|
"fastify": "^4.28.1",
|
|
55
56
|
"ts-node": "^10.9.2",
|
|
57
|
+
"tspace-echo-spear": "^1.0.0",
|
|
56
58
|
"typescript": "^5.4.5",
|
|
57
59
|
"yargs": "^17.7.2"
|
|
58
60
|
}
|