mikroserve 1.0.1 → 1.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 +233 -0
- package/lib/MikroServe.d.mts +9 -0
- package/lib/MikroServe.d.ts +9 -0
- package/lib/MikroServe.js +302 -37
- package/lib/MikroServe.mjs +6 -5
- package/lib/RateLimiter.js +2 -1
- package/lib/RateLimiter.mjs +1 -1
- package/lib/Router.js +1 -1
- package/lib/Router.mjs +1 -1
- package/lib/{chunk-YKRH6T5M.mjs → chunk-7LU765PG.mjs} +2 -2
- package/lib/chunk-7ZFF73JR.mjs +0 -0
- package/lib/{chunk-N5ZQZGGT.mjs → chunk-C4IW4XUH.mjs} +176 -40
- package/lib/{chunk-JJX5XRNB.mjs → chunk-DMNHVQTU.mjs} +6 -0
- package/lib/{chunk-ZFBBESGU.mjs → chunk-OF5DEOIU.mjs} +2 -1
- package/lib/chunk-VLQ7ZZIU.mjs +105 -0
- package/lib/{chunk-YOHL3T54.mjs → chunk-ZT2UGCN5.mjs} +29 -4
- package/lib/config.js +32 -3
- package/lib/config.mjs +2 -2
- package/lib/index.d.mts +2 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js +302 -37
- package/lib/index.mjs +7 -5
- package/lib/interfaces/index.d.mts +10 -0
- package/lib/interfaces/index.d.ts +10 -0
- package/lib/interfaces/index.mjs +1 -0
- package/lib/utils/configDefaults.d.mts +2 -0
- package/lib/utils/configDefaults.d.ts +2 -0
- package/lib/utils/configDefaults.js +6 -0
- package/lib/utils/configDefaults.mjs +1 -1
- package/lib/utils/multipartParser.d.mts +19 -0
- package/lib/utils/multipartParser.d.ts +19 -0
- package/lib/utils/multipartParser.js +129 -0
- package/lib/utils/multipartParser.mjs +6 -0
- package/package.json +4 -4
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/utils/multipartParser.ts
|
|
21
|
+
var multipartParser_exports = {};
|
|
22
|
+
__export(multipartParser_exports, {
|
|
23
|
+
parseMultipartFormData: () => parseMultipartFormData
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(multipartParser_exports);
|
|
26
|
+
function parseMultipartFormData(body, contentType) {
|
|
27
|
+
const boundaryMatch = contentType.match(/boundary=(?:"([^"]+)"|([^;]+))/i);
|
|
28
|
+
if (!boundaryMatch) {
|
|
29
|
+
throw new Error("Invalid multipart/form-data: missing boundary");
|
|
30
|
+
}
|
|
31
|
+
const boundary = boundaryMatch[1] || boundaryMatch[2];
|
|
32
|
+
const boundaryBuffer = Buffer.from(`--${boundary}`);
|
|
33
|
+
const endBoundaryBuffer = Buffer.from(`--${boundary}--`);
|
|
34
|
+
const fields = {};
|
|
35
|
+
const files = {};
|
|
36
|
+
const parts = splitByBoundary(body, boundaryBuffer);
|
|
37
|
+
for (const part of parts) {
|
|
38
|
+
if (part.length === 0) continue;
|
|
39
|
+
if (part.equals(endBoundaryBuffer.subarray(boundaryBuffer.length)))
|
|
40
|
+
continue;
|
|
41
|
+
const parsed = parsePart(part);
|
|
42
|
+
if (!parsed) continue;
|
|
43
|
+
const { name, filename, contentType: partContentType, data } = parsed;
|
|
44
|
+
if (filename) {
|
|
45
|
+
const file = {
|
|
46
|
+
filename,
|
|
47
|
+
contentType: partContentType || "application/octet-stream",
|
|
48
|
+
data,
|
|
49
|
+
size: data.length
|
|
50
|
+
};
|
|
51
|
+
if (files[name]) {
|
|
52
|
+
if (Array.isArray(files[name])) {
|
|
53
|
+
files[name].push(file);
|
|
54
|
+
} else {
|
|
55
|
+
files[name] = [files[name], file];
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
files[name] = file;
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
const value = data.toString("utf8");
|
|
62
|
+
if (fields[name]) {
|
|
63
|
+
if (Array.isArray(fields[name])) {
|
|
64
|
+
fields[name].push(value);
|
|
65
|
+
} else {
|
|
66
|
+
fields[name] = [fields[name], value];
|
|
67
|
+
}
|
|
68
|
+
} else {
|
|
69
|
+
fields[name] = value;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return { fields, files };
|
|
74
|
+
}
|
|
75
|
+
function splitByBoundary(buffer, boundary) {
|
|
76
|
+
const parts = [];
|
|
77
|
+
let start = 0;
|
|
78
|
+
while (start < buffer.length) {
|
|
79
|
+
const index = buffer.indexOf(boundary, start);
|
|
80
|
+
if (index === -1) break;
|
|
81
|
+
if (start !== index) {
|
|
82
|
+
parts.push(buffer.subarray(start, index));
|
|
83
|
+
}
|
|
84
|
+
start = index + boundary.length;
|
|
85
|
+
if (start < buffer.length && buffer[start] === 13 && buffer[start + 1] === 10) {
|
|
86
|
+
start += 2;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return parts;
|
|
90
|
+
}
|
|
91
|
+
function parsePart(part) {
|
|
92
|
+
const doubleCRLF = Buffer.from("\r\n\r\n");
|
|
93
|
+
const headerEndIndex = part.indexOf(doubleCRLF);
|
|
94
|
+
if (headerEndIndex === -1) return null;
|
|
95
|
+
const headersBuffer = part.subarray(0, headerEndIndex);
|
|
96
|
+
const dataBuffer = part.subarray(headerEndIndex + 4);
|
|
97
|
+
const headers = headersBuffer.toString("utf8");
|
|
98
|
+
const headerLines = headers.split("\r\n");
|
|
99
|
+
let disposition = "";
|
|
100
|
+
let name = "";
|
|
101
|
+
let filename;
|
|
102
|
+
let contentType;
|
|
103
|
+
for (const line of headerLines) {
|
|
104
|
+
const lowerLine = line.toLowerCase();
|
|
105
|
+
if (lowerLine.startsWith("content-disposition:")) {
|
|
106
|
+
disposition = line.substring("content-disposition:".length).trim();
|
|
107
|
+
const nameMatch = disposition.match(/name="([^"]+)"/);
|
|
108
|
+
if (nameMatch) {
|
|
109
|
+
name = nameMatch[1];
|
|
110
|
+
}
|
|
111
|
+
const filenameMatch = disposition.match(/filename="([^"]+)"/);
|
|
112
|
+
if (filenameMatch) {
|
|
113
|
+
filename = filenameMatch[1];
|
|
114
|
+
}
|
|
115
|
+
} else if (lowerLine.startsWith("content-type:")) {
|
|
116
|
+
contentType = line.substring("content-type:".length).trim();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (!name) return null;
|
|
120
|
+
let data = dataBuffer;
|
|
121
|
+
if (data.length >= 2 && data[data.length - 2] === 13 && data[data.length - 1] === 10) {
|
|
122
|
+
data = data.subarray(0, data.length - 2);
|
|
123
|
+
}
|
|
124
|
+
return { disposition, name, filename, contentType, data };
|
|
125
|
+
}
|
|
126
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
127
|
+
0 && (module.exports = {
|
|
128
|
+
parseMultipartFormData
|
|
129
|
+
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mikroserve",
|
|
3
3
|
"description": "Minimalistic, ready-to-use API, built on Node.js primitives.",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.1.1",
|
|
5
5
|
"author": "Mikael Vesavuori",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"keywords": [
|
|
@@ -45,16 +45,16 @@
|
|
|
45
45
|
"prepare": "husky"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@biomejs/biome": "
|
|
48
|
+
"@biomejs/biome": "2",
|
|
49
49
|
"@types/node": "latest",
|
|
50
|
-
"@vitest/coverage-v8": "
|
|
50
|
+
"@vitest/coverage-v8": "4",
|
|
51
51
|
"husky": "9",
|
|
52
52
|
"license-compliance": "latest",
|
|
53
53
|
"tsup": "8",
|
|
54
54
|
"tsx": "latest",
|
|
55
55
|
"type-coverage": "2",
|
|
56
56
|
"typescript": "5",
|
|
57
|
-
"vitest": "
|
|
57
|
+
"vitest": "4"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"mikroconf": "latest"
|