diff --git a/sync/streams/client-usage.mdx b/sync/streams/client-usage.mdx index 6d0cf50e..c434b6a1 100644 --- a/sync/streams/client-usage.mdx +++ b/sync/streams/client-usage.mdx @@ -648,6 +648,33 @@ await db.Connect(connector, new ConnectOptions { +## Opting Out of Auto-Subscribed Streams + +By default, every stream defined with [`auto_subscribe: true`](/sync/streams/overview#using-auto-subscribe) starts syncing as soon as the client connects. In some cases you may want to control this from the client — for example, to defer syncing reference data until the user has signed in to a specific workspace, or to keep storage minimal on lower-tier devices. + + +This option is currently only available in the Swift SDK. In other SDKs, auto-subscribed streams always sync on connect; remove `auto_subscribe: true` from the stream definition and use explicit subscriptions if you need on-demand control. + + + + +Set `includeDefaultStreams: false` on `ConnectOptions` to skip auto-subscribed streams. Streams the client subscribes to explicitly via `db.syncStream(...).subscribe()` continue to sync as normal. + +```swift +// Connect, but don't sync streams that have `auto_subscribe: true` +try await db.connect( + connector: connector, + options: ConnectOptions(includeDefaultStreams: false) +) + +// Explicit subscriptions still work +let sub = try await db.syncStream(name: "list_todos", params: ["list_id": JsonValue.string("abc")]).subscribe() +``` + +The default is `true`, which preserves the existing behavior of syncing every auto-subscribed stream on connect. + + + ## API Reference For quick reference, here are the key methods available in each SDK: diff --git a/sync/streams/overview.mdx b/sync/streams/overview.mdx index eb228225..a2ba18b7 100644 --- a/sync/streams/overview.mdx +++ b/sync/streams/overview.mdx @@ -164,6 +164,10 @@ streams: AND order_id IN (SELECT id FROM orders WHERE user_id = auth.user_id()) ``` + +Clients using the Swift SDK can opt out of auto-subscribed streams at connect time with `ConnectOptions(includeDefaultStreams: false)`. See [Opting out of auto-subscribed streams](/sync/streams/client-usage#opting-out-of-auto-subscribed-streams) for details. + + ## Client-Side Usage