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/dist/index.js CHANGED
@@ -24,7 +24,9 @@ var _MiddlewareNextCalledMultipleTimesError;
24
24
  var _StreamEncodingNotSupportedError;
25
25
  var _StreamDecodingNotSupportedError;
26
26
  var _PluginOperationAggregateError;
27
+ var _InvalidForkError;
27
28
  var _MissingStorageError;
29
+ var _UnterminatedPipelineError;
28
30
  /**
29
31
  * [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
30
32
  */
@@ -276,6 +278,17 @@ setErrorMessage(PluginOperationAggregateError, ({ action, errors, plugin }) => `
276
278
  /**
277
279
  * [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
278
280
  */
281
+ var InvalidForkError = class extends ErrorBase {
282
+ constructor(options) {
283
+ super("A forked branch does not reach any storage", options);
284
+ }
285
+ };
286
+ _InvalidForkError = InvalidForkError;
287
+ _InvalidForkError.prototype.name = "UniKvsInvalidForkError";
288
+ setErrorMessage(InvalidForkError, "ストレージに到達しない分岐があります", "ja");
289
+ /**
290
+ * [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
291
+ */
279
292
  var MissingStorageError = class extends ErrorBase {
280
293
  constructor(options) {
281
294
  super("At least one storage is required to use UniKvs", options);
@@ -284,6 +297,17 @@ var MissingStorageError = class extends ErrorBase {
284
297
  _MissingStorageError = MissingStorageError;
285
298
  _MissingStorageError.prototype.name = "UniKvsMissingStorageError";
286
299
  setErrorMessage(MissingStorageError, "UniKvs を使用するためには最低 1 つのストレージが必要です", "ja");
300
+ /**
301
+ * [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#errors)
302
+ */
303
+ var UnterminatedPipelineError = class extends ErrorBase {
304
+ constructor(options) {
305
+ super("The pipeline does not end with a storage", options);
306
+ }
307
+ };
308
+ _UnterminatedPipelineError = UnterminatedPipelineError;
309
+ _UnterminatedPipelineError.prototype.name = "UniKvsUnterminatedPipelineError";
310
+ setErrorMessage(UnterminatedPipelineError, "パイプラインがストレージで終わっていません。use() の後に persist() または fork() を呼び出してください", "ja");
287
311
  //#endregion
288
312
  //#region \0@oxc-project+runtime@0.154.0/helpers/esm/checkPrivateRedeclaration.js
289
313
  function _checkPrivateRedeclaration(e, t) {
@@ -572,7 +596,8 @@ var _lifecycle$1 = /* @__PURE__ */ new WeakMap();
572
596
  */
573
597
  var UniKvsMiddleware = class UniKvsMiddleware {
574
598
  constructor(middleware) {
575
- _classPrivateFieldInitSpec(this, _mw, void _initProto$1(this));
599
+ this.name = void _initProto$1(this);
600
+ _classPrivateFieldInitSpec(this, _mw, void 0);
576
601
  _classPrivateFieldInitSpec(this, _lifecycle$1, void 0);
577
602
  _classPrivateFieldSet2(_mw, this, middleware);
578
603
  _classPrivateFieldSet2(_lifecycle$1, this, new PluginLifecycle(middleware));
@@ -924,7 +949,8 @@ var _lifecycle = /* @__PURE__ */ new WeakMap();
924
949
  */
925
950
  var UniKvsStorage = class UniKvsStorage {
926
951
  constructor(storage) {
927
- _classPrivateFieldInitSpec(this, _io, void _initProto(this));
952
+ this.name = void _initProto(this);
953
+ _classPrivateFieldInitSpec(this, _io, void 0);
928
954
  _classPrivateFieldInitSpec(this, _lifecycle, void 0);
929
955
  _classPrivateFieldSet2(_io, this, storage);
930
956
  _classPrivateFieldSet2(_lifecycle, this, new PluginLifecycle(storage));
@@ -1084,34 +1110,23 @@ _UniKvsStorage = UniKvsStorage;
1084
1110
  */
1085
1111
  const branchStates = /* #__PURE__ */ new WeakMap();
1086
1112
  /**
1087
- * 分岐先のスナップショットを返します。
1113
+ * 分岐先を親の接頭辞付きで追加します。
1088
1114
  *
1089
- * 親の `fork` で接頭辞付加するために使用します。
1090
1115
  * `new Branch()` で作成された分岐以外の値が渡されたときは例外を投げます。
1091
1116
  * 外部からは使用しません。
1092
1117
  *
1093
- * @param branch スナップショットを取得する分岐です。
1094
- *
1095
- * @returns 分岐先のコピーを返します。
1096
- */
1097
- function getBranchDestinationsForFork(branch) {
1098
- const state = branchStates.get(branch);
1099
- if (!state) throw new TypeError("fork() expects a branch created by new Branch().");
1100
- return state.destinations.map((dest) => ({
1101
- storage: dest.storage,
1102
- middlewares: [...dest.middlewares]
1103
- }));
1104
- }
1105
- /**
1106
- * 分岐先を親の接頭辞付きで追加します。
1107
- *
1108
1118
  * @param destinations 追加先の分岐先列です。
1109
1119
  * @param prefix 親のミドルウェア列です。
1110
1120
  * @param branch 追加する分岐です。
1121
+ *
1122
+ * @throws 分岐がストレージに到達しない場合に `InvalidForkError` を投げます。
1111
1123
  */
1112
1124
  function appendForkDestinations(destinations, prefix, branch) {
1125
+ const state = branchStates.get(branch);
1126
+ if (!state) throw new TypeError("fork() expects a branch created by new Branch().");
1127
+ if (state.destinations.length === 0) throw new InvalidForkError();
1113
1128
  const prefixSnapshot = [...prefix];
1114
- for (const dest of getBranchDestinationsForFork(branch)) destinations.push({
1129
+ for (const dest of state.destinations) destinations.push({
1115
1130
  storage: dest.storage,
1116
1131
  middlewares: [...prefixSnapshot, ...dest.middlewares]
1117
1132
  });
@@ -3014,8 +3029,8 @@ var UniKvs = class {
3014
3029
  let ownsStream = stream !== null;
3015
3030
  try {
3016
3031
  try {
3017
- var _usingCtx6 = _usingCtx();
3018
- _usingCtx6.u(await asyncmux.readonly(this, signal));
3032
+ var _usingCtx3 = _usingCtx();
3033
+ _usingCtx3.u(await asyncmux.readonly(this, signal));
3019
3034
  if (_classPrivateFieldGet2(_con, this) === null) throw new UniKvsIsNotOpenError();
3020
3035
  const useContext = new SetContext({
3021
3036
  key,
@@ -3029,9 +3044,9 @@ var UniKvs = class {
3029
3044
  await _assertClassBrand(_UniKvs_brand, this, _setStream).call(this, io, signal, key, store, stream);
3030
3045
  } else await _assertClassBrand(_UniKvs_brand, this, _setPlain).call(this, io, signal, key, store, value);
3031
3046
  } catch (_) {
3032
- _usingCtx6.e = _;
3047
+ _usingCtx3.e = _;
3033
3048
  } finally {
3034
- _usingCtx6.d();
3049
+ _usingCtx3.d();
3035
3050
  }
3036
3051
  } catch (ex) {
3037
3052
  if (ownsStream && stream !== null) try {
@@ -3042,7 +3057,7 @@ var UniKvs = class {
3042
3057
  }
3043
3058
  async get(...args) {
3044
3059
  try {
3045
- var _usingCtx7 = _usingCtx();
3060
+ var _usingCtx4 = _usingCtx();
3046
3061
  if (_classPrivateFieldGet2(_con, this) === null) throw new UniKvsIsNotOpenError();
3047
3062
  const [options] = parseInput(GetArgsSchema, args);
3048
3063
  const { key, vars: varsOption, repair = false, signal: signalOption, throwOnRepairDenied = false } = options;
@@ -3050,7 +3065,7 @@ var UniKvs = class {
3050
3065
  const { ac, io } = _classPrivateFieldGet2(_con, this);
3051
3066
  const signal = combineSignals([ac.signal, signalOption]);
3052
3067
  const store = _assertClassBrand(_UniKvs_brand, this, _createOperationStore).call(this, varsOption);
3053
- _usingCtx7.u(await asyncmux.readonly(this, signal));
3068
+ _usingCtx4.u(await asyncmux.readonly(this, signal));
3054
3069
  if (_classPrivateFieldGet2(_con, this) === null) throw new UniKvsIsNotOpenError();
3055
3070
  const leafNames = _classPrivateFieldGet2(_pipeline, this).leaves.map((leaf) => leaf.name);
3056
3071
  const useContext = new GetContext({
@@ -3072,8 +3087,8 @@ var UniKvs = class {
3072
3087
  const missing = [];
3073
3088
  const errors = [];
3074
3089
  try {
3075
- var _usingCtx8 = _usingCtx();
3076
- _usingCtx8.u(await (repair ? io.lock({
3090
+ var _usingCtx5 = _usingCtx();
3091
+ _usingCtx5.u(await (repair ? io.lock({
3077
3092
  key,
3078
3093
  signal
3079
3094
  }) : io.rLock({
@@ -3126,9 +3141,9 @@ var UniKvs = class {
3126
3141
  if (hit === null) throw _assertClassBrand(_UniKvs_brand, this, _notFound).call(this, key, errors);
3127
3142
  if (repair) data = await _assertClassBrand(_UniKvs_brand, this, _repairPlain).call(this, data, hit, missing, store, key, signal, throwOnRepairDenied);
3128
3143
  } catch (_) {
3129
- _usingCtx8.e = _;
3144
+ _usingCtx5.e = _;
3130
3145
  } finally {
3131
- _usingCtx8.d();
3146
+ _usingCtx5.d();
3132
3147
  }
3133
3148
  if (!repair) data = await _classPrivateFieldGet2(_pipeline, this).decode(hit.leaf, {
3134
3149
  key,
@@ -3138,9 +3153,9 @@ var UniKvs = class {
3138
3153
  if (valueSchema) data = parseOutput(valueSchema.schema, data);
3139
3154
  return data;
3140
3155
  } catch (_) {
3141
- _usingCtx7.e = _;
3156
+ _usingCtx4.e = _;
3142
3157
  } finally {
3143
- _usingCtx7.d();
3158
+ _usingCtx4.d();
3144
3159
  }
3145
3160
  }
3146
3161
  async stream(...args) {
@@ -3152,8 +3167,8 @@ var UniKvs = class {
3152
3167
  const signal = combineSignals([ac.signal, signalOption]);
3153
3168
  const store = _assertClassBrand(_UniKvs_brand, this, _createOperationStore).call(this, varsOption);
3154
3169
  try {
3155
- var _usingCtx9 = _usingCtx();
3156
- _usingCtx9.u(await asyncmux.readonly(this, signal));
3170
+ var _usingCtx6 = _usingCtx();
3171
+ _usingCtx6.u(await asyncmux.readonly(this, signal));
3157
3172
  if (_classPrivateFieldGet2(_con, this) === null) throw new UniKvsIsNotOpenError();
3158
3173
  const leafNames = _classPrivateFieldGet2(_pipeline, this).leaves.map((leaf) => leaf.name);
3159
3174
  const useContext = new StreamContext({
@@ -3356,14 +3371,14 @@ var UniKvs = class {
3356
3371
  throw ex;
3357
3372
  }
3358
3373
  } catch (_) {
3359
- _usingCtx9.e = _;
3374
+ _usingCtx6.e = _;
3360
3375
  } finally {
3361
- _usingCtx9.d();
3376
+ _usingCtx6.d();
3362
3377
  }
3363
3378
  }
3364
3379
  async has(...args) {
3365
3380
  try {
3366
- var _usingCtx10 = _usingCtx();
3381
+ var _usingCtx7 = _usingCtx();
3367
3382
  if (_classPrivateFieldGet2(_con, this) === null) throw new UniKvsIsNotOpenError();
3368
3383
  const [options] = parseInput(HasArgsSchema, args);
3369
3384
  const { key, vars: varsOption, signal: signalOption } = options;
@@ -3371,7 +3386,7 @@ var UniKvs = class {
3371
3386
  const { ac, io } = _classPrivateFieldGet2(_con, this);
3372
3387
  const signal = combineSignals([ac.signal, signalOption]);
3373
3388
  const store = _assertClassBrand(_UniKvs_brand, this, _createOperationStore).call(this, varsOption);
3374
- _usingCtx10.u(await asyncmux.readonly(this, signal));
3389
+ _usingCtx7.u(await asyncmux.readonly(this, signal));
3375
3390
  if (_classPrivateFieldGet2(_con, this) === null) throw new UniKvsIsNotOpenError();
3376
3391
  const useContext = new HasContext({
3377
3392
  key,
@@ -3380,7 +3395,7 @@ var UniKvs = class {
3380
3395
  });
3381
3396
  await _assertClassBrand(_UniKvs_brand, this, _use).call(this, "read", useContext);
3382
3397
  throwIfAborted(signal);
3383
- _usingCtx10.u(await io.rLock({
3398
+ _usingCtx7.u(await io.rLock({
3384
3399
  key,
3385
3400
  signal
3386
3401
  }));
@@ -3412,14 +3427,14 @@ var UniKvs = class {
3412
3427
  if (errors.length > 0) throw _assertClassBrand(_UniKvs_brand, this, _notFound).call(this, key, errors);
3413
3428
  return false;
3414
3429
  } catch (_) {
3415
- _usingCtx10.e = _;
3430
+ _usingCtx7.e = _;
3416
3431
  } finally {
3417
- _usingCtx10.d();
3432
+ _usingCtx7.d();
3418
3433
  }
3419
3434
  }
3420
3435
  async delete(...args) {
3421
3436
  try {
3422
- var _usingCtx11 = _usingCtx();
3437
+ var _usingCtx8 = _usingCtx();
3423
3438
  if (_classPrivateFieldGet2(_con, this) === null) throw new UniKvsIsNotOpenError();
3424
3439
  const [options] = parseInput(DeleteArgsSchema, args);
3425
3440
  const { key, vars: varsOption, signal: signalOption } = options;
@@ -3427,7 +3442,7 @@ var UniKvs = class {
3427
3442
  const { ac, io } = _classPrivateFieldGet2(_con, this);
3428
3443
  const signal = combineSignals([ac.signal, signalOption]);
3429
3444
  const store = _assertClassBrand(_UniKvs_brand, this, _createOperationStore).call(this, varsOption);
3430
- _usingCtx11.u(await asyncmux.readonly(this, signal));
3445
+ _usingCtx8.u(await asyncmux.readonly(this, signal));
3431
3446
  if (_classPrivateFieldGet2(_con, this) === null) throw new UniKvsIsNotOpenError();
3432
3447
  const useContext = new DeleteContext({
3433
3448
  key,
@@ -3435,7 +3450,7 @@ var UniKvs = class {
3435
3450
  signal
3436
3451
  });
3437
3452
  await _assertClassBrand(_UniKvs_brand, this, _use).call(this, "delete", useContext);
3438
- _usingCtx11.u(await io.lock({
3453
+ _usingCtx8.u(await io.lock({
3439
3454
  key,
3440
3455
  signal
3441
3456
  }));
@@ -3473,23 +3488,23 @@ var UniKvs = class {
3473
3488
  plugin: "storage"
3474
3489
  });
3475
3490
  } catch (_) {
3476
- _usingCtx11.e = _;
3491
+ _usingCtx8.e = _;
3477
3492
  } finally {
3478
- _usingCtx11.d();
3493
+ _usingCtx8.d();
3479
3494
  }
3480
3495
  }
3481
3496
  async clear(...args) {
3482
3497
  try {
3483
- var _usingCtx12 = _usingCtx();
3498
+ var _usingCtx9 = _usingCtx();
3484
3499
  if (_classPrivateFieldGet2(_con, this) === null) throw new UniKvsIsNotOpenError();
3485
3500
  const [options = {}] = parseInput(ClearArgsSchema, args);
3486
3501
  const { vars: varsOption, signal: signalOption } = options;
3487
3502
  const { ac, io } = _classPrivateFieldGet2(_con, this);
3488
3503
  const signal = combineSignals([ac.signal, signalOption]);
3489
3504
  const store = _assertClassBrand(_UniKvs_brand, this, _createOperationStore).call(this, varsOption);
3490
- _usingCtx12.u(await asyncmux.readonly(this, signal));
3505
+ _usingCtx9.u(await asyncmux.readonly(this, signal));
3491
3506
  if (_classPrivateFieldGet2(_con, this) === null) throw new UniKvsIsNotOpenError();
3492
- _usingCtx12.u(await io.lock({ signal }));
3507
+ _usingCtx9.u(await io.lock({ signal }));
3493
3508
  const useContext = new ClearContext({
3494
3509
  store,
3495
3510
  signal
@@ -3518,9 +3533,9 @@ var UniKvs = class {
3518
3533
  plugin: "storage"
3519
3534
  });
3520
3535
  } catch (_) {
3521
- _usingCtx12.e = _;
3536
+ _usingCtx9.e = _;
3522
3537
  } finally {
3523
- _usingCtx12.d();
3538
+ _usingCtx9.d();
3524
3539
  }
3525
3540
  }
3526
3541
  };
@@ -3533,7 +3548,7 @@ var UniKvs = class {
3533
3548
  */
3534
3549
  function _createOperationVars(vars) {
3535
3550
  const map = new Map(_classPrivateFieldGet2(_baseVars, this));
3536
- if (vars) for (const [k, v] of vars) map.set(k, v);
3551
+ if (vars) for (const [k, value] of vars) map.set(k, value);
3537
3552
  return map;
3538
3553
  }
3539
3554
  /**
@@ -3585,11 +3600,11 @@ function _notFound(key, errors) {
3585
3600
  }
3586
3601
  async function _close(operationVars, signal, con, progress) {
3587
3602
  try {
3588
- var _usingCtx3 = _usingCtx();
3589
- _usingCtx3.u(await asyncmux(this, signal));
3603
+ var _usingCtx10 = _usingCtx();
3604
+ _usingCtx10.u(await asyncmux(this, signal));
3590
3605
  if (_classPrivateFieldGet2(_con, this) !== con) throw new UniKvsIsNotOpenError();
3591
3606
  const { io } = _classPrivateFieldGet2(_con, this);
3592
- _usingCtx3.u(await io.lock({ signal }));
3607
+ _usingCtx10.u(await io.lock({ signal }));
3593
3608
  const closeFns = [];
3594
3609
  for (const [index, leaf] of _classPrivateFieldGet2(_pipeline, this).leaves.entries()) {
3595
3610
  const createContext = () => new CloseContext({
@@ -3656,9 +3671,9 @@ async function _close(operationVars, signal, con, progress) {
3656
3671
  }
3657
3672
  _classPrivateFieldSet2(_con, this, null);
3658
3673
  } catch (_) {
3659
- _usingCtx3.e = _;
3674
+ _usingCtx10.e = _;
3660
3675
  } finally {
3661
- _usingCtx3.d();
3676
+ _usingCtx10.d();
3662
3677
  }
3663
3678
  }
3664
3679
  /**
@@ -3778,13 +3793,13 @@ async function _use(action, c) {
3778
3793
  */
3779
3794
  async function _setPlain(io, signal, key, store, value) {
3780
3795
  try {
3781
- var _usingCtx4 = _usingCtx();
3796
+ var _usingCtx11 = _usingCtx();
3782
3797
  const targets = await _classPrivateFieldGet2(_pipeline, this).encode({
3783
3798
  key,
3784
3799
  store,
3785
3800
  signal
3786
3801
  }, value);
3787
- _usingCtx4.u(await io.lock({
3802
+ _usingCtx11.u(await io.lock({
3788
3803
  key,
3789
3804
  signal
3790
3805
  }));
@@ -3809,9 +3824,9 @@ async function _setPlain(io, signal, key, store, value) {
3809
3824
  }));
3810
3825
  await _assertClassBrand(_UniKvs_brand, this, _finishWrites).call(this, targets, store, failed, errors, signal);
3811
3826
  } catch (_) {
3812
- _usingCtx4.e = _;
3827
+ _usingCtx11.e = _;
3813
3828
  } finally {
3814
- _usingCtx4.d();
3829
+ _usingCtx11.d();
3815
3830
  }
3816
3831
  }
3817
3832
  /**
@@ -3825,7 +3840,7 @@ async function _setPlain(io, signal, key, store, value) {
3825
3840
  */
3826
3841
  async function _setStream(io, signal, key, store, value) {
3827
3842
  try {
3828
- var _usingCtx5 = _usingCtx();
3843
+ var _usingCtx12 = _usingCtx();
3829
3844
  const streams = /* @__PURE__ */ new Set([value]);
3830
3845
  let tree;
3831
3846
  try {
@@ -3838,7 +3853,7 @@ async function _setStream(io, signal, key, store, value) {
3838
3853
  await cancelStreams(streams, ex);
3839
3854
  throw ex;
3840
3855
  }
3841
- _usingCtx5.u(await io.lock({
3856
+ _usingCtx12.u(await io.lock({
3842
3857
  key,
3843
3858
  signal
3844
3859
  }).catch(async (ex) => {
@@ -3870,9 +3885,9 @@ async function _setStream(io, signal, key, store, value) {
3870
3885
  }));
3871
3886
  await _assertClassBrand(_UniKvs_brand, this, _finishWrites).call(this, tree.targets, store, failed, errors, signal);
3872
3887
  } catch (_) {
3873
- _usingCtx5.e = _;
3888
+ _usingCtx12.e = _;
3874
3889
  } finally {
3875
- _usingCtx5.d();
3890
+ _usingCtx12.d();
3876
3891
  }
3877
3892
  }
3878
3893
  /**
@@ -3936,6 +3951,7 @@ const UniKvsBuilderOptionsSchema = object({
3936
3951
  const UniKvsBuilderArgsSchema = tuple([optional(UniKvsBuilderOptionsSchema)]);
3937
3952
  var _destinations = /* @__PURE__ */ new WeakMap();
3938
3953
  var _middlewares = /* @__PURE__ */ new WeakMap();
3954
+ var _hasUnboundMiddlewares = /* @__PURE__ */ new WeakMap();
3939
3955
  var _valueSchemaResolver = /* @__PURE__ */ new WeakMap();
3940
3956
  var _vars = /* @__PURE__ */ new WeakMap();
3941
3957
  /**
@@ -3945,22 +3961,26 @@ var UniKvsBuilder = class {
3945
3961
  constructor(...args) {
3946
3962
  _classPrivateFieldInitSpec(this, _destinations, void 0);
3947
3963
  _classPrivateFieldInitSpec(this, _middlewares, void 0);
3964
+ _classPrivateFieldInitSpec(this, _hasUnboundMiddlewares, void 0);
3948
3965
  _classPrivateFieldInitSpec(this, _valueSchemaResolver, void 0);
3949
3966
  _classPrivateFieldInitSpec(this, _vars, void 0);
3950
3967
  const [options = {}] = parseInput(UniKvsBuilderArgsSchema, args);
3951
3968
  const { vars, schema } = options;
3952
3969
  _classPrivateFieldSet2(_destinations, this, []);
3953
3970
  _classPrivateFieldSet2(_middlewares, this, []);
3971
+ _classPrivateFieldSet2(_hasUnboundMiddlewares, this, false);
3954
3972
  _classPrivateFieldSet2(_valueSchemaResolver, this, null);
3955
3973
  _classPrivateFieldSet2(_vars, this, new Map(vars));
3956
3974
  if (schema) _classPrivateFieldSet2(_valueSchemaResolver, this, createValueSchemaResolver(schema));
3957
3975
  }
3958
3976
  fork(branch) {
3959
3977
  appendForkDestinations(_classPrivateFieldGet2(_destinations, this), _classPrivateFieldGet2(_middlewares, this), branch);
3978
+ _classPrivateFieldSet2(_hasUnboundMiddlewares, this, false);
3960
3979
  return this;
3961
3980
  }
3962
3981
  use(middleware) {
3963
3982
  _classPrivateFieldGet2(_middlewares, this).push(UniKvsMiddleware.from(middleware));
3983
+ _classPrivateFieldSet2(_hasUnboundMiddlewares, this, true);
3964
3984
  return this;
3965
3985
  }
3966
3986
  persist(storage) {
@@ -3968,6 +3988,7 @@ var UniKvsBuilder = class {
3968
3988
  storage: UniKvsStorage.from(storage),
3969
3989
  middlewares: [..._classPrivateFieldGet2(_middlewares, this)]
3970
3990
  });
3991
+ _classPrivateFieldSet2(_hasUnboundMiddlewares, this, false);
3971
3992
  return this;
3972
3993
  }
3973
3994
  setVars(...args) {
@@ -3991,9 +4012,23 @@ var UniKvsBuilder = class {
3991
4012
  this.setVars(target);
3992
4013
  return this;
3993
4014
  }
3994
- build() {
4015
+ isValid() {
4016
+ return _classPrivateFieldGet2(_destinations, this).length > 0 && !_classPrivateFieldGet2(_hasUnboundMiddlewares, this);
4017
+ }
4018
+ build(options = {}) {
3995
4019
  if (_classPrivateFieldGet2(_destinations, this).length === 0) throw new MissingStorageError();
3996
- return new UniKvs([..._classPrivateFieldGet2(_vars, this).entries()], PipelineGraph.compile([..._classPrivateFieldGet2(_destinations, this)]), _classPrivateFieldGet2(_valueSchemaResolver, this));
4020
+ if (_classPrivateFieldGet2(_hasUnboundMiddlewares, this)) throw new UnterminatedPipelineError();
4021
+ const beforeAll = options.beforeAll?.map((mw) => UniKvsMiddleware.from(mw)) ?? [];
4022
+ const beforeStorage = options.beforeStorage?.map((mw) => UniKvsMiddleware.from(mw)) ?? [];
4023
+ const destinations = beforeAll.length === 0 && beforeStorage.length === 0 ? _classPrivateFieldGet2(_destinations, this) : _classPrivateFieldGet2(_destinations, this).map((dest) => ({
4024
+ storage: dest.storage,
4025
+ middlewares: [
4026
+ ...beforeAll,
4027
+ ...dest.middlewares,
4028
+ ...beforeStorage
4029
+ ]
4030
+ }));
4031
+ return new UniKvs([..._classPrivateFieldGet2(_vars, this).entries()], PipelineGraph.compile(destinations), _classPrivateFieldGet2(_valueSchemaResolver, this));
3997
4032
  }
3998
4033
  };
3999
4034
  //#endregion
@@ -4027,6 +4062,6 @@ function Value(schema) {
4027
4062
  return createValueSchemaDescriptor("any", schema);
4028
4063
  }
4029
4064
  //#endregion
4030
- export { UniKvsBranch as Branch, UniKvsBranch, UniKvsBuilder as Builder, UniKvsBuilder, InvalidInputError, InvalidOutputError, InvalidUsageErrorBase, KeyNotFoundError, MiddlewareDestinationFrozenError, MiddlewareDestinationMissingError, MiddlewareIsNotOpenError, MiddlewareNextCalledMultipleTimesError, MiddlewareNextNotAwaitedError, MiddlewareNextNotCalledError, MissingStorageError, MultipartWriteNotSupportedError, PlainValue, PluginOperationAggregateError, ReadableStreamNotSupportedError, StorageIsNotOpenError, StreamDecodingNotSupportedError, StreamEncodingNotSupportedError, StreamValue, UniKvs, UniKvsIsNotOpenError, UniKvsIsOpenError, Value, WritableStreamNotSupportedError };
4065
+ export { UniKvsBranch as Branch, UniKvsBranch, UniKvsBuilder as Builder, UniKvsBuilder, InvalidForkError, InvalidInputError, InvalidOutputError, InvalidUsageErrorBase, KeyNotFoundError, MiddlewareDestinationFrozenError, MiddlewareDestinationMissingError, MiddlewareIsNotOpenError, MiddlewareNextCalledMultipleTimesError, MiddlewareNextNotAwaitedError, MiddlewareNextNotCalledError, MissingStorageError, MultipartWriteNotSupportedError, PlainValue, PluginOperationAggregateError, ReadableStreamNotSupportedError, StorageIsNotOpenError, StreamDecodingNotSupportedError, StreamEncodingNotSupportedError, StreamValue, UniKvs, UniKvsIsNotOpenError, UniKvsIsOpenError, UnterminatedPipelineError, Value, WritableStreamNotSupportedError };
4031
4066
 
4032
4067
  //# sourceMappingURL=index.js.map