@powersync/common 2.3.1 → 2.5.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/lib/client/CommonPowerSyncDatabase.d.ts +17 -4
- package/lib/client/connection/PowerSyncBackendConnector.d.ts +76 -8
- package/lib/client/sync/options.d.ts +44 -0
- package/lib/client/sync/options.js.map +1 -1
- package/lib/client/watched/processors/DifferentialQueryProcessor.d.ts +4 -0
- package/lib/db/DBAdapter.js +4 -3
- package/lib/db/DBAdapter.js.map +1 -1
- package/lib/db/schema/Table.d.ts +18 -1
- package/lib/db/schema/Table.js +10 -2
- package/lib/db/schema/Table.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/client/CommonPowerSyncDatabase.ts +18 -4
- package/src/client/connection/PowerSyncBackendConnector.ts +81 -8
- package/src/client/sync/options.ts +48 -0
- package/src/client/watched/processors/DifferentialQueryProcessor.ts +4 -0
- package/src/db/DBAdapter.ts +6 -4
- package/src/db/schema/Table.ts +27 -2
- package/src/index.ts +3 -1
|
@@ -7,7 +7,7 @@ import { PowerSyncLogger } from '../utils/Logger.js';
|
|
|
7
7
|
import { DatabaseSource } from './SQLOpenFactory.js';
|
|
8
8
|
import { TriggerManager } from './triggers/TriggerManager.js';
|
|
9
9
|
import { PowerSyncBackendConnector } from './connection/PowerSyncBackendConnector.js';
|
|
10
|
-
import { SyncOptions } from './sync/options.js';
|
|
10
|
+
import { DownloadOptions, SyncOptions, UploadOptions } from './sync/options.js';
|
|
11
11
|
import { SyncStream } from './sync/sync-streams.js';
|
|
12
12
|
import { UploadQueueStats } from '../db/crud/UploadQueueStatus.js';
|
|
13
13
|
import { CrudBatch } from './sync/bucket/CrudBatch.js';
|
|
@@ -28,7 +28,7 @@ export interface DisconnectAndClearOptions {
|
|
|
28
28
|
/**
|
|
29
29
|
* A [soft] clear deletes publicly visible tables, but keeps internal copies of data synced in the database.
|
|
30
30
|
*
|
|
31
|
-
* This usually means that if {@link CommonPowerSyncDatabase
|
|
31
|
+
* This usually means that if {@link CommonPowerSyncDatabase.(connect:1)} is later called again with a JWT from the same
|
|
32
32
|
* user, the first sync is very fast because all internal data is still available. When a different user logs in, no
|
|
33
33
|
* old data would be visible at any point. Using soft deletes is recommended where it's not a security issue that old
|
|
34
34
|
* data could be reconstructed from internal database tables.
|
|
@@ -182,7 +182,7 @@ export interface CommonPowerSyncDatabase extends BaseObserverInterface<PowerSync
|
|
|
182
182
|
/**
|
|
183
183
|
* Replace the schema with a new version. This is for advanced use cases - typically the schema should just be specified once in the constructor.
|
|
184
184
|
*
|
|
185
|
-
* Cannot be used while connected - this should only be called before {@link CommonPowerSyncDatabase.connect}.
|
|
185
|
+
* Cannot be used while connected - this should only be called before {@link CommonPowerSyncDatabase.(connect:1)}.
|
|
186
186
|
*/
|
|
187
187
|
updateSchema(schema: Schema): Promise<void>;
|
|
188
188
|
/**
|
|
@@ -194,10 +194,23 @@ export interface CommonPowerSyncDatabase extends BaseObserverInterface<PowerSync
|
|
|
194
194
|
* Connects to stream of events from the PowerSync instance.
|
|
195
195
|
*/
|
|
196
196
|
connect(connector: PowerSyncBackendConnector, options?: SyncOptions): Promise<void>;
|
|
197
|
+
/**
|
|
198
|
+
* Connects this PowerSync database for downloading rows from your source database, uploading local mutations to your
|
|
199
|
+
* backend, or both.
|
|
200
|
+
*
|
|
201
|
+
* For downloads, {@link DownloadOptions} need to be provided. This includes the URL of the PowerSync service to
|
|
202
|
+
* connect to and a callback responsible for obtaining an authentication token.
|
|
203
|
+
* For uploads, {@link UploadOptions} provides a callback responsible for uploading local mutations to your backend.
|
|
204
|
+
*
|
|
205
|
+
* A single connect call can provide both download and upload options. Each call overrides all previous options. In
|
|
206
|
+
* particular, first calling connect with download options only and then again with upload options does not keep the
|
|
207
|
+
* download active. Provide both options in one call to sync both ways.
|
|
208
|
+
*/
|
|
209
|
+
connect(options: SyncOptions & (DownloadOptions | UploadOptions)): Promise<void>;
|
|
197
210
|
/**
|
|
198
211
|
* Close the sync connection.
|
|
199
212
|
*
|
|
200
|
-
* Use {@link CommonPowerSyncDatabase.connect} to connect again.
|
|
213
|
+
* Use {@link CommonPowerSyncDatabase.(connect:1)} to connect again.
|
|
201
214
|
*/
|
|
202
215
|
disconnect(): Promise<void>;
|
|
203
216
|
/**
|
|
@@ -3,7 +3,24 @@ import { CommonPowerSyncDatabase } from '../CommonPowerSyncDatabase.js';
|
|
|
3
3
|
/**
|
|
4
4
|
* @public
|
|
5
5
|
*/
|
|
6
|
-
export interface
|
|
6
|
+
export interface PostCustomCheckpoints {
|
|
7
|
+
/**
|
|
8
|
+
* Posts a client-generated checkpoint request to the backend and returns the effective checkpoint request state.
|
|
9
|
+
*
|
|
10
|
+
* This method is optional. It only needs to be implemented when the selected {@link CheckpointMode} is `requests`
|
|
11
|
+
* and [asynchronous backend uploads](https://docs.powersync.com/client-sdks/advanced/checkpoint-requests#asynchronous-upload-backends)
|
|
12
|
+
* are used. In any other case, this method should not be present on backend connectors.
|
|
13
|
+
*
|
|
14
|
+
* @param requestId - The client-generated checkpoint request ID (a positive 64-bit integer encoded as a string).
|
|
15
|
+
* @param clientId - The PowerSync client ID for the current device.
|
|
16
|
+
* @param signal - An optional abort signal that completes when the checkpoint is no longer necessary.
|
|
17
|
+
*/
|
|
18
|
+
postCheckpointRequest?(clientId: string, requestId: string, signal?: AbortSignal): Promise<string>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export interface PowerSyncBackendConnector extends PostCustomCheckpoints {
|
|
7
24
|
/** Allows the PowerSync client to retrieve an authentication token from your backend
|
|
8
25
|
* which is used to authenticate against the PowerSync service.
|
|
9
26
|
*
|
|
@@ -23,15 +40,66 @@ export interface PowerSyncBackendConnector {
|
|
|
23
40
|
* Any thrown errors will result in a retry after the configured wait period (default: 5 seconds).
|
|
24
41
|
*/
|
|
25
42
|
uploadData: (database: CommonPowerSyncDatabase) => Promise<void>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Authenticates the PowerSync SDK against a PowerSync service, allowing it to download changes.
|
|
46
|
+
*
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
export interface Authenticator extends PostCustomCheckpoints {
|
|
26
50
|
/**
|
|
27
|
-
*
|
|
51
|
+
* Obtain a token used to authenticate against a PowerSync service.
|
|
28
52
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
53
|
+
* @param options - Options, including an abort signal completing when the SDK is no longer interested in these
|
|
54
|
+
* credentials. Supported authenticators can reject the promise with the `AbortSignal.reason` when aborted.
|
|
55
|
+
* @returns A promise resolving to PowerSync credentials. It may reject when credentials could not be resolved.
|
|
56
|
+
*/
|
|
57
|
+
resolveCredentials(options: ResolveCredentialsOptions): Promise<string>;
|
|
58
|
+
/**
|
|
59
|
+
* Invoked by the SDK when the PowerSync service has rejected credentials previously returned by
|
|
60
|
+
* {@link Authenticator.resolveCredentials}.
|
|
32
61
|
*
|
|
33
|
-
*
|
|
34
|
-
|
|
62
|
+
* Subsequent calls to {@link Authenticator.resolveCredentials} should return new credentials in this case.
|
|
63
|
+
*/
|
|
64
|
+
invalidateCredentials?(): void;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The signature of a function uploading local mutations to a backend.
|
|
68
|
+
*
|
|
69
|
+
* @public
|
|
70
|
+
*/
|
|
71
|
+
export type MutationUploader = (options: UploadMutationsOptions) => Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Base interface for options with an abort signal.
|
|
74
|
+
*
|
|
75
|
+
* @public
|
|
76
|
+
*/
|
|
77
|
+
export interface HasAbortSignal {
|
|
78
|
+
/**
|
|
79
|
+
* An optional abort signal, owned by the SDK.
|
|
80
|
+
*
|
|
81
|
+
* This signal completes when the SDK is no longer interested in the operation is triggered, e.g. because
|
|
82
|
+
* {@link CommonPowerSyncDatabase.disconnect} was called.
|
|
83
|
+
* Compatible {@link Authenticator} and {@link MutationUploader} implementations may use this to abort their work, but
|
|
84
|
+
* this is not required.
|
|
85
|
+
*/
|
|
86
|
+
abort?: AbortSignal;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Options passed to {@link Authenticator.resolveCredentials}.
|
|
90
|
+
*
|
|
91
|
+
* @public
|
|
92
|
+
*/
|
|
93
|
+
export interface ResolveCredentialsOptions extends HasAbortSignal {
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Options passed to {@link MutationUploader}.
|
|
97
|
+
*
|
|
98
|
+
* @public
|
|
99
|
+
*/
|
|
100
|
+
export interface UploadMutationsOptions extends HasAbortSignal {
|
|
101
|
+
/**
|
|
102
|
+
* The database on which {@link CommonPowerSyncDatabase.(connect:1)} has been called, for convenience.
|
|
35
103
|
*/
|
|
36
|
-
|
|
104
|
+
database: CommonPowerSyncDatabase;
|
|
37
105
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Authenticator, MutationUploader } from '../connection/PowerSyncBackendConnector.js';
|
|
1
2
|
import { StreamingSyncRequestParameterType } from './stream/JsonValue.js';
|
|
2
3
|
/**
|
|
3
4
|
* Options that affect how the PowerSync SDK connects to the PowerSync Service.
|
|
@@ -44,6 +45,49 @@ export interface SyncOptions {
|
|
|
44
45
|
* The mode used to request checkpoints from the service (used after uploading local data).
|
|
45
46
|
*/
|
|
46
47
|
checkpointMode?: CheckpointMode;
|
|
48
|
+
/**
|
|
49
|
+
* How long to wait for the PowerSync Service to respond, in milliseconds. This defaults to 30 seconds.
|
|
50
|
+
*
|
|
51
|
+
* For checkpoint requests, this limits the whole request. For the sync stream over HTTP, this limits the time until
|
|
52
|
+
* the response starts, not how long the stream stays open. WebSocket connections use their own timeouts.
|
|
53
|
+
*
|
|
54
|
+
* A request that takes longer fails and is retried after {@link SyncOptions.retryDelayMs}.
|
|
55
|
+
*/
|
|
56
|
+
connectTimeoutMs?: number;
|
|
57
|
+
/**
|
|
58
|
+
* Enables the core extension's diagnostics event stream: detailed per-bucket download stats,
|
|
59
|
+
* including each bucket's `target_count`, and inferred column types. Off by default.
|
|
60
|
+
*
|
|
61
|
+
* The events are internal. No public API exposes them; only PowerSync DevTools reads them, to show
|
|
62
|
+
* per-bucket totals. See https://docs.powersync.com/tools/devtools-overview.
|
|
63
|
+
*/
|
|
64
|
+
diagnostics?: boolean;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Options required when connecting a PowerSync database for downloads.
|
|
68
|
+
*
|
|
69
|
+
* @public
|
|
70
|
+
*/
|
|
71
|
+
export interface DownloadOptions {
|
|
72
|
+
/**
|
|
73
|
+
* The hostname of the PowerSync service to connect to.
|
|
74
|
+
*/
|
|
75
|
+
powerSyncEndpoint: string;
|
|
76
|
+
/**
|
|
77
|
+
* The authenticator responsible for providing authentication tokens to the PowerSync service.
|
|
78
|
+
*/
|
|
79
|
+
authenticator: Authenticator;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Options required when connecting a PowerSync database for uploads.
|
|
83
|
+
*
|
|
84
|
+
* @public
|
|
85
|
+
*/
|
|
86
|
+
export interface UploadOptions {
|
|
87
|
+
/**
|
|
88
|
+
* The function responsible for uploading local mutations.
|
|
89
|
+
*/
|
|
90
|
+
upload: MutationUploader;
|
|
47
91
|
}
|
|
48
92
|
/**
|
|
49
93
|
* @public
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../../src/client/sync/options.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../../src/client/sync/options.ts"],"names":[],"mappings":"AA0GA;;GAEG;AACH,MAAM,CAAN,IAAY,0BAGX;AAHD,WAAY,0BAA0B;IACpC,2CAAa,CAAA;IACb,uDAAyB,CAAA;AAC3B,CAAC,EAHW,0BAA0B,KAA1B,0BAA0B,QAGrC;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,aAYX;AAZD,WAAY,aAAa;IACvB;;;OAGG;IACH,sCAAqB,CAAA;IAErB;;;OAGG;IACH,0CAAyB,CAAA;AAC3B,CAAC,EAZW,aAAa,KAAb,aAAa,QAYxB"}
|
|
@@ -83,6 +83,10 @@ export interface DifferentialWatchedQuerySettings<RowType> extends DifferentialW
|
|
|
83
83
|
* @public
|
|
84
84
|
*/
|
|
85
85
|
export interface DifferentialWatchedQueryListener<RowType> extends WatchedQueryListener<ReadonlyArray<Readonly<RowType>>> {
|
|
86
|
+
/**
|
|
87
|
+
* Called when the result set has changed.
|
|
88
|
+
* This also fires if rows have only been reordered, in which case `added`, `removed` and `updated` are empty.
|
|
89
|
+
*/
|
|
86
90
|
onDiff?: (diff: WatchedQueryDifferential<RowType>) => void | Promise<void>;
|
|
87
91
|
}
|
|
88
92
|
/**
|
package/lib/db/DBAdapter.js
CHANGED
|
@@ -106,18 +106,19 @@ class TransactionImplementation extends LockContext {
|
|
|
106
106
|
}
|
|
107
107
|
static async runWith(ctx, fn) {
|
|
108
108
|
let tx = new TransactionImplementation(ctx);
|
|
109
|
+
await ctx.execute('BEGIN IMMEDIATE');
|
|
109
110
|
try {
|
|
110
|
-
await ctx.execute('BEGIN IMMEDIATE');
|
|
111
111
|
const result = await fn(tx);
|
|
112
112
|
await tx.commit();
|
|
113
113
|
return result;
|
|
114
114
|
}
|
|
115
115
|
catch (ex) {
|
|
116
|
+
tx.finalized = true;
|
|
116
117
|
try {
|
|
117
|
-
await
|
|
118
|
+
await ctx.execute('ROLLBACK');
|
|
118
119
|
}
|
|
119
120
|
catch (ex2) {
|
|
120
|
-
// In rare cases, a rollback may fail.
|
|
121
|
+
// In rare cases, a rollback may fail (e.g. if user code invoked commit() and then threw afterwards).
|
|
121
122
|
// Safe to ignore.
|
|
122
123
|
}
|
|
123
124
|
throw ex;
|
package/lib/db/DBAdapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DBAdapter.js","sourceRoot":"","sources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AC;YAC5B,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC;YAClB,OAAO,MAAM,CAAC;QAChB,CAAC;QAAC,OAAO,EAAE,EAAE,CAAC;YACZ,EAAE,CAAC,SAAS,GAAG,IAAI,CAAC;YAEpB,IAAI,CAAC;gBACH,MAAM,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;YAChC,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,qGAAqG;gBACrG,kBAAkB;YACpB,CAAC;YACD,MAAM,EAAE,CAAC;QACX,CAAC;IACH,CAAC;CACF"}
|
package/lib/db/schema/Table.d.ts
CHANGED
|
@@ -15,6 +15,21 @@ export interface TableOrRawTableOptions {
|
|
|
15
15
|
}
|
|
16
16
|
interface SharedTableOptions extends TableOrRawTableOptions {
|
|
17
17
|
viewName?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Marks this table as a direct, managed table.
|
|
20
|
+
*
|
|
21
|
+
* Enabling this flag makes PowerSync store data directly as SQLite rows instead of using an intermediate view around
|
|
22
|
+
* a JSON store.
|
|
23
|
+
*
|
|
24
|
+
* The table is still managed by the PowerSync SDK, which is responsible for creating, altering and dropping them.
|
|
25
|
+
* You can query managed tables like JSON-based views, and mutations are consistently tracked as pending uploads.
|
|
26
|
+
* For more information on managed tables, see [the documentation](https://docs.powersync.com/client-sdks/advanced/performance-optimization#managed-views-vs-managed-tables).
|
|
27
|
+
*
|
|
28
|
+
* Direct tables can't use a {@link ResolvedTableOptions.viewName}.
|
|
29
|
+
*
|
|
30
|
+
* @alpha Direct tables are currently in alpha.
|
|
31
|
+
*/
|
|
32
|
+
direct?: boolean;
|
|
18
33
|
}
|
|
19
34
|
/** Whether to include previous column values when PowerSync tracks local changes.
|
|
20
35
|
*
|
|
@@ -78,6 +93,7 @@ export declare class ResolvedTable {
|
|
|
78
93
|
get trackPrevious(): boolean | TrackPreviousOptions;
|
|
79
94
|
get trackMetadata(): boolean;
|
|
80
95
|
get ignoreEmptyUpdates(): boolean;
|
|
96
|
+
get direct(): boolean | undefined;
|
|
81
97
|
get internalName(): string;
|
|
82
98
|
get validName(): boolean;
|
|
83
99
|
validate(): void;
|
|
@@ -89,7 +105,7 @@ export declare class ResolvedTable {
|
|
|
89
105
|
include_metadata: boolean | undefined;
|
|
90
106
|
ignore_empty_update: boolean | undefined;
|
|
91
107
|
name: string;
|
|
92
|
-
view_name: string;
|
|
108
|
+
view_name: string | undefined;
|
|
93
109
|
columns: {
|
|
94
110
|
name: string;
|
|
95
111
|
type: import("./Column.js").ColumnType | undefined;
|
|
@@ -102,6 +118,7 @@ export declare class ResolvedTable {
|
|
|
102
118
|
type: import("./Column.js").ColumnType;
|
|
103
119
|
}[];
|
|
104
120
|
}[];
|
|
121
|
+
direct: boolean | undefined;
|
|
105
122
|
};
|
|
106
123
|
private applyDefaultOptions;
|
|
107
124
|
}
|
package/lib/db/schema/Table.js
CHANGED
|
@@ -59,6 +59,9 @@ export class ResolvedTable {
|
|
|
59
59
|
get ignoreEmptyUpdates() {
|
|
60
60
|
return this.options.ignoreEmptyUpdates;
|
|
61
61
|
}
|
|
62
|
+
get direct() {
|
|
63
|
+
return this.options.direct;
|
|
64
|
+
}
|
|
62
65
|
get internalName() {
|
|
63
66
|
if (this.options.localOnly) {
|
|
64
67
|
return `ps_data_local__${this.name}`;
|
|
@@ -120,13 +123,17 @@ export class ResolvedTable {
|
|
|
120
123
|
}
|
|
121
124
|
indexNames.add(index.name);
|
|
122
125
|
}
|
|
126
|
+
if (this.direct && this.viewNameOverride != null) {
|
|
127
|
+
throw new Error(`Direct table ${this.name} can't use a view name override`);
|
|
128
|
+
}
|
|
123
129
|
}
|
|
124
130
|
toJSON() {
|
|
125
131
|
return {
|
|
126
132
|
name: this.name,
|
|
127
|
-
view_name: this.
|
|
133
|
+
view_name: this.viewNameOverride,
|
|
128
134
|
columns: this.columns.map((c) => c.toJSON()),
|
|
129
135
|
indexes: this.indexes.map((e) => e.toJSON(this)),
|
|
136
|
+
direct: this.direct,
|
|
130
137
|
...encodeTableOptions(this)
|
|
131
138
|
};
|
|
132
139
|
}
|
|
@@ -197,7 +204,8 @@ export class Table extends ResolvedTable {
|
|
|
197
204
|
localOnly: options?.localOnly,
|
|
198
205
|
trackPrevious: options?.trackPrevious,
|
|
199
206
|
trackMetadata: options?.trackMetadata,
|
|
200
|
-
ignoreEmptyUpdates: options?.ignoreEmptyUpdates
|
|
207
|
+
ignoreEmptyUpdates: options?.ignoreEmptyUpdates,
|
|
208
|
+
direct: options?.direct
|
|
201
209
|
};
|
|
202
210
|
}
|
|
203
211
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Table.js","sourceRoot":"","sources":["../../../src/db/schema/Table.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAuC,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD;;;GAGG;AACH,MAAM,qBAAqB,GAAG,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"Table.js","sourceRoot":"","sources":["../../../src/db/schema/Table.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAuC,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD;;;GAGG;AACH,MAAM,qBAAqB,GAAG,IAAI,CAAC;AAgFnC,MAAM,qBAAqB,GAAG;IAC5B,OAAO,EAAE,EAAE;IACX,UAAU,EAAE,KAAK;IACjB,SAAS,EAAE,KAAK;IAChB,aAAa,EAAE,KAAK;IACpB,aAAa,EAAE,KAAK;IACpB,kBAAkB,EAAE,KAAK;CAC1B,C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C,CAAC,IAAI,aAAa,CAAC;oBAChB,IAAI,EAAE,mBAAmB,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;oBAC3C,SAAS,EAAE,CAAC,mBAAmB,CAAC,UAAU,CAAC,GAAG,CAAC;iBAChD,CAAC;gBACJ,CAAC,CAAC,mBAAmB,CACxB;SACF,CAAC,CACL,CAAC;QAEF,OAAO;YACL,IAAI,EAAE,EAAE;YACR,OAAO,EAAE,gBAAgB;YACzB,OAAO,EAAE,gBAAgB;YACzB,QAAQ,EAAE,OAAO,EAAE,QAAQ;YAC3B,UAAU,EAAE,OAAO,EAAE,UAAU;YAC/B,SAAS,EAAE,OAAO,EAAE,SAAS;YAC7B,aAAa,EAAE,OAAO,EAAE,aAAa;YACrC,aAAa,EAAE,OAAO,EAAE,aAAa;YACrC,kBAAkB,EAAE,OAAO,EAAE,kBAAkB;YAC/C,MAAM,EAAE,OAAO,EAAE,MAAM;SACxB,CAAC;IACJ,CAAC;CACF"}
|
package/lib/index.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export * from './client/sync/bucket/CrudTransaction.js';
|
|
|
17
17
|
export * from './client/sync/CheckpointRequest.js';
|
|
18
18
|
export * from './client/sync/stream/JsonValue.js';
|
|
19
19
|
export * from './client/sync/sync-streams.js';
|
|
20
|
-
export { SyncOptions, SyncStreamConnectionMethod, FetchStrategy, CheckpointMode, CheckpointRequestsOptions } from './client/sync/options.js';
|
|
20
|
+
export { SyncOptions, SyncStreamConnectionMethod, FetchStrategy, CheckpointMode, CheckpointRequestsOptions, DownloadOptions, UploadOptions } from './client/sync/options.js';
|
|
21
21
|
export { ProgressWithOperations, SyncProgress } from './db/crud/SyncProgress.js';
|
|
22
22
|
export * from './db/crud/SyncStatus.js';
|
|
23
23
|
export * from './db/crud/UploadQueueStatus.js';
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":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;AAC9C,OAAO,EAEL,0BAA0B,EAC1B,aAAa,EAKd,MAAM,0BAA0B,CAAC;AAGlC,cAAc,yBAAyB,CAAC;AACxC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC;AAE7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AAErC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kCAAkC,CAAC;AACjD,cAAc,qCAAqC,CAAC;AACpD,cAAc,iCAAiC,CAAC;AAChD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,2DAA2D,CAAC;AAC1E,cAAc,uDAAuD,CAAC;AACtE,cAAc,kCAAkC,CAAC;AAGjD,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mBAAmB,CAAC;AAElC,cAAc,kBAAkB,CAAC"}
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@ import { PowerSyncLogger } from '../utils/Logger.js';
|
|
|
7
7
|
import { DatabaseSource } from './SQLOpenFactory.js';
|
|
8
8
|
import { TriggerManager } from './triggers/TriggerManager.js';
|
|
9
9
|
import { PowerSyncBackendConnector } from './connection/PowerSyncBackendConnector.js';
|
|
10
|
-
import { SyncOptions } from './sync/options.js';
|
|
10
|
+
import { DownloadOptions, SyncOptions, UploadOptions } from './sync/options.js';
|
|
11
11
|
import { SyncStream } from './sync/sync-streams.js';
|
|
12
12
|
import { UploadQueueStats } from '../db/crud/UploadQueueStatus.js';
|
|
13
13
|
import { CrudBatch } from './sync/bucket/CrudBatch.js';
|
|
@@ -29,7 +29,7 @@ export interface DisconnectAndClearOptions {
|
|
|
29
29
|
/**
|
|
30
30
|
* A [soft] clear deletes publicly visible tables, but keeps internal copies of data synced in the database.
|
|
31
31
|
*
|
|
32
|
-
* This usually means that if {@link CommonPowerSyncDatabase
|
|
32
|
+
* This usually means that if {@link CommonPowerSyncDatabase.(connect:1)} is later called again with a JWT from the same
|
|
33
33
|
* user, the first sync is very fast because all internal data is still available. When a different user logs in, no
|
|
34
34
|
* old data would be visible at any point. Using soft deletes is recommended where it's not a security issue that old
|
|
35
35
|
* data could be reconstructed from internal database tables.
|
|
@@ -204,7 +204,7 @@ export interface CommonPowerSyncDatabase extends BaseObserverInterface<PowerSync
|
|
|
204
204
|
/**
|
|
205
205
|
* Replace the schema with a new version. This is for advanced use cases - typically the schema should just be specified once in the constructor.
|
|
206
206
|
*
|
|
207
|
-
* Cannot be used while connected - this should only be called before {@link CommonPowerSyncDatabase.connect}.
|
|
207
|
+
* Cannot be used while connected - this should only be called before {@link CommonPowerSyncDatabase.(connect:1)}.
|
|
208
208
|
*/
|
|
209
209
|
updateSchema(schema: Schema): Promise<void>;
|
|
210
210
|
|
|
@@ -219,10 +219,24 @@ export interface CommonPowerSyncDatabase extends BaseObserverInterface<PowerSync
|
|
|
219
219
|
*/
|
|
220
220
|
connect(connector: PowerSyncBackendConnector, options?: SyncOptions): Promise<void>;
|
|
221
221
|
|
|
222
|
+
/**
|
|
223
|
+
* Connects this PowerSync database for downloading rows from your source database, uploading local mutations to your
|
|
224
|
+
* backend, or both.
|
|
225
|
+
*
|
|
226
|
+
* For downloads, {@link DownloadOptions} need to be provided. This includes the URL of the PowerSync service to
|
|
227
|
+
* connect to and a callback responsible for obtaining an authentication token.
|
|
228
|
+
* For uploads, {@link UploadOptions} provides a callback responsible for uploading local mutations to your backend.
|
|
229
|
+
*
|
|
230
|
+
* A single connect call can provide both download and upload options. Each call overrides all previous options. In
|
|
231
|
+
* particular, first calling connect with download options only and then again with upload options does not keep the
|
|
232
|
+
* download active. Provide both options in one call to sync both ways.
|
|
233
|
+
*/
|
|
234
|
+
connect(options: SyncOptions & (DownloadOptions | UploadOptions)): Promise<void>;
|
|
235
|
+
|
|
222
236
|
/**
|
|
223
237
|
* Close the sync connection.
|
|
224
238
|
*
|
|
225
|
-
* Use {@link CommonPowerSyncDatabase.connect} to connect again.
|
|
239
|
+
* Use {@link CommonPowerSyncDatabase.(connect:1)} to connect again.
|
|
226
240
|
*/
|
|
227
241
|
disconnect(): Promise<void>;
|
|
228
242
|
|
|
@@ -4,7 +4,25 @@ import { CommonPowerSyncDatabase } from '../CommonPowerSyncDatabase.js';
|
|
|
4
4
|
/**
|
|
5
5
|
* @public
|
|
6
6
|
*/
|
|
7
|
-
export interface
|
|
7
|
+
export interface PostCustomCheckpoints {
|
|
8
|
+
/**
|
|
9
|
+
* Posts a client-generated checkpoint request to the backend and returns the effective checkpoint request state.
|
|
10
|
+
*
|
|
11
|
+
* This method is optional. It only needs to be implemented when the selected {@link CheckpointMode} is `requests`
|
|
12
|
+
* and [asynchronous backend uploads](https://docs.powersync.com/client-sdks/advanced/checkpoint-requests#asynchronous-upload-backends)
|
|
13
|
+
* are used. In any other case, this method should not be present on backend connectors.
|
|
14
|
+
*
|
|
15
|
+
* @param requestId - The client-generated checkpoint request ID (a positive 64-bit integer encoded as a string).
|
|
16
|
+
* @param clientId - The PowerSync client ID for the current device.
|
|
17
|
+
* @param signal - An optional abort signal that completes when the checkpoint is no longer necessary.
|
|
18
|
+
*/
|
|
19
|
+
postCheckpointRequest?(clientId: string, requestId: string, signal?: AbortSignal): Promise<string>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export interface PowerSyncBackendConnector extends PostCustomCheckpoints {
|
|
8
26
|
/** Allows the PowerSync client to retrieve an authentication token from your backend
|
|
9
27
|
* which is used to authenticate against the PowerSync service.
|
|
10
28
|
*
|
|
@@ -25,16 +43,71 @@ export interface PowerSyncBackendConnector {
|
|
|
25
43
|
* Any thrown errors will result in a retry after the configured wait period (default: 5 seconds).
|
|
26
44
|
*/
|
|
27
45
|
uploadData: (database: CommonPowerSyncDatabase) => Promise<void>;
|
|
46
|
+
}
|
|
28
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Authenticates the PowerSync SDK against a PowerSync service, allowing it to download changes.
|
|
50
|
+
*
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
export interface Authenticator extends PostCustomCheckpoints {
|
|
29
54
|
/**
|
|
30
|
-
*
|
|
55
|
+
* Obtain a token used to authenticate against a PowerSync service.
|
|
31
56
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
57
|
+
* @param options - Options, including an abort signal completing when the SDK is no longer interested in these
|
|
58
|
+
* credentials. Supported authenticators can reject the promise with the `AbortSignal.reason` when aborted.
|
|
59
|
+
* @returns A promise resolving to PowerSync credentials. It may reject when credentials could not be resolved.
|
|
60
|
+
*/
|
|
61
|
+
resolveCredentials(options: ResolveCredentialsOptions): Promise<string>;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Invoked by the SDK when the PowerSync service has rejected credentials previously returned by
|
|
65
|
+
* {@link Authenticator.resolveCredentials}.
|
|
35
66
|
*
|
|
36
|
-
*
|
|
37
|
-
|
|
67
|
+
* Subsequent calls to {@link Authenticator.resolveCredentials} should return new credentials in this case.
|
|
68
|
+
*/
|
|
69
|
+
invalidateCredentials?(): void;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The signature of a function uploading local mutations to a backend.
|
|
74
|
+
*
|
|
75
|
+
* @public
|
|
76
|
+
*/
|
|
77
|
+
export type MutationUploader = (options: UploadMutationsOptions) => Promise<void>;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Base interface for options with an abort signal.
|
|
81
|
+
*
|
|
82
|
+
* @public
|
|
83
|
+
*/
|
|
84
|
+
export interface HasAbortSignal {
|
|
85
|
+
/**
|
|
86
|
+
* An optional abort signal, owned by the SDK.
|
|
87
|
+
*
|
|
88
|
+
* This signal completes when the SDK is no longer interested in the operation is triggered, e.g. because
|
|
89
|
+
* {@link CommonPowerSyncDatabase.disconnect} was called.
|
|
90
|
+
* Compatible {@link Authenticator} and {@link MutationUploader} implementations may use this to abort their work, but
|
|
91
|
+
* this is not required.
|
|
92
|
+
*/
|
|
93
|
+
abort?: AbortSignal;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Options passed to {@link Authenticator.resolveCredentials}.
|
|
98
|
+
*
|
|
99
|
+
* @public
|
|
100
|
+
*/
|
|
101
|
+
export interface ResolveCredentialsOptions extends HasAbortSignal {}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Options passed to {@link MutationUploader}.
|
|
105
|
+
*
|
|
106
|
+
* @public
|
|
107
|
+
*/
|
|
108
|
+
export interface UploadMutationsOptions extends HasAbortSignal {
|
|
109
|
+
/**
|
|
110
|
+
* The database on which {@link CommonPowerSyncDatabase.(connect:1)} has been called, for convenience.
|
|
38
111
|
*/
|
|
39
|
-
|
|
112
|
+
database: CommonPowerSyncDatabase;
|
|
40
113
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Authenticator, MutationUploader } from '../connection/PowerSyncBackendConnector.js';
|
|
1
2
|
import { StreamingSyncRequestParameterType } from './stream/JsonValue.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -54,6 +55,53 @@ export interface SyncOptions {
|
|
|
54
55
|
* The mode used to request checkpoints from the service (used after uploading local data).
|
|
55
56
|
*/
|
|
56
57
|
checkpointMode?: CheckpointMode;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* How long to wait for the PowerSync Service to respond, in milliseconds. This defaults to 30 seconds.
|
|
61
|
+
*
|
|
62
|
+
* For checkpoint requests, this limits the whole request. For the sync stream over HTTP, this limits the time until
|
|
63
|
+
* the response starts, not how long the stream stays open. WebSocket connections use their own timeouts.
|
|
64
|
+
*
|
|
65
|
+
* A request that takes longer fails and is retried after {@link SyncOptions.retryDelayMs}.
|
|
66
|
+
*/
|
|
67
|
+
connectTimeoutMs?: number;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Enables the core extension's diagnostics event stream: detailed per-bucket download stats,
|
|
71
|
+
* including each bucket's `target_count`, and inferred column types. Off by default.
|
|
72
|
+
*
|
|
73
|
+
* The events are internal. No public API exposes them; only PowerSync DevTools reads them, to show
|
|
74
|
+
* per-bucket totals. See https://docs.powersync.com/tools/devtools-overview.
|
|
75
|
+
*/
|
|
76
|
+
diagnostics?: boolean;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Options required when connecting a PowerSync database for downloads.
|
|
81
|
+
*
|
|
82
|
+
* @public
|
|
83
|
+
*/
|
|
84
|
+
export interface DownloadOptions {
|
|
85
|
+
/**
|
|
86
|
+
* The hostname of the PowerSync service to connect to.
|
|
87
|
+
*/
|
|
88
|
+
powerSyncEndpoint: string;
|
|
89
|
+
/**
|
|
90
|
+
* The authenticator responsible for providing authentication tokens to the PowerSync service.
|
|
91
|
+
*/
|
|
92
|
+
authenticator: Authenticator;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Options required when connecting a PowerSync database for uploads.
|
|
97
|
+
*
|
|
98
|
+
* @public
|
|
99
|
+
*/
|
|
100
|
+
export interface UploadOptions {
|
|
101
|
+
/**
|
|
102
|
+
* The function responsible for uploading local mutations.
|
|
103
|
+
*/
|
|
104
|
+
upload: MutationUploader;
|
|
57
105
|
}
|
|
58
106
|
|
|
59
107
|
/**
|
|
@@ -92,6 +92,10 @@ export interface DifferentialWatchedQuerySettings<RowType> extends DifferentialW
|
|
|
92
92
|
export interface DifferentialWatchedQueryListener<RowType> extends WatchedQueryListener<
|
|
93
93
|
ReadonlyArray<Readonly<RowType>>
|
|
94
94
|
> {
|
|
95
|
+
/**
|
|
96
|
+
* Called when the result set has changed.
|
|
97
|
+
* This also fires if rows have only been reordered, in which case `added`, `removed` and `updated` are empty.
|
|
98
|
+
*/
|
|
95
99
|
onDiff?: (diff: WatchedQueryDifferential<RowType>) => void | Promise<void>;
|
|
96
100
|
}
|
|
97
101
|
|
package/src/db/DBAdapter.ts
CHANGED
|
@@ -258,17 +258,19 @@ class TransactionImplementation extends LockContext {
|
|
|
258
258
|
static async runWith<T>(ctx: LockContext, fn: (tx: Transaction) => Promise<T>): Promise<T> {
|
|
259
259
|
let tx = new TransactionImplementation(ctx);
|
|
260
260
|
|
|
261
|
-
|
|
262
|
-
await ctx.execute('BEGIN IMMEDIATE');
|
|
261
|
+
await ctx.execute('BEGIN IMMEDIATE');
|
|
263
262
|
|
|
263
|
+
try {
|
|
264
264
|
const result = await fn(tx);
|
|
265
265
|
await tx.commit();
|
|
266
266
|
return result;
|
|
267
267
|
} catch (ex) {
|
|
268
|
+
tx.finalized = true;
|
|
269
|
+
|
|
268
270
|
try {
|
|
269
|
-
await
|
|
271
|
+
await ctx.execute('ROLLBACK');
|
|
270
272
|
} catch (ex2) {
|
|
271
|
-
// In rare cases, a rollback may fail.
|
|
273
|
+
// In rare cases, a rollback may fail (e.g. if user code invoked commit() and then threw afterwards).
|
|
272
274
|
// Safe to ignore.
|
|
273
275
|
}
|
|
274
276
|
throw ex;
|
package/src/db/schema/Table.ts
CHANGED
|
@@ -24,6 +24,21 @@ export interface TableOrRawTableOptions {
|
|
|
24
24
|
|
|
25
25
|
interface SharedTableOptions extends TableOrRawTableOptions {
|
|
26
26
|
viewName?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Marks this table as a direct, managed table.
|
|
29
|
+
*
|
|
30
|
+
* Enabling this flag makes PowerSync store data directly as SQLite rows instead of using an intermediate view around
|
|
31
|
+
* a JSON store.
|
|
32
|
+
*
|
|
33
|
+
* The table is still managed by the PowerSync SDK, which is responsible for creating, altering and dropping them.
|
|
34
|
+
* You can query managed tables like JSON-based views, and mutations are consistently tracked as pending uploads.
|
|
35
|
+
* For more information on managed tables, see [the documentation](https://docs.powersync.com/client-sdks/advanced/performance-optimization#managed-views-vs-managed-tables).
|
|
36
|
+
*
|
|
37
|
+
* Direct tables can't use a {@link ResolvedTableOptions.viewName}.
|
|
38
|
+
*
|
|
39
|
+
* @alpha Direct tables are currently in alpha.
|
|
40
|
+
*/
|
|
41
|
+
direct?: boolean;
|
|
27
42
|
}
|
|
28
43
|
|
|
29
44
|
/** Whether to include previous column values when PowerSync tracks local changes.
|
|
@@ -135,6 +150,10 @@ export class ResolvedTable {
|
|
|
135
150
|
return this.options.ignoreEmptyUpdates!;
|
|
136
151
|
}
|
|
137
152
|
|
|
153
|
+
get direct() {
|
|
154
|
+
return this.options.direct;
|
|
155
|
+
}
|
|
156
|
+
|
|
138
157
|
get internalName() {
|
|
139
158
|
if (this.options.localOnly) {
|
|
140
159
|
return `ps_data_local__${this.name}`;
|
|
@@ -206,14 +225,19 @@ export class ResolvedTable {
|
|
|
206
225
|
|
|
207
226
|
indexNames.add(index.name);
|
|
208
227
|
}
|
|
228
|
+
|
|
229
|
+
if (this.direct && this.viewNameOverride != null) {
|
|
230
|
+
throw new Error(`Direct table ${this.name} can't use a view name override`);
|
|
231
|
+
}
|
|
209
232
|
}
|
|
210
233
|
|
|
211
234
|
toJSON() {
|
|
212
235
|
return {
|
|
213
236
|
name: this.name,
|
|
214
|
-
view_name: this.
|
|
237
|
+
view_name: this.viewNameOverride,
|
|
215
238
|
columns: this.columns.map((c) => c.toJSON()),
|
|
216
239
|
indexes: this.indexes.map((e) => e.toJSON(this)),
|
|
240
|
+
direct: this.direct,
|
|
217
241
|
...encodeTableOptions(this)
|
|
218
242
|
};
|
|
219
243
|
}
|
|
@@ -303,7 +327,8 @@ export class Table<Columns extends ColumnsType = ColumnsType> extends ResolvedTa
|
|
|
303
327
|
localOnly: options?.localOnly,
|
|
304
328
|
trackPrevious: options?.trackPrevious,
|
|
305
329
|
trackMetadata: options?.trackMetadata,
|
|
306
|
-
ignoreEmptyUpdates: options?.ignoreEmptyUpdates
|
|
330
|
+
ignoreEmptyUpdates: options?.ignoreEmptyUpdates,
|
|
331
|
+
direct: options?.direct
|
|
307
332
|
};
|
|
308
333
|
}
|
|
309
334
|
}
|
package/src/index.ts
CHANGED
|
@@ -23,7 +23,9 @@ export {
|
|
|
23
23
|
SyncStreamConnectionMethod,
|
|
24
24
|
FetchStrategy,
|
|
25
25
|
CheckpointMode,
|
|
26
|
-
CheckpointRequestsOptions
|
|
26
|
+
CheckpointRequestsOptions,
|
|
27
|
+
DownloadOptions,
|
|
28
|
+
UploadOptions
|
|
27
29
|
} from './client/sync/options.js';
|
|
28
30
|
|
|
29
31
|
export { ProgressWithOperations, SyncProgress } from './db/crud/SyncProgress.js';
|