@xmoxmo/bncr 0.6.2 → 0.6.4

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,3 +1,5 @@
1
+ import { existsSync } from 'node:fs';
2
+ import path from 'node:path';
1
3
  import type { RegisterDriftSnapshot } from '../core/register-trace.ts';
2
4
  import type {
3
5
  BncrConnection,
@@ -17,6 +19,13 @@ import { createBncrTransientStateRuntime } from './transient-state-runtime.ts';
17
19
  type StoredRouteRecord = { accountId: string; route: BncrRoute; updatedAt: number };
18
20
  type StoredLastSessionRecord = { sessionKey: string; scope: string; updatedAt: number };
19
21
 
22
+ export function shouldEnableBncrSqliteState(statePath: string | null): boolean {
23
+ if (!statePath) return false;
24
+ if (process.env.BNCR_SQLITE_STORE === '0') return false;
25
+ if (process.env.BNCR_SQLITE_STORE === '1') return true;
26
+ return existsSync(path.join(path.dirname(statePath), 'bncr.sqlite3'));
27
+ }
28
+
20
29
  export function createBncrStateTransientRuntimeGroup(runtime: {
21
30
  bridgeId: string;
22
31
  getStatePath: () => string | null;
@@ -92,6 +101,11 @@ export function createBncrStateTransientRuntimeGroup(runtime: {
92
101
  lastOutboundByAccount: runtime.lastOutboundByAccount,
93
102
  getLastDriftSnapshot: runtime.getLastDriftSnapshot,
94
103
  setLastDriftSnapshot: runtime.setLastDriftSnapshot,
104
+ createSqliteState: async (statePath) => {
105
+ if (!statePath || !shouldEnableBncrSqliteState(statePath)) return null;
106
+ const { createBncrSqliteStateDatabase } = await import('./sqlite-state.ts');
107
+ return createBncrSqliteStateDatabase(path.join(path.dirname(statePath), 'bncr.sqlite3'));
108
+ },
95
109
  });
96
110
 
97
111
  const transientStateRuntime = createBncrTransientStateRuntime({