@ts-pf/server-http 0.3.5 → 0.5.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/README.md +21 -1
- package/dist/handler.d.ts +10 -1
- package/dist/handler.d.ts.map +1 -1
- package/dist/handler.js +30 -8
- package/dist/handler.js.map +1 -1
- package/dist/streams.d.ts +12 -0
- package/dist/streams.d.ts.map +1 -0
- package/dist/streams.js +34 -0
- package/dist/streams.js.map +1 -0
- package/package.json +5 -5
- package/skills/ts-pf-server-http/SKILL.md +27 -4
package/README.md
CHANGED
|
@@ -18,7 +18,27 @@ 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. `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.
|
|
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, and `isUnexpectedError` from `@ts-pf/protocol` keeps the same filter: `onError: (e) => { if (isUnexpectedError(e)) logger.error(e) }`. 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. A procedure whose contract input or output is `stream()` on a codec with `streams: false` (the default `JSONCodec`, `MultipartCodec`) is `400 BAD_REQUEST` `Stream procedure requires a streaming codec`, also before the body is read and before context, middleware, or the handler run; pass `StreamCodec` / `SseCodec` to serve it. A handler that returns an `AsyncIterable` the codec does not encode as a stream gets the same answer, and the iterator is closed. `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
|
+
|
|
23
|
+
A `HandlerPlugin.onRequest` that throws answers like any protocol error: the throw takes the normal error path (`HandlerPlugin.onError`, the `onError` option or the default log, the JSON envelope with `x-ts-pf-protocol` and `httpStatus(error)`, then `onResponse`); a non-`PFError` throw is `500 INTERNAL` and logged by default. There is no `filter` option; to keep a procedure off HTTP while another transport still serves it, throw `NOT_FOUND`:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { PFError } from '@ts-pf/protocol'
|
|
27
|
+
import { FetchHandler, type HandlerPlugin } from '@ts-pf/server-http'
|
|
28
|
+
|
|
29
|
+
// `admin.*` is served over a message transport only; over HTTP it answers NOT_FOUND.
|
|
30
|
+
const hideAdmin: HandlerPlugin = {
|
|
31
|
+
name: 'hide-admin',
|
|
32
|
+
onRequest({ request }) {
|
|
33
|
+
if (new URL(request.url).pathname.startsWith('/rpc/admin/')) {
|
|
34
|
+
throw new PFError({ code: 'NOT_FOUND', message: 'Procedure not found' })
|
|
35
|
+
}
|
|
36
|
+
return undefined
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
new FetchHandler(app, { plugins: [hideAdmin] })
|
|
41
|
+
```
|
|
22
42
|
|
|
23
43
|
Do not import this package from `@ts-pf/client-http`.
|
|
24
44
|
|
package/dist/handler.d.ts
CHANGED
|
@@ -28,6 +28,10 @@ export declare class FetchHandler<TCtx = unknown> {
|
|
|
28
28
|
private readonly interceptors;
|
|
29
29
|
private readonly validation;
|
|
30
30
|
private readonly onError;
|
|
31
|
+
/** The codec says it cannot carry streams (`RpcCodec.streams === false`). */
|
|
32
|
+
private readonly rejectsStreams;
|
|
33
|
+
/** The codec says it carries streams (`RpcCodec.streams === true`); its encoding is trusted. */
|
|
34
|
+
private readonly carriesStreams;
|
|
31
35
|
constructor(router: ImplementedRouter<unknown, TCtx>, options?: {
|
|
32
36
|
codec?: RpcCodec;
|
|
33
37
|
plugins?: HandlerPlugin[];
|
|
@@ -76,7 +80,12 @@ export declare class FetchHandler<TCtx = unknown> {
|
|
|
76
80
|
private applyOnContext;
|
|
77
81
|
/** Step 4. `runProcedure` with the request signal, interceptors, and validation. */
|
|
78
82
|
private run;
|
|
79
|
-
/**
|
|
83
|
+
/**
|
|
84
|
+
* Step 5. Unless the codec declares `streams: true`, a stream output it did
|
|
85
|
+
* not encode as a `ReadableStream` (a codec that leaves `streams` unset, or
|
|
86
|
+
* a contract that does not declare `stream()`) is closed and answered like
|
|
87
|
+
* the step-1 stream check, never as a 200 with a non-stream body.
|
|
88
|
+
*/
|
|
80
89
|
private successResponse;
|
|
81
90
|
/** Step 6, side effects: `HandlerPlugin.onError` in array order, then `onError` or the default log. */
|
|
82
91
|
private reportError;
|
package/dist/handler.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,QAAQ,EAEd,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,QAAQ,EAEd,MAAM,aAAa,CAAA;AASpB,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,iBAAiB,EAEtB,KAAK,mBAAmB,EAGzB,MAAM,eAAe,CAAA;AACtB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAOjD,MAAM,MAAM,YAAY,GACpB;IAAE,OAA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AM,EAAE,MAAM,CAAA;QACd,OAAO,EAAE,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;KACzD,GACA,OAAO,CAAC,YAAY,CAAC;IA4CxB,kGAAkG;YACpF,cAAc;IAe5B;;;;OAIG;IACH,OAAO,CAAC,MAAM;IAWd,sEAAsE;YACxD,cAAc;IAY5B,oFAAoF;IACpF,OAAO,CAAC,GAAG;IAeX;;;;;OAKG;YACW,eAAe;IAa7B,uGAAuG;YACzF,WAAW;IAuBzB,OAAO,CAAC,QAAQ;IAmBhB,+FAA+F;YACjF,aAAa;IAO3B,kGAAkG;YACpF,OAAO;YAiBP,eAAe;CAkB9B"}
|
package/dist/handler.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { httpStatus, JSONCodec, PROTOCOL_HEADER, PROTOCOL_HTTP_STATUS, parseProcedurePath, } from '@ts-pf/http';
|
|
2
|
-
import { isPFError, PFError, PROTOCOL_VERSION, toWireError, } from '@ts-pf/protocol';
|
|
2
|
+
import { isAsyncIterable, isPFError, isUnexpectedError, PFError, PROTOCOL_VERSION, toWireError, } from '@ts-pf/protocol';
|
|
3
3
|
import { lookupProcedure, runProcedure, } from '@ts-pf/server';
|
|
4
|
+
import { closeUnsentStream, isStreamProcedure, streamCodecError, } from './streams.js';
|
|
4
5
|
/**
|
|
5
6
|
* `TCtx` is inferred from the router's context brand (the `$context<C>()`
|
|
6
7
|
* type behind `impl.router()`), so `handle(request, { context })` is checked
|
|
@@ -15,6 +16,10 @@ export class FetchHandler {
|
|
|
15
16
|
interceptors;
|
|
16
17
|
validation;
|
|
17
18
|
onError;
|
|
19
|
+
/** The codec says it cannot carry streams (`RpcCodec.streams === false`). */
|
|
20
|
+
rejectsStreams;
|
|
21
|
+
/** The codec says it carries streams (`RpcCodec.streams === true`); its encoding is trusted. */
|
|
22
|
+
carriesStreams;
|
|
18
23
|
constructor(router, options) {
|
|
19
24
|
this.router = router;
|
|
20
25
|
this.codec = options?.codec ?? new JSONCodec();
|
|
@@ -22,6 +27,8 @@ export class FetchHandler {
|
|
|
22
27
|
this.interceptors = options?.interceptors ?? [];
|
|
23
28
|
this.validation = options?.validation;
|
|
24
29
|
this.onError = options?.onError;
|
|
30
|
+
this.rejectsStreams = this.codec.streams === false;
|
|
31
|
+
this.carriesStreams = this.codec.streams === true;
|
|
25
32
|
}
|
|
26
33
|
/**
|
|
27
34
|
* The call pipeline (see the ts-pf skill, "Call pipeline"): each numbered
|
|
@@ -47,11 +54,14 @@ export class FetchHandler {
|
|
|
47
54
|
if (shortCircuit !== undefined) {
|
|
48
55
|
return await this.respond(state, shortCircuit);
|
|
49
56
|
}
|
|
50
|
-
// 1. method, then protocol version, then procedure
|
|
51
|
-
// answers before the body is read
|
|
57
|
+
// 1. method, then protocol version, then procedure, then the codec's
|
|
58
|
+
// stream support: a 405, 400, or 404 answers before the body is read
|
|
52
59
|
assertPost(state.request);
|
|
53
60
|
assertProtocolVersion(state.request);
|
|
54
61
|
const procedure = this.lookup(path);
|
|
62
|
+
if (this.rejectsStreams && isStreamProcedure(procedure)) {
|
|
63
|
+
throw streamCodecError();
|
|
64
|
+
}
|
|
55
65
|
// 2. decode the body
|
|
56
66
|
const decoded = await this.codec.decodeRequest(bodySource(state.request));
|
|
57
67
|
// 3. context factory, then HandlerPlugin.onContext
|
|
@@ -120,9 +130,21 @@ export class FetchHandler {
|
|
|
120
130
|
}
|
|
121
131
|
return runProcedure(procedure, input, state.context, runOpts);
|
|
122
132
|
}
|
|
123
|
-
/**
|
|
133
|
+
/**
|
|
134
|
+
* Step 5. Unless the codec declares `streams: true`, a stream output it did
|
|
135
|
+
* not encode as a `ReadableStream` (a codec that leaves `streams` unset, or
|
|
136
|
+
* a contract that does not declare `stream()`) is closed and answered like
|
|
137
|
+
* the step-1 stream check, never as a 200 with a non-stream body.
|
|
138
|
+
*/
|
|
124
139
|
async successResponse(output) {
|
|
125
|
-
|
|
140
|
+
const encoded = await this.codec.encodeSuccess(output);
|
|
141
|
+
if (!this.carriesStreams &&
|
|
142
|
+
isAsyncIterable(output) &&
|
|
143
|
+
!(encoded.body instanceof ReadableStream)) {
|
|
144
|
+
closeUnsentStream(output);
|
|
145
|
+
throw streamCodecError();
|
|
146
|
+
}
|
|
147
|
+
return encodedResponse(encoded, 200);
|
|
126
148
|
}
|
|
127
149
|
/** Step 6, side effects: `HandlerPlugin.onError` in array order, then `onError` or the default log. */
|
|
128
150
|
async reportError(error, state, path) {
|
|
@@ -142,14 +164,14 @@ export class FetchHandler {
|
|
|
142
164
|
this.logError(error, path);
|
|
143
165
|
}
|
|
144
166
|
logError(error, path) {
|
|
167
|
+
if (!isUnexpectedError(error)) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
145
170
|
const where = `"${path.join('/')}"`;
|
|
146
171
|
if (!isPFError(error)) {
|
|
147
172
|
console.error(`[ts-pf/server-http] Unhandled error in ${where}:`, error);
|
|
148
173
|
return;
|
|
149
174
|
}
|
|
150
|
-
if (error.code !== 'INTERNAL') {
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
175
|
const causes = this.validation?.output === true
|
|
154
176
|
? 'output schema failure, invalid declared error data, or an INTERNAL throw'
|
|
155
177
|
: 'invalid declared error data or an INTERNAL throw';
|
package/dist/handler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EACT,eAAe,EACf,oBAAoB,EACpB,kBAAkB,GAInB,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,SAAS,EACT,OAAO,EACP,gBAAgB,EAChB,WAAW,GACZ,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAGL,eAAe,EAGf,YAAY,GACb,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../src/handler.ts"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,OAAuB,EAAE,MAAc;IAC9D,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAA;IAC7B,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,gBAAgB,CAAC,CAAA;IAC9C,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,YAAY,QAAQ,CAAC,EAAE,CAAC;QACxC,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,OAAO,CAAC,WAAW,CAAC,CAAA;IAClD,CAAC;IACD,IAAI,OAAO,CAAC,IAAI,YAAY,cAAc,EAAE,CAAC;QAC3C,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,wBAAwB,CAAC,CAAA;QACtD,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,IAAI,CAAC,CAAA;IACxC,CAAC;IACD,OAAO,IAAI,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAA;AACxD,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PFError } from '@ts-pf/protocol';
|
|
2
|
+
import type { ImplementedProcedure } from '@ts-pf/server';
|
|
3
|
+
/** A stream procedure reached a codec that cannot carry streams. */
|
|
4
|
+
export declare function streamCodecError(): PFError;
|
|
5
|
+
/** The contract's input or output schema is a `stream()` schema. */
|
|
6
|
+
export declare function isStreamProcedure(procedure: ImplementedProcedure): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Close a stream output the codec did not encode as a stream. Never throws:
|
|
9
|
+
* a throwing or rejecting `return()` is cleanup, not the call's error.
|
|
10
|
+
*/
|
|
11
|
+
export declare function closeUnsentStream(output: AsyncIterable<unknown>): void;
|
|
12
|
+
//# sourceMappingURL=streams.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streams.d.ts","sourceRoot":"","sources":["../src/streams.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACzC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;AAWzD,oEAAoE;AACpE,wBAAgB,gBAAgB,IAAI,OAAO,CAE1C;AAMD,oEAAoE;AACpE,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,oBAAoB,GAAG,OAAO,CAG1E;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,GAAG,IAAI,CAOtE"}
|
package/dist/streams.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { PFError } from '@ts-pf/protocol';
|
|
2
|
+
/**
|
|
3
|
+
* The key `stream()` from `@ts-pf/stream` sets on its schema. Read inline:
|
|
4
|
+
* `server-http` does not depend on `@ts-pf/stream`.
|
|
5
|
+
*/
|
|
6
|
+
const STREAM_BRAND = '~pfStream';
|
|
7
|
+
/** Fixed `PROTOCOL.md` message ("Message streams"). */
|
|
8
|
+
const MESSAGE = 'Stream procedure requires a streaming codec';
|
|
9
|
+
/** A stream procedure reached a codec that cannot carry streams. */
|
|
10
|
+
export function streamCodecError() {
|
|
11
|
+
return new PFError({ code: 'BAD_REQUEST', message: MESSAGE, status: 400 });
|
|
12
|
+
}
|
|
13
|
+
function isStreamSchema(schema) {
|
|
14
|
+
return typeof schema === 'object' && schema !== null && STREAM_BRAND in schema;
|
|
15
|
+
}
|
|
16
|
+
/** The contract's input or output schema is a `stream()` schema. */
|
|
17
|
+
export function isStreamProcedure(procedure) {
|
|
18
|
+
const def = procedure['~pf'].contract['~pf'];
|
|
19
|
+
return isStreamSchema(def.input) || isStreamSchema(def.output);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Close a stream output the codec did not encode as a stream. Never throws:
|
|
23
|
+
* a throwing or rejecting `return()` is cleanup, not the call's error.
|
|
24
|
+
*/
|
|
25
|
+
export function closeUnsentStream(output) {
|
|
26
|
+
try {
|
|
27
|
+
const iterator = output[Symbol.asyncIterator]();
|
|
28
|
+
Promise.resolve(iterator.return?.()).catch(() => { });
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
// The call already failed; nothing else to close.
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=streams.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streams.js","sourceRoot":"","sources":["../src/streams.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAGzC;;;GAGG;AACH,MAAM,YAAY,GAAG,WAAW,CAAA;AAEhC,uDAAuD;AACvD,MAAM,OAAO,GAAG,6CAA6C,CAAA;AAE7D,oEAAoE;AACpE,MAAM,UAAU,gBAAgB;IAC9B,OAAO,IAAI,OAAO,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAA;AAC5E,CAAC;AAED,SAAS,cAAc,CAAC,MAAe;IACrC,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAI,YAAY,IAAI,MAAM,CAAA;AAChF,CAAC;AAED,oEAAoE;AACpE,MAAM,UAAU,iBAAiB,CAAC,SAA+B;IAC/D,MAAM,GAAG,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IAC5C,OAAO,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;AAChE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAA8B;IAC9D,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAA;QAC/C,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;IACtD,CAAC;IAAC,MAAM,CAAC;QACP,kDAAkD;IACpD,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ts-pf/server-http",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Fetch Request/Response handler and HTTP HandlerPlugins",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ts-pf",
|
|
@@ -50,12 +50,12 @@
|
|
|
50
50
|
"lint": "biome check src tests"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@ts-pf/http": "0.
|
|
54
|
-
"@ts-pf/protocol": "0.
|
|
55
|
-
"@ts-pf/server": "0.
|
|
53
|
+
"@ts-pf/http": "0.5.1",
|
|
54
|
+
"@ts-pf/protocol": "0.5.1",
|
|
55
|
+
"@ts-pf/server": "0.5.1"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@ts-pf/contract": "0.
|
|
58
|
+
"@ts-pf/contract": "0.5.1",
|
|
59
59
|
"zod": "^4.0.0"
|
|
60
60
|
}
|
|
61
61
|
}
|
|
@@ -48,24 +48,46 @@ A custom `HandlerPlugin` that returns a new request builds it with `new Request(
|
|
|
48
48
|
|
|
49
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.
|
|
50
50
|
|
|
51
|
-
Pass `onError` to route errors to your own logger. It receives the original error (before `INTERNAL` mapping) for every error response, runs after each `HandlerPlugin.onError`, cannot replace the response (a throw from it rejects `handle()`), and turns the default logging off
|
|
51
|
+
Pass `onError` to route errors to your own logger. It receives the original error (before `INTERNAL` mapping) for every error response, runs after each `HandlerPlugin.onError`, cannot replace the response (a throw from it rejects `handle()`), and turns the default logging off. To keep the default filter (unknown throws and `INTERNAL` only), use `isUnexpectedError` from `@ts-pf/protocol`:
|
|
52
52
|
|
|
53
53
|
```ts
|
|
54
|
+
import { isUnexpectedError } from '@ts-pf/protocol'
|
|
54
55
|
import { FetchHandler } from '@ts-pf/server-http'
|
|
55
56
|
|
|
56
57
|
new FetchHandler(app, {
|
|
57
|
-
onError(error, { request, path
|
|
58
|
-
|
|
58
|
+
onError(error, { request, path }) {
|
|
59
|
+
if (isUnexpectedError(error)) {
|
|
60
|
+
logger.error({ err: error, path: path.join('/'), url: request.url })
|
|
61
|
+
}
|
|
59
62
|
},
|
|
60
63
|
})
|
|
61
64
|
```
|
|
62
65
|
|
|
63
66
|
Errors thrown after a streamed response has started (`StreamCodec` / `SseCodec` output) are written in-band by the codec as `INTERNAL` items; they do not reach `onError` or the default log.
|
|
64
67
|
|
|
65
|
-
`FetchHandler` checks the method, then the protocol version, then looks the procedure up, all before it reads the body. A non-POST is `405 METHOD_NOT_ALLOWED`. A request whose `x-ts-pf-protocol` header is present and not `1` (surrounding whitespace ignored) is `400 BAD_REQUEST` `Unsupported protocol version`; a missing header is accepted, so curl and non-ts-pf clients work as before. An unknown path under the prefix is `404 NOT_FOUND`. In all
|
|
68
|
+
`FetchHandler` checks the method, then the protocol version, then looks the procedure up, all before it reads the body. A non-POST is `405 METHOD_NOT_ALLOWED`. A request whose `x-ts-pf-protocol` header is present and not `1` (surrounding whitespace ignored) is `400 BAD_REQUEST` `Unsupported protocol version`; a missing header is accepted, so curl and non-ts-pf clients work as before. An unknown path under the prefix is `404 NOT_FOUND`. A procedure whose contract input or output is `stream()` on a codec that declares `streams: false` (the default `JSONCodec`, `MultipartCodec`) is `400 BAD_REQUEST` `Stream procedure requires a streaming codec` — use `StreamCodec` / `SseCodec`. In all four cases the body is never buffered or decoded, whatever it holds (invalid JSON, a multipart upload, an oversized stream). `RequestLimitPlugin`'s `Content-Length` check runs earlier, in `onRequest`, so a declared oversize body is still `413 PAYLOAD_TOO_LARGE` on any path and for any method; only its streamed-body cap is skipped on a 404 or a stream-codec 400 because nothing reads the stream.
|
|
69
|
+
|
|
70
|
+
A `HandlerPlugin.onRequest` that throws a `PFError` is answered through the same error path (plugin `onError`, the `onError` option or default log, envelope + `x-ts-pf-protocol` + `httpStatus(error)`, `onResponse`); a non-`PFError` throw is `500 INTERNAL` (logged by default). It runs before the method check, protocol check, and lookup, on every request under the prefix, so the plugin's code wins for every method. There is no `filter` option — to keep a procedure off HTTP, throw `NOT_FOUND` for its path:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { PFError } from '@ts-pf/protocol'
|
|
74
|
+
import type { HandlerPlugin } from '@ts-pf/server-http'
|
|
75
|
+
|
|
76
|
+
const hideAdmin: HandlerPlugin = {
|
|
77
|
+
name: 'hide-admin',
|
|
78
|
+
onRequest({ request }) {
|
|
79
|
+
if (new URL(request.url).pathname.startsWith('/rpc/admin/')) {
|
|
80
|
+
throw new PFError({ code: 'NOT_FOUND', message: 'Procedure not found' })
|
|
81
|
+
}
|
|
82
|
+
return undefined
|
|
83
|
+
},
|
|
84
|
+
}
|
|
85
|
+
```
|
|
66
86
|
|
|
67
87
|
A JSON envelope object with keys but no `input` key (`{"id":1}` instead of `{"input":{"id":1}}`) is `400 BAD_REQUEST` `Request body must be {"input": ...}`, whichever codec carries it (plain JSON, the multipart `rpc` part, or a JSONL input line). `{}` and `{"input":null}` still mean no input.
|
|
68
88
|
|
|
89
|
+
A handler that returns an `AsyncIterable` the codec did not encode as a stream (a custom codec with `streams` unset, or a procedure whose contract does not declare `stream()`) also answers `400 BAD_REQUEST` `Stream procedure requires a streaming codec`, never a 200 with a JSON body; `FetchHandler` calls the iterator's `return()` once and drops its rejection.
|
|
90
|
+
|
|
69
91
|
## Cacheable reads and public REST (userland)
|
|
70
92
|
|
|
71
93
|
The wire is POST only, so a CDN or browser cannot cache a call by URL. When a read needs HTTP caching, bridge it in userland: `HandlerPlugin.onRequest` runs before the method check, so it can turn `GET {prefix}/{path}?input=<JSON>` into the POST `FetchHandler` serves. Opt in per procedure in the contract, and only for procedures with no side effects:
|
|
@@ -129,3 +151,4 @@ export async function getPlanet(id: string): Promise<Response> {
|
|
|
129
151
|
- Bridge GET for a procedure with side effects, or mark per-user data `public`.
|
|
130
152
|
- Port `HandlerPlugin` onto WS / stdio / MessagePort.
|
|
131
153
|
- Put file size caps here — those are `MultipartCodec` options.
|
|
154
|
+
- Serve `stream()` procedures through the default `JSONCodec` — they answer `400 BAD_REQUEST`.
|