@rebasepro/server 0.26.0 → 0.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/dist/{GCSStorageController-40FyFeSx.js → GCSStorageController-LXeAF6Ks.js} +37 -4
  2. package/dist/GCSStorageController-LXeAF6Ks.js.map +1 -0
  3. package/dist/{S3StorageController-Bl5shp94.js → S3StorageController-CVKMUXo_.js} +59 -11
  4. package/dist/S3StorageController-CVKMUXo_.js.map +1 -0
  5. package/dist/{access-BFAUvsSs.js → access-BDz4FO9D.js} +7 -7
  6. package/dist/access-BDz4FO9D.js.map +1 -0
  7. package/dist/api/openapi-generator.d.ts +13 -1
  8. package/dist/api/rest/api-generator.d.ts +16 -0
  9. package/dist/api/rest/batch.d.ts +9 -0
  10. package/dist/{ast-schema-editor-madTa9Hh.js → ast-schema-editor-C4bDSb61.js} +2 -2
  11. package/dist/{ast-schema-editor-madTa9Hh.js.map → ast-schema-editor-C4bDSb61.js.map} +1 -1
  12. package/dist/auth/admin-users-route.d.ts +3 -0
  13. package/dist/auth/apple-oauth.d.ts +39 -10
  14. package/dist/auth/capabilities.d.ts +2 -0
  15. package/dist/auth/interfaces.d.ts +78 -4
  16. package/dist/auth/otp-routes.d.ts +10 -0
  17. package/dist/{auth-izI7AEzC.js → auth-CZGfVKcL.js} +350 -137
  18. package/dist/auth-CZGfVKcL.js.map +1 -0
  19. package/dist/auth_adapter-B7RUMk6e.js.map +1 -1
  20. package/dist/backend/options.d.ts +29 -1
  21. package/dist/backend-CaG_Jyso.js.map +1 -1
  22. package/dist/{backup-BVbHoKo8.js → backup-BmzY9xdN.js} +8 -8
  23. package/dist/{backup-BVbHoKo8.js.map → backup-BmzY9xdN.js.map} +1 -1
  24. package/dist/boot/env.d.ts +6 -0
  25. package/dist/{branch-routes-B2vvEx53.js → branch-routes-DpgaeTJl.js} +4 -4
  26. package/dist/{branch-routes-B2vvEx53.js.map → branch-routes-DpgaeTJl.js.map} +1 -1
  27. package/dist/{contract-routes-CU2A3JnF.js → contract-routes-vYiBHbjI.js} +3 -3
  28. package/dist/{contract-routes-CU2A3JnF.js.map → contract-routes-vYiBHbjI.js.map} +1 -1
  29. package/dist/cron/cron-loader.d.ts +16 -0
  30. package/dist/{cron-loader-mMhqbVsl.js → cron-loader-C_C-lNgG.js} +39 -10
  31. package/dist/cron-loader-C_C-lNgG.js.map +1 -0
  32. package/dist/{cron-routes-Cs33j_Kr.js → cron-routes-DlwOV6zl.js} +5 -5
  33. package/dist/{cron-routes-Cs33j_Kr.js.map → cron-routes-DlwOV6zl.js.map} +1 -1
  34. package/dist/{cron-scheduler-Be7CNghL.js → cron-scheduler-6ipIm5mm.js} +41 -28
  35. package/dist/cron-scheduler-6ipIm5mm.js.map +1 -0
  36. package/dist/{cron-store-DLn11M8H.js → cron-store-KIOM8LCC.js} +5 -5
  37. package/dist/{cron-store-DLn11M8H.js.map → cron-store-KIOM8LCC.js.map} +1 -1
  38. package/dist/{ddl-bootstrap-CjRrn12l.js → ddl-bootstrap-DhCuwhHM.js} +2 -2
  39. package/dist/{ddl-bootstrap-CjRrn12l.js.map → ddl-bootstrap-DhCuwhHM.js.map} +1 -1
  40. package/dist/dist-DVqwVrBQ.js +22 -0
  41. package/dist/dist-DVqwVrBQ.js.map +1 -0
  42. package/dist/{load-failure-L5hvfDoG.js → dynamic-import-Bi3XK5y-.js} +30 -18
  43. package/dist/dynamic-import-Bi3XK5y-.js.map +1 -0
  44. package/dist/{errors-OMWkKSH-.js → errors-DIWnZIDY.js} +2 -2
  45. package/dist/{errors-OMWkKSH-.js.map → errors-DIWnZIDY.js.map} +1 -1
  46. package/dist/{field-access-DYsvjI_P.js → field-access-KYk8RGOx.js} +3 -2
  47. package/dist/field-access-KYk8RGOx.js.map +1 -0
  48. package/dist/{filter-dialect-TrKFWLqT.js → filter-dialect-CE4bloug.js} +2 -2
  49. package/dist/{filter-dialect-TrKFWLqT.js.map → filter-dialect-CE4bloug.js.map} +1 -1
  50. package/dist/{function-loader-B8YzXEsQ.js → function-loader-CKB9b4uP.js} +15 -6
  51. package/dist/function-loader-CKB9b4uP.js.map +1 -0
  52. package/dist/{function-routes-RxrCHNuM.js → function-routes-DLaXaiQA.js} +2 -2
  53. package/dist/{function-routes-RxrCHNuM.js.map → function-routes-DLaXaiQA.js.map} +1 -1
  54. package/dist/functions/function-loader.d.ts +5 -0
  55. package/dist/functions/index.js +16 -9
  56. package/dist/functions/index.js.map +1 -1
  57. package/dist/{history-recorder-Bsau7h4X.js → history-recorder-BE4HWR-M.js} +4 -4
  58. package/dist/{history-recorder-Bsau7h4X.js.map → history-recorder-BE4HWR-M.js.map} +1 -1
  59. package/dist/{history-store-BQz5YCkW.js → history-store-D-jDz4Nv.js} +2 -2
  60. package/dist/{history-store-BQz5YCkW.js.map → history-store-D-jDz4Nv.js.map} +1 -1
  61. package/dist/index.d.ts +1 -1
  62. package/dist/index.es.js +1361 -232
  63. package/dist/index.es.js.map +1 -1
  64. package/dist/init/docs.d.ts +1 -1
  65. package/dist/init/health.d.ts +13 -0
  66. package/dist/{internal-tables-L2t39RdT.js → internal-tables-CRaBxJeE.js} +57 -2
  67. package/dist/{internal-tables-L2t39RdT.js.map → internal-tables-CRaBxJeE.js.map} +1 -1
  68. package/dist/{jobs-Co6Ni5HP.js → jobs-CXTs9qXH.js} +5 -5
  69. package/dist/{jobs-Co6Ni5HP.js.map → jobs-CXTs9qXH.js.map} +1 -1
  70. package/dist/{jwt-rDS0884_.js → jwt-5EvX3lQa.js} +3 -3
  71. package/dist/{jwt-rDS0884_.js.map → jwt-5EvX3lQa.js.map} +1 -1
  72. package/dist/{keys-BXcdRNhJ.js → keys-DJ1ZNcZi.js} +2 -2
  73. package/dist/{keys-BXcdRNhJ.js.map → keys-DJ1ZNcZi.js.map} +1 -1
  74. package/dist/{logger-CW8pmTS6.js → logger-SigQ2oZJ.js} +17 -10
  75. package/dist/logger-SigQ2oZJ.js.map +1 -0
  76. package/dist/{logs-routes-CBt7mMIL.js → logs-routes-DXLvMasE.js} +3 -3
  77. package/dist/{logs-routes-CBt7mMIL.js.map → logs-routes-DXLvMasE.js.map} +1 -1
  78. package/dist/mcp/mcp-apps.d.ts +53 -0
  79. package/dist/mcp/mcp-routes.d.ts +10 -1
  80. package/dist/mcp/mcp-tools.d.ts +10 -0
  81. package/dist/metrics/index.d.ts +8 -0
  82. package/dist/metrics/realtime.d.ts +25 -0
  83. package/dist/{offline-AvuEcg7u-DFHL98OT.js → offline-BjJdcVBb-BOzzsnrh.js} +35 -7
  84. package/dist/offline-BjJdcVBb-BOzzsnrh.js.map +1 -0
  85. package/dist/{offline-store-BhYXViha-YTmjBpo2.js → offline-store-Cxhh99Q--FB6fSf5A.js} +43 -9
  86. package/dist/offline-store-Cxhh99Q--FB6fSf5A.js.map +1 -0
  87. package/dist/{openapi-generator-CyxEtYEX.js → openapi-generator-B6aw_KuR.js} +41 -7
  88. package/dist/openapi-generator-B6aw_KuR.js.map +1 -0
  89. package/dist/{proxy-BYir8tWK.js → proxy-2nS5N63I.js} +3 -3
  90. package/dist/{proxy-BYir8tWK.js.map → proxy-2nS5N63I.js.map} +1 -1
  91. package/dist/{query-parser-CDXWf2hH.js → query-parser-DFVCjW5i.js} +6 -6
  92. package/dist/{query-parser-CDXWf2hH.js.map → query-parser-DFVCjW5i.js.map} +1 -1
  93. package/dist/{request-timeout-DVjo-c_8.js → request-timeout-Cqm4JXtZ.js} +3 -3
  94. package/dist/{request-timeout-DVjo-c_8.js.map → request-timeout-Cqm4JXtZ.js.map} +1 -1
  95. package/dist/{rls-simulator-routes-bEY7-5-u.js → rls-simulator-routes-D5-XfjzW.js} +4 -4
  96. package/dist/{rls-simulator-routes-bEY7-5-u.js.map → rls-simulator-routes-D5-XfjzW.js.map} +1 -1
  97. package/dist/{schema-editor-routes-Dc3DU_jm.js → schema-editor-routes-DzSe6V0a.js} +4 -4
  98. package/dist/{schema-editor-routes-Dc3DU_jm.js.map → schema-editor-routes-DzSe6V0a.js.map} +1 -1
  99. package/dist/services/routed-realtime-service.d.ts +1 -1
  100. package/dist/{soft-delete-params-BRONCOA2.js → soft-delete-params-9lKBAlDw.js} +2 -2
  101. package/dist/{soft-delete-params-BRONCOA2.js.map → soft-delete-params-9lKBAlDw.js.map} +1 -1
  102. package/dist/{sql-export-routes-QycX8W8S.js → sql-export-routes-BxMqgAFX.js} +4 -4
  103. package/dist/{sql-export-routes-QycX8W8S.js.map → sql-export-routes-BxMqgAFX.js.map} +1 -1
  104. package/dist/{src-Bh9LRPb9.js → src-JQNz7cWv.js} +19 -2
  105. package/dist/{src-Bh9LRPb9.js.map → src-JQNz7cWv.js.map} +1 -1
  106. package/dist/storage/GCSStorageController.d.ts +9 -1
  107. package/dist/storage/LocalStorageController.d.ts +8 -1
  108. package/dist/storage/S3StorageController.d.ts +4 -2
  109. package/dist/storage/index.d.ts +1 -0
  110. package/dist/storage/orphan-sweep.d.ts +67 -0
  111. package/dist/storage/policies.d.ts +1 -1
  112. package/dist/storage/streams.d.ts +17 -0
  113. package/dist/storage/types.d.ts +15 -33
  114. package/dist/{upload-validation-Bgo626uY.js → upload-validation-IYXn4xcm.js} +41 -3
  115. package/dist/upload-validation-IYXn4xcm.js.map +1 -0
  116. package/dist/utils/load-failure.d.ts +9 -0
  117. package/dist/utils/logger.d.ts +9 -4
  118. package/package.json +7 -6
  119. package/dist/GCSStorageController-40FyFeSx.js.map +0 -1
  120. package/dist/S3StorageController-Bl5shp94.js.map +0 -1
  121. package/dist/access-BFAUvsSs.js.map +0 -1
  122. package/dist/auth-izI7AEzC.js.map +0 -1
  123. package/dist/cron-loader-mMhqbVsl.js.map +0 -1
  124. package/dist/cron-scheduler-Be7CNghL.js.map +0 -1
  125. package/dist/field-access-DYsvjI_P.js.map +0 -1
  126. package/dist/function-loader-B8YzXEsQ.js.map +0 -1
  127. package/dist/load-failure-L5hvfDoG.js.map +0 -1
  128. package/dist/logger-CW8pmTS6.js.map +0 -1
  129. package/dist/offline-AvuEcg7u-DFHL98OT.js.map +0 -1
  130. package/dist/offline-store-BhYXViha-YTmjBpo2.js.map +0 -1
  131. package/dist/openapi-generator-CyxEtYEX.js.map +0 -1
  132. package/dist/upload-validation-Bgo626uY.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"ddl-bootstrap-CjRrn12l.js","names":[],"sources":["../src/boot/ddl-bootstrap.ts"],"sourcesContent":["import { logger } from \"../utils/logger.js\";\n\n/**\n * Helpers for the \"create my internal table if it isn't there yet\" bootstrap\n * that several stores run at boot.\n *\n * These all look trivially safe — every statement is `IF NOT EXISTS` — and they\n * are not, for two reasons that only show up with more than one app instance:\n *\n * 1. `CREATE … IF NOT EXISTS` reads the catalog and then writes to it, and\n * those two steps are not one atomic operation. Instances starting together\n * — a rolling deploy, a replica count going from 1 to N, a crash loop\n * restarting the fleet — can both see \"absent\" and both try to create. The\n * loser gets a duplicate key on a *catalog* index instead of the silent\n * no-op the syntax appears to promise. Measured against Postgres 18: with\n * five instances booting at once, 8 of 10 `ensureTable` calls hit it.\n *\n * 2. A bootstrap written as one long `try` block therefore abandons everything\n * after the losing statement — including, in every store that has one, the\n * `REVOKE` that takes the table back off the end-user role. That revoke is\n * a security control and must not be collateral damage from a race.\n *\n * So: retry the race, contain each statement separately, and decide what to do\n * next from what actually exists rather than from who won.\n */\n\n/** A driver's `executeSql`, narrowed to what a bootstrap needs. */\nexport type SqlExec = (sqlText: string, options?: { params?: unknown[] }) => Promise<Record<string, unknown>[]>;\n\n/**\n * The first keyword of every statement that changes what the database *is* —\n * its tables, columns, indexes, types, functions, triggers, policies, roles and\n * privileges — as opposed to the rows in it.\n *\n * `DO` is here because every anonymous block Rebase runs exists to make a\n * guarded `GRANT`, `REVOKE` or `CREATE`; there is no row write anywhere in the\n * framework that needs one. `TRUNCATE`, `VACUUM` and `ANALYZE` are not: they\n * act on data and statistics, and none of them is something a change process\n * reviews.\n */\nconst SCHEMA_CHANGE_KEYWORDS = new Set([\n \"CREATE\", \"ALTER\", \"DROP\", \"GRANT\", \"REVOKE\", \"COMMENT\", \"DO\",\n \"REINDEX\", \"CLUSTER\", \"SECURITY\", \"IMPORT\", \"REASSIGN\"\n]);\n\n/** A statement with any leading whitespace and comments removed. */\nexport function withoutLeadingComments(sqlText: string): string {\n let rest = sqlText;\n for (;;) {\n rest = rest.trimStart();\n if (rest.startsWith(\"--\")) {\n const end = rest.indexOf(\"\\n\");\n rest = end === -1 ? \"\" : rest.slice(end + 1);\n } else if (rest.startsWith(\"/*\")) {\n const end = rest.indexOf(\"*/\");\n rest = end === -1 ? \"\" : rest.slice(end + 2);\n } else {\n return rest;\n }\n }\n}\n\n/** The statement's first keyword, past any leading comments, upper-cased. */\nfunction leadingKeyword(sqlText: string): string {\n return (withoutLeadingComments(sqlText).match(/^[A-Za-z]+/)?.[0] ?? \"\").toUpperCase();\n}\n\n/**\n * Whether a statement changes the database's structure or its privileges.\n *\n * Decided on the leading keyword, which is exact for every statement the\n * framework writes: none of them hides DDL behind a `WITH` or a function call.\n */\nexport function isSchemaChange(sqlText: string): boolean {\n return SCHEMA_CHANGE_KEYWORDS.has(leadingKeyword(sqlText));\n}\n\n/**\n * Raised in place of a schema change on a backend that provisions nothing.\n *\n * Its own class so a bootstrap step can tell \"this was not run on purpose\" from\n * \"this failed\", and say the first at `debug` rather than as an error per\n * statement on every boot.\n */\nexport class SchemaChangeRefusedError extends Error {\n readonly code = \"REBASE_PROVISIONING_OFF\";\n\n constructor(readonly statement: string) {\n super(\n \"Not run: this backend changes nothing in its database (provisioning is off). \" +\n `Statement: ${statement.trim().split(\"\\n\")[0]}`\n );\n this.name = \"SchemaChangeRefusedError\";\n }\n}\n\n/**\n * `exec`, with every schema change refused and every other statement passed\n * through.\n *\n * What a store is built on when its backend provisions nothing. The store's own\n * bootstrap still runs, so it reads what is there exactly as it always has and\n * reports what is missing in its own words; only the statements that would\n * have changed the database stop here. A guard rather than a branch per store,\n * because a branch is a thing the next store can forget.\n */\nexport function refuseSchemaChanges(exec: SqlExec): SqlExec {\n return (sqlText, options) => isSchemaChange(sqlText)\n ? Promise.reject(new SchemaChangeRefusedError(sqlText))\n : exec(sqlText, options);\n}\n\n/** {@link refuseSchemaChanges} when `provision` is `false`; `exec` itself otherwise. */\nexport function provisioningExec(exec: SqlExec, provision: boolean | undefined): SqlExec {\n return provision === false ? refuseSchemaChanges(exec) : exec;\n}\n\n\n/**\n * SQLSTATEs a *simultaneous boot* can raise from statements that are otherwise\n * idempotent. Retrying is always the right answer for these: the second attempt\n * finds the object present and does nothing.\n */\nexport const CONCURRENT_DDL_SQLSTATES = new Set([\n \"23505\", // unique_violation on pg_type / pg_class / pg_namespace\n \"42P06\", // duplicate_schema\n \"42P07\", // duplicate_table\n \"42710\", // duplicate_object — an index or a constraint\n \"40P01\" // deadlock_detected — two boots taking catalog locks in step\n]);\n\n/** Attempts per idempotent DDL statement, including the first. */\nexport const DDL_ATTEMPTS = 4;\nconst DDL_RETRY_BASE_MS = 40;\n\n/**\n * Walk an error's `cause` chain, stopping at the first link `visit` accepts.\n * Drizzle wraps the driver error, so nothing useful is ever on the top level.\n */\nexport function hasInCauseChain(err: unknown, visit: (e: Record<string, unknown>) => boolean): boolean {\n let current: unknown = err;\n for (let depth = 0; depth < 10 && current; depth++) {\n if (typeof current !== \"object\") break;\n const e = current as Record<string, unknown>;\n if (visit(e)) return true;\n current = e.cause;\n }\n return false;\n}\n\n/**\n * Is this the loser of a race to create something that already exists?\n *\n * Deliberately narrow. A permission failure, an unreachable database or a typo\n * in the DDL must surface on the first attempt rather than being retried four\n * times and then reported as a race that never was.\n */\nexport function isConcurrentDdlRace(err: unknown): boolean {\n return hasInCauseChain(err, (e) =>\n (typeof e.code === \"string\" && CONCURRENT_DDL_SQLSTATES.has(e.code)) ||\n // SQLite and MySQL say it in words rather than in a shared SQLSTATE.\n (typeof e.message === \"string\" && /already exists/i.test(e.message))\n );\n}\n\n/**\n * SQLSTATEs that mean, unambiguously, *the object is already there*.\n *\n * A subset of {@link CONCURRENT_DDL_SQLSTATES} and a stricter question. The\n * broad set answers \"should this be retried\"; this one answers \"is it safe to\n * carry on as though the statement had succeeded\", which is a claim about the\n * end state rather than about the attempt. Deadlock is not in it — a deadlocked\n * statement did nothing and must be retried, not skipped.\n */\nconst DUPLICATE_OBJECT_SQLSTATES = new Set([\n \"42P06\", // duplicate_schema\n \"42P07\", // duplicate_table\n \"42710\" // duplicate_object — a type, an index, a constraint\n]);\n\n/**\n * Did this statement fail *because a peer already created the same object*?\n *\n * The narrow companion to {@link isConcurrentDdlRace}, for the one caller that\n * needs to tell \"someone beat me to it\" from \"this genuinely failed\": a loop\n * applying a schema plan, where treating every `23505` as a harmless race would\n * silently swallow the one that matters — a unique constraint that cannot be\n * added because the customer's existing rows violate it.\n *\n * `23505` is therefore only accepted when it names a `pg_catalog` index. That is\n * what a lost `CREATE TYPE`/`CREATE TABLE` race raises (`pg_type_typname_nsp_index`\n * is the one seen in practice); a unique violation on user data names the user's\n * own constraint and is left to the caller.\n *\n * With one exception, in {@link NOT_A_RACE_PG_INDEXES}.\n */\nexport function isDuplicateObjectRace(err: unknown): boolean {\n return hasInCauseChain(err, (e) => {\n if (typeof e.code !== \"string\") return false;\n if (DUPLICATE_OBJECT_SQLSTATES.has(e.code)) return true;\n if (e.code !== \"23505\") return false;\n // node-postgres puts the violated index in `constraint`; some paths only\n // carry it in the detail text, so check both rather than miss the race.\n const constraint = typeof e.constraint === \"string\" ? e.constraint : \"\";\n const detail = typeof e.detail === \"string\" ? e.detail : \"\";\n for (const index of NOT_A_RACE_PG_INDEXES) {\n if (constraint === index || detail.includes(index)) return false;\n }\n return constraint.startsWith(\"pg_\") || /\\bpg_[a-z_]+_index\\b/.test(detail);\n });\n}\n\n/**\n * `pg_catalog` indexes whose `23505` is never a race.\n *\n * `pg_enum_typid_label_index` is unique on (type, label), and one statement\n * violates it on its own: `CREATE TYPE t AS ENUM ('draft', 'draft')` — which is\n * what a collection with two enum entries carrying the same `id` generates.\n * Under the `pg_` prefix rule that read as \"a peer created it first\", so the\n * type was never created, boot carried on, and the column fell back to `TEXT`\n * with no enum behind it. Verified against PGlite: the duplicate `CREATE TYPE`\n * raises exactly this.\n *\n * The concurrent-boot case this rule exists for does not come through here at\n * all. Two pods adding the same label race on `ALTER TYPE … ADD VALUE`, which\n * raises `42710` (already in {@link DUPLICATE_OBJECT_SQLSTATES}) — and the\n * generator writes `ADD VALUE IF NOT EXISTS`, so it usually raises nothing.\n *\n * The duplicate `id` is rejected earlier now, by `validate-config`, which names\n * the property. This is the second line: a config that reaches the database with\n * one fails loudly instead of degrading.\n */\nconst NOT_A_RACE_PG_INDEXES = [\"pg_enum_typid_label_index\"];\n\nexport interface DdlBootstrapper {\n /**\n * Run one idempotent statement — `CREATE … IF NOT EXISTS`, `ALTER TABLE …\n * ADD COLUMN IF NOT EXISTS` — retrying the catalog race a simultaneous boot\n * produces. Never throws: a statement that cannot be made to work is logged\n * and the caller carries on to the next one.\n */\n ensureObject(label: string, sqlText: string): Promise<void>;\n\n /** Contain one step's failure so that the steps after it still run. */\n step(label: string, run: () => Promise<unknown>): Promise<void>;\n\n /**\n * Is this table there and readable? Asked with a query any SQL dialect\n * answers, rather than `to_regclass`, so a future non-Postgres SQL driver\n * gets a real answer instead of a syntax error read as \"missing\".\n */\n isReadable(table: string): Promise<boolean>;\n}\n\n/**\n * @param exec the driver's SQL escape hatch\n * @param scope log prefix identifying the caller, e.g. `\"cron-store\"`\n */\nexport function createDdlBootstrapper(exec: SqlExec, scope: string): DdlBootstrapper {\n /** Jittered, so peers that collided once do not collide again in lockstep. */\n const backoff = (attempt: number) =>\n new Promise(resolve => setTimeout(resolve, DDL_RETRY_BASE_MS * attempt * (1 + Math.random())));\n\n const step: DdlBootstrapper[\"step\"] = async (label, run) => {\n try {\n await run();\n } catch (err) {\n if (hasInCauseChain(err, e => e.code === \"REBASE_PROVISIONING_OFF\")) {\n logger.debug(`[${scope}] ${label}: not run — this backend changes nothing in its database`);\n return;\n }\n logger.error(`[${scope}] ${label} failed`, { error: err });\n }\n };\n\n return {\n step,\n\n ensureObject(label, sqlText) {\n return step(label, async () => {\n for (let attempt = 1; ; attempt++) {\n try {\n await exec(sqlText);\n return;\n } catch (err) {\n if (!isConcurrentDdlRace(err) || attempt >= DDL_ATTEMPTS) throw err;\n logger.debug(\n `[${scope}] Lost a create race for ${label} with another instance ` +\n `(attempt ${attempt}/${DDL_ATTEMPTS}) — retrying`\n );\n await backoff(attempt);\n }\n }\n });\n },\n\n async isReadable(table) {\n try {\n await exec(`SELECT 1 FROM ${table} WHERE false`);\n return true;\n } catch {\n return false;\n }\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAwCA,IAAM,yCAAyB,IAAI,IAAI;CACnC;CAAU;CAAS;CAAQ;CAAS;CAAU;CAAW;CACzD;CAAW;CAAW;CAAY;CAAU;AAChD,CAAC;;AAGD,SAAgB,uBAAuB,SAAyB;CAC5D,IAAI,OAAO;CACX,SAAS;EACL,OAAO,KAAK,UAAU;EACtB,IAAI,KAAK,WAAW,IAAI,GAAG;GACvB,MAAM,MAAM,KAAK,QAAQ,IAAI;GAC7B,OAAO,QAAQ,KAAK,KAAK,KAAK,MAAM,MAAM,CAAC;EAC/C,OAAO,IAAI,KAAK,WAAW,IAAI,GAAG;GAC9B,MAAM,MAAM,KAAK,QAAQ,IAAI;GAC7B,OAAO,QAAQ,KAAK,KAAK,KAAK,MAAM,MAAM,CAAC;EAC/C,OACI,OAAO;CAEf;AACJ;;AAGA,SAAS,eAAe,SAAyB;CAC7C,QAAQ,uBAAuB,OAAO,CAAC,CAAC,MAAM,YAAY,CAAC,GAAG,MAAM,GAAA,CAAI,YAAY;AACxF;;;;;;;AAQA,SAAgB,eAAe,SAA0B;CACrD,OAAO,uBAAuB,IAAI,eAAe,OAAO,CAAC;AAC7D;;;;;;;;AASA,IAAa,2BAAb,cAA8C,MAAM;CAG3B;CAFrB,OAAgB;CAEhB,YAAY,WAA4B;EACpC,MACI,2FACc,UAAU,KAAK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} from \"../utils/logger.js\";\n\n/**\n * Helpers for the \"create my internal table if it isn't there yet\" bootstrap\n * that several stores run at boot.\n *\n * These all look trivially safe — every statement is `IF NOT EXISTS` — and they\n * are not, for two reasons that only show up with more than one app instance:\n *\n * 1. `CREATE … IF NOT EXISTS` reads the catalog and then writes to it, and\n * those two steps are not one atomic operation. Instances starting together\n * — a rolling deploy, a replica count going from 1 to N, a crash loop\n * restarting the fleet — can both see \"absent\" and both try to create. The\n * loser gets a duplicate key on a *catalog* index instead of the silent\n * no-op the syntax appears to promise. Measured against Postgres 18: with\n * five instances booting at once, 8 of 10 `ensureTable` calls hit it.\n *\n * 2. A bootstrap written as one long `try` block therefore abandons everything\n * after the losing statement — including, in every store that has one, the\n * `REVOKE` that takes the table back off the end-user role. That revoke is\n * a security control and must not be collateral damage from a race.\n *\n * So: retry the race, contain each statement separately, and decide what to do\n * next from what actually exists rather than from who won.\n */\n\n/** A driver's `executeSql`, narrowed to what a bootstrap needs. */\nexport type SqlExec = (sqlText: string, options?: { params?: unknown[] }) => Promise<Record<string, unknown>[]>;\n\n/**\n * The first keyword of every statement that changes what the database *is* —\n * its tables, columns, indexes, types, functions, triggers, policies, roles and\n * privileges — as opposed to the rows in it.\n *\n * `DO` is here because every anonymous block Rebase runs exists to make a\n * guarded `GRANT`, `REVOKE` or `CREATE`; there is no row write anywhere in the\n * framework that needs one. `TRUNCATE`, `VACUUM` and `ANALYZE` are not: they\n * act on data and statistics, and none of them is something a change process\n * reviews.\n */\nconst SCHEMA_CHANGE_KEYWORDS = new Set([\n \"CREATE\", \"ALTER\", \"DROP\", \"GRANT\", \"REVOKE\", \"COMMENT\", \"DO\",\n \"REINDEX\", \"CLUSTER\", \"SECURITY\", \"IMPORT\", \"REASSIGN\"\n]);\n\n/** A statement with any leading whitespace and comments removed. */\nexport function withoutLeadingComments(sqlText: string): string {\n let rest = sqlText;\n for (;;) {\n rest = rest.trimStart();\n if (rest.startsWith(\"--\")) {\n const end = rest.indexOf(\"\\n\");\n rest = end === -1 ? \"\" : rest.slice(end + 1);\n } else if (rest.startsWith(\"/*\")) {\n const end = rest.indexOf(\"*/\");\n rest = end === -1 ? \"\" : rest.slice(end + 2);\n } else {\n return rest;\n }\n }\n}\n\n/** The statement's first keyword, past any leading comments, upper-cased. */\nfunction leadingKeyword(sqlText: string): string {\n return (withoutLeadingComments(sqlText).match(/^[A-Za-z]+/)?.[0] ?? \"\").toUpperCase();\n}\n\n/**\n * Whether a statement changes the database's structure or its privileges.\n *\n * Decided on the leading keyword, which is exact for every statement the\n * framework writes: none of them hides DDL behind a `WITH` or a function call.\n */\nexport function isSchemaChange(sqlText: string): boolean {\n return SCHEMA_CHANGE_KEYWORDS.has(leadingKeyword(sqlText));\n}\n\n/**\n * Raised in place of a schema change on a backend that provisions nothing.\n *\n * Its own class so a bootstrap step can tell \"this was not run on purpose\" from\n * \"this failed\", and say the first at `debug` rather than as an error per\n * statement on every boot.\n */\nexport class SchemaChangeRefusedError extends Error {\n readonly code = \"REBASE_PROVISIONING_OFF\";\n\n constructor(readonly statement: string) {\n super(\n \"Not run: this backend changes nothing in its database (provisioning is off). \" +\n `Statement: ${statement.trim().split(\"\\n\")[0]}`\n );\n this.name = \"SchemaChangeRefusedError\";\n }\n}\n\n/**\n * `exec`, with every schema change refused and every other statement passed\n * through.\n *\n * What a store is built on when its backend provisions nothing. The store's own\n * bootstrap still runs, so it reads what is there exactly as it always has and\n * reports what is missing in its own words; only the statements that would\n * have changed the database stop here. A guard rather than a branch per store,\n * because a branch is a thing the next store can forget.\n */\nexport function refuseSchemaChanges(exec: SqlExec): SqlExec {\n return (sqlText, options) => isSchemaChange(sqlText)\n ? Promise.reject(new SchemaChangeRefusedError(sqlText))\n : exec(sqlText, options);\n}\n\n/** {@link refuseSchemaChanges} when `provision` is `false`; `exec` itself otherwise. */\nexport function provisioningExec(exec: SqlExec, provision: boolean | undefined): SqlExec {\n return provision === false ? refuseSchemaChanges(exec) : exec;\n}\n\n\n/**\n * SQLSTATEs a *simultaneous boot* can raise from statements that are otherwise\n * idempotent. Retrying is always the right answer for these: the second attempt\n * finds the object present and does nothing.\n */\nexport const CONCURRENT_DDL_SQLSTATES = new Set([\n \"23505\", // unique_violation on pg_type / pg_class / pg_namespace\n \"42P06\", // duplicate_schema\n \"42P07\", // duplicate_table\n \"42710\", // duplicate_object — an index or a constraint\n \"40P01\" // deadlock_detected — two boots taking catalog locks in step\n]);\n\n/** Attempts per idempotent DDL statement, including the first. */\nexport const DDL_ATTEMPTS = 4;\nconst DDL_RETRY_BASE_MS = 40;\n\n/**\n * Walk an error's `cause` chain, stopping at the first link `visit` accepts.\n * Drizzle wraps the driver error, so nothing useful is ever on the top level.\n */\nexport function hasInCauseChain(err: unknown, visit: (e: Record<string, unknown>) => boolean): boolean {\n let current: unknown = err;\n for (let depth = 0; depth < 10 && current; depth++) {\n if (typeof current !== \"object\") break;\n const e = current as Record<string, unknown>;\n if (visit(e)) return true;\n current = e.cause;\n }\n return false;\n}\n\n/**\n * Is this the loser of a race to create something that already exists?\n *\n * Deliberately narrow. A permission failure, an unreachable database or a typo\n * in the DDL must surface on the first attempt rather than being retried four\n * times and then reported as a race that never was.\n */\nexport function isConcurrentDdlRace(err: unknown): boolean {\n return hasInCauseChain(err, (e) =>\n (typeof e.code === \"string\" && CONCURRENT_DDL_SQLSTATES.has(e.code)) ||\n // SQLite and MySQL say it in words rather than in a shared SQLSTATE.\n (typeof e.message === \"string\" && /already exists/i.test(e.message))\n );\n}\n\n/**\n * SQLSTATEs that mean, unambiguously, *the object is already there*.\n *\n * A subset of {@link CONCURRENT_DDL_SQLSTATES} and a stricter question. The\n * broad set answers \"should this be retried\"; this one answers \"is it safe to\n * carry on as though the statement had succeeded\", which is a claim about the\n * end state rather than about the attempt. Deadlock is not in it — a deadlocked\n * statement did nothing and must be retried, not skipped.\n */\nconst DUPLICATE_OBJECT_SQLSTATES = new Set([\n \"42P06\", // duplicate_schema\n \"42P07\", // duplicate_table\n \"42710\" // duplicate_object — a type, an index, a constraint\n]);\n\n/**\n * Did this statement fail *because a peer already created the same object*?\n *\n * The narrow companion to {@link isConcurrentDdlRace}, for the one caller that\n * needs to tell \"someone beat me to it\" from \"this genuinely failed\": a loop\n * applying a schema plan, where treating every `23505` as a harmless race would\n * silently swallow the one that matters — a unique constraint that cannot be\n * added because the customer's existing rows violate it.\n *\n * `23505` is therefore only accepted when it names a `pg_catalog` index. That is\n * what a lost `CREATE TYPE`/`CREATE TABLE` race raises (`pg_type_typname_nsp_index`\n * is the one seen in practice); a unique violation on user data names the user's\n * own constraint and is left to the caller.\n *\n * With one exception, in {@link NOT_A_RACE_PG_INDEXES}.\n */\nexport function isDuplicateObjectRace(err: unknown): boolean {\n return hasInCauseChain(err, (e) => {\n if (typeof e.code !== \"string\") return false;\n if (DUPLICATE_OBJECT_SQLSTATES.has(e.code)) return true;\n if (e.code !== \"23505\") return false;\n // node-postgres puts the violated index in `constraint`; some paths only\n // carry it in the detail text, so check both rather than miss the race.\n const constraint = typeof e.constraint === \"string\" ? e.constraint : \"\";\n const detail = typeof e.detail === \"string\" ? e.detail : \"\";\n for (const index of NOT_A_RACE_PG_INDEXES) {\n if (constraint === index || detail.includes(index)) return false;\n }\n return constraint.startsWith(\"pg_\") || /\\bpg_[a-z_]+_index\\b/.test(detail);\n });\n}\n\n/**\n * `pg_catalog` indexes whose `23505` is never a race.\n *\n * `pg_enum_typid_label_index` is unique on (type, label), and one statement\n * violates it on its own: `CREATE TYPE t AS ENUM ('draft', 'draft')` — which is\n * what a collection with two enum entries carrying the same `id` generates.\n * Under the `pg_` prefix rule that read as \"a peer created it first\", so the\n * type was never created, boot carried on, and the column fell back to `TEXT`\n * with no enum behind it. Verified against PGlite: the duplicate `CREATE TYPE`\n * raises exactly this.\n *\n * The concurrent-boot case this rule exists for does not come through here at\n * all. Two pods adding the same label race on `ALTER TYPE … ADD VALUE`, which\n * raises `42710` (already in {@link DUPLICATE_OBJECT_SQLSTATES}) — and the\n * generator writes `ADD VALUE IF NOT EXISTS`, so it usually raises nothing.\n *\n * The duplicate `id` is rejected earlier now, by `validate-config`, which names\n * the property. This is the second line: a config that reaches the database with\n * one fails loudly instead of degrading.\n */\nconst NOT_A_RACE_PG_INDEXES = [\"pg_enum_typid_label_index\"];\n\nexport interface DdlBootstrapper {\n /**\n * Run one idempotent statement — `CREATE … IF NOT EXISTS`, `ALTER TABLE …\n * ADD COLUMN IF NOT EXISTS` — retrying the catalog race a simultaneous boot\n * produces. Never throws: a statement that cannot be made to work is logged\n * and the caller carries on to the next one.\n */\n ensureObject(label: string, sqlText: string): Promise<void>;\n\n /** Contain one step's failure so that the steps after it still run. */\n step(label: string, run: () => Promise<unknown>): Promise<void>;\n\n /**\n * Is this table there and readable? Asked with a query any SQL dialect\n * answers, rather than `to_regclass`, so a future non-Postgres SQL driver\n * gets a real answer instead of a syntax error read as \"missing\".\n */\n isReadable(table: string): Promise<boolean>;\n}\n\n/**\n * @param exec the driver's SQL escape hatch\n * @param scope log prefix identifying the caller, e.g. `\"cron-store\"`\n */\nexport function createDdlBootstrapper(exec: SqlExec, scope: string): DdlBootstrapper {\n /** Jittered, so peers that collided once do not collide again in lockstep. */\n const backoff = (attempt: number) =>\n new Promise(resolve => setTimeout(resolve, DDL_RETRY_BASE_MS * attempt * (1 + Math.random())));\n\n const step: DdlBootstrapper[\"step\"] = async (label, run) => {\n try {\n await run();\n } catch (err) {\n if (hasInCauseChain(err, e => e.code === \"REBASE_PROVISIONING_OFF\")) {\n logger.debug(`[${scope}] ${label}: not run — this backend changes nothing in its database`);\n return;\n }\n logger.error(`[${scope}] ${label} failed`, { error: err });\n }\n };\n\n return {\n step,\n\n ensureObject(label, sqlText) {\n return step(label, async () => {\n for (let attempt = 1; ; attempt++) {\n try {\n await exec(sqlText);\n return;\n } catch (err) {\n if (!isConcurrentDdlRace(err) || attempt >= DDL_ATTEMPTS) throw err;\n logger.debug(\n `[${scope}] Lost a create race for ${label} with another instance ` +\n `(attempt ${attempt}/${DDL_ATTEMPTS}) — retrying`\n );\n await backoff(attempt);\n }\n }\n });\n },\n\n async isReadable(table) {\n try {\n await exec(`SELECT 1 FROM ${table} WHERE false`);\n return true;\n } catch {\n return false;\n }\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAwCA,IAAM,yCAAyB,IAAI,IAAI;CACnC;CAAU;CAAS;CAAQ;CAAS;CAAU;CAAW;CACzD;CAAW;CAAW;CAAY;CAAU;AAChD,CAAC;;AAGD,SAAgB,uBAAuB,SAAyB;CAC5D,IAAI,OAAO;CACX,SAAS;EACL,OAAO,KAAK,UAAU;EACtB,IAAI,KAAK,WAAW,IAAI,GAAG;GACvB,MAAM,MAAM,KAAK,QAAQ,IAAI;GAC7B,OAAO,QAAQ,KAAK,KAAK,KAAK,MAAM,MAAM,CAAC;EAC/C,OAAO,IAAI,KAAK,WAAW,IAAI,GAAG;GAC9B,MAAM,MAAM,KAAK,QAAQ,IAAI;GAC7B,OAAO,QAAQ,KAAK,KAAK,KAAK,MAAM,MAAM,CAAC;EAC/C,OACI,OAAO;CAEf;AACJ;;AAGA,SAAS,eAAe,SAAyB;CAC7C,QAAQ,uBAAuB,OAAO,CAAC,CAAC,MAAM,YAAY,CAAC,GAAG,MAAM,GAAA,CAAI,YAAY;AACxF;;;;;;;AAQA,SAAgB,eAAe,SAA0B;CACrD,OAAO,uBAAuB,IAAI,eAAe,OAAO,CAAC;AAC7D;;;;;;;;AASA,IAAa,2BAAb,cAA8C,MAAM;CAG3B;CAFrB,OAAgB;CAEhB,YAAY,WAA4B;EACpC,MACI,2FACc,UAAU,KAAK,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,IAC/C;EAJiB,KAAA,YAAA;EAKjB,KAAK,OAAO;CAChB;AACJ;;;;;;;;;;;AAYA,SAAgB,oBAAoB,MAAwB;CACxD,QAAQ,SAAS,YAAY,eAAe,OAAO,IAC7C,QAAQ,OAAO,IAAI,yBAAyB,OAAO,CAAC,IACpD,KAAK,SAAS,OAAO;AAC/B;;AAGA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