@iobroker/db-base 4.0.21 → 4.1.0-alpha.0-20220819-74ceeddc
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/build/index.d.ts +4 -0
- package/build/index.js +10 -0
- package/build/lib/constants.d.ts +4 -0
- package/build/lib/constants.d.ts.map +1 -0
- package/build/lib/constants.js +11 -0
- package/build/lib/constants.js.map +1 -0
- package/build/lib/inMemFileDB.d.ts +130 -0
- package/build/lib/inMemFileDB.d.ts.map +1 -0
- package/{lib → build/lib}/inMemFileDB.js +119 -207
- package/build/lib/inMemFileDB.js.map +1 -0
- package/build/lib/redisHandler.d.ts +165 -0
- package/build/lib/redisHandler.d.ts.map +1 -0
- package/{lib → build/lib}/redisHandler.js +93 -145
- package/build/lib/redisHandler.js.map +1 -0
- package/package.json +24 -8
- package/index.js +0 -5
- package/lib/constants.js +0 -6
- package/lib/tools.js +0 -21
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
4
|
+
import type { Socket } from 'net';
|
|
5
|
+
import { EventEmitter } from 'events';
|
|
6
|
+
import type { InternalLogger } from '@iobroker/js-controller-common/tools';
|
|
7
|
+
declare type NestedArray<T> = T[] | NestedArray<T>[];
|
|
8
|
+
interface RedisHandlerOptions {
|
|
9
|
+
log: InternalLogger;
|
|
10
|
+
logScope?: string;
|
|
11
|
+
handleAsBuffers: boolean;
|
|
12
|
+
enhancedLogging?: boolean;
|
|
13
|
+
}
|
|
14
|
+
interface MultiCallElement {
|
|
15
|
+
responseIds: ResponseId[];
|
|
16
|
+
execCalled: boolean;
|
|
17
|
+
responseCount: number;
|
|
18
|
+
responseMap: Map<ResponseId, Buffer | null>;
|
|
19
|
+
execId?: ResponseId;
|
|
20
|
+
}
|
|
21
|
+
interface FullMultiCallElement extends MultiCallElement {
|
|
22
|
+
execId: ResponseId;
|
|
23
|
+
}
|
|
24
|
+
declare type ResponseId = number | null;
|
|
25
|
+
/**
|
|
26
|
+
* Class to handle a redis connection and provide events to react on for
|
|
27
|
+
* all incoming Redis commands
|
|
28
|
+
*/
|
|
29
|
+
export declare class RedisHandler extends EventEmitter {
|
|
30
|
+
private readonly socket;
|
|
31
|
+
private readonly logScope;
|
|
32
|
+
private readonly handleBuffers;
|
|
33
|
+
private readonly options;
|
|
34
|
+
private readonly log;
|
|
35
|
+
private readonly socketId;
|
|
36
|
+
private initialized;
|
|
37
|
+
private stop;
|
|
38
|
+
private readonly activeMultiCalls;
|
|
39
|
+
private readonly writeQueue;
|
|
40
|
+
private readonly resp;
|
|
41
|
+
/**
|
|
42
|
+
* Initialize and register all data handlers to send out events on new commands
|
|
43
|
+
* @param socket Network Socket/Connection
|
|
44
|
+
* @param options options objects, currently mainly for logger
|
|
45
|
+
*/
|
|
46
|
+
constructor(socket: Socket, options: RedisHandlerOptions);
|
|
47
|
+
/**
|
|
48
|
+
* Handle one incoming command, assign responseId and emit event to be handled
|
|
49
|
+
* @param data Array RESP data
|
|
50
|
+
* @private
|
|
51
|
+
*/
|
|
52
|
+
_handleCommand(data: any[]): void;
|
|
53
|
+
/**
|
|
54
|
+
* Check if the response to a certain command can be send out directly or
|
|
55
|
+
* if it needs to wait till earlier responses are ready
|
|
56
|
+
* @param responseId ID of the response
|
|
57
|
+
* @param data Buffer to send out
|
|
58
|
+
* @private
|
|
59
|
+
*/
|
|
60
|
+
_sendQueued(responseId: ResponseId, data: Buffer): void;
|
|
61
|
+
/**
|
|
62
|
+
* Really write out a response to the network connection
|
|
63
|
+
* @param data Buffer to send out
|
|
64
|
+
* @private
|
|
65
|
+
*/
|
|
66
|
+
_write(data: Buffer): void;
|
|
67
|
+
/**
|
|
68
|
+
* Guard to make sure a response is valid to be sent out
|
|
69
|
+
* @param responseId ID of the response
|
|
70
|
+
* @param data Buffer to send out
|
|
71
|
+
*/
|
|
72
|
+
sendResponse(responseId: ResponseId, data: Buffer): void;
|
|
73
|
+
/**
|
|
74
|
+
* Close network connection
|
|
75
|
+
*/
|
|
76
|
+
close(): void;
|
|
77
|
+
/**
|
|
78
|
+
* Return if socket/handler active or closed
|
|
79
|
+
* @returns is Handler/Connection active (not closed)
|
|
80
|
+
*/
|
|
81
|
+
isActive(): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Encode RESP's Null value to RESP buffer and send out
|
|
84
|
+
* @param responseId ID of the response
|
|
85
|
+
*/
|
|
86
|
+
sendNull(responseId: ResponseId): void;
|
|
87
|
+
/**
|
|
88
|
+
* Encode RESP's Null Array value to RESP buffer and send out
|
|
89
|
+
* @param responseId ID of the response
|
|
90
|
+
*/
|
|
91
|
+
sendNullArray(responseId: ResponseId): void;
|
|
92
|
+
/**
|
|
93
|
+
* Encode string to RESP buffer and send out
|
|
94
|
+
* @param responseId ID od the response
|
|
95
|
+
* @param str String to encode
|
|
96
|
+
*/
|
|
97
|
+
sendString(responseId: ResponseId, str: string): void;
|
|
98
|
+
/**
|
|
99
|
+
* Encode error object to RESP buffer and send out
|
|
100
|
+
* @param responseId ID of the response
|
|
101
|
+
* @param error Error object with error details to send out
|
|
102
|
+
*/
|
|
103
|
+
sendError(responseId: ResponseId, error: Error): void;
|
|
104
|
+
/**
|
|
105
|
+
* Encode integer to RESP buffer and send out
|
|
106
|
+
* @param responseId ID of the response
|
|
107
|
+
* @param num Integer to send out
|
|
108
|
+
*/
|
|
109
|
+
sendInteger(responseId: ResponseId, num: number): void;
|
|
110
|
+
/**
|
|
111
|
+
* Encode RESP's bulk string to RESP buffer and send out
|
|
112
|
+
* @param responseId ID of the response
|
|
113
|
+
* @param str String to send out
|
|
114
|
+
*/
|
|
115
|
+
sendBulk(responseId: ResponseId, str: string): void;
|
|
116
|
+
/**
|
|
117
|
+
* Encode RESP's bulk buffer to RESP buffer.
|
|
118
|
+
* @param responseId ID of the response
|
|
119
|
+
* @param buf Buffer to send out
|
|
120
|
+
*/
|
|
121
|
+
sendBufBulk(responseId: ResponseId, buf: Buffer): void;
|
|
122
|
+
/**
|
|
123
|
+
* Encode an Array depending on the type of the elements
|
|
124
|
+
* @param arr Array to encode
|
|
125
|
+
* @returns Array with Buffers with encoded values
|
|
126
|
+
*/
|
|
127
|
+
encodeRespArray(arr: unknown[]): NestedArray<Buffer>;
|
|
128
|
+
/**
|
|
129
|
+
* Encode a array values to buffers and send out
|
|
130
|
+
* @param responseId ID of the response
|
|
131
|
+
* @param arr Array to send out
|
|
132
|
+
*/
|
|
133
|
+
sendArray(responseId: ResponseId, arr: any[]): void;
|
|
134
|
+
/**
|
|
135
|
+
* Handles a 'multi' command
|
|
136
|
+
*
|
|
137
|
+
* @private
|
|
138
|
+
*/
|
|
139
|
+
_handleMulti(): void;
|
|
140
|
+
/**
|
|
141
|
+
* Handles an 'exec' command
|
|
142
|
+
*
|
|
143
|
+
* @param {number} responseId ID of the response
|
|
144
|
+
* @private
|
|
145
|
+
*/
|
|
146
|
+
_handleExec(responseId: ResponseId): void;
|
|
147
|
+
/**
|
|
148
|
+
* Builds up the exec response and sends it
|
|
149
|
+
* @param multiObj the multi object to send out
|
|
150
|
+
*
|
|
151
|
+
* @private
|
|
152
|
+
*/
|
|
153
|
+
_sendExecResponse(multiObj: FullMultiCallElement): void;
|
|
154
|
+
/**
|
|
155
|
+
* Handles a multi response
|
|
156
|
+
*
|
|
157
|
+
* @param responseId ID of the response
|
|
158
|
+
* @param index index of the multi call
|
|
159
|
+
* @param buf buffer to include in response
|
|
160
|
+
* @private
|
|
161
|
+
*/
|
|
162
|
+
_handleMultiResponse(responseId: ResponseId, index: number, buf: Buffer): void;
|
|
163
|
+
}
|
|
164
|
+
export {};
|
|
165
|
+
//# sourceMappingURL=redisHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redisHandler.d.ts","sourceRoot":"","sources":["../../src/lib/redisHandler.ts"],"names":[],"mappings":";;;AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,KAAK,CA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