@goodie-ts/kysely 0.5.4 → 0.6.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/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, and a CRUD repository base class.
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 `CrudRepository<T>` for common CRUD operations. All backed by `TransactionManager` which uses `AsyncLocalStorage` for transaction propagation.
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 { Transactional, CrudRepository, TransactionManager } from '@goodie-ts/kysely';
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 extends CrudRepository<Todo> {
30
- constructor(transactionManager: TransactionManager) {
31
- super('todos', transactionManager);
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.save({ title, completed: false });
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 `database` option specifies the class name of your Kysely wrapper (a `@Singleton` with a `.kysely` property).
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
 
@@ -0,0 +1,184 @@
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
+ "decorators": [
20
+ {
21
+ "name": "Singleton",
22
+ "importPath": "@goodie-ts/kysely"
23
+ },
24
+ {
25
+ "name": "ConfigurationProperties",
26
+ "importPath": "@goodie-ts/kysely"
27
+ }
28
+ ],
29
+ "methodDecorators": null,
30
+ "metadata": {
31
+ "valueFields": [
32
+ {
33
+ "fieldName": "min",
34
+ "key": "datasource.pool.min",
35
+ "default": "2"
36
+ },
37
+ {
38
+ "fieldName": "max",
39
+ "key": "datasource.pool.max",
40
+ "default": "10"
41
+ }
42
+ ]
43
+ },
44
+ "sourceLocation": {
45
+ "filePath": "@goodie-ts/kysely",
46
+ "line": 11,
47
+ "column": 1
48
+ }
49
+ },
50
+ {
51
+ "tokenRef": {
52
+ "kind": "class",
53
+ "className": "DatasourceConfig",
54
+ "importPath": "@goodie-ts/kysely"
55
+ },
56
+ "scope": "singleton",
57
+ "eager": false,
58
+ "name": null,
59
+ "constructorDeps": [
60
+ {
61
+ "tokenRef": {
62
+ "kind": "class",
63
+ "className": "PoolConfig",
64
+ "importPath": "@goodie-ts/kysely"
65
+ },
66
+ "optional": false,
67
+ "collection": false,
68
+ "sourceLocation": {
69
+ "filePath": "@goodie-ts/kysely",
70
+ "line": 40,
71
+ "column": 15
72
+ }
73
+ }
74
+ ],
75
+ "fieldDeps": [],
76
+ "factoryKind": "constructor",
77
+ "providesSource": null,
78
+ "baseTokenRefs": null,
79
+ "decorators": [
80
+ {
81
+ "name": "Singleton",
82
+ "importPath": "@goodie-ts/kysely"
83
+ },
84
+ {
85
+ "name": "ConfigurationProperties",
86
+ "importPath": "@goodie-ts/kysely"
87
+ }
88
+ ],
89
+ "methodDecorators": {
90
+ "validate": [
91
+ {
92
+ "name": "PostConstruct",
93
+ "importPath": "@goodie-ts/kysely"
94
+ }
95
+ ]
96
+ },
97
+ "metadata": {
98
+ "postConstructMethods": [
99
+ "validate"
100
+ ],
101
+ "valueFields": [
102
+ {
103
+ "fieldName": "url",
104
+ "key": "datasource.url",
105
+ "default": "''"
106
+ },
107
+ {
108
+ "fieldName": "dialect",
109
+ "key": "datasource.dialect",
110
+ "default": "''"
111
+ }
112
+ ]
113
+ },
114
+ "sourceLocation": {
115
+ "filePath": "@goodie-ts/kysely",
116
+ "line": 34,
117
+ "column": 1
118
+ }
119
+ },
120
+ {
121
+ "tokenRef": {
122
+ "kind": "class",
123
+ "className": "KyselyDatabase",
124
+ "importPath": "@goodie-ts/kysely"
125
+ },
126
+ "scope": "singleton",
127
+ "eager": false,
128
+ "name": null,
129
+ "constructorDeps": [
130
+ {
131
+ "tokenRef": {
132
+ "kind": "class",
133
+ "className": "DatasourceConfig",
134
+ "importPath": "@goodie-ts/kysely"
135
+ },
136
+ "optional": false,
137
+ "collection": false,
138
+ "sourceLocation": {
139
+ "filePath": "@goodie-ts/kysely",
140
+ "line": 35,
141
+ "column": 15
142
+ }
143
+ }
144
+ ],
145
+ "fieldDeps": [],
146
+ "factoryKind": "constructor",
147
+ "providesSource": null,
148
+ "baseTokenRefs": null,
149
+ "decorators": [
150
+ {
151
+ "name": "Singleton",
152
+ "importPath": "@goodie-ts/kysely"
153
+ }
154
+ ],
155
+ "methodDecorators": {
156
+ "init": [
157
+ {
158
+ "name": "PostConstruct",
159
+ "importPath": "@goodie-ts/kysely"
160
+ }
161
+ ],
162
+ "destroy": [
163
+ {
164
+ "name": "PreDestroy",
165
+ "importPath": "@goodie-ts/kysely"
166
+ }
167
+ ]
168
+ },
169
+ "metadata": {
170
+ "preDestroyMethods": [
171
+ "destroy"
172
+ ],
173
+ "postConstructMethods": [
174
+ "init"
175
+ ]
176
+ },
177
+ "sourceLocation": {
178
+ "filePath": "@goodie-ts/kysely",
179
+ "line": 31,
180
+ "column": 1
181
+ }
182
+ }
183
+ ]
184
+ }
@@ -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"}
@@ -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 { CrudRepository } from './crud-repository.js';
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';
@@ -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,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,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"}
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 { CrudRepository } from './crud-repository.js';
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,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAE9D,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"}
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"}