Skip to content

Commit 590ee67

Browse files
authored
update: added user parameters to PowerSyncCredentials which are available in sync rules. (#204)
1 parent 92384f7 commit 590ee67

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

.changeset/bright-cooks-change.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@powersync/common': minor
3+
'@powersync/web': minor
4+
---
5+
6+
Added support for user parameters. These parameters can be specified as part of the `connect` method's options object.

packages/common/src/client/sync/stream/AbstractStreamingSyncImplementation.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Logger, { ILogger } from 'js-logger';
44

55
import {
66
BucketRequest,
7+
StreamingSyncRequestParameterType,
78
isStreamingKeepalive,
89
isStreamingSyncCheckpoint,
910
isStreamingSyncCheckpointComplete,
@@ -73,6 +74,11 @@ export interface PowerSyncConnectionOptions {
7374
* Defaults to a HTTP streaming connection.
7475
*/
7576
connectionMethod?: SyncStreamConnectionMethod;
77+
78+
/**
79+
* These parameters are passed to the sync rules, and will be available under the`user_parameters` object.
80+
*/
81+
params?: Record<string, StreamingSyncRequestParameterType>;
7682
}
7783

7884
export interface StreamingSyncImplementation extends BaseObserver<StreamingSyncImplementationListener>, Disposable {
@@ -104,7 +110,8 @@ export const DEFAULT_STREAMING_SYNC_OPTIONS = {
104110
};
105111

106112
export const DEFAULT_STREAM_CONNECTION_OPTIONS: Required<PowerSyncConnectionOptions> = {
107-
connectionMethod: SyncStreamConnectionMethod.HTTP
113+
connectionMethod: SyncStreamConnectionMethod.HTTP,
114+
params: {}
108115
};
109116

110117
export abstract class AbstractStreamingSyncImplementation
@@ -445,7 +452,8 @@ export abstract class AbstractStreamingSyncImplementation
445452
data: {
446453
buckets: req,
447454
include_checksum: true,
448-
raw_data: true
455+
raw_data: true,
456+
parameters: resolvedOptions.params
449457
}
450458
};
451459

packages/common/src/client/sync/stream/streaming-sync-types.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ export interface SyncResponse {
5555
checkpoint?: Checkpoint;
5656
}
5757

58+
type JSONValue = string | number | boolean | null | undefined | JSONObject | JSONArray;
59+
60+
interface JSONObject {
61+
[key: string]: JSONValue;
62+
}
63+
type JSONArray = JSONValue[];
64+
65+
export type StreamingSyncRequestParameterType = JSONValue;
66+
5867
export interface StreamingSyncRequest {
5968
/**
6069
* Existing bucket states.
@@ -75,6 +84,11 @@ export interface StreamingSyncRequest {
7584
* Changes the response to stringified data in each OplogEntry
7685
*/
7786
raw_data: boolean;
87+
88+
/**
89+
* Client parameters to be passed to the sync rules.
90+
*/
91+
parameters?: Record<string, StreamingSyncRequestParameterType>;
7892
}
7993

8094
export interface StreamingSyncCheckpoint {

0 commit comments

Comments
 (0)