@duraxis/nestjs 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/LICENSE +15 -0
- package/README.md +94 -2
- package/dist/duraxis.connection.d.ts +18 -0
- package/dist/duraxis.decorators.d.ts +5 -0
- package/dist/duraxis.errors.d.ts +6 -0
- package/dist/duraxis.feature-discovery.d.ts +8 -0
- package/dist/duraxis.interfaces.d.ts +28 -0
- package/dist/duraxis.module.d.ts +10 -0
- package/dist/duraxis.registry.d.ts +8 -0
- package/dist/duraxis.tokens.d.ts +9 -0
- package/dist/index.cjs +849 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +813 -0
- package/dist/index.js.map +1 -0
- package/dist/transactions/transaction-aware.repository.d.ts +4 -0
- package/dist/transactions/transaction-context.manager.d.ts +18 -0
- package/dist/transactions/transaction-manager.registry.d.ts +7 -0
- package/dist/transactions/transaction.errors.d.ts +40 -0
- package/dist/transactions/transaction.manager.d.ts +29 -0
- package/dist/transactions/transaction.types.d.ts +30 -0
- package/dist/transactions/transactional.decorator.d.ts +6 -0
- package/dist/transactions/transactional.proxy.d.ts +4 -0
- package/package.json +69 -3
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,849 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _nestjs_common = require("@nestjs/common");
|
|
3
|
+
let _nestjs_core = require("@nestjs/core");
|
|
4
|
+
let _duraxis_core = require("@duraxis/core");
|
|
5
|
+
let _duraxis_orm = require("@duraxis/orm");
|
|
6
|
+
let node_async_hooks = require("node:async_hooks");
|
|
7
|
+
// src/duraxis.tokens.ts
|
|
8
|
+
var DEFAULT_DURAXIS_CONNECTION = "default";
|
|
9
|
+
var repositoryTokens = /* @__PURE__ */ new WeakMap();
|
|
10
|
+
function normalizeDuraxisConnectionName(name) {
|
|
11
|
+
const normalized = name ?? "default";
|
|
12
|
+
if (typeof normalized != "string" || normalized.trim() == "" || normalized.length > 128 || normalized.includes("\0")) throw new TypeError("Duraxis connection name must be a non-empty string of at most 128 characters");
|
|
13
|
+
return normalized;
|
|
14
|
+
}
|
|
15
|
+
function connectionToken(kind, connectionName) {
|
|
16
|
+
const name = normalizeDuraxisConnectionName(connectionName);
|
|
17
|
+
return Symbol.for(`@duraxis/nestjs/${kind}/${encodeURIComponent(name)}`);
|
|
18
|
+
}
|
|
19
|
+
function getDuraxisOrmToken(connectionName) {
|
|
20
|
+
return connectionToken("orm", connectionName);
|
|
21
|
+
}
|
|
22
|
+
function getDuraxisDatabaseToken(connectionName) {
|
|
23
|
+
return connectionToken("database", connectionName);
|
|
24
|
+
}
|
|
25
|
+
function getDuraxisTransactionManagerToken(connectionName) {
|
|
26
|
+
return connectionToken("transaction-manager", connectionName);
|
|
27
|
+
}
|
|
28
|
+
function getDuraxisRepositoryToken(entity, connectionName) {
|
|
29
|
+
const name = normalizeDuraxisConnectionName(connectionName);
|
|
30
|
+
let byConnection = repositoryTokens.get(entity);
|
|
31
|
+
if (!byConnection) {
|
|
32
|
+
byConnection = /* @__PURE__ */ new Map();
|
|
33
|
+
repositoryTokens.set(entity, byConnection);
|
|
34
|
+
}
|
|
35
|
+
let token = byConnection.get(name);
|
|
36
|
+
if (!token) {
|
|
37
|
+
token = Symbol(`@duraxis/nestjs/repository/${name}/${entity.name}`);
|
|
38
|
+
byConnection.set(name, token);
|
|
39
|
+
}
|
|
40
|
+
return token;
|
|
41
|
+
}
|
|
42
|
+
function getDuraxisOptionsToken(connectionName) {
|
|
43
|
+
return connectionToken("options", connectionName);
|
|
44
|
+
}
|
|
45
|
+
function getDuraxisConnectionToken(connectionName) {
|
|
46
|
+
return connectionToken("connection", connectionName);
|
|
47
|
+
}
|
|
48
|
+
// src/duraxis.connection.ts
|
|
49
|
+
function isStorageDriver(value) {
|
|
50
|
+
if (typeof value != "object" || value == null) return false;
|
|
51
|
+
return [
|
|
52
|
+
"get",
|
|
53
|
+
"put",
|
|
54
|
+
"delete",
|
|
55
|
+
"list"
|
|
56
|
+
].every((method) => method in value && typeof Reflect.get(value, method) == "function");
|
|
57
|
+
}
|
|
58
|
+
var DuraxisNestConnection = class DuraxisNestConnection {
|
|
59
|
+
name;
|
|
60
|
+
database;
|
|
61
|
+
orm;
|
|
62
|
+
onClosed;
|
|
63
|
+
#closing;
|
|
64
|
+
#beforeClose;
|
|
65
|
+
constructor(name, database, orm, onClosed) {
|
|
66
|
+
this.name = name;
|
|
67
|
+
this.database = database;
|
|
68
|
+
this.orm = orm;
|
|
69
|
+
this.onClosed = onClosed;
|
|
70
|
+
}
|
|
71
|
+
static async create(name, options, onClosed = () => {}) {
|
|
72
|
+
const driverIsFactory = typeof options.driver == "function";
|
|
73
|
+
const closeStorage = options.closeStorage ?? driverIsFactory;
|
|
74
|
+
let driver;
|
|
75
|
+
let database;
|
|
76
|
+
let orm;
|
|
77
|
+
try {
|
|
78
|
+
driver = driverIsFactory ? await options.driver() : options.driver;
|
|
79
|
+
if (!isStorageDriver(driver)) throw new TypeError("Duraxis driver factory returned an invalid StorageDriver");
|
|
80
|
+
database = new _duraxis_core.DuraxisDatabase({
|
|
81
|
+
...options.database,
|
|
82
|
+
storage: driver
|
|
83
|
+
});
|
|
84
|
+
orm = new _duraxis_orm.DuraxisORM({
|
|
85
|
+
database,
|
|
86
|
+
entities: options.entities ?? [],
|
|
87
|
+
...options.schema == null ? {} : { schema: options.schema },
|
|
88
|
+
closeDatabase: true,
|
|
89
|
+
closeStorage
|
|
90
|
+
});
|
|
91
|
+
await orm.initialize();
|
|
92
|
+
return new DuraxisNestConnection(name, database, orm, onClosed);
|
|
93
|
+
} catch (cause) {
|
|
94
|
+
try {
|
|
95
|
+
if (orm) await orm.close();
|
|
96
|
+
else if (database) await database.close({ closeStorage });
|
|
97
|
+
else if (driver && closeStorage) await driver.close?.();
|
|
98
|
+
} catch (cleanupCause) {
|
|
99
|
+
throw new AggregateError([cause, cleanupCause], `Duraxis connection ${name} initialization and cleanup both failed`);
|
|
100
|
+
}
|
|
101
|
+
throw cause;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async close() {
|
|
105
|
+
if (!this.#closing) this.#closing = this.closeResources();
|
|
106
|
+
await this.#closing;
|
|
107
|
+
}
|
|
108
|
+
setBeforeClose(callback) {
|
|
109
|
+
if (this.#beforeClose) throw new Error(`Duraxis connection ${this.name} already has a close coordinator`);
|
|
110
|
+
this.#beforeClose = callback;
|
|
111
|
+
}
|
|
112
|
+
async closeResources() {
|
|
113
|
+
const failures = [];
|
|
114
|
+
try {
|
|
115
|
+
await this.#beforeClose?.();
|
|
116
|
+
} catch (error) {
|
|
117
|
+
failures.push(error);
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
await this.orm.close();
|
|
121
|
+
} catch (error) {
|
|
122
|
+
failures.push(error);
|
|
123
|
+
} finally {
|
|
124
|
+
this.onClosed();
|
|
125
|
+
}
|
|
126
|
+
if (failures.length == 1) throw failures[0];
|
|
127
|
+
if (failures.length > 1) throw new AggregateError(failures, `Duraxis connection ${this.name} shutdown failed`);
|
|
128
|
+
}
|
|
129
|
+
async onModuleDestroy() {
|
|
130
|
+
await this.close();
|
|
131
|
+
}
|
|
132
|
+
async onApplicationShutdown() {
|
|
133
|
+
await this.close();
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
// src/duraxis.errors.ts
|
|
137
|
+
var DuraxisNestError = class extends Error {
|
|
138
|
+
constructor(message, options) {
|
|
139
|
+
super(message, options);
|
|
140
|
+
this.name = new.target.name;
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
var DuplicateDuraxisConnectionError = class extends DuraxisNestError {
|
|
144
|
+
constructor(connectionName) {
|
|
145
|
+
super(`Duraxis connection is configured more than once: ${connectionName}`);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
// src/transactions/transaction-context.manager.ts
|
|
149
|
+
var TransactionContextManager = class {
|
|
150
|
+
#storage = new node_async_hooks.AsyncLocalStorage();
|
|
151
|
+
current(connectionIdentity) {
|
|
152
|
+
return this.#storage.getStore()?.get(connectionIdentity);
|
|
153
|
+
}
|
|
154
|
+
async run(connectionIdentity, context, callback) {
|
|
155
|
+
const contexts = new Map(this.#storage.getStore() ?? []);
|
|
156
|
+
contexts.set(connectionIdentity, context);
|
|
157
|
+
return await this.#storage.run(contexts, callback);
|
|
158
|
+
}
|
|
159
|
+
async suspend(connectionIdentity, callback) {
|
|
160
|
+
const contexts = new Map(this.#storage.getStore() ?? []);
|
|
161
|
+
contexts.delete(connectionIdentity);
|
|
162
|
+
return await this.#storage.run(contexts, callback);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
// src/transactions/transaction.errors.ts
|
|
166
|
+
var TransactionRequiredError = class extends DuraxisNestError {
|
|
167
|
+
constructor(connectionName) {
|
|
168
|
+
super(`An active Duraxis transaction is required for connection ${connectionName}`);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
var ExistingTransactionError = class extends DuraxisNestError {
|
|
172
|
+
constructor(connectionName) {
|
|
173
|
+
super(`An active Duraxis transaction is forbidden for connection ${connectionName}`);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
var NestedTransactionNotSupportedError = class extends DuraxisNestError {
|
|
177
|
+
constructor() {
|
|
178
|
+
super("NESTED propagation is unavailable because Duraxis does not support savepoints");
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
var UnsupportedTransactionIsolationError = class extends DuraxisNestError {
|
|
182
|
+
constructor(isolation) {
|
|
183
|
+
super(`Unsupported Duraxis transaction isolation: ${isolation}`);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
var UnsupportedTransactionTimeoutError = class extends DuraxisNestError {
|
|
187
|
+
constructor() {
|
|
188
|
+
super("Transactional timeout is unavailable because Duraxis cannot safely cancel all writes");
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
var ReadOnlyTransactionError = class extends DuraxisNestError {
|
|
192
|
+
constructor(operation) {
|
|
193
|
+
super(`Operation ${operation} is not allowed in a read-only Duraxis transaction`);
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
var UnexpectedTransactionRollbackError = class extends DuraxisNestError {
|
|
197
|
+
constructor() {
|
|
198
|
+
super("Duraxis transaction rolled back because a participating scope marked it rollback-only");
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
var TransactionContextClosedError = class extends DuraxisNestError {
|
|
202
|
+
constructor() {
|
|
203
|
+
super("Duraxis transaction context is no longer active");
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
var TransactionalMethodReturnTypeError = class extends DuraxisNestError {
|
|
207
|
+
constructor(methodName) {
|
|
208
|
+
super(`Transactional method ${methodName} must return a Promise`);
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
var UnsupportedMixedTransactionError = class extends DuraxisNestError {
|
|
212
|
+
constructor() {
|
|
213
|
+
super("Imperative orm.transaction() cannot be started inside a declarative transaction");
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
var UnawaitedTransactionOperationError = class extends DuraxisNestError {
|
|
217
|
+
constructor(options) {
|
|
218
|
+
super("A repository operation was still pending when the transactional method completed", options);
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
var TransactionManagerShuttingDownError = class extends DuraxisNestError {
|
|
222
|
+
constructor() {
|
|
223
|
+
super("Duraxis transaction manager is shutting down");
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
var TransactionManagerNotFoundError = class extends DuraxisNestError {
|
|
227
|
+
constructor(connectionName) {
|
|
228
|
+
super(`No Duraxis transaction manager is registered for connection ${connectionName}`);
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
// src/transactions/transaction-manager.registry.ts
|
|
232
|
+
var TransactionManagerRegistry = class {
|
|
233
|
+
#managers = /* @__PURE__ */ new Map();
|
|
234
|
+
register(connectionName, manager) {
|
|
235
|
+
this.#managers.set(connectionName, manager);
|
|
236
|
+
}
|
|
237
|
+
unregister(connectionName, manager) {
|
|
238
|
+
if (this.#managers.get(connectionName) == manager) this.#managers.delete(connectionName);
|
|
239
|
+
}
|
|
240
|
+
get(connectionName) {
|
|
241
|
+
const manager = this.#managers.get(connectionName);
|
|
242
|
+
if (!manager) throw new TransactionManagerNotFoundError(connectionName);
|
|
243
|
+
return manager;
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
// \0@oxc-project+runtime@0.156.0/helpers/esm/decorate.js
|
|
247
|
+
function __decorate(decorators, target, key, desc) {
|
|
248
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
249
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
250
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
251
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
252
|
+
}
|
|
253
|
+
// src/duraxis.registry.ts
|
|
254
|
+
var DuraxisConnectionRegistry = class DuraxisConnectionRegistry {
|
|
255
|
+
#active = /* @__PURE__ */ new Map();
|
|
256
|
+
async create(name, options) {
|
|
257
|
+
if (this.#active.get(name)) throw new DuplicateDuraxisConnectionError(name);
|
|
258
|
+
let creation;
|
|
259
|
+
creation = DuraxisNestConnection.create(name, options, () => {
|
|
260
|
+
if (this.#active.get(name) == creation) this.#active.delete(name);
|
|
261
|
+
});
|
|
262
|
+
this.#active.set(name, creation);
|
|
263
|
+
try {
|
|
264
|
+
return await creation;
|
|
265
|
+
} catch (error) {
|
|
266
|
+
if (this.#active.get(name) == creation) this.#active.delete(name);
|
|
267
|
+
throw error;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
DuraxisConnectionRegistry = __decorate([(0, _nestjs_common.Injectable)()], DuraxisConnectionRegistry);
|
|
272
|
+
var DuraxisConnectionRegistryModule = class DuraxisConnectionRegistryModule {};
|
|
273
|
+
DuraxisConnectionRegistryModule = __decorate([(0, _nestjs_common.Global)(), (0, _nestjs_common.Module)({
|
|
274
|
+
providers: [
|
|
275
|
+
DuraxisConnectionRegistry,
|
|
276
|
+
TransactionContextManager,
|
|
277
|
+
TransactionManagerRegistry
|
|
278
|
+
],
|
|
279
|
+
exports: [
|
|
280
|
+
DuraxisConnectionRegistry,
|
|
281
|
+
TransactionContextManager,
|
|
282
|
+
TransactionManagerRegistry
|
|
283
|
+
]
|
|
284
|
+
})], DuraxisConnectionRegistryModule);
|
|
285
|
+
// src/duraxis.feature-discovery.ts
|
|
286
|
+
var DuraxisFeatureEntities = _nestjs_core.DiscoveryService.createDecorator();
|
|
287
|
+
function discoverFeatureEntities(discovery, connectionName) {
|
|
288
|
+
const entities = /* @__PURE__ */ new Set();
|
|
289
|
+
for (const provider of discovery.getProviders({ metadataKey: DuraxisFeatureEntities.KEY })) {
|
|
290
|
+
const metadata = discovery.getMetadataByDecorator(DuraxisFeatureEntities, provider);
|
|
291
|
+
if (metadata?.connectionName != connectionName) continue;
|
|
292
|
+
for (const entity of metadata.entities) entities.add(entity);
|
|
293
|
+
}
|
|
294
|
+
return [...entities];
|
|
295
|
+
}
|
|
296
|
+
// src/transactions/transaction.types.ts
|
|
297
|
+
var TransactionPropagation = /* @__PURE__ */ function(TransactionPropagation) {
|
|
298
|
+
TransactionPropagation["REQUIRED"] = "REQUIRED";
|
|
299
|
+
TransactionPropagation["REQUIRES_NEW"] = "REQUIRES_NEW";
|
|
300
|
+
TransactionPropagation["SUPPORTS"] = "SUPPORTS";
|
|
301
|
+
TransactionPropagation["MANDATORY"] = "MANDATORY";
|
|
302
|
+
TransactionPropagation["NOT_SUPPORTED"] = "NOT_SUPPORTED";
|
|
303
|
+
TransactionPropagation["NEVER"] = "NEVER";
|
|
304
|
+
TransactionPropagation["NESTED"] = "NESTED";
|
|
305
|
+
return TransactionPropagation;
|
|
306
|
+
}({});
|
|
307
|
+
var TransactionIsolation = /* @__PURE__ */ function(TransactionIsolation) {
|
|
308
|
+
TransactionIsolation["DEFAULT"] = "DEFAULT";
|
|
309
|
+
TransactionIsolation["SNAPSHOT"] = "SNAPSHOT";
|
|
310
|
+
return TransactionIsolation;
|
|
311
|
+
}({});
|
|
312
|
+
// src/transactions/transaction-aware.repository.ts
|
|
313
|
+
var WRITE_METHODS = /* @__PURE__ */ new Set([
|
|
314
|
+
"insert",
|
|
315
|
+
"save",
|
|
316
|
+
"update",
|
|
317
|
+
"upsert",
|
|
318
|
+
"delete"
|
|
319
|
+
]);
|
|
320
|
+
var BUILDER_METHODS = /* @__PURE__ */ new Set([
|
|
321
|
+
"where",
|
|
322
|
+
"andWhere",
|
|
323
|
+
"orWhere",
|
|
324
|
+
"andWhereGroup",
|
|
325
|
+
"orWhereGroup",
|
|
326
|
+
"notWhere",
|
|
327
|
+
"orderBy",
|
|
328
|
+
"select",
|
|
329
|
+
"limit",
|
|
330
|
+
"cursor",
|
|
331
|
+
"withSignal"
|
|
332
|
+
]);
|
|
333
|
+
var BUILDER_TERMINALS = /* @__PURE__ */ new Set([
|
|
334
|
+
"getMany",
|
|
335
|
+
"getOne",
|
|
336
|
+
"getCount",
|
|
337
|
+
"getPage",
|
|
338
|
+
"explain",
|
|
339
|
+
"toLogicalQuery"
|
|
340
|
+
]);
|
|
341
|
+
function isPromiseLike$1(value) {
|
|
342
|
+
return (typeof value == "object" || typeof value == "function") && value != null && typeof Reflect.get(value, "then") == "function";
|
|
343
|
+
}
|
|
344
|
+
function transactionAwareBuilder(entity, baseRepository, transactions, captured, steps = []) {
|
|
345
|
+
const target = baseRepository.createQueryBuilder();
|
|
346
|
+
return new Proxy(target, { get(_target, property) {
|
|
347
|
+
if (BUILDER_METHODS.has(property)) return (...arguments_) => transactionAwareBuilder(entity, baseRepository, transactions, captured, [...steps, {
|
|
348
|
+
method: property,
|
|
349
|
+
arguments: arguments_
|
|
350
|
+
}]);
|
|
351
|
+
if (BUILDER_TERMINALS.has(property)) return (...arguments_) => {
|
|
352
|
+
transactions.assertCapturedContext(captured);
|
|
353
|
+
let builder = transactions.resolveRepository(entity, baseRepository).createQueryBuilder();
|
|
354
|
+
for (const step of steps) {
|
|
355
|
+
const method = Reflect.get(builder, step.method);
|
|
356
|
+
if (typeof method != "function") throw new TypeError("Invalid QueryBuilder method");
|
|
357
|
+
const next = Reflect.apply(method, builder, step.arguments);
|
|
358
|
+
if (!(next instanceof _duraxis_orm.QueryBuilder)) throw new TypeError("QueryBuilder chain returned an invalid value");
|
|
359
|
+
builder = next;
|
|
360
|
+
}
|
|
361
|
+
const terminal = Reflect.get(builder, property);
|
|
362
|
+
if (typeof terminal != "function") throw new TypeError("Invalid QueryBuilder terminal");
|
|
363
|
+
const result = Reflect.apply(terminal, builder, arguments_);
|
|
364
|
+
return isPromiseLike$1(result) ? transactions.track(result) : result;
|
|
365
|
+
};
|
|
366
|
+
const value = Reflect.get(target, property, target);
|
|
367
|
+
return typeof value == "function" ? value.bind(target) : value;
|
|
368
|
+
} });
|
|
369
|
+
}
|
|
370
|
+
function createTransactionAwareRepository(entity, baseRepository, transactions) {
|
|
371
|
+
return new Proxy(baseRepository, { get(target, property) {
|
|
372
|
+
if (property == "createQueryBuilder") return () => transactionAwareBuilder(entity, baseRepository, transactions, transactions.currentContext());
|
|
373
|
+
const effective = transactions.resolveRepository(entity, baseRepository);
|
|
374
|
+
const value = Reflect.get(effective, property, effective);
|
|
375
|
+
if (typeof value != "function") return value;
|
|
376
|
+
return (...arguments_) => {
|
|
377
|
+
if (WRITE_METHODS.has(property)) transactions.assertWriteAllowed(String(property));
|
|
378
|
+
const current = transactions.resolveRepository(entity, baseRepository);
|
|
379
|
+
const method = Reflect.get(current, property, current);
|
|
380
|
+
if (typeof method != "function") throw new TypeError("Invalid Repository method");
|
|
381
|
+
const result = Reflect.apply(method, current, arguments_);
|
|
382
|
+
return isPromiseLike$1(result) ? transactions.track(result) : result;
|
|
383
|
+
};
|
|
384
|
+
} });
|
|
385
|
+
}
|
|
386
|
+
function createTransactionAwareOrm(orm, transactions) {
|
|
387
|
+
return new Proxy(orm, { get(target, property) {
|
|
388
|
+
if (property == "getRepository") return (entity) => transactions.getRepository(entity);
|
|
389
|
+
if (property == "transaction") return (...arguments_) => {
|
|
390
|
+
if (transactions.currentContext()) transactions.rejectMixedTransaction();
|
|
391
|
+
const method = Reflect.get(target, property, target);
|
|
392
|
+
if (typeof method != "function") throw new TypeError("Invalid ORM transaction method");
|
|
393
|
+
return Reflect.apply(method, target, arguments_);
|
|
394
|
+
};
|
|
395
|
+
const value = Reflect.get(target, property, target);
|
|
396
|
+
return typeof value == "function" ? value.bind(target) : value;
|
|
397
|
+
} });
|
|
398
|
+
}
|
|
399
|
+
// src/transactions/transaction.manager.ts
|
|
400
|
+
var RollbackOnlyAbort = class extends Error {};
|
|
401
|
+
function isPromiseLike(value) {
|
|
402
|
+
return (typeof value == "object" || typeof value == "function") && value != null && typeof Reflect.get(value, "then") == "function";
|
|
403
|
+
}
|
|
404
|
+
function inheritanceDistance(error, constructor) {
|
|
405
|
+
if (!(error instanceof constructor)) return Number.POSITIVE_INFINITY;
|
|
406
|
+
let distance = 0;
|
|
407
|
+
let prototype = Object.getPrototypeOf(error);
|
|
408
|
+
while (prototype && prototype != constructor.prototype) {
|
|
409
|
+
prototype = Object.getPrototypeOf(prototype);
|
|
410
|
+
distance++;
|
|
411
|
+
}
|
|
412
|
+
return distance;
|
|
413
|
+
}
|
|
414
|
+
function shouldRollback(error, options) {
|
|
415
|
+
if (!(error instanceof Error)) return true;
|
|
416
|
+
let bestDistance = Number.POSITIVE_INFINITY;
|
|
417
|
+
let rollback = true;
|
|
418
|
+
for (const constructor of options.rollbackFor ?? []) {
|
|
419
|
+
const distance = inheritanceDistance(error, constructor);
|
|
420
|
+
if (distance < bestDistance) {
|
|
421
|
+
bestDistance = distance;
|
|
422
|
+
rollback = true;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
for (const constructor of options.noRollbackFor ?? []) {
|
|
426
|
+
const distance = inheritanceDistance(error, constructor);
|
|
427
|
+
if (distance <= bestDistance) {
|
|
428
|
+
bestDistance = distance;
|
|
429
|
+
rollback = false;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
return rollback;
|
|
433
|
+
}
|
|
434
|
+
var TransactionManager = class {
|
|
435
|
+
connectionName;
|
|
436
|
+
connection;
|
|
437
|
+
orm;
|
|
438
|
+
contexts;
|
|
439
|
+
#repositories = /* @__PURE__ */ new Map();
|
|
440
|
+
#ormFacade;
|
|
441
|
+
#accepting = true;
|
|
442
|
+
#activePhysicalTransactions = 0;
|
|
443
|
+
#shutdownWaiters = /* @__PURE__ */ new Set();
|
|
444
|
+
constructor(connectionName, connection, orm, contexts) {
|
|
445
|
+
this.connectionName = connectionName;
|
|
446
|
+
this.connection = connection;
|
|
447
|
+
this.orm = orm;
|
|
448
|
+
this.contexts = contexts;
|
|
449
|
+
this.#ormFacade = createTransactionAwareOrm(orm, this);
|
|
450
|
+
}
|
|
451
|
+
get ormProxy() {
|
|
452
|
+
return this.#ormFacade;
|
|
453
|
+
}
|
|
454
|
+
getRepository(entity) {
|
|
455
|
+
const cached = this.#repositories.get(entity);
|
|
456
|
+
if (cached) return cached;
|
|
457
|
+
const repository = createTransactionAwareRepository(entity, this.orm.getRepository(entity), this);
|
|
458
|
+
this.#repositories.set(entity, repository);
|
|
459
|
+
return repository;
|
|
460
|
+
}
|
|
461
|
+
currentContext() {
|
|
462
|
+
const context = this.contexts.current(this.connection);
|
|
463
|
+
if (context && !context.physical.active) throw new TransactionContextClosedError();
|
|
464
|
+
return context;
|
|
465
|
+
}
|
|
466
|
+
currentStatus() {
|
|
467
|
+
const context = this.currentContext();
|
|
468
|
+
return context ? {
|
|
469
|
+
connectionName: this.connectionName,
|
|
470
|
+
active: context.physical.active,
|
|
471
|
+
newTransaction: context.newTransaction,
|
|
472
|
+
readOnly: context.readOnly,
|
|
473
|
+
rollbackOnly: context.physical.rollbackOnly
|
|
474
|
+
} : null;
|
|
475
|
+
}
|
|
476
|
+
setRollbackOnly() {
|
|
477
|
+
const context = this.currentContext();
|
|
478
|
+
if (!context) throw new TransactionRequiredError(this.connectionName);
|
|
479
|
+
context.physical.rollbackOnly = true;
|
|
480
|
+
}
|
|
481
|
+
async execute(options, methodName, invocation) {
|
|
482
|
+
this.validateOptions(options);
|
|
483
|
+
const current = this.currentContext();
|
|
484
|
+
if (!this.#accepting && !current) throw new TransactionManagerShuttingDownError();
|
|
485
|
+
switch (options.propagation ?? TransactionPropagation.REQUIRED) {
|
|
486
|
+
case TransactionPropagation.REQUIRED: return current ? await this.join(current, options, methodName, invocation) : await this.start(options, methodName, invocation);
|
|
487
|
+
case TransactionPropagation.REQUIRES_NEW: return await this.start(options, methodName, invocation);
|
|
488
|
+
case TransactionPropagation.SUPPORTS: return current ? await this.join(current, options, methodName, invocation) : await this.invoke(methodName, invocation);
|
|
489
|
+
case TransactionPropagation.MANDATORY:
|
|
490
|
+
if (!current) throw new TransactionRequiredError(this.connectionName);
|
|
491
|
+
return await this.join(current, options, methodName, invocation);
|
|
492
|
+
case TransactionPropagation.NOT_SUPPORTED: return current ? await this.contexts.suspend(this.connection, async () => await this.invoke(methodName, invocation)) : await this.invoke(methodName, invocation);
|
|
493
|
+
case TransactionPropagation.NEVER:
|
|
494
|
+
if (current) throw new ExistingTransactionError(this.connectionName);
|
|
495
|
+
return await this.invoke(methodName, invocation);
|
|
496
|
+
case TransactionPropagation.NESTED: throw new NestedTransactionNotSupportedError();
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
resolveRepository(entity, baseRepository) {
|
|
500
|
+
const context = this.currentContext();
|
|
501
|
+
return context ? context.physical.manager.getRepository(entity) : baseRepository;
|
|
502
|
+
}
|
|
503
|
+
assertWriteAllowed(operation) {
|
|
504
|
+
if (this.currentContext()?.readOnly) throw new ReadOnlyTransactionError(operation);
|
|
505
|
+
}
|
|
506
|
+
assertCapturedContext(captured) {
|
|
507
|
+
if (!captured) return;
|
|
508
|
+
const current = this.currentContext();
|
|
509
|
+
if (!captured.physical.active || current?.physical != captured.physical) throw new TransactionContextClosedError();
|
|
510
|
+
}
|
|
511
|
+
track(value) {
|
|
512
|
+
const context = this.currentContext();
|
|
513
|
+
const promise = Promise.resolve(value);
|
|
514
|
+
if (!context) return promise;
|
|
515
|
+
let tracked;
|
|
516
|
+
tracked = (async () => {
|
|
517
|
+
try {
|
|
518
|
+
return await promise;
|
|
519
|
+
} finally {
|
|
520
|
+
context.physical.pending.delete(tracked);
|
|
521
|
+
}
|
|
522
|
+
})();
|
|
523
|
+
context.physical.pending.add(tracked);
|
|
524
|
+
return tracked;
|
|
525
|
+
}
|
|
526
|
+
rejectMixedTransaction() {
|
|
527
|
+
throw new UnsupportedMixedTransactionError();
|
|
528
|
+
}
|
|
529
|
+
async shutdown() {
|
|
530
|
+
this.#accepting = false;
|
|
531
|
+
if (this.#activePhysicalTransactions == 0) return;
|
|
532
|
+
await new Promise((resolve) => this.#shutdownWaiters.add(resolve));
|
|
533
|
+
}
|
|
534
|
+
async start(options, methodName, invocation) {
|
|
535
|
+
if (!this.#accepting) throw new TransactionManagerShuttingDownError();
|
|
536
|
+
this.#activePhysicalTransactions++;
|
|
537
|
+
try {
|
|
538
|
+
const outcome = await this.orm.transaction(async (manager) => {
|
|
539
|
+
const physical = {
|
|
540
|
+
manager,
|
|
541
|
+
pending: /* @__PURE__ */ new Set(),
|
|
542
|
+
active: true,
|
|
543
|
+
rollbackOnly: false
|
|
544
|
+
};
|
|
545
|
+
const context = {
|
|
546
|
+
physical,
|
|
547
|
+
readOnly: options.readOnly ?? false,
|
|
548
|
+
newTransaction: true
|
|
549
|
+
};
|
|
550
|
+
try {
|
|
551
|
+
return await this.contexts.run(this.connection, context, async () => {
|
|
552
|
+
try {
|
|
553
|
+
const value = await this.invoke(methodName, invocation);
|
|
554
|
+
await this.rejectPendingOperations(physical);
|
|
555
|
+
if (physical.rollbackOnly) throw new RollbackOnlyAbort();
|
|
556
|
+
return {
|
|
557
|
+
type: "result",
|
|
558
|
+
value
|
|
559
|
+
};
|
|
560
|
+
} catch (error) {
|
|
561
|
+
await this.rejectPendingOperations(physical);
|
|
562
|
+
if (error instanceof RollbackOnlyAbort || shouldRollback(error, options)) throw error;
|
|
563
|
+
return {
|
|
564
|
+
type: "committed-error",
|
|
565
|
+
error
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
});
|
|
569
|
+
} finally {
|
|
570
|
+
physical.active = false;
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
if (outcome.type == "committed-error") throw outcome.error;
|
|
574
|
+
return outcome.value;
|
|
575
|
+
} catch (error) {
|
|
576
|
+
if (error instanceof RollbackOnlyAbort) throw new UnexpectedTransactionRollbackError();
|
|
577
|
+
throw error;
|
|
578
|
+
} finally {
|
|
579
|
+
this.#activePhysicalTransactions--;
|
|
580
|
+
if (this.#activePhysicalTransactions == 0) for (const resolve of this.#shutdownWaiters) resolve();
|
|
581
|
+
if (this.#activePhysicalTransactions == 0) this.#shutdownWaiters.clear();
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
async join(current, options, methodName, invocation) {
|
|
585
|
+
const context = {
|
|
586
|
+
physical: current.physical,
|
|
587
|
+
readOnly: current.readOnly || (options.readOnly ?? false),
|
|
588
|
+
newTransaction: false
|
|
589
|
+
};
|
|
590
|
+
return await this.contexts.run(this.connection, context, async () => {
|
|
591
|
+
try {
|
|
592
|
+
return await this.invoke(methodName, invocation);
|
|
593
|
+
} catch (error) {
|
|
594
|
+
if (shouldRollback(error, options)) current.physical.rollbackOnly = true;
|
|
595
|
+
throw error;
|
|
596
|
+
}
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
async invoke(methodName, invocation) {
|
|
600
|
+
const result = invocation();
|
|
601
|
+
if (!isPromiseLike(result)) throw new TransactionalMethodReturnTypeError(methodName);
|
|
602
|
+
return await result;
|
|
603
|
+
}
|
|
604
|
+
async rejectPendingOperations(physical) {
|
|
605
|
+
if (physical.pending.size == 0) return;
|
|
606
|
+
const rejected = (await Promise.allSettled([...physical.pending])).find((result) => result.status == "rejected");
|
|
607
|
+
throw new UnawaitedTransactionOperationError(rejected?.status == "rejected" ? { cause: rejected.reason } : void 0);
|
|
608
|
+
}
|
|
609
|
+
validateOptions(options) {
|
|
610
|
+
if (options.timeout != null) throw new UnsupportedTransactionTimeoutError();
|
|
611
|
+
const isolation = options.isolation ?? TransactionIsolation.DEFAULT;
|
|
612
|
+
if (isolation != TransactionIsolation.DEFAULT && isolation != TransactionIsolation.SNAPSHOT) throw new UnsupportedTransactionIsolationError(String(isolation));
|
|
613
|
+
if (options.connectionName != null) normalizeDuraxisConnectionName(options.connectionName);
|
|
614
|
+
}
|
|
615
|
+
};
|
|
616
|
+
// src/transactions/transactional.decorator.ts
|
|
617
|
+
var TRANSACTIONAL_METADATA = Symbol.for("@duraxis/nestjs/transactional");
|
|
618
|
+
function Transactional(options = {}) {
|
|
619
|
+
return (target, _propertyKey, descriptor) => {
|
|
620
|
+
const metadataTarget = descriptor?.value ?? target;
|
|
621
|
+
Reflect.defineMetadata(TRANSACTIONAL_METADATA, Object.freeze({ ...options }), metadataTarget);
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
/** Alias of `@Transactional()`. It is unrelated to `Transaction` from `@duraxis/core`. */
|
|
625
|
+
var Transaction = Transactional;
|
|
626
|
+
function transactionalOptions(instance, method) {
|
|
627
|
+
const classOptions = Reflect.getMetadata(TRANSACTIONAL_METADATA, instance.constructor);
|
|
628
|
+
const methodOptions = Reflect.getMetadata(TRANSACTIONAL_METADATA, method);
|
|
629
|
+
if (!classOptions && !methodOptions) return void 0;
|
|
630
|
+
return {
|
|
631
|
+
...classOptions,
|
|
632
|
+
...methodOptions
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
// src/transactions/transactional.proxy.ts
|
|
636
|
+
var LIFECYCLE_METHODS = /* @__PURE__ */ new Set([
|
|
637
|
+
"onModuleInit",
|
|
638
|
+
"onApplicationBootstrap",
|
|
639
|
+
"onModuleDestroy",
|
|
640
|
+
"beforeApplicationShutdown",
|
|
641
|
+
"onApplicationShutdown"
|
|
642
|
+
]);
|
|
643
|
+
function createTransactionalServiceProxy(instance, managers, defaultConnectionName) {
|
|
644
|
+
const methods = /* @__PURE__ */ new Map();
|
|
645
|
+
return new Proxy(instance, { get(target, property) {
|
|
646
|
+
const cached = methods.get(property);
|
|
647
|
+
if (cached) return cached;
|
|
648
|
+
const value = Reflect.get(target, property, target);
|
|
649
|
+
if (typeof value != "function") return value;
|
|
650
|
+
const options = LIFECYCLE_METHODS.has(property) ? void 0 : transactionalOptions(target, value);
|
|
651
|
+
const method = options ? (...arguments_) => {
|
|
652
|
+
const connectionName = normalizeDuraxisConnectionName(options.connectionName ?? defaultConnectionName);
|
|
653
|
+
return managers.get(connectionName).execute(options, `${target.constructor.name}.${String(property)}`, () => Reflect.apply(value, target, arguments_));
|
|
654
|
+
} : value.bind(target);
|
|
655
|
+
methods.set(property, method);
|
|
656
|
+
return method;
|
|
657
|
+
} });
|
|
658
|
+
}
|
|
659
|
+
function transactionalServiceProvider(service, defaultConnectionName) {
|
|
660
|
+
return {
|
|
661
|
+
provide: service,
|
|
662
|
+
inject: [_nestjs_core.ModuleRef, TransactionManagerRegistry],
|
|
663
|
+
useFactory: async (moduleRef, managers) => createTransactionalServiceProxy(await moduleRef.create(service), managers, defaultConnectionName)
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
// src/duraxis.module.ts
|
|
667
|
+
function rootProviders(name, optionsProvider) {
|
|
668
|
+
const connectionToken = getDuraxisConnectionToken(name);
|
|
669
|
+
const ormToken = getDuraxisOrmToken(name);
|
|
670
|
+
const databaseToken = getDuraxisDatabaseToken(name);
|
|
671
|
+
const transactionManagerToken = getDuraxisTransactionManagerToken(name);
|
|
672
|
+
return [
|
|
673
|
+
optionsProvider,
|
|
674
|
+
{
|
|
675
|
+
provide: connectionToken,
|
|
676
|
+
inject: [
|
|
677
|
+
getDuraxisOptionsToken(name),
|
|
678
|
+
DuraxisConnectionRegistry,
|
|
679
|
+
_nestjs_core.DiscoveryService
|
|
680
|
+
],
|
|
681
|
+
useFactory: async (options, registry, discovery) => {
|
|
682
|
+
const entities = new Set(options.entities ?? []);
|
|
683
|
+
if (options.autoLoadEntities) for (const entity of discoverFeatureEntities(discovery, name)) entities.add(entity);
|
|
684
|
+
return await registry.create(name, {
|
|
685
|
+
...options,
|
|
686
|
+
entities: [...entities]
|
|
687
|
+
});
|
|
688
|
+
}
|
|
689
|
+
},
|
|
690
|
+
{
|
|
691
|
+
provide: transactionManagerToken,
|
|
692
|
+
inject: [
|
|
693
|
+
connectionToken,
|
|
694
|
+
TransactionContextManager,
|
|
695
|
+
TransactionManagerRegistry
|
|
696
|
+
],
|
|
697
|
+
useFactory: (connection, contexts, managers) => {
|
|
698
|
+
const manager = new TransactionManager(name, connection, connection.orm, contexts);
|
|
699
|
+
managers.register(name, manager);
|
|
700
|
+
connection.setBeforeClose(async () => {
|
|
701
|
+
await manager.shutdown();
|
|
702
|
+
managers.unregister(name, manager);
|
|
703
|
+
});
|
|
704
|
+
return manager;
|
|
705
|
+
}
|
|
706
|
+
},
|
|
707
|
+
{
|
|
708
|
+
provide: ormToken,
|
|
709
|
+
inject: [transactionManagerToken],
|
|
710
|
+
useFactory: (transactions) => transactions.ormProxy
|
|
711
|
+
},
|
|
712
|
+
{
|
|
713
|
+
provide: databaseToken,
|
|
714
|
+
inject: [connectionToken],
|
|
715
|
+
useFactory: (connection) => connection.database
|
|
716
|
+
}
|
|
717
|
+
];
|
|
718
|
+
}
|
|
719
|
+
function rootModule(name, providers, imports = []) {
|
|
720
|
+
return {
|
|
721
|
+
module: DuraxisModule,
|
|
722
|
+
global: true,
|
|
723
|
+
imports: [
|
|
724
|
+
_nestjs_core.DiscoveryModule,
|
|
725
|
+
DuraxisConnectionRegistryModule,
|
|
726
|
+
...imports ?? []
|
|
727
|
+
],
|
|
728
|
+
providers: [...providers],
|
|
729
|
+
exports: [
|
|
730
|
+
getDuraxisOrmToken(name),
|
|
731
|
+
getDuraxisDatabaseToken(name),
|
|
732
|
+
getDuraxisTransactionManagerToken(name)
|
|
733
|
+
]
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
function featureModule(entities, services, connectionName) {
|
|
737
|
+
const name = normalizeDuraxisConnectionName(connectionName);
|
|
738
|
+
const uniqueEntities = [...new Set(entities)];
|
|
739
|
+
const uniqueServices = [...new Set(services)];
|
|
740
|
+
const repositoryProviders = uniqueEntities.map((entity) => repositoryProvider(entity, name));
|
|
741
|
+
const serviceProviders = uniqueServices.map((service) => transactionalServiceProvider(service, name));
|
|
742
|
+
let DuraxisFeatureEntitiesMarker = class DuraxisFeatureEntitiesMarker {};
|
|
743
|
+
DuraxisFeatureEntitiesMarker = __decorate([DuraxisFeatureEntities({
|
|
744
|
+
connectionName: name,
|
|
745
|
+
entities: uniqueEntities
|
|
746
|
+
})], DuraxisFeatureEntitiesMarker);
|
|
747
|
+
return {
|
|
748
|
+
module: DuraxisModule,
|
|
749
|
+
providers: [
|
|
750
|
+
DuraxisFeatureEntitiesMarker,
|
|
751
|
+
...repositoryProviders,
|
|
752
|
+
...serviceProviders
|
|
753
|
+
],
|
|
754
|
+
exports: [...repositoryProviders.map((provider) => provider.provide), ...uniqueServices]
|
|
755
|
+
};
|
|
756
|
+
}
|
|
757
|
+
function repositoryProvider(entity, connectionName) {
|
|
758
|
+
return {
|
|
759
|
+
provide: getDuraxisRepositoryToken(entity, connectionName),
|
|
760
|
+
inject: [getDuraxisOrmToken(connectionName)],
|
|
761
|
+
useFactory: (orm) => orm.getRepository(entity)
|
|
762
|
+
};
|
|
763
|
+
}
|
|
764
|
+
var DuraxisModule = class DuraxisModule {
|
|
765
|
+
static forRoot(options) {
|
|
766
|
+
const name = normalizeDuraxisConnectionName(options.name);
|
|
767
|
+
const connectionOptions = {
|
|
768
|
+
driver: options.driver,
|
|
769
|
+
...options.entities == null ? {} : { entities: options.entities },
|
|
770
|
+
...options.autoLoadEntities == null ? {} : { autoLoadEntities: options.autoLoadEntities },
|
|
771
|
+
...options.database == null ? {} : { database: options.database },
|
|
772
|
+
...options.schema == null ? {} : { schema: options.schema },
|
|
773
|
+
...options.closeStorage == null ? {} : { closeStorage: options.closeStorage }
|
|
774
|
+
};
|
|
775
|
+
return rootModule(name, rootProviders(name, {
|
|
776
|
+
provide: getDuraxisOptionsToken(name),
|
|
777
|
+
useValue: connectionOptions
|
|
778
|
+
}));
|
|
779
|
+
}
|
|
780
|
+
static forRootAsync(options) {
|
|
781
|
+
const name = normalizeDuraxisConnectionName(options.name);
|
|
782
|
+
return rootModule(name, rootProviders(name, {
|
|
783
|
+
provide: getDuraxisOptionsToken(name),
|
|
784
|
+
inject: options.inject == null ? [] : [...options.inject],
|
|
785
|
+
useFactory: options.useFactory
|
|
786
|
+
}), options.imports);
|
|
787
|
+
}
|
|
788
|
+
static forFeature(entities, connectionName) {
|
|
789
|
+
return featureModule(entities, [], connectionName);
|
|
790
|
+
}
|
|
791
|
+
static forTransactionalFeature(entities, providers, connectionName) {
|
|
792
|
+
return featureModule(entities, providers, connectionName);
|
|
793
|
+
}
|
|
794
|
+
static forTransactionalProviders(providers, connectionName) {
|
|
795
|
+
return featureModule([], providers, connectionName);
|
|
796
|
+
}
|
|
797
|
+
};
|
|
798
|
+
DuraxisModule = __decorate([(0, _nestjs_common.Module)({})], DuraxisModule);
|
|
799
|
+
// src/duraxis.decorators.ts
|
|
800
|
+
function InjectDuraxisRepository(entity, connectionName) {
|
|
801
|
+
return (0, _nestjs_common.Inject)(getDuraxisRepositoryToken(entity, connectionName));
|
|
802
|
+
}
|
|
803
|
+
function InjectDuraxisOrm(connectionName) {
|
|
804
|
+
return (0, _nestjs_common.Inject)(getDuraxisOrmToken(connectionName));
|
|
805
|
+
}
|
|
806
|
+
function InjectDuraxisDatabase(connectionName) {
|
|
807
|
+
return (0, _nestjs_common.Inject)(getDuraxisDatabaseToken(connectionName));
|
|
808
|
+
}
|
|
809
|
+
function InjectDuraxisTransactionManager(connectionName) {
|
|
810
|
+
return (0, _nestjs_common.Inject)(getDuraxisTransactionManagerToken(connectionName));
|
|
811
|
+
}
|
|
812
|
+
exports.DEFAULT_DURAXIS_CONNECTION = DEFAULT_DURAXIS_CONNECTION;
|
|
813
|
+
exports.DuplicateDuraxisConnectionError = DuplicateDuraxisConnectionError;
|
|
814
|
+
Object.defineProperty(exports, "DuraxisModule", {
|
|
815
|
+
enumerable: true,
|
|
816
|
+
get: function() {
|
|
817
|
+
return DuraxisModule;
|
|
818
|
+
}
|
|
819
|
+
});
|
|
820
|
+
exports.DuraxisNestError = DuraxisNestError;
|
|
821
|
+
exports.ExistingTransactionError = ExistingTransactionError;
|
|
822
|
+
exports.InjectDuraxisDatabase = InjectDuraxisDatabase;
|
|
823
|
+
exports.InjectDuraxisOrm = InjectDuraxisOrm;
|
|
824
|
+
exports.InjectDuraxisRepository = InjectDuraxisRepository;
|
|
825
|
+
exports.InjectDuraxisTransactionManager = InjectDuraxisTransactionManager;
|
|
826
|
+
exports.NestedTransactionNotSupportedError = NestedTransactionNotSupportedError;
|
|
827
|
+
exports.ReadOnlyTransactionError = ReadOnlyTransactionError;
|
|
828
|
+
exports.Transaction = Transaction;
|
|
829
|
+
exports.TransactionContextClosedError = TransactionContextClosedError;
|
|
830
|
+
exports.TransactionContextManager = TransactionContextManager;
|
|
831
|
+
exports.TransactionIsolation = TransactionIsolation;
|
|
832
|
+
exports.TransactionManager = TransactionManager;
|
|
833
|
+
exports.TransactionManagerNotFoundError = TransactionManagerNotFoundError;
|
|
834
|
+
exports.TransactionManagerShuttingDownError = TransactionManagerShuttingDownError;
|
|
835
|
+
exports.TransactionPropagation = TransactionPropagation;
|
|
836
|
+
exports.TransactionRequiredError = TransactionRequiredError;
|
|
837
|
+
exports.Transactional = Transactional;
|
|
838
|
+
exports.TransactionalMethodReturnTypeError = TransactionalMethodReturnTypeError;
|
|
839
|
+
exports.UnawaitedTransactionOperationError = UnawaitedTransactionOperationError;
|
|
840
|
+
exports.UnexpectedTransactionRollbackError = UnexpectedTransactionRollbackError;
|
|
841
|
+
exports.UnsupportedMixedTransactionError = UnsupportedMixedTransactionError;
|
|
842
|
+
exports.UnsupportedTransactionIsolationError = UnsupportedTransactionIsolationError;
|
|
843
|
+
exports.UnsupportedTransactionTimeoutError = UnsupportedTransactionTimeoutError;
|
|
844
|
+
exports.getDuraxisDatabaseToken = getDuraxisDatabaseToken;
|
|
845
|
+
exports.getDuraxisOrmToken = getDuraxisOrmToken;
|
|
846
|
+
exports.getDuraxisRepositoryToken = getDuraxisRepositoryToken;
|
|
847
|
+
exports.getDuraxisTransactionManagerToken = getDuraxisTransactionManagerToken;
|
|
848
|
+
|
|
849
|
+
//# sourceMappingURL=index.cjs.map
|