@protobase/cli 0.46.10 → 0.46.12
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/dist/auth/register.js +1 -2
- package/dist/auth/write-migration.js +1 -1
- package/dist/build/app-icons.js +1 -1
- package/dist/build/config-bundle.js +1 -1
- package/dist/build/deploy-bundle.js +2 -2
- package/dist/build/entry-code.js +1 -1
- package/dist/build/plugin-build.js +3 -3
- package/dist/build/plugin-fields.js +1 -1
- package/dist/build/service-worker-code.js +1 -1
- package/dist/build/shell.js +2 -2
- package/dist/build/ui-check.js +2 -2
- package/dist/build/vite-bundle.js +1 -1
- package/dist/bundle/manifest.js +1 -1
- package/dist/cli/package.js +1 -1
- package/dist/db/connect.js +8 -5
- package/dist/dev/check-database.js +5 -3
- package/dist/dev/entry.d.ts +2 -0
- package/dist/dev/entry.js +6 -10
- package/dist/dev/login-line.js +21 -0
- package/dist/dev/loopback.js +42 -0
- package/dist/dev/project.js +2 -2
- package/dist/dev/run.js +19 -11
- package/dist/dev/startup-logger.js +24 -0
- package/dist/doctor/run.js +4 -1
- package/dist/encryption/register.js +1 -2
- package/dist/error-message.js +15 -0
- package/dist/files/register.js +1 -2
- package/dist/infer/proposal.js +1 -1
- package/dist/main.js +34 -26
- package/dist/migration/load-project.js +1 -1
- package/dist/migration/register.js +7 -4
- package/dist/migration/summary.js +15 -0
- package/dist/mobile/local-spec.js +1 -1
- package/dist/mobile/run.js +1 -1
- package/dist/mobile/web-part.js +2 -2
- package/dist/mobile/workspace.js +1 -1
- package/dist/notifications/register.js +1 -2
- package/dist/organizations/api.js +15 -0
- package/dist/organizations/register.js +5 -15
- package/dist/project/favicon-link.js +1 -1
- package/dist/project/load-bundle-project.js +2 -2
- package/dist/project/load-data-config.js +2 -2
- package/dist/project/placeholder-secret.js +9 -0
- package/dist/scaffold/existing-config.js +4 -1
- package/dist/scaffold/plan.js +17 -5
- package/dist/scaffold/project.js +2 -1
- package/dist/scaffold/prompt.js +12 -5
- package/dist/scaffold/protobase-tables.js +44 -0
- package/dist/scaffold/run.js +3 -1
- package/dist/scaffold/ui-fields.js +3 -0
- package/dist/scaffold/ui-file.js +42 -5
- package/dist/serve/app.js +1 -1
- package/dist/serve/bundle-version.js +1 -1
- package/dist/serve/create-admin.js +3 -3
- package/dist/serve/host-modules.js +5 -5
- package/dist/serve/lifecycle.js +3 -3
- package/dist/serve/mobile-release.js +1 -1
- package/dist/serve/serve-bundle-path.js +1 -1
- package/dist/serve/serve-bundle.js +3 -3
- package/dist/serve/serve-dir.js +2 -2
- package/dist/supabase/dump-phase.js +2 -2
- package/dist/supabase/load-phase.js +2 -2
- package/dist/supabase/register.js +1 -1
- package/dist/supabase/storage-phase.js +1 -1
- package/dist/users/commands.js +7 -1
- package/dist/users/register.js +17 -11
- package/dist/users/users-api.js +2 -1
- package/dist/worker/start-worker.js +2 -2
- package/package.json +6 -6
- package/skills/protobase/SKILL.md +1 -0
- package/skills/protobase/references/getting-started.md +5 -1
- package/skills/protobase/references/guides/existing-database.md +112 -0
- package/skills/protobase/references/reference/auth.md +6 -6
- package/skills/protobase/references/reference/cli.md +19 -11
package/dist/main.js
CHANGED
|
@@ -1,49 +1,42 @@
|
|
|
1
|
-
import { loadNearestEnvFile } from "./dev/env.js";
|
|
2
1
|
import { registerAuth } from "./auth/register.js";
|
|
3
|
-
import {
|
|
4
|
-
import { resolveExtensions } from "./project/extensions.js";
|
|
5
|
-
import { buildPlugin, pluginManifestFile } from "./build/plugin-build.js";
|
|
6
|
-
import { buildShell } from "./build/shell.js";
|
|
7
|
-
import { buildDeployBundle } from "./build/deploy-bundle.js";
|
|
8
|
-
import { buildServeRuntime } from "./build/serve-runtime.js";
|
|
9
|
-
import { resolveConnectionUrl } from "./db/connect.js";
|
|
2
|
+
import { isConnectionString, resolveConnectionUrl } from "./db/connect.js";
|
|
10
3
|
import { parseHosts } from "./dev/hosts.js";
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { runScaffold } from "./scaffold/run.js";
|
|
15
|
-
import { reportCrashes } from "./serve/crash-reports.js";
|
|
16
|
-
import { closeOnSignals } from "./serve/signals.js";
|
|
17
|
-
import { serveBundle } from "./serve/serve-bundle.js";
|
|
18
|
-
import { serveBundleDir } from "./serve/serve-dir.js";
|
|
19
|
-
import { loadWorkerBundle, startWorker } from "./worker/start-worker.js";
|
|
4
|
+
import { loadNearestEnvFile } from "./dev/env.js";
|
|
5
|
+
import { resolveExtensions } from "./project/extensions.js";
|
|
6
|
+
import { placeholderSecretWarning } from "./project/placeholder-secret.js";
|
|
20
7
|
import { registerOrganizations } from "./organizations/register.js";
|
|
21
8
|
import { registerFiles } from "./files/register.js";
|
|
22
9
|
import { registerEncryption } from "./encryption/register.js";
|
|
23
10
|
import { registerMigration } from "./migration/register.js";
|
|
24
11
|
import { registerMobile } from "./mobile/register.js";
|
|
25
12
|
import { registerNotifications } from "./notifications/register.js";
|
|
13
|
+
import { protobaseVersion } from "./version/version.js";
|
|
26
14
|
import { registerSkill } from "./skill/register.js";
|
|
27
15
|
import { registerImport } from "./supabase/register.js";
|
|
28
16
|
import { registerToken, registerUsers } from "./users/register.js";
|
|
17
|
+
import { errorMessage } from "./error-message.js";
|
|
29
18
|
import { statSync } from "node:fs";
|
|
30
19
|
import path from "node:path";
|
|
31
20
|
import { Command, InvalidArgumentError } from "commander";
|
|
32
21
|
//#region src/main.ts
|
|
33
22
|
const out = (text) => process.stdout.write(text);
|
|
23
|
+
const warn = (message) => message && process.stderr.write(`warning: ${message}\n`);
|
|
34
24
|
const collect = (value, previous) => [...previous, value];
|
|
35
25
|
const uiSection = (value) => {
|
|
36
26
|
if (value === "names" || value === "list") return value;
|
|
37
27
|
throw new InvalidArgumentError("expected names or list");
|
|
38
28
|
};
|
|
39
29
|
const collectSection = (value, previous) => [...previous, uiSection(value)];
|
|
40
|
-
const program = new Command("protobase").description("Protobase command line");
|
|
41
|
-
program.command("scaffold").description("Generate or update config/<resource>/data.ts from a Postgres database").argument("[args...]", "connection string (
|
|
30
|
+
const program = new Command("protobase").description("Protobase command line").version(protobaseVersion, "-v, --version", "print the Protobase version");
|
|
31
|
+
program.command("scaffold").description("Generate or update config/<resource>/data.ts from a Postgres database").argument("[args...]", "connection string (default: DATABASE_URL from the environment or .env) followed by an optional target: all, schema, schema.table, schema.table.column").option("--env <variable>", "read the connection string from this environment variable").option("--config <dir>", "config folder", "config").option("--yes", "accept all proposals without asking", false).option("--dry-run", "print a diff instead of writing files", false).option("--ui", "also write config/<resource>/ui.ts (names and list)", false).option("--ui-list", "write only the list section of ui.ts", false).option("--ui-section <name>", "write only this ui.ts section (names or list), repeatable", collectSection, []).option("--exclude <table>", "skip a schema or schema.table, repeatable", collect, []).action(async (args, opts) => {
|
|
32
|
+
loadNearestEnvFile(process.cwd());
|
|
42
33
|
const [first, ...rest] = args;
|
|
43
|
-
const
|
|
44
|
-
const
|
|
34
|
+
const fromArgument = !opts.env && first !== void 0 && isConnectionString(first);
|
|
35
|
+
const url = resolveConnectionUrl(fromArgument ? first : void 0, opts.env);
|
|
36
|
+
const [target, ...extra] = fromArgument ? rest : args;
|
|
45
37
|
if (extra.length > 0) throw new Error(`Unexpected argument "${extra[0]}"`);
|
|
46
38
|
const ui = opts.ui ? ["names", "list"] : [...opts.uiSection, ...opts.uiList ? ["list"] : []];
|
|
39
|
+
const { runScaffold } = await import("./scaffold/run.js");
|
|
47
40
|
await runScaffold({
|
|
48
41
|
url,
|
|
49
42
|
target,
|
|
@@ -54,8 +47,10 @@ program.command("scaffold").description("Generate or update config/<resource>/da
|
|
|
54
47
|
excludes: opts.exclude
|
|
55
48
|
}, out);
|
|
56
49
|
});
|
|
57
|
-
program.command("doctor").description("Check a config folder against the database").argument("[connection]", "connection string").option("--env <variable>", "read the connection string from this environment variable").option("--config <dir>", "config folder", "config").action(async (connection, opts) => {
|
|
50
|
+
program.command("doctor").description("Check a config folder against the database").argument("[connection]", "connection string (default: DATABASE_URL from the environment or .env)").option("--env <variable>", "read the connection string from this environment variable").option("--config <dir>", "config folder", "config").action(async (connection, opts) => {
|
|
51
|
+
loadNearestEnvFile(process.cwd());
|
|
58
52
|
const url = resolveConnectionUrl(connection, opts.env);
|
|
53
|
+
const { runDoctor } = await import("./doctor/run.js");
|
|
59
54
|
const { errors } = await runDoctor({
|
|
60
55
|
url,
|
|
61
56
|
configDir: path.resolve(opts.config)
|
|
@@ -63,6 +58,7 @@ program.command("doctor").description("Check a config folder against the databas
|
|
|
63
58
|
if (errors > 0) process.exitCode = 1;
|
|
64
59
|
});
|
|
65
60
|
program.command("dev").description("Serve the admin app and API for the project in the current directory").option("--port <port>", "port for the app and API", "5173").option("--env <variable>", "environment variable holding the database URL", "DATABASE_URL").option("--allowed-hosts <hosts>", "extra Host headers to accept, comma separated; a leading dot matches subdomains (.trycloudflare.com)").option("--cache-dir <dir>", "Vite's dependency cache, so parallel dev servers do not share one").option("--extend <dir>", "merge the protobase.config.ts and protobase.ui.tsx in this folder before the project's, repeatable", collect, []).action(async (opts) => {
|
|
61
|
+
const { runDev } = await import("./dev/run.js");
|
|
66
62
|
const server = await runDev({
|
|
67
63
|
extensions: resolveExtensions(opts.extend),
|
|
68
64
|
port: Number(opts.port),
|
|
@@ -71,12 +67,14 @@ program.command("dev").description("Serve the admin app and API for the project
|
|
|
71
67
|
cacheDir: opts.cacheDir && path.resolve(opts.cacheDir),
|
|
72
68
|
allowedHosts: parseHosts(opts.allowedHosts)
|
|
73
69
|
}, out);
|
|
70
|
+
warn(placeholderSecretWarning(process.env));
|
|
74
71
|
process.once("SIGINT", () => void server.close().then(() => process.exit(0)));
|
|
75
72
|
process.once("SIGTERM", () => void server.close().then(() => process.exit(0)));
|
|
76
73
|
});
|
|
77
74
|
program.command("build").description("Build the deploy bundle of the project in the current directory: its config module, the admin app with the project's UI as a plugin, and the manifest").option("--out <dir>", "output folder", "dist").option("--bun", "have Bun's bundler write the config module, for a bundle only Bun serves (needs bun on PATH)", false).option("--extend <dir>", "merge the protobase.config.ts and protobase.ui.tsx in this folder before the project's, repeatable", collect, []).option("--source-maps", "end each script with a //# debugId= comment and write its source map, carrying the same id, beside it", false).action(async (opts) => {
|
|
78
75
|
const extensions = resolveExtensions(opts.extend);
|
|
79
76
|
const onWarning = (message) => process.stderr.write(`warning: ${message}\n`);
|
|
77
|
+
const [{ buildDeployBundle }, { manifestFile }] = await Promise.all([import("./build/deploy-bundle.js"), import("./bundle/manifest.js")]);
|
|
80
78
|
const manifest = await buildDeployBundle({
|
|
81
79
|
projectDir: process.cwd(),
|
|
82
80
|
outDir: path.resolve(opts.out),
|
|
@@ -92,6 +90,7 @@ program.command("build").description("Build the deploy bundle of the project in
|
|
|
92
90
|
program.command("build-plugin").description("Build a plugin the admin app loads at runtime: its protobase.ui.tsx as one ES module, its stylesheet and plugin.json").argument("[dir]", "the plugin folder, holding protobase.ui.tsx", ".").option("--out <dir>", "output folder (default: dist in the plugin folder)").option("--name <name>", "the plugin's name (default: its package.json name)").option("--source-maps", "end each script with a //# debugId= comment and write its source map, carrying the same id, beside it", false).action(async (dir, opts) => {
|
|
93
91
|
const pluginDir = path.resolve(dir);
|
|
94
92
|
const outDir = path.resolve(opts.out ?? path.join(dir, "dist"));
|
|
93
|
+
const { buildPlugin, pluginManifestFile } = await import("./build/plugin-build.js");
|
|
95
94
|
const manifest = await buildPlugin({
|
|
96
95
|
pluginDir,
|
|
97
96
|
outDir,
|
|
@@ -102,10 +101,12 @@ program.command("build-plugin").description("Build a plugin the admin app loads
|
|
|
102
101
|
out(`built ${shown.startsWith("..") ? outDir : shown || "."}: ${pluginManifestFile}, ${manifest.entry} and ${manifest.css} (${manifest.name}, plugin API ${manifest.api}, Protobase ${manifest.protobase})\n`);
|
|
103
102
|
});
|
|
104
103
|
program.command("build-shell", { hidden: true }).description("Build the admin app every bundle shares, as @protobase/ui's package and the protobase image ship it").argument("<out>", "output folder").option("--source-maps <dir>", "end each script with a //# debugId= comment and write its source map, carrying the same id, to this folder").action(async (outDir, opts) => {
|
|
104
|
+
const { buildShell } = await import("./build/shell.js");
|
|
105
105
|
const shell = await buildShell(path.resolve(outDir), opts.sourceMaps && path.resolve(opts.sourceMaps));
|
|
106
106
|
out(`built ${outDir}: the shell of Protobase ${shell.protobase} (plugin API ${shell.pluginApi})\n`);
|
|
107
107
|
});
|
|
108
108
|
program.command("build-serve").description("Bundle the serve runtime into one file for Bun: bun --no-install protobase-serve.js <bundle.js>").option("--out <file>", "output file", "dist/protobase-serve.js").option("--bun", "have Bun's bundler write the file (needs bun on PATH)", false).action(async (opts) => {
|
|
109
|
+
const { buildServeRuntime } = await import("./build/serve-runtime.js");
|
|
109
110
|
await buildServeRuntime({
|
|
110
111
|
outFile: path.resolve(opts.out),
|
|
111
112
|
bun: opts.bun
|
|
@@ -114,11 +115,18 @@ program.command("build-serve").description("Bundle the serve runtime into one fi
|
|
|
114
115
|
});
|
|
115
116
|
program.command("serve").description("Serve a bundle written by `protobase build` until SIGTERM or SIGINT: a folder as a host serves it, a config module as its API alone").argument("<bundle>", "the bundle folder, e.g. dist, or its dist/protobase.config.js").action(async (bundle) => {
|
|
116
117
|
loadNearestEnvFile(process.cwd());
|
|
117
|
-
|
|
118
|
-
|
|
118
|
+
warn(placeholderSecretWarning(process.env));
|
|
119
|
+
if (statSync(bundle).isDirectory()) await (await import("./serve/serve-dir.js")).serveBundleDir(bundle, process.env, out);
|
|
120
|
+
else await (await import("./serve/serve-bundle.js")).serveBundle(bundle, process.env, out);
|
|
119
121
|
});
|
|
120
122
|
program.command("worker").description("Run the jobs of a bundle from `protobase build` in a process of their own, until SIGTERM or SIGINT, as `serve` runs them beside the API").argument("<bundle>", "the bundle folder, e.g. dist, or its dist/protobase.config.js").action(async (bundle) => {
|
|
121
123
|
loadNearestEnvFile(process.cwd());
|
|
124
|
+
const [{ loadWorkerBundle, startWorker }, { projectErrorReporter }, { reportCrashes }, { closeOnSignals }] = await Promise.all([
|
|
125
|
+
import("./worker/start-worker.js"),
|
|
126
|
+
import("./project/error-reporter.js"),
|
|
127
|
+
import("./serve/crash-reports.js"),
|
|
128
|
+
import("./serve/signals.js")
|
|
129
|
+
]);
|
|
122
130
|
const project = await loadWorkerBundle(bundle);
|
|
123
131
|
const reporter = await projectErrorReporter(project, process.env);
|
|
124
132
|
if (reporter) reportCrashes(reporter);
|
|
@@ -141,8 +149,8 @@ registerImport(program);
|
|
|
141
149
|
registerMobile(program);
|
|
142
150
|
registerNotifications(program);
|
|
143
151
|
const run = (argv) => program.parseAsync(argv).catch((error) => {
|
|
144
|
-
process.stderr.write(`error: ${error
|
|
152
|
+
process.stderr.write(`error: ${errorMessage(error)}\n`);
|
|
145
153
|
process.exitCode = 1;
|
|
146
154
|
});
|
|
147
155
|
//#endregion
|
|
148
|
-
export { run };
|
|
156
|
+
export { program, run };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { loadNearestEnvFile } from "../dev/env.js";
|
|
2
|
-
import { importProjectFile } from "../project/import-project-file.js";
|
|
3
2
|
import { createPgDb } from "../project/pg-db.js";
|
|
3
|
+
import { importProjectFile } from "../project/import-project-file.js";
|
|
4
4
|
import { existsSync } from "node:fs";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { assistantSettings, authStoreTables, configExports, jobDefinitions, mergeConfig } from "@protobase/server";
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import { resolveExtensions } from "../project/extensions.js";
|
|
2
|
-
import {
|
|
3
|
-
import { migrationParts } from "./parts.js";
|
|
4
|
-
import { writeMigrations } from "./write-migrations.js";
|
|
2
|
+
import { migrationSummary } from "./summary.js";
|
|
5
3
|
import path from "node:path";
|
|
6
4
|
//#region src/migration/register.ts
|
|
7
5
|
const out = (text) => process.stdout.write(text);
|
|
8
6
|
const collect = (value, previous) => [...previous, value];
|
|
9
7
|
const registerMigration = (program) => {
|
|
10
8
|
program.command("migration").description("Write what the database still needs for every feature the config enables (auth, events, jobs) as the project's next SQL migrations").option("--dir <dir>", "migrations folder", "db/migrations").option("--extend <dir>", "merge the protobase.config.ts in this folder before the project's, as dev and build do, repeatable", collect, []).action(async (opts) => {
|
|
9
|
+
const [{ loadMigrationProject }, { migrationParts }, { writeMigrations }] = await Promise.all([
|
|
10
|
+
import("./load-project.js"),
|
|
11
|
+
import("./parts.js"),
|
|
12
|
+
import("./write-migrations.js")
|
|
13
|
+
]);
|
|
11
14
|
const project = await loadMigrationProject(process.cwd(), resolveExtensions(opts.extend));
|
|
12
15
|
try {
|
|
13
16
|
const files = await writeMigrations(migrationParts(project), path.resolve(opts.dir));
|
|
14
|
-
out(files
|
|
17
|
+
out(migrationSummary(files, process.cwd(), Boolean(project.auth)));
|
|
15
18
|
} finally {
|
|
16
19
|
await project.close();
|
|
17
20
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
//#region src/migration/summary.ts
|
|
3
|
+
/** Where to read how to add sign-in to a project that has none. */
|
|
4
|
+
const signInGuide = "https://docs.protobase.net/guides/existing-database/";
|
|
5
|
+
/**
|
|
6
|
+
* What `protobase migration` prints: the files it wrote, relative to `cwd`, or that the database is current for what
|
|
7
|
+
* the config enables. A config without `auth` enables no sign-in, so its database being current says nothing about it.
|
|
8
|
+
*/
|
|
9
|
+
const migrationSummary = (files, cwd, hasAuth) => {
|
|
10
|
+
const written = files.length > 0 ? files.map((file) => `wrote ${path.relative(cwd, file)}\n`).join("") + "apply them with the project's migrations\n" : "the database is up to date; nothing to write\n";
|
|
11
|
+
if (hasAuth) return written;
|
|
12
|
+
return `${written}no sign-in is configured, so nothing was written for it: export auth and authenticate from protobase.config.ts, see ${signInGuide}\n`;
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
export { migrationSummary, signInGuide };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
import { homedir } from "node:os";
|
|
3
2
|
import { pathToFileURL } from "node:url";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
4
|
//#region src/mobile/local-spec.ts
|
|
5
5
|
const localSpec = /^(?:file:|[.]|~[/\\]|[/\\]|[a-z]:)/i;
|
|
6
6
|
/** Whether npm installs the dependency spec `spec` from this machine, copying it, rather than fetching it. */
|
package/dist/mobile/run.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { checkInstalledPlugins, checkPinnedNative, pinnedNative } from "./pinned-packages.js";
|
|
2
1
|
import { nativeFingerprint } from "./fingerprint.js";
|
|
2
|
+
import { checkInstalledPlugins, checkPinnedNative, pinnedNative } from "./pinned-packages.js";
|
|
3
3
|
import { withoutAndroidSigning } from "./android-signing.js";
|
|
4
4
|
import { runChild } from "./child-process.js";
|
|
5
5
|
import { apiUrl, checkReleaseUrl, httpAllowances } from "./api-origin.js";
|
package/dist/mobile/web-part.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { bundleLayout } from "../bundle/manifest.js";
|
|
2
|
-
import { buildDeployBundle } from "../build/deploy-bundle.js";
|
|
3
2
|
import { withApiOrigin } from "./api-origin-page.js";
|
|
4
3
|
import { siteFiles } from "../serve/site-files.js";
|
|
4
|
+
import { buildDeployBundle } from "../build/deploy-bundle.js";
|
|
5
5
|
import path from "node:path";
|
|
6
|
-
import { releaseManifest } from "@protobase/server";
|
|
7
6
|
import { cp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
7
|
+
import { releaseManifest } from "@protobase/server";
|
|
8
8
|
import { releaseManifestFile } from "@protobase/schema/internal";
|
|
9
9
|
const writeReleaseManifest = async (web) => {
|
|
10
10
|
const files = await Promise.all((await siteFiles({
|
package/dist/mobile/workspace.js
CHANGED
|
@@ -6,8 +6,8 @@ import { isLocalSpec } from "./local-spec.js";
|
|
|
6
6
|
import { checkLocalPins, isUnmet, localPins } from "./local-pins.js";
|
|
7
7
|
import { existsSync } from "node:fs";
|
|
8
8
|
import path from "node:path";
|
|
9
|
-
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
10
9
|
import { fileURLToPath } from "node:url";
|
|
10
|
+
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
11
11
|
//#region src/mobile/workspace.ts
|
|
12
12
|
/** Where the mobile build lives in a project: npm's install of @protobase/mobile, the app's files and native projects. */
|
|
13
13
|
const workspaceDir = (projectDir) => path.join(projectDir, protobaseFolder, "mobile");
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { printVapidKeys } from "./print-vapid-keys.js";
|
|
2
1
|
//#region src/notifications/register.ts
|
|
3
2
|
const registerNotifications = (program) => {
|
|
4
|
-
program.command("notifications").description("Set up the delivery of notifications").command("vapid-keys").description("Print a fresh VAPID key pair for Web Push, as PROTOBASE_VAPID_PUBLIC_KEY and PROTOBASE_VAPID_PRIVATE_KEY").action(() => printVapidKeys((text) => void process.stdout.write(text), (text) => void process.stderr.write(text)));
|
|
3
|
+
program.command("notifications").description("Set up the delivery of notifications").command("vapid-keys").description("Print a fresh VAPID key pair for Web Push, as PROTOBASE_VAPID_PUBLIC_KEY and PROTOBASE_VAPID_PRIVATE_KEY").action(async () => (await import("./print-vapid-keys.js")).printVapidKeys((text) => void process.stdout.write(text), (text) => void process.stderr.write(text)));
|
|
5
4
|
};
|
|
6
5
|
//#endregion
|
|
7
6
|
export { registerNotifications };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { addAppRoleToOwners, addMember, createOrganization, listOrganizations, listUsers, removeMember, setMemberRoles, setUserRole } from "@protobase/server";
|
|
2
|
+
//#region src/organizations/api.ts
|
|
3
|
+
const organizationsApi = (auth) => ({
|
|
4
|
+
listOrganizations: () => listOrganizations(auth),
|
|
5
|
+
createOrganization: (input) => createOrganization(auth, input),
|
|
6
|
+
addMember: (input) => addMember(auth, input),
|
|
7
|
+
setMemberRoles: (input) => setMemberRoles(auth, input),
|
|
8
|
+
removeMember: (input) => removeMember(auth, input),
|
|
9
|
+
addAppRoleToOwners: (appRole) => addAppRoleToOwners(auth, appRole),
|
|
10
|
+
listUsers: () => listUsers(auth),
|
|
11
|
+
setUserRole: (input) => setUserRole(auth, input),
|
|
12
|
+
membershipRoles: () => auth.roleDefinitions.names.filter((name) => name !== "admin" && name !== "user")
|
|
13
|
+
});
|
|
14
|
+
//#endregion
|
|
15
|
+
export { organizationsApi };
|
|
@@ -1,20 +1,10 @@
|
|
|
1
|
-
import { loadProjectAuth } from "../users/load-auth.js";
|
|
2
1
|
import { addAppRoleCommand, addMemberCommand, createOrganizationCommand, listOrganizationsCommand, removeMemberCommand, setMemberRolesCommand } from "./commands.js";
|
|
3
|
-
import { addAppRoleToOwners, addMember, createOrganization, listOrganizations, listUsers, removeMember, setMemberRoles, setUserRole } from "@protobase/server";
|
|
4
2
|
//#region src/organizations/register.ts
|
|
5
3
|
const out = (text) => process.stdout.write(text);
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
setMemberRoles: (input) => setMemberRoles(auth, input),
|
|
11
|
-
removeMember: (input) => removeMember(auth, input),
|
|
12
|
-
addAppRoleToOwners: (appRole) => addAppRoleToOwners(auth, appRole),
|
|
13
|
-
listUsers: () => listUsers(auth),
|
|
14
|
-
setUserRole: (input) => setUserRole(auth, input),
|
|
15
|
-
membershipRoles: () => auth.roleDefinitions.names.filter((name) => name !== "admin" && name !== "user")
|
|
16
|
-
});
|
|
17
|
-
const projectApi = async () => organizationsApi(await loadProjectAuth(process.cwd()));
|
|
4
|
+
const projectApi = async () => {
|
|
5
|
+
const [{ organizationsApi }, { loadProjectAuth }] = await Promise.all([import("./api.js"), import("../users/load-auth.js")]);
|
|
6
|
+
return organizationsApi(await loadProjectAuth(process.cwd()));
|
|
7
|
+
};
|
|
18
8
|
const finish = (code) => process.exit(code);
|
|
19
9
|
const memberOptions = (command) => command.argument("<organization>", "its slug or id").argument("<email>").option("--org-role <role>", "owner, admin or member: who manages the organization").option("--app-roles <roles>", "app roles in this organization, comma separated (see `users roles`)");
|
|
20
10
|
const registerOrganizations = (program) => {
|
|
@@ -67,4 +57,4 @@ const registerOrganizations = (program) => {
|
|
|
67
57
|
});
|
|
68
58
|
};
|
|
69
59
|
//#endregion
|
|
70
|
-
export {
|
|
60
|
+
export { registerOrganizations };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { faviconFile, projectFavicon } from "../build/favicon.js";
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import { pngIcons } from "@protobase/server";
|
|
5
4
|
import { readFile } from "node:fs/promises";
|
|
5
|
+
import { pngIcons } from "@protobase/server";
|
|
6
6
|
//#region src/project/favicon-link.ts
|
|
7
7
|
/**
|
|
8
8
|
* Links the project's favicon at `/protobase.favicon.svg` in the app's page, and its Apple touch icon at
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { loadNearestEnvFile } from "../dev/env.js";
|
|
2
|
-
import { importProjectFile } from "./import-project-file.js";
|
|
3
|
-
import { readManifest } from "../bundle/manifest.js";
|
|
4
2
|
import { createPgDb } from "./pg-db.js";
|
|
3
|
+
import { readManifest } from "../bundle/manifest.js";
|
|
5
4
|
import { loadBundle } from "../serve/load-bundle.js";
|
|
5
|
+
import { importProjectFile } from "./import-project-file.js";
|
|
6
6
|
import { existsSync, statSync } from "node:fs";
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import { configExports } from "@protobase/server";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { importProjectCode } from "./import-project-file.js";
|
|
2
|
-
import { uiDirs } from "./convention-files.js";
|
|
3
1
|
import { conventionConfig } from "./convention.js";
|
|
2
|
+
import { uiDirs } from "./convention-files.js";
|
|
3
|
+
import { importProjectCode } from "./import-project-file.js";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { configExports } from "@protobase/server";
|
|
6
6
|
//#region src/project/load-data-config.ts
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/project/placeholder-secret.ts
|
|
2
|
+
const placeholder = /^change-?me/i;
|
|
3
|
+
/**
|
|
4
|
+
* A warning when BETTER_AUTH_SECRET is still the placeholder of .env.example: whoever knows it can sign session
|
|
5
|
+
* cookies for the app. Undefined otherwise.
|
|
6
|
+
*/
|
|
7
|
+
const placeholderSecretWarning = (env) => env.BETTER_AUTH_SECRET && placeholder.test(env.BETTER_AUTH_SECRET) ? "BETTER_AUTH_SECRET is still the placeholder from .env.example, which signs session cookies anyone can forge; set it to the output of `openssl rand -base64 32`" : void 0;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { placeholderSecretWarning };
|
|
@@ -23,11 +23,13 @@ const describeField = (name, initializer) => {
|
|
|
23
23
|
let column;
|
|
24
24
|
let type;
|
|
25
25
|
let enumValues;
|
|
26
|
+
let sortable = false;
|
|
26
27
|
let node = initializer;
|
|
27
28
|
while (Node.isCallExpression(node)) {
|
|
28
29
|
const expression = node.getExpression();
|
|
29
30
|
if (!Node.isPropertyAccessExpression(expression)) break;
|
|
30
31
|
if (expression.getName() === "column") column ??= stringArg(node);
|
|
32
|
+
if (expression.getName() === "sortable") sortable = true;
|
|
31
33
|
if (expression.getExpression().getText() === "f") {
|
|
32
34
|
type = expression.getName();
|
|
33
35
|
const arg = node.getArguments()[0];
|
|
@@ -41,7 +43,8 @@ const describeField = (name, initializer) => {
|
|
|
41
43
|
column: column ?? defaultColumn(name),
|
|
42
44
|
ignored: false,
|
|
43
45
|
...type && { type },
|
|
44
|
-
...enumValues && { enumValues }
|
|
46
|
+
...enumValues && { enumValues },
|
|
47
|
+
...sortable && { sortable }
|
|
45
48
|
};
|
|
46
49
|
};
|
|
47
50
|
const fieldsObject = (root) => {
|
package/dist/scaffold/plan.js
CHANGED
|
@@ -8,6 +8,7 @@ import { detectDrift } from "./drift.js";
|
|
|
8
8
|
import { ensureExports } from "./index-file.js";
|
|
9
9
|
import { assignNames } from "./resource-names.js";
|
|
10
10
|
import { planResource } from "./resource-plan.js";
|
|
11
|
+
import { protobaseSchemas } from "./protobase-tables.js";
|
|
11
12
|
import { dependencyOrder } from "./table-order.js";
|
|
12
13
|
import { isExcluded, matchesTarget } from "./targets.js";
|
|
13
14
|
import { uiFields } from "./ui-fields.js";
|
|
@@ -40,16 +41,22 @@ const change = (file, before, after) => before === after ? [] : [{
|
|
|
40
41
|
}];
|
|
41
42
|
const planScaffold = async (input) => {
|
|
42
43
|
const { configDir, existing, ui } = input;
|
|
43
|
-
const names = assignNames(input.tables, existing);
|
|
44
44
|
const byTable = new Map(existing.map((resource) => [resource.table, resource]));
|
|
45
|
+
const wanted = (table) => matchesTarget(input.target, table) && !isExcluded(input.excludes, table);
|
|
46
|
+
const tables = input.tables.filter((table) => table.kind === "table");
|
|
47
|
+
const skipped = protobaseSchemas(tables.filter((table) => matchesTarget(input.target, table)), input.target);
|
|
48
|
+
const isProtobase = (table) => skipped.some((schema) => schema.tables.includes(table));
|
|
49
|
+
const inProtobaseSchema = (view) => skipped.some(({ schema }) => schema === view.schema && schema !== "public");
|
|
50
|
+
const skippedViews = input.tables.filter((table) => table.kind !== "table" && wanted(table) && !byTable.has(tableKey(table)) && !inProtobaseSchema(table));
|
|
51
|
+
const names = assignNames(tables.filter((table) => !isProtobase(table)), existing);
|
|
45
52
|
const context = (table) => ({
|
|
46
53
|
table,
|
|
47
54
|
resourceNameOf: (schema, name) => names.get(`${schema}.${name}`) ?? name
|
|
48
55
|
});
|
|
49
|
-
const targets = dependencyOrder(
|
|
56
|
+
const targets = dependencyOrder(tables.filter((table) => wanted(table) && !isProtobase(table)));
|
|
50
57
|
const changes = [];
|
|
51
58
|
const drift = [];
|
|
52
|
-
const warnings =
|
|
59
|
+
const warnings = skippedViews.map((view) => `${tableKey(view)}: a ${view.kind}, skipped; scaffold writes resources over tables, declare one over a view by hand`);
|
|
53
60
|
const registrations = [];
|
|
54
61
|
const live = [];
|
|
55
62
|
const isLive = (key) => input.live?.includes(key) ?? false;
|
|
@@ -69,6 +76,10 @@ const planScaffold = async (input) => {
|
|
|
69
76
|
names: [viewName(identifier)]
|
|
70
77
|
});
|
|
71
78
|
};
|
|
79
|
+
for (const resource of existing) {
|
|
80
|
+
const table = input.tables.find((each) => tableKey(each) === resource.table);
|
|
81
|
+
if (table && isProtobase(table)) warnings.push(`${resource.table}: one of Protobase's own tables, which ${resource.dir}/data.ts declares; remove that resource`);
|
|
82
|
+
}
|
|
72
83
|
for (const table of targets) {
|
|
73
84
|
const key = tableKey(table);
|
|
74
85
|
const current = byTable.get(key);
|
|
@@ -110,12 +121,13 @@ const planScaffold = async (input) => {
|
|
|
110
121
|
}
|
|
111
122
|
const indexFile = path.join(configDir, "index.ts");
|
|
112
123
|
const indexBefore = await input.readText(indexFile);
|
|
113
|
-
const
|
|
114
|
-
if (
|
|
124
|
+
const exports = [...indexBefore === void 0 ? await registerExisting(input, registrations) : [], ...registrations];
|
|
125
|
+
if (exports.length > 0 || indexBefore === void 0) changes.push(...change(indexFile, indexBefore, ensureExports(indexBefore ?? "", exports)));
|
|
115
126
|
return {
|
|
116
127
|
changes,
|
|
117
128
|
drift,
|
|
118
129
|
warnings,
|
|
130
|
+
skipped,
|
|
119
131
|
live
|
|
120
132
|
};
|
|
121
133
|
};
|
package/dist/scaffold/project.js
CHANGED
|
@@ -5,7 +5,8 @@ const project = new Project({
|
|
|
5
5
|
skipAddingFilesFromTsConfig: true,
|
|
6
6
|
manipulationSettings: {
|
|
7
7
|
indentationText: IndentationText.TwoSpaces,
|
|
8
|
-
quoteKind: QuoteKind.Single
|
|
8
|
+
quoteKind: QuoteKind.Single,
|
|
9
|
+
useTrailingCommas: true
|
|
9
10
|
}
|
|
10
11
|
});
|
|
11
12
|
const parseSource = (text, name = "source.ts") => project.createSourceFile(name, text, { overwrite: true });
|
package/dist/scaffold/prompt.js
CHANGED
|
@@ -45,18 +45,25 @@ const edit = async (proposal, ask) => {
|
|
|
45
45
|
name
|
|
46
46
|
}, ask);
|
|
47
47
|
};
|
|
48
|
-
const interactive = () => {
|
|
48
|
+
const interactive = (input = process.stdin, output = process.stdout) => {
|
|
49
49
|
const rl = createInterface({
|
|
50
|
-
input
|
|
51
|
-
output
|
|
50
|
+
input,
|
|
51
|
+
output
|
|
52
52
|
});
|
|
53
|
+
let acceptRest = false;
|
|
53
54
|
const decide = async (initial, { table, required }) => {
|
|
55
|
+
if (acceptRest) return initial;
|
|
54
56
|
let proposal = initial;
|
|
55
57
|
for (;;) {
|
|
56
|
-
|
|
57
|
-
const options = required ? "[a]ccept, [e]dit" : "[a]ccept, [e]dit, [i]gnore";
|
|
58
|
+
output.write(`\n${table}.${proposal.column}\n ${proposal.name}: ${renderField(proposal)}\n`);
|
|
59
|
+
const options = required ? "[a]ccept, accept a[l]l, [e]dit" : "[a]ccept, accept a[l]l, [e]dit, [i]gnore";
|
|
58
60
|
const answer = (await rl.question(` ${options} (a): `)).trim().toLowerCase() || "a";
|
|
59
61
|
if (answer === "a") return proposal;
|
|
62
|
+
if (answer === "l") {
|
|
63
|
+
acceptRest = true;
|
|
64
|
+
output.write(" accepting this and every remaining proposal\n");
|
|
65
|
+
return proposal;
|
|
66
|
+
}
|
|
60
67
|
if (answer === "e") proposal = await edit(proposal, (q) => rl.question(q));
|
|
61
68
|
if (answer === "i" && !required) return null;
|
|
62
69
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
//#region src/scaffold/protobase-tables.ts
|
|
2
|
+
const storeCore = [
|
|
3
|
+
"user",
|
|
4
|
+
"session",
|
|
5
|
+
"account",
|
|
6
|
+
"verification"
|
|
7
|
+
];
|
|
8
|
+
const storeTables = /* @__PURE__ */ new Set([
|
|
9
|
+
...storeCore,
|
|
10
|
+
"jwks",
|
|
11
|
+
"passkey",
|
|
12
|
+
"two_factor",
|
|
13
|
+
"sign_in_policy",
|
|
14
|
+
"staff_sign_in"
|
|
15
|
+
]);
|
|
16
|
+
const isStoreTable = (name) => storeTables.has(name) || name.startsWith("oauth_");
|
|
17
|
+
const bySchema = (tables) => {
|
|
18
|
+
const groups = /* @__PURE__ */ new Map();
|
|
19
|
+
for (const table of tables) groups.set(table.schema, [...groups.get(table.schema) ?? [], table]);
|
|
20
|
+
return groups;
|
|
21
|
+
};
|
|
22
|
+
const authStore = (schema, tables) => {
|
|
23
|
+
if (schema === "auth") return tables;
|
|
24
|
+
if (!storeCore.every((name) => tables.some((table) => table.name === name))) return [];
|
|
25
|
+
return schema === "public" ? tables.filter((table) => isStoreTable(table.name)) : tables;
|
|
26
|
+
};
|
|
27
|
+
const jobQueue = (schema, tables) => schema === "jobs" && ["job", "version"].every((name) => tables.some((table) => table.name === name)) ? tables : [];
|
|
28
|
+
const protobaseSchemas = (tables, target) => [...bySchema(tables)].flatMap(([schema, own]) => {
|
|
29
|
+
if (target.schema === schema) return [];
|
|
30
|
+
const store = authStore(schema, own);
|
|
31
|
+
if (store.length > 0) return [{
|
|
32
|
+
schema,
|
|
33
|
+
what: "auth store",
|
|
34
|
+
tables: store
|
|
35
|
+
}];
|
|
36
|
+
const queue = jobQueue(schema, own);
|
|
37
|
+
return queue.length > 0 ? [{
|
|
38
|
+
schema,
|
|
39
|
+
what: "job queue",
|
|
40
|
+
tables: queue
|
|
41
|
+
}] : [];
|
|
42
|
+
});
|
|
43
|
+
//#endregion
|
|
44
|
+
export { protobaseSchemas };
|
package/dist/scaffold/run.js
CHANGED
|
@@ -12,6 +12,7 @@ const readText = (file) => readFile(file, "utf8").catch((error) => {
|
|
|
12
12
|
if (error.code === "ENOENT") return void 0;
|
|
13
13
|
throw error;
|
|
14
14
|
});
|
|
15
|
+
const skippedLine = ({ schema, what, tables }) => `skipped ${schema === "public" ? tables.map((table) => `public.${table.name}`).join(", ") : `schema ${schema}`}, Protobase's ${what}; pass "${schema}" as the target to scaffold it anyway\n`;
|
|
15
16
|
const write = async ({ path: file, after }) => {
|
|
16
17
|
await mkdir(path.dirname(file), { recursive: true });
|
|
17
18
|
await writeFile(file, after);
|
|
@@ -23,7 +24,7 @@ const runScaffold = async (options, out) => {
|
|
|
23
24
|
const plan = await (async () => {
|
|
24
25
|
try {
|
|
25
26
|
return await planScaffold({
|
|
26
|
-
tables: await introspect(sql),
|
|
27
|
+
tables: await introspect(sql, { views: true }),
|
|
27
28
|
existing: await readExistingResources(options.configDir),
|
|
28
29
|
configDir: options.configDir,
|
|
29
30
|
target: parseTarget(options.target),
|
|
@@ -43,6 +44,7 @@ const runScaffold = async (options, out) => {
|
|
|
43
44
|
for (const change of plan.changes) if (!options.dryRun) out(`${change.before === void 0 ? "created" : "updated"} ${change.path}\n`);
|
|
44
45
|
if (plan.changes.length === 0) out("Nothing to do, config is up to date.\n");
|
|
45
46
|
else if (options.dryRun) out(`${plan.changes.length} file(s) would change; nothing was written (--dry-run).\n`);
|
|
47
|
+
for (const schema of plan.skipped) out(skippedLine(schema));
|
|
46
48
|
for (const warning of plan.warnings) out(`warning: ${warning}\n`);
|
|
47
49
|
if (plan.drift.length > 0) {
|
|
48
50
|
out("\nDrift:\n");
|
|
@@ -11,10 +11,12 @@ const uiFields = (table, existing, decisions) => {
|
|
|
11
11
|
const resolved = declared ? {
|
|
12
12
|
name: declared.name,
|
|
13
13
|
type: declared.type ?? "text",
|
|
14
|
+
sortable: declared.sortable ?? false,
|
|
14
15
|
ignored: declared.ignored
|
|
15
16
|
} : decided && {
|
|
16
17
|
name: decided.proposal.name,
|
|
17
18
|
type: decided.proposal.type,
|
|
19
|
+
sortable: decided.proposal.sortable,
|
|
18
20
|
ignored: decided.ignored
|
|
19
21
|
};
|
|
20
22
|
if (!resolved || resolved.ignored) return [];
|
|
@@ -22,6 +24,7 @@ const uiFields = (table, existing, decisions) => {
|
|
|
22
24
|
return [{
|
|
23
25
|
name: resolved.name,
|
|
24
26
|
type: resolved.type,
|
|
27
|
+
sortable: resolved.sortable,
|
|
25
28
|
role
|
|
26
29
|
}];
|
|
27
30
|
});
|