@xfcfam/xf-sql 0.1.0 → 0.1.1
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 +3 -3
- package/dist/src/repository/base/DatabaseRepository.d.ts +0 -184
- package/dist/src/repository/base/DatabaseRepository.d.ts.map +0 -1
- package/dist/src/repository/base/DatabaseRepository.js +0 -216
- package/dist/src/repository/base/DatabaseRepository.js.map +0 -1
- package/dist/src/repository/base/TransactionalDatabaseRepository.d.ts +0 -86
- package/dist/src/repository/base/TransactionalDatabaseRepository.d.ts.map +0 -1
- package/dist/src/repository/base/TransactionalDatabaseRepository.js +0 -104
- package/dist/src/repository/base/TransactionalDatabaseRepository.js.map +0 -1
- package/dist/src/repository/structs/CheckViolationException.d.ts +0 -19
- package/dist/src/repository/structs/CheckViolationException.d.ts.map +0 -1
- package/dist/src/repository/structs/CheckViolationException.js +0 -22
- package/dist/src/repository/structs/CheckViolationException.js.map +0 -1
- package/dist/src/repository/structs/ConnectionException.d.ts +0 -15
- package/dist/src/repository/structs/ConnectionException.d.ts.map +0 -1
- package/dist/src/repository/structs/ConnectionException.js +0 -16
- package/dist/src/repository/structs/ConnectionException.js.map +0 -1
- package/dist/src/repository/structs/DatabaseException.d.ts +0 -14
- package/dist/src/repository/structs/DatabaseException.d.ts.map +0 -1
- package/dist/src/repository/structs/DatabaseException.js +0 -15
- package/dist/src/repository/structs/DatabaseException.js.map +0 -1
- package/dist/src/repository/structs/DeadlockException.d.ts +0 -16
- package/dist/src/repository/structs/DeadlockException.d.ts.map +0 -1
- package/dist/src/repository/structs/DeadlockException.js +0 -17
- package/dist/src/repository/structs/DeadlockException.js.map +0 -1
- package/dist/src/repository/structs/ForeignKeyViolationException.d.ts +0 -20
- package/dist/src/repository/structs/ForeignKeyViolationException.d.ts.map +0 -1
- package/dist/src/repository/structs/ForeignKeyViolationException.js +0 -23
- package/dist/src/repository/structs/ForeignKeyViolationException.js.map +0 -1
- package/dist/src/repository/structs/NotNullViolationException.d.ts +0 -20
- package/dist/src/repository/structs/NotNullViolationException.d.ts.map +0 -1
- package/dist/src/repository/structs/NotNullViolationException.js +0 -23
- package/dist/src/repository/structs/NotNullViolationException.js.map +0 -1
- package/dist/src/repository/structs/UniqueViolationException.d.ts +0 -36
- package/dist/src/repository/structs/UniqueViolationException.d.ts.map +0 -1
- package/dist/src/repository/structs/UniqueViolationException.js +0 -40
- package/dist/src/repository/structs/UniqueViolationException.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xfcfam/xf-sql",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "SQL Access Layer Generalization for the XF Architecture Model — encapsulates the Kysely query builder. Dialect-agnostic; pair with @xfcfam/xf-sql-postgres / @xfcfam/xf-sql-mysql / etc.",
|
|
5
5
|
"author": "XF Contributors",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,14 +33,14 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"kysely": "^0.
|
|
36
|
+
"kysely": "^0.28.17"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"@xfcfam/xf": "^0.2.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"typescript": "^5.4.0",
|
|
43
|
-
"vitest": "^2.
|
|
43
|
+
"vitest": "^3.2.6"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
46
|
"build": "tsc",
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { Repository } from '@xfarch/xf';
|
|
2
|
-
import { Kysely, type Dialect } from 'kysely';
|
|
3
|
-
/**
|
|
4
|
-
* Configuration accepted by {@link DatabaseRepository}'s constructor.
|
|
5
|
-
*
|
|
6
|
-
* The `dialect` is the only required field. Dialect adapter packages
|
|
7
|
-
* such as `@xfarch/xf-sql-postgres` build it for you behind a
|
|
8
|
-
* higher-level options shape.
|
|
9
|
-
*/
|
|
10
|
-
export interface DatabaseOptions {
|
|
11
|
-
/** Kysely Dialect implementation (Postgres, MySQL, SQLite, …). */
|
|
12
|
-
dialect: Dialect;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Base Generalization for the Access Layer when the underlying
|
|
16
|
-
* external system is a SQL database.
|
|
17
|
-
*
|
|
18
|
-
* Encapsulates the [Kysely](https://kysely.dev) query builder behind
|
|
19
|
-
* a single XF-canonical class. The implementer's concrete Logical
|
|
20
|
-
* extends this (or a dialect-specific subclass such as
|
|
21
|
-
* `PostgresDatabaseRepository`) and exposes domain-meaningful methods
|
|
22
|
-
* that compose queries against `this.db`, a `Kysely<Schema>` bound
|
|
23
|
-
* to the implementer's typed schema.
|
|
24
|
-
*
|
|
25
|
-
* Concrete dialect support lives in adapter packages — install one of
|
|
26
|
-
* `@xfarch/xf-sql-postgres`, `@xfarch/xf-sql-mysql`, etc., or supply
|
|
27
|
-
* any Kysely-compatible `Dialect` directly.
|
|
28
|
-
*
|
|
29
|
-
* ──────────────────────────────────────────────────────────────────
|
|
30
|
-
* IMPORTANT — Required configuration for subclasses
|
|
31
|
-
* ──────────────────────────────────────────────────────────────────
|
|
32
|
-
* The underlying Kysely instance is held in a static private WeakMap
|
|
33
|
-
* and created inside {@link init}. If a subclass overrides `init()` /
|
|
34
|
-
* `terminate()`, it MUST chain through `super`:
|
|
35
|
-
*
|
|
36
|
-
* async init() { await super.init(); // own setup }
|
|
37
|
-
* async terminate() { // own teardown; await super.terminate() }
|
|
38
|
-
*
|
|
39
|
-
* Forgetting `super.init()` leaves `this.db` uninitialised and every
|
|
40
|
-
* query will throw {@link NotInitializedException}.
|
|
41
|
-
*
|
|
42
|
-
* ──────────────────────────────────────────────────────────────────
|
|
43
|
-
* Overridable observation hooks
|
|
44
|
-
* ──────────────────────────────────────────────────────────────────
|
|
45
|
-
* - {@link onConnected} ← after `init()` creates the Kysely instance
|
|
46
|
-
* - {@link onDisconnected} ← after `terminate()` destroys it
|
|
47
|
-
* - {@link onQuery} ← for every query Kysely executes
|
|
48
|
-
* - {@link onError} ← for every {@link exec}-wrapped operation that rejects
|
|
49
|
-
*
|
|
50
|
-
* Transaction hooks ({@link onTransactionStart} / Commit / Rollback)
|
|
51
|
-
* live on {@link TransactionalDatabaseRepository}, the subclass that
|
|
52
|
-
* exposes explicit transaction control.
|
|
53
|
-
*
|
|
54
|
-
* ──────────────────────────────────────────────────────────────────
|
|
55
|
-
* Error translation
|
|
56
|
-
* ──────────────────────────────────────────────────────────────────
|
|
57
|
-
* Dialect-specific errors (driver Error objects) are not translated
|
|
58
|
-
* by this class — it does not know about Postgres SQLSTATEs, MySQL
|
|
59
|
-
* error numbers, etc. Use a dialect adapter subclass (such as
|
|
60
|
-
* `PostgresDatabaseRepository`) or override {@link translateError}
|
|
61
|
-
* yourself to map errors to the typed Exceptions exported from this
|
|
62
|
-
* package (`UniqueViolationException`, etc.).
|
|
63
|
-
*
|
|
64
|
-
* @typeParam Schema Implementer-defined TypeScript interface mapping
|
|
65
|
-
* table names to their column shapes. See the
|
|
66
|
-
* Kysely docs for the conventions on
|
|
67
|
-
* `Generated`, `ColumnType`, etc.
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* ```ts
|
|
71
|
-
* import { DatabaseRepository } from '@xfarch/xf-sql'
|
|
72
|
-
* import { PostgresDialect } from 'kysely'
|
|
73
|
-
* import { Pool } from 'pg'
|
|
74
|
-
*
|
|
75
|
-
* interface Schema {
|
|
76
|
-
* users: { id: number; name: string; email: string }
|
|
77
|
-
* }
|
|
78
|
-
*
|
|
79
|
-
* export class UsersDb extends DatabaseRepository<Schema> {
|
|
80
|
-
* constructor() {
|
|
81
|
-
* super({
|
|
82
|
-
* dialect: new PostgresDialect({
|
|
83
|
-
* pool: new Pool({ connectionString: process.env.DATABASE_URL }),
|
|
84
|
-
* }),
|
|
85
|
-
* })
|
|
86
|
-
* }
|
|
87
|
-
* async init() { await super.init() }
|
|
88
|
-
* async terminate() { await super.terminate() }
|
|
89
|
-
*
|
|
90
|
-
* getUser(id: number) {
|
|
91
|
-
* return this.db
|
|
92
|
-
* .selectFrom('users')
|
|
93
|
-
* .where('id', '=', id)
|
|
94
|
-
* .selectAll()
|
|
95
|
-
* .executeTakeFirstOrThrow()
|
|
96
|
-
* }
|
|
97
|
-
* }
|
|
98
|
-
* ```
|
|
99
|
-
*/
|
|
100
|
-
export declare abstract class DatabaseRepository<Schema = unknown> extends Repository<null> {
|
|
101
|
-
private static readonly state;
|
|
102
|
-
/** Options provided at construction time. */
|
|
103
|
-
protected readonly options: DatabaseOptions;
|
|
104
|
-
constructor(options: DatabaseOptions);
|
|
105
|
-
/**
|
|
106
|
-
* Typed Kysely instance bound to `Schema`. Use it to compose queries:
|
|
107
|
-
* `this.db.selectFrom('users')…`, `this.db.insertInto('users')…`.
|
|
108
|
-
* Throws if {@link init} has not been called.
|
|
109
|
-
*/
|
|
110
|
-
protected get db(): Kysely<Schema>;
|
|
111
|
-
/**
|
|
112
|
-
* Subclasses that override this method MUST call `await super.init()`
|
|
113
|
-
* **first**; otherwise {@link db} will throw on use.
|
|
114
|
-
*/
|
|
115
|
-
init(): Promise<void>;
|
|
116
|
-
/**
|
|
117
|
-
* Subclasses that override this method MUST call `await super.terminate()`
|
|
118
|
-
* **last** to release the connection pool held by the Kysely instance.
|
|
119
|
-
*/
|
|
120
|
-
terminate(): Promise<void>;
|
|
121
|
-
/**
|
|
122
|
-
* Hook for dialect-specific error translation. Default
|
|
123
|
-
* implementation is identity (returns the input unchanged).
|
|
124
|
-
*
|
|
125
|
-
* Dialect adapter subclasses (such as `PostgresDatabaseRepository`)
|
|
126
|
-
* override this to map driver errors to the typed Exceptions
|
|
127
|
-
* exported from this package.
|
|
128
|
-
*
|
|
129
|
-
* Called automatically by {@link exec}; not called for direct
|
|
130
|
-
* `this.db.…` usage, where the implementer is responsible for
|
|
131
|
-
* wrapping queries in `this.exec(...)`.
|
|
132
|
-
*/
|
|
133
|
-
protected translateError(err: unknown): unknown;
|
|
134
|
-
/**
|
|
135
|
-
* Execute an operation against the database, translating any
|
|
136
|
-
* dialect-specific errors to xf-sql Exception types via
|
|
137
|
-
* {@link translateError}.
|
|
138
|
-
*
|
|
139
|
-
* Use this whenever you need automatic error translation. For raw
|
|
140
|
-
* Kysely access without translation, use {@link db} directly.
|
|
141
|
-
*
|
|
142
|
-
* @example
|
|
143
|
-
* ```ts
|
|
144
|
-
* async createUser(input: UserInput) {
|
|
145
|
-
* return this.exec(() =>
|
|
146
|
-
* this.db.insertInto('users').values(input).returningAll().executeTakeFirstOrThrow()
|
|
147
|
-
* )
|
|
148
|
-
* }
|
|
149
|
-
* ```
|
|
150
|
-
*/
|
|
151
|
-
protected exec<R>(op: () => Promise<R>): Promise<R>;
|
|
152
|
-
/**
|
|
153
|
-
* Invoked after `init()` has created the Kysely instance. Default
|
|
154
|
-
* no-op. Override for connection-open telemetry, schema migrations,
|
|
155
|
-
* connection warmup, etc.
|
|
156
|
-
*/
|
|
157
|
-
protected onConnected(): Promise<void>;
|
|
158
|
-
/**
|
|
159
|
-
* Invoked after `terminate()` has destroyed the Kysely instance.
|
|
160
|
-
* Default no-op. Override for connection-close telemetry.
|
|
161
|
-
*/
|
|
162
|
-
protected onDisconnected(): Promise<void>;
|
|
163
|
-
/**
|
|
164
|
-
* Invoked for every query Kysely executes (both standalone and
|
|
165
|
-
* inside transactions). Receives the compiled SQL and the bound
|
|
166
|
-
* parameters. Default no-op.
|
|
167
|
-
*
|
|
168
|
-
* Use for audit logging or query profiling. The hook runs
|
|
169
|
-
* synchronously inside Kysely's pipeline — keep it cheap and avoid
|
|
170
|
-
* blocking work.
|
|
171
|
-
*/
|
|
172
|
-
protected onQuery(_sql: string, _params: readonly unknown[]): void;
|
|
173
|
-
/**
|
|
174
|
-
* Invoked when an `exec()`-wrapped operation rejects, or when
|
|
175
|
-
* Kysely emits a query-level error. The `operation` label
|
|
176
|
-
* distinguishes the source (`'exec'`, `'query'`, or the value
|
|
177
|
-
* supplied by a subclass). Default no-op.
|
|
178
|
-
*
|
|
179
|
-
* The hook fires before {@link translateError}; the (possibly
|
|
180
|
-
* untranslated) error is still re-thrown to the caller.
|
|
181
|
-
*/
|
|
182
|
-
protected onError(_operation: string, _error: unknown): void;
|
|
183
|
-
}
|
|
184
|
-
//# sourceMappingURL=DatabaseRepository.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DatabaseRepository.d.ts","sourceRoot":"","sources":["../../../../src/repository/base/DatabaseRepository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA2B,MAAM,YAAY,CAAA;AAChE,OAAO,EAAE,MAAM,EAAE,KAAK,OAAO,EAAE,MAAM,QAAQ,CAAA;AAE7C;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC9B,kEAAkE;IAClE,OAAO,EAAE,OAAO,CAAA;CACjB;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqFG;AACH,8BAAsB,kBAAkB,CAAC,MAAM,GAAG,OAAO,CAAE,SAAQ,UAAU,CAAC,IAAI,CAAC;IACjF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAuC;IAEpE,6CAA6C;IAC7C,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAA;gBAE/B,OAAO,EAAE,eAAe;IAKpC;;;;OAIG;IACH,SAAS,KAAK,EAAE,IAAI,MAAM,CAAC,MAAM,CAAC,CAMjC;IAED;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAiB3B;;;OAGG;IACG,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAShC;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO;IAI/C;;;;;;;;;;;;;;;;OAgBG;cACa,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAWzD;;;;OAIG;cACa,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAE5C;;;OAGG;cACa,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAE/C;;;;;;;;OAQG;IACH,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,OAAO,EAAE,GAAG,IAAI;IAElE;;;;;;;;OAQG;IACH,SAAS,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI;CAC7D"}
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
import { Repository, NotInitializedException } from '@xfarch/xf';
|
|
2
|
-
import { Kysely } from 'kysely';
|
|
3
|
-
/**
|
|
4
|
-
* Base Generalization for the Access Layer when the underlying
|
|
5
|
-
* external system is a SQL database.
|
|
6
|
-
*
|
|
7
|
-
* Encapsulates the [Kysely](https://kysely.dev) query builder behind
|
|
8
|
-
* a single XF-canonical class. The implementer's concrete Logical
|
|
9
|
-
* extends this (or a dialect-specific subclass such as
|
|
10
|
-
* `PostgresDatabaseRepository`) and exposes domain-meaningful methods
|
|
11
|
-
* that compose queries against `this.db`, a `Kysely<Schema>` bound
|
|
12
|
-
* to the implementer's typed schema.
|
|
13
|
-
*
|
|
14
|
-
* Concrete dialect support lives in adapter packages — install one of
|
|
15
|
-
* `@xfarch/xf-sql-postgres`, `@xfarch/xf-sql-mysql`, etc., or supply
|
|
16
|
-
* any Kysely-compatible `Dialect` directly.
|
|
17
|
-
*
|
|
18
|
-
* ──────────────────────────────────────────────────────────────────
|
|
19
|
-
* IMPORTANT — Required configuration for subclasses
|
|
20
|
-
* ──────────────────────────────────────────────────────────────────
|
|
21
|
-
* The underlying Kysely instance is held in a static private WeakMap
|
|
22
|
-
* and created inside {@link init}. If a subclass overrides `init()` /
|
|
23
|
-
* `terminate()`, it MUST chain through `super`:
|
|
24
|
-
*
|
|
25
|
-
* async init() { await super.init(); // own setup }
|
|
26
|
-
* async terminate() { // own teardown; await super.terminate() }
|
|
27
|
-
*
|
|
28
|
-
* Forgetting `super.init()` leaves `this.db` uninitialised and every
|
|
29
|
-
* query will throw {@link NotInitializedException}.
|
|
30
|
-
*
|
|
31
|
-
* ──────────────────────────────────────────────────────────────────
|
|
32
|
-
* Overridable observation hooks
|
|
33
|
-
* ──────────────────────────────────────────────────────────────────
|
|
34
|
-
* - {@link onConnected} ← after `init()` creates the Kysely instance
|
|
35
|
-
* - {@link onDisconnected} ← after `terminate()` destroys it
|
|
36
|
-
* - {@link onQuery} ← for every query Kysely executes
|
|
37
|
-
* - {@link onError} ← for every {@link exec}-wrapped operation that rejects
|
|
38
|
-
*
|
|
39
|
-
* Transaction hooks ({@link onTransactionStart} / Commit / Rollback)
|
|
40
|
-
* live on {@link TransactionalDatabaseRepository}, the subclass that
|
|
41
|
-
* exposes explicit transaction control.
|
|
42
|
-
*
|
|
43
|
-
* ──────────────────────────────────────────────────────────────────
|
|
44
|
-
* Error translation
|
|
45
|
-
* ──────────────────────────────────────────────────────────────────
|
|
46
|
-
* Dialect-specific errors (driver Error objects) are not translated
|
|
47
|
-
* by this class — it does not know about Postgres SQLSTATEs, MySQL
|
|
48
|
-
* error numbers, etc. Use a dialect adapter subclass (such as
|
|
49
|
-
* `PostgresDatabaseRepository`) or override {@link translateError}
|
|
50
|
-
* yourself to map errors to the typed Exceptions exported from this
|
|
51
|
-
* package (`UniqueViolationException`, etc.).
|
|
52
|
-
*
|
|
53
|
-
* @typeParam Schema Implementer-defined TypeScript interface mapping
|
|
54
|
-
* table names to their column shapes. See the
|
|
55
|
-
* Kysely docs for the conventions on
|
|
56
|
-
* `Generated`, `ColumnType`, etc.
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
* ```ts
|
|
60
|
-
* import { DatabaseRepository } from '@xfarch/xf-sql'
|
|
61
|
-
* import { PostgresDialect } from 'kysely'
|
|
62
|
-
* import { Pool } from 'pg'
|
|
63
|
-
*
|
|
64
|
-
* interface Schema {
|
|
65
|
-
* users: { id: number; name: string; email: string }
|
|
66
|
-
* }
|
|
67
|
-
*
|
|
68
|
-
* export class UsersDb extends DatabaseRepository<Schema> {
|
|
69
|
-
* constructor() {
|
|
70
|
-
* super({
|
|
71
|
-
* dialect: new PostgresDialect({
|
|
72
|
-
* pool: new Pool({ connectionString: process.env.DATABASE_URL }),
|
|
73
|
-
* }),
|
|
74
|
-
* })
|
|
75
|
-
* }
|
|
76
|
-
* async init() { await super.init() }
|
|
77
|
-
* async terminate() { await super.terminate() }
|
|
78
|
-
*
|
|
79
|
-
* getUser(id: number) {
|
|
80
|
-
* return this.db
|
|
81
|
-
* .selectFrom('users')
|
|
82
|
-
* .where('id', '=', id)
|
|
83
|
-
* .selectAll()
|
|
84
|
-
* .executeTakeFirstOrThrow()
|
|
85
|
-
* }
|
|
86
|
-
* }
|
|
87
|
-
* ```
|
|
88
|
-
*/
|
|
89
|
-
export class DatabaseRepository extends Repository {
|
|
90
|
-
static state = new WeakMap();
|
|
91
|
-
/** Options provided at construction time. */
|
|
92
|
-
options;
|
|
93
|
-
constructor(options) {
|
|
94
|
-
super(null);
|
|
95
|
-
this.options = options;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Typed Kysely instance bound to `Schema`. Use it to compose queries:
|
|
99
|
-
* `this.db.selectFrom('users')…`, `this.db.insertInto('users')…`.
|
|
100
|
-
* Throws if {@link init} has not been called.
|
|
101
|
-
*/
|
|
102
|
-
get db() {
|
|
103
|
-
const s = DatabaseRepository.state.get(this);
|
|
104
|
-
if (s === undefined) {
|
|
105
|
-
throw new NotInitializedException('DatabaseRepository: init() was not called (or super.init() was skipped)');
|
|
106
|
-
}
|
|
107
|
-
return s.db;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Subclasses that override this method MUST call `await super.init()`
|
|
111
|
-
* **first**; otherwise {@link db} will throw on use.
|
|
112
|
-
*/
|
|
113
|
-
async init() {
|
|
114
|
-
const db = new Kysely({
|
|
115
|
-
dialect: this.options.dialect,
|
|
116
|
-
log: (event) => {
|
|
117
|
-
if (event.level === 'query') {
|
|
118
|
-
this.onQuery(event.query.sql, event.query.parameters);
|
|
119
|
-
}
|
|
120
|
-
else if (event.level === 'error') {
|
|
121
|
-
// Kysely-emitted query errors are also routed through onError
|
|
122
|
-
// for symmetry with exec() failures.
|
|
123
|
-
this.onError('query', event.error);
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
});
|
|
127
|
-
DatabaseRepository.state.set(this, { db });
|
|
128
|
-
await this.onConnected();
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Subclasses that override this method MUST call `await super.terminate()`
|
|
132
|
-
* **last** to release the connection pool held by the Kysely instance.
|
|
133
|
-
*/
|
|
134
|
-
async terminate() {
|
|
135
|
-
const s = DatabaseRepository.state.get(this);
|
|
136
|
-
if (s !== undefined) {
|
|
137
|
-
await s.db.destroy();
|
|
138
|
-
DatabaseRepository.state.delete(this);
|
|
139
|
-
await this.onDisconnected();
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Hook for dialect-specific error translation. Default
|
|
144
|
-
* implementation is identity (returns the input unchanged).
|
|
145
|
-
*
|
|
146
|
-
* Dialect adapter subclasses (such as `PostgresDatabaseRepository`)
|
|
147
|
-
* override this to map driver errors to the typed Exceptions
|
|
148
|
-
* exported from this package.
|
|
149
|
-
*
|
|
150
|
-
* Called automatically by {@link exec}; not called for direct
|
|
151
|
-
* `this.db.…` usage, where the implementer is responsible for
|
|
152
|
-
* wrapping queries in `this.exec(...)`.
|
|
153
|
-
*/
|
|
154
|
-
translateError(err) {
|
|
155
|
-
return err;
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Execute an operation against the database, translating any
|
|
159
|
-
* dialect-specific errors to xf-sql Exception types via
|
|
160
|
-
* {@link translateError}.
|
|
161
|
-
*
|
|
162
|
-
* Use this whenever you need automatic error translation. For raw
|
|
163
|
-
* Kysely access without translation, use {@link db} directly.
|
|
164
|
-
*
|
|
165
|
-
* @example
|
|
166
|
-
* ```ts
|
|
167
|
-
* async createUser(input: UserInput) {
|
|
168
|
-
* return this.exec(() =>
|
|
169
|
-
* this.db.insertInto('users').values(input).returningAll().executeTakeFirstOrThrow()
|
|
170
|
-
* )
|
|
171
|
-
* }
|
|
172
|
-
* ```
|
|
173
|
-
*/
|
|
174
|
-
async exec(op) {
|
|
175
|
-
try {
|
|
176
|
-
return await op();
|
|
177
|
-
}
|
|
178
|
-
catch (err) {
|
|
179
|
-
this.onError('exec', err);
|
|
180
|
-
throw this.translateError(err);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
// ─── Overridable observation hooks ────────────────────────
|
|
184
|
-
/**
|
|
185
|
-
* Invoked after `init()` has created the Kysely instance. Default
|
|
186
|
-
* no-op. Override for connection-open telemetry, schema migrations,
|
|
187
|
-
* connection warmup, etc.
|
|
188
|
-
*/
|
|
189
|
-
async onConnected() { }
|
|
190
|
-
/**
|
|
191
|
-
* Invoked after `terminate()` has destroyed the Kysely instance.
|
|
192
|
-
* Default no-op. Override for connection-close telemetry.
|
|
193
|
-
*/
|
|
194
|
-
async onDisconnected() { }
|
|
195
|
-
/**
|
|
196
|
-
* Invoked for every query Kysely executes (both standalone and
|
|
197
|
-
* inside transactions). Receives the compiled SQL and the bound
|
|
198
|
-
* parameters. Default no-op.
|
|
199
|
-
*
|
|
200
|
-
* Use for audit logging or query profiling. The hook runs
|
|
201
|
-
* synchronously inside Kysely's pipeline — keep it cheap and avoid
|
|
202
|
-
* blocking work.
|
|
203
|
-
*/
|
|
204
|
-
onQuery(_sql, _params) { }
|
|
205
|
-
/**
|
|
206
|
-
* Invoked when an `exec()`-wrapped operation rejects, or when
|
|
207
|
-
* Kysely emits a query-level error. The `operation` label
|
|
208
|
-
* distinguishes the source (`'exec'`, `'query'`, or the value
|
|
209
|
-
* supplied by a subclass). Default no-op.
|
|
210
|
-
*
|
|
211
|
-
* The hook fires before {@link translateError}; the (possibly
|
|
212
|
-
* untranslated) error is still re-thrown to the caller.
|
|
213
|
-
*/
|
|
214
|
-
onError(_operation, _error) { }
|
|
215
|
-
}
|
|
216
|
-
//# sourceMappingURL=DatabaseRepository.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DatabaseRepository.js","sourceRoot":"","sources":["../../../../src/repository/base/DatabaseRepository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAA;AAChE,OAAO,EAAE,MAAM,EAAgB,MAAM,QAAQ,CAAA;AAkB7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqFG;AACH,MAAM,OAAgB,kBAAqC,SAAQ,UAAgB;IACzE,MAAM,CAAU,KAAK,GAAG,IAAI,OAAO,EAAyB,CAAA;IAEpE,6CAA6C;IAC1B,OAAO,CAAiB;IAE3C,YAAY,OAAwB;QAClC,KAAK,CAAC,IAAI,CAAC,CAAA;QACX,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED;;;;OAIG;IACH,IAAc,EAAE;QACd,MAAM,CAAC,GAAG,kBAAkB,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QAC5C,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC;YACpB,MAAM,IAAI,uBAAuB,CAAC,yEAAyE,CAAC,CAAA;QAC9G,CAAC;QACD,OAAO,CAAC,CAAC,EAAoB,CAAA;IAC/B,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,IAAI;QACR,MAAM,EAAE,GAAG,IAAI,MAAM,CAAS;YAC5B,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO;YAC7B,GAAG,EAAE,CAAC,KAAK,EAAE,EAAE;gBACb,IAAI,KAAK,CAAC,KAAK,KAAK,OAAO,EAAE,CAAC;oBAC5B,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;gBACvD,CAAC;qBAAM,IAAI,KAAK,CAAC,KAAK,KAAK,OAAO,EAAE,CAAC;oBACnC,8DAA8D;oBAC9D,qCAAqC;oBACrC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,CAAA;gBACpC,CAAC;YACH,CAAC;SACF,CAAC,CAAA;QACF,kBAAkB,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,CAAA;QAC1C,MAAM,IAAI,CAAC,WAAW,EAAE,CAAA;IAC1B,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,SAAS;QACb,MAAM,CAAC,GAAG,kBAAkB,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QAC5C,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC;YACpB,MAAM,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,CAAA;YACpB,kBAAkB,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;YACrC,MAAM,IAAI,CAAC,cAAc,EAAE,CAAA;QAC7B,CAAC;IACH,CAAC;IAED;;;;;;;;;;;OAWG;IACO,cAAc,CAAC,GAAY;QACnC,OAAO,GAAG,CAAA;IACZ,CAAC;IAED;;;;;;;;;;;;;;;;OAgBG;IACO,KAAK,CAAC,IAAI,CAAI,EAAoB;QAC1C,IAAI,CAAC;YACH,OAAO,MAAM,EAAE,EAAE,CAAA;QACnB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;YACzB,MAAM,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAA;QAChC,CAAC;IACH,CAAC;IAED,6DAA6D;IAE7D;;;;OAIG;IACO,KAAK,CAAC,WAAW,KAAmB,CAAC;IAE/C;;;OAGG;IACO,KAAK,CAAC,cAAc,KAAmB,CAAC;IAElD;;;;;;;;OAQG;IACO,OAAO,CAAC,IAAY,EAAE,OAA2B,IAAS,CAAC;IAErE;;;;;;;;OAQG;IACO,OAAO,CAAC,UAAkB,EAAE,MAAe,IAAS,CAAC"}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { type Transaction } from 'kysely';
|
|
2
|
-
import { DatabaseRepository } from './DatabaseRepository.js';
|
|
3
|
-
/**
|
|
4
|
-
* Generalization for SQL Access Layer components that need explicit
|
|
5
|
-
* transaction control on top of {@link DatabaseRepository}.
|
|
6
|
-
*
|
|
7
|
-
* Extends `DatabaseRepository<Schema>` and adds {@link transaction},
|
|
8
|
-
* a helper that runs a callback inside a Kysely transaction:
|
|
9
|
-
* commits on success, rolls back on throw.
|
|
10
|
-
*
|
|
11
|
-
* Error translation flows through {@link DatabaseRepository.translateError}
|
|
12
|
-
* — overriding it once on a dialect subclass covers both `exec` and
|
|
13
|
-
* `transaction`.
|
|
14
|
-
*
|
|
15
|
-
* ──────────────────────────────────────────────────────────────────
|
|
16
|
-
* Overridable transaction hooks
|
|
17
|
-
* ──────────────────────────────────────────────────────────────────
|
|
18
|
-
* - {@link onTransactionStart} ← before the callback runs
|
|
19
|
-
* - {@link onTransactionCommit} ← after the callback resolves
|
|
20
|
-
* - {@link onTransactionRollback} ← when the callback throws
|
|
21
|
-
*
|
|
22
|
-
* Each hook receives a `txId` — a short opaque identifier that
|
|
23
|
-
* correlates the three events of the same transaction. The id is
|
|
24
|
-
* generated per-call and has no meaning to the database (it's a
|
|
25
|
-
* sibling of telemetry trace ids, not of SQL `SAVEPOINT` names).
|
|
26
|
-
*
|
|
27
|
-
* @typeParam Schema See {@link DatabaseRepository}.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```ts
|
|
31
|
-
* import { TransactionalDatabaseRepository } from '@xfarch/xf-sql'
|
|
32
|
-
*
|
|
33
|
-
* export class OrdersDb extends TransactionalDatabaseRepository<Schema> {
|
|
34
|
-
* constructor() { super({ dialect: ... }) }
|
|
35
|
-
* async init() { await super.init() }
|
|
36
|
-
* async terminate() { await super.terminate() }
|
|
37
|
-
*
|
|
38
|
-
* async checkout(order: Order) {
|
|
39
|
-
* return this.transaction(async (trx) => {
|
|
40
|
-
* await trx.insertInto('orders').values(order).execute()
|
|
41
|
-
* await trx.updateTable('inventory')
|
|
42
|
-
* .set((eb) => ({ stock: eb('stock', '-', order.qty) }))
|
|
43
|
-
* .where('sku', '=', order.sku)
|
|
44
|
-
* .execute()
|
|
45
|
-
* return order.id
|
|
46
|
-
* })
|
|
47
|
-
* }
|
|
48
|
-
* }
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
export declare abstract class TransactionalDatabaseRepository<Schema = unknown> extends DatabaseRepository<Schema> {
|
|
52
|
-
/**
|
|
53
|
-
* Run `callback` inside a database transaction. Commits if the
|
|
54
|
-
* callback resolves; rolls back if it throws.
|
|
55
|
-
*
|
|
56
|
-
* The argument passed to `callback` is a `Transaction<Schema>` —
|
|
57
|
-
* a Kysely-typed transaction handle. Use it (not `this.db`) for
|
|
58
|
-
* queries inside the transaction so they participate in the same
|
|
59
|
-
* unit of work.
|
|
60
|
-
*
|
|
61
|
-
* Errors thrown inside the callback are translated through
|
|
62
|
-
* {@link DatabaseRepository.translateError} before being rethrown.
|
|
63
|
-
*/
|
|
64
|
-
protected transaction<R>(callback: (trx: Transaction<Schema>) => Promise<R>): Promise<R>;
|
|
65
|
-
/**
|
|
66
|
-
* Invoked just before the transaction callback runs. Default no-op.
|
|
67
|
-
* `txId` is a short opaque identifier that correlates the three
|
|
68
|
-
* events of the same transaction.
|
|
69
|
-
*/
|
|
70
|
-
protected onTransactionStart(_txId: string): void;
|
|
71
|
-
/**
|
|
72
|
-
* Invoked after the transaction callback resolves successfully and
|
|
73
|
-
* the commit completes. `durationMs` measures the full lifetime of
|
|
74
|
-
* the transaction (including commit latency). Default no-op.
|
|
75
|
-
*/
|
|
76
|
-
protected onTransactionCommit(_txId: string, _durationMs: number): void;
|
|
77
|
-
/**
|
|
78
|
-
* Invoked when the transaction callback throws and the rollback
|
|
79
|
-
* completes. `reason` is the original error (before
|
|
80
|
-
* {@link DatabaseRepository.translateError} is applied to the
|
|
81
|
-
* rethrow). Default no-op.
|
|
82
|
-
*/
|
|
83
|
-
protected onTransactionRollback(_txId: string, _reason: unknown): void;
|
|
84
|
-
private static makeTxId;
|
|
85
|
-
}
|
|
86
|
-
//# sourceMappingURL=TransactionalDatabaseRepository.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionalDatabaseRepository.d.ts","sourceRoot":"","sources":["../../../../src/repository/base/TransactionalDatabaseRepository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,QAAQ,CAAA;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAE5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,8BAAsB,+BAA+B,CAAC,MAAM,GAAG,OAAO,CACpE,SAAQ,kBAAkB,CAAC,MAAM,CAAC;IAElC;;;;;;;;;;;OAWG;cACa,WAAW,CAAC,CAAC,EAC3B,QAAQ,EAAE,CAAC,GAAG,EAAE,WAAW,CAAC,MAAM,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GACjD,OAAO,CAAC,CAAC,CAAC;IAgBb;;;;OAIG;IACH,SAAS,CAAC,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAEjD;;;;OAIG;IACH,SAAS,CAAC,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI;IAEvE;;;;;OAKG;IACH,SAAS,CAAC,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;IAItE,OAAO,CAAC,MAAM,CAAC,QAAQ;CAKxB"}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { DatabaseRepository } from './DatabaseRepository.js';
|
|
2
|
-
/**
|
|
3
|
-
* Generalization for SQL Access Layer components that need explicit
|
|
4
|
-
* transaction control on top of {@link DatabaseRepository}.
|
|
5
|
-
*
|
|
6
|
-
* Extends `DatabaseRepository<Schema>` and adds {@link transaction},
|
|
7
|
-
* a helper that runs a callback inside a Kysely transaction:
|
|
8
|
-
* commits on success, rolls back on throw.
|
|
9
|
-
*
|
|
10
|
-
* Error translation flows through {@link DatabaseRepository.translateError}
|
|
11
|
-
* — overriding it once on a dialect subclass covers both `exec` and
|
|
12
|
-
* `transaction`.
|
|
13
|
-
*
|
|
14
|
-
* ──────────────────────────────────────────────────────────────────
|
|
15
|
-
* Overridable transaction hooks
|
|
16
|
-
* ──────────────────────────────────────────────────────────────────
|
|
17
|
-
* - {@link onTransactionStart} ← before the callback runs
|
|
18
|
-
* - {@link onTransactionCommit} ← after the callback resolves
|
|
19
|
-
* - {@link onTransactionRollback} ← when the callback throws
|
|
20
|
-
*
|
|
21
|
-
* Each hook receives a `txId` — a short opaque identifier that
|
|
22
|
-
* correlates the three events of the same transaction. The id is
|
|
23
|
-
* generated per-call and has no meaning to the database (it's a
|
|
24
|
-
* sibling of telemetry trace ids, not of SQL `SAVEPOINT` names).
|
|
25
|
-
*
|
|
26
|
-
* @typeParam Schema See {@link DatabaseRepository}.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```ts
|
|
30
|
-
* import { TransactionalDatabaseRepository } from '@xfarch/xf-sql'
|
|
31
|
-
*
|
|
32
|
-
* export class OrdersDb extends TransactionalDatabaseRepository<Schema> {
|
|
33
|
-
* constructor() { super({ dialect: ... }) }
|
|
34
|
-
* async init() { await super.init() }
|
|
35
|
-
* async terminate() { await super.terminate() }
|
|
36
|
-
*
|
|
37
|
-
* async checkout(order: Order) {
|
|
38
|
-
* return this.transaction(async (trx) => {
|
|
39
|
-
* await trx.insertInto('orders').values(order).execute()
|
|
40
|
-
* await trx.updateTable('inventory')
|
|
41
|
-
* .set((eb) => ({ stock: eb('stock', '-', order.qty) }))
|
|
42
|
-
* .where('sku', '=', order.sku)
|
|
43
|
-
* .execute()
|
|
44
|
-
* return order.id
|
|
45
|
-
* })
|
|
46
|
-
* }
|
|
47
|
-
* }
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
export class TransactionalDatabaseRepository extends DatabaseRepository {
|
|
51
|
-
/**
|
|
52
|
-
* Run `callback` inside a database transaction. Commits if the
|
|
53
|
-
* callback resolves; rolls back if it throws.
|
|
54
|
-
*
|
|
55
|
-
* The argument passed to `callback` is a `Transaction<Schema>` —
|
|
56
|
-
* a Kysely-typed transaction handle. Use it (not `this.db`) for
|
|
57
|
-
* queries inside the transaction so they participate in the same
|
|
58
|
-
* unit of work.
|
|
59
|
-
*
|
|
60
|
-
* Errors thrown inside the callback are translated through
|
|
61
|
-
* {@link DatabaseRepository.translateError} before being rethrown.
|
|
62
|
-
*/
|
|
63
|
-
async transaction(callback) {
|
|
64
|
-
const txId = TransactionalDatabaseRepository.makeTxId();
|
|
65
|
-
const startedAt = Date.now();
|
|
66
|
-
this.onTransactionStart(txId);
|
|
67
|
-
try {
|
|
68
|
-
const result = await this.db.transaction().execute(callback);
|
|
69
|
-
this.onTransactionCommit(txId, Date.now() - startedAt);
|
|
70
|
-
return result;
|
|
71
|
-
}
|
|
72
|
-
catch (err) {
|
|
73
|
-
this.onTransactionRollback(txId, err);
|
|
74
|
-
throw this.translateError(err);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
// ─── Overridable transaction hooks ────────────────────────
|
|
78
|
-
/**
|
|
79
|
-
* Invoked just before the transaction callback runs. Default no-op.
|
|
80
|
-
* `txId` is a short opaque identifier that correlates the three
|
|
81
|
-
* events of the same transaction.
|
|
82
|
-
*/
|
|
83
|
-
onTransactionStart(_txId) { }
|
|
84
|
-
/**
|
|
85
|
-
* Invoked after the transaction callback resolves successfully and
|
|
86
|
-
* the commit completes. `durationMs` measures the full lifetime of
|
|
87
|
-
* the transaction (including commit latency). Default no-op.
|
|
88
|
-
*/
|
|
89
|
-
onTransactionCommit(_txId, _durationMs) { }
|
|
90
|
-
/**
|
|
91
|
-
* Invoked when the transaction callback throws and the rollback
|
|
92
|
-
* completes. `reason` is the original error (before
|
|
93
|
-
* {@link DatabaseRepository.translateError} is applied to the
|
|
94
|
-
* rethrow). Default no-op.
|
|
95
|
-
*/
|
|
96
|
-
onTransactionRollback(_txId, _reason) { }
|
|
97
|
-
// ─── Internals ────────────────────────────────────────────
|
|
98
|
-
static makeTxId() {
|
|
99
|
-
const t = Date.now().toString(36);
|
|
100
|
-
const r = Math.floor(Math.random() * 0x100000).toString(36).padStart(4, '0');
|
|
101
|
-
return `tx-${t}-${r}`;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
//# sourceMappingURL=TransactionalDatabaseRepository.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionalDatabaseRepository.js","sourceRoot":"","sources":["../../../../src/repository/base/TransactionalDatabaseRepository.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAE5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,MAAM,OAAgB,+BACpB,SAAQ,kBAA0B;IAElC;;;;;;;;;;;OAWG;IACO,KAAK,CAAC,WAAW,CACzB,QAAkD;QAElD,MAAM,IAAI,GAAG,+BAA+B,CAAC,QAAQ,EAAE,CAAA;QACvD,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QAC5B,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAA;QAC7B,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;YAC5D,IAAI,CAAC,mBAAmB,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC,CAAA;YACtD,OAAO,MAAM,CAAA;QACf,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,CAAC,qBAAqB,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;YACrC,MAAM,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAA;QAChC,CAAC;IACH,CAAC;IAED,6DAA6D;IAE7D;;;;OAIG;IACO,kBAAkB,CAAC,KAAa,IAAS,CAAC;IAEpD;;;;OAIG;IACO,mBAAmB,CAAC,KAAa,EAAE,WAAmB,IAAS,CAAC;IAE1E;;;;;OAKG;IACO,qBAAqB,CAAC,KAAa,EAAE,OAAgB,IAAS,CAAC;IAEzE,6DAA6D;IAErD,MAAM,CAAC,QAAQ;QACrB,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;QACjC,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,QAAQ,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;QAC5E,OAAO,MAAM,CAAC,IAAI,CAAC,EAAE,CAAA;IACvB,CAAC;CACF"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { DatabaseException } from './DatabaseException.js';
|
|
2
|
-
/**
|
|
3
|
-
* Thrown when an INSERT or UPDATE violates a CHECK constraint.
|
|
4
|
-
*
|
|
5
|
-
* The constraint name (when exposed by the driver) often matches the
|
|
6
|
-
* named CHECK in the schema, e.g. `users_age_positive_check`.
|
|
7
|
-
*/
|
|
8
|
-
export declare class CheckViolationException extends DatabaseException {
|
|
9
|
-
/** Name of the violated CHECK constraint, if known. */
|
|
10
|
-
readonly constraint?: string;
|
|
11
|
-
/** Table where the violation occurred, if known. */
|
|
12
|
-
readonly table?: string;
|
|
13
|
-
constructor(message: string, details?: {
|
|
14
|
-
constraint?: string;
|
|
15
|
-
table?: string;
|
|
16
|
-
cause?: unknown;
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=CheckViolationException.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CheckViolationException.d.ts","sourceRoot":"","sources":["../../../../src/repository/structs/CheckViolationException.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE1D;;;;;GAKG;AACH,qBAAa,uBAAwB,SAAQ,iBAAiB;IAC5D,uDAAuD;IACvD,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;IAC5B,oDAAoD;IACpD,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;gBAGrB,OAAO,EAAE,MAAM,EACf,OAAO,GAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAO;CAOzE"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { DatabaseException } from './DatabaseException.js';
|
|
2
|
-
/**
|
|
3
|
-
* Thrown when an INSERT or UPDATE violates a CHECK constraint.
|
|
4
|
-
*
|
|
5
|
-
* The constraint name (when exposed by the driver) often matches the
|
|
6
|
-
* named CHECK in the schema, e.g. `users_age_positive_check`.
|
|
7
|
-
*/
|
|
8
|
-
export class CheckViolationException extends DatabaseException {
|
|
9
|
-
/** Name of the violated CHECK constraint, if known. */
|
|
10
|
-
constraint;
|
|
11
|
-
/** Table where the violation occurred, if known. */
|
|
12
|
-
table;
|
|
13
|
-
constructor(message, details = {}) {
|
|
14
|
-
super(message, { cause: details.cause });
|
|
15
|
-
this.name = 'CheckViolationException';
|
|
16
|
-
if (details.constraint !== undefined)
|
|
17
|
-
this.constraint = details.constraint;
|
|
18
|
-
if (details.table !== undefined)
|
|
19
|
-
this.table = details.table;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=CheckViolationException.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CheckViolationException.js","sourceRoot":"","sources":["../../../../src/repository/structs/CheckViolationException.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE1D;;;;;GAKG;AACH,MAAM,OAAO,uBAAwB,SAAQ,iBAAiB;IAC5D,uDAAuD;IAC9C,UAAU,CAAS;IAC5B,oDAAoD;IAC3C,KAAK,CAAS;IAEvB,YACE,OAAe,EACf,UAAoE,EAAE;QAEtE,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAA;QACxC,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAA;QACrC,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS;YAAE,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAA;QAC1E,IAAI,OAAO,CAAC,KAAK,KAAU,SAAS;YAAE,IAAI,CAAC,KAAK,GAAQ,OAAO,CAAC,KAAK,CAAA;IACvE,CAAC;CACF"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { DatabaseException } from './DatabaseException.js';
|
|
2
|
-
/**
|
|
3
|
-
* Thrown when the database is unreachable — DNS failure, TCP refused,
|
|
4
|
-
* TLS handshake failure, statement / connection timeout, etc.
|
|
5
|
-
*
|
|
6
|
-
* The original transport error is preserved as the standard
|
|
7
|
-
* `Error.cause`. Use this alongside `RetryableRepository.withRetry`
|
|
8
|
-
* to back off and retry on transient transport failures.
|
|
9
|
-
*/
|
|
10
|
-
export declare class ConnectionException extends DatabaseException {
|
|
11
|
-
constructor(message: string, options?: {
|
|
12
|
-
cause?: unknown;
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=ConnectionException.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectionException.d.ts","sourceRoot":"","sources":["../../../../src/repository/structs/ConnectionException.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE1D;;;;;;;GAOG;AACH,qBAAa,mBAAoB,SAAQ,iBAAiB;gBAC5C,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAI3D"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { DatabaseException } from './DatabaseException.js';
|
|
2
|
-
/**
|
|
3
|
-
* Thrown when the database is unreachable — DNS failure, TCP refused,
|
|
4
|
-
* TLS handshake failure, statement / connection timeout, etc.
|
|
5
|
-
*
|
|
6
|
-
* The original transport error is preserved as the standard
|
|
7
|
-
* `Error.cause`. Use this alongside `RetryableRepository.withRetry`
|
|
8
|
-
* to back off and retry on transient transport failures.
|
|
9
|
-
*/
|
|
10
|
-
export class ConnectionException extends DatabaseException {
|
|
11
|
-
constructor(message, options) {
|
|
12
|
-
super(message, options);
|
|
13
|
-
this.name = 'ConnectionException';
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=ConnectionException.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectionException.js","sourceRoot":"","sources":["../../../../src/repository/structs/ConnectionException.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE1D;;;;;;;GAOG;AACH,MAAM,OAAO,mBAAoB,SAAQ,iBAAiB;IACxD,YAAY,OAAe,EAAE,OAA6B;QACxD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QACvB,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAA;IACnC,CAAC;CACF"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base type for every database-related error raised through xf-sql.
|
|
3
|
-
*
|
|
4
|
-
* Every concrete dialect-specific Exception in `@xfarch/xf-sql` is a
|
|
5
|
-
* subclass of `DatabaseException`. Consumers can branch on the
|
|
6
|
-
* specific subclass (e.g. `UniqueViolationException`) or fall back to
|
|
7
|
-
* `instanceof DatabaseException` to catch any DB-originated error.
|
|
8
|
-
*/
|
|
9
|
-
export declare class DatabaseException extends Error {
|
|
10
|
-
constructor(message: string, options?: {
|
|
11
|
-
cause?: unknown;
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=DatabaseException.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DatabaseException.d.ts","sourceRoot":"","sources":["../../../../src/repository/structs/DatabaseException.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;gBAC9B,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAI3D"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base type for every database-related error raised through xf-sql.
|
|
3
|
-
*
|
|
4
|
-
* Every concrete dialect-specific Exception in `@xfarch/xf-sql` is a
|
|
5
|
-
* subclass of `DatabaseException`. Consumers can branch on the
|
|
6
|
-
* specific subclass (e.g. `UniqueViolationException`) or fall back to
|
|
7
|
-
* `instanceof DatabaseException` to catch any DB-originated error.
|
|
8
|
-
*/
|
|
9
|
-
export class DatabaseException extends Error {
|
|
10
|
-
constructor(message, options) {
|
|
11
|
-
super(message, options);
|
|
12
|
-
this.name = 'DatabaseException';
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=DatabaseException.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DatabaseException.js","sourceRoot":"","sources":["../../../../src/repository/structs/DatabaseException.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C,YAAY,OAAe,EAAE,OAA6B;QACxD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QACvB,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAA;IACjC,CAAC;CACF"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { DatabaseException } from './DatabaseException.js';
|
|
2
|
-
/**
|
|
3
|
-
* Thrown when the database detects a deadlock and aborts one of the
|
|
4
|
-
* conflicting transactions.
|
|
5
|
-
*
|
|
6
|
-
* Deadlocks are typically retryable — the transaction can be re-run
|
|
7
|
-
* and will usually succeed once the conflicting party has finished.
|
|
8
|
-
* Pair with `RetryableRepository.withRetry` or
|
|
9
|
-
* `RetryRestRepository`-style policies in your Logical.
|
|
10
|
-
*/
|
|
11
|
-
export declare class DeadlockException extends DatabaseException {
|
|
12
|
-
constructor(message: string, options?: {
|
|
13
|
-
cause?: unknown;
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=DeadlockException.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DeadlockException.d.ts","sourceRoot":"","sources":["../../../../src/repository/structs/DeadlockException.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE1D;;;;;;;;GAQG;AACH,qBAAa,iBAAkB,SAAQ,iBAAiB;gBAC1C,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAI3D"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { DatabaseException } from './DatabaseException.js';
|
|
2
|
-
/**
|
|
3
|
-
* Thrown when the database detects a deadlock and aborts one of the
|
|
4
|
-
* conflicting transactions.
|
|
5
|
-
*
|
|
6
|
-
* Deadlocks are typically retryable — the transaction can be re-run
|
|
7
|
-
* and will usually succeed once the conflicting party has finished.
|
|
8
|
-
* Pair with `RetryableRepository.withRetry` or
|
|
9
|
-
* `RetryRestRepository`-style policies in your Logical.
|
|
10
|
-
*/
|
|
11
|
-
export class DeadlockException extends DatabaseException {
|
|
12
|
-
constructor(message, options) {
|
|
13
|
-
super(message, options);
|
|
14
|
-
this.name = 'DeadlockException';
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=DeadlockException.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DeadlockException.js","sourceRoot":"","sources":["../../../../src/repository/structs/DeadlockException.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE1D;;;;;;;;GAQG;AACH,MAAM,OAAO,iBAAkB,SAAQ,iBAAiB;IACtD,YAAY,OAAe,EAAE,OAA6B;QACxD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QACvB,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAA;IACjC,CAAC;CACF"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { DatabaseException } from './DatabaseException.js';
|
|
2
|
-
/**
|
|
3
|
-
* Thrown when an INSERT, UPDATE or DELETE violates a FOREIGN KEY
|
|
4
|
-
* constraint.
|
|
5
|
-
*
|
|
6
|
-
* Common scenarios: inserting a row that references a non-existent
|
|
7
|
-
* parent; deleting a row that is still referenced by children.
|
|
8
|
-
*/
|
|
9
|
-
export declare class ForeignKeyViolationException extends DatabaseException {
|
|
10
|
-
/** Name of the violated foreign-key constraint, if known. */
|
|
11
|
-
readonly constraint?: string;
|
|
12
|
-
/** Table where the violation occurred, if known. */
|
|
13
|
-
readonly table?: string;
|
|
14
|
-
constructor(message: string, details?: {
|
|
15
|
-
constraint?: string;
|
|
16
|
-
table?: string;
|
|
17
|
-
cause?: unknown;
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=ForeignKeyViolationException.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ForeignKeyViolationException.d.ts","sourceRoot":"","sources":["../../../../src/repository/structs/ForeignKeyViolationException.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE1D;;;;;;GAMG;AACH,qBAAa,4BAA6B,SAAQ,iBAAiB;IACjE,6DAA6D;IAC7D,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;IAC5B,oDAAoD;IACpD,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;gBAGrB,OAAO,EAAE,MAAM,EACf,OAAO,GAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAO;CAOzE"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { DatabaseException } from './DatabaseException.js';
|
|
2
|
-
/**
|
|
3
|
-
* Thrown when an INSERT, UPDATE or DELETE violates a FOREIGN KEY
|
|
4
|
-
* constraint.
|
|
5
|
-
*
|
|
6
|
-
* Common scenarios: inserting a row that references a non-existent
|
|
7
|
-
* parent; deleting a row that is still referenced by children.
|
|
8
|
-
*/
|
|
9
|
-
export class ForeignKeyViolationException extends DatabaseException {
|
|
10
|
-
/** Name of the violated foreign-key constraint, if known. */
|
|
11
|
-
constraint;
|
|
12
|
-
/** Table where the violation occurred, if known. */
|
|
13
|
-
table;
|
|
14
|
-
constructor(message, details = {}) {
|
|
15
|
-
super(message, { cause: details.cause });
|
|
16
|
-
this.name = 'ForeignKeyViolationException';
|
|
17
|
-
if (details.constraint !== undefined)
|
|
18
|
-
this.constraint = details.constraint;
|
|
19
|
-
if (details.table !== undefined)
|
|
20
|
-
this.table = details.table;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=ForeignKeyViolationException.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ForeignKeyViolationException.js","sourceRoot":"","sources":["../../../../src/repository/structs/ForeignKeyViolationException.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE1D;;;;;;GAMG;AACH,MAAM,OAAO,4BAA6B,SAAQ,iBAAiB;IACjE,6DAA6D;IACpD,UAAU,CAAS;IAC5B,oDAAoD;IAC3C,KAAK,CAAS;IAEvB,YACE,OAAe,EACf,UAAoE,EAAE;QAEtE,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAA;QACxC,IAAI,CAAC,IAAI,GAAG,8BAA8B,CAAA;QAC1C,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS;YAAE,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAA;QAC1E,IAAI,OAAO,CAAC,KAAK,KAAU,SAAS;YAAE,IAAI,CAAC,KAAK,GAAQ,OAAO,CAAC,KAAK,CAAA;IACvE,CAAC;CACF"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { DatabaseException } from './DatabaseException.js';
|
|
2
|
-
/**
|
|
3
|
-
* Thrown when an INSERT or UPDATE attempts to set a NOT NULL column
|
|
4
|
-
* to NULL.
|
|
5
|
-
*
|
|
6
|
-
* Almost always indicates a bug in the Repository or a missing input
|
|
7
|
-
* validation at the Business Layer.
|
|
8
|
-
*/
|
|
9
|
-
export declare class NotNullViolationException extends DatabaseException {
|
|
10
|
-
/** Table where the violation occurred, if known. */
|
|
11
|
-
readonly table?: string;
|
|
12
|
-
/** Column that was set to NULL, if known. */
|
|
13
|
-
readonly column?: string;
|
|
14
|
-
constructor(message: string, details?: {
|
|
15
|
-
table?: string;
|
|
16
|
-
column?: string;
|
|
17
|
-
cause?: unknown;
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=NotNullViolationException.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NotNullViolationException.d.ts","sourceRoot":"","sources":["../../../../src/repository/structs/NotNullViolationException.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE1D;;;;;;GAMG;AACH,qBAAa,yBAA0B,SAAQ,iBAAiB;IAC9D,oDAAoD;IACpD,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;IACvB,6CAA6C;IAC7C,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;gBAGtB,OAAO,EAAE,MAAM,EACf,OAAO,GAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAO;CAOrE"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { DatabaseException } from './DatabaseException.js';
|
|
2
|
-
/**
|
|
3
|
-
* Thrown when an INSERT or UPDATE attempts to set a NOT NULL column
|
|
4
|
-
* to NULL.
|
|
5
|
-
*
|
|
6
|
-
* Almost always indicates a bug in the Repository or a missing input
|
|
7
|
-
* validation at the Business Layer.
|
|
8
|
-
*/
|
|
9
|
-
export class NotNullViolationException extends DatabaseException {
|
|
10
|
-
/** Table where the violation occurred, if known. */
|
|
11
|
-
table;
|
|
12
|
-
/** Column that was set to NULL, if known. */
|
|
13
|
-
column;
|
|
14
|
-
constructor(message, details = {}) {
|
|
15
|
-
super(message, { cause: details.cause });
|
|
16
|
-
this.name = 'NotNullViolationException';
|
|
17
|
-
if (details.table !== undefined)
|
|
18
|
-
this.table = details.table;
|
|
19
|
-
if (details.column !== undefined)
|
|
20
|
-
this.column = details.column;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=NotNullViolationException.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NotNullViolationException.js","sourceRoot":"","sources":["../../../../src/repository/structs/NotNullViolationException.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE1D;;;;;;GAMG;AACH,MAAM,OAAO,yBAA0B,SAAQ,iBAAiB;IAC9D,oDAAoD;IAC3C,KAAK,CAAS;IACvB,6CAA6C;IACpC,MAAM,CAAS;IAExB,YACE,OAAe,EACf,UAAgE,EAAE;QAElE,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAA;QACxC,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAA;QACvC,IAAI,OAAO,CAAC,KAAK,KAAM,SAAS;YAAE,IAAI,CAAC,KAAK,GAAI,OAAO,CAAC,KAAK,CAAA;QAC7D,IAAI,OAAO,CAAC,MAAM,KAAK,SAAS;YAAE,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAA;IAChE,CAAC;CACF"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { DatabaseException } from './DatabaseException.js';
|
|
2
|
-
/**
|
|
3
|
-
* Thrown when an INSERT or UPDATE violates a UNIQUE / PRIMARY KEY
|
|
4
|
-
* constraint.
|
|
5
|
-
*
|
|
6
|
-
* Carries the violated constraint name plus the table / column when
|
|
7
|
-
* the underlying driver exposes them, so the Business Layer can
|
|
8
|
-
* surface a domain-meaningful error without parsing strings.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```ts
|
|
12
|
-
* try {
|
|
13
|
-
* await this.usersDb.createUser({ email: 'a@b.c', ... })
|
|
14
|
-
* } catch (err) {
|
|
15
|
-
* if (err instanceof UniqueViolationException && err.column === 'email') {
|
|
16
|
-
* throw new DomainError('Email already registered')
|
|
17
|
-
* }
|
|
18
|
-
* throw err
|
|
19
|
-
* }
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export declare class UniqueViolationException extends DatabaseException {
|
|
23
|
-
/** Name of the violated unique / primary-key constraint, if known. */
|
|
24
|
-
readonly constraint?: string;
|
|
25
|
-
/** Table where the violation occurred, if known. */
|
|
26
|
-
readonly table?: string;
|
|
27
|
-
/** Column involved in the violation, if known. */
|
|
28
|
-
readonly column?: string;
|
|
29
|
-
constructor(message: string, details?: {
|
|
30
|
-
constraint?: string;
|
|
31
|
-
table?: string;
|
|
32
|
-
column?: string;
|
|
33
|
-
cause?: unknown;
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
//# sourceMappingURL=UniqueViolationException.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"UniqueViolationException.d.ts","sourceRoot":"","sources":["../../../../src/repository/structs/UniqueViolationException.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE1D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,wBAAyB,SAAQ,iBAAiB;IAC7D,sEAAsE;IACtE,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;IAC5B,oDAAoD;IACpD,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;IACvB,kDAAkD;IAClD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;gBAGtB,OAAO,EAAE,MAAM,EACf,OAAO,GAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAO;CAQ1F"}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { DatabaseException } from './DatabaseException.js';
|
|
2
|
-
/**
|
|
3
|
-
* Thrown when an INSERT or UPDATE violates a UNIQUE / PRIMARY KEY
|
|
4
|
-
* constraint.
|
|
5
|
-
*
|
|
6
|
-
* Carries the violated constraint name plus the table / column when
|
|
7
|
-
* the underlying driver exposes them, so the Business Layer can
|
|
8
|
-
* surface a domain-meaningful error without parsing strings.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```ts
|
|
12
|
-
* try {
|
|
13
|
-
* await this.usersDb.createUser({ email: 'a@b.c', ... })
|
|
14
|
-
* } catch (err) {
|
|
15
|
-
* if (err instanceof UniqueViolationException && err.column === 'email') {
|
|
16
|
-
* throw new DomainError('Email already registered')
|
|
17
|
-
* }
|
|
18
|
-
* throw err
|
|
19
|
-
* }
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export class UniqueViolationException extends DatabaseException {
|
|
23
|
-
/** Name of the violated unique / primary-key constraint, if known. */
|
|
24
|
-
constraint;
|
|
25
|
-
/** Table where the violation occurred, if known. */
|
|
26
|
-
table;
|
|
27
|
-
/** Column involved in the violation, if known. */
|
|
28
|
-
column;
|
|
29
|
-
constructor(message, details = {}) {
|
|
30
|
-
super(message, { cause: details.cause });
|
|
31
|
-
this.name = 'UniqueViolationException';
|
|
32
|
-
if (details.constraint !== undefined)
|
|
33
|
-
this.constraint = details.constraint;
|
|
34
|
-
if (details.table !== undefined)
|
|
35
|
-
this.table = details.table;
|
|
36
|
-
if (details.column !== undefined)
|
|
37
|
-
this.column = details.column;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
//# sourceMappingURL=UniqueViolationException.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"UniqueViolationException.js","sourceRoot":"","sources":["../../../../src/repository/structs/UniqueViolationException.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE1D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,wBAAyB,SAAQ,iBAAiB;IAC7D,sEAAsE;IAC7D,UAAU,CAAS;IAC5B,oDAAoD;IAC3C,KAAK,CAAS;IACvB,kDAAkD;IACzC,MAAM,CAAS;IAExB,YACE,OAAe,EACf,UAAqF,EAAE;QAEvF,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAA;QACxC,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAA;QACtC,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS;YAAE,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAA;QAC1E,IAAI,OAAO,CAAC,KAAK,KAAU,SAAS;YAAE,IAAI,CAAC,KAAK,GAAQ,OAAO,CAAC,KAAK,CAAA;QACrE,IAAI,OAAO,CAAC,MAAM,KAAS,SAAS;YAAE,IAAI,CAAC,MAAM,GAAO,OAAO,CAAC,MAAM,CAAA;IACxE,CAAC;CACF"}
|