@ultimat3/entity 31.32.0 → 31.33.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/package.json +5 -5
- package/src/bulk-write.ts +4 -3
- package/src/coalesce.ts +3 -2
- package/src/containment.ts +6 -4
- package/src/count-by.ts +4 -3
- package/src/instant.ts +4 -2
- package/src/memory-match.ts +6 -4
- package/src/pg-array-literal.ts +6 -5
- package/src/pg-row.ts +5 -4
- package/src/query.ts +4 -3
- package/src/refuse.ts +4 -3
- package/src/sealed-repo.ts +3 -1
- package/src/seed.ts +1 -2
- package/src/type-pins.ts +6 -5
- package/src/write-tag.ts +8 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/entity",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.33.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.
|
|
48
|
-
"@ultimat3/db": "31.
|
|
49
|
-
"@ultimat3/schema": "31.
|
|
50
|
-
"@ultimat3/time": "31.
|
|
47
|
+
"@ultimat3/core": "31.33.0",
|
|
48
|
+
"@ultimat3/db": "31.33.0",
|
|
49
|
+
"@ultimat3/schema": "31.33.0",
|
|
50
|
+
"@ultimat3/time": "31.33.0"
|
|
51
51
|
}
|
|
52
52
|
}
|
package/src/bulk-write.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// Single responsibility: what a many-row write is made of, decided once in PROPERTY space so both
|
|
2
2
|
// drivers write the same thing — the columns one statement carries, which of them a collision
|
|
3
|
-
// overwrites, and the chunking that keeps a statement inside Postgres's bind count.
|
|
4
|
-
//
|
|
5
|
-
//
|
|
3
|
+
// overwrites, and the chunking that keeps a statement inside Postgres's bind count.
|
|
4
|
+
//
|
|
5
|
+
// The SQL is `pg-sql.ts`'s; everything here is the decision that has to precede it, and the
|
|
6
|
+
// in-memory driver reads the same answer rather than a second copy of the rule.
|
|
6
7
|
|
|
7
8
|
import { keyOf } from './batch-read';
|
|
8
9
|
import { columnFor } from './column';
|
package/src/coalesce.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
// Single responsibility: collapse the point lookups one request issues in the same microtask into
|
|
2
|
-
//
|
|
1
|
+
// Single responsibility: collapse the point lookups one request issues in the same microtask into a
|
|
2
|
+
// single `where id in (…)`, and hand a lookup a page already answered straight to the preload.
|
|
3
|
+
//
|
|
3
4
|
// A list that resolves an author per row is the N+1 this removes, and it removes it without adding
|
|
4
5
|
// a second way to read — `findById` keeps its signature and its meaning, and pays for one round
|
|
5
6
|
// trip instead of one per row.
|
package/src/containment.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// Single responsibility: what `@>`, `<@`, `&&` and a JSON key test MEAN, written once so the
|
|
2
|
-
// in-memory driver answers what Postgres answers.
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
2
|
+
// in-memory driver answers what Postgres answers.
|
|
3
|
+
//
|
|
4
|
+
// A `jsonb` or an `arrayOf()` column was declared and then unfilterable — the ten-operator
|
|
5
|
+
// vocabulary had nothing that could look inside one — so an app with either had to leave the query
|
|
6
|
+
// language for hand-written SQL, which is the one path in this framework with no tenancy guard on
|
|
7
|
+
// it.
|
|
6
8
|
//
|
|
7
9
|
// Every rule here is Postgres', reproduced rather than approximated. Where the two could not be
|
|
8
10
|
// made to agree the operator is refused instead (`memory-match.ts`), never guessed at.
|
package/src/count-by.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// Single responsibility: what a grouped count is made of — which columns a count may be keyed by,
|
|
2
2
|
// how many groups one statement is allowed to answer with, and the order the map comes back in.
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
3
|
+
//
|
|
4
|
+
// Both drivers read those three rules from here, so a `countBy` against memory means exactly what a
|
|
5
|
+
// `countBy` against Postgres means; a rule added to one driver alone is the drift this file exists
|
|
6
|
+
// to prevent.
|
|
6
7
|
|
|
7
8
|
import { renderFixShellArg } from '@ultimat3/core';
|
|
8
9
|
import { columnFor } from './column';
|
package/src/instant.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// Single responsibility: a `timestamptz` value at the precision the COLUMN stores it, rather than
|
|
2
2
|
// the precision a JS `Date` holds. The column keeps microseconds and a `Date` keeps milliseconds,
|
|
3
3
|
// so a page position minted from a decoded row ranks rows differently from the `order by` that
|
|
4
|
-
// produced them.
|
|
5
|
-
//
|
|
4
|
+
// produced them.
|
|
5
|
+
//
|
|
6
|
+
// Microseconds since the epoch is the one form both sides can be exact in, and this file is the
|
|
7
|
+
// only place the two representations meet.
|
|
6
8
|
|
|
7
9
|
/** A `Date` is exactly this much coarser than the column it came out of. */
|
|
8
10
|
const MICROS_PER_MILLI = 1000n;
|
package/src/memory-match.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// Single responsibility: what a `Predicate` MEANS in the in-memory driver — equality, ordering and
|
|
2
|
-
// LIKE.
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
2
|
+
// LIKE.
|
|
3
|
+
//
|
|
4
|
+
// Every rule here exists so the answer matches the one Postgres gives for the same predicate on the
|
|
5
|
+
// same column, which is why each is decided by the column's DECLARED KIND and never by the JS type
|
|
6
|
+
// of whichever value is in hand: the database decides by the column's type, so a driver deciding by
|
|
7
|
+
// `typeof` is answering a different question.
|
|
6
8
|
|
|
7
9
|
import { keyOf } from './batch-read';
|
|
8
10
|
import { columnFor } from './column';
|
package/src/pg-array-literal.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
// Single responsibility: the Postgres array TEXT literal — `{a,b}`, `{"a,b",NULL}`,
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
1
|
+
// Single responsibility: the Postgres array TEXT literal — `{a,b}`, `{"a,b",NULL}`, `{{1,2},{3,4}}`
|
|
2
|
+
// — read into a JS array. The one grammar in the framework: the repository reads a literal a driver
|
|
3
|
+
// left unparsed (`pg-array-decode.ts`) and `@ultimat3/realtime` reads the one the WAL carries, and
|
|
4
|
+
// two readers of one grammar are how a quoted `"NULL"` becomes a null in one of them.
|
|
5
|
+
//
|
|
6
|
+
// The element decoder arrives as a parameter, so this file knows no type.
|
|
6
7
|
//
|
|
7
8
|
// The writer is `arrayLiteral` in `pg-row.ts`; `pg-array-literal.test.ts` holds the two to each
|
|
8
9
|
// other, so what this package writes is what it can read.
|
package/src/pg-row.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// Single responsibility: the two-way map between a physical Postgres row and an entity row.
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
2
|
+
//
|
|
3
|
+
// Three things are not one-to-one and all three live here: the property key is camelCase while the
|
|
4
|
+
// column is snake_case, money is one property over two columns, and a value that came back from the
|
|
5
|
+
// driver is re-parsed by the column that declared it rather than trusted — int8 arrives as a
|
|
6
|
+
// string, timestamptz may arrive as one, and a silent `NaN` is worse than a loud throw.
|
|
6
7
|
|
|
7
8
|
import { columnFor, columnName, moneyColumns } from './column';
|
|
8
9
|
import { narrowMoney } from './columns';
|
package/src/query.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// The chainable read. Every chain terminates in a cursor page — `page()` returns rows plus the
|
|
2
2
|
// cursor for the next one, `all()`/`one()` are that page's rows, and `inBatches()` is that page
|
|
3
|
-
// repeated until the cursor runs out.
|
|
4
|
-
//
|
|
5
|
-
//
|
|
3
|
+
// repeated until the cursor runs out.
|
|
4
|
+
//
|
|
5
|
+
// There is no `offset()` and there will not be one: under concurrent writes an insert before the
|
|
6
|
+
// offset shifts every later page, so a client silently skips and repeats rows.
|
|
6
7
|
|
|
7
8
|
import type { Page } from '@ultimat3/core';
|
|
8
9
|
import { pageOf } from '@ultimat3/core';
|
package/src/refuse.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// The two refusals raised while a SCHEMA is still being written — a column and an invariant — and
|
|
2
|
-
// why neither goes through `invariantViolated`: that builder's fix is
|
|
3
|
-
//
|
|
4
|
-
//
|
|
2
|
+
// why neither goes through `invariantViolated`: that builder's fix is `x entities show <entityName>
|
|
3
|
+
// --json`, which needs an entity that exists.
|
|
4
|
+
//
|
|
5
|
+
// Passing the literal `'column'` emitted `x entities show column --json`, which answers
|
|
5
6
|
// `X_DECLARATION_UNKNOWN` — a fix line that raises a second, unrelated error (issue #290).
|
|
6
7
|
//
|
|
7
8
|
// So the fix is a parameter: every caller supplies the EDIT that repairs its own refusal, the
|
package/src/sealed-repo.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// Single responsibility: the ONE seam a sealed column crosses. A repository wrapped here seals the
|
|
2
2
|
// sealed properties of every row and patch on the way in, opens them on the way out, and rewrites
|
|
3
3
|
// or refuses every predicate that names one — so both drivers store ciphertext and neither knows
|
|
4
|
-
// it.
|
|
4
|
+
// it.
|
|
5
|
+
//
|
|
6
|
+
// Both driver factories return through this, which is why the typed handle and a hand-held
|
|
5
7
|
// `postgresRepo()` cannot disagree. An entity with no sealed column gets its repository back as is.
|
|
6
8
|
|
|
7
9
|
import { pageOf } from '@ultimat3/core';
|
package/src/seed.ts
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
// `insert` where the seed owns the id (`id('post:tenancy')` is a v5 uuid of the label, the same on
|
|
4
4
|
// every machine), `upsert` where the table owns it and a natural key is all there is.
|
|
5
5
|
|
|
6
|
-
import { createHash } from 'node:crypto';
|
|
7
6
|
import { type Environment, resolveEnvironment } from '@ultimat3/core';
|
|
8
7
|
import { overwrittenBy } from './bulk-write';
|
|
9
8
|
import { entityNow } from './clock';
|
|
@@ -35,7 +34,7 @@ export const seedId = (label: string): string => {
|
|
|
35
34
|
const input = new Uint8Array(16 + name.length);
|
|
36
35
|
input.set(bytesOf(NAMESPACE));
|
|
37
36
|
input.set(name, 16);
|
|
38
|
-
const digest = new Uint8Array(
|
|
37
|
+
const digest = new Uint8Array(new Bun.CryptoHasher('sha1').update(input).digest());
|
|
39
38
|
const bytes = digest.slice(0, 16);
|
|
40
39
|
bytes[6] = ((bytes[6] ?? 0) & 0x0f) | 0x50;
|
|
41
40
|
bytes[8] = ((bytes[8] ?? 0) & 0x3f) | 0x80;
|
package/src/type-pins.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
// Compile-time pins for the two type positions this package has already regressed in. Source, not
|
|
2
|
-
//
|
|
3
|
-
// test file and a type-level assertion written there can never fail.
|
|
4
|
-
//
|
|
5
|
-
//
|
|
1
|
+
// Compile-time pins for the two type positions this package has already regressed in. Source, not a
|
|
2
|
+
// `.test.ts`, on purpose: `tsconfig.json` excludes `src/**/*.test.ts`, so `tsc -b` never reads a
|
|
3
|
+
// test file and a type-level assertion written there can never fail.
|
|
4
|
+
//
|
|
5
|
+
// Everything below is erased — the module emits nothing — and a regression is a build error, which
|
|
6
|
+
// is the only kind of enforcement this repo counts (axiom 3).
|
|
6
7
|
|
|
7
8
|
import type { Id } from '@ultimat3/core';
|
|
8
9
|
import type { Schema, MoneyValue as SchemaMoneyValue } from '@ultimat3/schema';
|
package/src/write-tag.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
// A keyed write names itself in the write-ahead log.
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
1
|
+
// A keyed write names itself in the write-ahead log.
|
|
2
|
+
//
|
|
3
|
+
// The Postgres driver opens the transaction a keyed request's write lands in with
|
|
4
|
+
// `pg_logical_emit_message(true, WRITE_ORIGIN_WAL_PREFIX, <digest>)`, and `@ultimat3/realtime`'s
|
|
5
|
+
// replication stream names every change after it with that digest — which is how a `records` frame
|
|
6
|
+
// produced by the replicator, in another process, still tells the page that wrote it that this is
|
|
7
|
+
// its own echo. The in-process row observer reads the same fact off the request scope and needs
|
|
8
|
+
// none of this.
|
|
7
9
|
|
|
8
10
|
import { currentWriteOrigin, runToCompletion, WRITE_ORIGIN_WAL_PREFIX } from '@ultimat3/core';
|
|
9
11
|
import { currentTx, type DbClient, type DbTx, db, sql, withTransaction } from '@ultimat3/db';
|