unikvs 0.0.4 → 0.0.5
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/dist/src/_storage.d.ts +9 -9
- package/dist/src/_storage.d.ts.map +1 -1
- package/dist/src/_storage.js +13 -5
- package/dist/src/_transformer.d.ts +2 -2
- package/dist/src/_transformer.d.ts.map +1 -1
- package/dist/src/_transformer.js +10 -4
- package/dist/src/_valibot.d.ts +10 -9
- package/dist/src/_valibot.d.ts.map +1 -1
- package/dist/src/_valibot.js +13 -3
- package/dist/src/errors.d.ts +9 -2
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +25 -15
- package/dist/src/unikvs-config.d.ts +5 -5
- package/dist/src/unikvs-config.d.ts.map +1 -1
- package/dist/src/unikvs-config.js +1 -1
- package/dist/src/unikvs.d.ts +6 -6
- package/dist/src/unikvs.d.ts.map +1 -1
- package/dist/src/unikvs.js +28 -29
- package/package.json +19 -18
- package/src/_storage.ts +30 -13
- package/src/_transformer.ts +16 -6
- package/src/_valibot.ts +50 -10
- package/src/errors.ts +31 -3
- package/src/unikvs-config.ts +5 -8
- package/src/unikvs.ts +35 -36
package/dist/src/unikvs.js
CHANGED
|
@@ -11,12 +11,11 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
11
11
|
};
|
|
12
12
|
var _UniKvs_con, _UniKvs_context, _UniKvs_destinations, _UniKvs_transformers;
|
|
13
13
|
import { asyncmux, Asyncmux } from "asyncmux";
|
|
14
|
-
import * as v from "valibot";
|
|
15
14
|
import combineSignals from "./_combine-signals.js";
|
|
16
15
|
import logger from "./_logger.js";
|
|
17
16
|
import mergeContext from "./_merge-context.js";
|
|
18
17
|
import toValueStream from "./_to-value-stream.js";
|
|
19
|
-
import
|
|
18
|
+
import * as v from "./_valibot.js";
|
|
20
19
|
import { KeyNotFoundError, PluginOperationAggregateError, UniKvsIsNotOpenError, UniKvsIsOpenError, } from "./errors.js";
|
|
21
20
|
import UniKvsConfig from "./unikvs-config.js";
|
|
22
21
|
// -------------------------------------------------------------------------------------------------
|
|
@@ -106,7 +105,7 @@ const ioLockRegistry = typeof FinalizationRegistry !== "function"
|
|
|
106
105
|
? null
|
|
107
106
|
: new FinalizationRegistry((lock) => {
|
|
108
107
|
try {
|
|
109
|
-
lock.
|
|
108
|
+
lock.release();
|
|
110
109
|
}
|
|
111
110
|
catch { }
|
|
112
111
|
});
|
|
@@ -196,7 +195,7 @@ export default class UniKvs {
|
|
|
196
195
|
ioMux: new Asyncmux(),
|
|
197
196
|
}, "f");
|
|
198
197
|
try {
|
|
199
|
-
const [options = {}] =
|
|
198
|
+
const [options = {}] = v.parseInput(OpenArgsSchema, args);
|
|
200
199
|
const { signal: signalOption, context: contextOption } = options;
|
|
201
200
|
const { conAc } = __classPrivateFieldGet(this, _UniKvs_con, "f");
|
|
202
201
|
const signal = combineSignals([conAc.signal, signalOption]);
|
|
@@ -268,7 +267,7 @@ export default class UniKvs {
|
|
|
268
267
|
throw ex;
|
|
269
268
|
}
|
|
270
269
|
finally {
|
|
271
|
-
lock.
|
|
270
|
+
lock.release();
|
|
272
271
|
}
|
|
273
272
|
}
|
|
274
273
|
catch (ex) {
|
|
@@ -280,7 +279,7 @@ export default class UniKvs {
|
|
|
280
279
|
if (!__classPrivateFieldGet(this, _UniKvs_con, "f")) {
|
|
281
280
|
throw new UniKvsIsNotOpenError();
|
|
282
281
|
}
|
|
283
|
-
const [options = {}] =
|
|
282
|
+
const [options = {}] = v.parseInput(CloseArgsSchema, args);
|
|
284
283
|
const { signal = AbortSignal.timeout(10e3), context: contextOption } = options;
|
|
285
284
|
const context = mergeContext(__classPrivateFieldGet(this, _UniKvs_context, "f"), contextOption);
|
|
286
285
|
context["unikvs:action"] = "close";
|
|
@@ -328,12 +327,12 @@ export default class UniKvs {
|
|
|
328
327
|
}
|
|
329
328
|
}
|
|
330
329
|
finally {
|
|
331
|
-
lock.
|
|
330
|
+
lock.release();
|
|
332
331
|
}
|
|
333
332
|
}
|
|
334
333
|
finally {
|
|
335
334
|
__classPrivateFieldSet(this, _UniKvs_con, null, "f");
|
|
336
|
-
lock.
|
|
335
|
+
lock.release();
|
|
337
336
|
}
|
|
338
337
|
}
|
|
339
338
|
async [(_UniKvs_con = new WeakMap(), _UniKvs_context = new WeakMap(), _UniKvs_destinations = new WeakMap(), _UniKvs_transformers = new WeakMap(), Symbol.asyncDispose)]() {
|
|
@@ -348,7 +347,7 @@ export default class UniKvs {
|
|
|
348
347
|
if (!__classPrivateFieldGet(this, _UniKvs_con, "f")) {
|
|
349
348
|
throw new UniKvsIsNotOpenError();
|
|
350
349
|
}
|
|
351
|
-
const [options] =
|
|
350
|
+
const [options] = v.parseInput(SetArgsSchema, args);
|
|
352
351
|
const { key, value, signal: signalOption, context: contextOption } = options;
|
|
353
352
|
const { conAc, ioMux } = __classPrivateFieldGet(this, _UniKvs_con, "f");
|
|
354
353
|
const signal = combineSignals([conAc.signal, signalOption]);
|
|
@@ -389,7 +388,7 @@ export default class UniKvs {
|
|
|
389
388
|
}));
|
|
390
389
|
}
|
|
391
390
|
finally {
|
|
392
|
-
lock.
|
|
391
|
+
lock.release();
|
|
393
392
|
}
|
|
394
393
|
}
|
|
395
394
|
else {
|
|
@@ -411,7 +410,7 @@ export default class UniKvs {
|
|
|
411
410
|
}));
|
|
412
411
|
}
|
|
413
412
|
finally {
|
|
414
|
-
lock.
|
|
413
|
+
lock.release();
|
|
415
414
|
}
|
|
416
415
|
}
|
|
417
416
|
// エラーが発生した場合は集約します。
|
|
@@ -442,14 +441,14 @@ export default class UniKvs {
|
|
|
442
441
|
}
|
|
443
442
|
}
|
|
444
443
|
finally {
|
|
445
|
-
lock.
|
|
444
|
+
lock.release();
|
|
446
445
|
}
|
|
447
446
|
}
|
|
448
447
|
async get(...args) {
|
|
449
448
|
if (!__classPrivateFieldGet(this, _UniKvs_con, "f")) {
|
|
450
449
|
throw new UniKvsIsNotOpenError();
|
|
451
450
|
}
|
|
452
|
-
const [options] =
|
|
451
|
+
const [options] = v.parseInput(GetArgsSchema, args);
|
|
453
452
|
const { key, signal: signalOption, context: contextOption } = options;
|
|
454
453
|
const { conAc, ioMux } = __classPrivateFieldGet(this, _UniKvs_con, "f");
|
|
455
454
|
const signal = combineSignals([conAc.signal, signalOption]);
|
|
@@ -475,7 +474,7 @@ export default class UniKvs {
|
|
|
475
474
|
}
|
|
476
475
|
}
|
|
477
476
|
finally {
|
|
478
|
-
lock.
|
|
477
|
+
lock.release();
|
|
479
478
|
}
|
|
480
479
|
if (data === NONE) {
|
|
481
480
|
throw new KeyNotFoundError({ key });
|
|
@@ -489,14 +488,14 @@ export default class UniKvs {
|
|
|
489
488
|
return data;
|
|
490
489
|
}
|
|
491
490
|
finally {
|
|
492
|
-
lock.
|
|
491
|
+
lock.release();
|
|
493
492
|
}
|
|
494
493
|
}
|
|
495
494
|
async stream(...args) {
|
|
496
495
|
if (!__classPrivateFieldGet(this, _UniKvs_con, "f")) {
|
|
497
496
|
throw new UniKvsIsNotOpenError();
|
|
498
497
|
}
|
|
499
|
-
const [options] =
|
|
498
|
+
const [options] = v.parseInput(StreamArgsSchema, args);
|
|
500
499
|
const { key, signal: signalOption, context: contextOption } = options;
|
|
501
500
|
const { conAc, ioMux } = __classPrivateFieldGet(this, _UniKvs_con, "f");
|
|
502
501
|
const signal = combineSignals([conAc.signal, signalOption]);
|
|
@@ -537,7 +536,7 @@ export default class UniKvs {
|
|
|
537
536
|
}
|
|
538
537
|
catch { }
|
|
539
538
|
try {
|
|
540
|
-
lock.
|
|
539
|
+
lock.release();
|
|
541
540
|
}
|
|
542
541
|
catch { }
|
|
543
542
|
});
|
|
@@ -553,7 +552,7 @@ export default class UniKvs {
|
|
|
553
552
|
}
|
|
554
553
|
catch { }
|
|
555
554
|
try {
|
|
556
|
-
lock.
|
|
555
|
+
lock.release();
|
|
557
556
|
}
|
|
558
557
|
catch { }
|
|
559
558
|
});
|
|
@@ -562,19 +561,19 @@ export default class UniKvs {
|
|
|
562
561
|
return valueStream;
|
|
563
562
|
}
|
|
564
563
|
catch (ex) {
|
|
565
|
-
lock.
|
|
564
|
+
lock.release();
|
|
566
565
|
throw ex;
|
|
567
566
|
}
|
|
568
567
|
}
|
|
569
568
|
finally {
|
|
570
|
-
lock.
|
|
569
|
+
lock.release();
|
|
571
570
|
}
|
|
572
571
|
}
|
|
573
572
|
async has(...args) {
|
|
574
573
|
if (!__classPrivateFieldGet(this, _UniKvs_con, "f")) {
|
|
575
574
|
throw new UniKvsIsNotOpenError();
|
|
576
575
|
}
|
|
577
|
-
const [options] =
|
|
576
|
+
const [options] = v.parseInput(HasArgsSchema, args);
|
|
578
577
|
const { key, signal: signalOption, context: contextOption } = options;
|
|
579
578
|
const { conAc, ioMux } = __classPrivateFieldGet(this, _UniKvs_con, "f");
|
|
580
579
|
const signal = combineSignals([conAc.signal, signalOption]);
|
|
@@ -598,18 +597,18 @@ export default class UniKvs {
|
|
|
598
597
|
return false;
|
|
599
598
|
}
|
|
600
599
|
finally {
|
|
601
|
-
lock.
|
|
600
|
+
lock.release();
|
|
602
601
|
}
|
|
603
602
|
}
|
|
604
603
|
finally {
|
|
605
|
-
lock.
|
|
604
|
+
lock.release();
|
|
606
605
|
}
|
|
607
606
|
}
|
|
608
607
|
async delete(...args) {
|
|
609
608
|
if (!__classPrivateFieldGet(this, _UniKvs_con, "f")) {
|
|
610
609
|
throw new UniKvsIsNotOpenError();
|
|
611
610
|
}
|
|
612
|
-
const [options] =
|
|
611
|
+
const [options] = v.parseInput(DeleteArgsSchema, args);
|
|
613
612
|
const { key, signal: signalOption, context: contextOption } = options;
|
|
614
613
|
const { conAc, ioMux } = __classPrivateFieldGet(this, _UniKvs_con, "f");
|
|
615
614
|
const signal = combineSignals([conAc.signal, signalOption]);
|
|
@@ -642,18 +641,18 @@ export default class UniKvs {
|
|
|
642
641
|
}
|
|
643
642
|
}
|
|
644
643
|
finally {
|
|
645
|
-
lock.
|
|
644
|
+
lock.release();
|
|
646
645
|
}
|
|
647
646
|
}
|
|
648
647
|
finally {
|
|
649
|
-
lock.
|
|
648
|
+
lock.release();
|
|
650
649
|
}
|
|
651
650
|
}
|
|
652
651
|
async clear(...args) {
|
|
653
652
|
if (!__classPrivateFieldGet(this, _UniKvs_con, "f")) {
|
|
654
653
|
throw new UniKvsIsNotOpenError();
|
|
655
654
|
}
|
|
656
|
-
const [options = {}] =
|
|
655
|
+
const [options = {}] = v.parseInput(ClearArgsSchema, args);
|
|
657
656
|
const { signal: signalOption, context: contextOption } = options;
|
|
658
657
|
const { conAc, ioMux } = __classPrivateFieldGet(this, _UniKvs_con, "f");
|
|
659
658
|
const signal = combineSignals([conAc.signal, signalOption]);
|
|
@@ -683,11 +682,11 @@ export default class UniKvs {
|
|
|
683
682
|
}
|
|
684
683
|
}
|
|
685
684
|
finally {
|
|
686
|
-
lock.
|
|
685
|
+
lock.release();
|
|
687
686
|
}
|
|
688
687
|
}
|
|
689
688
|
finally {
|
|
690
|
-
lock.
|
|
689
|
+
lock.release();
|
|
691
690
|
}
|
|
692
691
|
}
|
|
693
692
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unikvs",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"homepage": "https://github.com/tai-kun/unikvs",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,33 +24,34 @@
|
|
|
24
24
|
"default": "./dist/src/index.js"
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
|
-
"scripts": {
|
|
28
|
-
"build": "tsc --project ./.config/tsconfig.build.json"
|
|
29
|
-
},
|
|
30
27
|
"dependencies": {
|
|
31
|
-
"@unikvs/core": "0.0.
|
|
32
|
-
"asyncmux": "^0.0.
|
|
28
|
+
"@unikvs/core": "0.0.5",
|
|
29
|
+
"asyncmux": "^0.0.8",
|
|
33
30
|
"call-fn-once": "^0.0.4",
|
|
34
31
|
"try-capture-stack-trace": "^0.0.3"
|
|
35
32
|
},
|
|
36
33
|
"devDependencies": {
|
|
37
|
-
"@tsconfig/
|
|
34
|
+
"@tsconfig/node24": "^24.0.4",
|
|
38
35
|
"@tsconfig/strictest": "^2.0.8",
|
|
39
|
-
"@types/node": "^
|
|
40
|
-
"@unikvs/checksum": "0.0.
|
|
41
|
-
"@unikvs/compression": "0.0.
|
|
42
|
-
"@unikvs/fs.node": "0.0.
|
|
43
|
-
"@unikvs/memory": "0.0.
|
|
44
|
-
"@unikvs/opfs": "0.0.
|
|
45
|
-
"@unikvs/utils": "0.0.
|
|
46
|
-
"@vitest/browser": "^4.1.
|
|
47
|
-
"@vitest/browser-playwright": "^4.1.
|
|
36
|
+
"@types/node": "^24.12.2",
|
|
37
|
+
"@unikvs/checksum": "0.0.5",
|
|
38
|
+
"@unikvs/compression": "0.0.5",
|
|
39
|
+
"@unikvs/fs.node": "0.0.5",
|
|
40
|
+
"@unikvs/memory": "0.0.5",
|
|
41
|
+
"@unikvs/opfs": "0.0.5",
|
|
42
|
+
"@unikvs/utils": "0.0.5",
|
|
43
|
+
"@vitest/browser": "^4.1.5",
|
|
44
|
+
"@vitest/browser-playwright": "^4.1.5",
|
|
48
45
|
"npm-check-updates": "^20.0.2",
|
|
49
46
|
"playwright": "^1.59.1",
|
|
50
|
-
"
|
|
47
|
+
"vite": "^8.0.10",
|
|
48
|
+
"vitest": "^4.1.5"
|
|
51
49
|
},
|
|
52
50
|
"peerDependencies": {
|
|
53
51
|
"@logtape/logtape": "^2.0.0",
|
|
54
52
|
"valibot": "^1.0.0"
|
|
53
|
+
},
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "tsc --project ./.config/tsconfig.build.json"
|
|
55
56
|
}
|
|
56
|
-
}
|
|
57
|
+
}
|
package/src/_storage.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { Context, IReadableStream, IStorage, IWritableStream
|
|
1
|
+
import type { Context, IReadableStream, IStorage, IWritableStream } from "@unikvs/core";
|
|
2
2
|
|
|
3
|
+
import * as v from "./_valibot.js";
|
|
3
4
|
import {
|
|
4
5
|
type PluginOperationAggregateError,
|
|
5
6
|
ReadableStreamNotSupportedError,
|
|
@@ -7,7 +8,7 @@ import {
|
|
|
7
8
|
WritableStreamNotSupportedError,
|
|
8
9
|
} from "./errors.js";
|
|
9
10
|
|
|
10
|
-
export class UniKvsStorage {
|
|
11
|
+
export default class UniKvsStorage {
|
|
11
12
|
private readonly io: IStorage;
|
|
12
13
|
|
|
13
14
|
public constructor(io: IStorage) {
|
|
@@ -37,7 +38,7 @@ export class UniKvsStorage {
|
|
|
37
38
|
public async onOtherWriteError(
|
|
38
39
|
context: Context,
|
|
39
40
|
signal: AbortSignal,
|
|
40
|
-
key: Key,
|
|
41
|
+
key: IStorage.Key,
|
|
41
42
|
error: PluginOperationAggregateError,
|
|
42
43
|
): Promise<void> {
|
|
43
44
|
if (!this.io.isOpen) {
|
|
@@ -56,7 +57,12 @@ export class UniKvsStorage {
|
|
|
56
57
|
});
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
public async write(
|
|
60
|
+
public async write(
|
|
61
|
+
context: Context,
|
|
62
|
+
signal: AbortSignal,
|
|
63
|
+
key: IStorage.Key,
|
|
64
|
+
data: unknown,
|
|
65
|
+
): Promise<void> {
|
|
60
66
|
if (!this.io.isOpen) {
|
|
61
67
|
throw new StorageIsNotOpenError({ name: this.io.name });
|
|
62
68
|
}
|
|
@@ -64,23 +70,28 @@ export class UniKvsStorage {
|
|
|
64
70
|
await this.io.write({ key, data, signal, context });
|
|
65
71
|
}
|
|
66
72
|
|
|
67
|
-
public async read(context: Context, signal: AbortSignal, key: Key): Promise<
|
|
73
|
+
public async read(context: Context, signal: AbortSignal, key: IStorage.Key): Promise<unknown> {
|
|
68
74
|
if (!this.io.isOpen) {
|
|
69
75
|
throw new StorageIsNotOpenError({ name: this.io.name });
|
|
70
76
|
}
|
|
71
77
|
|
|
72
|
-
|
|
78
|
+
const output = await this.io.read({ key, signal, context });
|
|
79
|
+
|
|
80
|
+
return output;
|
|
73
81
|
}
|
|
74
82
|
|
|
75
|
-
public async exists(context: Context, signal: AbortSignal, key: Key): Promise<boolean> {
|
|
83
|
+
public async exists(context: Context, signal: AbortSignal, key: IStorage.Key): Promise<boolean> {
|
|
76
84
|
if (!this.io.isOpen) {
|
|
77
85
|
throw new StorageIsNotOpenError({ name: this.io.name });
|
|
78
86
|
}
|
|
79
87
|
|
|
80
|
-
|
|
88
|
+
const output = await this.io.exists({ key, signal, context });
|
|
89
|
+
const parsed = Boolean(output);
|
|
90
|
+
|
|
91
|
+
return parsed;
|
|
81
92
|
}
|
|
82
93
|
|
|
83
|
-
public async delete(context: Context, signal: AbortSignal, key: Key): Promise<void> {
|
|
94
|
+
public async delete(context: Context, signal: AbortSignal, key: IStorage.Key): Promise<void> {
|
|
84
95
|
if (!this.io.isOpen) {
|
|
85
96
|
throw new StorageIsNotOpenError({ name: this.io.name });
|
|
86
97
|
}
|
|
@@ -99,7 +110,7 @@ export class UniKvsStorage {
|
|
|
99
110
|
public async getWritable(
|
|
100
111
|
context: Context,
|
|
101
112
|
signal: AbortSignal,
|
|
102
|
-
key: Key,
|
|
113
|
+
key: IStorage.Key,
|
|
103
114
|
): Promise<IWritableStream> {
|
|
104
115
|
if (!this.io.isOpen) {
|
|
105
116
|
throw new StorageIsNotOpenError({ name: this.io.name });
|
|
@@ -109,13 +120,16 @@ export class UniKvsStorage {
|
|
|
109
120
|
throw new WritableStreamNotSupportedError({ name: this.io.name });
|
|
110
121
|
}
|
|
111
122
|
|
|
112
|
-
|
|
123
|
+
const output = await this.io.getWritable({ key, signal, context });
|
|
124
|
+
const parsed = v.parseOutput(v.instance(WritableStream), output);
|
|
125
|
+
|
|
126
|
+
return parsed;
|
|
113
127
|
}
|
|
114
128
|
|
|
115
129
|
public async getReadable(
|
|
116
130
|
context: Context,
|
|
117
131
|
signal: AbortSignal,
|
|
118
|
-
key: Key,
|
|
132
|
+
key: IStorage.Key,
|
|
119
133
|
): Promise<IReadableStream> {
|
|
120
134
|
if (!this.io.isOpen) {
|
|
121
135
|
throw new StorageIsNotOpenError({ name: this.io.name });
|
|
@@ -125,6 +139,9 @@ export class UniKvsStorage {
|
|
|
125
139
|
throw new ReadableStreamNotSupportedError({ name: this.io.name });
|
|
126
140
|
}
|
|
127
141
|
|
|
128
|
-
|
|
142
|
+
const output = await this.io.getReadable({ key, signal, context });
|
|
143
|
+
const parsed = v.parseOutput(v.instance(ReadableStream), output);
|
|
144
|
+
|
|
145
|
+
return parsed;
|
|
129
146
|
}
|
|
130
147
|
}
|
package/src/_transformer.ts
CHANGED
|
@@ -33,20 +33,24 @@ export default class UniKvsTransformer {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
public async encode(context: Context, signal: AbortSignal, data: any): Promise<
|
|
36
|
+
public async encode(context: Context, signal: AbortSignal, data: any): Promise<unknown> {
|
|
37
37
|
if (!this.tf.isOpen) {
|
|
38
38
|
throw new TransformerIsNotOpenError({ name: this.tf.name });
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
const output = await this.tf.encode({ data, signal, context });
|
|
42
|
+
|
|
43
|
+
return output;
|
|
42
44
|
}
|
|
43
45
|
|
|
44
|
-
public async decode(context: Context, signal: AbortSignal, data: any): Promise<
|
|
46
|
+
public async decode(context: Context, signal: AbortSignal, data: any): Promise<unknown> {
|
|
45
47
|
if (!this.tf.isOpen) {
|
|
46
48
|
throw new TransformerIsNotOpenError({ name: this.tf.name });
|
|
47
49
|
}
|
|
48
50
|
|
|
49
|
-
|
|
51
|
+
const output = await this.tf.decode({ data, signal, context });
|
|
52
|
+
|
|
53
|
+
return output;
|
|
50
54
|
}
|
|
51
55
|
|
|
52
56
|
public async getEncodable(context: Context, signal: AbortSignal): Promise<IEncodable> {
|
|
@@ -58,7 +62,10 @@ export default class UniKvsTransformer {
|
|
|
58
62
|
throw new EncodableStreamNotSupportedError({ name: this.tf.name });
|
|
59
63
|
}
|
|
60
64
|
|
|
61
|
-
|
|
65
|
+
const output = await this.tf.getEncodable({ signal, context });
|
|
66
|
+
const parsed = output; // TODO(tai-kun): 要検証
|
|
67
|
+
|
|
68
|
+
return parsed;
|
|
62
69
|
}
|
|
63
70
|
|
|
64
71
|
public async getDecodable(context: Context, signal: AbortSignal): Promise<IDecodable> {
|
|
@@ -70,6 +77,9 @@ export default class UniKvsTransformer {
|
|
|
70
77
|
throw new DecodableStreamNotSupportedError({ name: this.tf.name });
|
|
71
78
|
}
|
|
72
79
|
|
|
73
|
-
|
|
80
|
+
const output = await this.tf.getDecodable({ signal, context });
|
|
81
|
+
const parsed = output; // TODO(tai-kun): 要検証
|
|
82
|
+
|
|
83
|
+
return parsed;
|
|
74
84
|
}
|
|
75
85
|
}
|
package/src/_valibot.ts
CHANGED
|
@@ -1,23 +1,63 @@
|
|
|
1
|
+
import type { ErrorOptions } from "@unikvs/core";
|
|
1
2
|
import { tryCaptureStackTrace } from "try-capture-stack-trace";
|
|
2
3
|
import { type InferOutput, safeParse } from "valibot";
|
|
3
4
|
|
|
4
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
InvalidInputError,
|
|
7
|
+
InvalidOutputError,
|
|
8
|
+
type InvalidInputErrorArgs,
|
|
9
|
+
type InvalidOutputErrorArgs,
|
|
10
|
+
} from "./errors.js";
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
any,
|
|
14
|
+
omit,
|
|
15
|
+
pipe,
|
|
16
|
+
array,
|
|
17
|
+
tuple,
|
|
18
|
+
union,
|
|
19
|
+
number,
|
|
20
|
+
object,
|
|
21
|
+
record,
|
|
22
|
+
string,
|
|
23
|
+
symbol,
|
|
24
|
+
unknown,
|
|
25
|
+
instance,
|
|
26
|
+
minValue,
|
|
27
|
+
optional,
|
|
28
|
+
transform,
|
|
29
|
+
safeInteger,
|
|
30
|
+
} from "valibot";
|
|
5
31
|
|
|
6
32
|
type BaseSchema = typeof safeParse extends (schema: infer S, ...args: any) => any ? S : never;
|
|
7
33
|
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
34
|
+
export interface ParseInputErrorConstructor {
|
|
35
|
+
new (args: InvalidInputErrorArgs, options?: ErrorOptions): Error;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function parseInput<const TSchema extends BaseSchema>(
|
|
39
|
+
schema: TSchema,
|
|
40
|
+
value: unknown,
|
|
41
|
+
Error: ParseInputErrorConstructor = InvalidInputError,
|
|
42
|
+
): InferOutput<TSchema> {
|
|
43
|
+
const result = safeParse(schema, value);
|
|
44
|
+
if (result.success) {
|
|
45
|
+
return result.output;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const error = new Error({ value, issues: result.issues });
|
|
49
|
+
tryCaptureStackTrace(error, parseInput);
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
12
52
|
|
|
13
|
-
export interface
|
|
14
|
-
new (args:
|
|
53
|
+
export interface ParseOutputErrorConstructor {
|
|
54
|
+
new (args: InvalidOutputErrorArgs, options?: ErrorOptions): Error;
|
|
15
55
|
}
|
|
16
56
|
|
|
17
|
-
export function
|
|
57
|
+
export function parseOutput<const TSchema extends BaseSchema>(
|
|
18
58
|
schema: TSchema,
|
|
19
59
|
value: unknown,
|
|
20
|
-
Error:
|
|
60
|
+
Error: ParseOutputErrorConstructor = InvalidOutputError,
|
|
21
61
|
): InferOutput<TSchema> {
|
|
22
62
|
const result = safeParse(schema, value);
|
|
23
63
|
if (result.success) {
|
|
@@ -25,6 +65,6 @@ export function parse<const TSchema extends BaseSchema>(
|
|
|
25
65
|
}
|
|
26
66
|
|
|
27
67
|
const error = new Error({ value, issues: result.issues });
|
|
28
|
-
tryCaptureStackTrace(error,
|
|
68
|
+
tryCaptureStackTrace(error, parseOutput);
|
|
29
69
|
throw error;
|
|
30
70
|
}
|
package/src/errors.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
setErrorMessage,
|
|
3
|
+
ErrorBase,
|
|
4
|
+
type ErrorOptions,
|
|
5
|
+
type ErrorMeta,
|
|
6
|
+
type IStorage,
|
|
7
|
+
} from "@unikvs/core";
|
|
2
8
|
import type { BaseIssue } from "valibot";
|
|
3
9
|
|
|
4
10
|
// -------------------------------------------------------------------------------------------------
|
|
@@ -90,7 +96,7 @@ export class UniKvsIsNotOpenError extends ErrorBase<undefined> {
|
|
|
90
96
|
setErrorMessage(UniKvsIsNotOpenError, "UniKvs は開いていません", "ja");
|
|
91
97
|
|
|
92
98
|
export type KeyNotFoundErrorMeta = {
|
|
93
|
-
readonly key: Key;
|
|
99
|
+
readonly key: IStorage.Key;
|
|
94
100
|
};
|
|
95
101
|
|
|
96
102
|
export type KeyNotFoundErrorArgs = KeyNotFoundErrorMeta;
|
|
@@ -101,7 +107,7 @@ export class KeyNotFoundError extends ErrorBase<KeyNotFoundErrorMeta> {
|
|
|
101
107
|
}
|
|
102
108
|
|
|
103
109
|
public constructor(args: KeyNotFoundErrorArgs, options?: ErrorOptions) {
|
|
104
|
-
super(args, ({ key }) => `Key ${JSON.stringify(key)} not found`, options);
|
|
110
|
+
super(args, ({ key }) => `IStorage.Key ${JSON.stringify(key)} not found`, options);
|
|
105
111
|
}
|
|
106
112
|
}
|
|
107
113
|
|
|
@@ -197,6 +203,28 @@ setErrorMessage(
|
|
|
197
203
|
"ja",
|
|
198
204
|
);
|
|
199
205
|
|
|
206
|
+
export type MultipartWriteNotSupportedErrorMeta = {
|
|
207
|
+
readonly name: string;
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
export type MultipartWriteNotSupportedErrorArgs = MultipartWriteNotSupportedErrorMeta;
|
|
211
|
+
|
|
212
|
+
export class MultipartWriteNotSupportedError extends ErrorBase<MultipartWriteNotSupportedErrorMeta> {
|
|
213
|
+
static {
|
|
214
|
+
this.prototype.name = "UniKvsMultipartWriteNotSupportedError";
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
public constructor(args: MultipartWriteNotSupportedErrorArgs, options?: ErrorOptions) {
|
|
218
|
+
super(args, ({ name }) => `Storage "${name}" does not support multipart-write`, options);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
setErrorMessage(
|
|
223
|
+
StorageIsNotOpenError,
|
|
224
|
+
({ name }) => `ストレージ "${name}" はマルチパート書き込みをサポートしていません`,
|
|
225
|
+
"ja",
|
|
226
|
+
);
|
|
227
|
+
|
|
200
228
|
// -------------------------------------------------------------------------------------------------
|
|
201
229
|
//
|
|
202
230
|
// トランスフォーマー
|
package/src/unikvs-config.ts
CHANGED
|
@@ -3,13 +3,12 @@ import type {
|
|
|
3
3
|
IReadableStreamStorage,
|
|
4
4
|
IStorage,
|
|
5
5
|
IWritableStreamStorage,
|
|
6
|
-
Key,
|
|
7
6
|
IDecodableStreamTransformer,
|
|
8
7
|
IEncodableStreamTransformer,
|
|
9
8
|
ITransformer,
|
|
10
9
|
} from "@unikvs/core";
|
|
11
10
|
|
|
12
|
-
import
|
|
11
|
+
import UniKvsStorage from "./_storage.js";
|
|
13
12
|
import UniKvsTransformer from "./_transformer.js";
|
|
14
13
|
import type { ContextSource } from "./context.types.js";
|
|
15
14
|
import { MissingStorageError } from "./errors.js";
|
|
@@ -95,18 +94,16 @@ export type StreamValue<TChunkData = any> = [Type: typeof STREAM_VALUE, ChunkDat
|
|
|
95
94
|
/**
|
|
96
95
|
* UniKvs で扱う値の抽象型です。プレーンな値かストリーム値のいずれかになります。
|
|
97
96
|
*
|
|
98
|
-
* @template
|
|
97
|
+
* @template TData データまたはチャンクデータの型です。
|
|
99
98
|
*/
|
|
100
|
-
export type Value<
|
|
101
|
-
| PlainValue<TDataAndChunkData>
|
|
102
|
-
| StreamValue<TDataAndChunkData>;
|
|
99
|
+
export type Value<TData = any> = PlainValue<TData> | StreamValue<TData>;
|
|
103
100
|
|
|
104
101
|
/**
|
|
105
102
|
* キーと値のマッピングを定義するオブジェクトの型です。
|
|
106
103
|
*
|
|
107
104
|
* @template T マッピングされる値の型です。
|
|
108
105
|
*/
|
|
109
|
-
export type KeyValueMapping<T = any> = { readonly [key: Key]: Value<T> };
|
|
106
|
+
export type KeyValueMapping<T = any> = { readonly [key: IStorage.Key]: Value<T> };
|
|
110
107
|
|
|
111
108
|
/**
|
|
112
109
|
* PlainValue 型から内部のデータ型を抽出します。
|
|
@@ -130,7 +127,7 @@ export type $InferStreamValueChunkData<TStremValue> =
|
|
|
130
127
|
* @template TKeyValueMapping 対象となるマッピング型です。
|
|
131
128
|
*/
|
|
132
129
|
export type KeyofKeyValueMapping<TKeyValueMapping extends KeyValueMapping = KeyValueMapping> =
|
|
133
|
-
Extract<keyof TKeyValueMapping, Key>;
|
|
130
|
+
Extract<keyof TKeyValueMapping, IStorage.Key>;
|
|
134
131
|
|
|
135
132
|
/**
|
|
136
133
|
* UniKvs の設定を構築するためのビルダーインターフェースです。
|