@xrystal/core 3.6.0 → 3.6.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/package.json +1 -1
- package/source/loader/logger/index.d.ts +1 -1
- package/source/loader/logger/index.js +17 -25
- package/x/dist/index.d.ts +0 -2
- package/x/dist/index.js +0 -8
- package/x/dist/loader/configs/index.d.ts +0 -13
- package/x/dist/loader/configs/index.js +0 -17
- package/x/dist/loader/events/index.d.ts +0 -6
- package/x/dist/loader/events/index.js +0 -25
- package/x/dist/loader/index.d.ts +0 -6
- package/x/dist/loader/index.js +0 -6
- package/x/dist/loader/localizations/index.d.ts +0 -14
- package/x/dist/loader/localizations/index.js +0 -32
- package/x/dist/loader/logger/index.d.ts +0 -28
- package/x/dist/loader/logger/index.js +0 -179
- package/x/dist/loader/system/index.d.ts +0 -8
- package/x/dist/loader/system/index.js +0 -14
- package/x/dist/project/index.d.ts +0 -6
- package/x/dist/project/index.js +0 -63
- package/x/dist/utils/constants/index.d.ts +0 -8
- package/x/dist/utils/constants/index.js +0 -10
- package/x/dist/utils/helpers/date/index.d.ts +0 -16
- package/x/dist/utils/helpers/date/index.js +0 -48
- package/x/dist/utils/helpers/filters/index.d.ts +0 -17
- package/x/dist/utils/helpers/filters/index.js +0 -44
- package/x/dist/utils/helpers/hash/crypto.d.ts +0 -3
- package/x/dist/utils/helpers/hash/crypto.js +0 -22
- package/x/dist/utils/helpers/id/index.d.ts +0 -13
- package/x/dist/utils/helpers/id/index.js +0 -24
- package/x/dist/utils/helpers/index.d.ts +0 -17
- package/x/dist/utils/helpers/index.js +0 -17
- package/x/dist/utils/helpers/ip/index.d.ts +0 -1
- package/x/dist/utils/helpers/ip/index.js +0 -3
- package/x/dist/utils/helpers/is/index.d.ts +0 -11
- package/x/dist/utils/helpers/is/index.js +0 -35
- package/x/dist/utils/helpers/locales/index.d.ts +0 -52
- package/x/dist/utils/helpers/locales/index.js +0 -161
- package/x/dist/utils/helpers/locales copy/index.d.ts +0 -52
- package/x/dist/utils/helpers/locales copy/index.js +0 -161
- package/x/dist/utils/helpers/math/index.d.ts +0 -2
- package/x/dist/utils/helpers/math/index.js +0 -14
- package/x/dist/utils/helpers/objects/index.d.ts +0 -1
- package/x/dist/utils/helpers/objects/index.js +0 -55
- package/x/dist/utils/helpers/path/index.d.ts +0 -2
- package/x/dist/utils/helpers/path/index.js +0 -4
- package/x/dist/utils/helpers/regex/checkSpecialRegexControl.d.ts +0 -1
- package/x/dist/utils/helpers/regex/checkSpecialRegexControl.js +0 -3
- package/x/dist/utils/helpers/string/index.d.ts +0 -1
- package/x/dist/utils/helpers/string/index.js +0 -9
- package/x/dist/utils/helpers/timer/index.d.ts +0 -3
- package/x/dist/utils/helpers/timer/index.js +0 -5
- package/x/dist/utils/helpers/tmp/index.d.ts +0 -8
- package/x/dist/utils/helpers/tmp/index.js +0 -109
- package/x/dist/utils/helpers/validates/index.d.ts +0 -5
- package/x/dist/utils/helpers/validates/index.js +0 -20
- package/x/dist/utils/index.d.ts +0 -3
- package/x/dist/utils/index.js +0 -3
- package/x/dist/utils/models/classes/class.controller.d.ts +0 -80
- package/x/dist/utils/models/classes/class.controller.js +0 -164
- package/x/dist/utils/models/classes/class.response.d.ts +0 -17
- package/x/dist/utils/models/classes/class.response.js +0 -37
- package/x/dist/utils/models/classes/class.services.d.ts +0 -129
- package/x/dist/utils/models/classes/class.services.js +0 -344
- package/x/dist/utils/models/classes/class.tmp-file-loader.d.ts +0 -8
- package/x/dist/utils/models/classes/class.tmp-file-loader.js +0 -38
- package/x/dist/utils/models/classes/class.x.d.ts +0 -12
- package/x/dist/utils/models/classes/class.x.js +0 -16
- package/x/dist/utils/models/enums/index.d.ts +0 -117
- package/x/dist/utils/models/enums/index.js +0 -133
- package/x/dist/utils/models/index.d.ts +0 -8
- package/x/dist/utils/models/index.js +0 -8
- package/x/dist/utils/models/types/index.d.ts +0 -3
- package/x/dist/utils/models/types/index.js +0 -2
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export function calcPercentace(value, percentage) {
|
|
2
|
-
if (typeof value !== "number" || typeof percentage !== "number") {
|
|
3
|
-
throw new Error("Değerler sayısal olmalıdır.");
|
|
4
|
-
}
|
|
5
|
-
return (value * percentage) / 100;
|
|
6
|
-
}
|
|
7
|
-
export function bankersRounding(value, decimals = 2) {
|
|
8
|
-
const factor = Math.pow(10, decimals);
|
|
9
|
-
const rounded = Math.round(value * factor);
|
|
10
|
-
const isHalf = (value * factor) % 1 === 0.5;
|
|
11
|
-
return isHalf && rounded % 2 !== 0
|
|
12
|
-
? (rounded - 1) / factor
|
|
13
|
-
: rounded / factor;
|
|
14
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function pickProps<T extends object, K extends keyof T>(obj: T | null | undefined, props: (K | string)[]): Pick<T, K>;
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
export function pickProps(obj, props) {
|
|
2
|
-
if (!obj) {
|
|
3
|
-
return {};
|
|
4
|
-
}
|
|
5
|
-
const negativeProps = new Set();
|
|
6
|
-
const positiveProps = new Set();
|
|
7
|
-
for (const p of props) {
|
|
8
|
-
if (typeof p === 'string' && p.startsWith('-')) {
|
|
9
|
-
negativeProps.add(p.substring(1));
|
|
10
|
-
}
|
|
11
|
-
else {
|
|
12
|
-
positiveProps.add(p);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function getNestedValue(o, path) {
|
|
16
|
-
return path.reduce((acc, key) => (acc && acc[key] !== undefined ? acc[key] : undefined), o);
|
|
17
|
-
}
|
|
18
|
-
function setNestedValue(o, path, value) {
|
|
19
|
-
let current = o;
|
|
20
|
-
for (let i = 0; i < path.length - 1; i++) {
|
|
21
|
-
if (!(path[i] in current))
|
|
22
|
-
current[path[i]] = {};
|
|
23
|
-
current = current[path[i]];
|
|
24
|
-
}
|
|
25
|
-
current[path[path.length - 1]] = value;
|
|
26
|
-
}
|
|
27
|
-
if (negativeProps.size > 0) {
|
|
28
|
-
const result = {};
|
|
29
|
-
function recurse(currentObj, currentPath = [], resObj) {
|
|
30
|
-
for (const key in currentObj) {
|
|
31
|
-
const fullPath = [...currentPath, key].join('.');
|
|
32
|
-
if (!Array.from(negativeProps).some(neg => fullPath === neg || fullPath.startsWith(neg + '.'))) {
|
|
33
|
-
if (typeof currentObj[key] === 'object' && currentObj[key] !== null && !Array.isArray(currentObj[key])) {
|
|
34
|
-
resObj[key] = {};
|
|
35
|
-
recurse(currentObj[key], [...currentPath, key], resObj[key]);
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
resObj[key] = currentObj[key];
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
recurse(obj, [], result);
|
|
44
|
-
return result;
|
|
45
|
-
}
|
|
46
|
-
const result = {};
|
|
47
|
-
for (const p of positiveProps) {
|
|
48
|
-
const path = p.split('.');
|
|
49
|
-
const value = getNestedValue(obj, path);
|
|
50
|
-
if (value !== undefined) {
|
|
51
|
-
setNestedValue(result, path, value);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return result;
|
|
55
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function checkSpecialRegexControl(str: string, regex: RegExp): boolean;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function cleanStringForNormalize(input: string): string;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export declare function resolveObjWithHandlebars(obj: any, context: any): any;
|
|
2
|
-
export declare function findFileRecursively(startDir: string, baseName: string, extName?: string, excludedDirs?: string[]): string | null;
|
|
3
|
-
export declare const argvsConverter: (argvs: string) => {
|
|
4
|
-
[key: string]: string;
|
|
5
|
-
};
|
|
6
|
-
export declare const findExt: (filename: string) => string;
|
|
7
|
-
export declare const changeExtensions: (filename: string, repalceExt: string) => string;
|
|
8
|
-
export declare const webFileFindEngine: (folderPath: string) => string[];
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import Handlebars from 'handlebars';
|
|
4
|
-
import { SupportFileExtensionsEnum } from "../../index.js";
|
|
5
|
-
export function resolveObjWithHandlebars(obj, context) {
|
|
6
|
-
if (typeof obj === "string") {
|
|
7
|
-
const compileResult = Handlebars.compile(obj);
|
|
8
|
-
return compileResult(context);
|
|
9
|
-
}
|
|
10
|
-
else if (typeof obj === "object" && obj !== null) {
|
|
11
|
-
for (const key in obj) {
|
|
12
|
-
obj[key] = resolveObjWithHandlebars(obj[key], context);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
return obj;
|
|
16
|
-
}
|
|
17
|
-
export function findFileRecursively(startDir, baseName, extName = '', excludedDirs = ['node_modules', '.git']) {
|
|
18
|
-
if (typeof startDir !== 'string' || !fs.existsSync(startDir)) {
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
const targetName = baseName + (extName.startsWith('.') ? extName : (extName ? `.${extName}` : ''));
|
|
22
|
-
try {
|
|
23
|
-
const entries = fs.readdirSync(startDir, { withFileTypes: true });
|
|
24
|
-
for (const entry of entries) {
|
|
25
|
-
const fullPath = path.join(startDir, entry.name);
|
|
26
|
-
if (entry.isFile()) {
|
|
27
|
-
if (!extName) {
|
|
28
|
-
const entryExt = path.extname(entry.name);
|
|
29
|
-
const entryBase = path.basename(entry.name, entryExt);
|
|
30
|
-
if (entryBase === baseName) {
|
|
31
|
-
return fullPath;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
if (entry.name === targetName) {
|
|
36
|
-
return fullPath;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
if (entry.isDirectory()) {
|
|
41
|
-
const isHiddenOrExcluded = entry.name.startsWith('.') || excludedDirs.includes(entry.name);
|
|
42
|
-
if (isHiddenOrExcluded) {
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
const foundPath = findFileRecursively(fullPath, baseName, extName, excludedDirs);
|
|
46
|
-
if (foundPath) {
|
|
47
|
-
return foundPath;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
catch (error) {
|
|
54
|
-
if (error.code === 'EACCES') {
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
// => ---
|
|
61
|
-
export const argvsConverter = (argvs) => {
|
|
62
|
-
const reelArgvs = argvs?.slice(2);
|
|
63
|
-
const reelConvertedArgvs = {};
|
|
64
|
-
reelArgvs.forEach((argv) => {
|
|
65
|
-
if (argv.startsWith('--')) {
|
|
66
|
-
console.log(argv);
|
|
67
|
-
const [key, value] = argv.split('=');
|
|
68
|
-
reelConvertedArgvs[key.replace('--', '')] = value || '';
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
return reelConvertedArgvs;
|
|
72
|
-
};
|
|
73
|
-
export const findExt = (filename) => {
|
|
74
|
-
const split = filename.split('.');
|
|
75
|
-
return split[split.length - 1];
|
|
76
|
-
};
|
|
77
|
-
export const changeExtensions = (filename, repalceExt) => {
|
|
78
|
-
return filename.replace(findExt(filename), repalceExt);
|
|
79
|
-
};
|
|
80
|
-
export const webFileFindEngine = (folderPath) => {
|
|
81
|
-
try {
|
|
82
|
-
const files = fs.readdirSync(folderPath);
|
|
83
|
-
const fullFileExtension = Object.values(SupportFileExtensionsEnum).map(ext => '.' + ext);
|
|
84
|
-
const filteredFiles = [];
|
|
85
|
-
files.forEach(file => {
|
|
86
|
-
const filePath = path.join(folderPath, file);
|
|
87
|
-
const isDirectory = fs.statSync(filePath).isDirectory();
|
|
88
|
-
if (isDirectory) {
|
|
89
|
-
const subFolderFiles = webFileFindEngine(filePath);
|
|
90
|
-
subFolderFiles.forEach(subFile => {
|
|
91
|
-
filteredFiles.push(path.join(file, subFile).split('\\').join('/')); // Alt klasördeki dosya yolunu, ana klasör yoluna ekleyerek dosyları benzersiz yapıyoruz sonda ise diğer işletim sistemlerien uygun hale getiriyoruz
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
for (const ffn of fullFileExtension) {
|
|
96
|
-
if (file.endsWith(ffn)) {
|
|
97
|
-
filteredFiles.push(file);
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
return filteredFiles;
|
|
104
|
-
}
|
|
105
|
-
catch (error /* unknow */) {
|
|
106
|
-
console.error('Error: ', error.message);
|
|
107
|
-
return [];
|
|
108
|
-
}
|
|
109
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export const validateScopes = ({ scopes, permissions, resources }) => {
|
|
2
|
-
const parsedScopes = scopes.split(' ');
|
|
3
|
-
function dublicateControl(parsedScopes) {
|
|
4
|
-
const uniqueScopes = new Set(parsedScopes);
|
|
5
|
-
if (uniqueScopes.size !== parsedScopes.length) {
|
|
6
|
-
return true;
|
|
7
|
-
}
|
|
8
|
-
return false;
|
|
9
|
-
}
|
|
10
|
-
if (dublicateControl(parsedScopes)) {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
const isInvalid = parsedScopes.some((scope) => {
|
|
14
|
-
const [resource, permission] = scope.split(':');
|
|
15
|
-
const isValidResource = resources.includes(resource);
|
|
16
|
-
const isValidPermission = permissions.includes(permission);
|
|
17
|
-
return !isValidResource || !isValidPermission;
|
|
18
|
-
});
|
|
19
|
-
return !isInvalid;
|
|
20
|
-
};
|
package/x/dist/utils/index.d.ts
DELETED
package/x/dist/utils/index.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { ProtocolEnum, ResponseSchema } from '../../index';
|
|
2
|
-
export interface CustomRequest {
|
|
3
|
-
accounts?: any;
|
|
4
|
-
query: Record<string, any>;
|
|
5
|
-
url: string;
|
|
6
|
-
method: string;
|
|
7
|
-
headers: Record<string, string>;
|
|
8
|
-
body?: any;
|
|
9
|
-
params?: Record<string, string>;
|
|
10
|
-
t?: Function;
|
|
11
|
-
}
|
|
12
|
-
export interface CustomResponse {
|
|
13
|
-
status: (code: number) => CustomResponse;
|
|
14
|
-
send: (data: any) => any;
|
|
15
|
-
json: (data: any) => any;
|
|
16
|
-
locals: Record<string, any>;
|
|
17
|
-
}
|
|
18
|
-
export interface ReturnChecksCallbackFuncInterface {
|
|
19
|
-
status?: boolean;
|
|
20
|
-
message?: string;
|
|
21
|
-
payload?: any;
|
|
22
|
-
code?: number;
|
|
23
|
-
response?: Function;
|
|
24
|
-
invalid?: boolean;
|
|
25
|
-
}
|
|
26
|
-
export interface ReturnLogicCallbackFuncInterface {
|
|
27
|
-
status?: boolean;
|
|
28
|
-
message?: string;
|
|
29
|
-
payload?: any;
|
|
30
|
-
code?: number;
|
|
31
|
-
response?: Function;
|
|
32
|
-
}
|
|
33
|
-
export interface ReturnResponseCallbackFuncInterface {
|
|
34
|
-
message: Array<string>;
|
|
35
|
-
response?: Function;
|
|
36
|
-
}
|
|
37
|
-
export type Sort = {
|
|
38
|
-
key: string;
|
|
39
|
-
value: number;
|
|
40
|
-
};
|
|
41
|
-
declare abstract class Controller {
|
|
42
|
-
private logger;
|
|
43
|
-
protected protocol: ProtocolEnum | null;
|
|
44
|
-
protected req: CustomRequest | null;
|
|
45
|
-
protected res: CustomResponse | null;
|
|
46
|
-
constructor({ protocol, req, res, ctx }: {
|
|
47
|
-
protocol: ProtocolEnum;
|
|
48
|
-
req?: any;
|
|
49
|
-
res?: any;
|
|
50
|
-
ctx?: any;
|
|
51
|
-
});
|
|
52
|
-
protected responseProtocolSwitch: ({ protocol, req, res, resStatus, context }: {
|
|
53
|
-
protocol: ProtocolEnum;
|
|
54
|
-
req: CustomRequest;
|
|
55
|
-
res: CustomResponse;
|
|
56
|
-
resStatus?: number;
|
|
57
|
-
context: (helpers: {
|
|
58
|
-
localeLanguageConverter?: Function;
|
|
59
|
-
}) => ResponseSchema;
|
|
60
|
-
}) => Promise<any>;
|
|
61
|
-
protected parsedQuerys: (url: string) => Record<string, any>;
|
|
62
|
-
protected log: (level: string, message: string) => Promise<void>;
|
|
63
|
-
}
|
|
64
|
-
export declare class ControllerSchema extends Controller {
|
|
65
|
-
schema({ checks, logic, response, }: {
|
|
66
|
-
checks?: (args: {
|
|
67
|
-
payload: any;
|
|
68
|
-
convertedPayload: any;
|
|
69
|
-
}) => Promise<ReturnChecksCallbackFuncInterface | Array<any>>;
|
|
70
|
-
logic: (args: {
|
|
71
|
-
payload: any;
|
|
72
|
-
convertedPayload: any;
|
|
73
|
-
}) => Promise<ReturnLogicCallbackFuncInterface>;
|
|
74
|
-
response?: (args: {
|
|
75
|
-
payload: any;
|
|
76
|
-
convertedPayload: any;
|
|
77
|
-
}) => Promise<ReturnResponseCallbackFuncInterface>;
|
|
78
|
-
}): Promise<any>;
|
|
79
|
-
}
|
|
80
|
-
export { Controller };
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import qs from 'qs';
|
|
2
|
-
import { LoggerService } from '../../../loader';
|
|
3
|
-
import { responseMessageHelper, ResponseSchema, x } from '../../index';
|
|
4
|
-
class Controller {
|
|
5
|
-
logger = x.get(LoggerService);
|
|
6
|
-
protocol = null;
|
|
7
|
-
req = null;
|
|
8
|
-
res = null;
|
|
9
|
-
constructor({ protocol, req, res, ctx }) {
|
|
10
|
-
this.protocol = protocol;
|
|
11
|
-
if (ctx) {
|
|
12
|
-
this.req = {
|
|
13
|
-
url: ctx.request.url,
|
|
14
|
-
method: ctx.request.method,
|
|
15
|
-
headers: Object.fromEntries(ctx.request.headers),
|
|
16
|
-
body: ctx.body,
|
|
17
|
-
params: ctx.params,
|
|
18
|
-
query: ctx.query || {},
|
|
19
|
-
accounts: ctx.user || ctx.accounts,
|
|
20
|
-
t: ctx.t
|
|
21
|
-
};
|
|
22
|
-
this.res = {
|
|
23
|
-
locals: {},
|
|
24
|
-
status(code) {
|
|
25
|
-
this.locals._code = code;
|
|
26
|
-
return this;
|
|
27
|
-
},
|
|
28
|
-
send(data) {
|
|
29
|
-
return new Response(JSON.stringify(data), {
|
|
30
|
-
status: this.locals._code || 200,
|
|
31
|
-
headers: { 'content-type': 'application/json' }
|
|
32
|
-
});
|
|
33
|
-
},
|
|
34
|
-
json(data) {
|
|
35
|
-
return this.send(data);
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
this.req = {
|
|
41
|
-
url: req?.originalUrl || req?.url,
|
|
42
|
-
method: req?.method,
|
|
43
|
-
headers: req?.headers || {},
|
|
44
|
-
body: req?.body,
|
|
45
|
-
params: req?.params,
|
|
46
|
-
query: req?.query || {},
|
|
47
|
-
accounts: req?.accounts,
|
|
48
|
-
t: req?.t
|
|
49
|
-
};
|
|
50
|
-
this.res = {
|
|
51
|
-
locals: res?.locals || {},
|
|
52
|
-
status(code) {
|
|
53
|
-
res.status(code);
|
|
54
|
-
return this;
|
|
55
|
-
},
|
|
56
|
-
send(data) {
|
|
57
|
-
return res.send(data);
|
|
58
|
-
},
|
|
59
|
-
json(data) {
|
|
60
|
-
return res.json(data);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
responseProtocolSwitch = async ({ protocol, req, res, resStatus = 200, context }) => {
|
|
66
|
-
const responseData = context({ localeLanguageConverter: req.t });
|
|
67
|
-
return res.status(resStatus).send(responseData);
|
|
68
|
-
};
|
|
69
|
-
parsedQuerys = (url) => {
|
|
70
|
-
const queryString = url.includes('?') ? url.split('?')[1] : '';
|
|
71
|
-
if (!queryString)
|
|
72
|
-
return {};
|
|
73
|
-
return qs.parse(queryString, { decoder: decodeURIComponent });
|
|
74
|
-
};
|
|
75
|
-
log = async (level, message) => {
|
|
76
|
-
this.logger.winston.log({ level, message });
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
export class ControllerSchema extends Controller {
|
|
80
|
-
async schema({ checks, logic, response, }) {
|
|
81
|
-
const payload = { req: this.req, res: this.res };
|
|
82
|
-
const convertedPayload = {
|
|
83
|
-
...payload,
|
|
84
|
-
parsedQuerys: this.parsedQuerys(this.req.url)
|
|
85
|
-
};
|
|
86
|
-
try {
|
|
87
|
-
if (checks) {
|
|
88
|
-
const checkResult = await checks({ payload, convertedPayload });
|
|
89
|
-
let isInvalid = false;
|
|
90
|
-
if (Array.isArray(checkResult)) {
|
|
91
|
-
isInvalid = !checkResult.every(c => c !== undefined && c !== null && c !== "");
|
|
92
|
-
}
|
|
93
|
-
else if (typeof checkResult === 'object' && checkResult.message) {
|
|
94
|
-
return await this.responseProtocolSwitch({
|
|
95
|
-
protocol: this.protocol,
|
|
96
|
-
req: this.req,
|
|
97
|
-
res: this.res,
|
|
98
|
-
context: () => new ResponseSchema({
|
|
99
|
-
status: checkResult.status || false,
|
|
100
|
-
message: checkResult.message,
|
|
101
|
-
payload: checkResult.payload,
|
|
102
|
-
code: checkResult.code
|
|
103
|
-
}).getResponse
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
if (isInvalid) {
|
|
107
|
-
return await this.responseProtocolSwitch({
|
|
108
|
-
protocol: this.protocol,
|
|
109
|
-
req: this.req,
|
|
110
|
-
res: this.res,
|
|
111
|
-
resStatus: 400,
|
|
112
|
-
context: ({ localeLanguageConverter }) => new ResponseSchema({
|
|
113
|
-
status: false,
|
|
114
|
-
message: responseMessageHelper.schemaMissingDataChecks(localeLanguageConverter)
|
|
115
|
-
}).getResponse
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
const logicResult = await logic({ payload, convertedPayload });
|
|
120
|
-
if (logicResult.response instanceof Function) {
|
|
121
|
-
return logicResult.response(logicResult.payload);
|
|
122
|
-
}
|
|
123
|
-
if (logicResult.message) {
|
|
124
|
-
return await this.responseProtocolSwitch({
|
|
125
|
-
protocol: this.protocol,
|
|
126
|
-
req: this.req,
|
|
127
|
-
res: this.res,
|
|
128
|
-
resStatus: 400,
|
|
129
|
-
context: () => new ResponseSchema({
|
|
130
|
-
status: logicResult.status || false,
|
|
131
|
-
message: logicResult.message,
|
|
132
|
-
payload: logicResult.payload,
|
|
133
|
-
code: logicResult.code
|
|
134
|
-
}).getResponse
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
if (response) {
|
|
138
|
-
const resResult = await response({ payload, convertedPayload });
|
|
139
|
-
if (resResult.response instanceof Function) {
|
|
140
|
-
return resResult.response(resResult);
|
|
141
|
-
}
|
|
142
|
-
return await this.responseProtocolSwitch({
|
|
143
|
-
protocol: this.protocol,
|
|
144
|
-
req: this.req,
|
|
145
|
-
res: this.res,
|
|
146
|
-
resStatus: 200,
|
|
147
|
-
context: ({ localeLanguageConverter }) => new ResponseSchema({
|
|
148
|
-
status: true,
|
|
149
|
-
message: responseMessageHelper.successFully(resResult.message[0], resResult.message[1], localeLanguageConverter),
|
|
150
|
-
payload: logicResult.payload
|
|
151
|
-
}).getResponse
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
catch (error) {
|
|
156
|
-
await this.log('error', `Schema Error: ${error.message}`);
|
|
157
|
-
return this.res.status(500).send({
|
|
158
|
-
status: false,
|
|
159
|
-
message: error.message
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
export { Controller };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export interface PayloadSchemaInterface {
|
|
2
|
-
status: boolean;
|
|
3
|
-
message: string;
|
|
4
|
-
payload?: any;
|
|
5
|
-
[key: string]: any;
|
|
6
|
-
code?: number;
|
|
7
|
-
}
|
|
8
|
-
export declare class ResponseSchema {
|
|
9
|
-
constructor({ status, message, payload, code }: PayloadSchemaInterface);
|
|
10
|
-
status: boolean;
|
|
11
|
-
message: string;
|
|
12
|
-
payload: any;
|
|
13
|
-
code: number;
|
|
14
|
-
validData(): any;
|
|
15
|
-
statusCodeGenerator(): number;
|
|
16
|
-
get getResponse(): ResponseSchema;
|
|
17
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
export class ResponseSchema {
|
|
2
|
-
constructor({ status = false, message = '', payload = null, code = 0 }) {
|
|
3
|
-
this.status = status;
|
|
4
|
-
this.message = message;
|
|
5
|
-
this.payload = payload;
|
|
6
|
-
this.code = code;
|
|
7
|
-
}
|
|
8
|
-
status;
|
|
9
|
-
message;
|
|
10
|
-
payload;
|
|
11
|
-
code;
|
|
12
|
-
validData() {
|
|
13
|
-
return this.payload; // => ileride burada değiştirmeler olabilir.
|
|
14
|
-
}
|
|
15
|
-
statusCodeGenerator() {
|
|
16
|
-
if (this.status === false && this.code === 401 || this.code === 403) {
|
|
17
|
-
return Number(this.code);
|
|
18
|
-
}
|
|
19
|
-
else if (this.status === true) {
|
|
20
|
-
return this.code = 0;
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
return this.code = 1;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
get getResponse() {
|
|
27
|
-
let response = {
|
|
28
|
-
status: this.status,
|
|
29
|
-
message: this.message,
|
|
30
|
-
};
|
|
31
|
-
if (this.payload !== null) {
|
|
32
|
-
response.payload = this.validData();
|
|
33
|
-
}
|
|
34
|
-
response.code = this.statusCodeGenerator();
|
|
35
|
-
return { ...response };
|
|
36
|
-
}
|
|
37
|
-
}
|