@ereo/db-drizzle 0.1.28 → 0.1.31
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/adapter.d.ts +16 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +30 -3
- package/package.json +2 -2
package/dist/adapter.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* with support for multiple database drivers.
|
|
6
6
|
*/
|
|
7
7
|
import { type DatabaseAdapter } from '@ereo/db';
|
|
8
|
-
import type { DrizzleConfig } from './types';
|
|
8
|
+
import type { DrizzleConfig, BunSQLiteConfig } from './types';
|
|
9
9
|
/**
|
|
10
10
|
* Create a Drizzle database adapter.
|
|
11
11
|
*
|
|
@@ -20,4 +20,19 @@ import type { DrizzleConfig } from './types';
|
|
|
20
20
|
* });
|
|
21
21
|
*/
|
|
22
22
|
export declare function createDrizzleAdapter<TSchema = unknown>(config: DrizzleConfig): DatabaseAdapter<TSchema>;
|
|
23
|
+
/**
|
|
24
|
+
* Valid PRAGMA journal modes for SQLite.
|
|
25
|
+
*/
|
|
26
|
+
export declare const VALID_JOURNAL_MODES: readonly ["DELETE", "TRUNCATE", "PERSIST", "MEMORY", "WAL", "OFF"];
|
|
27
|
+
/**
|
|
28
|
+
* Valid PRAGMA synchronous modes for SQLite.
|
|
29
|
+
*/
|
|
30
|
+
export declare const VALID_SYNCHRONOUS: readonly ["OFF", "NORMAL", "FULL", "EXTRA"];
|
|
31
|
+
/**
|
|
32
|
+
* Validate PRAGMA configuration values.
|
|
33
|
+
* Defense-in-depth: runtime validation prevents SQL injection even if TypeScript types are bypassed.
|
|
34
|
+
*
|
|
35
|
+
* @throws {Error} If any PRAGMA value is invalid
|
|
36
|
+
*/
|
|
37
|
+
export declare function validatePragmaConfig(pragma: NonNullable<BunSQLiteConfig['pragma']>): void;
|
|
23
38
|
//# sourceMappingURL=adapter.d.ts.map
|
package/dist/adapter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACL,KAAK,eAAe,EAgBrB,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EACV,aAAa,
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACL,KAAK,eAAe,EAgBrB,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EACV,aAAa,EAOb,eAAe,EAGhB,MAAM,SAAS,CAAC;AAyQjB;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,GAAG,OAAO,EACpD,MAAM,EAAE,aAAa,GACpB,eAAe,CAAC,OAAO,CAAC,CAE1B;AA6HD;;GAEG;AACH,eAAO,MAAM,mBAAmB,oEAAqE,CAAC;AAEtG;;GAEG;AACH,eAAO,MAAM,iBAAiB,6CAA8C,CAAC;AAE7E;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,WAAW,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAI,CAkBzF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
*
|
|
35
35
|
* @packageDocumentation
|
|
36
36
|
*/
|
|
37
|
-
export { createDrizzleAdapter } from './adapter';
|
|
37
|
+
export { createDrizzleAdapter, validatePragmaConfig, VALID_JOURNAL_MODES, VALID_SYNCHRONOUS, } from './adapter';
|
|
38
38
|
export { defineDrizzleConfig, definePostgresConfig, defineNeonHttpConfig, defineNeonWebSocketConfig, definePlanetScaleConfig, defineLibSQLConfig, defineBunSQLiteConfig, defineBetterSQLite3Config, defineD1Config, defineEdgeConfig, detectRuntime, isEdgeRuntime, suggestDrivers, type EdgeConfigOptions, type RuntimeEnvironment, } from './config';
|
|
39
39
|
export { type DrizzleDriver, type DrizzleConfig, type DrizzleClient, type PostgresConfig, type NeonHttpConfig, type NeonWebSocketConfig, type PlanetScaleConfig, type LibSQLConfig, type BunSQLiteConfig, type BetterSQLite3Config, type D1Config, EDGE_COMPATIBLE_DRIVERS, type D1Database, type D1PreparedStatement, type D1Result, type D1ExecResult, } from './types';
|
|
40
40
|
export { createDatabasePlugin, useDb, useAdapter, getDb, withTransaction, type DatabaseAdapter, type RequestScopedClient, type QueryResult, type MutationResult, type DedupResult, type DedupStats, type TransactionOptions, } from '@ereo/db';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAMH,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAMH,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,WAAW,CAAC;AAMnB,OAAO,EAEL,mBAAmB,EAEnB,oBAAoB,EACpB,oBAAoB,EACpB,yBAAyB,EACzB,uBAAuB,EACvB,kBAAkB,EAClB,qBAAqB,EACrB,yBAAyB,EACzB,cAAc,EAEd,gBAAgB,EAEhB,aAAa,EACb,aAAa,EACb,cAAc,EAEd,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,GACxB,MAAM,UAAU,CAAC;AAMlB,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,aAAa,EAElB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,QAAQ,EAEb,uBAAuB,EAEvB,KAAK,UAAU,EACf,KAAK,mBAAmB,EACxB,KAAK,QAAQ,EACb,KAAK,YAAY,GAClB,MAAM,SAAS,CAAC;AAMjB,OAAO,EAEL,oBAAoB,EACpB,KAAK,EACL,UAAU,EACV,KAAK,EACL,eAAe,EAEf,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,kBAAkB,GACxB,MAAM,UAAU,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -284,20 +284,44 @@ async function createLibSQLClient(config) {
|
|
|
284
284
|
});
|
|
285
285
|
return { client, connection };
|
|
286
286
|
}
|
|
287
|
+
var VALID_JOURNAL_MODES = ["DELETE", "TRUNCATE", "PERSIST", "MEMORY", "WAL", "OFF"];
|
|
288
|
+
var VALID_SYNCHRONOUS = ["OFF", "NORMAL", "FULL", "EXTRA"];
|
|
289
|
+
function validatePragmaConfig(pragma) {
|
|
290
|
+
const { journal_mode, synchronous, cache_size } = pragma;
|
|
291
|
+
if (journal_mode) {
|
|
292
|
+
if (!VALID_JOURNAL_MODES.includes(journal_mode)) {
|
|
293
|
+
throw new Error(`Invalid journal_mode: ${journal_mode}`);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
if (synchronous) {
|
|
297
|
+
if (!VALID_SYNCHRONOUS.includes(synchronous)) {
|
|
298
|
+
throw new Error(`Invalid synchronous mode: ${synchronous}`);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
if (cache_size !== undefined && cache_size !== 0) {
|
|
302
|
+
if (!Number.isInteger(cache_size)) {
|
|
303
|
+
throw new Error(`Invalid cache_size: ${cache_size}`);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
287
307
|
async function createBunSQLiteClient(config) {
|
|
288
308
|
const sqliteModule = await import("bun:sqlite");
|
|
289
309
|
const drizzleModule = await import("drizzle-orm/bun-sqlite");
|
|
290
310
|
const connection = new sqliteModule.Database(config.url);
|
|
291
311
|
if (config.pragma) {
|
|
312
|
+
validatePragmaConfig(config.pragma);
|
|
292
313
|
const { journal_mode, synchronous, foreign_keys, cache_size } = config.pragma;
|
|
293
|
-
if (journal_mode)
|
|
314
|
+
if (journal_mode) {
|
|
294
315
|
connection.exec(`PRAGMA journal_mode = ${journal_mode}`);
|
|
295
|
-
|
|
316
|
+
}
|
|
317
|
+
if (synchronous) {
|
|
296
318
|
connection.exec(`PRAGMA synchronous = ${synchronous}`);
|
|
319
|
+
}
|
|
297
320
|
if (foreign_keys !== undefined)
|
|
298
321
|
connection.exec(`PRAGMA foreign_keys = ${foreign_keys ? "ON" : "OFF"}`);
|
|
299
|
-
if (cache_size)
|
|
322
|
+
if (cache_size) {
|
|
300
323
|
connection.exec(`PRAGMA cache_size = ${cache_size}`);
|
|
324
|
+
}
|
|
301
325
|
}
|
|
302
326
|
const client = drizzleModule.drizzle(connection, {
|
|
303
327
|
schema: config.schema,
|
|
@@ -631,6 +655,7 @@ import {
|
|
|
631
655
|
} from "@ereo/db";
|
|
632
656
|
export {
|
|
633
657
|
withTransaction,
|
|
658
|
+
validatePragmaConfig,
|
|
634
659
|
useDb,
|
|
635
660
|
useAdapter,
|
|
636
661
|
suggestDrivers,
|
|
@@ -649,5 +674,7 @@ export {
|
|
|
649
674
|
defineBetterSQLite3Config,
|
|
650
675
|
createDrizzleAdapter,
|
|
651
676
|
createDatabasePlugin,
|
|
677
|
+
VALID_SYNCHRONOUS,
|
|
678
|
+
VALID_JOURNAL_MODES,
|
|
652
679
|
EDGE_COMPATIBLE_DRIVERS
|
|
653
680
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ereo/db-drizzle",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.31",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Ereo Team",
|
|
6
6
|
"homepage": "https://ereo.dev",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"typecheck": "tsc --noEmit"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@ereo/db": "^0.1.
|
|
36
|
+
"@ereo/db": "^0.1.31",
|
|
37
37
|
"drizzle-orm": "^0.30.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|