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