emilsoftware-utilities 1.3.13 → 1.3.14

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.
@@ -1,19 +1 @@
1
- export declare class Autobind {
2
- /**
3
- * Binds a method to the instance, ensuring `this` references are preserved.
4
- */
5
- static boundMethod(target: any, key: any, descriptor: any): {
6
- configurable: boolean;
7
- get(): any;
8
- set(value: any): void;
9
- };
10
- /**
11
- * Applies `boundMethod` to all methods in the class prototype.
12
- */
13
- static boundClass(target: any): any;
14
- /**
15
- * Retrieves all property keys (including symbols) from the prototype.
16
- */
17
- private static getPrototypeKeys;
18
- static apply(...args: any[]): any;
19
- }
1
+ export declare function autobind(...args: any[]): any;
package/dist/Autobind.js CHANGED
@@ -1,29 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Autobind = void 0;
4
- var Autobind = /** @class */ (function () {
5
- function Autobind() {
3
+ exports.autobind = autobind;
4
+ // DECORATOR
5
+ /**
6
+ * Return a descriptor removing the value and returning a getter
7
+ * The getter will return a .bind version of the function
8
+ * and memoize the result against a symbol on the instance
9
+ */
10
+ function boundMethod(target, key, descriptor) {
11
+ var fn = descriptor === null || descriptor === void 0 ? void 0 : descriptor.value;
12
+ if (typeof fn !== 'function') {
13
+ throw new TypeError("@boundMethod decorator can only be applied to methods not: ".concat(typeof fn));
6
14
  }
7
- /**
8
- * Binds a method to the instance, ensuring `this` references are preserved.
9
- */
10
- Autobind.boundMethod = function (target, key, descriptor) {
11
- var fn = descriptor === null || descriptor === void 0 ? void 0 : descriptor.value;
12
- if (typeof fn !== 'function') {
13
- throw new TypeError("@boundMethod decorator can only be applied to methods, not: ".concat(typeof fn));
14
- }
15
- var definingProperty = false;
16
- return {
17
- configurable: true,
18
- get: function () {
19
- if (definingProperty ||
20
- this === target.prototype ||
21
- Object.prototype.hasOwnProperty.call(this, key) ||
22
- typeof fn !== 'function') {
23
- return fn;
24
- }
25
- var boundFn = fn.bind(this);
26
- definingProperty = true;
15
+ // In IE11 calling Object.defineProperty has a side effect of evaluating the
16
+ // getter for the property which is being replaced. This causes infinite
17
+ // recursion and an "Out of stack space" error.
18
+ var definingProperty = false;
19
+ return {
20
+ configurable: true,
21
+ get: function () {
22
+ // eslint-disable-next-line no-prototype-builtins
23
+ if (definingProperty || this === target.prototype || this.hasOwnProperty(key) ||
24
+ typeof fn !== 'function') {
25
+ return fn;
26
+ }
27
+ var boundFn = fn.bind(this);
28
+ definingProperty = true;
29
+ if (key) {
27
30
  Object.defineProperty(this, key, {
28
31
  configurable: true,
29
32
  get: function () {
@@ -31,55 +34,59 @@ var Autobind = /** @class */ (function () {
31
34
  },
32
35
  set: function (value) {
33
36
  fn = value;
37
+ // @ts-ignore
34
38
  delete this[key];
35
- },
39
+ }
36
40
  });
37
- definingProperty = false;
38
- return boundFn;
39
- },
40
- set: function (value) {
41
- fn = value;
42
- },
43
- };
44
- };
45
- /**
46
- * Applies `boundMethod` to all methods in the class prototype.
47
- */
48
- Autobind.boundClass = function (target) {
49
- var keys = Autobind.getPrototypeKeys(target.prototype);
50
- keys.forEach(function (key) {
51
- if (key === 'constructor')
52
- return;
53
- var descriptor = Object.getOwnPropertyDescriptor(target.prototype, key);
54
- if (descriptor && typeof descriptor.value === 'function') {
55
- Object.defineProperty(target.prototype, key, Autobind.boundMethod(target, key, descriptor));
56
41
  }
57
- });
58
- return target;
59
- };
60
- /**
61
- * Retrieves all property keys (including symbols) from the prototype.
62
- */
63
- Autobind.getPrototypeKeys = function (proto) {
64
- if (typeof Reflect !== 'undefined' && typeof Reflect.ownKeys === 'function') {
65
- return Reflect.ownKeys(proto);
42
+ definingProperty = false;
43
+ return boundFn;
44
+ },
45
+ set: function (value) {
46
+ fn = value;
66
47
  }
67
- var keys = Object.getOwnPropertyNames(proto);
48
+ };
49
+ }
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
68
63
  if (typeof Object.getOwnPropertySymbols === 'function') {
69
- return keys.concat(Object.getOwnPropertySymbols(proto));
64
+ // @ts-ignore
65
+ keys = keys.concat(Object.getOwnPropertySymbols(target.prototype));
70
66
  }
71
- return keys;
72
- };
73
- Autobind.apply = function () {
74
- var args = [];
75
- for (var _i = 0; _i < arguments.length; _i++) {
76
- args[_i] = arguments[_i];
67
+ }
68
+ keys.forEach(function (key) {
69
+ // Ignore special case target method
70
+ if (key === 'constructor') {
71
+ return;
77
72
  }
78
- if (args.length === 1) {
79
- return Autobind.boundClass(args[0]);
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));
80
77
  }
81
- return Autobind.boundMethod(args[0], args[1], args[2]);
82
- };
83
- return Autobind;
84
- }());
85
- exports.Autobind = Autobind;
78
+ });
79
+ return target;
80
+ }
81
+ function autobind() {
82
+ var args = [];
83
+ for (var _i = 0; _i < arguments.length; _i++) {
84
+ args[_i] = arguments[_i];
85
+ }
86
+ if (args.length === 1) {
87
+ // @ts-ignore
88
+ return boundClass.apply(void 0, args);
89
+ }
90
+ // @ts-ignore
91
+ return boundMethod.apply(void 0, args);
92
+ }
package/dist/Orm.js CHANGED
@@ -103,8 +103,7 @@ var Logger_1 = require("./Logger");
103
103
  var Utilities_1 = require("./Utilities");
104
104
  var Autobind_1 = require("./Autobind");
105
105
  var Orm = function () {
106
- var _a;
107
- var _classDecorators = [(_a = Autobind_1.Autobind).apply.bind(_a)];
106
+ var _classDecorators = [Autobind_1.autobind];
108
107
  var _classDescriptor;
109
108
  var _classExtraInitializers = [];
110
109
  var _classThis;
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { Autobind } from "./Autobind";
1
+ import { autobind } from "./Autobind";
2
2
  import { DatabaseUpdater } from "./DatabaseUpdater";
3
3
  import { ExecutionTimeLogger } from "./ExecutionTimeLogger";
4
4
  import { LogLevels, Logger } from "./Logger";
5
5
  import { Orm } from "./Orm";
6
6
  import { DateUtilities, RestUtilities, DatabaseUtilities, StatusCode } from "./Utilities";
7
7
  export * from "es-node-firebird";
8
- export { Autobind, ExecutionTimeLogger, Logger, LogLevels, Orm, DateUtilities, RestUtilities, DatabaseUtilities, DatabaseUpdater, StatusCode };
8
+ export { autobind, ExecutionTimeLogger, Logger, LogLevels, Orm, DateUtilities, RestUtilities, DatabaseUtilities, DatabaseUpdater, StatusCode };
package/dist/index.js CHANGED
@@ -14,9 +14,9 @@ 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.StatusCode = exports.DatabaseUpdater = exports.DatabaseUtilities = exports.RestUtilities = exports.DateUtilities = exports.Orm = exports.LogLevels = exports.Logger = exports.ExecutionTimeLogger = exports.Autobind = void 0;
17
+ exports.StatusCode = exports.DatabaseUpdater = exports.DatabaseUtilities = exports.RestUtilities = exports.DateUtilities = exports.Orm = exports.LogLevels = exports.Logger = exports.ExecutionTimeLogger = exports.autobind = void 0;
18
18
  var Autobind_1 = require("./Autobind");
19
- Object.defineProperty(exports, "Autobind", { enumerable: true, get: function () { return Autobind_1.Autobind; } });
19
+ Object.defineProperty(exports, "autobind", { enumerable: true, get: function () { return Autobind_1.autobind; } });
20
20
  var DatabaseUpdater_1 = require("./DatabaseUpdater");
21
21
  Object.defineProperty(exports, "DatabaseUpdater", { enumerable: true, get: function () { return DatabaseUpdater_1.DatabaseUpdater; } });
22
22
  var ExecutionTimeLogger_1 = require("./ExecutionTimeLogger");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emilsoftware-utilities",
3
- "version": "1.3.13",
3
+ "version": "1.3.14",
4
4
  "description": "Utilities for EmilSoftware",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",