@powersync/common 0.0.0-dev-20260504100448 → 0.0.0-dev-20260630141119
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 +9 -8
- package/lib/attachments/AttachmentContext.js +8 -3
- package/lib/attachments/AttachmentContext.js.map +1 -1
- package/lib/attachments/AttachmentErrorHandler.d.ts +6 -6
- package/lib/attachments/AttachmentQueue.d.ts +85 -36
- package/lib/attachments/AttachmentQueue.js +19 -21
- 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/LocalStorageAdapter.d.ts +14 -8
- package/lib/attachments/LocalStorageAdapter.js +3 -0
- package/lib/attachments/LocalStorageAdapter.js.map +1 -1
- package/lib/attachments/RemoteStorageAdapter.d.ts +4 -4
- package/lib/attachments/Schema.d.ts +14 -6
- package/lib/attachments/Schema.js +8 -3
- package/lib/attachments/Schema.js.map +1 -1
- package/lib/attachments/SyncingService.d.ts +2 -2
- package/lib/attachments/SyncingService.js +8 -3
- package/lib/attachments/SyncingService.js.map +1 -1
- package/lib/attachments/WatchedAttachmentItem.d.ts +3 -1
- package/lib/client/{AbstractPowerSyncDatabase.d.ts → CommonPowerSyncDatabase.d.ts} +112 -238
- package/lib/client/CommonPowerSyncDatabase.js +2 -0
- package/lib/client/CommonPowerSyncDatabase.js.map +1 -0
- package/lib/client/Query.d.ts +9 -0
- package/lib/client/SQLOpenFactory.d.ts +44 -10
- package/lib/client/SQLOpenFactory.js +1 -19
- package/lib/client/SQLOpenFactory.js.map +1 -1
- package/lib/client/compilableQueryWatch.d.ts +8 -2
- package/lib/client/compilableQueryWatch.js +4 -2
- package/lib/client/compilableQueryWatch.js.map +1 -1
- package/lib/client/connection/PowerSyncBackendConnector.d.ts +6 -3
- package/lib/client/connection/PowerSyncCredentials.d.ts +3 -0
- package/lib/client/runOnSchemaChange.d.ts +5 -2
- package/lib/client/runOnSchemaChange.js +3 -0
- package/lib/client/runOnSchemaChange.js.map +1 -1
- package/lib/client/sync/bucket/CrudBatch.d.ts +2 -0
- package/lib/client/sync/bucket/CrudBatch.js +2 -0
- package/lib/client/sync/bucket/CrudBatch.js.map +1 -1
- package/lib/client/sync/bucket/CrudEntry.d.ts +9 -31
- package/lib/client/sync/bucket/CrudEntry.js +2 -97
- package/lib/client/sync/bucket/CrudEntry.js.map +1 -1
- package/lib/client/sync/bucket/CrudTransaction.d.ts +3 -0
- package/lib/client/sync/bucket/CrudTransaction.js +3 -0
- package/lib/client/sync/bucket/CrudTransaction.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/stream/JsonValue.d.ts +3 -0
- package/lib/client/sync/sync-streams.d.ts +23 -8
- package/lib/client/triggers/TriggerManager.d.ts +28 -56
- package/lib/client/triggers/TriggerManager.js +2 -1
- package/lib/client/triggers/TriggerManager.js.map +1 -1
- package/lib/client/triggers/sanitizeSQL.d.ts +4 -0
- package/lib/client/triggers/sanitizeSQL.js +4 -0
- package/lib/client/triggers/sanitizeSQL.js.map +1 -1
- package/lib/client/watched/GetAllQuery.d.ts +7 -3
- package/lib/client/watched/GetAllQuery.js +3 -1
- package/lib/client/watched/GetAllQuery.js.map +1 -1
- package/lib/client/watched/WatchedQuery.d.ts +20 -6
- package/lib/client/watched/WatchedQuery.js +3 -5
- package/lib/client/watched/WatchedQuery.js.map +1 -1
- package/lib/client/watched/processors/DifferentialQueryProcessor.d.ts +15 -45
- package/lib/client/watched/processors/DifferentialQueryProcessor.js +1 -172
- package/lib/client/watched/processors/DifferentialQueryProcessor.js.map +1 -1
- package/lib/client/watched/processors/OnChangeQueryProcessor.d.ts +4 -22
- package/lib/client/watched/processors/OnChangeQueryProcessor.js +1 -82
- package/lib/client/watched/processors/OnChangeQueryProcessor.js.map +1 -1
- package/lib/client/watched/processors/comparators.d.ts +8 -0
- package/lib/client/watched/processors/comparators.js +4 -0
- package/lib/client/watched/processors/comparators.js.map +1 -1
- package/lib/db/DBAdapter.d.ts +90 -113
- package/lib/db/DBAdapter.js +70 -89
- 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 +7 -14
- package/lib/db/crud/SyncProgress.js +1 -60
- package/lib/db/crud/SyncProgress.js.map +1 -1
- package/lib/db/crud/SyncStatus.d.ts +54 -91
- package/lib/db/crud/SyncStatus.js +1 -245
- package/lib/db/crud/SyncStatus.js.map +1 -1
- package/lib/db/crud/UploadQueueStatus.d.ts +3 -0
- package/lib/db/crud/UploadQueueStatus.js +3 -0
- package/lib/db/crud/UploadQueueStatus.js.map +1 -1
- package/lib/db/schema/Column.d.ts +22 -1
- package/lib/db/schema/Column.js +10 -4
- package/lib/db/schema/Column.js.map +1 -1
- package/lib/db/schema/Index.d.ts +8 -3
- package/lib/db/schema/Index.js +4 -1
- package/lib/db/schema/Index.js.map +1 -1
- package/lib/db/schema/IndexedColumn.d.ts +8 -3
- package/lib/db/schema/IndexedColumn.js +4 -1
- package/lib/db/schema/IndexedColumn.js.map +1 -1
- package/lib/db/schema/RawTable.d.ts +7 -1
- package/lib/db/schema/Schema.d.ts +10 -29
- package/lib/db/schema/Schema.js +3 -1
- package/lib/db/schema/Schema.js.map +1 -1
- package/lib/db/schema/Table.d.ts +69 -91
- package/lib/db/schema/Table.js +88 -87
- package/lib/db/schema/Table.js.map +1 -1
- package/lib/index.d.ts +6 -22
- package/lib/index.js +5 -22
- package/lib/index.js.map +1 -1
- package/lib/types/types.d.ts +6 -0
- package/lib/utils/BaseObserver.d.ts +12 -0
- package/lib/utils/BaseObserver.js +3 -0
- package/lib/utils/BaseObserver.js.map +1 -1
- package/lib/utils/Logger.d.ts +60 -22
- package/lib/utils/Logger.js +38 -30
- 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 -45
- package/lib/utils/mutex.js +1 -153
- package/lib/utils/mutex.js.map +1 -1
- package/package.json +9 -46
- package/src/attachments/AttachmentContext.ts +15 -13
- package/src/attachments/AttachmentErrorHandler.ts +6 -6
- package/src/attachments/AttachmentQueue.ts +99 -42
- package/src/attachments/AttachmentService.ts +7 -6
- package/src/attachments/LocalStorageAdapter.ts +14 -8
- package/src/attachments/README.md +2 -0
- package/src/attachments/RemoteStorageAdapter.ts +4 -4
- package/src/attachments/Schema.ts +14 -6
- package/src/attachments/SyncingService.ts +10 -6
- package/src/attachments/WatchedAttachmentItem.ts +3 -1
- package/src/client/CommonPowerSyncDatabase.ts +540 -0
- package/src/client/Query.ts +9 -0
- package/src/client/SQLOpenFactory.ts +47 -19
- package/src/client/compilableQueryWatch.ts +9 -4
- package/src/client/connection/PowerSyncBackendConnector.ts +6 -3
- package/src/client/connection/PowerSyncCredentials.ts +3 -0
- package/src/client/runOnSchemaChange.ts +5 -2
- package/src/client/sync/bucket/CrudBatch.ts +2 -0
- package/src/client/sync/bucket/CrudEntry.ts +10 -101
- package/src/client/sync/bucket/CrudTransaction.ts +3 -0
- package/src/client/sync/options.ts +77 -0
- package/src/client/sync/stream/JsonValue.ts +3 -0
- package/src/client/sync/sync-streams.ts +23 -10
- package/src/client/triggers/TriggerManager.ts +29 -59
- package/src/client/triggers/sanitizeSQL.ts +5 -0
- package/src/client/watched/GetAllQuery.ts +8 -4
- package/src/client/watched/WatchedQuery.ts +20 -11
- package/src/client/watched/processors/DifferentialQueryProcessor.ts +19 -219
- package/src/client/watched/processors/OnChangeQueryProcessor.ts +4 -109
- package/src/client/watched/processors/comparators.ts +8 -0
- package/src/db/DBAdapter.ts +160 -175
- package/src/db/QueryResult.ts +195 -0
- package/src/db/crud/SyncProgress.ts +8 -43
- package/src/db/crud/SyncStatus.ts +66 -216
- package/src/db/crud/UploadQueueStatus.ts +3 -0
- package/src/db/schema/Column.ts +22 -5
- package/src/db/schema/Index.ts +9 -3
- package/src/db/schema/IndexedColumn.ts +9 -3
- package/src/db/schema/RawTable.ts +7 -1
- package/src/db/schema/Schema.ts +12 -7
- package/src/db/schema/Table.ts +130 -180
- package/src/index.ts +6 -22
- package/src/types/types.ts +6 -0
- package/src/utils/BaseObserver.ts +12 -0
- package/src/utils/Logger.ts +86 -31
- package/src/utils/MetaBaseObserver.ts +14 -60
- package/src/utils/mutex.ts +4 -189
- package/dist/bundle.cjs +0 -14136
- package/dist/bundle.cjs.map +0 -1
- package/dist/bundle.mjs +0 -14056
- package/dist/bundle.mjs.map +0 -1
- package/dist/bundle.node.cjs +0 -11613
- package/dist/bundle.node.cjs.map +0 -1
- package/dist/bundle.node.mjs +0 -11533
- package/dist/bundle.node.mjs.map +0 -1
- package/dist/index.d.cts +0 -4052
- package/legacy/sync_protocol.d.ts +0 -103
- package/lib/client/AbstractPowerSyncDatabase.js +0 -987
- package/lib/client/AbstractPowerSyncDatabase.js.map +0 -1
- package/lib/client/AbstractPowerSyncOpenFactory.d.ts +0 -22
- package/lib/client/AbstractPowerSyncOpenFactory.js +0 -25
- package/lib/client/AbstractPowerSyncOpenFactory.js.map +0 -1
- package/lib/client/ConnectionManager.d.ts +0 -112
- 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 -1
- package/lib/client/constants.js +0 -2
- package/lib/client/constants.js.map +0 -1
- package/lib/client/sync/bucket/BucketStorageAdapter.d.ts +0 -40
- package/lib/client/sync/bucket/BucketStorageAdapter.js +0 -19
- package/lib/client/sync/bucket/BucketStorageAdapter.js.map +0 -1
- package/lib/client/sync/bucket/SqliteBucketStorage.d.ts +0 -34
- package/lib/client/sync/bucket/SqliteBucketStorage.js +0 -162
- package/lib/client/sync/bucket/SqliteBucketStorage.js.map +0 -1
- package/lib/client/sync/stream/AbstractRemote.d.ts +0 -151
- package/lib/client/sync/stream/AbstractRemote.js +0 -473
- package/lib/client/sync/stream/AbstractRemote.js.map +0 -1
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +0 -218
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +0 -663
- 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 -61
- package/lib/client/sync/stream/WebsocketClientTransport.js.map +0 -1
- package/lib/client/sync/stream/core-instruction.d.ts +0 -71
- package/lib/client/sync/stream/core-instruction.js +0 -27
- 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 -405
- 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 -10
- package/lib/db/ConnectionClosedError.js +0 -21
- package/lib/db/ConnectionClosedError.js.map +0 -1
- package/lib/db/schema/TableV2.d.ts +0 -9
- package/lib/db/schema/TableV2.js +0 -9
- package/lib/db/schema/TableV2.js.map +0 -1
- package/lib/utils/AbortOperation.d.ts +0 -9
- package/lib/utils/AbortOperation.js +0 -19
- package/lib/utils/AbortOperation.js.map +0 -1
- package/lib/utils/ControlledExecutor.d.ts +0 -25
- package/lib/utils/ControlledExecutor.js +0 -51
- package/lib/utils/ControlledExecutor.js.map +0 -1
- package/lib/utils/async.d.ts +0 -14
- package/lib/utils/async.js +0 -46
- package/lib/utils/async.js.map +0 -1
- package/lib/utils/parseQuery.d.ts +0 -6
- package/lib/utils/parseQuery.js +0 -17
- 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 -39
- package/lib/utils/stream_transform.js +0 -206
- package/lib/utils/stream_transform.js.map +0 -1
- package/src/client/AbstractPowerSyncDatabase.ts +0 -1362
- package/src/client/AbstractPowerSyncOpenFactory.ts +0 -39
- package/src/client/ConnectionManager.ts +0 -402
- package/src/client/CustomQuery.ts +0 -56
- package/src/client/constants.ts +0 -1
- package/src/client/sync/bucket/BucketStorageAdapter.ts +0 -49
- package/src/client/sync/bucket/SqliteBucketStorage.ts +0 -199
- package/src/client/sync/stream/AbstractRemote.ts +0 -602
- package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +0 -905
- package/src/client/sync/stream/WebsocketClientTransport.ts +0 -80
- package/src/client/sync/stream/core-instruction.ts +0 -98
- package/src/client/triggers/MemoryTriggerClaimManager.ts +0 -25
- package/src/client/triggers/TriggerManagerImpl.ts +0 -496
- package/src/client/watched/processors/AbstractQueryProcessor.ts +0 -226
- package/src/db/ConnectionClosedError.ts +0 -23
- package/src/db/schema/TableV2.ts +0 -9
- package/src/utils/AbortOperation.ts +0 -17
- package/src/utils/ControlledExecutor.ts +0 -72
- package/src/utils/async.ts +0 -50
- package/src/utils/parseQuery.ts +0 -25
- package/src/utils/queue.ts +0 -48
- package/src/utils/stream_transform.ts +0 -252
package/lib/db/DBAdapter.js
CHANGED
|
@@ -2,109 +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
|
-
*
|
|
8
|
+
* @public
|
|
7
9
|
*/
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return
|
|
17
|
-
}
|
|
18
|
-
async get(sql, parameters) {
|
|
19
|
-
const res = await this.execute(sql, parameters);
|
|
20
|
-
const first = res.rows?.item(0);
|
|
21
|
-
if (!first) {
|
|
22
|
-
throw new Error('Result set is empty');
|
|
23
|
-
}
|
|
24
|
-
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];
|
|
25
19
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
// Emulate executeBatch by running statements individually.
|
|
34
|
-
let lastInsertId;
|
|
35
|
-
let rowsAffected = 0;
|
|
36
|
-
for (const set of params) {
|
|
37
|
-
const result = await this.execute(query, set);
|
|
38
|
-
lastInsertId = result.insertId;
|
|
39
|
-
rowsAffected += result.rowsAffected;
|
|
40
|
-
}
|
|
41
|
-
return {
|
|
42
|
-
rowsAffected,
|
|
43
|
-
insertId: lastInsertId
|
|
44
|
-
};
|
|
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');
|
|
45
26
|
}
|
|
46
|
-
|
|
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
|
+
}
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
|
-
*
|
|
50
|
-
*/
|
|
51
|
-
export var RowUpdateType;
|
|
52
|
-
(function (RowUpdateType) {
|
|
53
|
-
RowUpdateType[RowUpdateType["SQLITE_INSERT"] = 18] = "SQLITE_INSERT";
|
|
54
|
-
RowUpdateType[RowUpdateType["SQLITE_DELETE"] = 9] = "SQLITE_DELETE";
|
|
55
|
-
RowUpdateType[RowUpdateType["SQLITE_UPDATE"] = 23] = "SQLITE_UPDATE";
|
|
56
|
-
})(RowUpdateType || (RowUpdateType = {}));
|
|
57
|
-
/**
|
|
58
|
-
* A mixin to implement {@link DBAdapter} by delegating to {@link ConnectionPool.readLock} and
|
|
59
|
-
* {@link ConnectionPool.writeLock}.
|
|
49
|
+
* @public
|
|
60
50
|
*/
|
|
61
|
-
export
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
getAll(sql, parameters)
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
getOptional(sql, parameters)
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
get(sql, parameters)
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
execute(query, params)
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
executeRaw(query, params)
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
executeBatch(query, params)
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
};
|
|
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
|
+
}
|
|
88
76
|
}
|
|
89
|
-
class
|
|
77
|
+
class TransactionImplementation extends LockContext {
|
|
90
78
|
inner;
|
|
91
79
|
finalized = false;
|
|
92
80
|
constructor(inner) {
|
|
81
|
+
super();
|
|
93
82
|
this.inner = inner;
|
|
94
83
|
}
|
|
95
84
|
async commit() {
|
|
96
85
|
if (this.finalized) {
|
|
97
|
-
return
|
|
86
|
+
return;
|
|
98
87
|
}
|
|
99
88
|
this.finalized = true;
|
|
100
|
-
|
|
89
|
+
await this.inner.execute('COMMIT');
|
|
101
90
|
}
|
|
102
91
|
async rollback() {
|
|
103
92
|
if (this.finalized) {
|
|
104
|
-
return
|
|
93
|
+
return;
|
|
105
94
|
}
|
|
106
95
|
this.finalized = true;
|
|
107
|
-
|
|
96
|
+
await this.inner.execute('ROLLBACK');
|
|
108
97
|
}
|
|
109
98
|
execute(query, params) {
|
|
110
99
|
return this.inner.execute(query, params);
|
|
@@ -115,8 +104,6 @@ class BaseTransaction {
|
|
|
115
104
|
executeBatch(query, params) {
|
|
116
105
|
return this.inner.executeBatch(query, params);
|
|
117
106
|
}
|
|
118
|
-
}
|
|
119
|
-
class TransactionImplementation extends DBGetUtilsDefaultMixin(BaseTransaction) {
|
|
120
107
|
static async runWith(ctx, fn) {
|
|
121
108
|
let tx = new TransactionImplementation(ctx);
|
|
122
109
|
try {
|
|
@@ -137,10 +124,4 @@ class TransactionImplementation extends DBGetUtilsDefaultMixin(BaseTransaction)
|
|
|
137
124
|
}
|
|
138
125
|
}
|
|
139
126
|
}
|
|
140
|
-
export function isBatchedUpdateNotification(update) {
|
|
141
|
-
return 'tables' in update;
|
|
142
|
-
}
|
|
143
|
-
export function extractTableUpdates(update) {
|
|
144
|
-
return isBatchedUpdateNotification(update) ? update.tables : [update.table];
|
|
145
|
-
}
|
|
146
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":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"DBAdapter.js","sourceRoot":"","sources":["../../src/db/DBAdapter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAgB,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACtE,OAAO,EAEL,kBAAkB,EAClB,sBAAs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;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,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAI,GAAmB;IACvD,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,GAAG,CAAC;IAC7D,IAAI,KAAwB,CAAC;IAE7B,SAAS,WAAW;QAClB,IAAI,KAA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;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,15 +1,10 @@
|
|
|
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
|
*
|
|
11
4
|
* To obtain these values, use {@link SyncProgress}, available through
|
|
12
5
|
* {@link SyncStatus#downloadProgress}.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
13
8
|
*/
|
|
14
9
|
export interface ProgressWithOperations {
|
|
15
10
|
/**
|
|
@@ -22,7 +17,8 @@ export interface ProgressWithOperations {
|
|
|
22
17
|
*/
|
|
23
18
|
downloadedOperations: number;
|
|
24
19
|
/**
|
|
25
|
-
* Relative progress, as {@link downloadedOperations} of
|
|
20
|
+
* Relative progress, as {@link ProgressWithOperations.downloadedOperations} of
|
|
21
|
+
* {@link ProgressWithOperations.totalOperations}.
|
|
26
22
|
*
|
|
27
23
|
* This will be a number between `0.0` and `1.0` (inclusive).
|
|
28
24
|
*
|
|
@@ -51,13 +47,10 @@ export interface ProgressWithOperations {
|
|
|
51
47
|
*
|
|
52
48
|
* Also note that data is downloaded in bulk, which means that individual counters are unlikely
|
|
53
49
|
* to be updated one-by-one.
|
|
50
|
+
*
|
|
51
|
+
* @public
|
|
54
52
|
*/
|
|
55
|
-
export
|
|
56
|
-
protected internal: InternalProgressInformation;
|
|
57
|
-
totalOperations: number;
|
|
58
|
-
downloadedOperations: number;
|
|
59
|
-
downloadedFraction: number;
|
|
60
|
-
constructor(internal: InternalProgressInformation);
|
|
53
|
+
export interface SyncProgress extends ProgressWithOperations {
|
|
61
54
|
/**
|
|
62
55
|
* Returns download progress towards all data up until the specified priority being received.
|
|
63
56
|
*
|
|
@@ -1,61 +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
|
-
export class SyncProgress {
|
|
26
|
-
internal;
|
|
27
|
-
totalOperations;
|
|
28
|
-
downloadedOperations;
|
|
29
|
-
downloadedFraction;
|
|
30
|
-
constructor(internal) {
|
|
31
|
-
this.internal = internal;
|
|
32
|
-
const untilCompletion = this.untilPriority(FULL_SYNC_PRIORITY);
|
|
33
|
-
this.totalOperations = untilCompletion.totalOperations;
|
|
34
|
-
this.downloadedOperations = untilCompletion.downloadedOperations;
|
|
35
|
-
this.downloadedFraction = untilCompletion.downloadedFraction;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Returns download progress towards all data up until the specified priority being received.
|
|
39
|
-
*
|
|
40
|
-
* The returned {@link ProgressWithOperations} tracks the target amount of operations that need
|
|
41
|
-
* to be downloaded in total and how many of them have already been received.
|
|
42
|
-
*/
|
|
43
|
-
untilPriority(priority) {
|
|
44
|
-
let total = 0;
|
|
45
|
-
let downloaded = 0;
|
|
46
|
-
for (const progress of Object.values(this.internal)) {
|
|
47
|
-
// Include higher-priority buckets, which are represented by lower numbers.
|
|
48
|
-
if (progress.priority <= priority) {
|
|
49
|
-
downloaded += progress.since_last;
|
|
50
|
-
total += progress.target_count - progress.at_last;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
let progress = total == 0 ? 0.0 : downloaded / total;
|
|
54
|
-
return {
|
|
55
|
-
totalOperations: total,
|
|
56
|
-
downloadedOperations: downloaded,
|
|
57
|
-
downloadedFraction: progress
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
}
|
|
1
|
+
export {};
|
|
61
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":""}
|