@alpha018/nestjs-redisom 1.0.1 → 1.1.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 +52 -12
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/redis-om/errors/index.d.ts +3 -0
- package/dist/redis-om/errors/index.js +14 -0
- package/dist/redis-om/errors/index.js.map +1 -0
- package/dist/redis-om/errors/redis-om-error.code.d.ts +7 -0
- package/dist/redis-om/errors/redis-om-error.code.js +12 -0
- package/dist/redis-om/errors/redis-om-error.code.js.map +1 -0
- package/dist/redis-om/errors/redis-om.exception.d.ts +9 -0
- package/dist/redis-om/errors/redis-om.exception.js +20 -0
- package/dist/redis-om/errors/redis-om.exception.js.map +1 -0
- package/dist/redis-om/errors/redis-om.exceptions.d.ts +24 -0
- package/dist/redis-om/errors/redis-om.exceptions.js +33 -0
- package/dist/redis-om/errors/redis-om.exceptions.js.map +1 -0
- package/dist/redis-om/interfaces/index.d.ts +2 -2
- package/dist/redis-om/redis-om-core.module.d.ts +3 -0
- package/dist/redis-om/redis-om-core.module.js +32 -6
- package/dist/redis-om/redis-om-core.module.js.map +1 -1
- package/dist/redis-om/redis-om.module.d.ts +1 -2
- package/dist/redis-om/redis-om.module.js +19 -1
- package/dist/redis-om/redis-om.module.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +44 -41
package/README.md
CHANGED
|
@@ -18,20 +18,23 @@
|
|
|
18
18
|
<a href="https://github.com/Alpha018/nestjs-redisom">
|
|
19
19
|
<img src="https://img.shields.io/github/stars/Alpha018/nestjs-redisom?style=social" alt="GitHub stars">
|
|
20
20
|
</a>
|
|
21
|
+
<a href="https://www.buymeacoffee.com/alpha018" target="_blank">
|
|
22
|
+
<img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" height="20px">
|
|
23
|
+
</a>
|
|
21
24
|
</div>
|
|
22
25
|
|
|
23
|
-
|
|
24
26
|
## Description
|
|
25
27
|
|
|
26
28
|
This library seamlessly integrates [RedisOM](https://redis.io/docs/latest/integrate/redisom-for-node-js/) into NestJS, offering:
|
|
27
|
-
|
|
28
|
-
-
|
|
29
|
-
-
|
|
29
|
+
|
|
30
|
+
- **Decorator-based Schema Definition**: Define your entities using `@Schema` and `@Prop`.
|
|
31
|
+
- **Repository Injection**: Inject repositories directly into your services using `@InjectRepository`.
|
|
32
|
+
- **Seamless Connection**: Configure your Redis connection globally with `forRoot` or `forRootAsync`.
|
|
30
33
|
|
|
31
34
|
## Installation
|
|
32
35
|
|
|
33
36
|
```bash
|
|
34
|
-
|
|
37
|
+
npm install @alpha018/nestjs-redisom redis-om redis
|
|
35
38
|
```
|
|
36
39
|
|
|
37
40
|
## Quick Start
|
|
@@ -55,6 +58,8 @@ export class CatEntity extends BaseEntity {
|
|
|
55
58
|
}
|
|
56
59
|
```
|
|
57
60
|
|
|
61
|
+
> **Note**: For all available property decorators, indexing options, and schema definitions, see the [Wiki: Defining Structures](https://github.com/Alpha018/nestjs-redisom/wiki/Defining-Structures).
|
|
62
|
+
|
|
58
63
|
### 2. Import the Module
|
|
59
64
|
|
|
60
65
|
Register `RedisOmModule` in your root `AppModule` and register your entities with `forFeature`.
|
|
@@ -75,6 +80,8 @@ import { CatEntity } from './cat.entity';
|
|
|
75
80
|
export class AppModule {}
|
|
76
81
|
```
|
|
77
82
|
|
|
83
|
+
> **Note**: For advanced connection setups, environmental validation, and asynchronous options, see the [Wiki: Configuration](https://github.com/Alpha018/nestjs-redisom/wiki/Configuration).
|
|
84
|
+
|
|
78
85
|
### 3. Usage in a Service
|
|
79
86
|
|
|
80
87
|
Inject the repository to save and search for entities.
|
|
@@ -104,6 +111,8 @@ export class CatsService {
|
|
|
104
111
|
}
|
|
105
112
|
```
|
|
106
113
|
|
|
114
|
+
> **Note**: To learn about all search capabilities and query building, see the [Wiki: Searching](https://github.com/Alpha018/nestjs-redisom/wiki/Searching).
|
|
115
|
+
|
|
107
116
|
## Advanced Usage
|
|
108
117
|
|
|
109
118
|
### 1. Nested Typed Objects
|
|
@@ -150,6 +159,8 @@ const results = await this.personRepo.search()
|
|
|
150
159
|
.return.all();
|
|
151
160
|
```
|
|
152
161
|
|
|
162
|
+
> **Note**: Discover more about embedded objects and array structures in the [Wiki: Defining Structures](https://github.com/Alpha018/nestjs-redisom/wiki/Defining-Structures).
|
|
163
|
+
|
|
153
164
|
### 2. Custom IDs
|
|
154
165
|
|
|
155
166
|
You can explicitly set the ID when saving an entity if you don't want to use the auto-generated ULID. This is useful for using existing IDs (like UUIDs, emails, or external system IDs).
|
|
@@ -164,6 +175,8 @@ await this.catRepo.save(id, entity);
|
|
|
164
175
|
await this.catRepo.save('unique-custom-id', entity);
|
|
165
176
|
```
|
|
166
177
|
|
|
178
|
+
> **Note**: Read more about identifier strategies in the [Wiki: Defining Structures](https://github.com/Alpha018/nestjs-redisom/wiki/Defining-Structures).
|
|
179
|
+
|
|
167
180
|
### 3. TTL (Time To Live)
|
|
168
181
|
|
|
169
182
|
You can set an expiration time (in seconds) for an entity. The key will automatically be deleted from Redis after the specified time.
|
|
@@ -176,6 +189,8 @@ await this.catRepo.save(id, sessionEntity);
|
|
|
176
189
|
await this.catRepo.expire(id, 60);
|
|
177
190
|
```
|
|
178
191
|
|
|
192
|
+
> **Note**: See entity expiration patterns in the [Wiki: Defining Structures](https://github.com/Alpha018/nestjs-redisom/wiki/Defining-Structures).
|
|
193
|
+
|
|
179
194
|
### 4. TLS Connection (Production / Cloud)
|
|
180
195
|
|
|
181
196
|
For secure connections (e.g., AWS ElastiCache, Redis Cloud), use the `rediss://` protocol and provide TLS options in the `socket` configuration.
|
|
@@ -211,19 +226,43 @@ RedisOmModule.forRootAsync({
|
|
|
211
226
|
})
|
|
212
227
|
```
|
|
213
228
|
|
|
229
|
+
> **Note**: Find more cloud connection examples in the [Wiki: Configuration](https://github.com/Alpha018/nestjs-redisom/wiki/Configuration).
|
|
230
|
+
|
|
231
|
+
### 5. Redis Cluster (Cluster Mode Enabled)
|
|
232
|
+
|
|
233
|
+
`nestjs-redisom` natively supports connecting to a Redis Cluster using the underlying `createCluster` functionality of Node-Redis.
|
|
234
|
+
|
|
235
|
+
Instead of providing a single `url`, you provide an array of `rootNodes`:
|
|
236
|
+
|
|
237
|
+
```typescript
|
|
238
|
+
RedisOmModule.forRoot({
|
|
239
|
+
rootNodes: [
|
|
240
|
+
{ url: 'redis://redis-cluster-node-1:7000' },
|
|
241
|
+
{ url: 'redis://redis-cluster-node-2:7000' }
|
|
242
|
+
],
|
|
243
|
+
defaults: {
|
|
244
|
+
password: 'your-cluster-password'
|
|
245
|
+
}
|
|
246
|
+
})
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
> **Note**: For full details on how the Node-Redis client uses these initial nodes for cluster auto-discovery (`CLUSTER SLOTS`), please refer to the [Configuration Wiki](https://github.com/Alpha018/nestjs-redisom/wiki/Configuration).
|
|
250
|
+
|
|
214
251
|
## Features
|
|
215
252
|
|
|
216
|
-
-
|
|
217
|
-
-
|
|
218
|
-
-
|
|
219
|
-
-
|
|
253
|
+
- **Schema Factory**: Automatically generates RedisOM schemas from your class metadata.
|
|
254
|
+
- **Nested Objects**: Support for typed nested objects with automatic schema flattening.
|
|
255
|
+
- **Async Configuration**: Supports `useFactory`, `useClass`, and `useExisting` for configuration.
|
|
256
|
+
- **Validation**: Compatible with `class-validator` (standard NestJS practice).
|
|
220
257
|
|
|
221
258
|
## Performance & Search Mechanics
|
|
222
259
|
|
|
223
260
|
This library leverages **RediSearch** (module of Redis Stack), meaning searches are **efficient and non-blocking**.
|
|
224
261
|
|
|
225
262
|
### 1. How Search Works
|
|
263
|
+
|
|
226
264
|
When you use `@Prop({ indexed: true })`, Redis OM creates an **Inverted Index**.
|
|
265
|
+
|
|
227
266
|
- **Search**: `repo.search()...` queries this index directly. It does **NOT** perform a linear scan (SCAN command) over the keyspace.
|
|
228
267
|
- **Complexity**: Searches are typically **O(K)** (where K is the number of results) or **O(log N)** for range queries. Retrieving by ID is **O(1)**.
|
|
229
268
|
|
|
@@ -238,6 +277,7 @@ When you use `@Prop({ indexed: true })`, Redis OM creates an **Inverted Index**.
|
|
|
238
277
|
| **Geo** | Radius / Polygon | **O(K + log N)** | Geospacial indexing. |
|
|
239
278
|
|
|
240
279
|
### 2. Resource Usage
|
|
280
|
+
|
|
241
281
|
- **Memory (RAM)**: Indexes consume additional memory. **Best Practice:** Only index fields that you intend to filter by.
|
|
242
282
|
- **CPU**: Search operations are highly optimized. Initial indexing of a large existing dataset may temporarily consume CPU, but incremental updates (`save`) are lightweight.
|
|
243
283
|
|
|
@@ -245,8 +285,8 @@ When you use `@Prop({ indexed: true })`, Redis OM creates an **Inverted Index**.
|
|
|
245
285
|
|
|
246
286
|
Check out a few resources that may come in handy when working with NestJS:
|
|
247
287
|
|
|
248
|
-
-
|
|
249
|
-
-
|
|
288
|
+
- Visit the [NestJS Documentation](https://docs.nestjs.com) to learn more about the framework.
|
|
289
|
+
- Visualize your application graph and interact with the NestJS application in real-time using [NestJS Devtools](https://devtools.nestjs.com).
|
|
250
290
|
|
|
251
291
|
## Support
|
|
252
292
|
|
|
@@ -254,7 +294,7 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors
|
|
|
254
294
|
|
|
255
295
|
## Stay in touch
|
|
256
296
|
|
|
257
|
-
-
|
|
297
|
+
- Author - [Tomás Alegre](https://github.com/Alpha018)
|
|
258
298
|
|
|
259
299
|
## License
|
|
260
300
|
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -21,4 +21,5 @@ __exportStar(require("./redis-om/redis-om-core.module"), exports);
|
|
|
21
21
|
__exportStar(require("./redis-om/common/base.entity"), exports);
|
|
22
22
|
__exportStar(require("./redis-om/redis-om.module"), exports);
|
|
23
23
|
__exportStar(require("./redis-om/interfaces"), exports);
|
|
24
|
+
__exportStar(require("./redis-om/errors"), exports);
|
|
24
25
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oFAAkE;AAClE,yEAAuD;AACvD,uEAAqD;AACrD,kEAAgD;AAChD,gEAA8C;AAC9C,6DAA2C;AAC3C,wDAAsC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oFAAkE;AAClE,yEAAuD;AACvD,uEAAqD;AACrD,kEAAgD;AAChD,gEAA8C;AAC9C,6DAA2C;AAC3C,wDAAsC;AACtC,oDAAkC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { RedisOmIndexCreationFailedException, RedisOmIndexAlreadyExistsException, RedisOmUnsupportedCommandException, RedisOmConnectionFailedException, RedisOmUnexpectedException, } from './redis-om.exceptions';
|
|
2
|
+
export { RedisOmErrorCode } from './redis-om-error.code';
|
|
3
|
+
export { RedisOmException } from './redis-om.exception';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RedisOmException = exports.RedisOmErrorCode = exports.RedisOmUnexpectedException = exports.RedisOmConnectionFailedException = exports.RedisOmUnsupportedCommandException = exports.RedisOmIndexAlreadyExistsException = exports.RedisOmIndexCreationFailedException = void 0;
|
|
4
|
+
var redis_om_exceptions_1 = require("./redis-om.exceptions");
|
|
5
|
+
Object.defineProperty(exports, "RedisOmIndexCreationFailedException", { enumerable: true, get: function () { return redis_om_exceptions_1.RedisOmIndexCreationFailedException; } });
|
|
6
|
+
Object.defineProperty(exports, "RedisOmIndexAlreadyExistsException", { enumerable: true, get: function () { return redis_om_exceptions_1.RedisOmIndexAlreadyExistsException; } });
|
|
7
|
+
Object.defineProperty(exports, "RedisOmUnsupportedCommandException", { enumerable: true, get: function () { return redis_om_exceptions_1.RedisOmUnsupportedCommandException; } });
|
|
8
|
+
Object.defineProperty(exports, "RedisOmConnectionFailedException", { enumerable: true, get: function () { return redis_om_exceptions_1.RedisOmConnectionFailedException; } });
|
|
9
|
+
Object.defineProperty(exports, "RedisOmUnexpectedException", { enumerable: true, get: function () { return redis_om_exceptions_1.RedisOmUnexpectedException; } });
|
|
10
|
+
var redis_om_error_code_1 = require("./redis-om-error.code");
|
|
11
|
+
Object.defineProperty(exports, "RedisOmErrorCode", { enumerable: true, get: function () { return redis_om_error_code_1.RedisOmErrorCode; } });
|
|
12
|
+
var redis_om_exception_1 = require("./redis-om.exception");
|
|
13
|
+
Object.defineProperty(exports, "RedisOmException", { enumerable: true, get: function () { return redis_om_exception_1.RedisOmException; } });
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/redis-om/errors/index.ts"],"names":[],"mappings":";;;AAAA,6DAM+B;AAL7B,0IAAA,mCAAmC,OAAA;AACnC,yIAAA,kCAAkC,OAAA;AAClC,yIAAA,kCAAkC,OAAA;AAClC,uIAAA,gCAAgC,OAAA;AAChC,iIAAA,0BAA0B,OAAA;AAE5B,6DAAyD;AAAhD,uHAAA,gBAAgB,OAAA;AACzB,2DAAwD;AAA/C,sHAAA,gBAAgB,OAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare enum RedisOmErrorCode {
|
|
2
|
+
INDEX_CREATION_FAILED = "REDIS_OM_INDEX_CREATION_FAILED",
|
|
3
|
+
INDEX_ALREADY_EXISTS = "REDIS_OM_INDEX_ALREADY_EXISTS",
|
|
4
|
+
UNSUPPORTED_COMMAND = "REDIS_OM_UNSUPPORTED_COMMAND",
|
|
5
|
+
CONNECTION_FAILED = "REDIS_OM_CONNECTION_FAILED",
|
|
6
|
+
UNEXPECTED_ERROR = "REDIS_OM_UNEXPECTED_ERROR"
|
|
7
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RedisOmErrorCode = void 0;
|
|
4
|
+
var RedisOmErrorCode;
|
|
5
|
+
(function (RedisOmErrorCode) {
|
|
6
|
+
RedisOmErrorCode["INDEX_CREATION_FAILED"] = "REDIS_OM_INDEX_CREATION_FAILED";
|
|
7
|
+
RedisOmErrorCode["INDEX_ALREADY_EXISTS"] = "REDIS_OM_INDEX_ALREADY_EXISTS";
|
|
8
|
+
RedisOmErrorCode["UNSUPPORTED_COMMAND"] = "REDIS_OM_UNSUPPORTED_COMMAND";
|
|
9
|
+
RedisOmErrorCode["CONNECTION_FAILED"] = "REDIS_OM_CONNECTION_FAILED";
|
|
10
|
+
RedisOmErrorCode["UNEXPECTED_ERROR"] = "REDIS_OM_UNEXPECTED_ERROR";
|
|
11
|
+
})(RedisOmErrorCode || (exports.RedisOmErrorCode = RedisOmErrorCode = {}));
|
|
12
|
+
//# sourceMappingURL=redis-om-error.code.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redis-om-error.code.js","sourceRoot":"","sources":["../../../src/redis-om/errors/redis-om-error.code.ts"],"names":[],"mappings":";;;AAKA,IAAY,gBAMX;AAND,WAAY,gBAAgB;IAC1B,4EAAwD,CAAA;IACxD,0EAAsD,CAAA;IACtD,wEAAoD,CAAA;IACpD,oEAAgD,CAAA;IAChD,kEAA8C,CAAA;AAChD,CAAC,EANW,gBAAgB,gCAAhB,gBAAgB,QAM3B"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { RedisOmErrorCode } from './redis-om-error.code';
|
|
2
|
+
export declare abstract class RedisOmException extends Error {
|
|
3
|
+
static readonly code: RedisOmErrorCode;
|
|
4
|
+
static readonly pattern?: RegExp;
|
|
5
|
+
static readonly message: string;
|
|
6
|
+
readonly code: RedisOmErrorCode;
|
|
7
|
+
constructor(cause?: unknown);
|
|
8
|
+
static matches(msg: string): boolean;
|
|
9
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RedisOmException = void 0;
|
|
4
|
+
class RedisOmException extends Error {
|
|
5
|
+
static code;
|
|
6
|
+
static pattern;
|
|
7
|
+
static message;
|
|
8
|
+
code;
|
|
9
|
+
constructor(cause) {
|
|
10
|
+
const { message, code } = new.target;
|
|
11
|
+
super(message, cause !== undefined ? { cause } : undefined);
|
|
12
|
+
this.name = this.constructor.name;
|
|
13
|
+
this.code = code;
|
|
14
|
+
}
|
|
15
|
+
static matches(msg) {
|
|
16
|
+
return this.pattern?.test(msg) ?? false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.RedisOmException = RedisOmException;
|
|
20
|
+
//# sourceMappingURL=redis-om.exception.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redis-om.exception.js","sourceRoot":"","sources":["../../../src/redis-om/errors/redis-om.exception.ts"],"names":[],"mappings":";;;AAmBA,MAAsB,gBAAiB,SAAQ,KAAK;IAClD,MAAM,CAAU,IAAI,CAAmB;IAEvC,MAAM,CAAU,OAAO,CAAU;IACjC,MAAM,CAAU,OAAO,CAAS;IAEvB,IAAI,CAAmB;IAEhC,YAAY,KAAe;QACzB,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC,MAAiC,CAAC;QAChE,KAAK,CAAC,OAAO,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAC5D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAClC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAGD,MAAM,CAAC,OAAO,CAAC,GAAW;QACxB,OAAO,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC;IAC1C,CAAC;CACF;AAnBD,4CAmBC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { RedisOmErrorCode } from './redis-om-error.code';
|
|
2
|
+
import { RedisOmException } from './redis-om.exception';
|
|
3
|
+
export declare class RedisOmUnsupportedCommandException extends RedisOmException {
|
|
4
|
+
static readonly message = "Redis does not support this command \u2014 Redis Stack modules may not be loaded";
|
|
5
|
+
static readonly code = RedisOmErrorCode.UNSUPPORTED_COMMAND;
|
|
6
|
+
static readonly pattern: RegExp;
|
|
7
|
+
}
|
|
8
|
+
export declare class RedisOmIndexAlreadyExistsException extends RedisOmException {
|
|
9
|
+
static readonly message = "Redis OM index already exists and will be reused";
|
|
10
|
+
static readonly code = RedisOmErrorCode.INDEX_ALREADY_EXISTS;
|
|
11
|
+
static readonly pattern: RegExp;
|
|
12
|
+
}
|
|
13
|
+
export declare class RedisOmIndexCreationFailedException extends RedisOmException {
|
|
14
|
+
static readonly code = RedisOmErrorCode.INDEX_CREATION_FAILED;
|
|
15
|
+
static readonly message = "Failed to create Redis OM index";
|
|
16
|
+
}
|
|
17
|
+
export declare class RedisOmUnexpectedException extends RedisOmException {
|
|
18
|
+
static readonly message = "An unexpected Redis OM error occurred";
|
|
19
|
+
static readonly code = RedisOmErrorCode.UNEXPECTED_ERROR;
|
|
20
|
+
}
|
|
21
|
+
export declare class RedisOmConnectionFailedException extends RedisOmException {
|
|
22
|
+
static readonly code = RedisOmErrorCode.CONNECTION_FAILED;
|
|
23
|
+
static readonly message = "Failed to connect to Redis";
|
|
24
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RedisOmConnectionFailedException = exports.RedisOmUnexpectedException = exports.RedisOmIndexCreationFailedException = exports.RedisOmIndexAlreadyExistsException = exports.RedisOmUnsupportedCommandException = void 0;
|
|
4
|
+
const redis_om_error_code_1 = require("./redis-om-error.code");
|
|
5
|
+
const redis_om_exception_1 = require("./redis-om.exception");
|
|
6
|
+
class RedisOmUnsupportedCommandException extends redis_om_exception_1.RedisOmException {
|
|
7
|
+
static message = 'Redis does not support this command — Redis Stack modules may not be loaded';
|
|
8
|
+
static code = redis_om_error_code_1.RedisOmErrorCode.UNSUPPORTED_COMMAND;
|
|
9
|
+
static pattern = /unknown command/i;
|
|
10
|
+
}
|
|
11
|
+
exports.RedisOmUnsupportedCommandException = RedisOmUnsupportedCommandException;
|
|
12
|
+
class RedisOmIndexAlreadyExistsException extends redis_om_exception_1.RedisOmException {
|
|
13
|
+
static message = 'Redis OM index already exists and will be reused';
|
|
14
|
+
static code = redis_om_error_code_1.RedisOmErrorCode.INDEX_ALREADY_EXISTS;
|
|
15
|
+
static pattern = /^Index already exists$/;
|
|
16
|
+
}
|
|
17
|
+
exports.RedisOmIndexAlreadyExistsException = RedisOmIndexAlreadyExistsException;
|
|
18
|
+
class RedisOmIndexCreationFailedException extends redis_om_exception_1.RedisOmException {
|
|
19
|
+
static code = redis_om_error_code_1.RedisOmErrorCode.INDEX_CREATION_FAILED;
|
|
20
|
+
static message = 'Failed to create Redis OM index';
|
|
21
|
+
}
|
|
22
|
+
exports.RedisOmIndexCreationFailedException = RedisOmIndexCreationFailedException;
|
|
23
|
+
class RedisOmUnexpectedException extends redis_om_exception_1.RedisOmException {
|
|
24
|
+
static message = 'An unexpected Redis OM error occurred';
|
|
25
|
+
static code = redis_om_error_code_1.RedisOmErrorCode.UNEXPECTED_ERROR;
|
|
26
|
+
}
|
|
27
|
+
exports.RedisOmUnexpectedException = RedisOmUnexpectedException;
|
|
28
|
+
class RedisOmConnectionFailedException extends redis_om_exception_1.RedisOmException {
|
|
29
|
+
static code = redis_om_error_code_1.RedisOmErrorCode.CONNECTION_FAILED;
|
|
30
|
+
static message = 'Failed to connect to Redis';
|
|
31
|
+
}
|
|
32
|
+
exports.RedisOmConnectionFailedException = RedisOmConnectionFailedException;
|
|
33
|
+
//# sourceMappingURL=redis-om.exceptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redis-om.exceptions.js","sourceRoot":"","sources":["../../../src/redis-om/errors/redis-om.exceptions.ts"],"names":[],"mappings":";;;AAAA,+DAAyD;AACzD,6DAAwD;AAOxD,MAAa,kCAAmC,SAAQ,qCAAgB;IACtE,MAAM,CAAmB,OAAO,GAC9B,6EAA6E,CAAC;IAChF,MAAM,CAAmB,IAAI,GAAG,sCAAgB,CAAC,mBAAmB,CAAC;IACrE,MAAM,CAAmB,OAAO,GAAG,kBAAkB,CAAC;;AAJxD,gFAKC;AAMD,MAAa,kCAAmC,SAAQ,qCAAgB;IACtE,MAAM,CAAmB,OAAO,GAC9B,kDAAkD,CAAC;IACrD,MAAM,CAAmB,IAAI,GAAG,sCAAgB,CAAC,oBAAoB,CAAC;IACtE,MAAM,CAAmB,OAAO,GAAG,wBAAwB,CAAC;;AAJ9D,gFAKC;AAMD,MAAa,mCAAoC,SAAQ,qCAAgB;IACvE,MAAM,CAAmB,IAAI,GAAG,sCAAgB,CAAC,qBAAqB,CAAC;IACvE,MAAM,CAAmB,OAAO,GAAG,iCAAiC,CAAC;;AAFvE,kFAGC;AAKD,MAAa,0BAA2B,SAAQ,qCAAgB;IAC9D,MAAM,CAAmB,OAAO,GAAG,uCAAuC,CAAC;IAC3E,MAAM,CAAmB,IAAI,GAAG,sCAAgB,CAAC,gBAAgB,CAAC;;AAFpE,gEAGC;AAKD,MAAa,gCAAiC,SAAQ,qCAAgB;IACpE,MAAM,CAAmB,IAAI,GAAG,sCAAgB,CAAC,iBAAiB,CAAC;IACnE,MAAM,CAAmB,OAAO,GAAG,4BAA4B,CAAC;;AAFlE,4EAGC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { RedisClusterOptions, RedisClientOptions } from 'redis';
|
|
1
2
|
import { ModuleMetadata, Type } from '@nestjs/common';
|
|
2
|
-
import { RedisClientOptions } from 'redis';
|
|
3
3
|
export interface RedisOmModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
4
4
|
useFactory?: (...args: any[]) => Promise<RedisOmModuleOptions> | RedisOmModuleOptions;
|
|
5
5
|
useExisting?: Type<RedisOmOptionsFactory>;
|
|
@@ -13,4 +13,4 @@ export interface RedisOmModelDefinition {
|
|
|
13
13
|
export interface RedisOmOptionsFactory {
|
|
14
14
|
createRedisOmOptions(): Promise<RedisOmModuleOptions> | RedisOmModuleOptions;
|
|
15
15
|
}
|
|
16
|
-
export type RedisOmModuleOptions = RedisClientOptions;
|
|
16
|
+
export type RedisOmModuleOptions = RedisClusterOptions | RedisClientOptions;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { OnApplicationShutdown, DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { RedisClusterType, RedisClientType } from 'redis';
|
|
2
3
|
import { RedisOmModuleAsyncOptions, RedisOmModuleOptions } from './interfaces';
|
|
3
4
|
export declare class RedisOmCoreModule implements OnApplicationShutdown {
|
|
5
|
+
private readonly redisClient;
|
|
6
|
+
constructor(redisClient: RedisClusterType | RedisClientType);
|
|
4
7
|
static forRootAsync(options: RedisOmModuleAsyncOptions): DynamicModule;
|
|
5
8
|
static forRoot(options: RedisOmModuleOptions): DynamicModule;
|
|
6
9
|
private static createAsyncProviders;
|
|
@@ -5,6 +5,12 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
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
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
8
14
|
var RedisOmCoreModule_1;
|
|
9
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
16
|
exports.RedisOmCoreModule = void 0;
|
|
@@ -13,6 +19,10 @@ const redis_1 = require("redis");
|
|
|
13
19
|
const redis_om_constants_1 = require("./redis-om.constants");
|
|
14
20
|
const redis_om_utils_1 = require("./common/redis-om.utils");
|
|
15
21
|
let RedisOmCoreModule = RedisOmCoreModule_1 = class RedisOmCoreModule {
|
|
22
|
+
redisClient;
|
|
23
|
+
constructor(redisClient) {
|
|
24
|
+
this.redisClient = redisClient;
|
|
25
|
+
}
|
|
16
26
|
static forRootAsync(options) {
|
|
17
27
|
const asyncProviders = this.createAsyncProviders(options);
|
|
18
28
|
return {
|
|
@@ -20,8 +30,9 @@ let RedisOmCoreModule = RedisOmCoreModule_1 = class RedisOmCoreModule {
|
|
|
20
30
|
...asyncProviders,
|
|
21
31
|
{
|
|
22
32
|
useFactory: async (opt) => {
|
|
23
|
-
const
|
|
24
|
-
|
|
33
|
+
const redisClient = opt.rootNodes
|
|
34
|
+
? (0, redis_1.createCluster)(opt)
|
|
35
|
+
: (0, redis_1.createClient)(opt);
|
|
25
36
|
await redisClient.connect();
|
|
26
37
|
return redisClient;
|
|
27
38
|
},
|
|
@@ -37,8 +48,9 @@ let RedisOmCoreModule = RedisOmCoreModule_1 = class RedisOmCoreModule {
|
|
|
37
48
|
static forRoot(options) {
|
|
38
49
|
const redisOmConnectionProvider = {
|
|
39
50
|
useFactory: async () => {
|
|
40
|
-
const
|
|
41
|
-
|
|
51
|
+
const redisClient = options.rootNodes
|
|
52
|
+
? (0, redis_1.createCluster)(options)
|
|
53
|
+
: (0, redis_1.createClient)(options);
|
|
42
54
|
await redisClient.connect();
|
|
43
55
|
return redisClient;
|
|
44
56
|
},
|
|
@@ -62,11 +74,25 @@ let RedisOmCoreModule = RedisOmCoreModule_1 = class RedisOmCoreModule {
|
|
|
62
74
|
}
|
|
63
75
|
return [];
|
|
64
76
|
}
|
|
65
|
-
async onApplicationShutdown() {
|
|
77
|
+
async onApplicationShutdown() {
|
|
78
|
+
try {
|
|
79
|
+
const isOpen = this.redisClient?.isOpen;
|
|
80
|
+
const isReady = 'isReady' in this.redisClient
|
|
81
|
+
? this.redisClient.isReady
|
|
82
|
+
: false;
|
|
83
|
+
if (isOpen || isReady) {
|
|
84
|
+
await this.redisClient.quit();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
}
|
|
89
|
+
}
|
|
66
90
|
};
|
|
67
91
|
exports.RedisOmCoreModule = RedisOmCoreModule;
|
|
68
92
|
exports.RedisOmCoreModule = RedisOmCoreModule = RedisOmCoreModule_1 = __decorate([
|
|
69
93
|
(0, common_1.Module)({}),
|
|
70
|
-
(0, common_1.Global)()
|
|
94
|
+
(0, common_1.Global)(),
|
|
95
|
+
__param(0, (0, common_1.Inject)((0, redis_om_utils_1.getConnectionToken)())),
|
|
96
|
+
__metadata("design:paramtypes", [Object])
|
|
71
97
|
], RedisOmCoreModule);
|
|
72
98
|
//# sourceMappingURL=redis-om-core.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redis-om-core.module.js","sourceRoot":"","sources":["../../src/redis-om/redis-om-core.module.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"redis-om-core.module.js","sourceRoot":"","sources":["../../src/redis-om/redis-om-core.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAOwB;AACxB,iCAKe;AAGf,6DAA+D;AAC/D,4DAA6D;AAUtD,IAAM,iBAAiB,yBAAvB,MAAM,iBAAiB;IAGT;IAFnB,YAEmB,WAA+C;QAA/C,gBAAW,GAAX,WAAW,CAAoC;IAC/D,CAAC;IAWJ,MAAM,CAAC,YAAY,CAAC,OAAkC;QACpD,MAAM,cAAc,GAAG,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AO;gBACL;oBACE,OAAO,EAAE,4CAAuB;oBAChC,UAAU,EAAE,OAAO,CAAC,UAAU;oBAC9B,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,EAAE;iBAC7B;aACF,CAAC;QACJ,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,KAAK,CAAC,qBAAqB;QACzB,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC;YACxC,MAAM,OAAO,GACX,SAAS,IAAI,IAAI,CAAC,WAAW;gBAC3B,CAAC,CAAE,IAAI,CAAC,WAAmB,CAAC,OAAO;gBACnC,CAAC,CAAC,KAAK,CAAC;YACZ,IAAI,MAAM,IAAI,OAAO,EAAE,CAAC;gBACtB,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;YAChC,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;QAET,CAAC;IACH,CAAC;CACF,CAAA;AAhGY,8CAAiB;4BAAjB,iBAAiB;IAF7B,IAAA,eAAM,EAAC,EAAE,CAAC;IACV,IAAA,eAAM,GAAE;IAGJ,WAAA,IAAA,eAAM,EAAC,IAAA,mCAAkB,GAAE,CAAC,CAAA;;GAFpB,iBAAiB,CAgG7B"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { DynamicModule } from '@nestjs/common';
|
|
2
|
-
import { Type } from '@nestjs/common';
|
|
1
|
+
import { DynamicModule, Type } from '@nestjs/common';
|
|
3
2
|
import { RedisOmModuleAsyncOptions, RedisOmModuleOptions } from './interfaces';
|
|
4
3
|
export declare class RedisOmModule {
|
|
5
4
|
static forFeature(models: Type<any>[]): DynamicModule;
|
|
@@ -39,16 +39,34 @@ exports.RedisOmModule = RedisOmModule = RedisOmModule_1 = __decorate([
|
|
|
39
39
|
(0, common_1.Module)({})
|
|
40
40
|
], RedisOmModule);
|
|
41
41
|
const redis_om_1 = require("redis-om");
|
|
42
|
+
const errors_1 = require("./errors");
|
|
43
|
+
const IGNORABLE_INDEX_ERRORS = [
|
|
44
|
+
errors_1.RedisOmIndexAlreadyExistsException,
|
|
45
|
+
errors_1.RedisOmUnsupportedCommandException,
|
|
46
|
+
];
|
|
42
47
|
function createRedisOmProvider(model) {
|
|
43
48
|
return {
|
|
44
49
|
useFactory: async (client) => {
|
|
45
50
|
const schema = schema_factory_1.SchemaFactory.createForClass(model);
|
|
46
51
|
const repository = new redis_om_1.Repository(schema, client);
|
|
47
|
-
|
|
52
|
+
try {
|
|
53
|
+
await repository.createIndex();
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
const known = classifyIndexError(error);
|
|
57
|
+
if (known === null) {
|
|
58
|
+
throw new errors_1.RedisOmIndexCreationFailedException(error);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
48
61
|
return repository;
|
|
49
62
|
},
|
|
50
63
|
provide: (0, redis_om_utils_1.getRepositoryToken)(model),
|
|
51
64
|
inject: [(0, redis_om_utils_1.getConnectionToken)()],
|
|
52
65
|
};
|
|
53
66
|
}
|
|
67
|
+
function classifyIndexError(error) {
|
|
68
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
69
|
+
const Match = IGNORABLE_INDEX_ERRORS.find((E) => E.matches(msg));
|
|
70
|
+
return Match ? new Match(error) : null;
|
|
71
|
+
}
|
|
54
72
|
//# sourceMappingURL=redis-om.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redis-om.module.js","sourceRoot":"","sources":["../../src/redis-om/redis-om.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"redis-om.module.js","sourceRoot":"","sources":["../../src/redis-om/redis-om.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAuE;AAGvE,4DAGiC;AAEjC,iEAA2D;AAC3D,+DAA2D;AAUpD,IAAM,aAAa,qBAAnB,MAAM,aAAa;IAmBxB,MAAM,CAAC,UAAU,CAAC,MAAmB;QACnC,MAAM,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