fiberx-backend-toolkit 0.0.33 → 0.0.35
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/dist/types/main.d.ts +1 -0
- package/dist/types/main.js +1 -0
- package/dist/types/module_type.d.ts +12 -0
- package/dist/types/module_type.js +2 -0
- package/dist/types/util_type.d.ts +5 -0
- package/dist/utils/main.d.ts +2 -1
- package/dist/utils/main.js +3 -1
- package/dist/utils/uuid_gen_util.d.ts +10 -0
- package/dist/utils/uuid_gen_util.js +54 -0
- package/package.json +1 -1
package/dist/types/main.d.ts
CHANGED
package/dist/types/main.js
CHANGED
|
@@ -30,6 +30,11 @@ export interface EnvVarConfigOptions {
|
|
|
30
30
|
staging_file_name?: string;
|
|
31
31
|
production_file_name?: string;
|
|
32
32
|
}
|
|
33
|
+
export interface FileObjectInterface {
|
|
34
|
+
mimetype: string;
|
|
35
|
+
size: number;
|
|
36
|
+
name: string;
|
|
37
|
+
}
|
|
33
38
|
export interface ServerErrorInterface extends Error {
|
|
34
39
|
syscall?: string;
|
|
35
40
|
code?: string;
|
package/dist/utils/main.d.ts
CHANGED
|
@@ -6,4 +6,5 @@ import SqlFormatterUtil from "./sql_formatter_util";
|
|
|
6
6
|
import ServerUtil from "./server_util";
|
|
7
7
|
import SafeExecuteUtil from "./safe_execute_util";
|
|
8
8
|
import InMemoryCache from "./cache_util";
|
|
9
|
-
|
|
9
|
+
import UUIDGeneratorUtil from "./uuid_gen_util";
|
|
10
|
+
export { LoggerUtil, InputTransformerUtil, InputValidatorUtil, EnvManagerUtil, SqlFormatterUtil, ServerUtil, SafeExecuteUtil, InMemoryCache, UUIDGeneratorUtil };
|
package/dist/utils/main.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.InMemoryCache = exports.SafeExecuteUtil = exports.ServerUtil = exports.SqlFormatterUtil = exports.EnvManagerUtil = exports.InputValidatorUtil = exports.InputTransformerUtil = exports.LoggerUtil = void 0;
|
|
6
|
+
exports.UUIDGeneratorUtil = exports.InMemoryCache = exports.SafeExecuteUtil = exports.ServerUtil = exports.SqlFormatterUtil = exports.EnvManagerUtil = exports.InputValidatorUtil = exports.InputTransformerUtil = exports.LoggerUtil = void 0;
|
|
7
7
|
const logger_util_1 = __importDefault(require("./logger_util"));
|
|
8
8
|
exports.LoggerUtil = logger_util_1.default;
|
|
9
9
|
const input_transformer_util_1 = __importDefault(require("./input_transformer_util"));
|
|
@@ -20,3 +20,5 @@ const safe_execute_util_1 = __importDefault(require("./safe_execute_util"));
|
|
|
20
20
|
exports.SafeExecuteUtil = safe_execute_util_1.default;
|
|
21
21
|
const cache_util_1 = __importDefault(require("./cache_util"));
|
|
22
22
|
exports.InMemoryCache = cache_util_1.default;
|
|
23
|
+
const uuid_gen_util_1 = __importDefault(require("./uuid_gen_util"));
|
|
24
|
+
exports.UUIDGeneratorUtil = uuid_gen_util_1.default;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { FileObjectInterface } from "../types/util_type";
|
|
2
|
+
declare class UUIDGeneratorUtil {
|
|
3
|
+
static generateUUIDV1(): string;
|
|
4
|
+
static generateUUIDV2(prefix?: string): string;
|
|
5
|
+
static generateUUIDV3(): string;
|
|
6
|
+
static generateUUIDV4(prefix?: string): string;
|
|
7
|
+
static generateNewFileName(file: FileObjectInterface): string;
|
|
8
|
+
static generateRandomPassword(min_length?: number): string;
|
|
9
|
+
}
|
|
10
|
+
export default UUIDGeneratorUtil;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const crypto_1 = require("crypto");
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
5
|
+
class UUIDGeneratorUtil {
|
|
6
|
+
// Method to Generate a standard UUID (Version 4) following RFC 4122.
|
|
7
|
+
static generateUUIDV1() { return (0, crypto_1.randomUUID)(); }
|
|
8
|
+
// Method to Generate a unique code based on the current timestamp and random characters.
|
|
9
|
+
static generateUUIDV2(prefix = "") {
|
|
10
|
+
const timestamp = Date.now().toString();
|
|
11
|
+
const time_stamp_part = parseInt(timestamp, 10).toString(36);
|
|
12
|
+
const random_part = Math.random().toString(36).substring(2, 6);
|
|
13
|
+
const unique_code = `${prefix.toUpperCase()}-${time_stamp_part}${random_part}`.toLowerCase();
|
|
14
|
+
return unique_code;
|
|
15
|
+
}
|
|
16
|
+
// Method to Generate a shorter unique code without hyphens: purely timestamp + random.
|
|
17
|
+
static generateUUIDV3() {
|
|
18
|
+
const timestamp = Date.now().toString();
|
|
19
|
+
const time_stamp_part = parseInt(timestamp, 10).toString(36);
|
|
20
|
+
const random_part = Math.random().toString(36).substring(2, 6);
|
|
21
|
+
return `${time_stamp_part}${random_part}`.toUpperCase();
|
|
22
|
+
}
|
|
23
|
+
// Method to Generate a random byte string with optional prefix.
|
|
24
|
+
static generateUUIDV4(prefix = "") { return `${prefix}_${(0, uuid_1.v4)()}`; }
|
|
25
|
+
// Method to Generate a new file name with a unique UUID
|
|
26
|
+
static generateNewFileName(file) {
|
|
27
|
+
const split = file.name.split(".");
|
|
28
|
+
const ext = split[split.length - 1];
|
|
29
|
+
const unique_name = this.generateUUIDV2("FILE");
|
|
30
|
+
return `${unique_name}.${ext}`;
|
|
31
|
+
}
|
|
32
|
+
static generateRandomPassword(min_length = 8) {
|
|
33
|
+
const length = Math.max(min_length, 6);
|
|
34
|
+
const lower_case = "abcdefghijklmnopqrstuvwxyz";
|
|
35
|
+
const upper_case = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
36
|
+
const digits = "0123456789";
|
|
37
|
+
const symbols = "!@#$%^&*()-_=+[]{};:,.<>?";
|
|
38
|
+
const all_chars = lower_case + upper_case + digits + symbols;
|
|
39
|
+
const randomChar = (set) => set[(0, crypto_1.randomInt)(0, set.length)];
|
|
40
|
+
let password = "";
|
|
41
|
+
password += randomChar(lower_case);
|
|
42
|
+
password += randomChar(upper_case);
|
|
43
|
+
password += randomChar(digits);
|
|
44
|
+
password += randomChar(symbols);
|
|
45
|
+
while (password.length < length) {
|
|
46
|
+
password += randomChar(all_chars);
|
|
47
|
+
}
|
|
48
|
+
return password
|
|
49
|
+
.split("")
|
|
50
|
+
.sort(() => (0, crypto_1.randomInt)(-1, 2))
|
|
51
|
+
.join("");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.default = UUIDGeneratorUtil;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fiberx-backend-toolkit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.35",
|
|
4
4
|
"description": "A TypeScript backend toolkit providing shared domain logic, infrastructure helpers, and utilities for FiberX server-side applications and services.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./dist/index.js",
|