@durable-streams/state 0.2.5 → 0.2.6

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
@@ -71,6 +71,7 @@ const db = createStreamDB({
71
71
  url: "https://api.example.com/streams/my-stream",
72
72
  contentType: "application/json",
73
73
  },
74
+ live: "sse", // optional: true, "long-poll", "sse", or false
74
75
  state: schema,
75
76
  })
76
77
 
package/dist/index.cjs CHANGED
@@ -448,7 +448,7 @@ function createStateSchema(collections) {
448
448
  * ```
449
449
  */
450
450
  function createStreamDB(options) {
451
- const { streamOptions, state, actions: actionsFactory } = options;
451
+ const { streamOptions, state, actions: actionsFactory, live = true } = options;
452
452
  const stream = new __durable_streams_client.DurableStream(streamOptions);
453
453
  const dispatcher = new EventDispatcher();
454
454
  const collectionInstances = {};
@@ -473,7 +473,7 @@ function createStreamDB(options) {
473
473
  if (consumerStarted) return;
474
474
  consumerStarted = true;
475
475
  streamResponse = await stream.stream({
476
- live: true,
476
+ live,
477
477
  signal: abortController.signal
478
478
  });
479
479
  streamResponse.subscribeJson((batch) => {
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Collection, Collection as Collection$1, SyncConfig, and, avg, count, createCollection, createOptimisticAction, createOptimisticAction as createOptimisticAction$1, eq, gt, gte, ilike, inArray, isNull, isUndefined, like, lt, lte, max, min, not, or, sum } from "@tanstack/db";
2
2
  import { StandardSchemaV1 } from "@standard-schema/spec";
3
- import { DurableStream, DurableStreamOptions } from "@durable-streams/client";
3
+ import { DurableStream, DurableStreamOptions, LiveMode } from "@durable-streams/client";
4
4
 
5
5
  //#region src/types.d.ts
6
6
  /**
@@ -188,6 +188,8 @@ type ActionMap<TActions extends Record<string, ActionDefinition<any>>> = { [K in
188
188
  interface CreateStreamDBOptions<TDef extends StreamStateDefinition = StreamStateDefinition, TActions extends Record<string, ActionDefinition<any>> = Record<string, never>> {
189
189
  /** Options for creating the durable stream (stream is created lazily on preload) */
190
190
  streamOptions: DurableStreamOptions;
191
+ /** Live read mode used by the StreamDB consumer. Defaults to true. */
192
+ live?: LiveMode;
191
193
  /** The stream state definition */
192
194
  state: TDef;
193
195
  /** Optional factory function to create actions with db and stream context */
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Collection, Collection as Collection$1, SyncConfig, and, avg, count, createCollection, createOptimisticAction, createOptimisticAction as createOptimisticAction$1, eq, gt, gte, ilike, inArray, isNull, isUndefined, like, lt, lte, max, min, not, or, sum } from "@tanstack/db";
2
- import { DurableStream, DurableStreamOptions } from "@durable-streams/client";
2
+ import { DurableStream, DurableStreamOptions, LiveMode } from "@durable-streams/client";
3
3
  import { StandardSchemaV1 } from "@standard-schema/spec";
4
4
 
5
5
  //#region src/types.d.ts
@@ -188,6 +188,8 @@ type ActionMap<TActions extends Record<string, ActionDefinition<any>>> = { [K in
188
188
  interface CreateStreamDBOptions<TDef extends StreamStateDefinition = StreamStateDefinition, TActions extends Record<string, ActionDefinition<any>> = Record<string, never>> {
189
189
  /** Options for creating the durable stream (stream is created lazily on preload) */
190
190
  streamOptions: DurableStreamOptions;
191
+ /** Live read mode used by the StreamDB consumer. Defaults to true. */
192
+ live?: LiveMode;
191
193
  /** The stream state definition */
192
194
  state: TDef;
193
195
  /** Optional factory function to create actions with db and stream context */
package/dist/index.js CHANGED
@@ -424,7 +424,7 @@ function createStateSchema(collections) {
424
424
  * ```
425
425
  */
426
426
  function createStreamDB(options) {
427
- const { streamOptions, state, actions: actionsFactory } = options;
427
+ const { streamOptions, state, actions: actionsFactory, live = true } = options;
428
428
  const stream = new DurableStream(streamOptions);
429
429
  const dispatcher = new EventDispatcher();
430
430
  const collectionInstances = {};
@@ -449,7 +449,7 @@ function createStreamDB(options) {
449
449
  if (consumerStarted) return;
450
450
  consumerStarted = true;
451
451
  streamResponse = await stream.stream({
452
- live: true,
452
+ live,
453
453
  signal: abortController.signal
454
454
  });
455
455
  streamResponse.subscribeJson((batch) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@durable-streams/state",
3
3
  "description": "State change event protocol for Durable Streams",
4
- "version": "0.2.5",
4
+ "version": "0.2.6",
5
5
  "author": "Durable Stream contributors",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -50,7 +50,7 @@
50
50
  ],
51
51
  "dependencies": {
52
52
  "@standard-schema/spec": "^1.0.0",
53
- "@durable-streams/client": "0.2.3"
53
+ "@durable-streams/client": "0.2.4"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "@tanstack/db": ">=0.5.0"
@@ -59,7 +59,7 @@
59
59
  "@tanstack/db": "latest",
60
60
  "@tanstack/intent": "latest",
61
61
  "tsdown": "^0.9.0",
62
- "@durable-streams/server": "0.3.1"
62
+ "@durable-streams/server": "0.3.2"
63
63
  },
64
64
  "engines": {
65
65
  "node": ">=18.0.0"
package/src/stream-db.ts CHANGED
@@ -7,6 +7,7 @@ import type { StandardSchemaV1 } from "@standard-schema/spec"
7
7
  import type {
8
8
  DurableStream,
9
9
  DurableStreamOptions,
10
+ LiveMode,
10
11
  StreamResponse,
11
12
  } from "@durable-streams/client"
12
13
 
@@ -121,6 +122,8 @@ export interface CreateStreamDBOptions<
121
122
  > {
122
123
  /** Options for creating the durable stream (stream is created lazily on preload) */
123
124
  streamOptions: DurableStreamOptions
125
+ /** Live read mode used by the StreamDB consumer. Defaults to true. */
126
+ live?: LiveMode
124
127
  /** The stream state definition */
125
128
  state: TDef
126
129
  /** Optional factory function to create actions with db and stream context */
@@ -762,7 +765,7 @@ export function createStreamDB<
762
765
  ): TActions extends Record<string, never>
763
766
  ? StreamDB<TDef>
764
767
  : StreamDBWithActions<TDef, TActions> {
765
- const { streamOptions, state, actions: actionsFactory } = options
768
+ const { streamOptions, state, actions: actionsFactory, live = true } = options
766
769
 
767
770
  // Create a stream handle (lightweight, doesn't connect until stream() is called)
768
771
  const stream = new DurableStreamClass(streamOptions)
@@ -807,7 +810,7 @@ export function createStreamDB<
807
810
 
808
811
  // Start streaming (this is where the connection actually happens)
809
812
  streamResponse = await stream.stream<StateEvent>({
810
- live: true,
813
+ live,
811
814
  signal: abortController.signal,
812
815
  })
813
816