@vrplatform/kysely 1.3.45-stage.4896 → 1.3.45-stage.490

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 (219) hide show
  1. package/build/.data.tar +0 -0
  2. package/build/main/camel-case/index.js +1 -1
  3. package/build/main/camel-case/index.js.map +1 -1
  4. package/build/main/control-plane/index.d.ts +344 -16
  5. package/build/main/control-plane/index.js +61 -0
  6. package/build/main/control-plane/index.js.map +1 -1
  7. package/build/main/domain.d.ts +4 -0
  8. package/build/main/domain.js +3 -0
  9. package/build/main/domain.js.map +1 -0
  10. package/build/main/error.d.ts +2 -1
  11. package/build/main/error.js +2 -1
  12. package/build/main/error.js.map +1 -1
  13. package/build/main/index.d.ts +19 -14
  14. package/build/main/index.js +235 -59
  15. package/build/main/index.js.map +1 -1
  16. package/build/main/isomorphic.d.ts +5 -5
  17. package/build/main/isomorphic.js +2 -8
  18. package/build/main/isomorphic.js.map +1 -1
  19. package/build/main/local/digest.d.ts +3 -3
  20. package/build/main/local/digest.js.map +1 -1
  21. package/build/main/local/generate.js +10 -8
  22. package/build/main/local/generate.js.map +1 -1
  23. package/build/main/local/index.d.ts +5 -1
  24. package/build/main/local/index.js +321 -10
  25. package/build/main/local/index.js.map +1 -1
  26. package/build/main/local/prune-pulled-schema.js +4 -1
  27. package/build/main/local/prune-pulled-schema.js.map +1 -1
  28. package/build/main/migration.d.ts +7 -0
  29. package/build/main/migration.js +11 -0
  30. package/build/main/migration.js.map +1 -0
  31. package/build/main/plugins.d.ts +2 -2
  32. package/build/main/plugins.js.map +1 -1
  33. package/build/main/postgres-error.d.ts +3 -3
  34. package/build/main/postgres-error.js +4 -3
  35. package/build/main/postgres-error.js.map +1 -1
  36. package/build/main/query/listing/status.d.ts +0 -10
  37. package/build/main/query/listing/status.js +2 -14
  38. package/build/main/query/listing/status.js.map +1 -1
  39. package/build/main/query/tenant/status.d.ts +5 -8
  40. package/build/main/query/tenant/status.js +18 -21
  41. package/build/main/query/tenant/status.js.map +1 -1
  42. package/build/main/regional.d.ts +7 -1
  43. package/build/main/regional.js +30 -17
  44. package/build/main/regional.js.map +1 -1
  45. package/build/main/test/index.d.ts +23 -11
  46. package/build/main/test/index.js +31 -23
  47. package/build/main/test/index.js.map +1 -1
  48. package/build/main/transaction.d.ts +3 -3
  49. package/build/main/transaction.js.map +1 -1
  50. package/build/main/v1.generated.d.ts +771 -139
  51. package/build/main/v1.generated.js.map +1 -1
  52. package/build/migrations-v2/0000000000000-baseline.ts +5 -0
  53. package/build/migrations-v2/0000000000001-public-audit-events-v2.ts +137 -0
  54. package/build/migrations-v2/0000000000002-audit-recovery-watermarks.ts +30 -0
  55. package/build/migrations-v2/0000000000003-audit-effect-recovery-watermark.ts +13 -0
  56. package/build/migrations-v2/0000000000004-audit-event-projected-at.ts +15 -0
  57. package/build/migrations-v2/0000000000005-audit-recovery-indexes.ts +63 -0
  58. package/build/migrations-v2/0000000000006-audit-action-public-event-projected-at.ts +22 -0
  59. package/build/migrations-v2/0000000000007-audit-action-public-event-projected-at-backfill.ts +35 -0
  60. package/build/migrations-v2/0000000000008-global-user-attribution.ts +33 -0
  61. package/build/migrations-v2/0000000000008-team-issue-rule-state.ts +52 -0
  62. package/build/migrations-v2/0000000000009-reservation-issue-projections.ts +45 -0
  63. package/build/migrations-v2/0000000000010-bank-rule-application-bank-record-delete-cascade.ts +26 -0
  64. package/build/migrations-v2/0000000000011-guest-balance-journal-entry-lookup-index.ts +25 -0
  65. package/build/migrations-v2/0000000000012-trial-free-analytics-billing-status.ts +72 -0
  66. package/build/migrations-v2/0000000000013-ui-permission-bundles.ts +45 -0
  67. package/build/migrations-v2/0000000000014-ui-permission-bundle-top-up.ts +32 -0
  68. package/build/migrations-v2/0000000000015-durable-flow-events.ts +163 -0
  69. package/build/migrations-v2/0000000000016-billing-listing-facts.ts +539 -0
  70. package/build/migrations-v2/0000000000016-managed-team-access.ts +34 -0
  71. package/build/migrations-v2/0000000000017-drop-trial-until.ts +42 -0
  72. package/build/migrations-v2/0000000000017-webhook-secret-reencryption-failures.ts +18 -0
  73. package/build/migrations-v2/0000000000018-accounting-integrity-monitoring.ts +276 -0
  74. package/build/migrations-v2/0000000000018-durable-flow-event-sensitive-input.ts +28 -0
  75. package/build/migrations-v2/0000000000019-accounting-integrity-run-shards.ts +26 -0
  76. package/build/migrations-v2/0000000000019-asynchronous-operations.ts +736 -0
  77. package/build/migrations-v2/0000000000020-accounting-integrity-case-classification.ts +52 -0
  78. package/build/migrations-v2/0000000000021-payment-line-classification-monitor-indexes.ts +31 -0
  79. package/build/migrations-v2/0000000000022-accounting-integrity-controlled-repairs.ts +281 -0
  80. package/build/migrations-v2/0000000000023-line-classification-usage.ts +325 -0
  81. package/build/migrations-v2/0000000000024-tenant-region-migration.ts +108 -0
  82. package/build/migrations-v2/0000000000025-partner-ach-denial-default.ts +30 -0
  83. package/build/migrations-v2/0000000000026-line-classification-usage-capture.ts +399 -0
  84. package/build/migrations-v2/0000000000027-payout-replacement-chain.ts +27 -0
  85. package/build/migrations-v2/0000000000028-accounting-integrity-operator-workflow.ts +108 -0
  86. package/build/migrations-v2/0000000000029-accounting-integrity-definition-artifacts.ts +40 -0
  87. package/build/migrations-v2/0000000000030-accounting-integrity-review-metadata-compatibility.ts +49 -0
  88. package/build/migrations-v2/0000000000031-ui-permission-role-simplification.ts +70 -0
  89. package/build/migrations-v2/0000000000032-tenant-delete-ownership-cascades.ts +44 -0
  90. package/build/migrations-v2/0000000000033-reservation-issue-seed-bucket-index.ts +19 -0
  91. package/build/migrations-v2/0000000000034-retire-recent-classification-indexes.ts +29 -0
  92. package/build/migrations-v2/0000000000035-core-change-autovacuum.ts +24 -0
  93. package/build/migrations-v2/0000000000036-journal-entry-inactive-reason-constraint.ts +33 -0
  94. package/build/migrations-v2/0000000000037-journal-entry-inactive-reasons.ts +19 -0
  95. package/build/{migrations/0000000000023-journal-entry-currency-mismatch-reason.ts → migrations-v2/0000000000038-journal-entry-group-inactive-reason.ts} +4 -4
  96. package/build/migrations-v2/0000000000039-reservation-guest-breakdown.ts +19 -0
  97. package/build/migrations-v2/0000000000040-csv-import-source-identity-index.ts +23 -0
  98. package/build/migrations-v2/0000000000041-payment-returns.ts +38 -0
  99. package/build/migrations-v2/0000000000042-operation-resource-types.ts +609 -0
  100. package/build/migrations-v2/0000000000043-reservation-journal-freshness.ts +149 -0
  101. package/build/migrations-v2/0000000000044-reservation-journal-freshness-backfill.ts +254 -0
  102. package/build/migrations-v2/0000000000045-reservation-journal-freshness-revision-repair.ts +83 -0
  103. package/build/migrations-v2/0000000000046-materialized-reservation-journal-operations.ts +709 -0
  104. package/build/migrations-v2/0000000000047-public-audit-completion.ts +77 -0
  105. package/build/migrations-v2/0000000000048-reservation-journal-full-refresh-repair.ts +136 -0
  106. package/build/migrations-v2/0000000000049-queued-journal-operation-failures.ts +60 -0
  107. package/build/migrations-v2/0000000000050-connection-oauth-state.ts +43 -0
  108. package/build/module/camel-case/index.js +1 -1
  109. package/build/module/camel-case/index.js.map +1 -1
  110. package/build/module/control-plane/index.d.ts +344 -16
  111. package/build/module/control-plane/index.js +49 -1
  112. package/build/module/control-plane/index.js.map +1 -1
  113. package/build/module/domain.d.ts +4 -0
  114. package/build/module/domain.js +2 -0
  115. package/build/module/domain.js.map +1 -0
  116. package/build/module/error.d.ts +2 -1
  117. package/build/module/error.js +3 -1
  118. package/build/module/error.js.map +1 -1
  119. package/build/module/index.d.ts +19 -14
  120. package/build/module/index.js +236 -57
  121. package/build/module/index.js.map +1 -1
  122. package/build/module/isomorphic.d.ts +5 -5
  123. package/build/module/isomorphic.js +1 -6
  124. package/build/module/isomorphic.js.map +1 -1
  125. package/build/module/local/digest.d.ts +3 -3
  126. package/build/module/local/digest.js.map +1 -1
  127. package/build/module/local/generate.js +10 -8
  128. package/build/module/local/generate.js.map +1 -1
  129. package/build/module/local/index.d.ts +5 -1
  130. package/build/module/local/index.js +322 -11
  131. package/build/module/local/index.js.map +1 -1
  132. package/build/module/local/prune-pulled-schema.js +4 -1
  133. package/build/module/local/prune-pulled-schema.js.map +1 -1
  134. package/build/module/migration.d.ts +7 -0
  135. package/build/module/migration.js +8 -0
  136. package/build/module/migration.js.map +1 -0
  137. package/build/module/plugins.d.ts +2 -2
  138. package/build/module/plugins.js.map +1 -1
  139. package/build/module/postgres-error.d.ts +3 -3
  140. package/build/module/postgres-error.js +4 -3
  141. package/build/module/postgres-error.js.map +1 -1
  142. package/build/module/query/listing/status.d.ts +0 -10
  143. package/build/module/query/listing/status.js +2 -12
  144. package/build/module/query/listing/status.js.map +1 -1
  145. package/build/module/query/tenant/status.d.ts +5 -8
  146. package/build/module/query/tenant/status.js +18 -21
  147. package/build/module/query/tenant/status.js.map +1 -1
  148. package/build/module/regional.d.ts +7 -1
  149. package/build/module/regional.js +30 -17
  150. package/build/module/regional.js.map +1 -1
  151. package/build/module/test/index.d.ts +23 -11
  152. package/build/module/test/index.js +31 -23
  153. package/build/module/test/index.js.map +1 -1
  154. package/build/module/transaction.d.ts +3 -3
  155. package/build/module/transaction.js.map +1 -1
  156. package/build/module/v1.generated.d.ts +771 -139
  157. package/build/module/v1.generated.js.map +1 -1
  158. package/package.json +5 -4
  159. package/build/migrations/0000000000001-init.ts +0 -5
  160. package/build/migrations/0000000000009-drop-store-schema.ts +0 -14
  161. package/build/migrations/0000000000010-bank-rules.ts +0 -190
  162. package/build/migrations/0000000000011-bank-rule-line-adjustments.ts +0 -65
  163. package/build/migrations/0000000000012-bank-rule-conditions.ts +0 -45
  164. package/build/migrations/0000000000013-bank-rule-name-unique.ts +0 -15
  165. package/build/migrations/0000000000014-bank-rule-drop-legacy-conditions.ts +0 -41
  166. package/build/migrations/0000000000015-booking-channel-logo-dev-provider.ts +0 -70
  167. package/build/migrations/0000000000016-owner-statement-draft-status.ts +0 -22
  168. package/build/migrations/0000000000017-tenant-migration-markers.ts +0 -18
  169. package/build/migrations/0000000000018-security-deposits-payable-category.ts +0 -63
  170. package/build/migrations/0000000000019-tenant-app-settings.ts +0 -76
  171. package/build/migrations/0000000000020-operating-opening-trial-balance.ts +0 -36
  172. package/build/migrations/0000000000021-audit-foreign-key-indexes.ts +0 -77
  173. package/build/migrations/0000000000022-opening-trial-balance-combined-columns.ts +0 -30
  174. package/build/migrations/0000000000024-listing-parent.ts +0 -37
  175. package/build/migrations/0000000000025-journal-entry-parent-listing.ts +0 -26
  176. package/build/migrations/0000000000026-booking-channel-logo-slots.ts +0 -89
  177. package/build/migrations/0000000000027-list-browse-performance-indexes.ts +0 -52
  178. package/build/migrations/0000000000028-flow-setting-status-jsonb.ts +0 -20
  179. package/build/migrations/0000000000029-tenant-slug.ts +0 -328
  180. package/build/migrations/0000000000030-pms-accounting-windows.ts +0 -50
  181. package/build/migrations/0000000000031-owner-statement-projection-listing-revision.ts +0 -20
  182. package/build/migrations/0000000000032-flow-event-listening.ts +0 -28
  183. package/build/migrations/0000000000033-opening-trial-balance-transaction.ts +0 -272
  184. package/build/migrations/0000000000034-historic-general-ledger.ts +0 -24
  185. package/build/migrations/0000000000035-tenant-regional-placement.ts +0 -37
  186. package/build/migrations/0000000000036-control-plane-projection-events.ts +0 -43
  187. package/build/migrations/0000000000037-tenant-guide-onboarding.ts +0 -21
  188. package/build/migrations/0000000000038-tracking-event-analytics-sink.ts +0 -31
  189. package/build/migrations/0000000000039-crunchy-region.ts +0 -86
  190. package/build/migrations/0000000000040-hostaway-region.ts +0 -72
  191. package/build/migrations/0000000000041-audit-tenant-fk.ts +0 -66
  192. package/build/migrations/0000000000042-ramp-staging-connect-params.ts +0 -35
  193. package/build/migrations/0000000000043-gl-pms-accounting-window-guard.ts +0 -125
  194. package/build/migrations/0000000000044-tenant-cross-region-fks.ts +0 -45
  195. package/build/migrations/0000000000045-cloudflare-region-env.ts +0 -100
  196. package/build/migrations/0000000000046-control-plane-outbox-alias.ts +0 -46
  197. package/build/migrations/0000000000047-ramp-contact-last-4-digits.ts +0 -16
  198. package/build/migrations/0000000000047-tenant-status-backfill.ts +0 -40
  199. package/build/migrations/0000000000048-tenant-status-constraint.ts +0 -24
  200. package/build/migrations/0000000000049-health-tenant-issues.ts +0 -69
  201. package/build/migrations/0000000000050-partner-webhooks.ts +0 -135
  202. package/build/migrations/0000000000051-health-webhook-runtime-grants.ts +0 -42
  203. package/build/migrations/0000000000052-feature-approval-team-enablement.ts +0 -13
  204. package/build/migrations/0000000000053-health-webhook-enums.ts +0 -296
  205. package/build/migrations/0000000000054-user-secondary-emails-jsonb.ts +0 -25
  206. package/build/migrations/0000000000055-outbound-webhooks-v1.ts +0 -221
  207. package/build/migrations/0000000000056-connection-webhook-version.ts +0 -18
  208. package/build/migrations/0000000000057-sync-webhook-version.ts +0 -18
  209. package/build/migrations/0000000000058-reservation-webhook-version.ts +0 -18
  210. package/build/migrations/0000000000059-listing-webhook-version.ts +0 -18
  211. package/build/migrations/0000000000060-owner-statement-webhook-version.ts +0 -19
  212. package/build/migrations/0000000000061-transaction-webhook-version.ts +0 -18
  213. package/build/migrations/0000000000062-plaid-connect-session.ts +0 -102
  214. package/build/migrations/0000000000063-pgcrypto.ts +0 -27
  215. package/build/migrations/0000000000064-partner-api-foundation.ts +0 -36
  216. package/build/migrations/0000000000065-canonical-jsonb-shapes.ts +0 -231
  217. package/build/migrations/0000000000066-source-delete-fk-indexes.ts +0 -20
  218. package/build/migrations/0000000000067-remove-opening-trial-balance-account-columns.ts +0 -34
  219. package/build/migrations/0000000000068-bank-record-account-delete-cascade.ts +0 -26
@@ -0,0 +1,77 @@
1
+ import type { Kysely } from 'kysely';
2
+ import { sql } from 'kysely';
3
+
4
+ export async function up(db: Kysely<unknown>): Promise<void> {
5
+ await sql`
6
+ create type audit.actor_organization_type as enum (
7
+ 'vrplatform', 'partner', 'team', 'system'
8
+ )
9
+ `.execute(db);
10
+ await sql`
11
+ alter type audit.source_type add value if not exists 'embedded'
12
+ `.execute(db);
13
+ await sql`
14
+ alter type webhook.subscription_event_type
15
+ add value if not exists 'audit.event.changed'
16
+ `.execute(db);
17
+ await sql`
18
+ alter type webhook.event_type
19
+ add value if not exists 'audit.event.changed'
20
+ `.execute(db);
21
+ await sql`
22
+ alter type webhook.resource_type
23
+ add value if not exists 'auditEvent'
24
+ `.execute(db);
25
+ await sql`
26
+ alter table audit.action
27
+ add column actor_organization_type audit.actor_organization_type,
28
+ add column actor_organization_id uuid,
29
+ add column actor_organization_name text
30
+ `.execute(db);
31
+ await sql`
32
+ alter table audit.mutation
33
+ add column public_outcome jsonb
34
+ `.execute(db);
35
+ await sql`
36
+ alter table audit.public_event
37
+ add column actor_organization_type audit.actor_organization_type,
38
+ add column actor_organization_id uuid,
39
+ add column actor_organization_name text,
40
+ add column attempted_entity_changes jsonb not null default '[]'::jsonb,
41
+ add column blocked_by jsonb not null default '[]'::jsonb,
42
+ add column recovery jsonb not null default '[]'::jsonb
43
+ `.execute(db);
44
+ await sql`
45
+ create index if not exists public_event_tenant_occurred_idx
46
+ on audit.public_event (tenant_id, occurred_at, updated_at, id)
47
+ `.execute(db);
48
+ }
49
+
50
+ export async function down(db: Kysely<unknown>): Promise<void> {
51
+ await sql`
52
+ drop index if exists audit.public_event_tenant_occurred_idx
53
+ `.execute(db);
54
+ await sql`
55
+ alter table audit.public_event
56
+ drop column if exists recovery,
57
+ drop column if exists blocked_by,
58
+ drop column if exists attempted_entity_changes,
59
+ drop column if exists actor_organization_name,
60
+ drop column if exists actor_organization_id,
61
+ drop column if exists actor_organization_type
62
+ `.execute(db);
63
+ await sql`
64
+ alter table audit.action
65
+ drop column if exists actor_organization_name,
66
+ drop column if exists actor_organization_id,
67
+ drop column if exists actor_organization_type
68
+ `.execute(db);
69
+ await sql`
70
+ alter table audit.mutation
71
+ drop column if exists public_outcome
72
+ `.execute(db);
73
+ await sql`
74
+ drop type if exists audit.actor_organization_type
75
+ `.execute(db);
76
+ // PostgreSQL enum values cannot be removed safely without rebuilding source_type.
77
+ }
@@ -0,0 +1,136 @@
1
+ import type { Kysely } from 'kysely';
2
+ import { sql } from 'kysely';
3
+
4
+ export async function up(db: Kysely<unknown>): Promise<void> {
5
+ await sql`
6
+ create temporary table reservation_journal_full_refresh_repair_scope (
7
+ invalidation_id uuid primary key,
8
+ tenant_id uuid not null,
9
+ reservation_id uuid not null,
10
+ applied_at timestamptz not null,
11
+ covering_effect_id uuid not null
12
+ ) on commit drop
13
+ `.execute(db);
14
+
15
+ await sql`
16
+ insert into reservation_journal_full_refresh_repair_scope (
17
+ invalidation_id,
18
+ tenant_id,
19
+ reservation_id,
20
+ applied_at,
21
+ covering_effect_id
22
+ )
23
+ select
24
+ pending.id,
25
+ pending.tenant_id,
26
+ pending.reservation_id,
27
+ covering.applied_at,
28
+ covering.effect_id
29
+ from accounting.reservation_journal_invalidation as pending
30
+ inner join lateral (
31
+ select
32
+ applied.applied_at,
33
+ applied.effect_id
34
+ from accounting.reservation_journal_invalidation as applied
35
+ inner join audit.effect as effect
36
+ on effect.tenant_id = applied.tenant_id
37
+ and effect.id = applied.effect_id
38
+ where applied.tenant_id = pending.tenant_id
39
+ and applied.reservation_id = pending.reservation_id
40
+ and applied.revision >= pending.revision
41
+ and applied.applied_at is not null
42
+ and applied.covered_by_effect_id = applied.effect_id
43
+ and effect.status = 'completed'
44
+ and coalesce(effect.payload ->> 'mode', 'full') = 'full'
45
+ and (
46
+ select attempt.status
47
+ from audit.effect_attempt as attempt
48
+ where attempt.tenant_id = effect.tenant_id
49
+ and attempt.effect_id = effect.id
50
+ order by attempt.attempt_num desc
51
+ limit 1
52
+ ) is distinct from 'skipped_locked'
53
+ order by applied.revision desc
54
+ limit 1
55
+ ) as covering on true
56
+ where pending.applied_at is null
57
+ `.execute(db);
58
+
59
+ await sql`
60
+ update accounting.reservation_journal_invalidation as invalidation
61
+ set
62
+ applied_at = scope.applied_at,
63
+ covered_by_effect_id = scope.covering_effect_id
64
+ from reservation_journal_full_refresh_repair_scope as scope
65
+ where invalidation.id = scope.invalidation_id
66
+ and invalidation.applied_at is null
67
+ `.execute(db);
68
+
69
+ await sql`
70
+ select state.tenant_id
71
+ from accounting.reservation_journal_state as state
72
+ inner join (
73
+ select distinct tenant_id, reservation_id
74
+ from reservation_journal_full_refresh_repair_scope
75
+ ) as scope
76
+ on scope.tenant_id = state.tenant_id
77
+ and scope.reservation_id = state.reservation_id
78
+ order by state.tenant_id, state.reservation_id
79
+ for update of state
80
+ `.execute(db);
81
+
82
+ await sql`
83
+ with advancement as (
84
+ select
85
+ state.tenant_id,
86
+ state.reservation_id,
87
+ coalesce(
88
+ min(invalidation.revision) filter (
89
+ where invalidation.applied_at is null
90
+ ) - 1,
91
+ max(invalidation.revision),
92
+ state.applied_revision
93
+ ) as applied_revision,
94
+ min(invalidation.created_at) filter (
95
+ where invalidation.applied_at is null
96
+ ) as stale_since,
97
+ max(invalidation.applied_at) as calculated_at
98
+ from accounting.reservation_journal_state as state
99
+ inner join (
100
+ select distinct tenant_id, reservation_id
101
+ from reservation_journal_full_refresh_repair_scope
102
+ ) as scope
103
+ on scope.tenant_id = state.tenant_id
104
+ and scope.reservation_id = state.reservation_id
105
+ left join accounting.reservation_journal_invalidation as invalidation
106
+ on invalidation.tenant_id = state.tenant_id
107
+ and invalidation.reservation_id = state.reservation_id
108
+ group by
109
+ state.tenant_id,
110
+ state.reservation_id,
111
+ state.applied_revision
112
+ )
113
+ update accounting.reservation_journal_state as state
114
+ set
115
+ applied_revision = greatest(
116
+ state.applied_revision,
117
+ advancement.applied_revision
118
+ ),
119
+ stale_since = advancement.stale_since,
120
+ calculated_at = case
121
+ when advancement.applied_revision > state.applied_revision
122
+ then greatest(state.calculated_at, advancement.calculated_at)
123
+ else state.calculated_at
124
+ end,
125
+ updated_at = now()
126
+ from advancement
127
+ where state.tenant_id = advancement.tenant_id
128
+ and state.reservation_id = advancement.reservation_id
129
+ and (
130
+ state.applied_revision < advancement.applied_revision
131
+ or state.stale_since is distinct from advancement.stale_since
132
+ )
133
+ `.execute(db);
134
+ }
135
+
136
+ export async function down(_db: Kysely<unknown>): Promise<void> {}
@@ -0,0 +1,60 @@
1
+ import { type Kysely, sql } from 'kysely';
2
+
3
+ export async function up(db: Kysely<unknown>): Promise<void> {
4
+ // Preserve the source lifecycle and failure precedence; ID format is not a failure policy.
5
+ await sql`
6
+ do $$
7
+ declare
8
+ definition text;
9
+ begin
10
+ definition := pg_get_functiondef('core.refresh_operation_state(uuid)'::regprocedure);
11
+ if position('and target_public_id_format = ''action''' in definition) = 0 then
12
+ raise exception 'Journal operation failure projection has an unexpected definition';
13
+ end if;
14
+ execute replace(definition, 'and target_public_id_format = ''action''', '');
15
+ end;
16
+ $$
17
+ `.execute(db);
18
+
19
+ await sql`
20
+ select core.refresh_operation_state(operation.id)
21
+ from core.operation as operation
22
+ where operation.type = 'reservation-journal-refresh'
23
+ and operation.public_id_format = 'legacy'
24
+ and operation.status = 'failed'
25
+ and exists (
26
+ select 1 from core.operation_source as source
27
+ where source.operation_id = operation.id
28
+ and source.source_type = 'audit-action'
29
+ )
30
+ `.execute(db);
31
+ }
32
+
33
+ export async function down(db: Kysely<unknown>): Promise<void> {
34
+ await sql`
35
+ do $$
36
+ declare
37
+ definition text;
38
+ begin
39
+ definition := pg_get_functiondef('core.refresh_operation_state(uuid)'::regprocedure);
40
+ if position('and target_public_id_format = ''action''' in definition) > 0
41
+ or position('and target_action_id is not null then' in definition) = 0 then
42
+ raise exception 'Journal operation failure projection has an unexpected definition';
43
+ end if;
44
+ execute replace(
45
+ definition,
46
+ 'and target_action_id is not null then',
47
+ 'and target_public_id_format = ''action'' and target_action_id is not null then'
48
+ );
49
+ end;
50
+ $$
51
+ `.execute(db);
52
+
53
+ await sql`
54
+ select core.refresh_operation_state(operation.id)
55
+ from core.operation as operation
56
+ where operation.type = 'reservation-journal-refresh'
57
+ and operation.public_id_format = 'legacy'
58
+ and operation.status = 'failed'
59
+ `.execute(db);
60
+ }
@@ -0,0 +1,43 @@
1
+ import type { Kysely } from 'kysely';
2
+ import { sql } from 'kysely';
3
+
4
+ export async function up(db: Kysely<unknown>): Promise<void> {
5
+ await sql`set local lock_timeout = '5s'`.execute(db);
6
+ await sql`set local statement_timeout = '60s'`.execute(db);
7
+ await sql`
8
+ create table public.connection_oauth_state (
9
+ state_hash text primary key,
10
+ tenant_id uuid not null references public.tenant (id) on delete cascade,
11
+ user_id uuid not null,
12
+ app_id text not null,
13
+ connection_id uuid,
14
+ params jsonb not null,
15
+ redirect_uri text not null,
16
+ expires_at timestamptz not null,
17
+ constraint connection_oauth_state_hash_shape check (state_hash ~ '^[0-9a-f]{64}$'),
18
+ constraint connection_oauth_state_params_object check (jsonb_typeof(params) = 'object')
19
+ )
20
+ `.execute(db);
21
+ await sql`create index connection_oauth_state_expiry_idx on public.connection_oauth_state (expires_at)`.execute(
22
+ db
23
+ );
24
+ await sql`create index connection_oauth_state_tenant_idx on public.connection_oauth_state (tenant_id)`.execute(
25
+ db
26
+ );
27
+ await sql`
28
+ do $$
29
+ begin
30
+ if exists (select 1 from pg_roles where rolname = 'application') then
31
+ grant select, insert, delete on public.connection_oauth_state to application;
32
+ -- SELECT FOR UPDATE SKIP LOCKED needs UPDATE on at least one column.
33
+ -- State bindings, parameters, and expiry remain non-updatable at runtime.
34
+ grant update (state_hash) on public.connection_oauth_state to application;
35
+ end if;
36
+ end;
37
+ $$
38
+ `.execute(db);
39
+ }
40
+
41
+ export async function down(db: Kysely<unknown>): Promise<void> {
42
+ await sql`drop table public.connection_oauth_state`.execute(db);
43
+ }
@@ -34,7 +34,7 @@ export class CustomCasePlugin extends CamelCasePlugin {
34
34
  }
35
35
  if (!alias.name.includes('_'))
36
36
  continue;
37
- throw new KyselyError(`Alias ${alias.name} contains underscore`);
37
+ throw new KyselyError('Alias contains underscore', { name: alias.name });
38
38
  }
39
39
  }
40
40
  mapRow(row) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"src/","sources":["camel-case/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,eAAe,GAIhB,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,WAAW,EAAE,MAA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nE,CAAC;IACH,CAAC;IAES,MAAM,CAAC,GAAG;QAClB,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,GAAG;YAAE,OAAO,GAAG,CAAC;QAEhD,MAAM,MAAM,GAAwB,EAAE,CAAC;QACvC,8GAA8G;QAC9G,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YACnC,IAAI,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;YACrB,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;YACpC,iEAAiE;YACjE,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;gBACzB,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;YAC7C,CAAC;YACD,MAAM,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC;QACzB,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["import {\n type AliasNode,\n CamelCasePlugin,\n type IdentifierNode,\n type RawNode,\n type SelectQueryNode,\n} from 'kysely';\nimport { KyselyError } from '../error';\n\nexport class CustomCasePlugin extends CamelCasePlugin {\n // _excludedColumns: Record<string, boolean> = {};\n constructor() {\n super({\n maintainNestedObjectKeys: true,\n });\n }\n\n transformResult(args) {\n return super.transformResult(args);\n }\n\n transformQuery(args) {\n this.verifyAlias(args.node);\n return super.transformQuery(args);\n }\n\n verifyAlias(node: SelectQueryNode) {\n if (!node?.selections) return;\n\n for (const x of node.selections ?? []) {\n const selection = x.selection as AliasNode;\n if (!selection.alias) continue;\n const alias = selection.alias as IdentifierNode;\n\n // alias can be a raw node (jsonArrayFrom)\n if (selection.node.kind === 'RawNode') {\n const rawNode = selection.node as RawNode;\n for (const x of rawNode.parameters ?? []) {\n if (x.kind === 'SelectQueryNode') {\n const selectQueryNode = x as SelectQueryNode;\n this.verifyAlias(selectQueryNode);\n }\n }\n }\n\n if (!alias.name.includes('_')) continue;\n\n throw new KyselyError(`Alias ${alias.name} contains underscore`);\n }\n }\n\n protected mapRow(row) {\n if (typeof row !== 'object' || !row) return row;\n\n const newRow: Record<string, any> = {};\n // we camel case on first layer, and nested ONLY if in an array (jsonArrayFrom), NOT if it's an object (jsonb)\n for (const key of Object.keys(row)) {\n let value = row[key];\n const newKey = super.camelCase(key);\n // array CAN be non object, so we need to check the first element\n if (Array.isArray(value)) {\n value = value.map((it) => this.mapRow(it));\n }\n newRow[newKey] = value;\n }\n return newRow;\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"src/","sources":["camel-case/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,eAAe,GAIhB,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,MAAM,OAAO,gBAAiB,SAAQ,eAAe;IACnD,kDAAkD;IAClD;QACE,KAAK,CAAC;YACJ,wBAAwB,EAAE,IAAI;SAC/B,CAAC,CAAC;IACL,CAAC;IAED,eAAe,CAAC,IAAI;QAClB,OAAO,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IAED,cAAc,CAAC,IAAI;QACjB,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC5B,OAAO,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,WAAW,CAAC,IAAqB;QAC/B,IAAI,CAAC,IAAI,EAAE,UAAU;YAAE,OAAO;QAE9B,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,UAAU,IAAI,EAAE,EAAE,CAAC;YACtC,MAAM,SAAS,GAAG,CAAC,CAAC,SAAsB,CAAC;YAC3C,IAAI,CAAC,SAAS,CAAC,KAAK;gBAAE,SAAS;YAC/B,MAAM,KAAK,GAAG,SAAS,CAA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ACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["import {\n type AliasNode,\n CamelCasePlugin,\n type IdentifierNode,\n type RawNode,\n type SelectQueryNode,\n} from 'kysely';\nimport { KyselyError } from '../error';\n\nexport class CustomCasePlugin extends CamelCasePlugin {\n // _excludedColumns: Record<string, boolean> = {};\n constructor() {\n super({\n maintainNestedObjectKeys: true,\n });\n }\n\n transformResult(args) {\n return super.transformResult(args);\n }\n\n transformQuery(args) {\n this.verifyAlias(args.node);\n return super.transformQuery(args);\n }\n\n verifyAlias(node: SelectQueryNode) {\n if (!node?.selections) return;\n\n for (const x of node.selections ?? []) {\n const selection = x.selection as AliasNode;\n if (!selection.alias) continue;\n const alias = selection.alias as IdentifierNode;\n\n // alias can be a raw node (jsonArrayFrom)\n if (selection.node.kind === 'RawNode') {\n const rawNode = selection.node as RawNode;\n for (const x of rawNode.parameters ?? []) {\n if (x.kind === 'SelectQueryNode') {\n const selectQueryNode = x as SelectQueryNode;\n this.verifyAlias(selectQueryNode);\n }\n }\n }\n\n if (!alias.name.includes('_')) continue;\n\n throw new KyselyError('Alias contains underscore', { name: alias.name });\n }\n }\n\n protected mapRow(row) {\n if (typeof row !== 'object' || !row) return row;\n\n const newRow: Record<string, any> = {};\n // we camel case on first layer, and nested ONLY if in an array (jsonArrayFrom), NOT if it's an object (jsonb)\n for (const key of Object.keys(row)) {\n let value = row[key];\n const newKey = super.camelCase(key);\n // array CAN be non object, so we need to check the first element\n if (Array.isArray(value)) {\n value = value.map((it) => this.mapRow(it));\n }\n newRow[newKey] = value;\n }\n return newRow;\n }\n}\n"]}