@byted-apaas/server-sdk-node 1.1.17 → 1.1.18-beta.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/application/application.d.ts +4 -2
- package/context/db/impl/dbV3.d.ts +47 -0
- package/context/db/impl/dbV3.js +63 -0
- package/context/db/impl/object.d.ts +1 -1
- package/context/db/impl/object.js +16 -11
- package/context/db/impl/oql/oql.d.ts +4 -2
- package/context/db/impl/oql/oql.js +6 -1
- package/context/db/impl/transaction/index.d.ts +3 -1
- package/context/db/impl/transaction/index.js +7 -1
- package/hooks/hooks.js +2 -0
- package/package.json +3 -2
|
@@ -22,10 +22,12 @@ export interface IApplication {
|
|
|
22
22
|
setLaneName(laneName: string): IApplication;
|
|
23
23
|
}
|
|
24
24
|
export type AppMode = 'openSDK' | 'faasSDK';
|
|
25
|
+
export type DataVersion = 'v1' | 'v2' | 'v3';
|
|
25
26
|
export interface AppCtx {
|
|
26
|
-
mode
|
|
27
|
+
mode?: AppMode;
|
|
27
28
|
env?: PlatformEnvType;
|
|
28
|
-
credential
|
|
29
|
+
credential?: AppCredential;
|
|
29
30
|
debugType?: '0' | '2';
|
|
30
31
|
x_tt_env?: string;
|
|
32
|
+
dataVersion?: DataVersion;
|
|
31
33
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { _IKAllEndpoint, _IKQuery } from './IObject';
|
|
2
|
+
import { ITransactionGetter } from './transaction';
|
|
3
|
+
import { IDB } from '../db';
|
|
4
|
+
import { metadataMap } from '../../../data/index';
|
|
5
|
+
import { IOql } from './oql/ioql';
|
|
6
|
+
export declare class DBV3<T, mt = metadataMap> implements IDB<T, mt> {
|
|
7
|
+
objectApiName: string;
|
|
8
|
+
constructor(objectApiName?: string);
|
|
9
|
+
/**
|
|
10
|
+
* 操作指定对象的记录数据
|
|
11
|
+
* @param objectApiName 指定对象的 ApiName
|
|
12
|
+
* @example
|
|
13
|
+
* ```
|
|
14
|
+
* context.db.object('_user').where({
|
|
15
|
+
* gender: 'male'
|
|
16
|
+
* }).find()
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
object<K extends keyof mt>(objectApiName: K): _IKAllEndpoint<mt[K]> & _IKQuery<mt[K]>;
|
|
20
|
+
/**
|
|
21
|
+
* 创建一个新的空事务
|
|
22
|
+
* @example
|
|
23
|
+
* ```
|
|
24
|
+
* let tx = context.db.newTransaction();
|
|
25
|
+
* let user = tx.object('_user').registerCreate({
|
|
26
|
+
* _name: new kunlun.type.Multilingual({ zh: '用户1', en: 'user1' }),
|
|
27
|
+
* });
|
|
28
|
+
* let contract = tx.object('contract').registerCreate({
|
|
29
|
+
* _name: new kunlun.type.Multilingual({ zh: '用户1的合同', en: 'user1's contract' }),
|
|
30
|
+
* user: {id: user._id}
|
|
31
|
+
* });
|
|
32
|
+
* await tx.commit();
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
newTransaction(): ITransactionGetter<T, mt>;
|
|
36
|
+
/**
|
|
37
|
+
* OQL 操作
|
|
38
|
+
* @param oql 指定 OQL 语句
|
|
39
|
+
* @example
|
|
40
|
+
* ```
|
|
41
|
+
* let users = await context.db.oql('select _email from _user').execute();
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
oql(oql: string): IOql;
|
|
45
|
+
oql(oql: string, nameArgs: Record<string, any>): IOql;
|
|
46
|
+
toDataParam(): any;
|
|
47
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DBV3 = void 0;
|
|
4
|
+
const object_1 = require("./object");
|
|
5
|
+
const index_1 = require("./transaction/index");
|
|
6
|
+
const oql_1 = require("./oql/oql");
|
|
7
|
+
class DBV3 {
|
|
8
|
+
constructor(objectApiName) {
|
|
9
|
+
this.objectApiName = objectApiName;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 操作指定对象的记录数据
|
|
13
|
+
* @param objectApiName 指定对象的 ApiName
|
|
14
|
+
* @example
|
|
15
|
+
* ```
|
|
16
|
+
* context.db.object('_user').where({
|
|
17
|
+
* gender: 'male'
|
|
18
|
+
* }).find()
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
object(objectApiName) {
|
|
22
|
+
const appCtx = {
|
|
23
|
+
dataVersion: "v3",
|
|
24
|
+
};
|
|
25
|
+
return new object_1._KObject(objectApiName, appCtx);
|
|
26
|
+
}
|
|
27
|
+
;
|
|
28
|
+
/**
|
|
29
|
+
* 创建一个新的空事务
|
|
30
|
+
* @example
|
|
31
|
+
* ```
|
|
32
|
+
* let tx = context.db.newTransaction();
|
|
33
|
+
* let user = tx.object('_user').registerCreate({
|
|
34
|
+
* _name: new kunlun.type.Multilingual({ zh: '用户1', en: 'user1' }),
|
|
35
|
+
* });
|
|
36
|
+
* let contract = tx.object('contract').registerCreate({
|
|
37
|
+
* _name: new kunlun.type.Multilingual({ zh: '用户1的合同', en: 'user1's contract' }),
|
|
38
|
+
* user: {id: user._id}
|
|
39
|
+
* });
|
|
40
|
+
* await tx.commit();
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
newTransaction() {
|
|
44
|
+
const appCtx = {
|
|
45
|
+
dataVersion: "v3",
|
|
46
|
+
};
|
|
47
|
+
return new index_1.Transaction(this.objectApiName, appCtx);
|
|
48
|
+
}
|
|
49
|
+
;
|
|
50
|
+
oql(oql, nameArgs) {
|
|
51
|
+
const appCtx = {
|
|
52
|
+
dataVersion: "v3",
|
|
53
|
+
};
|
|
54
|
+
if (nameArgs) {
|
|
55
|
+
return new oql_1.Oql(oql, nameArgs, appCtx);
|
|
56
|
+
}
|
|
57
|
+
return new oql_1.Oql(oql, undefined, appCtx);
|
|
58
|
+
}
|
|
59
|
+
toDataParam() {
|
|
60
|
+
console.log("================= toDataParam");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.DBV3 = DBV3;
|
|
@@ -9,7 +9,7 @@ export interface _KObject<T> extends _KObjectSync<T>, _KObjectAsync<T>, _KObject
|
|
|
9
9
|
}
|
|
10
10
|
export declare class _KObject<T> {
|
|
11
11
|
apiName: string;
|
|
12
|
-
constructor(objectApiName: string);
|
|
12
|
+
constructor(objectApiName: string, appCtx?: AppCtx);
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
15
|
* _KApplicationObject is open sdk object implement.
|
|
@@ -18,12 +18,13 @@ const structs_1 = require("../../../common/structs");
|
|
|
18
18
|
const queryPropertiesStore = new propertiesStore_1.default();
|
|
19
19
|
// _KObject will be Mixin with [_KObjectSync, _KObjectAsync, _KObjectQuery]
|
|
20
20
|
class _KObject {
|
|
21
|
-
constructor(objectApiName) {
|
|
21
|
+
constructor(objectApiName, appCtx) {
|
|
22
22
|
this.apiName = '';
|
|
23
23
|
if (!objectApiName) {
|
|
24
24
|
throw new server_common_node_1.exceptions.InvalidParamError('objectApiName is empty');
|
|
25
25
|
}
|
|
26
26
|
this.apiName = objectApiName;
|
|
27
|
+
this.appCtx = appCtx;
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
exports._KObject = _KObject;
|
|
@@ -330,7 +331,7 @@ class _KObjectQuery {
|
|
|
330
331
|
}
|
|
331
332
|
;
|
|
332
333
|
async findStream(handler) {
|
|
333
|
-
return new _KQuery(this.apiName, this.appCtx).findStream(handler);
|
|
334
|
+
return new _KQuery(this.apiName, this.appCtx, this.authType).findStream(handler);
|
|
334
335
|
}
|
|
335
336
|
orderBy(fieldApiNames, ...restFieldApiNames) {
|
|
336
337
|
fieldApiNames = !fieldApiNames ? [] : fieldApiNames;
|
|
@@ -351,7 +352,7 @@ class _KObjectQuery {
|
|
|
351
352
|
return new _KQuery(this.apiName, this.appCtx, this.authType).where(conditionMap);
|
|
352
353
|
}
|
|
353
354
|
fuzzySearch(keyword, fieldAPINames) {
|
|
354
|
-
return new _KQuery(this.apiName, this.appCtx).fuzzySearch(keyword, fieldAPINames);
|
|
355
|
+
return new _KQuery(this.apiName, this.appCtx, this.authType).fuzzySearch(keyword, fieldAPINames);
|
|
355
356
|
}
|
|
356
357
|
// limit, offset, count
|
|
357
358
|
limit(limit) {
|
|
@@ -390,13 +391,13 @@ class _KQuery {
|
|
|
390
391
|
apiName: objectApiName,
|
|
391
392
|
appCtx: appCtx,
|
|
392
393
|
queryBuilder: new queryBuilder_1.QueryBuilder(objectApiName),
|
|
393
|
-
queryV2: appCtx ? new logicV2_1.QueryV2(objectApiName) : null,
|
|
394
|
+
queryV2: appCtx && appCtx.mode === "openSDK" ? new logicV2_1.QueryV2(objectApiName) : null, // QueryV2 是提供给 openSDK 使用的
|
|
394
395
|
});
|
|
395
396
|
}
|
|
396
397
|
async find() {
|
|
397
398
|
this.findPreCheck();
|
|
398
399
|
const { apiName, appCtx, queryBuilder, queryV2 } = queryPropertiesStore.get(this);
|
|
399
|
-
if (
|
|
400
|
+
if (queryV2) {
|
|
400
401
|
const param = {
|
|
401
402
|
limit: queryV2._limit,
|
|
402
403
|
offset: queryV2._offset,
|
|
@@ -478,7 +479,7 @@ class _KQuery {
|
|
|
478
479
|
let maxId = 0, queryCount = 0;
|
|
479
480
|
let criterionV2;
|
|
480
481
|
let criterion;
|
|
481
|
-
if (
|
|
482
|
+
if (queryV2) {
|
|
482
483
|
criterionV2 = (0, logicV2_1.buildCriterionV2)(queryV2.filter);
|
|
483
484
|
criterionV2.push({ leftValue: '_id', operator: operator_1.operates.GT, rightValue: maxId });
|
|
484
485
|
}
|
|
@@ -499,7 +500,7 @@ class _KQuery {
|
|
|
499
500
|
break;
|
|
500
501
|
}
|
|
501
502
|
let rs;
|
|
502
|
-
if (
|
|
503
|
+
if (queryV2) {
|
|
503
504
|
criterionV2[criterionV2.length - 1].rightValue = maxId;
|
|
504
505
|
const param = {
|
|
505
506
|
limit: newLimit,
|
|
@@ -562,7 +563,7 @@ class _KQuery {
|
|
|
562
563
|
let maxId = 0, queryCount = 0;
|
|
563
564
|
let criterionV2;
|
|
564
565
|
let criterion;
|
|
565
|
-
if (
|
|
566
|
+
if (queryV2) {
|
|
566
567
|
criterionV2 = (0, logicV2_1.buildCriterionV2)(queryV2.filter);
|
|
567
568
|
criterionV2.push({ leftValue: '_id', operator: operator_1.operates.GT, rightValue: maxId });
|
|
568
569
|
}
|
|
@@ -589,7 +590,7 @@ class _KQuery {
|
|
|
589
590
|
break;
|
|
590
591
|
}
|
|
591
592
|
let rs;
|
|
592
|
-
if (
|
|
593
|
+
if (queryV2) {
|
|
593
594
|
criterionV2[criterionV2.length - 1].rightValue = maxId;
|
|
594
595
|
const param = {
|
|
595
596
|
limit: newLimit,
|
|
@@ -629,7 +630,7 @@ class _KQuery {
|
|
|
629
630
|
let maxId = 0, records = [];
|
|
630
631
|
while (true) {
|
|
631
632
|
let rs;
|
|
632
|
-
if (
|
|
633
|
+
if (queryV2) {
|
|
633
634
|
let criterion = (0, logicV2_1.buildCriterionV2)(queryV2.filter);
|
|
634
635
|
criterion.push({ leftValue: '_id', operator: operator_1.operates.GT, rightValue: maxId });
|
|
635
636
|
const param = {
|
|
@@ -688,6 +689,10 @@ class _KQuery {
|
|
|
688
689
|
return this;
|
|
689
690
|
}
|
|
690
691
|
select(fieldApiNames, ...restFieldApiNames) {
|
|
692
|
+
const { appCtx } = queryPropertiesStore.get(this);
|
|
693
|
+
if (appCtx && appCtx.dataVersion == "v3") {
|
|
694
|
+
console.log("=======================wby test: ", appCtx.dataVersion);
|
|
695
|
+
}
|
|
691
696
|
fieldApiNames = !fieldApiNames ? [] : fieldApiNames;
|
|
692
697
|
let fields = server_common_node_1.utils.argsToList(fieldApiNames, restFieldApiNames);
|
|
693
698
|
const { queryBuilder, queryV2 } = queryPropertiesStore.get(this);
|
|
@@ -767,7 +772,7 @@ class _KQuery {
|
|
|
767
772
|
;
|
|
768
773
|
async count() {
|
|
769
774
|
const { apiName, appCtx, queryBuilder, queryV2 } = queryPropertiesStore.get(this);
|
|
770
|
-
if (
|
|
775
|
+
if (queryV2) {
|
|
771
776
|
const param = {
|
|
772
777
|
limit: 1,
|
|
773
778
|
offset: queryV2._offset,
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { IOql } from './ioql';
|
|
2
|
+
import { AppCtx } from '../../../../application/application';
|
|
2
3
|
export declare class Oql implements IOql {
|
|
3
4
|
oql: string;
|
|
4
5
|
params: any[];
|
|
5
6
|
namedParams: Record<string, any>;
|
|
6
7
|
authType: string;
|
|
7
|
-
|
|
8
|
-
constructor(oql: string,
|
|
8
|
+
appCtx?: AppCtx;
|
|
9
|
+
constructor(oql: string, appCtx?: AppCtx);
|
|
10
|
+
constructor(oql: string, namedArgs: Record<string, any>, appCtx?: AppCtx);
|
|
9
11
|
execute(): Promise<any[]>;
|
|
10
12
|
useSystemAuth(): IOql;
|
|
11
13
|
useUserAuth(): IOql;
|
|
@@ -6,7 +6,8 @@ exports.Oql = void 0;
|
|
|
6
6
|
const Request = require("../../../../request/interface");
|
|
7
7
|
const constants_1 = require("@byted-apaas/server-common-node/constants/constants");
|
|
8
8
|
class Oql {
|
|
9
|
-
constructor(oql, namedArgs) {
|
|
9
|
+
constructor(oql, namedArgs, appCtx) {
|
|
10
|
+
this.appCtx = null;
|
|
10
11
|
this.oql = oql;
|
|
11
12
|
this.params = [];
|
|
12
13
|
this.namedParams = {};
|
|
@@ -14,8 +15,12 @@ class Oql {
|
|
|
14
15
|
if (namedArgs) {
|
|
15
16
|
this.namedParams = namedArgs;
|
|
16
17
|
}
|
|
18
|
+
this.appCtx = appCtx;
|
|
17
19
|
}
|
|
18
20
|
async execute() {
|
|
21
|
+
if (this.appCtx && this.appCtx.dataVersion === "v3") {
|
|
22
|
+
// todo wby
|
|
23
|
+
}
|
|
19
24
|
let records = await Request.GetInstance().oql(this.oql, this.params, this.namedParams, this.authType);
|
|
20
25
|
if (records && Array.isArray(records)) {
|
|
21
26
|
return records;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ITransaction, ITransactionWithCurrentObject, TransactionObject } from '../transaction';
|
|
2
2
|
import { TransactionOperation } from './operation';
|
|
3
3
|
import { currentObjApiName } from '../../../../data';
|
|
4
|
+
import { AppCtx } from '../../../../application/application';
|
|
4
5
|
type uuidOrRecordIDResult = {
|
|
5
6
|
_id: uuidOrRecordID;
|
|
6
7
|
};
|
|
@@ -12,8 +13,9 @@ export declare class Transaction<T, mt> implements ITransaction<mt>, ITransactio
|
|
|
12
13
|
uuid2result: Record<string, uuidOrRecordIDResult>;
|
|
13
14
|
isCommit: boolean;
|
|
14
15
|
authType: string;
|
|
16
|
+
appCtx?: AppCtx;
|
|
15
17
|
batchResults: (string | number)[][];
|
|
16
|
-
constructor(objectApiName: string);
|
|
18
|
+
constructor(objectApiName: string, appCtx?: AppCtx);
|
|
17
19
|
currentObject(): TransactionObject<mt[currentObjApiName]>;
|
|
18
20
|
object<T extends keyof mt>(objectApiName: T): TransactionObject<mt[T]>;
|
|
19
21
|
commit(): Promise<void>;
|
|
@@ -12,13 +12,15 @@ const assert = require('assert');
|
|
|
12
12
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
13
13
|
const { v4: uuidv4 } = require('uuid'); //nolint:byted_s_ts_no_require_imports
|
|
14
14
|
class Transaction {
|
|
15
|
-
constructor(objectApiName) {
|
|
15
|
+
constructor(objectApiName, appCtx) {
|
|
16
|
+
this.appCtx = null;
|
|
16
17
|
this.objectApiName = objectApiName;
|
|
17
18
|
this.placeholders = {};
|
|
18
19
|
this.operations = [];
|
|
19
20
|
this.uuid2result = {};
|
|
20
21
|
this.isCommit = false;
|
|
21
22
|
this.batchResults = [];
|
|
23
|
+
this.appCtx = appCtx;
|
|
22
24
|
}
|
|
23
25
|
// @ts-ignore
|
|
24
26
|
currentObject() {
|
|
@@ -215,6 +217,10 @@ class Transaction {
|
|
|
215
217
|
};
|
|
216
218
|
}
|
|
217
219
|
async commit() {
|
|
220
|
+
if (this.appCtx && this.appCtx.dataVersion === "v3") {
|
|
221
|
+
// todo wby
|
|
222
|
+
console.log("==========wby test= commit");
|
|
223
|
+
}
|
|
218
224
|
if (this.isCommit) {
|
|
219
225
|
throw new server_common_node_1.exceptions.InvalidParamError('The transaction cannot be committed repeatedly');
|
|
220
226
|
}
|
package/hooks/hooks.js
CHANGED
|
@@ -11,6 +11,7 @@ const common_1 = require("../request/common");
|
|
|
11
11
|
const integration_1 = require("../context/integration/impl/integration");
|
|
12
12
|
const metadataApi = require("../context/metadata/metadata");
|
|
13
13
|
const flow_1 = require("../global/application/flow/flow");
|
|
14
|
+
const dbV3_1 = require("../context/db/impl/dbV3");
|
|
14
15
|
/**
|
|
15
16
|
* 根据 key 获取对应的全局变量
|
|
16
17
|
* @param key 全局变量的 key
|
|
@@ -73,6 +74,7 @@ function mountApplication(context) {
|
|
|
73
74
|
global.application = {};
|
|
74
75
|
}
|
|
75
76
|
global.application.data = new db_1.DB();
|
|
77
|
+
global.application.dataV2 = new dbV3_1.DBV3();
|
|
76
78
|
// publicAPI
|
|
77
79
|
if (!global.application.publicAPI) {
|
|
78
80
|
global.application.publicAPI = {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@byted-apaas/server-sdk-node",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.18-beta.0",
|
|
4
4
|
"description": "aPaaS Server SDK",
|
|
5
5
|
"author": "zhouwexin <zhouwexin@bytedance.com>",
|
|
6
6
|
"homepage": "",
|
|
@@ -13,10 +13,11 @@
|
|
|
13
13
|
"clean": "tsc --build --clean && rm -rf **/*.js.map"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@byted-apaas/server-common-node": "^2.0.
|
|
16
|
+
"@byted-apaas/server-common-node": "^2.0.9",
|
|
17
17
|
"@jorgeferrero/stream-to-buffer": "^2.0.6",
|
|
18
18
|
"dayjs": "^1.9.6",
|
|
19
19
|
"form-data": "^3.0.0",
|
|
20
|
+
"package.json": "^2.0.1",
|
|
20
21
|
"typescript": "^4.9.3",
|
|
21
22
|
"uuid": "^8.3.2"
|
|
22
23
|
},
|