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.
- package/README.md +64 -14
- package/dist/cli/dump/db.d.ts +4 -4
- package/dist/cli/dump/db.js +25 -25
- package/dist/cli/generate/make.d.ts +4 -4
- package/dist/cli/generate/make.js +45 -45
- package/dist/cli/generate/model.d.ts +2 -2
- package/dist/cli/generate/model.js +6 -6
- package/dist/cli/index.d.ts +2 -2
- package/dist/cli/index.js +58 -58
- package/dist/cli/migrate/make.d.ts +4 -4
- package/dist/cli/migrate/make.js +30 -30
- package/dist/cli/models/make.d.ts +4 -4
- package/dist/cli/models/make.js +51 -51
- package/dist/cli/models/model.d.ts +2 -2
- package/dist/cli/models/model.js +20 -11
- package/dist/cli/query/index.d.ts +4 -4
- package/dist/cli/query/index.js +7 -7
- package/dist/cli/tables/make.d.ts +4 -4
- package/dist/cli/tables/make.js +26 -26
- package/dist/cli/tables/table.d.ts +2 -2
- package/dist/cli/tables/table.js +6 -6
- package/dist/lib/connection/index.d.ts +30 -30
- package/dist/lib/connection/index.js +144 -143
- package/dist/lib/connection/options.d.ts +15 -4
- package/dist/lib/connection/options.js +43 -42
- package/dist/lib/constants/index.d.ts +5 -8
- package/dist/lib/constants/index.js +162 -158
- package/dist/lib/index.d.ts +8 -8
- package/dist/lib/index.js +36 -36
- package/dist/lib/tspace/{AbstractDatabase.d.ts → AbstractBuilder.d.ts} +124 -116
- package/dist/lib/tspace/{AbstractDatabase.js → AbstractBuilder.js} +36 -34
- package/dist/lib/tspace/AbstractDB.d.ts +18 -18
- package/dist/lib/tspace/AbstractDB.js +11 -11
- package/dist/lib/tspace/AbstractModel.d.ts +41 -41
- package/dist/lib/tspace/AbstractModel.js +11 -11
- package/dist/lib/tspace/Blueprint.d.ts +136 -136
- package/dist/lib/tspace/Blueprint.js +228 -228
- package/dist/lib/tspace/{Database.d.ts → Builder.d.ts} +833 -706
- package/dist/lib/tspace/{Database.js → Builder.js} +2556 -2363
- package/dist/lib/tspace/DB.d.ts +152 -126
- package/dist/lib/tspace/DB.js +373 -264
- package/dist/lib/tspace/Interface.d.ts +110 -109
- package/dist/lib/tspace/Interface.js +2 -2
- package/dist/lib/tspace/Logger.d.ts +8 -8
- package/dist/lib/tspace/Logger.js +49 -49
- package/dist/lib/tspace/Model.d.ts +708 -609
- package/dist/lib/tspace/Model.js +2520 -2477
- package/dist/lib/tspace/ProxyHandler.d.ts +14 -14
- package/dist/lib/tspace/ProxyHandler.js +31 -31
- package/dist/lib/tspace/Schema.d.ts +8 -8
- package/dist/lib/tspace/Schema.js +45 -44
- package/dist/lib/tspace/index.d.ts +15 -15
- package/dist/lib/tspace/index.js +20 -20
- package/dist/lib/utils/index.d.ts +15 -15
- package/dist/lib/utils/index.js +155 -165
- 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(`
|
|
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 {
|
|
2
|
-
declare class Schema extends
|
|
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
|
|
14
|
-
class Schema extends
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
exports.
|
|
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;
|
package/dist/lib/tspace/index.js
CHANGED
|
@@ -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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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;
|
package/dist/lib/utils/index.js
CHANGED
|
@@ -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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
return
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (
|
|
125
|
-
return;
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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;
|