@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/src/db/schema/Table.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BaseColumnType,
|
|
3
|
-
Column,
|
|
4
|
-
ColumnsType,
|
|
5
|
-
ColumnType,
|
|
6
|
-
ExtractColumnValueType,
|
|
7
|
-
MAX_AMOUNT_OF_COLUMNS
|
|
8
|
-
} from './Column.js';
|
|
1
|
+
import { Column, ColumnsType, ExtractColumnValueType } from './Column.js';
|
|
9
2
|
import { Index } from './Index.js';
|
|
10
3
|
import { IndexedColumn } from './IndexedColumn.js';
|
|
11
4
|
import { encodeTableOptions } from './internal.js';
|
|
12
|
-
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* powersync-sqlite-core limits the number of column per table to 1999, due to internal SQLite limits.
|
|
8
|
+
* In earlier versions this was limited to 63.
|
|
9
|
+
*/
|
|
10
|
+
const MAX_AMOUNT_OF_COLUMNS = 1999;
|
|
13
11
|
|
|
14
12
|
/**
|
|
15
13
|
* Options that apply both to JSON-based tables and raw tables.
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
16
|
*/
|
|
17
17
|
export interface TableOrRawTableOptions {
|
|
18
18
|
localOnly?: boolean;
|
|
@@ -30,6 +30,8 @@ interface SharedTableOptions extends TableOrRawTableOptions {
|
|
|
30
30
|
*
|
|
31
31
|
* Including old values may be helpful for some backend connector implementations, which is
|
|
32
32
|
* why it can be enabled on per-table or per-columm basis.
|
|
33
|
+
*
|
|
34
|
+
* @public
|
|
33
35
|
*/
|
|
34
36
|
export interface TrackPreviousOptions {
|
|
35
37
|
/** When defined, a list of column names for which old values should be tracked. */
|
|
@@ -38,7 +40,10 @@ export interface TrackPreviousOptions {
|
|
|
38
40
|
onlyWhenChanged?: boolean;
|
|
39
41
|
}
|
|
40
42
|
|
|
41
|
-
|
|
43
|
+
/**
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
export interface ResolvedTableOptions extends SharedTableOptions {
|
|
42
47
|
/**
|
|
43
48
|
* The synced table name, matching sync rules
|
|
44
49
|
*/
|
|
@@ -47,19 +52,27 @@ export interface TableOptions extends SharedTableOptions {
|
|
|
47
52
|
indexes?: Index[];
|
|
48
53
|
}
|
|
49
54
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
/**
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
export type RowType<T extends Table<any>> =
|
|
59
|
+
T extends Table<infer Columns>
|
|
60
|
+
? { [K in keyof Columns]: ExtractColumnValueType<Columns[K]> } & { id: string }
|
|
61
|
+
: never;
|
|
55
62
|
|
|
56
|
-
|
|
63
|
+
/**
|
|
64
|
+
* @public
|
|
65
|
+
*/
|
|
66
|
+
export type IndexShorthand = Record<string, (string | IndexedColumn)[]>;
|
|
57
67
|
|
|
58
|
-
|
|
68
|
+
/**
|
|
69
|
+
* @public
|
|
70
|
+
*/
|
|
71
|
+
export interface TableOptions extends SharedTableOptions {
|
|
59
72
|
indexes?: IndexShorthand;
|
|
60
73
|
}
|
|
61
74
|
|
|
62
|
-
|
|
75
|
+
const DEFAULT_TABLE_OPTIONS = {
|
|
63
76
|
indexes: [],
|
|
64
77
|
insertOnly: false,
|
|
65
78
|
localOnly: false,
|
|
@@ -68,160 +81,18 @@ export const DEFAULT_TABLE_OPTIONS = {
|
|
|
68
81
|
ignoreEmptyUpdates: false
|
|
69
82
|
};
|
|
70
83
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
export class Table<Columns extends ColumnsType = ColumnsType> {
|
|
74
|
-
protected options: TableOptions;
|
|
75
|
-
|
|
76
|
-
protected _mappedColumns: Columns;
|
|
77
|
-
|
|
78
|
-
static createLocalOnly(options: TableOptions) {
|
|
79
|
-
return new Table({ ...options, localOnly: true, insertOnly: false });
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
static createInsertOnly(options: TableOptions) {
|
|
83
|
-
return new Table({ ...options, localOnly: false, insertOnly: true });
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Create a table.
|
|
88
|
-
* @deprecated This was only only included for TableV2 and is no longer necessary.
|
|
89
|
-
* Prefer to use new Table() directly.
|
|
90
|
-
*
|
|
91
|
-
* TODO remove in the next major release.
|
|
92
|
-
*/
|
|
93
|
-
static createTable(name: string, table: Table) {
|
|
94
|
-
return new Table({
|
|
95
|
-
name,
|
|
96
|
-
columns: table.columns,
|
|
97
|
-
indexes: table.indexes,
|
|
98
|
-
localOnly: table.options.localOnly,
|
|
99
|
-
insertOnly: table.options.insertOnly,
|
|
100
|
-
viewName: table.options.viewName
|
|
101
|
-
});
|
|
102
|
-
}
|
|
84
|
+
const InvalidSQLCharacters = /["'%,.#\s[\]]/;
|
|
103
85
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
* @param {TableV2Options} [v2Options] - Optional configuration options for V2 syntax
|
|
114
|
-
*
|
|
115
|
-
* @example
|
|
116
|
-
* ```javascript
|
|
117
|
-
* // New Constructor
|
|
118
|
-
* const table = new Table(
|
|
119
|
-
* {
|
|
120
|
-
* name: column.text,
|
|
121
|
-
* age: column.integer
|
|
122
|
-
* },
|
|
123
|
-
* { indexes: { nameIndex: ['name'] } }
|
|
124
|
-
* );
|
|
125
|
-
*```
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
* @example
|
|
129
|
-
* ```javascript
|
|
130
|
-
* // Deprecated Constructor
|
|
131
|
-
* const table = new Table({
|
|
132
|
-
* name: 'users',
|
|
133
|
-
* columns: [
|
|
134
|
-
* new Column({ name: 'name', type: ColumnType.TEXT }),
|
|
135
|
-
* new Column({ name: 'age', type: ColumnType.INTEGER })
|
|
136
|
-
* ]
|
|
137
|
-
* });
|
|
138
|
-
*```
|
|
139
|
-
*/
|
|
140
|
-
constructor(columns: Columns, options?: TableV2Options);
|
|
141
|
-
/**
|
|
142
|
-
* @deprecated This constructor will be removed in the next major release.
|
|
143
|
-
* Use the new constructor shown below instead as this does not show types.
|
|
144
|
-
* @example
|
|
145
|
-
* <caption>Use this instead</caption>
|
|
146
|
-
* ```javascript
|
|
147
|
-
* const table = new Table(
|
|
148
|
-
* {
|
|
149
|
-
* name: column.text,
|
|
150
|
-
* age: column.integer
|
|
151
|
-
* },
|
|
152
|
-
* { indexes: { nameIndex: ['name'] } }
|
|
153
|
-
* );
|
|
154
|
-
*```
|
|
155
|
-
*/
|
|
156
|
-
constructor(options: TableOptions);
|
|
157
|
-
constructor(optionsOrColumns: Columns | TableOptions, v2Options?: TableV2Options) {
|
|
158
|
-
if (this.isTableV1(optionsOrColumns)) {
|
|
159
|
-
this.initTableV1(optionsOrColumns);
|
|
160
|
-
} else {
|
|
161
|
-
this.initTableV2(optionsOrColumns, v2Options);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
copyWithName(name: string): Table {
|
|
166
|
-
return new Table({
|
|
167
|
-
...this.options,
|
|
168
|
-
name
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
private isTableV1(arg: TableOptions | Columns): arg is TableOptions {
|
|
173
|
-
return 'columns' in arg && Array.isArray(arg.columns);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
private initTableV1(options: TableOptions) {
|
|
177
|
-
this.options = {
|
|
178
|
-
...options,
|
|
179
|
-
indexes: options.indexes || []
|
|
180
|
-
};
|
|
181
|
-
this.applyDefaultOptions();
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
private initTableV2(columns: Columns, options?: TableV2Options) {
|
|
185
|
-
const convertedColumns = Object.entries(columns).map(
|
|
186
|
-
([name, columnInfo]) => new Column({ name, type: columnInfo.type })
|
|
187
|
-
);
|
|
188
|
-
|
|
189
|
-
const convertedIndexes = Object.entries(options?.indexes ?? {}).map(
|
|
190
|
-
([name, columnNames]) =>
|
|
191
|
-
new Index({
|
|
192
|
-
name,
|
|
193
|
-
columns: columnNames.map(
|
|
194
|
-
(name) =>
|
|
195
|
-
new IndexedColumn({
|
|
196
|
-
name: name.replace(/^-/, ''),
|
|
197
|
-
ascending: !name.startsWith('-')
|
|
198
|
-
})
|
|
199
|
-
)
|
|
200
|
-
})
|
|
201
|
-
);
|
|
202
|
-
|
|
203
|
-
this.options = {
|
|
204
|
-
name: '',
|
|
205
|
-
columns: convertedColumns,
|
|
206
|
-
indexes: convertedIndexes,
|
|
207
|
-
viewName: options?.viewName,
|
|
208
|
-
insertOnly: options?.insertOnly,
|
|
209
|
-
localOnly: options?.localOnly,
|
|
210
|
-
trackPrevious: options?.trackPrevious,
|
|
211
|
-
trackMetadata: options?.trackMetadata,
|
|
212
|
-
ignoreEmptyUpdates: options?.ignoreEmptyUpdates
|
|
213
|
-
};
|
|
86
|
+
/**
|
|
87
|
+
* A resolved table in the PowerSync schema, with all columns, index definitions and options.
|
|
88
|
+
*
|
|
89
|
+
* When constructing tables for your schema, consider using {@link Table} instead.
|
|
90
|
+
*
|
|
91
|
+
* @public
|
|
92
|
+
*/
|
|
93
|
+
export class ResolvedTable {
|
|
94
|
+
constructor(readonly options: ResolvedTableOptions) {
|
|
214
95
|
this.applyDefaultOptions();
|
|
215
|
-
|
|
216
|
-
this._mappedColumns = columns;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
private applyDefaultOptions() {
|
|
220
|
-
this.options.insertOnly ??= DEFAULT_TABLE_OPTIONS.insertOnly;
|
|
221
|
-
this.options.localOnly ??= DEFAULT_TABLE_OPTIONS.localOnly;
|
|
222
|
-
this.options.trackPrevious ??= DEFAULT_TABLE_OPTIONS.trackPrevious;
|
|
223
|
-
this.options.trackMetadata ??= DEFAULT_TABLE_OPTIONS.trackMetadata;
|
|
224
|
-
this.options.ignoreEmptyUpdates ??= DEFAULT_TABLE_OPTIONS.ignoreEmptyUpdates;
|
|
225
96
|
}
|
|
226
97
|
|
|
227
98
|
get name() {
|
|
@@ -240,16 +111,6 @@ export class Table<Columns extends ColumnsType = ColumnsType> {
|
|
|
240
111
|
return this.options.columns;
|
|
241
112
|
}
|
|
242
113
|
|
|
243
|
-
get columnMap(): Columns {
|
|
244
|
-
return (
|
|
245
|
-
this._mappedColumns ??
|
|
246
|
-
this.columns.reduce((hash: Record<string, BaseColumnType<any>>, column) => {
|
|
247
|
-
hash[column.name] = { type: column.type ?? ColumnType.TEXT };
|
|
248
|
-
return hash;
|
|
249
|
-
}, {} as Columns)
|
|
250
|
-
);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
114
|
get indexes() {
|
|
254
115
|
return this.options.indexes ?? [];
|
|
255
116
|
}
|
|
@@ -356,4 +217,93 @@ export class Table<Columns extends ColumnsType = ColumnsType> {
|
|
|
356
217
|
...encodeTableOptions(this)
|
|
357
218
|
};
|
|
358
219
|
}
|
|
220
|
+
|
|
221
|
+
private applyDefaultOptions() {
|
|
222
|
+
this.options.insertOnly ??= DEFAULT_TABLE_OPTIONS.insertOnly;
|
|
223
|
+
this.options.localOnly ??= DEFAULT_TABLE_OPTIONS.localOnly;
|
|
224
|
+
this.options.trackPrevious ??= DEFAULT_TABLE_OPTIONS.trackPrevious;
|
|
225
|
+
this.options.trackMetadata ??= DEFAULT_TABLE_OPTIONS.trackMetadata;
|
|
226
|
+
this.options.ignoreEmptyUpdates ??= DEFAULT_TABLE_OPTIONS.ignoreEmptyUpdates;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* A table with a statically-typed `Columns` record structure.
|
|
232
|
+
*
|
|
233
|
+
* This is the recommended way to declare tables in PowerSync schemas.
|
|
234
|
+
*
|
|
235
|
+
* @public
|
|
236
|
+
*/
|
|
237
|
+
export class Table<Columns extends ColumnsType = ColumnsType> extends ResolvedTable {
|
|
238
|
+
protected _mappedColumns!: Columns;
|
|
239
|
+
|
|
240
|
+
static createLocalOnly<Columns extends ColumnsType = ColumnsType>(columns: Columns, options?: TableOptions) {
|
|
241
|
+
return new Table(columns, { localOnly: true, insertOnly: false, ...options });
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
static createInsertOnly<Columns extends ColumnsType = ColumnsType>(columns: Columns, options?: TableOptions) {
|
|
245
|
+
return new Table(columns, { localOnly: false, insertOnly: true, ...options });
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Creates a new Table instance.
|
|
250
|
+
*
|
|
251
|
+
* @param columns - A Columns object (a record of column names to column types).
|
|
252
|
+
* @param options - Optional configuration options for the table.
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```javascript
|
|
256
|
+
* const table = new Table(
|
|
257
|
+
* {
|
|
258
|
+
* name: column.text,
|
|
259
|
+
* age: column.integer
|
|
260
|
+
* },
|
|
261
|
+
* { indexes: { nameIndex: ['name'] } }
|
|
262
|
+
* );
|
|
263
|
+
*```
|
|
264
|
+
*/
|
|
265
|
+
constructor(columns: Columns, options?: TableOptions) {
|
|
266
|
+
super(Table.optionsFromColumns<Columns>(columns, options));
|
|
267
|
+
this._mappedColumns = columns;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
copyWithName(name: string): ResolvedTable {
|
|
271
|
+
return new ResolvedTable({ ...this.options, name });
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
private static optionsFromColumns<Columns extends ColumnsType>(
|
|
275
|
+
columns: Columns,
|
|
276
|
+
options?: TableOptions
|
|
277
|
+
): ResolvedTableOptions {
|
|
278
|
+
const convertedColumns = Object.entries(columns).map(
|
|
279
|
+
([name, columnInfo]) => new Column({ name, type: columnInfo.type })
|
|
280
|
+
);
|
|
281
|
+
|
|
282
|
+
const convertedIndexes = Object.entries(options?.indexes ?? {}).map(
|
|
283
|
+
([name, columnNames]) =>
|
|
284
|
+
new Index({
|
|
285
|
+
name,
|
|
286
|
+
columns: columnNames.map((nameOrIndexedColumn) =>
|
|
287
|
+
typeof nameOrIndexedColumn === 'string'
|
|
288
|
+
? new IndexedColumn({
|
|
289
|
+
name: nameOrIndexedColumn.replace(/^-/, ''),
|
|
290
|
+
ascending: !nameOrIndexedColumn.startsWith('-')
|
|
291
|
+
})
|
|
292
|
+
: nameOrIndexedColumn
|
|
293
|
+
)
|
|
294
|
+
})
|
|
295
|
+
);
|
|
296
|
+
|
|
297
|
+
return {
|
|
298
|
+
name: '',
|
|
299
|
+
columns: convertedColumns,
|
|
300
|
+
indexes: convertedIndexes,
|
|
301
|
+
viewName: options?.viewName,
|
|
302
|
+
insertOnly: options?.insertOnly,
|
|
303
|
+
localOnly: options?.localOnly,
|
|
304
|
+
trackPrevious: options?.trackPrevious,
|
|
305
|
+
trackMetadata: options?.trackMetadata,
|
|
306
|
+
ignoreEmptyUpdates: options?.ignoreEmptyUpdates
|
|
307
|
+
};
|
|
308
|
+
}
|
|
359
309
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,63 +1,47 @@
|
|
|
1
1
|
export * from './attachments/AttachmentContext.js';
|
|
2
2
|
export * from './attachments/AttachmentErrorHandler.js';
|
|
3
3
|
export * from './attachments/AttachmentQueue.js';
|
|
4
|
-
export * from './attachments/AttachmentService.js';
|
|
5
4
|
export * from './attachments/LocalStorageAdapter.js';
|
|
6
5
|
export * from './attachments/RemoteStorageAdapter.js';
|
|
7
6
|
export * from './attachments/Schema.js';
|
|
8
|
-
export * from './attachments/SyncingService.js';
|
|
9
7
|
export * from './attachments/WatchedAttachmentItem.js';
|
|
10
8
|
|
|
11
|
-
export * from './client/
|
|
12
|
-
export * from './client/AbstractPowerSyncOpenFactory.js';
|
|
9
|
+
export * from './client/CommonPowerSyncDatabase.js';
|
|
13
10
|
export { compilableQueryWatch, CompilableQueryWatchHandler } from './client/compilableQueryWatch.js';
|
|
14
11
|
export * from './client/connection/PowerSyncBackendConnector.js';
|
|
15
12
|
export * from './client/connection/PowerSyncCredentials.js';
|
|
16
|
-
export { MAX_OP_ID } from './client/constants.js';
|
|
17
|
-
export { runOnSchemaChange } from './client/runOnSchemaChange.js';
|
|
18
13
|
export * from './client/SQLOpenFactory.js';
|
|
19
|
-
export * from './client/sync/bucket/BucketStorageAdapter.js';
|
|
20
14
|
export * from './client/sync/bucket/CrudBatch.js';
|
|
21
15
|
export { CrudEntry, OpId, UpdateType } from './client/sync/bucket/CrudEntry.js';
|
|
22
16
|
export * from './client/sync/bucket/CrudTransaction.js';
|
|
23
|
-
export * from './client/sync/bucket/SqliteBucketStorage.js';
|
|
24
|
-
export * from './client/sync/stream/AbstractRemote.js';
|
|
25
|
-
export * from './client/sync/stream/AbstractStreamingSyncImplementation.js';
|
|
26
17
|
export * from './client/sync/stream/JsonValue.js';
|
|
27
18
|
export * from './client/sync/sync-streams.js';
|
|
19
|
+
export { SyncOptions, SyncStreamConnectionMethod, FetchStrategy } from './client/sync/options.js';
|
|
28
20
|
|
|
29
|
-
export * from './client/ConnectionManager.js';
|
|
30
|
-
export * from './db/ConnectionClosedError.js';
|
|
31
21
|
export { ProgressWithOperations, SyncProgress } from './db/crud/SyncProgress.js';
|
|
32
22
|
export * from './db/crud/SyncStatus.js';
|
|
33
23
|
export * from './db/crud/UploadQueueStatus.js';
|
|
34
24
|
export * from './db/DBAdapter.js';
|
|
25
|
+
export * from './db/QueryResult.js';
|
|
35
26
|
export * from './db/schema/Column.js';
|
|
36
27
|
export * from './db/schema/Index.js';
|
|
37
28
|
export * from './db/schema/IndexedColumn.js';
|
|
38
|
-
export {
|
|
29
|
+
export { PendingStatement, PendingStatementParameter, RawTableType } from './db/schema/RawTable.js';
|
|
39
30
|
export * from './db/schema/Schema.js';
|
|
40
31
|
export * from './db/schema/Table.js';
|
|
41
|
-
export * from './db/schema/TableV2.js';
|
|
42
32
|
|
|
43
33
|
export * from './client/Query.js';
|
|
44
|
-
export { MEMORY_TRIGGER_CLAIM_MANAGER } from './client/triggers/MemoryTriggerClaimManager.js';
|
|
45
34
|
export * from './client/triggers/sanitizeSQL.js';
|
|
46
35
|
export * from './client/triggers/TriggerManager.js';
|
|
47
|
-
export { TriggerManagerImpl } from './client/triggers/TriggerManagerImpl.js';
|
|
48
36
|
export * from './client/watched/GetAllQuery.js';
|
|
49
|
-
export * from './client/watched/processors/AbstractQueryProcessor.js';
|
|
50
37
|
export * from './client/watched/processors/comparators.js';
|
|
51
38
|
export * from './client/watched/processors/DifferentialQueryProcessor.js';
|
|
52
39
|
export * from './client/watched/processors/OnChangeQueryProcessor.js';
|
|
53
40
|
export * from './client/watched/WatchedQuery.js';
|
|
54
41
|
|
|
55
|
-
export
|
|
42
|
+
export { type Mutex } from './utils/mutex.js';
|
|
56
43
|
export * from './utils/BaseObserver.js';
|
|
57
|
-
export * from './utils/
|
|
44
|
+
export * from './utils/MetaBaseObserver.js';
|
|
58
45
|
export * from './utils/Logger.js';
|
|
59
|
-
export * from './utils/mutex.js';
|
|
60
|
-
export * from './utils/parseQuery.js';
|
|
61
|
-
export type { SimpleAsyncIterator } from './utils/stream_transform.js';
|
|
62
46
|
|
|
63
47
|
export * from './types/types.js';
|
package/src/types/types.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @public
|
|
3
|
+
*/
|
|
1
4
|
export interface CompilableQuery<T> {
|
|
2
5
|
execute(): Promise<T[]>;
|
|
3
6
|
compile(): CompiledQuery;
|
|
4
7
|
}
|
|
5
8
|
|
|
9
|
+
/**
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
6
12
|
export interface CompiledQuery {
|
|
7
13
|
readonly sql: string;
|
|
8
14
|
readonly parameters: ReadonlyArray<unknown>;
|
|
@@ -1,13 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @public
|
|
3
|
+
*/
|
|
1
4
|
export interface Disposable {
|
|
2
5
|
dispose: () => Promise<void> | void;
|
|
3
6
|
}
|
|
4
7
|
|
|
8
|
+
/**
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
5
11
|
export type BaseListener = Record<string, ((...event: any) => any) | undefined>;
|
|
6
12
|
|
|
13
|
+
/**
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
7
16
|
export interface BaseObserverInterface<T extends BaseListener> {
|
|
8
17
|
registerListener(listener: Partial<T>): () => void;
|
|
9
18
|
}
|
|
10
19
|
|
|
20
|
+
/**
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
11
23
|
export class BaseObserver<T extends BaseListener = BaseListener> implements BaseObserverInterface<T> {
|
|
12
24
|
protected listeners = new Set<Partial<T>>();
|
|
13
25
|
|
package/src/utils/Logger.ts
CHANGED
|
@@ -1,47 +1,102 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @public
|
|
3
|
+
*/
|
|
4
|
+
export const LogLevels = {
|
|
5
|
+
trace: 10,
|
|
6
|
+
debug: 20,
|
|
7
|
+
info: 30,
|
|
8
|
+
warn: 40,
|
|
9
|
+
error: 50
|
|
10
|
+
} as const;
|
|
4
11
|
|
|
5
|
-
|
|
12
|
+
/**
|
|
13
|
+
* A log record passed to a {@link PowerSyncLogger}.
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
export interface LogRecord {
|
|
18
|
+
/**
|
|
19
|
+
* The log level (see {@link LogLevels} for preconfigured values) for the message. Depending on how a receiving logger
|
|
20
|
+
* has been configured, messages below a configured minimum level may be ignored.
|
|
21
|
+
*/
|
|
22
|
+
level: number;
|
|
6
23
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
TIME: TypedLogger.TIME,
|
|
12
|
-
WARN: TypedLogger.WARN,
|
|
13
|
-
ERROR: TypedLogger.ERROR,
|
|
14
|
-
OFF: TypedLogger.OFF
|
|
15
|
-
};
|
|
24
|
+
/**
|
|
25
|
+
* The main message to log.
|
|
26
|
+
*/
|
|
27
|
+
message: string;
|
|
16
28
|
|
|
17
|
-
|
|
18
|
-
|
|
29
|
+
/**
|
|
30
|
+
* When the log message contains an error, the error causing the log.
|
|
31
|
+
*
|
|
32
|
+
* This is not guaranteed to be an `Error` instance. On the web, we might have to serialize objects across message
|
|
33
|
+
* channels and represent them as a string.
|
|
34
|
+
*/
|
|
35
|
+
error?: unknown;
|
|
19
36
|
}
|
|
20
37
|
|
|
21
38
|
/**
|
|
22
|
-
*
|
|
39
|
+
* A logger used by the PowerSync SDK.
|
|
40
|
+
*
|
|
41
|
+
* This is deliberately a very simple interface, and it's not a designed to be a general-purpose logger you would use in
|
|
42
|
+
* your application. Instead, you can provide an implementation of this to PowerSync to make it use your preferred
|
|
43
|
+
* logging libraries.
|
|
23
44
|
*
|
|
24
|
-
*
|
|
25
|
-
* across all loggers created with `createLogger`. Adjusting settings on this
|
|
26
|
-
* base logger affects all loggers derived from it unless explicitly overridden.
|
|
45
|
+
* By default, the SDK uses a {@link createConsoleLogger} instance forwarding messages to `console.log`.
|
|
27
46
|
*
|
|
47
|
+
* @public
|
|
28
48
|
*/
|
|
29
|
-
export
|
|
30
|
-
|
|
49
|
+
export interface PowerSyncLogger {
|
|
50
|
+
log(record: LogRecord): void;
|
|
31
51
|
}
|
|
32
52
|
|
|
33
53
|
/**
|
|
34
|
-
*
|
|
54
|
+
* @public
|
|
55
|
+
*/
|
|
56
|
+
export interface CreateLoggerOptions {
|
|
57
|
+
/**
|
|
58
|
+
* A prefix for messages emitted by {@link createConsoleLogger} to make them more recognizable.
|
|
59
|
+
*
|
|
60
|
+
* Defaults to `'PowerSync'`.
|
|
61
|
+
*/
|
|
62
|
+
prefix: string;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The minimum log level to consider for messages. Defaults to {@link LogLevels.info}.
|
|
66
|
+
*/
|
|
67
|
+
minLevel: number;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* A very simple {@link PowerSyncLogger} implementation forwarding messages to `console.log`.
|
|
35
72
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* from the base logger by default but can override settings independently.
|
|
73
|
+
* @param options - Options to configure a minimum severity of the logger or a prefix to make messages more recognizable.
|
|
74
|
+
* @public
|
|
39
75
|
*/
|
|
40
|
-
export function
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
76
|
+
export function createConsoleLogger(options?: Partial<CreateLoggerOptions>): PowerSyncLogger & CreateLoggerOptions {
|
|
77
|
+
const { prefix = 'PowerSync', minLevel = LogLevels.info } = options ?? {};
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
prefix,
|
|
81
|
+
minLevel,
|
|
82
|
+
log({ level, message, error }) {
|
|
83
|
+
if (level < this.minLevel) return;
|
|
84
|
+
|
|
85
|
+
let emitter = console.log;
|
|
86
|
+
if (level >= LogLevels.error) {
|
|
87
|
+
emitter = console.error;
|
|
88
|
+
} else if (level >= LogLevels.warn) {
|
|
89
|
+
emitter = console.warn;
|
|
90
|
+
} else if (level >= LogLevels.info) {
|
|
91
|
+
emitter = console.info;
|
|
92
|
+
}
|
|
45
93
|
|
|
46
|
-
|
|
94
|
+
const messageWithPrefix = `[${prefix}]: ${message}`;
|
|
95
|
+
if (error) {
|
|
96
|
+
emitter(messageWithPrefix, error);
|
|
97
|
+
} else {
|
|
98
|
+
emitter(messageWithPrefix);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
47
102
|
}
|