@unikvs/redis.node 0.0.0 → 0.0.14
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 +1 -43
- package/dist/index.d.ts +222 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +430 -0
- package/dist/index.js.map +1 -0
- package/package.json +41 -8
- package/src/errors.ts +161 -0
- package/src/index.ts +19 -0
- package/src/redis.ts +544 -0
package/src/errors.ts
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { type ErrorOptions, ErrorBase, setErrorMessage, InvalidUsageErrorBase } from "@unikvs/core";
|
|
2
|
+
|
|
3
|
+
export type { KeyNotFoundErrorArgs, KeyNotFoundErrorMeta } from "@unikvs/core";
|
|
4
|
+
export { KeyNotFoundError } from "@unikvs/core";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/redis-node#error-cluster-not-supported)
|
|
8
|
+
*/
|
|
9
|
+
export class ClusterNotSupportedError extends InvalidUsageErrorBase<undefined> {
|
|
10
|
+
static {
|
|
11
|
+
this.prototype.name = "RedisClusterNotSupportedError";
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/redis-node#error-cluster-not-supported)
|
|
16
|
+
*/
|
|
17
|
+
public constructor(options?: ErrorOptions) {
|
|
18
|
+
super(
|
|
19
|
+
"Redis storage v1 supports standalone mode only: the `cluster` option is not supported.",
|
|
20
|
+
options,
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
setErrorMessage(
|
|
26
|
+
ClusterNotSupportedError,
|
|
27
|
+
"Redis ストレージ v1 は standalone モードのみに対応します。`cluster` オプションはサポートされていません。",
|
|
28
|
+
"ja",
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/redis-node#error-invalid-close-timeout)
|
|
33
|
+
*/
|
|
34
|
+
export type InvalidCloseTimeoutErrorMeta = {
|
|
35
|
+
/**
|
|
36
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/redis-node#invalid-close-timeout-actual)
|
|
37
|
+
*/
|
|
38
|
+
readonly actual: unknown;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/redis-node#error-invalid-close-timeout)
|
|
43
|
+
*/
|
|
44
|
+
export type InvalidCloseTimeoutErrorArgs = ErrorOptions & InvalidCloseTimeoutErrorMeta;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/redis-node#error-invalid-close-timeout)
|
|
48
|
+
*/
|
|
49
|
+
export class InvalidCloseTimeoutError extends ErrorBase<InvalidCloseTimeoutErrorMeta> {
|
|
50
|
+
static {
|
|
51
|
+
this.prototype.name = "RedisInvalidCloseTimeoutError";
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/redis-node#error-invalid-close-timeout)
|
|
56
|
+
*/
|
|
57
|
+
public constructor(args: InvalidCloseTimeoutErrorArgs) {
|
|
58
|
+
const { actual, ...options } = args;
|
|
59
|
+
const meta: InvalidCloseTimeoutErrorMeta = { actual };
|
|
60
|
+
super(
|
|
61
|
+
meta,
|
|
62
|
+
({ actual: messageActual }) =>
|
|
63
|
+
`\`closeTimeout\` must be a finite positive number (ms), but got ${String(messageActual)}.`,
|
|
64
|
+
options,
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
setErrorMessage(
|
|
70
|
+
InvalidCloseTimeoutError,
|
|
71
|
+
({ actual }) =>
|
|
72
|
+
`\`closeTimeout\` は有限の正数 (ミリ秒) でなければなりません。受け取った値: ${String(actual)}`,
|
|
73
|
+
"ja",
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/redis-node#error-connect-timeout)
|
|
78
|
+
*/
|
|
79
|
+
export type ConnectTimeoutErrorMeta = {
|
|
80
|
+
/**
|
|
81
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/redis-node#connect-timeout-timeoutms)
|
|
82
|
+
*/
|
|
83
|
+
readonly timeoutMs: number;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/redis-node#error-connect-timeout)
|
|
88
|
+
*/
|
|
89
|
+
export type ConnectTimeoutErrorArgs = ErrorOptions & ConnectTimeoutErrorMeta;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/redis-node#error-connect-timeout)
|
|
93
|
+
*/
|
|
94
|
+
export class ConnectTimeoutError extends ErrorBase<ConnectTimeoutErrorMeta> {
|
|
95
|
+
static {
|
|
96
|
+
this.prototype.name = "RedisConnectTimeoutError";
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/redis-node#error-connect-timeout)
|
|
101
|
+
*/
|
|
102
|
+
public constructor(args: ConnectTimeoutErrorArgs) {
|
|
103
|
+
const { timeoutMs, ...options } = args;
|
|
104
|
+
const meta: ConnectTimeoutErrorMeta = { timeoutMs };
|
|
105
|
+
super(
|
|
106
|
+
meta,
|
|
107
|
+
({ timeoutMs: messageTimeoutMs }) =>
|
|
108
|
+
`Timed out connecting to Redis after ${messageTimeoutMs}ms`,
|
|
109
|
+
options,
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
setErrorMessage(
|
|
115
|
+
ConnectTimeoutError,
|
|
116
|
+
({ timeoutMs }) => `Redis への接続が ${timeoutMs}ms でタイムアウトしました`,
|
|
117
|
+
"ja",
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/redis-node#error-close-timeout)
|
|
122
|
+
*/
|
|
123
|
+
export type CloseTimeoutErrorMeta = {
|
|
124
|
+
/**
|
|
125
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/redis-node#close-timeout-timeoutms)
|
|
126
|
+
*/
|
|
127
|
+
readonly timeoutMs: number;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/redis-node#error-close-timeout)
|
|
132
|
+
*/
|
|
133
|
+
export type CloseTimeoutErrorArgs = ErrorOptions & CloseTimeoutErrorMeta;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/redis-node#error-close-timeout)
|
|
137
|
+
*/
|
|
138
|
+
export class CloseTimeoutError extends ErrorBase<CloseTimeoutErrorMeta> {
|
|
139
|
+
static {
|
|
140
|
+
this.prototype.name = "RedisCloseTimeoutError";
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/redis-node#error-close-timeout)
|
|
145
|
+
*/
|
|
146
|
+
public constructor(args: CloseTimeoutErrorArgs) {
|
|
147
|
+
const { timeoutMs, ...options } = args;
|
|
148
|
+
const meta: CloseTimeoutErrorMeta = { timeoutMs };
|
|
149
|
+
super(
|
|
150
|
+
meta,
|
|
151
|
+
({ timeoutMs: messageTimeoutMs }) => `Timed out closing Redis after ${messageTimeoutMs}ms`,
|
|
152
|
+
options,
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
setErrorMessage(
|
|
158
|
+
CloseTimeoutError,
|
|
159
|
+
({ timeoutMs }) => `Redis からの切断処理が ${timeoutMs}ms でタイムアウトしました`,
|
|
160
|
+
"ja",
|
|
161
|
+
);
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type {
|
|
2
|
+
KeyNotFoundErrorArgs,
|
|
3
|
+
KeyNotFoundErrorMeta,
|
|
4
|
+
CloseTimeoutErrorArgs,
|
|
5
|
+
CloseTimeoutErrorMeta,
|
|
6
|
+
ConnectTimeoutErrorArgs,
|
|
7
|
+
ConnectTimeoutErrorMeta,
|
|
8
|
+
InvalidCloseTimeoutErrorArgs,
|
|
9
|
+
InvalidCloseTimeoutErrorMeta,
|
|
10
|
+
} from "./errors.js";
|
|
11
|
+
export {
|
|
12
|
+
KeyNotFoundError,
|
|
13
|
+
CloseTimeoutError,
|
|
14
|
+
ConnectTimeoutError,
|
|
15
|
+
ClusterNotSupportedError,
|
|
16
|
+
InvalidCloseTimeoutError,
|
|
17
|
+
} from "./errors.js";
|
|
18
|
+
export type * from "./redis.js";
|
|
19
|
+
export { default as Redis } from "./redis.js";
|