@devmoods/postgres-admin 0.3.0 → 0.5.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/client/_index.html +4 -3
- package/dist/client/assets/{index-BQSpf7B-.css → index-CsmHBa6X.css} +1 -1
- package/dist/client/assets/index-ssRqNbar.js +78 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.js +12 -11
- package/package.json +13 -12
- package/dist/client/assets/index-DxUnu_VS.js +0 -78
package/dist/index.d.ts
CHANGED
|
@@ -2,10 +2,14 @@ import * as express_serve_static_core from 'express-serve-static-core';
|
|
|
2
2
|
import { createPostgres } from '@devmoods/express-extras';
|
|
3
3
|
|
|
4
4
|
interface AdminRouterOptions {
|
|
5
|
-
postgres
|
|
5
|
+
postgres?: ReturnType<typeof createPostgres>;
|
|
6
6
|
basename?: string;
|
|
7
|
+
uiOptions?: AdminUIOptions;
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
+
interface AdminUIOptions {
|
|
10
|
+
title?: string;
|
|
11
|
+
}
|
|
12
|
+
declare function createRouter({ postgres: defaultPostgres, basename, uiOptions, }: AdminRouterOptions): express_serve_static_core.Router;
|
|
9
13
|
|
|
10
14
|
declare const admin: typeof createRouter;
|
|
11
15
|
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import { promises as fs } from "node:fs";
|
|
|
3
3
|
import * as path from "node:path";
|
|
4
4
|
import {
|
|
5
5
|
BadRequest,
|
|
6
|
+
createPostgres,
|
|
6
7
|
generateCsrfToken,
|
|
7
8
|
joinStatements,
|
|
8
9
|
route,
|
|
@@ -15,11 +16,6 @@ import express from "express";
|
|
|
15
16
|
import { NotFound, readEnv } from "@devmoods/express-extras";
|
|
16
17
|
import "pg-structure";
|
|
17
18
|
import { pgStructure } from "pg-structure/dist/main.js";
|
|
18
|
-
|
|
19
|
-
// src/types.ts
|
|
20
|
-
import "@bitiforms/react";
|
|
21
|
-
|
|
22
|
-
// src/api/structure.ts
|
|
23
19
|
var getDisplayType = (dbType) => {
|
|
24
20
|
switch (dbType) {
|
|
25
21
|
case "jsonb":
|
|
@@ -212,10 +208,15 @@ function queryParamToArray(queryParam) {
|
|
|
212
208
|
|
|
213
209
|
// src/api/app.ts
|
|
214
210
|
function createRouter({
|
|
215
|
-
postgres,
|
|
216
|
-
basename = "/admin"
|
|
211
|
+
postgres: defaultPostgres,
|
|
212
|
+
basename = "/admin",
|
|
213
|
+
uiOptions = {}
|
|
217
214
|
}) {
|
|
215
|
+
const postgres = defaultPostgres ?? createPostgres();
|
|
218
216
|
const app = express.Router();
|
|
217
|
+
if (!basename.startsWith("/")) {
|
|
218
|
+
throw new Error(`Option 'basename' must start with a slash /`);
|
|
219
|
+
}
|
|
219
220
|
app.get(
|
|
220
221
|
"/api/tables",
|
|
221
222
|
route(async () => {
|
|
@@ -322,7 +323,7 @@ function createRouter({
|
|
|
322
323
|
statement.append(
|
|
323
324
|
joinStatements(
|
|
324
325
|
definition.columnNames.map(
|
|
325
|
-
(c) => sql`${sql.identifier(c)}::text ILIKE ${`%${search}%`}`
|
|
326
|
+
(c) => sql`${sql.identifier(table)}.${sql.identifier(c)}::text ILIKE ${`%${search}%`}`
|
|
326
327
|
),
|
|
327
328
|
" OR "
|
|
328
329
|
)
|
|
@@ -333,14 +334,14 @@ function createRouter({
|
|
|
333
334
|
statement.append(
|
|
334
335
|
joinStatements(
|
|
335
336
|
orderBy.map(
|
|
336
|
-
(o) => sql`${sql.identifier(o.column)} ${sql.raw(o.direction)}`
|
|
337
|
+
(o) => sql`${sql.identifier(table)}.${sql.identifier(o.column)} ${sql.raw(o.direction)}`
|
|
337
338
|
),
|
|
338
339
|
", "
|
|
339
340
|
)
|
|
340
341
|
);
|
|
341
342
|
} else if (definition.primaryKey) {
|
|
342
343
|
statement.append(
|
|
343
|
-
sql` ORDER BY ${sql.identifier(definition.primaryKey)}`
|
|
344
|
+
sql` ORDER BY ${sql.identifier(table)}.${sql.identifier(definition.primaryKey)}`
|
|
344
345
|
);
|
|
345
346
|
}
|
|
346
347
|
statement.append(sql` LIMIT ${limit} OFFSET ${limit * (page - 1)}`);
|
|
@@ -436,7 +437,7 @@ function createRouter({
|
|
|
436
437
|
"node_modules/@devmoods/postgres-admin/dist/client/_index.html",
|
|
437
438
|
"utf-8"
|
|
438
439
|
);
|
|
439
|
-
return content.replace(
|
|
440
|
+
return content.replace(/{{ csrf_token }}/g, generateCsrfToken(req, res)).replace(/{{ basename }}/g, basename.slice(1)).replace(/{{ title }}/g, uiOptions.title ?? "Posterboi");
|
|
440
441
|
})
|
|
441
442
|
);
|
|
442
443
|
return app;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devmoods/postgres-admin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -15,33 +15,34 @@
|
|
|
15
15
|
"test": "vitest"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"
|
|
18
|
+
"date-fns": "^4.1.0",
|
|
19
19
|
"pg-structure": "^7.15.3"
|
|
20
20
|
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"@devmoods/express-extras": "^0.43.0"
|
|
23
|
+
},
|
|
21
24
|
"devDependencies": {
|
|
22
25
|
"@bitiforms/adapter-devmoods-ui": "^0.11.0",
|
|
23
26
|
"@bitiforms/react": "^0.11.0",
|
|
24
27
|
"@devmoods/fetch": "^4.0.1",
|
|
25
28
|
"@devmoods/ui": "^2.3.0",
|
|
26
|
-
"@tanstack/react-query": "^5.62.
|
|
27
|
-
"@types/react": "^
|
|
28
|
-
"@types/react-dom": "^
|
|
29
|
+
"@tanstack/react-query": "^5.62.3",
|
|
30
|
+
"@types/react": "^19.0.1",
|
|
31
|
+
"@types/react-dom": "^19.0.1",
|
|
29
32
|
"@vitejs/plugin-react": "^4.3.4",
|
|
30
33
|
"@vitest/coverage-v8": "2.1.8",
|
|
31
|
-
"date-fns": "^4.1.0",
|
|
32
34
|
"dotenv": "^16.4.7",
|
|
33
|
-
"express": "^4.21.
|
|
34
|
-
"react": "19.0.0
|
|
35
|
-
"react-dom": "19.0.0
|
|
35
|
+
"express": "^4.21.2",
|
|
36
|
+
"react": "^19.0.0",
|
|
37
|
+
"react-dom": "^19.0.0",
|
|
36
38
|
"react-fast-compare": "^3.2.2",
|
|
37
|
-
"react-icons": "5.4.0",
|
|
39
|
+
"react-icons": "^5.4.0",
|
|
38
40
|
"react-router": "^7.0.2",
|
|
39
41
|
"sass": "^1.82.0",
|
|
40
|
-
"sql-formatter": "^15.4.6",
|
|
41
42
|
"tsup": "^8.3.5",
|
|
42
43
|
"vite": "^6.0.3",
|
|
43
44
|
"vitest": "^2.1.8",
|
|
44
45
|
"zustand": "^5.0.2"
|
|
45
46
|
},
|
|
46
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "8e4e952ec7cc0653a5f1c638fe923dcf8ac73bed"
|
|
47
48
|
}
|