@powersync/service-core 0.12.2 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/dist/auth/KeySpec.d.ts +1 -0
- package/dist/auth/KeySpec.js +5 -2
- package/dist/auth/KeySpec.js.map +1 -1
- package/dist/auth/RemoteJWKSCollector.js +1 -1
- package/dist/auth/RemoteJWKSCollector.js.map +1 -1
- package/dist/entry/commands/compact-action.js +14 -14
- package/dist/entry/commands/compact-action.js.map +1 -1
- package/dist/entry/commands/migrate-action.js +15 -4
- package/dist/entry/commands/migrate-action.js.map +1 -1
- package/dist/index.d.ts +1 -3
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/dist/migrations/PowerSyncMigrationManager.d.ts +17 -0
- package/dist/migrations/PowerSyncMigrationManager.js +21 -0
- package/dist/migrations/PowerSyncMigrationManager.js.map +1 -0
- package/dist/migrations/ensure-automatic-migrations.d.ts +4 -0
- package/dist/migrations/ensure-automatic-migrations.js +14 -0
- package/dist/migrations/ensure-automatic-migrations.js.map +1 -0
- package/dist/migrations/migrations-index.d.ts +2 -3
- package/dist/migrations/migrations-index.js +2 -3
- package/dist/migrations/migrations-index.js.map +1 -1
- package/dist/routes/configure-fastify.d.ts +12 -12
- package/dist/routes/endpoints/admin.d.ts +24 -24
- package/dist/routes/endpoints/probes.d.ts +1 -1
- package/dist/routes/endpoints/probes.js +5 -5
- package/dist/routes/endpoints/probes.js.map +1 -1
- package/dist/storage/BucketStorage.d.ts +49 -1
- package/dist/storage/BucketStorage.js +26 -0
- package/dist/storage/BucketStorage.js.map +1 -1
- package/dist/storage/SourceTable.d.ts +4 -0
- package/dist/storage/SourceTable.js +4 -0
- package/dist/storage/SourceTable.js.map +1 -1
- package/dist/storage/bson.d.ts +24 -0
- package/dist/storage/bson.js +73 -0
- package/dist/storage/bson.js.map +1 -0
- package/dist/storage/storage-index.d.ts +3 -14
- package/dist/storage/storage-index.js +3 -14
- package/dist/storage/storage-index.js.map +1 -1
- package/dist/sync/sync.js +3 -1
- package/dist/sync/sync.js.map +1 -1
- package/dist/system/ServiceContext.d.ts +3 -0
- package/dist/system/ServiceContext.js +11 -3
- package/dist/system/ServiceContext.js.map +1 -1
- package/dist/util/config/types.d.ts +2 -2
- package/dist/util/utils.d.ts +13 -1
- package/dist/util/utils.js +20 -1
- package/dist/util/utils.js.map +1 -1
- package/package.json +7 -8
- package/src/auth/KeySpec.ts +5 -3
- package/src/auth/RemoteJWKSCollector.ts +1 -1
- package/src/entry/commands/compact-action.ts +19 -14
- package/src/entry/commands/migrate-action.ts +17 -4
- package/src/index.ts +1 -4
- package/src/migrations/PowerSyncMigrationManager.ts +42 -0
- package/src/migrations/ensure-automatic-migrations.ts +15 -0
- package/src/migrations/migrations-index.ts +2 -3
- package/src/routes/endpoints/probes.ts +6 -6
- package/src/storage/BucketStorage.ts +53 -1
- package/src/storage/SourceTable.ts +4 -0
- package/src/storage/bson.ts +78 -0
- package/src/storage/storage-index.ts +3 -15
- package/src/sync/sync.ts +3 -1
- package/src/system/ServiceContext.ts +17 -4
- package/src/util/config/types.ts +2 -2
- package/src/util/utils.ts +21 -1
- package/test/src/auth.test.ts +33 -0
- package/test/src/env.ts +0 -1
- package/test/src/routes/probes.test.ts +6 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/db/db-index.d.ts +0 -1
- package/dist/db/db-index.js +0 -2
- package/dist/db/db-index.js.map +0 -1
- package/dist/db/mongo.d.ts +0 -35
- package/dist/db/mongo.js +0 -73
- package/dist/db/mongo.js.map +0 -1
- package/dist/locks/LockManager.d.ts +0 -10
- package/dist/locks/LockManager.js +0 -7
- package/dist/locks/LockManager.js.map +0 -1
- package/dist/locks/MongoLocks.d.ts +0 -36
- package/dist/locks/MongoLocks.js +0 -81
- package/dist/locks/MongoLocks.js.map +0 -1
- package/dist/locks/locks-index.d.ts +0 -2
- package/dist/locks/locks-index.js +0 -3
- package/dist/locks/locks-index.js.map +0 -1
- package/dist/migrations/db/migrations/1684951997326-init.d.ts +0 -3
- package/dist/migrations/db/migrations/1684951997326-init.js +0 -33
- package/dist/migrations/db/migrations/1684951997326-init.js.map +0 -1
- package/dist/migrations/db/migrations/1688556755264-initial-sync-rules.d.ts +0 -2
- package/dist/migrations/db/migrations/1688556755264-initial-sync-rules.js +0 -5
- package/dist/migrations/db/migrations/1688556755264-initial-sync-rules.js.map +0 -1
- package/dist/migrations/db/migrations/1702295701188-sync-rule-state.d.ts +0 -3
- package/dist/migrations/db/migrations/1702295701188-sync-rule-state.js +0 -56
- package/dist/migrations/db/migrations/1702295701188-sync-rule-state.js.map +0 -1
- package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.d.ts +0 -3
- package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.js +0 -29
- package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.js.map +0 -1
- package/dist/migrations/db/migrations/1727099539247-custom-write-checkpoint-index.d.ts +0 -3
- package/dist/migrations/db/migrations/1727099539247-custom-write-checkpoint-index.js +0 -31
- package/dist/migrations/db/migrations/1727099539247-custom-write-checkpoint-index.js.map +0 -1
- package/dist/migrations/definitions.d.ts +0 -18
- package/dist/migrations/definitions.js +0 -6
- package/dist/migrations/definitions.js.map +0 -1
- package/dist/migrations/executor.d.ts +0 -16
- package/dist/migrations/executor.js +0 -64
- package/dist/migrations/executor.js.map +0 -1
- package/dist/migrations/migrations.d.ts +0 -18
- package/dist/migrations/migrations.js +0 -110
- package/dist/migrations/migrations.js.map +0 -1
- package/dist/migrations/store/migration-store.d.ts +0 -11
- package/dist/migrations/store/migration-store.js +0 -46
- package/dist/migrations/store/migration-store.js.map +0 -1
- package/dist/storage/MongoBucketStorage.d.ts +0 -48
- package/dist/storage/MongoBucketStorage.js +0 -427
- package/dist/storage/MongoBucketStorage.js.map +0 -1
- package/dist/storage/mongo/MongoBucketBatch.d.ts +0 -74
- package/dist/storage/mongo/MongoBucketBatch.js +0 -683
- package/dist/storage/mongo/MongoBucketBatch.js.map +0 -1
- package/dist/storage/mongo/MongoCompactor.d.ts +0 -40
- package/dist/storage/mongo/MongoCompactor.js +0 -310
- package/dist/storage/mongo/MongoCompactor.js.map +0 -1
- package/dist/storage/mongo/MongoIdSequence.d.ts +0 -12
- package/dist/storage/mongo/MongoIdSequence.js +0 -21
- package/dist/storage/mongo/MongoIdSequence.js.map +0 -1
- package/dist/storage/mongo/MongoPersistedSyncRules.d.ts +0 -9
- package/dist/storage/mongo/MongoPersistedSyncRules.js +0 -9
- package/dist/storage/mongo/MongoPersistedSyncRules.js.map +0 -1
- package/dist/storage/mongo/MongoPersistedSyncRulesContent.d.ts +0 -20
- package/dist/storage/mongo/MongoPersistedSyncRulesContent.js +0 -26
- package/dist/storage/mongo/MongoPersistedSyncRulesContent.js.map +0 -1
- package/dist/storage/mongo/MongoStorageProvider.d.ts +0 -5
- package/dist/storage/mongo/MongoStorageProvider.js +0 -26
- package/dist/storage/mongo/MongoStorageProvider.js.map +0 -1
- package/dist/storage/mongo/MongoSyncBucketStorage.d.ts +0 -38
- package/dist/storage/mongo/MongoSyncBucketStorage.js +0 -534
- package/dist/storage/mongo/MongoSyncBucketStorage.js.map +0 -1
- package/dist/storage/mongo/MongoSyncRulesLock.d.ts +0 -16
- package/dist/storage/mongo/MongoSyncRulesLock.js +0 -65
- package/dist/storage/mongo/MongoSyncRulesLock.js.map +0 -1
- package/dist/storage/mongo/MongoWriteCheckpointAPI.d.ts +0 -20
- package/dist/storage/mongo/MongoWriteCheckpointAPI.js +0 -104
- package/dist/storage/mongo/MongoWriteCheckpointAPI.js.map +0 -1
- package/dist/storage/mongo/OperationBatch.d.ts +0 -35
- package/dist/storage/mongo/OperationBatch.js +0 -119
- package/dist/storage/mongo/OperationBatch.js.map +0 -1
- package/dist/storage/mongo/PersistedBatch.d.ts +0 -46
- package/dist/storage/mongo/PersistedBatch.js +0 -223
- package/dist/storage/mongo/PersistedBatch.js.map +0 -1
- package/dist/storage/mongo/config.d.ts +0 -19
- package/dist/storage/mongo/config.js +0 -26
- package/dist/storage/mongo/config.js.map +0 -1
- package/dist/storage/mongo/db.d.ts +0 -36
- package/dist/storage/mongo/db.js +0 -47
- package/dist/storage/mongo/db.js.map +0 -1
- package/dist/storage/mongo/models.d.ts +0 -163
- package/dist/storage/mongo/models.js +0 -27
- package/dist/storage/mongo/models.js.map +0 -1
- package/dist/storage/mongo/util.d.ts +0 -54
- package/dist/storage/mongo/util.js +0 -190
- package/dist/storage/mongo/util.js.map +0 -1
- package/src/db/db-index.ts +0 -1
- package/src/db/mongo.ts +0 -81
- package/src/locks/LockManager.ts +0 -16
- package/src/locks/MongoLocks.ts +0 -142
- package/src/locks/locks-index.ts +0 -2
- package/src/migrations/db/migrations/1684951997326-init.ts +0 -38
- package/src/migrations/db/migrations/1688556755264-initial-sync-rules.ts +0 -5
- package/src/migrations/db/migrations/1702295701188-sync-rule-state.ts +0 -102
- package/src/migrations/db/migrations/1711543888062-write-checkpoint-index.ts +0 -34
- package/src/migrations/db/migrations/1727099539247-custom-write-checkpoint-index.ts +0 -37
- package/src/migrations/definitions.ts +0 -21
- package/src/migrations/executor.ts +0 -87
- package/src/migrations/migrations.ts +0 -142
- package/src/migrations/store/migration-store.ts +0 -63
- package/src/storage/MongoBucketStorage.ts +0 -541
- package/src/storage/mongo/MongoBucketBatch.ts +0 -900
- package/src/storage/mongo/MongoCompactor.ts +0 -393
- package/src/storage/mongo/MongoIdSequence.ts +0 -24
- package/src/storage/mongo/MongoPersistedSyncRules.ts +0 -16
- package/src/storage/mongo/MongoPersistedSyncRulesContent.ts +0 -50
- package/src/storage/mongo/MongoStorageProvider.ts +0 -31
- package/src/storage/mongo/MongoSyncBucketStorage.ts +0 -640
- package/src/storage/mongo/MongoSyncRulesLock.ts +0 -85
- package/src/storage/mongo/MongoWriteCheckpointAPI.ts +0 -154
- package/src/storage/mongo/OperationBatch.ts +0 -131
- package/src/storage/mongo/PersistedBatch.ts +0 -285
- package/src/storage/mongo/config.ts +0 -40
- package/src/storage/mongo/db.ts +0 -88
- package/src/storage/mongo/models.ts +0 -187
- package/src/storage/mongo/util.ts +0 -203
- package/test/src/__snapshots__/sync.test.ts.snap +0 -332
- package/test/src/bucket_validation.test.ts +0 -143
- package/test/src/bucket_validation.ts +0 -60
- package/test/src/compacting.test.ts +0 -295
- package/test/src/data_storage.test.ts +0 -1569
- package/test/src/stream_utils.ts +0 -42
- package/test/src/sync.test.ts +0 -511
- package/test/src/util.ts +0 -150
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { LifeCycledSystem, container } from '@powersync/lib-services-framework';
|
|
1
|
+
import { LifeCycledSystem, MigrationManager, container } from '@powersync/lib-services-framework';
|
|
2
|
+
import { framework } from '../index.js';
|
|
2
3
|
import * as metrics from '../metrics/Metrics.js';
|
|
3
4
|
import * as replication from '../replication/replication-index.js';
|
|
4
5
|
import * as routes from '../routes/routes-index.js';
|
|
@@ -15,12 +16,16 @@ export class ServiceContextContainer {
|
|
|
15
16
|
this.storageEngine = new storage.StorageEngine({
|
|
16
17
|
configuration
|
|
17
18
|
});
|
|
19
|
+
const migrationManager = new MigrationManager();
|
|
20
|
+
container.register(framework.ContainerImplementation.MIGRATION_MANAGER, migrationManager);
|
|
21
|
+
this.lifeCycleEngine.withLifecycle(migrationManager, {
|
|
22
|
+
// Migrations should be executed before the system starts
|
|
23
|
+
start: () => migrationManager[Symbol.asyncDispose]()
|
|
24
|
+
});
|
|
18
25
|
this.lifeCycleEngine.withLifecycle(this.storageEngine, {
|
|
19
26
|
start: (storageEngine) => storageEngine.start(),
|
|
20
27
|
stop: (storageEngine) => storageEngine.shutDown()
|
|
21
28
|
});
|
|
22
|
-
// Mongo storage is available as an option by default TODO: Consider moving this to a Mongo Storage Module
|
|
23
|
-
this.storageEngine.registerProvider(new storage.MongoStorageProvider());
|
|
24
29
|
}
|
|
25
30
|
get replicationEngine() {
|
|
26
31
|
return container.getOptional(replication.ReplicationEngine);
|
|
@@ -31,6 +36,9 @@ export class ServiceContextContainer {
|
|
|
31
36
|
get metrics() {
|
|
32
37
|
return container.getOptional(metrics.Metrics);
|
|
33
38
|
}
|
|
39
|
+
get migrations() {
|
|
40
|
+
return container.getImplementation(framework.ContainerImplementation.MIGRATION_MANAGER);
|
|
41
|
+
}
|
|
34
42
|
/**
|
|
35
43
|
* Allows for registering core and generic implementations of services/helpers.
|
|
36
44
|
* This uses the framework container under the hood.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceContext.js","sourceRoot":"","sources":["../../src/system/ServiceContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAqB,SAAS,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"ServiceContext.js","sourceRoot":"","sources":["../../src/system/ServiceContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAqB,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAErH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AAEjD,OAAO,KAAK,WAAW,MAAM,qCAAqC,CAAC;AACnE,OAAO,KAAK,MAAM,MAAM,2BAA2B,CAAC;AACpD,OAAO,KAAK,OAAO,MAAM,6BAA6B,CAAC;AAavD;;;;GAIG;AACH,MAAM,OAAO,uBAAuB;IAIlC,YAAmB,aAA4C;QAA5C,kBAAa,GAAb,aAAa,CAA+B;QAC7D,IAAI,CAAC,eAAe,GAAG,IAAI,gBAAgB,EAAE,CAAC;QAE9C,IAAI,CAAC,aAAa,GAAG,IAAI,OAAO,CAAC,aAAa,CAAC;YAC7C,aAAa;SACd,CAAC,CAAC;QAEH,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAC;QAChD,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,uBAAuB,CAAC,iBAAiB,EAAE,gBAAgB,CAAC,CAAC;QAE1F,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,gBAAgB,EAAE;YACnD,yDAAyD;YACzD,KAAK,EAAE,GAAG,EAAE,CAAC,gBAAgB,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE;SACrD,CAAC,CAAC;QAEH,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,IAAI,CAAC,aAAa,EAAE;YACrD,KAAK,EAAE,CAAC,aAAa,EAAE,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE;YAC/C,IAAI,EAAE,CAAC,aAAa,EAAE,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE;SAClD,CAAC,CAAC;IACL,CAAC;IAED,IAAI,iBAAiB;QACnB,OAAO,SAAS,CAAC,WAAW,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;IAC9D,CAAC;IAED,IAAI,YAAY;QACd,OAAO,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IACpD,CAAC;IAED,IAAI,OAAO;QACT,OAAO,SAAS,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAChD,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,SAAS,CAAC,iBAAiB,CAAC,SAAS,CAAC,uBAAuB,CAAC,iBAAiB,CAAC,CAAC;IAC1F,CAAC;IAED;;;OAGG;IACH,QAAQ,CAAI,UAAgC,EAAE,cAAiB;QAC7D,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;IACjD,CAAC;IAED;;OAEG;IACH,GAAG,CAAI,UAAgC;QACrC,OAAO,SAAS,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;IACjD,CAAC;CACF"}
|
|
@@ -24,8 +24,8 @@ export type SyncRulesConfig = {
|
|
|
24
24
|
};
|
|
25
25
|
export type ResolvedPowerSyncConfig = {
|
|
26
26
|
base_config: PowerSyncConfig;
|
|
27
|
-
connections?: configFile.
|
|
28
|
-
storage: configFile.
|
|
27
|
+
connections?: configFile.GenericDataSourceConfig[];
|
|
28
|
+
storage: configFile.GenericStorageConfig;
|
|
29
29
|
dev: {
|
|
30
30
|
demo_auth: boolean;
|
|
31
31
|
demo_password?: string;
|
package/dist/util/utils.d.ts
CHANGED
|
@@ -18,7 +18,12 @@ export declare function addBucketChecksums(a: BucketChecksum, b: PartialChecksum
|
|
|
18
18
|
export declare function getUuidReplicaIdentityBson(tuple: sync_rules.ToastableSqliteRow, columns: storage.ColumnDescriptor[]): bson.UUID;
|
|
19
19
|
export declare function uuidForRowBson(row: sync_rules.SqliteRow): bson.UUID;
|
|
20
20
|
export declare function hasToastedValues(row: sync_rules.ToastableSqliteRow): boolean;
|
|
21
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Returns true if we have a complete row.
|
|
23
|
+
*
|
|
24
|
+
* If we don't store data, we assume we always have a complete row.
|
|
25
|
+
*/
|
|
26
|
+
export declare function isCompleteRow(storeData: boolean, row: sync_rules.ToastableSqliteRow): row is sync_rules.SqliteRow;
|
|
22
27
|
export declare function checkpointUserId(user_id: string | undefined, client_id: string | undefined): string;
|
|
23
28
|
/**
|
|
24
29
|
* Reduce a bucket to the final state as stored on the client.
|
|
@@ -33,3 +38,10 @@ export declare function checkpointUserId(user_id: string | undefined, client_id:
|
|
|
33
38
|
* Used for tests.
|
|
34
39
|
*/
|
|
35
40
|
export declare function reduceBucket(operations: OplogEntry[]): OplogEntry[];
|
|
41
|
+
/**
|
|
42
|
+
* Flattens string to reduce memory usage (around 320 bytes -> 120 bytes),
|
|
43
|
+
* at the cost of some upfront CPU usage.
|
|
44
|
+
*
|
|
45
|
+
* From: https://github.com/davidmarkclements/flatstr/issues/8
|
|
46
|
+
*/
|
|
47
|
+
export declare function flatstr(s: string): string;
|
package/dist/util/utils.js
CHANGED
|
@@ -104,7 +104,16 @@ export function hasToastedValues(row) {
|
|
|
104
104
|
}
|
|
105
105
|
return false;
|
|
106
106
|
}
|
|
107
|
-
|
|
107
|
+
/**
|
|
108
|
+
* Returns true if we have a complete row.
|
|
109
|
+
*
|
|
110
|
+
* If we don't store data, we assume we always have a complete row.
|
|
111
|
+
*/
|
|
112
|
+
export function isCompleteRow(storeData, row) {
|
|
113
|
+
if (!storeData) {
|
|
114
|
+
// Assume the row is complete - no need to check
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
108
117
|
return !hasToastedValues(row);
|
|
109
118
|
}
|
|
110
119
|
export function checkpointUserId(user_id, client_id) {
|
|
@@ -169,6 +178,16 @@ export function reduceBucket(operations) {
|
|
|
169
178
|
];
|
|
170
179
|
return finalState;
|
|
171
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* Flattens string to reduce memory usage (around 320 bytes -> 120 bytes),
|
|
183
|
+
* at the cost of some upfront CPU usage.
|
|
184
|
+
*
|
|
185
|
+
* From: https://github.com/davidmarkclements/flatstr/issues/8
|
|
186
|
+
*/
|
|
187
|
+
export function flatstr(s) {
|
|
188
|
+
s.match(/\n/g);
|
|
189
|
+
return s;
|
|
190
|
+
}
|
|
172
191
|
function rowKey(entry) {
|
|
173
192
|
return `${entry.object_type}/${entry.object_id}/${entry.subkey}`;
|
|
174
193
|
}
|
package/dist/util/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/util/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAS7B,MAAM,CAAC,MAAM,YAAY,GAAG,sCAAsC,CAAC;AAEnE,MAAM,UAAU,gBAAgB,CAAC,UAAkB;IACjD,OAAO,IAAI,UAAU,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC;AACrE,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,IAAY,EAAE,EAAU,EAAE,IAA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AAM,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;IAEH,IAAI,UAAU,GAAiB;QAC7B,wDAAwD;QACxD,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE;QACpD,GAAG,IAAI;KACR,CAAC;IAEF,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,OAAO,CAAC,CAAS;IAC/B,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACf,OAAO,CAAC,CAAC;AACX,CAAC;AAED,SAAS,MAAM,CAAC,KAAiB;IAC/B,OAAO,GAAG,KAAK,CAAC,WAAW,IAAI,KAAK,CAAC,SAAS,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;AACnE,CAAC"}
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
-
"version": "0.
|
|
8
|
+
"version": "0.14.0",
|
|
9
9
|
"main": "dist/index.js",
|
|
10
10
|
"license": "FSL-1.1-Apache-2.0",
|
|
11
11
|
"type": "module",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"@opentelemetry/sdk-metrics": "1.24.1",
|
|
19
19
|
"async": "^3.2.4",
|
|
20
20
|
"async-mutex": "^0.5.0",
|
|
21
|
-
"bson": "^6.
|
|
21
|
+
"bson": "^6.8.0",
|
|
22
22
|
"commander": "^12.0.0",
|
|
23
23
|
"cors": "^2.8.5",
|
|
24
24
|
"ipaddr.js": "^2.1.0",
|
|
@@ -26,18 +26,17 @@
|
|
|
26
26
|
"jose": "^4.15.1",
|
|
27
27
|
"lodash": "^4.17.21",
|
|
28
28
|
"lru-cache": "^10.2.2",
|
|
29
|
-
"mongodb": "^6.11.0",
|
|
30
29
|
"node-fetch": "^3.3.2",
|
|
31
|
-
"ts-codec": "^1.
|
|
30
|
+
"ts-codec": "^1.3.0",
|
|
32
31
|
"uri-js": "^4.4.1",
|
|
33
32
|
"uuid": "^9.0.1",
|
|
34
33
|
"winston": "^3.13.0",
|
|
35
34
|
"yaml": "^2.3.2",
|
|
36
|
-
"@powersync/lib-services-framework": "0.
|
|
35
|
+
"@powersync/lib-services-framework": "0.3.0",
|
|
37
36
|
"@powersync/service-jsonbig": "0.17.10",
|
|
38
|
-
"@powersync/service-rsocket-router": "0.0.
|
|
39
|
-
"@powersync/service-sync-rules": "0.
|
|
40
|
-
"@powersync/service-types": "0.
|
|
37
|
+
"@powersync/service-rsocket-router": "0.0.15",
|
|
38
|
+
"@powersync/service-sync-rules": "0.23.1",
|
|
39
|
+
"@powersync/service-types": "0.7.0"
|
|
41
40
|
},
|
|
42
41
|
"devDependencies": {
|
|
43
42
|
"@types/async": "^3.2.24",
|
package/src/auth/KeySpec.ts
CHANGED
|
@@ -2,8 +2,9 @@ import * as jose from 'jose';
|
|
|
2
2
|
|
|
3
3
|
export const HS_ALGORITHMS = ['HS256', 'HS384', 'HS512'];
|
|
4
4
|
export const RSA_ALGORITHMS = ['RS256', 'RS384', 'RS512'];
|
|
5
|
+
export const EC_ALGORITHMS = ['ES256', 'ES384', 'ES512'];
|
|
5
6
|
export const OKP_ALGORITHMS = ['EdDSA'];
|
|
6
|
-
export const SUPPORTED_ALGORITHMS = [...HS_ALGORITHMS, ...RSA_ALGORITHMS, ...OKP_ALGORITHMS];
|
|
7
|
+
export const SUPPORTED_ALGORITHMS = [...HS_ALGORITHMS, ...RSA_ALGORITHMS, ...EC_ALGORITHMS, ...OKP_ALGORITHMS];
|
|
7
8
|
|
|
8
9
|
export interface KeyOptions {
|
|
9
10
|
/**
|
|
@@ -48,9 +49,10 @@ export class KeySpec {
|
|
|
48
49
|
return HS_ALGORITHMS.includes(jwtAlg);
|
|
49
50
|
} else if (this.source.kty === 'OKP') {
|
|
50
51
|
return OKP_ALGORITHMS.includes(jwtAlg);
|
|
52
|
+
} else if (this.source.kty === 'EC') {
|
|
53
|
+
return EC_ALGORITHMS.includes(jwtAlg);
|
|
51
54
|
}
|
|
52
|
-
|
|
53
|
-
// 'EC' is unsupported
|
|
55
|
+
|
|
54
56
|
return false;
|
|
55
57
|
}
|
|
56
58
|
|
|
@@ -73,7 +73,7 @@ export class RemoteJWKSCollector implements KeyCollector {
|
|
|
73
73
|
|
|
74
74
|
let keys: KeySpec[] = [];
|
|
75
75
|
for (let keyData of data.keys) {
|
|
76
|
-
if (keyData.kty != 'RSA' && keyData.kty != 'OKP') {
|
|
76
|
+
if (keyData.kty != 'RSA' && keyData.kty != 'OKP' && keyData.kty != 'EC') {
|
|
77
77
|
// HS (oct) keys not allowed because they are symmetric
|
|
78
78
|
continue;
|
|
79
79
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
|
|
3
|
-
import { logger } from '@powersync/lib-services-framework';
|
|
3
|
+
import { container, logger } from '@powersync/lib-services-framework';
|
|
4
4
|
import * as v8 from 'v8';
|
|
5
|
-
import * as
|
|
5
|
+
import * as system from '../../system/system-index.js';
|
|
6
6
|
import * as utils from '../../util/util-index.js';
|
|
7
|
+
|
|
8
|
+
import { modules } from '../../index.js';
|
|
7
9
|
import { extractRunnerOptions, wrapConfigCommand } from './config-command.js';
|
|
8
10
|
|
|
9
11
|
const COMMAND_NAME = 'compact';
|
|
@@ -32,20 +34,22 @@ export function registerCompactAction(program: Command) {
|
|
|
32
34
|
if (buckets == null) {
|
|
33
35
|
logger.info('Compacting storage for all buckets...');
|
|
34
36
|
} else {
|
|
35
|
-
logger.info(`Compacting storage for ${buckets
|
|
37
|
+
logger.info(`Compacting storage for ${buckets?.join(', ')}...`);
|
|
36
38
|
}
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
const config = await utils.loadConfig(extractRunnerOptions(options));
|
|
40
|
+
const serviceContext = new system.ServiceContextContainer(config);
|
|
41
|
+
|
|
42
|
+
// Register modules in order to allow custom module compacting
|
|
43
|
+
const moduleManager = container.getImplementation(modules.ModuleManager);
|
|
44
|
+
await moduleManager.initialize(serviceContext);
|
|
45
|
+
|
|
41
46
|
logger.info('Connecting to storage...');
|
|
42
|
-
|
|
43
|
-
const client = psdb.client;
|
|
44
|
-
await client.connect();
|
|
47
|
+
|
|
45
48
|
try {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
// Start the storage engine in order to create the appropriate BucketStorage
|
|
50
|
+
await serviceContext.lifeCycleEngine.start();
|
|
51
|
+
const bucketStorage = serviceContext.storageEngine.activeBucketStorage;
|
|
52
|
+
|
|
49
53
|
const active = await bucketStorage.getActiveSyncRulesContent();
|
|
50
54
|
if (active == null) {
|
|
51
55
|
logger.info('No active instance to compact');
|
|
@@ -57,9 +61,10 @@ export function registerCompactAction(program: Command) {
|
|
|
57
61
|
logger.info('Successfully compacted storage.');
|
|
58
62
|
} catch (e) {
|
|
59
63
|
logger.error(`Failed to compact: ${e.toString()}`);
|
|
64
|
+
// Indirectly triggers lifeCycleEngine.stop
|
|
60
65
|
process.exit(1);
|
|
61
66
|
} finally {
|
|
62
|
-
|
|
67
|
+
// Indirectly triggers lifeCycleEngine.stop
|
|
63
68
|
process.exit(0);
|
|
64
69
|
}
|
|
65
70
|
});
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { logger } from '@powersync/lib-services-framework';
|
|
1
|
+
import { container, logger, migrations } from '@powersync/lib-services-framework';
|
|
2
2
|
import { Command } from 'commander';
|
|
3
3
|
|
|
4
|
-
import * as
|
|
4
|
+
import * as modules from '../../modules/modules-index.js';
|
|
5
|
+
import * as system from '../../system/system-index.js';
|
|
6
|
+
import * as utils from '../../util/util-index.js';
|
|
5
7
|
import { extractRunnerOptions, wrapConfigCommand } from './config-command.js';
|
|
6
8
|
|
|
7
9
|
const COMMAND_NAME = 'migrate';
|
|
@@ -15,12 +17,23 @@ export function registerMigrationAction(program: Command) {
|
|
|
15
17
|
.description('Run migrations')
|
|
16
18
|
.argument('<direction>', 'Migration direction. `up` or `down`')
|
|
17
19
|
.action(async (direction: migrations.Direction, options) => {
|
|
20
|
+
const config = await utils.loadConfig(extractRunnerOptions(options));
|
|
21
|
+
const serviceContext = new system.ServiceContextContainer(config);
|
|
22
|
+
|
|
23
|
+
// Register modules in order to allow custom module migrations
|
|
24
|
+
const moduleManager = container.getImplementation(modules.ModuleManager);
|
|
25
|
+
await moduleManager.initialize(serviceContext);
|
|
26
|
+
|
|
18
27
|
try {
|
|
19
|
-
await migrations.migrate({
|
|
28
|
+
await serviceContext.migrations.migrate({
|
|
20
29
|
direction,
|
|
21
|
-
|
|
30
|
+
// Give the migrations access to the service context
|
|
31
|
+
migrationContext: {
|
|
32
|
+
service_context: serviceContext
|
|
33
|
+
}
|
|
22
34
|
});
|
|
23
35
|
|
|
36
|
+
await serviceContext.migrations[Symbol.asyncDispose]();
|
|
24
37
|
process.exit(0);
|
|
25
38
|
} catch (e) {
|
|
26
39
|
logger.error(`Migration failure`, e);
|
package/src/index.ts
CHANGED
|
@@ -6,9 +6,6 @@ export * as api from './api/api-index.js';
|
|
|
6
6
|
export * from './auth/auth-index.js';
|
|
7
7
|
export * as auth from './auth/auth-index.js';
|
|
8
8
|
|
|
9
|
-
export * from './db/db-index.js';
|
|
10
|
-
export * as db from './db/db-index.js';
|
|
11
|
-
|
|
12
9
|
export * from './entry/entry-index.js';
|
|
13
10
|
export * as entry from './entry/entry-index.js';
|
|
14
11
|
|
|
@@ -18,8 +15,8 @@ export * as framework from '@powersync/lib-services-framework';
|
|
|
18
15
|
export * from './metrics/Metrics.js';
|
|
19
16
|
export * as metrics from './metrics/Metrics.js';
|
|
20
17
|
|
|
18
|
+
export * from './migrations/migrations-index.js';
|
|
21
19
|
export * as migrations from './migrations/migrations-index.js';
|
|
22
|
-
export * from './migrations/migrations.js';
|
|
23
20
|
|
|
24
21
|
export * from './modules/modules-index.js';
|
|
25
22
|
export * as modules from './modules/modules-index.js';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as framework from '@powersync/lib-services-framework';
|
|
2
|
+
import fs from 'fs/promises';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import * as system from '../system/system-index.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* PowerSync service migrations each have this context available to the `up` and `down` methods.
|
|
8
|
+
*/
|
|
9
|
+
export interface PowerSyncMigrationContext {
|
|
10
|
+
service_context: system.ServiceContext;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface PowerSyncMigrationGenerics extends framework.MigrationAgentGenerics {
|
|
14
|
+
MIGRATION_CONTEXT: PowerSyncMigrationContext;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type PowerSyncMigrationFunction = framework.MigrationFunction<PowerSyncMigrationContext>;
|
|
18
|
+
|
|
19
|
+
export abstract class AbstractPowerSyncMigrationAgent extends framework.AbstractMigrationAgent<PowerSyncMigrationGenerics> {
|
|
20
|
+
abstract getInternalScriptsDir(): string;
|
|
21
|
+
|
|
22
|
+
async loadInternalMigrations(): Promise<framework.Migration<PowerSyncMigrationContext>[]> {
|
|
23
|
+
const migrationsDir = this.getInternalScriptsDir();
|
|
24
|
+
const files = await fs.readdir(migrationsDir);
|
|
25
|
+
const migrations = files.filter((file) => {
|
|
26
|
+
return '.js' == path.extname(file);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
return await Promise.all(
|
|
30
|
+
migrations.map(async (migration) => {
|
|
31
|
+
const module = await import(path.resolve(migrationsDir, migration));
|
|
32
|
+
return {
|
|
33
|
+
name: path.basename(migration).replace(path.extname(migration), ''),
|
|
34
|
+
up: module.up,
|
|
35
|
+
down: module.down
|
|
36
|
+
};
|
|
37
|
+
})
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type PowerSyncMigrationManager = framework.MigrationManager<PowerSyncMigrationGenerics>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as framework from '@powersync/lib-services-framework';
|
|
2
|
+
import * as system from '../system/system-index.js';
|
|
3
|
+
|
|
4
|
+
export const ensureAutomaticMigrations = async (options: { serviceContext: system.ServiceContext }) => {
|
|
5
|
+
const { serviceContext } = options;
|
|
6
|
+
if (serviceContext.configuration.migrations?.disable_auto_migration) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
await serviceContext.migrations.migrate({
|
|
10
|
+
direction: framework.migrations.Direction.Up,
|
|
11
|
+
migrationContext: {
|
|
12
|
+
service_context: serviceContext
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
};
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './migrations.js';
|
|
1
|
+
export * from './ensure-automatic-migrations.js';
|
|
2
|
+
export * from './PowerSyncMigrationManager.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { container, router } from
|
|
2
|
-
import { routeDefinition } from
|
|
1
|
+
import { container, router } from '@powersync/lib-services-framework';
|
|
2
|
+
import { routeDefinition } from '../router.js';
|
|
3
3
|
|
|
4
4
|
export enum ProbeRoutes {
|
|
5
5
|
STARTUP = '/probes/startup',
|
|
@@ -16,7 +16,7 @@ export const startupCheck = routeDefinition({
|
|
|
16
16
|
return new router.RouterResponse({
|
|
17
17
|
status: state.started ? 200 : 400,
|
|
18
18
|
data: {
|
|
19
|
-
...state
|
|
19
|
+
...state
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
22
|
}
|
|
@@ -28,13 +28,13 @@ export const livenessCheck = routeDefinition({
|
|
|
28
28
|
handler: async () => {
|
|
29
29
|
const state = container.probes.state();
|
|
30
30
|
|
|
31
|
-
const timeDifference = Date.now() - state.touched_at.getTime()
|
|
31
|
+
const timeDifference = Date.now() - state.touched_at.getTime();
|
|
32
32
|
const status = timeDifference < 10000 ? 200 : 400;
|
|
33
33
|
|
|
34
34
|
return new router.RouterResponse({
|
|
35
35
|
status,
|
|
36
36
|
data: {
|
|
37
|
-
...state
|
|
37
|
+
...state
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
40
|
}
|
|
@@ -49,7 +49,7 @@ export const readinessCheck = routeDefinition({
|
|
|
49
49
|
return new router.RouterResponse({
|
|
50
50
|
status: state.ready ? 200 : 400,
|
|
51
51
|
data: {
|
|
52
|
-
...state
|
|
52
|
+
...state
|
|
53
53
|
}
|
|
54
54
|
});
|
|
55
55
|
}
|
|
@@ -8,13 +8,49 @@ import {
|
|
|
8
8
|
SqliteRow,
|
|
9
9
|
ToastableSqliteRow
|
|
10
10
|
} from '@powersync/service-sync-rules';
|
|
11
|
+
import { BSON } from 'bson';
|
|
11
12
|
import * as util from '../util/util-index.js';
|
|
12
13
|
import { ReplicationEventPayload } from './ReplicationEventPayload.js';
|
|
13
14
|
import { SourceEntityDescriptor } from './SourceEntity.js';
|
|
14
15
|
import { SourceTable } from './SourceTable.js';
|
|
15
|
-
import { BatchedCustomWriteCheckpointOptions
|
|
16
|
+
import { BatchedCustomWriteCheckpointOptions } from './storage-index.js';
|
|
16
17
|
import { SyncStorageWriteCheckpointAPI } from './WriteCheckpointAPI.js';
|
|
17
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Replica id uniquely identifying a row on the source database.
|
|
21
|
+
*
|
|
22
|
+
* Can be any value serializable to BSON.
|
|
23
|
+
*
|
|
24
|
+
* If the value is an entire document, the data serialized to a v5 UUID may be a good choice here.
|
|
25
|
+
*/
|
|
26
|
+
export type ReplicaId = BSON.UUID | BSON.Document | any;
|
|
27
|
+
|
|
28
|
+
export enum SyncRuleState {
|
|
29
|
+
/**
|
|
30
|
+
* New sync rules - needs to be processed (initial replication).
|
|
31
|
+
*
|
|
32
|
+
* While multiple sets of sync rules _can_ be in PROCESSING,
|
|
33
|
+
* it's generally pointless, so we only keep one in that state.
|
|
34
|
+
*/
|
|
35
|
+
PROCESSING = 'PROCESSING',
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Sync rule processing is done, and can be used for sync.
|
|
39
|
+
*
|
|
40
|
+
* Only one set of sync rules should be in ACTIVE state.
|
|
41
|
+
*/
|
|
42
|
+
ACTIVE = 'ACTIVE',
|
|
43
|
+
/**
|
|
44
|
+
* This state is used when the sync rules has been replaced,
|
|
45
|
+
* and replication is or should be stopped.
|
|
46
|
+
*/
|
|
47
|
+
STOP = 'STOP',
|
|
48
|
+
/**
|
|
49
|
+
* After sync rules have been stopped, the data needs to be
|
|
50
|
+
* deleted. Once deleted, the state is TERMINATED.
|
|
51
|
+
*/
|
|
52
|
+
TERMINATED = 'TERMINATED'
|
|
53
|
+
}
|
|
18
54
|
export interface BucketStorageFactoryListener extends DisposableListener {
|
|
19
55
|
syncStorageCreated: (storage: SyncRulesBucketStorage) => void;
|
|
20
56
|
replicationEvent: (event: ReplicationEventPayload) => void;
|
|
@@ -501,3 +537,19 @@ export interface TerminateOptions {
|
|
|
501
537
|
*/
|
|
502
538
|
clearStorage: boolean;
|
|
503
539
|
}
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Helper for tests.
|
|
543
|
+
* This is not in the `service-core-tests` package in order for storage modules
|
|
544
|
+
* to provide relevant factories without requiring `service-core-tests` as a direct dependency.
|
|
545
|
+
*/
|
|
546
|
+
export interface TestStorageOptions {
|
|
547
|
+
/**
|
|
548
|
+
* By default, collections are only cleared/
|
|
549
|
+
* Setting this to true will drop the collections completely.
|
|
550
|
+
*/
|
|
551
|
+
dropAll?: boolean;
|
|
552
|
+
|
|
553
|
+
doNotClear?: boolean;
|
|
554
|
+
}
|
|
555
|
+
export type TestStorageFactory = (options?: TestStorageOptions) => Promise<BucketStorageFactory>;
|
|
@@ -48,6 +48,8 @@ export class SourceTable {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
|
+
* Use for postgres only.
|
|
52
|
+
*
|
|
51
53
|
* Usage: db.query({statement: `SELECT $1::regclass`, params: [{type: 'varchar', value: table.qualifiedName}]})
|
|
52
54
|
*/
|
|
53
55
|
get qualifiedName() {
|
|
@@ -55,6 +57,8 @@ export class SourceTable {
|
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
/**
|
|
60
|
+
* Use for postgres and logs only.
|
|
61
|
+
*
|
|
58
62
|
* Usage: db.query(`SELECT * FROM ${table.escapedIdentifier}`)
|
|
59
63
|
*/
|
|
60
64
|
get escapedIdentifier() {
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import * as bson from 'bson';
|
|
2
|
+
|
|
3
|
+
import { SqliteJsonValue } from '@powersync/service-sync-rules';
|
|
4
|
+
import { ReplicaId } from './BucketStorage.js';
|
|
5
|
+
|
|
6
|
+
export const BSON_DESERIALIZE_OPTIONS: bson.DeserializeOptions = {
|
|
7
|
+
// use bigint instead of Long
|
|
8
|
+
useBigInt64: true
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Lookup serialization must be number-agnostic. I.e. normalize numbers, instead of preserving numbers.
|
|
13
|
+
* @param lookup
|
|
14
|
+
*/
|
|
15
|
+
export const serializeLookupBuffer = (lookup: SqliteJsonValue[]): Buffer => {
|
|
16
|
+
const normalized = lookup.map((value) => {
|
|
17
|
+
if (typeof value == 'number' && Number.isInteger(value)) {
|
|
18
|
+
return BigInt(value);
|
|
19
|
+
} else {
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
return bson.serialize({ l: normalized }) as Buffer;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const serializeLookup = (lookup: SqliteJsonValue[]) => {
|
|
27
|
+
return new bson.Binary(serializeLookupBuffer(lookup));
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* True if this is a bson.UUID.
|
|
32
|
+
*
|
|
33
|
+
* Works even with multiple copies of the bson package.
|
|
34
|
+
*/
|
|
35
|
+
export const isUUID = (value: any): value is bson.UUID => {
|
|
36
|
+
if (value == null || typeof value != 'object') {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
const uuid = value as bson.UUID;
|
|
40
|
+
return uuid._bsontype == 'Binary' && uuid.sub_type == bson.Binary.SUBTYPE_UUID;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const serializeReplicaId = (id: ReplicaId): Buffer => {
|
|
44
|
+
return bson.serialize({ id }) as Buffer;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const deserializeReplicaId = (id: Buffer): ReplicaId => {
|
|
48
|
+
const deserialized = deserializeBson(id);
|
|
49
|
+
return deserialized.id;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const deserializeBson = (buffer: Buffer) => {
|
|
53
|
+
return bson.deserialize(buffer, BSON_DESERIALIZE_OPTIONS);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const serializeBson = (document: any): Buffer => {
|
|
57
|
+
return bson.serialize(document) as Buffer;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Returns true if two ReplicaId values are the same (serializes to the same BSON value).
|
|
62
|
+
*/
|
|
63
|
+
export const replicaIdEquals = (a: ReplicaId, b: ReplicaId) => {
|
|
64
|
+
if (a === b) {
|
|
65
|
+
return true;
|
|
66
|
+
} else if (typeof a == 'string' && typeof b == 'string') {
|
|
67
|
+
return a == b;
|
|
68
|
+
} else if (isUUID(a) && isUUID(b)) {
|
|
69
|
+
return a.equals(b);
|
|
70
|
+
} else if (a == null && b == null) {
|
|
71
|
+
return true;
|
|
72
|
+
} else if ((b == null && a != null) || (a == null && b != null)) {
|
|
73
|
+
return false;
|
|
74
|
+
} else {
|
|
75
|
+
// There are many possible primitive values, this covers them all
|
|
76
|
+
return serializeReplicaId(a).equals(serializeReplicaId(b) as ArrayBuffer as Uint8Array);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
@@ -1,21 +1,9 @@
|
|
|
1
|
+
export * from './bson.js';
|
|
1
2
|
export * from './BucketStorage.js';
|
|
2
|
-
export * from './
|
|
3
|
+
export * from './ChecksumCache.js';
|
|
3
4
|
export * from './ReplicationEventPayload.js';
|
|
4
5
|
export * from './SourceEntity.js';
|
|
5
6
|
export * from './SourceTable.js';
|
|
6
7
|
export * from './StorageEngine.js';
|
|
7
|
-
|
|
8
|
-
export * from './mongo/config.js';
|
|
9
|
-
export * from './mongo/db.js';
|
|
10
|
-
export * from './mongo/models.js';
|
|
11
|
-
export * from './mongo/MongoBucketBatch.js';
|
|
12
|
-
export * from './mongo/MongoIdSequence.js';
|
|
13
|
-
export * from './mongo/MongoPersistedSyncRules.js';
|
|
14
|
-
export * from './mongo/MongoPersistedSyncRulesContent.js';
|
|
15
|
-
export * from './mongo/MongoStorageProvider.js';
|
|
16
|
-
export * from './mongo/MongoSyncBucketStorage.js';
|
|
17
|
-
export * from './mongo/MongoSyncRulesLock.js';
|
|
18
|
-
export * from './mongo/OperationBatch.js';
|
|
19
|
-
export * from './mongo/PersistedBatch.js';
|
|
20
|
-
export * from './mongo/util.js';
|
|
8
|
+
export * from './StorageProvider.js';
|
|
21
9
|
export * from './WriteCheckpointAPI.js';
|
package/src/sync/sync.ts
CHANGED
|
@@ -318,7 +318,9 @@ async function* bucketDataBatch(request: BucketDataRequest): AsyncGenerator<Buck
|
|
|
318
318
|
// Send the object as is, will most likely be encoded as a BSON document
|
|
319
319
|
send_data = { data: r };
|
|
320
320
|
} else if (raw_data) {
|
|
321
|
-
|
|
321
|
+
/**
|
|
322
|
+
* Data is a raw string - we can use the more efficient JSON.stringify.
|
|
323
|
+
*/
|
|
322
324
|
const response: util.StreamingSyncData = {
|
|
323
325
|
data: r
|
|
324
326
|
};
|