pangea-server 1.0.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 +1 -0
- package/dist/authentication/access-token.class.d.ts +13 -0
- package/dist/authentication/access-token.class.js +28 -0
- package/dist/authentication/authentication.helpers.d.ts +17 -0
- package/dist/authentication/authentication.helpers.js +77 -0
- package/dist/authentication/authentication.types.d.ts +11 -0
- package/dist/authentication/authentication.types.js +2 -0
- package/dist/authentication/base-auth.class.d.ts +9 -0
- package/dist/authentication/base-auth.class.js +29 -0
- package/dist/authentication/index.d.ts +4 -0
- package/dist/authentication/index.js +20 -0
- package/dist/database/base-service.class.d.ts +15 -0
- package/dist/database/base-service.class.js +28 -0
- package/dist/database/database.helpers.d.ts +4 -0
- package/dist/database/database.helpers.js +19 -0
- package/dist/database/database.types.d.ts +59 -0
- package/dist/database/database.types.js +2 -0
- package/dist/database/db-client.d.ts +11 -0
- package/dist/database/db-client.js +69 -0
- package/dist/database/db.class.d.ts +64 -0
- package/dist/database/db.class.js +270 -0
- package/dist/database/decorators/columns/column.d.ts +10 -0
- package/dist/database/decorators/columns/column.js +47 -0
- package/dist/database/decorators/columns/date.columns.d.ts +4 -0
- package/dist/database/decorators/columns/date.columns.js +16 -0
- package/dist/database/decorators/columns/general.columns.d.ts +4 -0
- package/dist/database/decorators/columns/general.columns.js +54 -0
- package/dist/database/decorators/columns/json.columns.d.ts +3 -0
- package/dist/database/decorators/columns/json.columns.js +22 -0
- package/dist/database/decorators/columns/number.columns.d.ts +10 -0
- package/dist/database/decorators/columns/number.columns.js +33 -0
- package/dist/database/decorators/columns/string.columns.d.ts +10 -0
- package/dist/database/decorators/columns/string.columns.js +55 -0
- package/dist/database/decorators/index.d.ts +23 -0
- package/dist/database/decorators/index.js +50 -0
- package/dist/database/decorators/relations.d.ts +12 -0
- package/dist/database/decorators/relations.js +42 -0
- package/dist/database/decorators/table.d.ts +6 -0
- package/dist/database/decorators/table.js +57 -0
- package/dist/database/index.d.ts +8 -0
- package/dist/database/index.js +26 -0
- package/dist/database/init-database.d.ts +11 -0
- package/dist/database/init-database.js +69 -0
- package/dist/database/model-decorators/column.d.ts +11 -0
- package/dist/database/model-decorators/column.js +51 -0
- package/dist/database/model-decorators/date-columns.d.ts +6 -0
- package/dist/database/model-decorators/date-columns.js +41 -0
- package/dist/database/model-decorators/decorators.types.d.ts +20 -0
- package/dist/database/model-decorators/decorators.types.js +2 -0
- package/dist/database/model-decorators/general-columns.d.ts +4 -0
- package/dist/database/model-decorators/general-columns.js +54 -0
- package/dist/database/model-decorators/index.d.ts +23 -0
- package/dist/database/model-decorators/index.js +50 -0
- package/dist/database/model-decorators/json-columns.d.ts +3 -0
- package/dist/database/model-decorators/json-columns.js +46 -0
- package/dist/database/model-decorators/number-columns.d.ts +10 -0
- package/dist/database/model-decorators/number-columns.js +58 -0
- package/dist/database/model-decorators/relations.d.ts +12 -0
- package/dist/database/model-decorators/relations.js +42 -0
- package/dist/database/model-decorators/string-columns.d.ts +9 -0
- package/dist/database/model-decorators/string-columns.js +51 -0
- package/dist/database/model-decorators/table.d.ts +6 -0
- package/dist/database/model-decorators/table.js +57 -0
- package/dist/database/models/base-model.class.d.ts +33 -0
- package/dist/database/models/base-model.class.js +76 -0
- package/dist/database/models/index.d.ts +2 -0
- package/dist/database/models/index.js +18 -0
- package/dist/database/models/user.model.d.ts +5 -0
- package/dist/database/models/user.model.js +25 -0
- package/dist/database/seed.helpers.d.ts +4 -0
- package/dist/database/seed.helpers.js +44 -0
- package/dist/helpers/console.helpers.d.ts +8 -0
- package/dist/helpers/console.helpers.js +29 -0
- package/dist/helpers/controllers.helpers.d.ts +2 -0
- package/dist/helpers/controllers.helpers.js +6 -0
- package/dist/helpers/env.helpers.d.ts +4 -0
- package/dist/helpers/env.helpers.js +32 -0
- package/dist/helpers/error.helpers.d.ts +20 -0
- package/dist/helpers/error.helpers.js +29 -0
- package/dist/helpers/file.helpers.d.ts +4 -0
- package/dist/helpers/file.helpers.js +78 -0
- package/dist/helpers/hashing.helpers.d.ts +2 -0
- package/dist/helpers/hashing.helpers.js +16 -0
- package/dist/helpers/html-sanitize.helpers.d.ts +4 -0
- package/dist/helpers/html-sanitize.helpers.js +30 -0
- package/dist/helpers/index.d.ts +11 -0
- package/dist/helpers/index.js +27 -0
- package/dist/helpers/job.helpers.d.ts +8 -0
- package/dist/helpers/job.helpers.js +20 -0
- package/dist/helpers/mailer.helpers.d.ts +33 -0
- package/dist/helpers/mailer.helpers.js +34 -0
- package/dist/helpers/multer.helpers.d.ts +2 -0
- package/dist/helpers/multer.helpers.js +52 -0
- package/dist/helpers/print.helpers.d.ts +8 -0
- package/dist/helpers/print.helpers.js +29 -0
- package/dist/helpers/random.helpers.d.ts +4 -0
- package/dist/helpers/random.helpers.js +27 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +26 -0
- package/dist/main.d.ts +13 -0
- package/dist/main.js +65 -0
- package/dist/middlewares/delay-request.middleware.d.ts +1 -0
- package/dist/middlewares/delay-request.middleware.js +16 -0
- package/dist/middlewares/handle-error.middleware.d.ts +1 -0
- package/dist/middlewares/handle-error.middleware.js +13 -0
- package/dist/resources/color.resources.d.ts +18 -0
- package/dist/resources/color.resources.js +20 -0
- package/dist/resources/index.d.ts +2 -0
- package/dist/resources/index.js +18 -0
- package/dist/resources/refs.d.ts +32 -0
- package/dist/resources/refs.js +35 -0
- package/dist/resources/string.resources.d.ts +15 -0
- package/dist/resources/string.resources.js +16 -0
- package/dist/router/app-router.class.d.ts +18 -0
- package/dist/router/app-router.class.js +34 -0
- package/dist/router/call-controller.d.ts +5 -0
- package/dist/router/call-controller.js +47 -0
- package/dist/router/index.d.ts +1 -0
- package/dist/router/index.js +17 -0
- package/dist/router/router.types.d.ts +15 -0
- package/dist/router/router.types.js +2 -0
- package/dist/types/error.types.d.ts +4 -0
- package/dist/types/error.types.js +2 -0
- package/dist/types/global.types.d.ts +22 -0
- package/dist/types/global.types.js +2 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +4 -0
- package/dist/validations/general-schemas.d.ts +20 -0
- package/dist/validations/general-schemas.js +15 -0
- package/dist/validations/index.d.ts +3 -0
- package/dist/validations/index.js +19 -0
- package/dist/validations/validate-request.middleware.d.ts +2 -0
- package/dist/validations/validate-request.middleware.js +33 -0
- package/dist/validations/validation-locations.d.ts +1 -0
- package/dist/validations/validation-locations.js +4 -0
- package/dist/validations/validations.types.d.ts +23 -0
- package/dist/validations/validations.types.js +21 -0
- package/dist/validator/general-schemas.d.ts +1 -0
- package/dist/validator/general-schemas.js +25 -0
- package/dist/validator/index.d.ts +1 -0
- package/dist/validator/index.js +17 -0
- package/dist/validator/tags.d.ts +1 -0
- package/dist/validator/tags.js +5 -0
- package/dist/validator/validate-request.d.ts +2 -0
- package/dist/validator/validate-request.js +71 -0
- package/dist/validator/validator.types.d.ts +6 -0
- package/dist/validator/validator.types.js +2 -0
- package/dist/validator/validators.helpers.d.ts +38 -0
- package/dist/validator/validators.helpers.js +8 -0
- package/package.json +78 -0
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.HasMany = exports.HasOne = exports.BelongsTo = void 0;
|
|
27
|
+
const seq = __importStar(require("sequelize-typescript"));
|
|
28
|
+
exports.BelongsTo = getRelation(seq.BelongsTo);
|
|
29
|
+
exports.HasOne = getRelation(seq.HasOne);
|
|
30
|
+
exports.HasMany = getRelation(seq.HasMany);
|
|
31
|
+
// internal functions
|
|
32
|
+
function getRelation(relationFn) {
|
|
33
|
+
return function (getModelFn, options = {}) {
|
|
34
|
+
return function (target, propertyName) {
|
|
35
|
+
const { foreignKey, ...relOptions } = options;
|
|
36
|
+
relationFn(getModelFn, { as: propertyName, ...(foreignKey && { foreignKey }) })(target, propertyName);
|
|
37
|
+
const model = target.constructor;
|
|
38
|
+
const { eager = relationFn !== seq.HasMany, required = relationFn === seq.BelongsTo ? !model.Columns[`${propertyName}Id`].allowNull : false, paranoid = relationFn !== seq.BelongsTo, joinDepth = 1, ...restOptions } = relOptions;
|
|
39
|
+
model.AddRelation(propertyName, { getModelFn, eager, required, paranoid, joinDepth, ...restOptions });
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.Table = void 0;
|
|
27
|
+
const seq = __importStar(require("sequelize-typescript"));
|
|
28
|
+
// helpers
|
|
29
|
+
const pangea_helpers_1 = require("pangea-helpers");
|
|
30
|
+
function Table(tableName, options = {}) {
|
|
31
|
+
const { indexes } = options;
|
|
32
|
+
return function (target) {
|
|
33
|
+
const tableIndexes = indexes || [];
|
|
34
|
+
const columnIndexes = target.ColumnIndexes;
|
|
35
|
+
const allIndexes = [...tableIndexes, ...columnIndexes];
|
|
36
|
+
seq.Table({
|
|
37
|
+
tableName,
|
|
38
|
+
charset: 'utf8mb4',
|
|
39
|
+
collate: 'utf8mb4_general_ci',
|
|
40
|
+
underscored: true,
|
|
41
|
+
timestamps: true,
|
|
42
|
+
paranoid: true,
|
|
43
|
+
indexes: allIndexes.map(({ field, fields, ...restIndex }) => {
|
|
44
|
+
return {
|
|
45
|
+
...restIndex,
|
|
46
|
+
fields: fields ? fields.map(pangea_helpers_1.camelToSnake) : field ? [(0, pangea_helpers_1.camelToSnake)(field)] : [],
|
|
47
|
+
};
|
|
48
|
+
}),
|
|
49
|
+
})(target);
|
|
50
|
+
const excludedAttributes = target.ExcludedAttributes;
|
|
51
|
+
if (!excludedAttributes.length)
|
|
52
|
+
return;
|
|
53
|
+
seq.DefaultScope(() => ({ attributes: { exclude: excludedAttributes } }))(target);
|
|
54
|
+
seq.Scopes(() => ({ withExcludedAttributes: { attributes: { include: excludedAttributes } } }))(target);
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
exports.Table = Table;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { Op as Ops } from 'sequelize';
|
|
2
|
+
export * from './decorators';
|
|
3
|
+
export * from './models';
|
|
4
|
+
export * from './base-service.class';
|
|
5
|
+
export * from './database.types';
|
|
6
|
+
export * from './db-client';
|
|
7
|
+
export * from './db.class';
|
|
8
|
+
export * from './seed.helpers';
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.Ops = void 0;
|
|
18
|
+
var sequelize_1 = require("sequelize");
|
|
19
|
+
Object.defineProperty(exports, "Ops", { enumerable: true, get: function () { return sequelize_1.Op; } });
|
|
20
|
+
__exportStar(require("./decorators"), exports);
|
|
21
|
+
__exportStar(require("./models"), exports);
|
|
22
|
+
__exportStar(require("./base-service.class"), exports);
|
|
23
|
+
__exportStar(require("./database.types"), exports);
|
|
24
|
+
__exportStar(require("./db-client"), exports);
|
|
25
|
+
__exportStar(require("./db.class"), exports);
|
|
26
|
+
__exportStar(require("./seed.helpers"), exports);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Sequelize } from 'sequelize-typescript';
|
|
2
|
+
import type { Models, Seeds } from './database.types';
|
|
3
|
+
type InitDatabaseConfig = {
|
|
4
|
+
logging?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export declare function initDatabase<M extends Models>(models: M, seeds: Seeds<M>, config?: InitDatabaseConfig): {
|
|
7
|
+
connectDatabase: () => Promise<void>;
|
|
8
|
+
disconnectDatabase: () => Promise<void>;
|
|
9
|
+
};
|
|
10
|
+
export declare function getDbClient(): Sequelize;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDbClient = exports.initDatabase = void 0;
|
|
4
|
+
const sequelize_typescript_1 = require("sequelize-typescript");
|
|
5
|
+
// helpers
|
|
6
|
+
const helpers_1 = require("pangea-backend/helpers");
|
|
7
|
+
const seed_helpers_1 = require("./seed.helpers");
|
|
8
|
+
let dbClient = undefined;
|
|
9
|
+
function initDatabase(models, seeds, config = {}) {
|
|
10
|
+
if (dbClient)
|
|
11
|
+
throw new Error('DbClient instance has already been initialized');
|
|
12
|
+
dbClient = new sequelize_typescript_1.Sequelize({
|
|
13
|
+
dialect: 'mysql',
|
|
14
|
+
host: (0, helpers_1.getEnvStr)('DB_HOST'),
|
|
15
|
+
port: (0, helpers_1.getEnvInt)('DB_PORT'),
|
|
16
|
+
username: (0, helpers_1.getEnvStr)('DB_USERNAME'),
|
|
17
|
+
password: (0, helpers_1.getEnvStr)('DB_PASSWORD'),
|
|
18
|
+
database: (0, helpers_1.getEnvStr)('DB_DATABASE'),
|
|
19
|
+
pool: { max: 5, min: 0, acquire: 30000, idle: 10000 },
|
|
20
|
+
models: Object.values(models),
|
|
21
|
+
logging: config.logging ? logQuery : false,
|
|
22
|
+
benchmark: true,
|
|
23
|
+
});
|
|
24
|
+
async function connectDatabase() {
|
|
25
|
+
try {
|
|
26
|
+
const dbClient = getDbClient();
|
|
27
|
+
await dbClient.authenticate();
|
|
28
|
+
(0, helpers_1.printSuccess)('database', 'database connected');
|
|
29
|
+
if ((0, helpers_1.getEnvStr)('ENVIRONMENT') !== 'production') {
|
|
30
|
+
if ((0, helpers_1.getEnvBool)('DB_DROP_TABLES'))
|
|
31
|
+
await (0, seed_helpers_1.dropTables)();
|
|
32
|
+
await (0, seed_helpers_1.syncTables)();
|
|
33
|
+
if ((0, helpers_1.getEnvBool)('DB_SEED_TABLES'))
|
|
34
|
+
await (0, seed_helpers_1.seedTables)(models, seeds);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
(0, helpers_1.printDanger)('database', err);
|
|
39
|
+
throw err;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async function disconnectDatabase() {
|
|
43
|
+
try {
|
|
44
|
+
const dbClient = getDbClient();
|
|
45
|
+
await dbClient.close();
|
|
46
|
+
(0, helpers_1.printSuccess)('database', 'database disconnected');
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
(0, helpers_1.printDanger)('database', err);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return { connectDatabase, disconnectDatabase };
|
|
53
|
+
}
|
|
54
|
+
exports.initDatabase = initDatabase;
|
|
55
|
+
function getDbClient() {
|
|
56
|
+
if (!dbClient)
|
|
57
|
+
throw new Error('DbClient instance is not initialized');
|
|
58
|
+
return dbClient;
|
|
59
|
+
}
|
|
60
|
+
exports.getDbClient = getDbClient;
|
|
61
|
+
// internal functions
|
|
62
|
+
function logQuery(sql, timing) {
|
|
63
|
+
(0, helpers_1.printInfo)('query', sql);
|
|
64
|
+
if (!timing)
|
|
65
|
+
return;
|
|
66
|
+
const logFns = { success: helpers_1.printSuccess, warning: helpers_1.printWarning, danger: helpers_1.printDanger };
|
|
67
|
+
const level = timing <= 50 ? 'success' : timing <= 200 ? 'warning' : 'danger';
|
|
68
|
+
logFns[level]('timing', `${timing} ms`);
|
|
69
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { DataType, ModelValidateOptions } from 'sequelize';
|
|
2
|
+
import type { ColGeneralOptions, ColNullable, ColOptional, ColVirtualOptions, DefaultValue } from './decorators.types';
|
|
3
|
+
type ForeignKeyAction = 'RESTRICT' | 'CASCADE' | 'SET NULL';
|
|
4
|
+
type ColumnOptions = ColGeneralOptions & ColNullable & ColOptional & ColVirtualOptions & {
|
|
5
|
+
fallbackDefaultValue?: DefaultValue;
|
|
6
|
+
validate?: ModelValidateOptions;
|
|
7
|
+
onUpdate?: ForeignKeyAction;
|
|
8
|
+
onDelete?: ForeignKeyAction;
|
|
9
|
+
};
|
|
10
|
+
export declare function Column(type: DataType, options?: ColumnOptions): (target: any, propertyName: string) => void;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.Column = void 0;
|
|
27
|
+
const seq = __importStar(require("sequelize-typescript"));
|
|
28
|
+
function Column(type, options = {}) {
|
|
29
|
+
const { nullable = false, optional, defaultValue, fallbackDefaultValue, index, unique = false, exclude, get, set, ...restOptions } = options;
|
|
30
|
+
let finalDefaultValue = defaultValue;
|
|
31
|
+
if (finalDefaultValue === undefined) {
|
|
32
|
+
finalDefaultValue = nullable ? null : !optional ? undefined : fallbackDefaultValue;
|
|
33
|
+
}
|
|
34
|
+
return function (target, propertyName) {
|
|
35
|
+
seq.Column({
|
|
36
|
+
type,
|
|
37
|
+
allowNull: nullable,
|
|
38
|
+
defaultValue: finalDefaultValue,
|
|
39
|
+
...(get && { get }),
|
|
40
|
+
...(set && { set }),
|
|
41
|
+
...restOptions,
|
|
42
|
+
})(target, propertyName);
|
|
43
|
+
const model = target.constructor;
|
|
44
|
+
model.AddColumn(propertyName, { allowNull: nullable, defaultValue: finalDefaultValue });
|
|
45
|
+
if (index || unique)
|
|
46
|
+
model.AddColumnIndex({ field: propertyName, unique });
|
|
47
|
+
if (exclude)
|
|
48
|
+
model.AddExcludedAttribute(propertyName);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
exports.Column = Column;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ColGeneralOptions, ColNullable, ColOptional } from './decorators.types';
|
|
2
|
+
type ColDateOptions = ColGeneralOptions & ColNullable & ColOptional;
|
|
3
|
+
export declare function ColDatetime(options?: ColDateOptions): (target: any, propertyName: string) => void;
|
|
4
|
+
export declare function ColDate(options?: ColDateOptions): (target: any, propertyName: string) => void;
|
|
5
|
+
export declare function ColTime(options?: ColDateOptions): (target: any, propertyName: string) => void;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.ColTime = exports.ColDate = exports.ColDatetime = void 0;
|
|
27
|
+
const sequelize_1 = require("sequelize");
|
|
28
|
+
const seq = __importStar(require("sequelize-typescript"));
|
|
29
|
+
const column_1 = require("./column");
|
|
30
|
+
function ColDatetime(options) {
|
|
31
|
+
return (0, column_1.Column)(seq.DataType.DATE, { ...options, fallbackDefaultValue: sequelize_1.NOW });
|
|
32
|
+
}
|
|
33
|
+
exports.ColDatetime = ColDatetime;
|
|
34
|
+
function ColDate(options) {
|
|
35
|
+
return (0, column_1.Column)(seq.DataType.DATEONLY, { ...options, fallbackDefaultValue: (0, sequelize_1.fn)('CURDATE') });
|
|
36
|
+
}
|
|
37
|
+
exports.ColDate = ColDate;
|
|
38
|
+
function ColTime(options) {
|
|
39
|
+
return (0, column_1.Column)(seq.DataType.TIME, { ...options, fallbackDefaultValue: (0, sequelize_1.fn)('CURRENT_TIME') });
|
|
40
|
+
}
|
|
41
|
+
exports.ColTime = ColTime;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type DefaultValue = unknown;
|
|
2
|
+
export type ColGeneralOptions = {
|
|
3
|
+
index?: boolean;
|
|
4
|
+
unique?: boolean;
|
|
5
|
+
exclude?: boolean;
|
|
6
|
+
defaultValue?: DefaultValue;
|
|
7
|
+
};
|
|
8
|
+
export type ColNullable = {
|
|
9
|
+
nullable?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export type ColOptional = {
|
|
12
|
+
optional?: boolean;
|
|
13
|
+
};
|
|
14
|
+
export type ColVirtualGet = (this: any) => unknown;
|
|
15
|
+
export type ColVirtualSet = (this: any, val: any) => void;
|
|
16
|
+
export type ColVirtualOptions = {
|
|
17
|
+
get?: ColVirtualGet;
|
|
18
|
+
set?: ColVirtualSet;
|
|
19
|
+
};
|
|
20
|
+
export type GetModelFn = () => BaseModelCtor;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ColGeneralOptions, ColNullable, ColVirtualGet, ColVirtualOptions, GetModelFn } from './decorators.types';
|
|
2
|
+
export declare function ColBool(options?: ColGeneralOptions): (target: any, propertyName: string) => void;
|
|
3
|
+
export declare function ColVirtual(options?: ColVirtualOptions | ColVirtualGet): Function;
|
|
4
|
+
export declare function ColForeignKey(getModelFn: GetModelFn, options?: ColGeneralOptions & ColNullable): (target: any, propertyName: string) => void;
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.ColForeignKey = exports.ColVirtual = exports.ColBool = void 0;
|
|
27
|
+
const seq = __importStar(require("sequelize-typescript"));
|
|
28
|
+
const column_1 = require("./column");
|
|
29
|
+
function ColBool(options) {
|
|
30
|
+
return (0, column_1.Column)(seq.DataType.BOOLEAN, { ...options, fallbackDefaultValue: false });
|
|
31
|
+
}
|
|
32
|
+
exports.ColBool = ColBool;
|
|
33
|
+
function ColVirtual(options) {
|
|
34
|
+
let get;
|
|
35
|
+
let set;
|
|
36
|
+
if (options) {
|
|
37
|
+
if (typeof options === 'function') {
|
|
38
|
+
get = options;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
get = options.get;
|
|
42
|
+
set = options.set;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return seq.Column({ type: seq.DataType.VIRTUAL, ...(get && { get }), ...(set && { set }) });
|
|
46
|
+
}
|
|
47
|
+
exports.ColVirtual = ColVirtual;
|
|
48
|
+
function ColForeignKey(getModelFn, options) {
|
|
49
|
+
return function (target, propertyName) {
|
|
50
|
+
(0, column_1.Column)(seq.DataType.INTEGER, { ...options, onUpdate: 'RESTRICT', onDelete: 'RESTRICT' })(target, propertyName);
|
|
51
|
+
seq.ForeignKey(getModelFn)(target, propertyName);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
exports.ColForeignKey = ColForeignKey;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as str from './string-columns';
|
|
2
|
+
import * as num from './number-columns';
|
|
3
|
+
import * as date from './date-columns';
|
|
4
|
+
import * as json from './json-columns';
|
|
5
|
+
import * as general from './general-columns';
|
|
6
|
+
export { Table } from './table';
|
|
7
|
+
export declare const col: {
|
|
8
|
+
Str: typeof str.ColStr;
|
|
9
|
+
Text: typeof str.ColText;
|
|
10
|
+
Int: typeof num.ColInt;
|
|
11
|
+
BigInt: typeof num.ColBigInt;
|
|
12
|
+
Float: typeof num.ColFloat;
|
|
13
|
+
Double: typeof num.ColDouble;
|
|
14
|
+
Datetime: typeof date.ColDatetime;
|
|
15
|
+
Date: typeof date.ColDate;
|
|
16
|
+
Time: typeof date.ColTime;
|
|
17
|
+
Json: typeof json.ColJson;
|
|
18
|
+
StrArray: typeof json.ColStrArray;
|
|
19
|
+
Bool: typeof general.ColBool;
|
|
20
|
+
Virtual: typeof general.ColVirtual;
|
|
21
|
+
ForeignKey: typeof general.ColForeignKey;
|
|
22
|
+
};
|
|
23
|
+
export * as rel from './relations';
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.rel = exports.col = exports.Table = void 0;
|
|
27
|
+
const str = __importStar(require("./string-columns"));
|
|
28
|
+
const num = __importStar(require("./number-columns"));
|
|
29
|
+
const date = __importStar(require("./date-columns"));
|
|
30
|
+
const json = __importStar(require("./json-columns"));
|
|
31
|
+
const general = __importStar(require("./general-columns"));
|
|
32
|
+
var table_1 = require("./table");
|
|
33
|
+
Object.defineProperty(exports, "Table", { enumerable: true, get: function () { return table_1.Table; } });
|
|
34
|
+
exports.col = {
|
|
35
|
+
Str: str.ColStr,
|
|
36
|
+
Text: str.ColText,
|
|
37
|
+
Int: num.ColInt,
|
|
38
|
+
BigInt: num.ColBigInt,
|
|
39
|
+
Float: num.ColFloat,
|
|
40
|
+
Double: num.ColDouble,
|
|
41
|
+
Datetime: date.ColDatetime,
|
|
42
|
+
Date: date.ColDate,
|
|
43
|
+
Time: date.ColTime,
|
|
44
|
+
Json: json.ColJson,
|
|
45
|
+
StrArray: json.ColStrArray,
|
|
46
|
+
Bool: general.ColBool,
|
|
47
|
+
Virtual: general.ColVirtual,
|
|
48
|
+
ForeignKey: general.ColForeignKey,
|
|
49
|
+
};
|
|
50
|
+
exports.rel = __importStar(require("./relations"));
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ColGeneralOptions, ColNullable } from './decorators.types';
|
|
2
|
+
export declare function ColJson(options?: ColGeneralOptions & ColNullable): (target: any, propertyName: string) => void;
|
|
3
|
+
export declare function ColStrArray(): (target: any, propertyName: string) => void;
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.ColStrArray = exports.ColJson = void 0;
|
|
27
|
+
const seq = __importStar(require("sequelize-typescript"));
|
|
28
|
+
const column_1 = require("./column");
|
|
29
|
+
function ColJson(options) {
|
|
30
|
+
return (0, column_1.Column)(seq.DataType.JSON, options);
|
|
31
|
+
}
|
|
32
|
+
exports.ColJson = ColJson;
|
|
33
|
+
function ColStrArray() {
|
|
34
|
+
return function (target, propertyName) {
|
|
35
|
+
(0, column_1.Column)(seq.DataType.TEXT, {
|
|
36
|
+
get() {
|
|
37
|
+
const val = this.getDataValue(propertyName);
|
|
38
|
+
return typeof val === 'string' && val.length > 0 ? val.split(',') : [];
|
|
39
|
+
},
|
|
40
|
+
set(val) {
|
|
41
|
+
this.setDataValue(propertyName, val.join(','));
|
|
42
|
+
},
|
|
43
|
+
})(target, propertyName);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
exports.ColStrArray = ColStrArray;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ColGeneralOptions, ColOptional } from './decorators.types';
|
|
2
|
+
type ColNumOptions = ColGeneralOptions & ColOptional & {
|
|
3
|
+
min?: number;
|
|
4
|
+
max?: number;
|
|
5
|
+
};
|
|
6
|
+
export declare function ColInt(options?: ColNumOptions): (target: any, propertyName: string) => void;
|
|
7
|
+
export declare function ColBigInt(options?: ColNumOptions): (target: any, propertyName: string) => void;
|
|
8
|
+
export declare function ColFloat(options?: ColNumOptions): (target: any, propertyName: string) => void;
|
|
9
|
+
export declare function ColDouble(options?: ColNumOptions): (target: any, propertyName: string) => void;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.ColDouble = exports.ColFloat = exports.ColBigInt = exports.ColInt = void 0;
|
|
27
|
+
const seq = __importStar(require("sequelize-typescript"));
|
|
28
|
+
const column_1 = require("./column");
|
|
29
|
+
function ColInt(options) {
|
|
30
|
+
return getNumColumn(seq.DataType.INTEGER, options);
|
|
31
|
+
}
|
|
32
|
+
exports.ColInt = ColInt;
|
|
33
|
+
function ColBigInt(options) {
|
|
34
|
+
return getNumColumn(seq.DataType.BIGINT, options);
|
|
35
|
+
}
|
|
36
|
+
exports.ColBigInt = ColBigInt;
|
|
37
|
+
function ColFloat(options) {
|
|
38
|
+
return getNumColumn(seq.DataType.FLOAT, options);
|
|
39
|
+
}
|
|
40
|
+
exports.ColFloat = ColFloat;
|
|
41
|
+
function ColDouble(options) {
|
|
42
|
+
return getNumColumn(seq.DataType.DOUBLE, options);
|
|
43
|
+
}
|
|
44
|
+
exports.ColDouble = ColDouble;
|
|
45
|
+
// internal functions
|
|
46
|
+
function getNumColumn(type, options = {}) {
|
|
47
|
+
const { min, max, ...restOptions } = options;
|
|
48
|
+
const validate = {};
|
|
49
|
+
if (min !== undefined)
|
|
50
|
+
validate.min = min;
|
|
51
|
+
if (max !== undefined)
|
|
52
|
+
validate.max = max;
|
|
53
|
+
return (0, column_1.Column)(type, {
|
|
54
|
+
...restOptions,
|
|
55
|
+
fallbackDefaultValue: 0,
|
|
56
|
+
...(Object.keys(validate).length ? { validate } : {}),
|
|
57
|
+
});
|
|
58
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { GetModelFn } from './decorators.types';
|
|
2
|
+
type RelationOptions = {
|
|
3
|
+
eager?: boolean;
|
|
4
|
+
required?: boolean;
|
|
5
|
+
paranoid?: boolean;
|
|
6
|
+
joinDepth?: number;
|
|
7
|
+
foreignKey?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const BelongsTo: (getModelFn: GetModelFn, options?: RelationOptions) => (target: any, propertyName: string) => void;
|
|
10
|
+
export declare const HasOne: (getModelFn: GetModelFn, options?: RelationOptions) => (target: any, propertyName: string) => void;
|
|
11
|
+
export declare const HasMany: (getModelFn: GetModelFn, options?: RelationOptions) => (target: any, propertyName: string) => void;
|
|
12
|
+
export {};
|