@ultimat3/entity 31.17.0 → 31.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CLAUDE.md CHANGED
@@ -80,7 +80,7 @@ A rule marked `†` has its full text in [`docs/history/entity-rules.md`](../../
80
80
  - **A `timestamp` cursor carries MICROSECONDS** (`seekPrecision`, `instant.ts`). Full rule: `docs/history/entity.md`.
81
81
  - **The four aggregates** (`sum`, `avg`, `min`, `max`) share `aggregate.ts`:
82
82
  never a float; `null` for an empty set; refusals `X_AGGREGATE_UNSUPPORTED`,
83
- `X_AGGREGATE_MIXED_CURRENCY`. Full rule: `docs/history/entity.md`. **`approximateCount()` is `reltuples`**; a filtered chain or tenant-scoped entity is
83
+ `X_AGGREGATE_MIXED_CURRENCY`. Full rule: `docs/history/entity.md`. **`approximateCount()` is `reltuples`**; a filtered chain, a tenant-scoped or a soft-deleting entity is
84
84
  `X_APPROXIMATE_COUNT_FILTERED`; `null` for an unanalysed table.
85
85
  - **`series`, views**: `time-bucket.ts` (zone rules, measured), `view-repo.ts` (read-only); `time-bucket.test.ts`, `view-entity.test.ts`.
86
86
  - **`json()` / `arrayOf()` are filterable** (`containment.ts`); no jsonpath operator. †
package/README.md CHANGED
@@ -474,7 +474,7 @@ visibility, never its page.
474
474
  | Empty set | `null` in every function, which is what SQL answers — a `0` would claim rows were seen. `count()` is `0`, and that is the distinction |
475
475
  | `avg` | one fixed scale (6 digits), rounded half away from zero from the exact rational, so both drivers land on one number |
476
476
  | Refused | `min`/`max` on `text` (ordering is the database's collation there and JS code-unit order here); `avg` over money (every answer would be a silent rounding of a fraction of a minor unit — `sum()` and `count()` instead, dividing where the rounding is a decision); an amount covering more than one currency **or scale**; a money total past ±2^53 minor units |
477
- | `approximateCount()` | `reltuples` out of `pg_class`, constant time, because `count(*)` walks every visible row and no index can make it cheaper. The whole **table** — a filtered chain and every tenant-scoped entity are `X_APPROXIMATE_COUNT_FILTERED`, and `null` means the table has never been analysed |
477
+ | `approximateCount()` | `reltuples` out of `pg_class`, constant time, because `count(*)` walks every visible row and no index can make it cheaper. The whole **table** — a filtered chain, every tenant-scoped entity and every soft-deleting one (`reltuples` counts the deleted rows) are `X_APPROXIMATE_COUNT_FILTERED`, and `null` means the table has never been analysed |
478
478
 
479
479
  ## The operator vocabulary
480
480
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/entity",
3
- "version": "31.17.0",
3
+ "version": "31.18.0",
4
4
  "description": "A table + its domain type + invariants the database also enforces",
5
5
  "keywords": [
6
6
  "ultimate",
@@ -44,9 +44,9 @@
44
44
  "test": "bun test"
45
45
  },
46
46
  "dependencies": {
47
- "@ultimat3/core": "31.17.0",
48
- "@ultimat3/db": "31.17.0",
49
- "@ultimat3/schema": "31.17.0",
50
- "@ultimat3/time": "31.17.0"
47
+ "@ultimat3/core": "31.18.0",
48
+ "@ultimat3/db": "31.18.0",
49
+ "@ultimat3/schema": "31.18.0",
50
+ "@ultimat3/time": "31.18.0"
51
51
  }
52
52
  }
package/src/plan.ts CHANGED
@@ -157,6 +157,9 @@ export const readPlan = <Row>(
157
157
  * A TENANT-SCOPED entity is therefore refused outright, filters or none: its whole-table estimate
158
158
  * is a number about every tenant, and a per-tenant row count is not a thing the planner holds.
159
159
  * That refusal is not a limitation of this method, it is what the method means.
160
+ *
161
+ * A SOFT-DELETING entity is refused for the same reason: `reltuples` counts the rows every other read
162
+ * hides (`deletedAt` set), so the estimate answers a question no caller of this repo can ask.
160
163
  */
161
164
  const assertEstimable = <Row>(entity: EntityCore<Row>, plan: QueryPlan): void => {
162
165
  if (entity.$tenantColumn !== null) {
@@ -166,6 +169,13 @@ const assertEstimable = <Row>(entity: EntityCore<Row>, plan: QueryPlan): void =>
166
169
  fix: `${entity.$name}.count() # the exact answer, scoped to the acting actor's tenant as every other read is`,
167
170
  });
168
171
  }
172
+ if (entity.$softDelete) {
173
+ throw new EntityError({
174
+ code: 'X_APPROXIMATE_COUNT_FILTERED',
175
+ cause: `${entity.$name}.approximateCount() is a whole-TABLE estimate and ${entity.$name} soft-deletes — the planner counts the deletedAt rows every read of it hides`,
176
+ fix: `${entity.$name}.count() # the exact answer, which leaves the soft-deleted rows out as every other read does`,
177
+ });
178
+ }
169
179
  if (plan.where.length === 0) return;
170
180
  const named = plan.where.map((each) => each.column).join(', ');
171
181
  throw new EntityError({