@rebasepro/server-postgres 0.12.1-canary.gf5f1d39 → 0.13.1-canary.g18cfeb7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/dist/PostgresBackendDriver.d.ts +49 -2
  2. package/dist/PostgresBootstrapper.d.ts +25 -1
  3. package/dist/auth/services.d.ts +21 -0
  4. package/dist/{src-BbFOPJ1S.js → auth-users-columns-Do9mw5Y5.js} +602 -200
  5. package/dist/auth-users-columns-Do9mw5Y5.js.map +1 -0
  6. package/dist/backup/backup-service.d.ts +10 -1
  7. package/dist/backup/pg-tools.d.ts +47 -0
  8. package/dist/backup-service-Bww-Lg0s.js +8999 -0
  9. package/dist/backup-service-Bww-Lg0s.js.map +1 -0
  10. package/dist/cli-helpers.d.ts +40 -1
  11. package/dist/connection-BuZ97wsr.js +250 -0
  12. package/dist/connection-BuZ97wsr.js.map +1 -0
  13. package/dist/connection.d.ts +42 -0
  14. package/dist/ensure-collection-policies-DMUdRQdM.js +57 -0
  15. package/dist/ensure-collection-policies-DMUdRQdM.js.map +1 -0
  16. package/dist/ensure-collection-tables-DSIxvLLD.js +694 -0
  17. package/dist/ensure-collection-tables-DSIxvLLD.js.map +1 -0
  18. package/dist/index.es.js +1701 -10167
  19. package/dist/index.es.js.map +1 -1
  20. package/dist/policy-CPkCqVTz.js +105 -0
  21. package/dist/policy-CPkCqVTz.js.map +1 -0
  22. package/dist/rls-bootstrap-sql-Bpv3nUZo.js +244 -0
  23. package/dist/rls-bootstrap-sql-Bpv3nUZo.js.map +1 -0
  24. package/dist/schema/auth-schema.d.ts +83 -144
  25. package/dist/schema/auth-users-columns.d.ts +97 -0
  26. package/dist/schema/ensure-collection-policies.d.ts +60 -0
  27. package/dist/schema/ensure-collection-tables.d.ts +45 -3
  28. package/dist/schema/generate-drizzle-schema-logic.d.ts +1 -1
  29. package/dist/schema/generate-postgres-ddl-logic.d.ts +137 -3
  30. package/dist/schema/generated-schema-staleness.d.ts +39 -0
  31. package/dist/schema/introspect-db-constraints.d.ts +57 -0
  32. package/dist/schema/introspect-db-logic.d.ts +94 -5
  33. package/dist/schema/introspect-db-queries.d.ts +119 -0
  34. package/dist/schema/introspect-db-structure.d.ts +263 -0
  35. package/dist/schema/introspect-db-types.d.ts +11 -0
  36. package/dist/schema/rls-bootstrap-sql.d.ts +135 -0
  37. package/dist/security/rls-enforcement.d.ts +53 -2
  38. package/dist/services/FetchService.d.ts +14 -8
  39. package/dist/services/RelationService.d.ts +24 -1
  40. package/dist/services/channel-bus/index.d.ts +1 -7
  41. package/dist/services/collection-helpers.d.ts +36 -2
  42. package/dist/services/dataService.d.ts +5 -1
  43. package/dist/services/realtimeService.d.ts +25 -21
  44. package/dist/services/row-pipeline.d.ts +1 -1
  45. package/dist/{src-Zqwaw3P5.js → src-C_wvdMnl.js} +78 -145
  46. package/dist/src-C_wvdMnl.js.map +1 -0
  47. package/dist/utils/connection-string.d.ts +29 -0
  48. package/dist/utils/drizzle-conditions.d.ts +5 -4
  49. package/dist/utils/pg-error-utils.d.ts +35 -0
  50. package/dist/websocket-D0TBU3ia.js +530 -0
  51. package/dist/websocket-D0TBU3ia.js.map +1 -0
  52. package/package.json +17 -16
  53. package/src/PostgresAdapter.ts +21 -2
  54. package/src/PostgresBackendDriver.ts +169 -3
  55. package/src/PostgresBootstrapper.ts +233 -35
  56. package/src/auth/ensure-tables.ts +335 -81
  57. package/src/auth/services.ts +24 -2
  58. package/src/backup/backup-cli.ts +41 -2
  59. package/src/backup/backup-service.ts +38 -5
  60. package/src/backup/pg-tools.ts +96 -3
  61. package/src/cli-helpers.ts +92 -9
  62. package/src/cli.ts +219 -56
  63. package/src/collections/validate-relations.ts +136 -14
  64. package/src/connection.ts +73 -0
  65. package/src/data-transformer.ts +22 -6
  66. package/src/databasePoolManager.ts +5 -2
  67. package/src/history/ensure-history-table.ts +7 -0
  68. package/src/schema/auth-schema.ts +30 -19
  69. package/src/schema/auth-users-columns.ts +131 -0
  70. package/src/schema/doctor.ts +7 -5
  71. package/src/schema/ensure-collection-policies.ts +105 -0
  72. package/src/schema/ensure-collection-tables.test.ts +105 -9
  73. package/src/schema/ensure-collection-tables.ts +301 -44
  74. package/src/schema/generate-drizzle-schema-logic.ts +49 -7
  75. package/src/schema/generate-postgres-ddl-logic.ts +474 -27
  76. package/src/schema/generated-schema-staleness.ts +169 -0
  77. package/src/schema/introspect-db-constraints.ts +385 -0
  78. package/src/schema/introspect-db-inference.ts +18 -8
  79. package/src/schema/introspect-db-logic.ts +385 -71
  80. package/src/schema/introspect-db-queries.ts +326 -0
  81. package/src/schema/introspect-db-structure.ts +670 -0
  82. package/src/schema/introspect-db-types.ts +56 -0
  83. package/src/schema/introspect-db.ts +37 -80
  84. package/src/schema/introspect-runtime.test.ts +56 -8
  85. package/src/schema/introspect-runtime.ts +31 -9
  86. package/src/schema/non-sql-collections.test.ts +131 -0
  87. package/src/schema/rls-bootstrap-sql.ts +288 -0
  88. package/src/security/anonymous-grants.test.ts +4 -2
  89. package/src/security/policy-drift.test.ts +11 -3
  90. package/src/security/rls-enforcement.ts +141 -3
  91. package/src/services/BranchService.ts +71 -28
  92. package/src/services/FetchService.ts +100 -107
  93. package/src/services/PersistService.ts +34 -7
  94. package/src/services/RelationService.ts +249 -48
  95. package/src/services/channel-bus/index.ts +0 -9
  96. package/src/services/channel-history.ts +8 -0
  97. package/src/services/channel-presence.ts +6 -0
  98. package/src/services/collection-helpers.ts +69 -3
  99. package/src/services/dataService.ts +5 -1
  100. package/src/services/realtimeService.ts +38 -35
  101. package/src/services/row-pipeline.ts +1 -1
  102. package/src/utils/connection-string.ts +58 -0
  103. package/src/utils/drizzle-conditions.ts +31 -6
  104. package/src/utils/pg-error-utils.ts +65 -0
  105. package/src/websocket.ts +18 -9
  106. package/dist/chunk-DSJWtz9O.js +0 -40
  107. package/dist/ensure-collection-tables-CNTcZGvn.js +0 -304
  108. package/dist/ensure-collection-tables-CNTcZGvn.js.map +0 -1
  109. package/dist/schema/auth-bootstrap-sql.d.ts +0 -24
  110. package/dist/src-BbFOPJ1S.js.map +0 -1
  111. package/dist/src-Zqwaw3P5.js.map +0 -1
  112. package/src/schema/auth-bootstrap-sql.ts +0 -47
@@ -1,5 +1,5 @@
1
1
  import type { StorageController } from "@rebasepro/server";
2
- import { BackupDestination, VersionCompatibility } from "./pg-tools";
2
+ import { BackupDestination, type RowSecurityIdentity, VersionCompatibility } from "./pg-tools";
3
3
  import { BackupObject, RetentionOptions } from "./retention";
4
4
  export declare class BackupToolError extends Error {
5
5
  readonly hint?: string | undefined;
@@ -54,6 +54,15 @@ export declare function createDump(opts: {
54
54
  inheritStdio?: boolean;
55
55
  includeGlobals?: boolean;
56
56
  env?: Record<string, string | undefined>;
57
+ /**
58
+ * Dump with row security left on, reading as this identity.
59
+ *
60
+ * The escape hatch for a managed Postgres, where the dumping role owns
61
+ * nothing and has no `BYPASSRLS`. Off by default, and deliberately so: with
62
+ * row security on, `pg_dump` stops erroring on rows it cannot see and
63
+ * simply omits them. See {@link RowSecurityIdentity}.
64
+ */
65
+ rowSecurity?: RowSecurityIdentity;
57
66
  }): Promise<BackupResult>;
58
67
  /**
59
68
  * Cheap integrity check on a freshly written dump: it must be non-empty and
@@ -79,6 +79,36 @@ export declare function parseBackupDestination(out: string): BackupDestination;
79
79
  * doubled slash.
80
80
  */
81
81
  export declare function joinStorageKey(prefix: string, fileName: string): string;
82
+ /**
83
+ * The identity `pg_dump` reads rows as, when row security is left on.
84
+ *
85
+ * Not optional, and that is the whole design. `pg_dump --enable-row-security`
86
+ * on its own is the dangerous command in this file: it turns the "query would
87
+ * be affected by row-level security policy" *error* into a dump that exits 0
88
+ * and is silently missing every row the dumping role's policies exclude. A
89
+ * backup that looks fine and restores most of your data is worse than one that
90
+ * refused to run.
91
+ *
92
+ * So the flag is unreachable without a subject to evaluate the policies
93
+ * against. Rebase's generated policies read `app.uid` and `app.user_roles`;
94
+ * supplying an admin role satisfies the `admin_full_access` rule and the dump
95
+ * sees everything that rule sees.
96
+ */
97
+ export interface RowSecurityIdentity {
98
+ /** Written to `app.uid`. Any non-empty value — it is only an audit trail. */
99
+ uid: string;
100
+ /** Written to `app.user_roles`. Must include a role the policies admit. */
101
+ roles: string[];
102
+ }
103
+ /**
104
+ * `PGOPTIONS` carrying an identity, for a libpq tool that has no other way to
105
+ * set a GUC.
106
+ *
107
+ * A backslash escape rather than quoting, which is what libpq's `-c` parsing
108
+ * takes: a space inside a value ends the option otherwise, so a role list is
109
+ * comma-joined and never spaced.
110
+ */
111
+ export declare function buildRowSecurityPgOptions(identity: RowSecurityIdentity): string;
82
112
  /**
83
113
  * Assemble the `pg_dump` argument vector. Uses the custom format (`-Fc`),
84
114
  * which is compressed and restorable selectively via `pg_restore`.
@@ -90,7 +120,24 @@ export declare function buildPgDumpArgs(opts: {
90
120
  excludeSchemas?: string[];
91
121
  /** Number of parallel jobs (directory format only; ignored for -Fc). */
92
122
  noOwner?: boolean;
123
+ /**
124
+ * Dump with row security on, as this identity. Omit — which is the default
125
+ * — and `pg_dump` errors rather than skipping rows it cannot see.
126
+ */
127
+ rowSecurity?: RowSecurityIdentity;
93
128
  }): string[];
129
+ /**
130
+ * Whether a `pg_dump` failure is the row-security one, and what to do about it.
131
+ *
132
+ * The error text names the table and nothing else, so the first read of it is
133
+ * "why would a backup be affected by RLS at all?" — the answer being that the
134
+ * dumping role is not the tables' owner and has no `BYPASSRLS`, which is the
135
+ * normal state of the `postgres` user on Cloud SQL, RDS and every other managed
136
+ * Postgres. Nothing about that is visible from the message.
137
+ *
138
+ * Returns `null` for any other failure, so the caller reports it unchanged.
139
+ */
140
+ export declare function diagnoseRowSecurityDumpFailure(error: unknown): string | null;
94
141
  /**
95
142
  * Assemble the `pg_restore` argument vector for a custom-format dump.
96
143
  */