@quereus/store 0.4.13 → 0.5.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 +52 -4
- package/dist/src/common/index.d.ts +1 -1
- package/dist/src/common/index.d.ts.map +1 -1
- package/dist/src/common/index.js +4 -2
- package/dist/src/common/index.js.map +1 -1
- package/dist/src/common/key-builder.d.ts +75 -27
- package/dist/src/common/key-builder.d.ts.map +1 -1
- package/dist/src/common/key-builder.js +104 -60
- package/dist/src/common/key-builder.js.map +1 -1
- package/dist/src/common/kv-store.d.ts +44 -6
- package/dist/src/common/kv-store.d.ts.map +1 -1
- package/dist/src/common/store-module.d.ts +16 -2
- package/dist/src/common/store-module.d.ts.map +1 -1
- package/dist/src/common/store-module.js +48 -43
- package/dist/src/common/store-module.js.map +1 -1
- package/dist/src/common/store-table.d.ts +30 -5
- package/dist/src/common/store-table.d.ts.map +1 -1
- package/dist/src/common/store-table.js +62 -58
- package/dist/src/common/store-table.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,6 +27,23 @@ This architecture enables:
|
|
|
27
27
|
- **Custom storage backends** - Implement `KVStore` for IndexedDB, LevelDB, LMDB, or other "NoSQL" stores
|
|
28
28
|
- **Dependency injection** - Use `KVStoreProvider` for store management
|
|
29
29
|
|
|
30
|
+
## Storage Architecture
|
|
31
|
+
|
|
32
|
+
The store module uses separate logical stores for different data types:
|
|
33
|
+
|
|
34
|
+
**Store Naming Convention:**
|
|
35
|
+
- `{schema}.{table}` - Data store (row data)
|
|
36
|
+
- `{schema}.{table}_idx_{indexName}` - Index stores (one per secondary index)
|
|
37
|
+
- `{schema}.{table}_stats` - Stats store (row count, metadata)
|
|
38
|
+
- `__catalog__` - Catalog store (DDL metadata)
|
|
39
|
+
|
|
40
|
+
**Key Formats:**
|
|
41
|
+
- **Data keys**: Encoded primary key (no prefix)
|
|
42
|
+
- **Index keys**: Encoded index columns + encoded PK
|
|
43
|
+
- **Catalog keys**: `{schema}.{table}` as string
|
|
44
|
+
|
|
45
|
+
This design eliminates redundant prefixes and groups related stores together by table name.
|
|
46
|
+
|
|
30
47
|
## Installation
|
|
31
48
|
|
|
32
49
|
```bash
|
|
@@ -83,14 +100,22 @@ class MyCustomStore implements KVStore {
|
|
|
83
100
|
iterate(options?: IterateOptions) { /* ... */ }
|
|
84
101
|
batch() { /* ... */ }
|
|
85
102
|
async close() { /* ... */ }
|
|
103
|
+
async approximateCount(options?: IterateOptions) { /* ... */ }
|
|
86
104
|
}
|
|
87
105
|
|
|
88
106
|
class MyCustomProvider implements KVStoreProvider {
|
|
89
107
|
async getStore(schemaName: string, tableName: string) {
|
|
90
108
|
return new MyCustomStore(/* ... */);
|
|
91
109
|
}
|
|
110
|
+
async getIndexStore(schemaName: string, tableName: string, indexName: string) {
|
|
111
|
+
return new MyCustomStore(/* ... */);
|
|
112
|
+
}
|
|
113
|
+
async getStatsStore(schemaName: string, tableName: string) {
|
|
114
|
+
return new MyCustomStore(/* ... */);
|
|
115
|
+
}
|
|
92
116
|
async getCatalogStore() { /* ... */ }
|
|
93
117
|
async closeStore(schemaName: string, tableName: string) { /* ... */ }
|
|
118
|
+
async closeIndexStore(schemaName: string, tableName: string, indexName: string) { /* ... */ }
|
|
94
119
|
async closeAll() { /* ... */ }
|
|
95
120
|
}
|
|
96
121
|
|
|
@@ -113,13 +138,30 @@ interface KVStore {
|
|
|
113
138
|
iterate(options?: IterateOptions): AsyncIterable<KVEntry>;
|
|
114
139
|
batch(): WriteBatch;
|
|
115
140
|
close(): Promise<void>;
|
|
141
|
+
approximateCount(options?: IterateOptions): Promise<number>;
|
|
116
142
|
}
|
|
117
143
|
|
|
118
144
|
interface KVStoreProvider {
|
|
145
|
+
// Get data store for a table
|
|
119
146
|
getStore(schemaName: string, tableName: string): Promise<KVStore>;
|
|
147
|
+
|
|
148
|
+
// Get index store for a secondary index
|
|
149
|
+
getIndexStore(schemaName: string, tableName: string, indexName: string): Promise<KVStore>;
|
|
150
|
+
|
|
151
|
+
// Get stats store for table statistics
|
|
152
|
+
getStatsStore(schemaName: string, tableName: string): Promise<KVStore>;
|
|
153
|
+
|
|
154
|
+
// Get catalog store for DDL metadata
|
|
120
155
|
getCatalogStore(): Promise<KVStore>;
|
|
156
|
+
|
|
157
|
+
// Close specific stores
|
|
121
158
|
closeStore(schemaName: string, tableName: string): Promise<void>;
|
|
159
|
+
closeIndexStore(schemaName: string, tableName: string, indexName: string): Promise<void>;
|
|
122
160
|
closeAll(): Promise<void>;
|
|
161
|
+
|
|
162
|
+
// Optional: Delete stores
|
|
163
|
+
deleteIndexStore?(schemaName: string, tableName: string, indexName: string): Promise<void>;
|
|
164
|
+
deleteTableStores?(schemaName: string, tableName: string): Promise<void>;
|
|
123
165
|
}
|
|
124
166
|
```
|
|
125
167
|
|
|
@@ -162,10 +204,17 @@ interface KVStoreProvider {
|
|
|
162
204
|
|
|
163
205
|
| Export | Description |
|
|
164
206
|
|--------|-------------|
|
|
165
|
-
| `
|
|
207
|
+
| `buildDataStoreName` | Build store name for table data |
|
|
208
|
+
| `buildIndexStoreName` | Build store name for an index |
|
|
209
|
+
| `buildStatsStoreName` | Build store name for table stats |
|
|
210
|
+
| `buildDataKey` | Build key for row data (encoded PK) |
|
|
166
211
|
| `buildIndexKey` | Build key for index entry |
|
|
167
|
-
| `
|
|
168
|
-
| `
|
|
212
|
+
| `buildCatalogKey` | Build key for catalog metadata |
|
|
213
|
+
| `buildFullScanBounds` | Build bounds for full table scan |
|
|
214
|
+
| `buildIndexPrefixBounds` | Build bounds for index prefix scan |
|
|
215
|
+
| `buildCatalogScanBounds` | Build bounds for catalog scan |
|
|
216
|
+
| `CATALOG_STORE_NAME` | Reserved catalog store name constant |
|
|
217
|
+
| `STORE_SUFFIX` | Store name suffixes (INDEX, STATS) |
|
|
169
218
|
|
|
170
219
|
## Related Packages
|
|
171
220
|
|
|
@@ -176,4 +225,3 @@ interface KVStoreProvider {
|
|
|
176
225
|
## License
|
|
177
226
|
|
|
178
227
|
MIT
|
|
179
|
-
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
export type { KVStore, KVEntry, WriteBatch, BatchOp, IterateOptions, KVStoreFactory, KVStoreOptions, KVStoreProvider, } from './kv-store.js';
|
|
5
5
|
export { encodeValue, encodeCompositeKey, decodeValue, decodeCompositeKey, registerCollationEncoder, getCollationEncoder, type CollationEncoder, type EncodeOptions, } from './encoding.js';
|
|
6
6
|
export { serializeRow, deserializeRow, serializeValue, deserializeValue, serializeStats, deserializeStats, type TableStats, } from './serialization.js';
|
|
7
|
-
export {
|
|
7
|
+
export { STORE_SUFFIX, CATALOG_STORE_NAME, buildDataStoreName, buildIndexStoreName, buildStatsStoreName, buildDataKey, buildIndexKey, buildCatalogKey, buildFullScanBounds, buildIndexPrefixBounds, buildCatalogScanBounds, KEY_PREFIX, buildTablePrefix, buildTableScanBounds, buildIndexScanBounds, buildMetaKey, buildMetaScanBounds, } from './key-builder.js';
|
|
8
8
|
export { StoreEventEmitter, type SchemaChangeEvent, type DataChangeEvent, type SchemaChangeListener, type DataChangeListener, } from './events.js';
|
|
9
9
|
export { generateTableDDL, generateIndexDDL, } from './ddl-generator.js';
|
|
10
10
|
export { TransactionCoordinator, type TransactionCallbacks, } from './transaction.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,YAAY,EACV,OAAO,EACP,OAAO,EACP,UAAU,EACV,OAAO,EACP,cAAc,EACd,cAAc,EACd,cAAc,EACd,eAAe,GAChB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EAClB,wBAAwB,EACxB,mBAAmB,EACnB,KAAK,gBAAgB,EACrB,KAAK,aAAa,GACnB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,YAAY,EACZ,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,KAAK,UAAU,GAChB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,YAAY,EACV,OAAO,EACP,OAAO,EACP,UAAU,EACV,OAAO,EACP,cAAc,EACd,cAAc,EACd,cAAc,EACd,eAAe,GAChB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EAClB,wBAAwB,EACxB,mBAAmB,EACnB,KAAK,gBAAgB,EACrB,KAAK,aAAa,GACnB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,YAAY,EACZ,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,KAAK,UAAU,GAChB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACN,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,YAAY,EACZ,aAAa,EACb,eAAe,EACf,mBAAmB,EACnB,sBAAsB,EACtB,sBAAsB,EAEtB,UAAU,EACV,gBAAgB,EAChB,oBAAoB,EACpB,oBAAoB,EACpB,YAAY,EACZ,mBAAmB,GACnB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,iBAAiB,EACjB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,GACxB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACL,sBAAsB,EACtB,KAAK,oBAAoB,GAC1B,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,EACL,UAAU,EACV,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,GACtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAGxD,OAAO,EAAE,WAAW,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/src/common/index.js
CHANGED
|
@@ -5,8 +5,10 @@
|
|
|
5
5
|
export { encodeValue, encodeCompositeKey, decodeValue, decodeCompositeKey, registerCollationEncoder, getCollationEncoder, } from './encoding.js';
|
|
6
6
|
// Row serialization
|
|
7
7
|
export { serializeRow, deserializeRow, serializeValue, deserializeValue, serializeStats, deserializeStats, } from './serialization.js';
|
|
8
|
-
// Key building
|
|
9
|
-
export {
|
|
8
|
+
// Key building - new API
|
|
9
|
+
export { STORE_SUFFIX, CATALOG_STORE_NAME, buildDataStoreName, buildIndexStoreName, buildStatsStoreName, buildDataKey, buildIndexKey, buildCatalogKey, buildFullScanBounds, buildIndexPrefixBounds, buildCatalogScanBounds,
|
|
10
|
+
// Legacy exports (deprecated)
|
|
11
|
+
KEY_PREFIX, buildTablePrefix, buildTableScanBounds, buildIndexScanBounds, buildMetaKey, buildMetaScanBounds, } from './key-builder.js';
|
|
10
12
|
// Events
|
|
11
13
|
export { StoreEventEmitter, } from './events.js';
|
|
12
14
|
// DDL generation
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAcH,eAAe;AACf,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EAClB,wBAAwB,EACxB,mBAAmB,GAGpB,MAAM,eAAe,CAAC;AAEvB,oBAAoB;AACpB,OAAO,EACL,YAAY,EACZ,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,gBAAgB,GAEjB,MAAM,oBAAoB,CAAC;AAE5B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAcH,eAAe;AACf,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EAClB,wBAAwB,EACxB,mBAAmB,GAGpB,MAAM,eAAe,CAAC;AAEvB,oBAAoB;AACpB,OAAO,EACL,YAAY,EACZ,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,gBAAgB,GAEjB,MAAM,oBAAoB,CAAC;AAE5B,yBAAyB;AACzB,OAAO,EACN,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,YAAY,EACZ,aAAa,EACb,eAAe,EACf,mBAAmB,EACnB,sBAAsB,EACtB,sBAAsB;AACtB,8BAA8B;AAC9B,UAAU,EACV,gBAAgB,EAChB,oBAAoB,EACpB,oBAAoB,EACpB,YAAY,EACZ,mBAAmB,GACnB,MAAM,kBAAkB,CAAC;AAE1B,SAAS;AACT,OAAO,EACL,iBAAiB,GAKlB,MAAM,aAAa,CAAC;AAErB,iBAAiB;AACjB,OAAO,EACL,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAE5B,sBAAsB;AACtB,OAAO,EACL,sBAAsB,GAEvB,MAAM,kBAAkB,CAAC;AAE1B,qBAAqB;AACrB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,qCAAqC;AACrC,OAAO,EACL,UAAU,GAGX,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,uBAAuB;AACvB,OAAO,EAAE,WAAW,EAA0B,MAAM,mBAAmB,CAAC"}
|
|
@@ -1,57 +1,105 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Key builder utilities for constructing storage keys.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Storage naming convention:
|
|
5
|
+
* {schema}.{table} - Data store (row data)
|
|
6
|
+
* {schema}.{table}_idx_{name} - Index store (secondary indexes)
|
|
7
|
+
* {schema}.{table}_stats - Stats store (row count, etc.)
|
|
8
|
+
* __catalog__ - Catalog store (DDL metadata)
|
|
9
|
+
*
|
|
10
|
+
* Within each store, keys are minimal:
|
|
11
|
+
* - Data store: just the encoded primary key
|
|
12
|
+
* - Index store: encoded index columns + encoded primary key
|
|
13
|
+
* - Stats store: single empty key (stats is the only value)
|
|
14
|
+
* - Catalog store: {schema}.{table} as the key
|
|
8
15
|
*/
|
|
9
16
|
import type { SqlValue } from '@quereus/quereus';
|
|
10
17
|
import { type EncodeOptions } from './encoding.js';
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
readonly
|
|
18
|
+
/**
|
|
19
|
+
* Store name suffixes for different data types.
|
|
20
|
+
*/
|
|
21
|
+
export declare const STORE_SUFFIX: {
|
|
22
|
+
readonly INDEX: "_idx_";
|
|
23
|
+
readonly STATS: "_stats";
|
|
16
24
|
};
|
|
25
|
+
/** Reserved catalog store name. */
|
|
26
|
+
export declare const CATALOG_STORE_NAME = "__catalog__";
|
|
17
27
|
/**
|
|
18
|
-
* Build a data
|
|
19
|
-
* Format:
|
|
28
|
+
* Build the store name for a table's data.
|
|
29
|
+
* Format: {schema}.{table}
|
|
20
30
|
*/
|
|
21
|
-
export declare function
|
|
31
|
+
export declare function buildDataStoreName(schemaName: string, tableName: string): string;
|
|
22
32
|
/**
|
|
23
|
-
* Build a secondary index
|
|
24
|
-
* Format:
|
|
33
|
+
* Build the store name for a secondary index.
|
|
34
|
+
* Format: {schema}.{table}_idx_{indexName}
|
|
35
|
+
*/
|
|
36
|
+
export declare function buildIndexStoreName(schemaName: string, tableName: string, indexName: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* Build the store name for table statistics.
|
|
39
|
+
* Format: {schema}.{table}_stats
|
|
25
40
|
*/
|
|
26
|
-
export declare function
|
|
41
|
+
export declare function buildStatsStoreName(schemaName: string, tableName: string): string;
|
|
27
42
|
/**
|
|
28
|
-
* Build a
|
|
29
|
-
|
|
43
|
+
* Build a data row key (just the encoded primary key).
|
|
44
|
+
*/
|
|
45
|
+
export declare function buildDataKey(pkValues: SqlValue[], options?: EncodeOptions): Uint8Array;
|
|
46
|
+
/**
|
|
47
|
+
* Build a secondary index key.
|
|
48
|
+
* Format: {encoded_index_cols}{encoded_pk}
|
|
49
|
+
*
|
|
50
|
+
* The index columns come first for range scans, followed by PK for uniqueness.
|
|
30
51
|
*/
|
|
31
|
-
export declare function
|
|
52
|
+
export declare function buildIndexKey(indexValues: SqlValue[], pkValues: SqlValue[], options?: EncodeOptions): Uint8Array;
|
|
32
53
|
/**
|
|
33
|
-
* Build a
|
|
34
|
-
* Format: {
|
|
54
|
+
* Build a catalog key for DDL storage.
|
|
55
|
+
* Format: {schema}.{table}
|
|
35
56
|
*/
|
|
36
|
-
export declare function
|
|
57
|
+
export declare function buildCatalogKey(schemaName: string, tableName: string): Uint8Array;
|
|
37
58
|
/**
|
|
38
|
-
* Build range bounds for scanning all rows
|
|
59
|
+
* Build range bounds for scanning all rows in a data store.
|
|
60
|
+
* Since keys are just encoded PKs, we scan the entire store.
|
|
39
61
|
*/
|
|
40
|
-
export declare function
|
|
62
|
+
export declare function buildFullScanBounds(): {
|
|
41
63
|
gte: Uint8Array;
|
|
42
64
|
lt: Uint8Array;
|
|
43
65
|
};
|
|
44
66
|
/**
|
|
45
|
-
* Build range bounds for scanning an index.
|
|
67
|
+
* Build range bounds for scanning an index with a prefix.
|
|
46
68
|
*/
|
|
47
|
-
export declare function
|
|
69
|
+
export declare function buildIndexPrefixBounds(prefixValues: SqlValue[], options?: EncodeOptions): {
|
|
48
70
|
gte: Uint8Array;
|
|
49
71
|
lt: Uint8Array;
|
|
50
72
|
};
|
|
51
73
|
/**
|
|
52
|
-
* Build range bounds for scanning
|
|
74
|
+
* Build range bounds for scanning catalog entries.
|
|
75
|
+
* Optionally filter by schema prefix.
|
|
53
76
|
*/
|
|
54
|
-
export declare function
|
|
77
|
+
export declare function buildCatalogScanBounds(schemaName?: string): {
|
|
78
|
+
gte: Uint8Array;
|
|
79
|
+
lt: Uint8Array;
|
|
80
|
+
};
|
|
81
|
+
/** @deprecated Use buildDataStoreName instead */
|
|
82
|
+
export declare const KEY_PREFIX: {
|
|
83
|
+
readonly DATA: Uint8Array<ArrayBuffer>;
|
|
84
|
+
readonly INDEX: Uint8Array<ArrayBuffer>;
|
|
85
|
+
readonly META: Uint8Array<ArrayBuffer>;
|
|
86
|
+
};
|
|
87
|
+
/** @deprecated Use buildDataKey instead */
|
|
88
|
+
export declare function buildTablePrefix(_prefix: 'd' | 'i' | 'm', schemaName: string, tableName: string): Uint8Array;
|
|
89
|
+
/** @deprecated Use buildFullScanBounds instead */
|
|
90
|
+
export declare function buildTableScanBounds(_schemaName: string, _tableName: string): {
|
|
91
|
+
gte: Uint8Array;
|
|
92
|
+
lt: Uint8Array;
|
|
93
|
+
};
|
|
94
|
+
/** @deprecated Use buildIndexPrefixBounds instead */
|
|
95
|
+
export declare function buildIndexScanBounds(_schemaName: string, _tableName: string, _indexName: string, prefixValues?: SqlValue[], options?: EncodeOptions): {
|
|
96
|
+
gte: Uint8Array;
|
|
97
|
+
lt: Uint8Array;
|
|
98
|
+
};
|
|
99
|
+
/** @deprecated Use buildCatalogKey instead */
|
|
100
|
+
export declare function buildMetaKey(_metaType: 'ddl' | 'stats' | 'index', schemaName: string, objectName: string, _subName?: string): Uint8Array;
|
|
101
|
+
/** @deprecated Use buildCatalogScanBounds instead */
|
|
102
|
+
export declare function buildMetaScanBounds(_metaType: 'ddl' | 'stats' | 'index', schemaName?: string): {
|
|
55
103
|
gte: Uint8Array;
|
|
56
104
|
lt: Uint8Array;
|
|
57
105
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"key-builder.d.ts","sourceRoot":"","sources":["../../../src/common/key-builder.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{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112 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Key builder utilities for constructing storage keys.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Storage naming convention:
|
|
5
|
+
* {schema}.{table} - Data store (row data)
|
|
6
|
+
* {schema}.{table}_idx_{name} - Index store (secondary indexes)
|
|
7
|
+
* {schema}.{table}_stats - Stats store (row count, etc.)
|
|
8
|
+
* __catalog__ - Catalog store (DDL metadata)
|
|
9
|
+
*
|
|
10
|
+
* Within each store, keys are minimal:
|
|
11
|
+
* - Data store: just the encoded primary key
|
|
12
|
+
* - Index store: encoded index columns + encoded primary key
|
|
13
|
+
* - Stats store: single empty key (stats is the only value)
|
|
14
|
+
* - Catalog store: {schema}.{table} as the key
|
|
8
15
|
*/
|
|
9
16
|
import { encodeCompositeKey } from './encoding.js';
|
|
10
17
|
const encoder = new TextEncoder();
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Store name suffixes for different data types.
|
|
20
|
+
*/
|
|
21
|
+
export const STORE_SUFFIX = {
|
|
22
|
+
INDEX: '_idx_',
|
|
23
|
+
STATS: '_stats',
|
|
16
24
|
};
|
|
17
|
-
/**
|
|
18
|
-
const
|
|
25
|
+
/** Reserved catalog store name. */
|
|
26
|
+
export const CATALOG_STORE_NAME = '__catalog__';
|
|
19
27
|
/**
|
|
20
|
-
* Build a data
|
|
21
|
-
* Format:
|
|
28
|
+
* Build the store name for a table's data.
|
|
29
|
+
* Format: {schema}.{table}
|
|
22
30
|
*/
|
|
23
|
-
export function
|
|
24
|
-
|
|
25
|
-
const pkEncoded = encodeCompositeKey(pkValues, options);
|
|
26
|
-
return concatBytes(tablePrefix, SEPARATOR, pkEncoded);
|
|
31
|
+
export function buildDataStoreName(schemaName, tableName) {
|
|
32
|
+
return `${schemaName}.${tableName}`.toLowerCase();
|
|
27
33
|
}
|
|
28
34
|
/**
|
|
29
|
-
* Build a secondary index
|
|
30
|
-
* Format:
|
|
35
|
+
* Build the store name for a secondary index.
|
|
36
|
+
* Format: {schema}.{table}_idx_{indexName}
|
|
31
37
|
*/
|
|
32
|
-
export function
|
|
33
|
-
|
|
34
|
-
const indexEncoded = encodeCompositeKey(indexValues, options);
|
|
35
|
-
const pkEncoded = encodeCompositeKey(pkValues, options);
|
|
36
|
-
return concatBytes(prefix, indexEncoded, SEPARATOR, pkEncoded);
|
|
38
|
+
export function buildIndexStoreName(schemaName, tableName, indexName) {
|
|
39
|
+
return `${schemaName}.${tableName}_idx_${indexName}`.toLowerCase();
|
|
37
40
|
}
|
|
38
41
|
/**
|
|
39
|
-
* Build
|
|
40
|
-
* Format:
|
|
42
|
+
* Build the store name for table statistics.
|
|
43
|
+
* Format: {schema}.{table}_stats
|
|
41
44
|
*/
|
|
42
|
-
export function
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
export function buildStatsStoreName(schemaName, tableName) {
|
|
46
|
+
return `${schemaName}.${tableName}_stats`.toLowerCase();
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Build a data row key (just the encoded primary key).
|
|
50
|
+
*/
|
|
51
|
+
export function buildDataKey(pkValues, options) {
|
|
52
|
+
return encodeCompositeKey(pkValues, options);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Build a secondary index key.
|
|
56
|
+
* Format: {encoded_index_cols}{encoded_pk}
|
|
57
|
+
*
|
|
58
|
+
* The index columns come first for range scans, followed by PK for uniqueness.
|
|
59
|
+
*/
|
|
60
|
+
export function buildIndexKey(indexValues, pkValues, options) {
|
|
61
|
+
const indexEncoded = encodeCompositeKey(indexValues, options);
|
|
62
|
+
const pkEncoded = encodeCompositeKey(pkValues, options);
|
|
63
|
+
return concatBytes(indexEncoded, pkEncoded);
|
|
48
64
|
}
|
|
49
65
|
/**
|
|
50
|
-
* Build a
|
|
51
|
-
* Format: {
|
|
66
|
+
* Build a catalog key for DDL storage.
|
|
67
|
+
* Format: {schema}.{table}
|
|
52
68
|
*/
|
|
53
|
-
export function
|
|
54
|
-
return encoder.encode(`${
|
|
69
|
+
export function buildCatalogKey(schemaName, tableName) {
|
|
70
|
+
return encoder.encode(`${schemaName}.${tableName}`.toLowerCase());
|
|
55
71
|
}
|
|
56
72
|
/**
|
|
57
|
-
* Build range bounds for scanning all rows
|
|
73
|
+
* Build range bounds for scanning all rows in a data store.
|
|
74
|
+
* Since keys are just encoded PKs, we scan the entire store.
|
|
58
75
|
*/
|
|
59
|
-
export function
|
|
60
|
-
const prefix = `d:${schemaName}.${tableName}:`;
|
|
76
|
+
export function buildFullScanBounds() {
|
|
61
77
|
return {
|
|
62
|
-
gte:
|
|
63
|
-
lt:
|
|
78
|
+
gte: new Uint8Array(0),
|
|
79
|
+
lt: new Uint8Array([0xff]), // All valid encoded keys are < 0xff
|
|
64
80
|
};
|
|
65
81
|
}
|
|
66
82
|
/**
|
|
67
|
-
* Build range bounds for scanning an index.
|
|
83
|
+
* Build range bounds for scanning an index with a prefix.
|
|
68
84
|
*/
|
|
69
|
-
export function
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (prefixValues && prefixValues.length > 0) {
|
|
73
|
-
const valueBytes = encodeCompositeKey(prefixValues, options);
|
|
74
|
-
const gte = concatBytes(prefixBytes, valueBytes);
|
|
75
|
-
return {
|
|
76
|
-
gte,
|
|
77
|
-
lt: incrementLastByte(gte),
|
|
78
|
-
};
|
|
85
|
+
export function buildIndexPrefixBounds(prefixValues, options) {
|
|
86
|
+
if (prefixValues.length === 0) {
|
|
87
|
+
return buildFullScanBounds();
|
|
79
88
|
}
|
|
89
|
+
const prefixEncoded = encodeCompositeKey(prefixValues, options);
|
|
80
90
|
return {
|
|
81
|
-
gte:
|
|
82
|
-
lt: incrementLastByte(
|
|
91
|
+
gte: prefixEncoded,
|
|
92
|
+
lt: incrementLastByte(prefixEncoded),
|
|
83
93
|
};
|
|
84
94
|
}
|
|
85
95
|
/**
|
|
86
|
-
* Build range bounds for scanning
|
|
96
|
+
* Build range bounds for scanning catalog entries.
|
|
97
|
+
* Optionally filter by schema prefix.
|
|
87
98
|
*/
|
|
88
|
-
export function
|
|
89
|
-
let prefix = `m:${metaType}:`;
|
|
99
|
+
export function buildCatalogScanBounds(schemaName) {
|
|
90
100
|
if (schemaName) {
|
|
91
|
-
prefix
|
|
101
|
+
const prefix = `${schemaName}.`.toLowerCase();
|
|
102
|
+
return {
|
|
103
|
+
gte: encoder.encode(prefix),
|
|
104
|
+
lt: incrementLastByte(encoder.encode(prefix)),
|
|
105
|
+
};
|
|
92
106
|
}
|
|
93
107
|
return {
|
|
94
|
-
gte:
|
|
95
|
-
lt:
|
|
108
|
+
gte: new Uint8Array(0),
|
|
109
|
+
lt: new Uint8Array([0xff]),
|
|
96
110
|
};
|
|
97
111
|
}
|
|
98
112
|
/**
|
|
@@ -127,4 +141,34 @@ function concatBytes(...arrays) {
|
|
|
127
141
|
}
|
|
128
142
|
return result;
|
|
129
143
|
}
|
|
144
|
+
// ============================================================================
|
|
145
|
+
// Legacy exports for backwards compatibility during migration
|
|
146
|
+
// These will be removed after all consumers are updated.
|
|
147
|
+
// ============================================================================
|
|
148
|
+
/** @deprecated Use buildDataStoreName instead */
|
|
149
|
+
export const KEY_PREFIX = {
|
|
150
|
+
DATA: encoder.encode('d:'),
|
|
151
|
+
INDEX: encoder.encode('i:'),
|
|
152
|
+
META: encoder.encode('m:'),
|
|
153
|
+
};
|
|
154
|
+
/** @deprecated Use buildDataKey instead */
|
|
155
|
+
export function buildTablePrefix(_prefix, schemaName, tableName) {
|
|
156
|
+
return encoder.encode(`${schemaName}.${tableName}`.toLowerCase());
|
|
157
|
+
}
|
|
158
|
+
/** @deprecated Use buildFullScanBounds instead */
|
|
159
|
+
export function buildTableScanBounds(_schemaName, _tableName) {
|
|
160
|
+
return buildFullScanBounds();
|
|
161
|
+
}
|
|
162
|
+
/** @deprecated Use buildIndexPrefixBounds instead */
|
|
163
|
+
export function buildIndexScanBounds(_schemaName, _tableName, _indexName, prefixValues, options) {
|
|
164
|
+
return buildIndexPrefixBounds(prefixValues || [], options);
|
|
165
|
+
}
|
|
166
|
+
/** @deprecated Use buildCatalogKey instead */
|
|
167
|
+
export function buildMetaKey(_metaType, schemaName, objectName, _subName) {
|
|
168
|
+
return buildCatalogKey(schemaName, objectName);
|
|
169
|
+
}
|
|
170
|
+
/** @deprecated Use buildCatalogScanBounds instead */
|
|
171
|
+
export function buildMetaScanBounds(_metaType, schemaName) {
|
|
172
|
+
return buildCatalogScanBounds(schemaName);
|
|
173
|
+
}
|
|
130
174
|
//# sourceMappingURL=key-builder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"key-builder.js","sourceRoot":"","sources":["../../../src/common/key-builder.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"key-builder.js","sourceRoot":"","sources":["../../../src/common/key-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,kBAAkB,EAAsB,MAAM,eAAe,CAAC;AAEvE,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAElC;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC3B,KAAK,EAAE,OAAO;IACd,KAAK,EAAE,QAAQ;CACN,CAAC;AAEX,mCAAmC;AACnC,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,CAAC;AAEhD;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,UAAkB,EAAE,SAAiB;IACvE,OAAO,GAAG,UAAU,IAAI,SAAS,EAAE,CAAC,WAAW,EAAE,CAAC;AACnD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAClC,UAAkB,EAClB,SAAiB,EACjB,SAAiB;IAEjB,OAAO,GAAG,UAAU,IAAI,SAAS,QAAQ,SAAS,EAAE,CAA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AC;AAED,8CAA8C;AAC9C,MAAM,UAAU,YAAY,CAC3B,SAAoC,EACpC,UAAkB,EAClB,UAAkB,EAClB,QAAiB;IAEjB,OAAO,eAAe,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;AAChD,CAAC;AAED,qDAAqD;AACrD,MAAM,UAAU,mBAAmB,CAClC,SAAoC,EACpC,UAAmB;IAEnB,OAAO,sBAAsB,CAAC,UAAU,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -112,39 +112,77 @@ export interface KVStoreOptions {
|
|
|
112
112
|
* This abstraction allows different storage backends (LevelDB, IndexedDB,
|
|
113
113
|
* React Native AsyncStorage, etc.) to be used with the StoreModule.
|
|
114
114
|
*
|
|
115
|
+
* Storage naming convention:
|
|
116
|
+
* {schema}.{table} - Data store (row data)
|
|
117
|
+
* {schema}.{table}_idx_{name} - Index store (secondary indexes)
|
|
118
|
+
* {schema}.{table}_stats - Stats store (row count, etc.)
|
|
119
|
+
* __catalog__ - Catalog store (DDL metadata)
|
|
120
|
+
*
|
|
115
121
|
* Implementations should manage store lifecycle and caching.
|
|
116
122
|
*/
|
|
117
123
|
export interface KVStoreProvider {
|
|
118
124
|
/**
|
|
119
|
-
* Get or create a KVStore for a table.
|
|
125
|
+
* Get or create a KVStore for a table's row data.
|
|
126
|
+
* Store name: {schema}.{table}
|
|
120
127
|
* @param schemaName - The schema name (e.g., 'main')
|
|
121
128
|
* @param tableName - The table name
|
|
122
129
|
* @param options - Additional options passed from CREATE TABLE
|
|
123
130
|
* @returns The KVStore instance
|
|
124
131
|
*/
|
|
125
132
|
getStore(schemaName: string, tableName: string, options?: Record<string, unknown>): Promise<KVStore>;
|
|
133
|
+
/**
|
|
134
|
+
* Get or create a KVStore for a secondary index.
|
|
135
|
+
* Store name: {schema}.{table}_idx_{indexName}
|
|
136
|
+
* @param schemaName - The schema name
|
|
137
|
+
* @param tableName - The table name
|
|
138
|
+
* @param indexName - The index name
|
|
139
|
+
* @returns The KVStore instance for the index
|
|
140
|
+
*/
|
|
141
|
+
getIndexStore(schemaName: string, tableName: string, indexName: string): Promise<KVStore>;
|
|
142
|
+
/**
|
|
143
|
+
* Get or create a KVStore for table statistics.
|
|
144
|
+
* Store name: {schema}.{table}_stats
|
|
145
|
+
* @param schemaName - The schema name
|
|
146
|
+
* @param tableName - The table name
|
|
147
|
+
* @returns The KVStore instance for stats
|
|
148
|
+
*/
|
|
149
|
+
getStatsStore(schemaName: string, tableName: string): Promise<KVStore>;
|
|
126
150
|
/**
|
|
127
151
|
* Get or create a KVStore for catalog/DDL metadata.
|
|
128
|
-
*
|
|
152
|
+
* Store name: __catalog__
|
|
129
153
|
* @returns The KVStore instance for catalog data
|
|
130
154
|
*/
|
|
131
155
|
getCatalogStore(): Promise<KVStore>;
|
|
132
156
|
/**
|
|
133
|
-
* Close a specific store.
|
|
157
|
+
* Close a specific table's data store.
|
|
134
158
|
* @param schemaName - The schema name
|
|
135
159
|
* @param tableName - The table name
|
|
136
160
|
*/
|
|
137
161
|
closeStore(schemaName: string, tableName: string): Promise<void>;
|
|
162
|
+
/**
|
|
163
|
+
* Close a specific index store.
|
|
164
|
+
* @param schemaName - The schema name
|
|
165
|
+
* @param tableName - The table name
|
|
166
|
+
* @param indexName - The index name
|
|
167
|
+
*/
|
|
168
|
+
closeIndexStore(schemaName: string, tableName: string, indexName: string): Promise<void>;
|
|
138
169
|
/**
|
|
139
170
|
* Close all stores managed by this provider.
|
|
140
171
|
*/
|
|
141
172
|
closeAll(): Promise<void>;
|
|
142
173
|
/**
|
|
143
|
-
*
|
|
144
|
-
* @param
|
|
174
|
+
* Delete an index store entirely (when dropping an index).
|
|
175
|
+
* @param schemaName - The schema name
|
|
176
|
+
* @param tableName - The table name
|
|
177
|
+
* @param indexName - The index name
|
|
178
|
+
*/
|
|
179
|
+
deleteIndexStore?(schemaName: string, tableName: string, indexName: string): Promise<void>;
|
|
180
|
+
/**
|
|
181
|
+
* Delete all stores for a table (data, indexes, stats).
|
|
182
|
+
* Called when dropping a table.
|
|
145
183
|
* @param schemaName - The schema name
|
|
146
184
|
* @param tableName - The table name
|
|
147
185
|
*/
|
|
148
|
-
|
|
186
|
+
deleteTableStores?(schemaName: string, tableName: string): Promise<void>;
|
|
149
187
|
}
|
|
150
188
|
//# sourceMappingURL=kv-store.d.ts.map
|
|
@@ -1 +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;
|
|
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;IAC9B,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;CACf;AAED;;GAEG;AACH,MAAM,WAAW,OAAO;IACvB,GAAG,EAAE,UAAU,CAAC;IAChB,KAAK,EAAE,UAAU,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,MAAM,OAAO,GAChB;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,GAAG,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,UAAU,CAAA;CAAE,GACnD;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,GAAG,EAAE,UAAU,CAAA;CAAE,CAAC;AAEvC;;GAEG;AACH,MAAM,WAAW,UAAU;IAC1B,6BAA6B;IAC7B,GAAG,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,GAA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