@ts-pf/protocol 0.5.0 → 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/PROTOCOL.md +3 -1
- package/README.md +1 -1
- package/conformance/README.md +15 -1
- package/package.json +1 -1
- package/skills/ts-pf-protocol/SKILL.md +1 -1
package/PROTOCOL.md
CHANGED
|
@@ -677,7 +677,9 @@ There is no session resumption: a new connection starts with `hello`, and no id,
|
|
|
677
677
|
|
|
678
678
|
Language-neutral test vectors for this document live in [`conformance/`](https://github.com/crobinson42/ts-pf/tree/main/packages/protocol/conformance) next to it, and ship in the `@ts-pf/protocol` npm package: `http.json` (unary JSON requests and response classification), `http-stream.json` (`application/jsonl` output streams), and `ws.json` (WebSocket frame scripts, which also cover stdio and `MessagePort` minus binary messages and close codes). They are plain JSON data, not schemas. A client in any language replays them against its own code, with no server and no network; the directory's `README.md` defines the format, how a runner replays each file, and how to report results.
|
|
679
679
|
|
|
680
|
-
Each file carries `"protocol": 1` and the `"revision"` of this document it was written against, and each case cites the sections it checks. Where a case and this document disagree, this document wins. The TypeScript reference client (`FetchLink`, `FetchLink` with `StreamCodec`, `WsLink`) replays every file in this repository's CI.
|
|
680
|
+
Each file carries `"protocol": 1` and the `"revision"` of this document it was written against, and each case cites the sections it checks. Where a case and this document disagree, this document wins. The TypeScript reference client (`FetchLink`, `FetchLink` with `StreamCodec`, `WsLink`) replays every file in this repository's CI. Test against a pinned package version, for example `https://cdn.jsdelivr.net/npm/@ts-pf/protocol@<version>/conformance/ws.json` (the fixtures README lists the options).
|
|
681
|
+
|
|
682
|
+
For a walkthrough of building a client in another language from this document (models, transport, response classification, streams, fixtures, drift), see the guide [Clients in other languages](https://github.com/crobinson42/ts-pf/blob/main/docs/other-languages.md).
|
|
681
683
|
|
|
682
684
|
## Appendix: TypeScript reference client
|
|
683
685
|
|
package/README.md
CHANGED
|
@@ -45,7 +45,7 @@ Detect a failure with `isPFError(error)` rather than `instanceof PFError`: it al
|
|
|
45
45
|
|
|
46
46
|
Two helpers the transports share, for codecs and adapters of your own: `toWireError(error)` is the `error` object of a failure envelope for any thrown value — a `PFError`'s `toJSON()`, anything else a fixed `{ code: 'INTERNAL', message: 'Internal server error' }` with no stack or message leak (log the original yourself). The message transports use it for the `hello-error` of a refused connection too, so a `PFError` thrown from a message handler's context factory reaches the client as its code. `isAsyncIterable(value)` is the one answer to "is this a stream" (a non-null object or function with a `Symbol.asyncIterator` function; a `ReadableStream` counts on Node, so exclude it at a site that wants bytes). `defined(obj)` returns a shallow copy without the keys whose value is `undefined`, typed with those keys optional — the one helper for forwarding optional fields under `exactOptionalPropertyTypes` (`{ ...required, ...defined({ signal }) }`).
|
|
47
47
|
|
|
48
|
-
Wire spec: [`PROTOCOL.md`](https://github.com/crobinson42/ts-pf/blob/main/packages/protocol/PROTOCOL.md), revision 1.2 (also shipped in this package). It is written for implementers in any language: RFC 2119 keywords, one-screen HTTP and WebSocket client checklists, the rule for classifying an HTTP response (a body that does not decode as an envelope is a transport failure, never an application outcome read off the HTTP status), WebSocket close-code ranges, and the TypeScript client's own conventions (`local`, `status: 0`, error messages) in an appendix. Happy path: [root README](https://github.com/crobinson42/ts-pf#readme).
|
|
48
|
+
Wire spec: [`PROTOCOL.md`](https://github.com/crobinson42/ts-pf/blob/main/packages/protocol/PROTOCOL.md), revision 1.2 (also shipped in this package). It is written for implementers in any language: RFC 2119 keywords, one-screen HTTP and WebSocket client checklists, the rule for classifying an HTTP response (a body that does not decode as an envelope is a transport failure, never an application outcome read off the HTTP status), WebSocket close-code ranges, and the TypeScript client's own conventions (`local`, `status: 0`, error messages) in an appendix. Building a client in another language: the guide [Clients in other languages](https://github.com/crobinson42/ts-pf/blob/main/docs/other-languages.md). Happy path: [root README](https://github.com/crobinson42/ts-pf#readme).
|
|
49
49
|
|
|
50
50
|
Conformance fixtures: [`conformance/`](https://github.com/crobinson42/ts-pf/tree/main/packages/protocol/conformance) (also shipped in this package) holds language-neutral JSON test vectors versioned with the spec revision — `http.json` (unary requests and response classification), `http-stream.json` (JSONL streams), and `ws.json` (WebSocket frame scripts). A client written in any language replays them against its own code to prove it follows `PROTOCOL.md`; the directory's `README.md` is the runner spec. They are data, not schemas. The TypeScript clients are tested against the same files. TypeScript runners can import them typed:
|
|
51
51
|
|
package/conformance/README.md
CHANGED
|
@@ -10,6 +10,20 @@ Language-neutral test vectors for [`PROTOCOL.md`](../PROTOCOL.md). A client in a
|
|
|
10
10
|
|
|
11
11
|
The files are data, not schemas: plain JSON, readable without a validator. They ship in the `@ts-pf/protocol` npm package (`conformance/`), and TypeScript can import them typed from `@ts-pf/protocol/conformance`.
|
|
12
12
|
|
|
13
|
+
Building a client from scratch? The guide [Clients in other languages](https://github.com/crobinson42/ts-pf/blob/main/docs/other-languages.md) puts the spec, the fixtures, and code generation in order.
|
|
14
|
+
|
|
15
|
+
## Getting the files
|
|
16
|
+
|
|
17
|
+
Pin the package version you test against, and never follow `latest`: a new revision may add cases. You do not need npm:
|
|
18
|
+
|
|
19
|
+
| Source | URL or command |
|
|
20
|
+
| -------- | --------------------------------------------------------------------------------------- |
|
|
21
|
+
| jsDelivr | `https://cdn.jsdelivr.net/npm/@ts-pf/protocol@<version>/conformance/<file>.json` |
|
|
22
|
+
| unpkg | `https://unpkg.com/@ts-pf/protocol@<version>/conformance/<file>.json` |
|
|
23
|
+
| npm | `npm pack @ts-pf/protocol@<version>`, then read `package/conformance/` from the tarball |
|
|
24
|
+
|
|
25
|
+
Commit the files your tests use next to a note of the version (or download them in CI from a pinned URL), so a fixture change reaches you as a reviewed diff.
|
|
26
|
+
|
|
13
27
|
## Versioning
|
|
14
28
|
|
|
15
29
|
Every file starts with:
|
|
@@ -135,7 +149,7 @@ Open the connection before the first step, configured with `options` when the ca
|
|
|
135
149
|
| `receive` | Deliver this frame to the client as one compact JSON text message. Some are invalid on purpose. |
|
|
136
150
|
| `receiveText` | Deliver this exact string as a text message (it need not be JSON). |
|
|
137
151
|
| `receiveBinary` | Deliver these bytes (base64) as a binary message. |
|
|
138
|
-
| `serverClose` | The server closes the connection (the value is `{}`). |
|
|
152
|
+
| `serverClose` | The server closes the connection (the value is `{}`). |
|
|
139
153
|
| `call` | The caller starts a call labelled by the value (`"a"`) with `path` and `input` (absent: no input), or with `inputStream`: a streamed input that yields those values and then completes. |
|
|
140
154
|
| `abort` | The caller gives up on call `"a"`: abort it if it is still pending, or stop reading it if it resolved to a stream. |
|
|
141
155
|
| `expect` | An outcome the caller observes, below. |
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@ Install: `npm i @ts-pf/protocol`
|
|
|
11
11
|
|
|
12
12
|
Link for agents: `npx skills experimental_sync -y`
|
|
13
13
|
|
|
14
|
-
Wire spec ships as `PROTOCOL.md` in this package (revision 1.2). Building a client in another language: start from
|
|
14
|
+
Wire spec ships as `PROTOCOL.md` in this package (revision 1.2). Building a client in another language: the guide [Clients in other languages](https://github.com/crobinson42/ts-pf/blob/main/docs/other-languages.md) walks through models, transport, streams, fixtures, and drift. Normatively, start from `PROTOCOL.md`'s "HTTP client checklist" / "WebSocket client checklist" and "Classifying an HTTP response" sections; TypeScript-only conventions (`local`, `status: 0`, `isLocalFailure`) are in its appendix. Prove the client with the language-neutral fixtures in this package's `conformance/` (`http.json`, `http-stream.json`, `ws.json`; plain JSON versioned with the spec revision; `conformance/README.md` says how to replay them). TypeScript runners import them typed from `@ts-pf/protocol/conformance`.
|
|
15
15
|
|
|
16
16
|
## Do
|
|
17
17
|
|