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
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.types.d.ts","sourceRoot":"","sources":["../../src/utils.types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC"}
|
package/dist/src/utils.types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#value-stream)
|
|
3
|
-
*/
|
|
4
|
-
export interface ValueStream<T = any> extends Omit<ReadableStream, keyof AsyncDisposable | keyof AsyncIterable<unknown>>, AsyncDisposable, AsyncIterable<T, void, unknown> {
|
|
5
|
-
/**
|
|
6
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#value-stream)
|
|
7
|
-
*/
|
|
8
|
-
dispose: (this: void) => Promise<void>;
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=value-stream.types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"value-stream.types.d.ts","sourceRoot":"","sources":["../../src/value-stream.types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,GAAG,CAClC,SACE,IAAI,CAAC,cAAc,EAAE,MAAM,eAAe,GAAG,MAAM,aAAa,CAAC,OAAO,CAAC,CAAC,EAC1E,eAAe,EACf,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC;IACjC;;OAEG;IACH,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACxC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Variables } from "@unikvs/core";
|
|
2
|
-
import type { ValueOf } from "./utils.types.js";
|
|
3
|
-
/**
|
|
4
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#variables-and-cancellation)
|
|
5
|
-
*/
|
|
6
|
-
export type VariableEntry = readonly [key: keyof Variables, value: ValueOf<Variables>];
|
|
7
|
-
/**
|
|
8
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#variables-and-cancellation)
|
|
9
|
-
*/
|
|
10
|
-
export type VariablesSource = Readonly<Variables> | readonly VariableEntry[];
|
|
11
|
-
//# sourceMappingURL=variables.types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"variables.types.d.ts","sourceRoot":"","sources":["../../src/variables.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEhD;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,SAAS,CAAC,GAAG,EAAE,MAAM,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;AAEvF;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC,SAAS,CAAC,GAAG,SAAS,aAAa,EAAE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/src/_merge-variables.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Variables } from "@unikvs/core";
|
|
2
|
-
|
|
3
|
-
import type { VariablesSource } from "./variables.types.js";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 2 つの Variables オブジェクトを結合します。
|
|
7
|
-
*
|
|
8
|
-
* 基本となる Variables に対して、追加または上書きする変数情報を結合し、新しい Variables オブジェクトを生成して返します。追加する変数情報が配列(キーと値のペアの配列)である場合は、オブジェクトに変換した上で結合処理を行います。
|
|
9
|
-
*
|
|
10
|
-
* @param a ベースとなる読み取り専用の Variables オブジェクトです。
|
|
11
|
-
* @param b 結合する読み取り専用の Variables、または VariablesSource、あるいは undefined です。
|
|
12
|
-
* @returns 結合された新しい Variables オブジェクトです。
|
|
13
|
-
*/
|
|
14
|
-
export default function mergeVariables(
|
|
15
|
-
a: Readonly<Variables>,
|
|
16
|
-
b: Readonly<Variables> | VariablesSource | undefined,
|
|
17
|
-
): Variables {
|
|
18
|
-
return { ...a, ...(Array.isArray(b) ? Object.fromEntries(b) : b) };
|
|
19
|
-
}
|
package/src/_transformer.ts
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import type { Variables, IDecodable, ITransformer, IEncodable } from "@unikvs/core";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
DecodableStreamNotSupportedError,
|
|
5
|
-
EncodableStreamNotSupportedError,
|
|
6
|
-
TransformerIsNotOpenError,
|
|
7
|
-
} from "./errors.js";
|
|
8
|
-
|
|
9
|
-
export default class UniKvsTransformer {
|
|
10
|
-
private readonly tf: ITransformer;
|
|
11
|
-
|
|
12
|
-
private managed: boolean;
|
|
13
|
-
|
|
14
|
-
public constructor(tf: ITransformer) {
|
|
15
|
-
this.tf = tf;
|
|
16
|
-
this.managed = false;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public async open(vars: Variables, signal: AbortSignal): Promise<void> {
|
|
20
|
-
if (typeof this.tf.open !== "function") {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (!this.tf.isOpen) {
|
|
25
|
-
this.managed = true;
|
|
26
|
-
await this.tf.open({ vars, signal });
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public async close(vars: Variables, signal: AbortSignal): Promise<void> {
|
|
31
|
-
if (typeof this.tf.close !== "function") {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (this.tf.isOpen && this.managed) {
|
|
36
|
-
await this.tf.close({ vars, signal });
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
public async encode(vars: Variables, signal: AbortSignal, data: any): Promise<unknown> {
|
|
41
|
-
if (!this.tf.isOpen) {
|
|
42
|
-
throw new TransformerIsNotOpenError({ name: this.tf.name });
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const output = await this.tf.encode({ data, vars, signal });
|
|
46
|
-
|
|
47
|
-
return output;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
public async decode(vars: Variables, signal: AbortSignal, data: any): Promise<unknown> {
|
|
51
|
-
if (!this.tf.isOpen) {
|
|
52
|
-
throw new TransformerIsNotOpenError({ name: this.tf.name });
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const output = await this.tf.decode({ data, vars, signal });
|
|
56
|
-
|
|
57
|
-
return output;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
public async getEncodable(vars: Variables, signal: AbortSignal): Promise<IEncodable> {
|
|
61
|
-
if (!this.tf.isOpen) {
|
|
62
|
-
throw new TransformerIsNotOpenError({ name: this.tf.name });
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (typeof this.tf.getEncodable !== "function") {
|
|
66
|
-
throw new EncodableStreamNotSupportedError({ name: this.tf.name });
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const output = await this.tf.getEncodable({ vars, signal });
|
|
70
|
-
const parsed = output; // TODO(tai-kun): 要検証
|
|
71
|
-
|
|
72
|
-
return parsed;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
public async getDecodable(vars: Variables, signal: AbortSignal): Promise<IDecodable> {
|
|
76
|
-
if (!this.tf.isOpen) {
|
|
77
|
-
throw new TransformerIsNotOpenError({ name: this.tf.name });
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (typeof this.tf.getDecodable !== "function") {
|
|
81
|
-
throw new DecodableStreamNotSupportedError({ name: this.tf.name });
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const output = await this.tf.getDecodable({ vars, signal });
|
|
85
|
-
const parsed = output; // TODO(tai-kun): 要検証
|
|
86
|
-
|
|
87
|
-
return parsed;
|
|
88
|
-
}
|
|
89
|
-
}
|
package/src/unikvs-config.ts
DELETED
|
@@ -1,401 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
IStorage,
|
|
3
|
-
Variables,
|
|
4
|
-
ITransformer,
|
|
5
|
-
IReadableStreamStorage,
|
|
6
|
-
IWritableStreamStorage,
|
|
7
|
-
IDecodableStreamTransformer,
|
|
8
|
-
IEncodableStreamTransformer,
|
|
9
|
-
} from "@unikvs/core";
|
|
10
|
-
|
|
11
|
-
import UniKvsStorage from "./_storage.js";
|
|
12
|
-
import UniKvsTransformer from "./_transformer.js";
|
|
13
|
-
import * as v from "./_valibot.js";
|
|
14
|
-
import {
|
|
15
|
-
type Value,
|
|
16
|
-
type UniKvsSchema,
|
|
17
|
-
type $InferPlainValueData,
|
|
18
|
-
type IValueSchemaResolver,
|
|
19
|
-
type $InferStreamValueChunkData,
|
|
20
|
-
UniKvsSchemaSchema,
|
|
21
|
-
createValueSchemaResolver,
|
|
22
|
-
} from "./_value-schemas.js";
|
|
23
|
-
import { MissingStorageError } from "./errors.js";
|
|
24
|
-
import type UniKvs from "./unikvs.js";
|
|
25
|
-
import type { ValueOf } from "./utils.types.js";
|
|
26
|
-
import type { VariablesSource } from "./variables.types.js";
|
|
27
|
-
|
|
28
|
-
export {
|
|
29
|
-
type UniKvsSchema,
|
|
30
|
-
type ValueSchemaInfo,
|
|
31
|
-
type UniKvsSchemaRecord,
|
|
32
|
-
type UniKvsSchemaEntries,
|
|
33
|
-
type $InferPlainValueData,
|
|
34
|
-
type IValueSchemaResolver,
|
|
35
|
-
type $InferKeyValueMapping,
|
|
36
|
-
type $InferPlainValueInput,
|
|
37
|
-
type $InferStreamValueChunkData,
|
|
38
|
-
type $InferStreamValueChunkInput,
|
|
39
|
-
Value,
|
|
40
|
-
PlainValue,
|
|
41
|
-
StreamValue,
|
|
42
|
-
} from "./_value-schemas.js";
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* トランスフォーマーから、デコード時の入力データの型を推論するユーティリティー型です。
|
|
46
|
-
*
|
|
47
|
-
* @template TTransformer 対象となるトランスフォーマーの型です。
|
|
48
|
-
*/
|
|
49
|
-
type $InferDecodeDataInput<TTransformer extends ITransformer> =
|
|
50
|
-
TTransformer extends ITransformer<any, infer TDecodeDataInput> ? TDecodeDataInput : never;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* トランスフォーマーから、エンコード時の出力データの型を推論するユーティリティー型です。
|
|
54
|
-
*
|
|
55
|
-
* @template TTransformer 対象となるトランスフォーマーの型です。
|
|
56
|
-
*/
|
|
57
|
-
type $InferEncodeDataOutput<TTransformer extends ITransformer> =
|
|
58
|
-
TTransformer extends ITransformer<any, any, infer TEncodeDataOutput> ? TEncodeDataOutput : never;
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* トランスフォーマーから、デコードストリームの入力チャンクデータの型を推論するユーティリティー型です。
|
|
62
|
-
*
|
|
63
|
-
* @template TTransformer 対象となるトランスフォーマーの型です。
|
|
64
|
-
*/
|
|
65
|
-
type $InferDecodeChunkInput<TTransformer extends ITransformer> =
|
|
66
|
-
TTransformer extends IDecodableStreamTransformer<infer TDecodeChunkInput>
|
|
67
|
-
? TDecodeChunkInput
|
|
68
|
-
: never;
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* トランスフォーマーから、エンコードストリームの出力チャンクデータの型を推論するユーティリティー型です。
|
|
72
|
-
*
|
|
73
|
-
* @template TTransformer 対象となるトランスフォーマーの型です。
|
|
74
|
-
*/
|
|
75
|
-
type $InferEncodeChunkOutput<TTransformer extends ITransformer> =
|
|
76
|
-
TTransformer extends IEncodableStreamTransformer<any, infer TEncodeChunkOutput>
|
|
77
|
-
? TEncodeChunkOutput
|
|
78
|
-
: never;
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* ストレージから、書き込みストリームの入力チャンクデータの型を推論するユーティリティー型です。
|
|
82
|
-
*
|
|
83
|
-
* @template TStorage 対象となるストレージの型です。
|
|
84
|
-
*/
|
|
85
|
-
type $InferWriteChunkInput<TStorage extends IStorage> =
|
|
86
|
-
TStorage extends IWritableStreamStorage<infer TWriteChunkInput> ? TWriteChunkInput : never;
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* ストレージから、読み込みストリームの出力チャンクデータの型を推論するユーティリティー型です。
|
|
90
|
-
*
|
|
91
|
-
* @template TStorage 対象となるストレージの型です。
|
|
92
|
-
*/
|
|
93
|
-
type $InferReadChunkOutput<TStorage extends IStorage> =
|
|
94
|
-
TStorage extends IReadableStreamStorage<infer TReadChunkOutput> ? TReadChunkOutput : never;
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#value-types)
|
|
98
|
-
*/
|
|
99
|
-
export type KeyValueMapping<T = any> = { readonly [key: IStorage.Key]: Value<T> };
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#value-types)
|
|
103
|
-
*/
|
|
104
|
-
export type KeyofKeyValueMapping<TKeyValueMapping extends KeyValueMapping = KeyValueMapping> =
|
|
105
|
-
Extract<keyof TKeyValueMapping, IStorage.Key>;
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#config-builder)
|
|
109
|
-
*/
|
|
110
|
-
export interface IUniKvsConfigBuilder<
|
|
111
|
-
TKeyValueMapping extends KeyValueMapping = KeyValueMapping,
|
|
112
|
-
TUniKvsDataInput = ValueOf<{
|
|
113
|
-
[TKey in KeyofKeyValueMapping<TKeyValueMapping>]: $InferPlainValueData<TKeyValueMapping[TKey]>;
|
|
114
|
-
}>,
|
|
115
|
-
TUniKvsDataOutput = TUniKvsDataInput,
|
|
116
|
-
TUniKvsChunkInput = ValueOf<{
|
|
117
|
-
[TKey in KeyofKeyValueMapping<TKeyValueMapping>]: $InferStreamValueChunkData<
|
|
118
|
-
TKeyValueMapping[TKey]
|
|
119
|
-
>;
|
|
120
|
-
}>,
|
|
121
|
-
TUniKvsChunkOutput = TUniKvsChunkInput,
|
|
122
|
-
TLastTransformerDecodeDataInput = TUniKvsDataOutput,
|
|
123
|
-
TLastTransformerEncodeDataOutput = TUniKvsDataInput,
|
|
124
|
-
TLastTransformerDecodeChunkInput = TUniKvsChunkOutput,
|
|
125
|
-
TLastTransformerEncodeChunkOutput = TUniKvsChunkInput,
|
|
126
|
-
> {
|
|
127
|
-
/**
|
|
128
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#config-builder)
|
|
129
|
-
*/
|
|
130
|
-
setVariables(vars: VariablesSource): this;
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#config-builder)
|
|
134
|
-
*/
|
|
135
|
-
appendStorage<
|
|
136
|
-
TStorage extends IStorage<
|
|
137
|
-
[TLastTransformerEncodeDataOutput] extends [never] ? any : TLastTransformerEncodeDataOutput,
|
|
138
|
-
[TLastTransformerDecodeDataInput] extends [never] ? any : TLastTransformerDecodeDataInput,
|
|
139
|
-
[TLastTransformerEncodeChunkOutput] extends [never] ? any : TLastTransformerEncodeChunkOutput,
|
|
140
|
-
[TLastTransformerDecodeChunkInput] extends [never] ? any : TLastTransformerDecodeChunkInput
|
|
141
|
-
>,
|
|
142
|
-
>(
|
|
143
|
-
storage: TStorage,
|
|
144
|
-
): IUniKvsConfigFinalizer<
|
|
145
|
-
TKeyValueMapping,
|
|
146
|
-
TLastTransformerEncodeDataOutput,
|
|
147
|
-
TLastTransformerDecodeDataInput,
|
|
148
|
-
[TLastTransformerEncodeChunkOutput] extends [never]
|
|
149
|
-
? never
|
|
150
|
-
: [$InferWriteChunkInput<TStorage>] extends [never]
|
|
151
|
-
? never
|
|
152
|
-
: TLastTransformerEncodeChunkOutput,
|
|
153
|
-
[TLastTransformerDecodeChunkInput] extends [never]
|
|
154
|
-
? never
|
|
155
|
-
: [$InferReadChunkOutput<TStorage>] extends [never]
|
|
156
|
-
? never
|
|
157
|
-
: TLastTransformerDecodeChunkInput,
|
|
158
|
-
TLastTransformerDecodeDataInput,
|
|
159
|
-
TLastTransformerEncodeDataOutput,
|
|
160
|
-
TLastTransformerDecodeChunkInput,
|
|
161
|
-
TLastTransformerEncodeChunkOutput
|
|
162
|
-
>;
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#config-builder)
|
|
166
|
-
*/
|
|
167
|
-
appendTransformer<
|
|
168
|
-
TTransformer extends ITransformer<
|
|
169
|
-
// 最後のトランスファーマーのエンコード出力を、入力値として受け入れられる必要があります。
|
|
170
|
-
[TLastTransformerEncodeDataOutput] extends [never] ? any : TLastTransformerEncodeDataOutput,
|
|
171
|
-
// ここではまだ、後段のトランスフォーマーのデコード出力を気にしません。
|
|
172
|
-
any,
|
|
173
|
-
// ここではまだ、後段のトランスフォーマーのエンコード入力を気にしません。
|
|
174
|
-
any,
|
|
175
|
-
// 最後のトランスフォーマーのデコード入力を出力する必要があります。
|
|
176
|
-
[TLastTransformerDecodeDataInput] extends [never] ? any : TLastTransformerDecodeDataInput,
|
|
177
|
-
// 最後のトランスファーマーのエンコード出力を、入力値として受け入れられる必要があります。
|
|
178
|
-
[TLastTransformerEncodeChunkOutput] extends [never] ? any : TLastTransformerEncodeChunkOutput,
|
|
179
|
-
// ここではまだ、後段のトランスフォーマーのデコード出力を気にしません。
|
|
180
|
-
any,
|
|
181
|
-
// ここではまだ、後段のトランスフォーマーのエンコード入力を気にしません。
|
|
182
|
-
any,
|
|
183
|
-
// 最後のトランスフォーマーのデコード入力を出力する必要があります。
|
|
184
|
-
[TLastTransformerDecodeChunkInput] extends [never] ? any : TLastTransformerDecodeChunkInput
|
|
185
|
-
>,
|
|
186
|
-
>(
|
|
187
|
-
transformer: TTransformer,
|
|
188
|
-
): IUniKvsConfigBuilder<
|
|
189
|
-
TKeyValueMapping,
|
|
190
|
-
TUniKvsDataInput,
|
|
191
|
-
TUniKvsDataOutput,
|
|
192
|
-
[TUniKvsChunkInput] extends [never]
|
|
193
|
-
? never
|
|
194
|
-
: [$InferDecodeChunkInput<TTransformer>] extends [never]
|
|
195
|
-
? never
|
|
196
|
-
: TUniKvsChunkInput,
|
|
197
|
-
[TUniKvsChunkOutput] extends [never]
|
|
198
|
-
? never
|
|
199
|
-
: [$InferEncodeChunkOutput<TTransformer>] extends [never]
|
|
200
|
-
? never
|
|
201
|
-
: TUniKvsChunkOutput,
|
|
202
|
-
$InferDecodeDataInput<TTransformer>,
|
|
203
|
-
$InferEncodeDataOutput<TTransformer>,
|
|
204
|
-
$InferDecodeChunkInput<TTransformer>,
|
|
205
|
-
$InferEncodeChunkOutput<TTransformer>
|
|
206
|
-
>;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#config-builder)
|
|
211
|
-
*/
|
|
212
|
-
export interface IUniKvsConfigFinalizer<
|
|
213
|
-
TKeyValueMapping extends KeyValueMapping = KeyValueMapping,
|
|
214
|
-
TWriteDataInput = any,
|
|
215
|
-
TReadDataOutput = any,
|
|
216
|
-
TWriteChunkInput = any,
|
|
217
|
-
TReadChunkOutput = any,
|
|
218
|
-
TLastTransformerDecodeDataInput = TReadDataOutput,
|
|
219
|
-
TLastTransformerEncodeDataOutput = TWriteDataInput,
|
|
220
|
-
TLastTransformerDecodeChunkInput = TReadChunkOutput,
|
|
221
|
-
TLastTransformerEncodeChunkOutput = TWriteChunkInput,
|
|
222
|
-
> {
|
|
223
|
-
/**
|
|
224
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#config-builder)
|
|
225
|
-
*/
|
|
226
|
-
create(): UniKvs<TKeyValueMapping>;
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#config-builder)
|
|
230
|
-
*/
|
|
231
|
-
setVariables(vars: VariablesSource): this;
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#config-builder)
|
|
235
|
-
*/
|
|
236
|
-
appendStorage<
|
|
237
|
-
TStorage extends IStorage<
|
|
238
|
-
[TLastTransformerEncodeDataOutput] extends [never] ? any : TLastTransformerEncodeDataOutput,
|
|
239
|
-
[TLastTransformerDecodeDataInput] extends [never] ? any : TLastTransformerDecodeDataInput,
|
|
240
|
-
[TLastTransformerEncodeChunkOutput] extends [never] ? any : TLastTransformerEncodeChunkOutput,
|
|
241
|
-
[TLastTransformerDecodeChunkInput] extends [never] ? any : TLastTransformerDecodeChunkInput
|
|
242
|
-
>,
|
|
243
|
-
>(
|
|
244
|
-
storage: TStorage,
|
|
245
|
-
): IUniKvsConfigFinalizer<
|
|
246
|
-
TKeyValueMapping,
|
|
247
|
-
TWriteDataInput,
|
|
248
|
-
TReadDataOutput,
|
|
249
|
-
[TWriteChunkInput] extends [never]
|
|
250
|
-
? never
|
|
251
|
-
: [$InferWriteChunkInput<TStorage>] extends [never]
|
|
252
|
-
? never
|
|
253
|
-
: TWriteChunkInput,
|
|
254
|
-
[TReadChunkOutput] extends [never]
|
|
255
|
-
? never
|
|
256
|
-
: [$InferReadChunkOutput<TStorage>] extends [never]
|
|
257
|
-
? never
|
|
258
|
-
: TReadChunkOutput,
|
|
259
|
-
TLastTransformerDecodeDataInput,
|
|
260
|
-
TLastTransformerEncodeDataOutput,
|
|
261
|
-
TLastTransformerDecodeChunkInput,
|
|
262
|
-
TLastTransformerEncodeChunkOutput
|
|
263
|
-
>;
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#config-builder)
|
|
267
|
-
*/
|
|
268
|
-
appendTransformer<
|
|
269
|
-
TTransformer extends ITransformer<
|
|
270
|
-
[TLastTransformerEncodeDataOutput] extends [never] ? any : TLastTransformerEncodeDataOutput,
|
|
271
|
-
any,
|
|
272
|
-
any,
|
|
273
|
-
[TLastTransformerDecodeDataInput] extends [never] ? any : TLastTransformerDecodeDataInput,
|
|
274
|
-
[TLastTransformerEncodeChunkOutput] extends [never] ? any : TLastTransformerEncodeChunkOutput,
|
|
275
|
-
any,
|
|
276
|
-
any,
|
|
277
|
-
[TLastTransformerDecodeChunkInput] extends [never] ? any : TLastTransformerDecodeChunkInput
|
|
278
|
-
>,
|
|
279
|
-
>(
|
|
280
|
-
transformer: TTransformer,
|
|
281
|
-
): IUniKvsConfigFinalizer<
|
|
282
|
-
TKeyValueMapping,
|
|
283
|
-
TWriteDataInput,
|
|
284
|
-
TReadDataOutput,
|
|
285
|
-
TWriteChunkInput,
|
|
286
|
-
TReadChunkOutput,
|
|
287
|
-
$InferDecodeDataInput<TTransformer>,
|
|
288
|
-
$InferEncodeDataOutput<TTransformer>,
|
|
289
|
-
$InferDecodeChunkInput<TTransformer>,
|
|
290
|
-
$InferEncodeChunkOutput<TTransformer>
|
|
291
|
-
>;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#config-builder)
|
|
296
|
-
*/
|
|
297
|
-
export type UniKvsConfigOptions = {
|
|
298
|
-
/**
|
|
299
|
-
* キーと値のスキーマ定義です。指定すると入出力値が検証されます。
|
|
300
|
-
*/
|
|
301
|
-
readonly schema?: UniKvsSchema | undefined;
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
const UniKvsConfigOptionsSchema = v.object({
|
|
305
|
-
/**
|
|
306
|
-
* キーと値のスキーマ定義です。
|
|
307
|
-
*/
|
|
308
|
-
schema: v.optional(UniKvsSchemaSchema),
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
const UniKvsConfigArgsSchema = v.tuple([v.optional(UniKvsConfigOptionsSchema)]);
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#config-builder)
|
|
315
|
-
*/
|
|
316
|
-
export default class UniKvsConfig implements IUniKvsConfigBuilder, IUniKvsConfigFinalizer {
|
|
317
|
-
/**
|
|
318
|
-
* UniKvs のコンストラクターです。
|
|
319
|
-
*/
|
|
320
|
-
readonly #UniKvs: typeof UniKvs;
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* アプリケーションの実行時情報を保持する変数オブジェクトです。
|
|
324
|
-
*/
|
|
325
|
-
#vars: Variables;
|
|
326
|
-
|
|
327
|
-
/**
|
|
328
|
-
* データの永続化先となるストレージのリストです。各ストレージは登録時点のトランスフォーマー数を保持します。
|
|
329
|
-
*/
|
|
330
|
-
readonly #destinations: { readonly storage: IStorage; readonly transformerCount: number }[];
|
|
331
|
-
|
|
332
|
-
/**
|
|
333
|
-
* データを変換するためのトランスフォーマーのリストです。登録順に保持します。
|
|
334
|
-
*/
|
|
335
|
-
readonly #transformers: ITransformer[];
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* キーに対応する値のスキーマ情報を解決するリゾルバーです。スキーマ未設定時は null となります。
|
|
339
|
-
*/
|
|
340
|
-
readonly #valueSchemaResolver: IValueSchemaResolver | null;
|
|
341
|
-
|
|
342
|
-
/**
|
|
343
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#config-builder)
|
|
344
|
-
*/
|
|
345
|
-
public constructor(UniKvsConstructor: typeof UniKvs, options?: UniKvsConfigOptions) {
|
|
346
|
-
const [parsed = {}] = v.parseInput(UniKvsConfigArgsSchema, [options]);
|
|
347
|
-
|
|
348
|
-
this.#UniKvs = UniKvsConstructor;
|
|
349
|
-
this.#vars = {};
|
|
350
|
-
this.#destinations = [];
|
|
351
|
-
this.#transformers = [];
|
|
352
|
-
this.#valueSchemaResolver = parsed.schema ? createValueSchemaResolver(parsed.schema) : null;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#config-builder)
|
|
357
|
-
*/
|
|
358
|
-
public create(): UniKvs {
|
|
359
|
-
const transformers = this.#transformers.map((tf) => new UniKvsTransformer(tf));
|
|
360
|
-
|
|
361
|
-
const [first, ...rest] = this.#destinations.map(({ storage, transformerCount }) => ({
|
|
362
|
-
storage: new UniKvsStorage(storage),
|
|
363
|
-
transformers: transformers.slice(0, transformerCount),
|
|
364
|
-
}));
|
|
365
|
-
|
|
366
|
-
// ストレージが空の場合は UniKvs として機能できないため、例外を投げます。
|
|
367
|
-
if (!first) {
|
|
368
|
-
throw new MissingStorageError();
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
// 変数の参照を切り離すために浅いコピーを作成して UniKvs を初期化します。
|
|
372
|
-
return new this.#UniKvs(this.#vars, [first, ...rest], transformers, this.#valueSchemaResolver);
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
/**
|
|
376
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#config-builder)
|
|
377
|
-
*/
|
|
378
|
-
public setVariables(vars: VariablesSource): this {
|
|
379
|
-
this.#vars = Array.isArray(vars) ? Object.fromEntries(vars) : { ...vars };
|
|
380
|
-
|
|
381
|
-
return this;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
/**
|
|
385
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#config-builder)
|
|
386
|
-
*/
|
|
387
|
-
public appendStorage(storage: IStorage): this {
|
|
388
|
-
this.#destinations.push({ storage, transformerCount: this.#transformers.length });
|
|
389
|
-
|
|
390
|
-
return this;
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
/**
|
|
394
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#config-builder)
|
|
395
|
-
*/
|
|
396
|
-
public appendTransformer(transformer: ITransformer): this {
|
|
397
|
-
this.#transformers.push(transformer);
|
|
398
|
-
|
|
399
|
-
return this;
|
|
400
|
-
}
|
|
401
|
-
}
|
package/src/utils.types.ts
DELETED
package/src/variables.types.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Variables } from "@unikvs/core";
|
|
2
|
-
|
|
3
|
-
import type { ValueOf } from "./utils.types.js";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#variables-and-cancellation)
|
|
7
|
-
*/
|
|
8
|
-
export type VariableEntry = readonly [key: keyof Variables, value: ValueOf<Variables>];
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#variables-and-cancellation)
|
|
12
|
-
*/
|
|
13
|
-
export type VariablesSource = Readonly<Variables> | readonly VariableEntry[];
|