@ultimat3/entity 31.0.0 → 31.2.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/entity",
3
- "version": "31.0.0",
3
+ "version": "31.2.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.0.0",
48
- "@ultimat3/db": "31.0.0",
49
- "@ultimat3/schema": "31.0.0",
50
- "@ultimat3/time": "31.0.0"
47
+ "@ultimat3/core": "31.2.0",
48
+ "@ultimat3/db": "31.2.0",
49
+ "@ultimat3/schema": "31.2.0",
50
+ "@ultimat3/time": "31.2.0"
51
51
  }
52
52
  }
@@ -4,7 +4,7 @@
4
4
  // `EntityError` has no slot for, so they are `UltimateError`s of their own.
5
5
 
6
6
  import { renderCauseValue, UltimateError } from '@ultimat3/core';
7
- import { DbError } from '@ultimat3/db';
7
+ import { type DbError, driverError, SQLSTATE } from '@ultimat3/db';
8
8
  import type { EntityCore } from './entity';
9
9
  import type { EntityErrorCode } from './entity-error';
10
10
 
@@ -67,14 +67,15 @@ export const driverRowOutOfScope = (
67
67
  });
68
68
 
69
69
  /**
70
- * The refusal a store raises for a duplicate key: `X_DB_UNIQUE_VIOLATION`, the code Postgres'
71
- * `23505` becomes, so a caller catching it reads one code whatever stores the row. No SQLSTATE
72
- * is invented: `sqlState()` answers `undefined`, because no server said anything.
70
+ * The refusal a store raises for a duplicate key: the error Postgres' `23505` becomes, built by the
71
+ * same `driverError` from the same fields a server sends — so `code`, `sqlState()`,
72
+ * `meta.sqlState` and `meta.constraint` read alike whatever stores the row. It used to carry no
73
+ * SQLSTATE ("no server said it"), and every app race handler matching `sqlState(e) === '23505'`
74
+ * passed in production and failed under the memory driver: two answers to one question.
73
75
  */
74
76
  export const entityUniqueViolation = (entity: EntityCore, constraint: string): DbError =>
75
- new DbError({
76
- code: 'X_DB_UNIQUE_VIOLATION',
77
- cause: `a row written into ${entity.$table} repeats the key of constraint ${renderCauseValue(constraint)}`,
78
- fix: `upsertAll(rows, { onConflict: [...] }) over the columns ${constraint} covers — or catch X_DB_UNIQUE_VIOLATION and answer 409, which is what a raced signup is`,
79
- meta: { constraint },
77
+ driverError(`write into ${entity.$table}`, {
78
+ code: SQLSTATE.uniqueViolation,
79
+ constraint,
80
+ message: `duplicate key value violates unique constraint "${constraint}"`,
80
81
  });
@@ -12,9 +12,9 @@ import type { RowPatch } from './types';
12
12
  import { uniqueConstraints } from './unique-constraints';
13
13
 
14
14
  /**
15
- * The refusal Postgres answers `23505` with: `X_DB_UNIQUE_VIOLATION`, the same code, through
16
- * `driver-errors.ts` — the one builder every non-Postgres store raises it with. No SQLSTATE is
17
- * faked: no server said `23505`, so `sqlState()` answers `undefined` here.
15
+ * The refusal Postgres answers `23505` with: `X_DB_UNIQUE_VIOLATION` carrying `23505`, through
16
+ * `driver-errors.ts` — the one builder every non-Postgres store raises it with
17
+ * (`unique-violation-parity.test.ts` holds it equal to the Postgres driver's).
18
18
  */
19
19
  export const uniqueViolation = (entity: EntityCore, constraint: string): Error =>
20
20
  entityUniqueViolation(entity, constraint);