@ts-pf/stream 0.5.1 → 0.6.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
@@ -19,6 +19,8 @@ new FetchLink({ url: '/rpc', codec })
19
19
  procedure.output(stream(z.object({ token: z.string() })))
20
20
  ```
21
21
 
22
+ An input `stream(item)` takes items of the item schema's input type from the sender; the handler iterates parsed items.
23
+
22
24
  Use the same codec on the handler and the link. A `stream()` procedure on the default `JSONCodec` (or `MultipartCodec`) answers `400 BAD_REQUEST` `Stream procedure requires a streaming codec` before the handler runs.
23
25
 
24
26
  Put cleanup on the handler's `signal`, not in a generator's `finally`: a cancel calls the stream's `return()`, and an async generator that was never pulled completes on `return()` without running its body, so its `finally` never runs, and a generator waiting on an `await` between yields does not see `return()` until its next `yield`. Over HTTP the handler's `signal` is `request.signal`, which fires on disconnect when your host aborts it.
package/dist/schema.d.ts CHANGED
@@ -1,4 +1,8 @@
1
1
  import type { StandardSchemaV1 } from '@standard-schema/spec';
2
- import { type InferSchemaOutput } from '@ts-pf/contract';
3
- export declare function stream<S>(item: S): StandardSchemaV1<AsyncIterable<InferSchemaOutput<S>>, AsyncIterable<InferSchemaOutput<S>>>;
2
+ import { type InferSchemaInput, type InferSchemaOutput } from '@ts-pf/contract';
3
+ /**
4
+ * A stream of `item`s. The sender's items are the item schema's input type;
5
+ * after the per-item check (a validated input stream) they are its output.
6
+ */
7
+ export declare function stream<S>(item: S): StandardSchemaV1<AsyncIterable<InferSchemaInput<S>>, AsyncIterable<InferSchemaOutput<S>>>;
4
8
  //# sourceMappingURL=schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAC7D,OAAO,EAAE,KAAK,iBAAiB,EAAkB,MAAM,iBAAiB,CAAA;AAIxE,wBAAgB,MAAM,CAAC,CAAC,EACtB,IAAI,EAAE,CAAC,GACN,gBAAgB,CACjB,aAAa,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,EACnC,aAAa,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CACpC,CAsBA"}
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAC7D,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EAEvB,MAAM,iBAAiB,CAAA;AAIxB;;;GAGG;AACH,wBAAgB,MAAM,CAAC,CAAC,EACtB,IAAI,EAAE,CAAC,GACN,gBAAgB,CACjB,aAAa,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,EAClC,aAAa,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CACpC,CAsBA"}
package/dist/schema.js CHANGED
@@ -1,6 +1,10 @@
1
- import { validateSchema } from '@ts-pf/contract';
1
+ import { validateSchema, } from '@ts-pf/contract';
2
2
  import { PFError } from '@ts-pf/protocol';
3
3
  import { isItemStream } from './item-stream.js';
4
+ /**
5
+ * A stream of `item`s. The sender's items are the item schema's input type;
6
+ * after the per-item check (a validated input stream) they are its output.
7
+ */
4
8
  export function stream(item) {
5
9
  const schema = {
6
10
  '~standard': {
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AACA,OAAO,EAA0B,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAE/C,MAAM,UAAU,MAAM,CACpB,IAAO;IAKP,MAAM,MAAM,GAGuB;QACjC,WAAW,EAAE;YACX,OAAO,EAAE,CAAC;YACV,MAAM,EAAE,OAAO;YACf,KAAK,EAA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I,CAAC;QACH,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE,CAAA;IACrB,CAAC;IAAC,MAAM,CAAC;QACP,6BAA6B;IAC/B,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ts-pf/stream",
3
- "version": "0.5.1",
3
+ "version": "0.6.0",
4
4
  "description": "Opt-in StreamCodec and stream() for root AsyncIterable (JSONL)",
5
5
  "keywords": [
6
6
  "ts-pf",
@@ -50,15 +50,15 @@
50
50
  },
51
51
  "dependencies": {
52
52
  "@standard-schema/spec": "^1.0.0",
53
- "@ts-pf/contract": "0.5.1",
54
- "@ts-pf/http": "0.5.1",
55
- "@ts-pf/protocol": "0.5.1"
53
+ "@ts-pf/contract": "0.6.0",
54
+ "@ts-pf/http": "0.6.0",
55
+ "@ts-pf/protocol": "0.6.0"
56
56
  },
57
57
  "devDependencies": {
58
- "@ts-pf/client": "0.5.1",
59
- "@ts-pf/client-http": "0.5.1",
60
- "@ts-pf/server": "0.5.1",
61
- "@ts-pf/server-http": "0.5.1",
58
+ "@ts-pf/client": "0.6.0",
59
+ "@ts-pf/client-http": "0.6.0",
60
+ "@ts-pf/server": "0.6.0",
61
+ "@ts-pf/server-http": "0.6.0",
62
62
  "zod": "^4.0.0"
63
63
  }
64
64
  }
@@ -27,7 +27,7 @@ new FetchLink({ url: '/rpc', codec })
27
27
  procedure.output(stream(z.object({ token: z.string() })))
28
28
  ```
29
29
 
30
- Root only. Same codec on handler and link. A failure line after the stream started rejects the iterator with a `PFError` whose `status` is `undefined` (the response was already 200); switch on `code`. Item checks follow the server validation flags. Stream input items are checked unless `validation.input` is `false`. Stream output items are checked only when `validation.output` is `true`:
30
+ Root only. Same codec on handler and link. A failure line after the stream started rejects the iterator with a `PFError` whose `status` is `undefined` (the response was already 200); switch on `code`. Item checks follow the server validation flags. Stream input items are checked unless `validation.input` is `false`. Stream output items are checked only when `validation.output` is `true`. An input `stream(item)` takes items of the item schema's input type from the sender; the handler iterates parsed items:
31
31
 
32
32
  ```ts no-check
33
33
  new FetchHandler(app, { codec, validation: { output: true } })