@bejibun/redis 0.1.17 → 0.1.18

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.
@@ -1,10 +1,11 @@
1
- var _a;
2
1
  import { defineValue, isEmpty, isNotEmpty } from "@bejibun/core";
3
2
  import { RedisClient } from "bun";
4
3
  import { EventEmitter } from "events";
5
4
  import config from "../config/redis";
6
5
  import RedisException from "../exceptions/RedisException";
7
- class RedisBuilder {
6
+ export default class RedisBuilder {
7
+ static clients = {};
8
+ static emitter = new EventEmitter();
8
9
  static connection(name) {
9
10
  return {
10
11
  del: (key) => this.del(key, name),
@@ -166,37 +167,33 @@ class RedisBuilder {
166
167
  static ensureExitHooks() {
167
168
  this.setupExitHooks();
168
169
  }
169
- }
170
- _a = RedisBuilder;
171
- RedisBuilder.clients = {};
172
- RedisBuilder.emitter = new EventEmitter();
173
- RedisBuilder.setupExitHooks = (() => {
174
- let initialized = false;
175
- return () => {
176
- if (initialized)
177
- return;
178
- initialized = true;
179
- const handleExit = async (signal) => {
180
- try {
181
- await _a.disconnect();
182
- console.log(`[Redis]: Disconnected on "${defineValue(signal, "exit")}".`);
183
- }
184
- catch (error) {
185
- console.error("[Redis]: Error during disconnect.", error.message);
186
- }
187
- finally {
188
- process.exit(0);
189
- }
170
+ static setupExitHooks = (() => {
171
+ let initialized = false;
172
+ return () => {
173
+ if (initialized)
174
+ return;
175
+ initialized = true;
176
+ const handleExit = async (signal) => {
177
+ try {
178
+ await RedisBuilder.disconnect();
179
+ console.log(`[Redis]: Disconnected on "${defineValue(signal, "exit")}".`);
180
+ }
181
+ catch (error) {
182
+ console.error("[Redis]: Error during disconnect.", error.message);
183
+ }
184
+ finally {
185
+ process.exit(0);
186
+ }
187
+ };
188
+ process.on("exit", async () => {
189
+ await handleExit();
190
+ });
191
+ process.on("SIGINT", async () => {
192
+ await handleExit("SIGINT");
193
+ });
194
+ process.on("SIGTERM", async () => {
195
+ await handleExit("SIGTERM");
196
+ });
190
197
  };
191
- process.on("exit", async () => {
192
- await handleExit();
193
- });
194
- process.on("SIGINT", async () => {
195
- await handleExit("SIGINT");
196
- });
197
- process.on("SIGTERM", async () => {
198
- await handleExit("SIGTERM");
199
- });
200
- };
201
- })();
202
- export default RedisBuilder;
198
+ })();
199
+ }
@@ -1,5 +1,6 @@
1
1
  import { defineValue } from "@bejibun/core";
2
2
  export default class RedisException extends Error {
3
+ code;
3
4
  constructor(message, code) {
4
5
  super(message);
5
6
  this.name = "RedisException";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bejibun/redis",
3
- "version": "0.1.17",
3
+ "version": "0.1.18",
4
4
  "description": "Redis for Bejibun Framework",
5
5
  "keywords": [
6
6
  "bun",
@@ -22,11 +22,11 @@
22
22
  "type": "module",
23
23
  "main": "./dist/index.js",
24
24
  "module": "./dist/index.js",
25
- "types": "./dist/types/index.d.ts",
25
+ "types": "./dist/index.d.ts",
26
26
  "exports": {
27
27
  ".": {
28
28
  "import": "./dist/index.js",
29
- "types": "./dist/types/index.d.ts"
29
+ "types": "./dist/index.d.ts"
30
30
  },
31
31
  "./exceptions/*": {
32
32
  "import": "./dist/exceptions/*.js",