@cloudbase/wx-cloud-client-sdk 1.0.0-alpha.0 → 1.0.0-alpha.2
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/demo/app.d.ts +1 -0
- package/lib/{api → src/api}/datasouce-caller.d.ts +1 -1
- package/lib/src/error.d.ts +10 -0
- package/lib/src/index.d.ts +3 -0
- package/lib/{orm → src/orm}/orm-client.d.ts +1 -1
- package/lib/src/types/index.d.ts +568 -0
- package/lib/{wxCloudCLientSDK.cjs.js → wxCloudClientSDK.cjs.js} +73 -71
- package/lib/{wxCloudCLientSDK.esm.js → wxCloudClientSDK.esm.js} +73 -71
- package/lib/{wxCloudCLientSDK.umd.js → wxCloudClientSDK.umd.js} +73 -71
- package/package.json +12 -8
- package/lib/index.d.ts +0 -3
- package/lib/types/index.d.ts +0 -130
|
@@ -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
|
|
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,
|
|
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 (
|
|
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,30 +78,38 @@ 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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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));
|
|
73
95
|
|
|
74
96
|
var callDataSource = function (_a) {
|
|
75
97
|
var dataSourceName = _a.dataSourceName, methodName = _a.methodName, params = _a.params, realMethodName = _a.realMethodName, callFunction = _a.callFunction;
|
|
76
98
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
77
99
|
var result, response, error_1;
|
|
78
|
-
var _b;
|
|
79
|
-
return __generator(this, function (
|
|
80
|
-
switch (
|
|
100
|
+
var _b, _c;
|
|
101
|
+
return __generator(this, function (_d) {
|
|
102
|
+
switch (_d.label) {
|
|
81
103
|
case 0:
|
|
82
104
|
result = {
|
|
83
105
|
data: {},
|
|
84
|
-
|
|
106
|
+
requestId: ''
|
|
85
107
|
};
|
|
86
|
-
|
|
108
|
+
_d.label = 1;
|
|
87
109
|
case 1:
|
|
88
|
-
|
|
110
|
+
_d.trys.push([1, 3, , 4]);
|
|
89
111
|
return [4 /*yield*/, callFunction({
|
|
90
|
-
name:
|
|
112
|
+
name: 'lowcode-datasource',
|
|
91
113
|
data: {
|
|
92
114
|
dataSourceName: dataSourceName,
|
|
93
115
|
methodName: methodName,
|
|
@@ -95,32 +117,31 @@ var callDataSource = function (_a) {
|
|
|
95
117
|
}
|
|
96
118
|
})];
|
|
97
119
|
case 2:
|
|
98
|
-
response =
|
|
120
|
+
response = _d.sent();
|
|
99
121
|
if (response === null || response === void 0 ? void 0 : response.result.code) {
|
|
100
|
-
result.
|
|
122
|
+
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
123
|
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
124
|
requestId: response === null || response === void 0 ? void 0 : response.requestId
|
|
104
|
-
};
|
|
125
|
+
});
|
|
105
126
|
}
|
|
106
127
|
else {
|
|
107
128
|
result.data = ((_b = response === null || response === void 0 ? void 0 : response.result) === null || _b === void 0 ? void 0 : _b.data) || {};
|
|
129
|
+
result.requestId = ((_c = response === null || response === void 0 ? void 0 : response.result) === null || _c === void 0 ? void 0 : _c.requestId) || '';
|
|
108
130
|
}
|
|
109
131
|
return [3 /*break*/, 4];
|
|
110
132
|
case 3:
|
|
111
|
-
error_1 =
|
|
112
|
-
|
|
113
|
-
|
|
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);
|
|
133
|
+
error_1 = _d.sent();
|
|
134
|
+
if (error_1.name === 'WxCloudSDKError') {
|
|
135
|
+
throw error_1;
|
|
122
136
|
}
|
|
123
|
-
|
|
137
|
+
else {
|
|
138
|
+
console.log(error_1);
|
|
139
|
+
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"), {
|
|
140
|
+
code: 'UnknownError',
|
|
141
|
+
originError: error_1
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
case 4: return [2 /*return*/, result];
|
|
124
145
|
}
|
|
125
146
|
});
|
|
126
147
|
});
|
|
@@ -128,25 +149,25 @@ var callDataSource = function (_a) {
|
|
|
128
149
|
|
|
129
150
|
var CRUD_METHODS = {
|
|
130
151
|
create: {
|
|
131
|
-
methodName:
|
|
152
|
+
methodName: 'wedaCreateV2'
|
|
132
153
|
},
|
|
133
154
|
createMany: {
|
|
134
|
-
methodName:
|
|
155
|
+
methodName: 'wedaBatchCreateV2'
|
|
135
156
|
},
|
|
136
157
|
update: {
|
|
137
|
-
methodName:
|
|
158
|
+
methodName: 'wedaUpdateV2'
|
|
138
159
|
},
|
|
139
160
|
updateMany: {
|
|
140
|
-
methodName:
|
|
161
|
+
methodName: 'wedaBatchUpdateV2'
|
|
141
162
|
},
|
|
142
163
|
"delete": {
|
|
143
|
-
methodName:
|
|
164
|
+
methodName: 'wedaDeleteV2'
|
|
144
165
|
},
|
|
145
166
|
deleteMany: {
|
|
146
|
-
methodName:
|
|
167
|
+
methodName: 'wedaBatchDeleteV2'
|
|
147
168
|
},
|
|
148
169
|
get: {
|
|
149
|
-
methodName:
|
|
170
|
+
methodName: 'wedaGetItemV2',
|
|
150
171
|
defaultParams: {
|
|
151
172
|
filter: {
|
|
152
173
|
where: {}
|
|
@@ -157,7 +178,7 @@ var CRUD_METHODS = {
|
|
|
157
178
|
}
|
|
158
179
|
},
|
|
159
180
|
list: {
|
|
160
|
-
methodName:
|
|
181
|
+
methodName: 'wedaGetRecordsV2',
|
|
161
182
|
defaultParams: {
|
|
162
183
|
filter: {
|
|
163
184
|
where: {}
|
|
@@ -173,18 +194,13 @@ var generateClientByDataSourceName = function (dataSourceName, callFunction) {
|
|
|
173
194
|
get: function (target, methodName) {
|
|
174
195
|
var operation = CRUD_METHODS[methodName];
|
|
175
196
|
if (!operation) {
|
|
176
|
-
var error = new Error("\u4E0D\u652F\u6301\u7684\u64CD\u4F5C: "
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
message: error.message || "Unknown error occurred",
|
|
183
|
-
requestId: "N/A"
|
|
184
|
-
}
|
|
185
|
-
};
|
|
197
|
+
var error = new Error("\u4E0D\u652F\u6301\u7684\u64CD\u4F5C: ".concat(methodName));
|
|
198
|
+
throw new WxCloudSDKError(error.message || 'Unknown error occurred', {
|
|
199
|
+
originError: error,
|
|
200
|
+
code: 'NotSupported',
|
|
201
|
+
requestId: 'N/A'
|
|
202
|
+
});
|
|
186
203
|
}
|
|
187
|
-
console.group("[" + dataSourceName + "." + methodName + "]");
|
|
188
204
|
return function (params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
189
205
|
var effectiveParams, rawData, result, dataKey;
|
|
190
206
|
var _a;
|
|
@@ -192,13 +208,6 @@ var generateClientByDataSourceName = function (dataSourceName, callFunction) {
|
|
|
192
208
|
switch (_b.label) {
|
|
193
209
|
case 0:
|
|
194
210
|
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
211
|
return [4 /*yield*/, callDataSource({
|
|
203
212
|
callFunction: callFunction,
|
|
204
213
|
dataSourceName: dataSourceName,
|
|
@@ -208,16 +217,9 @@ var generateClientByDataSourceName = function (dataSourceName, callFunction) {
|
|
|
208
217
|
})];
|
|
209
218
|
case 1:
|
|
210
219
|
rawData = _b.sent();
|
|
211
|
-
result = {
|
|
212
|
-
|
|
213
|
-
|
|
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();
|
|
220
|
+
result = { data: {} };
|
|
221
|
+
dataKey = operation.responseKey;
|
|
222
|
+
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
223
|
return [2 /*return*/, result];
|
|
222
224
|
}
|
|
223
225
|
});
|
|
@@ -230,7 +232,7 @@ var generateClientByDataSourceName = function (dataSourceName, callFunction) {
|
|
|
230
232
|
var generateClient = function (callFunction) {
|
|
231
233
|
return new Proxy({}, {
|
|
232
234
|
get: function (target, prop) {
|
|
233
|
-
if (typeof prop ===
|
|
235
|
+
if (typeof prop === 'string') {
|
|
234
236
|
// 返回一个函数,这个函数接受任意参数并返回一个 Promise
|
|
235
237
|
return generateClientByDataSourceName(prop, callFunction);
|
|
236
238
|
}
|
|
@@ -240,10 +242,10 @@ var generateClient = function (callFunction) {
|
|
|
240
242
|
|
|
241
243
|
function init(cloud) {
|
|
242
244
|
if (!cloud) {
|
|
243
|
-
throw new Error(
|
|
245
|
+
throw new Error('cloud is required');
|
|
244
246
|
}
|
|
245
247
|
if (!cloud.callFunction) {
|
|
246
|
-
throw new Error(
|
|
248
|
+
throw new Error('cloud.callFunction is required');
|
|
247
249
|
}
|
|
248
250
|
var OrmClientImpl = generateClient(cloud.callFunction.bind(cloud));
|
|
249
251
|
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
|
|
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,
|
|
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 (
|
|
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,30 +76,38 @@ 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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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));
|
|
71
93
|
|
|
72
94
|
var callDataSource = function (_a) {
|
|
73
95
|
var dataSourceName = _a.dataSourceName, methodName = _a.methodName, params = _a.params, realMethodName = _a.realMethodName, callFunction = _a.callFunction;
|
|
74
96
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
75
97
|
var result, response, error_1;
|
|
76
|
-
var _b;
|
|
77
|
-
return __generator(this, function (
|
|
78
|
-
switch (
|
|
98
|
+
var _b, _c;
|
|
99
|
+
return __generator(this, function (_d) {
|
|
100
|
+
switch (_d.label) {
|
|
79
101
|
case 0:
|
|
80
102
|
result = {
|
|
81
103
|
data: {},
|
|
82
|
-
|
|
104
|
+
requestId: ''
|
|
83
105
|
};
|
|
84
|
-
|
|
106
|
+
_d.label = 1;
|
|
85
107
|
case 1:
|
|
86
|
-
|
|
108
|
+
_d.trys.push([1, 3, , 4]);
|
|
87
109
|
return [4 /*yield*/, callFunction({
|
|
88
|
-
name:
|
|
110
|
+
name: 'lowcode-datasource',
|
|
89
111
|
data: {
|
|
90
112
|
dataSourceName: dataSourceName,
|
|
91
113
|
methodName: methodName,
|
|
@@ -93,32 +115,31 @@ var callDataSource = function (_a) {
|
|
|
93
115
|
}
|
|
94
116
|
})];
|
|
95
117
|
case 2:
|
|
96
|
-
response =
|
|
118
|
+
response = _d.sent();
|
|
97
119
|
if (response === null || response === void 0 ? void 0 : response.result.code) {
|
|
98
|
-
result.
|
|
120
|
+
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
121
|
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
122
|
requestId: response === null || response === void 0 ? void 0 : response.requestId
|
|
102
|
-
};
|
|
123
|
+
});
|
|
103
124
|
}
|
|
104
125
|
else {
|
|
105
126
|
result.data = ((_b = response === null || response === void 0 ? void 0 : response.result) === null || _b === void 0 ? void 0 : _b.data) || {};
|
|
127
|
+
result.requestId = ((_c = response === null || response === void 0 ? void 0 : response.result) === null || _c === void 0 ? void 0 : _c.requestId) || '';
|
|
106
128
|
}
|
|
107
129
|
return [3 /*break*/, 4];
|
|
108
130
|
case 3:
|
|
109
|
-
error_1 =
|
|
110
|
-
|
|
111
|
-
|
|
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);
|
|
131
|
+
error_1 = _d.sent();
|
|
132
|
+
if (error_1.name === 'WxCloudSDKError') {
|
|
133
|
+
throw error_1;
|
|
120
134
|
}
|
|
121
|
-
|
|
135
|
+
else {
|
|
136
|
+
console.log(error_1);
|
|
137
|
+
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"), {
|
|
138
|
+
code: 'UnknownError',
|
|
139
|
+
originError: error_1
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
case 4: return [2 /*return*/, result];
|
|
122
143
|
}
|
|
123
144
|
});
|
|
124
145
|
});
|
|
@@ -126,25 +147,25 @@ var callDataSource = function (_a) {
|
|
|
126
147
|
|
|
127
148
|
var CRUD_METHODS = {
|
|
128
149
|
create: {
|
|
129
|
-
methodName:
|
|
150
|
+
methodName: 'wedaCreateV2'
|
|
130
151
|
},
|
|
131
152
|
createMany: {
|
|
132
|
-
methodName:
|
|
153
|
+
methodName: 'wedaBatchCreateV2'
|
|
133
154
|
},
|
|
134
155
|
update: {
|
|
135
|
-
methodName:
|
|
156
|
+
methodName: 'wedaUpdateV2'
|
|
136
157
|
},
|
|
137
158
|
updateMany: {
|
|
138
|
-
methodName:
|
|
159
|
+
methodName: 'wedaBatchUpdateV2'
|
|
139
160
|
},
|
|
140
161
|
"delete": {
|
|
141
|
-
methodName:
|
|
162
|
+
methodName: 'wedaDeleteV2'
|
|
142
163
|
},
|
|
143
164
|
deleteMany: {
|
|
144
|
-
methodName:
|
|
165
|
+
methodName: 'wedaBatchDeleteV2'
|
|
145
166
|
},
|
|
146
167
|
get: {
|
|
147
|
-
methodName:
|
|
168
|
+
methodName: 'wedaGetItemV2',
|
|
148
169
|
defaultParams: {
|
|
149
170
|
filter: {
|
|
150
171
|
where: {}
|
|
@@ -155,7 +176,7 @@ var CRUD_METHODS = {
|
|
|
155
176
|
}
|
|
156
177
|
},
|
|
157
178
|
list: {
|
|
158
|
-
methodName:
|
|
179
|
+
methodName: 'wedaGetRecordsV2',
|
|
159
180
|
defaultParams: {
|
|
160
181
|
filter: {
|
|
161
182
|
where: {}
|
|
@@ -171,18 +192,13 @@ var generateClientByDataSourceName = function (dataSourceName, callFunction) {
|
|
|
171
192
|
get: function (target, methodName) {
|
|
172
193
|
var operation = CRUD_METHODS[methodName];
|
|
173
194
|
if (!operation) {
|
|
174
|
-
var error = new Error("\u4E0D\u652F\u6301\u7684\u64CD\u4F5C: "
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
message: error.message || "Unknown error occurred",
|
|
181
|
-
requestId: "N/A"
|
|
182
|
-
}
|
|
183
|
-
};
|
|
195
|
+
var error = new Error("\u4E0D\u652F\u6301\u7684\u64CD\u4F5C: ".concat(methodName));
|
|
196
|
+
throw new WxCloudSDKError(error.message || 'Unknown error occurred', {
|
|
197
|
+
originError: error,
|
|
198
|
+
code: 'NotSupported',
|
|
199
|
+
requestId: 'N/A'
|
|
200
|
+
});
|
|
184
201
|
}
|
|
185
|
-
console.group("[" + dataSourceName + "." + methodName + "]");
|
|
186
202
|
return function (params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
187
203
|
var effectiveParams, rawData, result, dataKey;
|
|
188
204
|
var _a;
|
|
@@ -190,13 +206,6 @@ var generateClientByDataSourceName = function (dataSourceName, callFunction) {
|
|
|
190
206
|
switch (_b.label) {
|
|
191
207
|
case 0:
|
|
192
208
|
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
209
|
return [4 /*yield*/, callDataSource({
|
|
201
210
|
callFunction: callFunction,
|
|
202
211
|
dataSourceName: dataSourceName,
|
|
@@ -206,16 +215,9 @@ var generateClientByDataSourceName = function (dataSourceName, callFunction) {
|
|
|
206
215
|
})];
|
|
207
216
|
case 1:
|
|
208
217
|
rawData = _b.sent();
|
|
209
|
-
result = {
|
|
210
|
-
|
|
211
|
-
|
|
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();
|
|
218
|
+
result = { data: {} };
|
|
219
|
+
dataKey = operation.responseKey;
|
|
220
|
+
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
221
|
return [2 /*return*/, result];
|
|
220
222
|
}
|
|
221
223
|
});
|
|
@@ -228,7 +230,7 @@ var generateClientByDataSourceName = function (dataSourceName, callFunction) {
|
|
|
228
230
|
var generateClient = function (callFunction) {
|
|
229
231
|
return new Proxy({}, {
|
|
230
232
|
get: function (target, prop) {
|
|
231
|
-
if (typeof prop ===
|
|
233
|
+
if (typeof prop === 'string') {
|
|
232
234
|
// 返回一个函数,这个函数接受任意参数并返回一个 Promise
|
|
233
235
|
return generateClientByDataSourceName(prop, callFunction);
|
|
234
236
|
}
|
|
@@ -238,10 +240,10 @@ var generateClient = function (callFunction) {
|
|
|
238
240
|
|
|
239
241
|
function init(cloud) {
|
|
240
242
|
if (!cloud) {
|
|
241
|
-
throw new Error(
|
|
243
|
+
throw new Error('cloud is required');
|
|
242
244
|
}
|
|
243
245
|
if (!cloud.callFunction) {
|
|
244
|
-
throw new Error(
|
|
246
|
+
throw new Error('cloud.callFunction is required');
|
|
245
247
|
}
|
|
246
248
|
var OrmClientImpl = generateClient(cloud.callFunction.bind(cloud));
|
|
247
249
|
cloud.models = OrmClientImpl;
|