@protobase/cli 0.46.9 → 0.46.10
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/entry-code.js +2 -1
- package/dist/build/export-order.js +52 -0
- package/dist/cli/package.js +1 -1
- package/dist/project/convention.js +3 -2
- package/dist/scaffold/plan.js +2 -1
- package/dist/scaffold/table-order.js +26 -0
- package/package.json +6 -6
- package/skills/protobase/references/reference/cli.md +1 -1
- package/skills/protobase/references/reference/sidebar.md +1 -1
package/dist/build/entry-code.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { moduleFile } from "../module-file.js";
|
|
2
|
+
import { exportOrder } from "./export-order.js";
|
|
2
3
|
import { uiDirs } from "../project/convention-files.js";
|
|
3
4
|
import { functionFiles } from "../project/functions-folder.js";
|
|
4
5
|
import { existsSync } from "node:fs";
|
|
@@ -15,7 +16,7 @@ const bundleEntryCode = (projectDir, extensions = []) => {
|
|
|
15
16
|
const lines = hasCustom ? [`import * as custom from ${JSON.stringify(custom)}`, "const project = custom.default ?? {}"] : ["const project = {}"];
|
|
16
17
|
if (hasIndex) {
|
|
17
18
|
const dirs = uiDirs(configDir);
|
|
18
|
-
lines.push(`import { conventionConfig } from ${JSON.stringify(conventionModule)}`, `import * as index from ${JSON.stringify(index)}`, ...dirs.map((dir, i) => `import * as ui${i} from ${JSON.stringify(path.join(configDir, dir, "ui.ts"))}`), `const convention = conventionConfig(index, [${dirs.map((dir, i) => `[${JSON.stringify(dir)}, ui${i}]`).join(", ")}])`);
|
|
19
|
+
lines.push(`import { conventionConfig } from ${JSON.stringify(conventionModule)}`, `import * as index from ${JSON.stringify(index)}`, ...dirs.map((dir, i) => `import * as ui${i} from ${JSON.stringify(path.join(configDir, dir, "ui.ts"))}`), `const convention = conventionConfig(index, [${dirs.map((dir, i) => `[${JSON.stringify(dir)}, ui${i}]`).join(", ")}], ${JSON.stringify(exportOrder(index))})`);
|
|
19
20
|
} else lines.push("const convention = undefined");
|
|
20
21
|
const functions = functionFiles(projectDir);
|
|
21
22
|
lines.push(...functions.map(({ file }, i) => `import * as function${i} from ${JSON.stringify(file)}`), `const functions = ${functions.length === 0 ? "undefined" : `{ ${functions.map(({ name }, i) => `${JSON.stringify(name)}: function${i}.default`).join(", ")} }`}`);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { parseSync } from "vite";
|
|
4
|
+
//#region src/build/export-order.ts
|
|
5
|
+
const extensions = [
|
|
6
|
+
"",
|
|
7
|
+
".ts",
|
|
8
|
+
".tsx",
|
|
9
|
+
".mts",
|
|
10
|
+
".js",
|
|
11
|
+
".mjs",
|
|
12
|
+
"/index.ts",
|
|
13
|
+
"/index.js"
|
|
14
|
+
];
|
|
15
|
+
const resolveRelative = (from, specifier) => {
|
|
16
|
+
const base = path.resolve(path.dirname(from), specifier);
|
|
17
|
+
const bases = /\.m?js$/.test(base) ? [base, base.replace(/\.(m?)js$/, ".$1ts")] : [base];
|
|
18
|
+
for (const candidate of bases.flatMap((each) => extensions.map((extension) => each + extension))) if (existsSync(candidate) && statSync(candidate).isFile()) return candidate;
|
|
19
|
+
};
|
|
20
|
+
const exportName = (name) => name.type === "Literal" ? String(name.value) : name.name;
|
|
21
|
+
const declaredNames = (declaration) => {
|
|
22
|
+
if (declaration.type === "VariableDeclaration") return declaration.declarations.flatMap((each) => each.id.type === "Identifier" ? [each.id.name] : []);
|
|
23
|
+
if ((declaration.type === "FunctionDeclaration" || declaration.type === "ClassDeclaration") && declaration.id) return [declaration.id.name];
|
|
24
|
+
return [];
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* The names a module exports, in the order its source declares them, following relative `export * from` into the
|
|
28
|
+
* modules they name. A bundle's `import * as` namespace sorts its names; this is the order `protobase dev` keeps.
|
|
29
|
+
* Names it cannot see, such as those of a package's `export *`, are left out.
|
|
30
|
+
*/
|
|
31
|
+
const exportOrder = (file, seen = /* @__PURE__ */ new Set()) => {
|
|
32
|
+
if (seen.has(file)) return [];
|
|
33
|
+
seen.add(file);
|
|
34
|
+
const { program } = parseSync(file, readFileSync(file, "utf8"));
|
|
35
|
+
const names = program.body.flatMap((statement) => {
|
|
36
|
+
if (statement.type === "ExportNamedDeclaration") {
|
|
37
|
+
if (statement.exportKind === "type") return [];
|
|
38
|
+
if (statement.declaration) return declaredNames(statement.declaration);
|
|
39
|
+
return statement.specifiers.filter((specifier) => specifier.exportKind !== "type").map((specifier) => exportName(specifier.exported));
|
|
40
|
+
}
|
|
41
|
+
if (statement.type === "ExportAllDeclaration") {
|
|
42
|
+
if (statement.exportKind === "type") return [];
|
|
43
|
+
if (statement.exported) return [exportName(statement.exported)];
|
|
44
|
+
const target = statement.source.value.startsWith(".") ? resolveRelative(file, statement.source.value) : void 0;
|
|
45
|
+
return target ? exportOrder(target, seen).filter((name) => name !== "default") : [];
|
|
46
|
+
}
|
|
47
|
+
return [];
|
|
48
|
+
});
|
|
49
|
+
return [...new Set(names)];
|
|
50
|
+
};
|
|
51
|
+
//#endregion
|
|
52
|
+
export { exportOrder };
|
package/dist/cli/package.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
//#region src/project/convention.ts
|
|
2
|
-
const conventionConfig = (index, uiModules) => {
|
|
3
|
-
const config =
|
|
2
|
+
const conventionConfig = (index, uiModules, order = []) => {
|
|
3
|
+
const config = Object.fromEntries(order.filter((name) => Object.hasOwn(index, name)).map((name) => [name, index[name]]));
|
|
4
|
+
Object.assign(config, index);
|
|
4
5
|
for (const [dir, exports] of uiModules) for (const [key, value] of Object.entries(exports)) if (!Object.values(config).includes(value)) config[`${dir}:${key}`] = value;
|
|
5
6
|
return config;
|
|
6
7
|
};
|
package/dist/scaffold/plan.js
CHANGED
|
@@ -8,6 +8,7 @@ import { detectDrift } from "./drift.js";
|
|
|
8
8
|
import { ensureExports } from "./index-file.js";
|
|
9
9
|
import { assignNames } from "./resource-names.js";
|
|
10
10
|
import { planResource } from "./resource-plan.js";
|
|
11
|
+
import { dependencyOrder } from "./table-order.js";
|
|
11
12
|
import { isExcluded, matchesTarget } from "./targets.js";
|
|
12
13
|
import { uiFields } from "./ui-fields.js";
|
|
13
14
|
import { addUiSections, renderUiFile, viewName } from "./ui-file.js";
|
|
@@ -45,7 +46,7 @@ const planScaffold = async (input) => {
|
|
|
45
46
|
table,
|
|
46
47
|
resourceNameOf: (schema, name) => names.get(`${schema}.${name}`) ?? name
|
|
47
48
|
});
|
|
48
|
-
const targets = input.tables.filter((table) => matchesTarget(input.target, table) && !isExcluded(input.excludes, table))
|
|
49
|
+
const targets = dependencyOrder(input.tables.filter((table) => matchesTarget(input.target, table) && !isExcluded(input.excludes, table)));
|
|
49
50
|
const changes = [];
|
|
50
51
|
const drift = [];
|
|
51
52
|
const warnings = [];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { tableKey } from "../db/model.js";
|
|
2
|
+
//#region src/scaffold/table-order.ts
|
|
3
|
+
/**
|
|
4
|
+
* The tables in the order their resources are registered in config/index.ts, which is the sidebar's and so the table
|
|
5
|
+
* the app opens on: each after the tables its foreign keys point to, otherwise by name. A cycle of foreign keys is
|
|
6
|
+
* broken where the walk by name first meets it.
|
|
7
|
+
*/
|
|
8
|
+
const dependencyOrder = (tables) => {
|
|
9
|
+
const byKey = new Map([...tables].sort((a, b) => tableKey(a).localeCompare(tableKey(b))).map((table) => [tableKey(table), table]));
|
|
10
|
+
const ordered = [];
|
|
11
|
+
const visited = /* @__PURE__ */ new Set();
|
|
12
|
+
const visit = (key) => {
|
|
13
|
+
const table = byKey.get(key);
|
|
14
|
+
if (!table || visited.has(key)) return;
|
|
15
|
+
visited.add(key);
|
|
16
|
+
for (const foreignKey of table.foreignKeys) visit(tableKey({
|
|
17
|
+
schema: foreignKey.refSchema,
|
|
18
|
+
name: foreignKey.refTable
|
|
19
|
+
}));
|
|
20
|
+
ordered.push(table);
|
|
21
|
+
};
|
|
22
|
+
for (const key of byKey.keys()) visit(key);
|
|
23
|
+
return ordered;
|
|
24
|
+
};
|
|
25
|
+
//#endregion
|
|
26
|
+
export { dependencyOrder };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.46.
|
|
3
|
+
"version": "0.46.10",
|
|
4
4
|
"description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"@better-auth/core": "^1.7.12",
|
|
37
37
|
"@hono/node-server": "^2.1.3",
|
|
38
38
|
"@hono/vite-dev-server": "^0.26.1",
|
|
39
|
-
"@protobase/layout": "0.46.
|
|
40
|
-
"@protobase/query": "0.46.
|
|
41
|
-
"@protobase/schema": "0.46.
|
|
42
|
-
"@protobase/server": "0.46.
|
|
43
|
-
"@protobase/ui": "0.46.
|
|
39
|
+
"@protobase/layout": "0.46.10",
|
|
40
|
+
"@protobase/query": "0.46.10",
|
|
41
|
+
"@protobase/schema": "0.46.10",
|
|
42
|
+
"@protobase/server": "0.46.10",
|
|
43
|
+
"@protobase/ui": "0.46.10",
|
|
44
44
|
"@react-email/render": "^2.1.0",
|
|
45
45
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
46
46
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -67,7 +67,7 @@ Interactively, each new column shows its proposal: accept, edit (name, type) or
|
|
|
67
67
|
|
|
68
68
|
### Re-running
|
|
69
69
|
|
|
70
|
-
Existing `data.ts` files are edited with ts-morph: only columns that are neither declared nor `null` are added, at the end of `.fields({...})`. Nothing else is rewritten, and key, soft delete and tenant calls are only written when a resource is created. `ui.ts` gets only missing sections. `config/index.ts` gets exports for resources created in the run (all resources when it does not exist yet); existing lines are never touched. A run with nothing new changes nothing. `schema.table.column` on an unscaffolded table scaffolds the whole table.
|
|
70
|
+
Existing `data.ts` files are edited with ts-morph: only columns that are neither declared nor `null` are added, at the end of `.fields({...})`. Nothing else is rewritten, and key, soft delete and tenant calls are only written when a resource is created. `ui.ts` gets only missing sections. `config/index.ts` gets exports for resources created in the run (all resources when it does not exist yet), each table after the tables its foreign keys point to and otherwise by name, so the sidebar, and the table the app opens on, start with tables others refer to; existing lines are never touched. A run with nothing new changes nothing. `schema.table.column` on an unscaffolded table scaffolds the whole table.
|
|
71
71
|
|
|
72
72
|
### Drift report
|
|
73
73
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
How sidebar entries are grouped, and how an entry lists recent records with status dots.
|
|
6
6
|
|
|
7
|
-
The admin's sidebar has one entry per resource view, grouped by `nav.group` (default: the database schema) and sorted by `nav.order
|
|
7
|
+
The admin's sidebar has one entry per resource view, grouped by `nav.group` (default: the database schema, with no group name for `public`) and sorted by `nav.order`, then by the order `config/index.ts` exports them, in `protobase dev` and in a built bundle alike. The app opens on the first entry. A view's [named lists](ui-config.md#more-than-one-list) are entries of their own, placed by their own `nav`. `nav({ hidden: true })` leaves a resource out, for line and link tables; a resource in the [user menu](user-menu.md) is left out too. [Composed pages](layouts.md#setup) have entries of their own, and groups that hold pages come first. A [remote resource](remote-resources.md) has its entry where its source's view places it; while its source cannot be reached, it sits under the source's label, marked "Cannot reach" with the source's name.
|
|
8
8
|
|
|
9
9
|
## The current organization
|
|
10
10
|
|