@heybox/hb-sdk 0.7.4 → 0.7.5-alpha.0
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/CHANGELOG.md +10 -0
- package/dist/cli-chunks/{build-CVPqGQY3.cjs → build-V1YBdpzY.cjs} +2 -2
- package/dist/cli-chunks/{context-C1nTGr-R.cjs → context-Ba1Je-wT.cjs} +1 -1
- package/dist/cli-chunks/{create-C5qrLLvv.cjs → create-CKGjqo9E.cjs} +1 -1
- package/dist/cli-chunks/{dev-U5BlN4ei.cjs → dev-XopYKLYZ.cjs} +7 -7
- package/dist/cli-chunks/{doctor-DxqHMTbm.cjs → doctor-BHbrYQqT.cjs} +1 -1
- package/dist/cli-chunks/{index-DLrcC_ij.cjs → index-C9mpajVG.cjs} +14 -14
- package/dist/cli-chunks/{index-BfR6OZeU.cjs → index-DKWfX6Ut.cjs} +1 -1
- package/dist/cli-chunks/{index.esm-DbbyeU1z.cjs → index.esm-SXAQ3WVR.cjs} +5 -5
- package/dist/cli-chunks/{login-DQkArK14.cjs → login-BVWicWqe.cjs} +2 -2
- package/dist/cli-chunks/{project-vite-c13CKUUl.cjs → project-vite-CBb38HJ3.cjs} +1 -1
- package/dist/cli-chunks/{remote-816SyJyA.cjs → remote-BG1u0NKT.cjs} +4 -4
- package/dist/cli-chunks/{session-ySUU0fVq.cjs → session-CJS_SEp9.cjs} +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/devtools/browser-dev-host/main.js +481 -404
- package/dist/index.cjs.js +602 -577
- package/dist/index.esm.js +602 -577
- package/dist/vite.cjs.js +1 -1
- package/dist/vite.esm.js +1 -1
- package/package.json +7 -7
- package/skill/references/api-root.md +1 -1
- package/skill/skill.json +4 -4
|
@@ -2884,12 +2884,38 @@ function bridgeError$2(code, message) {
|
|
|
2884
2884
|
return { code, message };
|
|
2885
2885
|
}
|
|
2886
2886
|
|
|
2887
|
+
// Integer Utility
|
|
2888
|
+
var UINT32_MAX = 4294967295;
|
|
2889
|
+
// DataView extension to handle int64 / uint64,
|
|
2890
|
+
// where the actual range is 53-bits integer (a.k.a. safe integer)
|
|
2891
|
+
function setUint64(view, offset, value) {
|
|
2892
|
+
var high = value / 4294967296;
|
|
2893
|
+
var low = value; // high bits are truncated by DataView
|
|
2894
|
+
view.setUint32(offset, high);
|
|
2895
|
+
view.setUint32(offset + 4, low);
|
|
2896
|
+
}
|
|
2897
|
+
function setInt64(view, offset, value) {
|
|
2898
|
+
var high = Math.floor(value / 4294967296);
|
|
2899
|
+
var low = value; // high bits are truncated by DataView
|
|
2900
|
+
view.setUint32(offset, high);
|
|
2901
|
+
view.setUint32(offset + 4, low);
|
|
2902
|
+
}
|
|
2903
|
+
function getInt64(view, offset) {
|
|
2904
|
+
var high = view.getInt32(offset);
|
|
2905
|
+
var low = view.getUint32(offset + 4);
|
|
2906
|
+
return high * 4294967296 + low;
|
|
2907
|
+
}
|
|
2908
|
+
|
|
2909
|
+
var _a, _b, _c;
|
|
2910
|
+
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") &&
|
|
2911
|
+
typeof TextEncoder !== "undefined" &&
|
|
2912
|
+
typeof TextDecoder !== "undefined";
|
|
2887
2913
|
function utf8Count(str) {
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2914
|
+
var strLength = str.length;
|
|
2915
|
+
var byteLength = 0;
|
|
2916
|
+
var pos = 0;
|
|
2891
2917
|
while (pos < strLength) {
|
|
2892
|
-
|
|
2918
|
+
var value = str.charCodeAt(pos++);
|
|
2893
2919
|
if ((value & 0xffffff80) === 0) {
|
|
2894
2920
|
// 1-byte
|
|
2895
2921
|
byteLength++;
|
|
@@ -2904,7 +2930,7 @@ function utf8Count(str) {
|
|
|
2904
2930
|
if (value >= 0xd800 && value <= 0xdbff) {
|
|
2905
2931
|
// high surrogate
|
|
2906
2932
|
if (pos < strLength) {
|
|
2907
|
-
|
|
2933
|
+
var extra = str.charCodeAt(pos);
|
|
2908
2934
|
if ((extra & 0xfc00) === 0xdc00) {
|
|
2909
2935
|
++pos;
|
|
2910
2936
|
value = ((value & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000;
|
|
@@ -2924,11 +2950,11 @@ function utf8Count(str) {
|
|
|
2924
2950
|
return byteLength;
|
|
2925
2951
|
}
|
|
2926
2952
|
function utf8EncodeJs(str, output, outputOffset) {
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2953
|
+
var strLength = str.length;
|
|
2954
|
+
var offset = outputOffset;
|
|
2955
|
+
var pos = 0;
|
|
2930
2956
|
while (pos < strLength) {
|
|
2931
|
-
|
|
2957
|
+
var value = str.charCodeAt(pos++);
|
|
2932
2958
|
if ((value & 0xffffff80) === 0) {
|
|
2933
2959
|
// 1-byte
|
|
2934
2960
|
output[offset++] = value;
|
|
@@ -2943,7 +2969,7 @@ function utf8EncodeJs(str, output, outputOffset) {
|
|
|
2943
2969
|
if (value >= 0xd800 && value <= 0xdbff) {
|
|
2944
2970
|
// high surrogate
|
|
2945
2971
|
if (pos < strLength) {
|
|
2946
|
-
|
|
2972
|
+
var extra = str.charCodeAt(pos);
|
|
2947
2973
|
if ((extra & 0xfc00) === 0xdc00) {
|
|
2948
2974
|
++pos;
|
|
2949
2975
|
value = ((value & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000;
|
|
@@ -2965,56 +2991,48 @@ function utf8EncodeJs(str, output, outputOffset) {
|
|
|
2965
2991
|
output[offset++] = (value & 0x3f) | 0x80;
|
|
2966
2992
|
}
|
|
2967
2993
|
}
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
// Run `npx ts-node benchmark/encode-string.ts` for details.
|
|
2977
|
-
const TEXT_ENCODER_THRESHOLD = 50;
|
|
2978
|
-
function utf8EncodeTE(str, output, outputOffset) {
|
|
2979
|
-
sharedTextEncoder.encodeInto(str, output.subarray(outputOffset));
|
|
2994
|
+
var sharedTextEncoder = TEXT_ENCODING_AVAILABLE ? new TextEncoder() : undefined;
|
|
2995
|
+
var TEXT_ENCODER_THRESHOLD = !TEXT_ENCODING_AVAILABLE
|
|
2996
|
+
? UINT32_MAX
|
|
2997
|
+
: typeof process !== "undefined" && ((_b = process === null || process === void 0 ? void 0 : process.env) === null || _b === void 0 ? void 0 : _b["TEXT_ENCODING"]) !== "force"
|
|
2998
|
+
? 200
|
|
2999
|
+
: 0;
|
|
3000
|
+
function utf8EncodeTEencode(str, output, outputOffset) {
|
|
3001
|
+
output.set(sharedTextEncoder.encode(str), outputOffset);
|
|
2980
3002
|
}
|
|
2981
|
-
function
|
|
2982
|
-
|
|
2983
|
-
utf8EncodeTE(str, output, outputOffset);
|
|
2984
|
-
}
|
|
2985
|
-
else {
|
|
2986
|
-
utf8EncodeJs(str, output, outputOffset);
|
|
2987
|
-
}
|
|
3003
|
+
function utf8EncodeTEencodeInto(str, output, outputOffset) {
|
|
3004
|
+
sharedTextEncoder.encodeInto(str, output.subarray(outputOffset));
|
|
2988
3005
|
}
|
|
2989
|
-
|
|
3006
|
+
var utf8EncodeTE = (sharedTextEncoder === null || sharedTextEncoder === void 0 ? void 0 : sharedTextEncoder.encodeInto) ? utf8EncodeTEencodeInto : utf8EncodeTEencode;
|
|
3007
|
+
var CHUNK_SIZE = 4096;
|
|
2990
3008
|
function utf8DecodeJs(bytes, inputOffset, byteLength) {
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
3009
|
+
var offset = inputOffset;
|
|
3010
|
+
var end = offset + byteLength;
|
|
3011
|
+
var units = [];
|
|
3012
|
+
var result = "";
|
|
2995
3013
|
while (offset < end) {
|
|
2996
|
-
|
|
3014
|
+
var byte1 = bytes[offset++];
|
|
2997
3015
|
if ((byte1 & 0x80) === 0) {
|
|
2998
3016
|
// 1 byte
|
|
2999
3017
|
units.push(byte1);
|
|
3000
3018
|
}
|
|
3001
3019
|
else if ((byte1 & 0xe0) === 0xc0) {
|
|
3002
3020
|
// 2 bytes
|
|
3003
|
-
|
|
3021
|
+
var byte2 = bytes[offset++] & 0x3f;
|
|
3004
3022
|
units.push(((byte1 & 0x1f) << 6) | byte2);
|
|
3005
3023
|
}
|
|
3006
3024
|
else if ((byte1 & 0xf0) === 0xe0) {
|
|
3007
3025
|
// 3 bytes
|
|
3008
|
-
|
|
3009
|
-
|
|
3026
|
+
var byte2 = bytes[offset++] & 0x3f;
|
|
3027
|
+
var byte3 = bytes[offset++] & 0x3f;
|
|
3010
3028
|
units.push(((byte1 & 0x1f) << 12) | (byte2 << 6) | byte3);
|
|
3011
3029
|
}
|
|
3012
3030
|
else if ((byte1 & 0xf8) === 0xf0) {
|
|
3013
3031
|
// 4 bytes
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3032
|
+
var byte2 = bytes[offset++] & 0x3f;
|
|
3033
|
+
var byte3 = bytes[offset++] & 0x3f;
|
|
3034
|
+
var byte4 = bytes[offset++] & 0x3f;
|
|
3035
|
+
var unit = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0c) | (byte3 << 0x06) | byte4;
|
|
3018
3036
|
if (unit > 0xffff) {
|
|
3019
3037
|
unit -= 0x10000;
|
|
3020
3038
|
units.push(((unit >>> 10) & 0x3ff) | 0xd800);
|
|
@@ -3026,84 +3044,86 @@ function utf8DecodeJs(bytes, inputOffset, byteLength) {
|
|
|
3026
3044
|
units.push(byte1);
|
|
3027
3045
|
}
|
|
3028
3046
|
if (units.length >= CHUNK_SIZE) {
|
|
3029
|
-
result += String.fromCharCode(
|
|
3047
|
+
result += String.fromCharCode.apply(String, units);
|
|
3030
3048
|
units.length = 0;
|
|
3031
3049
|
}
|
|
3032
3050
|
}
|
|
3033
3051
|
if (units.length > 0) {
|
|
3034
|
-
result += String.fromCharCode(
|
|
3052
|
+
result += String.fromCharCode.apply(String, units);
|
|
3035
3053
|
}
|
|
3036
3054
|
return result;
|
|
3037
3055
|
}
|
|
3038
|
-
new TextDecoder();
|
|
3056
|
+
TEXT_ENCODING_AVAILABLE ? new TextDecoder() : null;
|
|
3057
|
+
!TEXT_ENCODING_AVAILABLE
|
|
3058
|
+
? UINT32_MAX
|
|
3059
|
+
: typeof process !== "undefined" && ((_c = process === null || process === void 0 ? void 0 : process.env) === null || _c === void 0 ? void 0 : _c["TEXT_DECODER"]) !== "force"
|
|
3060
|
+
? 200
|
|
3061
|
+
: 0;
|
|
3039
3062
|
|
|
3040
3063
|
/**
|
|
3041
3064
|
* ExtData is used to handle Extension Types that are not registered to ExtensionCodec.
|
|
3042
3065
|
*/
|
|
3043
|
-
|
|
3044
|
-
type
|
|
3045
|
-
data;
|
|
3046
|
-
constructor(type, data) {
|
|
3066
|
+
var ExtData = /** @class */ (function () {
|
|
3067
|
+
function ExtData(type, data) {
|
|
3047
3068
|
this.type = type;
|
|
3048
3069
|
this.data = data;
|
|
3049
3070
|
}
|
|
3050
|
-
|
|
3071
|
+
return ExtData;
|
|
3072
|
+
}());
|
|
3051
3073
|
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3074
|
+
var __extends = (undefined && undefined.__extends) || (function () {
|
|
3075
|
+
var extendStatics = function (d, b) {
|
|
3076
|
+
extendStatics = Object.setPrototypeOf ||
|
|
3077
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
3078
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
3079
|
+
return extendStatics(d, b);
|
|
3080
|
+
};
|
|
3081
|
+
return function (d, b) {
|
|
3082
|
+
if (typeof b !== "function" && b !== null)
|
|
3083
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
3084
|
+
extendStatics(d, b);
|
|
3085
|
+
function __() { this.constructor = d; }
|
|
3086
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
3087
|
+
};
|
|
3088
|
+
})();
|
|
3089
|
+
var DecodeError = /** @class */ (function (_super) {
|
|
3090
|
+
__extends(DecodeError, _super);
|
|
3091
|
+
function DecodeError(message) {
|
|
3092
|
+
var _this = _super.call(this, message) || this;
|
|
3055
3093
|
// fix the prototype chain in a cross-platform way
|
|
3056
|
-
|
|
3057
|
-
Object.setPrototypeOf(
|
|
3058
|
-
Object.defineProperty(
|
|
3094
|
+
var proto = Object.create(DecodeError.prototype);
|
|
3095
|
+
Object.setPrototypeOf(_this, proto);
|
|
3096
|
+
Object.defineProperty(_this, "name", {
|
|
3059
3097
|
configurable: true,
|
|
3060
3098
|
enumerable: false,
|
|
3061
3099
|
value: DecodeError.name,
|
|
3062
3100
|
});
|
|
3101
|
+
return _this;
|
|
3063
3102
|
}
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
// Integer Utility
|
|
3067
|
-
// DataView extension to handle int64 / uint64,
|
|
3068
|
-
// where the actual range is 53-bits integer (a.k.a. safe integer)
|
|
3069
|
-
function setUint64(view, offset, value) {
|
|
3070
|
-
const high = value / 4294967296;
|
|
3071
|
-
const low = value; // high bits are truncated by DataView
|
|
3072
|
-
view.setUint32(offset, high);
|
|
3073
|
-
view.setUint32(offset + 4, low);
|
|
3074
|
-
}
|
|
3075
|
-
function setInt64(view, offset, value) {
|
|
3076
|
-
const high = Math.floor(value / 4294967296);
|
|
3077
|
-
const low = value; // high bits are truncated by DataView
|
|
3078
|
-
view.setUint32(offset, high);
|
|
3079
|
-
view.setUint32(offset + 4, low);
|
|
3080
|
-
}
|
|
3081
|
-
function getInt64(view, offset) {
|
|
3082
|
-
const high = view.getInt32(offset);
|
|
3083
|
-
const low = view.getUint32(offset + 4);
|
|
3084
|
-
return high * 4294967296 + low;
|
|
3085
|
-
}
|
|
3103
|
+
return DecodeError;
|
|
3104
|
+
}(Error));
|
|
3086
3105
|
|
|
3087
3106
|
// https://github.com/msgpack/msgpack/blob/master/spec.md#timestamp-extension-type
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
function encodeTimeSpecToTimestamp(
|
|
3107
|
+
var EXT_TIMESTAMP = -1;
|
|
3108
|
+
var TIMESTAMP32_MAX_SEC = 0x100000000 - 1; // 32-bit unsigned int
|
|
3109
|
+
var TIMESTAMP64_MAX_SEC = 0x400000000 - 1; // 34-bit unsigned int
|
|
3110
|
+
function encodeTimeSpecToTimestamp(_a) {
|
|
3111
|
+
var sec = _a.sec, nsec = _a.nsec;
|
|
3092
3112
|
if (sec >= 0 && nsec >= 0 && sec <= TIMESTAMP64_MAX_SEC) {
|
|
3093
3113
|
// Here sec >= 0 && nsec >= 0
|
|
3094
3114
|
if (nsec === 0 && sec <= TIMESTAMP32_MAX_SEC) {
|
|
3095
3115
|
// timestamp 32 = { sec32 (unsigned) }
|
|
3096
|
-
|
|
3097
|
-
|
|
3116
|
+
var rv = new Uint8Array(4);
|
|
3117
|
+
var view = new DataView(rv.buffer);
|
|
3098
3118
|
view.setUint32(0, sec);
|
|
3099
3119
|
return rv;
|
|
3100
3120
|
}
|
|
3101
3121
|
else {
|
|
3102
3122
|
// timestamp 64 = { nsec30 (unsigned), sec34 (unsigned) }
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3123
|
+
var secHigh = sec / 0x100000000;
|
|
3124
|
+
var secLow = sec & 0xffffffff;
|
|
3125
|
+
var rv = new Uint8Array(8);
|
|
3126
|
+
var view = new DataView(rv.buffer);
|
|
3107
3127
|
// nsec30 | secHigh2
|
|
3108
3128
|
view.setUint32(0, (nsec << 2) | (secHigh & 0x3));
|
|
3109
3129
|
// secLow32
|
|
@@ -3113,19 +3133,19 @@ function encodeTimeSpecToTimestamp({ sec, nsec }) {
|
|
|
3113
3133
|
}
|
|
3114
3134
|
else {
|
|
3115
3135
|
// timestamp 96 = { nsec32 (unsigned), sec64 (signed) }
|
|
3116
|
-
|
|
3117
|
-
|
|
3136
|
+
var rv = new Uint8Array(12);
|
|
3137
|
+
var view = new DataView(rv.buffer);
|
|
3118
3138
|
view.setUint32(0, nsec);
|
|
3119
3139
|
setInt64(view, 4, sec);
|
|
3120
3140
|
return rv;
|
|
3121
3141
|
}
|
|
3122
3142
|
}
|
|
3123
3143
|
function encodeDateToTimeSpec(date) {
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3144
|
+
var msec = date.getTime();
|
|
3145
|
+
var sec = Math.floor(msec / 1e3);
|
|
3146
|
+
var nsec = (msec - sec * 1e3) * 1e6;
|
|
3127
3147
|
// Normalizes { sec, nsec } to ensure nsec is unsigned.
|
|
3128
|
-
|
|
3148
|
+
var nsecInSec = Math.floor(nsec / 1e9);
|
|
3129
3149
|
return {
|
|
3130
3150
|
sec: sec + nsecInSec,
|
|
3131
3151
|
nsec: nsec - nsecInSec * 1e9,
|
|
@@ -3133,7 +3153,7 @@ function encodeDateToTimeSpec(date) {
|
|
|
3133
3153
|
}
|
|
3134
3154
|
function encodeTimestampExtension(object) {
|
|
3135
3155
|
if (object instanceof Date) {
|
|
3136
|
-
|
|
3156
|
+
var timeSpec = encodeDateToTimeSpec(object);
|
|
3137
3157
|
return encodeTimeSpecToTimestamp(timeSpec);
|
|
3138
3158
|
}
|
|
3139
3159
|
else {
|
|
@@ -3141,60 +3161,56 @@ function encodeTimestampExtension(object) {
|
|
|
3141
3161
|
}
|
|
3142
3162
|
}
|
|
3143
3163
|
function decodeTimestampToTimeSpec(data) {
|
|
3144
|
-
|
|
3164
|
+
var view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
3145
3165
|
// data may be 32, 64, or 96 bits
|
|
3146
3166
|
switch (data.byteLength) {
|
|
3147
3167
|
case 4: {
|
|
3148
3168
|
// timestamp 32 = { sec32 }
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
return { sec, nsec };
|
|
3169
|
+
var sec = view.getUint32(0);
|
|
3170
|
+
var nsec = 0;
|
|
3171
|
+
return { sec: sec, nsec: nsec };
|
|
3152
3172
|
}
|
|
3153
3173
|
case 8: {
|
|
3154
3174
|
// timestamp 64 = { nsec30, sec34 }
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
return { sec, nsec };
|
|
3175
|
+
var nsec30AndSecHigh2 = view.getUint32(0);
|
|
3176
|
+
var secLow32 = view.getUint32(4);
|
|
3177
|
+
var sec = (nsec30AndSecHigh2 & 0x3) * 0x100000000 + secLow32;
|
|
3178
|
+
var nsec = nsec30AndSecHigh2 >>> 2;
|
|
3179
|
+
return { sec: sec, nsec: nsec };
|
|
3160
3180
|
}
|
|
3161
3181
|
case 12: {
|
|
3162
3182
|
// timestamp 96 = { nsec32 (unsigned), sec64 (signed) }
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
return { sec, nsec };
|
|
3183
|
+
var sec = getInt64(view, 4);
|
|
3184
|
+
var nsec = view.getUint32(0);
|
|
3185
|
+
return { sec: sec, nsec: nsec };
|
|
3166
3186
|
}
|
|
3167
3187
|
default:
|
|
3168
|
-
throw new DecodeError(
|
|
3188
|
+
throw new DecodeError("Unrecognized data size for timestamp (expected 4, 8, or 12): ".concat(data.length));
|
|
3169
3189
|
}
|
|
3170
3190
|
}
|
|
3171
3191
|
function decodeTimestampExtension(data) {
|
|
3172
|
-
|
|
3192
|
+
var timeSpec = decodeTimestampToTimeSpec(data);
|
|
3173
3193
|
return new Date(timeSpec.sec * 1e3 + timeSpec.nsec / 1e6);
|
|
3174
3194
|
}
|
|
3175
|
-
|
|
3195
|
+
var timestampExtension = {
|
|
3176
3196
|
type: EXT_TIMESTAMP,
|
|
3177
3197
|
encode: encodeTimestampExtension,
|
|
3178
3198
|
decode: decodeTimestampExtension,
|
|
3179
3199
|
};
|
|
3180
3200
|
|
|
3181
3201
|
// ExtensionCodec to handle MessagePack extensions
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
builtInDecoders = [];
|
|
3191
|
-
// custom extensions
|
|
3192
|
-
encoders = [];
|
|
3193
|
-
decoders = [];
|
|
3194
|
-
constructor() {
|
|
3202
|
+
var ExtensionCodec = /** @class */ (function () {
|
|
3203
|
+
function ExtensionCodec() {
|
|
3204
|
+
// built-in extensions
|
|
3205
|
+
this.builtInEncoders = [];
|
|
3206
|
+
this.builtInDecoders = [];
|
|
3207
|
+
// custom extensions
|
|
3208
|
+
this.encoders = [];
|
|
3209
|
+
this.decoders = [];
|
|
3195
3210
|
this.register(timestampExtension);
|
|
3196
3211
|
}
|
|
3197
|
-
register
|
|
3212
|
+
ExtensionCodec.prototype.register = function (_a) {
|
|
3213
|
+
var type = _a.type, encode = _a.encode, decode = _a.decode;
|
|
3198
3214
|
if (type >= 0) {
|
|
3199
3215
|
// custom extensions
|
|
3200
3216
|
this.encoders[type] = encode;
|
|
@@ -3202,30 +3218,30 @@ class ExtensionCodec {
|
|
|
3202
3218
|
}
|
|
3203
3219
|
else {
|
|
3204
3220
|
// built-in extensions
|
|
3205
|
-
|
|
3221
|
+
var index = 1 + type;
|
|
3206
3222
|
this.builtInEncoders[index] = encode;
|
|
3207
3223
|
this.builtInDecoders[index] = decode;
|
|
3208
3224
|
}
|
|
3209
|
-
}
|
|
3210
|
-
tryToEncode(object, context) {
|
|
3225
|
+
};
|
|
3226
|
+
ExtensionCodec.prototype.tryToEncode = function (object, context) {
|
|
3211
3227
|
// built-in extensions
|
|
3212
|
-
for (
|
|
3213
|
-
|
|
3228
|
+
for (var i = 0; i < this.builtInEncoders.length; i++) {
|
|
3229
|
+
var encodeExt = this.builtInEncoders[i];
|
|
3214
3230
|
if (encodeExt != null) {
|
|
3215
|
-
|
|
3231
|
+
var data = encodeExt(object, context);
|
|
3216
3232
|
if (data != null) {
|
|
3217
|
-
|
|
3233
|
+
var type = -1 - i;
|
|
3218
3234
|
return new ExtData(type, data);
|
|
3219
3235
|
}
|
|
3220
3236
|
}
|
|
3221
3237
|
}
|
|
3222
3238
|
// custom extensions
|
|
3223
|
-
for (
|
|
3224
|
-
|
|
3239
|
+
for (var i = 0; i < this.encoders.length; i++) {
|
|
3240
|
+
var encodeExt = this.encoders[i];
|
|
3225
3241
|
if (encodeExt != null) {
|
|
3226
|
-
|
|
3242
|
+
var data = encodeExt(object, context);
|
|
3227
3243
|
if (data != null) {
|
|
3228
|
-
|
|
3244
|
+
var type = i;
|
|
3229
3245
|
return new ExtData(type, data);
|
|
3230
3246
|
}
|
|
3231
3247
|
}
|
|
@@ -3235,9 +3251,9 @@ class ExtensionCodec {
|
|
|
3235
3251
|
return object;
|
|
3236
3252
|
}
|
|
3237
3253
|
return null;
|
|
3238
|
-
}
|
|
3239
|
-
decode(data, type, context) {
|
|
3240
|
-
|
|
3254
|
+
};
|
|
3255
|
+
ExtensionCodec.prototype.decode = function (data, type, context) {
|
|
3256
|
+
var decodeExt = type < 0 ? this.builtInDecoders[-1 - type] : this.decoders[type];
|
|
3241
3257
|
if (decodeExt) {
|
|
3242
3258
|
return decodeExt(data, type, context);
|
|
3243
3259
|
}
|
|
@@ -3245,12 +3261,11 @@ class ExtensionCodec {
|
|
|
3245
3261
|
// decode() does not fail, returns ExtData instead.
|
|
3246
3262
|
return new ExtData(type, data);
|
|
3247
3263
|
}
|
|
3248
|
-
}
|
|
3249
|
-
|
|
3264
|
+
};
|
|
3265
|
+
ExtensionCodec.defaultCodec = new ExtensionCodec();
|
|
3266
|
+
return ExtensionCodec;
|
|
3267
|
+
}());
|
|
3250
3268
|
|
|
3251
|
-
function isArrayBufferLike(buffer) {
|
|
3252
|
-
return (buffer instanceof ArrayBuffer || (typeof SharedArrayBuffer !== "undefined" && buffer instanceof SharedArrayBuffer));
|
|
3253
|
-
}
|
|
3254
3269
|
function ensureUint8Array(buffer) {
|
|
3255
3270
|
if (buffer instanceof Uint8Array) {
|
|
3256
3271
|
return buffer;
|
|
@@ -3258,7 +3273,7 @@ function ensureUint8Array(buffer) {
|
|
|
3258
3273
|
else if (ArrayBuffer.isView(buffer)) {
|
|
3259
3274
|
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
3260
3275
|
}
|
|
3261
|
-
else if (
|
|
3276
|
+
else if (buffer instanceof ArrayBuffer) {
|
|
3262
3277
|
return new Uint8Array(buffer);
|
|
3263
3278
|
}
|
|
3264
3279
|
else {
|
|
@@ -3267,96 +3282,54 @@ function ensureUint8Array(buffer) {
|
|
|
3267
3282
|
}
|
|
3268
3283
|
}
|
|
3269
3284
|
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
extensionCodec
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
this.
|
|
3288
|
-
this.
|
|
3289
|
-
this.
|
|
3290
|
-
this.maxDepth = options?.maxDepth ?? DEFAULT_MAX_DEPTH;
|
|
3291
|
-
this.initialBufferSize = options?.initialBufferSize ?? DEFAULT_INITIAL_BUFFER_SIZE;
|
|
3292
|
-
this.sortKeys = options?.sortKeys ?? false;
|
|
3293
|
-
this.forceFloat32 = options?.forceFloat32 ?? false;
|
|
3294
|
-
this.ignoreUndefined = options?.ignoreUndefined ?? false;
|
|
3295
|
-
this.forceIntegerToFloat = options?.forceIntegerToFloat ?? false;
|
|
3285
|
+
var DEFAULT_MAX_DEPTH = 100;
|
|
3286
|
+
var DEFAULT_INITIAL_BUFFER_SIZE = 2048;
|
|
3287
|
+
var Encoder = /** @class */ (function () {
|
|
3288
|
+
function Encoder(extensionCodec, context, maxDepth, initialBufferSize, sortKeys, forceFloat32, ignoreUndefined, forceIntegerToFloat) {
|
|
3289
|
+
if (extensionCodec === void 0) { extensionCodec = ExtensionCodec.defaultCodec; }
|
|
3290
|
+
if (context === void 0) { context = undefined; }
|
|
3291
|
+
if (maxDepth === void 0) { maxDepth = DEFAULT_MAX_DEPTH; }
|
|
3292
|
+
if (initialBufferSize === void 0) { initialBufferSize = DEFAULT_INITIAL_BUFFER_SIZE; }
|
|
3293
|
+
if (sortKeys === void 0) { sortKeys = false; }
|
|
3294
|
+
if (forceFloat32 === void 0) { forceFloat32 = false; }
|
|
3295
|
+
if (ignoreUndefined === void 0) { ignoreUndefined = false; }
|
|
3296
|
+
if (forceIntegerToFloat === void 0) { forceIntegerToFloat = false; }
|
|
3297
|
+
this.extensionCodec = extensionCodec;
|
|
3298
|
+
this.context = context;
|
|
3299
|
+
this.maxDepth = maxDepth;
|
|
3300
|
+
this.initialBufferSize = initialBufferSize;
|
|
3301
|
+
this.sortKeys = sortKeys;
|
|
3302
|
+
this.forceFloat32 = forceFloat32;
|
|
3303
|
+
this.ignoreUndefined = ignoreUndefined;
|
|
3304
|
+
this.forceIntegerToFloat = forceIntegerToFloat;
|
|
3296
3305
|
this.pos = 0;
|
|
3297
3306
|
this.view = new DataView(new ArrayBuffer(this.initialBufferSize));
|
|
3298
3307
|
this.bytes = new Uint8Array(this.view.buffer);
|
|
3299
3308
|
}
|
|
3300
|
-
|
|
3301
|
-
// Because of slightly special argument `context`,
|
|
3302
|
-
// type assertion is needed.
|
|
3303
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
3304
|
-
return new Encoder({
|
|
3305
|
-
extensionCodec: this.extensionCodec,
|
|
3306
|
-
context: this.context,
|
|
3307
|
-
useBigInt64: this.useBigInt64,
|
|
3308
|
-
maxDepth: this.maxDepth,
|
|
3309
|
-
initialBufferSize: this.initialBufferSize,
|
|
3310
|
-
sortKeys: this.sortKeys,
|
|
3311
|
-
forceFloat32: this.forceFloat32,
|
|
3312
|
-
ignoreUndefined: this.ignoreUndefined,
|
|
3313
|
-
forceIntegerToFloat: this.forceIntegerToFloat,
|
|
3314
|
-
});
|
|
3315
|
-
}
|
|
3316
|
-
reinitializeState() {
|
|
3309
|
+
Encoder.prototype.reinitializeState = function () {
|
|
3317
3310
|
this.pos = 0;
|
|
3318
|
-
}
|
|
3311
|
+
};
|
|
3319
3312
|
/**
|
|
3320
3313
|
* This is almost equivalent to {@link Encoder#encode}, but it returns an reference of the encoder's internal buffer and thus much faster than {@link Encoder#encode}.
|
|
3321
3314
|
*
|
|
3322
3315
|
* @returns Encodes the object and returns a shared reference the encoder's internal buffer.
|
|
3323
3316
|
*/
|
|
3324
|
-
encodeSharedRef(object) {
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
try {
|
|
3330
|
-
this.entered = true;
|
|
3331
|
-
this.reinitializeState();
|
|
3332
|
-
this.doEncode(object, 1);
|
|
3333
|
-
return this.bytes.subarray(0, this.pos);
|
|
3334
|
-
}
|
|
3335
|
-
finally {
|
|
3336
|
-
this.entered = false;
|
|
3337
|
-
}
|
|
3338
|
-
}
|
|
3317
|
+
Encoder.prototype.encodeSharedRef = function (object) {
|
|
3318
|
+
this.reinitializeState();
|
|
3319
|
+
this.doEncode(object, 1);
|
|
3320
|
+
return this.bytes.subarray(0, this.pos);
|
|
3321
|
+
};
|
|
3339
3322
|
/**
|
|
3340
3323
|
* @returns Encodes the object and returns a copy of the encoder's internal buffer.
|
|
3341
3324
|
*/
|
|
3342
|
-
encode(object) {
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
this.entered = true;
|
|
3349
|
-
this.reinitializeState();
|
|
3350
|
-
this.doEncode(object, 1);
|
|
3351
|
-
return this.bytes.slice(0, this.pos);
|
|
3352
|
-
}
|
|
3353
|
-
finally {
|
|
3354
|
-
this.entered = false;
|
|
3355
|
-
}
|
|
3356
|
-
}
|
|
3357
|
-
doEncode(object, depth) {
|
|
3325
|
+
Encoder.prototype.encode = function (object) {
|
|
3326
|
+
this.reinitializeState();
|
|
3327
|
+
this.doEncode(object, 1);
|
|
3328
|
+
return this.bytes.slice(0, this.pos);
|
|
3329
|
+
};
|
|
3330
|
+
Encoder.prototype.doEncode = function (object, depth) {
|
|
3358
3331
|
if (depth > this.maxDepth) {
|
|
3359
|
-
throw new Error(
|
|
3332
|
+
throw new Error("Too deep objects in depth ".concat(depth));
|
|
3360
3333
|
}
|
|
3361
3334
|
if (object == null) {
|
|
3362
3335
|
this.encodeNil();
|
|
@@ -3365,50 +3338,42 @@ class Encoder {
|
|
|
3365
3338
|
this.encodeBoolean(object);
|
|
3366
3339
|
}
|
|
3367
3340
|
else if (typeof object === "number") {
|
|
3368
|
-
|
|
3369
|
-
this.encodeNumber(object);
|
|
3370
|
-
}
|
|
3371
|
-
else {
|
|
3372
|
-
this.encodeNumberAsFloat(object);
|
|
3373
|
-
}
|
|
3341
|
+
this.encodeNumber(object);
|
|
3374
3342
|
}
|
|
3375
3343
|
else if (typeof object === "string") {
|
|
3376
3344
|
this.encodeString(object);
|
|
3377
3345
|
}
|
|
3378
|
-
else if (this.useBigInt64 && typeof object === "bigint") {
|
|
3379
|
-
this.encodeBigInt64(object);
|
|
3380
|
-
}
|
|
3381
3346
|
else {
|
|
3382
3347
|
this.encodeObject(object, depth);
|
|
3383
3348
|
}
|
|
3384
|
-
}
|
|
3385
|
-
ensureBufferSizeToWrite(sizeToWrite) {
|
|
3386
|
-
|
|
3349
|
+
};
|
|
3350
|
+
Encoder.prototype.ensureBufferSizeToWrite = function (sizeToWrite) {
|
|
3351
|
+
var requiredSize = this.pos + sizeToWrite;
|
|
3387
3352
|
if (this.view.byteLength < requiredSize) {
|
|
3388
3353
|
this.resizeBuffer(requiredSize * 2);
|
|
3389
3354
|
}
|
|
3390
|
-
}
|
|
3391
|
-
resizeBuffer(newSize) {
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3355
|
+
};
|
|
3356
|
+
Encoder.prototype.resizeBuffer = function (newSize) {
|
|
3357
|
+
var newBuffer = new ArrayBuffer(newSize);
|
|
3358
|
+
var newBytes = new Uint8Array(newBuffer);
|
|
3359
|
+
var newView = new DataView(newBuffer);
|
|
3395
3360
|
newBytes.set(this.bytes);
|
|
3396
3361
|
this.view = newView;
|
|
3397
3362
|
this.bytes = newBytes;
|
|
3398
|
-
}
|
|
3399
|
-
encodeNil() {
|
|
3363
|
+
};
|
|
3364
|
+
Encoder.prototype.encodeNil = function () {
|
|
3400
3365
|
this.writeU8(0xc0);
|
|
3401
|
-
}
|
|
3402
|
-
encodeBoolean(object) {
|
|
3366
|
+
};
|
|
3367
|
+
Encoder.prototype.encodeBoolean = function (object) {
|
|
3403
3368
|
if (object === false) {
|
|
3404
3369
|
this.writeU8(0xc2);
|
|
3405
3370
|
}
|
|
3406
3371
|
else {
|
|
3407
3372
|
this.writeU8(0xc3);
|
|
3408
3373
|
}
|
|
3409
|
-
}
|
|
3410
|
-
encodeNumber(object) {
|
|
3411
|
-
if (
|
|
3374
|
+
};
|
|
3375
|
+
Encoder.prototype.encodeNumber = function (object) {
|
|
3376
|
+
if (Number.isSafeInteger(object) && !this.forceIntegerToFloat) {
|
|
3412
3377
|
if (object >= 0) {
|
|
3413
3378
|
if (object < 0x80) {
|
|
3414
3379
|
// positive fixint
|
|
@@ -3429,14 +3394,11 @@ class Encoder {
|
|
|
3429
3394
|
this.writeU8(0xce);
|
|
3430
3395
|
this.writeU32(object);
|
|
3431
3396
|
}
|
|
3432
|
-
else
|
|
3397
|
+
else {
|
|
3433
3398
|
// uint 64
|
|
3434
3399
|
this.writeU8(0xcf);
|
|
3435
3400
|
this.writeU64(object);
|
|
3436
3401
|
}
|
|
3437
|
-
else {
|
|
3438
|
-
this.encodeNumberAsFloat(object);
|
|
3439
|
-
}
|
|
3440
3402
|
}
|
|
3441
3403
|
else {
|
|
3442
3404
|
if (object >= -32) {
|
|
@@ -3458,45 +3420,28 @@ class Encoder {
|
|
|
3458
3420
|
this.writeU8(0xd2);
|
|
3459
3421
|
this.writeI32(object);
|
|
3460
3422
|
}
|
|
3461
|
-
else
|
|
3423
|
+
else {
|
|
3462
3424
|
// int 64
|
|
3463
3425
|
this.writeU8(0xd3);
|
|
3464
3426
|
this.writeI64(object);
|
|
3465
3427
|
}
|
|
3466
|
-
else {
|
|
3467
|
-
this.encodeNumberAsFloat(object);
|
|
3468
|
-
}
|
|
3469
3428
|
}
|
|
3470
3429
|
}
|
|
3471
3430
|
else {
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
this.writeU8(0xcb);
|
|
3484
|
-
this.writeF64(object);
|
|
3485
|
-
}
|
|
3486
|
-
}
|
|
3487
|
-
encodeBigInt64(object) {
|
|
3488
|
-
if (object >= BigInt(0)) {
|
|
3489
|
-
// uint 64
|
|
3490
|
-
this.writeU8(0xcf);
|
|
3491
|
-
this.writeBigUint64(object);
|
|
3492
|
-
}
|
|
3493
|
-
else {
|
|
3494
|
-
// int 64
|
|
3495
|
-
this.writeU8(0xd3);
|
|
3496
|
-
this.writeBigInt64(object);
|
|
3431
|
+
// non-integer numbers
|
|
3432
|
+
if (this.forceFloat32) {
|
|
3433
|
+
// float 32
|
|
3434
|
+
this.writeU8(0xca);
|
|
3435
|
+
this.writeF32(object);
|
|
3436
|
+
}
|
|
3437
|
+
else {
|
|
3438
|
+
// float 64
|
|
3439
|
+
this.writeU8(0xcb);
|
|
3440
|
+
this.writeF64(object);
|
|
3441
|
+
}
|
|
3497
3442
|
}
|
|
3498
|
-
}
|
|
3499
|
-
writeStringHeader(byteLength) {
|
|
3443
|
+
};
|
|
3444
|
+
Encoder.prototype.writeStringHeader = function (byteLength) {
|
|
3500
3445
|
if (byteLength < 32) {
|
|
3501
3446
|
// fixstr
|
|
3502
3447
|
this.writeU8(0xa0 + byteLength);
|
|
@@ -3517,20 +3462,30 @@ class Encoder {
|
|
|
3517
3462
|
this.writeU32(byteLength);
|
|
3518
3463
|
}
|
|
3519
3464
|
else {
|
|
3520
|
-
throw new Error(
|
|
3465
|
+
throw new Error("Too long string: ".concat(byteLength, " bytes in UTF-8"));
|
|
3521
3466
|
}
|
|
3522
|
-
}
|
|
3523
|
-
encodeString(object) {
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3467
|
+
};
|
|
3468
|
+
Encoder.prototype.encodeString = function (object) {
|
|
3469
|
+
var maxHeaderSize = 1 + 4;
|
|
3470
|
+
var strLength = object.length;
|
|
3471
|
+
if (strLength > TEXT_ENCODER_THRESHOLD) {
|
|
3472
|
+
var byteLength = utf8Count(object);
|
|
3473
|
+
this.ensureBufferSizeToWrite(maxHeaderSize + byteLength);
|
|
3474
|
+
this.writeStringHeader(byteLength);
|
|
3475
|
+
utf8EncodeTE(object, this.bytes, this.pos);
|
|
3476
|
+
this.pos += byteLength;
|
|
3477
|
+
}
|
|
3478
|
+
else {
|
|
3479
|
+
var byteLength = utf8Count(object);
|
|
3480
|
+
this.ensureBufferSizeToWrite(maxHeaderSize + byteLength);
|
|
3481
|
+
this.writeStringHeader(byteLength);
|
|
3482
|
+
utf8EncodeJs(object, this.bytes, this.pos);
|
|
3483
|
+
this.pos += byteLength;
|
|
3484
|
+
}
|
|
3485
|
+
};
|
|
3486
|
+
Encoder.prototype.encodeObject = function (object, depth) {
|
|
3532
3487
|
// try to encode objects with custom codec first of non-primitives
|
|
3533
|
-
|
|
3488
|
+
var ext = this.extensionCodec.tryToEncode(object, this.context);
|
|
3534
3489
|
if (ext != null) {
|
|
3535
3490
|
this.encodeExtension(ext);
|
|
3536
3491
|
}
|
|
@@ -3545,11 +3500,11 @@ class Encoder {
|
|
|
3545
3500
|
}
|
|
3546
3501
|
else {
|
|
3547
3502
|
// symbol, function and other special object come here unless extensionCodec handles them.
|
|
3548
|
-
throw new Error(
|
|
3503
|
+
throw new Error("Unrecognized object: ".concat(Object.prototype.toString.apply(object)));
|
|
3549
3504
|
}
|
|
3550
|
-
}
|
|
3551
|
-
encodeBinary(object) {
|
|
3552
|
-
|
|
3505
|
+
};
|
|
3506
|
+
Encoder.prototype.encodeBinary = function (object) {
|
|
3507
|
+
var size = object.byteLength;
|
|
3553
3508
|
if (size < 0x100) {
|
|
3554
3509
|
// bin 8
|
|
3555
3510
|
this.writeU8(0xc4);
|
|
@@ -3566,13 +3521,13 @@ class Encoder {
|
|
|
3566
3521
|
this.writeU32(size);
|
|
3567
3522
|
}
|
|
3568
3523
|
else {
|
|
3569
|
-
throw new Error(
|
|
3524
|
+
throw new Error("Too large binary: ".concat(size));
|
|
3570
3525
|
}
|
|
3571
|
-
|
|
3526
|
+
var bytes = ensureUint8Array(object);
|
|
3572
3527
|
this.writeU8a(bytes);
|
|
3573
|
-
}
|
|
3574
|
-
encodeArray(object, depth) {
|
|
3575
|
-
|
|
3528
|
+
};
|
|
3529
|
+
Encoder.prototype.encodeArray = function (object, depth) {
|
|
3530
|
+
var size = object.length;
|
|
3576
3531
|
if (size < 16) {
|
|
3577
3532
|
// fixarray
|
|
3578
3533
|
this.writeU8(0x90 + size);
|
|
@@ -3588,27 +3543,29 @@ class Encoder {
|
|
|
3588
3543
|
this.writeU32(size);
|
|
3589
3544
|
}
|
|
3590
3545
|
else {
|
|
3591
|
-
throw new Error(
|
|
3546
|
+
throw new Error("Too large array: ".concat(size));
|
|
3592
3547
|
}
|
|
3593
|
-
for (
|
|
3548
|
+
for (var _i = 0, object_1 = object; _i < object_1.length; _i++) {
|
|
3549
|
+
var item = object_1[_i];
|
|
3594
3550
|
this.doEncode(item, depth + 1);
|
|
3595
3551
|
}
|
|
3596
|
-
}
|
|
3597
|
-
countWithoutUndefined(object, keys) {
|
|
3598
|
-
|
|
3599
|
-
for (
|
|
3552
|
+
};
|
|
3553
|
+
Encoder.prototype.countWithoutUndefined = function (object, keys) {
|
|
3554
|
+
var count = 0;
|
|
3555
|
+
for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
|
|
3556
|
+
var key = keys_1[_i];
|
|
3600
3557
|
if (object[key] !== undefined) {
|
|
3601
3558
|
count++;
|
|
3602
3559
|
}
|
|
3603
3560
|
}
|
|
3604
3561
|
return count;
|
|
3605
|
-
}
|
|
3606
|
-
encodeMap(object, depth) {
|
|
3607
|
-
|
|
3562
|
+
};
|
|
3563
|
+
Encoder.prototype.encodeMap = function (object, depth) {
|
|
3564
|
+
var keys = Object.keys(object);
|
|
3608
3565
|
if (this.sortKeys) {
|
|
3609
3566
|
keys.sort();
|
|
3610
3567
|
}
|
|
3611
|
-
|
|
3568
|
+
var size = this.ignoreUndefined ? this.countWithoutUndefined(object, keys) : keys.length;
|
|
3612
3569
|
if (size < 16) {
|
|
3613
3570
|
// fixmap
|
|
3614
3571
|
this.writeU8(0x80 + size);
|
|
@@ -3624,30 +3581,19 @@ class Encoder {
|
|
|
3624
3581
|
this.writeU32(size);
|
|
3625
3582
|
}
|
|
3626
3583
|
else {
|
|
3627
|
-
throw new Error(
|
|
3584
|
+
throw new Error("Too large map object: ".concat(size));
|
|
3628
3585
|
}
|
|
3629
|
-
for (
|
|
3630
|
-
|
|
3586
|
+
for (var _i = 0, keys_2 = keys; _i < keys_2.length; _i++) {
|
|
3587
|
+
var key = keys_2[_i];
|
|
3588
|
+
var value = object[key];
|
|
3631
3589
|
if (!(this.ignoreUndefined && value === undefined)) {
|
|
3632
3590
|
this.encodeString(key);
|
|
3633
3591
|
this.doEncode(value, depth + 1);
|
|
3634
3592
|
}
|
|
3635
3593
|
}
|
|
3636
|
-
}
|
|
3637
|
-
encodeExtension(ext) {
|
|
3638
|
-
|
|
3639
|
-
const data = ext.data(this.pos + 6);
|
|
3640
|
-
const size = data.length;
|
|
3641
|
-
if (size >= 0x100000000) {
|
|
3642
|
-
throw new Error(`Too large extension object: ${size}`);
|
|
3643
|
-
}
|
|
3644
|
-
this.writeU8(0xc9);
|
|
3645
|
-
this.writeU32(size);
|
|
3646
|
-
this.writeI8(ext.type);
|
|
3647
|
-
this.writeU8a(data);
|
|
3648
|
-
return;
|
|
3649
|
-
}
|
|
3650
|
-
const size = ext.data.length;
|
|
3594
|
+
};
|
|
3595
|
+
Encoder.prototype.encodeExtension = function (ext) {
|
|
3596
|
+
var size = ext.data.length;
|
|
3651
3597
|
if (size === 1) {
|
|
3652
3598
|
// fixext 1
|
|
3653
3599
|
this.writeU8(0xd4);
|
|
@@ -3684,79 +3630,71 @@ class Encoder {
|
|
|
3684
3630
|
this.writeU32(size);
|
|
3685
3631
|
}
|
|
3686
3632
|
else {
|
|
3687
|
-
throw new Error(
|
|
3633
|
+
throw new Error("Too large extension object: ".concat(size));
|
|
3688
3634
|
}
|
|
3689
3635
|
this.writeI8(ext.type);
|
|
3690
3636
|
this.writeU8a(ext.data);
|
|
3691
|
-
}
|
|
3692
|
-
writeU8(value) {
|
|
3637
|
+
};
|
|
3638
|
+
Encoder.prototype.writeU8 = function (value) {
|
|
3693
3639
|
this.ensureBufferSizeToWrite(1);
|
|
3694
3640
|
this.view.setUint8(this.pos, value);
|
|
3695
3641
|
this.pos++;
|
|
3696
|
-
}
|
|
3697
|
-
writeU8a(values) {
|
|
3698
|
-
|
|
3642
|
+
};
|
|
3643
|
+
Encoder.prototype.writeU8a = function (values) {
|
|
3644
|
+
var size = values.length;
|
|
3699
3645
|
this.ensureBufferSizeToWrite(size);
|
|
3700
3646
|
this.bytes.set(values, this.pos);
|
|
3701
3647
|
this.pos += size;
|
|
3702
|
-
}
|
|
3703
|
-
writeI8(value) {
|
|
3648
|
+
};
|
|
3649
|
+
Encoder.prototype.writeI8 = function (value) {
|
|
3704
3650
|
this.ensureBufferSizeToWrite(1);
|
|
3705
3651
|
this.view.setInt8(this.pos, value);
|
|
3706
3652
|
this.pos++;
|
|
3707
|
-
}
|
|
3708
|
-
writeU16(value) {
|
|
3653
|
+
};
|
|
3654
|
+
Encoder.prototype.writeU16 = function (value) {
|
|
3709
3655
|
this.ensureBufferSizeToWrite(2);
|
|
3710
3656
|
this.view.setUint16(this.pos, value);
|
|
3711
3657
|
this.pos += 2;
|
|
3712
|
-
}
|
|
3713
|
-
writeI16(value) {
|
|
3658
|
+
};
|
|
3659
|
+
Encoder.prototype.writeI16 = function (value) {
|
|
3714
3660
|
this.ensureBufferSizeToWrite(2);
|
|
3715
3661
|
this.view.setInt16(this.pos, value);
|
|
3716
3662
|
this.pos += 2;
|
|
3717
|
-
}
|
|
3718
|
-
writeU32(value) {
|
|
3663
|
+
};
|
|
3664
|
+
Encoder.prototype.writeU32 = function (value) {
|
|
3719
3665
|
this.ensureBufferSizeToWrite(4);
|
|
3720
3666
|
this.view.setUint32(this.pos, value);
|
|
3721
3667
|
this.pos += 4;
|
|
3722
|
-
}
|
|
3723
|
-
writeI32(value) {
|
|
3668
|
+
};
|
|
3669
|
+
Encoder.prototype.writeI32 = function (value) {
|
|
3724
3670
|
this.ensureBufferSizeToWrite(4);
|
|
3725
3671
|
this.view.setInt32(this.pos, value);
|
|
3726
3672
|
this.pos += 4;
|
|
3727
|
-
}
|
|
3728
|
-
writeF32(value) {
|
|
3673
|
+
};
|
|
3674
|
+
Encoder.prototype.writeF32 = function (value) {
|
|
3729
3675
|
this.ensureBufferSizeToWrite(4);
|
|
3730
3676
|
this.view.setFloat32(this.pos, value);
|
|
3731
3677
|
this.pos += 4;
|
|
3732
|
-
}
|
|
3733
|
-
writeF64(value) {
|
|
3678
|
+
};
|
|
3679
|
+
Encoder.prototype.writeF64 = function (value) {
|
|
3734
3680
|
this.ensureBufferSizeToWrite(8);
|
|
3735
3681
|
this.view.setFloat64(this.pos, value);
|
|
3736
3682
|
this.pos += 8;
|
|
3737
|
-
}
|
|
3738
|
-
writeU64(value) {
|
|
3683
|
+
};
|
|
3684
|
+
Encoder.prototype.writeU64 = function (value) {
|
|
3739
3685
|
this.ensureBufferSizeToWrite(8);
|
|
3740
3686
|
setUint64(this.view, this.pos, value);
|
|
3741
3687
|
this.pos += 8;
|
|
3742
|
-
}
|
|
3743
|
-
writeI64(value) {
|
|
3688
|
+
};
|
|
3689
|
+
Encoder.prototype.writeI64 = function (value) {
|
|
3744
3690
|
this.ensureBufferSizeToWrite(8);
|
|
3745
3691
|
setInt64(this.view, this.pos, value);
|
|
3746
3692
|
this.pos += 8;
|
|
3747
|
-
}
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
this.view.setBigUint64(this.pos, value);
|
|
3751
|
-
this.pos += 8;
|
|
3752
|
-
}
|
|
3753
|
-
writeBigInt64(value) {
|
|
3754
|
-
this.ensureBufferSizeToWrite(8);
|
|
3755
|
-
this.view.setBigInt64(this.pos, value);
|
|
3756
|
-
this.pos += 8;
|
|
3757
|
-
}
|
|
3758
|
-
}
|
|
3693
|
+
};
|
|
3694
|
+
return Encoder;
|
|
3695
|
+
}());
|
|
3759
3696
|
|
|
3697
|
+
var defaultEncodeOptions = {};
|
|
3760
3698
|
/**
|
|
3761
3699
|
* It encodes `value` in the MessagePack format and
|
|
3762
3700
|
* returns a byte buffer.
|
|
@@ -3764,36 +3702,37 @@ class Encoder {
|
|
|
3764
3702
|
* The returned buffer is a slice of a larger `ArrayBuffer`, so you have to use its `#byteOffset` and `#byteLength` in order to convert it to another typed arrays including NodeJS `Buffer`.
|
|
3765
3703
|
*/
|
|
3766
3704
|
function encode(value, options) {
|
|
3767
|
-
|
|
3705
|
+
if (options === void 0) { options = defaultEncodeOptions; }
|
|
3706
|
+
var encoder = new Encoder(options.extensionCodec, options.context, options.maxDepth, options.initialBufferSize, options.sortKeys, options.forceFloat32, options.ignoreUndefined, options.forceIntegerToFloat);
|
|
3768
3707
|
return encoder.encodeSharedRef(value);
|
|
3769
3708
|
}
|
|
3770
3709
|
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
maxKeyLength;
|
|
3778
|
-
maxLengthPerKey;
|
|
3779
|
-
constructor(maxKeyLength = DEFAULT_MAX_KEY_LENGTH, maxLengthPerKey = DEFAULT_MAX_LENGTH_PER_KEY) {
|
|
3710
|
+
var DEFAULT_MAX_KEY_LENGTH = 16;
|
|
3711
|
+
var DEFAULT_MAX_LENGTH_PER_KEY = 16;
|
|
3712
|
+
var CachedKeyDecoder = /** @class */ (function () {
|
|
3713
|
+
function CachedKeyDecoder(maxKeyLength, maxLengthPerKey) {
|
|
3714
|
+
if (maxKeyLength === void 0) { maxKeyLength = DEFAULT_MAX_KEY_LENGTH; }
|
|
3715
|
+
if (maxLengthPerKey === void 0) { maxLengthPerKey = DEFAULT_MAX_LENGTH_PER_KEY; }
|
|
3780
3716
|
this.maxKeyLength = maxKeyLength;
|
|
3781
3717
|
this.maxLengthPerKey = maxLengthPerKey;
|
|
3718
|
+
this.hit = 0;
|
|
3719
|
+
this.miss = 0;
|
|
3782
3720
|
// avoid `new Array(N)`, which makes a sparse array,
|
|
3783
3721
|
// because a sparse array is typically slower than a non-sparse array.
|
|
3784
3722
|
this.caches = [];
|
|
3785
|
-
for (
|
|
3723
|
+
for (var i = 0; i < this.maxKeyLength; i++) {
|
|
3786
3724
|
this.caches.push([]);
|
|
3787
3725
|
}
|
|
3788
3726
|
}
|
|
3789
|
-
canBeCached(byteLength) {
|
|
3727
|
+
CachedKeyDecoder.prototype.canBeCached = function (byteLength) {
|
|
3790
3728
|
return byteLength > 0 && byteLength <= this.maxKeyLength;
|
|
3791
|
-
}
|
|
3792
|
-
find(bytes, inputOffset, byteLength) {
|
|
3793
|
-
|
|
3794
|
-
FIND_CHUNK: for (
|
|
3795
|
-
|
|
3796
|
-
|
|
3729
|
+
};
|
|
3730
|
+
CachedKeyDecoder.prototype.find = function (bytes, inputOffset, byteLength) {
|
|
3731
|
+
var records = this.caches[byteLength - 1];
|
|
3732
|
+
FIND_CHUNK: for (var _i = 0, records_1 = records; _i < records_1.length; _i++) {
|
|
3733
|
+
var record = records_1[_i];
|
|
3734
|
+
var recordBytes = record.bytes;
|
|
3735
|
+
for (var j = 0; j < byteLength; j++) {
|
|
3797
3736
|
if (recordBytes[j] !== bytes[inputOffset + j]) {
|
|
3798
3737
|
continue FIND_CHUNK;
|
|
3799
3738
|
}
|
|
@@ -3801,10 +3740,10 @@ class CachedKeyDecoder {
|
|
|
3801
3740
|
return record.str;
|
|
3802
3741
|
}
|
|
3803
3742
|
return null;
|
|
3804
|
-
}
|
|
3805
|
-
store(bytes, value) {
|
|
3806
|
-
|
|
3807
|
-
|
|
3743
|
+
};
|
|
3744
|
+
CachedKeyDecoder.prototype.store = function (bytes, value) {
|
|
3745
|
+
var records = this.caches[bytes.length - 1];
|
|
3746
|
+
var record = { bytes: bytes, str: value };
|
|
3808
3747
|
if (records.length >= this.maxLengthPerKey) {
|
|
3809
3748
|
// `records` are full!
|
|
3810
3749
|
// Set `record` to an arbitrary position.
|
|
@@ -3813,36 +3752,174 @@ class CachedKeyDecoder {
|
|
|
3813
3752
|
else {
|
|
3814
3753
|
records.push(record);
|
|
3815
3754
|
}
|
|
3816
|
-
}
|
|
3817
|
-
decode(bytes, inputOffset, byteLength) {
|
|
3818
|
-
|
|
3755
|
+
};
|
|
3756
|
+
CachedKeyDecoder.prototype.decode = function (bytes, inputOffset, byteLength) {
|
|
3757
|
+
var cachedValue = this.find(bytes, inputOffset, byteLength);
|
|
3819
3758
|
if (cachedValue != null) {
|
|
3820
3759
|
this.hit++;
|
|
3821
3760
|
return cachedValue;
|
|
3822
3761
|
}
|
|
3823
3762
|
this.miss++;
|
|
3824
|
-
|
|
3825
|
-
// Ensure to copy a slice of bytes because the
|
|
3826
|
-
|
|
3763
|
+
var str = utf8DecodeJs(bytes, inputOffset, byteLength);
|
|
3764
|
+
// Ensure to copy a slice of bytes because the byte may be NodeJS Buffer and Buffer#slice() returns a reference to its internal ArrayBuffer.
|
|
3765
|
+
var slicedCopyOfBytes = Uint8Array.prototype.slice.call(bytes, inputOffset, inputOffset + byteLength);
|
|
3827
3766
|
this.store(slicedCopyOfBytes, str);
|
|
3828
3767
|
return str;
|
|
3768
|
+
};
|
|
3769
|
+
return CachedKeyDecoder;
|
|
3770
|
+
}());
|
|
3771
|
+
|
|
3772
|
+
(undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3773
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3774
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
3775
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
3776
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
3777
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
3778
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
3779
|
+
});
|
|
3780
|
+
};
|
|
3781
|
+
(undefined && undefined.__generator) || function (thisArg, body) {
|
|
3782
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
3783
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
3784
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
3785
|
+
function step(op) {
|
|
3786
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
3787
|
+
while (_) try {
|
|
3788
|
+
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) return t;
|
|
3789
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
3790
|
+
switch (op[0]) {
|
|
3791
|
+
case 0: case 1: t = op; break;
|
|
3792
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
3793
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
3794
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
3795
|
+
default:
|
|
3796
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
3797
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
3798
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
3799
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
3800
|
+
if (t[2]) _.ops.pop();
|
|
3801
|
+
_.trys.pop(); continue;
|
|
3802
|
+
}
|
|
3803
|
+
op = body.call(thisArg, _);
|
|
3804
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
3805
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
3829
3806
|
}
|
|
3830
|
-
}
|
|
3831
|
-
|
|
3832
|
-
|
|
3807
|
+
};
|
|
3808
|
+
(undefined && undefined.__asyncValues) || function (o) {
|
|
3809
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
3810
|
+
var m = o[Symbol.asyncIterator], i;
|
|
3811
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
3812
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
3813
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
3814
|
+
};
|
|
3815
|
+
var __await$1 = (undefined && undefined.__await) || function (v) { return this instanceof __await$1 ? (this.v = v, this) : new __await$1(v); };
|
|
3816
|
+
(undefined && undefined.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
3817
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
3818
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
3819
|
+
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
3820
|
+
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
|
3821
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
3822
|
+
function step(r) { r.value instanceof __await$1 ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
3823
|
+
function fulfill(value) { resume("next", value); }
|
|
3824
|
+
function reject(value) { resume("throw", value); }
|
|
3825
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
3826
|
+
};
|
|
3827
|
+
var EMPTY_VIEW = new DataView(new ArrayBuffer(0));
|
|
3833
3828
|
new Uint8Array(EMPTY_VIEW.buffer);
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
throw new Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access");
|
|
3829
|
+
// IE11: Hack to support IE11.
|
|
3830
|
+
// IE11: Drop this hack and just use RangeError when IE11 is obsolete.
|
|
3831
|
+
var DataViewIndexOutOfBoundsError = (function () {
|
|
3832
|
+
try {
|
|
3833
|
+
// IE11: The spec says it should throw RangeError,
|
|
3834
|
+
// IE11: but in IE11 it throws TypeError.
|
|
3835
|
+
EMPTY_VIEW.getInt8(0);
|
|
3842
3836
|
}
|
|
3843
|
-
|
|
3837
|
+
catch (e) {
|
|
3838
|
+
return e.constructor;
|
|
3839
|
+
}
|
|
3840
|
+
throw new Error("never reached");
|
|
3841
|
+
})();
|
|
3842
|
+
new DataViewIndexOutOfBoundsError("Insufficient data");
|
|
3844
3843
|
new CachedKeyDecoder();
|
|
3845
3844
|
|
|
3845
|
+
// utility for whatwg streams
|
|
3846
|
+
(undefined && undefined.__generator) || function (thisArg, body) {
|
|
3847
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
3848
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
3849
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
3850
|
+
function step(op) {
|
|
3851
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
3852
|
+
while (_) try {
|
|
3853
|
+
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) return t;
|
|
3854
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
3855
|
+
switch (op[0]) {
|
|
3856
|
+
case 0: case 1: t = op; break;
|
|
3857
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
3858
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
3859
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
3860
|
+
default:
|
|
3861
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
3862
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
3863
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
3864
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
3865
|
+
if (t[2]) _.ops.pop();
|
|
3866
|
+
_.trys.pop(); continue;
|
|
3867
|
+
}
|
|
3868
|
+
op = body.call(thisArg, _);
|
|
3869
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
3870
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
3871
|
+
}
|
|
3872
|
+
};
|
|
3873
|
+
var __await = (undefined && undefined.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); };
|
|
3874
|
+
(undefined && undefined.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
3875
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
3876
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
3877
|
+
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
3878
|
+
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
|
3879
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
3880
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
3881
|
+
function fulfill(value) { resume("next", value); }
|
|
3882
|
+
function reject(value) { resume("throw", value); }
|
|
3883
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
3884
|
+
};
|
|
3885
|
+
|
|
3886
|
+
(undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3887
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3888
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
3889
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
3890
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
3891
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
3892
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
3893
|
+
});
|
|
3894
|
+
};
|
|
3895
|
+
(undefined && undefined.__generator) || function (thisArg, body) {
|
|
3896
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
3897
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
3898
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
3899
|
+
function step(op) {
|
|
3900
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
3901
|
+
while (_) try {
|
|
3902
|
+
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) return t;
|
|
3903
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
3904
|
+
switch (op[0]) {
|
|
3905
|
+
case 0: case 1: t = op; break;
|
|
3906
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
3907
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
3908
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
3909
|
+
default:
|
|
3910
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
3911
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
3912
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
3913
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
3914
|
+
if (t[2]) _.ops.pop();
|
|
3915
|
+
_.trys.pop(); continue;
|
|
3916
|
+
}
|
|
3917
|
+
op = body.call(thisArg, _);
|
|
3918
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
3919
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
3920
|
+
}
|
|
3921
|
+
};
|
|
3922
|
+
|
|
3846
3923
|
function encodeMiniProgramShareExtra(value) {
|
|
3847
3924
|
assertExtraValue(value);
|
|
3848
3925
|
const bytes = encode(value);
|