@quereus/store 4.5.0 → 4.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/README.md +34 -6
  2. package/dist/src/common/encoding.d.ts +4 -3
  3. package/dist/src/common/encoding.d.ts.map +1 -1
  4. package/dist/src/common/encoding.js +17 -13
  5. package/dist/src/common/encoding.js.map +1 -1
  6. package/dist/src/common/events.d.ts +31 -25
  7. package/dist/src/common/events.d.ts.map +1 -1
  8. package/dist/src/common/events.js +38 -39
  9. package/dist/src/common/events.js.map +1 -1
  10. package/dist/src/common/implicit-unique-index.d.ts +80 -0
  11. package/dist/src/common/implicit-unique-index.d.ts.map +1 -0
  12. package/dist/src/common/implicit-unique-index.js +148 -0
  13. package/dist/src/common/implicit-unique-index.js.map +1 -0
  14. package/dist/src/common/index.d.ts +7 -3
  15. package/dist/src/common/index.d.ts.map +1 -1
  16. package/dist/src/common/index.js +5 -2
  17. package/dist/src/common/index.js.map +1 -1
  18. package/dist/src/common/json-key.d.ts +30 -2
  19. package/dist/src/common/json-key.d.ts.map +1 -1
  20. package/dist/src/common/json-key.js +49 -2
  21. package/dist/src/common/json-key.js.map +1 -1
  22. package/dist/src/common/key-builder.d.ts +40 -20
  23. package/dist/src/common/key-builder.d.ts.map +1 -1
  24. package/dist/src/common/key-builder.js +31 -23
  25. package/dist/src/common/key-builder.js.map +1 -1
  26. package/dist/src/common/kv-store.d.ts +10 -0
  27. package/dist/src/common/kv-store.d.ts.map +1 -1
  28. package/dist/src/common/pk-key-resolution.d.ts +348 -0
  29. package/dist/src/common/pk-key-resolution.d.ts.map +1 -0
  30. package/dist/src/common/pk-key-resolution.js +481 -0
  31. package/dist/src/common/pk-key-resolution.js.map +1 -0
  32. package/dist/src/common/store-module-access-plan.d.ts +32 -0
  33. package/dist/src/common/store-module-access-plan.d.ts.map +1 -0
  34. package/dist/src/common/store-module-access-plan.js +428 -0
  35. package/dist/src/common/store-module-access-plan.js.map +1 -0
  36. package/dist/src/common/store-module-alter-column.d.ts +23 -0
  37. package/dist/src/common/store-module-alter-column.d.ts.map +1 -0
  38. package/dist/src/common/store-module-alter-column.js +389 -0
  39. package/dist/src/common/store-module-alter-column.js.map +1 -0
  40. package/dist/src/common/store-module-alter.d.ts +55 -0
  41. package/dist/src/common/store-module-alter.d.ts.map +1 -0
  42. package/dist/src/common/store-module-alter.js +504 -0
  43. package/dist/src/common/store-module-alter.js.map +1 -0
  44. package/dist/src/common/store-module-base.d.ts +268 -0
  45. package/dist/src/common/store-module-base.d.ts.map +1 -0
  46. package/dist/src/common/store-module-base.js +362 -0
  47. package/dist/src/common/store-module-base.js.map +1 -0
  48. package/dist/src/common/store-module-catalog.d.ts +269 -0
  49. package/dist/src/common/store-module-catalog.d.ts.map +1 -0
  50. package/dist/src/common/store-module-catalog.js +462 -0
  51. package/dist/src/common/store-module-catalog.js.map +1 -0
  52. package/dist/src/common/store-module-index-build.d.ts +88 -0
  53. package/dist/src/common/store-module-index-build.d.ts.map +1 -0
  54. package/dist/src/common/store-module-index-build.js +280 -0
  55. package/dist/src/common/store-module-index-build.js.map +1 -0
  56. package/dist/src/common/store-module-index.d.ts +116 -0
  57. package/dist/src/common/store-module-index.d.ts.map +1 -0
  58. package/dist/src/common/store-module-index.js +373 -0
  59. package/dist/src/common/store-module-index.js.map +1 -0
  60. package/dist/src/common/store-module-rename.d.ts +49 -0
  61. package/dist/src/common/store-module-rename.d.ts.map +1 -0
  62. package/dist/src/common/store-module-rename.js +268 -0
  63. package/dist/src/common/store-module-rename.js.map +1 -0
  64. package/dist/src/common/store-module-schema-rewrite.d.ts +57 -0
  65. package/dist/src/common/store-module-schema-rewrite.d.ts.map +1 -0
  66. package/dist/src/common/store-module-schema-rewrite.js +140 -0
  67. package/dist/src/common/store-module-schema-rewrite.js.map +1 -0
  68. package/dist/src/common/store-module-schema-sync.d.ts +232 -0
  69. package/dist/src/common/store-module-schema-sync.d.ts.map +1 -0
  70. package/dist/src/common/store-module-schema-sync.js +529 -0
  71. package/dist/src/common/store-module-schema-sync.js.map +1 -0
  72. package/dist/src/common/store-module.d.ts +43 -909
  73. package/dist/src/common/store-module.d.ts.map +1 -1
  74. package/dist/src/common/store-module.js +184 -3276
  75. package/dist/src/common/store-module.js.map +1 -1
  76. package/dist/src/common/store-table-base.d.ts +539 -0
  77. package/dist/src/common/store-table-base.d.ts.map +1 -0
  78. package/dist/src/common/store-table-base.js +900 -0
  79. package/dist/src/common/store-table-base.js.map +1 -0
  80. package/dist/src/common/store-table-constraints.d.ts +237 -0
  81. package/dist/src/common/store-table-constraints.d.ts.map +1 -0
  82. package/dist/src/common/store-table-constraints.js +624 -0
  83. package/dist/src/common/store-table-constraints.js.map +1 -0
  84. package/dist/src/common/store-table-scan.d.ts +452 -0
  85. package/dist/src/common/store-table-scan.d.ts.map +1 -0
  86. package/dist/src/common/store-table-scan.js +901 -0
  87. package/dist/src/common/store-table-scan.js.map +1 -0
  88. package/dist/src/common/store-table.d.ts +71 -1144
  89. package/dist/src/common/store-table.d.ts.map +1 -1
  90. package/dist/src/common/store-table.js +168 -2385
  91. package/dist/src/common/store-table.js.map +1 -1
  92. package/dist/src/testing/index.d.ts +12 -0
  93. package/dist/src/testing/index.d.ts.map +1 -0
  94. package/dist/src/testing/index.js +12 -0
  95. package/dist/src/testing/index.js.map +1 -0
  96. package/dist/src/testing/kv-assert.d.ts +19 -0
  97. package/dist/src/testing/kv-assert.d.ts.map +1 -0
  98. package/dist/src/testing/kv-assert.js +25 -0
  99. package/dist/src/testing/kv-assert.js.map +1 -0
  100. package/dist/src/testing/kv-conformance.d.ts.map +1 -1
  101. package/dist/src/testing/kv-conformance.js +1 -15
  102. package/dist/src/testing/kv-conformance.js.map +1 -1
  103. package/dist/src/testing/kv-provider-conformance.d.ts +54 -0
  104. package/dist/src/testing/kv-provider-conformance.d.ts.map +1 -0
  105. package/dist/src/testing/kv-provider-conformance.js +183 -0
  106. package/dist/src/testing/kv-provider-conformance.js.map +1 -0
  107. package/package.json +8 -8
package/README.md CHANGED
@@ -65,8 +65,10 @@ yield their rows once, and a composite index serves the cross-product of per-col
65
65
  (`a in (1,2) and b in (10,20)` is four seeks). Very large lists (over 1000 seek keys) and
66
66
  lists on semantically-ordered column types (TIMESPAN, JSON) fall back to the scan path —
67
67
  still correct, just not accelerated. `IN` on the primary key currently scans (see backlog
68
- `feat-store-pk-in-list-multiseek`). Index choice among several usable indexes is
69
- first-match, not cheapest — see backlog `bug-store-index-choice-ignores-cost`.
68
+ `feat-store-pk-in-list-multiseek`). When several secondary indexes can serve the same
69
+ predicate, the lowest-cost seek wins (equal costs keep the first-declared index), so
70
+ declaration order no longer decides whether a query does one seek or hundreds. The primary-key
71
+ arms still take precedence over any secondary index whenever they apply.
70
72
 
71
73
  The same multi-seek path also serves an `IN` whose values only exist once the query runs
72
74
  — `where v in (select … )`, which the engine may materialize into a set and hand down as
@@ -78,7 +80,7 @@ time such a set describes itself only by a ceiling (`PredicateConstraint.runtime
78
80
  which is what the cost and cap arithmetic judges. The engine also re-checks every row the
79
81
  seek returns, so an over-fetching window costs only time.
80
82
 
81
- **Catalog DDL is re-persisted on catalog-only mutations.** `ALTER … SET TAGS` (and the programmatic `setTableTags` / `setColumnTags` / `setConstraintTags` / `setViewTags` / `setMaterializedViewTags`), plus `CREATE`/`DROP VIEW` and `CREATE`/`DROP MATERIALIZED VIEW`, never reach `module.alterTable`/`module.destroy`. The module subscribes to the engine's schema-change events (`table_modified`, the `view_*` events, and the `materialized_view_*` events) and writes the matching `__catalog__` entry when its `generate*DDL` output changes — table / column / constraint / **index** / **view** / **materialized-view** tags, and view/MV lifecycle, all survive close → reopen. A table's bundle is its `CREATE TABLE` DDL, one `CREATE [UNIQUE] INDEX` line per secondary index, and one trailing `alter index … set tags (…)` line per *exposed implicit index* carrying user tags (an exposed implicit index is never materialized in the store's *engine-facing* schema — only in its internal enforcement schema, see the implicit-index note below — so its `UniqueConstraintSchema.exposedIndexTags` has no `CREATE INDEX` line to ride; the alter line re-applies silently on import). These async writes are serialized and drained by `closeAll()` (or the `whenCatalogPersisted()` barrier) before the provider closes. On reopen, `rehydrateCatalog` classifies entries by key prefix and imports them in phases — tables → views → materialized views, all through the engine's `importCatalog` (MVs re-materialize silently via the shared create core, dependency-ordered for MV-over-MV by fixpoint retry). See [`docs/schema.md`](../../docs/schema.md#view-and-materialized-view-persistence) for the full design.
83
+ **Catalog DDL is re-persisted on catalog-only mutations.** `ALTER … SET TAGS` (and the programmatic `setTableTags` / `setColumnTags` / `setConstraintTags` / `setViewTags` / `setMaterializedViewTags`), plus `CREATE`/`DROP VIEW` and `CREATE`/`DROP MATERIALIZED VIEW`, never reach `module.alterTable`/`module.destroy`. The module subscribes to the engine's schema-change events (`table_modified`, the `view_*` events, and the `materialized_view_*` events) and writes the matching `__catalog__` entry when its `generate*DDL` output changes — table / column / constraint / **index** / **view** / **materialized-view** tags, and view/MV lifecycle, all survive close → reopen. A table's bundle is its `CREATE TABLE` DDL, one `CREATE [UNIQUE] INDEX` line per secondary index, and one trailing `alter index … set tags (…)` line per *exposed implicit index* carrying user tags (an exposed implicit index is never materialized in the store's *engine-facing* schema — only in its internal enforcement schema, see the implicit-index note below — so its `UniqueConstraintSchema.exposedIndexTags` has no `CREATE INDEX` line to ride; the alter line re-applies silently on import). These async writes are serialized and drained by `closeAll()` (or the `whenCatalogPersisted()` barrier) before the provider closes. On reopen, `rehydrateCatalog` classifies entries by key prefix and imports them in phases — tables → views → materialized views, all through the engine's `importCatalog` (MVs re-materialize silently via the shared create core, dependency-ordered for MV-over-MV by fixpoint retry). See [`docs/view-persistence.md`](../../docs/view-persistence.md#view-and-materialized-view-persistence) for the full design.
82
84
 
83
85
  **How a UNIQUE constraint is enforced.** For each row written, the store looks for a conflicting row through the cheapest sound route available:
84
86
 
@@ -89,7 +91,7 @@ seek returns, so an over-fetching window costs only time.
89
91
  Route 2 turns a bulk insert from O(n²) into roughly O(n log n). It is skipped for a constraint the index cannot answer soundly:
90
92
 
91
93
  - A **partial** index cannot serve a constraint it does not derive from: it physically omits its out-of-scope rows, so a seek would miss a conflict among them.
92
- - Index-column bytes are encoded under the **table key collation** `K` (the `collation` module option, default `NOCASE`), not under the constraint's enforcement collation `C`. A seek returns exactly the rows `K`-equal to the new row, so it is a sound *superset* of the true conflict set only when `K` is coarser-than-or-equal-to `C` (a column that can never hold text; `C == K`; or `K = NOCASE` over `C = BINARY`). When `K` is finer — `K = BINARY` over `C = NOCASE`, or `K = NOCASE` over `C = RTRIM` — a seek would under-fetch and silently accept a real duplicate, so the constraint falls back to the full scan. "Can never hold text" is judged by physical representation, not by declared type name: an `ANY` or `JSON` column stores a string as a string, so neither is exempt.
94
+ - Index-column bytes are encoded under each index column's **own** key collation (the index's per-column `COLLATE`, else the table column's declared collation), and the constraint re-validates candidates under its enforcement collation `C` (the same resolution). For every index a designed path can hand the check the two are identical by construction, so the seek window is exactly the `C`-equal set. The check is kept because one undesigned path can still disagree — a user index whose name collides with the `_uc_*` a constraint would have minted lets a same-columns index with different collations be selected — and there a seek would under-fetch and silently accept a real duplicate, so the constraint falls back to the full scan. The **table key collation** `K` (the `collation` module option, default `NOCASE`) is not part of this decision; it is the fallback for an undecorated *primary-key* member only. "Can never hold text" (exempt — key bytes are type-native) is judged by physical representation, not by declared type name: an `ANY` or `JSON` column stores a string as a string, so neither is exempt — and because their `compare` ignores collation, they key hard-`BINARY`, so an `ANY`/`JSON` column carrying a declared `COLLATE` is exactly the shape that declines.
93
95
 
94
96
  Whichever route runs, the conflicting row is re-validated identically: the row being written is excluded by primary key, each constrained column is compared under its enforcement collation (a `CREATE UNIQUE INDEX … (col COLLATE x)` enforces `x`, else the column's declared collation), and a partial constraint's predicate must hold on the candidate.
95
97
 
@@ -99,9 +101,10 @@ Because route 2 trusts the index store to hold an entry for every live row, `CRE
99
101
 
100
102
  - **Kept out of the engine.** It lives only in the StoreTable's *enforcement* schema, never in the engine-registered schema, so the read-query planner does not see it (a plain `UNIQUE` gets no read-side plan from it — matching the memory backend) and it is never written to the catalog as a `CREATE INDEX`.
101
103
  - **Derived on open.** Reconstructing a StoreTable re-materializes the schema entry from `uniqueConstraints`; the physical index store persists on disk under its deterministic name and is reopened lazily. (A store written *before* this feature has no `_uc_*` store on disk — backwards compatibility is waived project-wide; reopening such a database would need the index rebuilt.)
102
- - **Reconciled across ALTER.** `ADD CONSTRAINT` builds the physical store from the existing rows (after the existing-row duplicate check passes); `DROP CONSTRAINT` tears it down (so a later re-`ADD` cannot reopen stale entries); `RENAME CONSTRAINT`, and a column rename that changes an unnamed constraint's implicit name, move the store; a PK / collation / data-type `ALTER` re-encodes it via the same rebuild that re-encodes explicit indexes.
104
+ - **Reconciled across ALTER and CREATE / DROP INDEX.** `ADD CONSTRAINT` builds the physical store from the existing rows (after the existing-row duplicate check passes); `DROP CONSTRAINT` tears it down (so a later re-`ADD` cannot reopen stale entries); `RENAME CONSTRAINT`, and a column rename that changes an unnamed constraint's implicit name, move the store; a PK / collation / data-type `ALTER` re-encodes it via the same rebuild that re-encodes explicit indexes.
103
105
  - **Relocated / reclaimed with the table.** `DROP TABLE` deletes the `_uc_*` store alongside the data + explicit-index stores; `RENAME TABLE` relocates it under the new name. Both resolve the physical store list from the *enforcement* schema (not the engine-facing `.indexes`, which omits `_uc_*`), so the implicit store is never stranded on drop nor left behind on rename (which would leave the renamed table seeking an empty store and accepting a duplicate).
104
- - **Always materialized, even alongside an explicit index.** When a user also declares a matching `CREATE INDEX`, both are maintained (their key bytes are byte-identical, so this is redundant, never wrong). Reusing the explicit index instead is a deferred optimization — see `tickets/backlog/debt-store-implicit-unique-index-reuse`.
106
+ - **Skipped when an explicit index already realizes the constraint.** A `UNIQUE` whose columns are covered — in the same order — by a full (non-partial) `CREATE INDEX` whose per-column collations match the declared column collations gets no `_uc_*` at all: that index enforces it, so a write maintains one structure instead of two. Reuse is refused for a partial index, a partial `UNIQUE`, an index over different or reordered columns, and a collation-mismatched index; those still build the `_uc_*` and both structures coexist. The decision is recomputed whenever the schema changes and is never persisted, so `CREATE INDEX` over a constrained column tears the redundant `_uc_*` store down and `DROP INDEX` rebuilds it from the live rows.
107
+ - **DDL-committing when it tears a store down.** Deleting a `_uc_*` store (or an explicit index store) discards a KVStore handle the transaction coordinator may hold buffered writes against, so those DDL statements flush the module's pending transaction first — the same `ddlTransactionality: 'auto-commit'` posture the row-rewriting `ALTER` arms take. A `CREATE INDEX` that retires no `_uc_*` does not flush.
105
108
 
106
109
  ## Installation
107
110
 
@@ -205,6 +208,30 @@ runKVStoreConformance('MyCustomStore', () => ({
205
208
  See `test/kv-conformance.spec.ts` (in-memory), and the LevelDB / IndexedDB plugins'
206
209
  `test/conformance.spec.ts` for worked adapters.
207
210
 
211
+ **If your provider implements `beginAtomicBatch`, also run the provider suite.** The same
212
+ entry point exports `runKVProviderConformance(name, makeProviderBackend)` — the battery for
213
+ the provider-level contract that ops queued across SEVERAL of the provider's stores commit
214
+ in one durable, all-or-nothing physical write (multi-store commit landing only in each op's
215
+ own store, nothing visible until `write()`, mixed put + delete, a delete of a missing key,
216
+ same-key last-op-wins, `clear()` discarding, the empty `write()` no-op, and `MISUSE` on a
217
+ store handle from a different provider):
218
+
219
+ ```typescript
220
+ import { runKVProviderConformance } from '@quereus/store/testing';
221
+
222
+ runKVProviderConformance('MyCustomProvider atomic batch', () => ({
223
+ open: async () => new MyCustomProvider(/* fresh, empty keyspace */),
224
+ // A SECOND provider over a DIFFERENT keyspace — source of the foreign handle that
225
+ // must be rejected with MISUSE.
226
+ openForeign: async () => new MyCustomProvider(/* another keyspace */),
227
+ teardown: async () => { /* close both, remove backing storage */ },
228
+ }));
229
+ ```
230
+
231
+ The LevelDB / IndexedDB plugins' `test/atomic-batch.spec.ts` run it, keeping only their
232
+ backend-specific cases (LevelDB's "no batch before the shared root is open", IndexedDB's
233
+ post-write read-cache invalidation) alongside.
234
+
208
235
  ## KVStore Interface
209
236
 
210
237
  The `KVStore` interface is the foundation for all storage backends:
@@ -443,6 +470,7 @@ console.log(hasIsolation(isolatedModule)); // true
443
470
  | `StoreTable` | Virtual table implementation (incl. `applyExternalRowChanges` / `readRowByPk` for externally-applied source writes) |
444
471
  | `ExternalRowOp` | One externally-applied row op (`upsert`/`delete`) for `StoreTable.applyExternalRowChanges` (type) |
445
472
  | `resolvePkKeyCollations` | Per-PK-column key collations (pass to `buildDataKey`/`buildIndexKey` to match `StoreTable`'s key bytes) |
473
+ | `resolveIndexKeyCollations` | Per-index-column key collations (the index half of `buildIndexKey`: index COLLATE ?? column collation ?? BINARY) |
446
474
  | `StoreConnection` | Transaction connection |
447
475
  | `TransactionCoordinator` | Transaction management |
448
476
  | `StoreEventEmitter` | Event system for data/schema changes |
@@ -41,7 +41,7 @@ import type { SqlValue, KeyNormalizerResolver } from '@quereus/quereus';
41
41
  export declare const BUILTIN_KEY_NORMALIZER_RESOLVER: KeyNormalizerResolver;
42
42
  /**
43
43
  * Per-column key value transform (resolved by `storeSemanticKeyTransform` in
44
- * store-table.ts): applied to a value BEFORE type-dispatched encoding, so a
44
+ * pk-key-resolution.ts): applied to a value BEFORE type-dispatched encoding, so a
45
45
  * semantic-ordering type keys in its `compare` order and identity. Two transforms
46
46
  * exist today:
47
47
  *
@@ -86,8 +86,9 @@ export declare function encodeValue(value: SqlValue, options?: EncodeOptions): U
86
86
  * composite primary key can carry a *per-column* key collation (e.g. a BINARY
87
87
  * member alongside a NOCASE member) rather than one collation for the whole key.
88
88
  * A `undefined` entry (or no array) falls back to `options.collation`. Collation
89
- * only affects TEXT/OBJECT encoding; non-text components ignore it, so a
90
- * per-column override on an integer/real/blob member is a harmless no-op.
89
+ * only affects TEXT encoding; every other storage class — including OBJECT, see
90
+ * {@link encodeObject} — ignores it, so a per-column override on an
91
+ * integer/real/blob/object member is a harmless no-op.
91
92
  *
92
93
  * When `transforms` is provided, each position with a defined entry maps its value
93
94
  * through that {@link KeyValueTransform} BEFORE encoding (and before DESC inversion),
@@ -1 +1 @@
1
- {"version":3,"file":"encoding.d.ts","sourceRoot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,EAAE,aAAa,CAAC,iBAAiB,GAAG,SAAS,CAAC,GACxD,UAAU,CAqBZ;AA0DD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAW3F;AA8CD;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAc3D;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAW/E;AA0ED;;;GAGG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,UAAU,EAClB,MAAM,GAAE,MAAU,EAClB,OAAO,CAAC,EAAE,aAAa,GACtB;IAAE,KAAK,EAAE,QAAQ,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CA0BxC;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,UAAU,EAClB,aAAa,CAAC,EAAE,MAAM,EACtB,OAAO,CAAC,EAAE,aAAa,GACtB,QAAQ,EAAE,CAeZ"}
@@ -100,7 +100,7 @@ export function encodeValue(value, options) {
100
100
  // JSON string so reorder-equal values ({a:1,b:2} vs {b:2,a:1}) encode to the
101
101
  // same bytes, matching the in-memory JSON comparator. Arrays stay positional.
102
102
  if (typeof value === 'object') {
103
- return encodeObject(canonicalJsonString(value), collation, normalizers);
103
+ return encodeObject(canonicalJsonString(value));
104
104
  }
105
105
  throw new Error(`Cannot encode value of type ${typeof value}`);
106
106
  }
@@ -117,8 +117,9 @@ export function encodeValue(value, options) {
117
117
  * composite primary key can carry a *per-column* key collation (e.g. a BINARY
118
118
  * member alongside a NOCASE member) rather than one collation for the whole key.
119
119
  * A `undefined` entry (or no array) falls back to `options.collation`. Collation
120
- * only affects TEXT/OBJECT encoding; non-text components ignore it, so a
121
- * per-column override on an integer/real/blob member is a harmless no-op.
120
+ * only affects TEXT encoding; every other storage class — including OBJECT, see
121
+ * {@link encodeObject} — ignores it, so a per-column override on an
122
+ * integer/real/blob/object member is a harmless no-op.
122
123
  *
123
124
  * When `transforms` is provided, each position with a defined entry maps its value
124
125
  * through that {@link KeyValueTransform} BEFORE encoding (and before DESC inversion),
@@ -364,13 +365,17 @@ function encodeBlob(value) {
364
365
  * resolved by `storeSemanticKeyTransform`) maps the value to a `Uint8Array` first, so
365
366
  * it encodes through the BLOB path in structural `compare` order instead.
366
367
  *
367
- * NOTE: the collation normalizer runs over the CANONICAL JSON STRING, not over the
368
- * object's text leaves — under the default NOCASE that already lowercases object keys
369
- * and string values inside the key bytes, and a normalizer that reorders or deletes
370
- * characters can leave a string `decodeObject` cannot `JSON.parse`. Latent today:
371
- * nothing in the row path decodes an object key (rows are serialized separately, and
372
- * `decodeCompositeKey` has no `src/` caller). If an object-valued key ever has to be
373
- * decoded, normalize the leaves before canonicalization rather than the string after.
368
+ * Deliberately takes NO collation: the canonical string is encoded verbatim. Collation
369
+ * never reaches an OBJECT-class value in the engine — `compareSameType` consults the
370
+ * collation function only on the TEXT/TEXT branch, and the engine's own key serializer
371
+ * (`util/key-serializer.ts`) normalizes only string values — so folding the canonical
372
+ * string here would make key identity/order disagree with the comparator that governs
373
+ * the structure. That mattered the moment `any collate nocase` became a real key
374
+ * collation (ticket `any-type-compare-honors-collation`): an object-valued member of
375
+ * such a PK collided at one lowercased key (`{"A":1}` vs `{"a":1}`) while the memory
376
+ * backend kept them distinct, and `order by` over the folded bytes inverted the
377
+ * comparator's code-point order. Encoding verbatim also keeps the bytes `JSON.parse`-able,
378
+ * which a character-deleting normalizer (RTRIM) would not.
374
379
  *
375
380
  * NOTE: no unpaired-surrogate guard here, unlike `encodeText`. `canonicalJsonString` ends
376
381
  * in `JSON.stringify`, which is well-formed (ES2019): it escapes every lone surrogate to
@@ -379,9 +384,8 @@ function encodeBlob(value) {
379
384
  * `JSON.stringify` (or gains a `rawJSON` passthrough), that escaping is lost and this must
380
385
  * call `assertNoUnpairedSurrogate` too.
381
386
  */
382
- function encodeObject(jsonString, collation, normalizers) {
383
- const sortValue = normalizers(collation)(jsonString);
384
- const utf8 = new TextEncoder().encode(sortValue);
387
+ function encodeObject(jsonString) {
388
+ const utf8 = new TextEncoder().encode(jsonString);
385
389
  return writeEscapedWithTerminator(TYPE_OBJECT, utf8);
386
390
  }
387
391
  // ============================================================================
@@ -1 +1 @@
1
- {"version":3,"file":"encoding.js","sourceRoot":"","sources":["../../../src/common/encoding.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAGH,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEtG,+EAA+E;AAC/E,mBAAmB;AACnB,+EAA+E;AAE/E;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAA0B,CAAC,aAAa,EAAE,EAAE;IACtF,IAAI,CAAC,aAAa,IAAI,aAAa,KAAK,QAAQ;QAAE,OAAO,mBAAmB,CAAC,MAAM,CAAC;IACpF,MAAM,UAAU,GAAG,mBAAmB,CAAC,aAAa,CAAC,WAAW,EAAE,CAAC,CAAC;IACpE,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,YAAY,CAAC,+BAA+B,aAAa,EAAE,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC;IAC3F,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAkCF,yBAAyB;AACzB,MAAM,SAAS,GAAG,IAAI,CAAC;AACvB;;;;;GAKG;AACH,MAAM,YAAY,GAAG,IAAI,CAAC;AAC1B,MAAM,SAAS,GAAG,IAAI,CAAC;AACvB,MAAM,SAAS,GAAG,IAAI,CAAC;AACvB,MAAM,WAAW,GAAG,IAAI,CAAC;AAEzB;;;;;;;;GAQG;AACH,MAAM,kBAAkB,GAAG,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EAAE,CAAC;QACN,CAAC;IACH,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC;AACjE,CAAC;AAED,SAAS,UAAU,CACjB,MAAkB,EAClB,MAAc,EACd,UAAkB;IAElB,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,0BAA0B,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxE,MAAM,KAAK,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAE9C,4EAA4E;IAC5E,gEAAgE;IAChE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;AAC9B,CAAC;AAED,SAAS,UAAU,CAAC,MAAkB,EAAE,MAAc;IACpD,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,0BAA0B,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;AACrC,CAAC;AAED;;;;;GAKG;AACH,SAAS,YAAY,CAAC,MAAkB,EAAE,MAAc;IACtD,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,0BAA0B,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxE,MAAM,UAAU,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACnD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAa,CAAC;IACjD,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;AAC9B,CAAC"}
@@ -10,18 +10,24 @@ export interface SchemaChangeEvent {
10
10
  objectType: 'table' | 'index';
11
11
  schemaName: string;
12
12
  objectName: string;
13
+ /** `RENAME TO` only: the table name before the rename (`objectName` carries the new one). */
14
+ oldObjectName?: string;
13
15
  ddl?: string;
14
16
  /** True if this event originated from sync (remote replica) or cross-tab. */
15
17
  remote?: boolean;
16
18
  }
17
19
  /**
18
20
  * Data change event types.
21
+ *
22
+ * Producers owe the engine's key contract (`docs/usage.md` § Subscribing to Data Changes):
23
+ * `key` is projected from the event's own row image, and an `update` never moves a row — a
24
+ * relocating primary-key change is a `delete` at the old key then an `insert` at the new one.
19
25
  */
20
26
  export interface DataChangeEvent {
21
27
  type: 'insert' | 'update' | 'delete';
22
28
  schemaName: string;
23
29
  tableName: string;
24
- /** Primary key values. Alias: pk */
30
+ /** Primary key projected from this event's own image: `newRow` for insert/update, `oldRow` for delete. Alias: pk */
25
31
  key?: SqlValue[];
26
32
  /** Primary key values. Alias: key */
27
33
  pk?: SqlValue[];
@@ -37,15 +43,6 @@ export interface DataChangeEvent {
37
43
  */
38
44
  export type SchemaChangeListener = (event: SchemaChangeEvent) => void;
39
45
  export type DataChangeListener = (event: DataChangeEvent) => void;
40
- /**
41
- * Key for identifying a pending remote schema event.
42
- */
43
- interface PendingRemoteSchemaEvent {
44
- type: 'create' | 'alter' | 'drop';
45
- objectType: 'table' | 'index';
46
- schemaName: string;
47
- objectName: string;
48
- }
49
46
  /**
50
47
  * Simple event emitter for store events.
51
48
  * Implements VTableEventEmitter for compatibility with core vtab event system.
@@ -56,10 +53,11 @@ export declare class StoreEventEmitter implements VTableEventEmitter {
56
53
  private batchedDataEvents;
57
54
  private isBatching;
58
55
  /**
59
- * Pending remote schema events that should be marked as remote when they arrive.
60
- * Uses a Map with stringified key for O(1) lookup.
56
+ * Open remote-schema scopes, refcounted per `(schema, object)` key. While a
57
+ * scope is open, every schema event naming that object is marked remote —
58
+ * see {@link beginRemoteSchemaScope}.
61
59
  */
62
- private pendingRemoteSchemaEvents;
60
+ private remoteSchemaScopes;
63
61
  /**
64
62
  * Subscribe to schema change events.
65
63
  * @returns Unsubscribe function.
@@ -72,23 +70,32 @@ export declare class StoreEventEmitter implements VTableEventEmitter {
72
70
  onDataChange(listener: DataChangeListener): () => void;
73
71
  /**
74
72
  * Emit a schema change event.
75
- * If the event matches a pending remote event, it's automatically marked as remote.
73
+ * If a remote-schema scope is open for the named object, the event is marked remote.
76
74
  */
77
75
  emitSchemaChange(event: SchemaChangeEvent): void;
78
76
  /**
79
- * Create a unique key for a schema event signature.
80
- */
81
- private makeSchemaEventKey;
82
- /**
83
- * Register an expected remote schema event.
84
- * When a matching event is emitted, it will be automatically marked as remote.
85
- * Uses reference counting to handle concurrent applies of the same event type.
77
+ * Open a remote-schema scope for `(schemaName, objectName)`: until the matching
78
+ * {@link endRemoteSchemaScope}, EVERY schema event naming that object is marked
79
+ * `remote: true` — whether the scoped statement emits zero, one, or several
80
+ * events. Matching never consumes the scope; only the caller's `finally` closes
81
+ * it, so a statement that emits nothing leaves nothing behind. Refcounted, so
82
+ * nested/concurrent scopes over the same object compose.
83
+ *
84
+ * Tradeoff of time-bounded (vs. the old signature-matched, consume-on-match)
85
+ * marking: a CONCURRENT local DDL on the same `(schema, object)`, issued while
86
+ * the scoped statement is in flight, would be mis-marked remote. `Database`
87
+ * serializes statements behind its execution mutex, so that requires a host
88
+ * issuing local DDL on the very table being replicated at that moment. The old
89
+ * scheme had the mirror-image hazard (a concurrent local DDL of the same
90
+ * signature consumed the marker) and additionally leaked or starved whenever a
91
+ * statement's event count was not exactly one.
86
92
  */
87
- expectRemoteSchemaEvent(event: PendingRemoteSchemaEvent): void;
93
+ beginRemoteSchemaScope(schemaName: string, objectName: string): void;
88
94
  /**
89
- * Clear an expected remote schema event (e.g., if the operation failed).
95
+ * Close a scope opened by {@link beginRemoteSchemaScope}. Call from a `finally`
96
+ * so a throwing statement cannot leave the scope open.
90
97
  */
91
- clearExpectedRemoteSchemaEvent(event: PendingRemoteSchemaEvent): void;
98
+ endRemoteSchemaScope(schemaName: string, objectName: string): void;
92
99
  /**
93
100
  * Emit a data change event.
94
101
  * If batching is active, queues the event for later emission.
@@ -124,5 +131,4 @@ export declare class StoreEventEmitter implements VTableEventEmitter {
124
131
  */
125
132
  removeAllListeners(): void;
126
133
  }
127
- export {};
128
134
  //# sourceMappingURL=events.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../../src/common/events.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE1E;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC;IAClC,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,6EAA6E;IAC7E,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;IACrC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,oCAAoC;IACpC,GAAG,CAAC,EAAE,QAAQ,EAAE,CAAC;IACjB,qCAAqC;IACrC,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC;IAChB,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,0DAA0D;IAC1D,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,6EAA6E;IAC7E,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,CAAC;AACtE,MAAM,MAAM,kBAAkB,GAAG,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;AAElE;;GAEG;AACH,UAAU,wBAAwB;IAChC,IAAI,EAAE,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC;IAClC,UAAU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BAAoB,GAAG,MAAM,IAAI;IAK1D;;;OAGG;IACH,YAAY,CAAC,QAAQ,EAAE,kBAAkB,GAAG,MAAM,IAAI;IAKtD;;;OAGG;IACH,gBAAgB,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI;IAchD;;;;;;;;;;;;;;;;OAgBG;IACH,sBAAsB,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI;IAKpE;;;OAGG;IACH,oBAAoB,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI;IAUlE;;;OAGG;IACH,cAAc,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI;IAe5C;;;OAGG;IACH,UAAU,IAAI,IAAI;IAKlB;;OAEG;IACH,UAAU,IAAI,IAAI;IAgBlB;;OAEG;IACH,YAAY,IAAI,IAAI;IAKrB;;OAEG;IACH,YAAY,IAAI,OAAO;IAIvB;;OAEG;IACH,gBAAgB,IAAI,OAAO;IAI3B;;OAEG;IACH,kBAAkB,IAAI,OAAO;IAI7B;;OAEG;IACH,kBAAkB,IAAI,IAAI;CAM1B"}
@@ -1,6 +1,10 @@
1
1
  /**
2
2
  * Reactive event types and emitter for schema and data changes.
3
3
  */
4
+ /** Case-insensitive `(schema, object)` scope key — identifiers are case-insensitive engine-wide. */
5
+ function remoteScopeKey(schemaName, objectName) {
6
+ return `${schemaName.toLowerCase()}:${objectName.toLowerCase()}`;
7
+ }
4
8
  /**
5
9
  * Simple event emitter for store events.
6
10
  * Implements VTableEventEmitter for compatibility with core vtab event system.
@@ -11,10 +15,11 @@ export class StoreEventEmitter {
11
15
  batchedDataEvents = [];
12
16
  isBatching = false;
13
17
  /**
14
- * Pending remote schema events that should be marked as remote when they arrive.
15
- * Uses a Map with stringified key for O(1) lookup.
18
+ * Open remote-schema scopes, refcounted per `(schema, object)` key. While a
19
+ * scope is open, every schema event naming that object is marked remote —
20
+ * see {@link beginRemoteSchemaScope}.
16
21
  */
17
- pendingRemoteSchemaEvents = new Map();
22
+ remoteSchemaScopes = new Map();
18
23
  /**
19
24
  * Subscribe to schema change events.
20
25
  * @returns Unsubscribe function.
@@ -33,21 +38,11 @@ export class StoreEventEmitter {
33
38
  }
34
39
  /**
35
40
  * Emit a schema change event.
36
- * If the event matches a pending remote event, it's automatically marked as remote.
41
+ * If a remote-schema scope is open for the named object, the event is marked remote.
37
42
  */
38
43
  emitSchemaChange(event) {
39
- // Check if this event matches a pending remote event
40
- const key = this.makeSchemaEventKey(event);
41
- const pendingCount = this.pendingRemoteSchemaEvents.get(key);
42
- if (pendingCount !== undefined && pendingCount > 0) {
43
- // Mark as remote and decrement the pending count
44
+ if ((this.remoteSchemaScopes.get(remoteScopeKey(event.schemaName, event.objectName)) ?? 0) > 0) {
44
45
  event = { ...event, remote: true };
45
- if (pendingCount === 1) {
46
- this.pendingRemoteSchemaEvents.delete(key);
47
- }
48
- else {
49
- this.pendingRemoteSchemaEvents.set(key, pendingCount - 1);
50
- }
51
46
  }
52
47
  for (const listener of this.schemaListeners) {
53
48
  try {
@@ -59,34 +54,38 @@ export class StoreEventEmitter {
59
54
  }
60
55
  }
61
56
  /**
62
- * Create a unique key for a schema event signature.
57
+ * Open a remote-schema scope for `(schemaName, objectName)`: until the matching
58
+ * {@link endRemoteSchemaScope}, EVERY schema event naming that object is marked
59
+ * `remote: true` — whether the scoped statement emits zero, one, or several
60
+ * events. Matching never consumes the scope; only the caller's `finally` closes
61
+ * it, so a statement that emits nothing leaves nothing behind. Refcounted, so
62
+ * nested/concurrent scopes over the same object compose.
63
+ *
64
+ * Tradeoff of time-bounded (vs. the old signature-matched, consume-on-match)
65
+ * marking: a CONCURRENT local DDL on the same `(schema, object)`, issued while
66
+ * the scoped statement is in flight, would be mis-marked remote. `Database`
67
+ * serializes statements behind its execution mutex, so that requires a host
68
+ * issuing local DDL on the very table being replicated at that moment. The old
69
+ * scheme had the mirror-image hazard (a concurrent local DDL of the same
70
+ * signature consumed the marker) and additionally leaked or starved whenever a
71
+ * statement's event count was not exactly one.
63
72
  */
64
- makeSchemaEventKey(event) {
65
- return `${event.type}:${event.objectType}:${event.schemaName.toLowerCase()}:${event.objectName.toLowerCase()}`;
73
+ beginRemoteSchemaScope(schemaName, objectName) {
74
+ const key = remoteScopeKey(schemaName, objectName);
75
+ this.remoteSchemaScopes.set(key, (this.remoteSchemaScopes.get(key) ?? 0) + 1);
66
76
  }
67
77
  /**
68
- * Register an expected remote schema event.
69
- * When a matching event is emitted, it will be automatically marked as remote.
70
- * Uses reference counting to handle concurrent applies of the same event type.
78
+ * Close a scope opened by {@link beginRemoteSchemaScope}. Call from a `finally`
79
+ * so a throwing statement cannot leave the scope open.
71
80
  */
72
- expectRemoteSchemaEvent(event) {
73
- const key = this.makeSchemaEventKey(event);
74
- const current = this.pendingRemoteSchemaEvents.get(key) ?? 0;
75
- this.pendingRemoteSchemaEvents.set(key, current + 1);
76
- }
77
- /**
78
- * Clear an expected remote schema event (e.g., if the operation failed).
79
- */
80
- clearExpectedRemoteSchemaEvent(event) {
81
- const key = this.makeSchemaEventKey(event);
82
- const current = this.pendingRemoteSchemaEvents.get(key);
83
- if (current !== undefined && current > 0) {
84
- if (current === 1) {
85
- this.pendingRemoteSchemaEvents.delete(key);
86
- }
87
- else {
88
- this.pendingRemoteSchemaEvents.set(key, current - 1);
89
- }
81
+ endRemoteSchemaScope(schemaName, objectName) {
82
+ const key = remoteScopeKey(schemaName, objectName);
83
+ const current = this.remoteSchemaScopes.get(key);
84
+ if (current === undefined || current <= 1) {
85
+ this.remoteSchemaScopes.delete(key);
86
+ }
87
+ else {
88
+ this.remoteSchemaScopes.set(key, current - 1);
90
89
  }
91
90
  }
92
91
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"events.js","sourceRoot":"","sources":["../../../src/common/events.ts"],"names":[],"mappings":"AAAA;;GAEG;AAoDH;;;GAGG;AACH,MAAM,OAAO,iBAAiB;IACrB,eAAe,GAA8B,IAAI,GAAG,EAAE,CAAC;IACvD,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,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;QACxB,IAAI,CAAC,iBAAiB,GAAG,EAAE,CAAC;IAC9B,CAAC;IAEF;;OAEG;IACH,YAAY;QACX,OAAO,IAAI,CAAC,eAAe,CAAC,IAAI,GAAG,CAAC,IAAI,IAAI,CAAC,aAAa,CAAC,IAAI,GAAG,CAAC,CAAC;IACrE,CAAC;IAED;;OAEG;IACH,gBAAgB;QACf,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,GAAG,CAAC,CAAC;IACpC,CAAC;IAED;;OAEG;IACH,kBAAkB;QACjB,OAAO,IAAI,CAAC,eAAe,CAAC,IAAI,GAAG,CAAC,CAAC;IACtC,CAAC;IAED;;OAEG;IACH,kBAAkB;QACjB,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;QAC7B,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;QAC3B,IAAI,CAAC,iBAAiB,GAAG,EAAE,CAAC;QAC5B,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;IACzB,CAAC;CACD"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * The hidden `_uc_*` secondary index the store materializes per non-derived
3
+ * UNIQUE constraint that no explicit index already covers, so a plain UNIQUE
4
+ * enforces via a point seek rather than a full scan — plus the reuse test that
5
+ * decides when an existing index already serves that role.
6
+ */
7
+ import { type TableSchema, type TableIndexSchema, type UniqueConstraintSchema } from '@quereus/quereus';
8
+ /**
9
+ * Deterministic name of the implicit covering index materialized for a
10
+ * NON-DERIVED UNIQUE constraint `uc`: the constraint's own name when it has one,
11
+ * else the auto-name `_uc_<colNames>`. This MUST equal the engine's
12
+ * `catalog.ts` `implicitIndexName`, so a name that ever reaches the catalog
13
+ * bundle generator is recognized as hidden / exposed-implicit rather than a user
14
+ * index.
15
+ */
16
+ export declare function implicitUniqueIndexName(schema: TableSchema, uc: UniqueConstraintSchema): string;
17
+ /**
18
+ * The existing `schema.indexes` entry that already realizes `uc`, or undefined
19
+ * when none does and {@link withImplicitUniqueIndexes} must materialize a hidden
20
+ * `_uc_*` of its own.
21
+ *
22
+ * A FULL (non-partial) index over exactly the constrained columns physically
23
+ * holds an entry for every live row, keyed by the same bytes the `_uc_*` would
24
+ * use — so `StoreTableConstraints.findUniqueConflictViaIndex` can seek it directly and
25
+ * a second identical structure would only double DML maintenance. Reuse is
26
+ * refused for:
27
+ *
28
+ * - an index-DERIVED UC (`derivedFromIndex`) — it already names its index;
29
+ * - a PARTIAL UNIQUE (`uc.predicate`) — the co-scoped `_uc_*` carries the SAME
30
+ * predicate OBJECT, which `StoreTableConstraints.findIndexForUniqueConstraint`
31
+ * matches on identity; a user index with an equal-but-distinct predicate
32
+ * physically omits rows the constraint still covers;
33
+ * - a PARTIAL index — it omits out-of-scope rows a full UNIQUE still covers;
34
+ * - a collation-mismatched index (see {@link indexCollationsMatchDeclared}).
35
+ *
36
+ * A DESC index IS reusable: every writer and reader of an index derives its
37
+ * direction flags from that index's own `columns[].desc`
38
+ * (`StoreTableConstraints.updateSecondaryIndexes`,
39
+ * `StoreTableConstraints.findUniqueConflictViaIndex`), so the enforcement probe lands
40
+ * on the same window a DESC-encoded entry was written to.
41
+ *
42
+ * Reuse makes a plain UNIQUE's hidden index depend on the set of EXPLICIT
43
+ * indexes, so `StoreModule.createIndex` / `dropIndex` must reconcile the physical
44
+ * `_uc_*` store on the transition — see
45
+ * `StoreModule.reconcileImplicitUniqueIndexStores`.
46
+ */
47
+ export declare function findReusableIndexForUnique(schema: TableSchema, uc: UniqueConstraintSchema): TableIndexSchema | undefined;
48
+ /**
49
+ * Return `schema` with a synthetic secondary index materialized into
50
+ * `schema.indexes` for every NON-DERIVED UNIQUE constraint that lacks one — the
51
+ * store analogue of `MemoryTableManager.ensureUniqueConstraintIndexes`.
52
+ *
53
+ * This is what lets a plain column- or table-level `UNIQUE` be enforced by a
54
+ * bounded index point-seek (`StoreTableConstraints.findUniqueConflictViaIndex`)
55
+ * instead of an O(rows) full scan: DML maintenance
56
+ * (`StoreTableConstraints.updateSecondaryIndexes`) and the UNIQUE check both iterate
57
+ * `schema.indexes`, so once the `_uc_*` entry is present the physical index is
58
+ * maintained and seeked with no new code path.
59
+ *
60
+ * The result is held ONLY in `StoreTableBase.materializedSchema` (the
61
+ * enforcement copy), never in the engine-facing `tableSchema` the store returns
62
+ * from `getSchema()` / registers with the engine. So the read-query planner and
63
+ * the catalog bundle never see `_uc_*` (it is fully derived on open from
64
+ * `uniqueConstraints`); like the memory backend, a plain UNIQUE gets no read-side
65
+ * plan from `_uc_*`, only enforcement / maintenance.
66
+ *
67
+ * Idempotent — a name already present is left untouched — and returns a frozen
68
+ * schema (or the input unchanged when there is nothing to add). A
69
+ * `derivedFromIndex` UC is skipped (its `CREATE UNIQUE INDEX` is already in
70
+ * `schema.indexes`). A partial UNIQUE's synthetic index carries the SAME
71
+ * `uc.predicate` object reference, which
72
+ * `StoreTableConstraints.findIndexForUniqueConstraint` matches on identity.
73
+ *
74
+ * A UC whose columns are already covered by a collation-compatible EXPLICIT full
75
+ * index is left WITHOUT a `_uc_*` — that index enforces it (see
76
+ * {@link findReusableIndexForUnique}), so building a byte-identical twin would
77
+ * only double the work of every INSERT / UPDATE / DELETE.
78
+ */
79
+ export declare function withImplicitUniqueIndexes(schema: TableSchema): TableSchema;
80
+ //# sourceMappingURL=implicit-unique-index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"implicit-unique-index.d.ts","sourceRoot":"","sources":["../../../src/common/implicit-unique-index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAEN,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC3B,MAAM,kBAAkB,CAAC;AAE1B;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,WAAW,EAAE,EAAE,EAAE,sBAAsB,GAAG,MAAM,CAE/F;AAkCD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,0BAA0B,CACzC,MAAM,EAAE,WAAW,EACnB,EAAE,EAAE,sBAAsB,GACxB,gBAAgB,GAAG,SAAS,CAc9B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW,CAuB1E"}