@cloudbase/wx-cloud-client-sdk 1.5.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 +6 -2
- package/lib/orm/http-orm-client.d.ts +1 -4
- package/lib/types/index.d.ts +3 -1
- package/lib/wxCloudClientSDK.cjs.js +167 -102
- package/lib/wxCloudClientSDK.esm.js +167 -103
- package/lib/wxCloudClientSDK.umd.js +167 -102
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
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 initHTTPOverCallFunction(cloud: CloudBaseInstance, options?: {
|
|
4
|
+
baseUrl?: string;
|
|
5
|
+
sqlBaseUrl?: string;
|
|
6
|
+
}): ExtendedCloudBaseInstance;
|
|
3
7
|
export declare function init(cloud: CloudBaseInstance): ExtendedCloudBaseInstance;
|
|
4
8
|
export * from './types';
|
|
5
9
|
export { generateHTTPClient };
|
|
@@ -7,6 +11,6 @@ declare const _default: {
|
|
|
7
11
|
init: typeof init;
|
|
8
12
|
generateHTTPClient: (callFunction: import("./types").CallFunction, fetch: (options: import("@cloudbase/adapter-interface").IFetchOptions) => any, baseUrl: string, options?: {
|
|
9
13
|
sqlBaseUrl?: string | undefined;
|
|
10
|
-
} | undefined) =>
|
|
14
|
+
} | undefined) => OrmClient;
|
|
11
15
|
};
|
|
12
16
|
export default _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.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;
|
|
@@ -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,6 +490,155 @@ var generateHTTPClientByDataSourceName = function (baseUrl, modelName, fetch, op
|
|
|
591
490
|
return client;
|
|
592
491
|
};
|
|
593
492
|
|
|
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) {
|
|
595
|
+
var _this = this;
|
|
596
|
+
if (!cloud) {
|
|
597
|
+
throw new Error('cloud is required');
|
|
598
|
+
}
|
|
599
|
+
if (!cloud.callFunction) {
|
|
600
|
+
throw new Error('cloud.callFunction is required');
|
|
601
|
+
}
|
|
602
|
+
var callFunction = cloud.callFunction.bind(cloud);
|
|
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
|
+
});
|
|
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
|
|
633
|
+
});
|
|
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
|
+
}
|
|
594
642
|
function init(cloud) {
|
|
595
643
|
if (!cloud) {
|
|
596
644
|
throw new Error('cloud is required');
|
|
@@ -602,6 +650,22 @@ function init(cloud) {
|
|
|
602
650
|
cloud.models = ormClientImpl;
|
|
603
651
|
return cloud;
|
|
604
652
|
}
|
|
653
|
+
function getDefaultGatewayBaseUrl(cloud) {
|
|
654
|
+
var _a, _b, _c, _d;
|
|
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;
|
|
656
|
+
if (typeof env !== 'string' || !env.trim())
|
|
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;
|
|
660
|
+
if (typeof env !== 'string' || !env.trim()) {
|
|
661
|
+
throw new Error('Generating default gateway base url failed: env not found');
|
|
662
|
+
}
|
|
663
|
+
env = env.trim();
|
|
664
|
+
return {
|
|
665
|
+
model: "https://".concat(env, ".api.tcloudbasegateway.com/v1/model"),
|
|
666
|
+
sql: "https://".concat(env, ".api.tcloudbasegateway.com/v1/sql")
|
|
667
|
+
};
|
|
668
|
+
}
|
|
605
669
|
var index = {
|
|
606
670
|
init: init,
|
|
607
671
|
generateHTTPClient: generateHTTPClient
|
|
@@ -610,3 +674,4 @@ var index = {
|
|
|
610
674
|
exports.default = index;
|
|
611
675
|
exports.generateHTTPClient = generateHTTPClient;
|
|
612
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.
|
|
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;
|
|
@@ -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,6 +486,155 @@ var generateHTTPClientByDataSourceName = function (baseUrl, modelName, fetch, op
|
|
|
587
486
|
return client;
|
|
588
487
|
};
|
|
589
488
|
|
|
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) {
|
|
591
|
+
var _this = this;
|
|
592
|
+
if (!cloud) {
|
|
593
|
+
throw new Error('cloud is required');
|
|
594
|
+
}
|
|
595
|
+
if (!cloud.callFunction) {
|
|
596
|
+
throw new Error('cloud.callFunction is required');
|
|
597
|
+
}
|
|
598
|
+
var callFunction = cloud.callFunction.bind(cloud);
|
|
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
|
+
});
|
|
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
|
|
629
|
+
});
|
|
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
|
+
}
|
|
590
638
|
function init(cloud) {
|
|
591
639
|
if (!cloud) {
|
|
592
640
|
throw new Error('cloud is required');
|
|
@@ -598,9 +646,25 @@ function init(cloud) {
|
|
|
598
646
|
cloud.models = ormClientImpl;
|
|
599
647
|
return cloud;
|
|
600
648
|
}
|
|
649
|
+
function getDefaultGatewayBaseUrl(cloud) {
|
|
650
|
+
var _a, _b, _c, _d;
|
|
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;
|
|
652
|
+
if (typeof env !== 'string' || !env.trim())
|
|
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;
|
|
656
|
+
if (typeof env !== 'string' || !env.trim()) {
|
|
657
|
+
throw new Error('Generating default gateway base url failed: env not found');
|
|
658
|
+
}
|
|
659
|
+
env = env.trim();
|
|
660
|
+
return {
|
|
661
|
+
model: "https://".concat(env, ".api.tcloudbasegateway.com/v1/model"),
|
|
662
|
+
sql: "https://".concat(env, ".api.tcloudbasegateway.com/v1/sql")
|
|
663
|
+
};
|
|
664
|
+
}
|
|
601
665
|
var index = {
|
|
602
666
|
init: init,
|
|
603
667
|
generateHTTPClient: generateHTTPClient
|
|
604
668
|
};
|
|
605
669
|
|
|
606
|
-
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.
|
|
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;
|
|
@@ -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,6 +492,155 @@
|
|
|
593
492
|
return client;
|
|
594
493
|
};
|
|
595
494
|
|
|
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) {
|
|
597
|
+
var _this = this;
|
|
598
|
+
if (!cloud) {
|
|
599
|
+
throw new Error('cloud is required');
|
|
600
|
+
}
|
|
601
|
+
if (!cloud.callFunction) {
|
|
602
|
+
throw new Error('cloud.callFunction is required');
|
|
603
|
+
}
|
|
604
|
+
var callFunction = cloud.callFunction.bind(cloud);
|
|
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
|
+
});
|
|
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
|
|
635
|
+
});
|
|
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
|
+
}
|
|
596
644
|
function init(cloud) {
|
|
597
645
|
if (!cloud) {
|
|
598
646
|
throw new Error('cloud is required');
|
|
@@ -604,6 +652,22 @@
|
|
|
604
652
|
cloud.models = ormClientImpl;
|
|
605
653
|
return cloud;
|
|
606
654
|
}
|
|
655
|
+
function getDefaultGatewayBaseUrl(cloud) {
|
|
656
|
+
var _a, _b, _c, _d;
|
|
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;
|
|
658
|
+
if (typeof env !== 'string' || !env.trim())
|
|
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;
|
|
662
|
+
if (typeof env !== 'string' || !env.trim()) {
|
|
663
|
+
throw new Error('Generating default gateway base url failed: env not found');
|
|
664
|
+
}
|
|
665
|
+
env = env.trim();
|
|
666
|
+
return {
|
|
667
|
+
model: "https://".concat(env, ".api.tcloudbasegateway.com/v1/model"),
|
|
668
|
+
sql: "https://".concat(env, ".api.tcloudbasegateway.com/v1/sql")
|
|
669
|
+
};
|
|
670
|
+
}
|
|
607
671
|
var index = {
|
|
608
672
|
init: init,
|
|
609
673
|
generateHTTPClient: generateHTTPClient
|
|
@@ -612,6 +676,7 @@
|
|
|
612
676
|
exports.default = index;
|
|
613
677
|
exports.generateHTTPClient = generateHTTPClient;
|
|
614
678
|
exports.init = init;
|
|
679
|
+
exports.initHTTPOverCallFunction = initHTTPOverCallFunction;
|
|
615
680
|
|
|
616
681
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
617
682
|
|
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.1",
|
|
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",
|