@cloudbase/wx-cloud-client-sdk 1.6.0 → 1.6.1
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 -3
- package/lib/wxCloudClientSDK.cjs.js +153 -31
- package/lib/wxCloudClientSDK.esm.js +153 -32
- package/lib/wxCloudClientSDK.umd.js +153 -31
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { CloudBaseInstance, ExtendedCloudBaseInstance } from './types';
|
|
1
|
+
import { CloudBaseInstance, ExtendedCloudBaseInstance, OrmClient } from './types';
|
|
2
2
|
import { generateHTTPClient } from './orm/http-orm-client';
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function initHTTPOverCallFunction(cloud: CloudBaseInstance, options?: {
|
|
4
4
|
baseUrl?: string;
|
|
5
5
|
sqlBaseUrl?: string;
|
|
6
6
|
}): ExtendedCloudBaseInstance;
|
|
7
|
+
export declare function init(cloud: CloudBaseInstance): ExtendedCloudBaseInstance;
|
|
7
8
|
export * from './types';
|
|
8
9
|
export { generateHTTPClient };
|
|
9
10
|
declare const _default: {
|
|
10
11
|
init: typeof init;
|
|
11
12
|
generateHTTPClient: (callFunction: import("./types").CallFunction, fetch: (options: import("@cloudbase/adapter-interface").IFetchOptions) => any, baseUrl: string, options?: {
|
|
12
13
|
sqlBaseUrl?: string | undefined;
|
|
13
|
-
} | undefined) =>
|
|
14
|
+
} | undefined) => OrmClient;
|
|
14
15
|
};
|
|
15
16
|
export default _default;
|
|
@@ -145,7 +145,7 @@ function getUserAgent() {
|
|
|
145
145
|
return ua_1;
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
|
-
var VERSION = "1.6.
|
|
148
|
+
var VERSION = "1.6.1";
|
|
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;
|
|
@@ -490,7 +490,108 @@ var generateHTTPClientByDataSourceName = function (baseUrl, modelName, fetch, op
|
|
|
490
490
|
return client;
|
|
491
491
|
};
|
|
492
492
|
|
|
493
|
-
|
|
493
|
+
var CRUD_METHODS = {
|
|
494
|
+
create: {
|
|
495
|
+
methodName: 'wedaCreateV2'
|
|
496
|
+
},
|
|
497
|
+
createMany: {
|
|
498
|
+
methodName: 'wedaBatchCreateV2'
|
|
499
|
+
},
|
|
500
|
+
update: {
|
|
501
|
+
methodName: 'wedaUpdateV2'
|
|
502
|
+
},
|
|
503
|
+
upsert: {
|
|
504
|
+
methodName: 'wedaUpsertV2'
|
|
505
|
+
},
|
|
506
|
+
updateMany: {
|
|
507
|
+
methodName: 'wedaBatchUpdateV2'
|
|
508
|
+
},
|
|
509
|
+
"delete": {
|
|
510
|
+
methodName: 'wedaDeleteV2'
|
|
511
|
+
},
|
|
512
|
+
deleteMany: {
|
|
513
|
+
methodName: 'wedaBatchDeleteV2'
|
|
514
|
+
},
|
|
515
|
+
get: {
|
|
516
|
+
methodName: 'wedaGetItemV2',
|
|
517
|
+
defaultParams: {
|
|
518
|
+
filter: {
|
|
519
|
+
where: {}
|
|
520
|
+
},
|
|
521
|
+
select: {
|
|
522
|
+
$master: true
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
},
|
|
526
|
+
list: {
|
|
527
|
+
methodName: 'wedaGetRecordsV2',
|
|
528
|
+
defaultParams: {
|
|
529
|
+
filter: {
|
|
530
|
+
where: {}
|
|
531
|
+
},
|
|
532
|
+
select: {
|
|
533
|
+
$master: true
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
};
|
|
538
|
+
var generateClientByDataSourceName = function (dataSourceName, callFunction) {
|
|
539
|
+
var client = new Proxy({}, {
|
|
540
|
+
get: function (target, methodName) {
|
|
541
|
+
var operation = CRUD_METHODS[methodName];
|
|
542
|
+
if (!operation) {
|
|
543
|
+
var error = new Error("\u4E0D\u652F\u6301\u7684\u64CD\u4F5C: ".concat(methodName));
|
|
544
|
+
throw new WxCloudSDKError(error.message || 'Unknown error occurred', {
|
|
545
|
+
originError: error,
|
|
546
|
+
code: 'NotSupported',
|
|
547
|
+
requestId: 'N/A'
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
return function (params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
551
|
+
var effectiveParams, rawData, result, dataKey;
|
|
552
|
+
var _a;
|
|
553
|
+
return __generator(this, function (_b) {
|
|
554
|
+
switch (_b.label) {
|
|
555
|
+
case 0:
|
|
556
|
+
effectiveParams = __assign(__assign({}, (operation.defaultParams || {})), (params || {}));
|
|
557
|
+
return [4 /*yield*/, callDataSource({
|
|
558
|
+
callFunction: callFunction,
|
|
559
|
+
dataSourceName: dataSourceName,
|
|
560
|
+
methodName: operation.methodName,
|
|
561
|
+
realMethodName: methodName,
|
|
562
|
+
params: effectiveParams,
|
|
563
|
+
envType: params === null || params === void 0 ? void 0 : params.envType
|
|
564
|
+
})];
|
|
565
|
+
case 1:
|
|
566
|
+
rawData = _b.sent();
|
|
567
|
+
result = { data: {} };
|
|
568
|
+
dataKey = operation.responseKey;
|
|
569
|
+
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;
|
|
570
|
+
return [2 /*return*/, result];
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
}); };
|
|
574
|
+
}
|
|
575
|
+
});
|
|
576
|
+
return client;
|
|
577
|
+
};
|
|
578
|
+
// 使用 TypeScript 的 Proxy 来定义一个动态的客户端
|
|
579
|
+
var generateClient = function (callFunction) {
|
|
580
|
+
var rawQueryClient = createRawQueryClient(callFunction);
|
|
581
|
+
return new Proxy({}, {
|
|
582
|
+
get: function (target, prop) {
|
|
583
|
+
if (typeof prop === 'string') {
|
|
584
|
+
if (Object.prototype.hasOwnProperty.call(rawQueryClient, prop)) {
|
|
585
|
+
return rawQueryClient[prop];
|
|
586
|
+
}
|
|
587
|
+
// 返回一个函数,这个函数接受任意参数并返回一个 Promise
|
|
588
|
+
return generateClientByDataSourceName(prop, callFunction);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
});
|
|
592
|
+
};
|
|
593
|
+
|
|
594
|
+
function initHTTPOverCallFunction(cloud, options) {
|
|
494
595
|
var _this = this;
|
|
495
596
|
if (!cloud) {
|
|
496
597
|
throw new Error('cloud is required');
|
|
@@ -499,43 +600,63 @@ function init(cloud, options) {
|
|
|
499
600
|
throw new Error('cloud.callFunction is required');
|
|
500
601
|
}
|
|
501
602
|
var callFunction = cloud.callFunction.bind(cloud);
|
|
502
|
-
var
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
var
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
603
|
+
var ormClient;
|
|
604
|
+
try {
|
|
605
|
+
var HTTPOverCallFunctionFetch = function (_a) {
|
|
606
|
+
var url = _a.url, body = _a.body, method = _a.method, headers = _a.headers;
|
|
607
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
608
|
+
var res, result;
|
|
609
|
+
var _b;
|
|
610
|
+
return __generator(this, function (_c) {
|
|
611
|
+
switch (_c.label) {
|
|
612
|
+
case 0: return [4 /*yield*/, callFunction({
|
|
613
|
+
name: 'httpOverCallFunction',
|
|
614
|
+
data: {
|
|
615
|
+
url: url,
|
|
616
|
+
method: method === null || method === void 0 ? void 0 : method.toUpperCase(),
|
|
617
|
+
headers: __assign(__assign({}, (headers || {})), { 'Content-Type': 'application/json' }),
|
|
618
|
+
body: body
|
|
619
|
+
}
|
|
620
|
+
})];
|
|
621
|
+
case 1:
|
|
622
|
+
res = _c.sent();
|
|
623
|
+
result = (_b = res === null || res === void 0 ? void 0 : res.result) === null || _b === void 0 ? void 0 : _b.body;
|
|
624
|
+
return [2 /*return*/, result];
|
|
625
|
+
}
|
|
626
|
+
});
|
|
523
627
|
});
|
|
628
|
+
};
|
|
629
|
+
var baseUrl = (options === null || options === void 0 ? void 0 : options.baseUrl) || getDefaultGatewayBaseUrl(cloud).model;
|
|
630
|
+
var sqlBaseUrl = (options === null || options === void 0 ? void 0 : options.sqlBaseUrl) || getDefaultGatewayBaseUrl(cloud).sql;
|
|
631
|
+
ormClient = generateHTTPClient(callFunction, HTTPOverCallFunctionFetch, baseUrl, {
|
|
632
|
+
sqlBaseUrl: sqlBaseUrl
|
|
524
633
|
});
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
cloud
|
|
634
|
+
}
|
|
635
|
+
catch (e) {
|
|
636
|
+
console.error('init http orm client failed, try call function orm', e);
|
|
637
|
+
ormClient = generateClient(callFunction);
|
|
638
|
+
}
|
|
639
|
+
cloud.models = ormClient;
|
|
640
|
+
return cloud;
|
|
641
|
+
}
|
|
642
|
+
function init(cloud) {
|
|
643
|
+
if (!cloud) {
|
|
644
|
+
throw new Error('cloud is required');
|
|
645
|
+
}
|
|
646
|
+
if (!cloud.callFunction) {
|
|
647
|
+
throw new Error('cloud.callFunction is required');
|
|
648
|
+
}
|
|
649
|
+
var ormClientImpl = generateClient(cloud.callFunction.bind(cloud));
|
|
650
|
+
cloud.models = ormClientImpl;
|
|
532
651
|
return cloud;
|
|
533
652
|
}
|
|
534
653
|
function getDefaultGatewayBaseUrl(cloud) {
|
|
535
|
-
var _a, _b, _c;
|
|
654
|
+
var _a, _b, _c, _d;
|
|
536
655
|
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
656
|
if (typeof env !== 'string' || !env.trim())
|
|
538
657
|
env = (_c = cloud === null || cloud === void 0 ? void 0 : cloud.config) === null || _c === void 0 ? void 0 : _c.env;
|
|
658
|
+
if (typeof env !== 'string' || !env.trim())
|
|
659
|
+
env = (_d = cloud === null || cloud === void 0 ? void 0 : cloud.config) === null || _d === void 0 ? void 0 : _d.envName;
|
|
539
660
|
if (typeof env !== 'string' || !env.trim()) {
|
|
540
661
|
throw new Error('Generating default gateway base url failed: env not found');
|
|
541
662
|
}
|
|
@@ -553,3 +674,4 @@ var index = {
|
|
|
553
674
|
exports.default = index;
|
|
554
675
|
exports.generateHTTPClient = generateHTTPClient;
|
|
555
676
|
exports.init = init;
|
|
677
|
+
exports.initHTTPOverCallFunction = initHTTPOverCallFunction;
|
|
@@ -141,7 +141,7 @@ function getUserAgent() {
|
|
|
141
141
|
return ua_1;
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
|
-
var VERSION = "1.6.
|
|
144
|
+
var VERSION = "1.6.1";
|
|
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;
|
|
@@ -486,7 +486,108 @@ var generateHTTPClientByDataSourceName = function (baseUrl, modelName, fetch, op
|
|
|
486
486
|
return client;
|
|
487
487
|
};
|
|
488
488
|
|
|
489
|
-
|
|
489
|
+
var CRUD_METHODS = {
|
|
490
|
+
create: {
|
|
491
|
+
methodName: 'wedaCreateV2'
|
|
492
|
+
},
|
|
493
|
+
createMany: {
|
|
494
|
+
methodName: 'wedaBatchCreateV2'
|
|
495
|
+
},
|
|
496
|
+
update: {
|
|
497
|
+
methodName: 'wedaUpdateV2'
|
|
498
|
+
},
|
|
499
|
+
upsert: {
|
|
500
|
+
methodName: 'wedaUpsertV2'
|
|
501
|
+
},
|
|
502
|
+
updateMany: {
|
|
503
|
+
methodName: 'wedaBatchUpdateV2'
|
|
504
|
+
},
|
|
505
|
+
"delete": {
|
|
506
|
+
methodName: 'wedaDeleteV2'
|
|
507
|
+
},
|
|
508
|
+
deleteMany: {
|
|
509
|
+
methodName: 'wedaBatchDeleteV2'
|
|
510
|
+
},
|
|
511
|
+
get: {
|
|
512
|
+
methodName: 'wedaGetItemV2',
|
|
513
|
+
defaultParams: {
|
|
514
|
+
filter: {
|
|
515
|
+
where: {}
|
|
516
|
+
},
|
|
517
|
+
select: {
|
|
518
|
+
$master: true
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
},
|
|
522
|
+
list: {
|
|
523
|
+
methodName: 'wedaGetRecordsV2',
|
|
524
|
+
defaultParams: {
|
|
525
|
+
filter: {
|
|
526
|
+
where: {}
|
|
527
|
+
},
|
|
528
|
+
select: {
|
|
529
|
+
$master: true
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
};
|
|
534
|
+
var generateClientByDataSourceName = function (dataSourceName, callFunction) {
|
|
535
|
+
var client = new Proxy({}, {
|
|
536
|
+
get: function (target, methodName) {
|
|
537
|
+
var operation = CRUD_METHODS[methodName];
|
|
538
|
+
if (!operation) {
|
|
539
|
+
var error = new Error("\u4E0D\u652F\u6301\u7684\u64CD\u4F5C: ".concat(methodName));
|
|
540
|
+
throw new WxCloudSDKError(error.message || 'Unknown error occurred', {
|
|
541
|
+
originError: error,
|
|
542
|
+
code: 'NotSupported',
|
|
543
|
+
requestId: 'N/A'
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
return function (params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
547
|
+
var effectiveParams, rawData, result, dataKey;
|
|
548
|
+
var _a;
|
|
549
|
+
return __generator(this, function (_b) {
|
|
550
|
+
switch (_b.label) {
|
|
551
|
+
case 0:
|
|
552
|
+
effectiveParams = __assign(__assign({}, (operation.defaultParams || {})), (params || {}));
|
|
553
|
+
return [4 /*yield*/, callDataSource({
|
|
554
|
+
callFunction: callFunction,
|
|
555
|
+
dataSourceName: dataSourceName,
|
|
556
|
+
methodName: operation.methodName,
|
|
557
|
+
realMethodName: methodName,
|
|
558
|
+
params: effectiveParams,
|
|
559
|
+
envType: params === null || params === void 0 ? void 0 : params.envType
|
|
560
|
+
})];
|
|
561
|
+
case 1:
|
|
562
|
+
rawData = _b.sent();
|
|
563
|
+
result = { data: {} };
|
|
564
|
+
dataKey = operation.responseKey;
|
|
565
|
+
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;
|
|
566
|
+
return [2 /*return*/, result];
|
|
567
|
+
}
|
|
568
|
+
});
|
|
569
|
+
}); };
|
|
570
|
+
}
|
|
571
|
+
});
|
|
572
|
+
return client;
|
|
573
|
+
};
|
|
574
|
+
// 使用 TypeScript 的 Proxy 来定义一个动态的客户端
|
|
575
|
+
var generateClient = function (callFunction) {
|
|
576
|
+
var rawQueryClient = createRawQueryClient(callFunction);
|
|
577
|
+
return new Proxy({}, {
|
|
578
|
+
get: function (target, prop) {
|
|
579
|
+
if (typeof prop === 'string') {
|
|
580
|
+
if (Object.prototype.hasOwnProperty.call(rawQueryClient, prop)) {
|
|
581
|
+
return rawQueryClient[prop];
|
|
582
|
+
}
|
|
583
|
+
// 返回一个函数,这个函数接受任意参数并返回一个 Promise
|
|
584
|
+
return generateClientByDataSourceName(prop, callFunction);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
});
|
|
588
|
+
};
|
|
589
|
+
|
|
590
|
+
function initHTTPOverCallFunction(cloud, options) {
|
|
490
591
|
var _this = this;
|
|
491
592
|
if (!cloud) {
|
|
492
593
|
throw new Error('cloud is required');
|
|
@@ -495,43 +596,63 @@ function init(cloud, options) {
|
|
|
495
596
|
throw new Error('cloud.callFunction is required');
|
|
496
597
|
}
|
|
497
598
|
var callFunction = cloud.callFunction.bind(cloud);
|
|
498
|
-
var
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
var
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
599
|
+
var ormClient;
|
|
600
|
+
try {
|
|
601
|
+
var HTTPOverCallFunctionFetch = function (_a) {
|
|
602
|
+
var url = _a.url, body = _a.body, method = _a.method, headers = _a.headers;
|
|
603
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
604
|
+
var res, result;
|
|
605
|
+
var _b;
|
|
606
|
+
return __generator(this, function (_c) {
|
|
607
|
+
switch (_c.label) {
|
|
608
|
+
case 0: return [4 /*yield*/, callFunction({
|
|
609
|
+
name: 'httpOverCallFunction',
|
|
610
|
+
data: {
|
|
611
|
+
url: url,
|
|
612
|
+
method: method === null || method === void 0 ? void 0 : method.toUpperCase(),
|
|
613
|
+
headers: __assign(__assign({}, (headers || {})), { 'Content-Type': 'application/json' }),
|
|
614
|
+
body: body
|
|
615
|
+
}
|
|
616
|
+
})];
|
|
617
|
+
case 1:
|
|
618
|
+
res = _c.sent();
|
|
619
|
+
result = (_b = res === null || res === void 0 ? void 0 : res.result) === null || _b === void 0 ? void 0 : _b.body;
|
|
620
|
+
return [2 /*return*/, result];
|
|
621
|
+
}
|
|
622
|
+
});
|
|
519
623
|
});
|
|
624
|
+
};
|
|
625
|
+
var baseUrl = (options === null || options === void 0 ? void 0 : options.baseUrl) || getDefaultGatewayBaseUrl(cloud).model;
|
|
626
|
+
var sqlBaseUrl = (options === null || options === void 0 ? void 0 : options.sqlBaseUrl) || getDefaultGatewayBaseUrl(cloud).sql;
|
|
627
|
+
ormClient = generateHTTPClient(callFunction, HTTPOverCallFunctionFetch, baseUrl, {
|
|
628
|
+
sqlBaseUrl: sqlBaseUrl
|
|
520
629
|
});
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
cloud
|
|
630
|
+
}
|
|
631
|
+
catch (e) {
|
|
632
|
+
console.error('init http orm client failed, try call function orm', e);
|
|
633
|
+
ormClient = generateClient(callFunction);
|
|
634
|
+
}
|
|
635
|
+
cloud.models = ormClient;
|
|
636
|
+
return cloud;
|
|
637
|
+
}
|
|
638
|
+
function init(cloud) {
|
|
639
|
+
if (!cloud) {
|
|
640
|
+
throw new Error('cloud is required');
|
|
641
|
+
}
|
|
642
|
+
if (!cloud.callFunction) {
|
|
643
|
+
throw new Error('cloud.callFunction is required');
|
|
644
|
+
}
|
|
645
|
+
var ormClientImpl = generateClient(cloud.callFunction.bind(cloud));
|
|
646
|
+
cloud.models = ormClientImpl;
|
|
528
647
|
return cloud;
|
|
529
648
|
}
|
|
530
649
|
function getDefaultGatewayBaseUrl(cloud) {
|
|
531
|
-
var _a, _b, _c;
|
|
650
|
+
var _a, _b, _c, _d;
|
|
532
651
|
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
652
|
if (typeof env !== 'string' || !env.trim())
|
|
534
653
|
env = (_c = cloud === null || cloud === void 0 ? void 0 : cloud.config) === null || _c === void 0 ? void 0 : _c.env;
|
|
654
|
+
if (typeof env !== 'string' || !env.trim())
|
|
655
|
+
env = (_d = cloud === null || cloud === void 0 ? void 0 : cloud.config) === null || _d === void 0 ? void 0 : _d.envName;
|
|
535
656
|
if (typeof env !== 'string' || !env.trim()) {
|
|
536
657
|
throw new Error('Generating default gateway base url failed: env not found');
|
|
537
658
|
}
|
|
@@ -546,4 +667,4 @@ var index = {
|
|
|
546
667
|
generateHTTPClient: generateHTTPClient
|
|
547
668
|
};
|
|
548
669
|
|
|
549
|
-
export { index as default, generateHTTPClient, init };
|
|
670
|
+
export { index as default, generateHTTPClient, init, initHTTPOverCallFunction };
|
|
@@ -147,7 +147,7 @@
|
|
|
147
147
|
return ua_1;
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
|
-
var VERSION = "1.6.
|
|
150
|
+
var VERSION = "1.6.1";
|
|
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;
|
|
@@ -492,7 +492,108 @@
|
|
|
492
492
|
return client;
|
|
493
493
|
};
|
|
494
494
|
|
|
495
|
-
|
|
495
|
+
var CRUD_METHODS = {
|
|
496
|
+
create: {
|
|
497
|
+
methodName: 'wedaCreateV2'
|
|
498
|
+
},
|
|
499
|
+
createMany: {
|
|
500
|
+
methodName: 'wedaBatchCreateV2'
|
|
501
|
+
},
|
|
502
|
+
update: {
|
|
503
|
+
methodName: 'wedaUpdateV2'
|
|
504
|
+
},
|
|
505
|
+
upsert: {
|
|
506
|
+
methodName: 'wedaUpsertV2'
|
|
507
|
+
},
|
|
508
|
+
updateMany: {
|
|
509
|
+
methodName: 'wedaBatchUpdateV2'
|
|
510
|
+
},
|
|
511
|
+
"delete": {
|
|
512
|
+
methodName: 'wedaDeleteV2'
|
|
513
|
+
},
|
|
514
|
+
deleteMany: {
|
|
515
|
+
methodName: 'wedaBatchDeleteV2'
|
|
516
|
+
},
|
|
517
|
+
get: {
|
|
518
|
+
methodName: 'wedaGetItemV2',
|
|
519
|
+
defaultParams: {
|
|
520
|
+
filter: {
|
|
521
|
+
where: {}
|
|
522
|
+
},
|
|
523
|
+
select: {
|
|
524
|
+
$master: true
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
},
|
|
528
|
+
list: {
|
|
529
|
+
methodName: 'wedaGetRecordsV2',
|
|
530
|
+
defaultParams: {
|
|
531
|
+
filter: {
|
|
532
|
+
where: {}
|
|
533
|
+
},
|
|
534
|
+
select: {
|
|
535
|
+
$master: true
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
};
|
|
540
|
+
var generateClientByDataSourceName = function (dataSourceName, callFunction) {
|
|
541
|
+
var client = new Proxy({}, {
|
|
542
|
+
get: function (target, methodName) {
|
|
543
|
+
var operation = CRUD_METHODS[methodName];
|
|
544
|
+
if (!operation) {
|
|
545
|
+
var error = new Error("\u4E0D\u652F\u6301\u7684\u64CD\u4F5C: ".concat(methodName));
|
|
546
|
+
throw new WxCloudSDKError(error.message || 'Unknown error occurred', {
|
|
547
|
+
originError: error,
|
|
548
|
+
code: 'NotSupported',
|
|
549
|
+
requestId: 'N/A'
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
return function (params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
553
|
+
var effectiveParams, rawData, result, dataKey;
|
|
554
|
+
var _a;
|
|
555
|
+
return __generator(this, function (_b) {
|
|
556
|
+
switch (_b.label) {
|
|
557
|
+
case 0:
|
|
558
|
+
effectiveParams = __assign(__assign({}, (operation.defaultParams || {})), (params || {}));
|
|
559
|
+
return [4 /*yield*/, callDataSource({
|
|
560
|
+
callFunction: callFunction,
|
|
561
|
+
dataSourceName: dataSourceName,
|
|
562
|
+
methodName: operation.methodName,
|
|
563
|
+
realMethodName: methodName,
|
|
564
|
+
params: effectiveParams,
|
|
565
|
+
envType: params === null || params === void 0 ? void 0 : params.envType
|
|
566
|
+
})];
|
|
567
|
+
case 1:
|
|
568
|
+
rawData = _b.sent();
|
|
569
|
+
result = { data: {} };
|
|
570
|
+
dataKey = operation.responseKey;
|
|
571
|
+
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;
|
|
572
|
+
return [2 /*return*/, result];
|
|
573
|
+
}
|
|
574
|
+
});
|
|
575
|
+
}); };
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
return client;
|
|
579
|
+
};
|
|
580
|
+
// 使用 TypeScript 的 Proxy 来定义一个动态的客户端
|
|
581
|
+
var generateClient = function (callFunction) {
|
|
582
|
+
var rawQueryClient = createRawQueryClient(callFunction);
|
|
583
|
+
return new Proxy({}, {
|
|
584
|
+
get: function (target, prop) {
|
|
585
|
+
if (typeof prop === 'string') {
|
|
586
|
+
if (Object.prototype.hasOwnProperty.call(rawQueryClient, prop)) {
|
|
587
|
+
return rawQueryClient[prop];
|
|
588
|
+
}
|
|
589
|
+
// 返回一个函数,这个函数接受任意参数并返回一个 Promise
|
|
590
|
+
return generateClientByDataSourceName(prop, callFunction);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
});
|
|
594
|
+
};
|
|
595
|
+
|
|
596
|
+
function initHTTPOverCallFunction(cloud, options) {
|
|
496
597
|
var _this = this;
|
|
497
598
|
if (!cloud) {
|
|
498
599
|
throw new Error('cloud is required');
|
|
@@ -501,43 +602,63 @@
|
|
|
501
602
|
throw new Error('cloud.callFunction is required');
|
|
502
603
|
}
|
|
503
604
|
var callFunction = cloud.callFunction.bind(cloud);
|
|
504
|
-
var
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
var
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
605
|
+
var ormClient;
|
|
606
|
+
try {
|
|
607
|
+
var HTTPOverCallFunctionFetch = function (_a) {
|
|
608
|
+
var url = _a.url, body = _a.body, method = _a.method, headers = _a.headers;
|
|
609
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
610
|
+
var res, result;
|
|
611
|
+
var _b;
|
|
612
|
+
return __generator(this, function (_c) {
|
|
613
|
+
switch (_c.label) {
|
|
614
|
+
case 0: return [4 /*yield*/, callFunction({
|
|
615
|
+
name: 'httpOverCallFunction',
|
|
616
|
+
data: {
|
|
617
|
+
url: url,
|
|
618
|
+
method: method === null || method === void 0 ? void 0 : method.toUpperCase(),
|
|
619
|
+
headers: __assign(__assign({}, (headers || {})), { 'Content-Type': 'application/json' }),
|
|
620
|
+
body: body
|
|
621
|
+
}
|
|
622
|
+
})];
|
|
623
|
+
case 1:
|
|
624
|
+
res = _c.sent();
|
|
625
|
+
result = (_b = res === null || res === void 0 ? void 0 : res.result) === null || _b === void 0 ? void 0 : _b.body;
|
|
626
|
+
return [2 /*return*/, result];
|
|
627
|
+
}
|
|
628
|
+
});
|
|
525
629
|
});
|
|
630
|
+
};
|
|
631
|
+
var baseUrl = (options === null || options === void 0 ? void 0 : options.baseUrl) || getDefaultGatewayBaseUrl(cloud).model;
|
|
632
|
+
var sqlBaseUrl = (options === null || options === void 0 ? void 0 : options.sqlBaseUrl) || getDefaultGatewayBaseUrl(cloud).sql;
|
|
633
|
+
ormClient = generateHTTPClient(callFunction, HTTPOverCallFunctionFetch, baseUrl, {
|
|
634
|
+
sqlBaseUrl: sqlBaseUrl
|
|
526
635
|
});
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
cloud
|
|
636
|
+
}
|
|
637
|
+
catch (e) {
|
|
638
|
+
console.error('init http orm client failed, try call function orm', e);
|
|
639
|
+
ormClient = generateClient(callFunction);
|
|
640
|
+
}
|
|
641
|
+
cloud.models = ormClient;
|
|
642
|
+
return cloud;
|
|
643
|
+
}
|
|
644
|
+
function init(cloud) {
|
|
645
|
+
if (!cloud) {
|
|
646
|
+
throw new Error('cloud is required');
|
|
647
|
+
}
|
|
648
|
+
if (!cloud.callFunction) {
|
|
649
|
+
throw new Error('cloud.callFunction is required');
|
|
650
|
+
}
|
|
651
|
+
var ormClientImpl = generateClient(cloud.callFunction.bind(cloud));
|
|
652
|
+
cloud.models = ormClientImpl;
|
|
534
653
|
return cloud;
|
|
535
654
|
}
|
|
536
655
|
function getDefaultGatewayBaseUrl(cloud) {
|
|
537
|
-
var _a, _b, _c;
|
|
656
|
+
var _a, _b, _c, _d;
|
|
538
657
|
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
658
|
if (typeof env !== 'string' || !env.trim())
|
|
540
659
|
env = (_c = cloud === null || cloud === void 0 ? void 0 : cloud.config) === null || _c === void 0 ? void 0 : _c.env;
|
|
660
|
+
if (typeof env !== 'string' || !env.trim())
|
|
661
|
+
env = (_d = cloud === null || cloud === void 0 ? void 0 : cloud.config) === null || _d === void 0 ? void 0 : _d.envName;
|
|
541
662
|
if (typeof env !== 'string' || !env.trim()) {
|
|
542
663
|
throw new Error('Generating default gateway base url failed: env not found');
|
|
543
664
|
}
|
|
@@ -555,6 +676,7 @@
|
|
|
555
676
|
exports.default = index;
|
|
556
677
|
exports.generateHTTPClient = generateHTTPClient;
|
|
557
678
|
exports.init = init;
|
|
679
|
+
exports.initHTTPOverCallFunction = initHTTPOverCallFunction;
|
|
558
680
|
|
|
559
681
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
560
682
|
|