@decaf-ts/transactional-decorators 0.1.5 → 0.2.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 +1 -1
- package/dist/transactional-decorators.cjs +1 -1
- package/dist/transactional-decorators.cjs.map +1 -1
- package/dist/transactional-decorators.js +1 -1
- package/dist/transactional-decorators.js.map +1 -1
- package/lib/Transaction.cjs +254 -56
- package/lib/Transaction.d.ts +44 -18
- package/lib/Transaction.js.map +1 -1
- package/lib/constants.cjs +0 -1
- package/lib/constants.js.map +1 -1
- package/lib/decorators.cjs +60 -146
- package/lib/decorators.d.ts +1 -11
- package/lib/decorators.js.map +1 -1
- package/lib/errors.cjs +11 -0
- package/lib/errors.d.ts +4 -0
- package/lib/errors.js.map +1 -0
- package/lib/esm/Transaction.d.ts +44 -18
- package/lib/esm/Transaction.js +254 -56
- package/lib/esm/Transaction.js.map +1 -1
- package/lib/esm/constants.js +0 -1
- package/lib/esm/constants.js.map +1 -1
- package/lib/esm/decorators.d.ts +1 -11
- package/lib/esm/decorators.js +60 -145
- package/lib/esm/decorators.js.map +1 -1
- package/lib/esm/errors.d.ts +4 -0
- package/lib/esm/errors.js +7 -0
- package/lib/esm/errors.js.map +1 -0
- package/lib/esm/index.d.ts +4 -1
- package/lib/esm/index.js +6 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/interfaces/TransactionLock.d.ts +2 -2
- package/lib/esm/locks/{SyncronousLock.d.ts → SynchronousLock.d.ts} +10 -6
- package/lib/esm/locks/SynchronousLock.js +131 -0
- package/lib/esm/locks/SynchronousLock.js.map +1 -0
- package/lib/esm/locks/index.d.ts +1 -1
- package/lib/esm/locks/index.js +1 -1
- package/lib/esm/locks/index.js.map +1 -1
- package/lib/esm/overrides/Metadata.d.ts +8 -0
- package/lib/esm/overrides/Metadata.js +2 -0
- package/lib/esm/overrides/Metadata.js.map +1 -0
- package/lib/esm/overrides/index.d.ts +2 -0
- package/lib/esm/overrides/index.js +3 -0
- package/lib/esm/overrides/index.js.map +1 -0
- package/lib/esm/overrides/overrides.d.ts +1 -0
- package/lib/esm/overrides/overrides.js +12 -0
- package/lib/esm/overrides/overrides.js.map +1 -0
- package/lib/esm/types.d.ts +0 -10
- package/lib/esm/types.js +11 -0
- package/lib/esm/types.js.map +1 -1
- package/lib/index.cjs +7 -2
- package/lib/index.d.ts +4 -1
- package/lib/index.js.map +1 -1
- package/lib/interfaces/TransactionLock.d.ts +2 -2
- package/lib/locks/SynchronousLock.cjs +135 -0
- package/lib/locks/{SyncronousLock.d.ts → SynchronousLock.d.ts} +10 -6
- package/lib/locks/SynchronousLock.js.map +1 -0
- package/lib/locks/index.cjs +1 -1
- package/lib/locks/index.d.ts +1 -1
- package/lib/locks/index.js.map +1 -1
- package/lib/overrides/Metadata.cjs +4 -0
- package/lib/overrides/Metadata.d.ts +8 -0
- package/lib/overrides/Metadata.js.map +1 -0
- package/lib/overrides/index.cjs +19 -0
- package/lib/overrides/index.d.ts +2 -0
- package/lib/overrides/index.js.map +1 -0
- package/lib/overrides/overrides.cjs +14 -0
- package/lib/overrides/overrides.d.ts +1 -0
- package/lib/overrides/overrides.js.map +1 -0
- package/lib/types.cjs +11 -0
- package/lib/types.d.ts +0 -10
- package/lib/types.js.map +1 -1
- package/package.json +2 -3
- package/lib/esm/locks/SyncronousLock.js +0 -128
- package/lib/esm/locks/SyncronousLock.js.map +0 -1
- package/lib/esm/utils.d.ts +0 -1
- package/lib/esm/utils.js +0 -14
- package/lib/esm/utils.js.map +0 -1
- package/lib/locks/SyncronousLock.cjs +0 -132
- package/lib/locks/SyncronousLock.js.map +0 -1
- package/lib/utils.cjs +0 -17
- package/lib/utils.d.ts +0 -1
- package/lib/utils.js.map +0 -1
package/lib/esm/decorators.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TransactionalKeys } from "./constants.js";
|
|
2
|
-
import {
|
|
2
|
+
import { Metadata, method } from "@decaf-ts/decoration";
|
|
3
3
|
import { Transaction } from "./Transaction.js";
|
|
4
4
|
import { InternalError } from "@decaf-ts/db-decorators";
|
|
5
5
|
/**
|
|
@@ -37,151 +37,66 @@ import { InternalError } from "@decaf-ts/db-decorators";
|
|
|
37
37
|
export function transactional(...data) {
|
|
38
38
|
return function (target, propertyKey, descriptor) {
|
|
39
39
|
if (!descriptor)
|
|
40
|
-
throw new InternalError("
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
45
|
-
const self = this;
|
|
46
|
-
return new Promise((resolve, reject) => {
|
|
47
|
-
const cb = (err, result) => {
|
|
48
|
-
Transaction.release(err).then(() => {
|
|
49
|
-
if (err)
|
|
50
|
-
return reject(err);
|
|
51
|
-
resolve(result);
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
let transaction = args.shift();
|
|
55
|
-
if (transaction instanceof Transaction) {
|
|
56
|
-
const updatedTransaction = new Transaction(this.constructor.name, propertyKey, async () => {
|
|
57
|
-
originalMethod
|
|
58
|
-
.call(updatedTransaction.bindToTransaction(self), ...args)
|
|
59
|
-
.then(resolve)
|
|
60
|
-
.catch(reject);
|
|
61
|
-
}, data.length ? data : undefined);
|
|
62
|
-
transaction.bindTransaction(updatedTransaction);
|
|
63
|
-
transaction.fire();
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
args.unshift(transaction);
|
|
67
|
-
transaction = new Transaction(this.constructor.name, propertyKey, () => {
|
|
68
|
-
originalMethod
|
|
69
|
-
.call(transaction.bindToTransaction(self), ...args)
|
|
70
|
-
.then((result) => cb(undefined, result))
|
|
71
|
-
.catch(cb);
|
|
72
|
-
}, data.length ? data : undefined);
|
|
73
|
-
Transaction.submit(transaction);
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
};
|
|
77
|
-
Object.defineProperty(methodWrapper, "name", {
|
|
78
|
-
value: propertyKey,
|
|
40
|
+
throw new InternalError("This decorator only applies to methods");
|
|
41
|
+
method()(target, propertyKey, descriptor);
|
|
42
|
+
Metadata.set(target.constructor, Metadata.key(TransactionalKeys.TRANSACTIONAL, propertyKey), {
|
|
43
|
+
data: data,
|
|
79
44
|
});
|
|
80
|
-
descriptor.value =
|
|
45
|
+
descriptor.value = new Proxy(descriptor.value, {
|
|
46
|
+
async apply(obj, thisArg, argArray) {
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
async function exitFunction(transaction, err, result) {
|
|
49
|
+
if (err && !(err instanceof Error) && !result) {
|
|
50
|
+
result = err;
|
|
51
|
+
err = undefined;
|
|
52
|
+
}
|
|
53
|
+
await transaction.release(err);
|
|
54
|
+
return err
|
|
55
|
+
? reject(err)
|
|
56
|
+
: resolve(result);
|
|
57
|
+
}
|
|
58
|
+
const candidate = argArray[0];
|
|
59
|
+
const transactionPrefixLength = (() => {
|
|
60
|
+
let count = 0;
|
|
61
|
+
while (count < argArray.length &&
|
|
62
|
+
argArray[count] instanceof Transaction) {
|
|
63
|
+
count++;
|
|
64
|
+
}
|
|
65
|
+
return count;
|
|
66
|
+
})();
|
|
67
|
+
const invocationArgs = transactionPrefixLength > 0
|
|
68
|
+
? argArray.slice(transactionPrefixLength)
|
|
69
|
+
: argArray;
|
|
70
|
+
const activeTransaction = candidate instanceof Transaction
|
|
71
|
+
? candidate
|
|
72
|
+
: Transaction.contextTransaction(thisArg);
|
|
73
|
+
if (activeTransaction) {
|
|
74
|
+
const updatedTransaction = new Transaction(target.name, propertyKey, async () => {
|
|
75
|
+
try {
|
|
76
|
+
return resolve(await Reflect.apply(obj, updatedTransaction.bindToTransaction(thisArg), invocationArgs));
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
return reject(e);
|
|
80
|
+
}
|
|
81
|
+
}, data.length ? data : undefined);
|
|
82
|
+
activeTransaction.bindTransaction(updatedTransaction);
|
|
83
|
+
activeTransaction.fire();
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
const newTransaction = new Transaction(target.name, propertyKey, async () => {
|
|
87
|
+
try {
|
|
88
|
+
return exitFunction(newTransaction, undefined, await Reflect.apply(obj, newTransaction.bindToTransaction(thisArg), invocationArgs));
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
return exitFunction(newTransaction, e);
|
|
92
|
+
}
|
|
93
|
+
}, data.length ? data : undefined);
|
|
94
|
+
Transaction.submit(newTransaction);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
return descriptor;
|
|
81
100
|
};
|
|
82
101
|
}
|
|
83
|
-
//
|
|
84
|
-
// /**
|
|
85
|
-
// * @summary Sets a class Async method as transactional
|
|
86
|
-
// *
|
|
87
|
-
// * @param {any[]} [metadata] option metadata available to the {@link TransactionLock}
|
|
88
|
-
// *
|
|
89
|
-
// * @function transactionalAsync
|
|
90
|
-
// *
|
|
91
|
-
// * @memberOf module:db-decorators.Decorators.transactions
|
|
92
|
-
// */
|
|
93
|
-
// export function transactionalAsync(...metadata: any[]) {
|
|
94
|
-
// return function (
|
|
95
|
-
// target: any,
|
|
96
|
-
// propertyKey: string,
|
|
97
|
-
// descriptor: PropertyDescriptor,
|
|
98
|
-
// ) {
|
|
99
|
-
// metadasta(getTransactionalKey(TransactionalKeys.TRANSACTIONAL))
|
|
100
|
-
// Reflect.defineMetadata(
|
|
101
|
-
// ,
|
|
102
|
-
// {
|
|
103
|
-
// type: "async",
|
|
104
|
-
// metadata: metadata.length ? metadata : undefined,
|
|
105
|
-
// } as TransactionalMetadata,
|
|
106
|
-
// target,
|
|
107
|
-
// propertyKey,
|
|
108
|
-
// );
|
|
109
|
-
//
|
|
110
|
-
// const originalMethod = descriptor.value;
|
|
111
|
-
//
|
|
112
|
-
// const methodWrapper = function (this: any, ...args: any[]) {
|
|
113
|
-
// const callback: Callback = args.pop();
|
|
114
|
-
// if (!callback || typeof callback !== "function")
|
|
115
|
-
// throw new CriticalError(`Missing Callback`);
|
|
116
|
-
//
|
|
117
|
-
// const cb = (err?: Err, ...args: any[]) => {
|
|
118
|
-
// Transaction.release(err).then((_) => callback(err, ...args));
|
|
119
|
-
// };
|
|
120
|
-
//
|
|
121
|
-
// const self = this;
|
|
122
|
-
//
|
|
123
|
-
// let transaction = args.shift();
|
|
124
|
-
// if (transaction instanceof Transaction) {
|
|
125
|
-
// const updatedTransaction: Transaction = new Transaction(
|
|
126
|
-
// this.constructor.name,
|
|
127
|
-
// propertyKey,
|
|
128
|
-
// () => {
|
|
129
|
-
// try {
|
|
130
|
-
// return originalMethod.call(
|
|
131
|
-
// updatedTransaction.bindToTransaction(self),
|
|
132
|
-
// ...args,
|
|
133
|
-
// callback,
|
|
134
|
-
// );
|
|
135
|
-
// } catch (e: any) {
|
|
136
|
-
// return callback(e);
|
|
137
|
-
// }
|
|
138
|
-
// },
|
|
139
|
-
// metadata.length ? metadata : undefined,
|
|
140
|
-
// );
|
|
141
|
-
//
|
|
142
|
-
// transaction.bindTransaction(updatedTransaction);
|
|
143
|
-
// transaction.fire();
|
|
144
|
-
// } else {
|
|
145
|
-
// args.unshift(transaction);
|
|
146
|
-
// transaction = undefined;
|
|
147
|
-
// transaction = new Transaction(
|
|
148
|
-
// this.constructor.name,
|
|
149
|
-
// propertyKey,
|
|
150
|
-
// () => {
|
|
151
|
-
// try {
|
|
152
|
-
// return originalMethod.call(
|
|
153
|
-
// transaction.bindToTransaction(self),
|
|
154
|
-
// ...args,
|
|
155
|
-
// cb,
|
|
156
|
-
// );
|
|
157
|
-
// } catch (e: any) {
|
|
158
|
-
// return cb(e);
|
|
159
|
-
// }
|
|
160
|
-
// },
|
|
161
|
-
// metadata.length ? metadata : undefined,
|
|
162
|
-
// );
|
|
163
|
-
// Transaction.submit(transaction);
|
|
164
|
-
// }
|
|
165
|
-
// };
|
|
166
|
-
//
|
|
167
|
-
// Object.defineProperty(methodWrapper, "name", {
|
|
168
|
-
// value: propertyKey,
|
|
169
|
-
// });
|
|
170
|
-
// descriptor.value = methodWrapper;
|
|
171
|
-
// };
|
|
172
|
-
// }
|
|
173
|
-
/**
|
|
174
|
-
* @description Utility for handling super calls in transactional methods
|
|
175
|
-
* @summary Wraps super method calls with the current transaction context when the super's method is also transactional, ensuring transaction continuity through the inheritance chain
|
|
176
|
-
* @param {Function} method - The super method (must be bound to the proper this), e.g., super.create.bind(this)
|
|
177
|
-
* @param {any[]} args - The arguments to call the method with
|
|
178
|
-
* @return {any} The result of the super method call
|
|
179
|
-
* @function transactionalSuperCall
|
|
180
|
-
* @memberOf module:transactions
|
|
181
|
-
*/
|
|
182
|
-
export function transactionalSuperCall(method, ...args) {
|
|
183
|
-
const lock = Transaction.getLock();
|
|
184
|
-
const currentTransaction = lock.currentTransaction;
|
|
185
|
-
return method(currentTransaction, ...args);
|
|
186
|
-
}
|
|
187
102
|
//# sourceMappingURL=decorators.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../src/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,uBAAoB;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../src/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,uBAAoB;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,yBAAsB;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,UAAU,aAAa,CAAC,GAAG,IAAW;IAC1C,OAAO,UAAU,MAAW,EAAE,WAAiB,EAAE,UAAgB;QAC/D,IAAI,CAAC,UAAU;YACb,MAAM,IAAI,aAAa,CAAC,wCAAwC,CAAC,CAAC;QACpE,MAAM,EAAE,CAAC,MAAM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,CAAC,CAAC,SAAS,CAC/B,CAAC;wBACF,WAAW,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;oBACrC,CAAC;gBACH,CAAC,CAAC,CAAC;YACL,CAAC;SACF,CAAC,CAAC;QAEH,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,MAAM,OAAO,YAAa,SAAQ,aAAa;IAC7C,YAAY,UAA0B,uBAAuB;QAC3D,KAAK,CAAC,OAAO,EAAE,YAAY,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACzC,CAAC;CACF"}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export * from "./interfaces";
|
|
2
2
|
export * from "./locks";
|
|
3
|
+
export * from "./overrides";
|
|
3
4
|
export * from "./constants";
|
|
5
|
+
export * from "./errors";
|
|
4
6
|
export * from "./decorators";
|
|
5
7
|
export * from "./Transaction";
|
|
6
8
|
export * from "./types";
|
|
@@ -15,4 +17,5 @@ export * from "./types";
|
|
|
15
17
|
* @const VERSION
|
|
16
18
|
* @memberOf module:transactions
|
|
17
19
|
*/
|
|
18
|
-
export declare const VERSION = "0.1.
|
|
20
|
+
export declare const VERSION = "0.1.5";
|
|
21
|
+
export declare const PACKAGE_NAME = "@decaf-ts/transactional-decorators";
|
package/lib/esm/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { Metadata } from "@decaf-ts/decoration";
|
|
1
2
|
export * from "./interfaces/index.js";
|
|
2
3
|
export * from "./locks/index.js";
|
|
4
|
+
export * from "./overrides/index.js";
|
|
3
5
|
export * from "./constants.js";
|
|
6
|
+
export * from "./errors.js";
|
|
4
7
|
export * from "./decorators.js";
|
|
5
8
|
export * from "./Transaction.js";
|
|
6
9
|
export * from "./types.js";
|
|
@@ -15,5 +18,7 @@ export * from "./types.js";
|
|
|
15
18
|
* @const VERSION
|
|
16
19
|
* @memberOf module:transactions
|
|
17
20
|
*/
|
|
18
|
-
export const VERSION = "0.1.
|
|
21
|
+
export const VERSION = "0.1.5";
|
|
22
|
+
export const PACKAGE_NAME = "@decaf-ts/transactional-decorators";
|
|
23
|
+
Metadata.registerLibrary(PACKAGE_NAME, VERSION);
|
|
19
24
|
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,sCAA6B;AAC7B,iCAAwB;AACxB,+BAA4B;AAC5B,gCAA6B;AAC7B,iCAA8B;AAC9B,2BAAwB;AAExB;;;;GAIG;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,sCAA6B;AAC7B,iCAAwB;AACxB,qCAA4B;AAC5B,+BAA4B;AAC5B,4BAAyB;AACzB,gCAA6B;AAC7B,iCAA8B;AAC9B,2BAAwB;AAExB;;;;GAIG;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,aAAa,CAAC;AAErC,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAC;AAE1C,QAAQ,CAAC,eAAe,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC"}
|
|
@@ -10,14 +10,14 @@ export interface TransactionLock {
|
|
|
10
10
|
* @description Current active transaction reference
|
|
11
11
|
* @summary Stores a reference to the currently executing transaction, allowing access to the active transaction context
|
|
12
12
|
*/
|
|
13
|
-
currentTransaction?: Transaction
|
|
13
|
+
currentTransaction?: Transaction<any>;
|
|
14
14
|
/**
|
|
15
15
|
* @description Submits a transaction for processing
|
|
16
16
|
* @summary Adds a transaction to the processing queue and handles its execution according to the lock's concurrency rules
|
|
17
17
|
* @param {Transaction} transaction - The transaction to be processed
|
|
18
18
|
* @return {void}
|
|
19
19
|
*/
|
|
20
|
-
submit(transaction: Transaction):
|
|
20
|
+
submit<R>(transaction: Transaction<R>): Promise<R>;
|
|
21
21
|
/**
|
|
22
22
|
* @description Releases the transaction lock
|
|
23
23
|
* @summary Releases the lock after the conclusion of a transaction, allowing the next transaction to proceed, and handles any errors that occurred
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Transaction } from "../Transaction";
|
|
2
2
|
import { TransactionLock } from "../interfaces/TransactionLock";
|
|
3
|
+
import { LoggedClass } from "@decaf-ts/logging";
|
|
3
4
|
/**
|
|
4
5
|
* @summary Simple Synchronous Lock implementation
|
|
5
6
|
* @description for transaction management
|
|
@@ -9,22 +10,25 @@ import { TransactionLock } from "../interfaces/TransactionLock";
|
|
|
9
10
|
* @param {Function} [onBegin] to be called at the start of the transaction
|
|
10
11
|
* @param {Function} [onEnd] to be called at the conclusion of the transaction
|
|
11
12
|
*
|
|
12
|
-
* @class
|
|
13
|
+
* @class SynchronousLock
|
|
13
14
|
* @implements TransactionLock
|
|
14
15
|
*/
|
|
15
|
-
export declare class
|
|
16
|
+
export declare class SynchronousLock extends LoggedClass implements TransactionLock {
|
|
16
17
|
private counter;
|
|
17
|
-
private pendingTransactions;
|
|
18
|
-
currentTransaction?: Transaction;
|
|
19
18
|
private readonly onBegin?;
|
|
20
19
|
private readonly onEnd?;
|
|
20
|
+
private pendingTransactions;
|
|
21
|
+
currentTransaction?: Transaction<any>;
|
|
22
|
+
private readonly loggerCache;
|
|
23
|
+
get log(): any;
|
|
24
|
+
private logger;
|
|
21
25
|
private readonly lock;
|
|
22
|
-
constructor(counter?: number, onBegin?: () => Promise<void
|
|
26
|
+
constructor(counter?: number, onBegin?: (() => Promise<void>) | undefined, onEnd?: ((err?: Error) => Promise<void>) | undefined);
|
|
23
27
|
/**
|
|
24
28
|
* @summary Submits a transaction to be processed
|
|
25
29
|
* @param {Transaction} transaction
|
|
26
30
|
*/
|
|
27
|
-
submit(transaction: Transaction):
|
|
31
|
+
submit<R>(transaction: Transaction<R>): Promise<R>;
|
|
28
32
|
/**
|
|
29
33
|
* @summary Executes a transaction
|
|
30
34
|
*
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { Transaction } from "./../Transaction.js";
|
|
2
|
+
import { Lock } from "./Lock.js";
|
|
3
|
+
import { isBrowser, LoggedClass } from "@decaf-ts/logging";
|
|
4
|
+
/**
|
|
5
|
+
* @summary Simple Synchronous Lock implementation
|
|
6
|
+
* @description for transaction management
|
|
7
|
+
* adapted from {@link https://www.talkinghightech.com/en/creating-a-js-lock-for-a-resource/}
|
|
8
|
+
*
|
|
9
|
+
* @param {number} [counter] the number of simultaneous transactions allowed. defaults to 1
|
|
10
|
+
* @param {Function} [onBegin] to be called at the start of the transaction
|
|
11
|
+
* @param {Function} [onEnd] to be called at the conclusion of the transaction
|
|
12
|
+
*
|
|
13
|
+
* @class SynchronousLock
|
|
14
|
+
* @implements TransactionLock
|
|
15
|
+
*/
|
|
16
|
+
export class SynchronousLock extends LoggedClass {
|
|
17
|
+
get log() {
|
|
18
|
+
if (!this["_log"]) {
|
|
19
|
+
this["_log"] = Transaction["log"].for(this);
|
|
20
|
+
}
|
|
21
|
+
return this["_log"];
|
|
22
|
+
}
|
|
23
|
+
logger(method) {
|
|
24
|
+
if (!this.loggerCache.has(method)) {
|
|
25
|
+
this.loggerCache.set(method, this.log.for(this[method]));
|
|
26
|
+
}
|
|
27
|
+
return this.loggerCache.get(method);
|
|
28
|
+
}
|
|
29
|
+
constructor(counter = 1, onBegin, onEnd) {
|
|
30
|
+
super();
|
|
31
|
+
this.counter = counter;
|
|
32
|
+
this.onBegin = onBegin;
|
|
33
|
+
this.onEnd = onEnd;
|
|
34
|
+
this.pendingTransactions = [];
|
|
35
|
+
this.currentTransaction = undefined;
|
|
36
|
+
this.loggerCache = new Map();
|
|
37
|
+
this.lock = new Lock();
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @summary Submits a transaction to be processed
|
|
41
|
+
* @param {Transaction} transaction
|
|
42
|
+
*/
|
|
43
|
+
async submit(transaction) {
|
|
44
|
+
const log = this.logger("submit");
|
|
45
|
+
await this.lock.acquire();
|
|
46
|
+
log.silly(`Lock acquired to submit transaction ${transaction.id}`);
|
|
47
|
+
if (this.currentTransaction &&
|
|
48
|
+
this.currentTransaction.id === transaction.id) {
|
|
49
|
+
this.lock.release();
|
|
50
|
+
log.silly(`Released lock for re-entrant transaction ${transaction.id}`);
|
|
51
|
+
return transaction.fire();
|
|
52
|
+
}
|
|
53
|
+
let resultPromise;
|
|
54
|
+
if (this.counter > 0) {
|
|
55
|
+
this.counter--;
|
|
56
|
+
this.lock.release();
|
|
57
|
+
log.silly(`Released lock for transaction ${transaction.id}`);
|
|
58
|
+
resultPromise = this.fireTransaction(transaction);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
log.debug(`Pushing transaction ${transaction.id} to the queue`);
|
|
62
|
+
this.pendingTransactions.push(transaction);
|
|
63
|
+
resultPromise = transaction.wait();
|
|
64
|
+
this.lock.release();
|
|
65
|
+
log.silly(`Released lock after queuing transaction ${transaction.id}`);
|
|
66
|
+
}
|
|
67
|
+
return resultPromise;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* @summary Executes a transaction
|
|
71
|
+
*
|
|
72
|
+
* @param {Transaction} transaction
|
|
73
|
+
* @private
|
|
74
|
+
*/
|
|
75
|
+
async fireTransaction(transaction) {
|
|
76
|
+
const log = this.logger("fireTransaction");
|
|
77
|
+
await this.lock.acquire();
|
|
78
|
+
log.silly(`Lock acquired obtain transaction ${transaction.id}`);
|
|
79
|
+
this.currentTransaction = transaction;
|
|
80
|
+
this.lock.release();
|
|
81
|
+
log.silly(`Released lock after obtaining ${transaction.id}`);
|
|
82
|
+
if (this.onBegin) {
|
|
83
|
+
log.verbose(`Calling onBegin for transaction ${transaction.id}`);
|
|
84
|
+
await this.onBegin();
|
|
85
|
+
}
|
|
86
|
+
log.info(`Starting transaction ${transaction.id}. ${this.pendingTransactions.length} remaining...`);
|
|
87
|
+
return transaction.fire();
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* @summary Releases The lock after the conclusion of a transaction
|
|
91
|
+
*/
|
|
92
|
+
async release(err) {
|
|
93
|
+
const log = this.logger("release");
|
|
94
|
+
await this.lock.acquire();
|
|
95
|
+
if (!this.currentTransaction)
|
|
96
|
+
log.warn("Trying to release an unexisting transaction. should never happen...");
|
|
97
|
+
log.verbose(`Releasing transaction ${this.currentTransaction?.toString(true, true)}`);
|
|
98
|
+
const id = this.currentTransaction?.id;
|
|
99
|
+
this.currentTransaction = undefined;
|
|
100
|
+
this.lock.release();
|
|
101
|
+
log.silly(`Released lock after clearing transaction ${id}`);
|
|
102
|
+
if (this.onEnd) {
|
|
103
|
+
log.verbose(`Calling onEnd for transaction ${id}`);
|
|
104
|
+
await this.onEnd(err);
|
|
105
|
+
}
|
|
106
|
+
await this.lock.acquire();
|
|
107
|
+
log.silly(`Acquired lock after completing transaction ${id} for pending transaction verification`);
|
|
108
|
+
if (this.pendingTransactions.length > 0) {
|
|
109
|
+
const transaction = this.pendingTransactions.shift();
|
|
110
|
+
const cb = () => {
|
|
111
|
+
return this.fireTransaction.call(this, transaction).catch((err) => {
|
|
112
|
+
this.log.for(this.fireTransaction).error(err);
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
log.silly(`Marking ${transaction.id} for execution`);
|
|
116
|
+
if (!isBrowser()) {
|
|
117
|
+
globalThis.process.nextTick(cb); // if you are on node
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
setTimeout(cb, 0);
|
|
121
|
+
} // if you are in the browser
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
log.debug(`No pending transactions. Incrementing counter.`);
|
|
125
|
+
this.counter++;
|
|
126
|
+
}
|
|
127
|
+
this.lock.release();
|
|
128
|
+
log.silly(`Released lock after completing transaction ${id}`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=SynchronousLock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SynchronousLock.js","sourceRoot":"","sources":["../../../src/locks/SynchronousLock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,4BAAuB;AAE7C,OAAO,EAAE,IAAI,EAAE,kBAAe;AAC9B,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE3D;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,eAAgB,SAAQ,WAAW;IAK9C,IAAa,GAAG;QACd,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;YAClB,IAAI,CAAC,MAAM,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC9C,CAAC;QACD,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;IACtB,CAAC;IAEO,MAAM,CAAC,MAAgD;QAC7D,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YAClC,IAAI,CAAC,WAAW,CAAC,GAAG,CAClB,MAAM,EACN,IAAI,CAAC,GAAG,CAAC,GAAG,CAAE,IAAuC,CAAC,MAAM,CAAC,CAAC,CAC/D,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,CAAoC,CAAC;IACzE,CAAC;IAID,YACU,UAAkB,CAAC,EACV,OAA6B,EAC7B,KAAsC;QAEvD,KAAK,EAAE,CAAC;QAJA,YAAO,GAAP,OAAO,CAAY;QACV,YAAO,GAAP,OAAO,CAAsB;QAC7B,UAAK,GAAL,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U,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;YACpB,CAAC,CAAC,4BAA4B;QAChC,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,KAAK,CAAC,gDAAgD,CAAC,CAAC;YAC5D,IAAI,CAAC,OAAO,EAAE,CAAC;QACjB,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QACpB,GAAG,CAAC,KAAK,CAAC,8CAA8C,EAAE,EAAE,CAAC,CAAC;IAChE,CAAC;CACF"}
|
package/lib/esm/locks/index.d.ts
CHANGED
package/lib/esm/locks/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/locks/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,0BAAuB;AACvB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/locks/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,0BAAuB;AACvB,qCAAkC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import "@decaf-ts/decoration";
|
|
2
|
+
import { Constructor } from "@decaf-ts/decorator-validation";
|
|
3
|
+
declare module "@decaf-ts/decoration" {
|
|
4
|
+
namespace Metadata {
|
|
5
|
+
function transactionals<T>(obj: Constructor<T>): (keyof T)[];
|
|
6
|
+
function isTransactional<T>(obj: Constructor<T>): boolean;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Metadata.js","sourceRoot":"","sources":["../../../src/overrides/Metadata.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/overrides/index.ts"],"names":[],"mappings":"AAAA,8BAA2B;AAC3B,+BAA4B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Metadata } from "@decaf-ts/decoration";
|
|
2
|
+
import { TransactionalKeys } from "./../constants.js";
|
|
3
|
+
Metadata.transactionals = function (obj) {
|
|
4
|
+
const meta = Metadata.get(obj, TransactionalKeys.TRANSACTIONAL);
|
|
5
|
+
if (!meta)
|
|
6
|
+
return [];
|
|
7
|
+
return Object.keys(meta);
|
|
8
|
+
};
|
|
9
|
+
Metadata.isTransactional = function (obj) {
|
|
10
|
+
return !!Metadata.get(obj, TransactionalKeys.TRANSACTIONAL);
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=overrides.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overrides.js","sourceRoot":"","sources":["../../../src/overrides/overrides.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,0BAAqB;AAGhD,QAAgB,CAAC,cAAc,GAAG,UACjC,GAAmB;IAEnB,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,iBAAiB,CAAC,aAAa,CAAC,CAAC;IAChE,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAC;IACrB,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAgB,CAAC;AAC1C,CAAC,CAAC;AAED,QAAgB,CAAC,eAAe,GAAG,UAAa,GAAmB;IAClE,OAAO,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,iBAAiB,CAAC,aAAa,CAAC,CAAC;AAC9D,CAAC,CAAC"}
|
package/lib/esm/types.d.ts
CHANGED
|
@@ -5,13 +5,3 @@
|
|
|
5
5
|
* @memberOf module:transactions
|
|
6
6
|
*/
|
|
7
7
|
export type LockCallable = (value?: void | PromiseLike<void>) => void;
|
|
8
|
-
/**
|
|
9
|
-
* @description Standard callback function type for asynchronous operations
|
|
10
|
-
* @summary Defines a Node.js-style callback function that receives an optional error as the first parameter and optional result and additional arguments
|
|
11
|
-
* @typedef {Function} Callback
|
|
12
|
-
* @param {Error} [err] - Optional error object if the operation failed
|
|
13
|
-
* @param {any} [result] - Optional result of the operation if successful
|
|
14
|
-
* @param {...any} [args] - Additional arguments that may be passed to the callback
|
|
15
|
-
* @memberOf module:transactions
|
|
16
|
-
*/
|
|
17
|
-
export type Callback = (err?: Error, result?: any, ...args: any[]) => void;
|
package/lib/esm/types.js
CHANGED
|
@@ -1,2 +1,13 @@
|
|
|
1
1
|
export {};
|
|
2
|
+
//
|
|
3
|
+
// /**
|
|
4
|
+
// * @description Standard callback function type for asynchronous operations
|
|
5
|
+
// * @summary Defines a Node.js-style callback function that receives an optional error as the first parameter and optional result and additional arguments
|
|
6
|
+
// * @typedef {Function} Callback
|
|
7
|
+
// * @param {Error} [err] - Optional error object if the operation failed
|
|
8
|
+
// * @param {any} [result] - Optional result of the operation if successful
|
|
9
|
+
// * @param {...any} [args] - Additional arguments that may be passed to the callback
|
|
10
|
+
// * @memberOf module:transactions
|
|
11
|
+
// */
|
|
12
|
+
// export type Callback = (err?: Error, result?: any, ...args: any[]) => void;
|
|
2
13
|
//# sourceMappingURL=types.js.map
|
package/lib/esm/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";AAOA,EAAE;AACF,MAAM;AACN,8EAA8E;AAC9E,4JAA4J;AAC5J,kCAAkC;AAClC,0EAA0E;AAC1E,4EAA4E;AAC5E,sFAAsF;AACtF,mCAAmC;AACnC,MAAM;AACN,8EAA8E"}
|
package/lib/index.cjs
CHANGED
|
@@ -14,10 +14,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.VERSION = void 0;
|
|
17
|
+
exports.PACKAGE_NAME = exports.VERSION = void 0;
|
|
18
|
+
const decoration_1 = require("@decaf-ts/decoration");
|
|
18
19
|
__exportStar(require("./interfaces/index.cjs"), exports);
|
|
19
20
|
__exportStar(require("./locks/index.cjs"), exports);
|
|
21
|
+
__exportStar(require("./overrides/index.cjs"), exports);
|
|
20
22
|
__exportStar(require("./constants.cjs"), exports);
|
|
23
|
+
__exportStar(require("./errors.cjs"), exports);
|
|
21
24
|
__exportStar(require("./decorators.cjs"), exports);
|
|
22
25
|
__exportStar(require("./Transaction.cjs"), exports);
|
|
23
26
|
__exportStar(require("./types.cjs"), exports);
|
|
@@ -32,5 +35,7 @@ __exportStar(require("./types.cjs"), exports);
|
|
|
32
35
|
* @const VERSION
|
|
33
36
|
* @memberOf module:transactions
|
|
34
37
|
*/
|
|
35
|
-
exports.VERSION = "0.1.
|
|
38
|
+
exports.VERSION = "0.1.5";
|
|
39
|
+
exports.PACKAGE_NAME = "@decaf-ts/transactional-decorators";
|
|
40
|
+
decoration_1.Metadata.registerLibrary(exports.PACKAGE_NAME, exports.VERSION);
|
|
36
41
|
//# sourceMappingURL=index.js.map
|