@avleon/core 0.0.46 → 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.
- package/License +21 -21
- package/README.md +666 -666
- package/dist/chunk-9hOWP6kD.cjs +64 -0
- package/dist/chunk-DORXReHP.js +37 -0
- package/dist/index-BxIMWhgy.d.ts +1284 -0
- package/dist/index-DPn7qtzq.d.cts +1283 -0
- package/dist/index.cjs +3194 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +3022 -79
- package/dist/index.js.map +1 -0
- package/dist/lib-Bk8hUm06.cjs +7847 -0
- package/dist/lib-Bk8hUm06.cjs.map +1 -0
- package/dist/lib-CvDxBMkR.js +7843 -0
- package/dist/lib-CvDxBMkR.js.map +1 -0
- package/package.json +41 -103
- package/dist/application.test.d.ts +0 -1
- package/dist/application.test.js +0 -15
- package/dist/authentication.d.ts +0 -13
- package/dist/authentication.js +0 -16
- package/dist/cache.d.ts +0 -12
- package/dist/cache.js +0 -78
- package/dist/cache.test.d.ts +0 -1
- package/dist/cache.test.js +0 -36
- package/dist/collection.d.ts +0 -43
- package/dist/collection.js +0 -231
- package/dist/collection.test.d.ts +0 -1
- package/dist/collection.test.js +0 -59
- package/dist/config.d.ts +0 -18
- package/dist/config.js +0 -58
- package/dist/config.test.d.ts +0 -1
- package/dist/config.test.js +0 -40
- package/dist/constants.d.ts +0 -1
- package/dist/constants.js +0 -4
- package/dist/container.d.ts +0 -30
- package/dist/container.js +0 -55
- package/dist/controller.d.ts +0 -50
- package/dist/controller.js +0 -71
- package/dist/controller.test.d.ts +0 -1
- package/dist/controller.test.js +0 -97
- package/dist/core/application.d.ts +0 -74
- package/dist/core/application.js +0 -424
- package/dist/core/router.d.ts +0 -44
- package/dist/core/router.js +0 -520
- package/dist/core/testing.d.ts +0 -21
- package/dist/core/testing.js +0 -104
- package/dist/core/types.d.ts +0 -67
- package/dist/core/types.js +0 -2
- package/dist/decorators.d.ts +0 -15
- package/dist/decorators.js +0 -41
- package/dist/environment-variables.d.ts +0 -49
- package/dist/environment-variables.js +0 -130
- package/dist/environment-variables.test.d.ts +0 -1
- package/dist/environment-variables.test.js +0 -70
- package/dist/event-dispatcher.d.ts +0 -22
- package/dist/event-dispatcher.js +0 -97
- package/dist/event-subscriber.d.ts +0 -14
- package/dist/event-subscriber.js +0 -87
- package/dist/exceptions/http-exceptions.d.ts +0 -50
- package/dist/exceptions/http-exceptions.js +0 -85
- package/dist/exceptions/index.d.ts +0 -1
- package/dist/exceptions/index.js +0 -17
- package/dist/exceptions/system-exception.d.ts +0 -22
- package/dist/exceptions/system-exception.js +0 -26
- package/dist/file-storage.d.ts +0 -69
- package/dist/file-storage.js +0 -323
- package/dist/file-storage.test.d.ts +0 -1
- package/dist/file-storage.test.js +0 -117
- package/dist/helpers.d.ts +0 -11
- package/dist/helpers.js +0 -27
- package/dist/helpers.test.d.ts +0 -1
- package/dist/helpers.test.js +0 -95
- package/dist/index.d.ts +0 -57
- package/dist/interfaces/avleon-application.d.ts +0 -75
- package/dist/interfaces/avleon-application.js +0 -2
- package/dist/kenx-provider.d.ts +0 -7
- package/dist/kenx-provider.js +0 -44
- package/dist/kenx-provider.test.d.ts +0 -1
- package/dist/kenx-provider.test.js +0 -36
- package/dist/logger.d.ts +0 -12
- package/dist/logger.js +0 -87
- package/dist/logger.test.d.ts +0 -1
- package/dist/logger.test.js +0 -42
- package/dist/map-types.d.ts +0 -17
- package/dist/map-types.js +0 -89
- package/dist/middleware.d.ts +0 -34
- package/dist/middleware.js +0 -73
- package/dist/middleware.test.d.ts +0 -1
- package/dist/middleware.test.js +0 -121
- package/dist/multipart.d.ts +0 -17
- package/dist/multipart.js +0 -70
- package/dist/multipart.test.d.ts +0 -1
- package/dist/multipart.test.js +0 -87
- package/dist/openapi.d.ts +0 -410
- package/dist/openapi.js +0 -59
- package/dist/openapi.test.d.ts +0 -1
- package/dist/openapi.test.js +0 -111
- package/dist/params.d.ts +0 -17
- package/dist/params.js +0 -64
- package/dist/params.test.d.ts +0 -1
- package/dist/params.test.js +0 -83
- package/dist/queue.d.ts +0 -29
- package/dist/queue.js +0 -84
- package/dist/response.d.ts +0 -16
- package/dist/response.js +0 -56
- package/dist/results.d.ts +0 -20
- package/dist/results.js +0 -32
- package/dist/route-methods.d.ts +0 -25
- package/dist/route-methods.js +0 -60
- package/dist/route-methods.test.d.ts +0 -1
- package/dist/route-methods.test.js +0 -129
- package/dist/swagger-schema.d.ts +0 -37
- package/dist/swagger-schema.js +0 -454
- package/dist/swagger-schema.test.d.ts +0 -1
- package/dist/swagger-schema.test.js +0 -125
- package/dist/types/app-builder.interface.d.ts +0 -15
- package/dist/types/app-builder.interface.js +0 -8
- package/dist/types/application.interface.d.ts +0 -8
- package/dist/types/application.interface.js +0 -2
- package/dist/utils/common-utils.d.ts +0 -17
- package/dist/utils/common-utils.js +0 -108
- package/dist/utils/di-utils.d.ts +0 -1
- package/dist/utils/di-utils.js +0 -22
- package/dist/utils/hash.d.ts +0 -2
- package/dist/utils/hash.js +0 -11
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +0 -18
- package/dist/utils/object-utils.d.ts +0 -11
- package/dist/utils/object-utils.js +0 -198
- package/dist/utils/optional-require.d.ts +0 -8
- package/dist/utils/optional-require.js +0 -70
- package/dist/utils/validation-utils.d.ts +0 -13
- package/dist/utils/validation-utils.js +0 -119
- package/dist/validation.d.ts +0 -39
- package/dist/validation.js +0 -108
- package/dist/validation.test.d.ts +0 -1
- package/dist/validation.test.js +0 -61
- package/dist/validator-extend.d.ts +0 -7
- package/dist/validator-extend.js +0 -28
- package/dist/websocket.d.ts +0 -10
- package/dist/websocket.js +0 -21
- package/dist/websocket.test.d.ts +0 -1
- package/dist/websocket.test.js +0 -27
package/package.json
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@avleon/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.48",
|
|
4
4
|
"description": "TypeScript-first web framework built on Fastify",
|
|
5
5
|
"author": "Tareq Hossain",
|
|
6
6
|
"license": "ISC",
|
|
7
|
+
"type": "module",
|
|
7
8
|
"main": "./dist/index.js",
|
|
9
|
+
"module": "./dist/index.mjs",
|
|
8
10
|
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./dist/index.mjs",
|
|
14
|
+
"require": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=20.0.0"
|
|
20
|
+
},
|
|
9
21
|
"files": [
|
|
10
22
|
"dist",
|
|
11
23
|
"README.md",
|
|
@@ -19,10 +31,9 @@
|
|
|
19
31
|
"typescript"
|
|
20
32
|
],
|
|
21
33
|
"scripts": {
|
|
22
|
-
"build": "
|
|
23
|
-
"
|
|
34
|
+
"build": "tsdown",
|
|
35
|
+
"watch": "tsdown --watch",
|
|
24
36
|
"prepublishOnly": "npm run build",
|
|
25
|
-
"watch": "tsc-watch",
|
|
26
37
|
"lint": "eslint .",
|
|
27
38
|
"lint:fix": "eslint . --fix",
|
|
28
39
|
"format": "prettier --write .",
|
|
@@ -31,111 +42,38 @@
|
|
|
31
42
|
"husky:init": "husky install"
|
|
32
43
|
},
|
|
33
44
|
"dependencies": {
|
|
34
|
-
"class-transformer": "^0.5.1",
|
|
35
|
-
"class-validator": "^0.14.2",
|
|
36
|
-
"fastify": "^5.1.0",
|
|
37
|
-
"mime": "^3.0.0",
|
|
38
|
-
"reflect-metadata": "^0.2.2",
|
|
39
|
-
"typedi": "^0.10.0"
|
|
40
|
-
},
|
|
41
|
-
"peerDependencies": {
|
|
42
45
|
"@fastify/cors": "^11.0.0",
|
|
43
46
|
"@fastify/multipart": "^9.0.3",
|
|
44
47
|
"@fastify/static": "^8.1.1",
|
|
45
|
-
"@fastify/swagger": "^9.
|
|
46
|
-
"@fastify/swagger-ui": "^5.
|
|
48
|
+
"@fastify/swagger": "^9.7.0",
|
|
49
|
+
"@fastify/swagger-ui": "^5.2.5",
|
|
47
50
|
"@fastify/view": "^11.0.0",
|
|
48
|
-
"@scalar/fastify-api-reference": "
|
|
49
|
-
"bcryptjs": "3.0.
|
|
51
|
+
"@scalar/fastify-api-reference": "^1.0.0",
|
|
52
|
+
"bcryptjs": "^3.0.3",
|
|
50
53
|
"bull": "^4.16.5",
|
|
51
|
-
"
|
|
54
|
+
"class-transformer": "^0.5.1",
|
|
55
|
+
"class-validator": "^0.14.2",
|
|
56
|
+
"dotenv": "^17.3.1",
|
|
57
|
+
"fastify": "^5.1.0",
|
|
52
58
|
"fastify-socket.io": "^4.0.0",
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"pino": "^
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"typeorm": "
|
|
59
|
+
"ioredis": "^5.10.1",
|
|
60
|
+
"knex": "^3.1.0",
|
|
61
|
+
"mime": "^3.0.0",
|
|
62
|
+
"mysql2": "^3.0.0",
|
|
63
|
+
"pg": "^8.0.0",
|
|
64
|
+
"pino": "^9.14.0",
|
|
65
|
+
"pino-pretty": "^13.1.3",
|
|
66
|
+
"reflect-metadata": "^0.2.2",
|
|
67
|
+
"socket.io": "^4.8.3",
|
|
68
|
+
"sqlite3": "^5.0.0",
|
|
69
|
+
"typedi": "^0.10.0",
|
|
70
|
+
"typeorm": "^0.3.28"
|
|
65
71
|
},
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
|
|
69
|
-
},
|
|
70
|
-
"@fastify/multipart": {
|
|
71
|
-
"optional": true
|
|
72
|
-
},
|
|
73
|
-
"@fastify/static": {
|
|
74
|
-
"optional": true
|
|
75
|
-
},
|
|
76
|
-
"@fastify/swagger": {
|
|
77
|
-
"optional": true
|
|
78
|
-
},
|
|
79
|
-
"@fastify/swagger-ui": {
|
|
80
|
-
"optional": true
|
|
81
|
-
},
|
|
82
|
-
"@fastify/view": {
|
|
83
|
-
"optional": true
|
|
84
|
-
},
|
|
85
|
-
"@scalar/fastify-api-reference": {
|
|
86
|
-
"optional": true
|
|
87
|
-
},
|
|
88
|
-
"bcryptjs": {
|
|
89
|
-
"optional": true
|
|
90
|
-
},
|
|
91
|
-
"bull": {
|
|
92
|
-
"optional": true
|
|
93
|
-
},
|
|
94
|
-
"dotenv": {
|
|
95
|
-
"optional": true
|
|
96
|
-
},
|
|
97
|
-
"fastify-socket.io": {
|
|
98
|
-
"optional": true
|
|
99
|
-
},
|
|
100
|
-
"highlight.js": {
|
|
101
|
-
"optional": true
|
|
102
|
-
},
|
|
103
|
-
"ioredis": {
|
|
104
|
-
"optional": true
|
|
105
|
-
},
|
|
106
|
-
"knex": {
|
|
107
|
-
"optional": true
|
|
108
|
-
},
|
|
109
|
-
"mssql": {
|
|
110
|
-
"optional": true
|
|
111
|
-
},
|
|
112
|
-
"mysql2": {
|
|
113
|
-
"optional": true
|
|
114
|
-
},
|
|
115
|
-
"pg": {
|
|
116
|
-
"optional": true
|
|
117
|
-
},
|
|
118
|
-
"pino": {
|
|
119
|
-
"optional": true
|
|
120
|
-
},
|
|
121
|
-
"pino-pretty": {
|
|
122
|
-
"optional": true
|
|
123
|
-
},
|
|
124
|
-
"sharp": {
|
|
125
|
-
"optional": true
|
|
126
|
-
},
|
|
127
|
-
"socket.io": {
|
|
128
|
-
"optional": true
|
|
129
|
-
},
|
|
130
|
-
"sqlite3": {
|
|
131
|
-
"optional": true
|
|
132
|
-
},
|
|
133
|
-
"typeorm": {
|
|
134
|
-
"optional": true
|
|
135
|
-
}
|
|
72
|
+
"optionalDependencies": {
|
|
73
|
+
"mssql": "^11.0.0",
|
|
74
|
+
"sharp": "^0.33.0"
|
|
136
75
|
},
|
|
137
76
|
"devDependencies": {
|
|
138
|
-
"@types/bcryptjs": "^3.0.0",
|
|
139
77
|
"@types/jest": "^29.5.14",
|
|
140
78
|
"@types/node": "^20.19.17",
|
|
141
79
|
"@typescript-eslint/eslint-plugin": "^8.44.0",
|
|
@@ -146,10 +84,10 @@
|
|
|
146
84
|
"jest": "^29.7.0",
|
|
147
85
|
"lint-staged": "^16.1.6",
|
|
148
86
|
"prettier": "^3.6.2",
|
|
149
|
-
"rimraf": "^6.0.1",
|
|
150
87
|
"ts-jest": "^29.4.4",
|
|
151
|
-
"
|
|
152
|
-
"typescript": "^5.7.2"
|
|
88
|
+
"tsdown": "^0.12.0",
|
|
89
|
+
"typescript": "^5.7.2",
|
|
90
|
+
"unplugin-unused": "^0.5.7"
|
|
153
91
|
},
|
|
154
92
|
"lint-staged": {
|
|
155
93
|
"*.{js,ts,json,md}": "pnpm format",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/application.test.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const testing_1 = require("./core/testing");
|
|
4
|
-
const application_1 = require("./core/application");
|
|
5
|
-
describe("Avleon.createApplication", () => {
|
|
6
|
-
it("should return an instance of AvleonApplication", () => {
|
|
7
|
-
const app = testing_1.Avleon.createApplication();
|
|
8
|
-
expect(app).toBeInstanceOf(application_1.AvleonApplication);
|
|
9
|
-
});
|
|
10
|
-
it("should always return the same instance (singleton)", () => {
|
|
11
|
-
const app1 = testing_1.Avleon.createApplication();
|
|
12
|
-
const app2 = testing_1.Avleon.createApplication();
|
|
13
|
-
expect(app1).toBe(app2);
|
|
14
|
-
});
|
|
15
|
-
});
|
package/dist/authentication.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright 2024
|
|
3
|
-
* @author Tareq Hossain
|
|
4
|
-
* @email xtrinsic96@gmail.com
|
|
5
|
-
* @url https://github.com/xtareq
|
|
6
|
-
*/
|
|
7
|
-
export type CurrentUser = {};
|
|
8
|
-
export declare abstract class BaseAuthetication {
|
|
9
|
-
abstract authenticate(): Promise<Boolean>;
|
|
10
|
-
abstract authorize(): Promise<Boolean>;
|
|
11
|
-
}
|
|
12
|
-
export declare function Authorized(): void;
|
|
13
|
-
export declare function CurrentUser(): void;
|
package/dist/authentication.js
DELETED
|
@@ -1,16 +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.BaseAuthetication = void 0;
|
|
10
|
-
exports.Authorized = Authorized;
|
|
11
|
-
exports.CurrentUser = CurrentUser;
|
|
12
|
-
class BaseAuthetication {
|
|
13
|
-
}
|
|
14
|
-
exports.BaseAuthetication = BaseAuthetication;
|
|
15
|
-
function Authorized() { }
|
|
16
|
-
function CurrentUser() { }
|
package/dist/cache.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Redis } from "ioredis";
|
|
2
|
-
export declare class CacheManager {
|
|
3
|
-
private store;
|
|
4
|
-
private tagsMap;
|
|
5
|
-
private redis;
|
|
6
|
-
constructor(redisInstance?: Redis);
|
|
7
|
-
private redisTagKey;
|
|
8
|
-
get<T>(key: string): Promise<T | null>;
|
|
9
|
-
set<T>(key: string, value: T, tags?: string[], ttl?: number): Promise<void>;
|
|
10
|
-
delete(key: string): Promise<void>;
|
|
11
|
-
invalidateTag(tag: string): Promise<void>;
|
|
12
|
-
}
|
package/dist/cache.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CacheManager = void 0;
|
|
4
|
-
class CacheManager {
|
|
5
|
-
constructor(redisInstance) {
|
|
6
|
-
this.store = new Map();
|
|
7
|
-
this.tagsMap = new Map();
|
|
8
|
-
this.redis = null;
|
|
9
|
-
this.redis = redisInstance || null;
|
|
10
|
-
}
|
|
11
|
-
redisTagKey(tag) {
|
|
12
|
-
return `cache-tags:${tag}`;
|
|
13
|
-
}
|
|
14
|
-
async get(key) {
|
|
15
|
-
if (this.redis) {
|
|
16
|
-
const val = await this.redis.get(key);
|
|
17
|
-
return val ? JSON.parse(val) : null;
|
|
18
|
-
}
|
|
19
|
-
const cached = this.store.get(key);
|
|
20
|
-
return cached ? cached.data : null;
|
|
21
|
-
}
|
|
22
|
-
async set(key, value, tags = [], ttl = 3600) {
|
|
23
|
-
const entry = {
|
|
24
|
-
data: value,
|
|
25
|
-
timestamp: Date.now(),
|
|
26
|
-
};
|
|
27
|
-
if (this.redis) {
|
|
28
|
-
await this.redis.set(key, JSON.stringify(entry.data), "EX", ttl);
|
|
29
|
-
for (const tag of tags) {
|
|
30
|
-
await this.redis.sadd(this.redisTagKey(tag), key);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
this.store.set(key, entry);
|
|
35
|
-
for (const tag of tags) {
|
|
36
|
-
if (!this.tagsMap.has(tag))
|
|
37
|
-
this.tagsMap.set(tag, new Set());
|
|
38
|
-
this.tagsMap.get(tag).add(key);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
async delete(key) {
|
|
43
|
-
if (this.redis) {
|
|
44
|
-
await this.redis.del(key);
|
|
45
|
-
// Also clean up from any tag sets
|
|
46
|
-
const tagKeys = await this.redis.keys("cache-tags:*");
|
|
47
|
-
for (const tagKey of tagKeys) {
|
|
48
|
-
await this.redis.srem(tagKey, key);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
this.store.delete(key);
|
|
53
|
-
for (const keys of this.tagsMap.values()) {
|
|
54
|
-
keys.delete(key);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
async invalidateTag(tag) {
|
|
59
|
-
if (this.redis) {
|
|
60
|
-
const tagKey = this.redisTagKey(tag);
|
|
61
|
-
const keys = await this.redis.smembers(tagKey);
|
|
62
|
-
if (keys.length) {
|
|
63
|
-
await this.redis.del(...keys); // delete all cached keys
|
|
64
|
-
await this.redis.del(tagKey); // delete the tag set
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
const keys = this.tagsMap.get(tag);
|
|
69
|
-
if (keys) {
|
|
70
|
-
for (const key of keys) {
|
|
71
|
-
this.store.delete(key);
|
|
72
|
-
}
|
|
73
|
-
this.tagsMap.delete(tag);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
exports.CacheManager = CacheManager;
|
package/dist/cache.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/cache.test.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const cache_1 = require("./cache");
|
|
4
|
-
describe("CacheManager (in-memory)", () => {
|
|
5
|
-
let cache;
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
cache = new cache_1.CacheManager();
|
|
8
|
-
});
|
|
9
|
-
it("should set and get a value", async () => {
|
|
10
|
-
await cache.set("foo", "bar");
|
|
11
|
-
const result = await cache.get("foo");
|
|
12
|
-
expect(result).toBe("bar");
|
|
13
|
-
});
|
|
14
|
-
it("should return null for missing key", async () => {
|
|
15
|
-
const result = await cache.get("missing");
|
|
16
|
-
expect(result).toBeNull();
|
|
17
|
-
});
|
|
18
|
-
it("should delete a key", async () => {
|
|
19
|
-
await cache.set("foo", "bar");
|
|
20
|
-
await cache.delete("foo");
|
|
21
|
-
const result = await cache.get("foo");
|
|
22
|
-
expect(result).toBeNull();
|
|
23
|
-
});
|
|
24
|
-
it("should associate keys with tags and invalidate by tag", async () => {
|
|
25
|
-
await cache.set("a", 1, ["tag1"]);
|
|
26
|
-
await cache.set("b", 2, ["tag1", "tag2"]);
|
|
27
|
-
await cache.set("c", 3, ["tag2"]);
|
|
28
|
-
await cache.invalidateTag("tag1");
|
|
29
|
-
expect(await cache.get("a")).toBeNull();
|
|
30
|
-
expect(await cache.get("b")).toBeNull();
|
|
31
|
-
expect(await cache.get("c")).toBe(3);
|
|
32
|
-
});
|
|
33
|
-
it("should not fail when invalidating a non-existent tag", async () => {
|
|
34
|
-
await expect(cache.invalidateTag("nope")).resolves.not.toThrow();
|
|
35
|
-
});
|
|
36
|
-
});
|
package/dist/collection.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { EntityTarget, ObjectLiteral, Repository } from "typeorm";
|
|
2
|
-
type Predicate<T> = (item: T) => boolean;
|
|
3
|
-
type ValueOperator<T> = {
|
|
4
|
-
$in?: T[];
|
|
5
|
-
};
|
|
6
|
-
type FieldCondition<T> = T | ValueOperator<T>;
|
|
7
|
-
type WhereCondition<T> = {
|
|
8
|
-
[K in keyof T]?: FieldCondition<T[K]>;
|
|
9
|
-
};
|
|
10
|
-
type LogicalOperators<T> = {
|
|
11
|
-
$and: Where<T>[];
|
|
12
|
-
} | {
|
|
13
|
-
$or: Where<T>[];
|
|
14
|
-
} | {
|
|
15
|
-
$not: Where<T>;
|
|
16
|
-
};
|
|
17
|
-
type Where<T> = WhereCondition<T> | LogicalOperators<T>;
|
|
18
|
-
export interface IFindOneOptions<T = any> {
|
|
19
|
-
where: Where<T>;
|
|
20
|
-
}
|
|
21
|
-
export type PaginationResult<T> = {
|
|
22
|
-
total: number;
|
|
23
|
-
data: T[];
|
|
24
|
-
next?: number | null;
|
|
25
|
-
prev?: number | null;
|
|
26
|
-
first?: number | null;
|
|
27
|
-
last?: number | null;
|
|
28
|
-
totalPage?: number;
|
|
29
|
-
};
|
|
30
|
-
export interface BasicCollection<T> {
|
|
31
|
-
clear(): void;
|
|
32
|
-
find(predicate?: Predicate<T>): T[];
|
|
33
|
-
findAsync(predicate?: Predicate<T>): Promise<T[]>;
|
|
34
|
-
findOne(predicate: Predicate<T> | IFindOneOptions<T>): T | undefined;
|
|
35
|
-
findOneAsync(predicate: Predicate<T> | IFindOneOptions<T>): Promise<T | undefined>;
|
|
36
|
-
}
|
|
37
|
-
export declare class Collection {
|
|
38
|
-
private constructor();
|
|
39
|
-
static from<T>(items: T[]): BasicCollection<T>;
|
|
40
|
-
static fromRepository<T extends ObjectLiteral>(entity: EntityTarget<T>): Repository<T>;
|
|
41
|
-
}
|
|
42
|
-
export declare function InjectRepository<T extends Repository<T>>(model: EntityTarget<T>): (object: any, propertyName: string | undefined, index?: number) => void;
|
|
43
|
-
export {};
|
package/dist/collection.js
DELETED
|
@@ -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 {};
|