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.
Files changed (82) hide show
  1. package/README.md +2 -2
  2. package/dist/index.d.ts +1553 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +4032 -0
  5. package/dist/index.js.map +1 -0
  6. package/package.json +34 -34
  7. package/src/_contexts.ts +1089 -0
  8. package/src/_logger.ts +5 -3
  9. package/src/_middleware.ts +207 -0
  10. package/src/_pipeline-graph.helpers.ts +183 -0
  11. package/src/_pipeline-graph.ts +1307 -0
  12. package/src/_pipeline-graph.types.ts +303 -0
  13. package/src/_pipeline-leaf-resolver.ts +70 -0
  14. package/src/_plugin-lifecycle.ts +201 -0
  15. package/src/_storage.ts +169 -115
  16. package/src/_streams.schemas.ts +21 -0
  17. package/src/_streams.ts +32 -6
  18. package/src/_to-value-stream.ts +22 -11
  19. package/src/_types.ts +237 -0
  20. package/src/_unikvs-branch.ts +94 -0
  21. package/src/_unikvs.schemas.ts +451 -0
  22. package/src/_valibot.ts +17 -6
  23. package/src/_value-schemas.ts +36 -206
  24. package/src/_value-validation.ts +57 -0
  25. package/src/errors.ts +391 -148
  26. package/src/index.ts +46 -25
  27. package/src/{value-stream.types.ts → types.ts} +1 -1
  28. package/src/unikvs-branch.ts +445 -0
  29. package/src/unikvs-builder.ts +706 -0
  30. package/src/unikvs.ts +1423 -1007
  31. package/src/unikvs.types.ts +194 -0
  32. package/src/value-schemas.ts +98 -0
  33. package/dist/src/_logger.d.ts +0 -3
  34. package/dist/src/_logger.d.ts.map +0 -1
  35. package/dist/src/_logger.js +0 -3
  36. package/dist/src/_merge-variables.d.ts +0 -13
  37. package/dist/src/_merge-variables.d.ts.map +0 -1
  38. package/dist/src/_merge-variables.js +0 -12
  39. package/dist/src/_storage.d.ts +0 -18
  40. package/dist/src/_storage.d.ts.map +0 -1
  41. package/dist/src/_storage.js +0 -103
  42. package/dist/src/_streams.d.ts +0 -20
  43. package/dist/src/_streams.d.ts.map +0 -1
  44. package/dist/src/_streams.js +0 -36
  45. package/dist/src/_to-value-stream.d.ts +0 -12
  46. package/dist/src/_to-value-stream.d.ts.map +0 -1
  47. package/dist/src/_to-value-stream.js +0 -102
  48. package/dist/src/_transformer.d.ts +0 -13
  49. package/dist/src/_transformer.d.ts.map +0 -1
  50. package/dist/src/_transformer.js +0 -60
  51. package/dist/src/_valibot.d.ts +0 -15
  52. package/dist/src/_valibot.d.ts.map +0 -1
  53. package/dist/src/_valibot.js +0 -23
  54. package/dist/src/_value-schemas.d.ts +0 -179
  55. package/dist/src/_value-schemas.d.ts.map +0 -1
  56. package/dist/src/_value-schemas.js +0 -150
  57. package/dist/src/errors.d.ts +0 -306
  58. package/dist/src/errors.d.ts.map +0 -1
  59. package/dist/src/errors.js +0 -234
  60. package/dist/src/index.d.ts +0 -10
  61. package/dist/src/index.d.ts.map +0 -1
  62. package/dist/src/index.js +0 -3
  63. package/dist/src/unikvs-config.d.ts +0 -174
  64. package/dist/src/unikvs-config.d.ts.map +0 -1
  65. package/dist/src/unikvs-config.js +0 -100
  66. package/dist/src/unikvs.d.ts +0 -272
  67. package/dist/src/unikvs.d.ts.map +0 -1
  68. package/dist/src/unikvs.js +0 -928
  69. package/dist/src/utils.types.d.ts +0 -5
  70. package/dist/src/utils.types.d.ts.map +0 -1
  71. package/dist/src/utils.types.js +0 -1
  72. package/dist/src/value-stream.types.d.ts +0 -10
  73. package/dist/src/value-stream.types.d.ts.map +0 -1
  74. package/dist/src/value-stream.types.js +0 -1
  75. package/dist/src/variables.types.d.ts +0 -11
  76. package/dist/src/variables.types.d.ts.map +0 -1
  77. package/dist/src/variables.types.js +0 -1
  78. package/src/_merge-variables.ts +0 -19
  79. package/src/_transformer.ts +0 -89
  80. package/src/unikvs-config.ts +0 -401
  81. package/src/utils.types.ts +0 -4
  82. package/src/variables.types.ts +0 -13
@@ -0,0 +1,1089 @@
1
+ import {
2
+ type IGetContext,
3
+ type IHasContext,
4
+ type ISetContext,
5
+ type IOpenContext,
6
+ type IClearContext,
7
+ type ICloseContext,
8
+ type IActionContext,
9
+ type IDecodeContext,
10
+ type IDeleteContext,
11
+ type IEncodeContext,
12
+ type IMapKeyContext,
13
+ type IStreamContext,
14
+ type IReadableStream,
15
+ type IPipelineContext,
16
+ type ILifecycleContext,
17
+ type ITransformContext,
18
+ type IKeyedActionContext,
19
+ type IDecodeStreamContext,
20
+ type IEncodeStreamContext,
21
+ type ITransformDataContext,
22
+ type ITransformStreamContext,
23
+ ReadonlyVariableError,
24
+ } from "@unikvs/core";
25
+
26
+ /**
27
+ * 実行時変数の 1 件分の形式です。
28
+ */
29
+ export type VariablesEntry = readonly [name: string, value: unknown];
30
+
31
+ /**
32
+ * 実行時変数の初期値に使えるマップ形式です。
33
+ *
34
+ * レコードまたはエントリーの反復子を受け付けます。
35
+ */
36
+ export type VariablesInit = Readonly<Record<string, unknown>> | Iterable<VariablesEntry>;
37
+
38
+ /**
39
+ * 実行時変数の初期値をエントリー列に正規化します。
40
+ *
41
+ * レコードは `Object.entries` で展開します。
42
+ * 反復子はそのまま返します。
43
+ *
44
+ * @param vars 初期値です。
45
+ *
46
+ * @returns エントリー列を返します。
47
+ */
48
+ function normalizeVariablesInit(vars: VariablesInit | undefined): Iterable<VariablesEntry> {
49
+ if (!vars) {
50
+ return [];
51
+ }
52
+
53
+ if (Symbol.iterator in vars) {
54
+ return vars;
55
+ }
56
+
57
+ return Object.entries(vars);
58
+ }
59
+
60
+ /**
61
+ * 複数のコンテキスト間で共有される変数ストアです。
62
+ *
63
+ * オニオン実行では操作内の全コンテキストが同一ストアを参照します。
64
+ * 下流の `set` を上流が `await next()` の後に `get` で参照できます。
65
+ */
66
+ export type VariablesStore = {
67
+ /**
68
+ * 変数のマップです。
69
+ */
70
+ readonly data: Map<string, unknown>;
71
+
72
+ /**
73
+ * 読み取り専用の変数名の集合です。
74
+ */
75
+ readonly readonly: Set<string>;
76
+ };
77
+
78
+ /**
79
+ * 新しい空の変数ストアを作成します。
80
+ *
81
+ * @param vars 初期値です。
82
+ *
83
+ * @returns 空ストアを返します。
84
+ */
85
+ export function createVariablesStore(
86
+ vars: readonly VariablesEntry[] | undefined = [],
87
+ ): VariablesStore {
88
+ return {
89
+ data: new Map(vars),
90
+ readonly: new Set(),
91
+ };
92
+ }
93
+
94
+ /**
95
+ * `PipelineContext` の初期値です。
96
+ */
97
+ type PipelineContextInit = {
98
+ /**
99
+ * 実行時変数の初期値です。
100
+ */
101
+ readonly vars?: VariablesInit | undefined;
102
+
103
+ /**
104
+ * 共有する変数ストアです。
105
+ *
106
+ * 指定したときは `vars` を複写せず、ストアの参照を共有します。
107
+ * 下流の `set` は上流の `get` に見えます。
108
+ * オニオン実行のネストで使用します。
109
+ * 省略時は独立したストアを作成します。
110
+ */
111
+ readonly store?: VariablesStore | undefined;
112
+ };
113
+
114
+ /**
115
+ * 実行時変数を保持する基底コンテキストです。
116
+ */
117
+ class PipelineContext implements IPipelineContext {
118
+ /**
119
+ * 変数のマップです。共有ストアの参照である場合があります。
120
+ */
121
+ readonly #data: Map<string, unknown>;
122
+
123
+ /**
124
+ * 読み取り専用の変数名の集合です。共有ストアの参照である場合があります。
125
+ */
126
+ readonly #readonly: Set<string>;
127
+
128
+ /**
129
+ * コンテキストを作成します。
130
+ *
131
+ * @param init 初期値です。
132
+ */
133
+ public constructor(init: PipelineContextInit) {
134
+ const { store } = init;
135
+
136
+ if (store) {
137
+ // 共有ストアを参照し、下流の変更が上流に見えるようにします。
138
+ this.#data = store.data;
139
+ this.#readonly = store.readonly;
140
+ } else {
141
+ this.#data = new Map();
142
+ this.#readonly = new Set();
143
+ }
144
+
145
+ const vars = normalizeVariablesInit(init.vars);
146
+
147
+ for (const [name, value] of vars) {
148
+ this.#data.set(name, value);
149
+ }
150
+ }
151
+
152
+ /**
153
+ * 変数の値を読み取ります。
154
+ *
155
+ * @param name 変数名です。
156
+ *
157
+ * @returns 変数の値を返します。
158
+ */
159
+ public get(name: string): unknown {
160
+ return this.#data.get(name);
161
+ }
162
+
163
+ /**
164
+ * 変数の値を書き込みます。
165
+ *
166
+ * @param name 変数名です。
167
+ * @param value 設定する値です。
168
+ *
169
+ * @returns 自身を返します。
170
+ */
171
+ public set(name: string, value: unknown): this {
172
+ if (this.#readonly.has(name)) {
173
+ throw new ReadonlyVariableError({ name });
174
+ }
175
+
176
+ this.#data.set(name, value);
177
+
178
+ return this;
179
+ }
180
+
181
+ /**
182
+ * 変数の値を設定し、読み取り専用にします。
183
+ *
184
+ * @param name 変数名です。
185
+ * @param value 設定する値です。
186
+ *
187
+ * @returns 自身を返します。
188
+ */
189
+ public setReadonly(name: string, value: unknown): this {
190
+ if (this.#readonly.has(name)) {
191
+ throw new ReadonlyVariableError({ name });
192
+ }
193
+
194
+ this.#data.set(name, value);
195
+ this.#readonly.add(name);
196
+
197
+ return this;
198
+ }
199
+ }
200
+
201
+ /**
202
+ * `MapKeyContext` の初期値です。
203
+ */
204
+ type MapKeyContextInit = {
205
+ /**
206
+ * 対象のキーです。
207
+ */
208
+ readonly key: string;
209
+
210
+ /**
211
+ * 共有する変数ストアです。
212
+ *
213
+ * 指定したときは `vars` を複写せず、ストアの参照を共有します。
214
+ * 下流の `set` は上流の `get` に見えます。
215
+ * オニオン実行のネストで使用します。
216
+ * 省略時は独立したストアを作成します。
217
+ */
218
+ readonly store?: VariablesStore | undefined;
219
+
220
+ /**
221
+ * 実行時変数の初期値です。
222
+ */
223
+ readonly vars?: VariablesInit | undefined;
224
+ };
225
+
226
+ export class MapKeyContext extends PipelineContext implements IMapKeyContext {
227
+ /**
228
+ * 対象のキーです。
229
+ */
230
+ public readonly key: string;
231
+
232
+ /**
233
+ * コンテキストを作成します。
234
+ *
235
+ * @param init 初期値です。
236
+ */
237
+ public constructor(init: MapKeyContextInit) {
238
+ const { key, vars, store } = init;
239
+ super({
240
+ vars,
241
+ store,
242
+ });
243
+ this.key = key;
244
+ }
245
+ }
246
+
247
+ /**
248
+ * `ActionContext` の初期値です。
249
+ */
250
+ type ActionContextInit<TAction extends IActionContext["action"]> = {
251
+ /**
252
+ * 実行する操作の種別です。
253
+ */
254
+ readonly action: TAction;
255
+
256
+ /**
257
+ * 中断を知らせるシグナルです。
258
+ */
259
+ readonly signal: AbortSignal;
260
+
261
+ /**
262
+ * 共有する変数ストアです。
263
+ *
264
+ * 指定したときは `vars` を複写せず、ストアの参照を共有します。
265
+ * 下流の `set` は上流の `get` に見えます。
266
+ * オニオン実行のネストで使用します。
267
+ * 省略時は独立したストアを作成します。
268
+ */
269
+ readonly store?: VariablesStore | undefined;
270
+
271
+ /**
272
+ * 実行時変数の初期値です。
273
+ */
274
+ readonly vars?: VariablesInit | undefined;
275
+ };
276
+
277
+ class ActionContext<const TAction extends IActionContext["action"]>
278
+ extends PipelineContext
279
+ implements IActionContext
280
+ {
281
+ /**
282
+ * 実行する操作の種別です。
283
+ */
284
+ public readonly action: TAction;
285
+
286
+ /**
287
+ * 中断を知らせるシグナルです。
288
+ */
289
+ public readonly signal: AbortSignal;
290
+
291
+ /**
292
+ * コンテキストを作成します。
293
+ *
294
+ * @param init 初期値です。
295
+ */
296
+ public constructor(init: ActionContextInit<TAction>) {
297
+ const { vars, store, action, signal } = init;
298
+ super({
299
+ vars,
300
+ store,
301
+ });
302
+ this.action = action;
303
+ this.signal = signal;
304
+ }
305
+ }
306
+
307
+ class LifecycleContext<const TAction extends ILifecycleContext["action"]>
308
+ extends ActionContext<TAction>
309
+ implements ILifecycleContext {}
310
+
311
+ /**
312
+ * `OpenContext` の初期値です。
313
+ */
314
+ type OpenContextInit = {
315
+ /**
316
+ * 中断を知らせるシグナルです。
317
+ */
318
+ readonly signal: AbortSignal;
319
+
320
+ /**
321
+ * 共有する変数ストアです。
322
+ *
323
+ * 指定したときは `vars` を複写せず、ストアの参照を共有します。
324
+ * 下流の `set` は上流の `get` に見えます。
325
+ * オニオン実行のネストで使用します。
326
+ * 省略時は独立したストアを作成します。
327
+ */
328
+ readonly store?: VariablesStore | undefined;
329
+
330
+ /**
331
+ * 実行時変数の初期値です。
332
+ */
333
+ readonly vars?: VariablesInit | undefined;
334
+ };
335
+
336
+ /**
337
+ * 開始処理のコンテキストです。
338
+ */
339
+ export class OpenContext extends LifecycleContext<"open"> implements IOpenContext {
340
+ /**
341
+ * コンテキストを作成します。
342
+ *
343
+ * @param init 初期値です。
344
+ */
345
+ public constructor(init: OpenContextInit) {
346
+ super({
347
+ ...init,
348
+ action: "open",
349
+ });
350
+ }
351
+ }
352
+
353
+ /**
354
+ * `CloseContext` の初期値です。
355
+ */
356
+ type CloseContextInit = {
357
+ /**
358
+ * 中断を知らせるシグナルです。
359
+ */
360
+ readonly signal: AbortSignal;
361
+
362
+ /**
363
+ * 共有する変数ストアです。
364
+ *
365
+ * 指定したときは `vars` を複写せず、ストアの参照を共有します。
366
+ * 下流の `set` は上流の `get` に見えます。
367
+ * オニオン実行のネストで使用します。
368
+ * 省略時は独立したストアを作成します。
369
+ */
370
+ readonly store?: VariablesStore | undefined;
371
+
372
+ /**
373
+ * 実行時変数の初期値です。
374
+ */
375
+ readonly vars?: VariablesInit | undefined;
376
+ };
377
+
378
+ /**
379
+ * 終了処理のコンテキストです。
380
+ */
381
+ export class CloseContext extends LifecycleContext<"close"> implements ICloseContext {
382
+ /**
383
+ * コンテキストを作成します。
384
+ *
385
+ * @param init 初期値です。
386
+ */
387
+ public constructor(init: CloseContextInit) {
388
+ super({
389
+ ...init,
390
+ action: "close",
391
+ });
392
+ }
393
+ }
394
+
395
+ /**
396
+ * `KeyedActionContext` の初期値です。
397
+ */
398
+ type KeyedActionContextInit<TAction extends IKeyedActionContext["action"]> = {
399
+ /**
400
+ * 実行する操作の種別です。
401
+ */
402
+ readonly action: TAction;
403
+
404
+ /**
405
+ * 対象のキーです。
406
+ */
407
+ readonly key: string;
408
+
409
+ /**
410
+ * 中断を知らせるシグナルです。
411
+ */
412
+ readonly signal: AbortSignal;
413
+
414
+ /**
415
+ * 共有する変数ストアです。
416
+ *
417
+ * 指定したときは `vars` を複写せず、ストアの参照を共有します。
418
+ * 下流の `set` は上流の `get` に見えます。
419
+ * オニオン実行のネストで使用します。
420
+ * 省略時は独立したストアを作成します。
421
+ */
422
+ readonly store?: VariablesStore | undefined;
423
+
424
+ /**
425
+ * 実行時変数の初期値です。
426
+ */
427
+ readonly vars?: VariablesInit | undefined;
428
+ };
429
+
430
+ class KeyedActionContext<TAction extends IKeyedActionContext["action"]>
431
+ extends ActionContext<TAction>
432
+ implements IKeyedActionContext
433
+ {
434
+ /**
435
+ * 対象のキーです。
436
+ */
437
+ public readonly key: string;
438
+
439
+ /**
440
+ * コンテキストを作成します。
441
+ *
442
+ * @param init 初期値です。
443
+ */
444
+ public constructor(init: KeyedActionContextInit<TAction>) {
445
+ const { key, ...superInit } = init;
446
+ super(superInit);
447
+ this.key = key;
448
+ }
449
+ }
450
+
451
+ /**
452
+ * `SetContext` の初期値です。
453
+ */
454
+ type SetContextInit = {
455
+ /**
456
+ * 対象のキーです。
457
+ */
458
+ readonly key: string;
459
+
460
+ /**
461
+ * 中断を知らせるシグナルです。
462
+ */
463
+ readonly signal: AbortSignal;
464
+
465
+ /**
466
+ * 共有する変数ストアです。
467
+ *
468
+ * 指定したときは `vars` を複写せず、ストアの参照を共有します。
469
+ * 下流の `set` は上流の `get` に見えます。
470
+ * オニオン実行のネストで使用します。
471
+ * 省略時は独立したストアを作成します。
472
+ */
473
+ readonly store?: VariablesStore | undefined;
474
+
475
+ /**
476
+ * 実行時変数の初期値です。
477
+ */
478
+ readonly vars?: VariablesInit | undefined;
479
+ };
480
+
481
+ /**
482
+ * 書き込み処理のコンテキストです。
483
+ */
484
+ export class SetContext extends KeyedActionContext<"set"> implements ISetContext {
485
+ /**
486
+ * コンテキストを作成します。
487
+ *
488
+ * @param init 初期値です。
489
+ */
490
+ public constructor(init: SetContextInit) {
491
+ super({
492
+ ...init,
493
+ action: "set",
494
+ });
495
+ }
496
+ }
497
+
498
+ /**
499
+ * `GetContext` の初期値です。
500
+ */
501
+ type GetContextInit = {
502
+ /**
503
+ * 対象のキーです。
504
+ */
505
+ readonly key: string;
506
+
507
+ /**
508
+ * 中断を知らせるシグナルです。
509
+ */
510
+ readonly signal: AbortSignal;
511
+
512
+ /**
513
+ * 修復の条件です。
514
+ *
515
+ * 省略時は修復しません。
516
+ */
517
+ readonly repair?: IGetContext["repair"] | undefined;
518
+
519
+ /**
520
+ * 共有する変数ストアです。
521
+ *
522
+ * 指定したときは `vars` を複写せず、ストアの参照を共有します。
523
+ * 下流の `set` は上流の `get` に見えます。
524
+ * オニオン実行のネストで使用します。
525
+ * 省略時は独立したストアを作成します。
526
+ */
527
+ readonly store?: VariablesStore | undefined;
528
+
529
+ /**
530
+ * 実行時変数の初期値です。
531
+ */
532
+ readonly vars?: VariablesInit | undefined;
533
+ };
534
+
535
+ /**
536
+ * 読み取り処理のコンテキストです。
537
+ */
538
+ export class GetContext extends KeyedActionContext<"get"> implements IGetContext {
539
+ /**
540
+ * 修復の条件です。
541
+ */
542
+ public readonly repair: IGetContext["repair"];
543
+
544
+ /**
545
+ * コンテキストを作成します。
546
+ *
547
+ * @param init 初期値です。
548
+ */
549
+ public constructor(init: GetContextInit) {
550
+ const {
551
+ repair = {
552
+ enabled: false,
553
+ targets: [],
554
+ },
555
+ ...superInit
556
+ } = init;
557
+ super({
558
+ ...superInit,
559
+ action: "get",
560
+ });
561
+ this.repair = repair;
562
+ }
563
+ }
564
+
565
+ /**
566
+ * `StreamContext` の初期値です。
567
+ */
568
+ type StreamContextInit = {
569
+ /**
570
+ * 対象のキーです。
571
+ */
572
+ readonly key: string;
573
+
574
+ /**
575
+ * 中断を知らせるシグナルです。
576
+ */
577
+ readonly signal: AbortSignal;
578
+
579
+ /**
580
+ * 修復の条件です。
581
+ *
582
+ * 省略時は修復しません。
583
+ */
584
+ readonly repair?: IStreamContext["repair"] | undefined;
585
+
586
+ /**
587
+ * 共有する変数ストアです。
588
+ *
589
+ * 指定したときは `vars` を複写せず、ストアの参照を共有します。
590
+ * 下流の `set` は上流の `get` に見えます。
591
+ * オニオン実行のネストで使用します。
592
+ * 省略時は独立したストアを作成します。
593
+ */
594
+ readonly store?: VariablesStore | undefined;
595
+
596
+ /**
597
+ * 実行時変数の初期値です。
598
+ */
599
+ readonly vars?: VariablesInit | undefined;
600
+ };
601
+
602
+ /**
603
+ * ストリーム処理のコンテキストです。
604
+ */
605
+ export class StreamContext extends KeyedActionContext<"stream"> implements IStreamContext {
606
+ /**
607
+ * 修復の条件です。
608
+ */
609
+ public readonly repair: IStreamContext["repair"];
610
+
611
+ /**
612
+ * コンテキストを作成します。
613
+ *
614
+ * @param init 初期値です。
615
+ */
616
+ public constructor(init: StreamContextInit) {
617
+ const {
618
+ repair = {
619
+ enabled: false,
620
+ targets: [],
621
+ },
622
+ ...superInit
623
+ } = init;
624
+ super({
625
+ ...superInit,
626
+ action: "stream",
627
+ });
628
+ this.repair = repair;
629
+ }
630
+ }
631
+
632
+ /**
633
+ * `HasContext` の初期値です。
634
+ */
635
+ type HasContextInit = {
636
+ /**
637
+ * 対象のキーです。
638
+ */
639
+ readonly key: string;
640
+
641
+ /**
642
+ * 中断を知らせるシグナルです。
643
+ */
644
+ readonly signal: AbortSignal;
645
+
646
+ /**
647
+ * 共有する変数ストアです。
648
+ *
649
+ * 指定したときは `vars` を複写せず、ストアの参照を共有します。
650
+ * 下流の `set` は上流の `get` に見えます。
651
+ * オニオン実行のネストで使用します。
652
+ * 省略時は独立したストアを作成します。
653
+ */
654
+ readonly store?: VariablesStore | undefined;
655
+
656
+ /**
657
+ * 実行時変数の初期値です。
658
+ */
659
+ readonly vars?: VariablesInit | undefined;
660
+ };
661
+
662
+ /**
663
+ * 存在確認のコンテキストです。
664
+ */
665
+ export class HasContext extends KeyedActionContext<"has"> implements IHasContext {
666
+ /**
667
+ * コンテキストを作成します。
668
+ *
669
+ * @param init 初期値です。
670
+ */
671
+ public constructor(init: HasContextInit) {
672
+ super({
673
+ ...init,
674
+ action: "has",
675
+ });
676
+ }
677
+ }
678
+
679
+ /**
680
+ * `DeleteContext` の初期値です。
681
+ */
682
+ type DeleteContextInit = {
683
+ /**
684
+ * 対象のキーです。
685
+ */
686
+ readonly key: string;
687
+
688
+ /**
689
+ * 中断を知らせるシグナルです。
690
+ */
691
+ readonly signal: AbortSignal;
692
+
693
+ /**
694
+ * 共有する変数ストアです。
695
+ *
696
+ * 指定したときは `vars` を複写せず、ストアの参照を共有します。
697
+ * 下流の `set` は上流の `get` に見えます。
698
+ * オニオン実行のネストで使用します。
699
+ * 省略時は独立したストアを作成します。
700
+ */
701
+ readonly store?: VariablesStore | undefined;
702
+
703
+ /**
704
+ * 実行時変数の初期値です。
705
+ */
706
+ readonly vars?: VariablesInit | undefined;
707
+ };
708
+
709
+ /**
710
+ * 削除処理のコンテキストです。
711
+ */
712
+ export class DeleteContext extends KeyedActionContext<"delete"> implements IDeleteContext {
713
+ /**
714
+ * コンテキストを作成します。
715
+ *
716
+ * @param init 初期値です。
717
+ */
718
+ public constructor(init: DeleteContextInit) {
719
+ super({
720
+ ...init,
721
+ action: "delete",
722
+ });
723
+ }
724
+ }
725
+
726
+ /**
727
+ * `ClearContext` の初期値です。
728
+ */
729
+ type ClearContextInit = {
730
+ /**
731
+ * 中断を知らせるシグナルです。
732
+ */
733
+ readonly signal: AbortSignal;
734
+
735
+ /**
736
+ * 共有する変数ストアです。
737
+ *
738
+ * 指定したときは `vars` を複写せず、ストアの参照を共有します。
739
+ * 下流の `set` は上流の `get` に見えます。
740
+ * オニオン実行のネストで使用します。
741
+ * 省略時は独立したストアを作成します。
742
+ */
743
+ readonly store?: VariablesStore | undefined;
744
+
745
+ /**
746
+ * 実行時変数の初期値です。
747
+ */
748
+ readonly vars?: VariablesInit | undefined;
749
+ };
750
+
751
+ /**
752
+ * 全削除のコンテキストです。
753
+ */
754
+ export class ClearContext extends ActionContext<"clear"> implements IClearContext {
755
+ /**
756
+ * コンテキストを作成します。
757
+ *
758
+ * @param init 初期値です。
759
+ */
760
+ public constructor(init: ClearContextInit) {
761
+ super({
762
+ ...init,
763
+ action: "clear",
764
+ });
765
+ }
766
+ }
767
+
768
+ /**
769
+ * `TransformContext` の初期値です。
770
+ */
771
+ type TransformContextInit<TAction extends ITransformContext["action"], TSource = any> = {
772
+ /**
773
+ * 実行する操作の種別です。
774
+ */
775
+ readonly action: TAction;
776
+
777
+ /**
778
+ * 対象のキーです。
779
+ */
780
+ readonly key: string;
781
+
782
+ /**
783
+ * 中断を知らせるシグナルです。
784
+ */
785
+ readonly signal: AbortSignal;
786
+
787
+ /**
788
+ * 変換前の値です。
789
+ */
790
+ readonly source: TSource;
791
+
792
+ /**
793
+ * 共有する変数ストアです。
794
+ *
795
+ * 指定したときは `vars` を複写せず、ストアの参照を共有します。
796
+ * 下流の `set` は上流の `get` に見えます。
797
+ * オニオン実行のネストで使用します。
798
+ * 省略時は独立したストアを作成します。
799
+ */
800
+ readonly store?: VariablesStore | undefined;
801
+
802
+ /**
803
+ * 実行時変数の初期値です。
804
+ */
805
+ readonly vars?: VariablesInit | undefined;
806
+ };
807
+
808
+ /**
809
+ * 値変換の基底コンテキストです。
810
+ */
811
+ class TransformContext<
812
+ const TAction extends ITransformContext["action"],
813
+ TSource = any,
814
+ TDestination = TSource,
815
+ >
816
+ extends KeyedActionContext<TAction>
817
+ implements ITransformContext<TSource, TDestination>
818
+ {
819
+ /**
820
+ * 変換前の値です。
821
+ */
822
+ public readonly source: TSource;
823
+
824
+ /**
825
+ * 変換後の値です。
826
+ *
827
+ * ミドルウェアが設定します。
828
+ * 存在しない場合は未設定を表します。
829
+ * `next` の実行後は凍結され、読み取りはできますが設定すると `MiddlewareDestinationFrozenError` を投げます。
830
+ */
831
+ public destination?: TDestination;
832
+
833
+ /**
834
+ * コンテキストを作成します。
835
+ *
836
+ * @param init 初期値です。
837
+ */
838
+ public constructor(init: TransformContextInit<TAction, TSource>) {
839
+ const { source, ...superInit } = init;
840
+ super(superInit);
841
+ this.source = source;
842
+ }
843
+ }
844
+
845
+ /**
846
+ * データ変換の基底コンテキストです。
847
+ */
848
+ class TransformDataContext<
849
+ const TAction extends ITransformDataContext["action"],
850
+ TSourceData = any,
851
+ TDestinationData = TSourceData,
852
+ >
853
+ extends TransformContext<TAction, TSourceData, TDestinationData>
854
+ implements ITransformDataContext<TSourceData, TDestinationData> {}
855
+
856
+ /**
857
+ * `EncodeContext` の初期値です。
858
+ */
859
+ type EncodeContextInit<TRawData = any> = {
860
+ /**
861
+ * 対象のキーです。
862
+ */
863
+ readonly key: string;
864
+
865
+ /**
866
+ * 中断を知らせるシグナルです。
867
+ */
868
+ readonly signal: AbortSignal;
869
+
870
+ /**
871
+ * 変換前の値です。
872
+ */
873
+ readonly source: TRawData;
874
+
875
+ /**
876
+ * 共有する変数ストアです。
877
+ *
878
+ * 指定したときは `vars` を複写せず、ストアの参照を共有します。
879
+ * 下流の `set` は上流の `get` に見えます。
880
+ * オニオン実行のネストで使用します。
881
+ * 省略時は独立したストアを作成します。
882
+ */
883
+ readonly store?: VariablesStore | undefined;
884
+
885
+ /**
886
+ * 実行時変数の初期値です。
887
+ */
888
+ readonly vars?: VariablesInit | undefined;
889
+ };
890
+
891
+ /**
892
+ * 符号化のコンテキストです。
893
+ */
894
+ export class EncodeContext<TRawData = any, TEncodedData = TRawData>
895
+ extends TransformDataContext<"set", TRawData, TEncodedData>
896
+ implements IEncodeContext<TRawData, TEncodedData>
897
+ {
898
+ /**
899
+ * コンテキストを作成します。
900
+ *
901
+ * @param init 初期値です。
902
+ */
903
+ public constructor(init: EncodeContextInit<TRawData>) {
904
+ super({
905
+ ...init,
906
+ action: "set",
907
+ });
908
+ }
909
+ }
910
+
911
+ /**
912
+ * `DecodeContext` の初期値です。
913
+ */
914
+ type DecodeContextInit<TRawData = any> = {
915
+ /**
916
+ * 対象のキーです。
917
+ */
918
+ readonly key: string;
919
+
920
+ /**
921
+ * 中断を知らせるシグナルです。
922
+ */
923
+ readonly signal: AbortSignal;
924
+
925
+ /**
926
+ * 変換前の値です。
927
+ */
928
+ readonly source: TRawData;
929
+
930
+ /**
931
+ * 共有する変数ストアです。
932
+ *
933
+ * 指定したときは `vars` を複写せず、ストアの参照を共有します。
934
+ * 下流の `set` は上流の `get` に見えます。
935
+ * オニオン実行のネストで使用します。
936
+ * 省略時は独立したストアを作成します。
937
+ */
938
+ readonly store?: VariablesStore | undefined;
939
+
940
+ /**
941
+ * 実行時変数の初期値です。
942
+ */
943
+ readonly vars?: VariablesInit | undefined;
944
+ };
945
+
946
+ /**
947
+ * 復号のコンテキストです。
948
+ */
949
+ export class DecodeContext<TRawData = any, TDecodedData = TRawData>
950
+ extends TransformDataContext<"get", TRawData, TDecodedData>
951
+ implements IDecodeContext<TRawData, TDecodedData>
952
+ {
953
+ /**
954
+ * コンテキストを作成します。
955
+ *
956
+ * @param init 初期値です。
957
+ */
958
+ public constructor(init: DecodeContextInit<TRawData>) {
959
+ super({
960
+ ...init,
961
+ action: "get",
962
+ });
963
+ }
964
+ }
965
+
966
+ /**
967
+ * ストリーム変換の基底コンテキストです。
968
+ */
969
+ class TransformStreamContext<
970
+ TAction extends ITransformStreamContext["action"],
971
+ TSourceChunk = any,
972
+ TDestinationChunk = TSourceChunk,
973
+ >
974
+ extends TransformContext<
975
+ TAction,
976
+ IReadableStream<TSourceChunk>,
977
+ IReadableStream<TDestinationChunk>
978
+ >
979
+ implements ITransformStreamContext<TSourceChunk, TDestinationChunk> {}
980
+
981
+ /**
982
+ * `EncodeStreamContext` の初期値です。
983
+ */
984
+ type EncodeStreamContextInit<TRawChunk = any> = {
985
+ /**
986
+ * 対象のキーです。
987
+ */
988
+ readonly key: string;
989
+
990
+ /**
991
+ * 中断を知らせるシグナルです。
992
+ */
993
+ readonly signal: AbortSignal;
994
+
995
+ /**
996
+ * 変換前のストリームです。
997
+ */
998
+ readonly source: IReadableStream<TRawChunk>;
999
+
1000
+ /**
1001
+ * 共有する変数ストアです。
1002
+ *
1003
+ * 指定したときは `vars` を複写せず、ストアの参照を共有します。
1004
+ * 下流の `set` は上流の `get` に見えます。
1005
+ * オニオン実行のネストで使用します。
1006
+ * 省略時は独立したストアを作成します。
1007
+ */
1008
+ readonly store?: VariablesStore | undefined;
1009
+
1010
+ /**
1011
+ * 実行時変数の初期値です。
1012
+ */
1013
+ readonly vars?: VariablesInit | undefined;
1014
+ };
1015
+
1016
+ /**
1017
+ * ストリーム符号化のコンテキストです。
1018
+ */
1019
+ export class EncodeStreamContext<TRawChunk = any, TEncodedChunk = TRawChunk>
1020
+ extends TransformStreamContext<"set", TRawChunk, TEncodedChunk>
1021
+ implements IEncodeStreamContext<TRawChunk, TEncodedChunk>
1022
+ {
1023
+ /**
1024
+ * コンテキストを作成します。
1025
+ *
1026
+ * @param init 初期値です。
1027
+ */
1028
+ public constructor(init: EncodeStreamContextInit<TRawChunk>) {
1029
+ super({
1030
+ ...init,
1031
+ action: "set",
1032
+ });
1033
+ }
1034
+ }
1035
+
1036
+ /**
1037
+ * `DecodeStreamContext` の初期値です。
1038
+ */
1039
+ type DecodeStreamContextInit<TRawChunk = any> = {
1040
+ /**
1041
+ * 対象のキーです。
1042
+ */
1043
+ readonly key: string;
1044
+
1045
+ /**
1046
+ * 中断を知らせるシグナルです。
1047
+ */
1048
+ readonly signal: AbortSignal;
1049
+
1050
+ /**
1051
+ * 変換前のストリームです。
1052
+ */
1053
+ readonly source: IReadableStream<TRawChunk>;
1054
+
1055
+ /**
1056
+ * 共有する変数ストアです。
1057
+ *
1058
+ * 指定したときは `vars` を複写せず、ストアの参照を共有します。
1059
+ * 下流の `set` は上流の `get` に見えます。
1060
+ * オニオン実行のネストで使用します。
1061
+ * 省略時は独立したストアを作成します。
1062
+ */
1063
+ readonly store?: VariablesStore | undefined;
1064
+
1065
+ /**
1066
+ * 実行時変数の初期値です。
1067
+ */
1068
+ readonly vars?: VariablesInit | undefined;
1069
+ };
1070
+
1071
+ /**
1072
+ * ストリーム復号のコンテキストです。
1073
+ */
1074
+ export class DecodeStreamContext<TRawChunk = any, TDecodedChunk = TRawChunk>
1075
+ extends TransformStreamContext<"stream", TRawChunk, TDecodedChunk>
1076
+ implements IDecodeStreamContext<TRawChunk, TDecodedChunk>
1077
+ {
1078
+ /**
1079
+ * コンテキストを作成します。
1080
+ *
1081
+ * @param init 初期値です。
1082
+ */
1083
+ public constructor(init: DecodeStreamContextInit<TRawChunk>) {
1084
+ super({
1085
+ ...init,
1086
+ action: "stream",
1087
+ });
1088
+ }
1089
+ }