@protobase/cli 0.21.7 → 0.21.9
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/db/queries.js +4 -0
- package/dist/dev/entry.js +9 -2
- package/dist/doctor/view-shapes.js +18 -0
- package/dist/migration/parts.js +32 -23
- package/dist/package.js +1 -1
- package/dist/scaffold/data-file.js +2 -1
- package/dist/scaffold/resource-plan.js +18 -1
- package/dist/serve/lifecycle.js +9 -2
- package/dist/worker/start-worker.js +5 -2
- package/package.json +6 -6
package/dist/db/queries.js
CHANGED
|
@@ -50,6 +50,10 @@ const selectIndexes = (sql, relations) => sql`
|
|
|
50
50
|
from unnest(i.indkey::int2[]) with ordinality k(attnum, ord)
|
|
51
51
|
left join pg_attribute a on a.attrelid = i.indrelid and a.attnum = k.attnum
|
|
52
52
|
where k.ord <= i.indnkeyatts) as columns,
|
|
53
|
+
(select array_agg(oc.opcname::text order by k.ord)
|
|
54
|
+
from unnest(i.indclass::oid[]) with ordinality k(opclass, ord)
|
|
55
|
+
join pg_opclass oc on oc.oid = k.opclass
|
|
56
|
+
where k.ord <= i.indnkeyatts) as opclasses,
|
|
53
57
|
i.indisunique as unique, i.indisprimary as primary, (i.indpred is not null) as partial, am.amname as method
|
|
54
58
|
from pg_index i
|
|
55
59
|
join pg_class c on c.oid = i.indrelid
|
package/dist/dev/entry.js
CHANGED
|
@@ -2,13 +2,13 @@ import { devJobs } from "./dev-jobs.js";
|
|
|
2
2
|
import { projectErrorReporter } from "../project/error-reporter.js";
|
|
3
3
|
import { projectAdmin } from "../project/project-admin.js";
|
|
4
4
|
import { loadProject, projectDb } from "./project.js";
|
|
5
|
-
import { checkAuthSchema, checkChanges, checkWebhooksSchema, configExports, hasUsers } from "@protobase/server";
|
|
5
|
+
import { checkAi, checkAuthSchema, checkChanges, checkComments, checkWebhooksSchema, configExports, hasUsers } from "@protobase/server";
|
|
6
6
|
import { Hono } from "hono";
|
|
7
7
|
//#region src/dev/entry.ts
|
|
8
8
|
const projectDir = process.env.PROTOBASE_PROJECT;
|
|
9
9
|
const project = await loadProject(projectDir, JSON.parse(process.env.PROTOBASE_EXTENSIONS ?? "[]"));
|
|
10
10
|
const db = projectDb(project, projectDir);
|
|
11
|
-
const { resources } = configExports(project.exports);
|
|
11
|
+
const { resources, views } = configExports(project.exports);
|
|
12
12
|
if (!project.authenticate) throw new Error("No authenticator: export `authenticate` (and `auth`) from protobase.config.ts; see https://docs.protobase.net/reference/auth/");
|
|
13
13
|
const store = globalThis;
|
|
14
14
|
if (project.auth && !store.__protobaseAuthSchemaChecked) {
|
|
@@ -16,6 +16,13 @@ if (project.auth && !store.__protobaseAuthSchemaChecked) {
|
|
|
16
16
|
store.__protobaseAuthSchemaChecked = true;
|
|
17
17
|
}
|
|
18
18
|
await checkChanges(db, resources.map((resource) => resource.toModel()), project.events);
|
|
19
|
+
await checkComments(db, resources.map((resource) => resource.toModel()));
|
|
20
|
+
checkAi({
|
|
21
|
+
models: resources.map((resource) => resource.toModel()),
|
|
22
|
+
views: views.map((source) => source.toModel()),
|
|
23
|
+
assistant: project.options?.assistant,
|
|
24
|
+
env: process.env
|
|
25
|
+
});
|
|
19
26
|
if (project.webhooks) await checkWebhooksSchema(db, project.webhooks);
|
|
20
27
|
const reporter = await projectErrorReporter(project, process.env);
|
|
21
28
|
const { admin, jobs } = projectAdmin({
|
|
@@ -138,6 +138,24 @@ const displayShapes = (model, view, models) => (view.list?.displays ?? []).flatM
|
|
|
138
138
|
}
|
|
139
139
|
}];
|
|
140
140
|
}
|
|
141
|
+
if (display.kind === "calendar") {
|
|
142
|
+
const start = model.fields[display.start];
|
|
143
|
+
if (!start) return [];
|
|
144
|
+
const end = display.end === void 0 ? void 0 : model.fields[display.end];
|
|
145
|
+
const sort = [[start.name, "asc"]];
|
|
146
|
+
const within = all([compare(start, ">="), compare(start, "<")]);
|
|
147
|
+
const filter = end ? any([within, all([compare(start, "<"), compare(end, ">=")])]) : within;
|
|
148
|
+
const text = end ? `(${start.name} >= … AND ${start.name} < …) OR (${start.name} < … AND ${end.name} >= …)` : `${start.name} >= … AND ${start.name} < …`;
|
|
149
|
+
return [{
|
|
150
|
+
resource: model.name,
|
|
151
|
+
request: request(model.name, text, sort),
|
|
152
|
+
from: `the calendar display "${display.name}"`,
|
|
153
|
+
query: {
|
|
154
|
+
filter,
|
|
155
|
+
sort
|
|
156
|
+
}
|
|
157
|
+
}];
|
|
158
|
+
}
|
|
141
159
|
const photos = display.kind === "cards" ? display.photos : void 0;
|
|
142
160
|
const holder = photos && models[photos.resource];
|
|
143
161
|
const field = holder?.fields[photos.field];
|
package/dist/migration/parts.js
CHANGED
|
@@ -1,27 +1,36 @@
|
|
|
1
|
-
import { authSchemaMigration, changesMigration, isCaptured, jobsSchemaMigration, webhooksMigration } from "@protobase/server";
|
|
1
|
+
import { authSchemaMigration, changesMigration, commentsMigration, isCaptured, 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
|
-
const migrationParts = (project) =>
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
4
|
+
const migrationParts = (project) => {
|
|
5
|
+
const comments = project.models.some((model) => model.comments);
|
|
6
|
+
const aiFields = project.models.some((model) => Object.values(model.fields).some((field) => field.ai));
|
|
7
|
+
return [
|
|
8
|
+
...project.auth ? [{
|
|
9
|
+
name: "auth",
|
|
10
|
+
title: "The auth schema changes this version of Protobase needs",
|
|
11
|
+
sql: () => authSchemaMigration(project.auth)
|
|
12
|
+
}] : [],
|
|
13
|
+
...project.jobs.length > 0 || project.models.some(isCaptured) || comments || aiFields || project.webhooks ? [{
|
|
14
|
+
name: "jobs",
|
|
15
|
+
title: "The jobs schema this version of Protobase needs",
|
|
16
|
+
sql: () => jobsSchemaMigration(project.db)
|
|
17
|
+
}] : [],
|
|
18
|
+
{
|
|
19
|
+
name: "changes",
|
|
20
|
+
title: "The change capture the resources' events and history need",
|
|
21
|
+
sql: () => changesMigration(project.db, project.models, project.events)
|
|
22
|
+
},
|
|
23
|
+
...comments ? [{
|
|
24
|
+
name: "comments",
|
|
25
|
+
title: "The comments table of the resources with comments",
|
|
26
|
+
sql: () => commentsMigration(project.db)
|
|
27
|
+
}] : [],
|
|
28
|
+
...project.webhooks ? [{
|
|
29
|
+
name: "webhooks",
|
|
30
|
+
title: "The webhook subscriptions of webhooks()",
|
|
31
|
+
sql: () => webhooksMigration(project.db, project.webhooks, project.events)
|
|
32
|
+
}] : []
|
|
33
|
+
];
|
|
34
|
+
};
|
|
26
35
|
//#endregion
|
|
27
36
|
export { migrationParts };
|
package/dist/package.js
CHANGED
|
@@ -15,7 +15,8 @@ const renderDataFile = (plan) => {
|
|
|
15
15
|
const tail = [
|
|
16
16
|
` .primaryKey((r) => ${refs(plan.primaryKey)})`,
|
|
17
17
|
plan.softDelete && ` .softDelete((r) => r.${plan.softDelete})`,
|
|
18
|
-
plan.tenant && ` .tenant((r) => r.${plan.tenant})
|
|
18
|
+
plan.tenant && ` .tenant((r) => r.${plan.tenant})`,
|
|
19
|
+
plan.search && ` .search((r) => [r.${plan.search}])`
|
|
19
20
|
].filter(Boolean);
|
|
20
21
|
return [
|
|
21
22
|
`import { f, resource } from '@protobase/schema'`,
|
|
@@ -8,6 +8,21 @@ const isSoftDeleteColumn = (table, column) => softDeleteColumn.test(column) && t
|
|
|
8
8
|
"timestamptz",
|
|
9
9
|
"date"
|
|
10
10
|
].includes(c.typeName));
|
|
11
|
+
const titleCandidates = [
|
|
12
|
+
"name",
|
|
13
|
+
"title",
|
|
14
|
+
"number",
|
|
15
|
+
"sku",
|
|
16
|
+
"email",
|
|
17
|
+
"code",
|
|
18
|
+
"description"
|
|
19
|
+
];
|
|
20
|
+
const trigramClasses = ["gin_trgm_ops", "gist_trgm_ops"];
|
|
21
|
+
const servesSearch = (table, column) => table.indexes.some((index) => !index.partial && index.columns.some((key, position) => key === column && trigramClasses.includes(index.opclasses[position] ?? "")));
|
|
22
|
+
const titleOf = (kept, key) => {
|
|
23
|
+
const texts = kept.filter((p) => p.type === "text" && !key.includes(p.column) && !isTenantColumn(p.column));
|
|
24
|
+
return titleCandidates.map((name) => texts.find((p) => p.name === name)).find(Boolean) ?? texts[0];
|
|
25
|
+
};
|
|
11
26
|
const planResource = (name, table, decisions) => {
|
|
12
27
|
const key = keyColumns(table);
|
|
13
28
|
if (!key) return void 0;
|
|
@@ -19,6 +34,7 @@ const planResource = (name, table, decisions) => {
|
|
|
19
34
|
const primaryKey = key.map(nameOf);
|
|
20
35
|
if (primaryKey.some((n) => n === void 0)) throw new Error(`${tableKey(table)}: key columns cannot be ignored`);
|
|
21
36
|
const primary = table.indexes.find((index) => index.primary);
|
|
37
|
+
const title = titleOf(kept, key);
|
|
22
38
|
return {
|
|
23
39
|
name,
|
|
24
40
|
table,
|
|
@@ -26,7 +42,8 @@ const planResource = (name, table, decisions) => {
|
|
|
26
42
|
primaryKey,
|
|
27
43
|
softDelete: find((c) => isSoftDeleteColumn(table, c)),
|
|
28
44
|
tenant: find(isTenantColumn),
|
|
29
|
-
unique: table.indexes.filter((index) => index.unique && !index.partial && index !== primary).flatMap((index) => index.columns.every((c) => c !== null) ? [index.columns] : [])
|
|
45
|
+
unique: table.indexes.filter((index) => index.unique && !index.partial && index !== primary).flatMap((index) => index.columns.every((c) => c !== null) ? [index.columns] : []),
|
|
46
|
+
...title && servesSearch(table, title.column) && { search: title.name }
|
|
30
47
|
};
|
|
31
48
|
};
|
|
32
49
|
//#endregion
|
package/dist/serve/lifecycle.js
CHANGED
|
@@ -2,7 +2,7 @@ import { projectAdmin } from "../project/project-admin.js";
|
|
|
2
2
|
import { createPgDb } from "../project/pg-db.js";
|
|
3
3
|
import { createServeApp } from "./app.js";
|
|
4
4
|
import { startCleanupTimer } from "./cleanup-timer.js";
|
|
5
|
-
import { checkAuthSchema, checkChanges, checkJobsSchema, checkWebhooksSchema, configExports, createFileCleanup, startJobs } from "@protobase/server";
|
|
5
|
+
import { checkAi, checkAuthSchema, checkChanges, checkComments, checkJobsSchema, checkWebhooksSchema, configExports, createFileCleanup, startJobs } from "@protobase/server";
|
|
6
6
|
import pg from "pg";
|
|
7
7
|
import { createAdaptorServer } from "@hono/node-server";
|
|
8
8
|
//#region src/serve/lifecycle.ts
|
|
@@ -19,9 +19,16 @@ const startServe = async ({ project, env, createDb = (url) => createPgDb(pg, url
|
|
|
19
19
|
if (env.startupChecks && project.auth) await checkAuthSchema(project.auth);
|
|
20
20
|
const ownDb = project.db ? void 0 : createDb(env.databaseUrl);
|
|
21
21
|
const db = project.db ?? ownDb;
|
|
22
|
-
const { resources } = configExports(project.config);
|
|
22
|
+
const { resources, views } = configExports(project.config);
|
|
23
23
|
const startJobsAndListen = async () => {
|
|
24
24
|
if (env.startupChecks) await checkChanges(db, resources.map((resource) => resource.toModel()), project.events);
|
|
25
|
+
if (env.startupChecks) await checkComments(db, resources.map((resource) => resource.toModel()));
|
|
26
|
+
if (env.startupChecks) checkAi({
|
|
27
|
+
models: resources.map((resource) => resource.toModel()),
|
|
28
|
+
views: views.map((source) => source.toModel()),
|
|
29
|
+
assistant: project.options?.assistant,
|
|
30
|
+
env: process.env
|
|
31
|
+
});
|
|
25
32
|
if (env.startupChecks && project.webhooks) await checkWebhooksSchema(db, project.webhooks);
|
|
26
33
|
const { admin, jobs: definitions } = projectAdmin(project, project.config, db, ui, reporter);
|
|
27
34
|
if (env.startupChecks && definitions.length > 0) await checkJobsSchema(db);
|
|
@@ -17,8 +17,11 @@ const bundleConfigFile = async (bundle) => {
|
|
|
17
17
|
* their own. It reads the jobs schema at start and refuses one that is missing or behind, like `serve`.
|
|
18
18
|
*/
|
|
19
19
|
const startWorker = async ({ project, databaseUrl, createDb = (url) => createPgDb(pg, url) }) => {
|
|
20
|
-
const
|
|
21
|
-
|
|
20
|
+
const builtIn = configExports(project.config).resources.some((resource) => {
|
|
21
|
+
const model = resource.toModel();
|
|
22
|
+
return isCaptured(model) || model.comments || Object.values(model.fields).some((field) => field.ai);
|
|
23
|
+
});
|
|
24
|
+
if (jobDefinitions(project.jobs ?? {}).length === 0 && !builtIn) throw new Error("The bundle has no jobs: export them from protobase.config.ts as `jobs`, or give a resource events, history, comments or an AI field");
|
|
22
25
|
if (!project.db && !databaseUrl) throw new Error("No database: set DATABASE_URL or export `db` from protobase.config.ts");
|
|
23
26
|
const ownDb = project.db ? void 0 : createDb(databaseUrl);
|
|
24
27
|
const db = project.db ?? ownDb;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.21.
|
|
3
|
+
"version": "0.21.9",
|
|
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.21.
|
|
38
|
-
"@protobase/query": "0.21.
|
|
39
|
-
"@protobase/schema": "0.21.
|
|
40
|
-
"@protobase/server": "0.21.
|
|
41
|
-
"@protobase/ui": "0.21.
|
|
37
|
+
"@protobase/layout": "0.21.9",
|
|
38
|
+
"@protobase/query": "0.21.9",
|
|
39
|
+
"@protobase/schema": "0.21.9",
|
|
40
|
+
"@protobase/server": "0.21.9",
|
|
41
|
+
"@protobase/ui": "0.21.9",
|
|
42
42
|
"@react-email/render": "^2.1.0",
|
|
43
43
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
44
44
|
"@tailwindcss/vite": "^4.3.3",
|