@powersync/service-core 0.8.5 → 0.8.7

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.
@@ -1294,4 +1294,26 @@ bucket_definitions:
1294
1294
 
1295
1295
  expect(getBatchMeta(batch3)).toEqual(null);
1296
1296
  });
1297
+
1298
+ test('empty storage metrics', async () => {
1299
+ const f = await factory({ dropAll: true });
1300
+
1301
+ const metrics = await f.getStorageMetrics();
1302
+ expect(metrics).toEqual({
1303
+ operations_size_bytes: 0,
1304
+ parameters_size_bytes: 0,
1305
+ replication_size_bytes: 0
1306
+ });
1307
+
1308
+ const r = await f.configureSyncRules('bucket_definitions: {}');
1309
+ const storage = f.getInstance(r.persisted_sync_rules!.parsed());
1310
+ await storage.autoActivate();
1311
+
1312
+ const metrics2 = await f.getStorageMetrics();
1313
+ expect(metrics2).toEqual({
1314
+ operations_size_bytes: 0,
1315
+ parameters_size_bytes: 0,
1316
+ replication_size_bytes: 0
1317
+ });
1318
+ });
1297
1319
  }
@@ -5,7 +5,6 @@ import { JSONBig } from '@powersync/service-jsonbig';
5
5
  import { RequestParameters } from '@powersync/service-sync-rules';
6
6
  import * as timers from 'timers/promises';
7
7
  import { describe, expect, test } from 'vitest';
8
- import { ZERO_LSN } from '../../src/replication/WalStream.js';
9
8
  import { streamResponse } from '../../src/sync/sync.js';
10
9
  import { makeTestTable, MONGO_STORAGE_FACTORY, StorageFactory } from './util.js';
11
10
 
@@ -33,7 +32,6 @@ function defineTests(factory: StorageFactory) {
33
32
  });
34
33
 
35
34
  const storage = await f.getInstance(syncRules.parsed());
36
- await storage.setSnapshotDone(ZERO_LSN);
37
35
  await storage.autoActivate();
38
36
 
39
37
  const result = await storage.startBatch({}, async (batch) => {
@@ -82,7 +80,6 @@ function defineTests(factory: StorageFactory) {
82
80
  });
83
81
 
84
82
  const storage = await f.getInstance(syncRules.parsed());
85
- await storage.setSnapshotDone(ZERO_LSN);
86
83
  await storage.autoActivate();
87
84
 
88
85
  const result = await storage.startBatch({}, async (batch) => {
@@ -125,7 +122,6 @@ function defineTests(factory: StorageFactory) {
125
122
  });
126
123
 
127
124
  const storage = await f.getInstance(syncRules.parsed());
128
- await storage.setSnapshotDone(ZERO_LSN);
129
125
  await storage.autoActivate();
130
126
 
131
127
  const stream = streamResponse({
@@ -152,7 +148,6 @@ function defineTests(factory: StorageFactory) {
152
148
  });
153
149
 
154
150
  const storage = await f.getInstance(syncRules.parsed());
155
- await storage.setSnapshotDone(ZERO_LSN);
156
151
  await storage.autoActivate();
157
152
 
158
153
  const stream = streamResponse({
@@ -211,7 +206,6 @@ function defineTests(factory: StorageFactory) {
211
206
  });
212
207
 
213
208
  const storage = await f.getInstance(syncRules.parsed());
214
- await storage.setSnapshotDone(ZERO_LSN);
215
209
  await storage.autoActivate();
216
210
 
217
211
  const exp = Date.now() / 1000 + 0.1;
@@ -249,7 +243,6 @@ function defineTests(factory: StorageFactory) {
249
243
  });
250
244
 
251
245
  const storage = await f.getInstance(syncRules.parsed());
252
- await storage.setSnapshotDone(ZERO_LSN);
253
246
  await storage.autoActivate();
254
247
 
255
248
  await storage.startBatch({}, async (batch) => {
package/test/src/util.ts CHANGED
@@ -22,11 +22,22 @@ Metrics.getInstance().resetCounters();
22
22
 
23
23
  export const TEST_URI = env.PG_TEST_URL;
24
24
 
25
- export type StorageFactory = () => Promise<BucketStorageFactory>;
25
+ export interface StorageOptions {
26
+ /**
27
+ * By default, collections are only cleared/
28
+ * Setting this to true will drop the collections completely.
29
+ */
30
+ dropAll?: boolean;
31
+ }
32
+ export type StorageFactory = (options?: StorageOptions) => Promise<BucketStorageFactory>;
26
33
 
27
- export const MONGO_STORAGE_FACTORY: StorageFactory = async () => {
34
+ export const MONGO_STORAGE_FACTORY: StorageFactory = async (options?: StorageOptions) => {
28
35
  const db = await connectMongo();
29
- await db.clear();
36
+ if (options?.dropAll) {
37
+ await db.drop();
38
+ } else {
39
+ await db.clear();
40
+ }
30
41
  return new MongoBucketStorage(db, { slot_name_prefix: 'test_' });
31
42
  };
32
43