@cloudbase/wx-cloud-client-sdk 1.0.0-alpha.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 +2 -0
- package/lib/index.d.ts +3 -0
- package/lib/orm/orm-client.d.ts +3 -0
- package/lib/types/index.d.ts +130 -0
- package/lib/wxCloudCLientSDK.cjs.js +253 -0
- package/lib/wxCloudCLientSDK.esm.js +251 -0
- package/lib/wxCloudCLientSDK.umd.js +259 -0
- package/package.json +35 -0
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
export declare type DataModelFields<T> = {
|
|
2
|
+
[key: string]: T;
|
|
3
|
+
};
|
|
4
|
+
export declare type MethodResponse<T> = {
|
|
5
|
+
data: T;
|
|
6
|
+
error?: null | {
|
|
7
|
+
code: string;
|
|
8
|
+
message: string;
|
|
9
|
+
requestId: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export declare type CloudBaseInstance = {
|
|
13
|
+
callFunction: CallFunction;
|
|
14
|
+
auth: any;
|
|
15
|
+
};
|
|
16
|
+
export interface ExtendedCloudBaseInstance extends CloudBaseInstance {
|
|
17
|
+
models: OrmClient;
|
|
18
|
+
}
|
|
19
|
+
export declare type CallFunction = (args: {
|
|
20
|
+
name: string;
|
|
21
|
+
data: {
|
|
22
|
+
dataSourceName: string;
|
|
23
|
+
methodName: string;
|
|
24
|
+
params: Record<string, any>;
|
|
25
|
+
};
|
|
26
|
+
}) => Promise<any>;
|
|
27
|
+
export interface CallDataSourceParams {
|
|
28
|
+
dataSourceName: string;
|
|
29
|
+
methodName: string;
|
|
30
|
+
params: Record<string, any>;
|
|
31
|
+
realMethodName: string;
|
|
32
|
+
callFunction: CallFunction;
|
|
33
|
+
}
|
|
34
|
+
export declare type CreateResponse<T> = {
|
|
35
|
+
id: string;
|
|
36
|
+
};
|
|
37
|
+
export declare type CreateManyResponse<T> = {
|
|
38
|
+
idList: string[];
|
|
39
|
+
};
|
|
40
|
+
export declare type UpdateResponse<T> = {
|
|
41
|
+
count: number;
|
|
42
|
+
};
|
|
43
|
+
export declare type DeleteResponse<T> = UpdateResponse<T>;
|
|
44
|
+
export declare type GetResponse<T> = MethodResponse<T>;
|
|
45
|
+
export declare type ListResponse<T> = MethodResponse<{
|
|
46
|
+
records: T[];
|
|
47
|
+
total?: number;
|
|
48
|
+
}>;
|
|
49
|
+
export declare type OrderByParams = {
|
|
50
|
+
[key: string]: 'asc' | 'desc';
|
|
51
|
+
};
|
|
52
|
+
export declare type SelectParams<T> = {
|
|
53
|
+
[key in keyof T]?: boolean;
|
|
54
|
+
};
|
|
55
|
+
export declare type BasicComparisonOperator = '$eq' | '$neq' | '$gt' | '$gte' | '$lt' | '$lte' | '$in' | '$nin';
|
|
56
|
+
export declare type SpecialComparisonOperator = '$search' | '$nsearch' | '$empty' | '$nempty' | '$eq-current-user' | '$ne-current-user';
|
|
57
|
+
export declare type ComparisonOperator = BasicComparisonOperator | SpecialComparisonOperator;
|
|
58
|
+
export declare type FilterCondition = {
|
|
59
|
+
[key in ComparisonOperator]?: any;
|
|
60
|
+
};
|
|
61
|
+
export declare type FilterConditionItem<T> = {
|
|
62
|
+
[key in keyof T]?: FilterCondition;
|
|
63
|
+
};
|
|
64
|
+
export declare type LogicalOperator = '$and' | '$or';
|
|
65
|
+
export declare type FilterObject<T> = {
|
|
66
|
+
[operator in LogicalOperator]?: FilterConditionItem<T>[] | FilterObject<T>;
|
|
67
|
+
};
|
|
68
|
+
export declare type FilterParams<T> = {
|
|
69
|
+
where?: FilterObject<T>;
|
|
70
|
+
};
|
|
71
|
+
export declare type ListParams<T> = {
|
|
72
|
+
filter?: FilterParams<T>;
|
|
73
|
+
select?: SelectParams<T>;
|
|
74
|
+
getCount?: boolean;
|
|
75
|
+
pageSize?: number;
|
|
76
|
+
pageNumber?: number;
|
|
77
|
+
orderBy?: OrderByParams[];
|
|
78
|
+
relateWhere?: any;
|
|
79
|
+
};
|
|
80
|
+
export declare type Relation = string;
|
|
81
|
+
export interface Fields {
|
|
82
|
+
_id?: string;
|
|
83
|
+
createdAt?: Date;
|
|
84
|
+
updatedAt?: Date;
|
|
85
|
+
owner?: Relation;
|
|
86
|
+
createBy?: Relation;
|
|
87
|
+
updateBy?: Relation;
|
|
88
|
+
_departmentList?: Relation[];
|
|
89
|
+
_openid?: string;
|
|
90
|
+
}
|
|
91
|
+
export interface DataModelMethods<T> {
|
|
92
|
+
create: (params: {
|
|
93
|
+
data: T;
|
|
94
|
+
}) => Promise<MethodResponse<CreateResponse<T>>>;
|
|
95
|
+
createMany: (params: {
|
|
96
|
+
data: T[];
|
|
97
|
+
}) => Promise<MethodResponse<CreateManyResponse<T>>>;
|
|
98
|
+
update: (params: {
|
|
99
|
+
data: T;
|
|
100
|
+
filter: FilterParams<T>;
|
|
101
|
+
}) => Promise<MethodResponse<UpdateResponse<T>>>;
|
|
102
|
+
updateMany: (params: {
|
|
103
|
+
data: T;
|
|
104
|
+
filter: FilterParams<T>;
|
|
105
|
+
}) => Promise<MethodResponse<UpdateResponse<T>>>;
|
|
106
|
+
delete: (params: {
|
|
107
|
+
filter: FilterParams<T>;
|
|
108
|
+
}) => Promise<MethodResponse<DeleteResponse<T>>>;
|
|
109
|
+
deleteMany: (params: {
|
|
110
|
+
filter: FilterParams<T>;
|
|
111
|
+
}) => Promise<MethodResponse<DeleteResponse<T>>>;
|
|
112
|
+
get: (params: {
|
|
113
|
+
filter: FilterParams<T>;
|
|
114
|
+
select?: SelectParams<T>;
|
|
115
|
+
}) => Promise<MethodResponse<T>>;
|
|
116
|
+
list: (params: {
|
|
117
|
+
filter?: FilterParams<T>;
|
|
118
|
+
select?: SelectParams<T>;
|
|
119
|
+
getCount?: boolean;
|
|
120
|
+
pageSize?: number;
|
|
121
|
+
pageNumber?: number;
|
|
122
|
+
orderBy?: OrderByParams[];
|
|
123
|
+
}) => Promise<MethodResponse<{
|
|
124
|
+
records: T[];
|
|
125
|
+
total?: number;
|
|
126
|
+
}>>;
|
|
127
|
+
}
|
|
128
|
+
export interface OrmClient {
|
|
129
|
+
[modelName: string]: DataModelMethods<any>;
|
|
130
|
+
}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/******************************************************************************
|
|
4
|
+
Copyright (c) Microsoft Corporation.
|
|
5
|
+
|
|
6
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
7
|
+
purpose with or without fee is hereby granted.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
***************************************************************************** */
|
|
17
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
var __assign = function() {
|
|
21
|
+
__assign = Object.assign || function __assign(t) {
|
|
22
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
23
|
+
s = arguments[i];
|
|
24
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
25
|
+
}
|
|
26
|
+
return t;
|
|
27
|
+
};
|
|
28
|
+
return __assign.apply(this, arguments);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
32
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
33
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
34
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
35
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
36
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
37
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function __generator(thisArg, body) {
|
|
42
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
43
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
44
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
45
|
+
function step(op) {
|
|
46
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
47
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
48
|
+
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
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
50
|
+
switch (op[0]) {
|
|
51
|
+
case 0: case 1: t = op; break;
|
|
52
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
53
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
54
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
55
|
+
default:
|
|
56
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
57
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
58
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
59
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
60
|
+
if (t[2]) _.ops.pop();
|
|
61
|
+
_.trys.pop(); continue;
|
|
62
|
+
}
|
|
63
|
+
op = body.call(thisArg, _);
|
|
64
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
65
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
66
|
+
}
|
|
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
|
+
};
|
|
73
|
+
|
|
74
|
+
var callDataSource = function (_a) {
|
|
75
|
+
var dataSourceName = _a.dataSourceName, methodName = _a.methodName, params = _a.params, realMethodName = _a.realMethodName, callFunction = _a.callFunction;
|
|
76
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
77
|
+
var result, response, error_1;
|
|
78
|
+
var _b;
|
|
79
|
+
return __generator(this, function (_c) {
|
|
80
|
+
switch (_c.label) {
|
|
81
|
+
case 0:
|
|
82
|
+
result = {
|
|
83
|
+
data: {},
|
|
84
|
+
error: null
|
|
85
|
+
};
|
|
86
|
+
_c.label = 1;
|
|
87
|
+
case 1:
|
|
88
|
+
_c.trys.push([1, 3, , 4]);
|
|
89
|
+
return [4 /*yield*/, callFunction({
|
|
90
|
+
name: "lowcode-datasource-preview",
|
|
91
|
+
data: {
|
|
92
|
+
dataSourceName: dataSourceName,
|
|
93
|
+
methodName: methodName,
|
|
94
|
+
params: params
|
|
95
|
+
}
|
|
96
|
+
})];
|
|
97
|
+
case 2:
|
|
98
|
+
response = _c.sent();
|
|
99
|
+
if (response === null || response === void 0 ? void 0 : response.result.code) {
|
|
100
|
+
result.error = {
|
|
101
|
+
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
|
+
requestId: response === null || response === void 0 ? void 0 : response.requestId
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
result.data = ((_b = response === null || response === void 0 ? void 0 : response.result) === null || _b === void 0 ? void 0 : _b.data) || {};
|
|
108
|
+
}
|
|
109
|
+
return [3 /*break*/, 4];
|
|
110
|
+
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);
|
|
122
|
+
}
|
|
123
|
+
return [2 /*return*/, result];
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
var CRUD_METHODS = {
|
|
130
|
+
create: {
|
|
131
|
+
methodName: "wedaCreateV2"
|
|
132
|
+
},
|
|
133
|
+
createMany: {
|
|
134
|
+
methodName: "wedaBatchCreateV2"
|
|
135
|
+
},
|
|
136
|
+
update: {
|
|
137
|
+
methodName: "wedaUpdateV2"
|
|
138
|
+
},
|
|
139
|
+
updateMany: {
|
|
140
|
+
methodName: "wedaBatchUpdateV2"
|
|
141
|
+
},
|
|
142
|
+
"delete": {
|
|
143
|
+
methodName: "wedaDeleteV2"
|
|
144
|
+
},
|
|
145
|
+
deleteMany: {
|
|
146
|
+
methodName: "wedaBatchDeleteV2"
|
|
147
|
+
},
|
|
148
|
+
get: {
|
|
149
|
+
methodName: "wedaGetItemV2",
|
|
150
|
+
defaultParams: {
|
|
151
|
+
filter: {
|
|
152
|
+
where: {}
|
|
153
|
+
},
|
|
154
|
+
select: {
|
|
155
|
+
$master: true
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
list: {
|
|
160
|
+
methodName: "wedaGetRecordsV2",
|
|
161
|
+
defaultParams: {
|
|
162
|
+
filter: {
|
|
163
|
+
where: {}
|
|
164
|
+
},
|
|
165
|
+
select: {
|
|
166
|
+
$master: true
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
var generateClientByDataSourceName = function (dataSourceName, callFunction) {
|
|
172
|
+
var client = new Proxy({}, {
|
|
173
|
+
get: function (target, methodName) {
|
|
174
|
+
var operation = CRUD_METHODS[methodName];
|
|
175
|
+
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
|
+
};
|
|
186
|
+
}
|
|
187
|
+
console.group("[" + dataSourceName + "." + methodName + "]");
|
|
188
|
+
return function (params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
189
|
+
var effectiveParams, rawData, result, dataKey;
|
|
190
|
+
var _a;
|
|
191
|
+
return __generator(this, function (_b) {
|
|
192
|
+
switch (_b.label) {
|
|
193
|
+
case 0:
|
|
194
|
+
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
|
+
return [4 /*yield*/, callDataSource({
|
|
203
|
+
callFunction: callFunction,
|
|
204
|
+
dataSourceName: dataSourceName,
|
|
205
|
+
methodName: operation.methodName,
|
|
206
|
+
realMethodName: methodName,
|
|
207
|
+
params: effectiveParams
|
|
208
|
+
})];
|
|
209
|
+
case 1:
|
|
210
|
+
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();
|
|
221
|
+
return [2 /*return*/, result];
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
}); };
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
return client;
|
|
228
|
+
};
|
|
229
|
+
// 使用 TypeScript 的 Proxy 来定义一个动态的客户端
|
|
230
|
+
var generateClient = function (callFunction) {
|
|
231
|
+
return new Proxy({}, {
|
|
232
|
+
get: function (target, prop) {
|
|
233
|
+
if (typeof prop === "string") {
|
|
234
|
+
// 返回一个函数,这个函数接受任意参数并返回一个 Promise
|
|
235
|
+
return generateClientByDataSourceName(prop, callFunction);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
function init(cloud) {
|
|
242
|
+
if (!cloud) {
|
|
243
|
+
throw new Error("cloud is required");
|
|
244
|
+
}
|
|
245
|
+
if (!cloud.callFunction) {
|
|
246
|
+
throw new Error("cloud.callFunction is required");
|
|
247
|
+
}
|
|
248
|
+
var OrmClientImpl = generateClient(cloud.callFunction.bind(cloud));
|
|
249
|
+
cloud.models = OrmClientImpl;
|
|
250
|
+
return cloud;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
exports.init = init;
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
/******************************************************************************
|
|
2
|
+
Copyright (c) Microsoft Corporation.
|
|
3
|
+
|
|
4
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
+
purpose with or without fee is hereby granted.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
9
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
11
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
12
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
14
|
+
***************************************************************************** */
|
|
15
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
var __assign = function() {
|
|
19
|
+
__assign = Object.assign || function __assign(t) {
|
|
20
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
21
|
+
s = arguments[i];
|
|
22
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
30
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
31
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
32
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
33
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
34
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
35
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function __generator(thisArg, body) {
|
|
40
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
41
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
42
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
43
|
+
function step(op) {
|
|
44
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
45
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
46
|
+
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
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
48
|
+
switch (op[0]) {
|
|
49
|
+
case 0: case 1: t = op; break;
|
|
50
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
51
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
52
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
53
|
+
default:
|
|
54
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
55
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
56
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
57
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
58
|
+
if (t[2]) _.ops.pop();
|
|
59
|
+
_.trys.pop(); continue;
|
|
60
|
+
}
|
|
61
|
+
op = body.call(thisArg, _);
|
|
62
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
63
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
64
|
+
}
|
|
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
|
+
};
|
|
71
|
+
|
|
72
|
+
var callDataSource = function (_a) {
|
|
73
|
+
var dataSourceName = _a.dataSourceName, methodName = _a.methodName, params = _a.params, realMethodName = _a.realMethodName, callFunction = _a.callFunction;
|
|
74
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
75
|
+
var result, response, error_1;
|
|
76
|
+
var _b;
|
|
77
|
+
return __generator(this, function (_c) {
|
|
78
|
+
switch (_c.label) {
|
|
79
|
+
case 0:
|
|
80
|
+
result = {
|
|
81
|
+
data: {},
|
|
82
|
+
error: null
|
|
83
|
+
};
|
|
84
|
+
_c.label = 1;
|
|
85
|
+
case 1:
|
|
86
|
+
_c.trys.push([1, 3, , 4]);
|
|
87
|
+
return [4 /*yield*/, callFunction({
|
|
88
|
+
name: "lowcode-datasource-preview",
|
|
89
|
+
data: {
|
|
90
|
+
dataSourceName: dataSourceName,
|
|
91
|
+
methodName: methodName,
|
|
92
|
+
params: params
|
|
93
|
+
}
|
|
94
|
+
})];
|
|
95
|
+
case 2:
|
|
96
|
+
response = _c.sent();
|
|
97
|
+
if (response === null || response === void 0 ? void 0 : response.result.code) {
|
|
98
|
+
result.error = {
|
|
99
|
+
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
|
+
requestId: response === null || response === void 0 ? void 0 : response.requestId
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
result.data = ((_b = response === null || response === void 0 ? void 0 : response.result) === null || _b === void 0 ? void 0 : _b.data) || {};
|
|
106
|
+
}
|
|
107
|
+
return [3 /*break*/, 4];
|
|
108
|
+
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);
|
|
120
|
+
}
|
|
121
|
+
return [2 /*return*/, result];
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
var CRUD_METHODS = {
|
|
128
|
+
create: {
|
|
129
|
+
methodName: "wedaCreateV2"
|
|
130
|
+
},
|
|
131
|
+
createMany: {
|
|
132
|
+
methodName: "wedaBatchCreateV2"
|
|
133
|
+
},
|
|
134
|
+
update: {
|
|
135
|
+
methodName: "wedaUpdateV2"
|
|
136
|
+
},
|
|
137
|
+
updateMany: {
|
|
138
|
+
methodName: "wedaBatchUpdateV2"
|
|
139
|
+
},
|
|
140
|
+
"delete": {
|
|
141
|
+
methodName: "wedaDeleteV2"
|
|
142
|
+
},
|
|
143
|
+
deleteMany: {
|
|
144
|
+
methodName: "wedaBatchDeleteV2"
|
|
145
|
+
},
|
|
146
|
+
get: {
|
|
147
|
+
methodName: "wedaGetItemV2",
|
|
148
|
+
defaultParams: {
|
|
149
|
+
filter: {
|
|
150
|
+
where: {}
|
|
151
|
+
},
|
|
152
|
+
select: {
|
|
153
|
+
$master: true
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
list: {
|
|
158
|
+
methodName: "wedaGetRecordsV2",
|
|
159
|
+
defaultParams: {
|
|
160
|
+
filter: {
|
|
161
|
+
where: {}
|
|
162
|
+
},
|
|
163
|
+
select: {
|
|
164
|
+
$master: true
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
var generateClientByDataSourceName = function (dataSourceName, callFunction) {
|
|
170
|
+
var client = new Proxy({}, {
|
|
171
|
+
get: function (target, methodName) {
|
|
172
|
+
var operation = CRUD_METHODS[methodName];
|
|
173
|
+
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
|
+
};
|
|
184
|
+
}
|
|
185
|
+
console.group("[" + dataSourceName + "." + methodName + "]");
|
|
186
|
+
return function (params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
187
|
+
var effectiveParams, rawData, result, dataKey;
|
|
188
|
+
var _a;
|
|
189
|
+
return __generator(this, function (_b) {
|
|
190
|
+
switch (_b.label) {
|
|
191
|
+
case 0:
|
|
192
|
+
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
|
+
return [4 /*yield*/, callDataSource({
|
|
201
|
+
callFunction: callFunction,
|
|
202
|
+
dataSourceName: dataSourceName,
|
|
203
|
+
methodName: operation.methodName,
|
|
204
|
+
realMethodName: methodName,
|
|
205
|
+
params: effectiveParams
|
|
206
|
+
})];
|
|
207
|
+
case 1:
|
|
208
|
+
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();
|
|
219
|
+
return [2 /*return*/, result];
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}); };
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
return client;
|
|
226
|
+
};
|
|
227
|
+
// 使用 TypeScript 的 Proxy 来定义一个动态的客户端
|
|
228
|
+
var generateClient = function (callFunction) {
|
|
229
|
+
return new Proxy({}, {
|
|
230
|
+
get: function (target, prop) {
|
|
231
|
+
if (typeof prop === "string") {
|
|
232
|
+
// 返回一个函数,这个函数接受任意参数并返回一个 Promise
|
|
233
|
+
return generateClientByDataSourceName(prop, callFunction);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
function init(cloud) {
|
|
240
|
+
if (!cloud) {
|
|
241
|
+
throw new Error("cloud is required");
|
|
242
|
+
}
|
|
243
|
+
if (!cloud.callFunction) {
|
|
244
|
+
throw new Error("cloud.callFunction is required");
|
|
245
|
+
}
|
|
246
|
+
var OrmClientImpl = generateClient(cloud.callFunction.bind(cloud));
|
|
247
|
+
cloud.models = OrmClientImpl;
|
|
248
|
+
return cloud;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export { init };
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.wxCloudClientSDK = {}));
|
|
5
|
+
})(this, (function (exports) { 'use strict';
|
|
6
|
+
|
|
7
|
+
/******************************************************************************
|
|
8
|
+
Copyright (c) Microsoft Corporation.
|
|
9
|
+
|
|
10
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
11
|
+
purpose with or without fee is hereby granted.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
14
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
15
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
16
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
17
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
18
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
19
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
20
|
+
***************************************************************************** */
|
|
21
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
var __assign = function() {
|
|
25
|
+
__assign = Object.assign || function __assign(t) {
|
|
26
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
27
|
+
s = arguments[i];
|
|
28
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
29
|
+
}
|
|
30
|
+
return t;
|
|
31
|
+
};
|
|
32
|
+
return __assign.apply(this, arguments);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function __generator(thisArg, body) {
|
|
46
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
47
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
48
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
49
|
+
function step(op) {
|
|
50
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
51
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
52
|
+
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
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
54
|
+
switch (op[0]) {
|
|
55
|
+
case 0: case 1: t = op; break;
|
|
56
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
57
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
58
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
59
|
+
default:
|
|
60
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
61
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
62
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
63
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
64
|
+
if (t[2]) _.ops.pop();
|
|
65
|
+
_.trys.pop(); continue;
|
|
66
|
+
}
|
|
67
|
+
op = body.call(thisArg, _);
|
|
68
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
69
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
74
|
+
var e = new Error(message);
|
|
75
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
var callDataSource = function (_a) {
|
|
79
|
+
var dataSourceName = _a.dataSourceName, methodName = _a.methodName, params = _a.params, realMethodName = _a.realMethodName, callFunction = _a.callFunction;
|
|
80
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
81
|
+
var result, response, error_1;
|
|
82
|
+
var _b;
|
|
83
|
+
return __generator(this, function (_c) {
|
|
84
|
+
switch (_c.label) {
|
|
85
|
+
case 0:
|
|
86
|
+
result = {
|
|
87
|
+
data: {},
|
|
88
|
+
error: null
|
|
89
|
+
};
|
|
90
|
+
_c.label = 1;
|
|
91
|
+
case 1:
|
|
92
|
+
_c.trys.push([1, 3, , 4]);
|
|
93
|
+
return [4 /*yield*/, callFunction({
|
|
94
|
+
name: "lowcode-datasource-preview",
|
|
95
|
+
data: {
|
|
96
|
+
dataSourceName: dataSourceName,
|
|
97
|
+
methodName: methodName,
|
|
98
|
+
params: params
|
|
99
|
+
}
|
|
100
|
+
})];
|
|
101
|
+
case 2:
|
|
102
|
+
response = _c.sent();
|
|
103
|
+
if (response === null || response === void 0 ? void 0 : response.result.code) {
|
|
104
|
+
result.error = {
|
|
105
|
+
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
|
+
requestId: response === null || response === void 0 ? void 0 : response.requestId
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
result.data = ((_b = response === null || response === void 0 ? void 0 : response.result) === null || _b === void 0 ? void 0 : _b.data) || {};
|
|
112
|
+
}
|
|
113
|
+
return [3 /*break*/, 4];
|
|
114
|
+
case 3:
|
|
115
|
+
error_1 = _c.sent();
|
|
116
|
+
console.error(error_1);
|
|
117
|
+
result.error = {
|
|
118
|
+
code: 'InternalError',
|
|
119
|
+
message: error_1.message || 'Unknown error occurred',
|
|
120
|
+
requestId: 'N/A'
|
|
121
|
+
};
|
|
122
|
+
return [3 /*break*/, 4];
|
|
123
|
+
case 4:
|
|
124
|
+
if (result.error) {
|
|
125
|
+
console.error(result.error);
|
|
126
|
+
}
|
|
127
|
+
return [2 /*return*/, result];
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
var CRUD_METHODS = {
|
|
134
|
+
create: {
|
|
135
|
+
methodName: "wedaCreateV2"
|
|
136
|
+
},
|
|
137
|
+
createMany: {
|
|
138
|
+
methodName: "wedaBatchCreateV2"
|
|
139
|
+
},
|
|
140
|
+
update: {
|
|
141
|
+
methodName: "wedaUpdateV2"
|
|
142
|
+
},
|
|
143
|
+
updateMany: {
|
|
144
|
+
methodName: "wedaBatchUpdateV2"
|
|
145
|
+
},
|
|
146
|
+
"delete": {
|
|
147
|
+
methodName: "wedaDeleteV2"
|
|
148
|
+
},
|
|
149
|
+
deleteMany: {
|
|
150
|
+
methodName: "wedaBatchDeleteV2"
|
|
151
|
+
},
|
|
152
|
+
get: {
|
|
153
|
+
methodName: "wedaGetItemV2",
|
|
154
|
+
defaultParams: {
|
|
155
|
+
filter: {
|
|
156
|
+
where: {}
|
|
157
|
+
},
|
|
158
|
+
select: {
|
|
159
|
+
$master: true
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
list: {
|
|
164
|
+
methodName: "wedaGetRecordsV2",
|
|
165
|
+
defaultParams: {
|
|
166
|
+
filter: {
|
|
167
|
+
where: {}
|
|
168
|
+
},
|
|
169
|
+
select: {
|
|
170
|
+
$master: true
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
var generateClientByDataSourceName = function (dataSourceName, callFunction) {
|
|
176
|
+
var client = new Proxy({}, {
|
|
177
|
+
get: function (target, methodName) {
|
|
178
|
+
var operation = CRUD_METHODS[methodName];
|
|
179
|
+
if (!operation) {
|
|
180
|
+
var error = new Error("\u4E0D\u652F\u6301\u7684\u64CD\u4F5C: " + methodName);
|
|
181
|
+
console.error(error);
|
|
182
|
+
return {
|
|
183
|
+
data: {},
|
|
184
|
+
error: {
|
|
185
|
+
code: "InternalError",
|
|
186
|
+
message: error.message || "Unknown error occurred",
|
|
187
|
+
requestId: "N/A"
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
console.group("[" + dataSourceName + "." + methodName + "]");
|
|
192
|
+
return function (params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
193
|
+
var effectiveParams, rawData, result, dataKey;
|
|
194
|
+
var _a;
|
|
195
|
+
return __generator(this, function (_b) {
|
|
196
|
+
switch (_b.label) {
|
|
197
|
+
case 0:
|
|
198
|
+
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
|
+
return [4 /*yield*/, callDataSource({
|
|
207
|
+
callFunction: callFunction,
|
|
208
|
+
dataSourceName: dataSourceName,
|
|
209
|
+
methodName: operation.methodName,
|
|
210
|
+
realMethodName: methodName,
|
|
211
|
+
params: effectiveParams
|
|
212
|
+
})];
|
|
213
|
+
case 1:
|
|
214
|
+
rawData = _b.sent();
|
|
215
|
+
result = { error: null, data: {} };
|
|
216
|
+
if (!rawData.error) {
|
|
217
|
+
dataKey = operation.responseKey;
|
|
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();
|
|
225
|
+
return [2 /*return*/, result];
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}); };
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
return client;
|
|
232
|
+
};
|
|
233
|
+
// 使用 TypeScript 的 Proxy 来定义一个动态的客户端
|
|
234
|
+
var generateClient = function (callFunction) {
|
|
235
|
+
return new Proxy({}, {
|
|
236
|
+
get: function (target, prop) {
|
|
237
|
+
if (typeof prop === "string") {
|
|
238
|
+
// 返回一个函数,这个函数接受任意参数并返回一个 Promise
|
|
239
|
+
return generateClientByDataSourceName(prop, callFunction);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
function init(cloud) {
|
|
246
|
+
if (!cloud) {
|
|
247
|
+
throw new Error("cloud is required");
|
|
248
|
+
}
|
|
249
|
+
if (!cloud.callFunction) {
|
|
250
|
+
throw new Error("cloud.callFunction is required");
|
|
251
|
+
}
|
|
252
|
+
var OrmClientImpl = generateClient(cloud.callFunction.bind(cloud));
|
|
253
|
+
cloud.models = OrmClientImpl;
|
|
254
|
+
return cloud;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
exports.init = init;
|
|
258
|
+
|
|
259
|
+
}));
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cloudbase/wx-cloud-client-sdk",
|
|
3
|
+
"version": "1.0.0-alpha.0",
|
|
4
|
+
"description": "wx cloud client sdk",
|
|
5
|
+
"main": "lib/wxCloudCLientSDK.cjs.js",
|
|
6
|
+
"module": "lib/wxCloudCLientSDK.esm.js",
|
|
7
|
+
"browser": "lib/wxCloudCLientSDK.umd.js",
|
|
8
|
+
"types": "lib/types/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"lib"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"clean": "npx rimraf lib/*",
|
|
14
|
+
"build": "npm run clean && rollup -c",
|
|
15
|
+
"start-demo": "parcel demo/index.html",
|
|
16
|
+
"build-demo": "npx rimraf dist/* && parcel build demo/index.html --public-url ./",
|
|
17
|
+
"publish": "npm publish --access public",
|
|
18
|
+
"publish-demo": "tcb hosting deploy dist wx-cloud-client-sdk-demo -e lowcode-4gs26nnz095f6f4d"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@rollup/plugin-commonjs": "^25.0.8",
|
|
22
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
23
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
24
|
+
"parcel-bundler": "1.6.1",
|
|
25
|
+
"rollup": "^4.18.0",
|
|
26
|
+
"typescript": "4.4.4"
|
|
27
|
+
},
|
|
28
|
+
"resolutions": {
|
|
29
|
+
"@babel/preset-env": "7.13.8"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"typescript",
|
|
33
|
+
"javascript"
|
|
34
|
+
]
|
|
35
|
+
}
|