@quereus/store 4.13.1 → 4.15.2

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.
Files changed (51) hide show
  1. package/README.md +761 -702
  2. package/dist/src/common/cost-profile.d.ts +13 -0
  3. package/dist/src/common/cost-profile.d.ts.map +1 -1
  4. package/dist/src/common/cost-profile.js.map +1 -1
  5. package/dist/src/common/events.d.ts +18 -28
  6. package/dist/src/common/events.d.ts.map +1 -1
  7. package/dist/src/common/events.js.map +1 -1
  8. package/dist/src/common/index.d.ts +1 -0
  9. package/dist/src/common/index.d.ts.map +1 -1
  10. package/dist/src/common/index.js +5 -0
  11. package/dist/src/common/index.js.map +1 -1
  12. package/dist/src/common/memory-store.d.ts +9 -0
  13. package/dist/src/common/memory-store.d.ts.map +1 -1
  14. package/dist/src/common/memory-store.js +11 -0
  15. package/dist/src/common/memory-store.js.map +1 -1
  16. package/dist/src/common/store-module-access-plan.js +15 -7
  17. package/dist/src/common/store-module-access-plan.js.map +1 -1
  18. package/dist/src/common/store-module-alter-column.d.ts.map +1 -1
  19. package/dist/src/common/store-module-alter-column.js +77 -62
  20. package/dist/src/common/store-module-alter-column.js.map +1 -1
  21. package/dist/src/common/store-module-alter.d.ts.map +1 -1
  22. package/dist/src/common/store-module-alter.js +2 -3
  23. package/dist/src/common/store-module-alter.js.map +1 -1
  24. package/dist/src/common/store-module-schema-sync.d.ts.map +1 -1
  25. package/dist/src/common/store-module-schema-sync.js +6 -0
  26. package/dist/src/common/store-module-schema-sync.js.map +1 -1
  27. package/dist/src/common/store-module.d.ts +17 -0
  28. package/dist/src/common/store-module.d.ts.map +1 -1
  29. package/dist/src/common/store-module.js +26 -2
  30. package/dist/src/common/store-module.js.map +1 -1
  31. package/dist/src/common/store-table.d.ts +17 -7
  32. package/dist/src/common/store-table.d.ts.map +1 -1
  33. package/dist/src/common/store-table.js +25 -12
  34. package/dist/src/common/store-table.js.map +1 -1
  35. package/dist/src/testing/index.d.ts +12 -0
  36. package/dist/src/testing/index.d.ts.map +1 -1
  37. package/dist/src/testing/index.js +12 -0
  38. package/dist/src/testing/index.js.map +1 -1
  39. package/dist/src/testing/kv-counting-store.d.ts +96 -0
  40. package/dist/src/testing/kv-counting-store.d.ts.map +1 -0
  41. package/dist/src/testing/kv-counting-store.js +226 -0
  42. package/dist/src/testing/kv-counting-store.js.map +1 -0
  43. package/dist/src/testing/kv-delegating-store.d.ts +28 -0
  44. package/dist/src/testing/kv-delegating-store.d.ts.map +1 -0
  45. package/dist/src/testing/kv-delegating-store.js +47 -0
  46. package/dist/src/testing/kv-delegating-store.js.map +1 -0
  47. package/dist/src/testing/memory-provider.d.ts +51 -0
  48. package/dist/src/testing/memory-provider.d.ts.map +1 -0
  49. package/dist/src/testing/memory-provider.js +124 -0
  50. package/dist/src/testing/memory-provider.js.map +1 -0
  51. package/package.json +5 -5
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Shared in-memory {@link KVStoreProvider} test double — test-support, ships in
3
+ * `@quereus/store/testing`.
4
+ *
5
+ * Nearly every spec in this package's `test/` directory (and this package's benchmark
6
+ * suite) opens with its own private copy of an all-`InMemoryKVStore` provider. This is the
7
+ * one shared implementation, built to the same conventions as its sibling
8
+ * {@link createCountingProvider}:
9
+ *
10
+ * - Store names come from {@link buildDataStoreName} / {@link buildIndexStoreName} and the
11
+ * reserved {@link CATALOG_STORE_NAME} / {@link STATS_STORE_NAME} constants — never
12
+ * hand-composed template strings, which drop the builders' lowercasing.
13
+ * - {@link KVStoreProvider.getStatsStore} returns ONE unified `__stats__` store for every
14
+ * table, as the interface specifies (its schema/table arguments are documented as
15
+ * ignored) — not the per-table `schema.table.__stats__` spelling most local copies use.
16
+ * - `options.costProfile` is spread in only when present, so a provider built with no
17
+ * options (or `{}`) has no `costProfile` property at all, matching what a genuine
18
+ * pre-profile third-party provider looks like.
19
+ *
20
+ * Unlike {@link createCountingProvider} — which deliberately omits `deleteIndexStore` /
21
+ * `deleteTableStores` — this provider implements both, and they ERASE rather than merely
22
+ * drop the map entry: see {@link erase} for why a live handle still needs its bytes cleared.
23
+ * `renameTableStores` is deliberately NOT implemented; `StoreModule` falls back to a generic
24
+ * copy for a provider without it (`test/rename-store-copy-fallback.spec.ts`), and nothing
25
+ * that needs this provider today renames.
26
+ *
27
+ * Neither is `beginAtomicBatch`, and that one is not a gap to fill later: separate
28
+ * `InMemoryKVStore`s share no commit domain, so there is nothing for a cross-store batch to
29
+ * make atomic. The consequence is worth knowing before reading numbers off this provider —
30
+ * `StoreModuleBase` sets `atomicProvider` from that method's presence and commits per store
31
+ * here, where a LevelDB-family provider commits in one physical write. A benchmark putting
32
+ * this provider next to LevelDB is comparing two commit PATHS, not one path over two
33
+ * backends.
34
+ */
35
+ import { buildDataStoreName, buildIndexStoreName, CATALOG_STORE_NAME, STATS_STORE_NAME } from '../common/key-builder.js';
36
+ import { InMemoryKVStore } from '../common/memory-store.js';
37
+ /**
38
+ * Build an all-`InMemoryKVStore` {@link KVStoreProvider}. Every distinct built store name
39
+ * gets its own `InMemoryKVStore`, created lazily on first access.
40
+ */
41
+ export function createInMemoryProvider(options) {
42
+ const stores = new Map();
43
+ // NOTE: a cached store the CALLER closed directly is handed back closed, so the next op
44
+ // on it throws `InMemoryKVStore is closed` rather than re-opening — unlike a real backend,
45
+ // which re-opens the name with its bytes intact. No StoreModule path does that today
46
+ // (`StoreTableBase.releaseIndexStore` is the only close, and its caller always deletes the
47
+ // store right after, which drops the entry). If a spec or benchmark ever closes a handle
48
+ // and keeps using the name, treat a closed cached store as absent here.
49
+ const getOrCreate = (key) => {
50
+ let store = stores.get(key);
51
+ if (!store) {
52
+ store = new InMemoryKVStore();
53
+ stores.set(key, store);
54
+ }
55
+ return store;
56
+ };
57
+ /**
58
+ * Erase the store named `key`: a caller re-opening this name afterwards must find it
59
+ * empty, and a caller still holding a LIVE handle to it must see the erase too (the
60
+ * reclaim battery's "handle the caller already closed" case is the other order — see
61
+ * below). Two cases, both ending in the map entry being dropped so the name re-opens
62
+ * fresh:
63
+ *
64
+ * - Live store: `clear()` it first, so an existing handle observes the erase, THEN
65
+ * drop the map entry.
66
+ * - Already-closed store (the caller closed its handle before asking for the delete —
67
+ * exactly what `StoreModuleIndex.tearDownIndexStore` does): `close()` already
68
+ * cleared its entries and marked it closed, so `clear()` would just throw
69
+ * (`checkOpen()`) for no benefit. Skip straight to dropping the map entry.
70
+ *
71
+ * A store that was never created (key absent from the map) is a no-op, matching the
72
+ * interface's speculative-delete contract.
73
+ *
74
+ * NOTE: the live handle is cleared, not closed, so a caller still holding it can go on
75
+ * PUTting into a store the provider has forgotten — those writes land nowhere anyone can
76
+ * read, silently. A real backend's handle is dead after its store is dropped. Closing here
77
+ * instead would trade the silence for a throw, but would also break the contract line
78
+ * above (a live handle must read back EMPTY, not throw); revisit if a spec is ever found
79
+ * writing through a post-delete handle.
80
+ */
81
+ const erase = async (key) => {
82
+ const store = stores.get(key);
83
+ if (!store)
84
+ return;
85
+ if (!store.isClosed) {
86
+ store.clear();
87
+ }
88
+ stores.delete(key);
89
+ };
90
+ return {
91
+ ...(options?.costProfile ? { costProfile: options.costProfile } : {}),
92
+ async getStore(schemaName, tableName) {
93
+ return getOrCreate(buildDataStoreName(schemaName, tableName));
94
+ },
95
+ async getIndexStore(schemaName, tableName, indexName) {
96
+ return getOrCreate(buildIndexStoreName(schemaName, tableName, indexName));
97
+ },
98
+ async getStatsStore() {
99
+ return getOrCreate(STATS_STORE_NAME);
100
+ },
101
+ async getCatalogStore() {
102
+ return getOrCreate(CATALOG_STORE_NAME);
103
+ },
104
+ async closeStore() { },
105
+ async closeIndexStore() { },
106
+ async closeAll() {
107
+ for (const store of stores.values())
108
+ await store.close();
109
+ stores.clear();
110
+ },
111
+ async deleteIndexStore(schemaName, tableName, indexName) {
112
+ await erase(buildIndexStoreName(schemaName, tableName, indexName));
113
+ },
114
+ async deleteTableStores(schemaName, tableName, indexNames) {
115
+ await erase(buildDataStoreName(schemaName, tableName));
116
+ for (const indexName of indexNames) {
117
+ await erase(buildIndexStoreName(schemaName, tableName, indexName));
118
+ }
119
+ // The unified __stats__ store is deliberately untouched — a table's row count is
120
+ // one ENTRY there, and removing it is the caller's business, not a store deletion.
121
+ },
122
+ };
123
+ }
124
+ //# sourceMappingURL=memory-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-provider.js","sourceRoot":"","sources":["../../../src/testing/memory-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAIH,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACzH,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAY5D;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAAiC;IACvE,MAAM,MAAM,GAAG,IAAI,GAAG,EAA2B,CAAC;IAElD,wFAAwF;IACxF,2FAA2F;IAC3F,qFAAqF;IACrF,2FAA2F;IAC3F,yFAAyF;IACzF,wEAAwE;IACxE,MAAM,WAAW,GAAG,CAAC,GAAW,EAAmB,EAAE;QACpD,IAAI,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC5B,IAAI,CAAC,KAAK,EAAE,CAAC;YACZ,KAAK,GAAG,IAAI,eAAe,EAAE,CAAC;YAC9B,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACxB,CAAC;QACD,OAAO,KAAK,CAAC;IACd,CAAC,CAAC;IAEF;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,MAAM,KAAK,GAAG,KAAK,EAAE,GAAW,EAAiB,EAAE;QAClD,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC9B,IAAI,CAAC,KAAK;YAAE,OAAO;QACnB,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;YACrB,KAAK,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vD,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;gBACpC,MAAM,KAAK,CAAC,mBAAmB,CAAC,UAAU,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC;YACpE,CAAC;YACD,iFAAiF;YACjF,mFAAmF;QACpF,CAAC;KACD,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quereus/store",
3
- "version": "4.13.1",
3
+ "version": "4.15.2",
4
4
  "type": "module",
5
5
  "description": "Abstract key-value storage module for Quereus",
6
6
  "keywords": [
@@ -52,12 +52,12 @@
52
52
  "test:single": "cd ../.. && node --import ./packages/quereus-store/register.mjs node_modules/mocha/bin/mocha.js --bail"
53
53
  },
54
54
  "peerDependencies": {
55
- "@quereus/isolation": "^4.13.1",
56
- "@quereus/quereus": "^4.13.1"
55
+ "@quereus/isolation": "^4.15.2",
56
+ "@quereus/quereus": "^4.15.2"
57
57
  },
58
58
  "dependencies": {
59
- "@quereus/isolation": "^4.13.1",
60
- "@quereus/quereus": "^4.13.1"
59
+ "@quereus/isolation": "^4.15.2",
60
+ "@quereus/quereus": "^4.15.2"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@types/mocha": "^10.0.10",