@decaf-ts/transactional-decorators 0.1.4 → 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.
Files changed (82) hide show
  1. package/README.md +1 -1
  2. package/dist/transactional-decorators.cjs +1 -1
  3. package/dist/transactional-decorators.cjs.map +1 -1
  4. package/dist/transactional-decorators.js +1 -1
  5. package/dist/transactional-decorators.js.map +1 -1
  6. package/lib/Transaction.cjs +254 -56
  7. package/lib/Transaction.d.ts +44 -18
  8. package/lib/Transaction.js.map +1 -1
  9. package/lib/constants.cjs +0 -1
  10. package/lib/constants.js.map +1 -1
  11. package/lib/decorators.cjs +60 -146
  12. package/lib/decorators.d.ts +1 -11
  13. package/lib/decorators.js.map +1 -1
  14. package/lib/errors.cjs +11 -0
  15. package/lib/errors.d.ts +4 -0
  16. package/lib/errors.js.map +1 -0
  17. package/lib/esm/Transaction.d.ts +44 -18
  18. package/lib/esm/Transaction.js +254 -56
  19. package/lib/esm/Transaction.js.map +1 -1
  20. package/lib/esm/constants.js +0 -1
  21. package/lib/esm/constants.js.map +1 -1
  22. package/lib/esm/decorators.d.ts +1 -11
  23. package/lib/esm/decorators.js +60 -145
  24. package/lib/esm/decorators.js.map +1 -1
  25. package/lib/esm/errors.d.ts +4 -0
  26. package/lib/esm/errors.js +7 -0
  27. package/lib/esm/errors.js.map +1 -0
  28. package/lib/esm/index.d.ts +4 -1
  29. package/lib/esm/index.js +6 -1
  30. package/lib/esm/index.js.map +1 -1
  31. package/lib/esm/interfaces/TransactionLock.d.ts +2 -2
  32. package/lib/esm/locks/{SyncronousLock.d.ts → SynchronousLock.d.ts} +10 -6
  33. package/lib/esm/locks/SynchronousLock.js +131 -0
  34. package/lib/esm/locks/SynchronousLock.js.map +1 -0
  35. package/lib/esm/locks/index.d.ts +1 -1
  36. package/lib/esm/locks/index.js +1 -1
  37. package/lib/esm/locks/index.js.map +1 -1
  38. package/lib/esm/overrides/Metadata.d.ts +8 -0
  39. package/lib/esm/overrides/Metadata.js +2 -0
  40. package/lib/esm/overrides/Metadata.js.map +1 -0
  41. package/lib/esm/overrides/index.d.ts +2 -0
  42. package/lib/esm/overrides/index.js +3 -0
  43. package/lib/esm/overrides/index.js.map +1 -0
  44. package/lib/esm/overrides/overrides.d.ts +1 -0
  45. package/lib/esm/overrides/overrides.js +12 -0
  46. package/lib/esm/overrides/overrides.js.map +1 -0
  47. package/lib/esm/types.d.ts +0 -10
  48. package/lib/esm/types.js +11 -0
  49. package/lib/esm/types.js.map +1 -1
  50. package/lib/index.cjs +7 -2
  51. package/lib/index.d.ts +4 -1
  52. package/lib/index.js.map +1 -1
  53. package/lib/interfaces/TransactionLock.d.ts +2 -2
  54. package/lib/locks/SynchronousLock.cjs +135 -0
  55. package/lib/locks/{SyncronousLock.d.ts → SynchronousLock.d.ts} +10 -6
  56. package/lib/locks/SynchronousLock.js.map +1 -0
  57. package/lib/locks/index.cjs +1 -1
  58. package/lib/locks/index.d.ts +1 -1
  59. package/lib/locks/index.js.map +1 -1
  60. package/lib/overrides/Metadata.cjs +4 -0
  61. package/lib/overrides/Metadata.d.ts +8 -0
  62. package/lib/overrides/Metadata.js.map +1 -0
  63. package/lib/overrides/index.cjs +19 -0
  64. package/lib/overrides/index.d.ts +2 -0
  65. package/lib/overrides/index.js.map +1 -0
  66. package/lib/overrides/overrides.cjs +14 -0
  67. package/lib/overrides/overrides.d.ts +1 -0
  68. package/lib/overrides/overrides.js.map +1 -0
  69. package/lib/types.cjs +11 -0
  70. package/lib/types.d.ts +0 -10
  71. package/lib/types.js.map +1 -1
  72. package/package.json +7 -32
  73. package/lib/esm/locks/SyncronousLock.js +0 -128
  74. package/lib/esm/locks/SyncronousLock.js.map +0 -1
  75. package/lib/esm/utils.d.ts +0 -1
  76. package/lib/esm/utils.js +0 -14
  77. package/lib/esm/utils.js.map +0 -1
  78. package/lib/locks/SyncronousLock.cjs +0 -132
  79. package/lib/locks/SyncronousLock.js.map +0 -1
  80. package/lib/utils.cjs +0 -17
  81. package/lib/utils.d.ts +0 -1
  82. package/lib/utils.js.map +0 -1
@@ -1,132 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SyncronousLock = void 0;
4
- const Lock_1 = require("./Lock.cjs");
5
- /**
6
- * @summary Simple Synchronous Lock implementation
7
- * @description for transaction management
8
- * adapted from {@link https://www.talkinghightech.com/en/creating-a-js-lock-for-a-resource/}
9
- *
10
- * @param {number} [counter] the number of simultaneous transactions allowed. defaults to 1
11
- * @param {Function} [onBegin] to be called at the start of the transaction
12
- * @param {Function} [onEnd] to be called at the conclusion of the transaction
13
- *
14
- * @class SyncronousLock
15
- * @implements TransactionLock
16
- */
17
- class SyncronousLock {
18
- constructor(counter = 1, onBegin, onEnd) {
19
- this.currentTransaction = undefined;
20
- this.lock = new Lock_1.Lock();
21
- this.counter = counter;
22
- this.pendingTransactions = [];
23
- this.onBegin = onBegin;
24
- this.onEnd = onEnd;
25
- }
26
- /**
27
- * @summary Submits a transaction to be processed
28
- * @param {Transaction} transaction
29
- */
30
- submit(transaction) {
31
- // eslint-disable-next-line @typescript-eslint/no-this-alias
32
- const self = this;
33
- self.lock.acquire().then(() => {
34
- if (self.currentTransaction &&
35
- self.currentTransaction.id === transaction.id) {
36
- self.lock.release();
37
- return transaction.fire();
38
- }
39
- if (self.counter > 0) {
40
- self.counter--;
41
- self.lock.release();
42
- return self.fireTransaction(transaction);
43
- }
44
- else {
45
- self.pendingTransactions.push(transaction);
46
- self.lock.release();
47
- }
48
- });
49
- }
50
- /**
51
- * @summary Executes a transaction
52
- *
53
- * @param {Transaction} transaction
54
- * @private
55
- */
56
- fireTransaction(transaction) {
57
- // eslint-disable-next-line @typescript-eslint/no-this-alias
58
- const self = this;
59
- self.lock.acquire().then(() => {
60
- self.currentTransaction = transaction;
61
- self.lock.release();
62
- if (self.onBegin)
63
- self.onBegin().then(() => {
64
- // all.call(
65
- // self,
66
- // `Firing transaction {0}. {1} remaining...`,
67
- // transaction.id,
68
- // this.pendingTransactions.length,
69
- // );
70
- transaction.fire();
71
- });
72
- else {
73
- // all.call(
74
- // self,
75
- // `Firing transaction {0}. {1} remaining...`,
76
- // transaction.id,
77
- // this.pendingTransactions.length,
78
- // );
79
- transaction.fire();
80
- }
81
- });
82
- }
83
- /**
84
- * @summary Releases The lock after the conclusion of a transaction
85
- */
86
- async release(err) {
87
- // eslint-disable-next-line @typescript-eslint/no-this-alias
88
- const self = this;
89
- return new Promise((resolve) => {
90
- self.lock.acquire().then(() => {
91
- if (!self.currentTransaction)
92
- console.warn("Trying to release an unexisting transaction. should never happen...");
93
- // debug.call(
94
- // self,
95
- // "Releasing transaction: {0}",
96
- // self.currentTransaction?.toString(true, true),
97
- // );
98
- self.currentTransaction = undefined;
99
- self.lock.release();
100
- const afterConclusionCB = () => {
101
- self.lock.acquire().then(() => {
102
- if (self.pendingTransactions.length > 0) {
103
- const transaction = self.pendingTransactions.shift();
104
- const cb = () => self.fireTransaction(transaction);
105
- //
106
- // all(
107
- // `Releasing Transaction Lock on transaction {0}`,
108
- // transaction.id,
109
- // );
110
- if (typeof globalThis.window ===
111
- "undefined")
112
- globalThis.process.nextTick(cb); // if you are on node
113
- else
114
- setTimeout(cb, 0); // if you are in the browser
115
- }
116
- else {
117
- self.counter++;
118
- }
119
- self.lock.release();
120
- resolve();
121
- });
122
- };
123
- if (self.onEnd)
124
- self.onEnd(err).then(() => afterConclusionCB());
125
- else
126
- afterConclusionCB();
127
- });
128
- });
129
- }
130
- }
131
- exports.SyncronousLock = SyncronousLock;
132
- //# sourceMappingURL=SyncronousLock.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SyncronousLock.js","sourceRoot":"","sources":["../../src/locks/SyncronousLock.ts"],"names":[],"mappings":";;;AAEA,qCAA8B;AAE9B;;;;;;;;;;;GAWG;AACH,MAAa,cAAc;IASzB,YACE,UAAkB,CAAC,EACnB,OAA6B,EAC7B,KAAsC;QATxC,uBAAkB,GAAiB,SAA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,CAAC,WAAW,CAAC,CAAC;4BACnD,EAAE;4BACF,OAAO;4BACP,qDAAqD;4BACrD,oBAAoB;4BACpB,KAAK;4BAEL,IACE,OAAQ,UAAyC,CAAC,MAAM;gCACxD,WAAW;gCAEX,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,qBAAqB;;gCACnD,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,4BAA4B;wBACtD,CAAC;6BAAM,CAAC;4BACN,IAAI,CAAC,OAAO,EAAE,CAAC;wBACjB,CAAC;wBACD,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;wBACpB,OAAO,EAAE,CAAC;oBACZ,CAAC,CAAC,CAAC;gBACL,CAAC,CAAC;gBAEF,IAAI,IAAI,CAAC,KAAK;oBAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,iBAAiB,EAAE,CAAC,CAAC;;oBAC3D,iBAAiB,EAAE,CAAC;YAC3B,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AApID,wCAoIC"}
package/lib/utils.cjs DELETED
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getObjectName = getObjectName;
4
- function getObjectName(obj) {
5
- if (!obj)
6
- return;
7
- if (typeof obj === "string")
8
- return obj;
9
- if (obj.constructor &&
10
- obj.constructor.name &&
11
- ["Function", "Object"].indexOf(obj.constructor.name) === -1)
12
- return obj.constructor.name;
13
- if (typeof obj === "function" && obj.name)
14
- return obj.name;
15
- return obj.toString();
16
- }
17
- //# sourceMappingURL=utils.js.map
package/lib/utils.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare function getObjectName(obj: any): string | undefined;
package/lib/utils.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;AAAA,sCAWC;AAXD,SAAgB,aAAa,CAAC,GAAQ;IACpC,IAAI,CAAC,GAAG;QAAE,OAAO;IACjB,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,GAAG,CAAC;IACxC,IACE,GAAG,CAAC,WAAW;QACf,GAAG,CAAC,WAAW,CAAC,IAAI;QACpB,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAE3D,OAAO,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC;IAC9B,IAAI,OAAO,GAAG,KAAK,UAAU,IAAI,GAAG,CAAC,IAAI;QAAE,OAAO,GAAG,CAAC,IAAI,CAAC;IAC3D,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;AACxB,CAAC"}