@velvetmonkey/vault-core 2.12.4 → 2.12.5

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.
@@ -1,273 +0,0 @@
1
- /**
2
- * Shared SQLite State Management
3
- *
4
- * Consolidates scattered JSON files and in-memory state into a single
5
- * SQLite database with FTS5 for entity search.
6
- *
7
- * Target performance:
8
- * - Startup <100ms for 10k note vault
9
- * - Entity search <10ms
10
- * - Single .flywheel/state.db for backup
11
- */
12
- import Database from 'better-sqlite3';
13
- import type { Statement, Transaction } from 'better-sqlite3';
14
- import type { EntityCategory, EntityWithAliases, EntityIndex } from './types.js';
15
- /** Search result from FTS5 entity search */
16
- export interface EntitySearchResult {
17
- id: number;
18
- name: string;
19
- nameLower: string;
20
- path: string;
21
- category: EntityCategory;
22
- aliases: string[];
23
- hubScore: number;
24
- rank: number;
25
- }
26
- /** Recency tracking for entities */
27
- export interface RecencyRow {
28
- entityNameLower: string;
29
- lastMentionedAt: number;
30
- mentionCount: number;
31
- }
32
- /** Database state metadata */
33
- export interface StateDbMetadata {
34
- schemaVersion: number;
35
- entitiesBuiltAt: string | null;
36
- entityCount: number;
37
- notesBuiltAt: string | null;
38
- noteCount: number;
39
- }
40
- /** State database instance with prepared statements */
41
- export interface StateDb {
42
- db: Database.Database;
43
- vaultPath: string;
44
- dbPath: string;
45
- insertEntity: Statement;
46
- updateEntity: Statement;
47
- deleteEntity: Statement;
48
- getEntityByName: Statement;
49
- getEntityById: Statement;
50
- getAllEntities: Statement;
51
- getEntitiesByCategory: Statement;
52
- searchEntitiesFts: Statement;
53
- clearEntities: Statement;
54
- getEntitiesByAlias: Statement;
55
- upsertRecency: Statement;
56
- getRecency: Statement;
57
- getAllRecency: Statement;
58
- clearRecency: Statement;
59
- setWriteState: Statement;
60
- getWriteState: Statement;
61
- deleteWriteState: Statement;
62
- setFlywheelConfigStmt: Statement;
63
- getFlywheelConfigStmt: Statement;
64
- getAllFlywheelConfigStmt: Statement;
65
- deleteFlywheelConfigStmt: Statement;
66
- insertTask: Statement;
67
- deleteTasksForPath: Statement;
68
- clearAllTasks: Statement;
69
- countTasksByStatus: Statement;
70
- getMetadataValue: Statement;
71
- setMetadataValue: Statement;
72
- bulkInsertEntities: Transaction<(entities: EntityWithAliases[], category: EntityCategory) => number>;
73
- replaceAllEntities: Transaction<(index: EntityIndex) => number>;
74
- close: () => void;
75
- }
76
- /** Current schema version - bump when schema changes */
77
- export declare const SCHEMA_VERSION = 14;
78
- /** State database filename */
79
- export declare const STATE_DB_FILENAME = "state.db";
80
- /** Directory for flywheel state */
81
- export declare const FLYWHEEL_DIR = ".flywheel";
82
- /**
83
- * Get the database path for a vault
84
- */
85
- export declare function getStateDbPath(vaultPath: string): string;
86
- /**
87
- * Open or create the state database for a vault
88
- *
89
- * @param vaultPath - Absolute path to the vault root
90
- * @returns StateDb instance with prepared statements
91
- */
92
- export declare function openStateDb(vaultPath: string): StateDb;
93
- /**
94
- * Search entities using FTS5 with porter stemming
95
- *
96
- * @param stateDb - State database instance
97
- * @param query - Search query (supports FTS5 syntax)
98
- * @param limit - Maximum results to return
99
- * @returns Array of matching entities with relevance scores
100
- */
101
- export declare function searchEntities(stateDb: StateDb, query: string, limit?: number): EntitySearchResult[];
102
- /**
103
- * Search entities by prefix for autocomplete
104
- *
105
- * @param stateDb - State database instance
106
- * @param prefix - Prefix to search for
107
- * @param limit - Maximum results to return
108
- */
109
- export declare function searchEntitiesPrefix(stateDb: StateDb, prefix: string, limit?: number): EntitySearchResult[];
110
- /**
111
- * Get entity by exact name (case-insensitive)
112
- */
113
- export declare function getEntityByName(stateDb: StateDb, name: string): EntitySearchResult | null;
114
- /**
115
- * Get all entities from the database
116
- */
117
- export declare function getAllEntitiesFromDb(stateDb: StateDb): EntitySearchResult[];
118
- /**
119
- * Convert database entities back to EntityIndex format
120
- */
121
- export declare function getEntityIndexFromDb(stateDb: StateDb): EntityIndex;
122
- /**
123
- * Get entities that have a given alias (case-insensitive)
124
- *
125
- * @param stateDb - State database instance
126
- * @param alias - Alias to search for (case-insensitive)
127
- * @returns Array of matching entities
128
- */
129
- export declare function getEntitiesByAlias(stateDb: StateDb, alias: string): EntitySearchResult[];
130
- /**
131
- * Record a mention of an entity
132
- */
133
- export declare function recordEntityMention(stateDb: StateDb, entityName: string, mentionedAt?: Date): void;
134
- /**
135
- * Get recency info for an entity
136
- */
137
- export declare function getEntityRecency(stateDb: StateDb, entityName: string): RecencyRow | null;
138
- /**
139
- * Get all recency data ordered by most recent
140
- */
141
- export declare function getAllRecency(stateDb: StateDb): RecencyRow[];
142
- /**
143
- * Set a write state value
144
- */
145
- export declare function setWriteState(stateDb: StateDb, key: string, value: unknown): void;
146
- /**
147
- * Get a write state value
148
- */
149
- export declare function getWriteState<T>(stateDb: StateDb, key: string): T | null;
150
- /**
151
- * Delete a write state key
152
- */
153
- export declare function deleteWriteState(stateDb: StateDb, key: string): void;
154
- /** Flywheel config row from database */
155
- export interface FlywheelConfigRow {
156
- key: string;
157
- value: string;
158
- }
159
- /**
160
- * Set a flywheel config value
161
- */
162
- export declare function setFlywheelConfig(stateDb: StateDb, key: string, value: unknown): void;
163
- /**
164
- * Get a flywheel config value
165
- */
166
- export declare function getFlywheelConfig<T>(stateDb: StateDb, key: string): T | null;
167
- /**
168
- * Get all flywheel config values as an object
169
- */
170
- export declare function getAllFlywheelConfig(stateDb: StateDb): Record<string, unknown>;
171
- /**
172
- * Delete a flywheel config key
173
- */
174
- export declare function deleteFlywheelConfig(stateDb: StateDb, key: string): void;
175
- /**
176
- * Save entire Flywheel config object to database
177
- * Stores each top-level key as a separate row
178
- */
179
- export declare function saveFlywheelConfigToDb(stateDb: StateDb, config: Record<string, unknown>): void;
180
- /**
181
- * Load Flywheel config from database and reconstruct as typed object
182
- */
183
- export declare function loadFlywheelConfigFromDb(stateDb: StateDb): Record<string, unknown> | null;
184
- /**
185
- * Record a merge dismissal so the pair never reappears in suggestions.
186
- */
187
- export declare function recordMergeDismissal(db: StateDb, sourcePath: string, targetPath: string, sourceName: string, targetName: string, reason: string): void;
188
- /**
189
- * Get all dismissed merge pair keys for filtering.
190
- */
191
- export declare function getDismissedMergePairs(db: StateDb): Set<string>;
192
- /**
193
- * Get database metadata
194
- */
195
- export declare function getStateDbMetadata(stateDb: StateDb): StateDbMetadata;
196
- /**
197
- * Check if entity data is stale (older than threshold)
198
- */
199
- export declare function isEntityDataStale(stateDb: StateDb, thresholdMs?: number): boolean;
200
- /**
201
- * Escape special FTS5 characters in a query
202
- */
203
- export declare function escapeFts5Query(query: string): string;
204
- /**
205
- * Check if the state database exists for a vault
206
- */
207
- export declare function stateDbExists(vaultPath: string): boolean;
208
- /**
209
- * Delete the state database (for testing or reset)
210
- */
211
- export declare function deleteStateDb(vaultPath: string): void;
212
- /** Serializable VaultIndex for caching */
213
- export interface VaultIndexCacheData {
214
- notes: Array<{
215
- path: string;
216
- title: string;
217
- aliases: string[];
218
- frontmatter: Record<string, unknown>;
219
- outlinks: Array<{
220
- target: string;
221
- alias?: string;
222
- line: number;
223
- }>;
224
- tags: string[];
225
- modified: number;
226
- created?: number;
227
- }>;
228
- backlinks: Array<[string, Array<{
229
- source: string;
230
- line: number;
231
- context?: string;
232
- }>]>;
233
- entities: Array<[string, string]>;
234
- tags: Array<[string, string[]]>;
235
- builtAt: number;
236
- }
237
- /** Cache metadata */
238
- export interface VaultIndexCacheInfo {
239
- builtAt: Date;
240
- noteCount: number;
241
- version: number;
242
- }
243
- /**
244
- * Save VaultIndex to cache
245
- *
246
- * @param stateDb - State database instance
247
- * @param indexData - Serialized VaultIndex data
248
- */
249
- export declare function saveVaultIndexCache(stateDb: StateDb, indexData: VaultIndexCacheData): void;
250
- /**
251
- * Load VaultIndex from cache
252
- *
253
- * @param stateDb - State database instance
254
- * @returns Cached VaultIndex data or null if not found
255
- */
256
- export declare function loadVaultIndexCache(stateDb: StateDb): VaultIndexCacheData | null;
257
- /**
258
- * Get cache metadata without loading full data
259
- */
260
- export declare function getVaultIndexCacheInfo(stateDb: StateDb): VaultIndexCacheInfo | null;
261
- /**
262
- * Clear the vault index cache
263
- */
264
- export declare function clearVaultIndexCache(stateDb: StateDb): void;
265
- /**
266
- * Check if cache is valid (not too old and note count matches)
267
- *
268
- * @param stateDb - State database instance
269
- * @param actualNoteCount - Current number of notes in vault
270
- * @param maxAgeMs - Maximum cache age in milliseconds (default 24 hours)
271
- */
272
- export declare function isVaultIndexCacheValid(stateDb: StateDb, actualNoteCount: number, maxAgeMs?: number): boolean;
273
- //# sourceMappingURL=sqlite.d.ts.map