@cmdless/ui-runtime 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -12
- package/out/main/bin.js +24 -41
- package/out/main/cleanup.js +20 -0
- package/out/main/host.js +79 -0
- package/out/main/hosting.js +448 -0
- package/out/{main/index.js → preload/index.cjs} +1522 -290
- package/out/renderer/assets/Card-BUDQ1UVY.js +15054 -0
- package/out/renderer/assets/Form-B5fhb-x2.css +1121 -0
- package/out/renderer/assets/Form-CE3B5mnl.js +26 -0
- package/out/renderer/assets/Mantine.context-oJEjRkJu.js +574 -0
- package/out/renderer/assets/MantineThemeProvider-DHX5fzKn.js +995 -0
- package/out/renderer/assets/SchemaInput-CACjraGT.js +69 -0
- package/out/renderer/assets/preload-helper-DVzrZ_Op.js +64 -0
- package/out/renderer/assets/use-media-query-d0EeyoH9.js +34 -0
- package/out/renderer/assets/validator-_xTzn1fv.js +31760 -0
- package/out/renderer/assets/view-Chm2p5Ws.js +20542 -0
- package/out/renderer/assets/view-DptMSuIE.css +10034 -0
- package/out/renderer/view.html +21 -0
- package/package.json +23 -6
- package/out/preload/index.mjs +0 -6
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { Command, Argument } from "commander";
|
|
6
|
-
import { types, cmdlessIPC, createElectronIPC } from "@cmdless/ui-sdk";
|
|
7
|
-
import { BinChannel, CmdlessEnv, getEphemeralPrefix, MessageSocketWaiter, CmdlessUI, binOutput, runAsMcp } from "@cmdless/ui-sdk/node";
|
|
8
|
-
import __cjs_mod__ from "node:module";
|
|
9
|
-
const __filename = import.meta.filename;
|
|
10
|
-
const __dirname = import.meta.dirname;
|
|
11
|
-
const require2 = __cjs_mod__.createRequire(import.meta.url);
|
|
1
|
+
"use strict";
|
|
2
|
+
const electron = require("electron");
|
|
3
|
+
var main = {};
|
|
4
|
+
var ril = {};
|
|
12
5
|
var api = {};
|
|
13
6
|
var messages = {};
|
|
14
7
|
var is = {};
|
|
@@ -555,7 +548,7 @@ function requireLinkedMap() {
|
|
|
555
548
|
return item.value;
|
|
556
549
|
}
|
|
557
550
|
forEach(callbackfn, thisArg) {
|
|
558
|
-
const
|
|
551
|
+
const state2 = this._state;
|
|
559
552
|
let current = this._head;
|
|
560
553
|
while (current) {
|
|
561
554
|
if (thisArg) {
|
|
@@ -563,21 +556,21 @@ function requireLinkedMap() {
|
|
|
563
556
|
} else {
|
|
564
557
|
callbackfn(current.value, current.key, this);
|
|
565
558
|
}
|
|
566
|
-
if (this._state !==
|
|
559
|
+
if (this._state !== state2) {
|
|
567
560
|
throw new Error(`LinkedMap got modified during iteration.`);
|
|
568
561
|
}
|
|
569
562
|
current = current.next;
|
|
570
563
|
}
|
|
571
564
|
}
|
|
572
565
|
keys() {
|
|
573
|
-
const
|
|
566
|
+
const state2 = this._state;
|
|
574
567
|
let current = this._head;
|
|
575
568
|
const iterator = {
|
|
576
569
|
[Symbol.iterator]: () => {
|
|
577
570
|
return iterator;
|
|
578
571
|
},
|
|
579
572
|
next: () => {
|
|
580
|
-
if (this._state !==
|
|
573
|
+
if (this._state !== state2) {
|
|
581
574
|
throw new Error(`LinkedMap got modified during iteration.`);
|
|
582
575
|
}
|
|
583
576
|
if (current) {
|
|
@@ -592,14 +585,14 @@ function requireLinkedMap() {
|
|
|
592
585
|
return iterator;
|
|
593
586
|
}
|
|
594
587
|
values() {
|
|
595
|
-
const
|
|
588
|
+
const state2 = this._state;
|
|
596
589
|
let current = this._head;
|
|
597
590
|
const iterator = {
|
|
598
591
|
[Symbol.iterator]: () => {
|
|
599
592
|
return iterator;
|
|
600
593
|
},
|
|
601
594
|
next: () => {
|
|
602
|
-
if (this._state !==
|
|
595
|
+
if (this._state !== state2) {
|
|
603
596
|
throw new Error(`LinkedMap got modified during iteration.`);
|
|
604
597
|
}
|
|
605
598
|
if (current) {
|
|
@@ -614,14 +607,14 @@ function requireLinkedMap() {
|
|
|
614
607
|
return iterator;
|
|
615
608
|
}
|
|
616
609
|
entries() {
|
|
617
|
-
const
|
|
610
|
+
const state2 = this._state;
|
|
618
611
|
let current = this._head;
|
|
619
612
|
const iterator = {
|
|
620
613
|
[Symbol.iterator]: () => {
|
|
621
614
|
return iterator;
|
|
622
615
|
},
|
|
623
616
|
next: () => {
|
|
624
|
-
if (this._state !==
|
|
617
|
+
if (this._state !== state2) {
|
|
625
618
|
throw new Error(`LinkedMap got modified during iteration.`);
|
|
626
619
|
}
|
|
627
620
|
if (current) {
|
|
@@ -1062,9 +1055,9 @@ function requireCancellation() {
|
|
|
1062
1055
|
CancellationToken2.is = is2;
|
|
1063
1056
|
})(CancellationToken || (cancellation.CancellationToken = CancellationToken = {}));
|
|
1064
1057
|
const shortcutEvent = Object.freeze(function(callback, context) {
|
|
1065
|
-
const
|
|
1058
|
+
const handle = (0, ral_1.default)().timer.setTimeout(callback.bind(context), 0);
|
|
1066
1059
|
return { dispose() {
|
|
1067
|
-
|
|
1060
|
+
handle.dispose();
|
|
1068
1061
|
} };
|
|
1069
1062
|
});
|
|
1070
1063
|
class MutableToken {
|
|
@@ -1142,15 +1135,15 @@ function requireSharedArrayCancellation() {
|
|
|
1142
1135
|
constructor() {
|
|
1143
1136
|
this.buffers = /* @__PURE__ */ new Map();
|
|
1144
1137
|
}
|
|
1145
|
-
enableCancellation(
|
|
1146
|
-
if (
|
|
1138
|
+
enableCancellation(request2) {
|
|
1139
|
+
if (request2.id === null) {
|
|
1147
1140
|
return;
|
|
1148
1141
|
}
|
|
1149
1142
|
const buffer = new SharedArrayBuffer(4);
|
|
1150
1143
|
const data = new Int32Array(buffer, 0, 1);
|
|
1151
1144
|
data[0] = CancellationState.Continue;
|
|
1152
|
-
this.buffers.set(
|
|
1153
|
-
|
|
1145
|
+
this.buffers.set(request2.id, buffer);
|
|
1146
|
+
request2.$cancellationData = buffer;
|
|
1154
1147
|
}
|
|
1155
1148
|
async sendCancellation(_conn, id) {
|
|
1156
1149
|
const buffer = this.buffers.get(id);
|
|
@@ -1192,8 +1185,8 @@ function requireSharedArrayCancellation() {
|
|
|
1192
1185
|
}
|
|
1193
1186
|
class SharedArrayReceiverStrategy {
|
|
1194
1187
|
kind = "request";
|
|
1195
|
-
createCancellationTokenSource(
|
|
1196
|
-
const buffer =
|
|
1188
|
+
createCancellationTokenSource(request2) {
|
|
1189
|
+
const buffer = request2.$cancellationData;
|
|
1197
1190
|
if (buffer === void 0) {
|
|
1198
1191
|
return new cancellation_1.CancellationTokenSource();
|
|
1199
1192
|
}
|
|
@@ -1228,8 +1221,8 @@ function requireSemaphore() {
|
|
|
1228
1221
|
this._waiting = [];
|
|
1229
1222
|
}
|
|
1230
1223
|
lock(thunk) {
|
|
1231
|
-
return new Promise((
|
|
1232
|
-
this._waiting.push({ thunk, resolve
|
|
1224
|
+
return new Promise((resolve, reject) => {
|
|
1225
|
+
this._waiting.push({ thunk, resolve, reject });
|
|
1233
1226
|
this.runNext();
|
|
1234
1227
|
});
|
|
1235
1228
|
}
|
|
@@ -1707,7 +1700,7 @@ function requireMessageBuffer() {
|
|
|
1707
1700
|
if (this._chunks.length === 0) {
|
|
1708
1701
|
return void 0;
|
|
1709
1702
|
}
|
|
1710
|
-
let
|
|
1703
|
+
let state2 = 0;
|
|
1711
1704
|
let chunkIndex = 0;
|
|
1712
1705
|
let offset = 0;
|
|
1713
1706
|
let chunkBytesRead = 0;
|
|
@@ -1718,39 +1711,39 @@ function requireMessageBuffer() {
|
|
|
1718
1711
|
const value = chunk[offset];
|
|
1719
1712
|
switch (value) {
|
|
1720
1713
|
case CR:
|
|
1721
|
-
switch (
|
|
1714
|
+
switch (state2) {
|
|
1722
1715
|
case 0:
|
|
1723
|
-
|
|
1716
|
+
state2 = 1;
|
|
1724
1717
|
break;
|
|
1725
1718
|
case 2:
|
|
1726
|
-
|
|
1719
|
+
state2 = 3;
|
|
1727
1720
|
break;
|
|
1728
1721
|
default:
|
|
1729
|
-
|
|
1722
|
+
state2 = 0;
|
|
1730
1723
|
}
|
|
1731
1724
|
break;
|
|
1732
1725
|
case LF:
|
|
1733
|
-
switch (
|
|
1726
|
+
switch (state2) {
|
|
1734
1727
|
case 1:
|
|
1735
|
-
|
|
1728
|
+
state2 = 2;
|
|
1736
1729
|
break;
|
|
1737
1730
|
case 3:
|
|
1738
|
-
|
|
1731
|
+
state2 = 4;
|
|
1739
1732
|
offset++;
|
|
1740
1733
|
break row;
|
|
1741
1734
|
default:
|
|
1742
|
-
|
|
1735
|
+
state2 = 0;
|
|
1743
1736
|
}
|
|
1744
1737
|
break;
|
|
1745
1738
|
default:
|
|
1746
|
-
|
|
1739
|
+
state2 = 0;
|
|
1747
1740
|
}
|
|
1748
1741
|
offset++;
|
|
1749
1742
|
}
|
|
1750
1743
|
chunkBytesRead += chunk.byteLength;
|
|
1751
1744
|
chunkIndex++;
|
|
1752
1745
|
}
|
|
1753
|
-
if (
|
|
1746
|
+
if (state2 !== 4) {
|
|
1754
1747
|
return void 0;
|
|
1755
1748
|
}
|
|
1756
1749
|
const buffer = this._read(chunkBytesRead + offset);
|
|
@@ -1832,7 +1825,7 @@ var hasRequiredConnection;
|
|
|
1832
1825
|
function requireConnection() {
|
|
1833
1826
|
if (hasRequiredConnection) return connection;
|
|
1834
1827
|
hasRequiredConnection = 1;
|
|
1835
|
-
(function(
|
|
1828
|
+
(function(exports2) {
|
|
1836
1829
|
var __createBinding = connection && connection.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
1837
1830
|
if (k2 === void 0) k2 = k;
|
|
1838
1831
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -1873,9 +1866,9 @@ function requireConnection() {
|
|
|
1873
1866
|
var __importDefault = connection && connection.__importDefault || function(mod) {
|
|
1874
1867
|
return mod && mod.__esModule ? mod : { "default": mod };
|
|
1875
1868
|
};
|
|
1876
|
-
Object.defineProperty(
|
|
1877
|
-
|
|
1878
|
-
|
|
1869
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
1870
|
+
exports2.ConnectionOptions = exports2.MessageStrategy = exports2.CancellationStrategy = exports2.CancellationSenderStrategy = exports2.CancellationReceiverStrategy = exports2.RequestCancellationReceiverStrategy = exports2.IdCancellationReceiverStrategy = exports2.ConnectionStrategy = exports2.ConnectionError = exports2.ConnectionErrors = exports2.LogTraceNotification = exports2.SetTraceNotification = exports2.TraceFormat = exports2.TraceValues = exports2.TraceValue = exports2.Trace = exports2.NullLogger = exports2.ProgressType = exports2.ProgressToken = void 0;
|
|
1871
|
+
exports2.createMessageConnection = createMessageConnection;
|
|
1879
1872
|
const ral_1 = __importDefault(requireRal());
|
|
1880
1873
|
const Is = __importStar(requireIs());
|
|
1881
1874
|
const messages_1 = requireMessages();
|
|
@@ -1892,7 +1885,7 @@ function requireConnection() {
|
|
|
1892
1885
|
return typeof value === "string" || typeof value === "number";
|
|
1893
1886
|
}
|
|
1894
1887
|
ProgressToken2.is = is2;
|
|
1895
|
-
})(ProgressToken || (
|
|
1888
|
+
})(ProgressToken || (exports2.ProgressToken = ProgressToken = {}));
|
|
1896
1889
|
var ProgressNotification;
|
|
1897
1890
|
(function(ProgressNotification2) {
|
|
1898
1891
|
ProgressNotification2.type = new messages_1.NotificationType("$/progress");
|
|
@@ -1907,7 +1900,7 @@ function requireConnection() {
|
|
|
1907
1900
|
constructor() {
|
|
1908
1901
|
}
|
|
1909
1902
|
}
|
|
1910
|
-
|
|
1903
|
+
exports2.ProgressType = ProgressType;
|
|
1911
1904
|
var StarRequestHandler;
|
|
1912
1905
|
(function(StarRequestHandler2) {
|
|
1913
1906
|
function is2(value) {
|
|
@@ -1915,7 +1908,7 @@ function requireConnection() {
|
|
|
1915
1908
|
}
|
|
1916
1909
|
StarRequestHandler2.is = is2;
|
|
1917
1910
|
})(StarRequestHandler || (StarRequestHandler = {}));
|
|
1918
|
-
|
|
1911
|
+
exports2.NullLogger = Object.freeze({
|
|
1919
1912
|
error: () => {
|
|
1920
1913
|
},
|
|
1921
1914
|
warn: () => {
|
|
@@ -1931,15 +1924,15 @@ function requireConnection() {
|
|
|
1931
1924
|
Trace2[Trace2["Messages"] = 1] = "Messages";
|
|
1932
1925
|
Trace2[Trace2["Compact"] = 2] = "Compact";
|
|
1933
1926
|
Trace2[Trace2["Verbose"] = 3] = "Verbose";
|
|
1934
|
-
})(Trace || (
|
|
1927
|
+
})(Trace || (exports2.Trace = Trace = {}));
|
|
1935
1928
|
var TraceValue;
|
|
1936
1929
|
(function(TraceValue2) {
|
|
1937
1930
|
TraceValue2.Off = "off";
|
|
1938
1931
|
TraceValue2.Messages = "messages";
|
|
1939
1932
|
TraceValue2.Compact = "compact";
|
|
1940
1933
|
TraceValue2.Verbose = "verbose";
|
|
1941
|
-
})(TraceValue || (
|
|
1942
|
-
|
|
1934
|
+
})(TraceValue || (exports2.TraceValue = TraceValue = {}));
|
|
1935
|
+
exports2.TraceValues = TraceValue;
|
|
1943
1936
|
(function(Trace2) {
|
|
1944
1937
|
function fromString(value) {
|
|
1945
1938
|
if (!Is.string(value)) {
|
|
@@ -1975,12 +1968,12 @@ function requireConnection() {
|
|
|
1975
1968
|
}
|
|
1976
1969
|
}
|
|
1977
1970
|
Trace2.toString = toString;
|
|
1978
|
-
})(Trace || (
|
|
1971
|
+
})(Trace || (exports2.Trace = Trace = {}));
|
|
1979
1972
|
var TraceFormat;
|
|
1980
1973
|
(function(TraceFormat2) {
|
|
1981
1974
|
TraceFormat2["Text"] = "text";
|
|
1982
1975
|
TraceFormat2["JSON"] = "json";
|
|
1983
|
-
})(TraceFormat || (
|
|
1976
|
+
})(TraceFormat || (exports2.TraceFormat = TraceFormat = {}));
|
|
1984
1977
|
(function(TraceFormat2) {
|
|
1985
1978
|
function fromString(value) {
|
|
1986
1979
|
if (!Is.string(value)) {
|
|
@@ -1994,21 +1987,21 @@ function requireConnection() {
|
|
|
1994
1987
|
}
|
|
1995
1988
|
}
|
|
1996
1989
|
TraceFormat2.fromString = fromString;
|
|
1997
|
-
})(TraceFormat || (
|
|
1990
|
+
})(TraceFormat || (exports2.TraceFormat = TraceFormat = {}));
|
|
1998
1991
|
var SetTraceNotification;
|
|
1999
1992
|
(function(SetTraceNotification2) {
|
|
2000
1993
|
SetTraceNotification2.type = new messages_1.NotificationType("$/setTrace");
|
|
2001
|
-
})(SetTraceNotification || (
|
|
1994
|
+
})(SetTraceNotification || (exports2.SetTraceNotification = SetTraceNotification = {}));
|
|
2002
1995
|
var LogTraceNotification;
|
|
2003
1996
|
(function(LogTraceNotification2) {
|
|
2004
1997
|
LogTraceNotification2.type = new messages_1.NotificationType("$/logTrace");
|
|
2005
|
-
})(LogTraceNotification || (
|
|
1998
|
+
})(LogTraceNotification || (exports2.LogTraceNotification = LogTraceNotification = {}));
|
|
2006
1999
|
var ConnectionErrors;
|
|
2007
2000
|
(function(ConnectionErrors2) {
|
|
2008
2001
|
ConnectionErrors2[ConnectionErrors2["Closed"] = 1] = "Closed";
|
|
2009
2002
|
ConnectionErrors2[ConnectionErrors2["Disposed"] = 2] = "Disposed";
|
|
2010
2003
|
ConnectionErrors2[ConnectionErrors2["AlreadyListening"] = 3] = "AlreadyListening";
|
|
2011
|
-
})(ConnectionErrors || (
|
|
2004
|
+
})(ConnectionErrors || (exports2.ConnectionErrors = ConnectionErrors = {}));
|
|
2012
2005
|
class ConnectionError extends Error {
|
|
2013
2006
|
code;
|
|
2014
2007
|
constructor(code, message) {
|
|
@@ -2017,7 +2010,7 @@ function requireConnection() {
|
|
|
2017
2010
|
Object.setPrototypeOf(this, ConnectionError.prototype);
|
|
2018
2011
|
}
|
|
2019
2012
|
}
|
|
2020
|
-
|
|
2013
|
+
exports2.ConnectionError = ConnectionError;
|
|
2021
2014
|
var ConnectionStrategy;
|
|
2022
2015
|
(function(ConnectionStrategy2) {
|
|
2023
2016
|
function is2(value) {
|
|
@@ -2025,7 +2018,7 @@ function requireConnection() {
|
|
|
2025
2018
|
return candidate && Is.func(candidate.cancelUndispatched);
|
|
2026
2019
|
}
|
|
2027
2020
|
ConnectionStrategy2.is = is2;
|
|
2028
|
-
})(ConnectionStrategy || (
|
|
2021
|
+
})(ConnectionStrategy || (exports2.ConnectionStrategy = ConnectionStrategy = {}));
|
|
2029
2022
|
var IdCancellationReceiverStrategy;
|
|
2030
2023
|
(function(IdCancellationReceiverStrategy2) {
|
|
2031
2024
|
function is2(value) {
|
|
@@ -2033,7 +2026,7 @@ function requireConnection() {
|
|
|
2033
2026
|
return candidate && (candidate.kind === void 0 || candidate.kind === "id") && Is.func(candidate.createCancellationTokenSource) && (candidate.dispose === void 0 || Is.func(candidate.dispose));
|
|
2034
2027
|
}
|
|
2035
2028
|
IdCancellationReceiverStrategy2.is = is2;
|
|
2036
|
-
})(IdCancellationReceiverStrategy || (
|
|
2029
|
+
})(IdCancellationReceiverStrategy || (exports2.IdCancellationReceiverStrategy = IdCancellationReceiverStrategy = {}));
|
|
2037
2030
|
var RequestCancellationReceiverStrategy;
|
|
2038
2031
|
(function(RequestCancellationReceiverStrategy2) {
|
|
2039
2032
|
function is2(value) {
|
|
@@ -2041,7 +2034,7 @@ function requireConnection() {
|
|
|
2041
2034
|
return candidate && candidate.kind === "request" && Is.func(candidate.createCancellationTokenSource) && (candidate.dispose === void 0 || Is.func(candidate.dispose));
|
|
2042
2035
|
}
|
|
2043
2036
|
RequestCancellationReceiverStrategy2.is = is2;
|
|
2044
|
-
})(RequestCancellationReceiverStrategy || (
|
|
2037
|
+
})(RequestCancellationReceiverStrategy || (exports2.RequestCancellationReceiverStrategy = RequestCancellationReceiverStrategy = {}));
|
|
2045
2038
|
var CancellationReceiverStrategy;
|
|
2046
2039
|
(function(CancellationReceiverStrategy2) {
|
|
2047
2040
|
CancellationReceiverStrategy2.Message = Object.freeze({
|
|
@@ -2053,7 +2046,7 @@ function requireConnection() {
|
|
|
2053
2046
|
return IdCancellationReceiverStrategy.is(value) || RequestCancellationReceiverStrategy.is(value);
|
|
2054
2047
|
}
|
|
2055
2048
|
CancellationReceiverStrategy2.is = is2;
|
|
2056
|
-
})(CancellationReceiverStrategy || (
|
|
2049
|
+
})(CancellationReceiverStrategy || (exports2.CancellationReceiverStrategy = CancellationReceiverStrategy = {}));
|
|
2057
2050
|
var CancellationSenderStrategy;
|
|
2058
2051
|
(function(CancellationSenderStrategy2) {
|
|
2059
2052
|
CancellationSenderStrategy2.Message = Object.freeze({
|
|
@@ -2068,7 +2061,7 @@ function requireConnection() {
|
|
|
2068
2061
|
return candidate && Is.func(candidate.sendCancellation) && Is.func(candidate.cleanup);
|
|
2069
2062
|
}
|
|
2070
2063
|
CancellationSenderStrategy2.is = is2;
|
|
2071
|
-
})(CancellationSenderStrategy || (
|
|
2064
|
+
})(CancellationSenderStrategy || (exports2.CancellationSenderStrategy = CancellationSenderStrategy = {}));
|
|
2072
2065
|
var CancellationStrategy;
|
|
2073
2066
|
(function(CancellationStrategy2) {
|
|
2074
2067
|
CancellationStrategy2.Message = Object.freeze({
|
|
@@ -2080,7 +2073,7 @@ function requireConnection() {
|
|
|
2080
2073
|
return candidate && CancellationReceiverStrategy.is(candidate.receiver) && CancellationSenderStrategy.is(candidate.sender);
|
|
2081
2074
|
}
|
|
2082
2075
|
CancellationStrategy2.is = is2;
|
|
2083
|
-
})(CancellationStrategy || (
|
|
2076
|
+
})(CancellationStrategy || (exports2.CancellationStrategy = CancellationStrategy = {}));
|
|
2084
2077
|
var MessageStrategy;
|
|
2085
2078
|
(function(MessageStrategy2) {
|
|
2086
2079
|
function is2(value) {
|
|
@@ -2088,7 +2081,7 @@ function requireConnection() {
|
|
|
2088
2081
|
return candidate && Is.func(candidate.handleMessage);
|
|
2089
2082
|
}
|
|
2090
2083
|
MessageStrategy2.is = is2;
|
|
2091
|
-
})(MessageStrategy || (
|
|
2084
|
+
})(MessageStrategy || (exports2.MessageStrategy = MessageStrategy = {}));
|
|
2092
2085
|
var ConnectionOptions;
|
|
2093
2086
|
(function(ConnectionOptions2) {
|
|
2094
2087
|
function is2(value) {
|
|
@@ -2096,7 +2089,7 @@ function requireConnection() {
|
|
|
2096
2089
|
return candidate && (CancellationStrategy.is(candidate.cancellationStrategy) || ConnectionStrategy.is(candidate.connectionStrategy) || MessageStrategy.is(candidate.messageStrategy) || Is.number(candidate.maxParallelism));
|
|
2097
2090
|
}
|
|
2098
2091
|
ConnectionOptions2.is = is2;
|
|
2099
|
-
})(ConnectionOptions || (
|
|
2092
|
+
})(ConnectionOptions || (exports2.ConnectionOptions = ConnectionOptions = {}));
|
|
2100
2093
|
var ConnectionState;
|
|
2101
2094
|
(function(ConnectionState2) {
|
|
2102
2095
|
ConnectionState2[ConnectionState2["New"] = 1] = "New";
|
|
@@ -2105,7 +2098,7 @@ function requireConnection() {
|
|
|
2105
2098
|
ConnectionState2[ConnectionState2["Disposed"] = 4] = "Disposed";
|
|
2106
2099
|
})(ConnectionState || (ConnectionState = {}));
|
|
2107
2100
|
function createMessageConnection(messageReader2, messageWriter2, _logger, options) {
|
|
2108
|
-
const logger = _logger !== void 0 ? _logger :
|
|
2101
|
+
const logger = _logger !== void 0 ? _logger : exports2.NullLogger;
|
|
2109
2102
|
let sequenceNumber = 0;
|
|
2110
2103
|
let notificationSequenceNumber = 0;
|
|
2111
2104
|
let unknownResponseSequenceNumber = 0;
|
|
@@ -2125,7 +2118,7 @@ function requireConnection() {
|
|
|
2125
2118
|
let trace = Trace.Off;
|
|
2126
2119
|
let traceFormat = TraceFormat.Text;
|
|
2127
2120
|
let tracer;
|
|
2128
|
-
let
|
|
2121
|
+
let state2 = ConnectionState.New;
|
|
2129
2122
|
const errorEmitter = new events_1.Emitter();
|
|
2130
2123
|
const closeEmitter = new events_1.Emitter();
|
|
2131
2124
|
const unhandledNotificationEmitter = new events_1.Emitter();
|
|
@@ -2136,17 +2129,17 @@ function requireConnection() {
|
|
|
2136
2129
|
return void 0;
|
|
2137
2130
|
}
|
|
2138
2131
|
function isListening() {
|
|
2139
|
-
return
|
|
2132
|
+
return state2 === ConnectionState.Listening;
|
|
2140
2133
|
}
|
|
2141
2134
|
function isClosed() {
|
|
2142
|
-
return
|
|
2135
|
+
return state2 === ConnectionState.Closed;
|
|
2143
2136
|
}
|
|
2144
2137
|
function isDisposed() {
|
|
2145
|
-
return
|
|
2138
|
+
return state2 === ConnectionState.Disposed;
|
|
2146
2139
|
}
|
|
2147
2140
|
function closeHandler() {
|
|
2148
|
-
if (
|
|
2149
|
-
|
|
2141
|
+
if (state2 === ConnectionState.New || state2 === ConnectionState.Listening) {
|
|
2142
|
+
state2 = ConnectionState.Closed;
|
|
2150
2143
|
closeEmitter.fire(void 0);
|
|
2151
2144
|
}
|
|
2152
2145
|
}
|
|
@@ -2853,9 +2846,9 @@ ${JSON.stringify(message, null, 4)}`);
|
|
|
2853
2846
|
if (typeof cancellationStrategy.sender.enableCancellation === "function") {
|
|
2854
2847
|
cancellationStrategy.sender.enableCancellation(requestMessage);
|
|
2855
2848
|
}
|
|
2856
|
-
return new Promise(async (
|
|
2849
|
+
return new Promise(async (resolve, reject) => {
|
|
2857
2850
|
const resolveWithCleanup = (r) => {
|
|
2858
|
-
|
|
2851
|
+
resolve(r);
|
|
2859
2852
|
cancellationStrategy.sender.cleanup(id);
|
|
2860
2853
|
disposable2?.dispose();
|
|
2861
2854
|
};
|
|
@@ -2948,7 +2941,7 @@ ${JSON.stringify(message, null, 4)}`);
|
|
|
2948
2941
|
if (isDisposed()) {
|
|
2949
2942
|
return;
|
|
2950
2943
|
}
|
|
2951
|
-
|
|
2944
|
+
state2 = ConnectionState.Disposed;
|
|
2952
2945
|
disposeEmitter.fire(void 0);
|
|
2953
2946
|
const error = new messages_1.ResponseError(messages_1.ErrorCodes.PendingResponseRejected, "Pending response rejected since connection got disposed");
|
|
2954
2947
|
for (const promise of responsePromises.values()) {
|
|
@@ -2968,7 +2961,7 @@ ${JSON.stringify(message, null, 4)}`);
|
|
|
2968
2961
|
listen: () => {
|
|
2969
2962
|
throwIfClosedOrDisposed();
|
|
2970
2963
|
throwIfListening();
|
|
2971
|
-
|
|
2964
|
+
state2 = ConnectionState.Listening;
|
|
2972
2965
|
messageReader2.listen(callback);
|
|
2973
2966
|
},
|
|
2974
2967
|
inspect: () => {
|
|
@@ -2999,371 +2992,1610 @@ var hasRequiredApi;
|
|
|
2999
2992
|
function requireApi() {
|
|
3000
2993
|
if (hasRequiredApi) return api;
|
|
3001
2994
|
hasRequiredApi = 1;
|
|
3002
|
-
(function(
|
|
2995
|
+
(function(exports2) {
|
|
3003
2996
|
var __importDefault = api && api.__importDefault || function(mod) {
|
|
3004
2997
|
return mod && mod.__esModule ? mod : { "default": mod };
|
|
3005
2998
|
};
|
|
3006
|
-
Object.defineProperty(
|
|
3007
|
-
|
|
3008
|
-
|
|
2999
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
3000
|
+
exports2.ProgressType = exports2.ProgressToken = exports2.createMessageConnection = exports2.NullLogger = exports2.ConnectionOptions = exports2.ConnectionStrategy = exports2.AbstractMessageBuffer = exports2.WriteableStreamMessageWriter = exports2.AbstractMessageWriter = exports2.MessageWriter = exports2.ReadableStreamMessageReader = exports2.AbstractMessageReader = exports2.MessageReader = exports2.SharedArrayReceiverStrategy = exports2.SharedArraySenderStrategy = exports2.CancellationToken = exports2.CancellationTokenSource = exports2.Emitter = exports2.Event = exports2.Disposable = exports2.LRUCache = exports2.Touch = exports2.LinkedMap = exports2.ParameterStructures = exports2.NotificationType9 = exports2.NotificationType8 = exports2.NotificationType7 = exports2.NotificationType6 = exports2.NotificationType5 = exports2.NotificationType4 = exports2.NotificationType3 = exports2.NotificationType2 = exports2.NotificationType1 = exports2.NotificationType0 = exports2.NotificationType = exports2.ErrorCodes = exports2.ResponseError = exports2.RequestType9 = exports2.RequestType8 = exports2.RequestType7 = exports2.RequestType6 = exports2.RequestType5 = exports2.RequestType4 = exports2.RequestType3 = exports2.RequestType2 = exports2.RequestType1 = exports2.RequestType0 = exports2.RequestType = exports2.Message = exports2.RAL = void 0;
|
|
3001
|
+
exports2.MessageStrategy = exports2.CancellationStrategy = exports2.CancellationSenderStrategy = exports2.RequestCancellationReceiverStrategy = exports2.IdCancellationReceiverStrategy = exports2.CancellationReceiverStrategy = exports2.ConnectionError = exports2.ConnectionErrors = exports2.LogTraceNotification = exports2.SetTraceNotification = exports2.TraceFormat = exports2.TraceValues = exports2.TraceValue = exports2.Trace = void 0;
|
|
3009
3002
|
const messages_1 = requireMessages();
|
|
3010
|
-
Object.defineProperty(
|
|
3003
|
+
Object.defineProperty(exports2, "Message", { enumerable: true, get: function() {
|
|
3011
3004
|
return messages_1.Message;
|
|
3012
3005
|
} });
|
|
3013
|
-
Object.defineProperty(
|
|
3006
|
+
Object.defineProperty(exports2, "RequestType", { enumerable: true, get: function() {
|
|
3014
3007
|
return messages_1.RequestType;
|
|
3015
3008
|
} });
|
|
3016
|
-
Object.defineProperty(
|
|
3009
|
+
Object.defineProperty(exports2, "RequestType0", { enumerable: true, get: function() {
|
|
3017
3010
|
return messages_1.RequestType0;
|
|
3018
3011
|
} });
|
|
3019
|
-
Object.defineProperty(
|
|
3012
|
+
Object.defineProperty(exports2, "RequestType1", { enumerable: true, get: function() {
|
|
3020
3013
|
return messages_1.RequestType1;
|
|
3021
3014
|
} });
|
|
3022
|
-
Object.defineProperty(
|
|
3015
|
+
Object.defineProperty(exports2, "RequestType2", { enumerable: true, get: function() {
|
|
3023
3016
|
return messages_1.RequestType2;
|
|
3024
3017
|
} });
|
|
3025
|
-
Object.defineProperty(
|
|
3018
|
+
Object.defineProperty(exports2, "RequestType3", { enumerable: true, get: function() {
|
|
3026
3019
|
return messages_1.RequestType3;
|
|
3027
3020
|
} });
|
|
3028
|
-
Object.defineProperty(
|
|
3021
|
+
Object.defineProperty(exports2, "RequestType4", { enumerable: true, get: function() {
|
|
3029
3022
|
return messages_1.RequestType4;
|
|
3030
3023
|
} });
|
|
3031
|
-
Object.defineProperty(
|
|
3024
|
+
Object.defineProperty(exports2, "RequestType5", { enumerable: true, get: function() {
|
|
3032
3025
|
return messages_1.RequestType5;
|
|
3033
3026
|
} });
|
|
3034
|
-
Object.defineProperty(
|
|
3027
|
+
Object.defineProperty(exports2, "RequestType6", { enumerable: true, get: function() {
|
|
3035
3028
|
return messages_1.RequestType6;
|
|
3036
3029
|
} });
|
|
3037
|
-
Object.defineProperty(
|
|
3030
|
+
Object.defineProperty(exports2, "RequestType7", { enumerable: true, get: function() {
|
|
3038
3031
|
return messages_1.RequestType7;
|
|
3039
3032
|
} });
|
|
3040
|
-
Object.defineProperty(
|
|
3033
|
+
Object.defineProperty(exports2, "RequestType8", { enumerable: true, get: function() {
|
|
3041
3034
|
return messages_1.RequestType8;
|
|
3042
3035
|
} });
|
|
3043
|
-
Object.defineProperty(
|
|
3036
|
+
Object.defineProperty(exports2, "RequestType9", { enumerable: true, get: function() {
|
|
3044
3037
|
return messages_1.RequestType9;
|
|
3045
3038
|
} });
|
|
3046
|
-
Object.defineProperty(
|
|
3039
|
+
Object.defineProperty(exports2, "ResponseError", { enumerable: true, get: function() {
|
|
3047
3040
|
return messages_1.ResponseError;
|
|
3048
3041
|
} });
|
|
3049
|
-
Object.defineProperty(
|
|
3042
|
+
Object.defineProperty(exports2, "ErrorCodes", { enumerable: true, get: function() {
|
|
3050
3043
|
return messages_1.ErrorCodes;
|
|
3051
3044
|
} });
|
|
3052
|
-
Object.defineProperty(
|
|
3045
|
+
Object.defineProperty(exports2, "NotificationType", { enumerable: true, get: function() {
|
|
3053
3046
|
return messages_1.NotificationType;
|
|
3054
3047
|
} });
|
|
3055
|
-
Object.defineProperty(
|
|
3048
|
+
Object.defineProperty(exports2, "NotificationType0", { enumerable: true, get: function() {
|
|
3056
3049
|
return messages_1.NotificationType0;
|
|
3057
3050
|
} });
|
|
3058
|
-
Object.defineProperty(
|
|
3051
|
+
Object.defineProperty(exports2, "NotificationType1", { enumerable: true, get: function() {
|
|
3059
3052
|
return messages_1.NotificationType1;
|
|
3060
3053
|
} });
|
|
3061
|
-
Object.defineProperty(
|
|
3054
|
+
Object.defineProperty(exports2, "NotificationType2", { enumerable: true, get: function() {
|
|
3062
3055
|
return messages_1.NotificationType2;
|
|
3063
3056
|
} });
|
|
3064
|
-
Object.defineProperty(
|
|
3057
|
+
Object.defineProperty(exports2, "NotificationType3", { enumerable: true, get: function() {
|
|
3065
3058
|
return messages_1.NotificationType3;
|
|
3066
3059
|
} });
|
|
3067
|
-
Object.defineProperty(
|
|
3060
|
+
Object.defineProperty(exports2, "NotificationType4", { enumerable: true, get: function() {
|
|
3068
3061
|
return messages_1.NotificationType4;
|
|
3069
3062
|
} });
|
|
3070
|
-
Object.defineProperty(
|
|
3063
|
+
Object.defineProperty(exports2, "NotificationType5", { enumerable: true, get: function() {
|
|
3071
3064
|
return messages_1.NotificationType5;
|
|
3072
3065
|
} });
|
|
3073
|
-
Object.defineProperty(
|
|
3066
|
+
Object.defineProperty(exports2, "NotificationType6", { enumerable: true, get: function() {
|
|
3074
3067
|
return messages_1.NotificationType6;
|
|
3075
3068
|
} });
|
|
3076
|
-
Object.defineProperty(
|
|
3069
|
+
Object.defineProperty(exports2, "NotificationType7", { enumerable: true, get: function() {
|
|
3077
3070
|
return messages_1.NotificationType7;
|
|
3078
3071
|
} });
|
|
3079
|
-
Object.defineProperty(
|
|
3072
|
+
Object.defineProperty(exports2, "NotificationType8", { enumerable: true, get: function() {
|
|
3080
3073
|
return messages_1.NotificationType8;
|
|
3081
3074
|
} });
|
|
3082
|
-
Object.defineProperty(
|
|
3075
|
+
Object.defineProperty(exports2, "NotificationType9", { enumerable: true, get: function() {
|
|
3083
3076
|
return messages_1.NotificationType9;
|
|
3084
3077
|
} });
|
|
3085
|
-
Object.defineProperty(
|
|
3078
|
+
Object.defineProperty(exports2, "ParameterStructures", { enumerable: true, get: function() {
|
|
3086
3079
|
return messages_1.ParameterStructures;
|
|
3087
3080
|
} });
|
|
3088
3081
|
const linkedMap_1 = requireLinkedMap();
|
|
3089
|
-
Object.defineProperty(
|
|
3082
|
+
Object.defineProperty(exports2, "LinkedMap", { enumerable: true, get: function() {
|
|
3090
3083
|
return linkedMap_1.LinkedMap;
|
|
3091
3084
|
} });
|
|
3092
|
-
Object.defineProperty(
|
|
3085
|
+
Object.defineProperty(exports2, "LRUCache", { enumerable: true, get: function() {
|
|
3093
3086
|
return linkedMap_1.LRUCache;
|
|
3094
3087
|
} });
|
|
3095
|
-
Object.defineProperty(
|
|
3088
|
+
Object.defineProperty(exports2, "Touch", { enumerable: true, get: function() {
|
|
3096
3089
|
return linkedMap_1.Touch;
|
|
3097
3090
|
} });
|
|
3098
3091
|
const disposable_1 = requireDisposable();
|
|
3099
|
-
Object.defineProperty(
|
|
3092
|
+
Object.defineProperty(exports2, "Disposable", { enumerable: true, get: function() {
|
|
3100
3093
|
return disposable_1.Disposable;
|
|
3101
3094
|
} });
|
|
3102
3095
|
const events_1 = requireEvents();
|
|
3103
|
-
Object.defineProperty(
|
|
3096
|
+
Object.defineProperty(exports2, "Event", { enumerable: true, get: function() {
|
|
3104
3097
|
return events_1.Event;
|
|
3105
3098
|
} });
|
|
3106
|
-
Object.defineProperty(
|
|
3099
|
+
Object.defineProperty(exports2, "Emitter", { enumerable: true, get: function() {
|
|
3107
3100
|
return events_1.Emitter;
|
|
3108
3101
|
} });
|
|
3109
3102
|
const cancellation_1 = requireCancellation();
|
|
3110
|
-
Object.defineProperty(
|
|
3103
|
+
Object.defineProperty(exports2, "CancellationTokenSource", { enumerable: true, get: function() {
|
|
3111
3104
|
return cancellation_1.CancellationTokenSource;
|
|
3112
3105
|
} });
|
|
3113
|
-
Object.defineProperty(
|
|
3106
|
+
Object.defineProperty(exports2, "CancellationToken", { enumerable: true, get: function() {
|
|
3114
3107
|
return cancellation_1.CancellationToken;
|
|
3115
3108
|
} });
|
|
3116
3109
|
const sharedArrayCancellation_1 = requireSharedArrayCancellation();
|
|
3117
|
-
Object.defineProperty(
|
|
3110
|
+
Object.defineProperty(exports2, "SharedArraySenderStrategy", { enumerable: true, get: function() {
|
|
3118
3111
|
return sharedArrayCancellation_1.SharedArraySenderStrategy;
|
|
3119
3112
|
} });
|
|
3120
|
-
Object.defineProperty(
|
|
3113
|
+
Object.defineProperty(exports2, "SharedArrayReceiverStrategy", { enumerable: true, get: function() {
|
|
3121
3114
|
return sharedArrayCancellation_1.SharedArrayReceiverStrategy;
|
|
3122
3115
|
} });
|
|
3123
3116
|
const messageReader_1 = requireMessageReader();
|
|
3124
|
-
Object.defineProperty(
|
|
3117
|
+
Object.defineProperty(exports2, "MessageReader", { enumerable: true, get: function() {
|
|
3125
3118
|
return messageReader_1.MessageReader;
|
|
3126
3119
|
} });
|
|
3127
|
-
Object.defineProperty(
|
|
3120
|
+
Object.defineProperty(exports2, "AbstractMessageReader", { enumerable: true, get: function() {
|
|
3128
3121
|
return messageReader_1.AbstractMessageReader;
|
|
3129
3122
|
} });
|
|
3130
|
-
Object.defineProperty(
|
|
3123
|
+
Object.defineProperty(exports2, "ReadableStreamMessageReader", { enumerable: true, get: function() {
|
|
3131
3124
|
return messageReader_1.ReadableStreamMessageReader;
|
|
3132
3125
|
} });
|
|
3133
3126
|
const messageWriter_1 = requireMessageWriter();
|
|
3134
|
-
Object.defineProperty(
|
|
3127
|
+
Object.defineProperty(exports2, "MessageWriter", { enumerable: true, get: function() {
|
|
3135
3128
|
return messageWriter_1.MessageWriter;
|
|
3136
3129
|
} });
|
|
3137
|
-
Object.defineProperty(
|
|
3130
|
+
Object.defineProperty(exports2, "AbstractMessageWriter", { enumerable: true, get: function() {
|
|
3138
3131
|
return messageWriter_1.AbstractMessageWriter;
|
|
3139
3132
|
} });
|
|
3140
|
-
Object.defineProperty(
|
|
3133
|
+
Object.defineProperty(exports2, "WriteableStreamMessageWriter", { enumerable: true, get: function() {
|
|
3141
3134
|
return messageWriter_1.WriteableStreamMessageWriter;
|
|
3142
3135
|
} });
|
|
3143
3136
|
const messageBuffer_1 = requireMessageBuffer();
|
|
3144
|
-
Object.defineProperty(
|
|
3137
|
+
Object.defineProperty(exports2, "AbstractMessageBuffer", { enumerable: true, get: function() {
|
|
3145
3138
|
return messageBuffer_1.AbstractMessageBuffer;
|
|
3146
3139
|
} });
|
|
3147
3140
|
const connection_1 = requireConnection();
|
|
3148
|
-
Object.defineProperty(
|
|
3141
|
+
Object.defineProperty(exports2, "ConnectionStrategy", { enumerable: true, get: function() {
|
|
3149
3142
|
return connection_1.ConnectionStrategy;
|
|
3150
3143
|
} });
|
|
3151
|
-
Object.defineProperty(
|
|
3144
|
+
Object.defineProperty(exports2, "ConnectionOptions", { enumerable: true, get: function() {
|
|
3152
3145
|
return connection_1.ConnectionOptions;
|
|
3153
3146
|
} });
|
|
3154
|
-
Object.defineProperty(
|
|
3147
|
+
Object.defineProperty(exports2, "NullLogger", { enumerable: true, get: function() {
|
|
3155
3148
|
return connection_1.NullLogger;
|
|
3156
3149
|
} });
|
|
3157
|
-
Object.defineProperty(
|
|
3150
|
+
Object.defineProperty(exports2, "createMessageConnection", { enumerable: true, get: function() {
|
|
3158
3151
|
return connection_1.createMessageConnection;
|
|
3159
3152
|
} });
|
|
3160
|
-
Object.defineProperty(
|
|
3153
|
+
Object.defineProperty(exports2, "ProgressToken", { enumerable: true, get: function() {
|
|
3161
3154
|
return connection_1.ProgressToken;
|
|
3162
3155
|
} });
|
|
3163
|
-
Object.defineProperty(
|
|
3156
|
+
Object.defineProperty(exports2, "ProgressType", { enumerable: true, get: function() {
|
|
3164
3157
|
return connection_1.ProgressType;
|
|
3165
3158
|
} });
|
|
3166
|
-
Object.defineProperty(
|
|
3159
|
+
Object.defineProperty(exports2, "Trace", { enumerable: true, get: function() {
|
|
3167
3160
|
return connection_1.Trace;
|
|
3168
3161
|
} });
|
|
3169
|
-
Object.defineProperty(
|
|
3162
|
+
Object.defineProperty(exports2, "TraceValue", { enumerable: true, get: function() {
|
|
3170
3163
|
return connection_1.TraceValue;
|
|
3171
3164
|
} });
|
|
3172
|
-
Object.defineProperty(
|
|
3165
|
+
Object.defineProperty(exports2, "TraceFormat", { enumerable: true, get: function() {
|
|
3173
3166
|
return connection_1.TraceFormat;
|
|
3174
3167
|
} });
|
|
3175
|
-
Object.defineProperty(
|
|
3168
|
+
Object.defineProperty(exports2, "SetTraceNotification", { enumerable: true, get: function() {
|
|
3176
3169
|
return connection_1.SetTraceNotification;
|
|
3177
3170
|
} });
|
|
3178
|
-
Object.defineProperty(
|
|
3171
|
+
Object.defineProperty(exports2, "LogTraceNotification", { enumerable: true, get: function() {
|
|
3179
3172
|
return connection_1.LogTraceNotification;
|
|
3180
3173
|
} });
|
|
3181
|
-
Object.defineProperty(
|
|
3174
|
+
Object.defineProperty(exports2, "ConnectionErrors", { enumerable: true, get: function() {
|
|
3182
3175
|
return connection_1.ConnectionErrors;
|
|
3183
3176
|
} });
|
|
3184
|
-
Object.defineProperty(
|
|
3177
|
+
Object.defineProperty(exports2, "ConnectionError", { enumerable: true, get: function() {
|
|
3185
3178
|
return connection_1.ConnectionError;
|
|
3186
3179
|
} });
|
|
3187
|
-
Object.defineProperty(
|
|
3180
|
+
Object.defineProperty(exports2, "CancellationReceiverStrategy", { enumerable: true, get: function() {
|
|
3188
3181
|
return connection_1.CancellationReceiverStrategy;
|
|
3189
3182
|
} });
|
|
3190
|
-
Object.defineProperty(
|
|
3183
|
+
Object.defineProperty(exports2, "IdCancellationReceiverStrategy", { enumerable: true, get: function() {
|
|
3191
3184
|
return connection_1.IdCancellationReceiverStrategy;
|
|
3192
3185
|
} });
|
|
3193
|
-
Object.defineProperty(
|
|
3186
|
+
Object.defineProperty(exports2, "RequestCancellationReceiverStrategy", { enumerable: true, get: function() {
|
|
3194
3187
|
return connection_1.RequestCancellationReceiverStrategy;
|
|
3195
3188
|
} });
|
|
3196
|
-
Object.defineProperty(
|
|
3189
|
+
Object.defineProperty(exports2, "CancellationSenderStrategy", { enumerable: true, get: function() {
|
|
3197
3190
|
return connection_1.CancellationSenderStrategy;
|
|
3198
3191
|
} });
|
|
3199
|
-
Object.defineProperty(
|
|
3192
|
+
Object.defineProperty(exports2, "CancellationStrategy", { enumerable: true, get: function() {
|
|
3200
3193
|
return connection_1.CancellationStrategy;
|
|
3201
3194
|
} });
|
|
3202
|
-
Object.defineProperty(
|
|
3195
|
+
Object.defineProperty(exports2, "MessageStrategy", { enumerable: true, get: function() {
|
|
3203
3196
|
return connection_1.MessageStrategy;
|
|
3204
3197
|
} });
|
|
3205
|
-
Object.defineProperty(
|
|
3198
|
+
Object.defineProperty(exports2, "TraceValues", { enumerable: true, get: function() {
|
|
3206
3199
|
return connection_1.TraceValues;
|
|
3207
3200
|
} });
|
|
3208
3201
|
const ral_1 = __importDefault(requireRal());
|
|
3209
|
-
|
|
3202
|
+
exports2.RAL = ral_1.default;
|
|
3210
3203
|
})(api);
|
|
3211
3204
|
return api;
|
|
3212
3205
|
}
|
|
3213
|
-
|
|
3214
|
-
function
|
|
3215
|
-
return
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3206
|
+
var hasRequiredRil;
|
|
3207
|
+
function requireRil() {
|
|
3208
|
+
if (hasRequiredRil) return ril;
|
|
3209
|
+
hasRequiredRil = 1;
|
|
3210
|
+
Object.defineProperty(ril, "__esModule", { value: true });
|
|
3211
|
+
ril.PromiseImpl = ril.QueueMicrotaskImpl = void 0;
|
|
3212
|
+
const api_1 = requireApi();
|
|
3213
|
+
class MessageBuffer extends api_1.AbstractMessageBuffer {
|
|
3214
|
+
static emptyBuffer = new Uint8Array(0);
|
|
3215
|
+
asciiDecoder;
|
|
3216
|
+
constructor(encoding = "utf-8") {
|
|
3217
|
+
super(encoding);
|
|
3218
|
+
this.asciiDecoder = new TextDecoder("ascii");
|
|
3219
|
+
}
|
|
3220
|
+
emptyBuffer() {
|
|
3221
|
+
return MessageBuffer.emptyBuffer;
|
|
3222
|
+
}
|
|
3223
|
+
fromString(value, _encoding) {
|
|
3224
|
+
return new TextEncoder().encode(value);
|
|
3225
|
+
}
|
|
3226
|
+
toString(value, encoding) {
|
|
3227
|
+
if (encoding === "ascii") {
|
|
3228
|
+
return this.asciiDecoder.decode(value);
|
|
3229
|
+
} else {
|
|
3230
|
+
return new TextDecoder(encoding).decode(value);
|
|
3231
|
+
}
|
|
3232
|
+
}
|
|
3233
|
+
asNative(buffer, length) {
|
|
3234
|
+
if (length === void 0) {
|
|
3235
|
+
return buffer;
|
|
3236
|
+
} else {
|
|
3237
|
+
return buffer.slice(0, length);
|
|
3238
|
+
}
|
|
3239
|
+
}
|
|
3240
|
+
allocNative(length) {
|
|
3241
|
+
return new Uint8Array(length);
|
|
3242
|
+
}
|
|
3243
|
+
}
|
|
3244
|
+
class ReadableStreamWrapper {
|
|
3245
|
+
socket;
|
|
3246
|
+
_onData;
|
|
3247
|
+
_messageListener;
|
|
3248
|
+
constructor(socket) {
|
|
3249
|
+
this.socket = socket;
|
|
3250
|
+
this._onData = new api_1.Emitter();
|
|
3251
|
+
this._messageListener = (event) => {
|
|
3252
|
+
const blob = event.data;
|
|
3253
|
+
blob.arrayBuffer().then((buffer) => {
|
|
3254
|
+
this._onData.fire(new Uint8Array(buffer));
|
|
3255
|
+
}, () => {
|
|
3256
|
+
(0, api_1.RAL)().console.error(`Converting blob to array buffer failed.`);
|
|
3257
|
+
});
|
|
3258
|
+
};
|
|
3259
|
+
this.socket.addEventListener("message", this._messageListener);
|
|
3260
|
+
}
|
|
3261
|
+
onClose(listener) {
|
|
3262
|
+
this.socket.addEventListener("close", listener);
|
|
3263
|
+
return api_1.Disposable.create(() => this.socket.removeEventListener("close", listener));
|
|
3264
|
+
}
|
|
3265
|
+
onError(listener) {
|
|
3266
|
+
this.socket.addEventListener("error", listener);
|
|
3267
|
+
return api_1.Disposable.create(() => this.socket.removeEventListener("error", listener));
|
|
3268
|
+
}
|
|
3269
|
+
onEnd(listener) {
|
|
3270
|
+
this.socket.addEventListener("end", listener);
|
|
3271
|
+
return api_1.Disposable.create(() => this.socket.removeEventListener("end", listener));
|
|
3272
|
+
}
|
|
3273
|
+
onData(listener) {
|
|
3274
|
+
return this._onData.event(listener);
|
|
3275
|
+
}
|
|
3276
|
+
}
|
|
3277
|
+
class WritableStreamWrapper {
|
|
3278
|
+
socket;
|
|
3279
|
+
constructor(socket) {
|
|
3280
|
+
this.socket = socket;
|
|
3281
|
+
}
|
|
3282
|
+
onClose(listener) {
|
|
3283
|
+
this.socket.addEventListener("close", listener);
|
|
3284
|
+
return api_1.Disposable.create(() => this.socket.removeEventListener("close", listener));
|
|
3285
|
+
}
|
|
3286
|
+
onError(listener) {
|
|
3287
|
+
this.socket.addEventListener("error", listener);
|
|
3288
|
+
return api_1.Disposable.create(() => this.socket.removeEventListener("error", listener));
|
|
3289
|
+
}
|
|
3290
|
+
onEnd(listener) {
|
|
3291
|
+
this.socket.addEventListener("end", listener);
|
|
3292
|
+
return api_1.Disposable.create(() => this.socket.removeEventListener("end", listener));
|
|
3293
|
+
}
|
|
3294
|
+
write(data, encoding) {
|
|
3295
|
+
if (typeof data === "string") {
|
|
3296
|
+
if (encoding !== void 0 && encoding !== "utf-8") {
|
|
3297
|
+
throw new Error(`In a Browser environments only utf-8 text encoding is supported. But got encoding: ${encoding}`);
|
|
3298
|
+
}
|
|
3299
|
+
this.socket.send(data);
|
|
3300
|
+
} else {
|
|
3301
|
+
if (data.buffer instanceof ArrayBuffer) {
|
|
3302
|
+
this.socket.send(data.buffer);
|
|
3303
|
+
} else {
|
|
3304
|
+
this.socket.send(new Uint8Array(data.buffer).slice().buffer);
|
|
3305
|
+
}
|
|
3306
|
+
}
|
|
3307
|
+
return Promise.resolve();
|
|
3308
|
+
}
|
|
3309
|
+
end() {
|
|
3310
|
+
this.socket.close();
|
|
3311
|
+
}
|
|
3312
|
+
}
|
|
3313
|
+
class QueueMicrotaskImpl {
|
|
3314
|
+
isDisposed;
|
|
3315
|
+
constructor(callback, ...args) {
|
|
3316
|
+
this.isDisposed = false;
|
|
3317
|
+
queueMicrotask(() => {
|
|
3318
|
+
if (!this.isDisposed) {
|
|
3319
|
+
callback(...args);
|
|
3320
|
+
}
|
|
3321
|
+
});
|
|
3322
|
+
}
|
|
3323
|
+
dispose() {
|
|
3324
|
+
this.isDisposed = true;
|
|
3325
|
+
}
|
|
3326
|
+
}
|
|
3327
|
+
ril.QueueMicrotaskImpl = QueueMicrotaskImpl;
|
|
3328
|
+
class PromiseImpl {
|
|
3329
|
+
isDisposed;
|
|
3330
|
+
constructor(callback, ...args) {
|
|
3331
|
+
this.isDisposed = false;
|
|
3332
|
+
Promise.resolve().then(() => {
|
|
3333
|
+
if (!this.isDisposed) {
|
|
3334
|
+
callback(...args);
|
|
3335
|
+
}
|
|
3336
|
+
}, () => {
|
|
3337
|
+
});
|
|
3338
|
+
}
|
|
3339
|
+
dispose() {
|
|
3340
|
+
this.isDisposed = true;
|
|
3341
|
+
}
|
|
3342
|
+
}
|
|
3343
|
+
ril.PromiseImpl = PromiseImpl;
|
|
3344
|
+
const _textEncoder = new TextEncoder();
|
|
3345
|
+
const _ril = Object.freeze({
|
|
3346
|
+
messageBuffer: Object.freeze({
|
|
3347
|
+
create: (encoding) => new MessageBuffer(encoding)
|
|
3348
|
+
}),
|
|
3349
|
+
applicationJson: Object.freeze({
|
|
3350
|
+
encoder: Object.freeze({
|
|
3351
|
+
name: "application/json",
|
|
3352
|
+
encode: (msg, options) => {
|
|
3353
|
+
if (options.charset !== "utf-8") {
|
|
3354
|
+
throw new Error(`In a Browser environments only utf-8 text encoding is supported. But got encoding: ${options.charset}`);
|
|
3355
|
+
}
|
|
3356
|
+
return Promise.resolve(_textEncoder.encode(JSON.stringify(msg, void 0, 0)));
|
|
3357
|
+
}
|
|
3358
|
+
}),
|
|
3359
|
+
decoder: Object.freeze({
|
|
3360
|
+
name: "application/json",
|
|
3361
|
+
decode: (buffer, options) => {
|
|
3362
|
+
if (!(buffer instanceof Uint8Array)) {
|
|
3363
|
+
throw new Error(`In a Browser environments only Uint8Arrays are supported.`);
|
|
3364
|
+
}
|
|
3365
|
+
return Promise.resolve(JSON.parse(new TextDecoder(options.charset).decode(buffer)));
|
|
3366
|
+
}
|
|
3367
|
+
})
|
|
3368
|
+
}),
|
|
3369
|
+
stream: Object.freeze({
|
|
3370
|
+
asReadableStream: (socket) => new ReadableStreamWrapper(socket),
|
|
3371
|
+
asWritableStream: (socket) => new WritableStreamWrapper(socket)
|
|
3372
|
+
}),
|
|
3373
|
+
console,
|
|
3374
|
+
timer: Object.freeze({
|
|
3375
|
+
setTimeout(callback, ms, ...args) {
|
|
3376
|
+
const handle = setTimeout(callback, ms, ...args);
|
|
3377
|
+
return { dispose: () => clearTimeout(handle) };
|
|
3378
|
+
},
|
|
3379
|
+
setImmediate(callback, ...args) {
|
|
3380
|
+
if (typeof globalThis.queueMicrotask === "function") {
|
|
3381
|
+
return new QueueMicrotaskImpl(callback, ...args);
|
|
3382
|
+
} else if (Promise !== void 0) {
|
|
3383
|
+
return new PromiseImpl(callback, ...args);
|
|
3384
|
+
} else {
|
|
3385
|
+
const handle = setTimeout(callback, 0, ...args);
|
|
3386
|
+
return { dispose: () => clearTimeout(handle) };
|
|
3387
|
+
}
|
|
3388
|
+
},
|
|
3389
|
+
setInterval(callback, ms, ...args) {
|
|
3390
|
+
const handle = setInterval(callback, ms, ...args);
|
|
3391
|
+
return { dispose: () => clearInterval(handle) };
|
|
3392
|
+
}
|
|
3393
|
+
})
|
|
3394
|
+
});
|
|
3395
|
+
function RIL() {
|
|
3396
|
+
return _ril;
|
|
3397
|
+
}
|
|
3398
|
+
(function(RIL2) {
|
|
3399
|
+
function install() {
|
|
3400
|
+
api_1.RAL.install(_ril);
|
|
3401
|
+
}
|
|
3402
|
+
RIL2.install = install;
|
|
3403
|
+
})(RIL || (RIL = {}));
|
|
3404
|
+
ril.default = RIL;
|
|
3405
|
+
return ril;
|
|
3406
|
+
}
|
|
3407
|
+
var hasRequiredMain;
|
|
3408
|
+
function requireMain() {
|
|
3409
|
+
if (hasRequiredMain) return main;
|
|
3410
|
+
hasRequiredMain = 1;
|
|
3411
|
+
(function(exports2) {
|
|
3412
|
+
var __createBinding = main && main.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
3413
|
+
if (k2 === void 0) k2 = k;
|
|
3414
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
3415
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
3416
|
+
desc = { enumerable: true, get: function() {
|
|
3417
|
+
return m[k];
|
|
3418
|
+
} };
|
|
3419
|
+
}
|
|
3420
|
+
Object.defineProperty(o, k2, desc);
|
|
3421
|
+
}) : (function(o, m, k, k2) {
|
|
3422
|
+
if (k2 === void 0) k2 = k;
|
|
3423
|
+
o[k2] = m[k];
|
|
3424
|
+
}));
|
|
3425
|
+
var __exportStar = main && main.__exportStar || function(m, exports3) {
|
|
3426
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p)) __createBinding(exports3, m, p);
|
|
3427
|
+
};
|
|
3428
|
+
var __importDefault = main && main.__importDefault || function(mod) {
|
|
3429
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
3430
|
+
};
|
|
3431
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
3432
|
+
exports2.BrowserMessageWriter = exports2.BrowserMessageReader = void 0;
|
|
3433
|
+
exports2.createMessageConnection = createMessageConnection;
|
|
3434
|
+
const ril_1 = __importDefault(requireRil());
|
|
3435
|
+
ril_1.default.install();
|
|
3436
|
+
const api_1 = requireApi();
|
|
3437
|
+
__exportStar(requireApi(), exports2);
|
|
3438
|
+
class BrowserMessageReader extends api_1.AbstractMessageReader {
|
|
3439
|
+
_onData;
|
|
3440
|
+
_messageListener;
|
|
3441
|
+
constructor(port) {
|
|
3442
|
+
super();
|
|
3443
|
+
this._onData = new api_1.Emitter();
|
|
3444
|
+
this._messageListener = (event) => {
|
|
3445
|
+
this._onData.fire(event.data);
|
|
3446
|
+
};
|
|
3447
|
+
port.addEventListener("error", (event) => this.fireError(event));
|
|
3448
|
+
port.onmessage = this._messageListener;
|
|
3449
|
+
}
|
|
3450
|
+
listen(callback) {
|
|
3451
|
+
return this._onData.event(callback);
|
|
3452
|
+
}
|
|
3453
|
+
}
|
|
3454
|
+
exports2.BrowserMessageReader = BrowserMessageReader;
|
|
3455
|
+
class BrowserMessageWriter extends api_1.AbstractMessageWriter {
|
|
3456
|
+
port;
|
|
3457
|
+
errorCount;
|
|
3458
|
+
constructor(port) {
|
|
3459
|
+
super();
|
|
3460
|
+
this.port = port;
|
|
3461
|
+
this.errorCount = 0;
|
|
3462
|
+
port.addEventListener("error", (event) => this.fireError(event));
|
|
3463
|
+
}
|
|
3464
|
+
write(msg) {
|
|
3465
|
+
try {
|
|
3466
|
+
this.port.postMessage(msg);
|
|
3467
|
+
return Promise.resolve();
|
|
3468
|
+
} catch (error) {
|
|
3469
|
+
this.handleError(error, msg);
|
|
3470
|
+
return Promise.reject(error);
|
|
3471
|
+
}
|
|
3472
|
+
}
|
|
3473
|
+
handleError(error, msg) {
|
|
3474
|
+
this.errorCount++;
|
|
3475
|
+
this.fireError(error, msg, this.errorCount);
|
|
3476
|
+
}
|
|
3477
|
+
end() {
|
|
3478
|
+
}
|
|
3479
|
+
}
|
|
3480
|
+
exports2.BrowserMessageWriter = BrowserMessageWriter;
|
|
3481
|
+
function createMessageConnection(reader, writer, logger, options) {
|
|
3482
|
+
if (logger === void 0) {
|
|
3483
|
+
logger = api_1.NullLogger;
|
|
3484
|
+
}
|
|
3485
|
+
if (api_1.ConnectionStrategy.is(options)) {
|
|
3486
|
+
options = { connectionStrategy: options };
|
|
3487
|
+
}
|
|
3488
|
+
return (0, api_1.createMessageConnection)(reader, writer, logger, options);
|
|
3489
|
+
}
|
|
3490
|
+
})(main);
|
|
3491
|
+
return main;
|
|
3492
|
+
}
|
|
3493
|
+
requireMain();
|
|
3494
|
+
var apiExports = requireApi();
|
|
3495
|
+
function defineSplitConnection(Reader, Writer) {
|
|
3496
|
+
return function create(input, output) {
|
|
3497
|
+
return apiExports.createMessageConnection(new Reader(input), new Writer(output));
|
|
3219
3498
|
};
|
|
3220
3499
|
}
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
const mcpHandlesByWindow = /* @__PURE__ */ new Map();
|
|
3233
|
-
function findMcpHandle(win, key) {
|
|
3234
|
-
for (let current = win; current; current = current.getParentWindow()) {
|
|
3235
|
-
const handle2 = mcpHandlesByWindow.get(current.id)?.get(key);
|
|
3236
|
-
if (handle2) return handle2;
|
|
3237
|
-
}
|
|
3238
|
-
return void 0;
|
|
3239
|
-
}
|
|
3240
|
-
function getMcpAddress(win, packageName, version) {
|
|
3241
|
-
const key = `${packageName}@${version ?? ""}`;
|
|
3242
|
-
const existing = findMcpHandle(win, key);
|
|
3243
|
-
if (existing) return existing.then(({ address }) => address);
|
|
3244
|
-
const handle2 = runAsMcp(import.meta, packageName, version);
|
|
3245
|
-
let owned = mcpHandlesByWindow.get(win.id);
|
|
3246
|
-
if (!owned) mcpHandlesByWindow.set(win.id, owned = /* @__PURE__ */ new Map());
|
|
3247
|
-
owned.set(key, handle2);
|
|
3248
|
-
handle2.catch(() => owned.delete(key));
|
|
3249
|
-
return handle2.then(({ address }) => address);
|
|
3250
|
-
}
|
|
3251
|
-
function disposeWindowMcpHandles(windowId) {
|
|
3252
|
-
const owned = mcpHandlesByWindow.get(windowId);
|
|
3253
|
-
if (!owned) return;
|
|
3254
|
-
mcpHandlesByWindow.delete(windowId);
|
|
3255
|
-
for (const handle2 of owned.values())
|
|
3256
|
-
handle2.then(({ dispose }) => dispose()).catch(() => {
|
|
3500
|
+
class CallbackMessageReader extends apiExports.AbstractMessageReader {
|
|
3501
|
+
callback;
|
|
3502
|
+
unsubscribe;
|
|
3503
|
+
constructor(receiver) {
|
|
3504
|
+
super();
|
|
3505
|
+
this.unsubscribe = apiExports.Disposable.create(receiver.subscribe((message) => this.callback?.(message)));
|
|
3506
|
+
}
|
|
3507
|
+
listen(callback) {
|
|
3508
|
+
this.callback = callback;
|
|
3509
|
+
return apiExports.Disposable.create(() => {
|
|
3510
|
+
this.callback = void 0;
|
|
3257
3511
|
});
|
|
3512
|
+
}
|
|
3513
|
+
dispose() {
|
|
3514
|
+
super.dispose();
|
|
3515
|
+
this.unsubscribe.dispose();
|
|
3516
|
+
}
|
|
3258
3517
|
}
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3518
|
+
class CallbackMessageWriter extends apiExports.AbstractMessageWriter {
|
|
3519
|
+
sender;
|
|
3520
|
+
constructor(sender) {
|
|
3521
|
+
super();
|
|
3522
|
+
this.sender = sender;
|
|
3523
|
+
}
|
|
3524
|
+
write(message) {
|
|
3525
|
+
this.sender.send(message);
|
|
3526
|
+
return Promise.resolve();
|
|
3527
|
+
}
|
|
3528
|
+
end() {
|
|
3529
|
+
}
|
|
3530
|
+
dispose() {
|
|
3531
|
+
super.dispose();
|
|
3532
|
+
this.sender.dispose?.();
|
|
3533
|
+
}
|
|
3534
|
+
}
|
|
3535
|
+
const createCallback = defineSplitConnection(CallbackMessageReader, CallbackMessageWriter);
|
|
3536
|
+
function splitSourceFor(create) {
|
|
3537
|
+
return function(input, output) {
|
|
3538
|
+
return (source) => create(input(source), output(source));
|
|
3539
|
+
};
|
|
3540
|
+
}
|
|
3541
|
+
function forElectronIPC(channel2) {
|
|
3542
|
+
return splitSourceFor(createCallback)((source) => ({
|
|
3543
|
+
subscribe: (callback) => {
|
|
3544
|
+
const listener = (_event, message) => callback(message);
|
|
3545
|
+
source.on(channel2, listener);
|
|
3546
|
+
return () => source.off(channel2, listener);
|
|
3547
|
+
}
|
|
3548
|
+
}), (source) => ({
|
|
3549
|
+
send: (message) => source.send(channel2, message)
|
|
3550
|
+
}));
|
|
3551
|
+
}
|
|
3552
|
+
var __extends = /* @__PURE__ */ (function() {
|
|
3553
|
+
var extendStatics = function(d, b) {
|
|
3554
|
+
extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
|
|
3555
|
+
d2.__proto__ = b2;
|
|
3556
|
+
} || function(d2, b2) {
|
|
3557
|
+
for (var p in b2) if (b2.hasOwnProperty(p)) d2[p] = b2[p];
|
|
3558
|
+
};
|
|
3559
|
+
return extendStatics(d, b);
|
|
3560
|
+
};
|
|
3561
|
+
return function(d, b) {
|
|
3562
|
+
extendStatics(d, b);
|
|
3563
|
+
function __() {
|
|
3564
|
+
this.constructor = d;
|
|
3277
3565
|
}
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3566
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
3567
|
+
};
|
|
3568
|
+
})();
|
|
3569
|
+
var _hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
3570
|
+
function hasOwnProperty(obj, key) {
|
|
3571
|
+
return _hasOwnProperty.call(obj, key);
|
|
3572
|
+
}
|
|
3573
|
+
function _objectKeys(obj) {
|
|
3574
|
+
if (Array.isArray(obj)) {
|
|
3575
|
+
var keys_1 = new Array(obj.length);
|
|
3576
|
+
for (var k = 0; k < keys_1.length; k++) {
|
|
3577
|
+
keys_1[k] = "" + k;
|
|
3578
|
+
}
|
|
3579
|
+
return keys_1;
|
|
3580
|
+
}
|
|
3581
|
+
if (Object.keys) {
|
|
3582
|
+
return Object.keys(obj);
|
|
3583
|
+
}
|
|
3584
|
+
var keys = [];
|
|
3585
|
+
for (var i in obj) {
|
|
3586
|
+
if (hasOwnProperty(obj, i)) {
|
|
3587
|
+
keys.push(i);
|
|
3588
|
+
}
|
|
3589
|
+
}
|
|
3590
|
+
return keys;
|
|
3591
|
+
}
|
|
3592
|
+
function _deepClone(obj) {
|
|
3593
|
+
switch (typeof obj) {
|
|
3594
|
+
case "object":
|
|
3595
|
+
return JSON.parse(JSON.stringify(obj));
|
|
3596
|
+
//Faster than ES5 clone - http://jsperf.com/deep-cloning-of-objects/5
|
|
3597
|
+
case "undefined":
|
|
3598
|
+
return null;
|
|
3599
|
+
//this is how JSON.stringify behaves for array items
|
|
3600
|
+
default:
|
|
3601
|
+
return obj;
|
|
3602
|
+
}
|
|
3603
|
+
}
|
|
3604
|
+
function isInteger(str) {
|
|
3605
|
+
var i = 0;
|
|
3606
|
+
var len = str.length;
|
|
3607
|
+
var charCode;
|
|
3608
|
+
while (i < len) {
|
|
3609
|
+
charCode = str.charCodeAt(i);
|
|
3610
|
+
if (charCode >= 48 && charCode <= 57) {
|
|
3611
|
+
i++;
|
|
3612
|
+
continue;
|
|
3613
|
+
}
|
|
3614
|
+
return false;
|
|
3615
|
+
}
|
|
3616
|
+
return true;
|
|
3617
|
+
}
|
|
3618
|
+
function escapePathComponent(path) {
|
|
3619
|
+
if (path.indexOf("/") === -1 && path.indexOf("~") === -1)
|
|
3620
|
+
return path;
|
|
3621
|
+
return path.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
3622
|
+
}
|
|
3623
|
+
function unescapePathComponent(path) {
|
|
3624
|
+
return path.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
3625
|
+
}
|
|
3626
|
+
function hasUndefined(obj) {
|
|
3627
|
+
if (obj === void 0) {
|
|
3628
|
+
return true;
|
|
3629
|
+
}
|
|
3630
|
+
if (obj) {
|
|
3631
|
+
if (Array.isArray(obj)) {
|
|
3632
|
+
for (var i_1 = 0, len = obj.length; i_1 < len; i_1++) {
|
|
3633
|
+
if (hasUndefined(obj[i_1])) {
|
|
3634
|
+
return true;
|
|
3635
|
+
}
|
|
3636
|
+
}
|
|
3637
|
+
} else if (typeof obj === "object") {
|
|
3638
|
+
var objKeys = _objectKeys(obj);
|
|
3639
|
+
var objKeysLength = objKeys.length;
|
|
3640
|
+
for (var i = 0; i < objKeysLength; i++) {
|
|
3641
|
+
if (hasUndefined(obj[objKeys[i]])) {
|
|
3642
|
+
return true;
|
|
3285
3643
|
}
|
|
3286
|
-
|
|
3287
|
-
}, win);
|
|
3288
|
-
} catch (error) {
|
|
3289
|
-
reject(error);
|
|
3644
|
+
}
|
|
3290
3645
|
}
|
|
3291
|
-
}
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3646
|
+
}
|
|
3647
|
+
return false;
|
|
3648
|
+
}
|
|
3649
|
+
function patchErrorMessageFormatter(message, args) {
|
|
3650
|
+
var messageParts = [message];
|
|
3651
|
+
for (var key in args) {
|
|
3652
|
+
var value = typeof args[key] === "object" ? JSON.stringify(args[key], null, 2) : args[key];
|
|
3653
|
+
if (typeof value !== "undefined") {
|
|
3654
|
+
messageParts.push(key + ": " + value);
|
|
3655
|
+
}
|
|
3656
|
+
}
|
|
3657
|
+
return messageParts.join("\n");
|
|
3658
|
+
}
|
|
3659
|
+
var PatchError = (
|
|
3660
|
+
/** @class */
|
|
3661
|
+
(function(_super) {
|
|
3662
|
+
__extends(PatchError2, _super);
|
|
3663
|
+
function PatchError2(message, name, index, operation, tree) {
|
|
3664
|
+
var _newTarget = this.constructor;
|
|
3665
|
+
var _this = _super.call(this, patchErrorMessageFormatter(message, { name, index, operation, tree })) || this;
|
|
3666
|
+
_this.name = name;
|
|
3667
|
+
_this.index = index;
|
|
3668
|
+
_this.operation = operation;
|
|
3669
|
+
_this.tree = tree;
|
|
3670
|
+
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
3671
|
+
_this.message = patchErrorMessageFormatter(message, { name, index, operation, tree });
|
|
3672
|
+
return _this;
|
|
3673
|
+
}
|
|
3674
|
+
return PatchError2;
|
|
3675
|
+
})(Error)
|
|
3676
|
+
);
|
|
3677
|
+
var JsonPatchError = PatchError;
|
|
3678
|
+
var deepClone = _deepClone;
|
|
3679
|
+
var objOps = {
|
|
3680
|
+
add: function(obj, key, document) {
|
|
3681
|
+
obj[key] = this.value;
|
|
3682
|
+
return { newDocument: document };
|
|
3683
|
+
},
|
|
3684
|
+
remove: function(obj, key, document) {
|
|
3685
|
+
var removed = obj[key];
|
|
3686
|
+
delete obj[key];
|
|
3687
|
+
return { newDocument: document, removed };
|
|
3688
|
+
},
|
|
3689
|
+
replace: function(obj, key, document) {
|
|
3690
|
+
var removed = obj[key];
|
|
3691
|
+
obj[key] = this.value;
|
|
3692
|
+
return { newDocument: document, removed };
|
|
3693
|
+
},
|
|
3694
|
+
move: function(obj, key, document) {
|
|
3695
|
+
var removed = getValueByPointer(document, this.path);
|
|
3696
|
+
if (removed) {
|
|
3697
|
+
removed = _deepClone(removed);
|
|
3698
|
+
}
|
|
3699
|
+
var originalValue = applyOperation(document, { op: "remove", path: this.from }).removed;
|
|
3700
|
+
applyOperation(document, { op: "add", path: this.path, value: originalValue });
|
|
3701
|
+
return { newDocument: document, removed };
|
|
3702
|
+
},
|
|
3703
|
+
copy: function(obj, key, document) {
|
|
3704
|
+
var valueToCopy = getValueByPointer(document, this.from);
|
|
3705
|
+
applyOperation(document, { op: "add", path: this.path, value: _deepClone(valueToCopy) });
|
|
3706
|
+
return { newDocument: document };
|
|
3707
|
+
},
|
|
3708
|
+
test: function(obj, key, document) {
|
|
3709
|
+
return { newDocument: document, test: _areEquals(obj[key], this.value) };
|
|
3710
|
+
},
|
|
3711
|
+
_get: function(obj, key, document) {
|
|
3712
|
+
this.value = obj[key];
|
|
3713
|
+
return { newDocument: document };
|
|
3714
|
+
}
|
|
3715
|
+
};
|
|
3716
|
+
var arrOps = {
|
|
3717
|
+
add: function(arr, i, document) {
|
|
3718
|
+
if (isInteger(i)) {
|
|
3719
|
+
arr.splice(i, 0, this.value);
|
|
3720
|
+
} else {
|
|
3721
|
+
arr[i] = this.value;
|
|
3722
|
+
}
|
|
3723
|
+
return { newDocument: document, index: i };
|
|
3724
|
+
},
|
|
3725
|
+
remove: function(arr, i, document) {
|
|
3726
|
+
var removedList = arr.splice(i, 1);
|
|
3727
|
+
return { newDocument: document, removed: removedList[0] };
|
|
3728
|
+
},
|
|
3729
|
+
replace: function(arr, i, document) {
|
|
3730
|
+
var removed = arr[i];
|
|
3731
|
+
arr[i] = this.value;
|
|
3732
|
+
return { newDocument: document, removed };
|
|
3733
|
+
},
|
|
3734
|
+
move: objOps.move,
|
|
3735
|
+
copy: objOps.copy,
|
|
3736
|
+
test: objOps.test,
|
|
3737
|
+
_get: objOps._get
|
|
3738
|
+
};
|
|
3739
|
+
function getValueByPointer(document, pointer) {
|
|
3740
|
+
if (pointer == "") {
|
|
3741
|
+
return document;
|
|
3742
|
+
}
|
|
3743
|
+
var getOriginalDestination = { op: "_get", path: pointer };
|
|
3744
|
+
applyOperation(document, getOriginalDestination);
|
|
3745
|
+
return getOriginalDestination.value;
|
|
3746
|
+
}
|
|
3747
|
+
function applyOperation(document, operation, validateOperation, mutateDocument, banPrototypeModifications, index) {
|
|
3748
|
+
if (validateOperation === void 0) {
|
|
3749
|
+
validateOperation = false;
|
|
3750
|
+
}
|
|
3751
|
+
if (mutateDocument === void 0) {
|
|
3752
|
+
mutateDocument = true;
|
|
3753
|
+
}
|
|
3754
|
+
if (banPrototypeModifications === void 0) {
|
|
3755
|
+
banPrototypeModifications = true;
|
|
3756
|
+
}
|
|
3757
|
+
if (index === void 0) {
|
|
3758
|
+
index = 0;
|
|
3759
|
+
}
|
|
3760
|
+
if (validateOperation) {
|
|
3761
|
+
if (typeof validateOperation == "function") {
|
|
3762
|
+
validateOperation(operation, 0, document, operation.path);
|
|
3763
|
+
} else {
|
|
3764
|
+
validator(operation, 0);
|
|
3765
|
+
}
|
|
3766
|
+
}
|
|
3767
|
+
if (operation.path === "") {
|
|
3768
|
+
var returnValue = { newDocument: document };
|
|
3769
|
+
if (operation.op === "add") {
|
|
3770
|
+
returnValue.newDocument = operation.value;
|
|
3771
|
+
return returnValue;
|
|
3772
|
+
} else if (operation.op === "replace") {
|
|
3773
|
+
returnValue.newDocument = operation.value;
|
|
3774
|
+
returnValue.removed = document;
|
|
3775
|
+
return returnValue;
|
|
3776
|
+
} else if (operation.op === "move" || operation.op === "copy") {
|
|
3777
|
+
returnValue.newDocument = getValueByPointer(document, operation.from);
|
|
3778
|
+
if (operation.op === "move") {
|
|
3779
|
+
returnValue.removed = document;
|
|
3780
|
+
}
|
|
3781
|
+
return returnValue;
|
|
3782
|
+
} else if (operation.op === "test") {
|
|
3783
|
+
returnValue.test = _areEquals(document, operation.value);
|
|
3784
|
+
if (returnValue.test === false) {
|
|
3785
|
+
throw new JsonPatchError("Test operation failed", "TEST_OPERATION_FAILED", index, operation, document);
|
|
3786
|
+
}
|
|
3787
|
+
returnValue.newDocument = document;
|
|
3788
|
+
return returnValue;
|
|
3789
|
+
} else if (operation.op === "remove") {
|
|
3790
|
+
returnValue.removed = document;
|
|
3791
|
+
returnValue.newDocument = null;
|
|
3792
|
+
return returnValue;
|
|
3793
|
+
} else if (operation.op === "_get") {
|
|
3794
|
+
operation.value = document;
|
|
3795
|
+
return returnValue;
|
|
3796
|
+
} else {
|
|
3797
|
+
if (validateOperation) {
|
|
3798
|
+
throw new JsonPatchError("Operation `op` property is not one of operations defined in RFC-6902", "OPERATION_OP_INVALID", index, operation, document);
|
|
3799
|
+
} else {
|
|
3800
|
+
return returnValue;
|
|
3801
|
+
}
|
|
3802
|
+
}
|
|
3803
|
+
} else {
|
|
3804
|
+
if (!mutateDocument) {
|
|
3805
|
+
document = _deepClone(document);
|
|
3806
|
+
}
|
|
3807
|
+
var path = operation.path || "";
|
|
3808
|
+
var keys = path.split("/");
|
|
3809
|
+
var obj = document;
|
|
3810
|
+
var t = 1;
|
|
3811
|
+
var len = keys.length;
|
|
3812
|
+
var existingPathFragment = void 0;
|
|
3813
|
+
var key = void 0;
|
|
3814
|
+
var validateFunction = void 0;
|
|
3815
|
+
if (typeof validateOperation == "function") {
|
|
3816
|
+
validateFunction = validateOperation;
|
|
3817
|
+
} else {
|
|
3818
|
+
validateFunction = validator;
|
|
3819
|
+
}
|
|
3820
|
+
while (true) {
|
|
3821
|
+
key = keys[t];
|
|
3822
|
+
if (key && key.indexOf("~") != -1) {
|
|
3823
|
+
key = unescapePathComponent(key);
|
|
3824
|
+
}
|
|
3825
|
+
if (banPrototypeModifications && (key == "__proto__" || key == "prototype" && t > 0 && keys[t - 1] == "constructor")) {
|
|
3826
|
+
throw new TypeError("JSON-Patch: modifying `__proto__` or `constructor/prototype` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README");
|
|
3827
|
+
}
|
|
3828
|
+
if (validateOperation) {
|
|
3829
|
+
if (existingPathFragment === void 0) {
|
|
3830
|
+
if (obj[key] === void 0) {
|
|
3831
|
+
existingPathFragment = keys.slice(0, t).join("/");
|
|
3832
|
+
} else if (t == len - 1) {
|
|
3833
|
+
existingPathFragment = operation.path;
|
|
3834
|
+
}
|
|
3835
|
+
if (existingPathFragment !== void 0) {
|
|
3836
|
+
validateFunction(operation, 0, document, existingPathFragment);
|
|
3837
|
+
}
|
|
3838
|
+
}
|
|
3839
|
+
}
|
|
3840
|
+
t++;
|
|
3841
|
+
if (Array.isArray(obj)) {
|
|
3842
|
+
if (key === "-") {
|
|
3843
|
+
key = obj.length;
|
|
3844
|
+
} else {
|
|
3845
|
+
if (validateOperation && !isInteger(key)) {
|
|
3846
|
+
throw new JsonPatchError("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index", "OPERATION_PATH_ILLEGAL_ARRAY_INDEX", index, operation, document);
|
|
3847
|
+
} else if (isInteger(key)) {
|
|
3848
|
+
key = ~~key;
|
|
3849
|
+
}
|
|
3850
|
+
}
|
|
3851
|
+
if (t >= len) {
|
|
3852
|
+
if (validateOperation && operation.op === "add" && key > obj.length) {
|
|
3853
|
+
throw new JsonPatchError("The specified index MUST NOT be greater than the number of elements in the array", "OPERATION_VALUE_OUT_OF_BOUNDS", index, operation, document);
|
|
3854
|
+
}
|
|
3855
|
+
var returnValue = arrOps[operation.op].call(operation, obj, key, document);
|
|
3856
|
+
if (returnValue.test === false) {
|
|
3857
|
+
throw new JsonPatchError("Test operation failed", "TEST_OPERATION_FAILED", index, operation, document);
|
|
3858
|
+
}
|
|
3859
|
+
return returnValue;
|
|
3860
|
+
}
|
|
3861
|
+
} else {
|
|
3862
|
+
if (t >= len) {
|
|
3863
|
+
var returnValue = objOps[operation.op].call(operation, obj, key, document);
|
|
3864
|
+
if (returnValue.test === false) {
|
|
3865
|
+
throw new JsonPatchError("Test operation failed", "TEST_OPERATION_FAILED", index, operation, document);
|
|
3866
|
+
}
|
|
3867
|
+
return returnValue;
|
|
3868
|
+
}
|
|
3869
|
+
}
|
|
3870
|
+
obj = obj[key];
|
|
3871
|
+
if (validateOperation && t < len && (!obj || typeof obj !== "object")) {
|
|
3872
|
+
throw new JsonPatchError("Cannot perform operation at the desired path", "OPERATION_PATH_UNRESOLVABLE", index, operation, document);
|
|
3873
|
+
}
|
|
3874
|
+
}
|
|
3875
|
+
}
|
|
3876
|
+
}
|
|
3877
|
+
function applyPatch(document, patch, validateOperation, mutateDocument, banPrototypeModifications) {
|
|
3878
|
+
if (mutateDocument === void 0) {
|
|
3879
|
+
mutateDocument = true;
|
|
3880
|
+
}
|
|
3881
|
+
if (banPrototypeModifications === void 0) {
|
|
3882
|
+
banPrototypeModifications = true;
|
|
3883
|
+
}
|
|
3884
|
+
if (validateOperation) {
|
|
3885
|
+
if (!Array.isArray(patch)) {
|
|
3886
|
+
throw new JsonPatchError("Patch sequence must be an array", "SEQUENCE_NOT_AN_ARRAY");
|
|
3887
|
+
}
|
|
3888
|
+
}
|
|
3889
|
+
if (!mutateDocument) {
|
|
3890
|
+
document = _deepClone(document);
|
|
3891
|
+
}
|
|
3892
|
+
var results = new Array(patch.length);
|
|
3893
|
+
for (var i = 0, length_1 = patch.length; i < length_1; i++) {
|
|
3894
|
+
results[i] = applyOperation(document, patch[i], validateOperation, true, banPrototypeModifications, i);
|
|
3895
|
+
document = results[i].newDocument;
|
|
3896
|
+
}
|
|
3897
|
+
results.newDocument = document;
|
|
3898
|
+
return results;
|
|
3899
|
+
}
|
|
3900
|
+
function applyReducer(document, operation, index) {
|
|
3901
|
+
var operationResult = applyOperation(document, operation);
|
|
3902
|
+
if (operationResult.test === false) {
|
|
3903
|
+
throw new JsonPatchError("Test operation failed", "TEST_OPERATION_FAILED", index, operation, document);
|
|
3904
|
+
}
|
|
3905
|
+
return operationResult.newDocument;
|
|
3906
|
+
}
|
|
3907
|
+
function validator(operation, index, document, existingPathFragment) {
|
|
3908
|
+
if (typeof operation !== "object" || operation === null || Array.isArray(operation)) {
|
|
3909
|
+
throw new JsonPatchError("Operation is not an object", "OPERATION_NOT_AN_OBJECT", index, operation, document);
|
|
3910
|
+
} else if (!objOps[operation.op]) {
|
|
3911
|
+
throw new JsonPatchError("Operation `op` property is not one of operations defined in RFC-6902", "OPERATION_OP_INVALID", index, operation, document);
|
|
3912
|
+
} else if (typeof operation.path !== "string") {
|
|
3913
|
+
throw new JsonPatchError("Operation `path` property is not a string", "OPERATION_PATH_INVALID", index, operation, document);
|
|
3914
|
+
} else if (operation.path.indexOf("/") !== 0 && operation.path.length > 0) {
|
|
3915
|
+
throw new JsonPatchError('Operation `path` property must start with "/"', "OPERATION_PATH_INVALID", index, operation, document);
|
|
3916
|
+
} else if ((operation.op === "move" || operation.op === "copy") && typeof operation.from !== "string") {
|
|
3917
|
+
throw new JsonPatchError("Operation `from` property is not present (applicable in `move` and `copy` operations)", "OPERATION_FROM_REQUIRED", index, operation, document);
|
|
3918
|
+
} else if ((operation.op === "add" || operation.op === "replace" || operation.op === "test") && operation.value === void 0) {
|
|
3919
|
+
throw new JsonPatchError("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)", "OPERATION_VALUE_REQUIRED", index, operation, document);
|
|
3920
|
+
} else if ((operation.op === "add" || operation.op === "replace" || operation.op === "test") && hasUndefined(operation.value)) {
|
|
3921
|
+
throw new JsonPatchError("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)", "OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED", index, operation, document);
|
|
3922
|
+
} else if (document) {
|
|
3923
|
+
if (operation.op == "add") {
|
|
3924
|
+
var pathLen = operation.path.split("/").length;
|
|
3925
|
+
var existingPathLen = existingPathFragment.split("/").length;
|
|
3926
|
+
if (pathLen !== existingPathLen + 1 && pathLen !== existingPathLen) {
|
|
3927
|
+
throw new JsonPatchError("Cannot perform an `add` operation at the desired path", "OPERATION_PATH_CANNOT_ADD", index, operation, document);
|
|
3928
|
+
}
|
|
3929
|
+
} else if (operation.op === "replace" || operation.op === "remove" || operation.op === "_get") {
|
|
3930
|
+
if (operation.path !== existingPathFragment) {
|
|
3931
|
+
throw new JsonPatchError("Cannot perform the operation at a path that does not exist", "OPERATION_PATH_UNRESOLVABLE", index, operation, document);
|
|
3932
|
+
}
|
|
3933
|
+
} else if (operation.op === "move" || operation.op === "copy") {
|
|
3934
|
+
var existingValue = { op: "_get", path: operation.from, value: void 0 };
|
|
3935
|
+
var error = validate([existingValue], document);
|
|
3936
|
+
if (error && error.name === "OPERATION_PATH_UNRESOLVABLE") {
|
|
3937
|
+
throw new JsonPatchError("Cannot perform the operation from a path that does not exist", "OPERATION_FROM_UNRESOLVABLE", index, operation, document);
|
|
3938
|
+
}
|
|
3939
|
+
}
|
|
3940
|
+
}
|
|
3941
|
+
}
|
|
3942
|
+
function validate(sequence, document, externalValidator) {
|
|
3943
|
+
try {
|
|
3944
|
+
if (!Array.isArray(sequence)) {
|
|
3945
|
+
throw new JsonPatchError("Patch sequence must be an array", "SEQUENCE_NOT_AN_ARRAY");
|
|
3946
|
+
}
|
|
3947
|
+
if (document) {
|
|
3948
|
+
applyPatch(_deepClone(document), _deepClone(sequence), externalValidator || true);
|
|
3949
|
+
} else {
|
|
3950
|
+
externalValidator = externalValidator || validator;
|
|
3951
|
+
for (var i = 0; i < sequence.length; i++) {
|
|
3952
|
+
externalValidator(sequence[i], i, document, void 0);
|
|
3953
|
+
}
|
|
3954
|
+
}
|
|
3955
|
+
} catch (e) {
|
|
3956
|
+
if (e instanceof JsonPatchError) {
|
|
3957
|
+
return e;
|
|
3958
|
+
} else {
|
|
3959
|
+
throw e;
|
|
3960
|
+
}
|
|
3961
|
+
}
|
|
3962
|
+
}
|
|
3963
|
+
function _areEquals(a, b) {
|
|
3964
|
+
if (a === b)
|
|
3965
|
+
return true;
|
|
3966
|
+
if (a && b && typeof a == "object" && typeof b == "object") {
|
|
3967
|
+
var arrA = Array.isArray(a), arrB = Array.isArray(b), i, length, key;
|
|
3968
|
+
if (arrA && arrB) {
|
|
3969
|
+
length = a.length;
|
|
3970
|
+
if (length != b.length)
|
|
3971
|
+
return false;
|
|
3972
|
+
for (i = length; i-- !== 0; )
|
|
3973
|
+
if (!_areEquals(a[i], b[i]))
|
|
3974
|
+
return false;
|
|
3975
|
+
return true;
|
|
3976
|
+
}
|
|
3977
|
+
if (arrA != arrB)
|
|
3978
|
+
return false;
|
|
3979
|
+
var keys = Object.keys(a);
|
|
3980
|
+
length = keys.length;
|
|
3981
|
+
if (length !== Object.keys(b).length)
|
|
3982
|
+
return false;
|
|
3983
|
+
for (i = length; i-- !== 0; )
|
|
3984
|
+
if (!b.hasOwnProperty(keys[i]))
|
|
3985
|
+
return false;
|
|
3986
|
+
for (i = length; i-- !== 0; ) {
|
|
3987
|
+
key = keys[i];
|
|
3988
|
+
if (!_areEquals(a[key], b[key]))
|
|
3989
|
+
return false;
|
|
3990
|
+
}
|
|
3991
|
+
return true;
|
|
3992
|
+
}
|
|
3993
|
+
return a !== a && b !== b;
|
|
3994
|
+
}
|
|
3995
|
+
const core = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
3996
|
+
__proto__: null,
|
|
3997
|
+
JsonPatchError,
|
|
3998
|
+
_areEquals,
|
|
3999
|
+
applyOperation,
|
|
4000
|
+
applyPatch,
|
|
4001
|
+
applyReducer,
|
|
4002
|
+
deepClone,
|
|
4003
|
+
getValueByPointer,
|
|
4004
|
+
validate,
|
|
4005
|
+
validator
|
|
4006
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
4007
|
+
var beforeDict = /* @__PURE__ */ new WeakMap();
|
|
4008
|
+
var Mirror = (
|
|
4009
|
+
/** @class */
|
|
4010
|
+
/* @__PURE__ */ (function() {
|
|
4011
|
+
function Mirror2(obj) {
|
|
4012
|
+
this.observers = /* @__PURE__ */ new Map();
|
|
4013
|
+
this.obj = obj;
|
|
4014
|
+
}
|
|
4015
|
+
return Mirror2;
|
|
4016
|
+
})()
|
|
4017
|
+
);
|
|
4018
|
+
var ObserverInfo = (
|
|
4019
|
+
/** @class */
|
|
4020
|
+
/* @__PURE__ */ (function() {
|
|
4021
|
+
function ObserverInfo2(callback, observer) {
|
|
4022
|
+
this.callback = callback;
|
|
4023
|
+
this.observer = observer;
|
|
4024
|
+
}
|
|
4025
|
+
return ObserverInfo2;
|
|
4026
|
+
})()
|
|
4027
|
+
);
|
|
4028
|
+
function getMirror(obj) {
|
|
4029
|
+
return beforeDict.get(obj);
|
|
4030
|
+
}
|
|
4031
|
+
function getObserverFromMirror(mirror, callback) {
|
|
4032
|
+
return mirror.observers.get(callback);
|
|
4033
|
+
}
|
|
4034
|
+
function removeObserverFromMirror(mirror, observer) {
|
|
4035
|
+
mirror.observers.delete(observer.callback);
|
|
4036
|
+
}
|
|
4037
|
+
function unobserve(root, observer) {
|
|
4038
|
+
observer.unobserve();
|
|
4039
|
+
}
|
|
4040
|
+
function observe(obj, callback) {
|
|
4041
|
+
var patches = [];
|
|
4042
|
+
var observer;
|
|
4043
|
+
var mirror = getMirror(obj);
|
|
4044
|
+
if (!mirror) {
|
|
4045
|
+
mirror = new Mirror(obj);
|
|
4046
|
+
beforeDict.set(obj, mirror);
|
|
4047
|
+
} else {
|
|
4048
|
+
var observerInfo = getObserverFromMirror(mirror, callback);
|
|
4049
|
+
observer = observerInfo && observerInfo.observer;
|
|
4050
|
+
}
|
|
4051
|
+
if (observer) {
|
|
4052
|
+
return observer;
|
|
4053
|
+
}
|
|
4054
|
+
observer = {};
|
|
4055
|
+
mirror.value = _deepClone(obj);
|
|
4056
|
+
if (callback) {
|
|
4057
|
+
observer.callback = callback;
|
|
4058
|
+
observer.next = null;
|
|
4059
|
+
var dirtyCheck = function() {
|
|
4060
|
+
generate(observer);
|
|
4061
|
+
};
|
|
4062
|
+
var fastCheck = function() {
|
|
4063
|
+
clearTimeout(observer.next);
|
|
4064
|
+
observer.next = setTimeout(dirtyCheck);
|
|
4065
|
+
};
|
|
4066
|
+
if (typeof window !== "undefined") {
|
|
4067
|
+
window.addEventListener("mouseup", fastCheck);
|
|
4068
|
+
window.addEventListener("keyup", fastCheck);
|
|
4069
|
+
window.addEventListener("mousedown", fastCheck);
|
|
4070
|
+
window.addEventListener("keydown", fastCheck);
|
|
4071
|
+
window.addEventListener("change", fastCheck);
|
|
4072
|
+
}
|
|
4073
|
+
}
|
|
4074
|
+
observer.patches = patches;
|
|
4075
|
+
observer.object = obj;
|
|
4076
|
+
observer.unobserve = function() {
|
|
4077
|
+
generate(observer);
|
|
4078
|
+
clearTimeout(observer.next);
|
|
4079
|
+
removeObserverFromMirror(mirror, observer);
|
|
4080
|
+
if (typeof window !== "undefined") {
|
|
4081
|
+
window.removeEventListener("mouseup", fastCheck);
|
|
4082
|
+
window.removeEventListener("keyup", fastCheck);
|
|
4083
|
+
window.removeEventListener("mousedown", fastCheck);
|
|
4084
|
+
window.removeEventListener("keydown", fastCheck);
|
|
4085
|
+
window.removeEventListener("change", fastCheck);
|
|
4086
|
+
}
|
|
4087
|
+
};
|
|
4088
|
+
mirror.observers.set(callback, new ObserverInfo(callback, observer));
|
|
4089
|
+
return observer;
|
|
4090
|
+
}
|
|
4091
|
+
function generate(observer, invertible) {
|
|
4092
|
+
if (invertible === void 0) {
|
|
4093
|
+
invertible = false;
|
|
4094
|
+
}
|
|
4095
|
+
var mirror = beforeDict.get(observer.object);
|
|
4096
|
+
_generate(mirror.value, observer.object, observer.patches, "", invertible);
|
|
4097
|
+
if (observer.patches.length) {
|
|
4098
|
+
applyPatch(mirror.value, observer.patches);
|
|
4099
|
+
}
|
|
4100
|
+
var temp = observer.patches;
|
|
4101
|
+
if (temp.length > 0) {
|
|
4102
|
+
observer.patches = [];
|
|
4103
|
+
if (observer.callback) {
|
|
4104
|
+
observer.callback(temp);
|
|
4105
|
+
}
|
|
4106
|
+
}
|
|
4107
|
+
return temp;
|
|
4108
|
+
}
|
|
4109
|
+
function _generate(mirror, obj, patches, path, invertible) {
|
|
4110
|
+
if (obj === mirror) {
|
|
4111
|
+
return;
|
|
4112
|
+
}
|
|
4113
|
+
if (typeof obj.toJSON === "function") {
|
|
4114
|
+
obj = obj.toJSON();
|
|
4115
|
+
}
|
|
4116
|
+
var newKeys = _objectKeys(obj);
|
|
4117
|
+
var oldKeys = _objectKeys(mirror);
|
|
4118
|
+
var deleted = false;
|
|
4119
|
+
for (var t = oldKeys.length - 1; t >= 0; t--) {
|
|
4120
|
+
var key = oldKeys[t];
|
|
4121
|
+
var oldVal = mirror[key];
|
|
4122
|
+
if (hasOwnProperty(obj, key) && !(obj[key] === void 0 && oldVal !== void 0 && Array.isArray(obj) === false)) {
|
|
4123
|
+
var newVal = obj[key];
|
|
4124
|
+
if (typeof oldVal == "object" && oldVal != null && typeof newVal == "object" && newVal != null && Array.isArray(oldVal) === Array.isArray(newVal)) {
|
|
4125
|
+
_generate(oldVal, newVal, patches, path + "/" + escapePathComponent(key), invertible);
|
|
4126
|
+
} else {
|
|
4127
|
+
if (oldVal !== newVal) {
|
|
4128
|
+
if (invertible) {
|
|
4129
|
+
patches.push({ op: "test", path: path + "/" + escapePathComponent(key), value: _deepClone(oldVal) });
|
|
4130
|
+
}
|
|
4131
|
+
patches.push({ op: "replace", path: path + "/" + escapePathComponent(key), value: _deepClone(newVal) });
|
|
4132
|
+
}
|
|
4133
|
+
}
|
|
4134
|
+
} else if (Array.isArray(mirror) === Array.isArray(obj)) {
|
|
4135
|
+
if (invertible) {
|
|
4136
|
+
patches.push({ op: "test", path: path + "/" + escapePathComponent(key), value: _deepClone(oldVal) });
|
|
4137
|
+
}
|
|
4138
|
+
patches.push({ op: "remove", path: path + "/" + escapePathComponent(key) });
|
|
4139
|
+
deleted = true;
|
|
4140
|
+
} else {
|
|
4141
|
+
if (invertible) {
|
|
4142
|
+
patches.push({ op: "test", path, value: mirror });
|
|
4143
|
+
}
|
|
4144
|
+
patches.push({ op: "replace", path, value: obj });
|
|
4145
|
+
}
|
|
4146
|
+
}
|
|
4147
|
+
if (!deleted && newKeys.length == oldKeys.length) {
|
|
4148
|
+
return;
|
|
4149
|
+
}
|
|
4150
|
+
for (var t = 0; t < newKeys.length; t++) {
|
|
4151
|
+
var key = newKeys[t];
|
|
4152
|
+
if (!hasOwnProperty(mirror, key) && obj[key] !== void 0) {
|
|
4153
|
+
patches.push({ op: "add", path: path + "/" + escapePathComponent(key), value: _deepClone(obj[key]) });
|
|
4154
|
+
}
|
|
4155
|
+
}
|
|
4156
|
+
}
|
|
4157
|
+
function compare(tree1, tree2, invertible) {
|
|
4158
|
+
if (invertible === void 0) {
|
|
4159
|
+
invertible = false;
|
|
4160
|
+
}
|
|
4161
|
+
var patches = [];
|
|
4162
|
+
_generate(tree1, tree2, patches, "", invertible);
|
|
4163
|
+
return patches;
|
|
4164
|
+
}
|
|
4165
|
+
const duplex = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
4166
|
+
__proto__: null,
|
|
4167
|
+
compare,
|
|
4168
|
+
generate,
|
|
4169
|
+
observe,
|
|
4170
|
+
unobserve
|
|
4171
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
4172
|
+
const jsonpatch = Object.assign({}, core, duplex, {
|
|
4173
|
+
JsonPatchError: PatchError,
|
|
4174
|
+
deepClone: _deepClone,
|
|
4175
|
+
escapePathComponent,
|
|
4176
|
+
unescapePathComponent
|
|
4177
|
+
});
|
|
4178
|
+
const isContainer = (value) => typeof value === "object" && value !== null;
|
|
4179
|
+
function diff(prev, next) {
|
|
4180
|
+
if (isContainer(prev) && isContainer(next) && Array.isArray(prev) === Array.isArray(next))
|
|
4181
|
+
return jsonpatch.compare(prev, next);
|
|
4182
|
+
return Object.is(prev, next) ? [] : [{ op: "replace", path: "", value: next }];
|
|
4183
|
+
}
|
|
4184
|
+
function createSaver(save) {
|
|
4185
|
+
let running = Promise.resolve();
|
|
4186
|
+
let queued;
|
|
4187
|
+
return (change) => {
|
|
4188
|
+
if (queued) {
|
|
4189
|
+
queued.change = { state: change.state, previous: queued.change.previous, ops: [...queued.change.ops, ...change.ops] };
|
|
4190
|
+
return queued.saved;
|
|
4191
|
+
}
|
|
4192
|
+
const entry = { change };
|
|
4193
|
+
entry.saved = running.then(() => {
|
|
4194
|
+
if (queued === entry)
|
|
4195
|
+
queued = void 0;
|
|
4196
|
+
return save(entry.change);
|
|
4197
|
+
});
|
|
4198
|
+
queued = entry;
|
|
4199
|
+
running = entry.saved.catch(() => {
|
|
4200
|
+
});
|
|
4201
|
+
return entry.saved;
|
|
4202
|
+
};
|
|
4203
|
+
}
|
|
4204
|
+
async function createStore(channels, storage) {
|
|
4205
|
+
const names = Object.keys(channels);
|
|
4206
|
+
const state2 = {};
|
|
4207
|
+
const seqs = /* @__PURE__ */ new Map();
|
|
4208
|
+
const savers = /* @__PURE__ */ new Map();
|
|
4209
|
+
const listeners = /* @__PURE__ */ new Map();
|
|
4210
|
+
for (const channel2 of names) {
|
|
4211
|
+
const channelStorage = storage[channel2];
|
|
4212
|
+
if (!channelStorage)
|
|
4213
|
+
throw new Error(`no storage for state channel: ${String(channel2)}`);
|
|
4214
|
+
state2[channel2] = structuredClone(await channelStorage.load());
|
|
4215
|
+
seqs.set(channel2, 0);
|
|
4216
|
+
if (channelStorage.save)
|
|
4217
|
+
savers.set(channel2, createSaver(channelStorage.save.bind(channelStorage)));
|
|
4218
|
+
}
|
|
4219
|
+
function assertChannel(channel2) {
|
|
4220
|
+
if (!seqs.has(channel2))
|
|
4221
|
+
throw new Error(`unknown state channel: ${String(channel2)}`);
|
|
4222
|
+
}
|
|
4223
|
+
function set(partial) {
|
|
4224
|
+
const saves = [];
|
|
4225
|
+
for (const channel2 of Object.keys(partial)) {
|
|
4226
|
+
assertChannel(channel2);
|
|
4227
|
+
const next = structuredClone(partial[channel2]);
|
|
4228
|
+
const previous = state2[channel2];
|
|
4229
|
+
const ops = diff(previous, next);
|
|
4230
|
+
if (ops.length === 0)
|
|
4231
|
+
continue;
|
|
4232
|
+
state2[channel2] = next;
|
|
4233
|
+
const seq = seqs.get(channel2) + 1;
|
|
4234
|
+
seqs.set(channel2, seq);
|
|
4235
|
+
for (const listener of listeners.get(channel2) ?? [])
|
|
4236
|
+
listener({ seq, ops });
|
|
4237
|
+
const save = savers.get(channel2);
|
|
4238
|
+
if (save)
|
|
4239
|
+
saves.push(save({ state: next, previous, ops }));
|
|
4240
|
+
}
|
|
4241
|
+
const saved = Promise.all(saves).then(() => {
|
|
4242
|
+
});
|
|
4243
|
+
saved.catch(() => {
|
|
4244
|
+
});
|
|
4245
|
+
return saved;
|
|
4246
|
+
}
|
|
4247
|
+
return {
|
|
4248
|
+
get state() {
|
|
4249
|
+
return state2;
|
|
4250
|
+
},
|
|
4251
|
+
seq: (channel2) => {
|
|
4252
|
+
assertChannel(channel2);
|
|
4253
|
+
return seqs.get(channel2);
|
|
4254
|
+
},
|
|
4255
|
+
set,
|
|
4256
|
+
update(channel2, edit) {
|
|
4257
|
+
assertChannel(channel2);
|
|
4258
|
+
const draft = structuredClone(state2[channel2]);
|
|
4259
|
+
const result = edit(draft);
|
|
4260
|
+
return set({ [channel2]: result === void 0 ? draft : result });
|
|
4261
|
+
},
|
|
4262
|
+
watch(channel2, listener) {
|
|
4263
|
+
assertChannel(channel2);
|
|
4264
|
+
let channelListeners = listeners.get(channel2);
|
|
4265
|
+
if (!channelListeners)
|
|
4266
|
+
listeners.set(channel2, channelListeners = /* @__PURE__ */ new Set());
|
|
4267
|
+
channelListeners.add(listener);
|
|
4268
|
+
return {
|
|
4269
|
+
state: structuredClone(state2[channel2]),
|
|
4270
|
+
seq: seqs.get(channel2),
|
|
4271
|
+
dispose: () => {
|
|
4272
|
+
channelListeners.delete(listener);
|
|
4273
|
+
}
|
|
4274
|
+
};
|
|
4275
|
+
}
|
|
4276
|
+
};
|
|
4277
|
+
}
|
|
4278
|
+
const subscribeType = new apiExports.RequestType("$/state/subscribe");
|
|
4279
|
+
const unsubscribeType = new apiExports.NotificationType("$/state/unsubscribe");
|
|
4280
|
+
const patchType = new apiExports.NotificationType("$/state/patch");
|
|
4281
|
+
function serveStore(connection2, store) {
|
|
4282
|
+
const watches = /* @__PURE__ */ new Map();
|
|
4283
|
+
const unsubscribe = (channel2) => {
|
|
4284
|
+
watches.get(channel2)?.();
|
|
4285
|
+
watches.delete(channel2);
|
|
4286
|
+
};
|
|
4287
|
+
connection2.onRequest(subscribeType, ({ channel: channel2 }) => {
|
|
4288
|
+
unsubscribe(channel2);
|
|
4289
|
+
const watch = store.watch(channel2, (patch) => connection2.sendNotification(patchType, { channel: channel2, ...patch }));
|
|
4290
|
+
watches.set(channel2, watch.dispose);
|
|
4291
|
+
return { state: watch.state, seq: watch.seq };
|
|
3301
4292
|
});
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
4293
|
+
connection2.onNotification(unsubscribeType, ({ channel: channel2 }) => unsubscribe(channel2));
|
|
4294
|
+
const closeAll = () => {
|
|
4295
|
+
for (const channel2 of [...watches.keys()])
|
|
4296
|
+
unsubscribe(channel2);
|
|
4297
|
+
};
|
|
4298
|
+
connection2.onClose(closeAll);
|
|
4299
|
+
connection2.onDispose(closeAll);
|
|
4300
|
+
}
|
|
4301
|
+
function mirrorState(connection2, channels) {
|
|
4302
|
+
const mirrors = /* @__PURE__ */ new Map();
|
|
4303
|
+
const notify = (mirror) => {
|
|
4304
|
+
for (const listener of mirror.listeners)
|
|
4305
|
+
listener(mirror.state);
|
|
4306
|
+
};
|
|
4307
|
+
function apply(mirror, patch) {
|
|
4308
|
+
if (patch.seq <= mirror.seq)
|
|
4309
|
+
return;
|
|
4310
|
+
if (patch.seq !== mirror.seq + 1) {
|
|
4311
|
+
void resubscribe(patch.channel, mirror);
|
|
4312
|
+
return;
|
|
4313
|
+
}
|
|
4314
|
+
mirror.state = jsonpatch.applyPatch(mirror.state, patch.ops, false, false).newDocument;
|
|
4315
|
+
mirror.seq = patch.seq;
|
|
4316
|
+
notify(mirror);
|
|
4317
|
+
}
|
|
4318
|
+
async function resubscribe(channel2, mirror) {
|
|
4319
|
+
if (mirror.pending)
|
|
4320
|
+
return mirror.pending;
|
|
4321
|
+
mirror.pending = (async () => {
|
|
4322
|
+
try {
|
|
4323
|
+
const { state: state3, seq } = await connection2.sendRequest(subscribeType, { channel: channel2 });
|
|
4324
|
+
mirror.state = state3;
|
|
4325
|
+
mirror.seq = seq;
|
|
4326
|
+
} finally {
|
|
4327
|
+
mirror.pending = void 0;
|
|
4328
|
+
}
|
|
4329
|
+
const queued = mirror.queued.splice(0);
|
|
4330
|
+
notify(mirror);
|
|
4331
|
+
for (const patch of queued)
|
|
4332
|
+
apply(mirror, patch);
|
|
4333
|
+
})();
|
|
4334
|
+
return mirror.pending;
|
|
4335
|
+
}
|
|
4336
|
+
connection2.onNotification(patchType, (patch) => {
|
|
4337
|
+
const mirror = mirrors.get(patch.channel);
|
|
4338
|
+
if (!mirror)
|
|
4339
|
+
return;
|
|
4340
|
+
if (mirror.pending)
|
|
4341
|
+
mirror.queued.push(patch);
|
|
4342
|
+
else
|
|
4343
|
+
apply(mirror, patch);
|
|
3306
4344
|
});
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
}
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
4345
|
+
const state2 = {};
|
|
4346
|
+
for (const channel2 of Object.keys(channels)) {
|
|
4347
|
+
state2[channel2] = {
|
|
4348
|
+
get current() {
|
|
4349
|
+
return mirrors.get(channel2)?.state;
|
|
4350
|
+
},
|
|
4351
|
+
async subscribe(listener) {
|
|
4352
|
+
let mirror = mirrors.get(channel2);
|
|
4353
|
+
if (!mirror) {
|
|
4354
|
+
mirror = { listeners: /* @__PURE__ */ new Set(), seq: 0, queued: [] };
|
|
4355
|
+
mirrors.set(channel2, mirror);
|
|
4356
|
+
mirror.listeners.add(listener);
|
|
4357
|
+
try {
|
|
4358
|
+
await resubscribe(channel2, mirror);
|
|
4359
|
+
} catch (error) {
|
|
4360
|
+
mirrors.delete(channel2);
|
|
4361
|
+
throw error;
|
|
4362
|
+
}
|
|
4363
|
+
} else {
|
|
4364
|
+
mirror.listeners.add(listener);
|
|
4365
|
+
if (mirror.pending)
|
|
4366
|
+
await mirror.pending;
|
|
4367
|
+
else
|
|
4368
|
+
listener(mirror.state);
|
|
4369
|
+
}
|
|
4370
|
+
const subscribed = mirror;
|
|
4371
|
+
return () => {
|
|
4372
|
+
subscribed.listeners.delete(listener);
|
|
4373
|
+
if (subscribed.listeners.size > 0 || mirrors.get(channel2) !== subscribed)
|
|
4374
|
+
return;
|
|
4375
|
+
mirrors.delete(channel2);
|
|
4376
|
+
void connection2.sendNotification(unsubscribeType, { channel: channel2 }).catch(() => {
|
|
4377
|
+
});
|
|
4378
|
+
};
|
|
4379
|
+
}
|
|
4380
|
+
};
|
|
4381
|
+
}
|
|
4382
|
+
return state2;
|
|
4383
|
+
}
|
|
4384
|
+
const versionType = new apiExports.RequestType0("$/version");
|
|
4385
|
+
class ProtocolMismatch extends Error {
|
|
4386
|
+
}
|
|
4387
|
+
function serveVersion(connection2, identity) {
|
|
4388
|
+
connection2.onRequest(versionType, () => identity);
|
|
4389
|
+
}
|
|
4390
|
+
async function checkVersion(connection2, identity) {
|
|
4391
|
+
let theirs;
|
|
4392
|
+
try {
|
|
4393
|
+
theirs = await connection2.sendRequest(versionType);
|
|
4394
|
+
} catch (error) {
|
|
4395
|
+
if (error instanceof apiExports.ResponseError && error.code === apiExports.ErrorCodes.MethodNotFound)
|
|
4396
|
+
throw new ProtocolMismatch(`${identity.name} doesn't say which protocol it speaks, so it's older than this client (protocol ${identity.version}) - update it`);
|
|
4397
|
+
throw error;
|
|
4398
|
+
}
|
|
4399
|
+
if (theirs.name !== identity.name)
|
|
4400
|
+
throw new ProtocolMismatch(`expected ${identity.name}, but this is ${theirs.name}`);
|
|
4401
|
+
if (theirs.version !== identity.version)
|
|
4402
|
+
throw new ProtocolMismatch(`${identity.name} speaks protocol ${theirs.version}, but this client speaks ${identity.version} - update whichever is older`);
|
|
4403
|
+
}
|
|
4404
|
+
function mergeSides(a, b) {
|
|
4405
|
+
return {
|
|
4406
|
+
requests: { ...a.requests, ...b.requests },
|
|
4407
|
+
notifications: { ...a.notifications, ...b.notifications }
|
|
4408
|
+
};
|
|
4409
|
+
}
|
|
4410
|
+
function channel(outgoing, incoming) {
|
|
4411
|
+
return { outgoing, incoming };
|
|
4412
|
+
}
|
|
4413
|
+
function peer({ outgoing, incoming }, connection2) {
|
|
4414
|
+
const request2 = {};
|
|
4415
|
+
const notify = {};
|
|
4416
|
+
const onRequest = {};
|
|
4417
|
+
const onNotification = {};
|
|
4418
|
+
for (const [name, definition] of Object.entries(outgoing.requests)) {
|
|
4419
|
+
request2[name] = (params) => connection2.sendRequest(definition.type, params);
|
|
4420
|
+
}
|
|
4421
|
+
for (const [name, definition] of Object.entries(outgoing.notifications)) {
|
|
4422
|
+
notify[name] = (params) => connection2.sendNotification(definition.type, params);
|
|
4423
|
+
}
|
|
4424
|
+
for (const [name, definition] of Object.entries(incoming.requests)) {
|
|
4425
|
+
onRequest[name] = (handler) => connection2.onRequest(definition.type, handler);
|
|
4426
|
+
}
|
|
4427
|
+
for (const [name, definition] of Object.entries(incoming.notifications)) {
|
|
4428
|
+
onNotification[name] = (handler) => connection2.onNotification(definition.type, handler);
|
|
4429
|
+
}
|
|
4430
|
+
return {
|
|
4431
|
+
request: request2,
|
|
4432
|
+
notify,
|
|
4433
|
+
onRequest,
|
|
4434
|
+
onNotification,
|
|
4435
|
+
listen: () => connection2.listen(),
|
|
4436
|
+
dispose: () => connection2.dispose(),
|
|
4437
|
+
onClose: (listener) => {
|
|
4438
|
+
let ended = false;
|
|
4439
|
+
const end = () => {
|
|
4440
|
+
if (ended)
|
|
4441
|
+
return;
|
|
4442
|
+
ended = true;
|
|
4443
|
+
listener();
|
|
4444
|
+
};
|
|
4445
|
+
const closed = connection2.onClose(end);
|
|
4446
|
+
const disposed = connection2.onDispose(end);
|
|
4447
|
+
return { dispose: () => {
|
|
4448
|
+
closed.dispose();
|
|
4449
|
+
disposed.dispose();
|
|
4450
|
+
} };
|
|
4451
|
+
}
|
|
4452
|
+
};
|
|
4453
|
+
}
|
|
4454
|
+
function createRpcClient(channel2, connection2, states, identity) {
|
|
4455
|
+
return {
|
|
4456
|
+
...peer(channel2, connection2),
|
|
4457
|
+
state: mirrorState(connection2, states),
|
|
4458
|
+
checkVersion: async () => {
|
|
4459
|
+
if (identity)
|
|
4460
|
+
await checkVersion(connection2, identity);
|
|
4461
|
+
}
|
|
4462
|
+
};
|
|
4463
|
+
}
|
|
4464
|
+
function createRpcServer(channel2, connection2, store, identity) {
|
|
4465
|
+
if (store)
|
|
4466
|
+
serveStore(connection2, store);
|
|
4467
|
+
if (identity)
|
|
4468
|
+
serveVersion(connection2, identity);
|
|
4469
|
+
const state2 = store ? { get current() {
|
|
4470
|
+
return store.state;
|
|
4471
|
+
}, set: store.set, update: store.update } : {};
|
|
4472
|
+
return { ...peer(channel2, connection2), state: state2 };
|
|
4473
|
+
}
|
|
4474
|
+
function protocol(client, server, state2, identity, name) {
|
|
4475
|
+
function createServer(connection2, ...[store]) {
|
|
4476
|
+
return createRpcServer(server, connection2, store, identity);
|
|
4477
|
+
}
|
|
4478
|
+
return {
|
|
4479
|
+
client,
|
|
4480
|
+
server,
|
|
4481
|
+
state: state2,
|
|
4482
|
+
name,
|
|
4483
|
+
identity,
|
|
4484
|
+
createClient(connection2) {
|
|
4485
|
+
return createRpcClient(client, connection2, state2, identity);
|
|
4486
|
+
},
|
|
4487
|
+
createStore(storage) {
|
|
4488
|
+
return createStore(state2, storage);
|
|
4489
|
+
},
|
|
4490
|
+
createServer,
|
|
4491
|
+
accept(configure, ...store) {
|
|
4492
|
+
return (connection2) => {
|
|
4493
|
+
const rpc = createServer(connection2, ...store);
|
|
4494
|
+
configure?.(rpc);
|
|
4495
|
+
return rpc;
|
|
4496
|
+
};
|
|
4497
|
+
},
|
|
4498
|
+
defineHost({ configure, state: storage }) {
|
|
4499
|
+
return async () => {
|
|
4500
|
+
const store = storage ? await createStore(state2, storage) : void 0;
|
|
4501
|
+
const accept = (connection2) => {
|
|
4502
|
+
const rpc = createServer(connection2, ...[store]);
|
|
4503
|
+
configure?.(rpc, store);
|
|
4504
|
+
return rpc;
|
|
4505
|
+
};
|
|
4506
|
+
return { store, accept };
|
|
4507
|
+
};
|
|
4508
|
+
}
|
|
4509
|
+
};
|
|
4510
|
+
}
|
|
4511
|
+
function side(value) {
|
|
4512
|
+
return {
|
|
4513
|
+
requests: value?.requests ?? {},
|
|
4514
|
+
notifications: value?.notifications ?? {}
|
|
4515
|
+
};
|
|
4516
|
+
}
|
|
4517
|
+
function getSide(spec, key) {
|
|
4518
|
+
return spec[key] ?? side();
|
|
4519
|
+
}
|
|
4520
|
+
function request(method) {
|
|
4521
|
+
return { type: new apiExports.RequestType(method) };
|
|
4522
|
+
}
|
|
4523
|
+
function notification(method) {
|
|
4524
|
+
return { type: new apiExports.NotificationType(method) };
|
|
4525
|
+
}
|
|
4526
|
+
function state(name) {
|
|
4527
|
+
return { name };
|
|
4528
|
+
}
|
|
4529
|
+
function defineProtocol(factory) {
|
|
4530
|
+
const spec = factory({ side, request, notification, state });
|
|
4531
|
+
const clientToServer = getSide(spec, "clientToServer");
|
|
4532
|
+
const serverToClient = getSide(spec, "serverToClient");
|
|
4533
|
+
const eitherToEither = getSide(spec, "eitherToEither");
|
|
4534
|
+
const client = channel(mergeSides(clientToServer, eitherToEither), mergeSides(serverToClient, eitherToEither));
|
|
4535
|
+
const server = channel(mergeSides(serverToClient, eitherToEither), mergeSides(clientToServer, eitherToEither));
|
|
4536
|
+
const identity = spec.name !== void 0 && spec.version !== void 0 ? { name: spec.name, version: spec.version } : void 0;
|
|
4537
|
+
return protocol(client, server, spec.state ?? {}, identity, spec.name);
|
|
4538
|
+
}
|
|
4539
|
+
const cmdlessIPC = defineProtocol(({ side: side2, request: request2, notification: notification2 }) => ({
|
|
4540
|
+
clientToServer: side2({
|
|
4541
|
+
requests: {
|
|
4542
|
+
connect: request2("connect")
|
|
4543
|
+
},
|
|
4544
|
+
notifications: {
|
|
4545
|
+
resolve: notification2("resolve")
|
|
4546
|
+
}
|
|
4547
|
+
})
|
|
4548
|
+
}));
|
|
4549
|
+
const createElectronIPC = forElectronIPC("cmdless:rpc");
|
|
4550
|
+
const cmdlessViewIPC = defineProtocol(({ side: side2, request: request2, notification: notification2 }) => ({
|
|
4551
|
+
clientToServer: side2({
|
|
4552
|
+
requests: {
|
|
4553
|
+
props: request2("view/props")
|
|
4554
|
+
},
|
|
4555
|
+
notifications: {
|
|
4556
|
+
event: notification2("view/event"),
|
|
4557
|
+
close: notification2("view/close"),
|
|
4558
|
+
resize: notification2("view/resize")
|
|
4559
|
+
}
|
|
4560
|
+
}),
|
|
4561
|
+
serverToClient: side2({
|
|
4562
|
+
notifications: {
|
|
4563
|
+
update: notification2("view/update")
|
|
4564
|
+
}
|
|
4565
|
+
})
|
|
4566
|
+
}));
|
|
4567
|
+
const createElectronViewIPC = forElectronIPC("cmdless:view");
|
|
4568
|
+
const ipc = cmdlessIPC.createClient(createElectronIPC(electron.ipcRenderer));
|
|
4569
|
+
const view = cmdlessViewIPC.createClient(createElectronViewIPC(electron.ipcRenderer));
|
|
4570
|
+
async function connect() {
|
|
4571
|
+
const { url, token } = await ipc.request.connect();
|
|
4572
|
+
const socket = new WebSocket(`${url}/?token=${encodeURIComponent(token)}`);
|
|
4573
|
+
await new Promise((resolve, reject) => {
|
|
4574
|
+
socket.addEventListener("open", () => resolve(), { once: true });
|
|
4575
|
+
socket.addEventListener("error", () => reject(new Error("couldn't reach the window's backend")), { once: true });
|
|
3345
4576
|
});
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
4577
|
+
const early = [];
|
|
4578
|
+
let deliver;
|
|
4579
|
+
socket.addEventListener("message", (event) => {
|
|
4580
|
+
const message = String(event.data);
|
|
4581
|
+
if (deliver) deliver(message);
|
|
4582
|
+
else early.push(message);
|
|
3350
4583
|
});
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
}
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
}
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
});
|
|
4584
|
+
return {
|
|
4585
|
+
send: (message) => socket.send(message),
|
|
4586
|
+
onMessage: (listener) => {
|
|
4587
|
+
deliver = listener;
|
|
4588
|
+
for (const message of early.splice(0)) listener(message);
|
|
4589
|
+
},
|
|
4590
|
+
onClose: (listener) => socket.addEventListener("close", (event) => listener(event.code, event.reason)),
|
|
4591
|
+
close: () => socket.close()
|
|
4592
|
+
};
|
|
4593
|
+
}
|
|
4594
|
+
const cmdless = {
|
|
4595
|
+
resolve: (value, exitCode) => ipc.notify.resolve({ value, exitCode }),
|
|
4596
|
+
connect,
|
|
4597
|
+
view
|
|
4598
|
+
};
|
|
4599
|
+
electron.contextBridge.exposeInMainWorld("cmdless", cmdless);
|
|
4600
|
+
ipc.listen();
|
|
4601
|
+
view.listen();
|