@ts-pf/server-http 0.3.2 → 0.3.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/README.md CHANGED
@@ -18,7 +18,7 @@ const handler = new FetchHandler(app, {
18
18
  const result = await handler.handle(request, { prefix: '/rpc', context: { db } })
19
19
  ```
20
20
 
21
- Options: `codec`, `plugins`, `interceptors`, `validation`, and `onError(error, { request, path, context })` (type `FetchHandlerOnError`). Without `onError`, unknown throws and `INTERNAL` errors are logged with `console.error`; passing it replaces that logging. Mid-stream errors are in-band codec items and reach neither. A JSON envelope object with keys but no `input` key is `400 BAD_REQUEST` from the codec; `{}` and `{"input":null}` still mean no input. A request `x-ts-pf-protocol` header that is present and not `1` is `400 BAD_REQUEST` `Unsupported protocol version` before the body is read; a missing header is accepted.
21
+ Options: `codec`, `plugins`, `interceptors`, `validation`, and `onError(error, { request, path, context })` (type `FetchHandlerOnError`). Without `onError`, unknown throws and `INTERNAL` errors are logged with `console.error`; passing it replaces that logging. Mid-stream errors are in-band codec items and reach neither. A JSON envelope object with keys but no `input` key is `400 BAD_REQUEST` from the codec; `{}` and `{"input":null}` still mean no input. A request `x-ts-pf-protocol` header that is present and not `1` is `400 BAD_REQUEST` `Unsupported protocol version` before the body is read; a missing header is accepted. `RequestLimitPlugin` rewraps any request with a body, so the context factory and plugin hooks see a plain `Request`; read host extras (srvx `request.ip`) from the request your host passed.
22
22
 
23
23
  Do not import this package from `@ts-pf/client-http`.
24
24
 
@@ -1 +1 @@
1
- {"version":3,"file":"request-limit-plugin.d.ts","sourceRoot":"","sources":["../src/request-limit-plugin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAEjD,MAAM,MAAM,yBAAyB,GAAG;IACtC,WAAW,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,qBAAa,kBAAmB,YAAW,aAAa;IACtD,QAAQ,CAAC,IAAI,mBAAkB;IAC/B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAQ;gBAExB,OAAO,EAAE,yBAAyB;IAI9C,SAAS,CAAC,EAAE,OAAO,EAAE,EAAE;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,GAAG,SAAS;CA2BlE"}
1
+ {"version":3,"file":"request-limit-plugin.d.ts","sourceRoot":"","sources":["../src/request-limit-plugin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAEjD,MAAM,MAAM,yBAAyB,GAAG;IACtC,WAAW,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,qBAAa,kBAAmB,YAAW,aAAa;IACtD,QAAQ,CAAC,IAAI,mBAAkB;IAC/B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAQ;gBAExB,OAAO,EAAE,yBAAyB;IAI9C,SAAS,CAAC,EAAE,OAAO,EAAE,EAAE;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,GAAG,SAAS;CAgClE"}
@@ -25,7 +25,12 @@ export class RequestLimitPlugin {
25
25
  controller.enqueue(chunk);
26
26
  },
27
27
  }));
28
- return new Request(request, {
28
+ // Built from the URL, not `new Request(request, init)`: userland Node
29
+ // bridges (srvx) hand over Request-shaped objects that undici cannot clone.
30
+ return new Request(request.url, {
31
+ method: request.method,
32
+ headers: request.headers,
33
+ signal: request.signal,
29
34
  body: limited,
30
35
  duplex: 'half',
31
36
  });
@@ -1 +1 @@
1
- {"version":3,"file":"request-limit-plugin.js","sourceRoot":"","sources":["../src/request-limit-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAOzC,MAAM,OAAO,kBAAkB;IACpB,IAAI,GAAG,eAAe,CAAA;IACd,WAAW,CAAQ;IAEpC,YAAY,OAAkC;QAC5C,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAA;IACxC,CAAC;IAED,SAAS,CAAC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OAAO,CAAC;QACjB,IAAI,EAAE,mBAAmB;QACzB,OAAO,EAAE,wBAAwB;KAClC,CAAC,CAAA;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ts-pf/server-http",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "Fetch Request/Response handler and HTTP HandlerPlugins",
5
5
  "keywords": [
6
6
  "ts-pf",
@@ -40,6 +40,10 @@ return result.response
40
40
 
41
41
  `plugins` is HTTP-only (`HandlerPlugin`). RPC call interceptors go on `{ interceptors }` from `@ts-pf/server`. `validation` is the same `ProcedureValidation` as `runProcedure`: input checks default on, output and stream output items run only with `{ validation: { output: true } }`. Set it on the constructor, not on `handle()`. `CORSPlugin` answers `OPTIONS` preflight.
42
42
 
43
+ `RequestLimitPlugin` rewraps any request with a body (to count its bytes), so the context factory, plugin hooks, and `onError` see a plain `Request`; bodyless requests keep your host's object. Read host extras such as srvx's `request.ip` / `request.runtime` from the request your host passed, typed as srvx's `ServerRequest`: `context: (req) => ({ req, ip: request.ip })`.
44
+
45
+ A custom `HandlerPlugin` that returns a new request builds it with `new Request(request.url, { method, headers, signal, body, duplex: 'half' })` (cast the init as `RequestInit & { duplex: 'half' }` under DOM types), not `new Request(request, init)`, which throws on srvx's Node request.
46
+
43
47
  ## Errors
44
48
 
45
49
  Unknown throws become `500 INTERNAL` with no stack on the wire. By default `FetchHandler` logs them with `console.error` (the original thrown value, tagged `[ts-pf/server-http]` with the procedure path). It also logs `INTERNAL` `PFError`s — an output schema failure under `validation.output`, invalid declared error `data`, or an explicit `INTERNAL` throw — naming those causes. Declared errors and every other protocol code (`VALIDATION`, `NOT_FOUND`, `BAD_REQUEST`, `METHOD_NOT_ALLOWED`, `PAYLOAD_TOO_LARGE`) are expected and are not logged.