@heybox/hb-sdk 0.7.4 → 0.8.0-alpha
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 +61 -0
- package/README.md +14 -14
- package/dist/cli-chunks/{build-CVPqGQY3.cjs → build-DJWFSM1B.cjs} +6 -5
- package/dist/cli-chunks/{context-C1nTGr-R.cjs → context-DV2UK1Nz.cjs} +2 -2
- package/dist/cli-chunks/{create-C5qrLLvv.cjs → create-2HfoB48V.cjs} +1 -1
- package/dist/cli-chunks/{dev-U5BlN4ei.cjs → dev-Dgt2zS9k.cjs} +8 -8
- package/dist/cli-chunks/{doctor-DxqHMTbm.cjs → doctor-C95gIao_.cjs} +1 -1
- package/dist/cli-chunks/{index-BfR6OZeU.cjs → index-BjoSXl8C.cjs} +2 -2
- package/dist/cli-chunks/{index-DLrcC_ij.cjs → index-D62ANeBv.cjs} +14 -14
- package/dist/cli-chunks/{index.esm-DbbyeU1z.cjs → index.esm-CigcxJ2B.cjs} +6 -6
- package/dist/cli-chunks/{login-DQkArK14.cjs → login-Cumknwdx.cjs} +2 -2
- package/dist/cli-chunks/{project-vite-c13CKUUl.cjs → project-vite-CcE-HMmd.cjs} +1 -1
- package/dist/cli-chunks/{remote-816SyJyA.cjs → remote-DDdP3xcE.cjs} +10 -8
- package/dist/cli-chunks/{runtime-gate-CtV7rWyX.cjs → runtime-gate-DFjw66kF.cjs} +20 -1
- package/dist/cli-chunks/{runtime-permission-env-D-8_jPG3.cjs → runtime-permission-env-CjsCe5bp.cjs} +13 -13
- package/dist/cli-chunks/{session-ySUU0fVq.cjs → session-BDi_AZSv.cjs} +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/devtools/browser-dev-host/main.js +654 -472
- package/dist/index.cjs.js +714 -639
- package/dist/index.esm.js +714 -639
- package/dist/miniapp-publish.cjs.js +13 -13
- package/dist/miniapp-publish.esm.js +13 -13
- package/dist/templates/vue3-vite-ts/README.md.ejs +2 -0
- package/dist/templates/vue3-vite-ts/vite.config.ts +1 -1
- package/dist/vite.cjs.js +31 -4
- package/dist/vite.esm.js +31 -5
- package/package.json +11 -8
- package/skill/references/api-protocol.md +14 -2
- package/skill/references/api-root.md +42 -21
- package/skill/references/examples.md +1 -1
- package/skill/references/safety-boundaries.md +1 -1
- package/skill/scripts/sync-references.mjs +3 -1
- package/skill/skill.json +4 -4
- package/types/core/errors.d.ts +5 -5
- package/types/core/sdk.d.ts +5 -5
- package/types/core/singleton.d.ts +56 -6
- package/types/miniapp-manifest/schema.d.ts +5 -0
- package/types/miniapp-publish/index.d.ts +8 -8
- package/types/modules/auth/index.d.ts +15 -1
- package/types/modules/cloud/index.d.ts +75 -5
- package/types/modules/device/index.d.ts +31 -3
- package/types/modules/navigation/index.d.ts +46 -4
- package/types/modules/network/index.d.ts +22 -11
- package/types/modules/share/copy-link.d.ts +3 -3
- package/types/modules/share/index.d.ts +61 -5
- package/types/modules/share/screenshot.d.ts +3 -3
- package/types/modules/share/show-share-menu.d.ts +3 -3
- package/types/modules/storage/index.d.ts +38 -10
- package/types/modules/ui/index.d.ts +46 -4
- package/types/modules/user/get-info.d.ts +1 -1
- package/types/modules/user/index.d.ts +46 -4
- package/types/modules/user/steam-game-list.d.ts +2 -2
- package/types/modules/viewport/index.d.ts +36 -8
- package/types/vite/index.d.ts +15 -7
package/dist/index.cjs.js
CHANGED
|
@@ -296,9 +296,9 @@ class HbMiniProgramSDKError extends Error {
|
|
|
296
296
|
/**
|
|
297
297
|
* 创建 SDK 标准错误。
|
|
298
298
|
*
|
|
299
|
-
* @param code 稳定错误码。
|
|
300
|
-
* @param message 面向开发者的错误说明。
|
|
301
|
-
* @param data 可选调试数据。
|
|
299
|
+
* @param code - 稳定错误码。
|
|
300
|
+
* @param message - 面向开发者的错误说明。
|
|
301
|
+
* @param data - 可选调试数据。
|
|
302
302
|
* @returns 标准化 `HbMiniProgramSDKError` 实例。
|
|
303
303
|
*
|
|
304
304
|
* @remarks
|
|
@@ -318,7 +318,7 @@ function createSDKError(code, message, data) {
|
|
|
318
318
|
* 仅在请求已经成功走完 bridge / runtime / 宿主调用链、但最终 HTTP 状态不满足
|
|
319
319
|
* `validateStatus` 时抛出。它不表示握手失败或 bridge 级错误。
|
|
320
320
|
*
|
|
321
|
-
* @typeParam T 标准化响应数据的类型。
|
|
321
|
+
* @typeParam T - 标准化响应数据的类型。
|
|
322
322
|
*/
|
|
323
323
|
class HbMiniProgramNetworkError extends Error {
|
|
324
324
|
/** HTTP 状态码。 */
|
|
@@ -332,7 +332,7 @@ class HbMiniProgramNetworkError extends Error {
|
|
|
332
332
|
/** 完整标准化响应。 */
|
|
333
333
|
response;
|
|
334
334
|
/**
|
|
335
|
-
* @param response 已完成请求的标准化网络响应。
|
|
335
|
+
* @param response - 已完成请求的标准化网络响应。
|
|
336
336
|
*/
|
|
337
337
|
constructor(response) {
|
|
338
338
|
const method = (response.config.method || 'GET').toUpperCase();
|
|
@@ -672,7 +672,7 @@ function createMessageId() {
|
|
|
672
672
|
/** 构建时替换为当前发布包的实际版本。 */
|
|
673
673
|
const HB_SDK_VERSION = typeof undefined === 'string'
|
|
674
674
|
? undefined
|
|
675
|
-
: '0.
|
|
675
|
+
: '0.8.0-alpha';
|
|
676
676
|
|
|
677
677
|
const DEFAULT_TIMEOUT = 10000;
|
|
678
678
|
const HANDSHAKE_RETRY_INTERVAL = 250;
|
|
@@ -1052,51 +1052,80 @@ function createCloudModule(requester) {
|
|
|
1052
1052
|
/**
|
|
1053
1053
|
* 复制当前小程序的通用分享链接。
|
|
1054
1054
|
*
|
|
1055
|
-
* @param requester 底层 bridge 请求能力。
|
|
1056
|
-
* @param options 分享扩展数据;不传时复制默认首页链接。
|
|
1055
|
+
* @param requester - 底层 bridge 请求能力。
|
|
1056
|
+
* @param options - 分享扩展数据;不传时复制默认首页链接。
|
|
1057
1057
|
* @returns 已写入系统剪贴板的完整分享链接。
|
|
1058
|
-
* @throws {HbMiniProgramSDKError} 当参数、bridge、父容器或剪贴板能力调用失败时抛出。
|
|
1058
|
+
* @throws {@link HbMiniProgramSDKError} 当参数、bridge、父容器或剪贴板能力调用失败时抛出。
|
|
1059
1059
|
*/
|
|
1060
1060
|
function copyLink(requester, options) {
|
|
1061
1061
|
return requester.request(SHARE_COPY_LINK_METHOD, options);
|
|
1062
1062
|
}
|
|
1063
1063
|
|
|
1064
|
-
//
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1064
|
+
// Integer Utility
|
|
1065
|
+
var UINT32_MAX = 4294967295;
|
|
1066
|
+
function setInt64(view, offset, value) {
|
|
1067
|
+
var high = Math.floor(value / 4294967296);
|
|
1068
|
+
var low = value; // high bits are truncated by DataView
|
|
1069
|
+
view.setUint32(offset, high);
|
|
1070
|
+
view.setUint32(offset + 4, low);
|
|
1071
|
+
}
|
|
1072
|
+
function getInt64(view, offset) {
|
|
1073
|
+
var high = view.getInt32(offset);
|
|
1074
|
+
var low = view.getUint32(offset + 4);
|
|
1075
|
+
return high * 4294967296 + low;
|
|
1076
|
+
}
|
|
1077
|
+
function getUint64(view, offset) {
|
|
1078
|
+
var high = view.getUint32(offset);
|
|
1079
|
+
var low = view.getUint32(offset + 4);
|
|
1080
|
+
return high * 4294967296 + low;
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
var _a, _b, _c;
|
|
1084
|
+
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") &&
|
|
1085
|
+
typeof TextEncoder !== "undefined" &&
|
|
1086
|
+
typeof TextDecoder !== "undefined";
|
|
1087
|
+
var sharedTextEncoder = TEXT_ENCODING_AVAILABLE ? new TextEncoder() : undefined;
|
|
1088
|
+
!TEXT_ENCODING_AVAILABLE
|
|
1089
|
+
? UINT32_MAX
|
|
1090
|
+
: typeof process !== "undefined" && ((_b = process === null || process === void 0 ? void 0 : process.env) === null || _b === void 0 ? void 0 : _b["TEXT_ENCODING"]) !== "force"
|
|
1091
|
+
? 200
|
|
1092
|
+
: 0;
|
|
1093
|
+
function utf8EncodeTEencode(str, output, outputOffset) {
|
|
1094
|
+
output.set(sharedTextEncoder.encode(str), outputOffset);
|
|
1095
|
+
}
|
|
1096
|
+
function utf8EncodeTEencodeInto(str, output, outputOffset) {
|
|
1097
|
+
sharedTextEncoder.encodeInto(str, output.subarray(outputOffset));
|
|
1098
|
+
}
|
|
1099
|
+
(sharedTextEncoder === null || sharedTextEncoder === void 0 ? void 0 : sharedTextEncoder.encodeInto) ? utf8EncodeTEencodeInto : utf8EncodeTEencode;
|
|
1100
|
+
var CHUNK_SIZE = 4096;
|
|
1072
1101
|
function utf8DecodeJs(bytes, inputOffset, byteLength) {
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1102
|
+
var offset = inputOffset;
|
|
1103
|
+
var end = offset + byteLength;
|
|
1104
|
+
var units = [];
|
|
1105
|
+
var result = "";
|
|
1077
1106
|
while (offset < end) {
|
|
1078
|
-
|
|
1107
|
+
var byte1 = bytes[offset++];
|
|
1079
1108
|
if ((byte1 & 0x80) === 0) {
|
|
1080
1109
|
// 1 byte
|
|
1081
1110
|
units.push(byte1);
|
|
1082
1111
|
}
|
|
1083
1112
|
else if ((byte1 & 0xe0) === 0xc0) {
|
|
1084
1113
|
// 2 bytes
|
|
1085
|
-
|
|
1114
|
+
var byte2 = bytes[offset++] & 0x3f;
|
|
1086
1115
|
units.push(((byte1 & 0x1f) << 6) | byte2);
|
|
1087
1116
|
}
|
|
1088
1117
|
else if ((byte1 & 0xf0) === 0xe0) {
|
|
1089
1118
|
// 3 bytes
|
|
1090
|
-
|
|
1091
|
-
|
|
1119
|
+
var byte2 = bytes[offset++] & 0x3f;
|
|
1120
|
+
var byte3 = bytes[offset++] & 0x3f;
|
|
1092
1121
|
units.push(((byte1 & 0x1f) << 12) | (byte2 << 6) | byte3);
|
|
1093
1122
|
}
|
|
1094
1123
|
else if ((byte1 & 0xf8) === 0xf0) {
|
|
1095
1124
|
// 4 bytes
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1125
|
+
var byte2 = bytes[offset++] & 0x3f;
|
|
1126
|
+
var byte3 = bytes[offset++] & 0x3f;
|
|
1127
|
+
var byte4 = bytes[offset++] & 0x3f;
|
|
1128
|
+
var unit = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0c) | (byte3 << 0x06) | byte4;
|
|
1100
1129
|
if (unit > 0xffff) {
|
|
1101
1130
|
unit -= 0x10000;
|
|
1102
1131
|
units.push(((unit >>> 10) & 0x3ff) | 0xd800);
|
|
@@ -1108,97 +1137,90 @@ function utf8DecodeJs(bytes, inputOffset, byteLength) {
|
|
|
1108
1137
|
units.push(byte1);
|
|
1109
1138
|
}
|
|
1110
1139
|
if (units.length >= CHUNK_SIZE) {
|
|
1111
|
-
result += String.fromCharCode(
|
|
1140
|
+
result += String.fromCharCode.apply(String, units);
|
|
1112
1141
|
units.length = 0;
|
|
1113
1142
|
}
|
|
1114
1143
|
}
|
|
1115
1144
|
if (units.length > 0) {
|
|
1116
|
-
result += String.fromCharCode(
|
|
1145
|
+
result += String.fromCharCode.apply(String, units);
|
|
1117
1146
|
}
|
|
1118
1147
|
return result;
|
|
1119
1148
|
}
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1149
|
+
var sharedTextDecoder = TEXT_ENCODING_AVAILABLE ? new TextDecoder() : null;
|
|
1150
|
+
var TEXT_DECODER_THRESHOLD = !TEXT_ENCODING_AVAILABLE
|
|
1151
|
+
? UINT32_MAX
|
|
1152
|
+
: typeof process !== "undefined" && ((_c = process === null || process === void 0 ? void 0 : process.env) === null || _c === void 0 ? void 0 : _c["TEXT_DECODER"]) !== "force"
|
|
1153
|
+
? 200
|
|
1154
|
+
: 0;
|
|
1124
1155
|
function utf8DecodeTD(bytes, inputOffset, byteLength) {
|
|
1125
|
-
|
|
1156
|
+
var stringBytes = bytes.subarray(inputOffset, inputOffset + byteLength);
|
|
1126
1157
|
return sharedTextDecoder.decode(stringBytes);
|
|
1127
1158
|
}
|
|
1128
|
-
function utf8Decode(bytes, inputOffset, byteLength) {
|
|
1129
|
-
if (byteLength > TEXT_DECODER_THRESHOLD) {
|
|
1130
|
-
return utf8DecodeTD(bytes, inputOffset, byteLength);
|
|
1131
|
-
}
|
|
1132
|
-
else {
|
|
1133
|
-
return utf8DecodeJs(bytes, inputOffset, byteLength);
|
|
1134
|
-
}
|
|
1135
|
-
}
|
|
1136
1159
|
|
|
1137
1160
|
/**
|
|
1138
1161
|
* ExtData is used to handle Extension Types that are not registered to ExtensionCodec.
|
|
1139
1162
|
*/
|
|
1140
|
-
|
|
1141
|
-
type
|
|
1142
|
-
data;
|
|
1143
|
-
constructor(type, data) {
|
|
1163
|
+
var ExtData = /** @class */ (function () {
|
|
1164
|
+
function ExtData(type, data) {
|
|
1144
1165
|
this.type = type;
|
|
1145
1166
|
this.data = data;
|
|
1146
1167
|
}
|
|
1147
|
-
|
|
1168
|
+
return ExtData;
|
|
1169
|
+
}());
|
|
1148
1170
|
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1171
|
+
var __extends = (undefined && undefined.__extends) || (function () {
|
|
1172
|
+
var extendStatics = function (d, b) {
|
|
1173
|
+
extendStatics = Object.setPrototypeOf ||
|
|
1174
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
1175
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
1176
|
+
return extendStatics(d, b);
|
|
1177
|
+
};
|
|
1178
|
+
return function (d, b) {
|
|
1179
|
+
if (typeof b !== "function" && b !== null)
|
|
1180
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
1181
|
+
extendStatics(d, b);
|
|
1182
|
+
function __() { this.constructor = d; }
|
|
1183
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
1184
|
+
};
|
|
1185
|
+
})();
|
|
1186
|
+
var DecodeError = /** @class */ (function (_super) {
|
|
1187
|
+
__extends(DecodeError, _super);
|
|
1188
|
+
function DecodeError(message) {
|
|
1189
|
+
var _this = _super.call(this, message) || this;
|
|
1152
1190
|
// fix the prototype chain in a cross-platform way
|
|
1153
|
-
|
|
1154
|
-
Object.setPrototypeOf(
|
|
1155
|
-
Object.defineProperty(
|
|
1191
|
+
var proto = Object.create(DecodeError.prototype);
|
|
1192
|
+
Object.setPrototypeOf(_this, proto);
|
|
1193
|
+
Object.defineProperty(_this, "name", {
|
|
1156
1194
|
configurable: true,
|
|
1157
1195
|
enumerable: false,
|
|
1158
1196
|
value: DecodeError.name,
|
|
1159
1197
|
});
|
|
1198
|
+
return _this;
|
|
1160
1199
|
}
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
// Integer Utility
|
|
1164
|
-
const UINT32_MAX = 4294967295;
|
|
1165
|
-
function setInt64(view, offset, value) {
|
|
1166
|
-
const high = Math.floor(value / 4294967296);
|
|
1167
|
-
const low = value; // high bits are truncated by DataView
|
|
1168
|
-
view.setUint32(offset, high);
|
|
1169
|
-
view.setUint32(offset + 4, low);
|
|
1170
|
-
}
|
|
1171
|
-
function getInt64(view, offset) {
|
|
1172
|
-
const high = view.getInt32(offset);
|
|
1173
|
-
const low = view.getUint32(offset + 4);
|
|
1174
|
-
return high * 4294967296 + low;
|
|
1175
|
-
}
|
|
1176
|
-
function getUint64(view, offset) {
|
|
1177
|
-
const high = view.getUint32(offset);
|
|
1178
|
-
const low = view.getUint32(offset + 4);
|
|
1179
|
-
return high * 4294967296 + low;
|
|
1180
|
-
}
|
|
1200
|
+
return DecodeError;
|
|
1201
|
+
}(Error));
|
|
1181
1202
|
|
|
1182
1203
|
// https://github.com/msgpack/msgpack/blob/master/spec.md#timestamp-extension-type
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
function encodeTimeSpecToTimestamp(
|
|
1204
|
+
var EXT_TIMESTAMP = -1;
|
|
1205
|
+
var TIMESTAMP32_MAX_SEC = 0x100000000 - 1; // 32-bit unsigned int
|
|
1206
|
+
var TIMESTAMP64_MAX_SEC = 0x400000000 - 1; // 34-bit unsigned int
|
|
1207
|
+
function encodeTimeSpecToTimestamp(_a) {
|
|
1208
|
+
var sec = _a.sec, nsec = _a.nsec;
|
|
1187
1209
|
if (sec >= 0 && nsec >= 0 && sec <= TIMESTAMP64_MAX_SEC) {
|
|
1188
1210
|
// Here sec >= 0 && nsec >= 0
|
|
1189
1211
|
if (nsec === 0 && sec <= TIMESTAMP32_MAX_SEC) {
|
|
1190
1212
|
// timestamp 32 = { sec32 (unsigned) }
|
|
1191
|
-
|
|
1192
|
-
|
|
1213
|
+
var rv = new Uint8Array(4);
|
|
1214
|
+
var view = new DataView(rv.buffer);
|
|
1193
1215
|
view.setUint32(0, sec);
|
|
1194
1216
|
return rv;
|
|
1195
1217
|
}
|
|
1196
1218
|
else {
|
|
1197
1219
|
// timestamp 64 = { nsec30 (unsigned), sec34 (unsigned) }
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1220
|
+
var secHigh = sec / 0x100000000;
|
|
1221
|
+
var secLow = sec & 0xffffffff;
|
|
1222
|
+
var rv = new Uint8Array(8);
|
|
1223
|
+
var view = new DataView(rv.buffer);
|
|
1202
1224
|
// nsec30 | secHigh2
|
|
1203
1225
|
view.setUint32(0, (nsec << 2) | (secHigh & 0x3));
|
|
1204
1226
|
// secLow32
|
|
@@ -1208,19 +1230,19 @@ function encodeTimeSpecToTimestamp({ sec, nsec }) {
|
|
|
1208
1230
|
}
|
|
1209
1231
|
else {
|
|
1210
1232
|
// timestamp 96 = { nsec32 (unsigned), sec64 (signed) }
|
|
1211
|
-
|
|
1212
|
-
|
|
1233
|
+
var rv = new Uint8Array(12);
|
|
1234
|
+
var view = new DataView(rv.buffer);
|
|
1213
1235
|
view.setUint32(0, nsec);
|
|
1214
1236
|
setInt64(view, 4, sec);
|
|
1215
1237
|
return rv;
|
|
1216
1238
|
}
|
|
1217
1239
|
}
|
|
1218
1240
|
function encodeDateToTimeSpec(date) {
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1241
|
+
var msec = date.getTime();
|
|
1242
|
+
var sec = Math.floor(msec / 1e3);
|
|
1243
|
+
var nsec = (msec - sec * 1e3) * 1e6;
|
|
1222
1244
|
// Normalizes { sec, nsec } to ensure nsec is unsigned.
|
|
1223
|
-
|
|
1245
|
+
var nsecInSec = Math.floor(nsec / 1e9);
|
|
1224
1246
|
return {
|
|
1225
1247
|
sec: sec + nsecInSec,
|
|
1226
1248
|
nsec: nsec - nsecInSec * 1e9,
|
|
@@ -1228,7 +1250,7 @@ function encodeDateToTimeSpec(date) {
|
|
|
1228
1250
|
}
|
|
1229
1251
|
function encodeTimestampExtension(object) {
|
|
1230
1252
|
if (object instanceof Date) {
|
|
1231
|
-
|
|
1253
|
+
var timeSpec = encodeDateToTimeSpec(object);
|
|
1232
1254
|
return encodeTimeSpecToTimestamp(timeSpec);
|
|
1233
1255
|
}
|
|
1234
1256
|
else {
|
|
@@ -1236,60 +1258,56 @@ function encodeTimestampExtension(object) {
|
|
|
1236
1258
|
}
|
|
1237
1259
|
}
|
|
1238
1260
|
function decodeTimestampToTimeSpec(data) {
|
|
1239
|
-
|
|
1261
|
+
var view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
1240
1262
|
// data may be 32, 64, or 96 bits
|
|
1241
1263
|
switch (data.byteLength) {
|
|
1242
1264
|
case 4: {
|
|
1243
1265
|
// timestamp 32 = { sec32 }
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
return { sec, nsec };
|
|
1266
|
+
var sec = view.getUint32(0);
|
|
1267
|
+
var nsec = 0;
|
|
1268
|
+
return { sec: sec, nsec: nsec };
|
|
1247
1269
|
}
|
|
1248
1270
|
case 8: {
|
|
1249
1271
|
// timestamp 64 = { nsec30, sec34 }
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
return { sec, nsec };
|
|
1272
|
+
var nsec30AndSecHigh2 = view.getUint32(0);
|
|
1273
|
+
var secLow32 = view.getUint32(4);
|
|
1274
|
+
var sec = (nsec30AndSecHigh2 & 0x3) * 0x100000000 + secLow32;
|
|
1275
|
+
var nsec = nsec30AndSecHigh2 >>> 2;
|
|
1276
|
+
return { sec: sec, nsec: nsec };
|
|
1255
1277
|
}
|
|
1256
1278
|
case 12: {
|
|
1257
1279
|
// timestamp 96 = { nsec32 (unsigned), sec64 (signed) }
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
return { sec, nsec };
|
|
1280
|
+
var sec = getInt64(view, 4);
|
|
1281
|
+
var nsec = view.getUint32(0);
|
|
1282
|
+
return { sec: sec, nsec: nsec };
|
|
1261
1283
|
}
|
|
1262
1284
|
default:
|
|
1263
|
-
throw new DecodeError(
|
|
1285
|
+
throw new DecodeError("Unrecognized data size for timestamp (expected 4, 8, or 12): ".concat(data.length));
|
|
1264
1286
|
}
|
|
1265
1287
|
}
|
|
1266
1288
|
function decodeTimestampExtension(data) {
|
|
1267
|
-
|
|
1289
|
+
var timeSpec = decodeTimestampToTimeSpec(data);
|
|
1268
1290
|
return new Date(timeSpec.sec * 1e3 + timeSpec.nsec / 1e6);
|
|
1269
1291
|
}
|
|
1270
|
-
|
|
1292
|
+
var timestampExtension = {
|
|
1271
1293
|
type: EXT_TIMESTAMP,
|
|
1272
1294
|
encode: encodeTimestampExtension,
|
|
1273
1295
|
decode: decodeTimestampExtension,
|
|
1274
1296
|
};
|
|
1275
1297
|
|
|
1276
1298
|
// ExtensionCodec to handle MessagePack extensions
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
builtInDecoders = [];
|
|
1286
|
-
// custom extensions
|
|
1287
|
-
encoders = [];
|
|
1288
|
-
decoders = [];
|
|
1289
|
-
constructor() {
|
|
1299
|
+
var ExtensionCodec = /** @class */ (function () {
|
|
1300
|
+
function ExtensionCodec() {
|
|
1301
|
+
// built-in extensions
|
|
1302
|
+
this.builtInEncoders = [];
|
|
1303
|
+
this.builtInDecoders = [];
|
|
1304
|
+
// custom extensions
|
|
1305
|
+
this.encoders = [];
|
|
1306
|
+
this.decoders = [];
|
|
1290
1307
|
this.register(timestampExtension);
|
|
1291
1308
|
}
|
|
1292
|
-
register
|
|
1309
|
+
ExtensionCodec.prototype.register = function (_a) {
|
|
1310
|
+
var type = _a.type, encode = _a.encode, decode = _a.decode;
|
|
1293
1311
|
if (type >= 0) {
|
|
1294
1312
|
// custom extensions
|
|
1295
1313
|
this.encoders[type] = encode;
|
|
@@ -1297,30 +1315,30 @@ class ExtensionCodec {
|
|
|
1297
1315
|
}
|
|
1298
1316
|
else {
|
|
1299
1317
|
// built-in extensions
|
|
1300
|
-
|
|
1318
|
+
var index = 1 + type;
|
|
1301
1319
|
this.builtInEncoders[index] = encode;
|
|
1302
1320
|
this.builtInDecoders[index] = decode;
|
|
1303
1321
|
}
|
|
1304
|
-
}
|
|
1305
|
-
tryToEncode(object, context) {
|
|
1322
|
+
};
|
|
1323
|
+
ExtensionCodec.prototype.tryToEncode = function (object, context) {
|
|
1306
1324
|
// built-in extensions
|
|
1307
|
-
for (
|
|
1308
|
-
|
|
1325
|
+
for (var i = 0; i < this.builtInEncoders.length; i++) {
|
|
1326
|
+
var encodeExt = this.builtInEncoders[i];
|
|
1309
1327
|
if (encodeExt != null) {
|
|
1310
|
-
|
|
1328
|
+
var data = encodeExt(object, context);
|
|
1311
1329
|
if (data != null) {
|
|
1312
|
-
|
|
1330
|
+
var type = -1 - i;
|
|
1313
1331
|
return new ExtData(type, data);
|
|
1314
1332
|
}
|
|
1315
1333
|
}
|
|
1316
1334
|
}
|
|
1317
1335
|
// custom extensions
|
|
1318
|
-
for (
|
|
1319
|
-
|
|
1336
|
+
for (var i = 0; i < this.encoders.length; i++) {
|
|
1337
|
+
var encodeExt = this.encoders[i];
|
|
1320
1338
|
if (encodeExt != null) {
|
|
1321
|
-
|
|
1339
|
+
var data = encodeExt(object, context);
|
|
1322
1340
|
if (data != null) {
|
|
1323
|
-
|
|
1341
|
+
var type = i;
|
|
1324
1342
|
return new ExtData(type, data);
|
|
1325
1343
|
}
|
|
1326
1344
|
}
|
|
@@ -1330,9 +1348,9 @@ class ExtensionCodec {
|
|
|
1330
1348
|
return object;
|
|
1331
1349
|
}
|
|
1332
1350
|
return null;
|
|
1333
|
-
}
|
|
1334
|
-
decode(data, type, context) {
|
|
1335
|
-
|
|
1351
|
+
};
|
|
1352
|
+
ExtensionCodec.prototype.decode = function (data, type, context) {
|
|
1353
|
+
var decodeExt = type < 0 ? this.builtInDecoders[-1 - type] : this.decoders[type];
|
|
1336
1354
|
if (decodeExt) {
|
|
1337
1355
|
return decodeExt(data, type, context);
|
|
1338
1356
|
}
|
|
@@ -1340,12 +1358,11 @@ class ExtensionCodec {
|
|
|
1340
1358
|
// decode() does not fail, returns ExtData instead.
|
|
1341
1359
|
return new ExtData(type, data);
|
|
1342
1360
|
}
|
|
1343
|
-
}
|
|
1344
|
-
|
|
1361
|
+
};
|
|
1362
|
+
ExtensionCodec.defaultCodec = new ExtensionCodec();
|
|
1363
|
+
return ExtensionCodec;
|
|
1364
|
+
}());
|
|
1345
1365
|
|
|
1346
|
-
function isArrayBufferLike(buffer) {
|
|
1347
|
-
return (buffer instanceof ArrayBuffer || (typeof SharedArrayBuffer !== "undefined" && buffer instanceof SharedArrayBuffer));
|
|
1348
|
-
}
|
|
1349
1366
|
function ensureUint8Array(buffer) {
|
|
1350
1367
|
if (buffer instanceof Uint8Array) {
|
|
1351
1368
|
return buffer;
|
|
@@ -1353,7 +1370,7 @@ function ensureUint8Array(buffer) {
|
|
|
1353
1370
|
else if (ArrayBuffer.isView(buffer)) {
|
|
1354
1371
|
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
1355
1372
|
}
|
|
1356
|
-
else if (
|
|
1373
|
+
else if (buffer instanceof ArrayBuffer) {
|
|
1357
1374
|
return new Uint8Array(buffer);
|
|
1358
1375
|
}
|
|
1359
1376
|
else {
|
|
@@ -1361,37 +1378,44 @@ function ensureUint8Array(buffer) {
|
|
|
1361
1378
|
return Uint8Array.from(buffer);
|
|
1362
1379
|
}
|
|
1363
1380
|
}
|
|
1381
|
+
function createDataView(buffer) {
|
|
1382
|
+
if (buffer instanceof ArrayBuffer) {
|
|
1383
|
+
return new DataView(buffer);
|
|
1384
|
+
}
|
|
1385
|
+
var bufferView = ensureUint8Array(buffer);
|
|
1386
|
+
return new DataView(bufferView.buffer, bufferView.byteOffset, bufferView.byteLength);
|
|
1387
|
+
}
|
|
1364
1388
|
|
|
1365
1389
|
function prettyByte(byte) {
|
|
1366
|
-
return
|
|
1390
|
+
return "".concat(byte < 0 ? "-" : "", "0x").concat(Math.abs(byte).toString(16).padStart(2, "0"));
|
|
1367
1391
|
}
|
|
1368
1392
|
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
maxKeyLength;
|
|
1376
|
-
maxLengthPerKey;
|
|
1377
|
-
constructor(maxKeyLength = DEFAULT_MAX_KEY_LENGTH, maxLengthPerKey = DEFAULT_MAX_LENGTH_PER_KEY) {
|
|
1393
|
+
var DEFAULT_MAX_KEY_LENGTH = 16;
|
|
1394
|
+
var DEFAULT_MAX_LENGTH_PER_KEY = 16;
|
|
1395
|
+
var CachedKeyDecoder = /** @class */ (function () {
|
|
1396
|
+
function CachedKeyDecoder(maxKeyLength, maxLengthPerKey) {
|
|
1397
|
+
if (maxKeyLength === void 0) { maxKeyLength = DEFAULT_MAX_KEY_LENGTH; }
|
|
1398
|
+
if (maxLengthPerKey === void 0) { maxLengthPerKey = DEFAULT_MAX_LENGTH_PER_KEY; }
|
|
1378
1399
|
this.maxKeyLength = maxKeyLength;
|
|
1379
1400
|
this.maxLengthPerKey = maxLengthPerKey;
|
|
1401
|
+
this.hit = 0;
|
|
1402
|
+
this.miss = 0;
|
|
1380
1403
|
// avoid `new Array(N)`, which makes a sparse array,
|
|
1381
1404
|
// because a sparse array is typically slower than a non-sparse array.
|
|
1382
1405
|
this.caches = [];
|
|
1383
|
-
for (
|
|
1406
|
+
for (var i = 0; i < this.maxKeyLength; i++) {
|
|
1384
1407
|
this.caches.push([]);
|
|
1385
1408
|
}
|
|
1386
1409
|
}
|
|
1387
|
-
canBeCached(byteLength) {
|
|
1410
|
+
CachedKeyDecoder.prototype.canBeCached = function (byteLength) {
|
|
1388
1411
|
return byteLength > 0 && byteLength <= this.maxKeyLength;
|
|
1389
|
-
}
|
|
1390
|
-
find(bytes, inputOffset, byteLength) {
|
|
1391
|
-
|
|
1392
|
-
FIND_CHUNK: for (
|
|
1393
|
-
|
|
1394
|
-
|
|
1412
|
+
};
|
|
1413
|
+
CachedKeyDecoder.prototype.find = function (bytes, inputOffset, byteLength) {
|
|
1414
|
+
var records = this.caches[byteLength - 1];
|
|
1415
|
+
FIND_CHUNK: for (var _i = 0, records_1 = records; _i < records_1.length; _i++) {
|
|
1416
|
+
var record = records_1[_i];
|
|
1417
|
+
var recordBytes = record.bytes;
|
|
1418
|
+
for (var j = 0; j < byteLength; j++) {
|
|
1395
1419
|
if (recordBytes[j] !== bytes[inputOffset + j]) {
|
|
1396
1420
|
continue FIND_CHUNK;
|
|
1397
1421
|
}
|
|
@@ -1399,10 +1423,10 @@ class CachedKeyDecoder {
|
|
|
1399
1423
|
return record.str;
|
|
1400
1424
|
}
|
|
1401
1425
|
return null;
|
|
1402
|
-
}
|
|
1403
|
-
store(bytes, value) {
|
|
1404
|
-
|
|
1405
|
-
|
|
1426
|
+
};
|
|
1427
|
+
CachedKeyDecoder.prototype.store = function (bytes, value) {
|
|
1428
|
+
var records = this.caches[bytes.length - 1];
|
|
1429
|
+
var record = { bytes: bytes, str: value };
|
|
1406
1430
|
if (records.length >= this.maxLengthPerKey) {
|
|
1407
1431
|
// `records` are full!
|
|
1408
1432
|
// Set `record` to an arbitrary position.
|
|
@@ -1411,323 +1435,335 @@ class CachedKeyDecoder {
|
|
|
1411
1435
|
else {
|
|
1412
1436
|
records.push(record);
|
|
1413
1437
|
}
|
|
1414
|
-
}
|
|
1415
|
-
decode(bytes, inputOffset, byteLength) {
|
|
1416
|
-
|
|
1438
|
+
};
|
|
1439
|
+
CachedKeyDecoder.prototype.decode = function (bytes, inputOffset, byteLength) {
|
|
1440
|
+
var cachedValue = this.find(bytes, inputOffset, byteLength);
|
|
1417
1441
|
if (cachedValue != null) {
|
|
1418
1442
|
this.hit++;
|
|
1419
1443
|
return cachedValue;
|
|
1420
1444
|
}
|
|
1421
1445
|
this.miss++;
|
|
1422
|
-
|
|
1423
|
-
// Ensure to copy a slice of bytes because the
|
|
1424
|
-
|
|
1446
|
+
var str = utf8DecodeJs(bytes, inputOffset, byteLength);
|
|
1447
|
+
// Ensure to copy a slice of bytes because the byte may be NodeJS Buffer and Buffer#slice() returns a reference to its internal ArrayBuffer.
|
|
1448
|
+
var slicedCopyOfBytes = Uint8Array.prototype.slice.call(bytes, inputOffset, inputOffset + byteLength);
|
|
1425
1449
|
this.store(slicedCopyOfBytes, str);
|
|
1426
1450
|
return str;
|
|
1427
|
-
}
|
|
1428
|
-
|
|
1451
|
+
};
|
|
1452
|
+
return CachedKeyDecoder;
|
|
1453
|
+
}());
|
|
1429
1454
|
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1455
|
+
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
1456
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
1457
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
1458
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
1459
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
1460
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
1461
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1462
|
+
});
|
|
1438
1463
|
};
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
if (this.stackHeadPosition === this.stack.length) {
|
|
1465
|
-
const partialState = {
|
|
1466
|
-
type: undefined,
|
|
1467
|
-
size: 0,
|
|
1468
|
-
array: undefined,
|
|
1469
|
-
position: 0,
|
|
1470
|
-
readCount: 0,
|
|
1471
|
-
map: undefined,
|
|
1472
|
-
key: null,
|
|
1473
|
-
};
|
|
1474
|
-
this.stack.push(partialState);
|
|
1475
|
-
}
|
|
1476
|
-
return this.stack[this.stackHeadPosition];
|
|
1477
|
-
}
|
|
1478
|
-
release(state) {
|
|
1479
|
-
const topStackState = this.stack[this.stackHeadPosition];
|
|
1480
|
-
if (topStackState !== state) {
|
|
1481
|
-
throw new Error("Invalid stack state. Released state is not on top of the stack.");
|
|
1482
|
-
}
|
|
1483
|
-
if (state.type === STATE_ARRAY) {
|
|
1484
|
-
const partialState = state;
|
|
1485
|
-
partialState.size = 0;
|
|
1486
|
-
partialState.array = undefined;
|
|
1487
|
-
partialState.position = 0;
|
|
1488
|
-
partialState.type = undefined;
|
|
1489
|
-
}
|
|
1490
|
-
if (state.type === STATE_MAP_KEY || state.type === STATE_MAP_VALUE) {
|
|
1491
|
-
const partialState = state;
|
|
1492
|
-
partialState.size = 0;
|
|
1493
|
-
partialState.map = undefined;
|
|
1494
|
-
partialState.readCount = 0;
|
|
1495
|
-
partialState.type = undefined;
|
|
1496
|
-
}
|
|
1497
|
-
this.stackHeadPosition--;
|
|
1498
|
-
}
|
|
1499
|
-
reset() {
|
|
1500
|
-
this.stack.length = 0;
|
|
1501
|
-
this.stackHeadPosition = -1;
|
|
1502
|
-
}
|
|
1503
|
-
}
|
|
1504
|
-
const HEAD_BYTE_REQUIRED = -1;
|
|
1505
|
-
const EMPTY_VIEW = new DataView(new ArrayBuffer(0));
|
|
1506
|
-
const EMPTY_BYTES = new Uint8Array(EMPTY_VIEW.buffer);
|
|
1507
|
-
try {
|
|
1508
|
-
// IE11: The spec says it should throw RangeError,
|
|
1509
|
-
// IE11: but in IE11 it throws TypeError.
|
|
1510
|
-
EMPTY_VIEW.getInt8(0);
|
|
1511
|
-
}
|
|
1512
|
-
catch (e) {
|
|
1513
|
-
if (!(e instanceof RangeError)) {
|
|
1514
|
-
throw new Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access");
|
|
1515
|
-
}
|
|
1516
|
-
}
|
|
1517
|
-
const MORE_DATA = new RangeError("Insufficient data");
|
|
1518
|
-
const sharedCachedKeyDecoder = new CachedKeyDecoder();
|
|
1519
|
-
class Decoder {
|
|
1520
|
-
extensionCodec;
|
|
1521
|
-
context;
|
|
1522
|
-
useBigInt64;
|
|
1523
|
-
rawStrings;
|
|
1524
|
-
maxStrLength;
|
|
1525
|
-
maxBinLength;
|
|
1526
|
-
maxArrayLength;
|
|
1527
|
-
maxMapLength;
|
|
1528
|
-
maxExtLength;
|
|
1529
|
-
keyDecoder;
|
|
1530
|
-
mapKeyConverter;
|
|
1531
|
-
totalPos = 0;
|
|
1532
|
-
pos = 0;
|
|
1533
|
-
view = EMPTY_VIEW;
|
|
1534
|
-
bytes = EMPTY_BYTES;
|
|
1535
|
-
headByte = HEAD_BYTE_REQUIRED;
|
|
1536
|
-
stack = new StackPool();
|
|
1537
|
-
entered = false;
|
|
1538
|
-
constructor(options) {
|
|
1539
|
-
this.extensionCodec = options?.extensionCodec ?? ExtensionCodec.defaultCodec;
|
|
1540
|
-
this.context = options?.context; // needs a type assertion because EncoderOptions has no context property when ContextType is undefined
|
|
1541
|
-
this.useBigInt64 = options?.useBigInt64 ?? false;
|
|
1542
|
-
this.rawStrings = options?.rawStrings ?? false;
|
|
1543
|
-
this.maxStrLength = options?.maxStrLength ?? UINT32_MAX;
|
|
1544
|
-
this.maxBinLength = options?.maxBinLength ?? UINT32_MAX;
|
|
1545
|
-
this.maxArrayLength = options?.maxArrayLength ?? UINT32_MAX;
|
|
1546
|
-
this.maxMapLength = options?.maxMapLength ?? UINT32_MAX;
|
|
1547
|
-
this.maxExtLength = options?.maxExtLength ?? UINT32_MAX;
|
|
1548
|
-
this.keyDecoder = options?.keyDecoder !== undefined ? options.keyDecoder : sharedCachedKeyDecoder;
|
|
1549
|
-
this.mapKeyConverter = options?.mapKeyConverter ?? mapKeyConverter;
|
|
1550
|
-
}
|
|
1551
|
-
clone() {
|
|
1552
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
1553
|
-
return new Decoder({
|
|
1554
|
-
extensionCodec: this.extensionCodec,
|
|
1555
|
-
context: this.context,
|
|
1556
|
-
useBigInt64: this.useBigInt64,
|
|
1557
|
-
rawStrings: this.rawStrings,
|
|
1558
|
-
maxStrLength: this.maxStrLength,
|
|
1559
|
-
maxBinLength: this.maxBinLength,
|
|
1560
|
-
maxArrayLength: this.maxArrayLength,
|
|
1561
|
-
maxMapLength: this.maxMapLength,
|
|
1562
|
-
maxExtLength: this.maxExtLength,
|
|
1563
|
-
keyDecoder: this.keyDecoder,
|
|
1564
|
-
});
|
|
1464
|
+
var __generator = (undefined && undefined.__generator) || function (thisArg, body) {
|
|
1465
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
1466
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
1467
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
1468
|
+
function step(op) {
|
|
1469
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
1470
|
+
while (_) try {
|
|
1471
|
+
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;
|
|
1472
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
1473
|
+
switch (op[0]) {
|
|
1474
|
+
case 0: case 1: t = op; break;
|
|
1475
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
1476
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
1477
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
1478
|
+
default:
|
|
1479
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
1480
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
1481
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
1482
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
1483
|
+
if (t[2]) _.ops.pop();
|
|
1484
|
+
_.trys.pop(); continue;
|
|
1485
|
+
}
|
|
1486
|
+
op = body.call(thisArg, _);
|
|
1487
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
1488
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
1565
1489
|
}
|
|
1566
|
-
|
|
1490
|
+
};
|
|
1491
|
+
var __asyncValues = (undefined && undefined.__asyncValues) || function (o) {
|
|
1492
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
1493
|
+
var m = o[Symbol.asyncIterator], i;
|
|
1494
|
+
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);
|
|
1495
|
+
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); }); }; }
|
|
1496
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
1497
|
+
};
|
|
1498
|
+
var __await = (undefined && undefined.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); };
|
|
1499
|
+
var __asyncGenerator = (undefined && undefined.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
1500
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
1501
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
1502
|
+
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
1503
|
+
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); }); }; }
|
|
1504
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
1505
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
1506
|
+
function fulfill(value) { resume("next", value); }
|
|
1507
|
+
function reject(value) { resume("throw", value); }
|
|
1508
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
1509
|
+
};
|
|
1510
|
+
var isValidMapKeyType = function (key) {
|
|
1511
|
+
var keyType = typeof key;
|
|
1512
|
+
return keyType === "string" || keyType === "number";
|
|
1513
|
+
};
|
|
1514
|
+
var HEAD_BYTE_REQUIRED = -1;
|
|
1515
|
+
var EMPTY_VIEW = new DataView(new ArrayBuffer(0));
|
|
1516
|
+
var EMPTY_BYTES = new Uint8Array(EMPTY_VIEW.buffer);
|
|
1517
|
+
// IE11: Hack to support IE11.
|
|
1518
|
+
// IE11: Drop this hack and just use RangeError when IE11 is obsolete.
|
|
1519
|
+
var DataViewIndexOutOfBoundsError = (function () {
|
|
1520
|
+
try {
|
|
1521
|
+
// IE11: The spec says it should throw RangeError,
|
|
1522
|
+
// IE11: but in IE11 it throws TypeError.
|
|
1523
|
+
EMPTY_VIEW.getInt8(0);
|
|
1524
|
+
}
|
|
1525
|
+
catch (e) {
|
|
1526
|
+
return e.constructor;
|
|
1527
|
+
}
|
|
1528
|
+
throw new Error("never reached");
|
|
1529
|
+
})();
|
|
1530
|
+
var MORE_DATA = new DataViewIndexOutOfBoundsError("Insufficient data");
|
|
1531
|
+
var sharedCachedKeyDecoder = new CachedKeyDecoder();
|
|
1532
|
+
var Decoder = /** @class */ (function () {
|
|
1533
|
+
function Decoder(extensionCodec, context, maxStrLength, maxBinLength, maxArrayLength, maxMapLength, maxExtLength, keyDecoder) {
|
|
1534
|
+
if (extensionCodec === void 0) { extensionCodec = ExtensionCodec.defaultCodec; }
|
|
1535
|
+
if (context === void 0) { context = undefined; }
|
|
1536
|
+
if (maxStrLength === void 0) { maxStrLength = UINT32_MAX; }
|
|
1537
|
+
if (maxBinLength === void 0) { maxBinLength = UINT32_MAX; }
|
|
1538
|
+
if (maxArrayLength === void 0) { maxArrayLength = UINT32_MAX; }
|
|
1539
|
+
if (maxMapLength === void 0) { maxMapLength = UINT32_MAX; }
|
|
1540
|
+
if (maxExtLength === void 0) { maxExtLength = UINT32_MAX; }
|
|
1541
|
+
if (keyDecoder === void 0) { keyDecoder = sharedCachedKeyDecoder; }
|
|
1542
|
+
this.extensionCodec = extensionCodec;
|
|
1543
|
+
this.context = context;
|
|
1544
|
+
this.maxStrLength = maxStrLength;
|
|
1545
|
+
this.maxBinLength = maxBinLength;
|
|
1546
|
+
this.maxArrayLength = maxArrayLength;
|
|
1547
|
+
this.maxMapLength = maxMapLength;
|
|
1548
|
+
this.maxExtLength = maxExtLength;
|
|
1549
|
+
this.keyDecoder = keyDecoder;
|
|
1567
1550
|
this.totalPos = 0;
|
|
1551
|
+
this.pos = 0;
|
|
1552
|
+
this.view = EMPTY_VIEW;
|
|
1553
|
+
this.bytes = EMPTY_BYTES;
|
|
1568
1554
|
this.headByte = HEAD_BYTE_REQUIRED;
|
|
1569
|
-
this.stack
|
|
1570
|
-
// view, bytes, and pos will be re-initialized in setBuffer()
|
|
1555
|
+
this.stack = [];
|
|
1571
1556
|
}
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
this.
|
|
1575
|
-
this.
|
|
1557
|
+
Decoder.prototype.reinitializeState = function () {
|
|
1558
|
+
this.totalPos = 0;
|
|
1559
|
+
this.headByte = HEAD_BYTE_REQUIRED;
|
|
1560
|
+
this.stack.length = 0;
|
|
1561
|
+
// view, bytes, and pos will be re-initialized in setBuffer()
|
|
1562
|
+
};
|
|
1563
|
+
Decoder.prototype.setBuffer = function (buffer) {
|
|
1564
|
+
this.bytes = ensureUint8Array(buffer);
|
|
1565
|
+
this.view = createDataView(this.bytes);
|
|
1576
1566
|
this.pos = 0;
|
|
1577
|
-
}
|
|
1578
|
-
appendBuffer(buffer) {
|
|
1567
|
+
};
|
|
1568
|
+
Decoder.prototype.appendBuffer = function (buffer) {
|
|
1579
1569
|
if (this.headByte === HEAD_BYTE_REQUIRED && !this.hasRemaining(1)) {
|
|
1580
1570
|
this.setBuffer(buffer);
|
|
1581
1571
|
}
|
|
1582
1572
|
else {
|
|
1583
|
-
|
|
1584
|
-
|
|
1573
|
+
var remainingData = this.bytes.subarray(this.pos);
|
|
1574
|
+
var newData = ensureUint8Array(buffer);
|
|
1585
1575
|
// concat remainingData + newData
|
|
1586
|
-
|
|
1576
|
+
var newBuffer = new Uint8Array(remainingData.length + newData.length);
|
|
1587
1577
|
newBuffer.set(remainingData);
|
|
1588
1578
|
newBuffer.set(newData, remainingData.length);
|
|
1589
1579
|
this.setBuffer(newBuffer);
|
|
1590
1580
|
}
|
|
1591
|
-
}
|
|
1592
|
-
hasRemaining(size) {
|
|
1581
|
+
};
|
|
1582
|
+
Decoder.prototype.hasRemaining = function (size) {
|
|
1593
1583
|
return this.view.byteLength - this.pos >= size;
|
|
1594
|
-
}
|
|
1595
|
-
createExtraByteError(posToShow) {
|
|
1596
|
-
|
|
1597
|
-
return new RangeError(
|
|
1598
|
-
}
|
|
1584
|
+
};
|
|
1585
|
+
Decoder.prototype.createExtraByteError = function (posToShow) {
|
|
1586
|
+
var _a = this, view = _a.view, pos = _a.pos;
|
|
1587
|
+
return new RangeError("Extra ".concat(view.byteLength - pos, " of ").concat(view.byteLength, " byte(s) found at buffer[").concat(posToShow, "]"));
|
|
1588
|
+
};
|
|
1599
1589
|
/**
|
|
1600
1590
|
* @throws {@link DecodeError}
|
|
1601
1591
|
* @throws {@link RangeError}
|
|
1602
1592
|
*/
|
|
1603
|
-
decode(buffer) {
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
this.entered = true;
|
|
1610
|
-
this.reinitializeState();
|
|
1611
|
-
this.setBuffer(buffer);
|
|
1612
|
-
const object = this.doDecodeSync();
|
|
1613
|
-
if (this.hasRemaining(1)) {
|
|
1614
|
-
throw this.createExtraByteError(this.pos);
|
|
1615
|
-
}
|
|
1616
|
-
return object;
|
|
1617
|
-
}
|
|
1618
|
-
finally {
|
|
1619
|
-
this.entered = false;
|
|
1620
|
-
}
|
|
1621
|
-
}
|
|
1622
|
-
*decodeMulti(buffer) {
|
|
1623
|
-
if (this.entered) {
|
|
1624
|
-
const instance = this.clone();
|
|
1625
|
-
yield* instance.decodeMulti(buffer);
|
|
1626
|
-
return;
|
|
1627
|
-
}
|
|
1628
|
-
try {
|
|
1629
|
-
this.entered = true;
|
|
1630
|
-
this.reinitializeState();
|
|
1631
|
-
this.setBuffer(buffer);
|
|
1632
|
-
while (this.hasRemaining(1)) {
|
|
1633
|
-
yield this.doDecodeSync();
|
|
1634
|
-
}
|
|
1635
|
-
}
|
|
1636
|
-
finally {
|
|
1637
|
-
this.entered = false;
|
|
1593
|
+
Decoder.prototype.decode = function (buffer) {
|
|
1594
|
+
this.reinitializeState();
|
|
1595
|
+
this.setBuffer(buffer);
|
|
1596
|
+
var object = this.doDecodeSync();
|
|
1597
|
+
if (this.hasRemaining(1)) {
|
|
1598
|
+
throw this.createExtraByteError(this.pos);
|
|
1638
1599
|
}
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
try {
|
|
1656
|
-
object = this.doDecodeSync();
|
|
1657
|
-
decoded = true;
|
|
1658
|
-
}
|
|
1659
|
-
catch (e) {
|
|
1660
|
-
if (!(e instanceof RangeError)) {
|
|
1661
|
-
throw e; // rethrow
|
|
1662
|
-
}
|
|
1663
|
-
// fallthrough
|
|
1664
|
-
}
|
|
1665
|
-
this.totalPos += this.pos;
|
|
1600
|
+
return object;
|
|
1601
|
+
};
|
|
1602
|
+
Decoder.prototype.decodeMulti = function (buffer) {
|
|
1603
|
+
return __generator(this, function (_a) {
|
|
1604
|
+
switch (_a.label) {
|
|
1605
|
+
case 0:
|
|
1606
|
+
this.reinitializeState();
|
|
1607
|
+
this.setBuffer(buffer);
|
|
1608
|
+
_a.label = 1;
|
|
1609
|
+
case 1:
|
|
1610
|
+
if (!this.hasRemaining(1)) return [3 /*break*/, 3];
|
|
1611
|
+
return [4 /*yield*/, this.doDecodeSync()];
|
|
1612
|
+
case 2:
|
|
1613
|
+
_a.sent();
|
|
1614
|
+
return [3 /*break*/, 1];
|
|
1615
|
+
case 3: return [2 /*return*/];
|
|
1666
1616
|
}
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1617
|
+
});
|
|
1618
|
+
};
|
|
1619
|
+
Decoder.prototype.decodeAsync = function (stream) {
|
|
1620
|
+
var stream_1, stream_1_1;
|
|
1621
|
+
var e_1, _a;
|
|
1622
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1623
|
+
var decoded, object, buffer, e_1_1, _b, headByte, pos, totalPos;
|
|
1624
|
+
return __generator(this, function (_c) {
|
|
1625
|
+
switch (_c.label) {
|
|
1626
|
+
case 0:
|
|
1627
|
+
decoded = false;
|
|
1628
|
+
_c.label = 1;
|
|
1629
|
+
case 1:
|
|
1630
|
+
_c.trys.push([1, 6, 7, 12]);
|
|
1631
|
+
stream_1 = __asyncValues(stream);
|
|
1632
|
+
_c.label = 2;
|
|
1633
|
+
case 2: return [4 /*yield*/, stream_1.next()];
|
|
1634
|
+
case 3:
|
|
1635
|
+
if (!(stream_1_1 = _c.sent(), !stream_1_1.done)) return [3 /*break*/, 5];
|
|
1636
|
+
buffer = stream_1_1.value;
|
|
1637
|
+
if (decoded) {
|
|
1638
|
+
throw this.createExtraByteError(this.totalPos);
|
|
1639
|
+
}
|
|
1640
|
+
this.appendBuffer(buffer);
|
|
1641
|
+
try {
|
|
1642
|
+
object = this.doDecodeSync();
|
|
1643
|
+
decoded = true;
|
|
1644
|
+
}
|
|
1645
|
+
catch (e) {
|
|
1646
|
+
if (!(e instanceof DataViewIndexOutOfBoundsError)) {
|
|
1647
|
+
throw e; // rethrow
|
|
1648
|
+
}
|
|
1649
|
+
// fallthrough
|
|
1650
|
+
}
|
|
1651
|
+
this.totalPos += this.pos;
|
|
1652
|
+
_c.label = 4;
|
|
1653
|
+
case 4: return [3 /*break*/, 2];
|
|
1654
|
+
case 5: return [3 /*break*/, 12];
|
|
1655
|
+
case 6:
|
|
1656
|
+
e_1_1 = _c.sent();
|
|
1657
|
+
e_1 = { error: e_1_1 };
|
|
1658
|
+
return [3 /*break*/, 12];
|
|
1659
|
+
case 7:
|
|
1660
|
+
_c.trys.push([7, , 10, 11]);
|
|
1661
|
+
if (!(stream_1_1 && !stream_1_1.done && (_a = stream_1.return))) return [3 /*break*/, 9];
|
|
1662
|
+
return [4 /*yield*/, _a.call(stream_1)];
|
|
1663
|
+
case 8:
|
|
1664
|
+
_c.sent();
|
|
1665
|
+
_c.label = 9;
|
|
1666
|
+
case 9: return [3 /*break*/, 11];
|
|
1667
|
+
case 10:
|
|
1668
|
+
if (e_1) throw e_1.error;
|
|
1669
|
+
return [7 /*endfinally*/];
|
|
1670
|
+
case 11: return [7 /*endfinally*/];
|
|
1671
|
+
case 12:
|
|
1672
|
+
if (decoded) {
|
|
1673
|
+
if (this.hasRemaining(1)) {
|
|
1674
|
+
throw this.createExtraByteError(this.totalPos);
|
|
1675
|
+
}
|
|
1676
|
+
return [2 /*return*/, object];
|
|
1677
|
+
}
|
|
1678
|
+
_b = this, headByte = _b.headByte, pos = _b.pos, totalPos = _b.totalPos;
|
|
1679
|
+
throw new RangeError("Insufficient data in parsing ".concat(prettyByte(headByte), " at ").concat(totalPos, " (").concat(pos, " in the current buffer)"));
|
|
1670
1680
|
}
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
}
|
|
1676
|
-
finally {
|
|
1677
|
-
this.entered = false;
|
|
1678
|
-
}
|
|
1679
|
-
}
|
|
1680
|
-
decodeArrayStream(stream) {
|
|
1681
|
+
});
|
|
1682
|
+
});
|
|
1683
|
+
};
|
|
1684
|
+
Decoder.prototype.decodeArrayStream = function (stream) {
|
|
1681
1685
|
return this.decodeMultiAsync(stream, true);
|
|
1682
|
-
}
|
|
1683
|
-
decodeStream(stream) {
|
|
1686
|
+
};
|
|
1687
|
+
Decoder.prototype.decodeStream = function (stream) {
|
|
1684
1688
|
return this.decodeMultiAsync(stream, false);
|
|
1685
|
-
}
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
return
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1689
|
+
};
|
|
1690
|
+
Decoder.prototype.decodeMultiAsync = function (stream, isArray) {
|
|
1691
|
+
return __asyncGenerator(this, arguments, function decodeMultiAsync_1() {
|
|
1692
|
+
var isArrayHeaderRequired, arrayItemsLeft, stream_2, stream_2_1, buffer, e_2, e_3_1;
|
|
1693
|
+
var e_3, _a;
|
|
1694
|
+
return __generator(this, function (_b) {
|
|
1695
|
+
switch (_b.label) {
|
|
1696
|
+
case 0:
|
|
1697
|
+
isArrayHeaderRequired = isArray;
|
|
1698
|
+
arrayItemsLeft = -1;
|
|
1699
|
+
_b.label = 1;
|
|
1700
|
+
case 1:
|
|
1701
|
+
_b.trys.push([1, 13, 14, 19]);
|
|
1702
|
+
stream_2 = __asyncValues(stream);
|
|
1703
|
+
_b.label = 2;
|
|
1704
|
+
case 2: return [4 /*yield*/, __await(stream_2.next())];
|
|
1705
|
+
case 3:
|
|
1706
|
+
if (!(stream_2_1 = _b.sent(), !stream_2_1.done)) return [3 /*break*/, 12];
|
|
1707
|
+
buffer = stream_2_1.value;
|
|
1708
|
+
if (isArray && arrayItemsLeft === 0) {
|
|
1709
|
+
throw this.createExtraByteError(this.totalPos);
|
|
1710
|
+
}
|
|
1711
|
+
this.appendBuffer(buffer);
|
|
1712
|
+
if (isArrayHeaderRequired) {
|
|
1713
|
+
arrayItemsLeft = this.readArraySize();
|
|
1714
|
+
isArrayHeaderRequired = false;
|
|
1715
|
+
this.complete();
|
|
1716
|
+
}
|
|
1717
|
+
_b.label = 4;
|
|
1718
|
+
case 4:
|
|
1719
|
+
_b.trys.push([4, 9, , 10]);
|
|
1720
|
+
_b.label = 5;
|
|
1721
|
+
case 5:
|
|
1722
|
+
return [4 /*yield*/, __await(this.doDecodeSync())];
|
|
1723
|
+
case 6: return [4 /*yield*/, _b.sent()];
|
|
1724
|
+
case 7:
|
|
1725
|
+
_b.sent();
|
|
1709
1726
|
if (--arrayItemsLeft === 0) {
|
|
1710
|
-
break;
|
|
1727
|
+
return [3 /*break*/, 8];
|
|
1711
1728
|
}
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1729
|
+
return [3 /*break*/, 5];
|
|
1730
|
+
case 8: return [3 /*break*/, 10];
|
|
1731
|
+
case 9:
|
|
1732
|
+
e_2 = _b.sent();
|
|
1733
|
+
if (!(e_2 instanceof DataViewIndexOutOfBoundsError)) {
|
|
1734
|
+
throw e_2; // rethrow
|
|
1735
|
+
}
|
|
1736
|
+
return [3 /*break*/, 10];
|
|
1737
|
+
case 10:
|
|
1738
|
+
this.totalPos += this.pos;
|
|
1739
|
+
_b.label = 11;
|
|
1740
|
+
case 11: return [3 /*break*/, 2];
|
|
1741
|
+
case 12: return [3 /*break*/, 19];
|
|
1742
|
+
case 13:
|
|
1743
|
+
e_3_1 = _b.sent();
|
|
1744
|
+
e_3 = { error: e_3_1 };
|
|
1745
|
+
return [3 /*break*/, 19];
|
|
1746
|
+
case 14:
|
|
1747
|
+
_b.trys.push([14, , 17, 18]);
|
|
1748
|
+
if (!(stream_2_1 && !stream_2_1.done && (_a = stream_2.return))) return [3 /*break*/, 16];
|
|
1749
|
+
return [4 /*yield*/, __await(_a.call(stream_2))];
|
|
1750
|
+
case 15:
|
|
1751
|
+
_b.sent();
|
|
1752
|
+
_b.label = 16;
|
|
1753
|
+
case 16: return [3 /*break*/, 18];
|
|
1754
|
+
case 17:
|
|
1755
|
+
if (e_3) throw e_3.error;
|
|
1756
|
+
return [7 /*endfinally*/];
|
|
1757
|
+
case 18: return [7 /*endfinally*/];
|
|
1758
|
+
case 19: return [2 /*return*/];
|
|
1719
1759
|
}
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
this.entered = false;
|
|
1725
|
-
}
|
|
1726
|
-
}
|
|
1727
|
-
doDecodeSync() {
|
|
1760
|
+
});
|
|
1761
|
+
});
|
|
1762
|
+
};
|
|
1763
|
+
Decoder.prototype.doDecodeSync = function () {
|
|
1728
1764
|
DECODE: while (true) {
|
|
1729
|
-
|
|
1730
|
-
|
|
1765
|
+
var headByte = this.readHeadByte();
|
|
1766
|
+
var object = void 0;
|
|
1731
1767
|
if (headByte >= 0xe0) {
|
|
1732
1768
|
// negative fixint (111x xxxx) 0xe0 - 0xff
|
|
1733
1769
|
object = headByte - 0x100;
|
|
@@ -1739,7 +1775,7 @@ class Decoder {
|
|
|
1739
1775
|
}
|
|
1740
1776
|
else if (headByte < 0x90) {
|
|
1741
1777
|
// fixmap (1000 xxxx) 0x80 - 0x8f
|
|
1742
|
-
|
|
1778
|
+
var size = headByte - 0x80;
|
|
1743
1779
|
if (size !== 0) {
|
|
1744
1780
|
this.pushMapState(size);
|
|
1745
1781
|
this.complete();
|
|
@@ -1751,7 +1787,7 @@ class Decoder {
|
|
|
1751
1787
|
}
|
|
1752
1788
|
else if (headByte < 0xa0) {
|
|
1753
1789
|
// fixarray (1001 xxxx) 0x90 - 0x9f
|
|
1754
|
-
|
|
1790
|
+
var size = headByte - 0x90;
|
|
1755
1791
|
if (size !== 0) {
|
|
1756
1792
|
this.pushArrayState(size);
|
|
1757
1793
|
this.complete();
|
|
@@ -1763,8 +1799,8 @@ class Decoder {
|
|
|
1763
1799
|
}
|
|
1764
1800
|
else {
|
|
1765
1801
|
// fixstr (101x xxxx) 0xa0 - 0xbf
|
|
1766
|
-
|
|
1767
|
-
object = this.
|
|
1802
|
+
var byteLength = headByte - 0xa0;
|
|
1803
|
+
object = this.decodeUtf8String(byteLength, 0);
|
|
1768
1804
|
}
|
|
1769
1805
|
}
|
|
1770
1806
|
else if (headByte === 0xc0) {
|
|
@@ -1801,12 +1837,7 @@ class Decoder {
|
|
|
1801
1837
|
}
|
|
1802
1838
|
else if (headByte === 0xcf) {
|
|
1803
1839
|
// uint 64
|
|
1804
|
-
|
|
1805
|
-
object = this.readU64AsBigInt();
|
|
1806
|
-
}
|
|
1807
|
-
else {
|
|
1808
|
-
object = this.readU64();
|
|
1809
|
-
}
|
|
1840
|
+
object = this.readU64();
|
|
1810
1841
|
}
|
|
1811
1842
|
else if (headByte === 0xd0) {
|
|
1812
1843
|
// int 8
|
|
@@ -1822,31 +1853,26 @@ class Decoder {
|
|
|
1822
1853
|
}
|
|
1823
1854
|
else if (headByte === 0xd3) {
|
|
1824
1855
|
// int 64
|
|
1825
|
-
|
|
1826
|
-
object = this.readI64AsBigInt();
|
|
1827
|
-
}
|
|
1828
|
-
else {
|
|
1829
|
-
object = this.readI64();
|
|
1830
|
-
}
|
|
1856
|
+
object = this.readI64();
|
|
1831
1857
|
}
|
|
1832
1858
|
else if (headByte === 0xd9) {
|
|
1833
1859
|
// str 8
|
|
1834
|
-
|
|
1835
|
-
object = this.
|
|
1860
|
+
var byteLength = this.lookU8();
|
|
1861
|
+
object = this.decodeUtf8String(byteLength, 1);
|
|
1836
1862
|
}
|
|
1837
1863
|
else if (headByte === 0xda) {
|
|
1838
1864
|
// str 16
|
|
1839
|
-
|
|
1840
|
-
object = this.
|
|
1865
|
+
var byteLength = this.lookU16();
|
|
1866
|
+
object = this.decodeUtf8String(byteLength, 2);
|
|
1841
1867
|
}
|
|
1842
1868
|
else if (headByte === 0xdb) {
|
|
1843
1869
|
// str 32
|
|
1844
|
-
|
|
1845
|
-
object = this.
|
|
1870
|
+
var byteLength = this.lookU32();
|
|
1871
|
+
object = this.decodeUtf8String(byteLength, 4);
|
|
1846
1872
|
}
|
|
1847
1873
|
else if (headByte === 0xdc) {
|
|
1848
1874
|
// array 16
|
|
1849
|
-
|
|
1875
|
+
var size = this.readU16();
|
|
1850
1876
|
if (size !== 0) {
|
|
1851
1877
|
this.pushArrayState(size);
|
|
1852
1878
|
this.complete();
|
|
@@ -1858,7 +1884,7 @@ class Decoder {
|
|
|
1858
1884
|
}
|
|
1859
1885
|
else if (headByte === 0xdd) {
|
|
1860
1886
|
// array 32
|
|
1861
|
-
|
|
1887
|
+
var size = this.readU32();
|
|
1862
1888
|
if (size !== 0) {
|
|
1863
1889
|
this.pushArrayState(size);
|
|
1864
1890
|
this.complete();
|
|
@@ -1870,7 +1896,7 @@ class Decoder {
|
|
|
1870
1896
|
}
|
|
1871
1897
|
else if (headByte === 0xde) {
|
|
1872
1898
|
// map 16
|
|
1873
|
-
|
|
1899
|
+
var size = this.readU16();
|
|
1874
1900
|
if (size !== 0) {
|
|
1875
1901
|
this.pushMapState(size);
|
|
1876
1902
|
this.complete();
|
|
@@ -1882,7 +1908,7 @@ class Decoder {
|
|
|
1882
1908
|
}
|
|
1883
1909
|
else if (headByte === 0xdf) {
|
|
1884
1910
|
// map 32
|
|
1885
|
-
|
|
1911
|
+
var size = this.readU32();
|
|
1886
1912
|
if (size !== 0) {
|
|
1887
1913
|
this.pushMapState(size);
|
|
1888
1914
|
this.complete();
|
|
@@ -1894,17 +1920,17 @@ class Decoder {
|
|
|
1894
1920
|
}
|
|
1895
1921
|
else if (headByte === 0xc4) {
|
|
1896
1922
|
// bin 8
|
|
1897
|
-
|
|
1923
|
+
var size = this.lookU8();
|
|
1898
1924
|
object = this.decodeBinary(size, 1);
|
|
1899
1925
|
}
|
|
1900
1926
|
else if (headByte === 0xc5) {
|
|
1901
1927
|
// bin 16
|
|
1902
|
-
|
|
1928
|
+
var size = this.lookU16();
|
|
1903
1929
|
object = this.decodeBinary(size, 2);
|
|
1904
1930
|
}
|
|
1905
1931
|
else if (headByte === 0xc6) {
|
|
1906
1932
|
// bin 32
|
|
1907
|
-
|
|
1933
|
+
var size = this.lookU32();
|
|
1908
1934
|
object = this.decodeBinary(size, 4);
|
|
1909
1935
|
}
|
|
1910
1936
|
else if (headByte === 0xd4) {
|
|
@@ -1929,44 +1955,47 @@ class Decoder {
|
|
|
1929
1955
|
}
|
|
1930
1956
|
else if (headByte === 0xc7) {
|
|
1931
1957
|
// ext 8
|
|
1932
|
-
|
|
1958
|
+
var size = this.lookU8();
|
|
1933
1959
|
object = this.decodeExtension(size, 1);
|
|
1934
1960
|
}
|
|
1935
1961
|
else if (headByte === 0xc8) {
|
|
1936
1962
|
// ext 16
|
|
1937
|
-
|
|
1963
|
+
var size = this.lookU16();
|
|
1938
1964
|
object = this.decodeExtension(size, 2);
|
|
1939
1965
|
}
|
|
1940
1966
|
else if (headByte === 0xc9) {
|
|
1941
1967
|
// ext 32
|
|
1942
|
-
|
|
1968
|
+
var size = this.lookU32();
|
|
1943
1969
|
object = this.decodeExtension(size, 4);
|
|
1944
1970
|
}
|
|
1945
1971
|
else {
|
|
1946
|
-
throw new DecodeError(
|
|
1972
|
+
throw new DecodeError("Unrecognized type byte: ".concat(prettyByte(headByte)));
|
|
1947
1973
|
}
|
|
1948
1974
|
this.complete();
|
|
1949
|
-
|
|
1975
|
+
var stack = this.stack;
|
|
1950
1976
|
while (stack.length > 0) {
|
|
1951
1977
|
// arrays and maps
|
|
1952
|
-
|
|
1953
|
-
if (state.type ===
|
|
1978
|
+
var state = stack[stack.length - 1];
|
|
1979
|
+
if (state.type === 0 /* State.ARRAY */) {
|
|
1954
1980
|
state.array[state.position] = object;
|
|
1955
1981
|
state.position++;
|
|
1956
1982
|
if (state.position === state.size) {
|
|
1983
|
+
stack.pop();
|
|
1957
1984
|
object = state.array;
|
|
1958
|
-
stack.release(state);
|
|
1959
1985
|
}
|
|
1960
1986
|
else {
|
|
1961
1987
|
continue DECODE;
|
|
1962
1988
|
}
|
|
1963
1989
|
}
|
|
1964
|
-
else if (state.type ===
|
|
1990
|
+
else if (state.type === 1 /* State.MAP_KEY */) {
|
|
1991
|
+
if (!isValidMapKeyType(object)) {
|
|
1992
|
+
throw new DecodeError("The type of key must be string or number but " + typeof object);
|
|
1993
|
+
}
|
|
1965
1994
|
if (object === "__proto__") {
|
|
1966
1995
|
throw new DecodeError("The key __proto__ is not allowed");
|
|
1967
1996
|
}
|
|
1968
|
-
state.key =
|
|
1969
|
-
state.type =
|
|
1997
|
+
state.key = object;
|
|
1998
|
+
state.type = 2 /* State.MAP_VALUE */;
|
|
1970
1999
|
continue DECODE;
|
|
1971
2000
|
}
|
|
1972
2001
|
else {
|
|
@@ -1974,31 +2003,31 @@ class Decoder {
|
|
|
1974
2003
|
state.map[state.key] = object;
|
|
1975
2004
|
state.readCount++;
|
|
1976
2005
|
if (state.readCount === state.size) {
|
|
2006
|
+
stack.pop();
|
|
1977
2007
|
object = state.map;
|
|
1978
|
-
stack.release(state);
|
|
1979
2008
|
}
|
|
1980
2009
|
else {
|
|
1981
2010
|
state.key = null;
|
|
1982
|
-
state.type =
|
|
2011
|
+
state.type = 1 /* State.MAP_KEY */;
|
|
1983
2012
|
continue DECODE;
|
|
1984
2013
|
}
|
|
1985
2014
|
}
|
|
1986
2015
|
}
|
|
1987
2016
|
return object;
|
|
1988
2017
|
}
|
|
1989
|
-
}
|
|
1990
|
-
readHeadByte() {
|
|
2018
|
+
};
|
|
2019
|
+
Decoder.prototype.readHeadByte = function () {
|
|
1991
2020
|
if (this.headByte === HEAD_BYTE_REQUIRED) {
|
|
1992
2021
|
this.headByte = this.readU8();
|
|
1993
2022
|
// console.log("headByte", prettyByte(this.headByte));
|
|
1994
2023
|
}
|
|
1995
2024
|
return this.headByte;
|
|
1996
|
-
}
|
|
1997
|
-
complete() {
|
|
2025
|
+
};
|
|
2026
|
+
Decoder.prototype.complete = function () {
|
|
1998
2027
|
this.headByte = HEAD_BYTE_REQUIRED;
|
|
1999
|
-
}
|
|
2000
|
-
readArraySize() {
|
|
2001
|
-
|
|
2028
|
+
};
|
|
2029
|
+
Decoder.prototype.readArraySize = function () {
|
|
2030
|
+
var headByte = this.readHeadByte();
|
|
2002
2031
|
switch (headByte) {
|
|
2003
2032
|
case 0xdc:
|
|
2004
2033
|
return this.readU16();
|
|
@@ -2009,162 +2038,158 @@ class Decoder {
|
|
|
2009
2038
|
return headByte - 0x90;
|
|
2010
2039
|
}
|
|
2011
2040
|
else {
|
|
2012
|
-
throw new DecodeError(
|
|
2041
|
+
throw new DecodeError("Unrecognized array type byte: ".concat(prettyByte(headByte)));
|
|
2013
2042
|
}
|
|
2014
2043
|
}
|
|
2015
2044
|
}
|
|
2016
|
-
}
|
|
2017
|
-
pushMapState(size) {
|
|
2045
|
+
};
|
|
2046
|
+
Decoder.prototype.pushMapState = function (size) {
|
|
2018
2047
|
if (size > this.maxMapLength) {
|
|
2019
|
-
throw new DecodeError(
|
|
2020
|
-
}
|
|
2021
|
-
this.stack.
|
|
2022
|
-
|
|
2023
|
-
|
|
2048
|
+
throw new DecodeError("Max length exceeded: map length (".concat(size, ") > maxMapLengthLength (").concat(this.maxMapLength, ")"));
|
|
2049
|
+
}
|
|
2050
|
+
this.stack.push({
|
|
2051
|
+
type: 1 /* State.MAP_KEY */,
|
|
2052
|
+
size: size,
|
|
2053
|
+
key: null,
|
|
2054
|
+
readCount: 0,
|
|
2055
|
+
map: {},
|
|
2056
|
+
});
|
|
2057
|
+
};
|
|
2058
|
+
Decoder.prototype.pushArrayState = function (size) {
|
|
2024
2059
|
if (size > this.maxArrayLength) {
|
|
2025
|
-
throw new DecodeError(
|
|
2026
|
-
}
|
|
2027
|
-
this.stack.pushArrayState(size);
|
|
2028
|
-
}
|
|
2029
|
-
decodeString(byteLength, headerOffset) {
|
|
2030
|
-
if (!this.rawStrings || this.stateIsMapKey()) {
|
|
2031
|
-
return this.decodeUtf8String(byteLength, headerOffset);
|
|
2060
|
+
throw new DecodeError("Max length exceeded: array length (".concat(size, ") > maxArrayLength (").concat(this.maxArrayLength, ")"));
|
|
2032
2061
|
}
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2062
|
+
this.stack.push({
|
|
2063
|
+
type: 0 /* State.ARRAY */,
|
|
2064
|
+
size: size,
|
|
2065
|
+
array: new Array(size),
|
|
2066
|
+
position: 0,
|
|
2067
|
+
});
|
|
2068
|
+
};
|
|
2069
|
+
Decoder.prototype.decodeUtf8String = function (byteLength, headerOffset) {
|
|
2070
|
+
var _a;
|
|
2039
2071
|
if (byteLength > this.maxStrLength) {
|
|
2040
|
-
throw new DecodeError(
|
|
2072
|
+
throw new DecodeError("Max length exceeded: UTF-8 byte length (".concat(byteLength, ") > maxStrLength (").concat(this.maxStrLength, ")"));
|
|
2041
2073
|
}
|
|
2042
2074
|
if (this.bytes.byteLength < this.pos + headerOffset + byteLength) {
|
|
2043
2075
|
throw MORE_DATA;
|
|
2044
2076
|
}
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
if (this.stateIsMapKey() && this.keyDecoder
|
|
2077
|
+
var offset = this.pos + headerOffset;
|
|
2078
|
+
var object;
|
|
2079
|
+
if (this.stateIsMapKey() && ((_a = this.keyDecoder) === null || _a === void 0 ? void 0 : _a.canBeCached(byteLength))) {
|
|
2048
2080
|
object = this.keyDecoder.decode(this.bytes, offset, byteLength);
|
|
2049
2081
|
}
|
|
2082
|
+
else if (byteLength > TEXT_DECODER_THRESHOLD) {
|
|
2083
|
+
object = utf8DecodeTD(this.bytes, offset, byteLength);
|
|
2084
|
+
}
|
|
2050
2085
|
else {
|
|
2051
|
-
object =
|
|
2086
|
+
object = utf8DecodeJs(this.bytes, offset, byteLength);
|
|
2052
2087
|
}
|
|
2053
2088
|
this.pos += headerOffset + byteLength;
|
|
2054
2089
|
return object;
|
|
2055
|
-
}
|
|
2056
|
-
stateIsMapKey() {
|
|
2090
|
+
};
|
|
2091
|
+
Decoder.prototype.stateIsMapKey = function () {
|
|
2057
2092
|
if (this.stack.length > 0) {
|
|
2058
|
-
|
|
2059
|
-
return state.type ===
|
|
2093
|
+
var state = this.stack[this.stack.length - 1];
|
|
2094
|
+
return state.type === 1 /* State.MAP_KEY */;
|
|
2060
2095
|
}
|
|
2061
2096
|
return false;
|
|
2062
|
-
}
|
|
2063
|
-
|
|
2064
|
-
* @throws {@link RangeError}
|
|
2065
|
-
*/
|
|
2066
|
-
decodeBinary(byteLength, headOffset) {
|
|
2097
|
+
};
|
|
2098
|
+
Decoder.prototype.decodeBinary = function (byteLength, headOffset) {
|
|
2067
2099
|
if (byteLength > this.maxBinLength) {
|
|
2068
|
-
throw new DecodeError(
|
|
2100
|
+
throw new DecodeError("Max length exceeded: bin length (".concat(byteLength, ") > maxBinLength (").concat(this.maxBinLength, ")"));
|
|
2069
2101
|
}
|
|
2070
2102
|
if (!this.hasRemaining(byteLength + headOffset)) {
|
|
2071
2103
|
throw MORE_DATA;
|
|
2072
2104
|
}
|
|
2073
|
-
|
|
2074
|
-
|
|
2105
|
+
var offset = this.pos + headOffset;
|
|
2106
|
+
var object = this.bytes.subarray(offset, offset + byteLength);
|
|
2075
2107
|
this.pos += headOffset + byteLength;
|
|
2076
2108
|
return object;
|
|
2077
|
-
}
|
|
2078
|
-
decodeExtension(size, headOffset) {
|
|
2109
|
+
};
|
|
2110
|
+
Decoder.prototype.decodeExtension = function (size, headOffset) {
|
|
2079
2111
|
if (size > this.maxExtLength) {
|
|
2080
|
-
throw new DecodeError(
|
|
2112
|
+
throw new DecodeError("Max length exceeded: ext length (".concat(size, ") > maxExtLength (").concat(this.maxExtLength, ")"));
|
|
2081
2113
|
}
|
|
2082
|
-
|
|
2083
|
-
|
|
2114
|
+
var extType = this.view.getInt8(this.pos + headOffset);
|
|
2115
|
+
var data = this.decodeBinary(size, headOffset + 1 /* extType */);
|
|
2084
2116
|
return this.extensionCodec.decode(data, extType, this.context);
|
|
2085
|
-
}
|
|
2086
|
-
lookU8() {
|
|
2117
|
+
};
|
|
2118
|
+
Decoder.prototype.lookU8 = function () {
|
|
2087
2119
|
return this.view.getUint8(this.pos);
|
|
2088
|
-
}
|
|
2089
|
-
lookU16() {
|
|
2120
|
+
};
|
|
2121
|
+
Decoder.prototype.lookU16 = function () {
|
|
2090
2122
|
return this.view.getUint16(this.pos);
|
|
2091
|
-
}
|
|
2092
|
-
lookU32() {
|
|
2123
|
+
};
|
|
2124
|
+
Decoder.prototype.lookU32 = function () {
|
|
2093
2125
|
return this.view.getUint32(this.pos);
|
|
2094
|
-
}
|
|
2095
|
-
readU8() {
|
|
2096
|
-
|
|
2126
|
+
};
|
|
2127
|
+
Decoder.prototype.readU8 = function () {
|
|
2128
|
+
var value = this.view.getUint8(this.pos);
|
|
2097
2129
|
this.pos++;
|
|
2098
2130
|
return value;
|
|
2099
|
-
}
|
|
2100
|
-
readI8() {
|
|
2101
|
-
|
|
2131
|
+
};
|
|
2132
|
+
Decoder.prototype.readI8 = function () {
|
|
2133
|
+
var value = this.view.getInt8(this.pos);
|
|
2102
2134
|
this.pos++;
|
|
2103
2135
|
return value;
|
|
2104
|
-
}
|
|
2105
|
-
readU16() {
|
|
2106
|
-
|
|
2136
|
+
};
|
|
2137
|
+
Decoder.prototype.readU16 = function () {
|
|
2138
|
+
var value = this.view.getUint16(this.pos);
|
|
2107
2139
|
this.pos += 2;
|
|
2108
2140
|
return value;
|
|
2109
|
-
}
|
|
2110
|
-
readI16() {
|
|
2111
|
-
|
|
2141
|
+
};
|
|
2142
|
+
Decoder.prototype.readI16 = function () {
|
|
2143
|
+
var value = this.view.getInt16(this.pos);
|
|
2112
2144
|
this.pos += 2;
|
|
2113
2145
|
return value;
|
|
2114
|
-
}
|
|
2115
|
-
readU32() {
|
|
2116
|
-
|
|
2146
|
+
};
|
|
2147
|
+
Decoder.prototype.readU32 = function () {
|
|
2148
|
+
var value = this.view.getUint32(this.pos);
|
|
2117
2149
|
this.pos += 4;
|
|
2118
2150
|
return value;
|
|
2119
|
-
}
|
|
2120
|
-
readI32() {
|
|
2121
|
-
|
|
2151
|
+
};
|
|
2152
|
+
Decoder.prototype.readI32 = function () {
|
|
2153
|
+
var value = this.view.getInt32(this.pos);
|
|
2122
2154
|
this.pos += 4;
|
|
2123
2155
|
return value;
|
|
2124
|
-
}
|
|
2125
|
-
readU64() {
|
|
2126
|
-
|
|
2127
|
-
this.pos += 8;
|
|
2128
|
-
return value;
|
|
2129
|
-
}
|
|
2130
|
-
readI64() {
|
|
2131
|
-
const value = getInt64(this.view, this.pos);
|
|
2132
|
-
this.pos += 8;
|
|
2133
|
-
return value;
|
|
2134
|
-
}
|
|
2135
|
-
readU64AsBigInt() {
|
|
2136
|
-
const value = this.view.getBigUint64(this.pos);
|
|
2156
|
+
};
|
|
2157
|
+
Decoder.prototype.readU64 = function () {
|
|
2158
|
+
var value = getUint64(this.view, this.pos);
|
|
2137
2159
|
this.pos += 8;
|
|
2138
2160
|
return value;
|
|
2139
|
-
}
|
|
2140
|
-
|
|
2141
|
-
|
|
2161
|
+
};
|
|
2162
|
+
Decoder.prototype.readI64 = function () {
|
|
2163
|
+
var value = getInt64(this.view, this.pos);
|
|
2142
2164
|
this.pos += 8;
|
|
2143
2165
|
return value;
|
|
2144
|
-
}
|
|
2145
|
-
readF32() {
|
|
2146
|
-
|
|
2166
|
+
};
|
|
2167
|
+
Decoder.prototype.readF32 = function () {
|
|
2168
|
+
var value = this.view.getFloat32(this.pos);
|
|
2147
2169
|
this.pos += 4;
|
|
2148
2170
|
return value;
|
|
2149
|
-
}
|
|
2150
|
-
readF64() {
|
|
2151
|
-
|
|
2171
|
+
};
|
|
2172
|
+
Decoder.prototype.readF64 = function () {
|
|
2173
|
+
var value = this.view.getFloat64(this.pos);
|
|
2152
2174
|
this.pos += 8;
|
|
2153
2175
|
return value;
|
|
2154
|
-
}
|
|
2155
|
-
|
|
2176
|
+
};
|
|
2177
|
+
return Decoder;
|
|
2178
|
+
}());
|
|
2156
2179
|
|
|
2180
|
+
var defaultDecodeOptions = {};
|
|
2157
2181
|
/**
|
|
2158
2182
|
* It decodes a single MessagePack object in a buffer.
|
|
2159
2183
|
*
|
|
2160
2184
|
* This is a synchronous decoding function.
|
|
2161
|
-
* See other variants for asynchronous decoding: {@link decodeAsync}, {@link
|
|
2185
|
+
* See other variants for asynchronous decoding: {@link decodeAsync()}, {@link decodeStream()}, or {@link decodeArrayStream()}.
|
|
2162
2186
|
*
|
|
2163
2187
|
* @throws {@link RangeError} if the buffer is incomplete, including the case where the buffer is empty.
|
|
2164
2188
|
* @throws {@link DecodeError} if the buffer contains invalid data.
|
|
2165
2189
|
*/
|
|
2166
2190
|
function decode(buffer, options) {
|
|
2167
|
-
|
|
2191
|
+
if (options === void 0) { options = defaultDecodeOptions; }
|
|
2192
|
+
var decoder = new Decoder(options.extensionCodec, options.context, options.maxStrLength, options.maxBinLength, options.maxArrayLength, options.maxMapLength, options.maxExtLength);
|
|
2168
2193
|
return decoder.decode(buffer);
|
|
2169
2194
|
}
|
|
2170
2195
|
|
|
@@ -2230,10 +2255,10 @@ function decodeBase64Url(value) {
|
|
|
2230
2255
|
/**
|
|
2231
2256
|
* 截图并唤起分享。
|
|
2232
2257
|
*
|
|
2233
|
-
* @param requester 底层 bridge 请求能力。
|
|
2234
|
-
* @param options 截图区域、延迟与保存相册等配置。
|
|
2258
|
+
* @param requester - 底层 bridge 请求能力。
|
|
2259
|
+
* @param options - 截图区域、延迟与保存相册等配置。
|
|
2235
2260
|
* @returns 由宿主客户端协议决定的结果。
|
|
2236
|
-
* @throws {HbMiniProgramSDKError} 当 bridge、父容器或宿主能力调用失败时抛出。
|
|
2261
|
+
* @throws {@link HbMiniProgramSDKError} 当 bridge、父容器或宿主能力调用失败时抛出。
|
|
2237
2262
|
*/
|
|
2238
2263
|
function screenshot(requester, options) {
|
|
2239
2264
|
return requester.request(SHARE_SCREENSHOT_METHOD, options);
|
|
@@ -2242,10 +2267,10 @@ function screenshot(requester, options) {
|
|
|
2242
2267
|
/**
|
|
2243
2268
|
* 展示基础分享面板。
|
|
2244
2269
|
*
|
|
2245
|
-
* @param requester 底层 bridge 请求能力。
|
|
2246
|
-
* @param options 基础分享参数。
|
|
2270
|
+
* @param requester - 底层 bridge 请求能力。
|
|
2271
|
+
* @param options - 基础分享参数。
|
|
2247
2272
|
* @returns 由宿主客户端协议决定的结果。
|
|
2248
|
-
* @throws {HbMiniProgramSDKError} 当 bridge、父容器或宿主能力调用失败时抛出。
|
|
2273
|
+
* @throws {@link HbMiniProgramSDKError} 当 bridge、父容器或宿主能力调用失败时抛出。
|
|
2249
2274
|
*/
|
|
2250
2275
|
function showShareMenu(requester, options) {
|
|
2251
2276
|
return requester.request(SHARE_SHOW_SHARE_MENU_METHOD, options);
|
|
@@ -2254,25 +2279,25 @@ function showShareMenu(requester, options) {
|
|
|
2254
2279
|
/**
|
|
2255
2280
|
* 创建分享模块。
|
|
2256
2281
|
*
|
|
2257
|
-
* @param requester 底层 bridge 请求能力。
|
|
2282
|
+
* @param requester - 底层 bridge 请求能力。
|
|
2258
2283
|
* @returns 面向业务层的分享模块对象。
|
|
2259
2284
|
*/
|
|
2260
2285
|
function createShareModule(requester, launchHref) {
|
|
2261
2286
|
return {
|
|
2262
|
-
copyLink: options => copyLink(requester, options),
|
|
2287
|
+
copyLink: (options) => copyLink(requester, options),
|
|
2263
2288
|
getExtra: () => readMiniProgramShareExtra(launchHref),
|
|
2264
|
-
showShareMenu: options => showShareMenu(requester, options),
|
|
2265
|
-
screenshot: options => screenshot(requester, options),
|
|
2289
|
+
showShareMenu: (options) => showShareMenu(requester, options),
|
|
2290
|
+
screenshot: (options) => screenshot(requester, options),
|
|
2266
2291
|
};
|
|
2267
2292
|
}
|
|
2268
2293
|
|
|
2269
2294
|
/**
|
|
2270
2295
|
* 获取小程序隔离 storage。
|
|
2271
2296
|
*
|
|
2272
|
-
* @param requester 底层 bridge 请求能力。
|
|
2273
|
-
* @param options 读取的 storage key。
|
|
2297
|
+
* @param requester - 底层 bridge 请求能力。
|
|
2298
|
+
* @param options - 读取的 storage key。
|
|
2274
2299
|
* @returns 对应 key 的标准化读取结果。
|
|
2275
|
-
* @throws {HbMiniProgramSDKError} 当 bridge、父容器或宿主能力调用失败时抛出。
|
|
2300
|
+
* @throws {@link HbMiniProgramSDKError} 当 bridge、父容器或宿主能力调用失败时抛出。
|
|
2276
2301
|
*/
|
|
2277
2302
|
function getStorage(requester, options) {
|
|
2278
2303
|
return requester.request(STORAGE_GET_STORAGE_METHOD, options);
|
|
@@ -2280,10 +2305,10 @@ function getStorage(requester, options) {
|
|
|
2280
2305
|
/**
|
|
2281
2306
|
* 写入小程序隔离 storage。
|
|
2282
2307
|
*
|
|
2283
|
-
* @param requester 底层 bridge 请求能力。
|
|
2284
|
-
* @param options 要写入的 storage key 与数据。
|
|
2308
|
+
* @param requester - 底层 bridge 请求能力。
|
|
2309
|
+
* @param options - 要写入的 storage key 与数据。
|
|
2285
2310
|
* @returns 当写入完成后 resolve。
|
|
2286
|
-
* @throws {HbMiniProgramSDKError} 当 bridge、父容器或宿主能力调用失败时抛出。
|
|
2311
|
+
* @throws {@link HbMiniProgramSDKError} 当 bridge、父容器或宿主能力调用失败时抛出。
|
|
2287
2312
|
*/
|
|
2288
2313
|
function setStorage(requester, options) {
|
|
2289
2314
|
return requester.request(STORAGE_SET_STORAGE_METHOD, options);
|
|
@@ -2291,13 +2316,13 @@ function setStorage(requester, options) {
|
|
|
2291
2316
|
/**
|
|
2292
2317
|
* 创建 storage 模块。
|
|
2293
2318
|
*
|
|
2294
|
-
* @param requester 底层 bridge 请求能力。
|
|
2319
|
+
* @param requester - 底层 bridge 请求能力。
|
|
2295
2320
|
* @returns 面向业务层的 storage 模块对象。
|
|
2296
2321
|
*/
|
|
2297
2322
|
function createStorageModule(requester) {
|
|
2298
2323
|
return {
|
|
2299
|
-
getStorage: options => getStorage(requester, options),
|
|
2300
|
-
setStorage: options => setStorage(requester, options),
|
|
2324
|
+
getStorage: (options) => getStorage(requester, options),
|
|
2325
|
+
setStorage: (options) => setStorage(requester, options),
|
|
2301
2326
|
};
|
|
2302
2327
|
}
|
|
2303
2328
|
|
|
@@ -2372,13 +2397,13 @@ function formatNetworkRequestFailureMessage(detail) {
|
|
|
2372
2397
|
return `${detail.kind} ${detail.method} ${detail.url}${statusPart}${codePart}`;
|
|
2373
2398
|
}
|
|
2374
2399
|
|
|
2375
|
-
const DEFAULT_VALIDATE_STATUS = status => status >= 200 && status < 300;
|
|
2400
|
+
const DEFAULT_VALIDATE_STATUS = (status) => status >= 200 && status < 300;
|
|
2376
2401
|
function isPlainObject(value) {
|
|
2377
2402
|
return Object.prototype.toString.call(value) === '[object Object]';
|
|
2378
2403
|
}
|
|
2379
2404
|
function clonePublicValue(value) {
|
|
2380
2405
|
if (Array.isArray(value)) {
|
|
2381
|
-
return value.map(item => clonePublicValue(item));
|
|
2406
|
+
return value.map((item) => clonePublicValue(item));
|
|
2382
2407
|
}
|
|
2383
2408
|
if (isPlainObject(value)) {
|
|
2384
2409
|
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, clonePublicValue(item)]));
|
|
@@ -2432,11 +2457,11 @@ function toNetworkResponse(payload, config) {
|
|
|
2432
2457
|
/**
|
|
2433
2458
|
* 发起网络请求并返回标准化响应。
|
|
2434
2459
|
*
|
|
2435
|
-
* @param requester 底层 bridge 请求能力。
|
|
2436
|
-
* @param config 面向业务层的网络请求配置。
|
|
2460
|
+
* @param requester - 底层 bridge 请求能力。
|
|
2461
|
+
* @param config - 面向业务层的网络请求配置。
|
|
2437
2462
|
* @returns 标准化网络响应。HTTP 2xx 默认返回 resolve。
|
|
2438
|
-
* @throws {HbMiniProgramNetworkError} 当请求已完成但 HTTP 状态不满足 `validateStatus` 时抛出。
|
|
2439
|
-
* @throws {HbMiniProgramSDKError} 当 bridge、运行时或宿主能力调用失败时抛出。
|
|
2463
|
+
* @throws {@link HbMiniProgramNetworkError} 当请求已完成但 HTTP 状态不满足 `validateStatus` 时抛出。
|
|
2464
|
+
* @throws {@link HbMiniProgramSDKError} 当 bridge、运行时或宿主能力调用失败时抛出。
|
|
2440
2465
|
*
|
|
2441
2466
|
* @remarks
|
|
2442
2467
|
* `validateStatus` 仅在 SDK 侧执行,不会跨 bridge 传输函数值。
|
|
@@ -2454,7 +2479,7 @@ async function request(requester, config) {
|
|
|
2454
2479
|
const validateStatus = config.validateStatus || DEFAULT_VALIDATE_STATUS;
|
|
2455
2480
|
try {
|
|
2456
2481
|
assertSupportedPublicNetworkRequest(config);
|
|
2457
|
-
const responsePayload = await requester.request(NETWORK_REQUEST_METHOD, toRequestPayload(config));
|
|
2482
|
+
const responsePayload = (await requester.request(NETWORK_REQUEST_METHOD, toRequestPayload(config)));
|
|
2458
2483
|
const response = toNetworkResponse(responsePayload, config);
|
|
2459
2484
|
if (!validateStatus(response.status)) {
|
|
2460
2485
|
const error = new HbMiniProgramNetworkError(response);
|
|
@@ -2506,21 +2531,21 @@ function assertSupportedPublicNetworkRequest(config) {
|
|
|
2506
2531
|
/**
|
|
2507
2532
|
* 创建 network 模块。
|
|
2508
2533
|
*
|
|
2509
|
-
* @param requester 底层 bridge 请求能力。
|
|
2534
|
+
* @param requester - 底层 bridge 请求能力。
|
|
2510
2535
|
* @returns 面向业务层的网络模块对象。
|
|
2511
2536
|
*/
|
|
2512
2537
|
function createNetworkModule(requester) {
|
|
2513
2538
|
return {
|
|
2514
|
-
request: config => request(requester, config),
|
|
2539
|
+
request: (config) => request(requester, config),
|
|
2515
2540
|
};
|
|
2516
2541
|
}
|
|
2517
2542
|
|
|
2518
2543
|
/**
|
|
2519
2544
|
* 获取当前小程序窗口信息。
|
|
2520
2545
|
*
|
|
2521
|
-
* @param requester 底层 bridge 请求能力。
|
|
2546
|
+
* @param requester - 底层 bridge 请求能力。
|
|
2522
2547
|
* @returns 当前小程序可用窗口信息。
|
|
2523
|
-
* @throws {HbMiniProgramSDKError} 当 bridge、父容器或宿主能力调用失败时抛出。
|
|
2548
|
+
* @throws {@link HbMiniProgramSDKError} 当 bridge、父容器或宿主能力调用失败时抛出。
|
|
2524
2549
|
*/
|
|
2525
2550
|
function getWindowInfo(requester) {
|
|
2526
2551
|
return requester.request(VIEWPORT_GET_WINDOW_INFO_METHOD);
|
|
@@ -2528,10 +2553,10 @@ function getWindowInfo(requester) {
|
|
|
2528
2553
|
/**
|
|
2529
2554
|
* 设置导航栏关闭按钮与状态栏图标/文字的前景样式。
|
|
2530
2555
|
*
|
|
2531
|
-
* @param requester 底层 bridge 请求能力。
|
|
2532
|
-
* @param options 导航栏样式配置。
|
|
2556
|
+
* @param requester - 底层 bridge 请求能力。
|
|
2557
|
+
* @param options - 导航栏样式配置。
|
|
2533
2558
|
* @returns 宿主接受设置后 resolve。
|
|
2534
|
-
* @throws {HbMiniProgramSDKError} 当 bridge、父容器或宿主能力调用失败时抛出。
|
|
2559
|
+
* @throws {@link HbMiniProgramSDKError} 当 bridge、父容器或宿主能力调用失败时抛出。
|
|
2535
2560
|
*/
|
|
2536
2561
|
function setNavigationBarStyle(requester, options) {
|
|
2537
2562
|
return requester.request(VIEWPORT_SET_NAVIGATION_BAR_STYLE_METHOD, options);
|
|
@@ -2539,13 +2564,13 @@ function setNavigationBarStyle(requester, options) {
|
|
|
2539
2564
|
/**
|
|
2540
2565
|
* 创建 Viewport 模块。
|
|
2541
2566
|
*
|
|
2542
|
-
* @param requester 底层 bridge 请求能力。
|
|
2567
|
+
* @param requester - 底层 bridge 请求能力。
|
|
2543
2568
|
* @returns 面向业务层的 Viewport 模块对象。
|
|
2544
2569
|
*/
|
|
2545
2570
|
function createViewportModule(requester) {
|
|
2546
2571
|
return {
|
|
2547
2572
|
getWindowInfo: () => getWindowInfo(requester),
|
|
2548
|
-
setNavigationBarStyle: options => setNavigationBarStyle(requester, options),
|
|
2573
|
+
setNavigationBarStyle: (options) => setNavigationBarStyle(requester, options),
|
|
2549
2574
|
};
|
|
2550
2575
|
}
|
|
2551
2576
|
|
|
@@ -2558,7 +2583,7 @@ function createViewportModule(requester) {
|
|
|
2558
2583
|
* `app_user_id`,并隐式授予 `identity` 与 `profile` 后返回昵称与头像,不展示授权 UI。未登录时返回
|
|
2559
2584
|
* `{ isHeyboxAppLoggedIn: false, authorization: null, userInfo: null }`。
|
|
2560
2585
|
*
|
|
2561
|
-
* @throws {HbMiniProgramSDKError} 当 SDK 调用失败时抛出。
|
|
2586
|
+
* @throws {@link HbMiniProgramSDKError} 当 SDK 调用失败时抛出。
|
|
2562
2587
|
*/
|
|
2563
2588
|
function getInfo(requester) {
|
|
2564
2589
|
return requester.request(USER_GET_INFO_METHOD);
|
|
@@ -2571,8 +2596,8 @@ function revokeAuthorization(requester) {
|
|
|
2571
2596
|
/**
|
|
2572
2597
|
* 获取当前用户 Steam 游戏库。
|
|
2573
2598
|
*
|
|
2574
|
-
* @param requester 底层 bridge 请求能力。
|
|
2575
|
-
* @param options 查询与分页参数。
|
|
2599
|
+
* @param requester - 底层 bridge 请求能力。
|
|
2600
|
+
* @param options - 查询与分页参数。
|
|
2576
2601
|
* @returns 当前用户 Steam 游戏库;未登录或未绑定 Steam 时返回状态对象。
|
|
2577
2602
|
*/
|
|
2578
2603
|
function getSteamGameList(requester, options) {
|
|
@@ -2602,8 +2627,8 @@ function hideLoading(requester) {
|
|
|
2602
2627
|
/** 创建 UI 模块。 */
|
|
2603
2628
|
function createUiModule(requester) {
|
|
2604
2629
|
return {
|
|
2605
|
-
showToast: options => showToast(requester, options),
|
|
2606
|
-
showLoading: options => showLoading(requester, options),
|
|
2630
|
+
showToast: (options) => showToast(requester, options),
|
|
2631
|
+
showLoading: (options) => showLoading(requester, options),
|
|
2607
2632
|
hideLoading: () => hideLoading(requester),
|
|
2608
2633
|
};
|
|
2609
2634
|
}
|
|
@@ -2619,8 +2644,8 @@ function setClipboard(requester, options) {
|
|
|
2619
2644
|
/** 创建设备能力模块。 */
|
|
2620
2645
|
function createDeviceModule(requester) {
|
|
2621
2646
|
return {
|
|
2622
|
-
vibrate: options => vibrate(requester, options),
|
|
2623
|
-
setClipboard: options => setClipboard(requester, options),
|
|
2647
|
+
vibrate: (options) => vibrate(requester, options),
|
|
2648
|
+
setClipboard: (options) => setClipboard(requester, options),
|
|
2624
2649
|
};
|
|
2625
2650
|
}
|
|
2626
2651
|
|
|
@@ -2731,7 +2756,7 @@ function createNavigationModule(requester) {
|
|
|
2731
2756
|
return {
|
|
2732
2757
|
close: () => close(requester),
|
|
2733
2758
|
reload: () => reload(requester),
|
|
2734
|
-
openAppPage: options => openAppPage(requester, options),
|
|
2759
|
+
openAppPage: (options) => openAppPage(requester, options),
|
|
2735
2760
|
};
|
|
2736
2761
|
}
|
|
2737
2762
|
|
|
@@ -2794,8 +2819,8 @@ class MiniProgramSDK {
|
|
|
2794
2819
|
/**
|
|
2795
2820
|
* 注册小程序生命周期或业务事件。
|
|
2796
2821
|
*
|
|
2797
|
-
* @param eventName 要监听的事件名。
|
|
2798
|
-
* @param handler 事件处理函数。
|
|
2822
|
+
* @param eventName - 要监听的事件名。
|
|
2823
|
+
* @param handler - 事件处理函数。
|
|
2799
2824
|
* @returns 事件解绑函数。
|
|
2800
2825
|
*/
|
|
2801
2826
|
on(eventName, handler) {
|
|
@@ -2804,8 +2829,8 @@ class MiniProgramSDK {
|
|
|
2804
2829
|
/**
|
|
2805
2830
|
* 移除小程序生命周期或业务事件。
|
|
2806
2831
|
*
|
|
2807
|
-
* @param eventName 要移除的事件名。
|
|
2808
|
-
* @param handler 对应的事件处理函数。
|
|
2832
|
+
* @param eventName - 要移除的事件名。
|
|
2833
|
+
* @param handler - 对应的事件处理函数。
|
|
2809
2834
|
*/
|
|
2810
2835
|
off(eventName, handler) {
|
|
2811
2836
|
this.client.off(eventName, handler);
|
|
@@ -2824,7 +2849,7 @@ class MiniProgramSDK {
|
|
|
2824
2849
|
/**
|
|
2825
2850
|
* 创建独立 SDK 实例。
|
|
2826
2851
|
*
|
|
2827
|
-
* @param options SDK 运行配置,例如超时时间、nonce 或测试环境注入的 window。
|
|
2852
|
+
* @param options - SDK 运行配置,例如超时时间、nonce 或测试环境注入的 window。
|
|
2828
2853
|
* @returns 可独立管理生命周期的 `MiniProgramSDK` 实例。
|
|
2829
2854
|
*
|
|
2830
2855
|
* @remarks
|
|
@@ -2850,20 +2875,59 @@ function getDefaultSDK() {
|
|
|
2850
2875
|
}
|
|
2851
2876
|
return defaultSDK;
|
|
2852
2877
|
}
|
|
2853
|
-
/**
|
|
2878
|
+
/**
|
|
2879
|
+
* 获取默认 SDK 实例的当前握手状态。
|
|
2880
|
+
*
|
|
2881
|
+
* @since 0.7.0-alpha.9
|
|
2882
|
+
* @hbPlatform android
|
|
2883
|
+
* @hbPlatform ios
|
|
2884
|
+
* @hbPlatform ohos
|
|
2885
|
+
* @hbPlatform windows
|
|
2886
|
+
* @hbPlatform macos
|
|
2887
|
+
* @hbClient android none
|
|
2888
|
+
* @hbClient ios none
|
|
2889
|
+
* @hbClient ohos none
|
|
2890
|
+
* @hbClient windows none
|
|
2891
|
+
* @hbClient macos none
|
|
2892
|
+
*/
|
|
2854
2893
|
function getHandshakeState() {
|
|
2855
2894
|
return getDefaultSDK().getHandshakeState();
|
|
2856
2895
|
}
|
|
2857
|
-
/**
|
|
2896
|
+
/**
|
|
2897
|
+
* 订阅默认 SDK 实例的握手状态,并立即接收当前状态。
|
|
2898
|
+
*
|
|
2899
|
+
* @since 0.7.0-alpha.9
|
|
2900
|
+
* @hbPlatform android
|
|
2901
|
+
* @hbPlatform ios
|
|
2902
|
+
* @hbPlatform ohos
|
|
2903
|
+
* @hbPlatform windows
|
|
2904
|
+
* @hbPlatform macos
|
|
2905
|
+
* @hbClient android none
|
|
2906
|
+
* @hbClient ios none
|
|
2907
|
+
* @hbClient ohos none
|
|
2908
|
+
* @hbClient windows none
|
|
2909
|
+
* @hbClient macos none
|
|
2910
|
+
*/
|
|
2858
2911
|
function onHandshakeStateChange(handler) {
|
|
2859
2912
|
return getDefaultSDK().onHandshakeStateChange(handler);
|
|
2860
2913
|
}
|
|
2861
2914
|
/**
|
|
2862
2915
|
* 注册默认 SDK 实例的事件监听。
|
|
2863
2916
|
*
|
|
2864
|
-
* @param eventName 要监听的事件名。
|
|
2865
|
-
* @param handler 事件处理函数。
|
|
2917
|
+
* @param eventName - 要监听的事件名。
|
|
2918
|
+
* @param handler - 事件处理函数。
|
|
2866
2919
|
* @returns 事件解绑函数。
|
|
2920
|
+
* @since 0.2.0-alpha.0
|
|
2921
|
+
* @hbPlatform android
|
|
2922
|
+
* @hbPlatform ios
|
|
2923
|
+
* @hbPlatform ohos
|
|
2924
|
+
* @hbPlatform windows
|
|
2925
|
+
* @hbPlatform macos
|
|
2926
|
+
* @hbClient android none
|
|
2927
|
+
* @hbClient ios none
|
|
2928
|
+
* @hbClient ohos none
|
|
2929
|
+
* @hbClient windows none
|
|
2930
|
+
* @hbClient macos none
|
|
2867
2931
|
*/
|
|
2868
2932
|
function on(eventName, handler) {
|
|
2869
2933
|
return getDefaultSDK().on(eventName, handler);
|
|
@@ -2871,9 +2935,20 @@ function on(eventName, handler) {
|
|
|
2871
2935
|
/**
|
|
2872
2936
|
* 移除默认 SDK 实例的事件监听。
|
|
2873
2937
|
*
|
|
2874
|
-
* @param eventName 要移除的事件名。
|
|
2875
|
-
* @param handler 对应的事件处理函数。
|
|
2938
|
+
* @param eventName - 要移除的事件名。
|
|
2939
|
+
* @param handler - 对应的事件处理函数。
|
|
2876
2940
|
* @returns 无返回值。
|
|
2941
|
+
* @since 0.2.0-alpha.0
|
|
2942
|
+
* @hbPlatform android
|
|
2943
|
+
* @hbPlatform ios
|
|
2944
|
+
* @hbPlatform ohos
|
|
2945
|
+
* @hbPlatform windows
|
|
2946
|
+
* @hbPlatform macos
|
|
2947
|
+
* @hbClient android none
|
|
2948
|
+
* @hbClient ios none
|
|
2949
|
+
* @hbClient ohos none
|
|
2950
|
+
* @hbClient windows none
|
|
2951
|
+
* @hbClient macos none
|
|
2877
2952
|
*/
|
|
2878
2953
|
function off(eventName, handler) {
|
|
2879
2954
|
getDefaultSDK().off(eventName, handler);
|