@rebasepro/server-postgres 0.30.1 → 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,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether the database protects every declared table this driver is about to
|
|
3
|
+
* serve — and the refusal to serve one it does not.
|
|
4
|
+
*
|
|
5
|
+
* A provisioning boot leaves each declared table with row-level security on
|
|
6
|
+
* and its declared policies written (or, where Postgres refuses the `ENABLE`,
|
|
7
|
+
* with the request role's privileges taken back). A backend that provisions
|
|
8
|
+
* nothing — `REBASE_PROVISION=false`, `provisionSchema: false`,
|
|
9
|
+
* `provision: { tables: false }`, `REBASE_MIGRATE_ON_BOOT=none` — trusts the
|
|
10
|
+
* database to be in that state already, and the database may not be: a
|
|
11
|
+
* hand-written migration, a `DISABLE ROW LEVEL SECURITY` left over from
|
|
12
|
+
* debugging, a restore from a dump older than the policies. With RLS off,
|
|
13
|
+
* every request role that holds the schema grant reads and writes every row,
|
|
14
|
+
* whatever `rls` the table declares.
|
|
15
|
+
*
|
|
16
|
+
* So, wherever a declared table starts being served (boot, after the policies
|
|
17
|
+
* step; a live schema apply's refresh, adoption included), the catalogue is
|
|
18
|
+
* read — one statement, no DDL — and a table is withheld when:
|
|
19
|
+
*
|
|
20
|
+
* - its row-level security is **off** (`relrowsecurity`): every row would be
|
|
21
|
+
* served to every caller; or
|
|
22
|
+
* - it declares policies and the database has **none of them** (by the name
|
|
23
|
+
* the provisioning path gives each — `planTablePolicies`, the same plan, so
|
|
24
|
+
* the same derived names): RLS on with no declared policy is either a table
|
|
25
|
+
* that answers nothing, or one whose access some policy this schema does
|
|
26
|
+
* not declare decides — a stray `USING (true)` would serve every row; or
|
|
27
|
+
* - a **restrictive** policy it declares is missing, or is not restrictive in
|
|
28
|
+
* the database: a restrictive policy is a gate (a tenant, an `anon` deny),
|
|
29
|
+
* and the permissive grants without it reach rows it exists to keep out; or
|
|
30
|
+
* - a many-to-many **junction** it reads and writes through (declared or
|
|
31
|
+
* implicit) fails any of the above, judged by the junction's own planned
|
|
32
|
+
* policies; or
|
|
33
|
+
* - a table one of its **`via`** relations passes through (a step, or a
|
|
34
|
+
* `table.column` a step joins on) fails any of the above — a declared table
|
|
35
|
+
* withheld for itself or for one of these reasons, or an implicit junction
|
|
36
|
+
* judged by its own planned policies.
|
|
37
|
+
*
|
|
38
|
+
* A missing **permissive** policy only narrows access (Postgres ORs the
|
|
39
|
+
* permissive policies), so the table is served and the boot log warns, naming
|
|
40
|
+
* the policy. A policy the schema does not declare cannot be judged here — it
|
|
41
|
+
* may be the database's own business — and is `rebase doctor`'s to report.
|
|
42
|
+
*
|
|
43
|
+
* Withheld is what introspection does with a table that has RLS off: not
|
|
44
|
+
* served, the statements that protect it in the log. A request for it is
|
|
45
|
+
* refused naming the reason (never the SQL); nothing else stops serving.
|
|
46
|
+
*
|
|
47
|
+
* @module
|
|
48
|
+
*/
|
|
49
|
+
import type { CompiledTable } from "@rebasepro/types";
|
|
50
|
+
import type { PostgresTableRegistry } from "../model/PostgresTableRegistry.js";
|
|
51
|
+
import type { RawSqlRunner } from "./rls-enforcement.js";
|
|
52
|
+
/** A declared table the database does not protect, and how to protect it. */
|
|
53
|
+
export interface UnprotectedServedTable {
|
|
54
|
+
/** The table's slug: what it is served under. */
|
|
55
|
+
slug: string;
|
|
56
|
+
/** `schema.table`. */
|
|
57
|
+
qualified: string;
|
|
58
|
+
/**
|
|
59
|
+
* What is wrong: RLS off, RLS on with none of its declared policies, or a
|
|
60
|
+
* declared restrictive policy missing (or permissive in the database).
|
|
61
|
+
*/
|
|
62
|
+
problem: "rls-off" | "no-policies" | "restrictive-missing";
|
|
63
|
+
/** The statements that bring the table to what a provisioning boot leaves. */
|
|
64
|
+
remediationSql: string;
|
|
65
|
+
/** The declared policies the database does not have as declared, by name. */
|
|
66
|
+
missingPolicies: string[];
|
|
67
|
+
/**
|
|
68
|
+
* Set when the table is withheld for a table one of its relations reads
|
|
69
|
+
* and writes through, not for itself: that table's `schema.table` — a
|
|
70
|
+
* many-to-many junction, or a table a `via` passes through (then
|
|
71
|
+
* {@link via} names the relation). `qualified`, `problem`,
|
|
72
|
+
* `remediationSql` and `missingPolicies` are then those of the table that
|
|
73
|
+
* fails the rule (for a chain of `via`s, the first one).
|
|
74
|
+
*/
|
|
75
|
+
junction?: string;
|
|
76
|
+
/** The `via` relation of this table that passes through {@link junction}, when that is why it is withheld. */
|
|
77
|
+
via?: string;
|
|
78
|
+
}
|
|
79
|
+
/** A declared table served without some of its permissive policies: access is narrower than declared. */
|
|
80
|
+
export interface NarrowedServedTable {
|
|
81
|
+
slug: string;
|
|
82
|
+
qualified: string;
|
|
83
|
+
/** The declared permissive policies the database does not have. */
|
|
84
|
+
missingPolicies: string[];
|
|
85
|
+
/** The statements that create them. */
|
|
86
|
+
remediationSql: string;
|
|
87
|
+
}
|
|
88
|
+
/** What {@link findServedTableProtection} found: tables to withhold, and tables served narrower than declared. */
|
|
89
|
+
export interface ServedTableProtection {
|
|
90
|
+
unprotected: UnprotectedServedTable[];
|
|
91
|
+
narrowed: NarrowedServedTable[];
|
|
92
|
+
}
|
|
93
|
+
/** What {@link findUnprotectedServedTables} renders the policies with — the boot's admin switch. */
|
|
94
|
+
export interface ServedTableProtectionOptions {
|
|
95
|
+
/** The driver's admin switch is live: admin policies go `TO rebase_admin`. */
|
|
96
|
+
adminRoleAvailable?: boolean;
|
|
97
|
+
/** The admin request role exists: admin-only policies get their companion. */
|
|
98
|
+
adminRequestRoleAvailable?: boolean;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The declared tables among `tables` that exist in the database unprotected.
|
|
102
|
+
* One catalogue read; a table the database does not have is not this check's
|
|
103
|
+
* (it answers "table not found" already). Views and junctions are left out:
|
|
104
|
+
* a view has no row-level security of its own, and a junction is never served.
|
|
105
|
+
*/
|
|
106
|
+
export declare function findUnprotectedServedTables(run: RawSqlRunner, tables: readonly CompiledTable[], options?: ServedTableProtectionOptions): Promise<UnprotectedServedTable[]>;
|
|
107
|
+
/**
|
|
108
|
+
* {@link findUnprotectedServedTables}, with the tables served narrower than
|
|
109
|
+
* declared (a permissive policy missing) beside them. One catalogue read.
|
|
110
|
+
*/
|
|
111
|
+
export declare function findServedTableProtection(run: RawSqlRunner, tables: readonly CompiledTable[], options?: ServedTableProtectionOptions): Promise<ServedTableProtection>;
|
|
112
|
+
/** What a caller asking for a withheld table is told: the reason, never the SQL. */
|
|
113
|
+
export declare function withheldTableMessage(table: Pick<UnprotectedServedTable, "slug" | "problem" | "junction" | "via">): string;
|
|
114
|
+
/**
|
|
115
|
+
* Withhold every table `found` names from `registry`, and say so: one error
|
|
116
|
+
* per table, with the statements that protect it, and what to run instead.
|
|
117
|
+
*/
|
|
118
|
+
export declare function withholdUnprotectedTables(registry: PostgresTableRegistry, found: readonly UnprotectedServedTable[]): void;
|
|
119
|
+
/**
|
|
120
|
+
* Say, once per table, that it is served with some of its declared permissive
|
|
121
|
+
* policies missing: those callers are refused rows the schema grants them. It
|
|
122
|
+
* is served — a missing grant only narrows access — and the log names the
|
|
123
|
+
* statements that create the policies.
|
|
124
|
+
*/
|
|
125
|
+
export declare function warnNarrowedTables(found: readonly NarrowedServedTable[]): void;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { SQL } from "drizzle-orm";
|
|
2
2
|
import { AnyPgColumn, PgTable } from "drizzle-orm/pg-core";
|
|
3
3
|
import { FilterValues, OrderByTuple, LogicalCondition } from "@rebasepro/types";
|
|
4
|
+
import type { ColumnDescriptor } from "@rebasepro/types";
|
|
4
5
|
import type { DriverAggregate, DriverAggregateGroup, IncludeSpec, VectorSearchParams } from "@rebasepro/types";
|
|
5
6
|
import { RelationService } from "./RelationService.js";
|
|
6
7
|
import { DrizzleClient } from "../interfaces.js";
|
|
7
|
-
import {
|
|
8
|
-
import { type NestedPathHop } from "./nested-path.js";
|
|
8
|
+
import { PostgresTableRegistry } from "../model/PostgresTableRegistry.js";
|
|
9
9
|
import { type WithDeleted } from "./soft-delete.js";
|
|
10
10
|
import { type ReadCallContextProvider } from "./read-scope.js";
|
|
11
11
|
/**
|
|
@@ -20,7 +20,8 @@ import { type ReadCallContextProvider } from "./read-scope.js";
|
|
|
20
20
|
* so they do it too — but only over a numeric column, and those are the two
|
|
21
21
|
* functions that also apply to text and dates.
|
|
22
22
|
*
|
|
23
|
-
* Decided by the column's
|
|
23
|
+
* Decided by the column's Postgres type (a numeric kind), not by trying
|
|
24
|
+
* `Number()` on the value.
|
|
24
25
|
* `?select=avg(price),max(price)` used to answer `{avg_price: 5,
|
|
25
26
|
* max_price: "8.5"}` — one column, two functions, two JSON types, and
|
|
26
27
|
* arithmetic on the second one silently concatenates. Parsing whatever looks
|
|
@@ -30,9 +31,7 @@ import { type ReadCallContextProvider } from "./read-scope.js";
|
|
|
30
31
|
* Exported to be tested: the parsing itself needs a database, this decision
|
|
31
32
|
* does not.
|
|
32
33
|
*/
|
|
33
|
-
export declare function numericAggregateAliases(aggregates: DriverAggregate[],
|
|
34
|
-
type?: string;
|
|
35
|
-
}>): Set<string>;
|
|
34
|
+
export declare function numericAggregateAliases(aggregates: DriverAggregate[], columns: ReadonlyMap<string, ColumnDescriptor>): Set<string>;
|
|
36
35
|
/**
|
|
37
36
|
* What `fingerprint()` computes over a table's row versions, from their tuple
|
|
38
37
|
* headers alone: no column is read, decoded or turned into text.
|
|
@@ -60,7 +59,7 @@ export declare class FetchService {
|
|
|
60
59
|
*/
|
|
61
60
|
private callContext?;
|
|
62
61
|
private relationService;
|
|
63
|
-
constructor(db: DrizzleClient, registry:
|
|
62
|
+
constructor(db: DrizzleClient, registry: PostgresTableRegistry,
|
|
64
63
|
/**
|
|
65
64
|
* How this service's reads reach the identity their `beforeQuery` hooks
|
|
66
65
|
* run as. Passed by the driver that constructed it; absent only in a
|
|
@@ -68,11 +67,6 @@ export declare class FetchService {
|
|
|
68
67
|
* read unnarrowed. See `read-scope.ts`.
|
|
69
68
|
*/
|
|
70
69
|
callContext?: ReadCallContextProvider | undefined);
|
|
71
|
-
/**
|
|
72
|
-
* Get the relational query builder for a given table name.
|
|
73
|
-
* Safely narrows the DrizzleClient union type to access db.query[tableName].
|
|
74
|
-
*/
|
|
75
|
-
private getQueryBuilder;
|
|
76
70
|
/**
|
|
77
71
|
* The context the condition builder needs to compile a filter key that is
|
|
78
72
|
* not a column name outright.
|
|
@@ -334,22 +328,6 @@ export declare class FetchService {
|
|
|
334
328
|
* driver's knowledge, not the HTTP layer's.
|
|
335
329
|
*/
|
|
336
330
|
cursorFor(collectionPath: string, row: Record<string, unknown>, orderBy?: OrderByTuple[]): string | undefined;
|
|
337
|
-
/**
|
|
338
|
-
* Every relation of one row, as the refs the admin renders, attached in
|
|
339
|
-
* place.
|
|
340
|
-
*
|
|
341
|
-
* Loaded by the batched loaders an `include` takes, so a target reached from
|
|
342
|
-
* this row is read as the caller may see it: its `beforeQuery` scope and its
|
|
343
|
-
* soft delete applied, its unreadable fields stripped. Populated through
|
|
344
|
-
* drizzle's relational `with`, the single get knew neither, and a
|
|
345
|
-
* tenant-scoped user fetching an owner was handed another tenant's docs —
|
|
346
|
-
* and the trashed ones — under a relation `?include=` answered correctly.
|
|
347
|
-
*
|
|
348
|
-
* A to-many relation that reaches nothing is `[]`; a to-one is left off. A
|
|
349
|
-
* relation that fails for a reason other than the database is logged and
|
|
350
|
-
* left off, as on the include path, rather than failing the whole row.
|
|
351
|
-
*/
|
|
352
|
-
private loadRelationRefs;
|
|
353
331
|
/**
|
|
354
332
|
* Extract cursor pagination conditions from startAfter options.
|
|
355
333
|
*
|
|
@@ -418,6 +396,13 @@ export declare class FetchService {
|
|
|
418
396
|
* Compile "rows reachable from this parent" into a `WHERE` condition on the
|
|
419
397
|
* target table, so a nested listing can run as an ordinary collection query.
|
|
420
398
|
*/
|
|
399
|
+
/**
|
|
400
|
+
* The order a nested listing (`authors/1/posts`) reads in: the caller's,
|
|
401
|
+
* when it names one, else the order the relation declares
|
|
402
|
+
* (`rel.hasMany(target, { orderBy })`). Passed down as the read's own
|
|
403
|
+
* `orderBy`, so the cursor of a paged listing is built on the same keys.
|
|
404
|
+
*/
|
|
405
|
+
private static nestedOrder;
|
|
421
406
|
private buildRelationScope;
|
|
422
407
|
/**
|
|
423
408
|
* Whether `id` is actually reachable at `collectionPath`.
|
|
@@ -430,55 +415,6 @@ export declare class FetchService {
|
|
|
430
415
|
* which is what a caller addressing it through the parent should see.
|
|
431
416
|
*/
|
|
432
417
|
private isAddressableUnder;
|
|
433
|
-
/**
|
|
434
|
-
* Fetch a single row by ID
|
|
435
|
-
*/
|
|
436
|
-
fetchOne<M extends Record<string, unknown>>(collectionPath: string, id: string | number, databaseId?: string, withDeleted?: WithDeleted): Promise<Record<string, unknown> | undefined>;
|
|
437
|
-
/**
|
|
438
|
-
* Unified method to fetch rows with optional search functionality
|
|
439
|
-
*/
|
|
440
|
-
fetchRowsWithConditions<M extends Record<string, unknown>>(collectionPath: string, options?: {
|
|
441
|
-
filter?: FilterValues<Extract<keyof M, string>>;
|
|
442
|
-
orderBy?: string | OrderByTuple[];
|
|
443
|
-
order?: "desc" | "asc";
|
|
444
|
-
limit?: number;
|
|
445
|
-
offset?: number;
|
|
446
|
-
startAfter?: Record<string, unknown>;
|
|
447
|
-
searchString?: string;
|
|
448
|
-
searchExplain?: boolean;
|
|
449
|
-
databaseId?: string;
|
|
450
|
-
vectorSearch?: VectorSearchParams;
|
|
451
|
-
logical?: LogicalCondition;
|
|
452
|
-
/** Narrow to the rows reachable from a parent through a relation. */
|
|
453
|
-
relatedTo?: NestedPathHop;
|
|
454
|
-
/** See `FetchCollectionProps.withDeleted`. */
|
|
455
|
-
withDeleted?: WithDeleted;
|
|
456
|
-
/**
|
|
457
|
-
* Relations to load. **Absent means none** — the same as it means
|
|
458
|
-
* over REST.
|
|
459
|
-
*
|
|
460
|
-
* It used to mean *all of them*, unconditionally, and this is the
|
|
461
|
-
* method the realtime refetch goes through. So a subscription was
|
|
462
|
-
* pushed rows carrying every relation the collection declares while
|
|
463
|
-
* the identical `find()` returned rows carrying none, and a client
|
|
464
|
-
* that rendered both saw the row change shape when a write landed.
|
|
465
|
-
*/
|
|
466
|
-
include?: IncludeSpec;
|
|
467
|
-
/** Columns to read — a projection pushed into the SELECT. */
|
|
468
|
-
fields?: string[];
|
|
469
|
-
/** `SELECT DISTINCT` over the projection. */
|
|
470
|
-
distinct?: boolean;
|
|
471
|
-
}): Promise<Record<string, unknown>[]>;
|
|
472
|
-
/**
|
|
473
|
-
* Fallback path used when db.query is unavailable.
|
|
474
|
-
*
|
|
475
|
-
* The primary path runs the results through `toFlatRow`, which maps
|
|
476
|
-
* relations from what drizzle already nested — no query per row. This one
|
|
477
|
-
* has no nesting to read, so it resolves relations itself, in batches.
|
|
478
|
-
*
|
|
479
|
-
* Process raw database results into flat rows with relations.
|
|
480
|
-
*/
|
|
481
|
-
private processRowResults;
|
|
482
418
|
/**
|
|
483
419
|
* Every row of a collection's table, as stored, a page at a time, in key
|
|
484
420
|
* order — the driver's `scanStoredRows`.
|
|
@@ -491,60 +427,6 @@ export declare class FetchService {
|
|
|
491
427
|
* deleted during the scan never shifts another past the next page.
|
|
492
428
|
*/
|
|
493
429
|
scanStoredRows(collectionPath: string, pageSize?: number): AsyncGenerator<Record<string, unknown>[]>;
|
|
494
|
-
/**
|
|
495
|
-
* Fetch a collection of rows
|
|
496
|
-
*/
|
|
497
|
-
fetchCollection<M extends Record<string, unknown>>(collectionPath: string, options?: {
|
|
498
|
-
filter?: FilterValues<Extract<keyof M, string>>;
|
|
499
|
-
/**
|
|
500
|
-
* An `or(...)`/`and(...)` group, applied alongside `filter`.
|
|
501
|
-
*
|
|
502
|
-
* `fetchRowsWithConditions` below has always applied this; it was
|
|
503
|
-
* simply absent from this signature, so the only callers that could
|
|
504
|
-
* pass one were the ones that went around this method. Realtime
|
|
505
|
-
* came through here, which is why a subscription filtered by a
|
|
506
|
-
* logical group was pushed every row in the table.
|
|
507
|
-
*/
|
|
508
|
-
logical?: LogicalCondition;
|
|
509
|
-
orderBy?: string | OrderByTuple[];
|
|
510
|
-
order?: "desc" | "asc";
|
|
511
|
-
limit?: number;
|
|
512
|
-
offset?: number;
|
|
513
|
-
startAfter?: Record<string, unknown>;
|
|
514
|
-
searchString?: string;
|
|
515
|
-
searchExplain?: boolean;
|
|
516
|
-
databaseId?: string;
|
|
517
|
-
vectorSearch?: VectorSearchParams;
|
|
518
|
-
/** Relations to load. Absent means none — see `fetchRowsWithConditions`. */
|
|
519
|
-
include?: IncludeSpec;
|
|
520
|
-
/** Columns to read — a projection pushed into the SELECT. */
|
|
521
|
-
fields?: string[];
|
|
522
|
-
/** `SELECT DISTINCT` over the projection. */
|
|
523
|
-
distinct?: boolean;
|
|
524
|
-
/** See `FetchCollectionProps.withDeleted`. */
|
|
525
|
-
withDeleted?: WithDeleted;
|
|
526
|
-
}): Promise<Record<string, unknown>[]>;
|
|
527
|
-
/**
|
|
528
|
-
* Search rows by text
|
|
529
|
-
*/
|
|
530
|
-
searchRows<M extends Record<string, unknown>>(collectionPath: string, searchString: string, options?: {
|
|
531
|
-
filter?: FilterValues<Extract<keyof M, string>>;
|
|
532
|
-
/**
|
|
533
|
-
* An `or(...)`/`and(...)` group, applied alongside `filter`.
|
|
534
|
-
*
|
|
535
|
-
* `fetchRowsWithConditions` has always applied one; it was missing
|
|
536
|
-
* from this signature, so a realtime search subscription carrying a
|
|
537
|
-
* group could not pass it on and served every row matching the text
|
|
538
|
-
* that RLS allowed.
|
|
539
|
-
*/
|
|
540
|
-
logical?: LogicalCondition;
|
|
541
|
-
orderBy?: string | OrderByTuple[];
|
|
542
|
-
order?: "desc" | "asc";
|
|
543
|
-
limit?: number;
|
|
544
|
-
databaseId?: string;
|
|
545
|
-
/** Ask each row which declared search field matched. */
|
|
546
|
-
searchExplain?: boolean;
|
|
547
|
-
}): Promise<Record<string, unknown>[]>;
|
|
548
430
|
/**
|
|
549
431
|
* Count rows in a collection
|
|
550
432
|
*/
|
|
@@ -638,6 +520,15 @@ export declare class FetchService {
|
|
|
638
520
|
/**
|
|
639
521
|
* Get the RelationService instance for external use
|
|
640
522
|
*/
|
|
523
|
+
/**
|
|
524
|
+
* Refuse a read made on an API caller's behalf that names a column or
|
|
525
|
+
* relation the caller may not read — filter, sort, projection, include
|
|
526
|
+
* (and its `where`), vector search. The trusted server plane (no viewer)
|
|
527
|
+
* is not refused. Every public read of this service passes here first, so
|
|
528
|
+
* an in-process `context.data` under the caller's scope is refused exactly
|
|
529
|
+
* as `GET /api/data` is (see {@link assertReadRequestReadable}).
|
|
530
|
+
*/
|
|
531
|
+
private assertCallerMayRead;
|
|
641
532
|
getRelationService(): RelationService;
|
|
642
533
|
/**
|
|
643
534
|
* Fetch a collection of rows, with the relations `include` names.
|
|
@@ -671,8 +562,6 @@ export declare class FetchService {
|
|
|
671
562
|
searchString?: string;
|
|
672
563
|
databaseId?: string;
|
|
673
564
|
vectorSearch?: VectorSearchParams;
|
|
674
|
-
/** Narrow to the rows reachable from a parent through a relation. */
|
|
675
|
-
relatedTo?: NestedPathHop;
|
|
676
565
|
/**
|
|
677
566
|
* See `FetchCollectionProps.withDeleted`. Applied by
|
|
678
567
|
* `fetchRowsWithConditionsRaw` — the one place this pipeline builds
|
|
@@ -1,22 +1,11 @@
|
|
|
1
|
-
import { FilterValues, type LogicalCondition
|
|
1
|
+
import { FilterValues, type LogicalCondition } from "@rebasepro/types";
|
|
2
2
|
import { RelationService } from "./RelationService.js";
|
|
3
3
|
import { type ReadCallContextProvider } from "./read-scope.js";
|
|
4
4
|
import { RelationWriteService } from "./RelationWriteService.js";
|
|
5
5
|
import { FetchService } from "./FetchService.js";
|
|
6
6
|
import { DrizzleClient } from "../interfaces.js";
|
|
7
|
-
import {
|
|
7
|
+
import { PostgresTableRegistry } from "../model/PostgresTableRegistry.js";
|
|
8
8
|
import { ApiError } from "@rebasepro/server";
|
|
9
|
-
/**
|
|
10
|
-
* The top-level properties whose value is stamped once, when the row is
|
|
11
|
-
* created: `on_create` dates and `user_on_create` identities.
|
|
12
|
-
*
|
|
13
|
-
* What they hold is a fact about the row's creation, so a write to a row that
|
|
14
|
-
* already exists has nothing to say about them — an update, and the
|
|
15
|
-
* conflict-update of an upsert that met a stored row. Top level only: a stamp
|
|
16
|
-
* nested inside a `map` is part of that map's value, not a column a write can
|
|
17
|
-
* leave out.
|
|
18
|
-
*/
|
|
19
|
-
export declare function createStampKeys(properties: Properties | undefined): string[];
|
|
20
9
|
/** How {@link PersistService.save} writes a row that may already be stored. */
|
|
21
10
|
export interface PersistSaveOptions {
|
|
22
11
|
/** INSERT ... ON CONFLICT DO UPDATE. See `SaveProps.upsert`. */
|
|
@@ -26,9 +15,9 @@ export interface PersistSaveOptions {
|
|
|
26
15
|
/**
|
|
27
16
|
* Keys of `values` that belong to the INSERT alone: what the create
|
|
28
17
|
* pipeline filled in rather than what the caller wrote — a declared
|
|
29
|
-
*
|
|
18
|
+
* literal `.default()`, a tenant stamp. When an upsert's INSERT meets a stored
|
|
30
19
|
* row, those columns keep the value they have. The create-time stamps
|
|
31
|
-
* (
|
|
20
|
+
* (`.onCreateNow()`, `.onCreateUser()`) are left out of the conflict-update
|
|
32
21
|
* without being named here.
|
|
33
22
|
*/
|
|
34
23
|
insertOnlyKeys?: readonly string[];
|
|
@@ -87,7 +76,7 @@ export declare class PersistService {
|
|
|
87
76
|
/** Writes: junction membership, foreign-key stamping, links. */
|
|
88
77
|
private relationWrites;
|
|
89
78
|
private fetchService;
|
|
90
|
-
constructor(db: DrizzleClient, registry:
|
|
79
|
+
constructor(db: DrizzleClient, registry: PostgresTableRegistry,
|
|
91
80
|
/**
|
|
92
81
|
* How this service's reads reach the identity their `beforeQuery` hooks
|
|
93
82
|
* run as. Passed by the driver that constructed it; absent only in a
|
|
@@ -148,7 +137,7 @@ export declare class PersistService {
|
|
|
148
137
|
* request the framework had just written to.
|
|
149
138
|
*
|
|
150
139
|
* Returns `undefined` when the link is not a column at all (a multi-hop
|
|
151
|
-
* `
|
|
140
|
+
* `via`), so the caller writes the row without stamping anything.
|
|
152
141
|
*
|
|
153
142
|
* `relation.localKey` is deliberately not consulted: it names a column on
|
|
154
143
|
* the *source* table. Falling back to it here — which is what this used to
|