tspace-mysql 1.2.9 → 1.3.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.
Files changed (56) hide show
  1. package/README.md +64 -14
  2. package/dist/cli/dump/db.d.ts +4 -4
  3. package/dist/cli/dump/db.js +25 -25
  4. package/dist/cli/generate/make.d.ts +4 -4
  5. package/dist/cli/generate/make.js +45 -45
  6. package/dist/cli/generate/model.d.ts +2 -2
  7. package/dist/cli/generate/model.js +6 -6
  8. package/dist/cli/index.d.ts +2 -2
  9. package/dist/cli/index.js +58 -58
  10. package/dist/cli/migrate/make.d.ts +4 -4
  11. package/dist/cli/migrate/make.js +30 -30
  12. package/dist/cli/models/make.d.ts +4 -4
  13. package/dist/cli/models/make.js +51 -51
  14. package/dist/cli/models/model.d.ts +2 -2
  15. package/dist/cli/models/model.js +20 -11
  16. package/dist/cli/query/index.d.ts +4 -4
  17. package/dist/cli/query/index.js +7 -7
  18. package/dist/cli/tables/make.d.ts +4 -4
  19. package/dist/cli/tables/make.js +26 -26
  20. package/dist/cli/tables/table.d.ts +2 -2
  21. package/dist/cli/tables/table.js +6 -6
  22. package/dist/lib/connection/index.d.ts +30 -30
  23. package/dist/lib/connection/index.js +144 -143
  24. package/dist/lib/connection/options.d.ts +15 -4
  25. package/dist/lib/connection/options.js +43 -42
  26. package/dist/lib/constants/index.d.ts +5 -8
  27. package/dist/lib/constants/index.js +162 -158
  28. package/dist/lib/index.d.ts +8 -8
  29. package/dist/lib/index.js +36 -36
  30. package/dist/lib/tspace/{AbstractDatabase.d.ts → AbstractBuilder.d.ts} +124 -116
  31. package/dist/lib/tspace/{AbstractDatabase.js → AbstractBuilder.js} +36 -34
  32. package/dist/lib/tspace/AbstractDB.d.ts +18 -18
  33. package/dist/lib/tspace/AbstractDB.js +11 -11
  34. package/dist/lib/tspace/AbstractModel.d.ts +41 -41
  35. package/dist/lib/tspace/AbstractModel.js +11 -11
  36. package/dist/lib/tspace/Blueprint.d.ts +136 -136
  37. package/dist/lib/tspace/Blueprint.js +228 -228
  38. package/dist/lib/tspace/{Database.d.ts → Builder.d.ts} +833 -706
  39. package/dist/lib/tspace/{Database.js → Builder.js} +2556 -2363
  40. package/dist/lib/tspace/DB.d.ts +152 -126
  41. package/dist/lib/tspace/DB.js +373 -264
  42. package/dist/lib/tspace/Interface.d.ts +110 -109
  43. package/dist/lib/tspace/Interface.js +2 -2
  44. package/dist/lib/tspace/Logger.d.ts +8 -8
  45. package/dist/lib/tspace/Logger.js +49 -49
  46. package/dist/lib/tspace/Model.d.ts +708 -609
  47. package/dist/lib/tspace/Model.js +2520 -2477
  48. package/dist/lib/tspace/ProxyHandler.d.ts +14 -14
  49. package/dist/lib/tspace/ProxyHandler.js +31 -31
  50. package/dist/lib/tspace/Schema.d.ts +8 -8
  51. package/dist/lib/tspace/Schema.js +45 -44
  52. package/dist/lib/tspace/index.d.ts +15 -15
  53. package/dist/lib/tspace/index.js +20 -20
  54. package/dist/lib/utils/index.d.ts +15 -15
  55. package/dist/lib/utils/index.js +155 -165
  56. package/package.json +2 -4
@@ -1,14 +1,14 @@
1
- declare const proxyHandler: {
2
- set: (self: any, name: string, value: any) => boolean;
3
- get: (self: {
4
- [x: string]: any;
5
- $db: {
6
- get: (arg: string) => string;
7
- };
8
- $logger: {
9
- get: () => any;
10
- };
11
- }, prop: string, value: unknown) => any;
12
- };
13
- export { proxyHandler };
14
- export default proxyHandler;
1
+ declare const proxyHandler: {
2
+ set: (self: any, name: string, value: any) => boolean;
3
+ get: (self: {
4
+ [x: string]: any;
5
+ $db: {
6
+ get: (arg: string) => string;
7
+ };
8
+ $logger: {
9
+ get: () => any;
10
+ };
11
+ }, prop: string, value: unknown) => any;
12
+ };
13
+ export { proxyHandler };
14
+ export default proxyHandler;
@@ -1,31 +1,31 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.proxyHandler = void 0;
4
- const Logger_1 = require("./Logger");
5
- const proxyHandler = {
6
- set: (self, name, value) => {
7
- var _a;
8
- if ((_a = self.$setters) === null || _a === void 0 ? void 0 : _a.includes(name))
9
- throw new Error(`no allow to set this ${name}`);
10
- self.$attributes = Object.assign(Object.assign({}, self.$attributes), { [name]: value });
11
- return true;
12
- },
13
- get: (self, prop, value) => {
14
- var _a, _b, _c, _d;
15
- try {
16
- new Logger_1.Logger(self, prop);
17
- switch (prop) {
18
- case 'tableName': return (_b = (_a = self.$db) === null || _a === void 0 ? void 0 : _a.get('TABLE_NAME')) === null || _b === void 0 ? void 0 : _b.replace(/`/g, '');
19
- case 'attributes': return self[`$${prop}`];
20
- case 'logger': return (_c = self.$logger) === null || _c === void 0 ? void 0 : _c.get();
21
- case 'result': return (_d = self.$db) === null || _d === void 0 ? void 0 : _d.get('RESULT');
22
- default: return Reflect.get(self, prop, value);
23
- }
24
- }
25
- catch (e) {
26
- throw new Error(e === null || e === void 0 ? void 0 : e.message);
27
- }
28
- }
29
- };
30
- exports.proxyHandler = proxyHandler;
31
- exports.default = proxyHandler;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.proxyHandler = void 0;
4
+ const Logger_1 = require("./Logger");
5
+ const proxyHandler = {
6
+ set: (self, name, value) => {
7
+ var _a;
8
+ if ((_a = self.$setters) === null || _a === void 0 ? void 0 : _a.includes(name))
9
+ throw new Error(`No allow to set this : ${name}`);
10
+ self.$attributes = Object.assign(Object.assign({}, self.$attributes), { [name]: value });
11
+ return true;
12
+ },
13
+ get: (self, prop, value) => {
14
+ var _a, _b, _c, _d;
15
+ try {
16
+ new Logger_1.Logger(self, prop);
17
+ switch (prop) {
18
+ case 'tableName': return (_b = (_a = self.$db) === null || _a === void 0 ? void 0 : _a.get('TABLE_NAME')) === null || _b === void 0 ? void 0 : _b.replace(/`/g, '');
19
+ case 'attributes': return self[`$${prop}`];
20
+ case 'logger': return (_c = self.$logger) === null || _c === void 0 ? void 0 : _c.get();
21
+ case 'result': return (_d = self.$db) === null || _d === void 0 ? void 0 : _d.get('RESULT');
22
+ default: return Reflect.get(self, prop, value);
23
+ }
24
+ }
25
+ catch (e) {
26
+ throw new Error(e === null || e === void 0 ? void 0 : e.message);
27
+ }
28
+ }
29
+ };
30
+ exports.proxyHandler = proxyHandler;
31
+ exports.default = proxyHandler;
@@ -1,8 +1,8 @@
1
- import { Database } from "./Database";
2
- declare class Schema extends Database {
3
- table: (table: string, schemas: {
4
- [x: string]: any;
5
- }) => Promise<void>;
6
- }
7
- export { Schema };
8
- export default Schema;
1
+ import { Builder } from "./Builder";
2
+ declare class Schema extends Builder {
3
+ table: (table: string, schemas: {
4
+ [x: string]: any;
5
+ }) => Promise<void>;
6
+ }
7
+ export { Schema };
8
+ export default Schema;
@@ -1,44 +1,45 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Schema = void 0;
13
- const Database_1 = require("./Database");
14
- class Schema extends Database_1.Database {
15
- constructor() {
16
- super(...arguments);
17
- this.table = (table, schemas) => __awaiter(this, void 0, void 0, function* () {
18
- var _a;
19
- try {
20
- let columns = [];
21
- for (const key in schemas) {
22
- const data = schemas[key];
23
- const { type, attrbuites } = data;
24
- columns = [
25
- ...columns,
26
- `${key} ${type} ${attrbuites === null || attrbuites === void 0 ? void 0 : attrbuites.join(' ')}`
27
- ];
28
- }
29
- const sql = [
30
- `CREATE TABLE IF NOT EXISTS`,
31
- `${table} (${columns === null || columns === void 0 ? void 0 : columns.join(',')})`,
32
- `ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8`
33
- ].join(' ');
34
- yield this.rawQuery(sql);
35
- console.log(`Migrats : '${table}' created successfully`);
36
- }
37
- catch (err) {
38
- console.log((_a = err.message) === null || _a === void 0 ? void 0 : _a.replace(/ER_TABLE_EXISTS_ERROR:/g, ""));
39
- }
40
- });
41
- }
42
- }
43
- exports.Schema = Schema;
44
- exports.default = Schema;
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Schema = void 0;
13
+ const Builder_1 = require("./Builder");
14
+ class Schema extends Builder_1.Builder {
15
+ constructor() {
16
+ super(...arguments);
17
+ this.table = (table, schemas) => __awaiter(this, void 0, void 0, function* () {
18
+ var _a;
19
+ try {
20
+ let columns = [];
21
+ for (const key in schemas) {
22
+ const data = schemas[key];
23
+ const { type, attrbuites } = data;
24
+ columns = [
25
+ ...columns,
26
+ `${key} ${type} ${attrbuites === null || attrbuites === void 0 ? void 0 : attrbuites.join(' ')}`
27
+ ];
28
+ }
29
+ const sql = [
30
+ `CREATE TABLE IF NOT EXISTS`,
31
+ `${table} (${columns === null || columns === void 0 ? void 0 : columns.join(',')})`,
32
+ `ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8`
33
+ ].join(' ');
34
+ yield this.rawQuery(sql);
35
+ console.log(`Migrats : '${table}' created successfully`);
36
+ return;
37
+ }
38
+ catch (err) {
39
+ console.log((_a = err.message) === null || _a === void 0 ? void 0 : _a.replace(/ER_TABLE_EXISTS_ERROR:/g, ""));
40
+ }
41
+ });
42
+ }
43
+ }
44
+ exports.Schema = Schema;
45
+ exports.default = Schema;
@@ -1,15 +1,15 @@
1
- import DB from './DB';
2
- import Model from './Model';
3
- import Schema from './Schema';
4
- import Blueprint from './Blueprint';
5
- export { DB };
6
- export { Model };
7
- export { Schema };
8
- export { Blueprint };
9
- declare const _default: {
10
- DB: typeof DB;
11
- Model: typeof Model;
12
- Schema: typeof Schema;
13
- Blueprint: typeof Blueprint;
14
- };
15
- export default _default;
1
+ import DB from './DB';
2
+ import Model from './Model';
3
+ import Schema from './Schema';
4
+ import Blueprint from './Blueprint';
5
+ export { DB };
6
+ export { Model };
7
+ export { Schema };
8
+ export { Blueprint };
9
+ declare const _default: {
10
+ DB: typeof DB;
11
+ Model: typeof Model;
12
+ Schema: typeof Schema;
13
+ Blueprint: typeof Blueprint;
14
+ };
15
+ export default _default;
@@ -1,20 +1,20 @@
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.Blueprint = exports.Schema = exports.Model = exports.DB = void 0;
7
- const DB_1 = __importDefault(require("./DB"));
8
- exports.DB = DB_1.default;
9
- const Model_1 = __importDefault(require("./Model"));
10
- exports.Model = Model_1.default;
11
- const Schema_1 = __importDefault(require("./Schema"));
12
- exports.Schema = Schema_1.default;
13
- const Blueprint_1 = __importDefault(require("./Blueprint"));
14
- exports.Blueprint = Blueprint_1.default;
15
- exports.default = {
16
- DB: DB_1.default,
17
- Model: Model_1.default,
18
- Schema: Schema_1.default,
19
- Blueprint: Blueprint_1.default
20
- };
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.Blueprint = exports.Schema = exports.Model = exports.DB = void 0;
7
+ const DB_1 = __importDefault(require("./DB"));
8
+ exports.DB = DB_1.default;
9
+ const Model_1 = __importDefault(require("./Model"));
10
+ exports.Model = Model_1.default;
11
+ const Schema_1 = __importDefault(require("./Schema"));
12
+ exports.Schema = Schema_1.default;
13
+ const Blueprint_1 = __importDefault(require("./Blueprint"));
14
+ exports.Blueprint = Blueprint_1.default;
15
+ exports.default = {
16
+ DB: DB_1.default,
17
+ Model: Model_1.default,
18
+ Schema: Schema_1.default,
19
+ Blueprint: Blueprint_1.default
20
+ };
@@ -1,15 +1,15 @@
1
- declare const utils: {
2
- consoleDebug: (debug?: string) => void;
3
- faker: (value: string) => string | number | boolean;
4
- columnRelation: (name: string) => string;
5
- timestamp: () => string;
6
- date: () => string;
7
- escape: (str: any) => any;
8
- escapeSubQuery: (str: any) => any;
9
- generateUUID: () => string;
10
- covertBooleanToNumber: (data: any) => any;
11
- snakeCase: (obj: any) => any;
12
- camelCase: (obj: any) => any;
13
- };
14
- export { utils };
15
- export default utils;
1
+ declare const utils: {
2
+ consoleDebug: (debug?: string) => void;
3
+ faker: (value: string) => string | number | boolean;
4
+ columnRelation: (name: string) => string;
5
+ timestamp: () => string;
6
+ date: () => string;
7
+ escape: (str: any) => any;
8
+ generateUUID: () => string;
9
+ covertBooleanToNumber: (data: any) => any;
10
+ snakeCase: (data: any) => any;
11
+ camelCase: (data: any) => any;
12
+ randomString: (length?: number) => string;
13
+ };
14
+ export { utils };
15
+ export default utils;
@@ -1,165 +1,155 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.utils = void 0;
4
- const timestamp = () => {
5
- const d = new Date();
6
- const year = d.getFullYear();
7
- const month = `0${(d.getMonth() + 1)}`.slice(-2);
8
- const date = `0${(d.getDate())}`.slice(-2);
9
- const hours = `0${(d.getHours())}`.slice(-2);
10
- const minutes = `0${(d.getMinutes())}`.slice(-2);
11
- const seconds = `0${(d.getSeconds())}`.slice(-2);
12
- const ymd = `${[
13
- year,
14
- month,
15
- date
16
- ].join('-')}`;
17
- const his = `${[
18
- hours,
19
- minutes,
20
- seconds
21
- ].join(':')}`;
22
- return `${ymd} ${his}`;
23
- };
24
- const date = () => {
25
- const d = new Date();
26
- const year = d.getFullYear();
27
- const month = `0${(d.getMonth() + 1)}`.slice(-2);
28
- const date = `0${(d.getDate())}`.slice(-2);
29
- const now = `${year}-${month}-${date}`;
30
- return now;
31
- };
32
- const escape = (str) => {
33
- try {
34
- const check = str == null || str === true || str === false || Number.isInteger(str);
35
- if (check)
36
- return str;
37
- const regxs = ['DROP TABLE', 'UPDATE ', 'DELETE FROM ', 'OR', 'SELECT ', 'FROM ', 'WHERE ', 'OR'];
38
- for (let i in regxs) {
39
- if (str.includes(regxs[i].toLocaleLowerCase())) {
40
- str = str.split(regxs[i]).join("");
41
- }
42
- }
43
- return str;
44
- }
45
- catch (e) {
46
- return str;
47
- }
48
- };
49
- const escapeSubQuery = (str) => {
50
- const check = str == null || str === true || str === false || Number.isInteger(str);
51
- if (check)
52
- return str;
53
- const regxs = ['DROP TABLE', 'UPDATE ', 'DELETE FROM ', 'TRUNCATE'];
54
- for (let i in regxs) {
55
- if (str.includes(regxs[i])) {
56
- str = str.split(regxs[i]).join("");
57
- }
58
- }
59
- return str;
60
- };
61
- const columnRelation = (name) => {
62
- var _a;
63
- const matches = (_a = name === null || name === void 0 ? void 0 : name.match(/[A-Z]/g)) !== null && _a !== void 0 ? _a : [];
64
- if (matches.length < 1)
65
- return `${name.toLocaleLowerCase()}`;
66
- return name.replace(matches[0], `_${matches[0].toUpperCase()}`);
67
- };
68
- const generateUUID = () => {
69
- const date = +new Date();
70
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
71
- let r = Math.random() * 16;
72
- r = (date + r) % 16 | 0;
73
- return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
74
- });
75
- };
76
- const covertBooleanToNumber = (data) => {
77
- if (Object.prototype.toString.apply(data).slice(8, -1) === 'Boolean')
78
- return +data;
79
- return data;
80
- };
81
- const snakeCase = (obj) => {
82
- try {
83
- if (typeof (obj) !== "object")
84
- return obj;
85
- Object.entries(obj).forEach(([oldName, _]) => {
86
- const newName = oldName.replace(/([A-Z])/g, (str) => `_${str.toLocaleLowerCase()}`);
87
- if (newName !== oldName) {
88
- if (obj.hasOwnProperty(oldName)) {
89
- obj = Object.assign(Object.assign({}, obj), { [newName]: obj[oldName] });
90
- delete obj[oldName];
91
- }
92
- }
93
- if (typeof (obj[newName]) === "object")
94
- obj[newName] = snakeCase(obj[newName]);
95
- });
96
- return obj;
97
- }
98
- catch (e) {
99
- return obj;
100
- }
101
- };
102
- const camelCase = (obj) => {
103
- try {
104
- if (typeof (obj) !== "object")
105
- return obj;
106
- Object.entries(obj).forEach(([oldName, _]) => {
107
- const newName = oldName.replace(/(.(\_|-|\s)+.)/g, (str) => str[0] + (str[str.length - 1].toUpperCase()));
108
- if (newName !== oldName) {
109
- if (obj.hasOwnProperty(oldName)) {
110
- obj = Object.assign(Object.assign({}, obj), { [newName]: obj[oldName] });
111
- delete obj[oldName];
112
- }
113
- }
114
- if (typeof (obj[newName]) === "object")
115
- obj[newName] = camelCase(obj[newName]);
116
- });
117
- return obj;
118
- }
119
- catch (e) {
120
- return obj;
121
- }
122
- };
123
- const consoleDebug = (debug) => {
124
- if (debug == null)
125
- return;
126
- console.log(`\n\x1b[33m${debug.replace(/(\r\n|\n|\r|\t)/gm, "").trim()};\x1b[0m`);
127
- };
128
- const faker = (value) => {
129
- if (!value.search('timestamp'))
130
- return timestamp();
131
- if (!value.search('datetime'))
132
- return timestamp();
133
- if (!value.search('date'))
134
- return date();
135
- if (!value.search('tinyint'))
136
- return [true, false][Math.round(Math.random())];
137
- if (!value.search('boolean'))
138
- return [true, false][Math.round(Math.random())];
139
- if (!value.search('longtext'))
140
- return [...Array(50)].map(() => Math.random().toString(36).substring(7)).join('');
141
- if (!value.search('int'))
142
- return Math.floor(Math.random() * 1000);
143
- if (!value.search('float'))
144
- return (Math.random() * 100).toFixed(2);
145
- if (!value.search('double'))
146
- return (Math.random() * 100).toFixed(2);
147
- if (!value.search('varchar'))
148
- return Buffer.from(Math.random().toString(36).substring(7)).toString('base64');
149
- return 'fake data';
150
- };
151
- const utils = {
152
- consoleDebug,
153
- faker,
154
- columnRelation,
155
- timestamp,
156
- date,
157
- escape,
158
- escapeSubQuery,
159
- generateUUID,
160
- covertBooleanToNumber,
161
- snakeCase,
162
- camelCase
163
- };
164
- exports.utils = utils;
165
- exports.default = utils;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.utils = void 0;
4
+ const timestamp = () => {
5
+ const d = new Date();
6
+ const year = d.getFullYear();
7
+ const month = `0${(d.getMonth() + 1)}`.slice(-2);
8
+ const date = `0${(d.getDate())}`.slice(-2);
9
+ const hours = `0${(d.getHours())}`.slice(-2);
10
+ const minutes = `0${(d.getMinutes())}`.slice(-2);
11
+ const seconds = `0${(d.getSeconds())}`.slice(-2);
12
+ const ymd = `${[
13
+ year,
14
+ month,
15
+ date
16
+ ].join('-')}`;
17
+ const his = `${[
18
+ hours,
19
+ minutes,
20
+ seconds
21
+ ].join(':')}`;
22
+ return `${ymd} ${his}`;
23
+ };
24
+ const date = () => {
25
+ const d = new Date();
26
+ const year = d.getFullYear();
27
+ const month = `0${(d.getMonth() + 1)}`.slice(-2);
28
+ const date = `0${(d.getDate())}`.slice(-2);
29
+ const now = `${year}-${month}-${date}`;
30
+ return now;
31
+ };
32
+ const escape = (str) => {
33
+ if (typeof str !== 'string')
34
+ return str;
35
+ return str.replace(/[\0\b\t\n\r\x1a\'\\]/g, '');
36
+ };
37
+ const columnRelation = (name) => {
38
+ var _a;
39
+ const matches = (_a = name === null || name === void 0 ? void 0 : name.match(/[A-Z]/g)) !== null && _a !== void 0 ? _a : [];
40
+ if (matches.length < 1)
41
+ return `${name.toLocaleLowerCase()}`;
42
+ return name.replace(matches[0], `_${matches[0].toUpperCase()}`);
43
+ };
44
+ const generateUUID = () => {
45
+ const date = +new Date();
46
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
47
+ let r = Math.random() * 16;
48
+ r = (date + r) % 16 | 0;
49
+ return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
50
+ });
51
+ };
52
+ const covertBooleanToNumber = (data) => {
53
+ if (Object.prototype.toString.apply(data).slice(8, -1) === 'Boolean')
54
+ return +data;
55
+ return data;
56
+ };
57
+ const snakeCase = (data) => {
58
+ try {
59
+ if (typeof (data) !== "object")
60
+ return data;
61
+ Object.entries(data).forEach(([oldName, _]) => {
62
+ const newName = oldName.replace(/([A-Z])/g, (str) => `_${str.toLocaleLowerCase()}`);
63
+ if (newName !== oldName) {
64
+ if (data.hasOwnProperty(oldName)) {
65
+ data = Object.assign(Object.assign({}, data), { [newName]: data[oldName] });
66
+ delete data[oldName];
67
+ }
68
+ }
69
+ if (typeof (data[newName]) === "object")
70
+ data[newName] = snakeCase(data[newName]);
71
+ });
72
+ return data;
73
+ }
74
+ catch (e) {
75
+ return data;
76
+ }
77
+ };
78
+ const camelCase = (data) => {
79
+ try {
80
+ if (typeof (data) !== "object")
81
+ return data;
82
+ Object.entries(data).forEach(([oldName]) => {
83
+ const newName = oldName.replace(/(.(\_|-|\s)+.)/g, (str) => str[0] + (str[str.length - 1].toUpperCase()));
84
+ if (newName !== oldName) {
85
+ if (data.hasOwnProperty(oldName)) {
86
+ data = Object.assign(Object.assign({}, data), { [newName]: data[oldName] });
87
+ delete data[oldName];
88
+ }
89
+ }
90
+ if (typeof (data[newName]) === "object")
91
+ data[newName] = camelCase(data[newName]);
92
+ });
93
+ return data;
94
+ }
95
+ catch (e) {
96
+ return data;
97
+ }
98
+ };
99
+ const consoleDebug = (debug) => {
100
+ if (debug == null)
101
+ return;
102
+ console.log(`\n\x1b[33m${debug.replace(/(\r\n|\n|\r|\t)/gm, "").trim()};\x1b[0m`);
103
+ };
104
+ const randomString = (length = 100) => {
105
+ let str = '';
106
+ const salt = 3;
107
+ for (let i = 0; i < length / salt; i++) {
108
+ str += Math.random().toString(36).substring(salt);
109
+ }
110
+ return str.slice(-length).toLocaleLowerCase().replace(/'/g, 'g');
111
+ };
112
+ const faker = (value) => {
113
+ var _a, _b;
114
+ if (!value.search('timestamp'))
115
+ return timestamp();
116
+ if (!value.search('datetime'))
117
+ return timestamp();
118
+ if (!value.search('date'))
119
+ return date();
120
+ if (!value.search('tinyint'))
121
+ return [true, false][Math.round(Math.random())];
122
+ if (!value.search('boolean'))
123
+ return [true, false][Math.round(Math.random())];
124
+ if (!value.search('longtext'))
125
+ return randomString(500);
126
+ if (!value.search('text'))
127
+ return randomString(500);
128
+ if (!value.search('int'))
129
+ return Number(Math.floor(Math.random() * 1000));
130
+ if (!value.search('float'))
131
+ return Number((Math.random() * 100).toFixed(2));
132
+ if (!value.search('double'))
133
+ return Number((Math.random() * 100).toFixed(2));
134
+ if (!value.search('varchar')) {
135
+ const regex = /\d+/g;
136
+ const limit = Number((_b = (_a = value === null || value === void 0 ? void 0 : value.match(regex)) === null || _a === void 0 ? void 0 : _a.pop()) !== null && _b !== void 0 ? _b : 255);
137
+ return randomString(limit);
138
+ }
139
+ return 'fake data';
140
+ };
141
+ const utils = {
142
+ consoleDebug,
143
+ faker,
144
+ columnRelation,
145
+ timestamp,
146
+ date,
147
+ escape,
148
+ generateUUID,
149
+ covertBooleanToNumber,
150
+ snakeCase,
151
+ camelCase,
152
+ randomString
153
+ };
154
+ exports.utils = utils;
155
+ exports.default = utils;