@cloudbase/wx-cloud-client-sdk 1.0.0-alpha.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/{src/types → types}/index.d.ts +43 -0
- package/lib/utils.d.ts +10 -0
- package/lib/wxCloudClientSDK.cjs.js +59 -1
- package/lib/wxCloudClientSDK.esm.js +59 -1
- package/lib/wxCloudClientSDK.umd.js +59 -1
- package/package.json +2 -1
- package/lib/demo/app.d.ts +0 -1
- /package/lib/{src/api → api}/datasouce-caller.d.ts +0 -0
- /package/lib/{src/error.d.ts → error.d.ts} +0 -0
- /package/lib/{src/index.d.ts → index.d.ts} +0 -0
- /package/lib/{src/orm → orm}/orm-client.d.ts +0 -0
|
@@ -87,6 +87,32 @@ export interface DataModelMethods<T> {
|
|
|
87
87
|
data: T;
|
|
88
88
|
filter: FilterParams<T>;
|
|
89
89
|
}) => Promise<MethodResponse<UpdateResponse<T>>>;
|
|
90
|
+
/**
|
|
91
|
+
* 创建或者更新的方法
|
|
92
|
+
* @param {Object} params - 包含创建或者更新对象以及和筛选条件的参数对象。
|
|
93
|
+
* @returns {Promise<MethodResponse<UpsertResponse<T>>>} 包含更新响应的Promise对象。
|
|
94
|
+
* @example
|
|
95
|
+
* models.<model_name>.upsert({
|
|
96
|
+
* update: {
|
|
97
|
+
* // 更新的数据字段
|
|
98
|
+
* },
|
|
99
|
+
* create: {
|
|
100
|
+
* // 创建的数据字段
|
|
101
|
+
* },
|
|
102
|
+
* filter: {
|
|
103
|
+
* where: {
|
|
104
|
+
* // 筛选条件
|
|
105
|
+
* }
|
|
106
|
+
* }
|
|
107
|
+
* }).then(({ data }) => {
|
|
108
|
+
* console.log(data.count); // 输出更新的数据条数
|
|
109
|
+
* });
|
|
110
|
+
*/
|
|
111
|
+
upsert: (params: {
|
|
112
|
+
update: T;
|
|
113
|
+
create: T;
|
|
114
|
+
filter: FilterParams<T>;
|
|
115
|
+
}) => Promise<MethodResponse<UpsertResponse<T>>>;
|
|
90
116
|
/**
|
|
91
117
|
* 更新多条数据的方法。
|
|
92
118
|
* @param {Object} params - 包含更新数据和筛选条件的参数对象。
|
|
@@ -253,6 +279,20 @@ export declare type UpdateResponse<T> = {
|
|
|
253
279
|
*/
|
|
254
280
|
count: number;
|
|
255
281
|
};
|
|
282
|
+
/**
|
|
283
|
+
* 创建或者更新的响应类型定义。
|
|
284
|
+
* @template T 模型字段的类型。
|
|
285
|
+
*/
|
|
286
|
+
export declare type UpsertResponse<T> = {
|
|
287
|
+
/**
|
|
288
|
+
* 变更的条数,返回非 0 值代表更新成功
|
|
289
|
+
*/
|
|
290
|
+
count: number;
|
|
291
|
+
/**
|
|
292
|
+
* 变更的条数,返回非 "" 值代表创建成功
|
|
293
|
+
*/
|
|
294
|
+
id: string;
|
|
295
|
+
};
|
|
256
296
|
/**
|
|
257
297
|
* 删除操作的响应类型定义,用于表示删除操作影响的记录数量。
|
|
258
298
|
* @template T 模型字段的类型。
|
|
@@ -563,6 +603,9 @@ export declare type CallFunction = (args: {
|
|
|
563
603
|
dataSourceName: string;
|
|
564
604
|
methodName: string;
|
|
565
605
|
params: Record<string, any>;
|
|
606
|
+
'x-sdk-version'?: string;
|
|
607
|
+
userAgent?: string;
|
|
608
|
+
referrer?: string;
|
|
566
609
|
};
|
|
567
610
|
}) => Promise<any>;
|
|
568
611
|
export {};
|
package/lib/utils.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 获取全局对象 window
|
|
3
|
+
* 小程序中可用, 但小程序中对象信息残缺, 无法访问 navigator 对象, ua 信息也无意义
|
|
4
|
+
*/
|
|
5
|
+
export declare function getGlobalObj(): false | typeof globalThis;
|
|
6
|
+
/** 获取referrer 信息, 担心小程序中报错, 故catch */
|
|
7
|
+
export declare function getReferrer(): any;
|
|
8
|
+
/** 获取用户UA, 小程序中使用 getSystemInfo 替代 */
|
|
9
|
+
export declare function getUserAgent(): any;
|
|
10
|
+
export declare const VERSION: string | undefined;
|
|
@@ -93,6 +93,58 @@ var WxCloudSDKError = /** @class */ (function (_super) {
|
|
|
93
93
|
return WxCloudSDKError;
|
|
94
94
|
}(Error));
|
|
95
95
|
|
|
96
|
+
/**
|
|
97
|
+
* 获取全局对象 window
|
|
98
|
+
* 小程序中可用, 但小程序中对象信息残缺, 无法访问 navigator 对象, ua 信息也无意义
|
|
99
|
+
*/
|
|
100
|
+
function getGlobalObj() {
|
|
101
|
+
// @ts-ignore
|
|
102
|
+
return (typeof window !== 'undefined' && window) || (typeof globalThis !== 'undefined' && globalThis);
|
|
103
|
+
}
|
|
104
|
+
/** 获取referrer 信息, 担心小程序中报错, 故catch */
|
|
105
|
+
function getReferrer() {
|
|
106
|
+
try {
|
|
107
|
+
var globalObj = getGlobalObj();
|
|
108
|
+
if (!globalObj)
|
|
109
|
+
return;
|
|
110
|
+
// 浏览器中
|
|
111
|
+
// @ts-ignore
|
|
112
|
+
if (typeof wx === 'undefined') {
|
|
113
|
+
// @ts-ignore
|
|
114
|
+
return getGlobalObj().location.href;
|
|
115
|
+
}
|
|
116
|
+
// 当前页面路由
|
|
117
|
+
// @ts-ignore
|
|
118
|
+
return globalObj.__wxRoute;
|
|
119
|
+
}
|
|
120
|
+
catch (_a) { }
|
|
121
|
+
}
|
|
122
|
+
/** 获取用户UA, 小程序中使用 getSystemInfo 替代 */
|
|
123
|
+
function getUserAgent() {
|
|
124
|
+
var globalObj = getGlobalObj();
|
|
125
|
+
// @ts-ignore
|
|
126
|
+
if (globalObj === null || globalObj === void 0 ? void 0 : globalObj.navigator)
|
|
127
|
+
return globalObj.navigator.userAgent;
|
|
128
|
+
// 微信小程序
|
|
129
|
+
// @ts-ignore
|
|
130
|
+
if (typeof wx !== 'undefined' && wx.getSystemInfo) {
|
|
131
|
+
var ua_1;
|
|
132
|
+
// 同步接口
|
|
133
|
+
// @ts-ignore
|
|
134
|
+
wx.getSystemInfo({
|
|
135
|
+
success: function (res) {
|
|
136
|
+
if (!res)
|
|
137
|
+
return;
|
|
138
|
+
ua_1 = ['brand', 'model', 'version', 'system', 'platform', 'SDKVersion', 'language']
|
|
139
|
+
.map(function (k) { return "".concat(k, ": ").concat(res[k]); })
|
|
140
|
+
.join(', ');
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
return ua_1;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
var VERSION = "1.0.0";
|
|
147
|
+
|
|
96
148
|
var callDataSource = function (_a) {
|
|
97
149
|
var dataSourceName = _a.dataSourceName, methodName = _a.methodName, params = _a.params, realMethodName = _a.realMethodName, callFunction = _a.callFunction;
|
|
98
150
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
@@ -113,7 +165,10 @@ var callDataSource = function (_a) {
|
|
|
113
165
|
data: {
|
|
114
166
|
dataSourceName: dataSourceName,
|
|
115
167
|
methodName: methodName,
|
|
116
|
-
params: params
|
|
168
|
+
params: params,
|
|
169
|
+
userAgent: getUserAgent(),
|
|
170
|
+
referrer: getReferrer(),
|
|
171
|
+
'x-sdk-version': VERSION
|
|
117
172
|
}
|
|
118
173
|
})];
|
|
119
174
|
case 2:
|
|
@@ -157,6 +212,9 @@ var CRUD_METHODS = {
|
|
|
157
212
|
update: {
|
|
158
213
|
methodName: 'wedaUpdateV2'
|
|
159
214
|
},
|
|
215
|
+
upsert: {
|
|
216
|
+
methodName: 'wedaUpsertV2'
|
|
217
|
+
},
|
|
160
218
|
updateMany: {
|
|
161
219
|
methodName: 'wedaBatchUpdateV2'
|
|
162
220
|
},
|
|
@@ -91,6 +91,58 @@ var WxCloudSDKError = /** @class */ (function (_super) {
|
|
|
91
91
|
return WxCloudSDKError;
|
|
92
92
|
}(Error));
|
|
93
93
|
|
|
94
|
+
/**
|
|
95
|
+
* 获取全局对象 window
|
|
96
|
+
* 小程序中可用, 但小程序中对象信息残缺, 无法访问 navigator 对象, ua 信息也无意义
|
|
97
|
+
*/
|
|
98
|
+
function getGlobalObj() {
|
|
99
|
+
// @ts-ignore
|
|
100
|
+
return (typeof window !== 'undefined' && window) || (typeof globalThis !== 'undefined' && globalThis);
|
|
101
|
+
}
|
|
102
|
+
/** 获取referrer 信息, 担心小程序中报错, 故catch */
|
|
103
|
+
function getReferrer() {
|
|
104
|
+
try {
|
|
105
|
+
var globalObj = getGlobalObj();
|
|
106
|
+
if (!globalObj)
|
|
107
|
+
return;
|
|
108
|
+
// 浏览器中
|
|
109
|
+
// @ts-ignore
|
|
110
|
+
if (typeof wx === 'undefined') {
|
|
111
|
+
// @ts-ignore
|
|
112
|
+
return getGlobalObj().location.href;
|
|
113
|
+
}
|
|
114
|
+
// 当前页面路由
|
|
115
|
+
// @ts-ignore
|
|
116
|
+
return globalObj.__wxRoute;
|
|
117
|
+
}
|
|
118
|
+
catch (_a) { }
|
|
119
|
+
}
|
|
120
|
+
/** 获取用户UA, 小程序中使用 getSystemInfo 替代 */
|
|
121
|
+
function getUserAgent() {
|
|
122
|
+
var globalObj = getGlobalObj();
|
|
123
|
+
// @ts-ignore
|
|
124
|
+
if (globalObj === null || globalObj === void 0 ? void 0 : globalObj.navigator)
|
|
125
|
+
return globalObj.navigator.userAgent;
|
|
126
|
+
// 微信小程序
|
|
127
|
+
// @ts-ignore
|
|
128
|
+
if (typeof wx !== 'undefined' && wx.getSystemInfo) {
|
|
129
|
+
var ua_1;
|
|
130
|
+
// 同步接口
|
|
131
|
+
// @ts-ignore
|
|
132
|
+
wx.getSystemInfo({
|
|
133
|
+
success: function (res) {
|
|
134
|
+
if (!res)
|
|
135
|
+
return;
|
|
136
|
+
ua_1 = ['brand', 'model', 'version', 'system', 'platform', 'SDKVersion', 'language']
|
|
137
|
+
.map(function (k) { return "".concat(k, ": ").concat(res[k]); })
|
|
138
|
+
.join(', ');
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
return ua_1;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
var VERSION = "1.0.0";
|
|
145
|
+
|
|
94
146
|
var callDataSource = function (_a) {
|
|
95
147
|
var dataSourceName = _a.dataSourceName, methodName = _a.methodName, params = _a.params, realMethodName = _a.realMethodName, callFunction = _a.callFunction;
|
|
96
148
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
@@ -111,7 +163,10 @@ var callDataSource = function (_a) {
|
|
|
111
163
|
data: {
|
|
112
164
|
dataSourceName: dataSourceName,
|
|
113
165
|
methodName: methodName,
|
|
114
|
-
params: params
|
|
166
|
+
params: params,
|
|
167
|
+
userAgent: getUserAgent(),
|
|
168
|
+
referrer: getReferrer(),
|
|
169
|
+
'x-sdk-version': VERSION
|
|
115
170
|
}
|
|
116
171
|
})];
|
|
117
172
|
case 2:
|
|
@@ -155,6 +210,9 @@ var CRUD_METHODS = {
|
|
|
155
210
|
update: {
|
|
156
211
|
methodName: 'wedaUpdateV2'
|
|
157
212
|
},
|
|
213
|
+
upsert: {
|
|
214
|
+
methodName: 'wedaUpsertV2'
|
|
215
|
+
},
|
|
158
216
|
updateMany: {
|
|
159
217
|
methodName: 'wedaBatchUpdateV2'
|
|
160
218
|
},
|
|
@@ -97,6 +97,58 @@
|
|
|
97
97
|
return WxCloudSDKError;
|
|
98
98
|
}(Error));
|
|
99
99
|
|
|
100
|
+
/**
|
|
101
|
+
* 获取全局对象 window
|
|
102
|
+
* 小程序中可用, 但小程序中对象信息残缺, 无法访问 navigator 对象, ua 信息也无意义
|
|
103
|
+
*/
|
|
104
|
+
function getGlobalObj() {
|
|
105
|
+
// @ts-ignore
|
|
106
|
+
return (typeof window !== 'undefined' && window) || (typeof globalThis !== 'undefined' && globalThis);
|
|
107
|
+
}
|
|
108
|
+
/** 获取referrer 信息, 担心小程序中报错, 故catch */
|
|
109
|
+
function getReferrer() {
|
|
110
|
+
try {
|
|
111
|
+
var globalObj = getGlobalObj();
|
|
112
|
+
if (!globalObj)
|
|
113
|
+
return;
|
|
114
|
+
// 浏览器中
|
|
115
|
+
// @ts-ignore
|
|
116
|
+
if (typeof wx === 'undefined') {
|
|
117
|
+
// @ts-ignore
|
|
118
|
+
return getGlobalObj().location.href;
|
|
119
|
+
}
|
|
120
|
+
// 当前页面路由
|
|
121
|
+
// @ts-ignore
|
|
122
|
+
return globalObj.__wxRoute;
|
|
123
|
+
}
|
|
124
|
+
catch (_a) { }
|
|
125
|
+
}
|
|
126
|
+
/** 获取用户UA, 小程序中使用 getSystemInfo 替代 */
|
|
127
|
+
function getUserAgent() {
|
|
128
|
+
var globalObj = getGlobalObj();
|
|
129
|
+
// @ts-ignore
|
|
130
|
+
if (globalObj === null || globalObj === void 0 ? void 0 : globalObj.navigator)
|
|
131
|
+
return globalObj.navigator.userAgent;
|
|
132
|
+
// 微信小程序
|
|
133
|
+
// @ts-ignore
|
|
134
|
+
if (typeof wx !== 'undefined' && wx.getSystemInfo) {
|
|
135
|
+
var ua_1;
|
|
136
|
+
// 同步接口
|
|
137
|
+
// @ts-ignore
|
|
138
|
+
wx.getSystemInfo({
|
|
139
|
+
success: function (res) {
|
|
140
|
+
if (!res)
|
|
141
|
+
return;
|
|
142
|
+
ua_1 = ['brand', 'model', 'version', 'system', 'platform', 'SDKVersion', 'language']
|
|
143
|
+
.map(function (k) { return "".concat(k, ": ").concat(res[k]); })
|
|
144
|
+
.join(', ');
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
return ua_1;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
var VERSION = "1.0.0";
|
|
151
|
+
|
|
100
152
|
var callDataSource = function (_a) {
|
|
101
153
|
var dataSourceName = _a.dataSourceName, methodName = _a.methodName, params = _a.params, realMethodName = _a.realMethodName, callFunction = _a.callFunction;
|
|
102
154
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
@@ -117,7 +169,10 @@
|
|
|
117
169
|
data: {
|
|
118
170
|
dataSourceName: dataSourceName,
|
|
119
171
|
methodName: methodName,
|
|
120
|
-
params: params
|
|
172
|
+
params: params,
|
|
173
|
+
userAgent: getUserAgent(),
|
|
174
|
+
referrer: getReferrer(),
|
|
175
|
+
'x-sdk-version': VERSION
|
|
121
176
|
}
|
|
122
177
|
})];
|
|
123
178
|
case 2:
|
|
@@ -161,6 +216,9 @@
|
|
|
161
216
|
update: {
|
|
162
217
|
methodName: 'wedaUpdateV2'
|
|
163
218
|
},
|
|
219
|
+
upsert: {
|
|
220
|
+
methodName: 'wedaUpsertV2'
|
|
221
|
+
},
|
|
164
222
|
updateMany: {
|
|
165
223
|
methodName: 'wedaBatchUpdateV2'
|
|
166
224
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/wx-cloud-client-sdk",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "wx cloud client sdk",
|
|
5
5
|
"main": "lib/wxCloudClientSDK.cjs.js",
|
|
6
6
|
"module": "lib/wxCloudClientSDK.esm.js",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@rollup/plugin-commonjs": "^25.0.8",
|
|
24
24
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
25
|
+
"@rollup/plugin-replace": "^5.0.7",
|
|
25
26
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
26
27
|
"parcel-bundler": "1.6.1",
|
|
27
28
|
"rollup": "^4.18.0",
|
package/lib/demo/app.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|