@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
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
/** A store held in memory. Values are copied in and out with `structuredClone`, as IndexedDB copies them. */
|
|
9
|
+
export class MemoryKeyValueStore {
|
|
10
|
+
constructor() {
|
|
11
|
+
/** Always true: the values go with the page. */
|
|
12
|
+
this.memoryOnly = true;
|
|
13
|
+
this.values = new Map();
|
|
14
|
+
}
|
|
15
|
+
/** A copy of the value held under `key`, or undefined. */
|
|
16
|
+
async get(key) {
|
|
17
|
+
return this.values.has(key) ? structuredClone(this.values.get(key)) : undefined;
|
|
18
|
+
}
|
|
19
|
+
/** Holds a copy of `value` under `key`. */
|
|
20
|
+
async set(key, value) {
|
|
21
|
+
this.values.set(key, structuredClone(value));
|
|
22
|
+
}
|
|
23
|
+
/** Removes `key`. */
|
|
24
|
+
async delete(key) {
|
|
25
|
+
this.values.delete(key);
|
|
26
|
+
}
|
|
27
|
+
/** Every key that begins with `prefix`, in order. */
|
|
28
|
+
async keys(prefix) {
|
|
29
|
+
return [...this.values.keys()].filter((key) => key.startsWith(prefix)).sort();
|
|
30
|
+
}
|
|
31
|
+
/** Removes every key that begins with `prefix`. */
|
|
32
|
+
async deletePrefix(prefix) {
|
|
33
|
+
for (const key of await this.keys(prefix))
|
|
34
|
+
this.values.delete(key);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A store whose keys all begin with `prefix`; its own keys are answered without it. Two namespaces stay apart only
|
|
39
|
+
* when neither prefix begins with the other, so end each with a character no id holds: the keys under `anna` are
|
|
40
|
+
* among those under `ann`, while `ann/` and `anna/` never meet. Each call makes a new store object.
|
|
41
|
+
*/
|
|
42
|
+
export function namespaced(store, prefix) {
|
|
43
|
+
return {
|
|
44
|
+
get memoryOnly() {
|
|
45
|
+
return store.memoryOnly;
|
|
46
|
+
},
|
|
47
|
+
get: (key) => store.get(prefix + key),
|
|
48
|
+
set: (key, value) => store.set(prefix + key, value),
|
|
49
|
+
delete: (key) => store.delete(prefix + key),
|
|
50
|
+
keys: async (inner) => (await store.keys(prefix + inner)).map((key) => key.slice(prefix.length)),
|
|
51
|
+
deletePrefix: (inner) => store.deletePrefix(prefix + inner),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=keyValueStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyValueStore.js","sourceRoot":"","sources":["../../../src/features/kv/keyValueStore.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAqBH,6GAA6G;AAC7G,MAAM,OAAO,mBAAmB;IAAhC;QACE,gDAAgD;QACvC,eAAU,GAAG,IAAI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C,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC;QACrC,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,GAAG,GAAG,EAAE,KAAK,CAAC;QACnD,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC;QAC3C,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAChG,YAAY,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,GAAG,KAAK,CAAC;KAC5D,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The key-value store over a SQL table, on any adapter: better-sqlite3 and sql.js files, the IndexedDB
|
|
3
|
+
* adapter in a browser, Capacitor on a phone, PostgreSQL on a server. It answers the calls the IndexedDB store answers,
|
|
4
|
+
* and gives back each value as the structured clone does (see `valueCodec`), so a host keeps one key-value contract on
|
|
5
|
+
* every platform.
|
|
6
|
+
* @module sql-storage-adapter/kv/sqlKeyValueStore
|
|
7
|
+
*/
|
|
8
|
+
import type { StorageAdapter } from '../../core/contracts/index.js';
|
|
9
|
+
import type { KeyValueStore } from './keyValueStore.js';
|
|
10
|
+
/** Where the store keeps its keys and values. */
|
|
11
|
+
export interface SqlKeyValueStoreOptions {
|
|
12
|
+
/**
|
|
13
|
+
* The table: lower-case letters, digits and underscores, starting with a letter or an underscore, at most 63
|
|
14
|
+
* characters. It is made, with a `key` and a `value` column, when it is missing.
|
|
15
|
+
*/
|
|
16
|
+
table: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Opens the key-value store over `options.table` on `adapter`, making the table when it is missing. The adapter must
|
|
20
|
+
* be open; the store never closes it.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const db = await createDatabase({ segment: 'agentos' });
|
|
25
|
+
* const kv = await createSqlKeyValueStore(db, { table: 'agentos_kv' });
|
|
26
|
+
* await kv.set('notes/1', { title: 'One', saved: Date.now() });
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @throws {Error} When `options.table` is not a table name the store takes.
|
|
30
|
+
*/
|
|
31
|
+
export declare function createSqlKeyValueStore(adapter: StorageAdapter, options: SqlKeyValueStoreOptions): Promise<KeyValueStore & {
|
|
32
|
+
close(): void;
|
|
33
|
+
}>;
|
|
34
|
+
//# sourceMappingURL=sqlKeyValueStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlKeyValueStore.d.ts","sourceRoot":"","sources":["../../../src/features/kv/sqlKeyValueStore.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGrD,iDAAiD;AACjD,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;CACf;AAmFD;;;;;;;;;;;;GAYG;AACH,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,aAAa,GAAG;IAAE,KAAK,IAAI,IAAI,CAAA;CAAE,CAAC,CAU5C"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The key-value store over a SQL table, on any adapter: better-sqlite3 and sql.js files, the IndexedDB
|
|
3
|
+
* adapter in a browser, Capacitor on a phone, PostgreSQL on a server. It answers the calls the IndexedDB store answers,
|
|
4
|
+
* and gives back each value as the structured clone does (see `valueCodec`), so a host keeps one key-value contract on
|
|
5
|
+
* every platform.
|
|
6
|
+
* @module sql-storage-adapter/kv/sqlKeyValueStore
|
|
7
|
+
*/
|
|
8
|
+
import { decodeValue, encodeValue } from './valueCodec.js';
|
|
9
|
+
/** A table name the store takes: an unquoted PostgreSQL identifier, which SQLite takes too. */
|
|
10
|
+
const TABLE_PATTERN = /^[a-z_][a-z0-9_]*$/;
|
|
11
|
+
/** PostgreSQL's identifier limit. */
|
|
12
|
+
const MAX_TABLE_LENGTH = 63;
|
|
13
|
+
/** The length of `text` in characters (code points), as SQLite's and PostgreSQL's `substr` count them. */
|
|
14
|
+
const characters = (text) => Array.from(text).length;
|
|
15
|
+
/**
|
|
16
|
+
* The store over one table. Each call is one statement on the adapter, so it is atomic, and runs in the adapter's
|
|
17
|
+
* transaction rules: through a transaction's handle it joins that transaction.
|
|
18
|
+
*
|
|
19
|
+
* Keys are text and are listed in the order of their UTF-16 code units, as IndexedDB orders them, whatever the
|
|
20
|
+
* database's collation. On PostgreSQL a key cannot hold the NUL character, which its text type refuses.
|
|
21
|
+
*/
|
|
22
|
+
class SqlKeyValueStore {
|
|
23
|
+
constructor(adapter, table) {
|
|
24
|
+
this.adapter = adapter;
|
|
25
|
+
this.table = table;
|
|
26
|
+
this.memoryOnly = !adapter.capabilities.has('persistence');
|
|
27
|
+
}
|
|
28
|
+
/** The value held under `key`, or undefined when there is none. */
|
|
29
|
+
async get(key) {
|
|
30
|
+
const row = await this.adapter.get(`SELECT "value" FROM "${this.table}" WHERE "key" = ?`, [key]);
|
|
31
|
+
return row ? decodeValue(row.value) : undefined;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Holds `value` under `key`, in place of what was there. A value the structured clone refuses is refused with a
|
|
35
|
+
* `DataCloneError` before anything is written, and the key keeps what it held.
|
|
36
|
+
*/
|
|
37
|
+
async set(key, value) {
|
|
38
|
+
const text = encodeValue(value);
|
|
39
|
+
await this.adapter.run(`INSERT INTO "${this.table}" ("key", "value") VALUES (?, ?) ON CONFLICT ("key") DO UPDATE SET "value" = excluded."value"`, [key, text]);
|
|
40
|
+
}
|
|
41
|
+
/** Removes `key`. A key that is not held is no error. */
|
|
42
|
+
async delete(key) {
|
|
43
|
+
await this.adapter.run(`DELETE FROM "${this.table}" WHERE "key" = ?`, [key]);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Every key that begins with `prefix`, in order. The prefix is read literally: `%`, `_` and `*` are characters,
|
|
47
|
+
* not patterns.
|
|
48
|
+
*/
|
|
49
|
+
async keys(prefix) {
|
|
50
|
+
const rows = prefix === ''
|
|
51
|
+
? await this.adapter.all(`SELECT "key" FROM "${this.table}"`)
|
|
52
|
+
: await this.adapter.all(`SELECT "key" FROM "${this.table}" WHERE substr("key", 1, ?) = ?`, [characters(prefix), prefix]);
|
|
53
|
+
return rows
|
|
54
|
+
.map((row) => row.key)
|
|
55
|
+
.filter((key) => key.startsWith(prefix))
|
|
56
|
+
.sort();
|
|
57
|
+
}
|
|
58
|
+
/** Removes every key that begins with `prefix`; with an empty prefix, every key of the table. */
|
|
59
|
+
async deletePrefix(prefix) {
|
|
60
|
+
if (prefix === '') {
|
|
61
|
+
await this.adapter.run(`DELETE FROM "${this.table}"`);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
await this.adapter.run(`DELETE FROM "${this.table}" WHERE substr("key", 1, ?) = ?`, [characters(prefix), prefix]);
|
|
65
|
+
}
|
|
66
|
+
/** Does nothing: the adapter is its caller's, who closes it. */
|
|
67
|
+
close() { }
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Opens the key-value store over `options.table` on `adapter`, making the table when it is missing. The adapter must
|
|
71
|
+
* be open; the store never closes it.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const db = await createDatabase({ segment: 'agentos' });
|
|
76
|
+
* const kv = await createSqlKeyValueStore(db, { table: 'agentos_kv' });
|
|
77
|
+
* await kv.set('notes/1', { title: 'One', saved: Date.now() });
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* @throws {Error} When `options.table` is not a table name the store takes.
|
|
81
|
+
*/
|
|
82
|
+
export async function createSqlKeyValueStore(adapter, options) {
|
|
83
|
+
const table = options.table;
|
|
84
|
+
if (typeof table !== 'string' || !TABLE_PATTERN.test(table) || table.length > MAX_TABLE_LENGTH) {
|
|
85
|
+
throw new Error(`Invalid table name ${JSON.stringify(table)} for the key-value store: lower-case letters, digits and underscores, ` +
|
|
86
|
+
`starting with a letter or an underscore, at most ${MAX_TABLE_LENGTH} characters.`);
|
|
87
|
+
}
|
|
88
|
+
await adapter.exec(`CREATE TABLE IF NOT EXISTS "${table}" ("key" TEXT PRIMARY KEY NOT NULL, "value" TEXT NOT NULL)`);
|
|
89
|
+
return new SqlKeyValueStore(adapter, table);
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=sqlKeyValueStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlKeyValueStore.js","sourceRoot":"","sources":["../../../src/features/kv/sqlKeyValueStore.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAWxD,+FAA+F;AAC/F,MAAM,aAAa,GAAG,oBAAoB,CAAC;AAE3C,qCAAqC;AACrC,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAE5B,0GAA0G;AAC1G,MAAM,UAAU,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;AAErE;;;;;;GAMG;AACH,MAAM,gBAAgB;IAIpB,YACmB,OAAuB,EACvB,KAAa;QADb,YAAO,GAAP,OAAO,CAAgB;QACvB,UAAK,GAAL,KAAK,CAAQ;QAE9B,I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the structured clone,
|
|
3
|
+
* which IndexedDB applies to every value it stores, gives it back: the SQL store and the IndexedDB store then answer
|
|
4
|
+
* alike, and a copy from one into the other can be checked value by value.
|
|
5
|
+
*
|
|
6
|
+
* What comes back, as the structured clone gives it (V8's serializer, which Chrome and Node.js run, is the model):
|
|
7
|
+
* strings (lone surrogates too), numbers (`-0`, `NaN` and the infinities too), booleans, `null`, `undefined`,
|
|
8
|
+
* bigints; plain objects and class instances as plain objects with their own enumerable string-keyed properties, in
|
|
9
|
+
* order; arrays with their holes and their own properties; `Date`, `RegExp` (source and flags), `Map`, `Set`,
|
|
10
|
+
* `ArrayBuffer`, the typed arrays and `DataView` (a view keeps its buffer, its offset and its length, and two views of
|
|
11
|
+
* one buffer share it); `Number`, `String`, `Boolean` and `BigInt` objects; errors, as `Error`, `EvalError`,
|
|
12
|
+
* `RangeError`, `ReferenceError`, `SyntaxError`, `TypeError` or `URIError` by their name, with their message, stack
|
|
13
|
+
* and cause. An object reached twice comes back as one object, and a cycle as a cycle.
|
|
14
|
+
*
|
|
15
|
+
* Refused with a `DataCloneError`, as the structured clone refuses them: functions, symbols, `WeakMap`, `WeakSet`,
|
|
16
|
+
* `WeakRef`, promises, iterators, generators, `SharedArrayBuffer`. Refused too, though IndexedDB keeps them: `Blob`,
|
|
17
|
+
* `File`, `ImageData`, `CryptoKey` and the other host objects, which text cannot hold.
|
|
18
|
+
*
|
|
19
|
+
* The text is JSON: it holds no NUL character, which PostgreSQL's text type refuses, and no lone surrogate, which
|
|
20
|
+
* cannot be encoded as UTF-8.
|
|
21
|
+
* @module sql-storage-adapter/kv/valueCodec
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* Encodes `value` as text the SQL store keeps.
|
|
25
|
+
*
|
|
26
|
+
* @throws {Error} A `DataCloneError` for a value the structured clone refuses, or one text cannot hold.
|
|
27
|
+
*/
|
|
28
|
+
export declare function encodeValue(value: unknown): string;
|
|
29
|
+
/**
|
|
30
|
+
* Decodes text `encodeValue` wrote.
|
|
31
|
+
*
|
|
32
|
+
* @throws {Error} When the text is not one `encodeValue` writes.
|
|
33
|
+
*/
|
|
34
|
+
export declare function decodeValue(text: string): unknown;
|
|
35
|
+
//# sourceMappingURL=valueCodec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"valueCodec.d.ts","sourceRoot":"","sources":["../../../src/features/kv/valueCodec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAkIH;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CA0HlD;AAaD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAiLjD"}
|