unikvs 0.0.10 → 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 +3 -0
- 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 +35 -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 +173 -96
- package/src/_streams.schemas.ts +21 -0
- package/src/_streams.ts +73 -0
- 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 -3
- package/src/_value-schemas.ts +192 -0
- package/src/_value-validation.ts +57 -0
- package/src/errors.ts +446 -252
- package/src/index.ts +46 -26
- package/src/types.ts +13 -0
- package/src/unikvs-branch.ts +445 -0
- package/src/unikvs-builder.ts +706 -0
- package/src/unikvs.ts +1456 -971
- 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-context.d.ts +0 -13
- package/dist/src/_merge-context.d.ts.map +0 -1
- package/dist/src/_merge-context.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 -94
- 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/context.types.d.ts +0 -17
- package/dist/src/context.types.d.ts.map +0 -1
- package/dist/src/context.types.js +0 -1
- package/dist/src/errors.d.ts +0 -340
- package/dist/src/errors.d.ts.map +0 -1
- package/dist/src/errors.js +0 -250
- 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 -255
- package/dist/src/unikvs-config.d.ts.map +0 -1
- package/dist/src/unikvs-config.js +0 -105
- package/dist/src/unikvs.d.ts +0 -354
- package/dist/src/unikvs.d.ts.map +0 -1
- package/dist/src/unikvs.js +0 -867
- package/dist/src/utils.types.d.ts +0 -7
- 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 -16
- package/dist/src/value-stream.types.d.ts.map +0 -1
- package/dist/src/value-stream.types.js +0 -1
- package/src/_merge-context.ts +0 -19
- package/src/_transformer.ts +0 -89
- package/src/context.types.ts +0 -19
- package/src/unikvs-config.ts +0 -426
- package/src/utils.types.ts +0 -6
- package/src/value-stream.types.ts +0 -19
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import type { VariablesInit } from "./_contexts.js";
|
|
2
|
+
import type { ValueOf } from "./_types.js";
|
|
3
|
+
import type {
|
|
4
|
+
OpenOptionsSchema,
|
|
5
|
+
ClearOptionsSchema,
|
|
6
|
+
CloseOptionsSchema,
|
|
7
|
+
} from "./_unikvs.schemas.js";
|
|
8
|
+
import type { InferInput } from "./_valibot.js";
|
|
9
|
+
import type { $InferPlainValueInput } from "./_value-schemas.js";
|
|
10
|
+
import type { KeyValueMapping } from "./unikvs-branch.js";
|
|
11
|
+
import type { Value, PlainValue, StreamValue } from "./value-schemas.js";
|
|
12
|
+
|
|
13
|
+
// -------------------------------------------------------------------------------------------------。
|
|
14
|
+
//
|
|
15
|
+
// ユーティリティー。
|
|
16
|
+
//
|
|
17
|
+
// -------------------------------------------------------------------------------------------------。
|
|
18
|
+
|
|
19
|
+
export type KeyofKeyValueMapping<TKeyValueMapping extends KeyValueMapping = KeyValueMapping> =
|
|
20
|
+
Extract<keyof TKeyValueMapping, string>;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#value-types)
|
|
24
|
+
*/
|
|
25
|
+
export type SetValue<TValue extends Value> =
|
|
26
|
+
| $InferPlainValueInput<TValue>
|
|
27
|
+
| (TValue extends StreamValue<any, infer TChunkInput> ? ReadableStream<TChunkInput> : never);
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#value-types)
|
|
31
|
+
*/
|
|
32
|
+
export type KeyofKeyValueMappingHasPlainValue<TKeyValueMapping extends KeyValueMapping> = ValueOf<{
|
|
33
|
+
[TKey in KeyofKeyValueMapping<TKeyValueMapping>]: PlainValue extends TKeyValueMapping[TKey]
|
|
34
|
+
? TKey
|
|
35
|
+
: never;
|
|
36
|
+
}>;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#value-types)
|
|
40
|
+
*/
|
|
41
|
+
export type KeyofKeyValueMappingHasStreamValue<TKeyValueMapping extends KeyValueMapping> = ValueOf<{
|
|
42
|
+
[TKey in KeyofKeyValueMapping<TKeyValueMapping>]: StreamValue extends TKeyValueMapping[TKey]
|
|
43
|
+
? TKey
|
|
44
|
+
: never;
|
|
45
|
+
}>;
|
|
46
|
+
|
|
47
|
+
// -------------------------------------------------------------------------------------------------。
|
|
48
|
+
//
|
|
49
|
+
// 型定義。
|
|
50
|
+
//
|
|
51
|
+
// -------------------------------------------------------------------------------------------------。
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#client-operations)
|
|
55
|
+
*/
|
|
56
|
+
export type OpenOptions = InferInput<typeof OpenOptionsSchema>;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#client-operations)
|
|
60
|
+
*/
|
|
61
|
+
export type CloseOptions = InferInput<typeof CloseOptionsSchema>;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#client-operations)
|
|
65
|
+
*/
|
|
66
|
+
export type SetOptions<
|
|
67
|
+
TKeyValueMapping extends KeyValueMapping = KeyValueMapping,
|
|
68
|
+
TKey extends KeyofKeyValueMapping<TKeyValueMapping> = KeyofKeyValueMapping<TKeyValueMapping>,
|
|
69
|
+
> = {
|
|
70
|
+
/**
|
|
71
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#client-operations)
|
|
72
|
+
*/
|
|
73
|
+
readonly key: TKey;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#client-operations)
|
|
77
|
+
*/
|
|
78
|
+
readonly value: SetValue<TKeyValueMapping[TKey]>;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#variables-and-cancellation)
|
|
82
|
+
*/
|
|
83
|
+
readonly signal?: AbortSignal | undefined;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#variables-and-cancellation)
|
|
87
|
+
*/
|
|
88
|
+
readonly vars?: VariablesInit | undefined;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#client-operations)
|
|
93
|
+
*/
|
|
94
|
+
export type GetOptions<TKey = string> = {
|
|
95
|
+
/**
|
|
96
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#client-operations)
|
|
97
|
+
*/
|
|
98
|
+
readonly key: TKey;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#client-operations)
|
|
102
|
+
*/
|
|
103
|
+
readonly repair?: boolean | undefined;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#client-operations)
|
|
107
|
+
*/
|
|
108
|
+
readonly throwOnRepairDenied?: boolean | undefined;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#variables-and-cancellation)
|
|
112
|
+
*/
|
|
113
|
+
readonly signal?: AbortSignal | undefined;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#variables-and-cancellation)
|
|
117
|
+
*/
|
|
118
|
+
readonly vars?: VariablesInit | undefined;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#value-stream)
|
|
123
|
+
*/
|
|
124
|
+
export type StreamOptions<TKey = string> = {
|
|
125
|
+
/**
|
|
126
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#value-stream)
|
|
127
|
+
*/
|
|
128
|
+
readonly key: TKey;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#value-stream)
|
|
132
|
+
*/
|
|
133
|
+
readonly repair?: boolean | undefined;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#value-stream)
|
|
137
|
+
*/
|
|
138
|
+
readonly throwOnRepairDenied?: boolean | undefined;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#variables-and-cancellation)
|
|
142
|
+
*/
|
|
143
|
+
readonly signal?: AbortSignal | undefined;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#variables-and-cancellation)
|
|
147
|
+
*/
|
|
148
|
+
readonly vars?: VariablesInit | undefined;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#client-operations)
|
|
153
|
+
*/
|
|
154
|
+
export type HasOptions<TKey = string> = {
|
|
155
|
+
/**
|
|
156
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#client-operations)
|
|
157
|
+
*/
|
|
158
|
+
readonly key: TKey;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#variables-and-cancellation)
|
|
162
|
+
*/
|
|
163
|
+
readonly signal?: AbortSignal | undefined;
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#variables-and-cancellation)
|
|
167
|
+
*/
|
|
168
|
+
readonly vars?: VariablesInit | undefined;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#client-operations)
|
|
173
|
+
*/
|
|
174
|
+
export type DeleteOptions<TKey = string> = {
|
|
175
|
+
/**
|
|
176
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#client-operations)
|
|
177
|
+
*/
|
|
178
|
+
readonly key: TKey;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#variables-and-cancellation)
|
|
182
|
+
*/
|
|
183
|
+
readonly signal?: AbortSignal | undefined;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#variables-and-cancellation)
|
|
187
|
+
*/
|
|
188
|
+
readonly vars?: VariablesInit | undefined;
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#client-operations)
|
|
193
|
+
*/
|
|
194
|
+
export type ClearOptions = InferInput<typeof ClearOptionsSchema>;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { InferInput, InferOutput, GenericSchema } from "./_valibot.js";
|
|
2
|
+
import {
|
|
3
|
+
type ValueSchemaInfo,
|
|
4
|
+
type ValueSchemaKind,
|
|
5
|
+
VALUE_SCHEMA_BRAND,
|
|
6
|
+
} from "./_value-schemas.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* スキーマ付きの値を表す内部オブジェクトです。
|
|
10
|
+
*/
|
|
11
|
+
type ValueSchemaDescriptor = ValueSchemaInfo & {
|
|
12
|
+
readonly [VALUE_SCHEMA_BRAND]: true;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* スキーマ情報を内部オブジェクトとして生成します。
|
|
17
|
+
*/
|
|
18
|
+
function createValueSchemaDescriptor(
|
|
19
|
+
kind: ValueSchemaKind,
|
|
20
|
+
schema: GenericSchema,
|
|
21
|
+
): ValueSchemaDescriptor {
|
|
22
|
+
return {
|
|
23
|
+
[VALUE_SCHEMA_BRAND]: true,
|
|
24
|
+
kind,
|
|
25
|
+
schema,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* プレーンな値を識別するための固有のシンボルです。
|
|
31
|
+
*/
|
|
32
|
+
declare const PLAIN_VALUE: unique symbol;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#value-types)
|
|
36
|
+
*/
|
|
37
|
+
export type PlainValue<TData = any, TInput = TData> = [
|
|
38
|
+
Type: typeof PLAIN_VALUE,
|
|
39
|
+
Data: TData,
|
|
40
|
+
Input: TInput,
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#value-types)
|
|
45
|
+
*/
|
|
46
|
+
export function PlainValue<const TSchema extends GenericSchema>(
|
|
47
|
+
schema: TSchema,
|
|
48
|
+
): PlainValue<InferOutput<TSchema>, InferInput<TSchema>> {
|
|
49
|
+
return createValueSchemaDescriptor("plain", schema) as unknown as PlainValue<
|
|
50
|
+
InferOutput<TSchema>,
|
|
51
|
+
InferInput<TSchema>
|
|
52
|
+
>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* ストリーム形式の値を識別するための固有のシンボルです。
|
|
57
|
+
*/
|
|
58
|
+
declare const STREAM_VALUE: unique symbol;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#value-types)
|
|
62
|
+
*/
|
|
63
|
+
export type StreamValue<TChunkData = any, TChunkInput = TChunkData> = [
|
|
64
|
+
Type: typeof STREAM_VALUE,
|
|
65
|
+
ChunkData: TChunkData,
|
|
66
|
+
ChunkInput: TChunkInput,
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#value-types)
|
|
71
|
+
*/
|
|
72
|
+
export function StreamValue<const TSchema extends GenericSchema>(
|
|
73
|
+
schema: TSchema,
|
|
74
|
+
): StreamValue<InferOutput<TSchema>, InferInput<TSchema>> {
|
|
75
|
+
return createValueSchemaDescriptor("stream", schema) as unknown as StreamValue<
|
|
76
|
+
InferOutput<TSchema>,
|
|
77
|
+
InferInput<TSchema>
|
|
78
|
+
>;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#value-types)
|
|
83
|
+
*/
|
|
84
|
+
export type Value<TDataAndChunkData = any, TInput = TDataAndChunkData> =
|
|
85
|
+
| PlainValue<TDataAndChunkData, TInput>
|
|
86
|
+
| StreamValue<TDataAndChunkData, TInput>;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#value-types)
|
|
90
|
+
*/
|
|
91
|
+
export function Value<const TSchema extends GenericSchema>(
|
|
92
|
+
schema: TSchema,
|
|
93
|
+
): Value<InferOutput<TSchema>, InferInput<TSchema>> {
|
|
94
|
+
return createValueSchemaDescriptor("any", schema) as unknown as Value<
|
|
95
|
+
InferOutput<TSchema>,
|
|
96
|
+
InferInput<TSchema>
|
|
97
|
+
>;
|
|
98
|
+
}
|
package/dist/src/_logger.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_logger.d.ts","sourceRoot":"","sources":["../../src/_logger.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,MAAM,mCAAsB,CAAC;eAEpB,MAAM"}
|
package/dist/src/_logger.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Context } from "@unikvs/core";
|
|
2
|
-
import type { ContextSource } from "./context.types.js";
|
|
3
|
-
/**
|
|
4
|
-
* 2 つの Context オブジェクトを結合します。
|
|
5
|
-
*
|
|
6
|
-
* 基本となる Context に対して、追加または上書きするコンテキスト情報を結合し、新しい Context オブジェクトを生成して返します。追加するコンテキスト情報が配列(キーと値のペアの配列)である場合は、オブジェクトに変換した上で結合処理を行います。
|
|
7
|
-
*
|
|
8
|
-
* @param a ベースとなる読み取り専用の Context オブジェクトです。
|
|
9
|
-
* @param b 結合する読み取り専用の Context、または ContextSource、あるいは undefined です。
|
|
10
|
-
* @returns 結合された新しい Context オブジェクトです。
|
|
11
|
-
*/
|
|
12
|
-
export default function mergeContext(a: Readonly<Context>, b: Readonly<Context> | ContextSource | undefined): Context;
|
|
13
|
-
//# sourceMappingURL=_merge-context.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_merge-context.d.ts","sourceRoot":"","sources":["../../src/_merge-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,EACpB,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,aAAa,GAAG,SAAS,GAC/C,OAAO,CAET"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 2 つの Context オブジェクトを結合します。
|
|
3
|
-
*
|
|
4
|
-
* 基本となる Context に対して、追加または上書きするコンテキスト情報を結合し、新しい Context オブジェクトを生成して返します。追加するコンテキスト情報が配列(キーと値のペアの配列)である場合は、オブジェクトに変換した上で結合処理を行います。
|
|
5
|
-
*
|
|
6
|
-
* @param a ベースとなる読み取り専用の Context オブジェクトです。
|
|
7
|
-
* @param b 結合する読み取り専用の Context、または ContextSource、あるいは undefined です。
|
|
8
|
-
* @returns 結合された新しい Context オブジェクトです。
|
|
9
|
-
*/
|
|
10
|
-
export default function mergeContext(a, b) {
|
|
11
|
-
return { ...a, ...(Array.isArray(b) ? Object.fromEntries(b) : b) };
|
|
12
|
-
}
|
package/dist/src/_storage.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Context, IStorage, IReadableStream, IWritableStream } from "@unikvs/core";
|
|
2
|
-
import { type PluginOperationAggregateError } from "./errors.js";
|
|
3
|
-
export default class UniKvsStorage {
|
|
4
|
-
private readonly io;
|
|
5
|
-
private managed;
|
|
6
|
-
constructor(io: IStorage);
|
|
7
|
-
open(context: Context, signal: AbortSignal): Promise<void>;
|
|
8
|
-
close(context: Context, signal: AbortSignal): Promise<void>;
|
|
9
|
-
write(context: Context, signal: AbortSignal, key: IStorage.Key, data: unknown): Promise<void>;
|
|
10
|
-
read(context: Context, signal: AbortSignal, key: IStorage.Key): Promise<unknown>;
|
|
11
|
-
exists(context: Context, signal: AbortSignal, key: IStorage.Key): Promise<boolean>;
|
|
12
|
-
delete(context: Context, signal: AbortSignal, key: IStorage.Key): Promise<void>;
|
|
13
|
-
clear(context: Context, signal: AbortSignal): Promise<void>;
|
|
14
|
-
getReadable(context: Context, signal: AbortSignal, key: IStorage.Key): Promise<IReadableStream>;
|
|
15
|
-
getWritable(context: Context, signal: AbortSignal, key: IStorage.Key): Promise<IWritableStream>;
|
|
16
|
-
onOtherWriteError(context: Context, signal: AbortSignal, key: IStorage.Key, err: PluginOperationAggregateError): Promise<void>;
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=_storage.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_storage.d.ts","sourceRoot":"","sources":["../../src/_storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAa,eAAe,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAGnG,OAAO,EACL,KAAK,6BAA6B,EAInC,MAAM,aAAa,CAAC;AAErB,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAW;IAE9B,OAAO,CAAC,OAAO,CAAU;IAEzB,YAAmB,EAAE,EAAE,QAAQ,EAG9B;IAEY,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAStE;IAEY,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAQvE;IAEY,KAAK,CAChB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,WAAW,EACnB,GAAG,EAAE,QAAQ,CAAC,GAAG,EACjB,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,IAAI,CAAC,CAMf;IAEY,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,CAAC,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,CAQ5F;IAEY,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,CAAC,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,CAS9F;IAEY,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,CAAC,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAM3F;IAEY,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAMvE;IAEY,WAAW,CACtB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,WAAW,EACnB,GAAG,EAAE,QAAQ,CAAC,GAAG,GAChB,OAAO,CAAC,eAAe,CAAC,CAa1B;IAEY,WAAW,CACtB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,WAAW,EACnB,GAAG,EAAE,QAAQ,CAAC,GAAG,GAChB,OAAO,CAAC,eAAe,CAAC,CAa1B;IAEY,iBAAiB,CAC5B,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,WAAW,EACnB,GAAG,EAAE,QAAQ,CAAC,GAAG,EACjB,GAAG,EAAE,6BAA6B,GACjC,OAAO,CAAC,IAAI,CAAC,CAsBf;CACF"}
|
package/dist/src/_storage.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import * as v from "./_valibot.js";
|
|
2
|
-
import { StorageIsNotOpenError, ReadableStreamNotSupportedError, WritableStreamNotSupportedError, } from "./errors.js";
|
|
3
|
-
export default class UniKvsStorage {
|
|
4
|
-
constructor(io) {
|
|
5
|
-
this.io = io;
|
|
6
|
-
this.managed = false;
|
|
7
|
-
}
|
|
8
|
-
async open(context, signal) {
|
|
9
|
-
if (typeof this.io.open !== "function") {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
if (!this.io.isOpen) {
|
|
13
|
-
this.managed = true;
|
|
14
|
-
await this.io.open({ signal, context });
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
async close(context, signal) {
|
|
18
|
-
if (typeof this.io.close !== "function") {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
if (this.io.isOpen && this.managed) {
|
|
22
|
-
await this.io.close({ signal, context });
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
async write(context, signal, key, data) {
|
|
26
|
-
if (!this.io.isOpen) {
|
|
27
|
-
throw new StorageIsNotOpenError({ name: this.io.name });
|
|
28
|
-
}
|
|
29
|
-
await this.io.write({ key, data, signal, context });
|
|
30
|
-
}
|
|
31
|
-
async read(context, signal, key) {
|
|
32
|
-
if (!this.io.isOpen) {
|
|
33
|
-
throw new StorageIsNotOpenError({ name: this.io.name });
|
|
34
|
-
}
|
|
35
|
-
const output = await this.io.read({ key, signal, context });
|
|
36
|
-
return output;
|
|
37
|
-
}
|
|
38
|
-
async exists(context, signal, key) {
|
|
39
|
-
if (!this.io.isOpen) {
|
|
40
|
-
throw new StorageIsNotOpenError({ name: this.io.name });
|
|
41
|
-
}
|
|
42
|
-
const output = await this.io.exists({ key, signal, context });
|
|
43
|
-
const parsed = Boolean(output);
|
|
44
|
-
return parsed;
|
|
45
|
-
}
|
|
46
|
-
async delete(context, signal, key) {
|
|
47
|
-
if (!this.io.isOpen) {
|
|
48
|
-
throw new StorageIsNotOpenError({ name: this.io.name });
|
|
49
|
-
}
|
|
50
|
-
await this.io.delete({ key, signal, context });
|
|
51
|
-
}
|
|
52
|
-
async clear(context, signal) {
|
|
53
|
-
if (!this.io.isOpen) {
|
|
54
|
-
throw new StorageIsNotOpenError({ name: this.io.name });
|
|
55
|
-
}
|
|
56
|
-
await this.io.clear({ signal, context });
|
|
57
|
-
}
|
|
58
|
-
async getReadable(context, signal, key) {
|
|
59
|
-
if (!this.io.isOpen) {
|
|
60
|
-
throw new StorageIsNotOpenError({ name: this.io.name });
|
|
61
|
-
}
|
|
62
|
-
if (typeof this.io.getReadable !== "function") {
|
|
63
|
-
throw new ReadableStreamNotSupportedError({ name: this.io.name });
|
|
64
|
-
}
|
|
65
|
-
const output = await this.io.getReadable({ key, signal, context });
|
|
66
|
-
const parsed = v.parseOutput(v.instance(ReadableStream), output);
|
|
67
|
-
return parsed;
|
|
68
|
-
}
|
|
69
|
-
async getWritable(context, signal, key) {
|
|
70
|
-
if (!this.io.isOpen) {
|
|
71
|
-
throw new StorageIsNotOpenError({ name: this.io.name });
|
|
72
|
-
}
|
|
73
|
-
if (typeof this.io.getWritable !== "function") {
|
|
74
|
-
throw new WritableStreamNotSupportedError({ name: this.io.name });
|
|
75
|
-
}
|
|
76
|
-
const output = await this.io.getWritable({ key, signal, context });
|
|
77
|
-
const parsed = v.parseOutput(v.instance(WritableStream), output);
|
|
78
|
-
return parsed;
|
|
79
|
-
}
|
|
80
|
-
async onOtherWriteError(context, signal, key, err) {
|
|
81
|
-
if (!this.io.isOpen) {
|
|
82
|
-
throw new StorageIsNotOpenError({ name: this.io.name });
|
|
83
|
-
}
|
|
84
|
-
if (typeof this.io.onOtherWriteError !== "function") {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
await this.io.onOtherWriteError({
|
|
88
|
-
key,
|
|
89
|
-
error: err,
|
|
90
|
-
signal,
|
|
91
|
-
context,
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { IReadableStream } from "@unikvs/core";
|
|
2
|
-
import type { ValueStream } from "./value-stream.types.js";
|
|
3
|
-
/**
|
|
4
|
-
* 与えられた `IReadableStream` を `ValueStream` に変換します。
|
|
5
|
-
*
|
|
6
|
-
* @template T ストリームが保持する値の型です。
|
|
7
|
-
* @param readableStream 変換対象となる `IReadableStream` インスタンスです。
|
|
8
|
-
* @param onAsyncDispose ストリーム破棄時の処理です。
|
|
9
|
-
* @returns 非同期イテレーターが付与された `ValueStream` インスタンスを返します。
|
|
10
|
-
*/
|
|
11
|
-
export default function toValueStream<T>(readableStream: IReadableStream<T>, onAsyncDispose: () => Promise<void>): ValueStream<T>;
|
|
12
|
-
//# sourceMappingURL=_to-value-stream.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_to-value-stream.d.ts","sourceRoot":"","sources":["../../src/_to-value-stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAIpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,CAAC,EACrC,cAAc,EAAE,eAAe,CAAC,CAAC,CAAC,EAClC,cAAc,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAClC,WAAW,CAAC,CAAC,CAAC,CAiGhB"}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { callAsyncableFnOnce } from "call-fn-once";
|
|
2
|
-
import logger from "./_logger.js";
|
|
3
|
-
/**
|
|
4
|
-
* 与えられた `IReadableStream` を `ValueStream` に変換します。
|
|
5
|
-
*
|
|
6
|
-
* @template T ストリームが保持する値の型です。
|
|
7
|
-
* @param readableStream 変換対象となる `IReadableStream` インスタンスです。
|
|
8
|
-
* @param onAsyncDispose ストリーム破棄時の処理です。
|
|
9
|
-
* @returns 非同期イテレーターが付与された `ValueStream` インスタンスを返します。
|
|
10
|
-
*/
|
|
11
|
-
export default function toValueStream(readableStream, onAsyncDispose) {
|
|
12
|
-
const cacheMap = new Map();
|
|
13
|
-
const reader = readableStream.getReader();
|
|
14
|
-
async function disposeValueStream() {
|
|
15
|
-
await callAsyncableFnOnce(cacheMap, "dispose", async () => {
|
|
16
|
-
try {
|
|
17
|
-
await reader.cancel();
|
|
18
|
-
}
|
|
19
|
-
catch (ex) {
|
|
20
|
-
logger.error `Failed to cancel the source stream: ${ex}`;
|
|
21
|
-
}
|
|
22
|
-
await onAsyncDispose();
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
// cancel・エラー・早期 break であっても dispose されるように、readable 側のキャンセルを直接フックしたストリームを返します。
|
|
26
|
-
const valueStream = new ReadableStream({
|
|
27
|
-
async pull(controller) {
|
|
28
|
-
try {
|
|
29
|
-
const { done, value } = await reader.read();
|
|
30
|
-
if (done) {
|
|
31
|
-
// ストリームが正常に完了したことも dispose 対象とし、完了を通知する前に破棄を完了させます。
|
|
32
|
-
await disposeValueStream();
|
|
33
|
-
controller.close();
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
controller.enqueue(value);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
catch (ex) {
|
|
40
|
-
// ソースエラー時も dispose (ロック解放など) を行わないと、ストリームを放棄した consumer に対してキーの I/O ロックがリークします。
|
|
41
|
-
// dispose 自体が失敗しても元の例外の伝播を壊さないように、失敗はログに残すだけにします。
|
|
42
|
-
await disposeValueStream().catch((e) => logger.error `Failed to dispose value stream: ${e}`);
|
|
43
|
-
controller.error(ex);
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
async cancel() {
|
|
47
|
-
await disposeValueStream();
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
const stream = Object.assign(valueStream,
|
|
51
|
-
// AsyncDisposable
|
|
52
|
-
{
|
|
53
|
-
[Symbol.asyncDispose]: disposeValueStream,
|
|
54
|
-
},
|
|
55
|
-
// { dispose(): Promise<void> }
|
|
56
|
-
{
|
|
57
|
-
dispose: disposeValueStream,
|
|
58
|
-
},
|
|
59
|
-
// AsyncIterable<T, void, unknown>
|
|
60
|
-
{
|
|
61
|
-
async *[Symbol.asyncIterator]() {
|
|
62
|
-
const r = this.getReader();
|
|
63
|
-
try {
|
|
64
|
-
// ストリームが終了するまでループを回し、チャンクを読み取ります。
|
|
65
|
-
while (true) {
|
|
66
|
-
const { done, value } = await r.read();
|
|
67
|
-
if (done) {
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
yield value;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
catch (ex) {
|
|
74
|
-
// エラーが発生した場合は、リーダーのキャンセルを試みます。
|
|
75
|
-
try {
|
|
76
|
-
await r.cancel(ex);
|
|
77
|
-
}
|
|
78
|
-
catch (ex) {
|
|
79
|
-
logger.error `Failed to cancel reader: ${ex}`;
|
|
80
|
-
}
|
|
81
|
-
throw ex;
|
|
82
|
-
}
|
|
83
|
-
finally {
|
|
84
|
-
// cancel・エラー・早期 break など完了方法に関係なくストリームを破棄し、キーの読み取りロックがリークしないようにします (2 回目以降は no-op)。
|
|
85
|
-
try {
|
|
86
|
-
await disposeValueStream();
|
|
87
|
-
}
|
|
88
|
-
catch (ex) {
|
|
89
|
-
logger.error `Failed to dispose value stream: ${ex}`;
|
|
90
|
-
}
|
|
91
|
-
// 最後に必ずリーダーのロックを解放し、ストリームを再利用可能な状態にします。
|
|
92
|
-
try {
|
|
93
|
-
r.releaseLock();
|
|
94
|
-
}
|
|
95
|
-
catch (ex) {
|
|
96
|
-
logger.error `Failed to release reader's lock: ${ex}`;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
},
|
|
100
|
-
});
|
|
101
|
-
return stream;
|
|
102
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Context, IDecodable, ITransformer, IEncodable } from "@unikvs/core";
|
|
2
|
-
export default class UniKvsTransformer {
|
|
3
|
-
private readonly tf;
|
|
4
|
-
private managed;
|
|
5
|
-
constructor(tf: ITransformer);
|
|
6
|
-
open(context: Context, signal: AbortSignal): Promise<void>;
|
|
7
|
-
close(context: Context, signal: AbortSignal): Promise<void>;
|
|
8
|
-
encode(context: Context, signal: AbortSignal, data: any): Promise<unknown>;
|
|
9
|
-
decode(context: Context, signal: AbortSignal, data: any): Promise<unknown>;
|
|
10
|
-
getEncodable(context: Context, signal: AbortSignal): Promise<IEncodable>;
|
|
11
|
-
getDecodable(context: Context, signal: AbortSignal): Promise<IDecodable>;
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=_transformer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_transformer.d.ts","sourceRoot":"","sources":["../../src/_transformer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAQlF,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAe;IAElC,OAAO,CAAC,OAAO,CAAU;IAEzB,YAAmB,EAAE,EAAE,YAAY,EAGlC;IAEY,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAStE;IAEY,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAQvE;IAEY,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,CAQtF;IAEY,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,CAQtF;IAEY,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAapF;IAEY,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAapF;CACF"}
|
package/dist/src/_transformer.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { DecodableStreamNotSupportedError, EncodableStreamNotSupportedError, TransformerIsNotOpenError, } from "./errors.js";
|
|
2
|
-
export default class UniKvsTransformer {
|
|
3
|
-
constructor(tf) {
|
|
4
|
-
this.tf = tf;
|
|
5
|
-
this.managed = false;
|
|
6
|
-
}
|
|
7
|
-
async open(context, signal) {
|
|
8
|
-
if (typeof this.tf.open !== "function") {
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
if (!this.tf.isOpen) {
|
|
12
|
-
this.managed = true;
|
|
13
|
-
await this.tf.open({ signal, context });
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
async close(context, signal) {
|
|
17
|
-
if (typeof this.tf.close !== "function") {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
if (this.tf.isOpen && this.managed) {
|
|
21
|
-
await this.tf.close({ signal, context });
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
async encode(context, signal, data) {
|
|
25
|
-
if (!this.tf.isOpen) {
|
|
26
|
-
throw new TransformerIsNotOpenError({ name: this.tf.name });
|
|
27
|
-
}
|
|
28
|
-
const output = await this.tf.encode({ data, signal, context });
|
|
29
|
-
return output;
|
|
30
|
-
}
|
|
31
|
-
async decode(context, signal, data) {
|
|
32
|
-
if (!this.tf.isOpen) {
|
|
33
|
-
throw new TransformerIsNotOpenError({ name: this.tf.name });
|
|
34
|
-
}
|
|
35
|
-
const output = await this.tf.decode({ data, signal, context });
|
|
36
|
-
return output;
|
|
37
|
-
}
|
|
38
|
-
async getEncodable(context, signal) {
|
|
39
|
-
if (!this.tf.isOpen) {
|
|
40
|
-
throw new TransformerIsNotOpenError({ name: this.tf.name });
|
|
41
|
-
}
|
|
42
|
-
if (typeof this.tf.getEncodable !== "function") {
|
|
43
|
-
throw new EncodableStreamNotSupportedError({ name: this.tf.name });
|
|
44
|
-
}
|
|
45
|
-
const output = await this.tf.getEncodable({ signal, context });
|
|
46
|
-
const parsed = output; // TODO(tai-kun): 要検証
|
|
47
|
-
return parsed;
|
|
48
|
-
}
|
|
49
|
-
async getDecodable(context, signal) {
|
|
50
|
-
if (!this.tf.isOpen) {
|
|
51
|
-
throw new TransformerIsNotOpenError({ name: this.tf.name });
|
|
52
|
-
}
|
|
53
|
-
if (typeof this.tf.getDecodable !== "function") {
|
|
54
|
-
throw new DecodableStreamNotSupportedError({ name: this.tf.name });
|
|
55
|
-
}
|
|
56
|
-
const output = await this.tf.getDecodable({ signal, context });
|
|
57
|
-
const parsed = output; // TODO(tai-kun): 要検証
|
|
58
|
-
return parsed;
|
|
59
|
-
}
|
|
60
|
-
}
|
package/dist/src/_valibot.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { type InferOutput, safeParse } from "valibot";
|
|
2
|
-
import { type InvalidInputErrorArgs, type InvalidOutputErrorArgs } from "./errors.js";
|
|
3
|
-
export type { InferInput, InferOutput } from "valibot";
|
|
4
|
-
export { any, omit, pipe, union, number, string, symbol, unknown, instance, minValue, optional, safeInteger, } from "valibot";
|
|
5
|
-
export { array, tuple, object, record, transform } from "@tai-kun/valibot-extra-lab";
|
|
6
|
-
type BaseSchema = typeof safeParse extends (schema: infer S, ...args: any) => any ? S : never;
|
|
7
|
-
export interface IParseInputErrorConstructor {
|
|
8
|
-
new (args: InvalidInputErrorArgs): Error;
|
|
9
|
-
}
|
|
10
|
-
export declare function parseInput<const TSchema extends BaseSchema>(schema: TSchema, value: unknown, Error?: IParseInputErrorConstructor): InferOutput<TSchema>;
|
|
11
|
-
export interface ParseOutputErrorConstructor {
|
|
12
|
-
new (args: InvalidOutputErrorArgs): Error;
|
|
13
|
-
}
|
|
14
|
-
export declare function parseOutput<const TSchema extends BaseSchema>(schema: TSchema, value: unknown, Error?: ParseOutputErrorConstructor): InferOutput<TSchema>;
|
|
15
|
-
//# sourceMappingURL=_valibot.d.ts.map
|