@nicia-ai/typegraph 0.1.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/LICENSE +21 -0
- package/README.md +47 -0
- package/dist/ast-BVyihVbP.d.cts +564 -0
- package/dist/ast-BVyihVbP.d.ts +564 -0
- package/dist/backend/drizzle/index.cjs +41 -0
- package/dist/backend/drizzle/index.cjs.map +1 -0
- package/dist/backend/drizzle/index.d.cts +12 -0
- package/dist/backend/drizzle/index.d.ts +12 -0
- package/dist/backend/drizzle/index.js +12 -0
- package/dist/backend/drizzle/index.js.map +1 -0
- package/dist/backend/drizzle/postgres.cjs +27 -0
- package/dist/backend/drizzle/postgres.cjs.map +1 -0
- package/dist/backend/drizzle/postgres.d.cts +37 -0
- package/dist/backend/drizzle/postgres.d.ts +37 -0
- package/dist/backend/drizzle/postgres.js +10 -0
- package/dist/backend/drizzle/postgres.js.map +1 -0
- package/dist/backend/drizzle/schema/postgres.cjs +40 -0
- package/dist/backend/drizzle/schema/postgres.cjs.map +1 -0
- package/dist/backend/drizzle/schema/postgres.d.cts +2419 -0
- package/dist/backend/drizzle/schema/postgres.d.ts +2419 -0
- package/dist/backend/drizzle/schema/postgres.js +7 -0
- package/dist/backend/drizzle/schema/postgres.js.map +1 -0
- package/dist/backend/drizzle/schema/sqlite.cjs +40 -0
- package/dist/backend/drizzle/schema/sqlite.cjs.map +1 -0
- package/dist/backend/drizzle/schema/sqlite.d.cts +2647 -0
- package/dist/backend/drizzle/schema/sqlite.d.ts +2647 -0
- package/dist/backend/drizzle/schema/sqlite.js +7 -0
- package/dist/backend/drizzle/schema/sqlite.js.map +1 -0
- package/dist/backend/drizzle/sqlite.cjs +27 -0
- package/dist/backend/drizzle/sqlite.cjs.map +1 -0
- package/dist/backend/drizzle/sqlite.d.cts +36 -0
- package/dist/backend/drizzle/sqlite.d.ts +36 -0
- package/dist/backend/drizzle/sqlite.js +10 -0
- package/dist/backend/drizzle/sqlite.js.map +1 -0
- package/dist/backend/postgres/index.cjs +53 -0
- package/dist/backend/postgres/index.cjs.map +1 -0
- package/dist/backend/postgres/index.d.cts +12 -0
- package/dist/backend/postgres/index.d.ts +12 -0
- package/dist/backend/postgres/index.js +12 -0
- package/dist/backend/postgres/index.js.map +1 -0
- package/dist/backend/sqlite/index.cjs +117 -0
- package/dist/backend/sqlite/index.cjs.map +1 -0
- package/dist/backend/sqlite/index.d.cts +71 -0
- package/dist/backend/sqlite/index.d.ts +71 -0
- package/dist/backend/sqlite/index.js +78 -0
- package/dist/backend/sqlite/index.js.map +1 -0
- package/dist/chunk-2QHQ2C4P.js +146 -0
- package/dist/chunk-2QHQ2C4P.js.map +1 -0
- package/dist/chunk-3A5TKOEJ.js +306 -0
- package/dist/chunk-3A5TKOEJ.js.map +1 -0
- package/dist/chunk-4PIEL2VO.js +162 -0
- package/dist/chunk-4PIEL2VO.js.map +1 -0
- package/dist/chunk-536PH5FT.js +342 -0
- package/dist/chunk-536PH5FT.js.map +1 -0
- package/dist/chunk-DBFCKELK.cjs +156 -0
- package/dist/chunk-DBFCKELK.cjs.map +1 -0
- package/dist/chunk-DDM2FZRJ.cjs +1143 -0
- package/dist/chunk-DDM2FZRJ.cjs.map +1 -0
- package/dist/chunk-DGUM43GV.js +10 -0
- package/dist/chunk-DGUM43GV.js.map +1 -0
- package/dist/chunk-F32HCHYA.cjs +680 -0
- package/dist/chunk-F32HCHYA.cjs.map +1 -0
- package/dist/chunk-IIAT36MI.js +353 -0
- package/dist/chunk-IIAT36MI.js.map +1 -0
- package/dist/chunk-JDAET5LO.js +236 -0
- package/dist/chunk-JDAET5LO.js.map +1 -0
- package/dist/chunk-JEQ2X3Z6.cjs +12 -0
- package/dist/chunk-JEQ2X3Z6.cjs.map +1 -0
- package/dist/chunk-JKTO7TW3.js +299 -0
- package/dist/chunk-JKTO7TW3.js.map +1 -0
- package/dist/chunk-K7SQ3SWP.js +497 -0
- package/dist/chunk-K7SQ3SWP.js.map +1 -0
- package/dist/chunk-L642L24T.js +142 -0
- package/dist/chunk-L642L24T.js.map +1 -0
- package/dist/chunk-MFVCSNIY.cjs +308 -0
- package/dist/chunk-MFVCSNIY.cjs.map +1 -0
- package/dist/chunk-MNO33ASC.cjs +240 -0
- package/dist/chunk-MNO33ASC.cjs.map +1 -0
- package/dist/chunk-N4AOJ3VF.cjs +154 -0
- package/dist/chunk-N4AOJ3VF.cjs.map +1 -0
- package/dist/chunk-P5CNM325.cjs +508 -0
- package/dist/chunk-P5CNM325.cjs.map +1 -0
- package/dist/chunk-RYT4H46I.js +646 -0
- package/dist/chunk-RYT4H46I.js.map +1 -0
- package/dist/chunk-SV5H3XM5.cjs +321 -0
- package/dist/chunk-SV5H3XM5.cjs.map +1 -0
- package/dist/chunk-TXHKFLWX.cjs +344 -0
- package/dist/chunk-TXHKFLWX.cjs.map +1 -0
- package/dist/chunk-UJAGXJDG.cjs +170 -0
- package/dist/chunk-UJAGXJDG.cjs.map +1 -0
- package/dist/chunk-VXRVGFCI.js +1128 -0
- package/dist/chunk-VXRVGFCI.js.map +1 -0
- package/dist/chunk-YM5AL65Y.cjs +357 -0
- package/dist/chunk-YM5AL65Y.cjs.map +1 -0
- package/dist/index.cjs +8334 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1365 -0
- package/dist/index.d.ts +1365 -0
- package/dist/index.js +8105 -0
- package/dist/index.js.map +1 -0
- package/dist/indexes/index.cjs +67 -0
- package/dist/indexes/index.cjs.map +1 -0
- package/dist/indexes/index.d.cts +62 -0
- package/dist/indexes/index.d.ts +62 -0
- package/dist/indexes/index.js +6 -0
- package/dist/indexes/index.js.map +1 -0
- package/dist/interchange/index.cjs +612 -0
- package/dist/interchange/index.cjs.map +1 -0
- package/dist/interchange/index.d.cts +288 -0
- package/dist/interchange/index.d.ts +288 -0
- package/dist/interchange/index.js +598 -0
- package/dist/interchange/index.js.map +1 -0
- package/dist/profiler/index.cjs +793 -0
- package/dist/profiler/index.cjs.map +1 -0
- package/dist/profiler/index.d.cts +283 -0
- package/dist/profiler/index.d.ts +283 -0
- package/dist/profiler/index.js +785 -0
- package/dist/profiler/index.js.map +1 -0
- package/dist/store-60Lcfi0w.d.ts +2263 -0
- package/dist/store-Bifii8MZ.d.cts +2263 -0
- package/dist/test-helpers-BjyRYJZX.d.ts +22 -0
- package/dist/test-helpers-NoQXhleQ.d.cts +22 -0
- package/dist/types-BRzHlhKC.d.cts +14 -0
- package/dist/types-BRzHlhKC.d.ts +14 -0
- package/dist/types-BrSfFSpW.d.cts +158 -0
- package/dist/types-CX4cLd7M.d.ts +152 -0
- package/dist/types-CjZ7g_7v.d.ts +442 -0
- package/dist/types-DDOSfrih.d.cts +442 -0
- package/dist/types-D_3mEv2y.d.ts +158 -0
- package/dist/types-a5rAxC92.d.cts +152 -0
- package/package.json +201 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { createSqliteTables, edges, embeddings, nodes, schemaVersions, tables, uniques } from '../../../chunk-2QHQ2C4P.js';
|
|
2
|
+
import '../../../chunk-VXRVGFCI.js';
|
|
3
|
+
import '../../../chunk-IIAT36MI.js';
|
|
4
|
+
import '../../../chunk-K7SQ3SWP.js';
|
|
5
|
+
import '../../../chunk-DGUM43GV.js';
|
|
6
|
+
//# sourceMappingURL=sqlite.js.map
|
|
7
|
+
//# sourceMappingURL=sqlite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"sqlite.js"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkMFVCSNIY_cjs = require('../../chunk-MFVCSNIY.cjs');
|
|
4
|
+
require('../../chunk-F32HCHYA.cjs');
|
|
5
|
+
var chunkN4AOJ3VF_cjs = require('../../chunk-N4AOJ3VF.cjs');
|
|
6
|
+
require('../../chunk-SV5H3XM5.cjs');
|
|
7
|
+
require('../../chunk-DDM2FZRJ.cjs');
|
|
8
|
+
require('../../chunk-YM5AL65Y.cjs');
|
|
9
|
+
require('../../chunk-P5CNM325.cjs');
|
|
10
|
+
require('../../chunk-JEQ2X3Z6.cjs');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
Object.defineProperty(exports, "createSqliteBackend", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () { return chunkMFVCSNIY_cjs.createSqliteBackend; }
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "createSqliteTables", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () { return chunkN4AOJ3VF_cjs.createSqliteTables; }
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(exports, "tables", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function () { return chunkN4AOJ3VF_cjs.tables; }
|
|
25
|
+
});
|
|
26
|
+
//# sourceMappingURL=sqlite.cjs.map
|
|
27
|
+
//# sourceMappingURL=sqlite.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"sqlite.cjs"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { BaseSQLiteDatabase } from 'drizzle-orm/sqlite-core';
|
|
2
|
+
import { G as GraphBackend } from '../../types-DDOSfrih.cjs';
|
|
3
|
+
import { SqliteTables } from './schema/sqlite.cjs';
|
|
4
|
+
export { TableNames, createSqliteTables, tables } from './schema/sqlite.cjs';
|
|
5
|
+
import 'drizzle-orm';
|
|
6
|
+
import '../../types-BRzHlhKC.cjs';
|
|
7
|
+
import '../../types-a5rAxC92.cjs';
|
|
8
|
+
import 'zod';
|
|
9
|
+
import '../../ast-BVyihVbP.cjs';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Options for creating a SQLite backend.
|
|
13
|
+
*/
|
|
14
|
+
type SqliteBackendOptions = Readonly<{
|
|
15
|
+
/**
|
|
16
|
+
* Custom table definitions. Use createSqliteTables() to customize table names.
|
|
17
|
+
* Defaults to standard TypeGraph table names.
|
|
18
|
+
*/
|
|
19
|
+
tables?: SqliteTables;
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* Any Drizzle SQLite database instance.
|
|
23
|
+
*/
|
|
24
|
+
type AnySqliteDatabase = BaseSQLiteDatabase<"sync" | "async", unknown>;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a TypeGraph backend for SQLite databases.
|
|
27
|
+
*
|
|
28
|
+
* Works with any Drizzle SQLite instance regardless of the underlying driver.
|
|
29
|
+
*
|
|
30
|
+
* @param db - A Drizzle SQLite database instance
|
|
31
|
+
* @param options - Backend configuration
|
|
32
|
+
* @returns A GraphBackend implementation
|
|
33
|
+
*/
|
|
34
|
+
declare function createSqliteBackend(db: AnySqliteDatabase, options?: SqliteBackendOptions): GraphBackend;
|
|
35
|
+
|
|
36
|
+
export { type SqliteBackendOptions, SqliteTables, createSqliteBackend };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { BaseSQLiteDatabase } from 'drizzle-orm/sqlite-core';
|
|
2
|
+
import { G as GraphBackend } from '../../types-CjZ7g_7v.js';
|
|
3
|
+
import { SqliteTables } from './schema/sqlite.js';
|
|
4
|
+
export { TableNames, createSqliteTables, tables } from './schema/sqlite.js';
|
|
5
|
+
import 'drizzle-orm';
|
|
6
|
+
import '../../types-BRzHlhKC.js';
|
|
7
|
+
import '../../types-CX4cLd7M.js';
|
|
8
|
+
import 'zod';
|
|
9
|
+
import '../../ast-BVyihVbP.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Options for creating a SQLite backend.
|
|
13
|
+
*/
|
|
14
|
+
type SqliteBackendOptions = Readonly<{
|
|
15
|
+
/**
|
|
16
|
+
* Custom table definitions. Use createSqliteTables() to customize table names.
|
|
17
|
+
* Defaults to standard TypeGraph table names.
|
|
18
|
+
*/
|
|
19
|
+
tables?: SqliteTables;
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* Any Drizzle SQLite database instance.
|
|
23
|
+
*/
|
|
24
|
+
type AnySqliteDatabase = BaseSQLiteDatabase<"sync" | "async", unknown>;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a TypeGraph backend for SQLite databases.
|
|
27
|
+
*
|
|
28
|
+
* Works with any Drizzle SQLite instance regardless of the underlying driver.
|
|
29
|
+
*
|
|
30
|
+
* @param db - A Drizzle SQLite database instance
|
|
31
|
+
* @param options - Backend configuration
|
|
32
|
+
* @returns A GraphBackend implementation
|
|
33
|
+
*/
|
|
34
|
+
declare function createSqliteBackend(db: AnySqliteDatabase, options?: SqliteBackendOptions): GraphBackend;
|
|
35
|
+
|
|
36
|
+
export { type SqliteBackendOptions, SqliteTables, createSqliteBackend };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { createSqliteBackend } from '../../chunk-3A5TKOEJ.js';
|
|
2
|
+
import '../../chunk-RYT4H46I.js';
|
|
3
|
+
export { createSqliteTables, tables } from '../../chunk-2QHQ2C4P.js';
|
|
4
|
+
import '../../chunk-JKTO7TW3.js';
|
|
5
|
+
import '../../chunk-VXRVGFCI.js';
|
|
6
|
+
import '../../chunk-IIAT36MI.js';
|
|
7
|
+
import '../../chunk-K7SQ3SWP.js';
|
|
8
|
+
import '../../chunk-DGUM43GV.js';
|
|
9
|
+
//# sourceMappingURL=sqlite.js.map
|
|
10
|
+
//# sourceMappingURL=sqlite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"sqlite.js"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkMNO33ASC_cjs = require('../../chunk-MNO33ASC.cjs');
|
|
4
|
+
var chunkTXHKFLWX_cjs = require('../../chunk-TXHKFLWX.cjs');
|
|
5
|
+
var chunkUJAGXJDG_cjs = require('../../chunk-UJAGXJDG.cjs');
|
|
6
|
+
require('../../chunk-F32HCHYA.cjs');
|
|
7
|
+
require('../../chunk-N4AOJ3VF.cjs');
|
|
8
|
+
require('../../chunk-SV5H3XM5.cjs');
|
|
9
|
+
require('../../chunk-DDM2FZRJ.cjs');
|
|
10
|
+
require('../../chunk-YM5AL65Y.cjs');
|
|
11
|
+
require('../../chunk-P5CNM325.cjs');
|
|
12
|
+
require('../../chunk-JEQ2X3Z6.cjs');
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
Object.defineProperty(exports, "getPostgresMigrationSQL", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () { return chunkMNO33ASC_cjs.getPostgresMigrationSQL; }
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(exports, "createPostgresBackend", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () { return chunkTXHKFLWX_cjs.createPostgresBackend; }
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "createPostgresTables", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () { return chunkUJAGXJDG_cjs.createPostgresTables; }
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports, "edges", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function () { return chunkUJAGXJDG_cjs.edges; }
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(exports, "embeddings", {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () { return chunkUJAGXJDG_cjs.embeddings; }
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "nodes", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () { return chunkUJAGXJDG_cjs.nodes; }
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(exports, "schemaVersions", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
get: function () { return chunkUJAGXJDG_cjs.schemaVersions; }
|
|
43
|
+
});
|
|
44
|
+
Object.defineProperty(exports, "tables", {
|
|
45
|
+
enumerable: true,
|
|
46
|
+
get: function () { return chunkUJAGXJDG_cjs.tables; }
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "uniques", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () { return chunkUJAGXJDG_cjs.uniques; }
|
|
51
|
+
});
|
|
52
|
+
//# sourceMappingURL=index.cjs.map
|
|
53
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.cjs"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { PostgresBackendOptions, createPostgresBackend } from '../drizzle/postgres.cjs';
|
|
2
|
+
export { PostgresTables, TableNames, createPostgresTables, edges, embeddings, nodes, schemaVersions, tables, uniques } from '../drizzle/schema/postgres.cjs';
|
|
3
|
+
export { g as getPostgresMigrationSQL } from '../../test-helpers-NoQXhleQ.cjs';
|
|
4
|
+
import 'drizzle-orm/pg-core';
|
|
5
|
+
import '../../types-DDOSfrih.cjs';
|
|
6
|
+
import 'drizzle-orm';
|
|
7
|
+
import '../../types-BRzHlhKC.cjs';
|
|
8
|
+
import '../../types-a5rAxC92.cjs';
|
|
9
|
+
import 'zod';
|
|
10
|
+
import '../../ast-BVyihVbP.cjs';
|
|
11
|
+
import '../drizzle/schema/sqlite.cjs';
|
|
12
|
+
import 'drizzle-orm/sqlite-core';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { PostgresBackendOptions, createPostgresBackend } from '../drizzle/postgres.js';
|
|
2
|
+
export { PostgresTables, TableNames, createPostgresTables, edges, embeddings, nodes, schemaVersions, tables, uniques } from '../drizzle/schema/postgres.js';
|
|
3
|
+
export { g as getPostgresMigrationSQL } from '../../test-helpers-BjyRYJZX.js';
|
|
4
|
+
import 'drizzle-orm/pg-core';
|
|
5
|
+
import '../../types-CjZ7g_7v.js';
|
|
6
|
+
import 'drizzle-orm';
|
|
7
|
+
import '../../types-BRzHlhKC.js';
|
|
8
|
+
import '../../types-CX4cLd7M.js';
|
|
9
|
+
import 'zod';
|
|
10
|
+
import '../../ast-BVyihVbP.js';
|
|
11
|
+
import '../drizzle/schema/sqlite.js';
|
|
12
|
+
import 'drizzle-orm/sqlite-core';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { getPostgresMigrationSQL } from '../../chunk-JDAET5LO.js';
|
|
2
|
+
export { createPostgresBackend } from '../../chunk-536PH5FT.js';
|
|
3
|
+
export { createPostgresTables, edges, embeddings, nodes, schemaVersions, tables, uniques } from '../../chunk-4PIEL2VO.js';
|
|
4
|
+
import '../../chunk-RYT4H46I.js';
|
|
5
|
+
import '../../chunk-2QHQ2C4P.js';
|
|
6
|
+
import '../../chunk-JKTO7TW3.js';
|
|
7
|
+
import '../../chunk-VXRVGFCI.js';
|
|
8
|
+
import '../../chunk-IIAT36MI.js';
|
|
9
|
+
import '../../chunk-K7SQ3SWP.js';
|
|
10
|
+
import '../../chunk-DGUM43GV.js';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkMNO33ASC_cjs = require('../../chunk-MNO33ASC.cjs');
|
|
4
|
+
require('../../chunk-UJAGXJDG.cjs');
|
|
5
|
+
var chunkMFVCSNIY_cjs = require('../../chunk-MFVCSNIY.cjs');
|
|
6
|
+
require('../../chunk-F32HCHYA.cjs');
|
|
7
|
+
var chunkN4AOJ3VF_cjs = require('../../chunk-N4AOJ3VF.cjs');
|
|
8
|
+
var chunkSV5H3XM5_cjs = require('../../chunk-SV5H3XM5.cjs');
|
|
9
|
+
require('../../chunk-DDM2FZRJ.cjs');
|
|
10
|
+
require('../../chunk-YM5AL65Y.cjs');
|
|
11
|
+
require('../../chunk-P5CNM325.cjs');
|
|
12
|
+
require('../../chunk-JEQ2X3Z6.cjs');
|
|
13
|
+
var Database = require('better-sqlite3');
|
|
14
|
+
var betterSqlite3 = require('drizzle-orm/better-sqlite3');
|
|
15
|
+
|
|
16
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
|
+
|
|
18
|
+
var Database__default = /*#__PURE__*/_interopDefault(Database);
|
|
19
|
+
|
|
20
|
+
function getUnknownErrorMessage(error) {
|
|
21
|
+
if (error instanceof Error) return error.message;
|
|
22
|
+
return String(error);
|
|
23
|
+
}
|
|
24
|
+
function parseNodeModuleVersionMismatchMessage(message) {
|
|
25
|
+
const regexp = /NODE_MODULE_VERSION (?<compiled>\d+)[\s\S]*?NODE_MODULE_VERSION (?<required>\d+)/;
|
|
26
|
+
const match = regexp.exec(message);
|
|
27
|
+
if (!match?.groups) return void 0;
|
|
28
|
+
const compiled = Number(match.groups.compiled);
|
|
29
|
+
const required = Number(match.groups.required);
|
|
30
|
+
if (!Number.isFinite(compiled) || !Number.isFinite(required))
|
|
31
|
+
return void 0;
|
|
32
|
+
return { compiled, required };
|
|
33
|
+
}
|
|
34
|
+
function createDatabase(path) {
|
|
35
|
+
try {
|
|
36
|
+
return new Database__default.default(path);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
const message = getUnknownErrorMessage(error);
|
|
39
|
+
const mismatch = parseNodeModuleVersionMismatchMessage(message);
|
|
40
|
+
if (!mismatch) throw error;
|
|
41
|
+
throw new chunkSV5H3XM5_cjs.ConfigurationError(
|
|
42
|
+
[
|
|
43
|
+
"Failed to load better-sqlite3 native addon.",
|
|
44
|
+
`It was compiled for NODE_MODULE_VERSION ${mismatch.compiled}, but this Node.js runtime requires ${mismatch.required}.`,
|
|
45
|
+
"This usually happens after switching Node versions without rebuilding native dependencies.",
|
|
46
|
+
"Rebuild with: pnpm rebuild better-sqlite3 (or npm rebuild better-sqlite3)."
|
|
47
|
+
].join(" "),
|
|
48
|
+
{
|
|
49
|
+
nodeVersion: process.version,
|
|
50
|
+
nodeModuleVersion: process.versions.modules,
|
|
51
|
+
compiledNodeModuleVersion: mismatch.compiled,
|
|
52
|
+
requiredNodeModuleVersion: mismatch.required
|
|
53
|
+
},
|
|
54
|
+
{ cause: error }
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function createLocalSqliteBackend(options = {}) {
|
|
59
|
+
const path = options.path ?? ":memory:";
|
|
60
|
+
const tables2 = options.tables ?? chunkN4AOJ3VF_cjs.tables;
|
|
61
|
+
const sqlite = createDatabase(path);
|
|
62
|
+
const db = betterSqlite3.drizzle(sqlite);
|
|
63
|
+
const ddlStatements = chunkMNO33ASC_cjs.generateSqliteDDL(tables2);
|
|
64
|
+
for (const statement of ddlStatements) {
|
|
65
|
+
sqlite.exec(statement);
|
|
66
|
+
}
|
|
67
|
+
const backend = chunkMFVCSNIY_cjs.createSqliteBackend(db, { tables: tables2 });
|
|
68
|
+
let isClosed = false;
|
|
69
|
+
function close() {
|
|
70
|
+
if (isClosed) return Promise.resolve();
|
|
71
|
+
isClosed = true;
|
|
72
|
+
sqlite.close();
|
|
73
|
+
return Promise.resolve();
|
|
74
|
+
}
|
|
75
|
+
const managedBackend = { ...backend, close };
|
|
76
|
+
return { backend: managedBackend, db };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
Object.defineProperty(exports, "generateSqliteDDL", {
|
|
80
|
+
enumerable: true,
|
|
81
|
+
get: function () { return chunkMNO33ASC_cjs.generateSqliteDDL; }
|
|
82
|
+
});
|
|
83
|
+
Object.defineProperty(exports, "getSqliteMigrationSQL", {
|
|
84
|
+
enumerable: true,
|
|
85
|
+
get: function () { return chunkMNO33ASC_cjs.getSqliteMigrationSQL; }
|
|
86
|
+
});
|
|
87
|
+
Object.defineProperty(exports, "createSqliteBackend", {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
get: function () { return chunkMFVCSNIY_cjs.createSqliteBackend; }
|
|
90
|
+
});
|
|
91
|
+
Object.defineProperty(exports, "createSqliteTables", {
|
|
92
|
+
enumerable: true,
|
|
93
|
+
get: function () { return chunkN4AOJ3VF_cjs.createSqliteTables; }
|
|
94
|
+
});
|
|
95
|
+
Object.defineProperty(exports, "edges", {
|
|
96
|
+
enumerable: true,
|
|
97
|
+
get: function () { return chunkN4AOJ3VF_cjs.edges; }
|
|
98
|
+
});
|
|
99
|
+
Object.defineProperty(exports, "nodes", {
|
|
100
|
+
enumerable: true,
|
|
101
|
+
get: function () { return chunkN4AOJ3VF_cjs.nodes; }
|
|
102
|
+
});
|
|
103
|
+
Object.defineProperty(exports, "schemaVersions", {
|
|
104
|
+
enumerable: true,
|
|
105
|
+
get: function () { return chunkN4AOJ3VF_cjs.schemaVersions; }
|
|
106
|
+
});
|
|
107
|
+
Object.defineProperty(exports, "tables", {
|
|
108
|
+
enumerable: true,
|
|
109
|
+
get: function () { return chunkN4AOJ3VF_cjs.tables; }
|
|
110
|
+
});
|
|
111
|
+
Object.defineProperty(exports, "uniques", {
|
|
112
|
+
enumerable: true,
|
|
113
|
+
get: function () { return chunkN4AOJ3VF_cjs.uniques; }
|
|
114
|
+
});
|
|
115
|
+
exports.createLocalSqliteBackend = createLocalSqliteBackend;
|
|
116
|
+
//# sourceMappingURL=index.cjs.map
|
|
117
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/backend/sqlite/index.ts"],"names":["Database","ConfigurationError","tables","drizzle","generateSqliteDDL","createSqliteBackend"],"mappings":";;;;;;;;;;;;;;;;;;;AAqDA,SAAS,uBAAuB,KAAA,EAAwB;AACtD,EAAA,IAAI,KAAA,YAAiB,KAAA,EAAO,OAAO,KAAA,CAAM,OAAA;AACzC,EAAA,OAAO,OAAO,KAAK,CAAA;AACrB;AAEA,SAAS,sCACP,OAAA,EACuC;AACvC,EAAA,MAAM,MAAA,GACJ,kFAAA;AACF,EAAA,MAAM,KAAA,GAAQ,MAAA,CAAO,IAAA,CAAK,OAAO,CAAA;AACjC,EAAA,IAAI,CAAC,KAAA,EAAO,MAAA,EAAQ,OAAO,MAAA;AAE3B,EAAA,MAAM,QAAA,GAAW,MAAA,CAAO,KAAA,CAAM,MAAA,CAAO,QAAQ,CAAA;AAC7C,EAAA,MAAM,QAAA,GAAW,MAAA,CAAO,KAAA,CAAM,MAAA,CAAO,QAAQ,CAAA;AAE7C,EAAA,IAAI,CAAC,OAAO,QAAA,CAAS,QAAQ,KAAK,CAAC,MAAA,CAAO,SAAS,QAAQ,CAAA;AACzD,IAAA,OAAO,MAAA;AAET,EAAA,OAAO,EAAE,UAAU,QAAA,EAAS;AAC9B;AAEA,SAAS,eAAe,IAAA,EAAiC;AACvD,EAAA,IAAI;AACF,IAAA,OAAO,IAAIA,0BAAS,IAAI,CAAA;AAAA,EAC1B,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,OAAA,GAAU,uBAAuB,KAAK,CAAA;AAC5C,IAAA,MAAM,QAAA,GAAW,sCAAsC,OAAO,CAAA;AAC9D,IAAA,IAAI,CAAC,UAAU,MAAM,KAAA;AAErB,IAAA,MAAM,IAAIC,oCAAA;AAAA,MACR;AAAA,QACE,6CAAA;AAAA,QACA,CAAA,wCAAA,EAA2C,QAAA,CAAS,QAAQ,CAAA,oCAAA,EAAuC,SAAS,QAAQ,CAAA,CAAA,CAAA;AAAA,QACpH,4FAAA;AAAA,QACA;AAAA,OACF,CAAE,KAAK,GAAG,CAAA;AAAA,MACV;AAAA,QACE,aAAa,OAAA,CAAQ,OAAA;AAAA,QACrB,iBAAA,EAAmB,QAAQ,QAAA,CAAS,OAAA;AAAA,QACpC,2BAA2B,QAAA,CAAS,QAAA;AAAA,QACpC,2BAA2B,QAAA,CAAS;AAAA,OACtC;AAAA,MACA,EAAE,OAAO,KAAA;AAAM,KACjB;AAAA,EACF;AACF;AAmEO,SAAS,wBAAA,CACd,OAAA,GAAqC,EAAC,EACZ;AAC1B,EAAA,MAAM,IAAA,GAAO,QAAQ,IAAA,IAAQ,UAAA;AAC7B,EAAA,MAAMC,OAAAA,GAAS,QAAQ,MAAA,IAAUA,wBAAA;AAEjC,EAAA,MAAM,MAAA,GAAS,eAAe,IAAI,CAAA;AAClC,EAAA,MAAM,EAAA,GAAKC,sBAAQ,MAAM,CAAA;AAGzB,EAAA,MAAM,aAAA,GAAgBC,oCAAkBF,OAAM,CAAA;AAC9C,EAAA,KAAA,MAAW,aAAa,aAAA,EAAe;AACrC,IAAA,MAAA,CAAO,KAAK,SAAS,CAAA;AAAA,EACvB;AAEA,EAAA,MAAM,UAAUG,qCAAA,CAAoB,EAAA,EAAI,EAAE,MAAA,EAAAH,SAAQ,CAAA;AAClD,EAAA,IAAI,QAAA,GAAW,KAAA;AAEf,EAAA,SAAS,KAAA,GAAuB;AAC9B,IAAA,IAAI,QAAA,EAAU,OAAO,OAAA,CAAQ,OAAA,EAAQ;AACrC,IAAA,QAAA,GAAW,IAAA;AACX,IAAA,MAAA,CAAO,KAAA,EAAM;AACb,IAAA,OAAO,QAAQ,OAAA,EAAQ;AAAA,EACzB;AAEA,EAAA,MAAM,cAAA,GAA+B,EAAE,GAAG,OAAA,EAAS,KAAA,EAAM;AAEzD,EAAA,OAAO,EAAE,OAAA,EAAS,cAAA,EAAgB,EAAA,EAAG;AACvC","file":"index.cjs","sourcesContent":["/**\n * SQLite backend for TypeGraph.\n *\n * Re-exports from the Drizzle implementation for backwards compatibility.\n *\n * @example Quick start with in-memory database\n * ```typescript\n * import { createLocalSqliteBackend } from \"@nicia-ai/typegraph/sqlite\";\n *\n * const { backend, db } = createLocalSqliteBackend();\n * const store = createStore(graph, backend);\n * ```\n *\n * @example File-based database for persistent local development\n * ```typescript\n * import { createLocalSqliteBackend } from \"@nicia-ai/typegraph/sqlite\";\n *\n * const { backend, db } = createLocalSqliteBackend({ path: \"./dev.db\" });\n * const store = createStore(graph, backend);\n * ```\n *\n * @example Full manual configuration\n * ```typescript\n * import { drizzle } from \"drizzle-orm/better-sqlite3\";\n * import Database from \"better-sqlite3\";\n * import { createSqliteBackend, getSqliteMigrationSQL } from \"@nicia-ai/typegraph/sqlite\";\n *\n * const sqlite = new Database(\"app.db\");\n * sqlite.exec(getSqliteMigrationSQL());\n * const db = drizzle(sqlite);\n * const backend = createSqliteBackend(db);\n * ```\n */\nimport Database from \"better-sqlite3\";\nimport {\n type BetterSQLite3Database,\n drizzle,\n} from \"drizzle-orm/better-sqlite3\";\n\nimport { ConfigurationError } from \"../../errors\";\nimport {\n createSqliteBackend,\n type SqliteTables,\n tables as defaultTables,\n} from \"../drizzle/sqlite\";\nimport { generateSqliteDDL } from \"../drizzle/test-helpers\";\nimport type { GraphBackend } from \"../types\";\n\ntype NodeModuleVersionMismatch = Readonly<{\n compiled: number;\n required: number;\n}>;\n\nfunction getUnknownErrorMessage(error: unknown): string {\n if (error instanceof Error) return error.message;\n return String(error);\n}\n\nfunction parseNodeModuleVersionMismatchMessage(\n message: string,\n): NodeModuleVersionMismatch | undefined {\n const regexp =\n /NODE_MODULE_VERSION (?<compiled>\\d+)[\\s\\S]*?NODE_MODULE_VERSION (?<required>\\d+)/;\n const match = regexp.exec(message);\n if (!match?.groups) return undefined;\n\n const compiled = Number(match.groups.compiled);\n const required = Number(match.groups.required);\n\n if (!Number.isFinite(compiled) || !Number.isFinite(required))\n return undefined;\n\n return { compiled, required };\n}\n\nfunction createDatabase(path: string): Database.Database {\n try {\n return new Database(path);\n } catch (error) {\n const message = getUnknownErrorMessage(error);\n const mismatch = parseNodeModuleVersionMismatchMessage(message);\n if (!mismatch) throw error;\n\n throw new ConfigurationError(\n [\n \"Failed to load better-sqlite3 native addon.\",\n `It was compiled for NODE_MODULE_VERSION ${mismatch.compiled}, but this Node.js runtime requires ${mismatch.required}.`,\n \"This usually happens after switching Node versions without rebuilding native dependencies.\",\n \"Rebuild with: pnpm rebuild better-sqlite3 (or npm rebuild better-sqlite3).\",\n ].join(\" \"),\n {\n nodeVersion: process.version,\n nodeModuleVersion: process.versions.modules,\n compiledNodeModuleVersion: mismatch.compiled,\n requiredNodeModuleVersion: mismatch.required,\n },\n { cause: error },\n );\n }\n}\n\n// ============================================================\n// Types\n// ============================================================\n\n/**\n * Options for creating a local SQLite backend.\n */\nexport type LocalSqliteBackendOptions = Readonly<{\n /**\n * Path to the SQLite database file.\n * Defaults to \":memory:\" for an in-memory database.\n */\n path?: string;\n\n /**\n * Custom table definitions.\n * Defaults to standard TypeGraph table names.\n */\n tables?: SqliteTables;\n}>;\n\n/**\n * Result of creating a local SQLite backend.\n */\nexport type LocalSqliteBackendResult = Readonly<{\n /**\n * The GraphBackend instance for use with createStore.\n */\n backend: GraphBackend;\n\n /**\n * The underlying Drizzle database instance.\n * Useful for direct SQL access or cleanup.\n */\n db: BetterSQLite3Database;\n}>;\n\n// ============================================================\n// Factory Function\n// ============================================================\n\n/**\n * Creates a SQLite backend with minimal configuration.\n *\n * This is a convenience function for local development and testing.\n * It handles database creation, schema migration, and backend setup.\n *\n * For production deployments or custom configurations, use createSqliteBackend\n * directly with your own Drizzle database instance.\n *\n * @param options - Configuration options\n * @returns Backend and database instances\n *\n * @example In-memory database (default)\n * ```typescript\n * const { backend } = createLocalSqliteBackend();\n * const store = createStore(graph, backend);\n * ```\n *\n * @example File-based database\n * ```typescript\n * const { backend, db } = createLocalSqliteBackend({ path: \"./data.db\" });\n * const store = createStore(graph, backend);\n * ```\n */\nexport function createLocalSqliteBackend(\n options: LocalSqliteBackendOptions = {},\n): LocalSqliteBackendResult {\n const path = options.path ?? \":memory:\";\n const tables = options.tables ?? defaultTables;\n\n const sqlite = createDatabase(path);\n const db = drizzle(sqlite);\n\n // Generate and execute DDL from schema\n const ddlStatements = generateSqliteDDL(tables);\n for (const statement of ddlStatements) {\n sqlite.exec(statement);\n }\n\n const backend = createSqliteBackend(db, { tables });\n let isClosed = false;\n\n function close(): Promise<void> {\n if (isClosed) return Promise.resolve();\n isClosed = true;\n sqlite.close();\n return Promise.resolve();\n }\n\n const managedBackend: GraphBackend = { ...backend, close };\n\n return { backend: managedBackend, db };\n}\n\n// ============================================================\n// Re-exports\n// ============================================================\n\n// Re-export everything from the Drizzle SQLite implementation\nexport {\n createSqliteBackend,\n createSqliteTables,\n type SqliteBackendOptions,\n type SqliteTables,\n type TableNames,\n tables,\n} from \"../drizzle/sqlite\";\n\n// Re-export individual tables for schema usage\nexport {\n edges,\n nodes,\n schemaVersions,\n uniques,\n} from \"../drizzle/schema/sqlite\";\n\n// Re-export migration SQL generation\nexport {\n generateSqliteDDL,\n getSqliteMigrationSQL,\n} from \"../drizzle/test-helpers\";\n"]}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { BetterSQLite3Database } from 'drizzle-orm/better-sqlite3';
|
|
2
|
+
export { SqliteBackendOptions, createSqliteBackend } from '../drizzle/sqlite.cjs';
|
|
3
|
+
import { G as GraphBackend } from '../../types-DDOSfrih.cjs';
|
|
4
|
+
import { SqliteTables } from '../drizzle/schema/sqlite.cjs';
|
|
5
|
+
export { TableNames, createSqliteTables, edges, nodes, schemaVersions, tables, uniques } from '../drizzle/schema/sqlite.cjs';
|
|
6
|
+
export { a as generateSqliteDDL, b as getSqliteMigrationSQL } from '../../test-helpers-NoQXhleQ.cjs';
|
|
7
|
+
import 'drizzle-orm/sqlite-core';
|
|
8
|
+
import 'drizzle-orm';
|
|
9
|
+
import '../../types-BRzHlhKC.cjs';
|
|
10
|
+
import '../../types-a5rAxC92.cjs';
|
|
11
|
+
import 'zod';
|
|
12
|
+
import '../../ast-BVyihVbP.cjs';
|
|
13
|
+
import '../drizzle/schema/postgres.cjs';
|
|
14
|
+
import 'drizzle-orm/pg-core';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Options for creating a local SQLite backend.
|
|
18
|
+
*/
|
|
19
|
+
type LocalSqliteBackendOptions = Readonly<{
|
|
20
|
+
/**
|
|
21
|
+
* Path to the SQLite database file.
|
|
22
|
+
* Defaults to ":memory:" for an in-memory database.
|
|
23
|
+
*/
|
|
24
|
+
path?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Custom table definitions.
|
|
27
|
+
* Defaults to standard TypeGraph table names.
|
|
28
|
+
*/
|
|
29
|
+
tables?: SqliteTables;
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* Result of creating a local SQLite backend.
|
|
33
|
+
*/
|
|
34
|
+
type LocalSqliteBackendResult = Readonly<{
|
|
35
|
+
/**
|
|
36
|
+
* The GraphBackend instance for use with createStore.
|
|
37
|
+
*/
|
|
38
|
+
backend: GraphBackend;
|
|
39
|
+
/**
|
|
40
|
+
* The underlying Drizzle database instance.
|
|
41
|
+
* Useful for direct SQL access or cleanup.
|
|
42
|
+
*/
|
|
43
|
+
db: BetterSQLite3Database;
|
|
44
|
+
}>;
|
|
45
|
+
/**
|
|
46
|
+
* Creates a SQLite backend with minimal configuration.
|
|
47
|
+
*
|
|
48
|
+
* This is a convenience function for local development and testing.
|
|
49
|
+
* It handles database creation, schema migration, and backend setup.
|
|
50
|
+
*
|
|
51
|
+
* For production deployments or custom configurations, use createSqliteBackend
|
|
52
|
+
* directly with your own Drizzle database instance.
|
|
53
|
+
*
|
|
54
|
+
* @param options - Configuration options
|
|
55
|
+
* @returns Backend and database instances
|
|
56
|
+
*
|
|
57
|
+
* @example In-memory database (default)
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const { backend } = createLocalSqliteBackend();
|
|
60
|
+
* const store = createStore(graph, backend);
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @example File-based database
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const { backend, db } = createLocalSqliteBackend({ path: "./data.db" });
|
|
66
|
+
* const store = createStore(graph, backend);
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
declare function createLocalSqliteBackend(options?: LocalSqliteBackendOptions): LocalSqliteBackendResult;
|
|
70
|
+
|
|
71
|
+
export { type LocalSqliteBackendOptions, type LocalSqliteBackendResult, SqliteTables, createLocalSqliteBackend };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { BetterSQLite3Database } from 'drizzle-orm/better-sqlite3';
|
|
2
|
+
export { SqliteBackendOptions, createSqliteBackend } from '../drizzle/sqlite.js';
|
|
3
|
+
import { G as GraphBackend } from '../../types-CjZ7g_7v.js';
|
|
4
|
+
import { SqliteTables } from '../drizzle/schema/sqlite.js';
|
|
5
|
+
export { TableNames, createSqliteTables, edges, nodes, schemaVersions, tables, uniques } from '../drizzle/schema/sqlite.js';
|
|
6
|
+
export { a as generateSqliteDDL, b as getSqliteMigrationSQL } from '../../test-helpers-BjyRYJZX.js';
|
|
7
|
+
import 'drizzle-orm/sqlite-core';
|
|
8
|
+
import 'drizzle-orm';
|
|
9
|
+
import '../../types-BRzHlhKC.js';
|
|
10
|
+
import '../../types-CX4cLd7M.js';
|
|
11
|
+
import 'zod';
|
|
12
|
+
import '../../ast-BVyihVbP.js';
|
|
13
|
+
import '../drizzle/schema/postgres.js';
|
|
14
|
+
import 'drizzle-orm/pg-core';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Options for creating a local SQLite backend.
|
|
18
|
+
*/
|
|
19
|
+
type LocalSqliteBackendOptions = Readonly<{
|
|
20
|
+
/**
|
|
21
|
+
* Path to the SQLite database file.
|
|
22
|
+
* Defaults to ":memory:" for an in-memory database.
|
|
23
|
+
*/
|
|
24
|
+
path?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Custom table definitions.
|
|
27
|
+
* Defaults to standard TypeGraph table names.
|
|
28
|
+
*/
|
|
29
|
+
tables?: SqliteTables;
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* Result of creating a local SQLite backend.
|
|
33
|
+
*/
|
|
34
|
+
type LocalSqliteBackendResult = Readonly<{
|
|
35
|
+
/**
|
|
36
|
+
* The GraphBackend instance for use with createStore.
|
|
37
|
+
*/
|
|
38
|
+
backend: GraphBackend;
|
|
39
|
+
/**
|
|
40
|
+
* The underlying Drizzle database instance.
|
|
41
|
+
* Useful for direct SQL access or cleanup.
|
|
42
|
+
*/
|
|
43
|
+
db: BetterSQLite3Database;
|
|
44
|
+
}>;
|
|
45
|
+
/**
|
|
46
|
+
* Creates a SQLite backend with minimal configuration.
|
|
47
|
+
*
|
|
48
|
+
* This is a convenience function for local development and testing.
|
|
49
|
+
* It handles database creation, schema migration, and backend setup.
|
|
50
|
+
*
|
|
51
|
+
* For production deployments or custom configurations, use createSqliteBackend
|
|
52
|
+
* directly with your own Drizzle database instance.
|
|
53
|
+
*
|
|
54
|
+
* @param options - Configuration options
|
|
55
|
+
* @returns Backend and database instances
|
|
56
|
+
*
|
|
57
|
+
* @example In-memory database (default)
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const { backend } = createLocalSqliteBackend();
|
|
60
|
+
* const store = createStore(graph, backend);
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @example File-based database
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const { backend, db } = createLocalSqliteBackend({ path: "./data.db" });
|
|
66
|
+
* const store = createStore(graph, backend);
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
declare function createLocalSqliteBackend(options?: LocalSqliteBackendOptions): LocalSqliteBackendResult;
|
|
70
|
+
|
|
71
|
+
export { type LocalSqliteBackendOptions, type LocalSqliteBackendResult, SqliteTables, createLocalSqliteBackend };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { generateSqliteDDL } from '../../chunk-JDAET5LO.js';
|
|
2
|
+
export { generateSqliteDDL, getSqliteMigrationSQL } from '../../chunk-JDAET5LO.js';
|
|
3
|
+
import '../../chunk-4PIEL2VO.js';
|
|
4
|
+
import { createSqliteBackend } from '../../chunk-3A5TKOEJ.js';
|
|
5
|
+
export { createSqliteBackend } from '../../chunk-3A5TKOEJ.js';
|
|
6
|
+
import '../../chunk-RYT4H46I.js';
|
|
7
|
+
import { tables } from '../../chunk-2QHQ2C4P.js';
|
|
8
|
+
export { createSqliteTables, edges, nodes, schemaVersions, tables, uniques } from '../../chunk-2QHQ2C4P.js';
|
|
9
|
+
import { ConfigurationError } from '../../chunk-JKTO7TW3.js';
|
|
10
|
+
import '../../chunk-VXRVGFCI.js';
|
|
11
|
+
import '../../chunk-IIAT36MI.js';
|
|
12
|
+
import '../../chunk-K7SQ3SWP.js';
|
|
13
|
+
import '../../chunk-DGUM43GV.js';
|
|
14
|
+
import Database from 'better-sqlite3';
|
|
15
|
+
import { drizzle } from 'drizzle-orm/better-sqlite3';
|
|
16
|
+
|
|
17
|
+
function getUnknownErrorMessage(error) {
|
|
18
|
+
if (error instanceof Error) return error.message;
|
|
19
|
+
return String(error);
|
|
20
|
+
}
|
|
21
|
+
function parseNodeModuleVersionMismatchMessage(message) {
|
|
22
|
+
const regexp = /NODE_MODULE_VERSION (?<compiled>\d+)[\s\S]*?NODE_MODULE_VERSION (?<required>\d+)/;
|
|
23
|
+
const match = regexp.exec(message);
|
|
24
|
+
if (!match?.groups) return void 0;
|
|
25
|
+
const compiled = Number(match.groups.compiled);
|
|
26
|
+
const required = Number(match.groups.required);
|
|
27
|
+
if (!Number.isFinite(compiled) || !Number.isFinite(required))
|
|
28
|
+
return void 0;
|
|
29
|
+
return { compiled, required };
|
|
30
|
+
}
|
|
31
|
+
function createDatabase(path) {
|
|
32
|
+
try {
|
|
33
|
+
return new Database(path);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
const message = getUnknownErrorMessage(error);
|
|
36
|
+
const mismatch = parseNodeModuleVersionMismatchMessage(message);
|
|
37
|
+
if (!mismatch) throw error;
|
|
38
|
+
throw new ConfigurationError(
|
|
39
|
+
[
|
|
40
|
+
"Failed to load better-sqlite3 native addon.",
|
|
41
|
+
`It was compiled for NODE_MODULE_VERSION ${mismatch.compiled}, but this Node.js runtime requires ${mismatch.required}.`,
|
|
42
|
+
"This usually happens after switching Node versions without rebuilding native dependencies.",
|
|
43
|
+
"Rebuild with: pnpm rebuild better-sqlite3 (or npm rebuild better-sqlite3)."
|
|
44
|
+
].join(" "),
|
|
45
|
+
{
|
|
46
|
+
nodeVersion: process.version,
|
|
47
|
+
nodeModuleVersion: process.versions.modules,
|
|
48
|
+
compiledNodeModuleVersion: mismatch.compiled,
|
|
49
|
+
requiredNodeModuleVersion: mismatch.required
|
|
50
|
+
},
|
|
51
|
+
{ cause: error }
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function createLocalSqliteBackend(options = {}) {
|
|
56
|
+
const path = options.path ?? ":memory:";
|
|
57
|
+
const tables2 = options.tables ?? tables;
|
|
58
|
+
const sqlite = createDatabase(path);
|
|
59
|
+
const db = drizzle(sqlite);
|
|
60
|
+
const ddlStatements = generateSqliteDDL(tables2);
|
|
61
|
+
for (const statement of ddlStatements) {
|
|
62
|
+
sqlite.exec(statement);
|
|
63
|
+
}
|
|
64
|
+
const backend = createSqliteBackend(db, { tables: tables2 });
|
|
65
|
+
let isClosed = false;
|
|
66
|
+
function close() {
|
|
67
|
+
if (isClosed) return Promise.resolve();
|
|
68
|
+
isClosed = true;
|
|
69
|
+
sqlite.close();
|
|
70
|
+
return Promise.resolve();
|
|
71
|
+
}
|
|
72
|
+
const managedBackend = { ...backend, close };
|
|
73
|
+
return { backend: managedBackend, db };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export { createLocalSqliteBackend };
|
|
77
|
+
//# sourceMappingURL=index.js.map
|
|
78
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/backend/sqlite/index.ts"],"names":["tables"],"mappings":";;;;;;;;;;;;;;;;AAqDA,SAAS,uBAAuB,KAAA,EAAwB;AACtD,EAAA,IAAI,KAAA,YAAiB,KAAA,EAAO,OAAO,KAAA,CAAM,OAAA;AACzC,EAAA,OAAO,OAAO,KAAK,CAAA;AACrB;AAEA,SAAS,sCACP,OAAA,EACuC;AACvC,EAAA,MAAM,MAAA,GACJ,kFAAA;AACF,EAAA,MAAM,KAAA,GAAQ,MAAA,CAAO,IAAA,CAAK,OAAO,CAAA;AACjC,EAAA,IAAI,CAAC,KAAA,EAAO,MAAA,EAAQ,OAAO,MAAA;AAE3B,EAAA,MAAM,QAAA,GAAW,MAAA,CAAO,KAAA,CAAM,MAAA,CAAO,QAAQ,CAAA;AAC7C,EAAA,MAAM,QAAA,GAAW,MAAA,CAAO,KAAA,CAAM,MAAA,CAAO,QAAQ,CAAA;AAE7C,EAAA,IAAI,CAAC,OAAO,QAAA,CAAS,QAAQ,KAAK,CAAC,MAAA,CAAO,SAAS,QAAQ,CAAA;AACzD,IAAA,OAAO,MAAA;AAET,EAAA,OAAO,EAAE,UAAU,QAAA,EAAS;AAC9B;AAEA,SAAS,eAAe,IAAA,EAAiC;AACvD,EAAA,IAAI;AACF,IAAA,OAAO,IAAI,SAAS,IAAI,CAAA;AAAA,EAC1B,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,OAAA,GAAU,uBAAuB,KAAK,CAAA;AAC5C,IAAA,MAAM,QAAA,GAAW,sCAAsC,OAAO,CAAA;AAC9D,IAAA,IAAI,CAAC,UAAU,MAAM,KAAA;AAErB,IAAA,MAAM,IAAI,kBAAA;AAAA,MACR;AAAA,QACE,6CAAA;AAAA,QACA,CAAA,wCAAA,EAA2C,QAAA,CAAS,QAAQ,CAAA,oCAAA,EAAuC,SAAS,QAAQ,CAAA,CAAA,CAAA;AAAA,QACpH,4FAAA;AAAA,QACA;AAAA,OACF,CAAE,KAAK,GAAG,CAAA;AAAA,MACV;AAAA,QACE,aAAa,OAAA,CAAQ,OAAA;AAAA,QACrB,iBAAA,EAAmB,QAAQ,QAAA,CAAS,OAAA;AAAA,QACpC,2BAA2B,QAAA,CAAS,QAAA;AAAA,QACpC,2BAA2B,QAAA,CAAS;AAAA,OACtC;AAAA,MACA,EAAE,OAAO,KAAA;AAAM,KACjB;AAAA,EACF;AACF;AAmEO,SAAS,wBAAA,CACd,OAAA,GAAqC,EAAC,EACZ;AAC1B,EAAA,MAAM,IAAA,GAAO,QAAQ,IAAA,IAAQ,UAAA;AAC7B,EAAA,MAAMA,OAAAA,GAAS,QAAQ,MAAA,IAAU,MAAA;AAEjC,EAAA,MAAM,MAAA,GAAS,eAAe,IAAI,CAAA;AAClC,EAAA,MAAM,EAAA,GAAK,QAAQ,MAAM,CAAA;AAGzB,EAAA,MAAM,aAAA,GAAgB,kBAAkBA,OAAM,CAAA;AAC9C,EAAA,KAAA,MAAW,aAAa,aAAA,EAAe;AACrC,IAAA,MAAA,CAAO,KAAK,SAAS,CAAA;AAAA,EACvB;AAEA,EAAA,MAAM,UAAU,mBAAA,CAAoB,EAAA,EAAI,EAAE,MAAA,EAAAA,SAAQ,CAAA;AAClD,EAAA,IAAI,QAAA,GAAW,KAAA;AAEf,EAAA,SAAS,KAAA,GAAuB;AAC9B,IAAA,IAAI,QAAA,EAAU,OAAO,OAAA,CAAQ,OAAA,EAAQ;AACrC,IAAA,QAAA,GAAW,IAAA;AACX,IAAA,MAAA,CAAO,KAAA,EAAM;AACb,IAAA,OAAO,QAAQ,OAAA,EAAQ;AAAA,EACzB;AAEA,EAAA,MAAM,cAAA,GAA+B,EAAE,GAAG,OAAA,EAAS,KAAA,EAAM;AAEzD,EAAA,OAAO,EAAE,OAAA,EAAS,cAAA,EAAgB,EAAA,EAAG;AACvC","file":"index.js","sourcesContent":["/**\n * SQLite backend for TypeGraph.\n *\n * Re-exports from the Drizzle implementation for backwards compatibility.\n *\n * @example Quick start with in-memory database\n * ```typescript\n * import { createLocalSqliteBackend } from \"@nicia-ai/typegraph/sqlite\";\n *\n * const { backend, db } = createLocalSqliteBackend();\n * const store = createStore(graph, backend);\n * ```\n *\n * @example File-based database for persistent local development\n * ```typescript\n * import { createLocalSqliteBackend } from \"@nicia-ai/typegraph/sqlite\";\n *\n * const { backend, db } = createLocalSqliteBackend({ path: \"./dev.db\" });\n * const store = createStore(graph, backend);\n * ```\n *\n * @example Full manual configuration\n * ```typescript\n * import { drizzle } from \"drizzle-orm/better-sqlite3\";\n * import Database from \"better-sqlite3\";\n * import { createSqliteBackend, getSqliteMigrationSQL } from \"@nicia-ai/typegraph/sqlite\";\n *\n * const sqlite = new Database(\"app.db\");\n * sqlite.exec(getSqliteMigrationSQL());\n * const db = drizzle(sqlite);\n * const backend = createSqliteBackend(db);\n * ```\n */\nimport Database from \"better-sqlite3\";\nimport {\n type BetterSQLite3Database,\n drizzle,\n} from \"drizzle-orm/better-sqlite3\";\n\nimport { ConfigurationError } from \"../../errors\";\nimport {\n createSqliteBackend,\n type SqliteTables,\n tables as defaultTables,\n} from \"../drizzle/sqlite\";\nimport { generateSqliteDDL } from \"../drizzle/test-helpers\";\nimport type { GraphBackend } from \"../types\";\n\ntype NodeModuleVersionMismatch = Readonly<{\n compiled: number;\n required: number;\n}>;\n\nfunction getUnknownErrorMessage(error: unknown): string {\n if (error instanceof Error) return error.message;\n return String(error);\n}\n\nfunction parseNodeModuleVersionMismatchMessage(\n message: string,\n): NodeModuleVersionMismatch | undefined {\n const regexp =\n /NODE_MODULE_VERSION (?<compiled>\\d+)[\\s\\S]*?NODE_MODULE_VERSION (?<required>\\d+)/;\n const match = regexp.exec(message);\n if (!match?.groups) return undefined;\n\n const compiled = Number(match.groups.compiled);\n const required = Number(match.groups.required);\n\n if (!Number.isFinite(compiled) || !Number.isFinite(required))\n return undefined;\n\n return { compiled, required };\n}\n\nfunction createDatabase(path: string): Database.Database {\n try {\n return new Database(path);\n } catch (error) {\n const message = getUnknownErrorMessage(error);\n const mismatch = parseNodeModuleVersionMismatchMessage(message);\n if (!mismatch) throw error;\n\n throw new ConfigurationError(\n [\n \"Failed to load better-sqlite3 native addon.\",\n `It was compiled for NODE_MODULE_VERSION ${mismatch.compiled}, but this Node.js runtime requires ${mismatch.required}.`,\n \"This usually happens after switching Node versions without rebuilding native dependencies.\",\n \"Rebuild with: pnpm rebuild better-sqlite3 (or npm rebuild better-sqlite3).\",\n ].join(\" \"),\n {\n nodeVersion: process.version,\n nodeModuleVersion: process.versions.modules,\n compiledNodeModuleVersion: mismatch.compiled,\n requiredNodeModuleVersion: mismatch.required,\n },\n { cause: error },\n );\n }\n}\n\n// ============================================================\n// Types\n// ============================================================\n\n/**\n * Options for creating a local SQLite backend.\n */\nexport type LocalSqliteBackendOptions = Readonly<{\n /**\n * Path to the SQLite database file.\n * Defaults to \":memory:\" for an in-memory database.\n */\n path?: string;\n\n /**\n * Custom table definitions.\n * Defaults to standard TypeGraph table names.\n */\n tables?: SqliteTables;\n}>;\n\n/**\n * Result of creating a local SQLite backend.\n */\nexport type LocalSqliteBackendResult = Readonly<{\n /**\n * The GraphBackend instance for use with createStore.\n */\n backend: GraphBackend;\n\n /**\n * The underlying Drizzle database instance.\n * Useful for direct SQL access or cleanup.\n */\n db: BetterSQLite3Database;\n}>;\n\n// ============================================================\n// Factory Function\n// ============================================================\n\n/**\n * Creates a SQLite backend with minimal configuration.\n *\n * This is a convenience function for local development and testing.\n * It handles database creation, schema migration, and backend setup.\n *\n * For production deployments or custom configurations, use createSqliteBackend\n * directly with your own Drizzle database instance.\n *\n * @param options - Configuration options\n * @returns Backend and database instances\n *\n * @example In-memory database (default)\n * ```typescript\n * const { backend } = createLocalSqliteBackend();\n * const store = createStore(graph, backend);\n * ```\n *\n * @example File-based database\n * ```typescript\n * const { backend, db } = createLocalSqliteBackend({ path: \"./data.db\" });\n * const store = createStore(graph, backend);\n * ```\n */\nexport function createLocalSqliteBackend(\n options: LocalSqliteBackendOptions = {},\n): LocalSqliteBackendResult {\n const path = options.path ?? \":memory:\";\n const tables = options.tables ?? defaultTables;\n\n const sqlite = createDatabase(path);\n const db = drizzle(sqlite);\n\n // Generate and execute DDL from schema\n const ddlStatements = generateSqliteDDL(tables);\n for (const statement of ddlStatements) {\n sqlite.exec(statement);\n }\n\n const backend = createSqliteBackend(db, { tables });\n let isClosed = false;\n\n function close(): Promise<void> {\n if (isClosed) return Promise.resolve();\n isClosed = true;\n sqlite.close();\n return Promise.resolve();\n }\n\n const managedBackend: GraphBackend = { ...backend, close };\n\n return { backend: managedBackend, db };\n}\n\n// ============================================================\n// Re-exports\n// ============================================================\n\n// Re-export everything from the Drizzle SQLite implementation\nexport {\n createSqliteBackend,\n createSqliteTables,\n type SqliteBackendOptions,\n type SqliteTables,\n type TableNames,\n tables,\n} from \"../drizzle/sqlite\";\n\n// Re-export individual tables for schema usage\nexport {\n edges,\n nodes,\n schemaVersions,\n uniques,\n} from \"../drizzle/schema/sqlite\";\n\n// Re-export migration SQL generation\nexport {\n generateSqliteDDL,\n getSqliteMigrationSQL,\n} from \"../drizzle/test-helpers\";\n"]}
|