@wevu/api 0.2.7 → 0.2.8

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.
Files changed (2) hide show
  1. package/dist/index.mjs +32 -36
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -153,6 +153,9 @@ function isNonPromisifiedMethod(name) {
153
153
  function isPlainObject(value) {
154
154
  return Object.prototype.toString.call(value) === "[object Object]";
155
155
  }
156
+ function hasOwn(source, key) {
157
+ return Object.prototype.hasOwnProperty.call(source, key);
158
+ }
156
159
  function hasCallbacks(value) {
157
160
  if (!isPlainObject(value)) return false;
158
161
  return typeof value.success === "function" || typeof value.fail === "function" || typeof value.complete === "function";
@@ -175,7 +178,7 @@ function createNotSupportedError(methodName, platform) {
175
178
  //#region src/core/callBridge.ts
176
179
  function resolveOptionsArg$1(args) {
177
180
  const nextArgs = args.slice();
178
- const lastArg = nextArgs.length > 0 ? nextArgs.at(-1) : void 0;
181
+ const lastArg = nextArgs.length > 0 ? nextArgs[nextArgs.length - 1] : void 0;
179
182
  if (isPlainObject(lastArg)) {
180
183
  const options = { ...lastArg };
181
184
  nextArgs[nextArgs.length - 1] = options;
@@ -195,7 +198,7 @@ function resolveOptionsArg$1(args) {
195
198
  * @description 将错误按小程序回调风格分发;若无回调则返回 reject Promise。
196
199
  */
197
200
  function callWithError(error, args) {
198
- const lastArg = args.length > 0 ? args.at(-1) : void 0;
201
+ const lastArg = args.length > 0 ? args[args.length - 1] : void 0;
199
202
  if (hasCallbacks(lastArg)) {
200
203
  lastArg.fail?.(error);
201
204
  lastArg.complete?.(error);
@@ -1339,7 +1342,7 @@ function mapSaveFileArgs(args) {
1339
1342
  const lastArg = nextArgs[lastIndex];
1340
1343
  if (!isPlainObject(lastArg)) return nextArgs;
1341
1344
  const nextOptions = { ...lastArg };
1342
- if (!Object.hasOwn(nextOptions, "apFilePath") && Object.hasOwn(nextOptions, "tempFilePath")) nextOptions.apFilePath = nextOptions.tempFilePath;
1345
+ if (!hasOwn(nextOptions, "apFilePath") && hasOwn(nextOptions, "tempFilePath")) nextOptions.apFilePath = nextOptions.tempFilePath;
1343
1346
  nextArgs[lastIndex] = nextOptions;
1344
1347
  return nextArgs;
1345
1348
  }
@@ -1349,15 +1352,15 @@ function mapCreateRewardedVideoAdArgs(args) {
1349
1352
  const lastIndex = nextArgs.length - 1;
1350
1353
  const lastArg = nextArgs[lastIndex];
1351
1354
  if (!isPlainObject(lastArg)) return nextArgs;
1352
- if (Object.hasOwn(lastArg, "multiton") && lastArg.multiton === true) throw createNotSupportedError("createRewardedVideoAd", "my");
1353
- if (Object.hasOwn(lastArg, "disableFallbackSharePage") && lastArg.disableFallbackSharePage === true) throw createNotSupportedError("createRewardedVideoAd", "my");
1355
+ if (hasOwn(lastArg, "multiton") && lastArg.multiton === true) throw createNotSupportedError("createRewardedVideoAd", "my");
1356
+ if (hasOwn(lastArg, "disableFallbackSharePage") && lastArg.disableFallbackSharePage === true) throw createNotSupportedError("createRewardedVideoAd", "my");
1354
1357
  const adUnitId = lastArg.adUnitId;
1355
1358
  if (typeof adUnitId === "string" && adUnitId.length > 0) nextArgs[lastIndex] = adUnitId;
1356
1359
  return nextArgs;
1357
1360
  }
1358
1361
  function mapRewardedAdInstance(result, args = []) {
1359
1362
  if (typeof result !== "object" || result === null) return result;
1360
- const adUnitIdArg = args.length > 0 ? args.at(-1) : void 0;
1363
+ const adUnitIdArg = args.length > 0 ? args[args.length - 1] : void 0;
1361
1364
  const adUnitId = typeof adUnitIdArg === "string" ? adUnitIdArg : void 0;
1362
1365
  if (!adUnitId) return result;
1363
1366
  const rewardedAd = result;
@@ -1389,7 +1392,7 @@ function mapCheckIsSoterEnrolledInDeviceArgs(args) {
1389
1392
  }
1390
1393
  function mapSoterCheckResult(methodName, result) {
1391
1394
  if (!isPlainObject(result)) return result;
1392
- if (Object.hasOwn(result, "errMsg")) return result;
1395
+ if (hasOwn(result, "errMsg")) return result;
1393
1396
  return {
1394
1397
  ...result,
1395
1398
  errMsg: `${methodName}:ok`
@@ -1405,11 +1408,11 @@ function toNumberCode(value) {
1405
1408
  function mapBleConnectionResult(methodName, codeKey, result) {
1406
1409
  if (!isPlainObject(result)) return result;
1407
1410
  const nextResult = { ...result };
1408
- if (!Object.hasOwn(nextResult, "errCode")) {
1411
+ if (!hasOwn(nextResult, "errCode")) {
1409
1412
  const code = toNumberCode(nextResult[codeKey]);
1410
1413
  if (typeof code === "number") nextResult.errCode = code;
1411
1414
  }
1412
- if (!Object.hasOwn(nextResult, "errMsg")) {
1415
+ if (!hasOwn(nextResult, "errMsg")) {
1413
1416
  if (typeof nextResult.errorMessage === "string" && nextResult.errorMessage.length > 0) nextResult.errMsg = nextResult.errorMessage;
1414
1417
  else if (nextResult.errCode === 0) nextResult.errMsg = `${methodName}:ok`;
1415
1418
  }
@@ -1423,7 +1426,7 @@ function mapCloseBleConnectionResult(result) {
1423
1426
  }
1424
1427
  function mapSaveFileResult(result) {
1425
1428
  if (!isPlainObject(result)) return result;
1426
- if (!Object.hasOwn(result, "savedFilePath") && Object.hasOwn(result, "apFilePath")) return {
1429
+ if (!hasOwn(result, "savedFilePath") && hasOwn(result, "apFilePath")) return {
1427
1430
  ...result,
1428
1431
  savedFilePath: result.apFilePath
1429
1432
  };
@@ -1431,7 +1434,7 @@ function mapSaveFileResult(result) {
1431
1434
  }
1432
1435
  function mapDouyinSaveFileResult(result) {
1433
1436
  if (!isPlainObject(result)) return result;
1434
- if (!Object.hasOwn(result, "savedFilePath") && Object.hasOwn(result, "filePath")) return {
1437
+ if (!hasOwn(result, "savedFilePath") && hasOwn(result, "filePath")) return {
1435
1438
  ...result,
1436
1439
  savedFilePath: result.filePath
1437
1440
  };
@@ -1458,8 +1461,8 @@ function mapToastArgs(args) {
1458
1461
  const lastArg = nextArgs[lastIndex];
1459
1462
  if (!isPlainObject(lastArg)) return nextArgs;
1460
1463
  const nextOptions = { ...lastArg };
1461
- if (!Object.hasOwn(nextOptions, "content") && Object.hasOwn(nextOptions, "title")) nextOptions.content = nextOptions.title;
1462
- if (Object.hasOwn(nextOptions, "icon")) nextOptions.type = mapToastType(nextOptions.icon);
1464
+ if (!hasOwn(nextOptions, "content") && hasOwn(nextOptions, "title")) nextOptions.content = nextOptions.title;
1465
+ if (hasOwn(nextOptions, "icon")) nextOptions.type = mapToastType(nextOptions.icon);
1463
1466
  nextArgs[lastIndex] = nextOptions;
1464
1467
  return nextArgs;
1465
1468
  }
@@ -1481,7 +1484,7 @@ function mapLoadingArgs(args) {
1481
1484
  const lastArg = nextArgs[lastIndex];
1482
1485
  if (!isPlainObject(lastArg)) return nextArgs;
1483
1486
  const nextOptions = { ...lastArg };
1484
- if (!Object.hasOwn(nextOptions, "content") && Object.hasOwn(nextOptions, "title")) nextOptions.content = nextOptions.title;
1487
+ if (!hasOwn(nextOptions, "content") && hasOwn(nextOptions, "title")) nextOptions.content = nextOptions.title;
1485
1488
  nextArgs[lastIndex] = nextOptions;
1486
1489
  return nextArgs;
1487
1490
  }
@@ -1492,13 +1495,13 @@ function mapActionSheetArgs(args) {
1492
1495
  const lastArg = nextArgs[lastIndex];
1493
1496
  if (!isPlainObject(lastArg)) return nextArgs;
1494
1497
  const nextOptions = { ...lastArg };
1495
- if (!Object.hasOwn(nextOptions, "items") && Array.isArray(nextOptions.itemList)) nextOptions.items = nextOptions.itemList;
1498
+ if (!hasOwn(nextOptions, "items") && Array.isArray(nextOptions.itemList)) nextOptions.items = nextOptions.itemList;
1496
1499
  nextArgs[lastIndex] = nextOptions;
1497
1500
  return nextArgs;
1498
1501
  }
1499
1502
  function mapActionSheetResult(result) {
1500
1503
  if (!isPlainObject(result)) return result;
1501
- if (!Object.hasOwn(result, "tapIndex") && Object.hasOwn(result, "index")) return {
1504
+ if (!hasOwn(result, "tapIndex") && hasOwn(result, "index")) return {
1502
1505
  ...result,
1503
1506
  tapIndex: result.index
1504
1507
  };
@@ -1511,11 +1514,11 @@ function mapModalArgs(args) {
1511
1514
  const lastArg = nextArgs[lastIndex];
1512
1515
  if (!isPlainObject(lastArg)) return nextArgs;
1513
1516
  const nextOptions = { ...lastArg };
1514
- if (Object.hasOwn(nextOptions, "showCancel") && nextOptions.showCancel === false) throw createNotSupportedError("showModal", "my");
1515
- if (Object.hasOwn(nextOptions, "editable") && nextOptions.editable === true) throw createNotSupportedError("showModal", "my");
1516
- if (Object.hasOwn(nextOptions, "placeholderText")) throw createNotSupportedError("showModal", "my");
1517
- if (!Object.hasOwn(nextOptions, "confirmButtonText") && Object.hasOwn(nextOptions, "confirmText")) nextOptions.confirmButtonText = nextOptions.confirmText;
1518
- if (!Object.hasOwn(nextOptions, "cancelButtonText") && Object.hasOwn(nextOptions, "cancelText")) nextOptions.cancelButtonText = nextOptions.cancelText;
1517
+ if (hasOwn(nextOptions, "showCancel") && nextOptions.showCancel === false) throw createNotSupportedError("showModal", "my");
1518
+ if (hasOwn(nextOptions, "editable") && nextOptions.editable === true) throw createNotSupportedError("showModal", "my");
1519
+ if (hasOwn(nextOptions, "placeholderText")) throw createNotSupportedError("showModal", "my");
1520
+ if (!hasOwn(nextOptions, "confirmButtonText") && hasOwn(nextOptions, "confirmText")) nextOptions.confirmButtonText = nextOptions.confirmText;
1521
+ if (!hasOwn(nextOptions, "cancelButtonText") && hasOwn(nextOptions, "cancelText")) nextOptions.cancelButtonText = nextOptions.cancelText;
1519
1522
  nextArgs[lastIndex] = nextOptions;
1520
1523
  return nextArgs;
1521
1524
  }
@@ -1523,11 +1526,11 @@ function mapModalResult(result) {
1523
1526
  if (!isPlainObject(result)) return result;
1524
1527
  let changed = false;
1525
1528
  const nextResult = { ...result };
1526
- if (!Object.hasOwn(nextResult, "cancel") && Object.hasOwn(nextResult, "confirm")) {
1529
+ if (!hasOwn(nextResult, "cancel") && hasOwn(nextResult, "confirm")) {
1527
1530
  nextResult.cancel = !nextResult.confirm;
1528
1531
  changed = true;
1529
1532
  }
1530
- if (!Object.hasOwn(nextResult, "content")) {
1533
+ if (!hasOwn(nextResult, "content")) {
1531
1534
  nextResult.content = "";
1532
1535
  changed = true;
1533
1536
  }
@@ -1535,7 +1538,7 @@ function mapModalResult(result) {
1535
1538
  }
1536
1539
  function mapChooseImageResult(result) {
1537
1540
  if (!isPlainObject(result)) return result;
1538
- if (!Object.hasOwn(result, "tempFilePaths") && Array.isArray(result.apFilePaths)) return {
1541
+ if (!hasOwn(result, "tempFilePaths") && Array.isArray(result.apFilePaths)) return {
1539
1542
  ...result,
1540
1543
  tempFilePaths: result.apFilePaths
1541
1544
  };
@@ -1571,13 +1574,13 @@ function mapSetClipboardArgs(args) {
1571
1574
  const lastArg = nextArgs[lastIndex];
1572
1575
  if (!isPlainObject(lastArg)) return nextArgs;
1573
1576
  const nextOptions = { ...lastArg };
1574
- if (!Object.hasOwn(nextOptions, "text") && Object.hasOwn(nextOptions, "data")) nextOptions.text = nextOptions.data;
1577
+ if (!hasOwn(nextOptions, "text") && hasOwn(nextOptions, "data")) nextOptions.text = nextOptions.data;
1575
1578
  nextArgs[lastIndex] = nextOptions;
1576
1579
  return nextArgs;
1577
1580
  }
1578
1581
  function mapClipboardResult(result) {
1579
1582
  if (!isPlainObject(result)) return result;
1580
- if (!Object.hasOwn(result, "data") && Object.hasOwn(result, "text")) return {
1583
+ if (!hasOwn(result, "data") && hasOwn(result, "text")) return {
1581
1584
  ...result,
1582
1585
  data: result.text
1583
1586
  };
@@ -2175,7 +2178,6 @@ const PLATFORM_METHOD_SET = {
2175
2178
  my: new Set(WEAPI_ALIPAY_METHODS),
2176
2179
  tt: new Set(WEAPI_DOUYIN_METHODS)
2177
2180
  };
2178
- function createFallbackMappingRule(platform, methodName) {}
2179
2181
  function resolveMappingRule(platform, methodName, options = {}) {
2180
2182
  const methodSet = PLATFORM_METHOD_SET[platform];
2181
2183
  const explicitRule = METHOD_MAPPINGS[platform]?.[methodName];
@@ -2192,12 +2194,6 @@ function resolveMappingRule(platform, methodName, options = {}) {
2192
2194
  target: methodName,
2193
2195
  source: "identity"
2194
2196
  };
2195
- const fallbackRule = createFallbackMappingRule(platform, methodName);
2196
- if (fallbackRule) return {
2197
- target: fallbackRule.target,
2198
- source: "fallback",
2199
- rule: fallbackRule
2200
- };
2201
2197
  return {
2202
2198
  target: methodName,
2203
2199
  source: "identity"
@@ -2276,7 +2272,7 @@ function clearTimer(timer) {
2276
2272
  }
2277
2273
  function resolveOptionsArg(args) {
2278
2274
  const nextArgs = args.slice();
2279
- const lastArg = nextArgs.length > 0 ? nextArgs.at(-1) : void 0;
2275
+ const lastArg = nextArgs.length > 0 ? nextArgs[nextArgs.length - 1] : void 0;
2280
2276
  if (isPlainObject(lastArg)) {
2281
2277
  const options = { ...lastArg };
2282
2278
  nextArgs[nextArgs.length - 1] = options;
@@ -2578,7 +2574,7 @@ function createWeapi(options = {}) {
2578
2574
  try {
2579
2575
  runtimeArgs = mappingRule?.mapArgs ? mappingRule.mapArgs(args) : args;
2580
2576
  } catch (error) {
2581
- const lastArg = args.length > 0 ? args.at(-1) : void 0;
2577
+ const lastArg = args.length > 0 ? args[args.length - 1] : void 0;
2582
2578
  if (hasCallbacks(lastArg)) {
2583
2579
  lastArg.fail?.(error);
2584
2580
  lastArg.complete?.(error);
@@ -2591,7 +2587,7 @@ function createWeapi(options = {}) {
2591
2587
  const result = runtimeMethod.apply(runtimeAdapter, runtimeArgs);
2592
2588
  return mappingRule?.mapResult ? mappingRule.mapResult(result, runtimeArgs) : result;
2593
2589
  }
2594
- const lastArg = runtimeArgs.length > 0 ? runtimeArgs.at(-1) : void 0;
2590
+ const lastArg = runtimeArgs.length > 0 ? runtimeArgs[runtimeArgs.length - 1] : void 0;
2595
2591
  if (hasCallbacks(lastArg)) {
2596
2592
  if (mappingRule?.mapResult && isPlainObject(lastArg)) {
2597
2593
  const options = lastArg;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wevu/api",
3
3
  "type": "module",
4
- "version": "0.2.7",
4
+ "version": "0.2.8",
5
5
  "description": "tsdown bundler template",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",