unikvs 0.0.12 → 0.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.
- package/README.md +2 -2
- package/dist/index.d.ts +1553 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4032 -0
- package/dist/index.js.map +1 -0
- package/package.json +34 -34
- package/src/_contexts.ts +1089 -0
- package/src/_logger.ts +5 -3
- package/src/_middleware.ts +207 -0
- package/src/_pipeline-graph.helpers.ts +183 -0
- package/src/_pipeline-graph.ts +1307 -0
- package/src/_pipeline-graph.types.ts +303 -0
- package/src/_pipeline-leaf-resolver.ts +70 -0
- package/src/_plugin-lifecycle.ts +201 -0
- package/src/_storage.ts +169 -115
- package/src/_streams.schemas.ts +21 -0
- package/src/_streams.ts +32 -6
- package/src/_to-value-stream.ts +22 -11
- package/src/_types.ts +237 -0
- package/src/_unikvs-branch.ts +94 -0
- package/src/_unikvs.schemas.ts +451 -0
- package/src/_valibot.ts +17 -6
- package/src/_value-schemas.ts +36 -206
- package/src/_value-validation.ts +57 -0
- package/src/errors.ts +391 -148
- package/src/index.ts +46 -25
- package/src/{value-stream.types.ts → types.ts} +1 -1
- package/src/unikvs-branch.ts +445 -0
- package/src/unikvs-builder.ts +706 -0
- package/src/unikvs.ts +1423 -1007
- package/src/unikvs.types.ts +194 -0
- package/src/value-schemas.ts +98 -0
- package/dist/src/_logger.d.ts +0 -3
- package/dist/src/_logger.d.ts.map +0 -1
- package/dist/src/_logger.js +0 -3
- package/dist/src/_merge-variables.d.ts +0 -13
- package/dist/src/_merge-variables.d.ts.map +0 -1
- package/dist/src/_merge-variables.js +0 -12
- package/dist/src/_storage.d.ts +0 -18
- package/dist/src/_storage.d.ts.map +0 -1
- package/dist/src/_storage.js +0 -103
- package/dist/src/_streams.d.ts +0 -20
- package/dist/src/_streams.d.ts.map +0 -1
- package/dist/src/_streams.js +0 -36
- package/dist/src/_to-value-stream.d.ts +0 -12
- package/dist/src/_to-value-stream.d.ts.map +0 -1
- package/dist/src/_to-value-stream.js +0 -102
- package/dist/src/_transformer.d.ts +0 -13
- package/dist/src/_transformer.d.ts.map +0 -1
- package/dist/src/_transformer.js +0 -60
- package/dist/src/_valibot.d.ts +0 -15
- package/dist/src/_valibot.d.ts.map +0 -1
- package/dist/src/_valibot.js +0 -23
- package/dist/src/_value-schemas.d.ts +0 -179
- package/dist/src/_value-schemas.d.ts.map +0 -1
- package/dist/src/_value-schemas.js +0 -150
- package/dist/src/errors.d.ts +0 -306
- package/dist/src/errors.d.ts.map +0 -1
- package/dist/src/errors.js +0 -234
- package/dist/src/index.d.ts +0 -10
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -3
- package/dist/src/unikvs-config.d.ts +0 -174
- package/dist/src/unikvs-config.d.ts.map +0 -1
- package/dist/src/unikvs-config.js +0 -100
- package/dist/src/unikvs.d.ts +0 -272
- package/dist/src/unikvs.d.ts.map +0 -1
- package/dist/src/unikvs.js +0 -928
- package/dist/src/utils.types.d.ts +0 -5
- package/dist/src/utils.types.d.ts.map +0 -1
- package/dist/src/utils.types.js +0 -1
- package/dist/src/value-stream.types.d.ts +0 -10
- package/dist/src/value-stream.types.d.ts.map +0 -1
- package/dist/src/value-stream.types.js +0 -1
- package/dist/src/variables.types.d.ts +0 -11
- package/dist/src/variables.types.d.ts.map +0 -1
- package/dist/src/variables.types.js +0 -1
- package/src/_merge-variables.ts +0 -19
- package/src/_transformer.ts +0 -89
- package/src/unikvs-config.ts +0 -401
- package/src/utils.types.ts +0 -4
- package/src/variables.types.ts +0 -13
package/src/errors.ts
CHANGED
|
@@ -1,26 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
|
-
setErrorMessage,
|
|
3
|
-
ErrorBase,
|
|
4
2
|
type ErrorOptions,
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
ErrorBase,
|
|
4
|
+
setErrorMessage,
|
|
5
|
+
KeyNotFoundError,
|
|
6
|
+
InvalidUsageErrorBase,
|
|
7
7
|
} from "@unikvs/core";
|
|
8
8
|
import type { BaseIssue } from "valibot";
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// 境界エラー
|
|
13
|
-
//
|
|
14
|
-
// -------------------------------------------------------------------------------------------------
|
|
10
|
+
export { KeyNotFoundError, InvalidUsageErrorBase };
|
|
11
|
+
export type { KeyNotFoundErrorArgs, KeyNotFoundErrorMeta } from "@unikvs/core";
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
18
|
-
*/
|
|
19
|
-
export class InvalidUsageErrorBase<
|
|
20
|
-
TMeta extends ErrorMeta | undefined = ErrorMeta | undefined,
|
|
21
|
-
> extends ErrorBase<TMeta> {}
|
|
22
|
-
|
|
23
|
-
// -------------------------------------------------------------------------------------------------
|
|
13
|
+
// -------------------------------------------------------------------------------------------------。
|
|
24
14
|
|
|
25
15
|
/**
|
|
26
16
|
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
@@ -67,12 +57,19 @@ export class InvalidInputError extends InvalidUsageErrorBase<InvalidInputErrorMe
|
|
|
67
57
|
|
|
68
58
|
public constructor(args: InvalidInputErrorArgs) {
|
|
69
59
|
const { value: input, issues, ...options } = args;
|
|
70
|
-
const meta: InvalidInputErrorMeta = {
|
|
71
|
-
|
|
60
|
+
const meta: InvalidInputErrorMeta = {
|
|
61
|
+
input,
|
|
62
|
+
issues,
|
|
63
|
+
};
|
|
64
|
+
super(
|
|
65
|
+
meta,
|
|
66
|
+
({ issues: messageIssues }) => messageIssues.map((i) => i.message).join(": "),
|
|
67
|
+
options,
|
|
68
|
+
);
|
|
72
69
|
}
|
|
73
70
|
}
|
|
74
71
|
|
|
75
|
-
//
|
|
72
|
+
// -------------------------------------------------------------------------------------------------。
|
|
76
73
|
|
|
77
74
|
/**
|
|
78
75
|
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
@@ -114,16 +111,23 @@ export class InvalidOutputError extends InvalidUsageErrorBase<InvalidOutputError
|
|
|
114
111
|
|
|
115
112
|
public constructor(args: InvalidOutputErrorArgs) {
|
|
116
113
|
const { value: output, issues, ...options } = args;
|
|
117
|
-
const meta: InvalidOutputErrorMeta = {
|
|
118
|
-
|
|
114
|
+
const meta: InvalidOutputErrorMeta = {
|
|
115
|
+
issues,
|
|
116
|
+
output,
|
|
117
|
+
};
|
|
118
|
+
super(
|
|
119
|
+
meta,
|
|
120
|
+
({ issues: messageIssues }) => messageIssues.map((i) => i.message).join(": "),
|
|
121
|
+
options,
|
|
122
|
+
);
|
|
119
123
|
}
|
|
120
124
|
}
|
|
121
125
|
|
|
122
|
-
//
|
|
126
|
+
// -------------------------------------------------------------------------------------------------。
|
|
123
127
|
//
|
|
124
|
-
// UniKvs
|
|
128
|
+
// UniKvs。
|
|
125
129
|
//
|
|
126
|
-
//
|
|
130
|
+
// -------------------------------------------------------------------------------------------------。
|
|
127
131
|
|
|
128
132
|
/**
|
|
129
133
|
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
@@ -155,65 +159,11 @@ export class UniKvsIsNotOpenError extends ErrorBase<undefined> {
|
|
|
155
159
|
|
|
156
160
|
setErrorMessage(UniKvsIsNotOpenError, "UniKvs は開いていません", "ja");
|
|
157
161
|
|
|
158
|
-
|
|
159
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
160
|
-
*/
|
|
161
|
-
export type KeyNotFoundErrorMeta = {
|
|
162
|
-
/**
|
|
163
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
164
|
-
*/
|
|
165
|
-
readonly key: IStorage.Key;
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
170
|
-
*/
|
|
171
|
-
export type KeyNotFoundErrorArgs = ErrorOptions & KeyNotFoundErrorMeta;
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
175
|
-
*/
|
|
176
|
-
export class KeyNotFoundError extends ErrorBase<KeyNotFoundErrorMeta> {
|
|
177
|
-
static {
|
|
178
|
-
this.prototype.name = "UniKvsKeyNotFoundError";
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
public constructor(args: KeyNotFoundErrorArgs) {
|
|
182
|
-
const { key, ...options } = args;
|
|
183
|
-
const meta: KeyNotFoundErrorMeta = { key };
|
|
184
|
-
super(meta, ({ key }) => `IStorage.Key ${JSON.stringify(key)} not found`, options);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
setErrorMessage(
|
|
189
|
-
KeyNotFoundError,
|
|
190
|
-
({ key }) => `キー ${JSON.stringify(key)} が見つかりません`,
|
|
191
|
-
"ja",
|
|
192
|
-
);
|
|
193
|
-
|
|
194
|
-
// -------------------------------------------------------------------------------------------------
|
|
162
|
+
// -------------------------------------------------------------------------------------------------。
|
|
195
163
|
//
|
|
196
|
-
//
|
|
164
|
+
// ストレージ。
|
|
197
165
|
//
|
|
198
|
-
//
|
|
199
|
-
|
|
200
|
-
// export type StorageIsOpenErrorMeta = {
|
|
201
|
-
// readonly name: string;
|
|
202
|
-
// };
|
|
203
|
-
|
|
204
|
-
// export type StorageIsOpenErrorArgs = StorageIsOpenErrorMeta;
|
|
205
|
-
|
|
206
|
-
// export class StorageIsOpenError extends ErrorBase<StorageIsOpenErrorMeta> {
|
|
207
|
-
// static {
|
|
208
|
-
// this.prototype.name = "UniKvsStorageIsOpenError";
|
|
209
|
-
// }
|
|
210
|
-
|
|
211
|
-
// public constructor(args: StorageIsOpenErrorArgs, options?: ErrorOptions) {
|
|
212
|
-
// super(args, ({ name }) => `Storage "${name}" is open`, options);
|
|
213
|
-
// }
|
|
214
|
-
// }
|
|
215
|
-
|
|
216
|
-
// setErrorMessage(StorageIsOpenError, ({ name }) => `ストレージ "${name}" は開いています`, "ja");
|
|
166
|
+
// -------------------------------------------------------------------------------------------------。
|
|
217
167
|
|
|
218
168
|
/**
|
|
219
169
|
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
@@ -241,7 +191,7 @@ export class StorageIsNotOpenError extends ErrorBase<StorageIsNotOpenErrorMeta>
|
|
|
241
191
|
public constructor(args: StorageIsNotOpenErrorArgs) {
|
|
242
192
|
const { name, ...options } = args;
|
|
243
193
|
const meta: StorageIsNotOpenErrorMeta = { name };
|
|
244
|
-
super(meta, ({ name }) => `Storage "${
|
|
194
|
+
super(meta, ({ name: messageName }) => `Storage "${messageName}" is not open`, options);
|
|
245
195
|
}
|
|
246
196
|
}
|
|
247
197
|
|
|
@@ -274,7 +224,11 @@ export class WritableStreamNotSupportedError extends ErrorBase<WritableStreamNot
|
|
|
274
224
|
public constructor(args: WritableStreamNotSupportedErrorArgs) {
|
|
275
225
|
const { name, ...options } = args;
|
|
276
226
|
const meta: WritableStreamNotSupportedErrorMeta = { name };
|
|
277
|
-
super(
|
|
227
|
+
super(
|
|
228
|
+
meta,
|
|
229
|
+
({ name: messageName }) => `Storage "${messageName}" does not support writable stream`,
|
|
230
|
+
options,
|
|
231
|
+
);
|
|
278
232
|
}
|
|
279
233
|
}
|
|
280
234
|
|
|
@@ -311,7 +265,11 @@ export class ReadableStreamNotSupportedError extends ErrorBase<ReadableStreamNot
|
|
|
311
265
|
public constructor(args: ReadableStreamNotSupportedErrorArgs) {
|
|
312
266
|
const { name, ...options } = args;
|
|
313
267
|
const meta: ReadableStreamNotSupportedErrorMeta = { name };
|
|
314
|
-
super(
|
|
268
|
+
super(
|
|
269
|
+
meta,
|
|
270
|
+
({ name: messageName }) => `Storage "${messageName}" does not support readable stream`,
|
|
271
|
+
options,
|
|
272
|
+
);
|
|
315
273
|
}
|
|
316
274
|
}
|
|
317
275
|
|
|
@@ -350,7 +308,11 @@ export class MultipartWriteNotSupportedError extends ErrorBase<MultipartWriteNot
|
|
|
350
308
|
public constructor(args: MultipartWriteNotSupportedErrorArgs) {
|
|
351
309
|
const { name, ...options } = args;
|
|
352
310
|
const meta: MultipartWriteNotSupportedErrorMeta = { name };
|
|
353
|
-
super(
|
|
311
|
+
super(
|
|
312
|
+
meta,
|
|
313
|
+
({ name: messageName }) => `Storage "${messageName}" does not support multipart-write`,
|
|
314
|
+
options,
|
|
315
|
+
);
|
|
354
316
|
}
|
|
355
317
|
}
|
|
356
318
|
|
|
@@ -360,107 +322,344 @@ setErrorMessage(
|
|
|
360
322
|
"ja",
|
|
361
323
|
);
|
|
362
324
|
|
|
363
|
-
//
|
|
325
|
+
// -------------------------------------------------------------------------------------------------。
|
|
364
326
|
//
|
|
365
|
-
//
|
|
327
|
+
// ミドルウェア。
|
|
366
328
|
//
|
|
367
|
-
//
|
|
329
|
+
// -------------------------------------------------------------------------------------------------。
|
|
368
330
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
331
|
+
/**
|
|
332
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
333
|
+
*/
|
|
334
|
+
export type MiddlewareIsNotOpenErrorMeta = {
|
|
335
|
+
/**
|
|
336
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
337
|
+
*/
|
|
338
|
+
readonly name: string;
|
|
339
|
+
};
|
|
372
340
|
|
|
373
|
-
|
|
341
|
+
/**
|
|
342
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
343
|
+
*/
|
|
344
|
+
export type MiddlewareIsNotOpenErrorArgs = ErrorOptions & MiddlewareIsNotOpenErrorMeta;
|
|
374
345
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
346
|
+
/**
|
|
347
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
348
|
+
*/
|
|
349
|
+
export class MiddlewareIsNotOpenError extends ErrorBase<MiddlewareIsNotOpenErrorMeta> {
|
|
350
|
+
static {
|
|
351
|
+
this.prototype.name = "UniKvsMiddlewareIsNotOpenError";
|
|
352
|
+
}
|
|
379
353
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
354
|
+
public constructor(args: MiddlewareIsNotOpenErrorArgs) {
|
|
355
|
+
const { name, ...options } = args;
|
|
356
|
+
const meta: MiddlewareIsNotOpenErrorMeta = { name };
|
|
357
|
+
super(meta, ({ name: messageName }) => `Middleware "${messageName}" is not open`, options);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
384
360
|
|
|
385
|
-
|
|
361
|
+
setErrorMessage(
|
|
362
|
+
MiddlewareIsNotOpenError,
|
|
363
|
+
({ name }) => `ミドルウェア "${name}" は開いていません`,
|
|
364
|
+
"ja",
|
|
365
|
+
);
|
|
386
366
|
|
|
387
367
|
/**
|
|
388
368
|
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
389
369
|
*/
|
|
390
|
-
export type
|
|
370
|
+
export type MiddlewareDestinationMissingErrorMeta = {
|
|
391
371
|
/**
|
|
392
372
|
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
393
373
|
*/
|
|
394
374
|
readonly name: string;
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
378
|
+
*/
|
|
379
|
+
readonly operation: "encode" | "decode";
|
|
395
380
|
};
|
|
396
381
|
|
|
397
382
|
/**
|
|
398
383
|
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
399
384
|
*/
|
|
400
|
-
export type
|
|
385
|
+
export type MiddlewareDestinationMissingErrorArgs = ErrorOptions &
|
|
386
|
+
MiddlewareDestinationMissingErrorMeta;
|
|
401
387
|
|
|
402
388
|
/**
|
|
403
389
|
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
404
390
|
*/
|
|
405
|
-
export class
|
|
391
|
+
export class MiddlewareDestinationMissingError extends ErrorBase<MiddlewareDestinationMissingErrorMeta> {
|
|
406
392
|
static {
|
|
407
|
-
this.prototype.name = "
|
|
393
|
+
this.prototype.name = "UniKvsMiddlewareDestinationMissingError";
|
|
408
394
|
}
|
|
409
395
|
|
|
410
|
-
public constructor(args:
|
|
411
|
-
const { name, ...options } = args;
|
|
412
|
-
const meta:
|
|
413
|
-
|
|
396
|
+
public constructor(args: MiddlewareDestinationMissingErrorArgs) {
|
|
397
|
+
const { name, operation, ...options } = args;
|
|
398
|
+
const meta: MiddlewareDestinationMissingErrorMeta = {
|
|
399
|
+
name,
|
|
400
|
+
operation,
|
|
401
|
+
};
|
|
402
|
+
super(
|
|
403
|
+
meta,
|
|
404
|
+
({ name: messageName, operation: messageOperation }) =>
|
|
405
|
+
`Middleware "${messageName}" did not set destination for ${messageOperation}.`,
|
|
406
|
+
options,
|
|
407
|
+
);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
setErrorMessage(
|
|
412
|
+
MiddlewareDestinationMissingError,
|
|
413
|
+
({ name, operation }) =>
|
|
414
|
+
`ミドルウェア "${name}" は ${operation} の destination を設定しませんでした。`,
|
|
415
|
+
"ja",
|
|
416
|
+
);
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
420
|
+
*/
|
|
421
|
+
export type MiddlewareDestinationFrozenErrorMeta = {
|
|
422
|
+
/**
|
|
423
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
424
|
+
*/
|
|
425
|
+
readonly action: "set" | "get" | "stream";
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
429
|
+
*/
|
|
430
|
+
readonly key: string;
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
435
|
+
*/
|
|
436
|
+
export type MiddlewareDestinationFrozenErrorArgs = ErrorOptions &
|
|
437
|
+
MiddlewareDestinationFrozenErrorMeta;
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
441
|
+
*/
|
|
442
|
+
export class MiddlewareDestinationFrozenError extends ErrorBase<MiddlewareDestinationFrozenErrorMeta> {
|
|
443
|
+
static {
|
|
444
|
+
this.prototype.name = "UniKvsMiddlewareDestinationFrozenError";
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
public constructor(args: MiddlewareDestinationFrozenErrorArgs) {
|
|
448
|
+
const { key, action, ...options } = args;
|
|
449
|
+
const meta: MiddlewareDestinationFrozenErrorMeta = {
|
|
450
|
+
key,
|
|
451
|
+
action,
|
|
452
|
+
};
|
|
453
|
+
super(
|
|
454
|
+
meta,
|
|
455
|
+
({ key: messageKey, action: messageAction }) =>
|
|
456
|
+
`Cannot set destination after next() was called for ${messageAction} operation on key ${JSON.stringify(messageKey)}.`,
|
|
457
|
+
options,
|
|
458
|
+
);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
setErrorMessage(
|
|
463
|
+
MiddlewareDestinationFrozenError,
|
|
464
|
+
({ key: messageKey, action: messageAction }) =>
|
|
465
|
+
`next() を呼び出した後に destination を設定できません(${messageAction} 操作、キー ${JSON.stringify(messageKey)})。`,
|
|
466
|
+
"ja",
|
|
467
|
+
);
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
471
|
+
*/
|
|
472
|
+
export type MiddlewareNextNotCalledErrorMeta = {
|
|
473
|
+
/**
|
|
474
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
475
|
+
*/
|
|
476
|
+
readonly name: string;
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
480
|
+
*/
|
|
481
|
+
readonly operation: "encode" | "decode" | "use";
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
486
|
+
*/
|
|
487
|
+
export type MiddlewareNextNotCalledErrorArgs = ErrorOptions & MiddlewareNextNotCalledErrorMeta;
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
491
|
+
*/
|
|
492
|
+
export class MiddlewareNextNotCalledError extends ErrorBase<MiddlewareNextNotCalledErrorMeta> {
|
|
493
|
+
static {
|
|
494
|
+
this.prototype.name = "UniKvsMiddlewareNextNotCalledError";
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
public constructor(args: MiddlewareNextNotCalledErrorArgs) {
|
|
498
|
+
const { name, operation, ...options } = args;
|
|
499
|
+
const meta: MiddlewareNextNotCalledErrorMeta = {
|
|
500
|
+
name,
|
|
501
|
+
operation,
|
|
502
|
+
};
|
|
503
|
+
super(
|
|
504
|
+
meta,
|
|
505
|
+
({ name: messageName, operation: messageOperation }) =>
|
|
506
|
+
`Middleware "${messageName}" did not call next() for ${messageOperation}.`,
|
|
507
|
+
options,
|
|
508
|
+
);
|
|
414
509
|
}
|
|
415
510
|
}
|
|
416
511
|
|
|
417
512
|
setErrorMessage(
|
|
418
|
-
|
|
419
|
-
({ name }) =>
|
|
513
|
+
MiddlewareNextNotCalledError,
|
|
514
|
+
({ name, operation }) => `ミドルウェア "${name}" は ${operation} で next() を呼びませんでした。`,
|
|
420
515
|
"ja",
|
|
421
516
|
);
|
|
422
517
|
|
|
423
518
|
/**
|
|
424
519
|
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
425
520
|
*/
|
|
426
|
-
export type
|
|
521
|
+
export type MiddlewareNextNotAwaitedErrorMeta = {
|
|
427
522
|
/**
|
|
428
523
|
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
429
524
|
*/
|
|
430
525
|
readonly name: string;
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
529
|
+
*/
|
|
530
|
+
readonly operation: "encode" | "decode" | "use";
|
|
431
531
|
};
|
|
432
532
|
|
|
433
533
|
/**
|
|
434
534
|
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
435
535
|
*/
|
|
436
|
-
export type
|
|
437
|
-
EncodableStreamNotSupportedErrorMeta;
|
|
536
|
+
export type MiddlewareNextNotAwaitedErrorArgs = ErrorOptions & MiddlewareNextNotAwaitedErrorMeta;
|
|
438
537
|
|
|
439
538
|
/**
|
|
440
539
|
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
441
540
|
*/
|
|
442
|
-
export class
|
|
541
|
+
export class MiddlewareNextNotAwaitedError extends ErrorBase<MiddlewareNextNotAwaitedErrorMeta> {
|
|
443
542
|
static {
|
|
444
|
-
this.prototype.name = "
|
|
543
|
+
this.prototype.name = "UniKvsMiddlewareNextNotAwaitedError";
|
|
445
544
|
}
|
|
446
545
|
|
|
447
|
-
public constructor(args:
|
|
546
|
+
public constructor(args: MiddlewareNextNotAwaitedErrorArgs) {
|
|
547
|
+
const { name, operation, ...options } = args;
|
|
548
|
+
const meta: MiddlewareNextNotAwaitedErrorMeta = {
|
|
549
|
+
name,
|
|
550
|
+
operation,
|
|
551
|
+
};
|
|
552
|
+
super(
|
|
553
|
+
meta,
|
|
554
|
+
({ name: messageName, operation: messageOperation }) =>
|
|
555
|
+
`Middleware "${messageName}" did not await next() for ${messageOperation}.`,
|
|
556
|
+
options,
|
|
557
|
+
);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
setErrorMessage(
|
|
562
|
+
MiddlewareNextNotAwaitedError,
|
|
563
|
+
({ name, operation }) =>
|
|
564
|
+
`ミドルウェア "${name}" は ${operation} で next() を await しませんでした。`,
|
|
565
|
+
"ja",
|
|
566
|
+
);
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
570
|
+
*/
|
|
571
|
+
export type MiddlewareNextCalledMultipleTimesErrorMeta = {
|
|
572
|
+
/**
|
|
573
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
574
|
+
*/
|
|
575
|
+
readonly name: string;
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
579
|
+
*/
|
|
580
|
+
readonly operation: "encode" | "decode" | "use";
|
|
581
|
+
};
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
585
|
+
*/
|
|
586
|
+
export type MiddlewareNextCalledMultipleTimesErrorArgs = ErrorOptions &
|
|
587
|
+
MiddlewareNextCalledMultipleTimesErrorMeta;
|
|
588
|
+
|
|
589
|
+
/**
|
|
590
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
591
|
+
*/
|
|
592
|
+
export class MiddlewareNextCalledMultipleTimesError extends ErrorBase<MiddlewareNextCalledMultipleTimesErrorMeta> {
|
|
593
|
+
static {
|
|
594
|
+
this.prototype.name = "UniKvsMiddlewareNextCalledMultipleTimesError";
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
public constructor(args: MiddlewareNextCalledMultipleTimesErrorArgs) {
|
|
598
|
+
const { name, operation, ...options } = args;
|
|
599
|
+
const meta: MiddlewareNextCalledMultipleTimesErrorMeta = {
|
|
600
|
+
name,
|
|
601
|
+
operation,
|
|
602
|
+
};
|
|
603
|
+
super(
|
|
604
|
+
meta,
|
|
605
|
+
({ name: messageName, operation: messageOperation }) =>
|
|
606
|
+
`Middleware "${messageName}" called next() multiple times for ${messageOperation}.`,
|
|
607
|
+
options,
|
|
608
|
+
);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
setErrorMessage(
|
|
613
|
+
MiddlewareNextCalledMultipleTimesError,
|
|
614
|
+
({ name, operation }) => `ミドルウェア "${name}" は ${operation} で next() を複数回呼びました。`,
|
|
615
|
+
"ja",
|
|
616
|
+
);
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
620
|
+
*/
|
|
621
|
+
export type StreamEncodingNotSupportedErrorMeta = {
|
|
622
|
+
/**
|
|
623
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
624
|
+
*/
|
|
625
|
+
readonly name: string;
|
|
626
|
+
};
|
|
627
|
+
|
|
628
|
+
/**
|
|
629
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
630
|
+
*/
|
|
631
|
+
export type StreamEncodingNotSupportedErrorArgs = ErrorOptions &
|
|
632
|
+
StreamEncodingNotSupportedErrorMeta;
|
|
633
|
+
|
|
634
|
+
/**
|
|
635
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
636
|
+
*/
|
|
637
|
+
export class StreamEncodingNotSupportedError extends ErrorBase<StreamEncodingNotSupportedErrorMeta> {
|
|
638
|
+
static {
|
|
639
|
+
this.prototype.name = "UniKvsStreamEncodingNotSupportedError";
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
public constructor(args: StreamEncodingNotSupportedErrorArgs) {
|
|
448
643
|
const { name, ...options } = args;
|
|
449
|
-
const meta:
|
|
450
|
-
super(
|
|
644
|
+
const meta: StreamEncodingNotSupportedErrorMeta = { name };
|
|
645
|
+
super(
|
|
646
|
+
meta,
|
|
647
|
+
({ name: messageName }) => `Middleware "${messageName}" does not support stream encoding.`,
|
|
648
|
+
options,
|
|
649
|
+
);
|
|
451
650
|
}
|
|
452
651
|
}
|
|
453
652
|
|
|
454
653
|
setErrorMessage(
|
|
455
|
-
|
|
456
|
-
({ name }) =>
|
|
654
|
+
StreamEncodingNotSupportedError,
|
|
655
|
+
({ name }) => `ミドルウェア "${name}" はストリームのエンコードをサポートしていません。`,
|
|
457
656
|
"ja",
|
|
458
657
|
);
|
|
459
658
|
|
|
460
659
|
/**
|
|
461
660
|
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
462
661
|
*/
|
|
463
|
-
export type
|
|
662
|
+
export type StreamDecodingNotSupportedErrorMeta = {
|
|
464
663
|
/**
|
|
465
664
|
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
466
665
|
*/
|
|
@@ -470,35 +669,39 @@ export type DecodableStreamNotSupportedErrorMeta = {
|
|
|
470
669
|
/**
|
|
471
670
|
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
472
671
|
*/
|
|
473
|
-
export type
|
|
474
|
-
|
|
672
|
+
export type StreamDecodingNotSupportedErrorArgs = ErrorOptions &
|
|
673
|
+
StreamDecodingNotSupportedErrorMeta;
|
|
475
674
|
|
|
476
675
|
/**
|
|
477
676
|
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
478
677
|
*/
|
|
479
|
-
export class
|
|
678
|
+
export class StreamDecodingNotSupportedError extends ErrorBase<StreamDecodingNotSupportedErrorMeta> {
|
|
480
679
|
static {
|
|
481
|
-
this.prototype.name = "
|
|
680
|
+
this.prototype.name = "UniKvsStreamDecodingNotSupportedError";
|
|
482
681
|
}
|
|
483
682
|
|
|
484
|
-
public constructor(args:
|
|
683
|
+
public constructor(args: StreamDecodingNotSupportedErrorArgs) {
|
|
485
684
|
const { name, ...options } = args;
|
|
486
|
-
const meta:
|
|
487
|
-
super(
|
|
685
|
+
const meta: StreamDecodingNotSupportedErrorMeta = { name };
|
|
686
|
+
super(
|
|
687
|
+
meta,
|
|
688
|
+
({ name: messageName }) => `Middleware "${messageName}" does not support decodable stream`,
|
|
689
|
+
options,
|
|
690
|
+
);
|
|
488
691
|
}
|
|
489
692
|
}
|
|
490
693
|
|
|
491
694
|
setErrorMessage(
|
|
492
|
-
|
|
493
|
-
({ name }) =>
|
|
695
|
+
StreamDecodingNotSupportedError,
|
|
696
|
+
({ name }) => `ミドルウェア "${name}" はデコード可能なストリームをサポートしていません`,
|
|
494
697
|
"ja",
|
|
495
698
|
);
|
|
496
699
|
|
|
497
|
-
//
|
|
700
|
+
// -------------------------------------------------------------------------------------------------。
|
|
498
701
|
//
|
|
499
|
-
// ストレージ /
|
|
702
|
+
// ストレージ / ミドルウェア。
|
|
500
703
|
//
|
|
501
|
-
//
|
|
704
|
+
// -------------------------------------------------------------------------------------------------。
|
|
502
705
|
|
|
503
706
|
/**
|
|
504
707
|
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
@@ -507,7 +710,7 @@ export type PluginOperationAggregateErrorMeta = {
|
|
|
507
710
|
/**
|
|
508
711
|
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
509
712
|
*/
|
|
510
|
-
readonly plugin: "plugin" | "storage" | "
|
|
713
|
+
readonly plugin: "plugin" | "storage" | "middleware";
|
|
511
714
|
|
|
512
715
|
/**
|
|
513
716
|
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
@@ -521,7 +724,17 @@ export type PluginOperationAggregateErrorMeta = {
|
|
|
521
724
|
/**
|
|
522
725
|
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
523
726
|
*/
|
|
524
|
-
readonly plugin: "storage" | "
|
|
727
|
+
readonly plugin: "storage" | "middleware";
|
|
728
|
+
|
|
729
|
+
/**
|
|
730
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
731
|
+
*/
|
|
732
|
+
readonly name?: string;
|
|
733
|
+
|
|
734
|
+
/**
|
|
735
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
736
|
+
*/
|
|
737
|
+
readonly index?: number;
|
|
525
738
|
|
|
526
739
|
/**
|
|
527
740
|
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
@@ -537,7 +750,7 @@ export type PluginOperationAggregateErrorArgs = ErrorOptions & {
|
|
|
537
750
|
/**
|
|
538
751
|
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
539
752
|
*/
|
|
540
|
-
readonly plugin?: "storage" | "
|
|
753
|
+
readonly plugin?: "storage" | "middleware";
|
|
541
754
|
|
|
542
755
|
/**
|
|
543
756
|
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
@@ -551,7 +764,17 @@ export type PluginOperationAggregateErrorArgs = ErrorOptions & {
|
|
|
551
764
|
/**
|
|
552
765
|
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
553
766
|
*/
|
|
554
|
-
readonly plugin?: "storage" | "
|
|
767
|
+
readonly plugin?: "storage" | "middleware";
|
|
768
|
+
|
|
769
|
+
/**
|
|
770
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
771
|
+
*/
|
|
772
|
+
readonly name?: string;
|
|
773
|
+
|
|
774
|
+
/**
|
|
775
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
776
|
+
*/
|
|
777
|
+
readonly index?: number;
|
|
555
778
|
|
|
556
779
|
/**
|
|
557
780
|
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
@@ -560,6 +783,17 @@ export type PluginOperationAggregateErrorArgs = ErrorOptions & {
|
|
|
560
783
|
}[];
|
|
561
784
|
};
|
|
562
785
|
|
|
786
|
+
/**
|
|
787
|
+
* プラグイン種別を正規化します。
|
|
788
|
+
*
|
|
789
|
+
* @param plugin 種別名です。
|
|
790
|
+
*
|
|
791
|
+
* @returns 正規化された種別を返します。
|
|
792
|
+
*/
|
|
793
|
+
function normalizePlugin(plugin: string): "storage" | "middleware" {
|
|
794
|
+
return plugin as "storage" | "middleware";
|
|
795
|
+
}
|
|
796
|
+
|
|
563
797
|
/**
|
|
564
798
|
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|
|
565
799
|
*/
|
|
@@ -569,21 +803,24 @@ export class PluginOperationAggregateError extends ErrorBase<PluginOperationAggr
|
|
|
569
803
|
}
|
|
570
804
|
|
|
571
805
|
public constructor(args: PluginOperationAggregateErrorArgs) {
|
|
572
|
-
const {
|
|
573
|
-
// 個々のエラーで種別が指定されていない場合は、既定の種別で補完します。
|
|
806
|
+
const { action, errors, plugin, ...options } = args;
|
|
574
807
|
const normalizedErrors = errors.map((error) => ({
|
|
575
|
-
plugin: error.plugin ?? plugin ??
|
|
808
|
+
plugin: normalizePlugin((error.plugin ?? plugin ?? "") as string),
|
|
809
|
+
...(error.name !== undefined ? { name: error.name } : {}),
|
|
810
|
+
...(error.index !== undefined ? { index: error.index } : {}),
|
|
576
811
|
reason: error.reason,
|
|
577
812
|
}));
|
|
578
813
|
const plugins = [...new Set(normalizedErrors.map((error) => error.plugin))];
|
|
814
|
+
const [onlyPlugin] = plugins;
|
|
579
815
|
const meta: PluginOperationAggregateErrorMeta = {
|
|
580
|
-
plugin: plugins.length === 1 ? plugins[0]! : "plugin",
|
|
581
816
|
action,
|
|
582
817
|
errors: normalizedErrors,
|
|
818
|
+
plugin: plugins.length === 1 && onlyPlugin !== undefined ? onlyPlugin : "plugin",
|
|
583
819
|
};
|
|
584
820
|
super(
|
|
585
821
|
meta,
|
|
586
|
-
({ action, errors, plugin }) =>
|
|
822
|
+
({ action: messageAction, errors: messageErrors, plugin: messagePlugin }) =>
|
|
823
|
+
`${messageErrors.length} ${messagePlugin}(s) fail ${messageAction} operation`,
|
|
587
824
|
options,
|
|
588
825
|
);
|
|
589
826
|
}
|
|
@@ -592,15 +829,21 @@ export class PluginOperationAggregateError extends ErrorBase<PluginOperationAggr
|
|
|
592
829
|
setErrorMessage(
|
|
593
830
|
PluginOperationAggregateError,
|
|
594
831
|
({ action, errors, plugin }) =>
|
|
595
|
-
`${errors.length} 個の${
|
|
832
|
+
`${errors.length} 個の${
|
|
833
|
+
{
|
|
834
|
+
plugin: "プラグイン",
|
|
835
|
+
storage: "ストレージ",
|
|
836
|
+
middleware: "ミドルウェア",
|
|
837
|
+
}[plugin]
|
|
838
|
+
}が ${action} 操作に失敗`,
|
|
596
839
|
"ja",
|
|
597
840
|
);
|
|
598
841
|
|
|
599
|
-
//
|
|
842
|
+
// -------------------------------------------------------------------------------------------------。
|
|
600
843
|
//
|
|
601
|
-
//
|
|
844
|
+
// その他。
|
|
602
845
|
//
|
|
603
|
-
//
|
|
846
|
+
// -------------------------------------------------------------------------------------------------。
|
|
604
847
|
|
|
605
848
|
/**
|
|
606
849
|
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
|