@avleon/core 0.0.28 → 0.0.30

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 (73) hide show
  1. package/dist/application.js +1 -1
  2. package/dist/cache.d.ts +1 -1
  3. package/dist/cache.js +2 -2
  4. package/dist/collection.d.ts +25 -32
  5. package/dist/collection.js +50 -6
  6. package/dist/collection.test.d.ts +1 -0
  7. package/dist/collection.test.js +59 -0
  8. package/dist/config.d.ts +2 -0
  9. package/dist/config.js +30 -5
  10. package/dist/config.test.d.ts +1 -0
  11. package/dist/config.test.js +40 -0
  12. package/dist/controller.js +2 -2
  13. package/dist/environment-variables.js +42 -5
  14. package/dist/event-dispatcher.d.ts +23 -0
  15. package/dist/event-dispatcher.js +102 -0
  16. package/dist/event-subscriber.d.ts +15 -0
  17. package/dist/event-subscriber.js +96 -0
  18. package/dist/exceptions/http-exceptions.js +1 -1
  19. package/dist/exceptions/index.d.ts +1 -1
  20. package/dist/exceptions/system-exception.js +3 -1
  21. package/dist/file-storage.js +1 -1
  22. package/dist/helpers.js +1 -1
  23. package/dist/icore.d.ts +5 -0
  24. package/dist/icore.js +53 -18
  25. package/dist/index.d.ts +2 -0
  26. package/dist/index.js +6 -1
  27. package/dist/utils/index.d.ts +2 -2
  28. package/dist/utils/optional-require.js +2 -2
  29. package/dist/validation.d.ts +1 -1
  30. package/dist/websocket.d.ts +7 -0
  31. package/dist/websocket.js +20 -0
  32. package/dist/websocket.test.d.ts +0 -0
  33. package/dist/websocket.test.js +1 -0
  34. package/package.json +4 -3
  35. package/src/application.ts +0 -104
  36. package/src/authentication.ts +0 -16
  37. package/src/cache.ts +0 -91
  38. package/src/collection.test.ts +0 -71
  39. package/src/collection.ts +0 -344
  40. package/src/config.test.ts +0 -35
  41. package/src/config.ts +0 -85
  42. package/src/constants.ts +0 -1
  43. package/src/container.ts +0 -54
  44. package/src/controller.ts +0 -125
  45. package/src/decorators.ts +0 -27
  46. package/src/environment-variables.ts +0 -53
  47. package/src/exceptions/http-exceptions.ts +0 -86
  48. package/src/exceptions/index.ts +0 -1
  49. package/src/exceptions/system-exception.ts +0 -35
  50. package/src/file-storage.ts +0 -206
  51. package/src/helpers.ts +0 -324
  52. package/src/icore.ts +0 -1060
  53. package/src/index.ts +0 -30
  54. package/src/interfaces/avleon-application.ts +0 -32
  55. package/src/logger.ts +0 -72
  56. package/src/map-types.ts +0 -159
  57. package/src/middleware.ts +0 -119
  58. package/src/multipart.ts +0 -116
  59. package/src/openapi.ts +0 -372
  60. package/src/params.ts +0 -111
  61. package/src/queue.ts +0 -126
  62. package/src/response.ts +0 -74
  63. package/src/results.ts +0 -30
  64. package/src/route-methods.ts +0 -186
  65. package/src/swagger-schema.ts +0 -213
  66. package/src/testing.ts +0 -220
  67. package/src/types/app-builder.interface.ts +0 -18
  68. package/src/types/application.interface.ts +0 -7
  69. package/src/utils/hash.ts +0 -8
  70. package/src/utils/index.ts +0 -2
  71. package/src/utils/optional-require.ts +0 -50
  72. package/src/validation.ts +0 -160
  73. package/src/validator-extend.ts +0 -25
package/src/cache.ts DELETED
@@ -1,91 +0,0 @@
1
- import type { Redis } from "ioredis";
2
-
3
- type CacheEntry<T = any> = {
4
- data: T;
5
- timestamp: number;
6
- };
7
-
8
- export class CacheManager {
9
- private store = new Map<string, CacheEntry>();
10
- private tagsMap = new Map<string, Set<string>>();
11
- private redis: Redis | null = null;
12
-
13
- constructor(redisInstance?: Redis) {
14
- this.redis = redisInstance || null;
15
- }
16
-
17
- private redisTagKey(tag: string) {
18
- return `cache-tags:${tag}`;
19
- }
20
-
21
- async get<T>(key: string): Promise<T | null> {
22
- if (this.redis) {
23
- const val = await this.redis.get(key);
24
- return val ? JSON.parse(val) : null;
25
- }
26
-
27
- const cached = this.store.get(key);
28
- return cached ? cached.data : null;
29
- }
30
-
31
- async set<T>(
32
- key: string,
33
- value: T,
34
- tags: string[] = [],
35
- ttl: number = 3600,
36
- ): Promise<void> {
37
- const entry: CacheEntry<T> = {
38
- data: value,
39
- timestamp: Date.now(),
40
- };
41
-
42
- if (this.redis) {
43
- await this.redis.set(key, JSON.stringify(entry.data), "EX", ttl);
44
- for (const tag of tags) {
45
- await this.redis.sadd(this.redisTagKey(tag), key);
46
- }
47
- } else {
48
- this.store.set(key, entry);
49
- for (const tag of tags) {
50
- if (!this.tagsMap.has(tag)) this.tagsMap.set(tag, new Set());
51
- this.tagsMap.get(tag)!.add(key);
52
- }
53
- }
54
- }
55
-
56
- async delete(key: string): Promise<void> {
57
- if (this.redis) {
58
- await this.redis.del(key);
59
-
60
- // Also clean up from any tag sets
61
- const tagKeys = await this.redis.keys("cache-tags:*");
62
- for (const tagKey of tagKeys) {
63
- await this.redis.srem(tagKey, key);
64
- }
65
- } else {
66
- this.store.delete(key);
67
- for (const keys of this.tagsMap.values()) {
68
- keys.delete(key);
69
- }
70
- }
71
- }
72
-
73
- async invalidateTag(tag: string): Promise<void> {
74
- if (this.redis) {
75
- const tagKey = this.redisTagKey(tag);
76
- const keys = await this.redis.smembers(tagKey);
77
- if (keys.length) {
78
- await this.redis.del(...keys); // delete all cached keys
79
- await this.redis.del(tagKey); // delete the tag set
80
- }
81
- } else {
82
- const keys = this.tagsMap.get(tag);
83
- if (keys) {
84
- for (const key of keys) {
85
- this.store.delete(key);
86
- }
87
- this.tagsMap.delete(tag);
88
- }
89
- }
90
- }
91
- }
@@ -1,71 +0,0 @@
1
- import Container from "typedi";
2
- import { CreateConfig, GetConfig } from "./config";
3
- import { BasicCollection, Collection } from "./collection";
4
-
5
- type Todo = {
6
- id: number;
7
- body: string;
8
- completed: boolean;
9
- };
10
-
11
- describe("Collection", () => {
12
- let collection!: BasicCollection<Todo>;
13
- beforeEach(() => {
14
- collection = Collection.from<Todo>([
15
- {
16
- id: 1,
17
- body: "test 1",
18
- completed: false,
19
- },
20
- {
21
- id: 2,
22
- body: "test 2",
23
- completed: true,
24
- },
25
- {
26
- id: 3,
27
- body: "test 2",
28
- completed: true,
29
- },
30
- ]);
31
- });
32
-
33
- afterEach(() => {
34
- collection.clear();
35
- });
36
-
37
- describe("find()", () => {
38
- it("should be return collection", () => {
39
- const result = collection.find();
40
- expect(result).toHaveProperty("length");
41
- expect(result.length).toBe(3);
42
- });
43
-
44
- it("should return only completed task", () => {
45
- const result = collection.find((todo) => todo.completed);
46
- expect(result).toHaveProperty("length");
47
- expect(result.length).toBe(2);
48
- expect(result[0].id).toBe(2);
49
- });
50
- });
51
-
52
- describe("findOne()", () => {
53
- it("should be return todo", () => {
54
- const result = collection.findOne({ where: { id: 1 } });
55
- expect(result).toHaveProperty("id");
56
- expect(result?.id).toBe(1);
57
- });
58
-
59
- it("should return only completed task", () => {
60
- const result = collection.findOne({
61
- where: {
62
- id: {
63
- $in: [3],
64
- },
65
- },
66
- });
67
- expect(result).toHaveProperty("id");
68
- expect(result?.completed).toBe(true);
69
- });
70
- });
71
- });
package/src/collection.ts DELETED
@@ -1,344 +0,0 @@
1
- /**
2
- * @copyright 2024
3
- * @author Tareq Hossain
4
- * @email xtrinsic96@gmail.com
5
- * @url https://github.com/xtareq
6
- */
7
- import Container from "typedi";
8
- import { NotFoundException } from "./exceptions";
9
- import {
10
- DataSource,
11
- EntityTarget,
12
- FindOneOptions,
13
- ObjectLiteral,
14
- Repository,
15
- } from "typeorm";
16
- import { UpsertOptions } from "typeorm/repository/UpsertOptions";
17
-
18
- type ObjKey<T> = keyof T;
19
- type ObjKeys<T> = ObjKey<T>[];
20
- type PaginationOptions = {
21
- take: number;
22
- skip?: number;
23
- };
24
-
25
- type Predicate<T> = (item: T) => boolean;
26
- interface TypeormEnitity extends ObjectLiteral {}
27
- type Primitive = string | number | boolean | null;
28
-
29
- type ValueOperator<T> = {
30
- $in?: T[];
31
- };
32
-
33
- type FieldCondition<T> = T | ValueOperator<T>;
34
-
35
- type WhereCondition<T> = {
36
- [K in keyof T]?: FieldCondition<T[K]>;
37
- };
38
-
39
- type LogicalOperators<T> =
40
- | { $and: Where<T>[] }
41
- | { $or: Where<T>[] }
42
- | { $not: Where<T> };
43
-
44
- type Where<T> = WhereCondition<T> | LogicalOperators<T>;
45
-
46
- export interface IFindOneOptions<T = any> {
47
- where: Where<T>;
48
- }
49
-
50
- export type PaginationResult<T> = {
51
- total: number;
52
- data: T[];
53
- next?: number | null;
54
- prev?: number | null;
55
- first?: number | null;
56
- last?: number | null;
57
- totalPage?: number;
58
- };
59
-
60
- type ICollection<T> = {
61
- findAll(): T[] | Promise<T[]>;
62
- };
63
-
64
- type EntityCollection<T extends ObjectLiteral> = {};
65
-
66
- export interface BasicCollection<T> {
67
- clear(): void;
68
- find(predicate?: Predicate<T>): T[];
69
- findAsync(predicate?: Predicate<T>): Promise<T[]>;
70
- findOne(predicate: Predicate<T> | IFindOneOptions<T>): T | undefined;
71
- findOneAsync(
72
- predicate: Predicate<T> | IFindOneOptions<T>,
73
- ): Promise<T | undefined>;
74
- }
75
- class BasicCollectionImpl<T> implements BasicCollection<T> {
76
- private items: T[];
77
-
78
- private constructor(items: T[]) {
79
- this.items = items;
80
- }
81
-
82
- static from<T>(items: T[]): BasicCollectionImpl<T> {
83
- return new BasicCollectionImpl(items);
84
- }
85
-
86
- clear() {
87
- this.items = [];
88
- }
89
-
90
- find(predicate?: Predicate<T>) {
91
- if (this.isFunction(predicate)) {
92
- return this.items.filter(predicate as Predicate<T>) as T[];
93
- }
94
- const results = Array.from(this.items);
95
- return results;
96
- }
97
-
98
- async findAsync(predicate?: Predicate<T>): Promise<T[]> {
99
- const results = Array.from(this.items);
100
- return results;
101
- }
102
-
103
- private _matches<T>(item: T, where: Where<T>): boolean {
104
- if ("$or" in where) {
105
- return where.$or.some((cond) => this._matches(item, cond));
106
- }
107
-
108
- if ("$and" in where) {
109
- return where.$and.every((cond) => this._matches(item, cond));
110
- }
111
-
112
- if ("$not" in where) {
113
- return !this._matches(item, where.$not);
114
- }
115
-
116
- // Field-based matching
117
- return Object.entries(where).every(([key, condition]) => {
118
- const itemValue = item[key as keyof T];
119
- if (
120
- condition &&
121
- typeof condition === "object" &&
122
- !Array.isArray(condition)
123
- ) {
124
- const op = condition as ValueOperator<any>;
125
-
126
- if ("$in" in op && Array.isArray(op.$in)) {
127
- return op.$in.includes(itemValue);
128
- }
129
- }
130
-
131
- return itemValue === condition;
132
- });
133
- }
134
-
135
- findOne(predicate: Predicate<T> | IFindOneOptions<T>): T | undefined {
136
- if (this.isFunction(predicate)) {
137
- return this.items.find(predicate as Predicate<T>) as T;
138
- }
139
- const result = this.items.filter((item) =>
140
- this._matches(item, predicate.where),
141
- );
142
- if (result.length > 0) {
143
- return result[0];
144
- }
145
- return undefined;
146
- }
147
-
148
- async findOneAsync(
149
- predicate: Predicate<T> | IFindOneOptions<T>,
150
- ): Promise<T | undefined> {
151
- if (this.isFunction(predicate)) {
152
- return this.items.find(predicate as Predicate<T>) as T;
153
- }
154
- return this.items.find((item) => this._matches(item, predicate.where));
155
- }
156
-
157
- // Utility function to check if a value is a function
158
- private isFunction(value: unknown): value is Function {
159
- return typeof value === "function";
160
- }
161
-
162
- add(item: Partial<T>): T;
163
- add(item: Partial<T>): T | Promise<T> {
164
- this.items.push(item as T);
165
- return this.items[this.items.length - 1];
166
- }
167
-
168
- addAll(items: T[]): void {
169
- this.items.push(...items);
170
- }
171
- update(predicate: (item: T) => boolean, updater: Partial<T>): void {
172
- const item = this.items.find(predicate);
173
- if (item) {
174
- const index = this.items.indexOf(item)!;
175
- this.items[index] = { ...item, ...updater };
176
- } else {
177
- throw new NotFoundException("Item not found");
178
- }
179
- }
180
-
181
- updateAll(predicate: (item: T) => boolean, updater: (item: T) => T): void {
182
- for (let i = 0; i < this.items.length; i++) {
183
- if (predicate(this.items[i])) {
184
- this.items[i] = updater(this.items[i]);
185
- }
186
- }
187
- }
188
- delete(predicate: (item: T) => boolean): void {
189
- const index = this.items.findIndex(predicate);
190
- if (index !== -1) {
191
- this.items.splice(index, 1);
192
- }
193
- }
194
- deleteAll(predicate: (item: T) => boolean): void {
195
- this.items = this.items.filter((item) => !predicate(item));
196
- }
197
- max<K extends keyof T>(key: K & string): number {
198
- return Math.max(...this.items.map((item) => item[key] as number));
199
- }
200
-
201
- min<K extends keyof T>(key: K & string): number {
202
- return Math.max(...this.items.map((item) => item[key] as number));
203
- }
204
-
205
- sum<K extends keyof T>(key: K & string): number {
206
- const nums = this.items.flatMap((x) => x[key]) as number[];
207
- return nums.reduce((sum, num) => sum + num, 0);
208
- }
209
-
210
- avg<K extends keyof T>(key: K & string): number {
211
- const nums = this.items.flatMap((x) => x[key]) as number[];
212
- return nums.reduce((sum, num) => sum + num, 0) / nums.length;
213
- }
214
-
215
- paginate(options?: PaginationOptions) {
216
- const take = options?.take || 10;
217
- const skip = options?.skip || 0;
218
- const total = this.items.length;
219
- const data = this.items.slice(skip, take);
220
- return {
221
- total,
222
- totalPage: Math.ceil(total / take),
223
- next: skip + take < total ? skip + take : null,
224
- data,
225
- };
226
- }
227
-
228
- private getDeepValue(item: any, path: string | keyof T): any {
229
- if (typeof path !== "string") return item[path];
230
- return path.split(".").reduce((acc, key) => acc?.[key], item);
231
- }
232
- }
233
-
234
- class AsynchronousCollection<T extends ObjectLiteral> {
235
- private model: EntityTarget<T>;
236
- private repo?: Repository<T>;
237
-
238
- private constructor(model: EntityTarget<T>) {
239
- this.model = model;
240
- }
241
-
242
- static fromRepository<T extends ObjectLiteral>(
243
- model: EntityTarget<T>,
244
- ): AsynchronousCollection<T> {
245
- return new AsynchronousCollection(model);
246
- }
247
-
248
- getRepository() {
249
- if (!this.repo) {
250
- const dataSourceKey = "idatasource";
251
- const dataSource = Container.get(dataSourceKey) as DataSource;
252
- console.log("datasource", dataSource);
253
- const repository = dataSource.getRepository<T>(this.model);
254
- this.repo = repository;
255
- return repository;
256
- }
257
- return this.repo;
258
- }
259
-
260
- // Pagination with query builder
261
- async paginate(options?: PaginationOptions): Promise<PaginationResult<T>> {
262
- const take = options?.take || 10;
263
- const skip = options?.skip || 0;
264
-
265
- const [data, total] = await this.getRepository().findAndCount({
266
- take,
267
- skip,
268
- });
269
-
270
- return {
271
- total,
272
- totalPage: Math.ceil(total / take),
273
- next: skip + take < total ? skip + take : null,
274
- prev: skip + take < total ? skip + take : null,
275
- data,
276
- };
277
- }
278
- }
279
-
280
- export class Collection {
281
- private constructor() {}
282
-
283
- static from<T>(items: T[]): BasicCollection<T> {
284
- return BasicCollectionImpl.from(items);
285
- }
286
- // Example refactoring of Collection.fromRepository for better type safety
287
- static fromRepository<T extends ObjectLiteral>(
288
- entity: EntityTarget<T>,
289
- ): Repository<T> {
290
- const asyncCollection = AsynchronousCollection.fromRepository(entity);
291
- // Assuming AsynchronousCollection has a method to get the Repository<T>
292
- return asyncCollection.getRepository();
293
- }
294
- }
295
-
296
- export function InjectRepository<T extends Repository<T>>(
297
- model: EntityTarget<T>,
298
- ) {
299
- return function (
300
- object: any,
301
- propertyName: string | undefined,
302
- index?: number,
303
- ) {
304
- let repo!: any | Repository<T>;
305
- try {
306
- Container.registerHandler({
307
- object,
308
- propertyName,
309
- index,
310
- value: (containerInstance) => {
311
- const dataSource = containerInstance.get<DataSource>("idatasource");
312
-
313
- repo = dataSource
314
- .getRepository<T>(model)
315
- .extend({ paginate: () => {} });
316
- repo.paginate = async function (
317
- options: PaginationOptions = { take: 10, skip: 0 },
318
- ): Promise<PaginationResult<T>> {
319
- const [data, total] = await this.findAndCount({
320
- take: options.take || 10,
321
- skip: options.skip || 0,
322
- });
323
-
324
- return {
325
- total,
326
- totalPage: Math.ceil(total / (options.take || 10)),
327
- next:
328
- options.skip! + options.take! < total
329
- ? options.skip! + options.take!
330
- : null,
331
- data,
332
- };
333
- };
334
- return repo;
335
- },
336
- });
337
- } catch (error: any) {
338
- console.log(error);
339
- if (error.name && error.name == "ServiceNotFoundError") {
340
- console.log("Database didn't initialized.");
341
- }
342
- }
343
- };
344
- }
@@ -1,35 +0,0 @@
1
- import "reflect-metadata";
2
- import { Config, CreateConfig, GetConfig, IConfig } from "./config";
3
- import { Environment } from "./environment-variables";
4
-
5
- type AppConfig = { name: string; os: string };
6
-
7
- describe("Config", () => {
8
- describe("class", () => {
9
- it("should be call by get config", () => {
10
- @Config
11
- class MyConfig {
12
- config(env: Environment) {
13
- return {
14
- name: "avleon",
15
- };
16
- }
17
- }
18
- const mConfig = GetConfig(MyConfig);
19
- expect(mConfig).toHaveProperty("name");
20
- expect(mConfig["name"]).toBe("avleon");
21
- });
22
- });
23
-
24
- describe("createConfig()", () => {
25
- it("it should create config and called with GetConfig", () => {
26
- CreateConfig("myconfig", (env) => ({
27
- firstname: "tareq",
28
- os: env.get("name"),
29
- }));
30
- const mConfig = GetConfig("myconfig");
31
- expect(mConfig).toHaveProperty("firstname");
32
- expect(mConfig.firstname).toBe("tareq");
33
- });
34
- });
35
- });
package/src/config.ts DELETED
@@ -1,85 +0,0 @@
1
- /**
2
- * @copyright 2024
3
- * @author Tareq Hossain
4
- * @email xtrinsic96@gmail.com
5
- * @url https://github.com/xtareq
6
- */
7
- import { Container, Service, Constructable, Token } from "typedi";
8
- import { Environment } from "./environment-variables";
9
- import { inject } from "./helpers";
10
-
11
- export interface IConfig<T = any> {
12
- config(env: Environment): T;
13
- }
14
-
15
- export function Config<T extends IConfig>(target: Constructable<T>) {
16
- Container.set({ id: target, type: target });
17
- }
18
-
19
- export class AppConfig {
20
- get<T extends IConfig<R>, R>(configClass: Constructable<T>): R {
21
- const instance = Container.get(configClass);
22
- if (!instance) {
23
- throw new Error(`Configuration for ${configClass.name} not found.`);
24
- }
25
- return instance.config(new Environment());
26
- }
27
- }
28
-
29
- // export function GetConfig<
30
- // T extends IConfig<R>,
31
- // R = ReturnType<InstanceType<Constructable<T>>["config"]>,
32
- // >(ConfigClass: Constructable<T>): R {
33
- // const instance = Container.get(ConfigClass);
34
- // if (!instance) {
35
- // throw new Error(
36
- // `Class "${ConfigClass.name}" is not registered as a config.`,
37
- // );
38
- // }
39
- // return instance.config(new Environment());
40
- // }
41
-
42
- export function GetConfig<
43
- T extends IConfig<R>,
44
- R = ReturnType<InstanceType<Constructable<T>>["config"]>,
45
- >(ConfigClass: Constructable<T>): R;
46
-
47
- export function GetConfig<T = any>(config: string | symbol): T;
48
-
49
- // Implementation
50
- export function GetConfig<R>(token: any): R {
51
- // 1. Class‐based: token.prototype.config is a function
52
- if (
53
- typeof token === "function" &&
54
- token.prototype != null &&
55
- typeof token.prototype.config === "function"
56
- ) {
57
- const instance = Container.get(token as Constructable<any>);
58
- if (!instance) {
59
- throw new Error(`Class "${token.name}" is not registered as a config.`);
60
- }
61
- return instance.config(inject(Environment));
62
- }
63
-
64
- // 2. Functional: token is the callback itself
65
- const stored = Container.get(token);
66
- if (!stored) {
67
- throw new Error("Config object is not registered.");
68
- }
69
- return stored as R;
70
- }
71
-
72
- export function CreateConfig<T>(
73
- token: string | symbol,
74
- callback: (env: Environment) => T,
75
- ) {
76
- let env!: Environment;
77
- try {
78
- env = Container.get(Environment);
79
- } catch (error) {
80
- env = new Environment();
81
- }
82
-
83
- let config: T = callback(env);
84
- Container.set<T>(token as Token<T>, config);
85
- }
package/src/constants.ts DELETED
@@ -1 +0,0 @@
1
- export const TEST_DATASOURCE_OPTIONS_KEY = Symbol("itestdatasource");
package/src/container.ts DELETED
@@ -1,54 +0,0 @@
1
- /**
2
- * @copyright 2024
3
- * @author Tareq Hossain
4
- * @email xtrinsic96@gmail.com
5
- * @url https://github.com/xtareq
6
- */
7
- import TypediContainer, { ContainerInstance, Token } from "typedi";
8
- import { DataSource } from "typeorm";
9
-
10
- export const FEATURE_KEY = Symbol.for("features");
11
- export const ROUTE_META_KEY = Symbol("iroute:options");
12
- export const CONTROLLER_META_KEY = Symbol("icontroller:options");
13
- export const PARAM_META_KEY = Symbol("iparam:options");
14
- export const QUERY_META_KEY = Symbol("iparam:options");
15
- export const REQUEST_BODY_META_KEY = Symbol("iparam:options");
16
- export const REQUEST_BODY_FILE_KEY = Symbol("iparam:options");
17
- export const REQUEST_BODY_FILES_KEY = Symbol("iparam:options");
18
- export const REQUEST_USER_META_KEY = Symbol("iparam:options");
19
- export const REQUEST_HEADER_META_KEY = Symbol("iheader:options");
20
- export const DATASOURCE_META_KEY = Symbol("idatasource:options");
21
- export const AUTHORIZATION_META_KEY = Symbol("idatasource:authorization");
22
-
23
- const controllerRegistry = new Set<Function>();
24
- const serviceRegistry = new Set<Function>();
25
- const optionsRegistry = new Map<string, any>();
26
-
27
- const Container = TypediContainer;
28
-
29
- export function registerController(controller: Function) {
30
- controllerRegistry.add(controller);
31
- }
32
- export function registerService(service: Function) {
33
- Container.set(service, service);
34
- serviceRegistry.add(service);
35
- }
36
-
37
- export function getRegisteredServices(): Function[] {
38
- return Array.from(serviceRegistry);
39
- }
40
- export function getRegisteredControllers(): Function[] {
41
- return Array.from(controllerRegistry);
42
- }
43
-
44
- export const API_CONTROLLER_METADATA_KEY = Symbol("apiController");
45
-
46
- export function isApiController(target: Function): boolean {
47
- return Reflect.getMetadata(API_CONTROLLER_METADATA_KEY, target) === true;
48
- }
49
- Container.set<string>("appName", "Iqra");
50
-
51
- export function registerDataSource(dataSource: any) {
52
- Container.set<DataSource>("idatasource", dataSource);
53
- }
54
- export default Container;