@vrplatform/kysely 1.3.45-stage.4839 → 1.3.45-stage.484

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 (218) 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 +345 -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 +760 -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/module/camel-case/index.js +1 -1
  108. package/build/module/camel-case/index.js.map +1 -1
  109. package/build/module/control-plane/index.d.ts +345 -16
  110. package/build/module/control-plane/index.js +49 -1
  111. package/build/module/control-plane/index.js.map +1 -1
  112. package/build/module/domain.d.ts +4 -0
  113. package/build/module/domain.js +2 -0
  114. package/build/module/domain.js.map +1 -0
  115. package/build/module/error.d.ts +2 -1
  116. package/build/module/error.js +3 -1
  117. package/build/module/error.js.map +1 -1
  118. package/build/module/index.d.ts +19 -14
  119. package/build/module/index.js +236 -57
  120. package/build/module/index.js.map +1 -1
  121. package/build/module/isomorphic.d.ts +5 -5
  122. package/build/module/isomorphic.js +1 -6
  123. package/build/module/isomorphic.js.map +1 -1
  124. package/build/module/local/digest.d.ts +3 -3
  125. package/build/module/local/digest.js.map +1 -1
  126. package/build/module/local/generate.js +10 -8
  127. package/build/module/local/generate.js.map +1 -1
  128. package/build/module/local/index.d.ts +5 -1
  129. package/build/module/local/index.js +322 -11
  130. package/build/module/local/index.js.map +1 -1
  131. package/build/module/local/prune-pulled-schema.js +4 -1
  132. package/build/module/local/prune-pulled-schema.js.map +1 -1
  133. package/build/module/migration.d.ts +7 -0
  134. package/build/module/migration.js +8 -0
  135. package/build/module/migration.js.map +1 -0
  136. package/build/module/plugins.d.ts +2 -2
  137. package/build/module/plugins.js.map +1 -1
  138. package/build/module/postgres-error.d.ts +3 -3
  139. package/build/module/postgres-error.js +4 -3
  140. package/build/module/postgres-error.js.map +1 -1
  141. package/build/module/query/listing/status.d.ts +0 -10
  142. package/build/module/query/listing/status.js +2 -12
  143. package/build/module/query/listing/status.js.map +1 -1
  144. package/build/module/query/tenant/status.d.ts +5 -8
  145. package/build/module/query/tenant/status.js +18 -21
  146. package/build/module/query/tenant/status.js.map +1 -1
  147. package/build/module/regional.d.ts +7 -1
  148. package/build/module/regional.js +30 -17
  149. package/build/module/regional.js.map +1 -1
  150. package/build/module/test/index.d.ts +23 -11
  151. package/build/module/test/index.js +31 -23
  152. package/build/module/test/index.js.map +1 -1
  153. package/build/module/transaction.d.ts +3 -3
  154. package/build/module/transaction.js.map +1 -1
  155. package/build/module/v1.generated.d.ts +760 -139
  156. package/build/module/v1.generated.js.map +1 -1
  157. package/package.json +5 -4
  158. package/build/migrations/0000000000001-init.ts +0 -5
  159. package/build/migrations/0000000000009-drop-store-schema.ts +0 -14
  160. package/build/migrations/0000000000010-bank-rules.ts +0 -190
  161. package/build/migrations/0000000000011-bank-rule-line-adjustments.ts +0 -65
  162. package/build/migrations/0000000000012-bank-rule-conditions.ts +0 -45
  163. package/build/migrations/0000000000013-bank-rule-name-unique.ts +0 -15
  164. package/build/migrations/0000000000014-bank-rule-drop-legacy-conditions.ts +0 -41
  165. package/build/migrations/0000000000015-booking-channel-logo-dev-provider.ts +0 -70
  166. package/build/migrations/0000000000016-owner-statement-draft-status.ts +0 -22
  167. package/build/migrations/0000000000017-tenant-migration-markers.ts +0 -18
  168. package/build/migrations/0000000000018-security-deposits-payable-category.ts +0 -63
  169. package/build/migrations/0000000000019-tenant-app-settings.ts +0 -76
  170. package/build/migrations/0000000000020-operating-opening-trial-balance.ts +0 -36
  171. package/build/migrations/0000000000021-audit-foreign-key-indexes.ts +0 -77
  172. package/build/migrations/0000000000022-opening-trial-balance-combined-columns.ts +0 -30
  173. package/build/migrations/0000000000024-listing-parent.ts +0 -37
  174. package/build/migrations/0000000000025-journal-entry-parent-listing.ts +0 -26
  175. package/build/migrations/0000000000026-booking-channel-logo-slots.ts +0 -89
  176. package/build/migrations/0000000000027-list-browse-performance-indexes.ts +0 -52
  177. package/build/migrations/0000000000028-flow-setting-status-jsonb.ts +0 -20
  178. package/build/migrations/0000000000029-tenant-slug.ts +0 -328
  179. package/build/migrations/0000000000030-pms-accounting-windows.ts +0 -50
  180. package/build/migrations/0000000000031-owner-statement-projection-listing-revision.ts +0 -20
  181. package/build/migrations/0000000000032-flow-event-listening.ts +0 -28
  182. package/build/migrations/0000000000033-opening-trial-balance-transaction.ts +0 -272
  183. package/build/migrations/0000000000034-historic-general-ledger.ts +0 -24
  184. package/build/migrations/0000000000035-tenant-regional-placement.ts +0 -37
  185. package/build/migrations/0000000000036-control-plane-projection-events.ts +0 -43
  186. package/build/migrations/0000000000037-tenant-guide-onboarding.ts +0 -21
  187. package/build/migrations/0000000000038-tracking-event-analytics-sink.ts +0 -31
  188. package/build/migrations/0000000000039-crunchy-region.ts +0 -86
  189. package/build/migrations/0000000000040-hostaway-region.ts +0 -72
  190. package/build/migrations/0000000000041-audit-tenant-fk.ts +0 -66
  191. package/build/migrations/0000000000042-ramp-staging-connect-params.ts +0 -35
  192. package/build/migrations/0000000000043-gl-pms-accounting-window-guard.ts +0 -125
  193. package/build/migrations/0000000000044-tenant-cross-region-fks.ts +0 -45
  194. package/build/migrations/0000000000045-cloudflare-region-env.ts +0 -100
  195. package/build/migrations/0000000000046-control-plane-outbox-alias.ts +0 -46
  196. package/build/migrations/0000000000047-ramp-contact-last-4-digits.ts +0 -16
  197. package/build/migrations/0000000000047-tenant-status-backfill.ts +0 -40
  198. package/build/migrations/0000000000048-tenant-status-constraint.ts +0 -24
  199. package/build/migrations/0000000000049-health-tenant-issues.ts +0 -69
  200. package/build/migrations/0000000000050-partner-webhooks.ts +0 -135
  201. package/build/migrations/0000000000051-health-webhook-runtime-grants.ts +0 -42
  202. package/build/migrations/0000000000052-feature-approval-team-enablement.ts +0 -13
  203. package/build/migrations/0000000000053-health-webhook-enums.ts +0 -296
  204. package/build/migrations/0000000000054-user-secondary-emails-jsonb.ts +0 -25
  205. package/build/migrations/0000000000055-outbound-webhooks-v1.ts +0 -221
  206. package/build/migrations/0000000000056-connection-webhook-version.ts +0 -18
  207. package/build/migrations/0000000000057-sync-webhook-version.ts +0 -18
  208. package/build/migrations/0000000000058-reservation-webhook-version.ts +0 -18
  209. package/build/migrations/0000000000059-listing-webhook-version.ts +0 -18
  210. package/build/migrations/0000000000060-owner-statement-webhook-version.ts +0 -19
  211. package/build/migrations/0000000000061-transaction-webhook-version.ts +0 -18
  212. package/build/migrations/0000000000062-plaid-connect-session.ts +0 -102
  213. package/build/migrations/0000000000063-pgcrypto.ts +0 -27
  214. package/build/migrations/0000000000064-partner-api-foundation.ts +0 -36
  215. package/build/migrations/0000000000065-canonical-jsonb-shapes.ts +0 -231
  216. package/build/migrations/0000000000066-source-delete-fk-indexes.ts +0 -20
  217. package/build/migrations/0000000000067-remove-opening-trial-balance-account-columns.ts +0 -34
  218. package/build/migrations/0000000000068-bank-record-account-delete-cascade.ts +0 -26
@@ -1 +1 @@
1
- {"version":3,"file":"generate.js","sourceRoot":"src/","sources":["local/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,qBAAqB,EAAe,QAA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,cAAc;QAC9B,GAAG,EAAE,SAAS;KACf,CAAC,CAAC;IAEH,MAAM,eAAe,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACpD,MAAM,CAAC,OAAO,GAAG,KAAK,IAAI,EAAE;QAC1B,IAAI,WAAW;YAAE,OAAO;QACxB,WAAW,GAAG,IAAI,CAAC;QACnB,yCAAyC;QACzC,MAAM,eAAe,EAAE,CAAC;QACxB,cAAc;QACd,0EAA0E;QAC1E,IAAI;IACN,CAAC,CAAC;IAEF,iFAAiF;IAEjF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { promises as fs } from 'node:fs';\nimport { exists } from 'node:fs/promises';\nimport * as path from 'node:path';\nimport { join } from 'node:path';\nimport { PGlite } from '@electric-sql/pglite';\nimport { FileMigrationProvider, type Kysely, Migrator } from 'kysely';\nimport codegen from 'kysely-codegen';\nimport { PGliteDialect } from 'kysely-pglite-dialect';\nimport { getKysely } from '../plugins';\nimport type { DB } from '../v1.generated';\n\nasync function normalizeGeneratedTypes(root: string) {\n const outFile = path.join(root, 'src/v1.generated.ts');\n const current = await Bun.file(outFile).text();\n const next = current.replace(\n 'export type Timestamp = ColumnType<Date, Date | string, Date | string>;',\n 'export type Timestamp = ColumnType<Date | string, Date | string, Date | string>;'\n );\n\n if (next !== current) {\n await Bun.write(outFile, next);\n }\n}\n\nasync function migrate(root: string, client: PGlite) {\n console.log('migrating pglite ....');\n const glob = new Bun.Glob('initial/*.sql');\n for await (const migration of glob.scan(root)) {\n const raw = await Bun.file(join(root, migration)).text();\n // `pg_dump` (v17+) prepends `\\restrict`/`\\unrestrict` psql meta commands\n // which PostgreSQL-compatible parsers (like PGlite) cannot execute.\n const sanitized = raw.replace(/^\\s*\\\\(?:un)?restrict.*$/gim, '');\n await client.exec(sanitized);\n }\n}\n\nasync function migrateKysely(root: string, kysely: Kysely<DB>) {\n console.log('init migrating kysely ....');\n const migrator = new Migrator({\n db: kysely,\n migrationTableSchema: 'core',\n migrationTableName: 'kysely_migration',\n migrationLockTableName: 'kysely_migration_lock',\n provider: new FileMigrationProvider({\n fs,\n path,\n // This needs to be an absolute path.\n migrationFolder: path.join(root, 'migrations'),\n }),\n });\n\n console.log('migrating kysely ....');\n const { error, results } = await migrator.migrateToLatest().catch(() => {\n console.error('failed to migrate');\n process.exit(1);\n });\n\n for (const it of results ?? []) {\n if (it.status === 'Success') {\n console.log(`migration \"${it.migrationName}\" was executed successfully`);\n } else if (it.status === 'Error') {\n console.error(`failed to execute migration \"${it.migrationName}\"`);\n }\n }\n\n if (error) {\n console.error('failed to migrate');\n console.error(error);\n process.exit(1);\n }\n}\n\nasync function generateDump(root: string, dumpPath: string) {\n const dataExists = await exists(dumpPath).catch(() => false);\n if (!dataExists) {\n console.log('Creating initial dump');\n const main = new PGlite();\n await migrate(root, main).catch(async (err) => {\n console.error('failed to migrate initial dump');\n await Bun.write(\n '../logs/migrate-initial-dump.json',\n JSON.stringify(err as any, null, 2)\n );\n process.exit(1);\n });\n const dialect = new PGliteDialect(main);\n const kysely = getKysely(dialect, {\n repositoryName: 'localTesting',\n log: undefined,\n });\n await migrateKysely(root, kysely).catch(() => {\n console.error('failed to migrate kysely');\n process.exit(1);\n });\n await codegen\n .generate({\n db: kysely,\n outFile: path.join(root, 'src/v1.generated.ts'),\n defaultSchemas: ['xxx'],\n camelCase: true,\n typeMapping: {\n date: 'string',\n },\n dialect: codegen.getDialect('postgres'),\n })\n .catch(() => {\n console.error('failed to generate kysely');\n process.exit(1);\n });\n await normalizeGeneratedTypes(root);\n const content = await main.dumpDataDir('none').catch(() => {\n console.error('failed to dump data');\n process.exit(1);\n });\n await Bun.write(dumpPath, content).catch(() => {\n console.error('failed to write dump');\n process.exit(1);\n });\n return content;\n }\n return Bun.file(dumpPath);\n}\n\nexport async function createLocalKysely(root: string, dumpPath: string) {\n let isDestroyed = false;\n //const now = performance.now();\n\n const dump = await generateDump(root, dumpPath);\n\n const pglite = new PGlite({ loadDataDir: dump });\n // warm up\n await pglite.sql`SELECT 1`;\n const dialect = new PGliteDialect(pglite);\n const kysely = getKysely(dialect, {\n repositoryName: 'localTesting',\n log: undefined,\n });\n\n const originalDestroy = kysely.destroy.bind(kysely);\n kysely.destroy = async () => {\n if (isDestroyed) return;\n isDestroyed = true;\n // const destroyTime = performance.now();\n await originalDestroy();\n //console.log(\n // `Database destroyed: ${Math.round(performance.now() - destroyTime)}ms`\n //);\n };\n\n // console.log(`Database initialized: ${Math.round(performance.now() - now)}ms`);\n\n return kysely;\n}\n"]}
1
+ {"version":3,"file":"generate.js","sourceRoot":"src/","sources":["local/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,qBAAqB,EAAe,QAAQ,EAAE,MAAM,QAAQ,CAAC;AACtE,OAAO,OAAO,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvC,KAAK,UAAU,uBAAuB,CAAC,IAAY;IACjD,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,qBAAqB,CAAC,CAAC;IACvD,MAAM,OAAO,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;IAC/C,MAAM,IAAI,GAAG,OAAO;SACjB,OAAO,CACN,yEAAyE,EACzE,kFAAkF,CACnF;SACA,OAAO,CACN,2CAA2C,EAC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OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { promises as fs } from 'node:fs';\nimport { exists } from 'node:fs/promises';\nimport * as path from 'node:path';\nimport { join } from 'node:path';\nimport { PGlite } from '@electric-sql/pglite';\nimport { FileMigrationProvider, type Kysely, Migrator } from 'kysely';\nimport codegen from 'kysely-codegen';\nimport { PGliteDialect } from 'kysely-pglite-dialect';\nimport { appMigrationEpoch } from '../migration';\nimport { getKysely } from '../plugins';\nimport type { DB } from '../v1.generated';\n\nasync function normalizeGeneratedTypes(root: string) {\n const outFile = path.join(root, 'src/v1.generated.ts');\n const current = await Bun.file(outFile).text();\n const next = current\n .replace(\n 'export type Timestamp = ColumnType<Date, Date | string, Date | string>;',\n 'export type Timestamp = ColumnType<Date | string, Date | string, Date | string>;'\n )\n .replace(\n ' managedTeamAccess: Generated<string>;\\n',\n ' managedTeamAccess: Generated<\"all\" | \"assigned\">;\\n'\n )\n .replace(' slug: string;\\n', ' slug: Generated<string>;\\n');\n\n if (next !== current) {\n await Bun.write(outFile, next);\n }\n}\n\nasync function migrate(root: string, client: PGlite) {\n console.log('migrating pglite ....');\n const glob = new Bun.Glob('initial/*.sql');\n for await (const migration of glob.scan(root)) {\n const raw = await Bun.file(join(root, migration)).text();\n // `pg_dump` (v17+) prepends `\\restrict`/`\\unrestrict` psql meta commands\n // which PostgreSQL-compatible parsers (like PGlite) cannot execute.\n const sanitized = raw.replace(/^\\s*\\\\(?:un)?restrict.*$/gim, '');\n await client.exec(sanitized);\n }\n}\n\nasync function migrateKysely(root: string, kysely: Kysely<DB>) {\n console.log('init migrating kysely ....');\n const migrator = new Migrator({\n allowUnorderedMigrations: true,\n db: kysely,\n migrationTableSchema: appMigrationEpoch.tableSchema,\n migrationTableName: appMigrationEpoch.tableName,\n migrationLockTableName: appMigrationEpoch.lockTableName,\n provider: new FileMigrationProvider({\n fs,\n path,\n // This needs to be an absolute path.\n migrationFolder: path.join(root, appMigrationEpoch.folder),\n }),\n });\n\n console.log('migrating kysely ....');\n const { error, results } = await migrator.migrateToLatest().catch(() => {\n console.error('failed to migrate');\n process.exit(1);\n });\n\n for (const it of results ?? []) {\n if (it.status === 'Success') {\n console.log(`migration \"${it.migrationName}\" was executed successfully`);\n } else if (it.status === 'Error') {\n console.error(`failed to execute migration \"${it.migrationName}\"`);\n }\n }\n\n if (error) {\n console.error('failed to migrate');\n console.error(error);\n process.exit(1);\n }\n}\n\nasync function generateDump(root: string, dumpPath: string) {\n const dataExists = await exists(dumpPath).catch(() => false);\n if (!dataExists) {\n console.log('Creating initial dump');\n const main = new PGlite();\n await migrate(root, main).catch(async (err) => {\n console.error('failed to migrate initial dump');\n await Bun.write(\n '../logs/migrate-initial-dump.json',\n JSON.stringify(err as any, null, 2)\n );\n process.exit(1);\n });\n const dialect = new PGliteDialect(main);\n const kysely = getKysely(dialect, {\n repositoryName: 'localTesting',\n log: undefined,\n });\n await migrateKysely(root, kysely).catch(() => {\n console.error('failed to migrate kysely');\n process.exit(1);\n });\n await codegen\n .generate({\n db: kysely,\n outFile: path.join(root, 'src/v1.generated.ts'),\n defaultSchemas: ['xxx'],\n camelCase: true,\n dialect: codegen.getDialect('postgres'),\n })\n .catch(() => {\n console.error('failed to generate kysely');\n process.exit(1);\n });\n await normalizeGeneratedTypes(root);\n const content = await main.dumpDataDir('none').catch(() => {\n console.error('failed to dump data');\n process.exit(1);\n });\n await Bun.write(dumpPath, content).catch(() => {\n console.error('failed to write dump');\n process.exit(1);\n });\n return content;\n }\n return Bun.file(dumpPath);\n}\n\nexport async function createLocalKysely(root: string, dumpPath: string) {\n let isDestroyed = false;\n //const now = performance.now();\n\n const dump = await generateDump(root, dumpPath);\n\n const pglite = new PGlite({ loadDataDir: dump });\n // warm up\n await pglite.sql`SELECT 1`;\n const dialect = new PGliteDialect(pglite);\n const kysely = getKysely(dialect, {\n repositoryName: 'localTesting',\n log: undefined,\n });\n\n const originalDestroy = kysely.destroy.bind(kysely);\n kysely.destroy = async () => {\n if (isDestroyed) return;\n isDestroyed = true;\n // const destroyTime = performance.now();\n await originalDestroy();\n //console.log(\n // `Database destroyed: ${Math.round(performance.now() - destroyTime)}ms`\n //);\n };\n\n // console.log(`Database initialized: ${Math.round(performance.now() - now)}ms`);\n\n return kysely;\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  import { type LogConfig } from 'kysely';
2
+ import type { ControlPlaneKysely } from '../index';
2
3
  import type { DB } from '../v1.generated';
3
4
  export declare const root: string;
4
5
  export declare const dumpPath: string;
@@ -6,4 +7,7 @@ export type UseLocalKyselyOptions = {
6
7
  repositoryName?: string;
7
8
  log?: true | LogConfig;
8
9
  };
9
- export declare function useLocalKysely(args?: UseLocalKyselyOptions): Promise<import("kysely").Kysely<DB>>;
10
+ export type LocalKysely = import('kysely').Kysely<DB> & {
11
+ controlPlaneKysely: ControlPlaneKysely;
12
+ };
13
+ export declare function useLocalKysely(args?: UseLocalKyselyOptions): Promise<LocalKysely>;
@@ -1,22 +1,25 @@
1
1
  import { promises as fs } from 'node:fs';
2
2
  import * as path from 'node:path';
3
3
  import { PGlite } from '@electric-sql/pglite';
4
- import { FileMigrationProvider, Migrator } from 'kysely';
4
+ import { FileMigrationProvider, Migrator, sql } from 'kysely';
5
5
  import { PGliteDialect } from 'kysely-pglite-dialect';
6
+ import { withControlPlaneSchema } from '../control-plane';
7
+ import { appMigrationEpoch } from '../migration';
6
8
  import { getKysely } from '../plugins';
7
9
  import { ensureDigestFunction, ensureGenRandomBytesFunction } from './digest';
8
10
  export const root = path.join(__dirname, '../..');
9
11
  export const dumpPath = path.join(root, '.data.tar');
10
12
  async function migrateToLatest(kysely) {
11
13
  const migrator = new Migrator({
14
+ allowUnorderedMigrations: true,
12
15
  db: kysely,
13
- migrationTableSchema: 'core',
14
- migrationTableName: 'kysely_migration',
15
- migrationLockTableName: 'kysely_migration_lock',
16
+ migrationTableSchema: appMigrationEpoch.tableSchema,
17
+ migrationTableName: appMigrationEpoch.tableName,
18
+ migrationLockTableName: appMigrationEpoch.lockTableName,
16
19
  provider: new FileMigrationProvider({
17
20
  fs,
18
21
  path,
19
- migrationFolder: path.join(root, 'migrations'),
22
+ migrationFolder: path.join(root, appMigrationEpoch.folder),
20
23
  }),
21
24
  });
22
25
  const { error } = await migrator.migrateToLatest();
@@ -24,21 +27,329 @@ async function migrateToLatest(kysely) {
24
27
  throw error;
25
28
  }
26
29
  }
30
+ // Every spec file used to replay this identical bootstrap - migrations, the
31
+ // schema surgery, and the control-plane seed copies - against a freshly loaded
32
+ // snapshot, which measured ~345ms per file against ~185ms for the snapshot load
33
+ // alone. None of it depends on the caller, so it runs once and is cached as a
34
+ // prepared snapshot keyed by everything that determines its content.
35
+ const preparedDumpPrefix = '.data.prepared.';
36
+ let preparedDumpPromise;
37
+ async function preparedDumpKey() {
38
+ const [snapshot, appMigrations, controlPlaneMigrations] = await Promise.all([
39
+ fs.stat(dumpPath),
40
+ fs.readdir(path.join(root, appMigrationEpoch.folder)),
41
+ fs.readdir(path.join(root, 'control-plane-migrations')),
42
+ ]);
43
+ const hasher = new Bun.CryptoHasher('sha256');
44
+ hasher.update(`${snapshot.size}:${snapshot.mtimeMs}`);
45
+ hasher.update(appMigrations.sort().join(','));
46
+ hasher.update(controlPlaneMigrations.sort().join(','));
47
+ // Source of the bootstrap itself, so editing the surgery rebuilds the
48
+ // snapshot. Read through toString() rather than the file: this module is also
49
+ // published as CommonJS, where import.meta is a compile error.
50
+ for (const step of [
51
+ buildPreparedDump,
52
+ migrateToLatest,
53
+ ensureDigestFunction,
54
+ ensureGenRandomBytesFunction,
55
+ ]) {
56
+ hasher.update(step.toString());
57
+ }
58
+ return hasher.digest('hex').slice(0, 16);
59
+ }
60
+ async function resolvePreparedDump() {
61
+ const key = await preparedDumpKey();
62
+ const target = path.join(root, `${preparedDumpPrefix}${key}.tar`);
63
+ const cached = Bun.file(target);
64
+ if (await cached.exists()) {
65
+ return cached;
66
+ }
67
+ const content = await buildPreparedDump();
68
+ // Sibling workers build this concurrently on a cold cache; rename is atomic,
69
+ // so a reader never observes a half-written snapshot.
70
+ const staging = `${target}.${process.pid}.tmp`;
71
+ await Bun.write(staging, content);
72
+ await fs.rename(staging, target);
73
+ // Only finished snapshots: a sibling worker's staging file also carries the
74
+ // prefix, and removing it would break its rename.
75
+ const current = path.basename(target);
76
+ for (const entry of await fs.readdir(root)) {
77
+ if (entry.startsWith(preparedDumpPrefix) &&
78
+ entry.endsWith('.tar') &&
79
+ entry !== current) {
80
+ await fs.rm(path.join(root, entry), { force: true });
81
+ }
82
+ }
83
+ return content;
84
+ }
85
+ async function buildPreparedDump() {
86
+ const pglite = new PGlite({
87
+ loadDataDir: Bun.file(dumpPath),
88
+ });
89
+ const dialect = new PGliteDialect(pglite);
90
+ const kysely = getKysely(dialect, {
91
+ repositoryName: 'localTestingPrepare',
92
+ });
93
+ await ensureDigestFunction(kysely);
94
+ await ensureGenRandomBytesFunction(kysely);
95
+ await migrateToLatest(kysely);
96
+ await sql `alter schema public rename to regional_public`.execute(kysely);
97
+ await sql `alter schema core rename to regional_core`.execute(kysely);
98
+ await sql `create schema public`.execute(kysely);
99
+ await sql `create schema core`.execute(kysely);
100
+ const controlPlaneBootstrapKysely = getKysely(dialect, {
101
+ repositoryName: 'localTestingPrepare/control-plane-bootstrap',
102
+ });
103
+ const controlPlaneMigrator = new Migrator({
104
+ db: controlPlaneBootstrapKysely,
105
+ migrationTableSchema: 'public',
106
+ migrationTableName: 'control_plane_kysely_migration',
107
+ migrationLockTableName: 'control_plane_kysely_migration_lock',
108
+ provider: new FileMigrationProvider({
109
+ fs,
110
+ path,
111
+ migrationFolder: path.join(root, 'control-plane-migrations'),
112
+ }),
113
+ });
114
+ const { error: controlPlaneMigrationError } = await controlPlaneMigrator.migrateToLatest();
115
+ if (controlPlaneMigrationError) {
116
+ throw controlPlaneMigrationError;
117
+ }
118
+ await sql `alter table core.flow set schema public`.execute(controlPlaneBootstrapKysely);
119
+ await sql `alter table core.issue_message_overwrite set schema public`.execute(controlPlaneBootstrapKysely);
120
+ await sql `drop schema core`.execute(controlPlaneBootstrapKysely);
121
+ await sql `alter schema public rename to control_plane`.execute(controlPlaneBootstrapKysely);
122
+ await sql `alter schema regional_public rename to public`.execute(controlPlaneBootstrapKysely);
123
+ await sql `alter schema regional_core rename to core`.execute(controlPlaneBootstrapKysely);
124
+ await sql `
125
+ do $$
126
+ declare
127
+ definition text;
128
+ begin
129
+ select pg_get_functiondef(
130
+ 'control_plane.normalize_tenant_slug(text)'::regprocedure
131
+ ) into definition;
132
+ execute replace(definition, 'public.', 'control_plane.');
133
+
134
+ select pg_get_functiondef(
135
+ 'control_plane.build_unique_tenant_slug(text,uuid)'::regprocedure
136
+ ) into definition;
137
+ execute replace(definition, 'public.', 'control_plane.');
138
+
139
+ select pg_get_functiondef(
140
+ 'control_plane.refresh_operation_state(uuid)'::regprocedure
141
+ ) into definition;
142
+ execute replace(definition, 'public.', 'control_plane.');
143
+
144
+ select pg_get_functiondef(
145
+ 'control_plane.refresh_destructive_job_operation()'::regprocedure
146
+ ) into definition;
147
+ execute replace(definition, 'public.', 'control_plane.');
148
+ end;
149
+ $$;
150
+ `.execute(controlPlaneBootstrapKysely);
151
+ // The canonical VRPlatform tenant. Production code falls back to this exact id
152
+ // in getCalculatedBillingPartnerId, so specs need it to exist without each of
153
+ // them creating - and mutating - their own copy of a shared singleton.
154
+ await kysely
155
+ .insertInto('public.tenant')
156
+ .values({
157
+ id: '7bfec41f-aa3f-4602-95d2-f7996e4f0e59',
158
+ name: 'VRPlatform',
159
+ type: 'partner',
160
+ status: 'active',
161
+ isActive: true,
162
+ isGeneralLedger: false,
163
+ isOnboarding: false,
164
+ partnerId: null,
165
+ billingPartnerId: null,
166
+ defaultCurrency: 'usd',
167
+ statementStartAt: new Date('2020-01-01T00:00:00Z'),
168
+ })
169
+ .onConflict((oc) => oc.column('id').doNothing())
170
+ .execute();
171
+ await sql `
172
+ insert into control_plane.app (
173
+ authentication,
174
+ category,
175
+ color,
176
+ created_at,
177
+ icon,
178
+ icon_round,
179
+ id,
180
+ info,
181
+ name,
182
+ type,
183
+ version
184
+ )
185
+ select
186
+ authentication,
187
+ category,
188
+ color,
189
+ created_at,
190
+ icon,
191
+ icon_round,
192
+ id,
193
+ info,
194
+ name,
195
+ type,
196
+ version
197
+ from public.app
198
+ on conflict (id) do nothing;
199
+ `.execute(controlPlaneBootstrapKysely);
200
+ await sql `
201
+ insert into control_plane.currency (name)
202
+ select name
203
+ from public.currency
204
+ on conflict (name) do nothing;
205
+ `.execute(controlPlaneBootstrapKysely);
206
+ await sql `
207
+ insert into control_plane.booking_channel (
208
+ channel_ref,
209
+ color,
210
+ created_at,
211
+ icon,
212
+ icon_provider,
213
+ id,
214
+ last_generate_run,
215
+ logo,
216
+ logo_provider,
217
+ selected_booking_channel_icon_candidate_id,
218
+ selected_booking_channel_logo_candidate_id,
219
+ unique_ref,
220
+ updated_at
221
+ )
222
+ select
223
+ channel_ref,
224
+ color,
225
+ created_at,
226
+ icon,
227
+ icon_provider,
228
+ id,
229
+ last_generate_run,
230
+ logo,
231
+ logo_provider,
232
+ selected_booking_channel_icon_candidate_id,
233
+ selected_booking_channel_logo_candidate_id,
234
+ unique_ref,
235
+ updated_at
236
+ from public.booking_channel
237
+ on conflict (id) do nothing;
238
+ `.execute(controlPlaneBootstrapKysely);
239
+ await sql `
240
+ insert into control_plane.booking_channel_icon_candidate (
241
+ booking_channel_id,
242
+ cloudflare_image_id,
243
+ color,
244
+ comment,
245
+ created_at,
246
+ external_icon,
247
+ height,
248
+ id,
249
+ provider,
250
+ source,
251
+ updated_at,
252
+ width
253
+ )
254
+ select
255
+ booking_channel_id,
256
+ cloudflare_image_id,
257
+ color,
258
+ comment,
259
+ created_at,
260
+ external_icon,
261
+ height,
262
+ id,
263
+ provider,
264
+ source,
265
+ updated_at,
266
+ width
267
+ from public.booking_channel_icon_candidate
268
+ on conflict (id) do nothing;
269
+ `.execute(controlPlaneBootstrapKysely);
270
+ await sql `
271
+ insert into control_plane.tenant (
272
+ billing_partner_id,
273
+ billing_plan,
274
+ created_at,
275
+ data_region,
276
+ id,
277
+ name,
278
+ partner_id,
279
+ slug,
280
+ status,
281
+ storage_realm,
282
+ type,
283
+ unique_ref,
284
+ updated_at
285
+ )
286
+ select
287
+ billing_partner_id,
288
+ billing_plan,
289
+ created_at,
290
+ data_region,
291
+ id,
292
+ name,
293
+ partner_id,
294
+ slug,
295
+ status,
296
+ storage_realm,
297
+ type,
298
+ unique_ref,
299
+ updated_at
300
+ from public.tenant
301
+ on conflict (id) do nothing;
302
+ `.execute(controlPlaneBootstrapKysely);
303
+ await sql `
304
+ insert into control_plane.token (
305
+ created_at,
306
+ expires_at,
307
+ id,
308
+ nano_id,
309
+ payload,
310
+ tenant_id,
311
+ type,
312
+ user_id
313
+ )
314
+ select
315
+ created_at,
316
+ expires_at,
317
+ id,
318
+ nano_id,
319
+ payload,
320
+ tenant_id,
321
+ type,
322
+ user_id
323
+ from public.token
324
+ on conflict (id) do nothing;
325
+ `.execute(controlPlaneBootstrapKysely);
326
+ const content = await pglite.dumpDataDir('none');
327
+ await kysely.destroy();
328
+ return content;
329
+ }
27
330
  export async function useLocalKysely(args = {}) {
28
331
  let isDestroyed = false;
29
- // const now = performance.now();
30
- const dump = Bun.file(dumpPath);
332
+ preparedDumpPromise ??= resolvePreparedDump();
31
333
  const pglite = new PGlite({
32
- loadDataDir: dump,
334
+ loadDataDir: await preparedDumpPromise,
33
335
  });
336
+ // The constructor is lazy. The bootstrap this replaced forced the snapshot to
337
+ // load before returning, so keep that contract: a returned handle is usable,
338
+ // and a bad snapshot fails here instead of inside an unrelated test.
339
+ await pglite.waitReady;
34
340
  const dialect = new PGliteDialect(pglite);
35
341
  const kysely = getKysely(dialect, {
36
342
  repositoryName: args?.repositoryName ?? 'localTesting',
37
343
  log: args?.log,
38
344
  });
39
- await ensureDigestFunction(kysely);
40
- await ensureGenRandomBytesFunction(kysely);
41
- await migrateToLatest(kysely);
345
+ const controlPlaneKysely = withControlPlaneSchema(getKysely(dialect, {
346
+ repositoryName: `${args.repositoryName ?? 'localTesting'}/control-plane`,
347
+ log: args.log,
348
+ }), 'control_plane', 'control_plane');
349
+ controlPlaneKysely.destroy = async () => { };
350
+ Object.defineProperty(kysely, 'controlPlaneKysely', {
351
+ value: controlPlaneKysely,
352
+ });
42
353
  const originalDestroy = kysely.destroy.bind(kysely);
43
354
  kysely.destroy = async () => {
44
355
  if (isDestroyed)
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"src/","sources":["local/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,qBAAqB,EAAkB,QAAQ,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,oBAAoB,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC;AAE9E,MAAM,CAAC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;AAClD,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;AAOrD,KAAK,UAAU,eAAe,CAAC,MAAmC;IAChE,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC;QAC5B,EAAE,EAAE,MAAM;QACV,oBAAoB,EAAE,MAAM;QAC5B,kBAAkB,EAAE,kBAAkB;QACtC,sBAAsB,EAAE,uBAAuB;QAC/C,QAAQ,EAAE,IAAI,qBAAqB,CAAC;YAClC,EAAE;YACF,IAAI;YACJ,eAAe,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC;SAC/C,CAAC;KACH,CAAC,CAAC;IAEH,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,QAAQ,CAAC,eAAe,EAAE,CAAC;IACnD,IAAI,KAAK,EAAE,CAAC;QACV,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,OAA8B,EAAE;IACnE,IAAI,WAAW,GAAG,KAAK,CAAC;IACxB,iCAAiC;IAEjC,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAEhC,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC;QACxB,WAAW,EAAE,IAAI;KAClB,CAAC,CAAC;IACH,MAAM,OAAO,GAAG,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC;IAC1C,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,EAAE;QAChC,cAAc,EAAE,IAAI,EAAE,cAAc,IAAI,cAAc;QACtD,GAAG,EAAE,IAAI,EAAE,GAAG;KACf,CAAC,CAAC;IACH,MAAM,oBAAoB,CAAC,MAAM,CAAC,CAAC;IACnC,MAAM,4BAA4B,CAAC,MAAM,CAAC,CAAC;IAC3C,MAAM,eAAe,CAAC,MAAqC,CAAC,CAAC;IAE7D,MAAM,eAAe,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACpD,MAAM,CAAC,OAAO,GAAG,KAAK,IAAI,EAAE;QAC1B,IAAI,WAAW;YAAE,OAAO;QACxB,WAAW,GAAG,IAAI,CAAC;QACnB,wCAAwC;QACxC,MAAM,eAAe,EAAE,CAAC;QACxB,cAAc;QACd,0EAA0E;QAC1E,IAAI;IACN,CAAC,CAAC;IAEF,iFAAiF;IAEjF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { promises as fs } from 'node:fs';\nimport * as path from 'node:path';\nimport { PGlite } from '@electric-sql/pglite';\nimport { FileMigrationProvider, type LogConfig, Migrator } from 'kysely';\nimport { PGliteDialect } from 'kysely-pglite-dialect';\nimport { getKysely } from '../plugins';\nimport type { DB } from '../v1.generated';\nimport { ensureDigestFunction, ensureGenRandomBytesFunction } from './digest';\n\nexport const root = path.join(__dirname, '../..');\nexport const dumpPath = path.join(root, '.data.tar');\n\nexport type UseLocalKyselyOptions = {\n repositoryName?: string;\n log?: true | LogConfig;\n};\n\nasync function migrateToLatest(kysely: import('kysely').Kysely<DB>) {\n const migrator = new Migrator({\n db: kysely,\n migrationTableSchema: 'core',\n migrationTableName: 'kysely_migration',\n migrationLockTableName: 'kysely_migration_lock',\n provider: new FileMigrationProvider({\n fs,\n path,\n migrationFolder: path.join(root, 'migrations'),\n }),\n });\n\n const { error } = await migrator.migrateToLatest();\n if (error) {\n throw error;\n }\n}\n\nexport async function useLocalKysely(args: UseLocalKyselyOptions = {}) {\n let isDestroyed = false;\n // const now = performance.now();\n\n const dump = Bun.file(dumpPath);\n\n const pglite = new PGlite({\n loadDataDir: dump,\n });\n const dialect = new PGliteDialect(pglite);\n const kysely = getKysely(dialect, {\n repositoryName: args?.repositoryName ?? 'localTesting',\n log: args?.log,\n });\n await ensureDigestFunction(kysely);\n await ensureGenRandomBytesFunction(kysely);\n await migrateToLatest(kysely as import('kysely').Kysely<DB>);\n\n const originalDestroy = kysely.destroy.bind(kysely);\n kysely.destroy = async () => {\n if (isDestroyed) return;\n isDestroyed = true;\n //const destroyTime = performance.now();\n await originalDestroy();\n //console.log(\n // `Database destroyed: ${Math.round(performance.now() - destroyTime)}ms`\n //);\n };\n\n // console.log(`Database initialized: ${Math.round(performance.now() - now)}ms`);\n\n return kysely;\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"src/","sources":["local/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OA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oBAAoB,EAAE;QAClD,KAAK,EAAE,kBAAkB;KAC1B,CAAC,CAAC;IAEH,MAAM,eAAe,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACpD,MAAM,CAAC,OAAO,GAAG,KAAK,IAAI,EAAE;QAC1B,IAAI,WAAW;YAAE,OAAO;QACxB,WAAW,GAAG,IAAI,CAAC;QACnB,wCAAwC;QACxC,MAAM,eAAe,EAAE,CAAC;QACxB,cAAc;QACd,0EAA0E;QAC1E,IAAI;IACN,CAAC,CAAC;IAEF,iFAAiF;IAEjF,OAAO,MAAqB,CAAC;AAC/B,CAAC","sourcesContent":["import { promises as fs } from 'node:fs';\nimport * as path from 'node:path';\nimport { PGlite } from '@electric-sql/pglite';\nimport { FileMigrationProvider, type LogConfig, Migrator, sql } from 'kysely';\nimport { PGliteDialect } from 'kysely-pglite-dialect';\nimport { type ControlPlaneDB, withControlPlaneSchema } from '../control-plane';\nimport type { ControlPlaneKysely } from '../index';\nimport { appMigrationEpoch } from '../migration';\nimport { getKysely } from '../plugins';\nimport type { DB } from '../v1.generated';\nimport { ensureDigestFunction, ensureGenRandomBytesFunction } from './digest';\n\nexport const root = path.join(__dirname, '../..');\nexport const dumpPath = path.join(root, '.data.tar');\n\nexport type UseLocalKyselyOptions = {\n repositoryName?: string;\n log?: true | LogConfig;\n};\n\nexport type LocalKysely = import('kysely').Kysely<DB> & {\n controlPlaneKysely: ControlPlaneKysely;\n};\n\nasync function migrateToLatest<Database>(\n kysely: import('kysely').Kysely<Database>\n) {\n const migrator = new Migrator({\n allowUnorderedMigrations: true,\n db: kysely,\n migrationTableSchema: appMigrationEpoch.tableSchema,\n migrationTableName: appMigrationEpoch.tableName,\n migrationLockTableName: appMigrationEpoch.lockTableName,\n provider: new FileMigrationProvider({\n fs,\n path,\n migrationFolder: path.join(root, appMigrationEpoch.folder),\n }),\n });\n\n const { error } = await migrator.migrateToLatest();\n if (error) {\n throw error;\n }\n}\n\n// Every spec file used to replay this identical bootstrap - migrations, the\n// schema surgery, and the control-plane seed copies - against a freshly loaded\n// snapshot, which measured ~345ms per file against ~185ms for the snapshot load\n// alone. None of it depends on the caller, so it runs once and is cached as a\n// prepared snapshot keyed by everything that determines its content.\nconst preparedDumpPrefix = '.data.prepared.';\n\nlet preparedDumpPromise: Promise<Blob> | undefined;\n\nasync function preparedDumpKey(): Promise<string> {\n const [snapshot, appMigrations, controlPlaneMigrations] = await Promise.all([\n fs.stat(dumpPath),\n fs.readdir(path.join(root, appMigrationEpoch.folder)),\n fs.readdir(path.join(root, 'control-plane-migrations')),\n ]);\n\n const hasher = new Bun.CryptoHasher('sha256');\n hasher.update(`${snapshot.size}:${snapshot.mtimeMs}`);\n hasher.update(appMigrations.sort().join(','));\n hasher.update(controlPlaneMigrations.sort().join(','));\n // Source of the bootstrap itself, so editing the surgery rebuilds the\n // snapshot. Read through toString() rather than the file: this module is also\n // published as CommonJS, where import.meta is a compile error.\n for (const step of [\n buildPreparedDump,\n migrateToLatest,\n ensureDigestFunction,\n ensureGenRandomBytesFunction,\n ]) {\n hasher.update(step.toString());\n }\n return hasher.digest('hex').slice(0, 16);\n}\n\nasync function resolvePreparedDump(): Promise<Blob> {\n const key = await preparedDumpKey();\n const target = path.join(root, `${preparedDumpPrefix}${key}.tar`);\n const cached = Bun.file(target);\n if (await cached.exists()) {\n return cached;\n }\n\n const content = await buildPreparedDump();\n // Sibling workers build this concurrently on a cold cache; rename is atomic,\n // so a reader never observes a half-written snapshot.\n const staging = `${target}.${process.pid}.tmp`;\n await Bun.write(staging, content);\n await fs.rename(staging, target);\n\n // Only finished snapshots: a sibling worker's staging file also carries the\n // prefix, and removing it would break its rename.\n const current = path.basename(target);\n for (const entry of await fs.readdir(root)) {\n if (\n entry.startsWith(preparedDumpPrefix) &&\n entry.endsWith('.tar') &&\n entry !== current\n ) {\n await fs.rm(path.join(root, entry), { force: true });\n }\n }\n\n return content;\n}\n\nasync function buildPreparedDump(): Promise<Blob> {\n const pglite = new PGlite({\n loadDataDir: Bun.file(dumpPath),\n });\n const dialect = new PGliteDialect(pglite);\n const kysely = getKysely<DB>(dialect, {\n repositoryName: 'localTestingPrepare',\n });\n await ensureDigestFunction(kysely);\n await ensureGenRandomBytesFunction(kysely);\n await migrateToLatest(kysely);\n\n await sql`alter schema public rename to regional_public`.execute(kysely);\n await sql`alter schema core rename to regional_core`.execute(kysely);\n await sql`create schema public`.execute(kysely);\n await sql`create schema core`.execute(kysely);\n\n const controlPlaneBootstrapKysely = getKysely<ControlPlaneDB>(dialect, {\n repositoryName: 'localTestingPrepare/control-plane-bootstrap',\n });\n const controlPlaneMigrator = new Migrator({\n db: controlPlaneBootstrapKysely,\n migrationTableSchema: 'public',\n migrationTableName: 'control_plane_kysely_migration',\n migrationLockTableName: 'control_plane_kysely_migration_lock',\n provider: new FileMigrationProvider({\n fs,\n path,\n migrationFolder: path.join(root, 'control-plane-migrations'),\n }),\n });\n const { error: controlPlaneMigrationError } =\n await controlPlaneMigrator.migrateToLatest();\n if (controlPlaneMigrationError) {\n throw controlPlaneMigrationError;\n }\n\n await sql`alter table core.flow set schema public`.execute(\n controlPlaneBootstrapKysely\n );\n await sql`alter table core.issue_message_overwrite set schema public`.execute(\n controlPlaneBootstrapKysely\n );\n await sql`drop schema core`.execute(controlPlaneBootstrapKysely);\n await sql`alter schema public rename to control_plane`.execute(\n controlPlaneBootstrapKysely\n );\n await sql`alter schema regional_public rename to public`.execute(\n controlPlaneBootstrapKysely\n );\n await sql`alter schema regional_core rename to core`.execute(\n controlPlaneBootstrapKysely\n );\n await sql`\n do $$\n declare\n definition text;\n begin\n select pg_get_functiondef(\n 'control_plane.normalize_tenant_slug(text)'::regprocedure\n ) into definition;\n execute replace(definition, 'public.', 'control_plane.');\n\n select pg_get_functiondef(\n 'control_plane.build_unique_tenant_slug(text,uuid)'::regprocedure\n ) into definition;\n execute replace(definition, 'public.', 'control_plane.');\n\n select pg_get_functiondef(\n 'control_plane.refresh_operation_state(uuid)'::regprocedure\n ) into definition;\n execute replace(definition, 'public.', 'control_plane.');\n\n select pg_get_functiondef(\n 'control_plane.refresh_destructive_job_operation()'::regprocedure\n ) into definition;\n execute replace(definition, 'public.', 'control_plane.');\n end;\n $$;\n `.execute(controlPlaneBootstrapKysely);\n // The canonical VRPlatform tenant. Production code falls back to this exact id\n // in getCalculatedBillingPartnerId, so specs need it to exist without each of\n // them creating - and mutating - their own copy of a shared singleton.\n await kysely\n .insertInto('public.tenant')\n .values({\n id: '7bfec41f-aa3f-4602-95d2-f7996e4f0e59',\n name: 'VRPlatform',\n type: 'partner',\n status: 'active',\n isActive: true,\n isGeneralLedger: false,\n isOnboarding: false,\n partnerId: null,\n billingPartnerId: null,\n defaultCurrency: 'usd',\n statementStartAt: new Date('2020-01-01T00:00:00Z'),\n })\n .onConflict((oc) => oc.column('id').doNothing())\n .execute();\n\n await sql`\n insert into control_plane.app (\n authentication,\n category,\n color,\n created_at,\n icon,\n icon_round,\n id,\n info,\n name,\n type,\n version\n )\n select\n authentication,\n category,\n color,\n created_at,\n icon,\n icon_round,\n id,\n info,\n name,\n type,\n version\n from public.app\n on conflict (id) do nothing;\n `.execute(controlPlaneBootstrapKysely);\n await sql`\n insert into control_plane.currency (name)\n select name\n from public.currency\n on conflict (name) do nothing;\n `.execute(controlPlaneBootstrapKysely);\n await sql`\n insert into control_plane.booking_channel (\n channel_ref,\n color,\n created_at,\n icon,\n icon_provider,\n id,\n last_generate_run,\n logo,\n logo_provider,\n selected_booking_channel_icon_candidate_id,\n selected_booking_channel_logo_candidate_id,\n unique_ref,\n updated_at\n )\n select\n channel_ref,\n color,\n created_at,\n icon,\n icon_provider,\n id,\n last_generate_run,\n logo,\n logo_provider,\n selected_booking_channel_icon_candidate_id,\n selected_booking_channel_logo_candidate_id,\n unique_ref,\n updated_at\n from public.booking_channel\n on conflict (id) do nothing;\n `.execute(controlPlaneBootstrapKysely);\n await sql`\n insert into control_plane.booking_channel_icon_candidate (\n booking_channel_id,\n cloudflare_image_id,\n color,\n comment,\n created_at,\n external_icon,\n height,\n id,\n provider,\n source,\n updated_at,\n width\n )\n select\n booking_channel_id,\n cloudflare_image_id,\n color,\n comment,\n created_at,\n external_icon,\n height,\n id,\n provider,\n source,\n updated_at,\n width\n from public.booking_channel_icon_candidate\n on conflict (id) do nothing;\n `.execute(controlPlaneBootstrapKysely);\n await sql`\n insert into control_plane.tenant (\n billing_partner_id,\n billing_plan,\n created_at,\n data_region,\n id,\n name,\n partner_id,\n slug,\n status,\n storage_realm,\n type,\n unique_ref,\n updated_at\n )\n select\n billing_partner_id,\n billing_plan,\n created_at,\n data_region,\n id,\n name,\n partner_id,\n slug,\n status,\n storage_realm,\n type,\n unique_ref,\n updated_at\n from public.tenant\n on conflict (id) do nothing;\n `.execute(controlPlaneBootstrapKysely);\n await sql`\n insert into control_plane.token (\n created_at,\n expires_at,\n id,\n nano_id,\n payload,\n tenant_id,\n type,\n user_id\n )\n select\n created_at,\n expires_at,\n id,\n nano_id,\n payload,\n tenant_id,\n type,\n user_id\n from public.token\n on conflict (id) do nothing;\n `.execute(controlPlaneBootstrapKysely);\n\n const content = await pglite.dumpDataDir('none');\n await kysely.destroy();\n return content;\n}\n\nexport async function useLocalKysely(\n args: UseLocalKyselyOptions = {}\n): Promise<LocalKysely> {\n let isDestroyed = false;\n\n preparedDumpPromise ??= resolvePreparedDump();\n const pglite = new PGlite({\n loadDataDir: await preparedDumpPromise,\n });\n // The constructor is lazy. The bootstrap this replaced forced the snapshot to\n // load before returning, so keep that contract: a returned handle is usable,\n // and a bad snapshot fails here instead of inside an unrelated test.\n await pglite.waitReady;\n const dialect = new PGliteDialect(pglite);\n const kysely = getKysely<DB>(dialect, {\n repositoryName: args?.repositoryName ?? 'localTesting',\n log: args?.log,\n });\n\n const controlPlaneKysely = withControlPlaneSchema(\n getKysely<ControlPlaneDB>(dialect, {\n repositoryName: `${args.repositoryName ?? 'localTesting'}/control-plane`,\n log: args.log,\n }),\n 'control_plane',\n 'control_plane'\n );\n controlPlaneKysely.destroy = async () => {};\n Object.defineProperty(kysely, 'controlPlaneKysely', {\n value: controlPlaneKysely,\n });\n\n const originalDestroy = kysely.destroy.bind(kysely);\n kysely.destroy = async () => {\n if (isDestroyed) return;\n isDestroyed = true;\n //const destroyTime = performance.now();\n await originalDestroy();\n //console.log(\n // `Database destroyed: ${Math.round(performance.now() - destroyTime)}ms`\n //);\n };\n\n // console.log(`Database initialized: ${Math.round(performance.now() - now)}ms`);\n\n return kysely as LocalKysely;\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  import { readFile, writeFile } from 'node:fs/promises';
2
2
  import { join } from 'node:path';
3
+ import { KyselyError } from '../error';
3
4
  const START_MARKER = '-- VRP legacy-column-prune:start';
4
5
  const END_MARKER = '-- VRP legacy-column-prune:end';
5
6
  const hasuraAuditTriggerPattern = /^CREATE TRIGGER "(notify_hasura_audit_[^"]+)" [\s\S]*? ON ([^\s;]+) FOR EACH ROW EXECUTE FUNCTION hdb_catalog\."notify_hasura_audit_[^"]+"\(\);$/gm;
@@ -109,7 +110,9 @@ export function applyPruneBlock(sql, columns) {
109
110
  if (startAt !== -1) {
110
111
  const endAt = sql.indexOf(END_MARKER, startAt);
111
112
  if (endAt === -1) {
112
- throw new Error(`Malformed legacy prune block in initial SQL: missing "${END_MARKER}".`);
113
+ throw new KyselyError('Malformed legacy prune block in initial SQL', {
114
+ missingMarker: END_MARKER,
115
+ });
113
116
  }
114
117
  const tailStart = endAt + END_MARKER.length;
115
118
  const afterTail = sql.slice(tailStart).replace(/^\s*\n/, '');
@@ -1 +1 @@
1
- {"version":3,"file":"prune-pulled-schema.js","sourceRoot":"src/","sources":["local/prune-pulled-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,YAAY,GAAG,kCAAkC,CAAC;AACxD,MAAM,UAAU,GAAG,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CAAC;IACd,CAAC;AACH,CAAC,CAAC,EAAE,CAAC","sourcesContent":["import { readFile, writeFile } from 'node:fs/promises';\nimport { join } from 'node:path';\n\nconst START_MARKER = '-- VRP legacy-column-prune:start';\nconst END_MARKER = '-- VRP legacy-column-prune:end';\n\nexport type LegacyColumnPrune = {\n table: `${string}.${string}`;\n column: string;\n issue: string;\n};\n\nconst hasuraAuditTriggerPattern =\n /^CREATE TRIGGER \"(notify_hasura_audit_[^\"]+)\" [\\s\\S]*? ON ([^\\s;]+) FOR EACH ROW EXECUTE FUNCTION hdb_catalog\\.\"notify_hasura_audit_[^\"]+\"\\(\\);$/gm;\n\nexport type HasuraAuditTrigger = {\n name: string;\n table: `${string}.${string}`;\n};\n\n/**\n * Active removals currently validated by runtime + type usage.\n * Add new entries here incrementally to surface compile/runtime callers.\n */\nexport const activeLegacyColumnPrunes: LegacyColumnPrune[] = [\n {\n issue: 'VRI-45',\n table: 'public.app',\n column: 'fly_app',\n },\n {\n issue: 'VRI-45',\n table: 'public.app',\n column: 'default_machine_size',\n },\n {\n issue: 'VRI-45',\n table: 'public.app',\n column: 'endpoint',\n },\n {\n issue: 'VRI-45',\n table: 'public.app',\n column: 'uid',\n },\n {\n issue: 'VRI-45',\n table: 'public.app',\n column: 'plugin_data',\n },\n {\n issue: 'VRI-45',\n table: 'public.app',\n column: 'config',\n },\n {\n issue: 'VRI-45',\n table: 'public.app',\n column: 'flows',\n },\n {\n issue: 'PRO-12855',\n table: 'public.owner_statement',\n column: 'cent_accounting_balance_start',\n },\n {\n issue: 'PRO-12855',\n table: 'public.owner_statement',\n column: 'cent_accounting_balance_end',\n },\n {\n issue: 'PRO-12855',\n table: 'accounting.contact',\n column: 'pms_status',\n },\n {\n issue: 'PRO-12855',\n table: 'public.owner',\n column: 'pms_status',\n },\n];\n\nexport function extractHasuraAuditTriggers(sql: string): HasuraAuditTrigger[] {\n const unique = new Map<string, HasuraAuditTrigger>();\n\n for (const match of sql.matchAll(hasuraAuditTriggerPattern)) {\n const name = match[1];\n const table = match[2] as `${string}.${string}`;\n const key = `${name}::${table}`;\n\n if (!unique.has(key)) {\n unique.set(key, { name, table });\n }\n }\n\n return [...unique.values()];\n}\n\nexport function buildPruneBlock(\n columns: readonly LegacyColumnPrune[],\n hasuraAuditTriggers: readonly HasuraAuditTrigger[] = []\n): string {\n const columnStatements = columns.map(\n (item) =>\n `ALTER TABLE ${item.table} DROP COLUMN IF EXISTS ${item.column}; -- ${item.issue}`\n );\n const triggerStatements = hasuraAuditTriggers.map(\n (trigger) =>\n `DROP TRIGGER IF EXISTS \"${trigger.name}\" ON ${trigger.table}; -- hasura-audit`\n );\n\n return [\n START_MARKER,\n '-- Managed by src/local/prune-pulled-schema.ts',\n ...columnStatements,\n ...(triggerStatements.length > 0\n ? [\n '',\n '-- Disable Hasura audit triggers in local bootstrap',\n ...triggerStatements,\n ]\n : []),\n END_MARKER,\n ].join('\\n');\n}\n\nexport function buildPruneReminderLog(columns: readonly LegacyColumnPrune[]) {\n const lines = [\n `[kysely] Legacy column prune reminder (${columns.length} columns). Remove these from production schema when ready:`,\n ];\n\n for (const item of columns) {\n lines.push(` - ${item.table}.${item.column} [${item.issue}]`);\n }\n\n return lines;\n}\n\nexport function applyPruneBlock(\n sql: string,\n columns: readonly LegacyColumnPrune[]\n): string {\n const hasuraAuditTriggers = extractHasuraAuditTriggers(sql);\n const startAt = sql.indexOf(START_MARKER);\n\n let base = sql;\n if (startAt !== -1) {\n const endAt = sql.indexOf(END_MARKER, startAt);\n if (endAt === -1) {\n throw new Error(\n `Malformed legacy prune block in initial SQL: missing \"${END_MARKER}\".`\n );\n }\n const tailStart = endAt + END_MARKER.length;\n const afterTail = sql.slice(tailStart).replace(/^\\s*\\n/, '');\n base = `${sql.slice(0, startAt).trimEnd()}\\n${afterTail}`;\n }\n\n const next = base.trimEnd();\n if (columns.length === 0) {\n return `${next}\\n`;\n }\n\n return `${next}\\n\\n${buildPruneBlock(columns, hasuraAuditTriggers)}\\n`;\n}\n\nexport async function prunePulledSchemaFile(filePath: string) {\n const original = await readFile(filePath, 'utf8');\n const updated = applyPruneBlock(original, activeLegacyColumnPrunes);\n const changed = updated !== original;\n if (changed) {\n await writeFile(filePath, updated, 'utf8');\n }\n\n const status = changed ? 'applied' : 'already up to date';\n console.log(`[kysely] Legacy column prune block ${status}.`);\n for (const line of buildPruneReminderLog(activeLegacyColumnPrunes)) {\n console.log(line);\n }\n}\n\nexport async function prunePulledSchema(root: string) {\n const filePath = join(root, 'initial/0000000000000-init.sql');\n await prunePulledSchemaFile(filePath);\n}\n\nasync function run() {\n await prunePulledSchema(process.cwd());\n}\n\nfunction isDirectExecution() {\n const entryPath = process.argv[1];\n if (!entryPath) {\n return false;\n }\n\n return (\n entryPath.endsWith('prune-pulled-schema.ts') ||\n entryPath.endsWith('prune-pulled-schema.js')\n );\n}\n\n(async () => {\n if (isDirectExecution()) {\n await run();\n }\n})();\n"]}
1
+ {"version":3,"file":"prune-pulled-schema.js","sourceRoot":"src/","sources":["local/prune-pulled-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,MAAM,YAAY,GAAG,kCAAkC,CAAC;AACxD,MAAM,UAAU,GAAG,gCAAgC,CAAC;AAQpD,MAAM,yBAAyB,GAC7B,oJAAoJ,CAAC;AAOvJ;;;GAGG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAwB;IAC3D;QACE,KAAK,EAAE,QAAQ;QACf,KAAK,EAAE,YAAY;QACnB,MAAM,EAAE,SAAS;KAClB;IACD;QACE,KAAK,EAAE,QAAQ;QACf,KAAK,EAAE,YAAY;QACnB,MAAM,EAAE,sBAAsB;KAC/B;IACD;QACE,KAAK,EAAE,QAAQ;QACf,KAAK,EAAE,YAAY;QACnB,MAAM,EAAE,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AAC,CAAC,SAAS,CAAC,CAAC,CAAC,oBAAoB,CAAC;IAC1D,OAAO,CAAC,GAAG,CAAC,sCAAsC,MAAM,GAAG,CAAC,CAAC;IAC7D,KAAK,MAAM,IAAI,IAAI,qBAAqB,CAAC,wBAAwB,CAAC,EAAE,CAAC;QACnE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,IAAY;IAClD,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,EAAE,gCAAgC,CAAC,CAAC;IAC9D,MAAM,qBAAqB,CAAC,QAAQ,CAAC,CAAC;AACxC,CAAC;AAED,KAAK,UAAU,GAAG;IAChB,MAAM,iBAAiB,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;AACzC,CAAC;AAED,SAAS,iBAAiB;IACxB,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClC,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,CACL,SAAS,CAAC,QAAQ,CAAC,wBAAwB,CAAC;QAC5C,SAAS,CAAC,QAAQ,CAAC,wBAAwB,CAAC,CAC7C,CAAC;AACJ,CAAC;AAED,CAAC,KAAK,IAAI,EAAE;IACV,IAAI,iBAAiB,EAAE,EAAE,CAAC;QACxB,MAAM,GAAG,EAAE,CAAC;IACd,CAAC;AACH,CAAC,CAAC,EAAE,CAAC","sourcesContent":["import { readFile, writeFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { KyselyError } from '../error';\n\nconst START_MARKER = '-- VRP legacy-column-prune:start';\nconst END_MARKER = '-- VRP legacy-column-prune:end';\n\nexport type LegacyColumnPrune = {\n table: `${string}.${string}`;\n column: string;\n issue: string;\n};\n\nconst hasuraAuditTriggerPattern =\n /^CREATE TRIGGER \"(notify_hasura_audit_[^\"]+)\" [\\s\\S]*? ON ([^\\s;]+) FOR EACH ROW EXECUTE FUNCTION hdb_catalog\\.\"notify_hasura_audit_[^\"]+\"\\(\\);$/gm;\n\nexport type HasuraAuditTrigger = {\n name: string;\n table: `${string}.${string}`;\n};\n\n/**\n * Active removals currently validated by runtime + type usage.\n * Add new entries here incrementally to surface compile/runtime callers.\n */\nexport const activeLegacyColumnPrunes: LegacyColumnPrune[] = [\n {\n issue: 'VRI-45',\n table: 'public.app',\n column: 'fly_app',\n },\n {\n issue: 'VRI-45',\n table: 'public.app',\n column: 'default_machine_size',\n },\n {\n issue: 'VRI-45',\n table: 'public.app',\n column: 'endpoint',\n },\n {\n issue: 'VRI-45',\n table: 'public.app',\n column: 'uid',\n },\n {\n issue: 'VRI-45',\n table: 'public.app',\n column: 'plugin_data',\n },\n {\n issue: 'VRI-45',\n table: 'public.app',\n column: 'config',\n },\n {\n issue: 'VRI-45',\n table: 'public.app',\n column: 'flows',\n },\n {\n issue: 'PRO-12855',\n table: 'public.owner_statement',\n column: 'cent_accounting_balance_start',\n },\n {\n issue: 'PRO-12855',\n table: 'public.owner_statement',\n column: 'cent_accounting_balance_end',\n },\n {\n issue: 'PRO-12855',\n table: 'accounting.contact',\n column: 'pms_status',\n },\n {\n issue: 'PRO-12855',\n table: 'public.owner',\n column: 'pms_status',\n },\n];\n\nexport function extractHasuraAuditTriggers(sql: string): HasuraAuditTrigger[] {\n const unique = new Map<string, HasuraAuditTrigger>();\n\n for (const match of sql.matchAll(hasuraAuditTriggerPattern)) {\n const name = match[1];\n const table = match[2] as `${string}.${string}`;\n const key = `${name}::${table}`;\n\n if (!unique.has(key)) {\n unique.set(key, { name, table });\n }\n }\n\n return [...unique.values()];\n}\n\nexport function buildPruneBlock(\n columns: readonly LegacyColumnPrune[],\n hasuraAuditTriggers: readonly HasuraAuditTrigger[] = []\n): string {\n const columnStatements = columns.map(\n (item) =>\n `ALTER TABLE ${item.table} DROP COLUMN IF EXISTS ${item.column}; -- ${item.issue}`\n );\n const triggerStatements = hasuraAuditTriggers.map(\n (trigger) =>\n `DROP TRIGGER IF EXISTS \"${trigger.name}\" ON ${trigger.table}; -- hasura-audit`\n );\n\n return [\n START_MARKER,\n '-- Managed by src/local/prune-pulled-schema.ts',\n ...columnStatements,\n ...(triggerStatements.length > 0\n ? [\n '',\n '-- Disable Hasura audit triggers in local bootstrap',\n ...triggerStatements,\n ]\n : []),\n END_MARKER,\n ].join('\\n');\n}\n\nexport function buildPruneReminderLog(columns: readonly LegacyColumnPrune[]) {\n const lines = [\n `[kysely] Legacy column prune reminder (${columns.length} columns). Remove these from production schema when ready:`,\n ];\n\n for (const item of columns) {\n lines.push(` - ${item.table}.${item.column} [${item.issue}]`);\n }\n\n return lines;\n}\n\nexport function applyPruneBlock(\n sql: string,\n columns: readonly LegacyColumnPrune[]\n): string {\n const hasuraAuditTriggers = extractHasuraAuditTriggers(sql);\n const startAt = sql.indexOf(START_MARKER);\n\n let base = sql;\n if (startAt !== -1) {\n const endAt = sql.indexOf(END_MARKER, startAt);\n if (endAt === -1) {\n throw new KyselyError('Malformed legacy prune block in initial SQL', {\n missingMarker: END_MARKER,\n });\n }\n const tailStart = endAt + END_MARKER.length;\n const afterTail = sql.slice(tailStart).replace(/^\\s*\\n/, '');\n base = `${sql.slice(0, startAt).trimEnd()}\\n${afterTail}`;\n }\n\n const next = base.trimEnd();\n if (columns.length === 0) {\n return `${next}\\n`;\n }\n\n return `${next}\\n\\n${buildPruneBlock(columns, hasuraAuditTriggers)}\\n`;\n}\n\nexport async function prunePulledSchemaFile(filePath: string) {\n const original = await readFile(filePath, 'utf8');\n const updated = applyPruneBlock(original, activeLegacyColumnPrunes);\n const changed = updated !== original;\n if (changed) {\n await writeFile(filePath, updated, 'utf8');\n }\n\n const status = changed ? 'applied' : 'already up to date';\n console.log(`[kysely] Legacy column prune block ${status}.`);\n for (const line of buildPruneReminderLog(activeLegacyColumnPrunes)) {\n console.log(line);\n }\n}\n\nexport async function prunePulledSchema(root: string) {\n const filePath = join(root, 'initial/0000000000000-init.sql');\n await prunePulledSchemaFile(filePath);\n}\n\nasync function run() {\n await prunePulledSchema(process.cwd());\n}\n\nfunction isDirectExecution() {\n const entryPath = process.argv[1];\n if (!entryPath) {\n return false;\n }\n\n return (\n entryPath.endsWith('prune-pulled-schema.ts') ||\n entryPath.endsWith('prune-pulled-schema.js')\n );\n}\n\n(async () => {\n if (isDirectExecution()) {\n await run();\n }\n})();\n"]}
@@ -0,0 +1,7 @@
1
+ export declare const appMigrationEpoch: {
2
+ readonly baseline: "0000000000000-baseline";
3
+ readonly folder: "migrations-v2";
4
+ readonly lockTableName: "kysely_migration_lock";
5
+ readonly tableName: "kysely_migration";
6
+ readonly tableSchema: "kysely_v2";
7
+ };
@@ -0,0 +1,8 @@
1
+ export const appMigrationEpoch = {
2
+ baseline: '0000000000000-baseline',
3
+ folder: 'migrations-v2',
4
+ lockTableName: 'kysely_migration_lock',
5
+ tableName: 'kysely_migration',
6
+ tableSchema: 'kysely_v2',
7
+ };
8
+ //# sourceMappingURL=migration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration.js","sourceRoot":"src/","sources":["migration.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,QAAQ,EAAE,wBAAwB;IAClC,MAAM,EAAE,eAAe;IACvB,aAAa,EAAE,uBAAuB;IACtC,SAAS,EAAE,kBAAkB;IAC7B,WAAW,EAAE,WAAW;CAChB,CAAC","sourcesContent":["export const appMigrationEpoch = {\n baseline: '0000000000000-baseline',\n folder: 'migrations-v2',\n lockTableName: 'kysely_migration_lock',\n tableName: 'kysely_migration',\n tableSchema: 'kysely_v2',\n} as const;\n"]}
@@ -1,6 +1,6 @@
1
1
  import { type Dialect, Kysely as K, type LogConfig } from 'kysely';
2
2
  import type { DB } from './v1.generated';
3
- export declare function getKysely(dialect: Dialect, options: {
3
+ export declare function getKysely<Database = DB>(dialect: Dialect, options: {
4
4
  repositoryName?: string;
5
5
  log?: true | LogConfig;
6
- }): K<DB>;
6
+ }): K<Database>;
@@ -1 +1 @@
1
- {"version":3,"file":"plugins.js","sourceRoot":"src/","sources":["plugins.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,MAAM,IAAI,CAAC,GAGZ,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,4BAA4B,EAAE,MAAM,4BAA4B,CAAC;AAG1E,MAAM,UAAU,SAAS,CACvB,OAAgB,EAChB,OAA4D;IAE5D,MAAM,OAAO,GAAmB,CAAC,IAAI,gBAAgB,EAAE,CAAC,CAAC;IAEzD,IAAI,OAAO,EAAE,cAAc,EAAE,CAAC;QAC5B,OAAO,CAAC,IAAI,CACV,IAAI,4BAA4B,CAAC;YAC/B,UAAU,EAAE,OAAO,CAAC,cAAc;SACnC,CAAC,CACH,CAAC;IACJ,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,CAAC,CAAK;QACvB,OAAO;QACP,OAAO;QACP,GAAG,EAAE,OAAO,EAAE,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,GAAG;KAC/D,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import {\n type Dialect,\n Kysely as K,\n type KyselyPlugin,\n type LogConfig,\n} from 'kysely';\nimport { CustomCasePlugin } from './camel-case';\nimport { KyselyPganalyzeCommentPlugin } from './pganalyze-comment-plugin';\nimport type { DB } from './v1.generated';\n\nexport function getKysely(\n dialect: Dialect,\n options: { repositoryName?: string; log?: true | LogConfig }\n) {\n const plugins: KyselyPlugin[] = [new CustomCasePlugin()];\n\n if (options?.repositoryName) {\n plugins.push(\n new KyselyPganalyzeCommentPlugin({\n repository: options.repositoryName,\n })\n );\n }\n const kysely = new K<DB>({\n dialect,\n plugins,\n log: options?.log === true ? ['query', 'error'] : options?.log,\n });\n return kysely;\n}\n"]}
1
+ {"version":3,"file":"plugins.js","sourceRoot":"src/","sources":["plugins.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,MAAM,IAAI,CAAC,GAGZ,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,4BAA4B,EAAE,MAAM,4BAA4B,CAAC;AAG1E,MAAM,UAAU,SAAS,CACvB,OAAgB,EAChB,OAA4D;IAE5D,MAAM,OAAO,GAAmB,CAAC,IAAI,gBAAgB,EAAE,CAAC,CAAC;IAEzD,IAAI,OAAO,EAAE,cAAc,EAAE,CAAC;QAC5B,OAAO,CAAC,IAAI,CACV,IAAI,4BAA4B,CAAC;YAC/B,UAAU,EAAE,OAAO,CAAC,cAAc;SACnC,CAAC,CACH,CAAC;IACJ,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,CAAC,CAAW;QAC7B,OAAO;QACP,OAAO;QACP,GAAG,EAAE,OAAO,EAAE,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,GAAG;KAC/D,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import {\n type Dialect,\n Kysely as K,\n type KyselyPlugin,\n type LogConfig,\n} from 'kysely';\nimport { CustomCasePlugin } from './camel-case';\nimport { KyselyPganalyzeCommentPlugin } from './pganalyze-comment-plugin';\nimport type { DB } from './v1.generated';\n\nexport function getKysely<Database = DB>(\n dialect: Dialect,\n options: { repositoryName?: string; log?: true | LogConfig }\n) {\n const plugins: KyselyPlugin[] = [new CustomCasePlugin()];\n\n if (options?.repositoryName) {\n plugins.push(\n new KyselyPganalyzeCommentPlugin({\n repository: options.repositoryName,\n })\n );\n }\n const kysely = new K<Database>({\n dialect,\n plugins,\n log: options?.log === true ? ['query', 'error'] : options?.log,\n });\n return kysely;\n}\n"]}
@@ -1,8 +1,8 @@
1
1
  /**
2
- * Matches PostgreSQL errors from both production's postgres.js driver and
3
- * PGlite, which expose constraint names under different property names.
2
+ * Matches PostgreSQL errors by code and, when requested, constraint. Production
3
+ * postgres.js and PGlite expose constraint names under different properties.
4
4
  */
5
5
  export declare function isPostgresError(error: unknown, expected: {
6
6
  code: string;
7
- constraint: string;
7
+ constraint?: string;
8
8
  }): boolean;
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Matches PostgreSQL errors from both production's postgres.js driver and
3
- * PGlite, which expose constraint names under different property names.
2
+ * Matches PostgreSQL errors by code and, when requested, constraint. Production
3
+ * postgres.js and PGlite expose constraint names under different properties.
4
4
  */
5
5
  export function isPostgresError(error, expected) {
6
6
  if (!(error instanceof Error) ||
@@ -13,6 +13,7 @@ export function isPostgresError(error, expected) {
13
13
  : 'constraint_name' in error && typeof error.constraint_name === 'string'
14
14
  ? error.constraint_name
15
15
  : undefined;
16
- return error.code === expected.code && constraint === expected.constraint;
16
+ return (error.code === expected.code &&
17
+ (expected.constraint === undefined || constraint === expected.constraint));
17
18
  }
18
19
  //# sourceMappingURL=postgres-error.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"postgres-error.js","sourceRoot":"src/","sources":["postgres-error.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC7B,KAAc,EACd,QAA8C;IAE9C,IACE,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC;QACzB,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC;QAClB,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,EAC9B,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,UAAU,GACd,YAAY,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,UAAU,KAAK,QAAQ;QAC3D,CAAC,CAAC,KAAK,CAAC,UAAU;QAClB,CAAC,CAAC,iBAAiB,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,eAAe,KAAK,QAAQ;YACvE,CAAC,CAAC,KAAK,CAAC,eAAe;YACvB,CAAC,CAAC,SAAS,CAAC;IAElB,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC,IAAI,IAAI,UAAU,KAAK,QAAQ,CAAC,UAAU,CAAC;AAC5E,CAAC","sourcesContent":["/**\n * Matches PostgreSQL errors from both production's postgres.js driver and\n * PGlite, which expose constraint names under different property names.\n */\nexport function isPostgresError(\n error: unknown,\n expected: { code: string; constraint: string }\n): boolean {\n if (\n !(error instanceof Error) ||\n !('code' in error) ||\n typeof error.code !== 'string'\n ) {\n return false;\n }\n\n const constraint =\n 'constraint' in error && typeof error.constraint === 'string'\n ? error.constraint\n : 'constraint_name' in error && typeof error.constraint_name === 'string'\n ? error.constraint_name\n : undefined;\n\n return error.code === expected.code && constraint === expected.constraint;\n}\n"]}
1
+ {"version":3,"file":"postgres-error.js","sourceRoot":"src/","sources":["postgres-error.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC7B,KAAc,EACd,QAA+C;IAE/C,IACE,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC;QACzB,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC;QAClB,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,EAC9B,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,UAAU,GACd,YAAY,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,UAAU,KAAK,QAAQ;QAC3D,CAAC,CAAC,KAAK,CAAC,UAAU;QAClB,CAAC,CAAC,iBAAiB,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,eAAe,KAAK,QAAQ;YACvE,CAAC,CAAC,KAAK,CAAC,eAAe;YACvB,CAAC,CAAC,SAAS,CAAC;IAElB,OAAO,CACL,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC,IAAI;QAC5B,CAAC,QAAQ,CAAC,UAAU,KAAK,SAAS,IAAI,UAAU,KAAK,QAAQ,CAAC,UAAU,CAAC,CAC1E,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Matches PostgreSQL errors by code and, when requested, constraint. Production\n * postgres.js and PGlite expose constraint names under different properties.\n */\nexport function isPostgresError(\n error: unknown,\n expected: { code: string; constraint?: string }\n): boolean {\n if (\n !(error instanceof Error) ||\n !('code' in error) ||\n typeof error.code !== 'string'\n ) {\n return false;\n }\n\n const constraint =\n 'constraint' in error && typeof error.constraint === 'string'\n ? error.constraint\n : 'constraint_name' in error && typeof error.constraint_name === 'string'\n ? error.constraint_name\n : undefined;\n\n return (\n error.code === expected.code &&\n (expected.constraint === undefined || constraint === expected.constraint)\n );\n}\n"]}