@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 CHANGED
@@ -9,5 +9,4 @@ export * from './normalize-pathname.js';
9
9
  export * from './req.js';
10
10
  export * from './response-builder.js';
11
11
  export * from './router.js';
12
- export * from './to-object.js';
13
12
  export * from './validate.js';
package/dist/index.js CHANGED
@@ -9,5 +9,4 @@ export * from './normalize-pathname.js';
9
9
  export * from './req.js';
10
10
  export * from './response-builder.js';
11
11
  export * from './router.js';
12
- export * from './to-object.js';
13
12
  export * from './validate.js';
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 = toObject, lookup = Object.create(null)) {
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 = toObject(req.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.0",
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.0",
38
- "@cfworker/worker-types": "^1.12.0",
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.12.0",
53
- "@types/chai": "^4.2.22",
54
- "@types/mocha": "^9.0.0",
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
- "json-pointer": "^0.6.1",
57
- "mocha": "^9.1.3",
58
- "typescript": "^4.5.2"
55
+ "jsonpointer": "^5.0.0",
56
+ "mocha": "^9.1.4",
57
+ "typescript": "^4.5.5"
59
58
  }
60
59
  }
package/src/index.ts CHANGED
@@ -9,5 +9,4 @@ export * from './normalize-pathname.js';
9
9
  export * from './req.js';
10
10
  export * from './response-builder.js';
11
11
  export * from './router.js';
12
- export * from './to-object.js';
13
12
  export * from './validate.js';
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 = toObject as 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 = toObject(req.headers);
60
+ const headers = Object.fromEntries(req.headers);
62
61
  validateRequestPart('headers', headers, $headers, lookup);
63
62
  }
64
63
  if ($search) {
@@ -1,3 +0,0 @@
1
- export declare function toObject<TKey extends string | number | symbol, TValue>(iterable: {
2
- [Symbol.iterator](): IterableIterator<[TKey, TValue]>;
3
- }): Record<TKey, TValue>;
package/dist/to-object.js DELETED
@@ -1,7 +0,0 @@
1
- export function toObject(iterable) {
2
- const obj = Object.create(null);
3
- for (const [key, value] of iterable) {
4
- obj[key] = value;
5
- }
6
- return obj;
7
- }
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
- }