emilsoftware-utilities 1.0.3 → 1.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.
- package/decorators/autobind.d.ts +15 -0
- package/decorators/autobind.js +94 -0
- package/decorators/log-execution-time.d.ts +1 -0
- package/decorators/log-execution-time.js +78 -0
- package/index.ts +1 -0
- package/package.json +29 -29
- package/src/orm.ts +0 -4
- package/tsconfig.json +1 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Return a descriptor removing the value and returning a getter
|
|
3
|
+
* The getter will return a .bind version of the function
|
|
4
|
+
* and memoize the result against a symbol on the instance
|
|
5
|
+
*/
|
|
6
|
+
export declare function boundMethod(target: any, key: any, descriptor: any): {
|
|
7
|
+
configurable: boolean;
|
|
8
|
+
get(): any;
|
|
9
|
+
set(value: any): void;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Use boundMethod to bind all methods on the target.prototype
|
|
13
|
+
*/
|
|
14
|
+
export declare function boundClass(target: any): any;
|
|
15
|
+
export default function autobind(...args: any[]): any;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.boundClass = exports.boundMethod = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Return a descriptor removing the value and returning a getter
|
|
6
|
+
* The getter will return a .bind version of the function
|
|
7
|
+
* and memoize the result against a symbol on the instance
|
|
8
|
+
*/
|
|
9
|
+
function boundMethod(target, key, descriptor) {
|
|
10
|
+
var fn = descriptor === null || descriptor === void 0 ? void 0 : descriptor.value;
|
|
11
|
+
if (typeof fn !== 'function') {
|
|
12
|
+
throw new TypeError("@boundMethod decorator can only be applied to methods not: ".concat(typeof fn));
|
|
13
|
+
}
|
|
14
|
+
// In IE11 calling Object.defineProperty has a side effect of evaluating the
|
|
15
|
+
// getter for the property which is being replaced. This causes infinite
|
|
16
|
+
// recursion and an "Out of stack space" error.
|
|
17
|
+
var definingProperty = false;
|
|
18
|
+
return {
|
|
19
|
+
configurable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
22
|
+
if (definingProperty || this === target.prototype || this.hasOwnProperty(key) ||
|
|
23
|
+
typeof fn !== 'function') {
|
|
24
|
+
return fn;
|
|
25
|
+
}
|
|
26
|
+
var boundFn = fn.bind(this);
|
|
27
|
+
definingProperty = true;
|
|
28
|
+
if (key) {
|
|
29
|
+
Object.defineProperty(this, key, {
|
|
30
|
+
configurable: true,
|
|
31
|
+
get: function () {
|
|
32
|
+
return boundFn;
|
|
33
|
+
},
|
|
34
|
+
set: function (value) {
|
|
35
|
+
fn = value;
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
delete this[key];
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
definingProperty = false;
|
|
42
|
+
return boundFn;
|
|
43
|
+
},
|
|
44
|
+
set: function (value) {
|
|
45
|
+
fn = value;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
exports.boundMethod = boundMethod;
|
|
50
|
+
/**
|
|
51
|
+
* Use boundMethod to bind all methods on the target.prototype
|
|
52
|
+
*/
|
|
53
|
+
function boundClass(target) {
|
|
54
|
+
// (Using reflect to get all keys including symbols)
|
|
55
|
+
var keys;
|
|
56
|
+
// Use Reflect if exists
|
|
57
|
+
if (typeof Reflect !== 'undefined' && typeof Reflect.ownKeys === 'function') {
|
|
58
|
+
keys = Reflect.ownKeys(target.prototype);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
keys = Object.getOwnPropertyNames(target.prototype);
|
|
62
|
+
// Use symbols if support is provided
|
|
63
|
+
if (typeof Object.getOwnPropertySymbols === 'function') {
|
|
64
|
+
// @ts-ignore
|
|
65
|
+
keys = keys.concat(Object.getOwnPropertySymbols(target.prototype));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
keys.forEach(function (key) {
|
|
69
|
+
// Ignore special case target method
|
|
70
|
+
if (key === 'constructor') {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
var descriptor = Object.getOwnPropertyDescriptor(target.prototype, key);
|
|
74
|
+
// Only methods need binding
|
|
75
|
+
if (typeof (descriptor === null || descriptor === void 0 ? void 0 : descriptor.value) === 'function') {
|
|
76
|
+
Object.defineProperty(target.prototype, key, boundMethod(target, key, descriptor));
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
return target;
|
|
80
|
+
}
|
|
81
|
+
exports.boundClass = boundClass;
|
|
82
|
+
function autobind() {
|
|
83
|
+
var args = [];
|
|
84
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
85
|
+
args[_i] = arguments[_i];
|
|
86
|
+
}
|
|
87
|
+
if (args.length === 1) {
|
|
88
|
+
// @ts-ignore
|
|
89
|
+
return boundClass.apply(void 0, args);
|
|
90
|
+
}
|
|
91
|
+
// @ts-ignore
|
|
92
|
+
return boundMethod.apply(void 0, args);
|
|
93
|
+
}
|
|
94
|
+
exports.default = autobind;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function logExecutionTime(fileName?: string): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
var logger_1 = require("../logger");
|
|
40
|
+
function logExecutionTime(fileName) {
|
|
41
|
+
if (fileName === void 0) { fileName = ""; }
|
|
42
|
+
return function (target, propertyKey, descriptor) {
|
|
43
|
+
var logger = new logger_1.Logger(fileName);
|
|
44
|
+
var originalMethod = descriptor.value;
|
|
45
|
+
descriptor.value = function () {
|
|
46
|
+
var args = [];
|
|
47
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
48
|
+
args[_i] = arguments[_i];
|
|
49
|
+
}
|
|
50
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
51
|
+
var start, result, end, durationInMilliseconds, error_1;
|
|
52
|
+
return __generator(this, function (_a) {
|
|
53
|
+
switch (_a.label) {
|
|
54
|
+
case 0:
|
|
55
|
+
start = process.hrtime();
|
|
56
|
+
logger.info(" ".concat(propertyKey, " method execution started . . ."));
|
|
57
|
+
_a.label = 1;
|
|
58
|
+
case 1:
|
|
59
|
+
_a.trys.push([1, 3, , 4]);
|
|
60
|
+
return [4 /*yield*/, originalMethod.apply(this, args)];
|
|
61
|
+
case 2:
|
|
62
|
+
result = _a.sent();
|
|
63
|
+
end = process.hrtime(start);
|
|
64
|
+
durationInMilliseconds = end[0] * 1000 + end[1] / 1e6;
|
|
65
|
+
logger.info(" ".concat(propertyKey, " method took ").concat(durationInMilliseconds.toFixed(2), " ms to execute"));
|
|
66
|
+
return [2 /*return*/, result];
|
|
67
|
+
case 3:
|
|
68
|
+
error_1 = _a.sent();
|
|
69
|
+
throw error_1;
|
|
70
|
+
case 4: return [2 /*return*/];
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
return descriptor;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
exports.default = logExecutionTime;
|
package/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist';
|
package/package.json
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "emilsoftware-utilities",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Utilities for EmilSoftware",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
-
"build": "tsc",
|
|
9
|
-
"prepublishOnly": "npm run build"
|
|
10
|
-
},
|
|
11
|
-
"repository": {
|
|
12
|
-
"type": "git",
|
|
13
|
-
"url": "git+https://github.com/mttdev382/emilsoftware-utilities.git"
|
|
14
|
-
},
|
|
15
|
-
"author": "",
|
|
16
|
-
"license": "ISC",
|
|
17
|
-
"bugs": {
|
|
18
|
-
"url": "https://github.com/mttdev382/emilsoftware-utilities/issues"
|
|
19
|
-
},
|
|
20
|
-
"homepage": "https://github.com/mttdev382/emilsoftware-utilities#readme",
|
|
21
|
-
"dependencies": {
|
|
22
|
-
"es-node-firebird": "^1.1.8",
|
|
23
|
-
"winston": "^3.11.0"
|
|
24
|
-
},
|
|
25
|
-
"devDependencies": {
|
|
26
|
-
"@types/node": "^20.10.5",
|
|
27
|
-
"typescript": "^5.3.3"
|
|
28
|
-
}
|
|
29
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "emilsoftware-utilities",
|
|
3
|
+
"version": "1.0.4",
|
|
4
|
+
"description": "Utilities for EmilSoftware",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"prepublishOnly": "npm run build"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/mttdev382/emilsoftware-utilities.git"
|
|
14
|
+
},
|
|
15
|
+
"author": "",
|
|
16
|
+
"license": "ISC",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/mttdev382/emilsoftware-utilities/issues"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/mttdev382/emilsoftware-utilities#readme",
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"es-node-firebird": "^1.1.8",
|
|
23
|
+
"winston": "^3.11.0"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/node": "^20.10.5",
|
|
27
|
+
"typescript": "^5.3.3"
|
|
28
|
+
}
|
|
29
|
+
}
|
package/src/orm.ts
CHANGED
|
@@ -23,7 +23,6 @@ export class Orm {
|
|
|
23
23
|
})
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
|
|
27
26
|
public static query(options: any, query: any, parameters: any[] = []): Promise<any> {
|
|
28
27
|
return new Promise((resolve, reject): void => {
|
|
29
28
|
Firebird.attach(options, (err: any, db: {
|
|
@@ -44,7 +43,6 @@ export class Orm {
|
|
|
44
43
|
});
|
|
45
44
|
}
|
|
46
45
|
|
|
47
|
-
|
|
48
46
|
public static execute(options: any, query: any, parameters: any = []): Promise<any> {
|
|
49
47
|
return new Promise((resolve, reject): void => {
|
|
50
48
|
Firebird.attach(options, (err: any, db: {
|
|
@@ -106,8 +104,6 @@ export class Orm {
|
|
|
106
104
|
});
|
|
107
105
|
});
|
|
108
106
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
107
|
}
|
|
112
108
|
|
|
113
109
|
|