@ts-transactional/core 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/dist/adapters/transaction.adapter.d.ts +14 -0
- package/dist/adapters/transaction.adapter.js +11 -0
- package/dist/adapters/transaction.adapter.js.map +1 -0
- package/dist/decorators/transactional.decorator.d.ts +2 -0
- package/dist/decorators/transactional.decorator.js +21 -0
- package/dist/decorators/transactional.decorator.js.map +1 -0
- package/dist/errors/transaction.errors.d.ts +15 -0
- package/dist/errors/transaction.errors.js +24 -0
- package/dist/errors/transaction.errors.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/manager/transaction.manager.d.ts +23 -0
- package/dist/manager/transaction.manager.js +135 -0
- package/dist/manager/transaction.manager.js.map +1 -0
- package/dist/types/transaction.types.d.ts +37 -0
- package/dist/types/transaction.types.js +20 -0
- package/dist/types/transaction.types.js.map +1 -0
- package/package.json +25 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DataSourceClass, TransactionalBeginTransactionArgs } from '../types/transaction.types';
|
|
2
|
+
export type TransactionAdapter<SourceClass extends DataSourceClass, Transaction = any> = {
|
|
3
|
+
dataSourceClass: SourceClass;
|
|
4
|
+
beginTransaction: (dataSource: InstanceType<SourceClass>, transactionArgs: TransactionalBeginTransactionArgs) => Promise<Transaction>;
|
|
5
|
+
commit: (transaction: Transaction) => Promise<void>;
|
|
6
|
+
rollback: (transaction: Transaction) => Promise<void>;
|
|
7
|
+
};
|
|
8
|
+
export declare class TransactionAdapterFactory {
|
|
9
|
+
static create<SourceClass extends DataSourceClass, Transaction>(adapter: TransactionAdapter<SourceClass, Transaction> & {
|
|
10
|
+
initializer?: () => void;
|
|
11
|
+
}): TransactionAdapter<SourceClass, Transaction> & {
|
|
12
|
+
initializer?: () => void;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransactionAdapterFactory = void 0;
|
|
4
|
+
class TransactionAdapterFactory {
|
|
5
|
+
static create(adapter) {
|
|
6
|
+
adapter?.initializer?.();
|
|
7
|
+
return adapter;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.TransactionAdapterFactory = TransactionAdapterFactory;
|
|
11
|
+
//# sourceMappingURL=transaction.adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.adapter.js","sourceRoot":"","sources":["../../src/adapters/transaction.adapter.ts"],"names":[],"mappings":";;;AAYA,MAAa,yBAAyB;IACpC,MAAM,CAAC,MAAM,CACX,OAEC;QAED,OAAO,EAAE,WAAW,EAAE,EAAE,CAAA;QACxB,OAAO,OAAO,CAAA;IAChB,CAAC;CACF;AATD,8DASC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Transactional = Transactional;
|
|
4
|
+
const transaction_manager_1 = require("../manager/transaction.manager");
|
|
5
|
+
function Transactional(options = {}) {
|
|
6
|
+
return function (target, propertyKey, descriptor) {
|
|
7
|
+
const originalMethod = descriptor.value;
|
|
8
|
+
descriptor.value = async function (...args) {
|
|
9
|
+
return transaction_manager_1.TransactionManager.execTransaction({
|
|
10
|
+
transactionOptions: options,
|
|
11
|
+
targetMethodInfo: {
|
|
12
|
+
method: originalMethod,
|
|
13
|
+
this: this,
|
|
14
|
+
methodArgs: args,
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
return descriptor;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=transactional.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transactional.decorator.js","sourceRoot":"","sources":["../../src/decorators/transactional.decorator.ts"],"names":[],"mappings":";;AAGA,sCAiBC;AApBD,wEAAmE;AAGnE,SAAgB,aAAa,CAAC,UAAgC,EAAE;IAC9D,OAAO,UAAU,MAAW,EAAE,WAA4B,EAAE,UAA8B;QACxF,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAA;QAEvC,UAAU,CAAC,KAAK,GAAG,KAAK,WAAW,GAAG,IAAW;YAC/C,OAAO,wCAAkB,CAAC,eAAe,CAAC;gBACxC,kBAAkB,EAAE,OAAO;gBAC3B,gBAAgB,EAAE;oBAChB,MAAM,EAAE,cAAc;oBACtB,IAAI,EAAE,IAAI;oBACV,UAAU,EAAE,IAAI;iBACjB;aACF,CAAC,CAAA;QACJ,CAAC,CAAA;QAED,OAAO,UAAU,CAAA;IACnB,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare class TransactionManagerError extends Error {
|
|
2
|
+
readonly code: string;
|
|
3
|
+
constructor({ code, message }: {
|
|
4
|
+
code: string;
|
|
5
|
+
message: string;
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
export declare class DataSourceNotFoundError extends TransactionManagerError {
|
|
9
|
+
constructor();
|
|
10
|
+
}
|
|
11
|
+
export declare class TransactionPropagationError extends TransactionManagerError {
|
|
12
|
+
constructor({ message }: {
|
|
13
|
+
message: string;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransactionPropagationError = exports.DataSourceNotFoundError = exports.TransactionManagerError = void 0;
|
|
4
|
+
class TransactionManagerError extends Error {
|
|
5
|
+
code;
|
|
6
|
+
constructor({ code, message }) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.code = code;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.TransactionManagerError = TransactionManagerError;
|
|
12
|
+
class DataSourceNotFoundError extends TransactionManagerError {
|
|
13
|
+
constructor() {
|
|
14
|
+
super({ code: 'DATASOURCE_NOT_FOUND', message: 'dataSource not found' });
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.DataSourceNotFoundError = DataSourceNotFoundError;
|
|
18
|
+
class TransactionPropagationError extends TransactionManagerError {
|
|
19
|
+
constructor({ message }) {
|
|
20
|
+
super({ code: `TRANSACTION_PROPAGATION_ERROR`, message: message });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.TransactionPropagationError = TransactionPropagationError;
|
|
24
|
+
//# sourceMappingURL=transaction.errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.errors.js","sourceRoot":"","sources":["../../src/errors/transaction.errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,uBAAwB,SAAQ,KAAK;IACvC,IAAI,CAAQ;IACrB,YAAY,EAAE,IAAI,EAAE,OAAO,EAAqC;QAC9D,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;CACF;AAND,0DAMC;AAED,MAAa,uBAAwB,SAAQ,uBAAuB;IAClE;QACE,KAAK,CAAC,EAAE,IAAI,EAAE,sBAAsB,EAAE,OAAO,EAAE,sBAAsB,EAAE,CAAC,CAAA;IAC1E,CAAC;CACF;AAJD,0DAIC;AAED,MAAa,2BAA4B,SAAQ,uBAAuB;IACtE,YAAY,EAAsB,OAAO,EAAwD;QAC/F,KAAK,CAAC,EAAE,IAAI,EAAE,+BAA+B,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAA;IACpE,CAAC;CACF;AAJD,kEAIC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./manager/transaction.manager"), exports);
|
|
18
|
+
__exportStar(require("./decorators/transactional.decorator"), exports);
|
|
19
|
+
__exportStar(require("./adapters/transaction.adapter"), exports);
|
|
20
|
+
__exportStar(require("./errors/transaction.errors"), exports);
|
|
21
|
+
__exportStar(require("./types/transaction.types"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gEAA6C;AAC7C,uEAAoD;AACpD,iEAA8C;AAC9C,8DAA2C;AAC3C,4DAAyC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { DataSourceObject, TransactionalOptions, TransactionalStore } from '../types/transaction.types';
|
|
2
|
+
export declare class TransactionManager {
|
|
3
|
+
private static defaultTransactionOptions;
|
|
4
|
+
private static asyncLocalStorage;
|
|
5
|
+
private static adapters;
|
|
6
|
+
private static _dataSources;
|
|
7
|
+
private static _primaryDataSource;
|
|
8
|
+
static get dataSources(): Map<any, DataSourceObject>;
|
|
9
|
+
static get primaryDataSource(): DataSourceObject;
|
|
10
|
+
private static set primaryDataSource(value);
|
|
11
|
+
private static getDataSourceKey;
|
|
12
|
+
static addDataSource(dataSource: DataSourceObject): void;
|
|
13
|
+
static getDataSource(dataSourceKey?: any): DataSourceObject;
|
|
14
|
+
static getAsyncLocalStorageTransactionStore(): TransactionalStore;
|
|
15
|
+
static execTransaction({ transactionOptions, targetMethodInfo, }: {
|
|
16
|
+
transactionOptions: TransactionalOptions;
|
|
17
|
+
targetMethodInfo: {
|
|
18
|
+
this: any;
|
|
19
|
+
method: (...args: any[]) => Promise<any>;
|
|
20
|
+
methodArgs?: any[];
|
|
21
|
+
};
|
|
22
|
+
}): Promise<any>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransactionManager = void 0;
|
|
4
|
+
const async_hooks_1 = require("async_hooks");
|
|
5
|
+
const transaction_errors_1 = require("../errors/transaction.errors");
|
|
6
|
+
const transaction_types_1 = require("../types/transaction.types");
|
|
7
|
+
class TransactionManager {
|
|
8
|
+
static defaultTransactionOptions = {
|
|
9
|
+
propagation: transaction_types_1.Propagation.REQUIRED,
|
|
10
|
+
};
|
|
11
|
+
static asyncLocalStorage = new async_hooks_1.AsyncLocalStorage();
|
|
12
|
+
static adapters = new Map();
|
|
13
|
+
static _dataSources = new Map();
|
|
14
|
+
static _primaryDataSource;
|
|
15
|
+
static get dataSources() {
|
|
16
|
+
return this._dataSources;
|
|
17
|
+
}
|
|
18
|
+
static get primaryDataSource() {
|
|
19
|
+
return this._primaryDataSource;
|
|
20
|
+
}
|
|
21
|
+
static set primaryDataSource(dataSource) {
|
|
22
|
+
this._primaryDataSource = dataSource;
|
|
23
|
+
}
|
|
24
|
+
static getDataSourceKey(dataSourceKey) {
|
|
25
|
+
if (!dataSourceKey)
|
|
26
|
+
return null;
|
|
27
|
+
else if (typeof dataSourceKey === 'string')
|
|
28
|
+
return dataSourceKey;
|
|
29
|
+
else {
|
|
30
|
+
if (dataSourceKey.constructor === Function) {
|
|
31
|
+
return dataSourceKey;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
return dataSourceKey?.constructor || dataSourceKey;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
static addDataSource(dataSource) {
|
|
39
|
+
dataSource.key ??= this.getDataSourceKey(dataSource.key || dataSource.source);
|
|
40
|
+
this.dataSources.set(dataSource.key, dataSource);
|
|
41
|
+
if (!this.primaryDataSource || dataSource.primary) {
|
|
42
|
+
this.primaryDataSource = dataSource;
|
|
43
|
+
}
|
|
44
|
+
if (dataSource?.transactionAdapter) {
|
|
45
|
+
this.adapters.set(dataSource.key, dataSource.transactionAdapter);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
static getDataSource(dataSourceKey) {
|
|
49
|
+
dataSourceKey = this.getDataSourceKey(dataSourceKey);
|
|
50
|
+
const dataSource = !dataSourceKey ? this.primaryDataSource : this.dataSources.get(dataSourceKey);
|
|
51
|
+
if (!dataSource) {
|
|
52
|
+
throw new transaction_errors_1.DataSourceNotFoundError();
|
|
53
|
+
}
|
|
54
|
+
return dataSource;
|
|
55
|
+
}
|
|
56
|
+
static getAsyncLocalStorageTransactionStore() {
|
|
57
|
+
const store = Object.assign({}, this.asyncLocalStorage.getStore() || {});
|
|
58
|
+
return store;
|
|
59
|
+
}
|
|
60
|
+
static async execTransaction({ transactionOptions, targetMethodInfo, }) {
|
|
61
|
+
const { propagation = this.defaultTransactionOptions.propagation || transaction_types_1.Propagation.SUPPORTS, readOnly, autocommit, isolationLevel, dataSourceKey, } = transactionOptions;
|
|
62
|
+
const store = TransactionManager.getAsyncLocalStorageTransactionStore();
|
|
63
|
+
const dataSource = TransactionManager.getDataSource(dataSourceKey);
|
|
64
|
+
const transactionAdapter = dataSource.transactionAdapter;
|
|
65
|
+
let isNewTransaction = false;
|
|
66
|
+
const beforeTransaction = store?.transaction;
|
|
67
|
+
const beginTransaction = async () => {
|
|
68
|
+
store.transactionID = Date.now() + '';
|
|
69
|
+
console.log('beginTransaction', store.transactionID);
|
|
70
|
+
store.adapter = transactionAdapter;
|
|
71
|
+
store.transaction = await transactionAdapter.beginTransaction(dataSource.source, {
|
|
72
|
+
isolationLevel,
|
|
73
|
+
});
|
|
74
|
+
isNewTransaction = true;
|
|
75
|
+
};
|
|
76
|
+
switch (propagation) {
|
|
77
|
+
case transaction_types_1.Propagation.REQUIRED:
|
|
78
|
+
if (!store.transaction) {
|
|
79
|
+
await beginTransaction();
|
|
80
|
+
}
|
|
81
|
+
break;
|
|
82
|
+
case transaction_types_1.Propagation.SUPPORTS:
|
|
83
|
+
if (!store.transaction) {
|
|
84
|
+
console.log('Executing without transaction');
|
|
85
|
+
}
|
|
86
|
+
break;
|
|
87
|
+
case transaction_types_1.Propagation.MANDATORY:
|
|
88
|
+
if (!store.transaction) {
|
|
89
|
+
throw new transaction_errors_1.TransactionPropagationError({ message: 'No existing transaction found for propagation MANDATORY' });
|
|
90
|
+
}
|
|
91
|
+
break;
|
|
92
|
+
case transaction_types_1.Propagation.REQUIRES_NEW:
|
|
93
|
+
await beginTransaction();
|
|
94
|
+
break;
|
|
95
|
+
case transaction_types_1.Propagation.NOT_SUPPORTED:
|
|
96
|
+
if (store.transaction) {
|
|
97
|
+
store.transaction = null;
|
|
98
|
+
console.log('Suspending current transaction');
|
|
99
|
+
}
|
|
100
|
+
break;
|
|
101
|
+
case transaction_types_1.Propagation.NEVER:
|
|
102
|
+
if (store.transaction) {
|
|
103
|
+
throw new transaction_errors_1.TransactionPropagationError({ message: 'Transaction present for propagation NEVER' });
|
|
104
|
+
}
|
|
105
|
+
break;
|
|
106
|
+
default:
|
|
107
|
+
throw new transaction_errors_1.TransactionPropagationError({ message: `Unsupported propagation type: ${propagation}` });
|
|
108
|
+
}
|
|
109
|
+
return this.asyncLocalStorage.run(store, async () => {
|
|
110
|
+
try {
|
|
111
|
+
const result = await targetMethodInfo.method.apply(targetMethodInfo.this, targetMethodInfo.methodArgs || []);
|
|
112
|
+
if (isNewTransaction) {
|
|
113
|
+
console.log('commit', store.transactionID, !!store.transaction);
|
|
114
|
+
await store.adapter?.commit(store.transaction);
|
|
115
|
+
}
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
if (isNewTransaction) {
|
|
120
|
+
console.log('rollback', store.transactionID, !!store.transaction);
|
|
121
|
+
await store.adapter?.rollback(store.transaction);
|
|
122
|
+
}
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
finally {
|
|
126
|
+
if (isNewTransaction) {
|
|
127
|
+
console.log('endTransaction', store.transactionID, !!store.transaction);
|
|
128
|
+
}
|
|
129
|
+
store.transaction = beforeTransaction;
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
exports.TransactionManager = TransactionManager;
|
|
135
|
+
//# sourceMappingURL=transaction.manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.manager.js","sourceRoot":"","sources":["../../src/manager/transaction.manager.ts"],"names":[],"mappings":";;;AAAA,6CAA+C;AAG/C,qEAAmG;AACnG,kEAAoH;AAGpH,MAAa,kBAAkB;IACrB,MAAM,CAAC,yBAAyB,GAAkC;QACxE,WAAW,EAAE,+BAAW,CAAC,QAAQ;KAClC,CAAA;IAEO,MAAM,CAAC,iBAAiB,GAAG,IAAI,+BAAiB,EAAsB,CAAA;IACtE,MAAM,CAAC,QAAQ,GAAsC,IAAI,GAAG,EAAE,CAAA;IAE9D,MAAM,CAAC,YAAY,GAA+B,IAAI,GAAG,EAAE,CAAA;IAC3D,MAAM,CAAC,kBAAkB,CAAkB;IAE5C,MAAM,KAAK,WAAW;QAC3B,OAAO,IAAI,CAAC,YAAY,CAAA;IAC1B,CAAC;IAEM,MAAM,KAAK,iBAAiB;QACjC,OAAO,IAAI,CAAC,kBAAkB,CAAA;IAChC,CAAC;IACO,MAAM,KAAK,iBA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,gBAAgB,CAAC,UAAU,IAAI,EAAE,CAAC,CAAA;gBAE5G,IAAI,gBAAgB,EAAE,CAAC;oBACrB,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,aAAa,EAAE,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;oBAC/D,MAAM,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;gBAChD,CAAC;gBAED,OAAO,MAAM,CAAA;YACf,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,gBAAgB,EAAE,CAAC;oBACrB,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,KAAK,CAAC,aAAa,EAAE,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;oBACjE,MAAM,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;gBAClD,CAAC;gBAED,MAAM,KAAK,CAAA;YACb,CAAC;oBAAS,CAAC;gBACT,IAAI,gBAAgB,EAAE,CAAC;oBACrB,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,KAAK,CAAC,aAAa,EAAE,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;gBACzE,CAAC;gBAED,KAAK,CAAC,WAAW,GAAG,iBAAiB,CAAA;YACvC,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;;AA3KH,gDA4KC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { TransactionAdapter } from '../adapters/transaction.adapter';
|
|
2
|
+
export declare enum Propagation {
|
|
3
|
+
REQUIRED = "REQUIRED",
|
|
4
|
+
SUPPORTS = "SUPPORTS",
|
|
5
|
+
MANDATORY = "MANDATORY",
|
|
6
|
+
REQUIRES_NEW = "REQUIRES_NEW",
|
|
7
|
+
NOT_SUPPORTED = "NOT_SUPPORTED",
|
|
8
|
+
NEVER = "NEVER"
|
|
9
|
+
}
|
|
10
|
+
export declare enum ISOLATION_LEVELS {
|
|
11
|
+
READ_UNCOMMITTED = "READ UNCOMMITTED",
|
|
12
|
+
READ_COMMITTED = "READ COMMITTED",
|
|
13
|
+
REPEATABLE_READ = "REPEATABLE READ",
|
|
14
|
+
SERIALIZABLE = "SERIALIZABLE"
|
|
15
|
+
}
|
|
16
|
+
export interface TransactionalOptions {
|
|
17
|
+
propagation?: Propagation;
|
|
18
|
+
dataSourceKey?: any;
|
|
19
|
+
isolationLevel?: ISOLATION_LEVELS;
|
|
20
|
+
autocommit?: boolean;
|
|
21
|
+
readOnly?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export type TransactionalBeginTransactionArgs = Pick<TransactionalOptions, 'isolationLevel' | 'autocommit' | 'readOnly'>;
|
|
24
|
+
export type DataSourceClass = {
|
|
25
|
+
new (): any;
|
|
26
|
+
};
|
|
27
|
+
export type DataSourceObject<T = any> = {
|
|
28
|
+
source: T;
|
|
29
|
+
key?: any;
|
|
30
|
+
primary?: boolean;
|
|
31
|
+
transactionAdapter?: TransactionAdapter<any>;
|
|
32
|
+
};
|
|
33
|
+
export type TransactionalStore = {
|
|
34
|
+
transaction?: any;
|
|
35
|
+
adapter?: TransactionAdapter<any>;
|
|
36
|
+
transactionID?: string;
|
|
37
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ISOLATION_LEVELS = exports.Propagation = void 0;
|
|
4
|
+
var Propagation;
|
|
5
|
+
(function (Propagation) {
|
|
6
|
+
Propagation["REQUIRED"] = "REQUIRED";
|
|
7
|
+
Propagation["SUPPORTS"] = "SUPPORTS";
|
|
8
|
+
Propagation["MANDATORY"] = "MANDATORY";
|
|
9
|
+
Propagation["REQUIRES_NEW"] = "REQUIRES_NEW";
|
|
10
|
+
Propagation["NOT_SUPPORTED"] = "NOT_SUPPORTED";
|
|
11
|
+
Propagation["NEVER"] = "NEVER";
|
|
12
|
+
})(Propagation || (exports.Propagation = Propagation = {}));
|
|
13
|
+
var ISOLATION_LEVELS;
|
|
14
|
+
(function (ISOLATION_LEVELS) {
|
|
15
|
+
ISOLATION_LEVELS["READ_UNCOMMITTED"] = "READ UNCOMMITTED";
|
|
16
|
+
ISOLATION_LEVELS["READ_COMMITTED"] = "READ COMMITTED";
|
|
17
|
+
ISOLATION_LEVELS["REPEATABLE_READ"] = "REPEATABLE READ";
|
|
18
|
+
ISOLATION_LEVELS["SERIALIZABLE"] = "SERIALIZABLE";
|
|
19
|
+
})(ISOLATION_LEVELS || (exports.ISOLATION_LEVELS = ISOLATION_LEVELS = {}));
|
|
20
|
+
//# sourceMappingURL=transaction.types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.types.js","sourceRoot":"","sources":["../../src/types/transaction.types.ts"],"names":[],"mappings":";;;AAEA,IAAY,WAQX;AARD,WAAY,WAAW;IACrB,oCAAqB,CAAA;IACrB,oCAAqB,CAAA;IACrB,sCAAuB,CAAA;IACvB,4CAA6B,CAAA;IAC7B,8CAA+B,CAAA;IAC/B,8BAAe,CAAA;AAEjB,CAAC,EARW,WAAW,2BAAX,WAAW,QAQtB;AAED,IAAY,gBAKX;AALD,WAAY,gBAAgB;IAC1B,yDAAqC,CAAA;IACrC,qDAAiC,CAAA;IACjC,uDAAmC,CAAA;IACnC,iDAA6B,CAAA;AAC/B,CAAC,EALW,gBAAgB,gCAAhB,gBAAgB,QAK3B"}
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ts-transactional/core",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "node.js typescript transactional library",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"peerDependencies": {
|
|
7
|
+
"reflect-metadata": "^0.2.2"
|
|
8
|
+
},
|
|
9
|
+
"devDependencies": {
|
|
10
|
+
"@types/jest": "^29.5.14",
|
|
11
|
+
"@types/node": "^22.10.10",
|
|
12
|
+
"eslint": "^9.14.0",
|
|
13
|
+
"jest": "^29.7.0",
|
|
14
|
+
"sqlite3": "^5.1.7",
|
|
15
|
+
"ts-jest": "^29.2.5",
|
|
16
|
+
"typescript": "^5.7.3"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"dev": "tsc --build --watch",
|
|
20
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
21
|
+
"version": "pnpm version",
|
|
22
|
+
"test": "jest",
|
|
23
|
+
"test:watch": "jest --watch"
|
|
24
|
+
}
|
|
25
|
+
}
|