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