@avleon/core 0.0.48 → 0.0.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as __toCommonJS, i as __require, n as __esmMin, o as __toESM, r as __exportAll } from "./chunk-DORXReHP.js";
|
|
2
2
|
import { getMetadataStorage, validateSync } from "class-validator";
|
|
3
|
-
import Container
|
|
3
|
+
import Container, { Container as Container$1, Service, Token } from "typedi";
|
|
4
4
|
import "reflect-metadata";
|
|
5
5
|
import fs, { createReadStream, existsSync } from "node:fs";
|
|
6
6
|
import crypto from "node:crypto";
|
|
@@ -19,7 +19,7 @@ function registerController(controller) {
|
|
|
19
19
|
controllerRegistry.add(controller);
|
|
20
20
|
}
|
|
21
21
|
function registerService(service) {
|
|
22
|
-
Container.set(service, service);
|
|
22
|
+
Container$1.set(service, service);
|
|
23
23
|
serviceRegistry.add(service);
|
|
24
24
|
}
|
|
25
25
|
function getRegisteredServices() {
|
|
@@ -32,12 +32,12 @@ function isApiController(target) {
|
|
|
32
32
|
return Reflect.getMetadata(API_CONTROLLER_METADATA_KEY, target) === true;
|
|
33
33
|
}
|
|
34
34
|
function registerDataSource(dataSource) {
|
|
35
|
-
Container.set("idatasource", dataSource);
|
|
35
|
+
Container$1.set("idatasource", dataSource);
|
|
36
36
|
}
|
|
37
37
|
function registerKnex(dataSource) {
|
|
38
|
-
Container.set("KnexConnection", dataSource);
|
|
38
|
+
Container$1.set("KnexConnection", dataSource);
|
|
39
39
|
}
|
|
40
|
-
var FEATURE_KEY, ROUTE_META_KEY, CONTROLLER_META_KEY, PARAM_META_KEY, QUERY_META_KEY, REQUEST_BODY_META_KEY, REQUEST_BODY_FILE_KEY, REQUEST_BODY_FILES_KEY, REQUEST_USER_META_KEY, REQUEST_HEADER_META_KEY, DATASOURCE_META_KEY, AUTHORIZATION_META_KEY, controllerRegistry, serviceRegistry,
|
|
40
|
+
var FEATURE_KEY, ROUTE_META_KEY, CONTROLLER_META_KEY, PARAM_META_KEY, QUERY_META_KEY, REQUEST_BODY_META_KEY, REQUEST_BODY_FILE_KEY, REQUEST_BODY_FILES_KEY, REQUEST_USER_META_KEY, REQUEST_HEADER_META_KEY, DATASOURCE_META_KEY, AUTHORIZATION_META_KEY, controllerRegistry, serviceRegistry, API_CONTROLLER_METADATA_KEY, container_default;
|
|
41
41
|
var init_container = __esmMin((() => {
|
|
42
42
|
FEATURE_KEY = Symbol.for("features");
|
|
43
43
|
ROUTE_META_KEY = Symbol("iroute:options");
|
|
@@ -53,9 +53,9 @@ var init_container = __esmMin((() => {
|
|
|
53
53
|
AUTHORIZATION_META_KEY = Symbol("idatasource:authorization");
|
|
54
54
|
controllerRegistry = /* @__PURE__ */ new Set();
|
|
55
55
|
serviceRegistry = /* @__PURE__ */ new Set();
|
|
56
|
-
Container = Container$1;
|
|
57
56
|
API_CONTROLLER_METADATA_KEY = Symbol("apiController");
|
|
58
|
-
Container.set("appName", "Iqra");
|
|
57
|
+
Container$1.set("appName", "Iqra");
|
|
58
|
+
container_default = Container$1;
|
|
59
59
|
}));
|
|
60
60
|
//#endregion
|
|
61
61
|
//#region src/swagger-schema.ts
|
|
@@ -980,7 +980,7 @@ var init_system_exception = __esmMin((() => {
|
|
|
980
980
|
//#region src/utils/di-utils.ts
|
|
981
981
|
function inject(cls) {
|
|
982
982
|
try {
|
|
983
|
-
return
|
|
983
|
+
return container_default.get(cls);
|
|
984
984
|
} catch (error) {
|
|
985
985
|
throw new SystemUseError("Not a project class. Maybe you wanna register it first.");
|
|
986
986
|
}
|
|
@@ -1224,7 +1224,7 @@ var AvleonRouter = class {
|
|
|
1224
1224
|
return [...classMiddlewares, ...methodMiddlewares];
|
|
1225
1225
|
}
|
|
1226
1226
|
async buildController(controller) {
|
|
1227
|
-
const ctrl = Container
|
|
1227
|
+
const ctrl = Container.get(controller);
|
|
1228
1228
|
const controllerMeta = Reflect.getMetadata(CONTROLLER_META_KEY, ctrl.constructor);
|
|
1229
1229
|
if (!controllerMeta) return;
|
|
1230
1230
|
const prototype = Object.getPrototypeOf(ctrl);
|
|
@@ -1302,15 +1302,15 @@ var AvleonRouter = class {
|
|
|
1302
1302
|
handler: async (req, res) => {
|
|
1303
1303
|
let reqClone = req;
|
|
1304
1304
|
if (authClsMeata.authorize && this.authorizeMiddleware) {
|
|
1305
|
-
await
|
|
1305
|
+
await container_default.get(this.authorizeMiddleware).authorize(reqClone, authClsMeata.options);
|
|
1306
1306
|
if (res.sent) return;
|
|
1307
1307
|
}
|
|
1308
1308
|
if (authClsMethodMeata.authorize && this.authorizeMiddleware) {
|
|
1309
|
-
await
|
|
1309
|
+
await container_default.get(this.authorizeMiddleware).authorize(reqClone, authClsMethodMeata.options);
|
|
1310
1310
|
if (res.sent) return;
|
|
1311
1311
|
}
|
|
1312
1312
|
if (classMiddlewares.length > 0) for (let m of classMiddlewares) {
|
|
1313
|
-
reqClone = await Container
|
|
1313
|
+
reqClone = await Container.get(m.constructor).invoke(reqClone, res);
|
|
1314
1314
|
if (res.sent) return;
|
|
1315
1315
|
}
|
|
1316
1316
|
const args = await this._mapArgs(reqClone, allMeta);
|
|
@@ -1461,7 +1461,7 @@ var AvleonRouter = class {
|
|
|
1461
1461
|
const route = {
|
|
1462
1462
|
useMiddleware: (middlewares) => {
|
|
1463
1463
|
const ms = (Array.isArray(middlewares) ? middlewares : [middlewares]).map((mclass) => {
|
|
1464
|
-
const cls = Container
|
|
1464
|
+
const cls = Container.get(mclass);
|
|
1465
1465
|
this.middlewares.set(mclass.name, cls);
|
|
1466
1466
|
return cls.invoke;
|
|
1467
1467
|
});
|
|
@@ -1544,13 +1544,13 @@ var init_kenx_provider = __esmMin((() => {
|
|
|
1544
1544
|
DB = class DB {
|
|
1545
1545
|
connection;
|
|
1546
1546
|
constructor() {
|
|
1547
|
-
const existing = Container$
|
|
1547
|
+
const existing = Container$1.has("KnexConnection") ? Container$1.get("KnexConnection") : null;
|
|
1548
1548
|
if (existing) this.connection = existing;
|
|
1549
1549
|
}
|
|
1550
1550
|
init(config) {
|
|
1551
1551
|
if (!this.connection) {
|
|
1552
1552
|
this.connection = __require("knex")(config);
|
|
1553
|
-
Container$
|
|
1553
|
+
Container$1.set("KnexConnection", this.connection);
|
|
1554
1554
|
}
|
|
1555
1555
|
return this.connection;
|
|
1556
1556
|
}
|
|
@@ -1592,7 +1592,7 @@ function Dispatch(event, options) {
|
|
|
1592
1592
|
const original = descriptor.value;
|
|
1593
1593
|
descriptor.value = async function(...args) {
|
|
1594
1594
|
const result = await original.apply(this, args);
|
|
1595
|
-
await Container$
|
|
1595
|
+
await Container$1.get(EventDispatcher).dispatch(event, result, options);
|
|
1596
1596
|
return result;
|
|
1597
1597
|
};
|
|
1598
1598
|
};
|
|
@@ -1631,8 +1631,8 @@ var init_event_dispatcher = __esmMin((() => {
|
|
|
1631
1631
|
async dispatchToTransports(event, data, options) {
|
|
1632
1632
|
const transports = options.transports ?? ["socket"];
|
|
1633
1633
|
for (const transport of transports) if (transport === "socket") {
|
|
1634
|
-
const io = Container$
|
|
1635
|
-
const socket = Container$
|
|
1634
|
+
const io = Container$1.get(SocketIoServer);
|
|
1635
|
+
const socket = Container$1.get(SocketContextService).getSocket();
|
|
1636
1636
|
if (options.broadcast && socket) if (options.room) socket.broadcast.to(options.room).emit(event, data);
|
|
1637
1637
|
else socket.broadcast.emit(event, data);
|
|
1638
1638
|
else if (options.room) io.to(options.room).emit(event, data);
|
|
@@ -1691,7 +1691,7 @@ var init_event_subscriber = __esmMin((() => {
|
|
|
1691
1691
|
register(socket) {
|
|
1692
1692
|
const subscriberClasses = getSocketSubscribers();
|
|
1693
1693
|
for (const SubscriberClass of subscriberClasses) {
|
|
1694
|
-
const instance = Container$
|
|
1694
|
+
const instance = Container$1.get(SubscriberClass);
|
|
1695
1695
|
const prototype = Object.getPrototypeOf(instance);
|
|
1696
1696
|
const methodNames = Object.getOwnPropertyNames(prototype).filter((name) => typeof prototype[name] === "function");
|
|
1697
1697
|
for (const methodName of methodNames) {
|
|
@@ -1812,7 +1812,7 @@ var AvleonApplication = class AvleonApplication {
|
|
|
1812
1812
|
if (this.dataSourceOptions) {
|
|
1813
1813
|
const { DataSource } = requireTypeorm();
|
|
1814
1814
|
this.dataSource = new DataSource(this.dataSourceOptions);
|
|
1815
|
-
Container
|
|
1815
|
+
Container.set(DataSource, this.dataSource);
|
|
1816
1816
|
}
|
|
1817
1817
|
}
|
|
1818
1818
|
}
|
|
@@ -1831,7 +1831,7 @@ var AvleonApplication = class AvleonApplication {
|
|
|
1831
1831
|
useDatasource(dataSource) {
|
|
1832
1832
|
const { DataSource } = requireTypeorm();
|
|
1833
1833
|
this.dataSource = dataSource;
|
|
1834
|
-
Container
|
|
1834
|
+
Container.set(DataSource, this.dataSource);
|
|
1835
1835
|
return this;
|
|
1836
1836
|
}
|
|
1837
1837
|
useMultipart(options) {
|
|
@@ -1897,7 +1897,7 @@ var AvleonApplication = class AvleonApplication {
|
|
|
1897
1897
|
}
|
|
1898
1898
|
useMiddlewares(middlewares) {
|
|
1899
1899
|
middlewares.forEach((m) => {
|
|
1900
|
-
const cls = Container
|
|
1900
|
+
const cls = Container.get(m);
|
|
1901
1901
|
this.app.addHook("preHandler", async (req, res) => {
|
|
1902
1902
|
await cls.invoke(req, res);
|
|
1903
1903
|
});
|
|
@@ -1948,7 +1948,7 @@ var AvleonApplication = class AvleonApplication {
|
|
|
1948
1948
|
useKnex(options) {
|
|
1949
1949
|
try {
|
|
1950
1950
|
const { DB } = (init_kenx_provider(), __toCommonJS(kenx_provider_exports));
|
|
1951
|
-
Container
|
|
1951
|
+
Container.get(DB).init(options.config ?? options);
|
|
1952
1952
|
} catch (e) {
|
|
1953
1953
|
if (e.message?.includes("knex")) throw e;
|
|
1954
1954
|
throw new Error("[Avleon] Failed to initialize Knex. Make sure knex and a database driver are installed.\nRun: npm install knex pg (or mysql2, sqlite3, etc.)");
|
|
@@ -1995,7 +1995,7 @@ var AvleonApplication = class AvleonApplication {
|
|
|
1995
1995
|
}
|
|
1996
1996
|
_mapFeatures() {
|
|
1997
1997
|
try {
|
|
1998
|
-
Container
|
|
1998
|
+
Container.get("features");
|
|
1999
1999
|
} catch {}
|
|
2000
2000
|
}
|
|
2001
2001
|
async initializeDatabase() {
|
|
@@ -2006,8 +2006,8 @@ var AvleonApplication = class AvleonApplication {
|
|
|
2006
2006
|
const { SocketContextService } = (init_event_dispatcher(), __toCommonJS(event_dispatcher_exports));
|
|
2007
2007
|
const { EventSubscriberRegistry } = (init_event_subscriber(), __toCommonJS(event_subscriber_exports));
|
|
2008
2008
|
const { SocketIoServer } = (init_websocket(), __toCommonJS(websocket_exports));
|
|
2009
|
-
const contextService = Container
|
|
2010
|
-
Container
|
|
2009
|
+
const contextService = Container.get(SocketContextService);
|
|
2010
|
+
Container.get(EventSubscriberRegistry).register(socket);
|
|
2011
2011
|
const originalOn = socket.on.bind(socket);
|
|
2012
2012
|
socket.on = (event, handler) => {
|
|
2013
2013
|
return originalOn(event, (...args) => {
|
|
@@ -2086,7 +2086,7 @@ var AvleonApplication = class AvleonApplication {
|
|
|
2086
2086
|
if (!this.app.io) throw new Error("Socket.IO not initialized. Make sure fastify-socket.io is registered correctly.");
|
|
2087
2087
|
try {
|
|
2088
2088
|
const { SocketIoServer } = (init_websocket(), __toCommonJS(websocket_exports));
|
|
2089
|
-
Container
|
|
2089
|
+
Container.set(SocketIoServer, this.app.io);
|
|
2090
2090
|
await this.app.io.on("connection", this.handleSocket.bind(this));
|
|
2091
2091
|
} catch (e) {
|
|
2092
2092
|
console.warn("[Avleon] WebSocket setup error:", e);
|
|
@@ -2114,16 +2114,16 @@ var AvleonTest = class AvleonTest {
|
|
|
2114
2114
|
static getController(controller, deps = []) {
|
|
2115
2115
|
const paramTypes = Reflect.getMetadata("design:paramtypes", controller) || [];
|
|
2116
2116
|
deps.forEach((dep, i) => {
|
|
2117
|
-
Container
|
|
2117
|
+
Container.set(paramTypes[i], dep);
|
|
2118
2118
|
});
|
|
2119
|
-
return Container
|
|
2119
|
+
return Container.get(controller);
|
|
2120
2120
|
}
|
|
2121
2121
|
static getProvider(service, deps = []) {
|
|
2122
2122
|
const paramTypes = Reflect.getMetadata("design:paramtypes", service) || [];
|
|
2123
2123
|
deps.forEach((dep, i) => {
|
|
2124
|
-
Container
|
|
2124
|
+
Container.set(paramTypes[i], dep);
|
|
2125
2125
|
});
|
|
2126
|
-
return Container
|
|
2126
|
+
return Container.get(service);
|
|
2127
2127
|
}
|
|
2128
2128
|
static createTestApplication(options) {
|
|
2129
2129
|
const app = AvleonApplication.getInternalApp({ dataSourceOptions: options.dataSource ? options.dataSource : void 0 });
|
|
@@ -2181,7 +2181,7 @@ var AvleonTest = class AvleonTest {
|
|
|
2181
2181
|
}
|
|
2182
2182
|
}
|
|
2183
2183
|
static clean() {
|
|
2184
|
-
Container
|
|
2184
|
+
Container.reset();
|
|
2185
2185
|
}
|
|
2186
2186
|
};
|
|
2187
2187
|
var Avleon = class {
|
|
@@ -2418,7 +2418,7 @@ var AsynchronousCollection = class AsynchronousCollection {
|
|
|
2418
2418
|
}
|
|
2419
2419
|
getRepository() {
|
|
2420
2420
|
if (!this.repo) {
|
|
2421
|
-
const dataSource = Container
|
|
2421
|
+
const dataSource = Container.get("idatasource");
|
|
2422
2422
|
console.log("datasource", dataSource);
|
|
2423
2423
|
const repository = dataSource.getRepository(this.model);
|
|
2424
2424
|
this.repo = repository;
|
|
@@ -2455,7 +2455,7 @@ function InjectRepository(model) {
|
|
|
2455
2455
|
return function(object, propertyName, index) {
|
|
2456
2456
|
let repo;
|
|
2457
2457
|
try {
|
|
2458
|
-
Container
|
|
2458
|
+
Container.registerHandler({
|
|
2459
2459
|
object,
|
|
2460
2460
|
propertyName,
|
|
2461
2461
|
index,
|
|
@@ -2830,37 +2830,37 @@ Environment = __decorate([Service()], Environment);
|
|
|
2830
2830
|
*/
|
|
2831
2831
|
init_helpers();
|
|
2832
2832
|
function AppConfig(target) {
|
|
2833
|
-
Container$
|
|
2833
|
+
Container$1.set({
|
|
2834
2834
|
id: target,
|
|
2835
2835
|
type: target
|
|
2836
2836
|
});
|
|
2837
2837
|
}
|
|
2838
2838
|
var AvleonConfig = class {
|
|
2839
2839
|
get(configClass) {
|
|
2840
|
-
const instance = Container$
|
|
2840
|
+
const instance = Container$1.get(configClass);
|
|
2841
2841
|
if (!instance) throw new Error(`Configuration for ${configClass.name} not found.`);
|
|
2842
2842
|
return instance.config(new Environment());
|
|
2843
2843
|
}
|
|
2844
2844
|
};
|
|
2845
2845
|
function GetConfig(token) {
|
|
2846
2846
|
if (typeof token === "function" && token.prototype != null && typeof token.prototype.config === "function") {
|
|
2847
|
-
const instance = Container$
|
|
2847
|
+
const instance = Container$1.get(token);
|
|
2848
2848
|
if (!instance) throw new Error(`Class "${token.name}" is not registered as a config.`);
|
|
2849
2849
|
return instance.config(inject(Environment));
|
|
2850
2850
|
}
|
|
2851
|
-
const stored = Container$
|
|
2851
|
+
const stored = Container$1.get(token);
|
|
2852
2852
|
if (!stored) throw new Error("Config object is not registered.");
|
|
2853
2853
|
return stored;
|
|
2854
2854
|
}
|
|
2855
2855
|
function CreateConfig(token, callback) {
|
|
2856
2856
|
let env;
|
|
2857
2857
|
try {
|
|
2858
|
-
env = Container$
|
|
2858
|
+
env = Container$1.get(Environment);
|
|
2859
2859
|
} catch (error) {
|
|
2860
2860
|
env = new Environment();
|
|
2861
2861
|
}
|
|
2862
2862
|
let config = callback(env);
|
|
2863
|
-
Container$
|
|
2863
|
+
Container$1.set(token, config);
|
|
2864
2864
|
}
|
|
2865
2865
|
//#endregion
|
|
2866
2866
|
//#region src/logger.ts
|
|
@@ -3021,6 +3021,6 @@ const OpenApiOk = (args1) => {
|
|
|
3021
3021
|
const OpenApiResponse = OpenApiResponse$1;
|
|
3022
3022
|
const OpenApiProperty = OpenApiProperty$1;
|
|
3023
3023
|
//#endregion
|
|
3024
|
-
export { API_CONTROLLER_METADATA_KEY, AUTHORIZATION_META_KEY, All, ApiController, AppAuthorization, AppConfig, AppMiddleware, AppService, AuthUser, AuthorizeMiddleware, Authorized, Avleon, AvleonApplication, AvleonConfig,
|
|
3024
|
+
export { API_CONTROLLER_METADATA_KEY, AUTHORIZATION_META_KEY, All, ApiController, AppAuthorization, AppConfig, AppMiddleware, AppService, AuthUser, AuthorizeMiddleware, Authorized, Avleon, AvleonApplication, AvleonConfig, container_default as AvleonContainer, AvleonMiddleware, AvleonQueue, AvleonRequest, AvleonTest, BadRequestException, BaseHttpException, Body, CONTROLLER_META_KEY, CacheManager, CanAuthorize, Collection, CreateConfig, CreateSwaggerObjectSchema, DATASOURCE_META_KEY, DB, Delete, Dispatch, Environment, EventDispatcher, EventSubscriberRegistry, FEATURE_KEY, FileStorage, ForbiddenException, Get, GetConfig, GetObjectSchema, GetSchema, Header, Helper, HttpExceptions, HttpResponse, InjectRepository, InternalErrorException, LoggerService, NotFound, NotFoundException, Ok, OpenApi, OpenApiOk, OpenApiProperty, OpenApiResponse, OpenApiSchema, Options, PARAM_META_KEY, Param, Patch, Post, Private, Put, QUERY_META_KEY, Query, Queue, REQUEST_BODY_FILES_KEY, REQUEST_BODY_FILE_KEY, REQUEST_BODY_META_KEY, REQUEST_HEADER_META_KEY, REQUEST_METADATA_KEY, REQUEST_USER_META_KEY, ROUTE_META_KEY, Results, Route, SocketContextService, Subscribe, UnauthorizedException, UseMiddleware, Utility, ValidationErrorException, Validator, autoCast, createControllerDecorator, exclude, extrctParamFromUrl, findDuplicates, formatUrl, generateClassSchema, generateSwaggerSchema, getDataType, getLineNumber, getPrivateChannelResolver, getRegisteredControllers, getRegisteredServices, getSocketSubscribers, inject, isApiController, isClassValidator, isClassValidatorClass, isConstructor, isPrivate, isValidJsonString, isValidType, jsonToInstance, jsonToJs, normalizeParamsToJsonSchema, normalizePath, normalizeQueryDeep, parsedPath, pick, registerController, registerDataSource, registerKnex, registerService, registerSocketSubscriber, sleep, transformObjectByInstanceToObject, uuid, validateObjectByInstance, validateOrThrow, validateRequestBody };
|
|
3025
3025
|
|
|
3026
3026
|
//# sourceMappingURL=index.js.map
|