@cloudbase/wx-cloud-client-sdk
Advanced tools
+4
-3
@@ -1,7 +0,8 @@ | ||
| import { CloudBaseInstance, ExtendedCloudBaseInstance } from './types'; | ||
| import { CloudBaseInstance, ExtendedCloudBaseInstance, OrmClient } from './types'; | ||
| import { generateHTTPClient } from './orm/http-orm-client'; | ||
| export declare function init(cloud: CloudBaseInstance, options?: { | ||
| export declare function initHTTPOverCallFunction(cloud: CloudBaseInstance, options?: { | ||
| baseUrl?: string; | ||
| sqlBaseUrl?: string; | ||
| }): ExtendedCloudBaseInstance; | ||
| export declare function init(cloud: CloudBaseInstance): ExtendedCloudBaseInstance; | ||
| export * from './types'; | ||
@@ -13,4 +14,4 @@ export { generateHTTPClient }; | ||
| sqlBaseUrl?: string | undefined; | ||
| } | undefined) => import("./types").OrmClient; | ||
| } | undefined) => OrmClient; | ||
| }; | ||
| export default _default; |
+153
-31
@@ -148,3 +148,3 @@ 'use strict'; | ||
| } | ||
| var VERSION = "1.6.0"; | ||
| var VERSION = "1.6.1"; | ||
@@ -494,3 +494,104 @@ var callDataSource = function (_a) { | ||
| function init(cloud, options) { | ||
| var CRUD_METHODS = { | ||
| create: { | ||
| methodName: 'wedaCreateV2' | ||
| }, | ||
| createMany: { | ||
| methodName: 'wedaBatchCreateV2' | ||
| }, | ||
| update: { | ||
| methodName: 'wedaUpdateV2' | ||
| }, | ||
| upsert: { | ||
| methodName: 'wedaUpsertV2' | ||
| }, | ||
| updateMany: { | ||
| methodName: 'wedaBatchUpdateV2' | ||
| }, | ||
| "delete": { | ||
| methodName: 'wedaDeleteV2' | ||
| }, | ||
| deleteMany: { | ||
| methodName: 'wedaBatchDeleteV2' | ||
| }, | ||
| get: { | ||
| methodName: 'wedaGetItemV2', | ||
| defaultParams: { | ||
| filter: { | ||
| where: {} | ||
| }, | ||
| select: { | ||
| $master: true | ||
| } | ||
| } | ||
| }, | ||
| list: { | ||
| methodName: 'wedaGetRecordsV2', | ||
| defaultParams: { | ||
| filter: { | ||
| where: {} | ||
| }, | ||
| select: { | ||
| $master: true | ||
| } | ||
| } | ||
| } | ||
| }; | ||
| var generateClientByDataSourceName = function (dataSourceName, callFunction) { | ||
| var client = new Proxy({}, { | ||
| get: function (target, methodName) { | ||
| var operation = CRUD_METHODS[methodName]; | ||
| if (!operation) { | ||
| var error = new Error("\u4E0D\u652F\u6301\u7684\u64CD\u4F5C: ".concat(methodName)); | ||
| throw new WxCloudSDKError(error.message || 'Unknown error occurred', { | ||
| originError: error, | ||
| code: 'NotSupported', | ||
| requestId: 'N/A' | ||
| }); | ||
| } | ||
| return function (params) { return __awaiter(void 0, void 0, void 0, function () { | ||
| var effectiveParams, rawData, result, dataKey; | ||
| var _a; | ||
| return __generator(this, function (_b) { | ||
| switch (_b.label) { | ||
| case 0: | ||
| effectiveParams = __assign(__assign({}, (operation.defaultParams || {})), (params || {})); | ||
| return [4 /*yield*/, callDataSource({ | ||
| callFunction: callFunction, | ||
| dataSourceName: dataSourceName, | ||
| methodName: operation.methodName, | ||
| realMethodName: methodName, | ||
| params: effectiveParams, | ||
| envType: params === null || params === void 0 ? void 0 : params.envType | ||
| })]; | ||
| case 1: | ||
| rawData = _b.sent(); | ||
| result = { data: {} }; | ||
| dataKey = operation.responseKey; | ||
| 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; | ||
| return [2 /*return*/, result]; | ||
| } | ||
| }); | ||
| }); }; | ||
| } | ||
| }); | ||
| return client; | ||
| }; | ||
| // 使用 TypeScript 的 Proxy 来定义一个动态的客户端 | ||
| var generateClient = function (callFunction) { | ||
| var rawQueryClient = createRawQueryClient(callFunction); | ||
| return new Proxy({}, { | ||
| get: function (target, prop) { | ||
| if (typeof prop === 'string') { | ||
| if (Object.prototype.hasOwnProperty.call(rawQueryClient, prop)) { | ||
| return rawQueryClient[prop]; | ||
| } | ||
| // 返回一个函数,这个函数接受任意参数并返回一个 Promise | ||
| return generateClientByDataSourceName(prop, callFunction); | ||
| } | ||
| } | ||
| }); | ||
| }; | ||
| function initHTTPOverCallFunction(cloud, options) { | ||
| var _this = this; | ||
@@ -504,39 +605,59 @@ if (!cloud) { | ||
| var callFunction = cloud.callFunction.bind(cloud); | ||
| var HTTPOverCallFunctionFetch = function (_a) { | ||
| var url = _a.url, body = _a.body, method = _a.method, headers = _a.headers; | ||
| return __awaiter(_this, void 0, void 0, function () { | ||
| var res, result; | ||
| var _b; | ||
| return __generator(this, function (_c) { | ||
| switch (_c.label) { | ||
| case 0: return [4 /*yield*/, callFunction({ | ||
| name: 'httpOverCallFunction', | ||
| data: { | ||
| url: url, | ||
| method: method === null || method === void 0 ? void 0 : method.toUpperCase(), | ||
| headers: __assign(__assign({}, (headers || {})), { 'Content-Type': 'application/json' }), | ||
| body: body | ||
| } | ||
| })]; | ||
| case 1: | ||
| res = _c.sent(); | ||
| result = (_b = res === null || res === void 0 ? void 0 : res.result) === null || _b === void 0 ? void 0 : _b.body; | ||
| return [2 /*return*/, result]; | ||
| } | ||
| var ormClient; | ||
| try { | ||
| var HTTPOverCallFunctionFetch = function (_a) { | ||
| var url = _a.url, body = _a.body, method = _a.method, headers = _a.headers; | ||
| return __awaiter(_this, void 0, void 0, function () { | ||
| var res, result; | ||
| var _b; | ||
| return __generator(this, function (_c) { | ||
| switch (_c.label) { | ||
| case 0: return [4 /*yield*/, callFunction({ | ||
| name: 'httpOverCallFunction', | ||
| data: { | ||
| url: url, | ||
| method: method === null || method === void 0 ? void 0 : method.toUpperCase(), | ||
| headers: __assign(__assign({}, (headers || {})), { 'Content-Type': 'application/json' }), | ||
| body: body | ||
| } | ||
| })]; | ||
| case 1: | ||
| res = _c.sent(); | ||
| result = (_b = res === null || res === void 0 ? void 0 : res.result) === null || _b === void 0 ? void 0 : _b.body; | ||
| return [2 /*return*/, result]; | ||
| } | ||
| }); | ||
| }); | ||
| }; | ||
| var baseUrl = (options === null || options === void 0 ? void 0 : options.baseUrl) || getDefaultGatewayBaseUrl(cloud).model; | ||
| var sqlBaseUrl = (options === null || options === void 0 ? void 0 : options.sqlBaseUrl) || getDefaultGatewayBaseUrl(cloud).sql; | ||
| ormClient = generateHTTPClient(callFunction, HTTPOverCallFunctionFetch, baseUrl, { | ||
| sqlBaseUrl: sqlBaseUrl | ||
| }); | ||
| }; | ||
| var baseUrl = (options === null || options === void 0 ? void 0 : options.baseUrl) || getDefaultGatewayBaseUrl(cloud).model; | ||
| var sqlBaseUrl = (options === null || options === void 0 ? void 0 : options.sqlBaseUrl) || getDefaultGatewayBaseUrl(cloud).sql; | ||
| var httpOrmClientImpl = generateHTTPClient(callFunction, HTTPOverCallFunctionFetch, baseUrl, { | ||
| sqlBaseUrl: sqlBaseUrl | ||
| }); | ||
| cloud.models = httpOrmClientImpl; | ||
| } | ||
| catch (e) { | ||
| console.error('init http orm client failed, try call function orm', e); | ||
| ormClient = generateClient(callFunction); | ||
| } | ||
| cloud.models = ormClient; | ||
| return cloud; | ||
| } | ||
| function init(cloud) { | ||
| if (!cloud) { | ||
| throw new Error('cloud is required'); | ||
| } | ||
| if (!cloud.callFunction) { | ||
| throw new Error('cloud.callFunction is required'); | ||
| } | ||
| var ormClientImpl = generateClient(cloud.callFunction.bind(cloud)); | ||
| cloud.models = ormClientImpl; | ||
| return cloud; | ||
| } | ||
| function getDefaultGatewayBaseUrl(cloud) { | ||
| var _a, _b, _c; | ||
| var _a, _b, _c, _d; | ||
| 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; | ||
| if (typeof env !== 'string' || !env.trim()) | ||
| env = (_c = cloud === null || cloud === void 0 ? void 0 : cloud.config) === null || _c === void 0 ? void 0 : _c.env; | ||
| if (typeof env !== 'string' || !env.trim()) | ||
| env = (_d = cloud === null || cloud === void 0 ? void 0 : cloud.config) === null || _d === void 0 ? void 0 : _d.envName; | ||
| if (typeof env !== 'string' || !env.trim()) { | ||
@@ -559,1 +680,2 @@ throw new Error('Generating default gateway base url failed: env not found'); | ||
| exports.init = init; | ||
| exports.initHTTPOverCallFunction = initHTTPOverCallFunction; |
+153
-32
@@ -144,3 +144,3 @@ /****************************************************************************** | ||
| } | ||
| var VERSION = "1.6.0"; | ||
| var VERSION = "1.6.1"; | ||
@@ -490,3 +490,104 @@ var callDataSource = function (_a) { | ||
| function init(cloud, options) { | ||
| var CRUD_METHODS = { | ||
| create: { | ||
| methodName: 'wedaCreateV2' | ||
| }, | ||
| createMany: { | ||
| methodName: 'wedaBatchCreateV2' | ||
| }, | ||
| update: { | ||
| methodName: 'wedaUpdateV2' | ||
| }, | ||
| upsert: { | ||
| methodName: 'wedaUpsertV2' | ||
| }, | ||
| updateMany: { | ||
| methodName: 'wedaBatchUpdateV2' | ||
| }, | ||
| "delete": { | ||
| methodName: 'wedaDeleteV2' | ||
| }, | ||
| deleteMany: { | ||
| methodName: 'wedaBatchDeleteV2' | ||
| }, | ||
| get: { | ||
| methodName: 'wedaGetItemV2', | ||
| defaultParams: { | ||
| filter: { | ||
| where: {} | ||
| }, | ||
| select: { | ||
| $master: true | ||
| } | ||
| } | ||
| }, | ||
| list: { | ||
| methodName: 'wedaGetRecordsV2', | ||
| defaultParams: { | ||
| filter: { | ||
| where: {} | ||
| }, | ||
| select: { | ||
| $master: true | ||
| } | ||
| } | ||
| } | ||
| }; | ||
| var generateClientByDataSourceName = function (dataSourceName, callFunction) { | ||
| var client = new Proxy({}, { | ||
| get: function (target, methodName) { | ||
| var operation = CRUD_METHODS[methodName]; | ||
| if (!operation) { | ||
| var error = new Error("\u4E0D\u652F\u6301\u7684\u64CD\u4F5C: ".concat(methodName)); | ||
| throw new WxCloudSDKError(error.message || 'Unknown error occurred', { | ||
| originError: error, | ||
| code: 'NotSupported', | ||
| requestId: 'N/A' | ||
| }); | ||
| } | ||
| return function (params) { return __awaiter(void 0, void 0, void 0, function () { | ||
| var effectiveParams, rawData, result, dataKey; | ||
| var _a; | ||
| return __generator(this, function (_b) { | ||
| switch (_b.label) { | ||
| case 0: | ||
| effectiveParams = __assign(__assign({}, (operation.defaultParams || {})), (params || {})); | ||
| return [4 /*yield*/, callDataSource({ | ||
| callFunction: callFunction, | ||
| dataSourceName: dataSourceName, | ||
| methodName: operation.methodName, | ||
| realMethodName: methodName, | ||
| params: effectiveParams, | ||
| envType: params === null || params === void 0 ? void 0 : params.envType | ||
| })]; | ||
| case 1: | ||
| rawData = _b.sent(); | ||
| result = { data: {} }; | ||
| dataKey = operation.responseKey; | ||
| 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; | ||
| return [2 /*return*/, result]; | ||
| } | ||
| }); | ||
| }); }; | ||
| } | ||
| }); | ||
| return client; | ||
| }; | ||
| // 使用 TypeScript 的 Proxy 来定义一个动态的客户端 | ||
| var generateClient = function (callFunction) { | ||
| var rawQueryClient = createRawQueryClient(callFunction); | ||
| return new Proxy({}, { | ||
| get: function (target, prop) { | ||
| if (typeof prop === 'string') { | ||
| if (Object.prototype.hasOwnProperty.call(rawQueryClient, prop)) { | ||
| return rawQueryClient[prop]; | ||
| } | ||
| // 返回一个函数,这个函数接受任意参数并返回一个 Promise | ||
| return generateClientByDataSourceName(prop, callFunction); | ||
| } | ||
| } | ||
| }); | ||
| }; | ||
| function initHTTPOverCallFunction(cloud, options) { | ||
| var _this = this; | ||
@@ -500,39 +601,59 @@ if (!cloud) { | ||
| var callFunction = cloud.callFunction.bind(cloud); | ||
| var HTTPOverCallFunctionFetch = function (_a) { | ||
| var url = _a.url, body = _a.body, method = _a.method, headers = _a.headers; | ||
| return __awaiter(_this, void 0, void 0, function () { | ||
| var res, result; | ||
| var _b; | ||
| return __generator(this, function (_c) { | ||
| switch (_c.label) { | ||
| case 0: return [4 /*yield*/, callFunction({ | ||
| name: 'httpOverCallFunction', | ||
| data: { | ||
| url: url, | ||
| method: method === null || method === void 0 ? void 0 : method.toUpperCase(), | ||
| headers: __assign(__assign({}, (headers || {})), { 'Content-Type': 'application/json' }), | ||
| body: body | ||
| } | ||
| })]; | ||
| case 1: | ||
| res = _c.sent(); | ||
| result = (_b = res === null || res === void 0 ? void 0 : res.result) === null || _b === void 0 ? void 0 : _b.body; | ||
| return [2 /*return*/, result]; | ||
| } | ||
| var ormClient; | ||
| try { | ||
| var HTTPOverCallFunctionFetch = function (_a) { | ||
| var url = _a.url, body = _a.body, method = _a.method, headers = _a.headers; | ||
| return __awaiter(_this, void 0, void 0, function () { | ||
| var res, result; | ||
| var _b; | ||
| return __generator(this, function (_c) { | ||
| switch (_c.label) { | ||
| case 0: return [4 /*yield*/, callFunction({ | ||
| name: 'httpOverCallFunction', | ||
| data: { | ||
| url: url, | ||
| method: method === null || method === void 0 ? void 0 : method.toUpperCase(), | ||
| headers: __assign(__assign({}, (headers || {})), { 'Content-Type': 'application/json' }), | ||
| body: body | ||
| } | ||
| })]; | ||
| case 1: | ||
| res = _c.sent(); | ||
| result = (_b = res === null || res === void 0 ? void 0 : res.result) === null || _b === void 0 ? void 0 : _b.body; | ||
| return [2 /*return*/, result]; | ||
| } | ||
| }); | ||
| }); | ||
| }; | ||
| var baseUrl = (options === null || options === void 0 ? void 0 : options.baseUrl) || getDefaultGatewayBaseUrl(cloud).model; | ||
| var sqlBaseUrl = (options === null || options === void 0 ? void 0 : options.sqlBaseUrl) || getDefaultGatewayBaseUrl(cloud).sql; | ||
| ormClient = generateHTTPClient(callFunction, HTTPOverCallFunctionFetch, baseUrl, { | ||
| sqlBaseUrl: sqlBaseUrl | ||
| }); | ||
| }; | ||
| var baseUrl = (options === null || options === void 0 ? void 0 : options.baseUrl) || getDefaultGatewayBaseUrl(cloud).model; | ||
| var sqlBaseUrl = (options === null || options === void 0 ? void 0 : options.sqlBaseUrl) || getDefaultGatewayBaseUrl(cloud).sql; | ||
| var httpOrmClientImpl = generateHTTPClient(callFunction, HTTPOverCallFunctionFetch, baseUrl, { | ||
| sqlBaseUrl: sqlBaseUrl | ||
| }); | ||
| cloud.models = httpOrmClientImpl; | ||
| } | ||
| catch (e) { | ||
| console.error('init http orm client failed, try call function orm', e); | ||
| ormClient = generateClient(callFunction); | ||
| } | ||
| cloud.models = ormClient; | ||
| return cloud; | ||
| } | ||
| function init(cloud) { | ||
| if (!cloud) { | ||
| throw new Error('cloud is required'); | ||
| } | ||
| if (!cloud.callFunction) { | ||
| throw new Error('cloud.callFunction is required'); | ||
| } | ||
| var ormClientImpl = generateClient(cloud.callFunction.bind(cloud)); | ||
| cloud.models = ormClientImpl; | ||
| return cloud; | ||
| } | ||
| function getDefaultGatewayBaseUrl(cloud) { | ||
| var _a, _b, _c; | ||
| var _a, _b, _c, _d; | ||
| 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; | ||
| if (typeof env !== 'string' || !env.trim()) | ||
| env = (_c = cloud === null || cloud === void 0 ? void 0 : cloud.config) === null || _c === void 0 ? void 0 : _c.env; | ||
| if (typeof env !== 'string' || !env.trim()) | ||
| env = (_d = cloud === null || cloud === void 0 ? void 0 : cloud.config) === null || _d === void 0 ? void 0 : _d.envName; | ||
| if (typeof env !== 'string' || !env.trim()) { | ||
@@ -552,2 +673,2 @@ throw new Error('Generating default gateway base url failed: env not found'); | ||
| export { index as default, generateHTTPClient, init }; | ||
| export { index as default, generateHTTPClient, init, initHTTPOverCallFunction }; |
+153
-31
@@ -150,3 +150,3 @@ (function (global, factory) { | ||
| } | ||
| var VERSION = "1.6.0"; | ||
| var VERSION = "1.6.1"; | ||
@@ -496,3 +496,104 @@ var callDataSource = function (_a) { | ||
| function init(cloud, options) { | ||
| var CRUD_METHODS = { | ||
| create: { | ||
| methodName: 'wedaCreateV2' | ||
| }, | ||
| createMany: { | ||
| methodName: 'wedaBatchCreateV2' | ||
| }, | ||
| update: { | ||
| methodName: 'wedaUpdateV2' | ||
| }, | ||
| upsert: { | ||
| methodName: 'wedaUpsertV2' | ||
| }, | ||
| updateMany: { | ||
| methodName: 'wedaBatchUpdateV2' | ||
| }, | ||
| "delete": { | ||
| methodName: 'wedaDeleteV2' | ||
| }, | ||
| deleteMany: { | ||
| methodName: 'wedaBatchDeleteV2' | ||
| }, | ||
| get: { | ||
| methodName: 'wedaGetItemV2', | ||
| defaultParams: { | ||
| filter: { | ||
| where: {} | ||
| }, | ||
| select: { | ||
| $master: true | ||
| } | ||
| } | ||
| }, | ||
| list: { | ||
| methodName: 'wedaGetRecordsV2', | ||
| defaultParams: { | ||
| filter: { | ||
| where: {} | ||
| }, | ||
| select: { | ||
| $master: true | ||
| } | ||
| } | ||
| } | ||
| }; | ||
| var generateClientByDataSourceName = function (dataSourceName, callFunction) { | ||
| var client = new Proxy({}, { | ||
| get: function (target, methodName) { | ||
| var operation = CRUD_METHODS[methodName]; | ||
| if (!operation) { | ||
| var error = new Error("\u4E0D\u652F\u6301\u7684\u64CD\u4F5C: ".concat(methodName)); | ||
| throw new WxCloudSDKError(error.message || 'Unknown error occurred', { | ||
| originError: error, | ||
| code: 'NotSupported', | ||
| requestId: 'N/A' | ||
| }); | ||
| } | ||
| return function (params) { return __awaiter(void 0, void 0, void 0, function () { | ||
| var effectiveParams, rawData, result, dataKey; | ||
| var _a; | ||
| return __generator(this, function (_b) { | ||
| switch (_b.label) { | ||
| case 0: | ||
| effectiveParams = __assign(__assign({}, (operation.defaultParams || {})), (params || {})); | ||
| return [4 /*yield*/, callDataSource({ | ||
| callFunction: callFunction, | ||
| dataSourceName: dataSourceName, | ||
| methodName: operation.methodName, | ||
| realMethodName: methodName, | ||
| params: effectiveParams, | ||
| envType: params === null || params === void 0 ? void 0 : params.envType | ||
| })]; | ||
| case 1: | ||
| rawData = _b.sent(); | ||
| result = { data: {} }; | ||
| dataKey = operation.responseKey; | ||
| 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; | ||
| return [2 /*return*/, result]; | ||
| } | ||
| }); | ||
| }); }; | ||
| } | ||
| }); | ||
| return client; | ||
| }; | ||
| // 使用 TypeScript 的 Proxy 来定义一个动态的客户端 | ||
| var generateClient = function (callFunction) { | ||
| var rawQueryClient = createRawQueryClient(callFunction); | ||
| return new Proxy({}, { | ||
| get: function (target, prop) { | ||
| if (typeof prop === 'string') { | ||
| if (Object.prototype.hasOwnProperty.call(rawQueryClient, prop)) { | ||
| return rawQueryClient[prop]; | ||
| } | ||
| // 返回一个函数,这个函数接受任意参数并返回一个 Promise | ||
| return generateClientByDataSourceName(prop, callFunction); | ||
| } | ||
| } | ||
| }); | ||
| }; | ||
| function initHTTPOverCallFunction(cloud, options) { | ||
| var _this = this; | ||
@@ -506,39 +607,59 @@ if (!cloud) { | ||
| var callFunction = cloud.callFunction.bind(cloud); | ||
| var HTTPOverCallFunctionFetch = function (_a) { | ||
| var url = _a.url, body = _a.body, method = _a.method, headers = _a.headers; | ||
| return __awaiter(_this, void 0, void 0, function () { | ||
| var res, result; | ||
| var _b; | ||
| return __generator(this, function (_c) { | ||
| switch (_c.label) { | ||
| case 0: return [4 /*yield*/, callFunction({ | ||
| name: 'httpOverCallFunction', | ||
| data: { | ||
| url: url, | ||
| method: method === null || method === void 0 ? void 0 : method.toUpperCase(), | ||
| headers: __assign(__assign({}, (headers || {})), { 'Content-Type': 'application/json' }), | ||
| body: body | ||
| } | ||
| })]; | ||
| case 1: | ||
| res = _c.sent(); | ||
| result = (_b = res === null || res === void 0 ? void 0 : res.result) === null || _b === void 0 ? void 0 : _b.body; | ||
| return [2 /*return*/, result]; | ||
| } | ||
| var ormClient; | ||
| try { | ||
| var HTTPOverCallFunctionFetch = function (_a) { | ||
| var url = _a.url, body = _a.body, method = _a.method, headers = _a.headers; | ||
| return __awaiter(_this, void 0, void 0, function () { | ||
| var res, result; | ||
| var _b; | ||
| return __generator(this, function (_c) { | ||
| switch (_c.label) { | ||
| case 0: return [4 /*yield*/, callFunction({ | ||
| name: 'httpOverCallFunction', | ||
| data: { | ||
| url: url, | ||
| method: method === null || method === void 0 ? void 0 : method.toUpperCase(), | ||
| headers: __assign(__assign({}, (headers || {})), { 'Content-Type': 'application/json' }), | ||
| body: body | ||
| } | ||
| })]; | ||
| case 1: | ||
| res = _c.sent(); | ||
| result = (_b = res === null || res === void 0 ? void 0 : res.result) === null || _b === void 0 ? void 0 : _b.body; | ||
| return [2 /*return*/, result]; | ||
| } | ||
| }); | ||
| }); | ||
| }; | ||
| var baseUrl = (options === null || options === void 0 ? void 0 : options.baseUrl) || getDefaultGatewayBaseUrl(cloud).model; | ||
| var sqlBaseUrl = (options === null || options === void 0 ? void 0 : options.sqlBaseUrl) || getDefaultGatewayBaseUrl(cloud).sql; | ||
| ormClient = generateHTTPClient(callFunction, HTTPOverCallFunctionFetch, baseUrl, { | ||
| sqlBaseUrl: sqlBaseUrl | ||
| }); | ||
| }; | ||
| var baseUrl = (options === null || options === void 0 ? void 0 : options.baseUrl) || getDefaultGatewayBaseUrl(cloud).model; | ||
| var sqlBaseUrl = (options === null || options === void 0 ? void 0 : options.sqlBaseUrl) || getDefaultGatewayBaseUrl(cloud).sql; | ||
| var httpOrmClientImpl = generateHTTPClient(callFunction, HTTPOverCallFunctionFetch, baseUrl, { | ||
| sqlBaseUrl: sqlBaseUrl | ||
| }); | ||
| cloud.models = httpOrmClientImpl; | ||
| } | ||
| catch (e) { | ||
| console.error('init http orm client failed, try call function orm', e); | ||
| ormClient = generateClient(callFunction); | ||
| } | ||
| cloud.models = ormClient; | ||
| return cloud; | ||
| } | ||
| function init(cloud) { | ||
| if (!cloud) { | ||
| throw new Error('cloud is required'); | ||
| } | ||
| if (!cloud.callFunction) { | ||
| throw new Error('cloud.callFunction is required'); | ||
| } | ||
| var ormClientImpl = generateClient(cloud.callFunction.bind(cloud)); | ||
| cloud.models = ormClientImpl; | ||
| return cloud; | ||
| } | ||
| function getDefaultGatewayBaseUrl(cloud) { | ||
| var _a, _b, _c; | ||
| var _a, _b, _c, _d; | ||
| 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; | ||
| if (typeof env !== 'string' || !env.trim()) | ||
| env = (_c = cloud === null || cloud === void 0 ? void 0 : cloud.config) === null || _c === void 0 ? void 0 : _c.env; | ||
| if (typeof env !== 'string' || !env.trim()) | ||
| env = (_d = cloud === null || cloud === void 0 ? void 0 : cloud.config) === null || _d === void 0 ? void 0 : _d.envName; | ||
| if (typeof env !== 'string' || !env.trim()) { | ||
@@ -561,2 +682,3 @@ throw new Error('Generating default gateway base url failed: env not found'); | ||
| exports.init = init; | ||
| exports.initHTTPOverCallFunction = initHTTPOverCallFunction; | ||
@@ -563,0 +685,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
+1
-1
| { | ||
| "name": "@cloudbase/wx-cloud-client-sdk", | ||
| "version": "1.6.0", | ||
| "version": "1.6.1", | ||
| "publishConfig": { | ||
@@ -5,0 +5,0 @@ "access": "public" |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
127627
12.43%2779
15.02%