@cloudbase/wx-cloud-client-sdk
Advanced tools
+4
-1
| import { CloudBaseInstance, ExtendedCloudBaseInstance } from './types'; | ||
| import { generateHTTPClient } from './orm/http-orm-client'; | ||
| export declare function init(cloud: CloudBaseInstance): ExtendedCloudBaseInstance; | ||
| export declare function init(cloud: CloudBaseInstance, options?: { | ||
| baseUrl?: string; | ||
| sqlBaseUrl?: string; | ||
| }): ExtendedCloudBaseInstance; | ||
| export * from './types'; | ||
@@ -5,0 +8,0 @@ export { generateHTTPClient }; |
@@ -1,4 +0,2 @@ | ||
| import { SDKRequestInterface } from '@cloudbase/adapter-interface'; | ||
| import { OrmClient, CallFunction } from '../types'; | ||
| type ModelFetch = NonNullable<SDKRequestInterface['fetch']>; | ||
| import { OrmClient, CallFunction, ModelFetch } from '../types'; | ||
| export declare const enum EQUERY_PARAM_TYPE { | ||
@@ -14,2 +12,1 @@ ARRAY = "ARRAY", | ||
| }) => OrmClient; | ||
| export {}; |
@@ -0,1 +1,2 @@ | ||
| import { SDKRequestInterface } from '@cloudbase/adapter-interface'; | ||
| /** | ||
@@ -292,3 +293,3 @@ * 基础 Model 类型定义 | ||
| */ | ||
| runSQLTemplate?: (params: { | ||
| runSQLTemplate: (params: { | ||
| /** | ||
@@ -729,2 +730,3 @@ * 模板名称 | ||
| }) => Promise<any>; | ||
| export type ModelFetch = NonNullable<SDKRequestInterface['fetch']>; | ||
| export {}; |
+48
-105
@@ -148,3 +148,3 @@ 'use strict'; | ||
| } | ||
| var VERSION = "1.5.0"; | ||
| var VERSION = "1.6.0"; | ||
@@ -310,103 +310,2 @@ var callDataSource = function (_a) { | ||
| 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); | ||
| } | ||
| } | ||
| }); | ||
| }; | ||
| var READ_DEFAULT_PARAMS = { | ||
@@ -596,3 +495,4 @@ filter: { | ||
| function init(cloud) { | ||
| function init(cloud, options) { | ||
| var _this = this; | ||
| if (!cloud) { | ||
@@ -604,6 +504,49 @@ throw new Error('cloud is required'); | ||
| } | ||
| var ormClientImpl = generateClient(cloud.callFunction.bind(cloud)); | ||
| cloud.models = ormClientImpl; | ||
| 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 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; | ||
| return cloud; | ||
| } | ||
| function getDefaultGatewayBaseUrl(cloud) { | ||
| var _a, _b, _c; | ||
| 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()) { | ||
| throw new Error('Generating default gateway base url failed: env not found'); | ||
| } | ||
| env = env.trim(); | ||
| return { | ||
| model: "https://".concat(env, ".api.tcloudbasegateway.com/v1/model"), | ||
| sql: "https://".concat(env, ".api.tcloudbasegateway.com/v1/sql") | ||
| }; | ||
| } | ||
| var index = { | ||
@@ -610,0 +553,0 @@ init: init, |
+48
-105
@@ -144,3 +144,3 @@ /****************************************************************************** | ||
| } | ||
| var VERSION = "1.5.0"; | ||
| var VERSION = "1.6.0"; | ||
@@ -306,103 +306,2 @@ var callDataSource = function (_a) { | ||
| 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); | ||
| } | ||
| } | ||
| }); | ||
| }; | ||
| var READ_DEFAULT_PARAMS = { | ||
@@ -592,3 +491,4 @@ filter: { | ||
| function init(cloud) { | ||
| function init(cloud, options) { | ||
| var _this = this; | ||
| if (!cloud) { | ||
@@ -600,6 +500,49 @@ throw new Error('cloud is required'); | ||
| } | ||
| var ormClientImpl = generateClient(cloud.callFunction.bind(cloud)); | ||
| cloud.models = ormClientImpl; | ||
| 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 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; | ||
| return cloud; | ||
| } | ||
| function getDefaultGatewayBaseUrl(cloud) { | ||
| var _a, _b, _c; | ||
| 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()) { | ||
| throw new Error('Generating default gateway base url failed: env not found'); | ||
| } | ||
| env = env.trim(); | ||
| return { | ||
| model: "https://".concat(env, ".api.tcloudbasegateway.com/v1/model"), | ||
| sql: "https://".concat(env, ".api.tcloudbasegateway.com/v1/sql") | ||
| }; | ||
| } | ||
| var index = { | ||
@@ -606,0 +549,0 @@ init: init, |
+48
-105
@@ -150,3 +150,3 @@ (function (global, factory) { | ||
| } | ||
| var VERSION = "1.5.0"; | ||
| var VERSION = "1.6.0"; | ||
@@ -312,103 +312,2 @@ var callDataSource = function (_a) { | ||
| 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); | ||
| } | ||
| } | ||
| }); | ||
| }; | ||
| var READ_DEFAULT_PARAMS = { | ||
@@ -598,3 +497,4 @@ filter: { | ||
| function init(cloud) { | ||
| function init(cloud, options) { | ||
| var _this = this; | ||
| if (!cloud) { | ||
@@ -606,6 +506,49 @@ throw new Error('cloud is required'); | ||
| } | ||
| var ormClientImpl = generateClient(cloud.callFunction.bind(cloud)); | ||
| cloud.models = ormClientImpl; | ||
| 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 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; | ||
| return cloud; | ||
| } | ||
| function getDefaultGatewayBaseUrl(cloud) { | ||
| var _a, _b, _c; | ||
| 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()) { | ||
| throw new Error('Generating default gateway base url failed: env not found'); | ||
| } | ||
| env = env.trim(); | ||
| return { | ||
| model: "https://".concat(env, ".api.tcloudbasegateway.com/v1/model"), | ||
| sql: "https://".concat(env, ".api.tcloudbasegateway.com/v1/sql") | ||
| }; | ||
| } | ||
| var index = { | ||
@@ -612,0 +555,0 @@ init: init, |
+2
-2
| { | ||
| "name": "@cloudbase/wx-cloud-client-sdk", | ||
| "version": "1.5.0", | ||
| "version": "1.6.0", | ||
| "publishConfig": { | ||
@@ -30,3 +30,3 @@ "access": "public" | ||
| "@cloudbase/adapter-interface": "^0.5.0", | ||
| "@cloudbase/js-sdk": "2.8.15-beta.0", | ||
| "@cloudbase/js-sdk": "2.15.0", | ||
| "@rollup/plugin-commonjs": "^25.0.8", | ||
@@ -33,0 +33,0 @@ "@rollup/plugin-node-resolve": "^15.2.3", |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
113519
-3.48%2416
-6.43%2
100%