@protobase/cli 0.46.11 → 0.46.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/register.js +1 -2
- package/dist/auth/write-migration.js +1 -1
- package/dist/build/app-icons.js +1 -1
- package/dist/build/config-bundle.js +1 -1
- package/dist/build/deploy-bundle.js +2 -2
- package/dist/build/entry-code.js +1 -1
- package/dist/build/plugin-build.js +3 -3
- package/dist/build/plugin-fields.js +1 -1
- package/dist/build/service-worker-code.js +1 -1
- package/dist/build/shell.js +2 -2
- package/dist/build/ui-check.js +2 -2
- package/dist/build/vite-bundle.js +1 -1
- package/dist/bundle/manifest.js +1 -1
- package/dist/cli/package.js +1 -1
- package/dist/db/connect.js +8 -5
- package/dist/dev/entry.js +3 -3
- package/dist/dev/project.js +2 -2
- package/dist/dev/run.js +8 -4
- package/dist/dev/startup-logger.js +24 -0
- package/dist/doctor/run.js +4 -1
- package/dist/encryption/register.js +1 -2
- package/dist/error-message.js +15 -0
- package/dist/files/register.js +1 -2
- package/dist/infer/proposal.js +1 -1
- package/dist/main.js +34 -26
- package/dist/migration/load-project.js +1 -1
- package/dist/migration/register.js +7 -4
- package/dist/migration/summary.js +15 -0
- package/dist/mobile/local-spec.js +1 -1
- package/dist/mobile/run.js +1 -1
- package/dist/mobile/web-part.js +2 -2
- package/dist/mobile/workspace.js +1 -1
- package/dist/notifications/register.js +1 -2
- package/dist/organizations/api.js +15 -0
- package/dist/organizations/register.js +5 -15
- package/dist/project/favicon-link.js +1 -1
- package/dist/project/load-bundle-project.js +2 -2
- package/dist/project/load-data-config.js +2 -2
- package/dist/project/placeholder-secret.js +9 -0
- package/dist/scaffold/existing-config.js +4 -1
- package/dist/scaffold/plan.js +11 -7
- package/dist/scaffold/project.js +2 -1
- package/dist/scaffold/prompt.js +12 -5
- package/dist/scaffold/run.js +1 -1
- package/dist/scaffold/ui-fields.js +3 -0
- package/dist/scaffold/ui-file.js +26 -4
- package/dist/serve/app.js +1 -1
- package/dist/serve/bundle-version.js +1 -1
- package/dist/serve/create-admin.js +3 -3
- package/dist/serve/host-modules.js +5 -5
- package/dist/serve/lifecycle.js +3 -3
- package/dist/serve/mobile-release.js +1 -1
- package/dist/serve/serve-bundle-path.js +1 -1
- package/dist/serve/serve-bundle.js +3 -3
- package/dist/serve/serve-dir.js +2 -2
- package/dist/supabase/dump-phase.js +2 -2
- package/dist/supabase/load-phase.js +2 -2
- package/dist/supabase/register.js +1 -1
- package/dist/supabase/storage-phase.js +1 -1
- package/dist/users/commands.js +7 -1
- package/dist/users/register.js +17 -11
- package/dist/users/users-api.js +2 -1
- package/dist/worker/start-worker.js +2 -2
- package/package.json +6 -6
- package/skills/protobase/SKILL.md +1 -0
- package/skills/protobase/references/getting-started.md +4 -0
- package/skills/protobase/references/guides/existing-database.md +112 -0
- package/skills/protobase/references/reference/cli.md +12 -7
package/dist/mobile/web-part.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { bundleLayout } from "../bundle/manifest.js";
|
|
2
|
-
import { buildDeployBundle } from "../build/deploy-bundle.js";
|
|
3
2
|
import { withApiOrigin } from "./api-origin-page.js";
|
|
4
3
|
import { siteFiles } from "../serve/site-files.js";
|
|
4
|
+
import { buildDeployBundle } from "../build/deploy-bundle.js";
|
|
5
5
|
import path from "node:path";
|
|
6
|
-
import { releaseManifest } from "@protobase/server";
|
|
7
6
|
import { cp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
7
|
+
import { releaseManifest } from "@protobase/server";
|
|
8
8
|
import { releaseManifestFile } from "@protobase/schema/internal";
|
|
9
9
|
const writeReleaseManifest = async (web) => {
|
|
10
10
|
const files = await Promise.all((await siteFiles({
|
package/dist/mobile/workspace.js
CHANGED
|
@@ -6,8 +6,8 @@ import { isLocalSpec } from "./local-spec.js";
|
|
|
6
6
|
import { checkLocalPins, isUnmet, localPins } from "./local-pins.js";
|
|
7
7
|
import { existsSync } from "node:fs";
|
|
8
8
|
import path from "node:path";
|
|
9
|
-
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
10
9
|
import { fileURLToPath } from "node:url";
|
|
10
|
+
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
11
11
|
//#region src/mobile/workspace.ts
|
|
12
12
|
/** Where the mobile build lives in a project: npm's install of @protobase/mobile, the app's files and native projects. */
|
|
13
13
|
const workspaceDir = (projectDir) => path.join(projectDir, protobaseFolder, "mobile");
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { printVapidKeys } from "./print-vapid-keys.js";
|
|
2
1
|
//#region src/notifications/register.ts
|
|
3
2
|
const registerNotifications = (program) => {
|
|
4
|
-
program.command("notifications").description("Set up the delivery of notifications").command("vapid-keys").description("Print a fresh VAPID key pair for Web Push, as PROTOBASE_VAPID_PUBLIC_KEY and PROTOBASE_VAPID_PRIVATE_KEY").action(() => printVapidKeys((text) => void process.stdout.write(text), (text) => void process.stderr.write(text)));
|
|
3
|
+
program.command("notifications").description("Set up the delivery of notifications").command("vapid-keys").description("Print a fresh VAPID key pair for Web Push, as PROTOBASE_VAPID_PUBLIC_KEY and PROTOBASE_VAPID_PRIVATE_KEY").action(async () => (await import("./print-vapid-keys.js")).printVapidKeys((text) => void process.stdout.write(text), (text) => void process.stderr.write(text)));
|
|
5
4
|
};
|
|
6
5
|
//#endregion
|
|
7
6
|
export { registerNotifications };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { addAppRoleToOwners, addMember, createOrganization, listOrganizations, listUsers, removeMember, setMemberRoles, setUserRole } from "@protobase/server";
|
|
2
|
+
//#region src/organizations/api.ts
|
|
3
|
+
const organizationsApi = (auth) => ({
|
|
4
|
+
listOrganizations: () => listOrganizations(auth),
|
|
5
|
+
createOrganization: (input) => createOrganization(auth, input),
|
|
6
|
+
addMember: (input) => addMember(auth, input),
|
|
7
|
+
setMemberRoles: (input) => setMemberRoles(auth, input),
|
|
8
|
+
removeMember: (input) => removeMember(auth, input),
|
|
9
|
+
addAppRoleToOwners: (appRole) => addAppRoleToOwners(auth, appRole),
|
|
10
|
+
listUsers: () => listUsers(auth),
|
|
11
|
+
setUserRole: (input) => setUserRole(auth, input),
|
|
12
|
+
membershipRoles: () => auth.roleDefinitions.names.filter((name) => name !== "admin" && name !== "user")
|
|
13
|
+
});
|
|
14
|
+
//#endregion
|
|
15
|
+
export { organizationsApi };
|
|
@@ -1,20 +1,10 @@
|
|
|
1
|
-
import { loadProjectAuth } from "../users/load-auth.js";
|
|
2
1
|
import { addAppRoleCommand, addMemberCommand, createOrganizationCommand, listOrganizationsCommand, removeMemberCommand, setMemberRolesCommand } from "./commands.js";
|
|
3
|
-
import { addAppRoleToOwners, addMember, createOrganization, listOrganizations, listUsers, removeMember, setMemberRoles, setUserRole } from "@protobase/server";
|
|
4
2
|
//#region src/organizations/register.ts
|
|
5
3
|
const out = (text) => process.stdout.write(text);
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
setMemberRoles: (input) => setMemberRoles(auth, input),
|
|
11
|
-
removeMember: (input) => removeMember(auth, input),
|
|
12
|
-
addAppRoleToOwners: (appRole) => addAppRoleToOwners(auth, appRole),
|
|
13
|
-
listUsers: () => listUsers(auth),
|
|
14
|
-
setUserRole: (input) => setUserRole(auth, input),
|
|
15
|
-
membershipRoles: () => auth.roleDefinitions.names.filter((name) => name !== "admin" && name !== "user")
|
|
16
|
-
});
|
|
17
|
-
const projectApi = async () => organizationsApi(await loadProjectAuth(process.cwd()));
|
|
4
|
+
const projectApi = async () => {
|
|
5
|
+
const [{ organizationsApi }, { loadProjectAuth }] = await Promise.all([import("./api.js"), import("../users/load-auth.js")]);
|
|
6
|
+
return organizationsApi(await loadProjectAuth(process.cwd()));
|
|
7
|
+
};
|
|
18
8
|
const finish = (code) => process.exit(code);
|
|
19
9
|
const memberOptions = (command) => command.argument("<organization>", "its slug or id").argument("<email>").option("--org-role <role>", "owner, admin or member: who manages the organization").option("--app-roles <roles>", "app roles in this organization, comma separated (see `users roles`)");
|
|
20
10
|
const registerOrganizations = (program) => {
|
|
@@ -67,4 +57,4 @@ const registerOrganizations = (program) => {
|
|
|
67
57
|
});
|
|
68
58
|
};
|
|
69
59
|
//#endregion
|
|
70
|
-
export {
|
|
60
|
+
export { registerOrganizations };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { faviconFile, projectFavicon } from "../build/favicon.js";
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import { pngIcons } from "@protobase/server";
|
|
5
4
|
import { readFile } from "node:fs/promises";
|
|
5
|
+
import { pngIcons } from "@protobase/server";
|
|
6
6
|
//#region src/project/favicon-link.ts
|
|
7
7
|
/**
|
|
8
8
|
* Links the project's favicon at `/protobase.favicon.svg` in the app's page, and its Apple touch icon at
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { loadNearestEnvFile } from "../dev/env.js";
|
|
2
|
-
import { importProjectFile } from "./import-project-file.js";
|
|
3
|
-
import { readManifest } from "../bundle/manifest.js";
|
|
4
2
|
import { createPgDb } from "./pg-db.js";
|
|
3
|
+
import { readManifest } from "../bundle/manifest.js";
|
|
5
4
|
import { loadBundle } from "../serve/load-bundle.js";
|
|
5
|
+
import { importProjectFile } from "./import-project-file.js";
|
|
6
6
|
import { existsSync, statSync } from "node:fs";
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import { configExports } from "@protobase/server";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { importProjectCode } from "./import-project-file.js";
|
|
2
|
-
import { uiDirs } from "./convention-files.js";
|
|
3
1
|
import { conventionConfig } from "./convention.js";
|
|
2
|
+
import { uiDirs } from "./convention-files.js";
|
|
3
|
+
import { importProjectCode } from "./import-project-file.js";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { configExports } from "@protobase/server";
|
|
6
6
|
//#region src/project/load-data-config.ts
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/project/placeholder-secret.ts
|
|
2
|
+
const placeholder = /^change-?me/i;
|
|
3
|
+
/**
|
|
4
|
+
* A warning when BETTER_AUTH_SECRET is still the placeholder of .env.example: whoever knows it can sign session
|
|
5
|
+
* cookies for the app. Undefined otherwise.
|
|
6
|
+
*/
|
|
7
|
+
const placeholderSecretWarning = (env) => env.BETTER_AUTH_SECRET && placeholder.test(env.BETTER_AUTH_SECRET) ? "BETTER_AUTH_SECRET is still the placeholder from .env.example, which signs session cookies anyone can forge; set it to the output of `openssl rand -base64 32`" : void 0;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { placeholderSecretWarning };
|
|
@@ -23,11 +23,13 @@ const describeField = (name, initializer) => {
|
|
|
23
23
|
let column;
|
|
24
24
|
let type;
|
|
25
25
|
let enumValues;
|
|
26
|
+
let sortable = false;
|
|
26
27
|
let node = initializer;
|
|
27
28
|
while (Node.isCallExpression(node)) {
|
|
28
29
|
const expression = node.getExpression();
|
|
29
30
|
if (!Node.isPropertyAccessExpression(expression)) break;
|
|
30
31
|
if (expression.getName() === "column") column ??= stringArg(node);
|
|
32
|
+
if (expression.getName() === "sortable") sortable = true;
|
|
31
33
|
if (expression.getExpression().getText() === "f") {
|
|
32
34
|
type = expression.getName();
|
|
33
35
|
const arg = node.getArguments()[0];
|
|
@@ -41,7 +43,8 @@ const describeField = (name, initializer) => {
|
|
|
41
43
|
column: column ?? defaultColumn(name),
|
|
42
44
|
ignored: false,
|
|
43
45
|
...type && { type },
|
|
44
|
-
...enumValues && { enumValues }
|
|
46
|
+
...enumValues && { enumValues },
|
|
47
|
+
...sortable && { sortable }
|
|
45
48
|
};
|
|
46
49
|
};
|
|
47
50
|
const fieldsObject = (root) => {
|
package/dist/scaffold/plan.js
CHANGED
|
@@ -41,18 +41,22 @@ const change = (file, before, after) => before === after ? [] : [{
|
|
|
41
41
|
}];
|
|
42
42
|
const planScaffold = async (input) => {
|
|
43
43
|
const { configDir, existing, ui } = input;
|
|
44
|
-
const skipped = protobaseSchemas(input.tables.filter((table) => matchesTarget(input.target, table)), input.target);
|
|
45
|
-
const isProtobase = (table) => skipped.some((schema) => schema.tables.includes(table));
|
|
46
|
-
const names = assignNames(input.tables.filter((table) => !isProtobase(table)), existing);
|
|
47
44
|
const byTable = new Map(existing.map((resource) => [resource.table, resource]));
|
|
45
|
+
const wanted = (table) => matchesTarget(input.target, table) && !isExcluded(input.excludes, table);
|
|
46
|
+
const tables = input.tables.filter((table) => table.kind === "table");
|
|
47
|
+
const skipped = protobaseSchemas(tables.filter((table) => matchesTarget(input.target, table)), input.target);
|
|
48
|
+
const isProtobase = (table) => skipped.some((schema) => schema.tables.includes(table));
|
|
49
|
+
const inProtobaseSchema = (view) => skipped.some(({ schema }) => schema === view.schema && schema !== "public");
|
|
50
|
+
const skippedViews = input.tables.filter((table) => table.kind !== "table" && wanted(table) && !byTable.has(tableKey(table)) && !inProtobaseSchema(table));
|
|
51
|
+
const names = assignNames(tables.filter((table) => !isProtobase(table)), existing);
|
|
48
52
|
const context = (table) => ({
|
|
49
53
|
table,
|
|
50
54
|
resourceNameOf: (schema, name) => names.get(`${schema}.${name}`) ?? name
|
|
51
55
|
});
|
|
52
|
-
const targets = dependencyOrder(
|
|
56
|
+
const targets = dependencyOrder(tables.filter((table) => wanted(table) && !isProtobase(table)));
|
|
53
57
|
const changes = [];
|
|
54
58
|
const drift = [];
|
|
55
|
-
const warnings =
|
|
59
|
+
const warnings = skippedViews.map((view) => `${tableKey(view)}: a ${view.kind}, skipped; scaffold writes resources over tables, declare one over a view by hand`);
|
|
56
60
|
const registrations = [];
|
|
57
61
|
const live = [];
|
|
58
62
|
const isLive = (key) => input.live?.includes(key) ?? false;
|
|
@@ -117,8 +121,8 @@ const planScaffold = async (input) => {
|
|
|
117
121
|
}
|
|
118
122
|
const indexFile = path.join(configDir, "index.ts");
|
|
119
123
|
const indexBefore = await input.readText(indexFile);
|
|
120
|
-
const
|
|
121
|
-
if (
|
|
124
|
+
const exports = [...indexBefore === void 0 ? await registerExisting(input, registrations) : [], ...registrations];
|
|
125
|
+
if (exports.length > 0 || indexBefore === void 0) changes.push(...change(indexFile, indexBefore, ensureExports(indexBefore ?? "", exports)));
|
|
122
126
|
return {
|
|
123
127
|
changes,
|
|
124
128
|
drift,
|
package/dist/scaffold/project.js
CHANGED
|
@@ -5,7 +5,8 @@ const project = new Project({
|
|
|
5
5
|
skipAddingFilesFromTsConfig: true,
|
|
6
6
|
manipulationSettings: {
|
|
7
7
|
indentationText: IndentationText.TwoSpaces,
|
|
8
|
-
quoteKind: QuoteKind.Single
|
|
8
|
+
quoteKind: QuoteKind.Single,
|
|
9
|
+
useTrailingCommas: true
|
|
9
10
|
}
|
|
10
11
|
});
|
|
11
12
|
const parseSource = (text, name = "source.ts") => project.createSourceFile(name, text, { overwrite: true });
|
package/dist/scaffold/prompt.js
CHANGED
|
@@ -45,18 +45,25 @@ const edit = async (proposal, ask) => {
|
|
|
45
45
|
name
|
|
46
46
|
}, ask);
|
|
47
47
|
};
|
|
48
|
-
const interactive = () => {
|
|
48
|
+
const interactive = (input = process.stdin, output = process.stdout) => {
|
|
49
49
|
const rl = createInterface({
|
|
50
|
-
input
|
|
51
|
-
output
|
|
50
|
+
input,
|
|
51
|
+
output
|
|
52
52
|
});
|
|
53
|
+
let acceptRest = false;
|
|
53
54
|
const decide = async (initial, { table, required }) => {
|
|
55
|
+
if (acceptRest) return initial;
|
|
54
56
|
let proposal = initial;
|
|
55
57
|
for (;;) {
|
|
56
|
-
|
|
57
|
-
const options = required ? "[a]ccept, [e]dit" : "[a]ccept, [e]dit, [i]gnore";
|
|
58
|
+
output.write(`\n${table}.${proposal.column}\n ${proposal.name}: ${renderField(proposal)}\n`);
|
|
59
|
+
const options = required ? "[a]ccept, accept a[l]l, [e]dit" : "[a]ccept, accept a[l]l, [e]dit, [i]gnore";
|
|
58
60
|
const answer = (await rl.question(` ${options} (a): `)).trim().toLowerCase() || "a";
|
|
59
61
|
if (answer === "a") return proposal;
|
|
62
|
+
if (answer === "l") {
|
|
63
|
+
acceptRest = true;
|
|
64
|
+
output.write(" accepting this and every remaining proposal\n");
|
|
65
|
+
return proposal;
|
|
66
|
+
}
|
|
60
67
|
if (answer === "e") proposal = await edit(proposal, (q) => rl.question(q));
|
|
61
68
|
if (answer === "i" && !required) return null;
|
|
62
69
|
}
|
package/dist/scaffold/run.js
CHANGED
|
@@ -24,7 +24,7 @@ const runScaffold = async (options, out) => {
|
|
|
24
24
|
const plan = await (async () => {
|
|
25
25
|
try {
|
|
26
26
|
return await planScaffold({
|
|
27
|
-
tables: await introspect(sql),
|
|
27
|
+
tables: await introspect(sql, { views: true }),
|
|
28
28
|
existing: await readExistingResources(options.configDir),
|
|
29
29
|
configDir: options.configDir,
|
|
30
30
|
target: parseTarget(options.target),
|
|
@@ -11,10 +11,12 @@ const uiFields = (table, existing, decisions) => {
|
|
|
11
11
|
const resolved = declared ? {
|
|
12
12
|
name: declared.name,
|
|
13
13
|
type: declared.type ?? "text",
|
|
14
|
+
sortable: declared.sortable ?? false,
|
|
14
15
|
ignored: declared.ignored
|
|
15
16
|
} : decided && {
|
|
16
17
|
name: decided.proposal.name,
|
|
17
18
|
type: decided.proposal.type,
|
|
19
|
+
sortable: decided.proposal.sortable,
|
|
18
20
|
ignored: decided.ignored
|
|
19
21
|
};
|
|
20
22
|
if (!resolved || resolved.ignored) return [];
|
|
@@ -22,6 +24,7 @@ const uiFields = (table, existing, decisions) => {
|
|
|
22
24
|
return [{
|
|
23
25
|
name: resolved.name,
|
|
24
26
|
type: resolved.type,
|
|
27
|
+
sortable: resolved.sortable,
|
|
25
28
|
role
|
|
26
29
|
}];
|
|
27
30
|
});
|
package/dist/scaffold/ui-file.js
CHANGED
|
@@ -4,6 +4,7 @@ import { methodCalls } from "./existing-config.js";
|
|
|
4
4
|
import { Node, SyntaxKind } from "ts-morph";
|
|
5
5
|
//#region src/scaffold/ui-file.ts
|
|
6
6
|
const auditField = /^(created|updated)(At|On|_at|_on)$/;
|
|
7
|
+
const createdField = /^(created|inserted)(At|On|_at|_on)$/;
|
|
7
8
|
const longText = /^(notes?|description|body|comment|comments)$/;
|
|
8
9
|
const listSize = 5;
|
|
9
10
|
const secretWords = /* @__PURE__ */ new Set([
|
|
@@ -21,17 +22,38 @@ const isSecretLike = (name) => {
|
|
|
21
22
|
const joined = words.join(" ");
|
|
22
23
|
return words.some((word) => secretWords.has(word)) || secretPairs.some((pair) => joined.includes(pair));
|
|
23
24
|
};
|
|
25
|
+
const relationsShown = 2;
|
|
26
|
+
/**
|
|
27
|
+
* The first useful fields: the key, unless it is a uuid nobody reads, then the records a record points at, such as an
|
|
28
|
+
* order line's order, then plain scalars, never a secret-like one. Without any of them, the key after all.
|
|
29
|
+
*/
|
|
24
30
|
const listColumns = (fields) => {
|
|
31
|
+
const keys = fields.filter((f) => f.role === "key" && f.type !== "uuid");
|
|
25
32
|
const plain = fields.filter((f) => f.role === "plain" && f.type !== "json" && !auditField.test(f.name) && !isSecretLike(f.name));
|
|
33
|
+
const relations = plain.filter((f) => f.type === "relation").slice(0, relationsShown);
|
|
26
34
|
const scalars = plain.filter((f) => f.type !== "relation" && !longText.test(f.name));
|
|
27
|
-
const
|
|
28
|
-
|
|
35
|
+
const picked = [
|
|
36
|
+
...keys,
|
|
37
|
+
...relations,
|
|
38
|
+
...scalars
|
|
39
|
+
].slice(0, listSize);
|
|
29
40
|
return (picked.length > 0 ? picked : fields.filter((f) => f.role === "key")).map((f) => f.name);
|
|
30
41
|
};
|
|
42
|
+
/**
|
|
43
|
+
* The newest records first, by the sortable date the records were created on, else by another sortable date. Without
|
|
44
|
+
* one the list keeps the API's order, by key.
|
|
45
|
+
*/
|
|
46
|
+
const listSort = (fields) => {
|
|
47
|
+
const dates = fields.filter((f) => f.sortable && (f.type === "timestamp" || f.type === "date"));
|
|
48
|
+
return (dates.find((f) => createdField.test(f.name)) ?? dates[0])?.name;
|
|
49
|
+
};
|
|
31
50
|
const viewName = (identifier) => `${identifier}View`;
|
|
32
51
|
const sectionText = {
|
|
33
52
|
names: (t) => `.names({ singular: '${humanizeSingular(t.tableName)}', plural: '${humanize(t.tableName)}' })`,
|
|
34
|
-
list: (t) =>
|
|
53
|
+
list: (t) => {
|
|
54
|
+
const sort = listSort(t.fields);
|
|
55
|
+
return `.list((r) => ({ columns: [${listColumns(t.fields).map((n) => `r.${n}`).join(", ")}]${sort ? `, sort: [[r.${sort}, 'desc']]` : ""} }))`;
|
|
56
|
+
}
|
|
35
57
|
};
|
|
36
58
|
const lines = (sections, target) => sections.map((s) => ` ${sectionText[s](target)}`);
|
|
37
59
|
const renderUiFile = (target, sections) => [
|
|
@@ -52,4 +74,4 @@ const addUiSections = (text, target, sections) => {
|
|
|
52
74
|
return source.getFullText();
|
|
53
75
|
};
|
|
54
76
|
//#endregion
|
|
55
|
-
export { addUiSections, isSecretLike, listColumns, renderUiFile, viewName };
|
|
77
|
+
export { addUiSections, isSecretLike, listColumns, listSort, renderUiFile, viewName };
|
package/dist/serve/app.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isApiPath } from "../bundle/manifest.js";
|
|
2
2
|
import { serveStaticSite } from "./static-site.js";
|
|
3
|
-
import { jobsDrainApp, mobileReleaseApp, webauthnPath } from "@protobase/server";
|
|
4
3
|
import { Hono } from "hono";
|
|
4
|
+
import { jobsDrainApp, mobileReleaseApp, webauthnPath } from "@protobase/server";
|
|
5
5
|
import { logger } from "hono/logger";
|
|
6
6
|
//#region src/serve/app.ts
|
|
7
7
|
const createServeApp = ({ admin, requestLog, site, jobs, drainToken, mobile }) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { manifestFile } from "../bundle/manifest.js";
|
|
2
1
|
import { protobaseVersion } from "../version/version.js";
|
|
2
|
+
import { manifestFile } from "../bundle/manifest.js";
|
|
3
3
|
import { bundleVersionProblem } from "../version/compatibility.js";
|
|
4
4
|
import { existsSync } from "node:fs";
|
|
5
5
|
import path from "node:path";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { checkBundleVersion } from "./bundle-version.js";
|
|
2
|
-
import { loadBundle } from "./load-bundle.js";
|
|
3
|
-
import { bundleConfigFile } from "../worker/start-worker.js";
|
|
4
1
|
import { readHidden } from "../users/password.js";
|
|
5
2
|
import { createUserCommand } from "../users/commands.js";
|
|
6
3
|
import { usersApi } from "../users/users-api.js";
|
|
4
|
+
import { checkBundleVersion } from "./bundle-version.js";
|
|
5
|
+
import { loadBundle } from "./load-bundle.js";
|
|
6
|
+
import { bundleConfigFile } from "../worker/start-worker.js";
|
|
7
7
|
import { checkAuthSchema } from "@protobase/server";
|
|
8
8
|
//#region src/serve/create-admin.ts
|
|
9
9
|
const createAdminInBundle = async (bundle, email, options, out) => {
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import * as server from "@protobase/server";
|
|
2
1
|
import * as postgres$1 from "postgres";
|
|
3
2
|
import * as nodeServer from "@hono/node-server";
|
|
4
|
-
import * as
|
|
3
|
+
import * as hono from "hono";
|
|
4
|
+
import * as server from "@protobase/server";
|
|
5
5
|
import * as kysely from "kysely";
|
|
6
6
|
import * as pg$1 from "pg";
|
|
7
|
-
import * as schema from "@protobase/schema";
|
|
8
|
-
import * as layout from "@protobase/layout";
|
|
9
|
-
import * as hono from "hono";
|
|
10
7
|
import * as reactEmailRender from "@react-email/render";
|
|
11
8
|
import * as apiReference from "@scalar/hono-api-reference";
|
|
12
9
|
import * as aipParsers from "aip-parsers";
|
|
@@ -19,6 +16,9 @@ import * as kyselyPostgres from "kysely/helpers/postgres";
|
|
|
19
16
|
import * as react from "react";
|
|
20
17
|
import * as reactJsxRuntime from "react/jsx-runtime";
|
|
21
18
|
import * as zod from "zod";
|
|
19
|
+
import * as layout from "@protobase/layout";
|
|
20
|
+
import * as query from "@protobase/query";
|
|
21
|
+
import * as schema from "@protobase/schema";
|
|
22
22
|
//#region src/serve/host-modules.ts
|
|
23
23
|
const hostModules = {
|
|
24
24
|
"@protobase/schema": schema,
|
package/dist/serve/lifecycle.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { protobaseVersion } from "../version/version.js";
|
|
2
|
-
import { apiWebSocketServer } from "../project/api-websocket-server.js";
|
|
3
|
-
import { withClientAddress } from "./client-address.js";
|
|
4
2
|
import { projectAdmin } from "../project/project-admin.js";
|
|
5
3
|
import { createPgDb } from "../project/pg-db.js";
|
|
4
|
+
import { withClientAddress } from "./client-address.js";
|
|
5
|
+
import { apiWebSocketServer } from "../project/api-websocket-server.js";
|
|
6
6
|
import { createServeApp } from "./app.js";
|
|
7
7
|
import { startCleanupTimer } from "./cleanup-timer.js";
|
|
8
8
|
import { closeSockets } from "./close-sockets.js";
|
|
9
9
|
import { servedRelease } from "./mobile-release.js";
|
|
10
|
-
import { assistantSettings, authStoreTables, backgroundSettled, checkAi, checkAuthSchema, checkChanges, checkComments, checkComputed, checkJobsSchema, checkNotificationsSchema, checkQueryRunner, checkWebhooksSchema, configExports, createFileCleanup, startJobs } from "@protobase/server";
|
|
11
10
|
import { createAdaptorServer, upgradeWebSocket } from "@hono/node-server";
|
|
11
|
+
import { assistantSettings, authStoreTables, backgroundSettled, checkAi, checkAuthSchema, checkChanges, checkComments, checkComputed, checkJobsSchema, checkNotificationsSchema, checkQueryRunner, checkWebhooksSchema, configExports, createFileCleanup, startJobs } from "@protobase/server";
|
|
12
12
|
import pg from "pg";
|
|
13
13
|
//#region src/serve/lifecycle.ts
|
|
14
14
|
const listen = (server, port) => new Promise((resolve, reject) => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { nativeFingerprint } from "../mobile/fingerprint.js";
|
|
2
2
|
import { withApiOrigin } from "../mobile/api-origin-page.js";
|
|
3
3
|
import { siteFiles } from "./site-files.js";
|
|
4
|
-
import { composeRelease } from "@protobase/server";
|
|
5
4
|
import { readFile } from "node:fs/promises";
|
|
5
|
+
import { composeRelease } from "@protobase/server";
|
|
6
6
|
//#region src/serve/mobile-release.ts
|
|
7
7
|
const loopback = [
|
|
8
8
|
"localhost",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readManifest } from "../bundle/manifest.js";
|
|
2
|
-
import { serveBundle } from "./serve-bundle.js";
|
|
3
2
|
import { bundleSite } from "./bundle-site.js";
|
|
3
|
+
import { serveBundle } from "./serve-bundle.js";
|
|
4
4
|
import { statSync } from "node:fs";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
//#region src/serve/serve-bundle-path.ts
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { readManifest } from "../bundle/manifest.js";
|
|
2
1
|
import { projectErrorReporter } from "../project/error-reporter.js";
|
|
3
|
-
import {
|
|
2
|
+
import { readManifest } from "../bundle/manifest.js";
|
|
4
3
|
import { checkBundleVersion } from "./bundle-version.js";
|
|
4
|
+
import { loadBundle } from "./load-bundle.js";
|
|
5
|
+
import { bundleUi } from "./bundle-ui.js";
|
|
5
6
|
import { reportCrashes } from "./crash-reports.js";
|
|
6
7
|
import { readServeEnv } from "./env.js";
|
|
7
8
|
import { startServe } from "./lifecycle.js";
|
|
8
|
-
import { loadBundle } from "./load-bundle.js";
|
|
9
9
|
import { closeOnSignals } from "./signals.js";
|
|
10
10
|
import path from "node:path";
|
|
11
11
|
//#region src/serve/serve-bundle.ts
|
package/dist/serve/serve-dir.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { readManifest } from "../bundle/manifest.js";
|
|
2
|
+
import { bundleSite } from "./bundle-site.js";
|
|
3
|
+
import { serveBundle } from "./serve-bundle.js";
|
|
2
4
|
import { installedShellDir } from "../build/shell.js";
|
|
3
5
|
import { pinnedNative } from "../mobile/pinned-packages.js";
|
|
4
|
-
import { serveBundle } from "./serve-bundle.js";
|
|
5
|
-
import { bundleSite } from "./bundle-site.js";
|
|
6
6
|
import { servedShell, shellVariable } from "./served-shell.js";
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
//#region src/serve/serve-dir.ts
|
|
@@ -17,9 +17,9 @@ import { ensureApiRoles, existingSchemas, existingTables } from "./target-checks
|
|
|
17
17
|
import { creatableExtensions } from "./target-extensions.js";
|
|
18
18
|
import { usersColumnsMigration } from "./users-migrations.js";
|
|
19
19
|
import path from "node:path";
|
|
20
|
-
import { isSchedule } from "@protobase/server";
|
|
21
|
-
import { mkdir, readFile, rm } from "node:fs/promises";
|
|
22
20
|
import postgres from "postgres";
|
|
21
|
+
import { mkdir, readFile, rm } from "node:fs/promises";
|
|
22
|
+
import { isSchedule } from "@protobase/server";
|
|
23
23
|
//#region src/supabase/dump-phase.ts
|
|
24
24
|
/** Fails unless the database at `sql` is Supabase's: its auth and storage schemas, and its own admin role. */
|
|
25
25
|
const checkSupabase = async (sql) => {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { loadProjectAuth } from "../users/load-auth.js";
|
|
2
|
-
import { writeAuthMigration } from "../auth/write-migration.js";
|
|
3
1
|
import { connect } from "../db/connect.js";
|
|
2
|
+
import { writeAuthMigration } from "../auth/write-migration.js";
|
|
4
3
|
import { runDoctor } from "../doctor/run.js";
|
|
5
4
|
import { runScaffold } from "../scaffold/run.js";
|
|
6
5
|
import { convertedCronJobs } from "./cron-plan.js";
|
|
@@ -11,6 +10,7 @@ import { loadScript, qualified } from "./load-script.js";
|
|
|
11
10
|
import { existingTables, filledTables, otherTables } from "./target-checks.js";
|
|
12
11
|
import { providerCounts } from "./identity-providers.js";
|
|
13
12
|
import { accountsMigration } from "./users-migrations.js";
|
|
13
|
+
import { loadProjectAuth } from "../users/load-auth.js";
|
|
14
14
|
import { cronJobFilesInTheWay, writeCronJobs } from "./cron-jobs-write.js";
|
|
15
15
|
import { importReport } from "./report.js";
|
|
16
16
|
import { existsSync } from "node:fs";
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { loadNearestEnvFile } from "../dev/env.js";
|
|
2
|
-
import { runSupabaseImport } from "./run.js";
|
|
3
2
|
import path from "node:path";
|
|
4
3
|
//#region src/supabase/register.ts
|
|
5
4
|
const out = (text) => process.stdout.write(text);
|
|
@@ -19,6 +18,7 @@ const registerImport = (program) => {
|
|
|
19
18
|
if (source && opts.sourceEnv) throw new Error("Pass either a connection string or --source-env, not both");
|
|
20
19
|
const projectDir = process.cwd();
|
|
21
20
|
loadNearestEnvFile(projectDir);
|
|
21
|
+
const { runSupabaseImport } = await import("./run.js");
|
|
22
22
|
await runSupabaseImport({
|
|
23
23
|
sourceUrl: source ?? (opts.sourceEnv ? variable(opts.sourceEnv) : void 0),
|
|
24
24
|
targetUrl: variable(opts.env),
|
|
@@ -9,8 +9,8 @@ import { storageObjects } from "./storage-objects.js";
|
|
|
9
9
|
import { bucketLines, megabytes, objectCount, overQuota, totalBytes } from "./storage-sizes.js";
|
|
10
10
|
import { storageReport } from "./storage-report.js";
|
|
11
11
|
import path from "node:path";
|
|
12
|
-
import { objectKey, storageProvider, storeUsage } from "@protobase/server";
|
|
13
12
|
import { writeFile } from "node:fs/promises";
|
|
13
|
+
import { objectKey, storageProvider, storeUsage } from "@protobase/server";
|
|
14
14
|
//#region src/supabase/storage-phase.ts
|
|
15
15
|
/** Objects copied at once: enough to keep a connection busy, few enough for any host. */
|
|
16
16
|
const parallel = 4;
|
package/dist/users/commands.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { resolvePassword } from "./password.js";
|
|
2
2
|
//#region src/users/commands.ts
|
|
3
3
|
const githubId = /^[1-9][0-9]*$/;
|
|
4
|
+
const shownAs = (role, labels) => {
|
|
5
|
+
const names = role.split(",");
|
|
6
|
+
const shown = names.map((name) => labels[name] ?? name);
|
|
7
|
+
return shown.some((label, index) => label.toLowerCase() !== names[index].toLowerCase()) ? `, shown in the app as ${shown.join(", ")}` : "";
|
|
8
|
+
};
|
|
4
9
|
const createUserCommand = async (api, options, deps, out) => {
|
|
5
10
|
if (!options.email.includes("@")) throw new Error(`"${options.email}" is not an email address`);
|
|
6
11
|
if (options.githubId !== void 0 && !githubId.test(options.githubId)) throw new Error(`"${options.githubId}" is not a GitHub user id, a number such as 583231`);
|
|
@@ -16,7 +21,8 @@ const createUserCommand = async (api, options, deps, out) => {
|
|
|
16
21
|
accountId: options.githubId
|
|
17
22
|
}] }
|
|
18
23
|
});
|
|
19
|
-
|
|
24
|
+
const { labels } = await api.roles();
|
|
25
|
+
out(`Created ${user.role} ${user.email}${shownAs(user.role, labels)}${options.githubId ? `, linked to GitHub user ${options.githubId}` : ""}\n`);
|
|
20
26
|
if (generated) out(`Password (shown once): ${password}\n`);
|
|
21
27
|
};
|
|
22
28
|
const listUsersCommand = async (api, out) => {
|
package/dist/users/register.js
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
import { loadProjectAuth } from "./load-auth.js";
|
|
2
1
|
import { addMemberCommand } from "../organizations/commands.js";
|
|
3
|
-
import { organizationsApi } from "../organizations/register.js";
|
|
4
|
-
import { readHidden, rejectPasswordArgument } from "./password.js";
|
|
5
|
-
import { createUserCommand, listRolesCommand, listUsersCommand } from "./commands.js";
|
|
6
2
|
import { deleteUserCommand, setRoleCommand } from "./manage.js";
|
|
7
|
-
import { usersApi } from "./users-api.js";
|
|
8
|
-
import { setDisabledInProject } from "./set-disabled.js";
|
|
9
3
|
import { parseTtl } from "./ttl.js";
|
|
10
4
|
import { Option } from "commander";
|
|
11
|
-
import { issueToken } from "@protobase/server";
|
|
12
5
|
import { createInterface } from "node:readline/promises";
|
|
13
6
|
//#region src/users/register.ts
|
|
14
7
|
const out = (text) => process.stdout.write(text);
|
|
15
|
-
const
|
|
8
|
+
const loadAuth = async () => (await import("./load-auth.js")).loadProjectAuth(process.cwd());
|
|
9
|
+
const projectApi = async () => {
|
|
10
|
+
const [{ usersApi }, auth] = await Promise.all([import("./users-api.js"), loadAuth()]);
|
|
11
|
+
return usersApi(auth);
|
|
12
|
+
};
|
|
16
13
|
const ask = async (question) => {
|
|
17
14
|
if (!process.stdin.isTTY) throw new Error("Confirmation needs a terminal; pass --yes to skip it");
|
|
18
15
|
const rl = createInterface({
|
|
@@ -27,8 +24,14 @@ const finish = (code) => process.exit(code);
|
|
|
27
24
|
const registerUsers = (program) => {
|
|
28
25
|
const users = program.command("users").description("Manage the admin users of the project in the current directory");
|
|
29
26
|
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
|
+
const { readHidden, rejectPasswordArgument } = await import("./password.js");
|
|
30
28
|
rejectPasswordArgument(opts.password);
|
|
31
|
-
const auth = await
|
|
29
|
+
const [{ createUserCommand }, { usersApi }, { organizationsApi }, auth] = await Promise.all([
|
|
30
|
+
import("./commands.js"),
|
|
31
|
+
import("./users-api.js"),
|
|
32
|
+
import("../organizations/api.js"),
|
|
33
|
+
loadAuth()
|
|
34
|
+
]);
|
|
32
35
|
await createUserCommand(usersApi(auth), {
|
|
33
36
|
email,
|
|
34
37
|
name: opts.name,
|
|
@@ -64,17 +67,20 @@ const registerUsers = (program) => {
|
|
|
64
67
|
finish(0);
|
|
65
68
|
});
|
|
66
69
|
for (const disabled of [true, false]) users.command(disabled ? "disable" : "enable").description(disabled ? "Ban a user and revoke their sessions" : "Lift a ban").argument("<email>").action(async (email) => {
|
|
67
|
-
|
|
70
|
+
const { setDisabledInProject } = await import("./set-disabled.js");
|
|
71
|
+
await setDisabledInProject(await loadAuth(), {
|
|
68
72
|
email,
|
|
69
73
|
disabled
|
|
70
74
|
}, out);
|
|
71
75
|
finish(0);
|
|
72
76
|
});
|
|
73
77
|
users.command("roles").description("List the roles of the project (the first is admin)").action(async () => {
|
|
78
|
+
const { listRolesCommand } = await import("./commands.js");
|
|
74
79
|
await listRolesCommand(await projectApi(), out);
|
|
75
80
|
finish(0);
|
|
76
81
|
});
|
|
77
82
|
users.command("list").description("List users: email, role, creation date").action(async () => {
|
|
83
|
+
const { listUsersCommand } = await import("./commands.js");
|
|
78
84
|
await listUsersCommand(await projectApi(), out);
|
|
79
85
|
finish(0);
|
|
80
86
|
});
|
|
@@ -82,7 +88,7 @@ const registerUsers = (program) => {
|
|
|
82
88
|
const registerToken = (program) => {
|
|
83
89
|
program.command("token").description("Print a bearer token (JWT) for an existing user").argument("<email>").option("--ttl <duration>", "lifetime: 30s, 15m, up to 24h", "15m").action(async (email, opts) => {
|
|
84
90
|
const ttlSeconds = parseTtl(opts.ttl);
|
|
85
|
-
const auth = await
|
|
91
|
+
const [{ issueToken }, auth] = await Promise.all([import("@protobase/server"), loadAuth()]);
|
|
86
92
|
const { token } = await issueToken(auth, {
|
|
87
93
|
email,
|
|
88
94
|
ttlSeconds
|
package/dist/users/users-api.js
CHANGED
|
@@ -4,7 +4,8 @@ const usersApi = (auth) => ({
|
|
|
4
4
|
hasUsers: () => hasUsers(auth),
|
|
5
5
|
roles: async () => ({
|
|
6
6
|
roles: roleChoices(auth),
|
|
7
|
-
defaultRole: auth.defaultRole
|
|
7
|
+
defaultRole: auth.defaultRole,
|
|
8
|
+
labels: auth.roleDefinitions.labels
|
|
8
9
|
}),
|
|
9
10
|
createUser: (input) => createUser(auth, input),
|
|
10
11
|
listUsers: () => listUsers(auth),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { readManifest } from "../bundle/manifest.js";
|
|
2
|
-
import { checkBundleVersion } from "../serve/bundle-version.js";
|
|
3
1
|
import { projectAdmin } from "../project/project-admin.js";
|
|
4
2
|
import { createPgDb } from "../project/pg-db.js";
|
|
3
|
+
import { readManifest } from "../bundle/manifest.js";
|
|
4
|
+
import { checkBundleVersion } from "../serve/bundle-version.js";
|
|
5
5
|
import { loadBundle } from "../serve/load-bundle.js";
|
|
6
6
|
import { statSync } from "node:fs";
|
|
7
7
|
import path from "node:path";
|