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
package/src/index.ts
CHANGED
|
@@ -1,52 +1,72 @@
|
|
|
1
|
-
export type * from "./context.types.js";
|
|
2
|
-
|
|
3
1
|
export type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
EncodableStreamNotSupportedErrorMeta,
|
|
2
|
+
Issue,
|
|
3
|
+
KeyNotFoundErrorArgs,
|
|
4
|
+
KeyNotFoundErrorMeta,
|
|
8
5
|
InvalidInputErrorArgs,
|
|
9
6
|
InvalidInputErrorMeta,
|
|
10
7
|
InvalidOutputErrorArgs,
|
|
11
8
|
InvalidOutputErrorMeta,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
StorageIsNotOpenErrorArgs,
|
|
10
|
+
StorageIsNotOpenErrorMeta,
|
|
11
|
+
MiddlewareIsNotOpenErrorArgs,
|
|
12
|
+
MiddlewareIsNotOpenErrorMeta,
|
|
13
|
+
MiddlewareNextNotCalledErrorArgs,
|
|
14
|
+
MiddlewareNextNotCalledErrorMeta,
|
|
15
|
+
MiddlewareNextNotAwaitedErrorArgs,
|
|
16
|
+
MiddlewareNextNotAwaitedErrorMeta,
|
|
15
17
|
PluginOperationAggregateErrorArgs,
|
|
16
18
|
PluginOperationAggregateErrorMeta,
|
|
19
|
+
MultipartWriteNotSupportedErrorArgs,
|
|
20
|
+
MultipartWriteNotSupportedErrorMeta,
|
|
17
21
|
ReadableStreamNotSupportedErrorArgs,
|
|
18
22
|
ReadableStreamNotSupportedErrorMeta,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
StreamDecodingNotSupportedErrorArgs,
|
|
24
|
+
StreamDecodingNotSupportedErrorMeta,
|
|
25
|
+
StreamEncodingNotSupportedErrorArgs,
|
|
26
|
+
StreamEncodingNotSupportedErrorMeta,
|
|
23
27
|
WritableStreamNotSupportedErrorArgs,
|
|
24
28
|
WritableStreamNotSupportedErrorMeta,
|
|
29
|
+
MiddlewareDestinationFrozenErrorArgs,
|
|
30
|
+
MiddlewareDestinationFrozenErrorMeta,
|
|
31
|
+
MiddlewareDestinationMissingErrorArgs,
|
|
32
|
+
MiddlewareDestinationMissingErrorMeta,
|
|
33
|
+
MiddlewareNextCalledMultipleTimesErrorArgs,
|
|
34
|
+
MiddlewareNextCalledMultipleTimesErrorMeta,
|
|
25
35
|
} from "./errors.js";
|
|
26
36
|
export {
|
|
27
|
-
|
|
28
|
-
EncodableStreamNotSupportedError,
|
|
37
|
+
KeyNotFoundError,
|
|
29
38
|
InvalidInputError,
|
|
39
|
+
UniKvsIsOpenError,
|
|
30
40
|
InvalidOutputError,
|
|
31
|
-
InvalidUsageErrorBase,
|
|
32
|
-
KeyNotFoundError,
|
|
33
41
|
MissingStorageError,
|
|
42
|
+
UniKvsIsNotOpenError,
|
|
43
|
+
InvalidUsageErrorBase,
|
|
44
|
+
StorageIsNotOpenError,
|
|
45
|
+
MiddlewareIsNotOpenError,
|
|
46
|
+
MiddlewareNextNotCalledError,
|
|
47
|
+
MiddlewareNextNotAwaitedError,
|
|
34
48
|
PluginOperationAggregateError,
|
|
49
|
+
MultipartWriteNotSupportedError,
|
|
35
50
|
ReadableStreamNotSupportedError,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
TransformerRegistrationError,
|
|
39
|
-
UniKvsIsNotOpenError,
|
|
40
|
-
UniKvsIsOpenError,
|
|
51
|
+
StreamDecodingNotSupportedError,
|
|
52
|
+
StreamEncodingNotSupportedError,
|
|
41
53
|
WritableStreamNotSupportedError,
|
|
54
|
+
MiddlewareDestinationFrozenError,
|
|
55
|
+
MiddlewareDestinationMissingError,
|
|
56
|
+
MiddlewareNextCalledMultipleTimesError,
|
|
42
57
|
} from "./errors.js";
|
|
43
58
|
|
|
44
|
-
export type * from "./
|
|
45
|
-
|
|
59
|
+
export type * from "./types.js";
|
|
60
|
+
|
|
61
|
+
export type * from "./unikvs-branch.js";
|
|
62
|
+
export { default as UniKvsBranch, default as Branch } from "./unikvs-branch.js";
|
|
63
|
+
|
|
64
|
+
export type * from "./unikvs-builder.js";
|
|
65
|
+
export { default as UniKvsBuilder, default as Builder } from "./unikvs-builder.js";
|
|
46
66
|
|
|
47
67
|
export type * from "./unikvs.js";
|
|
48
68
|
export { default as UniKvs } from "./unikvs.js";
|
|
49
69
|
|
|
50
|
-
export type * from "./
|
|
70
|
+
export type * from "./unikvs.types.js";
|
|
51
71
|
|
|
52
|
-
export
|
|
72
|
+
export * from "./value-schemas.js";
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#value-stream)
|
|
3
|
+
*/
|
|
4
|
+
export interface IValueStream<T = any>
|
|
5
|
+
extends
|
|
6
|
+
Omit<ReadableStream, keyof AsyncDisposable | keyof AsyncIterable<unknown>>,
|
|
7
|
+
AsyncDisposable,
|
|
8
|
+
AsyncIterable<T, void, unknown> {
|
|
9
|
+
/**
|
|
10
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#value-stream)
|
|
11
|
+
*/
|
|
12
|
+
dispose: (this: void) => Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
import type { IStorage, IMiddleware } from "@unikvs/core";
|
|
2
|
+
|
|
3
|
+
import UniKvsMiddleware from "./_middleware.js";
|
|
4
|
+
import UniKvsStorage from "./_storage.js";
|
|
5
|
+
import type {
|
|
6
|
+
$IsUnknown,
|
|
7
|
+
$CheckForkDecodeData,
|
|
8
|
+
$CheckForkEncodeData,
|
|
9
|
+
$InferReadDataOutput,
|
|
10
|
+
$InferWriteDataInput,
|
|
11
|
+
$CheckForkDecodeChunk,
|
|
12
|
+
$CheckForkEncodeChunk,
|
|
13
|
+
$InferDecodeDataInput,
|
|
14
|
+
$InferEncodeDataInput,
|
|
15
|
+
$InferReadChunkOutput,
|
|
16
|
+
$InferWriteChunkInput,
|
|
17
|
+
$InferDecodeChunkInput,
|
|
18
|
+
$InferDecodeDataOutput,
|
|
19
|
+
$InferEncodeChunkInput,
|
|
20
|
+
$InferEncodeDataOutput,
|
|
21
|
+
$InferDecodeChunkOutput,
|
|
22
|
+
$InferEncodeChunkOutput,
|
|
23
|
+
} from "./_types.js";
|
|
24
|
+
import { type BranchState, branchStates, appendForkDestinations } from "./_unikvs-branch.js";
|
|
25
|
+
import type { Value } from "./value-schemas.js";
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#value-types)
|
|
29
|
+
*/
|
|
30
|
+
export type KeyValueMapping<T = any> = Readonly<Record<string, Value<T>>>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#builder)
|
|
34
|
+
*/
|
|
35
|
+
export interface IUniKvsBranch<
|
|
36
|
+
TKeyValueMapping extends KeyValueMapping = KeyValueMapping,
|
|
37
|
+
TBranchChunkInput = any,
|
|
38
|
+
TBranchChunkOutput = any,
|
|
39
|
+
THeadEncodeDataInput = unknown,
|
|
40
|
+
THeadDecodeDataOutput = unknown,
|
|
41
|
+
THeadEncodeChunkInput = unknown,
|
|
42
|
+
THeadDecodeChunkOutput = unknown,
|
|
43
|
+
TLastDecodeDataInput = any,
|
|
44
|
+
TLastEncodeDataOutput = any,
|
|
45
|
+
TLastDecodeChunkInput = any,
|
|
46
|
+
TLastEncodeChunkOutput = any,
|
|
47
|
+
TBranchHasPersist extends boolean = false,
|
|
48
|
+
> {
|
|
49
|
+
fork<
|
|
50
|
+
TSubChunkInput,
|
|
51
|
+
TSubChunkOutput,
|
|
52
|
+
TSubHeadEncodeDataInput,
|
|
53
|
+
TSubHeadDecodeDataOutput,
|
|
54
|
+
TSubHeadEncodeChunkInput,
|
|
55
|
+
TSubHeadDecodeChunkOutput,
|
|
56
|
+
TSubLastDecodeDataInput,
|
|
57
|
+
TSubLastEncodeDataOutput,
|
|
58
|
+
TSubLastDecodeChunkInput,
|
|
59
|
+
TSubLastEncodeChunkOutput,
|
|
60
|
+
TSubHasPersist extends boolean,
|
|
61
|
+
>(
|
|
62
|
+
branch: IUniKvsBranch<
|
|
63
|
+
any,
|
|
64
|
+
TSubChunkInput,
|
|
65
|
+
TSubChunkOutput,
|
|
66
|
+
TSubHeadEncodeDataInput,
|
|
67
|
+
TSubHeadDecodeDataOutput,
|
|
68
|
+
TSubHeadEncodeChunkInput,
|
|
69
|
+
TSubHeadDecodeChunkOutput,
|
|
70
|
+
TSubLastDecodeDataInput,
|
|
71
|
+
TSubLastEncodeDataOutput,
|
|
72
|
+
TSubLastDecodeChunkInput,
|
|
73
|
+
TSubLastEncodeChunkOutput,
|
|
74
|
+
TSubHasPersist
|
|
75
|
+
> &
|
|
76
|
+
(TSubHasPersist extends true
|
|
77
|
+
? $CheckForkEncodeData<TLastEncodeDataOutput, TSubHeadEncodeDataInput>
|
|
78
|
+
: unknown) &
|
|
79
|
+
(TSubHasPersist extends true
|
|
80
|
+
? $CheckForkDecodeData<TLastDecodeDataInput, TSubHeadDecodeDataOutput>
|
|
81
|
+
: unknown) &
|
|
82
|
+
(TSubHasPersist extends true
|
|
83
|
+
? $CheckForkEncodeChunk<TLastEncodeChunkOutput, TSubHeadEncodeChunkInput>
|
|
84
|
+
: unknown) &
|
|
85
|
+
(TSubHasPersist extends true
|
|
86
|
+
? $CheckForkDecodeChunk<TLastDecodeChunkInput, TSubHeadDecodeChunkOutput>
|
|
87
|
+
: unknown),
|
|
88
|
+
): IUniKvsBranch<
|
|
89
|
+
TKeyValueMapping,
|
|
90
|
+
TSubHasPersist extends true
|
|
91
|
+
? [TBranchChunkInput] extends [never]
|
|
92
|
+
? never
|
|
93
|
+
: [TSubChunkInput] extends [never]
|
|
94
|
+
? never
|
|
95
|
+
: TBranchChunkInput
|
|
96
|
+
: TBranchChunkInput,
|
|
97
|
+
TSubHasPersist extends true
|
|
98
|
+
? [TBranchChunkOutput] extends [never]
|
|
99
|
+
? never
|
|
100
|
+
: [TSubChunkOutput] extends [never]
|
|
101
|
+
? never
|
|
102
|
+
: TBranchChunkOutput
|
|
103
|
+
: TBranchChunkOutput,
|
|
104
|
+
TSubHasPersist extends true
|
|
105
|
+
? $IsUnknown<THeadEncodeDataInput> extends true
|
|
106
|
+
? TSubHeadEncodeDataInput
|
|
107
|
+
: THeadEncodeDataInput
|
|
108
|
+
: THeadEncodeDataInput,
|
|
109
|
+
TSubHasPersist extends true
|
|
110
|
+
? $IsUnknown<THeadDecodeDataOutput> extends true
|
|
111
|
+
? TSubHeadDecodeDataOutput
|
|
112
|
+
: THeadDecodeDataOutput
|
|
113
|
+
: THeadDecodeDataOutput,
|
|
114
|
+
TSubHasPersist extends true
|
|
115
|
+
? $IsUnknown<THeadEncodeChunkInput> extends true
|
|
116
|
+
? TSubHeadEncodeChunkInput
|
|
117
|
+
: THeadEncodeChunkInput
|
|
118
|
+
: THeadEncodeChunkInput,
|
|
119
|
+
TSubHasPersist extends true
|
|
120
|
+
? $IsUnknown<THeadDecodeChunkOutput> extends true
|
|
121
|
+
? TSubHeadDecodeChunkOutput
|
|
122
|
+
: THeadDecodeChunkOutput
|
|
123
|
+
: THeadDecodeChunkOutput,
|
|
124
|
+
TLastDecodeDataInput,
|
|
125
|
+
TLastEncodeDataOutput,
|
|
126
|
+
TLastDecodeChunkInput,
|
|
127
|
+
TLastEncodeChunkOutput,
|
|
128
|
+
TBranchHasPersist extends true ? true : TSubHasPersist
|
|
129
|
+
>;
|
|
130
|
+
|
|
131
|
+
use<
|
|
132
|
+
TMiddleware extends IMiddleware<
|
|
133
|
+
[TLastEncodeDataOutput] extends [never] ? any : TLastEncodeDataOutput,
|
|
134
|
+
any,
|
|
135
|
+
[TLastEncodeChunkOutput] extends [never] ? any : TLastEncodeChunkOutput
|
|
136
|
+
>,
|
|
137
|
+
>(
|
|
138
|
+
middleware: TMiddleware,
|
|
139
|
+
): IUniKvsBranch<
|
|
140
|
+
TKeyValueMapping,
|
|
141
|
+
[TBranchChunkInput] extends [never]
|
|
142
|
+
? never
|
|
143
|
+
: [$InferDecodeChunkInput<TMiddleware>] extends [never]
|
|
144
|
+
? never
|
|
145
|
+
: TBranchChunkInput,
|
|
146
|
+
[TBranchChunkOutput] extends [never]
|
|
147
|
+
? never
|
|
148
|
+
: [$InferEncodeChunkOutput<TMiddleware>] extends [never]
|
|
149
|
+
? never
|
|
150
|
+
: TBranchChunkOutput,
|
|
151
|
+
$IsUnknown<THeadEncodeDataInput> extends true
|
|
152
|
+
? $InferEncodeDataInput<TMiddleware>
|
|
153
|
+
: THeadEncodeDataInput,
|
|
154
|
+
$IsUnknown<THeadDecodeDataOutput> extends true
|
|
155
|
+
? $InferDecodeDataOutput<TMiddleware>
|
|
156
|
+
: THeadDecodeDataOutput,
|
|
157
|
+
$IsUnknown<THeadEncodeChunkInput> extends true
|
|
158
|
+
? $InferEncodeChunkInput<TMiddleware>
|
|
159
|
+
: THeadEncodeChunkInput,
|
|
160
|
+
$IsUnknown<THeadDecodeChunkOutput> extends true
|
|
161
|
+
? $InferDecodeChunkOutput<TMiddleware>
|
|
162
|
+
: THeadDecodeChunkOutput,
|
|
163
|
+
$InferDecodeDataInput<TMiddleware>,
|
|
164
|
+
$InferEncodeDataOutput<TMiddleware>,
|
|
165
|
+
$InferDecodeChunkInput<TMiddleware>,
|
|
166
|
+
$InferEncodeChunkOutput<TMiddleware>,
|
|
167
|
+
TBranchHasPersist
|
|
168
|
+
>;
|
|
169
|
+
|
|
170
|
+
persist<
|
|
171
|
+
TStorage extends IStorage<
|
|
172
|
+
[TLastEncodeDataOutput] extends [never] ? any : TLastEncodeDataOutput,
|
|
173
|
+
[TLastDecodeDataInput] extends [never] ? any : TLastDecodeDataInput,
|
|
174
|
+
[TLastEncodeChunkOutput] extends [never] ? any : TLastEncodeChunkOutput,
|
|
175
|
+
[TLastDecodeChunkInput] extends [never] ? any : TLastDecodeChunkInput
|
|
176
|
+
>,
|
|
177
|
+
>(
|
|
178
|
+
storage: TStorage,
|
|
179
|
+
): IUniKvsBranch<
|
|
180
|
+
TKeyValueMapping,
|
|
181
|
+
[TBranchChunkInput] extends [never]
|
|
182
|
+
? never
|
|
183
|
+
: [$InferWriteChunkInput<TStorage>] extends [never]
|
|
184
|
+
? never
|
|
185
|
+
: TBranchChunkInput,
|
|
186
|
+
[TBranchChunkOutput] extends [never]
|
|
187
|
+
? never
|
|
188
|
+
: [$InferReadChunkOutput<TStorage>] extends [never]
|
|
189
|
+
? never
|
|
190
|
+
: TBranchChunkOutput,
|
|
191
|
+
$IsUnknown<THeadEncodeDataInput> extends true
|
|
192
|
+
? $InferWriteDataInput<TStorage>
|
|
193
|
+
: THeadEncodeDataInput,
|
|
194
|
+
$IsUnknown<THeadDecodeDataOutput> extends true
|
|
195
|
+
? $InferReadDataOutput<TStorage>
|
|
196
|
+
: THeadDecodeDataOutput,
|
|
197
|
+
$IsUnknown<THeadEncodeChunkInput> extends true
|
|
198
|
+
? $InferWriteChunkInput<TStorage>
|
|
199
|
+
: THeadEncodeChunkInput,
|
|
200
|
+
$IsUnknown<THeadDecodeChunkOutput> extends true
|
|
201
|
+
? $InferReadChunkOutput<TStorage>
|
|
202
|
+
: THeadDecodeChunkOutput,
|
|
203
|
+
TLastDecodeDataInput,
|
|
204
|
+
TLastEncodeDataOutput,
|
|
205
|
+
TLastDecodeChunkInput,
|
|
206
|
+
TLastEncodeChunkOutput,
|
|
207
|
+
true
|
|
208
|
+
>;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#builder)
|
|
213
|
+
*/
|
|
214
|
+
export default class UniKvsBranch<
|
|
215
|
+
TKeyValueMapping extends KeyValueMapping = KeyValueMapping,
|
|
216
|
+
TBranchChunkInput = any,
|
|
217
|
+
TBranchChunkOutput = any,
|
|
218
|
+
THeadEncodeDataInput = unknown,
|
|
219
|
+
THeadDecodeDataOutput = unknown,
|
|
220
|
+
THeadEncodeChunkInput = unknown,
|
|
221
|
+
THeadDecodeChunkOutput = unknown,
|
|
222
|
+
TLastDecodeDataInput = any,
|
|
223
|
+
TLastEncodeDataOutput = any,
|
|
224
|
+
TLastDecodeChunkInput = any,
|
|
225
|
+
TLastEncodeChunkOutput = any,
|
|
226
|
+
TBranchHasPersist extends boolean = false,
|
|
227
|
+
> implements IUniKvsBranch<
|
|
228
|
+
TKeyValueMapping,
|
|
229
|
+
TBranchChunkInput,
|
|
230
|
+
TBranchChunkOutput,
|
|
231
|
+
THeadEncodeDataInput,
|
|
232
|
+
THeadDecodeDataOutput,
|
|
233
|
+
THeadEncodeChunkInput,
|
|
234
|
+
THeadDecodeChunkOutput,
|
|
235
|
+
TLastDecodeDataInput,
|
|
236
|
+
TLastEncodeDataOutput,
|
|
237
|
+
TLastDecodeChunkInput,
|
|
238
|
+
TLastEncodeChunkOutput,
|
|
239
|
+
TBranchHasPersist
|
|
240
|
+
> {
|
|
241
|
+
public constructor() {
|
|
242
|
+
branchStates.set(this, {
|
|
243
|
+
middlewares: [],
|
|
244
|
+
destinations: [],
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* この分岐の構築状態を取得します。
|
|
250
|
+
*
|
|
251
|
+
* @returns 構築状態を返します。
|
|
252
|
+
*/
|
|
253
|
+
#branchState(): BranchState {
|
|
254
|
+
const state = branchStates.get(this);
|
|
255
|
+
|
|
256
|
+
if (state === undefined) {
|
|
257
|
+
throw new Error("分岐の構築状態が見つかりません。");
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
return state;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
public fork<
|
|
264
|
+
TSubChunkInput,
|
|
265
|
+
TSubChunkOutput,
|
|
266
|
+
TSubHeadEncodeDataInput,
|
|
267
|
+
TSubHeadDecodeDataOutput,
|
|
268
|
+
TSubHeadEncodeChunkInput,
|
|
269
|
+
TSubHeadDecodeChunkOutput,
|
|
270
|
+
TSubLastDecodeDataInput,
|
|
271
|
+
TSubLastEncodeDataOutput,
|
|
272
|
+
TSubLastDecodeChunkInput,
|
|
273
|
+
TSubLastEncodeChunkOutput,
|
|
274
|
+
TSubHasPersist extends boolean,
|
|
275
|
+
>(
|
|
276
|
+
branch: IUniKvsBranch<
|
|
277
|
+
any,
|
|
278
|
+
TSubChunkInput,
|
|
279
|
+
TSubChunkOutput,
|
|
280
|
+
TSubHeadEncodeDataInput,
|
|
281
|
+
TSubHeadDecodeDataOutput,
|
|
282
|
+
TSubHeadEncodeChunkInput,
|
|
283
|
+
TSubHeadDecodeChunkOutput,
|
|
284
|
+
TSubLastDecodeDataInput,
|
|
285
|
+
TSubLastEncodeDataOutput,
|
|
286
|
+
TSubLastDecodeChunkInput,
|
|
287
|
+
TSubLastEncodeChunkOutput,
|
|
288
|
+
TSubHasPersist
|
|
289
|
+
> &
|
|
290
|
+
(TSubHasPersist extends true
|
|
291
|
+
? $CheckForkEncodeData<TLastEncodeDataOutput, TSubHeadEncodeDataInput>
|
|
292
|
+
: unknown) &
|
|
293
|
+
(TSubHasPersist extends true
|
|
294
|
+
? $CheckForkDecodeData<TLastDecodeDataInput, TSubHeadDecodeDataOutput>
|
|
295
|
+
: unknown) &
|
|
296
|
+
(TSubHasPersist extends true
|
|
297
|
+
? $CheckForkEncodeChunk<TLastEncodeChunkOutput, TSubHeadEncodeChunkInput>
|
|
298
|
+
: unknown) &
|
|
299
|
+
(TSubHasPersist extends true
|
|
300
|
+
? $CheckForkDecodeChunk<TLastDecodeChunkInput, TSubHeadDecodeChunkOutput>
|
|
301
|
+
: unknown),
|
|
302
|
+
): IUniKvsBranch<
|
|
303
|
+
TKeyValueMapping,
|
|
304
|
+
TSubHasPersist extends true
|
|
305
|
+
? [TBranchChunkInput] extends [never]
|
|
306
|
+
? never
|
|
307
|
+
: [TSubChunkInput] extends [never]
|
|
308
|
+
? never
|
|
309
|
+
: TBranchChunkInput
|
|
310
|
+
: TBranchChunkInput,
|
|
311
|
+
TSubHasPersist extends true
|
|
312
|
+
? [TBranchChunkOutput] extends [never]
|
|
313
|
+
? never
|
|
314
|
+
: [TSubChunkOutput] extends [never]
|
|
315
|
+
? never
|
|
316
|
+
: TBranchChunkOutput
|
|
317
|
+
: TBranchChunkOutput,
|
|
318
|
+
TSubHasPersist extends true
|
|
319
|
+
? $IsUnknown<THeadEncodeDataInput> extends true
|
|
320
|
+
? TSubHeadEncodeDataInput
|
|
321
|
+
: THeadEncodeDataInput
|
|
322
|
+
: THeadEncodeDataInput,
|
|
323
|
+
TSubHasPersist extends true
|
|
324
|
+
? $IsUnknown<THeadDecodeDataOutput> extends true
|
|
325
|
+
? TSubHeadDecodeDataOutput
|
|
326
|
+
: THeadDecodeDataOutput
|
|
327
|
+
: THeadDecodeDataOutput,
|
|
328
|
+
TSubHasPersist extends true
|
|
329
|
+
? $IsUnknown<THeadEncodeChunkInput> extends true
|
|
330
|
+
? TSubHeadEncodeChunkInput
|
|
331
|
+
: THeadEncodeChunkInput
|
|
332
|
+
: THeadEncodeChunkInput,
|
|
333
|
+
TSubHasPersist extends true
|
|
334
|
+
? $IsUnknown<THeadDecodeChunkOutput> extends true
|
|
335
|
+
? TSubHeadDecodeChunkOutput
|
|
336
|
+
: THeadDecodeChunkOutput
|
|
337
|
+
: THeadDecodeChunkOutput,
|
|
338
|
+
TLastDecodeDataInput,
|
|
339
|
+
TLastEncodeDataOutput,
|
|
340
|
+
TLastDecodeChunkInput,
|
|
341
|
+
TLastEncodeChunkOutput,
|
|
342
|
+
TBranchHasPersist extends true ? true : TSubHasPersist
|
|
343
|
+
>;
|
|
344
|
+
public fork(branch: IUniKvsBranch): IUniKvsBranch {
|
|
345
|
+
const state = this.#branchState();
|
|
346
|
+
appendForkDestinations(state.destinations, state.middlewares, branch);
|
|
347
|
+
|
|
348
|
+
return this;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
public use<
|
|
352
|
+
TMiddleware extends IMiddleware<
|
|
353
|
+
[TLastEncodeDataOutput] extends [never] ? any : TLastEncodeDataOutput,
|
|
354
|
+
any,
|
|
355
|
+
[TLastEncodeChunkOutput] extends [never] ? any : TLastEncodeChunkOutput
|
|
356
|
+
>,
|
|
357
|
+
>(
|
|
358
|
+
middleware: TMiddleware,
|
|
359
|
+
): IUniKvsBranch<
|
|
360
|
+
TKeyValueMapping,
|
|
361
|
+
[TBranchChunkInput] extends [never]
|
|
362
|
+
? never
|
|
363
|
+
: [$InferDecodeChunkInput<TMiddleware>] extends [never]
|
|
364
|
+
? never
|
|
365
|
+
: TBranchChunkInput,
|
|
366
|
+
[TBranchChunkOutput] extends [never]
|
|
367
|
+
? never
|
|
368
|
+
: [$InferEncodeChunkOutput<TMiddleware>] extends [never]
|
|
369
|
+
? never
|
|
370
|
+
: TBranchChunkOutput,
|
|
371
|
+
$IsUnknown<THeadEncodeDataInput> extends true
|
|
372
|
+
? $InferEncodeDataInput<TMiddleware>
|
|
373
|
+
: THeadEncodeDataInput,
|
|
374
|
+
$IsUnknown<THeadDecodeDataOutput> extends true
|
|
375
|
+
? $InferDecodeDataOutput<TMiddleware>
|
|
376
|
+
: THeadDecodeDataOutput,
|
|
377
|
+
$IsUnknown<THeadEncodeChunkInput> extends true
|
|
378
|
+
? $InferEncodeChunkInput<TMiddleware>
|
|
379
|
+
: THeadEncodeChunkInput,
|
|
380
|
+
$IsUnknown<THeadDecodeChunkOutput> extends true
|
|
381
|
+
? $InferDecodeChunkOutput<TMiddleware>
|
|
382
|
+
: THeadDecodeChunkOutput,
|
|
383
|
+
$InferDecodeDataInput<TMiddleware>,
|
|
384
|
+
$InferEncodeDataOutput<TMiddleware>,
|
|
385
|
+
$InferDecodeChunkInput<TMiddleware>,
|
|
386
|
+
$InferEncodeChunkOutput<TMiddleware>,
|
|
387
|
+
TBranchHasPersist
|
|
388
|
+
>;
|
|
389
|
+
public use(middleware: IMiddleware): IUniKvsBranch {
|
|
390
|
+
const state = this.#branchState();
|
|
391
|
+
state.middlewares.push(UniKvsMiddleware.from(middleware));
|
|
392
|
+
|
|
393
|
+
return this;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
public persist<
|
|
397
|
+
TStorage extends IStorage<
|
|
398
|
+
[TLastEncodeDataOutput] extends [never] ? any : TLastEncodeDataOutput,
|
|
399
|
+
[TLastDecodeDataInput] extends [never] ? any : TLastDecodeDataInput,
|
|
400
|
+
[TLastEncodeChunkOutput] extends [never] ? any : TLastEncodeChunkOutput,
|
|
401
|
+
[TLastDecodeChunkInput] extends [never] ? any : TLastDecodeChunkInput
|
|
402
|
+
>,
|
|
403
|
+
>(
|
|
404
|
+
storage: TStorage,
|
|
405
|
+
): IUniKvsBranch<
|
|
406
|
+
TKeyValueMapping,
|
|
407
|
+
[TBranchChunkInput] extends [never]
|
|
408
|
+
? never
|
|
409
|
+
: [$InferWriteChunkInput<TStorage>] extends [never]
|
|
410
|
+
? never
|
|
411
|
+
: TBranchChunkInput,
|
|
412
|
+
[TBranchChunkOutput] extends [never]
|
|
413
|
+
? never
|
|
414
|
+
: [$InferReadChunkOutput<TStorage>] extends [never]
|
|
415
|
+
? never
|
|
416
|
+
: TBranchChunkOutput,
|
|
417
|
+
$IsUnknown<THeadEncodeDataInput> extends true
|
|
418
|
+
? $InferWriteDataInput<TStorage>
|
|
419
|
+
: THeadEncodeDataInput,
|
|
420
|
+
$IsUnknown<THeadDecodeDataOutput> extends true
|
|
421
|
+
? $InferReadDataOutput<TStorage>
|
|
422
|
+
: THeadDecodeDataOutput,
|
|
423
|
+
$IsUnknown<THeadEncodeChunkInput> extends true
|
|
424
|
+
? $InferWriteChunkInput<TStorage>
|
|
425
|
+
: THeadEncodeChunkInput,
|
|
426
|
+
$IsUnknown<THeadDecodeChunkOutput> extends true
|
|
427
|
+
? $InferReadChunkOutput<TStorage>
|
|
428
|
+
: THeadDecodeChunkOutput,
|
|
429
|
+
TLastDecodeDataInput,
|
|
430
|
+
TLastEncodeDataOutput,
|
|
431
|
+
TLastDecodeChunkInput,
|
|
432
|
+
TLastEncodeChunkOutput,
|
|
433
|
+
true
|
|
434
|
+
>;
|
|
435
|
+
public persist(storage: IStorage): IUniKvsBranch {
|
|
436
|
+
const state = this.#branchState();
|
|
437
|
+
state.destinations.push({
|
|
438
|
+
storage: UniKvsStorage.from(storage),
|
|
439
|
+
// 登録時点のチェーンをスナップショットして保持するため、以降の use はこの登録に影響しません。
|
|
440
|
+
middlewares: [...state.middlewares],
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
return this;
|
|
444
|
+
}
|
|
445
|
+
}
|