@antelopejs/postgres 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (357) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +151 -2
  3. package/dist/config.d.ts +33 -0
  4. package/dist/config.js +90 -0
  5. package/dist/config.js.map +1 -0
  6. package/dist/connection.d.ts +14 -0
  7. package/dist/connection.js +128 -0
  8. package/dist/connection.js.map +1 -0
  9. package/dist/implementations/database/changes.d.ts +19 -0
  10. package/dist/implementations/database/changes.js +100 -0
  11. package/dist/implementations/database/changes.js.map +1 -0
  12. package/dist/implementations/database/coerce.d.ts +15 -0
  13. package/dist/implementations/database/coerce.js +195 -0
  14. package/dist/implementations/database/coerce.js.map +1 -0
  15. package/dist/implementations/database/context.d.ts +32 -0
  16. package/dist/implementations/database/context.js +50 -0
  17. package/dist/implementations/database/context.js.map +1 -0
  18. package/dist/implementations/database/cursors.d.ts +16 -0
  19. package/dist/implementations/database/cursors.js +269 -0
  20. package/dist/implementations/database/cursors.js.map +1 -0
  21. package/dist/implementations/database/ddl.d.ts +62 -0
  22. package/dist/implementations/database/ddl.js +355 -0
  23. package/dist/implementations/database/ddl.js.map +1 -0
  24. package/dist/implementations/database/expression.d.ts +7 -0
  25. package/dist/implementations/database/expression.js +30 -0
  26. package/dist/implementations/database/expression.js.map +1 -0
  27. package/dist/implementations/database/external-catalog.d.ts +22 -0
  28. package/dist/implementations/database/external-catalog.js +82 -0
  29. package/dist/implementations/database/external-catalog.js.map +1 -0
  30. package/dist/implementations/database/external-errors.d.ts +20 -0
  31. package/dist/implementations/database/external-errors.js +67 -0
  32. package/dist/implementations/database/external-errors.js.map +1 -0
  33. package/dist/implementations/database/external-payload.d.ts +32 -0
  34. package/dist/implementations/database/external-payload.js +206 -0
  35. package/dist/implementations/database/external-payload.js.map +1 -0
  36. package/dist/implementations/database/external-refusals.d.ts +5 -0
  37. package/dist/implementations/database/external-refusals.js +23 -0
  38. package/dist/implementations/database/external-refusals.js.map +1 -0
  39. package/dist/implementations/database/external-schema.d.ts +3 -0
  40. package/dist/implementations/database/external-schema.js +121 -0
  41. package/dist/implementations/database/external-schema.js.map +1 -0
  42. package/dist/implementations/database/external-types.d.ts +29 -0
  43. package/dist/implementations/database/external-types.js +373 -0
  44. package/dist/implementations/database/external-types.js.map +1 -0
  45. package/dist/implementations/database/external-writes.d.ts +3 -0
  46. package/dist/implementations/database/external-writes.js +298 -0
  47. package/dist/implementations/database/external-writes.js.map +1 -0
  48. package/dist/implementations/database/feed-pipeline.d.ts +12 -0
  49. package/dist/implementations/database/feed-pipeline.js +92 -0
  50. package/dist/implementations/database/feed-pipeline.js.map +1 -0
  51. package/dist/implementations/database/feeds.d.ts +34 -0
  52. package/dist/implementations/database/feeds.js +338 -0
  53. package/dist/implementations/database/feeds.js.map +1 -0
  54. package/dist/implementations/database/fields.d.ts +37 -0
  55. package/dist/implementations/database/fields.js +114 -0
  56. package/dist/implementations/database/fields.js.map +1 -0
  57. package/dist/implementations/database/identifier.d.ts +8 -0
  58. package/dist/implementations/database/identifier.js +62 -0
  59. package/dist/implementations/database/identifier.js.map +1 -0
  60. package/dist/implementations/database/instances.d.ts +4 -0
  61. package/dist/implementations/database/instances.js +57 -0
  62. package/dist/implementations/database/instances.js.map +1 -0
  63. package/dist/implementations/database/introspect.d.ts +3 -0
  64. package/dist/implementations/database/introspect.js +36 -0
  65. package/dist/implementations/database/introspect.js.map +1 -0
  66. package/dist/implementations/database/jsonb.d.ts +29 -0
  67. package/dist/implementations/database/jsonb.js +54 -0
  68. package/dist/implementations/database/jsonb.js.map +1 -0
  69. package/dist/implementations/database/listener.d.ts +3 -0
  70. package/dist/implementations/database/listener.js +93 -0
  71. package/dist/implementations/database/listener.js.map +1 -0
  72. package/dist/implementations/database/migrate.d.ts +6 -0
  73. package/dist/implementations/database/migrate.js +282 -0
  74. package/dist/implementations/database/migrate.js.map +1 -0
  75. package/dist/implementations/database/payload.d.ts +24 -0
  76. package/dist/implementations/database/payload.js +113 -0
  77. package/dist/implementations/database/payload.js.map +1 -0
  78. package/dist/implementations/database/pipeline.d.ts +10 -0
  79. package/dist/implementations/database/pipeline.js +56 -0
  80. package/dist/implementations/database/pipeline.js.map +1 -0
  81. package/dist/implementations/database/query.d.ts +11 -0
  82. package/dist/implementations/database/query.js +189 -0
  83. package/dist/implementations/database/query.js.map +1 -0
  84. package/dist/implementations/database/readings.d.ts +17 -0
  85. package/dist/implementations/database/readings.js +133 -0
  86. package/dist/implementations/database/readings.js.map +1 -0
  87. package/dist/implementations/database/reaper.d.ts +6 -0
  88. package/dist/implementations/database/reaper.js +121 -0
  89. package/dist/implementations/database/reaper.js.map +1 -0
  90. package/dist/implementations/database/relation.d.ts +65 -0
  91. package/dist/implementations/database/relation.js +237 -0
  92. package/dist/implementations/database/relation.js.map +1 -0
  93. package/dist/implementations/database/result.d.ts +4 -0
  94. package/dist/implementations/database/result.js +70 -0
  95. package/dist/implementations/database/result.js.map +1 -0
  96. package/dist/implementations/database/row-source.d.ts +64 -0
  97. package/dist/implementations/database/row-source.js +279 -0
  98. package/dist/implementations/database/row-source.js.map +1 -0
  99. package/dist/implementations/database/schema.d.ts +15 -0
  100. package/dist/implementations/database/schema.js +143 -0
  101. package/dist/implementations/database/schema.js.map +1 -0
  102. package/dist/implementations/database/selection.d.ts +18 -0
  103. package/dist/implementations/database/selection.js +129 -0
  104. package/dist/implementations/database/selection.js.map +1 -0
  105. package/dist/implementations/database/sql.d.ts +24 -0
  106. package/dist/implementations/database/sql.js +48 -0
  107. package/dist/implementations/database/sql.js.map +1 -0
  108. package/dist/implementations/database/stage.d.ts +22 -0
  109. package/dist/implementations/database/stage.js +76 -0
  110. package/dist/implementations/database/stage.js.map +1 -0
  111. package/dist/implementations/database/stages-aggregate.d.ts +11 -0
  112. package/dist/implementations/database/stages-aggregate.js +112 -0
  113. package/dist/implementations/database/stages-aggregate.js.map +1 -0
  114. package/dist/implementations/database/stages-array.d.ts +2 -0
  115. package/dist/implementations/database/stages-array.js +162 -0
  116. package/dist/implementations/database/stages-array.js.map +1 -0
  117. package/dist/implementations/database/stages-core.d.ts +2 -0
  118. package/dist/implementations/database/stages-core.js +107 -0
  119. package/dist/implementations/database/stages-core.js.map +1 -0
  120. package/dist/implementations/database/stages-date.d.ts +2 -0
  121. package/dist/implementations/database/stages-date.js +65 -0
  122. package/dist/implementations/database/stages-date.js.map +1 -0
  123. package/dist/implementations/database/stages-group.d.ts +5 -0
  124. package/dist/implementations/database/stages-group.js +151 -0
  125. package/dist/implementations/database/stages-group.js.map +1 -0
  126. package/dist/implementations/database/stages-join.d.ts +2 -0
  127. package/dist/implementations/database/stages-join.js +162 -0
  128. package/dist/implementations/database/stages-join.js.map +1 -0
  129. package/dist/implementations/database/stages-numeric.d.ts +2 -0
  130. package/dist/implementations/database/stages-numeric.js +152 -0
  131. package/dist/implementations/database/stages-numeric.js.map +1 -0
  132. package/dist/implementations/database/stages-object.d.ts +2 -0
  133. package/dist/implementations/database/stages-object.js +81 -0
  134. package/dist/implementations/database/stages-object.js.map +1 -0
  135. package/dist/implementations/database/stages-projection.d.ts +2 -0
  136. package/dist/implementations/database/stages-projection.js +75 -0
  137. package/dist/implementations/database/stages-projection.js.map +1 -0
  138. package/dist/implementations/database/stages-rows.d.ts +2 -0
  139. package/dist/implementations/database/stages-rows.js +101 -0
  140. package/dist/implementations/database/stages-rows.js.map +1 -0
  141. package/dist/implementations/database/stages-selection.d.ts +2 -0
  142. package/dist/implementations/database/stages-selection.js +146 -0
  143. package/dist/implementations/database/stages-selection.js.map +1 -0
  144. package/dist/implementations/database/stages-string.d.ts +2 -0
  145. package/dist/implementations/database/stages-string.js +101 -0
  146. package/dist/implementations/database/stages-string.js.map +1 -0
  147. package/dist/implementations/database/subquery.d.ts +4 -0
  148. package/dist/implementations/database/subquery.js +49 -0
  149. package/dist/implementations/database/subquery.js.map +1 -0
  150. package/dist/implementations/database/types.d.ts +37 -0
  151. package/dist/implementations/database/types.js +57 -0
  152. package/dist/implementations/database/types.js.map +1 -0
  153. package/dist/implementations/database/utils.d.ts +16 -0
  154. package/dist/implementations/database/utils.js +38 -0
  155. package/dist/implementations/database/utils.js.map +1 -0
  156. package/dist/implementations/database/value.d.ts +10 -0
  157. package/dist/implementations/database/value.js +153 -0
  158. package/dist/implementations/database/value.js.map +1 -0
  159. package/dist/implementations/database/writes-atomic.d.ts +6 -0
  160. package/dist/implementations/database/writes-atomic.js +93 -0
  161. package/dist/implementations/database/writes-atomic.js.map +1 -0
  162. package/dist/implementations/database/writes-identity.d.ts +4 -0
  163. package/dist/implementations/database/writes-identity.js +181 -0
  164. package/dist/implementations/database/writes-identity.js.map +1 -0
  165. package/dist/implementations/database/writes-insert.d.ts +2 -0
  166. package/dist/implementations/database/writes-insert.js +136 -0
  167. package/dist/implementations/database/writes-insert.js.map +1 -0
  168. package/dist/implementations/database/writes-shared.d.ts +36 -0
  169. package/dist/implementations/database/writes-shared.js +64 -0
  170. package/dist/implementations/database/writes-shared.js.map +1 -0
  171. package/dist/implementations/database/writes.d.ts +16 -0
  172. package/dist/implementations/database/writes.js +52 -0
  173. package/dist/implementations/database/writes.js.map +1 -0
  174. package/dist/index.d.ts +4 -0
  175. package/dist/index.js +52 -0
  176. package/dist/index.js.map +1 -0
  177. package/dist/logger.d.ts +2 -0
  178. package/dist/logger.js +6 -0
  179. package/dist/logger.js.map +1 -0
  180. package/dist/test/antelope.test.d.ts +2 -0
  181. package/dist/test/antelope.test.js +88 -0
  182. package/dist/test/antelope.test.js.map +1 -0
  183. package/dist/test/atomic.test.d.ts +1 -0
  184. package/dist/test/atomic.test.js +132 -0
  185. package/dist/test/atomic.test.js.map +1 -0
  186. package/dist/test/contention.test.d.ts +1 -0
  187. package/dist/test/contention.test.js +183 -0
  188. package/dist/test/contention.test.js.map +1 -0
  189. package/dist/test/indexes.test.d.ts +1 -0
  190. package/dist/test/indexes.test.js +311 -0
  191. package/dist/test/indexes.test.js.map +1 -0
  192. package/dist/test/unit/changes.spec.d.ts +1 -0
  193. package/dist/test/unit/changes.spec.js +103 -0
  194. package/dist/test/unit/changes.spec.js.map +1 -0
  195. package/dist/test/unit/coerce.spec.d.ts +1 -0
  196. package/dist/test/unit/coerce.spec.js +162 -0
  197. package/dist/test/unit/coerce.spec.js.map +1 -0
  198. package/dist/test/unit/config.spec.d.ts +1 -0
  199. package/dist/test/unit/config.spec.js +123 -0
  200. package/dist/test/unit/config.spec.js.map +1 -0
  201. package/dist/test/unit/connection.spec.d.ts +1 -0
  202. package/dist/test/unit/connection.spec.js +171 -0
  203. package/dist/test/unit/connection.spec.js.map +1 -0
  204. package/dist/test/unit/cursors.spec.d.ts +1 -0
  205. package/dist/test/unit/cursors.spec.js +823 -0
  206. package/dist/test/unit/cursors.spec.js.map +1 -0
  207. package/dist/test/unit/ddl.spec.d.ts +1 -0
  208. package/dist/test/unit/ddl.spec.js +571 -0
  209. package/dist/test/unit/ddl.spec.js.map +1 -0
  210. package/dist/test/unit/expression-array.spec.d.ts +1 -0
  211. package/dist/test/unit/expression-array.spec.js +488 -0
  212. package/dist/test/unit/expression-array.spec.js.map +1 -0
  213. package/dist/test/unit/expression-date.spec.d.ts +1 -0
  214. package/dist/test/unit/expression-date.spec.js +329 -0
  215. package/dist/test/unit/expression-date.spec.js.map +1 -0
  216. package/dist/test/unit/expression-numeric.spec.d.ts +1 -0
  217. package/dist/test/unit/expression-numeric.spec.js +362 -0
  218. package/dist/test/unit/expression-numeric.spec.js.map +1 -0
  219. package/dist/test/unit/expression-object.spec.d.ts +1 -0
  220. package/dist/test/unit/expression-object.spec.js +230 -0
  221. package/dist/test/unit/expression-object.spec.js.map +1 -0
  222. package/dist/test/unit/expression-stages.spec.d.ts +1 -0
  223. package/dist/test/unit/expression-stages.spec.js +82 -0
  224. package/dist/test/unit/expression-stages.spec.js.map +1 -0
  225. package/dist/test/unit/expression-string.spec.d.ts +1 -0
  226. package/dist/test/unit/expression-string.spec.js +249 -0
  227. package/dist/test/unit/expression-string.spec.js.map +1 -0
  228. package/dist/test/unit/expression.spec.d.ts +1 -0
  229. package/dist/test/unit/expression.spec.js +449 -0
  230. package/dist/test/unit/expression.spec.js.map +1 -0
  231. package/dist/test/unit/external-comparisons.spec.d.ts +1 -0
  232. package/dist/test/unit/external-comparisons.spec.js +145 -0
  233. package/dist/test/unit/external-comparisons.spec.js.map +1 -0
  234. package/dist/test/unit/external-types.spec.d.ts +1 -0
  235. package/dist/test/unit/external-types.spec.js +191 -0
  236. package/dist/test/unit/external-types.spec.js.map +1 -0
  237. package/dist/test/unit/feeds.spec.d.ts +1 -0
  238. package/dist/test/unit/feeds.spec.js +374 -0
  239. package/dist/test/unit/feeds.spec.js.map +1 -0
  240. package/dist/test/unit/fields.spec.d.ts +1 -0
  241. package/dist/test/unit/fields.spec.js +79 -0
  242. package/dist/test/unit/fields.spec.js.map +1 -0
  243. package/dist/test/unit/identifier.spec.d.ts +1 -0
  244. package/dist/test/unit/identifier.spec.js +50 -0
  245. package/dist/test/unit/identifier.spec.js.map +1 -0
  246. package/dist/test/unit/payload.spec.d.ts +1 -0
  247. package/dist/test/unit/payload.spec.js +278 -0
  248. package/dist/test/unit/payload.spec.js.map +1 -0
  249. package/dist/test/unit/pipeline-aggregate.spec.d.ts +1 -0
  250. package/dist/test/unit/pipeline-aggregate.spec.js +199 -0
  251. package/dist/test/unit/pipeline-aggregate.spec.js.map +1 -0
  252. package/dist/test/unit/pipeline-fixture.d.ts +79 -0
  253. package/dist/test/unit/pipeline-fixture.js +277 -0
  254. package/dist/test/unit/pipeline-fixture.js.map +1 -0
  255. package/dist/test/unit/pipeline-group.spec.d.ts +1 -0
  256. package/dist/test/unit/pipeline-group.spec.js +390 -0
  257. package/dist/test/unit/pipeline-group.spec.js.map +1 -0
  258. package/dist/test/unit/pipeline-join.spec.d.ts +1 -0
  259. package/dist/test/unit/pipeline-join.spec.js +165 -0
  260. package/dist/test/unit/pipeline-join.spec.js.map +1 -0
  261. package/dist/test/unit/pipeline-lookup.spec.d.ts +1 -0
  262. package/dist/test/unit/pipeline-lookup.spec.js +268 -0
  263. package/dist/test/unit/pipeline-lookup.spec.js.map +1 -0
  264. package/dist/test/unit/pipeline-projection.spec.d.ts +1 -0
  265. package/dist/test/unit/pipeline-projection.spec.js +183 -0
  266. package/dist/test/unit/pipeline-projection.spec.js.map +1 -0
  267. package/dist/test/unit/pipeline-rows.spec.d.ts +1 -0
  268. package/dist/test/unit/pipeline-rows.spec.js +321 -0
  269. package/dist/test/unit/pipeline-rows.spec.js.map +1 -0
  270. package/dist/test/unit/pipeline-selection.spec.d.ts +1 -0
  271. package/dist/test/unit/pipeline-selection.spec.js +257 -0
  272. package/dist/test/unit/pipeline-selection.spec.js.map +1 -0
  273. package/dist/test/unit/pipeline-stages.spec.d.ts +1 -0
  274. package/dist/test/unit/pipeline-stages.spec.js +226 -0
  275. package/dist/test/unit/pipeline-stages.spec.js.map +1 -0
  276. package/dist/test/unit/pipeline.spec.d.ts +1 -0
  277. package/dist/test/unit/pipeline.spec.js +72 -0
  278. package/dist/test/unit/pipeline.spec.js.map +1 -0
  279. package/dist/test/unit/query.spec.d.ts +1 -0
  280. package/dist/test/unit/query.spec.js +212 -0
  281. package/dist/test/unit/query.spec.js.map +1 -0
  282. package/dist/test/unit/reaper.spec.d.ts +1 -0
  283. package/dist/test/unit/reaper.spec.js +122 -0
  284. package/dist/test/unit/reaper.spec.js.map +1 -0
  285. package/dist/test/unit/relation.spec.d.ts +1 -0
  286. package/dist/test/unit/relation.spec.js +348 -0
  287. package/dist/test/unit/relation.spec.js.map +1 -0
  288. package/dist/test/unit/result.spec.d.ts +1 -0
  289. package/dist/test/unit/result.spec.js +128 -0
  290. package/dist/test/unit/result.spec.js.map +1 -0
  291. package/dist/test/unit/row-source.spec.d.ts +1 -0
  292. package/dist/test/unit/row-source.spec.js +141 -0
  293. package/dist/test/unit/row-source.spec.js.map +1 -0
  294. package/dist/test/unit/schema.spec.d.ts +1 -0
  295. package/dist/test/unit/schema.spec.js +44 -0
  296. package/dist/test/unit/schema.spec.js.map +1 -0
  297. package/dist/test/unit/selection.spec.d.ts +1 -0
  298. package/dist/test/unit/selection.spec.js +182 -0
  299. package/dist/test/unit/selection.spec.js.map +1 -0
  300. package/dist/test/unit/spec-fixture.d.ts +11 -0
  301. package/dist/test/unit/spec-fixture.js +71 -0
  302. package/dist/test/unit/spec-fixture.js.map +1 -0
  303. package/dist/test/unit/sql.spec.d.ts +1 -0
  304. package/dist/test/unit/sql.spec.js +38 -0
  305. package/dist/test/unit/sql.spec.js.map +1 -0
  306. package/dist/test/unit/subquery.spec.d.ts +1 -0
  307. package/dist/test/unit/subquery.spec.js +154 -0
  308. package/dist/test/unit/subquery.spec.js.map +1 -0
  309. package/dist/test/unit/types.spec.d.ts +1 -0
  310. package/dist/test/unit/types.spec.js +39 -0
  311. package/dist/test/unit/types.spec.js.map +1 -0
  312. package/dist/test/unit/utils.spec.d.ts +1 -0
  313. package/dist/test/unit/utils.spec.js +22 -0
  314. package/dist/test/unit/utils.spec.js.map +1 -0
  315. package/dist/test/unit/value.spec.d.ts +1 -0
  316. package/dist/test/unit/value.spec.js +195 -0
  317. package/dist/test/unit/value.spec.js.map +1 -0
  318. package/dist/test/unit/writes-atomic.spec.d.ts +1 -0
  319. package/dist/test/unit/writes-atomic.spec.js +66 -0
  320. package/dist/test/unit/writes-atomic.spec.js.map +1 -0
  321. package/dist/test/unit/writes-insert.spec.d.ts +1 -0
  322. package/dist/test/unit/writes-insert.spec.js +270 -0
  323. package/dist/test/unit/writes-insert.spec.js.map +1 -0
  324. package/dist/test/unit/writes-replace.spec.d.ts +1 -0
  325. package/dist/test/unit/writes-replace.spec.js +100 -0
  326. package/dist/test/unit/writes-replace.spec.js.map +1 -0
  327. package/dist/test/unit/writes-target.spec.d.ts +1 -0
  328. package/dist/test/unit/writes-target.spec.js +118 -0
  329. package/dist/test/unit/writes-target.spec.js.map +1 -0
  330. package/dist/test/unit/writes-update.spec.d.ts +1 -0
  331. package/dist/test/unit/writes-update.spec.js +297 -0
  332. package/dist/test/unit/writes-update.spec.js.map +1 -0
  333. package/dist/test-external/fixture.d.ts +6 -0
  334. package/dist/test-external/fixture.js +136 -0
  335. package/dist/test-external/fixture.js.map +1 -0
  336. package/dist/test-external/native.test.d.ts +1 -0
  337. package/dist/test-external/native.test.js +132 -0
  338. package/dist/test-external/native.test.js.map +1 -0
  339. package/dist/test-external/reads.test.d.ts +1 -0
  340. package/dist/test-external/reads.test.js +232 -0
  341. package/dist/test-external/reads.test.js.map +1 -0
  342. package/dist/test-external/refusals.test.d.ts +1 -0
  343. package/dist/test-external/refusals.test.js +93 -0
  344. package/dist/test-external/refusals.test.js.map +1 -0
  345. package/dist/test-external/registration.test.d.ts +1 -0
  346. package/dist/test-external/registration.test.js +127 -0
  347. package/dist/test-external/registration.test.js.map +1 -0
  348. package/dist/test-external/sales.d.ts +5 -0
  349. package/dist/test-external/sales.js +126 -0
  350. package/dist/test-external/sales.js.map +1 -0
  351. package/dist/test-external/startup.test.d.ts +1 -0
  352. package/dist/test-external/startup.test.js +15 -0
  353. package/dist/test-external/startup.test.js.map +1 -0
  354. package/dist/test-external/writes.test.d.ts +1 -0
  355. package/dist/test-external/writes.test.js +315 -0
  356. package/dist/test-external/writes.test.js.map +1 -0
  357. package/package.json +78 -4
package/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright (c) 2025-present - AntelopeJS Team
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,152 @@
1
- # Temporary Holding Version
1
+ # @antelopejs/postgres
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ <div align="center">
4
+ <a href="https://www.npmjs.com/package/@antelopejs/postgres"><img alt="npm" src="https://img.shields.io/npm/v/@antelopejs/postgres?style=for-the-badge&labelColor=000000&color=000000"></a>
5
+ <a href="./LICENSE"><img alt="License" src="https://img.shields.io/npm/l/@antelopejs/postgres?style=for-the-badge&labelColor=000000&color=000000"></a>
6
+ <a href="https://discord.gg/sjK28QHrA7"><img src="https://img.shields.io/badge/Discord-18181B?logo=discord&style=for-the-badge&color=000000" alt="Discord"></a>
7
+ <a href="https://interfaces.antelopejs.com/docs/database"><img src="https://img.shields.io/badge/Docs-18181B?style=for-the-badge&color=000000" alt="Documentation"></a>
8
+ </div>
9
+
10
+ The PostgreSQL backend of AntelopeJS: it runs the database interface's queries on PostgreSQL with the [`pg`](https://github.com/brianc/node-postgres) driver, mapping schema definitions onto real relational tables with native column types and indexes. It can also serve tables that already exist in a database it does not own.
11
+
12
+ ## Interfaces
13
+
14
+ | Interface | Documentation |
15
+ | ------------------------------------------------------------------------------------ | ----------------------------------------------------------- |
16
+ | [`@antelopejs/interface-database`](https://github.com/AntelopeJS/interface-database) | [Database](https://interfaces.antelopejs.com/docs/database) |
17
+
18
+ Schemas, tables, queries, change feeds and atomic mutations are documented on the database interface pages.
19
+
20
+ ## Install
21
+
22
+ ```bash
23
+ ajs project modules add @antelopejs/postgres
24
+ ```
25
+
26
+ The command writes the module's default configuration: `postgres://postgres@localhost:5432/antelopejs`, with `migrations: "safe"`.
27
+
28
+ **Requires PostgreSQL 16 or later.** The adapter uses `pg_input_is_valid` so that a text or jsonb
29
+ value which is not a parseable date yields `null` instead of aborting the whole statement. It is
30
+ the only construct used above PostgreSQL 9.5.
31
+
32
+ ## Configuration
33
+
34
+ ```typescript [antelope.config.ts]
35
+ import { defineConfig } from "@antelopejs/interface-core/config";
36
+
37
+ export default defineConfig({
38
+ name: "my-project",
39
+ modules: {
40
+ postgres: {
41
+ source: {
42
+ type: "package",
43
+ package: "@antelopejs/postgres",
44
+ version: "^0.2.0",
45
+ },
46
+ config: {
47
+ url: "postgres://postgres@localhost:5432/my-project",
48
+ migrations: "safe",
49
+ pool: { max: 10 },
50
+ },
51
+ },
52
+ },
53
+ envOverrides: {
54
+ POSTGRES_URL: "modules.postgres.config.url",
55
+ },
56
+ });
57
+ ```
58
+
59
+ | Key | Description |
60
+ | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
61
+ | `mode` | `"owned"` (default) creates and converges the tables; `"external"` serves existing tables without changing them. |
62
+ | `url` | PostgreSQL connection string. |
63
+ | `migrations` | `"safe"` (default) only adds columns and indexes; `"destructive"` also alters and drops them. See [Schema convergence](./docs/storage.md#schema-convergence). |
64
+ | `schemaPrefix` | Prefix for generated PostgreSQL schema names, for several applications sharing one database. |
65
+ | `pool` | Optional [`pg.Pool`](https://node-postgres.com/apis/pool) options, merged over the URL. |
66
+
67
+ Cursor, statement-timeout and change-feed tuning are in [docs/configuration.md](./docs/configuration.md).
68
+
69
+ ## Quick start
70
+
71
+ In the module that stores data, add the database interface:
72
+
73
+ ```bash
74
+ pnpm add @antelopejs/interface-database
75
+ ```
76
+
77
+ Then follow the [database interface guide](https://framework.antelopejs.com/docs/guides/database) to declare a schema and query it. The same code runs on [`@antelopejs/mongodb`](https://github.com/AntelopeJS/mongodb) and [`@antelopejs/rethinkdb`](https://github.com/AntelopeJS/rethinkdb); [Behaviour worth knowing](./docs/behaviour.md) records where the backends differ.
78
+
79
+ ## Storage layout
80
+
81
+ Unlike the document-store backends, this module treats schema field declarations as real
82
+ DDL: each AntelopeJS schema becomes a PostgreSQL schema, each table a real table, and each
83
+ declared scalar field a natively typed, natively indexable column. Queries compile to a single
84
+ SQL statement — filters become `WHERE` clauses, joins become `JOIN`s, and a `filter` or `orderBy`
85
+ over a declared field reaches its btree index.
86
+
87
+ - One PostgreSQL schema per AntelopeJS schema id
88
+ - Declared scalar fields become typed columns; objects, arrays and undeclared fields live in `jsonb`
89
+ - Schema instances are isolated by an `_instance` discriminator column
90
+ - Additive schema convergence, with destructive changes refused unless explicitly enabled
91
+ - Change feeds, as a durable log plus a pull-based reader
92
+
93
+ **Requires PostgreSQL 16 or later.** The adapter uses `pg_input_is_valid` so that a text or jsonb
94
+ value which is not a parseable date yields `null` instead of aborting the whole statement. It is
95
+ the only construct used above PostgreSQL 9.5.
96
+
97
+ ## Documentation
98
+
99
+ - [Database](https://interfaces.antelopejs.com/docs/database): the `@antelopejs/interface-database` contract this module implements
100
+ - [Configuration](https://framework.antelopejs.com/docs/concepts/configuration): module sources, `config` blocks and config variables in `antelope.config.ts`
101
+
102
+ This repository documents what is specific to the PostgreSQL backend:
103
+
104
+ | | |
105
+ | ---------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
106
+ | [Storage and schema](./docs/storage.md) | What a registered schema becomes in the database, the field-type table, what reaches an index, and how registration converges |
107
+ | [Configuration](./docs/configuration.md) | Every option `construct` accepts |
108
+ | [External mode](./docs/external-mode.md) | Reading tables the module did not create, in a database it does not own |
109
+ | [Change feeds](./docs/change-feeds.md) | `changes()`, its ordering guarantee, its retention contract and its blind spots |
110
+ | [Errors and refusals](./docs/errors.md) | Everything the module refuses, with the message it refuses by |
111
+ | [Behaviour worth knowing](./docs/behaviour.md) | Things that answer rather than throw, where the answer may surprise you — including where this backend differs from the MongoDB and RethinkDB ones |
112
+
113
+ ## Compatibility
114
+
115
+ | Package | Supported range |
116
+ | -------------------------------- | ---------------- |
117
+ | `@antelopejs/interface-database` | `^0.1.8` |
118
+ | `@antelopejs/interface-core` | `>=0.1.1 <1.0.0` |
119
+
120
+ The module is developed and tested against `@antelopejs/core` `^1.14.0` on Node.js 22 and 24, with the `pg` driver `^8.22.0` and PostgreSQL 18.
121
+
122
+ ## Contributing
123
+
124
+ **Node 22 or later is required to develop or test this module**, though the published module itself
125
+ runs on any version its `pg` dependency supports. The floor comes from `testcontainers`, a
126
+ devDependency whose bundled `undici` calls `worker_threads.markAsUncloneable`, absent from Node 20.
127
+
128
+ ```bash
129
+ pnpm install
130
+ pnpm lint
131
+ pnpm format:check
132
+ pnpm knip
133
+ pnpm test:unit # fast loop: this repository's unit specs, no Docker
134
+ pnpm test # everything, against PostgreSQL: unit specs, conformance and external-mode suites
135
+ ```
136
+
137
+ `pnpm test` provisions PostgreSQL with Testcontainers, so it needs a Docker daemon. Besides this
138
+ repository's own tests, it runs the shared conformance suite of `@antelopejs/interface-database`,
139
+ discovered from `antelopeJs.implements`.
140
+
141
+ To test against an existing server instead of a container, set `PG_TEST_URL`. It must point to a
142
+ disposable instance: the external suite drops and recreates a fixture database and may create a role.
143
+
144
+ ```bash
145
+ PG_TEST_URL=postgres://postgres:postgres@localhost:5432/antelopejs_test pnpm test
146
+ ```
147
+
148
+ Read the [contribution guidelines](CONTRIBUTING.md) before opening a pull request.
149
+
150
+ ## License
151
+
152
+ [Apache-2.0](LICENSE)
@@ -0,0 +1,33 @@
1
+ import type { PoolConfig } from "pg";
2
+ export type MigrationMode = "safe" | "destructive";
3
+ export type Mode = "owned" | "external";
4
+ export interface Options {
5
+ mode?: Mode;
6
+ url?: string;
7
+ pool?: PoolConfig;
8
+ schemaPrefix?: string;
9
+ migrations?: MigrationMode;
10
+ cursorBatchSize?: number;
11
+ cursorIdleTimeoutMs?: number;
12
+ statementTimeoutMs?: number;
13
+ changeRetentionMs?: number;
14
+ changeBatchSize?: number;
15
+ changePollIntervalMs?: number;
16
+ }
17
+ export interface ResolvedOptions {
18
+ mode: Mode;
19
+ url: string;
20
+ pool: PoolConfig;
21
+ schemaPrefix: string;
22
+ migrations: MigrationMode;
23
+ cursorBatchSize: number;
24
+ cursorIdleTimeoutMs: number;
25
+ statementTimeoutMs?: number;
26
+ changeRetentionMs: number;
27
+ changeBatchSize: number;
28
+ changePollIntervalMs: number;
29
+ }
30
+ export declare function SetOptions(options?: Options): ResolvedOptions;
31
+ export declare function GetOptions(): ResolvedOptions;
32
+ export declare function IsExternal(): boolean;
33
+ export declare function ClearOptions(): void;
package/dist/config.js ADDED
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SetOptions = SetOptions;
4
+ exports.GetOptions = GetOptions;
5
+ exports.IsExternal = IsExternal;
6
+ exports.ClearOptions = ClearOptions;
7
+ const DEFAULT_URL = "postgres://postgres@localhost:5432/antelopejs";
8
+ const DEFAULT_MODE = "owned";
9
+ const MODES = ["owned", "external"];
10
+ const OWNED_ONLY_OPTIONS = [
11
+ "schemaPrefix",
12
+ "migrations",
13
+ "changeRetentionMs",
14
+ "changeBatchSize",
15
+ "changePollIntervalMs",
16
+ ];
17
+ const DEFAULT_MIGRATIONS = "safe";
18
+ const DEFAULT_SCHEMA_PREFIX = "";
19
+ const DEFAULT_CURSOR_BATCH_SIZE = 100;
20
+ const DEFAULT_CURSOR_IDLE_TIMEOUT_MS = 60_000;
21
+ const DEFAULT_CHANGE_RETENTION_MS = 300_000;
22
+ const DEFAULT_CHANGE_BATCH_SIZE = 256;
23
+ const DEFAULT_CHANGE_POLL_INTERVAL_MS = 5_000;
24
+ const SMALLEST_POSITIVE_INTEGER = 1;
25
+ const NOT_CONFIGURED = "PostgreSQL adapter is not configured: construct() has not run yet";
26
+ let resolved;
27
+ function PositiveSafeInteger(option, supplied, fallback) {
28
+ if (supplied === undefined) {
29
+ return fallback;
30
+ }
31
+ if (typeof supplied !== "number" ||
32
+ !Number.isSafeInteger(supplied) ||
33
+ supplied < SMALLEST_POSITIVE_INTEGER) {
34
+ throw new Error(`${option} must be a positive safe integer, received ${String(supplied)}`);
35
+ }
36
+ return supplied;
37
+ }
38
+ function ResolveMode(options) {
39
+ const mode = options?.mode ?? DEFAULT_MODE;
40
+ if (!MODES.includes(mode)) {
41
+ throw new Error(`mode must be one of ${MODES.join(", ")}, received ${String(mode)}`);
42
+ }
43
+ if (mode === "external") {
44
+ const refused = OWNED_ONLY_OPTIONS.filter((option) => options?.[option] !== undefined);
45
+ if (refused.length > 0) {
46
+ throw new Error(`${refused.join(", ")} cannot be set with mode "external": an external instance owns no schemas, runs no DDL and keeps no change log`);
47
+ }
48
+ }
49
+ return mode;
50
+ }
51
+ function ResolveUrl(mode, options) {
52
+ if (options?.url !== undefined && options.url.trim() !== "") {
53
+ return options.url;
54
+ }
55
+ if (mode === "external") {
56
+ throw new Error(`mode "external" needs a non-empty config.url; set it through the project's envOverrides`);
57
+ }
58
+ return DEFAULT_URL;
59
+ }
60
+ function SetOptions(options) {
61
+ const mode = ResolveMode(options);
62
+ const url = ResolveUrl(mode, options);
63
+ resolved = {
64
+ mode,
65
+ url,
66
+ pool: options?.pool ?? {},
67
+ schemaPrefix: options?.schemaPrefix ?? DEFAULT_SCHEMA_PREFIX,
68
+ migrations: options?.migrations ?? DEFAULT_MIGRATIONS,
69
+ cursorBatchSize: PositiveSafeInteger("cursorBatchSize", options?.cursorBatchSize, DEFAULT_CURSOR_BATCH_SIZE),
70
+ cursorIdleTimeoutMs: PositiveSafeInteger("cursorIdleTimeoutMs", options?.cursorIdleTimeoutMs, DEFAULT_CURSOR_IDLE_TIMEOUT_MS),
71
+ statementTimeoutMs: options?.statementTimeoutMs,
72
+ changeRetentionMs: PositiveSafeInteger("changeRetentionMs", options?.changeRetentionMs, DEFAULT_CHANGE_RETENTION_MS),
73
+ changeBatchSize: PositiveSafeInteger("changeBatchSize", options?.changeBatchSize, DEFAULT_CHANGE_BATCH_SIZE),
74
+ changePollIntervalMs: PositiveSafeInteger("changePollIntervalMs", options?.changePollIntervalMs, DEFAULT_CHANGE_POLL_INTERVAL_MS),
75
+ };
76
+ return resolved;
77
+ }
78
+ function GetOptions() {
79
+ if (!resolved) {
80
+ throw new Error(NOT_CONFIGURED);
81
+ }
82
+ return resolved;
83
+ }
84
+ function IsExternal() {
85
+ return GetOptions().mode === "external";
86
+ }
87
+ function ClearOptions() {
88
+ resolved = undefined;
89
+ }
90
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;AAgLA,gCAqCC;AAED,gCAKC;AAGD,gCAEC;AAED,oCAEC;AAzID,MAAM,WAAW,GAAG,+CAA+C,CAAC;AACpE,MAAM,YAAY,GAAS,OAAO,CAAC;AACnC,MAAM,KAAK,GAAoB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;AAOrD,MAAM,kBAAkB,GAA+B;IACrD,cAAc;IACd,YAAY;IACZ,mBAAmB;IACnB,iBAAiB;IACjB,sBAAsB;CACvB,CAAC;AACF,MAAM,kBAAkB,GAAkB,MAAM,CAAC;AACjD,MAAM,qBAAqB,GAAG,EAAE,CAAC;AACjC,MAAM,yBAAyB,GAAG,GAAG,CAAC;AACtC,MAAM,8BAA8B,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,oBAAoB,EAC7B,+BAA+B,CAChC;KACF,CAAC;IACF,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAgB,UAAU;IACxB,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC;IAClC,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAGD,SAAgB,UAAU;IACxB,OAAO,UAAU,EAAE,CAAC,IAAI,KAAK,UAAU,CAAC;AAC1C,CAAC;AAED,SAAgB,YAAY;IAC1B,QAAQ,GAAG,SAAS,CAAC;AACvB,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { Pool, type PoolClient, type QueryResult, type QueryResultRow } from "pg";
2
+ import { type Options } from "./config";
3
+ export type BeforeDisconnect = () => unknown;
4
+ export type PoolTeardown = () => Promise<void>;
5
+ export declare function GuardPool(created: Pool): Pool;
6
+ export declare function Connect(options?: Options): Promise<void>;
7
+ export declare function RegisterBeforeDisconnect(callback: BeforeDisconnect): () => void;
8
+ export declare function SettleBeforeDisconnect(endPool: PoolTeardown): Promise<void>;
9
+ export declare function Disconnect(): Promise<void>;
10
+ export declare function GetPool(): Pool;
11
+ export declare function Query<T extends QueryResultRow = QueryResultRow>(sql: string, params?: unknown[]): Promise<QueryResult<T>>;
12
+ export declare function GuardHeldClient(client: PoolClient): PoolClient;
13
+ export declare function AcquireClient(): Promise<PoolClient>;
14
+ export declare function GetSchemaPrefix(): string;
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GuardPool = GuardPool;
4
+ exports.Connect = Connect;
5
+ exports.RegisterBeforeDisconnect = RegisterBeforeDisconnect;
6
+ exports.SettleBeforeDisconnect = SettleBeforeDisconnect;
7
+ exports.Disconnect = Disconnect;
8
+ exports.GetPool = GetPool;
9
+ exports.Query = Query;
10
+ exports.GuardHeldClient = GuardHeldClient;
11
+ exports.AcquireClient = AcquireClient;
12
+ exports.GetSchemaPrefix = GetSchemaPrefix;
13
+ const pg_1 = require("pg");
14
+ const logger_1 = require("./logger");
15
+ const config_1 = require("./config");
16
+ const NOT_CONNECTED = "PostgreSQL adapter is not connected: construct() has not run yet";
17
+ const SESSION_SETTINGS = "SET TIME ZONE 'UTC'; SET DateStyle = 'ISO, MDY'";
18
+ const CLIENT_ERROR = "error";
19
+ const HELD_CLIENT_FAILED = "the connection under a borrowed PostgreSQL client failed while it was checked out";
20
+ const IDLE_CLIENT_FAILED = "the connection under an idle pooled PostgreSQL client failed";
21
+ const CONNECTED = "connected to PostgreSQL";
22
+ const DISCONNECTED = "disconnected from PostgreSQL";
23
+ const SLOW_ACQUIRE_MS = 10_000;
24
+ const SLOW_ACQUIRE = `no PostgreSQL client has become available in ${SLOW_ACQUIRE_MS} ms: either every pooled connection is checked out — a cursor holds one for as long as it is iterated — or a new connection is not being answered. Raise pool.max, or set pool.connectionTimeoutMillis to fail rather than wait`;
25
+ let pool;
26
+ let isWaiting = false;
27
+ const beforeDisconnect = new Set();
28
+ function PinSession(client) {
29
+ return client.query(SESSION_SETTINGS);
30
+ }
31
+ async function Invoke(callback) {
32
+ return callback();
33
+ }
34
+ function ReportIdleClientError(err) {
35
+ logger_1.Logger.Warn(IDLE_CLIENT_FAILED, err);
36
+ }
37
+ function GuardPool(created) {
38
+ created.on(CLIENT_ERROR, ReportIdleClientError);
39
+ return created;
40
+ }
41
+ async function Connect(options) {
42
+ await Disconnect();
43
+ const resolved = (0, config_1.SetOptions)(options);
44
+ const created = GuardPool(new pg_1.Pool({
45
+ connectionString: resolved.url,
46
+ statement_timeout: resolved.statementTimeoutMs,
47
+ ...resolved.pool,
48
+ onConnect: PinSession,
49
+ }));
50
+ try {
51
+ const client = await created.connect();
52
+ client.release();
53
+ }
54
+ catch (err) {
55
+ await created.end();
56
+ (0, config_1.ClearOptions)();
57
+ throw err;
58
+ }
59
+ pool = created;
60
+ logger_1.Logger.Info(CONNECTED);
61
+ }
62
+ function RegisterBeforeDisconnect(callback) {
63
+ beforeDisconnect.add(callback);
64
+ return () => {
65
+ beforeDisconnect.delete(callback);
66
+ };
67
+ }
68
+ async function SettleBeforeDisconnect(endPool) {
69
+ await Promise.allSettled([...beforeDisconnect].map(Invoke));
70
+ await endPool();
71
+ }
72
+ async function EndPool() {
73
+ const current = pool;
74
+ pool = undefined;
75
+ (0, config_1.ClearOptions)();
76
+ if (current) {
77
+ await current.end();
78
+ logger_1.Logger.Info(DISCONNECTED);
79
+ }
80
+ }
81
+ async function Disconnect() {
82
+ await SettleBeforeDisconnect(EndPool);
83
+ }
84
+ function GetPool() {
85
+ if (!pool) {
86
+ throw new Error(NOT_CONNECTED);
87
+ }
88
+ return pool;
89
+ }
90
+ function Query(sql, params) {
91
+ return GetPool().query(sql, params);
92
+ }
93
+ function ReportHeldClientError(err) {
94
+ logger_1.Logger.Warn(HELD_CLIENT_FAILED, err);
95
+ }
96
+ function WarnSlowAcquire() {
97
+ if (isWaiting) {
98
+ return;
99
+ }
100
+ isWaiting = true;
101
+ logger_1.Logger.Warn(SLOW_ACQUIRE);
102
+ }
103
+ function GuardHeldClient(client) {
104
+ const checkin = client.release;
105
+ client.on(CLIENT_ERROR, ReportHeldClientError);
106
+ client.release = (...args) => {
107
+ client.off(CLIENT_ERROR, ReportHeldClientError);
108
+ client.release = checkin;
109
+ return checkin.apply(client, args);
110
+ };
111
+ return client;
112
+ }
113
+ function AcquireClient() {
114
+ const current = GetPool();
115
+ const slow = setTimeout(WarnSlowAcquire, SLOW_ACQUIRE_MS);
116
+ slow.unref();
117
+ return current
118
+ .connect()
119
+ .then(GuardHeldClient)
120
+ .finally(() => {
121
+ clearTimeout(slow);
122
+ isWaiting = false;
123
+ });
124
+ }
125
+ function GetSchemaPrefix() {
126
+ return (0, config_1.GetOptions)().schemaPrefix;
127
+ }
128
+ //# sourceMappingURL=connection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":";;AA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AAC,eAAe,CAAC;SACrB,OAAO,CAAC,GAAG,EAAE;QACZ,YAAY,CAAC,IAAI,CAAC,CAAC;QACnB,SAAS,GAAG,KAAK,CAAC;IACpB,CAAC,CAAC,CAAC;AACP,CAAC;AAED,SAAgB,eAAe;IAC7B,OAAO,IAAA,mBAAU,GAAE,CAAC,YAAY,CAAC;AACnC,CAAC"}
@@ -0,0 +1,19 @@
1
+ export type ChangeOperation = "added" | "modified" | "removed";
2
+ export declare const CHANGES_STAGE = "changes";
3
+ export declare const LOG: string;
4
+ export declare const REAPED: string;
5
+ export declare const SEQ_COLUMN: string;
6
+ export declare const TXID_COLUMN: string;
7
+ export declare const CREATED_COLUMN: string;
8
+ export declare const SCHEMA_COLUMN: string;
9
+ export declare const TABLE_COLUMN: string;
10
+ export declare const LOG_INSTANCE_COLUMN: string;
11
+ export declare const OP_COLUMN: string;
12
+ export declare const OLD_ROW_COLUMN: string;
13
+ export declare const NEW_ROW_COLUMN: string;
14
+ export declare const SINGLETON_COLUMN: string;
15
+ export declare const HIGH_WATER_COLUMN: string;
16
+ export declare const EPOCH_COLUMN: string;
17
+ export declare const CHANGE_CHANNEL = "antelopejs_changes";
18
+ export declare const CHANGE_LOG_STATEMENTS: readonly string[];
19
+ export declare function TriggerStatements(schemaId: string, tableId: string): readonly string[];