@rebasepro/server-postgres 0.24.0 → 0.24.1-canary.gcb918fc
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 +16 -0
- package/dist/{BranchService-BRt78gfa.js → BranchService-Bsn2wfaj.js} +3 -2
- package/dist/{BranchService-BRt78gfa.js.map → BranchService-Bsn2wfaj.js.map} +1 -1
- package/dist/PostgresBackendDriver.d.ts +91 -2
- package/dist/PostgresBootstrapper.d.ts +101 -2
- package/dist/auth/ensure-tables.d.ts +12 -0
- package/dist/auth/services.d.ts +6 -0
- package/dist/backup/backup-cli.d.ts +14 -0
- package/dist/backup/backup-service.d.ts +2 -2
- package/dist/backup/pg-binary.d.ts +5 -0
- package/dist/{backup-cli-DW5p9_zv.js → backup-cli-DnpJi6I7.js} +37 -29
- package/dist/backup-cli-DnpJi6I7.js.map +1 -0
- package/dist/{backup-service-EwcDVG-8.js → backup-service-BTBB7RXn.js} +55 -21
- package/dist/backup-service-BTBB7RXn.js.map +1 -0
- package/dist/boot-ddl-DVpsFN6r.js +105 -0
- package/dist/boot-ddl-DVpsFN6r.js.map +1 -0
- package/dist/cli-console-Ca6ZlAVU.js +154 -0
- package/dist/cli-console-Ca6ZlAVU.js.map +1 -0
- package/dist/cli-console.d.ts +39 -0
- package/dist/cli-errors-CaI4ntyD.js +1919 -0
- package/dist/cli-errors-CaI4ntyD.js.map +1 -0
- package/dist/cli-errors.d.ts +51 -5
- package/dist/{cli-flags-BglvpjHv.js → cli-flags-JNI-pwSf.js} +6 -3
- package/dist/cli-flags-JNI-pwSf.js.map +1 -0
- package/dist/cli-helpers.d.ts +40 -0
- package/dist/cli-output.d.ts +16 -28
- package/dist/cli-push.d.ts +87 -0
- package/dist/cli.js +566 -182
- package/dist/cli.js.map +1 -1
- package/dist/{column-plan-helpers-1-LQD0yI.js → column-plan-helpers-drZIsSNf.js} +10 -4
- package/dist/{column-plan-helpers-1-LQD0yI.js.map → column-plan-helpers-drZIsSNf.js.map} +1 -1
- package/dist/{databasePoolManager-Bj5FbeAs.js → connection-C9mT8bgf.js} +24 -112
- package/dist/connection-C9mT8bgf.js.map +1 -0
- package/dist/connection.d.ts +13 -2
- package/dist/databasePoolManager-BIuewidb.js +119 -0
- package/dist/databasePoolManager-BIuewidb.js.map +1 -0
- package/dist/{ensure-collection-tables-kkkHk8oo.js → deferred-index-build-DP1_SNFo.js} +484 -346
- package/dist/deferred-index-build-DP1_SNFo.js.map +1 -0
- package/dist/{doctor-C-sYWbmt.js → doctor-C4WiftHm.js} +63 -52
- package/dist/doctor-C4WiftHm.js.map +1 -0
- package/dist/ensure-collection-policies-CXpbeNag.js +541 -0
- package/dist/ensure-collection-policies-CXpbeNag.js.map +1 -0
- package/dist/ensure-collection-tables-BhsU6qUE.js +532 -0
- package/dist/ensure-collection-tables-BhsU6qUE.js.map +1 -0
- package/dist/{ensure-tables-BmI_tRxc.js → ensure-tables-CVm_yvzb.js} +173 -77
- package/dist/ensure-tables-CVm_yvzb.js.map +1 -0
- package/dist/enum-labels-kept-D8fI1MoX.js +56 -0
- package/dist/enum-labels-kept-D8fI1MoX.js.map +1 -0
- package/dist/generate-drizzle-schema-Bz52jH2h.js +57 -0
- package/dist/generate-drizzle-schema-Bz52jH2h.js.map +1 -0
- package/dist/{generate-drizzle-schema-logic-sSFDp6LR.js → generate-drizzle-schema-logic-B74WN37S.js} +5 -5
- package/dist/generate-drizzle-schema-logic-B74WN37S.js.map +1 -0
- package/dist/generate-files-CdEckX6c.js +199 -0
- package/dist/generate-files-CdEckX6c.js.map +1 -0
- package/dist/{generate-postgres-ddl-logic-BJsLaVNX.js → generate-postgres-ddl-logic-B64O2oZF.js} +3 -3
- package/dist/{generate-postgres-ddl-logic-BJsLaVNX.js.map → generate-postgres-ddl-logic-B64O2oZF.js.map} +1 -1
- package/dist/generated-sql.d.ts +8 -2
- package/dist/history/HistoryService.d.ts +64 -5
- package/dist/history/ensure-history-table.d.ts +63 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +139 -19236
- package/dist/index.es.js.map +1 -1
- package/dist/{introspect-db-logic-kCETE8TY.js → introspect-db-logic-C-Di8dA9.js} +44 -6
- package/dist/introspect-db-logic-C-Di8dA9.js.map +1 -0
- package/dist/{introspect-db-queries-C_Q5VgQw.js → introspect-db-queries-D6kAqReI.js} +23 -1
- package/dist/introspect-db-queries-D6kAqReI.js.map +1 -0
- package/dist/open-rebase-CbOur0TU.js +20858 -0
- package/dist/open-rebase-CbOur0TU.js.map +1 -0
- package/dist/open-rebase.d.ts +86 -0
- package/dist/pg-error-utils-vJezlXdI.js +388 -0
- package/dist/pg-error-utils-vJezlXdI.js.map +1 -0
- package/dist/{plan-schema-DU9exq6C.js → plan-schema-B1YF_tYq.js} +151 -41
- package/dist/plan-schema-B1YF_tYq.js.map +1 -0
- package/dist/{policy-drift-B-J2hhm0.js → policy-drift-Dm8i-s1J.js} +23 -6
- package/dist/policy-drift-Dm8i-s1J.js.map +1 -0
- package/dist/push-index-prebuild-Db4AQF4i.js +45 -0
- package/dist/push-index-prebuild-Db4AQF4i.js.map +1 -0
- package/dist/push-legacy-renames-BK6ilQq2.js +34 -0
- package/dist/push-legacy-renames-BK6ilQq2.js.map +1 -0
- package/dist/{render-ddl-Ds2t_d9V.js → render-ddl-CtC3y9Ol.js} +8 -4
- package/dist/render-ddl-CtC3y9Ol.js.map +1 -0
- package/dist/{rls-bootstrap-sql-_KNnjanK.js → rls-bootstrap-sql-RQUljnJ1.js} +125 -1270
- package/dist/rls-bootstrap-sql-RQUljnJ1.js.map +1 -0
- package/dist/{rls-enforcement-CfXOJJaW.js → rls-enforcement-DvzqlaL1.js} +129 -17
- package/dist/rls-enforcement-DvzqlaL1.js.map +1 -0
- package/dist/schema/auth-schema.d.ts +2 -2
- package/dist/schema/boot-ddl.d.ts +47 -0
- package/dist/schema/collection-index.d.ts +45 -0
- package/dist/schema/column-plan-helpers.d.ts +5 -0
- package/dist/schema/deferred-index-build.d.ts +131 -0
- package/dist/schema/destructive-sql.d.ts +7 -0
- package/dist/schema/doctor-cli.js +110 -6
- package/dist/schema/doctor-cli.js.map +1 -1
- package/dist/schema/doctor-search-scale.d.ts +45 -0
- package/dist/schema/doctor.d.ts +20 -1
- package/dist/schema/ensure-collection-policies.d.ts +73 -35
- package/dist/schema/ensure-collection-tables.d.ts +56 -3
- package/dist/schema/enum-labels-kept.d.ts +26 -0
- package/dist/schema/generate-drizzle-schema.js +1 -1
- package/dist/schema/generate-files.d.ts +44 -0
- package/dist/schema/generate-next-step.d.ts +0 -13
- package/dist/schema/generate-postgres-ddl.js +10 -81
- package/dist/schema/generate-postgres-ddl.js.map +1 -1
- package/dist/schema/introspect-db-logic.d.ts +12 -0
- package/dist/schema/introspect-db-queries.d.ts +11 -1
- package/dist/schema/introspect-db-structure.d.ts +10 -0
- package/dist/schema/introspect-db.js +4 -5
- package/dist/schema/introspect-db.js.map +1 -1
- package/dist/schema/migration-post-process.d.ts +34 -0
- package/dist/schema/plan/diff-plan.d.ts +126 -0
- package/dist/schema/plan/types.d.ts +8 -0
- package/dist/schema/push-index-prebuild.d.ts +25 -0
- package/dist/schema/push-legacy-renames.d.ts +20 -0
- package/dist/schema/rls-bootstrap-sql.d.ts +15 -0
- package/dist/security/rls-enforcement.d.ts +32 -4
- package/dist/services/FetchService.d.ts +58 -8
- package/dist/services/PersistService.d.ts +15 -0
- package/dist/services/RelationService.d.ts +88 -3
- package/dist/services/cdc/CdcListener.d.ts +17 -6
- package/dist/services/cdc/trigger-cdc.d.ts +151 -27
- package/dist/services/channel-bus/index.d.ts +1 -1
- package/dist/services/channel-history.d.ts +15 -4
- package/dist/services/collection-helpers.d.ts +15 -0
- package/dist/services/field-viewer.d.ts +15 -1
- package/dist/services/pg-notify-listener.d.ts +7 -0
- package/dist/services/realtimeService.d.ts +314 -14
- package/dist/services/row-pipeline.d.ts +16 -9
- package/dist/services/socket-liveness.d.ts +42 -2
- package/dist/services/sql-script.d.ts +207 -3
- package/dist/services/vector-iterative-scan.d.ts +40 -0
- package/dist/services/write-depth.d.ts +6 -0
- package/dist/services/write-transaction-scope.d.ts +9 -0
- package/dist/socket-opt-ins.d.ts +64 -0
- package/dist/source-DBDbBTL4.js +811 -0
- package/dist/source-DBDbBTL4.js.map +1 -0
- package/dist/tsx-loader.d.ts +14 -0
- package/dist/utils/drizzle-conditions.d.ts +21 -1
- package/dist/utils/error-cause.d.ts +7 -0
- package/dist/utils/pg-error-utils.d.ts +2 -4
- package/dist/utils/result-rows.d.ts +10 -0
- package/dist/websocket-BLGc5yhs.js +1604 -0
- package/dist/websocket-BLGc5yhs.js.map +1 -0
- package/dist/websocket.d.ts +13 -0
- package/package.json +7 -7
- package/dist/backup-cli-DW5p9_zv.js.map +0 -1
- package/dist/backup-service-EwcDVG-8.js.map +0 -1
- package/dist/cli-errors-DsA-K9uP.js +0 -893
- package/dist/cli-errors-DsA-K9uP.js.map +0 -1
- package/dist/cli-flags-BglvpjHv.js.map +0 -1
- package/dist/cli-output-CNdMql-L.js +0 -47
- package/dist/cli-output-CNdMql-L.js.map +0 -1
- package/dist/collection-index-DdnsxiJ_.js +0 -286
- package/dist/collection-index-DdnsxiJ_.js.map +0 -1
- package/dist/databasePoolManager-Bj5FbeAs.js.map +0 -1
- package/dist/doctor-C-sYWbmt.js.map +0 -1
- package/dist/ensure-collection-policies-B1ureSIV.js +0 -160
- package/dist/ensure-collection-policies-B1ureSIV.js.map +0 -1
- package/dist/ensure-collection-tables-kkkHk8oo.js.map +0 -1
- package/dist/ensure-tables-BmI_tRxc.js.map +0 -1
- package/dist/generate-drizzle-schema-93M0lUxK.js +0 -123
- package/dist/generate-drizzle-schema-93M0lUxK.js.map +0 -1
- package/dist/generate-drizzle-schema-logic-sSFDp6LR.js.map +0 -1
- package/dist/introspect-db-logic-kCETE8TY.js.map +0 -1
- package/dist/introspect-db-queries-C_Q5VgQw.js.map +0 -1
- package/dist/plan-schema-DU9exq6C.js.map +0 -1
- package/dist/policy-drift-B-J2hhm0.js.map +0 -1
- package/dist/render-ddl-Ds2t_d9V.js.map +0 -1
- package/dist/rls-bootstrap-sql-_KNnjanK.js.map +0 -1
- package/dist/rls-enforcement-CfXOJJaW.js.map +0 -1
- package/dist/source-Br7L7GOI.js +0 -410
- package/dist/source-Br7L7GOI.js.map +0 -1
- package/dist/utils/sql-redaction.d.ts +0 -21
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from "module";
|
|
2
|
+
__createRequire(import.meta.url);
|
|
3
|
+
import { a as __toESM } from "./__vite-browser-external-BnuHet1e.js";
|
|
4
|
+
import { l as poolMaxCeiling } from "./connection-C9mT8bgf.js";
|
|
5
|
+
import { t as openRebase } from "./open-rebase-CbOur0TU.js";
|
|
6
|
+
import { i as outError, n as describeFailure, r as out } from "./source-DBDbBTL4.js";
|
|
7
|
+
import { t as require_arg } from "./arg-Dni7MzLB.js";
|
|
8
|
+
import { t as RELAYED_FLAGS } from "./cli-flags-JNI-pwSf.js";
|
|
9
|
+
import path from "path";
|
|
10
|
+
import fs from "fs";
|
|
11
|
+
import { inspect } from "node:util";
|
|
12
|
+
import repl from "node:repl";
|
|
13
|
+
//#region src/cli-console.ts
|
|
14
|
+
var import_arg = /* @__PURE__ */ __toESM(require_arg(), 1);
|
|
15
|
+
/**
|
|
16
|
+
* The flags `rebase console` takes. `--history` is the CLI's own: where it
|
|
17
|
+
* keeps the REPL's history (`.rebase/console_history` in the project).
|
|
18
|
+
*/
|
|
19
|
+
var CONSOLE_FLAGS = {
|
|
20
|
+
"--collections": String,
|
|
21
|
+
"-c": "--collections",
|
|
22
|
+
"--eval": String,
|
|
23
|
+
"-e": "--eval",
|
|
24
|
+
"--history": String
|
|
25
|
+
};
|
|
26
|
+
/** The constructor of `async function` — what `new Function` is for a body that awaits. */
|
|
27
|
+
var AsyncFunction = Object.getPrototypeOf(async () => void 0).constructor;
|
|
28
|
+
/**
|
|
29
|
+
* Run `code` with `rebase` and `collections` in scope and resolve with its
|
|
30
|
+
* value.
|
|
31
|
+
*
|
|
32
|
+
* Read as an expression first, so `rebase.dataAsAdmin.posts.find()` is its own
|
|
33
|
+
* result; code that is not one expression runs as a function body, where
|
|
34
|
+
* `await` works everywhere and `return` gives the result.
|
|
35
|
+
*/
|
|
36
|
+
async function evaluateInConsole(code, scope) {
|
|
37
|
+
let run;
|
|
38
|
+
try {
|
|
39
|
+
run = new AsyncFunction("rebase", "collections", `return (${code}\n);`);
|
|
40
|
+
} catch (error) {
|
|
41
|
+
if (!(error instanceof SyntaxError)) throw error;
|
|
42
|
+
run = new AsyncFunction("rebase", "collections", code);
|
|
43
|
+
}
|
|
44
|
+
return run(scope.rebase, scope.collections);
|
|
45
|
+
}
|
|
46
|
+
/** A result as JSON, the way `--eval` prints it: dates as ISO strings, bigints as strings. */
|
|
47
|
+
function consoleJson(value) {
|
|
48
|
+
return JSON.stringify(value, (_key, item) => typeof item === "bigint" ? item.toString() : item, 2) ?? "undefined";
|
|
49
|
+
}
|
|
50
|
+
/** The host and database a URL names, for the banner — never its credentials. */
|
|
51
|
+
function describeDatabase(databaseUrl) {
|
|
52
|
+
try {
|
|
53
|
+
const url = new URL(databaseUrl);
|
|
54
|
+
return `${url.hostname}${url.port ? `:${url.port}` : ""}${url.pathname}`;
|
|
55
|
+
} catch {
|
|
56
|
+
return "the configured database";
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* `rebase console [--eval <code>] [--collections <dir>]`, from the driver
|
|
61
|
+
* line `["console", …flags]`. Resolves with the exit code.
|
|
62
|
+
*/
|
|
63
|
+
async function consoleCommand(args, streams = {}) {
|
|
64
|
+
const flags = (0, import_arg.default)({
|
|
65
|
+
...RELAYED_FLAGS,
|
|
66
|
+
...CONSOLE_FLAGS
|
|
67
|
+
}, { argv: args.slice(1) });
|
|
68
|
+
if (flags["--help"]) {
|
|
69
|
+
out("Run `rebase console --help` for the options — this is the driver's own entry point.");
|
|
70
|
+
return 0;
|
|
71
|
+
}
|
|
72
|
+
const databaseUrl = flags["--database-url"] || process.env.DATABASE_URL;
|
|
73
|
+
if (!databaseUrl) {
|
|
74
|
+
outError("✗ No database to open: DATABASE_URL is not set. Set it in .env, or pass --database-url.");
|
|
75
|
+
return 1;
|
|
76
|
+
}
|
|
77
|
+
if (process.env.LOG_LEVEL === void 0) process.env.LOG_LEVEL = "warn";
|
|
78
|
+
const collectionsPath = path.resolve(flags["--collections"] || path.join("..", "config", "collections"));
|
|
79
|
+
const { loadCollections } = await import("./doctor-C4WiftHm.js").then((n) => n.t);
|
|
80
|
+
const collections = fs.existsSync(collectionsPath) ? await loadCollections(collectionsPath) : [];
|
|
81
|
+
const ceiling = poolMaxCeiling();
|
|
82
|
+
const rebase = await openRebase({
|
|
83
|
+
databaseUrl,
|
|
84
|
+
collections,
|
|
85
|
+
...ceiling !== null ? { pool: { max: ceiling } } : {}
|
|
86
|
+
});
|
|
87
|
+
try {
|
|
88
|
+
const code = flags["--eval"];
|
|
89
|
+
if (code !== void 0) try {
|
|
90
|
+
const result = await evaluateInConsole(code, {
|
|
91
|
+
rebase,
|
|
92
|
+
collections: rebase.collections
|
|
93
|
+
});
|
|
94
|
+
if (result !== void 0) out(consoleJson(result));
|
|
95
|
+
return 0;
|
|
96
|
+
} catch (error) {
|
|
97
|
+
outError(describeFailure(error));
|
|
98
|
+
return 1;
|
|
99
|
+
}
|
|
100
|
+
await startRepl({
|
|
101
|
+
rebase,
|
|
102
|
+
collections: rebase.collections
|
|
103
|
+
}, {
|
|
104
|
+
history: flags["--history"],
|
|
105
|
+
database: describeDatabase(databaseUrl),
|
|
106
|
+
...streams
|
|
107
|
+
});
|
|
108
|
+
return 0;
|
|
109
|
+
} finally {
|
|
110
|
+
await rebase.close();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/** The interactive half: a Node REPL until `.exit` or Ctrl-D. */
|
|
114
|
+
async function startRepl(scope, options) {
|
|
115
|
+
out("");
|
|
116
|
+
out(` rebase console — ${options.database}, ${scope.collections.length} collection(s)`);
|
|
117
|
+
out(" In scope: rebase (dataAsAdmin, sql, withAuth, close) and collections. Top-level await works.");
|
|
118
|
+
out(" Try: await rebase.dataAsAdmin.<collection>.find({ limit: 5 })");
|
|
119
|
+
out("");
|
|
120
|
+
const interactive = options.input === void 0;
|
|
121
|
+
const server = repl.start({
|
|
122
|
+
prompt: "",
|
|
123
|
+
useGlobal: false,
|
|
124
|
+
...options.input ? {
|
|
125
|
+
input: options.input,
|
|
126
|
+
terminal: false
|
|
127
|
+
} : {},
|
|
128
|
+
...options.output ? { output: options.output } : {},
|
|
129
|
+
writer: (value) => inspect(value, {
|
|
130
|
+
colors: interactive,
|
|
131
|
+
depth: 6
|
|
132
|
+
})
|
|
133
|
+
});
|
|
134
|
+
server.context.rebase = scope.rebase;
|
|
135
|
+
server.context.collections = scope.collections;
|
|
136
|
+
server.setPrompt("rebase> ");
|
|
137
|
+
const history = options.history;
|
|
138
|
+
if (history) {
|
|
139
|
+
fs.mkdirSync(path.dirname(history), { recursive: true });
|
|
140
|
+
await new Promise((resolve) => {
|
|
141
|
+
server.setupHistory(history, (error) => {
|
|
142
|
+
if (error) outError(` (history is off: ${error.message})`);
|
|
143
|
+
resolve();
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
const exited = new Promise((resolve) => server.once("exit", () => resolve()));
|
|
148
|
+
server.displayPrompt();
|
|
149
|
+
await exited;
|
|
150
|
+
}
|
|
151
|
+
//#endregion
|
|
152
|
+
export { consoleCommand };
|
|
153
|
+
|
|
154
|
+
//# sourceMappingURL=cli-console-Ca6ZlAVU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-console-Ca6ZlAVU.js","names":[],"sources":["../src/cli-console.ts"],"sourcesContent":["/**\n * `rebase console` — the driver's half.\n *\n * Loads the project's collections the way `rebase db push` does, opens the\n * database with {@link openRebase}, and either evaluates one piece of code\n * (`--eval`) or starts a Node REPL with `rebase` and `collections` in scope.\n * The `rebase` CLI resolves the database first (the managed one included) and\n * hands this process `DATABASE_URL`, exactly as it does for `db` commands.\n *\n * This is the boot side of `openRebase`: it is where the environment is read\n * — `DATABASE_URL`, and the `REBASE_DB_POOL_MAX` ceiling the managed\n * development database needs — and turned into explicit options.\n */\nimport arg from \"arg\";\nimport fs from \"fs\";\nimport path from \"path\";\nimport repl from \"node:repl\";\nimport { inspect } from \"node:util\";\nimport type { CollectionConfig } from \"@rebasepro/types\";\nimport { RELAYED_FLAGS } from \"./cli-flags\";\nimport { out, outError, describeFailure } from \"./cli-output\";\nimport { poolMaxCeiling } from \"./connection\";\nimport { openRebase, type OpenedRebase } from \"./open-rebase\";\n\n/**\n * The flags `rebase console` takes. `--history` is the CLI's own: where it\n * keeps the REPL's history (`.rebase/console_history` in the project).\n */\nexport const CONSOLE_FLAGS = {\n \"--collections\": String,\n \"-c\": \"--collections\",\n \"--eval\": String,\n \"-e\": \"--eval\",\n \"--history\": String\n} satisfies arg.Spec;\n\n/** What the code the console runs can name. */\nexport interface ConsoleScope {\n rebase: OpenedRebase;\n collections: CollectionConfig[];\n}\n\ntype ScopedFunction = (rebase: OpenedRebase, collections: CollectionConfig[]) => Promise<unknown>;\ntype AsyncFunctionConstructor = new (...parameters: string[]) => ScopedFunction;\n\n/** The constructor of `async function` — what `new Function` is for a body that awaits. */\nconst AsyncFunction: AsyncFunctionConstructor = Object.getPrototypeOf(async () => undefined).constructor;\n\n/**\n * Run `code` with `rebase` and `collections` in scope and resolve with its\n * value.\n *\n * Read as an expression first, so `rebase.dataAsAdmin.posts.find()` is its own\n * result; code that is not one expression runs as a function body, where\n * `await` works everywhere and `return` gives the result.\n */\nexport async function evaluateInConsole(code: string, scope: ConsoleScope): Promise<unknown> {\n let run: ScopedFunction;\n try {\n run = new AsyncFunction(\"rebase\", \"collections\", `return (${code}\\n);`);\n } catch (error) {\n if (!(error instanceof SyntaxError)) throw error;\n run = new AsyncFunction(\"rebase\", \"collections\", code);\n }\n return run(scope.rebase, scope.collections);\n}\n\n/** A result as JSON, the way `--eval` prints it: dates as ISO strings, bigints as strings. */\nexport function consoleJson(value: unknown): string {\n return JSON.stringify(value, (_key, item: unknown) => typeof item === \"bigint\" ? item.toString() : item, 2) ?? \"undefined\";\n}\n\n/** The host and database a URL names, for the banner — never its credentials. */\nfunction describeDatabase(databaseUrl: string): string {\n try {\n const url = new URL(databaseUrl);\n return `${url.hostname}${url.port ? `:${url.port}` : \"\"}${url.pathname}`;\n } catch {\n return \"the configured database\";\n }\n}\n\n/** Where the REPL reads and writes; the terminal unless a caller hands it streams. */\nexport interface ConsoleStreams {\n input?: NodeJS.ReadableStream;\n output?: NodeJS.WritableStream;\n}\n\n/**\n * `rebase console [--eval <code>] [--collections <dir>]`, from the driver\n * line `[\"console\", …flags]`. Resolves with the exit code.\n */\nexport async function consoleCommand(args: string[], streams: ConsoleStreams = {}): Promise<number> {\n const flags = arg({ ...RELAYED_FLAGS, ...CONSOLE_FLAGS }, { argv: args.slice(1) });\n if (flags[\"--help\"]) {\n out(\"Run `rebase console --help` for the options — this is the driver's own entry point.\");\n return 0;\n }\n\n const databaseUrl = flags[\"--database-url\"] || process.env.DATABASE_URL;\n if (!databaseUrl) {\n outError(\"✗ No database to open: DATABASE_URL is not set. Set it in .env, or pass --database-url.\");\n return 1;\n }\n\n // The console's own lines are what the reader is here for; the driver's\n // info-level boot notes are not, unless they asked for them.\n if (process.env.LOG_LEVEL === undefined) process.env.LOG_LEVEL = \"warn\";\n\n const collectionsPath = path.resolve(flags[\"--collections\"] || path.join(\"..\", \"config\", \"collections\"));\n const { loadCollections } = await import(\"./schema/doctor\");\n const collections = fs.existsSync(collectionsPath) ? await loadCollections(collectionsPath) : [];\n\n const ceiling = poolMaxCeiling();\n const rebase = await openRebase({\n databaseUrl,\n collections,\n ...(ceiling !== null ? { pool: { max: ceiling } } : {})\n });\n\n try {\n const code = flags[\"--eval\"];\n if (code !== undefined) {\n try {\n const result = await evaluateInConsole(code, { rebase, collections: rebase.collections });\n if (result !== undefined) out(consoleJson(result));\n return 0;\n } catch (error) {\n outError(describeFailure(error));\n return 1;\n }\n }\n\n await startRepl({ rebase, collections: rebase.collections }, {\n history: flags[\"--history\"],\n database: describeDatabase(databaseUrl),\n ...streams\n });\n return 0;\n } finally {\n await rebase.close();\n }\n}\n\n/** The interactive half: a Node REPL until `.exit` or Ctrl-D. */\nasync function startRepl(scope: ConsoleScope, options: { history?: string; database: string } & ConsoleStreams): Promise<void> {\n out(\"\");\n out(` rebase console — ${options.database}, ${scope.collections.length} collection(s)`);\n out(\" In scope: rebase (dataAsAdmin, sql, withAuth, close) and collections. Top-level await works.\");\n out(\" Try: await rebase.dataAsAdmin.<collection>.find({ limit: 5 })\");\n out(\"\");\n\n const interactive = options.input === undefined;\n // Started without a prompt, and given one once the scope is in place: a\n // line that arrives with the first prompt must already see `rebase`.\n const server = repl.start({\n prompt: \"\",\n useGlobal: false,\n ...(options.input ? { input: options.input, terminal: false } : {}),\n ...(options.output ? { output: options.output } : {}),\n writer: (value: unknown) => inspect(value, { colors: interactive, depth: 6 })\n });\n server.context.rebase = scope.rebase;\n server.context.collections = scope.collections;\n server.setPrompt(\"rebase> \");\n\n const history = options.history;\n if (history) {\n fs.mkdirSync(path.dirname(history), { recursive: true });\n await new Promise<void>((resolve) => {\n server.setupHistory(history, (error) => {\n if (error) outError(` (history is off: ${error.message})`);\n resolve();\n });\n });\n }\n\n const exited = new Promise<void>((resolve) => server.once(\"exit\", () => resolve()));\n server.displayPrompt();\n await exited;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA4BA,IAAa,gBAAgB;CACzB,iBAAiB;CACjB,MAAM;CACN,UAAU;CACV,MAAM;CACN,aAAa;AACjB;;AAYA,IAAM,gBAA0C,OAAO,eAAe,YAAY,KAAA,CAAS,CAAC,CAAC;;;;;;;;;AAU7F,eAAsB,kBAAkB,MAAc,OAAuC;CACzF,IAAI;CACJ,IAAI;EACA,MAAM,IAAI,cAAc,UAAU,eAAe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AO,aAAa,UAAU,UAAU;IACpC,IAAI,OAAO,SAAS,sBAAsB,MAAM,QAAQ,EAAE;IAC1D,QAAQ;GACZ,CAAC;EACL,CAAC;CACL;CAEA,MAAM,SAAS,IAAI,SAAe,YAAY,OAAO,KAAK,cAAc,QAAQ,CAAC,CAAC;CAClF,OAAO,cAAc;CACrB,MAAM;AACV"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { CollectionConfig } from "@rebasepro/types";
|
|
2
|
+
import { type OpenedRebase } from "./open-rebase.js";
|
|
3
|
+
/**
|
|
4
|
+
* The flags `rebase console` takes. `--history` is the CLI's own: where it
|
|
5
|
+
* keeps the REPL's history (`.rebase/console_history` in the project).
|
|
6
|
+
*/
|
|
7
|
+
export declare const CONSOLE_FLAGS: {
|
|
8
|
+
"--collections": StringConstructor;
|
|
9
|
+
"-c": string;
|
|
10
|
+
"--eval": StringConstructor;
|
|
11
|
+
"-e": string;
|
|
12
|
+
"--history": StringConstructor;
|
|
13
|
+
};
|
|
14
|
+
/** What the code the console runs can name. */
|
|
15
|
+
export interface ConsoleScope {
|
|
16
|
+
rebase: OpenedRebase;
|
|
17
|
+
collections: CollectionConfig[];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Run `code` with `rebase` and `collections` in scope and resolve with its
|
|
21
|
+
* value.
|
|
22
|
+
*
|
|
23
|
+
* Read as an expression first, so `rebase.dataAsAdmin.posts.find()` is its own
|
|
24
|
+
* result; code that is not one expression runs as a function body, where
|
|
25
|
+
* `await` works everywhere and `return` gives the result.
|
|
26
|
+
*/
|
|
27
|
+
export declare function evaluateInConsole(code: string, scope: ConsoleScope): Promise<unknown>;
|
|
28
|
+
/** A result as JSON, the way `--eval` prints it: dates as ISO strings, bigints as strings. */
|
|
29
|
+
export declare function consoleJson(value: unknown): string;
|
|
30
|
+
/** Where the REPL reads and writes; the terminal unless a caller hands it streams. */
|
|
31
|
+
export interface ConsoleStreams {
|
|
32
|
+
input?: NodeJS.ReadableStream;
|
|
33
|
+
output?: NodeJS.WritableStream;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* `rebase console [--eval <code>] [--collections <dir>]`, from the driver
|
|
37
|
+
* line `["console", …flags]`. Resolves with the exit code.
|
|
38
|
+
*/
|
|
39
|
+
export declare function consoleCommand(args: string[], streams?: ConsoleStreams): Promise<number>;
|