tspace-mysql 1.4.7 → 1.4.9
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 +128 -49
- package/dist/lib/{tspace/Interface.d.ts → Interface.d.ts} +18 -2
- package/dist/lib/connection/index.d.ts +1 -1
- package/dist/lib/constants/index.js +3 -3
- package/dist/lib/tspace/{Abstract → Abstracts}/AbstractBuilder.d.ts +3 -3
- package/dist/lib/tspace/{Abstract → Abstracts}/AbstractBuilder.js +2 -2
- package/dist/lib/tspace/{Abstract → Abstracts}/AbstractDB.d.ts +8 -2
- package/dist/lib/tspace/{Abstract → Abstracts}/AbstractModel.d.ts +22 -2
- package/dist/lib/tspace/Blueprint.d.ts +19 -5
- package/dist/lib/tspace/Blueprint.js +41 -19
- package/dist/lib/tspace/Builder.d.ts +26 -11
- package/dist/lib/tspace/Builder.js +378 -330
- package/dist/lib/tspace/DB.d.ts +42 -2
- package/dist/lib/tspace/DB.js +61 -5
- package/dist/lib/tspace/Decorator.d.ts +20 -0
- package/dist/lib/tspace/Decorator.js +166 -0
- package/dist/lib/tspace/{ProxyHandler.js → Handlers/Proxy.js} +1 -1
- package/dist/lib/tspace/{RelationHandler.d.ts → Handlers/Relation.d.ts} +4 -4
- package/dist/lib/tspace/{RelationHandler.js → Handlers/Relation.js} +103 -28
- package/dist/lib/tspace/{StateHandler.js → Handlers/State.js} +3 -2
- package/dist/lib/tspace/Model.d.ts +275 -11
- package/dist/lib/tspace/Model.js +989 -99
- package/dist/lib/tspace/Schema.js +5 -8
- package/dist/lib/tspace/index.d.ts +4 -0
- package/dist/lib/tspace/index.js +20 -2
- package/dist/lib/utils/index.d.ts +1 -0
- package/dist/lib/utils/index.js +9 -0
- package/dist/tests/01-Pool.test.d.ts +1 -0
- package/dist/tests/01-Pool.test.js +45 -0
- package/dist/tests/02-DB.test.d.ts +1 -0
- package/dist/tests/02-DB.test.js +109 -0
- package/dist/tests/03-Model.test.d.ts +1 -0
- package/dist/tests/03-Model.test.js +73 -0
- package/package.json +14 -3
- /package/dist/lib/{tspace/Interface.js → Interface.js} +0 -0
- /package/dist/lib/tspace/{Abstract → Abstracts}/AbstractDB.js +0 -0
- /package/dist/lib/tspace/{Abstract → Abstracts}/AbstractModel.js +0 -0
- /package/dist/lib/tspace/{ProxyHandler.d.ts → Handlers/Proxy.d.ts} +0 -0
- /package/dist/lib/tspace/{StateHandler.d.ts → Handlers/State.d.ts} +0 -0
|
@@ -55,9 +55,9 @@ class Schema extends Builder_1.Builder {
|
|
|
55
55
|
];
|
|
56
56
|
}
|
|
57
57
|
const sql = [
|
|
58
|
-
|
|
58
|
+
`${this.$constants('CREATE_TABLE_NOT_EXISTS')}`,
|
|
59
59
|
`${table} (${columns === null || columns === void 0 ? void 0 : columns.join(',')})`,
|
|
60
|
-
|
|
60
|
+
`${this.$constants('ENGINE')}`
|
|
61
61
|
].join(' ');
|
|
62
62
|
yield this.query(sql);
|
|
63
63
|
console.log(`Migrats : '${table}' created successfully`);
|
|
@@ -78,9 +78,9 @@ class Schema extends Builder_1.Builder {
|
|
|
78
78
|
];
|
|
79
79
|
}
|
|
80
80
|
const sql = [
|
|
81
|
-
|
|
81
|
+
`${this.$constants('CREATE_TABLE_NOT_EXISTS')}`,
|
|
82
82
|
`${table} (${columns === null || columns === void 0 ? void 0 : columns.join(', ')})`,
|
|
83
|
-
|
|
83
|
+
`${this.$constants('ENGINE')}`
|
|
84
84
|
].join(' ');
|
|
85
85
|
return sql;
|
|
86
86
|
};
|
|
@@ -175,7 +175,6 @@ class Schema extends Builder_1.Builder {
|
|
|
175
175
|
return __awaiter(this, void 0, void 0, function* () {
|
|
176
176
|
const checkTables = yield new Builder_1.Builder().query('SHOW TABLES');
|
|
177
177
|
const existsTables = checkTables.map((c) => Object.values(c)[0]);
|
|
178
|
-
// console.log(checkTables)
|
|
179
178
|
for (const model of models) {
|
|
180
179
|
if (model == null)
|
|
181
180
|
continue;
|
|
@@ -256,10 +255,8 @@ class Schema extends Builder_1.Builder {
|
|
|
256
255
|
yield new Builder_1.Builder().debug(log).query(sql);
|
|
257
256
|
}
|
|
258
257
|
catch (e) {
|
|
259
|
-
if (typeof foreign.on === "string")
|
|
260
|
-
console.log(e);
|
|
258
|
+
if (typeof foreign.on === "string")
|
|
261
259
|
continue;
|
|
262
|
-
}
|
|
263
260
|
if (String(e.message).includes("Duplicate foreign key constraint"))
|
|
264
261
|
continue;
|
|
265
262
|
const schemaModelOn = yield foreign.on.getSchemaModel();
|
|
@@ -2,14 +2,18 @@ import DB from './DB';
|
|
|
2
2
|
import Model from './Model';
|
|
3
3
|
import Schema from './Schema';
|
|
4
4
|
import Blueprint from './Blueprint';
|
|
5
|
+
import Pool from '../connection';
|
|
5
6
|
export { DB };
|
|
6
7
|
export { Model };
|
|
7
8
|
export { Schema };
|
|
8
9
|
export { Blueprint };
|
|
10
|
+
export { Pool };
|
|
11
|
+
export * from './Decorator';
|
|
9
12
|
declare const _default: {
|
|
10
13
|
DB: typeof DB;
|
|
11
14
|
Model: typeof Model;
|
|
12
15
|
Schema: typeof Schema;
|
|
13
16
|
Blueprint: typeof Blueprint;
|
|
17
|
+
Pool: import("../Interface").Connection;
|
|
14
18
|
};
|
|
15
19
|
export default _default;
|
package/dist/lib/tspace/index.js
CHANGED
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
18
|
};
|
|
5
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Blueprint = exports.Schema = exports.Model = exports.DB = void 0;
|
|
20
|
+
exports.Pool = exports.Blueprint = exports.Schema = exports.Model = exports.DB = void 0;
|
|
7
21
|
const DB_1 = __importDefault(require("./DB"));
|
|
8
22
|
exports.DB = DB_1.default;
|
|
9
23
|
const Model_1 = __importDefault(require("./Model"));
|
|
@@ -12,9 +26,13 @@ const Schema_1 = __importDefault(require("./Schema"));
|
|
|
12
26
|
exports.Schema = Schema_1.default;
|
|
13
27
|
const Blueprint_1 = __importDefault(require("./Blueprint"));
|
|
14
28
|
exports.Blueprint = Blueprint_1.default;
|
|
29
|
+
const connection_1 = __importDefault(require("../connection"));
|
|
30
|
+
exports.Pool = connection_1.default;
|
|
31
|
+
__exportStar(require("./Decorator"), exports);
|
|
15
32
|
exports.default = {
|
|
16
33
|
DB: DB_1.default,
|
|
17
34
|
Model: Model_1.default,
|
|
18
35
|
Schema: Schema_1.default,
|
|
19
|
-
Blueprint: Blueprint_1.default
|
|
36
|
+
Blueprint: Blueprint_1.default,
|
|
37
|
+
Pool: connection_1.default
|
|
20
38
|
};
|
|
@@ -7,6 +7,7 @@ declare const utils: {
|
|
|
7
7
|
timestamp: (dateString?: string) => string;
|
|
8
8
|
date: () => string;
|
|
9
9
|
escape: (str: any) => any;
|
|
10
|
+
escapeXSS: (str: any) => any;
|
|
10
11
|
isSubQuery: (subQuery: string) => boolean;
|
|
11
12
|
generateUUID: () => string;
|
|
12
13
|
covertBooleanToNumber: (data: any) => any;
|
package/dist/lib/utils/index.js
CHANGED
|
@@ -49,6 +49,13 @@ const escape = (str) => {
|
|
|
49
49
|
return str;
|
|
50
50
|
return str.replace(/[\0\b\t\n\r\x1a\'\\]/g, '');
|
|
51
51
|
};
|
|
52
|
+
const escapeXSS = (str) => {
|
|
53
|
+
if (typeof str !== 'string')
|
|
54
|
+
return str;
|
|
55
|
+
return str
|
|
56
|
+
.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '')
|
|
57
|
+
.replace(/on\w+="[^"]+"/g, '');
|
|
58
|
+
};
|
|
52
59
|
const isSubQuery = (subQuery) => {
|
|
53
60
|
const checkIsSubQuery = (/\bSELECT\s+(?!\*)/i.test(subQuery));
|
|
54
61
|
if (!checkIsSubQuery)
|
|
@@ -149,6 +156,7 @@ const randomString = (length = 100) => {
|
|
|
149
156
|
};
|
|
150
157
|
const faker = (value) => {
|
|
151
158
|
var _a, _b;
|
|
159
|
+
value = value.toLocaleLowerCase();
|
|
152
160
|
if (!value.search('timestamp'))
|
|
153
161
|
return timestamp();
|
|
154
162
|
if (!value.search('datetime'))
|
|
@@ -196,6 +204,7 @@ const utils = {
|
|
|
196
204
|
timestamp,
|
|
197
205
|
date,
|
|
198
206
|
escape,
|
|
207
|
+
escapeXSS,
|
|
199
208
|
isSubQuery,
|
|
200
209
|
generateUUID,
|
|
201
210
|
covertBooleanToNumber,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +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
|
+
const chai_1 = require("chai");
|
|
13
|
+
const mocha_1 = require("mocha");
|
|
14
|
+
const lib_1 = require("../lib");
|
|
15
|
+
(0, mocha_1.describe)('Testing Pool', function () {
|
|
16
|
+
/* ##################################################### */
|
|
17
|
+
(0, mocha_1.it)('Pool: It is can doing ?', function () {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
(0, chai_1.expect)(lib_1.Pool).to.have.an('object');
|
|
20
|
+
(0, chai_1.expect)(lib_1.Pool).to.have.property('query');
|
|
21
|
+
(0, chai_1.expect)(lib_1.Pool).to.have.property('connection');
|
|
22
|
+
(0, chai_1.expect)(lib_1.Pool.connection).to.be.a('function');
|
|
23
|
+
(0, chai_1.expect)(lib_1.Pool.query).to.be.a('function');
|
|
24
|
+
const query = yield lib_1.Pool.query('SELECT 1 as ping');
|
|
25
|
+
(0, chai_1.expect)(query).to.be.an('array');
|
|
26
|
+
(0, chai_1.expect)(query.length).to.be.equal(1);
|
|
27
|
+
(0, chai_1.expect)(query[0].ping).to.be.equal(1);
|
|
28
|
+
const connect = yield lib_1.Pool.connection();
|
|
29
|
+
(0, chai_1.expect)(connect).to.be.an('object');
|
|
30
|
+
(0, chai_1.expect)(connect).to.have.property('query');
|
|
31
|
+
(0, chai_1.expect)(connect).to.have.property('startTransaction');
|
|
32
|
+
(0, chai_1.expect)(connect).to.have.property('commit');
|
|
33
|
+
(0, chai_1.expect)(connect).to.have.property('rollback');
|
|
34
|
+
(0, chai_1.expect)(connect.startTransaction).to.be.a('function');
|
|
35
|
+
(0, chai_1.expect)(connect.commit).to.be.a('function');
|
|
36
|
+
(0, chai_1.expect)(connect.rollback).to.be.a('function');
|
|
37
|
+
(0, chai_1.expect)(connect.query).to.be.an('function');
|
|
38
|
+
const connectQuery = yield connect.query('SELECT 1 as ping');
|
|
39
|
+
(0, chai_1.expect)(connectQuery).to.be.an('array');
|
|
40
|
+
(0, chai_1.expect)(connectQuery.length).to.be.equal(1);
|
|
41
|
+
(0, chai_1.expect)(connectQuery[0].ping).to.be.equal(1);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
/* ###################################################### */
|
|
45
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
const chai_1 = __importStar(require("chai"));
|
|
39
|
+
const mocha_1 = require("mocha");
|
|
40
|
+
const chai_json_schema_1 = __importDefault(require("chai-json-schema"));
|
|
41
|
+
const lib_1 = require("../lib");
|
|
42
|
+
chai_1.default.use(chai_json_schema_1.default);
|
|
43
|
+
(0, mocha_1.describe)('Testing DB', function () {
|
|
44
|
+
/* ##################################################### */
|
|
45
|
+
(0, mocha_1.it)(`DB: await new DB('users').get()
|
|
46
|
+
It should return an array and must have all user schema attributes`, function () {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
const results = yield new lib_1.DB('users').get();
|
|
49
|
+
(0, chai_1.expect)(results).to.be.an('array');
|
|
50
|
+
const usersSchema = {
|
|
51
|
+
type: 'array',
|
|
52
|
+
items: {
|
|
53
|
+
type: 'object',
|
|
54
|
+
properties: {
|
|
55
|
+
id: { type: 'integer' },
|
|
56
|
+
uuid: { anyOf: [{ type: 'string' }, { type: 'null' }] },
|
|
57
|
+
email: { type: 'string' },
|
|
58
|
+
name: { anyOf: [{ type: 'string' }, { type: 'null' }] },
|
|
59
|
+
username: { type: 'string' },
|
|
60
|
+
password: { type: 'string' },
|
|
61
|
+
createdAt: { anyOf: [{ type: 'string' }, { type: 'date' }, { type: 'null' }] },
|
|
62
|
+
updatedAt: { anyOf: [{ type: 'string' }, { type: 'date' }, { type: 'null' }] },
|
|
63
|
+
deletedAt: { anyOf: [{ type: 'string' }, { type: 'date' }, { type: 'null' }] },
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
(0, chai_1.expect)(results).to.be.jsonSchema(usersSchema);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
(0, mocha_1.it)(`DB: await new DB('users').first()
|
|
71
|
+
It should returns an object and must have all user schema attributes`, function () {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
const results = yield new lib_1.DB('users').first();
|
|
74
|
+
(0, chai_1.expect)(results).to.be.an('object');
|
|
75
|
+
const userSchema = {
|
|
76
|
+
type: 'object',
|
|
77
|
+
properties: {
|
|
78
|
+
id: { type: 'integer' },
|
|
79
|
+
uuid: { anyOf: [{ type: 'string' }, { type: 'null' }] },
|
|
80
|
+
email: { type: 'string' },
|
|
81
|
+
name: { anyOf: [{ type: 'string' }, { type: 'null' }] },
|
|
82
|
+
username: { type: 'string' },
|
|
83
|
+
password: { type: 'string' },
|
|
84
|
+
createdAt: { anyOf: [{ type: 'string' }, { type: 'date' }, { type: 'null' }] },
|
|
85
|
+
updatedAt: { anyOf: [{ type: 'string' }, { type: 'date' }, { type: 'null' }] },
|
|
86
|
+
deletedAt: { anyOf: [{ type: 'string' }, { type: 'date' }, { type: 'null' }] },
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
(0, chai_1.expect)(results).to.be.jsonSchema(userSchema);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
(0, mocha_1.it)(`DB: await new DB('users').select('id').first()
|
|
93
|
+
It should returns an object and must only have an 'id'`, function () {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
const results = yield new lib_1.DB('users').select('id').first();
|
|
96
|
+
(0, chai_1.expect)(results).to.be.an('object');
|
|
97
|
+
(0, chai_1.expect)(results).to.have.property('id');
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
(0, mocha_1.it)(`DB: await new DB('users').except('id').first()
|
|
101
|
+
It should returns an object and must only have an 'id'`, function () {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
const results = yield new lib_1.DB('users').except('id').first();
|
|
104
|
+
(0, chai_1.expect)(results).to.be.an('object');
|
|
105
|
+
(0, chai_1.expect)(results).to.not.have.property('id');
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
/* ###################################################### */
|
|
109
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
const chai_1 = __importStar(require("chai"));
|
|
39
|
+
const mocha_1 = require("mocha");
|
|
40
|
+
const chai_json_schema_1 = __importDefault(require("chai-json-schema"));
|
|
41
|
+
const lib_1 = require("../lib");
|
|
42
|
+
chai_1.default.use(chai_json_schema_1.default);
|
|
43
|
+
class User extends lib_1.Model {
|
|
44
|
+
}
|
|
45
|
+
(0, mocha_1.describe)('Testing Model', function () {
|
|
46
|
+
/* ##################################################### */
|
|
47
|
+
(0, mocha_1.it)('Try to select * from users with User Model ?', function () {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
const results = yield new User().get();
|
|
50
|
+
(0, chai_1.expect)(results).to.be.an('array');
|
|
51
|
+
const usersSchema = {
|
|
52
|
+
type: 'array',
|
|
53
|
+
items: {
|
|
54
|
+
type: 'object',
|
|
55
|
+
properties: {
|
|
56
|
+
id: { type: 'integer' },
|
|
57
|
+
uuid: { anyOf: [{ type: 'string' }, { type: 'null' }] },
|
|
58
|
+
email: { type: 'string' },
|
|
59
|
+
name: { anyOf: [{ type: 'string' }, { type: 'null' }] },
|
|
60
|
+
username: { type: 'string' },
|
|
61
|
+
password: { type: 'string' },
|
|
62
|
+
createdAt: { anyOf: [{ type: 'string' }, { type: 'date' }, { type: 'null' }] },
|
|
63
|
+
updatedAt: { anyOf: [{ type: 'string' }, { type: 'date' }, { type: 'null' }] },
|
|
64
|
+
deletedAt: { anyOf: [{ type: 'string' }, { type: 'date' }, { type: 'null' }] },
|
|
65
|
+
},
|
|
66
|
+
required: ['uuid'],
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
(0, chai_1.expect)(results).to.be.jsonSchema(usersSchema);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
/* ###################################################### */
|
|
73
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tspace-mysql",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.9",
|
|
4
4
|
"description": "mysql query builder object relational mapping",
|
|
5
5
|
"main": "dist/lib/index.js",
|
|
6
6
|
"types": "dist/lib/index.d.ts",
|
|
@@ -47,10 +47,21 @@
|
|
|
47
47
|
"homepage": "https://github.com/thanathip41",
|
|
48
48
|
"scripts": {
|
|
49
49
|
"build": "tsc",
|
|
50
|
-
"prepare": "npm run build"
|
|
50
|
+
"prepare": "npm run build",
|
|
51
|
+
"test:build": "mocha './dist/tests/**/*.test.js' --reporter spec --no-timeouts --recursive --exit",
|
|
52
|
+
"test": "ts-mocha './src/tests/**/*.test.ts' --reporter spec --no-timeouts --recursive --exit"
|
|
51
53
|
},
|
|
52
54
|
"devDependencies": {
|
|
55
|
+
"@types/chai": "^4.3.11",
|
|
56
|
+
"@types/chai-json-schema": "^1.4.9",
|
|
57
|
+
"@types/mocha": "^10.0.6",
|
|
53
58
|
"@types/mysql": "^2.15.19",
|
|
54
|
-
"@types/pluralize": "^0.0.29"
|
|
59
|
+
"@types/pluralize": "^0.0.29",
|
|
60
|
+
"chai": "4.3.10",
|
|
61
|
+
"chai-json-schema": "^1.5.1",
|
|
62
|
+
"mocha": "^10.2.0",
|
|
63
|
+
"mochawesome": "^7.1.3",
|
|
64
|
+
"ts-mocha": "^10.0.0",
|
|
65
|
+
"typescript": "^5.3.3"
|
|
55
66
|
}
|
|
56
67
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|