@rebasepro/server-postgres 0.30.0 → 0.31.0-canary.g59cd6fd
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -8
- package/dist/{BranchService-CrXvcES2.js → BranchService-USp1AvZB.js} +3 -3
- package/dist/{BranchService-CrXvcES2.js.map → BranchService-USp1AvZB.js.map} +1 -1
- package/dist/PostgresBackendDriver.d.ts +99 -54
- package/dist/PostgresBootstrapper.d.ts +12 -27
- package/dist/auth/ensure-tables.d.ts +16 -5
- package/dist/auth/schema-version.d.ts +2 -2
- package/dist/auth/services.d.ts +2 -3
- package/dist/{auth-users-columns-C72EMoDJ.js → auth-users-columns-BpfgbkxZ.js} +2 -16
- package/dist/auth-users-columns-BpfgbkxZ.js.map +1 -0
- package/dist/{backup-cli-CTKCOLpX.js → backup-cli-DbKyEj6c.js} +4 -4
- package/dist/{backup-cli-CTKCOLpX.js.map → backup-cli-DbKyEj6c.js.map} +1 -1
- package/dist/{boot-ddl-CqGIwSYx.js → boot-ddl-5H2bL_80.js} +2 -2
- package/dist/{boot-ddl-CqGIwSYx.js.map → boot-ddl-5H2bL_80.js.map} +1 -1
- package/dist/{cli-console-DBPw-oAz.js → cli-console-DsRgGSBR.js} +65 -39
- package/dist/cli-console-DsRgGSBR.js.map +1 -0
- package/dist/cli-console.d.ts +16 -13
- package/dist/cli-flags.d.ts +8 -9
- package/dist/cli-helpers.d.ts +15 -11
- package/dist/{cli-errors-DYTxnLbW.js → cli-schema-dir-CiN0ephV.js} +184 -70
- package/dist/cli-schema-dir-CiN0ephV.js.map +1 -0
- package/dist/cli-schema-dir.d.ts +64 -0
- package/dist/cli.js +192 -257
- package/dist/cli.js.map +1 -1
- package/dist/data-transformer.d.ts +50 -19
- package/dist/{database-preflight-iBpT7-vv.js → database-preflight-bfnIBnjM.js} +5 -5
- package/dist/database-preflight-bfnIBnjM.js.map +1 -0
- package/dist/{deferred-index-build-BCU9RoHK.js → deferred-index-build-CcSDA7wE.js} +69 -13
- package/dist/deferred-index-build-CcSDA7wE.js.map +1 -0
- package/dist/{ensure-collection-policies-Bo-_fDAy.js → ensure-policies-rRmXb5bt.js} +31 -31
- package/dist/ensure-policies-rRmXb5bt.js.map +1 -0
- package/dist/{ensure-collection-tables-DCJINkT_.js → ensure-tables-Bvm-F2wW.js} +44 -37
- package/dist/ensure-tables-Bvm-F2wW.js.map +1 -0
- package/dist/{ensure-tables-BPGaGh0y.js → ensure-tables-CC8p_AK3.js} +34 -29
- package/dist/ensure-tables-CC8p_AK3.js.map +1 -0
- package/dist/{enum-labels-kept-YAgOZS4I.js → enum-labels-kept-FlX9SHdf.js} +8 -8
- package/dist/enum-labels-kept-FlX9SHdf.js.map +1 -0
- package/dist/{generate-drizzle-schema-DcrFr7YX.js → generate-drizzle-schema-SJMXxzPI.js} +12 -12
- package/dist/generate-drizzle-schema-SJMXxzPI.js.map +1 -0
- package/dist/{generate-drizzle-schema-logic-LTLZvt6r.js → generate-drizzle-schema-logic-DL7R1rAF.js} +15 -8
- package/dist/generate-drizzle-schema-logic-DL7R1rAF.js.map +1 -0
- package/dist/{generate-files-CsaVzatS.js → generate-files-tlJ9_lGI.js} +23 -30
- package/dist/generate-files-tlJ9_lGI.js.map +1 -0
- package/dist/{generate-next-step-DgK5BlBn.js → generate-next-step-CO09dovd.js} +3 -3
- package/dist/generate-next-step-CO09dovd.js.map +1 -0
- package/dist/{generate-postgres-ddl-logic-Dg0bcENZ.js → generate-postgres-ddl-logic-B8huc03c.js} +51 -21
- package/dist/generate-postgres-ddl-logic-B8huc03c.js.map +1 -0
- package/dist/{generated-schema-diff-By4dxyTH.js → generated-schema-diff-DoT2dYDe.js} +297 -279
- package/dist/generated-schema-diff-DoT2dYDe.js.map +1 -0
- package/dist/{generated-schema-staleness-BvNF3i-s.js → generated-schema-staleness-YBVq2kTn.js} +21 -29
- package/dist/generated-schema-staleness-YBVq2kTn.js.map +1 -0
- package/dist/history/ensure-history-table.d.ts +22 -0
- package/dist/index.d.ts +8 -2
- package/dist/index.es.js +201 -25
- package/dist/index.es.js.map +1 -1
- package/dist/interfaces.d.ts +3 -4
- package/dist/{introspect-db-queries-DevUrzll.js → introspect-db-queries-BgiRQqtR.js} +7 -2
- package/dist/introspect-db-queries-BgiRQqtR.js.map +1 -0
- package/dist/introspect-tables-Cw_A-kk4.js +2086 -0
- package/dist/introspect-tables-Cw_A-kk4.js.map +1 -0
- package/dist/load-tables-B1Re74ng.js +92 -0
- package/dist/load-tables-B1Re74ng.js.map +1 -0
- package/dist/{migrate-baseline-CmWXL7qx.js → migrate-baseline-DZmekgpD.js} +19 -32
- package/dist/migrate-baseline-DZmekgpD.js.map +1 -0
- package/dist/{migrate-policy-stamps-BN_Qad6c.js → migrate-policy-stamps-B_acrUQB.js} +18 -19
- package/dist/migrate-policy-stamps-B_acrUQB.js.map +1 -0
- package/dist/model/PostgresTableRegistry.d.ts +159 -0
- package/dist/model/build-registry.d.ts +25 -0
- package/dist/model/refresh-relational-schema.d.ts +24 -0
- package/dist/model/runtime-table.d.ts +53 -0
- package/dist/{collections → model}/validate-relations.d.ts +15 -21
- package/dist/{open-rebase-40paQfVW.js → open-rebase-4kisUF_k.js} +3946 -3870
- package/dist/open-rebase-4kisUF_k.js.map +1 -0
- package/dist/open-rebase.d.ts +16 -15
- package/dist/{pg-error-utils-DJHjCF7-.js → pg-error-utils-BT5NzGFZ.js} +17 -20
- package/dist/pg-error-utils-BT5NzGFZ.js.map +1 -0
- package/dist/plan-schema-Hbtjhge3.js +1633 -0
- package/dist/plan-schema-Hbtjhge3.js.map +1 -0
- package/dist/{policy-drift-C-m0uWHH.js → policy-drift-BVMyqHSa.js} +29 -29
- package/dist/policy-drift-BVMyqHSa.js.map +1 -0
- package/dist/{push-index-adoption-Cp7oZxSl.js → push-index-adoption-hpHTyXMR.js} +7 -7
- package/dist/push-index-adoption-hpHTyXMR.js.map +1 -0
- package/dist/{push-index-prebuild-DbwKGtQT.js → push-index-prebuild-Bty9F7bD.js} +6 -6
- package/dist/push-index-prebuild-Bty9F7bD.js.map +1 -0
- package/dist/{push-kept-defaults-CLcgsEPt.js → push-kept-defaults-Bst4MDup.js} +13 -16
- package/dist/push-kept-defaults-Bst4MDup.js.map +1 -0
- package/dist/{push-legacy-renames-BthD0E9W.js → push-legacy-renames-bB4bM6br.js} +6 -6
- package/dist/push-legacy-renames-bB4bM6br.js.map +1 -0
- package/dist/{push-policy-plan-BgcrroxQ.js → push-policy-plan-BI8U4BOD.js} +11 -11
- package/dist/push-policy-plan-BI8U4BOD.js.map +1 -0
- package/dist/{render-ddl-Ci3S_SoI.js → render-ddl-D4n86NHz.js} +14 -7
- package/dist/render-ddl-D4n86NHz.js.map +1 -0
- package/dist/{request-role-cli-Dy1EgJU9.js → request-role-cli-BdRzdE87.js} +11 -11
- package/dist/{request-role-cli-Dy1EgJU9.js.map → request-role-cli-BdRzdE87.js.map} +1 -1
- package/dist/{request-role-migration-GHTJnPMV.js → request-role-migration-C8aq_TO3.js} +2 -2
- package/dist/{request-role-migration-GHTJnPMV.js.map → request-role-migration-C8aq_TO3.js.map} +1 -1
- package/dist/{rls-enforcement-Cc_UhOxb.js → rls-enforcement-DB5HHj96.js} +19 -19
- package/dist/rls-enforcement-DB5HHj96.js.map +1 -0
- package/dist/{rls-settings-BCGMIig3.js → rls-settings-CmGK2U0a.js} +2 -2
- package/dist/rls-settings-CmGK2U0a.js.map +1 -0
- package/dist/schema/auth-users-columns.d.ts +1 -11
- package/dist/schema/catalogue-schema.d.ts +33 -29
- package/dist/schema/classify-change.d.ts +23 -16
- package/dist/schema/column-type-drift.d.ts +16 -0
- package/dist/schema/config-relations.d.ts +10 -9
- package/dist/schema/deferred-index-build.d.ts +1 -1
- package/dist/schema/doctor-cli.js +1544 -66
- package/dist/schema/doctor-cli.js.map +1 -1
- package/dist/schema/doctor-database.d.ts +7 -7
- package/dist/schema/doctor-policy-checks.d.ts +4 -4
- package/dist/schema/doctor-search-scale.d.ts +14 -14
- package/dist/schema/doctor.d.ts +27 -27
- package/dist/schema/dynamic-tables.d.ts +6 -5
- package/dist/schema/{ensure-collection-policies.d.ts → ensure-policies.d.ts} +20 -20
- package/dist/schema/{ensure-collection-tables.d.ts → ensure-tables.d.ts} +11 -11
- package/dist/schema/enum-labels-kept.d.ts +6 -6
- package/dist/schema/generate-drizzle-schema-logic.d.ts +3 -3
- package/dist/schema/generate-drizzle-schema.js +1 -1
- package/dist/schema/generate-files.d.ts +6 -6
- package/dist/schema/generate-postgres-ddl-logic.d.ts +23 -20
- package/dist/schema/generate-postgres-ddl.js +11 -11
- package/dist/schema/generate-postgres-ddl.js.map +1 -1
- package/dist/schema/generate-schema-commit.d.ts +13 -8
- package/dist/schema/generated-schema-diff.d.ts +16 -16
- package/dist/schema/generated-schema-staleness.d.ts +11 -11
- package/dist/schema/index-adoption.d.ts +4 -4
- package/dist/schema/introspect-db-customization.d.ts +47 -0
- package/dist/schema/introspect-db-inference.d.ts +30 -9
- package/dist/schema/introspect-db-logic.d.ts +79 -110
- package/dist/schema/introspect-db-project.d.ts +15 -18
- package/dist/schema/introspect-db-queries.d.ts +1 -1
- package/dist/schema/introspect-db-search.d.ts +25 -4
- package/dist/schema/introspect-db-storage.d.ts +4 -74
- package/dist/schema/introspect-db.js +102 -90
- package/dist/schema/introspect-db.js.map +1 -1
- package/dist/schema/introspect-runtime.d.ts +47 -36
- package/dist/schema/introspect-tables.d.ts +182 -0
- package/dist/schema/load-tables.d.ts +55 -0
- package/dist/schema/migrate-policy-stamps.d.ts +4 -4
- package/dist/schema/migration-freshness.d.ts +13 -13
- package/dist/schema/plan/column-order.d.ts +82 -0
- package/dist/schema/plan/diff-plan.d.ts +9 -3
- package/dist/schema/plan/plan-schema.d.ts +55 -52
- package/dist/schema/plan/render-drizzle.d.ts +1 -1
- package/dist/schema/plan/types.d.ts +24 -15
- package/dist/schema/push-index-adoption.d.ts +3 -3
- package/dist/schema/push-index-prebuild.d.ts +3 -3
- package/dist/schema/push-kept-defaults.d.ts +7 -7
- package/dist/schema/push-legacy-renames.d.ts +3 -3
- package/dist/schema/push-policy-plan.d.ts +5 -5
- package/dist/schema/reconcile-schema.d.ts +5 -5
- package/dist/schema/relation-names.d.ts +15 -20
- package/dist/schema/render-outputs.d.ts +76 -0
- package/dist/schema/search-column.d.ts +11 -43
- package/dist/schema/{collection-index.d.ts → table-index.d.ts} +21 -42
- package/dist/schema/{collections-schema-version.d.ts → tables-schema-version.d.ts} +8 -2
- package/dist/schema/vector-index.d.ts +24 -28
- package/dist/{search-column-BM-GV6vH.js → search-column-BO-WND-B.js} +86 -149
- package/dist/search-column-BO-WND-B.js.map +1 -0
- package/dist/security/caller-sql-columns.d.ts +9 -6
- package/dist/security/policy-drift.d.ts +14 -14
- package/dist/security/rls-enforcement.d.ts +19 -25
- package/dist/security/rls-settings.d.ts +2 -2
- package/dist/security/served-table-protection.d.ts +125 -0
- package/dist/services/FetchService.d.ts +22 -133
- package/dist/services/PersistService.d.ts +6 -17
- package/dist/services/RelationService.d.ts +57 -106
- package/dist/services/RelationWriteService.d.ts +59 -66
- package/dist/services/cdc/identity-columns.d.ts +7 -5
- package/dist/services/cdc/junction-tables.d.ts +14 -14
- package/dist/services/collection-helpers.d.ts +52 -95
- package/dist/services/dataService.d.ts +15 -12
- package/dist/services/field-op-sql.d.ts +11 -9
- package/dist/services/field-viewer.d.ts +12 -11
- package/dist/services/hidden-columns.d.ts +30 -0
- package/dist/services/index.d.ts +1 -1
- package/dist/services/junction-writes.d.ts +37 -18
- package/dist/services/nested-path.d.ts +18 -18
- package/dist/services/read-field-access.d.ts +23 -7
- package/dist/services/read-scope.d.ts +10 -9
- package/dist/services/realtimeService.d.ts +25 -10
- package/dist/services/relation-tables.d.ts +97 -0
- package/dist/services/row-pipeline.d.ts +50 -69
- package/dist/services/soft-delete.d.ts +25 -24
- package/dist/services/table-hooks.d.ts +146 -0
- package/dist/services/view-access.d.ts +7 -7
- package/dist/services/write-transaction-scope.d.ts +1 -1
- package/dist/{source-fZb92pN8.js → source-VxbrQojV.js} +111 -79
- package/dist/source-VxbrQojV.js.map +1 -0
- package/dist/{collections-schema-version-D7bDI0PJ.js → tables-schema-version-YvZIBlOP.js} +12 -6
- package/dist/tables-schema-version-YvZIBlOP.js.map +1 -0
- package/dist/utils/drizzle-conditions.d.ts +70 -84
- package/dist/utils/pg-array-null-patch.d.ts +27 -10
- package/dist/utils/pg-error-utils.d.ts +4 -4
- package/dist/{vector-index-DsQ3V2d2.js → vector-index-VSh3ufTd.js} +62 -54
- package/dist/vector-index-VSh3ufTd.js.map +1 -0
- package/dist/{websocket-B7ex6AQM.js → websocket-BevXvwfo.js} +51 -40
- package/dist/websocket-BevXvwfo.js.map +1 -0
- package/dist/websocket.d.ts +2 -2
- package/package.json +7 -7
- package/dist/auth-users-columns-C72EMoDJ.js.map +0 -1
- package/dist/cli-collections-path.d.ts +0 -31
- package/dist/cli-console-DBPw-oAz.js.map +0 -1
- package/dist/cli-errors-DYTxnLbW.js.map +0 -1
- package/dist/collections/PostgresCollectionRegistry.d.ts +0 -47
- package/dist/collections/buildRegistry.d.ts +0 -27
- package/dist/collections-schema-version-D7bDI0PJ.js.map +0 -1
- package/dist/column-plan-helpers-BeSztMor.js +0 -161
- package/dist/column-plan-helpers-BeSztMor.js.map +0 -1
- package/dist/database-preflight-iBpT7-vv.js.map +0 -1
- package/dist/deferred-index-build-BCU9RoHK.js.map +0 -1
- package/dist/doctor-Kg1oUK0Q.js +0 -1458
- package/dist/doctor-Kg1oUK0Q.js.map +0 -1
- package/dist/ensure-collection-policies-Bo-_fDAy.js.map +0 -1
- package/dist/ensure-collection-tables-DCJINkT_.js.map +0 -1
- package/dist/ensure-tables-BPGaGh0y.js.map +0 -1
- package/dist/enum-labels-kept-YAgOZS4I.js.map +0 -1
- package/dist/generate-drizzle-schema-DcrFr7YX.js.map +0 -1
- package/dist/generate-drizzle-schema-logic-LTLZvt6r.js.map +0 -1
- package/dist/generate-files-CsaVzatS.js.map +0 -1
- package/dist/generate-next-step-DgK5BlBn.js.map +0 -1
- package/dist/generate-postgres-ddl-logic-Dg0bcENZ.js.map +0 -1
- package/dist/generated-schema-diff-By4dxyTH.js.map +0 -1
- package/dist/generated-schema-staleness-BvNF3i-s.js.map +0 -1
- package/dist/introspect-db-logic-DWqAEURB.js +0 -2047
- package/dist/introspect-db-logic-DWqAEURB.js.map +0 -1
- package/dist/introspect-db-queries-DevUrzll.js.map +0 -1
- package/dist/migrate-baseline-CmWXL7qx.js.map +0 -1
- package/dist/migrate-policy-stamps-BN_Qad6c.js.map +0 -1
- package/dist/open-rebase-40paQfVW.js.map +0 -1
- package/dist/pg-error-utils-DJHjCF7-.js.map +0 -1
- package/dist/plan-schema-vJd3UEmT.js +0 -1604
- package/dist/plan-schema-vJd3UEmT.js.map +0 -1
- package/dist/policy-drift-C-m0uWHH.js.map +0 -1
- package/dist/push-index-adoption-Cp7oZxSl.js.map +0 -1
- package/dist/push-index-prebuild-DbwKGtQT.js.map +0 -1
- package/dist/push-kept-defaults-CLcgsEPt.js.map +0 -1
- package/dist/push-legacy-renames-BthD0E9W.js.map +0 -1
- package/dist/push-policy-plan-BgcrroxQ.js.map +0 -1
- package/dist/render-ddl-Ci3S_SoI.js.map +0 -1
- package/dist/rls-enforcement-Cc_UhOxb.js.map +0 -1
- package/dist/rls-settings-BCGMIig3.js.map +0 -1
- package/dist/schema/column-plan-helpers.d.ts +0 -161
- package/dist/schema/introspect-db-naming.d.ts +0 -10
- package/dist/search-column-BM-GV6vH.js.map +0 -1
- package/dist/source-fZb92pN8.js.map +0 -1
- package/dist/vector-index-DsQ3V2d2.js.map +0 -1
- package/dist/websocket-B7ex6AQM.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-VxbrQojV.js","names":["styles","process"],"sources":["../src/schema/table-index.ts","../src/schema/atlas-exclude.ts","../src/cli-output.ts","../../../node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/ansi-styles/index.js","../../../node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/supports-color/index.js","../../../node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/utilities.js","../../../node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/index.js"],"sourcesContent":["/**\n * The one place a table's `indexes` become `CREATE INDEX`.\n *\n * Like `search-column.ts` and `vector-index.ts`, this module exists so the DDL\n * generator and the boot-time ensure render the *same* specification rather\n * than describing the same index twice, differently.\n *\n * ## Why every form here is core Postgres\n *\n * `rebase db push` runs `atlas schema apply`, which materialises the desired\n * state in a bare scratch database to plan against. `--exclude` does not\n * suppress that replay, and `CREATE EXTENSION` cannot go in the file. So an\n * index wanting `gin_trgm_ops` or `vector_cosine_ops` would parse, plan, and\n * then fail against a database the author has never heard of. Those are\n * refused here instead, and redirected to the feature that owns them: trigram\n * search is `search:`, ANN is a `vector` property.\n *\n * Verified against atlas v1.2.3 and Postgres 18 before this was written: plain,\n * composite with `DESC NULLS LAST`, partial, unique, covering `INCLUDE`, `GIN`\n * and expression indexes all parse, apply, and re-plan clean. The Atlas\n * limitation that forced the search carve-out is that it will not parse a file\n * containing a function *definition* — a function *call* inside an index is\n * fine. That is why this module needs no carve-out and search did.\n *\n * ## Why the name carries a hash\n *\n * `CREATE INDEX IF NOT EXISTS` is a **name** check, not a definition check. A\n * readable name means a changed declaration keeps the old index and reports\n * success, forever. Hashing the index's *semantics* into its name makes a\n * redefinition a different object: the new one is built before the old one is\n * dropped, there is never a window with no index, and drift detection reduces\n * to a set difference over names.\n */\nimport type {\n TableDescriptor,\n TableIndex,\n TableIndexKey,\n TableIndexPredicate\n} from \"@rebasepro/types\";\nimport { columnByKey, columnNameOf } from \"@rebasepro/common\";\nimport { sha1Hex, truncateToBytes } from \"@rebasepro/utils\";\n\nexport type IndexMethod = \"btree\" | \"gin\" | \"brin\";\n\n/** A key column, with the ordering Postgres will actually apply. */\nexport interface ResolvedIndexKey {\n column: string;\n /** Always concrete. `btree` defaults ascending; unordered methods report `asc`. */\n direction: \"asc\" | \"desc\";\n /** Postgres's own default: `last` under `asc`, `first` under `desc`. */\n nulls: \"first\" | \"last\";\n}\n\n/** A predicate resolved onto column names, ready to render and to hash. */\nexport type ResolvedPredicate =\n | { column: string; op: \"=\" | \"!=\" | \"<\" | \"<=\" | \">\" | \">=\"; value: string | number | boolean }\n | { column: string; op: \"is null\" | \"is not null\" }\n | { column: string; op: \"in\"; value: readonly (string | number)[] }\n | { and: readonly ResolvedPredicate[] };\n\n/** One index, fully resolved. The only shape the renderers accept. */\nexport interface TableIndexSpec {\n schema: string;\n table: string;\n method: IndexMethod;\n unique: boolean;\n keys: ResolvedIndexKey[];\n include: string[];\n predicate: ResolvedPredicate | null;\n /**\n * The author's one-line justification, when there is one. Never enters\n * the name. A legacy `indexes` entry must state it; a table's may not.\n */\n reason?: string;\n /** Derived by {@link deriveIndexName}. Frozen — see the module comment. */\n indexName: string;\n /**\n * Set when Rebase derived this index for a foreign key rather than anybody\n * declaring it — see {@link foreignKeyIndexSpec}. Never enters the name, so\n * the derived index and a declared one over the same column are one object.\n *\n * Read by exactly one consumer: boot-ensure, which builds these in the\n * background on a table that already exists instead of holding the boot\n * for the build. Every renderer treats them like any other index.\n */\n derived?: \"foreign-key\";\n}\n\n/**\n * A declaration that cannot become an index.\n *\n * Thrown at build time, naming the collection and the array position, because\n * the alternative is a `CREATE INDEX` that fails during a push with a Postgres\n * error mentioning a column the author never wrote.\n */\nexport class TableIndexConfigError extends Error {\n readonly collectionSlug: string;\n readonly position: number;\n\n constructor(collectionSlug: string, position: number, message: string) {\n super(`${collectionSlug}.indexes[${position}]: ${message}`);\n this.name = \"TableIndexConfigError\";\n this.collectionSlug = collectionSlug;\n this.position = position;\n }\n}\n\n/** Postgres allows 32 key columns. See the doc comment on `on`. */\nexport const MAX_INDEX_KEYS = 5;\n\n/**\n * `_ix`/`_ux` plus `_` plus 7 hex — the part of the name that must always\n * survive truncation, and therefore is never inside the truncated portion.\n */\nconst NAME_SUFFIX_BYTES = 11;\n\n/**\n * Every Rebase-managed index name, and nothing else.\n *\n * The terminal `_ix_`/`_ux_` plus exactly seven lowercase hex characters is\n * what separates this scheme from every other producer in the codebase —\n * `_fkey`, `_gin`, `_trgm`, `_pkey`, `_key`, the vector distances, and the\n * `idx_` prefix auth uses. `_idx` was rejected as a tail because it is already\n * taken for real: `users_email_verification_token_idx` is byte-for-byte what a\n * naive `<table>_<column>_idx` derives on an auth-enabled `users` collection.\n *\n * Load-bearing for safety, not just tidiness. An index that does NOT match this\n * belongs to somebody else — a hand-written one, or one an introspected\n * database arrived with — and is excluded from the Atlas diff so the push\n * cannot drop it.\n */\nexport const isRebaseIndexName = (name: string): boolean => /_(?:ix|ux)_[0-9a-f]{7}$/.test(name);\n\nconst isOrderedMethod = (method: IndexMethod): boolean => method === \"btree\";\n\n/**\n * The parts of an index that decide what it *is*.\n *\n * A semantic projection, not the rendered statement — the same arrangement as\n * `getPolicyNameHash`, and for the same reason. A change to how this file\n * formats SQL (eliding a default `USING btree`, quoting differently, emitting\n * `NULLS LAST` explicitly) must not silently rename every index in every\n * deployed database. Hashing generator output would make every cosmetic edit a\n * fleet-wide DROP + CREATE.\n *\n * `reason` is deliberately absent: rewording a comment must not rebuild an\n * index. `nulls` is the *effective* placement, so writing Postgres's own\n * default down is a no-op rather than a redefinition.\n *\n * `v` is the only escape hatch, and it is expensive on purpose: bumping it\n * renames every index in the field.\n */\nexport const indexFingerprint = (spec: Omit<TableIndexSpec, \"indexName\">): string => sha1Hex(JSON.stringify({\n v: 1,\n s: spec.schema,\n t: spec.table,\n m: spec.method,\n u: spec.unique,\n k: spec.keys.map(k => [k.column, k.direction, k.nulls]),\n i: spec.include,\n w: spec.predicate\n})).substring(0, 7);\n\n/**\n * `<table>_<columns>_ix_<hash>`, or `_ux_` when unique.\n *\n * Truncation eats the readable head and never the hash. `toPostgresIdentifier`\n * truncates the whole string at 63 bytes, which on a hashed name would cut off\n * the one part that makes it unique — the failure already frozen into\n * `contracts/derived-names.txt`, where a foreign key is recorded with its\n * `_fkey` suffix truncated away, so a second foreign key on that table would\n * derive a byte-identical name.\n */\nexport const deriveIndexName = (spec: Omit<TableIndexSpec, \"indexName\">): string => {\n // Built suffix-first, so the two parts that carry meaning — the `_ix`/`_ux`\n // tag that {@link isRebaseIndexName} matches on, and the fingerprint — are\n // never in the string being truncated. Composing the whole name and then\n // trimming it to 63 loses both, silently: an 80-byte table name yields\n // `xxxx…xxx_610bb9e` with the tag gone, so the index stops being\n // recognisable as Rebase's and `db push` treats it as foreign forever.\n const tag = spec.unique ? \"ux\" : \"ix\";\n const suffix = `_${tag}_${indexFingerprint(spec)}`;\n const readable = `${spec.table}_${spec.keys.map(k => k.column).join(\"_\")}`;\n return `${truncateToBytes(readable, 63 - NAME_SUFFIX_BYTES)}${suffix}`;\n};\n\nconst quoteLiteral = (value: string | number | boolean): string => {\n if (typeof value === \"number\") return String(value);\n if (typeof value === \"boolean\") return value ? \"TRUE\" : \"FALSE\";\n return `'${value.replace(/'/g, \"''\")}'`;\n};\n\n/** Render a resolved predicate as the body of a `WHERE` clause. */\nexport const renderPredicate = (predicate: ResolvedPredicate): string => {\n if (\"and\" in predicate) {\n // Always parenthesised. Postgres would apply the same precedence\n // without it, but the rendered SQL is read by people diffing a plan.\n return predicate.and.map(renderPredicate).join(\" AND \");\n }\n switch (predicate.op) {\n case \"is null\":\n case \"is not null\":\n return `\"${predicate.column}\" ${predicate.op.toUpperCase()}`;\n case \"in\":\n return `\"${predicate.column}\" IN (${predicate.value.map(quoteLiteral).join(\", \")})`;\n default:\n return `\"${predicate.column}\" ${predicate.op} ${quoteLiteral(predicate.value)}`;\n }\n};\n\n/**\n * The `CREATE INDEX` for one spec.\n *\n * `concurrently` is a parameter rather than a string replacement on the way\n * out. `search-column.ts` and `vector-index.ts` both reach for\n * `.replace(\"CREATE INDEX IF NOT EXISTS\", …)` instead, which silently does\n * nothing for a UNIQUE index — the rendered text is `CREATE UNIQUE INDEX …`\n * and the pattern never matches.\n */\nexport const tableIndexStatement = (\n spec: TableIndexSpec,\n options: { concurrently?: boolean; ifNotExists?: boolean } = {}\n): string => {\n const unique = spec.unique ? \"UNIQUE \" : \"\";\n const concurrently = options.concurrently ? \"CONCURRENTLY \" : \"\";\n const ifNotExists = options.ifNotExists ? \"IF NOT EXISTS \" : \"\";\n const using = spec.method === \"btree\" ? \"\" : ` USING ${spec.method}`;\n\n const keys = spec.keys.map(k => {\n if (!isOrderedMethod(spec.method)) return `\"${k.column}\"`;\n const direction = k.direction === \"desc\" ? \" DESC\" : \"\";\n // Emitted only when it is not what the direction already implies, so\n // the rendered SQL matches what `pg_get_indexdef` reads back and a\n // re-plan finds no difference.\n const impliedNulls = k.direction === \"desc\" ? \"first\" : \"last\";\n const nulls = k.nulls === impliedNulls ? \"\" : ` NULLS ${k.nulls.toUpperCase()}`;\n return `\"${k.column}\"${direction}${nulls}`;\n }).join(\", \");\n\n const include = spec.include.length > 0\n ? ` INCLUDE (${spec.include.map(c => `\"${c}\"`).join(\", \")})`\n : \"\";\n const where = spec.predicate ? ` WHERE ${renderPredicate(spec.predicate)}` : \"\";\n\n return `CREATE ${unique}INDEX ${concurrently}${ifNotExists}\"${spec.indexName}\" ` +\n `ON \"${spec.schema}\".\"${spec.table}\"${using} (${keys})${include}${where};`;\n};\n\nexport const tableIndexStatements = (\n specs: readonly TableIndexSpec[],\n options: { concurrently?: boolean; ifNotExists?: boolean } = {}\n): string[] => specs.map(spec => tableIndexStatement(spec, options));\n\n/** One index key, as the spec builder reads it. */\ninterface IndexKeySource {\n key: string;\n direction?: \"asc\" | \"desc\";\n nulls?: \"first\" | \"last\";\n}\n\n/** A predicate, as the spec builder reads it. */\ntype IndexPredicateSource =\n | { key: string; op: \"=\" | \"!=\" | \"<\" | \"<=\" | \">\" | \">=\"; value: string | number | boolean }\n | { key: string; op: \"is null\" | \"is not null\" }\n | { key: string; op: \"in\"; value: readonly (string | number)[] }\n | { and: readonly IndexPredicateSource[] };\n\n/** One declared index, as the spec builder reads it. */\ninterface IndexSource {\n on: readonly IndexKeySource[];\n using?: IndexMethod;\n unique?: boolean;\n include?: readonly string[];\n where?: IndexPredicateSource;\n /** Absent or blank: no reason (an index may leave it out). */\n reason?: string;\n}\n\n/** The table the indexes are declared on. */\ninterface IndexTableSource {\n slug: string;\n schema: string;\n table: string;\n /** The primary-key columns. */\n primaryKey: readonly string[];\n indexes: readonly IndexSource[];\n /** The SQL column a key names; calls `fail` for a key that names none. */\n column(key: string, fail: (message: string) => never): string;\n /** Whether the key's own column already carries a single-column UNIQUE. */\n declaresUnique(key: string): boolean;\n}\n\nconst tableIndexKey = (entry: string | TableIndexKey): IndexKeySource => typeof entry === \"string\"\n ? { key: entry }\n : {\n key: entry.column,\n ...(entry.direction !== undefined ? { direction: entry.direction } : {}),\n ...(entry.nulls !== undefined ? { nulls: entry.nulls } : {})\n };\n\nconst tablePredicate = (predicate: TableIndexPredicate): IndexPredicateSource => {\n if (\"and\" in predicate) return { and: predicate.and.map(tablePredicate) };\n switch (predicate.op) {\n case \"is null\":\n case \"is not null\": return { key: predicate.column, op: predicate.op };\n case \"in\": return { key: predicate.column, op: \"in\", value: predicate.value };\n default: return { key: predicate.column, op: predicate.op, value: predicate.value };\n }\n};\n\nconst tableIndexSource = (index: TableIndex): IndexSource => ({\n on: index.columns.map(tableIndexKey),\n ...(index.using !== undefined ? { using: index.using } : {}),\n ...(index.unique !== undefined ? { unique: index.unique } : {}),\n ...(index.include !== undefined ? { include: index.include } : {}),\n ...(index.where !== undefined ? { where: tablePredicate(index.where) } : {}),\n ...(index.reason !== undefined ? { reason: index.reason } : {})\n});\n\n/**\n * The SQL column an index key names on a table: a column key, or a\n * `belongsTo` relation (its foreign-key column). Another relation kind has no\n * column here — its foreign key is on the target, or in a junction.\n */\nconst tableIndexColumn = (table: TableDescriptor, key: string, fail: (message: string) => never): string => {\n const column = columnByKey(table, key);\n if (column) return column.column;\n const relation = table.relations.find(candidate => candidate.name === key);\n if (relation?.kind === \"belongsTo\") return relation.localKey;\n if (relation) {\n return fail(\n `\"${key}\" is a ${relation.kind} relation, which has no column on this table — ` +\n `the foreign key lives on \"${relation.target}\". Declare the index there.`\n );\n }\n return fail(`\"${key}\" is no column key or \\`belongsTo\\` relation of this table.`);\n};\n\n/**\n * Every index one table declares (`indexes`), resolved and named, read from\n * its descriptor — what the planner calls, for a table and for a\n * materialized view's stored rows alike.\n *\n * Throws {@link TableIndexConfigError} rather than dropping a bad entry.\n */\nexport const buildTableIndexSpecs = (table: TableDescriptor): TableIndexSpec[] => {\n const declared = table.indexes;\n if (!declared || declared.length === 0) return [];\n return indexSpecsFrom({\n slug: table.slug,\n schema: table.schema,\n table: table.table,\n primaryKey: table.primaryKey.map(key => columnNameOf(table, key) ?? key),\n indexes: declared.map(tableIndexSource),\n column: (key, fail) => tableIndexColumn(table, key, fail),\n declaresUnique: key => {\n const column = columnByKey(table, key);\n if (column) return column.unique === true;\n const relation = table.relations.find(candidate => candidate.name === key);\n if (relation?.kind !== \"belongsTo\") return false;\n return table.columns.some(candidate => candidate.column === relation.localKey && candidate.unique === true);\n }\n });\n};\n\nconst resolveSourcePredicate = (\n source: IndexTableSource,\n predicate: IndexPredicateSource,\n fail: (message: string) => never\n): ResolvedPredicate => {\n if (\"and\" in predicate) {\n return { and: predicate.and.map(p => resolveSourcePredicate(source, p, fail)) };\n }\n const column = source.column(predicate.key, fail);\n switch (predicate.op) {\n case \"is null\":\n case \"is not null\":\n return { column, op: predicate.op };\n case \"in\": {\n const seen = new Set(predicate.value);\n if (seen.size !== predicate.value.length) {\n fail(`the \\`in\\` list for \"${predicate.key}\" repeats a value, which changes nothing.`);\n }\n return { column, op: \"in\", value: [...predicate.value] };\n }\n default:\n return { column, op: predicate.op, value: predicate.value };\n }\n};\n\nconst indexSpecsFrom = (source: IndexTableSource): TableIndexSpec[] => {\n const { slug, schema, table } = source;\n const pk = [...source.primaryKey].sort().join(\",\");\n\n const specs: TableIndexSpec[] = [];\n const byName = new Map<string, number>();\n\n source.indexes.forEach((index, position) => {\n const fail = (message: string): never => {\n throw new TableIndexConfigError(slug, position, message);\n };\n\n if (index.on.length === 0) {\n fail(\"`on` must name at least one column.\");\n }\n if (index.on.length > MAX_INDEX_KEYS) {\n fail(`\\`on\\` has ${index.on.length} keys; the limit is ${MAX_INDEX_KEYS}. Payload columns belong in \\`include\\`.`);\n }\n\n const method: IndexMethod = index.using ?? \"btree\";\n const unique = method === \"btree\" && Boolean(index.unique);\n if (!isOrderedMethod(method)) {\n for (const key of index.on) {\n if (key.direction !== undefined || key.nulls !== undefined) {\n fail(`access method \"${method}\" does not support ASC/DESC or NULLS options.`);\n }\n }\n }\n\n const keys: ResolvedIndexKey[] = index.on.map(key => {\n const column = source.column(key.key, fail);\n const direction = key.direction ?? \"asc\";\n const nulls = key.nulls ?? (direction === \"desc\" ? \"first\" : \"last\");\n return { column, direction, nulls };\n });\n\n const duplicateKey = keys.map(k => k.column).find((c, i, all) => all.indexOf(c) !== i);\n if (duplicateKey) fail(`\"${duplicateKey}\" appears twice in \\`on\\`.`);\n\n if (keys.map(k => k.column).sort().join(\",\") === pk && pk !== \"\") {\n fail(`this is the primary key — \"${table}_pkey\" already indexes exactly these columns.`);\n }\n\n const include = (index.include ?? []).map(key => source.column(key, fail));\n const overlap = include.find(c => keys.some(k => k.column === c));\n if (overlap) fail(`\"${overlap}\" is in both \\`on\\` and \\`include\\`; Postgres rejects the overlap.`);\n\n if (unique && keys.length === 1) {\n const key = index.on[0].key;\n if (source.declaresUnique(key)) {\n fail(\n `\"${key}\" already declares a single-column UNIQUE (\\`.unique()\\`, legacy \\`validation.unique\\`). ` +\n \"Two declarations of one guarantee — remove one.\"\n );\n }\n }\n\n const predicate = index.where ? resolveSourcePredicate(source, index.where, fail) : null;\n\n const reason = index.reason === undefined || index.reason.trim() === \"\" ? {} : { reason: index.reason };\n const withoutName = { schema, table, method, unique, keys, include, predicate, ...reason };\n const indexName = deriveIndexName(withoutName);\n\n const clash = byName.get(indexName);\n if (clash !== undefined) {\n fail(`derives the same name as indexes[${clash}] — they are the same index declared twice.`);\n }\n byName.set(indexName, position);\n\n specs.push({ ...withoutName, indexName });\n });\n\n return specs;\n};\n\n/**\n * The stable order every consumer of a set of index specs uses.\n *\n * Exported because the boot-time diff reads the specs off the schema plan\n * rather than rebuilding them, and it has to reach the same order the CLI's\n * exclude list and `schema.sql` do — a second sort written out beside this one\n * is a second order the moment either is edited.\n */\nexport const sortIndexSpecs = (specs: readonly TableIndexSpec[]): TableIndexSpec[] =>\n [...specs].sort((a, b) =>\n a.schema.localeCompare(b.schema) ||\n a.table.localeCompare(b.table) ||\n a.indexName.localeCompare(b.indexName));\n\n// ── Foreign-key indexes ──────────────────────────────────────────────────────\n\n/**\n * The `reason` a derived foreign-key index carries. Never part of the name —\n * see {@link indexFingerprint} — so rewording it renames nothing.\n */\nexport const FOREIGN_KEY_INDEX_REASON =\n \"Derived for a foreign key: Postgres indexes the key a constraint points at, never the column holding it.\";\n\n/**\n * Whether an index already serves an equality lookup on `column` alone.\n *\n * A btree whose *leading* key is the column does, unique or not — that is the\n * prefix rule, and it is why a composite `(author_id, created_at)` makes a\n * second index on `author_id` pure write amplification. A partial index does\n * not: it serves only the rows its predicate admits, and a foreign-key lookup\n * has to reach every row. Nor does GIN or BRIN, which answer different\n * questions than \"the rows whose key is one of these\".\n */\nexport const leadsWithColumn = (spec: Pick<TableIndexSpec, \"method\" | \"predicate\" | \"keys\">, column: string): boolean =>\n spec.method === \"btree\" && spec.predicate === null && spec.keys[0]?.column === column;\n\n/**\n * The btree a foreign-key column gets when nothing else already leads with it.\n *\n * Postgres creates the index a foreign key *references* (the target's primary\n * key) and never the one on the column *holding* it. Every read from the other\n * side of the link filters on that column — a `hasMany`/`hasOne` include, a\n * nested listing (`/authors/5/posts`, page and count), the reverse side of a\n * many-to-many — and so does the `ON DELETE` check when a target row goes. With\n * no index each of those is a sequential scan of the child table: measured at\n * 13 ms for 25 parents over 100k children, and about 250 ms per nested listing\n * at a million.\n *\n * Named by {@link deriveIndexName} like every other index, so it is a\n * Rebase-managed name (`_ix_<fingerprint>`), it is in the Atlas diff, and it\n * is byte-for-byte the name an author's own plain index on the column would\n * derive. That identity is what makes the derived index and a declared one the\n * same object rather than two.\n */\nexport const foreignKeyIndexSpec = (schema: string, table: string, column: string): TableIndexSpec => {\n const withoutName = {\n schema,\n table,\n method: \"btree\" as const,\n unique: false,\n keys: [{ column, direction: \"asc\" as const, nulls: \"last\" as const }],\n include: [],\n predicate: null,\n reason: FOREIGN_KEY_INDEX_REASON\n };\n return { ...withoutName, indexName: deriveIndexName(withoutName), derived: \"foreign-key\" };\n};\n","/**\n * The names `db push` hands Atlas's `--exclude`, spelled so they match.\n *\n * An exclude is the only thing between `atlas schema apply --auto-approve` and\n * an object Rebase does not own: a table no collection backs, a hand-written\n * index, a CHECK constraint, the search and vector columns Rebase applies\n * itself. Atlas reads each one as a glob split on `.`, so a name is not a\n * pattern as it stands. Measured against the pinned 1.2.3:\n *\n * - a `.` in a name makes one more part, and Atlas refuses the whole command,\n * `too many parts in pattern` — so every push fails on that database;\n * - `[`, `]`, `*` and `?` are glob syntax. `[v1]` is a class matching `v` or\n * `1`, so `idx[v1]` matches `idxv` and not the index called `idx[v1]`:\n * nothing is excluded, nothing is reported, and Atlas plans the drop. For\n * an index that drop is not gated, so it applied without a word.\n *\n * So each part is escaped on its own and the parts are joined: a `.` becomes\n * `?`, which matches it (and any one character, so a pattern that also keeps a\n * near-namesake errs on the side of keeping), and glob syntax is escaped with\n * `\\`, which Atlas reads as the literal.\n *\n * Code that reads these patterns back — the migration stripper, the generated\n * column ownership check, the index ownership check — reads them with\n * {@link excludePatternParts}, the exact inverse for a pattern built here.\n */\n\n/** One part of an Atlas `--exclude` pattern that matches exactly this name. */\nexport function atlasExcludeSegment(name: string): string {\n return name.replace(/[\\\\*?[\\]]/g, ch => `\\\\${ch}`).replace(/\\./g, \"?\");\n}\n\n/**\n * The pattern that matches exactly the object these names qualify:\n * `(schema, table)` for a table, `(schema, table, object)` for a column, an\n * index or a constraint. Three parts for anything on a table: a two-part\n * pattern reads as a table, matches nothing, and reports no error.\n */\nexport function atlasExcludePattern(...parts: string[]): string {\n return parts.map(atlasExcludeSegment).join(\".\");\n}\n\n/**\n * The names a pattern from {@link atlasExcludePattern} was built from, or\n * `undefined` for one that is not a plain name — a wildcard such as `auth.*`.\n *\n * Exact for every pattern built there: a `\\` escapes the character after it,\n * and an unescaped `?` can only be a dot.\n */\nexport function excludePatternParts(pattern: string): string[] | undefined {\n const parts: string[] = [];\n for (const segment of pattern.split(\".\")) {\n let name = \"\";\n for (let i = 0; i < segment.length; i++) {\n const ch = segment[i];\n if (ch === \"\\\\\" && i + 1 < segment.length) {\n name += segment[++i];\n } else if (ch === \"?\") {\n name += \".\";\n } else if (ch === \"*\" || ch === \"[\" || ch === \"]\") {\n return undefined;\n } else {\n name += ch;\n }\n }\n parts.push(name);\n }\n return parts;\n}\n","/**\n * Terminal output for the `rebase db|schema|doctor` commands.\n *\n * These commands used to write every line through `logger`, and that is a\n * category error with three separate consequences:\n *\n * - `logger` prefixes each line with its own level, so a box-drawn report\n * arrived as `ℹ️ [INFO] ┌─ ✗ Missing Column ───` and the frame no longer\n * lined up with anything;\n * - `logger` is gated by `LOG_LEVEL`, which ships in the scaffold's own\n * `.env.example` — a developer who quietened their dev server with\n * `LOG_LEVEL=warn` got a `rebase db push` that printed almost nothing and\n * still exited non-zero, indistinguishable from a crash;\n * - under `NODE_ENV=production` `logger` emits JSON, so the whole report\n * became log records with the chalk escape codes embedded in them.\n *\n * A CLI's report *is* its return value. It goes to the terminal unconditionally\n * and unadorned. `packages/cli` has always written its output this way; this is\n * the same three functions for the plugin CLI that `rebase` delegates to.\n *\n * `logger` still belongs in this package's *runtime* — a request handler has no\n * terminal and its lines want levels, timestamps and redaction. The rule is the\n * caller, not the severity: anything a developer reads because they typed a\n * command goes here, anything a server emits while running goes to `logger`.\n *\n * Errors and warnings go to stderr so `rebase db push > plan.txt` keeps the\n * diagnosis on the terminal where it is readable.\n */\nimport { parseEnvBoolean } from \"@rebasepro/types\";\n\n/** One line of human-facing output on stdout. */\nexport const out = (line = \"\"): void => {\n console.log(line);\n};\n\n/** One line of human-facing warning output on stderr. */\nexport const outWarn = (line = \"\"): void => {\n console.warn(line);\n};\n\n/** One line of human-facing error output on stderr. */\nexport const outError = (line = \"\"): void => {\n console.error(line);\n};\n\n/**\n * Whether a failure should be printed with its stack — `rebase --debug`, which\n * the launcher passes down as `REBASE_DEBUG`, or `REBASE_DEBUG` set by hand.\n */\nexport const wantsStack = (): boolean => parseEnvBoolean(process.env.REBASE_DEBUG) === true;\n\n/**\n * An error as a person reads it: its message, and its stack only under\n * `--debug`.\n *\n * The rule `rebase` itself follows (`bin/rebase.js`). These commands run in a\n * child process the launcher's handler never sees, so a syntax error in a\n * collection file reached the terminal as `Doctor failed CollectionConfigError:`\n * followed by twenty frames of loader internals, under a sentence that already\n * said which file and which line.\n */\nexport const describeFailure = (error: unknown): string => {\n if (!(error instanceof Error)) return String(error);\n // A definition the compiler refuses is fully described by its message —\n // one problem per line, each naming the table and key. The stack is the\n // compiler's, never the author's mistake. (A module that would not import\n // keeps the hint: its stack points into the author's file.)\n if (isSchemaDefinitionRefusal(error) && !wantsStack()) return error.message;\n const failedQuery = describeFailedQuery(error);\n const lead = failedQuery?.reason ? `${failedQuery.reason}\\n ` : \"\";\n if (wantsStack() && error.stack) {\n if (!failedQuery) return error.stack;\n // The stack opens with the message, `params:` line and all.\n const opening = `${error.name}: ${error.message}`;\n const frames = error.stack.startsWith(opening) ? error.stack.slice(opening.length) : `\\n${error.stack}`;\n return `${lead}${error.name}: ${failedQuery.query}${frames}`;\n }\n if (failedQuery) return `${lead}${failedQuery.query}\\n Re-run with --debug for the stack trace.`;\n return `${error.message}\\n Re-run with --debug for the stack trace.`;\n};\n\n/**\n * Whether an error is `SchemaDefinitionError` (`@rebasepro/common`), told by\n * its code so this module does not import the package.\n */\nfunction isSchemaDefinitionRefusal(error: Error): boolean {\n return \"code\" in error && error.code === \"SCHEMA_DEFINITION_INVALID\";\n}\n\n/**\n * A failed query as a reader needs it: why it failed — Postgres' own reason\n * with its SQLSTATE (`relation \"nope_table\" does not exist (42P01)`), or the\n * driver's when Postgres never answered — and the query without the values it\n * ran with. `null` for any other error.\n *\n * Drizzle reports a failed query as `Failed query: <sql>` and a `params:` line\n * and keeps the error underneath in `cause`, so the message alone names a query\n * and no reason: `rebase console -e` printed exactly that, `--debug` included.\n * The values stay off the terminal: they are whatever the code passed, a\n * password hash or a token as readily as an id.\n */\nfunction describeFailedQuery(error: Error): { reason: string | null; query: string } | null {\n if (!error.message.startsWith(\"Failed query:\")) return null;\n const paramsAt = error.message.lastIndexOf(\"\\nparams:\");\n const postgres = postgresError(error.cause);\n return {\n reason: postgres ? `${postgres.message} (${postgres.code})` : deepestMessage(error.cause),\n query: paramsAt === -1 ? error.message : error.message.slice(0, paramsAt)\n };\n}\n\n/** The error Postgres raised, from a cause chain: the one carrying a SQLSTATE. */\nfunction postgresError(cause: unknown, depth = 0): { code: string; message: string } | null {\n if (!(cause instanceof Error) || depth > 5) return null;\n if (\"code\" in cause && typeof cause.code === \"string\" && /^[0-9A-Z]{5}$/.test(cause.code) && cause.message) {\n return { code: cause.code, message: cause.message };\n }\n return postgresError(cause.cause, depth + 1);\n}\n\n/** The innermost message in a cause chain, or `null` when there is none. */\nfunction deepestMessage(cause: unknown, depth = 0): string | null {\n if (!(cause instanceof Error) || depth > 5) return null;\n return deepestMessage(cause.cause, depth + 1) ?? (cause.message || null);\n}\n","const ANSI_BACKGROUND_OFFSET = 10;\n\nconst wrapAnsi16 = (offset = 0) => code => `\\u001B[${code + offset}m`;\n\nconst wrapAnsi256 = (offset = 0) => code => `\\u001B[${38 + offset};5;${code}m`;\n\nconst wrapAnsi16m = (offset = 0) => (red, green, blue) => `\\u001B[${38 + offset};2;${red};${green};${blue}m`;\n\nconst styles = {\n\tmodifier: {\n\t\treset: [0, 0],\n\t\t// 21 isn't widely supported and 22 does the same thing\n\t\tbold: [1, 22],\n\t\tdim: [2, 22],\n\t\titalic: [3, 23],\n\t\tunderline: [4, 24],\n\t\toverline: [53, 55],\n\t\tinverse: [7, 27],\n\t\thidden: [8, 28],\n\t\tstrikethrough: [9, 29],\n\t},\n\tcolor: {\n\t\tblack: [30, 39],\n\t\tred: [31, 39],\n\t\tgreen: [32, 39],\n\t\tyellow: [33, 39],\n\t\tblue: [34, 39],\n\t\tmagenta: [35, 39],\n\t\tcyan: [36, 39],\n\t\twhite: [37, 39],\n\n\t\t// Bright color\n\t\tblackBright: [90, 39],\n\t\tgray: [90, 39], // Alias of `blackBright`\n\t\tgrey: [90, 39], // Alias of `blackBright`\n\t\tredBright: [91, 39],\n\t\tgreenBright: [92, 39],\n\t\tyellowBright: [93, 39],\n\t\tblueBright: [94, 39],\n\t\tmagentaBright: [95, 39],\n\t\tcyanBright: [96, 39],\n\t\twhiteBright: [97, 39],\n\t},\n\tbgColor: {\n\t\tbgBlack: [40, 49],\n\t\tbgRed: [41, 49],\n\t\tbgGreen: [42, 49],\n\t\tbgYellow: [43, 49],\n\t\tbgBlue: [44, 49],\n\t\tbgMagenta: [45, 49],\n\t\tbgCyan: [46, 49],\n\t\tbgWhite: [47, 49],\n\n\t\t// Bright color\n\t\tbgBlackBright: [100, 49],\n\t\tbgGray: [100, 49], // Alias of `bgBlackBright`\n\t\tbgGrey: [100, 49], // Alias of `bgBlackBright`\n\t\tbgRedBright: [101, 49],\n\t\tbgGreenBright: [102, 49],\n\t\tbgYellowBright: [103, 49],\n\t\tbgBlueBright: [104, 49],\n\t\tbgMagentaBright: [105, 49],\n\t\tbgCyanBright: [106, 49],\n\t\tbgWhiteBright: [107, 49],\n\t},\n};\n\nexport const modifierNames = Object.keys(styles.modifier);\nexport const foregroundColorNames = Object.keys(styles.color);\nexport const backgroundColorNames = Object.keys(styles.bgColor);\nexport const colorNames = [...foregroundColorNames, ...backgroundColorNames];\n\nfunction assembleStyles() {\n\tconst codes = new Map();\n\n\tfor (const [groupName, group] of Object.entries(styles)) {\n\t\tfor (const [styleName, style] of Object.entries(group)) {\n\t\t\tstyles[styleName] = {\n\t\t\t\topen: `\\u001B[${style[0]}m`,\n\t\t\t\tclose: `\\u001B[${style[1]}m`,\n\t\t\t};\n\n\t\t\tgroup[styleName] = styles[styleName];\n\n\t\t\tcodes.set(style[0], style[1]);\n\t\t}\n\n\t\tObject.defineProperty(styles, groupName, {\n\t\t\tvalue: group,\n\t\t\tenumerable: false,\n\t\t});\n\t}\n\n\tObject.defineProperty(styles, 'codes', {\n\t\tvalue: codes,\n\t\tenumerable: false,\n\t});\n\n\tstyles.color.close = '\\u001B[39m';\n\tstyles.bgColor.close = '\\u001B[49m';\n\n\tstyles.color.ansi = wrapAnsi16();\n\tstyles.color.ansi256 = wrapAnsi256();\n\tstyles.color.ansi16m = wrapAnsi16m();\n\tstyles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);\n\tstyles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);\n\tstyles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);\n\n\t// From https://github.com/Qix-/color-convert/blob/3f0e0d4e92e235796ccb17f6e85c72094a651f49/conversions.js\n\tObject.defineProperties(styles, {\n\t\trgbToAnsi256: {\n\t\t\tvalue(red, green, blue) {\n\t\t\t\t// We use the extended greyscale palette here, with the exception of\n\t\t\t\t// black and white. normal palette only has 4 greyscale shades.\n\t\t\t\tif (red === green && green === blue) {\n\t\t\t\t\tif (red < 8) {\n\t\t\t\t\t\treturn 16;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (red > 248) {\n\t\t\t\t\t\treturn 231;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn Math.round(((red - 8) / 247) * 24) + 232;\n\t\t\t\t}\n\n\t\t\t\treturn 16\n\t\t\t\t\t+ (36 * Math.round(red / 255 * 5))\n\t\t\t\t\t+ (6 * Math.round(green / 255 * 5))\n\t\t\t\t\t+ Math.round(blue / 255 * 5);\n\t\t\t},\n\t\t\tenumerable: false,\n\t\t},\n\t\thexToRgb: {\n\t\t\tvalue(hex) {\n\t\t\t\tconst matches = /[a-f\\d]{6}|[a-f\\d]{3}/i.exec(hex.toString(16));\n\t\t\t\tif (!matches) {\n\t\t\t\t\treturn [0, 0, 0];\n\t\t\t\t}\n\n\t\t\t\tlet [colorString] = matches;\n\n\t\t\t\tif (colorString.length === 3) {\n\t\t\t\t\tcolorString = [...colorString].map(character => character + character).join('');\n\t\t\t\t}\n\n\t\t\t\tconst integer = Number.parseInt(colorString, 16);\n\n\t\t\t\treturn [\n\t\t\t\t\t/* eslint-disable no-bitwise */\n\t\t\t\t\t(integer >> 16) & 0xFF,\n\t\t\t\t\t(integer >> 8) & 0xFF,\n\t\t\t\t\tinteger & 0xFF,\n\t\t\t\t\t/* eslint-enable no-bitwise */\n\t\t\t\t];\n\t\t\t},\n\t\t\tenumerable: false,\n\t\t},\n\t\thexToAnsi256: {\n\t\t\tvalue: hex => styles.rgbToAnsi256(...styles.hexToRgb(hex)),\n\t\t\tenumerable: false,\n\t\t},\n\t\tansi256ToAnsi: {\n\t\t\tvalue(code) {\n\t\t\t\tif (code < 8) {\n\t\t\t\t\treturn 30 + code;\n\t\t\t\t}\n\n\t\t\t\tif (code < 16) {\n\t\t\t\t\treturn 90 + (code - 8);\n\t\t\t\t}\n\n\t\t\t\tlet red;\n\t\t\t\tlet green;\n\t\t\t\tlet blue;\n\n\t\t\t\tif (code >= 232) {\n\t\t\t\t\tred = (((code - 232) * 10) + 8) / 255;\n\t\t\t\t\tgreen = red;\n\t\t\t\t\tblue = red;\n\t\t\t\t} else {\n\t\t\t\t\tcode -= 16;\n\n\t\t\t\t\tconst remainder = code % 36;\n\n\t\t\t\t\tred = Math.floor(code / 36) / 5;\n\t\t\t\t\tgreen = Math.floor(remainder / 6) / 5;\n\t\t\t\t\tblue = (remainder % 6) / 5;\n\t\t\t\t}\n\n\t\t\t\tconst value = Math.max(red, green, blue) * 2;\n\n\t\t\t\tif (value === 0) {\n\t\t\t\t\treturn 30;\n\t\t\t\t}\n\n\t\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\t\tlet result = 30 + ((Math.round(blue) << 2) | (Math.round(green) << 1) | Math.round(red));\n\n\t\t\t\tif (value === 2) {\n\t\t\t\t\tresult += 60;\n\t\t\t\t}\n\n\t\t\t\treturn result;\n\t\t\t},\n\t\t\tenumerable: false,\n\t\t},\n\t\trgbToAnsi: {\n\t\t\tvalue: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),\n\t\t\tenumerable: false,\n\t\t},\n\t\thexToAnsi: {\n\t\t\tvalue: hex => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),\n\t\t\tenumerable: false,\n\t\t},\n\t});\n\n\treturn styles;\n}\n\nconst ansiStyles = assembleStyles();\n\nexport default ansiStyles;\n","import process from 'node:process';\nimport os from 'node:os';\nimport tty from 'node:tty';\n\n// From: https://github.com/sindresorhus/has-flag/blob/main/index.js\n/// function hasFlag(flag, argv = globalThis.Deno?.args ?? process.argv) {\nfunction hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process.argv) {\n\tconst prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--');\n\tconst position = argv.indexOf(prefix + flag);\n\tconst terminatorPosition = argv.indexOf('--');\n\treturn position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);\n}\n\nconst {env} = process;\n\nlet flagForceColor;\nif (\n\thasFlag('no-color')\n\t|| hasFlag('no-colors')\n\t|| hasFlag('color=false')\n\t|| hasFlag('color=never')\n) {\n\tflagForceColor = 0;\n} else if (\n\thasFlag('color')\n\t|| hasFlag('colors')\n\t|| hasFlag('color=true')\n\t|| hasFlag('color=always')\n) {\n\tflagForceColor = 1;\n}\n\nfunction envForceColor() {\n\tif ('FORCE_COLOR' in env) {\n\t\tif (env.FORCE_COLOR === 'true') {\n\t\t\treturn 1;\n\t\t}\n\n\t\tif (env.FORCE_COLOR === 'false') {\n\t\t\treturn 0;\n\t\t}\n\n\t\treturn env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);\n\t}\n}\n\nfunction translateLevel(level) {\n\tif (level === 0) {\n\t\treturn false;\n\t}\n\n\treturn {\n\t\tlevel,\n\t\thasBasic: true,\n\t\thas256: level >= 2,\n\t\thas16m: level >= 3,\n\t};\n}\n\nfunction _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {\n\tconst noFlagForceColor = envForceColor();\n\tif (noFlagForceColor !== undefined) {\n\t\tflagForceColor = noFlagForceColor;\n\t}\n\n\tconst forceColor = sniffFlags ? flagForceColor : noFlagForceColor;\n\n\tif (forceColor === 0) {\n\t\treturn 0;\n\t}\n\n\tif (sniffFlags) {\n\t\tif (hasFlag('color=16m')\n\t\t\t|| hasFlag('color=full')\n\t\t\t|| hasFlag('color=truecolor')) {\n\t\t\treturn 3;\n\t\t}\n\n\t\tif (hasFlag('color=256')) {\n\t\t\treturn 2;\n\t\t}\n\t}\n\n\t// Check for Azure DevOps pipelines.\n\t// Has to be above the `!streamIsTTY` check.\n\tif ('TF_BUILD' in env && 'AGENT_NAME' in env) {\n\t\treturn 1;\n\t}\n\n\tif (haveStream && !streamIsTTY && forceColor === undefined) {\n\t\treturn 0;\n\t}\n\n\tconst min = forceColor || 0;\n\n\tif (env.TERM === 'dumb') {\n\t\treturn min;\n\t}\n\n\tif (process.platform === 'win32') {\n\t\t// Windows 10 build 10586 is the first Windows release that supports 256 colors.\n\t\t// Windows 10 build 14931 is the first release that supports 16m/TrueColor.\n\t\tconst osRelease = os.release().split('.');\n\t\tif (\n\t\t\tNumber(osRelease[0]) >= 10\n\t\t\t&& Number(osRelease[2]) >= 10_586\n\t\t) {\n\t\t\treturn Number(osRelease[2]) >= 14_931 ? 3 : 2;\n\t\t}\n\n\t\treturn 1;\n\t}\n\n\tif ('CI' in env) {\n\t\tif (['GITHUB_ACTIONS', 'GITEA_ACTIONS', 'CIRCLECI'].some(key => key in env)) {\n\t\t\treturn 3;\n\t\t}\n\n\t\tif (['TRAVIS', 'APPVEYOR', 'GITLAB_CI', 'BUILDKITE', 'DRONE'].some(sign => sign in env) || env.CI_NAME === 'codeship') {\n\t\t\treturn 1;\n\t\t}\n\n\t\treturn min;\n\t}\n\n\tif ('TEAMCITY_VERSION' in env) {\n\t\treturn /^(9\\.(0*[1-9]\\d*)\\.|\\d{2,}\\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;\n\t}\n\n\tif (env.COLORTERM === 'truecolor') {\n\t\treturn 3;\n\t}\n\n\tif (env.TERM === 'xterm-kitty') {\n\t\treturn 3;\n\t}\n\n\tif (env.TERM === 'xterm-ghostty') {\n\t\treturn 3;\n\t}\n\n\tif (env.TERM === 'wezterm') {\n\t\treturn 3;\n\t}\n\n\tif ('TERM_PROGRAM' in env) {\n\t\tconst version = Number.parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);\n\n\t\tswitch (env.TERM_PROGRAM) {\n\t\t\tcase 'iTerm.app': {\n\t\t\t\treturn version >= 3 ? 3 : 2;\n\t\t\t}\n\n\t\t\tcase 'Apple_Terminal': {\n\t\t\t\treturn 2;\n\t\t\t}\n\t\t\t// No default\n\t\t}\n\t}\n\n\tif (/-256(color)?$/i.test(env.TERM)) {\n\t\treturn 2;\n\t}\n\n\tif (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {\n\t\treturn 1;\n\t}\n\n\tif ('COLORTERM' in env) {\n\t\treturn 1;\n\t}\n\n\treturn min;\n}\n\nexport function createSupportsColor(stream, options = {}) {\n\tconst level = _supportsColor(stream, {\n\t\tstreamIsTTY: stream && stream.isTTY,\n\t\t...options,\n\t});\n\n\treturn translateLevel(level);\n}\n\nconst supportsColor = {\n\tstdout: createSupportsColor({isTTY: tty.isatty(1)}),\n\tstderr: createSupportsColor({isTTY: tty.isatty(2)}),\n};\n\nexport default supportsColor;\n","// TODO: When targeting Node.js 16, use `String.prototype.replaceAll`.\nexport function stringReplaceAll(string, substring, replacer) {\n\tlet index = string.indexOf(substring);\n\tif (index === -1) {\n\t\treturn string;\n\t}\n\n\tconst substringLength = substring.length;\n\tlet endIndex = 0;\n\tlet returnValue = '';\n\tdo {\n\t\treturnValue += string.slice(endIndex, index) + substring + replacer;\n\t\tendIndex = index + substringLength;\n\t\tindex = string.indexOf(substring, endIndex);\n\t} while (index !== -1);\n\n\treturnValue += string.slice(endIndex);\n\treturn returnValue;\n}\n\nexport function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {\n\tlet endIndex = 0;\n\tlet returnValue = '';\n\tdo {\n\t\tconst gotCR = string[index - 1] === '\\r';\n\t\treturnValue += string.slice(endIndex, (gotCR ? index - 1 : index)) + prefix + (gotCR ? '\\r\\n' : '\\n') + postfix;\n\t\tendIndex = index + 1;\n\t\tindex = string.indexOf('\\n', endIndex);\n\t} while (index !== -1);\n\n\treturnValue += string.slice(endIndex);\n\treturn returnValue;\n}\n","import ansiStyles from '#ansi-styles';\nimport supportsColor from '#supports-color';\nimport { // eslint-disable-line import/order\n\tstringReplaceAll,\n\tstringEncaseCRLFWithFirstIndex,\n} from './utilities.js';\n\nconst {stdout: stdoutColor, stderr: stderrColor} = supportsColor;\n\nconst GENERATOR = Symbol('GENERATOR');\nconst STYLER = Symbol('STYLER');\nconst IS_EMPTY = Symbol('IS_EMPTY');\n\n// `supportsColor.level` → `ansiStyles.color[name]` mapping\nconst levelMapping = [\n\t'ansi',\n\t'ansi',\n\t'ansi256',\n\t'ansi16m',\n];\n\nconst styles = Object.create(null);\n\nconst applyOptions = (object, options = {}) => {\n\tif (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {\n\t\tthrow new Error('The `level` option should be an integer from 0 to 3');\n\t}\n\n\t// Detect level if not set manually\n\tconst colorLevel = stdoutColor ? stdoutColor.level : 0;\n\tobject.level = options.level === undefined ? colorLevel : options.level;\n};\n\nexport class Chalk {\n\tconstructor(options) {\n\t\t// eslint-disable-next-line no-constructor-return\n\t\treturn chalkFactory(options);\n\t}\n}\n\nconst chalkFactory = options => {\n\tconst chalk = (...strings) => strings.join(' ');\n\tapplyOptions(chalk, options);\n\n\tObject.setPrototypeOf(chalk, createChalk.prototype);\n\n\treturn chalk;\n};\n\nfunction createChalk(options) {\n\treturn chalkFactory(options);\n}\n\nObject.setPrototypeOf(createChalk.prototype, Function.prototype);\n\nfor (const [styleName, style] of Object.entries(ansiStyles)) {\n\tstyles[styleName] = {\n\t\tget() {\n\t\t\tconst builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);\n\t\t\tObject.defineProperty(this, styleName, {value: builder});\n\t\t\treturn builder;\n\t\t},\n\t};\n}\n\nstyles.visible = {\n\tget() {\n\t\tconst builder = createBuilder(this, this[STYLER], true);\n\t\tObject.defineProperty(this, 'visible', {value: builder});\n\t\treturn builder;\n\t},\n};\n\nconst getModelAnsi = (model, level, type, ...arguments_) => {\n\tif (model === 'rgb') {\n\t\tif (level === 'ansi16m') {\n\t\t\treturn ansiStyles[type].ansi16m(...arguments_);\n\t\t}\n\n\t\tif (level === 'ansi256') {\n\t\t\treturn ansiStyles[type].ansi256(ansiStyles.rgbToAnsi256(...arguments_));\n\t\t}\n\n\t\treturn ansiStyles[type].ansi(ansiStyles.rgbToAnsi(...arguments_));\n\t}\n\n\tif (model === 'hex') {\n\t\treturn getModelAnsi('rgb', level, type, ...ansiStyles.hexToRgb(...arguments_));\n\t}\n\n\treturn ansiStyles[type][model](...arguments_);\n};\n\nconst usedModels = ['rgb', 'hex', 'ansi256'];\n\nfor (const model of usedModels) {\n\tstyles[model] = {\n\t\tget() {\n\t\t\tconst {level} = this;\n\t\t\treturn function (...arguments_) {\n\t\t\t\tconst styler = createStyler(getModelAnsi(model, levelMapping[level], 'color', ...arguments_), ansiStyles.color.close, this[STYLER]);\n\t\t\t\treturn createBuilder(this, styler, this[IS_EMPTY]);\n\t\t\t};\n\t\t},\n\t};\n\n\tconst bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);\n\tstyles[bgModel] = {\n\t\tget() {\n\t\t\tconst {level} = this;\n\t\t\treturn function (...arguments_) {\n\t\t\t\tconst styler = createStyler(getModelAnsi(model, levelMapping[level], 'bgColor', ...arguments_), ansiStyles.bgColor.close, this[STYLER]);\n\t\t\t\treturn createBuilder(this, styler, this[IS_EMPTY]);\n\t\t\t};\n\t\t},\n\t};\n}\n\nconst proto = Object.defineProperties(() => {}, {\n\t...styles,\n\tlevel: {\n\t\tenumerable: true,\n\t\tget() {\n\t\t\treturn this[GENERATOR].level;\n\t\t},\n\t\tset(level) {\n\t\t\tthis[GENERATOR].level = level;\n\t\t},\n\t},\n});\n\nconst createStyler = (open, close, parent) => {\n\tlet openAll;\n\tlet closeAll;\n\tif (parent === undefined) {\n\t\topenAll = open;\n\t\tcloseAll = close;\n\t} else {\n\t\topenAll = parent.openAll + open;\n\t\tcloseAll = close + parent.closeAll;\n\t}\n\n\treturn {\n\t\topen,\n\t\tclose,\n\t\topenAll,\n\t\tcloseAll,\n\t\tparent,\n\t};\n};\n\nconst createBuilder = (self, _styler, _isEmpty) => {\n\t// Single argument is hot path, implicit coercion is faster than anything\n\t// eslint-disable-next-line no-implicit-coercion\n\tconst builder = (...arguments_) => applyStyle(builder, (arguments_.length === 1) ? ('' + arguments_[0]) : arguments_.join(' '));\n\n\t// We alter the prototype because we must return a function, but there is\n\t// no way to create a function with a different prototype\n\tObject.setPrototypeOf(builder, proto);\n\n\tbuilder[GENERATOR] = self;\n\tbuilder[STYLER] = _styler;\n\tbuilder[IS_EMPTY] = _isEmpty;\n\n\treturn builder;\n};\n\nconst applyStyle = (self, string) => {\n\tif (self.level <= 0 || !string) {\n\t\treturn self[IS_EMPTY] ? '' : string;\n\t}\n\n\tlet styler = self[STYLER];\n\n\tif (styler === undefined) {\n\t\treturn string;\n\t}\n\n\tconst {openAll, closeAll} = styler;\n\tif (string.includes('\\u001B')) {\n\t\twhile (styler !== undefined) {\n\t\t\t// Replace any instances already present with a re-opening code\n\t\t\t// otherwise only the part of the string until said closing code\n\t\t\t// will be colored, and the rest will simply be 'plain'.\n\t\t\tstring = stringReplaceAll(string, styler.close, styler.open);\n\n\t\t\tstyler = styler.parent;\n\t\t}\n\t}\n\n\t// We can move both next actions out of loop, because remaining actions in loop won't have\n\t// any/visible effect on parts we add here. Close the styling before a linebreak and reopen\n\t// after next line to fix a bleed issue on macOS: https://github.com/chalk/chalk/pull/92\n\tconst lfIndex = string.indexOf('\\n');\n\tif (lfIndex !== -1) {\n\t\tstring = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);\n\t}\n\n\treturn openAll + string + closeAll;\n};\n\nObject.defineProperties(createChalk.prototype, styles);\n\nconst chalk = createChalk();\nexport const chalkStderr = createChalk({level: stderrColor ? stderrColor.level : 0});\n\nexport {\n\tmodifierNames,\n\tforegroundColorNames,\n\tbackgroundColorNames,\n\tcolorNames,\n\n\t// TODO: Remove these aliases in the next major version\n\tmodifierNames as modifiers,\n\tforegroundColorNames as foregroundColors,\n\tbackgroundColorNames as backgroundColors,\n\tcolorNames as colors,\n} from './vendor/ansi-styles/index.js';\n\nexport {\n\tstdoutColor as supportsColor,\n\tstderrColor as supportsColorStderr,\n};\n\nexport default chalk;\n"],"x_google_ignoreList":[3,4,5,6],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+FA,IAAa,wBAAb,cAA2C,MAAM;CAC7C;CACA;CAEA,YAAY,gBAAwB,UAAkB,SAAiB;EACnE,MAAM,GAAG,eAAe,WAAW,SAAS,KAAK,SAAS;EAC1D,KAAK,OAAO;EACZ,KAAK,iBAAiB;EACtB,KAAK,WAAW;CACpB;AACJ;;;;;AASA,IAAM,oBAAoB;;;;;;;;;;;;;;;;AAiB1B,IAAa,qBAAqB,SAA0B,0BAA0B,KAAK,IAAI;AAE/F,IAAM,mBAAmB,WAAiC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B;CAMD,MAAM,UAAU,OAAO,QAAQ,IAAI;CACnC,IAAI,YAAY,IACf,SAAS,+BAA+B,QAAQ,UAAU,SAAS,OAAO;CAG3E,OAAO,UAAU,SAAS;AAC3B;AAEA,OAAO,iBAAiB,YAAY,WAAW,MAAM;AAErD,IAAM,QAAQ,YAAY;AACC,YAAY,EAAC,OAAO,cAAc,YAAY,QAAQ,EAAC,CAAC"}
|
|
@@ -2,9 +2,9 @@ import { createRequire as __createRequire } from "module";
|
|
|
2
2
|
__createRequire(import.meta.url);
|
|
3
3
|
import { sql } from "drizzle-orm";
|
|
4
4
|
import { revokeInternalTableSql } from "@rebasepro/common";
|
|
5
|
-
//#region src/schema/
|
|
5
|
+
//#region src/schema/tables-schema-version.ts
|
|
6
6
|
/**
|
|
7
|
-
* The
|
|
7
|
+
* The schema version, stamped into the database.
|
|
8
8
|
*
|
|
9
9
|
* Deliberately the same table shape, the same key/value convention and the same
|
|
10
10
|
* "unstamped is null, and null is not an error" rule as `auth/schema-version.ts`.
|
|
@@ -32,6 +32,12 @@ import { revokeInternalTableSql } from "@rebasepro/common";
|
|
|
32
32
|
* deliberate limit, and the reason the runtime's response to a mismatch is to
|
|
33
33
|
* describe it rather than to decide who is wrong.
|
|
34
34
|
*/
|
|
35
|
+
/**
|
|
36
|
+
* The schema the meta table lives in: the runtime's own, `rebase`, whatever
|
|
37
|
+
* schema the tables are in. Shared by the boot (through the bootstrapper),
|
|
38
|
+
* `rebase db push` and the doctor, so all three read and write one row.
|
|
39
|
+
*/
|
|
40
|
+
var SCHEMA_META_SCHEMA = "rebase";
|
|
35
41
|
/** Key under which the version is stored in the meta table. */
|
|
36
42
|
var VERSION_KEY = "collections_schema_version";
|
|
37
43
|
/**
|
|
@@ -41,7 +47,7 @@ var VERSION_KEY = "collections_schema_version";
|
|
|
41
47
|
* `null` instead of a thrown 42P01 — the overwhelmingly common case on a fresh
|
|
42
48
|
* database is that neither exists yet, and that is not news.
|
|
43
49
|
*/
|
|
44
|
-
async function
|
|
50
|
+
async function readTablesSchemaVersion(db, metaSchema) {
|
|
45
51
|
const qualified = `"${metaSchema}"."schema_meta"`;
|
|
46
52
|
if (!(await db.execute(sql`SELECT to_regclass(${qualified}) IS NOT NULL AS present`)).rows[0]?.present) return null;
|
|
47
53
|
const raw = (await db.execute(sql`
|
|
@@ -59,7 +65,7 @@ async function readCollectionsSchemaVersion(db, metaSchema) {
|
|
|
59
65
|
* arranges; it is tolerated here for the same reason it is elsewhere in the boot
|
|
60
66
|
* path, and the caller treats any failure as a warning rather than a fatal.
|
|
61
67
|
*/
|
|
62
|
-
async function
|
|
68
|
+
async function stampTablesSchemaVersion(db, metaSchema, version) {
|
|
63
69
|
const qualified = `"${metaSchema}"."schema_meta"`;
|
|
64
70
|
if (!(await db.execute(sql`SELECT to_regclass(${qualified}) IS NOT NULL AS present`)).rows[0]?.present) {
|
|
65
71
|
await db.execute(sql`CREATE SCHEMA IF NOT EXISTS ${sql.identifier(metaSchema)}`);
|
|
@@ -79,6 +85,6 @@ async function stampCollectionsSchemaVersion(db, metaSchema, version) {
|
|
|
79
85
|
`);
|
|
80
86
|
}
|
|
81
87
|
//#endregion
|
|
82
|
-
export {
|
|
88
|
+
export { SCHEMA_META_SCHEMA, readTablesSchemaVersion, stampTablesSchemaVersion };
|
|
83
89
|
|
|
84
|
-
//# sourceMappingURL=
|
|
90
|
+
//# sourceMappingURL=tables-schema-version-YvZIBlOP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tables-schema-version-YvZIBlOP.js","names":[],"sources":["../src/schema/tables-schema-version.ts"],"sourcesContent":["/**\n * The schema version, stamped into the database.\n *\n * Deliberately the same table shape, the same key/value convention and the same\n * \"unstamped is null, and null is not an error\" rule as `auth/schema-version.ts`.\n * They answer the same kind of question — \"was this database provisioned by\n * something that agrees with me\" — and inventing a second convention for the\n * second one would be a second thing to find, back up and reason about.\n *\n * It does *not* follow the auth stamp's schema. `resolveAuthSchema` tracks the\n * users collection, so a project that puts its users in a custom schema moves\n * the auth stamp with them — correct there, because that stamp describes those\n * tables. This one describes the collections as a whole and belongs with the\n * runtime's own internal state, which is always `rebase`. Usually they land in\n * the same table anyway; when they do not, that is the reason.\n *\n * The value is opaque here on purpose. It is a hash produced by\n * `computeSchemaVersion` in `@rebasepro/types`, and this module's only job is to\n * put a string in and take the same string out. Comparing them, and deciding\n * what a difference means, is `boot/schema-stamp.ts` in the runtime — where it\n * can be tested without a database.\n *\n * Unlike the auth version, this is **not** ordered. The auth stamp is an integer\n * whose comparison direction carries meaning (a database newer than the runtime\n * is unrecoverable, older is the ordinary upgrade path). A schema hash has no\n * order at all: it can say the two disagree and never which is ahead. That is a\n * deliberate limit, and the reason the runtime's response to a mismatch is to\n * describe it rather than to decide who is wrong.\n */\nimport { sql } from \"drizzle-orm\";\nimport type { NodePgDatabase } from \"drizzle-orm/node-postgres\";\nimport { revokeInternalTableSql } from \"@rebasepro/common\";\n\n/**\n * The schema the meta table lives in: the runtime's own, `rebase`, whatever\n * schema the tables are in. Shared by the boot (through the bootstrapper),\n * `rebase db push` and the doctor, so all three read and write one row.\n */\nexport const SCHEMA_META_SCHEMA = \"rebase\";\n\n/** Key under which the version is stored in the meta table. */\nconst VERSION_KEY = \"collections_schema_version\";\n\n/**\n * Anything that can run SQL for us.\n *\n * Narrower than `NodePgDatabase` so the provisioning handle — which is what the\n * boot path actually has in hand — satisfies it without a cast at every call\n * site.\n */\nexport interface SchemaMetaQueryable {\n execute(query: unknown): Promise<{ rows: Record<string, unknown>[] }>;\n}\n\n/**\n * Read the stamped version, or `null` when this database has never been stamped.\n *\n * `to_regclass` rather than a plain `SELECT` so a missing schema or table is a\n * `null` instead of a thrown 42P01 — the overwhelmingly common case on a fresh\n * database is that neither exists yet, and that is not news.\n */\nexport async function readTablesSchemaVersion(\n db: SchemaMetaQueryable | NodePgDatabase,\n metaSchema: string\n): Promise<string | null> {\n const qualified = `\"${metaSchema}\".\"schema_meta\"`;\n const exists = await (db as SchemaMetaQueryable).execute(\n sql`SELECT to_regclass(${qualified}) IS NOT NULL AS present`\n );\n if (!(exists.rows[0] as { present: boolean } | undefined)?.present) return null;\n\n const result = await (db as SchemaMetaQueryable).execute(sql`\n SELECT value FROM ${sql.raw(qualified)} WHERE key = ${VERSION_KEY}\n `);\n const raw = (result.rows[0] as { value: string } | undefined)?.value;\n\n // An empty string is not a version anybody computed, and treating it as one\n // would make every process disagree with the database forever. Unstamped.\n return raw === undefined || raw.trim() === \"\" ? null : raw;\n}\n\n/**\n * Record the version this runtime just applied.\n *\n * Creates the meta table if the auth stamp has not already — the two are\n * independent halves of one boot and either may run first, so neither can assume\n * the table is there. `CREATE TABLE IF NOT EXISTS` is not atomic against a\n * concurrent identical statement, which is exactly the race a split deployment\n * arranges; it is tolerated here for the same reason it is elsewhere in the boot\n * path, and the caller treats any failure as a warning rather than a fatal.\n */\nexport async function stampTablesSchemaVersion(\n db: SchemaMetaQueryable | NodePgDatabase,\n metaSchema: string,\n version: string\n): Promise<void> {\n const qualified = `\"${metaSchema}\".\"schema_meta\"`;\n const exists = await (db as SchemaMetaQueryable).execute(\n sql`SELECT to_regclass(${qualified}) IS NOT NULL AS present`\n );\n if (!(exists.rows[0] as { present: boolean } | undefined)?.present) {\n await (db as SchemaMetaQueryable).execute(sql`CREATE SCHEMA IF NOT EXISTS ${sql.identifier(metaSchema)}`);\n await (db as SchemaMetaQueryable).execute(sql`\n CREATE TABLE IF NOT EXISTS ${sql.raw(qualified)} (\n key TEXT PRIMARY KEY,\n value TEXT NOT NULL,\n updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL\n )\n `);\n // On a backend without auth this stamp is what creates the table, and\n // it runs after the boot's last sweep of the request role's grants —\n // so the table inherited the schema-wide DML grant until the next\n // boot's sweep took it back. A request role that can rewrite the auth\n // version stamp can make that boot refuse. Taken back here, by its\n // creator, as every other internal table is.\n await (db as SchemaMetaQueryable).execute(sql.raw(revokeInternalTableSql(metaSchema, \"schema_meta\")));\n }\n await (db as SchemaMetaQueryable).execute(sql`\n INSERT INTO ${sql.raw(qualified)} (key, value)\n VALUES (${VERSION_KEY}, ${version})\n ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value, updated_at = NOW()\n `);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,IAAa,qBAAqB;;AAGlC,IAAM,cAAc;;;;;;;;AAoBpB,eAAsB,wBAClB,IACA,YACsB;CACtB,MAAM,YAAY,IAAI,WAAW;CAIjC,IAAI,EAAE,MAHgB,GAA2B,QAC7C,GAAG,sBAAsB,UAAU,yBACvC,EAAA,CACa,KAAK,EAAE,EAAuC,SAAS,OAAO;CAK3E,MAAM,OAAO,MAHS,GAA2B,QAAQ,GAAG;4BACpC,IAAI,IAAI,SAAS,EAAE,eAAe,YAAY;KACrE,EAAA,CACmB,KAAK,EAAE,EAAoC;CAI/D,OAAO,QAAQ,KAAA,KAAa,IAAI,KAAK,MAAM,KAAK,OAAO;AAC3D;;;;;;;;;;;AAYA,eAAsB,yBAClB,IACA,YACA,SACa;CACb,MAAM,YAAY,IAAI,WAAW;CAIjC,IAAI,EAAE,MAHgB,GAA2B,QAC7C,GAAG,sBAAsB,UAAU,yBACvC,EAAA,CACa,KAAK,EAAE,EAAuC,SAAS;EAChE,MAAO,GAA2B,QAAQ,GAAG,+BAA+B,IAAI,WAAW,UAAU,GAAG;EACxG,MAAO,GAA2B,QAAQ,GAAG;yCACZ,IAAI,IAAI,SAAS,EAAE;;;;;SAKnD;EAOD,MAAO,GAA2B,QAAQ,IAAI,IAAI,uBAAuB,YAAY,aAAa,CAAC,CAAC;CACxG;CACA,MAAO,GAA2B,QAAQ,GAAG;sBAC3B,IAAI,IAAI,SAAS,EAAE;kBACvB,YAAY,IAAI,QAAQ;;KAErC;AACL"}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { SQL } from "drizzle-orm";
|
|
2
2
|
import { AnyPgColumn, PgTable } from "drizzle-orm/pg-core";
|
|
3
|
-
import {
|
|
3
|
+
import { FilterValues, WhereFilterOp, LogicalCondition, FilterCondition, type RelationDescriptor, type RelationAggregateSort } from "@rebasepro/types";
|
|
4
|
+
import { type RelationOfKind } from "@rebasepro/common";
|
|
4
5
|
import { type SearchColumnSpec } from "../schema/search-column.js";
|
|
5
|
-
import {
|
|
6
|
+
import type { TableDescriptor } from "@rebasepro/types";
|
|
7
|
+
import { PostgresTableRegistry } from "../model/PostgresTableRegistry.js";
|
|
8
|
+
import { type PointsBackRelation } from "../services/relation-tables.js";
|
|
9
|
+
import type { RuntimeTable } from "../model/runtime-table.js";
|
|
6
10
|
/**
|
|
7
11
|
* What to do with a filter field that resolves to no column at all.
|
|
8
12
|
*
|
|
@@ -17,15 +21,17 @@ import { PostgresCollectionRegistry } from "../collections/PostgresCollectionReg
|
|
|
17
21
|
*/
|
|
18
22
|
export type UnknownFilterFieldsMode = "error" | "warn";
|
|
19
23
|
/**
|
|
20
|
-
* The
|
|
21
|
-
* one, for any caller: the list is a hint for a typo, and
|
|
22
|
-
* column there answers the question the unknown-field answer
|
|
24
|
+
* The column keys an unknown-field answer lists, sorted — never a private
|
|
25
|
+
* (`.private()`) one, for any caller: the list is a hint for a typo, and
|
|
26
|
+
* naming a hidden column there answers the question the unknown-field answer
|
|
27
|
+
* leaves open.
|
|
23
28
|
*
|
|
24
|
-
* Read off the
|
|
25
|
-
* uses to answer a query on a
|
|
26
|
-
* the same bytes. Off the table only
|
|
29
|
+
* Read off the table descriptor when there is one, with the function the REST
|
|
30
|
+
* check uses to answer a query on a private column (`queryableColumnKeys`) —
|
|
31
|
+
* so its answer and this one are the same bytes. Off the catalogue table only
|
|
32
|
+
* when no descriptor is in hand (a bare builder call, which declares no rule).
|
|
27
33
|
*/
|
|
28
|
-
export declare function listedColumnKeys(table: PgTable<any>,
|
|
34
|
+
export declare function listedColumnKeys(table: PgTable<any>, described: TableDescriptor | undefined): string[];
|
|
29
35
|
/**
|
|
30
36
|
* A user's search term, made safe to drop inside a `%…%` LIKE pattern.
|
|
31
37
|
*
|
|
@@ -44,9 +50,8 @@ export declare function listedColumnKeys(table: PgTable<any>, collection: Collec
|
|
|
44
50
|
* the page limit does not bound it because the scan happens first.
|
|
45
51
|
*
|
|
46
52
|
* This is the server-side half of the pattern `like-pattern-redos.test.ts`
|
|
47
|
-
* hardened the offline evaluator against
|
|
48
|
-
*
|
|
49
|
-
* it occupies a server thread instead") describes this call site.
|
|
53
|
+
* hardened the offline evaluator against: here the expression reaches the
|
|
54
|
+
* database, where it occupies a server process instead of a browser tab.
|
|
50
55
|
*
|
|
51
56
|
* Backslash is the default `ESCAPE` character for LIKE, and the pattern is
|
|
52
57
|
* bound rather than interpolated, so a single backslash here reaches the
|
|
@@ -70,6 +75,10 @@ export declare const escapeLikePattern: (value: string) => string;
|
|
|
70
75
|
* many-to-many was unaffected.
|
|
71
76
|
*/
|
|
72
77
|
export declare function joinColumn(table: PgTable<any>, name: string): AnyPgColumn | undefined;
|
|
78
|
+
/** A relation a filter, sort or count can correlate a subquery through: every kind but `via`. */
|
|
79
|
+
type CorrelatedRelation = Exclude<RelationDescriptor, {
|
|
80
|
+
kind: "via";
|
|
81
|
+
}>;
|
|
73
82
|
/** Set the process-wide behaviour for unresolvable filter fields. */
|
|
74
83
|
export declare function configureUnknownFilterFields(mode: UnknownFilterFieldsMode): void;
|
|
75
84
|
/** The process-wide behaviour for unresolvable filter fields. */
|
|
@@ -81,18 +90,18 @@ export interface FilterCompilationOptions {
|
|
|
81
90
|
*/
|
|
82
91
|
unknownFields?: UnknownFilterFieldsMode;
|
|
83
92
|
/**
|
|
84
|
-
* The
|
|
85
|
-
*
|
|
86
|
-
*
|
|
93
|
+
* The table the filter is written against. Its relations are what turn an
|
|
94
|
+
* owning-relation filter key into the foreign-key column it actually lives
|
|
95
|
+
* in; without it only the default key shapes can be guessed.
|
|
87
96
|
*/
|
|
88
|
-
|
|
97
|
+
owner?: RuntimeTable;
|
|
89
98
|
/**
|
|
90
99
|
* The driver's registry, for relations whose link is not on this row at
|
|
91
100
|
* all. A `manyToMany` compiles to an `EXISTS` over its junction and a
|
|
92
101
|
* `hasMany`/`hasOne` to one over the target table — neither of which this
|
|
93
102
|
* builder can reach from the collection alone.
|
|
94
103
|
*/
|
|
95
|
-
registry?:
|
|
104
|
+
registry?: PostgresTableRegistry;
|
|
96
105
|
/**
|
|
97
106
|
* The key column of the table being filtered — what those `EXISTS`
|
|
98
107
|
* subqueries correlate back to.
|
|
@@ -130,9 +139,9 @@ type FilterTarget = {
|
|
|
130
139
|
path: string[];
|
|
131
140
|
} | {
|
|
132
141
|
kind: "relation";
|
|
133
|
-
relation:
|
|
142
|
+
relation: PointsBackRelation | RelationOfKind<"manyToMany">;
|
|
134
143
|
/** Bound here so the compile step cannot be reached without them. */
|
|
135
|
-
registry:
|
|
144
|
+
registry: PostgresTableRegistry;
|
|
136
145
|
sourceIdColumn: AnyPgColumn;
|
|
137
146
|
} | {
|
|
138
147
|
/**
|
|
@@ -146,8 +155,8 @@ type FilterTarget = {
|
|
|
146
155
|
* in the type would let a later edit reach the compile step with a
|
|
147
156
|
* relation there is no correlation for.
|
|
148
157
|
*/
|
|
149
|
-
relation:
|
|
150
|
-
registry:
|
|
158
|
+
relation: CorrelatedRelation;
|
|
159
|
+
registry: PostgresTableRegistry;
|
|
151
160
|
/** The column on *this* table the subquery correlates back to. */
|
|
152
161
|
sourceIdColumn: AnyPgColumn;
|
|
153
162
|
/** The table the predicate is asked of, already resolved. */
|
|
@@ -161,15 +170,6 @@ export interface DrizzleDynamicQuery {
|
|
|
161
170
|
where(condition: SQL | undefined): this;
|
|
162
171
|
limit(limit: number): this;
|
|
163
172
|
}
|
|
164
|
-
/**
|
|
165
|
-
* Unified condition builder for Drizzle/PostgreSQL queries.
|
|
166
|
-
*
|
|
167
|
-
* This class uses static methods and satisfies the ConditionBuilderStatic<SQL> type.
|
|
168
|
-
* It translates Rebase filter conditions to Drizzle SQL conditions.
|
|
169
|
-
*
|
|
170
|
-
* @example
|
|
171
|
-
* const builder: ConditionBuilderStatic<SQL> = DrizzleConditionBuilder;
|
|
172
|
-
*/
|
|
173
173
|
export declare class DrizzleConditionBuilder {
|
|
174
174
|
/**
|
|
175
175
|
* Express "reachable from this parent through this relation" as a plain
|
|
@@ -188,10 +188,10 @@ export declare class DrizzleConditionBuilder {
|
|
|
188
188
|
* - `through` → `EXISTS (SELECT 1 FROM junction …)`, correlated on the
|
|
189
189
|
* target's key, so the junction never multiplies rows the
|
|
190
190
|
* way an `INNER JOIN` would.
|
|
191
|
-
* - `
|
|
191
|
+
* - `via` → the same `EXISTS`, with the chain's steps joined inside
|
|
192
192
|
* it and the final step correlating to the outer row.
|
|
193
193
|
*/
|
|
194
|
-
static buildRelationScopeCondition(relation:
|
|
194
|
+
static buildRelationScopeCondition(relation: RelationDescriptor,
|
|
195
195
|
/**
|
|
196
196
|
* Lazy: `via`, `belongsTo`, and a foreign key that points at a
|
|
197
197
|
* `sourceKey` need the parent's own table. A junction and a plain
|
|
@@ -215,9 +215,9 @@ export declare class DrizzleConditionBuilder {
|
|
|
215
215
|
* parent. One column, so it reaches a single-column key only —
|
|
216
216
|
* `findRelationDefects` refuses those links into a composite one.
|
|
217
217
|
*/
|
|
218
|
-
parentId: string | number, targetTable: PgTable<any>, targetIdColumn: AnyPgColumn, registry:
|
|
218
|
+
parentId: string | number, targetTable: PgTable<any>, targetIdColumn: AnyPgColumn, registry: PostgresTableRegistry): SQL;
|
|
219
219
|
/**
|
|
220
|
-
* `EXISTS` for
|
|
220
|
+
* `EXISTS` for a `via` relation's steps.
|
|
221
221
|
*
|
|
222
222
|
* The path is declared source → target. The subquery replays every step but
|
|
223
223
|
* the last from inside, and turns the last one into the correlation with the
|
|
@@ -254,8 +254,8 @@ export declare class DrizzleConditionBuilder {
|
|
|
254
254
|
private static resolveFilterTarget;
|
|
255
255
|
/**
|
|
256
256
|
* The answer to a filter field that names nothing. Built by the function
|
|
257
|
-
* the REST check answers
|
|
258
|
-
*
|
|
257
|
+
* the REST check answers a private column with, so the two cannot be told
|
|
258
|
+
* apart by a byte.
|
|
259
259
|
*/
|
|
260
260
|
private static unknownFilterField;
|
|
261
261
|
/**
|
|
@@ -349,7 +349,7 @@ export declare class DrizzleConditionBuilder {
|
|
|
349
349
|
* (`categories.children`, or a many-to-many whose junction and target are
|
|
350
350
|
* the same table), where the subquery's table and the outer one coincide.
|
|
351
351
|
*/
|
|
352
|
-
static buildRelationFilterCondition(relation:
|
|
352
|
+
static buildRelationFilterCondition(relation: PointsBackRelation | RelationOfKind<"manyToMany">, op: WhereFilterOp, value: unknown, sourceIdColumn: AnyPgColumn, registry: PostgresTableRegistry, field: string, collectionPath: string): SQL;
|
|
353
353
|
/**
|
|
354
354
|
* The inner predicate of a relation filter, and whether the `EXISTS`
|
|
355
355
|
* wrapping it is negated.
|
|
@@ -496,7 +496,7 @@ export declare class DrizzleConditionBuilder {
|
|
|
496
496
|
* cannot see does not contribute — an aggregate is over the rows that
|
|
497
497
|
* reader can see, which is the only total it could honestly report.
|
|
498
498
|
*/
|
|
499
|
-
static buildRelationAggregateExpression(spec: RelationAggregateSort, table: PgTable<any>,
|
|
499
|
+
static buildRelationAggregateExpression(spec: RelationAggregateSort, table: PgTable<any>, ownerTable: RuntimeTable, registry: PostgresTableRegistry, sourceIdColumn: AnyPgColumn, collectionPath: string, correlateTo?: unknown): SQL;
|
|
500
500
|
/** The column a table's rows are keyed by: its primary key, else `id`. */
|
|
501
501
|
private static primaryKeyColumn;
|
|
502
502
|
/**
|
|
@@ -520,36 +520,13 @@ export declare class DrizzleConditionBuilder {
|
|
|
520
520
|
* side's point of view — so the second was a distinction without a
|
|
521
521
|
* difference and one of the places the two could drift apart.
|
|
522
522
|
*/
|
|
523
|
-
static buildRelationConditions(relation:
|
|
523
|
+
static buildRelationConditions(relation: RelationDescriptor, parentId: string | number | (string | number)[], targetTable: PgTable<any>, parentTable: PgTable<any>, parentIdColumn: AnyPgColumn, targetIdColumn: AnyPgColumn, registry: PostgresTableRegistry): {
|
|
524
524
|
joinConditions: {
|
|
525
525
|
table: PgTable<any>;
|
|
526
526
|
condition: SQL;
|
|
527
527
|
}[];
|
|
528
528
|
whereConditions: SQL[];
|
|
529
529
|
};
|
|
530
|
-
/**
|
|
531
|
-
* Build conditions for join path relations
|
|
532
|
-
*/
|
|
533
|
-
private static buildJoinPathConditions;
|
|
534
|
-
/**
|
|
535
|
-
* One step of a join path walked target → parent: the table it brings in
|
|
536
|
-
* and the condition it joins on.
|
|
537
|
-
*
|
|
538
|
-
* A step listing alternatives joins on any of them, OR-ed. Each alternative
|
|
539
|
-
* is built the way a plain step is, and they must all bring in the same
|
|
540
|
-
* table — they are several ways to match one pair of tables, not several
|
|
541
|
-
* paths. The junction fallback is only tried for a plain step: guessing a
|
|
542
|
-
* junction for one alternative of several is guessing twice.
|
|
543
|
-
*/
|
|
544
|
-
private static buildReverseJoinStep;
|
|
545
|
-
/**
|
|
546
|
-
* Build a single join condition between tables
|
|
547
|
-
*/
|
|
548
|
-
private static buildSingleJoinCondition;
|
|
549
|
-
/**
|
|
550
|
-
* Try to build a junction table join when direct foreign key relationship is not found
|
|
551
|
-
*/
|
|
552
|
-
private static tryBuildJunctionJoin;
|
|
553
530
|
/**
|
|
554
531
|
* Build conditions for junction table (many-to-many) relations
|
|
555
532
|
*/
|
|
@@ -580,8 +557,10 @@ export declare class DrizzleConditionBuilder {
|
|
|
580
557
|
* - **Declared** — one `@@ websearch_to_tsquery` against the generated
|
|
581
558
|
* `tsvector` column. Stems, drops stopwords, AND-es the terms, reaches
|
|
582
559
|
* inside JSONB and arrays, and uses the GIN index.
|
|
583
|
-
* - **Not declared** — `ILIKE '%term%'` per term, OR-ed across
|
|
584
|
-
*
|
|
560
|
+
* - **Not declared** — `ILIKE '%term%'` per term, OR-ed across the
|
|
561
|
+
* table's text columns the caller may read (see `isIlikeSearchable`:
|
|
562
|
+
* `text`/`varchar`/`char`, never an enum, a uuid or a text `.oneOf()`)
|
|
563
|
+
* and AND-ed across the terms, with each term escaped
|
|
585
564
|
* (see {@link escapeLikePattern}) so it is matched as the literal text
|
|
586
565
|
* the user typed.
|
|
587
566
|
*
|
|
@@ -595,11 +574,11 @@ export declare class DrizzleConditionBuilder {
|
|
|
595
574
|
* Returns at most one condition. Every caller ORs what it gets back, which
|
|
596
575
|
* is right across columns and wrong across terms, so the AND is built here.
|
|
597
576
|
*
|
|
598
|
-
* `
|
|
599
|
-
*
|
|
600
|
-
*
|
|
577
|
+
* `described` is the searched table's descriptor: its `search` block and
|
|
578
|
+
* its columns' types and access rules are read from it, `table` is the
|
|
579
|
+
* catalogue table the columns are found on (by column key).
|
|
601
580
|
*/
|
|
602
|
-
static buildSearchConditions(searchString: string,
|
|
581
|
+
static buildSearchConditions(searchString: string, table: PgTable<any>, described: TableDescriptor): SQL[];
|
|
603
582
|
/**
|
|
604
583
|
* The `@@` predicate for a collection that declared a `search` block, or
|
|
605
584
|
* undefined for one that did not.
|
|
@@ -614,7 +593,7 @@ export declare class DrizzleConditionBuilder {
|
|
|
614
593
|
* phrases, `or`, and a leading `-` to exclude — and because it never throws
|
|
615
594
|
* on user input, which `to_tsquery` does on so much as a stray parenthesis.
|
|
616
595
|
*/
|
|
617
|
-
static buildFullTextCondition(searchString: string, table: PgTable<any>,
|
|
596
|
+
static buildFullTextCondition(searchString: string, table: PgTable<any>, described: TableDescriptor): SQL | undefined;
|
|
618
597
|
/**
|
|
619
598
|
* The substring half of {@link SearchMode} `"hybrid"`: every term found
|
|
620
599
|
* somewhere in the declared fields, with accents folded on both sides.
|
|
@@ -689,12 +668,12 @@ export declare class DrizzleConditionBuilder {
|
|
|
689
668
|
* the table yet, or when the caller did not ask: this costs a `ts_headline`
|
|
690
669
|
* per field per row and `ts_headline` re-parses the document.
|
|
691
670
|
*/
|
|
692
|
-
static buildSearchMatchesExpression(searchString: string, table: PgTable<any>,
|
|
671
|
+
static buildSearchMatchesExpression(searchString: string, table: PgTable<any>, described: TableDescriptor): SQL | undefined;
|
|
693
672
|
/**
|
|
694
673
|
* `ts_rank(<column>, <query>)` for the collection, or undefined when it has
|
|
695
674
|
* not opted in. This is what backs `orderBy: ["_score", "desc"]`.
|
|
696
675
|
*/
|
|
697
|
-
static buildSearchRankExpression(searchString: string, table: PgTable<any>,
|
|
676
|
+
static buildSearchRankExpression(searchString: string, table: PgTable<any>, described: TableDescriptor): SQL | undefined;
|
|
698
677
|
/**
|
|
699
678
|
* Build a unique field check condition: rows holding `value`, other than
|
|
700
679
|
* the one `excludeRow` names.
|
|
@@ -707,7 +686,7 @@ export declare class DrizzleConditionBuilder {
|
|
|
707
686
|
/**
|
|
708
687
|
* Build relation-based query with joins and conditions
|
|
709
688
|
*/
|
|
710
|
-
static buildRelationQuery<T extends DrizzleDynamicQuery>(baseQuery: T, relation:
|
|
689
|
+
static buildRelationQuery<T extends DrizzleDynamicQuery>(baseQuery: T, relation: RelationDescriptor, parentId: string | number | (string | number)[], targetTable: PgTable<any>, parentTable: PgTable<any>, parentIdColumn: AnyPgColumn, targetIdColumn: AnyPgColumn, registry: PostgresTableRegistry, additionalFilters?: SQL[]): T;
|
|
711
690
|
/**
|
|
712
691
|
* A count over a relation's target rows.
|
|
713
692
|
*
|
|
@@ -715,11 +694,7 @@ export declare class DrizzleConditionBuilder {
|
|
|
715
694
|
* junction; the owning/inverse pair that used to sit here built the same
|
|
716
695
|
* query twice.
|
|
717
696
|
*/
|
|
718
|
-
static buildRelationCountQuery<T extends DrizzleDynamicQuery>(baseCountQuery: T, relation:
|
|
719
|
-
/**
|
|
720
|
-
* Build join path conditions for count queries
|
|
721
|
-
*/
|
|
722
|
-
private static buildJoinPathCountQuery;
|
|
697
|
+
static buildRelationCountQuery<T extends DrizzleDynamicQuery>(baseCountQuery: T, relation: RelationDescriptor, parentId: string | number, targetTable: PgTable<any>, parentTable: PgTable<any>, parentIdColumn: AnyPgColumn, targetIdColumn: AnyPgColumn, registry: PostgresTableRegistry, additionalFilters?: SQL[]): T;
|
|
723
698
|
/**
|
|
724
699
|
* Build junction table conditions for count queries
|
|
725
700
|
*/
|
|
@@ -741,7 +716,11 @@ export declare class DrizzleConditionBuilder {
|
|
|
741
716
|
* failed. The tab's own listing worked — it walks the path forward from
|
|
742
717
|
* the parent, by position — so only the record behind it broke.
|
|
743
718
|
*/
|
|
744
|
-
|
|
719
|
+
/**
|
|
720
|
+
* A junction's pg table and its two key columns, for the join and count
|
|
721
|
+
* builders: each missing piece is its own error, naming the junction.
|
|
722
|
+
*/
|
|
723
|
+
private static junctionKeyColumns;
|
|
745
724
|
static getTableNamesFromColumns(columns: string | string[]): string[];
|
|
746
725
|
/**
|
|
747
726
|
* Helper method to extract column names from columns
|
|
@@ -770,7 +749,9 @@ export declare class DrizzleConditionBuilder {
|
|
|
770
749
|
vector: number[];
|
|
771
750
|
distance?: "cosine" | "l2" | "inner_product";
|
|
772
751
|
threshold?: number;
|
|
773
|
-
},
|
|
752
|
+
},
|
|
753
|
+
/** The searched table's descriptor: which of its columns the API does not have. */
|
|
754
|
+
described?: TableDescriptor): {
|
|
774
755
|
orderBy: SQL;
|
|
775
756
|
filter?: SQL;
|
|
776
757
|
distanceSelect: SQL;
|
|
@@ -784,15 +765,20 @@ export declare class DrizzleConditionBuilder {
|
|
|
784
765
|
* (`vector(1536)`) rather than on the declared property, so it holds for an
|
|
785
766
|
* introspected collection too, where the property carries no Rebase type.
|
|
786
767
|
*
|
|
787
|
-
* The answer for a name that is not a column lists no
|
|
788
|
-
*
|
|
789
|
-
*
|
|
768
|
+
* The answer for a name that is not a column lists no private column;
|
|
769
|
+
* the REST check answers a private one with the same function, so the two
|
|
770
|
+
* cannot be told apart.
|
|
771
|
+
*/
|
|
772
|
+
/**
|
|
773
|
+
* The vector column `property` names. A private column is a column the API
|
|
774
|
+
* does not have: it is never listed among the known ones, and an API
|
|
775
|
+
* caller naming it is answered exactly as a caller naming nothing (the
|
|
776
|
+
* trusted server plane, which has no viewer, may still rank by it).
|
|
790
777
|
*/
|
|
791
778
|
private static resolveVectorColumn;
|
|
792
779
|
}
|
|
793
780
|
/**
|
|
794
|
-
* Alias for DrizzleConditionBuilder
|
|
795
|
-
* This allows code to use PostgresConditionBuilder alongside future MongoConditionBuilder, etc.
|
|
781
|
+
* Alias for DrizzleConditionBuilder, named after the engine it compiles for.
|
|
796
782
|
*/
|
|
797
783
|
export declare const PostgresConditionBuilder: typeof DrizzleConditionBuilder;
|
|
798
784
|
export {};
|