@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
|
@@ -1,20 +1,12 @@
|
|
|
1
|
-
import type { BucketProgress } from '../../client/sync/stream/core-instruction.js';
|
|
2
1
|
import type { SyncStatus } from './SyncStatus.js';
|
|
3
2
|
|
|
4
|
-
// (bucket, progress) pairs
|
|
5
|
-
/** @internal */
|
|
6
|
-
export type InternalProgressInformation = Record<string, BucketProgress>;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @internal The priority used by the core extension to indicate that a full sync was completed.
|
|
10
|
-
*/
|
|
11
|
-
export const FULL_SYNC_PRIORITY = 2147483647;
|
|
12
|
-
|
|
13
3
|
/**
|
|
14
4
|
* Information about a progressing download made by the PowerSync SDK.
|
|
15
5
|
*
|
|
16
6
|
* To obtain these values, use {@link SyncProgress}, available through
|
|
17
7
|
* {@link SyncStatus#downloadProgress}.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
18
10
|
*/
|
|
19
11
|
export interface ProgressWithOperations {
|
|
20
12
|
/**
|
|
@@ -28,7 +20,8 @@ export interface ProgressWithOperations {
|
|
|
28
20
|
downloadedOperations: number;
|
|
29
21
|
|
|
30
22
|
/**
|
|
31
|
-
* Relative progress, as {@link downloadedOperations} of
|
|
23
|
+
* Relative progress, as {@link ProgressWithOperations.downloadedOperations} of
|
|
24
|
+
* {@link ProgressWithOperations.totalOperations}.
|
|
32
25
|
*
|
|
33
26
|
* This will be a number between `0.0` and `1.0` (inclusive).
|
|
34
27
|
*
|
|
@@ -58,43 +51,15 @@ export interface ProgressWithOperations {
|
|
|
58
51
|
*
|
|
59
52
|
* Also note that data is downloaded in bulk, which means that individual counters are unlikely
|
|
60
53
|
* to be updated one-by-one.
|
|
54
|
+
*
|
|
55
|
+
* @public
|
|
61
56
|
*/
|
|
62
|
-
export
|
|
63
|
-
totalOperations: number;
|
|
64
|
-
downloadedOperations: number;
|
|
65
|
-
downloadedFraction: number;
|
|
66
|
-
|
|
67
|
-
constructor(protected internal: InternalProgressInformation) {
|
|
68
|
-
const untilCompletion = this.untilPriority(FULL_SYNC_PRIORITY);
|
|
69
|
-
|
|
70
|
-
this.totalOperations = untilCompletion.totalOperations;
|
|
71
|
-
this.downloadedOperations = untilCompletion.downloadedOperations;
|
|
72
|
-
this.downloadedFraction = untilCompletion.downloadedFraction;
|
|
73
|
-
}
|
|
74
|
-
|
|
57
|
+
export interface SyncProgress extends ProgressWithOperations {
|
|
75
58
|
/**
|
|
76
59
|
* Returns download progress towards all data up until the specified priority being received.
|
|
77
60
|
*
|
|
78
61
|
* The returned {@link ProgressWithOperations} tracks the target amount of operations that need
|
|
79
62
|
* to be downloaded in total and how many of them have already been received.
|
|
80
63
|
*/
|
|
81
|
-
untilPriority(priority: number): ProgressWithOperations
|
|
82
|
-
let total = 0;
|
|
83
|
-
let downloaded = 0;
|
|
84
|
-
|
|
85
|
-
for (const progress of Object.values(this.internal)) {
|
|
86
|
-
// Include higher-priority buckets, which are represented by lower numbers.
|
|
87
|
-
if (progress.priority <= priority) {
|
|
88
|
-
downloaded += progress.since_last;
|
|
89
|
-
total += progress.target_count - progress.at_last;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
let progress = total == 0 ? 0.0 : downloaded / total;
|
|
94
|
-
return {
|
|
95
|
-
totalOperations: total,
|
|
96
|
-
downloadedOperations: downloaded,
|
|
97
|
-
downloadedFraction: progress
|
|
98
|
-
};
|
|
99
|
-
}
|
|
64
|
+
untilPriority(priority: number): ProgressWithOperations;
|
|
100
65
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { SyncClientImplementation } from '../../client/sync/stream/AbstractStreamingSyncImplementation.js';
|
|
2
|
-
import { CoreStreamSubscription } from '../../client/sync/stream/core-instruction.js';
|
|
3
1
|
import { SyncStreamDescription, SyncSubscriptionDescription } from '../../client/sync/sync-streams.js';
|
|
4
|
-
import {
|
|
2
|
+
import { ProgressWithOperations, SyncProgress } from './SyncProgress.js';
|
|
5
3
|
|
|
6
|
-
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
* @deprecated All fields are available on {@link SyncStatus} directly.
|
|
7
|
+
*/
|
|
8
|
+
export interface SyncDataFlowStatus {
|
|
7
9
|
downloading: boolean;
|
|
8
10
|
uploading: boolean;
|
|
9
11
|
/**
|
|
@@ -17,105 +19,79 @@ export type SyncDataFlowStatus = Partial<{
|
|
|
17
19
|
* Cleared on the next successful upload.
|
|
18
20
|
*/
|
|
19
21
|
uploadError?: Error;
|
|
20
|
-
|
|
21
|
-
* Internal information about how far we are downloading operations in buckets.
|
|
22
|
-
*
|
|
23
|
-
* Please use the {@link SyncStatus#downloadProgress} property to track sync progress.
|
|
24
|
-
*/
|
|
25
|
-
downloadProgress: InternalProgressInformation | null;
|
|
26
|
-
internalStreamSubscriptions: CoreStreamSubscription[] | null;
|
|
27
|
-
}>;
|
|
22
|
+
}
|
|
28
23
|
|
|
24
|
+
/**
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
29
27
|
export interface SyncPriorityStatus {
|
|
30
28
|
priority: number;
|
|
31
29
|
lastSyncedAt?: Date;
|
|
32
30
|
hasSynced?: boolean;
|
|
33
31
|
}
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
lastSyncedAt?: Date;
|
|
40
|
-
hasSynced?: boolean;
|
|
41
|
-
priorityStatusEntries?: SyncPriorityStatus[];
|
|
42
|
-
clientImplementation?: SyncClientImplementation;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export class SyncStatus {
|
|
46
|
-
constructor(protected options: SyncStatusOptions) {}
|
|
47
|
-
|
|
33
|
+
/**
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
export interface SyncStatus {
|
|
48
37
|
/**
|
|
49
|
-
*
|
|
50
|
-
* implementation).
|
|
38
|
+
* Indicates if the client is currently connected to the PowerSync service.
|
|
51
39
|
*
|
|
52
|
-
*
|
|
40
|
+
* @returns True if connected, false otherwise. Defaults to false if not specified.
|
|
53
41
|
*/
|
|
54
|
-
get
|
|
55
|
-
return this.options.clientImplementation;
|
|
56
|
-
}
|
|
42
|
+
get connected(): boolean;
|
|
57
43
|
|
|
58
44
|
/**
|
|
59
|
-
* Indicates if the client is
|
|
45
|
+
* Indicates if the client is in the process of establishing a connection to the PowerSync service.
|
|
60
46
|
*
|
|
61
|
-
* @returns
|
|
47
|
+
* @returns True if connecting, false otherwise. Defaults to false if not specified.
|
|
62
48
|
*/
|
|
63
|
-
get
|
|
64
|
-
return this.options.connected ?? false;
|
|
65
|
-
}
|
|
49
|
+
get connecting(): boolean;
|
|
66
50
|
|
|
67
51
|
/**
|
|
68
|
-
*
|
|
52
|
+
* Whether the PowerSync SDK is currently downloading data from the connected PowerSync service.
|
|
53
|
+
*/
|
|
54
|
+
get downloading(): boolean;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Whether the PowerSync SDK is currently uploading local mutations through the configured
|
|
58
|
+
* {@link PowerSyncBackendConnector}.
|
|
59
|
+
*/
|
|
60
|
+
get uploading(): boolean;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* An error that occurred during downloads (including connection establishment errors).
|
|
69
64
|
*
|
|
70
|
-
*
|
|
65
|
+
* A download error will be reported on all sync status entries until the next successful sync.
|
|
66
|
+
*/
|
|
67
|
+
get downloadError(): Error | undefined;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Error during uploading.
|
|
71
|
+
* Cleared on the next successful upload.
|
|
72
|
+
*/
|
|
73
|
+
get uploadError(): Error | undefined;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @deprecated All fields on {@link SyncDataFlowStatus} are available on {@link SyncStatus} directly.
|
|
71
77
|
*/
|
|
72
|
-
get
|
|
73
|
-
return this.options.connecting ?? false;
|
|
74
|
-
}
|
|
78
|
+
get dataFlowStatus(): SyncDataFlowStatus;
|
|
75
79
|
|
|
76
80
|
/**
|
|
77
81
|
* Time that a last sync has fully completed, if any.
|
|
78
82
|
* This timestamp is reset to null after a restart of the PowerSync service.
|
|
79
83
|
*
|
|
80
|
-
* @returns
|
|
84
|
+
* @returns The timestamp of the last successful sync, or undefined if no sync has completed.
|
|
81
85
|
*/
|
|
82
|
-
get lastSyncedAt()
|
|
83
|
-
return this.options.lastSyncedAt;
|
|
84
|
-
}
|
|
86
|
+
get lastSyncedAt(): Date | undefined;
|
|
85
87
|
|
|
86
88
|
/**
|
|
87
89
|
* Indicates whether there has been at least one full sync completed since initialization.
|
|
88
90
|
*
|
|
89
|
-
* @returns
|
|
91
|
+
* @returns True if at least one sync has completed, false if no sync has completed,
|
|
90
92
|
* or undefined when the state is still being loaded from the database.
|
|
91
93
|
*/
|
|
92
|
-
get hasSynced()
|
|
93
|
-
return this.options.hasSynced;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Provides the current data flow status regarding uploads and downloads.
|
|
98
|
-
*
|
|
99
|
-
* @returns {SyncDataFlowStatus} An object containing:
|
|
100
|
-
* - downloading: True if actively downloading changes (only when connected is also true)
|
|
101
|
-
* - uploading: True if actively uploading changes
|
|
102
|
-
* Defaults to {downloading: false, uploading: false} if not specified.
|
|
103
|
-
*/
|
|
104
|
-
get dataFlowStatus() {
|
|
105
|
-
return (
|
|
106
|
-
this.options.dataFlow ?? {
|
|
107
|
-
/**
|
|
108
|
-
* true if actively downloading changes.
|
|
109
|
-
* This is only true when {@link connected} is also true.
|
|
110
|
-
*/
|
|
111
|
-
downloading: false,
|
|
112
|
-
/**
|
|
113
|
-
* true if uploading changes.
|
|
114
|
-
*/
|
|
115
|
-
uploading: false
|
|
116
|
-
}
|
|
117
|
-
);
|
|
118
|
-
}
|
|
94
|
+
get hasSynced(): boolean | undefined;
|
|
119
95
|
|
|
120
96
|
/**
|
|
121
97
|
* All sync streams currently being tracked in teh database.
|
|
@@ -123,46 +99,28 @@ export class SyncStatus {
|
|
|
123
99
|
* This returns null when the database is currently being opened and we don't have reliable information about all
|
|
124
100
|
* included streams yet.
|
|
125
101
|
*/
|
|
126
|
-
get syncStreams(): SyncStreamStatus[] | undefined
|
|
127
|
-
return this.options.dataFlow?.internalStreamSubscriptions?.map((core) => new SyncStreamStatusView(this, core));
|
|
128
|
-
}
|
|
102
|
+
get syncStreams(): SyncStreamStatus[] | undefined;
|
|
129
103
|
|
|
130
104
|
/**
|
|
131
|
-
* If the `stream` appears in {@link syncStreams}, returns the current status for that stream.
|
|
105
|
+
* If the `stream` appears in {@link SyncStatus.syncStreams}, returns the current status for that stream.
|
|
132
106
|
*/
|
|
133
|
-
forStream(stream: SyncStreamDescription): SyncStreamStatus | undefined
|
|
134
|
-
const asJson = JSON.stringify(stream.parameters);
|
|
135
|
-
const raw = this.options.dataFlow?.internalStreamSubscriptions?.find(
|
|
136
|
-
(r) => r.name == stream.name && asJson == JSON.stringify(r.parameters)
|
|
137
|
-
);
|
|
138
|
-
|
|
139
|
-
return raw && new SyncStreamStatusView(this, raw);
|
|
140
|
-
}
|
|
107
|
+
forStream(stream: SyncStreamDescription): SyncStreamStatus | undefined;
|
|
141
108
|
|
|
142
109
|
/**
|
|
143
110
|
* Provides sync status information for all bucket priorities, sorted by priority (highest first).
|
|
144
111
|
*
|
|
145
|
-
* @returns
|
|
112
|
+
* @returns An array of status entries for different sync priority levels,
|
|
146
113
|
* sorted with highest priorities (lower numbers) first.
|
|
147
114
|
*/
|
|
148
|
-
get priorityStatusEntries()
|
|
149
|
-
return (this.options.priorityStatusEntries ?? []).slice().sort(SyncStatus.comparePriorities);
|
|
150
|
-
}
|
|
115
|
+
get priorityStatusEntries(): SyncPriorityStatus[] | undefined;
|
|
151
116
|
|
|
152
117
|
/**
|
|
153
118
|
* A realtime progress report on how many operations have been downloaded and
|
|
154
119
|
* how many are necessary in total to complete the next sync iteration.
|
|
155
120
|
*
|
|
156
|
-
* This field is only set when {@link
|
|
121
|
+
* This field is only set when {@link SyncStatus#downloading} is also true.
|
|
157
122
|
*/
|
|
158
|
-
get downloadProgress(): SyncProgress | null
|
|
159
|
-
const internalProgress = this.options.dataFlow?.downloadProgress;
|
|
160
|
-
if (internalProgress == null) {
|
|
161
|
-
return null;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
return new SyncProgress(internalProgress);
|
|
165
|
-
}
|
|
123
|
+
get downloadProgress(): SyncProgress | null;
|
|
166
124
|
|
|
167
125
|
/**
|
|
168
126
|
* Reports the sync status (a pair of {@link SyncStatus#hasSynced} and {@link SyncStatus#lastSyncedAt} fields)
|
|
@@ -180,144 +138,36 @@ export class SyncStatus {
|
|
|
180
138
|
* For example, if PowerSync just finished synchronizing buckets in priority level 3, calling this method
|
|
181
139
|
* with a priority of 1 may return information for priority level 3.
|
|
182
140
|
*
|
|
183
|
-
* @param
|
|
184
|
-
* @returns
|
|
141
|
+
* @param priority - The bucket priority for which the status should be reported
|
|
142
|
+
* @returns Status information for the requested priority level or the next higher level with available status
|
|
185
143
|
*/
|
|
186
|
-
statusForPriority(priority: number): SyncPriorityStatus
|
|
187
|
-
// priorityStatusEntries are sorted by ascending priorities (so higher numbers to lower numbers).
|
|
188
|
-
for (const known of this.priorityStatusEntries) {
|
|
189
|
-
// We look for the first entry that doesn't have a higher priority.
|
|
190
|
-
if (known.priority >= priority) {
|
|
191
|
-
return known;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// If we have a complete sync, that necessarily includes all priorities.
|
|
196
|
-
return {
|
|
197
|
-
priority,
|
|
198
|
-
lastSyncedAt: this.lastSyncedAt,
|
|
199
|
-
hasSynced: this.hasSynced
|
|
200
|
-
};
|
|
201
|
-
}
|
|
144
|
+
statusForPriority(priority: number): SyncPriorityStatus | undefined;
|
|
202
145
|
|
|
203
146
|
/**
|
|
204
147
|
* Compares this SyncStatus instance with another to determine if they are equal.
|
|
205
148
|
* Equality is determined by comparing the serialized JSON representation of both instances.
|
|
206
149
|
*
|
|
207
|
-
* @param
|
|
208
|
-
* @returns
|
|
150
|
+
* @param status - The SyncStatus instance to compare against
|
|
151
|
+
* @returns True if the instances are considered equal, false otherwise
|
|
209
152
|
*/
|
|
210
|
-
isEqual(status: SyncStatus)
|
|
211
|
-
/**
|
|
212
|
-
* By default Error object are serialized to an empty object.
|
|
213
|
-
* This replaces Errors with more useful information before serialization.
|
|
214
|
-
*/
|
|
215
|
-
const replacer = (_: string, value: any) => {
|
|
216
|
-
if (value instanceof Error) {
|
|
217
|
-
return {
|
|
218
|
-
name: value.name,
|
|
219
|
-
message: value.message,
|
|
220
|
-
stack: value.stack
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
return value;
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
return JSON.stringify(this.options, replacer) == JSON.stringify(status.options, replacer);
|
|
227
|
-
}
|
|
153
|
+
isEqual(status: SyncStatus): boolean;
|
|
228
154
|
|
|
229
155
|
/**
|
|
230
156
|
* Creates a human-readable string representation of the current sync status.
|
|
231
157
|
* Includes information about connection state, sync completion, and data flow.
|
|
232
158
|
*
|
|
233
|
-
* @returns
|
|
234
|
-
*/
|
|
235
|
-
getMessage() {
|
|
236
|
-
const dataFlow = this.dataFlowStatus;
|
|
237
|
-
return `SyncStatus<connected: ${this.connected} connecting: ${this.connecting} lastSyncedAt: ${this.lastSyncedAt} hasSynced: ${this.hasSynced}. Downloading: ${dataFlow.downloading}. Uploading: ${dataFlow.uploading}. UploadError: ${dataFlow.uploadError}, DownloadError?: ${dataFlow.downloadError}>`;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Serializes the SyncStatus instance to a plain object.
|
|
242
|
-
*
|
|
243
|
-
* @returns {SyncStatusOptions} A plain object representation of the sync status
|
|
159
|
+
* @returns A string representation of the sync status
|
|
244
160
|
*/
|
|
245
|
-
|
|
246
|
-
return {
|
|
247
|
-
connected: this.connected,
|
|
248
|
-
connecting: this.connecting,
|
|
249
|
-
dataFlow: {
|
|
250
|
-
...this.dataFlowStatus,
|
|
251
|
-
uploadError: this.serializeError(this.dataFlowStatus.uploadError),
|
|
252
|
-
downloadError: this.serializeError(this.dataFlowStatus.downloadError)
|
|
253
|
-
},
|
|
254
|
-
lastSyncedAt: this.lastSyncedAt,
|
|
255
|
-
hasSynced: this.hasSynced,
|
|
256
|
-
priorityStatusEntries: this.priorityStatusEntries
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* Not all errors are serializable over a MessagePort. E.g. some `DomExceptions` fail to be passed across workers.
|
|
262
|
-
* This explicitly serializes errors in the SyncStatus.
|
|
263
|
-
*/
|
|
264
|
-
protected serializeError(error?: Error) {
|
|
265
|
-
if (typeof error == 'undefined') {
|
|
266
|
-
return undefined;
|
|
267
|
-
}
|
|
268
|
-
return {
|
|
269
|
-
name: error.name,
|
|
270
|
-
message: error.message,
|
|
271
|
-
stack: error.stack
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
private static comparePriorities(a: SyncPriorityStatus, b: SyncPriorityStatus) {
|
|
276
|
-
return b.priority - a.priority; // Reverse because higher priorities have lower numbers
|
|
277
|
-
}
|
|
161
|
+
getMessage(): string;
|
|
278
162
|
}
|
|
279
163
|
|
|
280
164
|
/**
|
|
281
165
|
* Information about a sync stream subscription.
|
|
166
|
+
*
|
|
167
|
+
* @public
|
|
282
168
|
*/
|
|
283
169
|
export interface SyncStreamStatus {
|
|
284
170
|
progress: ProgressWithOperations | null;
|
|
285
171
|
subscription: SyncSubscriptionDescription;
|
|
286
172
|
priority: number | null;
|
|
287
173
|
}
|
|
288
|
-
|
|
289
|
-
class SyncStreamStatusView implements SyncStreamStatus {
|
|
290
|
-
subscription: SyncSubscriptionDescription;
|
|
291
|
-
|
|
292
|
-
constructor(
|
|
293
|
-
private status: SyncStatus,
|
|
294
|
-
private core: CoreStreamSubscription
|
|
295
|
-
) {
|
|
296
|
-
this.subscription = {
|
|
297
|
-
name: core.name,
|
|
298
|
-
parameters: core.parameters,
|
|
299
|
-
active: core.active,
|
|
300
|
-
isDefault: core.is_default,
|
|
301
|
-
hasExplicitSubscription: core.has_explicit_subscription,
|
|
302
|
-
expiresAt: core.expires_at != null ? new Date(core.expires_at * 1000) : null,
|
|
303
|
-
hasSynced: core.last_synced_at != null,
|
|
304
|
-
lastSyncedAt: core.last_synced_at != null ? new Date(core.last_synced_at * 1000) : null
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
get progress() {
|
|
309
|
-
if (this.status.dataFlowStatus.downloadProgress == null) {
|
|
310
|
-
// Don't make download progress public if we're not currently downloading.
|
|
311
|
-
return null;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
const { total, downloaded } = this.core.progress;
|
|
315
|
-
const progress = total == 0 ? 0.0 : downloaded / total;
|
|
316
|
-
|
|
317
|
-
return { totalOperations: total, downloadedOperations: downloaded, downloadedFraction: progress };
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
get priority() {
|
|
321
|
-
return this.core.priority;
|
|
322
|
-
}
|
|
323
|
-
}
|
package/src/db/schema/Column.ts
CHANGED
|
@@ -1,21 +1,36 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @see https://www.sqlite.org/lang_expr.html#castexpr
|
|
3
|
+
* @public
|
|
4
|
+
*/
|
|
2
5
|
export enum ColumnType {
|
|
3
6
|
TEXT = 'TEXT',
|
|
4
7
|
INTEGER = 'INTEGER',
|
|
5
8
|
REAL = 'REAL'
|
|
6
9
|
}
|
|
7
10
|
|
|
11
|
+
/**
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
8
14
|
export interface ColumnOptions {
|
|
9
15
|
name: string;
|
|
10
16
|
type?: ColumnType;
|
|
11
17
|
}
|
|
12
18
|
|
|
19
|
+
/**
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
13
22
|
export type BaseColumnType<T extends number | string | null> = {
|
|
14
23
|
type: ColumnType;
|
|
15
24
|
};
|
|
16
25
|
|
|
26
|
+
/**
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
17
29
|
export type ColumnsType = Record<string, BaseColumnType<any>>;
|
|
18
30
|
|
|
31
|
+
/**
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
19
34
|
export type ExtractColumnValueType<T extends BaseColumnType<any>> = T extends BaseColumnType<infer R> ? R : unknown;
|
|
20
35
|
|
|
21
36
|
const text: BaseColumnType<string | null> = {
|
|
@@ -30,16 +45,18 @@ const real: BaseColumnType<number | null> = {
|
|
|
30
45
|
type: ColumnType.REAL
|
|
31
46
|
};
|
|
32
47
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
48
|
+
/**
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
37
51
|
export const column = {
|
|
38
52
|
text,
|
|
39
53
|
integer,
|
|
40
54
|
real
|
|
41
55
|
};
|
|
42
56
|
|
|
57
|
+
/**
|
|
58
|
+
* @public
|
|
59
|
+
*/
|
|
43
60
|
export class Column {
|
|
44
61
|
constructor(protected options: ColumnOptions) {}
|
|
45
62
|
|
package/src/db/schema/Index.ts
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import { IndexedColumn } from './IndexedColumn.js';
|
|
2
|
-
import {
|
|
2
|
+
import { ResolvedTable } from './Table.js';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
4
7
|
export interface IndexOptions {
|
|
5
8
|
name: string;
|
|
6
9
|
columns?: IndexedColumn[];
|
|
7
10
|
}
|
|
8
11
|
|
|
9
|
-
|
|
12
|
+
const DEFAULT_INDEX_OPTIONS: Partial<IndexOptions> = {
|
|
10
13
|
columns: []
|
|
11
14
|
};
|
|
12
15
|
|
|
16
|
+
/**
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
13
19
|
export class Index {
|
|
14
20
|
static createAscending(options: IndexOptions, columnNames: string[]) {
|
|
15
21
|
return new Index({
|
|
@@ -30,7 +36,7 @@ export class Index {
|
|
|
30
36
|
return this.options.columns ?? [];
|
|
31
37
|
}
|
|
32
38
|
|
|
33
|
-
toJSON(table:
|
|
39
|
+
toJSON(table: ResolvedTable) {
|
|
34
40
|
return {
|
|
35
41
|
name: this.name,
|
|
36
42
|
columns: this.columns.map((c) => c.toJSON(table))
|
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import { ColumnType } from './Column.js';
|
|
2
|
-
import {
|
|
2
|
+
import { ResolvedTable } from './Table.js';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
4
7
|
export interface IndexColumnOptions {
|
|
5
8
|
name: string;
|
|
6
9
|
ascending?: boolean;
|
|
7
10
|
}
|
|
8
11
|
|
|
9
|
-
|
|
12
|
+
const DEFAULT_INDEX_COLUMN_OPTIONS: Partial<IndexColumnOptions> = {
|
|
10
13
|
ascending: true
|
|
11
14
|
};
|
|
12
15
|
|
|
16
|
+
/**
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
13
19
|
export class IndexedColumn {
|
|
14
20
|
protected options: IndexColumnOptions;
|
|
15
21
|
|
|
@@ -32,7 +38,7 @@ export class IndexedColumn {
|
|
|
32
38
|
return this.options.ascending;
|
|
33
39
|
}
|
|
34
40
|
|
|
35
|
-
toJSON(table:
|
|
41
|
+
toJSON(table: ResolvedTable) {
|
|
36
42
|
return {
|
|
37
43
|
name: this.name,
|
|
38
44
|
ascending: this.ascending,
|
|
@@ -7,8 +7,10 @@ import { TableOrRawTableOptions } from './Table.js';
|
|
|
7
7
|
* using client-side table and column constraints.
|
|
8
8
|
*
|
|
9
9
|
* To collect local writes to raw tables with PowerSync, custom triggers are required. See
|
|
10
|
-
* {@link https://docs.powersync.com/usage/use-case-examples/raw-tables
|
|
10
|
+
* {@link https://docs.powersync.com/usage/use-case-examples/raw-tables} for details and an example on
|
|
11
11
|
* using raw tables.
|
|
12
|
+
*
|
|
13
|
+
* @public
|
|
12
14
|
*/
|
|
13
15
|
export type RawTableType = RawTableTypeWithStatements | InferredRawTableType;
|
|
14
16
|
|
|
@@ -70,11 +72,15 @@ interface InferredRawTableType extends Partial<RawTableTypeWithStatements> {
|
|
|
70
72
|
* `{Column: 'name'}`.
|
|
71
73
|
* The `"Rest"` parameter gets resolved to a JSON object covering all values from the synced row that haven't been
|
|
72
74
|
* covered by a `Column` parameter.
|
|
75
|
+
*
|
|
76
|
+
* @public
|
|
73
77
|
*/
|
|
74
78
|
export type PendingStatementParameter = 'Id' | { Column: string } | 'Rest';
|
|
75
79
|
|
|
76
80
|
/**
|
|
77
81
|
* A statement that the PowerSync client should use to insert or delete data into a table managed by the user.
|
|
82
|
+
*
|
|
83
|
+
* @public
|
|
78
84
|
*/
|
|
79
85
|
export type PendingStatement = {
|
|
80
86
|
sql: string;
|
package/src/db/schema/Schema.ts
CHANGED
|
@@ -1,26 +1,31 @@
|
|
|
1
1
|
import { encodeTableOptions } from './internal.js';
|
|
2
2
|
import { RawTable, RawTableType } from './RawTable.js';
|
|
3
|
-
import { RowType, Table } from './Table.js';
|
|
3
|
+
import { ResolvedTable, RowType, Table } from './Table.js';
|
|
4
4
|
|
|
5
5
|
type SchemaType = Record<string, Table<any>>;
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
7
10
|
export type SchemaTableType<S extends SchemaType> = {
|
|
8
11
|
[K in keyof S]: RowType<S[K]>;
|
|
9
12
|
};
|
|
10
13
|
|
|
11
14
|
/**
|
|
12
15
|
* A schema is a collection of tables. It is used to define the structure of a database.
|
|
16
|
+
*
|
|
17
|
+
* @public
|
|
13
18
|
*/
|
|
14
19
|
export class Schema<S extends SchemaType = SchemaType> {
|
|
15
20
|
/*
|
|
16
21
|
Only available when constructing with mapped typed definition columns
|
|
17
22
|
*/
|
|
18
|
-
readonly types
|
|
19
|
-
readonly props
|
|
20
|
-
readonly tables:
|
|
23
|
+
readonly types!: SchemaTableType<S>;
|
|
24
|
+
readonly props!: S;
|
|
25
|
+
readonly tables: ResolvedTable[];
|
|
21
26
|
readonly rawTables: RawTable[];
|
|
22
27
|
|
|
23
|
-
constructor(tables:
|
|
28
|
+
constructor(tables: ResolvedTable[] | S) {
|
|
24
29
|
if (Array.isArray(tables)) {
|
|
25
30
|
/*
|
|
26
31
|
We need to validate that the tables have a name here because a user could pass in an array
|
|
@@ -52,7 +57,7 @@ export class Schema<S extends SchemaType = SchemaType> {
|
|
|
52
57
|
* Since raw tables are not backed by JSON, running complex queries on them may be more efficient. Further, they allow
|
|
53
58
|
* using client-side table and column constraints.
|
|
54
59
|
*
|
|
55
|
-
* @param tables An object of (table name, raw table definition) entries.
|
|
60
|
+
* @param tables - An object of (table name, raw table definition) entries.
|
|
56
61
|
*/
|
|
57
62
|
withRawTables(tables: Record<string, RawTableType>) {
|
|
58
63
|
for (const [name, rawTableDefinition] of Object.entries(tables)) {
|
|
@@ -66,7 +71,7 @@ export class Schema<S extends SchemaType = SchemaType> {
|
|
|
66
71
|
}
|
|
67
72
|
}
|
|
68
73
|
|
|
69
|
-
toJSON() {
|
|
74
|
+
toJSON(): unknown {
|
|
70
75
|
return {
|
|
71
76
|
tables: this.tables.map((t) => t.toJSON()),
|
|
72
77
|
raw_tables: this.rawTables.map(Schema.rawTableToJson)
|