@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.
Files changed (72) hide show
  1. package/README.md +62 -20
  2. package/dist/backend-CE3pM9-T.d.ts +167 -0
  3. package/dist/{backend-DuvHGgK1.d.cts → backend-DNzv8KSR.d.cts} +34 -20
  4. package/dist/{backend-DuvHGgK1.d.ts → backend-DNzv8KSR.d.ts} +34 -20
  5. package/dist/backend-EjFfw9yO.d.cts +167 -0
  6. package/dist/backend.cjs.map +1 -1
  7. package/dist/backend.d.cts +2 -2
  8. package/dist/backend.d.ts +2 -2
  9. package/dist/backend.js +1 -1
  10. package/dist/chunk-5JBNLH5W.js +732 -0
  11. package/dist/chunk-5JBNLH5W.js.map +1 -0
  12. package/dist/{chunk-3AHHXMWX.js → chunk-6IO74NKD.js} +23 -44
  13. package/dist/chunk-6IO74NKD.js.map +1 -0
  14. package/dist/{chunk-DJI3VXXA.js → chunk-7IEZ6IYY.js} +2 -2
  15. package/dist/chunk-7IEZ6IYY.js.map +1 -0
  16. package/dist/chunk-NGAJCALM.js +34 -0
  17. package/dist/chunk-NGAJCALM.js.map +1 -0
  18. package/dist/chunk-NZVSLWNY.js +867 -0
  19. package/dist/chunk-NZVSLWNY.js.map +1 -0
  20. package/dist/{chunk-N5HFDWQX.js → chunk-PWIO46RT.js} +1 -1
  21. package/dist/{chunk-N5HFDWQX.js.map → chunk-PWIO46RT.js.map} +1 -1
  22. package/dist/{client-BKi3vk0Q.d.ts → client-CNAwJayO.d.ts} +1 -1
  23. package/dist/{client-BrsaXtDV.d.cts → client-CaXH5D5C.d.cts} +1 -1
  24. package/dist/{client-Bk2Cm6xv.d.cts → client-DoyEdJ5w.d.cts} +1 -1
  25. package/dist/{client-Bk2Cm6xv.d.ts → client-DoyEdJ5w.d.ts} +1 -1
  26. package/dist/cloudflare/index.cjs +159 -167
  27. package/dist/cloudflare/index.cjs.map +1 -1
  28. package/dist/cloudflare/index.d.cts +73 -70
  29. package/dist/cloudflare/index.d.ts +73 -70
  30. package/dist/cloudflare/index.js +54 -589
  31. package/dist/cloudflare/index.js.map +1 -1
  32. package/dist/codegen/index.d.cts +1 -1
  33. package/dist/codegen/index.d.ts +1 -1
  34. package/dist/firestore-enterprise/index.cjs +11 -9
  35. package/dist/firestore-enterprise/index.cjs.map +1 -1
  36. package/dist/firestore-enterprise/index.d.cts +3 -3
  37. package/dist/firestore-enterprise/index.d.ts +3 -3
  38. package/dist/firestore-enterprise/index.js +6 -4
  39. package/dist/firestore-enterprise/index.js.map +1 -1
  40. package/dist/firestore-standard/index.cjs +11 -9
  41. package/dist/firestore-standard/index.cjs.map +1 -1
  42. package/dist/firestore-standard/index.d.cts +3 -3
  43. package/dist/firestore-standard/index.d.ts +3 -3
  44. package/dist/firestore-standard/index.js +4 -3
  45. package/dist/firestore-standard/index.js.map +1 -1
  46. package/dist/index.cjs +11 -9
  47. package/dist/index.cjs.map +1 -1
  48. package/dist/index.d.cts +5 -5
  49. package/dist/index.d.ts +5 -5
  50. package/dist/index.js +6 -4
  51. package/dist/index.js.map +1 -1
  52. package/dist/query-client/index.d.cts +2 -2
  53. package/dist/query-client/index.d.ts +2 -2
  54. package/dist/{registry-C2KUPVZj.d.ts → registry-By1i-zge.d.ts} +2 -2
  55. package/dist/{registry-Bc7h6WTM.d.cts → registry-CNToyEra.d.cts} +2 -2
  56. package/dist/sqlite/index.cjs +599 -380
  57. package/dist/sqlite/index.cjs.map +1 -1
  58. package/dist/sqlite/index.d.cts +4 -110
  59. package/dist/sqlite/index.d.ts +4 -110
  60. package/dist/sqlite/index.js +7 -1144
  61. package/dist/sqlite/index.js.map +1 -1
  62. package/dist/sqlite/local.cjs +2262 -0
  63. package/dist/sqlite/local.cjs.map +1 -0
  64. package/dist/sqlite/local.d.cts +109 -0
  65. package/dist/sqlite/local.d.ts +109 -0
  66. package/dist/sqlite/local.js +546 -0
  67. package/dist/sqlite/local.js.map +1 -0
  68. package/package.json +15 -1
  69. package/dist/chunk-3AHHXMWX.js.map +0 -1
  70. package/dist/chunk-DJI3VXXA.js.map +0 -1
  71. package/dist/chunk-NNBSUOOF.js +0 -289
  72. 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 };