unikvs 0.0.13 → 0.0.14

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unikvs",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "description": "A modular and portable KVS client implemented in TypeScript.",
5
5
  "homepage": "https://tai-kun.github.io/unikvs/",
6
6
  "license": "MIT",
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "@tai-kun/valibot-extra-lab": "^0.0.5",
28
- "@unikvs/core": "0.0.13",
28
+ "@unikvs/core": "0.0.14",
29
29
  "abort-signal-utils": "^0.0.6",
30
30
  "asyncmux": "^0.0.12",
31
31
  "call-fn-once": "^0.0.12",
@@ -35,14 +35,14 @@
35
35
  "devDependencies": {
36
36
  "@babel/plugin-proposal-decorators": "^8.0.2",
37
37
  "@rolldown/plugin-babel": "^0.2.4",
38
- "@unikvs/allow-repair": "0.0.13",
39
- "@unikvs/checksum": "0.0.13",
40
- "@unikvs/compression": "0.0.13",
41
- "@unikvs/fs.node": "0.0.13",
42
- "@unikvs/memory": "0.0.13",
43
- "@unikvs/opfs": "0.0.13",
38
+ "@unikvs/allow-repair": "0.0.14",
39
+ "@unikvs/checksum": "0.0.14",
40
+ "@unikvs/compression": "0.0.14",
41
+ "@unikvs/fs.node": "0.0.14",
42
+ "@unikvs/memory": "0.0.14",
43
+ "@unikvs/opfs": "0.0.14",
44
44
  "@unikvs/testing": "0.0.0",
45
- "@unikvs/utils": "0.0.13",
45
+ "@unikvs/utils": "0.0.14",
46
46
  "@vitest/browser-playwright": "5.0.5",
47
47
  "@vitest/coverage-istanbul": "5.0.5",
48
48
  "@vitest/coverage-v8": "5.0.5",
@@ -20,6 +20,11 @@ const instances = /* #__PURE__ */ new WeakMap<IMiddleware, UniKvsMiddleware>();
20
20
  * ミドルウェアを安全に使うための検証などの処理が集約されています。
21
21
  */
22
22
  export default class UniKvsMiddleware {
23
+ /**
24
+ * ミドルウェアの名前です。
25
+ */
26
+ public readonly name: string;
27
+
23
28
  /**
24
29
  * ラップするミドルウェアです。
25
30
  */
@@ -30,11 +35,6 @@ export default class UniKvsMiddleware {
30
35
  */
31
36
  readonly #lifecycle: PluginLifecycle<IMiddleware.OpenContext, IMiddleware.CloseContext>;
32
37
 
33
- /**
34
- * ミドルウェアの名前です。
35
- */
36
- public readonly name: string;
37
-
38
38
  private constructor(middleware: IMiddleware) {
39
39
  this.#mw = middleware;
40
40
  this.#lifecycle = new PluginLifecycle(middleware);
@@ -16,7 +16,7 @@ import type {
16
16
  IActiveLeafChecker,
17
17
  } from "./_pipeline-graph.types.js";
18
18
  import { ReadableStreamSchema } from "./_streams.schemas.js";
19
- import { parseOutput } from "./_valibot.js";
19
+ import * as v from "./_valibot.js";
20
20
  import { MiddlewareDestinationFrozenError, MiddlewareDestinationMissingError } from "./errors.js";
21
21
 
22
22
  /**
@@ -130,7 +130,7 @@ export function requireStreamDestination(
130
130
  ): IReadableStream {
131
131
  const destination = requireDestination(middleware, ctx, operation);
132
132
 
133
- return parseOutput(ReadableStreamSchema, destination);
133
+ return v.parseOutput(ReadableStreamSchema, destination);
134
134
  }
135
135
 
136
136
  /**
package/src/_storage.ts CHANGED
@@ -4,7 +4,7 @@ import { callFnOnce } from "call-fn-once";
4
4
 
5
5
  import { PluginLifecycle } from "./_plugin-lifecycle.js";
6
6
  import { ReadableStreamSchema, WritableStreamSchema } from "./_streams.schemas.js";
7
- import { parseOutput } from "./_valibot.js";
7
+ import * as v from "./_valibot.js";
8
8
  import {
9
9
  type PluginOperationAggregateError,
10
10
  StorageIsNotOpenError,
@@ -23,6 +23,11 @@ const instances = /* #__PURE__ */ new WeakMap<IStorage, UniKvsStorage>();
23
23
  * ストレージを安全に使うための検証などの処理が集約されています。
24
24
  */
25
25
  export default class UniKvsStorage {
26
+ /**
27
+ * ストレージの名前です。
28
+ */
29
+ public readonly name: string;
30
+
26
31
  /**
27
32
  * ラップするストレージです。
28
33
  */
@@ -33,11 +38,6 @@ export default class UniKvsStorage {
33
38
  */
34
39
  readonly #lifecycle: PluginLifecycle<IStorage.OpenContext, IStorage.CloseContext>;
35
40
 
36
- /**
37
- * ストレージの名前です。
38
- */
39
- public readonly name: string;
40
-
41
41
  private constructor(storage: IStorage) {
42
42
  this.#io = storage;
43
43
  this.#lifecycle = new PluginLifecycle(storage);
@@ -175,7 +175,7 @@ export default class UniKvsStorage {
175
175
 
176
176
  const output = await this.#io.getReadable(c);
177
177
 
178
- return parseOutput(ReadableStreamSchema, output);
178
+ return v.parseOutput(ReadableStreamSchema, output);
179
179
  }
180
180
 
181
181
  /**
@@ -196,7 +196,7 @@ export default class UniKvsStorage {
196
196
 
197
197
  const output = await this.#io.getWritable(c);
198
198
 
199
- return parseOutput(WritableStreamSchema, output);
199
+ return v.parseOutput(WritableStreamSchema, output);
200
200
  }
201
201
 
202
202
  /**
@@ -2,7 +2,7 @@ import type { IReadableStream, IWritableStream } from "@unikvs/core";
2
2
  import type { CustomIssue, CustomSchema, ErrorMessage } from "valibot";
3
3
 
4
4
  import { isReadableStream, isWritableStream } from "./_streams.js";
5
- import { custom } from "./_valibot.js";
5
+ import * as v from "./_valibot.js";
6
6
 
7
7
  /**
8
8
  * `ReadableStream` のインターフェースを満たすかを検証するためのスキーマです。
@@ -10,7 +10,7 @@ import { custom } from "./_valibot.js";
10
10
  export const ReadableStreamSchema: CustomSchema<
11
11
  IReadableStream,
12
12
  ErrorMessage<CustomIssue> | undefined
13
- > = custom<IReadableStream>(isReadableStream, "Expected a ReadableStream");
13
+ > = v.custom<IReadableStream>(isReadableStream, "Expected a ReadableStream");
14
14
 
15
15
  /**
16
16
  * `WritableStream` のインターフェースを満たすかを検証するためのスキーマです。
@@ -18,4 +18,4 @@ export const ReadableStreamSchema: CustomSchema<
18
18
  export const WritableStreamSchema: CustomSchema<
19
19
  IWritableStream,
20
20
  ErrorMessage<CustomIssue> | undefined
21
- > = custom<IWritableStream>(isWritableStream, "Expected a WritableStream");
21
+ > = v.custom<IWritableStream>(isWritableStream, "Expected a WritableStream");
@@ -1,5 +1,6 @@
1
1
  import type UniKvsMiddleware from "./_middleware.js";
2
2
  import type UniKvsStorage from "./_storage.js";
3
+ import { InvalidForkError } from "./errors.js";
3
4
  import type { IUniKvsBranch } from "./unikvs-branch.js";
4
5
 
5
6
  /**
@@ -46,47 +47,38 @@ export const branchStates: WeakMap<IUniKvsBranch, BranchState> = /* #__PURE__ */
46
47
  >();
47
48
 
48
49
  /**
49
- * 分岐先のスナップショットを返します。
50
+ * 分岐先を親の接頭辞付きで追加します。
50
51
  *
51
- * 親の `fork` で接頭辞付加するために使用します。
52
52
  * `new Branch()` で作成された分岐以外の値が渡されたときは例外を投げます。
53
53
  * 外部からは使用しません。
54
54
  *
55
- * @param branch スナップショットを取得する分岐です。
56
- *
57
- * @returns 分岐先のコピーを返します。
58
- */
59
- export function getBranchDestinationsForFork(branch: IUniKvsBranch): BranchDestination[] {
60
- const state = branchStates.get(branch);
61
-
62
- if (!state) {
63
- throw new TypeError("fork() expects a branch created by new Branch().");
64
- }
65
-
66
- // コピーを返します。親の fork で接頭辞を付けても、元の分岐は変更されません。
67
- return state.destinations.map((dest) => ({
68
- storage: dest.storage,
69
- middlewares: [...dest.middlewares],
70
- }));
71
- }
72
-
73
- /**
74
- * 分岐先を親の接頭辞付きで追加します。
75
- *
76
55
  * @param destinations 追加先の分岐先列です。
77
56
  * @param prefix 親のミドルウェア列です。
78
57
  * @param branch 追加する分岐です。
58
+ *
59
+ * @throws 分岐がストレージに到達しない場合に `InvalidForkError` を投げます。
79
60
  */
80
61
  export function appendForkDestinations(
81
62
  destinations: BranchDestination[],
82
63
  prefix: readonly UniKvsMiddleware[],
83
64
  branch: IUniKvsBranch,
84
65
  ): void {
66
+ const state = branchStates.get(branch);
67
+
68
+ if (!state) {
69
+ throw new TypeError("fork() expects a branch created by new Branch().");
70
+ }
71
+
72
+ if (state.destinations.length === 0) {
73
+ throw new InvalidForkError();
74
+ }
75
+
85
76
  const prefixSnapshot = [...prefix];
86
77
 
87
- for (const dest of getBranchDestinationsForFork(branch)) {
78
+ for (const dest of state.destinations) {
88
79
  destinations.push({
89
80
  storage: dest.storage,
81
+ // コピーして追加します。親の fork で接頭辞を付けても、元の分岐は変更されません。
90
82
  // fork 時点の親チェーンを接頭辞として各分岐先の先頭に付け、ブランチのミドルウェアを結合します。
91
83
  middlewares: [...prefixSnapshot, ...dest.middlewares],
92
84
  });
@@ -9,34 +9,20 @@ import type {
9
9
  } from "valibot";
10
10
 
11
11
  import type { VariablesEntry } from "./_contexts.js";
12
- import {
13
- omit,
14
- pipe,
15
- tuple,
16
- union,
17
- custom,
18
- object,
19
- record,
20
- string,
21
- boolean,
22
- unknown,
23
- instance,
24
- optional,
25
- transform,
26
- } from "./_valibot.js";
12
+ import * as v from "./_valibot.js";
27
13
 
28
- export const VariablesKeySchema: StringSchema<undefined> = string();
14
+ export const VariablesKeySchema: StringSchema<undefined> = v.string();
29
15
 
30
- export const VariablesInitSchema: GenericSchema<any, readonly VariablesEntry[]> = pipe(
31
- union([
32
- custom<Iterable<VariablesEntry>>(
16
+ export const VariablesInitSchema: GenericSchema<any, readonly VariablesEntry[]> = v.pipe(
17
+ v.union([
18
+ v.custom<Iterable<VariablesEntry>>(
33
19
  // 各アイテムの検証は今後の課題です。
34
20
  (input) => typeof input === "object" && input !== null && Symbol.iterator in input,
35
21
  "Expected a Iterable object",
36
22
  ),
37
- record(VariablesKeySchema, unknown()),
23
+ v.record(VariablesKeySchema, v.unknown()),
38
24
  ]),
39
- transform(
25
+ v.transform(
40
26
  (input: Iterable<VariablesEntry> | Record<string, unknown>): readonly VariablesEntry[] => {
41
27
  if (Symbol.iterator in input) {
42
28
  return [...input];
@@ -47,7 +33,7 @@ export const VariablesInitSchema: GenericSchema<any, readonly VariablesEntry[]>
47
33
  ),
48
34
  );
49
35
 
50
- export const VariablesArgsSchema: TupleSchema<[typeof VariablesInitSchema], undefined> = tuple([
36
+ export const VariablesArgsSchema: TupleSchema<[typeof VariablesInitSchema], undefined> = v.tuple([
51
37
  VariablesInitSchema,
52
38
  ]);
53
39
 
@@ -57,22 +43,22 @@ export const OpenOptionsSchema: ObjectSchema<
57
43
  readonly signal: OptionalSchema<InstanceSchema<typeof AbortSignal, undefined>, undefined>;
58
44
  },
59
45
  undefined
60
- > = object({
46
+ > = v.object({
61
47
  /**
62
48
  * 処理の中断を通知するためのシグナルです。
63
49
  */
64
- signal: optional(instance(AbortSignal)),
50
+ signal: v.optional(v.instance(AbortSignal)),
65
51
 
66
52
  /**
67
53
  * 実行時の変数です。
68
54
  */
69
- vars: optional(VariablesInitSchema),
55
+ vars: v.optional(VariablesInitSchema),
70
56
  });
71
57
 
72
58
  export const OpenArgsSchema: TupleSchema<
73
59
  [OptionalSchema<typeof OpenOptionsSchema, undefined>],
74
60
  undefined
75
- > = tuple([optional(OpenOptionsSchema)]);
61
+ > = v.tuple([v.optional(OpenOptionsSchema)]);
76
62
 
77
63
  export const CloseOptionsSchema: ObjectSchema<
78
64
  {
@@ -80,22 +66,22 @@ export const CloseOptionsSchema: ObjectSchema<
80
66
  readonly signal: OptionalSchema<InstanceSchema<typeof AbortSignal, undefined>, undefined>;
81
67
  },
82
68
  undefined
83
- > = object({
69
+ > = v.object({
84
70
  /**
85
71
  * 処理の中断を通知するためのシグナルです。
86
72
  */
87
- signal: optional(instance(AbortSignal)),
73
+ signal: v.optional(v.instance(AbortSignal)),
88
74
 
89
75
  /**
90
76
  * 実行時の変数です。
91
77
  */
92
- vars: optional(VariablesInitSchema),
78
+ vars: v.optional(VariablesInitSchema),
93
79
  });
94
80
 
95
81
  export const CloseArgsSchema: TupleSchema<
96
82
  [OptionalSchema<typeof CloseOptionsSchema, undefined>],
97
83
  undefined
98
- > = tuple([optional(CloseOptionsSchema)]);
84
+ > = v.tuple([v.optional(CloseOptionsSchema)]);
99
85
 
100
86
  export const SetOptionsSchema: ObjectSchema<
101
87
  {
@@ -105,11 +91,11 @@ export const SetOptionsSchema: ObjectSchema<
105
91
  readonly signal: OptionalSchema<InstanceSchema<typeof AbortSignal, undefined>, undefined>;
106
92
  },
107
93
  undefined
108
- > = object({
109
- key: string(),
110
- vars: optional(VariablesInitSchema),
111
- value: unknown(),
112
- signal: optional(instance(AbortSignal)),
94
+ > = v.object({
95
+ key: v.string(),
96
+ vars: v.optional(VariablesInitSchema),
97
+ value: v.unknown(),
98
+ signal: v.optional(v.instance(AbortSignal)),
113
99
  });
114
100
 
115
101
  export const SetArgsSchema: GenericSchema<
@@ -130,15 +116,15 @@ export const SetArgsSchema: GenericSchema<
130
116
  readonly signal?: AbortSignal | undefined;
131
117
  },
132
118
  ]
133
- > = union([
134
- tuple([SetOptionsSchema]),
135
- pipe(
136
- tuple([
119
+ > = v.union([
120
+ v.tuple([SetOptionsSchema]),
121
+ v.pipe(
122
+ v.tuple([
137
123
  SetOptionsSchema.entries.key,
138
124
  SetOptionsSchema.entries.value,
139
- optional(omit(SetOptionsSchema, ["key", "value"])),
125
+ v.optional(v.omit(SetOptionsSchema, ["key", "value"])),
140
126
  ]),
141
- transform(
127
+ v.transform(
142
128
  ([key, value, options]: [
143
129
  string,
144
130
  unknown,
@@ -176,12 +162,12 @@ export const GetOptionsSchema: ObjectSchema<
176
162
  readonly throwOnRepairDenied: OptionalSchema<BooleanSchema<undefined>, undefined>;
177
163
  },
178
164
  undefined
179
- > = object({
180
- key: string(),
181
- vars: optional(VariablesInitSchema),
182
- repair: optional(boolean()),
183
- signal: optional(instance(AbortSignal)),
184
- throwOnRepairDenied: optional(boolean()),
165
+ > = v.object({
166
+ key: v.string(),
167
+ vars: v.optional(VariablesInitSchema),
168
+ repair: v.optional(v.boolean()),
169
+ signal: v.optional(v.instance(AbortSignal)),
170
+ throwOnRepairDenied: v.optional(v.boolean()),
185
171
  });
186
172
 
187
173
  export const GetArgsSchema: GenericSchema<
@@ -204,11 +190,11 @@ export const GetArgsSchema: GenericSchema<
204
190
  readonly throwOnRepairDenied?: boolean | undefined;
205
191
  },
206
192
  ]
207
- > = union([
208
- tuple([GetOptionsSchema]),
209
- pipe(
210
- tuple([GetOptionsSchema.entries.key, optional(omit(GetOptionsSchema, ["key"]))]),
211
- transform(
193
+ > = v.union([
194
+ v.tuple([GetOptionsSchema]),
195
+ v.pipe(
196
+ v.tuple([GetOptionsSchema.entries.key, v.optional(v.omit(GetOptionsSchema, ["key"]))]),
197
+ v.transform(
212
198
  ([key, options]: [
213
199
  string,
214
200
  (
@@ -247,12 +233,12 @@ export const StreamOptionsSchema: ObjectSchema<
247
233
  readonly throwOnRepairDenied: OptionalSchema<BooleanSchema<undefined>, undefined>;
248
234
  },
249
235
  undefined
250
- > = object({
251
- key: string(),
252
- vars: optional(VariablesInitSchema),
253
- repair: optional(boolean()),
254
- signal: optional(instance(AbortSignal)),
255
- throwOnRepairDenied: optional(boolean()),
236
+ > = v.object({
237
+ key: v.string(),
238
+ vars: v.optional(VariablesInitSchema),
239
+ repair: v.optional(v.boolean()),
240
+ signal: v.optional(v.instance(AbortSignal)),
241
+ throwOnRepairDenied: v.optional(v.boolean()),
256
242
  });
257
243
 
258
244
  export const StreamArgsSchema: GenericSchema<
@@ -275,11 +261,11 @@ export const StreamArgsSchema: GenericSchema<
275
261
  readonly throwOnRepairDenied?: boolean | undefined;
276
262
  },
277
263
  ]
278
- > = union([
279
- tuple([StreamOptionsSchema]),
280
- pipe(
281
- tuple([StreamOptionsSchema.entries.key, optional(omit(StreamOptionsSchema, ["key"]))]),
282
- transform(
264
+ > = v.union([
265
+ v.tuple([StreamOptionsSchema]),
266
+ v.pipe(
267
+ v.tuple([StreamOptionsSchema.entries.key, v.optional(v.omit(StreamOptionsSchema, ["key"]))]),
268
+ v.transform(
283
269
  ([key, options]: [
284
270
  string,
285
271
  (
@@ -316,10 +302,10 @@ export const HasOptionsSchema: ObjectSchema<
316
302
  readonly signal: OptionalSchema<InstanceSchema<typeof AbortSignal, undefined>, undefined>;
317
303
  },
318
304
  undefined
319
- > = object({
320
- key: string(),
321
- vars: optional(VariablesInitSchema),
322
- signal: optional(instance(AbortSignal)),
305
+ > = v.object({
306
+ key: v.string(),
307
+ vars: v.optional(VariablesInitSchema),
308
+ signal: v.optional(v.instance(AbortSignal)),
323
309
  });
324
310
 
325
311
  export const HasArgsSchema: GenericSchema<
@@ -338,11 +324,11 @@ export const HasArgsSchema: GenericSchema<
338
324
  readonly signal?: AbortSignal | undefined;
339
325
  },
340
326
  ]
341
- > = union([
342
- tuple([HasOptionsSchema]),
343
- pipe(
344
- tuple([HasOptionsSchema.entries.key, optional(omit(HasOptionsSchema, ["key"]))]),
345
- transform(
327
+ > = v.union([
328
+ v.tuple([HasOptionsSchema]),
329
+ v.pipe(
330
+ v.tuple([HasOptionsSchema.entries.key, v.optional(v.omit(HasOptionsSchema, ["key"]))]),
331
+ v.transform(
346
332
  ([key, options]: [
347
333
  string,
348
334
  (
@@ -375,10 +361,10 @@ export const DeleteOptionsSchema: ObjectSchema<
375
361
  readonly signal: OptionalSchema<InstanceSchema<typeof AbortSignal, undefined>, undefined>;
376
362
  },
377
363
  undefined
378
- > = object({
379
- key: string(),
380
- vars: optional(VariablesInitSchema),
381
- signal: optional(instance(AbortSignal)),
364
+ > = v.object({
365
+ key: v.string(),
366
+ vars: v.optional(VariablesInitSchema),
367
+ signal: v.optional(v.instance(AbortSignal)),
382
368
  });
383
369
 
384
370
  export const DeleteArgsSchema: GenericSchema<
@@ -397,11 +383,11 @@ export const DeleteArgsSchema: GenericSchema<
397
383
  readonly signal?: AbortSignal | undefined;
398
384
  },
399
385
  ]
400
- > = union([
401
- tuple([DeleteOptionsSchema]),
402
- pipe(
403
- tuple([DeleteOptionsSchema.entries.key, optional(omit(DeleteOptionsSchema, ["key"]))]),
404
- transform(
386
+ > = v.union([
387
+ v.tuple([DeleteOptionsSchema]),
388
+ v.pipe(
389
+ v.tuple([DeleteOptionsSchema.entries.key, v.optional(v.omit(DeleteOptionsSchema, ["key"]))]),
390
+ v.transform(
405
391
  ([key, options]: [
406
392
  string,
407
393
  (
@@ -433,19 +419,19 @@ export const ClearOptionsSchema: ObjectSchema<
433
419
  readonly signal: OptionalSchema<InstanceSchema<typeof AbortSignal, undefined>, undefined>;
434
420
  },
435
421
  undefined
436
- > = object({
422
+ > = v.object({
437
423
  /**
438
424
  * 処理の中断を通知するためのシグナルです。
439
425
  */
440
- signal: optional(instance(AbortSignal)),
426
+ signal: v.optional(v.instance(AbortSignal)),
441
427
 
442
428
  /**
443
429
  * 実行時の変数です。
444
430
  */
445
- vars: optional(VariablesInitSchema),
431
+ vars: v.optional(VariablesInitSchema),
446
432
  });
447
433
 
448
434
  export const ClearArgsSchema: TupleSchema<
449
435
  [OptionalSchema<typeof ClearOptionsSchema, undefined>],
450
436
  undefined
451
- > = tuple([optional(ClearOptionsSchema)]);
437
+ > = v.tuple([v.optional(ClearOptionsSchema)]);
@@ -1,5 +1,4 @@
1
- import type { GenericSchema } from "./_valibot.js";
2
- import { union, safeParse } from "./_valibot.js";
1
+ import * as v from "./_valibot.js";
3
2
  import { InvalidInputError } from "./errors.js";
4
3
  import type { PlainValue, StreamValue } from "./value-schemas.js";
5
4
 
@@ -71,7 +70,7 @@ export type ValueSchemaInfo = {
71
70
  /**
72
71
  * データの検証に使用するスキーマです。
73
72
  */
74
- readonly schema: GenericSchema;
73
+ readonly schema: v.GenericSchema;
75
74
  };
76
75
 
77
76
  // -------------------------------------------------------------------------------------------------。
@@ -88,7 +87,7 @@ type UniKvsSchemaInfoRecord = Readonly<Record<string, ValueSchemaInfo>>;
88
87
  /**
89
88
  * 検証済みの配列形式のスキーマ定義です。
90
89
  */
91
- type UniKvsSchemaInfoEntries = readonly (readonly [GenericSchema, ValueSchemaInfo])[];
90
+ type UniKvsSchemaInfoEntries = readonly (readonly [v.GenericSchema, ValueSchemaInfo])[];
92
91
 
93
92
  /**
94
93
  * 検証済みのスキーマ定義です。
@@ -140,12 +139,12 @@ class RecordValueSchemaResolver implements IValueSchemaResolver {
140
139
  class EntriesValueSchemaResolver implements IValueSchemaResolver {
141
140
  readonly #entries: UniKvsSchemaInfoEntries;
142
141
 
143
- readonly #keySchema: GenericSchema | undefined;
142
+ readonly #keySchema: v.GenericSchema | undefined;
144
143
 
145
144
  public constructor(entries: UniKvsSchemaInfoEntries) {
146
145
  this.#entries = entries;
147
146
  if (entries.length > 0) {
148
- this.#keySchema = union(entries.map(([keySchema]) => keySchema));
147
+ this.#keySchema = v.union(entries.map(([keySchema]) => keySchema));
149
148
  }
150
149
  }
151
150
 
@@ -153,7 +152,7 @@ class EntriesValueSchemaResolver implements IValueSchemaResolver {
153
152
  let resolved: ValueSchemaInfo | undefined;
154
153
 
155
154
  for (const [keySchema, valueSchema] of this.#entries) {
156
- const result = safeParse(keySchema, key);
155
+ const result = v.safeParse(keySchema, key);
157
156
 
158
157
  if (result.success) {
159
158
  resolved = valueSchema;
@@ -162,7 +161,7 @@ class EntriesValueSchemaResolver implements IValueSchemaResolver {
162
161
  }
163
162
 
164
163
  if (resolved === undefined && this.#keySchema) {
165
- const result = safeParse(this.#keySchema, key);
164
+ const result = v.safeParse(this.#keySchema, key);
166
165
 
167
166
  if (!result.success) {
168
167
  throw new InvalidInputError({
@@ -1,13 +1,13 @@
1
1
  import { isReadableStream } from "./_streams.js";
2
- import { pipe, check, unknown, parseInput } from "./_valibot.js";
2
+ import * as v from "./_valibot.js";
3
3
  import type { ValueSchemaInfo } from "./_value-schemas.js";
4
4
 
5
5
  /**
6
6
  * プレーン値専用のスキーマに ReadableStream が渡されたことを報告するためのスキーマです。
7
7
  */
8
- const PlainValueInputSchema = pipe(
9
- unknown(),
10
- check(
8
+ const PlainValueInputSchema = v.pipe(
9
+ v.unknown(),
10
+ v.check(
11
11
  (input) => !isReadableStream(input),
12
12
  "Expected a plain value, but received a ReadableStream",
13
13
  ),
@@ -16,9 +16,9 @@ const PlainValueInputSchema = pipe(
16
16
  /**
17
17
  * ストリーム専用のスキーマにプレーン値が渡されたことを報告するためのスキーマです。
18
18
  */
19
- const StreamValueInputSchema = pipe(
20
- unknown(),
21
- check(isReadableStream, "Expected a ReadableStream, but received a plain value"),
19
+ const StreamValueInputSchema = v.pipe(
20
+ v.unknown(),
21
+ v.check(isReadableStream, "Expected a ReadableStream, but received a plain value"),
22
22
  );
23
23
 
24
24
  /**
@@ -35,14 +35,14 @@ export function parseSetValue(info: ValueSchemaInfo, value: unknown): unknown {
35
35
  if (isReadableStream(value)) {
36
36
  if (info.kind === "plain") {
37
37
  // 必ず検証に失敗するため、InvalidInputError が投げられます。
38
- parseInput(PlainValueInputSchema, value);
38
+ v.parseInput(PlainValueInputSchema, value);
39
39
  }
40
40
 
41
41
  // 入力チャンクを検証し、変換後の値を後続のパイプラインへ流します。
42
42
  return value.pipeThrough(
43
43
  new TransformStream({
44
44
  transform(chunk, controller) {
45
- controller.enqueue(parseInput(info.schema, chunk));
45
+ controller.enqueue(v.parseInput(info.schema, chunk));
46
46
  },
47
47
  }),
48
48
  );
@@ -50,8 +50,8 @@ export function parseSetValue(info: ValueSchemaInfo, value: unknown): unknown {
50
50
 
51
51
  if (info.kind === "stream") {
52
52
  // 必ず検証に失敗するため、InvalidInputError が投げられます。
53
- parseInput(StreamValueInputSchema, value);
53
+ v.parseInput(StreamValueInputSchema, value);
54
54
  }
55
55
 
56
- return parseInput(info.schema, value);
56
+ return v.parseInput(info.schema, value);
57
57
  }