admindb 2.1.0 → 2.2.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 +41 -12
- package/dist/app.d.ts +1 -69
- package/dist/app.js +3 -30
- package/dist/auth/config.d.ts +1 -19
- package/dist/auth/config.js +0 -26
- package/dist/auth/crypto.d.ts +1 -27
- package/dist/auth/crypto.js +1 -26
- package/dist/auth/index.d.ts +1 -5
- package/dist/auth/index.js +0 -1
- package/dist/auth/middleware.d.ts +1 -14
- package/dist/auth/middleware.js +0 -15
- package/dist/auth/routes.d.ts +1 -7
- package/dist/auth/routes.js +0 -8
- package/dist/auth/types.d.ts +1 -35
- package/dist/auth/types.js +1 -5
- package/dist/cli/args.d.ts +1 -45
- package/dist/cli/args.js +3 -11
- package/dist/cli/config.d.ts +1 -56
- package/dist/cli/config.js +0 -5
- package/dist/cli/index.d.ts +1 -4
- package/dist/cli/index.js +0 -1
- package/dist/cli/runner.d.ts +1 -1
- package/dist/cli/runner.js +6 -17
- package/dist/cli.d.ts +1 -2
- package/dist/cli.js +0 -1
- package/dist/data/chain.d.ts +1 -0
- package/dist/data/chain.js +707 -0
- package/dist/data/datasets.d.ts +1 -17
- package/dist/data/datasets.js +0 -4
- package/dist/data/detector.d.ts +1 -30
- package/dist/data/detector.js +53 -14
- package/dist/data/engine.d.ts +1 -10
- package/dist/data/engine.js +82 -48
- package/dist/data/index.d.ts +1 -5
- package/dist/data/index.js +1 -1
- package/dist/data/strategies.d.ts +1 -30
- package/dist/data/strategies.js +4 -8
- package/dist/data/types.d.ts +1 -73
- package/dist/data/types.js +0 -3
- package/dist/db/database.d.ts +1 -119
- package/dist/db/database.js +20 -14
- package/dist/db/export.d.ts +1 -12
- package/dist/db/export.js +54 -6
- package/dist/db/filters.d.ts +1 -22
- package/dist/db/filters.js +0 -16
- package/dist/db/index.d.ts +1 -8
- package/dist/db/index.js +0 -1
- package/dist/db/introspection.d.ts +1 -6
- package/dist/db/introspection.js +0 -5
- package/dist/db/manager.d.ts +1 -81
- package/dist/db/manager.js +13 -59
- package/dist/db/migrations.d.ts +1 -5
- package/dist/db/migrations.js +2 -5
- package/dist/db/postgres.d.ts +1 -85
- package/dist/db/postgres.js +21 -31
- package/dist/db/types.d.ts +1 -206
- package/dist/db/types.js +0 -1
- package/dist/index.d.ts +1 -23
- package/dist/index.js +0 -14
- package/dist/public/css/app.css +1 -1
- package/dist/public/js/api.js +1 -47
- package/dist/public/js/app.js +1 -262
- package/dist/public/js/browse.js +1 -1371
- package/dist/public/js/common.js +1 -0
- package/dist/public/js/databases.js +1 -235
- package/dist/public/js/designer.js +1 -258
- package/dist/public/js/forms.js +1 -826
- package/dist/public/js/home.js +1 -0
- package/dist/public/js/inspector.js +1 -638
- package/dist/public/js/query.js +1 -322
- package/dist/public/js/schema.js +1 -447
- package/dist/public/js/seed.js +1 -1090
- package/dist/routes/api/erd.d.ts +1 -0
- package/dist/routes/api/erd.js +50 -0
- package/dist/routes/api/helpers.d.ts +1 -42
- package/dist/routes/api/helpers.js +33 -3
- package/dist/routes/api/import-export.d.ts +1 -3
- package/dist/routes/api/import-export.js +0 -2
- package/dist/routes/api/index.d.ts +1 -4
- package/dist/routes/api/index.js +15 -4
- package/dist/routes/api/query.d.ts +1 -3
- package/dist/routes/api/query.js +13 -11
- package/dist/routes/api/rows.d.ts +1 -3
- package/dist/routes/api/rows.js +0 -11
- package/dist/routes/api/seed.d.ts +1 -3
- package/dist/routes/api/seed.js +79 -8
- package/dist/routes/api/tables.d.ts +1 -3
- package/dist/routes/api/tables.js +77 -6
- package/dist/routes/databases.d.ts +1 -26
- package/dist/routes/databases.js +1 -3
- package/dist/routes/index.d.ts +1 -3
- package/dist/routes/index.js +0 -1
- package/dist/routes/pages.d.ts +1 -9
- package/dist/routes/pages.js +18 -11
- package/dist/serverless.d.ts +1 -40
- package/dist/serverless.js +3 -39
- package/dist/sql/classifier.d.ts +1 -19
- package/dist/sql/classifier.js +0 -13
- package/dist/sql/error-analyzer.d.ts +1 -0
- package/dist/sql/error-analyzer.js +550 -0
- package/dist/sql/generator.d.ts +1 -81
- package/dist/sql/generator.js +0 -29
- package/dist/sql/index.d.ts +1 -2
- package/dist/sql/index.js +0 -1
- package/dist/types/api.d.ts +1 -412
- package/dist/types/api.js +0 -7
- package/dist/utils/colors.d.ts +1 -40
- package/dist/utils/colors.js +0 -10
- package/dist/utils/common.d.ts +1 -50
- package/dist/utils/common.js +19 -23
- package/dist/utils/csv.d.ts +1 -15
- package/dist/utils/csv.js +0 -13
- package/dist/utils/datatype.d.ts +1 -49
- package/dist/utils/datatype.js +0 -41
- package/dist/utils/icons.d.ts +1 -11
- package/dist/utils/icons.js +25 -16
- package/dist/utils/index.d.ts +1 -4
- package/dist/utils/index.js +0 -1
- package/dist/utils/logger.d.ts +1 -10
- package/dist/utils/logger.js +0 -4
- package/dist/views/layouts/main.hbs +14 -5
- package/dist/views/pages/databases.hbs +0 -18
- package/dist/views/pages/designer.hbs +0 -10
- package/dist/views/pages/erd.hbs +1241 -0
- package/dist/views/pages/error.hbs +0 -2
- package/dist/views/pages/form.hbs +0 -5
- package/dist/views/pages/home.hbs +98 -10
- package/dist/views/pages/info.hbs +107 -0
- package/dist/views/pages/login.hbs +0 -13
- package/dist/views/pages/query.hbs +54 -21
- package/dist/views/pages/schema.hbs +0 -20
- package/dist/views/pages/seed.hbs +435 -202
- package/dist/views/pages/table.hbs +0 -14
- package/dist/views/partials/icon.hbs +0 -1
- package/dist/views/partials/navbar.hbs +0 -6
- package/dist/views/partials/sidebar.hbs +12 -8
- package/docs/API.md +6 -1
- package/docs/EXAMPLES.md +3 -0
- package/package.json +7 -5
- package/dist/app.js.map +0 -1
- package/dist/auth/config.js.map +0 -1
- package/dist/auth/crypto.js.map +0 -1
- package/dist/auth/index.js.map +0 -1
- package/dist/auth/middleware.js.map +0 -1
- package/dist/auth/routes.js.map +0 -1
- package/dist/auth/types.js.map +0 -1
- package/dist/cli/args.js.map +0 -1
- package/dist/cli/config.js.map +0 -1
- package/dist/cli/index.js.map +0 -1
- package/dist/cli/runner.js.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/data/datasets.js.map +0 -1
- package/dist/data/detector.js.map +0 -1
- package/dist/data/engine.js.map +0 -1
- package/dist/data/index.js.map +0 -1
- package/dist/data/strategies.js.map +0 -1
- package/dist/data/types.js.map +0 -1
- package/dist/db/database.js.map +0 -1
- package/dist/db/export.js.map +0 -1
- package/dist/db/filters.js.map +0 -1
- package/dist/db/index.js.map +0 -1
- package/dist/db/introspection.js.map +0 -1
- package/dist/db/manager.js.map +0 -1
- package/dist/db/migrations.js.map +0 -1
- package/dist/db/postgres.js.map +0 -1
- package/dist/db/types.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/public/css/input.css +0 -302
- package/dist/public/js/icons.js +0 -51
- package/dist/routes/api/helpers.js.map +0 -1
- package/dist/routes/api/import-export.js.map +0 -1
- package/dist/routes/api/index.js.map +0 -1
- package/dist/routes/api/query.js.map +0 -1
- package/dist/routes/api/rows.js.map +0 -1
- package/dist/routes/api/seed.js.map +0 -1
- package/dist/routes/api/tables.js.map +0 -1
- package/dist/routes/databases.js.map +0 -1
- package/dist/routes/index.js.map +0 -1
- package/dist/routes/pages.js.map +0 -1
- package/dist/serverless.js.map +0 -1
- package/dist/sql/classifier.js.map +0 -1
- package/dist/sql/generator.js.map +0 -1
- package/dist/sql/index.js.map +0 -1
- package/dist/types/api.js.map +0 -1
- package/dist/utils/colors.js.map +0 -1
- package/dist/utils/common.js.map +0 -1
- package/dist/utils/csv.js.map +0 -1
- package/dist/utils/datatype.js.map +0 -1
- package/dist/utils/icons.js.map +0 -1
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/logger.js.map +0 -1
|
@@ -1,26 +1 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { DbManager, DatabaseEntry } from '../db/manager';
|
|
3
|
-
import type { Logger } from '../utils/logger';
|
|
4
|
-
interface DatabasesContext {
|
|
5
|
-
manager: DbManager;
|
|
6
|
-
logger: Logger;
|
|
7
|
-
basePath: string;
|
|
8
|
-
readonly?: boolean;
|
|
9
|
-
allowBrowse?: boolean;
|
|
10
|
-
browseRoot?: string;
|
|
11
|
-
invalidate?: (id: string) => void;
|
|
12
|
-
}
|
|
13
|
-
export interface DatabaseRow extends DatabaseEntry {
|
|
14
|
-
sizeLabel: string;
|
|
15
|
-
modifiedLabel: string;
|
|
16
|
-
tables: number;
|
|
17
|
-
}
|
|
18
|
-
export interface FsEntry {
|
|
19
|
-
name: string;
|
|
20
|
-
path: string;
|
|
21
|
-
isDir: boolean;
|
|
22
|
-
isDb: boolean;
|
|
23
|
-
size: number;
|
|
24
|
-
}
|
|
25
|
-
export declare function registerDatabasesRoutes(router: Router, ctx: DatabasesContext): void;
|
|
26
|
-
export {};
|
|
1
|
+
import type {Router} from 'express';import type {DbManager,DatabaseEntry} from '../db/manager';import type {Logger} from '../utils/logger';interface DatabasesContext{manager:DbManager;logger:Logger;basePath:string;readonly ?:boolean;allowBrowse?:boolean;browseRoot?:string;invalidate?:(id:string)=>void;}export interface DatabaseRow extends DatabaseEntry{sizeLabel:string;modifiedLabel:string;tables:number;}export interface FsEntry{name:string;path:string;isDir:boolean;isDb:boolean;size:number;}export declare function registerDatabasesRoutes(router:Router,ctx:DatabasesContext):void;export{};
|
package/dist/routes/databases.js
CHANGED
|
@@ -162,13 +162,12 @@ function registerDatabasesRoutes(router, ctx) {
|
|
|
162
162
|
if (!connectionString) {
|
|
163
163
|
return res.status(400).json({ success: false, error: 'PostgreSQL connection string is required (e.g. postgresql://user:password@localhost:5432/dbname).' });
|
|
164
164
|
}
|
|
165
|
-
if (!
|
|
165
|
+
if (!(0, common_1.isPostgresConnectionString)(connectionString)) {
|
|
166
166
|
return res.status(400).json({ success: false, error: 'Invalid connection protocol. Connection string must start with postgres:// or postgresql://' });
|
|
167
167
|
}
|
|
168
168
|
let id;
|
|
169
169
|
try {
|
|
170
170
|
id = manager.addConnection(name, connectionString, isRo);
|
|
171
|
-
// Verify the connection works
|
|
172
171
|
const db = manager.open(id);
|
|
173
172
|
await db.listTables();
|
|
174
173
|
}
|
|
@@ -227,4 +226,3 @@ function registerDatabasesRoutes(router, ctx) {
|
|
|
227
226
|
res.json({ success: true, data: { message: `Database "${id}" removed.` } });
|
|
228
227
|
}));
|
|
229
228
|
}
|
|
230
|
-
//# sourceMappingURL=databases.js.map
|
package/dist/routes/index.d.ts
CHANGED
package/dist/routes/index.js
CHANGED
package/dist/routes/pages.d.ts
CHANGED
|
@@ -1,9 +1 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { IDatabase } from '../db/index';
|
|
3
|
-
import type { Logger } from '../utils/logger';
|
|
4
|
-
interface PageContext {
|
|
5
|
-
db: IDatabase;
|
|
6
|
-
logger: Logger;
|
|
7
|
-
}
|
|
8
|
-
export declare function registerPages(router: Router, ctx: PageContext): void;
|
|
9
|
-
export {};
|
|
1
|
+
import type {Router} from 'express';import type {IDatabase} from '../db/index';import type {Logger} from '../utils/logger';interface PageContext{db:IDatabase;logger:Logger;}export declare function registerPages(router:Router,ctx:PageContext):void;export{};
|
package/dist/routes/pages.js
CHANGED
|
@@ -88,7 +88,6 @@ function registerPages(router, ctx) {
|
|
|
88
88
|
const notFound = (res, message) => {
|
|
89
89
|
res.status(404).render('pages/error', { title: 'Not found', status: 404, error: message });
|
|
90
90
|
};
|
|
91
|
-
// Home / browse overview.
|
|
92
91
|
router.get('/', async (_req, res, next) => {
|
|
93
92
|
try {
|
|
94
93
|
const names = res.locals.tables ?? [];
|
|
@@ -141,7 +140,6 @@ function registerPages(router, ctx) {
|
|
|
141
140
|
next(err);
|
|
142
141
|
}
|
|
143
142
|
});
|
|
144
|
-
// Browse a table's rows.
|
|
145
143
|
router.get('/tables/:table', async (req, res, next) => {
|
|
146
144
|
try {
|
|
147
145
|
const table = req.params.table;
|
|
@@ -184,7 +182,6 @@ function registerPages(router, ctx) {
|
|
|
184
182
|
const ref = rt.refs[0];
|
|
185
183
|
return { table: rt.table, from: ref?.from ?? '', to: ref?.to ?? '' };
|
|
186
184
|
});
|
|
187
|
-
// Per-row reference counts: parallel query per referencing table.
|
|
188
185
|
const countEntries = await Promise.all(refColumns.map(async (col) => {
|
|
189
186
|
const values = rawRows
|
|
190
187
|
.map((r) => r[col.to])
|
|
@@ -248,7 +245,6 @@ function registerPages(router, ctx) {
|
|
|
248
245
|
next(err);
|
|
249
246
|
}
|
|
250
247
|
});
|
|
251
|
-
// Table schema editor.
|
|
252
248
|
router.get('/tables/:table/schema', async (req, res, next) => {
|
|
253
249
|
try {
|
|
254
250
|
const table = req.params.table;
|
|
@@ -275,7 +271,6 @@ function registerPages(router, ctx) {
|
|
|
275
271
|
next(err);
|
|
276
272
|
}
|
|
277
273
|
});
|
|
278
|
-
// Data generator / seeder.
|
|
279
274
|
router.get('/tables/:table/seed', async (req, res, next) => {
|
|
280
275
|
try {
|
|
281
276
|
const table = req.params.table;
|
|
@@ -300,7 +295,6 @@ function registerPages(router, ctx) {
|
|
|
300
295
|
next(err);
|
|
301
296
|
}
|
|
302
297
|
});
|
|
303
|
-
// Insert form.
|
|
304
298
|
router.get('/tables/:table/rows/new', async (req, res, next) => {
|
|
305
299
|
try {
|
|
306
300
|
const table = req.params.table;
|
|
@@ -324,7 +318,6 @@ function registerPages(router, ctx) {
|
|
|
324
318
|
next(err);
|
|
325
319
|
}
|
|
326
320
|
});
|
|
327
|
-
// Edit form.
|
|
328
321
|
router.get('/tables/:table/rows/:id/edit', async (req, res, next) => {
|
|
329
322
|
try {
|
|
330
323
|
const table = req.params.table;
|
|
@@ -352,7 +345,9 @@ function registerPages(router, ctx) {
|
|
|
352
345
|
next(err);
|
|
353
346
|
}
|
|
354
347
|
});
|
|
355
|
-
|
|
348
|
+
router.get('/erd', (_req, res) => {
|
|
349
|
+
res.render('pages/erd', { title: 'ER Diagram' });
|
|
350
|
+
});
|
|
356
351
|
router.get('/designer', (_req, res) => {
|
|
357
352
|
res.render('pages/designer', {
|
|
358
353
|
title: 'New table',
|
|
@@ -361,7 +356,6 @@ function registerPages(router, ctx) {
|
|
|
361
356
|
isPostgres: db.dialect === 'postgres',
|
|
362
357
|
});
|
|
363
358
|
});
|
|
364
|
-
// Query editor.
|
|
365
359
|
router.get('/query', async (_req, res, next) => {
|
|
366
360
|
try {
|
|
367
361
|
const queries = await db.listSavedQueries();
|
|
@@ -371,7 +365,6 @@ function registerPages(router, ctx) {
|
|
|
371
365
|
next(err);
|
|
372
366
|
}
|
|
373
367
|
});
|
|
374
|
-
// Export: downloadable SQL dump.
|
|
375
368
|
router.get('/export', async (_req, res, next) => {
|
|
376
369
|
try {
|
|
377
370
|
const dump = await (0, export_1.generateSqlDump)(db);
|
|
@@ -386,5 +379,19 @@ function registerPages(router, ctx) {
|
|
|
386
379
|
next(err);
|
|
387
380
|
}
|
|
388
381
|
});
|
|
382
|
+
router.get('/info', async (_req, res, next) => {
|
|
383
|
+
try {
|
|
384
|
+
const settingsRes = await db.getSettings();
|
|
385
|
+
const settings = settingsRes.success ? settingsRes.data : {};
|
|
386
|
+
res.render('pages/info', {
|
|
387
|
+
title: 'Database Info',
|
|
388
|
+
settings,
|
|
389
|
+
dialect: db.dialect,
|
|
390
|
+
dbPath: db.path,
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
catch (err) {
|
|
394
|
+
next(err);
|
|
395
|
+
}
|
|
396
|
+
});
|
|
389
397
|
}
|
|
390
|
-
//# sourceMappingURL=pages.js.map
|
package/dist/serverless.d.ts
CHANGED
|
@@ -1,40 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { type AppOptions } from './app';
|
|
3
|
-
/**
|
|
4
|
-
* Detects if the current process is running in a serverless environment
|
|
5
|
-
* (e.g. Vercel, AWS Lambda, Netlify Functions, Google Cloud Functions/Run, Azure Functions, Cloudflare Pages).
|
|
6
|
-
*/
|
|
7
|
-
export declare function isServerlessEnvironment(env?: NodeJS.ProcessEnv): boolean;
|
|
8
|
-
/**
|
|
9
|
-
* Creates an HTTP request listener for standard Node.js serverless runtimes
|
|
10
|
-
* (Vercel API routes, Next.js custom route handlers, Google Cloud Functions, Azure Functions, Micro).
|
|
11
|
-
*
|
|
12
|
-
* In serverless mode, all write operations and database mutations are strictly disabled.
|
|
13
|
-
*
|
|
14
|
-
* Example (Vercel `api/index.ts`):
|
|
15
|
-
* ```ts
|
|
16
|
-
* import { createServerlessHandler } from 'admindb';
|
|
17
|
-
* export default createServerlessHandler({ dbPath: './data.db' });
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export declare function createServerlessHandler(options?: AppOptions): (req: IncomingMessage, res: ServerResponse) => void;
|
|
21
|
-
export interface LambdaProxyResult {
|
|
22
|
-
statusCode: number;
|
|
23
|
-
headers: Record<string, string>;
|
|
24
|
-
multiValueHeaders?: Record<string, string[]>;
|
|
25
|
-
body: string;
|
|
26
|
-
isBase64Encoded: boolean;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Creates an AWS Lambda handler for API Gateway (REST v1 and HTTP v2 payloads).
|
|
30
|
-
*
|
|
31
|
-
* In serverless mode, SQLite databases are read-only, while remote PostgreSQL
|
|
32
|
-
* connections are editable unless configured otherwise.
|
|
33
|
-
*
|
|
34
|
-
* Example (AWS Lambda `index.ts`):
|
|
35
|
-
* ```ts
|
|
36
|
-
* import { createLambdaHandler } from 'admindb';
|
|
37
|
-
* export const handler = createLambdaHandler({ dbPath: './data.db' });
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
export declare function createLambdaHandler(options?: AppOptions): (event: any, _context?: any) => Promise<LambdaProxyResult>;
|
|
1
|
+
import{IncomingMessage,ServerResponse} from 'node:http';import{type AppOptions} from './app';export declare function isServerlessEnvironment(env?:NodeJS.ProcessEnv):boolean;export declare function createServerlessHandler(options?:AppOptions):(req:IncomingMessage,res:ServerResponse)=>void;export interface LambdaProxyResult{statusCode:number;headers:Record<string,string>;multiValueHeaders?:Record<string,string[]>;body:string;isBase64Encoded:boolean;}export declare function createLambdaHandler(options?:AppOptions):(event:any,_context?:any)=>Promise<LambdaProxyResult>;
|
package/dist/serverless.js
CHANGED
|
@@ -6,57 +6,35 @@ exports.createLambdaHandler = createLambdaHandler;
|
|
|
6
6
|
const node_http_1 = require("node:http");
|
|
7
7
|
const node_net_1 = require("node:net");
|
|
8
8
|
const app_1 = require("./app");
|
|
9
|
-
|
|
10
|
-
* Detects if the current process is running in a serverless environment
|
|
11
|
-
* (e.g. Vercel, AWS Lambda, Netlify Functions, Google Cloud Functions/Run, Azure Functions, Cloudflare Pages).
|
|
12
|
-
*/
|
|
9
|
+
const common_1 = require("./utils/common");
|
|
13
10
|
function isServerlessEnvironment(env = process.env) {
|
|
14
|
-
// Explicit serverless flags
|
|
15
11
|
if (['1', 'true', 'yes', 'on'].includes(String(env.ADMINDB_SERVERLESS ?? env.SERVERLESS ?? env.IS_SERVERLESS ?? '').trim().toLowerCase())) {
|
|
16
12
|
return true;
|
|
17
13
|
}
|
|
18
|
-
// Vercel Serverless Functions
|
|
19
14
|
if (Boolean(env.VERCEL || env.VERCEL_ENV || env.NOW_REGION)) {
|
|
20
15
|
return true;
|
|
21
16
|
}
|
|
22
|
-
// AWS Lambda
|
|
23
17
|
if (Boolean(env.AWS_LAMBDA_FUNCTION_NAME || env.LAMBDA_TASK_ROOT || env.AWS_EXECUTION_ENV)) {
|
|
24
18
|
return true;
|
|
25
19
|
}
|
|
26
|
-
// Netlify Functions
|
|
27
20
|
if (Boolean(env.NETLIFY || env.NETLIFY_LOCAL)) {
|
|
28
21
|
return true;
|
|
29
22
|
}
|
|
30
|
-
// Google Cloud Functions / Cloud Run
|
|
31
23
|
if (Boolean(env.FUNCTION_TARGET || env.FUNCTION_NAME || env.K_SERVICE)) {
|
|
32
24
|
return true;
|
|
33
25
|
}
|
|
34
|
-
// Azure Functions
|
|
35
26
|
if (Boolean(env.FUNCTIONS_WORKER_RUNTIME || env.WEBSITE_INSTANCE_ID)) {
|
|
36
27
|
return true;
|
|
37
28
|
}
|
|
38
|
-
// Cloudflare Pages
|
|
39
29
|
if (Boolean(env.CF_PAGES)) {
|
|
40
30
|
return true;
|
|
41
31
|
}
|
|
42
32
|
return false;
|
|
43
33
|
}
|
|
44
|
-
/**
|
|
45
|
-
* Creates an HTTP request listener for standard Node.js serverless runtimes
|
|
46
|
-
* (Vercel API routes, Next.js custom route handlers, Google Cloud Functions, Azure Functions, Micro).
|
|
47
|
-
*
|
|
48
|
-
* In serverless mode, all write operations and database mutations are strictly disabled.
|
|
49
|
-
*
|
|
50
|
-
* Example (Vercel `api/index.ts`):
|
|
51
|
-
* ```ts
|
|
52
|
-
* import { createServerlessHandler } from 'admindb';
|
|
53
|
-
* export default createServerlessHandler({ dbPath: './data.db' });
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
34
|
function createServerlessHandler(options = {}) {
|
|
57
35
|
const rawTarget = options.connection || options.dbPath || '';
|
|
58
36
|
const isPg = Boolean(options.pgOptions) ||
|
|
59
|
-
(
|
|
37
|
+
(0, common_1.isPostgresConnectionString)(rawTarget) ||
|
|
60
38
|
options.db?.dialect === 'postgres';
|
|
61
39
|
const defaultReadonly = isPg ? false : true;
|
|
62
40
|
const app = (0, app_1.createRouter)({
|
|
@@ -68,22 +46,10 @@ function createServerlessHandler(options = {}) {
|
|
|
68
46
|
app(req, res);
|
|
69
47
|
};
|
|
70
48
|
}
|
|
71
|
-
/**
|
|
72
|
-
* Creates an AWS Lambda handler for API Gateway (REST v1 and HTTP v2 payloads).
|
|
73
|
-
*
|
|
74
|
-
* In serverless mode, SQLite databases are read-only, while remote PostgreSQL
|
|
75
|
-
* connections are editable unless configured otherwise.
|
|
76
|
-
*
|
|
77
|
-
* Example (AWS Lambda `index.ts`):
|
|
78
|
-
* ```ts
|
|
79
|
-
* import { createLambdaHandler } from 'admindb';
|
|
80
|
-
* export const handler = createLambdaHandler({ dbPath: './data.db' });
|
|
81
|
-
* ```
|
|
82
|
-
*/
|
|
83
49
|
function createLambdaHandler(options = {}) {
|
|
84
50
|
const rawTarget = options.connection || options.dbPath || '';
|
|
85
51
|
const isPg = Boolean(options.pgOptions) ||
|
|
86
|
-
(
|
|
52
|
+
(0, common_1.isPostgresConnectionString)(rawTarget) ||
|
|
87
53
|
options.db?.dialect === 'postgres';
|
|
88
54
|
const defaultReadonly = isPg ? false : true;
|
|
89
55
|
const app = (0, app_1.createRouter)({
|
|
@@ -117,7 +83,6 @@ function createLambdaHandler(options = {}) {
|
|
|
117
83
|
if (event.cookies && Array.isArray(event.cookies) && !headers['cookie']) {
|
|
118
84
|
headers['cookie'] = event.cookies.join('; ');
|
|
119
85
|
}
|
|
120
|
-
// Prepare request body
|
|
121
86
|
let bodyBuffer = null;
|
|
122
87
|
if (event.body) {
|
|
123
88
|
if (event.isBase64Encoded) {
|
|
@@ -207,4 +172,3 @@ function createLambdaHandler(options = {}) {
|
|
|
207
172
|
});
|
|
208
173
|
};
|
|
209
174
|
}
|
|
210
|
-
//# sourceMappingURL=serverless.js.map
|
package/dist/sql/classifier.d.ts
CHANGED
|
@@ -1,19 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Classify incoming SQL as a read (SELECT), a count query, or a write
|
|
3
|
-
* statement, so the query runner can decide how to render/execute it.
|
|
4
|
-
*/
|
|
5
|
-
export type SqlKind = 'select' | 'count' | 'read' | 'write';
|
|
6
|
-
/** Extract the first keyword, skipping leading whitespace and comments. */
|
|
7
|
-
export declare function firstKeyword(sql: string): string;
|
|
8
|
-
export interface Classification {
|
|
9
|
-
kind: SqlKind;
|
|
10
|
-
keyword: string;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Classify a SQL statement.
|
|
14
|
-
* - SELECT / WITH → `select`, unless it is a pure `count(...)` (no GROUP BY)
|
|
15
|
-
* in which case it is `count`.
|
|
16
|
-
* - INSERT / UPDATE / DELETE / REPLACE / CREATE / DROP / ALTER → `write`.
|
|
17
|
-
* - Anything else that may still return rows (PRAGMA, EXPLAIN, …) → `read`.
|
|
18
|
-
*/
|
|
19
|
-
export declare function classifySql(sql: string): Classification;
|
|
1
|
+
export type SqlKind='select'|'count'|'read'|'write';export declare function firstKeyword(sql:string):string;export interface Classification{kind:SqlKind;keyword:string;}export declare function classifySql(sql:string):Classification;
|
package/dist/sql/classifier.js
CHANGED
|
@@ -1,25 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Classify incoming SQL as a read (SELECT), a count query, or a write
|
|
4
|
-
* statement, so the query runner can decide how to render/execute it.
|
|
5
|
-
*/
|
|
6
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
3
|
exports.firstKeyword = firstKeyword;
|
|
8
4
|
exports.classifySql = classifySql;
|
|
9
5
|
const LEADING_NOISE = /^\s*((\/\*[\s\S]*?\*\/)|(--[^\n]*\n))*\s*/;
|
|
10
|
-
/** Extract the first keyword, skipping leading whitespace and comments. */
|
|
11
6
|
function firstKeyword(sql) {
|
|
12
7
|
const cleaned = String(sql).replace(LEADING_NOISE, '').trim();
|
|
13
8
|
const m = cleaned.match(/^([a-zA-Z]+)/);
|
|
14
9
|
return m ? m[1].toUpperCase() : '';
|
|
15
10
|
}
|
|
16
|
-
/**
|
|
17
|
-
* Classify a SQL statement.
|
|
18
|
-
* - SELECT / WITH → `select`, unless it is a pure `count(...)` (no GROUP BY)
|
|
19
|
-
* in which case it is `count`.
|
|
20
|
-
* - INSERT / UPDATE / DELETE / REPLACE / CREATE / DROP / ALTER → `write`.
|
|
21
|
-
* - Anything else that may still return rows (PRAGMA, EXPLAIN, …) → `read`.
|
|
22
|
-
*/
|
|
23
11
|
function classifySql(sql) {
|
|
24
12
|
const keyword = firstKeyword(sql);
|
|
25
13
|
if (keyword === 'SELECT' || keyword === 'WITH') {
|
|
@@ -34,4 +22,3 @@ function classifySql(sql) {
|
|
|
34
22
|
}
|
|
35
23
|
return { kind: 'read', keyword: keyword || 'UNKNOWN' };
|
|
36
24
|
}
|
|
37
|
-
//# sourceMappingURL=classifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import type {IDatabase} from '../db/types';export interface SqlErrorDetails{message:string;line?:number;column?:number;token?:string;snippet?:string;cause?:string;suggestion?:string;raw?:string;}export declare function buildErrorSnippet(sql:string,line:number,column:number):string;export declare function offsetToLineCol(sql:string,offset:number):{line:number;column:number;};export declare function maskCommentsAndStrings(sql:string):string;export declare function findTokenPosition(sql:string,token:string):{line:number;column:number;}|null;export declare function analyzeSqlError(sql:string,rawError:unknown,db?:IDatabase):Promise<SqlErrorDetails>;
|