@wevu/api 0.2.9 → 0.2.10
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/dist/index.mjs +21 -9
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -98,7 +98,7 @@ function detectGlobalAdapter() {
|
|
|
98
98
|
}
|
|
99
99
|
return {};
|
|
100
100
|
}
|
|
101
|
-
const WEAPI_NON_PROMISIFIED_METHOD_NAME_SET = new Set([
|
|
101
|
+
const WEAPI_NON_PROMISIFIED_METHOD_NAME_SET = /* @__PURE__ */ new Set([
|
|
102
102
|
"arrayBufferToBase64",
|
|
103
103
|
"base64ToArrayBuffer",
|
|
104
104
|
"canIUse",
|
|
@@ -2210,13 +2210,13 @@ function resolveMethodMappingWithMeta(platform, methodName, options = {}) {
|
|
|
2210
2210
|
}
|
|
2211
2211
|
//#endregion
|
|
2212
2212
|
//#region src/core/networkRequestPolicy/types.ts
|
|
2213
|
-
const NETWORK_METHODS = new Set([
|
|
2213
|
+
const NETWORK_METHODS = /* @__PURE__ */ new Set([
|
|
2214
2214
|
"request",
|
|
2215
2215
|
"uploadFile",
|
|
2216
2216
|
"downloadFile",
|
|
2217
2217
|
"connectSocket"
|
|
2218
2218
|
]);
|
|
2219
|
-
const HTTP_METHODS = new Set([
|
|
2219
|
+
const HTTP_METHODS = /* @__PURE__ */ new Set([
|
|
2220
2220
|
"request",
|
|
2221
2221
|
"uploadFile",
|
|
2222
2222
|
"downloadFile"
|
|
@@ -2467,7 +2467,7 @@ function createNetworkRequestPolicy(getPlatform, options = void 0) {
|
|
|
2467
2467
|
}
|
|
2468
2468
|
//#endregion
|
|
2469
2469
|
//#region src/core/createWeapi.ts
|
|
2470
|
-
const INTERNAL_KEYS = new Set([
|
|
2470
|
+
const INTERNAL_KEYS = /* @__PURE__ */ new Set([
|
|
2471
2471
|
"setAdapter",
|
|
2472
2472
|
"getAdapter",
|
|
2473
2473
|
"platform",
|
|
@@ -2476,6 +2476,7 @@ const INTERNAL_KEYS = new Set([
|
|
|
2476
2476
|
"supports"
|
|
2477
2477
|
]);
|
|
2478
2478
|
const PLATFORM_ALIASES = { kuaishou: "ks" };
|
|
2479
|
+
const WECHAT_FILE_SYSTEM_MANAGER_METHODS = /* @__PURE__ */ new Set(["saveFile", "removeSavedFile"]);
|
|
2479
2480
|
function normalizePlatformName(value) {
|
|
2480
2481
|
const normalized = normalizeMiniProgramPlatform(value);
|
|
2481
2482
|
if (!normalized) return;
|
|
@@ -2514,12 +2515,23 @@ function createWeapi(options = {}) {
|
|
|
2514
2515
|
if (!platformName) resolveAdapter();
|
|
2515
2516
|
return platformName;
|
|
2516
2517
|
};
|
|
2518
|
+
const resolveRuntimeMethod = (runtimeAdapter, platform, methodName) => {
|
|
2519
|
+
if (!runtimeAdapter) return;
|
|
2520
|
+
if (platform === "wx" && WECHAT_FILE_SYSTEM_MANAGER_METHODS.has(methodName)) {
|
|
2521
|
+
const getFileSystemManager = runtimeAdapter.getFileSystemManager;
|
|
2522
|
+
if (typeof getFileSystemManager !== "function") return;
|
|
2523
|
+
const fileSystemManager = getFileSystemManager.call(runtimeAdapter);
|
|
2524
|
+
const fileSystemMethod = fileSystemManager?.[methodName];
|
|
2525
|
+
return typeof fileSystemMethod === "function" ? fileSystemMethod.bind(fileSystemManager) : void 0;
|
|
2526
|
+
}
|
|
2527
|
+
return runtimeAdapter[methodName];
|
|
2528
|
+
};
|
|
2517
2529
|
const resolveTarget = (methodName) => {
|
|
2518
2530
|
const runtimeAdapter = resolveAdapter();
|
|
2519
2531
|
const platform = getPlatform();
|
|
2520
2532
|
const mappingInfo = resolveMethodMappingWithMeta(platform, methodName, { allowFallback });
|
|
2521
2533
|
const target = mappingInfo?.target ?? methodName;
|
|
2522
|
-
const supported = typeof (runtimeAdapter
|
|
2534
|
+
const supported = typeof resolveRuntimeMethod(runtimeAdapter, platform, target) === "function";
|
|
2523
2535
|
const supportLevel = !supported ? "unsupported" : mappingInfo?.source === "fallback" ? "fallback" : mappingInfo?.source === "explicit" ? "mapped" : "native";
|
|
2524
2536
|
return {
|
|
2525
2537
|
method: methodName,
|
|
@@ -2554,7 +2566,7 @@ function createWeapi(options = {}) {
|
|
|
2554
2566
|
return (...args) => callMissingApi(prop, getPlatform(), args);
|
|
2555
2567
|
}
|
|
2556
2568
|
const platform = getPlatform();
|
|
2557
|
-
const value = currentAdapter
|
|
2569
|
+
const value = resolveRuntimeMethod(currentAdapter, platform, (typeof prop === "string" ? resolveMethodMappingWithMeta(platform, prop, { allowFallback }) : void 0)?.target ?? prop);
|
|
2558
2570
|
if (typeof value !== "function") {
|
|
2559
2571
|
if (value === void 0 && typeof prop === "string") {
|
|
2560
2572
|
const missing = (...args) => callMissingApi(prop, getPlatform(), args);
|
|
@@ -2566,10 +2578,10 @@ function createWeapi(options = {}) {
|
|
|
2566
2578
|
}
|
|
2567
2579
|
const wrapped = (...args) => {
|
|
2568
2580
|
const runtimeAdapter = resolveAdapter();
|
|
2569
|
-
const
|
|
2581
|
+
const platform = getPlatform();
|
|
2582
|
+
const mappingInfo = resolveMethodMappingWithMeta(platform, prop, { allowFallback });
|
|
2570
2583
|
const mappingRule = mappingInfo?.rule;
|
|
2571
|
-
const
|
|
2572
|
-
const runtimeMethod = runtimeAdapter ? runtimeAdapter[methodName] : void 0;
|
|
2584
|
+
const runtimeMethod = resolveRuntimeMethod(runtimeAdapter, platform, mappingInfo?.target ?? prop);
|
|
2573
2585
|
let runtimeArgs = args;
|
|
2574
2586
|
try {
|
|
2575
2587
|
runtimeArgs = mappingRule?.mapArgs ? mappingRule.mapArgs(args) : args;
|