@powersync/service-core 0.0.0-dev-20241021151922 → 0.0.0-dev-20241021184609

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 (47) hide show
  1. package/CHANGELOG.md +5 -5
  2. package/dist/routes/endpoints/checkpointing.js +14 -82
  3. package/dist/routes/endpoints/checkpointing.js.map +1 -1
  4. package/dist/storage/BucketStorage.d.ts +3 -4
  5. package/dist/storage/BucketStorage.js.map +1 -1
  6. package/dist/storage/MongoBucketStorage.d.ts +8 -0
  7. package/dist/storage/MongoBucketStorage.js +21 -4
  8. package/dist/storage/MongoBucketStorage.js.map +1 -1
  9. package/dist/storage/StorageEngine.d.ts +5 -1
  10. package/dist/storage/StorageEngine.js +19 -1
  11. package/dist/storage/StorageEngine.js.map +1 -1
  12. package/dist/storage/StorageProvider.d.ts +8 -1
  13. package/dist/storage/mongo/MongoBucketBatch.d.ts +2 -2
  14. package/dist/storage/mongo/MongoBucketBatch.js.map +1 -1
  15. package/dist/storage/mongo/MongoStorageProvider.js +2 -1
  16. package/dist/storage/mongo/MongoStorageProvider.js.map +1 -1
  17. package/dist/storage/mongo/MongoSyncBucketStorage.d.ts +1 -9
  18. package/dist/storage/mongo/MongoSyncBucketStorage.js +4 -33
  19. package/dist/storage/mongo/MongoSyncBucketStorage.js.map +1 -1
  20. package/dist/storage/mongo/MongoWriteCheckpointAPI.d.ts +2 -4
  21. package/dist/storage/mongo/MongoWriteCheckpointAPI.js +7 -13
  22. package/dist/storage/mongo/MongoWriteCheckpointAPI.js.map +1 -1
  23. package/dist/storage/storage-index.d.ts +2 -2
  24. package/dist/storage/storage-index.js +2 -2
  25. package/dist/storage/storage-index.js.map +1 -1
  26. package/dist/storage/{WriteCheckpointAPI.d.ts → write-checkpoint.d.ts} +9 -28
  27. package/dist/storage/{WriteCheckpointAPI.js → write-checkpoint.js} +1 -1
  28. package/dist/storage/write-checkpoint.js.map +1 -0
  29. package/dist/util/config/compound-config-collector.js +1 -2
  30. package/dist/util/config/compound-config-collector.js.map +1 -1
  31. package/dist/util/config/types.d.ts +0 -1
  32. package/package.json +5 -5
  33. package/src/routes/endpoints/checkpointing.ts +1 -8
  34. package/src/storage/BucketStorage.ts +5 -6
  35. package/src/storage/MongoBucketStorage.ts +38 -6
  36. package/src/storage/StorageEngine.ts +24 -2
  37. package/src/storage/StorageProvider.ts +9 -1
  38. package/src/storage/mongo/MongoBucketBatch.ts +2 -2
  39. package/src/storage/mongo/MongoStorageProvider.ts +2 -1
  40. package/src/storage/mongo/MongoSyncBucketStorage.ts +4 -49
  41. package/src/storage/mongo/MongoWriteCheckpointAPI.ts +8 -16
  42. package/src/storage/storage-index.ts +2 -2
  43. package/src/storage/{WriteCheckpointAPI.ts → write-checkpoint.ts} +12 -30
  44. package/src/util/config/compound-config-collector.ts +1 -2
  45. package/src/util/config/types.ts +0 -1
  46. package/tsconfig.tsbuildinfo +1 -1
  47. package/dist/storage/WriteCheckpointAPI.js.map +0 -1
@@ -12,7 +12,7 @@ import {
12
12
  SaveOptions
13
13
  } from '../BucketStorage.js';
14
14
  import { SourceTable } from '../SourceTable.js';
15
- import { BatchedCustomWriteCheckpointOptions, CustomWriteCheckpointOptions } from '../WriteCheckpointAPI.js';
15
+ import { CustomWriteCheckpointOptions } from '../write-checkpoint.js';
16
16
  import { PowerSyncMongo } from './db.js';
17
17
  import { CurrentBucket, CurrentDataDocument, SourceKey, SyncRuleDocument } from './models.js';
18
18
  import { MongoIdSequence } from './MongoIdSequence.js';
@@ -83,7 +83,7 @@ export class MongoBucketBatch extends DisposableObserver<BucketBatchStorageListe
83
83
  this.sync_rules = sync_rules;
84
84
  }
85
85
 
86
- addCustomWriteCheckpoint(checkpoint: BatchedCustomWriteCheckpointOptions): void {
86
+ addCustomWriteCheckpoint(checkpoint: CustomWriteCheckpointOptions): void {
87
87
  this.write_checkpoint_batch.push({
88
88
  ...checkpoint,
89
89
  sync_rules_id: this.group_id
@@ -19,7 +19,8 @@ export class MongoStorageProvider implements BucketStorageProvider {
19
19
  return {
20
20
  storage: new MongoBucketStorage(database, {
21
21
  // TODO currently need the entire resolved config due to this
22
- slot_name_prefix: resolvedConfig.slot_name_prefix
22
+ slot_name_prefix: resolvedConfig.slot_name_prefix,
23
+ write_checkpoint_mode: options.writeCheckpointMode
23
24
  }),
24
25
  shutDown: () => client.close(),
25
26
  tearDown: () => {
@@ -2,8 +2,7 @@ import { SqliteJsonRow, SqliteJsonValue, SqlSyncRules } from '@powersync/service
2
2
  import * as bson from 'bson';
3
3
  import * as mongo from 'mongodb';
4
4
 
5
- import { DisposableObserver, logger } from '@powersync/lib-services-framework';
6
- import * as timers from 'timers/promises';
5
+ import { DisposableObserver } from '@powersync/lib-services-framework';
7
6
  import * as db from '../../db/db-index.js';
8
7
  import * as util from '../../util/util-index.js';
9
8
  import {
@@ -27,19 +26,13 @@ import {
27
26
  import { ChecksumCache, FetchPartialBucketChecksum, PartialChecksum, PartialChecksumMap } from '../ChecksumCache.js';
28
27
  import { MongoBucketStorage } from '../MongoBucketStorage.js';
29
28
  import { SourceTable } from '../SourceTable.js';
30
- import {
31
- BatchedCustomWriteCheckpointOptions,
32
- ManagedWriteCheckpointOptions,
33
- SyncStorageLastWriteCheckpointFilters,
34
- WriteCheckpointAPI,
35
- WriteCheckpointMode
36
- } from '../WriteCheckpointAPI.js';
37
29
  import { PowerSyncMongo } from './db.js';
38
30
  import { BucketDataDocument, BucketDataKey, SourceKey, SyncRuleState } from './models.js';
39
31
  import { MongoBucketBatch } from './MongoBucketBatch.js';
40
32
  import { MongoCompactor } from './MongoCompactor.js';
41
- import { MongoWriteCheckpointAPI } from './MongoWriteCheckpointAPI.js';
42
33
  import { BSON_DESERIALIZE_OPTIONS, idPrefixFilter, mapOpEntry, readSingleBatch, serializeLookup } from './util.js';
34
+ import { logger } from '@powersync/lib-services-framework';
35
+ import * as timers from 'timers/promises';
43
36
 
44
37
  export class MongoSyncBucketStorage
45
38
  extends DisposableObserver<SyncRulesBucketStorageListener>
@@ -53,53 +46,15 @@ export class MongoSyncBucketStorage
53
46
  });
54
47
 
55
48
  private parsedSyncRulesCache: SqlSyncRules | undefined;
56
- private writeCheckpointAPI: WriteCheckpointAPI;
57
49
 
58
50
  constructor(
59
51
  public readonly factory: MongoBucketStorage,
60
52
  public readonly group_id: number,
61
53
  private readonly sync_rules: PersistedSyncRulesContent,
62
- public readonly slot_name: string,
63
- writeCheckpointMode: WriteCheckpointMode = WriteCheckpointMode.MANAGED
54
+ public readonly slot_name: string
64
55
  ) {
65
56
  super();
66
57
  this.db = factory.db;
67
- this.writeCheckpointAPI = new MongoWriteCheckpointAPI({
68
- db: this.db,
69
- mode: writeCheckpointMode
70
- });
71
- }
72
-
73
- get writeCheckpointMode() {
74
- return this.writeCheckpointAPI.writeCheckpointMode;
75
- }
76
-
77
- setWriteCheckpointMode(mode: WriteCheckpointMode): void {
78
- this.writeCheckpointAPI.setWriteCheckpointMode(mode);
79
- }
80
-
81
- batchCreateCustomWriteCheckpoints(checkpoints: BatchedCustomWriteCheckpointOptions[]): Promise<void> {
82
- return this.writeCheckpointAPI.batchCreateCustomWriteCheckpoints(
83
- checkpoints.map((checkpoint) => ({ ...checkpoint, sync_rules_id: this.group_id }))
84
- );
85
- }
86
-
87
- createCustomWriteCheckpoint(checkpoint: BatchedCustomWriteCheckpointOptions): Promise<bigint> {
88
- return this.writeCheckpointAPI.createCustomWriteCheckpoint({
89
- ...checkpoint,
90
- sync_rules_id: this.group_id
91
- });
92
- }
93
-
94
- createManagedWriteCheckpoint(checkpoint: ManagedWriteCheckpointOptions): Promise<bigint> {
95
- return this.writeCheckpointAPI.createManagedWriteCheckpoint(checkpoint);
96
- }
97
-
98
- lastWriteCheckpoint(filters: SyncStorageLastWriteCheckpointFilters): Promise<bigint | null> {
99
- return this.writeCheckpointAPI.lastWriteCheckpoint({
100
- ...filters,
101
- sync_rules_id: this.group_id
102
- });
103
58
  }
104
59
 
105
60
  getParsedSyncRules(options: ParseSyncRulesOptions): SqlSyncRules {
@@ -7,7 +7,7 @@ import {
7
7
  ManagedWriteCheckpointOptions,
8
8
  WriteCheckpointAPI,
9
9
  WriteCheckpointMode
10
- } from '../WriteCheckpointAPI.js';
10
+ } from '../write-checkpoint.js';
11
11
  import { PowerSyncMongo } from './db.js';
12
12
 
13
13
  export type MongoCheckpointAPIOptions = {
@@ -17,19 +17,11 @@ export type MongoCheckpointAPIOptions = {
17
17
 
18
18
  export class MongoWriteCheckpointAPI implements WriteCheckpointAPI {
19
19
  readonly db: PowerSyncMongo;
20
- private _mode: WriteCheckpointMode;
20
+ readonly mode: WriteCheckpointMode;
21
21
 
22
22
  constructor(options: MongoCheckpointAPIOptions) {
23
23
  this.db = options.db;
24
- this._mode = options.mode;
25
- }
26
-
27
- get writeCheckpointMode() {
28
- return this._mode;
29
- }
30
-
31
- setWriteCheckpointMode(mode: WriteCheckpointMode): void {
32
- this._mode = mode;
24
+ this.mode = options.mode;
33
25
  }
34
26
 
35
27
  async batchCreateCustomWriteCheckpoints(checkpoints: CustomWriteCheckpointOptions[]): Promise<void> {
@@ -37,9 +29,9 @@ export class MongoWriteCheckpointAPI implements WriteCheckpointAPI {
37
29
  }
38
30
 
39
31
  async createCustomWriteCheckpoint(options: CustomWriteCheckpointOptions): Promise<bigint> {
40
- if (this.writeCheckpointMode !== WriteCheckpointMode.CUSTOM) {
32
+ if (this.mode !== WriteCheckpointMode.CUSTOM) {
41
33
  throw new framework.errors.ValidationError(
42
- `Creating a custom Write Checkpoint when the current Write Checkpoint mode is set to "${this.writeCheckpointMode}"`
34
+ `Creating a custom Write Checkpoint when the current Write Checkpoint mode is set to "${this.mode}"`
43
35
  );
44
36
  }
45
37
 
@@ -60,9 +52,9 @@ export class MongoWriteCheckpointAPI implements WriteCheckpointAPI {
60
52
  }
61
53
 
62
54
  async createManagedWriteCheckpoint(checkpoint: ManagedWriteCheckpointOptions): Promise<bigint> {
63
- if (this.writeCheckpointMode !== WriteCheckpointMode.MANAGED) {
55
+ if (this.mode !== WriteCheckpointMode.MANAGED) {
64
56
  throw new framework.errors.ValidationError(
65
- `Attempting to create a managed Write Checkpoint when the current Write Checkpoint mode is set to "${this.writeCheckpointMode}"`
57
+ `Creating a managed Write Checkpoint when the current Write Checkpoint mode is set to "${this.mode}"`
66
58
  );
67
59
  }
68
60
 
@@ -85,7 +77,7 @@ export class MongoWriteCheckpointAPI implements WriteCheckpointAPI {
85
77
  }
86
78
 
87
79
  async lastWriteCheckpoint(filters: LastWriteCheckpointFilters): Promise<bigint | null> {
88
- switch (this.writeCheckpointMode) {
80
+ switch (this.mode) {
89
81
  case WriteCheckpointMode.CUSTOM:
90
82
  if (false == 'sync_rules_id' in filters) {
91
83
  throw new framework.errors.ValidationError(`Sync rules ID is required for custom Write Checkpoint filtering`);
@@ -5,7 +5,6 @@ export * from './SourceEntity.js';
5
5
  export * from './SourceTable.js';
6
6
  export * from './StorageEngine.js';
7
7
 
8
- export * from './mongo/config.js';
9
8
  export * from './mongo/db.js';
10
9
  export * from './mongo/models.js';
11
10
  export * from './mongo/MongoBucketBatch.js';
@@ -18,4 +17,5 @@ export * from './mongo/MongoSyncRulesLock.js';
18
17
  export * from './mongo/OperationBatch.js';
19
18
  export * from './mongo/PersistedBatch.js';
20
19
  export * from './mongo/util.js';
21
- export * from './WriteCheckpointAPI.js';
20
+ export * from './mongo/config.js';
21
+ export * from './write-checkpoint.js';
@@ -26,19 +26,19 @@ export interface CustomWriteCheckpointFilters extends BaseWriteCheckpointIdentif
26
26
  sync_rules_id: number;
27
27
  }
28
28
 
29
- export interface BatchedCustomWriteCheckpointOptions extends BaseWriteCheckpointIdentifier {
29
+ export interface CustomWriteCheckpointOptions extends CustomWriteCheckpointFilters {
30
30
  /**
31
31
  * A supplied incrementing Write Checkpoint number
32
32
  */
33
33
  checkpoint: bigint;
34
34
  }
35
35
 
36
- export interface CustomWriteCheckpointOptions extends BatchedCustomWriteCheckpointOptions {
37
- /**
38
- * Sync rules which were active when this checkpoint was created.
39
- */
40
- sync_rules_id: number;
41
- }
36
+ /**
37
+ * Options for creating a custom Write Checkpoint in a batch.
38
+ * A {@link BucketStorageBatch} is already associated with a Sync Rules instance.
39
+ * The `sync_rules_id` is not required here.
40
+ */
41
+ export type BatchedCustomWriteCheckpointOptions = Omit<CustomWriteCheckpointOptions, 'sync_rules_id'>;
42
42
 
43
43
  /**
44
44
  * Managed Write Checkpoints are a mapping of User ID to replication HEAD
@@ -52,33 +52,15 @@ export interface ManagedWriteCheckpointFilters extends BaseWriteCheckpointIdenti
52
52
 
53
53
  export type ManagedWriteCheckpointOptions = ManagedWriteCheckpointFilters;
54
54
 
55
- export type SyncStorageLastWriteCheckpointFilters = BaseWriteCheckpointIdentifier | ManagedWriteCheckpointFilters;
56
55
  export type LastWriteCheckpointFilters = CustomWriteCheckpointFilters | ManagedWriteCheckpointFilters;
57
56
 
58
- export interface BaseWriteCheckpointAPI {
59
- readonly writeCheckpointMode: WriteCheckpointMode;
60
- setWriteCheckpointMode(mode: WriteCheckpointMode): void;
61
- createManagedWriteCheckpoint(checkpoint: ManagedWriteCheckpointOptions): Promise<bigint>;
62
- }
63
-
64
- /**
65
- * Write Checkpoint API to be used in conjunction with a {@link SyncRulesBucketStorage}.
66
- * This storage corresponds with a set of sync rules. These APIs don't require specifying a
67
- * sync rules id.
68
- */
69
- export interface SyncStorageWriteCheckpointAPI extends BaseWriteCheckpointAPI {
70
- batchCreateCustomWriteCheckpoints(checkpoints: BatchedCustomWriteCheckpointOptions[]): Promise<void>;
71
- createCustomWriteCheckpoint(checkpoint: BatchedCustomWriteCheckpointOptions): Promise<bigint>;
72
- lastWriteCheckpoint(filters: SyncStorageLastWriteCheckpointFilters): Promise<bigint | null>;
73
- }
74
-
75
- /**
76
- * Write Checkpoint API which is interfaced directly with the storage layer. This requires
77
- * sync rules identifiers for custom write checkpoints.
78
- */
79
- export interface WriteCheckpointAPI extends BaseWriteCheckpointAPI {
57
+ export interface WriteCheckpointAPI {
80
58
  batchCreateCustomWriteCheckpoints(checkpoints: CustomWriteCheckpointOptions[]): Promise<void>;
59
+
81
60
  createCustomWriteCheckpoint(checkpoint: CustomWriteCheckpointOptions): Promise<bigint>;
61
+
62
+ createManagedWriteCheckpoint(checkpoint: ManagedWriteCheckpointOptions): Promise<bigint>;
63
+
82
64
  lastWriteCheckpoint(filters: LastWriteCheckpointFilters): Promise<bigint | null>;
83
65
  }
84
66
 
@@ -122,8 +122,7 @@ export class CompoundConfigCollector {
122
122
  },
123
123
  // TODO maybe move this out of the connection or something
124
124
  // slot_name_prefix: connections[0]?.slot_name_prefix ?? 'powersync_'
125
- slot_name_prefix: 'powersync_',
126
- parameters: baseConfig.parameters ?? {}
125
+ slot_name_prefix: 'powersync_'
127
126
  };
128
127
 
129
128
  return config;
@@ -64,5 +64,4 @@ export type ResolvedPowerSyncConfig = {
64
64
 
65
65
  /** Prefix for postgres replication slot names. May eventually be connection-specific. */
66
66
  slot_name_prefix: string;
67
- parameters: Record<string, number | string | boolean | null>;
68
67
  };