@nestjs-redisx/testing 1.5.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/LICENSE +21 -0
- package/README.md +76 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1750 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1739 -0
- package/dist/index.mjs.map +1 -0
- package/dist/memory/api/redis-testing.module.d.ts +20 -0
- package/dist/memory/api/redis-testing.module.d.ts.map +1 -0
- package/dist/memory/api/register-memory-driver.d.ts +8 -0
- package/dist/memory/api/register-memory-driver.d.ts.map +1 -0
- package/dist/memory/application/ports/command-executor.port.d.ts +9 -0
- package/dist/memory/application/ports/command-executor.port.d.ts.map +1 -0
- package/dist/memory/application/services/command-executor.service.d.ts +49 -0
- package/dist/memory/application/services/command-executor.service.d.ts.map +1 -0
- package/dist/memory/domain/lua/lua-interpreter.d.ts +46 -0
- package/dist/memory/domain/lua/lua-interpreter.d.ts.map +1 -0
- package/dist/memory/domain/lua/lua-lexer.d.ts +11 -0
- package/dist/memory/domain/lua/lua-lexer.d.ts.map +1 -0
- package/dist/memory/domain/lua/lua-parser.d.ts +67 -0
- package/dist/memory/domain/lua/lua-parser.d.ts.map +1 -0
- package/dist/memory/domain/lua/redis-call.port.d.ts +7 -0
- package/dist/memory/domain/lua/redis-call.port.d.ts.map +1 -0
- package/dist/memory/domain/store/memory-store.d.ts +59 -0
- package/dist/memory/domain/store/memory-store.d.ts.map +1 -0
- package/dist/memory/domain/store/stream-value.d.ts +74 -0
- package/dist/memory/domain/store/stream-value.d.ts.map +1 -0
- package/dist/memory/infrastructure/adapters/memory-redis.adapter.d.ts +22 -0
- package/dist/memory/infrastructure/adapters/memory-redis.adapter.d.ts.map +1 -0
- package/dist/shared/constants/index.d.ts +6 -0
- package/dist/shared/constants/index.d.ts.map +1 -0
- package/dist/shared/errors/index.d.ts +22 -0
- package/dist/shared/errors/index.d.ts.map +1 -0
- package/dist/shared/types/index.d.ts +19 -0
- package/dist/shared/types/index.d.ts.map +1 -0
- package/package.json +76 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 NestJS RedisX Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/nestjs-redisx/nestjs-redisx/main/website/public/images/logo.png" alt="NestJS RedisX" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
# @nestjs-redisx/testing
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@nestjs-redisx/testing)
|
|
8
|
+
[](https://www.npmjs.com/package/@nestjs-redisx/testing)
|
|
9
|
+
[](https://opensource.org/licenses/MIT)
|
|
10
|
+
|
|
11
|
+
Testing utilities for NestJS RedisX: an **in-memory Redis driver** that runs the real cache, locks, rate-limit, and idempotency plugins — including their Lua scripts — with no Redis required. Fast, deterministic, isolated unit tests.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install -D @nestjs-redisx/testing
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick Example
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { Test } from '@nestjs/testing';
|
|
23
|
+
import { RedisTestingModule } from '@nestjs-redisx/testing';
|
|
24
|
+
import { CachePlugin, CACHE_SERVICE, ICacheService } from '@nestjs-redisx/cache';
|
|
25
|
+
|
|
26
|
+
const app = await Test.createTestingModule({
|
|
27
|
+
imports: [RedisTestingModule.forRoot({ plugins: [new CachePlugin()] })],
|
|
28
|
+
}).compile();
|
|
29
|
+
await app.init();
|
|
30
|
+
|
|
31
|
+
const cache = app.get<ICacheService>(CACHE_SERVICE);
|
|
32
|
+
|
|
33
|
+
let calls = 0;
|
|
34
|
+
const loader = async () => (calls++, { id: 1 });
|
|
35
|
+
await cache.getOrSet('user:1', loader, { ttl: 60 });
|
|
36
|
+
await cache.getOrSet('user:1', loader, { ttl: 60 });
|
|
37
|
+
// calls === 1 — real cache code, no Redis
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Prefer to configure `RedisModule` directly? Import the package (to register the
|
|
41
|
+
driver) and set `global.driver`:
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import '@nestjs-redisx/testing';
|
|
45
|
+
import { RedisModule } from '@nestjs-redisx/core';
|
|
46
|
+
|
|
47
|
+
RedisModule.forRoot({
|
|
48
|
+
clients: { type: 'single', host: 'localhost', port: 6379 }, // ignored
|
|
49
|
+
global: { driver: 'memory' },
|
|
50
|
+
plugins: [/* ... */],
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Scope
|
|
55
|
+
|
|
56
|
+
Supports the data structures and scripting used by the cache, locks, rate-limit,
|
|
57
|
+
idempotency, and streams plugins: strings, hashes, sets, sorted sets, lists,
|
|
58
|
+
streams (with consumer groups, PEL, `XACK`/`XCLAIM`/`XPENDING`), keys/TTL, and a
|
|
59
|
+
bounded Lua interpreter. Single-node semantics only — no cluster cross-slot or
|
|
60
|
+
Pub/Sub, and blocking reads return promptly rather than waiting.
|
|
61
|
+
|
|
62
|
+
## Documentation
|
|
63
|
+
|
|
64
|
+
Full documentation: [nestjs-redisx.dev/en/reference/testing/](https://nestjs-redisx.dev/en/reference/testing/)
|
|
65
|
+
|
|
66
|
+
## Using with AI Assistants
|
|
67
|
+
|
|
68
|
+
For better code generation with AI tools (Cursor, Claude Code, GitHub Copilot, etc.), point your agent to the full API reference:
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
https://nestjs-redisx.dev/llms-full.txt
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## License
|
|
75
|
+
|
|
76
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { RedisTestingModule, type RedisTestingModuleOptions, type RedisTestingModuleAsyncOptions } from './memory/api/redis-testing.module';
|
|
2
|
+
export { registerMemoryDriver } from './memory/api/register-memory-driver';
|
|
3
|
+
export { MemoryRedisAdapter } from './memory/infrastructure/adapters/memory-redis.adapter';
|
|
4
|
+
export { MemoryStore } from './memory/domain/store/memory-store';
|
|
5
|
+
export { LuaInterpreter } from './memory/domain/lua/lua-interpreter';
|
|
6
|
+
export { CommandExecutor } from './memory/application/services/command-executor.service';
|
|
7
|
+
export { MEMORY_DRIVER_TYPE } from './shared/constants';
|
|
8
|
+
export { MemoryDriverError, LuaExecutionError, WrongTypeError } from './shared/errors';
|
|
9
|
+
export type { IMemoryDriverOptions } from './shared/types';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,kBAAkB,EAAE,KAAK,yBAAyB,EAAE,KAAK,8BAA8B,EAAE,MAAM,mCAAmC,CAAC;AAC5I,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAG3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,uDAAuD,CAAC;AAG3F,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,wDAAwD,CAAC;AAGzF,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACvF,YAAY,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC"}
|