@rebasepro/server-postgres 0.17.3 → 0.18.1
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/LICENSE +0 -1
- package/README.md +31 -0
- package/dist/BranchService-ByLfM_Tt.js +360 -0
- package/dist/BranchService-ByLfM_Tt.js.map +1 -0
- package/dist/__vite-browser-external-BnuHet1e.js +46 -0
- package/dist/__vite-browser-external-BnuHet1e.js.map +1 -0
- package/dist/arg-Dni7MzLB.js +87 -0
- package/dist/arg-Dni7MzLB.js.map +1 -0
- package/dist/auth-users-columns-D2LBFrMH.js +116 -0
- package/dist/auth-users-columns-D2LBFrMH.js.map +1 -0
- package/dist/backup-argv.d.ts +19 -0
- package/dist/backup-cli-oM9WQVlV.js +408 -0
- package/dist/backup-cli-oM9WQVlV.js.map +1 -0
- package/dist/backup-service-Br3tqwsy.js +715 -0
- package/dist/backup-service-Br3tqwsy.js.map +1 -0
- package/dist/branch-argv.d.ts +28 -0
- package/dist/branch-prune.d.ts +77 -0
- package/dist/cli-collections-path.d.ts +31 -0
- package/dist/cli-errors-DxN4yzdH.js +657 -0
- package/dist/cli-errors-DxN4yzdH.js.map +1 -0
- package/dist/cli-errors.d.ts +123 -0
- package/dist/cli-flags.d.ts +101 -0
- package/dist/cli-helpers.d.ts +94 -10
- package/dist/cli-output-CNdMql-L.js +47 -0
- package/dist/cli-output-CNdMql-L.js.map +1 -0
- package/dist/cli.js +2020 -0
- package/dist/cli.js.map +1 -0
- package/dist/collection-index-BHgT_TKd.js +276 -0
- package/dist/collection-index-BHgT_TKd.js.map +1 -0
- package/dist/{collections-schema-version-BMeu3cgv.js → collections-schema-version-T6cGvrDi.js} +1 -2
- package/dist/{collections-schema-version-BMeu3cgv.js.map → collections-schema-version-T6cGvrDi.js.map} +1 -1
- package/dist/{connection-GOKU3Hu5.js → databasePoolManager-Bj5FbeAs.js} +112 -40
- package/dist/databasePoolManager-Bj5FbeAs.js.map +1 -0
- package/dist/databasePoolManager.d.ts +27 -0
- package/dist/doctor-D7HWmGzs.js +974 -0
- package/dist/doctor-D7HWmGzs.js.map +1 -0
- package/dist/{ensure-collection-policies-UCqgv_8c.js → ensure-collection-policies-2c2NV8zX.js} +7 -27
- package/dist/ensure-collection-policies-2c2NV8zX.js.map +1 -0
- package/dist/ensure-collection-tables-D4wJzM4y.js +820 -0
- package/dist/ensure-collection-tables-D4wJzM4y.js.map +1 -0
- package/dist/ensure-tables-CIojK-Rx.js +650 -0
- package/dist/ensure-tables-CIojK-Rx.js.map +1 -0
- package/dist/generate-drizzle-schema-CwEgVyjO.js +123 -0
- package/dist/generate-drizzle-schema-CwEgVyjO.js.map +1 -0
- package/dist/generate-drizzle-schema-logic-so2Z_lyC.js +528 -0
- package/dist/generate-drizzle-schema-logic-so2Z_lyC.js.map +1 -0
- package/dist/{ensure-collection-tables-DgVixhX3.js → generate-postgres-ddl-logic-CtnpIBVv.js} +126 -984
- package/dist/generate-postgres-ddl-logic-CtnpIBVv.js.map +1 -0
- package/dist/generated-schema-staleness-DQdfJl2A.js +157 -0
- package/dist/generated-schema-staleness-DQdfJl2A.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.es.js +7423 -1133
- package/dist/index.es.js.map +1 -1
- package/dist/introspect-db-logic-C6LQdTxj.js +1378 -0
- package/dist/introspect-db-logic-C6LQdTxj.js.map +1 -0
- package/dist/policy-drift-kNJ6X2Uj.js +313 -0
- package/dist/policy-drift-kNJ6X2Uj.js.map +1 -0
- package/dist/{backup-service-DCk7KhhL.js → rls-bootstrap-sql-DLDnUjtx.js} +737 -2689
- package/dist/rls-bootstrap-sql-DLDnUjtx.js.map +1 -0
- package/dist/{rls-enforcement-DvAbL9YJ.js → rls-enforcement-DeYEjYLt.js} +65 -190
- package/dist/rls-enforcement-DeYEjYLt.js.map +1 -0
- package/dist/schema/bin/generate-drizzle-schema.d.ts +1 -0
- package/dist/schema/bin/generate-postgres-ddl.d.ts +1 -0
- package/dist/schema/column-type-drift.d.ts +79 -0
- package/dist/schema/doctor-cli.js +129 -0
- package/dist/schema/doctor-cli.js.map +1 -0
- package/dist/schema/doctor.d.ts +42 -0
- package/dist/schema/ensure-collection-tables.d.ts +90 -0
- package/dist/schema/generate-drizzle-schema.d.ts +1 -1
- package/dist/schema/generate-drizzle-schema.js +24 -0
- package/dist/schema/generate-drizzle-schema.js.map +1 -0
- package/dist/schema/generate-next-step.d.ts +30 -0
- package/dist/schema/generate-postgres-ddl-logic.d.ts +28 -0
- package/dist/schema/generate-postgres-ddl.d.ts +1 -1
- package/dist/schema/generate-postgres-ddl.js +138 -0
- package/dist/schema/generate-postgres-ddl.js.map +1 -0
- package/dist/schema/generated-schema-staleness.d.ts +37 -0
- package/dist/schema/introspect-db-queries.d.ts +34 -0
- package/dist/schema/introspect-db.js +866 -0
- package/dist/schema/introspect-db.js.map +1 -0
- package/dist/security/rls-enforcement.d.ts +63 -2
- package/dist/services/BranchService.d.ts +86 -1
- package/dist/services/collection-helpers.d.ts +1 -1
- package/dist/services/realtimeService.d.ts +30 -2
- package/dist/services/row-pipeline.d.ts +12 -1
- package/dist/source-Br7L7GOI.js +410 -0
- package/dist/source-Br7L7GOI.js.map +1 -0
- package/dist/utils/pg-error-utils.d.ts +3 -1
- package/dist/utils/pg-numeric-number-patch.d.ts +31 -0
- package/dist/vector-index-DkWxm2de.js +309 -0
- package/dist/vector-index-DkWxm2de.js.map +1 -0
- package/package.json +32 -27
- package/dist/backup-service-DCk7KhhL.js.map +0 -1
- package/dist/collection-index-BRUg10H5.js +0 -5690
- package/dist/collection-index-BRUg10H5.js.map +0 -1
- package/dist/connection-GOKU3Hu5.js.map +0 -1
- package/dist/ensure-collection-policies-UCqgv_8c.js.map +0 -1
- package/dist/ensure-collection-tables-DgVixhX3.js.map +0 -1
- package/dist/rls-bootstrap-sql-B5C9LoJ6.js +0 -244
- package/dist/rls-bootstrap-sql-B5C9LoJ6.js.map +0 -1
- package/dist/rls-enforcement-DvAbL9YJ.js.map +0 -1
- package/dist/src-DiB5RP2Z.js +0 -541
- package/dist/src-DiB5RP2Z.js.map +0 -1
- package/dist/websocket-BZ4H5wUz.js +0 -8198
- package/dist/websocket-BZ4H5wUz.js.map +0 -1
- package/src/PostgresAdapter.ts +0 -91
- package/src/PostgresBackendDriver.ts +0 -1857
- package/src/PostgresBootstrapper.ts +0 -1157
- package/src/auth/ensure-tables.ts +0 -896
- package/src/auth/schema-version.ts +0 -260
- package/src/auth/services.ts +0 -1610
- package/src/backup/backup-cli.ts +0 -520
- package/src/backup/backup-cron.ts +0 -212
- package/src/backup/backup-logic.ts +0 -93
- package/src/backup/backup-service.ts +0 -485
- package/src/backup/index.ts +0 -12
- package/src/backup/pg-tools.ts +0 -403
- package/src/backup/retention.ts +0 -86
- package/src/cli-errors.ts +0 -265
- package/src/cli-helpers.ts +0 -569
- package/src/cli-output.ts +0 -43
- package/src/cli.ts +0 -1339
- package/src/collections/PostgresCollectionRegistry.ts +0 -108
- package/src/collections/buildRegistry.ts +0 -68
- package/src/collections/validate-relations.ts +0 -402
- package/src/connection.ts +0 -333
- package/src/data-transformer.ts +0 -845
- package/src/databasePoolManager.ts +0 -95
- package/src/history/HistoryService.ts +0 -254
- package/src/history/ensure-history-table.ts +0 -53
- package/src/index.ts +0 -19
- package/src/interfaces.ts +0 -60
- package/src/module-dir.ts +0 -7
- package/src/schema/atlas-argv.ts +0 -94
- package/src/schema/auth-schema.ts +0 -298
- package/src/schema/auth-users-columns.ts +0 -131
- package/src/schema/carved-out-migration.ts +0 -404
- package/src/schema/classify-change.ts +0 -436
- package/src/schema/collection-index.ts +0 -427
- package/src/schema/collections-schema-version.ts +0 -103
- package/src/schema/destructive-sql.ts +0 -94
- package/src/schema/doctor-cli.ts +0 -66
- package/src/schema/doctor-policy-checks.ts +0 -105
- package/src/schema/doctor.ts +0 -837
- package/src/schema/drizzle-ddl.ts +0 -33
- package/src/schema/dynamic-tables.test.ts +0 -302
- package/src/schema/dynamic-tables.ts +0 -293
- package/src/schema/ensure-collection-policies.ts +0 -198
- package/src/schema/ensure-collection-tables.test.ts +0 -518
- package/src/schema/ensure-collection-tables.ts +0 -1267
- package/src/schema/generate-drizzle-schema-logic.ts +0 -957
- package/src/schema/generate-drizzle-schema.ts +0 -143
- package/src/schema/generate-postgres-ddl-logic.ts +0 -1339
- package/src/schema/generate-postgres-ddl.ts +0 -180
- package/src/schema/generate-schema-commit.ts +0 -267
- package/src/schema/generated-schema-staleness.ts +0 -284
- package/src/schema/introspect-db-constraints.ts +0 -385
- package/src/schema/introspect-db-inference.ts +0 -255
- package/src/schema/introspect-db-logic.ts +0 -1387
- package/src/schema/introspect-db-naming.ts +0 -15
- package/src/schema/introspect-db-project.ts +0 -78
- package/src/schema/introspect-db-queries.ts +0 -326
- package/src/schema/introspect-db-structure.ts +0 -670
- package/src/schema/introspect-db-types.ts +0 -56
- package/src/schema/introspect-db.ts +0 -257
- package/src/schema/introspect-runtime.test.ts +0 -260
- package/src/schema/introspect-runtime.ts +0 -327
- package/src/schema/non-sql-collections.test.ts +0 -131
- package/src/schema/rls-bootstrap-sql.ts +0 -288
- package/src/schema/search-column.ts +0 -643
- package/src/schema/test-schema.ts +0 -11
- package/src/schema/vector-index.ts +0 -491
- package/src/security/anonymous-grants.test.ts +0 -73
- package/src/security/policy-drift.test.ts +0 -435
- package/src/security/policy-drift.ts +0 -473
- package/src/security/rls-enforcement.ts +0 -505
- package/src/services/BranchService.ts +0 -326
- package/src/services/FetchService.ts +0 -2115
- package/src/services/PersistService.ts +0 -557
- package/src/services/RelationService.ts +0 -978
- package/src/services/RelationWriteService.ts +0 -653
- package/src/services/cdc/CdcListener.ts +0 -103
- package/src/services/cdc/junction-tables.ts +0 -91
- package/src/services/cdc/trigger-cdc.ts +0 -173
- package/src/services/channel-bus/ChannelBus.ts +0 -44
- package/src/services/channel-bus/PostgresChannelBus.ts +0 -299
- package/src/services/channel-bus/index.ts +0 -114
- package/src/services/channel-history.ts +0 -424
- package/src/services/channel-presence.ts +0 -185
- package/src/services/collection-helpers.ts +0 -420
- package/src/services/dataService.ts +0 -256
- package/src/services/index.ts +0 -14
- package/src/services/junction-writes.ts +0 -295
- package/src/services/nested-path.ts +0 -145
- package/src/services/pg-notify-listener.ts +0 -151
- package/src/services/realtimeService.ts +0 -2545
- package/src/services/row-pipeline.ts +0 -240
- package/src/services/write-denial.ts +0 -55
- package/src/types.ts +0 -4
- package/src/utils/connection-string.ts +0 -58
- package/src/utils/drizzle-conditions.ts +0 -2743
- package/src/utils/pg-array-null-patch.ts +0 -42
- package/src/utils/pg-error-utils.ts +0 -391
- package/src/websocket.ts +0 -855
package/src/schema/doctor-cli.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* CLI entry point for `rebase doctor`.
|
|
4
|
-
* Invoked via tsx by the server-postgres CLI plugin.
|
|
5
|
-
*/
|
|
6
|
-
import path from "path";
|
|
7
|
-
import chalk from "chalk";
|
|
8
|
-
import { runDoctor } from "./doctor";
|
|
9
|
-
import { exitCodeForPolicyGate, runPolicyChecks } from "./doctor-policy-checks";
|
|
10
|
-
|
|
11
|
-
async function main() {
|
|
12
|
-
const collectionsArg = process.argv.find((a) => a.startsWith("--collections="));
|
|
13
|
-
const schemaArg = process.argv.find((a) => a.startsWith("--schema="));
|
|
14
|
-
const sdkArg = process.argv.find((a) => a.startsWith("--sdk="));
|
|
15
|
-
// --policies runs only the RLS checks: no schema diff, no SDK types. Useful
|
|
16
|
-
// as a CI gate against a deployed database, where the collection files and
|
|
17
|
-
// generated schema are not what you are asking about.
|
|
18
|
-
const policiesOnly = process.argv.includes("--policies");
|
|
19
|
-
|
|
20
|
-
const collectionsPath = collectionsArg?.split("=")[1] ?? path.join("..", "config", "collections");
|
|
21
|
-
const schemaPath = schemaArg?.split("=")[1] ?? path.join("src", "schema.generated.ts");
|
|
22
|
-
const sdkPath = sdkArg?.split("=")[1] ?? path.join("..", "generated", "sdk", "database.types.ts");
|
|
23
|
-
|
|
24
|
-
// Load .env
|
|
25
|
-
try {
|
|
26
|
-
const dotenv = await import("dotenv");
|
|
27
|
-
const envPath = process.env.DOTENV_CONFIG_PATH;
|
|
28
|
-
if (envPath) {
|
|
29
|
-
dotenv.config({ path: envPath, quiet: true });
|
|
30
|
-
} else {
|
|
31
|
-
dotenv.config({ quiet: true });
|
|
32
|
-
}
|
|
33
|
-
} catch {
|
|
34
|
-
// dotenv may not be installed
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const databaseUrl = process.env.DATABASE_URL || process.env.ADMIN_CONNECTION_STRING;
|
|
38
|
-
|
|
39
|
-
if (policiesOnly) {
|
|
40
|
-
// Non-zero so this can gate CI — the whole point of the flag, and a
|
|
41
|
-
// check that could not run has not passed. See exitCodeForPolicyGate.
|
|
42
|
-
process.exit(exitCodeForPolicyGate(await runPolicyChecks(collectionsPath, databaseUrl)));
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const report = await runDoctor({
|
|
46
|
-
collectionsPath: path.resolve(process.cwd(), collectionsPath),
|
|
47
|
-
schemaPath: path.resolve(process.cwd(), schemaPath),
|
|
48
|
-
sdkPath: path.resolve(process.cwd(), sdkPath),
|
|
49
|
-
databaseUrl: databaseUrl ?? undefined
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
const policyStatus = await runPolicyChecks(collectionsPath, databaseUrl);
|
|
53
|
-
|
|
54
|
-
// Exit non-zero if there are errors. A policy run that could not happen is
|
|
55
|
-
// reported loudly above but does not fail the interactive command — the
|
|
56
|
-
// same treatment the skipped database phase gets. `--policies` is the gate,
|
|
57
|
-
// and that one fails closed.
|
|
58
|
-
if (report.summary.errors > 0 || policyStatus === "problems") {
|
|
59
|
-
process.exit(1);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
main().catch((err) => {
|
|
64
|
-
console.error(chalk.red(" ✗ Doctor failed"), err instanceof Error ? (err.stack ?? err.message) : String(err));
|
|
65
|
-
process.exit(1);
|
|
66
|
-
});
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The RLS half of `rebase doctor`, and the exit code `--policies` gates CI on.
|
|
3
|
-
*
|
|
4
|
-
* Lives beside `doctor-cli.ts` rather than inside it because that file runs
|
|
5
|
-
* `main()` on import: a gate whose failure modes cannot be unit-tested is how
|
|
6
|
-
* this one shipped reporting success for work it never did.
|
|
7
|
-
*/
|
|
8
|
-
import path from "path";
|
|
9
|
-
import chalk from "chalk";
|
|
10
|
-
import { CollectionConfig } from "@rebasepro/types";
|
|
11
|
-
import { loadCollections } from "./doctor";
|
|
12
|
-
import { checkPolicyDrift, formatPolicyDrift, hasDrift } from "../security/policy-drift";
|
|
13
|
-
import { validatePolicyPgRoles, warnOnAnonymousGrants } from "../security/rls-enforcement";
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* What the RLS checks concluded.
|
|
17
|
-
*
|
|
18
|
-
* `unchecked` exists because "we could not look" and "we looked and it is fine"
|
|
19
|
-
* used to be reported identically: a collections path that did not resolve made
|
|
20
|
-
* the loader return `[]` (it warns, it does not throw), `checkPolicyDrift`
|
|
21
|
-
* early-returned an empty diff, and the gate printed
|
|
22
|
-
* `✓ RLS policies match your collections` having compared zero policies against
|
|
23
|
-
* zero collections. Any exception at all — a collection file that throws on
|
|
24
|
-
* import, a `pg_policies` read the CI role is not granted, a connection reset —
|
|
25
|
-
* did the same thing through a `warn`, and exited 0.
|
|
26
|
-
*/
|
|
27
|
-
export type PolicyCheckStatus = "ok" | "problems" | "unchecked";
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* The exit code for `rebase doctor --policies`.
|
|
31
|
-
*
|
|
32
|
-
* A gate that could not run has not passed. Only a completed, clean check
|
|
33
|
-
* exits 0 — anything else, including "we never opened a connection", is a
|
|
34
|
-
* failure, or the flag certifies a database nobody looked at.
|
|
35
|
-
*/
|
|
36
|
-
export function exitCodeForPolicyGate(status: PolicyCheckStatus): 0 | 1 {
|
|
37
|
-
return status === "ok" ? 0 : 1;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Policies actually deployed vs the ones the collections describe, plus policy
|
|
42
|
-
* roles this server could never satisfy.
|
|
43
|
-
*
|
|
44
|
-
* Never reports `ok` for work it did not do — see {@link PolicyCheckStatus}.
|
|
45
|
-
*/
|
|
46
|
-
export async function runPolicyChecks(collectionsPath: string, databaseUrl?: string): Promise<PolicyCheckStatus> {
|
|
47
|
-
if (!databaseUrl) {
|
|
48
|
-
console.error(chalk.yellow(" ⚠ No DATABASE_URL — RLS policies were NOT checked"));
|
|
49
|
-
return "unchecked";
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const resolvedPath = path.resolve(process.cwd(), collectionsPath);
|
|
53
|
-
let problems = false;
|
|
54
|
-
const { Pool } = await import("pg");
|
|
55
|
-
const pool = new Pool({ connectionString: databaseUrl });
|
|
56
|
-
try {
|
|
57
|
-
const collections: CollectionConfig[] = await loadCollections(resolvedPath);
|
|
58
|
-
|
|
59
|
-
// Zero collections is not "no drift", it is nothing to compare. The
|
|
60
|
-
// loader returns `[]` for a path that does not exist, so the commonest
|
|
61
|
-
// way to get here is a `--collections` path resolved against the wrong
|
|
62
|
-
// directory — which used to render as a green tick.
|
|
63
|
-
if (collections.length === 0) {
|
|
64
|
-
console.error(chalk.red(` ✗ No collections found in ${resolvedPath}`));
|
|
65
|
-
console.error(chalk.gray(" RLS policies were NOT checked. Pass --collections=<dir> if your collections live elsewhere."));
|
|
66
|
-
return "unchecked";
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const runSql = async (text: string) => (await pool.query(text)).rows as Record<string, unknown>[];
|
|
70
|
-
|
|
71
|
-
// A policy naming a role the server never runs as filters every row, so
|
|
72
|
-
// the collection reads as empty. Report it without booting a server.
|
|
73
|
-
try {
|
|
74
|
-
await validatePolicyPgRoles(runSql, collections as never);
|
|
75
|
-
console.log(chalk.green(" ✓ Policy roles are usable by this server"));
|
|
76
|
-
} catch (err) {
|
|
77
|
-
problems = true;
|
|
78
|
-
console.log("");
|
|
79
|
-
console.error(chalk.red(err instanceof Error ? err.message : String(err)));
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// A rule that reads as a lockdown but is true for every caller compiles
|
|
83
|
-
// to a grant. Report it without booting a server.
|
|
84
|
-
warnOnAnonymousGrants(collections as never);
|
|
85
|
-
|
|
86
|
-
const drift = await checkPolicyDrift(pool as never, collections);
|
|
87
|
-
console.log("");
|
|
88
|
-
if (hasDrift(drift)) {
|
|
89
|
-
problems = true;
|
|
90
|
-
console.log(chalk.yellow(" RLS policies: database does not match your collections"));
|
|
91
|
-
console.log(formatPolicyDrift(drift));
|
|
92
|
-
} else {
|
|
93
|
-
console.log(chalk.green(` ✓ RLS policies match your collections (${collections.length} collection(s) checked)`));
|
|
94
|
-
}
|
|
95
|
-
} catch (err) {
|
|
96
|
-
// Fail closed. This catch covers every query and every collection import
|
|
97
|
-
// above, so returning the pre-catch verdict made the documented CI gate
|
|
98
|
-
// green on exactly the runs it exists to catch.
|
|
99
|
-
console.error(chalk.red(" ✗ Could not check RLS policies:"), err instanceof Error ? err.message : String(err));
|
|
100
|
-
return "unchecked";
|
|
101
|
-
} finally {
|
|
102
|
-
await pool.end();
|
|
103
|
-
}
|
|
104
|
-
return problems ? "problems" : "ok";
|
|
105
|
-
}
|