@cloudbase/wx-cloud-client-sdk 1.0.0-alpha.1 → 1.0.0
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/lib/api/datasouce-caller.d.ts +1 -1
- package/lib/error.d.ts +10 -0
- package/lib/index.d.ts +2 -2
- package/lib/orm/orm-client.d.ts +1 -1
- package/lib/types/index.d.ts +567 -86
- package/lib/utils.d.ts +10 -0
- package/lib/{wxCloudCLientSDK.cjs.js → wxCloudClientSDK.cjs.js} +132 -72
- package/lib/{wxCloudCLientSDK.esm.js → wxCloudClientSDK.esm.js} +132 -72
- package/lib/{wxCloudCLientSDK.umd.js → wxCloudClientSDK.umd.js} +132 -72
- package/package.json +12 -7
|
@@ -18,8 +18,22 @@
|
|
|
18
18
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
19
19
|
PERFORMANCE OF THIS SOFTWARE.
|
|
20
20
|
***************************************************************************** */
|
|
21
|
-
/* global Reflect, Promise
|
|
21
|
+
/* global Reflect, Promise */
|
|
22
22
|
|
|
23
|
+
var extendStatics = function(d, b) {
|
|
24
|
+
extendStatics = Object.setPrototypeOf ||
|
|
25
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
26
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
27
|
+
return extendStatics(d, b);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
function __extends(d, b) {
|
|
31
|
+
if (typeof b !== "function" && b !== null)
|
|
32
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
33
|
+
extendStatics(d, b);
|
|
34
|
+
function __() { this.constructor = d; }
|
|
35
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
36
|
+
}
|
|
23
37
|
|
|
24
38
|
var __assign = function() {
|
|
25
39
|
__assign = Object.assign || function __assign(t) {
|
|
@@ -38,7 +52,7 @@
|
|
|
38
52
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
53
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
54
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
-
step((generator = generator.apply(thisArg,
|
|
55
|
+
step((generator = generator.apply(thisArg, [])).next());
|
|
42
56
|
});
|
|
43
57
|
}
|
|
44
58
|
|
|
@@ -48,7 +62,7 @@
|
|
|
48
62
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
49
63
|
function step(op) {
|
|
50
64
|
if (f) throw new TypeError("Generator is already executing.");
|
|
51
|
-
while (
|
|
65
|
+
while (_) try {
|
|
52
66
|
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;
|
|
53
67
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
54
68
|
switch (op[0]) {
|
|
@@ -68,63 +82,125 @@
|
|
|
68
82
|
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
69
83
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
70
84
|
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
var WxCloudSDKError = /** @class */ (function (_super) {
|
|
88
|
+
__extends(WxCloudSDKError, _super);
|
|
89
|
+
function WxCloudSDKError(message, extra) {
|
|
90
|
+
var _this = _super.call(this, message) || this;
|
|
91
|
+
_this.name = 'WxCloudSDKError';
|
|
92
|
+
_this.code = extra === null || extra === void 0 ? void 0 : extra.code;
|
|
93
|
+
_this.requestId = extra === null || extra === void 0 ? void 0 : extra.requestId;
|
|
94
|
+
_this.originError = extra === null || extra === void 0 ? void 0 : extra.originError;
|
|
95
|
+
return _this;
|
|
96
|
+
}
|
|
97
|
+
return WxCloudSDKError;
|
|
98
|
+
}(Error));
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* 获取全局对象 window
|
|
102
|
+
* 小程序中可用, 但小程序中对象信息残缺, 无法访问 navigator 对象, ua 信息也无意义
|
|
103
|
+
*/
|
|
104
|
+
function getGlobalObj() {
|
|
105
|
+
// @ts-ignore
|
|
106
|
+
return (typeof window !== 'undefined' && window) || (typeof globalThis !== 'undefined' && globalThis);
|
|
107
|
+
}
|
|
108
|
+
/** 获取referrer 信息, 担心小程序中报错, 故catch */
|
|
109
|
+
function getReferrer() {
|
|
110
|
+
try {
|
|
111
|
+
var globalObj = getGlobalObj();
|
|
112
|
+
if (!globalObj)
|
|
113
|
+
return;
|
|
114
|
+
// 浏览器中
|
|
115
|
+
// @ts-ignore
|
|
116
|
+
if (typeof wx === 'undefined') {
|
|
117
|
+
// @ts-ignore
|
|
118
|
+
return getGlobalObj().location.href;
|
|
119
|
+
}
|
|
120
|
+
// 当前页面路由
|
|
121
|
+
// @ts-ignore
|
|
122
|
+
return globalObj.__wxRoute;
|
|
123
|
+
}
|
|
124
|
+
catch (_a) { }
|
|
125
|
+
}
|
|
126
|
+
/** 获取用户UA, 小程序中使用 getSystemInfo 替代 */
|
|
127
|
+
function getUserAgent() {
|
|
128
|
+
var globalObj = getGlobalObj();
|
|
129
|
+
// @ts-ignore
|
|
130
|
+
if (globalObj === null || globalObj === void 0 ? void 0 : globalObj.navigator)
|
|
131
|
+
return globalObj.navigator.userAgent;
|
|
132
|
+
// 微信小程序
|
|
133
|
+
// @ts-ignore
|
|
134
|
+
if (typeof wx !== 'undefined' && wx.getSystemInfo) {
|
|
135
|
+
var ua_1;
|
|
136
|
+
// 同步接口
|
|
137
|
+
// @ts-ignore
|
|
138
|
+
wx.getSystemInfo({
|
|
139
|
+
success: function (res) {
|
|
140
|
+
if (!res)
|
|
141
|
+
return;
|
|
142
|
+
ua_1 = ['brand', 'model', 'version', 'system', 'platform', 'SDKVersion', 'language']
|
|
143
|
+
.map(function (k) { return "".concat(k, ": ").concat(res[k]); })
|
|
144
|
+
.join(', ');
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
return ua_1;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
var VERSION = "1.0.0";
|
|
77
151
|
|
|
78
152
|
var callDataSource = function (_a) {
|
|
79
153
|
var dataSourceName = _a.dataSourceName, methodName = _a.methodName, params = _a.params, realMethodName = _a.realMethodName, callFunction = _a.callFunction;
|
|
80
154
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
81
155
|
var result, response, error_1;
|
|
82
|
-
var _b;
|
|
83
|
-
return __generator(this, function (
|
|
84
|
-
switch (
|
|
156
|
+
var _b, _c;
|
|
157
|
+
return __generator(this, function (_d) {
|
|
158
|
+
switch (_d.label) {
|
|
85
159
|
case 0:
|
|
86
160
|
result = {
|
|
87
161
|
data: {},
|
|
88
|
-
|
|
162
|
+
requestId: ''
|
|
89
163
|
};
|
|
90
|
-
|
|
164
|
+
_d.label = 1;
|
|
91
165
|
case 1:
|
|
92
|
-
|
|
166
|
+
_d.trys.push([1, 3, , 4]);
|
|
93
167
|
return [4 /*yield*/, callFunction({
|
|
94
|
-
name:
|
|
168
|
+
name: 'lowcode-datasource',
|
|
95
169
|
data: {
|
|
96
170
|
dataSourceName: dataSourceName,
|
|
97
171
|
methodName: methodName,
|
|
98
|
-
params: params
|
|
172
|
+
params: params,
|
|
173
|
+
userAgent: getUserAgent(),
|
|
174
|
+
referrer: getReferrer(),
|
|
175
|
+
'x-sdk-version': VERSION
|
|
99
176
|
}
|
|
100
177
|
})];
|
|
101
178
|
case 2:
|
|
102
|
-
response =
|
|
179
|
+
response = _d.sent();
|
|
103
180
|
if (response === null || response === void 0 ? void 0 : response.result.code) {
|
|
104
|
-
result.
|
|
181
|
+
throw new WxCloudSDKError("\u3010\u9519\u8BEF\u3011".concat(response === null || response === void 0 ? void 0 : response.result.message, "\n\u3010\u64CD\u4F5C\u3011\u8C03\u7528 ").concat(dataSourceName, ".").concat(realMethodName, "\n\u3010\u8BF7\u6C42ID\u3011").concat((response === null || response === void 0 ? void 0 : response.requestId) || 'N/A'), {
|
|
105
182
|
code: response === null || response === void 0 ? void 0 : response.result.code,
|
|
106
|
-
message: "\u3010\u9519\u8BEF\u3011" + (response === null || response === void 0 ? void 0 : response.result.message) + " \n\u3010\u64CD\u4F5C\u3011\u8C03\u7528 " + dataSourceName + "." + realMethodName + "\n\u3010\u8BF7\u6C42ID\u3011" + (response === null || response === void 0 ? void 0 : response.requestId),
|
|
107
183
|
requestId: response === null || response === void 0 ? void 0 : response.requestId
|
|
108
|
-
};
|
|
184
|
+
});
|
|
109
185
|
}
|
|
110
186
|
else {
|
|
111
187
|
result.data = ((_b = response === null || response === void 0 ? void 0 : response.result) === null || _b === void 0 ? void 0 : _b.data) || {};
|
|
188
|
+
result.requestId = ((_c = response === null || response === void 0 ? void 0 : response.result) === null || _c === void 0 ? void 0 : _c.requestId) || '';
|
|
112
189
|
}
|
|
113
190
|
return [3 /*break*/, 4];
|
|
114
191
|
case 3:
|
|
115
|
-
error_1 =
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
console.error(result.error);
|
|
192
|
+
error_1 = _d.sent();
|
|
193
|
+
if (error_1.name === 'WxCloudSDKError') {
|
|
194
|
+
throw error_1;
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
console.log(error_1);
|
|
198
|
+
throw new WxCloudSDKError("\u3010\u9519\u8BEF\u3011".concat(error_1.message, "\n \u3010\u64CD\u4F5C\u3011\u8C03\u7528 ").concat(dataSourceName, ".").concat(realMethodName, "\n \u3010\u8BF7\u6C42ID\u3011N/A"), {
|
|
199
|
+
code: 'UnknownError',
|
|
200
|
+
originError: error_1
|
|
201
|
+
});
|
|
126
202
|
}
|
|
127
|
-
|
|
203
|
+
case 4: return [2 /*return*/, result];
|
|
128
204
|
}
|
|
129
205
|
});
|
|
130
206
|
});
|
|
@@ -132,25 +208,28 @@
|
|
|
132
208
|
|
|
133
209
|
var CRUD_METHODS = {
|
|
134
210
|
create: {
|
|
135
|
-
methodName:
|
|
211
|
+
methodName: 'wedaCreateV2'
|
|
136
212
|
},
|
|
137
213
|
createMany: {
|
|
138
|
-
methodName:
|
|
214
|
+
methodName: 'wedaBatchCreateV2'
|
|
139
215
|
},
|
|
140
216
|
update: {
|
|
141
|
-
methodName:
|
|
217
|
+
methodName: 'wedaUpdateV2'
|
|
218
|
+
},
|
|
219
|
+
upsert: {
|
|
220
|
+
methodName: 'wedaUpsertV2'
|
|
142
221
|
},
|
|
143
222
|
updateMany: {
|
|
144
|
-
methodName:
|
|
223
|
+
methodName: 'wedaBatchUpdateV2'
|
|
145
224
|
},
|
|
146
225
|
"delete": {
|
|
147
|
-
methodName:
|
|
226
|
+
methodName: 'wedaDeleteV2'
|
|
148
227
|
},
|
|
149
228
|
deleteMany: {
|
|
150
|
-
methodName:
|
|
229
|
+
methodName: 'wedaBatchDeleteV2'
|
|
151
230
|
},
|
|
152
231
|
get: {
|
|
153
|
-
methodName:
|
|
232
|
+
methodName: 'wedaGetItemV2',
|
|
154
233
|
defaultParams: {
|
|
155
234
|
filter: {
|
|
156
235
|
where: {}
|
|
@@ -161,7 +240,7 @@
|
|
|
161
240
|
}
|
|
162
241
|
},
|
|
163
242
|
list: {
|
|
164
|
-
methodName:
|
|
243
|
+
methodName: 'wedaGetRecordsV2',
|
|
165
244
|
defaultParams: {
|
|
166
245
|
filter: {
|
|
167
246
|
where: {}
|
|
@@ -177,18 +256,13 @@
|
|
|
177
256
|
get: function (target, methodName) {
|
|
178
257
|
var operation = CRUD_METHODS[methodName];
|
|
179
258
|
if (!operation) {
|
|
180
|
-
var error = new Error("\u4E0D\u652F\u6301\u7684\u64CD\u4F5C: "
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
message: error.message || "Unknown error occurred",
|
|
187
|
-
requestId: "N/A"
|
|
188
|
-
}
|
|
189
|
-
};
|
|
259
|
+
var error = new Error("\u4E0D\u652F\u6301\u7684\u64CD\u4F5C: ".concat(methodName));
|
|
260
|
+
throw new WxCloudSDKError(error.message || 'Unknown error occurred', {
|
|
261
|
+
originError: error,
|
|
262
|
+
code: 'NotSupported',
|
|
263
|
+
requestId: 'N/A'
|
|
264
|
+
});
|
|
190
265
|
}
|
|
191
|
-
console.group("[" + dataSourceName + "." + methodName + "]");
|
|
192
266
|
return function (params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
193
267
|
var effectiveParams, rawData, result, dataKey;
|
|
194
268
|
var _a;
|
|
@@ -196,13 +270,6 @@
|
|
|
196
270
|
switch (_b.label) {
|
|
197
271
|
case 0:
|
|
198
272
|
effectiveParams = __assign(__assign({}, (operation.defaultParams || {})), (params || {}));
|
|
199
|
-
console.log(params);
|
|
200
|
-
console.log({
|
|
201
|
-
dataSourceName: dataSourceName,
|
|
202
|
-
methodName: operation.methodName,
|
|
203
|
-
realMethodName: methodName,
|
|
204
|
-
params: effectiveParams
|
|
205
|
-
});
|
|
206
273
|
return [4 /*yield*/, callDataSource({
|
|
207
274
|
callFunction: callFunction,
|
|
208
275
|
dataSourceName: dataSourceName,
|
|
@@ -212,16 +279,9 @@
|
|
|
212
279
|
})];
|
|
213
280
|
case 1:
|
|
214
281
|
rawData = _b.sent();
|
|
215
|
-
result = {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
result.data = dataKey ? (_a = rawData === null || rawData === void 0 ? void 0 : rawData.data) === null || _a === void 0 ? void 0 : _a[dataKey] : rawData === null || rawData === void 0 ? void 0 : rawData.data;
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
221
|
-
result.error = rawData.error;
|
|
222
|
-
}
|
|
223
|
-
console.log(result);
|
|
224
|
-
console.groupEnd();
|
|
282
|
+
result = { data: {} };
|
|
283
|
+
dataKey = operation.responseKey;
|
|
284
|
+
result.data = dataKey ? (_a = rawData === null || rawData === void 0 ? void 0 : rawData.data) === null || _a === void 0 ? void 0 : _a[dataKey] : rawData === null || rawData === void 0 ? void 0 : rawData.data;
|
|
225
285
|
return [2 /*return*/, result];
|
|
226
286
|
}
|
|
227
287
|
});
|
|
@@ -234,7 +294,7 @@
|
|
|
234
294
|
var generateClient = function (callFunction) {
|
|
235
295
|
return new Proxy({}, {
|
|
236
296
|
get: function (target, prop) {
|
|
237
|
-
if (typeof prop ===
|
|
297
|
+
if (typeof prop === 'string') {
|
|
238
298
|
// 返回一个函数,这个函数接受任意参数并返回一个 Promise
|
|
239
299
|
return generateClientByDataSourceName(prop, callFunction);
|
|
240
300
|
}
|
|
@@ -244,10 +304,10 @@
|
|
|
244
304
|
|
|
245
305
|
function init(cloud) {
|
|
246
306
|
if (!cloud) {
|
|
247
|
-
throw new Error(
|
|
307
|
+
throw new Error('cloud is required');
|
|
248
308
|
}
|
|
249
309
|
if (!cloud.callFunction) {
|
|
250
|
-
throw new Error(
|
|
310
|
+
throw new Error('cloud.callFunction is required');
|
|
251
311
|
}
|
|
252
312
|
var OrmClientImpl = generateClient(cloud.callFunction.bind(cloud));
|
|
253
313
|
cloud.models = OrmClientImpl;
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/wx-cloud-client-sdk",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "wx cloud client sdk",
|
|
5
|
-
"main": "lib/
|
|
6
|
-
"module": "lib/
|
|
7
|
-
"browser": "lib/
|
|
5
|
+
"main": "lib/wxCloudClientSDK.cjs.js",
|
|
6
|
+
"module": "lib/wxCloudClientSDK.esm.js",
|
|
7
|
+
"browser": "lib/wxCloudClientSDK.umd.js",
|
|
8
8
|
"types": "lib/index.d.ts",
|
|
9
9
|
"files": [
|
|
10
10
|
"lib"
|
|
@@ -12,17 +12,22 @@
|
|
|
12
12
|
"scripts": {
|
|
13
13
|
"clean": "npx rimraf lib/*",
|
|
14
14
|
"build": "npm run clean && rollup -c",
|
|
15
|
-
"
|
|
15
|
+
"develop": "parcel demo/index.html",
|
|
16
|
+
"sync-dts": "cd demo && tcb model sync-dts --envId=lowcode-4gs26nnz095f6f4d",
|
|
16
17
|
"build-demo": "npx rimraf dist/* && parcel build demo/index.html --public-url ./",
|
|
17
18
|
"publish": "npm publish --access public",
|
|
18
|
-
"publish-demo": "tcb hosting deploy dist wx-cloud-client-sdk-demo -e lowcode-4gs26nnz095f6f4d"
|
|
19
|
+
"publish-demo": "tcb hosting deploy dist wx-cloud-client-sdk-demo -e lowcode-4gs26nnz095f6f4d",
|
|
20
|
+
"docs": "npx rimraf docs/* && typedoc --options typedoc.json"
|
|
19
21
|
},
|
|
20
22
|
"devDependencies": {
|
|
21
23
|
"@rollup/plugin-commonjs": "^25.0.8",
|
|
22
24
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
25
|
+
"@rollup/plugin-replace": "^5.0.7",
|
|
23
26
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
24
27
|
"parcel-bundler": "1.6.1",
|
|
25
28
|
"rollup": "^4.18.0",
|
|
29
|
+
"typedoc": "^0.25.13",
|
|
30
|
+
"typedoc-plugin-markdown": "^4.0.3",
|
|
26
31
|
"typescript": "4.4.4"
|
|
27
32
|
},
|
|
28
33
|
"resolutions": {
|
|
@@ -32,4 +37,4 @@
|
|
|
32
37
|
"typescript",
|
|
33
38
|
"javascript"
|
|
34
39
|
]
|
|
35
|
-
}
|
|
40
|
+
}
|