@typicalday/firegraph 0.14.1 → 0.16.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/README.md +62 -20
- package/dist/backend-CE3pM9-T.d.ts +167 -0
- package/dist/{backend-DuvHGgK1.d.cts → backend-DNzv8KSR.d.cts} +34 -20
- package/dist/{backend-DuvHGgK1.d.ts → backend-DNzv8KSR.d.ts} +34 -20
- package/dist/backend-EjFfw9yO.d.cts +167 -0
- package/dist/backend.cjs.map +1 -1
- package/dist/backend.d.cts +2 -2
- package/dist/backend.d.ts +2 -2
- package/dist/backend.js +1 -1
- package/dist/chunk-5JBNLH5W.js +732 -0
- package/dist/chunk-5JBNLH5W.js.map +1 -0
- package/dist/{chunk-3AHHXMWX.js → chunk-6IO74NKD.js} +23 -44
- package/dist/chunk-6IO74NKD.js.map +1 -0
- package/dist/{chunk-DJI3VXXA.js → chunk-7IEZ6IYY.js} +2 -2
- package/dist/chunk-7IEZ6IYY.js.map +1 -0
- package/dist/chunk-NGAJCALM.js +34 -0
- package/dist/chunk-NGAJCALM.js.map +1 -0
- package/dist/chunk-NZVSLWNY.js +867 -0
- package/dist/chunk-NZVSLWNY.js.map +1 -0
- package/dist/{chunk-N5HFDWQX.js → chunk-PWIO46RT.js} +1 -1
- package/dist/{chunk-N5HFDWQX.js.map → chunk-PWIO46RT.js.map} +1 -1
- package/dist/{client-BKi3vk0Q.d.ts → client-CNAwJayO.d.ts} +1 -1
- package/dist/{client-BrsaXtDV.d.cts → client-CaXH5D5C.d.cts} +1 -1
- package/dist/{client-Bk2Cm6xv.d.cts → client-DoyEdJ5w.d.cts} +1 -1
- package/dist/{client-Bk2Cm6xv.d.ts → client-DoyEdJ5w.d.ts} +1 -1
- package/dist/cloudflare/index.cjs +159 -167
- package/dist/cloudflare/index.cjs.map +1 -1
- package/dist/cloudflare/index.d.cts +73 -70
- package/dist/cloudflare/index.d.ts +73 -70
- package/dist/cloudflare/index.js +54 -589
- package/dist/cloudflare/index.js.map +1 -1
- package/dist/codegen/index.d.cts +1 -1
- package/dist/codegen/index.d.ts +1 -1
- package/dist/firestore-enterprise/index.cjs +11 -9
- package/dist/firestore-enterprise/index.cjs.map +1 -1
- package/dist/firestore-enterprise/index.d.cts +3 -3
- package/dist/firestore-enterprise/index.d.ts +3 -3
- package/dist/firestore-enterprise/index.js +6 -4
- package/dist/firestore-enterprise/index.js.map +1 -1
- package/dist/firestore-standard/index.cjs +11 -9
- package/dist/firestore-standard/index.cjs.map +1 -1
- package/dist/firestore-standard/index.d.cts +3 -3
- package/dist/firestore-standard/index.d.ts +3 -3
- package/dist/firestore-standard/index.js +4 -3
- package/dist/firestore-standard/index.js.map +1 -1
- package/dist/index.cjs +11 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/dist/query-client/index.d.cts +2 -2
- package/dist/query-client/index.d.ts +2 -2
- package/dist/{registry-C2KUPVZj.d.ts → registry-By1i-zge.d.ts} +2 -2
- package/dist/{registry-Bc7h6WTM.d.cts → registry-CNToyEra.d.cts} +2 -2
- package/dist/sqlite/index.cjs +599 -380
- package/dist/sqlite/index.cjs.map +1 -1
- package/dist/sqlite/index.d.cts +4 -110
- package/dist/sqlite/index.d.ts +4 -110
- package/dist/sqlite/index.js +7 -1144
- package/dist/sqlite/index.js.map +1 -1
- package/dist/sqlite/local.cjs +2262 -0
- package/dist/sqlite/local.cjs.map +1 -0
- package/dist/sqlite/local.d.cts +109 -0
- package/dist/sqlite/local.d.ts +109 -0
- package/dist/sqlite/local.js +546 -0
- package/dist/sqlite/local.js.map +1 -0
- package/package.json +15 -1
- package/dist/chunk-3AHHXMWX.js.map +0 -1
- package/dist/chunk-DJI3VXXA.js.map +0 -1
- package/dist/chunk-NNBSUOOF.js +0 -289
- package/dist/chunk-NNBSUOOF.js.map +0 -1
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Database } from 'better-sqlite3';
|
|
2
|
+
import { S as StorageBackend } from '../backend-DNzv8KSR.cjs';
|
|
3
|
+
import { a as SqliteCapability, S as SqliteBackendOptions, b as SqliteExecutor } from '../backend-EjFfw9yO.cjs';
|
|
4
|
+
import '@google-cloud/firestore';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Local SQLite backend over `better-sqlite3`.
|
|
8
|
+
*
|
|
9
|
+
* This entry point is published as `firegraph/sqlite-local` and is the only
|
|
10
|
+
* module in the library that references `better-sqlite3` — keep it out of
|
|
11
|
+
* `firegraph/sqlite` so that D1 / workerd bundles never see the native
|
|
12
|
+
* dependency. `better-sqlite3` is loaded via dynamic `import()` at factory
|
|
13
|
+
* call time, so merely importing this module stays side-effect free.
|
|
14
|
+
*
|
|
15
|
+
* The factory accepts either a database file path (`':memory:'` works) or an
|
|
16
|
+
* already-open `better-sqlite3` Database. Path-opened databases get
|
|
17
|
+
* `journal_mode = WAL` and a `busy_timeout` applied; caller-provided
|
|
18
|
+
* databases are used as-is (only `busy_timeout` is set) since the caller
|
|
19
|
+
* owns their pragma configuration.
|
|
20
|
+
*
|
|
21
|
+
* ## Search capabilities
|
|
22
|
+
*
|
|
23
|
+
* On top of the shared SQLite capability set, the local backend declares
|
|
24
|
+
* `search.fullText` and `search.vector` (see `src/internal/sqlite-search.ts`
|
|
25
|
+
* for the mechanics):
|
|
26
|
+
*
|
|
27
|
+
* - **Full-text search** is backed by one FTS5 table per graph table,
|
|
28
|
+
* kept in sync by pure-SQL triggers installed with the table's DDL.
|
|
29
|
+
* Because the triggers live in the database file, writes from ANY
|
|
30
|
+
* process or connection stay indexed. The trade-off is a per-write
|
|
31
|
+
* overhead (text extraction via `json_tree` + an FTS index update) on
|
|
32
|
+
* every insert/update/delete.
|
|
33
|
+
* - **Vector search** is a brute-force scan scored by a deterministic
|
|
34
|
+
* scalar UDF registered on this connection. UDFs are connection-local:
|
|
35
|
+
* `findNearest` only works through a backend created by this factory
|
|
36
|
+
* (other connections to the same file can read/write normally — only
|
|
37
|
+
* vector *search* needs the UDF).
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Capability union for the local better-sqlite3 backend: everything the
|
|
42
|
+
* shared SQLite edition declares, plus native FTS5 full-text search and
|
|
43
|
+
* brute-force vector search. `search.geo` stays out — there is no geo
|
|
44
|
+
* index in stock SQLite, and a UDF-scored scan without a haversine
|
|
45
|
+
* contract pinned by Firestore parity tests would be guesswork.
|
|
46
|
+
*/
|
|
47
|
+
type LocalSqliteCapability = SqliteCapability | 'search.fullText' | 'search.vector';
|
|
48
|
+
interface LocalSqliteBackendOptions extends SqliteBackendOptions {
|
|
49
|
+
/** Root graph table name. Defaults to `'firegraph'`. */
|
|
50
|
+
tableName?: string;
|
|
51
|
+
/**
|
|
52
|
+
* `PRAGMA busy_timeout` in milliseconds — how long a connection waits on a
|
|
53
|
+
* lock held by another process before erroring. Defaults to 5000.
|
|
54
|
+
*/
|
|
55
|
+
busyTimeoutMs?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Extra pragmas applied after the defaults, e.g.
|
|
58
|
+
* `{ synchronous: 'NORMAL', cache_size: -64000 }`. Applied in object
|
|
59
|
+
* order via `PRAGMA <key> = <value>`.
|
|
60
|
+
*/
|
|
61
|
+
pragmas?: Record<string, string | number>;
|
|
62
|
+
/**
|
|
63
|
+
* When opening by path: throw if the file does not already exist instead
|
|
64
|
+
* of creating it. Defaults to false.
|
|
65
|
+
*/
|
|
66
|
+
fileMustExist?: boolean;
|
|
67
|
+
}
|
|
68
|
+
interface LocalSqliteBackend {
|
|
69
|
+
/** The graph storage backend — pass to `createGraphClient`. */
|
|
70
|
+
backend: StorageBackend<LocalSqliteCapability>;
|
|
71
|
+
/** The underlying better-sqlite3 database, for raw access. */
|
|
72
|
+
db: Database;
|
|
73
|
+
/**
|
|
74
|
+
* Close the database. No-op when the factory was given an already-open
|
|
75
|
+
* Database (the caller owns its lifecycle).
|
|
76
|
+
*/
|
|
77
|
+
close(): void;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Build a transaction-capable `SqliteExecutor` over a better-sqlite3
|
|
81
|
+
* Database. Interactive transactions use manual `BEGIN IMMEDIATE` /
|
|
82
|
+
* `COMMIT` / `ROLLBACK` because `db.transaction()` requires a synchronous
|
|
83
|
+
* callback while `SqliteExecutor.transaction` callbacks are async.
|
|
84
|
+
*
|
|
85
|
+
* Exported for callers that want to wire `createSqliteBackend` directly
|
|
86
|
+
* (e.g. to share one executor across several root tables).
|
|
87
|
+
*/
|
|
88
|
+
declare function createBetterSqliteExecutor(db: Database): SqliteExecutor;
|
|
89
|
+
/**
|
|
90
|
+
* Open (or wrap) a local SQLite database and return a graph storage backend
|
|
91
|
+
* over it.
|
|
92
|
+
*
|
|
93
|
+
* ```typescript
|
|
94
|
+
* import { createLocalSqliteBackend } from 'firegraph/sqlite-local';
|
|
95
|
+
* import { createGraphClient } from 'firegraph/sqlite';
|
|
96
|
+
*
|
|
97
|
+
* const { backend, close } = await createLocalSqliteBackend('./graph.db');
|
|
98
|
+
* const client = createGraphClient(backend);
|
|
99
|
+
* // ... use the client — including fullTextSearch() and findNearest() ...
|
|
100
|
+
* close();
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* Requires `better-sqlite3` to be installed (declared as an optional peer
|
|
104
|
+
* dependency). The factory is async because the driver is loaded via
|
|
105
|
+
* dynamic `import()`.
|
|
106
|
+
*/
|
|
107
|
+
declare function createLocalSqliteBackend(pathOrDb: string | Database, options?: LocalSqliteBackendOptions): Promise<LocalSqliteBackend>;
|
|
108
|
+
|
|
109
|
+
export { type LocalSqliteBackend, type LocalSqliteBackendOptions, type LocalSqliteCapability, createBetterSqliteExecutor, createLocalSqliteBackend };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Database } from 'better-sqlite3';
|
|
2
|
+
import { S as StorageBackend } from '../backend-DNzv8KSR.js';
|
|
3
|
+
import { a as SqliteCapability, S as SqliteBackendOptions, b as SqliteExecutor } from '../backend-CE3pM9-T.js';
|
|
4
|
+
import '@google-cloud/firestore';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Local SQLite backend over `better-sqlite3`.
|
|
8
|
+
*
|
|
9
|
+
* This entry point is published as `firegraph/sqlite-local` and is the only
|
|
10
|
+
* module in the library that references `better-sqlite3` — keep it out of
|
|
11
|
+
* `firegraph/sqlite` so that D1 / workerd bundles never see the native
|
|
12
|
+
* dependency. `better-sqlite3` is loaded via dynamic `import()` at factory
|
|
13
|
+
* call time, so merely importing this module stays side-effect free.
|
|
14
|
+
*
|
|
15
|
+
* The factory accepts either a database file path (`':memory:'` works) or an
|
|
16
|
+
* already-open `better-sqlite3` Database. Path-opened databases get
|
|
17
|
+
* `journal_mode = WAL` and a `busy_timeout` applied; caller-provided
|
|
18
|
+
* databases are used as-is (only `busy_timeout` is set) since the caller
|
|
19
|
+
* owns their pragma configuration.
|
|
20
|
+
*
|
|
21
|
+
* ## Search capabilities
|
|
22
|
+
*
|
|
23
|
+
* On top of the shared SQLite capability set, the local backend declares
|
|
24
|
+
* `search.fullText` and `search.vector` (see `src/internal/sqlite-search.ts`
|
|
25
|
+
* for the mechanics):
|
|
26
|
+
*
|
|
27
|
+
* - **Full-text search** is backed by one FTS5 table per graph table,
|
|
28
|
+
* kept in sync by pure-SQL triggers installed with the table's DDL.
|
|
29
|
+
* Because the triggers live in the database file, writes from ANY
|
|
30
|
+
* process or connection stay indexed. The trade-off is a per-write
|
|
31
|
+
* overhead (text extraction via `json_tree` + an FTS index update) on
|
|
32
|
+
* every insert/update/delete.
|
|
33
|
+
* - **Vector search** is a brute-force scan scored by a deterministic
|
|
34
|
+
* scalar UDF registered on this connection. UDFs are connection-local:
|
|
35
|
+
* `findNearest` only works through a backend created by this factory
|
|
36
|
+
* (other connections to the same file can read/write normally — only
|
|
37
|
+
* vector *search* needs the UDF).
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Capability union for the local better-sqlite3 backend: everything the
|
|
42
|
+
* shared SQLite edition declares, plus native FTS5 full-text search and
|
|
43
|
+
* brute-force vector search. `search.geo` stays out — there is no geo
|
|
44
|
+
* index in stock SQLite, and a UDF-scored scan without a haversine
|
|
45
|
+
* contract pinned by Firestore parity tests would be guesswork.
|
|
46
|
+
*/
|
|
47
|
+
type LocalSqliteCapability = SqliteCapability | 'search.fullText' | 'search.vector';
|
|
48
|
+
interface LocalSqliteBackendOptions extends SqliteBackendOptions {
|
|
49
|
+
/** Root graph table name. Defaults to `'firegraph'`. */
|
|
50
|
+
tableName?: string;
|
|
51
|
+
/**
|
|
52
|
+
* `PRAGMA busy_timeout` in milliseconds — how long a connection waits on a
|
|
53
|
+
* lock held by another process before erroring. Defaults to 5000.
|
|
54
|
+
*/
|
|
55
|
+
busyTimeoutMs?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Extra pragmas applied after the defaults, e.g.
|
|
58
|
+
* `{ synchronous: 'NORMAL', cache_size: -64000 }`. Applied in object
|
|
59
|
+
* order via `PRAGMA <key> = <value>`.
|
|
60
|
+
*/
|
|
61
|
+
pragmas?: Record<string, string | number>;
|
|
62
|
+
/**
|
|
63
|
+
* When opening by path: throw if the file does not already exist instead
|
|
64
|
+
* of creating it. Defaults to false.
|
|
65
|
+
*/
|
|
66
|
+
fileMustExist?: boolean;
|
|
67
|
+
}
|
|
68
|
+
interface LocalSqliteBackend {
|
|
69
|
+
/** The graph storage backend — pass to `createGraphClient`. */
|
|
70
|
+
backend: StorageBackend<LocalSqliteCapability>;
|
|
71
|
+
/** The underlying better-sqlite3 database, for raw access. */
|
|
72
|
+
db: Database;
|
|
73
|
+
/**
|
|
74
|
+
* Close the database. No-op when the factory was given an already-open
|
|
75
|
+
* Database (the caller owns its lifecycle).
|
|
76
|
+
*/
|
|
77
|
+
close(): void;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Build a transaction-capable `SqliteExecutor` over a better-sqlite3
|
|
81
|
+
* Database. Interactive transactions use manual `BEGIN IMMEDIATE` /
|
|
82
|
+
* `COMMIT` / `ROLLBACK` because `db.transaction()` requires a synchronous
|
|
83
|
+
* callback while `SqliteExecutor.transaction` callbacks are async.
|
|
84
|
+
*
|
|
85
|
+
* Exported for callers that want to wire `createSqliteBackend` directly
|
|
86
|
+
* (e.g. to share one executor across several root tables).
|
|
87
|
+
*/
|
|
88
|
+
declare function createBetterSqliteExecutor(db: Database): SqliteExecutor;
|
|
89
|
+
/**
|
|
90
|
+
* Open (or wrap) a local SQLite database and return a graph storage backend
|
|
91
|
+
* over it.
|
|
92
|
+
*
|
|
93
|
+
* ```typescript
|
|
94
|
+
* import { createLocalSqliteBackend } from 'firegraph/sqlite-local';
|
|
95
|
+
* import { createGraphClient } from 'firegraph/sqlite';
|
|
96
|
+
*
|
|
97
|
+
* const { backend, close } = await createLocalSqliteBackend('./graph.db');
|
|
98
|
+
* const client = createGraphClient(backend);
|
|
99
|
+
* // ... use the client — including fullTextSearch() and findNearest() ...
|
|
100
|
+
* close();
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* Requires `better-sqlite3` to be installed (declared as an optional peer
|
|
104
|
+
* dependency). The factory is async because the driver is loaded via
|
|
105
|
+
* dynamic `import()`.
|
|
106
|
+
*/
|
|
107
|
+
declare function createLocalSqliteBackend(pathOrDb: string | Database, options?: LocalSqliteBackendOptions): Promise<LocalSqliteBackend>;
|
|
108
|
+
|
|
109
|
+
export { type LocalSqliteBackend, type LocalSqliteBackendOptions, type LocalSqliteCapability, createBetterSqliteExecutor, createLocalSqliteBackend };
|