admindb 2.2.1 → 2.3.1
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/README.md +368 -364
- package/dist/app.js +25 -16
- package/dist/auth/config.d.ts +1 -1
- package/dist/auth/config.js +18 -30
- package/dist/auth/crypto.js +11 -21
- package/dist/auth/middleware.js +9 -16
- package/dist/auth/routes.js +9 -15
- package/dist/cli/args.d.ts +1 -1
- package/dist/cli/args.js +20 -29
- package/dist/cli/config.d.ts +1 -1
- package/dist/cli/config.js +15 -18
- package/dist/cli/runner.js +13 -13
- package/dist/data/chain.d.ts +1 -1
- package/dist/data/chain.js +40 -617
- package/dist/data/datasets.d.ts +1 -1
- package/dist/data/datasets.js +43 -1
- package/dist/data/detector.js +45 -21
- package/dist/data/engine.d.ts +1 -1
- package/dist/data/engine.js +483 -142
- package/dist/data/index.d.ts +1 -1
- package/dist/data/index.js +8 -0
- package/dist/data/prng.d.ts +1 -0
- package/dist/data/prng.js +73 -0
- package/dist/data/registry.d.ts +1 -0
- package/dist/data/registry.js +805 -0
- package/dist/data/schema-graph.d.ts +1 -0
- package/dist/data/schema-graph.js +210 -0
- package/dist/data/strategies.d.ts +1 -1
- package/dist/data/strategies.js +44 -283
- package/dist/data/templates.d.ts +1 -0
- package/dist/data/templates.js +134 -0
- package/dist/data/types.d.ts +1 -1
- package/dist/data/validator.d.ts +1 -0
- package/dist/data/validator.js +160 -0
- package/dist/db/database.js +9 -14
- package/dist/db/export.js +32 -55
- package/dist/db/filters.d.ts +1 -1
- package/dist/db/filters.js +15 -38
- package/dist/db/introspection.js +4 -7
- package/dist/db/manager.d.ts +1 -1
- package/dist/db/manager.js +48 -53
- package/dist/db/migrations.js +7 -14
- package/dist/db/postgres.js +30 -78
- package/dist/index.d.ts +1 -1
- package/dist/public/css/app.css +1 -1
- package/dist/public/js/browse.js +1 -1
- package/dist/public/js/inspector.js +1 -1
- package/dist/public/js/query.js +1 -1
- package/dist/public/js/seed.js +1 -1
- package/dist/routes/api/erd.js +3 -8
- package/dist/routes/api/helpers.d.ts +1 -1
- package/dist/routes/api/helpers.js +75 -25
- package/dist/routes/api/import-export.js +1 -2
- package/dist/routes/api/query.js +2 -6
- package/dist/routes/api/rows.js +4 -8
- package/dist/routes/api/seed.js +35 -21
- package/dist/routes/api/tables.js +15 -30
- package/dist/routes/databases.js +8 -26
- package/dist/routes/pages.js +67 -18
- package/dist/serverless.js +31 -44
- package/dist/sql/generator.d.ts +1 -1
- package/dist/sql/generator.js +35 -109
- package/dist/types/api.d.ts +1 -1
- package/dist/utils/common.d.ts +1 -1
- package/dist/utils/common.js +45 -85
- package/dist/utils/csv.d.ts +1 -1
- package/dist/utils/csv.js +11 -17
- package/dist/utils/datatype.js +46 -60
- package/dist/utils/icons.js +8 -8
- package/dist/views/layouts/main.hbs +1 -87
- package/dist/views/pages/databases.hbs +1 -233
- package/dist/views/pages/designer.hbs +1 -89
- package/dist/views/pages/erd.hbs +1 -1241
- package/dist/views/pages/error.hbs +1 -10
- package/dist/views/pages/form.hbs +1 -59
- package/dist/views/pages/home.hbs +1 -220
- package/dist/views/pages/info.hbs +1 -107
- package/dist/views/pages/login.hbs +1 -98
- package/dist/views/pages/query.hbs +1 -129
- package/dist/views/pages/schema.hbs +1 -298
- package/dist/views/pages/seed-select.hbs +251 -0
- package/dist/views/pages/seed.hbs +256 -414
- package/dist/views/pages/table.hbs +1 -327
- package/dist/views/partials/navbar.hbs +1 -83
- package/dist/views/partials/sidebar.hbs +1 -129
- package/docs/API.md +149 -149
- package/docs/EXAMPLES.md +579 -579
- package/docs/SECURITY.md +265 -265
- package/package.json +80 -79
package/dist/routes/databases.js
CHANGED
|
@@ -40,12 +40,11 @@ function registerDatabasesRoutes(router, ctx) {
|
|
|
40
40
|
};
|
|
41
41
|
router.get('/', async (_req, res, next) => {
|
|
42
42
|
try {
|
|
43
|
-
const databases = await getDatabaseRows(manager);
|
|
44
43
|
res.render('pages/databases', {
|
|
45
44
|
title: 'Databases',
|
|
46
|
-
databases,
|
|
45
|
+
databases: await getDatabaseRows(manager),
|
|
47
46
|
dbDir: manager.directory,
|
|
48
|
-
readonly:
|
|
47
|
+
readonly: Boolean(ctx.readonly),
|
|
49
48
|
allowBrowse,
|
|
50
49
|
browseRoot,
|
|
51
50
|
config: { basePath: ctx.basePath },
|
|
@@ -56,8 +55,7 @@ function registerDatabasesRoutes(router, ctx) {
|
|
|
56
55
|
}
|
|
57
56
|
});
|
|
58
57
|
router.get('/api/databases', wrap(async (_req, res) => {
|
|
59
|
-
|
|
60
|
-
res.json({ success: true, data });
|
|
58
|
+
res.json({ success: true, data: await getDatabaseRows(manager) });
|
|
61
59
|
}));
|
|
62
60
|
const BLOCKED_NAMES = new Set([
|
|
63
61
|
'node_modules',
|
|
@@ -73,9 +71,7 @@ function registerDatabasesRoutes(router, ctx) {
|
|
|
73
71
|
function listDirectory(abs) {
|
|
74
72
|
const entries = [];
|
|
75
73
|
for (const name of (0, node_fs_1.readdirSync)(abs)) {
|
|
76
|
-
if (name.startsWith('.'))
|
|
77
|
-
continue;
|
|
78
|
-
if (BLOCKED_NAMES.has(name) || name.toLowerCase().startsWith('.env'))
|
|
74
|
+
if (name.startsWith('.') || BLOCKED_NAMES.has(name) || name.toLowerCase().startsWith('.env'))
|
|
79
75
|
continue;
|
|
80
76
|
const full = node_path_1.default.join(abs, name);
|
|
81
77
|
let isDir = false;
|
|
@@ -102,9 +98,8 @@ function registerDatabasesRoutes(router, ctx) {
|
|
|
102
98
|
return res.status(403).json({ success: false, error: 'File browsing is disabled — this server was started with specific database files.' });
|
|
103
99
|
}
|
|
104
100
|
const raw = String(req.query.path ?? '').trim();
|
|
105
|
-
if (raw.includes('\0'))
|
|
101
|
+
if (raw.includes('\0'))
|
|
106
102
|
return res.status(400).json({ success: false, error: 'Invalid path.' });
|
|
107
|
-
}
|
|
108
103
|
const base = raw ? node_path_1.default.resolve(raw) : manager.directory;
|
|
109
104
|
if (browseRoot && !(0, common_1.isPathWithinRoot)(browseRoot, base)) {
|
|
110
105
|
return res.status(403).json({ success: false, error: `Path is outside the allowed folder: ${browseRoot}` });
|
|
@@ -144,13 +139,7 @@ function registerDatabasesRoutes(router, ctx) {
|
|
|
144
139
|
return res.status(403).json({ success: false, error: `Cannot open a database outside the allowed folder: ${browseRoot}` });
|
|
145
140
|
}
|
|
146
141
|
const isRo = req.body?.readonly !== undefined ? Boolean(req.body.readonly) : undefined;
|
|
147
|
-
|
|
148
|
-
try {
|
|
149
|
-
id = manager.openFile(p, isRo);
|
|
150
|
-
}
|
|
151
|
-
catch (err) {
|
|
152
|
-
return res.status(400).json({ success: false, error: (0, common_1.errorMessage)(err) });
|
|
153
|
-
}
|
|
142
|
+
const id = manager.openFile(p, isRo);
|
|
154
143
|
res.json({ success: true, data: { id, message: `Opened "${id}".` } });
|
|
155
144
|
}));
|
|
156
145
|
router.post('/api/databases/connect-postgres', wrap(async (req, res) => {
|
|
@@ -172,9 +161,8 @@ function registerDatabasesRoutes(router, ctx) {
|
|
|
172
161
|
await db.listTables();
|
|
173
162
|
}
|
|
174
163
|
catch (err) {
|
|
175
|
-
if (id)
|
|
164
|
+
if (id)
|
|
176
165
|
manager.remove(id);
|
|
177
|
-
}
|
|
178
166
|
return res.status(400).json({ success: false, error: `Failed to connect to PostgreSQL: ${(0, common_1.errorMessage)(err)}` });
|
|
179
167
|
}
|
|
180
168
|
res.status(201).json({ success: true, data: { id, message: `Connected to PostgreSQL database "${id}".` } });
|
|
@@ -205,13 +193,7 @@ function registerDatabasesRoutes(router, ctx) {
|
|
|
205
193
|
const name = String(req.body?.name ?? '').trim();
|
|
206
194
|
if (!name)
|
|
207
195
|
return res.status(400).json({ success: false, error: 'Database name is required.' });
|
|
208
|
-
|
|
209
|
-
try {
|
|
210
|
-
id = manager.create(name);
|
|
211
|
-
}
|
|
212
|
-
catch (err) {
|
|
213
|
-
return res.status(400).json({ success: false, error: (0, common_1.errorMessage)(err) });
|
|
214
|
-
}
|
|
196
|
+
const id = manager.create(name);
|
|
215
197
|
res.status(201).json({ success: true, data: { id, message: `Database "${id}" created.` } });
|
|
216
198
|
}));
|
|
217
199
|
router.delete('/api/databases/:id', wrap(async (req, res) => {
|
package/dist/routes/pages.js
CHANGED
|
@@ -21,6 +21,9 @@ function buildDisplayRows(rawRows, info, table, basePath = '') {
|
|
|
21
21
|
let isImage = false;
|
|
22
22
|
let isUrl = false;
|
|
23
23
|
let isColor = false;
|
|
24
|
+
let isAudio = false;
|
|
25
|
+
let isVideo = false;
|
|
26
|
+
let isPdf = false;
|
|
24
27
|
let blobSize = '';
|
|
25
28
|
let blobMime = '';
|
|
26
29
|
let blobExt = '';
|
|
@@ -32,10 +35,7 @@ function buildDisplayRows(rawRows, info, table, basePath = '') {
|
|
|
32
35
|
if (Buffer.isBuffer(raw) || raw instanceof Uint8Array) {
|
|
33
36
|
buf = Buffer.isBuffer(raw) ? raw : Buffer.from(raw);
|
|
34
37
|
}
|
|
35
|
-
else if (typeof v === 'string' && /^0x[0-9a-f]*$/i.test(v)) {
|
|
36
|
-
buf = Buffer.from(v.slice(2), 'hex');
|
|
37
|
-
}
|
|
38
|
-
else if (typeof v === 'string' && /^\\x[0-9a-f]*$/i.test(v)) {
|
|
38
|
+
else if (typeof v === 'string' && (/^0x[0-9a-f]*$/i.test(v) || /^\\x[0-9a-f]*$/i.test(v))) {
|
|
39
39
|
buf = Buffer.from(v.slice(2), 'hex');
|
|
40
40
|
}
|
|
41
41
|
else {
|
|
@@ -46,6 +46,9 @@ function buildDisplayRows(rawRows, info, table, basePath = '') {
|
|
|
46
46
|
blobMime = mimeInfo.mime;
|
|
47
47
|
blobExt = mimeInfo.ext;
|
|
48
48
|
isImage = mimeInfo.isImage;
|
|
49
|
+
isAudio = mimeInfo.isAudio;
|
|
50
|
+
isVideo = mimeInfo.isVideo;
|
|
51
|
+
isPdf = mimeInfo.isPdf;
|
|
49
52
|
if (table && pkEncoded) {
|
|
50
53
|
blobUrl = `${basePath}/api/tables/${encodeURIComponent(table)}/row/${encodeURIComponent(pkEncoded)}/blob/${encodeURIComponent(c.name)}`;
|
|
51
54
|
}
|
|
@@ -54,12 +57,10 @@ function buildDisplayRows(rawRows, info, table, basePath = '') {
|
|
|
54
57
|
isJson = (0, datatype_1.isJsonString)(v);
|
|
55
58
|
}
|
|
56
59
|
else {
|
|
57
|
-
if (/^https?:\/\/[^\s$.?#].[^\s]*$/i.test(str))
|
|
60
|
+
if (/^https?:\/\/[^\s$.?#].[^\s]*$/i.test(str))
|
|
58
61
|
isUrl = true;
|
|
59
|
-
}
|
|
60
|
-
else if (/^#(?:[0-9a-fA-F]{3}){1,2}$|^rgba?\(\s*\d+\s*,\s*\d+\s*,\s*\d+/i.test(str)) {
|
|
62
|
+
else if (/^#(?:[0-9a-fA-F]{3}){1,2}$|^rgba?\(\s*\d+\s*,\s*\d+\s*,\s*\d+/i.test(str))
|
|
61
63
|
isColor = true;
|
|
62
|
-
}
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
66
|
return {
|
|
@@ -71,6 +72,9 @@ function buildDisplayRows(rawRows, info, table, basePath = '') {
|
|
|
71
72
|
isBlob,
|
|
72
73
|
isJson,
|
|
73
74
|
isImage,
|
|
75
|
+
isAudio,
|
|
76
|
+
isVideo,
|
|
77
|
+
isPdf,
|
|
74
78
|
isUrl,
|
|
75
79
|
isColor,
|
|
76
80
|
blobSize,
|
|
@@ -92,7 +96,7 @@ function registerPages(router, ctx) {
|
|
|
92
96
|
try {
|
|
93
97
|
const names = res.locals.tables ?? [];
|
|
94
98
|
const internalNames = res.locals.internalTables ?? [];
|
|
95
|
-
|
|
99
|
+
const colCountsMap = {};
|
|
96
100
|
if (db.dialect === 'postgres') {
|
|
97
101
|
const colRes = await db.all(`SELECT table_name, count(*)::int AS cols FROM information_schema.columns WHERE table_schema = 'public' GROUP BY table_name;`);
|
|
98
102
|
if (colRes.success && colRes.data) {
|
|
@@ -173,15 +177,12 @@ function registerPages(router, ctx) {
|
|
|
173
177
|
type: c.type,
|
|
174
178
|
active,
|
|
175
179
|
dir: active ? orderDir : null,
|
|
176
|
-
href: `${basePath}/tables/${encodeURIComponent(table)}?${qs}${filterQS ?
|
|
180
|
+
href: `${basePath}/tables/${encodeURIComponent(table)}?${qs}${filterQS ? `&${filterQS}` : ''}`,
|
|
177
181
|
};
|
|
178
182
|
});
|
|
179
183
|
const refColumns = (refsR.data ?? [])
|
|
180
184
|
.filter((r) => !r.table.startsWith('_'))
|
|
181
|
-
.map((rt) => {
|
|
182
|
-
const ref = rt.refs[0];
|
|
183
|
-
return { table: rt.table, from: ref?.from ?? '', to: ref?.to ?? '' };
|
|
184
|
-
});
|
|
185
|
+
.map((rt) => ({ table: rt.table, from: rt.refs[0]?.from ?? '', to: rt.refs[0]?.to ?? '' }));
|
|
185
186
|
const countEntries = await Promise.all(refColumns.map(async (col) => {
|
|
186
187
|
const values = rawRows
|
|
187
188
|
.map((r) => r[col.to])
|
|
@@ -271,9 +272,55 @@ function registerPages(router, ctx) {
|
|
|
271
272
|
next(err);
|
|
272
273
|
}
|
|
273
274
|
});
|
|
274
|
-
router.get('/
|
|
275
|
+
router.get('/seed', async (req, res, next) => {
|
|
276
|
+
try {
|
|
277
|
+
const tableNames = res.locals.tables ?? [];
|
|
278
|
+
if (tableNames.length === 0) {
|
|
279
|
+
return res.render('pages/seed-select', {
|
|
280
|
+
title: 'Seed Data Generator',
|
|
281
|
+
tables: [],
|
|
282
|
+
hasTables: false,
|
|
283
|
+
dialect: db.dialect,
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
const tableStats = await Promise.all(tableNames.map(async (name) => {
|
|
287
|
+
const [info, countRes] = await Promise.all([db.getTableInfo(name), db.getRowCount(name)]);
|
|
288
|
+
const cols = info.success && info.data ? info.data.columns.length : 0;
|
|
289
|
+
const fks = info.success && info.data ? info.data.foreignKeys.length : 0;
|
|
290
|
+
const rowCount = countRes.success ? countRes.data : 0;
|
|
291
|
+
return {
|
|
292
|
+
name,
|
|
293
|
+
cols,
|
|
294
|
+
fks,
|
|
295
|
+
rowCount,
|
|
296
|
+
};
|
|
297
|
+
}));
|
|
298
|
+
const defaultTable = req.query.table ? String(req.query.table) : tableStats[0]?.name;
|
|
299
|
+
const defaultMode = req.query.mode === 'chain' ? 'chain' : 'single';
|
|
300
|
+
res.render('pages/seed-select', {
|
|
301
|
+
title: 'Seed Data Generator · Choose Table & Mode',
|
|
302
|
+
tables: tableStats,
|
|
303
|
+
hasTables: true,
|
|
304
|
+
defaultTable,
|
|
305
|
+
defaultMode,
|
|
306
|
+
dialect: db.dialect,
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
catch (err) {
|
|
310
|
+
next(err);
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
router.get('/tables/:table/seed', (req, res) => {
|
|
314
|
+
const table = req.params.table;
|
|
315
|
+
const qs = req.url.includes('?') ? req.url.slice(req.url.indexOf('?')) : '';
|
|
316
|
+
const bp = res.locals.basePath || '';
|
|
317
|
+
return res.redirect(301, `${bp}/seed/${encodeURIComponent(table)}${qs}`);
|
|
318
|
+
});
|
|
319
|
+
router.get('/seed/:table', async (req, res, next) => {
|
|
275
320
|
try {
|
|
276
321
|
const table = req.params.table;
|
|
322
|
+
const allTables = res.locals.tables ?? [];
|
|
323
|
+
const initialMode = req.query.mode === 'chain' ? 'chain' : 'single';
|
|
277
324
|
const [info, countRes] = await Promise.all([db.getTableInfo(table), db.getRowCount(table)]);
|
|
278
325
|
if (!info.success || !info.data || info.data.columns.length === 0) {
|
|
279
326
|
return notFound(res, `Table "${table}" does not exist.`);
|
|
@@ -284,11 +331,14 @@ function registerPages(router, ctx) {
|
|
|
284
331
|
res.render('pages/seed', {
|
|
285
332
|
title: `Seed data · ${table}`,
|
|
286
333
|
table,
|
|
334
|
+
allTables,
|
|
335
|
+
mode: initialMode,
|
|
336
|
+
isChainMode: initialMode === 'chain',
|
|
287
337
|
rowCount,
|
|
288
338
|
colCount: info.data.columns.length,
|
|
289
339
|
maxRows: index_1.MAX_SEED_ROWS,
|
|
290
340
|
quickCounts: [10, 50, 100, 500, 1000, index_1.MAX_SEED_ROWS],
|
|
291
|
-
seedConfig: { table, columns, rowCount, maxRows: index_1.MAX_SEED_ROWS },
|
|
341
|
+
seedConfig: { table, columns, rowCount, maxRows: index_1.MAX_SEED_ROWS, mode: initialMode },
|
|
292
342
|
});
|
|
293
343
|
}
|
|
294
344
|
catch (err) {
|
|
@@ -382,10 +432,9 @@ function registerPages(router, ctx) {
|
|
|
382
432
|
router.get('/info', async (_req, res, next) => {
|
|
383
433
|
try {
|
|
384
434
|
const settingsRes = await db.getSettings();
|
|
385
|
-
const settings = settingsRes.success ? settingsRes.data : {};
|
|
386
435
|
res.render('pages/info', {
|
|
387
436
|
title: 'Database Info',
|
|
388
|
-
settings,
|
|
437
|
+
settings: settingsRes.success ? settingsRes.data : {},
|
|
389
438
|
dialect: db.dialect,
|
|
390
439
|
dbPath: db.path,
|
|
391
440
|
});
|
package/dist/serverless.js
CHANGED
|
@@ -11,59 +11,56 @@ function isServerlessEnvironment(env = process.env) {
|
|
|
11
11
|
if (['1', 'true', 'yes', 'on'].includes(String(env.ADMINDB_SERVERLESS ?? env.SERVERLESS ?? env.IS_SERVERLESS ?? '').trim().toLowerCase())) {
|
|
12
12
|
return true;
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (Boolean(env.NETLIFY || env.NETLIFY_LOCAL)) {
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
23
|
-
if (Boolean(env.FUNCTION_TARGET || env.FUNCTION_NAME || env.K_SERVICE)) {
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
if (Boolean(env.FUNCTIONS_WORKER_RUNTIME || env.WEBSITE_INSTANCE_ID)) {
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
if (Boolean(env.CF_PAGES)) {
|
|
30
|
-
return true;
|
|
31
|
-
}
|
|
32
|
-
return false;
|
|
14
|
+
return Boolean(env.VERCEL || env.VERCEL_ENV || env.NOW_REGION ||
|
|
15
|
+
env.AWS_LAMBDA_FUNCTION_NAME || env.LAMBDA_TASK_ROOT || env.AWS_EXECUTION_ENV ||
|
|
16
|
+
env.NETLIFY || env.NETLIFY_LOCAL ||
|
|
17
|
+
env.FUNCTION_TARGET || env.FUNCTION_NAME || env.K_SERVICE ||
|
|
18
|
+
env.FUNCTIONS_WORKER_RUNTIME || env.WEBSITE_INSTANCE_ID ||
|
|
19
|
+
env.CF_PAGES);
|
|
33
20
|
}
|
|
34
21
|
function createServerlessHandler(options = {}) {
|
|
35
|
-
const
|
|
22
|
+
const envTarget = process.env.ADMINDB_CONNECTION ||
|
|
23
|
+
process.env.DATABASE_URL ||
|
|
24
|
+
process.env.POSTGRES_URL ||
|
|
25
|
+
process.env.PG_CONNECTION ||
|
|
26
|
+
'';
|
|
27
|
+
const rawTarget = options.connection || options.dbPath || ((0, common_1.isPostgresConnectionString)(envTarget) ? envTarget : '');
|
|
36
28
|
const isPg = Boolean(options.pgOptions) ||
|
|
37
29
|
(0, common_1.isPostgresConnectionString)(rawTarget) ||
|
|
38
30
|
options.db?.dialect === 'postgres';
|
|
39
|
-
const defaultReadonly = isPg
|
|
31
|
+
const defaultReadonly = !isPg;
|
|
40
32
|
const app = (0, app_1.createRouter)({
|
|
41
33
|
...options,
|
|
34
|
+
connection: options.connection || ((0, common_1.isPostgresConnectionString)(rawTarget) ? rawTarget : undefined),
|
|
42
35
|
serverless: options.serverless ?? true,
|
|
43
|
-
readonly: options.readonly
|
|
36
|
+
readonly: options.readonly !== undefined ? Boolean(options.readonly) : defaultReadonly,
|
|
44
37
|
});
|
|
45
38
|
return (req, res) => {
|
|
46
39
|
app(req, res);
|
|
47
40
|
};
|
|
48
41
|
}
|
|
49
42
|
function createLambdaHandler(options = {}) {
|
|
50
|
-
const
|
|
43
|
+
const envTarget = process.env.ADMINDB_CONNECTION ||
|
|
44
|
+
process.env.DATABASE_URL ||
|
|
45
|
+
process.env.POSTGRES_URL ||
|
|
46
|
+
process.env.PG_CONNECTION ||
|
|
47
|
+
'';
|
|
48
|
+
const rawTarget = options.connection || options.dbPath || ((0, common_1.isPostgresConnectionString)(envTarget) ? envTarget : '');
|
|
51
49
|
const isPg = Boolean(options.pgOptions) ||
|
|
52
50
|
(0, common_1.isPostgresConnectionString)(rawTarget) ||
|
|
53
51
|
options.db?.dialect === 'postgres';
|
|
54
|
-
const defaultReadonly = isPg
|
|
52
|
+
const defaultReadonly = !isPg;
|
|
55
53
|
const app = (0, app_1.createRouter)({
|
|
56
54
|
...options,
|
|
55
|
+
connection: options.connection || ((0, common_1.isPostgresConnectionString)(rawTarget) ? rawTarget : undefined),
|
|
57
56
|
serverless: options.serverless ?? true,
|
|
58
|
-
readonly: options.readonly
|
|
57
|
+
readonly: options.readonly !== undefined ? Boolean(options.readonly) : defaultReadonly,
|
|
59
58
|
});
|
|
60
59
|
return async (event, _context) => {
|
|
61
60
|
return new Promise((resolve) => {
|
|
62
61
|
try {
|
|
63
62
|
const isV2 = Boolean(event.version === '2.0' || event.rawPath);
|
|
64
|
-
const method = (isV2
|
|
65
|
-
? event.requestContext?.http?.method
|
|
66
|
-
: event.httpMethod) || 'GET';
|
|
63
|
+
const method = (isV2 ? event.requestContext?.http?.method : event.httpMethod) || 'GET';
|
|
67
64
|
const rawPath = isV2 ? (event.rawPath || '/') : (event.path || '/');
|
|
68
65
|
const qs = isV2
|
|
69
66
|
? (event.rawQueryString || '')
|
|
@@ -76,24 +73,17 @@ function createLambdaHandler(options = {}) {
|
|
|
76
73
|
const rawHeaders = event.headers || {};
|
|
77
74
|
const headers = {};
|
|
78
75
|
for (const [k, v] of Object.entries(rawHeaders)) {
|
|
79
|
-
if (v !== undefined && v !== null)
|
|
76
|
+
if (v !== undefined && v !== null)
|
|
80
77
|
headers[k.toLowerCase()] = String(v);
|
|
81
|
-
}
|
|
82
78
|
}
|
|
83
79
|
if (event.cookies && Array.isArray(event.cookies) && !headers['cookie']) {
|
|
84
80
|
headers['cookie'] = event.cookies.join('; ');
|
|
85
81
|
}
|
|
86
82
|
let bodyBuffer = null;
|
|
87
83
|
if (event.body) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
bodyBuffer = Buffer.from(event.body, 'utf8');
|
|
93
|
-
}
|
|
94
|
-
if (!headers['content-length']) {
|
|
84
|
+
bodyBuffer = event.isBase64Encoded ? Buffer.from(event.body, 'base64') : Buffer.from(event.body, 'utf8');
|
|
85
|
+
if (!headers['content-length'])
|
|
95
86
|
headers['content-length'] = String(bodyBuffer.length);
|
|
96
|
-
}
|
|
97
87
|
}
|
|
98
88
|
const socket = new node_net_1.Socket();
|
|
99
89
|
const req = new node_http_1.IncomingMessage(socket);
|
|
@@ -103,16 +93,14 @@ function createLambdaHandler(options = {}) {
|
|
|
103
93
|
req.httpVersion = '1.1';
|
|
104
94
|
req.httpVersionMajor = 1;
|
|
105
95
|
req.httpVersionMinor = 1;
|
|
106
|
-
if (bodyBuffer)
|
|
96
|
+
if (bodyBuffer)
|
|
107
97
|
req.push(bodyBuffer);
|
|
108
|
-
}
|
|
109
98
|
req.push(null);
|
|
110
99
|
const res = new node_http_1.ServerResponse(req);
|
|
111
100
|
const chunks = [];
|
|
112
101
|
res.write = function (chunk, ...args) {
|
|
113
|
-
if (chunk)
|
|
102
|
+
if (chunk)
|
|
114
103
|
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
115
|
-
}
|
|
116
104
|
const cb = typeof args[0] === 'function' ? args[0] : typeof args[1] === 'function' ? args[1] : undefined;
|
|
117
105
|
if (cb)
|
|
118
106
|
cb();
|
|
@@ -133,8 +121,7 @@ function createLambdaHandler(options = {}) {
|
|
|
133
121
|
cb();
|
|
134
122
|
const responseHeaders = {};
|
|
135
123
|
const multiValueHeaders = {};
|
|
136
|
-
const
|
|
137
|
-
for (const [k, v] of Object.entries(resHeaders)) {
|
|
124
|
+
for (const [k, v] of Object.entries(res.getHeaders())) {
|
|
138
125
|
if (Array.isArray(v)) {
|
|
139
126
|
multiValueHeaders[k] = v.map(String);
|
|
140
127
|
responseHeaders[k] = v.map(String).join(', ');
|
package/dist/sql/generator.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SQLITE_DESIGNER_TYPES:readonly ["TEXT","INTEGER","REAL","BLOB","BOOLEAN","DATE","DATETIME","NUMERIC","VARCHAR(255)","JSON"];export declare const POSTGRES_DESIGNER_TYPES:readonly ["TEXT","VARCHAR(255)","INTEGER","BIGINT","SMALLINT","SERIAL","BIGSERIAL","REAL","DECIMAL(10,2)","NUMERIC","BOOLEAN","DATE","DATETIME","TIMESTAMP","TIMESTAMPTZ","TIME","INTERVAL","JSON","JSONB","UUID","BYTEA","INET"];export declare const DESIGNER_TYPES:readonly ["TEXT","VARCHAR(255)","INTEGER","BIGINT","SMALLINT","SERIAL","BIGSERIAL","REAL","DECIMAL(10,2)","NUMERIC","BOOLEAN","DATE","DATETIME","TIMESTAMP","TIMESTAMPTZ","TIME","INTERVAL","JSON","JSONB","UUID","BYTEA","BLOB","INET"];export declare
|
|
1
|
+
export declare const SQLITE_DESIGNER_TYPES:readonly ["TEXT","INTEGER","REAL","BLOB","BOOLEAN","DATE","DATETIME","NUMERIC","VARCHAR(255)","JSON"];export declare const POSTGRES_DESIGNER_TYPES:readonly ["TEXT","VARCHAR(255)","INTEGER","BIGINT","SMALLINT","SERIAL","BIGSERIAL","REAL","DECIMAL(10,2)","NUMERIC","BOOLEAN","DATE","DATETIME","TIMESTAMP","TIMESTAMPTZ","TIME","INTERVAL","JSON","JSONB","UUID","BYTEA","INET"];export declare const DESIGNER_TYPES:readonly ["TEXT","VARCHAR(255)","INTEGER","BIGINT","SMALLINT","SERIAL","BIGSERIAL","REAL","DECIMAL(10,2)","NUMERIC","BOOLEAN","DATE","DATETIME","TIMESTAMP","TIMESTAMPTZ","TIME","INTERVAL","JSON","JSONB","UUID","BYTEA","BLOB","INET"];export declare const getDesignerTypes:(dialect?:"sqlite"|"postgres")=>readonly string[];export type DesignerColumnType=( typeof DESIGNER_TYPES)[number];export interface ColumnDef{name:string;type:string;primaryKey?:boolean;notNull?:boolean;unique?:boolean;defaultValue?:string|null;foreignKey?:{table:string;column:string;}|null;}export interface FieldValue{column:string;value:unknown;}export declare const quoteIdentifier:(identifier:string)=>string;export declare const escapeString:(value:string)=>string;export declare function sqlValue(value:unknown):string;export interface MappedType{sqlType:string;defaultAuto?:string;}export declare function mapColumnType(type:string):MappedType;export interface RenderOptions{forAddColumn?:boolean;}export declare function formatSqlDefault(raw:string,colType?:string):string;export declare function renderColumnDef(col:ColumnDef,opts?:RenderOptions):string;export declare function generateCreateTable(tableName:string,columns:ColumnDef[]):string;export declare function generateAddColumn(tableName:string,col:ColumnDef):string;export declare function generateRenameTable(tableName:string,newName:string):string;export declare function generateRenameColumn(tableName:string,oldName:string,newName:string):string;export declare function generateDropColumn(tableName:string,column:string):string;export declare function generateDropTable(tableName:string):string;export interface IndexDef{name?:string;columns:string[];unique?:boolean;}export declare function generateCreateIndex(tableName:string,index:IndexDef):string;export declare function generateDropIndex(indexName:string):string;export declare function generateInsert(table:string,fields:FieldValue[]):string;export declare function generateUpdate(table:string,fields:FieldValue[],where:FieldValue[]):string;
|