@viardex/viardex-libs 1.0.12 → 1.0.13

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.
Files changed (40) hide show
  1. package/README.md +12 -235
  2. package/dist/cache/{index.mjs → index.cjs} +48 -12
  3. package/dist/cache/index.cjs.map +1 -0
  4. package/dist/cache/{index.d.mts → index.d.cts} +1 -1
  5. package/dist/cache/index.d.ts +1 -1
  6. package/dist/cache/index.js +11 -47
  7. package/dist/cache/index.js.map +1 -1
  8. package/dist/common/{index.mjs → index.cjs} +159 -54
  9. package/dist/common/index.cjs.map +1 -0
  10. package/dist/common/{index.d.mts → index.d.cts} +0 -1
  11. package/dist/common/index.d.ts +0 -1
  12. package/dist/common/index.js +53 -158
  13. package/dist/common/index.js.map +1 -1
  14. package/dist/{index.mjs → index.cjs} +242 -108
  15. package/dist/index.cjs.map +1 -0
  16. package/dist/{index.d.mts → index.d.cts} +5 -6
  17. package/dist/index.d.ts +0 -1
  18. package/dist/index.js +107 -241
  19. package/dist/index.js.map +1 -1
  20. package/dist/logger/{index.mjs → index.cjs} +52 -26
  21. package/dist/logger/index.cjs.map +1 -0
  22. package/dist/logger/index.js +25 -51
  23. package/dist/logger/index.js.map +1 -1
  24. package/dist/nats/{index.mjs → index.cjs} +63 -18
  25. package/dist/nats/index.cjs.map +1 -0
  26. package/dist/nats/index.js +17 -62
  27. package/dist/nats/index.js.map +1 -1
  28. package/dist/rpc/{index.mjs → index.cjs} +32 -10
  29. package/dist/rpc/{index.mjs.map → index.cjs.map} +1 -1
  30. package/dist/rpc/index.js +9 -31
  31. package/dist/rpc/index.js.map +1 -1
  32. package/package.json +14 -13
  33. package/dist/cache/index.mjs.map +0 -1
  34. package/dist/common/index.mjs.map +0 -1
  35. package/dist/index.mjs.map +0 -1
  36. package/dist/logger/index.mjs.map +0 -1
  37. package/dist/nats/index.mjs.map +0 -1
  38. /package/dist/logger/{index.d.mts → index.d.cts} +0 -0
  39. /package/dist/nats/{index.d.mts → index.d.cts} +0 -0
  40. /package/dist/rpc/{index.d.mts → index.d.cts} +0 -0
package/README.md CHANGED
@@ -1,249 +1,26 @@
1
1
  # Viardex Libs
2
2
 
3
- Shared NestJS infrastructure for Viardex services.
3
+ Shared TypeScript infrastructure library (`@viardex/viardex-libs`) for Viardex services.
4
4
 
5
- ## Argon
5
+ ## Modules
6
6
 
7
- `@viardex/viardex-libs` provides a shared Argon2id hashing module for passwords, passcodes, and transaction PINs.
7
+ - **`nats`**: JetStream client provider, connection factory, and message subject constants.
8
+ - **`cache`**: Redis connection abstractions and distributed caching utilities.
9
+ - **`common`**: Shared DTOs, custom decorators, validation schemas, and utility functions.
10
+ - **`rpc`**: Microservice RPC contracts and client patterns.
11
+ - **`logger`**: Structured JSON logging module wrapping `pino` with request correlation.
8
12
 
9
- ```ts
10
- import { ArgonModule, ArgonService } from '@viardex/viardex-libs';
11
-
12
- @Module({
13
- imports: [ArgonModule],
14
- })
15
- export class AppModule {}
16
- ```
13
+ ## Usage
17
14
 
18
- Example:
19
-
20
- ```ts
21
- constructor(private readonly argonService: ArgonService) {}
22
-
23
- const hash = await this.argonService.hash(password);
24
- const isValid = await this.argonService.verify(hash, password);
25
- const shouldRotate = await this.argonService.needsRehash(hash);
15
+ ```bash
16
+ npm install @viardex/viardex-libs
26
17
  ```
27
18
 
28
- `ArgonService.verify()` safely returns `false` for malformed hashes instead of leaking low-level argon exceptions into auth flows.
29
-
30
- ## Auth
31
-
32
- `@viardex/viardex-libs` provides the shared JWT verifier module.
33
-
34
19
  ```ts
35
- import { AuthModule } from '@viardex/viardex-libs';
20
+ import { NatsModule, NotificationSubjects } from '@viardex/viardex-libs';
36
21
 
37
22
  @Module({
38
- imports: [AuthModule],
23
+ imports: [NatsModule],
39
24
  })
40
25
  export class AppModule {}
41
26
  ```
42
-
43
- ### Decorators
44
-
45
- Use the shared barrel:
46
-
47
- ```ts
48
- import {
49
- AuthModule,
50
- CurrentAuth,
51
- Permissions,
52
- Public,
53
- Roles,
54
- } from '@viardex/viardex-libs';
55
- ```
56
-
57
- - `@Public()` marks a route as bypassing the global JWT guard.
58
- - `@Roles(...roles)` declares allowed staff roles for a route.
59
- - `@Permissions(...permissions)` declares required permissions for a route.
60
- - `@CurrentAuth()` returns the verified JWT principal from the request.
61
-
62
- ### Guards
63
-
64
- Guard classes live under `src/auth/guards` and are exported through the shared barrel:
65
-
66
- ```ts
67
- import { PermissionsGuard, RolesGuard } from '@viardex/viardex-libs';
68
- ```
69
-
70
- Example:
71
-
72
- ```ts
73
- @UseGuards(RolesGuard, PermissionsGuard)
74
- @Roles('admin', 'support')
75
- @Permissions('tickets.read', 'tickets.resolve')
76
- @Get('tickets')
77
- listTickets() {}
78
- ```
79
-
80
- ### JWT Config
81
-
82
- Services should expose:
83
-
84
- ```env
85
- JWT_ALGORITHM=RS256
86
- JWT_ISSUER=viardex-user-service
87
- JWT_AUDIENCE=viardex-api
88
- JWT_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----\n...\n-----END PUBLIC KEY-----"
89
- ```
90
-
91
- The shared auth module verifies JWTs globally. Role and permission guards are opt-in at the route or controller level.
92
-
93
- ## Logger
94
-
95
- `LoggerModule` is global and wraps `nestjs-pino`.
96
-
97
- - development uses `pino-pretty`
98
- - non-HTTP contexts are ignored by `LoggingInterceptor`
99
- - request logging keeps request id, method, URL, status code, and duration
100
-
101
- ## Health
102
-
103
- `HealthModule` exposes:
104
-
105
- - `GET /health` for lightweight liveness
106
- - `GET /health/ready` for readiness checks
107
-
108
- Readiness currently checks storage, memory, and NATS connectivity.
109
-
110
- ## Cache
111
-
112
- `CacheModule.register()` exposes a Redis-backed `CacheService`.
113
-
114
- Preferred APIs:
115
-
116
- - `set()` / `get()`
117
- - `setJson()` / `getJson()`
118
- - `setIfNotExists()` for idempotency / locks
119
- - `scan()` instead of `keys()` for production-safe pattern reads
120
- - `ping()` for lightweight health checks
121
-
122
- ## Common
123
-
124
- `@viardex/viardex-libs` also exposes shared DTOs, pipes, response helpers, and safe formatting utilities through the root barrel.
125
-
126
- ### Response Shape
127
-
128
- Use the shared response helpers to keep HTTP payloads consistent across Nest services.
129
-
130
- ```ts
131
- import { AppResponse } from '@viardex/viardex-libs';
132
-
133
- return AppResponse.success('User fetched successfully', user);
134
- ```
135
-
136
- For paginated endpoints:
137
-
138
- ```ts
139
- return AppResponse.paginated('Users fetched successfully', items, {
140
- page,
141
- limit,
142
- totalItems,
143
- totalPages,
144
- });
145
- ```
146
-
147
- Shared response exports include:
148
-
149
- - `ApiResponse`
150
- - `PaginationMeta`
151
- - `ResponseMeta`
152
- - `ErrorDetail`
153
- - `AppResponse`
154
- - `ResponseInterceptor`
155
- - `HttpExceptionFilter`
156
-
157
- ### DTOs And Pipes
158
-
159
- Shared request helpers include:
160
-
161
- - `PaginationQueryDto`
162
- - `PaginationQueryCleanerPipe`
163
- - `FileValidationPipe`
164
-
165
- ### Cards
166
-
167
- Shared card-safe helpers are available for masking and display use cases:
168
-
169
- - `maskPan`
170
- - `extractLast4`
171
- - `extractBin`
172
- - `formatCardExpiry`
173
- - `normalizeCardExpiry`
174
- - `formatCardLabel`
175
-
176
- These are for safe formatting and display only. Sensitive authentication data like CVV must never be stored or handled through shared helpers.
177
-
178
- ### Crypto
179
-
180
- Shared crypto helpers are intentionally limited to generic amount and formatting concerns:
181
-
182
- - `toAtomicUnits`
183
- - `fromAtomicUnits`
184
- - `formatCryptoAmount`
185
- - `normalizeTxHash`
186
- - `isHexTxHash`
187
- - `isPositiveAmount`
188
-
189
- They are useful for asset formatting and validation, but custody, compliance, signing, and chain-specific business logic should stay inside the owning service.
190
-
191
- ## Nest And Go Mapping
192
-
193
- The Go shared package in `viardex-go` follows the same auth concepts, but uses middleware and request context instead of Nest metadata and guards.
194
-
195
- | Nest (`viardex-libs`) | Go (`viardex-go`) |
196
- | --------------------- | ----------------------------------------------------------- |
197
- | `AuthModule` | `auth` package setup in service bootstrap |
198
- | `AuthService` | `auth.NewService(...)` / `auth.Service` |
199
- | `AuthPrincipal` | `auth.Principal` |
200
- | `AuthTokenType` | `auth.TokenType` |
201
- | `AuthGuard` | `middlewares.Auth(...)` |
202
- | `RolesGuard` | `middlewares.RequireRoles(...)` |
203
- | `PermissionsGuard` | `middlewares.RequirePermissions(...)` |
204
- | `AuthTokenTypes(...)` | `middlewares.RequireTokenTypes(...)` |
205
- | `Public()` | keep route/group outside auth middleware |
206
- | `Roles(...)` | wrap route/group with `middlewares.RequireRoles(...)` |
207
- | `Permissions(...)` | wrap route/group with `middlewares.RequirePermissions(...)` |
208
- | `CurrentAuth()` | `auth.PrincipalFromContext(r.Context())` |
209
-
210
- ### Example Comparison
211
-
212
- Nest:
213
-
214
- ```ts
215
- @UseGuards(PermissionsGuard)
216
- @Permissions('ledger.read')
217
- @Get('/ledger')
218
- ```
219
-
220
- Go:
221
-
222
- ```go
223
- r.With(middlewares.RequirePermissions("ledger.read")).Get("/ledger", handler)
224
- ```
225
-
226
- Nest:
227
-
228
- ```ts
229
- @Public()
230
- @Get('/health')
231
- ```
232
-
233
- Go:
234
-
235
- ```go
236
- r.Get("/health", handler)
237
- ```
238
-
239
- Nest:
240
-
241
- ```ts
242
- const principal = request.user;
243
- ```
244
-
245
- Go:
246
-
247
- ```go
248
- principal, ok := auth.PrincipalFromContext(r.Context())
249
- ```
@@ -1,16 +1,51 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
2
7
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/cache/index.ts
31
+ var cache_exports = {};
32
+ __export(cache_exports, {
33
+ CACHE_MODULE_OPTIONS: () => CACHE_MODULE_OPTIONS,
34
+ CacheModule: () => CacheModule,
35
+ CacheService: () => CacheService
36
+ });
37
+ module.exports = __toCommonJS(cache_exports);
3
38
 
4
39
  // src/cache/cache.constants.ts
5
40
  var CACHE_MODULE_OPTIONS = /* @__PURE__ */ Symbol("CACHE_MODULE_OPTIONS");
6
41
 
7
42
  // src/cache/cache.module.ts
8
- import { Module } from "@nestjs/common";
9
- import { ConfigModule } from "@nestjs/config";
43
+ var import_common2 = require("@nestjs/common");
44
+ var import_config = require("@nestjs/config");
10
45
 
11
46
  // src/cache/cache.service.ts
12
- import { Inject, Injectable } from "@nestjs/common";
13
- import Redis from "ioredis";
47
+ var import_common = require("@nestjs/common");
48
+ var import_ioredis = __toESM(require("ioredis"), 1);
14
49
  function _ts_decorate(decorators, target, key, desc) {
15
50
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
16
51
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
@@ -48,7 +83,7 @@ var CacheService = class {
48
83
  }
49
84
  async onModuleInit() {
50
85
  const options = this.options || {};
51
- this.redisClient = new Redis({
86
+ this.redisClient = new import_ioredis.default({
52
87
  ...options,
53
88
  host: options.host || process.env.REDIS_HOST || "localhost",
54
89
  port: options.port || +(process.env?.REDIS_PORT || 6379),
@@ -136,8 +171,8 @@ var CacheService = class {
136
171
  }
137
172
  };
138
173
  CacheService = _ts_decorate([
139
- Injectable(),
140
- _ts_param(0, Inject(CACHE_MODULE_OPTIONS)),
174
+ (0, import_common.Injectable)(),
175
+ _ts_param(0, (0, import_common.Inject)(CACHE_MODULE_OPTIONS)),
141
176
  _ts_metadata("design:type", Function),
142
177
  _ts_metadata("design:paramtypes", [
143
178
  typeof CacheOptions === "undefined" ? Object : CacheOptions
@@ -167,7 +202,7 @@ var CacheModule = class _CacheModule {
167
202
  return {
168
203
  module: _CacheModule,
169
204
  imports: [
170
- ConfigModule
205
+ import_config.ConfigModule
171
206
  ],
172
207
  providers: [
173
208
  CacheService,
@@ -183,11 +218,12 @@ var CacheModule = class _CacheModule {
183
218
  }
184
219
  };
185
220
  CacheModule = _ts_decorate2([
186
- Module({})
221
+ (0, import_common2.Module)({})
187
222
  ], CacheModule);
188
- export {
223
+ // Annotate the CommonJS export names for ESM import in node:
224
+ 0 && (module.exports = {
189
225
  CACHE_MODULE_OPTIONS,
190
226
  CacheModule,
191
227
  CacheService
192
- };
193
- //# sourceMappingURL=index.mjs.map
228
+ });
229
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/cache/index.ts","../../src/cache/cache.constants.ts","../../src/cache/cache.module.ts","../../src/cache/cache.service.ts"],"sourcesContent":["export * from './cache.constants';\nexport * from './cache.module';\nexport * from './cache.service';\n","export const CACHE_MODULE_OPTIONS = Symbol('CACHE_MODULE_OPTIONS');\n","import { DynamicModule, Module } from '@nestjs/common';\nimport { ConfigModule } from '@nestjs/config';\nimport { CacheService } from './cache.service';\nimport { CacheOptions } from './cache.interface';\nimport { CACHE_MODULE_OPTIONS } from './cache.constants';\n\n@Module({})\nexport class CacheModule {\n static register(options: CacheOptions = {}): DynamicModule {\n return {\n module: CacheModule,\n imports: [ConfigModule],\n providers: [\n CacheService,\n { provide: CACHE_MODULE_OPTIONS, useValue: options },\n ],\n exports: [CacheService],\n };\n }\n}\n","import {\n Inject,\n Injectable,\n OnModuleDestroy,\n OnModuleInit,\n} from '@nestjs/common';\nimport Redis from 'ioredis';\nimport type { CacheOptions } from './cache.interface';\nimport { CACHE_MODULE_OPTIONS } from './cache.constants';\n\n@Injectable()\nexport class CacheService implements OnModuleInit, OnModuleDestroy {\n private redisClient!: Redis;\n\n constructor(\n @Inject(CACHE_MODULE_OPTIONS) private readonly options: CacheOptions\n ) {}\n\n async onModuleInit() {\n const options = this.options || {};\n\n this.redisClient = new Redis({\n ...options,\n host: options.host || process.env.REDIS_HOST || 'localhost',\n port: options.port || +(process.env?.REDIS_PORT || 6379),\n username: options.username || process.env?.REDIS_USERNAME,\n password: options.password || process.env?.REDIS_PASSWORD,\n keyPrefix: options.keyPrefix || 'viardex:',\n });\n }\n\n async onModuleDestroy() {\n await this.redisClient.quit();\n }\n\n getClient(): Redis {\n return this.redisClient;\n }\n\n async ping(): Promise<string> {\n return this.redisClient.ping();\n }\n\n async set(key: string, value: string, ttlSeconds?: number): Promise<void> {\n if (ttlSeconds) {\n await this.redisClient.setex(key, ttlSeconds, value);\n } else {\n await this.redisClient.set(key, value);\n }\n }\n\n async setIfNotExists(\n key: string,\n value: string,\n ttlSeconds?: number\n ): Promise<boolean> {\n const result = ttlSeconds\n ? await this.redisClient.set(key, value, 'EX', ttlSeconds, 'NX')\n : await this.redisClient.set(key, value, 'NX');\n\n return result === 'OK';\n }\n\n async get(key: string): Promise<string | null> {\n return this.redisClient.get(key);\n }\n\n async setJson<T>(key: string, value: T, ttlSeconds?: number): Promise<void> {\n await this.set(key, JSON.stringify(value), ttlSeconds);\n }\n\n async getJson<T>(key: string): Promise<T | null> {\n const value = await this.get(key);\n return value ? (JSON.parse(value) as T) : null;\n }\n\n async del(key: string): Promise<void> {\n await this.redisClient.del(key);\n }\n\n async exists(key: string): Promise<boolean> {\n const result = await this.redisClient.exists(key);\n return result === 1;\n }\n\n async ttl(key: string): Promise<number> {\n return this.redisClient.ttl(key);\n }\n\n async keys(pattern: string): Promise<string[]> {\n return this.redisClient.keys(pattern);\n }\n\n async scan(pattern: string, count = 100): Promise<string[]> {\n const keys: string[] = [];\n let cursor = '0';\n\n do {\n const [nextCursor, batch] = await this.redisClient.scan(\n cursor,\n 'MATCH',\n pattern,\n 'COUNT',\n count\n );\n cursor = nextCursor;\n keys.push(...batch);\n } while (cursor !== '0');\n\n return keys;\n }\n\n async flushAll(): Promise<void> {\n await this.redisClient.flushall();\n }\n\n async incr(key: string): Promise<number> {\n return this.redisClient.incr(key);\n }\n\n async decr(key: string): Promise<number> {\n return this.redisClient.decr(key);\n }\n\n async hset(key: string, field: string, value: string): Promise<void> {\n await this.redisClient.hset(key, field, value);\n }\n\n async hget(key: string, field: string): Promise<string | null> {\n return this.redisClient.hget(key, field);\n }\n\n async hgetall(key: string): Promise<Record<string, string>> {\n return this.redisClient.hgetall(key);\n }\n\n async hdel(key: string, field: string): Promise<void> {\n await this.redisClient.hdel(key, field);\n }\n\n async expire(key: string, ttlSeconds: number): Promise<void> {\n await this.redisClient.expire(key, ttlSeconds);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;ACAO,IAAMA,uBAAuBC,uBAAO,sBAAA;;;ACA3C,IAAAC,iBAAsC;AACtC,oBAA6B;;;ACD7B,oBAKO;AACP,qBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKX,IAAMC,eAAN,MAAMA;SAAAA;;;;EACHC;EAER,YACiDC,SAC/C;SAD+CA,UAAAA;EAC9C;EAEH,MAAMC,eAAe;AACnB,UAAMD,UAAU,KAAKA,WAAW,CAAC;AAEjC,SAAKD,cAAc,IAAIG,eAAAA,QAAM;MAC3B,GAAGF;MACHG,MAAMH,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rC;AACF;;;;;;;;;;;;;;;;;;;;;;;;;ADxIO,IAAM+B,cAAN,MAAMA,aAAAA;SAAAA;;;EACX,OAAOC,SAASC,UAAwB,CAAC,GAAkB;AACzD,WAAO;MACLC,QAAQH;MACRI,SAAS;QAACC;;MACVC,WAAW;QACTC;QACA;UAAEC,SAASC;UAAsBC,UAAUR;QAAQ;;MAErDS,SAAS;QAACJ;;IACZ;EACF;AACF;;;;","names":["CACHE_MODULE_OPTIONS","Symbol","import_common","CacheService","redisClient","options","onModuleInit","Redis","host","process","env","REDIS_HOST","port","REDIS_PORT","username","REDIS_USERNAME","password","REDIS_PASSWORD","keyPrefix","onModuleDestroy","quit","getClient","ping","set","key","value","ttlSeconds","setex","setIfNotExists","result","get","setJson","JSON","stringify","getJson","parse","del","exists","ttl","keys","pattern","scan","count","cursor","nextCursor","batch","push","flushAll","flushall","incr","decr","hset","field","hget","hgetall","hdel","expire","CacheModule","register","options","module","imports","ConfigModule","providers","CacheService","provide","CACHE_MODULE_OPTIONS","useValue","exports"]}
@@ -1,5 +1,5 @@
1
1
  import { DynamicModule, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
2
- import Redis, { RedisOptions } from 'ioredis';
2
+ import { RedisOptions } from 'ioredis';
3
3
 
4
4
  declare const CACHE_MODULE_OPTIONS: unique symbol;
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { DynamicModule, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
2
- import Redis, { RedisOptions } from 'ioredis';
2
+ import { RedisOptions } from 'ioredis';
3
3
 
4
4
  declare const CACHE_MODULE_OPTIONS: unique symbol;
5
5
 
@@ -1,51 +1,16 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/cache/index.ts
31
- var cache_exports = {};
32
- __export(cache_exports, {
33
- CACHE_MODULE_OPTIONS: () => CACHE_MODULE_OPTIONS,
34
- CacheModule: () => CacheModule,
35
- CacheService: () => CacheService
36
- });
37
- module.exports = __toCommonJS(cache_exports);
38
3
 
39
4
  // src/cache/cache.constants.ts
40
5
  var CACHE_MODULE_OPTIONS = /* @__PURE__ */ Symbol("CACHE_MODULE_OPTIONS");
41
6
 
42
7
  // src/cache/cache.module.ts
43
- var import_common2 = require("@nestjs/common");
44
- var import_config = require("@nestjs/config");
8
+ import { Module } from "@nestjs/common";
9
+ import { ConfigModule } from "@nestjs/config";
45
10
 
46
11
  // src/cache/cache.service.ts
47
- var import_common = require("@nestjs/common");
48
- var import_ioredis = __toESM(require("ioredis"));
12
+ import { Inject, Injectable } from "@nestjs/common";
13
+ import Redis from "ioredis";
49
14
  function _ts_decorate(decorators, target, key, desc) {
50
15
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
51
16
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
@@ -83,7 +48,7 @@ var CacheService = class {
83
48
  }
84
49
  async onModuleInit() {
85
50
  const options = this.options || {};
86
- this.redisClient = new import_ioredis.default({
51
+ this.redisClient = new Redis({
87
52
  ...options,
88
53
  host: options.host || process.env.REDIS_HOST || "localhost",
89
54
  port: options.port || +(process.env?.REDIS_PORT || 6379),
@@ -171,8 +136,8 @@ var CacheService = class {
171
136
  }
172
137
  };
173
138
  CacheService = _ts_decorate([
174
- (0, import_common.Injectable)(),
175
- _ts_param(0, (0, import_common.Inject)(CACHE_MODULE_OPTIONS)),
139
+ Injectable(),
140
+ _ts_param(0, Inject(CACHE_MODULE_OPTIONS)),
176
141
  _ts_metadata("design:type", Function),
177
142
  _ts_metadata("design:paramtypes", [
178
143
  typeof CacheOptions === "undefined" ? Object : CacheOptions
@@ -202,7 +167,7 @@ var CacheModule = class _CacheModule {
202
167
  return {
203
168
  module: _CacheModule,
204
169
  imports: [
205
- import_config.ConfigModule
170
+ ConfigModule
206
171
  ],
207
172
  providers: [
208
173
  CacheService,
@@ -218,12 +183,11 @@ var CacheModule = class _CacheModule {
218
183
  }
219
184
  };
220
185
  CacheModule = _ts_decorate2([
221
- (0, import_common2.Module)({})
186
+ Module({})
222
187
  ], CacheModule);
223
- // Annotate the CommonJS export names for ESM import in node:
224
- 0 && (module.exports = {
188
+ export {
225
189
  CACHE_MODULE_OPTIONS,
226
190
  CacheModule,
227
191
  CacheService
228
- });
192
+ };
229
193
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/cache/index.ts","../../src/cache/cache.constants.ts","../../src/cache/cache.module.ts","../../src/cache/cache.service.ts"],"sourcesContent":["export * from './cache.constants';\nexport * from './cache.module';\nexport * from './cache.service';\n","export const CACHE_MODULE_OPTIONS = Symbol('CACHE_MODULE_OPTIONS');\n","import { DynamicModule, Module } from '@nestjs/common';\nimport { ConfigModule } from '@nestjs/config';\nimport { CacheService } from './cache.service';\nimport { CacheOptions } from './cache.interface';\nimport { CACHE_MODULE_OPTIONS } from './cache.constants';\n\n@Module({})\nexport class CacheModule {\n static register(options: CacheOptions = {}): DynamicModule {\n return {\n module: CacheModule,\n imports: [ConfigModule],\n providers: [\n CacheService,\n { provide: CACHE_MODULE_OPTIONS, useValue: options },\n ],\n exports: [CacheService],\n };\n }\n}\n","import {\n Inject,\n Injectable,\n OnModuleDestroy,\n OnModuleInit,\n} from '@nestjs/common';\nimport Redis from 'ioredis';\nimport type { CacheOptions } from './cache.interface';\nimport { CACHE_MODULE_OPTIONS } from './cache.constants';\n\n@Injectable()\nexport class CacheService implements OnModuleInit, OnModuleDestroy {\n private redisClient!: Redis;\n\n constructor(\n @Inject(CACHE_MODULE_OPTIONS) private readonly options: CacheOptions\n ) {}\n\n async onModuleInit() {\n const options = this.options || {};\n\n this.redisClient = new Redis({\n ...options,\n host: options.host || process.env.REDIS_HOST || 'localhost',\n port: options.port || +(process.env?.REDIS_PORT || 6379),\n username: options.username || process.env?.REDIS_USERNAME,\n password: options.password || process.env?.REDIS_PASSWORD,\n keyPrefix: options.keyPrefix || 'viardex:',\n });\n }\n\n async onModuleDestroy() {\n await this.redisClient.quit();\n }\n\n getClient(): Redis {\n return this.redisClient;\n }\n\n async ping(): Promise<string> {\n return this.redisClient.ping();\n }\n\n async set(key: string, value: string, ttlSeconds?: number): Promise<void> {\n if (ttlSeconds) {\n await this.redisClient.setex(key, ttlSeconds, value);\n } else {\n await this.redisClient.set(key, value);\n }\n }\n\n async setIfNotExists(\n key: string,\n value: string,\n ttlSeconds?: number\n ): Promise<boolean> {\n const result = ttlSeconds\n ? await this.redisClient.set(key, value, 'EX', ttlSeconds, 'NX')\n : await this.redisClient.set(key, value, 'NX');\n\n return result === 'OK';\n }\n\n async get(key: string): Promise<string | null> {\n return this.redisClient.get(key);\n }\n\n async setJson<T>(key: string, value: T, ttlSeconds?: number): Promise<void> {\n await this.set(key, JSON.stringify(value), ttlSeconds);\n }\n\n async getJson<T>(key: string): Promise<T | null> {\n const value = await this.get(key);\n return value ? (JSON.parse(value) as T) : null;\n }\n\n async del(key: string): Promise<void> {\n await this.redisClient.del(key);\n }\n\n async exists(key: string): Promise<boolean> {\n const result = await this.redisClient.exists(key);\n return result === 1;\n }\n\n async ttl(key: string): Promise<number> {\n return this.redisClient.ttl(key);\n }\n\n async keys(pattern: string): Promise<string[]> {\n return this.redisClient.keys(pattern);\n }\n\n async scan(pattern: string, count = 100): Promise<string[]> {\n const keys: string[] = [];\n let cursor = '0';\n\n do {\n const [nextCursor, batch] = await this.redisClient.scan(\n cursor,\n 'MATCH',\n pattern,\n 'COUNT',\n count\n );\n cursor = nextCursor;\n keys.push(...batch);\n } while (cursor !== '0');\n\n return keys;\n }\n\n async flushAll(): Promise<void> {\n await this.redisClient.flushall();\n }\n\n async incr(key: string): Promise<number> {\n return this.redisClient.incr(key);\n }\n\n async decr(key: string): Promise<number> {\n return this.redisClient.decr(key);\n }\n\n async hset(key: string, field: string, value: string): Promise<void> {\n await this.redisClient.hset(key, field, value);\n }\n\n async hget(key: string, field: string): Promise<string | null> {\n return this.redisClient.hget(key, field);\n }\n\n async hgetall(key: string): Promise<Record<string, string>> {\n return this.redisClient.hgetall(key);\n }\n\n async hdel(key: string, field: string): Promise<void> {\n await this.redisClient.hdel(key, field);\n }\n\n async expire(key: string, ttlSeconds: number): Promise<void> {\n await this.redisClient.expire(key, ttlSeconds);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;ACAO,IAAMA,uBAAuBC,uBAAO,sBAAA;;;ACA3C,IAAAC,iBAAsC;AACtC,oBAA6B;;;ACD7B,oBAKO;AACP,qBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKX,IAAMC,eAAN,MAAMA;SAAAA;;;;EACHC;EAER,YACiDC,SAC/C;SAD+CA,UAAAA;EAC9C;EAEH,MA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K/B,KAAK4B,KAAAA;EACnC;EAEA,MAAMI,OAAOhC,KAAaE,YAAmC;AAC3D,UAAM,KAAKtB,YAAYoD,OAAOhC,KAAKE,UAAAA;EACrC;AACF;;;;;;;;;;;;;;;;;;;;;;;;;ADxIO,IAAM+B,cAAN,MAAMA,aAAAA;SAAAA;;;EACX,OAAOC,SAASC,UAAwB,CAAC,GAAkB;AACzD,WAAO;MACLC,QAAQH;MACRI,SAAS;QAACC;;MACVC,WAAW;QACTC;QACA;UAAEC,SAASC;UAAsBC,UAAUR;QAAQ;;MAErDS,SAAS;QAACJ;;IACZ;EACF;AACF;;;;","names":["CACHE_MODULE_OPTIONS","Symbol","import_common","CacheService","redisClient","options","onModuleInit","Redis","host","process","env","REDIS_HOST","port","REDIS_PORT","username","REDIS_USERNAME","password","REDIS_PASSWORD","keyPrefix","onModuleDestroy","quit","getClient","ping","set","key","value","ttlSeconds","setex","setIfNotExists","result","get","setJson","JSON","stringify","getJson","parse","del","exists","ttl","keys","pattern","scan","count","cursor","nextCursor","batch","push","flushAll","flushall","incr","decr","hset","field","hget","hgetall","hdel","expire","CacheModule","register","options","module","imports","ConfigModule","providers","CacheService","provide","CACHE_MODULE_OPTIONS","useValue","exports"]}
1
+ {"version":3,"sources":["../../src/cache/cache.constants.ts","../../src/cache/cache.module.ts","../../src/cache/cache.service.ts"],"sourcesContent":["export const CACHE_MODULE_OPTIONS = Symbol('CACHE_MODULE_OPTIONS');\n","import { DynamicModule, Module } from '@nestjs/common';\nimport { ConfigModule } from '@nestjs/config';\nimport { CacheService } from './cache.service';\nimport { CacheOptions } from './cache.interface';\nimport { CACHE_MODULE_OPTIONS } from './cache.constants';\n\n@Module({})\nexport class CacheModule {\n static register(options: CacheOptions = {}): DynamicModule {\n return {\n module: CacheModule,\n imports: [ConfigModule],\n providers: [\n CacheService,\n { provide: CACHE_MODULE_OPTIONS, useValue: options },\n ],\n exports: [CacheService],\n };\n }\n}\n","import {\n Inject,\n Injectable,\n OnModuleDestroy,\n OnModuleInit,\n} from '@nestjs/common';\nimport Redis from 'ioredis';\nimport type { CacheOptions } from './cache.interface';\nimport { CACHE_MODULE_OPTIONS } from './cache.constants';\n\n@Injectable()\nexport class CacheService implements OnModuleInit, OnModuleDestroy {\n private redisClient!: Redis;\n\n constructor(\n @Inject(CACHE_MODULE_OPTIONS) private readonly options: CacheOptions\n ) {}\n\n async onModuleInit() {\n const options = this.options || {};\n\n this.redisClient = new Redis({\n ...options,\n host: options.host || process.env.REDIS_HOST || 'localhost',\n port: options.port || +(process.env?.REDIS_PORT || 6379),\n username: options.username || process.env?.REDIS_USERNAME,\n password: options.password || process.env?.REDIS_PASSWORD,\n keyPrefix: options.keyPrefix || 'viardex:',\n });\n }\n\n async onModuleDestroy() {\n await this.redisClient.quit();\n }\n\n getClient(): Redis {\n return this.redisClient;\n }\n\n async ping(): Promise<string> {\n return this.redisClient.ping();\n }\n\n async set(key: string, value: string, ttlSeconds?: number): Promise<void> {\n if (ttlSeconds) {\n await this.redisClient.setex(key, ttlSeconds, value);\n } else {\n await this.redisClient.set(key, value);\n }\n }\n\n async setIfNotExists(\n key: string,\n value: string,\n ttlSeconds?: number\n ): Promise<boolean> {\n const result = ttlSeconds\n ? await this.redisClient.set(key, value, 'EX', ttlSeconds, 'NX')\n : await this.redisClient.set(key, value, 'NX');\n\n return result === 'OK';\n }\n\n async get(key: string): Promise<string | null> {\n return this.redisClient.get(key);\n }\n\n async setJson<T>(key: string, value: T, ttlSeconds?: number): Promise<void> {\n await this.set(key, JSON.stringify(value), ttlSeconds);\n }\n\n async getJson<T>(key: string): Promise<T | null> {\n const value = await this.get(key);\n return value ? (JSON.parse(value) as T) : null;\n }\n\n async del(key: string): Promise<void> {\n await this.redisClient.del(key);\n }\n\n async exists(key: string): Promise<boolean> {\n const result = await this.redisClient.exists(key);\n return result === 1;\n }\n\n async ttl(key: string): Promise<number> {\n return this.redisClient.ttl(key);\n }\n\n async keys(pattern: string): Promise<string[]> {\n return this.redisClient.keys(pattern);\n }\n\n async scan(pattern: string, count = 100): Promise<string[]> {\n const keys: string[] = [];\n let cursor = '0';\n\n do {\n const [nextCursor, batch] = await this.redisClient.scan(\n cursor,\n 'MATCH',\n pattern,\n 'COUNT',\n count\n );\n cursor = nextCursor;\n keys.push(...batch);\n } while (cursor !== '0');\n\n return keys;\n }\n\n async flushAll(): Promise<void> {\n await this.redisClient.flushall();\n }\n\n async incr(key: string): Promise<number> {\n return this.redisClient.incr(key);\n }\n\n async decr(key: string): Promise<number> {\n return this.redisClient.decr(key);\n }\n\n async hset(key: string, field: string, value: string): Promise<void> {\n await this.redisClient.hset(key, field, value);\n }\n\n async hget(key: string, field: string): Promise<string | null> {\n return this.redisClient.hget(key, field);\n }\n\n async hgetall(key: string): Promise<Record<string, string>> {\n return this.redisClient.hgetall(key);\n }\n\n async hdel(key: string, field: string): Promise<void> {\n await this.redisClient.hdel(key, field);\n }\n\n async expire(key: string, ttlSeconds: number): Promise<void> {\n await this.redisClient.expire(key, ttlSeconds);\n }\n}\n"],"mappings":";;;;AAAO,IAAMA,uBAAuBC,uBAAO,sBAAA;;;ACA3C,SAAwBC,cAAc;AACtC,SAASC,oBAAoB;;;ACD7B,SACEC,QACAC,kBAGK;AACP,OAAOC,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKX,IAAMC,eAAN,MAAMA;SAAAA;;;;EACHC;EAER,YACiDC,SAC/C;SAD+CA,UAAAA;EAC9C;EAEH,MAAMC,eAAe;AACnB,UAAMD,UAAU,KAAKA,WAAW,CAAC;AAEjC,SAAKD,cAAc,IAAIG,MAAM;MAC3B,GAAGF;MACHG,MAAMH,QAAQG,QAAQC,QAAQC,IAAIC,cAAc;MAChDC,MAAMP,QAAQO,QAAQ,EAAEH,QAAQC,KAAKG,cAAc;MACnDC,UAAUT,QAAQS,YAAYL,QAAQC,KAAKK;MAC3CC,UAAUX,QAAQW,YAAYP,QAAQC,KAAKO;MAC3CC,WAAWb,QAAQa,aAAa;IAClC,CAAA;EACF;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;MAErDS,SAAS;QAACJ;;IACZ;EACF;AACF;;;;","names":["CACHE_MODULE_OPTIONS","Symbol","Module","ConfigModule","Inject","Injectable","Redis","CacheService","redisClient","options","onModuleInit","Redis","host","process","env","REDIS_HOST","port","REDIS_PORT","username","REDIS_USERNAME","password","REDIS_PASSWORD","keyPrefix","onModuleDestroy","quit","getClient","ping","set","key","value","ttlSeconds","setex","setIfNotExists","result","get","setJson","JSON","stringify","getJson","parse","del","exists","ttl","keys","pattern","scan","count","cursor","nextCursor","batch","push","flushAll","flushall","incr","decr","hset","field","hget","hgetall","hdel","expire","CacheModule","register","options","module","imports","ConfigModule","providers","CacheService","provide","CACHE_MODULE_OPTIONS","useValue","exports"]}