@statewalker/webrun-http-proxy 0.2.3 → 0.3.0

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 CHANGED
@@ -39,7 +39,7 @@ pnpm add @statewalker/webrun-http-proxy
39
39
  | --- | --- |
40
40
  | `urlUpstream(init)` | Returns an `Upstream` that re-issues requests against `init.base`. |
41
41
  | `UrlUpstreamInit` | Its options (below). |
42
- | `Upstream`, `FetchHandler` | Both `(request: Request) => Promise<Response>`. |
42
+ | `Upstream`, `FetchHandler` | Both `(request: Request) => Response \| Promise<Response>`: the same type as `FetchHandler` in `@statewalker/webrun-http-streams`, declared here to keep zero dependencies. |
43
43
  | `MARKER` | `"x-webrun-proxy"`, the header on responses this package makes itself. |
44
44
 
45
45
  | `UrlUpstreamInit` field | Default | Meaning |
package/dist/proxy.d.ts CHANGED
@@ -23,17 +23,19 @@
23
23
  * upstream call running. It is forwarded.
24
24
  */
25
25
  /**
26
- * A handler, in the only shape this package needs.
26
+ * A handler: sync or async, as a Service Worker's or a Durable Object's `fetch`.
27
27
  *
28
- * Declared here rather than imported: it is one line, and depending on another
29
- * package for it would give a proxy a dependency it has no other use for.
28
+ * The same type as `FetchHandler` in `@statewalker/webrun-http-streams` (a type
29
+ * test there keeps them identical). Declared here rather than imported: it is
30
+ * one line, and depending on another package for it would give a proxy a
31
+ * dependency it has no other use for.
30
32
  */
31
- export type FetchHandler = (request: Request) => Promise<Response>;
33
+ export type FetchHandler = (request: Request) => Response | Promise<Response>;
32
34
  /** Marks this layer's OWN responses, so they are never mistaken for an upstream's. Same header the proxy already uses. */
33
35
  export declare const MARKER = "x-webrun-proxy";
34
36
  /**
35
37
  * An upstream is just a handler. That is the whole merge: a local service, a
36
- * remote origin and another peer are all `(Request) => Promise<Response>`.
38
+ * remote origin and another peer are all a `FetchHandler`.
37
39
  */
38
40
  export type Upstream = FetchHandler;
39
41
  export interface UrlUpstreamInit {
@@ -1 +1 @@
1
- {"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../src/proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEnE,0HAA0H;AAC1H,eAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC;;;GAGG;AACH,MAAM,MAAM,QAAQ,GAAG,YAAY,CAAC;AAEpC,MAAM,WAAW,eAAe;IAC9B;;;;;;;OAOG;IACH,mBAAmB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAExC,0EAA0E;IAC1E,IAAI,EAAE,MAAM,CAAC;IACb,uEAAuE;IACvE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,+FAA+F;IAC/F,UAAU,CAAC,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IACtD,qDAAqD;IACrD,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;IACzB,+CAA+C;IAC/C,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,eAAe,GAAG,QAAQ,CAkH3D"}
1
+ {"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../src/proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH;;;;;;;GAOG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAE9E,0HAA0H;AAC1H,eAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC;;;GAGG;AACH,MAAM,MAAM,QAAQ,GAAG,YAAY,CAAC;AAEpC,MAAM,WAAW,eAAe;IAC9B;;;;;;;OAOG;IACH,mBAAmB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAExC,0EAA0E;IAC1E,IAAI,EAAE,MAAM,CAAC;IACb,uEAAuE;IACvE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,+FAA+F;IAC/F,UAAU,CAAC,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IACtD,qDAAqD;IACrD,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;IACzB,+CAA+C;IAC/C,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,eAAe,GAAG,QAAQ,CAkH3D"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statewalker/webrun-http-proxy",
3
- "version": "0.2.3",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "description": "Re-issue an HTTP request to an outside origin, safely: credentials consumed, hop-by-hop headers dropped, body streamed.",
6
6
  "bugs": {
@@ -35,7 +35,7 @@
35
35
  "rimraf": "^6.1.3",
36
36
  "rolldown": "^1.2.12",
37
37
  "typescript": "^7.0.2",
38
- "vitest": "^5.0.3"
38
+ "vitest": "^5.0.5"
39
39
  },
40
40
  "publishConfig": {
41
41
  "access": "public"
package/src/proxy.ts CHANGED
@@ -24,19 +24,21 @@
24
24
  */
25
25
 
26
26
  /**
27
- * A handler, in the only shape this package needs.
27
+ * A handler: sync or async, as a Service Worker's or a Durable Object's `fetch`.
28
28
  *
29
- * Declared here rather than imported: it is one line, and depending on another
30
- * package for it would give a proxy a dependency it has no other use for.
29
+ * The same type as `FetchHandler` in `@statewalker/webrun-http-streams` (a type
30
+ * test there keeps them identical). Declared here rather than imported: it is
31
+ * one line, and depending on another package for it would give a proxy a
32
+ * dependency it has no other use for.
31
33
  */
32
- export type FetchHandler = (request: Request) => Promise<Response>;
34
+ export type FetchHandler = (request: Request) => Response | Promise<Response>;
33
35
 
34
36
  /** Marks this layer's OWN responses, so they are never mistaken for an upstream's. Same header the proxy already uses. */
35
37
  export const MARKER = "x-webrun-proxy";
36
38
 
37
39
  /**
38
40
  * An upstream is just a handler. That is the whole merge: a local service, a
39
- * remote origin and another peer are all `(Request) => Promise<Response>`.
41
+ * remote origin and another peer are all a `FetchHandler`.
40
42
  */
41
43
  export type Upstream = FetchHandler;
42
44