@avleon/core 0.0.8 → 0.0.11
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/authentication.d.ts +6 -0
- package/dist/authentication.js +7 -2
- package/dist/collection.js +7 -0
- package/dist/config.d.ts +7 -1
- package/dist/config.js +6 -0
- package/dist/container.d.ts +8 -0
- package/dist/container.js +9 -1
- package/dist/controller.js +6 -0
- package/dist/decorators.d.ts +6 -0
- package/dist/decorators.js +6 -0
- package/dist/environment-variables.d.ts +7 -0
- package/dist/environment-variables.js +10 -1
- package/dist/exceptions/http-exceptions.d.ts +6 -0
- package/dist/exceptions/http-exceptions.js +6 -0
- package/dist/exceptions/system-exception.d.ts +6 -0
- package/dist/file-storage.d.ts +17 -0
- package/dist/file-storage.js +153 -0
- package/dist/helpers.js +7 -1
- package/dist/icore.d.ts +105 -9
- package/dist/icore.js +193 -40
- package/dist/index.d.ts +9 -0
- package/dist/index.js +9 -1
- package/dist/map-types.d.ts +6 -1
- package/dist/map-types.js +6 -1
- package/dist/middleware.js +6 -0
- package/dist/multipart.d.ts +17 -0
- package/dist/multipart.js +62 -0
- package/dist/openapi.d.ts +6 -0
- package/dist/params.js +6 -0
- package/dist/queue.d.ts +6 -0
- package/dist/queue.js +6 -0
- package/dist/response.d.ts +6 -0
- package/dist/response.js +8 -1
- package/dist/security.d.ts +4 -0
- package/dist/security.js +15 -0
- package/dist/swagger-schema.d.ts +6 -0
- package/dist/swagger-schema.js +6 -0
- package/dist/types/app-builder.interface.d.ts +6 -0
- package/dist/types/app-builder.interface.js +6 -0
- package/dist/types/application.interface.d.ts +6 -0
- package/dist/validation.d.ts +6 -0
- package/dist/validation.js +6 -0
- package/dist/validator-extend.d.ts +6 -0
- package/dist/validator-extend.js +6 -0
- package/package.json +15 -8
package/dist/authentication.d.ts
CHANGED
package/dist/authentication.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @copyright 2024
|
|
4
|
+
* @author Tareq Hossain
|
|
5
|
+
* @email xtrinsic96@gmail.com
|
|
6
|
+
* @url https://github.com/xtareq
|
|
7
|
+
*/
|
|
2
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
9
|
exports.BaseAuthetication = void 0;
|
|
4
10
|
exports.Authorized = Authorized;
|
|
@@ -6,6 +12,5 @@ exports.CurrentUser = CurrentUser;
|
|
|
6
12
|
class BaseAuthetication {
|
|
7
13
|
}
|
|
8
14
|
exports.BaseAuthetication = BaseAuthetication;
|
|
9
|
-
function Authorized() {
|
|
10
|
-
}
|
|
15
|
+
function Authorized() { }
|
|
11
16
|
function CurrentUser() { }
|
package/dist/collection.js
CHANGED
|
@@ -4,6 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Collection = exports.Repository = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* @copyright 2024
|
|
9
|
+
* @author Tareq Hossain
|
|
10
|
+
* @email xtrinsic96@gmail.com
|
|
11
|
+
* @url https://github.com/xtareq
|
|
12
|
+
*/
|
|
7
13
|
const typedi_1 = __importDefault(require("typedi"));
|
|
8
14
|
const exceptions_1 = require("./exceptions");
|
|
9
15
|
const typeorm_1 = require("typeorm");
|
|
@@ -134,6 +140,7 @@ class AsynchronousCollection {
|
|
|
134
140
|
total,
|
|
135
141
|
totalPage: Math.ceil(total / take),
|
|
136
142
|
next: skip + take < total ? skip + take : null,
|
|
143
|
+
prev: skip + take < total ? skip + take : null,
|
|
137
144
|
data,
|
|
138
145
|
};
|
|
139
146
|
}
|
package/dist/config.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright 2024
|
|
3
|
+
* @author Tareq Hossain
|
|
4
|
+
* @email xtrinsic96@gmail.com
|
|
5
|
+
* @url https://github.com/xtareq
|
|
6
|
+
*/
|
|
1
7
|
import { Constructable } from "typedi";
|
|
2
8
|
import { Environment } from "./environment-variables";
|
|
3
9
|
export interface IConfig<T = any> {
|
|
@@ -7,4 +13,4 @@ export declare function Config<T extends IConfig>(target: Constructable<T>): voi
|
|
|
7
13
|
export declare class AppConfig {
|
|
8
14
|
get<T extends IConfig<R>, R>(configClass: Constructable<T>): R;
|
|
9
15
|
}
|
|
10
|
-
export declare function GetConfig<T extends IConfig<R>, R = ReturnType<InstanceType<Constructable<T>>[
|
|
16
|
+
export declare function GetConfig<T extends IConfig<R>, R = ReturnType<InstanceType<Constructable<T>>["config"]>>(ConfigClass: Constructable<T>): R;
|
package/dist/config.js
CHANGED
|
@@ -3,6 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AppConfig = void 0;
|
|
4
4
|
exports.Config = Config;
|
|
5
5
|
exports.GetConfig = GetConfig;
|
|
6
|
+
/**
|
|
7
|
+
* @copyright 2024
|
|
8
|
+
* @author Tareq Hossain
|
|
9
|
+
* @email xtrinsic96@gmail.com
|
|
10
|
+
* @url https://github.com/xtareq
|
|
11
|
+
*/
|
|
6
12
|
const typedi_1 = require("typedi");
|
|
7
13
|
const environment_variables_1 = require("./environment-variables");
|
|
8
14
|
function Config(target) {
|
package/dist/container.d.ts
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright 2024
|
|
3
|
+
* @author Tareq Hossain
|
|
4
|
+
* @email xtrinsic96@gmail.com
|
|
5
|
+
* @url https://github.com/xtareq
|
|
6
|
+
*/
|
|
1
7
|
import TypediContainer from "typedi";
|
|
2
8
|
export declare const ROUTE_META_KEY: unique symbol;
|
|
3
9
|
export declare const CONTROLLER_META_KEY: unique symbol;
|
|
4
10
|
export declare const PARAM_META_KEY: unique symbol;
|
|
5
11
|
export declare const QUERY_META_KEY: unique symbol;
|
|
6
12
|
export declare const REQUEST_BODY_META_KEY: unique symbol;
|
|
13
|
+
export declare const REQUEST_BODY_FILE_KEY: unique symbol;
|
|
14
|
+
export declare const REQUEST_BODY_FILES_KEY: unique symbol;
|
|
7
15
|
export declare const REQUEST_USER_META_KEY: unique symbol;
|
|
8
16
|
export declare const REQUEST_HEADER_META_KEY: unique symbol;
|
|
9
17
|
export declare const DATASOURCE_META_KEY: unique symbol;
|
package/dist/container.js
CHANGED
|
@@ -3,19 +3,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.API_CONTROLLER_METADATA_KEY = exports.AUTHORIZATION_META_KEY = exports.DATASOURCE_META_KEY = exports.REQUEST_HEADER_META_KEY = exports.REQUEST_USER_META_KEY = exports.REQUEST_BODY_META_KEY = exports.QUERY_META_KEY = exports.PARAM_META_KEY = exports.CONTROLLER_META_KEY = exports.ROUTE_META_KEY = void 0;
|
|
6
|
+
exports.API_CONTROLLER_METADATA_KEY = exports.AUTHORIZATION_META_KEY = exports.DATASOURCE_META_KEY = exports.REQUEST_HEADER_META_KEY = exports.REQUEST_USER_META_KEY = exports.REQUEST_BODY_FILES_KEY = exports.REQUEST_BODY_FILE_KEY = exports.REQUEST_BODY_META_KEY = exports.QUERY_META_KEY = exports.PARAM_META_KEY = exports.CONTROLLER_META_KEY = exports.ROUTE_META_KEY = void 0;
|
|
7
7
|
exports.registerController = registerController;
|
|
8
8
|
exports.registerService = registerService;
|
|
9
9
|
exports.getRegisteredServices = getRegisteredServices;
|
|
10
10
|
exports.getRegisteredControllers = getRegisteredControllers;
|
|
11
11
|
exports.isApiController = isApiController;
|
|
12
12
|
exports.registerDataSource = registerDataSource;
|
|
13
|
+
/**
|
|
14
|
+
* @copyright 2024
|
|
15
|
+
* @author Tareq Hossain
|
|
16
|
+
* @email xtrinsic96@gmail.com
|
|
17
|
+
* @url https://github.com/xtareq
|
|
18
|
+
*/
|
|
13
19
|
const typedi_1 = __importDefault(require("typedi"));
|
|
14
20
|
exports.ROUTE_META_KEY = Symbol("iroute:options");
|
|
15
21
|
exports.CONTROLLER_META_KEY = Symbol("icontroller:options");
|
|
16
22
|
exports.PARAM_META_KEY = Symbol("iparam:options");
|
|
17
23
|
exports.QUERY_META_KEY = Symbol("iparam:options");
|
|
18
24
|
exports.REQUEST_BODY_META_KEY = Symbol("iparam:options");
|
|
25
|
+
exports.REQUEST_BODY_FILE_KEY = Symbol("iparam:options");
|
|
26
|
+
exports.REQUEST_BODY_FILES_KEY = Symbol("iparam:options");
|
|
19
27
|
exports.REQUEST_USER_META_KEY = Symbol("iparam:options");
|
|
20
28
|
exports.REQUEST_HEADER_META_KEY = Symbol("iheader:options");
|
|
21
29
|
exports.DATASOURCE_META_KEY = Symbol("idatasource:options");
|
package/dist/controller.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @copyright 2024
|
|
4
|
+
* @author Tareq Hossain
|
|
5
|
+
* @email xtrinsic96@gmail.com
|
|
6
|
+
* @url https://github.com/xtareq
|
|
7
|
+
*/
|
|
2
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
9
|
exports.createControllerDecorator = createControllerDecorator;
|
|
4
10
|
exports.ApiController = ApiController;
|
package/dist/decorators.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright 2024
|
|
3
|
+
* @author Tareq Hossain
|
|
4
|
+
* @email xtrinsic96@gmail.com
|
|
5
|
+
* @url https://github.com/xtareq
|
|
6
|
+
*/
|
|
1
7
|
import { Service as _service } from "typedi";
|
|
2
8
|
export declare function AppService(target: any): void;
|
|
3
9
|
export declare function AppService(): any;
|
package/dist/decorators.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @copyright 2024
|
|
4
|
+
* @author Tareq Hossain
|
|
5
|
+
* @email xtrinsic96@gmail.com
|
|
6
|
+
* @url https://github.com/xtareq
|
|
7
|
+
*/
|
|
2
8
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
9
|
if (k2 === undefined) k2 = k;
|
|
4
10
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright 2024
|
|
3
|
+
* @author Tareq Hossain
|
|
4
|
+
* @email xtrinsic96@gmail.com
|
|
5
|
+
* @url https://github.com/xtareq
|
|
6
|
+
*/
|
|
1
7
|
export declare class Environment {
|
|
2
8
|
private parseEnvFile;
|
|
3
9
|
get<T = any>(key: string): T;
|
|
10
|
+
getOrThrow<T = any>(key: string): T;
|
|
4
11
|
getAll<T = any>(): T;
|
|
5
12
|
}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @copyright 2024
|
|
4
|
+
* @author Tareq Hossain
|
|
5
|
+
* @email xtrinsic96@gmail.com
|
|
6
|
+
* @url https://github.com/xtareq
|
|
7
|
+
*/
|
|
2
8
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
9
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
10
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -15,7 +21,6 @@ const path_1 = __importDefault(require("path"));
|
|
|
15
21
|
const fs_1 = __importDefault(require("fs"));
|
|
16
22
|
const typedi_1 = require("typedi");
|
|
17
23
|
const system_exception_1 = require("./exceptions/system-exception");
|
|
18
|
-
// Load environment variables
|
|
19
24
|
dotenv_1.default.config({ path: path_1.default.join(process.cwd(), ".env") });
|
|
20
25
|
let Environment = class Environment {
|
|
21
26
|
parseEnvFile(filePath) {
|
|
@@ -30,6 +35,10 @@ let Environment = class Environment {
|
|
|
30
35
|
}
|
|
31
36
|
}
|
|
32
37
|
get(key) {
|
|
38
|
+
const parsedEnv = this.parseEnvFile(path_1.default.join(process.cwd(), '.env'));
|
|
39
|
+
return parsedEnv[key];
|
|
40
|
+
}
|
|
41
|
+
getOrThrow(key) {
|
|
33
42
|
const parsedEnv = this.parseEnvFile(path_1.default.join(process.cwd(), '.env'));
|
|
34
43
|
if (!Object(parsedEnv).hasOwnProperty(key)) {
|
|
35
44
|
throw new system_exception_1.EnvironmentVariableNotFound(key);
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.httpExcepitoins = exports.ForbiddenException = exports.UnauthorizedException = exports.NotFoundException = exports.InternalErrorException = exports.ValidationErrorException = exports.BadRequestException = exports.BaseHttpException = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @copyright 2024
|
|
6
|
+
* @author Tareq Hossain
|
|
7
|
+
* @email xtrinsic96@gmail.com
|
|
8
|
+
* @url https://github.com/xtareq
|
|
9
|
+
*/
|
|
4
10
|
class BaseHttpException extends Error {
|
|
5
11
|
constructor(message) {
|
|
6
12
|
super(JSON.stringify(message));
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { MultipartFile } from './multipart';
|
|
2
|
+
interface TransformOptions {
|
|
3
|
+
resize?: {
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
};
|
|
7
|
+
format?: 'jpeg' | 'png' | 'webp' | 'avif';
|
|
8
|
+
quality?: number;
|
|
9
|
+
}
|
|
10
|
+
export declare class FileStorage {
|
|
11
|
+
private transformOptions;
|
|
12
|
+
transform(options: TransformOptions): this;
|
|
13
|
+
save(f: MultipartFile, options: any): Promise<import("@fastify/multipart").MultipartFile | undefined>;
|
|
14
|
+
saveAs(f: MultipartFile, filename: string, options: any): Promise<import("@fastify/multipart").MultipartFile | undefined>;
|
|
15
|
+
private processImage;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,153 @@
|
|
|
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 __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
42
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.FileStorage = void 0;
|
|
46
|
+
const fs_1 = __importDefault(require("fs"));
|
|
47
|
+
const path_1 = __importDefault(require("path"));
|
|
48
|
+
const promises_1 = require("stream/promises");
|
|
49
|
+
const http_exceptions_1 = require("./exceptions/http-exceptions");
|
|
50
|
+
const decorators_1 = require("./decorators");
|
|
51
|
+
const os_1 = __importDefault(require("os"));
|
|
52
|
+
let FileStorage = class FileStorage {
|
|
53
|
+
constructor() {
|
|
54
|
+
this.transformOptions = null;
|
|
55
|
+
}
|
|
56
|
+
transform(options) {
|
|
57
|
+
this.transformOptions = options;
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
async save(f, options) {
|
|
61
|
+
if (f && f.file) {
|
|
62
|
+
let fname = f.filename;
|
|
63
|
+
if (options) {
|
|
64
|
+
if (options.dest) {
|
|
65
|
+
fname = options.saveAs ? options.dest + '/' + options.saveAs : options.dest + '/' + f.filename;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
fname = path_1.default.join(process.cwd(), `public/${options.saveAs ? options.saveAs : f.filename}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
fname = path_1.default.join(process.cwd(), `public/${f.filename}`);
|
|
73
|
+
}
|
|
74
|
+
if (fs_1.default.existsSync(fname) && !options.overwrite) {
|
|
75
|
+
throw new http_exceptions_1.InternalErrorException("File already exists.");
|
|
76
|
+
}
|
|
77
|
+
if (this.transformOptions) {
|
|
78
|
+
const tempFilePath = path_1.default.join(os_1.default.tmpdir(), `temp-${Date.now()}-${f.filename}`);
|
|
79
|
+
await (0, promises_1.pipeline)(f.file, fs_1.default.createWriteStream(tempFilePath));
|
|
80
|
+
await this.processImage(fs_1.default.createReadStream(tempFilePath), fname);
|
|
81
|
+
fs_1.default.unlinkSync(tempFilePath);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
await (0, promises_1.pipeline)(f.file, fs_1.default.createWriteStream(fname));
|
|
85
|
+
}
|
|
86
|
+
return Object.assign(Object.assign({}, f), { filename: (options === null || options === void 0 ? void 0 : options.saveAs) ? options.saveAs : f.filename });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async saveAs(f, filename, options) {
|
|
90
|
+
if (f && f.file) {
|
|
91
|
+
let fname = filename;
|
|
92
|
+
if (options && options.dest) {
|
|
93
|
+
fname = options.dest + '/' + filename;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
fname = path_1.default.join(process.cwd(), `public/${filename}`);
|
|
97
|
+
}
|
|
98
|
+
if (fs_1.default.existsSync(fname) && !options.overwrite) {
|
|
99
|
+
throw new http_exceptions_1.InternalErrorException("File already exists.");
|
|
100
|
+
}
|
|
101
|
+
if (this.transformOptions) {
|
|
102
|
+
await this.processImage(f.file, fname);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
await (0, promises_1.pipeline)(f.file, fs_1.default.createWriteStream(fname));
|
|
106
|
+
}
|
|
107
|
+
return Object.assign(Object.assign({}, f), { filename: filename });
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async processImage(fileStream, outputPath) {
|
|
111
|
+
var _a, _b;
|
|
112
|
+
try {
|
|
113
|
+
const sharp = await Promise.resolve().then(() => __importStar(require('sharp'))); // Lazy import sharp
|
|
114
|
+
let sharpPipeline = sharp.default();
|
|
115
|
+
if ((_a = this.transformOptions) === null || _a === void 0 ? void 0 : _a.resize) {
|
|
116
|
+
sharpPipeline = sharpPipeline.resize(this.transformOptions.resize.width, this.transformOptions.resize.height);
|
|
117
|
+
}
|
|
118
|
+
if ((_b = this.transformOptions) === null || _b === void 0 ? void 0 : _b.format) {
|
|
119
|
+
switch (this.transformOptions.format) {
|
|
120
|
+
case 'jpeg':
|
|
121
|
+
sharpPipeline = sharpPipeline.jpeg({ quality: this.transformOptions.quality || 80 });
|
|
122
|
+
break;
|
|
123
|
+
case 'png':
|
|
124
|
+
sharpPipeline = sharpPipeline.png({ quality: this.transformOptions.quality || 80 });
|
|
125
|
+
break;
|
|
126
|
+
case 'webp':
|
|
127
|
+
sharpPipeline = sharpPipeline.webp({ quality: this.transformOptions.quality || 80 });
|
|
128
|
+
break;
|
|
129
|
+
case 'avif':
|
|
130
|
+
sharpPipeline = sharpPipeline.avif({ quality: this.transformOptions.quality || 80 });
|
|
131
|
+
break;
|
|
132
|
+
default:
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
await (0, promises_1.pipeline)(fileStream, sharpPipeline, fs_1.default.createWriteStream(outputPath));
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
if (error.code === 'MODULE_NOT_FOUND' && error.message.includes('sharp')) {
|
|
140
|
+
throw new http_exceptions_1.InternalErrorException('sharp module not found. Please install sharp to use image transformations.');
|
|
141
|
+
}
|
|
142
|
+
console.error('Image processing failed:', error);
|
|
143
|
+
throw new http_exceptions_1.InternalErrorException('Image processing failed.');
|
|
144
|
+
}
|
|
145
|
+
finally {
|
|
146
|
+
this.transformOptions = null; // Reset transform options after processing
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
exports.FileStorage = FileStorage;
|
|
151
|
+
exports.FileStorage = FileStorage = __decorate([
|
|
152
|
+
decorators_1.AppService
|
|
153
|
+
], FileStorage);
|
package/dist/helpers.js
CHANGED
|
@@ -19,6 +19,12 @@ exports.jsonToInstance = jsonToInstance;
|
|
|
19
19
|
exports.transformObjectByInstanceToObject = transformObjectByInstanceToObject;
|
|
20
20
|
exports.validateObjectByInstance = validateObjectByInstance;
|
|
21
21
|
exports.validateRequestBody = validateRequestBody;
|
|
22
|
+
/**
|
|
23
|
+
* @copyright 2024
|
|
24
|
+
* @author Tareq Hossain
|
|
25
|
+
* @email xtrinsic96@gmail.com
|
|
26
|
+
* @url https://github.com/xtareq
|
|
27
|
+
*/
|
|
22
28
|
const class_transformer_1 = require("class-transformer");
|
|
23
29
|
const exceptions_1 = require("./exceptions");
|
|
24
30
|
const fs_1 = __importDefault(require("fs"));
|
|
@@ -32,7 +38,7 @@ function inject(cls) {
|
|
|
32
38
|
return container_1.default.get(cls);
|
|
33
39
|
}
|
|
34
40
|
catch (error) {
|
|
35
|
-
throw new system_exception_1.SystemUseError(`Not
|
|
41
|
+
throw new system_exception_1.SystemUseError(`Not a project class. Maybe you wanna register it first.`);
|
|
36
42
|
}
|
|
37
43
|
}
|
|
38
44
|
function isConstructor(func) {
|
package/dist/icore.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright 2024
|
|
3
|
+
* @author Tareq Hossain
|
|
4
|
+
* @email xtrinsic96@gmail.com
|
|
5
|
+
* @url https://github.com/xtareq
|
|
6
|
+
*/
|
|
1
7
|
import { FastifyInstance, FastifyReply, FastifyRequest, HookHandlerDoneFunction } from "fastify";
|
|
2
8
|
import { Constructable } from "typedi";
|
|
3
9
|
import { Constructor } from "./helpers";
|
|
@@ -6,6 +12,9 @@ import { DataSourceOptions } from "typeorm";
|
|
|
6
12
|
import { AppMiddleware } from "./middleware";
|
|
7
13
|
import { OpenApiOptions, OpenApiUiOptions } from "./openapi";
|
|
8
14
|
import { IConfig } from "./config";
|
|
15
|
+
import { FastifyCorsOptions } from "@fastify/cors";
|
|
16
|
+
import { FastifyMultipartOptions } from "@fastify/multipart";
|
|
17
|
+
import { MultipartFile } from "./multipart";
|
|
9
18
|
export type FuncRoute = {
|
|
10
19
|
handler: any;
|
|
11
20
|
middlewares?: any[];
|
|
@@ -30,7 +39,7 @@ export interface ParamMetaOptions {
|
|
|
30
39
|
validate: boolean;
|
|
31
40
|
dataType: any;
|
|
32
41
|
validatorClass: boolean;
|
|
33
|
-
type: "route:param" | "route:query" | "route:body" | "route:header" | "route:user";
|
|
42
|
+
type: "route:param" | "route:query" | "route:body" | "route:header" | "route:user" | "route:file" | "route:files";
|
|
34
43
|
}
|
|
35
44
|
export interface MethodParamMeta {
|
|
36
45
|
params: ParamMetaOptions[];
|
|
@@ -39,12 +48,44 @@ export interface MethodParamMeta {
|
|
|
39
48
|
headers: ParamMetaOptions[];
|
|
40
49
|
currentUser: ParamMetaOptions[];
|
|
41
50
|
swagger?: OpenApiUiOptions;
|
|
51
|
+
file?: any[];
|
|
52
|
+
files?: MultipartFile[];
|
|
42
53
|
}
|
|
43
54
|
type StaticFileOptions = {
|
|
44
55
|
path?: PathLike;
|
|
45
56
|
prefix?: string;
|
|
46
57
|
};
|
|
47
|
-
|
|
58
|
+
type MultipartOptions = {
|
|
59
|
+
destination: PathLike;
|
|
60
|
+
} & FastifyMultipartOptions;
|
|
61
|
+
type AvleonApp = FastifyInstance;
|
|
62
|
+
export type TestAppOptions = {
|
|
63
|
+
controllers: Constructor[];
|
|
64
|
+
};
|
|
65
|
+
export interface AvleonTestAppliction {
|
|
66
|
+
addDataSource: (dataSourceOptions: DataSourceOptions) => void;
|
|
67
|
+
getApp: (options?: TestAppOptions) => any;
|
|
68
|
+
getController: <T>(controller: Constructor<T>) => T;
|
|
69
|
+
}
|
|
70
|
+
export interface IAvleonApplication {
|
|
71
|
+
isDevelopment(): boolean;
|
|
72
|
+
useCors(corsOptions?: FastifyCorsOptions): void;
|
|
73
|
+
useOpenApi<T extends IConfig<R>, R = ReturnType<InstanceType<Constructable<T>>["config"]>>(ConfigClass: Constructable<T>, modifyConfig?: (config: R) => R): void;
|
|
74
|
+
useSwagger(options: OpenApiUiOptions): Promise<void>;
|
|
75
|
+
useMultipart(options: MultipartOptions): IAvleonApplication;
|
|
76
|
+
useMiddlewares<T extends AppMiddleware>(mclasses: Constructor<T>[]): void;
|
|
77
|
+
useAuthoriztion<T extends any>(middleware: Constructor<T>): void;
|
|
78
|
+
mapRoute<T extends (...args: any[]) => any>(method: "get" | "post" | "put" | "delete", path: string, fn: T): Promise<void>;
|
|
79
|
+
mapGet<T extends (...args: any[]) => any>(path: string, fn: T): any;
|
|
80
|
+
mapPost<T extends (...args: any[]) => any>(path: string, fn: T): any;
|
|
81
|
+
mapPut<T extends (...args: any[]) => any>(path: string, fn: T): any;
|
|
82
|
+
mapDelete<T extends (...args: any[]) => any>(path: string, fn: T): any;
|
|
83
|
+
mapControllers(controllers: any[]): any;
|
|
84
|
+
useStaticFiles(options?: StaticFileOptions): void;
|
|
85
|
+
run(port?: number): Promise<void>;
|
|
86
|
+
getTestApp(): any;
|
|
87
|
+
}
|
|
88
|
+
declare class AvleonApplication implements IAvleonApplication {
|
|
48
89
|
private static instance;
|
|
49
90
|
private static buildOptions;
|
|
50
91
|
private app;
|
|
@@ -55,20 +96,46 @@ declare class AvleonApplication {
|
|
|
55
96
|
private rMap;
|
|
56
97
|
private hasSwagger;
|
|
57
98
|
private globalSwaggerOptions;
|
|
99
|
+
private dataSourceOptions?;
|
|
58
100
|
private controllers;
|
|
59
101
|
private authorizeMiddleware?;
|
|
60
102
|
private appConfig;
|
|
103
|
+
private dataSource?;
|
|
104
|
+
private metaCache;
|
|
105
|
+
private multipartOptions;
|
|
61
106
|
private constructor();
|
|
62
107
|
static getInternalApp(buildOptions: any): AvleonApplication;
|
|
63
108
|
isDevelopment(): boolean;
|
|
64
109
|
private initSwagger;
|
|
65
|
-
|
|
110
|
+
useCors(corsOptions?: FastifyCorsOptions): void;
|
|
111
|
+
useOpenApi<T extends IConfig<R>, R = ReturnType<InstanceType<Constructable<T>>["config"]>>(ConfigClass: Constructable<T>, modifyConfig?: (config: R) => R): void;
|
|
112
|
+
/**
|
|
113
|
+
* @deprecated
|
|
114
|
+
* Will remove in next major version
|
|
115
|
+
*/
|
|
66
116
|
useSwagger(options: OpenApiUiOptions): Promise<void>;
|
|
117
|
+
useMultipart(options: MultipartOptions): this;
|
|
67
118
|
private handleMiddlewares;
|
|
68
119
|
private executeMiddlewares;
|
|
120
|
+
/**
|
|
121
|
+
* build controller
|
|
122
|
+
* @param controller
|
|
123
|
+
* @returns void
|
|
124
|
+
*/
|
|
69
125
|
private buildController;
|
|
126
|
+
/**
|
|
127
|
+
* map all request parameters
|
|
128
|
+
* @param req
|
|
129
|
+
* @param meta
|
|
130
|
+
* @returns
|
|
131
|
+
*/
|
|
70
132
|
private _mapArgs;
|
|
71
|
-
|
|
133
|
+
/**
|
|
134
|
+
* Process Meta for controlelr class methods
|
|
135
|
+
* @param prototype
|
|
136
|
+
* @param method
|
|
137
|
+
* @returns
|
|
138
|
+
*/
|
|
72
139
|
private _processMeta;
|
|
73
140
|
autoControllers(): Promise<void>;
|
|
74
141
|
mapControllers(controllers: Function[]): void;
|
|
@@ -98,19 +165,48 @@ declare class AvleonApplication {
|
|
|
98
165
|
useSwagger: (options: OpenApiOptions) => /*elided*/ any;
|
|
99
166
|
};
|
|
100
167
|
useStaticFiles(options?: StaticFileOptions): void;
|
|
168
|
+
initializeDatabase(): Promise<void>;
|
|
101
169
|
run(port?: number): Promise<void>;
|
|
102
|
-
getTestApp(
|
|
170
|
+
getTestApp(buildOptions?: any): Promise<any>;
|
|
171
|
+
}
|
|
172
|
+
export type Application = typeof AvleonApplication;
|
|
173
|
+
export interface ITestBuilder {
|
|
174
|
+
getTestApplication(): AvleonTestAppliction;
|
|
175
|
+
createTestApplication(options: any): AvleonTestAppliction;
|
|
176
|
+
}
|
|
177
|
+
export interface IAppBuilder {
|
|
178
|
+
registerPlugin<T extends Function, S extends {}>(plugin: T, options: S): Promise<void>;
|
|
179
|
+
addDataSource<T extends IConfig<R>, R = ReturnType<InstanceType<Constructable<T>>["config"]>>(ConfigClass: Constructable<T>, modifyConfig?: (config: R) => R): void;
|
|
180
|
+
build<T extends IAvleonApplication>(): T;
|
|
103
181
|
}
|
|
104
|
-
export declare class
|
|
182
|
+
export declare class TestBuilder {
|
|
183
|
+
private static instance;
|
|
184
|
+
private app;
|
|
185
|
+
private dataSourceOptions?;
|
|
186
|
+
private constructor();
|
|
187
|
+
static createBuilder(): TestBuilder;
|
|
188
|
+
getController<T>(controller: Constructor<T>): T;
|
|
189
|
+
getService<T>(service: Constructor<T>): T;
|
|
190
|
+
getTestApplication(options: TestAppOptions): Promise<AvleonApp>;
|
|
191
|
+
build(app: IAvleonApplication): any;
|
|
192
|
+
fromApplication(app: IAvleonApplication): any;
|
|
193
|
+
}
|
|
194
|
+
export declare class Builder implements ITestBuilder, IAppBuilder {
|
|
105
195
|
private static instance;
|
|
106
196
|
private alreadyBuilt;
|
|
107
197
|
private database;
|
|
108
198
|
private dataSource?;
|
|
199
|
+
private multipartOptions;
|
|
200
|
+
private dataSourceOptions?;
|
|
201
|
+
private testBuilder;
|
|
202
|
+
private appConfig;
|
|
109
203
|
private constructor();
|
|
204
|
+
getTestApplication(): AvleonTestAppliction;
|
|
110
205
|
static createAppBuilder(): Builder;
|
|
111
|
-
static
|
|
206
|
+
static creatTestAppBuilder(): ITestBuilder;
|
|
112
207
|
registerPlugin<T extends Function, S extends {}>(plugin: T, options: S): Promise<void>;
|
|
113
|
-
addDataSource(config:
|
|
114
|
-
|
|
208
|
+
addDataSource<T extends IConfig<R>, R = ReturnType<InstanceType<Constructable<T>>["config"]>>(ConfigClass: Constructable<T>, modifyConfig?: (config: R) => R): void;
|
|
209
|
+
createTestApplication<T extends AvleonTestAppliction>(buildOptions?: any): any;
|
|
210
|
+
build<T extends IAvleonApplication>(): T;
|
|
115
211
|
}
|
|
116
212
|
export {};
|