@powersync/service-core 1.12.0 → 1.13.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 (91) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/api/RouteAPI.d.ts +1 -5
  3. package/dist/api/diagnostics.js +1 -1
  4. package/dist/api/diagnostics.js.map +1 -1
  5. package/dist/entry/cli-entry.js +2 -2
  6. package/dist/entry/cli-entry.js.map +1 -1
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.js +1 -0
  9. package/dist/index.js.map +1 -1
  10. package/dist/metrics/open-telemetry/OpenTelemetryMetricsFactory.d.ts +1 -1
  11. package/dist/metrics/open-telemetry/OpenTelemetryMetricsFactory.js.map +1 -1
  12. package/dist/replication/AbstractReplicationJob.d.ts +4 -0
  13. package/dist/replication/AbstractReplicationJob.js.map +1 -1
  14. package/dist/replication/AbstractReplicator.d.ts +25 -1
  15. package/dist/replication/AbstractReplicator.js +53 -3
  16. package/dist/replication/AbstractReplicator.js.map +1 -1
  17. package/dist/replication/RelationCache.d.ts +9 -0
  18. package/dist/replication/RelationCache.js +20 -0
  19. package/dist/replication/RelationCache.js.map +1 -0
  20. package/dist/replication/replication-index.d.ts +1 -0
  21. package/dist/replication/replication-index.js +1 -0
  22. package/dist/replication/replication-index.js.map +1 -1
  23. package/dist/replication/replication-metrics.js +6 -0
  24. package/dist/replication/replication-metrics.js.map +1 -1
  25. package/dist/routes/endpoints/admin.js +2 -0
  26. package/dist/routes/endpoints/admin.js.map +1 -1
  27. package/dist/routes/endpoints/sync-rules.js +6 -6
  28. package/dist/routes/endpoints/sync-rules.js.map +1 -1
  29. package/dist/storage/BucketStorageBatch.d.ts +21 -3
  30. package/dist/storage/BucketStorageBatch.js +2 -1
  31. package/dist/storage/BucketStorageBatch.js.map +1 -1
  32. package/dist/storage/PersistedSyncRulesContent.d.ts +5 -0
  33. package/dist/storage/SourceTable.d.ts +17 -1
  34. package/dist/storage/SourceTable.js +28 -0
  35. package/dist/storage/SourceTable.js.map +1 -1
  36. package/dist/storage/StorageEngine.d.ts +3 -2
  37. package/dist/storage/StorageEngine.js +3 -0
  38. package/dist/storage/StorageEngine.js.map +1 -1
  39. package/dist/storage/StorageProvider.d.ts +2 -0
  40. package/dist/storage/SyncRulesBucketStorage.d.ts +18 -6
  41. package/dist/storage/SyncRulesBucketStorage.js.map +1 -1
  42. package/dist/storage/WriteCheckpointAPI.d.ts +0 -26
  43. package/dist/storage/WriteCheckpointAPI.js.map +1 -1
  44. package/dist/storage/bson.js +4 -1
  45. package/dist/storage/bson.js.map +1 -1
  46. package/dist/streams/BroadcastIterable.d.ts +1 -1
  47. package/dist/streams/streams-index.d.ts +0 -1
  48. package/dist/streams/streams-index.js +0 -1
  49. package/dist/streams/streams-index.js.map +1 -1
  50. package/dist/sync/BucketChecksumState.js +2 -2
  51. package/dist/sync/BucketChecksumState.js.map +1 -1
  52. package/dist/sync/sync.js +2 -2
  53. package/dist/sync/sync.js.map +1 -1
  54. package/dist/system/ServiceContext.js +6 -0
  55. package/dist/system/ServiceContext.js.map +1 -1
  56. package/dist/util/protocol-types.d.ts +9 -9
  57. package/dist/util/protocol-types.js.map +1 -1
  58. package/dist/util/utils.d.ts +1 -1
  59. package/package.json +5 -5
  60. package/src/api/RouteAPI.ts +1 -6
  61. package/src/api/diagnostics.ts +1 -1
  62. package/src/entry/cli-entry.ts +2 -2
  63. package/src/index.ts +2 -0
  64. package/src/metrics/open-telemetry/OpenTelemetryMetricsFactory.ts +3 -3
  65. package/src/replication/AbstractReplicationJob.ts +5 -0
  66. package/src/replication/AbstractReplicator.ts +56 -3
  67. package/src/replication/RelationCache.ts +25 -0
  68. package/src/replication/replication-index.ts +1 -0
  69. package/src/replication/replication-metrics.ts +7 -0
  70. package/src/routes/endpoints/admin.ts +2 -0
  71. package/src/routes/endpoints/sync-rules.ts +6 -6
  72. package/src/storage/BucketStorageBatch.ts +26 -4
  73. package/src/storage/PersistedSyncRulesContent.ts +6 -0
  74. package/src/storage/SourceTable.ts +44 -1
  75. package/src/storage/StorageEngine.ts +6 -2
  76. package/src/storage/StorageProvider.ts +3 -0
  77. package/src/storage/SyncRulesBucketStorage.ts +22 -6
  78. package/src/storage/WriteCheckpointAPI.ts +0 -30
  79. package/src/storage/bson.ts +4 -1
  80. package/src/streams/BroadcastIterable.ts +1 -1
  81. package/src/streams/streams-index.ts +0 -1
  82. package/src/sync/BucketChecksumState.ts +2 -2
  83. package/src/sync/sync.ts +3 -3
  84. package/src/system/ServiceContext.ts +6 -0
  85. package/src/util/protocol-types.ts +15 -10
  86. package/tsconfig.tsbuildinfo +1 -1
  87. package/dist/streams/Demultiplexer.d.ts +0 -52
  88. package/dist/streams/Demultiplexer.js +0 -128
  89. package/dist/streams/Demultiplexer.js.map +0 -1
  90. package/src/streams/Demultiplexer.ts +0 -165
  91. package/test/src/demultiplexer.test.ts +0 -205
package/src/sync/sync.ts CHANGED
@@ -93,7 +93,7 @@ async function* streamResponseInner(
93
93
  ): AsyncGenerator<util.StreamingSyncLine | string | null> {
94
94
  const { raw_data, binary_data } = params;
95
95
 
96
- const checkpointUserId = util.checkpointUserId(syncParams.token_parameters.user_id as string, params.client_id);
96
+ const checkpointUserId = util.checkpointUserId(syncParams.tokenParameters.user_id as string, params.client_id);
97
97
 
98
98
  const checksumState = new BucketChecksumState({
99
99
  syncContext,
@@ -228,7 +228,7 @@ async function* streamResponseInner(
228
228
  onRowsSent: markOperationsSent,
229
229
  abort_connection: signal,
230
230
  abort_batch: abortCheckpointSignal,
231
- user_id: syncParams.user_id,
231
+ user_id: syncParams.userId,
232
232
  // Passing null here will emit a full sync complete message at the end. If we pass a priority, we'll emit a partial
233
233
  // sync complete message instead.
234
234
  forPriority: !isLast ? priority : null,
@@ -440,7 +440,7 @@ async function* bucketDataBatch(request: BucketDataRequest): AsyncGenerator<Buck
440
440
  }
441
441
  }
442
442
 
443
- function transformLegacyResponse(bucketData: util.SyncBucketData): any {
443
+ function transformLegacyResponse(bucketData: util.SyncBucketData): util.SyncBucketData<util.ProtocolOplogData> {
444
444
  return {
445
445
  ...bucketData,
446
446
  data: bucketData.data.map((entry) => {
@@ -59,6 +59,12 @@ export class ServiceContextContainer implements ServiceContext {
59
59
  this.storageEngine = new storage.StorageEngine({
60
60
  configuration
61
61
  });
62
+ this.storageEngine.registerListener({
63
+ storageFatalError: (error) => {
64
+ // Propagate the error to the lifecycle engine
65
+ this.lifeCycleEngine.stopWithError(error);
66
+ }
67
+ });
62
68
 
63
69
  this.lifeCycleEngine.withLifecycle(this.storageEngine, {
64
70
  start: (storageEngine) => storageEngine.start(),
@@ -1,5 +1,6 @@
1
1
  import * as t from 'ts-codec';
2
- import { BucketDescription, BucketPriority, SqliteJsonValue } from '@powersync/service-sync-rules';
2
+ import { BucketDescription, BucketPriority, SqliteJsonRow } from '@powersync/service-sync-rules';
3
+ import { JsonContainer } from '@powersync/service-jsonbig';
3
4
 
4
5
  export const BucketRequest = t.object({
5
6
  name: t.string,
@@ -65,7 +66,7 @@ export interface StreamingSyncCheckpointDiff {
65
66
  }
66
67
 
67
68
  export interface StreamingSyncData {
68
- data: SyncBucketData;
69
+ data: SyncBucketData<ProtocolOplogData>;
69
70
  }
70
71
 
71
72
  export interface StreamingSyncCheckpointComplete {
@@ -109,13 +110,9 @@ export interface BucketState {
109
110
  op_id: string;
110
111
  }
111
112
 
112
- export interface SyncDataBatch {
113
- buckets: SyncBucketData[];
114
- }
115
-
116
- export interface SyncBucketData {
113
+ export interface SyncBucketData<Data extends ProtocolOplogData = StoredOplogData> {
117
114
  bucket: string;
118
- data: OplogEntry[];
115
+ data: OplogEntry<Data>[];
119
116
  /**
120
117
  * True if there _could_ be more data for this bucket, and another request must be made.
121
118
  */
@@ -130,12 +127,20 @@ export interface SyncBucketData {
130
127
  next_after: ProtocolOpId;
131
128
  }
132
129
 
133
- export interface OplogEntry {
130
+ export type StoredOplogData = string | null;
131
+
132
+ // Note: When clients have both raw_data and binary_data disabled (this only affects legacy
133
+ // clients), data is actually a `Record<string, SqliteJsonValue>`. Oplog entries are always
134
+ // stored as a serialized (JSON) string so that they don't have to be parsed in the sync service,
135
+ // this representation only exists on the way out for legacy clients.
136
+ export type ProtocolOplogData = SqliteJsonRow | JsonContainer | StoredOplogData;
137
+
138
+ export interface OplogEntry<Data extends ProtocolOplogData = StoredOplogData> {
134
139
  op_id: ProtocolOpId;
135
140
  op: 'PUT' | 'REMOVE' | 'MOVE' | 'CLEAR';
136
141
  object_type?: string;
137
142
  object_id?: string;
138
- data?: Record<string, SqliteJsonValue> | string | null;
143
+ data?: Data;
139
144
  checksum: number | bigint;
140
145
  subkey?: string;
141
146
  }