@goodie-ts/kysely 1.0.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.
- package/README.md +2 -2
- package/dist/abstract-migration.d.ts +2 -2
- package/dist/abstract-migration.js +2 -2
- package/dist/{beans.json → components.json} +786 -62
- package/dist/decorators/migration.d.ts +1 -1
- package/dist/decorators/migration.js +1 -1
- package/dist/dialects/d1.js +4 -4
- package/dist/dialects/d1.js.map +1 -1
- package/dist/dialects/libsql.d.ts.map +1 -1
- package/dist/dialects/libsql.js +6 -6
- package/dist/dialects/libsql.js.map +1 -1
- package/dist/dialects/mysql.d.ts.map +1 -1
- package/dist/dialects/mysql.js +6 -6
- package/dist/dialects/mysql.js.map +1 -1
- package/dist/dialects/neon.d.ts.map +1 -1
- package/dist/dialects/neon.js +6 -6
- package/dist/dialects/neon.js.map +1 -1
- package/dist/dialects/planetscale.d.ts.map +1 -1
- package/dist/dialects/planetscale.js +6 -6
- package/dist/dialects/planetscale.js.map +1 -1
- package/dist/dialects/postgres.d.ts.map +1 -1
- package/dist/dialects/postgres.js +6 -6
- package/dist/dialects/postgres.js.map +1 -1
- package/dist/dialects/sqlite.d.ts.map +1 -1
- package/dist/dialects/sqlite.js +6 -6
- package/dist/dialects/sqlite.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/kysely-database.d.ts +2 -2
- package/dist/kysely-database.js +2 -2
- package/dist/kysely-transformer-plugin.d.ts +2 -5
- package/dist/kysely-transformer-plugin.d.ts.map +1 -1
- package/dist/kysely-transformer-plugin.js +18 -197
- package/dist/kysely-transformer-plugin.js.map +1 -1
- package/dist/migration-post-processor.d.ts +18 -0
- package/dist/migration-post-processor.d.ts.map +1 -0
- package/dist/migration-post-processor.js +117 -0
- package/dist/migration-post-processor.js.map +1 -0
- package/dist/pool-config.d.ts.map +1 -1
- package/dist/pool-config.js +2 -2
- package/dist/pool-config.js.map +1 -1
- package/dist/transaction-manager.d.ts +6 -4
- package/dist/transaction-manager.d.ts.map +1 -1
- package/dist/transaction-manager.js +166 -119
- package/dist/transaction-manager.js.map +1 -1
- package/dist/transactional-interceptor.d.ts.map +1 -1
- package/dist/transactional-interceptor.js +68 -17
- package/dist/transactional-interceptor.js.map +1 -1
- package/package.json +6 -6
- package/dist/migration-runner.d.ts +0 -16
- package/dist/migration-runner.d.ts.map +0 -1
- package/dist/migration-runner.js +0 -45
- package/dist/migration-runner.js.map +0 -1
|
@@ -4,11 +4,8 @@
|
|
|
4
4
|
* Scans @Transactional decorators on methods and wires
|
|
5
5
|
* TransactionalInterceptor as an AOP interceptor dependency at compile time.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* Wires TransactionManager and MigrationRunner using `KyselyDatabase` from
|
|
11
|
-
* library beans — no manual `database` option needed.
|
|
7
|
+
* Registers @Migration decorated classes as components so they are discovered
|
|
8
|
+
* by the MigrationPostProcessor library component via `ctx.getAll(AbstractMigration)`.
|
|
12
9
|
*
|
|
13
10
|
* **Limitation:** Propagation is detected via AST text matching
|
|
14
11
|
* (`text.includes('REQUIRES_NEW')`). Only string literal values in the
|
|
@@ -17,22 +14,18 @@
|
|
|
17
14
|
*/
|
|
18
15
|
export function createKyselyPlugin(_options) {
|
|
19
16
|
const classTransactionalInfo = new Map();
|
|
20
|
-
/** @Migration decorated classes discovered during visitClass. */
|
|
21
|
-
const migrationClasses = [];
|
|
22
17
|
return {
|
|
23
18
|
name: 'kysely',
|
|
24
19
|
visitClass(ctx) {
|
|
25
|
-
// Detect @Migration('name')
|
|
20
|
+
// Detect @Migration('name') — register as a component so the scanner picks it up
|
|
26
21
|
for (const decorator of ctx.classDeclaration.getDecorators()) {
|
|
27
22
|
if (decorator.getName() !== 'Migration')
|
|
28
23
|
continue;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
className: ctx.className,
|
|
33
|
-
filePath: ctx.filePath,
|
|
34
|
-
migrationName: name,
|
|
24
|
+
ctx.registerComponent({
|
|
25
|
+
scope: 'singleton',
|
|
26
|
+
decoratorName: 'Migration',
|
|
35
27
|
});
|
|
28
|
+
break;
|
|
36
29
|
}
|
|
37
30
|
},
|
|
38
31
|
visitMethod(ctx) {
|
|
@@ -55,20 +48,20 @@ export function createKyselyPlugin(_options) {
|
|
|
55
48
|
classTransactionalInfo.set(key, existing);
|
|
56
49
|
}
|
|
57
50
|
},
|
|
58
|
-
afterResolve(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
51
|
+
afterResolve(components) {
|
|
52
|
+
// Wire @Transactional interceptor metadata onto components
|
|
53
|
+
for (const component of components) {
|
|
54
|
+
const className = component.tokenRef.kind === 'class'
|
|
55
|
+
? component.tokenRef.className
|
|
56
|
+
: undefined;
|
|
64
57
|
if (!className)
|
|
65
58
|
continue;
|
|
66
|
-
const key = `${
|
|
59
|
+
const key = `${component.tokenRef.importPath}:${className}`;
|
|
67
60
|
const infos = classTransactionalInfo.get(key);
|
|
68
61
|
if (!infos || infos.length === 0)
|
|
69
62
|
continue;
|
|
70
|
-
|
|
71
|
-
|
|
63
|
+
const existing = (component.metadata.interceptedMethods ??
|
|
64
|
+
[]);
|
|
72
65
|
for (const info of infos) {
|
|
73
66
|
const methodEntry = existing.find((m) => m.methodName === info.methodName);
|
|
74
67
|
const interceptorRef = {
|
|
@@ -88,181 +81,9 @@ export function createKyselyPlugin(_options) {
|
|
|
88
81
|
});
|
|
89
82
|
}
|
|
90
83
|
}
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
const hasMigrations = migrationClasses.length > 0;
|
|
94
|
-
if (!needsInterceptor && !hasMigrations)
|
|
95
|
-
return beans;
|
|
96
|
-
// Check if any KyselyDatabase subclass exists (via baseTokenRefs).
|
|
97
|
-
// Wire deps using the abstract KyselyDatabase token — runtime resolves
|
|
98
|
-
// the concrete impl via baseTokenRefs after conditional filtering.
|
|
99
|
-
const hasKyselyDatabase = beans.some((b) => b.tokenRef.kind === 'class' &&
|
|
100
|
-
(b.baseTokenRefs?.some((ref) => ref.className === 'KyselyDatabase' &&
|
|
101
|
-
ref.importPath === '@goodie-ts/kysely') ||
|
|
102
|
-
(b.tokenRef.className === 'KyselyDatabase' &&
|
|
103
|
-
b.tokenRef.importPath === '@goodie-ts/kysely')));
|
|
104
|
-
const kyselyDatabaseTokenRef = {
|
|
105
|
-
kind: 'class',
|
|
106
|
-
className: 'KyselyDatabase',
|
|
107
|
-
importPath: '@goodie-ts/kysely',
|
|
108
|
-
};
|
|
109
|
-
const kyselyProviderDep = hasKyselyDatabase
|
|
110
|
-
? [
|
|
111
|
-
{
|
|
112
|
-
tokenRef: kyselyDatabaseTokenRef,
|
|
113
|
-
optional: false,
|
|
114
|
-
collection: false,
|
|
115
|
-
sourceLocation: {
|
|
116
|
-
filePath: '@goodie-ts/kysely',
|
|
117
|
-
line: 0,
|
|
118
|
-
column: 0,
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
]
|
|
122
|
-
: [];
|
|
123
|
-
// --- Transactional synthetic beans ---
|
|
124
|
-
if (needsInterceptor) {
|
|
125
|
-
syntheticBeans.push({
|
|
126
|
-
tokenRef: {
|
|
127
|
-
kind: 'class',
|
|
128
|
-
className: 'TransactionManager',
|
|
129
|
-
importPath: '@goodie-ts/kysely',
|
|
130
|
-
},
|
|
131
|
-
scope: 'singleton',
|
|
132
|
-
eager: false,
|
|
133
|
-
name: undefined,
|
|
134
|
-
constructorDeps: kyselyProviderDep,
|
|
135
|
-
fieldDeps: [],
|
|
136
|
-
factoryKind: 'constructor',
|
|
137
|
-
providesSource: undefined,
|
|
138
|
-
metadata: {},
|
|
139
|
-
sourceLocation: {
|
|
140
|
-
filePath: '@goodie-ts/kysely',
|
|
141
|
-
line: 0,
|
|
142
|
-
column: 0,
|
|
143
|
-
},
|
|
144
|
-
});
|
|
145
|
-
syntheticBeans.push({
|
|
146
|
-
tokenRef: {
|
|
147
|
-
kind: 'class',
|
|
148
|
-
className: 'TransactionalInterceptor',
|
|
149
|
-
importPath: '@goodie-ts/kysely',
|
|
150
|
-
},
|
|
151
|
-
scope: 'singleton',
|
|
152
|
-
eager: false,
|
|
153
|
-
name: undefined,
|
|
154
|
-
constructorDeps: [
|
|
155
|
-
{
|
|
156
|
-
tokenRef: {
|
|
157
|
-
kind: 'class',
|
|
158
|
-
className: 'TransactionManager',
|
|
159
|
-
importPath: '@goodie-ts/kysely',
|
|
160
|
-
},
|
|
161
|
-
optional: false,
|
|
162
|
-
collection: false,
|
|
163
|
-
sourceLocation: {
|
|
164
|
-
filePath: '@goodie-ts/kysely',
|
|
165
|
-
line: 0,
|
|
166
|
-
column: 0,
|
|
167
|
-
},
|
|
168
|
-
},
|
|
169
|
-
],
|
|
170
|
-
fieldDeps: [],
|
|
171
|
-
factoryKind: 'constructor',
|
|
172
|
-
providesSource: undefined,
|
|
173
|
-
metadata: {},
|
|
174
|
-
sourceLocation: {
|
|
175
|
-
filePath: '@goodie-ts/kysely',
|
|
176
|
-
line: 0,
|
|
177
|
-
column: 0,
|
|
178
|
-
},
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
// --- @Migration synthetic beans ---
|
|
182
|
-
if (hasMigrations) {
|
|
183
|
-
if (kyselyProviderDep.length === 0) {
|
|
184
|
-
console.warn('[@goodie-ts/kysely] @Migration classes found but no Kysely provider detected. ' +
|
|
185
|
-
'MigrationRunner will not be created.');
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
// Sort migrations by name for deterministic execution order
|
|
189
|
-
migrationClasses.sort((a, b) => a.migrationName.localeCompare(b.migrationName));
|
|
190
|
-
// Synthetic bean per @Migration class (no baseTokenRefs — wired as individual deps)
|
|
191
|
-
const migrationDeps = [];
|
|
192
|
-
for (const m of migrationClasses) {
|
|
193
|
-
syntheticBeans.push({
|
|
194
|
-
tokenRef: {
|
|
195
|
-
kind: 'class',
|
|
196
|
-
className: m.className,
|
|
197
|
-
importPath: m.filePath,
|
|
198
|
-
},
|
|
199
|
-
scope: 'singleton',
|
|
200
|
-
eager: false,
|
|
201
|
-
name: undefined,
|
|
202
|
-
constructorDeps: [],
|
|
203
|
-
fieldDeps: [],
|
|
204
|
-
factoryKind: 'constructor',
|
|
205
|
-
providesSource: undefined,
|
|
206
|
-
metadata: {},
|
|
207
|
-
sourceLocation: {
|
|
208
|
-
filePath: m.filePath,
|
|
209
|
-
line: 0,
|
|
210
|
-
column: 0,
|
|
211
|
-
},
|
|
212
|
-
});
|
|
213
|
-
migrationDeps.push({
|
|
214
|
-
tokenRef: {
|
|
215
|
-
kind: 'class',
|
|
216
|
-
className: m.className,
|
|
217
|
-
importPath: m.filePath,
|
|
218
|
-
},
|
|
219
|
-
optional: false,
|
|
220
|
-
collection: false,
|
|
221
|
-
sourceLocation: {
|
|
222
|
-
filePath: '@goodie-ts/kysely',
|
|
223
|
-
line: 0,
|
|
224
|
-
column: 0,
|
|
225
|
-
},
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
// MigrationRunner: eager singleton, depends on KyselyProvider + individual migration deps
|
|
229
|
-
syntheticBeans.push({
|
|
230
|
-
tokenRef: {
|
|
231
|
-
kind: 'class',
|
|
232
|
-
className: 'MigrationRunner',
|
|
233
|
-
importPath: '@goodie-ts/kysely',
|
|
234
|
-
},
|
|
235
|
-
scope: 'singleton',
|
|
236
|
-
eager: true,
|
|
237
|
-
name: undefined,
|
|
238
|
-
constructorDeps: [kyselyProviderDep[0], ...migrationDeps],
|
|
239
|
-
fieldDeps: [],
|
|
240
|
-
factoryKind: 'constructor',
|
|
241
|
-
providesSource: undefined,
|
|
242
|
-
metadata: { postConstructMethods: ['migrate'] },
|
|
243
|
-
sourceLocation: {
|
|
244
|
-
filePath: '@goodie-ts/kysely',
|
|
245
|
-
line: 0,
|
|
246
|
-
column: 0,
|
|
247
|
-
},
|
|
248
|
-
});
|
|
249
|
-
}
|
|
84
|
+
component.metadata.interceptedMethods = existing;
|
|
250
85
|
}
|
|
251
|
-
return
|
|
252
|
-
},
|
|
253
|
-
codegen(beans) {
|
|
254
|
-
const hasTransactional = beans.some((b) => {
|
|
255
|
-
const methods = b.metadata.interceptedMethods;
|
|
256
|
-
return methods?.some((m) => m.interceptors.some((i) => i.className === 'TransactionalInterceptor'));
|
|
257
|
-
});
|
|
258
|
-
if (!hasTransactional)
|
|
259
|
-
return {};
|
|
260
|
-
// TransactionManager and TransactionalInterceptor imports are already
|
|
261
|
-
// generated by collectClassImports (they are synthetic bean tokens).
|
|
262
|
-
// Only need to contribute the buildInterceptorChain import.
|
|
263
|
-
return {
|
|
264
|
-
imports: ["import { buildInterceptorChain } from '@goodie-ts/core'"],
|
|
265
|
-
};
|
|
86
|
+
return components;
|
|
266
87
|
},
|
|
267
88
|
};
|
|
268
89
|
}
|
|
@@ -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":"AAgBA;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,kBAAkB,CAChC,QAA8B;IAE9B,MAAM,sBAAsB,GAAG,IAAI,GAAG,EAAqC,CAAC;IAE5E,OAAO;QACL,IAAI,EAAE,QAAQ;QAEd,UAAU,CAAC,GAAwB;YACjC,iFAAiF;YACjF,KAAK,MAAM,SAAS,IAAI,GAAG,CAAC,gBAAgB,CAAC,aAAa,EAAE,EAAE,CAAC;gBAC7D,IAAI,SAAS,CAAC,OAAO,EAAE,KAAK,WAAW;oBAAE,SAAS;gBAClD,GAAG,CAAC,iBAAiB,CAAC;oBACpB,KAAK,EAAE,WAAW;oBAClB,aAAa,EAAE,WAAW;iBAC3B,CAAC,CAAC;gBACH,MAAM;Y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ponentPostProcessor } from '@goodie-ts/core';
|
|
2
|
+
/**
|
|
3
|
+
* Runs Kysely migrations when `KyselyDatabase` is initialized.
|
|
4
|
+
*
|
|
5
|
+
* Replaces the previous `MigrationRunner` eager singleton. As a
|
|
6
|
+
* `ComponentPostProcessor`, migrations execute during `KyselyDatabase`
|
|
7
|
+
* initialization — guaranteeing every consumer receives a fully-migrated
|
|
8
|
+
* database instance.
|
|
9
|
+
*/
|
|
10
|
+
export declare class MigrationPostProcessor implements ComponentPostProcessor {
|
|
11
|
+
private readonly ctx;
|
|
12
|
+
private migrationPromise;
|
|
13
|
+
constructor(ctx: ApplicationContext);
|
|
14
|
+
afterInit<T>(component: T, _definition: ComponentDefinition<T>): T | Promise<T>;
|
|
15
|
+
private runMigrations;
|
|
16
|
+
private doMigrate;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=migration-post-processor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-post-processor.d.ts","sourceRoot":"","sources":["../src/migration-post-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAG5B,MAAM,iBAAiB,CAAC;AAOzB;;;;;;;GAOG;AACH,qBAEa,sBAAuB,YAAW,sBAAsB;IAGvD,OAAO,CAAC,QAAQ,CAAC,GAAG;IAFhC,OAAO,CAAC,gBAAgB,CAA8B;gBAEzB,GAAG,EAAE,kBAAkB;IAEpD,SAAS,CAAC,CAAC,EACT,SAAS,EAAE,CAAC,EACZ,WAAW,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAClC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAQjB,OAAO,CAAC,aAAa;YASP,SAAS;CAmCxB"}
|
|
@@ -0,0 +1,117 @@
|
|
|
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 { PostProcessor, Singleton, } from '@goodie-ts/core';
|
|
36
|
+
import { Migrator } from 'kysely';
|
|
37
|
+
import { AbstractMigration } from './abstract-migration.js';
|
|
38
|
+
import { getMigrationName } from './decorators/migration.js';
|
|
39
|
+
import { KyselyDatabase } from './kysely-database.js';
|
|
40
|
+
/**
|
|
41
|
+
* Runs Kysely migrations when `KyselyDatabase` is initialized.
|
|
42
|
+
*
|
|
43
|
+
* Replaces the previous `MigrationRunner` eager singleton. As a
|
|
44
|
+
* `ComponentPostProcessor`, migrations execute during `KyselyDatabase`
|
|
45
|
+
* initialization — guaranteeing every consumer receives a fully-migrated
|
|
46
|
+
* database instance.
|
|
47
|
+
*/
|
|
48
|
+
let MigrationPostProcessor = (() => {
|
|
49
|
+
let _classDecorators = [PostProcessor(), Singleton()];
|
|
50
|
+
let _classDescriptor;
|
|
51
|
+
let _classExtraInitializers = [];
|
|
52
|
+
let _classThis;
|
|
53
|
+
var MigrationPostProcessor = class {
|
|
54
|
+
static { _classThis = this; }
|
|
55
|
+
static {
|
|
56
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
57
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
58
|
+
MigrationPostProcessor = _classThis = _classDescriptor.value;
|
|
59
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
60
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
61
|
+
}
|
|
62
|
+
ctx;
|
|
63
|
+
migrationPromise = null;
|
|
64
|
+
constructor(ctx) {
|
|
65
|
+
this.ctx = ctx;
|
|
66
|
+
}
|
|
67
|
+
afterInit(component, _definition) {
|
|
68
|
+
if (!(component instanceof KyselyDatabase))
|
|
69
|
+
return component;
|
|
70
|
+
if (this.migrationPromise) {
|
|
71
|
+
return this.migrationPromise.then(() => component);
|
|
72
|
+
}
|
|
73
|
+
return this.runMigrations(component);
|
|
74
|
+
}
|
|
75
|
+
runMigrations(db) {
|
|
76
|
+
this.migrationPromise = this.doMigrate(db).catch((err) => {
|
|
77
|
+
// Clear so the next request retries — migrateToLatest() is idempotent.
|
|
78
|
+
this.migrationPromise = null;
|
|
79
|
+
throw err;
|
|
80
|
+
});
|
|
81
|
+
return this.migrationPromise.then(() => db);
|
|
82
|
+
}
|
|
83
|
+
async doMigrate(db) {
|
|
84
|
+
const migrations = this.ctx.getAll(AbstractMigration);
|
|
85
|
+
if (migrations.length === 0)
|
|
86
|
+
return;
|
|
87
|
+
const migrationMap = {};
|
|
88
|
+
for (const m of migrations) {
|
|
89
|
+
const name = getMigrationName(m);
|
|
90
|
+
if (!name) {
|
|
91
|
+
throw new Error(`MigrationPostProcessor received an object without @Migration metadata: ${m.constructor.name}`);
|
|
92
|
+
}
|
|
93
|
+
// Kysely's Migrator spreads migration objects (...migration), which
|
|
94
|
+
// drops prototype methods from class instances. Bind explicitly.
|
|
95
|
+
migrationMap[name] = {
|
|
96
|
+
up: m.up.bind(m),
|
|
97
|
+
down: m.down?.bind(m),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
const migrator = new Migrator({
|
|
101
|
+
db: db.kysely,
|
|
102
|
+
provider: { getMigrations: async () => migrationMap },
|
|
103
|
+
});
|
|
104
|
+
const { error, results } = await migrator.migrateToLatest();
|
|
105
|
+
for (const r of results ?? []) {
|
|
106
|
+
if (r.status === 'Error') {
|
|
107
|
+
console.error(`Migration "${r.migrationName}" failed`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (error)
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
return MigrationPostProcessor = _classThis;
|
|
115
|
+
})();
|
|
116
|
+
export { MigrationPostProcessor };
|
|
117
|
+
//# sourceMappingURL=migration-post-processor.js.map
|
|
@@ -0,0 +1 @@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AAK;gBAAE,MAAM,KAAK,CAAC;QACzB,CAAC;;;;SA3DU,sBAAsB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pool-config.d.ts","sourceRoot":"","sources":["../src/pool-config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pool-config.d.ts","sourceRoot":"","sources":["../src/pool-config.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,qBAKa,UAAU;IACrB,GAAG,SAAK;IACR,GAAG,SAAM;CACV"}
|
package/dist/pool-config.js
CHANGED
|
@@ -32,7 +32,7 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
|
|
|
32
32
|
}
|
|
33
33
|
return useValue ? value : void 0;
|
|
34
34
|
};
|
|
35
|
-
import { ConditionalOnProperty,
|
|
35
|
+
import { ConditionalOnProperty, Config, Singleton } from '@goodie-ts/core';
|
|
36
36
|
/**
|
|
37
37
|
* Connection pool configuration, bound from `datasource.pool.*` keys.
|
|
38
38
|
*
|
|
@@ -41,7 +41,7 @@ import { ConditionalOnProperty, ConfigurationProperties, Singleton, } from '@goo
|
|
|
41
41
|
* don't use pooling.
|
|
42
42
|
*/
|
|
43
43
|
let PoolConfig = (() => {
|
|
44
|
-
let _classDecorators = [Singleton(),
|
|
44
|
+
let _classDecorators = [Singleton(), Config('datasource.pool'), ConditionalOnProperty('datasource.dialect', {
|
|
45
45
|
havingValue: ['postgres', 'mysql'],
|
|
46
46
|
})];
|
|
47
47
|
let _classDescriptor;
|
package/dist/pool-config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pool-config.js","sourceRoot":"","sources":["../src/pool-config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"pool-config.js","sourceRoot":"","sources":["../src/pool-config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE3E;;;;;;GAMG;IAMU,UAAU;4BALtB,SAAS,EAAE,EACX,MAAM,CAAC,iBAAiB,CAAC,EACzB,qBAAqB,CAAC,oBAAoB,EAAE;YAC3C,WAAW,EAAE,CAAC,UAAU,EAAE,OAAO,CAAC;SACnC,CAAC;;;;;;;;YACF,6KAGC;;;YAHY,uDAAU;;QACrB,GAAG,GAAG,CAAC,CAAC;QACR,GAAG,GAAG,EAAE,CAAC;;;;SAFE,UAAU"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Kysely, Transaction } from 'kysely';
|
|
2
|
+
import type { KyselyDatabase } from './kysely-database.js';
|
|
2
3
|
/**
|
|
3
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.
|
|
@@ -13,18 +14,19 @@ export interface KyselyProvider {
|
|
|
13
14
|
* Provides transaction propagation across async call chains without
|
|
14
15
|
* explicitly threading a transaction object through every method.
|
|
15
16
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
17
|
+
* Library component — constructor receives the `KyselyDatabase` component
|
|
18
|
+
* and reads its `.kysely` and `.supportsReturning` properties.
|
|
19
|
+
* For tests, call `new TransactionManager()` with no args + `configure()`.
|
|
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?;
|
|
24
|
-
constructor(
|
|
26
|
+
constructor(kyselyDatabase?: KyselyDatabase);
|
|
25
27
|
/**
|
|
26
28
|
* Configure the Kysely instance used for transactions.
|
|
27
|
-
* Called manually or after @
|
|
29
|
+
* Called manually or after @OnInit creates the Kysely instance.
|
|
28
30
|
*/
|
|
29
31
|
configure(kysely: Kysely<any>, supportsReturning?: boolean): void;
|
|
30
32
|
private get kysely();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction-manager.d.ts","sourceRoot":"","sources":["../src/transaction-manager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transaction-manager.d.ts","sourceRoot":"","sources":["../src/transaction-manager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;IACpB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;;;;;;;GASG;AACH,qBACa,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;gBAEzB,cAAc,CAAC,EAAE,cAAc;IAyB3C;;;OAGG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,iBAAiB,CAAC,EAAE,OAAO,GAAG,IAAI;IAOjE,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"}
|