@protobase/cli 0.49.2 → 0.50.0
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/bin/protobase.mjs +3 -2
- package/dist/build/config-bundle.js +1 -1
- package/dist/build/deploy-bundle.js +3 -4
- package/dist/build/plugin-build.js +16 -8
- package/dist/build/plugin-fields.js +5 -2
- package/dist/build/ui-check.js +5 -0
- package/dist/build/view-check.js +1 -1
- package/dist/cli/package.js +1 -1
- package/dist/config/project-files.js +4 -1
- package/dist/config/source-config.js +1 -1
- package/dist/dev/api-process.js +1 -1
- package/dist/dev/app-server.js +43 -35
- package/dist/dev/create-db.js +2 -2
- package/dist/dev/project.js +3 -2
- package/dist/dev/server-package.js +9 -21
- package/dist/doctor/run.js +1 -1
- package/dist/hand-over.d.ts +15 -0
- package/dist/hand-over.js +32 -0
- package/dist/main.js +22 -5
- package/dist/project/bundled-imports.js +41 -0
- package/dist/project/import-project-file.js +28 -8
- package/dist/project/load-data-config.js +4 -3
- package/dist/project/project-types.js +66 -0
- package/dist/run/preload.d.ts +1 -0
- package/dist/run/preload.js +20 -0
- package/dist/run/run-script.js +36 -0
- package/dist/supabase/load-phase.js +5 -4
- package/dist/version/project-packages.js +39 -0
- package/dist/version/project-version.js +33 -12
- package/package.json +9 -8
- package/skills/protobase/SKILL.md +1 -1
- package/skills/protobase/references/features/build-and-run.md +3 -0
- package/skills/protobase/references/features/releases.md +2 -1
- package/skills/protobase/references/getting-started.md +18 -5
- package/skills/protobase/references/guides/api-functions.md +1 -1
- package/skills/protobase/references/guides/billing-page.md +4 -4
- package/skills/protobase/references/guides/create-page.md +2 -2
- package/skills/protobase/references/guides/deploy.md +24 -8
- package/skills/protobase/references/guides/field-type.md +1 -1
- package/skills/protobase/references/guides/first-plugin.md +1 -1
- package/skills/protobase/references/guides/plugin-build.md +1 -1
- package/skills/protobase/references/guides/remote-resources.md +1 -1
- package/skills/protobase/references/guides/table-to-admin.md +8 -8
- package/skills/protobase/references/reference/ai.md +1 -1
- package/skills/protobase/references/reference/api.md +4 -4
- package/skills/protobase/references/reference/architecture.md +11 -6
- package/skills/protobase/references/reference/assistant.md +1 -1
- package/skills/protobase/references/reference/auth.md +17 -4
- package/skills/protobase/references/reference/blocks.md +1 -1
- package/skills/protobase/references/reference/bottom-bar.md +2 -2
- package/skills/protobase/references/reference/cli.md +50 -21
- package/skills/protobase/references/reference/client.md +3 -1
- package/skills/protobase/references/reference/config/api.md +2 -2
- package/skills/protobase/references/reference/config/app.md +2 -2
- package/skills/protobase/references/reference/config/sign-in.md +2 -3
- package/skills/protobase/references/reference/config.md +11 -9
- package/skills/protobase/references/reference/custom-components.md +3 -2
- package/skills/protobase/references/reference/email.md +4 -4
- package/skills/protobase/references/reference/events.md +1 -1
- package/skills/protobase/references/reference/jobs.md +6 -5
- package/skills/protobase/references/reference/layouts.md +2 -2
- package/skills/protobase/references/reference/mcp.md +9 -8
- package/skills/protobase/references/reference/notifications.md +10 -8
- package/skills/protobase/references/reference/plugins.md +3 -3
- package/skills/protobase/references/reference/ui-config.md +1 -1
- package/skills/protobase/references/reference/user-menu.md +3 -3
- package/skills/protobase/references/reference/versioning.md +21 -4
- package/skills/protobase/references/reference/webhooks.md +5 -5
|
@@ -6,11 +6,12 @@ import { configExports } from "@protobase/server/config-exports";
|
|
|
6
6
|
//#region src/project/load-data-config.ts
|
|
7
7
|
/**
|
|
8
8
|
* The resources, views and pages of a config folder, as the config module has them by convention: config/index.ts and
|
|
9
|
-
* every config/<dir>/ui.ts
|
|
9
|
+
* every config/<dir>/ui.ts, of the project in `projectDir`. Only those files and what they import run, not
|
|
10
|
+
* protobase.config.ts, which may need secrets.
|
|
10
11
|
*/
|
|
11
|
-
const loadDataConfig = async (configDir) => {
|
|
12
|
+
const loadDataConfig = async (configDir, projectDir) => {
|
|
12
13
|
const dirs = uiDirs(configDir);
|
|
13
|
-
const [index, ...ui] = await importProjectFiles([path.join(configDir, "index.ts"), ...dirs.map((dir) => path.join(configDir, dir, "ui.ts"))]);
|
|
14
|
+
const [index, ...ui] = await importProjectFiles([path.join(configDir, "index.ts"), ...dirs.map((dir) => path.join(configDir, dir, "ui.ts"))], projectDir);
|
|
14
15
|
const config = conventionConfig(index, dirs.map((dir, i) => [dir, ui[i]]));
|
|
15
16
|
const { resources, views, pages } = configExports(config);
|
|
16
17
|
return {
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { findPackageDirSync, packageName } from "../build/packages/package-dir.js";
|
|
2
|
+
import { projectPackages } from "../version/project-packages.js";
|
|
3
|
+
import { hostModuleIds } from "../serve/host-module-ids.js";
|
|
4
|
+
import { uiPackageDir } from "./admin-app.js";
|
|
5
|
+
import { protobaseFolder } from "./protobase-folder.js";
|
|
6
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
10
|
+
//#region src/project/project-types.ts
|
|
11
|
+
/** The tsconfig a project's own extends, relative to the project. */
|
|
12
|
+
const typesFile = path.join(protobaseFolder, "tsconfig.json");
|
|
13
|
+
const cliDir = fileURLToPath(new URL("../..", import.meta.url));
|
|
14
|
+
const typedPackages = [.../* @__PURE__ */ new Set([
|
|
15
|
+
"@protobase/cli",
|
|
16
|
+
"@protobase/client",
|
|
17
|
+
"@protobase/ui",
|
|
18
|
+
...hostModuleIds.map((id) => packageName(id))
|
|
19
|
+
])];
|
|
20
|
+
const declarationOf = (dir, target) => {
|
|
21
|
+
if (target === null) return void 0;
|
|
22
|
+
if (typeof target !== "string") {
|
|
23
|
+
const chosen = target.types ?? target.import ?? target.default ?? target.require;
|
|
24
|
+
return chosen === void 0 ? void 0 : declarationOf(dir, chosen);
|
|
25
|
+
}
|
|
26
|
+
const file = path.join(dir, target);
|
|
27
|
+
if (/\.(d\.[mc]?ts|tsx?)$/.test(file)) return existsSync(file) ? file : void 0;
|
|
28
|
+
if (!/\.[mc]?js$/.test(file)) return void 0;
|
|
29
|
+
return [
|
|
30
|
+
".d.ts",
|
|
31
|
+
".d.mts",
|
|
32
|
+
".d.cts"
|
|
33
|
+
].map((extension) => file.replace(/\.[mc]?js$/, extension)).find((candidate) => existsSync(candidate));
|
|
34
|
+
};
|
|
35
|
+
const packagePaths = (name, dir) => {
|
|
36
|
+
const manifest = JSON.parse(readFileSync(path.join(dir, "package.json"), "utf8"));
|
|
37
|
+
const exported = manifest.exports;
|
|
38
|
+
return (exported === void 0 || exported === null ? [[".", manifest.types ?? manifest.typings ?? manifest.main ?? "index.js"]] : typeof exported === "string" || !Object.keys(exported).every((key) => key.startsWith(".")) ? [[".", exported]] : Object.entries(exported).filter(([key]) => !key.includes("*"))).flatMap(([sub, target]) => {
|
|
39
|
+
const file = declarationOf(dir, target);
|
|
40
|
+
return file ? [[`${name}${sub.slice(1)}`, file]] : [];
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* The `paths` that point TypeScript at the CLI's own copies of the packages a bundled project gets from it, each import
|
|
45
|
+
* by name, never `*`, so a package the project lacks still fails as missing.
|
|
46
|
+
*/
|
|
47
|
+
const cliTypePaths = (ownDir = cliDir) => Object.fromEntries(typedPackages.flatMap((name) => {
|
|
48
|
+
const dir = findPackageDirSync(name, ownDir) ?? findPackageDirSync(name, uiPackageDir);
|
|
49
|
+
return dir ? packagePaths(name, dir).map(([id, file]) => [id, [file]]) : [];
|
|
50
|
+
}));
|
|
51
|
+
/**
|
|
52
|
+
* Writes `.protobase/tsconfig.json` in `projectDir`, which the project's tsconfig.json extends: in a bundled project
|
|
53
|
+
* its `paths` give the @protobase packages and those the serve runtime supplies the types of the CLI that builds the
|
|
54
|
+
* app, with nothing installed; a locked project's installed packages type themselves, so it holds no paths. The
|
|
55
|
+
* folder ignores itself in git, since the paths are this machine's.
|
|
56
|
+
*/
|
|
57
|
+
const writeProjectTypes = async (projectDir) => {
|
|
58
|
+
const folder = path.join(projectDir, protobaseFolder);
|
|
59
|
+
await mkdir(folder, { recursive: true });
|
|
60
|
+
const ignore = path.join(folder, ".gitignore");
|
|
61
|
+
if (!existsSync(ignore)) await writeFile(ignore, "*\n");
|
|
62
|
+
const compilerOptions = projectPackages(projectDir).mode === "bundled" ? { paths: cliTypePaths() } : {};
|
|
63
|
+
await writeFile(path.join(projectDir, typesFile), `${JSON.stringify({ compilerOptions }, null, 2)}\n`);
|
|
64
|
+
};
|
|
65
|
+
//#endregion
|
|
66
|
+
export { cliTypePaths, typesFile, writeProjectTypes };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { hostModuleIds } from "../serve/host-module-ids.js";
|
|
2
|
+
import { provideHostModules } from "../serve/host-modules.js";
|
|
3
|
+
import { cliTypePaths } from "../project/project-types.js";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
//#region src/run/preload.ts
|
|
6
|
+
const bun = globalThis.Bun;
|
|
7
|
+
const cliDir = fileURLToPath(new URL("../..", import.meta.url));
|
|
8
|
+
provideHostModules();
|
|
9
|
+
const others = Object.keys(cliTypePaths()).filter((id) => id.startsWith("@protobase/") && !hostModuleIds.includes(id));
|
|
10
|
+
bun.plugin({
|
|
11
|
+
name: "protobase-cli-modules",
|
|
12
|
+
setup: (build) => {
|
|
13
|
+
for (const id of others) build.module(id, async () => ({
|
|
14
|
+
exports: await import(bun.resolveSync(id, cliDir)),
|
|
15
|
+
loader: "object"
|
|
16
|
+
}));
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
//#endregion
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { projectPackages } from "../version/project-packages.js";
|
|
2
|
+
import { moduleFile } from "../module-file.js";
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
//#region src/run/run-script.ts
|
|
5
|
+
const preload = moduleFile("./preload", import.meta.url);
|
|
6
|
+
/**
|
|
7
|
+
* The Bun command line that runs `file` with `args` for the project in `projectDir`: never installing a missing package,
|
|
8
|
+
* and in a bundled project with the CLI's own copies of the @protobase packages and those the serve runtime supplies
|
|
9
|
+
* (see preload.ts). A locked project's script imports its installed packages.
|
|
10
|
+
*/
|
|
11
|
+
const scriptCommand = (projectDir, file, args) => [
|
|
12
|
+
"--no-install",
|
|
13
|
+
...projectPackages(projectDir).mode === "bundled" ? ["--preload", preload] : [],
|
|
14
|
+
file,
|
|
15
|
+
...args
|
|
16
|
+
];
|
|
17
|
+
/**
|
|
18
|
+
* Runs a project script, such as a seed or a migration, under Bun in a process of its own, in `projectDir`, and
|
|
19
|
+
* resolves with its exit code. Its output goes to this process's, so a host that captures that captures it too.
|
|
20
|
+
*/
|
|
21
|
+
const runScript = (projectDir, file, args) => new Promise((resolve, reject) => {
|
|
22
|
+
const child = spawn("bun", scriptCommand(projectDir, file, args), {
|
|
23
|
+
cwd: projectDir,
|
|
24
|
+
stdio: [
|
|
25
|
+
"inherit",
|
|
26
|
+
"pipe",
|
|
27
|
+
"pipe"
|
|
28
|
+
]
|
|
29
|
+
});
|
|
30
|
+
child.stdout.on("data", (chunk) => process.stdout.write(chunk));
|
|
31
|
+
child.stderr.on("data", (chunk) => process.stderr.write(chunk));
|
|
32
|
+
child.once("error", (error) => reject(error.code === "ENOENT" ? /* @__PURE__ */ new Error("protobase run needs Bun: install it from https://bun.sh") : error));
|
|
33
|
+
child.once("close", (code, signal) => resolve(code ?? (signal ? 1 : 0)));
|
|
34
|
+
});
|
|
35
|
+
//#endregion
|
|
36
|
+
export { runScript, scriptCommand };
|
|
@@ -37,13 +37,14 @@ const checkReady = async (url, projectDir, manifest) => {
|
|
|
37
37
|
await sql.end();
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
|
-
/** `protobase doctor`'s output on the config at `configDir`, or `undefined` when there is none. */
|
|
41
|
-
const doctorOutput = async (url, configDir) => {
|
|
40
|
+
/** `protobase doctor`'s output on the config at `configDir` of the project in `projectDir`, or `undefined` when there is none. */
|
|
41
|
+
const doctorOutput = async (url, configDir, projectDir) => {
|
|
42
42
|
if (!existsSync(path.join(configDir, "index.ts"))) return void 0;
|
|
43
43
|
let text = "";
|
|
44
44
|
await runDoctor({
|
|
45
45
|
url,
|
|
46
|
-
configDir
|
|
46
|
+
configDir,
|
|
47
|
+
projectDir
|
|
47
48
|
}, (line) => text += line);
|
|
48
49
|
return text;
|
|
49
50
|
};
|
|
@@ -106,7 +107,7 @@ const runLoadPhase = async (options, out) => {
|
|
|
106
107
|
out(`wrote ${path.relative(options.projectDir, path.join(options.migrationsDir, accountsFile))}, the users' accounts with their Supabase passwords and social providers\n`);
|
|
107
108
|
const target = connect(options.targetUrl);
|
|
108
109
|
const providers = await providerCounts(target).finally(() => target.end());
|
|
109
|
-
await writeFile(state.report, importReport(manifest, await doctorOutput(options.targetUrl, options.configDir), jobsWired, live, providers), { mode: 384 });
|
|
110
|
+
await writeFile(state.report, importReport(manifest, await doctorOutput(options.targetUrl, options.configDir, options.projectDir), jobsWired, live, providers), { mode: 384 });
|
|
110
111
|
out(`wrote ${path.relative(options.projectDir, state.report)}: what the import could not carry over\n`);
|
|
111
112
|
out("next: apply the migrations with the project's migrations; Supabase's users then sign in with their own passwords\n");
|
|
112
113
|
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
//#region src/version/project-packages.ts
|
|
4
|
+
const fields = [
|
|
5
|
+
"dependencies",
|
|
6
|
+
"devDependencies",
|
|
7
|
+
"optionalDependencies",
|
|
8
|
+
"peerDependencies"
|
|
9
|
+
];
|
|
10
|
+
/** The @protobase packages the package.json in `projectDir` lists, each with its field and specifier; none without one. */
|
|
11
|
+
const listedPackages = (projectDir) => {
|
|
12
|
+
const file = path.join(projectDir, "package.json");
|
|
13
|
+
if (!existsSync(file)) return [];
|
|
14
|
+
const manifest = JSON.parse(readFileSync(file, "utf8"));
|
|
15
|
+
return fields.flatMap((field) => Object.entries(manifest[field] ?? {}).flatMap(([name, specifier]) => name.startsWith("@protobase/") ? [{
|
|
16
|
+
field,
|
|
17
|
+
name,
|
|
18
|
+
specifier
|
|
19
|
+
}] : []));
|
|
20
|
+
};
|
|
21
|
+
/** Locked when any @protobase package is listed in dependencies, otherwise bundled. */
|
|
22
|
+
const modeOf = (listed) => listed.some((entry) => entry.field === "dependencies") ? "locked" : "bundled";
|
|
23
|
+
/**
|
|
24
|
+
* The project's mode and Protobase version specifier, from the package.json in `projectDir`. Every @protobase package
|
|
25
|
+
* it lists must carry the same specifier: they are released together and pass values to each other.
|
|
26
|
+
*/
|
|
27
|
+
const projectPackages = (projectDir) => {
|
|
28
|
+
const listed = listedPackages(projectDir);
|
|
29
|
+
const [first] = listed;
|
|
30
|
+
if (!first) return { mode: "bundled" };
|
|
31
|
+
const other = listed.find((entry) => entry.specifier !== first.specifier);
|
|
32
|
+
if (other) throw new Error(`${path.join(projectDir, "package.json")} lists ${first.name} at ${first.specifier} and ${other.name} at ${other.specifier}; list every @protobase package at the same version`);
|
|
33
|
+
return {
|
|
34
|
+
mode: modeOf(listed),
|
|
35
|
+
specifier: first.specifier
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
//#endregion
|
|
39
|
+
export { listedPackages, modeOf, projectPackages };
|
|
@@ -1,35 +1,56 @@
|
|
|
1
1
|
import { protobaseVersion } from "./version.js";
|
|
2
2
|
import { findPackageDirSync } from "../build/packages/package-dir.js";
|
|
3
|
+
import { projectPackages } from "./project-packages.js";
|
|
3
4
|
import { readFileSync } from "node:fs";
|
|
4
5
|
import path from "node:path";
|
|
5
6
|
import semver from "semver";
|
|
6
7
|
//#region src/version/project-version.ts
|
|
7
|
-
const
|
|
8
|
+
const installedPackages = [
|
|
8
9
|
"@protobase/cli",
|
|
9
10
|
"@protobase/server",
|
|
10
11
|
"@protobase/ui"
|
|
11
12
|
];
|
|
12
13
|
/**
|
|
13
|
-
* The Protobase version the project in `projectDir
|
|
14
|
+
* The Protobase version installed for the project in `projectDir`: the version its lockfile installed, read from the
|
|
14
15
|
* @protobase package Node's resolution finds from there. Undefined outside a project, or before its install.
|
|
15
16
|
*/
|
|
16
17
|
const projectProtobaseVersion = (projectDir) => {
|
|
17
|
-
for (const name of
|
|
18
|
+
for (const name of installedPackages) {
|
|
18
19
|
const dir = findPackageDirSync(name, projectDir);
|
|
19
20
|
if (dir) return JSON.parse(readFileSync(path.join(dir, "package.json"), "utf8")).version;
|
|
20
21
|
}
|
|
21
22
|
};
|
|
22
23
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
24
|
+
* The Protobase version a bundle of the project in `projectDir` runs on, its manifest's `protobase`: the version of the
|
|
25
|
+
* copies the build uses, the CLI's own in a bundled project and the installed ones in a locked project, which fails
|
|
26
|
+
* before its install.
|
|
26
27
|
*/
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
const bundleProtobaseVersion = (projectDir, cliVersion = protobaseVersion) => {
|
|
29
|
+
if (projectPackages(projectDir).mode === "bundled") return cliVersion;
|
|
30
|
+
const installed = projectProtobaseVersion(projectDir);
|
|
31
|
+
if (installed === void 0) throw new Error(`${projectDir} lists its @protobase packages in dependencies and has none installed; install the project's dependencies first`);
|
|
32
|
+
return installed;
|
|
33
|
+
};
|
|
34
|
+
const checkInstalled = (projectDir, cliVersion) => {
|
|
35
|
+
const installed = projectProtobaseVersion(projectDir);
|
|
36
|
+
if (installed === void 0) return;
|
|
37
|
+
const range = `^${installed}`;
|
|
31
38
|
if (semver.satisfies(cliVersion, range)) return;
|
|
32
|
-
throw new Error(`This project
|
|
39
|
+
throw new Error(`This project has Protobase ${installed} installed, and this CLI is Protobase ${cliVersion}: run it with a Protobase ${range} CLI`);
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Refuses a project whose Protobase version this CLI does not satisfy, the one version check the CLI makes: the
|
|
43
|
+
* specifier its package.json lists the @protobase packages at must hold the CLI's version, by semver, and in a locked
|
|
44
|
+
* project, whose installed copies run, those must be ones the CLI runs. A specifier that is no semver range, such as
|
|
45
|
+
* `workspace:*`, says no version, so the installed copies are checked instead. Outside a project, or one that lists no
|
|
46
|
+
* @protobase package, there is nothing to check.
|
|
47
|
+
*/
|
|
48
|
+
const checkProjectVersion = (projectDir, cliVersion = protobaseVersion) => {
|
|
49
|
+
const { mode, specifier } = projectPackages(projectDir);
|
|
50
|
+
if (specifier === void 0) return;
|
|
51
|
+
const range = semver.validRange(specifier) !== null;
|
|
52
|
+
if (range && !semver.satisfies(cliVersion, specifier)) throw new Error(`This project asks for Protobase ${specifier}, and this CLI is Protobase ${cliVersion}: run it with a CLI whose version ${specifier} holds`);
|
|
53
|
+
if (mode === "locked" || !range) checkInstalled(projectDir, cliVersion);
|
|
33
54
|
};
|
|
34
55
|
//#endregion
|
|
35
|
-
export { checkProjectVersion, projectProtobaseVersion };
|
|
56
|
+
export { bundleProtobaseVersion, checkProjectVersion, projectProtobaseVersion };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.50.0",
|
|
4
4
|
"description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
"sideEffects": [
|
|
14
14
|
"./dist/dev/entry.js",
|
|
15
15
|
"./dist/dev/api-process.js",
|
|
16
|
-
"./dist/serve/main.js"
|
|
16
|
+
"./dist/serve/main.js",
|
|
17
|
+
"./dist/run/preload.js"
|
|
17
18
|
],
|
|
18
19
|
"engines": {
|
|
19
20
|
"node": ">=22.12.0"
|
|
@@ -40,12 +41,12 @@
|
|
|
40
41
|
"dependencies": {
|
|
41
42
|
"@better-auth/core": "^1.7.12",
|
|
42
43
|
"@hono/node-server": "^2.1.3",
|
|
43
|
-
"@protobase/config": "0.
|
|
44
|
-
"@protobase/layout": "0.
|
|
45
|
-
"@protobase/query": "0.
|
|
46
|
-
"@protobase/schema": "0.
|
|
47
|
-
"@protobase/server": "0.
|
|
48
|
-
"@protobase/ui": "0.
|
|
44
|
+
"@protobase/config": "0.50.0",
|
|
45
|
+
"@protobase/layout": "0.50.0",
|
|
46
|
+
"@protobase/query": "0.50.0",
|
|
47
|
+
"@protobase/schema": "0.50.0",
|
|
48
|
+
"@protobase/server": "0.50.0",
|
|
49
|
+
"@protobase/ui": "0.50.0",
|
|
49
50
|
"@react-email/render": "^2.1.0",
|
|
50
51
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
51
52
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -11,7 +11,7 @@ Run the CLI as the project does: `npx protobase <command>`, or `bun run protobas
|
|
|
11
11
|
|
|
12
12
|
## Everyday workflow
|
|
13
13
|
|
|
14
|
-
1. Run `protobase dev`: one
|
|
14
|
+
1. Run `protobase dev`: one port for the admin app and the API, which runs in a process of its own; changes to config, layouts and functions show without a restart.
|
|
15
15
|
2. Change the config (`data.ts`, `ui.ts`, layouts) or the app's code.
|
|
16
16
|
3. Database changes go through the project's migrations, never through startup: `protobase migration` writes the migrations a config feature needs, the project applies them with its own migrate script. See [references/reference/cli.md](references/reference/cli.md#migration).
|
|
17
17
|
|
|
@@ -6,6 +6,8 @@ Develop, build and run an app, on servers, in containers and on phones.
|
|
|
6
6
|
|
|
7
7
|
- [Node and Bun](../reference/cli.md#how-it-runs): The `protobase` command runs on Node 22.12 or later or on Bun, and a bundle runs on both unless it is built for Bun only.
|
|
8
8
|
- [Dev server](../reference/cli.md#dev): The admin app and the API on one port, with changes shown without a restart.
|
|
9
|
+
- [Editor types](../reference/cli.md#types): `protobase types` gives the editor and `tsc` the types of the CLI that builds the app, with nothing installed.
|
|
10
|
+
- [Project scripts](../reference/cli.md#run): `protobase run` runs a seed or a migration script on the CLI's packages.
|
|
9
11
|
- [Migrations from config](../reference/cli.md#migration): Writes the SQL migrations for what the config turns on, as files of the project.
|
|
10
12
|
- [User and organization commands](../reference/cli.md#users): Create users, set roles and manage organizations from the terminal.
|
|
11
13
|
- [Encryption commands](../reference/cli.md#encryption-status): Report and fix plaintext or old-key values of encrypted fields.
|
|
@@ -19,4 +21,5 @@ Develop, build and run an app, on servers, in containers and on phones.
|
|
|
19
21
|
- [Separate worker](../reference/cli.md#worker): Jobs and event delivery in their own process.
|
|
20
22
|
- [Container images](../guides/deploy.md#images): A runtime image for each release, for amd64 and arm64.
|
|
21
23
|
- [Self-hosted image](../guides/deploy.md#a-self-hosted-image): One image with the app inside that serves, migrates and creates the first admin.
|
|
24
|
+
- [Protobase Cloud deploys](../guides/deploy.md#protobase-cloud): A push to the app's GitHub branch builds it, migrates and checks its database in one transaction, and switches to the new version once it answers its health check.
|
|
22
25
|
- [Mobile apps](../guides/mobile-app.md) (beta): Runs an app on iOS and Android, also on your own iPhone, with sign-in, and builds signed store releases from a section in its config.
|
|
@@ -6,7 +6,8 @@ How Protobase is released and versioned, and what a release keeps working.
|
|
|
6
6
|
|
|
7
7
|
- [Releases](../reference/versioning.md#releases): Every fix and feature is released when it lands, as npm packages, published with provenance, and images of one version.
|
|
8
8
|
- [Version rules](../reference/versioning.md#versions-below-10): Semantic versioning. Below 1.0 a minor version may break.
|
|
9
|
-
- [
|
|
9
|
+
- [Bundled and locked projects](../reference/versioning.md#bundled-and-locked-projects): A project that lists the `@protobase` packages as dev dependencies, or not at all, runs on the CLI's own and updates with a newer CLI, with nothing of Protobase installed. Listed as dependencies, they lock it to one version.
|
|
10
|
+
- [Bundles and runtimes](../reference/versioning.md#bundles-and-runtimes): The CLI runs every project whose version specifier holds its own version, and a bundle names the version it was built with, for the host to serve it on.
|
|
10
11
|
- [Plugins keep working](../reference/versioning.md#plugins): Plugins target a plugin API that releases keep.
|
|
11
12
|
- [Runtime updates](../reference/versioning.md#runtime-updates): Admins see whether the runtime has an update and start it from the app, when the host offers one.
|
|
12
13
|
- [New version notice](../reference/versioning.md#a-new-version-under-an-open-page): An open page keeps working when the server moves to a new Protobase version, and offers a reload.
|
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
Start an app with npm create protobase, install the repository, run the ERP, real estate and property portal examples and learn the development commands.
|
|
6
6
|
|
|
7
|
-
Protobase is a config-driven admin panel framework for existing Postgres databases.
|
|
7
|
+
Protobase is a config-driven admin panel framework for existing Postgres databases. Each resource's data config lives in `config/<resource>/data.ts` and its UI config in `ui.ts`, all exported from `config/index.ts`; the rest of the app, its sign-in, jobs, files and API settings, is one object of data in [`protobase.config.ts`](reference/config.md). A Hono server serves the API and a React app renders the admin. Coding agents get the guides and reference of the installed version with [`protobase skill install`](reference/cli.md#skill).
|
|
8
8
|
|
|
9
9
|
An app's own React code, its components, field types and actions, is a [plugin](reference/plugins.md): built on its own against a plugin API that Protobase's releases keep, and loaded by the admin app when it starts. Protobase maintains the admin app, the API and the server, and a plugin keeps working as the app moves to newer releases, with their fixes and features, without changes of its own. Below 1.0 a new minor version may still change the config, and the bundle is built again for it; the plugins' code stays as it is (see [Who maintains what](reference/plugins.md#who-maintains-what)).
|
|
10
10
|
|
|
11
11
|
## Start an app
|
|
12
12
|
|
|
13
|
-
`npm create protobase my-app` asks which preset to start from, scratch (the default), the ERP or real estate, writes the project into `my-app`, with the `@protobase` packages in the range of the latest release's
|
|
13
|
+
`npm create protobase my-app` asks which preset to start from, scratch (the default), the ERP or real estate, writes the project into `my-app`, with the `@protobase` packages in `devDependencies` at the caret range of the latest release, so it is [bundled](reference/versioning.md#bundled-and-locked-projects): dev, the build and its scripts run the CLI's own copies, and a newer CLI in that range updates it with no change to its files. It prints the next steps. Without a folder it asks for one too. `--preset <name>` picks the preset without asking; without a terminal it takes scratch. `bun create protobase` and `pnpm create protobase` do the same, and take `--preset` without the `--` that npm needs. It needs Node 22.12 or later. Each preset has an `AGENTS.md` with the rules for a coding agent that changes the app, such as a new migration file for every schema change.
|
|
14
14
|
|
|
15
15
|
```sh
|
|
16
16
|
npm create protobase my-app
|
|
@@ -28,6 +28,19 @@ bun run protobase users create you@example.com --generate-password
|
|
|
28
28
|
bun run dev # http://localhost:5173
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
+
### The first table
|
|
32
|
+
|
|
33
|
+
A scratch app starts without resources, so `protobase doctor` refuses it until it has one. A table comes in through a migration, the next file in `db/migrations/`, and `scaffold` writes its resource from the database:
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
# db/migrations/007_customers.sql: create table customers (id bigint generated always as identity primary key, name text not null);
|
|
37
|
+
bun run db:migrate
|
|
38
|
+
bun run protobase scaffold --ui --yes --exclude public.schema_migrations
|
|
39
|
+
bun run protobase doctor
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
`scaffold` writes `config/customers/data.ts` and `ui.ts` and exports them from `config/index.ts`, where Protobase finds every resource, view and page; `--exclude public.schema_migrations` leaves out the table the migrate script records its migrations in. `bun run dev` shows the new list at once. The [Data config](reference/data-config.md) and [UI config](reference/ui-config.md) say what else a resource can be.
|
|
43
|
+
|
|
31
44
|
## Admin over an existing database
|
|
32
45
|
|
|
33
46
|
For a Postgres database you already have, [Admin over an existing database](guides/existing-database.md) goes from an empty folder to signing in: install the packages, scaffold the config from the tables, check it with `doctor`, add sign-in and its tables, create the first admin and run `protobase dev`.
|
|
@@ -88,14 +101,14 @@ bun run --cwd tests/apps/property-portal dev # http://localhost:517
|
|
|
88
101
|
| `bun run test:watch` | `bun run test` in watch mode |
|
|
89
102
|
| `bun run test:integration` | the database, subprocess and build tests (projects `integration*`), against the Postgres container, among them the real-Postgres tests (`*.postgres.test.ts`) |
|
|
90
103
|
| `bun run test:smoke` / `node --run test:smoke` | the CLI on Bun or on Node builds the ERP and serves its bundle, whose `€` must come back intact; part of `test:integration` on Bun |
|
|
91
|
-
| `bun run presets:write <version> <dir>` | writes each preset to `<dir>/<name>`: a standalone copy of its example with the `@protobase` packages in the caret range of `<version>` (`^x.y.z`, which below 1.0 covers only that minor) and its own `bun.lock` at exactly `<version>`, which must be on npm |
|
|
104
|
+
| `bun run presets:write <version> <dir>` | writes each preset to `<dir>/<name>`: a standalone copy of its example with the `@protobase` packages in `devDependencies`, bundled, in the caret range of `<version>` (`^x.y.z`, which below 1.0 covers only that minor) and its own `bun.lock` at exactly `<version>`, which must be on npm |
|
|
92
105
|
| `bun run images:context` | the build contexts of the `protobase` and `protobase-dev` images in `dist/images`, at the version in `package.json` (see [Deploy](guides/deploy.md#images)) |
|
|
93
106
|
| `bun run test:presets` | writes each preset as `bun run presets:write` does it and installs it with Bun from npm (so at a published version), then migrates, seeds, checks, tests and builds it on a database of its own, as a role without superuser rights; needs the Postgres container |
|
|
94
107
|
| `bun run test:postgres` | the Postgres suite in `tests/postgres/` (Vitest project `postgres`): the ERP's medium seed and the planner's statistics on it, and the jobs and event delivery through PgBouncer; needs the Postgres and PgBouncer containers and `bun run test:db postgres` |
|
|
95
108
|
| `bun run test:db` | builds the template databases the database tests clone for each run (`protobase_test_template`, `real_estate_test_template`, `property_portal_test_template`, all at small scale, and the empty, auth and jobs `snapshot_*_test_template` the real-Postgres and end-to-end tests clone), when missing or older than what they are built from; without them those tests skip. `bun run test:db postgres` builds the Postgres suite's (`protobase_medium_test_template`, the ERP at medium scale), `bun run test:db snapshots` the ones `test:record` records on (`snapshot_*_test_template`). Tests never use the `protobase`, `real_estate` or `property_portal` databases |
|
|
96
109
|
| `bun run typecheck` | `tsc --noEmit` |
|
|
97
110
|
| `bun run check:boundaries` | dependency-cruiser package rules |
|
|
98
|
-
| `bun run check` | typecheck
|
|
111
|
+
| `bun run check` | typecheck, the unit, snapshot, integration and end-to-end tests a change affects (all of them without `CHECK_BASE`), and check:boundaries |
|
|
99
112
|
| `bun run storybook` | Storybook on port 6006 |
|
|
100
113
|
| `bun run build-storybook` | static Storybook build; its toolbar switches every story between light and dark |
|
|
101
114
|
| `bun run screenshots` / `bun run screenshots:dark` | screenshots of the stories tagged `website`, in light into `screenshots/`, in dark into `screenshots/dark/` |
|
|
@@ -105,4 +118,4 @@ bun run --cwd tests/apps/property-portal dev # http://localhost:517
|
|
|
105
118
|
| `bun run release --dry-run` | the next version and its changelog, from the commits since the last release (see [Versioning](reference/versioning.md)) |
|
|
106
119
|
| `bun run docs:check` | opens every page of the built site in Chromium and fails on console errors and failed requests; `BASE=https://docs.protobase.net` checks the live site |
|
|
107
120
|
|
|
108
|
-
Each public import is a package in `packages/` (`@protobase/schema`, `layout`, `query`, `client`, `ui`, `server`, and `cli` for the `protobase` command); `packages/presets` writes the projects a new app starts from and is not published; `packages/create-protobase` is `npm create protobase`, with every preset. See [Architecture](reference/architecture.md) for the layout and import rules.
|
|
121
|
+
Each public import is a package in `packages/` (`@protobase/schema`, `layout`, `query`, `client`, `ui`, `server`, `config` for `protobase.config.ts`, `mobile` for `protobase mobile`, and `cli` for the `protobase` command); `packages/presets` writes the projects a new app starts from and is not published; `packages/create-protobase` is `npm create protobase`, with every preset. See [Architecture](reference/architecture.md) for the layout and import rules.
|
|
@@ -402,7 +402,7 @@ export default defineFunction({ longQueries: true }, async (request, { db }) =>
|
|
|
402
402
|
```
|
|
403
403
|
|
|
404
404
|
- **Up to 30 seconds** per query, the most any query of an app may run. Work longer than that belongs in steps, such as a [job](../reference/jobs.md) per batch, which takes `longQueries` too.
|
|
405
|
-
- **One connection kept for it.** Under `protobase dev` and `serve`, those queries run on a connection of their own, which asks for the longer timeout when it logs in, so long work never takes the connections pages need; a second long call waits for it. A PgBouncer of your own in front of the database must list `statement_timeout` in `track_extra_parameters` to pass that on; Protobase Cloud's does.
|
|
405
|
+
- **One connection kept for it.** Under `protobase dev` and `serve`, those queries run on a connection of their own, which asks for the longer timeout when it logs in, so long work never takes the connections pages need; a second long call waits for it. A PgBouncer of your own in front of the database must list `statement_timeout` in `track_extra_parameters` to pass that on; Protobase Cloud's does.
|
|
406
406
|
- **`records` keep the API's limit,** [`statementTimeoutMs`](../reference/api.md#safety).
|
|
407
407
|
- **A query past its limit** is stopped, and the call answers `504 statement-timeout` naming the call, its limit and the way out, such as `POST /api/functions/import ran a query longer than the database's statement timeout, so the database stopped it. Make the query faster, such as with an index or a narrower filter, or give it longQueries: true, whose queries may run up to 30 s.` It goes to the app's error hook, `hooks/error.ts`, and the [error tracker](../reference/api.md#error-reporting).
|
|
408
408
|
|
|
@@ -40,7 +40,7 @@ The card shows the active subscription. `plan.name` and `plan.price` reach throu
|
|
|
40
40
|
|
|
41
41
|
The two header buttons are named actions of the subscriptions view, each with its own kind of behaviour. The views of the billing schema declare every action this page uses:
|
|
42
42
|
|
|
43
|
-
```ts title="config/billing/
|
|
43
|
+
```ts title="config/billing/ui.ts"
|
|
44
44
|
import { view } from '@protobase/schema'
|
|
45
45
|
import type { billingProfiles, invoices, paymentMethods, plans, subscriptions } from './billing-config'
|
|
46
46
|
|
|
@@ -73,7 +73,7 @@ export const invoicesView = view<typeof invoices>('invoices')
|
|
|
73
73
|
.actions((a) => [a.action('download', { label: 'Download PDF' })])
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
-
`a.update('cancel', ...)` sets `status` after its `confirm` question. `a.link` opens its `href`, with `{plan}` filled in from the record:
|
|
76
|
+
`a.update('cancel', ...)` sets `status` after its `confirm` question. `a.link` opens its `href`, with `{plan}` filled in from the record: an `href` leaves the app (`https:`, `mailto:`), while a place in the app is a `to`, such as `{ kind: 'record', resource: 'plans', key: '{plan}' }`; a path in the app as an `href` is refused. Cancel the plan in the story and the card says there is no active plan, because its `filter` no longer matches.
|
|
77
77
|
|
|
78
78
|
## 2. Who we bill
|
|
79
79
|
|
|
@@ -260,7 +260,7 @@ export const billing = page(
|
|
|
260
260
|
|
|
261
261
|
Two things here are not built-in blocks.
|
|
262
262
|
|
|
263
|
-
`SeatHistory` is a **custom component**. `component('SeatHistory')` declares it for the layout, with its props typed, and the element stays data: `{ type: 'SeatHistory', props: { months: 6 }, custom: true }`. The React code lives in the app, exported under the same name from `protobase.ui.tsx` at the project root, which the admin
|
|
263
|
+
`SeatHistory` is a **custom component**. `component('SeatHistory')` declares it for the layout, with its props typed, and the element stays data: `{ type: 'SeatHistory', props: { months: 6 }, custom: true }`. The React code lives in the app, exported under the same name from `protobase.ui.tsx` at the project root, which `protobase build` builds into a [plugin](../reference/plugins.md) the admin app loads. Inside a RecordCard, `useLayoutRecord()` gives it the record.
|
|
264
264
|
|
|
265
265
|
"Download PDF" is a named action without built-in behaviour (`a.action('download', ...)`), so it runs the handler registered under its name, with the record, the API client and the router. The ERP example has one of each, its component in a file of its own:
|
|
266
266
|
|
|
@@ -281,7 +281,7 @@ const send = async ({ record, recordKey, etag, client }: ActionContext) => {
|
|
|
281
281
|
export default defineUi({ actions: { send } })
|
|
282
282
|
```
|
|
283
283
|
|
|
284
|
-
The rest is familiar: a
|
|
284
|
+
The rest is familiar: a `Table` of the latest invoices, with a link to all of them, spanning two of the three columns, a count of open invoices, and a `Link` inside the text of a card.
|
|
285
285
|
|
|
286
286
|
If the app has no component registered under a name, the page says so where the component would be, and an action without a handler is disabled:
|
|
287
287
|
|
|
@@ -26,7 +26,7 @@ export const bookRepair = page(
|
|
|
26
26
|
)
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
Its `roles` say who may book: they are the people who get the page, and so **New**.
|
|
29
|
+
Its `roles` say who may book: they are the people who get the page, and so **New**. Protobase finds pages among the exports of `config/index.ts`, so export it there: `export { bookRepair } from './pages/book-repair'`.
|
|
30
30
|
|
|
31
31
|
## 2. The component
|
|
32
32
|
|
|
@@ -94,7 +94,7 @@ export const repairsView = view<typeof repairs>('repairs')
|
|
|
94
94
|
|
|
95
95
|
## 4. Create through a function
|
|
96
96
|
|
|
97
|
-
With its own page, the shop can make the [API function](api-functions.md) `book-repair` the only way in: it checks the answers, plans the job and inserts the repair with `db`, which skips the access rules. The resource's API then refuses creates:
|
|
97
|
+
With its own page, the shop can make the [API function](api-functions.md) `book-repair`, the default export of `functions/book-repair.ts`, the only way in: it checks the answers, plans the job and inserts the repair with `db`, which skips the access rules. The resource's API then refuses creates:
|
|
98
98
|
|
|
99
99
|
```ts
|
|
100
100
|
// config/repairs/data.ts
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
# Deploy
|
|
4
4
|
|
|
5
|
-
Ship a project as one bundle folder and run it with the serve runtime.
|
|
5
|
+
Ship a project as one bundle folder and run it with the serve runtime, on a host of your own or on Protobase Cloud from a push to GitHub.
|
|
6
6
|
|
|
7
|
-
A project ships as one bundle folder; the host runs protobase around it.
|
|
7
|
+
A project ships as one bundle folder; the host runs protobase around it. An app on Protobase Cloud deploys from a push to its GitHub branch instead, which builds and serves the bundle for it (see [Protobase Cloud](#protobase-cloud)).
|
|
8
8
|
|
|
9
9
|
```sh
|
|
10
10
|
bun run --cwd tests/apps/erp protobase build # the bundle to ship: tests/apps/erp/dist/
|
|
@@ -28,7 +28,7 @@ dist/
|
|
|
28
28
|
plugins and the app's version
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
The host serves `public/` itself and sends only the manifest's `api` paths to the runtime (`/api` and the two OAuth discovery documents of [MCP clients](../reference/auth.md#oauth-for-mcp-clients), and `/.well-known/webauthn
|
|
31
|
+
The host serves `public/` itself and sends only the manifest's `api` paths to the runtime (`/api` and the two OAuth discovery documents of [MCP clients](../reference/auth.md#oauth-for-mcp-clients)), and `/.well-known/webauthn` for an app on [several origins](../reference/auth.md#several-origins), which the manifest does not list, so loading the UI never needs a running container. With the UI it sends `X-Frame-Options: DENY` and `Content-Security-Policy: frame-ancestors 'none'`, as `protobase serve` does, so no other site frames the app's pages. The runtime serves the API alone; `protobase serve dist` serves the whole folder the same way, to check a bundle locally. The host passes `DATABASE_URL`, `PORT` (default 8787) and optionally `PROTOBASE_DB_CONNECTIONS` (the connections the app may open, so its functions and jobs leave one to requests, see [`serve`](../reference/cli.md#serve)), `REQUEST_LOG`, `PROTOBASE_SMTP_URL` and `PROTOBASE_MAIL_FROM` (the mail server and sender for [password reset](../reference/auth.md#password-reset) and emailed sign-in codes) `PROTOBASE_APP_NAME` (the app's name in that mail, see [`name`](../reference/config/app.md#name)) `PROTOBASE_SIGN_IN_*` (a provider people with an account sign in with, the [platform sign-in provider](../reference/auth.md#platform-sign-in-provider)) `PROTOBASE_OPERATOR_*` (the provider its staff sign in with for [staff sign-in](../reference/auth.md#staff-sign-in)), `PROTOBASE_ORIGINS` and `PROTOBASE_PASSKEY_DOMAIN` (the app's [other origins](../reference/auth.md#several-origins) and its passkey domain) `PROTOBASE_CORS_ORIGINS` (the websites that may call its API, see [CORS](../reference/api.md#cors)), `PROTOBASE_TRUSTED_PROXIES` (the proxies in front of the runtime, whose `X-Forwarded-For` names the client the sign-in limits count, see [Client addresses](../reference/auth.md#client-addresses)) and `PROTOBASE_SENTRY_DSN` (the app's [error tracker](../reference/api.md#error-reporting)), `PROTOBASE_URL` and `PROTOBASE_SECRET` (the app's address and secret, unless its config sets [`url` and `secret`](../reference/config/app.md)), plus the project's own settings, which its config reads where it serves. The runtime and the config module are plain JavaScript for Bun: no install, no TypeScript, no writes. The runtime supplies protobase and the dependencies it runs on the server (`pg`, `postgres`, `kysely`, `better-auth`, ...), so the config module carries only the project's code and the other packages it uses. The manifest's `protobase` is the version the bundle was built with, the building CLI's in a [bundled project](../reference/versioning.md#bundled-and-locked-projects) and the installed one in a locked project, and the host serves the bundle on the runtime of that version (see [Versioning](../reference/versioning.md#bundles-and-runtimes)). The manifest format and the routing rules are in the CLI reference: [`build`](../reference/cli.md#build), [`build-serve`](../reference/cli.md#build-serve) and [`serve`](../reference/cli.md#serve).
|
|
32
32
|
|
|
33
33
|
## Migrations
|
|
34
34
|
|
|
@@ -41,10 +41,10 @@ Every release pushes two public images to GitHub's registry, for `linux/amd64` a
|
|
|
41
41
|
| Image | What it holds |
|
|
42
42
|
| --- | --- |
|
|
43
43
|
| `ghcr.io/prototeamhq/protobase:<version>` | the serve runtime, compiled with Bun into `/opt/protobase/protobase-serve`, which serves the API of the bundle mounted at `/app` (and, given the folder, its app too, see [a self-hosted image](#a-self-hosted-image)); the release's prebuilt admin app at `/opt/protobase/shell`, which a host may serve for the bundle's [shell paths](../reference/plugins.md#the-shell) instead of the bundle's copy; Bun for its healthcheck on `/health`, and the C++ runtime native add-ons link. It runs as `nonroot` (65532) and writes nothing, so it runs with a read-only root filesystem |
|
|
44
|
-
| `ghcr.io/prototeamhq/protobase-dev:<version>` | Bun and the presets at `/opt/protobase/presets/<name>` (`erp`, `real-estate`, `scratch`), with the dependencies they share installed in `/workspace` and Bun's cache in `/opt/bun-cache`. It has no Node: the presets' scripts and the `protobase` command run on Bun. It runs as `bun` (1000) |
|
|
44
|
+
| `ghcr.io/prototeamhq/protobase-dev:<version>` | Bun, the `protobase` command of that version installed globally (in `/opt/protobase/cli`, on `PATH`), and the presets at `/opt/protobase/presets/<name>` (`erp`, `real-estate`, `scratch`), with the dependencies they share installed in `/workspace` and Bun's cache in `/opt/bun-cache`. The global `protobase` builds a bundled project with nothing installed and hands a locked one over to the CLI it installed (see [Bundled and locked projects](../reference/versioning.md#bundled-and-locked-projects)). It has no Node: the presets' scripts and the `protobase` command run on Bun. It runs as `bun` (1000) |
|
|
45
45
|
|
|
46
46
|
```sh
|
|
47
|
-
docker run -v "$PWD/dist:/app:ro" -p 127.0.0.1:8787:8787 -e DATABASE_URL -e PROTOBASE_URL -e PROTOBASE_SECRET ghcr.io/prototeamhq/protobase:
|
|
47
|
+
docker run -v "$PWD/dist:/app:ro" -p 127.0.0.1:8787:8787 -e DATABASE_URL -e PROTOBASE_URL -e PROTOBASE_SECRET ghcr.io/prototeamhq/protobase:"$VERSION" # the version of the @protobase/cli that built dist/
|
|
48
48
|
```
|
|
49
49
|
|
|
50
50
|
In `protobase-dev`, copy a preset into `/workspace` and `bun install --frozen-lockfile` has nothing to do; installed anywhere else, it comes from the cache, without the network.
|
|
@@ -54,7 +54,7 @@ The Dockerfiles are `docker/protobase/Dockerfile` and `docker/protobase-dev/Dock
|
|
|
54
54
|
```sh
|
|
55
55
|
bun run images:context # dist/images/protobase and dist/images/protobase-dev
|
|
56
56
|
docker build -f docker/protobase/Dockerfile -t protobase dist/images/protobase
|
|
57
|
-
docker build -f docker/protobase-dev/Dockerfile -t protobase-dev dist/images/protobase-dev
|
|
57
|
+
docker build -f docker/protobase-dev/Dockerfile --build-arg PROTOBASE_VERSION="$(bun -p "require('./package.json').version")" -t protobase-dev dist/images/protobase-dev
|
|
58
58
|
```
|
|
59
59
|
|
|
60
60
|
## A self-hosted image
|
|
@@ -62,8 +62,9 @@ docker build -f docker/protobase-dev/Dockerfile -t protobase-dev dist/images/pro
|
|
|
62
62
|
A product built on Protobase ships to self-hosters as one image: the runtime image with the bundle inside. Build the bundle with `protobase build --bun`, then:
|
|
63
63
|
|
|
64
64
|
```dockerfile
|
|
65
|
-
# The runtime of the @protobase/cli version that built dist
|
|
66
|
-
|
|
65
|
+
# The runtime of the @protobase/cli version that built dist/: docker build --build-arg VERSION=<that version> .
|
|
66
|
+
ARG VERSION
|
|
67
|
+
FROM ghcr.io/prototeamhq/protobase:${VERSION}
|
|
67
68
|
COPY dist /app
|
|
68
69
|
CMD ["/app"]
|
|
69
70
|
```
|
|
@@ -189,3 +190,18 @@ docker compose up -d
|
|
|
189
190
|
Stop any `protobase worker` processes before `migrate` too.
|
|
190
191
|
|
|
191
192
|
When a migration fails, `migrate` exits with an error and its transaction is rolled back, so the schema is unchanged. Set `APP_VERSION` back and `docker compose start app` brings the old version back on it. A plain `docker compose up -d` with the new version also stops the old one before `migrate`, but after a failure nothing serves until `APP_VERSION` is set back and `up -d` runs again. Going back after a migration that succeeded needs the backup.
|
|
193
|
+
|
|
194
|
+
## Protobase Cloud
|
|
195
|
+
|
|
196
|
+
An app on Protobase Cloud whose code is on GitHub follows one branch of its repository, the default branch unless the app was linked to another. A push to that branch deploys it; nothing else does, and a change on another branch, a tag or a pull request deploys nothing.
|
|
197
|
+
|
|
198
|
+
1. Protobase Cloud builds the branch's newest commit. While a build runs, later pushes wait, and the next build takes the newest commit then, so quick pushes give one build.
|
|
199
|
+
2. The build installs the packages with `bun install --frozen-lockfile` and runs `protobase build`. It runs neither the project's typecheck nor its tests.
|
|
200
|
+
3. The deploy stops the app's writes, then runs the project's `db:migrate`, the auth schema's migration and `protobase doctor --env DATABASE_URL` in one database transaction, which commits only when all of them pass. Pages keep reading meanwhile; a write, sign-in included, answers that the app is being updated.
|
|
201
|
+
4. Writes come back, the new version starts on its own and must answer `/health` with its startup checks, and only then does the app switch to it.
|
|
202
|
+
|
|
203
|
+
When a step fails, the previous version keeps serving on the database as it was, except after a failed start, which comes after the migrations committed: they stay applied. Each build reports on GitHub as the check run `Protobase deploy` on the commit it built, with the step that failed and the end of its output. A commit whose build failed is not built again: the fix is a new push.
|
|
204
|
+
|
|
205
|
+
Since the deploy runs neither the typecheck nor the tests, and refuses what `doctor` refuses, check a change before pushing it: the project's typecheck and tests, `protobase doctor --env DATABASE_URL` on a database with the migrations applied, and `protobase build`. The migrations run in one transaction, so a statement Postgres refuses in one, such as `create index concurrently`, fails the deploy. Protobase Cloud also pushes to the branch itself, for an update of the app's Protobase packages, so pull before pushing.
|
|
206
|
+
|
|
207
|
+
[`protobase skill install`](../reference/cli.md#skill) writes the `protobase-cloud` agent skill into the project, with how to check that a change went live and why a deploy failed, step by step.
|
|
@@ -77,7 +77,7 @@ import { StepsDisplay, StepsEditor } from './components/order-steps'
|
|
|
77
77
|
export { OrdersPerDay } from './components/orders-per-day'
|
|
78
78
|
|
|
79
79
|
export default definePlugin({
|
|
80
|
-
|
|
80
|
+
// ...the plugin's other entries, such as its actions
|
|
81
81
|
fields: { steps: { of: ['enum'], display: StepsDisplay, editor: StepsEditor } },
|
|
82
82
|
})
|
|
83
83
|
```
|
|
@@ -143,7 +143,7 @@ export const salesOverview = page(
|
|
|
143
143
|
)
|
|
144
144
|
```
|
|
145
145
|
|
|
146
|
-
`{ plugin: 'sales-tools' }` tells `protobase build` that the project's own `protobase.ui.tsx` does not have the component, so it does not fail on it. Start the app with `bun run protobase dev` and sign in: the start page shows the card with the five newest drafts, and `sales-tools 1.0.0` under them. `/api/meta` named the plugin, the app read its `plugin.json`, saw that it fits, and loaded its module and stylesheet.
|
|
146
|
+
`{ plugin: 'sales-tools' }` tells `protobase build` that the project's own `protobase.ui.tsx` does not have the component, so it does not fail on it. The ERP exports the page from `config/index.ts` already (`export { salesOverview } from './overview/page'`); in another app, add that export, since Protobase finds pages there. Start the app with `bun run protobase dev` and sign in: the start page shows the card with the five newest drafts, and `sales-tools 1.0.0` under them. `/api/meta` named the plugin, the app read its `plugin.json`, saw that it fits, and loaded its module and stylesheet.
|
|
147
147
|
|
|
148
148
|
## 6. Change the plugin, not the app
|
|
149
149
|
|