@zeltjs/redis 0.4.0 → 0.6.0
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 +36 -0
- package/dist/index.js +20 -6
- package/dist/index.js.map +1 -1
- package/dist/redis.config-DvXFWRzU.js +31 -0
- package/dist/redis.config-DvXFWRzU.js.map +1 -0
- package/dist/testing/index.js +20 -7
- package/dist/testing/index.js.map +1 -1
- package/package.json +5 -5
- package/dist/redis.config-tNzVzgF8.js +0 -17
- package/dist/redis.config-tNzVzgF8.js.map +0 -1
package/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# @zeltjs/redis
|
|
2
|
+
|
|
3
|
+
[](https://zeltjs.com)
|
|
4
|
+
|
|
5
|
+
Redis integration for Zelt applications.
|
|
6
|
+
|
|
7
|
+
**[Read the Documentation](https://zeltjs.com)**
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @zeltjs/redis @zeltjs/core
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { createApp, Controller, Get, inject } from '@zeltjs/core';
|
|
19
|
+
import { RedisConfig, RedisService } from '@zeltjs/redis';
|
|
20
|
+
|
|
21
|
+
@Controller('/cache')
|
|
22
|
+
class CacheController {
|
|
23
|
+
constructor(private redis = inject(RedisService)) {}
|
|
24
|
+
|
|
25
|
+
@Get('/:key')
|
|
26
|
+
async get(key: string) {
|
|
27
|
+
const value = await this.redis.get(key);
|
|
28
|
+
return { value };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const app = createApp({
|
|
33
|
+
http: { controllers: [CacheController] },
|
|
34
|
+
configs: [RedisConfig],
|
|
35
|
+
});
|
|
36
|
+
```
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import { t as RedisConfig } from "./redis.config-
|
|
1
|
+
import { t as RedisConfig } from "./redis.config-DvXFWRzU.js";
|
|
2
2
|
import { Injectable, LifecycleManager, inject } from "@zeltjs/core";
|
|
3
3
|
import Redis from "ioredis";
|
|
4
4
|
//#region src/redis.service.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
6
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
7
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
8
|
+
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;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
}
|
|
11
|
+
function _ts_metadata(k, v) {
|
|
12
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
13
|
+
}
|
|
14
|
+
var RedisService = class {
|
|
10
15
|
get client() {
|
|
11
16
|
return this._client;
|
|
12
17
|
}
|
|
@@ -14,7 +19,16 @@ var RedisService = @Injectable() class {
|
|
|
14
19
|
async shutdown() {
|
|
15
20
|
this._client.disconnect();
|
|
16
21
|
}
|
|
22
|
+
constructor(config = inject(RedisConfig), lifecycle = inject(LifecycleManager)) {
|
|
23
|
+
this._client = new Redis(config.url, config.options);
|
|
24
|
+
lifecycle.register(this);
|
|
25
|
+
}
|
|
17
26
|
};
|
|
27
|
+
RedisService = _ts_decorate([
|
|
28
|
+
Injectable(),
|
|
29
|
+
_ts_metadata("design:type", Function),
|
|
30
|
+
_ts_metadata("design:paramtypes", [void 0, void 0])
|
|
31
|
+
], RedisService);
|
|
18
32
|
//#endregion
|
|
19
33
|
export { RedisConfig, RedisService };
|
|
20
34
|
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/redis.service.ts"],"sourcesContent":["import type { Lifecycle } from '@zeltjs/core';\nimport { Injectable, inject, LifecycleManager } from '@zeltjs/core';\nimport Redis from 'ioredis';\n\nimport { RedisConfig } from './redis.config';\n\n@Injectable()\nexport class RedisService implements Lifecycle {\n private readonly _client: Redis;\n\n constructor(config = inject(RedisConfig), lifecycle = inject(LifecycleManager)) {\n this._client = new Redis(config.url, config.options);\n lifecycle.register(this);\n }\n\n get client(): Redis {\n return this._client;\n }\n\n async startup(): Promise<void> {}\n\n async shutdown(): Promise<void> {\n this._client.disconnect();\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":["Injectable","inject","LifecycleManager","Redis","RedisConfig","RedisService","client","_client","startup","shutdown","disconnect","config","lifecycle","url","options","register"],"sources":["../src/redis.service.ts"],"sourcesContent":["import type { Lifecycle } from '@zeltjs/core';\nimport { Injectable, inject, LifecycleManager } from '@zeltjs/core';\nimport Redis from 'ioredis';\n\nimport { RedisConfig } from './redis.config';\n\n@Injectable()\nexport class RedisService implements Lifecycle {\n private readonly _client: Redis;\n\n constructor(config = inject(RedisConfig), lifecycle = inject(LifecycleManager)) {\n this._client = new Redis(config.url, config.options);\n lifecycle.register(this);\n }\n\n get client(): Redis {\n return this._client;\n }\n\n async startup(): Promise<void> {}\n\n async shutdown(): Promise<void> {\n this._client.disconnect();\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAOA,IAAaK,eAAb,MAAaA;CAQX,IAAIC,SAAgB;AAClB,SAAO,KAAKC;;CAGd,MAAMC,UAAyB;CAE/B,MAAMC,WAA0B;AAC9B,OAAKF,QAAQG,YAAU;;CAZzB,YAAYC,SAASV,OAAOG,YAAY,EAAEQ,YAAYX,OAAOC,iBAAiB,EAAE;AAC9E,OAAKK,UAAU,IAAIJ,MAAMQ,OAAOE,KAAKF,OAAOG,QAAO;AACnDF,YAAUG,SAAS,KAAI"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Config, EnvService, inject } from "@zeltjs/core";
|
|
2
|
+
//#region src/redis.config.ts
|
|
3
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
4
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
5
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
6
|
+
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;
|
|
7
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
8
|
+
}
|
|
9
|
+
function _ts_metadata(k, v) {
|
|
10
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
11
|
+
}
|
|
12
|
+
var RedisConfig = class {
|
|
13
|
+
get url() {
|
|
14
|
+
return this.env.getString("REDIS_URL", "redis://localhost:6379");
|
|
15
|
+
}
|
|
16
|
+
get options() {
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
19
|
+
constructor(env = inject(EnvService)) {
|
|
20
|
+
this.env = env;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
RedisConfig = _ts_decorate([
|
|
24
|
+
Config,
|
|
25
|
+
_ts_metadata("design:type", Function),
|
|
26
|
+
_ts_metadata("design:paramtypes", [void 0])
|
|
27
|
+
], RedisConfig);
|
|
28
|
+
//#endregion
|
|
29
|
+
export { RedisConfig as t };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=redis.config-DvXFWRzU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redis.config-DvXFWRzU.js","names":["Config","EnvService","inject","RedisConfig","url","env","getString","options"],"sources":["../src/redis.config.ts"],"sourcesContent":["import { Config, EnvService, inject } from '@zeltjs/core';\nimport type { RedisOptions } from 'ioredis';\n\n@Config\nexport class RedisConfig {\n constructor(private env = inject(EnvService)) {}\n\n get url(): string {\n return this.env.getString('REDIS_URL', 'redis://localhost:6379');\n }\n\n get options(): RedisOptions {\n return {};\n }\n}\n"],"mappings":";;;;;;;;;;;AAIA,IAAaG,cAAb,MAAaA;CAGX,IAAIC,MAAc;AAChB,SAAO,KAAKC,IAAIC,UAAU,aAAa,yBAAA;;CAGzC,IAAIC,UAAwB;AAC1B,SAAO,EAAC;;CAPV,YAAY,MAAcL,OAAOD,WAAW,EAAE;OAA1BI,MAAAA"}
|
package/dist/testing/index.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import { t as RedisConfig } from "../redis.config-
|
|
1
|
+
import { t as RedisConfig } from "../redis.config-DvXFWRzU.js";
|
|
2
2
|
import { Config, LifecycleManager, inject } from "@zeltjs/core";
|
|
3
3
|
import { GenericContainer } from "testcontainers";
|
|
4
4
|
//#region src/testing/redis-test-container.config.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
6
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
7
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
8
|
+
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;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
}
|
|
11
|
+
function _ts_metadata(k, v) {
|
|
12
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
13
|
+
}
|
|
14
|
+
var RedisTestContainerConfig = class extends RedisConfig {
|
|
11
15
|
get image() {
|
|
12
16
|
return "redis:7-alpine";
|
|
13
17
|
}
|
|
@@ -26,7 +30,16 @@ var RedisTestContainerConfig = @Config class extends RedisConfig {
|
|
|
26
30
|
get options() {
|
|
27
31
|
return {};
|
|
28
32
|
}
|
|
33
|
+
constructor(lifecycle = inject(LifecycleManager)) {
|
|
34
|
+
super(), this.connectionUrl = "";
|
|
35
|
+
lifecycle.register(this);
|
|
36
|
+
}
|
|
29
37
|
};
|
|
38
|
+
RedisTestContainerConfig = _ts_decorate([
|
|
39
|
+
Config,
|
|
40
|
+
_ts_metadata("design:type", Function),
|
|
41
|
+
_ts_metadata("design:paramtypes", [void 0])
|
|
42
|
+
], RedisTestContainerConfig);
|
|
30
43
|
//#endregion
|
|
31
44
|
export { RedisTestContainerConfig };
|
|
32
45
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/testing/redis-test-container.config.ts"],"sourcesContent":["import type { Lifecycle } from '@zeltjs/core';\nimport { Config, inject, LifecycleManager } from '@zeltjs/core';\nimport type { StartedTestContainer } from 'testcontainers';\nimport { GenericContainer } from 'testcontainers';\n\nimport { RedisConfig } from '../redis.config';\n\n@Config\nexport class RedisTestContainerConfig extends RedisConfig implements Lifecycle {\n private container: StartedTestContainer | undefined;\n private connectionUrl = '';\n\n constructor(lifecycle = inject(LifecycleManager)) {\n super();\n lifecycle.register(this);\n }\n\n protected get image(): string {\n return 'redis:7-alpine';\n }\n\n async startup(): Promise<void> {\n this.container = await new GenericContainer(this.image).withExposedPorts(6379).start();\n const host = this.container.getHost();\n const port = this.container.getMappedPort(6379);\n this.connectionUrl = `redis://${host}:${port}`;\n }\n\n async shutdown(): Promise<void> {\n await this.container?.stop();\n }\n\n override get url(): string {\n return this.connectionUrl;\n }\n\n override get options(): RedisConfig['options'] {\n return {};\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":["Config","inject","LifecycleManager","GenericContainer","RedisConfig","RedisTestContainerConfig","image","startup","container","withExposedPorts","start","host","getHost","port","getMappedPort","connectionUrl","shutdown","stop","url","options","lifecycle","register"],"sources":["../../src/testing/redis-test-container.config.ts"],"sourcesContent":["import type { Lifecycle } from '@zeltjs/core';\nimport { Config, inject, LifecycleManager } from '@zeltjs/core';\nimport type { StartedTestContainer } from 'testcontainers';\nimport { GenericContainer } from 'testcontainers';\n\nimport { RedisConfig } from '../redis.config';\n\n@Config\nexport class RedisTestContainerConfig extends RedisConfig implements Lifecycle {\n private container: StartedTestContainer | undefined;\n private connectionUrl = '';\n\n constructor(lifecycle = inject(LifecycleManager)) {\n super();\n lifecycle.register(this);\n }\n\n protected get image(): string {\n return 'redis:7-alpine';\n }\n\n async startup(): Promise<void> {\n this.container = await new GenericContainer(this.image).withExposedPorts(6379).start();\n const host = this.container.getHost();\n const port = this.container.getMappedPort(6379);\n this.connectionUrl = `redis://${host}:${port}`;\n }\n\n async shutdown(): Promise<void> {\n await this.container?.stop();\n }\n\n override get url(): string {\n return this.connectionUrl;\n }\n\n override get options(): RedisConfig['options'] {\n return {};\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAQA,IAAaK,2BAAb,cAA8CD,YAAAA;CAS5C,IAAcE,QAAgB;AAC5B,SAAO;;CAGT,MAAMC,UAAyB;AAC7B,OAAKC,YAAY,MAAM,IAAIL,iBAAiB,KAAKG,MAAK,CAAEG,iBAAiB,KAAA,CAAMC,OAAK;EACpF,MAAMC,OAAO,KAAKH,UAAUI,SAAO;EACnC,MAAMC,OAAO,KAAKL,UAAUM,cAAc,KAAA;AAC1C,OAAKC,gBAAgB,WAAWJ,KAAK,GAAGE;;CAG1C,MAAMG,WAA0B;AAC9B,QAAM,KAAKR,WAAWS,MAAAA;;CAGxB,IAAaC,MAAc;AACzB,SAAO,KAAKH;;CAGd,IAAaI,UAAkC;AAC7C,SAAO,EAAC;;CAzBV,YAAYC,YAAYnB,OAAOC,iBAAiB,EAAE;AAChD,SAAK,EAAA,KAHCa,gBAAgB;AAItBK,YAAUC,SAAS,KAAI"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeltjs/redis",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
],
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"testcontainers": ">=10 <12",
|
|
29
|
-
"@zeltjs/core": "0.
|
|
30
|
-
"@zeltjs/testing": "0.
|
|
29
|
+
"@zeltjs/core": "0.6.0",
|
|
30
|
+
"@zeltjs/testing": "0.6.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependenciesMeta": {
|
|
33
33
|
"@zeltjs/testing": {
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/node": "22.19.17",
|
|
45
45
|
"testcontainers": "10.25.0",
|
|
46
|
-
"@zeltjs/core": "0.
|
|
47
|
-
"@zeltjs/testing": "0.
|
|
46
|
+
"@zeltjs/core": "0.6.0",
|
|
47
|
+
"@zeltjs/testing": "0.6.0"
|
|
48
48
|
},
|
|
49
49
|
"volta": {
|
|
50
50
|
"extends": "../../package.json"
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Config, EnvService, inject } from "@zeltjs/core";
|
|
2
|
-
//#region src/redis.config.ts
|
|
3
|
-
var RedisConfig = @Config class {
|
|
4
|
-
constructor(env = inject(EnvService)) {
|
|
5
|
-
this.env = env;
|
|
6
|
-
}
|
|
7
|
-
get url() {
|
|
8
|
-
return this.env.getString("REDIS_URL", "redis://localhost:6379");
|
|
9
|
-
}
|
|
10
|
-
get options() {
|
|
11
|
-
return {};
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
//#endregion
|
|
15
|
-
export { RedisConfig as t };
|
|
16
|
-
|
|
17
|
-
//# sourceMappingURL=redis.config-tNzVzgF8.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"redis.config-tNzVzgF8.js","names":[],"sources":["../src/redis.config.ts"],"sourcesContent":["import { Config, EnvService, inject } from '@zeltjs/core';\nimport type { RedisOptions } from 'ioredis';\n\n@Config\nexport class RedisConfig {\n constructor(private env = inject(EnvService)) {}\n\n get url(): string {\n return this.env.getString('REDIS_URL', 'redis://localhost:6379');\n }\n\n get options(): RedisOptions {\n return {};\n }\n}\n"],"mappings":";;AAIA,IAAa,cADb,CAAC,OAAD,MACyB;CACvB,YAAY,MAAc,OAAO,WAAW,EAAE;AAA1B,OAAA,MAAA;;CAEpB,IAAI,MAAc;AAChB,SAAO,KAAK,IAAI,UAAU,aAAa,yBAAyB;;CAGlE,IAAI,UAAwB;AAC1B,SAAO,EAAE"}
|