@cfworker/web 1.12.0 → 1.12.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/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/validate.js +2 -3
- package/package.json +9 -10
- package/src/index.ts +0 -1
- package/src/validate.ts +2 -3
- package/dist/to-object.d.ts +0 -3
- package/dist/to-object.js +0 -7
- package/src/to-object.ts +0 -15
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/validate.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { dereference, validate as schemaValidate } from '@cfworker/json-schema';
|
|
2
2
|
import { HttpError } from './http-error.js';
|
|
3
|
-
import { toObject } from './to-object.js';
|
|
4
3
|
const draft = '2019-09';
|
|
5
4
|
const hasBody = {
|
|
6
5
|
POST: true,
|
|
@@ -8,7 +7,7 @@ const hasBody = {
|
|
|
8
7
|
DELETE: true,
|
|
9
8
|
PATCH: true
|
|
10
9
|
};
|
|
11
|
-
function middlewareFactory(schemas, parser =
|
|
10
|
+
function middlewareFactory(schemas, parser = Object.fromEntries, lookup = Object.create(null)) {
|
|
12
11
|
const { headers: $headers, search: $search, params: $params, body: $body } = schemas;
|
|
13
12
|
if ($headers) {
|
|
14
13
|
dereference($headers, { ...lookup });
|
|
@@ -27,7 +26,7 @@ function middlewareFactory(schemas, parser = toObject, lookup = Object.create(nu
|
|
|
27
26
|
validateRequestPart('params', req.params, $params, lookup);
|
|
28
27
|
}
|
|
29
28
|
if ($headers) {
|
|
30
|
-
const headers =
|
|
29
|
+
const headers = Object.fromEntries(req.headers);
|
|
31
30
|
validateRequestPart('headers', headers, $headers, lookup);
|
|
32
31
|
}
|
|
33
32
|
if ($search) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cfworker/web",
|
|
3
|
-
"version": "1.12.
|
|
3
|
+
"version": "1.12.1",
|
|
4
4
|
"description": "Web framework for Cloudflare Workers and service workers, inspired by Koa and fastify",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"middleware",
|
|
@@ -34,12 +34,11 @@
|
|
|
34
34
|
"test": "cfworker test test/**/*.spec.ts --nocheck"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@cfworker/json-schema": "^1.12.
|
|
38
|
-
"@cfworker/worker-types": "^1.12.
|
|
37
|
+
"@cfworker/json-schema": "^1.12.1",
|
|
38
|
+
"@cfworker/worker-types": "^1.12.1",
|
|
39
39
|
"@cloudflare/workers-types": "^2.2.2",
|
|
40
40
|
"@types/cookie": "^0.4.1",
|
|
41
41
|
"@types/html-escaper": "^3.0.0",
|
|
42
|
-
"@types/json-pointer": "^1.0.31",
|
|
43
42
|
"@types/statuses": "^2.0.0",
|
|
44
43
|
"cookie": "^0.4.1",
|
|
45
44
|
"html-escaper": "^3.0.3",
|
|
@@ -49,12 +48,12 @@
|
|
|
49
48
|
"statuses": "^2.0.1"
|
|
50
49
|
},
|
|
51
50
|
"devDependencies": {
|
|
52
|
-
"@cfworker/dev": "^1.
|
|
53
|
-
"@types/chai": "^4.
|
|
54
|
-
"@types/mocha": "^9.
|
|
51
|
+
"@cfworker/dev": "^1.13.1",
|
|
52
|
+
"@types/chai": "^4.3.0",
|
|
53
|
+
"@types/mocha": "^9.1.0",
|
|
55
54
|
"chai": "^4.3.4",
|
|
56
|
-
"
|
|
57
|
-
"mocha": "^9.1.
|
|
58
|
-
"typescript": "^4.5.
|
|
55
|
+
"jsonpointer": "^5.0.0",
|
|
56
|
+
"mocha": "^9.1.4",
|
|
57
|
+
"typescript": "^4.5.5"
|
|
59
58
|
}
|
|
60
59
|
}
|
package/src/index.ts
CHANGED
package/src/validate.ts
CHANGED
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
} from '@cfworker/json-schema';
|
|
7
7
|
import { HttpError } from './http-error.js';
|
|
8
8
|
import { Middleware } from './middleware.js';
|
|
9
|
-
import { toObject } from './to-object.js';
|
|
10
9
|
|
|
11
10
|
export interface RequestSchemas {
|
|
12
11
|
body?: Schema;
|
|
@@ -30,7 +29,7 @@ const hasBody: Record<string, true> = {
|
|
|
30
29
|
|
|
31
30
|
function middlewareFactory(
|
|
32
31
|
schemas: RequestSchemas,
|
|
33
|
-
parser: RequestParser =
|
|
32
|
+
parser: RequestParser = Object.fromEntries,
|
|
34
33
|
lookup = Object.create(null)
|
|
35
34
|
): Middleware {
|
|
36
35
|
const {
|
|
@@ -58,7 +57,7 @@ function middlewareFactory(
|
|
|
58
57
|
validateRequestPart('params', req.params, $params, lookup);
|
|
59
58
|
}
|
|
60
59
|
if ($headers) {
|
|
61
|
-
const headers =
|
|
60
|
+
const headers = Object.fromEntries(req.headers);
|
|
62
61
|
validateRequestPart('headers', headers, $headers, lookup);
|
|
63
62
|
}
|
|
64
63
|
if ($search) {
|
package/dist/to-object.d.ts
DELETED
package/dist/to-object.js
DELETED
package/src/to-object.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Convert an iterable to an object.
|
|
3
|
-
*/
|
|
4
|
-
export function toObject<
|
|
5
|
-
TKey extends string | number | symbol,
|
|
6
|
-
TValue
|
|
7
|
-
>(iterable: {
|
|
8
|
-
[Symbol.iterator](): IterableIterator<[TKey, TValue]>;
|
|
9
|
-
}): Record<TKey, TValue> {
|
|
10
|
-
const obj = Object.create(null) as Record<TKey, TValue>;
|
|
11
|
-
for (const [key, value] of iterable) {
|
|
12
|
-
obj[key] = value;
|
|
13
|
-
}
|
|
14
|
-
return obj;
|
|
15
|
-
}
|