alado 3.0.0 → 3.1.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/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Alado [alado.tech](https://alado.tech/)
|
|
2
2
|
|
|
3
|
-
> A fast, lightweight
|
|
3
|
+
> A fast, lightweight Node.js HTTP framework with built-in routing, validation, authentication, file uploads, and automatic OpenAPI 3.0 documentation. Its only runtime dependency is `swagger-ui-dist`, for the docs UI.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/alado)
|
|
6
6
|
[](./LICENSE)
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
|
|
38
38
|
## Why Alado
|
|
39
39
|
|
|
40
|
-
Alado sits in a unique position — it has the **simplicity of Express**, the **performance focus of Fastify**, and the **decorator-based structure of NestJS**, but with **
|
|
40
|
+
Alado sits in a unique position — it has the **simplicity of Express**, the **performance focus of Fastify**, and the **decorator-based structure of NestJS**, but with **a single runtime dependency** (`swagger-ui-dist`) and a much smaller surface area.
|
|
41
41
|
|
|
42
42
|
---
|
|
43
43
|
|
|
@@ -45,7 +45,7 @@ Alado sits in a unique position — it has the **simplicity of Express**, the **
|
|
|
45
45
|
|
|
46
46
|
| Feature | Alado | Express | Fastify | NestJS |
|
|
47
47
|
| --------------------------- | ---------- | --------------------- | ------------ | ----------- |
|
|
48
|
-
|
|
|
48
|
+
| Single runtime dependency | ✅ | ❌ | ❌ | ❌ |
|
|
49
49
|
| Decorator-based routing | ✅ | ❌ | ❌ | ✅ |
|
|
50
50
|
| Built-in request validation | ✅ | ❌ | ✅ (schemas) | ✅ (pipes) |
|
|
51
51
|
| Built-in auth pipeline | ✅ | ❌ | ✅ (plugin) | ✅ (guards) |
|
|
@@ -438,7 +438,7 @@ class CredentialsDto {
|
|
|
438
438
|
|
|
439
439
|
## Validation
|
|
440
440
|
|
|
441
|
-
The project uses a built-in chainable validator — a lightweight,
|
|
441
|
+
The project uses a built-in chainable validator — a lightweight, dependency-free TypeScript validation library with sync and async support.
|
|
442
442
|
|
|
443
443
|
### Basic usage
|
|
444
444
|
|
|
@@ -10,6 +10,24 @@ function isXmlContentType(contentType) {
|
|
|
10
10
|
const mime = (contentType || '').split(';')[0].trim().toLowerCase();
|
|
11
11
|
return mime === _const_1.ContentType.XML || mime === _const_1.ContentType.TEXT_XML || /^application\/[\w.+-]+\+xml$/.test(mime);
|
|
12
12
|
}
|
|
13
|
+
function collectChunks(req, limit, received, reject) {
|
|
14
|
+
return (chunk) => {
|
|
15
|
+
received.bytes += chunk.length;
|
|
16
|
+
if (limit && received.bytes > limit) {
|
|
17
|
+
req.removeAllListeners('data');
|
|
18
|
+
req.removeAllListeners('end');
|
|
19
|
+
reject({
|
|
20
|
+
statusCode: 413,
|
|
21
|
+
message: 'Content Too Large',
|
|
22
|
+
});
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
received.chunks.push(chunk);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function concatChunks(received, encoding) {
|
|
29
|
+
return Buffer.concat(received.chunks, received.bytes).toString(encoding);
|
|
30
|
+
}
|
|
13
31
|
async function bodyParser(req, res, limit) {
|
|
14
32
|
const contentType = req.headers['content-type'];
|
|
15
33
|
const result = {
|
|
@@ -18,24 +36,15 @@ async function bodyParser(req, res, limit) {
|
|
|
18
36
|
rawBody: '',
|
|
19
37
|
};
|
|
20
38
|
let body = '';
|
|
39
|
+
const received = { chunks: [], bytes: 0 };
|
|
21
40
|
if (contentType?.startsWith(_const_1.ContentType.FORM_DATA)) {
|
|
22
|
-
req.setEncoding('binary');
|
|
23
41
|
const matchingArray = /boundary=(.+)$/.exec(req.headers['content-type']);
|
|
24
42
|
const boundary = matchingArray && matchingArray[1];
|
|
25
43
|
await new Promise((resolve, reject) => {
|
|
26
|
-
req.on('data', (
|
|
27
|
-
body += chunk.toString();
|
|
28
|
-
// binary encoding: one char per byte, so length is the byte count
|
|
29
|
-
if (limit && body.length > limit) {
|
|
30
|
-
req.removeAllListeners('data');
|
|
31
|
-
req.removeAllListeners('end');
|
|
32
|
-
reject({
|
|
33
|
-
statusCode: 413,
|
|
34
|
-
message: 'Content Too Large',
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
});
|
|
44
|
+
req.on('data', collectChunks(req, limit, received, reject));
|
|
38
45
|
req.on('end', () => {
|
|
46
|
+
// multipart is parsed as a binary string: one char per byte, file bytes kept intact
|
|
47
|
+
body = concatChunks(received, 'binary');
|
|
39
48
|
result.rawBody = body;
|
|
40
49
|
const formData = {
|
|
41
50
|
files: [],
|
|
@@ -49,7 +58,10 @@ async function bodyParser(req, res, limit) {
|
|
|
49
58
|
const regExpMatchArray = item.match(regEx);
|
|
50
59
|
element[key] = regExpMatchArray && regExpMatchArray[1] && regExpMatchArray[1];
|
|
51
60
|
});
|
|
52
|
-
const {
|
|
61
|
+
const { value, filename, mimetype } = element;
|
|
62
|
+
// the body is parsed as a binary string (one char per byte) to keep file bytes intact;
|
|
63
|
+
// text (field names and values) is UTF-8 and has to be decoded back
|
|
64
|
+
const name = element.name && Buffer.from(element.name, 'binary').toString('utf8');
|
|
53
65
|
if (!name || !value) {
|
|
54
66
|
continue;
|
|
55
67
|
}
|
|
@@ -64,7 +76,7 @@ async function bodyParser(req, res, limit) {
|
|
|
64
76
|
formData.files.push(file);
|
|
65
77
|
}
|
|
66
78
|
else {
|
|
67
|
-
formData.fields[name] = value;
|
|
79
|
+
formData.fields[name] = Buffer.from(value, 'binary').toString('utf8');
|
|
68
80
|
}
|
|
69
81
|
}
|
|
70
82
|
for (const key in formData.fields) {
|
|
@@ -85,18 +97,9 @@ async function bodyParser(req, res, limit) {
|
|
|
85
97
|
}
|
|
86
98
|
else {
|
|
87
99
|
await new Promise((resolve, reject) => {
|
|
88
|
-
req.on('data', (
|
|
89
|
-
body += chunk.toString();
|
|
90
|
-
if (limit && Buffer.byteLength(body, 'utf8') > limit) {
|
|
91
|
-
req.removeAllListeners('data');
|
|
92
|
-
req.removeAllListeners('end');
|
|
93
|
-
reject({
|
|
94
|
-
statusCode: 413,
|
|
95
|
-
message: 'Content Too Large',
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
});
|
|
100
|
+
req.on('data', collectChunks(req, limit, received, reject));
|
|
99
101
|
req.on('end', () => {
|
|
102
|
+
body = concatChunks(received, 'utf8');
|
|
100
103
|
result.rawBody = body;
|
|
101
104
|
if (contentType?.startsWith(_const_1.ContentType.JSON)) {
|
|
102
105
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"body-parser.js","sourceRoot":"","sources":["../../../src/helpers/parser/body-parser.ts"],"names":[],"mappings":";;AAOA,4CAGC;
|
|
1
|
+
{"version":3,"file":"body-parser.js","sourceRoot":"","sources":["../../../src/helpers/parser/body-parser.ts"],"names":[],"mappings":";;AAOA,4CAGC;AA6BD,gCA+GC;AArJD,mCAAkG;AAClG,mCAAkC;AAElC,6CAAyC;AAEzC,+GAA+G;AAC/G,SAAgB,gBAAgB,CAAC,WAA+B;IAC9D,MAAM,IAAI,GAAW,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC5E,OAAO,IAAI,KAAK,oBAAW,CAAC,GAAG,IAAI,IAAI,KAAK,oBAAW,CAAC,QAAQ,IAAI,8BAA8B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAChH,CAAC;AAID,SAAS,aAAa,CACpB,GAAoB,EACpB,KAAa,EACb,QAAsB,EACtB,MAAyC;IAEzC,OAAO,CAAC,KAAa,EAAE,EAAE;QACvB,QAAQ,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,CAAC;QAC/B,IAAI,KAAK,IAAI,QAAQ,CAAC,KAAK,GAAG,KAAK,EAAE,CAAC;YACpC,GAAG,CAAC,kBAAkB,CAAC,MAAM,CA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;wBAC3B,CAAC;oBACH,CAAC;oBACD,OAAO,EAAE,CAAC;gBACZ,CAAC;qBAAM,IAAI,gBAAgB,CAAC,WAAW,CAAC,EAAE,CAAC;oBACzC,IAAI,CAAC;wBACH,MAAM,CAAC,IAAI,GAAG,IAAA,sBAAS,EAAC,IAAI,CAAC,CAAC;wBAC9B,OAAO,EAAE,CAAC;oBACZ,CAAC;oBAAC,OAAO,CAAC,EAAE,CAAC;wBACX,MAAM,CAAC,EAAE,UAAU,EAAE,GAAG,EAAE,OAAO,EAAE,qBAAqB,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;oBACzE,CAAC;gBACH,CAAC;qBAAM,CAAC;oBACN,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC;oBACnB,OAAO,EAAE,CAAC;gBACZ,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "alado",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"description": "Fast, lightweight, robust framework for HTTP applications written in Node.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"HTTP",
|
|
7
7
|
"framework",
|
|
8
|
-
"no-dependency",
|
|
9
8
|
"http-server",
|
|
10
9
|
"server",
|
|
11
10
|
"alado"
|