@powersync/service-core 0.0.0-dev-20240725112650 → 0.0.0-dev-20240918092408

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 (331) hide show
  1. package/CHANGELOG.md +80 -2
  2. package/dist/api/RouteAPI.d.ts +68 -0
  3. package/dist/api/RouteAPI.js +2 -0
  4. package/dist/api/RouteAPI.js.map +1 -0
  5. package/dist/api/api-index.d.ts +1 -0
  6. package/dist/api/api-index.js +1 -0
  7. package/dist/api/api-index.js.map +1 -1
  8. package/dist/api/diagnostics.d.ts +4 -4
  9. package/dist/api/diagnostics.js +11 -65
  10. package/dist/api/diagnostics.js.map +1 -1
  11. package/dist/api/schema.d.ts +3 -5
  12. package/dist/api/schema.js +9 -79
  13. package/dist/api/schema.js.map +1 -1
  14. package/dist/auth/KeyStore.d.ts +7 -4
  15. package/dist/auth/KeyStore.js +1 -1
  16. package/dist/auth/KeyStore.js.map +1 -1
  17. package/dist/auth/auth-index.d.ts +0 -1
  18. package/dist/auth/auth-index.js +0 -1
  19. package/dist/auth/auth-index.js.map +1 -1
  20. package/dist/entry/cli-entry.js +3 -2
  21. package/dist/entry/cli-entry.js.map +1 -1
  22. package/dist/entry/commands/compact-action.js +12 -8
  23. package/dist/entry/commands/compact-action.js.map +1 -1
  24. package/dist/entry/commands/migrate-action.js +4 -5
  25. package/dist/entry/commands/migrate-action.js.map +1 -1
  26. package/dist/entry/commands/teardown-action.js +2 -2
  27. package/dist/entry/commands/teardown-action.js.map +1 -1
  28. package/dist/index.d.ts +4 -2
  29. package/dist/index.js +4 -2
  30. package/dist/index.js.map +1 -1
  31. package/dist/metrics/Metrics.d.ts +2 -2
  32. package/dist/metrics/Metrics.js +5 -13
  33. package/dist/metrics/Metrics.js.map +1 -1
  34. package/dist/migrations/db/migrations/1684951997326-init.d.ts +2 -2
  35. package/dist/migrations/db/migrations/1684951997326-init.js +4 -2
  36. package/dist/migrations/db/migrations/1684951997326-init.js.map +1 -1
  37. package/dist/migrations/db/migrations/1702295701188-sync-rule-state.d.ts +2 -2
  38. package/dist/migrations/db/migrations/1702295701188-sync-rule-state.js +4 -2
  39. package/dist/migrations/db/migrations/1702295701188-sync-rule-state.js.map +1 -1
  40. package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.d.ts +2 -2
  41. package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.js +4 -2
  42. package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.js.map +1 -1
  43. package/dist/migrations/migrations.d.ts +8 -0
  44. package/dist/migrations/migrations.js +19 -7
  45. package/dist/migrations/migrations.js.map +1 -1
  46. package/dist/modules/AbstractModule.d.ts +26 -0
  47. package/dist/modules/AbstractModule.js +11 -0
  48. package/dist/modules/AbstractModule.js.map +1 -0
  49. package/dist/modules/ModuleManager.d.ts +11 -0
  50. package/dist/modules/ModuleManager.js +32 -0
  51. package/dist/modules/ModuleManager.js.map +1 -0
  52. package/dist/modules/modules-index.d.ts +2 -0
  53. package/dist/modules/modules-index.js +3 -0
  54. package/dist/modules/modules-index.js.map +1 -0
  55. package/dist/replication/AbstractReplicationJob.d.ts +38 -0
  56. package/dist/replication/AbstractReplicationJob.js +51 -0
  57. package/dist/replication/AbstractReplicationJob.js.map +1 -0
  58. package/dist/replication/AbstractReplicator.d.ts +53 -0
  59. package/dist/replication/AbstractReplicator.js +187 -0
  60. package/dist/replication/AbstractReplicator.js.map +1 -0
  61. package/dist/replication/ErrorRateLimiter.d.ts +0 -9
  62. package/dist/replication/ErrorRateLimiter.js +1 -42
  63. package/dist/replication/ErrorRateLimiter.js.map +1 -1
  64. package/dist/replication/ReplicationEngine.d.ts +18 -0
  65. package/dist/replication/ReplicationEngine.js +41 -0
  66. package/dist/replication/ReplicationEngine.js.map +1 -0
  67. package/dist/replication/ReplicationModule.d.ts +39 -0
  68. package/dist/replication/ReplicationModule.js +65 -0
  69. package/dist/replication/ReplicationModule.js.map +1 -0
  70. package/dist/replication/replication-index.d.ts +4 -6
  71. package/dist/replication/replication-index.js +4 -6
  72. package/dist/replication/replication-index.js.map +1 -1
  73. package/dist/routes/RouterEngine.d.ts +42 -0
  74. package/dist/routes/RouterEngine.js +80 -0
  75. package/dist/routes/RouterEngine.js.map +1 -0
  76. package/dist/routes/auth.d.ts +2 -2
  77. package/dist/routes/auth.js +11 -11
  78. package/dist/routes/auth.js.map +1 -1
  79. package/dist/routes/configure-fastify.d.ts +30 -176
  80. package/dist/routes/configure-fastify.js +10 -11
  81. package/dist/routes/configure-fastify.js.map +1 -1
  82. package/dist/routes/configure-rsocket.d.ts +3 -3
  83. package/dist/routes/configure-rsocket.js +6 -5
  84. package/dist/routes/configure-rsocket.js.map +1 -1
  85. package/dist/routes/endpoints/admin.d.ts +0 -34
  86. package/dist/routes/endpoints/admin.js +48 -89
  87. package/dist/routes/endpoints/admin.js.map +1 -1
  88. package/dist/routes/endpoints/checkpointing.d.ts +56 -16
  89. package/dist/routes/endpoints/checkpointing.js +33 -12
  90. package/dist/routes/endpoints/checkpointing.js.map +1 -1
  91. package/dist/routes/endpoints/route-endpoints-index.d.ts +0 -1
  92. package/dist/routes/endpoints/route-endpoints-index.js +0 -1
  93. package/dist/routes/endpoints/route-endpoints-index.js.map +1 -1
  94. package/dist/routes/endpoints/socket-route.js +40 -25
  95. package/dist/routes/endpoints/socket-route.js.map +1 -1
  96. package/dist/routes/endpoints/sync-rules.d.ts +1 -1
  97. package/dist/routes/endpoints/sync-rules.js +32 -23
  98. package/dist/routes/endpoints/sync-rules.js.map +1 -1
  99. package/dist/routes/endpoints/sync-stream.d.ts +10 -0
  100. package/dist/routes/endpoints/sync-stream.js +13 -8
  101. package/dist/routes/endpoints/sync-stream.js.map +1 -1
  102. package/dist/routes/router-socket.d.ts +1 -0
  103. package/dist/routes/router-socket.js +2 -1
  104. package/dist/routes/router-socket.js.map +1 -1
  105. package/dist/routes/router.d.ts +6 -2
  106. package/dist/routes/router.js.map +1 -1
  107. package/dist/routes/routes-index.d.ts +1 -0
  108. package/dist/routes/routes-index.js +1 -0
  109. package/dist/routes/routes-index.js.map +1 -1
  110. package/dist/runner/teardown.js +47 -76
  111. package/dist/runner/teardown.js.map +1 -1
  112. package/dist/storage/BucketStorage.d.ts +30 -19
  113. package/dist/storage/BucketStorage.js +0 -10
  114. package/dist/storage/BucketStorage.js.map +1 -1
  115. package/dist/storage/MongoBucketStorage.d.ts +4 -4
  116. package/dist/storage/MongoBucketStorage.js +19 -24
  117. package/dist/storage/MongoBucketStorage.js.map +1 -1
  118. package/dist/storage/SourceEntity.d.ts +20 -0
  119. package/dist/storage/SourceEntity.js +2 -0
  120. package/dist/storage/SourceEntity.js.map +1 -0
  121. package/dist/storage/SourceTable.d.ts +4 -5
  122. package/dist/storage/SourceTable.js +3 -4
  123. package/dist/storage/SourceTable.js.map +1 -1
  124. package/dist/storage/StorageEngine.d.ts +24 -0
  125. package/dist/storage/StorageEngine.js +43 -0
  126. package/dist/storage/StorageEngine.js.map +1 -0
  127. package/dist/storage/StorageProvider.d.ts +21 -0
  128. package/dist/storage/StorageProvider.js +2 -0
  129. package/dist/storage/StorageProvider.js.map +1 -0
  130. package/dist/storage/mongo/MongoBucketBatch.d.ts +1 -1
  131. package/dist/storage/mongo/MongoBucketBatch.js +6 -7
  132. package/dist/storage/mongo/MongoBucketBatch.js.map +1 -1
  133. package/dist/storage/mongo/MongoCompactor.js +2 -1
  134. package/dist/storage/mongo/MongoCompactor.js.map +1 -1
  135. package/dist/storage/mongo/MongoPersistedSyncRulesContent.d.ts +2 -2
  136. package/dist/storage/mongo/MongoPersistedSyncRulesContent.js +2 -2
  137. package/dist/storage/mongo/MongoPersistedSyncRulesContent.js.map +1 -1
  138. package/dist/storage/mongo/MongoStorageProvider.d.ts +5 -0
  139. package/dist/storage/mongo/MongoStorageProvider.js +26 -0
  140. package/dist/storage/mongo/MongoStorageProvider.js.map +1 -0
  141. package/dist/storage/mongo/MongoSyncBucketStorage.d.ts +7 -6
  142. package/dist/storage/mongo/MongoSyncBucketStorage.js +24 -15
  143. package/dist/storage/mongo/MongoSyncBucketStorage.js.map +1 -1
  144. package/dist/storage/mongo/MongoSyncRulesLock.js +1 -1
  145. package/dist/storage/mongo/MongoSyncRulesLock.js.map +1 -1
  146. package/dist/storage/mongo/OperationBatch.d.ts +7 -3
  147. package/dist/storage/mongo/OperationBatch.js +16 -7
  148. package/dist/storage/mongo/OperationBatch.js.map +1 -1
  149. package/dist/storage/mongo/PersistedBatch.d.ts +3 -3
  150. package/dist/storage/mongo/PersistedBatch.js +2 -2
  151. package/dist/storage/mongo/PersistedBatch.js.map +1 -1
  152. package/dist/storage/mongo/models.d.ts +13 -4
  153. package/dist/storage/mongo/models.js.map +1 -1
  154. package/dist/storage/mongo/util.d.ts +12 -1
  155. package/dist/storage/mongo/util.js +50 -2
  156. package/dist/storage/mongo/util.js.map +1 -1
  157. package/dist/storage/storage-index.d.ts +5 -2
  158. package/dist/storage/storage-index.js +5 -2
  159. package/dist/storage/storage-index.js.map +1 -1
  160. package/dist/sync/sync.d.ts +2 -1
  161. package/dist/sync/sync.js +36 -10
  162. package/dist/sync/sync.js.map +1 -1
  163. package/dist/sync/util.js.map +1 -1
  164. package/dist/system/ServiceContext.d.ts +37 -0
  165. package/dist/system/ServiceContext.js +48 -0
  166. package/dist/system/ServiceContext.js.map +1 -0
  167. package/dist/system/system-index.d.ts +1 -1
  168. package/dist/system/system-index.js +1 -1
  169. package/dist/system/system-index.js.map +1 -1
  170. package/dist/util/config/compound-config-collector.d.ts +9 -2
  171. package/dist/util/config/compound-config-collector.js +14 -23
  172. package/dist/util/config/compound-config-collector.js.map +1 -1
  173. package/dist/util/config/sync-rules/sync-rules-provider.d.ts +9 -0
  174. package/dist/util/config/sync-rules/sync-rules-provider.js +15 -0
  175. package/dist/util/config/sync-rules/sync-rules-provider.js.map +1 -0
  176. package/dist/util/config/types.d.ts +6 -4
  177. package/dist/util/config/types.js.map +1 -1
  178. package/dist/util/config.d.ts +3 -4
  179. package/dist/util/config.js +5 -20
  180. package/dist/util/config.js.map +1 -1
  181. package/dist/util/protocol-types.d.ts +4 -0
  182. package/dist/util/protocol-types.js +5 -1
  183. package/dist/util/protocol-types.js.map +1 -1
  184. package/dist/util/util-index.d.ts +3 -6
  185. package/dist/util/util-index.js +3 -6
  186. package/dist/util/util-index.js.map +1 -1
  187. package/dist/util/utils.d.ts +10 -6
  188. package/dist/util/utils.js +45 -25
  189. package/dist/util/utils.js.map +1 -1
  190. package/package.json +5 -7
  191. package/src/api/RouteAPI.ts +78 -0
  192. package/src/api/api-index.ts +1 -0
  193. package/src/api/diagnostics.ts +16 -71
  194. package/src/api/schema.ts +13 -89
  195. package/src/auth/KeyStore.ts +9 -6
  196. package/src/auth/auth-index.ts +0 -1
  197. package/src/entry/cli-entry.ts +3 -2
  198. package/src/entry/commands/compact-action.ts +12 -9
  199. package/src/entry/commands/migrate-action.ts +5 -8
  200. package/src/entry/commands/teardown-action.ts +2 -2
  201. package/src/index.ts +5 -2
  202. package/src/metrics/Metrics.ts +6 -16
  203. package/src/migrations/db/migrations/1684951997326-init.ts +9 -4
  204. package/src/migrations/db/migrations/1702295701188-sync-rule-state.ts +7 -4
  205. package/src/migrations/db/migrations/1711543888062-write-checkpoint-index.ts +6 -4
  206. package/src/migrations/migrations.ts +24 -8
  207. package/src/modules/AbstractModule.ts +37 -0
  208. package/src/modules/ModuleManager.ts +34 -0
  209. package/src/modules/modules-index.ts +2 -0
  210. package/src/replication/AbstractReplicationJob.ts +79 -0
  211. package/src/replication/AbstractReplicator.ts +227 -0
  212. package/src/replication/ErrorRateLimiter.ts +0 -44
  213. package/src/replication/ReplicationEngine.ts +43 -0
  214. package/src/replication/ReplicationModule.ts +101 -0
  215. package/src/replication/replication-index.ts +4 -6
  216. package/src/routes/RouterEngine.ts +120 -0
  217. package/src/routes/auth.ts +21 -12
  218. package/src/routes/configure-fastify.ts +13 -14
  219. package/src/routes/configure-rsocket.ts +9 -8
  220. package/src/routes/endpoints/admin.ts +74 -100
  221. package/src/routes/endpoints/checkpointing.ts +46 -12
  222. package/src/routes/endpoints/route-endpoints-index.ts +0 -1
  223. package/src/routes/endpoints/socket-route.ts +44 -27
  224. package/src/routes/endpoints/sync-rules.ts +41 -25
  225. package/src/routes/endpoints/sync-stream.ts +13 -8
  226. package/src/routes/router-socket.ts +2 -1
  227. package/src/routes/router.ts +6 -3
  228. package/src/routes/routes-index.ts +1 -0
  229. package/src/runner/teardown.ts +50 -88
  230. package/src/storage/BucketStorage.ts +38 -25
  231. package/src/storage/MongoBucketStorage.ts +23 -26
  232. package/src/storage/SourceEntity.ts +22 -0
  233. package/src/storage/SourceTable.ts +4 -6
  234. package/src/storage/StorageEngine.ts +55 -0
  235. package/src/storage/StorageProvider.ts +27 -0
  236. package/src/storage/mongo/MongoBucketBatch.ts +8 -8
  237. package/src/storage/mongo/MongoCompactor.ts +2 -1
  238. package/src/storage/mongo/MongoPersistedSyncRulesContent.ts +3 -3
  239. package/src/storage/mongo/MongoStorageProvider.ts +31 -0
  240. package/src/storage/mongo/MongoSyncBucketStorage.ts +39 -20
  241. package/src/storage/mongo/MongoSyncRulesLock.ts +1 -1
  242. package/src/storage/mongo/OperationBatch.ts +18 -11
  243. package/src/storage/mongo/PersistedBatch.ts +6 -5
  244. package/src/storage/mongo/models.ts +13 -4
  245. package/src/storage/mongo/util.ts +49 -4
  246. package/src/storage/storage-index.ts +5 -2
  247. package/src/sync/sync.ts +46 -11
  248. package/src/sync/util.ts +0 -1
  249. package/src/system/ServiceContext.ts +68 -0
  250. package/src/system/system-index.ts +1 -1
  251. package/src/util/config/compound-config-collector.ts +30 -31
  252. package/src/util/config/sync-rules/sync-rules-provider.ts +18 -0
  253. package/src/util/config/types.ts +6 -5
  254. package/src/util/config.ts +6 -23
  255. package/src/util/protocol-types.ts +6 -1
  256. package/src/util/util-index.ts +3 -6
  257. package/src/util/utils.ts +55 -39
  258. package/test/src/__snapshots__/sync.test.ts.snap +7 -7
  259. package/test/src/auth.test.ts +7 -7
  260. package/test/src/broadcast_iterable.test.ts +1 -1
  261. package/test/src/checksum_cache.test.ts +3 -3
  262. package/test/src/compacting.test.ts +26 -17
  263. package/test/src/data_storage.test.ts +258 -146
  264. package/test/src/env.ts +1 -3
  265. package/test/src/merge_iterable.test.ts +1 -6
  266. package/test/src/setup.ts +1 -1
  267. package/test/src/stream_utils.ts +42 -0
  268. package/test/src/sync.test.ts +52 -31
  269. package/test/src/util.ts +48 -51
  270. package/test/tsconfig.json +1 -1
  271. package/tsconfig.tsbuildinfo +1 -1
  272. package/dist/auth/SupabaseKeyCollector.d.ts +0 -22
  273. package/dist/auth/SupabaseKeyCollector.js +0 -61
  274. package/dist/auth/SupabaseKeyCollector.js.map +0 -1
  275. package/dist/replication/PgRelation.d.ts +0 -16
  276. package/dist/replication/PgRelation.js +0 -26
  277. package/dist/replication/PgRelation.js.map +0 -1
  278. package/dist/replication/WalConnection.d.ts +0 -34
  279. package/dist/replication/WalConnection.js +0 -190
  280. package/dist/replication/WalConnection.js.map +0 -1
  281. package/dist/replication/WalStream.d.ts +0 -57
  282. package/dist/replication/WalStream.js +0 -515
  283. package/dist/replication/WalStream.js.map +0 -1
  284. package/dist/replication/WalStreamManager.d.ts +0 -30
  285. package/dist/replication/WalStreamManager.js +0 -198
  286. package/dist/replication/WalStreamManager.js.map +0 -1
  287. package/dist/replication/WalStreamRunner.d.ts +0 -38
  288. package/dist/replication/WalStreamRunner.js +0 -155
  289. package/dist/replication/WalStreamRunner.js.map +0 -1
  290. package/dist/replication/util.d.ts +0 -9
  291. package/dist/replication/util.js +0 -62
  292. package/dist/replication/util.js.map +0 -1
  293. package/dist/routes/endpoints/dev.d.ts +0 -312
  294. package/dist/routes/endpoints/dev.js +0 -172
  295. package/dist/routes/endpoints/dev.js.map +0 -1
  296. package/dist/system/CorePowerSyncSystem.d.ts +0 -23
  297. package/dist/system/CorePowerSyncSystem.js +0 -52
  298. package/dist/system/CorePowerSyncSystem.js.map +0 -1
  299. package/dist/util/PgManager.d.ts +0 -24
  300. package/dist/util/PgManager.js +0 -55
  301. package/dist/util/PgManager.js.map +0 -1
  302. package/dist/util/migration_lib.d.ts +0 -11
  303. package/dist/util/migration_lib.js +0 -64
  304. package/dist/util/migration_lib.js.map +0 -1
  305. package/dist/util/pgwire_utils.d.ts +0 -24
  306. package/dist/util/pgwire_utils.js +0 -117
  307. package/dist/util/pgwire_utils.js.map +0 -1
  308. package/dist/util/populate_test_data.d.ts +0 -8
  309. package/dist/util/populate_test_data.js +0 -65
  310. package/dist/util/populate_test_data.js.map +0 -1
  311. package/src/auth/SupabaseKeyCollector.ts +0 -67
  312. package/src/replication/PgRelation.ts +0 -42
  313. package/src/replication/WalConnection.ts +0 -227
  314. package/src/replication/WalStream.ts +0 -624
  315. package/src/replication/WalStreamManager.ts +0 -213
  316. package/src/replication/WalStreamRunner.ts +0 -180
  317. package/src/replication/util.ts +0 -76
  318. package/src/routes/endpoints/dev.ts +0 -199
  319. package/src/system/CorePowerSyncSystem.ts +0 -64
  320. package/src/util/PgManager.ts +0 -64
  321. package/src/util/migration_lib.ts +0 -79
  322. package/src/util/pgwire_utils.ts +0 -139
  323. package/src/util/populate_test_data.ts +0 -78
  324. package/test/src/__snapshots__/pg_test.test.ts.snap +0 -256
  325. package/test/src/large_batch.test.ts +0 -194
  326. package/test/src/pg_test.test.ts +0 -450
  327. package/test/src/schema_changes.test.ts +0 -545
  328. package/test/src/slow_tests.test.ts +0 -338
  329. package/test/src/validation.test.ts +0 -63
  330. package/test/src/wal_stream.test.ts +0 -319
  331. package/test/src/wal_stream_utils.ts +0 -156
@@ -0,0 +1,53 @@
1
+ import * as storage from '../storage/storage-index.js';
2
+ import { SyncRulesProvider } from '../util/config/sync-rules/sync-rules-provider.js';
3
+ import winston from 'winston';
4
+ import { AbstractReplicationJob } from './AbstractReplicationJob.js';
5
+ import { StorageEngine } from '../storage/storage-index.js';
6
+ import { ErrorRateLimiter } from './ErrorRateLimiter.js';
7
+ export interface CreateJobOptions {
8
+ lock: storage.ReplicationLock;
9
+ storage: storage.SyncRulesBucketStorage;
10
+ }
11
+ export interface AbstractReplicatorOptions {
12
+ id: string;
13
+ storageEngine: StorageEngine;
14
+ syncRuleProvider: SyncRulesProvider;
15
+ /**
16
+ * This limits the effect of retries when there is a persistent issue.
17
+ */
18
+ rateLimiter: ErrorRateLimiter;
19
+ }
20
+ /**
21
+ * A replicator manages the mechanics for replicating data from a data source to a storage bucket.
22
+ * This includes copying across the original data set and then keeping it in sync with the data source using Replication Jobs.
23
+ * It also handles any changes to the sync rules.
24
+ */
25
+ export declare abstract class AbstractReplicator<T extends AbstractReplicationJob = AbstractReplicationJob> {
26
+ private options;
27
+ protected logger: winston.Logger;
28
+ /**
29
+ * Map of replication jobs by sync rule id. Usually there is only one running job, but there could be two when
30
+ * transitioning to a new set of sync rules.
31
+ * @private
32
+ */
33
+ private replicationJobs;
34
+ private stopped;
35
+ private lastPing;
36
+ protected constructor(options: AbstractReplicatorOptions);
37
+ abstract createJob(options: CreateJobOptions): T;
38
+ /**
39
+ * Clean up any configuration or state for the specified sync rule on the datasource.
40
+ * Should be a no-op if the configuration has already been cleared
41
+ */
42
+ abstract cleanUp(syncRuleStorage: storage.SyncRulesBucketStorage): Promise<void>;
43
+ get id(): string;
44
+ protected get storage(): storage.BucketStorageFactory;
45
+ protected get syncRuleProvider(): SyncRulesProvider;
46
+ protected get rateLimiter(): ErrorRateLimiter;
47
+ start(): Promise<void>;
48
+ stop(): Promise<void>;
49
+ private runLoop;
50
+ private refresh;
51
+ protected createJobId(syncRuleId: number): string;
52
+ protected terminateSyncRules(syncRuleStorage: storage.SyncRulesBucketStorage): Promise<void>;
53
+ }
@@ -0,0 +1,187 @@
1
+ import { hrtime } from 'node:process';
2
+ import { container, logger } from '@powersync/lib-services-framework';
3
+ // 5 minutes
4
+ const PING_INTERVAL = 1000000000n * 300n;
5
+ /**
6
+ * A replicator manages the mechanics for replicating data from a data source to a storage bucket.
7
+ * This includes copying across the original data set and then keeping it in sync with the data source using Replication Jobs.
8
+ * It also handles any changes to the sync rules.
9
+ */
10
+ export class AbstractReplicator {
11
+ constructor(options) {
12
+ this.options = options;
13
+ /**
14
+ * Map of replication jobs by sync rule id. Usually there is only one running job, but there could be two when
15
+ * transitioning to a new set of sync rules.
16
+ * @private
17
+ */
18
+ this.replicationJobs = new Map();
19
+ this.stopped = false;
20
+ // First ping is only after 5 minutes, not when starting
21
+ this.lastPing = hrtime.bigint();
22
+ this.logger = logger.child({ name: `Replicator:${options.id}` });
23
+ }
24
+ get id() {
25
+ return this.options.id;
26
+ }
27
+ get storage() {
28
+ return this.options.storageEngine.activeBucketStorage;
29
+ }
30
+ get syncRuleProvider() {
31
+ return this.options.syncRuleProvider;
32
+ }
33
+ get rateLimiter() {
34
+ return this.options.rateLimiter;
35
+ }
36
+ async start() {
37
+ this.runLoop().catch((e) => {
38
+ this.logger.error('Data source fatal replication error', e);
39
+ container.reporter.captureException(e);
40
+ setTimeout(() => {
41
+ process.exit(1);
42
+ }, 1000);
43
+ });
44
+ }
45
+ async stop() {
46
+ this.stopped = true;
47
+ let promises = [];
48
+ for (const job of this.replicationJobs.values()) {
49
+ promises.push(job.stop());
50
+ }
51
+ await Promise.all(promises);
52
+ }
53
+ async runLoop() {
54
+ const syncRules = await this.syncRuleProvider.get();
55
+ let configuredLock = undefined;
56
+ if (syncRules != null) {
57
+ this.logger.info('Loaded sync rules');
58
+ try {
59
+ // Configure new sync rules, if they have changed.
60
+ // In that case, also immediately take out a lock, so that another process doesn't start replication on it.
61
+ const { lock } = await this.storage.configureSyncRules(syncRules, {
62
+ lock: true
63
+ });
64
+ if (lock) {
65
+ configuredLock = lock;
66
+ }
67
+ }
68
+ catch (e) {
69
+ // Log, but continue with previous sync rules
70
+ this.logger.error(`Failed to update sync rules from configuration`, e);
71
+ }
72
+ }
73
+ else {
74
+ this.logger.info('No sync rules configured - configure via API');
75
+ }
76
+ while (!this.stopped) {
77
+ await container.probes.touch();
78
+ try {
79
+ await this.refresh({ configured_lock: configuredLock });
80
+ // The lock is only valid on the first refresh.
81
+ configuredLock = undefined;
82
+ // Ensure that the replication jobs' connections are kept alive.
83
+ // We don't ping while in error retry back-off, to avoid having too failures.
84
+ if (this.rateLimiter.mayPing()) {
85
+ const now = hrtime.bigint();
86
+ if (now - this.lastPing >= PING_INTERVAL) {
87
+ for (const activeJob of this.replicationJobs.values()) {
88
+ await activeJob.keepAlive();
89
+ }
90
+ this.lastPing = now;
91
+ }
92
+ }
93
+ }
94
+ catch (e) {
95
+ this.logger.error('Failed to refresh replication jobs', e);
96
+ }
97
+ await new Promise((resolve) => setTimeout(resolve, 5000));
98
+ }
99
+ }
100
+ async refresh(options) {
101
+ if (this.stopped) {
102
+ return;
103
+ }
104
+ let configuredLock = options?.configured_lock;
105
+ const existingJobs = new Map(this.replicationJobs.entries());
106
+ const replicatingSyncRules = await this.storage.getReplicatingSyncRules();
107
+ const newJobs = new Map();
108
+ for (let syncRules of replicatingSyncRules) {
109
+ const existingJob = existingJobs.get(syncRules.id);
110
+ if (existingJob && !existingJob.isStopped) {
111
+ // No change
112
+ existingJobs.delete(syncRules.id);
113
+ newJobs.set(syncRules.id, existingJob);
114
+ }
115
+ else if (existingJob && existingJob.isStopped) {
116
+ // Stopped (e.g. fatal error).
117
+ // Remove from the list. Next refresh call will restart the job.
118
+ existingJobs.delete(syncRules.id);
119
+ }
120
+ else {
121
+ // New sync rules were found (or resume after restart)
122
+ try {
123
+ let lock;
124
+ if (configuredLock?.sync_rules_id == syncRules.id) {
125
+ lock = configuredLock;
126
+ }
127
+ else {
128
+ lock = await syncRules.lock();
129
+ }
130
+ const storage = this.storage.getInstance(syncRules);
131
+ const newJob = this.createJob({
132
+ lock: lock,
133
+ storage: storage
134
+ });
135
+ newJobs.set(syncRules.id, newJob);
136
+ newJob.start();
137
+ }
138
+ catch (e) {
139
+ // Could be a sync rules parse error,
140
+ // for example from stricter validation that was added.
141
+ // This will be retried every couple of seconds.
142
+ // When new (valid) sync rules are deployed and processed, this one be disabled.
143
+ this.logger.error('Failed to start replication for new sync rules', e);
144
+ }
145
+ }
146
+ }
147
+ this.replicationJobs = newJobs;
148
+ // Terminate any orphaned jobs that no longer have sync rules
149
+ for (let job of existingJobs.values()) {
150
+ // Old - stop and clean up
151
+ try {
152
+ await job.stop();
153
+ await this.terminateSyncRules(job.storage);
154
+ }
155
+ catch (e) {
156
+ // This will be retried
157
+ this.logger.warn('Failed to terminate old replication job}', e);
158
+ }
159
+ }
160
+ // Sync rules stopped previously or by a different process.
161
+ const stopped = await this.storage.getStoppedSyncRules();
162
+ for (let syncRules of stopped) {
163
+ try {
164
+ const syncRuleStorage = this.storage.getInstance(syncRules);
165
+ await this.terminateSyncRules(syncRuleStorage);
166
+ }
167
+ catch (e) {
168
+ this.logger.warn(`Failed clean up replication config for sync rule: ${syncRules.id}`, e);
169
+ }
170
+ }
171
+ }
172
+ createJobId(syncRuleId) {
173
+ return `${this.id}-${syncRuleId}`;
174
+ }
175
+ async terminateSyncRules(syncRuleStorage) {
176
+ this.logger.info(`Terminating sync rules: ${syncRuleStorage.group_id}...`);
177
+ try {
178
+ await this.cleanUp(syncRuleStorage);
179
+ await syncRuleStorage.terminate();
180
+ this.logger.info(`Successfully terminated sync rules: ${syncRuleStorage.group_id}`);
181
+ }
182
+ catch (e) {
183
+ this.logger.warn(`Failed clean up replication config for sync rules: ${syncRuleStorage.group_id}`, e);
184
+ }
185
+ }
186
+ }
187
+ //# sourceMappingURL=AbstractReplicator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AbstractReplicator.js","sourceRoot":"","sources":["../../src/replication/AbstractReplicator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAOtE,YAAY;AACZ,MAAM,aAAa,GAAG,WAAc,GAAG,IAAI,CAAC;AAiB5C;;;;GAIG;AACH,MAAM,OAAgB,kBAAkB;IAatC,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mBAAmB,EAAE,CAAC;QACzD,KAAK,IAAI,SAAS,IAAI,OAAO,EAAE;YAC7B,IAAI;gBACF,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;gBAC5D,MAAM,IAAI,CAAC,kBAAkB,CAAC,eAAe,CAAC,CAAC;aAChD;YAAC,OAAO,CAAC,EAAE;gBACV,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,qDAAqD,SAAS,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;aAC1F;SACF;IACH,CAAC;IAES,WAAW,CAAC,UAAkB;QACtC,OAAO,GAAG,IAAI,CAAC,EAAE,IAAI,UAAU,EAAE,CAAC;IACpC,CAAC;IAES,KAAK,CAAC,kBAAkB,CAAC,eAA+C;QAChF,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,2BAA2B,eAAe,CAAC,QAAQ,KAAK,CAAC,CAAC;QAC3E,IAAI;YACF,MAAM,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;YACpC,MAAM,eAAe,CAAC,SAAS,EAAE,CAAC;YAClC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,uCAAuC,eAAe,CAAC,QAAQ,EAAE,CAAC,CAAC;SACrF;QAAC,OAAO,CAAC,EAAE;YACV,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,sDAAsD,eAAe,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC;SACvG;IACH,CAAC;CACF"}
@@ -6,12 +6,3 @@ export interface ErrorRateLimiter {
6
6
  reportError(e: any): void;
7
7
  mayPing(): boolean;
8
8
  }
9
- export declare class DefaultErrorRateLimiter implements ErrorRateLimiter {
10
- nextAllowed: number;
11
- waitUntilAllowed(options?: {
12
- signal?: AbortSignal | undefined;
13
- } | undefined): Promise<void>;
14
- mayPing(): boolean;
15
- reportError(e: any): void;
16
- private setDelay;
17
- }
@@ -1,43 +1,2 @@
1
- import { setTimeout } from 'timers/promises';
2
- export class DefaultErrorRateLimiter {
3
- constructor() {
4
- this.nextAllowed = Date.now();
5
- }
6
- async waitUntilAllowed(options) {
7
- const delay = Math.max(0, this.nextAllowed - Date.now());
8
- // Minimum delay between connections, even without errors
9
- this.setDelay(500);
10
- await setTimeout(delay, undefined, { signal: options?.signal });
11
- }
12
- mayPing() {
13
- return Date.now() >= this.nextAllowed;
14
- }
15
- reportError(e) {
16
- const message = e.message ?? '';
17
- if (message.includes('password authentication failed')) {
18
- // Wait 15 minutes, to avoid triggering Supabase's fail2ban
19
- this.setDelay(900000);
20
- }
21
- else if (message.includes('ENOTFOUND')) {
22
- // DNS lookup issue - incorrect URI or deleted instance
23
- this.setDelay(120000);
24
- }
25
- else if (message.includes('ECONNREFUSED')) {
26
- // Could be fail2ban or similar
27
- this.setDelay(120000);
28
- }
29
- else if (message.includes('Unable to do postgres query on ended pool') ||
30
- message.includes('Postgres unexpectedly closed connection')) {
31
- // Connection timed out - ignore / immediately retry
32
- // We don't explicitly set the delay to 0, since there could have been another error that
33
- // we need to respect.
34
- }
35
- else {
36
- this.setDelay(30000);
37
- }
38
- }
39
- setDelay(delay) {
40
- this.nextAllowed = Math.max(this.nextAllowed, Date.now() + delay);
41
- }
42
- }
1
+ export {};
43
2
  //# sourceMappingURL=ErrorRateLimiter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ErrorRateLimiter.js","sourceRoot":"","sources":["../../src/replication/ErrorRateLimiter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAS7C,MAAM,OAAO,uBAAuB;IAApC;QACE,gBAAW,GAAW,IAAI,CAAC,GAAG,EAAE,CAAC;IAuCnC,CAAC;IArCC,KAAK,CAAC,gBAAgB,CAAC,OAA0D;QAC/E,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;QACzD,yD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+ import { AbstractReplicator } from './AbstractReplicator.js';
2
+ export declare class ReplicationEngine {
3
+ private readonly replicators;
4
+ /**
5
+ * Register a Replicator with the engine
6
+ *
7
+ * @param replicator
8
+ */
9
+ register(replicator: AbstractReplicator): void;
10
+ /**
11
+ * Start replication on all managed Replicators
12
+ */
13
+ start(): void;
14
+ /**
15
+ * Stop replication on all managed Replicators
16
+ */
17
+ shutDown(): Promise<void>;
18
+ }
@@ -0,0 +1,41 @@
1
+ import { logger } from '@powersync/lib-services-framework';
2
+ export class ReplicationEngine {
3
+ constructor() {
4
+ this.replicators = new Map();
5
+ }
6
+ /**
7
+ * Register a Replicator with the engine
8
+ *
9
+ * @param replicator
10
+ */
11
+ register(replicator) {
12
+ if (this.replicators.has(replicator.id)) {
13
+ throw new Error(`Replicator with id: ${replicator.id} already registered`);
14
+ }
15
+ logger.info(`Successfully registered Replicator ${replicator.id} with ReplicationEngine`);
16
+ this.replicators.set(replicator.id, replicator);
17
+ }
18
+ /**
19
+ * Start replication on all managed Replicators
20
+ */
21
+ start() {
22
+ logger.info('Starting Replication Engine...');
23
+ for (const replicator of this.replicators.values()) {
24
+ logger.info(`Starting Replicator: ${replicator.id}`);
25
+ replicator.start();
26
+ }
27
+ logger.info('Successfully started Replication Engine.');
28
+ }
29
+ /**
30
+ * Stop replication on all managed Replicators
31
+ */
32
+ async shutDown() {
33
+ logger.info('Shutting down Replication Engine...');
34
+ for (const replicator of this.replicators.values()) {
35
+ logger.info(`Stopping Replicator: ${replicator.id}`);
36
+ await replicator.stop();
37
+ }
38
+ logger.info('Successfully shut down Replication Engine.');
39
+ }
40
+ }
41
+ //# sourceMappingURL=ReplicationEngine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReplicationEngine.js","sourceRoot":"","sources":["../../src/replication/ReplicationEngine.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAE3D,MAAM,OAAO,iBAAiB;IAA9B;QACmB,gBAAW,GAAoC,IAAI,GAAG,EAAE,CAAC;IAsC5E,CAAC;IApCC;;;;OAIG;IACI,QAAQ,CAAC,UAA8B;QAC5C,IAAI,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,EAAE;YACvC,MAAM,IAAI,KAAK,CAAC,uBAAuB,UAAU,CAAC,EAAE,qBAAqB,CAAC,CAAC;SAC5E;QACD,MAAM,CAAC,IAAI,CAAC,sCAAsC,UAAU,CAAC,EAAE,yBAAyB,CAAC,CAAC;QAC1F,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,EAAE,UAAU,CAAC,CAAC;IAClD,CAAC;IAED;;OAEG;IACI,KAAK;QACV,MAAM,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAC;QAC9C,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,EAAE;YAClD,MAAM,CAAC,IAAI,CAAC,wBAAwB,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC;YACrD,UAAU,CAAC,KAAK,EAAE,CAAC;SACpB;QACD,MAAM,CAAC,IAAI,CAAC,0CAA0C,CAAC,CAAC;IAC1D,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,QAAQ;QACnB,MAAM,CAAC,IAAI,CAAC,qCAAqC,CAAC,CAAC;QACnD,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,EAAE;YAClD,MAAM,CAAC,IAAI,CAAC,wBAAwB,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC;YACrD,MAAM,UAAU,CAAC,IAAI,EAAE,CAAC;SACzB;QACD,MAAM,CAAC,IAAI,CAAC,4CAA4C,CAAC,CAAC;IAC5D,CAAC;CACF"}
@@ -0,0 +1,39 @@
1
+ import { DataSourceConfig } from '@powersync/service-types/dist/config/PowerSyncConfig.js';
2
+ import * as t from 'ts-codec';
3
+ import * as api from '../api/api-index.js';
4
+ import * as modules from '../modules/modules-index.js';
5
+ import * as system from '../system/system-index.js';
6
+ import { AbstractReplicator } from './AbstractReplicator.js';
7
+ export interface ReplicationModuleOptions extends modules.AbstractModuleOptions {
8
+ type: string;
9
+ configSchema: t.AnyCodec;
10
+ }
11
+ /**
12
+ * A replication module describes all the functionality that PowerSync requires to
13
+ * replicate data from a DataSource. Whenever a new data source is added to powersync this class should be extended.
14
+ */
15
+ export declare abstract class ReplicationModule<TConfig extends DataSourceConfig> extends modules.AbstractModule {
16
+ protected type: string;
17
+ protected configSchema: t.AnyCodec;
18
+ protected decodedConfig: TConfig | undefined;
19
+ /**
20
+ * @protected
21
+ * @param options
22
+ */
23
+ protected constructor(options: ReplicationModuleOptions);
24
+ /**
25
+ * Create the RouteAPI adapter for the DataSource required to service the sync API
26
+ * endpoints.
27
+ */
28
+ protected abstract createRouteAPIAdapter(): api.RouteAPI;
29
+ /**
30
+ * Create the Replicator to be used by the ReplicationEngine.
31
+ */
32
+ protected abstract createReplicator(context: system.ServiceContext): AbstractReplicator;
33
+ /**
34
+ * Register this module's Replicators and RouteAPI adapters if the required configuration is present.
35
+ */
36
+ initialize(context: system.ServiceContext): Promise<void>;
37
+ private validateConfig;
38
+ protected getDefaultId(dataSourceName: string): string;
39
+ }
@@ -0,0 +1,65 @@
1
+ import * as t from 'ts-codec';
2
+ import * as types from '@powersync/service-types';
3
+ import * as modules from '../modules/modules-index.js';
4
+ import { schema } from '@powersync/lib-services-framework';
5
+ /**
6
+ * A replication module describes all the functionality that PowerSync requires to
7
+ * replicate data from a DataSource. Whenever a new data source is added to powersync this class should be extended.
8
+ */
9
+ export class ReplicationModule extends modules.AbstractModule {
10
+ /**
11
+ * @protected
12
+ * @param options
13
+ */
14
+ constructor(options) {
15
+ super(options);
16
+ this.type = options.type;
17
+ this.configSchema = options.configSchema;
18
+ }
19
+ /**
20
+ * Register this module's Replicators and RouteAPI adapters if the required configuration is present.
21
+ */
22
+ async initialize(context) {
23
+ if (!context.configuration.connections) {
24
+ // No data source configuration found in the config skip for now
25
+ return;
26
+ }
27
+ const matchingConfig = context.configuration.connections.filter((dataSource) => dataSource.type === this.type);
28
+ if (!matchingConfig.length) {
29
+ // This module is needed given the config
30
+ return;
31
+ }
32
+ if (matchingConfig.length > 1) {
33
+ this.logger.warning(`Multiple data sources of type ${this.type} found in the configuration. Only the first will be used.`);
34
+ }
35
+ try {
36
+ const baseMatchingConfig = matchingConfig[0];
37
+ // If validation fails, log the error and continue, no replication will happen for this data source
38
+ this.validateConfig(baseMatchingConfig);
39
+ this.decodedConfig = this.configSchema.decode(baseMatchingConfig);
40
+ context.replicationEngine?.register(this.createReplicator(context));
41
+ context.routerEngine?.registerAPI(this.createRouteAPIAdapter());
42
+ }
43
+ catch (e) {
44
+ this.logger.error('Failed to initialize.', e);
45
+ }
46
+ }
47
+ validateConfig(config) {
48
+ const validator = schema
49
+ .parseJSONSchema(
50
+ // This generates a schema for the encoded form of the codec
51
+ t.generateJSONSchema(this.configSchema, {
52
+ allowAdditional: true,
53
+ parsers: [types.configFile.portParser]
54
+ }))
55
+ .validator();
56
+ const valid = validator.validate(config);
57
+ if (!valid.valid) {
58
+ throw new Error(`Failed to validate Module ${this.name} configuration: ${valid.errors.join(', ')}`);
59
+ }
60
+ }
61
+ getDefaultId(dataSourceName) {
62
+ return `${this.type}-${dataSourceName}`;
63
+ }
64
+ }
65
+ //# sourceMappingURL=ReplicationModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReplicationModule.js","sourceRoot":"","sources":["../../src/replication/ReplicationModule.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAE9B,OAAO,KAAK,KAAK,MAAM,0BAA0B,CAAC;AAElD,OAAO,KAAK,OAAO,MAAM,6BAA6B,CAAC;AAEvD,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAQ3D;;;GAGG;AACH,MAAM,OAAgB,iBAAoD,SAAQ,OAAO,CAAC,cAAc;IAKtG;;;O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C,MAAM,SAAS,GAAG,MAAM;aACrB,eAAe;QACd,4DAA4D;QAC5D,CAAC,CAAC,kBAAkB,CAAC,IAAI,CAAC,YAAY,EAAE;YACtC,eAAe,EAAE,IAAI;YACrB,OAAO,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,UAAU,CAAC;SACvC,CAAC,CACH;aACA,SAAS,EAAE,CAAC;QAEf,MAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAEzC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE;YAChB,MAAM,IAAI,KAAK,CAAC,6BAA6B,IAAI,CAAC,IAAI,mBAAmB,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;SACrG;IACH,CAAC;IAES,YAAY,CAAC,cAAsB;QAC3C,OAAO,GAAG,IAAI,CAAC,IAAI,IAAI,cAAc,EAAE,CAAC;IAC1C,CAAC;CACF"}
@@ -1,7 +1,5 @@
1
1
  export * from './ErrorRateLimiter.js';
2
- export * from './PgRelation.js';
3
- export * from './util.js';
4
- export * from './WalConnection.js';
5
- export * from './WalStream.js';
6
- export * from './WalStreamManager.js';
7
- export * from './WalStreamRunner.js';
2
+ export * from './AbstractReplicationJob.js';
3
+ export * from './AbstractReplicator.js';
4
+ export * from './ReplicationEngine.js';
5
+ export * from './ReplicationModule.js';
@@ -1,8 +1,6 @@
1
1
  export * from './ErrorRateLimiter.js';
2
- export * from './PgRelation.js';
3
- export * from './util.js';
4
- export * from './WalConnection.js';
5
- export * from './WalStream.js';
6
- export * from './WalStreamManager.js';
7
- export * from './WalStreamRunner.js';
2
+ export * from './AbstractReplicationJob.js';
3
+ export * from './AbstractReplicator.js';
4
+ export * from './ReplicationEngine.js';
5
+ export * from './ReplicationModule.js';
8
6
  //# sourceMappingURL=replication-index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"replication-index.js","sourceRoot":"","sources":["../../src/replication/replication-index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"replication-index.js","sourceRoot":"","sources":["../../src/replication/replication-index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC"}
@@ -0,0 +1,42 @@
1
+ import * as api from '../api/api-index.js';
2
+ import { SocketRouteGenerator } from './router-socket.js';
3
+ import { RouteDefinition } from './router.js';
4
+ export type RouterSetupResponse = {
5
+ onShutdown: () => Promise<void>;
6
+ };
7
+ export type RouterEngineRoutes = {
8
+ api_routes: RouteDefinition[];
9
+ stream_routes: RouteDefinition[];
10
+ socket_routes: SocketRouteGenerator[];
11
+ };
12
+ export type RouterSetup = (routes: RouterEngineRoutes) => Promise<RouterSetupResponse>;
13
+ /**
14
+ * Serves as a registry from which SyncAPIs can be retrieved based on Replication DataSource type
15
+ * Initially only one SyncAPI per DataSource type is supported
16
+ */
17
+ export declare class RouterEngine {
18
+ closed: boolean;
19
+ routes: RouterEngineRoutes;
20
+ protected stopHandlers: Set<() => void>;
21
+ /**
22
+ * A final cleanup handler to be executed after all stopHandlers
23
+ */
24
+ protected cleanupHandler: (() => Promise<void>) | null;
25
+ private api;
26
+ constructor();
27
+ registerAPI(api: api.RouteAPI): void;
28
+ getAPI(): api.RouteAPI;
29
+ /**
30
+ * Starts the router given the configuration provided
31
+ */
32
+ start(setup: RouterSetup): Promise<void>;
33
+ /**
34
+ * Runs all stop handlers then final cleanup.
35
+ */
36
+ shutDown(): Promise<void>;
37
+ /**
38
+ * Add a stop handler callback to be executed when the router engine is being
39
+ * shutdown.
40
+ */
41
+ addStopHandler(handler: () => void): () => void;
42
+ }
@@ -0,0 +1,80 @@
1
+ import { logger } from '@powersync/lib-services-framework';
2
+ import { ADMIN_ROUTES } from './endpoints/admin.js';
3
+ import { CHECKPOINT_ROUTES } from './endpoints/checkpointing.js';
4
+ import { syncStreamReactive } from './endpoints/socket-route.js';
5
+ import { SYNC_RULES_ROUTES } from './endpoints/sync-rules.js';
6
+ import { SYNC_STREAM_ROUTES } from './endpoints/sync-stream.js';
7
+ /**
8
+ * Serves as a registry from which SyncAPIs can be retrieved based on Replication DataSource type
9
+ * Initially only one SyncAPI per DataSource type is supported
10
+ */
11
+ export class RouterEngine {
12
+ constructor() {
13
+ this.api = null;
14
+ this.stopHandlers = new Set();
15
+ this.cleanupHandler = null;
16
+ this.closed = false;
17
+ // Default routes
18
+ this.routes = {
19
+ api_routes: [...ADMIN_ROUTES, ...CHECKPOINT_ROUTES, ...SYNC_RULES_ROUTES],
20
+ stream_routes: [...SYNC_STREAM_ROUTES],
21
+ socket_routes: [syncStreamReactive]
22
+ };
23
+ }
24
+ registerAPI(api) {
25
+ if (this.api) {
26
+ logger.warn('A RouteAPI has already been registered. Overriding existing implementation');
27
+ }
28
+ this.api = api;
29
+ }
30
+ getAPI() {
31
+ if (!this.api) {
32
+ throw new Error('No RouteAPI adapter has been registered yet.');
33
+ }
34
+ return this.api;
35
+ }
36
+ /**
37
+ * Starts the router given the configuration provided
38
+ */
39
+ async start(setup) {
40
+ logger.info('Starting Router Engine...');
41
+ const { onShutdown } = await setup(this.routes);
42
+ this.cleanupHandler = onShutdown;
43
+ logger.info('Successfully started Router Engine.');
44
+ }
45
+ /**
46
+ * Runs all stop handlers then final cleanup.
47
+ */
48
+ async shutDown() {
49
+ logger.info('Shutting down Router Engine...');
50
+ // Close open streams, so that they don't block the server from closing.
51
+ // Note: This does not work well when streaming requests are queued. In that case, the server still doesn't
52
+ // close in the 30-second timeout.
53
+ this.closed = true;
54
+ logger.info(`Closing ${this.stopHandlers.size} streams.`);
55
+ for (let handler of this.stopHandlers) {
56
+ handler();
57
+ }
58
+ logger.info(`Running cleanup.`);
59
+ // Typically closes the server
60
+ await this.cleanupHandler?.();
61
+ // Close the api handlers
62
+ await this.api?.shutdown();
63
+ logger.info('Successfully shut down Router Engine.');
64
+ }
65
+ /**
66
+ * Add a stop handler callback to be executed when the router engine is being
67
+ * shutdown.
68
+ */
69
+ addStopHandler(handler) {
70
+ if (this.closed) {
71
+ handler();
72
+ return () => { };
73
+ }
74
+ this.stopHandlers.add(handler);
75
+ return () => {
76
+ this.stopHandlers.delete(handler);
77
+ };
78
+ }
79
+ }
80
+ //# sourceMappingURL=RouterEngine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RouterEngine.js","sourceRoot":"","sources":["../../src/routes/RouterEngine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAI3D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAgBhE;;;GAGG;AACH,MAAM,OAAO,YAAY;IAavB;QACE,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC;QAChB,IAAI,CAAC,YAAY,GAAG,IAAI,GAAG,EAAE,CAAC;QAC9B,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QAEpB,iBAAiB;QACjB,IAAI,CAAC,MAAM,GAAG;YACZ,UAAU,EAAE,CAAC,GAAG,YAAY,EAAE,GAAG,iBAAiB,EAAE,GAAG,iBAAiB,CAAC;YACzE,aAAa,EAAE,CAAC,GAAG,kBAAkB,CAAC;YACtC,aAAa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