pangea-server 1.0.45 → 1.0.47
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/database/db.class.js +6 -0
- package/package.json +1 -1
- package/dist/database/database.helpers.d.ts +0 -4
- package/dist/database/database.helpers.js +0 -19
- package/dist/database/init-database.d.ts +0 -11
- package/dist/database/init-database.js +0 -69
- package/dist/database/model-decorators/column.d.ts +0 -11
- package/dist/database/model-decorators/column.js +0 -51
- package/dist/database/model-decorators/date-columns.d.ts +0 -6
- package/dist/database/model-decorators/date-columns.js +0 -41
- package/dist/database/model-decorators/decorators.types.d.ts +0 -20
- package/dist/database/model-decorators/decorators.types.js +0 -2
- package/dist/database/model-decorators/general-columns.d.ts +0 -4
- package/dist/database/model-decorators/general-columns.js +0 -54
- package/dist/database/model-decorators/index.d.ts +0 -23
- package/dist/database/model-decorators/index.js +0 -50
- package/dist/database/model-decorators/json-columns.d.ts +0 -3
- package/dist/database/model-decorators/json-columns.js +0 -46
- package/dist/database/model-decorators/number-columns.d.ts +0 -10
- package/dist/database/model-decorators/number-columns.js +0 -58
- package/dist/database/model-decorators/relations.d.ts +0 -12
- package/dist/database/model-decorators/relations.js +0 -42
- package/dist/database/model-decorators/string-columns.d.ts +0 -9
- package/dist/database/model-decorators/string-columns.js +0 -51
- package/dist/database/model-decorators/table.d.ts +0 -6
- package/dist/database/model-decorators/table.js +0 -57
- package/dist/helpers/console.helpers.d.ts +0 -8
- package/dist/helpers/console.helpers.js +0 -29
- package/dist/resources/refs.d.ts +0 -32
- package/dist/resources/refs.js +0 -35
- package/dist/validations/general-schemas.d.ts +0 -20
- package/dist/validations/general-schemas.js +0 -15
- package/dist/validations/index.d.ts +0 -3
- package/dist/validations/index.js +0 -19
- package/dist/validations/validate-request.middleware.d.ts +0 -2
- package/dist/validations/validate-request.middleware.js +0 -33
- package/dist/validations/validation-locations.d.ts +0 -1
- package/dist/validations/validation-locations.js +0 -4
- package/dist/validations/validations.types.d.ts +0 -23
- package/dist/validations/validations.types.js +0 -21
- package/dist/validator/general-schemas.d.ts +0 -1
- package/dist/validator/general-schemas.js +0 -25
- package/dist/validator/tags.d.ts +0 -1
- package/dist/validator/tags.js +0 -5
|
@@ -84,6 +84,7 @@ class Db {
|
|
|
84
84
|
};
|
|
85
85
|
}
|
|
86
86
|
const deletedAtWhere = paranoid === 'deleted' ? { deletedAt: { [_1.Ops.not]: null } } : {};
|
|
87
|
+
console.log(getFinalAttributes(attributes));
|
|
87
88
|
return {
|
|
88
89
|
attributes: getFinalAttributes(attributes),
|
|
89
90
|
...getIncludeAndWhere(model, include, { ...where, ...searchWhere, ...deletedAtWhere }),
|
|
@@ -191,12 +192,17 @@ function getFinalAttributes(attributes) {
|
|
|
191
192
|
if (!attributes)
|
|
192
193
|
return;
|
|
193
194
|
return attributes.map((attribute) => {
|
|
195
|
+
console.log(attribute);
|
|
194
196
|
if (typeof attribute === 'string')
|
|
195
197
|
return [(0, sequelize_1.col)((0, pangea_helpers_1.camelToSnake)(attribute)), attribute];
|
|
198
|
+
console.log('[alias, column]');
|
|
196
199
|
const [alias, column] = Object.entries(attribute)[0];
|
|
200
|
+
console.log(alias, ': ', column);
|
|
197
201
|
if (typeof column === 'string')
|
|
198
202
|
return [(0, sequelize_1.col)((0, pangea_helpers_1.camelToSnake)(column)), alias];
|
|
203
|
+
console.log('[op, field]');
|
|
199
204
|
const [op, field] = column;
|
|
205
|
+
console.log(op, ': ', field);
|
|
200
206
|
return [(0, sequelize_1.fn)(op, (0, sequelize_1.col)(field)), alias];
|
|
201
207
|
});
|
|
202
208
|
}
|
package/package.json
CHANGED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { Transaction } from 'sequelize';
|
|
2
|
-
export declare function startTransaction(): Promise<Transaction>;
|
|
3
|
-
export declare function disableForeignKeyChecks(t?: Transaction): Promise<[unknown[], unknown]>;
|
|
4
|
-
export declare function enableForeignKeyChecks(t?: Transaction): Promise<[unknown[], unknown]>;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.enableForeignKeyChecks = exports.disableForeignKeyChecks = exports.startTransaction = void 0;
|
|
4
|
-
const init_database_1 = require("./init-database");
|
|
5
|
-
function startTransaction() {
|
|
6
|
-
const dbClient = (0, init_database_1.getDbClient)();
|
|
7
|
-
return dbClient.transaction();
|
|
8
|
-
}
|
|
9
|
-
exports.startTransaction = startTransaction;
|
|
10
|
-
function disableForeignKeyChecks(t) {
|
|
11
|
-
const dbClient = (0, init_database_1.getDbClient)();
|
|
12
|
-
return dbClient.query('SET FOREIGN_KEY_CHECKS = 0', { transaction: t });
|
|
13
|
-
}
|
|
14
|
-
exports.disableForeignKeyChecks = disableForeignKeyChecks;
|
|
15
|
-
function enableForeignKeyChecks(t) {
|
|
16
|
-
const dbClient = (0, init_database_1.getDbClient)();
|
|
17
|
-
return dbClient.query('SET FOREIGN_KEY_CHECKS = 1', { transaction: t });
|
|
18
|
-
}
|
|
19
|
-
exports.enableForeignKeyChecks = enableForeignKeyChecks;
|
|
@@ -1,11 +0,0 @@
|
|
|
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 {};
|
|
@@ -1,69 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
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 {};
|
|
@@ -1,51 +0,0 @@
|
|
|
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;
|
|
@@ -1,6 +0,0 @@
|
|
|
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 {};
|
|
@@ -1,41 +0,0 @@
|
|
|
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;
|
|
@@ -1,20 +0,0 @@
|
|
|
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;
|
|
@@ -1,4 +0,0 @@
|
|
|
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;
|
|
@@ -1,54 +0,0 @@
|
|
|
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;
|
|
@@ -1,23 +0,0 @@
|
|
|
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';
|
|
@@ -1,50 +0,0 @@
|
|
|
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"));
|
|
@@ -1,3 +0,0 @@
|
|
|
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;
|
|
@@ -1,46 +0,0 @@
|
|
|
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;
|
|
@@ -1,10 +0,0 @@
|
|
|
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 {};
|
|
@@ -1,58 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
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 {};
|
|
@@ -1,42 +0,0 @@
|
|
|
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, { model: getModelFn(), eager, required, paranoid, joinDepth, ...restOptions });
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { ColGeneralOptions, ColNullable, ColOptional } from './decorators.types';
|
|
2
|
-
type ColStrOptions = ColGeneralOptions & ColOptional & {
|
|
3
|
-
minLength?: number;
|
|
4
|
-
maxLength?: number;
|
|
5
|
-
regex?: RegExp;
|
|
6
|
-
};
|
|
7
|
-
export declare function ColStr(options?: ColStrOptions & ColNullable): (target: any, propertyName: string) => void;
|
|
8
|
-
export declare function ColText(options?: ColStrOptions): (target: any, propertyName: string) => void;
|
|
9
|
-
export {};
|
|
@@ -1,51 +0,0 @@
|
|
|
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.ColText = exports.ColStr = void 0;
|
|
27
|
-
const seq = __importStar(require("sequelize-typescript"));
|
|
28
|
-
const column_1 = require("./column");
|
|
29
|
-
// resources
|
|
30
|
-
const refs_1 = require("../../resources/refs");
|
|
31
|
-
function ColStr(options = {}) {
|
|
32
|
-
const { maxLength = refs_1.refs.stringLengths.medium, ...restOptions } = options;
|
|
33
|
-
return getStrColumn(seq.DataType.STRING(maxLength), { ...restOptions, maxLength });
|
|
34
|
-
}
|
|
35
|
-
exports.ColStr = ColStr;
|
|
36
|
-
function ColText(options) {
|
|
37
|
-
return getStrColumn(seq.DataType.TEXT, options);
|
|
38
|
-
}
|
|
39
|
-
exports.ColText = ColText;
|
|
40
|
-
// internal functions
|
|
41
|
-
function getStrColumn(type, options = {}) {
|
|
42
|
-
const { minLength = 0, maxLength = Infinity, regex, ...restOptions } = options;
|
|
43
|
-
return (0, column_1.Column)(type, {
|
|
44
|
-
...restOptions,
|
|
45
|
-
fallbackDefaultValue: '',
|
|
46
|
-
validate: {
|
|
47
|
-
len: [minLength, maxLength],
|
|
48
|
-
...(regex ? { is: regex } : {}),
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
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;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export declare function printInfo(label: string | undefined, msg: string): void;
|
|
2
|
-
export declare function printSuccess(label: string | undefined, msg: string): void;
|
|
3
|
-
export declare function printWarning(label: string | undefined, warning: string | Error): void;
|
|
4
|
-
type PrintDangerConfig = {
|
|
5
|
-
printError?: boolean;
|
|
6
|
-
};
|
|
7
|
-
export declare function printDanger(label: string | undefined, danger: string | Error, config?: PrintDangerConfig): void;
|
|
8
|
-
export {};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.printDanger = exports.printWarning = exports.printSuccess = exports.printInfo = void 0;
|
|
4
|
-
function printInfo(label, msg) {
|
|
5
|
-
const finalLabel = label || 'info';
|
|
6
|
-
console.log(`\x1b[34m[${finalLabel}]\x1b[0m`, msg);
|
|
7
|
-
}
|
|
8
|
-
exports.printInfo = printInfo;
|
|
9
|
-
function printSuccess(label, msg) {
|
|
10
|
-
const finalLabel = label || 'success';
|
|
11
|
-
console.log(`\x1b[32m[${finalLabel}]\x1b[0m`, msg);
|
|
12
|
-
}
|
|
13
|
-
exports.printSuccess = printSuccess;
|
|
14
|
-
function printWarning(label, warning) {
|
|
15
|
-
const finalLabel = label || 'warning';
|
|
16
|
-
const msg = warning instanceof Error ? `${warning.name}: ${warning.message}` : warning;
|
|
17
|
-
console.warn(`\x1b[33m[${finalLabel}]\x1b[0m`, msg);
|
|
18
|
-
}
|
|
19
|
-
exports.printWarning = printWarning;
|
|
20
|
-
function printDanger(label, danger, config) {
|
|
21
|
-
const { printError } = config || {};
|
|
22
|
-
const finalLabel = label || 'danger';
|
|
23
|
-
const isError = danger instanceof Error;
|
|
24
|
-
const msg = isError ? `${danger.name}: ${danger.message}` : danger;
|
|
25
|
-
console.error(`\x1b[31m[${finalLabel}]\x1b[0m`, msg);
|
|
26
|
-
if (isError && printError)
|
|
27
|
-
console.error(danger);
|
|
28
|
-
}
|
|
29
|
-
exports.printDanger = printDanger;
|
package/dist/resources/refs.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
export declare const refs: {
|
|
2
|
-
readonly stringLengths: {
|
|
3
|
-
readonly extraShort: 50;
|
|
4
|
-
readonly short: 100;
|
|
5
|
-
readonly medium: 250;
|
|
6
|
-
readonly long: 500;
|
|
7
|
-
readonly extraLong: 1000;
|
|
8
|
-
readonly ultraLong: 1500;
|
|
9
|
-
readonly hyperLong: 2000;
|
|
10
|
-
};
|
|
11
|
-
readonly randomStringLengths: {
|
|
12
|
-
readonly short: 32;
|
|
13
|
-
readonly long: 64;
|
|
14
|
-
};
|
|
15
|
-
readonly colors: {
|
|
16
|
-
readonly coralPink: "#FF6B6B";
|
|
17
|
-
readonly warmOrange: "#FF8855";
|
|
18
|
-
readonly mandarinOrange: "#FFB76A";
|
|
19
|
-
readonly cornYellow: "#FFD54D";
|
|
20
|
-
readonly oliveGreen: "#7A7F42";
|
|
21
|
-
readonly pistachioGreen: "#A6C566";
|
|
22
|
-
readonly aquaMarine: "#5FD4BB";
|
|
23
|
-
readonly polarMint: "#80C9B4";
|
|
24
|
-
readonly arcticBlue: "#7FAFDD";
|
|
25
|
-
readonly ceruleanBlue: "#007BA2";
|
|
26
|
-
readonly cobaltBlue: "#005493";
|
|
27
|
-
readonly smokyGray: "#5F6D6E";
|
|
28
|
-
readonly ashGray: "#A1B1B5";
|
|
29
|
-
readonly softMauve: "#B495C8";
|
|
30
|
-
readonly orchidPurple: "#C66CC6";
|
|
31
|
-
};
|
|
32
|
-
};
|
package/dist/resources/refs.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.refs = void 0;
|
|
4
|
-
exports.refs = {
|
|
5
|
-
stringLengths: {
|
|
6
|
-
extraShort: 50,
|
|
7
|
-
short: 100,
|
|
8
|
-
medium: 250,
|
|
9
|
-
long: 500,
|
|
10
|
-
extraLong: 1000,
|
|
11
|
-
ultraLong: 1500,
|
|
12
|
-
hyperLong: 2000,
|
|
13
|
-
},
|
|
14
|
-
randomStringLengths: {
|
|
15
|
-
short: 32,
|
|
16
|
-
long: 64,
|
|
17
|
-
},
|
|
18
|
-
colors: {
|
|
19
|
-
coralPink: '#FF6B6B',
|
|
20
|
-
warmOrange: '#FF8855',
|
|
21
|
-
mandarinOrange: '#FFB76A',
|
|
22
|
-
cornYellow: '#FFD54D',
|
|
23
|
-
oliveGreen: '#7A7F42',
|
|
24
|
-
pistachioGreen: '#A6C566',
|
|
25
|
-
aquaMarine: '#5FD4BB',
|
|
26
|
-
polarMint: '#80C9B4',
|
|
27
|
-
arcticBlue: '#7FAFDD',
|
|
28
|
-
ceruleanBlue: '#007BA2',
|
|
29
|
-
cobaltBlue: '#005493',
|
|
30
|
-
smokyGray: '#5F6D6E',
|
|
31
|
-
ashGray: '#A1B1B5',
|
|
32
|
-
softMauve: '#B495C8',
|
|
33
|
-
orchidPurple: '#C66CC6',
|
|
34
|
-
},
|
|
35
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export type IdSchema = ModelId;
|
|
2
|
-
export declare const idSchema: import("joi").NumberSchema<number>;
|
|
3
|
-
export type IdSchemaOptional = IdSchema | 0;
|
|
4
|
-
export declare const idSchemaOptional: import("joi").NumberSchema<number>;
|
|
5
|
-
export type ArrayOfIdsSchema = IdSchema[];
|
|
6
|
-
export declare const arrayOfIdsSchema: import("joi").ArraySchema<any[]>;
|
|
7
|
-
export interface ParamsIdSchema {
|
|
8
|
-
id: IdSchema;
|
|
9
|
-
}
|
|
10
|
-
export declare const paramsIdSchema: import("joi").ObjectSchema<any>;
|
|
11
|
-
export interface QueryGetManySchema {
|
|
12
|
-
page?: number | null;
|
|
13
|
-
pageSize?: number | null;
|
|
14
|
-
search?: string | null;
|
|
15
|
-
}
|
|
16
|
-
export declare const queryGetManySchemaObject: {
|
|
17
|
-
page: import("joi").NumberSchema<number>;
|
|
18
|
-
pageSize: import("joi").NumberSchema<number>;
|
|
19
|
-
search: import("joi").StringSchema<string>;
|
|
20
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.queryGetManySchemaObject = exports.paramsIdSchema = exports.arrayOfIdsSchema = exports.idSchemaOptional = exports.idSchema = void 0;
|
|
4
|
-
const express_validation_1 = require("express-validation");
|
|
5
|
-
exports.idSchema = express_validation_1.Joi.number().integer().min(1);
|
|
6
|
-
exports.idSchemaOptional = exports.idSchema.allow(0);
|
|
7
|
-
exports.arrayOfIdsSchema = express_validation_1.Joi.array().items(exports.idSchema);
|
|
8
|
-
exports.paramsIdSchema = express_validation_1.Joi.object({
|
|
9
|
-
id: exports.idSchema.required(),
|
|
10
|
-
});
|
|
11
|
-
exports.queryGetManySchemaObject = {
|
|
12
|
-
page: express_validation_1.Joi.number().integer().min(0).allow(null),
|
|
13
|
-
pageSize: express_validation_1.Joi.number().integer().min(0).allow(null),
|
|
14
|
-
search: express_validation_1.Joi.string().allow('').allow(null),
|
|
15
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
__exportStar(require("./general-schemas"), exports);
|
|
18
|
-
__exportStar(require("./validate-request.middleware"), exports);
|
|
19
|
-
__exportStar(require("./validations.types"), exports);
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateRequest = void 0;
|
|
4
|
-
const express_validation_1 = require("express-validation");
|
|
5
|
-
const validation_locations_1 = require("./validation-locations");
|
|
6
|
-
// helpers
|
|
7
|
-
const helpers_1 = require("pangea-backend/helpers");
|
|
8
|
-
function validateRequest(validation) {
|
|
9
|
-
return async function (req, res, next) {
|
|
10
|
-
if (!validation) {
|
|
11
|
-
(0, helpers_1.printWarning)('validation', 'no data validation');
|
|
12
|
-
removeUnvalidatedData(req);
|
|
13
|
-
next();
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
const evOptions = { context: true, keyByField: true };
|
|
17
|
-
const validationOptions = { allowUnknown: true, stripUnknown: true, convert: true, dateFormat: 'iso' };
|
|
18
|
-
await (0, express_validation_1.validate)(validation, evOptions, validationOptions)(req, res, (err) => {
|
|
19
|
-
if (err)
|
|
20
|
-
helpers_1.AppError.Throw({ statusCodeName: 'BAD_REQUEST', errorCode: 'INVALID_INPUT_DATA', err });
|
|
21
|
-
removeUnvalidatedData(req, validation);
|
|
22
|
-
next();
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
exports.validateRequest = validateRequest;
|
|
27
|
-
// internal functions
|
|
28
|
-
function removeUnvalidatedData(req, validation) {
|
|
29
|
-
for (const location of validation_locations_1.validationLocations) {
|
|
30
|
-
if (!validation || !validation[location])
|
|
31
|
-
req[location] = {};
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const validationLocations: readonly ["params", "query", "body"];
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import Joi from 'joi';
|
|
2
|
-
import { validationLocations } from './validation-locations';
|
|
3
|
-
import type { ParamsIdSchema, QueryGetManySchema } from './general-schemas';
|
|
4
|
-
import type { PlainObject, EmptyObject } from 'pangea-helpers';
|
|
5
|
-
export type ValidationLocation = (typeof validationLocations)[number];
|
|
6
|
-
export type ValidationRoute = {
|
|
7
|
-
[key in ValidationLocation]?: Joi.ObjectSchema;
|
|
8
|
-
};
|
|
9
|
-
export declare class ValidationRouteType<P extends PlainObject = EmptyObject, Q extends PlainObject = EmptyObject, B extends PlainObject = EmptyObject> {
|
|
10
|
-
params: P;
|
|
11
|
-
query: Q;
|
|
12
|
-
body: B;
|
|
13
|
-
}
|
|
14
|
-
export declare class ValidationRouteTypeGetOne extends ValidationRouteType<ParamsIdSchema, EmptyObject, EmptyObject> {
|
|
15
|
-
}
|
|
16
|
-
export declare class ValidationRouteTypeGetMany<Q extends PlainObject = EmptyObject> extends ValidationRouteType<EmptyObject, QueryGetManySchema & Q, EmptyObject> {
|
|
17
|
-
}
|
|
18
|
-
export declare class ValidationRouteTypePostOne<B extends PlainObject = PlainObject> extends ValidationRouteType<EmptyObject, EmptyObject, B> {
|
|
19
|
-
}
|
|
20
|
-
export declare class ValidationRouteTypePutOne<B extends PlainObject = PlainObject> extends ValidationRouteType<ParamsIdSchema, EmptyObject, B> {
|
|
21
|
-
}
|
|
22
|
-
export declare class ValidationRouteTypeDeleteOne extends ValidationRouteType<ParamsIdSchema, EmptyObject, EmptyObject> {
|
|
23
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ValidationRouteTypeDeleteOne = exports.ValidationRouteTypePutOne = exports.ValidationRouteTypePostOne = exports.ValidationRouteTypeGetMany = exports.ValidationRouteTypeGetOne = exports.ValidationRouteType = void 0;
|
|
4
|
-
class ValidationRouteType {
|
|
5
|
-
}
|
|
6
|
-
exports.ValidationRouteType = ValidationRouteType;
|
|
7
|
-
class ValidationRouteTypeGetOne extends ValidationRouteType {
|
|
8
|
-
}
|
|
9
|
-
exports.ValidationRouteTypeGetOne = ValidationRouteTypeGetOne;
|
|
10
|
-
class ValidationRouteTypeGetMany extends ValidationRouteType {
|
|
11
|
-
}
|
|
12
|
-
exports.ValidationRouteTypeGetMany = ValidationRouteTypeGetMany;
|
|
13
|
-
class ValidationRouteTypePostOne extends ValidationRouteType {
|
|
14
|
-
}
|
|
15
|
-
exports.ValidationRouteTypePostOne = ValidationRouteTypePostOne;
|
|
16
|
-
class ValidationRouteTypePutOne extends ValidationRouteType {
|
|
17
|
-
}
|
|
18
|
-
exports.ValidationRouteTypePutOne = ValidationRouteTypePutOne;
|
|
19
|
-
class ValidationRouteTypeDeleteOne extends ValidationRouteType {
|
|
20
|
-
}
|
|
21
|
-
exports.ValidationRouteTypeDeleteOne = ValidationRouteTypeDeleteOne;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// import { Joi } from 'express-validation';
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
// export type IdSchema = ModelId;
|
|
5
|
-
// export const idSchema = Joi.number().integer().min(1);
|
|
6
|
-
// export type IdSchemaOptional = IdSchema | 0;
|
|
7
|
-
// export const idSchemaOptional = idSchema.allow(0);
|
|
8
|
-
// export type ArrayOfIdsSchema = IdSchema[];
|
|
9
|
-
// export const arrayOfIdsSchema = Joi.array().items(idSchema);
|
|
10
|
-
// export interface ParamsIdSchema {
|
|
11
|
-
// id: IdSchema;
|
|
12
|
-
// }
|
|
13
|
-
// export const paramsIdSchema = Joi.object({
|
|
14
|
-
// id: idSchema.required(),
|
|
15
|
-
// });
|
|
16
|
-
// export interface QueryGetManySchema {
|
|
17
|
-
// page?: number | null;
|
|
18
|
-
// pageSize?: number | null;
|
|
19
|
-
// search?: string | null;
|
|
20
|
-
// }
|
|
21
|
-
// export const queryGetManySchemaObject = {
|
|
22
|
-
// page: Joi.number().integer().min(0).allow(null),
|
|
23
|
-
// pageSize: Joi.number().integer().min(0).allow(null),
|
|
24
|
-
// search: Joi.string().allow('').allow(null),
|
|
25
|
-
// };
|
package/dist/validator/tags.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { tags as val } from 'typia';
|
package/dist/validator/tags.js
DELETED