unikvs 0.0.15 → 0.0.17
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.d.ts +79 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +935 -667
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
- package/src/_contexts.ts +113 -31
- package/src/_storage.ts +80 -0
- package/src/_unikvs.schemas.ts +124 -0
- package/src/errors.ts +2 -2
- package/src/unikvs.ts +245 -3
- package/src/unikvs.types.ts +50 -0
package/dist/index.js
CHANGED
|
@@ -728,821 +728,917 @@ _UniKvsMiddleware = UniKvsMiddleware;
|
|
|
728
728
|
]
|
|
729
729
|
]).e;
|
|
730
730
|
//#endregion
|
|
731
|
-
//#region ../src/
|
|
732
|
-
/**
|
|
733
|
-
* 値が `ReadableStream` のインターフェースを満たすかどうかを判定します。
|
|
734
|
-
*
|
|
735
|
-
* ランタイムによっては `ReadableStream` クラスを継承せずに同じインターフェースを備えたオブジェクトが存在するため、`instanceof` ではなく必要なメソッドの有無で判定します。
|
|
736
|
-
*
|
|
737
|
-
* @param input 判定する値です。
|
|
738
|
-
*
|
|
739
|
-
* @returns `ReadableStream` のインターフェースを満たす場合は `true` を返します。
|
|
740
|
-
*/
|
|
741
|
-
function isReadableStream(input) {
|
|
742
|
-
if (typeof input !== "object" || input === null) return false;
|
|
743
|
-
const stream = input;
|
|
744
|
-
return typeof stream.tee === "function" && typeof stream.cancel === "function" && typeof stream.pipeTo === "function" && typeof stream.getReader === "function" && typeof stream.pipeThrough === "function";
|
|
745
|
-
}
|
|
731
|
+
//#region ../src/_contexts.ts
|
|
746
732
|
/**
|
|
747
|
-
*
|
|
733
|
+
* 実行時変数の初期値をエントリー列に正規化します。
|
|
748
734
|
*
|
|
749
|
-
*
|
|
735
|
+
* レコードは `Object.entries` で展開します。
|
|
736
|
+
* 反復子はそのまま返します。
|
|
750
737
|
*
|
|
751
|
-
* @param
|
|
738
|
+
* @param vars 初期値です。
|
|
752
739
|
*
|
|
753
|
-
* @returns
|
|
740
|
+
* @returns エントリー列を返します。
|
|
754
741
|
*/
|
|
755
|
-
function
|
|
756
|
-
if (
|
|
757
|
-
|
|
758
|
-
return
|
|
742
|
+
function normalizeVariablesInit(vars) {
|
|
743
|
+
if (!vars) return [];
|
|
744
|
+
if (Symbol.iterator in vars) return vars;
|
|
745
|
+
return Object.entries(vars);
|
|
759
746
|
}
|
|
760
747
|
/**
|
|
761
|
-
*
|
|
748
|
+
* 新しい空の変数ストアを作成します。
|
|
762
749
|
*
|
|
763
|
-
*
|
|
750
|
+
* @param vars 初期値です。
|
|
764
751
|
*
|
|
765
|
-
* @
|
|
766
|
-
* @param reason キャンセル理由です。
|
|
767
|
-
*/
|
|
768
|
-
async function cancelStreams(streams, reason) {
|
|
769
|
-
await Promise.all([...new Set(streams)].map(async (stream) => {
|
|
770
|
-
try {
|
|
771
|
-
await stream.cancel(reason);
|
|
772
|
-
} catch {}
|
|
773
|
-
}));
|
|
774
|
-
}
|
|
775
|
-
//#endregion
|
|
776
|
-
//#region ../src/_valibot.ts
|
|
777
|
-
function parseInput(schema, value, Error = InvalidInputError) {
|
|
778
|
-
const result = safeParse(schema, value);
|
|
779
|
-
if (result.success) return result.output;
|
|
780
|
-
const error = new Error({
|
|
781
|
-
value,
|
|
782
|
-
issues: result.issues
|
|
783
|
-
});
|
|
784
|
-
tryCaptureStackTrace(error, parseInput);
|
|
785
|
-
throw error;
|
|
786
|
-
}
|
|
787
|
-
function parseOutput(schema, value, Error = InvalidOutputError) {
|
|
788
|
-
const result = safeParse(schema, value);
|
|
789
|
-
if (result.success) return result.output;
|
|
790
|
-
const error = new Error({
|
|
791
|
-
value,
|
|
792
|
-
issues: result.issues
|
|
793
|
-
});
|
|
794
|
-
tryCaptureStackTrace(error, parseOutput);
|
|
795
|
-
throw error;
|
|
796
|
-
}
|
|
797
|
-
//#endregion
|
|
798
|
-
//#region ../src/_streams.schemas.ts
|
|
799
|
-
/**
|
|
800
|
-
* `ReadableStream` のインターフェースを満たすかを検証するためのスキーマです。
|
|
801
|
-
*/
|
|
802
|
-
const ReadableStreamSchema = custom(isReadableStream, "Expected a ReadableStream");
|
|
803
|
-
/**
|
|
804
|
-
* `WritableStream` のインターフェースを満たすかを検証するためのスキーマです。
|
|
752
|
+
* @returns 空ストアを返します。
|
|
805
753
|
*/
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
let _initProto;
|
|
811
|
-
function _applyDecs(e, t, n, r, o, i) {
|
|
812
|
-
var a, c, u, s, f, l, p, d = Symbol.metadata || Symbol.for("Symbol.metadata"), m = Object.defineProperty, h = Object.create, y = [h(null), h(null)], v = t.length;
|
|
813
|
-
function g(t, n, r) {
|
|
814
|
-
return function(o, i) {
|
|
815
|
-
n && (i = o, o = e);
|
|
816
|
-
for (var a = 0; a < t.length; a++) i = t[a].apply(o, r ? [i] : []);
|
|
817
|
-
return r ? i : o;
|
|
818
|
-
};
|
|
819
|
-
}
|
|
820
|
-
function b(e, t, n, r) {
|
|
821
|
-
if ("function" != typeof e && (r || void 0 !== e)) throw new TypeError(t + " must " + (n || "be") + " a function" + (r ? "" : " or undefined"));
|
|
822
|
-
return e;
|
|
823
|
-
}
|
|
824
|
-
function applyDec(e, t, n, r, o, i, u, s, f, l, p) {
|
|
825
|
-
function d(e) {
|
|
826
|
-
if (!p(e)) throw new TypeError("Attempted to access private element on non-instance");
|
|
827
|
-
}
|
|
828
|
-
var h = [].concat(t[0]), v = t[3], w = !u, D = 1 === o, S = 3 === o, j = 4 === o, E = 2 === o;
|
|
829
|
-
function I(t, n, r) {
|
|
830
|
-
return function(o, i) {
|
|
831
|
-
return n && (i = o, o = e), r && r(o), P[t].call(o, i);
|
|
832
|
-
};
|
|
833
|
-
}
|
|
834
|
-
if (!w) {
|
|
835
|
-
var P = {}, k = [], F = S ? "get" : j || D ? "set" : "value";
|
|
836
|
-
if (f ? (l || D ? P = {
|
|
837
|
-
get: _setFunctionName(function() {
|
|
838
|
-
return v(this);
|
|
839
|
-
}, r, "get"),
|
|
840
|
-
set: function(e) {
|
|
841
|
-
t[4](this, e);
|
|
842
|
-
}
|
|
843
|
-
} : P[F] = v, l || _setFunctionName(P[F], r, E ? "" : F)) : l || (P = Object.getOwnPropertyDescriptor(e, r)), !l && !f) {
|
|
844
|
-
if ((c = y[+s][r]) && 7 !== (c ^ o)) throw Error("Decorating two elements with the same name (" + P[F].name + ") is not supported yet");
|
|
845
|
-
y[+s][r] = o < 3 ? 1 : o;
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
for (var N = e, O = h.length - 1; O >= 0; O -= n ? 2 : 1) {
|
|
849
|
-
var T = b(h[O], "A decorator", "be", !0), z = n ? h[O - 1] : void 0, A = {}, H = {
|
|
850
|
-
kind: [
|
|
851
|
-
"field",
|
|
852
|
-
"accessor",
|
|
853
|
-
"method",
|
|
854
|
-
"getter",
|
|
855
|
-
"setter",
|
|
856
|
-
"class"
|
|
857
|
-
][o],
|
|
858
|
-
name: r,
|
|
859
|
-
metadata: a,
|
|
860
|
-
addInitializer: function(e, t) {
|
|
861
|
-
if (e.v) throw new TypeError("attempted to call addInitializer after decoration was finished");
|
|
862
|
-
b(t, "An initializer", "be", !0), i.push(t);
|
|
863
|
-
}.bind(null, A)
|
|
864
|
-
};
|
|
865
|
-
if (w) c = T.call(z, N, H), A.v = 1, b(c, "class decorators", "return") && (N = c);
|
|
866
|
-
else if (H.static = s, H.private = f, c = H.access = { has: f ? p.bind() : function(e) {
|
|
867
|
-
return r in e;
|
|
868
|
-
} }, j || (c.get = f ? E ? function(e) {
|
|
869
|
-
return d(e), P.value;
|
|
870
|
-
} : I("get", 0, d) : function(e) {
|
|
871
|
-
return e[r];
|
|
872
|
-
}), E || S || (c.set = f ? I("set", 0, d) : function(e, t) {
|
|
873
|
-
e[r] = t;
|
|
874
|
-
}), N = T.call(z, D ? {
|
|
875
|
-
get: P.get,
|
|
876
|
-
set: P.set
|
|
877
|
-
} : P[F], H), A.v = 1, D) {
|
|
878
|
-
if ("object" == typeof N && N) (c = b(N.get, "accessor.get")) && (P.get = c), (c = b(N.set, "accessor.set")) && (P.set = c), (c = b(N.init, "accessor.init")) && k.unshift(c);
|
|
879
|
-
else if (void 0 !== N) throw new TypeError("accessor decorators must return an object with get, set, or init properties or undefined");
|
|
880
|
-
} else b(N, (l ? "field" : "method") + " decorators", "return") && (l ? k.unshift(N) : P[F] = N);
|
|
881
|
-
}
|
|
882
|
-
return o < 2 && u.push(g(k, s, 1), g(i, s, 0)), l || w || (f ? D ? u.splice(-1, 0, I("get", s), I("set", s)) : u.push(E ? P[F] : b.call.bind(P[F])) : m(e, r, P)), N;
|
|
883
|
-
}
|
|
884
|
-
function w(e) {
|
|
885
|
-
return m(e, d, {
|
|
886
|
-
configurable: !0,
|
|
887
|
-
enumerable: !0,
|
|
888
|
-
value: a
|
|
889
|
-
});
|
|
890
|
-
}
|
|
891
|
-
return void 0 !== i && (a = i[d]), a = h(null == a ? null : a), f = [], l = function(e) {
|
|
892
|
-
e && f.push(g(e));
|
|
893
|
-
}, p = function(t, r) {
|
|
894
|
-
for (var i = 0; i < n.length; i++) {
|
|
895
|
-
var a = n[i], c = a[1], l = 7 & c;
|
|
896
|
-
if ((8 & c) == t && !l == r) {
|
|
897
|
-
var p = a[2], d = !!a[3], m = 16 & c;
|
|
898
|
-
applyDec(t ? e : e.prototype, a, m, d ? "#" + p : _toPropertyKey(p), l, l < 2 ? [] : t ? s = s || [] : u = u || [], f, !!t, d, r, t && d ? function(t) {
|
|
899
|
-
return _checkInRHS(t) === e;
|
|
900
|
-
} : o);
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
}, p(8, 0), p(0, 0), p(8, 1), p(0, 1), l(u), l(s), c = f, v || w(e), {
|
|
904
|
-
e: c,
|
|
905
|
-
get c() {
|
|
906
|
-
var n = [];
|
|
907
|
-
return v && [w(e = applyDec(e, [t], r, e.name, 5, n)), g(n, 1)];
|
|
908
|
-
}
|
|
754
|
+
function createVariablesStore(vars = []) {
|
|
755
|
+
return {
|
|
756
|
+
data: new Map(vars),
|
|
757
|
+
readonly: /* @__PURE__ */ new Set()
|
|
909
758
|
};
|
|
910
759
|
}
|
|
911
|
-
|
|
912
|
-
var i = _toPrimitive(t, "string");
|
|
913
|
-
return "symbol" == typeof i ? i : i + "";
|
|
914
|
-
}
|
|
915
|
-
function _toPrimitive(t, e) {
|
|
916
|
-
if ("object" != typeof t || !t) return t;
|
|
917
|
-
var r;
|
|
918
|
-
if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
|
|
919
|
-
var i = r.call(t, e || "default");
|
|
920
|
-
if ("object" != typeof i) return i;
|
|
921
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
922
|
-
}
|
|
923
|
-
return ("string" === e ? String : Number)(t);
|
|
924
|
-
}
|
|
925
|
-
function _setFunctionName(e, t, n) {
|
|
926
|
-
"symbol" == typeof t && (t = (t = t.description) ? "[" + t + "]" : "");
|
|
927
|
-
try {
|
|
928
|
-
Object.defineProperty(e, "name", {
|
|
929
|
-
configurable: !0,
|
|
930
|
-
value: n ? n + " " + t : t
|
|
931
|
-
});
|
|
932
|
-
} catch (e) {}
|
|
933
|
-
return e;
|
|
934
|
-
}
|
|
935
|
-
function _checkInRHS(e) {
|
|
936
|
-
if (Object(e) !== e) throw TypeError("right-hand side of 'in' should be an object, got " + (null !== e ? typeof e : "null"));
|
|
937
|
-
return e;
|
|
938
|
-
}
|
|
939
|
-
/**
|
|
940
|
-
* 同じオブジェクトに対して同じ `UniKvsStorage` インスタンスを返すためのメモです。
|
|
941
|
-
*/
|
|
942
|
-
const instances = /* #__PURE__ */ new WeakMap();
|
|
943
|
-
var _io = /* @__PURE__ */ new WeakMap();
|
|
944
|
-
var _lifecycle = /* @__PURE__ */ new WeakMap();
|
|
760
|
+
var _store = /* @__PURE__ */ new WeakMap();
|
|
945
761
|
/**
|
|
946
|
-
*
|
|
947
|
-
*
|
|
948
|
-
* ストレージを安全に使うための検証などの処理が集約されています。
|
|
762
|
+
* 実行時変数を保持する基底コンテキストです。
|
|
949
763
|
*/
|
|
950
|
-
var
|
|
951
|
-
constructor(storage) {
|
|
952
|
-
this.name = void _initProto(this);
|
|
953
|
-
_classPrivateFieldInitSpec(this, _io, void 0);
|
|
954
|
-
_classPrivateFieldInitSpec(this, _lifecycle, void 0);
|
|
955
|
-
_classPrivateFieldSet2(_io, this, storage);
|
|
956
|
-
_classPrivateFieldSet2(_lifecycle, this, new PluginLifecycle(storage));
|
|
957
|
-
this.name = storage.name;
|
|
958
|
-
}
|
|
764
|
+
var PipelineContext = class {
|
|
959
765
|
/**
|
|
960
|
-
*
|
|
961
|
-
*
|
|
962
|
-
* @param storage 元となるストレージです。
|
|
766
|
+
* コンテキストを作成します。
|
|
963
767
|
*
|
|
964
|
-
* @
|
|
768
|
+
* @param init 初期値です。
|
|
965
769
|
*/
|
|
966
|
-
|
|
967
|
-
|
|
770
|
+
constructor(init) {
|
|
771
|
+
_classPrivateFieldInitSpec(this, _store, void 0);
|
|
772
|
+
const { store } = init;
|
|
773
|
+
_classPrivateFieldSet2(_store, this, store ?? createVariablesStore());
|
|
774
|
+
const vars = normalizeVariablesInit(init.vars);
|
|
775
|
+
for (const [name, value] of vars) _classPrivateFieldGet2(_store, this).data.set(name, value);
|
|
968
776
|
}
|
|
969
777
|
/**
|
|
970
|
-
*
|
|
778
|
+
* 共有する実行時変数のストアを取得します。
|
|
971
779
|
*
|
|
972
|
-
* @
|
|
780
|
+
* @returns 実行時変数のストアを返します。
|
|
973
781
|
*/
|
|
974
|
-
|
|
975
|
-
|
|
782
|
+
get store() {
|
|
783
|
+
return _classPrivateFieldGet2(_store, this);
|
|
976
784
|
}
|
|
977
785
|
/**
|
|
978
|
-
*
|
|
786
|
+
* 変数の値を読み取ります。
|
|
979
787
|
*
|
|
980
|
-
* @param
|
|
788
|
+
* @param name 変数名です。
|
|
789
|
+
*
|
|
790
|
+
* @returns 変数の値を返します。
|
|
981
791
|
*/
|
|
982
|
-
|
|
983
|
-
|
|
792
|
+
get(name) {
|
|
793
|
+
return _classPrivateFieldGet2(_store, this).data.get(name);
|
|
984
794
|
}
|
|
985
795
|
/**
|
|
986
|
-
*
|
|
796
|
+
* 変数の値を書き込みます。
|
|
987
797
|
*
|
|
988
|
-
* @param
|
|
989
|
-
|
|
990
|
-
async retryClose(c) {
|
|
991
|
-
await _classPrivateFieldGet2(_lifecycle, this).retryClose(c);
|
|
992
|
-
}
|
|
993
|
-
/**
|
|
994
|
-
* データを書き込みます。
|
|
798
|
+
* @param name 変数名です。
|
|
799
|
+
* @param value 設定する値です。
|
|
995
800
|
*
|
|
996
|
-
* @
|
|
997
|
-
* @param data 書き込むデータです。
|
|
801
|
+
* @returns 自身を返します。
|
|
998
802
|
*/
|
|
999
|
-
|
|
1000
|
-
if (
|
|
1001
|
-
|
|
803
|
+
set(name, value) {
|
|
804
|
+
if (_classPrivateFieldGet2(_store, this).readonly.has(name)) throw new ReadonlyVariableError({ name });
|
|
805
|
+
_classPrivateFieldGet2(_store, this).data.set(name, value);
|
|
806
|
+
return this;
|
|
1002
807
|
}
|
|
1003
808
|
/**
|
|
1004
|
-
*
|
|
809
|
+
* 変数の値を設定し、読み取り専用にします。
|
|
1005
810
|
*
|
|
1006
|
-
* @param
|
|
811
|
+
* @param name 変数名です。
|
|
812
|
+
* @param value 設定する値です。
|
|
1007
813
|
*
|
|
1008
|
-
* @returns
|
|
814
|
+
* @returns 自身を返します。
|
|
1009
815
|
*/
|
|
1010
|
-
|
|
1011
|
-
if (
|
|
1012
|
-
|
|
816
|
+
setReadonly(name, value) {
|
|
817
|
+
if (_classPrivateFieldGet2(_store, this).readonly.has(name)) throw new ReadonlyVariableError({ name });
|
|
818
|
+
_classPrivateFieldGet2(_store, this).data.set(name, value);
|
|
819
|
+
_classPrivateFieldGet2(_store, this).readonly.add(name);
|
|
820
|
+
return this;
|
|
1013
821
|
}
|
|
822
|
+
};
|
|
823
|
+
/**
|
|
824
|
+
* コンテキストが共有する実行時変数のストアを取得します。
|
|
825
|
+
*
|
|
826
|
+
* 外部実装のコンテキストは共有ストアを公開しないため、独立したストアを返します。
|
|
827
|
+
*
|
|
828
|
+
* @param context 対象のコンテキストです。
|
|
829
|
+
*
|
|
830
|
+
* @returns 実行時変数のストアを返します。
|
|
831
|
+
*/
|
|
832
|
+
function getVariablesStore(context) {
|
|
833
|
+
return context instanceof PipelineContext ? context.store : createVariablesStore();
|
|
834
|
+
}
|
|
835
|
+
var MapKeyContext = class extends PipelineContext {
|
|
1014
836
|
/**
|
|
1015
|
-
*
|
|
1016
|
-
*
|
|
1017
|
-
* @param c 存在確認コンテキストです。
|
|
837
|
+
* コンテキストを作成します。
|
|
1018
838
|
*
|
|
1019
|
-
* @
|
|
839
|
+
* @param init 初期値です。
|
|
1020
840
|
*/
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
841
|
+
constructor(init) {
|
|
842
|
+
const { key, vars, store } = init;
|
|
843
|
+
super({
|
|
844
|
+
vars,
|
|
845
|
+
store
|
|
846
|
+
});
|
|
847
|
+
this.key = key;
|
|
1024
848
|
}
|
|
849
|
+
};
|
|
850
|
+
var ActionContext = class extends PipelineContext {
|
|
1025
851
|
/**
|
|
1026
|
-
*
|
|
852
|
+
* コンテキストを作成します。
|
|
1027
853
|
*
|
|
1028
|
-
* @param
|
|
854
|
+
* @param init 初期値です。
|
|
1029
855
|
*/
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
856
|
+
constructor(init) {
|
|
857
|
+
const { vars, store, action, signal } = init;
|
|
858
|
+
super({
|
|
859
|
+
vars,
|
|
860
|
+
store
|
|
861
|
+
});
|
|
862
|
+
this.action = action;
|
|
863
|
+
this.signal = signal;
|
|
1033
864
|
}
|
|
865
|
+
};
|
|
866
|
+
var LifecycleContext = class extends ActionContext {};
|
|
867
|
+
/**
|
|
868
|
+
* 開始処理のコンテキストです。
|
|
869
|
+
*/
|
|
870
|
+
var OpenContext = class extends LifecycleContext {
|
|
1034
871
|
/**
|
|
1035
|
-
*
|
|
872
|
+
* コンテキストを作成します。
|
|
1036
873
|
*
|
|
1037
|
-
* @param
|
|
874
|
+
* @param init 初期値です。
|
|
1038
875
|
*/
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
876
|
+
constructor(init) {
|
|
877
|
+
super({
|
|
878
|
+
...init,
|
|
879
|
+
action: "open"
|
|
880
|
+
});
|
|
1042
881
|
}
|
|
882
|
+
};
|
|
883
|
+
/**
|
|
884
|
+
* 終了処理のコンテキストです。
|
|
885
|
+
*/
|
|
886
|
+
var CloseContext = class extends LifecycleContext {
|
|
1043
887
|
/**
|
|
1044
|
-
*
|
|
1045
|
-
*
|
|
1046
|
-
* @param c ストリーム取得コンテキストです。
|
|
888
|
+
* コンテキストを作成します。
|
|
1047
889
|
*
|
|
1048
|
-
* @
|
|
890
|
+
* @param init 初期値です。
|
|
1049
891
|
*/
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
892
|
+
constructor(init) {
|
|
893
|
+
super({
|
|
894
|
+
...init,
|
|
895
|
+
action: "close"
|
|
896
|
+
});
|
|
1055
897
|
}
|
|
898
|
+
};
|
|
899
|
+
var KeyedActionContext = class extends ActionContext {
|
|
1056
900
|
/**
|
|
1057
|
-
*
|
|
1058
|
-
*
|
|
1059
|
-
* @param c ストリーム取得コンテキストです。
|
|
901
|
+
* コンテキストを作成します。
|
|
1060
902
|
*
|
|
1061
|
-
* @
|
|
903
|
+
* @param init 初期値です。
|
|
1062
904
|
*/
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
return parseOutput(WritableStreamSchema, output);
|
|
905
|
+
constructor(init) {
|
|
906
|
+
const { key, ...superInit } = init;
|
|
907
|
+
super(superInit);
|
|
908
|
+
this.key = key;
|
|
1068
909
|
}
|
|
910
|
+
};
|
|
911
|
+
/**
|
|
912
|
+
* 書き込み処理のコンテキストです。
|
|
913
|
+
*/
|
|
914
|
+
var SetContext = class extends KeyedActionContext {
|
|
1069
915
|
/**
|
|
1070
|
-
*
|
|
916
|
+
* コンテキストを作成します。
|
|
1071
917
|
*
|
|
1072
|
-
* @param
|
|
1073
|
-
* @param err 集約エラーです。
|
|
918
|
+
* @param init 初期値です。
|
|
1074
919
|
*/
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
plugin: "storage",
|
|
1081
|
-
reason: error.reason
|
|
1082
|
-
})),
|
|
1083
|
-
plugin: "storage"
|
|
1084
|
-
}]);
|
|
920
|
+
constructor(init) {
|
|
921
|
+
super({
|
|
922
|
+
...init,
|
|
923
|
+
action: "set"
|
|
924
|
+
});
|
|
1085
925
|
}
|
|
1086
926
|
};
|
|
1087
|
-
_UniKvsStorage = UniKvsStorage;
|
|
1088
|
-
[_initProto] = _applyDecs(_UniKvsStorage, [], [
|
|
1089
|
-
[
|
|
1090
|
-
asyncmux,
|
|
1091
|
-
2,
|
|
1092
|
-
"open"
|
|
1093
|
-
],
|
|
1094
|
-
[
|
|
1095
|
-
asyncmux,
|
|
1096
|
-
2,
|
|
1097
|
-
"close"
|
|
1098
|
-
],
|
|
1099
|
-
[
|
|
1100
|
-
asyncmux,
|
|
1101
|
-
2,
|
|
1102
|
-
"retryClose"
|
|
1103
|
-
]
|
|
1104
|
-
]).e;
|
|
1105
|
-
//#endregion
|
|
1106
|
-
//#region ../src/_unikvs-branch.ts
|
|
1107
927
|
/**
|
|
1108
|
-
*
|
|
1109
|
-
* コンパイラーによる `#` フィールドのダウンレベルと同様に、`WeakMap` をブランド兼ストレージとして使います。
|
|
928
|
+
* 読み取り処理のコンテキストです。
|
|
1110
929
|
*/
|
|
1111
|
-
|
|
930
|
+
var GetContext = class extends KeyedActionContext {
|
|
931
|
+
/**
|
|
932
|
+
* コンテキストを作成します。
|
|
933
|
+
*
|
|
934
|
+
* @param init 初期値です。
|
|
935
|
+
*/
|
|
936
|
+
constructor(init) {
|
|
937
|
+
const { repair = {
|
|
938
|
+
enabled: false,
|
|
939
|
+
targets: []
|
|
940
|
+
}, ...superInit } = init;
|
|
941
|
+
super({
|
|
942
|
+
...superInit,
|
|
943
|
+
action: "get"
|
|
944
|
+
});
|
|
945
|
+
this.repair = repair;
|
|
946
|
+
}
|
|
947
|
+
};
|
|
1112
948
|
/**
|
|
1113
|
-
*
|
|
1114
|
-
*
|
|
1115
|
-
* `new Branch()` で作成された分岐以外の値が渡されたときは例外を投げます。
|
|
1116
|
-
* 外部からは使用しません。
|
|
1117
|
-
*
|
|
1118
|
-
* @param destinations 追加先の分岐先列です。
|
|
1119
|
-
* @param prefix 親のミドルウェア列です。
|
|
1120
|
-
* @param branch 追加する分岐です。
|
|
1121
|
-
*
|
|
1122
|
-
* @throws 分岐がストレージに到達しない場合に `InvalidForkError` を投げます。
|
|
949
|
+
* ストリーム処理のコンテキストです。
|
|
1123
950
|
*/
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
951
|
+
var StreamContext = class extends KeyedActionContext {
|
|
952
|
+
/**
|
|
953
|
+
* コンテキストを作成します。
|
|
954
|
+
*
|
|
955
|
+
* @param init 初期値です。
|
|
956
|
+
*/
|
|
957
|
+
constructor(init) {
|
|
958
|
+
const { repair = {
|
|
959
|
+
enabled: false,
|
|
960
|
+
targets: []
|
|
961
|
+
}, ...superInit } = init;
|
|
962
|
+
super({
|
|
963
|
+
...superInit,
|
|
964
|
+
action: "stream"
|
|
965
|
+
});
|
|
966
|
+
this.repair = repair;
|
|
967
|
+
}
|
|
968
|
+
};
|
|
1137
969
|
/**
|
|
1138
|
-
*
|
|
970
|
+
* 存在確認のコンテキストです。
|
|
1139
971
|
*/
|
|
1140
|
-
var
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
972
|
+
var HasContext = class extends KeyedActionContext {
|
|
973
|
+
/**
|
|
974
|
+
* コンテキストを作成します。
|
|
975
|
+
*
|
|
976
|
+
* @param init 初期値です。
|
|
977
|
+
*/
|
|
978
|
+
constructor(init) {
|
|
979
|
+
super({
|
|
980
|
+
...init,
|
|
981
|
+
action: "has"
|
|
1146
982
|
});
|
|
1147
983
|
}
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
984
|
+
};
|
|
985
|
+
/**
|
|
986
|
+
* 削除処理のコンテキストです。
|
|
987
|
+
*/
|
|
988
|
+
var DeleteContext = class extends KeyedActionContext {
|
|
989
|
+
/**
|
|
990
|
+
* コンテキストを作成します。
|
|
991
|
+
*
|
|
992
|
+
* @param init 初期値です。
|
|
993
|
+
*/
|
|
994
|
+
constructor(init) {
|
|
995
|
+
super({
|
|
996
|
+
...init,
|
|
997
|
+
action: "delete"
|
|
998
|
+
});
|
|
1152
999
|
}
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1000
|
+
};
|
|
1001
|
+
/**
|
|
1002
|
+
* コピー・移動で共通のコンテキストです。
|
|
1003
|
+
*/
|
|
1004
|
+
var TransferContext = class extends KeyedActionContext {
|
|
1005
|
+
/**
|
|
1006
|
+
* コンテキストを作成します。
|
|
1007
|
+
*
|
|
1008
|
+
* @param init 初期値です。
|
|
1009
|
+
*/
|
|
1010
|
+
constructor(init) {
|
|
1011
|
+
const { destinationKey, ...superInit } = init;
|
|
1012
|
+
super(superInit);
|
|
1013
|
+
this.destinationKey = destinationKey;
|
|
1156
1014
|
}
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1015
|
+
};
|
|
1016
|
+
/**
|
|
1017
|
+
* コピー処理のコンテキストです。
|
|
1018
|
+
*/
|
|
1019
|
+
var CopyContext = class extends TransferContext {
|
|
1020
|
+
/**
|
|
1021
|
+
* コンテキストを作成します。
|
|
1022
|
+
*
|
|
1023
|
+
* @param init 初期値です。
|
|
1024
|
+
*/
|
|
1025
|
+
constructor(init) {
|
|
1026
|
+
super({
|
|
1027
|
+
...init,
|
|
1028
|
+
action: "copy"
|
|
1162
1029
|
});
|
|
1163
|
-
return this;
|
|
1164
1030
|
}
|
|
1165
1031
|
};
|
|
1166
1032
|
/**
|
|
1167
|
-
*
|
|
1033
|
+
* 移動処理のコンテキストです。
|
|
1034
|
+
*/
|
|
1035
|
+
var MoveContext = class extends TransferContext {
|
|
1036
|
+
/**
|
|
1037
|
+
* コンテキストを作成します。
|
|
1038
|
+
*
|
|
1039
|
+
* @param init 初期値です。
|
|
1040
|
+
*/
|
|
1041
|
+
constructor(init) {
|
|
1042
|
+
super({
|
|
1043
|
+
...init,
|
|
1044
|
+
action: "move"
|
|
1045
|
+
});
|
|
1046
|
+
}
|
|
1047
|
+
};
|
|
1048
|
+
/**
|
|
1049
|
+
* 全削除のコンテキストです。
|
|
1050
|
+
*/
|
|
1051
|
+
var ClearContext = class extends ActionContext {
|
|
1052
|
+
/**
|
|
1053
|
+
* コンテキストを作成します。
|
|
1054
|
+
*
|
|
1055
|
+
* @param init 初期値です。
|
|
1056
|
+
*/
|
|
1057
|
+
constructor(init) {
|
|
1058
|
+
super({
|
|
1059
|
+
...init,
|
|
1060
|
+
action: "clear"
|
|
1061
|
+
});
|
|
1062
|
+
}
|
|
1063
|
+
};
|
|
1064
|
+
/**
|
|
1065
|
+
* 値変換の基底コンテキストです。
|
|
1066
|
+
*/
|
|
1067
|
+
var TransformContext = class extends KeyedActionContext {
|
|
1068
|
+
/**
|
|
1069
|
+
* コンテキストを作成します。
|
|
1070
|
+
*
|
|
1071
|
+
* @param init 初期値です。
|
|
1072
|
+
*/
|
|
1073
|
+
constructor(init) {
|
|
1074
|
+
const { source, ...superInit } = init;
|
|
1075
|
+
super(superInit);
|
|
1076
|
+
this.source = source;
|
|
1077
|
+
}
|
|
1078
|
+
};
|
|
1079
|
+
/**
|
|
1080
|
+
* データ変換の基底コンテキストです。
|
|
1081
|
+
*/
|
|
1082
|
+
var TransformDataContext = class extends TransformContext {};
|
|
1083
|
+
/**
|
|
1084
|
+
* 符号化のコンテキストです。
|
|
1085
|
+
*/
|
|
1086
|
+
var EncodeContext = class extends TransformDataContext {
|
|
1087
|
+
/**
|
|
1088
|
+
* コンテキストを作成します。
|
|
1089
|
+
*
|
|
1090
|
+
* @param init 初期値です。
|
|
1091
|
+
*/
|
|
1092
|
+
constructor(init) {
|
|
1093
|
+
super({
|
|
1094
|
+
...init,
|
|
1095
|
+
action: "set"
|
|
1096
|
+
});
|
|
1097
|
+
}
|
|
1098
|
+
};
|
|
1099
|
+
/**
|
|
1100
|
+
* 復号のコンテキストです。
|
|
1101
|
+
*/
|
|
1102
|
+
var DecodeContext = class extends TransformDataContext {
|
|
1103
|
+
/**
|
|
1104
|
+
* コンテキストを作成します。
|
|
1105
|
+
*
|
|
1106
|
+
* @param init 初期値です。
|
|
1107
|
+
*/
|
|
1108
|
+
constructor(init) {
|
|
1109
|
+
super({
|
|
1110
|
+
...init,
|
|
1111
|
+
action: "get"
|
|
1112
|
+
});
|
|
1113
|
+
}
|
|
1114
|
+
};
|
|
1115
|
+
/**
|
|
1116
|
+
* ストリーム変換の基底コンテキストです。
|
|
1117
|
+
*/
|
|
1118
|
+
var TransformStreamContext = class extends TransformContext {};
|
|
1119
|
+
/**
|
|
1120
|
+
* ストリーム符号化のコンテキストです。
|
|
1121
|
+
*/
|
|
1122
|
+
var EncodeStreamContext = class extends TransformStreamContext {
|
|
1123
|
+
/**
|
|
1124
|
+
* コンテキストを作成します。
|
|
1125
|
+
*
|
|
1126
|
+
* @param init 初期値です。
|
|
1127
|
+
*/
|
|
1128
|
+
constructor(init) {
|
|
1129
|
+
super({
|
|
1130
|
+
...init,
|
|
1131
|
+
action: "set"
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
1134
|
+
};
|
|
1135
|
+
/**
|
|
1136
|
+
* ストリーム復号のコンテキストです。
|
|
1137
|
+
*/
|
|
1138
|
+
var DecodeStreamContext = class extends TransformStreamContext {
|
|
1139
|
+
/**
|
|
1140
|
+
* コンテキストを作成します。
|
|
1141
|
+
*
|
|
1142
|
+
* @param init 初期値です。
|
|
1143
|
+
*/
|
|
1144
|
+
constructor(init) {
|
|
1145
|
+
super({
|
|
1146
|
+
...init,
|
|
1147
|
+
action: "stream"
|
|
1148
|
+
});
|
|
1149
|
+
}
|
|
1150
|
+
};
|
|
1151
|
+
//#endregion
|
|
1152
|
+
//#region ../src/_streams.ts
|
|
1153
|
+
/**
|
|
1154
|
+
* 値が `ReadableStream` のインターフェースを満たすかどうかを判定します。
|
|
1168
1155
|
*
|
|
1169
|
-
*
|
|
1156
|
+
* ランタイムによっては `ReadableStream` クラスを継承せずに同じインターフェースを備えたオブジェクトが存在するため、`instanceof` ではなく必要なメソッドの有無で判定します。
|
|
1157
|
+
*
|
|
1158
|
+
* @param input 判定する値です。
|
|
1159
|
+
*
|
|
1160
|
+
* @returns `ReadableStream` のインターフェースを満たす場合は `true` を返します。
|
|
1170
1161
|
*/
|
|
1171
|
-
function
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
return
|
|
1162
|
+
function isReadableStream(input) {
|
|
1163
|
+
if (typeof input !== "object" || input === null) return false;
|
|
1164
|
+
const stream = input;
|
|
1165
|
+
return typeof stream.tee === "function" && typeof stream.cancel === "function" && typeof stream.pipeTo === "function" && typeof stream.getReader === "function" && typeof stream.pipeThrough === "function";
|
|
1175
1166
|
}
|
|
1176
|
-
//#endregion
|
|
1177
|
-
//#region ../src/_contexts.ts
|
|
1178
1167
|
/**
|
|
1179
|
-
*
|
|
1168
|
+
* 値が `WritableStream` のインターフェースを満たすかどうかを判定します。
|
|
1180
1169
|
*
|
|
1181
|
-
*
|
|
1182
|
-
* 反復子はそのまま返します。
|
|
1170
|
+
* ランタイムによっては `WritableStream` クラスを継承せずに同じインターフェースを備えたオブジェクトが存在するため、`instanceof` ではなく必要なメソッドの有無で判定します。
|
|
1183
1171
|
*
|
|
1184
|
-
* @param
|
|
1172
|
+
* @param input 判定する値です。
|
|
1185
1173
|
*
|
|
1186
|
-
* @returns
|
|
1174
|
+
* @returns `WritableStream` のインターフェースを満たす場合は `true` を返します。
|
|
1187
1175
|
*/
|
|
1188
|
-
function
|
|
1189
|
-
if (
|
|
1190
|
-
|
|
1191
|
-
return
|
|
1176
|
+
function isWritableStream(input) {
|
|
1177
|
+
if (typeof input !== "object" || input === null) return false;
|
|
1178
|
+
const stream = input;
|
|
1179
|
+
return typeof stream.abort === "function" && typeof stream.close === "function" && typeof stream.getWriter === "function";
|
|
1192
1180
|
}
|
|
1193
1181
|
/**
|
|
1194
|
-
*
|
|
1182
|
+
* ストリームの重複を除いてキャンセルします。
|
|
1195
1183
|
*
|
|
1196
|
-
*
|
|
1184
|
+
* 個々のキャンセルに失敗しても無視し、元の例外を優先して伝えます。
|
|
1197
1185
|
*
|
|
1198
|
-
* @
|
|
1186
|
+
* @param streams キャンセルするストリームです。
|
|
1187
|
+
* @param reason キャンセル理由です。
|
|
1199
1188
|
*/
|
|
1200
|
-
function
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1189
|
+
async function cancelStreams(streams, reason) {
|
|
1190
|
+
await Promise.all([...new Set(streams)].map(async (stream) => {
|
|
1191
|
+
try {
|
|
1192
|
+
await stream.cancel(reason);
|
|
1193
|
+
} catch {}
|
|
1194
|
+
}));
|
|
1195
|
+
}
|
|
1196
|
+
//#endregion
|
|
1197
|
+
//#region ../src/_valibot.ts
|
|
1198
|
+
function parseInput(schema, value, Error = InvalidInputError) {
|
|
1199
|
+
const result = safeParse(schema, value);
|
|
1200
|
+
if (result.success) return result.output;
|
|
1201
|
+
const error = new Error({
|
|
1202
|
+
value,
|
|
1203
|
+
issues: result.issues
|
|
1204
|
+
});
|
|
1205
|
+
tryCaptureStackTrace(error, parseInput);
|
|
1206
|
+
throw error;
|
|
1207
|
+
}
|
|
1208
|
+
function parseOutput(schema, value, Error = InvalidOutputError) {
|
|
1209
|
+
const result = safeParse(schema, value);
|
|
1210
|
+
if (result.success) return result.output;
|
|
1211
|
+
const error = new Error({
|
|
1212
|
+
value,
|
|
1213
|
+
issues: result.issues
|
|
1214
|
+
});
|
|
1215
|
+
tryCaptureStackTrace(error, parseOutput);
|
|
1216
|
+
throw error;
|
|
1217
|
+
}
|
|
1218
|
+
//#endregion
|
|
1219
|
+
//#region ../src/_streams.schemas.ts
|
|
1220
|
+
/**
|
|
1221
|
+
* `ReadableStream` のインターフェースを満たすかを検証するためのスキーマです。
|
|
1222
|
+
*/
|
|
1223
|
+
const ReadableStreamSchema = custom(isReadableStream, "Expected a ReadableStream");
|
|
1224
|
+
/**
|
|
1225
|
+
* `WritableStream` のインターフェースを満たすかを検証するためのスキーマです。
|
|
1226
|
+
*/
|
|
1227
|
+
const WritableStreamSchema = custom(isWritableStream, "Expected a WritableStream");
|
|
1228
|
+
//#endregion
|
|
1229
|
+
//#region ../src/_storage.ts
|
|
1230
|
+
var _UniKvsStorage;
|
|
1231
|
+
let _initProto;
|
|
1232
|
+
function _applyDecs(e, t, n, r, o, i) {
|
|
1233
|
+
var a, c, u, s, f, l, p, d = Symbol.metadata || Symbol.for("Symbol.metadata"), m = Object.defineProperty, h = Object.create, y = [h(null), h(null)], v = t.length;
|
|
1234
|
+
function g(t, n, r) {
|
|
1235
|
+
return function(o, i) {
|
|
1236
|
+
n && (i = o, o = e);
|
|
1237
|
+
for (var a = 0; a < t.length; a++) i = t[a].apply(o, r ? [i] : []);
|
|
1238
|
+
return r ? i : o;
|
|
1239
|
+
};
|
|
1240
|
+
}
|
|
1241
|
+
function b(e, t, n, r) {
|
|
1242
|
+
if ("function" != typeof e && (r || void 0 !== e)) throw new TypeError(t + " must " + (n || "be") + " a function" + (r ? "" : " or undefined"));
|
|
1243
|
+
return e;
|
|
1244
|
+
}
|
|
1245
|
+
function applyDec(e, t, n, r, o, i, u, s, f, l, p) {
|
|
1246
|
+
function d(e) {
|
|
1247
|
+
if (!p(e)) throw new TypeError("Attempted to access private element on non-instance");
|
|
1248
|
+
}
|
|
1249
|
+
var h = [].concat(t[0]), v = t[3], w = !u, D = 1 === o, S = 3 === o, j = 4 === o, E = 2 === o;
|
|
1250
|
+
function I(t, n, r) {
|
|
1251
|
+
return function(o, i) {
|
|
1252
|
+
return n && (i = o, o = e), r && r(o), P[t].call(o, i);
|
|
1253
|
+
};
|
|
1254
|
+
}
|
|
1255
|
+
if (!w) {
|
|
1256
|
+
var P = {}, k = [], F = S ? "get" : j || D ? "set" : "value";
|
|
1257
|
+
if (f ? (l || D ? P = {
|
|
1258
|
+
get: _setFunctionName(function() {
|
|
1259
|
+
return v(this);
|
|
1260
|
+
}, r, "get"),
|
|
1261
|
+
set: function(e) {
|
|
1262
|
+
t[4](this, e);
|
|
1263
|
+
}
|
|
1264
|
+
} : P[F] = v, l || _setFunctionName(P[F], r, E ? "" : F)) : l || (P = Object.getOwnPropertyDescriptor(e, r)), !l && !f) {
|
|
1265
|
+
if ((c = y[+s][r]) && 7 !== (c ^ o)) throw Error("Decorating two elements with the same name (" + P[F].name + ") is not supported yet");
|
|
1266
|
+
y[+s][r] = o < 3 ? 1 : o;
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
for (var N = e, O = h.length - 1; O >= 0; O -= n ? 2 : 1) {
|
|
1270
|
+
var T = b(h[O], "A decorator", "be", !0), z = n ? h[O - 1] : void 0, A = {}, H = {
|
|
1271
|
+
kind: [
|
|
1272
|
+
"field",
|
|
1273
|
+
"accessor",
|
|
1274
|
+
"method",
|
|
1275
|
+
"getter",
|
|
1276
|
+
"setter",
|
|
1277
|
+
"class"
|
|
1278
|
+
][o],
|
|
1279
|
+
name: r,
|
|
1280
|
+
metadata: a,
|
|
1281
|
+
addInitializer: function(e, t) {
|
|
1282
|
+
if (e.v) throw new TypeError("attempted to call addInitializer after decoration was finished");
|
|
1283
|
+
b(t, "An initializer", "be", !0), i.push(t);
|
|
1284
|
+
}.bind(null, A)
|
|
1285
|
+
};
|
|
1286
|
+
if (w) c = T.call(z, N, H), A.v = 1, b(c, "class decorators", "return") && (N = c);
|
|
1287
|
+
else if (H.static = s, H.private = f, c = H.access = { has: f ? p.bind() : function(e) {
|
|
1288
|
+
return r in e;
|
|
1289
|
+
} }, j || (c.get = f ? E ? function(e) {
|
|
1290
|
+
return d(e), P.value;
|
|
1291
|
+
} : I("get", 0, d) : function(e) {
|
|
1292
|
+
return e[r];
|
|
1293
|
+
}), E || S || (c.set = f ? I("set", 0, d) : function(e, t) {
|
|
1294
|
+
e[r] = t;
|
|
1295
|
+
}), N = T.call(z, D ? {
|
|
1296
|
+
get: P.get,
|
|
1297
|
+
set: P.set
|
|
1298
|
+
} : P[F], H), A.v = 1, D) {
|
|
1299
|
+
if ("object" == typeof N && N) (c = b(N.get, "accessor.get")) && (P.get = c), (c = b(N.set, "accessor.set")) && (P.set = c), (c = b(N.init, "accessor.init")) && k.unshift(c);
|
|
1300
|
+
else if (void 0 !== N) throw new TypeError("accessor decorators must return an object with get, set, or init properties or undefined");
|
|
1301
|
+
} else b(N, (l ? "field" : "method") + " decorators", "return") && (l ? k.unshift(N) : P[F] = N);
|
|
1302
|
+
}
|
|
1303
|
+
return o < 2 && u.push(g(k, s, 1), g(i, s, 0)), l || w || (f ? D ? u.splice(-1, 0, I("get", s), I("set", s)) : u.push(E ? P[F] : b.call.bind(P[F])) : m(e, r, P)), N;
|
|
1304
|
+
}
|
|
1305
|
+
function w(e) {
|
|
1306
|
+
return m(e, d, {
|
|
1307
|
+
configurable: !0,
|
|
1308
|
+
enumerable: !0,
|
|
1309
|
+
value: a
|
|
1310
|
+
});
|
|
1311
|
+
}
|
|
1312
|
+
return void 0 !== i && (a = i[d]), a = h(null == a ? null : a), f = [], l = function(e) {
|
|
1313
|
+
e && f.push(g(e));
|
|
1314
|
+
}, p = function(t, r) {
|
|
1315
|
+
for (var i = 0; i < n.length; i++) {
|
|
1316
|
+
var a = n[i], c = a[1], l = 7 & c;
|
|
1317
|
+
if ((8 & c) == t && !l == r) {
|
|
1318
|
+
var p = a[2], d = !!a[3], m = 16 & c;
|
|
1319
|
+
applyDec(t ? e : e.prototype, a, m, d ? "#" + p : _toPropertyKey(p), l, l < 2 ? [] : t ? s = s || [] : u = u || [], f, !!t, d, r, t && d ? function(t) {
|
|
1320
|
+
return _checkInRHS(t) === e;
|
|
1321
|
+
} : o);
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
}, p(8, 0), p(0, 0), p(8, 1), p(0, 1), l(u), l(s), c = f, v || w(e), {
|
|
1325
|
+
e: c,
|
|
1326
|
+
get c() {
|
|
1327
|
+
var n = [];
|
|
1328
|
+
return v && [w(e = applyDec(e, [t], r, e.name, 5, n)), g(n, 1)];
|
|
1329
|
+
}
|
|
1204
1330
|
};
|
|
1205
1331
|
}
|
|
1206
|
-
|
|
1207
|
-
var
|
|
1332
|
+
function _toPropertyKey(t) {
|
|
1333
|
+
var i = _toPrimitive(t, "string");
|
|
1334
|
+
return "symbol" == typeof i ? i : i + "";
|
|
1335
|
+
}
|
|
1336
|
+
function _toPrimitive(t, e) {
|
|
1337
|
+
if ("object" != typeof t || !t) return t;
|
|
1338
|
+
var r;
|
|
1339
|
+
if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
|
|
1340
|
+
var i = r.call(t, e || "default");
|
|
1341
|
+
if ("object" != typeof i) return i;
|
|
1342
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
1343
|
+
}
|
|
1344
|
+
return ("string" === e ? String : Number)(t);
|
|
1345
|
+
}
|
|
1346
|
+
function _setFunctionName(e, t, n) {
|
|
1347
|
+
"symbol" == typeof t && (t = (t = t.description) ? "[" + t + "]" : "");
|
|
1348
|
+
try {
|
|
1349
|
+
Object.defineProperty(e, "name", {
|
|
1350
|
+
configurable: !0,
|
|
1351
|
+
value: n ? n + " " + t : t
|
|
1352
|
+
});
|
|
1353
|
+
} catch (e) {}
|
|
1354
|
+
return e;
|
|
1355
|
+
}
|
|
1356
|
+
function _checkInRHS(e) {
|
|
1357
|
+
if (Object(e) !== e) throw TypeError("right-hand side of 'in' should be an object, got " + (null !== e ? typeof e : "null"));
|
|
1358
|
+
return e;
|
|
1359
|
+
}
|
|
1360
|
+
/**
|
|
1361
|
+
* 同じオブジェクトに対して同じ `UniKvsStorage` インスタンスを返すためのメモです。
|
|
1362
|
+
*/
|
|
1363
|
+
const instances = /* #__PURE__ */ new WeakMap();
|
|
1364
|
+
var _io = /* @__PURE__ */ new WeakMap();
|
|
1365
|
+
var _lifecycle = /* @__PURE__ */ new WeakMap();
|
|
1208
1366
|
/**
|
|
1209
|
-
*
|
|
1367
|
+
* `IStorage` を `UniKvs` 内部から扱うためのラッパーです。
|
|
1368
|
+
*
|
|
1369
|
+
* ストレージを安全に使うための検証などの処理が集約されています。
|
|
1210
1370
|
*/
|
|
1211
|
-
var
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
_classPrivateFieldInitSpec(this, _readonly, void 0);
|
|
1220
|
-
const { store } = init;
|
|
1221
|
-
if (store) {
|
|
1222
|
-
_classPrivateFieldSet2(_data, this, store.data);
|
|
1223
|
-
_classPrivateFieldSet2(_readonly, this, store.readonly);
|
|
1224
|
-
} else {
|
|
1225
|
-
_classPrivateFieldSet2(_data, this, /* @__PURE__ */ new Map());
|
|
1226
|
-
_classPrivateFieldSet2(_readonly, this, /* @__PURE__ */ new Set());
|
|
1227
|
-
}
|
|
1228
|
-
const vars = normalizeVariablesInit(init.vars);
|
|
1229
|
-
for (const [name, value] of vars) _classPrivateFieldGet2(_data, this).set(name, value);
|
|
1230
|
-
}
|
|
1231
|
-
/**
|
|
1232
|
-
* 変数の値を読み取ります。
|
|
1233
|
-
*
|
|
1234
|
-
* @param name 変数名です。
|
|
1235
|
-
*
|
|
1236
|
-
* @returns 変数の値を返します。
|
|
1237
|
-
*/
|
|
1238
|
-
get(name) {
|
|
1239
|
-
return _classPrivateFieldGet2(_data, this).get(name);
|
|
1371
|
+
var UniKvsStorage = class UniKvsStorage {
|
|
1372
|
+
constructor(storage) {
|
|
1373
|
+
this.name = void _initProto(this);
|
|
1374
|
+
_classPrivateFieldInitSpec(this, _io, void 0);
|
|
1375
|
+
_classPrivateFieldInitSpec(this, _lifecycle, void 0);
|
|
1376
|
+
_classPrivateFieldSet2(_io, this, storage);
|
|
1377
|
+
_classPrivateFieldSet2(_lifecycle, this, new PluginLifecycle(storage));
|
|
1378
|
+
this.name = storage.name;
|
|
1240
1379
|
}
|
|
1241
1380
|
/**
|
|
1242
|
-
*
|
|
1381
|
+
* `IStorage` から `UniKvs` 内部から扱うためのストレージを作成します。
|
|
1243
1382
|
*
|
|
1244
|
-
* @param
|
|
1245
|
-
* @param value 設定する値です。
|
|
1383
|
+
* @param storage 元となるストレージです。
|
|
1246
1384
|
*
|
|
1247
|
-
* @returns
|
|
1385
|
+
* @returns 検証などの機能が集約されたストレージです。
|
|
1248
1386
|
*/
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
_classPrivateFieldGet2(_data, this).set(name, value);
|
|
1252
|
-
return this;
|
|
1387
|
+
static from(storage) {
|
|
1388
|
+
return callFnOnce(instances, storage, () => new UniKvsStorage(storage));
|
|
1253
1389
|
}
|
|
1254
1390
|
/**
|
|
1255
|
-
*
|
|
1256
|
-
*
|
|
1257
|
-
* @param name 変数名です。
|
|
1258
|
-
* @param value 設定する値です。
|
|
1391
|
+
* ストレージを開きます。
|
|
1259
1392
|
*
|
|
1260
|
-
* @
|
|
1393
|
+
* @param c オープンコンテキストです。
|
|
1261
1394
|
*/
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
_classPrivateFieldGet2(_data, this).set(name, value);
|
|
1265
|
-
_classPrivateFieldGet2(_readonly, this).add(name);
|
|
1266
|
-
return this;
|
|
1395
|
+
async open(c) {
|
|
1396
|
+
await _classPrivateFieldGet2(_lifecycle, this).open(c);
|
|
1267
1397
|
}
|
|
1268
1398
|
/**
|
|
1269
|
-
*
|
|
1399
|
+
* ストレージを閉じます。
|
|
1270
1400
|
*
|
|
1271
|
-
* @
|
|
1401
|
+
* @param c クローズコンテキストです。
|
|
1272
1402
|
*/
|
|
1273
|
-
|
|
1274
|
-
|
|
1403
|
+
async close(c) {
|
|
1404
|
+
await _classPrivateFieldGet2(_lifecycle, this).close(c);
|
|
1275
1405
|
}
|
|
1276
|
-
};
|
|
1277
|
-
var MapKeyContext = class extends PipelineContext {
|
|
1278
1406
|
/**
|
|
1279
|
-
*
|
|
1407
|
+
* 失敗した実 `close` だけを再試行します。
|
|
1280
1408
|
*
|
|
1281
|
-
* @param
|
|
1409
|
+
* @param c クローズコンテキストです。
|
|
1282
1410
|
*/
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
super({
|
|
1286
|
-
vars,
|
|
1287
|
-
store
|
|
1288
|
-
});
|
|
1289
|
-
this.key = key;
|
|
1411
|
+
async retryClose(c) {
|
|
1412
|
+
await _classPrivateFieldGet2(_lifecycle, this).retryClose(c);
|
|
1290
1413
|
}
|
|
1291
|
-
};
|
|
1292
|
-
var ActionContext = class extends PipelineContext {
|
|
1293
1414
|
/**
|
|
1294
|
-
*
|
|
1415
|
+
* データを書き込みます。
|
|
1295
1416
|
*
|
|
1296
|
-
* @param
|
|
1417
|
+
* @param c 書き込みコンテキストです。
|
|
1418
|
+
* @param data 書き込むデータです。
|
|
1297
1419
|
*/
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
vars,
|
|
1302
|
-
store
|
|
1303
|
-
});
|
|
1304
|
-
this.action = action;
|
|
1305
|
-
this.signal = signal;
|
|
1420
|
+
async write(c, data) {
|
|
1421
|
+
if (!_classPrivateFieldGet2(_io, this).isOpen) throw new StorageIsNotOpenError({ name: this.name });
|
|
1422
|
+
await _classPrivateFieldGet2(_io, this).write(c, data);
|
|
1306
1423
|
}
|
|
1307
|
-
};
|
|
1308
|
-
var LifecycleContext = class extends ActionContext {};
|
|
1309
|
-
/**
|
|
1310
|
-
* 開始処理のコンテキストです。
|
|
1311
|
-
*/
|
|
1312
|
-
var OpenContext = class extends LifecycleContext {
|
|
1313
1424
|
/**
|
|
1314
|
-
*
|
|
1425
|
+
* データを読み取ります。
|
|
1315
1426
|
*
|
|
1316
|
-
* @param
|
|
1317
|
-
*/
|
|
1318
|
-
constructor(init) {
|
|
1319
|
-
super({
|
|
1320
|
-
...init,
|
|
1321
|
-
action: "open"
|
|
1322
|
-
});
|
|
1323
|
-
}
|
|
1324
|
-
};
|
|
1325
|
-
/**
|
|
1326
|
-
* 終了処理のコンテキストです。
|
|
1327
|
-
*/
|
|
1328
|
-
var CloseContext = class extends LifecycleContext {
|
|
1329
|
-
/**
|
|
1330
|
-
* コンテキストを作成します。
|
|
1427
|
+
* @param c 読み取りコンテキストです。
|
|
1331
1428
|
*
|
|
1332
|
-
* @
|
|
1429
|
+
* @returns 読み取ったデータを返します。
|
|
1333
1430
|
*/
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
action: "close"
|
|
1338
|
-
});
|
|
1431
|
+
async read(c) {
|
|
1432
|
+
if (!_classPrivateFieldGet2(_io, this).isOpen) throw new StorageIsNotOpenError({ name: this.name });
|
|
1433
|
+
return await _classPrivateFieldGet2(_io, this).read(c);
|
|
1339
1434
|
}
|
|
1340
|
-
};
|
|
1341
|
-
var KeyedActionContext = class extends ActionContext {
|
|
1342
1435
|
/**
|
|
1343
|
-
*
|
|
1436
|
+
* データの存在を確認します。
|
|
1344
1437
|
*
|
|
1345
|
-
* @param
|
|
1346
|
-
*/
|
|
1347
|
-
constructor(init) {
|
|
1348
|
-
const { key, ...superInit } = init;
|
|
1349
|
-
super(superInit);
|
|
1350
|
-
this.key = key;
|
|
1351
|
-
}
|
|
1352
|
-
};
|
|
1353
|
-
/**
|
|
1354
|
-
* 書き込み処理のコンテキストです。
|
|
1355
|
-
*/
|
|
1356
|
-
var SetContext = class extends KeyedActionContext {
|
|
1357
|
-
/**
|
|
1358
|
-
* コンテキストを作成します。
|
|
1438
|
+
* @param c 存在確認コンテキストです。
|
|
1359
1439
|
*
|
|
1360
|
-
* @
|
|
1440
|
+
* @returns 存在する場合は `true` を返します。
|
|
1361
1441
|
*/
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
action: "set"
|
|
1366
|
-
});
|
|
1442
|
+
async exists(c) {
|
|
1443
|
+
if (!_classPrivateFieldGet2(_io, this).isOpen) throw new StorageIsNotOpenError({ name: this.name });
|
|
1444
|
+
return await _classPrivateFieldGet2(_io, this).exists(c);
|
|
1367
1445
|
}
|
|
1368
|
-
};
|
|
1369
|
-
/**
|
|
1370
|
-
* 読み取り処理のコンテキストです。
|
|
1371
|
-
*/
|
|
1372
|
-
var GetContext = class extends KeyedActionContext {
|
|
1373
1446
|
/**
|
|
1374
|
-
*
|
|
1447
|
+
* データを削除します。
|
|
1375
1448
|
*
|
|
1376
|
-
* @param
|
|
1449
|
+
* @param c 削除コンテキストです。
|
|
1377
1450
|
*/
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
targets: []
|
|
1382
|
-
}, ...superInit } = init;
|
|
1383
|
-
super({
|
|
1384
|
-
...superInit,
|
|
1385
|
-
action: "get"
|
|
1386
|
-
});
|
|
1387
|
-
this.repair = repair;
|
|
1451
|
+
async delete(c) {
|
|
1452
|
+
if (!_classPrivateFieldGet2(_io, this).isOpen) throw new StorageIsNotOpenError({ name: this.name });
|
|
1453
|
+
await _classPrivateFieldGet2(_io, this).delete(c);
|
|
1388
1454
|
}
|
|
1389
|
-
};
|
|
1390
|
-
/**
|
|
1391
|
-
* ストリーム処理のコンテキストです。
|
|
1392
|
-
*/
|
|
1393
|
-
var StreamContext = class extends KeyedActionContext {
|
|
1394
1455
|
/**
|
|
1395
|
-
*
|
|
1456
|
+
* データをすべて削除します。
|
|
1396
1457
|
*
|
|
1397
|
-
* @param
|
|
1458
|
+
* @param c クリアコンテキストです。
|
|
1398
1459
|
*/
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
targets: []
|
|
1403
|
-
}, ...superInit } = init;
|
|
1404
|
-
super({
|
|
1405
|
-
...superInit,
|
|
1406
|
-
action: "stream"
|
|
1407
|
-
});
|
|
1408
|
-
this.repair = repair;
|
|
1460
|
+
async clear(c) {
|
|
1461
|
+
if (!_classPrivateFieldGet2(_io, this).isOpen) throw new StorageIsNotOpenError({ name: this.name });
|
|
1462
|
+
await _classPrivateFieldGet2(_io, this).clear(c);
|
|
1409
1463
|
}
|
|
1410
|
-
};
|
|
1411
|
-
/**
|
|
1412
|
-
* 存在確認のコンテキストです。
|
|
1413
|
-
*/
|
|
1414
|
-
var HasContext = class extends KeyedActionContext {
|
|
1415
1464
|
/**
|
|
1416
|
-
*
|
|
1465
|
+
* データを別のキーへ複製します。
|
|
1417
1466
|
*
|
|
1418
|
-
* @param
|
|
1467
|
+
* @param c コピー元とコピー先のキーを持つコンテキストです。
|
|
1419
1468
|
*/
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1469
|
+
async copy(c) {
|
|
1470
|
+
if (!_classPrivateFieldGet2(_io, this).isOpen) throw new StorageIsNotOpenError({ name: this.name });
|
|
1471
|
+
if (_classPrivateFieldGet2(_io, this).copy === void 0) {
|
|
1472
|
+
const data = await _classPrivateFieldGet2(_io, this).read(c);
|
|
1473
|
+
if (c.key !== c.destinationKey) await _classPrivateFieldGet2(_io, this).write(new CopyContext({
|
|
1474
|
+
key: c.destinationKey,
|
|
1475
|
+
store: getVariablesStore(c),
|
|
1476
|
+
signal: c.signal,
|
|
1477
|
+
destinationKey: c.destinationKey
|
|
1478
|
+
}), data);
|
|
1479
|
+
return;
|
|
1480
|
+
}
|
|
1481
|
+
await _classPrivateFieldGet2(_io, this).copy(c);
|
|
1425
1482
|
}
|
|
1426
|
-
};
|
|
1427
|
-
/**
|
|
1428
|
-
* 削除処理のコンテキストです。
|
|
1429
|
-
*/
|
|
1430
|
-
var DeleteContext = class extends KeyedActionContext {
|
|
1431
1483
|
/**
|
|
1432
|
-
*
|
|
1484
|
+
* データを別のキーへ移動します。
|
|
1433
1485
|
*
|
|
1434
|
-
* @param
|
|
1486
|
+
* @param c 移動元と移動先のキーを持つコンテキストです。
|
|
1435
1487
|
*/
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1488
|
+
async move(c) {
|
|
1489
|
+
if (!_classPrivateFieldGet2(_io, this).isOpen) throw new StorageIsNotOpenError({ name: this.name });
|
|
1490
|
+
if (_classPrivateFieldGet2(_io, this).move === void 0) {
|
|
1491
|
+
if (c.key === c.destinationKey) {
|
|
1492
|
+
await _classPrivateFieldGet2(_io, this).read(c);
|
|
1493
|
+
return;
|
|
1494
|
+
}
|
|
1495
|
+
if (_classPrivateFieldGet2(_io, this).copy === void 0) {
|
|
1496
|
+
const data = await _classPrivateFieldGet2(_io, this).read(c);
|
|
1497
|
+
await _classPrivateFieldGet2(_io, this).write(new MoveContext({
|
|
1498
|
+
key: c.destinationKey,
|
|
1499
|
+
store: getVariablesStore(c),
|
|
1500
|
+
signal: c.signal,
|
|
1501
|
+
destinationKey: c.destinationKey
|
|
1502
|
+
}), data);
|
|
1503
|
+
} else await _classPrivateFieldGet2(_io, this).copy(c);
|
|
1504
|
+
await _classPrivateFieldGet2(_io, this).delete(c);
|
|
1505
|
+
return;
|
|
1506
|
+
}
|
|
1507
|
+
await _classPrivateFieldGet2(_io, this).move(c);
|
|
1441
1508
|
}
|
|
1442
|
-
};
|
|
1443
|
-
/**
|
|
1444
|
-
* 全削除のコンテキストです。
|
|
1445
|
-
*/
|
|
1446
|
-
var ClearContext = class extends ActionContext {
|
|
1447
1509
|
/**
|
|
1448
|
-
*
|
|
1510
|
+
* 読み取り用のストリームを取得します。
|
|
1449
1511
|
*
|
|
1450
|
-
* @param
|
|
1451
|
-
*/
|
|
1452
|
-
constructor(init) {
|
|
1453
|
-
super({
|
|
1454
|
-
...init,
|
|
1455
|
-
action: "clear"
|
|
1456
|
-
});
|
|
1457
|
-
}
|
|
1458
|
-
};
|
|
1459
|
-
/**
|
|
1460
|
-
* 値変換の基底コンテキストです。
|
|
1461
|
-
*/
|
|
1462
|
-
var TransformContext = class extends KeyedActionContext {
|
|
1463
|
-
/**
|
|
1464
|
-
* コンテキストを作成します。
|
|
1512
|
+
* @param c ストリーム取得コンテキストです。
|
|
1465
1513
|
*
|
|
1466
|
-
* @
|
|
1514
|
+
* @returns 読み取り用のストリームを返します。
|
|
1467
1515
|
*/
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1516
|
+
async getReadable(c) {
|
|
1517
|
+
if (!_classPrivateFieldGet2(_io, this).isOpen) throw new StorageIsNotOpenError({ name: this.name });
|
|
1518
|
+
if (_classPrivateFieldGet2(_io, this).getReadable === void 0) throw new ReadableStreamNotSupportedError({ name: this.name });
|
|
1519
|
+
const output = await _classPrivateFieldGet2(_io, this).getReadable(c);
|
|
1520
|
+
return parseOutput(ReadableStreamSchema, output);
|
|
1472
1521
|
}
|
|
1473
|
-
};
|
|
1474
|
-
/**
|
|
1475
|
-
* データ変換の基底コンテキストです。
|
|
1476
|
-
*/
|
|
1477
|
-
var TransformDataContext = class extends TransformContext {};
|
|
1478
|
-
/**
|
|
1479
|
-
* 符号化のコンテキストです。
|
|
1480
|
-
*/
|
|
1481
|
-
var EncodeContext = class extends TransformDataContext {
|
|
1482
1522
|
/**
|
|
1483
|
-
*
|
|
1523
|
+
* 書き込み用のストリームを取得します。
|
|
1484
1524
|
*
|
|
1485
|
-
* @param
|
|
1525
|
+
* @param c ストリーム取得コンテキストです。
|
|
1526
|
+
*
|
|
1527
|
+
* @returns 書き込み用のストリームを返します。
|
|
1486
1528
|
*/
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1529
|
+
async getWritable(c) {
|
|
1530
|
+
if (!_classPrivateFieldGet2(_io, this).isOpen) throw new StorageIsNotOpenError({ name: this.name });
|
|
1531
|
+
if (_classPrivateFieldGet2(_io, this).getWritable === void 0) throw new WritableStreamNotSupportedError({ name: this.name });
|
|
1532
|
+
const output = await _classPrivateFieldGet2(_io, this).getWritable(c);
|
|
1533
|
+
return parseOutput(WritableStreamSchema, output);
|
|
1492
1534
|
}
|
|
1493
|
-
};
|
|
1494
|
-
/**
|
|
1495
|
-
* 復号のコンテキストです。
|
|
1496
|
-
*/
|
|
1497
|
-
var DecodeContext = class extends TransformDataContext {
|
|
1498
1535
|
/**
|
|
1499
|
-
*
|
|
1536
|
+
* 他のストレージへの書き込み失敗を通知します。
|
|
1500
1537
|
*
|
|
1501
|
-
* @param
|
|
1538
|
+
* @param c 書き込み失敗通知コンテキストです。
|
|
1539
|
+
* @param err 集約エラーです。
|
|
1502
1540
|
*/
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1541
|
+
async onOtherWriteError(c, err) {
|
|
1542
|
+
if (!_classPrivateFieldGet2(_io, this).isOpen) throw new StorageIsNotOpenError({ name: this.name });
|
|
1543
|
+
if (_classPrivateFieldGet2(_io, this).onOtherWriteError === void 0) return;
|
|
1544
|
+
await _classPrivateFieldGet2(_io, this).onOtherWriteError(c, [{
|
|
1545
|
+
errors: err.meta.errors.map((error) => ({
|
|
1546
|
+
plugin: "storage",
|
|
1547
|
+
reason: error.reason
|
|
1548
|
+
})),
|
|
1549
|
+
plugin: "storage"
|
|
1550
|
+
}]);
|
|
1508
1551
|
}
|
|
1509
1552
|
};
|
|
1553
|
+
_UniKvsStorage = UniKvsStorage;
|
|
1554
|
+
[_initProto] = _applyDecs(_UniKvsStorage, [], [
|
|
1555
|
+
[
|
|
1556
|
+
asyncmux,
|
|
1557
|
+
2,
|
|
1558
|
+
"open"
|
|
1559
|
+
],
|
|
1560
|
+
[
|
|
1561
|
+
asyncmux,
|
|
1562
|
+
2,
|
|
1563
|
+
"close"
|
|
1564
|
+
],
|
|
1565
|
+
[
|
|
1566
|
+
asyncmux,
|
|
1567
|
+
2,
|
|
1568
|
+
"retryClose"
|
|
1569
|
+
]
|
|
1570
|
+
]).e;
|
|
1571
|
+
//#endregion
|
|
1572
|
+
//#region ../src/_unikvs-branch.ts
|
|
1510
1573
|
/**
|
|
1511
|
-
*
|
|
1574
|
+
* インスタンスと内部状態の対応表です。
|
|
1575
|
+
* コンパイラーによる `#` フィールドのダウンレベルと同様に、`WeakMap` をブランド兼ストレージとして使います。
|
|
1512
1576
|
*/
|
|
1513
|
-
|
|
1577
|
+
const branchStates = /* #__PURE__ */ new WeakMap();
|
|
1514
1578
|
/**
|
|
1515
|
-
*
|
|
1579
|
+
* 分岐先を親の接頭辞付きで追加します。
|
|
1580
|
+
*
|
|
1581
|
+
* `new Branch()` で作成された分岐以外の値が渡されたときは例外を投げます。
|
|
1582
|
+
* 外部からは使用しません。
|
|
1583
|
+
*
|
|
1584
|
+
* @param destinations 追加先の分岐先列です。
|
|
1585
|
+
* @param prefix 親のミドルウェア列です。
|
|
1586
|
+
* @param branch 追加する分岐です。
|
|
1587
|
+
*
|
|
1588
|
+
* @throws 分岐がストレージに到達しない場合に `InvalidForkError` を投げます。
|
|
1516
1589
|
*/
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1590
|
+
function appendForkDestinations(destinations, prefix, branch) {
|
|
1591
|
+
const state = branchStates.get(branch);
|
|
1592
|
+
if (!state) throw new TypeError("fork() expects a branch created by new Branch().");
|
|
1593
|
+
if (state.destinations.length === 0) throw new InvalidForkError();
|
|
1594
|
+
const prefixSnapshot = [...prefix];
|
|
1595
|
+
for (const dest of state.destinations) destinations.push({
|
|
1596
|
+
storage: dest.storage,
|
|
1597
|
+
middlewares: [...prefixSnapshot, ...dest.middlewares]
|
|
1598
|
+
});
|
|
1599
|
+
}
|
|
1600
|
+
//#endregion
|
|
1601
|
+
//#region ../src/unikvs-branch.ts
|
|
1602
|
+
var _UniKvsBranch_brand = /* @__PURE__ */ new WeakSet();
|
|
1530
1603
|
/**
|
|
1531
|
-
*
|
|
1604
|
+
* [API Reference](https://tai-kun.github.io/unikvs/packages/unikvs#builder)
|
|
1532
1605
|
*/
|
|
1533
|
-
var
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1606
|
+
var UniKvsBranch = class {
|
|
1607
|
+
constructor() {
|
|
1608
|
+
_classPrivateMethodInitSpec(this, _UniKvsBranch_brand);
|
|
1609
|
+
branchStates.set(this, {
|
|
1610
|
+
middlewares: [],
|
|
1611
|
+
destinations: []
|
|
1612
|
+
});
|
|
1613
|
+
}
|
|
1614
|
+
fork(branch) {
|
|
1615
|
+
const state = _assertClassBrand(_UniKvsBranch_brand, this, _branchState).call(this);
|
|
1616
|
+
appendForkDestinations(state.destinations, state.middlewares, branch);
|
|
1617
|
+
return this;
|
|
1618
|
+
}
|
|
1619
|
+
use(middleware) {
|
|
1620
|
+
_assertClassBrand(_UniKvsBranch_brand, this, _branchState).call(this).middlewares.push(UniKvsMiddleware.from(middleware));
|
|
1621
|
+
return this;
|
|
1622
|
+
}
|
|
1623
|
+
persist(storage) {
|
|
1624
|
+
const state = _assertClassBrand(_UniKvsBranch_brand, this, _branchState).call(this);
|
|
1625
|
+
state.destinations.push({
|
|
1626
|
+
storage: UniKvsStorage.from(storage),
|
|
1627
|
+
middlewares: [...state.middlewares]
|
|
1543
1628
|
});
|
|
1629
|
+
return this;
|
|
1544
1630
|
}
|
|
1545
1631
|
};
|
|
1632
|
+
/**
|
|
1633
|
+
* この分岐の構築状態を取得します。
|
|
1634
|
+
*
|
|
1635
|
+
* @returns 構築状態を返します。
|
|
1636
|
+
*/
|
|
1637
|
+
function _branchState() {
|
|
1638
|
+
const state = branchStates.get(this);
|
|
1639
|
+
if (state === void 0) throw new Error("分岐の構築状態が見つかりません。");
|
|
1640
|
+
return state;
|
|
1641
|
+
}
|
|
1546
1642
|
//#endregion
|
|
1547
1643
|
//#region ../src/_logger.ts
|
|
1548
1644
|
const logger = getLogger("unikvs");
|
|
@@ -2579,6 +2675,36 @@ const DeleteArgsSchema = union([tuple([DeleteOptionsSchema]), pipe(tuple([Delete
|
|
|
2579
2675
|
...options,
|
|
2580
2676
|
key
|
|
2581
2677
|
}]))]);
|
|
2678
|
+
const CopyOptionsSchema = object({
|
|
2679
|
+
key: string(),
|
|
2680
|
+
vars: optional(VariablesInitSchema),
|
|
2681
|
+
signal: optional(instance(AbortSignal)),
|
|
2682
|
+
destinationKey: string()
|
|
2683
|
+
});
|
|
2684
|
+
const CopyArgsSchema = union([tuple([CopyOptionsSchema]), pipe(tuple([
|
|
2685
|
+
CopyOptionsSchema.entries.key,
|
|
2686
|
+
CopyOptionsSchema.entries.destinationKey,
|
|
2687
|
+
optional(omit(CopyOptionsSchema, ["key", "destinationKey"]))
|
|
2688
|
+
]), transform(([key, destinationKey, options]) => [{
|
|
2689
|
+
...options,
|
|
2690
|
+
key,
|
|
2691
|
+
destinationKey
|
|
2692
|
+
}]))]);
|
|
2693
|
+
const MoveOptionsSchema = object({
|
|
2694
|
+
key: string(),
|
|
2695
|
+
vars: optional(VariablesInitSchema),
|
|
2696
|
+
signal: optional(instance(AbortSignal)),
|
|
2697
|
+
destinationKey: string()
|
|
2698
|
+
});
|
|
2699
|
+
const MoveArgsSchema = union([tuple([MoveOptionsSchema]), pipe(tuple([
|
|
2700
|
+
MoveOptionsSchema.entries.key,
|
|
2701
|
+
MoveOptionsSchema.entries.destinationKey,
|
|
2702
|
+
optional(omit(MoveOptionsSchema, ["key", "destinationKey"]))
|
|
2703
|
+
]), transform(([key, destinationKey, options]) => [{
|
|
2704
|
+
...options,
|
|
2705
|
+
key,
|
|
2706
|
+
destinationKey
|
|
2707
|
+
}]))]);
|
|
2582
2708
|
const ClearOptionsSchema = object({
|
|
2583
2709
|
/**
|
|
2584
2710
|
* 処理の中断を通知するためのシグナルです。
|
|
@@ -3501,6 +3627,14 @@ var UniKvs = class {
|
|
|
3501
3627
|
_usingCtx8.d();
|
|
3502
3628
|
}
|
|
3503
3629
|
}
|
|
3630
|
+
async copy(...args) {
|
|
3631
|
+
const [options] = parseInput(CopyArgsSchema, args);
|
|
3632
|
+
await _assertClassBrand(_UniKvs_brand, this, _transfer).call(this, "copy", options);
|
|
3633
|
+
}
|
|
3634
|
+
async move(...args) {
|
|
3635
|
+
const [options] = parseInput(MoveArgsSchema, args);
|
|
3636
|
+
await _assertClassBrand(_UniKvs_brand, this, _transfer).call(this, "move", options);
|
|
3637
|
+
}
|
|
3504
3638
|
async clear(...args) {
|
|
3505
3639
|
try {
|
|
3506
3640
|
var _usingCtx9 = _usingCtx();
|
|
@@ -3548,6 +3682,139 @@ var UniKvs = class {
|
|
|
3548
3682
|
}
|
|
3549
3683
|
};
|
|
3550
3684
|
/**
|
|
3685
|
+
* コピーまたは移動を実行します。
|
|
3686
|
+
*
|
|
3687
|
+
* @param action 実行する操作です。
|
|
3688
|
+
* @param options コピー元・移動元とコピー先・移動先のキーを持つオプションです。
|
|
3689
|
+
*
|
|
3690
|
+
* @returns 操作が完了したら解決します。
|
|
3691
|
+
*/
|
|
3692
|
+
async function _transfer(action, options) {
|
|
3693
|
+
try {
|
|
3694
|
+
var _usingCtx10 = _usingCtx();
|
|
3695
|
+
if (_classPrivateFieldGet2(_con, this) === null) throw new UniKvsIsNotOpenError();
|
|
3696
|
+
const { key, destinationKey } = options;
|
|
3697
|
+
_assertClassBrand(_UniKvs_brand, this, _resolveValueSchema).call(this, key);
|
|
3698
|
+
_assertClassBrand(_UniKvs_brand, this, _resolveValueSchema).call(this, destinationKey);
|
|
3699
|
+
const { ac, io } = _classPrivateFieldGet2(_con, this);
|
|
3700
|
+
const signal = combineSignals([ac.signal, options.signal]);
|
|
3701
|
+
const store = _assertClassBrand(_UniKvs_brand, this, _createOperationStore).call(this, options.vars);
|
|
3702
|
+
_usingCtx10.u(await asyncmux.readonly(this, signal));
|
|
3703
|
+
if (_classPrivateFieldGet2(_con, this) === null) throw new UniKvsIsNotOpenError();
|
|
3704
|
+
const useContext = action === "copy" ? new CopyContext({
|
|
3705
|
+
key,
|
|
3706
|
+
store,
|
|
3707
|
+
signal,
|
|
3708
|
+
destinationKey
|
|
3709
|
+
}) : new MoveContext({
|
|
3710
|
+
key,
|
|
3711
|
+
store,
|
|
3712
|
+
signal,
|
|
3713
|
+
destinationKey
|
|
3714
|
+
});
|
|
3715
|
+
await _assertClassBrand(_UniKvs_brand, this, _use).call(this, action, useContext);
|
|
3716
|
+
throwIfAborted(signal);
|
|
3717
|
+
const sourceResolver = _classPrivateFieldGet2(_pipeline, this).createResolver({
|
|
3718
|
+
key,
|
|
3719
|
+
store,
|
|
3720
|
+
signal
|
|
3721
|
+
});
|
|
3722
|
+
const destinationResolver = key === destinationKey ? sourceResolver : _classPrivateFieldGet2(_pipeline, this).createResolver({
|
|
3723
|
+
key: destinationKey,
|
|
3724
|
+
store,
|
|
3725
|
+
signal
|
|
3726
|
+
});
|
|
3727
|
+
if (key === destinationKey) try {
|
|
3728
|
+
var _usingCtx11 = _usingCtx();
|
|
3729
|
+
_usingCtx11.u(await io.lock({
|
|
3730
|
+
key,
|
|
3731
|
+
signal
|
|
3732
|
+
}));
|
|
3733
|
+
await _assertClassBrand(_UniKvs_brand, this, _transferLeaves).call(this, action, key, store, signal, sourceResolver, destinationResolver);
|
|
3734
|
+
return;
|
|
3735
|
+
} catch (_) {
|
|
3736
|
+
_usingCtx11.e = _;
|
|
3737
|
+
} finally {
|
|
3738
|
+
_usingCtx11.d();
|
|
3739
|
+
}
|
|
3740
|
+
const firstLockKey = key < destinationKey ? key : destinationKey;
|
|
3741
|
+
const secondLockKey = key < destinationKey ? destinationKey : key;
|
|
3742
|
+
_usingCtx10.u(await io.lock({
|
|
3743
|
+
key: firstLockKey,
|
|
3744
|
+
signal
|
|
3745
|
+
}));
|
|
3746
|
+
_usingCtx10.u(await io.lock({
|
|
3747
|
+
key: secondLockKey,
|
|
3748
|
+
signal
|
|
3749
|
+
}));
|
|
3750
|
+
await _assertClassBrand(_UniKvs_brand, this, _transferLeaves).call(this, action, key, store, signal, sourceResolver, destinationResolver);
|
|
3751
|
+
} catch (_) {
|
|
3752
|
+
_usingCtx10.e = _;
|
|
3753
|
+
} finally {
|
|
3754
|
+
_usingCtx10.d();
|
|
3755
|
+
}
|
|
3756
|
+
}
|
|
3757
|
+
/**
|
|
3758
|
+
* 各ストレージへコピーまたは移動を適用します。
|
|
3759
|
+
*
|
|
3760
|
+
* @param action 実行する操作です。
|
|
3761
|
+
* @param key コピー元または移動元の論理キーです。
|
|
3762
|
+
* @param store 操作内で共有される変数ストアです。
|
|
3763
|
+
* @param signal 中断シグナルです。
|
|
3764
|
+
* @param sourceResolver コピー元・移動元のキーを解決するリゾルバーです。
|
|
3765
|
+
* @param destinationResolver コピー先・移動先のキーを解決するリゾルバーです。
|
|
3766
|
+
*
|
|
3767
|
+
* @returns 操作が完了したら解決します。
|
|
3768
|
+
*/
|
|
3769
|
+
async function _transferLeaves(action, key, store, signal, sourceResolver, destinationResolver) {
|
|
3770
|
+
const errors = [];
|
|
3771
|
+
let found = 0;
|
|
3772
|
+
await Promise.all(_classPrivateFieldGet2(_pipeline, this).leaves.map(async (leaf) => {
|
|
3773
|
+
const sourceKey = sourceResolver.resolve(leaf).key;
|
|
3774
|
+
const destinationKey = destinationResolver.resolve(leaf).key;
|
|
3775
|
+
try {
|
|
3776
|
+
const existsContext = new HasContext({
|
|
3777
|
+
key: sourceKey,
|
|
3778
|
+
store,
|
|
3779
|
+
signal
|
|
3780
|
+
});
|
|
3781
|
+
if (!await leaf.storage.exists(existsContext)) return;
|
|
3782
|
+
found += 1;
|
|
3783
|
+
if (action === "copy") {
|
|
3784
|
+
const c = new CopyContext({
|
|
3785
|
+
key: sourceKey,
|
|
3786
|
+
store,
|
|
3787
|
+
signal,
|
|
3788
|
+
destinationKey
|
|
3789
|
+
});
|
|
3790
|
+
await leaf.storage.copy(c);
|
|
3791
|
+
} else {
|
|
3792
|
+
const c = new MoveContext({
|
|
3793
|
+
key: sourceKey,
|
|
3794
|
+
store,
|
|
3795
|
+
signal,
|
|
3796
|
+
destinationKey
|
|
3797
|
+
});
|
|
3798
|
+
await leaf.storage.move(c);
|
|
3799
|
+
}
|
|
3800
|
+
} catch (ex) {
|
|
3801
|
+
if (signal.aborted) throw ex;
|
|
3802
|
+
errors.push({
|
|
3803
|
+
name: leaf.name,
|
|
3804
|
+
index: leaf.index,
|
|
3805
|
+
reason: ex
|
|
3806
|
+
});
|
|
3807
|
+
logger.error`Failed to ${action} in a storage: ${ex}`;
|
|
3808
|
+
}
|
|
3809
|
+
}));
|
|
3810
|
+
if (found === 0) throw _assertClassBrand(_UniKvs_brand, this, _notFound).call(this, key, errors, action);
|
|
3811
|
+
if (errors.length > 0) throw new PluginOperationAggregateError({
|
|
3812
|
+
action,
|
|
3813
|
+
errors,
|
|
3814
|
+
plugin: "storage"
|
|
3815
|
+
});
|
|
3816
|
+
}
|
|
3817
|
+
/**
|
|
3551
3818
|
* 基本変数と操作固有変数を結合した実行時変数マップを作成します。
|
|
3552
3819
|
*
|
|
3553
3820
|
* @param vars 操作固有の変数です。
|
|
@@ -3586,10 +3853,11 @@ function _resolveValueSchema(key) {
|
|
|
3586
3853
|
*
|
|
3587
3854
|
* @param key 読み取ったキーです。
|
|
3588
3855
|
* @param errors 収集した失敗です。
|
|
3856
|
+
* @param action 失敗を集約する操作です。
|
|
3589
3857
|
*
|
|
3590
3858
|
* @returns `KeyNotFoundError` を返します。
|
|
3591
3859
|
*/
|
|
3592
|
-
function _notFound(key, errors) {
|
|
3860
|
+
function _notFound(key, errors, action = "read") {
|
|
3593
3861
|
const args = { key };
|
|
3594
3862
|
switch (errors.length) {
|
|
3595
3863
|
case 0: break;
|
|
@@ -3599,7 +3867,7 @@ function _notFound(key, errors) {
|
|
|
3599
3867
|
break;
|
|
3600
3868
|
}
|
|
3601
3869
|
default: args.cause = new PluginOperationAggregateError({
|
|
3602
|
-
action
|
|
3870
|
+
action,
|
|
3603
3871
|
errors,
|
|
3604
3872
|
plugin: "storage"
|
|
3605
3873
|
});
|
|
@@ -3608,11 +3876,11 @@ function _notFound(key, errors) {
|
|
|
3608
3876
|
}
|
|
3609
3877
|
async function _close(operationVars, signal, con, progress) {
|
|
3610
3878
|
try {
|
|
3611
|
-
var
|
|
3612
|
-
|
|
3879
|
+
var _usingCtx12 = _usingCtx();
|
|
3880
|
+
_usingCtx12.u(await asyncmux(this, signal));
|
|
3613
3881
|
if (_classPrivateFieldGet2(_con, this) !== con) throw new UniKvsIsNotOpenError();
|
|
3614
3882
|
const { io } = _classPrivateFieldGet2(_con, this);
|
|
3615
|
-
|
|
3883
|
+
_usingCtx12.u(await io.lock({ signal }));
|
|
3616
3884
|
const closeFns = [];
|
|
3617
3885
|
for (const [index, leaf] of _classPrivateFieldGet2(_pipeline, this).leaves.entries()) {
|
|
3618
3886
|
const createContext = () => new CloseContext({
|
|
@@ -3679,9 +3947,9 @@ async function _close(operationVars, signal, con, progress) {
|
|
|
3679
3947
|
}
|
|
3680
3948
|
_classPrivateFieldSet2(_con, this, null);
|
|
3681
3949
|
} catch (_) {
|
|
3682
|
-
|
|
3950
|
+
_usingCtx12.e = _;
|
|
3683
3951
|
} finally {
|
|
3684
|
-
|
|
3952
|
+
_usingCtx12.d();
|
|
3685
3953
|
}
|
|
3686
3954
|
}
|
|
3687
3955
|
/**
|
|
@@ -3801,13 +4069,13 @@ async function _use(action, c) {
|
|
|
3801
4069
|
*/
|
|
3802
4070
|
async function _setPlain(io, signal, key, store, value) {
|
|
3803
4071
|
try {
|
|
3804
|
-
var
|
|
4072
|
+
var _usingCtx13 = _usingCtx();
|
|
3805
4073
|
const targets = await _classPrivateFieldGet2(_pipeline, this).encode({
|
|
3806
4074
|
key,
|
|
3807
4075
|
store,
|
|
3808
4076
|
signal
|
|
3809
4077
|
}, value);
|
|
3810
|
-
|
|
4078
|
+
_usingCtx13.u(await io.lock({
|
|
3811
4079
|
key,
|
|
3812
4080
|
signal
|
|
3813
4081
|
}));
|
|
@@ -3832,9 +4100,9 @@ async function _setPlain(io, signal, key, store, value) {
|
|
|
3832
4100
|
}));
|
|
3833
4101
|
await _assertClassBrand(_UniKvs_brand, this, _finishWrites).call(this, targets, store, failed, errors, signal);
|
|
3834
4102
|
} catch (_) {
|
|
3835
|
-
|
|
4103
|
+
_usingCtx13.e = _;
|
|
3836
4104
|
} finally {
|
|
3837
|
-
|
|
4105
|
+
_usingCtx13.d();
|
|
3838
4106
|
}
|
|
3839
4107
|
}
|
|
3840
4108
|
/**
|
|
@@ -3848,7 +4116,7 @@ async function _setPlain(io, signal, key, store, value) {
|
|
|
3848
4116
|
*/
|
|
3849
4117
|
async function _setStream(io, signal, key, store, value) {
|
|
3850
4118
|
try {
|
|
3851
|
-
var
|
|
4119
|
+
var _usingCtx14 = _usingCtx();
|
|
3852
4120
|
const streams = /* @__PURE__ */ new Set([value]);
|
|
3853
4121
|
let tree;
|
|
3854
4122
|
try {
|
|
@@ -3861,7 +4129,7 @@ async function _setStream(io, signal, key, store, value) {
|
|
|
3861
4129
|
await cancelStreams(streams, ex);
|
|
3862
4130
|
throw ex;
|
|
3863
4131
|
}
|
|
3864
|
-
|
|
4132
|
+
_usingCtx14.u(await io.lock({
|
|
3865
4133
|
key,
|
|
3866
4134
|
signal
|
|
3867
4135
|
}).catch(async (ex) => {
|
|
@@ -3893,9 +4161,9 @@ async function _setStream(io, signal, key, store, value) {
|
|
|
3893
4161
|
}));
|
|
3894
4162
|
await _assertClassBrand(_UniKvs_brand, this, _finishWrites).call(this, tree.targets, store, failed, errors, signal);
|
|
3895
4163
|
} catch (_) {
|
|
3896
|
-
|
|
4164
|
+
_usingCtx14.e = _;
|
|
3897
4165
|
} finally {
|
|
3898
|
-
|
|
4166
|
+
_usingCtx14.d();
|
|
3899
4167
|
}
|
|
3900
4168
|
}
|
|
3901
4169
|
/**
|