@ts-pf/http 0.1.0-beta.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 ADDED
@@ -0,0 +1,9 @@
1
+ # @ts-pf/http
2
+
3
+ HTTP wire helpers for ts-pf: `JSONCodec`, `RpcCodec`, `PROTOCOL_HEADER`, URL path join/parse, and `httpStatus`. Analog of [`@ts-pf/message`](../message).
4
+
5
+ Agent skill: [`skills/ts-pf-http/`](skills/ts-pf-http/). Sync with `npx skills experimental_sync -y`.
6
+
7
+ Does **not** include `FetchHandler` or `FetchLink`. Those live in [`@ts-pf/server-http`](../server-http) and [`@ts-pf/client-http`](../client-http).
8
+
9
+ Wire spec: [`packages/protocol/PROTOCOL.md`](../protocol/PROTOCOL.md).
@@ -0,0 +1,14 @@
1
+ import { type RpcRequest, type RpcResponse } from '@ts-pf/protocol';
2
+ import type { RpcBodySource, RpcCodec, RpcEncodedBody } from './rpc.js';
3
+ export declare class JSONCodec implements RpcCodec {
4
+ encodeRequest(req: RpcRequest): RpcEncodedBody;
5
+ decodeRequest(source: RpcBodySource): Promise<RpcRequest>;
6
+ encodeSuccess<T>(output: T): RpcEncodedBody;
7
+ encodeFailure(error: {
8
+ code: string;
9
+ message: string;
10
+ data?: unknown;
11
+ }): RpcEncodedBody;
12
+ decodeResponse<T = unknown>(source: RpcBodySource): Promise<RpcResponse<T>>;
13
+ }
14
+ //# sourceMappingURL=codec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../src/codec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAC5E,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAkBvE,qBAAa,SAAU,YAAW,QAAQ;IACxC,aAAa,CAAC,GAAG,EAAE,UAAU,GAAG,cAAc;IAOxC,aAAa,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,UAAU,CAAC;IAqB/D,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,cAAc;IAI3C,aAAa,CAAC,KAAK,EAAE;QACnB,IAAI,EAAE,MAAM,CAAA;QACZ,OAAO,EAAE,MAAM,CAAA;QACf,IAAI,CAAC,EAAE,OAAO,CAAA;KACf,GAAG,cAAc;IAWZ,cAAc,CAAC,CAAC,GAAG,OAAO,EAC9B,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;CAiC3B"}
package/dist/codec.js ADDED
@@ -0,0 +1,83 @@
1
+ import { PFError } from '@ts-pf/protocol';
2
+ function parseJson(body) {
3
+ try {
4
+ return JSON.parse(body);
5
+ }
6
+ catch {
7
+ throw new PFError({
8
+ code: 'BAD_REQUEST',
9
+ status: 400,
10
+ message: 'Invalid JSON',
11
+ });
12
+ }
13
+ }
14
+ function jsonBody(body) {
15
+ return { contentType: 'application/json', body };
16
+ }
17
+ export class JSONCodec {
18
+ encodeRequest(req) {
19
+ if (req.input === undefined) {
20
+ return jsonBody('{}');
21
+ }
22
+ return jsonBody(JSON.stringify({ input: req.input }));
23
+ }
24
+ async decodeRequest(source) {
25
+ const text = await source.text();
26
+ const parsed = parseJson(text.length > 0 ? text : '{}');
27
+ if (parsed === null ||
28
+ typeof parsed !== 'object' ||
29
+ Array.isArray(parsed)) {
30
+ throw new PFError({
31
+ code: 'BAD_REQUEST',
32
+ status: 400,
33
+ message: 'Request body must be a JSON object',
34
+ });
35
+ }
36
+ const input = parsed.input;
37
+ if (input === undefined || input === null) {
38
+ return { input: undefined };
39
+ }
40
+ return { input };
41
+ }
42
+ encodeSuccess(output) {
43
+ return jsonBody(JSON.stringify({ ok: true, output }));
44
+ }
45
+ encodeFailure(error) {
46
+ const payload = {
47
+ code: error.code,
48
+ message: error.message,
49
+ };
50
+ if (error.data !== undefined) {
51
+ payload.data = error.data;
52
+ }
53
+ return jsonBody(JSON.stringify({ ok: false, error: payload }));
54
+ }
55
+ async decodeResponse(source) {
56
+ const parsed = parseJson(await source.text());
57
+ if (parsed === null ||
58
+ typeof parsed !== 'object' ||
59
+ Array.isArray(parsed)) {
60
+ throw new PFError({
61
+ code: 'BAD_REQUEST',
62
+ status: 400,
63
+ message: 'Response body must be a JSON object',
64
+ });
65
+ }
66
+ const value = parsed;
67
+ if (value.ok === true) {
68
+ return { ok: true, output: value.output };
69
+ }
70
+ if (value.ok === false && value.error && typeof value.error === 'object') {
71
+ return {
72
+ ok: false,
73
+ error: value.error,
74
+ };
75
+ }
76
+ throw new PFError({
77
+ code: 'BAD_REQUEST',
78
+ status: 400,
79
+ message: 'Invalid RPC envelope',
80
+ });
81
+ }
82
+ }
83
+ //# sourceMappingURL=codec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codec.js","sourceRoot":"","sources":["../src/codec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAqC,MAAM,iBAAiB,CAAA;AAG5E,SAAS,SAAS,CAAC,IAAY;IAC7B,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAY,CAAA;IACpC,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,OAAO,CAAC;YAChB,IAAI,EAAE,aAAa;YACnB,MAAM,EAAE,GAAG;YACX,OAAO,EAAE,cAAc;SACxB,CAAC,CAAA;IACJ,CAAC;AACH,CAAC;AAED,SAAS,QAAQ,CAAC,IAAY;IAC5B,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,IAAI,EAAE,CAAA;AAClD,CAAC;AAED,MAAM,OAAO,SAAS;IACpB,aAAa,CAAC,GAAe;QAC3B,IAAI,GAAG,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YAC5B,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAA;QACvB,CAAC;QACD,OAAO,QAAQ,CAAC,IAAI,CAAC,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,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC,CAAA;IAChE,CAAC;IAED,KAAK,CAAC,cAAc,CAClB,MAAqB;QAErB,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC,CAAA;QAC7C,IACE,MAAM,KAAK,IAAI;YACf,OAAO,MAAM,KAAK,QAAQ;YAC1B,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EACrB,CAAC;YACD,MAAM,IAAI,OAAO,CAAC;gBAChB,IAAI,EAAE,aAAa;gBACnB,MAAM,EAAE,GAAG;gBACX,OAAO,EAAE,qCAAqC;aAC/C,CAAC,CAAA;QACJ,CAAC;QACD,MAAM,KAAK,GAAG,MAIb,CAAA;QACD,IAAI,KAAK,CAAC,EAAE,KAAK,IAAI,EAAE,CAAC;YACtB,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,MAAW,EAAE,CAAA;QAChD,CAAC;QACD,IAAI,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI,KAAK,CAAC,KAAK,IAAI,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;YACzE,OAAO;gBACL,EAAE,EAAE,KAAK;gBACT,KAAK,EAAE,KAAK,CAAC,KAA0D;aACxE,CAAA;QACH,CAAC;QACD,MAAM,IAAI,OAAO,CAAC;YAChB,IAAI,EAAE,aAAa;YACnB,MAAM,EAAE,GAAG;YACX,OAAO,EAAE,sBAAsB;SAChC,CAAC,CAAA;IACJ,CAAC;CACF"}
@@ -0,0 +1,11 @@
1
+ import type { PFError } from '@ts-pf/protocol';
2
+ export declare const PROTOCOL_HTTP_STATUS: {
3
+ readonly BAD_REQUEST: 400;
4
+ readonly VALIDATION: 422;
5
+ readonly NOT_FOUND: 404;
6
+ readonly METHOD_NOT_ALLOWED: 405;
7
+ readonly PAYLOAD_TOO_LARGE: 413;
8
+ readonly INTERNAL: 500;
9
+ };
10
+ export declare function httpStatus(error: PFError): number;
11
+ //# sourceMappingURL=http-status.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-status.d.ts","sourceRoot":"","sources":["../src/http-status.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAE9C,eAAO,MAAM,oBAAoB;;;;;;;CAOvB,CAAA;AAEV,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAQjD"}
@@ -0,0 +1,18 @@
1
+ export const PROTOCOL_HTTP_STATUS = {
2
+ BAD_REQUEST: 400,
3
+ VALIDATION: 422,
4
+ NOT_FOUND: 404,
5
+ METHOD_NOT_ALLOWED: 405,
6
+ PAYLOAD_TOO_LARGE: 413,
7
+ INTERNAL: 500,
8
+ };
9
+ export function httpStatus(error) {
10
+ if (error.local === true) {
11
+ return 0;
12
+ }
13
+ if (Object.hasOwn(PROTOCOL_HTTP_STATUS, error.code)) {
14
+ return PROTOCOL_HTTP_STATUS[error.code];
15
+ }
16
+ return error.status;
17
+ }
18
+ //# sourceMappingURL=http-status.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-status.js","sourceRoot":"","sources":["../src/http-status.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,WAAW,EAAE,GAAG;IAChB,UAAU,EAAE,GAAG;IACf,SAAS,EAAE,GAAG;IACd,kBAAkB,EAAE,GAAG;IACvB,iBAAiB,EAAE,GAAG;IACtB,QAAQ,EAAE,GAAG;CACL,CAAA;AAEV,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,IAAI,KAAK,CAAC,KAAK,KAAK,IAAI,EAAE,CAAC;QACzB,OAAO,CAAC,CAAA;IACV,CAAC;IACD,IAAI,MAAM,CAAC,MAAM,CAAC,oBAAoB,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QACpD,OAAO,oBAAoB,CAAC,KAAK,CAAC,IAAyC,CAAC,CAAA;IAC9E,CAAC;IACD,OAAO,KAAK,CAAC,MAAM,CAAA;AACrB,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { JSONCodec } from './codec.js';
2
+ export { httpStatus, PROTOCOL_HTTP_STATUS } from './http-status.js';
3
+ export { joinProcedurePath, parseProcedurePath } from './path.js';
4
+ export { PROTOCOL_HEADER, type RpcBodySource, type RpcCodec, type RpcEncodedBody, } from './rpc.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AACnE,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAA;AACjE,OAAO,EACL,eAAe,EACf,KAAK,aAAa,EAClB,KAAK,QAAQ,EACb,KAAK,cAAc,GACpB,MAAM,UAAU,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { JSONCodec } from './codec.js';
2
+ export { httpStatus, PROTOCOL_HTTP_STATUS } from './http-status.js';
3
+ export { joinProcedurePath, parseProcedurePath } from './path.js';
4
+ export { PROTOCOL_HEADER, } from './rpc.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AACnE,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAA;AACjE,OAAO,EACL,eAAe,GAIhB,MAAM,UAAU,CAAA"}
package/dist/path.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export declare function joinProcedurePath(prefix: string, segments: readonly string[]): string;
2
+ export declare function parseProcedurePath(pathname: string, prefix: string): string[] | null;
3
+ //# sourceMappingURL=path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../src/path.ts"],"names":[],"mappings":"AAKA,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,SAAS,MAAM,EAAE,GAC1B,MAAM,CAMR;AAED,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GACb,MAAM,EAAE,GAAG,IAAI,CAiBjB"}
package/dist/path.js ADDED
@@ -0,0 +1,29 @@
1
+ function normalizePrefix(prefix) {
2
+ const withLeading = prefix.startsWith('/') ? prefix : `/${prefix}`;
3
+ return withLeading.endsWith('/') ? withLeading.slice(0, -1) : withLeading;
4
+ }
5
+ export function joinProcedurePath(prefix, segments) {
6
+ const base = normalizePrefix(prefix);
7
+ if (segments.length === 0) {
8
+ return base;
9
+ }
10
+ return `${base}/${segments.join('/')}`;
11
+ }
12
+ export function parseProcedurePath(pathname, prefix) {
13
+ const base = normalizePrefix(prefix);
14
+ const path = pathname.endsWith('/') && pathname.length > 1
15
+ ? pathname.slice(0, -1)
16
+ : pathname;
17
+ if (path === base) {
18
+ return [];
19
+ }
20
+ if (!path.startsWith(`${base}/`)) {
21
+ return null;
22
+ }
23
+ const rest = path.slice(base.length + 1);
24
+ if (rest.length === 0) {
25
+ return [];
26
+ }
27
+ return rest.split('/');
28
+ }
29
+ //# sourceMappingURL=path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path.js","sourceRoot":"","sources":["../src/path.ts"],"names":[],"mappings":"AAAA,SAAS,eAAe,CAAC,MAAc;IACrC,MAAM,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,MAAM,EAAE,CAAA;IAClE,O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 import type { RpcRequest, RpcResponse } from '@ts-pf/protocol';
2
+ export declare const PROTOCOL_HEADER = "x-ts-pf-protocol";
3
+ export interface RpcEncodedBody {
4
+ readonly contentType: string;
5
+ readonly body: string | Blob | FormData | ReadableStream<Uint8Array> | null;
6
+ }
7
+ export interface RpcBodySource {
8
+ readonly contentType: string | null;
9
+ text(): Promise<string>;
10
+ formData(): Promise<FormData>;
11
+ body(): ReadableStream<Uint8Array> | null;
12
+ }
13
+ export interface RpcCodec {
14
+ encodeRequest(req: RpcRequest): RpcEncodedBody | Promise<RpcEncodedBody>;
15
+ decodeRequest(source: RpcBodySource): RpcRequest | Promise<RpcRequest>;
16
+ encodeSuccess<T>(output: T): RpcEncodedBody | Promise<RpcEncodedBody>;
17
+ encodeFailure(error: {
18
+ code: string;
19
+ message: string;
20
+ data?: unknown;
21
+ }): RpcEncodedBody | Promise<RpcEncodedBody>;
22
+ decodeResponse<T = unknown>(source: RpcBodySource): RpcResponse<T> | Promise<RpcResponse<T>>;
23
+ }
24
+ //# sourceMappingURL=rpc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpc.d.ts","sourceRoot":"","sources":["../src/rpc.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAE9D,eAAO,MAAM,eAAe,qBAAqB,CAAA;AAEjD,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,QAAQ,GAAG,cAAc,CAAC,UAAU,CAAC,GAAG,IAAI,CAAA;CAC5E;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;IACnC,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAA;IACvB,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAA;IAC7B,IAAI,IAAI,cAAc,CAAC,UAAU,CAAC,GAAG,IAAI,CAAA;CAC1C;AAED,MAAM,WAAW,QAAQ;IACvB,aAAa,CAAC,GAAG,EAAE,UAAU,GAAG,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;IACxE,aAAa,CAAC,MAAM,EAAE,aAAa,GAAG,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;IACtE,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;IACrE,aAAa,CAAC,KAAK,EAAE;QACnB,IAAI,EAAE,MAAM,CAAA;QACZ,OAAO,EAAE,MAAM,CAAA;QACf,IAAI,CAAC,EAAE,OAAO,CAAA;KACf,GAAG,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;IAC5C,cAAc,CAAC,CAAC,GAAG,OAAO,EACxB,MAAM,EAAE,aAAa,GACpB,WAAW,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAA;CAC5C"}
package/dist/rpc.js ADDED
@@ -0,0 +1,2 @@
1
+ export const PROTOCOL_HEADER = 'x-ts-pf-protocol';
2
+ //# sourceMappingURL=rpc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpc.js","sourceRoot":"","sources":["../src/rpc.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,eAAe,GAAG,kBAAkB,CAAA"}
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@ts-pf/http",
3
+ "version": "0.1.0-beta.0",
4
+ "description": "HTTP wire helpers: JSONCodec, RpcCodec, PROTOCOL_HEADER, path helpers, httpStatus",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/crobinson42/ts-pf.git",
9
+ "directory": "packages/http"
10
+ },
11
+ "homepage": "https://github.com/crobinson42/ts-pf/tree/main/packages/http#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/crobinson42/ts-pf/issues"
14
+ },
15
+ "type": "module",
16
+ "sideEffects": false,
17
+ "exports": {
18
+ ".": {
19
+ "types": "./src/index.ts",
20
+ "import": "./src/index.ts"
21
+ }
22
+ },
23
+ "publishConfig": {
24
+ "access": "public",
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "import": "./dist/index.js"
29
+ }
30
+ }
31
+ },
32
+ "files": [
33
+ "dist",
34
+ "skills"
35
+ ],
36
+ "scripts": {
37
+ "build": "tsc -p tsconfig.build.json",
38
+ "test": "vitest run",
39
+ "type-check": "tsc --noEmit",
40
+ "lint": "biome check src tests"
41
+ },
42
+ "dependencies": {
43
+ "@ts-pf/protocol": "0.1.0-beta.0"
44
+ }
45
+ }
@@ -0,0 +1,42 @@
1
+ ---
2
+ name: ts-pf-http
3
+ description: Use when writing or configuring a ts-pf HTTP codec — JSONCodec, RpcCodec, PROTOCOL_HEADER, joinProcedurePath, httpStatus. Triggers: @ts-pf/http, JSONCodec, RpcCodec, PROTOCOL_HTTP_STATUS.
4
+ ---
5
+
6
+ # @ts-pf/http
7
+
8
+ HTTP wire helpers. No `FetchHandler`, no `FetchLink`.
9
+
10
+ Install: `npm i @ts-pf/http@beta`
11
+
12
+ Link for agents: `npx skills experimental_sync -y`
13
+
14
+ ## Do
15
+
16
+ ```ts
17
+ import { JSONCodec, PROTOCOL_HEADER, httpStatus, joinProcedurePath } from '@ts-pf/http'
18
+
19
+ const codec = new JSONCodec()
20
+ joinProcedurePath('/rpc', ['planet', 'find']) // '/rpc/planet/find'
21
+ httpStatus(error) // Response.status from PFError
22
+ // header name: PROTOCOL_HEADER ('x-ts-pf-protocol')
23
+ ```
24
+
25
+ `JSONCodec` is the default body. Encode returns `{ contentType, body }`. Decode takes `{ contentType, text(), formData(), body() }`.
26
+
27
+ ## API
28
+
29
+ - `JSONCodec`, `RpcCodec`, `RpcEncodedBody`, `RpcBodySource`
30
+ - `PROTOCOL_HEADER`, `joinProcedurePath`, `parseProcedurePath`
31
+ - `httpStatus`, `PROTOCOL_HTTP_STATUS`
32
+
33
+ ## Pair with
34
+
35
+ - Handler/link: `ts-pf-server-http` / `ts-pf-client-http` (they take `{ codec }`)
36
+ - Other bodies: `ts-pf-file` / `ts-pf-stream` / `ts-pf-sse`
37
+
38
+ ## Don't
39
+
40
+ - `FetchHandler` or `FetchLink` here.
41
+ - Put these exports on `@ts-pf/protocol`.
42
+ - Use this as a WebSocket / stdio framer — that is `ts-pf-message`.