@quereus/store 0.3.6 → 0.3.7
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 +2 -2
- package/dist/src/common/ddl-generator.d.ts +15 -0
- package/dist/src/common/ddl-generator.d.ts.map +1 -0
- package/dist/src/common/ddl-generator.js +131 -0
- package/dist/src/common/ddl-generator.js.map +1 -0
- package/dist/src/common/encoding.d.ts +65 -0
- package/dist/src/common/encoding.d.ts.map +1 -0
- package/dist/src/common/encoding.js +339 -0
- package/dist/src/common/encoding.js.map +1 -0
- package/dist/src/common/events.d.ts +119 -0
- package/dist/src/common/events.d.ts.map +1 -0
- package/dist/src/common/events.js +158 -0
- package/dist/src/common/events.js.map +1 -0
- package/dist/src/common/index.d.ts +15 -0
- package/dist/src/common/index.d.ts.map +1 -0
- package/dist/src/common/index.js +23 -0
- package/dist/src/common/index.js.map +1 -0
- package/dist/src/common/key-builder.d.ts +58 -0
- package/dist/src/common/key-builder.d.ts.map +1 -0
- package/dist/src/common/key-builder.js +130 -0
- package/dist/src/common/key-builder.js.map +1 -0
- package/dist/src/common/kv-store.d.ts +150 -0
- package/dist/src/common/kv-store.d.ts.map +1 -0
- package/dist/src/common/kv-store.js +6 -0
- package/dist/src/common/kv-store.js.map +1 -0
- package/dist/src/common/memory-store.d.ts +37 -0
- package/dist/src/common/memory-store.d.ts.map +1 -0
- package/dist/src/common/memory-store.js +146 -0
- package/dist/src/common/memory-store.js.map +1 -0
- package/dist/src/common/serialization.d.ts +41 -0
- package/dist/src/common/serialization.d.ts.map +1 -0
- package/dist/src/common/serialization.js +111 -0
- package/dist/src/common/serialization.js.map +1 -0
- package/dist/src/common/store-connection.d.ts +34 -0
- package/dist/src/common/store-connection.d.ts.map +1 -0
- package/dist/src/common/store-connection.js +55 -0
- package/dist/src/common/store-connection.js.map +1 -0
- package/dist/src/common/store-module.d.ts +111 -0
- package/dist/src/common/store-module.d.ts.map +1 -0
- package/dist/src/common/store-module.js +331 -0
- package/dist/src/common/store-module.js.map +1 -0
- package/dist/src/common/store-table.d.ts +115 -0
- package/dist/src/common/store-table.d.ts.map +1 -0
- package/dist/src/common/store-table.js +472 -0
- package/dist/src/common/store-table.js.map +1 -0
- package/dist/src/common/transaction.d.ts +57 -0
- package/dist/src/common/transaction.d.ts.map +1 -0
- package/dist/src/common/transaction.js +156 -0
- package/dist/src/common/transaction.js.map +1 -0
- package/dist/src/index.d.ts +17 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +18 -0
- package/dist/src/index.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract key-value store interface.
|
|
3
|
+
* Implemented by LevelDBStore (Node.js) and IndexedDBStore (browser).
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Options for iterating over key-value pairs.
|
|
7
|
+
*/
|
|
8
|
+
export interface IterateOptions {
|
|
9
|
+
/** Start key (inclusive). If omitted, starts from beginning. */
|
|
10
|
+
gte?: Uint8Array;
|
|
11
|
+
/** Start key (exclusive). */
|
|
12
|
+
gt?: Uint8Array;
|
|
13
|
+
/** End key (inclusive). */
|
|
14
|
+
lte?: Uint8Array;
|
|
15
|
+
/** End key (exclusive). If omitted, iterates to end. */
|
|
16
|
+
lt?: Uint8Array;
|
|
17
|
+
/** Iterate in reverse order. */
|
|
18
|
+
reverse?: boolean;
|
|
19
|
+
/** Maximum number of entries to return. */
|
|
20
|
+
limit?: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A key-value pair from iteration.
|
|
24
|
+
*/
|
|
25
|
+
export interface KVEntry {
|
|
26
|
+
key: Uint8Array;
|
|
27
|
+
value: Uint8Array;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Batch operation types.
|
|
31
|
+
*/
|
|
32
|
+
export type BatchOp = {
|
|
33
|
+
type: 'put';
|
|
34
|
+
key: Uint8Array;
|
|
35
|
+
value: Uint8Array;
|
|
36
|
+
} | {
|
|
37
|
+
type: 'delete';
|
|
38
|
+
key: Uint8Array;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Write batch for atomic operations.
|
|
42
|
+
*/
|
|
43
|
+
export interface WriteBatch {
|
|
44
|
+
/** Queue a put operation. */
|
|
45
|
+
put(key: Uint8Array, value: Uint8Array): void;
|
|
46
|
+
/** Queue a delete operation. */
|
|
47
|
+
delete(key: Uint8Array): void;
|
|
48
|
+
/** Execute all queued operations atomically. */
|
|
49
|
+
write(): Promise<void>;
|
|
50
|
+
/** Discard all queued operations. */
|
|
51
|
+
clear(): void;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Abstract key-value store interface.
|
|
55
|
+
* Provides sorted key-value storage with range iteration support.
|
|
56
|
+
*/
|
|
57
|
+
export interface KVStore {
|
|
58
|
+
/**
|
|
59
|
+
* Get a value by key.
|
|
60
|
+
* @returns The value, or undefined if not found.
|
|
61
|
+
*/
|
|
62
|
+
get(key: Uint8Array): Promise<Uint8Array | undefined>;
|
|
63
|
+
/**
|
|
64
|
+
* Put a key-value pair.
|
|
65
|
+
*/
|
|
66
|
+
put(key: Uint8Array, value: Uint8Array): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Delete a key.
|
|
69
|
+
*/
|
|
70
|
+
delete(key: Uint8Array): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Check if a key exists.
|
|
73
|
+
*/
|
|
74
|
+
has(key: Uint8Array): Promise<boolean>;
|
|
75
|
+
/**
|
|
76
|
+
* Iterate over key-value pairs in sorted order.
|
|
77
|
+
* Keys are compared lexicographically by bytes.
|
|
78
|
+
*/
|
|
79
|
+
iterate(options?: IterateOptions): AsyncIterable<KVEntry>;
|
|
80
|
+
/**
|
|
81
|
+
* Create a write batch for atomic operations.
|
|
82
|
+
*/
|
|
83
|
+
batch(): WriteBatch;
|
|
84
|
+
/**
|
|
85
|
+
* Close the store and release resources.
|
|
86
|
+
*/
|
|
87
|
+
close(): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Get approximate number of keys in a range.
|
|
90
|
+
* Used for query planning cost estimation.
|
|
91
|
+
*/
|
|
92
|
+
approximateCount(options?: IterateOptions): Promise<number>;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Factory function to open a KVStore.
|
|
96
|
+
*/
|
|
97
|
+
export type KVStoreFactory = (options: KVStoreOptions) => Promise<KVStore>;
|
|
98
|
+
/**
|
|
99
|
+
* Options for opening a KVStore.
|
|
100
|
+
*/
|
|
101
|
+
export interface KVStoreOptions {
|
|
102
|
+
/** Storage path (LevelDB) or database name (IndexedDB). */
|
|
103
|
+
path: string;
|
|
104
|
+
/** Create if doesn't exist. Default: true. */
|
|
105
|
+
createIfMissing?: boolean;
|
|
106
|
+
/** Throw error if already exists. Default: false. */
|
|
107
|
+
errorIfExists?: boolean;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Provider interface for creating/getting KVStore instances.
|
|
111
|
+
*
|
|
112
|
+
* This abstraction allows different storage backends (LevelDB, IndexedDB,
|
|
113
|
+
* React Native AsyncStorage, etc.) to be used with the StoreModule.
|
|
114
|
+
*
|
|
115
|
+
* Implementations should manage store lifecycle and caching.
|
|
116
|
+
*/
|
|
117
|
+
export interface KVStoreProvider {
|
|
118
|
+
/**
|
|
119
|
+
* Get or create a KVStore for a table.
|
|
120
|
+
* @param schemaName - The schema name (e.g., 'main')
|
|
121
|
+
* @param tableName - The table name
|
|
122
|
+
* @param options - Additional options passed from CREATE TABLE
|
|
123
|
+
* @returns The KVStore instance
|
|
124
|
+
*/
|
|
125
|
+
getStore(schemaName: string, tableName: string, options?: Record<string, unknown>): Promise<KVStore>;
|
|
126
|
+
/**
|
|
127
|
+
* Get or create a KVStore for catalog/DDL metadata.
|
|
128
|
+
* Some providers may use the same store as data, others may use a separate store.
|
|
129
|
+
* @returns The KVStore instance for catalog data
|
|
130
|
+
*/
|
|
131
|
+
getCatalogStore(): Promise<KVStore>;
|
|
132
|
+
/**
|
|
133
|
+
* Close a specific store.
|
|
134
|
+
* @param schemaName - The schema name
|
|
135
|
+
* @param tableName - The table name
|
|
136
|
+
*/
|
|
137
|
+
closeStore(schemaName: string, tableName: string): Promise<void>;
|
|
138
|
+
/**
|
|
139
|
+
* Close all stores managed by this provider.
|
|
140
|
+
*/
|
|
141
|
+
closeAll(): Promise<void>;
|
|
142
|
+
/**
|
|
143
|
+
* Optional: Called when a store is first accessed to perform any setup.
|
|
144
|
+
* @param store - The store that was just opened
|
|
145
|
+
* @param schemaName - The schema name
|
|
146
|
+
* @param tableName - The table name
|
|
147
|
+
*/
|
|
148
|
+
onStoreOpened?(store: KVStore, schemaName: string, tableName: string): void;
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=kv-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kv-store.d.ts","sourceRoot":"","sources":["../../../src/common/kv-store.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,gEAAgE;IAChE,GAAG,CAAC,EAAE,UAAU,CAAC;IACjB,6BAA6B;IAC7B,EAAE,CAAC,EAAE,UAAU,CAAC;IAChB,2BAA2B;IAC3B,GAAG,CAAC,EAAE,UAAU,CAAC;IACjB,wDAAwD;IACxD,EAAE,CAAC,EAAE,UAAU,CAAC;IAChB,gCAAgC;IAChC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,2CAA2C;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,GAAG,EAAE,UAAU,CAAC;IAChB,KAAK,EAAE,UAAU,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,MAAM,OAAO,GACf;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,GAAG,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,UAAU,CAAA;CAA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M,WAAW,cAAc;IAC7B,2DAA2D;IAC3D,IAAI,EAAE,MAAM,CAAC;IACb,8CAA8C;IAC9C,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,qDAAqD;IACrD,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;;;OAMG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAErG;;;;OAIG;IACH,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAEpC;;;;OAIG;IACH,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjE;;OAEG;IACH,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1B;;;;;OAKG;IACH,aAAa,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kv-store.js","sourceRoot":"","sources":["../../../src/common/kv-store.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory KVStore implementation.
|
|
3
|
+
*
|
|
4
|
+
* Useful for:
|
|
5
|
+
* - Testing without filesystem/IndexedDB dependencies
|
|
6
|
+
* - Schema seed generation at build time
|
|
7
|
+
* - Temporary storage that doesn't need persistence
|
|
8
|
+
*
|
|
9
|
+
* Keys are stored using hex encoding for correct lexicographic ordering.
|
|
10
|
+
*/
|
|
11
|
+
import type { KVStore, KVEntry, WriteBatch, IterateOptions } from './kv-store.js';
|
|
12
|
+
/**
|
|
13
|
+
* In-memory implementation of KVStore.
|
|
14
|
+
* Uses a Map with hex-encoded keys for correct byte ordering.
|
|
15
|
+
*/
|
|
16
|
+
export declare class InMemoryKVStore implements KVStore {
|
|
17
|
+
private data;
|
|
18
|
+
private closed;
|
|
19
|
+
get(key: Uint8Array): Promise<Uint8Array | undefined>;
|
|
20
|
+
put(key: Uint8Array, value: Uint8Array): Promise<void>;
|
|
21
|
+
delete(key: Uint8Array): Promise<void>;
|
|
22
|
+
has(key: Uint8Array): Promise<boolean>;
|
|
23
|
+
iterate(options?: IterateOptions): AsyncIterable<KVEntry>;
|
|
24
|
+
batch(): WriteBatch;
|
|
25
|
+
close(): Promise<void>;
|
|
26
|
+
approximateCount(options?: IterateOptions): Promise<number>;
|
|
27
|
+
/**
|
|
28
|
+
* Clear all data without closing the store.
|
|
29
|
+
*/
|
|
30
|
+
clear(): void;
|
|
31
|
+
/**
|
|
32
|
+
* Get the number of entries in the store.
|
|
33
|
+
*/
|
|
34
|
+
get size(): number;
|
|
35
|
+
private checkOpen;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=memory-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-store.d.ts","sourceRoot":"","sources":["../../../src/common/memory-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAiBlF;;;GAGG;AACH,qBAAa,eAAgB,YAAW,OAAO;IAC7C,OAAO,CAAC,IAAI,CAA6D;IACzE,OAAO,CAAC,MAAM,CAAS;IAEjB,GAAG,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAKrD,GAAG,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAStD,MAAM,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAKtC,GAAG,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC;IAKrC,OAAO,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,aAAa,CAAC,OAAO,CAAC;IAsChE,KAAK,IAAI,UAAU;IA2Bb,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAKtB,gBAAgB,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC;IAajE;;OAEG;IACH,KAAK,IAAI,IAAI;IAKb;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,OAAO,CAAC,SAAS;CAKlB"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory KVStore implementation.
|
|
3
|
+
*
|
|
4
|
+
* Useful for:
|
|
5
|
+
* - Testing without filesystem/IndexedDB dependencies
|
|
6
|
+
* - Schema seed generation at build time
|
|
7
|
+
* - Temporary storage that doesn't need persistence
|
|
8
|
+
*
|
|
9
|
+
* Keys are stored using hex encoding for correct lexicographic ordering.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Convert Uint8Array to hex string for Map key storage.
|
|
13
|
+
* Hex encoding preserves lexicographic ordering.
|
|
14
|
+
*/
|
|
15
|
+
function keyToHex(key) {
|
|
16
|
+
return Array.from(key).map(b => b.toString(16).padStart(2, '0')).join('');
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Compare two hex strings lexicographically.
|
|
20
|
+
*/
|
|
21
|
+
function compareHex(a, b) {
|
|
22
|
+
return a.localeCompare(b);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* In-memory implementation of KVStore.
|
|
26
|
+
* Uses a Map with hex-encoded keys for correct byte ordering.
|
|
27
|
+
*/
|
|
28
|
+
export class InMemoryKVStore {
|
|
29
|
+
data = new Map();
|
|
30
|
+
closed = false;
|
|
31
|
+
async get(key) {
|
|
32
|
+
this.checkOpen();
|
|
33
|
+
return this.data.get(keyToHex(key))?.value;
|
|
34
|
+
}
|
|
35
|
+
async put(key, value) {
|
|
36
|
+
this.checkOpen();
|
|
37
|
+
// Store copies to prevent external mutation
|
|
38
|
+
this.data.set(keyToHex(key), {
|
|
39
|
+
key: new Uint8Array(key),
|
|
40
|
+
value: new Uint8Array(value),
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
async delete(key) {
|
|
44
|
+
this.checkOpen();
|
|
45
|
+
this.data.delete(keyToHex(key));
|
|
46
|
+
}
|
|
47
|
+
async has(key) {
|
|
48
|
+
this.checkOpen();
|
|
49
|
+
return this.data.has(keyToHex(key));
|
|
50
|
+
}
|
|
51
|
+
async *iterate(options) {
|
|
52
|
+
this.checkOpen();
|
|
53
|
+
// Sort entries by hex key for correct ordering
|
|
54
|
+
const entries = Array.from(this.data.entries())
|
|
55
|
+
.sort((a, b) => compareHex(a[0], b[0]));
|
|
56
|
+
// Apply reverse if requested
|
|
57
|
+
if (options?.reverse) {
|
|
58
|
+
entries.reverse();
|
|
59
|
+
}
|
|
60
|
+
// Calculate bounds
|
|
61
|
+
const gteHex = options?.gte ? keyToHex(options.gte) : undefined;
|
|
62
|
+
const gtHex = options?.gt ? keyToHex(options.gt) : undefined;
|
|
63
|
+
const lteHex = options?.lte ? keyToHex(options.lte) : undefined;
|
|
64
|
+
const ltHex = options?.lt ? keyToHex(options.lt) : undefined;
|
|
65
|
+
let count = 0;
|
|
66
|
+
const limit = options?.limit;
|
|
67
|
+
for (const [keyHex, { key, value }] of entries) {
|
|
68
|
+
// Check lower bounds
|
|
69
|
+
if (gteHex !== undefined && keyHex < gteHex)
|
|
70
|
+
continue;
|
|
71
|
+
if (gtHex !== undefined && keyHex <= gtHex)
|
|
72
|
+
continue;
|
|
73
|
+
// Check upper bounds
|
|
74
|
+
if (lteHex !== undefined && keyHex > lteHex)
|
|
75
|
+
break;
|
|
76
|
+
if (ltHex !== undefined && keyHex >= ltHex)
|
|
77
|
+
break;
|
|
78
|
+
// Check limit
|
|
79
|
+
if (limit !== undefined && count >= limit)
|
|
80
|
+
break;
|
|
81
|
+
yield { key, value };
|
|
82
|
+
count++;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
batch() {
|
|
86
|
+
const ops = [];
|
|
87
|
+
const store = this;
|
|
88
|
+
return {
|
|
89
|
+
put(key, value) {
|
|
90
|
+
ops.push({ type: 'put', key: new Uint8Array(key), value: new Uint8Array(value) });
|
|
91
|
+
},
|
|
92
|
+
delete(key) {
|
|
93
|
+
ops.push({ type: 'delete', key: new Uint8Array(key) });
|
|
94
|
+
},
|
|
95
|
+
async write() {
|
|
96
|
+
for (const op of ops) {
|
|
97
|
+
if (op.type === 'put') {
|
|
98
|
+
await store.put(op.key, op.value);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
await store.delete(op.key);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
ops.length = 0;
|
|
105
|
+
},
|
|
106
|
+
clear() {
|
|
107
|
+
ops.length = 0;
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
async close() {
|
|
112
|
+
this.closed = true;
|
|
113
|
+
this.data.clear();
|
|
114
|
+
}
|
|
115
|
+
async approximateCount(options) {
|
|
116
|
+
this.checkOpen();
|
|
117
|
+
if (!options) {
|
|
118
|
+
return this.data.size;
|
|
119
|
+
}
|
|
120
|
+
// Count entries in range
|
|
121
|
+
let count = 0;
|
|
122
|
+
for await (const _ of this.iterate(options)) {
|
|
123
|
+
count++;
|
|
124
|
+
}
|
|
125
|
+
return count;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Clear all data without closing the store.
|
|
129
|
+
*/
|
|
130
|
+
clear() {
|
|
131
|
+
this.checkOpen();
|
|
132
|
+
this.data.clear();
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Get the number of entries in the store.
|
|
136
|
+
*/
|
|
137
|
+
get size() {
|
|
138
|
+
return this.data.size;
|
|
139
|
+
}
|
|
140
|
+
checkOpen() {
|
|
141
|
+
if (this.closed) {
|
|
142
|
+
throw new Error('InMemoryKVStore is closed');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=memory-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-store.js","sourceRoot":"","sources":["../../../src/common/memory-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH;;;GAGG;AACH,SAAS,QAAQ,CAAC,GAAe;IAC/B,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC5E,CAAC;AAED;;GAEG;AACH,SAAS,UAAU,CAAC,CAAS,EAAE,CAAS;IACtC,OAAO,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;AAC5B,CAAC;AAED;;;GAGG;AACH,MAAM,OAAO,eAAe;IAClB,IAAI,GAAG,IAAI,GAAG,EAAkD,CAAC;IACjE,MAAM,GAAG,KAAK,CAAC;IAEvB,KAAK,CAAC,GAAG,CAAC,GAAe;QACvB,IAAI,CAAC,SAAS,EAAE,CAAC;QACjB,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC;IAC7C,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAe,EAAE,KAAiB;QAC1C,IAAI,CAAC,SAAS,EAAE,CAAC;QACjB,4CAA4C;QAC5C,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YAC3B,GAAG,EAAE,IAAI,UAAU,CAAC,G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;IAEO,SAAS;QACf,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Row serialization for persistent storage.
|
|
3
|
+
*
|
|
4
|
+
* Uses extended JSON format that preserves SQL value types:
|
|
5
|
+
* - bigint: { "$bigint": "12345678901234567890" }
|
|
6
|
+
* - Uint8Array: { "$blob": "base64..." }
|
|
7
|
+
* - Other types: Native JSON representation
|
|
8
|
+
*/
|
|
9
|
+
import type { Row, SqlValue } from '@quereus/quereus';
|
|
10
|
+
/**
|
|
11
|
+
* Serialize a row to a byte array for storage.
|
|
12
|
+
*/
|
|
13
|
+
export declare function serializeRow(row: Row): Uint8Array;
|
|
14
|
+
/**
|
|
15
|
+
* Deserialize a byte array back to a row.
|
|
16
|
+
*/
|
|
17
|
+
export declare function deserializeRow(buffer: Uint8Array): Row;
|
|
18
|
+
/**
|
|
19
|
+
* Serialize a single SQL value to a byte array.
|
|
20
|
+
*/
|
|
21
|
+
export declare function serializeValue(value: SqlValue): Uint8Array;
|
|
22
|
+
/**
|
|
23
|
+
* Deserialize a byte array back to a SQL value.
|
|
24
|
+
*/
|
|
25
|
+
export declare function deserializeValue(buffer: Uint8Array): SqlValue;
|
|
26
|
+
/**
|
|
27
|
+
* Table statistics stored in metadata.
|
|
28
|
+
*/
|
|
29
|
+
export interface TableStats {
|
|
30
|
+
rowCount: number;
|
|
31
|
+
updatedAt: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Serialize table statistics.
|
|
35
|
+
*/
|
|
36
|
+
export declare function serializeStats(stats: TableStats): Uint8Array;
|
|
37
|
+
/**
|
|
38
|
+
* Deserialize table statistics.
|
|
39
|
+
*/
|
|
40
|
+
export declare function deserializeStats(buffer: Uint8Array): TableStats;
|
|
41
|
+
//# sourceMappingURL=serialization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialization.d.ts","sourceRoot":"","sources":["../../../src/common/serialization.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAKtD;;GAEG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,GAAG,UAAU,CAGjD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,GAAG,CAGtD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,QAAQ,GAAG,UAAU,CAG1D;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,GAAG,QAAQ,CAG7D;AA6ED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAE5D;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAE/D"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Row serialization for persistent storage.
|
|
3
|
+
*
|
|
4
|
+
* Uses extended JSON format that preserves SQL value types:
|
|
5
|
+
* - bigint: { "$bigint": "12345678901234567890" }
|
|
6
|
+
* - Uint8Array: { "$blob": "base64..." }
|
|
7
|
+
* - Other types: Native JSON representation
|
|
8
|
+
*/
|
|
9
|
+
const BIGINT_MARKER = '$bigint';
|
|
10
|
+
const BLOB_MARKER = '$blob';
|
|
11
|
+
/**
|
|
12
|
+
* Serialize a row to a byte array for storage.
|
|
13
|
+
*/
|
|
14
|
+
export function serializeRow(row) {
|
|
15
|
+
const json = JSON.stringify(row, replacer);
|
|
16
|
+
return new TextEncoder().encode(json);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Deserialize a byte array back to a row.
|
|
20
|
+
*/
|
|
21
|
+
export function deserializeRow(buffer) {
|
|
22
|
+
const json = new TextDecoder().decode(buffer);
|
|
23
|
+
return JSON.parse(json, reviver);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Serialize a single SQL value to a byte array.
|
|
27
|
+
*/
|
|
28
|
+
export function serializeValue(value) {
|
|
29
|
+
const json = JSON.stringify(value, replacer);
|
|
30
|
+
return new TextEncoder().encode(json);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Deserialize a byte array back to a SQL value.
|
|
34
|
+
*/
|
|
35
|
+
export function deserializeValue(buffer) {
|
|
36
|
+
const json = new TextDecoder().decode(buffer);
|
|
37
|
+
return JSON.parse(json, reviver);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* JSON replacer function for SQL values.
|
|
41
|
+
*/
|
|
42
|
+
function replacer(_key, value) {
|
|
43
|
+
if (typeof value === 'bigint') {
|
|
44
|
+
return { [BIGINT_MARKER]: value.toString() };
|
|
45
|
+
}
|
|
46
|
+
if (value instanceof Uint8Array) {
|
|
47
|
+
return { [BLOB_MARKER]: uint8ArrayToBase64(value) };
|
|
48
|
+
}
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* JSON reviver function for SQL values.
|
|
53
|
+
*/
|
|
54
|
+
function reviver(_key, value) {
|
|
55
|
+
if (value !== null && typeof value === 'object' && !Array.isArray(value)) {
|
|
56
|
+
const obj = value;
|
|
57
|
+
if (BIGINT_MARKER in obj && typeof obj[BIGINT_MARKER] === 'string') {
|
|
58
|
+
return BigInt(obj[BIGINT_MARKER]);
|
|
59
|
+
}
|
|
60
|
+
if (BLOB_MARKER in obj && typeof obj[BLOB_MARKER] === 'string') {
|
|
61
|
+
return base64ToUint8Array(obj[BLOB_MARKER]);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Convert Uint8Array to base64 string.
|
|
68
|
+
* Works in both Node.js and browser environments.
|
|
69
|
+
*/
|
|
70
|
+
function uint8ArrayToBase64(bytes) {
|
|
71
|
+
// Use Buffer in Node.js for efficiency
|
|
72
|
+
if (typeof Buffer !== 'undefined') {
|
|
73
|
+
return Buffer.from(bytes).toString('base64');
|
|
74
|
+
}
|
|
75
|
+
// Browser fallback
|
|
76
|
+
let binary = '';
|
|
77
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
78
|
+
binary += String.fromCharCode(bytes[i]);
|
|
79
|
+
}
|
|
80
|
+
return btoa(binary);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Convert base64 string to Uint8Array.
|
|
84
|
+
* Works in both Node.js and browser environments.
|
|
85
|
+
*/
|
|
86
|
+
function base64ToUint8Array(base64) {
|
|
87
|
+
// Use Buffer in Node.js for efficiency
|
|
88
|
+
if (typeof Buffer !== 'undefined') {
|
|
89
|
+
return new Uint8Array(Buffer.from(base64, 'base64'));
|
|
90
|
+
}
|
|
91
|
+
// Browser fallback
|
|
92
|
+
const binary = atob(base64);
|
|
93
|
+
const bytes = new Uint8Array(binary.length);
|
|
94
|
+
for (let i = 0; i < binary.length; i++) {
|
|
95
|
+
bytes[i] = binary.charCodeAt(i);
|
|
96
|
+
}
|
|
97
|
+
return bytes;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Serialize table statistics.
|
|
101
|
+
*/
|
|
102
|
+
export function serializeStats(stats) {
|
|
103
|
+
return new TextEncoder().encode(JSON.stringify(stats));
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Deserialize table statistics.
|
|
107
|
+
*/
|
|
108
|
+
export function deserializeStats(buffer) {
|
|
109
|
+
return JSON.parse(new TextDecoder().decode(buffer));
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=serialization.js.map
|
|
@@ -0,0 +1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B,CAAC;AAED;;;GAGG;AACH,SAAS,kBAAkB,CAAC,MAAc;IACxC,uCAAuC;IACvC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IACvD,CAAC;IAED,mBAAmB;IACnB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;IAC5B,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC5C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACvC,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAClC,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAcD;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,KAAiB;IAC9C,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;AACzD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAkB;IACjD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAe,CAAC;AACpE,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic VirtualTableConnection implementation for KVStore-backed tables.
|
|
3
|
+
*
|
|
4
|
+
* Delegates transaction operations to a shared TransactionCoordinator.
|
|
5
|
+
*/
|
|
6
|
+
import type { VirtualTableConnection } from '@quereus/quereus';
|
|
7
|
+
import type { TransactionCoordinator } from './transaction.js';
|
|
8
|
+
/**
|
|
9
|
+
* Connection to a KVStore-backed table.
|
|
10
|
+
* All connections share a TransactionCoordinator for multi-table atomicity.
|
|
11
|
+
*/
|
|
12
|
+
export declare class StoreConnection implements VirtualTableConnection {
|
|
13
|
+
readonly connectionId: string;
|
|
14
|
+
readonly tableName: string;
|
|
15
|
+
private coordinator;
|
|
16
|
+
constructor(tableName: string, coordinator: TransactionCoordinator);
|
|
17
|
+
/** Begin a transaction. */
|
|
18
|
+
begin(): void;
|
|
19
|
+
/** Commit the transaction. */
|
|
20
|
+
commit(): Promise<void>;
|
|
21
|
+
/** Rollback the transaction. */
|
|
22
|
+
rollback(): void;
|
|
23
|
+
/** Create a savepoint. */
|
|
24
|
+
createSavepoint(index: number): void;
|
|
25
|
+
/** Release a savepoint. */
|
|
26
|
+
releaseSavepoint(index: number): void;
|
|
27
|
+
/** Rollback to a savepoint. */
|
|
28
|
+
rollbackToSavepoint(index: number): void;
|
|
29
|
+
/** Disconnect (rolls back if in transaction). */
|
|
30
|
+
disconnect(): Promise<void>;
|
|
31
|
+
/** Get the coordinator for mutation operations. */
|
|
32
|
+
getCoordinator(): TransactionCoordinator;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=store-connection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store-connection.d.ts","sourceRoot":"","sources":["../../../src/common/store-connection.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAI/D;;;GAGG;AACH,qBAAa,eAAgB,YAAW,sBAAsB;IAC5D,SAAgB,YAAY,EAAE,MAAM,CAAC;IACrC,SAAgB,SAAS,EAAE,MAAM,CAAC;IAClC,OAAO,CAAC,WAAW,CAAyB;gBAEhC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,sBAAsB;IAMlE,2BAA2B;IAC3B,KAAK,IAAI,IAAI;IAIb,8BAA8B;IACxB,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAI7B,gCAAgC;IAChC,QAAQ,IAAI,IAAI;IAIhB,0BAA0B;IAC1B,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAIpC,2BAA2B;IAC3B,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAIrC,+BAA+B;IAC/B,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAIxC,iDAAiD;IAC3C,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAMjC,mDAAmD;IACnD,cAAc,IAAI,sBAAsB;CAGzC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic VirtualTableConnection implementation for KVStore-backed tables.
|
|
3
|
+
*
|
|
4
|
+
* Delegates transaction operations to a shared TransactionCoordinator.
|
|
5
|
+
*/
|
|
6
|
+
let connectionCounter = 0;
|
|
7
|
+
/**
|
|
8
|
+
* Connection to a KVStore-backed table.
|
|
9
|
+
* All connections share a TransactionCoordinator for multi-table atomicity.
|
|
10
|
+
*/
|
|
11
|
+
export class StoreConnection {
|
|
12
|
+
connectionId;
|
|
13
|
+
tableName;
|
|
14
|
+
coordinator;
|
|
15
|
+
constructor(tableName, coordinator) {
|
|
16
|
+
this.connectionId = `store-${tableName}-${++connectionCounter}`;
|
|
17
|
+
this.tableName = tableName;
|
|
18
|
+
this.coordinator = coordinator;
|
|
19
|
+
}
|
|
20
|
+
/** Begin a transaction. */
|
|
21
|
+
begin() {
|
|
22
|
+
this.coordinator.begin();
|
|
23
|
+
}
|
|
24
|
+
/** Commit the transaction. */
|
|
25
|
+
async commit() {
|
|
26
|
+
await this.coordinator.commit();
|
|
27
|
+
}
|
|
28
|
+
/** Rollback the transaction. */
|
|
29
|
+
rollback() {
|
|
30
|
+
this.coordinator.rollback();
|
|
31
|
+
}
|
|
32
|
+
/** Create a savepoint. */
|
|
33
|
+
createSavepoint(index) {
|
|
34
|
+
this.coordinator.createSavepoint(index);
|
|
35
|
+
}
|
|
36
|
+
/** Release a savepoint. */
|
|
37
|
+
releaseSavepoint(index) {
|
|
38
|
+
this.coordinator.releaseSavepoint(index);
|
|
39
|
+
}
|
|
40
|
+
/** Rollback to a savepoint. */
|
|
41
|
+
rollbackToSavepoint(index) {
|
|
42
|
+
this.coordinator.rollbackToSavepoint(index);
|
|
43
|
+
}
|
|
44
|
+
/** Disconnect (rolls back if in transaction). */
|
|
45
|
+
async disconnect() {
|
|
46
|
+
if (this.coordinator.isInTransaction()) {
|
|
47
|
+
this.coordinator.rollback();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/** Get the coordinator for mutation operations. */
|
|
51
|
+
getCoordinator() {
|
|
52
|
+
return this.coordinator;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=store-connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store-connection.js","sourceRoot":"","sources":["../../../src/common/store-connection.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,IAAI,iBAAiB,GAAG,CAAC,CAAC;AAE1B;;;GAGG;AACH,MAAM,OAAO,eAAe;IACV,YAAY,CAAS;IACrB,SAAS,CAAS;IAC1B,WAAW,CAAyB;IAE5C,YAAY,SAAiB,EAAE,WAAmC;QAChE,IAAI,CAAC,YAAY,GAAG,SAAS,SAAS,IAAI,EAAE,iBAAiB,EAAE,CAAC;QAChE,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAED,2BAA2B;IAC3B,KAAK;QACH,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;IAC3B,CAAC;IAED,8BAA8B;IAC9B,KAAK,CAAC,MAAM;QACV,MAAM,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;IAClC,CAAC;IAED,gCAAgC;IAChC,QAAQ;QACN,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC;IA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