@decaf-ts/transactional-decorators 0.0.4

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 (51) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +297 -0
  3. package/dist/esm/transactional-decorators.bundle.min.esm.js +2 -0
  4. package/dist/esm/transactional-decorators.bundle.min.esm.js.LICENSE.txt +14 -0
  5. package/dist/transactional-decorators.bundle.min.js +2 -0
  6. package/dist/transactional-decorators.bundle.min.js.LICENSE.txt +14 -0
  7. package/lib/Transaction.cjs +3 -0
  8. package/lib/Transaction.d.ts +79 -0
  9. package/lib/constants.cjs +1 -0
  10. package/lib/constants.d.ts +1 -0
  11. package/lib/decorators.cjs +1 -0
  12. package/lib/decorators.d.ts +26 -0
  13. package/lib/esm/Transaction.d.ts +79 -0
  14. package/lib/esm/Transaction.js +3 -0
  15. package/lib/esm/constants.d.ts +1 -0
  16. package/lib/esm/constants.js +1 -0
  17. package/lib/esm/decorators.d.ts +26 -0
  18. package/lib/esm/decorators.js +1 -0
  19. package/lib/esm/index.d.ts +24 -0
  20. package/lib/esm/index.js +1 -0
  21. package/lib/esm/interfaces/TransactionLock.d.ts +26 -0
  22. package/lib/esm/interfaces/TransactionLock.js +0 -0
  23. package/lib/esm/interfaces/index.d.ts +1 -0
  24. package/lib/esm/interfaces/index.js +1 -0
  25. package/lib/esm/locks/Lock.d.ts +24 -0
  26. package/lib/esm/locks/Lock.js +1 -0
  27. package/lib/esm/locks/SyncronousLock.d.ts +40 -0
  28. package/lib/esm/locks/SyncronousLock.js +1 -0
  29. package/lib/esm/locks/index.d.ts +2 -0
  30. package/lib/esm/locks/index.js +1 -0
  31. package/lib/esm/types.d.ts +7 -0
  32. package/lib/esm/types.js +0 -0
  33. package/lib/esm/utils.d.ts +1 -0
  34. package/lib/esm/utils.js +1 -0
  35. package/lib/index.cjs +1 -0
  36. package/lib/index.d.ts +24 -0
  37. package/lib/interfaces/TransactionLock.cjs +1 -0
  38. package/lib/interfaces/TransactionLock.d.ts +26 -0
  39. package/lib/interfaces/index.cjs +1 -0
  40. package/lib/interfaces/index.d.ts +1 -0
  41. package/lib/locks/Lock.cjs +1 -0
  42. package/lib/locks/Lock.d.ts +24 -0
  43. package/lib/locks/SyncronousLock.cjs +1 -0
  44. package/lib/locks/SyncronousLock.d.ts +40 -0
  45. package/lib/locks/index.cjs +1 -0
  46. package/lib/locks/index.d.ts +2 -0
  47. package/lib/types.cjs +1 -0
  48. package/lib/types.d.ts +7 -0
  49. package/lib/utils.cjs +1 -0
  50. package/lib/utils.d.ts +1 -0
  51. package/package.json +107 -0
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @summary Simple Synchronous Lock implementation
3
+ * @description for transaction management
4
+ * adapted from {@link https://www.talkinghightech.com/en/creating-a-js-lock-for-a-resource/}
5
+ *
6
+ * @param {number} [counter] the number of simultaneous transactions allowed. defaults to 1
7
+ * @param {Function} [onBegin] to be called at the start of the transaction
8
+ * @param {Function} [onEnd] to be called at the conclusion of the transaction
9
+ *
10
+ * @class SyncronousLock
11
+ * @implements TransactionLock
12
+ *
13
+ * @category Transactions
14
+ */ import { Transaction } from "../Transaction";
15
+ import { TransactionLock } from "../interfaces/TransactionLock";
16
+ export declare class SyncronousLock implements TransactionLock {
17
+ private counter;
18
+ private pendingTransactions;
19
+ currentTransaction?: Transaction;
20
+ private readonly onBegin?;
21
+ private readonly onEnd?;
22
+ private readonly lock;
23
+ constructor(counter?: number, onBegin?: () => Promise<void>, onEnd?: (err?: Error) => Promise<void>);
24
+ /**
25
+ * @summary Submits a transaction to be processed
26
+ * @param {Transaction} transaction
27
+ */
28
+ submit(transaction: Transaction): void;
29
+ /**
30
+ * @summary Executes a transaction
31
+ *
32
+ * @param {Transaction} transaction
33
+ * @private
34
+ */
35
+ private fireTransaction;
36
+ /**
37
+ * @summary Releases The lock after the conclusion of a transaction
38
+ */
39
+ release(err?: Error): Promise<void>;
40
+ }
@@ -0,0 +1 @@
1
+ import{Lock}from"./Lock";class SyncronousLock{constructor(n=1,e,o){this.currentTransaction=void 0,this.lock=new Lock,this.counter=n,this.pendingTransactions=[],this.onBegin=e,this.onEnd=o}submit(n){let e=this;e.lock.acquire().then(()=>e.currentTransaction&&e.currentTransaction.id===n.id?(e.lock.release(),n.fire()):0<e.counter?(e.counter--,e.lock.release(),e.fireTransaction(n)):(e.pendingTransactions.push(n),void e.lock.release()))}fireTransaction(n){let e=this;e.lock.acquire().then(()=>{e.currentTransaction=n,e.lock.release(),e.onBegin?e.onBegin().then(()=>{n.fire()}):n.fire()})}async release(e){let r=this;return new Promise(o=>{r.lock.acquire().then(()=>{r.currentTransaction||console.warn("Trying to release an unexisting transaction. should never happen..."),r.currentTransaction=void 0,r.lock.release();let n=()=>{r.lock.acquire().then(()=>{if(0<r.pendingTransactions.length){let n=r.pendingTransactions.shift();var e=()=>r.fireTransaction(n);void 0===globalThis.window?globalThis.process.nextTick(e):setTimeout(e,0)}else r.counter++;r.lock.release(),o()})};r.onEnd?r.onEnd(e).then(()=>n()):n()})})}}export{SyncronousLock};
@@ -0,0 +1,2 @@
1
+ export * from "./Lock";
2
+ export * from "./SyncronousLock";
@@ -0,0 +1 @@
1
+ export*from"./Lock";export*from"./SyncronousLock";
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @summary defines a callable as perceived by the lock
3
+ *
4
+ * @memberOf module:db-decorators.Transactions
5
+ */
6
+ export type LockCallable = (value?: void | PromiseLike<void>) => void;
7
+ export type Callback = (err?: Error, result?: any, ...args: any[]) => void;
File without changes
@@ -0,0 +1 @@
1
+ export declare function getObjectName(obj: any): string | undefined;
@@ -0,0 +1 @@
1
+ function getObjectName(t){if(t)return"string"==typeof t?t:t.constructor&&t.constructor.name&&-1===["Function","Object"].indexOf(t.constructor.name)?t.constructor.name:"function"==typeof t&&t.name?t.name:t.toString()}export{getObjectName};
package/lib/index.cjs ADDED
@@ -0,0 +1 @@
1
+ var __createBinding=this&&this.__createBinding||(Object.create?function(e,r,t,o){void 0===o&&(o=t);var i=Object.getOwnPropertyDescriptor(r,t);i&&("get"in i?r.__esModule:!i.writable&&!i.configurable)||(i={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,o,i)}:function(e,r,t,o){e[o=void 0===o?t:o]=r[t]}),__exportStar=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||__createBinding(r,e,t)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.VERSION=void 0,__exportStar(require("./interfaces/index.cjs"),exports),__exportStar(require("./locks/index.cjs"),exports),__exportStar(require("./constants.cjs"),exports),__exportStar(require("./decorators.cjs"),exports),__exportStar(require("./Transaction.cjs"),exports),__exportStar(require("./types.cjs"),exports),exports.VERSION="0.0.3";
package/lib/index.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ export * from "./interfaces";
2
+ export * from "./locks";
3
+ export * from "./constants";
4
+ export * from "./decorators";
5
+ export * from "./Transaction";
6
+ export * from "./types";
7
+ /**
8
+ * @summary Module summary
9
+ * @description Module description
10
+ * @module ts-workspace
11
+ */
12
+ /**
13
+ * @summary Namespace summary
14
+ * @description Namespace description
15
+ * @namespace Namespace
16
+ * @memberOf module:ts-workspace
17
+ */
18
+ /**
19
+ * @summary stores the current package version
20
+ * @description this is how you should document a constant
21
+ * @const VERSION
22
+ * @memberOf module:ts-workspace
23
+ */
24
+ export declare const VERSION = "0.0.3";
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,"__esModule",{value:!0});
@@ -0,0 +1,26 @@
1
+ import { Transaction } from "../Transaction";
2
+ /**
3
+ * @summary Transaction lock interface
4
+ * @interface TransactionLock
5
+ *
6
+ * @category Transactions
7
+ */
8
+ export interface TransactionLock {
9
+ /**
10
+ * @summary stores the current transactions
11
+ * @property currentTransaction
12
+ */
13
+ currentTransaction?: Transaction;
14
+ /**
15
+ * @summary Submits a transaction to be processed
16
+ * @param {Transaction} transaction
17
+ * @method
18
+ */
19
+ submit(transaction: Transaction): void;
20
+ /**
21
+ * @summary Releases The lock after the conclusion of a transaction
22
+ * @param {Err} [err] the error (if any) that caused the release
23
+ * @method
24
+ */
25
+ release(err?: Error): Promise<void>;
26
+ }
@@ -0,0 +1 @@
1
+ var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&("get"in n?t.__esModule:!n.writable&&!n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,n)}:function(e,t,r,i){e[i=void 0===i?r:i]=t[r]}),__exportStar=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||__createBinding(t,e,r)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./TransactionLock.cjs"),exports);
@@ -0,0 +1 @@
1
+ export * from "./TransactionLock";
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,"__esModule",{value:!0}),exports.Lock=void 0;class Lock{constructor(){this.queue=[],this.locked=!1}async execute(e){await this.acquire();let s;try{s=await Promise.resolve(e())}catch(e){throw this.release(),e}return this.release(),s}async acquire(){let s=this;return s.locked?new Promise(e=>s.queue.push(e)):(s.locked=!0,Promise.resolve())}release(){var e=this.queue.shift();e?void 0===globalThis.window?globalThis.process.nextTick(e):setTimeout(e,0):this.locked=!1}}exports.Lock=Lock;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @summary Simple Promise based Lock class
3
+ *
4
+ * @class Lock
5
+ * @category Transactions
6
+ */
7
+ export declare class Lock {
8
+ private queue;
9
+ private locked;
10
+ /**
11
+ * @summary executes when lock is available
12
+ * @param {Function} func
13
+ */
14
+ execute(func: () => any): Promise<any>;
15
+ /**
16
+ * @summary waits to acquire the lock
17
+ * @param {string} [issuer]
18
+ */
19
+ acquire(): Promise<void>;
20
+ /**
21
+ * @summary releases the lock
22
+ */
23
+ release(): void;
24
+ }
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,"__esModule",{value:!0}),exports.SyncronousLock=void 0;let Lock_1=require("./Lock.cjs");class SyncronousLock{constructor(e=1,n,o){this.currentTransaction=void 0,this.lock=new Lock_1.Lock,this.counter=e,this.pendingTransactions=[],this.onBegin=n,this.onEnd=o}submit(e){let n=this;n.lock.acquire().then(()=>n.currentTransaction&&n.currentTransaction.id===e.id?(n.lock.release(),e.fire()):0<n.counter?(n.counter--,n.lock.release(),n.fireTransaction(e)):(n.pendingTransactions.push(e),void n.lock.release()))}fireTransaction(e){let n=this;n.lock.acquire().then(()=>{n.currentTransaction=e,n.lock.release(),n.onBegin?n.onBegin().then(()=>{e.fire()}):e.fire()})}async release(n){let r=this;return new Promise(o=>{r.lock.acquire().then(()=>{r.currentTransaction||console.warn("Trying to release an unexisting transaction. should never happen..."),r.currentTransaction=void 0,r.lock.release();let e=()=>{r.lock.acquire().then(()=>{if(0<r.pendingTransactions.length){let e=r.pendingTransactions.shift();var n=()=>r.fireTransaction(e);void 0===globalThis.window?globalThis.process.nextTick(n):setTimeout(n,0)}else r.counter++;r.lock.release(),o()})};r.onEnd?r.onEnd(n).then(()=>e()):e()})})}}exports.SyncronousLock=SyncronousLock;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @summary Simple Synchronous Lock implementation
3
+ * @description for transaction management
4
+ * adapted from {@link https://www.talkinghightech.com/en/creating-a-js-lock-for-a-resource/}
5
+ *
6
+ * @param {number} [counter] the number of simultaneous transactions allowed. defaults to 1
7
+ * @param {Function} [onBegin] to be called at the start of the transaction
8
+ * @param {Function} [onEnd] to be called at the conclusion of the transaction
9
+ *
10
+ * @class SyncronousLock
11
+ * @implements TransactionLock
12
+ *
13
+ * @category Transactions
14
+ */ import { Transaction } from "../Transaction";
15
+ import { TransactionLock } from "../interfaces/TransactionLock";
16
+ export declare class SyncronousLock implements TransactionLock {
17
+ private counter;
18
+ private pendingTransactions;
19
+ currentTransaction?: Transaction;
20
+ private readonly onBegin?;
21
+ private readonly onEnd?;
22
+ private readonly lock;
23
+ constructor(counter?: number, onBegin?: () => Promise<void>, onEnd?: (err?: Error) => Promise<void>);
24
+ /**
25
+ * @summary Submits a transaction to be processed
26
+ * @param {Transaction} transaction
27
+ */
28
+ submit(transaction: Transaction): void;
29
+ /**
30
+ * @summary Executes a transaction
31
+ *
32
+ * @param {Transaction} transaction
33
+ * @private
34
+ */
35
+ private fireTransaction;
36
+ /**
37
+ * @summary Releases The lock after the conclusion of a transaction
38
+ */
39
+ release(err?: Error): Promise<void>;
40
+ }
@@ -0,0 +1 @@
1
+ var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&("get"in i?t.__esModule:!i.writable&&!i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,i)}:function(e,t,r,o){e[o=void 0===o?r:o]=t[r]}),__exportStar=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||__createBinding(t,e,r)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./Lock.cjs"),exports),__exportStar(require("./SyncronousLock.cjs"),exports);
@@ -0,0 +1,2 @@
1
+ export * from "./Lock";
2
+ export * from "./SyncronousLock";
package/lib/types.cjs ADDED
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,"__esModule",{value:!0});
package/lib/types.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @summary defines a callable as perceived by the lock
3
+ *
4
+ * @memberOf module:db-decorators.Transactions
5
+ */
6
+ export type LockCallable = (value?: void | PromiseLike<void>) => void;
7
+ export type Callback = (err?: Error, result?: any, ...args: any[]) => void;
package/lib/utils.cjs ADDED
@@ -0,0 +1 @@
1
+ function getObjectName(e){if(e)return"string"==typeof e?e:e.constructor&&e.constructor.name&&-1===["Function","Object"].indexOf(e.constructor.name)?e.constructor.name:"function"==typeof e&&e.name?e.name:e.toString()}Object.defineProperty(exports,"__esModule",{value:!0}),exports.getObjectName=getObjectName;
package/lib/utils.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function getObjectName(obj: any): string | undefined;
package/package.json ADDED
@@ -0,0 +1,107 @@
1
+ {
2
+ "name": "@decaf-ts/transactional-decorators",
3
+ "version": "0.0.4",
4
+ "description": "template for ts projects",
5
+ "type": "module",
6
+ "exports": {
7
+ "require": "./lib/index.cjs",
8
+ "import": "./lib/esm/index.js"
9
+ },
10
+ "types": "lib/index.d.ts",
11
+ "scripts": {
12
+ "do-install": "TOKEN=$(cat .token) npm install",
13
+ "flash-forward": "npx npm-check-updates -u && npm run do-install",
14
+ "reset": "rm -rf * && git checkout . && git pull && npm run do-install",
15
+ "build": "rimraf ./lib && rimraf ./dist && gulp dev",
16
+ "build:prod": "rimraf ./lib && rimraf ./dist && gulp prod",
17
+ "test": "jest --coverage --testPathPattern=\"/tests/unit\" --passWithNoTests --detectOpenHandles",
18
+ "test:integration": "jest --coverage --testPathPattern=\"/tests/(integration)\" --passWithNoTests --detectOpenHandles",
19
+ "test:all": "jest --coverage --testPathPattern=\"/tests/(unit|integration)\" --passWithNoTests --detectOpenHandles",
20
+ "lint": "eslint .",
21
+ "lint-fix": "eslint --fix ./src/*",
22
+ "test:circular": "dpdm -T --no-warning --no-tree ./src/index.ts",
23
+ "prepare-release": "npm run lint-fix && npm run build:prod && npm run docs",
24
+ "release": "./bin/tag-release.sh",
25
+ "clean-publish": "npx clean-publish",
26
+ "coverage": "npm run test:all && jest-coverage-badges --input \"./workdocs/coverage/coverage-summary.json\" --output \"./workdocs/badges\"",
27
+ "drawings": "for FILE in workdocs/drawings/*.drawio; do echo \"converting $FILE to image...\" && docker run --rm -v $(pwd):/data rlespinasse/drawio-export --format png $FILE; done && cp -rf workdocs/drawings/export/* workdocs/resources/",
28
+ "uml": "cd workdocs/uml && for FILE in ./*.puml; do docker run --rm -v $(pwd):/work -w /work miy4/plantuml -DPLANTUML_LIMIT_SIZE=8192 -tpng $FILE; done && cd ../.. && cp -fr workdocs/uml/*.png workdocs/resources/",
29
+ "docs": "npx rimraf ./docs && mkdir docs && npm run do-install -- better-docs taffydb && gulp docs; npm remove better-docs taffydb"
30
+ },
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "git+https://github.com/decaf-ts/ts-workspace.git"
34
+ },
35
+ "engines": {
36
+ "node": ">=20.0.0",
37
+ "npm": ">=10.0.0"
38
+ },
39
+ "files": [
40
+ "lib",
41
+ "dist"
42
+ ],
43
+ "keywords": [
44
+ "plantuml",
45
+ "mermaid",
46
+ "uml",
47
+ "drawio",
48
+ "mddocs",
49
+ "md",
50
+ "jsdoc",
51
+ "doc",
52
+ "docs",
53
+ "documentation",
54
+ "ci/cd",
55
+ "ci",
56
+ "cd",
57
+ "template",
58
+ "typescript",
59
+ "ts"
60
+ ],
61
+ "author": "Tiago Venceslau",
62
+ "license": "MIT",
63
+ "bugs": {
64
+ "url": "https://github.com/decaf-ts/ts-workspace/issues"
65
+ },
66
+ "homepage": "https://github.com/decaf-ts/ts-workspace#readme",
67
+ "devDependencies": {
68
+ "@decaf-ts/db-decorators": "latest",
69
+ "@decaf-ts/decorator-validation": "latest",
70
+ "@decaf-ts/injectable-decorators": "latest",
71
+ "@types/jest": "^29.5.12",
72
+ "@typescript-eslint/eslint-plugin": "^7.1.1",
73
+ "clean-publish": "^4.3.0",
74
+ "eslint": "^8.57.0",
75
+ "eslint-config-prettier": "^9.1.0",
76
+ "eslint-plugin-prettier": "^5.1.3",
77
+ "gulp": "^4.0.2",
78
+ "gulp-if": "^3.0.0",
79
+ "gulp-rename": "^2.0.0",
80
+ "gulp-replace": "^1.1.4",
81
+ "gulp-run-command": "^0.0.10",
82
+ "gulp-sourcemaps": "^3.0.0",
83
+ "gulp-typescript": "^6.0.0-alpha.1",
84
+ "gulp-uglify": "^3.0.2",
85
+ "jest": "^29.7.0",
86
+ "jest-coverage-badges": "^1.1.2",
87
+ "jest-junit": "^16.0.0",
88
+ "jsdoc": "^4.0.2",
89
+ "jsdoc-mermaid": "^1.0.0",
90
+ "markdown-include": "^0.4.3",
91
+ "merge-stream": "^2.0.0",
92
+ "nodemon": "^3.1.0",
93
+ "npm-check-updates": "^16.14.15",
94
+ "prettier": "^3.2.5",
95
+ "rimraf": "^5.0.5",
96
+ "ts-jest": "^29.1.2",
97
+ "ts-loader": "^9.5.1",
98
+ "ts-node": "^10.9.2",
99
+ "typescript": "^5.4.2",
100
+ "vinyl-named": "^1.1.0",
101
+ "webpack-stream": "^7.0.0"
102
+ },
103
+ "peerDependencies": {
104
+ "@decaf-ts/reflection": "latest",
105
+ "reflect-metadata": "^0.2.1"
106
+ }
107
+ }