@powersync/service-core 0.13.0 → 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.
Files changed (181) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/entry/commands/compact-action.js +14 -14
  3. package/dist/entry/commands/compact-action.js.map +1 -1
  4. package/dist/entry/commands/migrate-action.js +15 -4
  5. package/dist/entry/commands/migrate-action.js.map +1 -1
  6. package/dist/index.d.ts +1 -3
  7. package/dist/index.js +1 -3
  8. package/dist/index.js.map +1 -1
  9. package/dist/migrations/PowerSyncMigrationManager.d.ts +17 -0
  10. package/dist/migrations/PowerSyncMigrationManager.js +21 -0
  11. package/dist/migrations/PowerSyncMigrationManager.js.map +1 -0
  12. package/dist/migrations/ensure-automatic-migrations.d.ts +4 -0
  13. package/dist/migrations/ensure-automatic-migrations.js +14 -0
  14. package/dist/migrations/ensure-automatic-migrations.js.map +1 -0
  15. package/dist/migrations/migrations-index.d.ts +2 -3
  16. package/dist/migrations/migrations-index.js +2 -3
  17. package/dist/migrations/migrations-index.js.map +1 -1
  18. package/dist/routes/configure-fastify.d.ts +12 -12
  19. package/dist/routes/endpoints/admin.d.ts +24 -24
  20. package/dist/storage/BucketStorage.d.ts +49 -1
  21. package/dist/storage/BucketStorage.js +26 -0
  22. package/dist/storage/BucketStorage.js.map +1 -1
  23. package/dist/storage/bson.d.ts +24 -0
  24. package/dist/storage/bson.js +73 -0
  25. package/dist/storage/bson.js.map +1 -0
  26. package/dist/storage/storage-index.d.ts +3 -14
  27. package/dist/storage/storage-index.js +3 -14
  28. package/dist/storage/storage-index.js.map +1 -1
  29. package/dist/sync/sync.js +3 -1
  30. package/dist/sync/sync.js.map +1 -1
  31. package/dist/system/ServiceContext.d.ts +3 -0
  32. package/dist/system/ServiceContext.js +11 -3
  33. package/dist/system/ServiceContext.js.map +1 -1
  34. package/dist/util/config/types.d.ts +2 -2
  35. package/dist/util/utils.d.ts +13 -1
  36. package/dist/util/utils.js +20 -1
  37. package/dist/util/utils.js.map +1 -1
  38. package/package.json +7 -8
  39. package/src/entry/commands/compact-action.ts +19 -14
  40. package/src/entry/commands/migrate-action.ts +17 -4
  41. package/src/index.ts +1 -4
  42. package/src/migrations/PowerSyncMigrationManager.ts +42 -0
  43. package/src/migrations/ensure-automatic-migrations.ts +15 -0
  44. package/src/migrations/migrations-index.ts +2 -3
  45. package/src/storage/BucketStorage.ts +53 -1
  46. package/src/storage/bson.ts +78 -0
  47. package/src/storage/storage-index.ts +3 -15
  48. package/src/sync/sync.ts +3 -1
  49. package/src/system/ServiceContext.ts +17 -4
  50. package/src/util/config/types.ts +2 -2
  51. package/src/util/utils.ts +21 -1
  52. package/test/src/env.ts +0 -1
  53. package/tsconfig.tsbuildinfo +1 -1
  54. package/dist/db/db-index.d.ts +0 -1
  55. package/dist/db/db-index.js +0 -2
  56. package/dist/db/db-index.js.map +0 -1
  57. package/dist/db/mongo.d.ts +0 -35
  58. package/dist/db/mongo.js +0 -73
  59. package/dist/db/mongo.js.map +0 -1
  60. package/dist/locks/LockManager.d.ts +0 -10
  61. package/dist/locks/LockManager.js +0 -7
  62. package/dist/locks/LockManager.js.map +0 -1
  63. package/dist/locks/MongoLocks.d.ts +0 -36
  64. package/dist/locks/MongoLocks.js +0 -81
  65. package/dist/locks/MongoLocks.js.map +0 -1
  66. package/dist/locks/locks-index.d.ts +0 -2
  67. package/dist/locks/locks-index.js +0 -3
  68. package/dist/locks/locks-index.js.map +0 -1
  69. package/dist/migrations/db/migrations/1684951997326-init.d.ts +0 -3
  70. package/dist/migrations/db/migrations/1684951997326-init.js +0 -33
  71. package/dist/migrations/db/migrations/1684951997326-init.js.map +0 -1
  72. package/dist/migrations/db/migrations/1688556755264-initial-sync-rules.d.ts +0 -2
  73. package/dist/migrations/db/migrations/1688556755264-initial-sync-rules.js +0 -5
  74. package/dist/migrations/db/migrations/1688556755264-initial-sync-rules.js.map +0 -1
  75. package/dist/migrations/db/migrations/1702295701188-sync-rule-state.d.ts +0 -3
  76. package/dist/migrations/db/migrations/1702295701188-sync-rule-state.js +0 -56
  77. package/dist/migrations/db/migrations/1702295701188-sync-rule-state.js.map +0 -1
  78. package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.d.ts +0 -3
  79. package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.js +0 -29
  80. package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.js.map +0 -1
  81. package/dist/migrations/db/migrations/1727099539247-custom-write-checkpoint-index.d.ts +0 -3
  82. package/dist/migrations/db/migrations/1727099539247-custom-write-checkpoint-index.js +0 -31
  83. package/dist/migrations/db/migrations/1727099539247-custom-write-checkpoint-index.js.map +0 -1
  84. package/dist/migrations/definitions.d.ts +0 -18
  85. package/dist/migrations/definitions.js +0 -6
  86. package/dist/migrations/definitions.js.map +0 -1
  87. package/dist/migrations/executor.d.ts +0 -16
  88. package/dist/migrations/executor.js +0 -64
  89. package/dist/migrations/executor.js.map +0 -1
  90. package/dist/migrations/migrations.d.ts +0 -18
  91. package/dist/migrations/migrations.js +0 -110
  92. package/dist/migrations/migrations.js.map +0 -1
  93. package/dist/migrations/store/migration-store.d.ts +0 -11
  94. package/dist/migrations/store/migration-store.js +0 -46
  95. package/dist/migrations/store/migration-store.js.map +0 -1
  96. package/dist/storage/MongoBucketStorage.d.ts +0 -48
  97. package/dist/storage/MongoBucketStorage.js +0 -427
  98. package/dist/storage/MongoBucketStorage.js.map +0 -1
  99. package/dist/storage/mongo/MongoBucketBatch.d.ts +0 -74
  100. package/dist/storage/mongo/MongoBucketBatch.js +0 -683
  101. package/dist/storage/mongo/MongoBucketBatch.js.map +0 -1
  102. package/dist/storage/mongo/MongoCompactor.d.ts +0 -40
  103. package/dist/storage/mongo/MongoCompactor.js +0 -310
  104. package/dist/storage/mongo/MongoCompactor.js.map +0 -1
  105. package/dist/storage/mongo/MongoIdSequence.d.ts +0 -12
  106. package/dist/storage/mongo/MongoIdSequence.js +0 -21
  107. package/dist/storage/mongo/MongoIdSequence.js.map +0 -1
  108. package/dist/storage/mongo/MongoPersistedSyncRules.d.ts +0 -9
  109. package/dist/storage/mongo/MongoPersistedSyncRules.js +0 -9
  110. package/dist/storage/mongo/MongoPersistedSyncRules.js.map +0 -1
  111. package/dist/storage/mongo/MongoPersistedSyncRulesContent.d.ts +0 -20
  112. package/dist/storage/mongo/MongoPersistedSyncRulesContent.js +0 -26
  113. package/dist/storage/mongo/MongoPersistedSyncRulesContent.js.map +0 -1
  114. package/dist/storage/mongo/MongoStorageProvider.d.ts +0 -5
  115. package/dist/storage/mongo/MongoStorageProvider.js +0 -26
  116. package/dist/storage/mongo/MongoStorageProvider.js.map +0 -1
  117. package/dist/storage/mongo/MongoSyncBucketStorage.d.ts +0 -38
  118. package/dist/storage/mongo/MongoSyncBucketStorage.js +0 -534
  119. package/dist/storage/mongo/MongoSyncBucketStorage.js.map +0 -1
  120. package/dist/storage/mongo/MongoSyncRulesLock.d.ts +0 -16
  121. package/dist/storage/mongo/MongoSyncRulesLock.js +0 -65
  122. package/dist/storage/mongo/MongoSyncRulesLock.js.map +0 -1
  123. package/dist/storage/mongo/MongoWriteCheckpointAPI.d.ts +0 -20
  124. package/dist/storage/mongo/MongoWriteCheckpointAPI.js +0 -104
  125. package/dist/storage/mongo/MongoWriteCheckpointAPI.js.map +0 -1
  126. package/dist/storage/mongo/OperationBatch.d.ts +0 -35
  127. package/dist/storage/mongo/OperationBatch.js +0 -119
  128. package/dist/storage/mongo/OperationBatch.js.map +0 -1
  129. package/dist/storage/mongo/PersistedBatch.d.ts +0 -46
  130. package/dist/storage/mongo/PersistedBatch.js +0 -223
  131. package/dist/storage/mongo/PersistedBatch.js.map +0 -1
  132. package/dist/storage/mongo/config.d.ts +0 -19
  133. package/dist/storage/mongo/config.js +0 -26
  134. package/dist/storage/mongo/config.js.map +0 -1
  135. package/dist/storage/mongo/db.d.ts +0 -36
  136. package/dist/storage/mongo/db.js +0 -47
  137. package/dist/storage/mongo/db.js.map +0 -1
  138. package/dist/storage/mongo/models.d.ts +0 -163
  139. package/dist/storage/mongo/models.js +0 -27
  140. package/dist/storage/mongo/models.js.map +0 -1
  141. package/dist/storage/mongo/util.d.ts +0 -54
  142. package/dist/storage/mongo/util.js +0 -190
  143. package/dist/storage/mongo/util.js.map +0 -1
  144. package/src/db/db-index.ts +0 -1
  145. package/src/db/mongo.ts +0 -81
  146. package/src/locks/LockManager.ts +0 -16
  147. package/src/locks/MongoLocks.ts +0 -142
  148. package/src/locks/locks-index.ts +0 -2
  149. package/src/migrations/db/migrations/1684951997326-init.ts +0 -38
  150. package/src/migrations/db/migrations/1688556755264-initial-sync-rules.ts +0 -5
  151. package/src/migrations/db/migrations/1702295701188-sync-rule-state.ts +0 -102
  152. package/src/migrations/db/migrations/1711543888062-write-checkpoint-index.ts +0 -34
  153. package/src/migrations/db/migrations/1727099539247-custom-write-checkpoint-index.ts +0 -37
  154. package/src/migrations/definitions.ts +0 -21
  155. package/src/migrations/executor.ts +0 -87
  156. package/src/migrations/migrations.ts +0 -142
  157. package/src/migrations/store/migration-store.ts +0 -63
  158. package/src/storage/MongoBucketStorage.ts +0 -541
  159. package/src/storage/mongo/MongoBucketBatch.ts +0 -900
  160. package/src/storage/mongo/MongoCompactor.ts +0 -393
  161. package/src/storage/mongo/MongoIdSequence.ts +0 -24
  162. package/src/storage/mongo/MongoPersistedSyncRules.ts +0 -16
  163. package/src/storage/mongo/MongoPersistedSyncRulesContent.ts +0 -50
  164. package/src/storage/mongo/MongoStorageProvider.ts +0 -31
  165. package/src/storage/mongo/MongoSyncBucketStorage.ts +0 -640
  166. package/src/storage/mongo/MongoSyncRulesLock.ts +0 -85
  167. package/src/storage/mongo/MongoWriteCheckpointAPI.ts +0 -154
  168. package/src/storage/mongo/OperationBatch.ts +0 -131
  169. package/src/storage/mongo/PersistedBatch.ts +0 -285
  170. package/src/storage/mongo/config.ts +0 -40
  171. package/src/storage/mongo/db.ts +0 -88
  172. package/src/storage/mongo/models.ts +0 -187
  173. package/src/storage/mongo/util.ts +0 -203
  174. package/test/src/__snapshots__/sync.test.ts.snap +0 -332
  175. package/test/src/bucket_validation.test.ts +0 -143
  176. package/test/src/bucket_validation.ts +0 -60
  177. package/test/src/compacting.test.ts +0 -295
  178. package/test/src/data_storage.test.ts +0 -1569
  179. package/test/src/stream_utils.ts +0 -42
  180. package/test/src/sync.test.ts +0 -511
  181. package/test/src/util.ts +0 -150
@@ -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 './definitions.js';
2
- export * from './executor.js';
3
- export * from './migrations.js';
1
+ export * from './ensure-automatic-migrations.js';
2
+ export * from './PowerSyncMigrationManager.js';
@@ -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, ReplicaId } from './storage-index.js';
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>;
@@ -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 './MongoBucketStorage.js';
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
- // Data is a raw string - we can use the more efficient JSON.stringify.
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
  };
@@ -1,6 +1,8 @@
1
- import { LifeCycledSystem, ServiceIdentifier, container } from '@powersync/lib-services-framework';
1
+ import { LifeCycledSystem, MigrationManager, ServiceIdentifier, container } from '@powersync/lib-services-framework';
2
2
 
3
+ import { framework } from '../index.js';
3
4
  import * as metrics from '../metrics/Metrics.js';
5
+ import { PowerSyncMigrationManager } from '../migrations/PowerSyncMigrationManager.js';
4
6
  import * as replication from '../replication/replication-index.js';
5
7
  import * as routes from '../routes/routes-index.js';
6
8
  import * as storage from '../storage/storage-index.js';
@@ -13,6 +15,7 @@ export interface ServiceContext {
13
15
  replicationEngine: replication.ReplicationEngine | null;
14
16
  routerEngine: routes.RouterEngine | null;
15
17
  storageEngine: storage.StorageEngine;
18
+ migrations: PowerSyncMigrationManager;
16
19
  }
17
20
 
18
21
  /**
@@ -30,13 +33,19 @@ export class ServiceContextContainer implements ServiceContext {
30
33
  this.storageEngine = new storage.StorageEngine({
31
34
  configuration
32
35
  });
36
+
37
+ const migrationManager = new MigrationManager();
38
+ container.register(framework.ContainerImplementation.MIGRATION_MANAGER, migrationManager);
39
+
40
+ this.lifeCycleEngine.withLifecycle(migrationManager, {
41
+ // Migrations should be executed before the system starts
42
+ start: () => migrationManager[Symbol.asyncDispose]()
43
+ });
44
+
33
45
  this.lifeCycleEngine.withLifecycle(this.storageEngine, {
34
46
  start: (storageEngine) => storageEngine.start(),
35
47
  stop: (storageEngine) => storageEngine.shutDown()
36
48
  });
37
-
38
- // Mongo storage is available as an option by default TODO: Consider moving this to a Mongo Storage Module
39
- this.storageEngine.registerProvider(new storage.MongoStorageProvider());
40
49
  }
41
50
 
42
51
  get replicationEngine(): replication.ReplicationEngine | null {
@@ -51,6 +60,10 @@ export class ServiceContextContainer implements ServiceContext {
51
60
  return container.getOptional(metrics.Metrics);
52
61
  }
53
62
 
63
+ get migrations(): PowerSyncMigrationManager {
64
+ return container.getImplementation(framework.ContainerImplementation.MIGRATION_MANAGER);
65
+ }
66
+
54
67
  /**
55
68
  * Allows for registering core and generic implementations of services/helpers.
56
69
  * This uses the framework container under the hood.
@@ -30,8 +30,8 @@ export type SyncRulesConfig = {
30
30
 
31
31
  export type ResolvedPowerSyncConfig = {
32
32
  base_config: PowerSyncConfig;
33
- connections?: configFile.DataSourceConfig[];
34
- storage: configFile.StorageConfig;
33
+ connections?: configFile.GenericDataSourceConfig[];
34
+ storage: configFile.GenericStorageConfig;
35
35
  dev: {
36
36
  demo_auth: boolean;
37
37
  demo_password?: string;
package/src/util/utils.ts CHANGED
@@ -131,7 +131,16 @@ export function hasToastedValues(row: sync_rules.ToastableSqliteRow) {
131
131
  return false;
132
132
  }
133
133
 
134
- export function isCompleteRow(row: sync_rules.ToastableSqliteRow): row is sync_rules.SqliteRow {
134
+ /**
135
+ * Returns true if we have a complete row.
136
+ *
137
+ * If we don't store data, we assume we always have a complete row.
138
+ */
139
+ export function isCompleteRow(storeData: boolean, row: sync_rules.ToastableSqliteRow): row is sync_rules.SqliteRow {
140
+ if (!storeData) {
141
+ // Assume the row is complete - no need to check
142
+ return true;
143
+ }
135
144
  return !hasToastedValues(row);
136
145
  }
137
146
 
@@ -199,6 +208,17 @@ export function reduceBucket(operations: OplogEntry[]) {
199
208
  return finalState;
200
209
  }
201
210
 
211
+ /**
212
+ * Flattens string to reduce memory usage (around 320 bytes -> 120 bytes),
213
+ * at the cost of some upfront CPU usage.
214
+ *
215
+ * From: https://github.com/davidmarkclements/flatstr/issues/8
216
+ */
217
+ export function flatstr(s: string) {
218
+ s.match(/\n/g);
219
+ return s;
220
+ }
221
+
202
222
  function rowKey(entry: OplogEntry) {
203
223
  return `${entry.object_type}/${entry.object_id}/${entry.subkey}`;
204
224
  }
package/test/src/env.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { utils } from '@powersync/lib-services-framework';
2
2
 
3
3
  export const env = utils.collectEnvironmentVariables({
4
- MONGO_TEST_URL: utils.type.string.default('mongodb://localhost:27017/powersync_test'),
5
4
  CI: utils.type.boolean.default('false')
6
5
  });