unikvs 0.0.12 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/index.d.ts +1553 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4032 -0
- package/dist/index.js.map +1 -0
- package/package.json +34 -34
- package/src/_contexts.ts +1089 -0
- package/src/_logger.ts +5 -3
- package/src/_middleware.ts +207 -0
- package/src/_pipeline-graph.helpers.ts +183 -0
- package/src/_pipeline-graph.ts +1307 -0
- package/src/_pipeline-graph.types.ts +303 -0
- package/src/_pipeline-leaf-resolver.ts +70 -0
- package/src/_plugin-lifecycle.ts +201 -0
- package/src/_storage.ts +169 -115
- package/src/_streams.schemas.ts +21 -0
- package/src/_streams.ts +32 -6
- package/src/_to-value-stream.ts +22 -11
- package/src/_types.ts +237 -0
- package/src/_unikvs-branch.ts +94 -0
- package/src/_unikvs.schemas.ts +451 -0
- package/src/_valibot.ts +17 -6
- package/src/_value-schemas.ts +36 -206
- package/src/_value-validation.ts +57 -0
- package/src/errors.ts +391 -148
- package/src/index.ts +46 -25
- package/src/{value-stream.types.ts → types.ts} +1 -1
- package/src/unikvs-branch.ts +445 -0
- package/src/unikvs-builder.ts +706 -0
- package/src/unikvs.ts +1423 -1007
- package/src/unikvs.types.ts +194 -0
- package/src/value-schemas.ts +98 -0
- package/dist/src/_logger.d.ts +0 -3
- package/dist/src/_logger.d.ts.map +0 -1
- package/dist/src/_logger.js +0 -3
- package/dist/src/_merge-variables.d.ts +0 -13
- package/dist/src/_merge-variables.d.ts.map +0 -1
- package/dist/src/_merge-variables.js +0 -12
- package/dist/src/_storage.d.ts +0 -18
- package/dist/src/_storage.d.ts.map +0 -1
- package/dist/src/_storage.js +0 -103
- package/dist/src/_streams.d.ts +0 -20
- package/dist/src/_streams.d.ts.map +0 -1
- package/dist/src/_streams.js +0 -36
- package/dist/src/_to-value-stream.d.ts +0 -12
- package/dist/src/_to-value-stream.d.ts.map +0 -1
- package/dist/src/_to-value-stream.js +0 -102
- package/dist/src/_transformer.d.ts +0 -13
- package/dist/src/_transformer.d.ts.map +0 -1
- package/dist/src/_transformer.js +0 -60
- package/dist/src/_valibot.d.ts +0 -15
- package/dist/src/_valibot.d.ts.map +0 -1
- package/dist/src/_valibot.js +0 -23
- package/dist/src/_value-schemas.d.ts +0 -179
- package/dist/src/_value-schemas.d.ts.map +0 -1
- package/dist/src/_value-schemas.js +0 -150
- package/dist/src/errors.d.ts +0 -306
- package/dist/src/errors.d.ts.map +0 -1
- package/dist/src/errors.js +0 -234
- package/dist/src/index.d.ts +0 -10
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -3
- package/dist/src/unikvs-config.d.ts +0 -174
- package/dist/src/unikvs-config.d.ts.map +0 -1
- package/dist/src/unikvs-config.js +0 -100
- package/dist/src/unikvs.d.ts +0 -272
- package/dist/src/unikvs.d.ts.map +0 -1
- package/dist/src/unikvs.js +0 -928
- package/dist/src/utils.types.d.ts +0 -5
- package/dist/src/utils.types.d.ts.map +0 -1
- package/dist/src/utils.types.js +0 -1
- package/dist/src/value-stream.types.d.ts +0 -10
- package/dist/src/value-stream.types.d.ts.map +0 -1
- package/dist/src/value-stream.types.js +0 -1
- package/dist/src/variables.types.d.ts +0 -11
- package/dist/src/variables.types.d.ts.map +0 -1
- package/dist/src/variables.types.js +0 -1
- package/src/_merge-variables.ts +0 -19
- package/src/_transformer.ts +0 -89
- package/src/unikvs-config.ts +0 -401
- package/src/utils.types.ts +0 -4
- package/src/variables.types.ts +0 -13
package/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(vars, 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({ vars, signal });
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
async close(vars, signal) {
|
|
17
|
-
if (typeof this.tf.close !== "function") {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
if (this.tf.isOpen && this.managed) {
|
|
21
|
-
await this.tf.close({ vars, signal });
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
async encode(vars, signal, data) {
|
|
25
|
-
if (!this.tf.isOpen) {
|
|
26
|
-
throw new TransformerIsNotOpenError({ name: this.tf.name });
|
|
27
|
-
}
|
|
28
|
-
const output = await this.tf.encode({ data, vars, signal });
|
|
29
|
-
return output;
|
|
30
|
-
}
|
|
31
|
-
async decode(vars, signal, data) {
|
|
32
|
-
if (!this.tf.isOpen) {
|
|
33
|
-
throw new TransformerIsNotOpenError({ name: this.tf.name });
|
|
34
|
-
}
|
|
35
|
-
const output = await this.tf.decode({ data, vars, signal });
|
|
36
|
-
return output;
|
|
37
|
-
}
|
|
38
|
-
async getEncodable(vars, 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({ vars, signal });
|
|
46
|
-
const parsed = output; // TODO(tai-kun): 要検証
|
|
47
|
-
return parsed;
|
|
48
|
-
}
|
|
49
|
-
async getDecodable(vars, 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({ vars, signal });
|
|
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 { GenericSchema, InferInput, InferOutput } from "valibot";
|
|
4
|
-
export { any, check, custom, omit, pipe, union, number, string, symbol, unknown, instance, minValue, optional, safeInteger, safeParse, } 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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_valibot.d.ts","sourceRoot":"","sources":["../../src/_valibot.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,WAAW,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEtD,OAAO,EACL,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAG5B,MAAM,aAAa,CAAC;AAErB,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtE,OAAO,EACL,GAAG,EACH,KAAK,EACL,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,MAAM,EACN,MAAM,EACN,MAAM,EACN,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,SAAS,GACV,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAErF,KAAK,UAAU,GAAG,OAAO,SAAS,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,GAAG,GAAG,CAAC,GAAG,KAAK,CAAC;AAE9F,MAAM,WAAW,2BAA2B;IAC1C,KAAK,IAAI,EAAE,qBAAqB,GAAG,KAAK,CAAC;CAC1C;AAED,wBAAgB,UAAU,CAAC,KAAK,CAAC,OAAO,SAAS,UAAU,EACzD,MAAM,EAAE,OAAO,EACf,KAAK,EAAE,OAAO,EACd,KAAK,GAAE,2BAA+C,GACrD,WAAW,CAAC,OAAO,CAAC,CAStB;AAED,MAAM,WAAW,2BAA2B;IAC1C,KAAK,IAAI,EAAE,sBAAsB,GAAG,KAAK,CAAC;CAC3C;AAED,wBAAgB,WAAW,CAAC,KAAK,CAAC,OAAO,SAAS,UAAU,EAC1D,MAAM,EAAE,OAAO,EACf,KAAK,EAAE,OAAO,EACd,KAAK,GAAE,2BAAgD,GACtD,WAAW,CAAC,OAAO,CAAC,CAStB"}
|
package/dist/src/_valibot.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { tryCaptureStackTrace } from "try-capture-stack-trace";
|
|
2
|
-
import { safeParse } from "valibot";
|
|
3
|
-
import { InvalidInputError, InvalidOutputError, } from "./errors.js";
|
|
4
|
-
export { any, check, custom, omit, pipe, union, number, string, symbol, unknown, instance, minValue, optional, safeInteger, safeParse, } from "valibot";
|
|
5
|
-
export { array, tuple, object, record, transform } from "@tai-kun/valibot-extra-lab";
|
|
6
|
-
export function parseInput(schema, value, Error = InvalidInputError) {
|
|
7
|
-
const result = safeParse(schema, value);
|
|
8
|
-
if (result.success) {
|
|
9
|
-
return result.output;
|
|
10
|
-
}
|
|
11
|
-
const error = new Error({ value, issues: result.issues });
|
|
12
|
-
tryCaptureStackTrace(error, parseInput);
|
|
13
|
-
throw error;
|
|
14
|
-
}
|
|
15
|
-
export function parseOutput(schema, value, Error = InvalidOutputError) {
|
|
16
|
-
const result = safeParse(schema, value);
|
|
17
|
-
if (result.success) {
|
|
18
|
-
return result.output;
|
|
19
|
-
}
|
|
20
|
-
const error = new Error({ value, issues: result.issues });
|
|
21
|
-
tryCaptureStackTrace(error, parseOutput);
|
|
22
|
-
throw error;
|
|
23
|
-
}
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import * as v from "./_valibot.js";
|
|
2
|
-
/**
|
|
3
|
-
* プレーンな値を識別するための固有のシンボルです。
|
|
4
|
-
*/
|
|
5
|
-
declare const PLAIN_VALUE: unique symbol;
|
|
6
|
-
/**
|
|
7
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#value-types)
|
|
8
|
-
*
|
|
9
|
-
* @template TData 入出力されるデータの型です。
|
|
10
|
-
* @template TInput `set` が受け付ける入力データの型です。
|
|
11
|
-
*/
|
|
12
|
-
export type PlainValue<TData = any, TInput = TData> = [
|
|
13
|
-
Type: typeof PLAIN_VALUE,
|
|
14
|
-
Data: TData,
|
|
15
|
-
Input: TInput
|
|
16
|
-
];
|
|
17
|
-
/**
|
|
18
|
-
* ストリーム形式の値を識別するための固有のシンボルです。
|
|
19
|
-
*/
|
|
20
|
-
declare const STREAM_VALUE: unique symbol;
|
|
21
|
-
/**
|
|
22
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#value-types)
|
|
23
|
-
*
|
|
24
|
-
* @template TChunkData 入出力されるチャンクデータの型です。
|
|
25
|
-
* @template TChunkInput `set` が受け付ける入力チャンクデータの型です。
|
|
26
|
-
*/
|
|
27
|
-
export type StreamValue<TChunkData = any, TChunkInput = TChunkData> = [
|
|
28
|
-
Type: typeof STREAM_VALUE,
|
|
29
|
-
ChunkData: TChunkData,
|
|
30
|
-
ChunkInput: TChunkInput
|
|
31
|
-
];
|
|
32
|
-
/**
|
|
33
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#value-types)
|
|
34
|
-
*
|
|
35
|
-
* @template TDataAndChunkData データまたはチャンクデータの型です。
|
|
36
|
-
* @template TInput `set` が受け付ける入力データまたは入力チャンクデータの型です。
|
|
37
|
-
*/
|
|
38
|
-
export type Value<TDataAndChunkData = any, TInput = TDataAndChunkData> = PlainValue<TDataAndChunkData, TInput> | StreamValue<TDataAndChunkData, TInput>;
|
|
39
|
-
/**
|
|
40
|
-
* PlainValue 型から内部のデータ型を抽出します。
|
|
41
|
-
*
|
|
42
|
-
* @template TPlainValue 対象となる PlainValue 型です。
|
|
43
|
-
*/
|
|
44
|
-
export type $InferPlainValueData<TPlainValue> = TPlainValue extends PlainValue<infer TData, any> ? TData : never;
|
|
45
|
-
/**
|
|
46
|
-
* PlainValue 型から入力データの型を抽出します。
|
|
47
|
-
*
|
|
48
|
-
* @template TPlainValue 対象となる PlainValue 型です。
|
|
49
|
-
*/
|
|
50
|
-
export type $InferPlainValueInput<TPlainValue> = TPlainValue extends PlainValue<any, infer TInput> ? TInput : never;
|
|
51
|
-
/**
|
|
52
|
-
* StreamValue 型から内部のチャンクデータ型を抽出します。
|
|
53
|
-
*
|
|
54
|
-
* @template TStreamValue 対象となる StreamValue 型です。
|
|
55
|
-
*/
|
|
56
|
-
export type $InferStreamValueChunkData<TStreamValue> = TStreamValue extends StreamValue<infer TChunkData, any> ? TChunkData : never;
|
|
57
|
-
/**
|
|
58
|
-
* StreamValue 型から入力チャンクデータの型を抽出します。
|
|
59
|
-
*
|
|
60
|
-
* @template TStreamValue 対象となる StreamValue 型です。
|
|
61
|
-
*/
|
|
62
|
-
export type $InferStreamValueChunkInput<TStreamValue> = TStreamValue extends StreamValue<any, infer TChunkInput> ? TChunkInput : never;
|
|
63
|
-
/**
|
|
64
|
-
* スキーマ付きの値が扱うデータの種類です。
|
|
65
|
-
*
|
|
66
|
-
* - `"plain"`: プレーンな値のみを扱います。
|
|
67
|
-
* - `"stream"`: ストリーム形式の値のみを扱います。
|
|
68
|
-
* - `"any"`: プレーンな値とストリーム形式の値のどちらも扱います。
|
|
69
|
-
*/
|
|
70
|
-
export type ValueSchemaKind = "plain" | "stream" | "any";
|
|
71
|
-
/**
|
|
72
|
-
* キーに対応する値のスキーマ情報です。
|
|
73
|
-
*/
|
|
74
|
-
export type ValueSchemaInfo = {
|
|
75
|
-
/**
|
|
76
|
-
* 扱うデータの種類です。
|
|
77
|
-
*/
|
|
78
|
-
readonly kind: ValueSchemaKind;
|
|
79
|
-
/**
|
|
80
|
-
* データの検証に使用するスキーマです。
|
|
81
|
-
*/
|
|
82
|
-
readonly schema: v.GenericSchema;
|
|
83
|
-
};
|
|
84
|
-
/**
|
|
85
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#value-types)
|
|
86
|
-
*
|
|
87
|
-
* プレーンな値のスキーマを定義します。
|
|
88
|
-
*
|
|
89
|
-
* @template TSchema スキーマの型です。
|
|
90
|
-
* @param schema 値の検証に使用する Valibot スキーマです。
|
|
91
|
-
* @returns プレーンな値であることを示す型情報を返します。
|
|
92
|
-
*/
|
|
93
|
-
export declare function PlainValue<const TSchema extends v.GenericSchema>(schema: TSchema): PlainValue<v.InferOutput<TSchema>, v.InferInput<TSchema>>;
|
|
94
|
-
/**
|
|
95
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#value-types)
|
|
96
|
-
*
|
|
97
|
-
* ストリーム形式の値のスキーマを定義します。
|
|
98
|
-
*
|
|
99
|
-
* @template TSchema スキーマの型です。
|
|
100
|
-
* @param schema チャンクデータの検証に使用する Valibot スキーマです。
|
|
101
|
-
* @returns ストリーム形式の値であることを示す型情報を返します。
|
|
102
|
-
*/
|
|
103
|
-
export declare function StreamValue<const TSchema extends v.GenericSchema>(schema: TSchema): StreamValue<v.InferOutput<TSchema>, v.InferInput<TSchema>>;
|
|
104
|
-
/**
|
|
105
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#value-types)
|
|
106
|
-
*
|
|
107
|
-
* プレーンな値とストリーム形式の値の両方で使えるスキーマを定義します。
|
|
108
|
-
*
|
|
109
|
-
* @template TSchema スキーマの型です。
|
|
110
|
-
* @param schema データとチャンクデータの検証に使用する Valibot スキーマです。
|
|
111
|
-
* @returns どちらの形式でも使える値であることを示す型情報を返します。
|
|
112
|
-
*/
|
|
113
|
-
export declare function Value<const TSchema extends v.GenericSchema>(schema: TSchema): Value<v.InferOutput<TSchema>, v.InferInput<TSchema>>;
|
|
114
|
-
/**
|
|
115
|
-
* オブジェクト形式のスキーマ定義です。キーをそのままキーとして扱います。
|
|
116
|
-
*/
|
|
117
|
-
export type UniKvsSchemaRecord = {
|
|
118
|
-
readonly [key: string]: Value<any, any>;
|
|
119
|
-
};
|
|
120
|
-
/**
|
|
121
|
-
* 配列形式のスキーマ定義です。キーのスキーマと値のスキーマの組を並べます。
|
|
122
|
-
*/
|
|
123
|
-
export type UniKvsSchemaEntries = readonly (readonly [v.GenericSchema, Value<any, any>])[];
|
|
124
|
-
/**
|
|
125
|
-
* `UniKvs.config()` の `schema` オプションに指定できるスキーマ定義です。
|
|
126
|
-
*/
|
|
127
|
-
export type UniKvsSchema = UniKvsSchemaRecord | UniKvsSchemaEntries;
|
|
128
|
-
/**
|
|
129
|
-
* スキーマ定義からキーと値のマッピング型を推論します。
|
|
130
|
-
*
|
|
131
|
-
* @template TSchema 対象となるスキーマ定義の型です。
|
|
132
|
-
*/
|
|
133
|
-
export type $InferKeyValueMapping<TSchema extends UniKvsSchema> = TSchema extends readonly (readonly [v.GenericSchema, infer TValue extends Value<any, any>])[] ? {
|
|
134
|
-
readonly [key: string]: TValue;
|
|
135
|
-
} : TSchema extends {
|
|
136
|
-
readonly [key: string]: Value<any, any>;
|
|
137
|
-
} ? {
|
|
138
|
-
readonly [TKey in keyof TSchema]: TSchema[TKey];
|
|
139
|
-
} : never;
|
|
140
|
-
/**
|
|
141
|
-
* 検証済みのオブジェクト形式のスキーマ定義です。
|
|
142
|
-
*/
|
|
143
|
-
export type UniKvsSchemaInfoRecord = {
|
|
144
|
-
readonly [key: string]: ValueSchemaInfo;
|
|
145
|
-
};
|
|
146
|
-
/**
|
|
147
|
-
* 検証済みの配列形式のスキーマ定義です。
|
|
148
|
-
*/
|
|
149
|
-
export type UniKvsSchemaInfoEntries = readonly (readonly [v.GenericSchema, ValueSchemaInfo])[];
|
|
150
|
-
/**
|
|
151
|
-
* 検証済みのスキーマ定義です。
|
|
152
|
-
*/
|
|
153
|
-
export type UniKvsSchemaInfo = UniKvsSchemaInfoRecord | UniKvsSchemaInfoEntries;
|
|
154
|
-
/**
|
|
155
|
-
* `schema` オプションの検証に使用するスキーマです。
|
|
156
|
-
*/
|
|
157
|
-
export declare const UniKvsSchemaSchema: import("valibot").UnionSchema<[import("@tai-kun/valibot-extra-lab").ArraySchema<import("@tai-kun/valibot-extra-lab").TupleSchema<[import("valibot").CustomSchema<v.GenericSchema, undefined>, import("valibot").CustomSchema<ValueSchemaInfo, undefined>], undefined>, undefined>, import("@tai-kun/valibot-extra-lab").RecordSchema<import("valibot").StringSchema<undefined>, import("valibot").CustomSchema<ValueSchemaInfo, undefined>, undefined>], undefined>;
|
|
158
|
-
/**
|
|
159
|
-
* キーに対応する値のスキーマ情報を解決するインターフェースです。
|
|
160
|
-
*/
|
|
161
|
-
export interface IValueSchemaResolver {
|
|
162
|
-
/**
|
|
163
|
-
* キーに対応する値のスキーマ情報を返します。
|
|
164
|
-
*
|
|
165
|
-
* @param key 解決するキーです。
|
|
166
|
-
* @returns 対応するスキーマ情報を返します。対応する定義がない場合は `undefined` を返します。
|
|
167
|
-
* @throws キーがどのキースキーマにも一致しない場合に `InvalidInputError` を投げます。
|
|
168
|
-
*/
|
|
169
|
-
resolve(key: string): ValueSchemaInfo | undefined;
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* 検証済みのスキーマ定義からスキーマリゾルバーを生成します。
|
|
173
|
-
*
|
|
174
|
-
* @param schema 検証済みのスキーマ定義です。
|
|
175
|
-
* @returns スキーマリゾルバーを返します。
|
|
176
|
-
*/
|
|
177
|
-
export declare function createValueSchemaResolver(schema: UniKvsSchemaInfo): IValueSchemaResolver;
|
|
178
|
-
export {};
|
|
179
|
-
//# sourceMappingURL=_value-schemas.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_value-schemas.d.ts","sourceRoot":"","sources":["../../src/_value-schemas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,eAAe,CAAC;AASnC;;GAEG;AACH,OAAO,CAAC,MAAM,WAAW,EAAE,OAAO,MAAM,CAAC;AAEzC;;;;;GAKG;AACH,MAAM,MAAM,UAAU,CAAC,KAAK,GAAG,GAAG,EAAE,MAAM,GAAG,KAAK,IAAI;IACpD,IAAI,EAAE,OAAO,WAAW;IACxB,IAAI,EAAE,KAAK;IACX,KAAK,EAAE,MAAM;CACd,CAAC;AAEF;;GAEG;AACH,OAAO,CAAC,MAAM,YAAY,EAAE,OAAO,MAAM,CAAC;AAE1C;;;;;GAKG;AACH,MAAM,MAAM,WAAW,CAAC,UAAU,GAAG,GAAG,EAAE,WAAW,GAAG,UAAU,IAAI;IACpE,IAAI,EAAE,OAAO,YAAY;IACzB,SAAS,EAAE,UAAU;IACrB,UAAU,EAAE,WAAW;CACxB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,KAAK,CAAC,iBAAiB,GAAG,GAAG,EAAE,MAAM,GAAG,iBAAiB,IACjE,UAAU,CAAC,iBAAiB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sB,GAAG;IAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,eAAe,CAAA;CAAE,CAAC;AAEjF;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,aAAa,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC;AAE/F;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,sBAAsB,GAAG,uBAAuB,CAAC;AAEhF;;GAEG;AACH,eAAO,MAAM,kBAAkB,qcAQ7B,CAAC;AAQH;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;;;OAMG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAAC;CACnD;AAuDD;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,gBAAgB,GAAG,oBAAoB,CAMxF"}
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var _RecordValueSchemaResolver_entries, _EntriesValueSchemaResolver_entries, _EntriesValueSchemaResolver_keySchema;
|
|
13
|
-
import * as v from "./_valibot.js";
|
|
14
|
-
import { InvalidInputError } from "./errors.js";
|
|
15
|
-
// -------------------------------------------------------------------------------------------------
|
|
16
|
-
//
|
|
17
|
-
// 値のスキーマ
|
|
18
|
-
//
|
|
19
|
-
// -------------------------------------------------------------------------------------------------
|
|
20
|
-
/**
|
|
21
|
-
* スキーマ付きの値であることを識別するためのブランドです。
|
|
22
|
-
*
|
|
23
|
-
* 同じライブラリーが複数読み込まれた環境でも認識できるようにグローバルシンボルを使用します。
|
|
24
|
-
*/
|
|
25
|
-
const VALUE_SCHEMA_BRAND = Symbol.for("unikvs.valueSchema");
|
|
26
|
-
/**
|
|
27
|
-
* 値が Valibot のスキーマであるかどうかを判定します。
|
|
28
|
-
*/
|
|
29
|
-
function isGenericSchema(input) {
|
|
30
|
-
return (typeof input === "object" &&
|
|
31
|
-
input !== null &&
|
|
32
|
-
typeof input["~run"] === "function");
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* 値がスキーマ情報であるかどうかを判定します。
|
|
36
|
-
*/
|
|
37
|
-
function isValueSchemaInfo(input) {
|
|
38
|
-
return (typeof input === "object" &&
|
|
39
|
-
input !== null &&
|
|
40
|
-
input[VALUE_SCHEMA_BRAND] === true);
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* スキーマ情報を内部オブジェクトとして生成します。
|
|
44
|
-
*/
|
|
45
|
-
function createValueSchemaDescriptor(kind, schema) {
|
|
46
|
-
return { [VALUE_SCHEMA_BRAND]: true, kind, schema };
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#value-types)
|
|
50
|
-
*
|
|
51
|
-
* プレーンな値のスキーマを定義します。
|
|
52
|
-
*
|
|
53
|
-
* @template TSchema スキーマの型です。
|
|
54
|
-
* @param schema 値の検証に使用する Valibot スキーマです。
|
|
55
|
-
* @returns プレーンな値であることを示す型情報を返します。
|
|
56
|
-
*/
|
|
57
|
-
export function PlainValue(schema) {
|
|
58
|
-
return createValueSchemaDescriptor("plain", schema);
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#value-types)
|
|
62
|
-
*
|
|
63
|
-
* ストリーム形式の値のスキーマを定義します。
|
|
64
|
-
*
|
|
65
|
-
* @template TSchema スキーマの型です。
|
|
66
|
-
* @param schema チャンクデータの検証に使用する Valibot スキーマです。
|
|
67
|
-
* @returns ストリーム形式の値であることを示す型情報を返します。
|
|
68
|
-
*/
|
|
69
|
-
export function StreamValue(schema) {
|
|
70
|
-
return createValueSchemaDescriptor("stream", schema);
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#value-types)
|
|
74
|
-
*
|
|
75
|
-
* プレーンな値とストリーム形式の値の両方で使えるスキーマを定義します。
|
|
76
|
-
*
|
|
77
|
-
* @template TSchema スキーマの型です。
|
|
78
|
-
* @param schema データとチャンクデータの検証に使用する Valibot スキーマです。
|
|
79
|
-
* @returns どちらの形式でも使える値であることを示す型情報を返します。
|
|
80
|
-
*/
|
|
81
|
-
export function Value(schema) {
|
|
82
|
-
return createValueSchemaDescriptor("any", schema);
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* `schema` オプションの検証に使用するスキーマです。
|
|
86
|
-
*/
|
|
87
|
-
export const UniKvsSchemaSchema = v.union([
|
|
88
|
-
v.array(v.tuple([
|
|
89
|
-
v.custom(isGenericSchema),
|
|
90
|
-
v.custom(isValueSchemaInfo),
|
|
91
|
-
])),
|
|
92
|
-
v.record(v.string(), v.custom(isValueSchemaInfo)),
|
|
93
|
-
]);
|
|
94
|
-
/**
|
|
95
|
-
* オブジェクト形式のスキーマ定義からスキーマ情報を解決します。
|
|
96
|
-
*/
|
|
97
|
-
class RecordValueSchemaResolver {
|
|
98
|
-
constructor(entries) {
|
|
99
|
-
_RecordValueSchemaResolver_entries.set(this, void 0);
|
|
100
|
-
__classPrivateFieldSet(this, _RecordValueSchemaResolver_entries, new Map(Object.entries(entries)), "f");
|
|
101
|
-
}
|
|
102
|
-
resolve(key) {
|
|
103
|
-
return __classPrivateFieldGet(this, _RecordValueSchemaResolver_entries, "f").get(key);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
_RecordValueSchemaResolver_entries = new WeakMap();
|
|
107
|
-
/**
|
|
108
|
-
* 配列形式のスキーマ定義からスキーマ情報を解決します。
|
|
109
|
-
*
|
|
110
|
-
* キースキーマに最初に一致した定義を採用します。
|
|
111
|
-
*/
|
|
112
|
-
class EntriesValueSchemaResolver {
|
|
113
|
-
constructor(entries) {
|
|
114
|
-
_EntriesValueSchemaResolver_entries.set(this, void 0);
|
|
115
|
-
_EntriesValueSchemaResolver_keySchema.set(this, void 0);
|
|
116
|
-
__classPrivateFieldSet(this, _EntriesValueSchemaResolver_entries, entries, "f");
|
|
117
|
-
__classPrivateFieldSet(this, _EntriesValueSchemaResolver_keySchema, entries.length > 0 ? v.union(entries.map(([keySchema]) => keySchema)) : undefined, "f");
|
|
118
|
-
}
|
|
119
|
-
resolve(key) {
|
|
120
|
-
for (const [keySchema, valueSchema] of __classPrivateFieldGet(this, _EntriesValueSchemaResolver_entries, "f")) {
|
|
121
|
-
const result = v.safeParse(keySchema, key);
|
|
122
|
-
if (result.success) {
|
|
123
|
-
return valueSchema;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
if (__classPrivateFieldGet(this, _EntriesValueSchemaResolver_keySchema, "f")) {
|
|
127
|
-
const result = v.safeParse(__classPrivateFieldGet(this, _EntriesValueSchemaResolver_keySchema, "f"), key);
|
|
128
|
-
if (!result.success) {
|
|
129
|
-
throw new InvalidInputError({
|
|
130
|
-
value: key,
|
|
131
|
-
issues: result.issues,
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
return undefined;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
_EntriesValueSchemaResolver_entries = new WeakMap(), _EntriesValueSchemaResolver_keySchema = new WeakMap();
|
|
139
|
-
/**
|
|
140
|
-
* 検証済みのスキーマ定義からスキーマリゾルバーを生成します。
|
|
141
|
-
*
|
|
142
|
-
* @param schema 検証済みのスキーマ定義です。
|
|
143
|
-
* @returns スキーマリゾルバーを返します。
|
|
144
|
-
*/
|
|
145
|
-
export function createValueSchemaResolver(schema) {
|
|
146
|
-
if (Array.isArray(schema)) {
|
|
147
|
-
return new EntriesValueSchemaResolver(schema);
|
|
148
|
-
}
|
|
149
|
-
return new RecordValueSchemaResolver(schema);
|
|
150
|
-
}
|