@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.
- package/README.md +355 -369
- 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 -83
- 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 +67 -116
- package/dist/application.d.ts +0 -47
- package/dist/application.js +0 -50
- 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 -111
- 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 -23
- package/dist/event-dispatcher.js +0 -100
- 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 -104
- package/dist/helpers.d.ts +0 -44
- package/dist/helpers.js +0 -419
- package/dist/helpers.test.d.ts +0 -1
- package/dist/helpers.test.js +0 -95
- package/dist/icore.d.ts +0 -226
- package/dist/icore.js +0 -968
- package/dist/icore.test.d.ts +0 -1
- package/dist/icore.test.js +0 -14
- package/dist/index.d.ts +0 -55
- package/dist/interfaces/avleon-application.d.ts +0 -27
- package/dist/interfaces/avleon-application.js +0 -1
- 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 -27
- package/dist/middleware.js +0 -64
- 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 -343
- package/dist/openapi.js +0 -27
- 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 -49
- package/dist/route-methods.test.d.ts +0 -1
- package/dist/route-methods.test.js +0 -129
- package/dist/swagger-schema.d.ts +0 -43
- package/dist/swagger-schema.js +0 -452
- package/dist/swagger-schema.test.d.ts +0 -1
- package/dist/swagger-schema.test.js +0 -105
- package/dist/testing.d.ts +0 -55
- package/dist/testing.js +0 -196
- 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/hash.d.ts +0 -4
- package/dist/utils/hash.js +0 -15
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +0 -18
- package/dist/utils/optional-require.d.ts +0 -8
- package/dist/utils/optional-require.js +0 -70
- package/dist/validation.d.ts +0 -39
- package/dist/validation.js +0 -111
- 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 -7
- package/dist/websocket.js +0 -20
- package/dist/websocket.test.d.ts +0 -1
- package/dist/websocket.test.js +0 -27
package/package.json
CHANGED
|
@@ -1,124 +1,79 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@avleon/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.48",
|
|
4
|
+
"description": "TypeScript-first web framework built on Fastify",
|
|
5
|
+
"author": "Tareq Hossain",
|
|
6
|
+
"license": "ISC",
|
|
7
|
+
"type": "module",
|
|
4
8
|
"main": "./dist/index.js",
|
|
9
|
+
"module": "./dist/index.mjs",
|
|
5
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
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"README.md",
|
|
24
|
+
"LICENSE"
|
|
25
|
+
],
|
|
6
26
|
"keywords": [
|
|
7
27
|
"restapi",
|
|
8
28
|
"avleon",
|
|
9
29
|
"backend",
|
|
10
|
-
"fastify"
|
|
30
|
+
"fastify",
|
|
31
|
+
"typescript"
|
|
11
32
|
],
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
"directories": {
|
|
23
|
-
"test": "."
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsdown",
|
|
35
|
+
"watch": "tsdown --watch",
|
|
36
|
+
"prepublishOnly": "npm run build",
|
|
37
|
+
"lint": "eslint .",
|
|
38
|
+
"lint:fix": "eslint . --fix",
|
|
39
|
+
"format": "prettier --write .",
|
|
40
|
+
"test": "jest",
|
|
41
|
+
"test:watch": "jest --watch",
|
|
42
|
+
"husky:init": "husky install"
|
|
24
43
|
},
|
|
25
44
|
"dependencies": {
|
|
26
|
-
"bull": "^4.16.5",
|
|
27
|
-
"class-transformer": "^0.5.1",
|
|
28
|
-
"class-validator": "^0.14.2",
|
|
29
|
-
"fastify": "^5.1.0",
|
|
30
|
-
"mime": "^4.1.0",
|
|
31
|
-
"pino": "^9.10.0",
|
|
32
|
-
"pino-pretty": "^13.1.1",
|
|
33
|
-
"reflect-metadata": "^0.2.2",
|
|
34
|
-
"typedi": "^0.10.0"
|
|
35
|
-
},
|
|
36
|
-
"peerDependencies": {
|
|
37
45
|
"@fastify/cors": "^11.0.0",
|
|
38
46
|
"@fastify/multipart": "^9.0.3",
|
|
39
47
|
"@fastify/static": "^8.1.1",
|
|
40
|
-
"@fastify/swagger": "^9.
|
|
41
|
-
"@fastify/swagger-ui": "^5.
|
|
48
|
+
"@fastify/swagger": "^9.7.0",
|
|
49
|
+
"@fastify/swagger-ui": "^5.2.5",
|
|
42
50
|
"@fastify/view": "^11.0.0",
|
|
43
|
-
"@scalar/fastify-api-reference": "
|
|
44
|
-
"bcryptjs": "3.0.
|
|
45
|
-
"
|
|
51
|
+
"@scalar/fastify-api-reference": "^1.0.0",
|
|
52
|
+
"bcryptjs": "^3.0.3",
|
|
53
|
+
"bull": "^4.16.5",
|
|
54
|
+
"class-transformer": "^0.5.1",
|
|
55
|
+
"class-validator": "^0.14.2",
|
|
56
|
+
"dotenv": "^17.3.1",
|
|
57
|
+
"fastify": "^5.1.0",
|
|
46
58
|
"fastify-socket.io": "^4.0.0",
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
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"
|
|
57
71
|
},
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
|
|
61
|
-
},
|
|
62
|
-
"@fastify/cors": {
|
|
63
|
-
"optional": true
|
|
64
|
-
},
|
|
65
|
-
"@fastify/multipart": {
|
|
66
|
-
"optional": true
|
|
67
|
-
},
|
|
68
|
-
"@fastify/static": {
|
|
69
|
-
"optional": true
|
|
70
|
-
},
|
|
71
|
-
"@fastify/swagger": {
|
|
72
|
-
"optional": true
|
|
73
|
-
},
|
|
74
|
-
"@fastify/swagger-ui": {
|
|
75
|
-
"optional": true
|
|
76
|
-
},
|
|
77
|
-
"@fastify/view": {
|
|
78
|
-
"optional": true
|
|
79
|
-
},
|
|
80
|
-
"@scalar/fastify-api-reference": {
|
|
81
|
-
"optional": true
|
|
82
|
-
},
|
|
83
|
-
"ioredis": {
|
|
84
|
-
"optional": true
|
|
85
|
-
},
|
|
86
|
-
"sharp": {
|
|
87
|
-
"optional": true
|
|
88
|
-
},
|
|
89
|
-
"typeorm": {
|
|
90
|
-
"optional": true
|
|
91
|
-
},
|
|
92
|
-
"knex": {
|
|
93
|
-
"optional": true
|
|
94
|
-
},
|
|
95
|
-
"mssql": {
|
|
96
|
-
"optional": true
|
|
97
|
-
},
|
|
98
|
-
"mysql2": {
|
|
99
|
-
"optional": true
|
|
100
|
-
},
|
|
101
|
-
"pg": {
|
|
102
|
-
"optional": true
|
|
103
|
-
},
|
|
104
|
-
"sqlite3": {
|
|
105
|
-
"optional": true
|
|
106
|
-
},
|
|
107
|
-
"fastify-socket.io": {
|
|
108
|
-
"optional": true
|
|
109
|
-
},
|
|
110
|
-
"socket.io": {
|
|
111
|
-
"optional": true
|
|
112
|
-
},
|
|
113
|
-
"dotenv": {
|
|
114
|
-
"optional": true
|
|
115
|
-
},
|
|
116
|
-
"highlight.js": {
|
|
117
|
-
"optional": true
|
|
118
|
-
}
|
|
72
|
+
"optionalDependencies": {
|
|
73
|
+
"mssql": "^11.0.0",
|
|
74
|
+
"sharp": "^0.33.0"
|
|
119
75
|
},
|
|
120
76
|
"devDependencies": {
|
|
121
|
-
"@types/bcryptjs": "^3.0.0",
|
|
122
77
|
"@types/jest": "^29.5.14",
|
|
123
78
|
"@types/node": "^20.19.17",
|
|
124
79
|
"@typescript-eslint/eslint-plugin": "^8.44.0",
|
|
@@ -129,10 +84,10 @@
|
|
|
129
84
|
"jest": "^29.7.0",
|
|
130
85
|
"lint-staged": "^16.1.6",
|
|
131
86
|
"prettier": "^3.6.2",
|
|
132
|
-
"rimraf": "^6.0.1",
|
|
133
87
|
"ts-jest": "^29.4.4",
|
|
134
|
-
"
|
|
135
|
-
"typescript": "^5.7.2"
|
|
88
|
+
"tsdown": "^0.12.0",
|
|
89
|
+
"typescript": "^5.7.2",
|
|
90
|
+
"unplugin-unused": "^0.5.7"
|
|
136
91
|
},
|
|
137
92
|
"lint-staged": {
|
|
138
93
|
"*.{js,ts,json,md}": "pnpm format",
|
|
@@ -141,15 +96,11 @@
|
|
|
141
96
|
"cross-env CI=true jest --bail --findRelatedTests --passWithNoTests --config=jest.config.js"
|
|
142
97
|
]
|
|
143
98
|
},
|
|
144
|
-
"
|
|
145
|
-
"
|
|
146
|
-
"
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
"
|
|
150
|
-
"format": "prettier --write .",
|
|
151
|
-
"test": "jest",
|
|
152
|
-
"test:watch": "jest --watch",
|
|
153
|
-
"husky:init": "husky install"
|
|
99
|
+
"repository": {
|
|
100
|
+
"type": "git",
|
|
101
|
+
"url": "git+https://github.com/avleonjs/avleon-core"
|
|
102
|
+
},
|
|
103
|
+
"publishConfig": {
|
|
104
|
+
"access": "public"
|
|
154
105
|
}
|
|
155
|
-
}
|
|
106
|
+
}
|
package/dist/application.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { Constructor } from "./helpers";
|
|
2
|
-
import { RouteShorthandMethod } from "fastify";
|
|
3
|
-
export interface AvleonApplication {
|
|
4
|
-
useCors: () => void;
|
|
5
|
-
useOpenApi: () => void;
|
|
6
|
-
useView: () => void;
|
|
7
|
-
useAuth: () => void;
|
|
8
|
-
useMultipart: () => void;
|
|
9
|
-
useDataSource: () => void;
|
|
10
|
-
useMiddlewares: () => void;
|
|
11
|
-
useControllers: () => void;
|
|
12
|
-
useAutoControllers: () => void;
|
|
13
|
-
useStaticFiles: () => void;
|
|
14
|
-
useCustomErrorHandler: () => void;
|
|
15
|
-
mapGroup: () => any;
|
|
16
|
-
mapGet: () => any;
|
|
17
|
-
mapPost: () => any;
|
|
18
|
-
mapPut: () => any;
|
|
19
|
-
mapPatch: () => any;
|
|
20
|
-
mapDelete: () => any;
|
|
21
|
-
mapView: () => any;
|
|
22
|
-
run: (port: number) => void;
|
|
23
|
-
}
|
|
24
|
-
export interface InlineRoutes {
|
|
25
|
-
get: RouteShorthandMethod;
|
|
26
|
-
post: RouteShorthandMethod;
|
|
27
|
-
put: RouteShorthandMethod;
|
|
28
|
-
patch: RouteShorthandMethod;
|
|
29
|
-
delete: RouteShorthandMethod;
|
|
30
|
-
}
|
|
31
|
-
export interface Application {
|
|
32
|
-
inlineRoutes: () => InlineRoutes;
|
|
33
|
-
mapGroup: (path?: string | RegExp) => InlineRoutes;
|
|
34
|
-
/**
|
|
35
|
-
* Start the application
|
|
36
|
-
* @param port
|
|
37
|
-
* @returns void
|
|
38
|
-
*/
|
|
39
|
-
start: (port?: number) => void;
|
|
40
|
-
}
|
|
41
|
-
export interface TestApplication {
|
|
42
|
-
getController: <T>(controller: Constructor<T>) => T;
|
|
43
|
-
}
|
|
44
|
-
export declare class Builder {
|
|
45
|
-
static createApplication(): Application;
|
|
46
|
-
static createTestApplication(app?: Application): TestApplication;
|
|
47
|
-
}
|
package/dist/application.js
DELETED
|
@@ -1,50 +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.Builder = void 0;
|
|
7
|
-
const typedi_1 = __importDefault(require("typedi"));
|
|
8
|
-
const fastify_1 = __importDefault(require("fastify"));
|
|
9
|
-
class IqraTestApplication {
|
|
10
|
-
getController(controller) {
|
|
11
|
-
const con = typedi_1.default.get(controller);
|
|
12
|
-
return con;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
class IqraApplication {
|
|
16
|
-
constructor() {
|
|
17
|
-
if (!this.app) {
|
|
18
|
-
this.app = fastify_1.default.prototype;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
inlineRoutes() {
|
|
22
|
-
return {
|
|
23
|
-
get: this.app.get,
|
|
24
|
-
post: this.app.post,
|
|
25
|
-
put: this.app.put,
|
|
26
|
-
patch: this.app.patch,
|
|
27
|
-
delete: this.app.delete,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
mapGroup(path) {
|
|
31
|
-
return this.inlineRoutes();
|
|
32
|
-
}
|
|
33
|
-
start(port) {
|
|
34
|
-
const p = port ? port : 4000;
|
|
35
|
-
this.app.listen({ port: p });
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
class Builder {
|
|
39
|
-
static createApplication() {
|
|
40
|
-
const app = new IqraApplication();
|
|
41
|
-
return app;
|
|
42
|
-
}
|
|
43
|
-
static createTestApplication(app) {
|
|
44
|
-
const testApp = new IqraTestApplication();
|
|
45
|
-
return testApp;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
exports.Builder = Builder;
|
|
49
|
-
const app = Builder.createApplication();
|
|
50
|
-
const route = app.inlineRoutes();
|
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 {};
|