@quereus/store 0.4.14 → 0.5.1

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 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
+ - `{prefix}.__stats__` - Unified stats store (row counts for all tables)
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
- | `buildDataKey` | Build key for row data |
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
- | `buildMetaKey` | Build key for metadata |
168
- | `buildTableScanBounds` | Build bounds for table scan |
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 { KEY_PREFIX, buildDataKey, buildIndexKey, buildMetaKey, buildTablePrefix, buildTableScanBounds, buildIndexScanBounds, buildMetaScanBounds, } from './key-builder.js';
7
+ export { STORE_SUFFIX, CATALOG_STORE_NAME, STATS_STORE_NAME, buildDataStoreName, buildIndexStoreName, buildStatsStoreName, buildStatsKey, 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,EACL,UAAU,EACV,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,GACpB,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"}
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,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,aAAa,EACb,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"}
@@ -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 { KEY_PREFIX, buildDataKey, buildIndexKey, buildMetaKey, buildTablePrefix, buildTableScanBounds, buildIndexScanBounds, buildMetaScanBounds, } from './key-builder.js';
8
+ // Key building - new API
9
+ export { STORE_SUFFIX, CATALOG_STORE_NAME, STATS_STORE_NAME, buildDataStoreName, buildIndexStoreName, buildStatsStoreName, buildStatsKey, 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,eAAe;AACf,OAAO,EACL,UAAU,EACV,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,GACpB,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
+ {"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,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,aAAa,EACb,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,113 @@
1
1
  /**
2
2
  * Key builder utilities for constructing storage keys.
3
3
  *
4
- * Key prefixes:
5
- * d: - Data rows
6
- * i: - Secondary indexes
7
- * m: - Metadata (DDL, stats)
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
- /** Key prefix bytes. */
12
- export declare const KEY_PREFIX: {
13
- readonly DATA: Uint8Array<ArrayBuffer>;
14
- readonly INDEX: Uint8Array<ArrayBuffer>;
15
- readonly META: Uint8Array<ArrayBuffer>;
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__";
27
+ /** Reserved stats store name. */
28
+ export declare const STATS_STORE_NAME = "__stats__";
17
29
  /**
18
- * Build a data row key.
19
- * Format: d:{schema}.{table}:{encoded_pk}
30
+ * Build the store name for a table's data.
31
+ * Format: {schema}.{table}
20
32
  */
21
- export declare function buildDataKey(schemaName: string, tableName: string, pkValues: SqlValue[], options?: EncodeOptions): Uint8Array;
33
+ export declare function buildDataStoreName(schemaName: string, tableName: string): string;
22
34
  /**
23
- * Build a secondary index key.
24
- * Format: i:{schema}.{table}.{indexName}:{encoded_index_cols}:{encoded_pk}
35
+ * Build the store name for a secondary index.
36
+ * Format: {schema}.{table}_idx_{indexName}
25
37
  */
26
- export declare function buildIndexKey(schemaName: string, tableName: string, indexName: string, indexValues: SqlValue[], pkValues: SqlValue[], options?: EncodeOptions): Uint8Array;
38
+ export declare function buildIndexStoreName(schemaName: string, tableName: string, indexName: string): string;
27
39
  /**
28
- * Build a metadata key.
29
- * Format: m:{type}:{schema}.{name}
40
+ * Build the store name for table statistics.
41
+ * @deprecated Stats are now stored in the unified __stats__ store. Use buildStatsKey instead.
42
+ * Format: {schema}.{table}_stats
43
+ */
44
+ export declare function buildStatsStoreName(schemaName: string, tableName: string): string;
45
+ /**
46
+ * Build a stats key for use in the unified __stats__ store.
47
+ * Format: {schema}.{table}
48
+ */
49
+ export declare function buildStatsKey(schemaName: string, tableName: string): Uint8Array;
50
+ /**
51
+ * Build a data row key (just the encoded primary key).
52
+ */
53
+ export declare function buildDataKey(pkValues: SqlValue[], options?: EncodeOptions): Uint8Array;
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.
30
59
  */
31
- export declare function buildMetaKey(metaType: 'ddl' | 'stats' | 'index', schemaName: string, objectName: string, subName?: string): Uint8Array;
60
+ export declare function buildIndexKey(indexValues: SqlValue[], pkValues: SqlValue[], options?: EncodeOptions): Uint8Array;
32
61
  /**
33
- * Build a table prefix for range scans.
34
- * Format: {prefix}:{schema}.{table}
62
+ * Build a catalog key for DDL storage.
63
+ * Format: {schema}.{table}
35
64
  */
36
- export declare function buildTablePrefix(prefix: 'd' | 'i' | 'm', schemaName: string, tableName: string): Uint8Array;
65
+ export declare function buildCatalogKey(schemaName: string, tableName: string): Uint8Array;
37
66
  /**
38
- * Build range bounds for scanning all rows of a table.
67
+ * Build range bounds for scanning all rows in a data store.
68
+ * Since keys are just encoded PKs, we scan the entire store.
39
69
  */
40
- export declare function buildTableScanBounds(schemaName: string, tableName: string): {
70
+ export declare function buildFullScanBounds(): {
41
71
  gte: Uint8Array;
42
72
  lt: Uint8Array;
43
73
  };
44
74
  /**
45
- * Build range bounds for scanning an index.
75
+ * Build range bounds for scanning an index with a prefix.
46
76
  */
47
- export declare function buildIndexScanBounds(schemaName: string, tableName: string, indexName: string, prefixValues?: SqlValue[], options?: EncodeOptions): {
77
+ export declare function buildIndexPrefixBounds(prefixValues: SqlValue[], options?: EncodeOptions): {
48
78
  gte: Uint8Array;
49
79
  lt: Uint8Array;
50
80
  };
51
81
  /**
52
- * Build range bounds for scanning all metadata of a type.
82
+ * Build range bounds for scanning catalog entries.
83
+ * Optionally filter by schema prefix.
53
84
  */
54
- export declare function buildMetaScanBounds(metaType: 'ddl' | 'stats' | 'index', schemaName?: string): {
85
+ export declare function buildCatalogScanBounds(schemaName?: string): {
86
+ gte: Uint8Array;
87
+ lt: Uint8Array;
88
+ };
89
+ /** @deprecated Use buildDataStoreName instead */
90
+ export declare const KEY_PREFIX: {
91
+ readonly DATA: Uint8Array<ArrayBuffer>;
92
+ readonly INDEX: Uint8Array<ArrayBuffer>;
93
+ readonly META: Uint8Array<ArrayBuffer>;
94
+ };
95
+ /** @deprecated Use buildDataKey instead */
96
+ export declare function buildTablePrefix(_prefix: 'd' | 'i' | 'm', schemaName: string, tableName: string): Uint8Array;
97
+ /** @deprecated Use buildFullScanBounds instead */
98
+ export declare function buildTableScanBounds(_schemaName: string, _tableName: string): {
99
+ gte: Uint8Array;
100
+ lt: Uint8Array;
101
+ };
102
+ /** @deprecated Use buildIndexPrefixBounds instead */
103
+ export declare function buildIndexScanBounds(_schemaName: string, _tableName: string, _indexName: string, prefixValues?: SqlValue[], options?: EncodeOptions): {
104
+ gte: Uint8Array;
105
+ lt: Uint8Array;
106
+ };
107
+ /** @deprecated Use buildCatalogKey instead */
108
+ export declare function buildMetaKey(_metaType: 'ddl' | 'stats' | 'index', schemaName: string, objectName: string, _subName?: string): Uint8Array;
109
+ /** @deprecated Use buildCatalogScanBounds instead */
110
+ export declare function buildMetaScanBounds(_metaType: 'ddl' | 'stats' | 'index', schemaName?: string): {
55
111
  gte: Uint8Array;
56
112
  lt: Uint8Array;
57
113
  };
@@ -1 +1 @@
1
- {"version":3,"file":"key-builder.d.ts","sourceRoot":"","sources":["../../../src/common/key-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAsB,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAIvE,wBAAwB;AACxB,eAAO,MAAM,UAAU;;;;CAIb,CAAC;AAKX;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,QAAQ,EAAE,EACpB,OAAO,CAAC,EAAE,aAAa,GACtB,UAAU,CAKZ;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,QAAQ,EAAE,EACvB,QAAQ,EAAE,QAAQ,EAAE,EACpB,OAAO,CAAC,EAAE,aAAa,GACtB,UAAU,CAMZ;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,KAAK,GAAG,OAAO,GAAG,OAAO,EACnC,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,MAAM,GACf,UAAU,CAMZ;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,EACvB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,GAChB,UAAU,CAEZ;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,GAChB;IAAE,GAAG,EAAE,UAAU,CAAC;IAAC,EAAE,EAAE,UAAU,CAAA;CAAE,CAMrC;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,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AAM,EAClB,UAAU,EAAE,MAAM,EAClB,YAAY,CAAC,EAAE,QAAQ,EAAE,EACzB,OAAO,CAAC,EAAE,aAAa,GACrB;IAAE,GAAG,EAAE,UAAU,CAAC;IAAC,EAAE,EAAE,UAAU,CAAA;CAAE,CAErC;AAED,8CAA8C;AAC9C,wBAAgB,YAAY,CAC3B,SAAS,EAAE,KAAK,GAAG,OAAO,GAAG,OAAO,EACpC,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,QAAQ,CAAC,EAAE,MAAM,GACf,UAAU,CAEZ;AAED,qDAAqD;AACrD,wBAAgB,mBAAmB,CAClC,SAAS,EAAE,KAAK,GAAG,OAAO,GAAG,OAAO,EACpC,UAAU,CAAC,EAAE,MAAM,GACjB;IAAE,GAAG,EAAE,UAAU,CAAC;IAAC,EAAE,EAAE,UAAU,CAAA;CAAE,CAErC"}
@@ -1,98 +1,122 @@
1
1
  /**
2
2
  * Key builder utilities for constructing storage keys.
3
3
  *
4
- * Key prefixes:
5
- * d: - Data rows
6
- * i: - Secondary indexes
7
- * m: - Metadata (DDL, stats)
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
- /** Key prefix bytes. */
12
- export const KEY_PREFIX = {
13
- DATA: encoder.encode('d:'),
14
- INDEX: encoder.encode('i:'),
15
- META: encoder.encode('m:'),
18
+ /**
19
+ * Store name suffixes for different data types.
20
+ */
21
+ export const STORE_SUFFIX = {
22
+ INDEX: '_idx_',
23
+ STATS: '_stats',
16
24
  };
17
- /** Separator between key components. */
18
- const SEPARATOR = encoder.encode(':');
25
+ /** Reserved catalog store name. */
26
+ export const CATALOG_STORE_NAME = '__catalog__';
27
+ /** Reserved stats store name. */
28
+ export const STATS_STORE_NAME = '__stats__';
19
29
  /**
20
- * Build a data row key.
21
- * Format: d:{schema}.{table}:{encoded_pk}
30
+ * Build the store name for a table's data.
31
+ * Format: {schema}.{table}
22
32
  */
23
- export function buildDataKey(schemaName, tableName, pkValues, options) {
24
- const tablePrefix = buildTablePrefix('d', schemaName, tableName);
25
- const pkEncoded = encodeCompositeKey(pkValues, options);
26
- return concatBytes(tablePrefix, SEPARATOR, pkEncoded);
33
+ export function buildDataStoreName(schemaName, tableName) {
34
+ return `${schemaName}.${tableName}`.toLowerCase();
27
35
  }
28
36
  /**
29
- * Build a secondary index key.
30
- * Format: i:{schema}.{table}.{indexName}:{encoded_index_cols}:{encoded_pk}
37
+ * Build the store name for a secondary index.
38
+ * Format: {schema}.{table}_idx_{indexName}
31
39
  */
32
- export function buildIndexKey(schemaName, tableName, indexName, indexValues, pkValues, options) {
33
- const prefix = encoder.encode(`i:${schemaName}.${tableName}.${indexName}:`);
34
- const indexEncoded = encodeCompositeKey(indexValues, options);
35
- const pkEncoded = encodeCompositeKey(pkValues, options);
36
- return concatBytes(prefix, indexEncoded, SEPARATOR, pkEncoded);
40
+ export function buildIndexStoreName(schemaName, tableName, indexName) {
41
+ return `${schemaName}.${tableName}_idx_${indexName}`.toLowerCase();
37
42
  }
38
43
  /**
39
- * Build a metadata key.
40
- * Format: m:{type}:{schema}.{name}
44
+ * Build the store name for table statistics.
45
+ * @deprecated Stats are now stored in the unified __stats__ store. Use buildStatsKey instead.
46
+ * Format: {schema}.{table}_stats
41
47
  */
42
- export function buildMetaKey(metaType, schemaName, objectName, subName) {
43
- let key = `m:${metaType}:${schemaName}.${objectName}`;
44
- if (subName) {
45
- key += `#${subName}`;
46
- }
47
- return encoder.encode(key);
48
+ export function buildStatsStoreName(schemaName, tableName) {
49
+ return `${schemaName}.${tableName}_stats`.toLowerCase();
50
+ }
51
+ /**
52
+ * Build a stats key for use in the unified __stats__ store.
53
+ * Format: {schema}.{table}
54
+ */
55
+ export function buildStatsKey(schemaName, tableName) {
56
+ return encoder.encode(`${schemaName}.${tableName}`.toLowerCase());
48
57
  }
49
58
  /**
50
- * Build a table prefix for range scans.
51
- * Format: {prefix}:{schema}.{table}
59
+ * Build a data row key (just the encoded primary key).
52
60
  */
53
- export function buildTablePrefix(prefix, schemaName, tableName) {
54
- return encoder.encode(`${prefix}:${schemaName}.${tableName}`);
61
+ export function buildDataKey(pkValues, options) {
62
+ return encodeCompositeKey(pkValues, options);
55
63
  }
56
64
  /**
57
- * Build range bounds for scanning all rows of a table.
65
+ * Build a secondary index key.
66
+ * Format: {encoded_index_cols}{encoded_pk}
67
+ *
68
+ * The index columns come first for range scans, followed by PK for uniqueness.
58
69
  */
59
- export function buildTableScanBounds(schemaName, tableName) {
60
- const prefix = `d:${schemaName}.${tableName}:`;
70
+ export function buildIndexKey(indexValues, pkValues, options) {
71
+ const indexEncoded = encodeCompositeKey(indexValues, options);
72
+ const pkEncoded = encodeCompositeKey(pkValues, options);
73
+ return concatBytes(indexEncoded, pkEncoded);
74
+ }
75
+ /**
76
+ * Build a catalog key for DDL storage.
77
+ * Format: {schema}.{table}
78
+ */
79
+ export function buildCatalogKey(schemaName, tableName) {
80
+ return encoder.encode(`${schemaName}.${tableName}`.toLowerCase());
81
+ }
82
+ /**
83
+ * Build range bounds for scanning all rows in a data store.
84
+ * Since keys are just encoded PKs, we scan the entire store.
85
+ */
86
+ export function buildFullScanBounds() {
61
87
  return {
62
- gte: encoder.encode(prefix),
63
- lt: incrementLastByte(encoder.encode(prefix)),
88
+ gte: new Uint8Array(0),
89
+ lt: new Uint8Array([0xff]), // All valid encoded keys are < 0xff
64
90
  };
65
91
  }
66
92
  /**
67
- * Build range bounds for scanning an index.
93
+ * Build range bounds for scanning an index with a prefix.
68
94
  */
69
- export function buildIndexScanBounds(schemaName, tableName, indexName, prefixValues, options) {
70
- const prefix = `i:${schemaName}.${tableName}.${indexName}:`;
71
- const prefixBytes = encoder.encode(prefix);
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
- };
95
+ export function buildIndexPrefixBounds(prefixValues, options) {
96
+ if (prefixValues.length === 0) {
97
+ return buildFullScanBounds();
79
98
  }
99
+ const prefixEncoded = encodeCompositeKey(prefixValues, options);
80
100
  return {
81
- gte: prefixBytes,
82
- lt: incrementLastByte(prefixBytes),
101
+ gte: prefixEncoded,
102
+ lt: incrementLastByte(prefixEncoded),
83
103
  };
84
104
  }
85
105
  /**
86
- * Build range bounds for scanning all metadata of a type.
106
+ * Build range bounds for scanning catalog entries.
107
+ * Optionally filter by schema prefix.
87
108
  */
88
- export function buildMetaScanBounds(metaType, schemaName) {
89
- let prefix = `m:${metaType}:`;
109
+ export function buildCatalogScanBounds(schemaName) {
90
110
  if (schemaName) {
91
- prefix += `${schemaName}.`;
111
+ const prefix = `${schemaName}.`.toLowerCase();
112
+ return {
113
+ gte: encoder.encode(prefix),
114
+ lt: incrementLastByte(encoder.encode(prefix)),
115
+ };
92
116
  }
93
117
  return {
94
- gte: encoder.encode(prefix),
95
- lt: incrementLastByte(encoder.encode(prefix)),
118
+ gte: new Uint8Array(0),
119
+ lt: new Uint8Array([0xff]),
96
120
  };
97
121
  }
98
122
  /**
@@ -127,4 +151,34 @@ function concatBytes(...arrays) {
127
151
  }
128
152
  return result;
129
153
  }
154
+ // ============================================================================
155
+ // Legacy exports for backwards compatibility during migration
156
+ // These will be removed after all consumers are updated.
157
+ // ============================================================================
158
+ /** @deprecated Use buildDataStoreName instead */
159
+ export const KEY_PREFIX = {
160
+ DATA: encoder.encode('d:'),
161
+ INDEX: encoder.encode('i:'),
162
+ META: encoder.encode('m:'),
163
+ };
164
+ /** @deprecated Use buildDataKey instead */
165
+ export function buildTablePrefix(_prefix, schemaName, tableName) {
166
+ return encoder.encode(`${schemaName}.${tableName}`.toLowerCase());
167
+ }
168
+ /** @deprecated Use buildFullScanBounds instead */
169
+ export function buildTableScanBounds(_schemaName, _tableName) {
170
+ return buildFullScanBounds();
171
+ }
172
+ /** @deprecated Use buildIndexPrefixBounds instead */
173
+ export function buildIndexScanBounds(_schemaName, _tableName, _indexName, prefixValues, options) {
174
+ return buildIndexPrefixBounds(prefixValues || [], options);
175
+ }
176
+ /** @deprecated Use buildCatalogKey instead */
177
+ export function buildMetaKey(_metaType, schemaName, objectName, _subName) {
178
+ return buildCatalogKey(schemaName, objectName);
179
+ }
180
+ /** @deprecated Use buildCatalogScanBounds instead */
181
+ export function buildMetaScanBounds(_metaType, schemaName) {
182
+ return buildCatalogScanBounds(schemaName);
183
+ }
130
184
  //# sourceMappingURL=key-builder.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"key-builder.js","sourceRoot":"","sources":["../../../src/common/key-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,kBAAkB,EAAsB,MAAM,eAAe,CAAC;AAEvE,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAElC,wBAAwB;AACxB,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC;IAC1B,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC;IAC3B,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC;CAClB,CAAC;AAEX,wCAAwC;AACxC,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAEtC;;;GAGG;AACH,MAAM,UAAU,YAAY,CAC1B,UAAkB,EAClB,SAAiB,EACjB,QAAoB,EACpB,OAAuB;IAEvB,MAAM,WAAW,GAAG,gBAAgB,CA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C;IACD,OAAO,MAAM,CAAC;AACf,CAAC;AAED,+EAA+E;AAC/E,8DAA8D;AAC9D,yDAAyD;AACzD,+EAA+E;AAE/E,iDAAiD;AACjD,MAAM,CAAC,MAAM,UAAU,GAAG;IACzB,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC;IAC1B,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC;IAC3B,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC;CACjB,CAAC;AAEX,2CAA2C;AAC3C,MAAM,UAAU,gBAAgB,CAC/B,OAAwB,EACxB,UAAkB,EAClB,SAAiB;IAEjB,OAAO,OAAO,CAAC,MAAM,CAAC,GAAG,UAAU,IAAI,SAAS,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;AACnE,CAAC;AAED,kDAAkD;AAClD,MAAM,UAAU,oBAAoB,CACnC,WAAmB,EACnB,UAAkB;IAElB,OAAO,mBAAmB,EAAE,CAAC;AAC9B,CAAC;AAED,qDAAqD;AACrD,MAAM,UAAU,oBAAoB,CACnC,WAAmB,EACnB,UAAkB,EAClB,UAAkB,EAClB,YAAyB,EACzB,OAAuB;IAEvB,OAAO,sBAAsB,CAAC,YAAY,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;AAC5D,CAAC;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,78 @@ 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
+ * {prefix}.__stats__ - Unified stats store (row counts for all tables)
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 the unified KVStore for table statistics.
144
+ * All table statistics are stored in a single __stats__ store, keyed by {schema}.{table}.
145
+ * Note: schemaName and tableName parameters are ignored (kept for API compatibility).
146
+ * @param schemaName - Unused (kept for API compatibility)
147
+ * @param tableName - Unused (kept for API compatibility)
148
+ * @returns The unified __stats__ KVStore instance
149
+ */
150
+ getStatsStore(schemaName: string, tableName: string): Promise<KVStore>;
126
151
  /**
127
152
  * 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.
153
+ * Store name: __catalog__
129
154
  * @returns The KVStore instance for catalog data
130
155
  */
131
156
  getCatalogStore(): Promise<KVStore>;
132
157
  /**
133
- * Close a specific store.
158
+ * Close a specific table's data store.
134
159
  * @param schemaName - The schema name
135
160
  * @param tableName - The table name
136
161
  */
137
162
  closeStore(schemaName: string, tableName: string): Promise<void>;
163
+ /**
164
+ * Close a specific index store.
165
+ * @param schemaName - The schema name
166
+ * @param tableName - The table name
167
+ * @param indexName - The index name
168
+ */
169
+ closeIndexStore(schemaName: string, tableName: string, indexName: string): Promise<void>;
138
170
  /**
139
171
  * Close all stores managed by this provider.
140
172
  */
141
173
  closeAll(): Promise<void>;
142
174
  /**
143
- * Optional: Called when a store is first accessed to perform any setup.
144
- * @param store - The store that was just opened
175
+ * Delete an index store entirely (when dropping an index).
176
+ * @param schemaName - The schema name
177
+ * @param tableName - The table name
178
+ * @param indexName - The index name
179
+ */
180
+ deleteIndexStore?(schemaName: string, tableName: string, indexName: string): Promise<void>;
181
+ /**
182
+ * Delete all stores for a table (data, indexes, stats).
183
+ * Called when dropping a table.
145
184
  * @param schemaName - The schema name
146
185
  * @param tableName - The table name
147
186
  */
148
- onStoreOpened?(store: KVStore, schemaName: string, tableName: string): void;
187
+ deleteTableStores?(schemaName: string, tableName: string): Promise<void>;
149
188
  }
150
189
  //# sourceMappingURL=kv-store.d.ts.map