@powersync/service-core 0.0.2

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 (412) hide show
  1. package/.probes/.gitkeep +0 -0
  2. package/CHANGELOG.md +13 -0
  3. package/LICENSE +67 -0
  4. package/README.md +3 -0
  5. package/dist/api/api-index.d.ts +2 -0
  6. package/dist/api/api-index.js +3 -0
  7. package/dist/api/api-index.js.map +1 -0
  8. package/dist/api/diagnostics.d.ts +21 -0
  9. package/dist/api/diagnostics.js +183 -0
  10. package/dist/api/diagnostics.js.map +1 -0
  11. package/dist/api/schema.d.ts +5 -0
  12. package/dist/api/schema.js +88 -0
  13. package/dist/api/schema.js.map +1 -0
  14. package/dist/auth/CachedKeyCollector.d.ts +46 -0
  15. package/dist/auth/CachedKeyCollector.js +116 -0
  16. package/dist/auth/CachedKeyCollector.js.map +1 -0
  17. package/dist/auth/CompoundKeyCollector.d.ts +8 -0
  18. package/dist/auth/CompoundKeyCollector.js +23 -0
  19. package/dist/auth/CompoundKeyCollector.js.map +1 -0
  20. package/dist/auth/JwtPayload.d.ts +10 -0
  21. package/dist/auth/JwtPayload.js +2 -0
  22. package/dist/auth/JwtPayload.js.map +1 -0
  23. package/dist/auth/KeyCollector.d.ts +24 -0
  24. package/dist/auth/KeyCollector.js +2 -0
  25. package/dist/auth/KeyCollector.js.map +1 -0
  26. package/dist/auth/KeySpec.d.ts +26 -0
  27. package/dist/auth/KeySpec.js +49 -0
  28. package/dist/auth/KeySpec.js.map +1 -0
  29. package/dist/auth/KeyStore.d.ts +39 -0
  30. package/dist/auth/KeyStore.js +131 -0
  31. package/dist/auth/KeyStore.js.map +1 -0
  32. package/dist/auth/LeakyBucket.d.ts +39 -0
  33. package/dist/auth/LeakyBucket.js +57 -0
  34. package/dist/auth/LeakyBucket.js.map +1 -0
  35. package/dist/auth/RemoteJWKSCollector.d.ts +24 -0
  36. package/dist/auth/RemoteJWKSCollector.js +106 -0
  37. package/dist/auth/RemoteJWKSCollector.js.map +1 -0
  38. package/dist/auth/StaticKeyCollector.d.ts +14 -0
  39. package/dist/auth/StaticKeyCollector.js +19 -0
  40. package/dist/auth/StaticKeyCollector.js.map +1 -0
  41. package/dist/auth/SupabaseKeyCollector.d.ts +22 -0
  42. package/dist/auth/SupabaseKeyCollector.js +61 -0
  43. package/dist/auth/SupabaseKeyCollector.js.map +1 -0
  44. package/dist/auth/auth-index.d.ts +10 -0
  45. package/dist/auth/auth-index.js +11 -0
  46. package/dist/auth/auth-index.js.map +1 -0
  47. package/dist/db/db-index.d.ts +1 -0
  48. package/dist/db/db-index.js +2 -0
  49. package/dist/db/db-index.js.map +1 -0
  50. package/dist/db/mongo.d.ts +29 -0
  51. package/dist/db/mongo.js +65 -0
  52. package/dist/db/mongo.js.map +1 -0
  53. package/dist/entry/cli-entry.d.ts +15 -0
  54. package/dist/entry/cli-entry.js +36 -0
  55. package/dist/entry/cli-entry.js.map +1 -0
  56. package/dist/entry/commands/config-command.d.ts +10 -0
  57. package/dist/entry/commands/config-command.js +21 -0
  58. package/dist/entry/commands/config-command.js.map +1 -0
  59. package/dist/entry/commands/migrate-action.d.ts +2 -0
  60. package/dist/entry/commands/migrate-action.js +18 -0
  61. package/dist/entry/commands/migrate-action.js.map +1 -0
  62. package/dist/entry/commands/start-action.d.ts +3 -0
  63. package/dist/entry/commands/start-action.js +15 -0
  64. package/dist/entry/commands/start-action.js.map +1 -0
  65. package/dist/entry/commands/teardown-action.d.ts +2 -0
  66. package/dist/entry/commands/teardown-action.js +17 -0
  67. package/dist/entry/commands/teardown-action.js.map +1 -0
  68. package/dist/entry/entry-index.d.ts +5 -0
  69. package/dist/entry/entry-index.js +6 -0
  70. package/dist/entry/entry-index.js.map +1 -0
  71. package/dist/index.d.ts +24 -0
  72. package/dist/index.js +26 -0
  73. package/dist/index.js.map +1 -0
  74. package/dist/metrics/metrics.d.ts +16 -0
  75. package/dist/metrics/metrics.js +139 -0
  76. package/dist/metrics/metrics.js.map +1 -0
  77. package/dist/migrations/db/migrations/1684951997326-init.d.ts +3 -0
  78. package/dist/migrations/db/migrations/1684951997326-init.js +31 -0
  79. package/dist/migrations/db/migrations/1684951997326-init.js.map +1 -0
  80. package/dist/migrations/db/migrations/1688556755264-initial-sync-rules.d.ts +2 -0
  81. package/dist/migrations/db/migrations/1688556755264-initial-sync-rules.js +5 -0
  82. package/dist/migrations/db/migrations/1688556755264-initial-sync-rules.js.map +1 -0
  83. package/dist/migrations/db/migrations/1702295701188-sync-rule-state.d.ts +3 -0
  84. package/dist/migrations/db/migrations/1702295701188-sync-rule-state.js +54 -0
  85. package/dist/migrations/db/migrations/1702295701188-sync-rule-state.js.map +1 -0
  86. package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.d.ts +3 -0
  87. package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.js +27 -0
  88. package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.js.map +1 -0
  89. package/dist/migrations/db/store.d.ts +3 -0
  90. package/dist/migrations/db/store.js +10 -0
  91. package/dist/migrations/db/store.js.map +1 -0
  92. package/dist/migrations/migrations.d.ts +10 -0
  93. package/dist/migrations/migrations.js +94 -0
  94. package/dist/migrations/migrations.js.map +1 -0
  95. package/dist/replication/ErrorRateLimiter.d.ts +17 -0
  96. package/dist/replication/ErrorRateLimiter.js +42 -0
  97. package/dist/replication/ErrorRateLimiter.js.map +1 -0
  98. package/dist/replication/PgRelation.d.ts +16 -0
  99. package/dist/replication/PgRelation.js +26 -0
  100. package/dist/replication/PgRelation.js.map +1 -0
  101. package/dist/replication/WalConnection.d.ts +34 -0
  102. package/dist/replication/WalConnection.js +190 -0
  103. package/dist/replication/WalConnection.js.map +1 -0
  104. package/dist/replication/WalStream.d.ts +58 -0
  105. package/dist/replication/WalStream.js +517 -0
  106. package/dist/replication/WalStream.js.map +1 -0
  107. package/dist/replication/WalStreamManager.d.ts +30 -0
  108. package/dist/replication/WalStreamManager.js +199 -0
  109. package/dist/replication/WalStreamManager.js.map +1 -0
  110. package/dist/replication/WalStreamRunner.d.ts +38 -0
  111. package/dist/replication/WalStreamRunner.js +155 -0
  112. package/dist/replication/WalStreamRunner.js.map +1 -0
  113. package/dist/replication/replication-index.d.ts +7 -0
  114. package/dist/replication/replication-index.js +8 -0
  115. package/dist/replication/replication-index.js.map +1 -0
  116. package/dist/replication/util.d.ts +9 -0
  117. package/dist/replication/util.js +62 -0
  118. package/dist/replication/util.js.map +1 -0
  119. package/dist/routes/admin.d.ts +7 -0
  120. package/dist/routes/admin.js +192 -0
  121. package/dist/routes/admin.js.map +1 -0
  122. package/dist/routes/auth.d.ts +58 -0
  123. package/dist/routes/auth.js +182 -0
  124. package/dist/routes/auth.js.map +1 -0
  125. package/dist/routes/checkpointing.d.ts +3 -0
  126. package/dist/routes/checkpointing.js +30 -0
  127. package/dist/routes/checkpointing.js.map +1 -0
  128. package/dist/routes/dev.d.ts +6 -0
  129. package/dist/routes/dev.js +163 -0
  130. package/dist/routes/dev.js.map +1 -0
  131. package/dist/routes/route-generators.d.ts +15 -0
  132. package/dist/routes/route-generators.js +32 -0
  133. package/dist/routes/route-generators.js.map +1 -0
  134. package/dist/routes/router-socket.d.ts +10 -0
  135. package/dist/routes/router-socket.js +5 -0
  136. package/dist/routes/router-socket.js.map +1 -0
  137. package/dist/routes/router.d.ts +13 -0
  138. package/dist/routes/router.js +2 -0
  139. package/dist/routes/router.js.map +1 -0
  140. package/dist/routes/routes-index.d.ts +4 -0
  141. package/dist/routes/routes-index.js +5 -0
  142. package/dist/routes/routes-index.js.map +1 -0
  143. package/dist/routes/socket-route.d.ts +2 -0
  144. package/dist/routes/socket-route.js +119 -0
  145. package/dist/routes/socket-route.js.map +1 -0
  146. package/dist/routes/sync-rules.d.ts +6 -0
  147. package/dist/routes/sync-rules.js +182 -0
  148. package/dist/routes/sync-rules.js.map +1 -0
  149. package/dist/routes/sync-stream.d.ts +5 -0
  150. package/dist/routes/sync-stream.js +74 -0
  151. package/dist/routes/sync-stream.js.map +1 -0
  152. package/dist/runner/teardown.d.ts +2 -0
  153. package/dist/runner/teardown.js +79 -0
  154. package/dist/runner/teardown.js.map +1 -0
  155. package/dist/storage/BucketStorage.d.ts +298 -0
  156. package/dist/storage/BucketStorage.js +25 -0
  157. package/dist/storage/BucketStorage.js.map +1 -0
  158. package/dist/storage/MongoBucketStorage.d.ts +51 -0
  159. package/dist/storage/MongoBucketStorage.js +388 -0
  160. package/dist/storage/MongoBucketStorage.js.map +1 -0
  161. package/dist/storage/SourceTable.d.ts +39 -0
  162. package/dist/storage/SourceTable.js +50 -0
  163. package/dist/storage/SourceTable.js.map +1 -0
  164. package/dist/storage/mongo/MongoBucketBatch.d.ts +48 -0
  165. package/dist/storage/mongo/MongoBucketBatch.js +584 -0
  166. package/dist/storage/mongo/MongoBucketBatch.js.map +1 -0
  167. package/dist/storage/mongo/MongoIdSequence.d.ts +12 -0
  168. package/dist/storage/mongo/MongoIdSequence.js +21 -0
  169. package/dist/storage/mongo/MongoIdSequence.js.map +1 -0
  170. package/dist/storage/mongo/MongoPersistedSyncRules.d.ts +9 -0
  171. package/dist/storage/mongo/MongoPersistedSyncRules.js +9 -0
  172. package/dist/storage/mongo/MongoPersistedSyncRules.js.map +1 -0
  173. package/dist/storage/mongo/MongoPersistedSyncRulesContent.d.ts +20 -0
  174. package/dist/storage/mongo/MongoPersistedSyncRulesContent.js +26 -0
  175. package/dist/storage/mongo/MongoPersistedSyncRulesContent.js.map +1 -0
  176. package/dist/storage/mongo/MongoSyncBucketStorage.d.ts +27 -0
  177. package/dist/storage/mongo/MongoSyncBucketStorage.js +379 -0
  178. package/dist/storage/mongo/MongoSyncBucketStorage.js.map +1 -0
  179. package/dist/storage/mongo/MongoSyncRulesLock.d.ts +16 -0
  180. package/dist/storage/mongo/MongoSyncRulesLock.js +65 -0
  181. package/dist/storage/mongo/MongoSyncRulesLock.js.map +1 -0
  182. package/dist/storage/mongo/OperationBatch.d.ts +26 -0
  183. package/dist/storage/mongo/OperationBatch.js +101 -0
  184. package/dist/storage/mongo/OperationBatch.js.map +1 -0
  185. package/dist/storage/mongo/PersistedBatch.d.ts +42 -0
  186. package/dist/storage/mongo/PersistedBatch.js +200 -0
  187. package/dist/storage/mongo/PersistedBatch.js.map +1 -0
  188. package/dist/storage/mongo/db.d.ts +23 -0
  189. package/dist/storage/mongo/db.js +34 -0
  190. package/dist/storage/mongo/db.js.map +1 -0
  191. package/dist/storage/mongo/models.d.ts +137 -0
  192. package/dist/storage/mongo/models.js +27 -0
  193. package/dist/storage/mongo/models.js.map +1 -0
  194. package/dist/storage/mongo/util.d.ts +26 -0
  195. package/dist/storage/mongo/util.js +81 -0
  196. package/dist/storage/mongo/util.js.map +1 -0
  197. package/dist/storage/storage-index.d.ts +14 -0
  198. package/dist/storage/storage-index.js +15 -0
  199. package/dist/storage/storage-index.js.map +1 -0
  200. package/dist/sync/BroadcastIterable.d.ts +38 -0
  201. package/dist/sync/BroadcastIterable.js +153 -0
  202. package/dist/sync/BroadcastIterable.js.map +1 -0
  203. package/dist/sync/LastValueSink.d.ts +25 -0
  204. package/dist/sync/LastValueSink.js +84 -0
  205. package/dist/sync/LastValueSink.js.map +1 -0
  206. package/dist/sync/merge.d.ts +39 -0
  207. package/dist/sync/merge.js +175 -0
  208. package/dist/sync/merge.js.map +1 -0
  209. package/dist/sync/safeRace.d.ts +1 -0
  210. package/dist/sync/safeRace.js +91 -0
  211. package/dist/sync/safeRace.js.map +1 -0
  212. package/dist/sync/sync-index.d.ts +6 -0
  213. package/dist/sync/sync-index.js +7 -0
  214. package/dist/sync/sync-index.js.map +1 -0
  215. package/dist/sync/sync.d.ts +18 -0
  216. package/dist/sync/sync.js +248 -0
  217. package/dist/sync/sync.js.map +1 -0
  218. package/dist/sync/util.d.ts +26 -0
  219. package/dist/sync/util.js +73 -0
  220. package/dist/sync/util.js.map +1 -0
  221. package/dist/system/CorePowerSyncSystem.d.ts +18 -0
  222. package/dist/system/CorePowerSyncSystem.js +28 -0
  223. package/dist/system/CorePowerSyncSystem.js.map +1 -0
  224. package/dist/util/Mutex.d.ts +47 -0
  225. package/dist/util/Mutex.js +132 -0
  226. package/dist/util/Mutex.js.map +1 -0
  227. package/dist/util/PgManager.d.ts +24 -0
  228. package/dist/util/PgManager.js +55 -0
  229. package/dist/util/PgManager.js.map +1 -0
  230. package/dist/util/alerting.d.ts +4 -0
  231. package/dist/util/alerting.js +14 -0
  232. package/dist/util/alerting.js.map +1 -0
  233. package/dist/util/config/collectors/config-collector.d.ts +29 -0
  234. package/dist/util/config/collectors/config-collector.js +116 -0
  235. package/dist/util/config/collectors/config-collector.js.map +1 -0
  236. package/dist/util/config/collectors/impl/base64-config-collector.d.ts +6 -0
  237. package/dist/util/config/collectors/impl/base64-config-collector.js +15 -0
  238. package/dist/util/config/collectors/impl/base64-config-collector.js.map +1 -0
  239. package/dist/util/config/collectors/impl/fallback-config-collector.d.ts +11 -0
  240. package/dist/util/config/collectors/impl/fallback-config-collector.js +19 -0
  241. package/dist/util/config/collectors/impl/fallback-config-collector.js.map +1 -0
  242. package/dist/util/config/collectors/impl/filesystem-config-collector.d.ts +6 -0
  243. package/dist/util/config/collectors/impl/filesystem-config-collector.js +35 -0
  244. package/dist/util/config/collectors/impl/filesystem-config-collector.js.map +1 -0
  245. package/dist/util/config/compound-config-collector.d.ts +32 -0
  246. package/dist/util/config/compound-config-collector.js +126 -0
  247. package/dist/util/config/compound-config-collector.js.map +1 -0
  248. package/dist/util/config/sync-rules/impl/base64-sync-rules-collector.d.ts +7 -0
  249. package/dist/util/config/sync-rules/impl/base64-sync-rules-collector.js +17 -0
  250. package/dist/util/config/sync-rules/impl/base64-sync-rules-collector.js.map +1 -0
  251. package/dist/util/config/sync-rules/impl/filesystem-sync-rules-collector.d.ts +7 -0
  252. package/dist/util/config/sync-rules/impl/filesystem-sync-rules-collector.js +21 -0
  253. package/dist/util/config/sync-rules/impl/filesystem-sync-rules-collector.js.map +1 -0
  254. package/dist/util/config/sync-rules/impl/inline-sync-rules-collector.d.ts +7 -0
  255. package/dist/util/config/sync-rules/impl/inline-sync-rules-collector.js +17 -0
  256. package/dist/util/config/sync-rules/impl/inline-sync-rules-collector.js.map +1 -0
  257. package/dist/util/config/sync-rules/sync-collector.d.ts +6 -0
  258. package/dist/util/config/sync-rules/sync-collector.js +3 -0
  259. package/dist/util/config/sync-rules/sync-collector.js.map +1 -0
  260. package/dist/util/config/types.d.ts +53 -0
  261. package/dist/util/config/types.js +7 -0
  262. package/dist/util/config/types.js.map +1 -0
  263. package/dist/util/config.d.ts +7 -0
  264. package/dist/util/config.js +35 -0
  265. package/dist/util/config.js.map +1 -0
  266. package/dist/util/env.d.ts +10 -0
  267. package/dist/util/env.js +25 -0
  268. package/dist/util/env.js.map +1 -0
  269. package/dist/util/memory-tracking.d.ts +7 -0
  270. package/dist/util/memory-tracking.js +58 -0
  271. package/dist/util/memory-tracking.js.map +1 -0
  272. package/dist/util/migration_lib.d.ts +11 -0
  273. package/dist/util/migration_lib.js +64 -0
  274. package/dist/util/migration_lib.js.map +1 -0
  275. package/dist/util/pgwire_utils.d.ts +24 -0
  276. package/dist/util/pgwire_utils.js +117 -0
  277. package/dist/util/pgwire_utils.js.map +1 -0
  278. package/dist/util/populate_test_data.d.ts +8 -0
  279. package/dist/util/populate_test_data.js +65 -0
  280. package/dist/util/populate_test_data.js.map +1 -0
  281. package/dist/util/protocol-types.d.ts +178 -0
  282. package/dist/util/protocol-types.js +38 -0
  283. package/dist/util/protocol-types.js.map +1 -0
  284. package/dist/util/secs.d.ts +2 -0
  285. package/dist/util/secs.js +49 -0
  286. package/dist/util/secs.js.map +1 -0
  287. package/dist/util/util-index.d.ts +22 -0
  288. package/dist/util/util-index.js +23 -0
  289. package/dist/util/util-index.js.map +1 -0
  290. package/dist/util/utils.d.ts +14 -0
  291. package/dist/util/utils.js +75 -0
  292. package/dist/util/utils.js.map +1 -0
  293. package/package.json +55 -0
  294. package/src/api/api-index.ts +2 -0
  295. package/src/api/diagnostics.ts +221 -0
  296. package/src/api/schema.ts +99 -0
  297. package/src/auth/CachedKeyCollector.ts +132 -0
  298. package/src/auth/CompoundKeyCollector.ts +33 -0
  299. package/src/auth/JwtPayload.ts +11 -0
  300. package/src/auth/KeyCollector.ts +27 -0
  301. package/src/auth/KeySpec.ts +67 -0
  302. package/src/auth/KeyStore.ts +156 -0
  303. package/src/auth/LeakyBucket.ts +66 -0
  304. package/src/auth/RemoteJWKSCollector.ts +130 -0
  305. package/src/auth/StaticKeyCollector.ts +21 -0
  306. package/src/auth/SupabaseKeyCollector.ts +67 -0
  307. package/src/auth/auth-index.ts +10 -0
  308. package/src/db/db-index.ts +1 -0
  309. package/src/db/mongo.ts +72 -0
  310. package/src/entry/cli-entry.ts +41 -0
  311. package/src/entry/commands/config-command.ts +36 -0
  312. package/src/entry/commands/migrate-action.ts +25 -0
  313. package/src/entry/commands/start-action.ts +24 -0
  314. package/src/entry/commands/teardown-action.ts +23 -0
  315. package/src/entry/entry-index.ts +5 -0
  316. package/src/index.ts +37 -0
  317. package/src/metrics/metrics.ts +169 -0
  318. package/src/migrations/db/migrations/1684951997326-init.ts +33 -0
  319. package/src/migrations/db/migrations/1688556755264-initial-sync-rules.ts +5 -0
  320. package/src/migrations/db/migrations/1702295701188-sync-rule-state.ts +99 -0
  321. package/src/migrations/db/migrations/1711543888062-write-checkpoint-index.ts +32 -0
  322. package/src/migrations/db/store.ts +11 -0
  323. package/src/migrations/migrations.ts +122 -0
  324. package/src/replication/ErrorRateLimiter.ts +49 -0
  325. package/src/replication/PgRelation.ts +42 -0
  326. package/src/replication/WalConnection.ts +227 -0
  327. package/src/replication/WalStream.ts +626 -0
  328. package/src/replication/WalStreamManager.ts +214 -0
  329. package/src/replication/WalStreamRunner.ts +180 -0
  330. package/src/replication/replication-index.ts +7 -0
  331. package/src/replication/util.ts +76 -0
  332. package/src/routes/admin.ts +229 -0
  333. package/src/routes/auth.ts +209 -0
  334. package/src/routes/checkpointing.ts +38 -0
  335. package/src/routes/dev.ts +194 -0
  336. package/src/routes/route-generators.ts +39 -0
  337. package/src/routes/router-socket.ts +13 -0
  338. package/src/routes/router.ts +17 -0
  339. package/src/routes/routes-index.ts +5 -0
  340. package/src/routes/socket-route.ts +131 -0
  341. package/src/routes/sync-rules.ts +210 -0
  342. package/src/routes/sync-stream.ts +92 -0
  343. package/src/runner/teardown.ts +91 -0
  344. package/src/storage/BucketStorage.ts +386 -0
  345. package/src/storage/MongoBucketStorage.ts +493 -0
  346. package/src/storage/SourceTable.ts +60 -0
  347. package/src/storage/mongo/MongoBucketBatch.ts +756 -0
  348. package/src/storage/mongo/MongoIdSequence.ts +24 -0
  349. package/src/storage/mongo/MongoPersistedSyncRules.ts +16 -0
  350. package/src/storage/mongo/MongoPersistedSyncRulesContent.ts +47 -0
  351. package/src/storage/mongo/MongoSyncBucketStorage.ts +517 -0
  352. package/src/storage/mongo/MongoSyncRulesLock.ts +81 -0
  353. package/src/storage/mongo/OperationBatch.ts +115 -0
  354. package/src/storage/mongo/PersistedBatch.ts +245 -0
  355. package/src/storage/mongo/db.ts +69 -0
  356. package/src/storage/mongo/models.ts +157 -0
  357. package/src/storage/mongo/util.ts +88 -0
  358. package/src/storage/storage-index.ts +15 -0
  359. package/src/sync/BroadcastIterable.ts +161 -0
  360. package/src/sync/LastValueSink.ts +100 -0
  361. package/src/sync/merge.ts +200 -0
  362. package/src/sync/safeRace.ts +99 -0
  363. package/src/sync/sync-index.ts +6 -0
  364. package/src/sync/sync.ts +312 -0
  365. package/src/sync/util.ts +98 -0
  366. package/src/system/CorePowerSyncSystem.ts +43 -0
  367. package/src/util/Mutex.ts +159 -0
  368. package/src/util/PgManager.ts +64 -0
  369. package/src/util/alerting.ts +17 -0
  370. package/src/util/config/collectors/config-collector.ts +141 -0
  371. package/src/util/config/collectors/impl/base64-config-collector.ts +18 -0
  372. package/src/util/config/collectors/impl/fallback-config-collector.ts +22 -0
  373. package/src/util/config/collectors/impl/filesystem-config-collector.ts +41 -0
  374. package/src/util/config/compound-config-collector.ts +171 -0
  375. package/src/util/config/sync-rules/impl/base64-sync-rules-collector.ts +21 -0
  376. package/src/util/config/sync-rules/impl/filesystem-sync-rules-collector.ts +26 -0
  377. package/src/util/config/sync-rules/impl/inline-sync-rules-collector.ts +21 -0
  378. package/src/util/config/sync-rules/sync-collector.ts +8 -0
  379. package/src/util/config/types.ts +60 -0
  380. package/src/util/config.ts +39 -0
  381. package/src/util/env.ts +28 -0
  382. package/src/util/memory-tracking.ts +67 -0
  383. package/src/util/migration_lib.ts +79 -0
  384. package/src/util/pgwire_utils.ts +139 -0
  385. package/src/util/populate_test_data.ts +78 -0
  386. package/src/util/protocol-types.ts +223 -0
  387. package/src/util/secs.ts +54 -0
  388. package/src/util/util-index.ts +25 -0
  389. package/src/util/utils.ts +102 -0
  390. package/test/src/__snapshots__/pg_test.test.ts.snap +256 -0
  391. package/test/src/__snapshots__/sync.test.ts.snap +235 -0
  392. package/test/src/auth.test.ts +340 -0
  393. package/test/src/broadcast_iterable.test.ts +156 -0
  394. package/test/src/data_storage.test.ts +1176 -0
  395. package/test/src/env.ts +8 -0
  396. package/test/src/large_batch.test.ts +194 -0
  397. package/test/src/merge_iterable.test.ts +355 -0
  398. package/test/src/pg_test.test.ts +432 -0
  399. package/test/src/schema_changes.test.ts +545 -0
  400. package/test/src/slow_tests.test.ts +257 -0
  401. package/test/src/sql_functions.test.ts +254 -0
  402. package/test/src/sql_operators.test.ts +132 -0
  403. package/test/src/sync.test.ts +293 -0
  404. package/test/src/sync_rules.test.ts +1051 -0
  405. package/test/src/util.ts +67 -0
  406. package/test/src/validation.test.ts +63 -0
  407. package/test/src/wal_stream.test.ts +310 -0
  408. package/test/src/wal_stream_utils.ts +147 -0
  409. package/test/tsconfig.json +20 -0
  410. package/tsconfig.json +20 -0
  411. package/tsconfig.tsbuildinfo +1 -0
  412. package/vitest.config.ts +11 -0
File without changes
package/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # @powersync/service-core
2
+
3
+ ## 0.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 285f368: Initial public release
8
+ - Updated dependencies [285f368]
9
+ - @powersync/service-rsocket-router@0.0.6
10
+ - @powersync/service-sync-rules@0.17.10
11
+ - @powersync/service-jpgwire@0.17.10
12
+ - @powersync/service-jsonbig@0.17.10
13
+ - @powersync/service-types@0.0.2
package/LICENSE ADDED
@@ -0,0 +1,67 @@
1
+ # Functional Source License, Version 1.1, Apache 2.0 Future License
2
+
3
+ ## Abbreviation
4
+
5
+ FSL-1.1-Apache-2.0
6
+
7
+ ## Notice
8
+
9
+ Copyright 2023-2024 Journey Mobile, Inc.
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under these Terms and Conditions, as indicated by our inclusion of these Terms and Conditions with the Software.
20
+
21
+ ### License Grant
22
+
23
+ Subject to your compliance with this License Grant and the Patents, Redistribution and Trademark clauses below, we hereby grant you the right to use, copy, modify, create derivative works, publicly perform, publicly display and redistribute the Software for any Permitted Purpose identified below.
24
+
25
+ ### Permitted Purpose
26
+
27
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use means making the Software available to others in a commercial product or service that:
28
+
29
+ 1. substitutes for the Software;
30
+ 2. substitutes for any other product or service we offer using the Software that exists as of the date we make the Software available; or
31
+ 3. offers the same or substantially similar functionality as the Software.
32
+
33
+ Permitted Purposes specifically include using the Software:
34
+
35
+ 1. for your internal use and access;
36
+ 2. for non-commercial education;
37
+ 3. for non-commercial research; and
38
+ 4. in connection with professional services that you provide to a licensee using the Software in accordance with these Terms and Conditions.
39
+
40
+ ### Patents
41
+
42
+ To the extent your use for a Permitted Purpose would necessarily infringe our patents, the license grant above includes a license under our patents. If you make a claim against any party that the Software infringes or contributes to the infringement of any patent, then your patent license to the Software ends immediately.
43
+
44
+ ### Redistribution
45
+
46
+ The Terms and Conditions apply to all copies, modifications and derivatives of the Software.
47
+ If you redistribute any copies, modifications or derivatives of the Software, you must include a copy of or a link to these Terms and Conditions and not remove any copyright notices provided in or with the Software.
48
+
49
+ ### Disclaimer
50
+
51
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
52
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
53
+
54
+ ### Trademarks
55
+
56
+ Except for displaying the License Details and identifying us as the origin of the Software, you have no right under these Terms and Conditions to use our trademarks, trade names, service marks or product names.
57
+
58
+ ## Grant of Future License
59
+
60
+ We hereby irrevocably grant you an additional license to use the Software under the Apache License, Version 2.0 that is effective on the second anniversary of the date we make the Software available. On or after that date, you may use the Software under the Apache License, Version 2.0, in which case the following will apply:
61
+
62
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
63
+ You may obtain a copy of the License at
64
+
65
+ http://www.apache.org/licenses/LICENSE-2.0
66
+
67
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # PowerSync Service Core
2
+
3
+ This package contains core logic used by the PowerSync backend services.
@@ -0,0 +1,2 @@
1
+ export * from './diagnostics.js';
2
+ export * from './schema.js';
@@ -0,0 +1,3 @@
1
+ export * from './diagnostics.js';
2
+ export * from './schema.js';
3
+ //# sourceMappingURL=api-index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-index.js","sourceRoot":"","sources":["../../src/api/api-index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { ConnectionStatus, SyncRulesStatus } from '@powersync/service-types';
2
+ import * as storage from '../storage/storage-index.js';
3
+ import { CorePowerSyncSystem } from '../system/CorePowerSyncSystem.js';
4
+ export declare function getConnectionStatus(system: CorePowerSyncSystem): Promise<ConnectionStatus | null>;
5
+ export interface DiagnosticsOptions {
6
+ /**
7
+ * Include sync rules content in response.
8
+ */
9
+ include_content?: boolean;
10
+ /**
11
+ * Check against storage database.
12
+ *
13
+ * If false, uses placeholder values for e.g. initial_replication_done.
14
+ */
15
+ live_status: boolean;
16
+ /**
17
+ * Check against the source postgres connection.
18
+ */
19
+ check_connection: boolean;
20
+ }
21
+ export declare function getSyncRulesStatus(sync_rules: storage.PersistedSyncRulesContent | null, system: CorePowerSyncSystem, options: DiagnosticsOptions): Promise<SyncRulesStatus | undefined>;
@@ -0,0 +1,183 @@
1
+ import * as micro from '@journeyapps-platform/micro';
2
+ import { DEFAULT_TAG } from '@powersync/service-sync-rules';
3
+ import { pgwireRows } from '@powersync/service-jpgwire';
4
+ import { baseUri } from '@powersync/service-types';
5
+ import * as replication from '../replication/replication-index.js';
6
+ import * as util from '../util/util-index.js';
7
+ export async function getConnectionStatus(system) {
8
+ if (system.pgwire_pool == null) {
9
+ return null;
10
+ }
11
+ const pool = system.requirePgPool();
12
+ const base = {
13
+ id: system.config.connection.id,
14
+ postgres_uri: baseUri(system.config.connection)
15
+ };
16
+ try {
17
+ await util.retriedQuery(pool, `SELECT 'PowerSync connection test'`);
18
+ }
19
+ catch (e) {
20
+ return {
21
+ ...base,
22
+ connected: false,
23
+ errors: [{ level: 'fatal', message: e.message }]
24
+ };
25
+ }
26
+ try {
27
+ await replication.checkSourceConfiguration(pool);
28
+ }
29
+ catch (e) {
30
+ return {
31
+ ...base,
32
+ connected: true,
33
+ errors: [{ level: 'fatal', message: e.message }]
34
+ };
35
+ }
36
+ return {
37
+ ...base,
38
+ connected: true,
39
+ errors: []
40
+ };
41
+ }
42
+ export async function getSyncRulesStatus(sync_rules, system, options) {
43
+ if (sync_rules == null) {
44
+ return undefined;
45
+ }
46
+ const include_content = options.include_content ?? false;
47
+ const live_status = options.live_status ?? false;
48
+ const check_connection = options.check_connection ?? false;
49
+ let rules;
50
+ let persisted;
51
+ try {
52
+ persisted = sync_rules.parsed();
53
+ rules = persisted.sync_rules;
54
+ }
55
+ catch (e) {
56
+ return {
57
+ content: include_content ? sync_rules.sync_rules_content : undefined,
58
+ connections: [],
59
+ errors: [{ level: 'fatal', message: e.message }]
60
+ };
61
+ }
62
+ const systemStorage = live_status ? await system.storage.getInstance(persisted) : undefined;
63
+ const status = await systemStorage?.getStatus();
64
+ let replication_lag_bytes = undefined;
65
+ let tables_flat = [];
66
+ if (check_connection) {
67
+ const pool = system.requirePgPool();
68
+ const source_table_patterns = rules.getSourceTables();
69
+ const wc = new replication.WalConnection({
70
+ db: pool,
71
+ sync_rules: rules
72
+ });
73
+ const resolved_tables = await wc.getDebugTablesInfo(source_table_patterns);
74
+ tables_flat = resolved_tables.flatMap((info) => {
75
+ if (info.table) {
76
+ return [info.table];
77
+ }
78
+ else if (info.tables) {
79
+ return info.tables;
80
+ }
81
+ else {
82
+ return [];
83
+ }
84
+ });
85
+ if (systemStorage) {
86
+ try {
87
+ const results = await util.retriedQuery(pool, {
88
+ statement: `SELECT
89
+ slot_name,
90
+ confirmed_flush_lsn,
91
+ pg_current_wal_lsn(),
92
+ (pg_current_wal_lsn() - confirmed_flush_lsn) AS lsn_distance
93
+ FROM pg_replication_slots WHERE slot_name = $1 LIMIT 1;`,
94
+ params: [{ type: 'varchar', value: systemStorage.slot_name }]
95
+ });
96
+ const [row] = pgwireRows(results);
97
+ if (row) {
98
+ replication_lag_bytes = Number(row.lsn_distance);
99
+ }
100
+ }
101
+ catch (e) {
102
+ // Ignore
103
+ micro.logger.warn(`Unable to get replication lag`, e);
104
+ }
105
+ }
106
+ }
107
+ else {
108
+ const source_table_patterns = rules.getSourceTables();
109
+ const tag = system.config.connection.tag ?? DEFAULT_TAG;
110
+ tables_flat = source_table_patterns.map((pattern) => {
111
+ if (pattern.isWildcard) {
112
+ return {
113
+ schema: pattern.schema,
114
+ name: pattern.tablePrefix,
115
+ pattern: pattern.isWildcard ? pattern.tablePattern : undefined,
116
+ data_queries: false,
117
+ parameter_queries: false,
118
+ replication_id: [],
119
+ errors: [{ level: 'fatal', message: 'connection failed' }]
120
+ };
121
+ }
122
+ else {
123
+ const source = {
124
+ connectionTag: tag,
125
+ schema: pattern.schema,
126
+ table: pattern.tablePattern
127
+ };
128
+ const syncData = rules.tableSyncsData(source);
129
+ const syncParameters = rules.tableSyncsParameters(source);
130
+ return {
131
+ schema: pattern.schema,
132
+ name: pattern.name,
133
+ data_queries: syncData,
134
+ parameter_queries: syncParameters,
135
+ replication_id: [],
136
+ errors: [{ level: 'fatal', message: 'connection failed' }]
137
+ };
138
+ }
139
+ });
140
+ }
141
+ const errors = tables_flat.flatMap((info) => info.errors);
142
+ if (sync_rules.last_fatal_error) {
143
+ errors.push({ level: 'fatal', message: sync_rules.last_fatal_error });
144
+ }
145
+ errors.push(...rules.errors.map((e) => {
146
+ return {
147
+ level: e.type,
148
+ message: e.message
149
+ };
150
+ }));
151
+ return {
152
+ content: include_content ? sync_rules.sync_rules_content : undefined,
153
+ connections: [
154
+ {
155
+ id: system.config.connection.id,
156
+ tag: system.config.connection.tag ?? DEFAULT_TAG,
157
+ slot_name: sync_rules.slot_name,
158
+ initial_replication_done: status?.snapshot_done ?? false,
159
+ // TODO: Rename?
160
+ last_lsn: status?.checkpoint_lsn ?? undefined,
161
+ last_checkpoint_ts: sync_rules.last_checkpoint_ts?.toISOString(),
162
+ last_keepalive_ts: sync_rules.last_keepalive_ts?.toISOString(),
163
+ replication_lag_bytes: replication_lag_bytes,
164
+ tables: tables_flat
165
+ }
166
+ ],
167
+ errors: deduplicate(errors)
168
+ };
169
+ }
170
+ function deduplicate(errors) {
171
+ let seen = new Set();
172
+ let result = [];
173
+ for (let error of errors) {
174
+ const key = JSON.stringify(error);
175
+ if (seen.has(key)) {
176
+ continue;
177
+ }
178
+ seen.add(key);
179
+ result.push(error);
180
+ }
181
+ return result;
182
+ }
183
+ //# sourceMappingURL=diagnostics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../../src/api/diagnostics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,6BAA6B,CAAC;AACrD,OAAO,EAAE,WAAW,EAAsC,MAAM,+BAA+B,CAAC;AAChG,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAgD,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAEjG,OAAO,KAAK,WAAW,MAAM,oCAAoC,CAAC;AAElE,OAAO,KAAK,IAAI,MAAM,sBAAsB,CAAC;AAI7C,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,MAA2B;IACnE,IAAI,MAAM,CAAC,WAAW,IAAI,IAAI,EAAE,CAAC;QAC/B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,CAAC,aAAa,EAAE,CAAC;IAEpC,MAAM,IAAI,GAAG;QACX,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC,UAAW,CAAC,EAAE;QAChC,YAAY,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,UAAW,CAAC;KACjD,CAAC;IACF,IAAI,CAAC;QACH,MAAM,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,oCAAoC,CAAC,CAAC;IACtE,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO;YACL,GAAG,IAAI;YACP,SAAS,EAAE,KAAK;YAChB,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;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kB,EAAE,WAAW,EAAE;gBAChE,iBAAiB,EAAE,UAAU,CAAC,iBAAiB,EAAE,WAAW,EAAE;gBAC9D,qBAAqB,EAAE,qBAAqB;gBAC5C,MAAM,EAAE,WAAW;aACpB;SACF;QACD,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC;KAC5B,CAAC;AACJ,CAAC;AAED,SAAS,WAAW,CAAC,MAAyD;IAC5E,IAAI,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC7B,IAAI,MAAM,GAAsD,EAAE,CAAC;IACnE,KAAK,IAAI,KAAK,IAAI,MAAM,EAAE,CAAC;QACzB,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAClC,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAClB,SAAS;QACX,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACd,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type * as pgwire from '@powersync/service-jpgwire';
2
+ import { DatabaseSchema, internal_routes } from '@powersync/service-types';
3
+ import { CorePowerSyncSystem } from '../system/CorePowerSyncSystem.js';
4
+ export declare function getConnectionsSchema(system: CorePowerSyncSystem): Promise<internal_routes.GetSchemaResponse>;
5
+ export declare function getConnectionSchema(db: pgwire.PgClient): Promise<DatabaseSchema[]>;
@@ -0,0 +1,88 @@
1
+ import { pgwireRows } from '@powersync/service-jpgwire';
2
+ import * as util from '../util/util-index.js';
3
+ export async function getConnectionsSchema(system) {
4
+ if (system.config.connection == null) {
5
+ return { connections: [] };
6
+ }
7
+ const schemas = await getConnectionSchema(system.requirePgPool());
8
+ return {
9
+ connections: [
10
+ {
11
+ schemas,
12
+ tag: system.config.connection.tag,
13
+ id: system.config.connection.id
14
+ }
15
+ ]
16
+ };
17
+ }
18
+ export async function getConnectionSchema(db) {
19
+ var _a;
20
+ // https://github.com/Borvik/vscode-postgres/blob/88ec5ed061a0c9bced6c5d4ec122d0759c3f3247/src/language/server.ts
21
+ const results = await util.retriedQuery(db, `SELECT
22
+ tbl.schemaname,
23
+ tbl.tablename,
24
+ tbl.quoted_name,
25
+ json_agg(a ORDER BY attnum) as columns
26
+ FROM
27
+ (
28
+ SELECT
29
+ n.nspname as schemaname,
30
+ c.relname as tablename,
31
+ (quote_ident(n.nspname) || '.' || quote_ident(c.relname)) as quoted_name
32
+ FROM
33
+ pg_catalog.pg_class c
34
+ JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
35
+ WHERE
36
+ c.relkind = 'r'
37
+ AND n.nspname not in ('information_schema', 'pg_catalog', 'pg_toast')
38
+ AND n.nspname not like 'pg_temp_%'
39
+ AND n.nspname not like 'pg_toast_temp_%'
40
+ AND c.relnatts > 0
41
+ AND has_schema_privilege(n.oid, 'USAGE') = true
42
+ AND has_table_privilege(quote_ident(n.nspname) || '.' || quote_ident(c.relname), 'SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER') = true
43
+ ) as tbl
44
+ LEFT JOIN (
45
+ SELECT
46
+ attrelid,
47
+ attname,
48
+ format_type(atttypid, atttypmod) as data_type,
49
+ (SELECT typname FROM pg_catalog.pg_type WHERE oid = atttypid) as pg_type,
50
+ attnum,
51
+ attisdropped
52
+ FROM
53
+ pg_attribute
54
+ ) as a ON (
55
+ a.attrelid = tbl.quoted_name::regclass
56
+ AND a.attnum > 0
57
+ AND NOT a.attisdropped
58
+ AND has_column_privilege(tbl.quoted_name, a.attname, 'SELECT, INSERT, UPDATE, REFERENCES')
59
+ )
60
+ GROUP BY schemaname, tablename, quoted_name`);
61
+ const rows = pgwireRows(results);
62
+ let schemas = {};
63
+ for (let row of rows) {
64
+ const schema = (schemas[_a = row.schemaname] ?? (schemas[_a] = {
65
+ name: row.schemaname,
66
+ tables: []
67
+ }));
68
+ const table = {
69
+ name: row.tablename,
70
+ columns: []
71
+ };
72
+ schema.tables.push(table);
73
+ const columnInfo = JSON.parse(row.columns);
74
+ for (let column of columnInfo) {
75
+ let pg_type = column.pg_type;
76
+ if (pg_type.startsWith('_')) {
77
+ pg_type = `${pg_type.substring(1)}[]`;
78
+ }
79
+ table.columns.push({
80
+ name: column.attname,
81
+ type: column.data_type,
82
+ pg_type: pg_type
83
+ });
84
+ }
85
+ }
86
+ return Object.values(schemas);
87
+ }
88
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/api/schema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAGxD,OAAO,KAAK,IAAI,MAAM,sBAAsB,CAAC;AAG7C,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,MAA2B;IACpE,IAAI,MAAM,CAAC,MAAM,CAAC,UAAU,IAAI,IAAI,EAAE,CAAC;QACrC,OAAO,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC;IAC7B,CAAC;IACD,MAAM,OAAO,GAAG,MAAM,mBAAmB,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC,CAAC;IAClE,OAAO;QACL,WAAW,EAAE;YACX;gBACE,OAAO;gBACP,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,UAAW,CAAC,GAAG;gBAClC,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC,UAAW,CAAC,EAAE;aACjC;SACF;KACF,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,EAAmB;;IAC3D,iHAAiH;IACjH,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,YAAY,CACrC,EAAE,EACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4CAuCwC,CACzC,CAAC;IACF,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IAEjC,IAAI,OAAO,GAAwB,EAAE,CAAC;IAEtC,KAAK,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;QACrB,MAAM,MAAM,GAAG,CAAC,OAAO,MAAC,GAAG,CAAC,UAAU,MAAtB,OAAO,OAAqB;YAC1C,IAAI,EAAE,GAAG,CAAC,UAAU;YACpB,MAAM,EAAE,EAAE;SACX,EAAC,CAAC;QACH,MAAM,KAAK,GAAG;YACZ,IAAI,EAAE,GAAG,CAAC,SAAS;YACnB,OAAO,EAAE,EAAW;SACrB,CAAC;QACF,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAE1B,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC3C,KAAK,IAAI,MAAM,IAAI,UAAU,EAAE,CAAC;YAC9B,IAAI,OAAO,GAAG,MAAM,CAAC,OAAiB,CAAC;YACvC,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC5B,OAAO,GAAG,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;YACxC,CAAC;YACD,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;gBACjB,IAAI,EAAE,MAAM,CAAC,OAAO;gBACpB,IAAI,EAAE,MAAM,CAAC,SAAS;gBACtB,OAAO,EAAE,OAAO;aACjB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC"}
@@ -0,0 +1,46 @@
1
+ import { KeyCollector, KeyResult } from './KeyCollector.js';
2
+ /**
3
+ * Manages caching and refreshing for a key collector.
4
+ *
5
+ * Cache refreshing is activity-based, instead of automatically refreshing.
6
+ *
7
+ * Generally:
8
+ * * If the last refresh was > 5 minutes ago, trigger a background refresh, but use the cached keys.
9
+ * * If the last refresh was > 60 minutes ago, discard the cache, and force a refresh.
10
+ * * If the last refresh resulted in an error, refresh based on a retry delay, but use cached keys.
11
+ */
12
+ export declare class CachedKeyCollector implements KeyCollector {
13
+ private source;
14
+ private currentKeys;
15
+ /**
16
+ * The time that currentKeys was set.
17
+ */
18
+ private keyTimestamp;
19
+ /**
20
+ * Refresh every 5 minutes - the default refresh rate.
21
+ */
22
+ private backgroundRefreshInterval;
23
+ /**
24
+ * Refresh a _max_ of once every minute at steady state.
25
+ *
26
+ * This controls the refresh rate under error conditions.
27
+ */
28
+ private rateLimiter;
29
+ /**
30
+ * Expire keys after an hour, if we failed to refresh in that time.
31
+ */
32
+ private keyExpiry;
33
+ private currentErrors;
34
+ /**
35
+ * Indicates a "fatal" error that should be retried.
36
+ */
37
+ private error;
38
+ private refreshPromise;
39
+ constructor(source: KeyCollector);
40
+ getKeys(): Promise<KeyResult>;
41
+ private refresh;
42
+ noKeyFound(): Promise<void>;
43
+ private refreshInner;
44
+ private wantsRefresh;
45
+ addTimeForTests(time: number): Promise<void>;
46
+ }
@@ -0,0 +1,116 @@
1
+ import * as jose from 'jose';
2
+ import timers from 'timers/promises';
3
+ import { LeakyBucket } from './LeakyBucket.js';
4
+ /**
5
+ * Manages caching and refreshing for a key collector.
6
+ *
7
+ * Cache refreshing is activity-based, instead of automatically refreshing.
8
+ *
9
+ * Generally:
10
+ * * If the last refresh was > 5 minutes ago, trigger a background refresh, but use the cached keys.
11
+ * * If the last refresh was > 60 minutes ago, discard the cache, and force a refresh.
12
+ * * If the last refresh resulted in an error, refresh based on a retry delay, but use cached keys.
13
+ */
14
+ export class CachedKeyCollector {
15
+ constructor(source) {
16
+ this.source = source;
17
+ this.currentKeys = [];
18
+ /**
19
+ * The time that currentKeys was set.
20
+ */
21
+ this.keyTimestamp = 0;
22
+ /**
23
+ * Refresh every 5 minutes - the default refresh rate.
24
+ */
25
+ this.backgroundRefreshInterval = 300000;
26
+ /**
27
+ * Refresh a _max_ of once every minute at steady state.
28
+ *
29
+ * This controls the refresh rate under error conditions.
30
+ */
31
+ this.rateLimiter = new LeakyBucket({ maxCapacity: 10, periodMs: 60000 });
32
+ /**
33
+ * Expire keys after an hour, if we failed to refresh in that time.
34
+ */
35
+ this.keyExpiry = 3600000;
36
+ this.currentErrors = [];
37
+ /**
38
+ * Indicates a "fatal" error that should be retried.
39
+ */
40
+ this.error = false;
41
+ this.refreshPromise = undefined;
42
+ }
43
+ async getKeys() {
44
+ const now = Date.now();
45
+ if (now - this.keyTimestamp > this.keyExpiry) {
46
+ // Keys have expired - clear
47
+ this.currentKeys = [];
48
+ }
49
+ if (this.wantsRefresh()) {
50
+ // Trigger background refresh.
51
+ // This also sets refreshPromise
52
+ this.refresh();
53
+ }
54
+ if (now - this.keyTimestamp > this.keyExpiry) {
55
+ // Keys have expired - wait for fetching new keys
56
+ // It is possible that the refresh was actually triggered,
57
+ // e.g. in the case of waiting for error retries.
58
+ // In the case of very slow requests, we don't wait for it to complete, but the
59
+ // request can still complete in the background.
60
+ const timeout = timers.setTimeout(3000);
61
+ await Promise.race([this.refreshPromise, timeout]);
62
+ }
63
+ return { keys: this.currentKeys, errors: this.currentErrors };
64
+ }
65
+ refresh() {
66
+ if (this.refreshPromise == null) {
67
+ if (!this.rateLimiter.allowed()) {
68
+ return;
69
+ }
70
+ this.refreshPromise = this.refreshInner().finally(() => {
71
+ this.refreshPromise = undefined;
72
+ });
73
+ }
74
+ return this.refreshPromise;
75
+ }
76
+ async noKeyFound() {
77
+ // Refresh keys if allowed by the rate limiter
78
+ await this.refresh();
79
+ }
80
+ async refreshInner() {
81
+ try {
82
+ const { keys, errors } = await this.source.getKeys();
83
+ // Partial or full result
84
+ this.currentKeys = keys;
85
+ this.currentErrors = errors;
86
+ this.keyTimestamp = Date.now();
87
+ this.error = false;
88
+ }
89
+ catch (e) {
90
+ this.error = true;
91
+ // No result - keep previous keys
92
+ if (e instanceof jose.errors.JOSEError) {
93
+ this.currentErrors = [e];
94
+ }
95
+ else {
96
+ this.currentErrors = [new jose.errors.JOSEError(e.message ?? 'Failed to fetch keys')];
97
+ }
98
+ }
99
+ }
100
+ wantsRefresh() {
101
+ if (this.error) {
102
+ return true;
103
+ }
104
+ if (Date.now() - this.rateLimiter.lastGrantedRequest >= this.backgroundRefreshInterval) {
105
+ return true;
106
+ }
107
+ return false;
108
+ }
109
+ async addTimeForTests(time) {
110
+ this.keyTimestamp -= time;
111
+ this.rateLimiter.reset();
112
+ this.rateLimiter.lastGrantedRequest -= time;
113
+ await this.refreshPromise;
114
+ }
115
+ }
116
+ //# sourceMappingURL=CachedKeyCollector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CachedKeyCollector.js","sourceRoot":"","sources":["../../src/auth/CachedKeyCollector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAErC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG/C;;;;;;;;;GASG;AAEH,MAAM,OAAO,kBAAkB;IAgC7B,YAAoB,MAAoB;QAApB,WAAM,GAAN,MAAM,CAAc;QA/BhC,gBAAW,GAAc,EAAE,CAAC;QACpC;;WAEG;QACK,iBAAY,GAAW,CAAC,CAAC;QAEjC;;WAEG;QACK,8BAAyB,GAAG,MAAM,CAAC;QAE3C;;;;WAIG;QACK,gBAAW,GAAG,IAAI,WAAW,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;QAE5E;;WAEG;QACK,cAAS,GAAG,OAAO,CAAC;QAEpB,kBAAa,GAA4B,EAAE,CAAC;QACpD;;WAEG;QACK,UAAK,GAAG,KAAK,CAAC;QAEd,mBAAc,GAA8B,SAAS,CAAC;IAEnB,CAAC;IAE5C,KAAK,CAAC,OAAO;QACX,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,IAAI,GAAG,GAAG,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;YAC7C,4BAA4B;YAC5B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W,GAAG,IAAI,CAAC;YACxB,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC;YAC5B,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YAC/B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACrB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;YAClB,iCAAiC;YACjC,IAAI,CAAC,YAAY,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;gBACvC,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC,CAAC;YAC3B,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,aAAa,GAAG,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,IAAI,sBAAsB,CAAC,CAAC,CAAC;YACxF,CAAC;QACH,CAAC;IACH,CAAC;IAEO,YAAY;QAClB,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC,kBAAkB,IAAI,IAAI,CAAC,yBAAyB,EAAE,CAAC;YACvF,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,IAAY;QAChC,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC;QAC1B,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,WAAW,CAAC,kBAAkB,IAAI,IAAI,CAAC;QAC5C,MAAM,IAAI,CAAC,cAAc,CAAC;IAC5B,CAAC;CACF"}
@@ -0,0 +1,8 @@
1
+ import { KeyCollector, KeyResult } from './KeyCollector.js';
2
+ export declare class CompoundKeyCollector implements KeyCollector {
3
+ private collectors;
4
+ constructor(collectors?: KeyCollector[]);
5
+ add(collector: KeyCollector): void;
6
+ getKeys(): Promise<KeyResult>;
7
+ noKeyFound(): Promise<void>;
8
+ }
@@ -0,0 +1,23 @@
1
+ export class CompoundKeyCollector {
2
+ constructor(collectors) {
3
+ this.collectors = collectors ?? [];
4
+ }
5
+ add(collector) {
6
+ this.collectors.push(collector);
7
+ }
8
+ async getKeys() {
9
+ let keys = [];
10
+ let errors = [];
11
+ const promises = this.collectors.map((collector) => collector.getKeys().then((result) => {
12
+ keys.push(...result.keys);
13
+ errors.push(...result.errors);
14
+ }));
15
+ await Promise.all(promises);
16
+ return { keys, errors };
17
+ }
18
+ async noKeyFound() {
19
+ const promises = this.collectors.map((collector) => collector.noKeyFound?.());
20
+ await Promise.all(promises);
21
+ }
22
+ }
23
+ //# sourceMappingURL=CompoundKeyCollector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CompoundKeyCollector.js","sourceRoot":"","sources":["../../src/auth/CompoundKeyCollector.ts"],"names":[],"mappings":"AAIA,MAAM,OAAO,oBAAoB;IAG/B,YAAY,UAA2B;QACrC,IAAI,CAAC,UAAU,GAAG,UAAU,IAAI,EAAE,CAAC;IACrC,CAAC;IAED,GAAG,CAAC,SAAuB;QACzB,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,OAAO;QACX,IAAI,IAAI,GAAc,EAAE,CAAC;QACzB,IAAI,MAAM,GAA4B,EAAE,CAAC;QACzC,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CACjD,SAAS,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;YAClC,IAAI,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;YAC1B,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;QAChC,CAAC,CAAC,CACH,CAAC;QACF,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,UAAU;QACd,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;QAC9E,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC;CACF"}
@@ -0,0 +1,10 @@
1
+ export interface JwtPayload {
2
+ /**
3
+ * user_id
4
+ */
5
+ sub: string;
6
+ parameters: Record<string, any>;
7
+ iss?: string | undefined;
8
+ exp: number;
9
+ iat: number;
10
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=JwtPayload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JwtPayload.js","sourceRoot":"","sources":["../../src/auth/JwtPayload.ts"],"names":[],"mappings":""}