@goodie-ts/kysely 0.7.0 → 2.0.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.
Files changed (82) hide show
  1. package/README.md +18 -2
  2. package/dist/abstract-migration.d.ts +2 -2
  3. package/dist/abstract-migration.js +2 -2
  4. package/dist/components.json +1854 -0
  5. package/dist/decorators/migration.d.ts +1 -1
  6. package/dist/decorators/migration.js +1 -1
  7. package/dist/dialect.d.ts +4 -18
  8. package/dist/dialect.d.ts.map +1 -1
  9. package/dist/dialect.js +5 -27
  10. package/dist/dialect.js.map +1 -1
  11. package/dist/dialects/d1.d.ts +23 -0
  12. package/dist/dialects/d1.d.ts.map +1 -0
  13. package/dist/dialects/d1.js +126 -0
  14. package/dist/dialects/d1.js.map +1 -0
  15. package/dist/dialects/index.d.ts +8 -0
  16. package/dist/dialects/index.d.ts.map +1 -0
  17. package/dist/dialects/index.js +8 -0
  18. package/dist/dialects/index.js.map +1 -0
  19. package/dist/dialects/libsql.d.ts +19 -0
  20. package/dist/dialects/libsql.d.ts.map +1 -0
  21. package/dist/dialects/libsql.js +129 -0
  22. package/dist/dialects/libsql.js.map +1 -0
  23. package/dist/dialects/mysql.d.ts +24 -0
  24. package/dist/dialects/mysql.d.ts.map +1 -0
  25. package/dist/dialects/mysql.js +141 -0
  26. package/dist/dialects/mysql.js.map +1 -0
  27. package/dist/dialects/neon.d.ts +17 -0
  28. package/dist/dialects/neon.d.ts.map +1 -0
  29. package/dist/dialects/neon.js +126 -0
  30. package/dist/dialects/neon.js.map +1 -0
  31. package/dist/dialects/planetscale.d.ts +20 -0
  32. package/dist/dialects/planetscale.d.ts.map +1 -0
  33. package/dist/dialects/planetscale.js +132 -0
  34. package/dist/dialects/planetscale.js.map +1 -0
  35. package/dist/dialects/postgres.d.ts +30 -0
  36. package/dist/dialects/postgres.d.ts.map +1 -0
  37. package/dist/dialects/postgres.js +148 -0
  38. package/dist/dialects/postgres.js.map +1 -0
  39. package/dist/dialects/sqlite.d.ts +17 -0
  40. package/dist/dialects/sqlite.d.ts.map +1 -0
  41. package/dist/dialects/sqlite.js +126 -0
  42. package/dist/dialects/sqlite.js.map +1 -0
  43. package/dist/index.d.ts +4 -3
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +4 -3
  46. package/dist/index.js.map +1 -1
  47. package/dist/kysely-database.d.ts +12 -19
  48. package/dist/kysely-database.d.ts.map +1 -1
  49. package/dist/kysely-database.js +7 -87
  50. package/dist/kysely-database.js.map +1 -1
  51. package/dist/kysely-transformer-plugin.d.ts +2 -5
  52. package/dist/kysely-transformer-plugin.d.ts.map +1 -1
  53. package/dist/kysely-transformer-plugin.js +18 -192
  54. package/dist/kysely-transformer-plugin.js.map +1 -1
  55. package/dist/migration-post-processor.d.ts +18 -0
  56. package/dist/migration-post-processor.d.ts.map +1 -0
  57. package/dist/migration-post-processor.js +117 -0
  58. package/dist/migration-post-processor.js.map +1 -0
  59. package/dist/pool-config.d.ts +12 -0
  60. package/dist/pool-config.d.ts.map +1 -0
  61. package/dist/{datasource-config.js → pool-config.js} +9 -57
  62. package/dist/pool-config.js.map +1 -0
  63. package/dist/transaction-manager.d.ts +9 -9
  64. package/dist/transaction-manager.d.ts.map +1 -1
  65. package/dist/transaction-manager.js +167 -123
  66. package/dist/transaction-manager.js.map +1 -1
  67. package/dist/transactional-interceptor.d.ts.map +1 -1
  68. package/dist/transactional-interceptor.js +68 -17
  69. package/dist/transactional-interceptor.js.map +1 -1
  70. package/package.json +23 -8
  71. package/dist/beans.json +0 -184
  72. package/dist/datasource-config.d.ts +0 -31
  73. package/dist/datasource-config.d.ts.map +0 -1
  74. package/dist/datasource-config.js.map +0 -1
  75. package/dist/dialect-factory.d.ts +0 -9
  76. package/dist/dialect-factory.d.ts.map +0 -1
  77. package/dist/dialect-factory.js +0 -48
  78. package/dist/dialect-factory.js.map +0 -1
  79. package/dist/migration-runner.d.ts +0 -16
  80. package/dist/migration-runner.d.ts.map +0 -1
  81. package/dist/migration-runner.js +0 -45
  82. package/dist/migration-runner.js.map +0 -1
@@ -1,31 +1,81 @@
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
+ };
1
35
  import { AsyncLocalStorage } from 'node:async_hooks';
2
- import { supportsReturning as dialectSupportsReturning } from './dialect.js';
36
+ import { Singleton } from '@goodie-ts/core';
3
37
  /**
4
38
  * Manages database transactions using AsyncLocalStorage.
5
39
  *
6
40
  * Provides transaction propagation across async call chains without
7
41
  * explicitly threading a transaction object through every method.
8
42
  *
9
- * When auto-wired via `createKyselyPlugin()`, the constructor receives
10
- * the KyselyDatabase bean and reads its `.kysely` property.
11
- * Manual `configure()` is still supported for backward compatibility.
43
+ * Library component constructor receives the `KyselyDatabase` component
44
+ * and reads its `.kysely` and `.supportsReturning` properties.
45
+ * For tests, call `new TransactionManager()` with no args + `configure()`.
12
46
  */
13
- export class TransactionManager {
14
- storage = new AsyncLocalStorage();
15
- kyselyRef;
16
- testTransactionActive = false;
17
- _supportsReturning;
18
- constructor(kyselyOrProvider, dialect) {
19
- if (kyselyOrProvider) {
20
- if ('kysely' in kyselyOrProvider) {
21
- // Capture the current value (may already be set if @PostConstruct ran)
22
- this.kyselyRef = kyselyOrProvider.kysely;
23
- // Make the provider's .kysely property transaction-aware.
24
- // Any code accessing provider.kysely (e.g. database.kysely) will
25
- // automatically use the active transaction when inside one.
26
- // The setter ensures @PostConstruct can still assign the value.
47
+ let TransactionManager = (() => {
48
+ let _classDecorators = [Singleton()];
49
+ let _classDescriptor;
50
+ let _classExtraInitializers = [];
51
+ let _classThis;
52
+ var TransactionManager = class {
53
+ static { _classThis = this; }
54
+ static {
55
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
56
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
57
+ TransactionManager = _classThis = _classDescriptor.value;
58
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
59
+ __runInitializers(_classThis, _classExtraInitializers);
60
+ }
61
+ storage = new AsyncLocalStorage();
62
+ kyselyRef;
63
+ testTransactionActive = false;
64
+ _supportsReturning;
65
+ constructor(kyselyDatabase) {
66
+ if (kyselyDatabase) {
67
+ // Capture the current value (may already be set if @OnInit ran)
68
+ this.kyselyRef = kyselyDatabase.kysely;
69
+ // Read supportsReturning from the database (e.g. KyselyDatabase subclass)
70
+ if (kyselyDatabase.supportsReturning !== undefined) {
71
+ this._supportsReturning = kyselyDatabase.supportsReturning;
72
+ }
73
+ // Make the database's .kysely property transaction-aware.
74
+ // Any code accessing database.kysely will automatically use the
75
+ // active transaction when inside one.
76
+ // The setter ensures @OnInit can still assign the value.
27
77
  const tm = this;
28
- Object.defineProperty(kyselyOrProvider, 'kysely', {
78
+ Object.defineProperty(kyselyDatabase, 'kysely', {
29
79
  get() {
30
80
  return tm.getConnection();
31
81
  },
@@ -35,118 +85,112 @@ export class TransactionManager {
35
85
  configurable: true,
36
86
  });
37
87
  }
38
- else {
39
- this.kyselyRef = kyselyOrProvider;
88
+ }
89
+ /**
90
+ * Configure the Kysely instance used for transactions.
91
+ * Called manually or after @OnInit creates the Kysely instance.
92
+ */
93
+ configure(kysely, supportsReturning) {
94
+ this.kyselyRef = kysely;
95
+ if (supportsReturning !== undefined) {
96
+ this._supportsReturning = supportsReturning;
40
97
  }
41
- const resolvedDialect = dialect ??
42
- ('dialect' in kyselyOrProvider
43
- ? kyselyOrProvider.dialect
44
- : undefined);
45
- if (resolvedDialect) {
46
- this._supportsReturning = dialectSupportsReturning(resolvedDialect);
98
+ }
99
+ get kysely() {
100
+ if (!this.kyselyRef) {
101
+ throw new Error('TransactionManager not configured. Call transactionManager.configure(kysely) or use createKyselyPlugin({ database: "YourDatabase" }).');
47
102
  }
103
+ return this.kyselyRef;
48
104
  }
49
- }
50
- /**
51
- * Configure the Kysely instance used for transactions.
52
- * Called by KyselyDatabase after creating the Kysely instance in @PostConstruct.
53
- */
54
- configure(kysely, dialect) {
55
- this.kyselyRef = kysely;
56
- this._supportsReturning = dialectSupportsReturning(dialect);
57
- }
58
- get kysely() {
59
- if (!this.kyselyRef) {
60
- throw new Error('TransactionManager not configured. Call transactionManager.configure(kysely) or use createKyselyPlugin({ database: "YourDatabase" }).');
105
+ /**
106
+ * Run a function inside a transaction.
107
+ *
108
+ * - If already in a transaction (REQUIRED propagation), reuses it.
109
+ * - If `requiresNew` is true, always starts a fresh transaction.
110
+ */
111
+ async runInTransaction(fn, requiresNew = false) {
112
+ // Inside a test transaction, all queries already use the test transaction.
113
+ // Skip creating new transactions to avoid Kysely's nested transaction error.
114
+ if (this.testTransactionActive) {
115
+ return fn();
116
+ }
117
+ const existing = this.storage.getStore();
118
+ if (existing && !requiresNew) {
119
+ return fn();
120
+ }
121
+ return this.kysely.transaction().execute(async (trx) => {
122
+ return this.storage.run(trx, fn);
123
+ });
61
124
  }
62
- return this.kyselyRef;
63
- }
64
- /**
65
- * Run a function inside a transaction.
66
- *
67
- * - If already in a transaction (REQUIRED propagation), reuses it.
68
- * - If `requiresNew` is true, always starts a fresh transaction.
69
- */
70
- async runInTransaction(fn, requiresNew = false) {
71
- // Inside a test transaction, all queries already use the test transaction.
72
- // Skip creating new transactions to avoid Kysely's nested transaction error.
73
- if (this.testTransactionActive) {
74
- return fn();
125
+ /** Get the current transaction, or undefined if not in one. */
126
+ currentTransaction() {
127
+ return this.storage.getStore();
75
128
  }
76
- const existing = this.storage.getStore();
77
- if (existing && !requiresNew) {
78
- return fn();
129
+ /**
130
+ * Get the current database connection — transaction-aware.
131
+ * Returns the active transaction if inside one, otherwise the raw Kysely instance.
132
+ */
133
+ getConnection() {
134
+ return this.currentTransaction() ?? this.kysely;
79
135
  }
80
- return this.kysely.transaction().execute(async (trx) => {
81
- return this.storage.run(trx, fn);
82
- });
83
- }
84
- /** Get the current transaction, or undefined if not in one. */
85
- currentTransaction() {
86
- return this.storage.getStore();
87
- }
88
- /**
89
- * Get the current database connection — transaction-aware.
90
- * Returns the active transaction if inside one, otherwise the raw Kysely instance.
91
- */
92
- getConnection() {
93
- return this.currentTransaction() ?? this.kysely;
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.');
136
+ /**
137
+ * Whether the underlying dialect supports RETURNING clauses.
138
+ * Derived from the KyselyDatabase provider at construction / configure time.
139
+ */
140
+ get supportsReturning() {
141
+ if (this._supportsReturning === undefined) {
142
+ throw new Error('TransactionManager not configured. Call configure(kysely) or pass a KyselyProvider to the constructor.');
143
+ }
144
+ return this._supportsReturning;
102
145
  }
103
- return this._supportsReturning;
104
- }
105
- /**
106
- * Start a test-scoped transaction that ALL queries will use.
107
- *
108
- * Replaces the internal Kysely reference with the transaction object,
109
- * so any code calling `getConnection()` or `database.kysely` (via the
110
- * provider proxy) will automatically use this transaction.
111
- *
112
- * Designed for test frameworks (e.g. vitest fixtures) where
113
- * AsyncLocalStorage context may not propagate through `use()`.
114
- *
115
- * @returns A rollback function — call it to roll back the transaction
116
- * and restore the original Kysely instance.
117
- */
118
- async startTestTransaction() {
119
- const original = this.kyselyRef;
120
- let triggerRollback;
121
- let transactionReady;
122
- const readyPromise = new Promise((resolve) => {
123
- transactionReady = resolve;
124
- });
125
- const rollbackPromise = this.kysely
126
- .transaction()
127
- .execute(async (trx) => {
128
- this.kyselyRef = trx;
129
- this.testTransactionActive = true;
130
- transactionReady();
131
- await new Promise((_resolve, reject) => {
132
- triggerRollback = () => reject(new TestRollbackSignal());
146
+ /**
147
+ * Start a test-scoped transaction that ALL queries will use.
148
+ *
149
+ * Replaces the internal Kysely reference with the transaction object,
150
+ * so any code calling `getConnection()` or `database.kysely` (via the
151
+ * provider proxy) will automatically use this transaction.
152
+ *
153
+ * Designed for test frameworks (e.g. vitest fixtures) where
154
+ * AsyncLocalStorage context may not propagate through `use()`.
155
+ *
156
+ * @returns A rollback function call it to roll back the transaction
157
+ * and restore the original Kysely instance.
158
+ */
159
+ async startTestTransaction() {
160
+ const original = this.kyselyRef;
161
+ let triggerRollback;
162
+ let transactionReady;
163
+ const readyPromise = new Promise((resolve) => {
164
+ transactionReady = resolve;
133
165
  });
134
- })
135
- .catch((e) => {
136
- if (!(e instanceof TestRollbackSignal))
137
- throw e;
138
- })
139
- .finally(() => {
140
- this.testTransactionActive = false;
141
- this.kyselyRef = original;
142
- });
143
- await readyPromise;
144
- return async () => {
145
- triggerRollback();
146
- await rollbackPromise;
147
- };
148
- }
149
- }
166
+ const rollbackPromise = this.kysely
167
+ .transaction()
168
+ .execute(async (trx) => {
169
+ this.kyselyRef = trx;
170
+ this.testTransactionActive = true;
171
+ transactionReady();
172
+ await new Promise((_resolve, reject) => {
173
+ triggerRollback = () => reject(new TestRollbackSignal());
174
+ });
175
+ })
176
+ .catch((e) => {
177
+ if (!(e instanceof TestRollbackSignal))
178
+ throw e;
179
+ })
180
+ .finally(() => {
181
+ this.testTransactionActive = false;
182
+ this.kyselyRef = original;
183
+ });
184
+ await readyPromise;
185
+ return async () => {
186
+ triggerRollback();
187
+ await rollbackPromise;
188
+ };
189
+ }
190
+ };
191
+ return TransactionManager = _classThis;
192
+ })();
193
+ export { TransactionManager };
150
194
  /** @internal Sentinel error for test transaction rollback. */
151
195
  class TestRollbackSignal extends Error {
152
196
  constructor() {
@@ -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;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,gBA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O,CAAC,QAAQ,CAAC,kBAAkB;gBAAlB,kBAAkB,EAAE,kBAAkB;IAEnE,SAAS,CAAC,GAAG,EAAE,iBAAiB,GAAG,OAAO;CAY3C"}
1
+ {"version":3,"file":"transactional-interceptor.d.ts","sourceRoot":"","sources":["../src/transactional-interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAE5E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAOnE;;;;;GAKG;AACH,qBACa,wBAAyB,YAAW,iBAAiB;IACpD,OAAO,CAAC,QAAQ,CAAC,kBAAkB;gBAAlB,kBAAkB,EAAE,kBAAkB;IAEnE,SAAS,CAAC,GAAG,EAAE,iBAAiB,GAAG,OAAO;CAY3C"}
@@ -1,24 +1,75 @@
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 { Singleton } from '@goodie-ts/core';
1
36
  /**
2
37
  * AOP interceptor that wraps method execution in a database transaction.
3
38
  *
4
39
  * Reads propagation strategy from `ctx.metadata` (set by the kysely
5
40
  * transformer plugin).
6
41
  */
7
- export class TransactionalInterceptor {
8
- transactionManager;
9
- constructor(transactionManager) {
10
- this.transactionManager = transactionManager;
11
- }
12
- intercept(ctx) {
13
- const meta = ctx.metadata;
14
- if (!meta)
15
- return ctx.proceed();
16
- const requiresNew = meta.propagation === 'REQUIRES_NEW';
17
- return this.transactionManager.runInTransaction(async () => {
18
- // Must await so rejected promises propagate within the transaction scope,
19
- // ensuring Kysely rolls back on failure.
20
- return await ctx.proceed();
21
- }, requiresNew);
22
- }
23
- }
42
+ let TransactionalInterceptor = (() => {
43
+ let _classDecorators = [Singleton()];
44
+ let _classDescriptor;
45
+ let _classExtraInitializers = [];
46
+ let _classThis;
47
+ var TransactionalInterceptor = class {
48
+ static { _classThis = this; }
49
+ static {
50
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
51
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
52
+ TransactionalInterceptor = _classThis = _classDescriptor.value;
53
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
54
+ __runInitializers(_classThis, _classExtraInitializers);
55
+ }
56
+ transactionManager;
57
+ constructor(transactionManager) {
58
+ this.transactionManager = transactionManager;
59
+ }
60
+ intercept(ctx) {
61
+ const meta = ctx.metadata;
62
+ if (!meta)
63
+ return ctx.proceed();
64
+ const requiresNew = meta.propagation === 'REQUIRES_NEW';
65
+ return this.transactionManager.runInTransaction(async () => {
66
+ // Must await so rejected promises propagate within the transaction scope,
67
+ // ensuring Kysely rolls back on failure.
68
+ return await ctx.proceed();
69
+ }, requiresNew);
70
+ }
71
+ };
72
+ return TransactionalInterceptor = _classThis;
73
+ })();
74
+ export { TransactionalInterceptor };
24
75
  //# sourceMappingURL=transactional-interceptor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"transactional-interceptor.js","sourceRoot":"","sources":["../src/transactional-interceptor.ts"],"names":[],"mappings":"AAQA;;;;;GAKG;AACH,MAAM,OAAO,wBAAwB;IACN;IAA7B,YAA6B,kBAAsC;QAAtC,uBAAkB,GAAlB,kBAAkB,CAAoB;IAAG,CAAC;IAEvE,SAAS,CAAC,GAAsB;QAC9B,MAAM,IAAI,GAAG,GAAG,CAAC,QAA6C,CAAC;QAC/D,IAAI,CAAC,IAAI;YAAE,OAAO,GAAG,CAAC,OAAO,EAAE,CAAC;QAEhC,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,KAAK,cAAc,CAAC;QAExD,OAAO,IAAI,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,KAAK,IAAI,EAAE;YACzD,0EAA0E;YAC1E,yCAAyC;YACzC,OAAO,MAAM,GAAG,CAAC,OAAO,EAAE,CAAC;QAC7B,CAAC,EAAE,WAAW,CAAC,CAAC;IAClB,CAAC;CACF"}
1
+ {"version":3,"file":"transactional-interceptor.js","sourceRoot":"","sources":["../src/transactional-interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAQ5C;;;;;GAKG;IAEU,wBAAwB;4BADpC,SAAS,EAAE;;;;;;;;YACZ,6KAeC;;;YAfY,uDAAwB;;QACN,kBAAkB;QAA/C,YAA6B,kBAAsC;YAAtC,uBAAkB,GAAlB,kBAAkB,CAAoB;QAAG,CAAC;QAEvE,SAAS,CAAC,GAAsB;YAC9B,MAAM,IAAI,GAAG,GAAG,CAAC,QAA6C,CAAC;YAC/D,IAAI,CAAC,IAAI;gBAAE,OAAO,GAAG,CAAC,OAAO,EAAE,CAAC;YAEhC,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,KAAK,cAAc,CAAC;YAExD,OAAO,IAAI,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,KAAK,IAAI,EAAE;gBACzD,0EAA0E;gBAC1E,yCAAyC;gBACzC,OAAO,MAAM,GAAG,CAAC,OAAO,EAAE,CAAC;YAC7B,CAAC,EAAE,WAAW,CAAC,CAAC;QAClB,CAAC;;;;SAdU,wBAAwB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goodie-ts/kysely",
3
- "version": "0.7.0",
3
+ "version": "2.0.0",
4
4
  "description": "Kysely integration for goodie-ts — @Transactional decorator, TransactionManager, KyselyDatabase",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -13,7 +13,7 @@
13
13
  "access": "public"
14
14
  },
15
15
  "goodie": {
16
- "beans": "dist/beans.json",
16
+ "components": "dist/components.json",
17
17
  "plugin": "./dist/kysely-transformer-plugin.js"
18
18
  },
19
19
  "main": "dist/index.js",
@@ -24,14 +24,16 @@
24
24
  "import": "./dist/index.js"
25
25
  }
26
26
  },
27
- "dependencies": {
28
- "@goodie-ts/core": "^0.10.0"
29
- },
30
27
  "peerDependencies": {
28
+ "@goodie-ts/core": ">=2.0.0",
31
29
  "kysely": ">=0.27.0",
32
30
  "pg": ">=8.0.0",
33
31
  "mysql2": ">=3.0.0",
34
- "better-sqlite3": ">=9.0.0"
32
+ "better-sqlite3": ">=9.0.0",
33
+ "kysely-neon": ">=0.3.0",
34
+ "kysely-planetscale": ">=1.0.0",
35
+ "@libsql/kysely-libsql": ">=0.4.0",
36
+ "kysely-d1": ">=0.4.0"
35
37
  },
36
38
  "peerDependenciesMeta": {
37
39
  "pg": {
@@ -42,6 +44,18 @@
42
44
  },
43
45
  "better-sqlite3": {
44
46
  "optional": true
47
+ },
48
+ "kysely-neon": {
49
+ "optional": true
50
+ },
51
+ "kysely-planetscale": {
52
+ "optional": true
53
+ },
54
+ "@libsql/kysely-libsql": {
55
+ "optional": true
56
+ },
57
+ "kysely-d1": {
58
+ "optional": true
45
59
  }
46
60
  },
47
61
  "devDependencies": {
@@ -53,8 +67,9 @@
53
67
  "mysql2": "^3.0.0",
54
68
  "pg": "^8.0.0",
55
69
  "ts-morph": "^24.0.0",
56
- "@goodie-ts/cli": "0.6.6",
57
- "@goodie-ts/transformer": "0.12.0"
70
+ "@goodie-ts/core": "2.0.0",
71
+ "@goodie-ts/cli": "2.0.0",
72
+ "@goodie-ts/transformer": "2.0.0"
58
73
  },
59
74
  "files": [
60
75
  "dist"