@goodie-ts/kysely 0.5.3 → 0.6.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/README.md +22 -9
- package/dist/beans.json +135 -0
- package/dist/datasource-config.d.ts +31 -0
- package/dist/datasource-config.d.ts.map +1 -0
- package/dist/datasource-config.js +113 -0
- package/dist/datasource-config.js.map +1 -0
- package/dist/dialect-factory.d.ts +9 -0
- package/dist/dialect-factory.d.ts.map +1 -0
- package/dist/dialect-factory.js +48 -0
- package/dist/dialect-factory.js.map +1 -0
- package/dist/dialect.d.ts +24 -0
- package/dist/dialect.d.ts.map +1 -0
- package/dist/dialect.js +33 -0
- package/dist/dialect.js.map +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/kysely-database.d.ts +37 -0
- package/dist/kysely-database.d.ts.map +1 -0
- package/dist/kysely-database.js +103 -0
- package/dist/kysely-database.js.map +1 -0
- package/dist/kysely-transformer-plugin.d.ts +4 -13
- package/dist/kysely-transformer-plugin.d.ts.map +1 -1
- package/dist/kysely-transformer-plugin.js +25 -75
- package/dist/kysely-transformer-plugin.js.map +1 -1
- package/dist/transaction-manager.d.ts +14 -6
- package/dist/transaction-manager.d.ts.map +1 -1
- package/dist/transaction-manager.js +30 -5
- package/dist/transaction-manager.js.map +1 -1
- package/package.json +27 -6
- package/dist/crud-repository.d.ts +0 -40
- package/dist/crud-repository.d.ts.map +0 -1
- package/dist/crud-repository.js +0 -64
- package/dist/crud-repository.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @goodie-ts/kysely
|
|
2
2
|
|
|
3
|
-
[Kysely](https://kysely.dev/) integration for [goodie-ts](https://github.com/GOOD-Code-ApS/goodie) — declarative transactions, auto-wired migrations
|
|
3
|
+
[Kysely](https://kysely.dev/) integration for [goodie-ts](https://github.com/GOOD-Code-ApS/goodie) — `KyselyDatabase` library bean, declarative transactions, and auto-wired migrations.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -10,7 +10,7 @@ pnpm add @goodie-ts/kysely kysely
|
|
|
10
10
|
|
|
11
11
|
## Overview
|
|
12
12
|
|
|
13
|
-
Provides `@Transactional` for declarative transaction management, `@Migration` for auto-discovered database migrations, and `
|
|
13
|
+
Provides `KyselyDatabase` as a library-provided `@Singleton` that creates and manages a `Kysely<any>` instance from configuration. Use `@Module` with `@Provides` for typed `Kysely<DB>` access. Includes `@Transactional` for declarative transaction management, `@Migration` for auto-discovered database migrations, and `TransactionManager` with `AsyncLocalStorage` for transaction propagation.
|
|
14
14
|
|
|
15
15
|
## Decorators
|
|
16
16
|
|
|
@@ -22,13 +22,26 @@ Provides `@Transactional` for declarative transaction management, `@Migration` f
|
|
|
22
22
|
## Usage
|
|
23
23
|
|
|
24
24
|
```typescript
|
|
25
|
-
import { Singleton } from '@goodie-ts/core';
|
|
26
|
-
import {
|
|
25
|
+
import { Module, Provides, Singleton } from '@goodie-ts/core';
|
|
26
|
+
import { KyselyDatabase, Transactional } from '@goodie-ts/kysely';
|
|
27
|
+
import type { Kysely } from 'kysely';
|
|
28
|
+
|
|
29
|
+
@Module()
|
|
30
|
+
class DatabaseModule {
|
|
31
|
+
constructor(private db: KyselyDatabase) {}
|
|
32
|
+
|
|
33
|
+
@Provides()
|
|
34
|
+
typedKysely(): Kysely<Database> {
|
|
35
|
+
return this.db.kysely as Kysely<Database>;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
27
38
|
|
|
28
39
|
@Singleton()
|
|
29
|
-
class TodoRepository
|
|
30
|
-
constructor(
|
|
31
|
-
|
|
40
|
+
class TodoRepository {
|
|
41
|
+
constructor(private readonly db: Kysely<Database>) {}
|
|
42
|
+
|
|
43
|
+
async findAll(): Promise<Todo[]> {
|
|
44
|
+
return this.db.selectFrom('todos').selectAll().execute();
|
|
32
45
|
}
|
|
33
46
|
}
|
|
34
47
|
|
|
@@ -39,7 +52,7 @@ class TodoService {
|
|
|
39
52
|
@Transactional()
|
|
40
53
|
async createMany(titles: string[]) {
|
|
41
54
|
for (const title of titles) {
|
|
42
|
-
await this.repo.
|
|
55
|
+
await this.repo.create(title);
|
|
43
56
|
}
|
|
44
57
|
// All-or-nothing: rolls back on error
|
|
45
58
|
}
|
|
@@ -80,7 +93,7 @@ export default defineConfig({
|
|
|
80
93
|
});
|
|
81
94
|
```
|
|
82
95
|
|
|
83
|
-
The
|
|
96
|
+
The kysely plugin is auto-discovered — no manual `plugins` configuration needed. `KyselyDatabase` is provided as a library bean.
|
|
84
97
|
|
|
85
98
|
## License
|
|
86
99
|
|
package/dist/beans.json
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 1,
|
|
3
|
+
"package": "@goodie-ts/kysely",
|
|
4
|
+
"beans": [
|
|
5
|
+
{
|
|
6
|
+
"tokenRef": {
|
|
7
|
+
"kind": "class",
|
|
8
|
+
"className": "PoolConfig",
|
|
9
|
+
"importPath": "@goodie-ts/kysely"
|
|
10
|
+
},
|
|
11
|
+
"scope": "singleton",
|
|
12
|
+
"eager": false,
|
|
13
|
+
"name": null,
|
|
14
|
+
"constructorDeps": [],
|
|
15
|
+
"fieldDeps": [],
|
|
16
|
+
"factoryKind": "constructor",
|
|
17
|
+
"providesSource": null,
|
|
18
|
+
"baseTokenRefs": null,
|
|
19
|
+
"metadata": {
|
|
20
|
+
"valueFields": [
|
|
21
|
+
{
|
|
22
|
+
"fieldName": "min",
|
|
23
|
+
"key": "datasource.pool.min",
|
|
24
|
+
"default": "2"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"fieldName": "max",
|
|
28
|
+
"key": "datasource.pool.max",
|
|
29
|
+
"default": "10"
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
"sourceLocation": {
|
|
34
|
+
"filePath": "@goodie-ts/kysely",
|
|
35
|
+
"line": 11,
|
|
36
|
+
"column": 1
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"tokenRef": {
|
|
41
|
+
"kind": "class",
|
|
42
|
+
"className": "DatasourceConfig",
|
|
43
|
+
"importPath": "@goodie-ts/kysely"
|
|
44
|
+
},
|
|
45
|
+
"scope": "singleton",
|
|
46
|
+
"eager": false,
|
|
47
|
+
"name": null,
|
|
48
|
+
"constructorDeps": [
|
|
49
|
+
{
|
|
50
|
+
"tokenRef": {
|
|
51
|
+
"kind": "class",
|
|
52
|
+
"className": "PoolConfig",
|
|
53
|
+
"importPath": "@goodie-ts/kysely"
|
|
54
|
+
},
|
|
55
|
+
"optional": false,
|
|
56
|
+
"collection": false,
|
|
57
|
+
"sourceLocation": {
|
|
58
|
+
"filePath": "@goodie-ts/kysely",
|
|
59
|
+
"line": 40,
|
|
60
|
+
"column": 15
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
],
|
|
64
|
+
"fieldDeps": [],
|
|
65
|
+
"factoryKind": "constructor",
|
|
66
|
+
"providesSource": null,
|
|
67
|
+
"baseTokenRefs": null,
|
|
68
|
+
"metadata": {
|
|
69
|
+
"postConstructMethods": [
|
|
70
|
+
"validate"
|
|
71
|
+
],
|
|
72
|
+
"valueFields": [
|
|
73
|
+
{
|
|
74
|
+
"fieldName": "url",
|
|
75
|
+
"key": "datasource.url",
|
|
76
|
+
"default": "''"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"fieldName": "dialect",
|
|
80
|
+
"key": "datasource.dialect",
|
|
81
|
+
"default": "''"
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
},
|
|
85
|
+
"sourceLocation": {
|
|
86
|
+
"filePath": "@goodie-ts/kysely",
|
|
87
|
+
"line": 34,
|
|
88
|
+
"column": 1
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"tokenRef": {
|
|
93
|
+
"kind": "class",
|
|
94
|
+
"className": "KyselyDatabase",
|
|
95
|
+
"importPath": "@goodie-ts/kysely"
|
|
96
|
+
},
|
|
97
|
+
"scope": "singleton",
|
|
98
|
+
"eager": false,
|
|
99
|
+
"name": null,
|
|
100
|
+
"constructorDeps": [
|
|
101
|
+
{
|
|
102
|
+
"tokenRef": {
|
|
103
|
+
"kind": "class",
|
|
104
|
+
"className": "DatasourceConfig",
|
|
105
|
+
"importPath": "@goodie-ts/kysely"
|
|
106
|
+
},
|
|
107
|
+
"optional": false,
|
|
108
|
+
"collection": false,
|
|
109
|
+
"sourceLocation": {
|
|
110
|
+
"filePath": "@goodie-ts/kysely",
|
|
111
|
+
"line": 35,
|
|
112
|
+
"column": 15
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
],
|
|
116
|
+
"fieldDeps": [],
|
|
117
|
+
"factoryKind": "constructor",
|
|
118
|
+
"providesSource": null,
|
|
119
|
+
"baseTokenRefs": null,
|
|
120
|
+
"metadata": {
|
|
121
|
+
"preDestroyMethods": [
|
|
122
|
+
"destroy"
|
|
123
|
+
],
|
|
124
|
+
"postConstructMethods": [
|
|
125
|
+
"init"
|
|
126
|
+
]
|
|
127
|
+
},
|
|
128
|
+
"sourceLocation": {
|
|
129
|
+
"filePath": "@goodie-ts/kysely",
|
|
130
|
+
"line": 31,
|
|
131
|
+
"column": 1
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
]
|
|
135
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Connection pool configuration, bound from `datasource.pool.*` keys.
|
|
3
|
+
*/
|
|
4
|
+
export declare class PoolConfig {
|
|
5
|
+
min: number;
|
|
6
|
+
max: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Configuration properties for the datasource, bound from `datasource.*` keys.
|
|
10
|
+
*
|
|
11
|
+
* Users configure via `config/default.json`:
|
|
12
|
+
* ```json
|
|
13
|
+
* {
|
|
14
|
+
* "datasource": {
|
|
15
|
+
* "url": "postgres://localhost:5432/mydb",
|
|
16
|
+
* "dialect": "postgres",
|
|
17
|
+
* "pool": { "min": 2, "max": 10 }
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* Or via environment variables: `DATASOURCE_URL`, `DATASOURCE_DIALECT`, etc.
|
|
23
|
+
*/
|
|
24
|
+
export declare class DatasourceConfig {
|
|
25
|
+
readonly pool: PoolConfig;
|
|
26
|
+
url: string;
|
|
27
|
+
dialect: string;
|
|
28
|
+
constructor(pool: PoolConfig);
|
|
29
|
+
validate(): void;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=datasource-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datasource-config.d.ts","sourceRoot":"","sources":["../src/datasource-config.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,qBAEa,UAAU;IACrB,GAAG,SAAK;IACR,GAAG,SAAM;CACV;AAED;;;;;;;;;;;;;;;GAeG;AACH,qBAEa,gBAAgB;IAIf,QAAQ,CAAC,IAAI,EAAE,UAAU;IAHrC,GAAG,SAAM;IACT,OAAO,SAAM;gBAEQ,IAAI,EAAE,UAAU;IAGrC,QAAQ;CAcT"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
2
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
3
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
4
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
5
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
6
|
+
var _, done = false;
|
|
7
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
8
|
+
var context = {};
|
|
9
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
10
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
11
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
12
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
13
|
+
if (kind === "accessor") {
|
|
14
|
+
if (result === void 0) continue;
|
|
15
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
16
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
17
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
18
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
19
|
+
}
|
|
20
|
+
else if (_ = accept(result)) {
|
|
21
|
+
if (kind === "field") initializers.unshift(_);
|
|
22
|
+
else descriptor[key] = _;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
26
|
+
done = true;
|
|
27
|
+
};
|
|
28
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
29
|
+
var useValue = arguments.length > 2;
|
|
30
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
31
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
32
|
+
}
|
|
33
|
+
return useValue ? value : void 0;
|
|
34
|
+
};
|
|
35
|
+
import { ConfigurationProperties, PostConstruct, Singleton, } from '@goodie-ts/core';
|
|
36
|
+
import { validateDialect } from './dialect.js';
|
|
37
|
+
/**
|
|
38
|
+
* Connection pool configuration, bound from `datasource.pool.*` keys.
|
|
39
|
+
*/
|
|
40
|
+
let PoolConfig = (() => {
|
|
41
|
+
let _classDecorators = [Singleton(), ConfigurationProperties('datasource.pool')];
|
|
42
|
+
let _classDescriptor;
|
|
43
|
+
let _classExtraInitializers = [];
|
|
44
|
+
let _classThis;
|
|
45
|
+
var PoolConfig = class {
|
|
46
|
+
static { _classThis = this; }
|
|
47
|
+
static {
|
|
48
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
49
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
50
|
+
PoolConfig = _classThis = _classDescriptor.value;
|
|
51
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
52
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
53
|
+
}
|
|
54
|
+
min = 2;
|
|
55
|
+
max = 10;
|
|
56
|
+
};
|
|
57
|
+
return PoolConfig = _classThis;
|
|
58
|
+
})();
|
|
59
|
+
export { PoolConfig };
|
|
60
|
+
/**
|
|
61
|
+
* Configuration properties for the datasource, bound from `datasource.*` keys.
|
|
62
|
+
*
|
|
63
|
+
* Users configure via `config/default.json`:
|
|
64
|
+
* ```json
|
|
65
|
+
* {
|
|
66
|
+
* "datasource": {
|
|
67
|
+
* "url": "postgres://localhost:5432/mydb",
|
|
68
|
+
* "dialect": "postgres",
|
|
69
|
+
* "pool": { "min": 2, "max": 10 }
|
|
70
|
+
* }
|
|
71
|
+
* }
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* Or via environment variables: `DATASOURCE_URL`, `DATASOURCE_DIALECT`, etc.
|
|
75
|
+
*/
|
|
76
|
+
let DatasourceConfig = (() => {
|
|
77
|
+
let _classDecorators = [Singleton(), ConfigurationProperties('datasource')];
|
|
78
|
+
let _classDescriptor;
|
|
79
|
+
let _classExtraInitializers = [];
|
|
80
|
+
let _classThis;
|
|
81
|
+
let _instanceExtraInitializers = [];
|
|
82
|
+
let _validate_decorators;
|
|
83
|
+
var DatasourceConfig = class {
|
|
84
|
+
static { _classThis = this; }
|
|
85
|
+
static {
|
|
86
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
87
|
+
_validate_decorators = [PostConstruct()];
|
|
88
|
+
__esDecorate(this, null, _validate_decorators, { kind: "method", name: "validate", static: false, private: false, access: { has: obj => "validate" in obj, get: obj => obj.validate }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
89
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
90
|
+
DatasourceConfig = _classThis = _classDescriptor.value;
|
|
91
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
92
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
93
|
+
}
|
|
94
|
+
pool = __runInitializers(this, _instanceExtraInitializers);
|
|
95
|
+
url = '';
|
|
96
|
+
dialect = '';
|
|
97
|
+
constructor(pool) {
|
|
98
|
+
this.pool = pool;
|
|
99
|
+
}
|
|
100
|
+
validate() {
|
|
101
|
+
if (!this.dialect) {
|
|
102
|
+
throw new Error("DatasourceConfig: 'datasource.dialect' is required. Supported dialects: postgres, mysql, sqlite");
|
|
103
|
+
}
|
|
104
|
+
validateDialect(this.dialect);
|
|
105
|
+
if (!this.url) {
|
|
106
|
+
throw new Error("DatasourceConfig: 'datasource.url' is required. Example: postgres://localhost:5432/mydb");
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
return DatasourceConfig = _classThis;
|
|
111
|
+
})();
|
|
112
|
+
export { DatasourceConfig };
|
|
113
|
+
//# sourceMappingURL=datasource-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datasource-config.js","sourceRoot":"","sources":["../src/datasource-config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EACL,uBAAuB,EACvB,aAAa,EACb,SAAS,GACV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C;;GAEG;IAGU,UAAU;4BAFtB,SAAS,EAAE,EACX,uBAAuB,CAAC,iBAAiB,CAAC;;;;;;;;YAC3C,6KAGC;;;YAHY,uDAAU;;QACrB,GAAG,GAAG,CAAC,CAAC;QACR,GAAG,GAAG,EAAE,CAAC;;;;SAFE,UAAU;AAKvB;;;;;;;;;;;;;;;GAeG;IAGU,gBAAgB;4BAF5B,SAAS,EAAE,EACX,uBAAuB,CAAC,YAAY,CAAC;;;;;;;;;;oCAOnC,aAAa,EAAE;YAChB,2KAAA,QAAQ,6DAaP;YApBH,6KAqBC;;;YArBY,uDAAgB;;QAIN,IAAI,GAJd,mDAAgB;QAC3B,GAAG,GAAG,EAAE,CAAC;QACT,OAAO,GAAG,EAAE,CAAC;QAEb,YAAqB,IAAgB;YAAhB,SAAI,GAAJ,IAAI,CAAY;QAAG,CAAC;QAGzC,QAAQ;YACN,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;gBAClB,MAAM,IAAI,KAAK,CACb,iGAAiG,CAClG,CAAC;YACJ,CAAC;YACD,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAE9B,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;gBACd,MAAM,IAAI,KAAK,CACb,yFAAyF,CAC1F,CAAC;YACJ,CAAC;QACH,CAAC;;;;SApBU,gBAAgB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DatasourceConfig } from './datasource-config.js';
|
|
2
|
+
/**
|
|
3
|
+
* Create a Kysely dialect instance from DatasourceConfig.
|
|
4
|
+
*
|
|
5
|
+
* Dynamically imports the appropriate driver package based on `config.dialect`.
|
|
6
|
+
* The driver packages are optional peer dependencies — users install only what they need.
|
|
7
|
+
*/
|
|
8
|
+
export default function createDialect(config: DatasourceConfig): Promise<import("kysely").PostgresDialect | import("kysely").MysqlDialect | import("kysely").SqliteDialect>;
|
|
9
|
+
//# sourceMappingURL=dialect-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialect-factory.d.ts","sourceRoot":"","sources":["../src/dialect-factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG/D;;;;;GAKG;AACH,wBAA8B,aAAa,CAAC,MAAM,EAAE,gBAAgB,8GAcnE"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a Kysely dialect instance from DatasourceConfig.
|
|
3
|
+
*
|
|
4
|
+
* Dynamically imports the appropriate driver package based on `config.dialect`.
|
|
5
|
+
* The driver packages are optional peer dependencies — users install only what they need.
|
|
6
|
+
*/
|
|
7
|
+
export default async function createDialect(config) {
|
|
8
|
+
const dialect = config.dialect;
|
|
9
|
+
switch (dialect) {
|
|
10
|
+
case 'postgres':
|
|
11
|
+
return createPostgresDialect(config);
|
|
12
|
+
case 'mysql':
|
|
13
|
+
return createMysqlDialect(config);
|
|
14
|
+
case 'sqlite':
|
|
15
|
+
return createSqliteDialect(config);
|
|
16
|
+
default:
|
|
17
|
+
throw new Error(`Unsupported dialect: '${dialect}'. Supported dialects: 'postgres', 'mysql', 'sqlite'.`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async function createPostgresDialect(config) {
|
|
21
|
+
const { Pool } = await import('pg');
|
|
22
|
+
const { PostgresDialect } = await import('kysely');
|
|
23
|
+
return new PostgresDialect({
|
|
24
|
+
pool: new Pool({
|
|
25
|
+
connectionString: config.url,
|
|
26
|
+
min: config.pool.min,
|
|
27
|
+
max: config.pool.max,
|
|
28
|
+
}),
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
async function createMysqlDialect(config) {
|
|
32
|
+
const mysql2 = await import('mysql2/promise');
|
|
33
|
+
const { MysqlDialect } = await import('kysely');
|
|
34
|
+
return new MysqlDialect({
|
|
35
|
+
pool: mysql2.createPool({
|
|
36
|
+
uri: config.url,
|
|
37
|
+
connectionLimit: config.pool.max,
|
|
38
|
+
}),
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
async function createSqliteDialect(config) {
|
|
42
|
+
const BetterSqlite3 = await import('better-sqlite3');
|
|
43
|
+
const { SqliteDialect } = await import('kysely');
|
|
44
|
+
return new SqliteDialect({
|
|
45
|
+
database: new BetterSqlite3.default(config.url),
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=dialect-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialect-factory.js","sourceRoot":"","sources":["../src/dialect-factory.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,aAAa,CAAC,MAAwB;IAClE,MAAM,OAAO,GAAG,MAAM,CAAC,OAAkB,CAAC;IAC1C,QAAQ,OAAO,EAAE,CAAC;QAChB,KAAK,UAAU;YACb,OAAO,qBAAqB,CAAC,MAAM,CAAC,CAAC;QACvC,KAAK,OAAO;YACV,OAAO,kBAAkB,CAAC,MAAM,CAAC,CAAC;QACpC,KAAK,QAAQ;YACX,OAAO,mBAAmB,CAAC,MAAM,CAAC,CAAC;QACrC;YACE,MAAM,IAAI,KAAK,CACb,yBAAyB,OAAO,uDAAuD,CACxF,CAAC;IACN,CAAC;AACH,CAAC;AAED,KAAK,UAAU,qBAAqB,CAAC,MAAwB;IAC3D,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,CAAC;IACpC,MAAM,EAAE,eAAe,EAAE,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAC;IACnD,OAAO,IAAI,eAAe,CAAC;QACzB,IAAI,EAAE,IAAI,IAAI,CAAC;YACb,gBAAgB,EAAE,MAAM,CAAC,GAAG;YAC5B,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG;YACpB,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG;SACrB,CAAC;KACH,CAAC,CAAC;AACL,CAAC;AAED,KAAK,UAAU,kBAAkB,CAAC,MAAwB;IACxD,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,gBAAgB,CAAC,CAAC;IAC9C,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAC;IAChD,OAAO,IAAI,YAAY,CAAC;QACtB,IAAI,EAAE,MAAM,CAAC,UAAU,CAAC;YACtB,GAAG,EAAE,MAAM,CAAC,GAAG;YACf,eAAe,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG;SACjC,CAAC;KACH,CAAC,CAAC;AACL,CAAC;AAED,KAAK,UAAU,mBAAmB,CAAC,MAAwB;IACzD,MAAM,aAAa,GAAG,MAAM,MAAM,CAAC,gBAAgB,CAAC,CAAC;IACrD,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAC;IACjD,OAAO,IAAI,aAAa,CAAC;QACvB,QAAQ,EAAE,IAAI,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC;KAChD,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supported database dialects.
|
|
3
|
+
*
|
|
4
|
+
* Used by `DatasourceConfig` to configure the database connection
|
|
5
|
+
* and by `TransactionManager` to determine dialect capabilities
|
|
6
|
+
* like `RETURNING` clause support.
|
|
7
|
+
*/
|
|
8
|
+
export type Dialect = 'postgres' | 'mysql' | 'sqlite';
|
|
9
|
+
/** All valid dialect values. Used for validation at config injection time. */
|
|
10
|
+
export declare const DIALECTS: readonly Dialect[];
|
|
11
|
+
/**
|
|
12
|
+
* Whether the given dialect supports `RETURNING` clauses natively.
|
|
13
|
+
*
|
|
14
|
+
* - **postgres**: `INSERT/UPDATE/DELETE ... RETURNING *`
|
|
15
|
+
* - **sqlite**: `INSERT/UPDATE/DELETE ... RETURNING *` (since 3.35)
|
|
16
|
+
* - **mysql**: No native support — falls back to INSERT + SELECT
|
|
17
|
+
*/
|
|
18
|
+
export declare function supportsReturning(dialect: Dialect): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Validate that a string is a supported dialect.
|
|
21
|
+
* Throws at DI startup if the user provides an unsupported value.
|
|
22
|
+
*/
|
|
23
|
+
export declare function validateDialect(value: string): Dialect;
|
|
24
|
+
//# sourceMappingURL=dialect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialect.d.ts","sourceRoot":"","sources":["../src/dialect.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,MAAM,OAAO,GAAG,UAAU,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEtD,8EAA8E;AAC9E,eAAO,MAAM,QAAQ,EAAE,SAAS,OAAO,EAI7B,CAAC;AAEX;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAQ3D;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAOtD"}
|
package/dist/dialect.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** All valid dialect values. Used for validation at config injection time. */
|
|
2
|
+
export const DIALECTS = [
|
|
3
|
+
'postgres',
|
|
4
|
+
'mysql',
|
|
5
|
+
'sqlite',
|
|
6
|
+
];
|
|
7
|
+
/**
|
|
8
|
+
* Whether the given dialect supports `RETURNING` clauses natively.
|
|
9
|
+
*
|
|
10
|
+
* - **postgres**: `INSERT/UPDATE/DELETE ... RETURNING *`
|
|
11
|
+
* - **sqlite**: `INSERT/UPDATE/DELETE ... RETURNING *` (since 3.35)
|
|
12
|
+
* - **mysql**: No native support — falls back to INSERT + SELECT
|
|
13
|
+
*/
|
|
14
|
+
export function supportsReturning(dialect) {
|
|
15
|
+
switch (dialect) {
|
|
16
|
+
case 'postgres':
|
|
17
|
+
case 'sqlite':
|
|
18
|
+
return true;
|
|
19
|
+
case 'mysql':
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Validate that a string is a supported dialect.
|
|
25
|
+
* Throws at DI startup if the user provides an unsupported value.
|
|
26
|
+
*/
|
|
27
|
+
export function validateDialect(value) {
|
|
28
|
+
if (DIALECTS.includes(value)) {
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
throw new Error(`Unsupported datasource dialect: '${value}'. Supported dialects: ${DIALECTS.join(', ')}`);
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=dialect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialect.js","sourceRoot":"","sources":["../src/dialect.ts"],"names":[],"mappings":"AASA,8EAA8E;AAC9E,MAAM,CAAC,MAAM,QAAQ,GAAuB;IAC1C,UAAU;IACV,OAAO;IACP,QAAQ;CACA,CAAC;AAEX;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAgB;IAChD,QAAQ,OAAO,EAAE,CAAC;QAChB,KAAK,UAAU,CAAC;QAChB,KAAK,QAAQ;YACX,OAAO,IAAI,CAAC;QACd,KAAK,OAAO;YACV,OAAO,KAAK,CAAC;IACjB,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,KAAa;IAC3C,IAAI,QAAQ,CAAC,QAAQ,CAAC,KAAgB,CAAC,EAAE,CAAC;QACxC,OAAO,KAAgB,CAAC;IAC1B,CAAC;IACD,MAAM,IAAI,KAAK,CACb,oCAAoC,KAAK,0BAA0B,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACzF,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export { AbstractMigration } from './abstract-migration.js';
|
|
2
|
-
export {
|
|
2
|
+
export { DatasourceConfig, PoolConfig } from './datasource-config.js';
|
|
3
3
|
export { getMigrationName, Migration } from './decorators/migration.js';
|
|
4
4
|
export { Transactional } from './decorators/transactional.js';
|
|
5
|
+
export type { Dialect } from './dialect.js';
|
|
6
|
+
export { DIALECTS, supportsReturning, validateDialect } from './dialect.js';
|
|
7
|
+
export { KyselyDatabase } from './kysely-database.js';
|
|
5
8
|
export type { KyselyPluginOptions } from './kysely-transformer-plugin.js';
|
|
6
9
|
export { createKyselyPlugin } from './kysely-transformer-plugin.js';
|
|
7
10
|
export { MigrationRunner } from './migration-runner.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,YAAY,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,YAAY,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export { AbstractMigration } from './abstract-migration.js';
|
|
2
|
-
export {
|
|
2
|
+
export { DatasourceConfig, PoolConfig } from './datasource-config.js';
|
|
3
3
|
export { getMigrationName, Migration } from './decorators/migration.js';
|
|
4
4
|
export { Transactional } from './decorators/transactional.js';
|
|
5
|
+
export { DIALECTS, supportsReturning, validateDialect } from './dialect.js';
|
|
6
|
+
export { KyselyDatabase } from './kysely-database.js';
|
|
5
7
|
export { createKyselyPlugin } from './kysely-transformer-plugin.js';
|
|
6
8
|
export { MigrationRunner } from './migration-runner.js';
|
|
7
9
|
export { TransactionManager } from './transaction-manager.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAE9D,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import type { DatasourceConfig } from './datasource-config.js';
|
|
3
|
+
import type { Dialect } from './dialect.js';
|
|
4
|
+
/**
|
|
5
|
+
* Library-provided Kysely database singleton.
|
|
6
|
+
*
|
|
7
|
+
* Creates and manages a `Kysely<DB>` instance based on `DatasourceConfig`.
|
|
8
|
+
* Automatically selects the correct dialect driver via dynamic import:
|
|
9
|
+
* - `postgres` → `pg` + `PostgresDialect`
|
|
10
|
+
* - `mysql` → `mysql2` + `MysqlDialect`
|
|
11
|
+
* - `sqlite` → `better-sqlite3` + `SqliteDialect`
|
|
12
|
+
*
|
|
13
|
+
* Non-generic (`Kysely<any>`) by design. Users bridge to their schema
|
|
14
|
+
* type via a `@Module` with `@Provides`:
|
|
15
|
+
* ```typescript
|
|
16
|
+
* @Module()
|
|
17
|
+
* class DatabaseModule {
|
|
18
|
+
* constructor(private db: KyselyDatabase) {}
|
|
19
|
+
*
|
|
20
|
+
* @Provides()
|
|
21
|
+
* typedKysely(): Kysely<DB> {
|
|
22
|
+
* return this.db.kysely as Kysely<DB>;
|
|
23
|
+
* }
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* Repositories then inject `Kysely<DB>` for fully typed access.
|
|
28
|
+
*/
|
|
29
|
+
export declare class KyselyDatabase {
|
|
30
|
+
private readonly config;
|
|
31
|
+
kysely: Kysely<any>;
|
|
32
|
+
constructor(config: DatasourceConfig);
|
|
33
|
+
get dialect(): Dialect;
|
|
34
|
+
init(): Promise<void>;
|
|
35
|
+
destroy(): Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=kysely-database.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kysely-database.d.ts","sourceRoot":"","sources":["../src/kysely-database.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBACa,cAAc;IAGb,OAAO,CAAC,QAAQ,CAAC,MAAM;IAFnC,MAAM,EAAG,MAAM,CAAC,GAAG,CAAC,CAAC;gBAEQ,MAAM,EAAE,gBAAgB;IAErD,IAAI,OAAO,IAAI,OAAO,CAErB;IAGK,IAAI;IAQJ,OAAO;CAGd"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
2
|
+
var useValue = arguments.length > 2;
|
|
3
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
4
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
5
|
+
}
|
|
6
|
+
return useValue ? value : void 0;
|
|
7
|
+
};
|
|
8
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
9
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
10
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
11
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
12
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
13
|
+
var _, done = false;
|
|
14
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
15
|
+
var context = {};
|
|
16
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
17
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
18
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
19
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
20
|
+
if (kind === "accessor") {
|
|
21
|
+
if (result === void 0) continue;
|
|
22
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
23
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
24
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
25
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
26
|
+
}
|
|
27
|
+
else if (_ = accept(result)) {
|
|
28
|
+
if (kind === "field") initializers.unshift(_);
|
|
29
|
+
else descriptor[key] = _;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
33
|
+
done = true;
|
|
34
|
+
};
|
|
35
|
+
import { PostConstruct, PreDestroy, Singleton } from '@goodie-ts/core';
|
|
36
|
+
/**
|
|
37
|
+
* Library-provided Kysely database singleton.
|
|
38
|
+
*
|
|
39
|
+
* Creates and manages a `Kysely<DB>` instance based on `DatasourceConfig`.
|
|
40
|
+
* Automatically selects the correct dialect driver via dynamic import:
|
|
41
|
+
* - `postgres` → `pg` + `PostgresDialect`
|
|
42
|
+
* - `mysql` → `mysql2` + `MysqlDialect`
|
|
43
|
+
* - `sqlite` → `better-sqlite3` + `SqliteDialect`
|
|
44
|
+
*
|
|
45
|
+
* Non-generic (`Kysely<any>`) by design. Users bridge to their schema
|
|
46
|
+
* type via a `@Module` with `@Provides`:
|
|
47
|
+
* ```typescript
|
|
48
|
+
* @Module()
|
|
49
|
+
* class DatabaseModule {
|
|
50
|
+
* constructor(private db: KyselyDatabase) {}
|
|
51
|
+
*
|
|
52
|
+
* @Provides()
|
|
53
|
+
* typedKysely(): Kysely<DB> {
|
|
54
|
+
* return this.db.kysely as Kysely<DB>;
|
|
55
|
+
* }
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* Repositories then inject `Kysely<DB>` for fully typed access.
|
|
60
|
+
*/
|
|
61
|
+
let KyselyDatabase = (() => {
|
|
62
|
+
let _classDecorators = [Singleton()];
|
|
63
|
+
let _classDescriptor;
|
|
64
|
+
let _classExtraInitializers = [];
|
|
65
|
+
let _classThis;
|
|
66
|
+
let _instanceExtraInitializers = [];
|
|
67
|
+
let _init_decorators;
|
|
68
|
+
let _destroy_decorators;
|
|
69
|
+
var KyselyDatabase = class {
|
|
70
|
+
static { _classThis = this; }
|
|
71
|
+
static {
|
|
72
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
73
|
+
_init_decorators = [PostConstruct()];
|
|
74
|
+
_destroy_decorators = [PreDestroy()];
|
|
75
|
+
__esDecorate(this, null, _init_decorators, { kind: "method", name: "init", static: false, private: false, access: { has: obj => "init" in obj, get: obj => obj.init }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
76
|
+
__esDecorate(this, null, _destroy_decorators, { kind: "method", name: "destroy", static: false, private: false, access: { has: obj => "destroy" in obj, get: obj => obj.destroy }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
77
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
78
|
+
KyselyDatabase = _classThis = _classDescriptor.value;
|
|
79
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
80
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
81
|
+
}
|
|
82
|
+
config = __runInitializers(this, _instanceExtraInitializers);
|
|
83
|
+
kysely;
|
|
84
|
+
constructor(config) {
|
|
85
|
+
this.config = config;
|
|
86
|
+
}
|
|
87
|
+
get dialect() {
|
|
88
|
+
return this.config.dialect;
|
|
89
|
+
}
|
|
90
|
+
async init() {
|
|
91
|
+
const { default: createDialect } = await import('./dialect-factory.js');
|
|
92
|
+
const kyselyDialect = await createDialect(this.config);
|
|
93
|
+
const { Kysely } = await import('kysely');
|
|
94
|
+
this.kysely = new Kysely({ dialect: kyselyDialect });
|
|
95
|
+
}
|
|
96
|
+
async destroy() {
|
|
97
|
+
await this.kysely?.destroy();
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
return KyselyDatabase = _classThis;
|
|
101
|
+
})();
|
|
102
|
+
export { KyselyDatabase };
|
|
103
|
+
//# sourceMappingURL=kysely-database.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kysely-database.js","sourceRoot":"","sources":["../src/kysely-database.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAKvE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;IAEU,cAAc;4BAD1B,SAAS,EAAE;;;;;;;;;;;gCAUT,aAAa,EAAE;mCAQf,UAAU,EAAE;YAPb,+JAAM,IAAI,6DAKT;YAGD,wKAAM,OAAO,6DAEZ;YApBH,6KAqBC;;;YArBY,uDAAc;;QAGI,MAAM,GAHxB,mDAAc;QACzB,MAAM,CAAe;QAErB,YAA6B,MAAwB;YAAxB,WAAM,GAAN,MAAM,CAAkB;QAAG,CAAC;QAEzD,IAAI,OAAO;YACT,OAAO,IAAI,CAAC,MAAM,CAAC,OAAkB,CAAC;QACxC,CAAC;QAGD,KAAK,CAAC,IAAI;YACR,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,MAAM,MAAM,CAAC,sBAAsB,CAAC,CAAC;YACxE,MAAM,aAAa,GAAG,MAAM,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACvD,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC1C,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC,CAAC;QACvD,CAAC;QAGD,KAAK,CAAC,OAAO;YACX,MAAM,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC;QAC/B,CAAC;;;;SApBU,cAAc"}
|
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import type { TransformerPlugin } from '@goodie-ts/transformer';
|
|
2
2
|
/** Options for the Kysely transformer plugin. */
|
|
3
|
-
export
|
|
4
|
-
/**
|
|
5
|
-
* Explicit class name of the bean that provides a `Kysely<...>` property.
|
|
6
|
-
* Overrides auto-detection. Use this to disambiguate when multiple classes
|
|
7
|
-
* expose a `Kysely` property.
|
|
8
|
-
*/
|
|
9
|
-
database?: string;
|
|
10
|
-
}
|
|
3
|
+
export type KyselyPluginOptions = Record<string, never>;
|
|
11
4
|
/**
|
|
12
5
|
* Create the Kysely transformer plugin.
|
|
13
6
|
*
|
|
@@ -17,16 +10,14 @@ export interface KyselyPluginOptions {
|
|
|
17
10
|
* Scans @Migration decorated classes and wires a MigrationRunner that
|
|
18
11
|
* executes all migrations at startup via @PostConstruct.
|
|
19
12
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* and/or MigrationRunner constructor dependency. Use `options.database` to
|
|
23
|
-
* override when multiple classes expose a `Kysely` property.
|
|
13
|
+
* Wires TransactionManager and MigrationRunner using `KyselyDatabase` from
|
|
14
|
+
* library beans — no manual `database` option needed.
|
|
24
15
|
*
|
|
25
16
|
* **Limitation:** Propagation is detected via AST text matching
|
|
26
17
|
* (`text.includes('REQUIRES_NEW')`). Only string literal values in the
|
|
27
18
|
* decorator argument are supported — const references or computed values
|
|
28
19
|
* will fall back to `'REQUIRED'` silently.
|
|
29
20
|
*/
|
|
30
|
-
export declare function createKyselyPlugin(
|
|
21
|
+
export declare function createKyselyPlugin(_options?: KyselyPluginOptions): TransformerPlugin;
|
|
31
22
|
export default createKyselyPlugin;
|
|
32
23
|
//# sourceMappingURL=kysely-transformer-plugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kysely-transformer-plugin.d.ts","sourceRoot":"","sources":["../src/kysely-transformer-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAKV,iBAAiB,EAClB,MAAM,wBAAwB,CAAC;AAEhC,iDAAiD;AACjD,MAAM,
|
|
1
|
+
{"version":3,"file":"kysely-transformer-plugin.d.ts","sourceRoot":"","sources":["../src/kysely-transformer-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAKV,iBAAiB,EAClB,MAAM,wBAAwB,CAAC;AAEhC,iDAAiD;AACjD,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAexD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,CAAC,EAAE,mBAAmB,GAC7B,iBAAiB,CAwSnB;AAED,eAAe,kBAAkB,CAAC"}
|
|
@@ -7,38 +7,21 @@
|
|
|
7
7
|
* Scans @Migration decorated classes and wires a MigrationRunner that
|
|
8
8
|
* executes all migrations at startup via @PostConstruct.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* and/or MigrationRunner constructor dependency. Use `options.database` to
|
|
13
|
-
* override when multiple classes expose a `Kysely` property.
|
|
10
|
+
* Wires TransactionManager and MigrationRunner using `KyselyDatabase` from
|
|
11
|
+
* library beans — no manual `database` option needed.
|
|
14
12
|
*
|
|
15
13
|
* **Limitation:** Propagation is detected via AST text matching
|
|
16
14
|
* (`text.includes('REQUIRES_NEW')`). Only string literal values in the
|
|
17
15
|
* decorator argument are supported — const references or computed values
|
|
18
16
|
* will fall back to `'REQUIRED'` silently.
|
|
19
17
|
*/
|
|
20
|
-
export function createKyselyPlugin(
|
|
18
|
+
export function createKyselyPlugin(_options) {
|
|
21
19
|
const classTransactionalInfo = new Map();
|
|
22
|
-
/** Classes discovered with a `Kysely<...>` property. Keyed by filePath:className. */
|
|
23
|
-
const kyselyProviders = [];
|
|
24
20
|
/** @Migration decorated classes discovered during visitClass. */
|
|
25
21
|
const migrationClasses = [];
|
|
26
22
|
return {
|
|
27
23
|
name: 'kysely',
|
|
28
24
|
visitClass(ctx) {
|
|
29
|
-
// Detect Kysely<...> properties for auto-wiring
|
|
30
|
-
for (const prop of ctx.classDeclaration.getProperties()) {
|
|
31
|
-
// Check the type annotation text (AST-level), not the resolved type.
|
|
32
|
-
// This avoids requiring the 'kysely' package to be resolvable at transform time.
|
|
33
|
-
const typeAnnotation = prop.getTypeNode()?.getText();
|
|
34
|
-
if (typeAnnotation?.startsWith('Kysely<')) {
|
|
35
|
-
kyselyProviders.push({
|
|
36
|
-
className: ctx.className,
|
|
37
|
-
filePath: ctx.filePath,
|
|
38
|
-
});
|
|
39
|
-
break; // one match per class is enough
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
25
|
// Detect @Migration('name') class decorator
|
|
43
26
|
for (const decorator of ctx.classDeclaration.getDecorators()) {
|
|
44
27
|
if (decorator.getName() !== 'Migration')
|
|
@@ -110,9 +93,28 @@ export function createKyselyPlugin(options) {
|
|
|
110
93
|
const hasMigrations = migrationClasses.length > 0;
|
|
111
94
|
if (!needsInterceptor && !hasMigrations)
|
|
112
95
|
return beans;
|
|
113
|
-
//
|
|
114
|
-
|
|
115
|
-
|
|
96
|
+
// Find KyselyDatabase from library beans for auto-wiring.
|
|
97
|
+
const kyselyDatabaseBean = beans.find((b) => b.tokenRef.kind === 'class' &&
|
|
98
|
+
b.tokenRef.className === 'KyselyDatabase' &&
|
|
99
|
+
b.tokenRef.importPath === '@goodie-ts/kysely');
|
|
100
|
+
const kyselyProviderDep = kyselyDatabaseBean && kyselyDatabaseBean.tokenRef.kind === 'class'
|
|
101
|
+
? [
|
|
102
|
+
{
|
|
103
|
+
tokenRef: {
|
|
104
|
+
kind: 'class',
|
|
105
|
+
className: 'KyselyDatabase',
|
|
106
|
+
importPath: '@goodie-ts/kysely',
|
|
107
|
+
},
|
|
108
|
+
optional: false,
|
|
109
|
+
collection: false,
|
|
110
|
+
sourceLocation: {
|
|
111
|
+
filePath: '@goodie-ts/kysely',
|
|
112
|
+
line: 0,
|
|
113
|
+
column: 0,
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
]
|
|
117
|
+
: [];
|
|
116
118
|
// --- Transactional synthetic beans ---
|
|
117
119
|
if (needsInterceptor) {
|
|
118
120
|
syntheticBeans.push({
|
|
@@ -259,57 +261,5 @@ export function createKyselyPlugin(options) {
|
|
|
259
261
|
},
|
|
260
262
|
};
|
|
261
263
|
}
|
|
262
|
-
/**
|
|
263
|
-
* Resolve which bean provides the Kysely instance for TransactionManager auto-wiring.
|
|
264
|
-
*
|
|
265
|
-
* Priority:
|
|
266
|
-
* 1. Explicit `database` option (string class name)
|
|
267
|
-
* 2. Auto-detected class with a `Kysely<...>` property (single match)
|
|
268
|
-
* 3. No wiring (zero matches, or multiple matches without explicit option)
|
|
269
|
-
*/
|
|
270
|
-
function resolveKyselyProvider(beans, explicitDatabase, autoDetected) {
|
|
271
|
-
// Determine target class name
|
|
272
|
-
let targetClassName;
|
|
273
|
-
if (explicitDatabase) {
|
|
274
|
-
targetClassName = explicitDatabase;
|
|
275
|
-
}
|
|
276
|
-
else if (autoDetected.length === 1) {
|
|
277
|
-
targetClassName = autoDetected[0].className;
|
|
278
|
-
}
|
|
279
|
-
else if (autoDetected.length > 1) {
|
|
280
|
-
const names = autoDetected.map((p) => p.className).join(', ');
|
|
281
|
-
console.warn(`[@goodie-ts/kysely] Multiple Kysely providers detected: ${names}. ` +
|
|
282
|
-
"Use createKyselyPlugin({ database: 'ClassName' }) to disambiguate. " +
|
|
283
|
-
'TransactionManager will require manual configure().');
|
|
284
|
-
return [];
|
|
285
|
-
}
|
|
286
|
-
else {
|
|
287
|
-
// Zero providers — no auto-wiring
|
|
288
|
-
return [];
|
|
289
|
-
}
|
|
290
|
-
// Find the bean matching the target class name
|
|
291
|
-
const databaseBean = beans.find((b) => b.tokenRef.kind === 'class' && b.tokenRef.className === targetClassName);
|
|
292
|
-
if (databaseBean && databaseBean.tokenRef.kind === 'class') {
|
|
293
|
-
return [
|
|
294
|
-
{
|
|
295
|
-
tokenRef: {
|
|
296
|
-
kind: 'class',
|
|
297
|
-
className: databaseBean.tokenRef.className,
|
|
298
|
-
importPath: databaseBean.tokenRef.importPath,
|
|
299
|
-
},
|
|
300
|
-
optional: false,
|
|
301
|
-
collection: false,
|
|
302
|
-
sourceLocation: {
|
|
303
|
-
filePath: '@goodie-ts/kysely',
|
|
304
|
-
line: 0,
|
|
305
|
-
column: 0,
|
|
306
|
-
},
|
|
307
|
-
},
|
|
308
|
-
];
|
|
309
|
-
}
|
|
310
|
-
console.warn(`[@goodie-ts/kysely] Database class '${targetClassName}' not found in beans. ` +
|
|
311
|
-
'TransactionManager will require manual configure().');
|
|
312
|
-
return [];
|
|
313
|
-
}
|
|
314
264
|
export default createKyselyPlugin;
|
|
315
265
|
//# sourceMappingURL=kysely-transformer-plugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kysely-transformer-plugin.js","sourceRoot":"","sources":["../src/kysely-transformer-plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"kysely-transformer-plugin.js","sourceRoot":"","sources":["../src/kysely-transformer-plugin.ts"],"names":[],"mappings":"AAwBA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,kBAAkB,CAChC,QAA8B;IAE9B,MAAM,sBAAsB,GAAG,IAAI,GAAG,EAAqC,CAAC;IAE5E,iEAAiE;IACjE,MAAM,gBAAgB,GAAyB,EAAE,CAAC;IAElD,OAAO;QACL,IAAI,EAAE,QAAQ;QAEd,UAAU,CAAC,GAAwB;YACjC,4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4D;YAC5D,OAAO;gBACL,OAAO,EAAE,CAAC,yDAAyD,CAAC;aACrE,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC;AAED,eAAe,kBAAkB,CAAC"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { Kysely, Transaction } from 'kysely';
|
|
2
|
+
import type { Dialect } from './dialect.js';
|
|
2
3
|
/**
|
|
3
|
-
* An object that exposes a `.kysely` property — e.g. a
|
|
4
|
+
* An object that exposes a `.kysely` property — e.g. KyselyDatabase or a custom wrapper.
|
|
4
5
|
* Used for duck-type detection in the TransactionManager constructor.
|
|
5
6
|
*/
|
|
6
7
|
export interface KyselyProvider {
|
|
7
8
|
kysely: Kysely<any>;
|
|
9
|
+
dialect?: Dialect;
|
|
8
10
|
}
|
|
9
11
|
/**
|
|
10
12
|
* Manages database transactions using AsyncLocalStorage.
|
|
@@ -12,20 +14,21 @@ export interface KyselyProvider {
|
|
|
12
14
|
* Provides transaction propagation across async call chains without
|
|
13
15
|
* explicitly threading a transaction object through every method.
|
|
14
16
|
*
|
|
15
|
-
* When auto-wired via `createKyselyPlugin(
|
|
16
|
-
* the
|
|
17
|
+
* When auto-wired via `createKyselyPlugin()`, the constructor receives
|
|
18
|
+
* the KyselyDatabase bean and reads its `.kysely` property.
|
|
17
19
|
* Manual `configure()` is still supported for backward compatibility.
|
|
18
20
|
*/
|
|
19
21
|
export declare class TransactionManager {
|
|
20
22
|
private readonly storage;
|
|
21
23
|
private kyselyRef?;
|
|
22
24
|
private testTransactionActive;
|
|
23
|
-
|
|
25
|
+
private _supportsReturning?;
|
|
26
|
+
constructor(kyselyOrProvider?: Kysely<any> | KyselyProvider, dialect?: Dialect);
|
|
24
27
|
/**
|
|
25
28
|
* Configure the Kysely instance used for transactions.
|
|
26
|
-
*
|
|
29
|
+
* Called by KyselyDatabase after creating the Kysely instance in @PostConstruct.
|
|
27
30
|
*/
|
|
28
|
-
configure(kysely: Kysely<any
|
|
31
|
+
configure(kysely: Kysely<any>, dialect: Dialect): void;
|
|
29
32
|
private get kysely();
|
|
30
33
|
/**
|
|
31
34
|
* Run a function inside a transaction.
|
|
@@ -41,6 +44,11 @@ export declare class TransactionManager {
|
|
|
41
44
|
* Returns the active transaction if inside one, otherwise the raw Kysely instance.
|
|
42
45
|
*/
|
|
43
46
|
getConnection(): Kysely<any>;
|
|
47
|
+
/**
|
|
48
|
+
* Whether the underlying dialect supports RETURNING clauses.
|
|
49
|
+
* Eagerly derived at construction / configure time.
|
|
50
|
+
*/
|
|
51
|
+
get supportsReturning(): boolean;
|
|
44
52
|
/**
|
|
45
53
|
* Start a test-scoped transaction that ALL queries will use.
|
|
46
54
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction-manager.d.ts","sourceRoot":"","sources":["../src/transaction-manager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"transaction-manager.d.ts","sourceRoot":"","sources":["../src/transaction-manager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAG5C;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;GASG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA6C;IACrE,OAAO,CAAC,SAAS,CAAC,CAAc;IAChC,OAAO,CAAC,qBAAqB,CAAS;IACtC,OAAO,CAAC,kBAAkB,CAAC,CAAU;gBAGnC,gBAAgB,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,GAAG,cAAc,EAC/C,OAAO,CAAC,EAAE,OAAO;IAkCnB;;;OAGG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;IAKtD,OAAO,KAAK,MAAM,GAOjB;IAED;;;;;OAKG;IACG,gBAAgB,CAAC,CAAC,EACtB,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,WAAW,UAAQ,GAClB,OAAO,CAAC,CAAC,CAAC;IAiBb,+DAA+D;IAC/D,kBAAkB,IAAI,WAAW,CAAC,GAAG,CAAC,GAAG,SAAS;IAIlD;;;OAGG;IACH,aAAa,IAAI,MAAM,CAAC,GAAG,CAAC;IAI5B;;;OAGG;IACH,IAAI,iBAAiB,IAAI,OAAO,CAO/B;IAED;;;;;;;;;;;;OAYG;IACG,oBAAoB,IAAI,OAAO,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAmC3D"}
|
|
@@ -1,44 +1,59 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
import { supportsReturning as dialectSupportsReturning } from './dialect.js';
|
|
2
3
|
/**
|
|
3
4
|
* Manages database transactions using AsyncLocalStorage.
|
|
4
5
|
*
|
|
5
6
|
* Provides transaction propagation across async call chains without
|
|
6
7
|
* explicitly threading a transaction object through every method.
|
|
7
8
|
*
|
|
8
|
-
* When auto-wired via `createKyselyPlugin(
|
|
9
|
-
* the
|
|
9
|
+
* When auto-wired via `createKyselyPlugin()`, the constructor receives
|
|
10
|
+
* the KyselyDatabase bean and reads its `.kysely` property.
|
|
10
11
|
* Manual `configure()` is still supported for backward compatibility.
|
|
11
12
|
*/
|
|
12
13
|
export class TransactionManager {
|
|
13
14
|
storage = new AsyncLocalStorage();
|
|
14
15
|
kyselyRef;
|
|
15
16
|
testTransactionActive = false;
|
|
16
|
-
|
|
17
|
+
_supportsReturning;
|
|
18
|
+
constructor(kyselyOrProvider, dialect) {
|
|
17
19
|
if (kyselyOrProvider) {
|
|
18
20
|
if ('kysely' in kyselyOrProvider) {
|
|
21
|
+
// Capture the current value (may already be set if @PostConstruct ran)
|
|
19
22
|
this.kyselyRef = kyselyOrProvider.kysely;
|
|
20
23
|
// Make the provider's .kysely property transaction-aware.
|
|
21
24
|
// Any code accessing provider.kysely (e.g. database.kysely) will
|
|
22
25
|
// automatically use the active transaction when inside one.
|
|
26
|
+
// The setter ensures @PostConstruct can still assign the value.
|
|
23
27
|
const tm = this;
|
|
24
28
|
Object.defineProperty(kyselyOrProvider, 'kysely', {
|
|
25
29
|
get() {
|
|
26
30
|
return tm.getConnection();
|
|
27
31
|
},
|
|
32
|
+
set(value) {
|
|
33
|
+
tm.kyselyRef = value;
|
|
34
|
+
},
|
|
28
35
|
configurable: true,
|
|
29
36
|
});
|
|
30
37
|
}
|
|
31
38
|
else {
|
|
32
39
|
this.kyselyRef = kyselyOrProvider;
|
|
33
40
|
}
|
|
41
|
+
const resolvedDialect = dialect ??
|
|
42
|
+
('dialect' in kyselyOrProvider
|
|
43
|
+
? kyselyOrProvider.dialect
|
|
44
|
+
: undefined);
|
|
45
|
+
if (resolvedDialect) {
|
|
46
|
+
this._supportsReturning = dialectSupportsReturning(resolvedDialect);
|
|
47
|
+
}
|
|
34
48
|
}
|
|
35
49
|
}
|
|
36
50
|
/**
|
|
37
51
|
* Configure the Kysely instance used for transactions.
|
|
38
|
-
*
|
|
52
|
+
* Called by KyselyDatabase after creating the Kysely instance in @PostConstruct.
|
|
39
53
|
*/
|
|
40
|
-
configure(kysely) {
|
|
54
|
+
configure(kysely, dialect) {
|
|
41
55
|
this.kyselyRef = kysely;
|
|
56
|
+
this._supportsReturning = dialectSupportsReturning(dialect);
|
|
42
57
|
}
|
|
43
58
|
get kysely() {
|
|
44
59
|
if (!this.kyselyRef) {
|
|
@@ -77,6 +92,16 @@ export class TransactionManager {
|
|
|
77
92
|
getConnection() {
|
|
78
93
|
return this.currentTransaction() ?? this.kysely;
|
|
79
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Whether the underlying dialect supports RETURNING clauses.
|
|
97
|
+
* Eagerly derived at construction / configure time.
|
|
98
|
+
*/
|
|
99
|
+
get supportsReturning() {
|
|
100
|
+
if (this._supportsReturning === undefined) {
|
|
101
|
+
throw new Error('TransactionManager not configured. Call configure(kysely) or pass a Kysely instance to the constructor.');
|
|
102
|
+
}
|
|
103
|
+
return this._supportsReturning;
|
|
104
|
+
}
|
|
80
105
|
/**
|
|
81
106
|
* Start a test-scoped transaction that ALL queries will use.
|
|
82
107
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction-manager.js","sourceRoot":"","sources":["../src/transaction-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"transaction-manager.js","sourceRoot":"","sources":["../src/transaction-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,OAAO,EAAE,iBAAiB,IAAI,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAW7E;;;;;;;;;GASG;AACH,MAAM,OAAO,kBAAkB;IACZ,OAAO,GAAG,IAAI,iBAAiB,EAAoB,CAAC;IAC7D,SAAS,CAAe;IACxB,qBAAqB,GAAG,KAAK,CAAC;IAC9B,kBAAkB,CAAW;IAErC,YACE,gBAA+C,EAC/C,OAAiB;QAEjB,IAAI,gBAAgB,EAAE,CAAC;YACrB,IAAI,QAAQ,IAAI,gBAAgB,EAAE,CAAC;gBACjC,uEAAuE;gBACvE,IAAI,CAAC,SAAS,GAAG,gBAAgB,CAAC,MAAM,CAAC;gBACzC,0DAA0D;gBAC1D,iEAAiE;gBACjE,4DAA4D;gBAC5D,gEAAgE;gBAChE,MAAM,EAAE,GAAG,IAAI,CAAC;gBAChB,MAAM,CAAC,cAAc,CAAC,gBAAgB,EAAE,QAAQ,EAAE;oBAChD,GAAG;wBACD,OAAO,EAAE,CAAC,aAAa,EAAE,CAAC;oB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C,CAAC;QACL,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,CAAU,EAAE,EAAE;YACpB,IAAI,CAAC,CAAC,CAAC,YAAY,kBAAkB,CAAC;gBAAE,MAAM,CAAC,CAAC;QAClD,CAAC,CAAC;aACD,OAAO,CAAC,GAAG,EAAE;YACZ,IAAI,CAAC,qBAAqB,GAAG,KAAK,CAAC;YACnC,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC5B,CAAC,CAAC,CAAC;QAEL,MAAM,YAAY,CAAC;QAEnB,OAAO,KAAK,IAAI,EAAE;YAChB,eAAe,EAAE,CAAC;YAClB,MAAM,eAAe,CAAC;QACxB,CAAC,CAAC;IACJ,CAAC;CACF;AAED,8DAA8D;AAC9D,MAAM,kBAAmB,SAAQ,KAAK;IACpC;QACE,KAAK,CAAC,oBAAoB,CAAC,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goodie-ts/kysely",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Kysely integration for goodie-ts — @Transactional decorator, TransactionManager,
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"description": "Kysely integration for goodie-ts — @Transactional decorator, TransactionManager, KyselyDatabase",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"repository": {
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"access": "public"
|
|
14
14
|
},
|
|
15
15
|
"goodie": {
|
|
16
|
+
"beans": "dist/beans.json",
|
|
16
17
|
"plugin": "./dist/kysely-transformer-plugin.js"
|
|
17
18
|
},
|
|
18
19
|
"main": "dist/index.js",
|
|
@@ -24,22 +25,42 @@
|
|
|
24
25
|
}
|
|
25
26
|
},
|
|
26
27
|
"dependencies": {
|
|
27
|
-
"@goodie-ts/core": "^0.
|
|
28
|
+
"@goodie-ts/core": "^0.8.0"
|
|
28
29
|
},
|
|
29
30
|
"peerDependencies": {
|
|
30
|
-
"kysely": ">=0.27.0"
|
|
31
|
+
"kysely": ">=0.27.0",
|
|
32
|
+
"pg": ">=8.0.0",
|
|
33
|
+
"mysql2": ">=3.0.0",
|
|
34
|
+
"better-sqlite3": ">=9.0.0"
|
|
35
|
+
},
|
|
36
|
+
"peerDependenciesMeta": {
|
|
37
|
+
"pg": {
|
|
38
|
+
"optional": true
|
|
39
|
+
},
|
|
40
|
+
"mysql2": {
|
|
41
|
+
"optional": true
|
|
42
|
+
},
|
|
43
|
+
"better-sqlite3": {
|
|
44
|
+
"optional": true
|
|
45
|
+
}
|
|
31
46
|
},
|
|
32
47
|
"devDependencies": {
|
|
48
|
+
"@types/better-sqlite3": "^7.0.0",
|
|
33
49
|
"@types/node": "^22.0.0",
|
|
50
|
+
"@types/pg": "^8.0.0",
|
|
51
|
+
"better-sqlite3": "^9.0.0",
|
|
34
52
|
"kysely": "^0.27.0",
|
|
53
|
+
"mysql2": "^3.0.0",
|
|
54
|
+
"pg": "^8.0.0",
|
|
35
55
|
"ts-morph": "^24.0.0",
|
|
36
|
-
"@goodie-ts/
|
|
56
|
+
"@goodie-ts/cli": "0.6.3",
|
|
57
|
+
"@goodie-ts/transformer": "0.9.1"
|
|
37
58
|
},
|
|
38
59
|
"files": [
|
|
39
60
|
"dist"
|
|
40
61
|
],
|
|
41
62
|
"scripts": {
|
|
42
|
-
"build": "tsc",
|
|
63
|
+
"build": "tsc && goodie generate --mode library",
|
|
43
64
|
"clean": "rm -rf dist *.tsbuildinfo"
|
|
44
65
|
}
|
|
45
66
|
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { Kysely } from 'kysely';
|
|
2
|
-
import type { TransactionManager } from './transaction-manager.js';
|
|
3
|
-
/**
|
|
4
|
-
* Abstract base class for CRUD repositories backed by Kysely.
|
|
5
|
-
*
|
|
6
|
-
* **PostgreSQL-only:** Uses `RETURNING` clauses in `save()` and `deleteById()`.
|
|
7
|
-
* MySQL and SQLite do not support `RETURNING`. For other dialects, override
|
|
8
|
-
* these methods in your subclass.
|
|
9
|
-
*
|
|
10
|
-
* Provides standard `findAll`, `findById`, `save`, and `deleteById` operations.
|
|
11
|
-
* All queries use `TransactionManager.getConnection()` to be transaction-aware.
|
|
12
|
-
*
|
|
13
|
-
* The `db` getter returns `Kysely<any>` — typed table access is intentionally
|
|
14
|
-
* erased because the transformer cannot generate clean tokens for `Kysely<DB>`
|
|
15
|
-
* generic types. Subclasses can cast as needed for custom queries.
|
|
16
|
-
*
|
|
17
|
-
* @typeParam T - The entity/row type returned by queries.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```typescript
|
|
21
|
-
* class TodoRepository extends CrudRepository<Todo> {
|
|
22
|
-
* constructor(transactionManager: TransactionManager) {
|
|
23
|
-
* super('todos', transactionManager);
|
|
24
|
-
* }
|
|
25
|
-
* }
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
export declare abstract class CrudRepository<T extends Record<string, unknown>> {
|
|
29
|
-
protected readonly tableName: string;
|
|
30
|
-
protected readonly transactionManager: TransactionManager;
|
|
31
|
-
protected readonly idColumn: string;
|
|
32
|
-
constructor(tableName: string, transactionManager: TransactionManager, idColumn?: string);
|
|
33
|
-
/** Get the current transaction-aware Kysely connection. */
|
|
34
|
-
protected get db(): Kysely<any>;
|
|
35
|
-
findAll(): Promise<T[]>;
|
|
36
|
-
findById(id: unknown): Promise<T | undefined>;
|
|
37
|
-
save(entity: Record<string, unknown>): Promise<T>;
|
|
38
|
-
deleteById(id: unknown): Promise<T | undefined>;
|
|
39
|
-
}
|
|
40
|
-
//# sourceMappingURL=crud-repository.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"crud-repository.d.ts","sourceRoot":"","sources":["../src/crud-repository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAEnE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,8BAAsB,cAAc,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAElE,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,MAAM;IACpC,SAAS,CAAC,QAAQ,CAAC,kBAAkB,EAAE,kBAAkB;IACzD,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM;gBAFhB,SAAS,EAAE,MAAM,EACjB,kBAAkB,EAAE,kBAAkB,EACtC,QAAQ,GAAE,MAAa;IAG5C,2DAA2D;IAC3D,SAAS,KAAK,EAAE,IAAI,MAAM,CAAC,GAAG,CAAC,CAE9B;IAEK,OAAO,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC;IAMvB,QAAQ,CAAC,EAAE,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAQ7C,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAQjD,UAAU,CAAC,EAAE,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;CAOtD"}
|
package/dist/crud-repository.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Abstract base class for CRUD repositories backed by Kysely.
|
|
3
|
-
*
|
|
4
|
-
* **PostgreSQL-only:** Uses `RETURNING` clauses in `save()` and `deleteById()`.
|
|
5
|
-
* MySQL and SQLite do not support `RETURNING`. For other dialects, override
|
|
6
|
-
* these methods in your subclass.
|
|
7
|
-
*
|
|
8
|
-
* Provides standard `findAll`, `findById`, `save`, and `deleteById` operations.
|
|
9
|
-
* All queries use `TransactionManager.getConnection()` to be transaction-aware.
|
|
10
|
-
*
|
|
11
|
-
* The `db` getter returns `Kysely<any>` — typed table access is intentionally
|
|
12
|
-
* erased because the transformer cannot generate clean tokens for `Kysely<DB>`
|
|
13
|
-
* generic types. Subclasses can cast as needed for custom queries.
|
|
14
|
-
*
|
|
15
|
-
* @typeParam T - The entity/row type returned by queries.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```typescript
|
|
19
|
-
* class TodoRepository extends CrudRepository<Todo> {
|
|
20
|
-
* constructor(transactionManager: TransactionManager) {
|
|
21
|
-
* super('todos', transactionManager);
|
|
22
|
-
* }
|
|
23
|
-
* }
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
export class CrudRepository {
|
|
27
|
-
tableName;
|
|
28
|
-
transactionManager;
|
|
29
|
-
idColumn;
|
|
30
|
-
constructor(tableName, transactionManager, idColumn = 'id') {
|
|
31
|
-
this.tableName = tableName;
|
|
32
|
-
this.transactionManager = transactionManager;
|
|
33
|
-
this.idColumn = idColumn;
|
|
34
|
-
}
|
|
35
|
-
/** Get the current transaction-aware Kysely connection. */
|
|
36
|
-
get db() {
|
|
37
|
-
return this.transactionManager.getConnection();
|
|
38
|
-
}
|
|
39
|
-
async findAll() {
|
|
40
|
-
return this.db.selectFrom(this.tableName).selectAll().execute();
|
|
41
|
-
}
|
|
42
|
-
async findById(id) {
|
|
43
|
-
return this.db
|
|
44
|
-
.selectFrom(this.tableName)
|
|
45
|
-
.selectAll()
|
|
46
|
-
.where(this.idColumn, '=', id)
|
|
47
|
-
.executeTakeFirst();
|
|
48
|
-
}
|
|
49
|
-
async save(entity) {
|
|
50
|
-
return this.db
|
|
51
|
-
.insertInto(this.tableName)
|
|
52
|
-
.values(entity)
|
|
53
|
-
.returningAll()
|
|
54
|
-
.executeTakeFirstOrThrow();
|
|
55
|
-
}
|
|
56
|
-
async deleteById(id) {
|
|
57
|
-
return this.db
|
|
58
|
-
.deleteFrom(this.tableName)
|
|
59
|
-
.where(this.idColumn, '=', id)
|
|
60
|
-
.returningAll()
|
|
61
|
-
.executeTakeFirst();
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
//# sourceMappingURL=crud-repository.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"crud-repository.js","sourceRoot":"","sources":["../src/crud-repository.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,OAAgB,cAAc;IAEb;IACA;IACA;IAHrB,YACqB,SAAiB,EACjB,kBAAsC,EACtC,WAAmB,IAAI;QAFvB,cAAS,GAAT,SAAS,CAAQ;QACjB,uBAAkB,GAAlB,kBAAkB,CAAoB;QACtC,aAAQ,GAAR,QAAQ,CAAe;IACzC,CAAC;IAEJ,2DAA2D;IAC3D,IAAc,EAAE;QACd,OAAO,IAAI,CAAC,kBAAkB,CAAC,aAAa,EAAiB,CAAC;IAChE,CAAC;IAED,KAAK,CAAC,OAAO;QACX,OAAO,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,CAAC,OAAO,EAE5D,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,EAAW;QACxB,OAAO,IAAI,CAAC,EAAE;aACX,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC;aAC1B,SAAS,EAAE;aACX,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,EAAE,EAAE,CAAC;aAC7B,gBAAgB,EAA4B,CAAC;IAClD,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,MAA+B;QACxC,OAAO,IAAI,CAAC,EAAE;aACX,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC;aAC1B,MAAM,CAAC,MAAM,CAAC;aACd,YAAY,EAAE;aACd,uBAAuB,EAAgB,CAAC;IAC7C,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,EAAW;QAC1B,OAAO,IAAI,CAAC,EAAE;aACX,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC;aAC1B,KAAK,CAAC,IAAI,CAAC,QA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