@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 +5 -5
- package/src/driver-errors.ts +10 -9
- package/src/memory-unique.ts +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/entity",
|
|
3
|
-
"version": "31.
|
|
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.
|
|
48
|
-
"@ultimat3/db": "31.
|
|
49
|
-
"@ultimat3/schema": "31.
|
|
50
|
-
"@ultimat3/time": "31.
|
|
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
|
}
|
package/src/driver-errors.ts
CHANGED
|
@@ -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:
|
|
71
|
-
* `
|
|
72
|
-
*
|
|
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
|
-
|
|
76
|
-
code:
|
|
77
|
-
|
|
78
|
-
|
|
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
|
});
|
package/src/memory-unique.ts
CHANGED
|
@@ -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
|
|
16
|
-
* `driver-errors.ts` — the one builder every non-Postgres store raises it with
|
|
17
|
-
*
|
|
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);
|