@thi.ng/server 0.12.21 → 0.12.22
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/api.d.ts +4 -1
- package/package.json +19 -19
- package/utils/formdata.d.ts +31 -4
- package/utils/formdata.js +3 -3
package/api.d.ts
CHANGED
|
@@ -140,7 +140,7 @@ export interface RequestCtx {
|
|
|
140
140
|
/**
|
|
141
141
|
* Parsed query string params (aka URL search params).
|
|
142
142
|
*/
|
|
143
|
-
query:
|
|
143
|
+
query: ParsedFormData;
|
|
144
144
|
/**
|
|
145
145
|
* Parsed cookies, if any.
|
|
146
146
|
*/
|
|
@@ -150,6 +150,9 @@ export interface RequestCtx {
|
|
|
150
150
|
*/
|
|
151
151
|
session?: ServerSession;
|
|
152
152
|
}
|
|
153
|
+
export type ParsedFormData = {
|
|
154
|
+
[id: string]: string | string[] | ParsedFormData;
|
|
155
|
+
};
|
|
153
156
|
export type HandlerResult = MaybePromise<void>;
|
|
154
157
|
export type PreInterceptorResult = MaybePromise<boolean>;
|
|
155
158
|
export type PostInterceptorResult = MaybePromise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/server",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.22",
|
|
4
4
|
"description": "Minimal HTTP server with declarative routing, static file serving and freely extensible via pre/post interceptors",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -39,25 +39,25 @@
|
|
|
39
39
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@thi.ng/api": "^8.12.
|
|
43
|
-
"@thi.ng/arrays": "^2.14.
|
|
44
|
-
"@thi.ng/cache": "^2.3.
|
|
45
|
-
"@thi.ng/checks": "^3.8.
|
|
46
|
-
"@thi.ng/errors": "^2.6.
|
|
47
|
-
"@thi.ng/file-io": "^2.2.
|
|
48
|
-
"@thi.ng/leaky-bucket": "^0.2.
|
|
49
|
-
"@thi.ng/logger": "^3.2.
|
|
50
|
-
"@thi.ng/mime": "^2.8.
|
|
51
|
-
"@thi.ng/paths": "^5.2.
|
|
52
|
-
"@thi.ng/router": "^4.1.
|
|
53
|
-
"@thi.ng/strings": "^3.9.
|
|
54
|
-
"@thi.ng/timestamp": "^1.1.
|
|
55
|
-
"@thi.ng/uuid": "^1.1.
|
|
42
|
+
"@thi.ng/api": "^8.12.13",
|
|
43
|
+
"@thi.ng/arrays": "^2.14.6",
|
|
44
|
+
"@thi.ng/cache": "^2.3.62",
|
|
45
|
+
"@thi.ng/checks": "^3.8.3",
|
|
46
|
+
"@thi.ng/errors": "^2.6.2",
|
|
47
|
+
"@thi.ng/file-io": "^2.2.23",
|
|
48
|
+
"@thi.ng/leaky-bucket": "^0.2.25",
|
|
49
|
+
"@thi.ng/logger": "^3.2.12",
|
|
50
|
+
"@thi.ng/mime": "^2.8.5",
|
|
51
|
+
"@thi.ng/paths": "^5.2.32",
|
|
52
|
+
"@thi.ng/router": "^4.1.54",
|
|
53
|
+
"@thi.ng/strings": "^3.9.34",
|
|
54
|
+
"@thi.ng/timestamp": "^1.1.32",
|
|
55
|
+
"@thi.ng/uuid": "^1.1.45"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@types/node": "^24.10.
|
|
59
|
-
"esbuild": "^0.27.
|
|
60
|
-
"typedoc": "^0.28.
|
|
58
|
+
"@types/node": "^24.10.9",
|
|
59
|
+
"esbuild": "^0.27.2",
|
|
60
|
+
"typedoc": "^0.28.16",
|
|
61
61
|
"typescript": "^5.9.3"
|
|
62
62
|
},
|
|
63
63
|
"keywords": [
|
|
@@ -167,5 +167,5 @@
|
|
|
167
167
|
"status": "alpha",
|
|
168
168
|
"year": 2024
|
|
169
169
|
},
|
|
170
|
-
"gitHead": "
|
|
170
|
+
"gitHead": "828ec2e9ffde7307231b03cff46598c0915b1857\n"
|
|
171
171
|
}
|
package/utils/formdata.d.ts
CHANGED
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
import type { IncomingMessage } from "node:http";
|
|
2
|
-
|
|
3
|
-
export declare const
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import type { ParsedFormData } from "../api.js";
|
|
3
|
+
export declare const parseSearchParams: (params: URLSearchParams) => ParsedFormData;
|
|
4
|
+
/**
|
|
5
|
+
* Parses given URL's query string {@link parseFormData}. Any prefix
|
|
6
|
+
* before/including the first `?` will be ignored.
|
|
7
|
+
*
|
|
8
|
+
* @param url
|
|
9
|
+
*/
|
|
10
|
+
export declare const parseQuerystring: (url: string) => ParsedFormData;
|
|
11
|
+
export declare const parseRequestFormData: (req: IncomingMessage) => Promise<ParsedFormData>;
|
|
12
|
+
/**
|
|
13
|
+
* Parses given URI-encoded string of key-value pairs into a
|
|
14
|
+
* {@link ParsedFormData} object. Throws an error if there're syntax/nesting
|
|
15
|
+
* errors.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* Supports the following syntax:
|
|
19
|
+
*
|
|
20
|
+
* - `key=value`
|
|
21
|
+
* - `key[]=value`: append value to `key` array
|
|
22
|
+
* - `key[a]=value`: set value `a` in object `key`
|
|
23
|
+
* - `key[a][b]=value`: set nested value in object `key`
|
|
24
|
+
* - `key[a][]=value`: append value to nested array in object `key`
|
|
25
|
+
*
|
|
26
|
+
* Ignores attempts to manipulate a JS prototype chain (via
|
|
27
|
+
* [`isProtoPath()`](https://docs.thi.ng/umbrella/checks/functions/isProtoPath.html)),
|
|
28
|
+
* i.e. `foo[__proto__][bar]=42` will be skipped.
|
|
29
|
+
*
|
|
30
|
+
* @param body
|
|
31
|
+
*/
|
|
32
|
+
export declare const parseFormData: (body: string) => ParsedFormData;
|
|
6
33
|
//# sourceMappingURL=formdata.d.ts.map
|
package/utils/formdata.js
CHANGED
|
@@ -2,10 +2,10 @@ import { isArray, isProtoPath } from "@thi.ng/checks";
|
|
|
2
2
|
import { illegalArgs } from "@thi.ng/errors";
|
|
3
3
|
import { setInUnsafe, updateInUnsafe } from "@thi.ng/paths";
|
|
4
4
|
const parseSearchParams = (params) => {
|
|
5
|
-
|
|
5
|
+
let acc = {};
|
|
6
6
|
for (const [k, v] of params) {
|
|
7
|
-
if (k.includes("["))
|
|
8
|
-
if (!isProtoPath(k)) acc[k] = v;
|
|
7
|
+
if (k.includes("[")) acc = parseObjectVal(acc, k, v);
|
|
8
|
+
else if (!isProtoPath(k)) acc[k] = v;
|
|
9
9
|
}
|
|
10
10
|
return acc;
|
|
11
11
|
};
|