@open-norantec/utilities 2.1.0 → 2.1.1

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,56 +1,121 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ArrayUtil = void 0;
4
- class ArrayUtil {
5
- static checkUnique(data, validator) {
1
+ var __values = (this && this.__values) || function(o) {
2
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
3
+ if (m) return m.call(o);
4
+ if (o && typeof o.length === "number") return {
5
+ next: function () {
6
+ if (o && i >= o.length) o = void 0;
7
+ return { value: o && o[i++], done: !o };
8
+ }
9
+ };
10
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
11
+ };
12
+ var __read = (this && this.__read) || function (o, n) {
13
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
14
+ if (!m) return o;
15
+ var i = m.call(o), r, ar = [], e;
16
+ try {
17
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
18
+ }
19
+ catch (error) { e = { error: error }; }
20
+ finally {
21
+ try {
22
+ if (r && !r.done && (m = i["return"])) m.call(i);
23
+ }
24
+ finally { if (e) throw e.error; }
25
+ }
26
+ return ar;
27
+ };
28
+ var ArrayUtil = (function () {
29
+ function ArrayUtil() {
30
+ }
31
+ ArrayUtil.checkUnique = function (data, validator) {
32
+ var e_1, _a;
6
33
  if (!data || !Array.isArray(data)) {
7
34
  return;
8
35
  }
9
- const values = [];
10
- for (const item of data) {
11
- const currentValue = validator(item);
36
+ var values = [];
37
+ var _loop_1 = function (item) {
38
+ var currentValue = validator(item);
12
39
  if (!Array.isArray(currentValue)) {
13
- continue;
40
+ return "continue";
14
41
  }
15
- const exist = values.some((checkValue) => {
16
- for (const [index, value] of checkValue.entries()) {
17
- if (currentValue[index] !== value) {
18
- return false;
42
+ var exist = values.some(function (checkValue) {
43
+ var e_2, _a;
44
+ try {
45
+ for (var _b = (e_2 = void 0, __values(checkValue.entries())), _c = _b.next(); !_c.done; _c = _b.next()) {
46
+ var _d = __read(_c.value, 2), index = _d[0], value = _d[1];
47
+ if (currentValue[index] !== value) {
48
+ return false;
49
+ }
50
+ }
51
+ }
52
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
53
+ finally {
54
+ try {
55
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
19
56
  }
57
+ finally { if (e_2) throw e_2.error; }
20
58
  }
21
59
  return true;
22
60
  });
23
61
  if (exist) {
24
- return false;
62
+ return { value: false };
25
63
  }
26
64
  values.push(currentValue);
65
+ };
66
+ try {
67
+ for (var data_1 = __values(data), data_1_1 = data_1.next(); !data_1_1.done; data_1_1 = data_1.next()) {
68
+ var item = data_1_1.value;
69
+ var state_1 = _loop_1(item);
70
+ if (typeof state_1 === "object")
71
+ return state_1.value;
72
+ }
73
+ }
74
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
75
+ finally {
76
+ try {
77
+ if (data_1_1 && !data_1_1.done && (_a = data_1.return)) _a.call(data_1);
78
+ }
79
+ finally { if (e_1) throw e_1.error; }
27
80
  }
28
81
  return true;
29
- }
30
- static getPositiveIndexValue(length, index) {
82
+ };
83
+ ArrayUtil.getPositiveIndexValue = function (length, index) {
31
84
  if (!length || !index) {
32
85
  return index;
33
86
  }
34
- let result = index;
87
+ var result = index;
35
88
  while (result < 0) {
36
89
  result = length + result;
37
90
  }
38
91
  return result;
39
- }
40
- static traverse(array, transformer) {
92
+ };
93
+ ArrayUtil.traverse = function (array, transformer) {
94
+ var e_3, _a;
41
95
  if (!Array.isArray(array)) {
42
96
  return [];
43
97
  }
44
- const result = [];
45
- for (const item of array) {
46
- if (Array.isArray(item)) {
47
- result.push(ArrayUtil.traverse(item, transformer));
98
+ var result = [];
99
+ try {
100
+ for (var array_1 = __values(array), array_1_1 = array_1.next(); !array_1_1.done; array_1_1 = array_1.next()) {
101
+ var item = array_1_1.value;
102
+ if (Array.isArray(item)) {
103
+ result.push(ArrayUtil.traverse(item, transformer));
104
+ }
105
+ else {
106
+ result.push(typeof transformer === 'function' ? transformer(item) : item);
107
+ }
48
108
  }
49
- else {
50
- result.push(typeof transformer === 'function' ? transformer(item) : item);
109
+ }
110
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
111
+ finally {
112
+ try {
113
+ if (array_1_1 && !array_1_1.done && (_a = array_1.return)) _a.call(array_1);
51
114
  }
115
+ finally { if (e_3) throw e_3.error; }
52
116
  }
53
117
  return result;
54
- }
55
- }
56
- exports.ArrayUtil = ArrayUtil;
118
+ };
119
+ return ArrayUtil;
120
+ }());
121
+ export { ArrayUtil };
@@ -1,23 +1,64 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AttemptUtil = void 0;
4
- class AttemptUtil {
5
- static exec(callbackFn) {
6
- try {
7
- return callbackFn === null || callbackFn === void 0 ? void 0 : callbackFn();
8
- }
9
- catch (error) {
10
- return error;
11
- }
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
12
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ 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;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ var AttemptUtil = (function () {
38
+ function AttemptUtil() {
12
39
  }
13
- static async execPromise(promise) {
14
- var _a;
40
+ AttemptUtil.exec = function (callbackFn) {
15
41
  try {
16
- return (_a = promise === null || promise === void 0 ? void 0 : promise.catch) === null || _a === void 0 ? void 0 : _a.call(promise, (error) => Promise.resolve(error));
42
+ return callbackFn === null || callbackFn === void 0 ? void 0 : callbackFn();
17
43
  }
18
44
  catch (error) {
19
45
  return error;
20
46
  }
21
- }
22
- }
23
- exports.AttemptUtil = AttemptUtil;
47
+ };
48
+ AttemptUtil.execPromise = function (promise) {
49
+ return __awaiter(this, void 0, void 0, function () {
50
+ var _a;
51
+ return __generator(this, function (_b) {
52
+ try {
53
+ return [2, (_a = promise === null || promise === void 0 ? void 0 : promise.catch) === null || _a === void 0 ? void 0 : _a.call(promise, function (error) { return Promise.resolve(error); })];
54
+ }
55
+ catch (error) {
56
+ return [2, error];
57
+ }
58
+ return [2];
59
+ });
60
+ });
61
+ };
62
+ return AttemptUtil;
63
+ }());
64
+ export { AttemptUtil };
@@ -2,5 +2,5 @@ export declare class CryptoUtil {
2
2
  static importRsaPrivatePemKey(pemString: string, algorithm: AlgorithmIdentifier, keyUsages: Iterable<KeyUsage>): Promise<CryptoKey>;
3
3
  static importRsaPublicPemKey(pemString: string, algorithm: AlgorithmIdentifier, keyUsages: Iterable<KeyUsage>): Promise<CryptoKey>;
4
4
  static sha256Hex(input: string): Promise<string>;
5
- static convertHexToUint8Array(hexString: string): Uint8Array;
5
+ static convertHexToUint8Array(hexString: string): Uint8Array<ArrayBuffer>;
6
6
  }
@@ -1,40 +1,106 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CryptoUtil = void 0;
4
- class CryptoUtil {
5
- static async importRsaPrivatePemKey(pemString, algorithm, keyUsages) {
6
- const base64 = pemString.replace(/(-----(BEGIN|END) PRIVATE KEY-----|\n|\r)/g, '').trim();
7
- const binaryString = atob(base64);
8
- const keyArrayBuffer = new ArrayBuffer(binaryString.length);
9
- const keyArrayBufferView = new Uint8Array(keyArrayBuffer);
10
- for (let i = 0; i < binaryString.length; i += 1) {
11
- keyArrayBufferView[i] = binaryString.charCodeAt(i);
12
- }
13
- const importedKey = await crypto.subtle.importKey('pkcs8', keyArrayBuffer, algorithm, true, keyUsages);
14
- return importedKey;
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
12
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ 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;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
15
35
  }
16
- static async importRsaPublicPemKey(pemString, algorithm, keyUsages) {
17
- const base64 = pemString.replace(/(-----(BEGIN|END) PUBLIC KEY-----|\n|\r)/g, '').trim();
18
- const binaryString = atob(base64);
19
- const keyArrayBuffer = new ArrayBuffer(binaryString.length);
20
- const keyArrayBufferView = new Uint8Array(keyArrayBuffer);
21
- for (let i = 0; i < binaryString.length; i += 1) {
22
- keyArrayBufferView[i] = binaryString.charCodeAt(i);
23
- }
24
- const importedKey = await crypto.subtle.importKey('spki', keyArrayBuffer, algorithm, true, keyUsages);
25
- return importedKey;
36
+ };
37
+ var CryptoUtil = (function () {
38
+ function CryptoUtil() {
26
39
  }
27
- static async sha256Hex(input) {
28
- const encoder = new TextEncoder();
29
- const data = encoder.encode(input);
30
- const hashBuffer = await crypto.subtle.digest('SHA-256', data);
31
- const hashArray = Array.from(new Uint8Array(hashBuffer));
32
- return hashArray.map((b) => b.toString(16).padStart(2, '0')).join('');
33
- }
34
- static convertHexToUint8Array(hexString) {
35
- return new Uint8Array(new Array(hexString.length / 2).fill(0).map((value, index) => {
40
+ CryptoUtil.importRsaPrivatePemKey = function (pemString, algorithm, keyUsages) {
41
+ return __awaiter(this, void 0, void 0, function () {
42
+ var base64, binaryString, keyArrayBuffer, keyArrayBufferView, i, importedKey;
43
+ return __generator(this, function (_a) {
44
+ switch (_a.label) {
45
+ case 0:
46
+ base64 = pemString.replace(/(-----(BEGIN|END) PRIVATE KEY-----|\n|\r)/g, '').trim();
47
+ binaryString = atob(base64);
48
+ keyArrayBuffer = new ArrayBuffer(binaryString.length);
49
+ keyArrayBufferView = new Uint8Array(keyArrayBuffer);
50
+ for (i = 0; i < binaryString.length; i += 1) {
51
+ keyArrayBufferView[i] = binaryString.charCodeAt(i);
52
+ }
53
+ return [4, crypto.subtle.importKey('pkcs8', keyArrayBuffer, algorithm, true, keyUsages)];
54
+ case 1:
55
+ importedKey = _a.sent();
56
+ return [2, importedKey];
57
+ }
58
+ });
59
+ });
60
+ };
61
+ CryptoUtil.importRsaPublicPemKey = function (pemString, algorithm, keyUsages) {
62
+ return __awaiter(this, void 0, void 0, function () {
63
+ var base64, binaryString, keyArrayBuffer, keyArrayBufferView, i, importedKey;
64
+ return __generator(this, function (_a) {
65
+ switch (_a.label) {
66
+ case 0:
67
+ base64 = pemString.replace(/(-----(BEGIN|END) PUBLIC KEY-----|\n|\r)/g, '').trim();
68
+ binaryString = atob(base64);
69
+ keyArrayBuffer = new ArrayBuffer(binaryString.length);
70
+ keyArrayBufferView = new Uint8Array(keyArrayBuffer);
71
+ for (i = 0; i < binaryString.length; i += 1) {
72
+ keyArrayBufferView[i] = binaryString.charCodeAt(i);
73
+ }
74
+ return [4, crypto.subtle.importKey('spki', keyArrayBuffer, algorithm, true, keyUsages)];
75
+ case 1:
76
+ importedKey = _a.sent();
77
+ return [2, importedKey];
78
+ }
79
+ });
80
+ });
81
+ };
82
+ CryptoUtil.sha256Hex = function (input) {
83
+ return __awaiter(this, void 0, void 0, function () {
84
+ var encoder, data, hashBuffer, hashArray;
85
+ return __generator(this, function (_a) {
86
+ switch (_a.label) {
87
+ case 0:
88
+ encoder = new TextEncoder();
89
+ data = encoder.encode(input);
90
+ return [4, crypto.subtle.digest('SHA-256', data)];
91
+ case 1:
92
+ hashBuffer = _a.sent();
93
+ hashArray = Array.from(new Uint8Array(hashBuffer));
94
+ return [2, hashArray.map(function (b) { return b.toString(16).padStart(2, '0'); }).join('')];
95
+ }
96
+ });
97
+ });
98
+ };
99
+ CryptoUtil.convertHexToUint8Array = function (hexString) {
100
+ return new Uint8Array(new Array(hexString.length / 2).fill(0).map(function (value, index) {
36
101
  return parseInt(hexString.slice(index * 2, index * 2 + 2), 16);
37
102
  }));
38
- }
39
- }
40
- exports.CryptoUtil = CryptoUtil;
103
+ };
104
+ return CryptoUtil;
105
+ }());
106
+ export { CryptoUtil };
@@ -1,15 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DateUtil = void 0;
4
- const string_util_class_1 = require("./string-util.class");
5
- class DateUtil {
6
- static isValidDate(date) {
7
- return date instanceof Date && !Number.isNaN(Date.prototype.getTime.call(date));
1
+ import { StringUtil } from './string-util.class';
2
+ var DateUtil = (function () {
3
+ function DateUtil() {
8
4
  }
9
- static isValidDateString(value) {
10
- if (string_util_class_1.StringUtil.isFalsyString(value))
5
+ DateUtil.isValidDate = function (date) {
6
+ return date instanceof Date && !Number.isNaN(Date.prototype.getTime.call(date));
7
+ };
8
+ DateUtil.isValidDateString = function (value) {
9
+ if (StringUtil.isFalsyString(value))
11
10
  return false;
12
11
  return DateUtil.isValidDate(new Date(value));
13
- }
14
- }
15
- exports.DateUtil = DateUtil;
12
+ };
13
+ return DateUtil;
14
+ }());
15
+ export { DateUtil };
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import * as crypto from 'node:crypto';
4
2
  export declare class ECDHUtil {
5
3
  private readonly curveName;
@@ -1,32 +1,31 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ECDHUtil = void 0;
4
- const crypto = require("node:crypto");
5
- class ECDHUtil {
6
- constructor(curveName = 'prime256v1') {
1
+ import * as crypto from 'node:crypto';
2
+ var ECDHUtil = (function () {
3
+ function ECDHUtil(curveName) {
4
+ if (curveName === void 0) { curveName = 'prime256v1'; }
7
5
  this.curveName = curveName;
8
6
  this.ecdh = crypto.createECDH(this.curveName);
9
7
  this.ALGORITHM = 'aes-256-gcm';
10
8
  }
11
- encrypt(data, otherPublicKey) {
12
- const sharedKey = this.ecdh.computeSecret(new Uint8Array(otherPublicKey));
13
- const iv = crypto.randomBytes(16);
14
- const cipher = crypto.createCipheriv(this.ALGORITHM, new Uint8Array(sharedKey), new Uint8Array(iv));
15
- const encrypted = Buffer.concat([new Uint8Array(cipher.update(data, 'utf-8')), new Uint8Array(cipher.final())]);
9
+ ECDHUtil.prototype.encrypt = function (data, otherPublicKey) {
10
+ var sharedKey = this.ecdh.computeSecret(new Uint8Array(otherPublicKey));
11
+ var iv = crypto.randomBytes(16);
12
+ var cipher = crypto.createCipheriv(this.ALGORITHM, new Uint8Array(sharedKey), new Uint8Array(iv));
13
+ var encrypted = Buffer.concat([new Uint8Array(cipher.update(data, 'utf-8')), new Uint8Array(cipher.final())]);
16
14
  return Buffer.concat([new Uint8Array(iv), new Uint8Array(encrypted), new Uint8Array(cipher.getAuthTag())]).toString('base64');
17
- }
18
- decrypt(encryptedData, otherPublicKey) {
19
- const sharedKey = this.ecdh.computeSecret(new Uint8Array(otherPublicKey));
20
- const data = Buffer.from(encryptedData, 'base64');
21
- const iv = data.subarray(0, 16);
22
- const authTag = data.subarray(data.length - 16);
23
- const encrypted = data.subarray(16, data.length - 16);
24
- const decipher = crypto.createDecipheriv(this.ALGORITHM, new Uint8Array(sharedKey), new Uint8Array(iv));
15
+ };
16
+ ECDHUtil.prototype.decrypt = function (encryptedData, otherPublicKey) {
17
+ var sharedKey = this.ecdh.computeSecret(new Uint8Array(otherPublicKey));
18
+ var data = Buffer.from(encryptedData, 'base64');
19
+ var iv = data.subarray(0, 16);
20
+ var authTag = data.subarray(data.length - 16);
21
+ var encrypted = data.subarray(16, data.length - 16);
22
+ var decipher = crypto.createDecipheriv(this.ALGORITHM, new Uint8Array(sharedKey), new Uint8Array(iv));
25
23
  decipher.setAuthTag(new Uint8Array(authTag));
26
24
  return Buffer.concat([
27
25
  new Uint8Array(decipher.update(new Uint8Array(encrypted))),
28
26
  new Uint8Array(decipher.final()),
29
27
  ]).toString('utf-8');
30
- }
31
- }
32
- exports.ECDHUtil = ECDHUtil;
28
+ };
29
+ return ECDHUtil;
30
+ }());
31
+ export { ECDHUtil };
@@ -6,5 +6,5 @@ export declare class EnumUtil {
6
6
  static getEntries(inputEnum: IEnum): Array<[string, any]>;
7
7
  static isValidValue(inputEnum: IEnum, inputValue: any): boolean;
8
8
  static isEqual(enum1: IEnum, enum2: IEnum): boolean;
9
- static createEnumSchema<const T extends Record<string, string>>(object: T, params?: Parameters<typeof z.enum>[1]): z.ZodEnum<{ [k_1 in T[keyof T]]: k_1; } extends infer T_1 ? { [k in keyof T_1]: { [k_1 in T[keyof T]]: k_1; }[k]; } : never>;
9
+ static createEnumSchema<const T extends Record<string, string>>(object: T, params?: Parameters<typeof z.enum>[1]): z.ZodEnum<{ [k_1 in T[keyof T]]: k_1; } extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never>;
10
10
  }
@@ -1,42 +1,84 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EnumUtil = void 0;
4
- const zod_1 = require("./zod");
5
- class EnumUtil {
6
- static getEntries(inputEnum) {
1
+ var __read = (this && this.__read) || function (o, n) {
2
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
3
+ if (!m) return o;
4
+ var i = m.call(o), r, ar = [], e;
5
+ try {
6
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
7
+ }
8
+ catch (error) { e = { error: error }; }
9
+ finally {
7
10
  try {
8
- return Object.entries(inputEnum).filter(([key]) => {
11
+ if (r && !r.done && (m = i["return"])) m.call(i);
12
+ }
13
+ finally { if (e) throw e.error; }
14
+ }
15
+ return ar;
16
+ };
17
+ var __values = (this && this.__values) || function(o) {
18
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
19
+ if (m) return m.call(o);
20
+ if (o && typeof o.length === "number") return {
21
+ next: function () {
22
+ if (o && i >= o.length) o = void 0;
23
+ return { value: o && o[i++], done: !o };
24
+ }
25
+ };
26
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
27
+ };
28
+ import { z } from './zod';
29
+ var EnumUtil = (function () {
30
+ function EnumUtil() {
31
+ }
32
+ EnumUtil.getEntries = function (inputEnum) {
33
+ try {
34
+ return Object.entries(inputEnum).filter(function (_a) {
35
+ var _b = __read(_a, 1), key = _b[0];
9
36
  return (key.length > 1 && key.startsWith('0')) || Number.isNaN(Number(key));
10
37
  });
11
38
  }
12
39
  catch (e) {
13
40
  return [];
14
41
  }
15
- }
16
- static isValidValue(inputEnum, inputValue) {
17
- const entries = EnumUtil.getEntries(inputEnum);
42
+ };
43
+ EnumUtil.isValidValue = function (inputEnum, inputValue) {
44
+ var entries = EnumUtil.getEntries(inputEnum);
18
45
  if (entries.length === 0)
19
46
  return false;
20
- return entries.some(([, value]) => value === inputValue);
21
- }
22
- static isEqual(enum1, enum2) {
23
- const entries1 = this.getEntries(enum1);
24
- const entries2 = this.getEntries(enum2);
47
+ return entries.some(function (_a) {
48
+ var _b = __read(_a, 2), value = _b[1];
49
+ return value === inputValue;
50
+ });
51
+ };
52
+ EnumUtil.isEqual = function (enum1, enum2) {
53
+ var e_1, _a;
54
+ var entries1 = this.getEntries(enum1);
55
+ var entries2 = this.getEntries(enum2);
25
56
  if (entries1.length !== entries2.length) {
26
57
  return false;
27
58
  }
28
59
  if (entries1.length === 0) {
29
60
  return true;
30
61
  }
31
- for (const [key, value] of entries1) {
32
- if (entries2[key] !== value) {
33
- return false;
62
+ try {
63
+ for (var entries1_1 = __values(entries1), entries1_1_1 = entries1_1.next(); !entries1_1_1.done; entries1_1_1 = entries1_1.next()) {
64
+ var _b = __read(entries1_1_1.value, 2), key = _b[0], value = _b[1];
65
+ if (entries2[key] !== value) {
66
+ return false;
67
+ }
68
+ }
69
+ }
70
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
71
+ finally {
72
+ try {
73
+ if (entries1_1_1 && !entries1_1_1.done && (_a = entries1_1.return)) _a.call(entries1_1);
34
74
  }
75
+ finally { if (e_1) throw e_1.error; }
35
76
  }
36
77
  return true;
37
- }
38
- static createEnumSchema(object, params) {
39
- return zod_1.z.enum(Object.values(object), params);
40
- }
41
- }
42
- exports.EnumUtil = EnumUtil;
78
+ };
79
+ EnumUtil.createEnumSchema = function (object, params) {
80
+ return z.enum(Object.values(object), params);
81
+ };
82
+ return EnumUtil;
83
+ }());
84
+ export { EnumUtil };
package/dist/enums.js CHANGED
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Enums = void 0;
4
- var Enums;
1
+ export var Enums;
5
2
  (function (Enums) {
6
3
  Enums.OrderOrientation = {
7
4
  ASC: 'ASC',
@@ -52,4 +49,4 @@ var Enums;
52
49
  VERBOSE: 'verbose',
53
50
  DEBUG: 'debug',
54
51
  };
55
- })(Enums || (exports.Enums = Enums = {}));
52
+ })(Enums || (Enums = {}));