@powersync/common 1.57.2 → 2.0.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/attachments/AttachmentContext.d.ts +5 -5
- package/lib/attachments/AttachmentContext.js +6 -2
- package/lib/attachments/AttachmentContext.js.map +1 -1
- package/lib/attachments/AttachmentQueue.d.ts +6 -6
- package/lib/attachments/AttachmentQueue.js +9 -8
- package/lib/attachments/AttachmentQueue.js.map +1 -1
- package/lib/attachments/AttachmentService.d.ts +3 -3
- package/lib/attachments/AttachmentService.js +4 -3
- package/lib/attachments/AttachmentService.js.map +1 -1
- package/lib/attachments/Schema.d.ts +2 -2
- package/lib/attachments/SyncingService.d.ts +2 -2
- package/lib/attachments/SyncingService.js +21 -6
- package/lib/attachments/SyncingService.js.map +1 -1
- package/lib/client/{AbstractPowerSyncDatabase.d.ts → CommonPowerSyncDatabase.d.ts} +56 -232
- package/lib/client/CommonPowerSyncDatabase.js +2 -0
- package/lib/client/CommonPowerSyncDatabase.js.map +1 -0
- package/lib/client/SQLOpenFactory.d.ts +35 -13
- package/lib/client/SQLOpenFactory.js +1 -25
- package/lib/client/SQLOpenFactory.js.map +1 -1
- package/lib/client/compilableQueryWatch.d.ts +2 -2
- package/lib/client/compilableQueryWatch.js +1 -2
- package/lib/client/compilableQueryWatch.js.map +1 -1
- package/lib/client/connection/PowerSyncBackendConnector.d.ts +3 -3
- package/lib/client/runOnSchemaChange.d.ts +2 -2
- package/lib/client/runOnSchemaChange.js.map +1 -1
- package/lib/client/sync/bucket/CrudEntry.d.ts +3 -34
- package/lib/client/sync/bucket/CrudEntry.js +0 -99
- package/lib/client/sync/bucket/CrudEntry.js.map +1 -1
- package/lib/client/sync/options.d.ts +65 -0
- package/lib/client/sync/options.js +25 -0
- package/lib/client/sync/options.js.map +1 -0
- package/lib/client/sync/sync-streams.d.ts +1 -1
- package/lib/client/triggers/TriggerManager.d.ts +9 -38
- package/lib/client/watched/GetAllQuery.d.ts +3 -3
- package/lib/client/watched/GetAllQuery.js +1 -1
- package/lib/client/watched/GetAllQuery.js.map +1 -1
- package/lib/client/watched/WatchedQuery.d.ts +2 -10
- package/lib/client/watched/WatchedQuery.js +0 -11
- package/lib/client/watched/WatchedQuery.js.map +1 -1
- package/lib/client/watched/processors/DifferentialQueryProcessor.d.ts +0 -50
- package/lib/client/watched/processors/DifferentialQueryProcessor.js +1 -176
- package/lib/client/watched/processors/DifferentialQueryProcessor.js.map +1 -1
- package/lib/client/watched/processors/OnChangeQueryProcessor.d.ts +0 -22
- package/lib/client/watched/processors/OnChangeQueryProcessor.js +1 -82
- package/lib/client/watched/processors/OnChangeQueryProcessor.js.map +1 -1
- package/lib/db/DBAdapter.d.ts +72 -154
- package/lib/db/DBAdapter.js +70 -108
- package/lib/db/DBAdapter.js.map +1 -1
- package/lib/db/QueryResult.d.ts +104 -0
- package/lib/db/QueryResult.js +96 -0
- package/lib/db/QueryResult.js.map +1 -0
- package/lib/db/crud/SyncProgress.d.ts +1 -13
- package/lib/db/crud/SyncProgress.js +1 -62
- package/lib/db/crud/SyncProgress.js.map +1 -1
- package/lib/db/crud/SyncStatus.d.ts +32 -66
- package/lib/db/crud/SyncStatus.js +1 -253
- package/lib/db/crud/SyncStatus.js.map +1 -1
- package/lib/db/schema/Column.d.ts +0 -7
- package/lib/db/schema/Column.js +0 -7
- package/lib/db/schema/Column.js.map +1 -1
- package/lib/db/schema/Index.d.ts +2 -6
- package/lib/db/schema/Index.js +1 -4
- package/lib/db/schema/Index.js.map +1 -1
- package/lib/db/schema/IndexedColumn.d.ts +2 -6
- package/lib/db/schema/IndexedColumn.js +1 -4
- package/lib/db/schema/IndexedColumn.js.map +1 -1
- package/lib/db/schema/Schema.d.ts +4 -28
- package/lib/db/schema/Schema.js.map +1 -1
- package/lib/db/schema/Table.d.ts +50 -96
- package/lib/db/schema/Table.js +83 -91
- package/lib/db/schema/Table.js.map +1 -1
- package/lib/index.d.ts +5 -21
- package/lib/index.js +5 -22
- package/lib/index.js.map +1 -1
- package/lib/utils/BaseObserver.d.ts +1 -1
- package/lib/utils/BaseObserver.js +1 -1
- package/lib/utils/Logger.d.ts +52 -23
- package/lib/utils/Logger.js +35 -33
- package/lib/utils/Logger.js.map +1 -1
- package/lib/utils/MetaBaseObserver.d.ts +11 -11
- package/lib/utils/MetaBaseObserver.js +1 -50
- package/lib/utils/MetaBaseObserver.js.map +1 -1
- package/lib/utils/mutex.d.ts +3 -53
- package/lib/utils/mutex.js +1 -156
- package/lib/utils/mutex.js.map +1 -1
- package/package.json +8 -45
- package/src/attachments/AttachmentContext.ts +11 -10
- package/src/attachments/AttachmentQueue.ts +15 -14
- package/src/attachments/AttachmentService.ts +7 -6
- package/src/attachments/Schema.ts +2 -2
- package/src/attachments/SyncingService.ts +23 -9
- package/src/client/CommonPowerSyncDatabase.ts +540 -0
- package/src/client/SQLOpenFactory.ts +38 -22
- package/src/client/compilableQueryWatch.ts +3 -4
- package/src/client/connection/PowerSyncBackendConnector.ts +3 -3
- package/src/client/runOnSchemaChange.ts +2 -2
- package/src/client/sync/bucket/CrudEntry.ts +4 -104
- package/src/client/sync/options.ts +77 -0
- package/src/client/sync/sync-streams.ts +1 -1
- package/src/client/triggers/TriggerManager.ts +10 -41
- package/src/client/watched/GetAllQuery.ts +3 -3
- package/src/client/watched/WatchedQuery.ts +2 -15
- package/src/client/watched/processors/DifferentialQueryProcessor.ts +0 -223
- package/src/client/watched/processors/OnChangeQueryProcessor.ts +0 -111
- package/src/db/DBAdapter.ts +141 -226
- package/src/db/QueryResult.ts +195 -0
- package/src/db/crud/SyncProgress.ts +2 -42
- package/src/db/crud/SyncStatus.ts +45 -220
- package/src/db/schema/Column.ts +0 -8
- package/src/db/schema/Index.ts +3 -6
- package/src/db/schema/IndexedColumn.ts +3 -6
- package/src/db/schema/Schema.ts +4 -4
- package/src/db/schema/Table.ts +111 -186
- package/src/index.ts +5 -21
- package/src/utils/BaseObserver.ts +1 -1
- package/src/utils/Logger.ts +80 -42
- package/src/utils/MetaBaseObserver.ts +14 -60
- package/src/utils/mutex.ts +4 -201
- package/dist/bundle.cjs +0 -14393
- package/dist/bundle.cjs.map +0 -1
- package/dist/bundle.mjs +0 -14312
- package/dist/bundle.mjs.map +0 -1
- package/dist/bundle.node.cjs +0 -12024
- package/dist/bundle.node.cjs.map +0 -1
- package/dist/bundle.node.mjs +0 -11943
- package/dist/bundle.node.mjs.map +0 -1
- package/dist/index.d.cts +0 -4651
- package/legacy/sync_protocol.d.ts +0 -103
- package/lib/client/AbstractPowerSyncDatabase.js +0 -990
- package/lib/client/AbstractPowerSyncDatabase.js.map +0 -1
- package/lib/client/AbstractPowerSyncOpenFactory.d.ts +0 -28
- package/lib/client/AbstractPowerSyncOpenFactory.js +0 -28
- package/lib/client/AbstractPowerSyncOpenFactory.js.map +0 -1
- package/lib/client/ConnectionManager.d.ts +0 -115
- package/lib/client/ConnectionManager.js +0 -294
- package/lib/client/ConnectionManager.js.map +0 -1
- package/lib/client/CustomQuery.d.ts +0 -22
- package/lib/client/CustomQuery.js +0 -43
- package/lib/client/CustomQuery.js.map +0 -1
- package/lib/client/constants.d.ts +0 -4
- package/lib/client/constants.js +0 -5
- package/lib/client/constants.js.map +0 -1
- package/lib/client/sync/bucket/BucketStorageAdapter.d.ts +0 -56
- package/lib/client/sync/bucket/BucketStorageAdapter.js +0 -29
- package/lib/client/sync/bucket/BucketStorageAdapter.js.map +0 -1
- package/lib/client/sync/bucket/SqliteBucketStorage.d.ts +0 -37
- package/lib/client/sync/bucket/SqliteBucketStorage.js +0 -165
- package/lib/client/sync/bucket/SqliteBucketStorage.js.map +0 -1
- package/lib/client/sync/stream/AbstractRemote.d.ts +0 -180
- package/lib/client/sync/stream/AbstractRemote.js +0 -508
- package/lib/client/sync/stream/AbstractRemote.js.map +0 -1
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +0 -265
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +0 -705
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js.map +0 -1
- package/lib/client/sync/stream/WebsocketClientTransport.d.ts +0 -15
- package/lib/client/sync/stream/WebsocketClientTransport.js +0 -62
- package/lib/client/sync/stream/WebsocketClientTransport.js.map +0 -1
- package/lib/client/sync/stream/core-instruction.d.ts +0 -77
- package/lib/client/sync/stream/core-instruction.js +0 -30
- package/lib/client/sync/stream/core-instruction.js.map +0 -1
- package/lib/client/triggers/MemoryTriggerClaimManager.d.ts +0 -6
- package/lib/client/triggers/MemoryTriggerClaimManager.js +0 -21
- package/lib/client/triggers/MemoryTriggerClaimManager.js.map +0 -1
- package/lib/client/triggers/TriggerManagerImpl.d.ts +0 -39
- package/lib/client/triggers/TriggerManagerImpl.js +0 -410
- package/lib/client/triggers/TriggerManagerImpl.js.map +0 -1
- package/lib/client/watched/processors/AbstractQueryProcessor.d.ts +0 -68
- package/lib/client/watched/processors/AbstractQueryProcessor.js +0 -151
- package/lib/client/watched/processors/AbstractQueryProcessor.js.map +0 -1
- package/lib/db/ConnectionClosedError.d.ts +0 -12
- package/lib/db/ConnectionClosedError.js +0 -23
- package/lib/db/ConnectionClosedError.js.map +0 -1
- package/lib/db/schema/TableV2.d.ts +0 -11
- package/lib/db/schema/TableV2.js +0 -11
- package/lib/db/schema/TableV2.js.map +0 -1
- package/lib/utils/AbortOperation.d.ts +0 -11
- package/lib/utils/AbortOperation.js +0 -21
- package/lib/utils/AbortOperation.js.map +0 -1
- package/lib/utils/ControlledExecutor.d.ts +0 -31
- package/lib/utils/ControlledExecutor.js +0 -54
- package/lib/utils/ControlledExecutor.js.map +0 -1
- package/lib/utils/async.d.ts +0 -46
- package/lib/utils/async.js +0 -147
- package/lib/utils/async.js.map +0 -1
- package/lib/utils/compatibility.d.ts +0 -8
- package/lib/utils/compatibility.js +0 -9
- package/lib/utils/compatibility.js.map +0 -1
- package/lib/utils/parseQuery.d.ts +0 -12
- package/lib/utils/parseQuery.js +0 -20
- package/lib/utils/parseQuery.js.map +0 -1
- package/lib/utils/queue.d.ts +0 -16
- package/lib/utils/queue.js +0 -42
- package/lib/utils/queue.js.map +0 -1
- package/lib/utils/stream_transform.d.ts +0 -41
- package/lib/utils/stream_transform.js +0 -211
- package/lib/utils/stream_transform.js.map +0 -1
- package/src/client/AbstractPowerSyncDatabase.ts +0 -1408
- package/src/client/AbstractPowerSyncOpenFactory.ts +0 -45
- package/src/client/ConnectionManager.ts +0 -405
- package/src/client/CustomQuery.ts +0 -56
- package/src/client/constants.ts +0 -4
- package/src/client/sync/bucket/BucketStorageAdapter.ts +0 -65
- package/src/client/sync/bucket/SqliteBucketStorage.ts +0 -202
- package/src/client/sync/stream/AbstractRemote.ts +0 -648
- package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +0 -970
- package/src/client/sync/stream/WebsocketClientTransport.ts +0 -82
- package/src/client/sync/stream/core-instruction.ts +0 -109
- package/src/client/triggers/MemoryTriggerClaimManager.ts +0 -25
- package/src/client/triggers/TriggerManagerImpl.ts +0 -501
- package/src/client/watched/processors/AbstractQueryProcessor.ts +0 -226
- package/src/db/ConnectionClosedError.ts +0 -25
- package/src/db/schema/TableV2.ts +0 -11
- package/src/utils/AbortOperation.ts +0 -19
- package/src/utils/ControlledExecutor.ts +0 -78
- package/src/utils/async.ts +0 -185
- package/src/utils/compatibility.ts +0 -9
- package/src/utils/parseQuery.ts +0 -31
- package/src/utils/queue.ts +0 -48
- package/src/utils/stream_transform.ts +0 -260
package/lib/db/DBAdapter.js
CHANGED
|
@@ -2,115 +2,98 @@
|
|
|
2
2
|
* Set of generic interfaces to allow PowerSync compatibility with
|
|
3
3
|
* different SQLite DB implementations.
|
|
4
4
|
*/
|
|
5
|
+
import { BaseObserver } from '../utils/BaseObserver.js';
|
|
6
|
+
import { queryResultFromRaw, queryResultWithoutRows } from './QueryResult.js';
|
|
5
7
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* @internal
|
|
8
|
+
* @public
|
|
9
9
|
*/
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return
|
|
19
|
-
}
|
|
20
|
-
async get(sql, parameters) {
|
|
21
|
-
const res = await this.execute(sql, parameters);
|
|
22
|
-
const first = res.rows?.item(0);
|
|
23
|
-
if (!first) {
|
|
24
|
-
throw new Error('Result set is empty');
|
|
25
|
-
}
|
|
26
|
-
return first;
|
|
10
|
+
export class LockContext {
|
|
11
|
+
async getAll(sql, parameters) {
|
|
12
|
+
const rs = await this.execute(sql, parameters);
|
|
13
|
+
return Array.from(rs);
|
|
14
|
+
}
|
|
15
|
+
async getOptional(sql, parameters) {
|
|
16
|
+
const { array } = await this.execute(sql, parameters);
|
|
17
|
+
if (array.length > 0) {
|
|
18
|
+
return array[0];
|
|
27
19
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
// Emulate executeBatch by running statements individually.
|
|
36
|
-
let lastInsertId;
|
|
37
|
-
let rowsAffected = 0;
|
|
38
|
-
for (const set of params) {
|
|
39
|
-
const result = await this.execute(query, set);
|
|
40
|
-
lastInsertId = result.insertId;
|
|
41
|
-
rowsAffected += result.rowsAffected;
|
|
42
|
-
}
|
|
43
|
-
return {
|
|
44
|
-
rowsAffected,
|
|
45
|
-
insertId: lastInsertId
|
|
46
|
-
};
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
async get(sql, parameters) {
|
|
23
|
+
const row = await this.getOptional(sql, parameters);
|
|
24
|
+
if (row == null) {
|
|
25
|
+
throw new Error('Result set is empty');
|
|
47
26
|
}
|
|
48
|
-
|
|
27
|
+
return row;
|
|
28
|
+
}
|
|
29
|
+
async execute(query, params) {
|
|
30
|
+
const raw = await this.executeRaw(query, params);
|
|
31
|
+
return queryResultFromRaw(raw);
|
|
32
|
+
}
|
|
33
|
+
async executeBatch(query, params = []) {
|
|
34
|
+
// Emulate executeBatch by running statements individually.
|
|
35
|
+
let lastInsertId;
|
|
36
|
+
let rowsAffected = 0;
|
|
37
|
+
for (const set of params) {
|
|
38
|
+
const result = await this.execute(query, set);
|
|
39
|
+
lastInsertId = result.insertId;
|
|
40
|
+
rowsAffected += result.rowsAffected ?? 0;
|
|
41
|
+
}
|
|
42
|
+
return queryResultWithoutRows({
|
|
43
|
+
rowsAffected,
|
|
44
|
+
insertId: lastInsertId
|
|
45
|
+
});
|
|
46
|
+
}
|
|
49
47
|
}
|
|
50
48
|
/**
|
|
51
|
-
* Update table operation numbers from SQLite
|
|
52
|
-
*
|
|
53
49
|
* @public
|
|
54
50
|
*/
|
|
55
|
-
export
|
|
56
|
-
(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
get(sql, parameters) {
|
|
82
|
-
return this.readLock((ctx) => ctx.get(sql, parameters));
|
|
83
|
-
}
|
|
84
|
-
execute(query, params) {
|
|
85
|
-
return this.writeLock((ctx) => ctx.execute(query, params));
|
|
86
|
-
}
|
|
87
|
-
executeRaw(query, params) {
|
|
88
|
-
return this.writeLock((ctx) => ctx.executeRaw(query, params));
|
|
89
|
-
}
|
|
90
|
-
executeBatch(query, params) {
|
|
91
|
-
return this.writeTransaction((tx) => tx.executeBatch(query, params));
|
|
92
|
-
}
|
|
93
|
-
};
|
|
51
|
+
export class DBAdapter extends BaseObserver {
|
|
52
|
+
readTransaction(fn, options) {
|
|
53
|
+
return this.readLock((ctx) => TransactionImplementation.runWith(ctx, fn), options);
|
|
54
|
+
}
|
|
55
|
+
writeTransaction(fn, options) {
|
|
56
|
+
return this.writeLock((ctx) => TransactionImplementation.runWith(ctx, fn), options);
|
|
57
|
+
}
|
|
58
|
+
getAll(sql, parameters) {
|
|
59
|
+
return this.readLock((ctx) => ctx.getAll(sql, parameters));
|
|
60
|
+
}
|
|
61
|
+
getOptional(sql, parameters) {
|
|
62
|
+
return this.readLock((ctx) => ctx.getOptional(sql, parameters));
|
|
63
|
+
}
|
|
64
|
+
get(sql, parameters) {
|
|
65
|
+
return this.readLock((ctx) => ctx.get(sql, parameters));
|
|
66
|
+
}
|
|
67
|
+
execute(query, params) {
|
|
68
|
+
return this.writeLock((ctx) => ctx.execute(query, params));
|
|
69
|
+
}
|
|
70
|
+
executeRaw(query, params) {
|
|
71
|
+
return this.writeLock((ctx) => ctx.executeRaw(query, params));
|
|
72
|
+
}
|
|
73
|
+
executeBatch(query, params) {
|
|
74
|
+
return this.writeTransaction((tx) => tx.executeBatch(query, params));
|
|
75
|
+
}
|
|
94
76
|
}
|
|
95
|
-
class
|
|
77
|
+
class TransactionImplementation extends LockContext {
|
|
96
78
|
inner;
|
|
97
79
|
finalized = false;
|
|
98
80
|
constructor(inner) {
|
|
81
|
+
super();
|
|
99
82
|
this.inner = inner;
|
|
100
83
|
}
|
|
101
84
|
async commit() {
|
|
102
85
|
if (this.finalized) {
|
|
103
|
-
return
|
|
86
|
+
return;
|
|
104
87
|
}
|
|
105
88
|
this.finalized = true;
|
|
106
|
-
|
|
89
|
+
await this.inner.execute('COMMIT');
|
|
107
90
|
}
|
|
108
91
|
async rollback() {
|
|
109
92
|
if (this.finalized) {
|
|
110
|
-
return
|
|
93
|
+
return;
|
|
111
94
|
}
|
|
112
95
|
this.finalized = true;
|
|
113
|
-
|
|
96
|
+
await this.inner.execute('ROLLBACK');
|
|
114
97
|
}
|
|
115
98
|
execute(query, params) {
|
|
116
99
|
return this.inner.execute(query, params);
|
|
@@ -121,19 +104,10 @@ class BaseTransaction {
|
|
|
121
104
|
executeBatch(query, params) {
|
|
122
105
|
return this.inner.executeBatch(query, params);
|
|
123
106
|
}
|
|
124
|
-
}
|
|
125
|
-
class TransactionImplementation extends DBGetUtilsDefaultMixin(BaseTransaction) {
|
|
126
107
|
static async runWith(ctx, fn) {
|
|
127
108
|
let tx = new TransactionImplementation(ctx);
|
|
128
|
-
// For write transactions, use BEGIN IMMEDIATE to immediately obtain a write lock on the database (instead of doing
|
|
129
|
-
// that on the first statement). If we have a genuine read-only connection, we also use BEGIN IMMEDIATE there: In
|
|
130
|
-
// WAL mode, that ensures we pin the current state of the database (instead of the state at the first statement in
|
|
131
|
-
// the transaction). But if we have a "fake" read-only connection implemented through `pragma query_only = true`, we
|
|
132
|
-
// can't use this trick because it would attempt to lock the connection. So there, we use a regular `BEGIN`
|
|
133
|
-
// statement.
|
|
134
|
-
const useBeginImmediate = ctx.connectionType != 'queryOnly';
|
|
135
109
|
try {
|
|
136
|
-
await ctx.execute(
|
|
110
|
+
await ctx.execute('BEGIN IMMEDIATE');
|
|
137
111
|
const result = await fn(tx);
|
|
138
112
|
await tx.commit();
|
|
139
113
|
return result;
|
|
@@ -150,16 +124,4 @@ class TransactionImplementation extends DBGetUtilsDefaultMixin(BaseTransaction)
|
|
|
150
124
|
}
|
|
151
125
|
}
|
|
152
126
|
}
|
|
153
|
-
/**
|
|
154
|
-
* @internal
|
|
155
|
-
*/
|
|
156
|
-
export function isBatchedUpdateNotification(update) {
|
|
157
|
-
return 'tables' in update;
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* @internal
|
|
161
|
-
*/
|
|
162
|
-
export function extractTableUpdates(update) {
|
|
163
|
-
return isBatchedUpdateNotification(update) ? update.tables : [update.table];
|
|
164
|
-
}
|
|
165
127
|
//# sourceMappingURL=DBAdapter.js.map
|
package/lib/db/DBAdapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DBAdapter.js","sourceRoot":"","sources":["../../src/db/DBAdapter.ts"],"names":[],"m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AAC;QACtB,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACvC,CAAC;IAED,OAAO,CAAI,KAAa,EAAE,MAA0B;QAClD,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC3C,CAAC;IAED,UAAU,CAAC,KAAa,EAAE,MAA0B;QAClD,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC9C,CAAC;IAED,YAAY,CAAC,KAAa,EAAE,MAAgB;QAC1C,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAChD,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,OAAO,CAAI,GAAgB,EAAE,EAAmC;QAC3E,IAAI,EAAE,GAAG,IAAI,yBAAyB,CAAC,GAAG,CAAC,CAAC;QAE5C,IAAI,CAAC;YACH,MAAM,GAAG,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;YAErC,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;YAC5B,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC;YAClB,OAAO,MAAM,CAAC;QAChB,CAAC;QAAC,OAAO,EAAE,EAAE,CAAC;YACZ,IAAI,CAAC;gBACH,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC;YACtB,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,sCAAsC;gBACtC,kBAAkB;YACpB,CAAC;YACD,MAAM,EAAE,CAAC;QACX,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A SQLite value, either text, a number, a blob value or null.
|
|
3
|
+
*
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export type SqliteValue = string | number | bigint | number[] | Uint8Array | null;
|
|
7
|
+
/**
|
|
8
|
+
* A record of SQLite values representing a row.
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export type SqliteRecord = Record<string, SqliteValue>;
|
|
13
|
+
/**
|
|
14
|
+
* A representation of query results as JavaScript object.
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export interface ResultSet {
|
|
19
|
+
/**
|
|
20
|
+
* The amount of rows in the result set.
|
|
21
|
+
*/
|
|
22
|
+
get length(): number;
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated Use {@link QueryResult.array} instead.
|
|
25
|
+
*/
|
|
26
|
+
get _array(): any[];
|
|
27
|
+
/**
|
|
28
|
+
* @deprecated Use {@link QueryResult.array} instead.
|
|
29
|
+
*/
|
|
30
|
+
item<T>(idx: number): T;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Shared superinterface for {@link QueryResult} and {@link RawQueryResult}.
|
|
34
|
+
*
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
export interface BaseQueryResult {
|
|
38
|
+
/** Represents the auto-generated row id if applicable. */
|
|
39
|
+
insertId?: number;
|
|
40
|
+
/**
|
|
41
|
+
* Number of affected rows reported by SQLite for a write query.
|
|
42
|
+
*
|
|
43
|
+
* When using the default client-side [JSON-based view system](https://docs.powersync.com/architecture/client-architecture#client-side-schema-and-sqlite-database-structure),
|
|
44
|
+
* `rowsAffected` may be `0` for successful `UPDATE` and `DELETE` statements.
|
|
45
|
+
* Use a `RETURNING` clause and inspect `rows` when you need to confirm which rows changed.
|
|
46
|
+
*/
|
|
47
|
+
rowsAffected?: number;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Object returned by SQL Query executions.
|
|
51
|
+
*
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
export interface QueryResult<T = SqliteRecord> extends BaseQueryResult, Iterable<T, undefined> {
|
|
55
|
+
/**
|
|
56
|
+
* If the query returned rows, the result set containing returned values.
|
|
57
|
+
*/
|
|
58
|
+
rows?: ResultSet;
|
|
59
|
+
/**
|
|
60
|
+
* Rows in this result set.
|
|
61
|
+
*/
|
|
62
|
+
array: T[];
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* A raw array-based result set representing rows returned by SQLite.
|
|
66
|
+
*
|
|
67
|
+
* @public
|
|
68
|
+
*/
|
|
69
|
+
export interface RawQueryResult extends BaseQueryResult {
|
|
70
|
+
/**
|
|
71
|
+
* Names of columns in this result set. Every column has a name, so the length of this array is always equal to the
|
|
72
|
+
* amount of columns in the result set.
|
|
73
|
+
*
|
|
74
|
+
* Note that column names are not necessarily unique, e.g. a `SELECT foo.user, bar.user FROM ...` will have
|
|
75
|
+
* `['user', 'user']` in this array.
|
|
76
|
+
*/
|
|
77
|
+
columnNames: string[];
|
|
78
|
+
/**
|
|
79
|
+
* Rows in the result set.
|
|
80
|
+
*
|
|
81
|
+
* Each row has a length equal to {@link RawQueryResult.columnNames}.
|
|
82
|
+
*/
|
|
83
|
+
rawRows: SqliteValue[][];
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Creates a query result by mapping raw rows to JavaScript.
|
|
87
|
+
*
|
|
88
|
+
* This should not be used with libraries doing this mapping natively, as that is typically more performant.
|
|
89
|
+
*
|
|
90
|
+
* @public
|
|
91
|
+
*/
|
|
92
|
+
export declare function queryResultFromRaw<T>(raw: RawQueryResult): QueryResult<T>;
|
|
93
|
+
/**
|
|
94
|
+
* Creates a query result from rows that have already been mapped to JavaScript.
|
|
95
|
+
*
|
|
96
|
+
* @public
|
|
97
|
+
*/
|
|
98
|
+
export declare function queryResultFromMapped<T>(base: BaseQueryResult, rows?: T[]): QueryResult<T>;
|
|
99
|
+
/**
|
|
100
|
+
* Creates a {@link QueryResult} not containing any rows.
|
|
101
|
+
*
|
|
102
|
+
* @public
|
|
103
|
+
*/
|
|
104
|
+
export declare function queryResultWithoutRows(result: BaseQueryResult): QueryResult<never>;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
function rowToRecord(columnNames, row) {
|
|
2
|
+
const record = {};
|
|
3
|
+
columnNames.forEach((name, idx) => (record[name] = row[idx]));
|
|
4
|
+
return record;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Creates a query result by mapping raw rows to JavaScript.
|
|
8
|
+
*
|
|
9
|
+
* This should not be used with libraries doing this mapping natively, as that is typically more performant.
|
|
10
|
+
*
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export function queryResultFromRaw(raw) {
|
|
14
|
+
const { insertId, rowsAffected, columnNames, rawRows } = raw;
|
|
15
|
+
let array;
|
|
16
|
+
function loadAsArray() {
|
|
17
|
+
if (array)
|
|
18
|
+
return array;
|
|
19
|
+
return (array = rawRows.map((row) => rowToRecord(columnNames, row)));
|
|
20
|
+
}
|
|
21
|
+
function getRow(idx) {
|
|
22
|
+
if (array)
|
|
23
|
+
return array[idx];
|
|
24
|
+
return rowToRecord(columnNames, rawRows[idx]);
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
insertId,
|
|
28
|
+
rowsAffected,
|
|
29
|
+
get array() {
|
|
30
|
+
return loadAsArray();
|
|
31
|
+
},
|
|
32
|
+
rows: {
|
|
33
|
+
length: rawRows.length,
|
|
34
|
+
get _array() {
|
|
35
|
+
return loadAsArray();
|
|
36
|
+
},
|
|
37
|
+
item: getRow
|
|
38
|
+
},
|
|
39
|
+
[Symbol.iterator]() {
|
|
40
|
+
let nextIndex = 0;
|
|
41
|
+
return {
|
|
42
|
+
next: function () {
|
|
43
|
+
if (nextIndex >= rawRows.length) {
|
|
44
|
+
return { done: true, value: undefined };
|
|
45
|
+
}
|
|
46
|
+
const row = getRow(nextIndex);
|
|
47
|
+
nextIndex++;
|
|
48
|
+
return { done: false, value: row };
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Creates a query result from rows that have already been mapped to JavaScript.
|
|
56
|
+
*
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
59
|
+
export function queryResultFromMapped(base, rows) {
|
|
60
|
+
if (rows == null)
|
|
61
|
+
return queryResultWithoutRows(base);
|
|
62
|
+
return {
|
|
63
|
+
insertId: base.insertId,
|
|
64
|
+
rowsAffected: base.rowsAffected,
|
|
65
|
+
array: rows ?? [],
|
|
66
|
+
rows: {
|
|
67
|
+
length: rows.length,
|
|
68
|
+
_array: rows,
|
|
69
|
+
item(i) {
|
|
70
|
+
return rows[i];
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
[Symbol.iterator]() {
|
|
74
|
+
return rows[Symbol.iterator]();
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Creates a {@link QueryResult} not containing any rows.
|
|
80
|
+
*
|
|
81
|
+
* @public
|
|
82
|
+
*/
|
|
83
|
+
export function queryResultWithoutRows(result) {
|
|
84
|
+
return {
|
|
85
|
+
...result,
|
|
86
|
+
array: [],
|
|
87
|
+
[Symbol.iterator]() {
|
|
88
|
+
return {
|
|
89
|
+
next() {
|
|
90
|
+
return { done: true, value: undefined };
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=QueryResult.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueryResult.js","sourceRoot":"","sources":["../../src/db/QueryResult.ts"],"names":[],"mappings":"AA6FA,SAAS,WAAW,CAAI,WAAqB,EAAE,GAAkB;IAC/D,MAAM,MAAM,GAAiB,EAAE,CAAC;IAChC,WAAW,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAC9D,OAAO,MAAW,CAAC;AACrB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ACF,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAI,IAAqB,EAAE,IAAU;IACxE,IAAI,IAAI,IAAI,IAAI;QAAE,OAAO,sBAAsB,CAAC,IAAI,CAAC,CAAC;IAEtD,OAAO;QACL,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,YAAY,EAAE,IAAI,CAAC,YAAY;QAC/B,KAAK,EAAE,IAAI,IAAI,EAAE;QACjB,IAAI,EAAE;YACJ,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,MAAM,EAAE,IAAI;YACZ,IAAI,CAAC,CAAS;gBACZ,OAAO,IAAI,CAAC,CAAC,CAAQ,CAAC;YACxB,CAAC;SACkB;QACrB,CAAC,MAAM,CAAC,QAAQ,CAAC;YACf,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;QACjC,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAAuB;IAC5D,OAAO;QACL,GAAG,MAAM;QACT,KAAK,EAAE,EAAE;QACT,CAAC,MAAM,CAAC,QAAQ,CAAC;YACf,OAAO;gBACL,IAAI;oBACF,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;gBAC1C,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
import type { BucketProgress } from '../../client/sync/stream/core-instruction.js';
|
|
2
|
-
/** @internal */
|
|
3
|
-
export type InternalProgressInformation = Record<string, BucketProgress>;
|
|
4
|
-
/**
|
|
5
|
-
* @internal The priority used by the core extension to indicate that a full sync was completed.
|
|
6
|
-
*/
|
|
7
|
-
export declare const FULL_SYNC_PRIORITY = 2147483647;
|
|
8
1
|
/**
|
|
9
2
|
* Information about a progressing download made by the PowerSync SDK.
|
|
10
3
|
*
|
|
@@ -57,12 +50,7 @@ export interface ProgressWithOperations {
|
|
|
57
50
|
*
|
|
58
51
|
* @public
|
|
59
52
|
*/
|
|
60
|
-
export
|
|
61
|
-
protected internal: InternalProgressInformation;
|
|
62
|
-
totalOperations: number;
|
|
63
|
-
downloadedOperations: number;
|
|
64
|
-
downloadedFraction: number;
|
|
65
|
-
constructor(internal: InternalProgressInformation);
|
|
53
|
+
export interface SyncProgress extends ProgressWithOperations {
|
|
66
54
|
/**
|
|
67
55
|
* Returns download progress towards all data up until the specified priority being received.
|
|
68
56
|
*
|
|
@@ -1,63 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
* @internal The priority used by the core extension to indicate that a full sync was completed.
|
|
3
|
-
*/
|
|
4
|
-
export const FULL_SYNC_PRIORITY = 2147483647;
|
|
5
|
-
/**
|
|
6
|
-
* Provides realtime progress on how PowerSync is downloading rows.
|
|
7
|
-
*
|
|
8
|
-
* The progress until the next complete sync is available through the fields on {@link ProgressWithOperations},
|
|
9
|
-
* which this class implements.
|
|
10
|
-
* Additionally, the {@link SyncProgress.untilPriority} method can be used to otbain progress towards
|
|
11
|
-
* a specific priority (instead of the progress for the entire download).
|
|
12
|
-
*
|
|
13
|
-
* The reported progress always reflects the status towards the end of a sync iteration (after
|
|
14
|
-
* which a consistent snapshot of all buckets is available locally).
|
|
15
|
-
*
|
|
16
|
-
* In rare cases (in particular, when a [compacting](https://docs.powersync.com/usage/lifecycle-maintenance/compacting-buckets)
|
|
17
|
-
* operation takes place between syncs), it's possible for the returned numbers to be slightly
|
|
18
|
-
* inaccurate. For this reason, {@link SyncProgress} should be seen as an approximation of progress.
|
|
19
|
-
* The information returned is good enough to build progress bars, but not exact enough to track
|
|
20
|
-
* individual download counts.
|
|
21
|
-
*
|
|
22
|
-
* Also note that data is downloaded in bulk, which means that individual counters are unlikely
|
|
23
|
-
* to be updated one-by-one.
|
|
24
|
-
*
|
|
25
|
-
* @public
|
|
26
|
-
*/
|
|
27
|
-
export class SyncProgress {
|
|
28
|
-
internal;
|
|
29
|
-
totalOperations;
|
|
30
|
-
downloadedOperations;
|
|
31
|
-
downloadedFraction;
|
|
32
|
-
constructor(internal) {
|
|
33
|
-
this.internal = internal;
|
|
34
|
-
const untilCompletion = this.untilPriority(FULL_SYNC_PRIORITY);
|
|
35
|
-
this.totalOperations = untilCompletion.totalOperations;
|
|
36
|
-
this.downloadedOperations = untilCompletion.downloadedOperations;
|
|
37
|
-
this.downloadedFraction = untilCompletion.downloadedFraction;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Returns download progress towards all data up until the specified priority being received.
|
|
41
|
-
*
|
|
42
|
-
* The returned {@link ProgressWithOperations} tracks the target amount of operations that need
|
|
43
|
-
* to be downloaded in total and how many of them have already been received.
|
|
44
|
-
*/
|
|
45
|
-
untilPriority(priority) {
|
|
46
|
-
let total = 0;
|
|
47
|
-
let downloaded = 0;
|
|
48
|
-
for (const progress of Object.values(this.internal)) {
|
|
49
|
-
// Include higher-priority buckets, which are represented by lower numbers.
|
|
50
|
-
if (progress.priority <= priority) {
|
|
51
|
-
downloaded += progress.since_last;
|
|
52
|
-
total += progress.target_count - progress.at_last;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
let progress = total == 0 ? 0.0 : downloaded / total;
|
|
56
|
-
return {
|
|
57
|
-
totalOperations: total,
|
|
58
|
-
downloadedOperations: downloaded,
|
|
59
|
-
downloadedFraction: progress
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
}
|
|
1
|
+
export {};
|
|
63
2
|
//# sourceMappingURL=SyncProgress.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SyncProgress.js","sourceRoot":"","sources":["../../../src/db/crud/SyncProgress.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SyncProgress.js","sourceRoot":"","sources":["../../../src/db/crud/SyncProgress.ts"],"names":[],"mappings":""}
|