@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.
@@ -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, SuppressedError, Symbol */
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, _arguments || [])).next());
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 (g && (g = 0, op[0] && (_ = 0)), _) try {
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,30 +82,38 @@
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
- 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
- };
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));
77
99
 
78
100
  var callDataSource = function (_a) {
79
101
  var dataSourceName = _a.dataSourceName, methodName = _a.methodName, params = _a.params, realMethodName = _a.realMethodName, callFunction = _a.callFunction;
80
102
  return __awaiter(void 0, void 0, void 0, function () {
81
103
  var result, response, error_1;
82
- var _b;
83
- return __generator(this, function (_c) {
84
- switch (_c.label) {
104
+ var _b, _c;
105
+ return __generator(this, function (_d) {
106
+ switch (_d.label) {
85
107
  case 0:
86
108
  result = {
87
109
  data: {},
88
- error: null
110
+ requestId: ''
89
111
  };
90
- _c.label = 1;
112
+ _d.label = 1;
91
113
  case 1:
92
- _c.trys.push([1, 3, , 4]);
114
+ _d.trys.push([1, 3, , 4]);
93
115
  return [4 /*yield*/, callFunction({
94
- name: "lowcode-datasource-preview",
116
+ name: 'lowcode-datasource',
95
117
  data: {
96
118
  dataSourceName: dataSourceName,
97
119
  methodName: methodName,
@@ -99,32 +121,31 @@
99
121
  }
100
122
  })];
101
123
  case 2:
102
- response = _c.sent();
124
+ response = _d.sent();
103
125
  if (response === null || response === void 0 ? void 0 : response.result.code) {
104
- result.error = {
126
+ 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
127
  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
128
  requestId: response === null || response === void 0 ? void 0 : response.requestId
108
- };
129
+ });
109
130
  }
110
131
  else {
111
132
  result.data = ((_b = response === null || response === void 0 ? void 0 : response.result) === null || _b === void 0 ? void 0 : _b.data) || {};
133
+ result.requestId = ((_c = response === null || response === void 0 ? void 0 : response.result) === null || _c === void 0 ? void 0 : _c.requestId) || '';
112
134
  }
113
135
  return [3 /*break*/, 4];
114
136
  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);
137
+ error_1 = _d.sent();
138
+ if (error_1.name === 'WxCloudSDKError') {
139
+ throw error_1;
126
140
  }
127
- return [2 /*return*/, result];
141
+ else {
142
+ console.log(error_1);
143
+ 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"), {
144
+ code: 'UnknownError',
145
+ originError: error_1
146
+ });
147
+ }
148
+ case 4: return [2 /*return*/, result];
128
149
  }
129
150
  });
130
151
  });
@@ -132,25 +153,25 @@
132
153
 
133
154
  var CRUD_METHODS = {
134
155
  create: {
135
- methodName: "wedaCreateV2"
156
+ methodName: 'wedaCreateV2'
136
157
  },
137
158
  createMany: {
138
- methodName: "wedaBatchCreateV2"
159
+ methodName: 'wedaBatchCreateV2'
139
160
  },
140
161
  update: {
141
- methodName: "wedaUpdateV2"
162
+ methodName: 'wedaUpdateV2'
142
163
  },
143
164
  updateMany: {
144
- methodName: "wedaBatchUpdateV2"
165
+ methodName: 'wedaBatchUpdateV2'
145
166
  },
146
167
  "delete": {
147
- methodName: "wedaDeleteV2"
168
+ methodName: 'wedaDeleteV2'
148
169
  },
149
170
  deleteMany: {
150
- methodName: "wedaBatchDeleteV2"
171
+ methodName: 'wedaBatchDeleteV2'
151
172
  },
152
173
  get: {
153
- methodName: "wedaGetItemV2",
174
+ methodName: 'wedaGetItemV2',
154
175
  defaultParams: {
155
176
  filter: {
156
177
  where: {}
@@ -161,7 +182,7 @@
161
182
  }
162
183
  },
163
184
  list: {
164
- methodName: "wedaGetRecordsV2",
185
+ methodName: 'wedaGetRecordsV2',
165
186
  defaultParams: {
166
187
  filter: {
167
188
  where: {}
@@ -177,18 +198,13 @@
177
198
  get: function (target, methodName) {
178
199
  var operation = CRUD_METHODS[methodName];
179
200
  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
- };
201
+ var error = new Error("\u4E0D\u652F\u6301\u7684\u64CD\u4F5C: ".concat(methodName));
202
+ throw new WxCloudSDKError(error.message || 'Unknown error occurred', {
203
+ originError: error,
204
+ code: 'NotSupported',
205
+ requestId: 'N/A'
206
+ });
190
207
  }
191
- console.group("[" + dataSourceName + "." + methodName + "]");
192
208
  return function (params) { return __awaiter(void 0, void 0, void 0, function () {
193
209
  var effectiveParams, rawData, result, dataKey;
194
210
  var _a;
@@ -196,13 +212,6 @@
196
212
  switch (_b.label) {
197
213
  case 0:
198
214
  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
215
  return [4 /*yield*/, callDataSource({
207
216
  callFunction: callFunction,
208
217
  dataSourceName: dataSourceName,
@@ -212,16 +221,9 @@
212
221
  })];
213
222
  case 1:
214
223
  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();
224
+ result = { data: {} };
225
+ dataKey = operation.responseKey;
226
+ 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
227
  return [2 /*return*/, result];
226
228
  }
227
229
  });
@@ -234,7 +236,7 @@
234
236
  var generateClient = function (callFunction) {
235
237
  return new Proxy({}, {
236
238
  get: function (target, prop) {
237
- if (typeof prop === "string") {
239
+ if (typeof prop === 'string') {
238
240
  // 返回一个函数,这个函数接受任意参数并返回一个 Promise
239
241
  return generateClientByDataSourceName(prop, callFunction);
240
242
  }
@@ -244,10 +246,10 @@
244
246
 
245
247
  function init(cloud) {
246
248
  if (!cloud) {
247
- throw new Error("cloud is required");
249
+ throw new Error('cloud is required');
248
250
  }
249
251
  if (!cloud.callFunction) {
250
- throw new Error("cloud.callFunction is required");
252
+ throw new Error('cloud.callFunction is required');
251
253
  }
252
254
  var OrmClientImpl = generateClient(cloud.callFunction.bind(cloud));
253
255
  cloud.models = OrmClientImpl;
package/package.json CHANGED
@@ -1,21 +1,23 @@
1
1
  {
2
2
  "name": "@cloudbase/wx-cloud-client-sdk",
3
- "version": "1.0.0-alpha.0",
3
+ "version": "1.0.0-alpha.2",
4
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",
5
+ "main": "lib/wxCloudClientSDK.cjs.js",
6
+ "module": "lib/wxCloudClientSDK.esm.js",
7
+ "browser": "lib/wxCloudClientSDK.umd.js",
8
+ "types": "lib/index.d.ts",
9
9
  "files": [
10
10
  "lib"
11
11
  ],
12
12
  "scripts": {
13
13
  "clean": "npx rimraf lib/*",
14
14
  "build": "npm run clean && rollup -c",
15
- "start-demo": "parcel demo/index.html",
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",
@@ -23,6 +25,8 @@
23
25
  "@rollup/plugin-typescript": "^11.1.6",
24
26
  "parcel-bundler": "1.6.1",
25
27
  "rollup": "^4.18.0",
28
+ "typedoc": "^0.25.13",
29
+ "typedoc-plugin-markdown": "^4.0.3",
26
30
  "typescript": "4.4.4"
27
31
  },
28
32
  "resolutions": {
@@ -32,4 +36,4 @@
32
36
  "typescript",
33
37
  "javascript"
34
38
  ]
35
- }
39
+ }
package/lib/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import { CloudBaseInstance, ExtendedCloudBaseInstance } from "./types";
2
- export declare function init(cloud: CloudBaseInstance): ExtendedCloudBaseInstance;
3
- export * from "./types";
@@ -1,130 +0,0 @@
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
- }