@protobase/cli 0.8.2 → 0.9.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/dist/dev/entry.js +9 -20
- package/dist/migration/load-project.js +1 -0
- package/dist/migration/parts.js +8 -3
- package/dist/package.js +1 -1
- package/dist/project/project-admin.js +35 -0
- package/dist/serve/app.js +2 -20
- package/dist/serve/lifecycle.js +5 -4
- package/dist/worker/start-worker.js +14 -9
- package/package.json +6 -6
package/dist/dev/entry.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { devJobs } from "./dev-jobs.js";
|
|
2
|
+
import { projectAdmin } from "../project/project-admin.js";
|
|
2
3
|
import { loadProject, projectDb } from "./project.js";
|
|
3
|
-
import { checkAuthSchema, checkChanges,
|
|
4
|
+
import { checkAuthSchema, checkChanges, checkWebhooksSchema, configExports, hasUsers } from "@protobase/server";
|
|
4
5
|
import { Hono } from "hono";
|
|
5
6
|
//#region src/dev/entry.ts
|
|
6
7
|
const projectDir = process.env.PROTOBASE_PROJECT;
|
|
7
8
|
const project = await loadProject(projectDir, JSON.parse(process.env.PROTOBASE_EXTENSIONS ?? "[]"));
|
|
8
9
|
const db = projectDb(project, projectDir);
|
|
9
|
-
const { resources
|
|
10
|
+
const { resources } = configExports(project.exports);
|
|
10
11
|
if (!project.authenticate) throw new Error("No authenticator: export `authenticate` (and `auth`) from protobase.config.ts; see https://docs.protobase.net/reference/auth/");
|
|
11
12
|
const store = globalThis;
|
|
12
13
|
if (project.auth && !store.__protobaseAuthSchemaChecked) {
|
|
@@ -14,24 +15,12 @@ if (project.auth && !store.__protobaseAuthSchemaChecked) {
|
|
|
14
15
|
store.__protobaseAuthSchemaChecked = true;
|
|
15
16
|
}
|
|
16
17
|
await checkChanges(db, resources.map((resource) => resource.toModel()), project.events);
|
|
17
|
-
await
|
|
18
|
-
const admin =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
db,
|
|
24
|
-
authenticate: project.authenticate,
|
|
25
|
-
...project.auth && { auth: project.auth },
|
|
26
|
-
...project.functions && { functions: project.functions },
|
|
27
|
-
...project.files && { files: project.files },
|
|
28
|
-
...project.events && { events: project.events },
|
|
29
|
-
jobs: jobDefinitions(project.jobs ?? {}),
|
|
30
|
-
options: {
|
|
31
|
-
onUnhandledError: (error) => console.error(error),
|
|
32
|
-
...project.options
|
|
33
|
-
}
|
|
34
|
-
});
|
|
18
|
+
if (project.webhooks) await checkWebhooksSchema(db, project.webhooks);
|
|
19
|
+
const { admin, jobs } = projectAdmin({
|
|
20
|
+
...project,
|
|
21
|
+
authenticate: project.authenticate
|
|
22
|
+
}, project.exports, db);
|
|
23
|
+
await devJobs(db, jobs);
|
|
35
24
|
var entry_default = new Hono().route("/", admin);
|
|
36
25
|
if (project.auth && !store.__protobaseNoUsersShown) {
|
|
37
26
|
store.__protobaseNoUsersShown = true;
|
|
@@ -32,6 +32,7 @@ const loadMigrationProject = async (dir, extensions = []) => {
|
|
|
32
32
|
db: project.db ?? ownDb,
|
|
33
33
|
...project.auth && { auth: project.auth },
|
|
34
34
|
...project.events && { events: project.events },
|
|
35
|
+
...project.webhooks && { webhooks: project.webhooks },
|
|
35
36
|
jobs: jobDefinitions(project.jobs ?? {}),
|
|
36
37
|
close: async () => {
|
|
37
38
|
await ownDb?.destroy();
|
package/dist/migration/parts.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { authSchemaMigration, changesMigration, jobsSchemaMigration } from "@protobase/server";
|
|
1
|
+
import { authSchemaMigration, changesMigration, jobsSchemaMigration, webhooksMigration } from "@protobase/server";
|
|
2
2
|
//#region src/migration/parts.ts
|
|
3
3
|
/** Every feature the project's config enables, in the order their files are written. */
|
|
4
4
|
const migrationParts = (project) => [
|
|
@@ -7,7 +7,7 @@ const migrationParts = (project) => [
|
|
|
7
7
|
title: "The auth schema changes this version of Protobase needs",
|
|
8
8
|
sql: () => authSchemaMigration(project.auth)
|
|
9
9
|
}] : [],
|
|
10
|
-
...project.jobs.length > 0 ? [{
|
|
10
|
+
...project.jobs.length > 0 || project.models.some((model) => model.events) || project.webhooks ? [{
|
|
11
11
|
name: "jobs",
|
|
12
12
|
title: "The jobs schema this version of Protobase needs",
|
|
13
13
|
sql: () => jobsSchemaMigration(project.db)
|
|
@@ -16,7 +16,12 @@ const migrationParts = (project) => [
|
|
|
16
16
|
name: "changes",
|
|
17
17
|
title: "The change capture the resources' events need",
|
|
18
18
|
sql: () => changesMigration(project.db, project.models, project.events)
|
|
19
|
-
}
|
|
19
|
+
},
|
|
20
|
+
...project.webhooks ? [{
|
|
21
|
+
name: "webhooks",
|
|
22
|
+
title: "The webhook subscriptions of webhooks()",
|
|
23
|
+
sql: () => webhooksMigration(project.db, project.webhooks, project.events)
|
|
24
|
+
}] : []
|
|
20
25
|
];
|
|
21
26
|
//#endregion
|
|
22
27
|
export { migrationParts };
|
package/dist/package.js
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { configExports, createAdmin, jobDefinitions } from "@protobase/server";
|
|
2
|
+
//#region src/project/project-admin.ts
|
|
3
|
+
/**
|
|
4
|
+
* The admin API of a project over `db`, as `dev`, `serve` and `worker` build it: its config module's resources, views,
|
|
5
|
+
* pages and subscriptions, and the rest of its config. `jobs` are the project's own and the delivery of its events.
|
|
6
|
+
*/
|
|
7
|
+
const projectAdmin = (project, config, db) => {
|
|
8
|
+
const { resources, views, pages, userMenu, subscriptions } = configExports(config);
|
|
9
|
+
const own = jobDefinitions(project.jobs ?? {});
|
|
10
|
+
const admin = createAdmin({
|
|
11
|
+
resources,
|
|
12
|
+
views,
|
|
13
|
+
pages,
|
|
14
|
+
...userMenu && { userMenu },
|
|
15
|
+
db,
|
|
16
|
+
authenticate: project.authenticate,
|
|
17
|
+
...project.auth && { auth: project.auth },
|
|
18
|
+
...project.functions && { functions: project.functions },
|
|
19
|
+
...project.files && { files: project.files },
|
|
20
|
+
...project.events && { events: project.events },
|
|
21
|
+
...project.webhooks && { webhooks: project.webhooks },
|
|
22
|
+
jobs: own,
|
|
23
|
+
subscriptions,
|
|
24
|
+
options: {
|
|
25
|
+
onUnhandledError: (error) => console.error(error),
|
|
26
|
+
...project.options
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return {
|
|
30
|
+
admin,
|
|
31
|
+
jobs: [...own, ...admin.jobs]
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
//#endregion
|
|
35
|
+
export { projectAdmin };
|
package/dist/serve/app.js
CHANGED
|
@@ -1,28 +1,10 @@
|
|
|
1
1
|
import { isApiPath } from "../bundle/manifest.js";
|
|
2
2
|
import { serveStaticSite } from "./static-site.js";
|
|
3
|
-
import {
|
|
3
|
+
import { jobsDrainApp } from "@protobase/server";
|
|
4
4
|
import { Hono } from "hono";
|
|
5
5
|
import { logger } from "hono/logger";
|
|
6
6
|
//#region src/serve/app.ts
|
|
7
|
-
const createServeApp = ({
|
|
8
|
-
const { resources, views, pages, userMenu } = configExports(project.config);
|
|
9
|
-
const admin = createAdmin({
|
|
10
|
-
resources,
|
|
11
|
-
views,
|
|
12
|
-
pages,
|
|
13
|
-
...userMenu && { userMenu },
|
|
14
|
-
db,
|
|
15
|
-
authenticate: project.authenticate,
|
|
16
|
-
...project.auth && { auth: project.auth },
|
|
17
|
-
...project.functions && { functions: project.functions },
|
|
18
|
-
...project.files && { files: project.files },
|
|
19
|
-
...project.events && { events: project.events },
|
|
20
|
-
jobs: jobDefinitions(project.jobs ?? {}),
|
|
21
|
-
options: {
|
|
22
|
-
onUnhandledError: (error) => console.error(error),
|
|
23
|
-
...project.options
|
|
24
|
-
}
|
|
25
|
-
});
|
|
7
|
+
const createServeApp = ({ admin, requestLog, site, jobs, drainToken }) => {
|
|
26
8
|
const app = new Hono();
|
|
27
9
|
if (requestLog) app.use(logger());
|
|
28
10
|
app.get("/health", (c) => c.json({ status: "ok" }));
|
package/dist/serve/lifecycle.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { projectAdmin } from "../project/project-admin.js";
|
|
1
2
|
import { createPgDb } from "../project/pg-db.js";
|
|
2
3
|
import { createServeApp } from "./app.js";
|
|
3
4
|
import { startCleanupTimer } from "./cleanup-timer.js";
|
|
4
|
-
import { checkAuthSchema, checkChanges, checkJobsSchema, configExports, createFileCleanup,
|
|
5
|
+
import { checkAuthSchema, checkChanges, checkJobsSchema, checkWebhooksSchema, configExports, createFileCleanup, startJobs } from "@protobase/server";
|
|
5
6
|
import { createAdaptorServer } from "@hono/node-server";
|
|
6
7
|
import pg from "pg";
|
|
7
8
|
//#region src/serve/lifecycle.ts
|
|
@@ -19,9 +20,10 @@ const startServe = async ({ project, env, createDb = (url) => createPgDb(pg, url
|
|
|
19
20
|
const ownDb = project.db ? void 0 : createDb(env.databaseUrl);
|
|
20
21
|
const db = project.db ?? ownDb;
|
|
21
22
|
const { resources } = configExports(project.config);
|
|
22
|
-
const definitions = jobDefinitions(project.jobs ?? {});
|
|
23
23
|
const startJobsAndListen = async () => {
|
|
24
24
|
await checkChanges(db, resources.map((resource) => resource.toModel()), project.events);
|
|
25
|
+
if (project.webhooks) await checkWebhooksSchema(db, project.webhooks);
|
|
26
|
+
const { admin, jobs: definitions } = projectAdmin(project, project.config, db);
|
|
25
27
|
if (definitions.length > 0) await checkJobsSchema(db);
|
|
26
28
|
const jobs = definitions.length > 0 ? await startJobs({
|
|
27
29
|
db,
|
|
@@ -30,8 +32,7 @@ const startServe = async ({ project, env, createDb = (url) => createPgDb(pg, url
|
|
|
30
32
|
onError: (error) => console.error(error)
|
|
31
33
|
}) : void 0;
|
|
32
34
|
const app = createServeApp({
|
|
33
|
-
|
|
34
|
-
db,
|
|
35
|
+
admin,
|
|
35
36
|
requestLog: env.requestLog,
|
|
36
37
|
site,
|
|
37
38
|
...jobs && { jobs },
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { readManifest } from "../bundle/manifest.js";
|
|
2
2
|
import { checkBundleVersion } from "../serve/bundle-version.js";
|
|
3
|
+
import { projectAdmin } from "../project/project-admin.js";
|
|
3
4
|
import { createPgDb } from "../project/pg-db.js";
|
|
4
5
|
import { loadBundle } from "../serve/load-bundle.js";
|
|
5
6
|
import { statSync } from "node:fs";
|
|
6
7
|
import path from "node:path";
|
|
7
|
-
import { checkJobsSchema, jobDefinitions, startJobs } from "@protobase/server";
|
|
8
|
+
import { checkJobsSchema, configExports, jobDefinitions, startJobs } from "@protobase/server";
|
|
8
9
|
import pg from "pg";
|
|
9
10
|
//#region src/worker/start-worker.ts
|
|
10
11
|
const bundleConfigFile = async (bundle) => {
|
|
@@ -16,20 +17,24 @@ const bundleConfigFile = async (bundle) => {
|
|
|
16
17
|
* their own. It reads the jobs schema at start and refuses one that is missing or behind, like `serve`.
|
|
17
18
|
*/
|
|
18
19
|
const startWorker = async ({ project, databaseUrl, createDb = (url) => createPgDb(pg, url) }) => {
|
|
19
|
-
const
|
|
20
|
-
if (
|
|
20
|
+
const withEvents = configExports(project.config).resources.some((resource) => resource.toModel().events);
|
|
21
|
+
if (jobDefinitions(project.jobs ?? {}).length === 0 && !withEvents) throw new Error("The bundle has no jobs: export them from protobase.config.ts as `jobs`, or give a resource events");
|
|
21
22
|
if (!project.db && !databaseUrl) throw new Error("No database: set DATABASE_URL or export `db` from protobase.config.ts");
|
|
22
23
|
const ownDb = project.db ? void 0 : createDb(databaseUrl);
|
|
23
24
|
const db = project.db ?? ownDb;
|
|
24
25
|
const start = async () => {
|
|
26
|
+
const { jobs: definitions } = projectAdmin(project, project.config, db);
|
|
25
27
|
await checkJobsSchema(db);
|
|
26
|
-
return
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
return {
|
|
29
|
+
definitions,
|
|
30
|
+
runtime: await startJobs({
|
|
31
|
+
db,
|
|
32
|
+
jobs: definitions,
|
|
33
|
+
onError: (error) => console.error(error)
|
|
34
|
+
})
|
|
35
|
+
};
|
|
31
36
|
};
|
|
32
|
-
const jobs = await start().catch(async (error) => {
|
|
37
|
+
const { definitions, runtime: jobs } = await start().catch(async (error) => {
|
|
33
38
|
await ownDb?.destroy();
|
|
34
39
|
throw error;
|
|
35
40
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.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": {
|
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@hono/node-server": "^2.1.3",
|
|
36
36
|
"@hono/vite-dev-server": "^0.26.1",
|
|
37
|
-
"@protobase/layout": "0.
|
|
38
|
-
"@protobase/query": "0.
|
|
39
|
-
"@protobase/schema": "0.
|
|
40
|
-
"@protobase/server": "0.
|
|
41
|
-
"@protobase/ui": "0.
|
|
37
|
+
"@protobase/layout": "0.9.0",
|
|
38
|
+
"@protobase/query": "0.9.0",
|
|
39
|
+
"@protobase/schema": "0.9.0",
|
|
40
|
+
"@protobase/server": "0.9.0",
|
|
41
|
+
"@protobase/ui": "0.9.0",
|
|
42
42
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
43
43
|
"@tailwindcss/vite": "^4.3.3",
|
|
44
44
|
"@vitejs/plugin-react": "^6.1.2",
|