@holochain/hc-spin 0.200.2 → 0.200.4

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.
@@ -7,6 +7,7 @@ const commander = require("commander");
7
7
  const contextMenu = require("electron-context-menu");
8
8
  const split = require("split");
9
9
  const childProcess = require("child_process");
10
+ const msgpack = require("@msgpack/msgpack");
10
11
  const url = require("url");
11
12
  const utils = require("@electron-toolkit/utils");
12
13
  const net$1 = require("node:net");
@@ -755,1573 +756,6 @@ var AppStatusFilter;
755
756
  AppStatusFilter2["Stopped"] = "stopped";
756
757
  AppStatusFilter2["Paused"] = "paused";
757
758
  })(AppStatusFilter || (AppStatusFilter = {}));
758
- var UINT32_MAX = 4294967295;
759
- function setUint64(view, offset, value) {
760
- var high = value / 4294967296;
761
- var low = value;
762
- view.setUint32(offset, high);
763
- view.setUint32(offset + 4, low);
764
- }
765
- function setInt64(view, offset, value) {
766
- var high = Math.floor(value / 4294967296);
767
- var low = value;
768
- view.setUint32(offset, high);
769
- view.setUint32(offset + 4, low);
770
- }
771
- function getInt64(view, offset) {
772
- var high = view.getInt32(offset);
773
- var low = view.getUint32(offset + 4);
774
- return high * 4294967296 + low;
775
- }
776
- function getUint64(view, offset) {
777
- var high = view.getUint32(offset);
778
- var low = view.getUint32(offset + 4);
779
- return high * 4294967296 + low;
780
- }
781
- var _a, _b, _c;
782
- var TEXT_ENCODING_AVAILABLE = (typeof process === "undefined" || ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a["TEXT_ENCODING"]) !== "never") && typeof TextEncoder !== "undefined" && typeof TextDecoder !== "undefined";
783
- function utf8Count(str) {
784
- var strLength = str.length;
785
- var byteLength = 0;
786
- var pos = 0;
787
- while (pos < strLength) {
788
- var value = str.charCodeAt(pos++);
789
- if ((value & 4294967168) === 0) {
790
- byteLength++;
791
- continue;
792
- } else if ((value & 4294965248) === 0) {
793
- byteLength += 2;
794
- } else {
795
- if (value >= 55296 && value <= 56319) {
796
- if (pos < strLength) {
797
- var extra = str.charCodeAt(pos);
798
- if ((extra & 64512) === 56320) {
799
- ++pos;
800
- value = ((value & 1023) << 10) + (extra & 1023) + 65536;
801
- }
802
- }
803
- }
804
- if ((value & 4294901760) === 0) {
805
- byteLength += 3;
806
- } else {
807
- byteLength += 4;
808
- }
809
- }
810
- }
811
- return byteLength;
812
- }
813
- function utf8EncodeJs(str, output, outputOffset) {
814
- var strLength = str.length;
815
- var offset = outputOffset;
816
- var pos = 0;
817
- while (pos < strLength) {
818
- var value = str.charCodeAt(pos++);
819
- if ((value & 4294967168) === 0) {
820
- output[offset++] = value;
821
- continue;
822
- } else if ((value & 4294965248) === 0) {
823
- output[offset++] = value >> 6 & 31 | 192;
824
- } else {
825
- if (value >= 55296 && value <= 56319) {
826
- if (pos < strLength) {
827
- var extra = str.charCodeAt(pos);
828
- if ((extra & 64512) === 56320) {
829
- ++pos;
830
- value = ((value & 1023) << 10) + (extra & 1023) + 65536;
831
- }
832
- }
833
- }
834
- if ((value & 4294901760) === 0) {
835
- output[offset++] = value >> 12 & 15 | 224;
836
- output[offset++] = value >> 6 & 63 | 128;
837
- } else {
838
- output[offset++] = value >> 18 & 7 | 240;
839
- output[offset++] = value >> 12 & 63 | 128;
840
- output[offset++] = value >> 6 & 63 | 128;
841
- }
842
- }
843
- output[offset++] = value & 63 | 128;
844
- }
845
- }
846
- var sharedTextEncoder = TEXT_ENCODING_AVAILABLE ? new TextEncoder() : void 0;
847
- var TEXT_ENCODER_THRESHOLD = !TEXT_ENCODING_AVAILABLE ? UINT32_MAX : typeof process !== "undefined" && ((_b = process === null || process === void 0 ? void 0 : process.env) === null || _b === void 0 ? void 0 : _b["TEXT_ENCODING"]) !== "force" ? 200 : 0;
848
- function utf8EncodeTEencode(str, output, outputOffset) {
849
- output.set(sharedTextEncoder.encode(str), outputOffset);
850
- }
851
- function utf8EncodeTEencodeInto(str, output, outputOffset) {
852
- sharedTextEncoder.encodeInto(str, output.subarray(outputOffset));
853
- }
854
- var utf8EncodeTE = (sharedTextEncoder === null || sharedTextEncoder === void 0 ? void 0 : sharedTextEncoder.encodeInto) ? utf8EncodeTEencodeInto : utf8EncodeTEencode;
855
- var CHUNK_SIZE = 4096;
856
- function utf8DecodeJs(bytes, inputOffset, byteLength) {
857
- var offset = inputOffset;
858
- var end = offset + byteLength;
859
- var units = [];
860
- var result = "";
861
- while (offset < end) {
862
- var byte1 = bytes[offset++];
863
- if ((byte1 & 128) === 0) {
864
- units.push(byte1);
865
- } else if ((byte1 & 224) === 192) {
866
- var byte2 = bytes[offset++] & 63;
867
- units.push((byte1 & 31) << 6 | byte2);
868
- } else if ((byte1 & 240) === 224) {
869
- var byte2 = bytes[offset++] & 63;
870
- var byte3 = bytes[offset++] & 63;
871
- units.push((byte1 & 31) << 12 | byte2 << 6 | byte3);
872
- } else if ((byte1 & 248) === 240) {
873
- var byte2 = bytes[offset++] & 63;
874
- var byte3 = bytes[offset++] & 63;
875
- var byte4 = bytes[offset++] & 63;
876
- var unit = (byte1 & 7) << 18 | byte2 << 12 | byte3 << 6 | byte4;
877
- if (unit > 65535) {
878
- unit -= 65536;
879
- units.push(unit >>> 10 & 1023 | 55296);
880
- unit = 56320 | unit & 1023;
881
- }
882
- units.push(unit);
883
- } else {
884
- units.push(byte1);
885
- }
886
- if (units.length >= CHUNK_SIZE) {
887
- result += String.fromCharCode.apply(String, units);
888
- units.length = 0;
889
- }
890
- }
891
- if (units.length > 0) {
892
- result += String.fromCharCode.apply(String, units);
893
- }
894
- return result;
895
- }
896
- var sharedTextDecoder = TEXT_ENCODING_AVAILABLE ? new TextDecoder() : null;
897
- var TEXT_DECODER_THRESHOLD = !TEXT_ENCODING_AVAILABLE ? UINT32_MAX : typeof process !== "undefined" && ((_c = process === null || process === void 0 ? void 0 : process.env) === null || _c === void 0 ? void 0 : _c["TEXT_DECODER"]) !== "force" ? 200 : 0;
898
- function utf8DecodeTD(bytes, inputOffset, byteLength) {
899
- var stringBytes = bytes.subarray(inputOffset, inputOffset + byteLength);
900
- return sharedTextDecoder.decode(stringBytes);
901
- }
902
- var ExtData = (
903
- /** @class */
904
- /* @__PURE__ */ function() {
905
- function ExtData2(type, data) {
906
- this.type = type;
907
- this.data = data;
908
- }
909
- return ExtData2;
910
- }()
911
- );
912
- var __extends = /* @__PURE__ */ function() {
913
- var extendStatics = function(d, b) {
914
- extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
915
- d2.__proto__ = b2;
916
- } || function(d2, b2) {
917
- for (var p in b2)
918
- if (Object.prototype.hasOwnProperty.call(b2, p))
919
- d2[p] = b2[p];
920
- };
921
- return extendStatics(d, b);
922
- };
923
- return function(d, b) {
924
- if (typeof b !== "function" && b !== null)
925
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
926
- extendStatics(d, b);
927
- function __() {
928
- this.constructor = d;
929
- }
930
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
931
- };
932
- }();
933
- var DecodeError = (
934
- /** @class */
935
- function(_super) {
936
- __extends(DecodeError2, _super);
937
- function DecodeError2(message) {
938
- var _this = _super.call(this, message) || this;
939
- var proto = Object.create(DecodeError2.prototype);
940
- Object.setPrototypeOf(_this, proto);
941
- Object.defineProperty(_this, "name", {
942
- configurable: true,
943
- enumerable: false,
944
- value: DecodeError2.name
945
- });
946
- return _this;
947
- }
948
- return DecodeError2;
949
- }(Error)
950
- );
951
- var EXT_TIMESTAMP = -1;
952
- var TIMESTAMP32_MAX_SEC = 4294967296 - 1;
953
- var TIMESTAMP64_MAX_SEC = 17179869184 - 1;
954
- function encodeTimeSpecToTimestamp(_a2) {
955
- var sec = _a2.sec, nsec = _a2.nsec;
956
- if (sec >= 0 && nsec >= 0 && sec <= TIMESTAMP64_MAX_SEC) {
957
- if (nsec === 0 && sec <= TIMESTAMP32_MAX_SEC) {
958
- var rv = new Uint8Array(4);
959
- var view = new DataView(rv.buffer);
960
- view.setUint32(0, sec);
961
- return rv;
962
- } else {
963
- var secHigh = sec / 4294967296;
964
- var secLow = sec & 4294967295;
965
- var rv = new Uint8Array(8);
966
- var view = new DataView(rv.buffer);
967
- view.setUint32(0, nsec << 2 | secHigh & 3);
968
- view.setUint32(4, secLow);
969
- return rv;
970
- }
971
- } else {
972
- var rv = new Uint8Array(12);
973
- var view = new DataView(rv.buffer);
974
- view.setUint32(0, nsec);
975
- setInt64(view, 4, sec);
976
- return rv;
977
- }
978
- }
979
- function encodeDateToTimeSpec(date) {
980
- var msec = date.getTime();
981
- var sec = Math.floor(msec / 1e3);
982
- var nsec = (msec - sec * 1e3) * 1e6;
983
- var nsecInSec = Math.floor(nsec / 1e9);
984
- return {
985
- sec: sec + nsecInSec,
986
- nsec: nsec - nsecInSec * 1e9
987
- };
988
- }
989
- function encodeTimestampExtension(object) {
990
- if (object instanceof Date) {
991
- var timeSpec = encodeDateToTimeSpec(object);
992
- return encodeTimeSpecToTimestamp(timeSpec);
993
- } else {
994
- return null;
995
- }
996
- }
997
- function decodeTimestampToTimeSpec(data) {
998
- var view = new DataView(data.buffer, data.byteOffset, data.byteLength);
999
- switch (data.byteLength) {
1000
- case 4: {
1001
- var sec = view.getUint32(0);
1002
- var nsec = 0;
1003
- return { sec, nsec };
1004
- }
1005
- case 8: {
1006
- var nsec30AndSecHigh2 = view.getUint32(0);
1007
- var secLow32 = view.getUint32(4);
1008
- var sec = (nsec30AndSecHigh2 & 3) * 4294967296 + secLow32;
1009
- var nsec = nsec30AndSecHigh2 >>> 2;
1010
- return { sec, nsec };
1011
- }
1012
- case 12: {
1013
- var sec = getInt64(view, 4);
1014
- var nsec = view.getUint32(0);
1015
- return { sec, nsec };
1016
- }
1017
- default:
1018
- throw new DecodeError("Unrecognized data size for timestamp (expected 4, 8, or 12): ".concat(data.length));
1019
- }
1020
- }
1021
- function decodeTimestampExtension(data) {
1022
- var timeSpec = decodeTimestampToTimeSpec(data);
1023
- return new Date(timeSpec.sec * 1e3 + timeSpec.nsec / 1e6);
1024
- }
1025
- var timestampExtension = {
1026
- type: EXT_TIMESTAMP,
1027
- encode: encodeTimestampExtension,
1028
- decode: decodeTimestampExtension
1029
- };
1030
- var ExtensionCodec = (
1031
- /** @class */
1032
- function() {
1033
- function ExtensionCodec2() {
1034
- this.builtInEncoders = [];
1035
- this.builtInDecoders = [];
1036
- this.encoders = [];
1037
- this.decoders = [];
1038
- this.register(timestampExtension);
1039
- }
1040
- ExtensionCodec2.prototype.register = function(_a2) {
1041
- var type = _a2.type, encode2 = _a2.encode, decode2 = _a2.decode;
1042
- if (type >= 0) {
1043
- this.encoders[type] = encode2;
1044
- this.decoders[type] = decode2;
1045
- } else {
1046
- var index = 1 + type;
1047
- this.builtInEncoders[index] = encode2;
1048
- this.builtInDecoders[index] = decode2;
1049
- }
1050
- };
1051
- ExtensionCodec2.prototype.tryToEncode = function(object, context) {
1052
- for (var i = 0; i < this.builtInEncoders.length; i++) {
1053
- var encodeExt = this.builtInEncoders[i];
1054
- if (encodeExt != null) {
1055
- var data = encodeExt(object, context);
1056
- if (data != null) {
1057
- var type = -1 - i;
1058
- return new ExtData(type, data);
1059
- }
1060
- }
1061
- }
1062
- for (var i = 0; i < this.encoders.length; i++) {
1063
- var encodeExt = this.encoders[i];
1064
- if (encodeExt != null) {
1065
- var data = encodeExt(object, context);
1066
- if (data != null) {
1067
- var type = i;
1068
- return new ExtData(type, data);
1069
- }
1070
- }
1071
- }
1072
- if (object instanceof ExtData) {
1073
- return object;
1074
- }
1075
- return null;
1076
- };
1077
- ExtensionCodec2.prototype.decode = function(data, type, context) {
1078
- var decodeExt = type < 0 ? this.builtInDecoders[-1 - type] : this.decoders[type];
1079
- if (decodeExt) {
1080
- return decodeExt(data, type, context);
1081
- } else {
1082
- return new ExtData(type, data);
1083
- }
1084
- };
1085
- ExtensionCodec2.defaultCodec = new ExtensionCodec2();
1086
- return ExtensionCodec2;
1087
- }()
1088
- );
1089
- function ensureUint8Array(buffer) {
1090
- if (buffer instanceof Uint8Array) {
1091
- return buffer;
1092
- } else if (ArrayBuffer.isView(buffer)) {
1093
- return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1094
- } else if (buffer instanceof ArrayBuffer) {
1095
- return new Uint8Array(buffer);
1096
- } else {
1097
- return Uint8Array.from(buffer);
1098
- }
1099
- }
1100
- function createDataView(buffer) {
1101
- if (buffer instanceof ArrayBuffer) {
1102
- return new DataView(buffer);
1103
- }
1104
- var bufferView = ensureUint8Array(buffer);
1105
- return new DataView(bufferView.buffer, bufferView.byteOffset, bufferView.byteLength);
1106
- }
1107
- var DEFAULT_MAX_DEPTH = 100;
1108
- var DEFAULT_INITIAL_BUFFER_SIZE = 2048;
1109
- var Encoder = (
1110
- /** @class */
1111
- function() {
1112
- function Encoder2(extensionCodec, context, maxDepth, initialBufferSize, sortKeys, forceFloat32, ignoreUndefined, forceIntegerToFloat) {
1113
- if (extensionCodec === void 0) {
1114
- extensionCodec = ExtensionCodec.defaultCodec;
1115
- }
1116
- if (context === void 0) {
1117
- context = void 0;
1118
- }
1119
- if (maxDepth === void 0) {
1120
- maxDepth = DEFAULT_MAX_DEPTH;
1121
- }
1122
- if (initialBufferSize === void 0) {
1123
- initialBufferSize = DEFAULT_INITIAL_BUFFER_SIZE;
1124
- }
1125
- if (sortKeys === void 0) {
1126
- sortKeys = false;
1127
- }
1128
- if (forceFloat32 === void 0) {
1129
- forceFloat32 = false;
1130
- }
1131
- if (ignoreUndefined === void 0) {
1132
- ignoreUndefined = false;
1133
- }
1134
- if (forceIntegerToFloat === void 0) {
1135
- forceIntegerToFloat = false;
1136
- }
1137
- this.extensionCodec = extensionCodec;
1138
- this.context = context;
1139
- this.maxDepth = maxDepth;
1140
- this.initialBufferSize = initialBufferSize;
1141
- this.sortKeys = sortKeys;
1142
- this.forceFloat32 = forceFloat32;
1143
- this.ignoreUndefined = ignoreUndefined;
1144
- this.forceIntegerToFloat = forceIntegerToFloat;
1145
- this.pos = 0;
1146
- this.view = new DataView(new ArrayBuffer(this.initialBufferSize));
1147
- this.bytes = new Uint8Array(this.view.buffer);
1148
- }
1149
- Encoder2.prototype.reinitializeState = function() {
1150
- this.pos = 0;
1151
- };
1152
- Encoder2.prototype.encodeSharedRef = function(object) {
1153
- this.reinitializeState();
1154
- this.doEncode(object, 1);
1155
- return this.bytes.subarray(0, this.pos);
1156
- };
1157
- Encoder2.prototype.encode = function(object) {
1158
- this.reinitializeState();
1159
- this.doEncode(object, 1);
1160
- return this.bytes.slice(0, this.pos);
1161
- };
1162
- Encoder2.prototype.doEncode = function(object, depth) {
1163
- if (depth > this.maxDepth) {
1164
- throw new Error("Too deep objects in depth ".concat(depth));
1165
- }
1166
- if (object == null) {
1167
- this.encodeNil();
1168
- } else if (typeof object === "boolean") {
1169
- this.encodeBoolean(object);
1170
- } else if (typeof object === "number") {
1171
- this.encodeNumber(object);
1172
- } else if (typeof object === "string") {
1173
- this.encodeString(object);
1174
- } else {
1175
- this.encodeObject(object, depth);
1176
- }
1177
- };
1178
- Encoder2.prototype.ensureBufferSizeToWrite = function(sizeToWrite) {
1179
- var requiredSize = this.pos + sizeToWrite;
1180
- if (this.view.byteLength < requiredSize) {
1181
- this.resizeBuffer(requiredSize * 2);
1182
- }
1183
- };
1184
- Encoder2.prototype.resizeBuffer = function(newSize) {
1185
- var newBuffer = new ArrayBuffer(newSize);
1186
- var newBytes = new Uint8Array(newBuffer);
1187
- var newView = new DataView(newBuffer);
1188
- newBytes.set(this.bytes);
1189
- this.view = newView;
1190
- this.bytes = newBytes;
1191
- };
1192
- Encoder2.prototype.encodeNil = function() {
1193
- this.writeU8(192);
1194
- };
1195
- Encoder2.prototype.encodeBoolean = function(object) {
1196
- if (object === false) {
1197
- this.writeU8(194);
1198
- } else {
1199
- this.writeU8(195);
1200
- }
1201
- };
1202
- Encoder2.prototype.encodeNumber = function(object) {
1203
- if (Number.isSafeInteger(object) && !this.forceIntegerToFloat) {
1204
- if (object >= 0) {
1205
- if (object < 128) {
1206
- this.writeU8(object);
1207
- } else if (object < 256) {
1208
- this.writeU8(204);
1209
- this.writeU8(object);
1210
- } else if (object < 65536) {
1211
- this.writeU8(205);
1212
- this.writeU16(object);
1213
- } else if (object < 4294967296) {
1214
- this.writeU8(206);
1215
- this.writeU32(object);
1216
- } else {
1217
- this.writeU8(207);
1218
- this.writeU64(object);
1219
- }
1220
- } else {
1221
- if (object >= -32) {
1222
- this.writeU8(224 | object + 32);
1223
- } else if (object >= -128) {
1224
- this.writeU8(208);
1225
- this.writeI8(object);
1226
- } else if (object >= -32768) {
1227
- this.writeU8(209);
1228
- this.writeI16(object);
1229
- } else if (object >= -2147483648) {
1230
- this.writeU8(210);
1231
- this.writeI32(object);
1232
- } else {
1233
- this.writeU8(211);
1234
- this.writeI64(object);
1235
- }
1236
- }
1237
- } else {
1238
- if (this.forceFloat32) {
1239
- this.writeU8(202);
1240
- this.writeF32(object);
1241
- } else {
1242
- this.writeU8(203);
1243
- this.writeF64(object);
1244
- }
1245
- }
1246
- };
1247
- Encoder2.prototype.writeStringHeader = function(byteLength) {
1248
- if (byteLength < 32) {
1249
- this.writeU8(160 + byteLength);
1250
- } else if (byteLength < 256) {
1251
- this.writeU8(217);
1252
- this.writeU8(byteLength);
1253
- } else if (byteLength < 65536) {
1254
- this.writeU8(218);
1255
- this.writeU16(byteLength);
1256
- } else if (byteLength < 4294967296) {
1257
- this.writeU8(219);
1258
- this.writeU32(byteLength);
1259
- } else {
1260
- throw new Error("Too long string: ".concat(byteLength, " bytes in UTF-8"));
1261
- }
1262
- };
1263
- Encoder2.prototype.encodeString = function(object) {
1264
- var maxHeaderSize = 1 + 4;
1265
- var strLength = object.length;
1266
- if (strLength > TEXT_ENCODER_THRESHOLD) {
1267
- var byteLength = utf8Count(object);
1268
- this.ensureBufferSizeToWrite(maxHeaderSize + byteLength);
1269
- this.writeStringHeader(byteLength);
1270
- utf8EncodeTE(object, this.bytes, this.pos);
1271
- this.pos += byteLength;
1272
- } else {
1273
- var byteLength = utf8Count(object);
1274
- this.ensureBufferSizeToWrite(maxHeaderSize + byteLength);
1275
- this.writeStringHeader(byteLength);
1276
- utf8EncodeJs(object, this.bytes, this.pos);
1277
- this.pos += byteLength;
1278
- }
1279
- };
1280
- Encoder2.prototype.encodeObject = function(object, depth) {
1281
- var ext = this.extensionCodec.tryToEncode(object, this.context);
1282
- if (ext != null) {
1283
- this.encodeExtension(ext);
1284
- } else if (Array.isArray(object)) {
1285
- this.encodeArray(object, depth);
1286
- } else if (ArrayBuffer.isView(object)) {
1287
- this.encodeBinary(object);
1288
- } else if (typeof object === "object") {
1289
- this.encodeMap(object, depth);
1290
- } else {
1291
- throw new Error("Unrecognized object: ".concat(Object.prototype.toString.apply(object)));
1292
- }
1293
- };
1294
- Encoder2.prototype.encodeBinary = function(object) {
1295
- var size = object.byteLength;
1296
- if (size < 256) {
1297
- this.writeU8(196);
1298
- this.writeU8(size);
1299
- } else if (size < 65536) {
1300
- this.writeU8(197);
1301
- this.writeU16(size);
1302
- } else if (size < 4294967296) {
1303
- this.writeU8(198);
1304
- this.writeU32(size);
1305
- } else {
1306
- throw new Error("Too large binary: ".concat(size));
1307
- }
1308
- var bytes = ensureUint8Array(object);
1309
- this.writeU8a(bytes);
1310
- };
1311
- Encoder2.prototype.encodeArray = function(object, depth) {
1312
- var size = object.length;
1313
- if (size < 16) {
1314
- this.writeU8(144 + size);
1315
- } else if (size < 65536) {
1316
- this.writeU8(220);
1317
- this.writeU16(size);
1318
- } else if (size < 4294967296) {
1319
- this.writeU8(221);
1320
- this.writeU32(size);
1321
- } else {
1322
- throw new Error("Too large array: ".concat(size));
1323
- }
1324
- for (var _i = 0, object_1 = object; _i < object_1.length; _i++) {
1325
- var item = object_1[_i];
1326
- this.doEncode(item, depth + 1);
1327
- }
1328
- };
1329
- Encoder2.prototype.countWithoutUndefined = function(object, keys) {
1330
- var count = 0;
1331
- for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
1332
- var key = keys_1[_i];
1333
- if (object[key] !== void 0) {
1334
- count++;
1335
- }
1336
- }
1337
- return count;
1338
- };
1339
- Encoder2.prototype.encodeMap = function(object, depth) {
1340
- var keys = Object.keys(object);
1341
- if (this.sortKeys) {
1342
- keys.sort();
1343
- }
1344
- var size = this.ignoreUndefined ? this.countWithoutUndefined(object, keys) : keys.length;
1345
- if (size < 16) {
1346
- this.writeU8(128 + size);
1347
- } else if (size < 65536) {
1348
- this.writeU8(222);
1349
- this.writeU16(size);
1350
- } else if (size < 4294967296) {
1351
- this.writeU8(223);
1352
- this.writeU32(size);
1353
- } else {
1354
- throw new Error("Too large map object: ".concat(size));
1355
- }
1356
- for (var _i = 0, keys_2 = keys; _i < keys_2.length; _i++) {
1357
- var key = keys_2[_i];
1358
- var value = object[key];
1359
- if (!(this.ignoreUndefined && value === void 0)) {
1360
- this.encodeString(key);
1361
- this.doEncode(value, depth + 1);
1362
- }
1363
- }
1364
- };
1365
- Encoder2.prototype.encodeExtension = function(ext) {
1366
- var size = ext.data.length;
1367
- if (size === 1) {
1368
- this.writeU8(212);
1369
- } else if (size === 2) {
1370
- this.writeU8(213);
1371
- } else if (size === 4) {
1372
- this.writeU8(214);
1373
- } else if (size === 8) {
1374
- this.writeU8(215);
1375
- } else if (size === 16) {
1376
- this.writeU8(216);
1377
- } else if (size < 256) {
1378
- this.writeU8(199);
1379
- this.writeU8(size);
1380
- } else if (size < 65536) {
1381
- this.writeU8(200);
1382
- this.writeU16(size);
1383
- } else if (size < 4294967296) {
1384
- this.writeU8(201);
1385
- this.writeU32(size);
1386
- } else {
1387
- throw new Error("Too large extension object: ".concat(size));
1388
- }
1389
- this.writeI8(ext.type);
1390
- this.writeU8a(ext.data);
1391
- };
1392
- Encoder2.prototype.writeU8 = function(value) {
1393
- this.ensureBufferSizeToWrite(1);
1394
- this.view.setUint8(this.pos, value);
1395
- this.pos++;
1396
- };
1397
- Encoder2.prototype.writeU8a = function(values) {
1398
- var size = values.length;
1399
- this.ensureBufferSizeToWrite(size);
1400
- this.bytes.set(values, this.pos);
1401
- this.pos += size;
1402
- };
1403
- Encoder2.prototype.writeI8 = function(value) {
1404
- this.ensureBufferSizeToWrite(1);
1405
- this.view.setInt8(this.pos, value);
1406
- this.pos++;
1407
- };
1408
- Encoder2.prototype.writeU16 = function(value) {
1409
- this.ensureBufferSizeToWrite(2);
1410
- this.view.setUint16(this.pos, value);
1411
- this.pos += 2;
1412
- };
1413
- Encoder2.prototype.writeI16 = function(value) {
1414
- this.ensureBufferSizeToWrite(2);
1415
- this.view.setInt16(this.pos, value);
1416
- this.pos += 2;
1417
- };
1418
- Encoder2.prototype.writeU32 = function(value) {
1419
- this.ensureBufferSizeToWrite(4);
1420
- this.view.setUint32(this.pos, value);
1421
- this.pos += 4;
1422
- };
1423
- Encoder2.prototype.writeI32 = function(value) {
1424
- this.ensureBufferSizeToWrite(4);
1425
- this.view.setInt32(this.pos, value);
1426
- this.pos += 4;
1427
- };
1428
- Encoder2.prototype.writeF32 = function(value) {
1429
- this.ensureBufferSizeToWrite(4);
1430
- this.view.setFloat32(this.pos, value);
1431
- this.pos += 4;
1432
- };
1433
- Encoder2.prototype.writeF64 = function(value) {
1434
- this.ensureBufferSizeToWrite(8);
1435
- this.view.setFloat64(this.pos, value);
1436
- this.pos += 8;
1437
- };
1438
- Encoder2.prototype.writeU64 = function(value) {
1439
- this.ensureBufferSizeToWrite(8);
1440
- setUint64(this.view, this.pos, value);
1441
- this.pos += 8;
1442
- };
1443
- Encoder2.prototype.writeI64 = function(value) {
1444
- this.ensureBufferSizeToWrite(8);
1445
- setInt64(this.view, this.pos, value);
1446
- this.pos += 8;
1447
- };
1448
- return Encoder2;
1449
- }()
1450
- );
1451
- var defaultEncodeOptions = {};
1452
- function encode$1(value, options) {
1453
- if (options === void 0) {
1454
- options = defaultEncodeOptions;
1455
- }
1456
- var encoder = new Encoder(options.extensionCodec, options.context, options.maxDepth, options.initialBufferSize, options.sortKeys, options.forceFloat32, options.ignoreUndefined, options.forceIntegerToFloat);
1457
- return encoder.encodeSharedRef(value);
1458
- }
1459
- function prettyByte(byte) {
1460
- return "".concat(byte < 0 ? "-" : "", "0x").concat(Math.abs(byte).toString(16).padStart(2, "0"));
1461
- }
1462
- var DEFAULT_MAX_KEY_LENGTH = 16;
1463
- var DEFAULT_MAX_LENGTH_PER_KEY = 16;
1464
- var CachedKeyDecoder = (
1465
- /** @class */
1466
- function() {
1467
- function CachedKeyDecoder2(maxKeyLength, maxLengthPerKey) {
1468
- if (maxKeyLength === void 0) {
1469
- maxKeyLength = DEFAULT_MAX_KEY_LENGTH;
1470
- }
1471
- if (maxLengthPerKey === void 0) {
1472
- maxLengthPerKey = DEFAULT_MAX_LENGTH_PER_KEY;
1473
- }
1474
- this.maxKeyLength = maxKeyLength;
1475
- this.maxLengthPerKey = maxLengthPerKey;
1476
- this.hit = 0;
1477
- this.miss = 0;
1478
- this.caches = [];
1479
- for (var i = 0; i < this.maxKeyLength; i++) {
1480
- this.caches.push([]);
1481
- }
1482
- }
1483
- CachedKeyDecoder2.prototype.canBeCached = function(byteLength) {
1484
- return byteLength > 0 && byteLength <= this.maxKeyLength;
1485
- };
1486
- CachedKeyDecoder2.prototype.find = function(bytes, inputOffset, byteLength) {
1487
- var records = this.caches[byteLength - 1];
1488
- FIND_CHUNK:
1489
- for (var _i = 0, records_1 = records; _i < records_1.length; _i++) {
1490
- var record = records_1[_i];
1491
- var recordBytes = record.bytes;
1492
- for (var j = 0; j < byteLength; j++) {
1493
- if (recordBytes[j] !== bytes[inputOffset + j]) {
1494
- continue FIND_CHUNK;
1495
- }
1496
- }
1497
- return record.str;
1498
- }
1499
- return null;
1500
- };
1501
- CachedKeyDecoder2.prototype.store = function(bytes, value) {
1502
- var records = this.caches[bytes.length - 1];
1503
- var record = { bytes, str: value };
1504
- if (records.length >= this.maxLengthPerKey) {
1505
- records[Math.random() * records.length | 0] = record;
1506
- } else {
1507
- records.push(record);
1508
- }
1509
- };
1510
- CachedKeyDecoder2.prototype.decode = function(bytes, inputOffset, byteLength) {
1511
- var cachedValue = this.find(bytes, inputOffset, byteLength);
1512
- if (cachedValue != null) {
1513
- this.hit++;
1514
- return cachedValue;
1515
- }
1516
- this.miss++;
1517
- var str = utf8DecodeJs(bytes, inputOffset, byteLength);
1518
- var slicedCopyOfBytes = Uint8Array.prototype.slice.call(bytes, inputOffset, inputOffset + byteLength);
1519
- this.store(slicedCopyOfBytes, str);
1520
- return str;
1521
- };
1522
- return CachedKeyDecoder2;
1523
- }()
1524
- );
1525
- var __awaiter = function(thisArg, _arguments, P, generator) {
1526
- function adopt(value) {
1527
- return value instanceof P ? value : new P(function(resolve) {
1528
- resolve(value);
1529
- });
1530
- }
1531
- return new (P || (P = Promise))(function(resolve, reject) {
1532
- function fulfilled(value) {
1533
- try {
1534
- step(generator.next(value));
1535
- } catch (e) {
1536
- reject(e);
1537
- }
1538
- }
1539
- function rejected(value) {
1540
- try {
1541
- step(generator["throw"](value));
1542
- } catch (e) {
1543
- reject(e);
1544
- }
1545
- }
1546
- function step(result) {
1547
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
1548
- }
1549
- step((generator = generator.apply(thisArg, _arguments || [])).next());
1550
- });
1551
- };
1552
- var __generator = function(thisArg, body) {
1553
- var _ = { label: 0, sent: function() {
1554
- if (t[0] & 1)
1555
- throw t[1];
1556
- return t[1];
1557
- }, trys: [], ops: [] }, f, y, t, g;
1558
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
1559
- return this;
1560
- }), g;
1561
- function verb(n) {
1562
- return function(v2) {
1563
- return step([n, v2]);
1564
- };
1565
- }
1566
- function step(op) {
1567
- if (f)
1568
- throw new TypeError("Generator is already executing.");
1569
- while (_)
1570
- try {
1571
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
1572
- return t;
1573
- if (y = 0, t)
1574
- op = [op[0] & 2, t.value];
1575
- switch (op[0]) {
1576
- case 0:
1577
- case 1:
1578
- t = op;
1579
- break;
1580
- case 4:
1581
- _.label++;
1582
- return { value: op[1], done: false };
1583
- case 5:
1584
- _.label++;
1585
- y = op[1];
1586
- op = [0];
1587
- continue;
1588
- case 7:
1589
- op = _.ops.pop();
1590
- _.trys.pop();
1591
- continue;
1592
- default:
1593
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
1594
- _ = 0;
1595
- continue;
1596
- }
1597
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
1598
- _.label = op[1];
1599
- break;
1600
- }
1601
- if (op[0] === 6 && _.label < t[1]) {
1602
- _.label = t[1];
1603
- t = op;
1604
- break;
1605
- }
1606
- if (t && _.label < t[2]) {
1607
- _.label = t[2];
1608
- _.ops.push(op);
1609
- break;
1610
- }
1611
- if (t[2])
1612
- _.ops.pop();
1613
- _.trys.pop();
1614
- continue;
1615
- }
1616
- op = body.call(thisArg, _);
1617
- } catch (e) {
1618
- op = [6, e];
1619
- y = 0;
1620
- } finally {
1621
- f = t = 0;
1622
- }
1623
- if (op[0] & 5)
1624
- throw op[1];
1625
- return { value: op[0] ? op[1] : void 0, done: true };
1626
- }
1627
- };
1628
- var __asyncValues = function(o) {
1629
- if (!Symbol.asyncIterator)
1630
- throw new TypeError("Symbol.asyncIterator is not defined.");
1631
- var m2 = o[Symbol.asyncIterator], i;
1632
- return m2 ? m2.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() {
1633
- return this;
1634
- }, i);
1635
- function verb(n) {
1636
- i[n] = o[n] && function(v2) {
1637
- return new Promise(function(resolve, reject) {
1638
- v2 = o[n](v2), settle(resolve, reject, v2.done, v2.value);
1639
- });
1640
- };
1641
- }
1642
- function settle(resolve, reject, d, v2) {
1643
- Promise.resolve(v2).then(function(v3) {
1644
- resolve({ value: v3, done: d });
1645
- }, reject);
1646
- }
1647
- };
1648
- var __await = function(v2) {
1649
- return this instanceof __await ? (this.v = v2, this) : new __await(v2);
1650
- };
1651
- var __asyncGenerator = function(thisArg, _arguments, generator) {
1652
- if (!Symbol.asyncIterator)
1653
- throw new TypeError("Symbol.asyncIterator is not defined.");
1654
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
1655
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() {
1656
- return this;
1657
- }, i;
1658
- function verb(n) {
1659
- if (g[n])
1660
- i[n] = function(v2) {
1661
- return new Promise(function(a, b) {
1662
- q.push([n, v2, a, b]) > 1 || resume2(n, v2);
1663
- });
1664
- };
1665
- }
1666
- function resume2(n, v2) {
1667
- try {
1668
- step(g[n](v2));
1669
- } catch (e) {
1670
- settle(q[0][3], e);
1671
- }
1672
- }
1673
- function step(r) {
1674
- r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
1675
- }
1676
- function fulfill(value) {
1677
- resume2("next", value);
1678
- }
1679
- function reject(value) {
1680
- resume2("throw", value);
1681
- }
1682
- function settle(f, v2) {
1683
- if (f(v2), q.shift(), q.length)
1684
- resume2(q[0][0], q[0][1]);
1685
- }
1686
- };
1687
- var isValidMapKeyType = function(key) {
1688
- var keyType = typeof key;
1689
- return keyType === "string" || keyType === "number";
1690
- };
1691
- var HEAD_BYTE_REQUIRED = -1;
1692
- var EMPTY_VIEW = new DataView(new ArrayBuffer(0));
1693
- var EMPTY_BYTES = new Uint8Array(EMPTY_VIEW.buffer);
1694
- var DataViewIndexOutOfBoundsError = function() {
1695
- try {
1696
- EMPTY_VIEW.getInt8(0);
1697
- } catch (e) {
1698
- return e.constructor;
1699
- }
1700
- throw new Error("never reached");
1701
- }();
1702
- var MORE_DATA = new DataViewIndexOutOfBoundsError("Insufficient data");
1703
- var sharedCachedKeyDecoder = new CachedKeyDecoder();
1704
- var Decoder = (
1705
- /** @class */
1706
- function() {
1707
- function Decoder2(extensionCodec, context, maxStrLength, maxBinLength, maxArrayLength, maxMapLength, maxExtLength, keyDecoder) {
1708
- if (extensionCodec === void 0) {
1709
- extensionCodec = ExtensionCodec.defaultCodec;
1710
- }
1711
- if (context === void 0) {
1712
- context = void 0;
1713
- }
1714
- if (maxStrLength === void 0) {
1715
- maxStrLength = UINT32_MAX;
1716
- }
1717
- if (maxBinLength === void 0) {
1718
- maxBinLength = UINT32_MAX;
1719
- }
1720
- if (maxArrayLength === void 0) {
1721
- maxArrayLength = UINT32_MAX;
1722
- }
1723
- if (maxMapLength === void 0) {
1724
- maxMapLength = UINT32_MAX;
1725
- }
1726
- if (maxExtLength === void 0) {
1727
- maxExtLength = UINT32_MAX;
1728
- }
1729
- if (keyDecoder === void 0) {
1730
- keyDecoder = sharedCachedKeyDecoder;
1731
- }
1732
- this.extensionCodec = extensionCodec;
1733
- this.context = context;
1734
- this.maxStrLength = maxStrLength;
1735
- this.maxBinLength = maxBinLength;
1736
- this.maxArrayLength = maxArrayLength;
1737
- this.maxMapLength = maxMapLength;
1738
- this.maxExtLength = maxExtLength;
1739
- this.keyDecoder = keyDecoder;
1740
- this.totalPos = 0;
1741
- this.pos = 0;
1742
- this.view = EMPTY_VIEW;
1743
- this.bytes = EMPTY_BYTES;
1744
- this.headByte = HEAD_BYTE_REQUIRED;
1745
- this.stack = [];
1746
- }
1747
- Decoder2.prototype.reinitializeState = function() {
1748
- this.totalPos = 0;
1749
- this.headByte = HEAD_BYTE_REQUIRED;
1750
- this.stack.length = 0;
1751
- };
1752
- Decoder2.prototype.setBuffer = function(buffer) {
1753
- this.bytes = ensureUint8Array(buffer);
1754
- this.view = createDataView(this.bytes);
1755
- this.pos = 0;
1756
- };
1757
- Decoder2.prototype.appendBuffer = function(buffer) {
1758
- if (this.headByte === HEAD_BYTE_REQUIRED && !this.hasRemaining(1)) {
1759
- this.setBuffer(buffer);
1760
- } else {
1761
- var remainingData = this.bytes.subarray(this.pos);
1762
- var newData = ensureUint8Array(buffer);
1763
- var newBuffer = new Uint8Array(remainingData.length + newData.length);
1764
- newBuffer.set(remainingData);
1765
- newBuffer.set(newData, remainingData.length);
1766
- this.setBuffer(newBuffer);
1767
- }
1768
- };
1769
- Decoder2.prototype.hasRemaining = function(size) {
1770
- return this.view.byteLength - this.pos >= size;
1771
- };
1772
- Decoder2.prototype.createExtraByteError = function(posToShow) {
1773
- var _a2 = this, view = _a2.view, pos = _a2.pos;
1774
- return new RangeError("Extra ".concat(view.byteLength - pos, " of ").concat(view.byteLength, " byte(s) found at buffer[").concat(posToShow, "]"));
1775
- };
1776
- Decoder2.prototype.decode = function(buffer) {
1777
- this.reinitializeState();
1778
- this.setBuffer(buffer);
1779
- var object = this.doDecodeSync();
1780
- if (this.hasRemaining(1)) {
1781
- throw this.createExtraByteError(this.pos);
1782
- }
1783
- return object;
1784
- };
1785
- Decoder2.prototype.decodeMulti = function(buffer) {
1786
- return __generator(this, function(_a2) {
1787
- switch (_a2.label) {
1788
- case 0:
1789
- this.reinitializeState();
1790
- this.setBuffer(buffer);
1791
- _a2.label = 1;
1792
- case 1:
1793
- if (!this.hasRemaining(1))
1794
- return [3, 3];
1795
- return [4, this.doDecodeSync()];
1796
- case 2:
1797
- _a2.sent();
1798
- return [3, 1];
1799
- case 3:
1800
- return [
1801
- 2
1802
- /*return*/
1803
- ];
1804
- }
1805
- });
1806
- };
1807
- Decoder2.prototype.decodeAsync = function(stream2) {
1808
- var stream_1, stream_1_1;
1809
- var e_1, _a2;
1810
- return __awaiter(this, void 0, void 0, function() {
1811
- var decoded, object, buffer, e_1_1, _b2, headByte, pos, totalPos;
1812
- return __generator(this, function(_c2) {
1813
- switch (_c2.label) {
1814
- case 0:
1815
- decoded = false;
1816
- _c2.label = 1;
1817
- case 1:
1818
- _c2.trys.push([1, 6, 7, 12]);
1819
- stream_1 = __asyncValues(stream2);
1820
- _c2.label = 2;
1821
- case 2:
1822
- return [4, stream_1.next()];
1823
- case 3:
1824
- if (!(stream_1_1 = _c2.sent(), !stream_1_1.done))
1825
- return [3, 5];
1826
- buffer = stream_1_1.value;
1827
- if (decoded) {
1828
- throw this.createExtraByteError(this.totalPos);
1829
- }
1830
- this.appendBuffer(buffer);
1831
- try {
1832
- object = this.doDecodeSync();
1833
- decoded = true;
1834
- } catch (e) {
1835
- if (!(e instanceof DataViewIndexOutOfBoundsError)) {
1836
- throw e;
1837
- }
1838
- }
1839
- this.totalPos += this.pos;
1840
- _c2.label = 4;
1841
- case 4:
1842
- return [3, 2];
1843
- case 5:
1844
- return [3, 12];
1845
- case 6:
1846
- e_1_1 = _c2.sent();
1847
- e_1 = { error: e_1_1 };
1848
- return [3, 12];
1849
- case 7:
1850
- _c2.trys.push([7, , 10, 11]);
1851
- if (!(stream_1_1 && !stream_1_1.done && (_a2 = stream_1.return)))
1852
- return [3, 9];
1853
- return [4, _a2.call(stream_1)];
1854
- case 8:
1855
- _c2.sent();
1856
- _c2.label = 9;
1857
- case 9:
1858
- return [3, 11];
1859
- case 10:
1860
- if (e_1)
1861
- throw e_1.error;
1862
- return [
1863
- 7
1864
- /*endfinally*/
1865
- ];
1866
- case 11:
1867
- return [
1868
- 7
1869
- /*endfinally*/
1870
- ];
1871
- case 12:
1872
- if (decoded) {
1873
- if (this.hasRemaining(1)) {
1874
- throw this.createExtraByteError(this.totalPos);
1875
- }
1876
- return [2, object];
1877
- }
1878
- _b2 = this, headByte = _b2.headByte, pos = _b2.pos, totalPos = _b2.totalPos;
1879
- throw new RangeError("Insufficient data in parsing ".concat(prettyByte(headByte), " at ").concat(totalPos, " (").concat(pos, " in the current buffer)"));
1880
- }
1881
- });
1882
- });
1883
- };
1884
- Decoder2.prototype.decodeArrayStream = function(stream2) {
1885
- return this.decodeMultiAsync(stream2, true);
1886
- };
1887
- Decoder2.prototype.decodeStream = function(stream2) {
1888
- return this.decodeMultiAsync(stream2, false);
1889
- };
1890
- Decoder2.prototype.decodeMultiAsync = function(stream2, isArray) {
1891
- return __asyncGenerator(this, arguments, function decodeMultiAsync_1() {
1892
- var isArrayHeaderRequired, arrayItemsLeft, stream_2, stream_2_1, buffer, e_2, e_3_1;
1893
- var e_3, _a2;
1894
- return __generator(this, function(_b2) {
1895
- switch (_b2.label) {
1896
- case 0:
1897
- isArrayHeaderRequired = isArray;
1898
- arrayItemsLeft = -1;
1899
- _b2.label = 1;
1900
- case 1:
1901
- _b2.trys.push([1, 13, 14, 19]);
1902
- stream_2 = __asyncValues(stream2);
1903
- _b2.label = 2;
1904
- case 2:
1905
- return [4, __await(stream_2.next())];
1906
- case 3:
1907
- if (!(stream_2_1 = _b2.sent(), !stream_2_1.done))
1908
- return [3, 12];
1909
- buffer = stream_2_1.value;
1910
- if (isArray && arrayItemsLeft === 0) {
1911
- throw this.createExtraByteError(this.totalPos);
1912
- }
1913
- this.appendBuffer(buffer);
1914
- if (isArrayHeaderRequired) {
1915
- arrayItemsLeft = this.readArraySize();
1916
- isArrayHeaderRequired = false;
1917
- this.complete();
1918
- }
1919
- _b2.label = 4;
1920
- case 4:
1921
- _b2.trys.push([4, 9, , 10]);
1922
- _b2.label = 5;
1923
- case 5:
1924
- return [4, __await(this.doDecodeSync())];
1925
- case 6:
1926
- return [4, _b2.sent()];
1927
- case 7:
1928
- _b2.sent();
1929
- if (--arrayItemsLeft === 0) {
1930
- return [3, 8];
1931
- }
1932
- return [3, 5];
1933
- case 8:
1934
- return [3, 10];
1935
- case 9:
1936
- e_2 = _b2.sent();
1937
- if (!(e_2 instanceof DataViewIndexOutOfBoundsError)) {
1938
- throw e_2;
1939
- }
1940
- return [3, 10];
1941
- case 10:
1942
- this.totalPos += this.pos;
1943
- _b2.label = 11;
1944
- case 11:
1945
- return [3, 2];
1946
- case 12:
1947
- return [3, 19];
1948
- case 13:
1949
- e_3_1 = _b2.sent();
1950
- e_3 = { error: e_3_1 };
1951
- return [3, 19];
1952
- case 14:
1953
- _b2.trys.push([14, , 17, 18]);
1954
- if (!(stream_2_1 && !stream_2_1.done && (_a2 = stream_2.return)))
1955
- return [3, 16];
1956
- return [4, __await(_a2.call(stream_2))];
1957
- case 15:
1958
- _b2.sent();
1959
- _b2.label = 16;
1960
- case 16:
1961
- return [3, 18];
1962
- case 17:
1963
- if (e_3)
1964
- throw e_3.error;
1965
- return [
1966
- 7
1967
- /*endfinally*/
1968
- ];
1969
- case 18:
1970
- return [
1971
- 7
1972
- /*endfinally*/
1973
- ];
1974
- case 19:
1975
- return [
1976
- 2
1977
- /*return*/
1978
- ];
1979
- }
1980
- });
1981
- });
1982
- };
1983
- Decoder2.prototype.doDecodeSync = function() {
1984
- DECODE:
1985
- while (true) {
1986
- var headByte = this.readHeadByte();
1987
- var object = void 0;
1988
- if (headByte >= 224) {
1989
- object = headByte - 256;
1990
- } else if (headByte < 192) {
1991
- if (headByte < 128) {
1992
- object = headByte;
1993
- } else if (headByte < 144) {
1994
- var size = headByte - 128;
1995
- if (size !== 0) {
1996
- this.pushMapState(size);
1997
- this.complete();
1998
- continue DECODE;
1999
- } else {
2000
- object = {};
2001
- }
2002
- } else if (headByte < 160) {
2003
- var size = headByte - 144;
2004
- if (size !== 0) {
2005
- this.pushArrayState(size);
2006
- this.complete();
2007
- continue DECODE;
2008
- } else {
2009
- object = [];
2010
- }
2011
- } else {
2012
- var byteLength = headByte - 160;
2013
- object = this.decodeUtf8String(byteLength, 0);
2014
- }
2015
- } else if (headByte === 192) {
2016
- object = null;
2017
- } else if (headByte === 194) {
2018
- object = false;
2019
- } else if (headByte === 195) {
2020
- object = true;
2021
- } else if (headByte === 202) {
2022
- object = this.readF32();
2023
- } else if (headByte === 203) {
2024
- object = this.readF64();
2025
- } else if (headByte === 204) {
2026
- object = this.readU8();
2027
- } else if (headByte === 205) {
2028
- object = this.readU16();
2029
- } else if (headByte === 206) {
2030
- object = this.readU32();
2031
- } else if (headByte === 207) {
2032
- object = this.readU64();
2033
- } else if (headByte === 208) {
2034
- object = this.readI8();
2035
- } else if (headByte === 209) {
2036
- object = this.readI16();
2037
- } else if (headByte === 210) {
2038
- object = this.readI32();
2039
- } else if (headByte === 211) {
2040
- object = this.readI64();
2041
- } else if (headByte === 217) {
2042
- var byteLength = this.lookU8();
2043
- object = this.decodeUtf8String(byteLength, 1);
2044
- } else if (headByte === 218) {
2045
- var byteLength = this.lookU16();
2046
- object = this.decodeUtf8String(byteLength, 2);
2047
- } else if (headByte === 219) {
2048
- var byteLength = this.lookU32();
2049
- object = this.decodeUtf8String(byteLength, 4);
2050
- } else if (headByte === 220) {
2051
- var size = this.readU16();
2052
- if (size !== 0) {
2053
- this.pushArrayState(size);
2054
- this.complete();
2055
- continue DECODE;
2056
- } else {
2057
- object = [];
2058
- }
2059
- } else if (headByte === 221) {
2060
- var size = this.readU32();
2061
- if (size !== 0) {
2062
- this.pushArrayState(size);
2063
- this.complete();
2064
- continue DECODE;
2065
- } else {
2066
- object = [];
2067
- }
2068
- } else if (headByte === 222) {
2069
- var size = this.readU16();
2070
- if (size !== 0) {
2071
- this.pushMapState(size);
2072
- this.complete();
2073
- continue DECODE;
2074
- } else {
2075
- object = {};
2076
- }
2077
- } else if (headByte === 223) {
2078
- var size = this.readU32();
2079
- if (size !== 0) {
2080
- this.pushMapState(size);
2081
- this.complete();
2082
- continue DECODE;
2083
- } else {
2084
- object = {};
2085
- }
2086
- } else if (headByte === 196) {
2087
- var size = this.lookU8();
2088
- object = this.decodeBinary(size, 1);
2089
- } else if (headByte === 197) {
2090
- var size = this.lookU16();
2091
- object = this.decodeBinary(size, 2);
2092
- } else if (headByte === 198) {
2093
- var size = this.lookU32();
2094
- object = this.decodeBinary(size, 4);
2095
- } else if (headByte === 212) {
2096
- object = this.decodeExtension(1, 0);
2097
- } else if (headByte === 213) {
2098
- object = this.decodeExtension(2, 0);
2099
- } else if (headByte === 214) {
2100
- object = this.decodeExtension(4, 0);
2101
- } else if (headByte === 215) {
2102
- object = this.decodeExtension(8, 0);
2103
- } else if (headByte === 216) {
2104
- object = this.decodeExtension(16, 0);
2105
- } else if (headByte === 199) {
2106
- var size = this.lookU8();
2107
- object = this.decodeExtension(size, 1);
2108
- } else if (headByte === 200) {
2109
- var size = this.lookU16();
2110
- object = this.decodeExtension(size, 2);
2111
- } else if (headByte === 201) {
2112
- var size = this.lookU32();
2113
- object = this.decodeExtension(size, 4);
2114
- } else {
2115
- throw new DecodeError("Unrecognized type byte: ".concat(prettyByte(headByte)));
2116
- }
2117
- this.complete();
2118
- var stack = this.stack;
2119
- while (stack.length > 0) {
2120
- var state = stack[stack.length - 1];
2121
- if (state.type === 0) {
2122
- state.array[state.position] = object;
2123
- state.position++;
2124
- if (state.position === state.size) {
2125
- stack.pop();
2126
- object = state.array;
2127
- } else {
2128
- continue DECODE;
2129
- }
2130
- } else if (state.type === 1) {
2131
- if (!isValidMapKeyType(object)) {
2132
- throw new DecodeError("The type of key must be string or number but " + typeof object);
2133
- }
2134
- if (object === "__proto__") {
2135
- throw new DecodeError("The key __proto__ is not allowed");
2136
- }
2137
- state.key = object;
2138
- state.type = 2;
2139
- continue DECODE;
2140
- } else {
2141
- state.map[state.key] = object;
2142
- state.readCount++;
2143
- if (state.readCount === state.size) {
2144
- stack.pop();
2145
- object = state.map;
2146
- } else {
2147
- state.key = null;
2148
- state.type = 1;
2149
- continue DECODE;
2150
- }
2151
- }
2152
- }
2153
- return object;
2154
- }
2155
- };
2156
- Decoder2.prototype.readHeadByte = function() {
2157
- if (this.headByte === HEAD_BYTE_REQUIRED) {
2158
- this.headByte = this.readU8();
2159
- }
2160
- return this.headByte;
2161
- };
2162
- Decoder2.prototype.complete = function() {
2163
- this.headByte = HEAD_BYTE_REQUIRED;
2164
- };
2165
- Decoder2.prototype.readArraySize = function() {
2166
- var headByte = this.readHeadByte();
2167
- switch (headByte) {
2168
- case 220:
2169
- return this.readU16();
2170
- case 221:
2171
- return this.readU32();
2172
- default: {
2173
- if (headByte < 160) {
2174
- return headByte - 144;
2175
- } else {
2176
- throw new DecodeError("Unrecognized array type byte: ".concat(prettyByte(headByte)));
2177
- }
2178
- }
2179
- }
2180
- };
2181
- Decoder2.prototype.pushMapState = function(size) {
2182
- if (size > this.maxMapLength) {
2183
- throw new DecodeError("Max length exceeded: map length (".concat(size, ") > maxMapLengthLength (").concat(this.maxMapLength, ")"));
2184
- }
2185
- this.stack.push({
2186
- type: 1,
2187
- size,
2188
- key: null,
2189
- readCount: 0,
2190
- map: {}
2191
- });
2192
- };
2193
- Decoder2.prototype.pushArrayState = function(size) {
2194
- if (size > this.maxArrayLength) {
2195
- throw new DecodeError("Max length exceeded: array length (".concat(size, ") > maxArrayLength (").concat(this.maxArrayLength, ")"));
2196
- }
2197
- this.stack.push({
2198
- type: 0,
2199
- size,
2200
- array: new Array(size),
2201
- position: 0
2202
- });
2203
- };
2204
- Decoder2.prototype.decodeUtf8String = function(byteLength, headerOffset) {
2205
- var _a2;
2206
- if (byteLength > this.maxStrLength) {
2207
- throw new DecodeError("Max length exceeded: UTF-8 byte length (".concat(byteLength, ") > maxStrLength (").concat(this.maxStrLength, ")"));
2208
- }
2209
- if (this.bytes.byteLength < this.pos + headerOffset + byteLength) {
2210
- throw MORE_DATA;
2211
- }
2212
- var offset = this.pos + headerOffset;
2213
- var object;
2214
- if (this.stateIsMapKey() && ((_a2 = this.keyDecoder) === null || _a2 === void 0 ? void 0 : _a2.canBeCached(byteLength))) {
2215
- object = this.keyDecoder.decode(this.bytes, offset, byteLength);
2216
- } else if (byteLength > TEXT_DECODER_THRESHOLD) {
2217
- object = utf8DecodeTD(this.bytes, offset, byteLength);
2218
- } else {
2219
- object = utf8DecodeJs(this.bytes, offset, byteLength);
2220
- }
2221
- this.pos += headerOffset + byteLength;
2222
- return object;
2223
- };
2224
- Decoder2.prototype.stateIsMapKey = function() {
2225
- if (this.stack.length > 0) {
2226
- var state = this.stack[this.stack.length - 1];
2227
- return state.type === 1;
2228
- }
2229
- return false;
2230
- };
2231
- Decoder2.prototype.decodeBinary = function(byteLength, headOffset) {
2232
- if (byteLength > this.maxBinLength) {
2233
- throw new DecodeError("Max length exceeded: bin length (".concat(byteLength, ") > maxBinLength (").concat(this.maxBinLength, ")"));
2234
- }
2235
- if (!this.hasRemaining(byteLength + headOffset)) {
2236
- throw MORE_DATA;
2237
- }
2238
- var offset = this.pos + headOffset;
2239
- var object = this.bytes.subarray(offset, offset + byteLength);
2240
- this.pos += headOffset + byteLength;
2241
- return object;
2242
- };
2243
- Decoder2.prototype.decodeExtension = function(size, headOffset) {
2244
- if (size > this.maxExtLength) {
2245
- throw new DecodeError("Max length exceeded: ext length (".concat(size, ") > maxExtLength (").concat(this.maxExtLength, ")"));
2246
- }
2247
- var extType = this.view.getInt8(this.pos + headOffset);
2248
- var data = this.decodeBinary(
2249
- size,
2250
- headOffset + 1
2251
- /* extType */
2252
- );
2253
- return this.extensionCodec.decode(data, extType, this.context);
2254
- };
2255
- Decoder2.prototype.lookU8 = function() {
2256
- return this.view.getUint8(this.pos);
2257
- };
2258
- Decoder2.prototype.lookU16 = function() {
2259
- return this.view.getUint16(this.pos);
2260
- };
2261
- Decoder2.prototype.lookU32 = function() {
2262
- return this.view.getUint32(this.pos);
2263
- };
2264
- Decoder2.prototype.readU8 = function() {
2265
- var value = this.view.getUint8(this.pos);
2266
- this.pos++;
2267
- return value;
2268
- };
2269
- Decoder2.prototype.readI8 = function() {
2270
- var value = this.view.getInt8(this.pos);
2271
- this.pos++;
2272
- return value;
2273
- };
2274
- Decoder2.prototype.readU16 = function() {
2275
- var value = this.view.getUint16(this.pos);
2276
- this.pos += 2;
2277
- return value;
2278
- };
2279
- Decoder2.prototype.readI16 = function() {
2280
- var value = this.view.getInt16(this.pos);
2281
- this.pos += 2;
2282
- return value;
2283
- };
2284
- Decoder2.prototype.readU32 = function() {
2285
- var value = this.view.getUint32(this.pos);
2286
- this.pos += 4;
2287
- return value;
2288
- };
2289
- Decoder2.prototype.readI32 = function() {
2290
- var value = this.view.getInt32(this.pos);
2291
- this.pos += 4;
2292
- return value;
2293
- };
2294
- Decoder2.prototype.readU64 = function() {
2295
- var value = getUint64(this.view, this.pos);
2296
- this.pos += 8;
2297
- return value;
2298
- };
2299
- Decoder2.prototype.readI64 = function() {
2300
- var value = getInt64(this.view, this.pos);
2301
- this.pos += 8;
2302
- return value;
2303
- };
2304
- Decoder2.prototype.readF32 = function() {
2305
- var value = this.view.getFloat32(this.pos);
2306
- this.pos += 4;
2307
- return value;
2308
- };
2309
- Decoder2.prototype.readF64 = function() {
2310
- var value = this.view.getFloat64(this.pos);
2311
- this.pos += 8;
2312
- return value;
2313
- };
2314
- return Decoder2;
2315
- }()
2316
- );
2317
- var defaultDecodeOptions = {};
2318
- function decode$1(buffer, options) {
2319
- if (options === void 0) {
2320
- options = defaultDecodeOptions;
2321
- }
2322
- var decoder = new Decoder(options.extensionCodec, options.context, options.maxStrLength, options.maxBinLength, options.maxArrayLength, options.maxMapLength, options.maxExtLength);
2323
- return decoder.decode(buffer);
2324
- }
2325
759
  function uid() {
2326
760
  return window.crypto.getRandomValues(new Uint32Array(1))[0];
2327
761
  }
@@ -7887,7 +6321,7 @@ const signZomeCallTauri = async (request) => {
7887
6321
  cell_id: [Array.from(request.cell_id[0]), Array.from(request.cell_id[1])],
7888
6322
  zome_name: request.zome_name,
7889
6323
  fn_name: request.fn_name,
7890
- payload: Array.from(encode$1(request.payload)),
6324
+ payload: Array.from(msgpack.encode(request.payload)),
7891
6325
  nonce: Array.from(await randomNonce()),
7892
6326
  expires_at: getNonceExpiration()
7893
6327
  };
@@ -7917,7 +6351,7 @@ const signZomeCallElectron = async (request) => {
7917
6351
  cellId: [Array.from(request.cell_id[0]), Array.from(request.cell_id[1])],
7918
6352
  zomeName: request.zome_name,
7919
6353
  fnName: request.fn_name,
7920
- payload: Array.from(encode$1(request.payload)),
6354
+ payload: Array.from(msgpack.encode(request.payload)),
7921
6355
  nonce: Array.from(await randomNonce()),
7922
6356
  expiresAt: getNonceExpiration()
7923
6357
  };
@@ -12197,19 +10631,19 @@ class WsClient extends Emittery {
12197
10631
  throw new Error("websocket client: unknown message format");
12198
10632
  }
12199
10633
  }
12200
- const message = decode$1(deserializedData);
10634
+ const message = msgpack.decode(deserializedData);
12201
10635
  assertHolochainMessage(message);
12202
10636
  if (message.type === "signal") {
12203
10637
  if (message.data === null) {
12204
10638
  throw new Error("received a signal without data");
12205
10639
  }
12206
- const deserializedSignal = decode$1(message.data);
10640
+ const deserializedSignal = msgpack.decode(message.data);
12207
10641
  assertHolochainSignal(deserializedSignal);
12208
10642
  if (SignalType.System in deserializedSignal) {
12209
10643
  return;
12210
10644
  }
12211
10645
  const encodedAppSignal = deserializedSignal[SignalType.App];
12212
- const payload = decode$1(encodedAppSignal.signal);
10646
+ const payload = msgpack.decode(encodedAppSignal.signal);
12213
10647
  const signal = {
12214
10648
  cell_id: encodedAppSignal.cell_id,
12215
10649
  zome_name: encodedAppSignal.zome_name,
@@ -12257,9 +10691,9 @@ class WsClient extends Emittery {
12257
10691
  * @param data - Data to send.
12258
10692
  */
12259
10693
  emitSignal(data) {
12260
- const encodedMsg = encode$1({
10694
+ const encodedMsg = msgpack.encode({
12261
10695
  type: "signal",
12262
- data: encode$1(data)
10696
+ data: msgpack.encode(data)
12263
10697
  });
12264
10698
  this.socket.send(encodedMsg);
12265
10699
  }
@@ -12294,10 +10728,10 @@ class WsClient extends Emittery {
12294
10728
  }
12295
10729
  sendMessage(request, resolve, reject) {
12296
10730
  const id = this.index;
12297
- const encodedMsg = encode$1({
10731
+ const encodedMsg = msgpack.encode({
12298
10732
  id,
12299
10733
  type: "request",
12300
- data: encode$1(request)
10734
+ data: msgpack.encode(request)
12301
10735
  });
12302
10736
  this.socket.send(encodedMsg);
12303
10737
  this.pendingRequests[id] = { resolve, reject };
@@ -12309,7 +10743,7 @@ class WsClient extends Emittery {
12309
10743
  if (msg.data === null || msg.data === void 0) {
12310
10744
  this.pendingRequests[id].reject(new Error("Response canceled by responder"));
12311
10745
  } else {
12312
- this.pendingRequests[id].resolve(decode$1(msg.data));
10746
+ this.pendingRequests[id].resolve(msgpack.decode(msg.data));
12313
10747
  }
12314
10748
  delete this.pendingRequests[id];
12315
10749
  } else {
@@ -12476,7 +10910,7 @@ const callZomeTransform = {
12476
10910
  }
12477
10911
  return signZomeCallTauri(request);
12478
10912
  },
12479
- output: (response) => decode$1(response)
10913
+ output: (response) => msgpack.decode(response)
12480
10914
  };
12481
10915
  const appInfoTransform = (appWs) => ({
12482
10916
  input: (request) => {
@@ -12500,7 +10934,7 @@ const signZomeCall = async (request) => {
12500
10934
  zome_name: request.zome_name,
12501
10935
  fn_name: request.fn_name,
12502
10936
  provenance: signingCredentialsForCell.signingKey,
12503
- payload: encode$1(request.payload),
10937
+ payload: msgpack.encode(request.payload),
12504
10938
  nonce: await randomNonce(),
12505
10939
  expires_at: getNonceExpiration()
12506
10940
  };
@@ -13301,36 +11735,37 @@ function validateCliArgs(cliArgs, cliOpts, appDataRootDir) {
13301
11735
  appId,
13302
11736
  holochainPath,
13303
11737
  numAgents,
13304
- networkSeed: cliOpts.networkSeed,
13305
11738
  uiSource: cliOpts.uiPath ? { type: "path", path: cliOpts.uiPath } : cliOpts.uiPort ? { type: "port", port: cliOpts.uiPort } : { type: "path", path: path.join(appDataRootDir, "apps", appId, "ui") },
13306
- singalingUrl: cliOpts.signalingUrl,
13307
- bootstrapUrl: cliOpts.bootstrapUrl,
13308
11739
  happOrWebhappPath: isHapp ? { type: "happ", path: happOrWebhappPath } : { type: "webhapp", path: happOrWebhappPath }
13309
11740
  };
13310
11741
  }
13311
11742
  const rustUtils = require("@holochain/hc-spin-rust-utils");
13312
11743
  const cli = new commander.Command();
13313
- cli.name("hc-spin").description("CLI to run Holochain aps during development.").version(`0.200.2 (for holochain 0.2.x)`).argument(
11744
+ cli.name("hc-spin").description("CLI to run Holochain apps during development.").version(`0.100.0 (for holochain 0.1.x)`).argument(
13314
11745
  "<path>",
13315
11746
  "Path to .webhapp or .happ file to launch. If a .happ file is passed, either a UI path must be specified via --ui-path or a port pointing to a localhost server via --ui-port"
13316
11747
  ).option(
13317
11748
  "--app-id <string>",
13318
11749
  "Install the app with a specific app id. By default the app id is derived from the name of the .webhapp/.happ file that you pass but this option allows you to set it explicitly"
13319
- ).option(
13320
- "--bootstrap-url <url>",
13321
- "Url of the bootstrap server to use. By default, hc spin spins up a local development bootstrap server for you but this argument allows you to specify a custom one."
13322
11750
  ).option("--holochain-path <path>", "Set the path to the holochain binary [default: holochain].").addOption(
13323
11751
  new commander.Option("-n, --num-agents <number>", "How many agents to spawn the app for.").argParser(
13324
11752
  parseInt
13325
11753
  )
13326
- ).option("--network-seed <string>", "Install the app with a specific network seed.").option("--ui-path <path>", "Path to the folder containing the index.html of the webhapp's UI.").option(
11754
+ ).option("--ui-path <path>", "Path to the folder containing the index.html of the webhapp's UI.").option(
13327
11755
  "--ui-port <number>",
13328
11756
  "Port pointing to a localhost dev server that serves your UI assets."
13329
- ).option(
13330
- "--signaling-url <url>",
13331
- "Url of the signaling server to use. By default, hc spin spins up a local development signaling server for you but this argument allows you to specify a custom one."
13332
11757
  );
13333
11758
  cli.parse();
11759
+ const rl = require("readline").createInterface({
11760
+ input: process.stdin,
11761
+ output: process.stdout
11762
+ });
11763
+ rl.on("SIGINT", function() {
11764
+ process.emit("SIGINT");
11765
+ });
11766
+ process.on("SIGINT", () => {
11767
+ electron.app.quit();
11768
+ });
13334
11769
  const files = fs.readdirSync(electron.app.getPath("temp"));
13335
11770
  const hcSpinFolders = files.filter((file) => file.startsWith(`hc-spin-`));
13336
11771
  for (const folder of hcSpinFolders) {
@@ -13356,42 +11791,43 @@ contextMenu({
13356
11791
  showSearchWithGoogle: false,
13357
11792
  showInspectElement: true
13358
11793
  });
13359
- const handleSignZomeCall = (e, zomeCall) => {
11794
+ const handleSignZomeCall = async (e, request) => {
11795
+ const windowInfo = WINDOW_INFO_MAP[e.sender.id];
11796
+ if (request.provenance.toString() !== Array.from(windowInfo.agentPubKey).toString())
11797
+ return Promise.reject("Agent public key unauthorized.");
11798
+ const zomeCallUnsignedNapi = {
11799
+ provenance: Array.from(request.provenance),
11800
+ cellId: [Array.from(request.cell_id[0]), Array.from(request.cell_id[1])],
11801
+ zomeName: request.zome_name,
11802
+ fnName: request.fn_name,
11803
+ payload: Array.from(msgpack.encode(request.payload)),
11804
+ nonce: Array.from(await randomNonce()),
11805
+ expiresAt: getNonceExpiration()
11806
+ };
11807
+ const zomeCallSignedNapi = await windowInfo.zomeCallSigner.signZomeCall(zomeCallUnsignedNapi);
11808
+ const zomeCallSigned = {
11809
+ provenance: Uint8Array.from(zomeCallSignedNapi.provenance),
11810
+ cap_secret: null,
11811
+ cell_id: [
11812
+ Uint8Array.from(zomeCallSignedNapi.cellId[0]),
11813
+ Uint8Array.from(zomeCallSignedNapi.cellId[1])
11814
+ ],
11815
+ zome_name: zomeCallSignedNapi.zomeName,
11816
+ fn_name: zomeCallSignedNapi.fnName,
11817
+ payload: Uint8Array.from(zomeCallSignedNapi.payload),
11818
+ signature: Uint8Array.from(zomeCallSignedNapi.signature),
11819
+ expires_at: zomeCallSignedNapi.expiresAt,
11820
+ nonce: Uint8Array.from(zomeCallSignedNapi.nonce)
11821
+ };
11822
+ return zomeCallSigned;
11823
+ };
11824
+ const handleSignZomeCallLegacy = async (e, request) => {
13360
11825
  const windowInfo = WINDOW_INFO_MAP[e.sender.id];
13361
- if (zomeCall.provenance.toString() !== Array.from(windowInfo.agentPubKey).toString())
11826
+ if (request.provenance.toString() !== Array.from(windowInfo.agentPubKey).toString())
13362
11827
  return Promise.reject("Agent public key unauthorized.");
13363
- return windowInfo.zomeCallSigner.signZomeCall(zomeCall);
11828
+ return windowInfo.zomeCallSigner.signZomeCall(request);
13364
11829
  };
13365
- async function startLocalServices() {
13366
- const localServicesHandle = childProcess__namespace.spawn("hc", ["run-local-services"]);
13367
- return new Promise((resolve) => {
13368
- let bootStrapUrl;
13369
- let signalUrl;
13370
- let bootstrapRunning = false;
13371
- let signalRunnig = false;
13372
- localServicesHandle.stdout.pipe(split()).on("data", async (line) => {
13373
- console.log(`[hc-spin] | [hc run-local-services]: ${line}`);
13374
- if (line.includes("HC BOOTSTRAP - ADDR:")) {
13375
- bootStrapUrl = line.split("# HC BOOTSTRAP - ADDR:")[1].trim();
13376
- }
13377
- if (line.includes("HC SIGNAL - ADDR:")) {
13378
- signalUrl = line.split("# HC SIGNAL - ADDR:")[1].trim();
13379
- }
13380
- if (line.includes("HC BOOTSTRAP - RUNNING")) {
13381
- bootstrapRunning = true;
13382
- }
13383
- if (line.includes("HC SIGNAL - RUNNING")) {
13384
- signalRunnig = true;
13385
- }
13386
- if (bootstrapRunning && signalRunnig)
13387
- resolve([bootStrapUrl, signalUrl]);
13388
- });
13389
- localServicesHandle.stderr.pipe(split()).on("data", async (line) => {
13390
- console.log(`[hc-spin] | [hc run-local-services] ERROR: ${line}`);
13391
- });
13392
- });
13393
- }
13394
- async function spawnSandboxes(nAgents, happPath, bootStrapUrl, signalUrl, appId, networkSeed) {
11830
+ async function spawnSandboxes(nAgents, happPath, appId) {
13395
11831
  const generateArgs = [
13396
11832
  "sandbox",
13397
11833
  "--piped",
@@ -13399,22 +11835,18 @@ async function spawnSandboxes(nAgents, happPath, bootStrapUrl, signalUrl, appId,
13399
11835
  "--num-sandboxes",
13400
11836
  nAgents.toString(),
13401
11837
  "--app-id",
13402
- appId,
13403
- "--run"
11838
+ appId
13404
11839
  ];
13405
- let appPorts = "";
11840
+ const appPorts = [];
11841
+ let appPortsString = "";
13406
11842
  for (var i = 1; i <= nAgents; i++) {
13407
11843
  const appPort = await getPorts();
13408
- appPorts += `${appPort},`;
13409
- }
13410
- generateArgs.push(appPorts.slice(0, appPorts.length - 1));
13411
- if (networkSeed) {
13412
- generateArgs.push("--network-seed");
13413
- generateArgs.push(networkSeed);
11844
+ appPortsString += `${appPort},`;
11845
+ appPorts.push(appPort);
13414
11846
  }
13415
- generateArgs.push(happPath, "network", "--bootstrap", bootStrapUrl, "webrtc", signalUrl);
11847
+ generateArgs.push("--run", appPortsString.slice(0, appPortsString.length - 1));
11848
+ generateArgs.push(happPath, "network", "mdns");
13416
11849
  let readyConductors = 0;
13417
- const portsInfo = {};
13418
11850
  const sandboxPaths = [];
13419
11851
  const sandboxHandle = childProcess__namespace.spawn("hc", generateArgs);
13420
11852
  sandboxHandle.stdin.write("pass");
@@ -13426,17 +11858,10 @@ async function spawnSandboxes(nAgents, happPath, bootStrapUrl, signalUrl, appId,
13426
11858
  const sanboxPath = line.split("\x1B[1;4;48;5;254;38;5;4m")[1].split("\x1B[0m \x1B[1m")[0].trim();
13427
11859
  sandboxPaths.push(sanboxPath);
13428
11860
  }
13429
- if (line.includes("lair-keystore connection_url")) {
13430
- line.split("#")[2].trim();
13431
- }
13432
- if (line.includes("Conductor launched")) {
13433
- const split1 = line.split("{");
13434
- const ports = JSON.parse(`{${split1[1]}`);
13435
- const conductorNum = split1[0].split("#!")[1].trim();
13436
- portsInfo[conductorNum] = ports;
11861
+ if (line.includes("Running conductor on admin port")) {
13437
11862
  readyConductors += 1;
13438
11863
  if (readyConductors === nAgents)
13439
- resolve([sandboxHandle, sandboxPaths, portsInfo]);
11864
+ resolve([sandboxHandle, sandboxPaths, appPorts]);
13440
11865
  }
13441
11866
  });
13442
11867
  sandboxHandle.stderr.pipe(split()).on("data", async (line) => {
@@ -13446,6 +11871,7 @@ async function spawnSandboxes(nAgents, happPath, bootStrapUrl, signalUrl, appId,
13446
11871
  }
13447
11872
  electron.app.whenReady().then(async () => {
13448
11873
  electron.ipcMain.handle("sign-zome-call", handleSignZomeCall);
11874
+ electron.ipcMain.handle("sign-zome-call-legacy", handleSignZomeCallLegacy);
13449
11875
  let happTargetDir;
13450
11876
  if (CLI_OPTS.happOrWebhappPath.type === "webhapp") {
13451
11877
  happTargetDir = path.join(DATA_ROOT_DIR, "apps", CLI_OPTS.appId);
@@ -13457,14 +11883,12 @@ electron.app.whenReady().then(async () => {
13457
11883
  happTargetDir
13458
11884
  );
13459
11885
  }
13460
- const [bootstrapUrl, signalingUrl] = await startLocalServices();
13461
- const [sandboxHandle, sandboxPaths, portsInfo] = await spawnSandboxes(
11886
+ const [sandboxHandle, sandboxPaths, appPorts] = await spawnSandboxes(
13462
11887
  CLI_OPTS.numAgents,
13463
11888
  happTargetDir ? happTargetDir : CLI_OPTS.happOrWebhappPath.path,
13464
- CLI_OPTS.bootstrapUrl ? CLI_OPTS.bootstrapUrl : bootstrapUrl,
13465
- CLI_OPTS.singalingUrl ? CLI_OPTS.singalingUrl : signalingUrl,
13466
11889
  CLI_OPTS.appId
13467
11890
  );
11891
+ console.log("Got app ports: ", appPorts);
13468
11892
  const lairUrls = [];
13469
11893
  sandboxPaths.forEach((sandbox) => {
13470
11894
  const conductorConfigPath = path.join(sandbox, "conductor-config.yaml");
@@ -13481,15 +11905,14 @@ electron.app.whenReady().then(async () => {
13481
11905
  SANDBOX_PROCESSES.push(sandboxHandle);
13482
11906
  for (var i = 0; i < cli.opts().numAgents; i++) {
13483
11907
  const zomeCallSigner = await rustUtils.ZomeCallSigner.connect(lairUrls[i], "pass");
13484
- const appPort = portsInfo[i].app_ports[0];
13485
- const appWs = await AppWebsocket.connect(new URL(`ws://127.0.0.1:${appPort}`));
11908
+ const appWs = await AppWebsocket.connect(new URL(`ws://127.0.0.1:${appPorts[i]}`));
13486
11909
  const appInfo = await appWs.appInfo({ installed_app_id: CLI_OPTS.appId });
13487
11910
  const happWindow = await createHappWindow(
13488
11911
  CLI_OPTS.uiSource,
13489
11912
  CLI_OPTS.happOrWebhappPath,
13490
11913
  CLI_OPTS.appId,
13491
11914
  i + 1,
13492
- appPort,
11915
+ appPorts[i],
13493
11916
  DATA_ROOT_DIR
13494
11917
  );
13495
11918
  WINDOW_INFO_MAP[happWindow.webContents.id] = {
@@ -13499,9 +11922,7 @@ electron.app.whenReady().then(async () => {
13499
11922
  }
13500
11923
  });
13501
11924
  electron.app.on("window-all-closed", () => {
13502
- if (process.platform !== "darwin") {
13503
- electron.app.quit();
13504
- }
11925
+ electron.app.quit();
13505
11926
  });
13506
11927
  electron.app.on("quit", () => {
13507
11928
  fs.writeFileSync(