diff --git a/.changeset/bright-cooks-change.md b/.changeset/bright-cooks-change.md new file mode 100644 index 000000000..4b0a9f56d --- /dev/null +++ b/.changeset/bright-cooks-change.md @@ -0,0 +1,6 @@ +--- +'@powersync/common': minor +'@powersync/web': minor +--- + +Added support for user parameters. These parameters can be specified as part of the `connect` method's options object. diff --git a/packages/common/src/client/sync/stream/AbstractStreamingSyncImplementation.ts b/packages/common/src/client/sync/stream/AbstractStreamingSyncImplementation.ts index 2adfc6b54..f44c8ba7b 100644 --- a/packages/common/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +++ b/packages/common/src/client/sync/stream/AbstractStreamingSyncImplementation.ts @@ -4,6 +4,7 @@ import Logger, { ILogger } from 'js-logger'; import { BucketRequest, + StreamingSyncRequestParameterType, isStreamingKeepalive, isStreamingSyncCheckpoint, isStreamingSyncCheckpointComplete, @@ -73,6 +74,11 @@ export interface PowerSyncConnectionOptions { * Defaults to a HTTP streaming connection. */ connectionMethod?: SyncStreamConnectionMethod; + + /** + * These parameters are passed to the sync rules, and will be available under the`user_parameters` object. + */ + params?: Record; } export interface StreamingSyncImplementation extends BaseObserver, Disposable { @@ -104,7 +110,8 @@ export const DEFAULT_STREAMING_SYNC_OPTIONS = { }; export const DEFAULT_STREAM_CONNECTION_OPTIONS: Required = { - connectionMethod: SyncStreamConnectionMethod.HTTP + connectionMethod: SyncStreamConnectionMethod.HTTP, + params: {} }; export abstract class AbstractStreamingSyncImplementation @@ -445,7 +452,8 @@ export abstract class AbstractStreamingSyncImplementation data: { buckets: req, include_checksum: true, - raw_data: true + raw_data: true, + parameters: resolvedOptions.params } }; diff --git a/packages/common/src/client/sync/stream/streaming-sync-types.ts b/packages/common/src/client/sync/stream/streaming-sync-types.ts index 747d5bd0d..fab672016 100644 --- a/packages/common/src/client/sync/stream/streaming-sync-types.ts +++ b/packages/common/src/client/sync/stream/streaming-sync-types.ts @@ -55,6 +55,15 @@ export interface SyncResponse { checkpoint?: Checkpoint; } +type JSONValue = string | number | boolean | null | undefined | JSONObject | JSONArray; + +interface JSONObject { + [key: string]: JSONValue; +} +type JSONArray = JSONValue[]; + +export type StreamingSyncRequestParameterType = JSONValue; + export interface StreamingSyncRequest { /** * Existing bucket states. @@ -75,6 +84,11 @@ export interface StreamingSyncRequest { * Changes the response to stringified data in each OplogEntry */ raw_data: boolean; + + /** + * Client parameters to be passed to the sync rules. + */ + parameters?: Record; } export interface StreamingSyncCheckpoint {