@protobase/cli 0.46.15 → 0.47.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build/config-bundle.js +2 -2
- package/dist/build/plugin-build.js +2 -2
- package/dist/build/serve-runtime.js +1 -1
- package/dist/build/shell.js +2 -2
- package/dist/cli/package.js +1 -1
- package/dist/dev/api-child.js +49 -0
- package/dist/dev/api-forward.js +70 -0
- package/dist/dev/api-process.d.ts +18 -0
- package/dist/dev/api-process.js +77 -0
- package/dist/dev/api-support.d.ts +3 -0
- package/dist/dev/api-support.js +3 -0
- package/dist/dev/api-vite.d.ts +9 -0
- package/dist/dev/api-vite.js +33 -0
- package/dist/dev/api-websockets.js +1 -23
- package/dist/dev/app-server.js +70 -0
- package/dist/dev/dev-jobs.d.ts +6 -0
- package/dist/dev/run.js +34 -93
- package/dist/dev/server-package.js +39 -0
- package/dist/encryption/register.js +7 -6
- package/dist/files/register.js +5 -2
- package/dist/main.js +8 -5
- package/dist/migration/register.js +4 -4
- package/dist/mobile/register.js +3 -4
- package/dist/notifications/print-vapid-keys.js +1 -1
- package/dist/organizations/register.js +6 -1
- package/dist/project/api-websocket-server.d.ts +9 -0
- package/dist/project/extensions.d.ts +8 -0
- package/dist/project/favicon-link.js +1 -1
- package/dist/serve/lifecycle.js +1 -1
- package/dist/skill/register.js +1 -1
- package/dist/users/register.js +4 -3
- package/dist/users/set-disabled.js +1 -1
- package/dist/version/project-version.js +10 -7
- package/package.json +7 -7
- package/skills/protobase/references/getting-started.md +1 -1
- package/skills/protobase/references/reference/architecture.md +1 -1
- package/skills/protobase/references/reference/cli.md +4 -2
- package/skills/protobase/references/reference/versioning.md +3 -3
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { extensionImports } from "../project/extensions.js";
|
|
2
1
|
import { findPackageDir, packageName } from "./packages/package-dir.js";
|
|
2
|
+
import { layoutCheck } from "./layout-check.js";
|
|
3
|
+
import { extensionImports } from "../project/extensions.js";
|
|
3
4
|
import { viteBundle } from "./vite-bundle.js";
|
|
4
5
|
import { hostModuleIds } from "../serve/host-module-ids.js";
|
|
5
6
|
import { collectComponents } from "./component-names.js";
|
|
6
7
|
import { bundleEntryCode } from "./entry-code.js";
|
|
7
|
-
import { layoutCheck } from "./layout-check.js";
|
|
8
8
|
import { hostPackages } from "./packages/host-packages.js";
|
|
9
9
|
import { isNativePackage } from "./packages/native-package.js";
|
|
10
10
|
import path from "node:path";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { findPackageDirSync, readPackageJson } from "./packages/package-dir.js";
|
|
1
2
|
import { uiPackageDir } from "../project/admin-app.js";
|
|
2
3
|
import { extensionImports } from "../project/extensions.js";
|
|
3
|
-
import { findPackageDirSync, readPackageJson } from "./packages/package-dir.js";
|
|
4
4
|
import { sharedModules } from "../project/shared-modules.js";
|
|
5
5
|
import { pluginFieldTypes } from "./plugin-fields.js";
|
|
6
6
|
import { layerPluginUtilities } from "./plugin-styles.js";
|
|
@@ -9,9 +9,9 @@ import { existsSync } from "node:fs";
|
|
|
9
9
|
import path from "node:path";
|
|
10
10
|
import { writeFile } from "node:fs/promises";
|
|
11
11
|
import { inRange } from "@protobase/schema/internal";
|
|
12
|
+
import { build } from "vite";
|
|
12
13
|
import tailwindcss from "@tailwindcss/vite";
|
|
13
14
|
import react from "@vitejs/plugin-react";
|
|
14
|
-
import { build } from "vite";
|
|
15
15
|
//#region src/build/plugin-build.ts
|
|
16
16
|
/** The module a plugin's components and action handlers are exported from, as a project's are. */
|
|
17
17
|
const pluginEntryFile = "protobase.ui.tsx";
|
package/dist/build/shell.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { adminAppDir, uiEntry, uiPackageDir } from "../project/admin-app.js";
|
|
2
1
|
import { readPackageJson } from "./packages/package-dir.js";
|
|
2
|
+
import { adminAppDir, uiEntry, uiPackageDir } from "../project/admin-app.js";
|
|
3
3
|
import { projectUiPlugin } from "../project/project-ui.js";
|
|
4
4
|
import { sharedModulesPlugin } from "../project/shared-modules.js";
|
|
5
5
|
import { faviconLink } from "../project/favicon-link.js";
|
|
@@ -11,9 +11,9 @@ import { shellCodeSplitting } from "./shell-chunks.js";
|
|
|
11
11
|
import { existsSync } from "node:fs";
|
|
12
12
|
import path from "node:path";
|
|
13
13
|
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
14
|
+
import { build } from "vite";
|
|
14
15
|
import tailwindcss from "@tailwindcss/vite";
|
|
15
16
|
import react from "@vitejs/plugin-react";
|
|
16
|
-
import { build } from "vite";
|
|
17
17
|
import { tmpdir } from "node:os";
|
|
18
18
|
//#region src/build/shell.ts
|
|
19
19
|
/** What a shell folder holds beside its files: the `BundleShell` a bundle's manifest copies. */
|
package/dist/cli/package.js
CHANGED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { moduleFile } from "../module-file.js";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fork } from "node:child_process";
|
|
4
|
+
//#region src/dev/api-child.ts
|
|
5
|
+
const apiProcess = moduleFile("./api-process", import.meta.url);
|
|
6
|
+
const loaderArgs = () => path.extname(apiProcess) === ".ts" && !process.versions.bun ? ["--import", import.meta.resolve("tsx")] : [];
|
|
7
|
+
/**
|
|
8
|
+
* Forks the API of `protobase dev` into a process of its own, on the same runtime and with the same environment, which
|
|
9
|
+
* loads @protobase/server meanwhile. `start` has it load the API for the dev server at `devUrl` and resolves once it
|
|
10
|
+
* listens, or rejects with the error that stopped it loading; `stop` lets its running jobs finish and ends it. `onExit`
|
|
11
|
+
* hears of an API process that ends while it serves, other than through `stop`.
|
|
12
|
+
*/
|
|
13
|
+
const forkApiChild = (options, onExit) => {
|
|
14
|
+
const child = fork(apiProcess, [JSON.stringify(options)], { execArgv: [...process.execArgv, ...loaderArgs()] });
|
|
15
|
+
let stopping = false;
|
|
16
|
+
let ready = false;
|
|
17
|
+
const exited = new Promise((resolve) => child.once("exit", () => resolve()));
|
|
18
|
+
const outcome = new Promise((resolve) => {
|
|
19
|
+
child.once("message", resolve);
|
|
20
|
+
child.once("exit", (code, signal) => resolve({ failed: `The API process of protobase dev ended (${signal ?? `exit code ${code}`}) before it was ready` }));
|
|
21
|
+
});
|
|
22
|
+
child.once("exit", (code) => {
|
|
23
|
+
if (ready && !stopping) onExit(code ?? 1);
|
|
24
|
+
});
|
|
25
|
+
const stop = async () => {
|
|
26
|
+
stopping = true;
|
|
27
|
+
if (child.exitCode === null && child.signalCode === null) child.kill("SIGTERM");
|
|
28
|
+
await exited;
|
|
29
|
+
};
|
|
30
|
+
const start = async (devUrl) => {
|
|
31
|
+
if (child.connected) child.send({ start: { devUrl } });
|
|
32
|
+
const message = await outcome;
|
|
33
|
+
if ("failed" in message) {
|
|
34
|
+
await stop();
|
|
35
|
+
throw new Error(message.failed);
|
|
36
|
+
}
|
|
37
|
+
ready = true;
|
|
38
|
+
return {
|
|
39
|
+
port: message.ready.port,
|
|
40
|
+
anyUsers: message.ready.anyUsers
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
return {
|
|
44
|
+
start,
|
|
45
|
+
stop
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
//#endregion
|
|
49
|
+
export { forkApiChild };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { devHost } from "./loopback.js";
|
|
2
|
+
import { apiUpgrades } from "./api-websockets.js";
|
|
3
|
+
import { pipeline } from "node:stream";
|
|
4
|
+
import { connect } from "node:net";
|
|
5
|
+
import { request } from "node:http";
|
|
6
|
+
//#region src/dev/api-forward.ts
|
|
7
|
+
/**
|
|
8
|
+
* The requests the API process answers: everything under /api, the passkey origins at /.well-known/webauthn, the OAuth
|
|
9
|
+
* discovery documents MCP clients read (`oauthWellKnownPaths`), below which a resource's own one is, and the push worker
|
|
10
|
+
* (`withDevServiceWorker`). Vite serves the rest.
|
|
11
|
+
*/
|
|
12
|
+
const isApiRequest = (url) => /^(\/api(\/|\?|$)|\/\.well-known\/webauthn(\?|$)|\/\.well-known\/oauth-(authorization-server|protected-resource)(\/|\?|$)|\/protobase\.sw\.js(\?|$))/.test(url);
|
|
13
|
+
const hopByHop = /* @__PURE__ */ new Set([
|
|
14
|
+
"connection",
|
|
15
|
+
"keep-alive",
|
|
16
|
+
"transfer-encoding"
|
|
17
|
+
]);
|
|
18
|
+
const forwardRequest = (port, request$1, response, next) => {
|
|
19
|
+
let answered = false;
|
|
20
|
+
let left = false;
|
|
21
|
+
const upstream = request({
|
|
22
|
+
host: devHost,
|
|
23
|
+
port,
|
|
24
|
+
method: request$1.method,
|
|
25
|
+
path: request$1.url,
|
|
26
|
+
headers: request$1.headers,
|
|
27
|
+
agent: false
|
|
28
|
+
}, (answer) => {
|
|
29
|
+
answered = true;
|
|
30
|
+
const headers = Object.fromEntries(Object.entries(answer.headers).filter(([name]) => !hopByHop.has(name)));
|
|
31
|
+
response.writeHead(answer.statusCode, answer.statusMessage, headers);
|
|
32
|
+
pipeline(answer, response, () => void 0);
|
|
33
|
+
});
|
|
34
|
+
response.on("close", () => {
|
|
35
|
+
left = true;
|
|
36
|
+
upstream.destroy();
|
|
37
|
+
});
|
|
38
|
+
upstream.on("error", (error) => {
|
|
39
|
+
if (!answered && !left) next(error);
|
|
40
|
+
});
|
|
41
|
+
request$1.pipe(upstream);
|
|
42
|
+
};
|
|
43
|
+
const forwardUpgrade = (port, request, socket, head) => {
|
|
44
|
+
const upstream = connect(port, devHost, () => {
|
|
45
|
+
const lines = [`${request.method} ${request.url} HTTP/${request.httpVersion}`];
|
|
46
|
+
for (let i = 0; i < request.rawHeaders.length; i += 2) lines.push(`${request.rawHeaders[i]}: ${request.rawHeaders[i + 1]}`);
|
|
47
|
+
upstream.write(`${lines.join("\r\n")}\r\n\r\n`);
|
|
48
|
+
if (head.length > 0) upstream.write(head);
|
|
49
|
+
socket.pipe(upstream).pipe(socket);
|
|
50
|
+
});
|
|
51
|
+
upstream.on("error", () => socket.destroy());
|
|
52
|
+
socket.on("error", () => upstream.destroy());
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Hands the API's requests and WebSockets to the API process on `port` once it is ready, after Vite's host check and
|
|
56
|
+
* CORS as before; a request that comes while it starts waits for it.
|
|
57
|
+
*/
|
|
58
|
+
const apiForward = (port) => ({
|
|
59
|
+
name: "protobase-api-forward",
|
|
60
|
+
configureServer: (server) => {
|
|
61
|
+
server.middlewares.use((request, response, next) => {
|
|
62
|
+
if (!isApiRequest(request.url ?? "")) return next();
|
|
63
|
+
port().then((ready) => forwardRequest(ready, request, response, next), next);
|
|
64
|
+
});
|
|
65
|
+
const upgrade = (request, socket, head) => port().then((ready) => forwardUpgrade(ready, request, socket, head), () => socket.destroy());
|
|
66
|
+
server.httpServer?.on("upgrade", apiUpgrades(() => server.config.server.allowedHosts, (request, socket, head) => void upgrade(request, socket, head)));
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
//#endregion
|
|
70
|
+
export { apiForward, isApiRequest };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ApiViteOptions } from "./api-vite.js";
|
|
2
|
+
//#region src/dev/api-process.d.ts
|
|
3
|
+
export type ApiProcessOptions = ApiViteOptions;
|
|
4
|
+
export type ApiProcessMessage = {
|
|
5
|
+
ready: {
|
|
6
|
+
port: number;
|
|
7
|
+
anyUsers?: boolean;
|
|
8
|
+
};
|
|
9
|
+
} | {
|
|
10
|
+
failed: string;
|
|
11
|
+
};
|
|
12
|
+
/** What run.ts sends once its server listens: the app's origin, whose /api/sb functions call as SUPABASE_URL. */
|
|
13
|
+
export type ApiProcessStart = {
|
|
14
|
+
start: {
|
|
15
|
+
devUrl: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
//#endregion
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { errorMessage } from "../error-message.js";
|
|
2
|
+
import { moduleFile } from "../module-file.js";
|
|
3
|
+
import { createApiVite } from "./api-vite.js";
|
|
4
|
+
import { devHost } from "./loopback.js";
|
|
5
|
+
import { isProjectFile } from "./project-files.js";
|
|
6
|
+
import { serverPackage } from "./server-package.js";
|
|
7
|
+
import { startupLogger } from "./startup-logger.js";
|
|
8
|
+
import { createAdaptorServer } from "@hono/node-server";
|
|
9
|
+
//#region src/dev/api-process.ts
|
|
10
|
+
const entry = moduleFile("./entry", import.meta.url);
|
|
11
|
+
const support = moduleFile("./api-support", import.meta.url);
|
|
12
|
+
const restartCode = 1012;
|
|
13
|
+
const options = JSON.parse(process.argv[2]);
|
|
14
|
+
const projectDirs = [options.projectDir, ...options.extensions.map((extension) => extension.dir)];
|
|
15
|
+
const logging = startupLogger();
|
|
16
|
+
let sockets;
|
|
17
|
+
let server;
|
|
18
|
+
const devUrl = new Promise((resolve) => process.once("message", (message) => resolve(message.start.devUrl)));
|
|
19
|
+
const vite = await createApiVite(options, serverPackage(options.projectDir), logging.logger);
|
|
20
|
+
vite.watcher.add(projectDirs);
|
|
21
|
+
vite.watcher.on("all", (_event, file) => {
|
|
22
|
+
if (!isProjectFile(projectDirs, file)) return;
|
|
23
|
+
vite.environments.ssr.moduleGraph.invalidateAll();
|
|
24
|
+
sockets?.clients.forEach((client) => client.close(restartCode));
|
|
25
|
+
});
|
|
26
|
+
const internalError = (error) => {
|
|
27
|
+
vite.ssrFixStacktrace(error);
|
|
28
|
+
vite.config.logger.error(`Internal server error: ${error.message}\n${error.stack ?? ""}`, { error });
|
|
29
|
+
return new Response(`Internal server error: ${error.message}\n`, {
|
|
30
|
+
status: 500,
|
|
31
|
+
headers: { "content-type": "text/plain; charset=utf-8" }
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
const fetch = async (request, env) => {
|
|
35
|
+
const api = await vite.ssrLoadModule(entry).catch((error) => error);
|
|
36
|
+
if (api instanceof Error) return internalError(api);
|
|
37
|
+
return api.default.fetch(request, env);
|
|
38
|
+
};
|
|
39
|
+
const listen = (server) => new Promise((resolve, reject) => {
|
|
40
|
+
server.once("error", reject);
|
|
41
|
+
server.listen(0, devHost, () => {
|
|
42
|
+
server.off("error", reject);
|
|
43
|
+
resolve(server.address().port);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
const stop = async () => {
|
|
47
|
+
server?.close();
|
|
48
|
+
server?.closeAllConnections();
|
|
49
|
+
await (await vite.ssrLoadModule(support)).stopDevJobs();
|
|
50
|
+
await vite.close();
|
|
51
|
+
process.exit(process.exitCode ?? 0);
|
|
52
|
+
};
|
|
53
|
+
const start = async () => {
|
|
54
|
+
sockets = (await vite.ssrLoadModule(support)).apiWebSocketServer();
|
|
55
|
+
process.env.PROTOBASE_DEV_URL = await devUrl;
|
|
56
|
+
const anyUsers = await (await vite.ssrLoadModule(entry)).anyUsers();
|
|
57
|
+
logging.started();
|
|
58
|
+
server = createAdaptorServer({
|
|
59
|
+
fetch,
|
|
60
|
+
overrideGlobalObjects: false,
|
|
61
|
+
websocket: { server: sockets }
|
|
62
|
+
});
|
|
63
|
+
const port = await listen(server);
|
|
64
|
+
process.send({ ready: {
|
|
65
|
+
port,
|
|
66
|
+
anyUsers
|
|
67
|
+
} });
|
|
68
|
+
};
|
|
69
|
+
process.on("SIGINT", () => void 0);
|
|
70
|
+
process.on("SIGTERM", () => void stop());
|
|
71
|
+
process.on("disconnect", () => void stop());
|
|
72
|
+
await start().catch((error) => {
|
|
73
|
+
process.exitCode = 1;
|
|
74
|
+
process.send({ failed: errorMessage(error) });
|
|
75
|
+
});
|
|
76
|
+
//#endregion
|
|
77
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { layoutCheck } from "../build/layout-check.js";
|
|
2
|
+
import { extensionImports } from "../project/extensions.js";
|
|
3
|
+
import { createServer } from "vite";
|
|
4
|
+
//#region src/dev/api-vite.ts
|
|
5
|
+
/**
|
|
6
|
+
* The Vite server the API process loads the API through: no page, no HMR socket and no dependency optimisation; the
|
|
7
|
+
* project's server-side files transformed as the dev server's page transforms them, and the `dedupe` packages of
|
|
8
|
+
* `resolution`, @protobase/server among them, resolved from its root for every importer, the CLI's files included.
|
|
9
|
+
*/
|
|
10
|
+
const createApiVite = (options, resolution, logger) => createServer({
|
|
11
|
+
root: resolution.root,
|
|
12
|
+
configFile: false,
|
|
13
|
+
...logger && { customLogger: logger },
|
|
14
|
+
...options.cacheDir && { cacheDir: options.cacheDir },
|
|
15
|
+
appType: "custom",
|
|
16
|
+
server: {
|
|
17
|
+
middlewareMode: true,
|
|
18
|
+
hmr: false,
|
|
19
|
+
ws: false
|
|
20
|
+
},
|
|
21
|
+
optimizeDeps: {
|
|
22
|
+
noDiscovery: true,
|
|
23
|
+
include: []
|
|
24
|
+
},
|
|
25
|
+
resolve: { dedupe: resolution.dedupe },
|
|
26
|
+
oxc: { jsx: {
|
|
27
|
+
runtime: "automatic",
|
|
28
|
+
importSource: "react"
|
|
29
|
+
} },
|
|
30
|
+
plugins: [extensionImports(options.projectDir, options.extensions), layoutCheck()]
|
|
31
|
+
});
|
|
32
|
+
//#endregion
|
|
33
|
+
export { createApiVite };
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import { apiWebSocketServer } from "../project/api-websocket-server.js";
|
|
2
1
|
import { isAllowedHost } from "./allowed-host.js";
|
|
3
|
-
import { isProjectFile } from "./project-files.js";
|
|
4
|
-
import { createAdaptorServer } from "@hono/node-server";
|
|
5
2
|
//#region src/dev/api-websockets.ts
|
|
6
3
|
const isApiWebSocket = (url) => /^\/api\/sb\/realtime\/v1\/websocket(\?|$)/.test(url) || /^\/api\/functions\/[^/?#]+(\/|\?|$)/.test(url);
|
|
7
|
-
const restartCode = 1012;
|
|
8
4
|
/**
|
|
9
5
|
* The listener for Vite's `upgrade` event: an API socket goes to `forward` once its Host passes Vite's host check, as
|
|
10
6
|
* every other dev request does, and is refused with 403 otherwise; any other upgrade is left to Vite.
|
|
@@ -14,23 +10,5 @@ const apiUpgrades = (allowedHosts, forward) => (request, socket, head) => {
|
|
|
14
10
|
if (isAllowedHost(request.headers.host, allowedHosts())) return forward(request, socket, head);
|
|
15
11
|
socket.end("HTTP/1.1 403 Forbidden\r\nConnection: close\r\nContent-Length: 0\r\n\r\n");
|
|
16
12
|
};
|
|
17
|
-
const apiWebSockets = (entry, dirs) => {
|
|
18
|
-
const wss = apiWebSocketServer();
|
|
19
|
-
return {
|
|
20
|
-
name: "protobase-api-websockets",
|
|
21
|
-
configureServer: (server) => {
|
|
22
|
-
const upgrades = createAdaptorServer({
|
|
23
|
-
fetch: async (request, env) => (await server.ssrLoadModule(entry)).default.fetch(request, env),
|
|
24
|
-
overrideGlobalObjects: false,
|
|
25
|
-
websocket: { server: wss }
|
|
26
|
-
});
|
|
27
|
-
server.httpServer?.on("upgrade", apiUpgrades(() => server.config.server.allowedHosts, (request, socket, head) => upgrades.emit("upgrade", request, socket, head)));
|
|
28
|
-
server.httpServer?.on("close", () => upgrades.emit("close"));
|
|
29
|
-
},
|
|
30
|
-
handleHotUpdate: ({ file }) => {
|
|
31
|
-
if (isProjectFile(dirs, file)) wss.clients.forEach((client) => client.close(restartCode));
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
13
|
//#endregion
|
|
36
|
-
export { apiUpgrades,
|
|
14
|
+
export { apiUpgrades, isApiWebSocket };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { uiPackageDir } from "../project/admin-app.js";
|
|
2
|
+
import { layoutCheck } from "../build/layout-check.js";
|
|
3
|
+
import { extensionImports, extensionStyles } from "../project/extensions.js";
|
|
4
|
+
import { devHost } from "./loopback.js";
|
|
5
|
+
import { frameHeaders } from "../serve/static-site.js";
|
|
6
|
+
import { projectUiPlugin } from "../project/project-ui.js";
|
|
7
|
+
import { sharedModulesPlugin } from "../project/shared-modules.js";
|
|
8
|
+
import { faviconLink } from "../project/favicon-link.js";
|
|
9
|
+
import { themeLink } from "../project/theme-link.js";
|
|
10
|
+
import { createServer, searchForWorkspaceRoot } from "vite";
|
|
11
|
+
import tailwindcss from "@tailwindcss/vite";
|
|
12
|
+
import react from "@vitejs/plugin-react";
|
|
13
|
+
//#region src/dev/app-server.ts
|
|
14
|
+
const appDependencies = [
|
|
15
|
+
"react",
|
|
16
|
+
"react/jsx-runtime",
|
|
17
|
+
"react/jsx-dev-runtime",
|
|
18
|
+
"react-dom",
|
|
19
|
+
"react-dom/client",
|
|
20
|
+
"lucide-react",
|
|
21
|
+
"zod",
|
|
22
|
+
"@tanstack/react-query",
|
|
23
|
+
"@tanstack/react-table",
|
|
24
|
+
"recharts",
|
|
25
|
+
"@sentry/browser",
|
|
26
|
+
"maplibre-gl",
|
|
27
|
+
"pmtiles",
|
|
28
|
+
"fflate",
|
|
29
|
+
"react-map-gl/maplibre"
|
|
30
|
+
];
|
|
31
|
+
/**
|
|
32
|
+
* The Vite server of `protobase dev` that serves the admin app from `appDir`, with the project's UI, theme and icons,
|
|
33
|
+
* on `port`; `plugins` come first, such as the one that hands the API's requests to its process.
|
|
34
|
+
*/
|
|
35
|
+
const createAppServer = (options, plugins) => createServer({
|
|
36
|
+
root: options.appDir,
|
|
37
|
+
configFile: false,
|
|
38
|
+
...options.cacheDir && { cacheDir: options.cacheDir },
|
|
39
|
+
optimizeDeps: {
|
|
40
|
+
include: appDependencies,
|
|
41
|
+
exclude: ["@protobase/ui"]
|
|
42
|
+
},
|
|
43
|
+
server: {
|
|
44
|
+
headers: frameHeaders,
|
|
45
|
+
host: devHost,
|
|
46
|
+
port: options.port,
|
|
47
|
+
strictPort: true,
|
|
48
|
+
...options.allowedHosts.length > 0 && { allowedHosts: options.allowedHosts },
|
|
49
|
+
fs: { allow: [
|
|
50
|
+
searchForWorkspaceRoot(options.projectDir),
|
|
51
|
+
uiPackageDir,
|
|
52
|
+
options.projectDir,
|
|
53
|
+
...options.extensions.map((extension) => extension.dir)
|
|
54
|
+
] }
|
|
55
|
+
},
|
|
56
|
+
plugins: [
|
|
57
|
+
...plugins,
|
|
58
|
+
sharedModulesPlugin(),
|
|
59
|
+
themeLink(options.projectDir),
|
|
60
|
+
faviconLink(options.projectDir),
|
|
61
|
+
projectUiPlugin(options.projectDir, options.extensions),
|
|
62
|
+
extensionImports(options.projectDir, options.extensions),
|
|
63
|
+
extensionStyles(options.extensions),
|
|
64
|
+
layoutCheck(),
|
|
65
|
+
react(),
|
|
66
|
+
tailwindcss()
|
|
67
|
+
]
|
|
68
|
+
});
|
|
69
|
+
//#endregion
|
|
70
|
+
export { createAppServer };
|
package/dist/dev/run.js
CHANGED
|
@@ -1,59 +1,17 @@
|
|
|
1
1
|
import { loadNearestEnvFile } from "./env.js";
|
|
2
|
-
import { adminAppDir, adminAppMain
|
|
3
|
-
import {
|
|
4
|
-
import { stopDevJobs } from "./dev-jobs.js";
|
|
5
|
-
import { frameHeaders } from "../serve/static-site.js";
|
|
6
|
-
import { projectUiPlugin } from "../project/project-ui.js";
|
|
7
|
-
import { sharedModulesPlugin } from "../project/shared-modules.js";
|
|
8
|
-
import { moduleFile } from "../module-file.js";
|
|
9
|
-
import { layoutCheck } from "../build/layout-check.js";
|
|
10
|
-
import { faviconLink } from "../project/favicon-link.js";
|
|
11
|
-
import { themeLink } from "../project/theme-link.js";
|
|
2
|
+
import { adminAppDir, adminAppMain } from "../project/admin-app.js";
|
|
3
|
+
import { alsoOnIpv6, checkPortFree } from "./loopback.js";
|
|
12
4
|
import { checkDatabase } from "./check-database.js";
|
|
13
|
-
import { alsoOnIpv6, checkPortFree, devHost } from "./loopback.js";
|
|
14
5
|
import { loginLine } from "./login-line.js";
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import { apiWebSockets } from "./api-websockets.js";
|
|
6
|
+
import { apiForward } from "./api-forward.js";
|
|
7
|
+
import { forkApiChild } from "./api-child.js";
|
|
18
8
|
import { existsSync } from "node:fs";
|
|
19
9
|
import path from "node:path";
|
|
20
|
-
import tailwindcss from "@tailwindcss/vite";
|
|
21
|
-
import react from "@vitejs/plugin-react";
|
|
22
|
-
import { createServer, searchForWorkspaceRoot } from "vite";
|
|
23
|
-
import devServer from "@hono/vite-dev-server";
|
|
24
10
|
//#region src/dev/run.ts
|
|
25
|
-
const entry = moduleFile("./entry", import.meta.url);
|
|
26
11
|
const requireAppFiles = (appDir) => {
|
|
27
12
|
const missing = ["index.html", adminAppMain].filter((file) => !existsSync(path.join(appDir, file)));
|
|
28
13
|
if (missing.length > 0) throw new Error(`The admin app is missing ${missing.join(", ")} in ${appDir}; \`protobase dev\` serves the app from there`);
|
|
29
14
|
};
|
|
30
|
-
const reloadOnProjectChange = (dirs) => ({
|
|
31
|
-
name: "protobase-project-reload",
|
|
32
|
-
handleHotUpdate: ({ file, server }) => {
|
|
33
|
-
if (isProjectFile(dirs, file)) server.environments.ssr.moduleGraph.invalidateAll();
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
const stopJobsOnClose = {
|
|
37
|
-
name: "protobase-jobs",
|
|
38
|
-
closeBundle: () => stopDevJobs()
|
|
39
|
-
};
|
|
40
|
-
const appDependencies = [
|
|
41
|
-
"react",
|
|
42
|
-
"react/jsx-runtime",
|
|
43
|
-
"react/jsx-dev-runtime",
|
|
44
|
-
"react-dom",
|
|
45
|
-
"react-dom/client",
|
|
46
|
-
"lucide-react",
|
|
47
|
-
"zod",
|
|
48
|
-
"@tanstack/react-query",
|
|
49
|
-
"@tanstack/react-table",
|
|
50
|
-
"recharts",
|
|
51
|
-
"@sentry/browser",
|
|
52
|
-
"maplibre-gl",
|
|
53
|
-
"pmtiles",
|
|
54
|
-
"fflate",
|
|
55
|
-
"react-map-gl/maplibre"
|
|
56
|
-
];
|
|
57
15
|
const runDev = async (options, out) => {
|
|
58
16
|
loadNearestEnvFile(options.projectDir);
|
|
59
17
|
const url = process.env[options.envVar];
|
|
@@ -63,64 +21,47 @@ const runDev = async (options, out) => {
|
|
|
63
21
|
await checkDatabase(url, options.projectDir);
|
|
64
22
|
if (options.port !== 0) await checkPortFree(options.port);
|
|
65
23
|
const extensions = options.extensions ?? [];
|
|
66
|
-
const projectDirs = [options.projectDir, ...extensions.map((extension) => extension.dir)];
|
|
67
24
|
process.env.PROTOBASE_PROJECT = options.projectDir;
|
|
68
25
|
process.env.PROTOBASE_EXTENSIONS = JSON.stringify(extensions);
|
|
69
26
|
process.env.PROTOBASE_DATABASE_URL = url;
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
host: devHost,
|
|
83
|
-
port: options.port,
|
|
84
|
-
strictPort: true,
|
|
85
|
-
...options.allowedHosts.length > 0 && { allowedHosts: options.allowedHosts },
|
|
86
|
-
fs: { allow: [
|
|
87
|
-
searchForWorkspaceRoot(options.projectDir),
|
|
88
|
-
uiPackageDir,
|
|
89
|
-
options.projectDir,
|
|
90
|
-
...extensions.map((extension) => extension.dir)
|
|
91
|
-
] }
|
|
92
|
-
},
|
|
93
|
-
plugins: [
|
|
94
|
-
reloadOnProjectChange(projectDirs),
|
|
95
|
-
apiWebSockets(entry, projectDirs),
|
|
96
|
-
stopJobsOnClose,
|
|
97
|
-
sharedModulesPlugin(),
|
|
98
|
-
themeLink(options.projectDir),
|
|
99
|
-
faviconLink(options.projectDir),
|
|
100
|
-
projectUiPlugin(options.projectDir, extensions),
|
|
101
|
-
extensionImports(options.projectDir, extensions),
|
|
102
|
-
extensionStyles(extensions),
|
|
103
|
-
layoutCheck(),
|
|
104
|
-
react(),
|
|
105
|
-
tailwindcss(),
|
|
106
|
-
devServer({
|
|
107
|
-
entry,
|
|
108
|
-
exclude: [/^(?!\/api(\/|\?|$)|\/\.well-known\/webauthn(\?|$)|\/\.well-known\/oauth-(authorization-server|protected-resource)(\/|\?|$)|\/protobase\.sw\.js(\?|$)).*/],
|
|
109
|
-
injectClientScript: false
|
|
110
|
-
})
|
|
111
|
-
]
|
|
27
|
+
const onApiExit = (code) => {
|
|
28
|
+
process.stderr.write(`error: the API process of protobase dev ended with exit code ${code}\n`);
|
|
29
|
+
server.close().then(() => process.exit(code || 1));
|
|
30
|
+
};
|
|
31
|
+
const apiChild = forkApiChild({
|
|
32
|
+
projectDir: options.projectDir,
|
|
33
|
+
extensions,
|
|
34
|
+
...options.cacheDir && { cacheDir: path.join(options.cacheDir, "api") }
|
|
35
|
+
}, onApiExit);
|
|
36
|
+
let apiReady = () => void 0;
|
|
37
|
+
const api = new Promise((resolve) => {
|
|
38
|
+
apiReady = resolve;
|
|
112
39
|
});
|
|
40
|
+
const stopApiOnClose = {
|
|
41
|
+
name: "protobase-api-process",
|
|
42
|
+
closeBundle: () => apiChild.stop()
|
|
43
|
+
};
|
|
44
|
+
const stopApiAndThrow = async (error) => {
|
|
45
|
+
await apiChild.stop();
|
|
46
|
+
throw error;
|
|
47
|
+
};
|
|
48
|
+
const { createAppServer } = await import("./app-server.js");
|
|
49
|
+
const server = await createAppServer({
|
|
50
|
+
...options,
|
|
51
|
+
appDir,
|
|
52
|
+
extensions
|
|
53
|
+
}, [apiForward(() => api.then((child) => child.port)), stopApiOnClose]).catch(stopApiAndThrow);
|
|
113
54
|
const closeAndThrow = async (error) => {
|
|
114
55
|
await server.close();
|
|
115
56
|
throw error;
|
|
116
57
|
};
|
|
117
|
-
await server.listen();
|
|
58
|
+
await server.listen().catch(closeAndThrow);
|
|
118
59
|
const address = server.httpServer?.address();
|
|
119
60
|
const port = typeof address === "object" && address ? address.port : options.port;
|
|
120
61
|
if (server.httpServer) await alsoOnIpv6(server.httpServer, port).catch(closeAndThrow);
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
62
|
+
const started = await apiChild.start(`http://localhost:${port}`).catch(closeAndThrow);
|
|
63
|
+
apiReady(started);
|
|
64
|
+
const { anyUsers } = started;
|
|
124
65
|
out(`protobase dev ready at http://localhost:${port}\n project ${options.projectDir}\n api http://localhost:${port}/api/v1 (docs at /api/docs)\n` + loginLine(anyUsers, process.env.npm_config_user_agent));
|
|
125
66
|
return server;
|
|
126
67
|
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
//#region src/dev/server-package.ts
|
|
5
|
+
const server = "@protobase/server";
|
|
6
|
+
const framework = [
|
|
7
|
+
"@protobase/layout",
|
|
8
|
+
"@protobase/query",
|
|
9
|
+
"@protobase/schema",
|
|
10
|
+
server
|
|
11
|
+
];
|
|
12
|
+
const dependencyFields = [
|
|
13
|
+
"dependencies",
|
|
14
|
+
"devDependencies",
|
|
15
|
+
"optionalDependencies",
|
|
16
|
+
"peerDependencies"
|
|
17
|
+
];
|
|
18
|
+
const cliDir = fileURLToPath(new URL("../..", import.meta.url));
|
|
19
|
+
/**
|
|
20
|
+
* Where the API of `protobase dev` gets @protobase/server: from the project's node_modules when its package.json lists
|
|
21
|
+
* it, so a project that is not installed fails as any missing package does; otherwise, with no package.json or one
|
|
22
|
+
* without it, the CLI's own, with the CLI's other framework packages.
|
|
23
|
+
*/
|
|
24
|
+
const serverPackage = (projectDir, ownDir = cliDir) => {
|
|
25
|
+
const file = path.join(projectDir, "package.json");
|
|
26
|
+
const manifest = existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : {};
|
|
27
|
+
if (dependencyFields.some((field) => manifest[field]?.[server] !== void 0)) return {
|
|
28
|
+
from: "project",
|
|
29
|
+
root: projectDir,
|
|
30
|
+
dedupe: [server]
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
from: "cli",
|
|
34
|
+
root: ownDir,
|
|
35
|
+
dedupe: framework
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
//#endregion
|
|
39
|
+
export { serverPackage };
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { printStatus } from "./print-status.js";
|
|
2
|
-
import { printApply } from "./print-apply.js";
|
|
3
|
-
import { rebindOption } from "./rebind-option.js";
|
|
4
1
|
//#region src/encryption/register.ts
|
|
5
2
|
const out = (text) => void process.stdout.write(text);
|
|
6
3
|
const bundleArgument = ["[bundle]", "a bundle from `protobase build` (its folder or config module); default: the project in the current directory"];
|
|
@@ -20,10 +17,14 @@ const withTools = async (bundle, work) => {
|
|
|
20
17
|
};
|
|
21
18
|
const registerEncryption = (program) => {
|
|
22
19
|
const encryption = program.command("encryption").description("Check and update the stored values of encrypted fields");
|
|
23
|
-
encryption.command("status").description("Count each encrypted field's values by key, list plaintext and unreadable ones and old values left in history; exits 1 when any need work").argument(...bundleArgument).action(
|
|
24
|
-
|
|
20
|
+
encryption.command("status").description("Count each encrypted field's values by key, list plaintext and unreadable ones and old values left in history; exits 1 when any need work").argument(...bundleArgument).action(async (bundle) => {
|
|
21
|
+
const { printStatus } = await import("./print-status.js");
|
|
22
|
+
await withTools(bundle, async (tools) => printStatus(await tools.status(), out));
|
|
23
|
+
});
|
|
24
|
+
encryption.command("apply").description("Encrypt plaintext values, move values to the current key, rebind renamed ones and remove old values from history; exits 1 when unreadable values remain").argument(...bundleArgument).option("--rebind <resource[.field]>", "rebind the values of a resource, or one field, sealed before a rename").option("--from-table <table>", "the table, as .table() named it, the values were in before").option("--from-column <column>", "the column the field's values were in before").action(async (bundle, flags) => {
|
|
25
|
+
const [{ rebindOption }, { printApply }] = await Promise.all([import("./rebind-option.js"), import("./print-apply.js")]);
|
|
25
26
|
const rebind = rebindOption(flags);
|
|
26
|
-
|
|
27
|
+
await withTools(bundle, async (tools) => {
|
|
27
28
|
out(`Encrypting with key ${tools.kid}\n`);
|
|
28
29
|
return printApply(await tools.apply(rebind ? { rebind } : {}), out);
|
|
29
30
|
});
|
package/dist/files/register.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { cleanupCommand } from "./cleanup-command.js";
|
|
2
1
|
//#region src/files/register.ts
|
|
3
2
|
const out = (text) => process.stdout.write(text);
|
|
4
3
|
const registerFiles = (program) => {
|
|
5
4
|
program.command("files").description("Manage the stored files of the project in the current directory").command("cleanup").description("Delete the files whose scheduled delete is due and that no row references, such as replaced files and unused uploads").argument("[bundle]", "a bundle from `protobase build` (its folder or config module); default: the project in the current directory").action(async (bundle) => {
|
|
6
|
-
const [{ createFileCleanup }, { loadBundleProject }] = await Promise.all([
|
|
5
|
+
const [{ createFileCleanup }, { loadBundleProject }, { cleanupCommand }] = await Promise.all([
|
|
6
|
+
import("@protobase/server"),
|
|
7
|
+
import("../project/load-bundle-project.js"),
|
|
8
|
+
import("./cleanup-command.js")
|
|
9
|
+
]);
|
|
7
10
|
const project = await loadBundleProject(bundle, process.cwd());
|
|
8
11
|
try {
|
|
9
12
|
const cleanup = createFileCleanup(project);
|
package/dist/main.js
CHANGED
|
@@ -2,7 +2,6 @@ import { registerAuth } from "./auth/register.js";
|
|
|
2
2
|
import { isConnectionString, resolveConnectionUrl } from "./db/connection-url.js";
|
|
3
3
|
import { parseHosts } from "./dev/hosts.js";
|
|
4
4
|
import { loadNearestEnvFile } from "./dev/env.js";
|
|
5
|
-
import { resolveExtensions } from "./project/extensions.js";
|
|
6
5
|
import { placeholderSecretWarning } from "./project/placeholder-secret.js";
|
|
7
6
|
import { registerOrganizations } from "./organizations/register.js";
|
|
8
7
|
import { registerFiles } from "./files/register.js";
|
|
@@ -16,7 +15,7 @@ import { registerImport } from "./supabase/register.js";
|
|
|
16
15
|
import { registerToken, registerUsers } from "./users/register.js";
|
|
17
16
|
import { ExitSignal } from "./exit-signal.js";
|
|
18
17
|
import { errorMessage } from "./error-message.js";
|
|
19
|
-
import {
|
|
18
|
+
import { checkProjectVersion } from "./version/project-version.js";
|
|
20
19
|
import { statSync } from "node:fs";
|
|
21
20
|
import path from "node:path";
|
|
22
21
|
import { Command, InvalidArgumentError } from "commander";
|
|
@@ -30,7 +29,7 @@ const uiSection = (value) => {
|
|
|
30
29
|
};
|
|
31
30
|
const collectSection = (value, previous) => [...previous, uiSection(value)];
|
|
32
31
|
const program = new Command("protobase").description("Protobase command line").version(protobaseVersion, "-v, --version", "print the Protobase version");
|
|
33
|
-
program.hook("preAction", () =>
|
|
32
|
+
program.hook("preAction", () => checkProjectVersion(process.cwd()));
|
|
34
33
|
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) => {
|
|
35
34
|
loadNearestEnvFile(process.cwd());
|
|
36
35
|
const [first, ...rest] = args;
|
|
@@ -61,7 +60,7 @@ program.command("doctor").description("Check a config folder against the databas
|
|
|
61
60
|
if (errors > 0) process.exitCode = 1;
|
|
62
61
|
});
|
|
63
62
|
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) => {
|
|
64
|
-
const { runDev } = await import("./dev/run.js");
|
|
63
|
+
const [{ runDev }, { resolveExtensions }] = await Promise.all([import("./dev/run.js"), import("./project/extensions.js")]);
|
|
65
64
|
const server = await runDev({
|
|
66
65
|
extensions: resolveExtensions(opts.extend),
|
|
67
66
|
port: Number(opts.port),
|
|
@@ -75,9 +74,13 @@ program.command("dev").description("Serve the admin app and API for the project
|
|
|
75
74
|
process.once("SIGTERM", () => void server.close().then(() => process.exit(0)));
|
|
76
75
|
});
|
|
77
76
|
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) => {
|
|
77
|
+
const [{ buildDeployBundle }, { manifestFile }, { resolveExtensions }] = await Promise.all([
|
|
78
|
+
import("./build/deploy-bundle.js"),
|
|
79
|
+
import("./bundle/manifest.js"),
|
|
80
|
+
import("./project/extensions.js")
|
|
81
|
+
]);
|
|
78
82
|
const extensions = resolveExtensions(opts.extend);
|
|
79
83
|
const onWarning = (message) => process.stderr.write(`warning: ${message}\n`);
|
|
80
|
-
const [{ buildDeployBundle }, { manifestFile }] = await Promise.all([import("./build/deploy-bundle.js"), import("./bundle/manifest.js")]);
|
|
81
84
|
const manifest = await buildDeployBundle({
|
|
82
85
|
projectDir: process.cwd(),
|
|
83
86
|
outDir: path.resolve(opts.out),
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { resolveExtensions } from "../project/extensions.js";
|
|
2
|
-
import { migrationSummary } from "./summary.js";
|
|
3
1
|
import path from "node:path";
|
|
4
2
|
//#region src/migration/register.ts
|
|
5
3
|
const out = (text) => process.stdout.write(text);
|
|
6
4
|
const collect = (value, previous) => [...previous, value];
|
|
7
5
|
const registerMigration = (program) => {
|
|
8
6
|
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([
|
|
7
|
+
const [{ loadMigrationProject }, { migrationParts }, { writeMigrations }, { migrationSummary }, { resolveExtensions }] = await Promise.all([
|
|
10
8
|
import("./load-project.js"),
|
|
11
9
|
import("./parts.js"),
|
|
12
|
-
import("./write-migrations.js")
|
|
10
|
+
import("./write-migrations.js"),
|
|
11
|
+
import("./summary.js"),
|
|
12
|
+
import("../project/extensions.js")
|
|
13
13
|
]);
|
|
14
14
|
const project = await loadMigrationProject(process.cwd(), resolveExtensions(opts.extend));
|
|
15
15
|
try {
|
package/dist/mobile/register.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { resolveExtensions } from "../project/extensions.js";
|
|
2
1
|
import { parseAppVersion, parseBuildNumber, parsePlatform, parsePort, parseSigningName, parseTeamId } from "./arguments.js";
|
|
3
2
|
import path from "node:path";
|
|
4
3
|
//#region src/mobile/register.ts
|
|
@@ -10,7 +9,7 @@ const registerMobile = (program) => {
|
|
|
10
9
|
const apiHelp = "the server the app calls (default: the auth issuer, the project's baseURL)";
|
|
11
10
|
const extend = "merge the protobase.config.ts and protobase.ui.tsx in this folder before the project's, repeatable";
|
|
12
11
|
mobile.command("run").description("Generate the native project and run the app in a simulator, an emulator or on a device").argument("<platform>", "ios or android", parsePlatform).option(api, apiHelp).option("--target <id>", "the device or simulator to run on (default: Capacitor asks)").option("--team <id>", "iOS: your Apple Developer team id, which signs the app to run on your iPhone", parseTeamId).option("--live", "open the running protobase dev instead of the app's own files, reloading as you save", false).option("--port <port>", "the port of protobase dev, for --live", parsePort, 5173).option("--extend <dir>", extend, collect, []).action(async (chosen, opts) => {
|
|
13
|
-
const { mobileRun } = await import("./run.js");
|
|
12
|
+
const [{ mobileRun }, { resolveExtensions }] = await Promise.all([import("./run.js"), import("../project/extensions.js")]);
|
|
14
13
|
await mobileRun({
|
|
15
14
|
projectDir: process.cwd(),
|
|
16
15
|
platform: chosen,
|
|
@@ -22,7 +21,7 @@ const registerMobile = (program) => {
|
|
|
22
21
|
}, out);
|
|
23
22
|
});
|
|
24
23
|
mobile.command("open").description("Generate the native project and open it in Xcode or Android Studio").argument("<platform>", "ios or android", parsePlatform).option(api, apiHelp).option("--extend <dir>", extend, collect, []).action(async (chosen, opts) => {
|
|
25
|
-
const { mobileOpen } = await import("./run.js");
|
|
24
|
+
const [{ mobileOpen }, { resolveExtensions }] = await Promise.all([import("./run.js"), import("../project/extensions.js")]);
|
|
26
25
|
await mobileOpen({
|
|
27
26
|
projectDir: process.cwd(),
|
|
28
27
|
platform: chosen,
|
|
@@ -33,7 +32,7 @@ const registerMobile = (program) => {
|
|
|
33
32
|
mobile.command("build").description("Generate the native project and build a signed release: an .aab for Google Play, an .ipa for the App Store").argument("<platform>", "ios or android", parsePlatform).requiredOption("--app-version <version>", "the version the stores show, such as 1.2.3", parseAppVersion).requiredOption("--build-number <number>", "the build number, higher with each upload", parseBuildNumber).option(api, `${apiHelp}; https only`).option("--out <dir>", "the folder the binary goes to", "mobile-release").option("--team <id>", "iOS: your Apple Developer team id", parseTeamId).option("--certificate <name>", "iOS, manual signing: the signing certificate", parseSigningName).option("--profile <name>", "iOS, manual signing: the provisioning profile", parseSigningName).option("--extend <dir>", extend, collect, []).action(async (chosen, opts) => {
|
|
34
33
|
if (chosen === "android" && (opts.team || opts.certificate || opts.profile)) throw new Error("--team, --certificate and --profile are for iOS: Android signs with the PROTOBASE_ANDROID_* variables");
|
|
35
34
|
if (Boolean(opts.certificate) !== Boolean(opts.profile)) throw new Error("Manual signing takes both --certificate and --profile");
|
|
36
|
-
const { mobileBuild } = await import("./build.js");
|
|
35
|
+
const [{ mobileBuild }, { resolveExtensions }] = await Promise.all([import("./build.js"), import("../project/extensions.js")]);
|
|
37
36
|
const projectDir = process.cwd();
|
|
38
37
|
await mobileBuild({
|
|
39
38
|
projectDir,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { generateVapidKeys, vapidPrivateKeyVariable, vapidPublicKeyVariable, vapidSubjectVariable } from "@protobase/server";
|
|
1
|
+
import { generateVapidKeys, vapidPrivateKeyVariable, vapidPublicKeyVariable, vapidSubjectVariable } from "@protobase/server/vapid";
|
|
2
2
|
//#region src/notifications/print-vapid-keys.ts
|
|
3
3
|
/**
|
|
4
4
|
* Prints a fresh VAPID key pair as the two environment variables Web Push reads, and on `note` how to set the third.
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { addAppRoleCommand, addMemberCommand, createOrganizationCommand, listOrganizationsCommand, removeMemberCommand, setMemberRolesCommand } from "./commands.js";
|
|
2
1
|
//#region src/organizations/register.ts
|
|
3
2
|
const out = (text) => process.stdout.write(text);
|
|
4
3
|
const projectApi = async () => {
|
|
@@ -10,10 +9,12 @@ const memberOptions = (command) => command.argument("<organization>", "its slug
|
|
|
10
9
|
const registerOrganizations = (program) => {
|
|
11
10
|
const organizations = program.command("organizations").description("Manage the organizations of the project in the current directory (with `organizations` in createAuth)");
|
|
12
11
|
organizations.command("list").description("List organizations with their members and roles").action(async () => {
|
|
12
|
+
const { listOrganizationsCommand } = await import("./commands.js");
|
|
13
13
|
await listOrganizationsCommand(await projectApi(), out);
|
|
14
14
|
finish(0);
|
|
15
15
|
});
|
|
16
16
|
organizations.command("create").description("Create an organization; its owner holds every app role").argument("<name>").requiredOption("--owner <email>", "the user who owns it").option("--slug <slug>", "default: from the name").option("--id <id>", "keep an existing tenant value, for an app that ran as one organization").option("--members <all>", "\"all\": every other user joins; their global roles move here, superusers become owners").action(async (name, opts) => {
|
|
17
|
+
const { createOrganizationCommand } = await import("./commands.js");
|
|
17
18
|
await createOrganizationCommand(await projectApi(), {
|
|
18
19
|
name,
|
|
19
20
|
owner: opts.owner,
|
|
@@ -24,6 +25,7 @@ const registerOrganizations = (program) => {
|
|
|
24
25
|
finish(0);
|
|
25
26
|
});
|
|
26
27
|
memberOptions(organizations.command("add-member").description("Add a user to an organization (organization role member unless given)")).action(async (organization, email, opts) => {
|
|
28
|
+
const { addMemberCommand } = await import("./commands.js");
|
|
27
29
|
await addMemberCommand(await projectApi(), {
|
|
28
30
|
organization,
|
|
29
31
|
email,
|
|
@@ -33,6 +35,7 @@ const registerOrganizations = (program) => {
|
|
|
33
35
|
finish(0);
|
|
34
36
|
});
|
|
35
37
|
memberOptions(organizations.command("set-roles").description("Change a member's organization role, app roles, or both")).action(async (organization, email, opts) => {
|
|
38
|
+
const { setMemberRolesCommand } = await import("./commands.js");
|
|
36
39
|
await setMemberRolesCommand(await projectApi(), {
|
|
37
40
|
organization,
|
|
38
41
|
email,
|
|
@@ -42,6 +45,7 @@ const registerOrganizations = (program) => {
|
|
|
42
45
|
finish(0);
|
|
43
46
|
});
|
|
44
47
|
organizations.command("remove-member").description("Remove a member (refuses the last owner)").argument("<organization>", "its slug or id").argument("<email>").action(async (organization, email) => {
|
|
48
|
+
const { removeMemberCommand } = await import("./commands.js");
|
|
45
49
|
await removeMemberCommand(await projectApi(), {
|
|
46
50
|
organization,
|
|
47
51
|
email
|
|
@@ -49,6 +53,7 @@ const registerOrganizations = (program) => {
|
|
|
49
53
|
finish(0);
|
|
50
54
|
});
|
|
51
55
|
organizations.command("add-app-role").description("Give an app role to every owner of every organization, for a role added after they were made").argument("<role>").requiredOption("--to <owners>", "\"owners\"").action(async (role, opts) => {
|
|
56
|
+
const { addAppRoleCommand } = await import("./commands.js");
|
|
52
57
|
await addAppRoleCommand(await projectApi(), {
|
|
53
58
|
role,
|
|
54
59
|
to: opts.to
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { WebSocketServer } from "ws";
|
|
2
|
+
//#region src/project/api-websocket-server.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* The server of npm `ws` that upgrades the API's sockets, realtime's and the app's functions', on Node and Bun: a frame
|
|
5
|
+
* over its socket's cap (`maxPayloadOf`, or a function's lower `maxMessageBytes`) closes the socket with 1009 before it
|
|
6
|
+
* is read.
|
|
7
|
+
*/
|
|
8
|
+
export declare const apiWebSocketServer: () => WebSocketServer;
|
|
9
|
+
//#endregion
|
|
@@ -2,7 +2,7 @@ import { faviconFile, projectFavicon } from "../build/favicon.js";
|
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { readFile } from "node:fs/promises";
|
|
5
|
-
import { pngIcons } from "@protobase/
|
|
5
|
+
import { pngIcons } from "@protobase/schema/png-icons";
|
|
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
|
package/dist/serve/lifecycle.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { protobaseVersion } from "../version/version.js";
|
|
2
2
|
import { projectAdmin } from "../project/project-admin.js";
|
|
3
3
|
import { createPgDb } from "../project/pg-db.js";
|
|
4
|
-
import { withClientAddress } from "./client-address.js";
|
|
5
4
|
import { apiWebSocketServer } from "../project/api-websocket-server.js";
|
|
5
|
+
import { withClientAddress } from "./client-address.js";
|
|
6
6
|
import { createServeApp } from "./app.js";
|
|
7
7
|
import { startCleanupTimer } from "./cleanup-timer.js";
|
|
8
8
|
import { closeSockets } from "./close-sockets.js";
|
package/dist/skill/register.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { protobaseVersion } from "../version/version.js";
|
|
2
|
-
import { bundledSkills, installSkill } from "./install.js";
|
|
3
2
|
import { join } from "node:path";
|
|
4
3
|
import { fileURLToPath } from "node:url";
|
|
5
4
|
//#region src/skill/register.ts
|
|
6
5
|
const skillsDir = fileURLToPath(new URL("../../skills", import.meta.url));
|
|
7
6
|
function registerSkill(program) {
|
|
8
7
|
program.command("skill").description("the protobase agent skills").command("install [name]").description("copy the agent skills of this CLI's version, or only the one named, into the project's .agents/skills and .claude/skills").action(async (name) => {
|
|
8
|
+
const { bundledSkills, installSkill } = await import("./install.js");
|
|
9
9
|
const skills = await bundledSkills(skillsDir);
|
|
10
10
|
if (name && !skills.includes(name)) throw new Error(`no skill named ${name}; this CLI ships ${skills.join(", ")}`);
|
|
11
11
|
const projectDir = process.cwd();
|
package/dist/users/register.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { addMemberCommand } from "../organizations/commands.js";
|
|
2
|
-
import { deleteUserCommand, setRoleCommand } from "./manage.js";
|
|
3
1
|
import { parseTtl } from "./ttl.js";
|
|
4
2
|
import { Option } from "commander";
|
|
5
3
|
import { createInterface } from "node:readline/promises";
|
|
@@ -26,10 +24,11 @@ const registerUsers = (program) => {
|
|
|
26
24
|
users.command("create").description("Create a user; the first user is always an admin").argument("<email>").option("--name <name>", "display name").option("--role <role>", "role for users after the first (default: the project's default role; see `users roles`)").option("--password-stdin", "read the password from stdin", false).option("--generate-password", "generate a strong password and print it once", false).option("--no-password", "no password: the user signs in by emailed code, passkey or a sign-in provider").option("--github-id <id>", "link the user to this GitHub user id, so signing in with GitHub finds them whatever their address").option("--organization <organization>", "with organizations: add the user to this one (its slug or id)").option("--org-role <role>", "with --organization: owner, admin or member (default member)").option("--app-roles <roles>", "with --organization: app roles there, comma separated").addOption(new Option("--password <value>").hideHelp()).action(async (email, opts) => {
|
|
27
25
|
const { readHidden, rejectPasswordArgument } = await import("./password.js");
|
|
28
26
|
rejectPasswordArgument(opts.password);
|
|
29
|
-
const [{ createUserCommand }, { usersApi }, { organizationsApi }, auth] = await Promise.all([
|
|
27
|
+
const [{ createUserCommand }, { usersApi }, { organizationsApi }, { addMemberCommand }, auth] = await Promise.all([
|
|
30
28
|
import("./commands.js"),
|
|
31
29
|
import("./users-api.js"),
|
|
32
30
|
import("../organizations/api.js"),
|
|
31
|
+
import("../organizations/commands.js"),
|
|
33
32
|
loadAuth()
|
|
34
33
|
]);
|
|
35
34
|
await createUserCommand(usersApi(auth), {
|
|
@@ -53,6 +52,7 @@ const registerUsers = (program) => {
|
|
|
53
52
|
finish(0);
|
|
54
53
|
});
|
|
55
54
|
users.command("delete").description("Delete a user (refuses the last admin)").argument("<email>").option("--yes", "skip the confirmation", false).action(async (email, opts) => {
|
|
55
|
+
const { deleteUserCommand } = await import("./manage.js");
|
|
56
56
|
await deleteUserCommand(await projectApi(), {
|
|
57
57
|
email,
|
|
58
58
|
yes: opts.yes
|
|
@@ -60,6 +60,7 @@ const registerUsers = (program) => {
|
|
|
60
60
|
finish(0);
|
|
61
61
|
});
|
|
62
62
|
users.command("set-role").description("Change a user's role, or several comma separated (refuses to demote the last admin)").argument("<email>").argument("<role>").action(async (email, role) => {
|
|
63
|
+
const { setRoleCommand } = await import("./manage.js");
|
|
63
64
|
await setRoleCommand(await projectApi(), {
|
|
64
65
|
email,
|
|
65
66
|
role
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { setDisabledCommand } from "./manage.js";
|
|
2
1
|
import { usersApi } from "./users-api.js";
|
|
2
|
+
import { setDisabledCommand } from "./manage.js";
|
|
3
3
|
import { checkAuthSchema } from "@protobase/server";
|
|
4
4
|
//#region src/users/set-disabled.ts
|
|
5
5
|
const setDisabledInProject = async (auth, options, out) => {
|
|
@@ -2,6 +2,7 @@ import { protobaseVersion } from "./version.js";
|
|
|
2
2
|
import { findPackageDirSync } from "../build/packages/package-dir.js";
|
|
3
3
|
import { readFileSync } from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
|
+
import semver from "semver";
|
|
5
6
|
//#region src/version/project-version.ts
|
|
6
7
|
const projectPackages = [
|
|
7
8
|
"@protobase/cli",
|
|
@@ -18,15 +19,17 @@ const projectProtobaseVersion = (projectDir) => {
|
|
|
18
19
|
if (dir) return JSON.parse(readFileSync(path.join(dir, "package.json"), "utf8")).version;
|
|
19
20
|
}
|
|
20
21
|
};
|
|
21
|
-
const major = (version) => version.split(".")[0];
|
|
22
22
|
/**
|
|
23
|
-
* Refuses a project
|
|
24
|
-
* CLI
|
|
23
|
+
* Refuses a project whose Protobase version this CLI is not compatible with, the one version check the CLI makes: the
|
|
24
|
+
* CLI's version must be in the caret range of the project's, so from 1.0 on the same major and below 1.0, where a minor
|
|
25
|
+
* may break, the same minor, and never older. Outside a project, or before its install, there is nothing to check.
|
|
25
26
|
*/
|
|
26
|
-
const
|
|
27
|
+
const checkProjectVersion = (projectDir, cliVersion = protobaseVersion) => {
|
|
27
28
|
const project = projectProtobaseVersion(projectDir);
|
|
28
|
-
if (project === void 0
|
|
29
|
-
|
|
29
|
+
if (project === void 0) return;
|
|
30
|
+
const range = `^${project}`;
|
|
31
|
+
if (semver.satisfies(cliVersion, range)) return;
|
|
32
|
+
throw new Error(`This project is on Protobase ${project}, and this CLI is Protobase ${cliVersion}: run it with a Protobase ${range} CLI`);
|
|
30
33
|
};
|
|
31
34
|
//#endregion
|
|
32
|
-
export {
|
|
35
|
+
export { checkProjectVersion, projectProtobaseVersion };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.47.1",
|
|
4
4
|
"description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"type": "module",
|
|
13
13
|
"sideEffects": [
|
|
14
14
|
"./dist/dev/entry.js",
|
|
15
|
+
"./dist/dev/api-process.js",
|
|
15
16
|
"./dist/serve/main.js"
|
|
16
17
|
],
|
|
17
18
|
"engines": {
|
|
@@ -38,12 +39,11 @@
|
|
|
38
39
|
"dependencies": {
|
|
39
40
|
"@better-auth/core": "^1.7.12",
|
|
40
41
|
"@hono/node-server": "^2.1.3",
|
|
41
|
-
"@
|
|
42
|
-
"@protobase/
|
|
43
|
-
"@protobase/
|
|
44
|
-
"@protobase/
|
|
45
|
-
"@protobase/
|
|
46
|
-
"@protobase/ui": "0.46.15",
|
|
42
|
+
"@protobase/layout": "0.47.1",
|
|
43
|
+
"@protobase/query": "0.47.1",
|
|
44
|
+
"@protobase/schema": "0.47.1",
|
|
45
|
+
"@protobase/server": "0.47.1",
|
|
46
|
+
"@protobase/ui": "0.47.1",
|
|
47
47
|
"@react-email/render": "^2.1.0",
|
|
48
48
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
49
49
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -88,7 +88,7 @@ bun run --cwd examples/property-portal dev # http://localhost:5173
|
|
|
88
88
|
| `bun run test:watch` | `bun run test` in watch mode |
|
|
89
89
|
| `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
90
|
| `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 range of `<version>`
|
|
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 |
|
|
92
92
|
| `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
93
|
| `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
94
|
| `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` |
|
|
@@ -20,7 +20,7 @@ A Bun workspace of npm packages under the `@protobase` scope, in `packages/<name
|
|
|
20
20
|
| `@protobase/presets` | `packages/presets` | none: private, `bun run presets:write` writes a project per preset | Bun | none; each preset depends on the `@protobase` packages of the major it is written at, locked at that version |
|
|
21
21
|
| `examples/*` | | none | any | `@protobase/*` entry points only |
|
|
22
22
|
|
|
23
|
-
The presets are written from `examples/erp`, `examples/real-estate` and `examples/scratch` (from scratch) by `bun run presets:write <version> <dir>`, run from a clone of this repository; `npm create protobase` (`packages/create-protobase`) writes them too, without a lockfile. Each is a standalone copy with the `@protobase` packages in the range of `<version
|
|
23
|
+
The presets are written from `examples/erp`, `examples/real-estate` and `examples/scratch` (from scratch) by `bun run presets:write <version> <dir>`, run from a clone of this repository; `npm create protobase` (`packages/create-protobase`) writes them too, without a lockfile. Each is a standalone copy with the `@protobase` packages in the caret range of `<version>`, `^x.y.z`, so an app takes the updates semver calls compatible: within that major from 1.0 on, and within that minor below 1.0, where a minor may break, and its own `bun.lock` at exactly `<version>`. The three declare the same dependencies, so one `node_modules` fits them all, and their `db:migrate` (the auth schema's migrations included), `typecheck` and `test` scripts take their settings from the environment, or a `.env` beside them, and reach nothing outside the project.
|
|
24
24
|
|
|
25
25
|
The JSX runtime belongs to `@protobase/layout` because a layout file names one package in `@jsxImportSource @protobase/layout`, and TypeScript and Vite look up `jsx-runtime` and `jsx-dev-runtime` under it. Each field type is split along the same lines: its Zod builder is `packages/schema/src/fields/<type>.ts` and its SQL parameter conversion `packages/query/src/fields/<type>.ts`.
|
|
26
26
|
|
|
@@ -123,7 +123,9 @@ Exit code is 1 when there are errors. Run it after the project's migrations and
|
|
|
123
123
|
protobase dev [--port 5173] [--env DATABASE_URL] [--cache-dir <dir>] [--allowed-hosts <hosts>] [--extend <dir>] # run inside a project, e.g. bun run --cwd examples/erp dev
|
|
124
124
|
```
|
|
125
125
|
|
|
126
|
-
One
|
|
126
|
+
One port, two processes: Vite serves the admin app from `@protobase/ui`'s `src/app/` (`dist/app/` when installed; `index.html` and `main.tsx`, or `main.js`; the command fails with a clear message when they are missing) and hands `/api`, supabase-js's `/api/sb` included, to the Hono app from `createAdmin`, which runs in a process of its own; the CLI's process never loads `@protobase/server`. Open `http://localhost:<port>`; the API reference is at `/api/docs`.
|
|
127
|
+
|
|
128
|
+
- **Server package:** the API's process loads `@protobase/server` from the project's `node_modules` when its `package.json` lists it, in any of its dependency fields; a project that lists it without installing it fails as with any missing package. Without a `package.json`, or with one that does not list it, it uses the copy the CLI ships, with the CLI's `@protobase/schema`, `@protobase/query` and `@protobase/layout`.
|
|
127
129
|
|
|
128
130
|
- **Secret:** a `BETTER_AUTH_SECRET` still set to the placeholder of `.env.example` (`change-me-...`) prints a warning once the server is ready, as `serve` does at start: anyone who knows it can sign session cookies.
|
|
129
131
|
- **Database:** the URL comes from the variable named by `--env`, read from the environment or the nearest `.env` at or above the project. The connection is checked before anything starts; if it fails, the command names host, port and reason (and, when nothing listens there, points to its `db:up` script when it has one). The project needs `pg` installed, because the API connects with Kysely over the project's own `pg`.
|
|
@@ -131,7 +133,7 @@ One process, one port: Vite serves the admin app from `@protobase/ui`'s `src/app
|
|
|
131
133
|
- **Cache:** Vite's dependency cache is `node_modules/.vite`; two dev servers sharing it can disturb each other's optimisation, so pass `--cache-dir` for a second one (the integration test does).
|
|
132
134
|
- **Login:** real sign-in only, with the `authenticate` and `auth` exported by `protobase.config.ts` (see [Login with Better Auth](auth.md)). A project without an authenticator fails at startup with a message pointing there, one whose auth schema is behind with the tables and columns it lacks (see [`auth migration`](#auth-migration)), and one with a resource whose [events](events.md) or [history](history.md) lack their triggers, or whose [comments](comments.md) lack their table, or whose [rollup and formula fields](data-config.md#rollups-and-formulas) lack their columns or triggers, which it checks again on every reload (see [`migration`](#migration)), and one with an [AI field or action](ai.md#the-model) and no model key; there is no development login. The `login` line of the startup message says how to sign in: while the auth store has no users, it prints the exact command that creates the first admin, such as `bun run protobase users create you@example.com --generate-password` (the package manager that started `dev`, `npx` otherwise). Against a database that has users already, such as an app's hosted one, sign in as one of them or add one with a new email; its own password is set there.
|
|
133
135
|
- **Mobile releases:** see [below](#mobile-releases).
|
|
134
|
-
- **Jobs:** with [jobs](jobs.md) in the config it runs them in
|
|
136
|
+
- **Jobs:** with [jobs](jobs.md) in the config it runs them in the API's process, once the jobs schema checks out (see [`migration`](#migration)); an edited job runs its new code from the next job on.
|
|
135
137
|
- **Tunnels and other hosts:** Vite only answers `localhost` by default. `--allowed-hosts .trycloudflare.com,app.example.com` adds Host headers (a leading dot matches all subdomains). Hot reload needs no extra setting: the Vite client takes protocol, host and port from the page, so behind an HTTPS tunnel it connects over `wss` on 443 as long as the tunnel forwards WebSockets.
|
|
136
138
|
- **Project discovery**, by convention: `config/index.ts` exports the resources (and views), and every `config/*/ui.ts` export that is not already exported by the index is added as a view. Each `functions/<name>.ts` (or `functions/<name>/index.ts`) is an [API function](../guides/api-functions.md) at `/api/functions/<name>`. A `protobase.config.ts` in the project root replaces the convention; its default export may contain any of:
|
|
137
139
|
|
|
@@ -56,13 +56,13 @@ Running the workflow by hand with a tag (`gh workflow run release.yml -f tag=v0.
|
|
|
56
56
|
|
|
57
57
|
## Bundles and runtimes
|
|
58
58
|
|
|
59
|
-
The CLI makes one version check, when it starts:
|
|
59
|
+
The CLI makes one version check, when it starts: its own version must be in the caret range of the project's, the version of the `@protobase` packages installed in the current directory, which semver calls compatible with it. From 1.0 on that is the same major, and below 1.0, where a minor may break, the same minor, never older than the project's. A 0.14.2 CLI runs a 0.14.0 project and refuses a 0.15.0 or a 1.2.0 one before any command runs:
|
|
60
60
|
|
|
61
61
|
```
|
|
62
|
-
error: This project is on Protobase 1.2.0, and this CLI is Protobase 0.14.2: run it with a Protobase 1.
|
|
62
|
+
error: This project is on Protobase 1.2.0, and this CLI is Protobase 0.14.2: run it with a Protobase ^1.2.0 CLI
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
-
Within
|
|
65
|
+
Within its caret range the CLI stays backwards compatible, so a platform builds every app with the newest CLI in the caret range of the app's version. Nothing else compares versions: not the build, not the serve runtime. `protobase build` writes the version the project is pinned to, the `@protobase/cli` its lockfile installed, into [the manifest](cli.md#the-manifest) as `protobase`, whichever CLI built the bundle, and a host serves the bundle on the runtime of that version. The check is `checkProjectVersion` in `packages/cli/src/version/project-version.ts`.
|
|
66
66
|
|
|
67
67
|
## Plugins
|
|
68
68
|
|