@vrplatform/kysely 1.3.45-4459 → 1.3.45-44603116832

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (352) hide show
  1. package/build/.data.tar +2 -2
  2. package/build/main/camel-case/index.d.ts +4 -4
  3. package/build/main/camel-case/index.js +3 -2
  4. package/build/main/camel-case/index.js.map +1 -1
  5. package/build/main/connect-handoff.d.ts +12 -0
  6. package/build/main/connect-handoff.js +73 -0
  7. package/build/main/connect-handoff.js.map +1 -0
  8. package/build/main/control-plane/index.d.ts +421 -14
  9. package/build/main/control-plane/index.js +71 -0
  10. package/build/main/control-plane/index.js.map +1 -1
  11. package/build/main/domain.d.ts +4 -0
  12. package/build/main/domain.js +3 -0
  13. package/build/main/domain.js.map +1 -0
  14. package/build/main/error.d.ts +2 -1
  15. package/build/main/error.js +2 -1
  16. package/build/main/error.js.map +1 -1
  17. package/build/main/index.d.ts +57 -15
  18. package/build/main/index.js +498 -66
  19. package/build/main/index.js.map +1 -1
  20. package/build/main/isomorphic.d.ts +6 -6
  21. package/build/main/isomorphic.js +4 -8
  22. package/build/main/isomorphic.js.map +1 -1
  23. package/build/main/local/digest.d.ts +3 -3
  24. package/build/main/local/digest.js.map +1 -1
  25. package/build/main/local/generate.js +15 -13
  26. package/build/main/local/generate.js.map +1 -1
  27. package/build/main/local/index.d.ts +5 -1
  28. package/build/main/local/index.js +346 -12
  29. package/build/main/local/index.js.map +1 -1
  30. package/build/main/local/prune-pulled-schema.js +4 -1
  31. package/build/main/local/prune-pulled-schema.js.map +1 -1
  32. package/build/main/migration-source.d.ts +4 -0
  33. package/build/main/migration-source.js +45 -0
  34. package/build/main/migration-source.js.map +1 -0
  35. package/build/main/migration.d.ts +7 -0
  36. package/build/main/migration.js +11 -0
  37. package/build/main/migration.js.map +1 -0
  38. package/build/main/pganalyze-comment-plugin/comment-transformer.js +3 -1
  39. package/build/main/pganalyze-comment-plugin/comment-transformer.js.map +1 -1
  40. package/build/main/pganalyze-comment-plugin/index.js.map +1 -1
  41. package/build/main/plugins.d.ts +2 -2
  42. package/build/main/plugins.js.map +1 -1
  43. package/build/main/postgres-error.d.ts +9 -0
  44. package/build/main/postgres-error.js +28 -0
  45. package/build/main/postgres-error.js.map +1 -0
  46. package/build/main/query/index.d.ts +1 -0
  47. package/build/main/query/index.js +1 -0
  48. package/build/main/query/index.js.map +1 -1
  49. package/build/main/query/listing/status.d.ts +2 -12
  50. package/build/main/query/listing/status.js +35 -20
  51. package/build/main/query/listing/status.js.map +1 -1
  52. package/build/main/query/tenant/billing-partner.d.ts +4 -0
  53. package/build/main/query/tenant/billing-partner.js +8 -0
  54. package/build/main/query/tenant/billing-partner.js.map +1 -0
  55. package/build/main/query/tenant/feature-enabled.d.ts +6 -0
  56. package/build/main/query/tenant/feature-enabled.js +30 -0
  57. package/build/main/query/tenant/feature-enabled.js.map +1 -0
  58. package/build/main/query/tenant/index.d.ts +4 -0
  59. package/build/main/query/tenant/index.js +21 -0
  60. package/build/main/query/tenant/index.js.map +1 -0
  61. package/build/main/query/tenant/status.d.ts +9 -0
  62. package/build/main/query/tenant/status.js +32 -0
  63. package/build/main/query/tenant/status.js.map +1 -0
  64. package/build/main/query/tenant/where-uuid-in.d.ts +2 -0
  65. package/build/main/query/tenant/where-uuid-in.js +14 -0
  66. package/build/main/query/tenant/where-uuid-in.js.map +1 -0
  67. package/build/main/regional.d.ts +31 -4
  68. package/build/main/regional.js +69 -8
  69. package/build/main/regional.js.map +1 -1
  70. package/build/main/test/index.d.ts +21 -11
  71. package/build/main/test/index.js +31 -26
  72. package/build/main/test/index.js.map +1 -1
  73. package/build/main/transaction.d.ts +3 -3
  74. package/build/main/transaction.js.map +1 -1
  75. package/build/main/v1.generated.d.ts +1407 -177
  76. package/build/main/v1.generated.js.map +1 -1
  77. package/build/migrations-v2/0000000000000-baseline.ts +5 -0
  78. package/build/migrations-v2/0000000000001-public-audit-events-v2.ts +137 -0
  79. package/build/migrations-v2/0000000000002-audit-recovery-watermarks.ts +30 -0
  80. package/build/migrations-v2/0000000000003-audit-effect-recovery-watermark.ts +13 -0
  81. package/build/migrations-v2/0000000000004-audit-event-projected-at.ts +15 -0
  82. package/build/migrations-v2/0000000000005-audit-recovery-indexes.ts +63 -0
  83. package/build/migrations-v2/0000000000006-audit-action-public-event-projected-at.ts +22 -0
  84. package/build/migrations-v2/0000000000007-audit-action-public-event-projected-at-backfill.ts +35 -0
  85. package/build/migrations-v2/0000000000008-global-user-attribution.ts +33 -0
  86. package/build/migrations-v2/0000000000008-team-issue-rule-state.ts +52 -0
  87. package/build/migrations-v2/0000000000009-reservation-issue-projections.ts +45 -0
  88. package/build/migrations-v2/0000000000010-bank-rule-application-bank-record-delete-cascade.ts +26 -0
  89. package/build/migrations-v2/0000000000011-guest-balance-journal-entry-lookup-index.ts +25 -0
  90. package/build/migrations-v2/0000000000012-trial-free-analytics-billing-status.ts +72 -0
  91. package/build/migrations-v2/0000000000013-ui-permission-bundles.ts +45 -0
  92. package/build/migrations-v2/0000000000014-ui-permission-bundle-top-up.ts +32 -0
  93. package/build/migrations-v2/0000000000015-durable-flow-events.ts +163 -0
  94. package/build/migrations-v2/0000000000016-billing-listing-facts.ts +539 -0
  95. package/build/migrations-v2/0000000000016-managed-team-access.ts +34 -0
  96. package/build/migrations-v2/0000000000017-drop-trial-until.ts +42 -0
  97. package/build/migrations-v2/0000000000017-webhook-secret-reencryption-failures.ts +18 -0
  98. package/build/migrations-v2/0000000000018-accounting-integrity-monitoring.ts +276 -0
  99. package/build/migrations-v2/0000000000018-durable-flow-event-sensitive-input.ts +28 -0
  100. package/build/migrations-v2/0000000000019-accounting-integrity-run-shards.ts +26 -0
  101. package/build/migrations-v2/0000000000019-asynchronous-operations.ts +736 -0
  102. package/build/migrations-v2/0000000000020-accounting-integrity-case-classification.ts +52 -0
  103. package/build/migrations-v2/0000000000021-payment-line-classification-monitor-indexes.ts +31 -0
  104. package/build/migrations-v2/0000000000022-accounting-integrity-controlled-repairs.ts +281 -0
  105. package/build/migrations-v2/0000000000023-line-classification-usage.ts +325 -0
  106. package/build/migrations-v2/0000000000024-tenant-region-migration.ts +108 -0
  107. package/build/migrations-v2/0000000000025-partner-ach-denial-default.ts +30 -0
  108. package/build/migrations-v2/0000000000026-line-classification-usage-capture.ts +399 -0
  109. package/build/migrations-v2/0000000000027-payout-replacement-chain.ts +27 -0
  110. package/build/migrations-v2/0000000000028-accounting-integrity-operator-workflow.ts +108 -0
  111. package/build/migrations-v2/0000000000029-accounting-integrity-definition-artifacts.ts +40 -0
  112. package/build/migrations-v2/0000000000030-accounting-integrity-review-metadata-compatibility.ts +49 -0
  113. package/build/migrations-v2/0000000000031-ui-permission-role-simplification.ts +70 -0
  114. package/build/migrations-v2/0000000000032-tenant-delete-ownership-cascades.ts +44 -0
  115. package/build/migrations-v2/0000000000033-plaid-connect-session-telemetry.ts +31 -0
  116. package/build/migrations-v2/0000000000033-reservation-issue-seed-bucket-index.ts +19 -0
  117. package/build/migrations-v2/0000000000034-retire-recent-classification-indexes.ts +29 -0
  118. package/build/migrations-v2/0000000000035-core-change-autovacuum.ts +24 -0
  119. package/build/migrations-v2/0000000000036-journal-entry-inactive-reason-constraint.ts +33 -0
  120. package/build/migrations-v2/0000000000037-journal-entry-inactive-reasons.ts +19 -0
  121. package/build/{migrations/0000000000023-journal-entry-currency-mismatch-reason.ts → migrations-v2/0000000000038-journal-entry-group-inactive-reason.ts} +4 -4
  122. package/build/migrations-v2/0000000000039-reservation-guest-breakdown.ts +19 -0
  123. package/build/migrations-v2/0000000000040-csv-import-source-identity-index.ts +23 -0
  124. package/build/migrations-v2/0000000000041-payment-returns.ts +38 -0
  125. package/build/migrations-v2/0000000000042-operation-resource-types.ts +609 -0
  126. package/build/migrations-v2/0000000000043-reservation-journal-freshness.ts +149 -0
  127. package/build/migrations-v2/0000000000044-reservation-journal-freshness-backfill.ts +254 -0
  128. package/build/migrations-v2/0000000000045-reservation-journal-freshness-revision-repair.ts +83 -0
  129. package/build/migrations-v2/0000000000046-materialized-reservation-journal-operations.ts +709 -0
  130. package/build/migrations-v2/0000000000047-public-audit-completion.ts +77 -0
  131. package/build/migrations-v2/0000000000048-reservation-journal-full-refresh-repair.ts +136 -0
  132. package/build/migrations-v2/0000000000049-queued-journal-operation-failures.ts +60 -0
  133. package/build/migrations-v2/0000000000050-connection-oauth-state.ts +43 -0
  134. package/build/migrations-v2/0000000000051-owner-statement-email-delivery.ts +134 -0
  135. package/build/migrations-v2/0000000000052-fee-journal-lock-skip-operations.ts +59 -0
  136. package/build/migrations-v2/0000000000053-fee-journal-lock-skip-null-attempt.ts +44 -0
  137. package/build/migrations-v2/0000000000054-journal-refresh-issue-codes.ts +16 -0
  138. package/build/migrations-v2/0000000000055-tenant-billing-subscription.ts +8 -0
  139. package/build/migrations-v2/0000000000056-journal-operation-failure-precedence.ts +306 -0
  140. package/build/migrations-v2/0000000000057-journal-invalidation-failure-code.ts +28 -0
  141. package/build/migrations-v2/0000000000058-journal-invalidation-locked-failure.ts +16 -0
  142. package/build/migrations-v2/0000000000059-billing-active-listing-cross-region-partner.ts +135 -0
  143. package/build/migrations-v2/0000000000060-accounting-integrity-change-driven.ts +99 -0
  144. package/build/migrations-v2/0000000000061-tenant-pending-onboarding-status.ts +37 -0
  145. package/build/migrations-v2/0000000000062-statement-payout-operations.ts +16 -0
  146. package/build/migrations-v2/0000000000063-missing-account-assignments-issue-code.ts +13 -0
  147. package/build/migrations-v2/0000000000064-journal-invalidation-source-lookup-index.ts +26 -0
  148. package/build/migrations-v2/0000000000065-hasura-connection-event-credentials.ts +42 -0
  149. package/build/migrations-v2/0000000000066-recurring-fee-listing-subscription-match-by.ts +51 -0
  150. package/build/migrations-v2/0000000000067-connection-credential-metadata.ts +60 -0
  151. package/build/migrations-v2/0000000000068-connection-credential-version.ts +34 -0
  152. package/build/migrations-v2/0000000000069-owner-statement-contact-email-delivery.ts +84 -0
  153. package/build/migrations-v2/0000000000070-payment-writer-compatibility.ts +69 -0
  154. package/build/migrations-v2/0000000000071-payments.ts +532 -0
  155. package/build/migrations-v2/0000000000072-journal-entry-payment-index.ts +21 -0
  156. package/build/migrations-v2/0000000000073-batch-invalidation-operation-registration.ts +74 -0
  157. package/build/migrations-v2/0000000000074-owner-statement-email-history.ts +34 -0
  158. package/build/migrations-v2/0000000000075-tenant-deletion-lookup-indexes.ts +46 -0
  159. package/build/migrations-v2/0000000000076-tenant-onboarding-not-null.ts +23 -0
  160. package/build/migrations-v2/0000000000077-payment-writer-statement-attachment.ts +92 -0
  161. package/build/migrations-v2/0000000000078-trigger-timeout-indexes.ts +44 -0
  162. package/build/migrations-v2/0000000000079-core-change-tenant-statistics.ts +26 -0
  163. package/build/migrations-v2/0000000000080-drop-legacy-tracking-event.ts +60 -0
  164. package/build/migrations-v2/0000000000081-recurring-fee-planner-operation-status.ts +35 -0
  165. package/build/migrations-v2/0000000000082-reservation-search-trigram-indexes.ts +54 -0
  166. package/build/migrations-v2/0000000000083-journal-entry-deposit-lookup-index.ts +31 -0
  167. package/build/migrations-v2/0000000000084-journal-entry-reservation-revenue-indexes.ts +57 -0
  168. package/build/migrations-v2/0000000000085-owner-statement-link-email-template.ts +23 -0
  169. package/build/migrations-v2/0000000000086-contact-payment-setup.ts +72 -0
  170. package/build/migrations-v2/0000000000087-address-delete-fk-indexes.ts +30 -0
  171. package/build/migrations-v2/0000000000088-owner-statement-email-switch.ts +76 -0
  172. package/build/migrations-v2/0000000000089-contact-bank-details-requested-at.ts +21 -0
  173. package/build/migrations-v2/0000000000090-contact-bank-account-api-key.ts +22 -0
  174. package/build/migrations-v2/0000000000091-contact-bank-details-request.ts +78 -0
  175. package/build/migrations-v2/0000000000092-payment-provider-reference.ts +22 -0
  176. package/build/migrations-v2/0000000000093-payment-reversal-offline-undo.ts +18 -0
  177. package/build/migrations-v2/0000000000094-reservation-status-checkout-index.ts +37 -0
  178. package/build/migrations-v2/0000000000095-payment-batches.ts +196 -0
  179. package/build/migrations-v2/0000000000096-guide-ongoing-tasks-issue-codes.ts +26 -0
  180. package/build/migrations-v2/0000000000097-reservation-line-mapping-suggestions.ts +53 -0
  181. package/build/migrations-v2/0000000000098-cancelled-reservation-balances-issue-code.ts +13 -0
  182. package/build/migrations-v2/0000000000099-contact-bank-account-request-source.ts +28 -0
  183. package/build/migrations-v2/0000000000100-drop-regional-feature-flags.ts +105 -0
  184. package/build/migrations-v2/0000000000101-bank-record-match-source.ts +45 -0
  185. package/build/migrations-v2/0000000000102-owner-statement-email-one-template.ts +63 -0
  186. package/build/migrations-v2/0000000000103-reservation-line-mapping-update-operation.ts +10 -0
  187. package/build/migrations-v2/0000000000104-export-job-payment-batch-pdf.ts +12 -0
  188. package/build/migrations-v2/0000000000105-drop-regional-token.ts +60 -0
  189. package/build/migrations-v2/0000000000106-incremental-audit-action-source.ts +158 -0
  190. package/build/migrations-v2/0000000000107-audit-mutation-transaction-insert-index.ts +44 -0
  191. package/build/migrations-v2/0000000000108-reservation-stay-type.ts +24 -0
  192. package/build/migrations-v2/0000000000109-long-term-liabilities-category-order.ts +21 -0
  193. package/build/migrations-v2/0000000000110-pms-sync-failures-issue-code.ts +13 -0
  194. package/build/migrations-v2/0000000000110-reservation-line-type-taxable.ts +21 -0
  195. package/build/migrations-v2/0000000000111-reservation-line-type-suggestion-taxable.ts +20 -0
  196. package/build/migrations-v2/0000000000112-contact-payment-method-outside-default.ts +44 -0
  197. package/build/migrations-v2/0000000000113-merchant-fee-reference-assignment.ts +25 -0
  198. package/build/migrations-v2/0000000000114-recurring-fee-nights-filter.ts +32 -0
  199. package/build/migrations-v2/0000000000115-bank-records-with-suggested-rule-issue-code.ts +13 -0
  200. package/build/migrations-v2/0000000000116-guest-review.ts +45 -0
  201. package/build/migrations-v2/0000000000117-ramp-external-funding-accounts.ts +91 -0
  202. package/build/migrations-v2/0000000000118-pm-payout-assignment.ts +25 -0
  203. package/build/migrations-v2/0000000000119-chart-of-accounts-classifications.ts +46 -0
  204. package/build/migrations-v2/0000000000120-feedback.ts +41 -0
  205. package/build/migrations-v2/0000000000121-source-owner-block-calendar-index.ts +43 -0
  206. package/build/migrations-v2/0000000000122-recurring-fee-stay-types-filter.ts +20 -0
  207. package/build/migrations-v2/0000000000123-reservation-owner-stay-type-index.ts +40 -0
  208. package/build/migrations-v2/0000000000124-remove-tenant-test-and-billable-columns.ts +63 -0
  209. package/build/migrations-v2/0000000000125-ramp-application.ts +56 -0
  210. package/build/migrations-v2/0000000000126-advanced-deposits-update-operation.ts +10 -0
  211. package/build/migrations-v2/0000000000127-contact-1099-tax-details.ts +46 -0
  212. package/build/migrations-v2/0000000000128-tax-1099-email-templates.ts +36 -0
  213. package/build/migrations-v2/0000000000129-tenant-locked-at.ts +18 -0
  214. package/build/migrations-v2/0000000000130-second-factor-reset.ts +65 -0
  215. package/build/migrations-v2/0000000000131-payout-hold.ts +49 -0
  216. package/build/migrations-v2/0000000000132-member-invite-approval.ts +62 -0
  217. package/build/migrations-v2/0000000000133-audit-action-client-ip.ts +38 -0
  218. package/build/migrations-v2/0000000000134-drop-orphaned-hasura-triggers.ts +39 -0
  219. package/build/migrations-v2/0000000000135-drop-orphaned-hasura-triggers-literal.ts +42 -0
  220. package/build/migrations-v2/0000000000136-drop-all-hasura-triggers.ts +43 -0
  221. package/build/migrations-v2/0000000000137-webhook-event.ts +57 -0
  222. package/build/migrations-v2/0000000000138-contact-tax-details-requested-at.ts +24 -0
  223. package/build/migrations-v2/0000000000139-tax-statement-1099.ts +140 -0
  224. package/build/migrations-v2/0000000000140-owner-payment-settings.ts +53 -0
  225. package/build/migrations-v2/0000000000141-owner-payment-requests.ts +100 -0
  226. package/build/migrations-v2/0000000000148-statement-level-operation-triggers.ts +229 -0
  227. package/build/migrations-v2/0000000000150-recurring-fee-listing-subscription-listing-index.ts +37 -0
  228. package/build/migrations-v2/0000000000151-core-change-unused-indexes.ts +85 -0
  229. package/build/migrations-v2/0000000000152-core-change-pms-sync-failures-index.ts +38 -0
  230. package/build/migrations-v2/0000000000154-accounting-integrity-backlog-performance.ts +68 -0
  231. package/build/migrations-v2/0000000000155-source-last-successful-hash.ts +23 -0
  232. package/build/module/camel-case/index.d.ts +4 -4
  233. package/build/module/camel-case/index.js +4 -3
  234. package/build/module/camel-case/index.js.map +1 -1
  235. package/build/module/connect-handoff.d.ts +12 -0
  236. package/build/module/connect-handoff.js +70 -0
  237. package/build/module/connect-handoff.js.map +1 -0
  238. package/build/module/control-plane/index.d.ts +421 -14
  239. package/build/module/control-plane/index.js +58 -1
  240. package/build/module/control-plane/index.js.map +1 -1
  241. package/build/module/domain.d.ts +4 -0
  242. package/build/module/domain.js +2 -0
  243. package/build/module/domain.js.map +1 -0
  244. package/build/module/error.d.ts +2 -1
  245. package/build/module/error.js +3 -1
  246. package/build/module/error.js.map +1 -1
  247. package/build/module/index.d.ts +57 -15
  248. package/build/module/index.js +496 -64
  249. package/build/module/index.js.map +1 -1
  250. package/build/module/isomorphic.d.ts +6 -6
  251. package/build/module/isomorphic.js +2 -7
  252. package/build/module/isomorphic.js.map +1 -1
  253. package/build/module/local/digest.d.ts +3 -3
  254. package/build/module/local/digest.js.map +1 -1
  255. package/build/module/local/generate.js +15 -13
  256. package/build/module/local/generate.js.map +1 -1
  257. package/build/module/local/index.d.ts +5 -1
  258. package/build/module/local/index.js +347 -13
  259. package/build/module/local/index.js.map +1 -1
  260. package/build/module/local/prune-pulled-schema.js +4 -1
  261. package/build/module/local/prune-pulled-schema.js.map +1 -1
  262. package/build/module/migration-source.d.ts +4 -0
  263. package/build/module/migration-source.js +42 -0
  264. package/build/module/migration-source.js.map +1 -0
  265. package/build/module/migration.d.ts +7 -0
  266. package/build/module/migration.js +8 -0
  267. package/build/module/migration.js.map +1 -0
  268. package/build/module/pganalyze-comment-plugin/comment-transformer.js +3 -1
  269. package/build/module/pganalyze-comment-plugin/comment-transformer.js.map +1 -1
  270. package/build/module/plugins.d.ts +2 -2
  271. package/build/module/plugins.js.map +1 -1
  272. package/build/module/postgres-error.d.ts +9 -0
  273. package/build/module/postgres-error.js +24 -0
  274. package/build/module/postgres-error.js.map +1 -0
  275. package/build/module/query/index.d.ts +1 -0
  276. package/build/module/query/index.js +1 -0
  277. package/build/module/query/index.js.map +1 -1
  278. package/build/module/query/listing/status.d.ts +2 -12
  279. package/build/module/query/listing/status.js +35 -18
  280. package/build/module/query/listing/status.js.map +1 -1
  281. package/build/module/query/tenant/billing-partner.d.ts +4 -0
  282. package/build/module/query/tenant/billing-partner.js +5 -0
  283. package/build/module/query/tenant/billing-partner.js.map +1 -0
  284. package/build/module/query/tenant/feature-enabled.d.ts +6 -0
  285. package/build/module/query/tenant/feature-enabled.js +27 -0
  286. package/build/module/query/tenant/feature-enabled.js.map +1 -0
  287. package/build/module/query/tenant/index.d.ts +4 -0
  288. package/build/module/query/tenant/index.js +5 -0
  289. package/build/module/query/tenant/index.js.map +1 -0
  290. package/build/module/query/tenant/status.d.ts +9 -0
  291. package/build/module/query/tenant/status.js +28 -0
  292. package/build/module/query/tenant/status.js.map +1 -0
  293. package/build/module/query/tenant/where-uuid-in.d.ts +2 -0
  294. package/build/module/query/tenant/where-uuid-in.js +11 -0
  295. package/build/module/query/tenant/where-uuid-in.js.map +1 -0
  296. package/build/module/regional.d.ts +31 -4
  297. package/build/module/regional.js +68 -8
  298. package/build/module/regional.js.map +1 -1
  299. package/build/module/test/index.d.ts +21 -11
  300. package/build/module/test/index.js +31 -26
  301. package/build/module/test/index.js.map +1 -1
  302. package/build/module/transaction.d.ts +3 -3
  303. package/build/module/transaction.js.map +1 -1
  304. package/build/module/v1.generated.d.ts +1407 -177
  305. package/build/module/v1.generated.js.map +1 -1
  306. package/package.json +19 -16
  307. package/build/migrations/0000000000001-init.ts +0 -5
  308. package/build/migrations/0000000000009-drop-store-schema.ts +0 -14
  309. package/build/migrations/0000000000010-bank-rules.ts +0 -190
  310. package/build/migrations/0000000000011-bank-rule-line-adjustments.ts +0 -65
  311. package/build/migrations/0000000000012-bank-rule-conditions.ts +0 -45
  312. package/build/migrations/0000000000013-bank-rule-name-unique.ts +0 -15
  313. package/build/migrations/0000000000014-bank-rule-drop-legacy-conditions.ts +0 -41
  314. package/build/migrations/0000000000015-booking-channel-logo-dev-provider.ts +0 -70
  315. package/build/migrations/0000000000016-owner-statement-draft-status.ts +0 -22
  316. package/build/migrations/0000000000017-tenant-migration-markers.ts +0 -18
  317. package/build/migrations/0000000000018-security-deposits-payable-category.ts +0 -63
  318. package/build/migrations/0000000000019-tenant-app-settings.ts +0 -76
  319. package/build/migrations/0000000000020-operating-opening-trial-balance.ts +0 -36
  320. package/build/migrations/0000000000021-audit-foreign-key-indexes.ts +0 -77
  321. package/build/migrations/0000000000022-opening-trial-balance-combined-columns.ts +0 -30
  322. package/build/migrations/0000000000024-listing-parent.ts +0 -37
  323. package/build/migrations/0000000000025-journal-entry-parent-listing.ts +0 -26
  324. package/build/migrations/0000000000026-booking-channel-logo-slots.ts +0 -89
  325. package/build/migrations/0000000000027-list-browse-performance-indexes.ts +0 -52
  326. package/build/migrations/0000000000028-flow-setting-status-jsonb.ts +0 -20
  327. package/build/migrations/0000000000029-tenant-slug.ts +0 -328
  328. package/build/migrations/0000000000030-pms-accounting-windows.ts +0 -50
  329. package/build/migrations/0000000000031-owner-statement-projection-listing-revision.ts +0 -20
  330. package/build/migrations/0000000000032-flow-event-listening.ts +0 -28
  331. package/build/migrations/0000000000033-opening-trial-balance-transaction.ts +0 -272
  332. package/build/migrations/0000000000034-historic-general-ledger.ts +0 -24
  333. package/build/migrations/0000000000035-tenant-regional-placement.ts +0 -37
  334. package/build/migrations/0000000000036-control-plane-projection-events.ts +0 -43
  335. package/build/migrations/0000000000037-tenant-guide-onboarding.ts +0 -21
  336. package/build/migrations/0000000000038-tracking-event-analytics-sink.ts +0 -31
  337. package/build/migrations/0000000000039-crunchy-region.ts +0 -86
  338. package/build/migrations/0000000000040-hostaway-region.ts +0 -72
  339. package/build/migrations/0000000000041-audit-tenant-fk.ts +0 -66
  340. package/build/migrations/0000000000042-ramp-staging-connect-params.ts +0 -35
  341. package/build/migrations/0000000000043-gl-pms-accounting-window-guard.ts +0 -125
  342. package/build/migrations/0000000000044-tenant-cross-region-fks.ts +0 -45
  343. package/build/migrations/0000000000045-cloudflare-region-env.ts +0 -100
  344. package/build/migrations/0000000000046-control-plane-outbox-alias.ts +0 -46
  345. package/build/migrations/0000000000047-ramp-contact-last-4-digits.ts +0 -16
  346. package/build/migrations/0000000000047-tenant-status-backfill.ts +0 -40
  347. package/build/migrations/0000000000048-tenant-status-constraint.ts +0 -24
  348. package/build/migrations/0000000000049-health-tenant-issues.ts +0 -69
  349. package/build/migrations/0000000000050-partner-webhooks.ts +0 -135
  350. package/build/migrations/0000000000051-health-webhook-runtime-grants.ts +0 -42
  351. package/build/migrations/0000000000052-feature-approval-team-enablement.ts +0 -13
  352. package/build/migrations/0000000000053-health-webhook-enums.ts +0 -296
@@ -17,92 +17,524 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.DatabaseError = void 0;
20
+ exports.retryPostgresLockFailure = retryPostgresLockFailure;
21
+ exports.retryPostgresConnectionLoss = retryPostgresConnectionLoss;
21
22
  exports.useKysely = useKysely;
23
+ exports.usePostgres = usePostgres;
22
24
  exports.useAsyncPostgres = useAsyncPostgres;
23
25
  exports.useAsyncKysely = useAsyncKysely;
24
- exports.usePostgres = usePostgres;
26
+ exports.useAsyncNeonWebSocketKysely = useAsyncNeonWebSocketKysely;
27
+ exports.useControlPlaneKysely = useControlPlaneKysely;
28
+ exports.useAsyncControlPlaneKysely = useAsyncControlPlaneKysely;
25
29
  exports.forceCloseAllPostgres = forceCloseAllPostgres;
26
30
  const exponential_backoff_1 = require("exponential-backoff");
31
+ const serverless_1 = require("@neondatabase/serverless");
32
+ const kysely_1 = require("kysely");
27
33
  const kysely_postgres_js_1 = require("kysely-postgres-js");
28
34
  const postgres_1 = __importDefault(require("postgres"));
35
+ const control_plane_1 = require("./control-plane");
29
36
  const error_1 = require("./error");
30
37
  const plugins_1 = require("./plugins");
38
+ const postgres_error_1 = require("./postgres-error");
39
+ __exportStar(require("./connect-handoff"), exports);
31
40
  __exportStar(require("./error"), exports);
32
41
  __exportStar(require("./isomorphic"), exports);
42
+ __exportStar(require("./postgres-error"), exports);
33
43
  __exportStar(require("./query"), exports);
34
44
  __exportStar(require("./regional"), exports);
35
45
  __exportStar(require("./transaction"), exports);
36
46
  const utils_1 = require("@vrplatform/utils");
37
- const retryableMessages = ['CONNECTION_CLOSED', 'CONNECT_TIMEOUT'];
47
+ const retryableMessages = [
48
+ 'CONNECTION_CLOSED',
49
+ 'CONNECT_TIMEOUT',
50
+ 'Idle connection closed by Hyperdrive.',
51
+ 'server_login_retry',
52
+ 'Timed out while creating a new server connection.',
53
+ // Neon rejects the login before any statement runs (PRO-19169).
54
+ 'Failed to acquire permit to connect to the database',
55
+ ];
56
+ const postgresRetryAttempts = 3;
57
+ /**
58
+ * Parameter types PostgreSQL described per statement signature (PRO-18871).
59
+ * Postgres.js describes a statement in a round trip of its own before it can
60
+ * execute it when a parameter type is unknown, and a Worker request always
61
+ * starts on new connections. The patched driver reads and fills this map
62
+ * through its `statement_types` option and then parses, describes, binds and
63
+ * executes a known statement in one round trip. It forgets a statement's
64
+ * types when the statement fails, so a schema change is described again.
65
+ */
66
+ class StatementTypes extends Map {
67
+ set(signature, types) {
68
+ if (!this.has(signature) && this.size >= 2000) {
69
+ this.delete(this.keys().next().value);
70
+ }
71
+ return super.set(signature, types);
72
+ }
73
+ }
74
+ /**
75
+ * Named prepared statements one reserved Hyperdrive connection may hold (PRO-19814).
76
+ * Hyperdrive drops a connection that holds about 105: with a limit of 108 or more
77
+ * the paid payout move answered 503 on staging, with 104 or less it passed. A
78
+ * transaction pins its connection, so a statement past the limit runs unnamed
79
+ * there, without the cross-connection mismatch of PRO-17965; one already named
80
+ * stays named. The margin covers statements earlier reservations named on the
81
+ * same connection.
82
+ */
83
+ const hyperdriveNamedStatementLimit = 64;
84
+ /**
85
+ * Statement types and array types, kept for the isolate's lifetime per
86
+ * database: the control plane, and the regional database of each data region
87
+ * (`''` for the Worker's own). Enum type OIDs differ between databases.
88
+ *
89
+ * Array types map element type OIDs to their array type OIDs. Postgres.js looks
90
+ * them up on every new connection, an origin round trip each, about 100 ms
91
+ * from Frankfurt and 220 ms from Singapore to the control plane (PRO-19580).
92
+ * The first connection fills the map and later connections reuse it. A
93
+ * migration that adds an enum reaches an isolate when it restarts; until then
94
+ * arrays of that enum are neither parsed nor serialized.
95
+ */
96
+ const hyperdriveTypes = new Map();
97
+ function isRetryableConnectionError(error) {
98
+ const message = error instanceof Error ? error.message : String(error);
99
+ return retryableMessages.some((retryable) => message.includes(retryable));
100
+ }
101
+ function isNodeShuttingDown(error) {
102
+ return (error instanceof Error &&
103
+ (error.message === 'Node shutting down' ||
104
+ error.message === 'Node shutting down.' ||
105
+ error.message === 'shutting down'));
106
+ }
107
+ function isConnectionReset(error) {
108
+ return (error instanceof Error && 'code' in error && error.code === 'ECONNRESET');
109
+ }
110
+ function isRetryableConnectionAcquisitionError(error) {
111
+ return (isRetryableConnectionError(error) ||
112
+ isConnectionReset(error) ||
113
+ // Hyperdrive refuses any new connection while its node shuts down
114
+ // (PRO-19168).
115
+ isNodeShuttingDown(error) ||
116
+ (error instanceof Error &&
117
+ (error.message === 'connection attempt failed' ||
118
+ // Opening a connection happens before any statement runs, so the
119
+ // open is safe to retry (PRO-18866).
120
+ error.message === 'Egress connection severed outside of Hyperdrive' ||
121
+ error.message === 'Network connection lost.' ||
122
+ ('code' in error && error.code === 'CONNECTION_DESTROYED'))));
123
+ }
124
+ /**
125
+ * Postgres.js closes a reserved connection when its socket dies, whether the
126
+ * statement in flight fails with `CONNECTION_CLOSED` or with the socket error.
127
+ * A statement sent to it afterwards is never answered: it throws in a timer
128
+ * callback or is silently never written (PRO-17710). A destroyed connection
129
+ * rejects at once, so it needs no guard.
130
+ */
131
+ function isConnectionClosed(error) {
132
+ return (isConnectionReset(error) ||
133
+ (error instanceof Error &&
134
+ 'code' in error &&
135
+ (error.code === 'CONNECTION_CLOSED' ||
136
+ error.code === 'EPIPE' ||
137
+ error.code === 'ETIMEDOUT')));
138
+ }
139
+ function isQueryRetryDiagnosticError(error) {
140
+ const message = error instanceof Error ? error.message : String(error);
141
+ return (isRetryableConnectionError(error) ||
142
+ isConnectionReset(error) ||
143
+ message === 'Egress connection severed outside of Hyperdrive' ||
144
+ message === 'Network connection lost.' ||
145
+ isNodeShuttingDown(error));
146
+ }
147
+ async function retryPostgres(operation, retry, diagnostic) {
148
+ let attemptCount = 0;
149
+ let retried = false;
150
+ let lastError;
151
+ const emitDiagnostic = (outcome) => {
152
+ if (!diagnostic)
153
+ return;
154
+ diagnostic.emit({
155
+ attemptCount,
156
+ dataRegion: diagnostic.dataRegion,
157
+ errorClass: lastError instanceof Error
158
+ ? 'code' in lastError && typeof lastError.code === 'string'
159
+ ? lastError.code
160
+ : lastError.constructor.name
161
+ : 'unknown',
162
+ operationKind: diagnostic.operationKind,
163
+ outcome,
164
+ repositoryName: diagnostic.repositoryName,
165
+ });
166
+ };
167
+ try {
168
+ return await (0, exponential_backoff_1.backOff)(async () => {
169
+ attemptCount++;
170
+ return await operation();
171
+ }, {
172
+ numOfAttempts: postgresRetryAttempts,
173
+ startingDelay: (0, utils_1.parseDuration)('1s'),
174
+ maxDelay: (0, utils_1.parseDuration)('5s'),
175
+ // Scheduled chunk fan-outs open many connections at once; full jitter
176
+ // keeps their retries from reconnecting in lockstep.
177
+ jitter: 'full',
178
+ async retry(error, attemptNumber) {
179
+ lastError = error;
180
+ const shouldRetry = attemptNumber < postgresRetryAttempts &&
181
+ (await retry(error, attemptNumber));
182
+ if (shouldRetry && diagnostic) {
183
+ retried = true;
184
+ emitDiagnostic('retrying');
185
+ }
186
+ return shouldRetry;
187
+ },
188
+ });
189
+ }
190
+ catch (error) {
191
+ lastError = error;
192
+ if (diagnostic?.shouldEmit(error)) {
193
+ emitDiagnostic(retried && attemptCount === postgresRetryAttempts
194
+ ? 'exhausted'
195
+ : 'notRetryable');
196
+ }
197
+ throw error;
198
+ }
199
+ }
38
200
  /**
39
- * @deprecated This method is deprecated in favor of the useAsyncKysely method.
201
+ * Replays a complete database operation after a PostgreSQL deadlock (40P01)
202
+ * or lock timeout (55P03), using the same three-attempt jittered budget as
203
+ * connection retries. The operation must own its transaction and must not
204
+ * contain external side effects such as partner API writes.
40
205
  */
206
+ function retryPostgresLockFailure(operation) {
207
+ return retryPostgres(operation, (error) => (0, postgres_error_1.isPostgresError)(error, { code: '40P01' }) ||
208
+ (0, postgres_error_1.isPostgresError)(error, { code: '55P03' }));
209
+ }
210
+ /**
211
+ * Replays a complete database operation whose connection dropped mid-way, such as a Hyperdrive
212
+ * `CONNECTION_CLOSED`, with the same three-attempt jittered budget. The operation must own its
213
+ * transaction, be safe to replay after a commit whose response was lost, and keep external side
214
+ * effects after its commit.
215
+ */
216
+ function retryPostgresConnectionLoss(operation) {
217
+ return retryPostgres(operation, (error) => isConnectionClosed(error) || isRetryableConnectionError(error));
218
+ }
219
+ class RetryingPostgresJSDialect extends kysely_postgres_js_1.PostgresJSDialect {
220
+ constructor(config, retryDiagnostic, closeOnScriptTimeout) {
221
+ super(config);
222
+ this.config = config;
223
+ this.retryDiagnostic = retryDiagnostic;
224
+ this.closeOnScriptTimeout = closeOnScriptTimeout;
225
+ }
226
+ /** Ends the run when a script's database operation gets no answer (PRO-19037). */
227
+ async withScriptDeadline(operation) {
228
+ if (!this.closeOnScriptTimeout)
229
+ return await operation();
230
+ let timer;
231
+ try {
232
+ return await Promise.race([
233
+ operation(),
234
+ new Promise((_, reject) => {
235
+ timer = setTimeout(() => {
236
+ console.error('Postgres operation timed out', {
237
+ timeoutMs: scriptQueryTimeoutMs,
238
+ });
239
+ this.closeOnScriptTimeout?.();
240
+ reject(new error_1.KyselyError('Postgres operation timed out', {
241
+ timeoutMs: scriptQueryTimeoutMs,
242
+ }));
243
+ }, scriptQueryTimeoutMs);
244
+ }),
245
+ ]);
246
+ }
247
+ finally {
248
+ clearTimeout(timer);
249
+ }
250
+ }
251
+ createDriver() {
252
+ const driver = new kysely_postgres_js_1.PostgresJSDriver(this.config);
253
+ const connections = new WeakMap();
254
+ const getConnection = (connection) => {
255
+ const state = connections.get(connection);
256
+ if (!state)
257
+ throw new Error('Postgres connection state is unavailable');
258
+ return state;
259
+ };
260
+ return {
261
+ init: () => driver.init(),
262
+ acquireConnection: async () => {
263
+ const state = {
264
+ connection: await driver.acquireConnection(),
265
+ inTransaction: false,
266
+ };
267
+ const connection = {
268
+ executeQuery: (compiledQuery) => this.withScriptDeadline(() => {
269
+ const operationKind = state.inTransaction
270
+ ? 'transaction'
271
+ : compiledQuery.query.kind === 'SelectQueryNode'
272
+ ? 'select'
273
+ : 'mutation';
274
+ return retryPostgres(() => {
275
+ if (state.lost)
276
+ return Promise.reject(state.lost);
277
+ return state.connection
278
+ .executeQuery(compiledQuery)
279
+ .catch((error) => {
280
+ if (isConnectionClosed(error))
281
+ state.lost = error;
282
+ throw error;
283
+ });
284
+ }, async (error) => {
285
+ const message = error instanceof Error ? error.message : String(error);
286
+ if (state.inTransaction ||
287
+ (!isRetryableConnectionError(error) &&
288
+ (compiledQuery.query.kind !== 'SelectQueryNode' ||
289
+ (!isConnectionReset(error) &&
290
+ message !==
291
+ 'Egress connection severed outside of Hyperdrive' &&
292
+ message !== 'Network connection lost.' &&
293
+ !isNodeShuttingDown(error))))) {
294
+ return false;
295
+ }
296
+ // Postgres.js already ejects a severed reserved connection.
297
+ // Acquire a new reservation before replaying the safe read.
298
+ state.connection = await driver.acquireConnection();
299
+ state.lost = undefined;
300
+ return true;
301
+ }, this.retryDiagnostic
302
+ ? {
303
+ ...this.retryDiagnostic,
304
+ operationKind,
305
+ shouldEmit: isQueryRetryDiagnosticError,
306
+ }
307
+ : undefined);
308
+ }),
309
+ streamQuery: (compiledQuery, chunkSize) => {
310
+ if (chunkSize === undefined) {
311
+ throw new Error('Postgres stream chunk size is required');
312
+ }
313
+ return state.connection.streamQuery(compiledQuery, chunkSize);
314
+ },
315
+ };
316
+ connections.set(connection, state);
317
+ return connection;
318
+ },
319
+ beginTransaction: async (connection, settings) => {
320
+ const state = getConnection(connection);
321
+ state.inTransaction = true;
322
+ try {
323
+ await this.withScriptDeadline(() => driver.beginTransaction(state.connection, settings));
324
+ }
325
+ catch (error) {
326
+ state.inTransaction = false;
327
+ if (isConnectionClosed(error))
328
+ state.lost = error;
329
+ throw error;
330
+ }
331
+ },
332
+ commitTransaction: async (connection) => {
333
+ const state = getConnection(connection);
334
+ try {
335
+ if (state.lost)
336
+ throw state.lost;
337
+ await this.withScriptDeadline(() => driver.commitTransaction(state.connection));
338
+ }
339
+ finally {
340
+ state.inTransaction = false;
341
+ }
342
+ },
343
+ rollbackTransaction: async (connection) => {
344
+ const state = getConnection(connection);
345
+ try {
346
+ // PostgreSQL rolls the transaction back when its session ends, and a
347
+ // statement on the closed connection would never be answered.
348
+ if (state.lost)
349
+ return;
350
+ await this.withScriptDeadline(() => driver.rollbackTransaction(state.connection));
351
+ }
352
+ finally {
353
+ state.inTransaction = false;
354
+ }
355
+ },
356
+ savepoint: (connection, savepointName, compileQuery) => this.withScriptDeadline(() => {
357
+ const state = getConnection(connection);
358
+ if (state.lost)
359
+ throw state.lost;
360
+ return driver.savepoint(state.connection, savepointName, compileQuery);
361
+ }),
362
+ rollbackToSavepoint: (connection, savepointName, compileQuery) => this.withScriptDeadline(() => {
363
+ const state = getConnection(connection);
364
+ if (state.lost)
365
+ throw state.lost;
366
+ return driver.rollbackToSavepoint(state.connection, savepointName, compileQuery);
367
+ }),
368
+ releaseSavepoint: (connection, savepointName, compileQuery) => this.withScriptDeadline(() => {
369
+ const state = getConnection(connection);
370
+ if (state.lost)
371
+ throw state.lost;
372
+ return driver.releaseSavepoint(state.connection, savepointName, compileQuery);
373
+ }),
374
+ releaseConnection: async (connection) => {
375
+ const state = getConnection(connection);
376
+ connections.delete(connection);
377
+ // Releasing a closed connection would put it back in the open pool,
378
+ // and the next statement on it would hang. Postgres.js reconnects
379
+ // from the closed pool on demand, and a failed reconnect is a
380
+ // retryable CONNECT_TIMEOUT.
381
+ if (state.lost)
382
+ return;
383
+ await driver.releaseConnection(state.connection);
384
+ },
385
+ destroy: () => driver.destroy(),
386
+ };
387
+ }
388
+ }
41
389
  function useKysely(postgres, options) {
42
390
  console.debug('Creating Kysely instance');
43
- const kysely = (0, plugins_1.getKysely)(new kysely_postgres_js_1.PostgresJSDialect({
44
- postgres,
45
- onReserveConnection: async (connection) => {
46
- const executeQuery = connection.executeQuery.bind(connection);
47
- connection.executeQuery = (arg) => (0, exponential_backoff_1.backOff)(async () => await executeQuery(arg), {
48
- numOfAttempts: 3,
49
- startingDelay: (0, utils_1.parseDuration)('1s'),
50
- maxDelay: (0, utils_1.parseDuration)('5s'),
51
- retry: (error) => {
52
- const message = error instanceof Error ? error.message : String(error);
53
- if (retryableMessages.some((m) => message?.includes(m))) {
54
- return true;
55
- }
56
- return false;
57
- },
58
- });
59
- },
60
- }), {
391
+ const emitRetryDiagnostic = options?.onRetryDiagnostic ??
392
+ (options?.repositoryName
393
+ ? (diagnostic) => console.warn('Postgres operation retry diagnostic', diagnostic)
394
+ : undefined);
395
+ const reserveConnection = postgres.reserve.bind(postgres);
396
+ postgres.reserve = async () => {
397
+ const connection = await retryPostgres(reserveConnection, isRetryableConnectionAcquisitionError, emitRetryDiagnostic
398
+ ? {
399
+ dataRegion: options?.dataRegion,
400
+ emit: emitRetryDiagnostic,
401
+ operationKind: 'acquisition',
402
+ repositoryName: options?.repositoryName,
403
+ shouldEmit: isRetryableConnectionAcquisitionError,
404
+ }
405
+ : undefined);
406
+ if (options?.hyperdrive) {
407
+ const unsafe = connection.unsafe;
408
+ const named = new Set();
409
+ connection.unsafe = (query, parameters, queryOptions) => {
410
+ // A statement past the limit runs unnamed; one already named stays named.
411
+ const prepare = named.has(query) || named.size < hyperdriveNamedStatementLimit;
412
+ if (prepare)
413
+ named.add(query);
414
+ return unsafe(query, parameters, { ...queryOptions, prepare });
415
+ };
416
+ }
417
+ return connection;
418
+ };
419
+ const kysely = (0, plugins_1.getKysely)(new RetryingPostgresJSDialect({ postgres }, emitRetryDiagnostic
420
+ ? {
421
+ dataRegion: options?.dataRegion,
422
+ emit: emitRetryDiagnostic,
423
+ repositoryName: options?.repositoryName,
424
+ shouldEmit: isQueryRetryDiagnosticError,
425
+ }
426
+ : undefined, options?.script
427
+ ? () => void postgres.end({ timeout: 0 }).catch(() => undefined)
428
+ : undefined), {
61
429
  repositoryName: options?.repositoryName,
62
430
  log: options?.log,
63
431
  });
64
432
  kysely.destroy = async () => {
65
433
  console.debug('Closing Kysely connection');
66
- await Promise.race([
67
- postgres.end({ timeout: 5000 }).catch(() => undefined),
68
- new Promise((res) => setTimeout(res, 6000)),
69
- ]);
434
+ await postgres.end({ timeout: 5 }).catch(() => undefined);
70
435
  const index = _connections.indexOf(postgres);
71
436
  if (index !== -1)
72
437
  _connections.splice(index, 1);
73
438
  };
74
439
  return kysely;
75
440
  }
441
+ const scriptQueryTimeoutMs = (0, utils_1.parseDuration)('1h');
76
442
  let _connections = [];
443
+ function usePostgres(connectionString, opt) {
444
+ const ssl = opt?.forceDisableSSL !== true && !opt?.hyperdrive;
445
+ const typesKey = opt?.hyperdrive === 'regional'
446
+ ? `regional/${opt.dataRegion ?? ''}`
447
+ : opt?.hyperdrive;
448
+ let types = typesKey ? hyperdriveTypes.get(typesKey) : undefined;
449
+ if (typesKey && !types) {
450
+ types = { arrays: new Map(), statements: new StatementTypes() };
451
+ hyperdriveTypes.set(typesKey, types);
452
+ }
453
+ const sql = (0, postgres_1.default)(connectionString, {
454
+ ssl: ssl ? 'require' : false,
455
+ // Named prepared statements: PRO-17965 (Hyperdrive and Crunchy PgBouncer).
456
+ prepare: true,
457
+ ...(opt?.hyperdrive && types
458
+ ? {
459
+ max: 5,
460
+ // Retire idle clients before Hyperdrive can close them asynchronously.
461
+ idle_timeout: 10,
462
+ statement_types: types.statements,
463
+ array_types: types.arrays,
464
+ // PRO-19758: Hyperdrive forwards this name to the origin. A
465
+ // constant, because Hyperdrive pools origin connections across
466
+ // requests, so a route name would be wrong.
467
+ connection: { application_name: `hyperdrive/${opt.hyperdrive}` },
468
+ // No read-write check (PRO-17156): Hyperdrive pools by transaction,
469
+ // so it covered one origin connection, not the ones later statements
470
+ // run on, and cost an origin round trip per connection (PRO-19580).
471
+ }
472
+ : {
473
+ ...(opt?.max ? { max: opt.max } : {}),
474
+ target_session_attrs: 'read-write',
475
+ connect_timeout: 10,
476
+ idle_timeout: 60,
477
+ // PRO-19758: pg_stat_activity shows which client holds a direct
478
+ // connection.
479
+ ...(opt?.repositoryName
480
+ ? {
481
+ connection: {
482
+ application_name: `${opt.script ? 'script:' : ''}${opt.repositoryName}`.slice(0, 63),
483
+ },
484
+ }
485
+ : {}),
486
+ ...(opt?.script ? { keep_alive: 10 } : {}),
487
+ }),
488
+ });
489
+ if (opt?.onReserve) {
490
+ const { onReserve } = opt;
491
+ const reserve = sql.reserve.bind(sql);
492
+ // Innermost wrapper: it times each open or reuse of a connection, the
493
+ // startup probe too, and is not part of the retry loop (PRO-18952).
494
+ sql.reserve = async () => {
495
+ const startedAtEpochMs = Date.now();
496
+ const startedAt = performance.now();
497
+ try {
498
+ return await reserve();
499
+ }
500
+ finally {
501
+ onReserve({
502
+ durationMs: performance.now() - startedAt,
503
+ startedAtEpochMs,
504
+ });
505
+ }
506
+ };
507
+ }
508
+ // statement_timeout/lock_timeout are role-level settings on the cluster
509
+ // (ALTER ROLE application SET ...) so they cover every pooled
510
+ // connection; per-session SETs here only ever applied to one of them
511
+ _connections.push(sql);
512
+ return sql;
513
+ }
77
514
  async function useAsyncPostgres(connectionString, opt) {
78
515
  const delayMs = 2500;
79
- const retries = opt?.probe === false ? 1 : opt?.retries === false ? 0 : opt?.retries || 3;
80
- const ssl = opt?.forceDisableSSL !== true;
516
+ const probe = opt?.probe === true;
517
+ const retries = probe ? (opt?.retries === false ? 0 : opt?.retries || 3) : 1;
81
518
  const url = new URL(connectionString);
82
- console.debug(`Creating Postgres connection with ${retries} retries and ssl=${ssl} and port=${url.port}`);
519
+ console.debug(`Creating Postgres connection with probe=${probe}, ${retries} attempts, ssl=${opt?.forceDisableSSL !== true && !opt?.hyperdrive}, and port=${url.port}`);
83
520
  if (_connections.length > 0)
84
521
  console.warn(`We already have ${_connections.length} Postgres connections`);
85
522
  for (let attempt = 1; attempt <= retries; attempt++) {
523
+ let sql;
86
524
  try {
87
- const sql = (0, postgres_1.default)(connectionString, {
88
- ssl: ssl ? 'require' : false,
89
- // connect_timeout: 10
90
- // idle_timeout: 10
91
- // enable prepare statements, pgbouncer on crunchy allows for prepared statements
92
- prepare: true,
93
- connect_timeout: 10,
94
- idle_timeout: 60,
95
- });
96
- if (opt?.probe !== false) {
97
- await sql `select 1`;
525
+ sql = usePostgres(connectionString, opt);
526
+ if (probe) {
527
+ // Opening a direct connection already checks that the session is
528
+ // writable; a probe query would add a round trip.
529
+ (await sql.reserve()).release();
98
530
  }
99
- // statement_timeout/lock_timeout are role-level settings on the cluster
100
- // (ALTER ROLE application SET ...) so they cover every pooled
101
- // connection; per-session SETs here only ever applied to one of them
102
- _connections.push(sql);
103
531
  return sql;
104
532
  }
105
533
  catch (err) {
534
+ if (sql) {
535
+ await sql.end({ timeout: 0 }).catch(() => undefined);
536
+ _connections.splice(_connections.indexOf(sql), 1);
537
+ }
106
538
  if (attempt === retries)
107
539
  throw err;
108
540
  console.warn(`Postgres connection failed (attempt ${attempt}), retrying...`);
@@ -116,33 +548,33 @@ async function useAsyncKysely(connectionString, opt) {
116
548
  const sql = await useAsyncPostgres(connectionString, opt);
117
549
  return useKysely(sql, opt);
118
550
  }
119
- /**
120
- * @deprecated This method is deprecated in favor of the useAsyncKysely method.
121
- */
122
- function usePostgres(connectionString, opt) {
123
- if (!connectionString)
124
- throw new error_1.KyselyError('No connection string');
125
- const ssl = opt?.forceDisableSSL !== true;
126
- const url = new URL(connectionString);
127
- console.debug(`Creating sync Postgres connection with ssl=${ssl} and port=${url.port}`);
128
- const pg = (0, postgres_1.default)(connectionString, {
129
- ssl: ssl ? 'require' : false,
130
- });
131
- _connections.push(pg);
132
- return pg;
551
+ async function useAsyncNeonWebSocketKysely(connectionString, opt) {
552
+ const pool = new serverless_1.Pool({ connectionString, max: 5 });
553
+ const kysely = (0, plugins_1.getKysely)(new kysely_1.PostgresDialect({ pool }), opt ?? {});
554
+ kysely.destroy = async () => {
555
+ console.debug('Closing Neon WebSocket Kysely connection');
556
+ await pool.end();
557
+ };
558
+ if (opt?.probe)
559
+ await pool.query('select 1');
560
+ return kysely;
561
+ }
562
+ function useControlPlaneKysely(postgres, options) {
563
+ const kysely = useKysely(postgres, options);
564
+ const controlPlaneKysely = (0, control_plane_1.withControlPlaneSchema)(kysely, 'public');
565
+ // `withPlugin` returns a new instance without the `destroy` that removes
566
+ // this client from `_connections` (PRO-20691).
567
+ controlPlaneKysely.destroy = kysely.destroy;
568
+ return controlPlaneKysely;
569
+ }
570
+ async function useAsyncControlPlaneKysely(connectionString, opt) {
571
+ return useControlPlaneKysely(await useAsyncPostgres(connectionString, opt), opt);
133
572
  }
134
573
  async function forceCloseAllPostgres(timeoutMs = 5000) {
135
574
  await Promise.race([
136
- Promise.all(_connections.map((pg) => pg.end({ timeout: timeoutMs }).catch(() => undefined))),
575
+ Promise.all(_connections.map((pg) => pg.end({ timeout: timeoutMs / 1000 }).catch(() => undefined))),
137
576
  new Promise((res) => setTimeout(res, timeoutMs + 1000)),
138
577
  ]);
139
578
  _connections = [];
140
579
  }
141
- class DatabaseError extends Error {
142
- constructor(message, cause) {
143
- super(message);
144
- this.cause = cause;
145
- }
146
- }
147
- exports.DatabaseError = DatabaseError;
148
580
  //# sourceMappingURL=index.js.map