namirasoft-node 1.2.2 → 1.2.3
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/index.d.ts +0 -4
- package/dist/index.js +0 -4
- package/dist/index.js.map +1 -1
- package/package.json +2 -3
- package/src/index.ts +0 -4
- package/dist/BaseMySqlDatabase.d.ts +0 -4
- package/dist/BaseMySqlDatabase.js +0 -11
- package/dist/BaseMySqlDatabase.js.map +0 -1
- package/dist/BaseSequelizeDatabase.d.ts +0 -12
- package/dist/BaseSequelizeDatabase.js +0 -76
- package/dist/BaseSequelizeDatabase.js.map +0 -1
- package/dist/BaseSequelizeModel.d.ts +0 -3
- package/dist/BaseSequelizeModel.js +0 -8
- package/dist/BaseSequelizeModel.js.map +0 -1
- package/dist/BaseSequelizeTable.d.ts +0 -60
- package/dist/BaseSequelizeTable.js +0 -159
- package/dist/BaseSequelizeTable.js.map +0 -1
- package/src/BaseMySqlDatabase.ts +0 -8
- package/src/BaseSequelizeDatabase.ts +0 -84
- package/src/BaseSequelizeModel.ts +0 -5
- package/src/BaseSequelizeTable.ts +0 -169
package/dist/index.d.ts
CHANGED
|
@@ -3,10 +3,6 @@ export * from "./BaseApplication";
|
|
|
3
3
|
export * from "./BaseApplicationLink";
|
|
4
4
|
export * from "./BaseController";
|
|
5
5
|
export * from "./BaseDatabase";
|
|
6
|
-
export * from "./BaseMySqlDatabase";
|
|
7
|
-
export * from "./BaseSequelizeDatabase";
|
|
8
|
-
export * from "./BaseSequelizeModel";
|
|
9
|
-
export * from "./BaseSequelizeTable";
|
|
10
6
|
export * from "./BaseTable";
|
|
11
7
|
export * from "./EmailService";
|
|
12
8
|
export * from "./EnvService";
|
package/dist/index.js
CHANGED
|
@@ -19,10 +19,6 @@ __exportStar(require("./BaseApplication"), exports);
|
|
|
19
19
|
__exportStar(require("./BaseApplicationLink"), exports);
|
|
20
20
|
__exportStar(require("./BaseController"), exports);
|
|
21
21
|
__exportStar(require("./BaseDatabase"), exports);
|
|
22
|
-
__exportStar(require("./BaseMySqlDatabase"), exports);
|
|
23
|
-
__exportStar(require("./BaseSequelizeDatabase"), exports);
|
|
24
|
-
__exportStar(require("./BaseSequelizeModel"), exports);
|
|
25
|
-
__exportStar(require("./BaseSequelizeTable"), exports);
|
|
26
22
|
__exportStar(require("./BaseTable"), exports);
|
|
27
23
|
__exportStar(require("./EmailService"), exports);
|
|
28
24
|
__exportStar(require("./EnvService"), exports);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,oDAAkC;AAClC,wDAAsC;AACtC,mDAAiC;AACjC,iDAA+B;AAC/B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,oDAAkC;AAClC,wDAAsC;AACtC,mDAAiC;AACjC,iDAA+B;AAC/B,8CAA4B;AAC5B,iDAA+B;AAC/B,+CAA6B;AAC7B,gDAA8B;AAC9B,yCAAuB;AACvB,iDAA+B;AAC/B,yDAAuC;AACvC,4DAA0C"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "namirasoft-node",
|
|
3
3
|
"description": "Namira Software Corporation Node NPM Package",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.3",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"scripts": {},
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"@supercharge/request-ip": "^1.2.0",
|
|
12
12
|
"@types/cors": "^2.8.17",
|
|
13
13
|
"@types/express": "^4.17.21",
|
|
14
|
-
"@types/node": "^20.10.
|
|
14
|
+
"@types/node": "^20.10.1",
|
|
15
15
|
"@types/nodemailer": "^6.4.14",
|
|
16
16
|
"@types/nodemailer-smtp-transport": "^2.7.8",
|
|
17
17
|
"@types/swagger-jsdoc": "^6.0.4",
|
|
@@ -25,7 +25,6 @@
|
|
|
25
25
|
"nodemailer": "^6.9.7",
|
|
26
26
|
"nodemailer-smtp-transport": "^2.7.4",
|
|
27
27
|
"request-ip": "^3.3.0",
|
|
28
|
-
"sequelize": "^6.35.1",
|
|
29
28
|
"swagger-jsdoc": "^6.2.8",
|
|
30
29
|
"swagger-ui-express": "^5.0.0"
|
|
31
30
|
}
|
package/src/index.ts
CHANGED
|
@@ -3,10 +3,6 @@ export * from "./BaseApplication";
|
|
|
3
3
|
export * from "./BaseApplicationLink";
|
|
4
4
|
export * from "./BaseController";
|
|
5
5
|
export * from "./BaseDatabase";
|
|
6
|
-
export * from "./BaseMySqlDatabase";
|
|
7
|
-
export * from "./BaseSequelizeDatabase";
|
|
8
|
-
export * from "./BaseSequelizeModel";
|
|
9
|
-
export * from "./BaseSequelizeTable";
|
|
10
6
|
export * from "./BaseTable";
|
|
11
7
|
export * from "./EmailService";
|
|
12
8
|
export * from "./EnvService";
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseMySqlDatabase = void 0;
|
|
4
|
-
const BaseSequelizeDatabase_1 = require("./BaseSequelizeDatabase");
|
|
5
|
-
class BaseMySqlDatabase extends BaseSequelizeDatabase_1.BaseSequelizeDatabase {
|
|
6
|
-
constructor(host, port, name, user, pass, logging = false) {
|
|
7
|
-
super('mysql', host, port, name, user, pass, logging);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
exports.BaseMySqlDatabase = BaseMySqlDatabase;
|
|
11
|
-
//# sourceMappingURL=BaseMySqlDatabase.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BaseMySqlDatabase.js","sourceRoot":"","sources":["../src/BaseMySqlDatabase.ts"],"names":[],"mappings":";;;AAAA,mEAAgE;AAChE,MAAsB,iBAAkB,SAAQ,6CAAqB;IAEjE,YAAY,IAAY,EAAE,IAAY,EAAE,IAAY,EAAE,IAAY,EAAE,IAAY,EAAE,UAAmB,KAAK;QAEtG,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAC1D,CAAC;CACJ;AAND,8CAMC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Sequelize, Dialect } from "sequelize";
|
|
2
|
-
import { FindOptions, Transaction, Attributes } from 'sequelize';
|
|
3
|
-
import { BaseDatabase } from "./BaseDatabase";
|
|
4
|
-
import { BaseSequelizeModel } from "./BaseSequelizeModel";
|
|
5
|
-
import { Where } from "sequelize/types/utils";
|
|
6
|
-
export declare abstract class BaseSequelizeDatabase extends BaseDatabase {
|
|
7
|
-
sequelize: Sequelize;
|
|
8
|
-
constructor(dialect: Dialect, host: string, port: number, name: string, user: string, pass: string, logging?: boolean);
|
|
9
|
-
startTransaction<T>(handler: (trx: Transaction) => Promise<T>, trx: Transaction | null): Promise<T>;
|
|
10
|
-
getGoogleSearchConditions(columns: string[], search: string, conditions: Where[]): Where[];
|
|
11
|
-
paginate<T extends BaseSequelizeModel>(options: FindOptions<Attributes<T>>, page_number: number, page_size: number, page_size_default?: number): void;
|
|
12
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
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.BaseSequelizeDatabase = void 0;
|
|
13
|
-
const sequelize_1 = require("sequelize");
|
|
14
|
-
const BaseDatabase_1 = require("./BaseDatabase");
|
|
15
|
-
class BaseSequelizeDatabase extends BaseDatabase_1.BaseDatabase {
|
|
16
|
-
constructor(dialect, host, port, name, user, pass, logging = false) {
|
|
17
|
-
super();
|
|
18
|
-
this.sequelize = new sequelize_1.Sequelize(name, user, pass, {
|
|
19
|
-
dialect,
|
|
20
|
-
host,
|
|
21
|
-
port,
|
|
22
|
-
logging
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
startTransaction(handler, trx) {
|
|
26
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
if (trx)
|
|
28
|
-
return yield handler(trx);
|
|
29
|
-
trx = yield this.sequelize.transaction();
|
|
30
|
-
try {
|
|
31
|
-
let result = yield handler(trx);
|
|
32
|
-
yield trx.commit();
|
|
33
|
-
return result;
|
|
34
|
-
}
|
|
35
|
-
catch (error) {
|
|
36
|
-
yield trx.rollback();
|
|
37
|
-
throw error;
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
getGoogleSearchConditions(columns, search, conditions) {
|
|
42
|
-
if (!conditions)
|
|
43
|
-
conditions = [];
|
|
44
|
-
if (search)
|
|
45
|
-
if (search.split) {
|
|
46
|
-
let toks = search.split(' ');
|
|
47
|
-
if (toks.length > 0) {
|
|
48
|
-
for (let i = 0; i < toks.length; i++) {
|
|
49
|
-
let rOpr = { [sequelize_1.Op.like]: '%' + toks[i].trim() + '%' };
|
|
50
|
-
let lOpr;
|
|
51
|
-
let cs = columns.map(column => sequelize_1.Sequelize.col(column));
|
|
52
|
-
lOpr = sequelize_1.Sequelize.fn("concat", ...cs);
|
|
53
|
-
let condition = sequelize_1.Sequelize.where(lOpr, rOpr);
|
|
54
|
-
conditions.push(condition);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return conditions;
|
|
59
|
-
}
|
|
60
|
-
paginate(options, page_number, page_size, page_size_default) {
|
|
61
|
-
// page_number
|
|
62
|
-
if (isNaN(page_number))
|
|
63
|
-
page_number = 1;
|
|
64
|
-
// page_size
|
|
65
|
-
if (isNaN(page_size))
|
|
66
|
-
if (page_size_default)
|
|
67
|
-
page_size = page_size_default;
|
|
68
|
-
if (isNaN(page_size))
|
|
69
|
-
page_size = 20;
|
|
70
|
-
//
|
|
71
|
-
options.offset = (page_number - 1) * page_size;
|
|
72
|
-
options.limit = page_size;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
exports.BaseSequelizeDatabase = BaseSequelizeDatabase;
|
|
76
|
-
//# sourceMappingURL=BaseSequelizeDatabase.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BaseSequelizeDatabase.js","sourceRoot":"","sources":["../src/BaseSequelizeDatabase.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAmD;AAEnD,iDAA8C;AAI9C,MAAsB,qBAAsB,SAAQ,2BAAY;IAG5D,YAAY,OAAgB,EAAE,IAAY,EAAE,IAAY,EAAE,IAAY,EAAE,IAAY,EAAE,IAAY,EAAE,UAAmB,KAAK;QAExH,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,SAAS,GAAG,IAAI,qBAAS,CAC1B,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ;YACI,OAAO;YACP,IAAI;YACJ,IAAI;YACJ,OAAO;SACV,CAAC,CAAC;IACX,CAAC;IACK,gBAAgB,CAAI,OAAyC,EAAE,GAAuB;;YAExF,IAAI,GAAG;gBACH,OAAO,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC;YAC9B,GAAG,GAAG,MAAM,IAAI,CAAC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A+B,OAAmC,EACtE,WAAmB,EAAE,SAAiB,EAAE,iBAA0B;QAElE,cAAc;QACd,IAAI,KAAK,CAAC,WAAW,CAAC;YAClB,WAAW,GAAG,CAAC,CAAC;QACpB,YAAY;QACZ,IAAI,KAAK,CAAC,SAAS,CAAC;YAChB,IAAI,iBAAiB;gBACjB,SAAS,GAAG,iBAAiB,CAAC;QACtC,IAAI,KAAK,CAAC,SAAS,CAAC;YAChB,SAAS,GAAG,EAAE,CAAC;QACnB,EAAE;QACF,OAAO,CAAC,MAAM,GAAG,CAAC,WAAW,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC;QAC/C,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC;IAC9B,CAAC;CACJ;AA7ED,sDA6EC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseSequelizeModel = void 0;
|
|
4
|
-
const sequelize_1 = require("sequelize");
|
|
5
|
-
class BaseSequelizeModel extends sequelize_1.Model {
|
|
6
|
-
}
|
|
7
|
-
exports.BaseSequelizeModel = BaseSequelizeModel;
|
|
8
|
-
//# sourceMappingURL=BaseSequelizeModel.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BaseSequelizeModel.js","sourceRoot":"","sources":["../src/BaseSequelizeModel.ts"],"names":[],"mappings":";;;AAAA,yCAAkC;AAElC,MAAsB,kBAAmB,SAAQ,iBAAK;CAErD;AAFD,gDAEC"}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { ModelOptions, ModelAttributes, ModelAttributeColumnOptions } from "sequelize";
|
|
2
|
-
import { BaseSequelizeDatabase } from "./BaseSequelizeDatabase";
|
|
3
|
-
import { BaseTable } from "./BaseTable";
|
|
4
|
-
import { ModelCtor, FindOptions, Transaction, Attributes } from 'sequelize';
|
|
5
|
-
import { BaseSequelizeModel } from "./BaseSequelizeModel";
|
|
6
|
-
import { ArraySchema, BaseVariableSchema, ObjectSchema } from "namirasoft-schema";
|
|
7
|
-
export declare class BaseSequelizeTable<D extends BaseSequelizeDatabase, M extends BaseSequelizeModel> extends BaseTable<D> {
|
|
8
|
-
model: ModelCtor<M>;
|
|
9
|
-
attributes: ModelAttributes<M, Attributes<M>>;
|
|
10
|
-
constructor(database: D);
|
|
11
|
-
find(options: FindOptions<Attributes<M>>, trx: Transaction | null): Promise<M>;
|
|
12
|
-
define(modelName: string, attributes: ModelAttributes<M, Attributes<M>>, options?: ModelOptions<M>): void;
|
|
13
|
-
protected getExamples(): {
|
|
14
|
-
[name: string]: string;
|
|
15
|
-
};
|
|
16
|
-
protected forEachColumn(handler: (name: string, column: ModelAttributeColumnOptions) => void): void;
|
|
17
|
-
getSchema(require: boolean, name?: string, excludeColumns?: string[], joins?: BaseVariableSchema[]): ObjectSchema;
|
|
18
|
-
getArraySchema(require: boolean, name?: string, excludeColumns?: string[], joins?: BaseVariableSchema[]): ArraySchema;
|
|
19
|
-
private getVariableSchema;
|
|
20
|
-
private getTypeSchema;
|
|
21
|
-
protected isFloat(type: any): type is {
|
|
22
|
-
options: {
|
|
23
|
-
length: number;
|
|
24
|
-
decimals: number;
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
protected isDouble(type: any): type is {
|
|
28
|
-
options: {
|
|
29
|
-
length: number;
|
|
30
|
-
decimals: number;
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
protected isDecimal(type: any): type is {
|
|
34
|
-
options: {
|
|
35
|
-
precision: number;
|
|
36
|
-
scale: number;
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
protected isReal(type: any): type is {
|
|
40
|
-
options: {
|
|
41
|
-
length: number;
|
|
42
|
-
decimals: number;
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
protected isChar(type: any): type is {
|
|
46
|
-
options: {
|
|
47
|
-
length: number;
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
protected isString(type: any): type is {
|
|
51
|
-
options: {
|
|
52
|
-
length: number;
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
protected isEnum(type: any): type is {
|
|
56
|
-
options: {
|
|
57
|
-
values: string[];
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
}
|
|
@@ -1,159 +0,0 @@
|
|
|
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.BaseSequelizeTable = void 0;
|
|
13
|
-
const sequelize_1 = require("sequelize");
|
|
14
|
-
const BaseTable_1 = require("./BaseTable");
|
|
15
|
-
const namirasoft_core_1 = require("namirasoft-core");
|
|
16
|
-
const namirasoft_schema_1 = require("namirasoft-schema");
|
|
17
|
-
const EnumSchema_1 = require("namirasoft-schema/dist/schema/type/EnumSchema");
|
|
18
|
-
class BaseSequelizeTable extends BaseTable_1.BaseTable {
|
|
19
|
-
constructor(database) {
|
|
20
|
-
super(database);
|
|
21
|
-
}
|
|
22
|
-
find(options, trx) {
|
|
23
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
options.transaction = trx;
|
|
25
|
-
let value = yield this.model.findOne(options);
|
|
26
|
-
if (value != null)
|
|
27
|
-
return value;
|
|
28
|
-
throw namirasoft_core_1.ErrorOperation.getHTTP(404, "Could not found " + this.model.name);
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
define(modelName, attributes, options) {
|
|
32
|
-
this.attributes = attributes;
|
|
33
|
-
if (!options)
|
|
34
|
-
options = {};
|
|
35
|
-
if (options.name == undefined)
|
|
36
|
-
options.name = {
|
|
37
|
-
plural: modelName,
|
|
38
|
-
singular: modelName
|
|
39
|
-
};
|
|
40
|
-
if (options.paranoid == undefined)
|
|
41
|
-
options.paranoid = true;
|
|
42
|
-
if (options.freezeTableName == undefined)
|
|
43
|
-
options.freezeTableName = true;
|
|
44
|
-
if (options.tableName == undefined)
|
|
45
|
-
options.tableName = modelName;
|
|
46
|
-
if (options.underscored == undefined)
|
|
47
|
-
options.underscored = true;
|
|
48
|
-
if (options.timestamps == undefined)
|
|
49
|
-
options.timestamps = true;
|
|
50
|
-
if (options.paranoid == undefined)
|
|
51
|
-
options.paranoid = true;
|
|
52
|
-
if (options.createdAt == undefined)
|
|
53
|
-
options.createdAt = true;
|
|
54
|
-
if (options.updatedAt == undefined)
|
|
55
|
-
options.updatedAt = true;
|
|
56
|
-
this.model = this.database.sequelize.define(modelName, attributes, options);
|
|
57
|
-
}
|
|
58
|
-
getExamples() {
|
|
59
|
-
return {};
|
|
60
|
-
}
|
|
61
|
-
forEachColumn(handler) {
|
|
62
|
-
let keys = Object.keys(this.attributes);
|
|
63
|
-
let secures = this.getSecureColumns();
|
|
64
|
-
for (let i = 0; i < keys.length; i++)
|
|
65
|
-
if (!secures.includes(keys[i])) {
|
|
66
|
-
const column = this.attributes[keys[i]];
|
|
67
|
-
handler(keys[i], column);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
getSchema(require, name, excludeColumns, joins) {
|
|
71
|
-
if (!excludeColumns)
|
|
72
|
-
excludeColumns = [];
|
|
73
|
-
let readOnlyColumns = this.getReadOnlyColumns();
|
|
74
|
-
let ans = new namirasoft_schema_1.ObjectSchema(name !== null && name !== void 0 ? name : this.model.name, require, null);
|
|
75
|
-
this.forEachColumn((name, column) => {
|
|
76
|
-
if (excludeColumns)
|
|
77
|
-
if (!excludeColumns.includes(name))
|
|
78
|
-
ans.addField(this.getVariableSchema(name, column, readOnlyColumns.includes(name)));
|
|
79
|
-
});
|
|
80
|
-
if (joins)
|
|
81
|
-
ans.addField(...joins);
|
|
82
|
-
return ans;
|
|
83
|
-
}
|
|
84
|
-
getArraySchema(require, name, excludeColumns, joins) {
|
|
85
|
-
let ans = this.getSchema(require, name, excludeColumns, joins);
|
|
86
|
-
return new namirasoft_schema_1.ArraySchema(require, [ans]);
|
|
87
|
-
}
|
|
88
|
-
getVariableSchema(name, element, read_only) {
|
|
89
|
-
let schema = this.getTypeSchema(element);
|
|
90
|
-
schema.read_only = read_only;
|
|
91
|
-
let es = this.getExamples();
|
|
92
|
-
schema.example = es[name];
|
|
93
|
-
return new namirasoft_schema_1.BaseVariableSchema(name, schema);
|
|
94
|
-
}
|
|
95
|
-
getTypeSchema(element) {
|
|
96
|
-
var _a;
|
|
97
|
-
let required = !((_a = element.allowNull) !== null && _a !== void 0 ? _a : true);
|
|
98
|
-
if (element.type instanceof sequelize_1.DataTypes.BOOLEAN)
|
|
99
|
-
return new namirasoft_schema_1.BoolSchema(required);
|
|
100
|
-
else if (element.type instanceof sequelize_1.DataTypes.TINYINT)
|
|
101
|
-
return new namirasoft_schema_1.TinyIntSchema(required);
|
|
102
|
-
else if (element.type instanceof sequelize_1.DataTypes.SMALLINT)
|
|
103
|
-
return new namirasoft_schema_1.SmallIntSchema(required);
|
|
104
|
-
else if (element.type instanceof sequelize_1.DataTypes.MEDIUMINT)
|
|
105
|
-
return new namirasoft_schema_1.MediumIntSchema(required);
|
|
106
|
-
else if (element.type instanceof sequelize_1.DataTypes.INTEGER)
|
|
107
|
-
return new namirasoft_schema_1.IntegerSchema(required);
|
|
108
|
-
else if (element.type instanceof sequelize_1.DataTypes.BIGINT)
|
|
109
|
-
return new namirasoft_schema_1.BigIntSchema(required);
|
|
110
|
-
else if (this.isFloat(element.type))
|
|
111
|
-
return new namirasoft_schema_1.FloatSchema(required, element.type.options.decimals);
|
|
112
|
-
else if (this.isDouble(element.type))
|
|
113
|
-
return new namirasoft_schema_1.DoubleSchema(required, element.type.options.decimals);
|
|
114
|
-
else if (this.isDecimal(element.type))
|
|
115
|
-
return new namirasoft_schema_1.DecimalSchema(required, element.type.options.scale);
|
|
116
|
-
else if (this.isReal(element.type))
|
|
117
|
-
return new namirasoft_schema_1.RealSchema(required, element.type.options.decimals);
|
|
118
|
-
else if (this.isChar(element.type))
|
|
119
|
-
return new namirasoft_schema_1.StringSchema(required, element.type.options.length, element.type.options.length);
|
|
120
|
-
else if (this.isString(element.type))
|
|
121
|
-
return new namirasoft_schema_1.StringSchema(required, null, element.type.options.length);
|
|
122
|
-
else if (element.type instanceof sequelize_1.DataTypes.TEXT)
|
|
123
|
-
return new namirasoft_schema_1.StringSchema(required, null, null);
|
|
124
|
-
else if (element.type instanceof sequelize_1.DataTypes.DATE)
|
|
125
|
-
return new namirasoft_schema_1.DateTimeSchema(required);
|
|
126
|
-
else if (element.type instanceof sequelize_1.DataTypes.DATEONLY)
|
|
127
|
-
return new namirasoft_schema_1.DateSchema(required);
|
|
128
|
-
else if (element.type instanceof sequelize_1.DataTypes.TIME)
|
|
129
|
-
return new namirasoft_schema_1.TimeSchema(required);
|
|
130
|
-
else if (this.isEnum(element.type))
|
|
131
|
-
return new EnumSchema_1.EnumSchema(required, ...element.type.options.values);
|
|
132
|
-
else if (element.type instanceof sequelize_1.DataTypes.JSON)
|
|
133
|
-
return new namirasoft_schema_1.AnySchema(required);
|
|
134
|
-
throw new Error("Unsupported datatype for schema: " + element.type);
|
|
135
|
-
}
|
|
136
|
-
isFloat(type) {
|
|
137
|
-
return type instanceof sequelize_1.DataTypes.FLOAT;
|
|
138
|
-
}
|
|
139
|
-
isDouble(type) {
|
|
140
|
-
return type instanceof sequelize_1.DataTypes.DOUBLE;
|
|
141
|
-
}
|
|
142
|
-
isDecimal(type) {
|
|
143
|
-
return type instanceof sequelize_1.DataTypes.DECIMAL;
|
|
144
|
-
}
|
|
145
|
-
isReal(type) {
|
|
146
|
-
return type instanceof sequelize_1.DataTypes.REAL;
|
|
147
|
-
}
|
|
148
|
-
isChar(type) {
|
|
149
|
-
return type instanceof sequelize_1.DataTypes.CHAR;
|
|
150
|
-
}
|
|
151
|
-
isString(type) {
|
|
152
|
-
return type instanceof sequelize_1.DataTypes.STRING;
|
|
153
|
-
}
|
|
154
|
-
isEnum(type) {
|
|
155
|
-
return type instanceof sequelize_1.DataTypes.STRING;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
exports.BaseSequelizeTable = BaseSequelizeTable;
|
|
159
|
-
//# sourceMappingURL=BaseSequelizeTable.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BaseSequelizeTable.js","sourceRoot":"","sources":["../src/BaseSequelizeTable.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAkG;AAElG,2CAAwC;AAGxC,qDAAiD;AACjD,yDAAkT;AAClT,8EAA2E;AAE3E,MAAa,kBAAkF,SAAQ,qBAAY;IAI/G,YAAY,QAAW;QAEnB,KAAK,CAAC,QAAQ,CAAC,CAAC;IACpB,CAAC;IACK,IAAI,CAAC,OAAmC,EAAE,GAAuB;;YAEnE,OAAO,CAAC,WAAW,GAAG,GAAG,CAAC;YAC1B,IAAI,KAAK,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAI,OAAO,CAAC,CAAC;YACjD,IAAI,KAAK,IAAI,IAAI;gBACb,OAAO,KAAK,CAAC;YACjB,MAAM,gCAAc,CAAC,OAAO,CAAC,GAAG,EAAE,kBAAkB,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC5E,CAAC;KAAA;IACD,MAAM,CAAC,SAAiB,EAAE,UAA6C,EAAE,OAAyB;QAG9F,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,OAAO;YACR,OAAO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
1
|
-
import { BaseSequelizeDatabase } from "./BaseSequelizeDatabase";
|
|
2
|
-
export abstract class BaseMySqlDatabase extends BaseSequelizeDatabase
|
|
3
|
-
{
|
|
4
|
-
constructor(host: string, port: number, name: string, user: string, pass: string, logging: boolean = false)
|
|
5
|
-
{
|
|
6
|
-
super('mysql', host, port, name, user, pass, logging);
|
|
7
|
-
}
|
|
8
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { Sequelize, Dialect, Op } from "sequelize";
|
|
2
|
-
import { FindOptions, Transaction, Attributes } from 'sequelize';
|
|
3
|
-
import { BaseDatabase } from "./BaseDatabase";
|
|
4
|
-
import { BaseSequelizeModel } from "./BaseSequelizeModel";
|
|
5
|
-
import { Where } from "sequelize/types/utils";
|
|
6
|
-
|
|
7
|
-
export abstract class BaseSequelizeDatabase extends BaseDatabase
|
|
8
|
-
{
|
|
9
|
-
public sequelize: Sequelize;
|
|
10
|
-
constructor(dialect: Dialect, host: string, port: number, name: string, user: string, pass: string, logging: boolean = false)
|
|
11
|
-
{
|
|
12
|
-
super();
|
|
13
|
-
this.sequelize = new Sequelize(
|
|
14
|
-
name,
|
|
15
|
-
user,
|
|
16
|
-
pass,
|
|
17
|
-
{
|
|
18
|
-
dialect,
|
|
19
|
-
host,
|
|
20
|
-
port,
|
|
21
|
-
logging
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
async startTransaction<T>(handler: (trx: Transaction) => Promise<T>, trx: Transaction | null): Promise<T>
|
|
25
|
-
{
|
|
26
|
-
if (trx)
|
|
27
|
-
return await handler(trx);
|
|
28
|
-
trx = await this.sequelize.transaction();
|
|
29
|
-
try
|
|
30
|
-
{
|
|
31
|
-
let result = await handler(trx);
|
|
32
|
-
await trx.commit();
|
|
33
|
-
return result;
|
|
34
|
-
}
|
|
35
|
-
catch (error)
|
|
36
|
-
{
|
|
37
|
-
await trx.rollback();
|
|
38
|
-
throw error;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
getGoogleSearchConditions(columns: string[], search: string, conditions: Where[])
|
|
42
|
-
{
|
|
43
|
-
if (!conditions)
|
|
44
|
-
conditions = [];
|
|
45
|
-
if (search)
|
|
46
|
-
if (search.split)
|
|
47
|
-
{
|
|
48
|
-
let toks = search.split(' ');
|
|
49
|
-
if (toks.length > 0)
|
|
50
|
-
{
|
|
51
|
-
for (let i = 0; i < toks.length; i++)
|
|
52
|
-
{
|
|
53
|
-
let rOpr = { [Op.like]: '%' + toks[i].trim() + '%' };
|
|
54
|
-
let lOpr;
|
|
55
|
-
let cs = columns.map(column => Sequelize.col(column));
|
|
56
|
-
lOpr = Sequelize.fn(
|
|
57
|
-
"concat",
|
|
58
|
-
...cs
|
|
59
|
-
);
|
|
60
|
-
let condition = Sequelize.where(lOpr, rOpr);
|
|
61
|
-
conditions.push(condition);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return conditions;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
paginate<T extends BaseSequelizeModel>(options: FindOptions<Attributes<T>>,
|
|
69
|
-
page_number: number, page_size: number, page_size_default?: number)
|
|
70
|
-
{
|
|
71
|
-
// page_number
|
|
72
|
-
if (isNaN(page_number))
|
|
73
|
-
page_number = 1;
|
|
74
|
-
// page_size
|
|
75
|
-
if (isNaN(page_size))
|
|
76
|
-
if (page_size_default)
|
|
77
|
-
page_size = page_size_default;
|
|
78
|
-
if (isNaN(page_size))
|
|
79
|
-
page_size = 20;
|
|
80
|
-
//
|
|
81
|
-
options.offset = (page_number - 1) * page_size;
|
|
82
|
-
options.limit = page_size;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import { ModelOptions, ModelAttributes, ModelAttributeColumnOptions, DataTypes } from "sequelize";
|
|
2
|
-
import { BaseSequelizeDatabase } from "./BaseSequelizeDatabase";
|
|
3
|
-
import { BaseTable } from "./BaseTable";
|
|
4
|
-
import { ModelCtor, FindOptions, Transaction, Attributes } from 'sequelize';
|
|
5
|
-
import { BaseSequelizeModel } from "./BaseSequelizeModel";
|
|
6
|
-
import { ErrorOperation } from "namirasoft-core";
|
|
7
|
-
import { AnySchema, ArraySchema, BaseTypeSchema, BaseVariableSchema, BigIntSchema, BoolSchema, DateSchema, DateTimeSchema, DecimalSchema, DoubleSchema, FloatSchema, IntegerSchema, MediumIntSchema, ObjectSchema, RealSchema, SmallIntSchema, StringSchema, TimeSchema, TinyIntSchema } from "namirasoft-schema";
|
|
8
|
-
import { EnumSchema } from "namirasoft-schema/dist/schema/type/EnumSchema";
|
|
9
|
-
|
|
10
|
-
export class BaseSequelizeTable<D extends BaseSequelizeDatabase, M extends BaseSequelizeModel> extends BaseTable<D>
|
|
11
|
-
{
|
|
12
|
-
model!: ModelCtor<M>;
|
|
13
|
-
attributes!: ModelAttributes<M, Attributes<M>>;
|
|
14
|
-
constructor(database: D)
|
|
15
|
-
{
|
|
16
|
-
super(database);
|
|
17
|
-
}
|
|
18
|
-
async find(options: FindOptions<Attributes<M>>, trx: Transaction | null): Promise<M>
|
|
19
|
-
{
|
|
20
|
-
options.transaction = trx;
|
|
21
|
-
let value = await this.model.findOne<M>(options);
|
|
22
|
-
if (value != null)
|
|
23
|
-
return value;
|
|
24
|
-
throw ErrorOperation.getHTTP(404, "Could not found " + this.model.name);
|
|
25
|
-
}
|
|
26
|
-
define(modelName: string, attributes: ModelAttributes<M, Attributes<M>>, options?: ModelOptions<M>
|
|
27
|
-
): void
|
|
28
|
-
{
|
|
29
|
-
this.attributes = attributes;
|
|
30
|
-
if (!options)
|
|
31
|
-
options = {};
|
|
32
|
-
if (options.name == undefined)
|
|
33
|
-
options.name = {
|
|
34
|
-
plural: modelName,
|
|
35
|
-
singular: modelName
|
|
36
|
-
};
|
|
37
|
-
if (options.paranoid == undefined)
|
|
38
|
-
options.paranoid = true;
|
|
39
|
-
if (options.freezeTableName == undefined)
|
|
40
|
-
options.freezeTableName = true;
|
|
41
|
-
if (options.tableName == undefined)
|
|
42
|
-
options.tableName = modelName;
|
|
43
|
-
if (options.underscored == undefined)
|
|
44
|
-
options.underscored = true;
|
|
45
|
-
if (options.timestamps == undefined)
|
|
46
|
-
options.timestamps = true;
|
|
47
|
-
if (options.paranoid == undefined)
|
|
48
|
-
options.paranoid = true;
|
|
49
|
-
if (options.createdAt == undefined)
|
|
50
|
-
options.createdAt = true;
|
|
51
|
-
if (options.updatedAt == undefined)
|
|
52
|
-
options.updatedAt = true;
|
|
53
|
-
|
|
54
|
-
this.model = this.database.sequelize.define(modelName, attributes, options);
|
|
55
|
-
}
|
|
56
|
-
protected getExamples(): { [name: string]: string }
|
|
57
|
-
{
|
|
58
|
-
return {};
|
|
59
|
-
}
|
|
60
|
-
protected forEachColumn(handler: (name: string, column: ModelAttributeColumnOptions) => void)
|
|
61
|
-
{
|
|
62
|
-
let keys = Object.keys(this.attributes);
|
|
63
|
-
let secures = this.getSecureColumns();
|
|
64
|
-
for (let i = 0; i < keys.length; i++)
|
|
65
|
-
if (!secures.includes(keys[i]))
|
|
66
|
-
{
|
|
67
|
-
const column = this.attributes[keys[i]] as ModelAttributeColumnOptions;
|
|
68
|
-
handler(keys[i], column);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
getSchema(require: boolean, name?: string, excludeColumns?: string[], joins?: BaseVariableSchema[]): ObjectSchema
|
|
72
|
-
{
|
|
73
|
-
if (!excludeColumns)
|
|
74
|
-
excludeColumns = [];
|
|
75
|
-
let readOnlyColumns = this.getReadOnlyColumns();
|
|
76
|
-
let ans = new ObjectSchema(name ?? this.model.name, require, null);
|
|
77
|
-
this.forEachColumn((name, column) =>
|
|
78
|
-
{
|
|
79
|
-
if (excludeColumns)
|
|
80
|
-
if (!excludeColumns.includes(name))
|
|
81
|
-
ans.addField(this.getVariableSchema(name, column, readOnlyColumns.includes(name)));
|
|
82
|
-
});
|
|
83
|
-
if (joins)
|
|
84
|
-
ans.addField(...joins);
|
|
85
|
-
return ans;
|
|
86
|
-
}
|
|
87
|
-
getArraySchema(require: boolean, name?: string, excludeColumns?: string[], joins?: BaseVariableSchema[]): ArraySchema
|
|
88
|
-
{
|
|
89
|
-
let ans = this.getSchema(require, name, excludeColumns, joins);
|
|
90
|
-
return new ArraySchema(require, [ans]);
|
|
91
|
-
}
|
|
92
|
-
private getVariableSchema(name: string, element: ModelAttributeColumnOptions, read_only: boolean): BaseVariableSchema
|
|
93
|
-
{
|
|
94
|
-
let schema = this.getTypeSchema(element);
|
|
95
|
-
schema.read_only = read_only;
|
|
96
|
-
let es = this.getExamples();
|
|
97
|
-
schema.example = es[name];
|
|
98
|
-
return new BaseVariableSchema(name, schema);
|
|
99
|
-
}
|
|
100
|
-
private getTypeSchema(element: ModelAttributeColumnOptions): BaseTypeSchema
|
|
101
|
-
{
|
|
102
|
-
let required = !(element.allowNull ?? true);
|
|
103
|
-
if (element.type instanceof DataTypes.BOOLEAN)
|
|
104
|
-
return new BoolSchema(required);
|
|
105
|
-
else if (element.type instanceof DataTypes.TINYINT)
|
|
106
|
-
return new TinyIntSchema(required);
|
|
107
|
-
else if (element.type instanceof DataTypes.SMALLINT)
|
|
108
|
-
return new SmallIntSchema(required);
|
|
109
|
-
else if (element.type instanceof DataTypes.MEDIUMINT)
|
|
110
|
-
return new MediumIntSchema(required);
|
|
111
|
-
else if (element.type instanceof DataTypes.INTEGER)
|
|
112
|
-
return new IntegerSchema(required);
|
|
113
|
-
else if (element.type instanceof DataTypes.BIGINT)
|
|
114
|
-
return new BigIntSchema(required);
|
|
115
|
-
else if (this.isFloat(element.type))
|
|
116
|
-
return new FloatSchema(required, element.type.options.decimals);
|
|
117
|
-
else if (this.isDouble(element.type))
|
|
118
|
-
return new DoubleSchema(required, element.type.options.decimals);
|
|
119
|
-
else if (this.isDecimal(element.type))
|
|
120
|
-
return new DecimalSchema(required, element.type.options.scale);
|
|
121
|
-
else if (this.isReal(element.type))
|
|
122
|
-
return new RealSchema(required, element.type.options.decimals);
|
|
123
|
-
else if (this.isChar(element.type))
|
|
124
|
-
return new StringSchema(required, element.type.options.length, element.type.options.length);
|
|
125
|
-
else if (this.isString(element.type))
|
|
126
|
-
return new StringSchema(required, null, element.type.options.length);
|
|
127
|
-
else if (element.type instanceof DataTypes.TEXT)
|
|
128
|
-
return new StringSchema(required, null, null);
|
|
129
|
-
else if (element.type instanceof DataTypes.DATE)
|
|
130
|
-
return new DateTimeSchema(required);
|
|
131
|
-
else if (element.type instanceof DataTypes.DATEONLY)
|
|
132
|
-
return new DateSchema(required);
|
|
133
|
-
else if (element.type instanceof DataTypes.TIME)
|
|
134
|
-
return new TimeSchema(required);
|
|
135
|
-
else if (this.isEnum(element.type))
|
|
136
|
-
return new EnumSchema(required, ...element.type.options.values);
|
|
137
|
-
else if (element.type instanceof DataTypes.JSON)
|
|
138
|
-
return new AnySchema(required);
|
|
139
|
-
throw new Error("Unsupported datatype for schema: " + element.type);
|
|
140
|
-
}
|
|
141
|
-
protected isFloat(type: any): type is { options: { length: number, decimals: number } }
|
|
142
|
-
{
|
|
143
|
-
return type instanceof DataTypes.FLOAT;
|
|
144
|
-
}
|
|
145
|
-
protected isDouble(type: any): type is { options: { length: number, decimals: number } }
|
|
146
|
-
{
|
|
147
|
-
return type instanceof DataTypes.DOUBLE;
|
|
148
|
-
}
|
|
149
|
-
protected isDecimal(type: any): type is { options: { precision: number, scale: number } }
|
|
150
|
-
{
|
|
151
|
-
return type instanceof DataTypes.DECIMAL;
|
|
152
|
-
}
|
|
153
|
-
protected isReal(type: any): type is { options: { length: number, decimals: number } }
|
|
154
|
-
{
|
|
155
|
-
return type instanceof DataTypes.REAL;
|
|
156
|
-
}
|
|
157
|
-
protected isChar(type: any): type is { options: { length: number } }
|
|
158
|
-
{
|
|
159
|
-
return type instanceof DataTypes.CHAR;
|
|
160
|
-
}
|
|
161
|
-
protected isString(type: any): type is { options: { length: number } }
|
|
162
|
-
{
|
|
163
|
-
return type instanceof DataTypes.STRING;
|
|
164
|
-
}
|
|
165
|
-
protected isEnum(type: any): type is { options: { values: string[] } }
|
|
166
|
-
{
|
|
167
|
-
return type instanceof DataTypes.STRING;
|
|
168
|
-
}
|
|
169
|
-
}
|