@powersync/service-core 0.0.0-dev-20240718134716 → 0.0.0-dev-20240918082156

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 (352) hide show
  1. package/CHANGELOG.md +89 -6
  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 +4 -2
  21. package/dist/entry/cli-entry.js.map +1 -1
  22. package/dist/entry/commands/compact-action.d.ts +2 -0
  23. package/dist/entry/commands/compact-action.js +52 -0
  24. package/dist/entry/commands/compact-action.js.map +1 -0
  25. package/dist/entry/commands/migrate-action.js +4 -5
  26. package/dist/entry/commands/migrate-action.js.map +1 -1
  27. package/dist/entry/commands/teardown-action.js +2 -2
  28. package/dist/entry/commands/teardown-action.js.map +1 -1
  29. package/dist/entry/entry-index.d.ts +1 -0
  30. package/dist/entry/entry-index.js +1 -0
  31. package/dist/entry/entry-index.js.map +1 -1
  32. package/dist/index.d.ts +4 -2
  33. package/dist/index.js +4 -2
  34. package/dist/index.js.map +1 -1
  35. package/dist/metrics/Metrics.d.ts +6 -5
  36. package/dist/metrics/Metrics.js +53 -10
  37. package/dist/metrics/Metrics.js.map +1 -1
  38. package/dist/migrations/db/migrations/1684951997326-init.d.ts +2 -2
  39. package/dist/migrations/db/migrations/1684951997326-init.js +4 -2
  40. package/dist/migrations/db/migrations/1684951997326-init.js.map +1 -1
  41. package/dist/migrations/db/migrations/1702295701188-sync-rule-state.d.ts +2 -2
  42. package/dist/migrations/db/migrations/1702295701188-sync-rule-state.js +4 -2
  43. package/dist/migrations/db/migrations/1702295701188-sync-rule-state.js.map +1 -1
  44. package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.d.ts +2 -2
  45. package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.js +4 -2
  46. package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.js.map +1 -1
  47. package/dist/migrations/migrations.d.ts +8 -0
  48. package/dist/migrations/migrations.js +19 -7
  49. package/dist/migrations/migrations.js.map +1 -1
  50. package/dist/modules/AbstractModule.d.ts +26 -0
  51. package/dist/modules/AbstractModule.js +11 -0
  52. package/dist/modules/AbstractModule.js.map +1 -0
  53. package/dist/modules/ModuleManager.d.ts +11 -0
  54. package/dist/modules/ModuleManager.js +32 -0
  55. package/dist/modules/ModuleManager.js.map +1 -0
  56. package/dist/modules/modules-index.d.ts +2 -0
  57. package/dist/modules/modules-index.js +3 -0
  58. package/dist/modules/modules-index.js.map +1 -0
  59. package/dist/replication/AbstractReplicationJob.d.ts +38 -0
  60. package/dist/replication/AbstractReplicationJob.js +51 -0
  61. package/dist/replication/AbstractReplicationJob.js.map +1 -0
  62. package/dist/replication/AbstractReplicator.d.ts +53 -0
  63. package/dist/replication/AbstractReplicator.js +187 -0
  64. package/dist/replication/AbstractReplicator.js.map +1 -0
  65. package/dist/replication/ErrorRateLimiter.d.ts +0 -9
  66. package/dist/replication/ErrorRateLimiter.js +1 -42
  67. package/dist/replication/ErrorRateLimiter.js.map +1 -1
  68. package/dist/replication/ReplicationEngine.d.ts +18 -0
  69. package/dist/replication/ReplicationEngine.js +41 -0
  70. package/dist/replication/ReplicationEngine.js.map +1 -0
  71. package/dist/replication/ReplicationModule.d.ts +39 -0
  72. package/dist/replication/ReplicationModule.js +65 -0
  73. package/dist/replication/ReplicationModule.js.map +1 -0
  74. package/dist/replication/replication-index.d.ts +4 -6
  75. package/dist/replication/replication-index.js +4 -6
  76. package/dist/replication/replication-index.js.map +1 -1
  77. package/dist/routes/RouterEngine.d.ts +42 -0
  78. package/dist/routes/RouterEngine.js +80 -0
  79. package/dist/routes/RouterEngine.js.map +1 -0
  80. package/dist/routes/auth.d.ts +2 -2
  81. package/dist/routes/auth.js +11 -11
  82. package/dist/routes/auth.js.map +1 -1
  83. package/dist/routes/configure-fastify.d.ts +737 -0
  84. package/dist/routes/configure-fastify.js +57 -0
  85. package/dist/routes/configure-fastify.js.map +1 -0
  86. package/dist/routes/configure-rsocket.d.ts +13 -0
  87. package/dist/routes/configure-rsocket.js +47 -0
  88. package/dist/routes/configure-rsocket.js.map +1 -0
  89. package/dist/routes/endpoints/admin.d.ts +0 -34
  90. package/dist/routes/endpoints/admin.js +48 -89
  91. package/dist/routes/endpoints/admin.js.map +1 -1
  92. package/dist/routes/endpoints/checkpointing.d.ts +56 -16
  93. package/dist/routes/endpoints/checkpointing.js +33 -12
  94. package/dist/routes/endpoints/checkpointing.js.map +1 -1
  95. package/dist/routes/endpoints/route-endpoints-index.d.ts +0 -1
  96. package/dist/routes/endpoints/route-endpoints-index.js +0 -1
  97. package/dist/routes/endpoints/route-endpoints-index.js.map +1 -1
  98. package/dist/routes/endpoints/socket-route.js +46 -39
  99. package/dist/routes/endpoints/socket-route.js.map +1 -1
  100. package/dist/routes/endpoints/sync-rules.d.ts +1 -1
  101. package/dist/routes/endpoints/sync-rules.js +32 -23
  102. package/dist/routes/endpoints/sync-rules.js.map +1 -1
  103. package/dist/routes/endpoints/sync-stream.d.ts +10 -0
  104. package/dist/routes/endpoints/sync-stream.js +17 -13
  105. package/dist/routes/endpoints/sync-stream.js.map +1 -1
  106. package/dist/routes/route-register.d.ts +1 -1
  107. package/dist/routes/route-register.js +1 -1
  108. package/dist/routes/route-register.js.map +1 -1
  109. package/dist/routes/router-socket.d.ts +5 -4
  110. package/dist/routes/router-socket.js +2 -1
  111. package/dist/routes/router-socket.js.map +1 -1
  112. package/dist/routes/router.d.ts +7 -2
  113. package/dist/routes/router.js.map +1 -1
  114. package/dist/routes/routes-index.d.ts +3 -0
  115. package/dist/routes/routes-index.js +3 -0
  116. package/dist/routes/routes-index.js.map +1 -1
  117. package/dist/runner/teardown.js +47 -76
  118. package/dist/runner/teardown.js.map +1 -1
  119. package/dist/storage/BucketStorage.d.ts +61 -20
  120. package/dist/storage/BucketStorage.js +0 -10
  121. package/dist/storage/BucketStorage.js.map +1 -1
  122. package/dist/storage/MongoBucketStorage.d.ts +4 -4
  123. package/dist/storage/MongoBucketStorage.js +19 -24
  124. package/dist/storage/MongoBucketStorage.js.map +1 -1
  125. package/dist/storage/SourceEntity.d.ts +20 -0
  126. package/dist/storage/SourceEntity.js +2 -0
  127. package/dist/storage/SourceEntity.js.map +1 -0
  128. package/dist/storage/SourceTable.d.ts +4 -5
  129. package/dist/storage/SourceTable.js +3 -4
  130. package/dist/storage/SourceTable.js.map +1 -1
  131. package/dist/storage/StorageEngine.d.ts +24 -0
  132. package/dist/storage/StorageEngine.js +43 -0
  133. package/dist/storage/StorageEngine.js.map +1 -0
  134. package/dist/storage/StorageProvider.d.ts +21 -0
  135. package/dist/storage/StorageProvider.js +2 -0
  136. package/dist/storage/StorageProvider.js.map +1 -0
  137. package/dist/storage/mongo/MongoBucketBatch.d.ts +1 -1
  138. package/dist/storage/mongo/MongoBucketBatch.js +6 -7
  139. package/dist/storage/mongo/MongoBucketBatch.js.map +1 -1
  140. package/dist/storage/mongo/MongoCompactor.d.ts +40 -0
  141. package/dist/storage/mongo/MongoCompactor.js +293 -0
  142. package/dist/storage/mongo/MongoCompactor.js.map +1 -0
  143. package/dist/storage/mongo/MongoPersistedSyncRulesContent.d.ts +2 -2
  144. package/dist/storage/mongo/MongoPersistedSyncRulesContent.js +2 -2
  145. package/dist/storage/mongo/MongoPersistedSyncRulesContent.js.map +1 -1
  146. package/dist/storage/mongo/MongoStorageProvider.d.ts +5 -0
  147. package/dist/storage/mongo/MongoStorageProvider.js +26 -0
  148. package/dist/storage/mongo/MongoStorageProvider.js.map +1 -0
  149. package/dist/storage/mongo/MongoSyncBucketStorage.d.ts +9 -7
  150. package/dist/storage/mongo/MongoSyncBucketStorage.js +43 -28
  151. package/dist/storage/mongo/MongoSyncBucketStorage.js.map +1 -1
  152. package/dist/storage/mongo/MongoSyncRulesLock.js +1 -1
  153. package/dist/storage/mongo/MongoSyncRulesLock.js.map +1 -1
  154. package/dist/storage/mongo/OperationBatch.d.ts +7 -3
  155. package/dist/storage/mongo/OperationBatch.js +16 -7
  156. package/dist/storage/mongo/OperationBatch.js.map +1 -1
  157. package/dist/storage/mongo/PersistedBatch.d.ts +3 -3
  158. package/dist/storage/mongo/PersistedBatch.js +2 -2
  159. package/dist/storage/mongo/PersistedBatch.js.map +1 -1
  160. package/dist/storage/mongo/models.d.ts +17 -7
  161. package/dist/storage/mongo/models.js.map +1 -1
  162. package/dist/storage/mongo/util.d.ts +14 -0
  163. package/dist/storage/mongo/util.js +70 -0
  164. package/dist/storage/mongo/util.js.map +1 -1
  165. package/dist/storage/storage-index.d.ts +5 -2
  166. package/dist/storage/storage-index.js +5 -2
  167. package/dist/storage/storage-index.js.map +1 -1
  168. package/dist/sync/RequestTracker.js +2 -3
  169. package/dist/sync/RequestTracker.js.map +1 -1
  170. package/dist/sync/sync-index.d.ts +1 -0
  171. package/dist/sync/sync-index.js +1 -0
  172. package/dist/sync/sync-index.js.map +1 -1
  173. package/dist/sync/sync.d.ts +2 -1
  174. package/dist/sync/sync.js +56 -17
  175. package/dist/sync/sync.js.map +1 -1
  176. package/dist/system/ServiceContext.d.ts +37 -0
  177. package/dist/system/ServiceContext.js +48 -0
  178. package/dist/system/ServiceContext.js.map +1 -0
  179. package/dist/system/system-index.d.ts +1 -1
  180. package/dist/system/system-index.js +1 -1
  181. package/dist/system/system-index.js.map +1 -1
  182. package/dist/util/config/collectors/config-collector.d.ts +12 -0
  183. package/dist/util/config/collectors/config-collector.js +43 -0
  184. package/dist/util/config/collectors/config-collector.js.map +1 -1
  185. package/dist/util/config/compound-config-collector.d.ts +10 -29
  186. package/dist/util/config/compound-config-collector.js +28 -84
  187. package/dist/util/config/compound-config-collector.js.map +1 -1
  188. package/dist/util/config/sync-rules/sync-rules-provider.d.ts +9 -0
  189. package/dist/util/config/sync-rules/sync-rules-provider.js +15 -0
  190. package/dist/util/config/sync-rules/sync-rules-provider.js.map +1 -0
  191. package/dist/util/config/types.d.ts +6 -4
  192. package/dist/util/config/types.js.map +1 -1
  193. package/dist/util/config.d.ts +3 -4
  194. package/dist/util/config.js +5 -20
  195. package/dist/util/config.js.map +1 -1
  196. package/dist/util/protocol-types.d.ts +4 -0
  197. package/dist/util/protocol-types.js +5 -1
  198. package/dist/util/protocol-types.js.map +1 -1
  199. package/dist/util/util-index.d.ts +3 -6
  200. package/dist/util/util-index.js +3 -6
  201. package/dist/util/util-index.js.map +1 -1
  202. package/dist/util/utils.d.ts +10 -6
  203. package/dist/util/utils.js +45 -25
  204. package/dist/util/utils.js.map +1 -1
  205. package/package.json +7 -7
  206. package/src/api/RouteAPI.ts +78 -0
  207. package/src/api/api-index.ts +1 -0
  208. package/src/api/diagnostics.ts +16 -71
  209. package/src/api/schema.ts +13 -89
  210. package/src/auth/KeyStore.ts +9 -6
  211. package/src/auth/auth-index.ts +0 -1
  212. package/src/entry/cli-entry.ts +4 -2
  213. package/src/entry/commands/compact-action.ts +57 -0
  214. package/src/entry/commands/migrate-action.ts +5 -8
  215. package/src/entry/commands/teardown-action.ts +2 -2
  216. package/src/entry/entry-index.ts +1 -0
  217. package/src/index.ts +5 -2
  218. package/src/metrics/Metrics.ts +70 -15
  219. package/src/migrations/db/migrations/1684951997326-init.ts +9 -4
  220. package/src/migrations/db/migrations/1702295701188-sync-rule-state.ts +7 -4
  221. package/src/migrations/db/migrations/1711543888062-write-checkpoint-index.ts +6 -4
  222. package/src/migrations/migrations.ts +24 -8
  223. package/src/modules/AbstractModule.ts +37 -0
  224. package/src/modules/ModuleManager.ts +34 -0
  225. package/src/modules/modules-index.ts +2 -0
  226. package/src/replication/AbstractReplicationJob.ts +79 -0
  227. package/src/replication/AbstractReplicator.ts +227 -0
  228. package/src/replication/ErrorRateLimiter.ts +0 -44
  229. package/src/replication/ReplicationEngine.ts +43 -0
  230. package/src/replication/ReplicationModule.ts +101 -0
  231. package/src/replication/replication-index.ts +4 -6
  232. package/src/routes/RouterEngine.ts +120 -0
  233. package/src/routes/auth.ts +21 -12
  234. package/src/routes/configure-fastify.ts +101 -0
  235. package/src/routes/configure-rsocket.ts +60 -0
  236. package/src/routes/endpoints/admin.ts +74 -100
  237. package/src/routes/endpoints/checkpointing.ts +46 -12
  238. package/src/routes/endpoints/route-endpoints-index.ts +0 -1
  239. package/src/routes/endpoints/socket-route.ts +50 -42
  240. package/src/routes/endpoints/sync-rules.ts +41 -25
  241. package/src/routes/endpoints/sync-stream.ts +17 -13
  242. package/src/routes/route-register.ts +2 -2
  243. package/src/routes/router-socket.ts +6 -5
  244. package/src/routes/router.ts +7 -2
  245. package/src/routes/routes-index.ts +3 -0
  246. package/src/runner/teardown.ts +50 -88
  247. package/src/storage/BucketStorage.ts +74 -26
  248. package/src/storage/MongoBucketStorage.ts +23 -26
  249. package/src/storage/SourceEntity.ts +22 -0
  250. package/src/storage/SourceTable.ts +4 -6
  251. package/src/storage/StorageEngine.ts +55 -0
  252. package/src/storage/StorageProvider.ts +27 -0
  253. package/src/storage/mongo/MongoBucketBatch.ts +8 -8
  254. package/src/storage/mongo/MongoCompactor.ts +372 -0
  255. package/src/storage/mongo/MongoPersistedSyncRulesContent.ts +3 -3
  256. package/src/storage/mongo/MongoStorageProvider.ts +31 -0
  257. package/src/storage/mongo/MongoSyncBucketStorage.ts +64 -34
  258. package/src/storage/mongo/MongoSyncRulesLock.ts +1 -1
  259. package/src/storage/mongo/OperationBatch.ts +18 -11
  260. package/src/storage/mongo/PersistedBatch.ts +6 -5
  261. package/src/storage/mongo/models.ts +17 -7
  262. package/src/storage/mongo/util.ts +71 -1
  263. package/src/storage/storage-index.ts +5 -2
  264. package/src/sync/RequestTracker.ts +3 -3
  265. package/src/sync/sync-index.ts +1 -0
  266. package/src/sync/sync.ts +66 -17
  267. package/src/system/ServiceContext.ts +68 -0
  268. package/src/system/system-index.ts +1 -1
  269. package/src/util/config/collectors/config-collector.ts +48 -0
  270. package/src/util/config/compound-config-collector.ts +45 -110
  271. package/src/util/config/sync-rules/sync-rules-provider.ts +18 -0
  272. package/src/util/config/types.ts +6 -5
  273. package/src/util/config.ts +6 -23
  274. package/src/util/protocol-types.ts +6 -1
  275. package/src/util/util-index.ts +3 -6
  276. package/src/util/utils.ts +55 -39
  277. package/test/src/__snapshots__/sync.test.ts.snap +90 -5
  278. package/test/src/auth.test.ts +7 -7
  279. package/test/src/broadcast_iterable.test.ts +1 -1
  280. package/test/src/bucket_validation.test.ts +142 -0
  281. package/test/src/bucket_validation.ts +116 -0
  282. package/test/src/checksum_cache.test.ts +3 -3
  283. package/test/src/compacting.test.ts +216 -0
  284. package/test/src/data_storage.test.ts +275 -204
  285. package/test/src/env.ts +1 -3
  286. package/test/src/merge_iterable.test.ts +1 -6
  287. package/test/src/setup.ts +1 -1
  288. package/test/src/stream_utils.ts +42 -0
  289. package/test/src/sync.test.ts +209 -48
  290. package/test/src/util.ts +110 -55
  291. package/test/tsconfig.json +1 -1
  292. package/tsconfig.tsbuildinfo +1 -1
  293. package/dist/auth/SupabaseKeyCollector.d.ts +0 -22
  294. package/dist/auth/SupabaseKeyCollector.js +0 -61
  295. package/dist/auth/SupabaseKeyCollector.js.map +0 -1
  296. package/dist/replication/PgRelation.d.ts +0 -16
  297. package/dist/replication/PgRelation.js +0 -26
  298. package/dist/replication/PgRelation.js.map +0 -1
  299. package/dist/replication/WalConnection.d.ts +0 -34
  300. package/dist/replication/WalConnection.js +0 -190
  301. package/dist/replication/WalConnection.js.map +0 -1
  302. package/dist/replication/WalStream.d.ts +0 -57
  303. package/dist/replication/WalStream.js +0 -517
  304. package/dist/replication/WalStream.js.map +0 -1
  305. package/dist/replication/WalStreamManager.d.ts +0 -30
  306. package/dist/replication/WalStreamManager.js +0 -198
  307. package/dist/replication/WalStreamManager.js.map +0 -1
  308. package/dist/replication/WalStreamRunner.d.ts +0 -38
  309. package/dist/replication/WalStreamRunner.js +0 -155
  310. package/dist/replication/WalStreamRunner.js.map +0 -1
  311. package/dist/replication/util.d.ts +0 -9
  312. package/dist/replication/util.js +0 -62
  313. package/dist/replication/util.js.map +0 -1
  314. package/dist/routes/endpoints/dev.d.ts +0 -312
  315. package/dist/routes/endpoints/dev.js +0 -172
  316. package/dist/routes/endpoints/dev.js.map +0 -1
  317. package/dist/system/CorePowerSyncSystem.d.ts +0 -23
  318. package/dist/system/CorePowerSyncSystem.js +0 -52
  319. package/dist/system/CorePowerSyncSystem.js.map +0 -1
  320. package/dist/util/PgManager.d.ts +0 -24
  321. package/dist/util/PgManager.js +0 -55
  322. package/dist/util/PgManager.js.map +0 -1
  323. package/dist/util/migration_lib.d.ts +0 -11
  324. package/dist/util/migration_lib.js +0 -64
  325. package/dist/util/migration_lib.js.map +0 -1
  326. package/dist/util/pgwire_utils.d.ts +0 -24
  327. package/dist/util/pgwire_utils.js +0 -117
  328. package/dist/util/pgwire_utils.js.map +0 -1
  329. package/dist/util/populate_test_data.d.ts +0 -8
  330. package/dist/util/populate_test_data.js +0 -65
  331. package/dist/util/populate_test_data.js.map +0 -1
  332. package/src/auth/SupabaseKeyCollector.ts +0 -67
  333. package/src/replication/PgRelation.ts +0 -42
  334. package/src/replication/WalConnection.ts +0 -227
  335. package/src/replication/WalStream.ts +0 -628
  336. package/src/replication/WalStreamManager.ts +0 -213
  337. package/src/replication/WalStreamRunner.ts +0 -180
  338. package/src/replication/util.ts +0 -76
  339. package/src/routes/endpoints/dev.ts +0 -199
  340. package/src/system/CorePowerSyncSystem.ts +0 -64
  341. package/src/util/PgManager.ts +0 -64
  342. package/src/util/migration_lib.ts +0 -79
  343. package/src/util/pgwire_utils.ts +0 -139
  344. package/src/util/populate_test_data.ts +0 -78
  345. package/test/src/__snapshots__/pg_test.test.ts.snap +0 -256
  346. package/test/src/large_batch.test.ts +0 -194
  347. package/test/src/pg_test.test.ts +0 -450
  348. package/test/src/schema_changes.test.ts +0 -545
  349. package/test/src/slow_tests.test.ts +0 -296
  350. package/test/src/validation.test.ts +0 -63
  351. package/test/src/wal_stream.test.ts +0 -314
  352. package/test/src/wal_stream_utils.ts +0 -147
@@ -1,312 +0,0 @@
1
- import { router, schema } from '@powersync/lib-services-framework';
2
- export declare const auth: router.Endpoint<{
3
- password: string;
4
- user: string;
5
- }, {
6
- token: string;
7
- user_id: string;
8
- endpoint: string;
9
- }, import("../router.js").Context, import("../router.js").RequestEndpointHandlerPayload<{
10
- password: string;
11
- user: string;
12
- }, import("../router.js").Context, import("../router.js").BasicRouterRequest>, router.EndpointHandler<import("../router.js").RequestEndpointHandlerPayload<{
13
- password: string;
14
- user: string;
15
- }, import("../router.js").Context, import("../router.js").BasicRouterRequest>, {
16
- token: string;
17
- user_id: string;
18
- endpoint: string;
19
- }>> & {
20
- path: string;
21
- method: router.HTTPMethod.POST;
22
- validator: schema.MicroValidator<{
23
- password: string;
24
- user: string;
25
- }, string[]>;
26
- handler: (payload: import("../router.js").RequestEndpointHandlerPayload<{
27
- password: string;
28
- user: string;
29
- }, import("../router.js").Context, import("../router.js").BasicRouterRequest>) => Promise<{
30
- token: string;
31
- user_id: string;
32
- endpoint: string;
33
- }>;
34
- };
35
- export declare const auth2: router.Endpoint<{
36
- password: string;
37
- user: string;
38
- }, {
39
- token: string;
40
- user_id: string;
41
- }, import("../router.js").Context, import("../router.js").RequestEndpointHandlerPayload<{
42
- password: string;
43
- user: string;
44
- }, import("../router.js").Context, import("../router.js").BasicRouterRequest>, router.EndpointHandler<import("../router.js").RequestEndpointHandlerPayload<{
45
- password: string;
46
- user: string;
47
- }, import("../router.js").Context, import("../router.js").BasicRouterRequest>, {
48
- token: string;
49
- user_id: string;
50
- }>> & {
51
- path: string;
52
- method: router.HTTPMethod.POST;
53
- validator: schema.MicroValidator<{
54
- password: string;
55
- user: string;
56
- }, string[]>;
57
- handler: (payload: import("../router.js").RequestEndpointHandlerPayload<{
58
- password: string;
59
- user: string;
60
- }, import("../router.js").Context, import("../router.js").BasicRouterRequest>) => Promise<{
61
- token: string;
62
- user_id: string;
63
- }>;
64
- };
65
- export declare const token: router.Endpoint<{}, {
66
- token: string;
67
- user_id: string | undefined;
68
- endpoint: string;
69
- }, import("../router.js").Context, import("../router.js").RequestEndpointHandlerPayload<{}, import("../router.js").Context, import("../router.js").BasicRouterRequest>, router.EndpointHandler<import("../router.js").RequestEndpointHandlerPayload<{}, import("../router.js").Context, import("../router.js").BasicRouterRequest>, {
70
- token: string;
71
- user_id: string | undefined;
72
- endpoint: string;
73
- }>> & {
74
- path: string;
75
- method: router.HTTPMethod.POST;
76
- validator: schema.MicroValidator<{}, string[]>;
77
- authorize: (payload: import("../router.js").RequestEndpointHandlerPayload) => Promise<{
78
- authorized: boolean;
79
- errors: any[];
80
- } | {
81
- authorized: boolean;
82
- errors?: undefined;
83
- }>;
84
- handler: (payload: import("../router.js").RequestEndpointHandlerPayload<{}, import("../router.js").Context, import("../router.js").BasicRouterRequest>) => Promise<{
85
- token: string;
86
- user_id: string | undefined;
87
- endpoint: string;
88
- }>;
89
- };
90
- export declare const crud: router.Endpoint<{
91
- data: {
92
- type: string;
93
- id: string;
94
- op: string;
95
- data?: any;
96
- op_id?: number | undefined;
97
- }[];
98
- write_checkpoint?: boolean | undefined;
99
- }, {
100
- write_checkpoint: string;
101
- checkpoint?: undefined;
102
- } | {
103
- write_checkpoint?: undefined;
104
- checkpoint?: undefined;
105
- } | {
106
- checkpoint: string;
107
- write_checkpoint?: undefined;
108
- }, import("../router.js").Context, import("../router.js").RequestEndpointHandlerPayload<{
109
- data: {
110
- type: string;
111
- id: string;
112
- op: string;
113
- data?: any;
114
- op_id?: number | undefined;
115
- }[];
116
- write_checkpoint?: boolean | undefined;
117
- }, import("../router.js").Context, import("../router.js").BasicRouterRequest>, router.EndpointHandler<import("../router.js").RequestEndpointHandlerPayload<{
118
- data: {
119
- type: string;
120
- id: string;
121
- op: string;
122
- data?: any;
123
- op_id?: number | undefined;
124
- }[];
125
- write_checkpoint?: boolean | undefined;
126
- }, import("../router.js").Context, import("../router.js").BasicRouterRequest>, {
127
- write_checkpoint: string;
128
- checkpoint?: undefined;
129
- } | {
130
- write_checkpoint?: undefined;
131
- checkpoint?: undefined;
132
- } | {
133
- checkpoint: string;
134
- write_checkpoint?: undefined;
135
- }>> & {
136
- path: string;
137
- method: router.HTTPMethod.POST;
138
- validator: schema.MicroValidator<{
139
- data: {
140
- type: string;
141
- id: string;
142
- op: string;
143
- data?: any;
144
- op_id?: number | undefined;
145
- }[];
146
- write_checkpoint?: boolean | undefined;
147
- }, string[]>;
148
- authorize: (payload: import("../router.js").RequestEndpointHandlerPayload) => Promise<{
149
- authorized: boolean;
150
- errors: any[];
151
- } | {
152
- authorized: boolean;
153
- errors?: undefined;
154
- }>;
155
- handler: (payload: import("../router.js").RequestEndpointHandlerPayload<{
156
- data: {
157
- type: string;
158
- id: string;
159
- op: string;
160
- data?: any;
161
- op_id?: number | undefined;
162
- }[];
163
- write_checkpoint?: boolean | undefined;
164
- }, import("../router.js").Context, import("../router.js").BasicRouterRequest>) => Promise<{
165
- write_checkpoint: string;
166
- checkpoint?: undefined;
167
- } | {
168
- write_checkpoint?: undefined;
169
- checkpoint?: undefined;
170
- } | {
171
- checkpoint: string;
172
- write_checkpoint?: undefined;
173
- }>;
174
- };
175
- export declare const DEV_ROUTES: ((router.Endpoint<{
176
- password: string;
177
- user: string;
178
- }, {
179
- token: string;
180
- user_id: string;
181
- }, import("../router.js").Context, import("../router.js").RequestEndpointHandlerPayload<{
182
- password: string;
183
- user: string;
184
- }, import("../router.js").Context, import("../router.js").BasicRouterRequest>, router.EndpointHandler<import("../router.js").RequestEndpointHandlerPayload<{
185
- password: string;
186
- user: string;
187
- }, import("../router.js").Context, import("../router.js").BasicRouterRequest>, {
188
- token: string;
189
- user_id: string;
190
- }>> & {
191
- path: string;
192
- method: router.HTTPMethod.POST;
193
- validator: schema.MicroValidator<{
194
- password: string;
195
- user: string;
196
- }, string[]>;
197
- handler: (payload: import("../router.js").RequestEndpointHandlerPayload<{
198
- password: string;
199
- user: string;
200
- }, import("../router.js").Context, import("../router.js").BasicRouterRequest>) => Promise<{
201
- token: string;
202
- user_id: string;
203
- }>;
204
- }) | (router.Endpoint<{}, {
205
- token: string;
206
- user_id: string | undefined;
207
- endpoint: string;
208
- }, import("../router.js").Context, import("../router.js").RequestEndpointHandlerPayload<{}, import("../router.js").Context, import("../router.js").BasicRouterRequest>, router.EndpointHandler<import("../router.js").RequestEndpointHandlerPayload<{}, import("../router.js").Context, import("../router.js").BasicRouterRequest>, {
209
- token: string;
210
- user_id: string | undefined;
211
- endpoint: string;
212
- }>> & {
213
- path: string;
214
- method: router.HTTPMethod.POST;
215
- validator: schema.MicroValidator<{}, string[]>;
216
- authorize: (payload: import("../router.js").RequestEndpointHandlerPayload) => Promise<{
217
- authorized: boolean;
218
- errors: any[];
219
- } | {
220
- authorized: boolean;
221
- errors?: undefined;
222
- }>;
223
- handler: (payload: import("../router.js").RequestEndpointHandlerPayload<{}, import("../router.js").Context, import("../router.js").BasicRouterRequest>) => Promise<{
224
- token: string;
225
- user_id: string | undefined;
226
- endpoint: string;
227
- }>;
228
- }) | (router.Endpoint<{
229
- data: {
230
- type: string;
231
- id: string;
232
- op: string;
233
- data?: any;
234
- op_id?: number | undefined;
235
- }[];
236
- write_checkpoint?: boolean | undefined;
237
- }, {
238
- write_checkpoint: string;
239
- checkpoint?: undefined;
240
- } | {
241
- write_checkpoint?: undefined;
242
- checkpoint?: undefined;
243
- } | {
244
- checkpoint: string;
245
- write_checkpoint?: undefined;
246
- }, import("../router.js").Context, import("../router.js").RequestEndpointHandlerPayload<{
247
- data: {
248
- type: string;
249
- id: string;
250
- op: string;
251
- data?: any;
252
- op_id?: number | undefined;
253
- }[];
254
- write_checkpoint?: boolean | undefined;
255
- }, import("../router.js").Context, import("../router.js").BasicRouterRequest>, router.EndpointHandler<import("../router.js").RequestEndpointHandlerPayload<{
256
- data: {
257
- type: string;
258
- id: string;
259
- op: string;
260
- data?: any;
261
- op_id?: number | undefined;
262
- }[];
263
- write_checkpoint?: boolean | undefined;
264
- }, import("../router.js").Context, import("../router.js").BasicRouterRequest>, {
265
- write_checkpoint: string;
266
- checkpoint?: undefined;
267
- } | {
268
- write_checkpoint?: undefined;
269
- checkpoint?: undefined;
270
- } | {
271
- checkpoint: string;
272
- write_checkpoint?: undefined;
273
- }>> & {
274
- path: string;
275
- method: router.HTTPMethod.POST;
276
- validator: schema.MicroValidator<{
277
- data: {
278
- type: string;
279
- id: string;
280
- op: string;
281
- data?: any;
282
- op_id?: number | undefined;
283
- }[];
284
- write_checkpoint?: boolean | undefined;
285
- }, string[]>;
286
- authorize: (payload: import("../router.js").RequestEndpointHandlerPayload) => Promise<{
287
- authorized: boolean;
288
- errors: any[];
289
- } | {
290
- authorized: boolean;
291
- errors?: undefined;
292
- }>;
293
- handler: (payload: import("../router.js").RequestEndpointHandlerPayload<{
294
- data: {
295
- type: string;
296
- id: string;
297
- op: string;
298
- data?: any;
299
- op_id?: number | undefined;
300
- }[];
301
- write_checkpoint?: boolean | undefined;
302
- }, import("../router.js").Context, import("../router.js").BasicRouterRequest>) => Promise<{
303
- write_checkpoint: string;
304
- checkpoint?: undefined;
305
- } | {
306
- write_checkpoint?: undefined;
307
- checkpoint?: undefined;
308
- } | {
309
- checkpoint: string;
310
- write_checkpoint?: undefined;
311
- }>;
312
- }))[];
@@ -1,172 +0,0 @@
1
- import * as t from 'ts-codec';
2
- import { errors, router, schema } from '@powersync/lib-services-framework';
3
- import * as util from '../../util/util-index.js';
4
- import { authDevUser, authUser, endpoint, issueDevToken, issueLegacyDevToken, issuePowerSyncToken } from '../auth.js';
5
- import { routeDefinition } from '../router.js';
6
- const AuthParams = t.object({
7
- user: t.string,
8
- password: t.string
9
- });
10
- // For legacy web client only. Remove soon.
11
- export const auth = routeDefinition({
12
- path: '/auth.json',
13
- method: router.HTTPMethod.POST,
14
- validator: schema.createTsCodecValidator(AuthParams, { allowAdditional: true }),
15
- handler: async (payload) => {
16
- const { user, password } = payload.params;
17
- const config = payload.context.system.config;
18
- if (config.dev.demo_auth == false || config.dev.demo_password == null) {
19
- throw new errors.AuthorizationError(['Demo auth disabled']);
20
- }
21
- if (password == config.dev.demo_password) {
22
- const token = await issueLegacyDevToken(payload.request, user, payload.context.system.config);
23
- return { token, user_id: user, endpoint: endpoint(payload.request) };
24
- }
25
- else {
26
- throw new errors.AuthorizationError(['Authentication failed']);
27
- }
28
- }
29
- });
30
- export const auth2 = routeDefinition({
31
- path: '/dev/auth.json',
32
- method: router.HTTPMethod.POST,
33
- validator: schema.createTsCodecValidator(AuthParams, { allowAdditional: true }),
34
- handler: async (payload) => {
35
- const { user, password } = payload.params;
36
- const config = payload.context.system.config;
37
- if (config.dev.demo_auth == false || config.dev.demo_password == null) {
38
- throw new errors.AuthorizationError(['Demo auth disabled']);
39
- }
40
- if (password == config.dev.demo_password) {
41
- const token = await issueDevToken(payload.request, user, payload.context.system.config);
42
- return { token, user_id: user };
43
- }
44
- else {
45
- throw new errors.AuthorizationError(['Authentication failed']);
46
- }
47
- }
48
- });
49
- const TokenParams = t.object({});
50
- export const token = routeDefinition({
51
- path: '/dev/token.json',
52
- method: router.HTTPMethod.POST,
53
- validator: schema.createTsCodecValidator(TokenParams, { allowAdditional: true }),
54
- authorize: authDevUser,
55
- handler: async (payload) => {
56
- const { user_id } = payload.context;
57
- const outToken = await issuePowerSyncToken(payload.request, user_id, payload.context.system.config);
58
- return { token: outToken, user_id: user_id, endpoint: endpoint(payload.request) };
59
- }
60
- });
61
- const OpType = {
62
- PUT: 'PUT',
63
- PATCH: 'PATCH',
64
- DELETE: 'DELETE'
65
- };
66
- const CrudEntry = t.object({
67
- op: t.Enum(OpType),
68
- type: t.string,
69
- id: t.string,
70
- op_id: t.number.optional(),
71
- data: t.any.optional()
72
- });
73
- const CrudRequest = t.object({
74
- data: t.array(CrudEntry),
75
- write_checkpoint: t.boolean.optional()
76
- });
77
- export const crud = routeDefinition({
78
- path: '/crud.json',
79
- method: router.HTTPMethod.POST,
80
- validator: schema.createTsCodecValidator(CrudRequest, { allowAdditional: true }),
81
- authorize: authUser,
82
- handler: async (payload) => {
83
- const { user_id, system } = payload.context;
84
- const pool = system.requirePgPool();
85
- if (!system.config.dev.crud_api) {
86
- throw new Error('CRUD api disabled');
87
- }
88
- const params = payload.params;
89
- let statements = [];
90
- // Implementation note:
91
- // Postgres does automatic "assigment cast" for query literals,
92
- // e.g. a string literal to uuid. However, the same doesn't apply
93
- // to query parameters.
94
- // To handle those automatically, we use `json_populate_record`
95
- // to automatically cast to the correct types.
96
- for (let op of params.data) {
97
- const table = util.escapeIdentifier(op.type);
98
- if (op.op == 'PUT') {
99
- const data = op.data;
100
- const with_id = { ...data, id: op.id };
101
- const columnsEscaped = Object.keys(with_id).map(util.escapeIdentifier);
102
- const columnsJoined = columnsEscaped.join(', ');
103
- let updateClauses = [];
104
- for (let key of Object.keys(data)) {
105
- updateClauses.push(`${util.escapeIdentifier(key)} = EXCLUDED.${util.escapeIdentifier(key)}`);
106
- }
107
- const updateClause = updateClauses.length > 0 ? `DO UPDATE SET ${updateClauses.join(', ')}` : `DO NOTHING`;
108
- const statement = `
109
- WITH data_row AS (
110
- SELECT (json_populate_record(null::${table}, $1::json)).*
111
- )
112
- INSERT INTO ${table} (${columnsJoined})
113
- SELECT ${columnsJoined} FROM data_row
114
- ON CONFLICT(id) ${updateClause}`;
115
- statements.push({
116
- statement: statement,
117
- params: [{ type: 'varchar', value: JSON.stringify(with_id) }]
118
- });
119
- }
120
- else if (op.op == 'PATCH') {
121
- const data = op.data;
122
- const with_id = { ...data, id: op.id };
123
- let updateClauses = [];
124
- for (let key of Object.keys(data)) {
125
- updateClauses.push(`${util.escapeIdentifier(key)} = data_row.${util.escapeIdentifier(key)}`);
126
- }
127
- const statement = `
128
- WITH data_row AS (
129
- SELECT (json_populate_record(null::${table}, $1::json)).*
130
- )
131
- UPDATE ${table}
132
- SET ${updateClauses.join(', ')}
133
- FROM data_row
134
- WHERE ${table}.id = data_row.id`;
135
- statements.push({
136
- statement: statement,
137
- params: [{ type: 'varchar', value: JSON.stringify(with_id) }]
138
- });
139
- }
140
- else if (op.op == 'DELETE') {
141
- statements.push({
142
- statement: `
143
- WITH data_row AS (
144
- SELECT (json_populate_record(null::${table}, $1::json)).*
145
- )
146
- DELETE FROM ${table}
147
- USING data_row
148
- WHERE ${table}.id = data_row.id`,
149
- params: [{ type: 'varchar', value: JSON.stringify({ id: op.id }) }]
150
- });
151
- }
152
- }
153
- await pool.query(...statements);
154
- const storage = system.storage;
155
- if (payload.params.write_checkpoint === true) {
156
- const write_checkpoint = await util.createWriteCheckpoint(pool, storage, payload.context.user_id);
157
- return { write_checkpoint: String(write_checkpoint) };
158
- }
159
- else if (payload.params.write_checkpoint === false) {
160
- return {};
161
- }
162
- else {
163
- // Legacy
164
- const checkpoint = await util.getClientCheckpoint(pool, storage);
165
- return {
166
- checkpoint
167
- };
168
- }
169
- }
170
- });
171
- export const DEV_ROUTES = [auth, auth2, token, crud];
172
- //# sourceMappingURL=dev.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dev.js","sourceRoot":"","sources":["../../../src/routes/endpoints/dev.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAE9B,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAE3E,OAAO,KAAK,IAAI,MAAM,0BAA0B,CAAC;AACjD,OAAO,EAAE,WAAW,E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,IAAI,CAAC,CAAC"}
@@ -1,23 +0,0 @@
1
- import * as pgwire from '@powersync/service-jpgwire';
2
- import { LifeCycledSystem } from '@powersync/lib-services-framework';
3
- import * as storage from '../storage/storage-index.js';
4
- import * as utils from '../util/util-index.js';
5
- export declare abstract class CorePowerSyncSystem extends LifeCycledSystem {
6
- config: utils.ResolvedPowerSyncConfig;
7
- abstract storage: storage.BucketStorageFactory;
8
- abstract pgwire_pool?: pgwire.PgClient;
9
- closed: boolean;
10
- protected stopHandlers: Set<() => void>;
11
- constructor(config: utils.ResolvedPowerSyncConfig);
12
- get client_keystore(): import("../index.js").KeyStore;
13
- get dev_client_keystore(): import("../index.js").KeyStore;
14
- /**
15
- * Adds a termination handler which will call handlers registered via
16
- * [addStopHandler].
17
- * This should be called after the server is started and it's termination handler is added.
18
- * This is so that the handler is run before the server's handler, allowing streams to be interrupted on exit
19
- */
20
- addTerminationHandler(): void;
21
- addStopHandler(handler: () => void): () => void;
22
- requirePgPool(): pgwire.PgClient;
23
- }
@@ -1,52 +0,0 @@
1
- import { LifeCycledSystem, container, logger } from '@powersync/lib-services-framework';
2
- export class CorePowerSyncSystem extends LifeCycledSystem {
3
- constructor(config) {
4
- super();
5
- this.config = config;
6
- this.stopHandlers = new Set();
7
- this.closed = false;
8
- }
9
- get client_keystore() {
10
- return this.config.client_keystore;
11
- }
12
- get dev_client_keystore() {
13
- return this.config.dev_client_keystore;
14
- }
15
- /**
16
- * Adds a termination handler which will call handlers registered via
17
- * [addStopHandler].
18
- * This should be called after the server is started and it's termination handler is added.
19
- * This is so that the handler is run before the server's handler, allowing streams to be interrupted on exit
20
- */
21
- addTerminationHandler() {
22
- container.terminationHandler.handleTerminationSignal(async () => {
23
- // Close open streams, so that they don't block the server from closing.
24
- // Note: This does not work well when streaming requests are queued. In that case, the server still doesn't
25
- // close in the 30-second timeout.
26
- this.closed = true;
27
- logger.info(`Closing ${this.stopHandlers.size} streams`);
28
- for (let handler of this.stopHandlers) {
29
- handler();
30
- }
31
- });
32
- }
33
- addStopHandler(handler) {
34
- if (this.closed) {
35
- handler();
36
- return () => { };
37
- }
38
- this.stopHandlers.add(handler);
39
- return () => {
40
- this.stopHandlers.delete(handler);
41
- };
42
- }
43
- requirePgPool() {
44
- if (this.pgwire_pool == null) {
45
- throw new Error('No source connection configured');
46
- }
47
- else {
48
- return this.pgwire_pool;
49
- }
50
- }
51
- }
52
- //# sourceMappingURL=CorePowerSyncSystem.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CorePowerSyncSystem.js","sourceRoot":"","sources":["../../src/system/CorePowerSyncSystem.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAKxF,MAAM,OAAgB,mBAAoB,SAAQ,gBAAgB;IAOhE,YAAmB,MAAqC;QACtD,KAAK,EAAE,CAAC;QADS,WAAM,GAAN,MAAM,CAA+B;QAF9C,iBAAY,GAAoB,IAAI,GAAG,EAAE,CAAC;QAIlD,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,IAAI,eAAe;QACjB,OAAO,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC;IACrC,CAAC;IAED,IAAI,mBAAmB;QACrB,OAAO,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC;IACzC,CAAC;IAED;;;;;OAKG;IACH,qBAAqB;QACnB,SAAS,CAAC,kBAAkB,CAAC,uBAAuB,CAAC,KAAK,IAAI,EAAE;YAC9D,wEAAwE;YACxE,2GAA2G;YAC3G,kCAAkC;YAClC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;YACnB,MAAM,CAAC,IAAI,CAAC,WAAW,IAAI,CAAC,YAAY,CAAC,IAAI,UAAU,CAAC,CAAC;YACzD,KAAK,IAAI,OAAO,IAAI,IAAI,CAAC,YAAY,EAAE;gBACrC,OAAO,EAAE,CAAC;aACX;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,cAAc,CAAC,OAAmB;QAChC,IAAI,IAAI,CAAC,MAAM,EAAE;YACf,OAAO,EAAE,CAAC;YACV,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC;SACjB;QACD,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC/B,OAAO,GAAG,EAAE;YACV,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACpC,CAAC,CAAC;IACJ,CAAC;IAED,aAAa;QACX,IAAI,IAAI,CAAC,WAAW,IAAI,IAAI,EAAE;YAC5B,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;SACpD;aAAM;YACL,OAAO,IAAI,CAAC,WAAY,CAAC;SAC1B;IACH,CAAC;CACF"}
@@ -1,24 +0,0 @@
1
- import * as pgwire from '@powersync/service-jpgwire';
2
- import { NormalizedPostgresConnection } from '@powersync/service-types';
3
- export declare class PgManager {
4
- options: NormalizedPostgresConnection;
5
- poolOptions: pgwire.PgPoolOptions;
6
- /**
7
- * Do not use this for any transactions.
8
- */
9
- readonly pool: pgwire.PgClient;
10
- private connectionPromises;
11
- constructor(options: NormalizedPostgresConnection, poolOptions: pgwire.PgPoolOptions);
12
- /**
13
- * Create a new replication connection.
14
- */
15
- replicationConnection(): Promise<pgwire.PgConnection>;
16
- /**
17
- * Create a new standard connection, used for initial snapshot.
18
- *
19
- * This connection must not be shared between multiple async contexts.
20
- */
21
- snapshotConnection(): Promise<pgwire.PgConnection>;
22
- end(): Promise<void>;
23
- destroy(): Promise<void>;
24
- }
@@ -1,55 +0,0 @@
1
- import * as pgwire from '@powersync/service-jpgwire';
2
- export class PgManager {
3
- constructor(options, poolOptions) {
4
- this.options = options;
5
- this.poolOptions = poolOptions;
6
- this.connectionPromises = [];
7
- // The pool is lazy - no connections are opened until a query is performed.
8
- this.pool = pgwire.connectPgWirePool(this.options, poolOptions);
9
- }
10
- /**
11
- * Create a new replication connection.
12
- */
13
- async replicationConnection() {
14
- const p = pgwire.connectPgWire(this.options, { type: 'replication' });
15
- this.connectionPromises.push(p);
16
- return await p;
17
- }
18
- /**
19
- * Create a new standard connection, used for initial snapshot.
20
- *
21
- * This connection must not be shared between multiple async contexts.
22
- */
23
- async snapshotConnection() {
24
- const p = pgwire.connectPgWire(this.options, { type: 'standard' });
25
- this.connectionPromises.push(p);
26
- return await p;
27
- }
28
- async end() {
29
- for (let result of await Promise.allSettled([
30
- this.pool.end(),
31
- ...this.connectionPromises.map((promise) => {
32
- return promise.then((connection) => connection.end());
33
- })
34
- ])) {
35
- // Throw the first error, if any
36
- if (result.status == 'rejected') {
37
- throw result.reason;
38
- }
39
- }
40
- }
41
- async destroy() {
42
- this.pool.destroy();
43
- for (let result of await Promise.allSettled([
44
- ...this.connectionPromises.map((promise) => {
45
- return promise.then((connection) => connection.destroy());
46
- })
47
- ])) {
48
- // Throw the first error, if any
49
- if (result.status == 'rejected') {
50
- throw result.reason;
51
- }
52
- }
53
- }
54
- }
55
- //# sourceMappingURL=PgManager.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PgManager.js","sourceRoot":"","sources":["../../src/util/PgManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,4BAA4B,CAAC;AAGrD,MAAM,OAAO,SAAS;IAQpB,YAAmB,OAAqC,EAAS,WAAiC;QAA/E,YAAO,GAAP,OAAO,CAA8B;QAAS,gBAAW,GAAX,WAAW,CAAsB;QAF1F,uBAAkB,GAAmC,EAAE,CAAC;QAG9D,2EAA2E;QAC3E,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IAClE,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,qBAAqB;QACzB,MAAM,CAAC,GAAG,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC,CAAC;QACtE,IAAI,CAAC,kBAAk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AAM,CAAC;aACrB;SACF;IACH,CAAC;CACF"}
@@ -1,11 +0,0 @@
1
- import * as pgwire from '@powersync/service-jpgwire';
2
- export type MigrationFunction = (db: pgwire.PgConnection) => Promise<void>;
3
- export declare class Migrations {
4
- private migrations;
5
- add(id: number, name: string, up: MigrationFunction): void;
6
- up(db: pgwire.PgConnection): Promise<void>;
7
- getCurrentMigration(db: pgwire.PgConnection): Promise<{
8
- id: number;
9
- }>;
10
- ensureMigrationsTable(db: pgwire.PgConnection): Promise<void>;
11
- }