@samet-it/be-redis-common 1.1.10 → 1.3.2

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,3 +1,3 @@
1
- export * from './index.types';
2
- export * from './redis.channel';
3
- export * from './redis-direct.channel';
1
+ export * from './index.types.js';
2
+ export * from './redis.channel.js';
3
+ export * from './redis-direct.channel.js';
@@ -1,19 +1,3 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./index.types"), exports);
18
- __exportStar(require("./redis.channel"), exports);
19
- __exportStar(require("./redis-direct.channel"), exports);
1
+ export * from './index.types.js';
2
+ export * from './redis.channel.js';
3
+ export * from './redis-direct.channel.js';
@@ -1,8 +1,7 @@
1
- import type { RedisConnectionLike } from "../connection";
2
- import type { CacheChannelProps, CacheChannelLike, CacheChannelOpt, CacheExecOpt } from "@samet-it/be-cache-common";
3
- import type { Entity } from "@samet-it/be-base-common";
4
- import type { RedisClientType } from "redis";
5
- import type { KeyValue } from "@leyyo/common";
1
+ import { RedisConnectionLike } from "../connection/index.js";
2
+ import { CacheChannelLike, CacheChannelOpt, CacheChannelProps, CacheExecOpt } from "@samet-it/be-cache-common";
3
+ import { Entity, KeyValue } from "@samet-it/be-base-common";
4
+ import { RedisClientType } from "redis";
6
5
  /**
7
6
  * Redis channel interface
8
7
  *
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,8 +1,7 @@
1
- import { RedisChannel } from "./redis.channel";
2
- import { type Entity } from "@samet-it/be-base-common";
3
- import type { RedisConnectionLike } from "../connection";
4
- import type { RedisDirectChannelOpt } from "./index.types";
5
- import type { KeyValue } from "@leyyo/common";
1
+ import { RedisChannel } from "./redis.channel.js";
2
+ import { type Entity, KeyValue } from "@samet-it/be-base-common";
3
+ import { RedisConnectionLike } from "../connection/index.js";
4
+ import { RedisDirectChannelOpt } from "./index.types.js";
6
5
  /**
7
6
  * Redis direct channel class
8
7
  *
@@ -1,8 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RedisDirectChannel = void 0;
4
- const redis_channel_1 = require("./redis.channel");
5
- const be_base_common_1 = require("@samet-it/be-base-common");
1
+ import { RedisChannel } from "./redis.channel.js";
2
+ import { logCommon, setFqn } from "@samet-it/be-base-common";
3
+ import { FQN } from "../internal.js";
6
4
  /**
7
5
  * Redis direct channel class
8
6
  *
@@ -10,7 +8,7 @@ const be_base_common_1 = require("@samet-it/be-base-common");
10
8
  * - 0-`ENT`: entity {@link Entity}
11
9
  * - 1-`ID`: id type {@link KeyValue}
12
10
  * */
13
- class RedisDirectChannel extends redis_channel_1.RedisChannel {
11
+ export class RedisDirectChannel extends RedisChannel {
14
12
  /**
15
13
  * Constructor
16
14
  *
@@ -19,7 +17,7 @@ class RedisDirectChannel extends redis_channel_1.RedisChannel {
19
17
  * */
20
18
  constructor(conn, opt) {
21
19
  super(conn, opt);
22
- this.logger = be_base_common_1.logger.create(`RedisDirect${opt.name ? '#' + opt.name : ''}`);
20
+ this.logger = logCommon.of(`RedisDirect${opt.name ? '#' + opt.name : ''}`);
23
21
  }
24
22
  }
25
- exports.RedisDirectChannel = RedisDirectChannel;
23
+ setFqn(RedisDirectChannel, FQN);
@@ -1,9 +1,8 @@
1
- import type { RedisConnectionLike } from "../connection";
2
- import type { RedisChannelProps, RedisChannelLike, RedisChannelOpt, RedisExecOpt } from "./index.types";
3
- import { type Entity } from "@samet-it/be-base-common";
1
+ import { RedisConnectionLike } from "../connection/index.js";
2
+ import { RedisChannelLike, RedisChannelOpt, RedisChannelProps, RedisExecOpt } from "./index.types.js";
3
+ import { Entity, KeyValue } from "@samet-it/be-base-common";
4
4
  import { CacheChannel } from "@samet-it/be-cache-common";
5
- import type { KeyValue } from "@leyyo/common";
6
- import type { RedisClientType } from "redis";
5
+ import { RedisClientType } from "redis";
7
6
  /**
8
7
  * Redis abstract channel class
9
8
  *
@@ -1,16 +1,6 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.RedisChannel = void 0;
13
- const be_cache_common_1 = require("@samet-it/be-cache-common");
1
+ import { setFqn } from "@samet-it/be-base-common";
2
+ import { CacheChannel } from "@samet-it/be-cache-common";
3
+ import { FQN } from "../internal.js";
14
4
  // noinspection JSUnusedGlobalSymbols
15
5
  /**
16
6
  * Redis abstract channel class
@@ -19,7 +9,7 @@ const be_cache_common_1 = require("@samet-it/be-cache-common");
19
9
  * - 0-`ENT`: entity {@link Entity}
20
10
  * - 1-`ID`: id type {@link KeyValue}
21
11
  * */
22
- class RedisChannel extends be_cache_common_1.CacheChannel {
12
+ export class RedisChannel extends CacheChannel {
23
13
  // endregion protected-property
24
14
  /**
25
15
  * Constructor
@@ -42,186 +32,167 @@ class RedisChannel extends be_cache_common_1.CacheChannel {
42
32
  // endregion getter
43
33
  // region native-calls
44
34
  /** @inheritDoc */
45
- $get(path, opt) {
46
- return __awaiter(this, void 0, void 0, function* () {
47
- if (!this.isConnected) {
48
- return undefined;
49
- }
50
- if (typeof path !== 'string') {
51
- return undefined;
52
- }
53
- try {
54
- return yield this.client.get(path);
55
- }
56
- catch (e) {
57
- this.checkError(e, { name: 'GET', method: '$get' });
58
- }
35
+ async $get(path, opt) {
36
+ if (!this.isConnected) {
37
+ return undefined;
38
+ }
39
+ if (typeof path !== 'string') {
59
40
  return undefined;
60
- });
41
+ }
42
+ try {
43
+ return await this.client.get(path);
44
+ }
45
+ catch (e) {
46
+ this.checkError(e, { name: 'GET', method: '$get' });
47
+ }
48
+ return undefined;
61
49
  }
62
50
  /** @inheritDoc */
63
- $getMore(paths, _opt) {
64
- return __awaiter(this, void 0, void 0, function* () {
65
- if (!this.isConnected) {
66
- return [];
67
- }
68
- if (paths.length < 1) {
69
- return [];
70
- }
71
- if (paths.length == 1) {
72
- try {
73
- const rec = (yield this.client.get(paths[0]));
74
- return rec ? [rec] : [];
75
- }
76
- catch (e) {
77
- this.checkError(e, { name: 'GET', method: '$getMore' });
78
- return [];
79
- }
80
- }
51
+ async $getMore(paths, _opt) {
52
+ if (!this.isConnected) {
53
+ return [];
54
+ }
55
+ if (paths.length < 1) {
56
+ return [];
57
+ }
58
+ if (paths.length == 1) {
81
59
  try {
82
- return (yield this.client.mGet(paths));
60
+ const rec = (await this.client.get(paths[0]));
61
+ return rec ? [rec] : [];
83
62
  }
84
63
  catch (e) {
85
- this.checkError(e, { name: 'MGET', method: '$getMore' });
64
+ this.checkError(e, { name: 'GET', method: '$getMore' });
86
65
  return [];
87
66
  }
88
- });
67
+ }
68
+ try {
69
+ return (await this.client.mGet(paths));
70
+ }
71
+ catch (e) {
72
+ this.checkError(e, { name: 'MGET', method: '$getMore' });
73
+ return [];
74
+ }
89
75
  }
90
76
  /** @inheritDoc */
91
- $set(path, value, _opt) {
92
- return __awaiter(this, void 0, void 0, function* () {
93
- if (!this.isConnected) {
94
- return false;
95
- }
96
- if (typeof path !== 'string' || typeof value !== 'string') {
97
- return false;
98
- }
99
- try {
100
- yield this.client.set(path, value);
101
- return true;
102
- }
103
- catch (e) {
104
- this.checkError(e, { name: 'SET', method: '$set' });
105
- }
77
+ async $set(path, value, _opt) {
78
+ if (!this.isConnected) {
79
+ return false;
80
+ }
81
+ if (typeof path !== 'string' || typeof value !== 'string') {
106
82
  return false;
107
- });
83
+ }
84
+ try {
85
+ await this.client.set(path, value);
86
+ return true;
87
+ }
88
+ catch (e) {
89
+ this.checkError(e, { name: 'SET', method: '$set' });
90
+ }
91
+ return false;
108
92
  }
109
93
  /** @inheritDoc */
110
- $setMore(map, _opt) {
111
- return __awaiter(this, void 0, void 0, function* () {
112
- if (!this.isConnected) {
94
+ async $setMore(map, _opt) {
95
+ if (!this.isConnected) {
96
+ return 0;
97
+ }
98
+ if (!map || typeof map !== 'object' || Array.isArray(map)) {
99
+ return 0;
100
+ }
101
+ const keys = Object.keys(map);
102
+ switch (keys.length) {
103
+ case 0:
113
104
  return 0;
114
- }
115
- if (!map || typeof map !== 'object' || Array.isArray(map)) {
116
- return 0;
117
- }
118
- const keys = Object.keys(map);
119
- switch (keys.length) {
120
- case 0:
121
- return 0;
122
- case 1:
123
- const key = keys[0];
124
- try {
125
- yield this.client.set(key, map[key]);
126
- }
127
- catch (e) {
128
- this.checkError(e, { name: 'SET', method: '$setMore' });
129
- }
130
- return 1;
131
- default:
132
- try {
133
- yield this.client.mSet(map);
134
- }
135
- catch (e) {
136
- this.checkError(e, { name: 'MSET', method: '$setMore' });
137
- }
138
- return keys.length;
139
- }
140
- });
105
+ case 1:
106
+ const key = keys[0];
107
+ try {
108
+ await this.client.set(key, map[key]);
109
+ }
110
+ catch (e) {
111
+ this.checkError(e, { name: 'SET', method: '$setMore' });
112
+ }
113
+ return 1;
114
+ default:
115
+ try {
116
+ await this.client.mSet(map);
117
+ }
118
+ catch (e) {
119
+ this.checkError(e, { name: 'MSET', method: '$setMore' });
120
+ }
121
+ return keys.length;
122
+ }
141
123
  }
142
124
  /** @inheritDoc */
143
- $delete(path, _opt) {
144
- return __awaiter(this, void 0, void 0, function* () {
145
- if (!this.isConnected) {
146
- return false;
147
- }
148
- if (typeof path !== 'string') {
149
- return false;
150
- }
151
- try {
152
- const result = yield this.client.del(path);
153
- return result > 0;
154
- }
155
- catch (e) {
156
- this.checkError(e, { name: 'DEL', method: '$delete' });
157
- }
125
+ async $delete(path, _opt) {
126
+ if (!this.isConnected) {
127
+ return false;
128
+ }
129
+ if (typeof path !== 'string') {
158
130
  return false;
159
- });
131
+ }
132
+ try {
133
+ const result = await this.client.del(path);
134
+ return result > 0;
135
+ }
136
+ catch (e) {
137
+ this.checkError(e, { name: 'DEL', method: '$delete' });
138
+ }
139
+ return false;
160
140
  }
161
141
  /** @inheritDoc */
162
- $deleteMore(paths, _opt) {
163
- return __awaiter(this, void 0, void 0, function* () {
164
- if (!this.isConnected) {
165
- return 0;
166
- }
167
- if (paths.length < 1) {
168
- return 0;
169
- }
170
- try {
171
- yield this.client.del(paths);
172
- }
173
- catch (e) {
174
- this.checkError(e, { name: 'DEL', method: '$deleteMore' });
175
- }
176
- return paths.length;
177
- });
142
+ async $deleteMore(paths, _opt) {
143
+ if (!this.isConnected) {
144
+ return 0;
145
+ }
146
+ if (paths.length < 1) {
147
+ return 0;
148
+ }
149
+ try {
150
+ await this.client.del(paths);
151
+ }
152
+ catch (e) {
153
+ this.checkError(e, { name: 'DEL', method: '$deleteMore' });
154
+ }
155
+ return paths.length;
178
156
  }
179
157
  /** @inheritDoc */
180
- $addLinks(idPath, paths, _opt) {
181
- return __awaiter(this, void 0, void 0, function* () {
182
- if (!this.isConnected) {
183
- return 0;
184
- }
185
- if (paths.length < 1) {
186
- return 0;
187
- }
188
- try {
189
- yield this.client.sAdd(idPath, paths);
190
- }
191
- catch (e) {
192
- this.checkError(e, { name: 'SADD', method: '$addLinks' });
193
- }
194
- return paths.length;
195
- });
158
+ async $addLinks(idPath, paths, _opt) {
159
+ if (!this.isConnected) {
160
+ return 0;
161
+ }
162
+ if (paths.length < 1) {
163
+ return 0;
164
+ }
165
+ try {
166
+ await this.client.sAdd(idPath, paths);
167
+ }
168
+ catch (e) {
169
+ this.checkError(e, { name: 'SADD', method: '$addLinks' });
170
+ }
171
+ return paths.length;
196
172
  }
197
173
  /** @inheritDoc */
198
- $expire(path, seconds, _opt) {
199
- return __awaiter(this, void 0, void 0, function* () {
200
- if (!this.isConnected) {
201
- return false;
202
- }
203
- try {
204
- return (yield this.client.expire(path, seconds)) > 0;
205
- }
206
- catch (e) {
207
- this.checkError(e, { name: 'EXPIRE', method: '$expire' });
208
- }
209
- });
174
+ async $expire(path, seconds, _opt) {
175
+ if (!this.isConnected) {
176
+ return false;
177
+ }
178
+ try {
179
+ return (await this.client.expire(path, seconds)) > 0;
180
+ }
181
+ catch (e) {
182
+ this.checkError(e, { name: 'EXPIRE', method: '$expire' });
183
+ }
210
184
  }
211
185
  /** @inheritDoc */
212
- $getLinks(idPath, _opt) {
213
- return __awaiter(this, void 0, void 0, function* () {
214
- var _a;
215
- if (!this.isConnected) {
216
- return [];
217
- }
218
- try {
219
- return (_a = (yield this.client.sMembers(idPath))) !== null && _a !== void 0 ? _a : [];
220
- }
221
- catch (e) {
222
- this.checkError(e, { name: 'SMEMBERS', method: '$getLinks' });
223
- }
224
- });
186
+ async $getLinks(idPath, _opt) {
187
+ if (!this.isConnected) {
188
+ return [];
189
+ }
190
+ try {
191
+ return (await this.client.sMembers(idPath)) ?? [];
192
+ }
193
+ catch (e) {
194
+ this.checkError(e, { name: 'SMEMBERS', method: '$getLinks' });
195
+ }
225
196
  }
226
197
  }
227
- exports.RedisChannel = RedisChannel;
198
+ setFqn(RedisChannel, FQN);
@@ -1,2 +1,2 @@
1
- export * from './redis-common.config';
2
- export * from './index.types';
1
+ export * from './redis-common.config.js';
2
+ export * from './index.types.js';
@@ -1,18 +1,2 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./redis-common.config"), exports);
18
- __exportStar(require("./index.types"), exports);
1
+ export * from './redis-common.config.js';
2
+ export * from './index.types.js';
@@ -1,4 +1,4 @@
1
- import type { EnvBase } from "@leyyo/env";
1
+ import { EnvBase } from "@leyyo/env";
2
2
  export interface RedisCommonConf extends EnvBase {
3
3
  /**
4
4
  * Redis Enabled
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,5 +1,5 @@
1
- import type { RedisCommonConf } from "./index.types";
1
+ import { RedisCommonConf } from "./index.types.js";
2
2
  /**
3
3
  * Redis common config
4
4
  * */
5
- export declare const redisCommonConfig: import("@leyyo/env").EnvScopeRuntime<RedisCommonConf, "REDIS", undefined>;
5
+ export declare const redisCommonConfig: import("@samet-it/be-base-common").EnvScopeRuntime<RedisCommonConf, "REDIS", undefined>;
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.redisCommonConfig = void 0;
4
- const env_1 = require("@leyyo/env");
1
+ import { envCore } from "@samet-it/be-base-common";
5
2
  /**
6
3
  * Redis common config
7
4
  * */
8
- exports.redisCommonConfig = env_1.envCore.configure
5
+ export const redisCommonConfig = envCore.configure
9
6
  .scope('RedisCommon', 'REDIS')
10
7
  .start()
11
8
  // @formatter:off
@@ -1,4 +1,4 @@
1
- export * from './index.types';
2
- export * from './redis.connection';
3
- export * from './redis-direct.connection';
4
- export * from './redis-connection.fn';
1
+ export * from './index.types.js';
2
+ export * from './redis.connection.js';
3
+ export * from './redis-direct.connection.js';
4
+ export * from './redis-connection.fn.js';
@@ -1,20 +1,4 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./index.types"), exports);
18
- __exportStar(require("./redis.connection"), exports);
19
- __exportStar(require("./redis-direct.connection"), exports);
20
- __exportStar(require("./redis-connection.fn"), exports);
1
+ export * from './index.types.js';
2
+ export * from './redis.connection.js';
3
+ export * from './redis-direct.connection.js';
4
+ export * from './redis-connection.fn.js';
@@ -1,9 +1,7 @@
1
- import type { CacheConnectionLike, CacheConnOpt } from "@samet-it/be-cache-common";
2
- import type { RedisClientType } from "redis";
3
- import type { Entity } from "@samet-it/be-base-common";
4
- import type { RedisDirectChannelOpt, RedisChannelLike } from "../channel";
5
- import type { CacheConnProps } from "@samet-it/be-cache-common";
6
- import type { KeyValue } from "@leyyo/common";
1
+ import { CacheConnectionLike, CacheConnOpt, CacheConnProps } from "@samet-it/be-cache-common";
2
+ import { RedisClientType } from "redis";
3
+ import { Entity, KeyValue } from "@samet-it/be-base-common";
4
+ import { RedisChannelLike, RedisDirectChannelOpt } from "../channel/index.js";
7
5
  /**
8
6
  * Redis connection interface
9
7
  * */
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,4 +1,4 @@
1
- import type { RedisConnDirectOpt, RedisDirectConnectionLike } from "./index.types";
1
+ import { RedisConnDirectOpt, RedisDirectConnectionLike } from "./index.types.js";
2
2
  /**
3
3
  * Crete new redis connection
4
4
  *
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.redisConnection = redisConnection;
4
- const redis_direct_connection_1 = require("./redis-direct.connection");
1
+ import { RedisDirectConnection } from "./redis-direct.connection.js";
5
2
  // noinspection JSUnusedGlobalSymbols
6
3
  /**
7
4
  * Crete new redis connection
@@ -9,6 +6,6 @@ const redis_direct_connection_1 = require("./redis-direct.connection");
9
6
  * @param {RedisConnDirectOpt} opt - option
10
7
  * @return {RedisDirectConnectionLike} - new redis connection
11
8
  * */
12
- function redisConnection(opt) {
13
- return new redis_direct_connection_1.RedisDirectConnection(opt);
9
+ export function redisConnection(opt) {
10
+ return new RedisDirectConnection(opt);
14
11
  }
@@ -1,8 +1,7 @@
1
- import { RedisConnection } from "./redis.connection";
2
- import { type Entity } from "@samet-it/be-base-common";
3
- import { type RedisDirectChannelOpt, type RedisChannelLike } from "../channel";
4
- import type { RedisConnDirectOpt, RedisDirectConnectionLike } from "./index.types";
5
- import type { KeyValue } from "@leyyo/common";
1
+ import { RedisConnection } from "./redis.connection.js";
2
+ import { Entity, KeyValue } from "@samet-it/be-base-common";
3
+ import { RedisChannelLike, RedisDirectChannelOpt } from "../channel/index.js";
4
+ import { RedisConnDirectOpt, RedisDirectConnectionLike } from "./index.types.js";
6
5
  /**
7
6
  * Redis connection direct class
8
7
  * */
@@ -1,13 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RedisDirectConnection = void 0;
4
- const redis_connection_1 = require("./redis.connection");
5
- const be_base_common_1 = require("@samet-it/be-base-common");
6
- const channel_1 = require("../channel");
1
+ import { RedisConnection } from "./redis.connection.js";
2
+ import { logCommon, setFqn } from "@samet-it/be-base-common";
3
+ import { RedisDirectChannel } from "../channel/index.js";
4
+ import { FQN } from "../internal.js";
7
5
  /**
8
6
  * Redis connection direct class
9
7
  * */
10
- class RedisDirectConnection extends redis_connection_1.RedisConnection {
8
+ export class RedisDirectConnection extends RedisConnection {
11
9
  /**
12
10
  * Constructor
13
11
  *
@@ -15,11 +13,11 @@ class RedisDirectConnection extends redis_connection_1.RedisConnection {
15
13
  * */
16
14
  constructor(opt) {
17
15
  super(opt);
18
- this.logger = be_base_common_1.logger.create(`RedisConnection${(opt === null || opt === void 0 ? void 0 : opt.name) ? '#' + (opt === null || opt === void 0 ? void 0 : opt.name) : ''}`);
16
+ this.logger = logCommon.of(`RedisConnection${opt?.name ? '#' + opt?.name : ''}`);
19
17
  }
20
18
  /** @inheritDoc */
21
19
  newChannel(opt) {
22
- return new channel_1.RedisDirectChannel(this, opt);
20
+ return new RedisDirectChannel(this, opt);
23
21
  }
24
22
  }
25
- exports.RedisDirectConnection = RedisDirectConnection;
23
+ setFqn(RedisDirectConnection, FQN);
@@ -1,6 +1,6 @@
1
- import type { RedisConnectionLike, RedisConnProps, RedisConnOpt } from "./index.types";
1
+ import { RedisClientType } from 'redis';
2
+ import { RedisConnectionLike, RedisConnOpt, RedisConnProps } from "./index.types.js";
2
3
  import { CacheConnection } from "@samet-it/be-cache-common";
3
- import type { RedisClientType } from "redis";
4
4
  /**
5
5
  * Redis connection abstract class
6
6
  * */
@@ -1,56 +1,49 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
- return new (P || (P = Promise))(function (resolve, reject) {
38
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
- step((generator = generator.apply(thisArg, _arguments || [])).next());
42
- });
43
- };
44
- Object.defineProperty(exports, "__esModule", { value: true });
45
- exports.RedisConnection = void 0;
46
- const redis = __importStar(require("redis"));
47
- const config_1 = require("../config");
48
- const be_cache_common_1 = require("@samet-it/be-cache-common");
49
- const be_base_common_1 = require("@samet-it/be-base-common");
1
+ import * as redis from 'redis';
2
+ import { redisCommonConfig } from "../config/index.js";
3
+ import { CacheConnection, CacheError } from "@samet-it/be-cache-common";
4
+ import { errorCommon, logCommon, setFqn } from "@samet-it/be-base-common";
5
+ import { FQN } from "../internal.js";
50
6
  /**
51
7
  * Redis connection abstract class
52
8
  * */
53
- class RedisConnection extends be_cache_common_1.CacheConnection {
9
+ export class RedisConnection extends CacheConnection {
10
+ // region private-property
11
+ /**
12
+ * Base/starting/min delay for connection
13
+ *
14
+ * @type {number} - as seconds
15
+ * */
16
+ static CONN_BASE_DELAY = 500; // 0.5 sec
17
+ /**
18
+ * Last/max delay for connection
19
+ *
20
+ * @type {number} - as seconds
21
+ * */
22
+ static CONN_MAX_DELAY = 1_000 * 60 * 60; // 60 minutes
23
+ /**
24
+ * Try count
25
+ *
26
+ * @type {number} - times
27
+ * */
28
+ static CONN_TRY_COUNT = 100; // 100 times
29
+ /**
30
+ * Base/starting/min delay for ping
31
+ *
32
+ * @type {number} - as seconds
33
+ * */
34
+ static PING_BASE_DELAY = 200; // 0.2 sec
35
+ /**
36
+ * Last/max delay ping
37
+ *
38
+ * @type {number} - as seconds
39
+ * */
40
+ static PING_MAX_DELAY = 1_000 * 60 * 10; // 10 minutes
41
+ /**
42
+ * Try count
43
+ *
44
+ * @type {number} - times
45
+ * */
46
+ static PING_TRY_COUNT = 100; // 100 times
54
47
  // endregion protected-property
55
48
  /**
56
49
  * Constructor
@@ -60,7 +53,7 @@ class RedisConnection extends be_cache_common_1.CacheConnection {
60
53
  constructor(opt) {
61
54
  super(opt);
62
55
  if (!this.logger) {
63
- this.logger = be_base_common_1.logger.create(this);
56
+ this.logger = logCommon.of(this);
64
57
  }
65
58
  this._readFromEnv();
66
59
  this._buildUrl();
@@ -80,19 +73,18 @@ class RedisConnection extends be_cache_common_1.CacheConnection {
80
73
  * Read credentials from environment
81
74
  * */
82
75
  _readFromEnv() {
83
- var _a, _b, _c, _d, _e, _f, _g;
84
76
  const { _props: props } = this;
85
- let env = config_1.redisCommonConfig.valueShort;
77
+ let env = redisCommonConfig.valueShort;
86
78
  if (props.envVariant) {
87
- env = config_1.redisCommonConfig.configure.getVariation(props.envVariant).valueShort;
79
+ env = redisCommonConfig.configure.getVariation(props.envVariant).valueShort;
88
80
  }
89
- props.isEnabled = (_a = props.isEnabled) !== null && _a !== void 0 ? _a : env.ENABLED;
90
- props.protocol = (_b = props.protocol) !== null && _b !== void 0 ? _b : env.PROTOCOL;
91
- props.host = (_c = props.host) !== null && _c !== void 0 ? _c : env.HOST;
92
- props.port = (_d = props.port) !== null && _d !== void 0 ? _d : env.PORT;
93
- props.username = (_e = props.username) !== null && _e !== void 0 ? _e : env.USER;
94
- props.password = (_f = props.password) !== null && _f !== void 0 ? _f : env.PASS;
95
- props.dbNumber = (_g = props.dbNumber) !== null && _g !== void 0 ? _g : env.DB_NUMBER;
81
+ props.isEnabled = props.isEnabled ?? env.ENABLED;
82
+ props.protocol = props.protocol ?? env.PROTOCOL;
83
+ props.host = props.host ?? env.HOST;
84
+ props.port = props.port ?? env.PORT;
85
+ props.username = props.username ?? env.USER;
86
+ props.password = props.password ?? env.PASS;
87
+ props.dbNumber = props.dbNumber ?? env.DB_NUMBER;
96
88
  }
97
89
  /**
98
90
  * Build url from credentials
@@ -126,129 +118,88 @@ class RedisConnection extends be_cache_common_1.CacheConnection {
126
118
  // endregion protected-method
127
119
  // region connect
128
120
  /** {@inheritDoc} */
129
- connect() {
130
- return __awaiter(this, void 0, void 0, function* () {
131
- const { _props: props } = this;
132
- if (!this.isEnabled) {
133
- return false;
134
- }
135
- if (this.isConnected) {
136
- return true;
137
- }
138
- if (this._props.connectTryCount > RedisConnection.CONN_TRY_COUNT) {
139
- const err = new be_cache_common_1.CacheError('Maximum try county', { tryCount: this._props.connectTryCount });
140
- this.logger.error(be_base_common_1.errorHandler.common.logText(err, 'connect'));
141
- return false;
142
- }
143
- try {
144
- props.client = redis.createClient({ url: this._props.producedUrl });
145
- props.client
146
- .on("error", err => {
147
- this.logger.warn(be_base_common_1.errorHandler.common.logText(err, 'connection', this._props.connectTryCount));
148
- props.connectTryCount++;
149
- const old = this.isConnected;
150
- props.isConnected = false;
151
- if (old) {
152
- this._triggerOnCase('disconnected', this._onDisconnected, false);
153
- }
154
- setTimeout(() => this.connect().then(), this._connectionDelay);
155
- })
156
- .on('connect', () => {
157
- this.logger.info(`on[connect]`);
158
- props.isConnected = true;
159
- props.connectTryCount = 0;
160
- this._triggerOnCase('connected', this._onConnected, false);
161
- if (props.isFirst === undefined) {
162
- this._triggerOnCase('first-connected', this._onFirstConnected, true);
163
- props.isFirst = false;
164
- }
165
- // clear stopped ping
166
- if (this._props.pingTryCount > RedisConnection.PING_TRY_COUNT) {
167
- this._props.pingTryCount = 0;
168
- setTimeout(() => this.ping(true).then(), 30000);
169
- }
170
- })
171
- .on('ready', () => this.logger.info('on[ready]'))
172
- .on('close', () => this.logger.info('on[close]'))
173
- .on('reconnecting', () => this.logger.info('on[reconnecting]'))
174
- .on('end', () => this.logger.info('on[end]'));
175
- yield props.client.connect();
176
- this.logger.info('Connected');
177
- setTimeout(() => this.ping(true).then(), 30000);
178
- }
179
- catch (e) {
180
- this.logger.warn(be_base_common_1.errorHandler.common.logText(e, 'connection', this._props.connectTryCount));
181
- }
121
+ async connect() {
122
+ const { _props: props } = this;
123
+ if (!this.isEnabled) {
124
+ return false;
125
+ }
126
+ if (this.isConnected) {
182
127
  return true;
183
- });
184
- }
185
- /** {@inheritDoc} */
186
- ping(next) {
187
- return __awaiter(this, void 0, void 0, function* () {
188
- if (!this.isEnabled) {
189
- return false;
190
- }
191
- if (this._props.pingTryCount > RedisConnection.PING_TRY_COUNT) {
192
- const err = new be_cache_common_1.CacheError('Maximum try county', { tryCount: this._props.pingTryCount });
193
- this.logger.error(be_base_common_1.errorHandler.common.logText(err, 'connect'));
194
- return false;
195
- }
196
- let result = false;
197
- if (this.isConnected) {
198
- try {
199
- yield this.client.ping();
200
- this._props.pingTryCount = 0;
201
- result = true;
128
+ }
129
+ if (this._props.connectTryCount > RedisConnection.CONN_TRY_COUNT) {
130
+ const err = new CacheError('Maximum try county', { tryCount: this._props.connectTryCount });
131
+ this.logger.error(errorCommon.text(err, 'connect'));
132
+ return false;
133
+ }
134
+ try {
135
+ props.client = redis.createClient({ url: this._props.producedUrl });
136
+ props.client
137
+ .on("error", err => {
138
+ this.logger.warn(errorCommon.text(err, 'connection', this._props.connectTryCount));
139
+ props.connectTryCount++;
140
+ const old = this.isConnected;
141
+ props.isConnected = false;
142
+ if (old) {
143
+ this._triggerOnCase('disconnected', this._onDisconnected, false);
144
+ }
145
+ setTimeout(() => this.connect().then(), this._connectionDelay);
146
+ })
147
+ .on('connect', () => {
148
+ this.logger.info(`on[connect]`);
149
+ props.isConnected = true;
150
+ props.connectTryCount = 0;
151
+ this._triggerOnCase('connected', this._onConnected, false);
152
+ if (props.isFirst === undefined) {
153
+ this._triggerOnCase('first-connected', this._onFirstConnected, true);
154
+ props.isFirst = false;
202
155
  }
203
- catch (err) {
204
- this._props.pingTryCount++;
205
- this.logger.warn(be_base_common_1.errorHandler.common.logText(err, 'ping', this._props.pingTryCount));
206
- setTimeout(() => this.ping(true).then(), this._pingDelay);
207
- next = false;
156
+ // clear stopped ping
157
+ if (this._props.pingTryCount > RedisConnection.PING_TRY_COUNT) {
158
+ this._props.pingTryCount = 0;
159
+ setTimeout(() => this.ping(true).then(), 30_000);
208
160
  }
161
+ })
162
+ .on('ready', () => this.logger.info('on[ready]'))
163
+ .on('close', () => this.logger.info('on[close]'))
164
+ .on('reconnecting', () => this.logger.info('on[reconnecting]'))
165
+ .on('end', () => this.logger.info('on[end]'));
166
+ await props.client.connect();
167
+ this.logger.info('Connected');
168
+ setTimeout(() => this.ping(true).then(), 30_000);
169
+ }
170
+ catch (e) {
171
+ this.logger.warn(errorCommon.text(e, 'connection', this._props.connectTryCount));
172
+ }
173
+ return true;
174
+ }
175
+ /** {@inheritDoc} */
176
+ async ping(next) {
177
+ if (!this.isEnabled) {
178
+ return false;
179
+ }
180
+ if (this._props.pingTryCount > RedisConnection.PING_TRY_COUNT) {
181
+ const err = new CacheError('Maximum try county', { tryCount: this._props.pingTryCount });
182
+ this.logger.error(errorCommon.text(err, 'connect'));
183
+ return false;
184
+ }
185
+ let result = false;
186
+ if (this.isConnected) {
187
+ try {
188
+ await this.client.ping();
189
+ this._props.pingTryCount = 0;
190
+ result = true;
209
191
  }
210
- if (next) {
211
- setTimeout(() => this.ping(true).then(), 30000);
192
+ catch (err) {
193
+ this._props.pingTryCount++;
194
+ this.logger.warn(errorCommon.text(err, 'ping', this._props.pingTryCount));
195
+ setTimeout(() => this.ping(true).then(), this._pingDelay);
196
+ next = false;
212
197
  }
213
- return result;
214
- });
198
+ }
199
+ if (next) {
200
+ setTimeout(() => this.ping(true).then(), 30_000);
201
+ }
202
+ return result;
215
203
  }
216
204
  }
217
- exports.RedisConnection = RedisConnection;
218
- // region private-property
219
- /**
220
- * Base/starting/min delay for connection
221
- *
222
- * @type {number} - as seconds
223
- * */
224
- RedisConnection.CONN_BASE_DELAY = 500; // 0.5 sec
225
- /**
226
- * Last/max delay for connection
227
- *
228
- * @type {number} - as seconds
229
- * */
230
- RedisConnection.CONN_MAX_DELAY = 1000 * 60 * 60; // 60 minutes
231
- /**
232
- * Try count
233
- *
234
- * @type {number} - times
235
- * */
236
- RedisConnection.CONN_TRY_COUNT = 100; // 100 times
237
- /**
238
- * Base/starting/min delay for ping
239
- *
240
- * @type {number} - as seconds
241
- * */
242
- RedisConnection.PING_BASE_DELAY = 200; // 0.2 sec
243
- /**
244
- * Last/max delay ping
245
- *
246
- * @type {number} - as seconds
247
- * */
248
- RedisConnection.PING_MAX_DELAY = 1000 * 60 * 10; // 10 minutes
249
- /**
250
- * Try count
251
- *
252
- * @type {number} - times
253
- * */
254
- RedisConnection.PING_TRY_COUNT = 100; // 100 times
205
+ setFqn(RedisConnection, FQN);
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
- export * from './connection';
2
- export * from './config';
3
- export * from './channel';
1
+ export * from './connection/index.js';
2
+ export * from './config/index.js';
3
+ export * from './channel/index.js';
4
+ export * from './index.foretell.js';
5
+ export * from './index.loader.js';
@@ -0,0 +1 @@
1
+ export declare const foretell_sametRedisCommon: any[];
@@ -0,0 +1,8 @@
1
+ import { foretell_sametBaseCommon } from "@samet-it/be-base-common";
2
+ import { foretell_sametCacheCommon } from "@samet-it/be-cache-common/dist/index.foretell.js";
3
+ // noinspection JSUnusedGlobalSymbols
4
+ export const foretell_sametRedisCommon = [
5
+ // dependencies
6
+ ...foretell_sametBaseCommon,
7
+ ...foretell_sametCacheCommon,
8
+ ];
package/dist/index.js CHANGED
@@ -1,19 +1,5 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./connection"), exports);
18
- __exportStar(require("./config"), exports);
19
- __exportStar(require("./channel"), exports);
1
+ export * from './connection/index.js';
2
+ export * from './config/index.js';
3
+ export * from './channel/index.js';
4
+ export * from './index.foretell.js';
5
+ export * from './index.loader.js';
@@ -0,0 +1 @@
1
+ export declare const loader_sametRedisCommon: import("@leyyo/common").LoaderLike;
@@ -0,0 +1,10 @@
1
+ import { defineLoader } from "@leyyo/common";
2
+ import { FQN } from "./internal.js";
3
+ import { loader_sametBaseCommon } from "@samet-it/be-base-common";
4
+ import { loader_sametCacheCommon } from "@samet-it/be-cache-common/dist/index.loader.js";
5
+ // noinspection JSUnusedGlobalSymbols
6
+ export const loader_sametRedisCommon = defineLoader(FQN,
7
+ // dependencies
8
+ ...loader_sametBaseCommon, ...loader_sametCacheCommon,
9
+ // classes
10
+ () => import('./channel/redis.channel.js').then(m => m.RedisChannel), () => import('./channel/redis-direct.channel.js').then(m => m.RedisDirectChannel), () => import('./connection/redis.connection.js').then(m => m.RedisConnection), () => import('./connection/redis-direct.connection.js').then(m => m.RedisDirectConnection), () => import('./config/redis-common.config.js').then(m => m.redisCommonConfig));
@@ -0,0 +1 @@
1
+ export declare const NME: string, FQN: string, VER: string, CNF: import("@samet-it/be-base-common").LeyyoConfig;
@@ -0,0 +1,2 @@
1
+ import { sysAll } from "@samet-it/be-base-common";
2
+ export const { pck: { name: NME, fqn: FQN, version: VER }, config: CNF } = sysAll(import.meta.url);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@samet-it/be-redis-common",
3
- "version": "1.1.10",
3
+ "version": "1.3.2",
4
4
  "description": "Redis common component",
5
5
  "keywords": [
6
6
  "redis",
@@ -20,13 +20,13 @@
20
20
  "email": "mustafay@samet.com.tr"
21
21
  },
22
22
  "main": "dist/index.js",
23
- "type": "commonjs",
23
+ "type": "module",
24
24
  "scripts": {
25
25
  "clear": "rimraf dist && rimraf coverage",
26
26
  "clear:nm": "rimraf node_modules && npm run clear",
27
27
  "lint": "eslint src/**/*.ts --quiet",
28
28
  "lint:verbose": "eslint src/**/*.ts",
29
- "asset": "node -r ts-node/register commands/assets.ts",
29
+ "asset": "node -r ts-node/register commands/assets.js",
30
30
  "build": "npm run clear && tsc && npm run asset",
31
31
  "test": "jest --config=jest.json --detectOpenHandles",
32
32
  "coverage": "rimraf coverage && jest --config=jest.json --coverage --coverageDirectory=coverage",
@@ -68,10 +68,8 @@
68
68
  }
69
69
  },
70
70
  "dependencies": {
71
- "@leyyo/common": "^1.2.4",
72
- "@leyyo/env": "^1.2.5",
73
- "@samet-it/be-base-common": "^1.1.5",
74
- "@samet-it/be-cache-common": "^1.1.10",
71
+ "@samet-it/be-base-common": "^1.3.4",
72
+ "@samet-it/be-cache-common": "^1.3.5",
75
73
  "redis": "^5.10.0"
76
74
  }
77
75
  }
File without changes