@cfworker/web 1.12.0 → 1.12.3

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/router.d.ts CHANGED
@@ -36,5 +36,5 @@ export declare class Router {
36
36
  all(pathname: string, ...middleware: Middleware[]): this;
37
37
  middleware: Middleware;
38
38
  compose(conditions: RouteCondition[], ...middleware: Middleware[]): this;
39
- private resolve;
39
+ resolve(ctx: Context): Route | undefined;
40
40
  }
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.3",
4
4
  "description": "Web framework for Cloudflare Workers and service workers, inspired by Koa and fastify",
5
5
  "keywords": [
6
6
  "middleware",
@@ -34,27 +34,26 @@
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.2",
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
- "cookie": "^0.4.1",
43
+ "cookie": "^0.4.2",
45
44
  "html-escaper": "^3.0.3",
46
- "negotiator": "^0.6.2",
45
+ "negotiator": "^0.6.3",
47
46
  "path-to-regexp": "^6.2.0",
48
47
  "secure-json-parse": "^2.4.0",
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",
55
- "chai": "^4.3.4",
56
- "json-pointer": "^0.6.1",
57
- "mocha": "^9.1.3",
58
- "typescript": "^4.5.2"
51
+ "@cfworker/dev": "^1.14.0",
52
+ "@types/chai": "^4.3.0",
53
+ "@types/mocha": "^9.1.0",
54
+ "chai": "^4.3.6",
55
+ "jsonpointer": "^5.0.0",
56
+ "mocha": "^9.2.1",
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/router.ts CHANGED
@@ -117,7 +117,7 @@ export class Router {
117
117
  return this;
118
118
  }
119
119
 
120
- private resolve(ctx: Context) {
120
+ public resolve(ctx: Context) {
121
121
  return this.routes.find(
122
122
  ({ conditions }) =>
123
123
  conditions.length === 0 || conditions.every(c => c(ctx))
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
- }