@protobase/cli 0.21.8 → 0.21.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/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
|
|
@@ -23,8 +23,13 @@ const loadMigrationProject = async (dir, extensions = []) => {
|
|
|
23
23
|
config: custom.config ?? await importProjectFile(index)
|
|
24
24
|
};
|
|
25
25
|
const extended = await Promise.all(extensions.flatMap((extension) => extension.config ? [configOf(extension.config)] : []));
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
return migrationProject(mergeConfig(...extended, own), process.env.DATABASE_URL);
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* A merged project config, for what its database needs: its resources' models, its database (the one it exports, or a
|
|
30
|
+
* pool on `url`) and the features that write migrations. `close` ends the pool it opened.
|
|
31
|
+
*/
|
|
32
|
+
const migrationProject = (project, url) => {
|
|
28
33
|
if (!project.db && !url) throw new Error("No database: set DATABASE_URL or export `db` from protobase.config.ts");
|
|
29
34
|
const ownDb = project.db ? void 0 : createPgDb(pg, url);
|
|
30
35
|
return {
|
|
@@ -40,4 +45,4 @@ const loadMigrationProject = async (dir, extensions = []) => {
|
|
|
40
45
|
};
|
|
41
46
|
};
|
|
42
47
|
//#endregion
|
|
43
|
-
export { loadMigrationProject };
|
|
48
|
+
export { loadMigrationProject, migrationProject };
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.21.
|
|
3
|
+
"version": "0.21.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": {
|
|
@@ -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.10",
|
|
38
|
+
"@protobase/query": "0.21.10",
|
|
39
|
+
"@protobase/schema": "0.21.10",
|
|
40
|
+
"@protobase/server": "0.21.10",
|
|
41
|
+
"@protobase/ui": "0.21.10",
|
|
42
42
|
"@react-email/render": "^2.1.0",
|
|
43
43
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
44
44
|
"@tailwindcss/vite": "^4.3.3",
|