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