@agentxjs/persistence 1.5.10 → 1.5.11
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 +6 -1
- package/dist/drivers/sqlite.js +15 -3
- package/dist/drivers/sqlite.js.map +3 -3
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
- **Subpath Exports** - Import only the driver you need (tree-shaking friendly)
|
|
16
16
|
- **Multiple Backends** - SQLite, Redis, MongoDB, MySQL, PostgreSQL
|
|
17
17
|
- **Zero Config Default** - Memory driver works out of the box
|
|
18
|
-
- **
|
|
18
|
+
- **Cross-Runtime** - SQLite driver works on both Bun and Node.js 22+
|
|
19
19
|
|
|
20
20
|
## Installation
|
|
21
21
|
|
|
@@ -67,6 +67,11 @@ const persistence = await createPersistence(redisDriver({ url: "redis://localhos
|
|
|
67
67
|
|
|
68
68
|
### SQLite
|
|
69
69
|
|
|
70
|
+
Automatically detects runtime:
|
|
71
|
+
|
|
72
|
+
- **Bun**: uses `bun:sqlite` (built-in)
|
|
73
|
+
- **Node.js 22+**: uses `node:sqlite` (built-in)
|
|
74
|
+
|
|
70
75
|
```typescript
|
|
71
76
|
sqliteDriver({
|
|
72
77
|
path: "./data.db", // Database file path
|
package/dist/drivers/sqlite.js
CHANGED
|
@@ -19,13 +19,25 @@ var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
|
19
19
|
|
|
20
20
|
// src/drivers/sqlite.ts
|
|
21
21
|
import { createStorage } from "unstorage";
|
|
22
|
+
async function getSqliteConnector(path) {
|
|
23
|
+
if (typeof Bun !== "undefined") {
|
|
24
|
+
const { default: bunSqliteConnector } = await import("db0/connectors/bun-sqlite");
|
|
25
|
+
return bunSqliteConnector({ path });
|
|
26
|
+
}
|
|
27
|
+
const nodeSqlite = globalThis.process?.getBuiltinModule?.("node:sqlite");
|
|
28
|
+
if (nodeSqlite) {
|
|
29
|
+
const { default: nodeSqliteConnector } = await import("db0/connectors/node-sqlite");
|
|
30
|
+
return nodeSqliteConnector({ path });
|
|
31
|
+
}
|
|
32
|
+
throw new Error("No SQLite driver available. Requires Bun runtime or Node.js 22+.");
|
|
33
|
+
}
|
|
22
34
|
function sqliteDriver(options) {
|
|
23
35
|
return {
|
|
24
36
|
async createStorage() {
|
|
25
37
|
const { default: db0Driver } = await import("unstorage/drivers/db0");
|
|
26
38
|
const { createDatabase } = await import("db0");
|
|
27
|
-
const
|
|
28
|
-
const database = createDatabase(
|
|
39
|
+
const connector = await getSqliteConnector(options.path);
|
|
40
|
+
const database = createDatabase(connector);
|
|
29
41
|
return createStorage({
|
|
30
42
|
driver: db0Driver({ database })
|
|
31
43
|
});
|
|
@@ -36,4 +48,4 @@ export {
|
|
|
36
48
|
sqliteDriver
|
|
37
49
|
};
|
|
38
50
|
|
|
39
|
-
//# debugId=
|
|
51
|
+
//# debugId=9C750D9F3C5B308064756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/drivers/sqlite.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/**\n * SQLite Driver - SQLite database storage\n *\n * Uses db0 with
|
|
5
|
+
"/**\n * SQLite Driver - SQLite database storage\n *\n * Uses db0 with automatic runtime detection:\n * - Bun: uses bun:sqlite (built-in)\n * - Node.js 22+: uses node:sqlite (built-in)\n *\n * @example\n * ```typescript\n * import { createPersistence } from \"@agentxjs/persistence\";\n * import { sqliteDriver } from \"@agentxjs/persistence/sqlite\";\n *\n * const persistence = await createPersistence(\n * sqliteDriver({ path: \"./data/agentx.db\" })\n * );\n * ```\n */\n\nimport { createStorage, type Storage } from \"unstorage\";\nimport type { PersistenceDriver } from \"../Persistence\";\n\ndeclare const Bun: unknown;\n\nexport interface SqliteDriverOptions {\n /**\n * Path to SQLite database file\n * @example \"./data/agentx.db\"\n */\n path: string;\n}\n\n/**\n * Detect runtime and return appropriate SQLite connector\n */\nasync function getSqliteConnector(path: string) {\n // Bun runtime - use bun:sqlite\n if (typeof Bun !== \"undefined\") {\n const { default: bunSqliteConnector } = await import(\"db0/connectors/bun-sqlite\");\n return bunSqliteConnector({ path });\n }\n\n // Node.js 22+ - use built-in node:sqlite\n const nodeSqlite = globalThis.process?.getBuiltinModule?.(\"node:sqlite\");\n if (nodeSqlite) {\n const { default: nodeSqliteConnector } = await import(\"db0/connectors/node-sqlite\");\n return nodeSqliteConnector({ path });\n }\n\n throw new Error(\"No SQLite driver available. Requires Bun runtime or Node.js 22+.\");\n}\n\n/**\n * Create a SQLite driver\n *\n * @param options - Driver options\n */\nexport function sqliteDriver(options: SqliteDriverOptions): PersistenceDriver {\n return {\n async createStorage(): Promise<Storage> {\n // Dynamic imports to avoid bundling when not used\n const { default: db0Driver } = await import(\"unstorage/drivers/db0\");\n const { createDatabase } = await import(\"db0\");\n\n const connector = await getSqliteConnector(options.path);\n const database = createDatabase(connector);\n\n return createStorage({\n driver: db0Driver({ database }),\n });\n },\n };\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAkBA;AAgBA,eAAe,kBAAkB,CAAC,MAAc;AAAA,EAE9C,IAAI,OAAO,QAAQ,aAAa;AAAA,IAC9B,QAAQ,SAAS,uBAAuB,MAAa;AAAA,IACrD,OAAO,mBAAmB,EAAE,KAAK,CAAC;AAAA,EACpC;AAAA,EAGA,MAAM,aAAa,WAAW,SAAS,mBAAmB,aAAa;AAAA,EACvE,IAAI,YAAY;AAAA,IACd,QAAQ,SAAS,wBAAwB,MAAa;AAAA,IACtD,OAAO,oBAAoB,EAAE,KAAK,CAAC;AAAA,EACrC;AAAA,EAEA,MAAM,IAAI,MAAM,kEAAkE;AAAA;AAQ7E,SAAS,YAAY,CAAC,SAAiD;AAAA,EAC5E,OAAO;AAAA,SACC,cAAa,GAAqB;AAAA,MAEtC,QAAQ,SAAS,cAAc,MAAa;AAAA,MAC5C,QAAQ,mBAAmB,MAAa;AAAA,MAExC,MAAM,YAAY,MAAM,mBAAmB,QAAQ,IAAI;AAAA,MACvD,MAAM,WAAW,eAAe,SAAS;AAAA,MAEzC,OAAO,cAAc;AAAA,QACnB,QAAQ,UAAU,EAAE,SAAS,CAAC;AAAA,MAChC,CAAC;AAAA;AAAA,EAEL;AAAA;",
|
|
8
|
+
"debugId": "9C750D9F3C5B308064756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentxjs/persistence",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.11",
|
|
4
4
|
"description": "Multi-backend persistence layer for AgentX - supports memory, SQLite, Redis, MongoDB, and SQL databases",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agentx",
|
|
@@ -16,6 +16,9 @@
|
|
|
16
16
|
"directory": "packages/persistence"
|
|
17
17
|
},
|
|
18
18
|
"license": "MIT",
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=22.0.0"
|
|
21
|
+
},
|
|
19
22
|
"type": "module",
|
|
20
23
|
"main": "./dist/index.js",
|
|
21
24
|
"types": "./dist/index.d.ts",
|
|
@@ -60,8 +63,8 @@
|
|
|
60
63
|
"clean": "rm -rf dist"
|
|
61
64
|
},
|
|
62
65
|
"dependencies": {
|
|
63
|
-
"@agentxjs/common": "^1.5.
|
|
64
|
-
"@agentxjs/types": "^1.5.
|
|
66
|
+
"@agentxjs/common": "^1.5.11",
|
|
67
|
+
"@agentxjs/types": "^1.5.11",
|
|
65
68
|
"unstorage": "^1.14.4"
|
|
66
69
|
},
|
|
67
70
|
"peerDependencies": {
|