badmfck-api-server 1.7.3 → 1.7.5
Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,14 @@
|
|
1
|
+
export declare class UID {
|
2
|
+
private static readonly epoch;
|
3
|
+
private static nextUniqueID;
|
4
|
+
private static nextUniqueTRXID;
|
5
|
+
static generate(): string;
|
6
|
+
static generateRandomNumberBase(count: number): string;
|
7
|
+
static generateNumberic(year?: string): number;
|
8
|
+
static getNextDescendingIndex(): number;
|
9
|
+
static getNext(): string;
|
10
|
+
static getNextTRX(): string;
|
11
|
+
static generateTrxUID(date?: Date): number;
|
12
|
+
static sha256(str: string): string;
|
13
|
+
static leadZero(i: number): string;
|
14
|
+
}
|
@@ -0,0 +1,73 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.UID = void 0;
|
7
|
+
const crypto_1 = __importDefault(require("crypto"));
|
8
|
+
class UID {
|
9
|
+
static epoch = 1697037922668;
|
10
|
+
static nextUniqueID = 1;
|
11
|
+
static nextUniqueTRXID = 1;
|
12
|
+
static generate() {
|
13
|
+
let uid = Buffer.from(parseInt(((+new Date()) - this.epoch)
|
14
|
+
+ ""
|
15
|
+
+ Math.round(Math.random() * 1000)).toString(16), 'hex').toString('base64');
|
16
|
+
uid = uid.replaceAll("=", "");
|
17
|
+
uid = uid.replaceAll("+", ".");
|
18
|
+
uid = uid.replaceAll("/", "-");
|
19
|
+
return uid;
|
20
|
+
}
|
21
|
+
static generateRandomNumberBase(count) {
|
22
|
+
let base = "";
|
23
|
+
for (let i = 0; i < count; i++)
|
24
|
+
base += Math.round(Math.random() * 9);
|
25
|
+
return base;
|
26
|
+
}
|
27
|
+
static generateNumberic(year) {
|
28
|
+
if (!year)
|
29
|
+
year = new Date().getFullYear() + "";
|
30
|
+
const nextID = UID.nextUniqueID++;
|
31
|
+
if (UID.nextUniqueID > 99)
|
32
|
+
UID.nextUniqueID = 1;
|
33
|
+
return parseInt(year.substring(2) + "" + (+new Date() - this.epoch) + "" + (nextID + "").padStart(2, "0"));
|
34
|
+
}
|
35
|
+
static getNextDescendingIndex() {
|
36
|
+
return Number.MAX_SAFE_INTEGER - (+new Date());
|
37
|
+
}
|
38
|
+
static getNext() {
|
39
|
+
const nextID = UID.nextUniqueID++;
|
40
|
+
if (UID.nextUniqueID > 99)
|
41
|
+
UID.nextUniqueID = 1;
|
42
|
+
return this.leadZero(nextID);
|
43
|
+
}
|
44
|
+
static getNextTRX() {
|
45
|
+
const nextID = UID.nextUniqueTRXID++;
|
46
|
+
if (UID.nextUniqueTRXID > 99)
|
47
|
+
UID.nextUniqueTRXID = 1;
|
48
|
+
return this.leadZero(nextID);
|
49
|
+
}
|
50
|
+
static generateTrxUID(date) {
|
51
|
+
if (!date)
|
52
|
+
date = new Date();
|
53
|
+
const year = (new Date().getFullYear() + "").substring(2);
|
54
|
+
const seconds = (date.getHours() * 3600 + date.getMinutes() * 60 + date.getSeconds()) + "";
|
55
|
+
const str = year
|
56
|
+
+ this.leadZero(date.getMonth() + 1)
|
57
|
+
+ this.leadZero(date.getDate())
|
58
|
+
+ seconds.padStart(5, "0")
|
59
|
+
+ this.getNextTRX();
|
60
|
+
return parseInt(str);
|
61
|
+
}
|
62
|
+
static sha256(str) {
|
63
|
+
let uid = crypto_1.default.createHash("sha256").update(str).digest("base64");
|
64
|
+
uid = uid.replaceAll("=", "");
|
65
|
+
uid = uid.replaceAll("+", ".");
|
66
|
+
uid = uid.replaceAll("/", "-");
|
67
|
+
return uid;
|
68
|
+
}
|
69
|
+
static leadZero(i) {
|
70
|
+
return (i + "").padStart(2, "0");
|
71
|
+
}
|
72
|
+
}
|
73
|
+
exports.UID = UID;
|
@@ -4,5 +4,8 @@ declare class DefaultErrors {
|
|
4
4
|
static UNKNOWN_REQUEST: IError;
|
5
5
|
static JSON_MALFORMED: IError;
|
6
6
|
}
|
7
|
-
export declare
|
7
|
+
export declare class ErrorUtils {
|
8
|
+
static isError(obj: any): boolean;
|
9
|
+
static appendStack(error: IError, stack?: IError[]): IError;
|
10
|
+
}
|
8
11
|
export default DefaultErrors;
|
@@ -1,21 +1,27 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.ErrorUtils = void 0;
|
4
4
|
const Validator_1 = require("../helper/Validator");
|
5
5
|
class DefaultErrors {
|
6
6
|
static NOT_IMPLEMENTED = { code: 1, message: "Not implemented" };
|
7
7
|
static UNKNOWN_REQUEST = { code: 2, message: "Unknown request" };
|
8
8
|
static JSON_MALFORMED = { code: 3, message: "JSON malformed" };
|
9
9
|
}
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
10
|
+
class ErrorUtils {
|
11
|
+
static isError(obj) {
|
12
|
+
const isFieldsExists = Validator_1.Validator.validateObject(['code', 'message'], obj);
|
13
|
+
if (!isFieldsExists)
|
14
|
+
return false;
|
15
|
+
if (Validator_1.Validator.validateValue("code", { type: "number" }) !== Validator_1.ValidationReport.OK)
|
16
|
+
return false;
|
17
|
+
if (Validator_1.Validator.validateValue("message", { type: "string" }) !== Validator_1.ValidationReport.OK)
|
18
|
+
return false;
|
19
|
+
return true;
|
20
|
+
}
|
21
|
+
static appendStack(error, stack) {
|
22
|
+
error.stack = stack;
|
23
|
+
return error;
|
24
|
+
}
|
25
|
+
}
|
26
|
+
exports.ErrorUtils = ErrorUtils;
|
21
27
|
exports.default = DefaultErrors;
|
package/dist/index.d.ts
CHANGED
@@ -3,6 +3,8 @@ import { LocalRequest } from "./apiServer/LocalRequest";
|
|
3
3
|
import { MysqlService } from "./apiServer/MysqlService";
|
4
4
|
import { Validator } from "./apiServer/helper/Validator";
|
5
5
|
import { LogService } from "./apiServer/LogService";
|
6
|
+
import { ErrorUtils } from "./apiServer/structures/DefaultErrors";
|
6
7
|
import { S_MONITOR_REGISTRATE_ACTION } from "./apiServer/monitor/Monitor";
|
7
8
|
import { DataProvider } from "./apiServer/helper/DataProvider";
|
8
|
-
|
9
|
+
import { UID } from "./apiServer/helper/UID";
|
10
|
+
export { UID, APIService, Initializer, LocalRequest, MysqlService, Validator, LogService, DataProvider, ErrorUtils, S_MONITOR_REGISTRATE_ACTION };
|
package/dist/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.S_MONITOR_REGISTRATE_ACTION = exports.DataProvider = exports.LogService = exports.Validator = exports.MysqlService = exports.LocalRequest = exports.Initializer = exports.APIService = void 0;
|
3
|
+
exports.S_MONITOR_REGISTRATE_ACTION = exports.ErrorUtils = exports.DataProvider = exports.LogService = exports.Validator = exports.MysqlService = exports.LocalRequest = exports.Initializer = exports.APIService = exports.UID = void 0;
|
4
4
|
const APIService_1 = require("./apiServer/APIService");
|
5
5
|
Object.defineProperty(exports, "APIService", { enumerable: true, get: function () { return APIService_1.APIService; } });
|
6
6
|
Object.defineProperty(exports, "Initializer", { enumerable: true, get: function () { return APIService_1.Initializer; } });
|
@@ -12,7 +12,11 @@ const Validator_1 = require("./apiServer/helper/Validator");
|
|
12
12
|
Object.defineProperty(exports, "Validator", { enumerable: true, get: function () { return Validator_1.Validator; } });
|
13
13
|
const LogService_1 = require("./apiServer/LogService");
|
14
14
|
Object.defineProperty(exports, "LogService", { enumerable: true, get: function () { return LogService_1.LogService; } });
|
15
|
+
const DefaultErrors_1 = require("./apiServer/structures/DefaultErrors");
|
16
|
+
Object.defineProperty(exports, "ErrorUtils", { enumerable: true, get: function () { return DefaultErrors_1.ErrorUtils; } });
|
15
17
|
const Monitor_1 = require("./apiServer/monitor/Monitor");
|
16
18
|
Object.defineProperty(exports, "S_MONITOR_REGISTRATE_ACTION", { enumerable: true, get: function () { return Monitor_1.S_MONITOR_REGISTRATE_ACTION; } });
|
17
19
|
const DataProvider_1 = require("./apiServer/helper/DataProvider");
|
18
20
|
Object.defineProperty(exports, "DataProvider", { enumerable: true, get: function () { return DataProvider_1.DataProvider; } });
|
21
|
+
const UID_1 = require("./apiServer/helper/UID");
|
22
|
+
Object.defineProperty(exports, "UID", { enumerable: true, get: function () { return UID_1.UID; } });
|