@framers/sql-storage-adapter 0.6.15 → 0.7.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 +174 -3
- package/dist/adapters/baseStorageAdapter.d.ts.map +1 -1
- package/dist/adapters/baseStorageAdapter.js +4 -2
- package/dist/adapters/baseStorageAdapter.js.map +1 -1
- package/dist/adapters/betterSqliteAdapter.d.ts +18 -2
- package/dist/adapters/betterSqliteAdapter.d.ts.map +1 -1
- package/dist/adapters/betterSqliteAdapter.js +23 -7
- package/dist/adapters/betterSqliteAdapter.js.map +1 -1
- package/dist/adapters/capacitorSqliteAdapter.d.ts +8 -0
- package/dist/adapters/capacitorSqliteAdapter.d.ts.map +1 -1
- package/dist/adapters/capacitorSqliteAdapter.js +11 -1
- package/dist/adapters/capacitorSqliteAdapter.js.map +1 -1
- package/dist/adapters/electron/electronMainAdapter.d.ts +10 -0
- package/dist/adapters/electron/electronMainAdapter.d.ts.map +1 -1
- package/dist/adapters/electron/electronMainAdapter.js +21 -12
- package/dist/adapters/electron/electronMainAdapter.js.map +1 -1
- package/dist/adapters/indexedDbAdapter.d.ts +202 -54
- package/dist/adapters/indexedDbAdapter.d.ts.map +1 -1
- package/dist/adapters/indexedDbAdapter.js +560 -123
- package/dist/adapters/indexedDbAdapter.js.map +1 -1
- package/dist/adapters/postgresAdapter.d.ts +159 -3
- package/dist/adapters/postgresAdapter.d.ts.map +1 -1
- package/dist/adapters/postgresAdapter.js +667 -140
- package/dist/adapters/postgresAdapter.js.map +1 -1
- package/dist/adapters/sqlJsAdapter.d.ts +21 -3
- package/dist/adapters/sqlJsAdapter.d.ts.map +1 -1
- package/dist/adapters/sqlJsAdapter.js +29 -26
- package/dist/adapters/sqlJsAdapter.js.map +1 -1
- package/dist/core/contracts/index.d.ts +9 -0
- package/dist/core/contracts/index.d.ts.map +1 -1
- package/dist/core/contracts/index.js.map +1 -1
- package/dist/core/database.d.ts +43 -8
- package/dist/core/database.d.ts.map +1 -1
- package/dist/core/database.js +40 -5
- package/dist/core/database.js.map +1 -1
- package/dist/core/resolver.d.ts +20 -1
- package/dist/core/resolver.d.ts.map +1 -1
- package/dist/core/resolver.js +33 -11
- package/dist/core/resolver.js.map +1 -1
- package/dist/features/kv/idb.d.ts +79 -0
- package/dist/features/kv/idb.d.ts.map +1 -0
- package/dist/features/kv/idb.js +14 -0
- package/dist/features/kv/idb.js.map +1 -0
- package/dist/features/kv/index.d.ts +14 -0
- package/dist/features/kv/index.d.ts.map +1 -0
- package/dist/features/kv/index.js +14 -0
- package/dist/features/kv/index.js.map +1 -0
- package/dist/features/kv/indexedDbKeyValueStore.d.ts +77 -0
- package/dist/features/kv/indexedDbKeyValueStore.d.ts.map +1 -0
- package/dist/features/kv/indexedDbKeyValueStore.js +127 -0
- package/dist/features/kv/indexedDbKeyValueStore.js.map +1 -0
- package/dist/features/kv/keyValueStore.d.ts +48 -0
- package/dist/features/kv/keyValueStore.d.ts.map +1 -0
- package/dist/features/kv/keyValueStore.js +54 -0
- package/dist/features/kv/keyValueStore.js.map +1 -0
- package/dist/features/kv/sqlKeyValueStore.d.ts +34 -0
- package/dist/features/kv/sqlKeyValueStore.d.ts.map +1 -0
- package/dist/features/kv/sqlKeyValueStore.js +91 -0
- package/dist/features/kv/sqlKeyValueStore.js.map +1 -0
- package/dist/features/kv/valueCodec.d.ts +35 -0
- package/dist/features/kv/valueCodec.d.ts.map +1 -0
- package/dist/features/kv/valueCodec.js +462 -0
- package/dist/features/kv/valueCodec.js.map +1 -0
- package/dist/features/migrations/dataExport.js +9 -6
- package/dist/features/migrations/dataExport.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/shared/errors.d.ts +23 -0
- package/dist/shared/errors.d.ts.map +1 -0
- package/dist/shared/errors.js +44 -0
- package/dist/shared/errors.js.map +1 -0
- package/dist/shared/logger.d.ts +26 -0
- package/dist/shared/logger.d.ts.map +1 -0
- package/dist/shared/logger.js +26 -0
- package/dist/shared/logger.js.map +1 -0
- package/dist/shared/parameterUtils.d.ts +7 -0
- package/dist/shared/parameterUtils.d.ts.map +1 -1
- package/dist/shared/parameterUtils.js +25 -0
- package/dist/shared/parameterUtils.js.map +1 -1
- package/dist/shared/postgresTarget.d.ts +4 -3
- package/dist/shared/postgresTarget.d.ts.map +1 -1
- package/dist/shared/postgresTarget.js +6 -4
- package/dist/shared/postgresTarget.js.map +1 -1
- package/dist/shared/segment.d.ts +43 -0
- package/dist/shared/segment.d.ts.map +1 -0
- package/dist/shared/segment.js +77 -0
- package/dist/shared/segment.js.map +1 -0
- package/dist/shared/sqlPlaceholders.d.ts +40 -0
- package/dist/shared/sqlPlaceholders.d.ts.map +1 -0
- package/dist/shared/sqlPlaceholders.js +276 -0
- package/dist/shared/sqlPlaceholders.js.map +1 -0
- package/package.json +10 -2
package/dist/core/resolver.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { AdapterKind } from './contracts/context.js';
|
|
|
3
3
|
import { type CapacitorAdapterOptions } from '../adapters/capacitorSqliteAdapter.js';
|
|
4
4
|
import { type PostgresAdapterOptions } from '../adapters/postgresAdapter.js';
|
|
5
5
|
import { type IndexedDbAdapterOptions } from '../adapters/indexedDbAdapter.js';
|
|
6
|
+
import { type StorageLogger } from '../shared/logger.js';
|
|
6
7
|
export type { AdapterKind } from './contracts/context.js';
|
|
7
8
|
export interface StorageResolutionOptions {
|
|
8
9
|
/** Absolute path for sqlite file (used by better-sqlite3/sql.js when persistence is desired). */
|
|
@@ -24,12 +25,17 @@ export interface StorageResolutionOptions {
|
|
|
24
25
|
* the connection string comes from DATABASE_URL.
|
|
25
26
|
*/
|
|
26
27
|
postgres?: PostgresAdapterOptions;
|
|
27
|
-
/** Options passed to the IndexedDB adapter (browser persistence). */
|
|
28
|
+
/** Options passed to the IndexedDB adapter (browser persistence), all of them. */
|
|
28
29
|
indexedDb?: IndexedDbAdapterOptions;
|
|
29
30
|
/** Options forwarded to adapter.open. */
|
|
30
31
|
openOptions?: StorageOpenOptions;
|
|
31
32
|
/** Suppress fallback chain logs (adapter not-found warnings). Default: false. */
|
|
32
33
|
quiet?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* The logger for this call's resolver lines (pino's fits). Default: the one
|
|
36
|
+
* `setStorageLogger()` set, else the console.
|
|
37
|
+
*/
|
|
38
|
+
logger?: StorageLogger;
|
|
33
39
|
/**
|
|
34
40
|
* Strict resolution, for servers: only the database the options name opens.
|
|
35
41
|
* Default: false.
|
|
@@ -49,6 +55,19 @@ export interface StorageResolutionOptions {
|
|
|
49
55
|
* `filePath` is given.
|
|
50
56
|
*/
|
|
51
57
|
strict?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Keeps the resolved adapter's tables apart from other users of the same
|
|
60
|
+
* database: on PostgreSQL a schema of the segment's name, on better-sqlite3
|
|
61
|
+
* and sql.js a file with the segment in its name (`app.sqlite3` becomes
|
|
62
|
+
* `app-agentos.sqlite3`), on IndexedDB and Capacitor a database name with
|
|
63
|
+
* the segment appended (`app-db-agentos`). Lower-case letters, digits and
|
|
64
|
+
* underscores; not `public`, `information_schema` or a name beginning with
|
|
65
|
+
* `pg_`. A name that cannot be a segment is refused before any adapter is
|
|
66
|
+
* tried, and so is a segment with `postgres.pool`, which the Postgres
|
|
67
|
+
* adapter cannot start in the segment. Takes the place of a `segment` in
|
|
68
|
+
* `postgres`, `indexedDb` or `capacitor`.
|
|
69
|
+
*/
|
|
70
|
+
segment?: string;
|
|
52
71
|
}
|
|
53
72
|
/**
|
|
54
73
|
* Resolves the most appropriate storage adapter for the current runtime.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../../src/core/resolver.ts"],"names":[],"mappings":"AAyCA,OAAO,KAAK,EAAE,cAAc,EAAyB,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAE7F,OAAO,KAAK,EAAE,W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CAAC;IACjB;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AA+DD;;;GAGG;AACH,eAAO,MAAM,qBAAqB,aAAmB,wBAAwB,KAAQ,OAAO,CAAC,cAAc,CA4L1G,CAAC"}
|
package/dist/core/resolver.js
CHANGED
|
@@ -43,6 +43,8 @@ import { createCapacitorSqliteAdapter } from '../adapters/capacitorSqliteAdapter
|
|
|
43
43
|
import { createPostgresAdapter } from '../adapters/postgresAdapter.js';
|
|
44
44
|
import { IndexedDbAdapter } from '../adapters/indexedDbAdapter.js';
|
|
45
45
|
import { isNonEmpty, namesPostgresServer } from '../shared/postgresTarget.js';
|
|
46
|
+
import { validateSegment } from '../shared/segment.js';
|
|
47
|
+
import { getStorageLogger } from '../shared/logger.js';
|
|
46
48
|
const isCapacitorRuntime = () => {
|
|
47
49
|
if (typeof window === 'undefined') {
|
|
48
50
|
return false;
|
|
@@ -85,7 +87,26 @@ const unsupportedKind = (kind) => {
|
|
|
85
87
|
* Tries candidates in the supplied priority order and falls back when one fails.
|
|
86
88
|
*/
|
|
87
89
|
export const resolveStorageAdapter = async (options = {}) => {
|
|
90
|
+
// A segment name is a programming error, not an adapter that failed: refuse
|
|
91
|
+
// it before trying any.
|
|
92
|
+
const segment = options.segment === undefined ? undefined : validateSegment(options.segment);
|
|
93
|
+
// A segment on a pool of the caller's never opens: the Postgres adapter sets
|
|
94
|
+
// the segment's search_path when it starts a connection, and it does not
|
|
95
|
+
// start the connections of a pool it did not make. Without strict, the
|
|
96
|
+
// failed postgres candidate would fall through to a local file in the
|
|
97
|
+
// segment, so the pair is refused before any adapter is tried.
|
|
98
|
+
if ((segment ?? options.postgres?.segment) !== undefined && options.postgres?.pool) {
|
|
99
|
+
throw new Error("A segment cannot run on a PostgreSQL pool of the caller's (postgres.pool): the segment's search_path is set when " +
|
|
100
|
+
'each connection of the pool starts, and the adapter does not start the connections of a pool it did not make. ' +
|
|
101
|
+
'Give the connection settings and the segment instead of the pool.');
|
|
102
|
+
}
|
|
103
|
+
/** The segment an adapter's own options carry, unless the resolver's takes their place. */
|
|
104
|
+
const segmentFor = (own) => {
|
|
105
|
+
const chosen = segment ?? own;
|
|
106
|
+
return chosen === undefined ? {} : { segment: chosen };
|
|
107
|
+
};
|
|
88
108
|
const envOverride = getEnv('STORAGE_ADAPTER');
|
|
109
|
+
const log = options.logger ?? getStorageLogger();
|
|
89
110
|
const strict = options.strict === true;
|
|
90
111
|
const postgresOptions = options.postgres;
|
|
91
112
|
const explicitConnection = postgresOptions?.connectionString;
|
|
@@ -110,14 +131,14 @@ export const resolveStorageAdapter = async (options = {}) => {
|
|
|
110
131
|
}
|
|
111
132
|
// Electron detection - provide guidance to use dedicated Electron adapters
|
|
112
133
|
if (isElectronMain()) {
|
|
113
|
-
|
|
134
|
+
log.warn({ runtime: 'electron-main' }, 'Electron main process detected. ' +
|
|
114
135
|
'Consider using the dedicated Electron adapter for full framework support:\n' +
|
|
115
136
|
" import { createElectronMainAdapter } from '@framers/sql-storage-adapter/electron';\n" +
|
|
116
137
|
'Falling back to better-sqlite3 adapter.');
|
|
117
138
|
return ['better-sqlite3'];
|
|
118
139
|
}
|
|
119
140
|
if (isElectronRenderer()) {
|
|
120
|
-
|
|
141
|
+
log.warn({ runtime: 'electron-renderer' }, 'Electron renderer process detected. ' +
|
|
121
142
|
'For IPC-based database access, use the dedicated Electron adapter:\n' +
|
|
122
143
|
" import { createElectronRendererAdapter } from '@framers/sql-storage-adapter/electron';\n" +
|
|
123
144
|
'Note: Direct database access in renderer is not recommended for security reasons.');
|
|
@@ -155,6 +176,7 @@ export const resolveStorageAdapter = async (options = {}) => {
|
|
|
155
176
|
return createPostgresAdapter({
|
|
156
177
|
...postgresOptions,
|
|
157
178
|
...(postgresConnection ? { connectionString: postgresConnection } : {}),
|
|
179
|
+
...segmentFor(postgresOptions?.segment),
|
|
158
180
|
});
|
|
159
181
|
},
|
|
160
182
|
openOptions: postgresConnection ? { connectionString: postgresConnection } : undefined
|
|
@@ -163,13 +185,13 @@ export const resolveStorageAdapter = async (options = {}) => {
|
|
|
163
185
|
case 'better-sqlite3':
|
|
164
186
|
return {
|
|
165
187
|
name,
|
|
166
|
-
factory: async () => createBetterSqliteAdapter(filePath),
|
|
188
|
+
factory: async () => createBetterSqliteAdapter(filePath, segmentFor(undefined)),
|
|
167
189
|
openOptions: { filePath }
|
|
168
190
|
};
|
|
169
191
|
case 'capacitor':
|
|
170
192
|
return {
|
|
171
193
|
name,
|
|
172
|
-
factory: async () => createCapacitorSqliteAdapter(options.capacitor)
|
|
194
|
+
factory: async () => createCapacitorSqliteAdapter({ ...options.capacitor, ...segmentFor(options.capacitor?.segment) })
|
|
173
195
|
};
|
|
174
196
|
case 'indexeddb':
|
|
175
197
|
return {
|
|
@@ -178,11 +200,10 @@ export const resolveStorageAdapter = async (options = {}) => {
|
|
|
178
200
|
// Use dedicated indexedDb options, fallback to legacy openOptions.adapterOptions
|
|
179
201
|
const legacyOptions = options.openOptions?.adapterOptions;
|
|
180
202
|
return new IndexedDbAdapter({
|
|
203
|
+
...options.indexedDb,
|
|
181
204
|
dbName: options.indexedDb?.dbName || legacyOptions?.dbName || 'app-db',
|
|
182
|
-
storeName: options.indexedDb?.storeName,
|
|
183
205
|
autoSave: options.indexedDb?.autoSave ?? true,
|
|
184
|
-
|
|
185
|
-
sqlJsConfig: options.indexedDb?.sqlJsConfig,
|
|
206
|
+
...segmentFor(options.indexedDb?.segment),
|
|
186
207
|
});
|
|
187
208
|
}
|
|
188
209
|
};
|
|
@@ -192,7 +213,7 @@ export const resolveStorageAdapter = async (options = {}) => {
|
|
|
192
213
|
case 'memory':
|
|
193
214
|
return {
|
|
194
215
|
name: 'sqljs',
|
|
195
|
-
factory: async () => createSqlJsAdapter(),
|
|
216
|
+
factory: async () => createSqlJsAdapter(segmentFor(undefined)),
|
|
196
217
|
openOptions: { filePath }
|
|
197
218
|
};
|
|
198
219
|
default:
|
|
@@ -214,8 +235,9 @@ export const resolveStorageAdapter = async (options = {}) => {
|
|
|
214
235
|
...options.openOptions,
|
|
215
236
|
};
|
|
216
237
|
await adapter.open(openOptions);
|
|
217
|
-
if (!quiet)
|
|
218
|
-
|
|
238
|
+
if (!quiet) {
|
|
239
|
+
log.info(segment === undefined ? { adapter: candidate.name } : { adapter: candidate.name, segment }, `Using adapter "${candidate.name}"${segment === undefined ? '' : ` for segment "${segment}"`}.`);
|
|
240
|
+
}
|
|
219
241
|
return adapter;
|
|
220
242
|
}
|
|
221
243
|
catch (error) {
|
|
@@ -226,7 +248,7 @@ export const resolveStorageAdapter = async (options = {}) => {
|
|
|
226
248
|
}
|
|
227
249
|
if (!quiet) {
|
|
228
250
|
const msg = error instanceof Error ? error.message : String(error);
|
|
229
|
-
|
|
251
|
+
log.warn({ adapter: candidate.name, error: msg }, `${candidate.name} not available, trying next. ${msg}`);
|
|
230
252
|
}
|
|
231
253
|
continue;
|
|
232
254
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolver.js","sourceRoot":"","sources":["../../src/core/resolver.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,MAAM,SAAS,GAAG,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,WAAW,CAAC;AAC1F,MAAM,MAAM,GAAG,OAAO,OAAO,KAAK,WAAW,IAAI,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC;AAE1E,6DAA6D;AAC7D,MAAM,QAAQ,GAAG,KAAK,EAAE,KAAe,EAAmB,EAAE;IAC1D,IAAI,SAAS,EAAE,CAAC;QACd,8EAA8E;QAC9E,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IACD,wCAAwC;IACxC,IAAI,MAAM,EAAE,CAAC;QACX,IAAI,CAAC;YACH,4DAA4D;YAC5D,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC;YAClC,OAAO,IAAI,CA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AE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,EAC1F,kBAAkB,SAAS,CAAC,IAAI,IAAI,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,iBAAiB,OAAO,GAAG,GAAG,CAChG,CAAC;YACJ,CAAC;YACD,OAAO,OAAO,CAAC;QACjB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACnB,IAAI,MAAM,IAAI,SAAS,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;gBAC5C,MAAM,GAAG,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBACnE,MAAM,IAAI,sBAAsB,CAC9B,iGAAiG,GAAG,EAAE,EACtG,MAAM,CACP,CAAC;YACJ,CAAC;YACD,IAAI,CAAC,KAAK,EAAE,CAAC;gBACX,MAAM,GAAG,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBACnE,GAAG,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,SAAS,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,GAAG,SAAS,CAAC,IAAI,gCAAgC,GAAG,EAAE,CAAC,CAAC;YAC5G,CAAC;YACD,SAAS;QACX,CAAC;IACH,CAAC;IAED,MAAM,IAAI,sBAAsB,CAAC,kEAAkE,EAAE,MAAM,CAAC,CAAC;AAC/G,CAAC,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The part of IndexedDB the key-value store calls, typed structurally: the module compiles without the DOM
|
|
3
|
+
* library, and a page's IndexedDB satisfies these shapes.
|
|
4
|
+
* Moved unchanged from @framers/agentos src/core/storage/browser/idb.ts.
|
|
5
|
+
* @module sql-storage-adapter/kv/idb
|
|
6
|
+
*/
|
|
7
|
+
/** A request's outcome and its two events. */
|
|
8
|
+
export interface IdbRequestLike<T> {
|
|
9
|
+
/** What the request answered, once it is done. */
|
|
10
|
+
readonly result: T;
|
|
11
|
+
/** Why the request failed, once it is done; null when it did not. */
|
|
12
|
+
readonly error: unknown;
|
|
13
|
+
/** Called when the request has succeeded. */
|
|
14
|
+
onsuccess: (() => void) | null;
|
|
15
|
+
/** Called when the request has failed. */
|
|
16
|
+
onerror: (() => void) | null;
|
|
17
|
+
}
|
|
18
|
+
/** A key range; only made and passed on. */
|
|
19
|
+
export type IdbKeyRangeLike = object;
|
|
20
|
+
/** The object store's calls the store makes. */
|
|
21
|
+
export interface IdbObjectStoreLike {
|
|
22
|
+
/** Reads the value under a key. */
|
|
23
|
+
get(key: string): IdbRequestLike<unknown>;
|
|
24
|
+
/** Writes a value under a key, in place of what was there. */
|
|
25
|
+
put(value: unknown, key: string): IdbRequestLike<unknown>;
|
|
26
|
+
/** Removes one key, or every key of a range. */
|
|
27
|
+
delete(key: string | IdbKeyRangeLike): IdbRequestLike<unknown>;
|
|
28
|
+
/** Removes every key. */
|
|
29
|
+
clear(): IdbRequestLike<unknown>;
|
|
30
|
+
/** Lists the keys of a range, or every key. */
|
|
31
|
+
getAllKeys(range?: IdbKeyRangeLike): IdbRequestLike<unknown[]>;
|
|
32
|
+
}
|
|
33
|
+
/** A transaction and its three events. */
|
|
34
|
+
export interface IdbTransactionLike {
|
|
35
|
+
/** Why the transaction was aborted; null until it is, and after a plain abort. */
|
|
36
|
+
readonly error: unknown;
|
|
37
|
+
/** One of the object stores the transaction was opened over. */
|
|
38
|
+
objectStore(name: string): IdbObjectStoreLike;
|
|
39
|
+
/** Called when everything the transaction did is kept. */
|
|
40
|
+
oncomplete: (() => void) | null;
|
|
41
|
+
/** Called when one of the transaction's requests has failed, before the transaction is aborted for it. */
|
|
42
|
+
onerror: (() => void) | null;
|
|
43
|
+
/** Called when the transaction is aborted and nothing it did is kept. */
|
|
44
|
+
onabort: (() => void) | null;
|
|
45
|
+
}
|
|
46
|
+
/** An open database. */
|
|
47
|
+
export interface IdbDatabaseLike {
|
|
48
|
+
/** The names of the database's object stores. */
|
|
49
|
+
readonly objectStoreNames: {
|
|
50
|
+
contains(name: string): boolean;
|
|
51
|
+
};
|
|
52
|
+
/** Makes an object store with out-of-line keys; only inside an upgrade. */
|
|
53
|
+
createObjectStore(name: string): unknown;
|
|
54
|
+
/** Opens a transaction over one object store. */
|
|
55
|
+
transaction(storeName: string, mode: 'readonly' | 'readwrite'): IdbTransactionLike;
|
|
56
|
+
/** Closes the connection once its transactions are done. */
|
|
57
|
+
close(): void;
|
|
58
|
+
}
|
|
59
|
+
/** The request `open` answers. */
|
|
60
|
+
export interface IdbOpenRequestLike extends IdbRequestLike<IdbDatabaseLike> {
|
|
61
|
+
/** The upgrade's transaction while `onupgradeneeded` runs; null outside it. */
|
|
62
|
+
readonly transaction: {
|
|
63
|
+
abort(): void;
|
|
64
|
+
} | null;
|
|
65
|
+
/** Called when the database is new or older than the version asked for, inside the upgrade. */
|
|
66
|
+
onupgradeneeded: (() => void) | null;
|
|
67
|
+
/** Called when an upgrade waits for another connection to close. */
|
|
68
|
+
onblocked: (() => void) | null;
|
|
69
|
+
}
|
|
70
|
+
/** The page's `indexedDB` and `IDBKeyRange`, or an error when the page has none. */
|
|
71
|
+
export declare function idb(): {
|
|
72
|
+
factory: {
|
|
73
|
+
open(name: string, version?: number): IdbOpenRequestLike;
|
|
74
|
+
};
|
|
75
|
+
keyRange: {
|
|
76
|
+
bound(lower: string, upper: string): IdbKeyRangeLike;
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=idb.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"idb.d.ts","sourceRoot":"","sources":["../../../src/features/kv/idb.ts"],"names":[],"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I,CAAC;IAC7B,yEAAyE;IACzE,OAAO,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC;CAC9B;AAED,wBAAwB;AACxB,MAAM,WAAW,eAAe;IAC9B,iDAAiD;IACjD,QAAQ,CAAC,gBAAgB,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IAC/D,2EAA2E;IAC3E,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IACzC,iDAAiD;IACjD,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,WAAW,GAAG,kBAAkB,CAAC;IACnF,4DAA4D;IAC5D,KAAK,IAAI,IAAI,CAAC;CACf;AAED,kCAAkC;AAClC,MAAM,WAAW,kBAAmB,SAAQ,cAAc,CAAC,eAAe,CAAC;IACzE,+EAA+E;IAC/E,QAAQ,CAAC,WAAW,EAAE;QAAE,KAAK,IAAI,IAAI,CAAA;KAAE,GAAG,IAAI,CAAC;IAC/C,+FAA+F;IAC/F,eAAe,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC;IACrC,oEAAoE;IACpE,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC;CAChC;AAED,oFAAoF;AACpF,wBAAgB,GAAG,IAAI;IAAE,OAAO,EAAE;QAAE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,kBAAkB,CAAA;KAAE,CAAC;IAAC,QAAQ,EAAE;QAAE,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,eAAe,CAAA;KAAE,CAAA;CAAE,CAOnK"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The part of IndexedDB the key-value store calls, typed structurally: the module compiles without the DOM
|
|
3
|
+
* library, and a page's IndexedDB satisfies these shapes.
|
|
4
|
+
* Moved unchanged from @framers/agentos src/core/storage/browser/idb.ts.
|
|
5
|
+
* @module sql-storage-adapter/kv/idb
|
|
6
|
+
*/
|
|
7
|
+
/** The page's `indexedDB` and `IDBKeyRange`, or an error when the page has none. */
|
|
8
|
+
export function idb() {
|
|
9
|
+
const scope = globalThis;
|
|
10
|
+
if (!scope.indexedDB || !scope.IDBKeyRange)
|
|
11
|
+
throw new Error('IndexedDB is not available here.');
|
|
12
|
+
return { factory: scope.indexedDB, keyRange: scope.IDBKeyRange };
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=idb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"idb.js","sourceRoot":"","sources":["../../../src/features/kv/idb.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAmEH,oFAAoF;AACpF,MAAM,UAAU,GAAG;IACjB,MAAM,KAAK,GAAG,UAGb,CAAC;IACF,IAAI,CAAC,KAAK,CAAC,SAAS,IAAI,CAAC,KAAK,CAAC,WAAW;QAAE,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IAChG,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,SAAS,EAAE,QAAQ,EAAE,KAAK,CAAC,WAAW,EAAE,CAAC;AACnE,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The key-value module, `@framers/sql-storage-adapter/kv`: one `KeyValueStore` contract and its
|
|
3
|
+
* stores. `openIndexedDbStore` keeps values in one IndexedDB object store, moved unchanged from @framers/agentos, so a
|
|
4
|
+
* page's keys stay where they are; `createSqlKeyValueStore` keeps them in a SQL table on any adapter; the memory store
|
|
5
|
+
* keeps them for the page alone.
|
|
6
|
+
*
|
|
7
|
+
* The module imports no adapter, so a page that loads it for its key-value store loads neither sql.js nor pg.
|
|
8
|
+
* @module sql-storage-adapter/kv
|
|
9
|
+
*/
|
|
10
|
+
export { MemoryKeyValueStore, namespaced, type KeyValueStore } from './keyValueStore.js';
|
|
11
|
+
export { IndexedDbKeyValueStore, openIndexedDbStore, type IndexedDbStoreOptions } from './indexedDbKeyValueStore.js';
|
|
12
|
+
export { idb, type IdbDatabaseLike, type IdbKeyRangeLike, type IdbObjectStoreLike, type IdbOpenRequestLike, type IdbRequestLike, type IdbTransactionLike, } from './idb.js';
|
|
13
|
+
export { createSqlKeyValueStore, type SqlKeyValueStoreOptions } from './sqlKeyValueStore.js';
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/features/kv/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACtF,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,KAAK,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAClH,OAAO,EACL,GAAG,EACH,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,kBAAkB,GACxB,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,sBAAsB,EAAE,KAAK,uBAAuB,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The key-value module, `@framers/sql-storage-adapter/kv`: one `KeyValueStore` contract and its
|
|
3
|
+
* stores. `openIndexedDbStore` keeps values in one IndexedDB object store, moved unchanged from @framers/agentos, so a
|
|
4
|
+
* page's keys stay where they are; `createSqlKeyValueStore` keeps them in a SQL table on any adapter; the memory store
|
|
5
|
+
* keeps them for the page alone.
|
|
6
|
+
*
|
|
7
|
+
* The module imports no adapter, so a page that loads it for its key-value store loads neither sql.js nor pg.
|
|
8
|
+
* @module sql-storage-adapter/kv
|
|
9
|
+
*/
|
|
10
|
+
export { MemoryKeyValueStore, namespaced } from './keyValueStore.js';
|
|
11
|
+
export { IndexedDbKeyValueStore, openIndexedDbStore } from './indexedDbKeyValueStore.js';
|
|
12
|
+
export { idb, } from './idb.js';
|
|
13
|
+
export { createSqlKeyValueStore } from './sqlKeyValueStore.js';
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/features/kv/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAsB,MAAM,iBAAiB,CAAC;AACtF,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAA8B,MAAM,0BAA0B,CAAC;AAClH,OAAO,EACL,GAAG,GAOJ,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,sBAAsB,EAAgC,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The key-value store over one IndexedDB object store with out-of-line keys. It opens a database at
|
|
3
|
+
* the version given (1 by default) and creates the object store only when the open upgrades the database (a new one,
|
|
4
|
+
* or one below that version), so a database another page made at that version is read in place. A browser that
|
|
5
|
+
* refuses IndexedDB gets the memory store.
|
|
6
|
+
* Moved unchanged from @framers/agentos src/core/storage/browser/IndexedDbKeyValueStore.ts: the same database,
|
|
7
|
+
* object store, version and keys.
|
|
8
|
+
* @module sql-storage-adapter/kv/indexedDbKeyValueStore
|
|
9
|
+
*/
|
|
10
|
+
import { type IdbDatabaseLike } from './idb.js';
|
|
11
|
+
import { type KeyValueStore } from './keyValueStore.js';
|
|
12
|
+
/** Where the store lives. */
|
|
13
|
+
export interface IndexedDbStoreOptions {
|
|
14
|
+
/** The database's name. */
|
|
15
|
+
dbName: string;
|
|
16
|
+
/** The object store's name. It is made, with out-of-line keys, only when the open upgrades the database. */
|
|
17
|
+
storeName: string;
|
|
18
|
+
/**
|
|
19
|
+
* The version the database is opened at. A database that exists at this version is opened as it is, even when it
|
|
20
|
+
* lacks the object store, and every call of the store then rejects; one below it is upgraded, and gains the object
|
|
21
|
+
* store when it lacks it; one above it is refused by the browser.
|
|
22
|
+
* @default 1
|
|
23
|
+
*/
|
|
24
|
+
version?: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The store over IndexedDB. Each call is one transaction over the object store: its promise is fulfilled when that
|
|
28
|
+
* transaction completes, and rejected with the reason when its request fails or the transaction is aborted.
|
|
29
|
+
*
|
|
30
|
+
* `keys` and `deletePrefix` read the keys between `prefix` and `prefix` followed by U+FFFF, so they miss a key that
|
|
31
|
+
* holds U+FFFF right after the prefix and goes on: keep keys to characters below it.
|
|
32
|
+
*
|
|
33
|
+
* The connection stays open until `close`: when another tab opens the database at a newer version, its upgrade waits
|
|
34
|
+
* for this tab to close the store or go. A connection the browser closes (the database deleted, the site's storage
|
|
35
|
+
* cleared) is not opened again, and every call then rejects.
|
|
36
|
+
*/
|
|
37
|
+
export declare class IndexedDbKeyValueStore implements KeyValueStore {
|
|
38
|
+
private readonly db;
|
|
39
|
+
private readonly storeName;
|
|
40
|
+
/** Always false: the values are in the browser's database. */
|
|
41
|
+
readonly memoryOnly = false;
|
|
42
|
+
/**
|
|
43
|
+
* @param db - An open database that holds the object store.
|
|
44
|
+
* @param storeName - The object store's name.
|
|
45
|
+
*/
|
|
46
|
+
constructor(db: IdbDatabaseLike, storeName: string);
|
|
47
|
+
private run;
|
|
48
|
+
private static range;
|
|
49
|
+
/** The value held under `key`, or undefined when there is none. */
|
|
50
|
+
get<T = unknown>(key: string): Promise<T | undefined>;
|
|
51
|
+
/** Holds a structured clone of `value` under `key`. */
|
|
52
|
+
set(key: string, value: unknown): Promise<void>;
|
|
53
|
+
/** Removes `key`. */
|
|
54
|
+
delete(key: string): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Every key that begins with `prefix`, in order. With an empty prefix, every key of the object store, a key that is
|
|
57
|
+
* not a string (a number, a date or an array another page wrote) given as `String` writes it.
|
|
58
|
+
*/
|
|
59
|
+
keys(prefix: string): Promise<string[]>;
|
|
60
|
+
/** Removes every key that begins with `prefix`; with an empty prefix, everything the object store holds. */
|
|
61
|
+
deletePrefix(prefix: string): Promise<void>;
|
|
62
|
+
/** Closes the database connection. */
|
|
63
|
+
close(): void;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Opens the store, or the memory store when the browser refuses IndexedDB: a page with no `indexedDB`, an `open`
|
|
67
|
+
* that throws or fails (a database above `version` among them), or an upgrade that waits on another tab. The
|
|
68
|
+
* answer's `memoryOnly` says which it is; the memory store's `close` does nothing.
|
|
69
|
+
*
|
|
70
|
+
* An upgrade that waited on another tab still has its turn once that tab closes the database. It is aborted then,
|
|
71
|
+
* so the database stays as it was and the connection it opened is closed: nothing is left open behind the memory
|
|
72
|
+
* store.
|
|
73
|
+
*/
|
|
74
|
+
export declare function openIndexedDbStore(options: IndexedDbStoreOptions): Promise<KeyValueStore & {
|
|
75
|
+
close(): void;
|
|
76
|
+
}>;
|
|
77
|
+
//# sourceMappingURL=indexedDbKeyValueStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexedDbKeyValueStore.d.ts","sourceRoot":"","sources":["../../../src/features/kv/indexedDbKeyValueStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAO,KAAK,eAAe,EAAsE,MAAM,OAAO,CAAC;AACtH,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE1E,6BAA6B;AAC7B,MAAM,WAAW,qBAAqB;IACpC,2BAA2B;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,4GAA4G;IAC5G,SAAS,EAAE,MAAM,CAAC;IAClB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;GAUG;AACH,qBAAa,sBAAuB,YAAW,aAAa;IAQ9C,OAAO,CAAC,QAAQ,CAAC,EAAE;IAAmB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAP5E,8DAA8D;IAC9D,QAAQ,CAAC,UAAU,SAAS;IAE5B;;;OAGG;gBAC0B,EAAE,EAAE,eAAe,EAAmB,SAAS,EAAE,MAAM;IAEpF,OAAO,CAAC,GAAG;IAaX,OAAO,CAAC,MAAM,CAAC,KAAK;IAIpB,mEAAmE;IAC7D,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAI3D,uDAAuD;IACjD,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAIrD,qBAAqB;IACf,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxC;;;OAGG;IACG,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAK7C,4GAA4G;IACtG,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKjD,sCAAsC;IACtC,KAAK,IAAI,IAAI;CAGd;AAED;;;;;;;;GAQG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,aAAa,GAAG;IAAE,KAAK,IAAI,IAAI,CAAA;CAAE,CAAC,CAoCnH"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The key-value store over one IndexedDB object store with out-of-line keys. It opens a database at
|
|
3
|
+
* the version given (1 by default) and creates the object store only when the open upgrades the database (a new one,
|
|
4
|
+
* or one below that version), so a database another page made at that version is read in place. A browser that
|
|
5
|
+
* refuses IndexedDB gets the memory store.
|
|
6
|
+
* Moved unchanged from @framers/agentos src/core/storage/browser/IndexedDbKeyValueStore.ts: the same database,
|
|
7
|
+
* object store, version and keys.
|
|
8
|
+
* @module sql-storage-adapter/kv/indexedDbKeyValueStore
|
|
9
|
+
*/
|
|
10
|
+
import { idb } from './idb.js';
|
|
11
|
+
import { MemoryKeyValueStore } from './keyValueStore.js';
|
|
12
|
+
/**
|
|
13
|
+
* The store over IndexedDB. Each call is one transaction over the object store: its promise is fulfilled when that
|
|
14
|
+
* transaction completes, and rejected with the reason when its request fails or the transaction is aborted.
|
|
15
|
+
*
|
|
16
|
+
* `keys` and `deletePrefix` read the keys between `prefix` and `prefix` followed by U+FFFF, so they miss a key that
|
|
17
|
+
* holds U+FFFF right after the prefix and goes on: keep keys to characters below it.
|
|
18
|
+
*
|
|
19
|
+
* The connection stays open until `close`: when another tab opens the database at a newer version, its upgrade waits
|
|
20
|
+
* for this tab to close the store or go. A connection the browser closes (the database deleted, the site's storage
|
|
21
|
+
* cleared) is not opened again, and every call then rejects.
|
|
22
|
+
*/
|
|
23
|
+
export class IndexedDbKeyValueStore {
|
|
24
|
+
/**
|
|
25
|
+
* @param db - An open database that holds the object store.
|
|
26
|
+
* @param storeName - The object store's name.
|
|
27
|
+
*/
|
|
28
|
+
constructor(db, storeName) {
|
|
29
|
+
this.db = db;
|
|
30
|
+
this.storeName = storeName;
|
|
31
|
+
/** Always false: the values are in the browser's database. */
|
|
32
|
+
this.memoryOnly = false;
|
|
33
|
+
}
|
|
34
|
+
run(mode, work) {
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
const transaction = this.db.transaction(this.storeName, mode);
|
|
37
|
+
const request = work(transaction.objectStore(this.storeName));
|
|
38
|
+
transaction.oncomplete = () => resolve(request.result);
|
|
39
|
+
// A failed request's event reaches the transaction before the transaction is aborted for it, so the
|
|
40
|
+
// transaction's own error is still null then, and the request's says why. A transaction aborted for a reason
|
|
41
|
+
// of its own has that reason set by the time its unfinished request's event arrives.
|
|
42
|
+
transaction.onerror = () => reject(transaction.error ?? request.error ?? new Error('IndexedDB request failed'));
|
|
43
|
+
transaction.onabort = () => reject(transaction.error ?? new Error('IndexedDB transaction aborted'));
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
static range(prefix) {
|
|
47
|
+
return prefix === '' ? undefined : idb().keyRange.bound(prefix, `${prefix}\uffff`);
|
|
48
|
+
}
|
|
49
|
+
/** The value held under `key`, or undefined when there is none. */
|
|
50
|
+
async get(key) {
|
|
51
|
+
return (await this.run('readonly', (store) => store.get(key)));
|
|
52
|
+
}
|
|
53
|
+
/** Holds a structured clone of `value` under `key`. */
|
|
54
|
+
async set(key, value) {
|
|
55
|
+
await this.run('readwrite', (store) => store.put(value, key));
|
|
56
|
+
}
|
|
57
|
+
/** Removes `key`. */
|
|
58
|
+
async delete(key) {
|
|
59
|
+
await this.run('readwrite', (store) => store.delete(key));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Every key that begins with `prefix`, in order. With an empty prefix, every key of the object store, a key that is
|
|
63
|
+
* not a string (a number, a date or an array another page wrote) given as `String` writes it.
|
|
64
|
+
*/
|
|
65
|
+
async keys(prefix) {
|
|
66
|
+
const keys = await this.run('readonly', (store) => store.getAllKeys(IndexedDbKeyValueStore.range(prefix)));
|
|
67
|
+
return keys.map(String).filter((key) => key.startsWith(prefix)).sort();
|
|
68
|
+
}
|
|
69
|
+
/** Removes every key that begins with `prefix`; with an empty prefix, everything the object store holds. */
|
|
70
|
+
async deletePrefix(prefix) {
|
|
71
|
+
const range = IndexedDbKeyValueStore.range(prefix);
|
|
72
|
+
await this.run('readwrite', (store) => (range ? store.delete(range) : store.clear()));
|
|
73
|
+
}
|
|
74
|
+
/** Closes the database connection. */
|
|
75
|
+
close() {
|
|
76
|
+
this.db.close();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Opens the store, or the memory store when the browser refuses IndexedDB: a page with no `indexedDB`, an `open`
|
|
81
|
+
* that throws or fails (a database above `version` among them), or an upgrade that waits on another tab. The
|
|
82
|
+
* answer's `memoryOnly` says which it is; the memory store's `close` does nothing.
|
|
83
|
+
*
|
|
84
|
+
* An upgrade that waited on another tab still has its turn once that tab closes the database. It is aborted then,
|
|
85
|
+
* so the database stays as it was and the connection it opened is closed: nothing is left open behind the memory
|
|
86
|
+
* store.
|
|
87
|
+
*/
|
|
88
|
+
export async function openIndexedDbStore(options) {
|
|
89
|
+
try {
|
|
90
|
+
const db = await new Promise((resolve, reject) => {
|
|
91
|
+
const request = idb().factory.open(options.dbName, options.version ?? 1);
|
|
92
|
+
// True once the promise is settled. The browser does not end a blocked open: it goes on when the other tab
|
|
93
|
+
// closes the database, after the store has answered from memory, and what it opens then is nobody's.
|
|
94
|
+
let answered = false;
|
|
95
|
+
const refuse = (reason) => {
|
|
96
|
+
answered = true;
|
|
97
|
+
reject(reason);
|
|
98
|
+
};
|
|
99
|
+
request.onupgradeneeded = () => {
|
|
100
|
+
if (answered && request.transaction) {
|
|
101
|
+
// Aborting the upgrade fails the open, which closes its connection and leaves the database as it was.
|
|
102
|
+
request.transaction.abort();
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (!request.result.objectStoreNames.contains(options.storeName))
|
|
106
|
+
request.result.createObjectStore(options.storeName);
|
|
107
|
+
};
|
|
108
|
+
request.onsuccess = () => {
|
|
109
|
+
if (answered) {
|
|
110
|
+
// An open that succeeds after the answer (an upgrade that could not be aborted) is closed at once.
|
|
111
|
+
request.result.close();
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
answered = true;
|
|
115
|
+
resolve(request.result);
|
|
116
|
+
};
|
|
117
|
+
request.onerror = () => refuse(request.error);
|
|
118
|
+
request.onblocked = () => refuse(new Error('the database is held open by another tab at an older version'));
|
|
119
|
+
});
|
|
120
|
+
return new IndexedDbKeyValueStore(db, options.storeName);
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
const memory = new MemoryKeyValueStore();
|
|
124
|
+
return Object.assign(memory, { close: () => undefined });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=indexedDbKeyValueStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexedDbKeyValueStore.js","sourceRoot":"","sources":["../../../src/features/kv/indexedDbKeyValueStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,GAAG,EAA4F,MAAM,OAAO,CAAC;AACtH,OAAO,EAAE,mBAAmB,EAAsB,MAAM,iBAAiB,CAAC;AAiB1E;;;;;;;;;;GAUG;AACH,MAAM,OAAO,sBAAsB;IAIjC;;;OAGG;IACH,YAA6B,EAAmB,EAAmB,SAAiB;QAAvD,OAAE,GAAF,EAAE,CAAiB;QAAmB,cAAS,GAAT,SAAS,CAAQ;QAPpF,8DAA8D;QACrD,eAAU,GAAG,KAAK,CAAC;IAM2D,CAAC;IAEhF,GAAG,CAAI,IAA8B,EAAE,IAAsD;QACnG,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,MAAM,WAAW,GAAG,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;YAC9D,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;YAC9D,WAAW,CAAC,UAAU,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YACvD,oGAAoG;YACpG,6GAA6G;YAC7G,qFAAqF;YACrF,WAAW,CAAC,OAAO,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,IAAI,OAAO,CAAC,KAAK,IAAI,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC,CAAC;YAChH,WAAW,CAAC,OAAO,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,IAAI,IAAI,KAAK,CAAC,+B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AAC,OAAO,CAAC,SAAS,CAAC;oBAAE,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YACxH,CAAC,CAAC;YACF,OAAO,CAAC,SAAS,GAAG,GAAG,EAAE;gBACvB,IAAI,QAAQ,EAAE,CAAC;oBACb,mGAAmG;oBACnG,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;oBACvB,OAAO;gBACT,CAAC;gBACD,QAAQ,GAAG,IAAI,CAAC;gBAChB,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAC1B,CAAC,CAAC;YACF,OAAO,CAAC,OAAO,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAC9C,OAAO,CAAC,SAAS,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAC,CAAC;QAC9G,CAAC,CAAC,CAAC;QACH,OAAO,IAAI,sBAAsB,CAAC,EAAE,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IAC3D,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,MAAM,GAAG,IAAI,mBAAmB,EAAE,CAAC;QACzC,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,SAAS,EAAE,CAAC,CAAC;IAC3D,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview A key-value store for a page: values are structured-cloneable, keys are listed and removed by
|
|
3
|
+
* prefix. `namespaced` scopes one to a prefix, which keeps two users of one browser apart when neither's prefix
|
|
4
|
+
* begins with the other's.
|
|
5
|
+
* Moved unchanged from @framers/agentos src/core/storage/browser/KeyValueStore.ts.
|
|
6
|
+
* @module sql-storage-adapter/kv/keyValueStore
|
|
7
|
+
*/
|
|
8
|
+
/** What a page's store does. */
|
|
9
|
+
export interface KeyValueStore {
|
|
10
|
+
/** True when nothing outlives the page (a browser that refused the database). */
|
|
11
|
+
readonly memoryOnly: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* The value held under `key`, or undefined when there is none. The type argument is the caller's word for what
|
|
14
|
+
* it stored: the store checks nothing of what it reads.
|
|
15
|
+
*/
|
|
16
|
+
get<T = unknown>(key: string): Promise<T | undefined>;
|
|
17
|
+
/** Holds `value` under `key`, in place of what was there. The value must be one the structured clone can copy. */
|
|
18
|
+
set(key: string, value: unknown): Promise<void>;
|
|
19
|
+
/** Removes `key`. A key that is not held is no error. */
|
|
20
|
+
delete(key: string): Promise<void>;
|
|
21
|
+
/** Every key that begins with `prefix`, in order. */
|
|
22
|
+
keys(prefix: string): Promise<string[]>;
|
|
23
|
+
/** Removes every key that begins with `prefix`. */
|
|
24
|
+
deletePrefix(prefix: string): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
/** A store held in memory. Values are copied in and out with `structuredClone`, as IndexedDB copies them. */
|
|
27
|
+
export declare class MemoryKeyValueStore implements KeyValueStore {
|
|
28
|
+
/** Always true: the values go with the page. */
|
|
29
|
+
readonly memoryOnly = true;
|
|
30
|
+
private readonly values;
|
|
31
|
+
/** A copy of the value held under `key`, or undefined. */
|
|
32
|
+
get<T = unknown>(key: string): Promise<T | undefined>;
|
|
33
|
+
/** Holds a copy of `value` under `key`. */
|
|
34
|
+
set(key: string, value: unknown): Promise<void>;
|
|
35
|
+
/** Removes `key`. */
|
|
36
|
+
delete(key: string): Promise<void>;
|
|
37
|
+
/** Every key that begins with `prefix`, in order. */
|
|
38
|
+
keys(prefix: string): Promise<string[]>;
|
|
39
|
+
/** Removes every key that begins with `prefix`. */
|
|
40
|
+
deletePrefix(prefix: string): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* A store whose keys all begin with `prefix`; its own keys are answered without it. Two namespaces stay apart only
|
|
44
|
+
* when neither prefix begins with the other, so end each with a character no id holds: the keys under `anna` are
|
|
45
|
+
* among those under `ann`, while `ann/` and `anna/` never meet. Each call makes a new store object.
|
|
46
|
+
*/
|
|
47
|
+
export declare function namespaced(store: KeyValueStore, prefix: string): KeyValueStore;
|
|
48
|
+
//# sourceMappingURL=keyValueStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyValueStore.d.ts","sourceRoot":"","sources":["../../../src/features/kv/keyValueStore.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,gCAAgC;AAChC,MAAM,WAAW,aAAa;IAC5B,iFAAiF;IACjF,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B;;;OAGG;IACH,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;IACtD,kHAAkH;IAClH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,yDAAyD;IACzD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,qDAAqD;IACrD,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACxC,mDAAmD;IACnD,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7C;AAED,6GAA6G;AAC7G,qBAAa,mBAAoB,YAAW,aAAa;IACvD,gDAAgD;IAChD,QAAQ,CAAC,UAAU,QAAQ;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA8B;IAErD,0DAA0D;IACpD,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAI3D,2CAA2C;IACrC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,G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