@avleon/core 0.0.45 → 0.0.48

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.
Files changed (131) hide show
  1. package/README.md +355 -369
  2. package/dist/chunk-9hOWP6kD.cjs +64 -0
  3. package/dist/chunk-DORXReHP.js +37 -0
  4. package/dist/index-BxIMWhgy.d.ts +1284 -0
  5. package/dist/index-DPn7qtzq.d.cts +1283 -0
  6. package/dist/index.cjs +3194 -0
  7. package/dist/index.cjs.map +1 -0
  8. package/dist/index.js +3022 -83
  9. package/dist/index.js.map +1 -0
  10. package/dist/lib-Bk8hUm06.cjs +7847 -0
  11. package/dist/lib-Bk8hUm06.cjs.map +1 -0
  12. package/dist/lib-CvDxBMkR.js +7843 -0
  13. package/dist/lib-CvDxBMkR.js.map +1 -0
  14. package/package.json +67 -116
  15. package/dist/application.d.ts +0 -47
  16. package/dist/application.js +0 -50
  17. package/dist/authentication.d.ts +0 -13
  18. package/dist/authentication.js +0 -16
  19. package/dist/cache.d.ts +0 -12
  20. package/dist/cache.js +0 -78
  21. package/dist/cache.test.d.ts +0 -1
  22. package/dist/cache.test.js +0 -36
  23. package/dist/collection.d.ts +0 -43
  24. package/dist/collection.js +0 -231
  25. package/dist/collection.test.d.ts +0 -1
  26. package/dist/collection.test.js +0 -59
  27. package/dist/config.d.ts +0 -18
  28. package/dist/config.js +0 -58
  29. package/dist/config.test.d.ts +0 -1
  30. package/dist/config.test.js +0 -40
  31. package/dist/constants.d.ts +0 -1
  32. package/dist/constants.js +0 -4
  33. package/dist/container.d.ts +0 -30
  34. package/dist/container.js +0 -55
  35. package/dist/controller.d.ts +0 -50
  36. package/dist/controller.js +0 -71
  37. package/dist/controller.test.d.ts +0 -1
  38. package/dist/controller.test.js +0 -111
  39. package/dist/decorators.d.ts +0 -15
  40. package/dist/decorators.js +0 -41
  41. package/dist/environment-variables.d.ts +0 -49
  42. package/dist/environment-variables.js +0 -130
  43. package/dist/environment-variables.test.d.ts +0 -1
  44. package/dist/environment-variables.test.js +0 -70
  45. package/dist/event-dispatcher.d.ts +0 -23
  46. package/dist/event-dispatcher.js +0 -100
  47. package/dist/event-subscriber.d.ts +0 -14
  48. package/dist/event-subscriber.js +0 -87
  49. package/dist/exceptions/http-exceptions.d.ts +0 -50
  50. package/dist/exceptions/http-exceptions.js +0 -85
  51. package/dist/exceptions/index.d.ts +0 -1
  52. package/dist/exceptions/index.js +0 -17
  53. package/dist/exceptions/system-exception.d.ts +0 -22
  54. package/dist/exceptions/system-exception.js +0 -26
  55. package/dist/file-storage.d.ts +0 -69
  56. package/dist/file-storage.js +0 -323
  57. package/dist/file-storage.test.d.ts +0 -1
  58. package/dist/file-storage.test.js +0 -104
  59. package/dist/helpers.d.ts +0 -44
  60. package/dist/helpers.js +0 -419
  61. package/dist/helpers.test.d.ts +0 -1
  62. package/dist/helpers.test.js +0 -95
  63. package/dist/icore.d.ts +0 -226
  64. package/dist/icore.js +0 -968
  65. package/dist/icore.test.d.ts +0 -1
  66. package/dist/icore.test.js +0 -14
  67. package/dist/index.d.ts +0 -55
  68. package/dist/interfaces/avleon-application.d.ts +0 -27
  69. package/dist/interfaces/avleon-application.js +0 -1
  70. package/dist/kenx-provider.d.ts +0 -7
  71. package/dist/kenx-provider.js +0 -44
  72. package/dist/kenx-provider.test.d.ts +0 -1
  73. package/dist/kenx-provider.test.js +0 -36
  74. package/dist/logger.d.ts +0 -12
  75. package/dist/logger.js +0 -87
  76. package/dist/logger.test.d.ts +0 -1
  77. package/dist/logger.test.js +0 -42
  78. package/dist/map-types.d.ts +0 -17
  79. package/dist/map-types.js +0 -89
  80. package/dist/middleware.d.ts +0 -27
  81. package/dist/middleware.js +0 -64
  82. package/dist/middleware.test.d.ts +0 -1
  83. package/dist/middleware.test.js +0 -121
  84. package/dist/multipart.d.ts +0 -17
  85. package/dist/multipart.js +0 -70
  86. package/dist/multipart.test.d.ts +0 -1
  87. package/dist/multipart.test.js +0 -87
  88. package/dist/openapi.d.ts +0 -343
  89. package/dist/openapi.js +0 -27
  90. package/dist/openapi.test.d.ts +0 -1
  91. package/dist/openapi.test.js +0 -111
  92. package/dist/params.d.ts +0 -17
  93. package/dist/params.js +0 -64
  94. package/dist/params.test.d.ts +0 -1
  95. package/dist/params.test.js +0 -83
  96. package/dist/queue.d.ts +0 -29
  97. package/dist/queue.js +0 -84
  98. package/dist/response.d.ts +0 -16
  99. package/dist/response.js +0 -56
  100. package/dist/results.d.ts +0 -20
  101. package/dist/results.js +0 -32
  102. package/dist/route-methods.d.ts +0 -25
  103. package/dist/route-methods.js +0 -49
  104. package/dist/route-methods.test.d.ts +0 -1
  105. package/dist/route-methods.test.js +0 -129
  106. package/dist/swagger-schema.d.ts +0 -43
  107. package/dist/swagger-schema.js +0 -452
  108. package/dist/swagger-schema.test.d.ts +0 -1
  109. package/dist/swagger-schema.test.js +0 -105
  110. package/dist/testing.d.ts +0 -55
  111. package/dist/testing.js +0 -196
  112. package/dist/types/app-builder.interface.d.ts +0 -15
  113. package/dist/types/app-builder.interface.js +0 -8
  114. package/dist/types/application.interface.d.ts +0 -8
  115. package/dist/types/application.interface.js +0 -2
  116. package/dist/utils/hash.d.ts +0 -4
  117. package/dist/utils/hash.js +0 -15
  118. package/dist/utils/index.d.ts +0 -2
  119. package/dist/utils/index.js +0 -18
  120. package/dist/utils/optional-require.d.ts +0 -8
  121. package/dist/utils/optional-require.js +0 -70
  122. package/dist/validation.d.ts +0 -39
  123. package/dist/validation.js +0 -111
  124. package/dist/validation.test.d.ts +0 -1
  125. package/dist/validation.test.js +0 -61
  126. package/dist/validator-extend.d.ts +0 -7
  127. package/dist/validator-extend.js +0 -28
  128. package/dist/websocket.d.ts +0 -7
  129. package/dist/websocket.js +0 -20
  130. package/dist/websocket.test.d.ts +0 -1
  131. package/dist/websocket.test.js +0 -27
@@ -1,231 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Collection = void 0;
7
- exports.InjectRepository = InjectRepository;
8
- /**
9
- * @copyright 2024
10
- * @author Tareq Hossain
11
- * @email xtrinsic96@gmail.com
12
- * @url https://github.com/xtareq
13
- */
14
- const typedi_1 = __importDefault(require("typedi"));
15
- const exceptions_1 = require("./exceptions");
16
- class BasicCollectionImpl {
17
- constructor(items) {
18
- this.items = items;
19
- }
20
- static from(items) {
21
- return new BasicCollectionImpl(items);
22
- }
23
- clear() {
24
- this.items = [];
25
- }
26
- find(predicate) {
27
- if (this.isFunction(predicate)) {
28
- return this.items.filter(predicate);
29
- }
30
- const results = Array.from(this.items);
31
- return results;
32
- }
33
- async findAsync(predicate) {
34
- const results = Array.from(this.items);
35
- return results;
36
- }
37
- _matches(item, where) {
38
- if ("$or" in where) {
39
- return where.$or.some((cond) => this._matches(item, cond));
40
- }
41
- if ("$and" in where) {
42
- return where.$and.every((cond) => this._matches(item, cond));
43
- }
44
- if ("$not" in where) {
45
- return !this._matches(item, where.$not);
46
- }
47
- // Field-based matching
48
- return Object.entries(where).every(([key, condition]) => {
49
- const itemValue = item[key];
50
- if (condition &&
51
- typeof condition === "object" &&
52
- !Array.isArray(condition)) {
53
- const op = condition;
54
- if ("$in" in op && Array.isArray(op.$in)) {
55
- return op.$in.includes(itemValue);
56
- }
57
- }
58
- return itemValue === condition;
59
- });
60
- }
61
- findOne(predicate) {
62
- if (this.isFunction(predicate)) {
63
- return this.items.find(predicate);
64
- }
65
- const result = this.items.filter((item) => this._matches(item, predicate.where));
66
- if (result.length > 0) {
67
- return result[0];
68
- }
69
- return undefined;
70
- }
71
- async findOneAsync(predicate) {
72
- if (this.isFunction(predicate)) {
73
- return this.items.find(predicate);
74
- }
75
- return this.items.find((item) => this._matches(item, predicate.where));
76
- }
77
- // Utility function to check if a value is a function
78
- isFunction(value) {
79
- return typeof value === "function";
80
- }
81
- add(item) {
82
- this.items.push(item);
83
- return this.items[this.items.length - 1];
84
- }
85
- addAll(items) {
86
- this.items.push(...items);
87
- }
88
- update(predicate, updater) {
89
- const item = this.items.find(predicate);
90
- if (item) {
91
- const index = this.items.indexOf(item);
92
- this.items[index] = { ...item, ...updater };
93
- }
94
- else {
95
- throw new exceptions_1.NotFoundException("Item not found");
96
- }
97
- }
98
- updateAll(predicate, updater) {
99
- for (let i = 0; i < this.items.length; i++) {
100
- if (predicate(this.items[i])) {
101
- this.items[i] = updater(this.items[i]);
102
- }
103
- }
104
- }
105
- delete(predicate) {
106
- const index = this.items.findIndex(predicate);
107
- if (index !== -1) {
108
- this.items.splice(index, 1);
109
- }
110
- }
111
- deleteAll(predicate) {
112
- this.items = this.items.filter((item) => !predicate(item));
113
- }
114
- max(key) {
115
- return Math.max(...this.items.map((item) => item[key]));
116
- }
117
- min(key) {
118
- return Math.max(...this.items.map((item) => item[key]));
119
- }
120
- sum(key) {
121
- const nums = this.items.flatMap((x) => x[key]);
122
- return nums.reduce((sum, num) => sum + num, 0);
123
- }
124
- avg(key) {
125
- const nums = this.items.flatMap((x) => x[key]);
126
- return nums.reduce((sum, num) => sum + num, 0) / nums.length;
127
- }
128
- paginate(options) {
129
- const take = (options === null || options === void 0 ? void 0 : options.take) || 10;
130
- const skip = (options === null || options === void 0 ? void 0 : options.skip) || 0;
131
- const total = this.items.length;
132
- const data = this.items.slice(skip, take);
133
- return {
134
- total,
135
- totalPage: Math.ceil(total / take),
136
- next: skip + take < total ? skip + take : null,
137
- data,
138
- };
139
- }
140
- getDeepValue(item, path) {
141
- if (typeof path !== "string")
142
- return item[path];
143
- return path.split(".").reduce((acc, key) => acc === null || acc === void 0 ? void 0 : acc[key], item);
144
- }
145
- }
146
- class AsynchronousCollection {
147
- constructor(model) {
148
- this.model = model;
149
- }
150
- static fromRepository(model) {
151
- return new AsynchronousCollection(model);
152
- }
153
- getRepository() {
154
- if (!this.repo) {
155
- const dataSourceKey = "idatasource";
156
- const dataSource = typedi_1.default.get(dataSourceKey);
157
- console.log("datasource", dataSource);
158
- const repository = dataSource.getRepository(this.model);
159
- this.repo = repository;
160
- return repository;
161
- }
162
- return this.repo;
163
- }
164
- // Pagination with query builder
165
- async paginate(options) {
166
- const take = (options === null || options === void 0 ? void 0 : options.take) || 10;
167
- const skip = (options === null || options === void 0 ? void 0 : options.skip) || 0;
168
- const [data, total] = await this.getRepository().findAndCount({
169
- take,
170
- skip,
171
- });
172
- return {
173
- total,
174
- totalPage: Math.ceil(total / take),
175
- next: skip + take < total ? skip + take : null,
176
- prev: skip + take < total ? skip + take : null,
177
- data,
178
- };
179
- }
180
- }
181
- class Collection {
182
- constructor() { }
183
- static from(items) {
184
- return BasicCollectionImpl.from(items);
185
- }
186
- // Example refactoring of Collection.fromRepository for better type safety
187
- static fromRepository(entity) {
188
- const asyncCollection = AsynchronousCollection.fromRepository(entity);
189
- // Assuming AsynchronousCollection has a method to get the Repository<T>
190
- return asyncCollection.getRepository();
191
- }
192
- }
193
- exports.Collection = Collection;
194
- function InjectRepository(model) {
195
- return function (object, propertyName, index) {
196
- let repo;
197
- try {
198
- typedi_1.default.registerHandler({
199
- object,
200
- propertyName,
201
- index,
202
- value: (containerInstance) => {
203
- const dataSource = containerInstance.get("idatasource");
204
- repo = dataSource
205
- .getRepository(model)
206
- .extend({ paginate: () => { } });
207
- repo.paginate = async function (options = { take: 10, skip: 0 }) {
208
- const [data, total] = await this.findAndCount({
209
- take: options.take || 10,
210
- skip: options.skip || 0,
211
- });
212
- return {
213
- total,
214
- totalPage: Math.ceil(total / (options.take || 10)),
215
- next: options.skip + options.take < total
216
- ? options.skip + options.take
217
- : null,
218
- data,
219
- };
220
- };
221
- return repo;
222
- },
223
- });
224
- }
225
- catch (error) {
226
- if (error.name && error.name == "ServiceNotFoundError") {
227
- console.log("Database didn't initialized.");
228
- }
229
- }
230
- };
231
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,59 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const collection_1 = require("./collection");
4
- describe("Collection", () => {
5
- let collection;
6
- beforeEach(() => {
7
- collection = collection_1.Collection.from([
8
- {
9
- id: 1,
10
- body: "test 1",
11
- completed: false,
12
- },
13
- {
14
- id: 2,
15
- body: "test 2",
16
- completed: true,
17
- },
18
- {
19
- id: 3,
20
- body: "test 2",
21
- completed: true,
22
- },
23
- ]);
24
- });
25
- afterEach(() => {
26
- collection.clear();
27
- });
28
- describe("find()", () => {
29
- it("should be return collection", () => {
30
- const result = collection.find();
31
- expect(result).toHaveProperty("length");
32
- expect(result.length).toBe(3);
33
- });
34
- it("should return only completed task", () => {
35
- const result = collection.find((todo) => todo.completed);
36
- expect(result).toHaveProperty("length");
37
- expect(result.length).toBe(2);
38
- expect(result[0].id).toBe(2);
39
- });
40
- });
41
- describe("findOne()", () => {
42
- it("should be return todo", () => {
43
- const result = collection.findOne({ where: { id: 1 } });
44
- expect(result).toHaveProperty("id");
45
- expect(result === null || result === void 0 ? void 0 : result.id).toBe(1);
46
- });
47
- it("should return only completed task", () => {
48
- const result = collection.findOne({
49
- where: {
50
- id: {
51
- $in: [3],
52
- },
53
- },
54
- });
55
- expect(result).toHaveProperty("id");
56
- expect(result === null || result === void 0 ? void 0 : result.completed).toBe(true);
57
- });
58
- });
59
- });
package/dist/config.d.ts DELETED
@@ -1,18 +0,0 @@
1
- /**
2
- * @copyright 2024
3
- * @author Tareq Hossain
4
- * @email xtrinsic96@gmail.com
5
- * @url https://github.com/xtareq
6
- */
7
- import { Constructable } from "typedi";
8
- import { Environment } from "./environment-variables";
9
- export interface IConfig<T = any> {
10
- config(env: Environment): T;
11
- }
12
- export declare function AppConfig<T extends IConfig>(target: Constructable<T>): void;
13
- export declare class AvleonConfig {
14
- get<T extends IConfig<R>, R>(configClass: Constructable<T>): R;
15
- }
16
- export declare function GetConfig<T extends IConfig<R>, R = ReturnType<InstanceType<Constructable<T>>["config"]>>(ConfigClass: Constructable<T>): R;
17
- export declare function GetConfig<T = any>(config: string | symbol): T;
18
- export declare function CreateConfig<T>(token: string | symbol, callback: (env: Environment) => T): void;
package/dist/config.js DELETED
@@ -1,58 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AvleonConfig = void 0;
4
- exports.AppConfig = AppConfig;
5
- exports.GetConfig = GetConfig;
6
- exports.CreateConfig = CreateConfig;
7
- /**
8
- * @copyright 2024
9
- * @author Tareq Hossain
10
- * @email xtrinsic96@gmail.com
11
- * @url https://github.com/xtareq
12
- */
13
- const typedi_1 = require("typedi");
14
- const environment_variables_1 = require("./environment-variables");
15
- const helpers_1 = require("./helpers");
16
- function AppConfig(target) {
17
- typedi_1.Container.set({ id: target, type: target });
18
- }
19
- class AvleonConfig {
20
- get(configClass) {
21
- const instance = typedi_1.Container.get(configClass);
22
- if (!instance) {
23
- throw new Error(`Configuration for ${configClass.name} not found.`);
24
- }
25
- return instance.config(new environment_variables_1.Environment());
26
- }
27
- }
28
- exports.AvleonConfig = AvleonConfig;
29
- // Implementation
30
- function GetConfig(token) {
31
- // 1. Class‐based: token.prototype.config is a function
32
- if (typeof token === "function" &&
33
- token.prototype != null &&
34
- typeof token.prototype.config === "function") {
35
- const instance = typedi_1.Container.get(token);
36
- if (!instance) {
37
- throw new Error(`Class "${token.name}" is not registered as a config.`);
38
- }
39
- return instance.config((0, helpers_1.inject)(environment_variables_1.Environment));
40
- }
41
- // 2. Functional: token is the callback itself
42
- const stored = typedi_1.Container.get(token);
43
- if (!stored) {
44
- throw new Error("Config object is not registered.");
45
- }
46
- return stored;
47
- }
48
- function CreateConfig(token, callback) {
49
- let env;
50
- try {
51
- env = typedi_1.Container.get(environment_variables_1.Environment);
52
- }
53
- catch (error) {
54
- env = new environment_variables_1.Environment();
55
- }
56
- let config = callback(env);
57
- typedi_1.Container.set(token, config);
58
- }
@@ -1 +0,0 @@
1
- import "reflect-metadata";
@@ -1,40 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- 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;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- require("reflect-metadata");
10
- const config_1 = require("./config");
11
- describe("Config", () => {
12
- describe("class", () => {
13
- it("should be call by get config", () => {
14
- let MyConfig = class MyConfig {
15
- config(env) {
16
- return {
17
- name: "avleon",
18
- };
19
- }
20
- };
21
- MyConfig = __decorate([
22
- config_1.AppConfig
23
- ], MyConfig);
24
- const mConfig = (0, config_1.GetConfig)(MyConfig);
25
- expect(mConfig).toHaveProperty("name");
26
- expect(mConfig["name"]).toBe("avleon");
27
- });
28
- });
29
- describe("createConfig()", () => {
30
- it("it should create config and called with GetConfig", () => {
31
- (0, config_1.CreateConfig)("myconfig", (env) => ({
32
- firstname: "tareq",
33
- os: env.get("name"),
34
- }));
35
- const mConfig = (0, config_1.GetConfig)("myconfig");
36
- expect(mConfig).toHaveProperty("firstname");
37
- expect(mConfig.firstname).toBe("tareq");
38
- });
39
- });
40
- });
@@ -1 +0,0 @@
1
- export declare const TEST_DATASOURCE_OPTIONS_KEY: unique symbol;
package/dist/constants.js DELETED
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TEST_DATASOURCE_OPTIONS_KEY = void 0;
4
- exports.TEST_DATASOURCE_OPTIONS_KEY = Symbol("itestdatasource");
@@ -1,30 +0,0 @@
1
- /**
2
- * @copyright 2024
3
- * @author Tareq Hossain
4
- * @email xtrinsic96@gmail.com
5
- * @url https://github.com/xtareq
6
- */
7
- import { Knex } from "knex";
8
- import TypediContainer from "typedi";
9
- export declare const FEATURE_KEY: unique symbol;
10
- export declare const ROUTE_META_KEY: unique symbol;
11
- export declare const CONTROLLER_META_KEY: unique symbol;
12
- export declare const PARAM_META_KEY: unique symbol;
13
- export declare const QUERY_META_KEY: unique symbol;
14
- export declare const REQUEST_BODY_META_KEY: unique symbol;
15
- export declare const REQUEST_BODY_FILE_KEY: unique symbol;
16
- export declare const REQUEST_BODY_FILES_KEY: unique symbol;
17
- export declare const REQUEST_USER_META_KEY: unique symbol;
18
- export declare const REQUEST_HEADER_META_KEY: unique symbol;
19
- export declare const DATASOURCE_META_KEY: unique symbol;
20
- export declare const AUTHORIZATION_META_KEY: unique symbol;
21
- declare const Container: typeof TypediContainer;
22
- export declare function registerController(controller: Function): void;
23
- export declare function registerService(service: Function): void;
24
- export declare function getRegisteredServices(): Function[];
25
- export declare function getRegisteredControllers(): Function[];
26
- export declare const API_CONTROLLER_METADATA_KEY: unique symbol;
27
- export declare function isApiController(target: Function): boolean;
28
- export declare function registerDataSource(dataSource: any): void;
29
- export declare function registerKnex(dataSource: Knex.Config): void;
30
- export default Container;
package/dist/container.js DELETED
@@ -1,55 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
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_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 = exports.FEATURE_KEY = void 0;
7
- exports.registerController = registerController;
8
- exports.registerService = registerService;
9
- exports.getRegisteredServices = getRegisteredServices;
10
- exports.getRegisteredControllers = getRegisteredControllers;
11
- exports.isApiController = isApiController;
12
- exports.registerDataSource = registerDataSource;
13
- exports.registerKnex = registerKnex;
14
- const typedi_1 = __importDefault(require("typedi"));
15
- exports.FEATURE_KEY = Symbol.for("features");
16
- exports.ROUTE_META_KEY = Symbol("iroute:options");
17
- exports.CONTROLLER_META_KEY = Symbol("icontroller:options");
18
- exports.PARAM_META_KEY = Symbol("iparam:options");
19
- exports.QUERY_META_KEY = Symbol("iparam:options");
20
- exports.REQUEST_BODY_META_KEY = Symbol("iparam:options");
21
- exports.REQUEST_BODY_FILE_KEY = Symbol("iparam:options");
22
- exports.REQUEST_BODY_FILES_KEY = Symbol("iparam:options");
23
- exports.REQUEST_USER_META_KEY = Symbol("iparam:options");
24
- exports.REQUEST_HEADER_META_KEY = Symbol("iheader:options");
25
- exports.DATASOURCE_META_KEY = Symbol("idatasource:options");
26
- exports.AUTHORIZATION_META_KEY = Symbol("idatasource:authorization");
27
- const controllerRegistry = new Set();
28
- const serviceRegistry = new Set();
29
- const optionsRegistry = new Map();
30
- const Container = typedi_1.default;
31
- function registerController(controller) {
32
- controllerRegistry.add(controller);
33
- }
34
- function registerService(service) {
35
- Container.set(service, service);
36
- serviceRegistry.add(service);
37
- }
38
- function getRegisteredServices() {
39
- return Array.from(serviceRegistry);
40
- }
41
- function getRegisteredControllers() {
42
- return Array.from(controllerRegistry);
43
- }
44
- exports.API_CONTROLLER_METADATA_KEY = Symbol("apiController");
45
- function isApiController(target) {
46
- return Reflect.getMetadata(exports.API_CONTROLLER_METADATA_KEY, target) === true;
47
- }
48
- Container.set("appName", "Iqra");
49
- function registerDataSource(dataSource) {
50
- Container.set("idatasource", dataSource);
51
- }
52
- function registerKnex(dataSource) {
53
- Container.set("KnexConnection", dataSource);
54
- }
55
- exports.default = Container;
@@ -1,50 +0,0 @@
1
- /**
2
- * @copyright 2024
3
- * @author Tareq Hossain
4
- * @email xtrinsic96@gmail.com
5
- * @url https://github.com/xtareq
6
- */
7
- export declare const REQUEST_METADATA_KEY: unique symbol;
8
- export declare function AvleonRequest(): ParameterDecorator;
9
- /**
10
- * Options for configuring a controller.
11
- * @remarks
12
- * Controller default options
13
- * @type {Object} ControllerOptions
14
- * @property {string} [name] - The name of the controller.
15
- * @property {string} [path] - The base path for the controller's routes.
16
- * @property {string} [version] - The version of the controller. If not provided, it will default to the version from `package.json`.
17
- * @property {string} [since] - The date or version since the controller was introduced.
18
- * @property {any} [meta] - Additional metadata associated with the controller.
19
- */
20
- export type ControllerOptions = {
21
- /**
22
- *@property {string} name
23
- *@description Name of the controller. If specified it'll used as swagger tags
24
- *@default Contorller class name
25
- * */
26
- name?: string;
27
- path?: string;
28
- version?: string;
29
- since?: string;
30
- meta?: any;
31
- };
32
- export declare function createControllerDecorator(type?: "api" | "web"): (pathOrOptions?: string | ControllerOptions, maybeOptions?: ControllerOptions) => ClassDecorator;
33
- /**
34
- *@description Api controller's are used for rest . It will populate
35
- * json on return and all it http methods {get} {post} etc must return
36
- *Results.*
37
- * @param path {string} this will used as route prefix
38
- *
39
- **/
40
- export declare function ApiController(target: Function): void;
41
- export declare function ApiController(path: string): ClassDecorator;
42
- /**
43
- *@description Api controller's are used for rest . It will populate
44
- * json on return and all it http methods {get} {post} etc must return
45
- * Results.*
46
- * @param {ControllerOptions} options this will used as route prefix
47
- *
48
- **/
49
- export declare function ApiController(options: ControllerOptions): ClassDecorator;
50
- export declare function ApiController(path: string, options?: ControllerOptions): ClassDecorator;
@@ -1,71 +0,0 @@
1
- "use strict";
2
- /**
3
- * @copyright 2024
4
- * @author Tareq Hossain
5
- * @email xtrinsic96@gmail.com
6
- * @url https://github.com/xtareq
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.REQUEST_METADATA_KEY = void 0;
10
- exports.AvleonRequest = AvleonRequest;
11
- exports.createControllerDecorator = createControllerDecorator;
12
- exports.ApiController = ApiController;
13
- const typedi_1 = require("typedi");
14
- const container_1 = require("./container");
15
- exports.REQUEST_METADATA_KEY = Symbol('avleon:request');
16
- function AvleonRequest() {
17
- return (target, propertyKey, parameterIndex) => {
18
- const existingParams = Reflect.getMetadata(exports.REQUEST_METADATA_KEY, target, propertyKey) || [];
19
- existingParams.push({
20
- index: parameterIndex,
21
- type: 'request',
22
- });
23
- Reflect.defineMetadata(exports.REQUEST_METADATA_KEY, existingParams, target, propertyKey);
24
- };
25
- }
26
- function createControllerDecorator(type = "web") {
27
- return function (pathOrOptions, maybeOptions) {
28
- return function (target) {
29
- let path = "/";
30
- let options = {};
31
- if (typeof pathOrOptions === "string") {
32
- path = pathOrOptions;
33
- options = maybeOptions || {};
34
- }
35
- else if (typeof pathOrOptions === "object") {
36
- options = pathOrOptions;
37
- path = options.path || "/";
38
- }
39
- Reflect.defineMetadata(container_1.API_CONTROLLER_METADATA_KEY, true, target);
40
- // Ensure Service is applied as a ClassDecorator
41
- if (typeof typedi_1.Service === "function") {
42
- (0, container_1.registerController)(target); // Add to custom registry
43
- (0, typedi_1.Service)()(target); // Apply DI decorator
44
- Reflect.defineMetadata(container_1.CONTROLLER_META_KEY, { type, path, options }, target);
45
- }
46
- else {
47
- throw new Error("Service decorator is not a function");
48
- }
49
- };
50
- };
51
- }
52
- function ApiController(pathOrOptions = "/", mayBeOptions) {
53
- if (typeof pathOrOptions == "function") {
54
- Reflect.defineMetadata(container_1.API_CONTROLLER_METADATA_KEY, true, pathOrOptions);
55
- // Ensure Service is applied as a ClassDecorator
56
- if (typeof typedi_1.Service === "function") {
57
- (0, container_1.registerController)(pathOrOptions); // Add to custom registry
58
- (0, typedi_1.Service)()(pathOrOptions); // Apply DI decorator
59
- Reflect.defineMetadata(container_1.CONTROLLER_META_KEY, { type: "api", path: "/", options: {} }, pathOrOptions);
60
- }
61
- else {
62
- throw new Error("Service decorator is not a function");
63
- }
64
- }
65
- else {
66
- if (mayBeOptions) {
67
- return createControllerDecorator("api")(pathOrOptions, mayBeOptions);
68
- }
69
- return createControllerDecorator("api")(pathOrOptions);
70
- }
71
- }
@@ -1 +0,0 @@
1
- import "reflect-metadata";