@byted-apaas/server-sdk-node 1.0.7 → 1.0.9
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/context/db/db.d.ts +12 -0
- package/context/db/impl/IObject.d.ts +10 -10
- package/context/db/impl/db.d.ts +1 -0
- package/context/db/impl/db.js +4 -9
- package/context/db/impl/object.js +21 -16
- package/context/db/impl/oql/oql.d.ts +1 -0
- package/context/db/impl/oql/oql.js +5 -1
- package/package.json +2 -2
- package/request/innerapi.js +1 -1
- package/request/openapi.js +3 -3
package/context/db/db.d.ts
CHANGED
|
@@ -51,6 +51,18 @@ export interface IDB<T, mt> {
|
|
|
51
51
|
* ```
|
|
52
52
|
*/
|
|
53
53
|
oql(oql: string): IOql;
|
|
54
|
+
/**
|
|
55
|
+
* OQL 操作
|
|
56
|
+
* @param oql OQL 语句
|
|
57
|
+
* @param nameArgs 用于替换 OQL 语句中的占位符
|
|
58
|
+
* @example
|
|
59
|
+
* ```
|
|
60
|
+
* let employees = await context.db.oql("select _email from _user where _type = $user_type",{
|
|
61
|
+
* "user_type": "_employee",
|
|
62
|
+
* }).execute();
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
oql(oql: string, nameArgs: Record<string, any>): IOql;
|
|
54
66
|
}
|
|
55
67
|
/**
|
|
56
68
|
* IDBWithCurrentObject 经由 IDBGetter 返回,是 DB 的动态增加的接口结构
|
|
@@ -158,7 +158,7 @@ export interface _IKQuery<T> {
|
|
|
158
158
|
* context.db.object("_user").orderBy(["_email", "_phoneNumber"]).find()
|
|
159
159
|
* ```
|
|
160
160
|
*/
|
|
161
|
-
orderBy<K extends keyof T>(fieldApiNames: K[]): _IKQuery<T>;
|
|
161
|
+
orderBy<K extends keyof T>(fieldApiNames: K[]): Omit<_IKQuery<T>, 'findAll'>;
|
|
162
162
|
/**
|
|
163
163
|
* 根据指定字段升序排序(a -> z, 0 -> 9)
|
|
164
164
|
* @param fieldApiNames 排序依据的字段,按先后顺序确定优先级,用逗号分隔
|
|
@@ -167,7 +167,7 @@ export interface _IKQuery<T> {
|
|
|
167
167
|
* context.db.object("_user").orderBy("_email", "_phoneNumber").find()
|
|
168
168
|
* ```
|
|
169
169
|
*/
|
|
170
|
-
orderBy<K extends keyof T>(...fieldApiNames: K[]): _IKQuery<T>;
|
|
170
|
+
orderBy<K extends keyof T>(...fieldApiNames: K[]): Omit<_IKQuery<T>, 'findAll'>;
|
|
171
171
|
/**
|
|
172
172
|
* 根据指定字段降序排序(z -> a, 9 -> 0)
|
|
173
173
|
* @param fieldApiNames 排序依据的字段数组,按先后顺序确定优先级
|
|
@@ -176,7 +176,7 @@ export interface _IKQuery<T> {
|
|
|
176
176
|
* context.db.object("_user").orderByDesc("_email", "_phoneNumber").find()
|
|
177
177
|
* ```
|
|
178
178
|
*/
|
|
179
|
-
orderByDesc<K extends keyof T>(fieldApiNames: K[]): _IKQuery<T>;
|
|
179
|
+
orderByDesc<K extends keyof T>(fieldApiNames: K[]): Omit<_IKQuery<T>, 'findAll'>;
|
|
180
180
|
/**
|
|
181
181
|
* 根据指定字段降序排序(z -> a, 9 -> 0)
|
|
182
182
|
* @param fieldApiNames 排序依据的字段,按先后顺序确定优先级,用逗号分隔
|
|
@@ -185,7 +185,7 @@ export interface _IKQuery<T> {
|
|
|
185
185
|
* context.db.object("_user").orderByDesc("_email", "_phoneNumber").find()
|
|
186
186
|
* ```
|
|
187
187
|
*/
|
|
188
|
-
orderByDesc<K extends keyof T>(...fieldApiNames: K[]): _IKQuery<T>;
|
|
188
|
+
orderByDesc<K extends keyof T>(...fieldApiNames: K[]): Omit<_IKQuery<T>, 'findAll'>;
|
|
189
189
|
/**
|
|
190
190
|
* 指定需返回的字段
|
|
191
191
|
* @param fieldApiNames 需返回的字段数组
|
|
@@ -194,7 +194,7 @@ export interface _IKQuery<T> {
|
|
|
194
194
|
* context.db.object("_user").select(["_name", "_email"]).find()
|
|
195
195
|
* ```
|
|
196
196
|
*/
|
|
197
|
-
select<K extends keyof T>(fieldApiNames: K[]): _IKQuery<T>;
|
|
197
|
+
select<K extends keyof T>(fieldApiNames: K[]): Omit<_IKQuery<T>, 'findAll'>;
|
|
198
198
|
/**
|
|
199
199
|
* 指定需返回的字段
|
|
200
200
|
* @param fieldApiNames 需返回的字段,用逗号分隔
|
|
@@ -203,7 +203,7 @@ export interface _IKQuery<T> {
|
|
|
203
203
|
* context.db.object("_user").select("_name", "_email").find()
|
|
204
204
|
* ```
|
|
205
205
|
*/
|
|
206
|
-
select<K extends keyof T>(...fieldApiNames: K[]): _IKQuery<T>;
|
|
206
|
+
select<K extends keyof T>(...fieldApiNames: K[]): Omit<_IKQuery<T>, 'findAll'>;
|
|
207
207
|
/**
|
|
208
208
|
* 设置查询条件
|
|
209
209
|
* @param conditionMap 对字段赋值以指定查询筛选条件
|
|
@@ -215,11 +215,11 @@ export interface _IKQuery<T> {
|
|
|
215
215
|
* }).find()
|
|
216
216
|
* ```
|
|
217
217
|
*/
|
|
218
|
-
where(conditionMap: _WhereCond<T>): _IKQuery<T>;
|
|
218
|
+
where(conditionMap: _WhereCond<T>): Omit<_IKQuery<T>, 'findAll'>;
|
|
219
219
|
/**
|
|
220
220
|
* 设置查询条件
|
|
221
221
|
*/
|
|
222
|
-
where(): _IKQuery<T>;
|
|
222
|
+
where(): Omit<_IKQuery<T>, 'findAll'>;
|
|
223
223
|
/**
|
|
224
224
|
* 指定分页查询的数量
|
|
225
225
|
* @param limit 分页查询的数量
|
|
@@ -229,7 +229,7 @@ export interface _IKQuery<T> {
|
|
|
229
229
|
* context.db.object("_user").limit(10)
|
|
230
230
|
* ```
|
|
231
231
|
*/
|
|
232
|
-
limit(limit: number): _IKQuery<T>;
|
|
232
|
+
limit(limit: number): Omit<_IKQuery<T>, 'findAll'>;
|
|
233
233
|
/**
|
|
234
234
|
* 指定分页查询的偏移量
|
|
235
235
|
* @param offset 分页查询的偏移量
|
|
@@ -239,7 +239,7 @@ export interface _IKQuery<T> {
|
|
|
239
239
|
* context.db.object("_user").offset(0)
|
|
240
240
|
* ```
|
|
241
241
|
*/
|
|
242
|
-
offset(offset: number): _IKQuery<T>;
|
|
242
|
+
offset(offset: number): Omit<_IKQuery<T>, 'findAll'>;
|
|
243
243
|
/**
|
|
244
244
|
* 指定条件的行数
|
|
245
245
|
* @example
|
package/context/db/impl/db.d.ts
CHANGED
|
@@ -43,6 +43,7 @@ export declare class DB<T, mt = metadataMap> implements IDB<T, mt> {
|
|
|
43
43
|
* ```
|
|
44
44
|
*/
|
|
45
45
|
oql(oql: string): IOql;
|
|
46
|
+
oql(oql: string, nameArgs: Record<string, any>): IOql;
|
|
46
47
|
}
|
|
47
48
|
export declare class DBWithCurrentObject<T, mt = metadataMap> extends DB<T, mt> implements IDB<T, mt>, IDBWithCurrentObject<T, mt> {
|
|
48
49
|
/**
|
package/context/db/impl/db.js
CHANGED
|
@@ -42,15 +42,10 @@ class DB {
|
|
|
42
42
|
return new index_1.Transaction(this.objectApiName);
|
|
43
43
|
}
|
|
44
44
|
;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
* ```
|
|
50
|
-
* let users = await context.db.oql("select _email from _user").execute();
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
oql(oql) {
|
|
45
|
+
oql(oql, nameArgs) {
|
|
46
|
+
if (nameArgs) {
|
|
47
|
+
return new oql_1.Oql(oql, nameArgs);
|
|
48
|
+
}
|
|
54
49
|
return new oql_1.Oql(oql);
|
|
55
50
|
}
|
|
56
51
|
}
|
|
@@ -56,24 +56,30 @@ class _KObjectSync {
|
|
|
56
56
|
}
|
|
57
57
|
;
|
|
58
58
|
async delete(recordOrRecordID) {
|
|
59
|
+
let recordID = 0;
|
|
59
60
|
// 用户直接传入 record id 来进行删除的情况
|
|
60
61
|
if (typeof recordOrRecordID === "number") {
|
|
61
|
-
|
|
62
|
+
recordID = recordOrRecordID;
|
|
62
63
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
else {
|
|
65
|
+
// 用户传入 object 结构来进行删除的情况
|
|
66
|
+
let record = recordOrRecordID;
|
|
67
|
+
if (server_common_node_1.checkUtils.isObject(record)) {
|
|
68
|
+
// 如果用户没有传入包含 id 的 record,则报错
|
|
69
|
+
if (!record._id) {
|
|
70
|
+
throw new server_common_node_1.exceptions.InvalidParamError("record._id is empty");
|
|
71
|
+
}
|
|
72
|
+
recordID = record._id;
|
|
69
73
|
}
|
|
74
|
+
}
|
|
75
|
+
if (recordID > 0) {
|
|
70
76
|
if (this.appCtx && this.appCtx.mode == 'openSDK') {
|
|
71
77
|
// request from OpenSDK
|
|
72
78
|
return await (0, common_1.runCtxForOpenSDK)(this.appCtx, async () => {
|
|
73
|
-
return await Request.GetInstance().openSDKDeleteRecordBySync(this.apiName,
|
|
79
|
+
return await Request.GetInstance().openSDKDeleteRecordBySync(this.apiName, recordID);
|
|
74
80
|
});
|
|
75
81
|
}
|
|
76
|
-
return await Request.GetInstance().deleteRecordBySync(this.apiName,
|
|
82
|
+
return await Request.GetInstance().deleteRecordBySync(this.apiName, recordID);
|
|
77
83
|
}
|
|
78
84
|
throw new server_common_node_1.exceptions.InvalidParamError("record must be number or object");
|
|
79
85
|
}
|
|
@@ -163,8 +169,7 @@ class _KObjectSync {
|
|
|
163
169
|
return await Request.GetInstance().openSDKDeleteRecordsBySync(this.apiName, recordIDs);
|
|
164
170
|
});
|
|
165
171
|
}
|
|
166
|
-
await Request.GetInstance().deleteRecordsBySync(this.apiName, recordIDs);
|
|
167
|
-
return;
|
|
172
|
+
return await Request.GetInstance().deleteRecordsBySync(this.apiName, recordIDs);
|
|
168
173
|
}
|
|
169
174
|
async batchUpdate(recordMapList) {
|
|
170
175
|
// 参数校验、组装
|
|
@@ -184,13 +189,11 @@ class _KObjectSync {
|
|
|
184
189
|
}
|
|
185
190
|
if (this.appCtx && this.appCtx.mode == 'openSDK') {
|
|
186
191
|
// request from OpenSDK
|
|
187
|
-
await (0, common_1.runCtxForOpenSDK)(this.appCtx, async () => {
|
|
188
|
-
return await Request.GetInstance().openSDKUpdateRecordsBySync(this.apiName,
|
|
192
|
+
return await (0, common_1.runCtxForOpenSDK)(this.appCtx, async () => {
|
|
193
|
+
return await Request.GetInstance().openSDKUpdateRecordsBySync(this.apiName, recordMapList);
|
|
189
194
|
});
|
|
190
|
-
return;
|
|
191
195
|
}
|
|
192
|
-
await Request.GetInstance().updateRecordsBySync(this.apiName, recordMap);
|
|
193
|
-
return;
|
|
196
|
+
return await Request.GetInstance().updateRecordsBySync(this.apiName, recordMap);
|
|
194
197
|
}
|
|
195
198
|
;
|
|
196
199
|
}
|
|
@@ -495,6 +498,7 @@ class _KQuery {
|
|
|
495
498
|
}
|
|
496
499
|
limit(limit) {
|
|
497
500
|
const { queryBuilder, queryV2 } = queryPropertiesStore.get(this);
|
|
501
|
+
limit = Number(limit);
|
|
498
502
|
if (queryV2) {
|
|
499
503
|
queryV2.limit(limit);
|
|
500
504
|
}
|
|
@@ -506,6 +510,7 @@ class _KQuery {
|
|
|
506
510
|
;
|
|
507
511
|
offset(offset) {
|
|
508
512
|
const { queryBuilder, queryV2 } = queryPropertiesStore.get(this);
|
|
513
|
+
offset = Number(offset);
|
|
509
514
|
if (queryV2) {
|
|
510
515
|
queryV2.offset(offset);
|
|
511
516
|
}
|
|
@@ -5,10 +5,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
5
5
|
exports.Oql = void 0;
|
|
6
6
|
const Request = require("../../../../request/interface");
|
|
7
7
|
class Oql {
|
|
8
|
-
constructor(oql) {
|
|
8
|
+
constructor(oql, namedArgs) {
|
|
9
9
|
this.oql = oql;
|
|
10
10
|
this.params = [];
|
|
11
11
|
this.namedParams = {};
|
|
12
|
+
this.params = [];
|
|
13
|
+
if (namedArgs) {
|
|
14
|
+
this.namedParams = namedArgs;
|
|
15
|
+
}
|
|
12
16
|
}
|
|
13
17
|
async execute() {
|
|
14
18
|
let records = await Request.GetInstance().oql(this.oql, this.params, this.namedParams);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@byted-apaas/server-sdk-node",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "aPaaS Server SDK",
|
|
5
5
|
"author": "zhouwexin <zhouwexin@bytedance.com>",
|
|
6
6
|
"homepage": "",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"pre-build": "rm -rf build && tsc"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@byted-apaas/server-common-node": "^1.0.
|
|
15
|
+
"@byted-apaas/server-common-node": "^1.0.11",
|
|
16
16
|
"@jorgeferrero/stream-to-buffer": "^2.0.6",
|
|
17
17
|
"dayjs": "^1.9.6",
|
|
18
18
|
"form-data": "^3.0.0",
|
package/request/innerapi.js
CHANGED
package/request/openapi.js
CHANGED
|
@@ -582,7 +582,7 @@ async function openSDKCreateRecordsBySync(objectApiName, records) {
|
|
|
582
582
|
let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
|
|
583
583
|
urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
|
|
584
584
|
// 2.请求
|
|
585
|
-
options.json = records;
|
|
585
|
+
options.json = { records: records };
|
|
586
586
|
return await openapi.doRequest(null, urlPath, options);
|
|
587
587
|
}
|
|
588
588
|
;
|
|
@@ -592,7 +592,7 @@ async function openSDKUpdateRecordsBySync(objectApiName, records) {
|
|
|
592
592
|
let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
|
|
593
593
|
urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
|
|
594
594
|
// 2.请求
|
|
595
|
-
options.json = records;
|
|
595
|
+
options.json = { records: records };
|
|
596
596
|
return await openapi.doRequest(null, urlPath, options);
|
|
597
597
|
}
|
|
598
598
|
;
|
|
@@ -602,7 +602,7 @@ async function openSDKDeleteRecordsBySync(objectApiName, recordIDs) {
|
|
|
602
602
|
let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
|
|
603
603
|
urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
|
|
604
604
|
// 2.请求
|
|
605
|
-
options.json = recordIDs;
|
|
605
|
+
options.json = { _ids: recordIDs };
|
|
606
606
|
return await openapi.doRequest(null, urlPath, options);
|
|
607
607
|
}
|
|
608
608
|
;
|