@wevu/api 0.2.2 → 0.2.4

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 CHANGED
@@ -1,37 +1,18 @@
1
+ import { getMiniProgramPlatformByRuntimeGlobalKey, getMiniProgramRuntimeGlobalKey, getMiniProgramRuntimeGlobalKeys, getMiniProgramRuntimeHostConfigKey, normalizeMiniProgramPlatform, resolveMiniProgramPlatform } from "@weapp-core/shared";
1
2
  //#region src/core/adapter.ts
2
3
  const GLOBAL_ADAPTER_KEYS = [
3
- {
4
- platform: "wx",
5
- key: "wx"
6
- },
7
- {
8
- platform: "my",
9
- key: "my"
10
- },
11
- {
12
- platform: "tt",
13
- key: "tt"
14
- },
4
+ ...getMiniProgramRuntimeGlobalKeys().map((key) => ({
5
+ platform: key,
6
+ key
7
+ })),
15
8
  {
16
9
  platform: "qq",
17
10
  key: "qq"
18
11
  },
19
- {
20
- platform: "swan",
21
- key: "swan"
22
- },
23
12
  {
24
13
  platform: "ks",
25
14
  key: "ks"
26
15
  },
27
- {
28
- platform: "jd",
29
- key: "jd"
30
- },
31
- {
32
- platform: "xhs",
33
- key: "xhs"
34
- },
35
16
  {
36
17
  platform: "dd",
37
18
  key: "dd"
@@ -71,6 +52,56 @@ function detectGlobalAdapter() {
71
52
  }
72
53
  return {};
73
54
  }
55
+ const WEAPI_NON_PROMISIFIED_METHOD_NAME_SET = new Set([
56
+ "arrayBufferToBase64",
57
+ "base64ToArrayBuffer",
58
+ "canIUse",
59
+ "cancelIdleCallback",
60
+ "createAnimation",
61
+ "createAudioContext",
62
+ "createCameraContext",
63
+ "createCanvasContext",
64
+ "createEditorContext",
65
+ "createInnerAudioContext",
66
+ "createIntersectionObserver",
67
+ "createInterstitialAd",
68
+ "createLivePlayerContext",
69
+ "createLivePusherContext",
70
+ "createMapContext",
71
+ "createMediaAudioPlayer",
72
+ "createMediaContainer",
73
+ "createMediaRecorder",
74
+ "createOffscreenCanvas",
75
+ "createRewardedVideoAd",
76
+ "createSelectorQuery",
77
+ "createTCPSocket",
78
+ "createUDPSocket",
79
+ "createVKSession",
80
+ "createVideoContext",
81
+ "createWebAudioContext",
82
+ "createWorker",
83
+ "getBackgroundAudioManager",
84
+ "getFileSystemManager",
85
+ "getLogManager",
86
+ "getMenuButtonBoundingClientRect",
87
+ "getNFCAdapter",
88
+ "getOpenDataContext",
89
+ "getPerformance",
90
+ "getRealtimeLogManager",
91
+ "getRecorderManager",
92
+ "getUpdateManager",
93
+ "getUserCryptoManager",
94
+ "getXrFrameSystem",
95
+ "nextTick",
96
+ "reportAnalytics",
97
+ "requestIdleCallback"
98
+ ]);
99
+ /**
100
+ * @description 判断方法是否应保留原始同步返回值,而不是包装为 Promise。
101
+ */
102
+ function isNonPromisifiedMethod(name) {
103
+ return WEAPI_NON_PROMISIFIED_METHOD_NAME_SET.has(name);
104
+ }
74
105
  //#endregion
75
106
  //#region src/core/utils.ts
76
107
  function isPlainObject(value) {
@@ -89,7 +120,7 @@ function isEventMethod(name) {
89
120
  return ON_EVENT_RE.test(name) || OFF_EVENT_RE.test(name);
90
121
  }
91
122
  function shouldSkipPromise(name) {
92
- return isSyncMethod(name) || isEventMethod(name) || name === "createInterstitialAd" || name === "createRewardedVideoAd" || name === "createVKSession" || name === "createCameraContext" || name === "cancelIdleCallback" || name === "nextTick" || name === "getLogManager" || name === "reportAnalytics";
123
+ return isSyncMethod(name) || isEventMethod(name) || isNonPromisifiedMethod(name);
93
124
  }
94
125
  function createNotSupportedError(methodName, platform) {
95
126
  return { errMsg: `${platform ? `${platform}.${methodName}` : methodName}:fail method not supported` };
@@ -688,6 +719,53 @@ const WEAPI_TT_METHODS_UNSUBSCRIBE_AUDIENCES_FOLLOW_ACTION_TO_VIBRATE_SHORT = [
688
719
  */
689
720
  const WEAPI_TT_METHODS = [...WEAPI_TT_METHODS_APPLY_EC_COUPON_TO_UNSUBSCRIBE_ALL_SPECIFIED_USER_COMMENT, ...WEAPI_TT_METHODS_UNSUBSCRIBE_AUDIENCES_FOLLOW_ACTION_TO_VIBRATE_SHORT];
690
721
  //#endregion
722
+ //#region src/core/apiCatalog/typeSources.ts
723
+ /**
724
+ * @description 三端 API 名单(由 typings 自动提取,请勿手工修改)
725
+ * @generated by scripts/sync-api-catalog.mjs
726
+ */
727
+ const WEAPI_TYPE_SOURCES = {
728
+ default: {
729
+ package: "miniprogram-api-typings",
730
+ version: "5.1.2"
731
+ },
732
+ wechat: {
733
+ package: "miniprogram-api-typings",
734
+ version: "5.1.2"
735
+ },
736
+ alipay: {
737
+ package: "@mini-types/alipay",
738
+ version: "3.0.14"
739
+ },
740
+ douyin: {
741
+ package: "@douyin-microapp/typings",
742
+ version: "1.3.1"
743
+ },
744
+ wx: {
745
+ package: "miniprogram-api-typings",
746
+ version: "5.1.2"
747
+ },
748
+ my: {
749
+ package: "@mini-types/alipay",
750
+ version: "3.0.14"
751
+ },
752
+ tt: {
753
+ package: "@douyin-microapp/typings",
754
+ version: "1.3.1"
755
+ }
756
+ };
757
+ const WEAPI_PLATFORM_TYPE_SOURCES = {
758
+ default: WEAPI_TYPE_SOURCES.default,
759
+ wechat: WEAPI_TYPE_SOURCES.wechat,
760
+ alipay: WEAPI_TYPE_SOURCES.alipay,
761
+ douyin: WEAPI_TYPE_SOURCES.douyin
762
+ };
763
+ const WEAPI_RUNTIME_TYPE_SOURCES = {
764
+ wx: WEAPI_TYPE_SOURCES.wx,
765
+ my: WEAPI_TYPE_SOURCES.my,
766
+ tt: WEAPI_TYPE_SOURCES.tt
767
+ };
768
+ //#endregion
691
769
  //#region src/core/apiCatalog/wxMethodsAddCardToJoinVoIPChat.ts
692
770
  /**
693
771
  * @description 三端 API 名单(由 typings 自动提取,请勿手工修改)
@@ -1192,17 +1270,19 @@ const WEAPI_WX_METHODS_PRE_DOWNLOAD_SUBPACKAGE_TO_WRITE_BLECHARACTERISTIC_VALUE
1192
1270
  "vibrateShort",
1193
1271
  "writeBLECharacteristicValue"
1194
1272
  ];
1195
- [
1273
+ //#endregion
1274
+ //#region src/core/apiCatalog/index.ts
1275
+ const WEAPI_WECHAT_METHODS = [
1196
1276
  ...WEAPI_WX_METHODS_ADD_CARD_TO_JOIN_VO_IPCHAT,
1197
1277
  ...WEAPI_WX_METHODS_LOAD_BUILT_IN_FONT_FACE_TO_POST_MESSAGE_TO_REFERRER_PAGE,
1198
1278
  ...WEAPI_WX_METHODS_PRE_DOWNLOAD_SUBPACKAGE_TO_WRITE_BLECHARACTERISTIC_VALUE
1199
1279
  ];
1280
+ const WEAPI_ALIPAY_METHODS = WEAPI_MY_METHODS;
1281
+ const WEAPI_DOUYIN_METHODS = WEAPI_TT_METHODS;
1282
+ const WEAPI_MINIPROGRAM_METHODS = WEAPI_WECHAT_METHODS;
1200
1283
  //#endregion
1201
1284
  //#region src/core/methodMapping/rules/helpersDeviceAndStorage.ts
1202
- const PLATFORM_ALIASES$1 = {
1203
- alipay: "my",
1204
- douyin: "tt"
1205
- };
1285
+ const PLATFORM_ALIASES$1 = { kuaishou: "ks" };
1206
1286
  function mapSaveFileArgs(args) {
1207
1287
  if (args.length === 0) return args;
1208
1288
  const nextArgs = [...args];
@@ -1309,9 +1389,10 @@ function mapDouyinSaveFileResult(result) {
1309
1389
  return result;
1310
1390
  }
1311
1391
  function normalizePlatformName$1(value) {
1312
- if (!value) return;
1313
- const normalized = value.trim().toLowerCase();
1392
+ const normalized = normalizeMiniProgramPlatform(value);
1314
1393
  if (!normalized) return;
1394
+ const miniProgramPlatform = resolveMiniProgramPlatform(normalized);
1395
+ if (miniProgramPlatform) return getMiniProgramRuntimeGlobalKey(miniProgramPlatform);
1315
1396
  return PLATFORM_ALIASES$1[normalized] ?? normalized;
1316
1397
  }
1317
1398
  //#endregion
@@ -2040,9 +2121,10 @@ const METHOD_MAPPINGS = {
2040
2121
  ...TT_METHOD_MAPPINGS_JOIN_VO_IPCHAT_TO_OFF_BLECONNECTION_STATE_CHANGE
2041
2122
  }
2042
2123
  };
2124
+ new Set(WEAPI_MINIPROGRAM_METHODS);
2043
2125
  const PLATFORM_METHOD_SET = {
2044
- my: new Set(WEAPI_MY_METHODS),
2045
- tt: new Set(WEAPI_TT_METHODS)
2126
+ my: new Set(WEAPI_ALIPAY_METHODS),
2127
+ tt: new Set(WEAPI_DOUYIN_METHODS)
2046
2128
  };
2047
2129
  function createFallbackMappingRule(platform, methodName) {}
2048
2130
  function resolveMappingRule(platform, methodName, options = {}) {
@@ -2114,8 +2196,18 @@ function resolveQueueSize(value) {
2114
2196
  if (!isFinitePositiveNumber(value)) return 100;
2115
2197
  return Math.max(1, Math.floor(value));
2116
2198
  }
2199
+ function resolveCurrentMiniProgramHostConfig() {
2200
+ const runtimeRoot = globalThis;
2201
+ for (const globalKey of getMiniProgramRuntimeGlobalKeys()) {
2202
+ if (!runtimeRoot[globalKey]) continue;
2203
+ const hostConfig = runtimeRoot[getMiniProgramRuntimeHostConfigKey(getMiniProgramPlatformByRuntimeGlobalKey(globalKey))];
2204
+ return isPlainObject(hostConfig) ? hostConfig : void 0;
2205
+ }
2206
+ const defaultHostConfig = runtimeRoot[getMiniProgramRuntimeHostConfigKey(void 0)];
2207
+ return isPlainObject(defaultHostConfig) ? defaultHostConfig : void 0;
2208
+ }
2117
2209
  function resolveHostTimeoutConfig() {
2118
- const networkTimeout = globalThis.__wxConfig?.networkTimeout;
2210
+ const networkTimeout = resolveCurrentMiniProgramHostConfig()?.networkTimeout;
2119
2211
  if (!isPlainObject(networkTimeout)) return {};
2120
2212
  const result = {};
2121
2213
  if (isFinitePositiveNumber(networkTimeout.request)) result.request = networkTimeout.request;
@@ -2338,14 +2430,12 @@ const INTERNAL_KEYS = new Set([
2338
2430
  "resolveTarget",
2339
2431
  "supports"
2340
2432
  ]);
2341
- const PLATFORM_ALIASES = {
2342
- alipay: "my",
2343
- douyin: "tt"
2344
- };
2433
+ const PLATFORM_ALIASES = { kuaishou: "ks" };
2345
2434
  function normalizePlatformName(value) {
2346
- if (!value) return;
2347
- const normalized = value.trim().toLowerCase();
2435
+ const normalized = normalizeMiniProgramPlatform(value);
2348
2436
  if (!normalized) return;
2437
+ const miniProgramPlatform = resolveMiniProgramPlatform(normalized);
2438
+ if (miniProgramPlatform) return getMiniProgramRuntimeGlobalKey(miniProgramPlatform);
2349
2439
  return PLATFORM_ALIASES[normalized] ?? normalized;
2350
2440
  }
2351
2441
  /**
@@ -2505,10 +2595,12 @@ function createWeapi(options = {}) {
2505
2595
  * | --- | --- | --- |
2506
2596
  * | 微信小程序 (`wx`) | `miniprogram-api-typings` | ✅ 全量 |
2507
2597
  * | 支付宝小程序 (`my`) | `@mini-types/alipay` | ✅ 全量 |
2598
+ * | 百度智能小程序 (`swan`) | 运行时透传 | ⚠️ 按宿主能力支持 |
2508
2599
  * | 抖音小程序 (`tt`) | `@douyin-microapp/typings` | ✅ 全量 |
2509
- * | 其他平台对象 (`swan/jd/xhs/...`) | 运行时对象透传 | ⚠️ 按宿主能力支持 |
2600
+ * | 京东小程序 (`jd`) | 运行时透传 | ⚠️ 按宿主能力支持 |
2601
+ * | 小红书小程序 (`xhs`) | 运行时透传 | ⚠️ 按宿主能力支持 |
2510
2602
  * @generated weapi-platform-matrix:end
2511
2603
  */
2512
2604
  const wpi = createWeapi();
2513
2605
  //#endregion
2514
- export { createWeapi, wpi };
2606
+ export { WEAPI_PLATFORM_TYPE_SOURCES, WEAPI_RUNTIME_TYPE_SOURCES, WEAPI_TYPE_SOURCES, createWeapi, wpi };
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@wevu/api",
3
3
  "type": "module",
4
- "version": "0.2.2",
4
+ "version": "0.2.4",
5
5
  "description": "tsdown bundler template",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
8
8
  "repository": {
9
9
  "type": "git",
10
10
  "url": "git+https://github.com/weapp-vite/weapp-vite.git",
11
- "directory": "packages/weapi"
11
+ "directory": "packages-runtime/weapi"
12
12
  },
13
13
  "bugs": {
14
14
  "url": "https://github.com/weapp-vite/weapp-vite/issues"
@@ -34,7 +34,8 @@
34
34
  "dependencies": {
35
35
  "@douyin-microapp/typings": "^1.3.1",
36
36
  "@mini-types/alipay": "^3.0.14",
37
- "miniprogram-api-typings": "^5.1.2"
37
+ "miniprogram-api-typings": "^5.1.2",
38
+ "@weapp-core/shared": "3.0.4"
38
39
  },
39
40
  "publishConfig": {
40
41
  "access": "public"
package/types/index.d.ts CHANGED
@@ -7,35 +7,133 @@ import type {
7
7
  CreateWeapiOptions,
8
8
  WeapiAdapter,
9
9
  WeapiAlipayAdapter,
10
+ WeapiAlipayMethodName,
11
+ WeapiAlipayMiniProgramRawAdapterSource,
10
12
  WeapiAlipayRawAdapter,
11
13
  WeapiCrossPlatformAdapter,
12
14
  WeapiCrossPlatformRawAdapter,
15
+ WeapiDefaultMiniProgramRawAdapterSource,
13
16
  WeapiDouyinAdapter,
17
+ WeapiDouyinMethodName,
18
+ WeapiDouyinMiniProgramRawAdapterSource,
14
19
  WeapiDouyinRawAdapter,
15
20
  WeapiInstance,
16
21
  WeapiMethodSupportQueryOptions,
22
+ WeapiMiniProgramAdapter,
23
+ WeapiMiniProgramAlipayAdapter,
24
+ WeapiMiniProgramAlipayMethodName,
25
+ WeapiMiniProgramAlipayRawAdapter,
26
+ WeapiMiniProgramBluetoothError,
27
+ WeapiMiniProgramClipboardDataResult,
28
+ WeapiMiniProgramConnectSocketOption,
29
+ WeapiMiniProgramCrossPlatformAdapter,
30
+ WeapiMiniProgramCrossPlatformRawAdapter,
31
+ WeapiMiniProgramDouyinAdapter,
32
+ WeapiMiniProgramDouyinMethodName,
33
+ WeapiMiniProgramDouyinRawAdapter,
34
+ WeapiMiniProgramLogManager,
35
+ WeapiMiniProgramMethodName,
36
+ WeapiMiniProgramPlatformRawAdapterSourceName,
37
+ WeapiMiniProgramPlatformRawAdapterSourceRegistry,
38
+ WeapiMiniProgramRawAdapter,
39
+ WeapiMiniProgramRawAdapterSourceName,
40
+ WeapiMiniProgramRequestMethod,
41
+ WeapiMiniProgramRequestOption,
42
+ WeapiMiniProgramRequestSuccessResult,
43
+ WeapiMiniProgramRequestTask,
44
+ WeapiMiniProgramRuntimeRawAdapterSourceName,
45
+ WeapiMiniProgramRuntimeRawAdapterSourceRegistry,
46
+ WeapiMiniProgramSelectorQuery,
47
+ WeapiMiniProgramSocketTask,
48
+ WeapiMiniProgramSystemInfo,
49
+ WeapiMiniProgramUpdateManager,
50
+ WeapiMiniProgramVideoContext,
51
+ WeapiMiniProgramWechatMethodName,
52
+ WeapiMiniProgramWechatRawAdapter,
53
+ WeapiMiniProgramWxAdapter,
54
+ WeapiMiniProgramWxMethodName,
55
+ WeapiMiniProgramWxRawAdapter,
56
+ WeapiPlatformTypeSourceName,
17
57
  WeapiPromisify,
18
58
  WeapiResolvedTarget,
59
+ WeapiRuntimeTypeSourceName,
19
60
  WeapiSupportLevel,
61
+ WeapiTtMiniProgramRawAdapterSource,
62
+ WeapiTypeSourceName,
63
+ WeapiWechatMethodName,
64
+ WeapiWechatMiniProgramRawAdapterSource,
65
+ WeapiWechatRawAdapter,
20
66
  WeapiWxAdapter,
67
+ WeapiWxMethodName,
21
68
  WeapiWxRawAdapter,
22
69
  } from '../dist/index.d.mts'
23
70
 
71
+ export declare const WEAPI_PLATFORM_TYPE_SOURCES: typeof import('../dist/index.mjs').WEAPI_PLATFORM_TYPE_SOURCES
72
+ export declare const WEAPI_RUNTIME_TYPE_SOURCES: typeof import('../dist/index.mjs').WEAPI_RUNTIME_TYPE_SOURCES
73
+ export declare const WEAPI_TYPE_SOURCES: typeof import('../dist/index.mjs').WEAPI_TYPE_SOURCES
74
+
24
75
  export type {
25
76
  CreateWeapiOptions,
26
77
  WeapiAdapter,
27
78
  WeapiAlipayAdapter,
79
+ WeapiAlipayMethodName,
80
+ WeapiAlipayMiniProgramRawAdapterSource,
28
81
  WeapiAlipayRawAdapter,
29
82
  WeapiCrossPlatformAdapter,
30
83
  WeapiCrossPlatformRawAdapter,
84
+ WeapiDefaultMiniProgramRawAdapterSource,
31
85
  WeapiDouyinAdapter,
86
+ WeapiDouyinMethodName,
87
+ WeapiDouyinMiniProgramRawAdapterSource,
32
88
  WeapiDouyinRawAdapter,
33
89
  WeapiInstance,
34
90
  WeapiMethodSupportQueryOptions,
91
+ WeapiMiniProgramAdapter,
92
+ WeapiMiniProgramAlipayAdapter,
93
+ WeapiMiniProgramAlipayMethodName,
94
+ WeapiMiniProgramAlipayRawAdapter,
95
+ WeapiMiniProgramBluetoothError,
96
+ WeapiMiniProgramClipboardDataResult,
97
+ WeapiMiniProgramConnectSocketOption,
98
+ WeapiMiniProgramCrossPlatformAdapter,
99
+ WeapiMiniProgramCrossPlatformRawAdapter,
100
+ WeapiMiniProgramDouyinAdapter,
101
+ WeapiMiniProgramDouyinMethodName,
102
+ WeapiMiniProgramDouyinRawAdapter,
103
+ WeapiMiniProgramLogManager,
104
+ WeapiMiniProgramMethodName,
105
+ WeapiMiniProgramPlatformRawAdapterSourceName,
106
+ WeapiMiniProgramPlatformRawAdapterSourceRegistry,
107
+ WeapiMiniProgramRawAdapter,
108
+ WeapiMiniProgramRawAdapterSourceName,
109
+ WeapiMiniProgramRequestMethod,
110
+ WeapiMiniProgramRequestOption,
111
+ WeapiMiniProgramRequestSuccessResult,
112
+ WeapiMiniProgramRequestTask,
113
+ WeapiMiniProgramRuntimeRawAdapterSourceName,
114
+ WeapiMiniProgramRuntimeRawAdapterSourceRegistry,
115
+ WeapiMiniProgramSelectorQuery,
116
+ WeapiMiniProgramSocketTask,
117
+ WeapiMiniProgramSystemInfo,
118
+ WeapiMiniProgramUpdateManager,
119
+ WeapiMiniProgramVideoContext,
120
+ WeapiMiniProgramWechatMethodName,
121
+ WeapiMiniProgramWechatRawAdapter,
122
+ WeapiMiniProgramWxAdapter,
123
+ WeapiMiniProgramWxMethodName,
124
+ WeapiMiniProgramWxRawAdapter,
125
+ WeapiPlatformTypeSourceName,
35
126
  WeapiPromisify,
36
127
  WeapiResolvedTarget,
128
+ WeapiRuntimeTypeSourceName,
37
129
  WeapiSupportLevel,
130
+ WeapiTtMiniProgramRawAdapterSource,
131
+ WeapiTypeSourceName,
132
+ WeapiWechatMethodName,
133
+ WeapiWechatMiniProgramRawAdapterSource,
134
+ WeapiWechatRawAdapter,
38
135
  WeapiWxAdapter,
136
+ WeapiWxMethodName,
39
137
  WeapiWxRawAdapter,
40
138
  }
41
139
 
@@ -53,8 +151,10 @@ export type WeapiDefaultInstance = WeapiInstance<WeapiCrossPlatformRawAdapter>
53
151
  * | --- | --- | --- | --- |
54
152
  * | 微信小程序 | `wx` | `miniprogram-api-typings` | ✅ 全量 |
55
153
  * | 支付宝小程序 | `my` | `@mini-types/alipay` | ✅ 全量 |
154
+ * | 百度智能小程序 | `swan` | 运行时透传 | ⚠️ 按宿主能力支持 |
56
155
  * | 抖音小程序 | `tt` | `@douyin-microapp/typings` | ✅ 全量 |
57
- * | 其他平台(swan/jd/xhs 等) | 运行时宿主对象 | 运行时透传 | ⚠️ 按宿主能力支持 |
156
+ * | 京东小程序 | `jd` | 运行时透传 | ⚠️ 按宿主能力支持 |
157
+ * | 小红书小程序 | `xhs` | 运行时透传 | ⚠️ 按宿主能力支持 |
58
158
  * @generated weapi-platform-matrix:end
59
159
  */
60
160
  export const wpi: WeapiDefaultInstance