@cloudbase/wx-cloud-client-sdk 1.5.0 → 1.6.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/index.d.ts +4 -1
- package/lib/orm/http-orm-client.d.ts +1 -4
- package/lib/types/index.d.ts +3 -1
- package/lib/wxCloudClientSDK.cjs.js +48 -105
- package/lib/wxCloudClientSDK.esm.js +48 -105
- package/lib/wxCloudClientSDK.umd.js +48 -105
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { CloudBaseInstance, ExtendedCloudBaseInstance } from './types';
|
|
2
2
|
import { generateHTTPClient } from './orm/http-orm-client';
|
|
3
|
-
export declare function init(cloud: CloudBaseInstance
|
|
3
|
+
export declare function init(cloud: CloudBaseInstance, options?: {
|
|
4
|
+
baseUrl?: string;
|
|
5
|
+
sqlBaseUrl?: string;
|
|
6
|
+
}): ExtendedCloudBaseInstance;
|
|
4
7
|
export * from './types';
|
|
5
8
|
export { generateHTTPClient };
|
|
6
9
|
declare const _default: {
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { OrmClient, CallFunction } from '../types';
|
|
3
|
-
type ModelFetch = NonNullable<SDKRequestInterface['fetch']>;
|
|
1
|
+
import { OrmClient, CallFunction, ModelFetch } from '../types';
|
|
4
2
|
export declare const enum EQUERY_PARAM_TYPE {
|
|
5
3
|
ARRAY = "ARRAY",
|
|
6
4
|
BOOLEAN = "BOOLEAN",
|
|
@@ -11,4 +9,3 @@ export declare const enum EQUERY_PARAM_TYPE {
|
|
|
11
9
|
export declare const generateHTTPClient: (callFunction: CallFunction, fetch: ModelFetch, baseUrl: string, options?: {
|
|
12
10
|
sqlBaseUrl?: string;
|
|
13
11
|
}) => OrmClient;
|
|
14
|
-
export {};
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SDKRequestInterface } from '@cloudbase/adapter-interface';
|
|
1
2
|
/**
|
|
2
3
|
* 基础 Model 类型定义
|
|
3
4
|
*/
|
|
@@ -289,7 +290,7 @@ export interface DataModelMethods<T> {
|
|
|
289
290
|
* @param {Object} params - 包含模板名、模板参数、环境类型的参数对象。
|
|
290
291
|
* @returns {Promise<MethodResponse<unknown>>} 包含记录列表和总数的Promise对象。
|
|
291
292
|
*/
|
|
292
|
-
runSQLTemplate
|
|
293
|
+
runSQLTemplate: (params: {
|
|
293
294
|
/**
|
|
294
295
|
* 模板名称
|
|
295
296
|
*/
|
|
@@ -725,4 +726,5 @@ export type CallFunction = (args: {
|
|
|
725
726
|
name: string;
|
|
726
727
|
data: Record<string, any>;
|
|
727
728
|
}) => Promise<any>;
|
|
729
|
+
export type ModelFetch = NonNullable<SDKRequestInterface['fetch']>;
|
|
728
730
|
export {};
|
|
@@ -145,7 +145,7 @@ function getUserAgent() {
|
|
|
145
145
|
return ua_1;
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
|
-
var VERSION = "1.
|
|
148
|
+
var VERSION = "1.6.0";
|
|
149
149
|
|
|
150
150
|
var callDataSource = function (_a) {
|
|
151
151
|
var dataSourceName = _a.dataSourceName, methodName = _a.methodName, params = _a.params, realMethodName = _a.realMethodName, callFunction = _a.callFunction, _b = _a.envType, envType = _b === void 0 ? 'prod' : _b, mode = _a.mode;
|
|
@@ -306,107 +306,6 @@ var createRawQueryClient = function (callFunction) { return ({
|
|
|
306
306
|
}
|
|
307
307
|
}); };
|
|
308
308
|
|
|
309
|
-
var CRUD_METHODS = {
|
|
310
|
-
create: {
|
|
311
|
-
methodName: 'wedaCreateV2'
|
|
312
|
-
},
|
|
313
|
-
createMany: {
|
|
314
|
-
methodName: 'wedaBatchCreateV2'
|
|
315
|
-
},
|
|
316
|
-
update: {
|
|
317
|
-
methodName: 'wedaUpdateV2'
|
|
318
|
-
},
|
|
319
|
-
upsert: {
|
|
320
|
-
methodName: 'wedaUpsertV2'
|
|
321
|
-
},
|
|
322
|
-
updateMany: {
|
|
323
|
-
methodName: 'wedaBatchUpdateV2'
|
|
324
|
-
},
|
|
325
|
-
"delete": {
|
|
326
|
-
methodName: 'wedaDeleteV2'
|
|
327
|
-
},
|
|
328
|
-
deleteMany: {
|
|
329
|
-
methodName: 'wedaBatchDeleteV2'
|
|
330
|
-
},
|
|
331
|
-
get: {
|
|
332
|
-
methodName: 'wedaGetItemV2',
|
|
333
|
-
defaultParams: {
|
|
334
|
-
filter: {
|
|
335
|
-
where: {}
|
|
336
|
-
},
|
|
337
|
-
select: {
|
|
338
|
-
$master: true
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
},
|
|
342
|
-
list: {
|
|
343
|
-
methodName: 'wedaGetRecordsV2',
|
|
344
|
-
defaultParams: {
|
|
345
|
-
filter: {
|
|
346
|
-
where: {}
|
|
347
|
-
},
|
|
348
|
-
select: {
|
|
349
|
-
$master: true
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
};
|
|
354
|
-
var generateClientByDataSourceName = function (dataSourceName, callFunction) {
|
|
355
|
-
var client = new Proxy({}, {
|
|
356
|
-
get: function (target, methodName) {
|
|
357
|
-
var operation = CRUD_METHODS[methodName];
|
|
358
|
-
if (!operation) {
|
|
359
|
-
var error = new Error("\u4E0D\u652F\u6301\u7684\u64CD\u4F5C: ".concat(methodName));
|
|
360
|
-
throw new WxCloudSDKError(error.message || 'Unknown error occurred', {
|
|
361
|
-
originError: error,
|
|
362
|
-
code: 'NotSupported',
|
|
363
|
-
requestId: 'N/A'
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
return function (params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
367
|
-
var effectiveParams, rawData, result, dataKey;
|
|
368
|
-
var _a;
|
|
369
|
-
return __generator(this, function (_b) {
|
|
370
|
-
switch (_b.label) {
|
|
371
|
-
case 0:
|
|
372
|
-
effectiveParams = __assign(__assign({}, (operation.defaultParams || {})), (params || {}));
|
|
373
|
-
return [4 /*yield*/, callDataSource({
|
|
374
|
-
callFunction: callFunction,
|
|
375
|
-
dataSourceName: dataSourceName,
|
|
376
|
-
methodName: operation.methodName,
|
|
377
|
-
realMethodName: methodName,
|
|
378
|
-
params: effectiveParams,
|
|
379
|
-
envType: params === null || params === void 0 ? void 0 : params.envType
|
|
380
|
-
})];
|
|
381
|
-
case 1:
|
|
382
|
-
rawData = _b.sent();
|
|
383
|
-
result = { data: {} };
|
|
384
|
-
dataKey = operation.responseKey;
|
|
385
|
-
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;
|
|
386
|
-
return [2 /*return*/, result];
|
|
387
|
-
}
|
|
388
|
-
});
|
|
389
|
-
}); };
|
|
390
|
-
}
|
|
391
|
-
});
|
|
392
|
-
return client;
|
|
393
|
-
};
|
|
394
|
-
// 使用 TypeScript 的 Proxy 来定义一个动态的客户端
|
|
395
|
-
var generateClient = function (callFunction) {
|
|
396
|
-
var rawQueryClient = createRawQueryClient(callFunction);
|
|
397
|
-
return new Proxy({}, {
|
|
398
|
-
get: function (target, prop) {
|
|
399
|
-
if (typeof prop === 'string') {
|
|
400
|
-
if (Object.prototype.hasOwnProperty.call(rawQueryClient, prop)) {
|
|
401
|
-
return rawQueryClient[prop];
|
|
402
|
-
}
|
|
403
|
-
// 返回一个函数,这个函数接受任意参数并返回一个 Promise
|
|
404
|
-
return generateClientByDataSourceName(prop, callFunction);
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
});
|
|
408
|
-
};
|
|
409
|
-
|
|
410
309
|
var READ_DEFAULT_PARAMS = {
|
|
411
310
|
filter: {
|
|
412
311
|
where: {}
|
|
@@ -591,17 +490,61 @@ var generateHTTPClientByDataSourceName = function (baseUrl, modelName, fetch, op
|
|
|
591
490
|
return client;
|
|
592
491
|
};
|
|
593
492
|
|
|
594
|
-
function init(cloud) {
|
|
493
|
+
function init(cloud, options) {
|
|
494
|
+
var _this = this;
|
|
595
495
|
if (!cloud) {
|
|
596
496
|
throw new Error('cloud is required');
|
|
597
497
|
}
|
|
598
498
|
if (!cloud.callFunction) {
|
|
599
499
|
throw new Error('cloud.callFunction is required');
|
|
600
500
|
}
|
|
601
|
-
var
|
|
602
|
-
|
|
501
|
+
var callFunction = cloud.callFunction.bind(cloud);
|
|
502
|
+
var HTTPOverCallFunctionFetch = function (_a) {
|
|
503
|
+
var url = _a.url, body = _a.body, method = _a.method, headers = _a.headers;
|
|
504
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
505
|
+
var res, result;
|
|
506
|
+
var _b;
|
|
507
|
+
return __generator(this, function (_c) {
|
|
508
|
+
switch (_c.label) {
|
|
509
|
+
case 0: return [4 /*yield*/, callFunction({
|
|
510
|
+
name: 'httpOverCallFunction',
|
|
511
|
+
data: {
|
|
512
|
+
url: url,
|
|
513
|
+
method: method === null || method === void 0 ? void 0 : method.toUpperCase(),
|
|
514
|
+
headers: __assign(__assign({}, (headers || {})), { 'Content-Type': 'application/json' }),
|
|
515
|
+
body: body
|
|
516
|
+
}
|
|
517
|
+
})];
|
|
518
|
+
case 1:
|
|
519
|
+
res = _c.sent();
|
|
520
|
+
result = (_b = res === null || res === void 0 ? void 0 : res.result) === null || _b === void 0 ? void 0 : _b.body;
|
|
521
|
+
return [2 /*return*/, result];
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
});
|
|
525
|
+
};
|
|
526
|
+
var baseUrl = (options === null || options === void 0 ? void 0 : options.baseUrl) || getDefaultGatewayBaseUrl(cloud).model;
|
|
527
|
+
var sqlBaseUrl = (options === null || options === void 0 ? void 0 : options.sqlBaseUrl) || getDefaultGatewayBaseUrl(cloud).sql;
|
|
528
|
+
var httpOrmClientImpl = generateHTTPClient(callFunction, HTTPOverCallFunctionFetch, baseUrl, {
|
|
529
|
+
sqlBaseUrl: sqlBaseUrl
|
|
530
|
+
});
|
|
531
|
+
cloud.models = httpOrmClientImpl;
|
|
603
532
|
return cloud;
|
|
604
533
|
}
|
|
534
|
+
function getDefaultGatewayBaseUrl(cloud) {
|
|
535
|
+
var _a, _b, _c;
|
|
536
|
+
var env = (_b = (_a = cloud === null || cloud === void 0 ? void 0 : cloud.extend) === null || _a === void 0 ? void 0 : _a.AI) === null || _b === void 0 ? void 0 : _b.env;
|
|
537
|
+
if (typeof env !== 'string' || !env.trim())
|
|
538
|
+
env = (_c = cloud === null || cloud === void 0 ? void 0 : cloud.config) === null || _c === void 0 ? void 0 : _c.env;
|
|
539
|
+
if (typeof env !== 'string' || !env.trim()) {
|
|
540
|
+
throw new Error('Generating default gateway base url failed: env not found');
|
|
541
|
+
}
|
|
542
|
+
env = env.trim();
|
|
543
|
+
return {
|
|
544
|
+
model: "https://".concat(env, ".api.tcloudbasegateway.com/v1/model"),
|
|
545
|
+
sql: "https://".concat(env, ".api.tcloudbasegateway.com/v1/sql")
|
|
546
|
+
};
|
|
547
|
+
}
|
|
605
548
|
var index = {
|
|
606
549
|
init: init,
|
|
607
550
|
generateHTTPClient: generateHTTPClient
|
|
@@ -141,7 +141,7 @@ function getUserAgent() {
|
|
|
141
141
|
return ua_1;
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
|
-
var VERSION = "1.
|
|
144
|
+
var VERSION = "1.6.0";
|
|
145
145
|
|
|
146
146
|
var callDataSource = function (_a) {
|
|
147
147
|
var dataSourceName = _a.dataSourceName, methodName = _a.methodName, params = _a.params, realMethodName = _a.realMethodName, callFunction = _a.callFunction, _b = _a.envType, envType = _b === void 0 ? 'prod' : _b, mode = _a.mode;
|
|
@@ -302,107 +302,6 @@ var createRawQueryClient = function (callFunction) { return ({
|
|
|
302
302
|
}
|
|
303
303
|
}); };
|
|
304
304
|
|
|
305
|
-
var CRUD_METHODS = {
|
|
306
|
-
create: {
|
|
307
|
-
methodName: 'wedaCreateV2'
|
|
308
|
-
},
|
|
309
|
-
createMany: {
|
|
310
|
-
methodName: 'wedaBatchCreateV2'
|
|
311
|
-
},
|
|
312
|
-
update: {
|
|
313
|
-
methodName: 'wedaUpdateV2'
|
|
314
|
-
},
|
|
315
|
-
upsert: {
|
|
316
|
-
methodName: 'wedaUpsertV2'
|
|
317
|
-
},
|
|
318
|
-
updateMany: {
|
|
319
|
-
methodName: 'wedaBatchUpdateV2'
|
|
320
|
-
},
|
|
321
|
-
"delete": {
|
|
322
|
-
methodName: 'wedaDeleteV2'
|
|
323
|
-
},
|
|
324
|
-
deleteMany: {
|
|
325
|
-
methodName: 'wedaBatchDeleteV2'
|
|
326
|
-
},
|
|
327
|
-
get: {
|
|
328
|
-
methodName: 'wedaGetItemV2',
|
|
329
|
-
defaultParams: {
|
|
330
|
-
filter: {
|
|
331
|
-
where: {}
|
|
332
|
-
},
|
|
333
|
-
select: {
|
|
334
|
-
$master: true
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
},
|
|
338
|
-
list: {
|
|
339
|
-
methodName: 'wedaGetRecordsV2',
|
|
340
|
-
defaultParams: {
|
|
341
|
-
filter: {
|
|
342
|
-
where: {}
|
|
343
|
-
},
|
|
344
|
-
select: {
|
|
345
|
-
$master: true
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
};
|
|
350
|
-
var generateClientByDataSourceName = function (dataSourceName, callFunction) {
|
|
351
|
-
var client = new Proxy({}, {
|
|
352
|
-
get: function (target, methodName) {
|
|
353
|
-
var operation = CRUD_METHODS[methodName];
|
|
354
|
-
if (!operation) {
|
|
355
|
-
var error = new Error("\u4E0D\u652F\u6301\u7684\u64CD\u4F5C: ".concat(methodName));
|
|
356
|
-
throw new WxCloudSDKError(error.message || 'Unknown error occurred', {
|
|
357
|
-
originError: error,
|
|
358
|
-
code: 'NotSupported',
|
|
359
|
-
requestId: 'N/A'
|
|
360
|
-
});
|
|
361
|
-
}
|
|
362
|
-
return function (params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
363
|
-
var effectiveParams, rawData, result, dataKey;
|
|
364
|
-
var _a;
|
|
365
|
-
return __generator(this, function (_b) {
|
|
366
|
-
switch (_b.label) {
|
|
367
|
-
case 0:
|
|
368
|
-
effectiveParams = __assign(__assign({}, (operation.defaultParams || {})), (params || {}));
|
|
369
|
-
return [4 /*yield*/, callDataSource({
|
|
370
|
-
callFunction: callFunction,
|
|
371
|
-
dataSourceName: dataSourceName,
|
|
372
|
-
methodName: operation.methodName,
|
|
373
|
-
realMethodName: methodName,
|
|
374
|
-
params: effectiveParams,
|
|
375
|
-
envType: params === null || params === void 0 ? void 0 : params.envType
|
|
376
|
-
})];
|
|
377
|
-
case 1:
|
|
378
|
-
rawData = _b.sent();
|
|
379
|
-
result = { data: {} };
|
|
380
|
-
dataKey = operation.responseKey;
|
|
381
|
-
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;
|
|
382
|
-
return [2 /*return*/, result];
|
|
383
|
-
}
|
|
384
|
-
});
|
|
385
|
-
}); };
|
|
386
|
-
}
|
|
387
|
-
});
|
|
388
|
-
return client;
|
|
389
|
-
};
|
|
390
|
-
// 使用 TypeScript 的 Proxy 来定义一个动态的客户端
|
|
391
|
-
var generateClient = function (callFunction) {
|
|
392
|
-
var rawQueryClient = createRawQueryClient(callFunction);
|
|
393
|
-
return new Proxy({}, {
|
|
394
|
-
get: function (target, prop) {
|
|
395
|
-
if (typeof prop === 'string') {
|
|
396
|
-
if (Object.prototype.hasOwnProperty.call(rawQueryClient, prop)) {
|
|
397
|
-
return rawQueryClient[prop];
|
|
398
|
-
}
|
|
399
|
-
// 返回一个函数,这个函数接受任意参数并返回一个 Promise
|
|
400
|
-
return generateClientByDataSourceName(prop, callFunction);
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
});
|
|
404
|
-
};
|
|
405
|
-
|
|
406
305
|
var READ_DEFAULT_PARAMS = {
|
|
407
306
|
filter: {
|
|
408
307
|
where: {}
|
|
@@ -587,17 +486,61 @@ var generateHTTPClientByDataSourceName = function (baseUrl, modelName, fetch, op
|
|
|
587
486
|
return client;
|
|
588
487
|
};
|
|
589
488
|
|
|
590
|
-
function init(cloud) {
|
|
489
|
+
function init(cloud, options) {
|
|
490
|
+
var _this = this;
|
|
591
491
|
if (!cloud) {
|
|
592
492
|
throw new Error('cloud is required');
|
|
593
493
|
}
|
|
594
494
|
if (!cloud.callFunction) {
|
|
595
495
|
throw new Error('cloud.callFunction is required');
|
|
596
496
|
}
|
|
597
|
-
var
|
|
598
|
-
|
|
497
|
+
var callFunction = cloud.callFunction.bind(cloud);
|
|
498
|
+
var HTTPOverCallFunctionFetch = function (_a) {
|
|
499
|
+
var url = _a.url, body = _a.body, method = _a.method, headers = _a.headers;
|
|
500
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
501
|
+
var res, result;
|
|
502
|
+
var _b;
|
|
503
|
+
return __generator(this, function (_c) {
|
|
504
|
+
switch (_c.label) {
|
|
505
|
+
case 0: return [4 /*yield*/, callFunction({
|
|
506
|
+
name: 'httpOverCallFunction',
|
|
507
|
+
data: {
|
|
508
|
+
url: url,
|
|
509
|
+
method: method === null || method === void 0 ? void 0 : method.toUpperCase(),
|
|
510
|
+
headers: __assign(__assign({}, (headers || {})), { 'Content-Type': 'application/json' }),
|
|
511
|
+
body: body
|
|
512
|
+
}
|
|
513
|
+
})];
|
|
514
|
+
case 1:
|
|
515
|
+
res = _c.sent();
|
|
516
|
+
result = (_b = res === null || res === void 0 ? void 0 : res.result) === null || _b === void 0 ? void 0 : _b.body;
|
|
517
|
+
return [2 /*return*/, result];
|
|
518
|
+
}
|
|
519
|
+
});
|
|
520
|
+
});
|
|
521
|
+
};
|
|
522
|
+
var baseUrl = (options === null || options === void 0 ? void 0 : options.baseUrl) || getDefaultGatewayBaseUrl(cloud).model;
|
|
523
|
+
var sqlBaseUrl = (options === null || options === void 0 ? void 0 : options.sqlBaseUrl) || getDefaultGatewayBaseUrl(cloud).sql;
|
|
524
|
+
var httpOrmClientImpl = generateHTTPClient(callFunction, HTTPOverCallFunctionFetch, baseUrl, {
|
|
525
|
+
sqlBaseUrl: sqlBaseUrl
|
|
526
|
+
});
|
|
527
|
+
cloud.models = httpOrmClientImpl;
|
|
599
528
|
return cloud;
|
|
600
529
|
}
|
|
530
|
+
function getDefaultGatewayBaseUrl(cloud) {
|
|
531
|
+
var _a, _b, _c;
|
|
532
|
+
var env = (_b = (_a = cloud === null || cloud === void 0 ? void 0 : cloud.extend) === null || _a === void 0 ? void 0 : _a.AI) === null || _b === void 0 ? void 0 : _b.env;
|
|
533
|
+
if (typeof env !== 'string' || !env.trim())
|
|
534
|
+
env = (_c = cloud === null || cloud === void 0 ? void 0 : cloud.config) === null || _c === void 0 ? void 0 : _c.env;
|
|
535
|
+
if (typeof env !== 'string' || !env.trim()) {
|
|
536
|
+
throw new Error('Generating default gateway base url failed: env not found');
|
|
537
|
+
}
|
|
538
|
+
env = env.trim();
|
|
539
|
+
return {
|
|
540
|
+
model: "https://".concat(env, ".api.tcloudbasegateway.com/v1/model"),
|
|
541
|
+
sql: "https://".concat(env, ".api.tcloudbasegateway.com/v1/sql")
|
|
542
|
+
};
|
|
543
|
+
}
|
|
601
544
|
var index = {
|
|
602
545
|
init: init,
|
|
603
546
|
generateHTTPClient: generateHTTPClient
|
|
@@ -147,7 +147,7 @@
|
|
|
147
147
|
return ua_1;
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
|
-
var VERSION = "1.
|
|
150
|
+
var VERSION = "1.6.0";
|
|
151
151
|
|
|
152
152
|
var callDataSource = function (_a) {
|
|
153
153
|
var dataSourceName = _a.dataSourceName, methodName = _a.methodName, params = _a.params, realMethodName = _a.realMethodName, callFunction = _a.callFunction, _b = _a.envType, envType = _b === void 0 ? 'prod' : _b, mode = _a.mode;
|
|
@@ -308,107 +308,6 @@
|
|
|
308
308
|
}
|
|
309
309
|
}); };
|
|
310
310
|
|
|
311
|
-
var CRUD_METHODS = {
|
|
312
|
-
create: {
|
|
313
|
-
methodName: 'wedaCreateV2'
|
|
314
|
-
},
|
|
315
|
-
createMany: {
|
|
316
|
-
methodName: 'wedaBatchCreateV2'
|
|
317
|
-
},
|
|
318
|
-
update: {
|
|
319
|
-
methodName: 'wedaUpdateV2'
|
|
320
|
-
},
|
|
321
|
-
upsert: {
|
|
322
|
-
methodName: 'wedaUpsertV2'
|
|
323
|
-
},
|
|
324
|
-
updateMany: {
|
|
325
|
-
methodName: 'wedaBatchUpdateV2'
|
|
326
|
-
},
|
|
327
|
-
"delete": {
|
|
328
|
-
methodName: 'wedaDeleteV2'
|
|
329
|
-
},
|
|
330
|
-
deleteMany: {
|
|
331
|
-
methodName: 'wedaBatchDeleteV2'
|
|
332
|
-
},
|
|
333
|
-
get: {
|
|
334
|
-
methodName: 'wedaGetItemV2',
|
|
335
|
-
defaultParams: {
|
|
336
|
-
filter: {
|
|
337
|
-
where: {}
|
|
338
|
-
},
|
|
339
|
-
select: {
|
|
340
|
-
$master: true
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
},
|
|
344
|
-
list: {
|
|
345
|
-
methodName: 'wedaGetRecordsV2',
|
|
346
|
-
defaultParams: {
|
|
347
|
-
filter: {
|
|
348
|
-
where: {}
|
|
349
|
-
},
|
|
350
|
-
select: {
|
|
351
|
-
$master: true
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
};
|
|
356
|
-
var generateClientByDataSourceName = function (dataSourceName, callFunction) {
|
|
357
|
-
var client = new Proxy({}, {
|
|
358
|
-
get: function (target, methodName) {
|
|
359
|
-
var operation = CRUD_METHODS[methodName];
|
|
360
|
-
if (!operation) {
|
|
361
|
-
var error = new Error("\u4E0D\u652F\u6301\u7684\u64CD\u4F5C: ".concat(methodName));
|
|
362
|
-
throw new WxCloudSDKError(error.message || 'Unknown error occurred', {
|
|
363
|
-
originError: error,
|
|
364
|
-
code: 'NotSupported',
|
|
365
|
-
requestId: 'N/A'
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
|
-
return function (params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
369
|
-
var effectiveParams, rawData, result, dataKey;
|
|
370
|
-
var _a;
|
|
371
|
-
return __generator(this, function (_b) {
|
|
372
|
-
switch (_b.label) {
|
|
373
|
-
case 0:
|
|
374
|
-
effectiveParams = __assign(__assign({}, (operation.defaultParams || {})), (params || {}));
|
|
375
|
-
return [4 /*yield*/, callDataSource({
|
|
376
|
-
callFunction: callFunction,
|
|
377
|
-
dataSourceName: dataSourceName,
|
|
378
|
-
methodName: operation.methodName,
|
|
379
|
-
realMethodName: methodName,
|
|
380
|
-
params: effectiveParams,
|
|
381
|
-
envType: params === null || params === void 0 ? void 0 : params.envType
|
|
382
|
-
})];
|
|
383
|
-
case 1:
|
|
384
|
-
rawData = _b.sent();
|
|
385
|
-
result = { data: {} };
|
|
386
|
-
dataKey = operation.responseKey;
|
|
387
|
-
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;
|
|
388
|
-
return [2 /*return*/, result];
|
|
389
|
-
}
|
|
390
|
-
});
|
|
391
|
-
}); };
|
|
392
|
-
}
|
|
393
|
-
});
|
|
394
|
-
return client;
|
|
395
|
-
};
|
|
396
|
-
// 使用 TypeScript 的 Proxy 来定义一个动态的客户端
|
|
397
|
-
var generateClient = function (callFunction) {
|
|
398
|
-
var rawQueryClient = createRawQueryClient(callFunction);
|
|
399
|
-
return new Proxy({}, {
|
|
400
|
-
get: function (target, prop) {
|
|
401
|
-
if (typeof prop === 'string') {
|
|
402
|
-
if (Object.prototype.hasOwnProperty.call(rawQueryClient, prop)) {
|
|
403
|
-
return rawQueryClient[prop];
|
|
404
|
-
}
|
|
405
|
-
// 返回一个函数,这个函数接受任意参数并返回一个 Promise
|
|
406
|
-
return generateClientByDataSourceName(prop, callFunction);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
});
|
|
410
|
-
};
|
|
411
|
-
|
|
412
311
|
var READ_DEFAULT_PARAMS = {
|
|
413
312
|
filter: {
|
|
414
313
|
where: {}
|
|
@@ -593,17 +492,61 @@
|
|
|
593
492
|
return client;
|
|
594
493
|
};
|
|
595
494
|
|
|
596
|
-
function init(cloud) {
|
|
495
|
+
function init(cloud, options) {
|
|
496
|
+
var _this = this;
|
|
597
497
|
if (!cloud) {
|
|
598
498
|
throw new Error('cloud is required');
|
|
599
499
|
}
|
|
600
500
|
if (!cloud.callFunction) {
|
|
601
501
|
throw new Error('cloud.callFunction is required');
|
|
602
502
|
}
|
|
603
|
-
var
|
|
604
|
-
|
|
503
|
+
var callFunction = cloud.callFunction.bind(cloud);
|
|
504
|
+
var HTTPOverCallFunctionFetch = function (_a) {
|
|
505
|
+
var url = _a.url, body = _a.body, method = _a.method, headers = _a.headers;
|
|
506
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
507
|
+
var res, result;
|
|
508
|
+
var _b;
|
|
509
|
+
return __generator(this, function (_c) {
|
|
510
|
+
switch (_c.label) {
|
|
511
|
+
case 0: return [4 /*yield*/, callFunction({
|
|
512
|
+
name: 'httpOverCallFunction',
|
|
513
|
+
data: {
|
|
514
|
+
url: url,
|
|
515
|
+
method: method === null || method === void 0 ? void 0 : method.toUpperCase(),
|
|
516
|
+
headers: __assign(__assign({}, (headers || {})), { 'Content-Type': 'application/json' }),
|
|
517
|
+
body: body
|
|
518
|
+
}
|
|
519
|
+
})];
|
|
520
|
+
case 1:
|
|
521
|
+
res = _c.sent();
|
|
522
|
+
result = (_b = res === null || res === void 0 ? void 0 : res.result) === null || _b === void 0 ? void 0 : _b.body;
|
|
523
|
+
return [2 /*return*/, result];
|
|
524
|
+
}
|
|
525
|
+
});
|
|
526
|
+
});
|
|
527
|
+
};
|
|
528
|
+
var baseUrl = (options === null || options === void 0 ? void 0 : options.baseUrl) || getDefaultGatewayBaseUrl(cloud).model;
|
|
529
|
+
var sqlBaseUrl = (options === null || options === void 0 ? void 0 : options.sqlBaseUrl) || getDefaultGatewayBaseUrl(cloud).sql;
|
|
530
|
+
var httpOrmClientImpl = generateHTTPClient(callFunction, HTTPOverCallFunctionFetch, baseUrl, {
|
|
531
|
+
sqlBaseUrl: sqlBaseUrl
|
|
532
|
+
});
|
|
533
|
+
cloud.models = httpOrmClientImpl;
|
|
605
534
|
return cloud;
|
|
606
535
|
}
|
|
536
|
+
function getDefaultGatewayBaseUrl(cloud) {
|
|
537
|
+
var _a, _b, _c;
|
|
538
|
+
var env = (_b = (_a = cloud === null || cloud === void 0 ? void 0 : cloud.extend) === null || _a === void 0 ? void 0 : _a.AI) === null || _b === void 0 ? void 0 : _b.env;
|
|
539
|
+
if (typeof env !== 'string' || !env.trim())
|
|
540
|
+
env = (_c = cloud === null || cloud === void 0 ? void 0 : cloud.config) === null || _c === void 0 ? void 0 : _c.env;
|
|
541
|
+
if (typeof env !== 'string' || !env.trim()) {
|
|
542
|
+
throw new Error('Generating default gateway base url failed: env not found');
|
|
543
|
+
}
|
|
544
|
+
env = env.trim();
|
|
545
|
+
return {
|
|
546
|
+
model: "https://".concat(env, ".api.tcloudbasegateway.com/v1/model"),
|
|
547
|
+
sql: "https://".concat(env, ".api.tcloudbasegateway.com/v1/sql")
|
|
548
|
+
};
|
|
549
|
+
}
|
|
607
550
|
var index = {
|
|
608
551
|
init: init,
|
|
609
552
|
generateHTTPClient: generateHTTPClient
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/wx-cloud-client-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@cloudbase/adapter-interface": "^0.5.0",
|
|
30
|
-
"@cloudbase/js-sdk": "2.
|
|
30
|
+
"@cloudbase/js-sdk": "2.15.0",
|
|
31
31
|
"@rollup/plugin-commonjs": "^25.0.8",
|
|
32
32
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
33
33
|
"@rollup/plugin-replace": "^5.0.7",
|