@byted-apaas/server-sdk-node 1.1.23-beta.9 → 1.1.23
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/package.json +2 -2
- package/application/application.d.ts +0 -33
- package/application/application.js +0 -2
- package/application/function/function.d.ts +0 -14
- package/application/function/function.js +0 -20
- package/application/impl/common.d.ts +0 -2
- package/application/impl/common.js +0 -52
- package/application/impl/impl.d.ts +0 -19
- package/application/impl/impl.js +0 -45
- package/common/structs.d.ts +0 -15
- package/common/structs.js +0 -21
- package/constants/constants.d.ts +0 -13
- package/constants/constants.js +0 -18
- package/context/context.d.ts +0 -44
- package/context/context.js +0 -25
- package/context/db/db.d.ts +0 -110
- package/context/db/db.js +0 -2
- package/context/db/impl/IObject.d.ts +0 -303
- package/context/db/impl/IObject.js +0 -5
- package/context/db/impl/IObjectV3.d.ts +0 -239
- package/context/db/impl/IObjectV3.js +0 -5
- package/context/db/impl/db.d.ts +0 -62
- package/context/db/impl/db.js +0 -84
- package/context/db/impl/dbV3.d.ts +0 -35
- package/context/db/impl/dbV3.js +0 -50
- package/context/db/impl/object.d.ts +0 -123
- package/context/db/impl/object.js +0 -1008
- package/context/db/impl/oql/ioql.d.ts +0 -14
- package/context/db/impl/oql/ioql.js +0 -4
- package/context/db/impl/oql/oql.d.ts +0 -14
- package/context/db/impl/oql/oql.js +0 -39
- package/context/db/impl/order.d.ts +0 -9
- package/context/db/impl/order.js +0 -15
- package/context/db/impl/propertiesStore.d.ts +0 -8
- package/context/db/impl/propertiesStore.js +0 -29
- package/context/db/impl/queryBuilder.d.ts +0 -33
- package/context/db/impl/queryBuilder.js +0 -72
- package/context/db/impl/transaction/index.d.ts +0 -25
- package/context/db/impl/transaction/index.js +0 -300
- package/context/db/impl/transaction/operation.d.ts +0 -27
- package/context/db/impl/transaction/operation.js +0 -69
- package/context/db/impl/transaction.d.ts +0 -70
- package/context/db/impl/transaction.js +0 -4
- package/context/globalConfig/globalConfig.d.ts +0 -7
- package/context/globalConfig/globalConfig.js +0 -16
- package/context/integration/IIntegration.d.ts +0 -30
- package/context/integration/IIntegration.js +0 -4
- package/context/integration/impl/integration.d.ts +0 -16
- package/context/integration/impl/integration.js +0 -62
- package/context/metadata/components/common.d.ts +0 -6
- package/context/metadata/components/common.js +0 -17
- package/context/metadata/components/components.d.ts +0 -12
- package/context/metadata/components/components.js +0 -19
- package/context/metadata/components/desktop/list.d.ts +0 -16
- package/context/metadata/components/desktop/list.js +0 -402
- package/context/metadata/components/desktop/recordDetail.d.ts +0 -11
- package/context/metadata/components/desktop/recordDetail.js +0 -53
- package/context/metadata/components/mobile/list.d.ts +0 -24
- package/context/metadata/components/mobile/list.js +0 -145
- package/context/metadata/metadata.d.ts +0 -63
- package/context/metadata/metadata.js +0 -125
- package/context/metadata/objects/fields.d.ts +0 -158
- package/context/metadata/objects/fields.js +0 -369
- package/context/metadata/objects/fields.util.d.ts +0 -52
- package/context/metadata/objects/fields.util.js +0 -420
- package/context/metadata/objects/fieldsV3.d.ts +0 -159
- package/context/metadata/objects/fieldsV3.js +0 -369
- package/context/metadata/objects/objects.d.ts +0 -11
- package/context/metadata/objects/objects.js +0 -20
- package/context/metadata/types/common.d.ts +0 -11
- package/context/metadata/types/common.js +0 -33
- package/context/metadata/types/components.d.ts +0 -90
- package/context/metadata/types/components.js +0 -4
- package/context/metadata/types/objects.d.ts +0 -246
- package/context/metadata/types/objects.js +0 -4
- package/context/metadata/types/objectsV3.d.ts +0 -128
- package/context/metadata/types/objectsV3.js +0 -4
- package/context/msg/msg.d.ts +0 -38
- package/context/msg/msg.js +0 -35
- package/context/resources/IResources.d.ts +0 -68
- package/context/resources/IResources.js +0 -2
- package/context/resources/impl/resources.d.ts +0 -42
- package/context/resources/impl/resources.js +0 -161
- package/context/tasks/tasks.d.ts +0 -33
- package/context/tasks/tasks.js +0 -139
- package/data/index.d.ts +0 -27
- package/data/index.js +0 -4
- package/global/application/flow/flow.d.ts +0 -99
- package/global/application/flow/flow.js +0 -8
- package/global/application/flow/impl/flow.d.ts +0 -20
- package/global/application/flow/impl/flow.js +0 -56
- package/global/application/globalVar/globalVar.d.ts +0 -7
- package/global/application/globalVar/globalVar.js +0 -2
- package/global/global.d.ts +0 -70
- package/global/global.js +0 -3
- package/hooks/api.d.ts +0 -65
- package/hooks/api.js +0 -347
- package/hooks/hooks.d.ts +0 -1
- package/hooks/hooks.js +0 -107
- package/kunlun/kunlun.d.ts +0 -55
- package/kunlun/kunlun.js +0 -58
- package/kunlun/operator/IOperator.d.ts +0 -158
- package/kunlun/operator/IOperator.js +0 -4
- package/kunlun/operator/impl/expression.d.ts +0 -75
- package/kunlun/operator/impl/expression.js +0 -96
- package/kunlun/operator/impl/logic.d.ts +0 -68
- package/kunlun/operator/impl/logic.js +0 -573
- package/kunlun/operator/impl/logicV2.d.ts +0 -59
- package/kunlun/operator/impl/logicV2.js +0 -197
- package/kunlun/operator/impl/operator.d.ts +0 -179
- package/kunlun/operator/impl/operator.js +0 -222
- package/kunlun/operator/impl/operatorV2.d.ts +0 -180
- package/kunlun/operator/impl/operatorV2.js +0 -216
- package/lib/core.d.ts +0 -4
- package/lib/core.js +0 -19
- package/request/common.d.ts +0 -13
- package/request/common.js +0 -88
- package/request/constants.d.ts +0 -12
- package/request/constants.js +0 -29
- package/request/faasinfra.d.ts +0 -8
- package/request/faasinfra.js +0 -146
- package/request/interface.d.ts +0 -121
- package/request/interface.js +0 -30
- package/request/openapi.d.ts +0 -84
- package/request/openapi.js +0 -1529
- package/request/structs.d.ts +0 -99
- package/request/structs.js +0 -15
- package/types/types.d.ts +0 -79
- package/types/types.js +0 -4
- package/version/version.d.ts +0 -2
- package/version/version.js +0 -8
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { IOql } from './ioql';
|
|
2
|
-
import { AppCtx } from '../../../../application/application';
|
|
3
|
-
export declare class Oql implements IOql {
|
|
4
|
-
oql: string;
|
|
5
|
-
params: any[];
|
|
6
|
-
namedParams: Record<string, any>;
|
|
7
|
-
authType: string;
|
|
8
|
-
appCtx?: AppCtx;
|
|
9
|
-
constructor(oql: string, appCtx?: AppCtx);
|
|
10
|
-
constructor(oql: string, namedArgs: Record<string, any>, appCtx?: AppCtx);
|
|
11
|
-
execute(): Promise<any[]>;
|
|
12
|
-
useSystemAuth(): IOql;
|
|
13
|
-
useUserAuth(): IOql;
|
|
14
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright 2022 ByteDance Ltd. and/or its affiliates
|
|
3
|
-
// SPDX-License-Identifier: MIT
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.Oql = void 0;
|
|
6
|
-
const Request = require("../../../../request/interface");
|
|
7
|
-
const constants_1 = require("@byted-apaas/server-common-node/constants/constants");
|
|
8
|
-
class Oql {
|
|
9
|
-
constructor(oql, namedArgs, appCtx) {
|
|
10
|
-
this.appCtx = null;
|
|
11
|
-
this.oql = oql;
|
|
12
|
-
this.params = [];
|
|
13
|
-
this.namedParams = {};
|
|
14
|
-
this.params = [];
|
|
15
|
-
if (namedArgs) {
|
|
16
|
-
this.namedParams = namedArgs;
|
|
17
|
-
}
|
|
18
|
-
this.appCtx = appCtx;
|
|
19
|
-
}
|
|
20
|
-
async execute() {
|
|
21
|
-
if (this.appCtx && this.appCtx.dataVersion === 'v3') {
|
|
22
|
-
// todo wby
|
|
23
|
-
}
|
|
24
|
-
let records = await Request.GetInstance().oql(this.oql, this.params, this.namedParams, this.authType);
|
|
25
|
-
if (records && Array.isArray(records)) {
|
|
26
|
-
return records;
|
|
27
|
-
}
|
|
28
|
-
return [];
|
|
29
|
-
}
|
|
30
|
-
useSystemAuth() {
|
|
31
|
-
this.authType = constants_1.AuthTypeSystem;
|
|
32
|
-
return this;
|
|
33
|
-
}
|
|
34
|
-
useUserAuth() {
|
|
35
|
-
this.authType = constants_1.AuthTypeMixUserSystem;
|
|
36
|
-
return this;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
exports.Oql = Oql;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export declare const ASC = "asc";
|
|
2
|
-
export declare const DESC = "desc";
|
|
3
|
-
export type OrderType = 'asc' | 'desc';
|
|
4
|
-
export declare class Order {
|
|
5
|
-
field: string;
|
|
6
|
-
type: string;
|
|
7
|
-
direction: OrderType;
|
|
8
|
-
constructor(fieldApiName: string, direction: OrderType);
|
|
9
|
-
}
|
package/context/db/impl/order.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright 2022 ByteDance Ltd. and/or its affiliates
|
|
3
|
-
// SPDX-License-Identifier: MIT
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.Order = exports.DESC = exports.ASC = void 0;
|
|
6
|
-
exports.ASC = 'asc';
|
|
7
|
-
exports.DESC = 'desc';
|
|
8
|
-
class Order {
|
|
9
|
-
constructor(fieldApiName, direction) {
|
|
10
|
-
this.field = fieldApiName;
|
|
11
|
-
this.type = '';
|
|
12
|
-
this.direction = direction;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.Order = Order;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export default class PropertiesStore<Properties> {
|
|
2
|
-
private map;
|
|
3
|
-
properties(obj: object): Properties;
|
|
4
|
-
get(key: object): Properties | undefined;
|
|
5
|
-
set(key: object, value: Properties): WeakMap<object, Properties>;
|
|
6
|
-
has(key: object): boolean;
|
|
7
|
-
delete(key: object): boolean;
|
|
8
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright 2022 ByteDance Ltd. and/or its affiliates
|
|
3
|
-
// SPDX-License-Identifier: MIT
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
class PropertiesStore {
|
|
6
|
-
constructor() {
|
|
7
|
-
this.map = new WeakMap();
|
|
8
|
-
}
|
|
9
|
-
properties(obj) {
|
|
10
|
-
const properties = this.get(obj);
|
|
11
|
-
if (!properties) {
|
|
12
|
-
throw Error('Properties store error. ');
|
|
13
|
-
}
|
|
14
|
-
return properties;
|
|
15
|
-
}
|
|
16
|
-
get(key) {
|
|
17
|
-
return this.map.get(key);
|
|
18
|
-
}
|
|
19
|
-
set(key, value) {
|
|
20
|
-
return this.map.set(key, value);
|
|
21
|
-
}
|
|
22
|
-
has(key) {
|
|
23
|
-
return this.map.has(key);
|
|
24
|
-
}
|
|
25
|
-
delete(key) {
|
|
26
|
-
return this.map.delete(key);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
exports.default = PropertiesStore;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { Order, OrderType } from './order';
|
|
2
|
-
import { Logic } from '../../../kunlun/operator/impl/logic';
|
|
3
|
-
export declare const defaultLimit = 200;
|
|
4
|
-
/**
|
|
5
|
-
* 查询构造器,在 DB 中被初始化,用于构建一次查询
|
|
6
|
-
*/
|
|
7
|
-
export declare class QueryBuilder {
|
|
8
|
-
objectApiName: string;
|
|
9
|
-
dataSource: string;
|
|
10
|
-
select: string[];
|
|
11
|
-
where: Logic[];
|
|
12
|
-
limit: number;
|
|
13
|
-
isSetLimit: boolean;
|
|
14
|
-
offset: number;
|
|
15
|
-
order: Order[];
|
|
16
|
-
logic: Logic;
|
|
17
|
-
fuzzySearch: object;
|
|
18
|
-
quickQuery: string;
|
|
19
|
-
quickQueryFields: string[];
|
|
20
|
-
constructor(objectApiName: string);
|
|
21
|
-
addLogic(logic: Logic): void;
|
|
22
|
-
getLogic(): Logic;
|
|
23
|
-
addSelect(fieldApiName: string): void;
|
|
24
|
-
addSelects(fields: string[]): void;
|
|
25
|
-
getSelect(): string[];
|
|
26
|
-
addOrder(field: string, orderType: OrderType): void;
|
|
27
|
-
addOrders(fields: string[], orderType: OrderType): void;
|
|
28
|
-
getOrder(): Order[];
|
|
29
|
-
setOffset(offset: number): void;
|
|
30
|
-
setLimit(limit: number): void;
|
|
31
|
-
getLimit(): number;
|
|
32
|
-
getOffset(): number;
|
|
33
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright 2022 ByteDance Ltd. and/or its affiliates
|
|
3
|
-
// SPDX-License-Identifier: MIT
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.QueryBuilder = exports.defaultLimit = void 0;
|
|
6
|
-
const order_1 = require("./order");
|
|
7
|
-
const logic_1 = require("../../../kunlun/operator/impl/logic");
|
|
8
|
-
const server_common_node_1 = require("@byted-apaas/server-common-node");
|
|
9
|
-
// SDK 仅作 limit 小于 0 校验,其他校验拦截由底层控制,如当查询结果不满足受控条件时,limit 仅支持最大 200
|
|
10
|
-
exports.defaultLimit = 200;
|
|
11
|
-
/**
|
|
12
|
-
* 查询构造器,在 DB 中被初始化,用于构建一次查询
|
|
13
|
-
*/
|
|
14
|
-
class QueryBuilder {
|
|
15
|
-
constructor(objectApiName) {
|
|
16
|
-
this.objectApiName = objectApiName;
|
|
17
|
-
this.dataSource = '';
|
|
18
|
-
this.select = [];
|
|
19
|
-
this.where = null;
|
|
20
|
-
this.limit = exports.defaultLimit;
|
|
21
|
-
this.offset = 0;
|
|
22
|
-
this.order = [];
|
|
23
|
-
this.logic = new logic_1.Logic();
|
|
24
|
-
}
|
|
25
|
-
addLogic(logic) {
|
|
26
|
-
this.logic.addLogic(logic);
|
|
27
|
-
}
|
|
28
|
-
getLogic() {
|
|
29
|
-
return this.logic;
|
|
30
|
-
}
|
|
31
|
-
addSelect(fieldApiName) {
|
|
32
|
-
this.select.push(fieldApiName);
|
|
33
|
-
}
|
|
34
|
-
addSelects(fields) {
|
|
35
|
-
fields.forEach(field => {
|
|
36
|
-
// field 非空,则 push 进查询条件
|
|
37
|
-
if (field) {
|
|
38
|
-
this.select.push(field);
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
getSelect() {
|
|
43
|
-
return this.select;
|
|
44
|
-
}
|
|
45
|
-
addOrder(field, orderType) {
|
|
46
|
-
this.order.push(new order_1.Order(field, orderType));
|
|
47
|
-
}
|
|
48
|
-
addOrders(fields, orderType) {
|
|
49
|
-
fields.forEach(field => this.order.push(new order_1.Order(field, orderType)));
|
|
50
|
-
}
|
|
51
|
-
getOrder() {
|
|
52
|
-
return this.order;
|
|
53
|
-
}
|
|
54
|
-
setOffset(offset) {
|
|
55
|
-
if (offset < 0) {
|
|
56
|
-
// need import exceptions
|
|
57
|
-
throw new server_common_node_1.exceptions.InvalidParamError(`offset(${offset}) < 0`);
|
|
58
|
-
}
|
|
59
|
-
this.offset = offset;
|
|
60
|
-
}
|
|
61
|
-
setLimit(limit) {
|
|
62
|
-
this.limit = limit;
|
|
63
|
-
this.isSetLimit = true;
|
|
64
|
-
}
|
|
65
|
-
getLimit() {
|
|
66
|
-
return this.limit;
|
|
67
|
-
}
|
|
68
|
-
getOffset() {
|
|
69
|
-
return this.offset;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
exports.QueryBuilder = QueryBuilder;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { ITransaction, ITransactionWithCurrentObject, TransactionObject } from '../transaction';
|
|
2
|
-
import { TransactionOperation } from './operation';
|
|
3
|
-
import { currentObjApiName } from '../../../../data';
|
|
4
|
-
import { AppCtx } from '../../../../application/application';
|
|
5
|
-
type uuidOrRecordIDResult = {
|
|
6
|
-
_id: uuidOrRecordID;
|
|
7
|
-
};
|
|
8
|
-
type uuidOrRecordID = number | string;
|
|
9
|
-
export declare class Transaction<T, mt> implements ITransaction<mt>, ITransactionWithCurrentObject<mt> {
|
|
10
|
-
objectApiName: string;
|
|
11
|
-
placeholders: Record<string, number>;
|
|
12
|
-
operations: TransactionOperation[];
|
|
13
|
-
uuid2result: Record<string, uuidOrRecordIDResult>;
|
|
14
|
-
isCommit: boolean;
|
|
15
|
-
authType: string;
|
|
16
|
-
appCtx?: AppCtx;
|
|
17
|
-
batchResults: (string | number)[][];
|
|
18
|
-
constructor(objectApiName: string, appCtx?: AppCtx);
|
|
19
|
-
currentObject(): TransactionObject<mt[currentObjApiName]>;
|
|
20
|
-
object<T extends keyof mt>(objectApiName: T): TransactionObject<mt[T]>;
|
|
21
|
-
commit(): Promise<void>;
|
|
22
|
-
useSystemAuth(): this;
|
|
23
|
-
useUserAuth(): this;
|
|
24
|
-
}
|
|
25
|
-
export {};
|
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright 2022 ByteDance Ltd. and/or its affiliates
|
|
3
|
-
// SPDX-License-Identifier: MIT
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.Transaction = void 0;
|
|
6
|
-
const server_common_node_1 = require("@byted-apaas/server-common-node");
|
|
7
|
-
const Request = require("../../../../request/interface");
|
|
8
|
-
const operation_1 = require("./operation");
|
|
9
|
-
const constants_1 = require("@byted-apaas/server-common-node/constants/constants");
|
|
10
|
-
const permissionUtils = require("@byted-apaas/server-common-node/utils/permissionUtils");
|
|
11
|
-
const assert = require('assert');
|
|
12
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
13
|
-
const { v4: uuidv4 } = require('uuid'); //nolint:byted_s_ts_no_require_imports
|
|
14
|
-
class Transaction {
|
|
15
|
-
constructor(objectApiName, appCtx) {
|
|
16
|
-
this.appCtx = null;
|
|
17
|
-
this.objectApiName = objectApiName;
|
|
18
|
-
this.placeholders = {};
|
|
19
|
-
this.operations = [];
|
|
20
|
-
this.uuid2result = {};
|
|
21
|
-
this.isCommit = false;
|
|
22
|
-
this.batchResults = [];
|
|
23
|
-
this.appCtx = appCtx;
|
|
24
|
-
}
|
|
25
|
-
// @ts-ignore
|
|
26
|
-
currentObject() {
|
|
27
|
-
if (!this.objectApiName) {
|
|
28
|
-
throw new server_common_node_1.exceptions.InternalError(`objectApiName is empty`);
|
|
29
|
-
}
|
|
30
|
-
return this.object(this.objectApiName);
|
|
31
|
-
}
|
|
32
|
-
object(objectApiName) {
|
|
33
|
-
if (!objectApiName) {
|
|
34
|
-
throw new server_common_node_1.exceptions.InvalidParamError(`objectApiName is empty`);
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
// 注册创建的逻辑:
|
|
38
|
-
// 事务中进行创建和不使用事务其实是一样的,特别之处在于返回的 ID 是由 SDK 生成的 uuid。
|
|
39
|
-
// SDK 生成的 uuid 只是为了 Mock 住 ID 这个字段,在事务执行后并不会落库。
|
|
40
|
-
registerCreate: (oldRecord) => {
|
|
41
|
-
if (this.isCommit) {
|
|
42
|
-
throw new server_common_node_1.exceptions.InvalidParamError('Committed transaction cannot register operations');
|
|
43
|
-
}
|
|
44
|
-
if (!oldRecord) {
|
|
45
|
-
throw new server_common_node_1.exceptions.InvalidParamError('record is empty');
|
|
46
|
-
}
|
|
47
|
-
if (server_common_node_1.checkUtils.isNotObject(oldRecord)) {
|
|
48
|
-
throw new server_common_node_1.exceptions.InvalidParamError('record is not object');
|
|
49
|
-
}
|
|
50
|
-
let record = permissionUtils.delUnauthField(oldRecord).newRecord;
|
|
51
|
-
let uuid = uuidv4();
|
|
52
|
-
let result = { _id: uuid };
|
|
53
|
-
record._id = uuid;
|
|
54
|
-
this.placeholders[uuid] = 0;
|
|
55
|
-
this.operations.push(new operation_1.CreateOperation(objectApiName, record));
|
|
56
|
-
this.uuid2result[uuid] = result;
|
|
57
|
-
return result;
|
|
58
|
-
},
|
|
59
|
-
// 注册更新的逻辑:
|
|
60
|
-
// 由于事务中创建的 Record 的 ID 是 uuid,而已经创建的 Record 的 ID 是 number 类型,因此在传入 ID 的情况下类型为 string | number
|
|
61
|
-
registerUpdate: (idOrRecord, record) => {
|
|
62
|
-
let recordMap;
|
|
63
|
-
if (this.isCommit) {
|
|
64
|
-
throw new server_common_node_1.exceptions.InvalidParamError('Committed transaction cannot register operations');
|
|
65
|
-
}
|
|
66
|
-
if (typeof idOrRecord === 'number' || typeof idOrRecord === 'string') {
|
|
67
|
-
recordMap = record;
|
|
68
|
-
recordMap._id = idOrRecord;
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
recordMap = idOrRecord;
|
|
72
|
-
}
|
|
73
|
-
if (!recordMap) {
|
|
74
|
-
throw new server_common_node_1.exceptions.InvalidParamError('record is empty');
|
|
75
|
-
}
|
|
76
|
-
recordMap = permissionUtils.delUnauthField(recordMap).newRecord;
|
|
77
|
-
// const recordID: number = recordMap._id;
|
|
78
|
-
let recordID;
|
|
79
|
-
if (typeof recordMap._id === 'number') {
|
|
80
|
-
recordID = recordMap._id;
|
|
81
|
-
}
|
|
82
|
-
else if (typeof recordMap._id === 'string') {
|
|
83
|
-
recordID = parseInt(recordMap._id);
|
|
84
|
-
}
|
|
85
|
-
if (!recordID) {
|
|
86
|
-
throw new server_common_node_1.exceptions.InvalidParamError('record._id is empty');
|
|
87
|
-
}
|
|
88
|
-
this.operations.push(new operation_1.UpdateOperation(objectApiName, recordMap));
|
|
89
|
-
},
|
|
90
|
-
// 注册删除的逻辑:
|
|
91
|
-
// 注册删除和注册更新一样,ID 有可能是事务中创建的 Record,也有可能是现存的 Record,因此 ID 的类型是 string | number
|
|
92
|
-
registerDelete: (idOrRecord) => {
|
|
93
|
-
if (this.isCommit) {
|
|
94
|
-
throw new server_common_node_1.exceptions.InvalidParamError('Committed transaction cannot register operations');
|
|
95
|
-
}
|
|
96
|
-
if (!idOrRecord) {
|
|
97
|
-
throw new server_common_node_1.exceptions.InvalidParamError('record is empty');
|
|
98
|
-
}
|
|
99
|
-
let recordId = null;
|
|
100
|
-
if (typeof idOrRecord === 'number' || typeof idOrRecord === 'string') {
|
|
101
|
-
recordId = idOrRecord;
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
if (server_common_node_1.checkUtils.isObject(idOrRecord)) {
|
|
105
|
-
if (!idOrRecord._id) {
|
|
106
|
-
throw new server_common_node_1.exceptions.InvalidParamError('record._id is empty');
|
|
107
|
-
}
|
|
108
|
-
recordId = idOrRecord._id;
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
throw new server_common_node_1.exceptions.InvalidParamError('param type should be number | string | Object. ');
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
this.operations.push(new operation_1.DeleteOperation(objectApiName, { _id: recordId }));
|
|
115
|
-
},
|
|
116
|
-
// 注册批量创建
|
|
117
|
-
registerBatchCreate: (recordMaps) => {
|
|
118
|
-
if (this.isCommit) {
|
|
119
|
-
throw new server_common_node_1.exceptions.InvalidParamError('Committed transaction cannot register operations');
|
|
120
|
-
}
|
|
121
|
-
if (!recordMaps) {
|
|
122
|
-
throw new server_common_node_1.exceptions.InvalidParamError('recordMaps is empty');
|
|
123
|
-
}
|
|
124
|
-
if (!Array.isArray(recordMaps)) {
|
|
125
|
-
throw new server_common_node_1.exceptions.InvalidParamError('recordMaps is not Array');
|
|
126
|
-
}
|
|
127
|
-
if (recordMaps.length < 1) {
|
|
128
|
-
return [];
|
|
129
|
-
}
|
|
130
|
-
recordMaps = permissionUtils.batchDelUnauthField(recordMaps).newRecords;
|
|
131
|
-
let result = [];
|
|
132
|
-
let records = [];
|
|
133
|
-
for (let oldRecord of recordMaps) {
|
|
134
|
-
let record = { ...oldRecord };
|
|
135
|
-
let uuid = uuidv4();
|
|
136
|
-
this.placeholders[uuid] = 0;
|
|
137
|
-
record._id = uuid;
|
|
138
|
-
result.push(uuid);
|
|
139
|
-
records.push(record);
|
|
140
|
-
}
|
|
141
|
-
this.operations.push(new operation_1.BatchCreateOperation(objectApiName, records));
|
|
142
|
-
this.batchResults.push(result);
|
|
143
|
-
return result;
|
|
144
|
-
},
|
|
145
|
-
registerBatchUpdate: (recordMaps) => {
|
|
146
|
-
if (this.isCommit) {
|
|
147
|
-
throw new server_common_node_1.exceptions.InvalidParamError('Committed transaction cannot register operations');
|
|
148
|
-
}
|
|
149
|
-
if (!recordMaps) {
|
|
150
|
-
throw new server_common_node_1.exceptions.InvalidParamError('recordMaps is empty');
|
|
151
|
-
}
|
|
152
|
-
if (!Array.isArray(recordMaps)) {
|
|
153
|
-
throw new server_common_node_1.exceptions.InvalidParamError('recordMaps is not Array');
|
|
154
|
-
}
|
|
155
|
-
if (recordMaps.length < 1) {
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
recordMaps = permissionUtils.batchDelUnauthField(recordMaps).newRecords;
|
|
159
|
-
// 判断同字段同值更新标志
|
|
160
|
-
let isSameValue = true;
|
|
161
|
-
let ids = [];
|
|
162
|
-
let flag = recordMaps[0];
|
|
163
|
-
for (let record of recordMaps) {
|
|
164
|
-
if (server_common_node_1.checkUtils.isNotObject(record)) {
|
|
165
|
-
throw new server_common_node_1.exceptions.InvalidParamError('one record of recordMaps is not object');
|
|
166
|
-
}
|
|
167
|
-
if (!record._id) {
|
|
168
|
-
throw new server_common_node_1.exceptions.InvalidParamError(`one record of recordMaps has no _id ${JSON.stringify(record)}`);
|
|
169
|
-
}
|
|
170
|
-
ids.push(record._id);
|
|
171
|
-
if (!deepEqualExceptID(flag, record)) {
|
|
172
|
-
isSameValue = false;
|
|
173
|
-
break;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
if (isSameValue) {
|
|
177
|
-
this.operations.push(new operation_1.BatchUpdateSameValueOperation(objectApiName, {
|
|
178
|
-
'ids': ids,
|
|
179
|
-
'value': flag,
|
|
180
|
-
}));
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
for (const i in ids) {
|
|
184
|
-
recordMaps[i]._id = ids[i];
|
|
185
|
-
}
|
|
186
|
-
this.operations.push(new operation_1.BatchUpdateOperation(objectApiName, recordMaps));
|
|
187
|
-
}
|
|
188
|
-
},
|
|
189
|
-
// 注册批量删除
|
|
190
|
-
registerBatchDelete: (idOrRecords) => {
|
|
191
|
-
if (this.isCommit) {
|
|
192
|
-
throw new server_common_node_1.exceptions.InvalidParamError('Committed transaction cannot register operations');
|
|
193
|
-
}
|
|
194
|
-
if (!idOrRecords) {
|
|
195
|
-
throw new server_common_node_1.exceptions.InvalidParamError('idOrRecords is empty');
|
|
196
|
-
}
|
|
197
|
-
if (!Array.isArray(idOrRecords)) {
|
|
198
|
-
throw new server_common_node_1.exceptions.InvalidParamError('idOrRecords is not Array');
|
|
199
|
-
}
|
|
200
|
-
if (idOrRecords.length < 1) {
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
let ids = [];
|
|
204
|
-
for (const idOrRecord of idOrRecords) {
|
|
205
|
-
switch (typeof idOrRecord) {
|
|
206
|
-
case 'string':
|
|
207
|
-
case 'number':
|
|
208
|
-
ids.push(idOrRecord);
|
|
209
|
-
break;
|
|
210
|
-
case 'object':
|
|
211
|
-
if (!idOrRecord._id) {
|
|
212
|
-
throw new server_common_node_1.exceptions.InvalidParamError('_id of one record is empty');
|
|
213
|
-
}
|
|
214
|
-
else {
|
|
215
|
-
ids.push(idOrRecord._id);
|
|
216
|
-
}
|
|
217
|
-
break;
|
|
218
|
-
default:
|
|
219
|
-
throw new server_common_node_1.exceptions.InvalidParamError('type of one param is not string | number | object');
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
this.operations.push(new operation_1.BatchDeleteOperation(objectApiName, { 'ids': ids }));
|
|
223
|
-
},
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
async commit() {
|
|
227
|
-
if (this.isCommit) {
|
|
228
|
-
throw new server_common_node_1.exceptions.InvalidParamError('The transaction cannot be committed repeatedly');
|
|
229
|
-
}
|
|
230
|
-
this.isCommit = true;
|
|
231
|
-
if (!this.operations || this.operations.length === 0) {
|
|
232
|
-
return;
|
|
233
|
-
}
|
|
234
|
-
let uuid2recordId = await Request.GetInstance().modifyRecordsWithTransaction(this.placeholders, this.operations, this.authType, this.appCtx.dataVersion);
|
|
235
|
-
if (!uuid2recordId) {
|
|
236
|
-
throw new server_common_node_1.exceptions.InternalError('uuid2recordId is empty');
|
|
237
|
-
}
|
|
238
|
-
// 单个注册结果映射
|
|
239
|
-
for (let uuid of Object.keys(this.uuid2result)) {
|
|
240
|
-
let preResult = this.uuid2result[uuid];
|
|
241
|
-
let recordId = uuid2recordId.get(uuid);
|
|
242
|
-
if (!recordId) {
|
|
243
|
-
throw new server_common_node_1.exceptions.InternalError(`uuid (${uuid}) is not in uuid2recordId (${JSON.stringify(uuid2recordId)})`);
|
|
244
|
-
}
|
|
245
|
-
if (typeof (recordId) !== 'number') {
|
|
246
|
-
throw new server_common_node_1.exceptions.InternalError(`the type (${typeof (recordId)}) of recordId (${recordId}) must be number`);
|
|
247
|
-
}
|
|
248
|
-
preResult._id = recordId;
|
|
249
|
-
}
|
|
250
|
-
if (!this.batchResults) {
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
// 批量注册结果映射
|
|
254
|
-
for (let i = 0; i < this.batchResults.length; i++) {
|
|
255
|
-
if (!this.batchResults[i]) {
|
|
256
|
-
continue;
|
|
257
|
-
}
|
|
258
|
-
for (let j = 0; j < this.batchResults[i].length; j++) {
|
|
259
|
-
if (!this.batchResults[i][j]) {
|
|
260
|
-
continue;
|
|
261
|
-
}
|
|
262
|
-
let recordId = uuid2recordId.get(this.batchResults[i][j]);
|
|
263
|
-
if (!recordId) {
|
|
264
|
-
throw new server_common_node_1.exceptions.InternalError(`uuid (${this.batchResults[i][j]}) is not in uuid2recordId (${JSON.stringify(uuid2recordId)})`);
|
|
265
|
-
}
|
|
266
|
-
if (typeof (recordId) !== 'number') {
|
|
267
|
-
throw new server_common_node_1.exceptions.InternalError(`the type (${typeof (recordId)}) of recordId (${recordId}) must be number`);
|
|
268
|
-
}
|
|
269
|
-
this.batchResults[i][j] = recordId;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
useSystemAuth() {
|
|
274
|
-
this.authType = constants_1.AuthTypeSystem;
|
|
275
|
-
return this;
|
|
276
|
-
}
|
|
277
|
-
useUserAuth() {
|
|
278
|
-
this.authType = constants_1.AuthTypeUser;
|
|
279
|
-
return this;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
exports.Transaction = Transaction;
|
|
283
|
-
function deepEqualExceptID(left, right) {
|
|
284
|
-
const leftID = left._id, rightID = right._id;
|
|
285
|
-
delete left._id;
|
|
286
|
-
delete right._id;
|
|
287
|
-
let result = deepEqual(left, right);
|
|
288
|
-
left._id = leftID;
|
|
289
|
-
right._id = rightID;
|
|
290
|
-
return result;
|
|
291
|
-
}
|
|
292
|
-
function deepEqual(left, right) {
|
|
293
|
-
try {
|
|
294
|
-
assert.deepStrictEqual(left, right);
|
|
295
|
-
}
|
|
296
|
-
catch (e) {
|
|
297
|
-
return false;
|
|
298
|
-
}
|
|
299
|
-
return true;
|
|
300
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export declare class TransactionOperation {
|
|
2
|
-
operationType: number;
|
|
3
|
-
objectApiName: string;
|
|
4
|
-
input: string;
|
|
5
|
-
constructor(operationType: number, objectApiName: string, input: any);
|
|
6
|
-
}
|
|
7
|
-
export declare class CreateOperation extends TransactionOperation {
|
|
8
|
-
constructor(objectApiName: string, input: any);
|
|
9
|
-
}
|
|
10
|
-
export declare class UpdateOperation extends TransactionOperation {
|
|
11
|
-
constructor(objectApiName: string, input: any);
|
|
12
|
-
}
|
|
13
|
-
export declare class DeleteOperation extends TransactionOperation {
|
|
14
|
-
constructor(objectApiName: string, input: any);
|
|
15
|
-
}
|
|
16
|
-
export declare class BatchCreateOperation extends TransactionOperation {
|
|
17
|
-
constructor(objectApiName: string, input: any);
|
|
18
|
-
}
|
|
19
|
-
export declare class BatchUpdateOperation extends TransactionOperation {
|
|
20
|
-
constructor(objectApiName: string, input: any);
|
|
21
|
-
}
|
|
22
|
-
export declare class BatchDeleteOperation extends TransactionOperation {
|
|
23
|
-
constructor(objectApiName: string, input: any);
|
|
24
|
-
}
|
|
25
|
-
export declare class BatchUpdateSameValueOperation extends TransactionOperation {
|
|
26
|
-
constructor(objectApiName: string, input: any);
|
|
27
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BatchUpdateSameValueOperation = exports.BatchDeleteOperation = exports.BatchUpdateOperation = exports.BatchCreateOperation = exports.DeleteOperation = exports.UpdateOperation = exports.CreateOperation = exports.TransactionOperation = void 0;
|
|
4
|
-
const exceptions = require('@byted-apaas/server-common-node').exceptions;
|
|
5
|
-
var OperationType;
|
|
6
|
-
(function (OperationType) {
|
|
7
|
-
OperationType[OperationType["OPERATION_TYPE_CREATE"] = 1] = "OPERATION_TYPE_CREATE";
|
|
8
|
-
OperationType[OperationType["OPERATION_TYPE_UPDATE"] = 2] = "OPERATION_TYPE_UPDATE";
|
|
9
|
-
OperationType[OperationType["OPERATION_TYPE_DELETE"] = 3] = "OPERATION_TYPE_DELETE";
|
|
10
|
-
OperationType[OperationType["OPERATION_TYPE_BATCH_CREATE"] = 4] = "OPERATION_TYPE_BATCH_CREATE";
|
|
11
|
-
OperationType[OperationType["OPERATION_TYPE_BATCH_UPDATE"] = 5] = "OPERATION_TYPE_BATCH_UPDATE";
|
|
12
|
-
OperationType[OperationType["OPERATION_TYPE_BATCH_DELETE"] = 6] = "OPERATION_TYPE_BATCH_DELETE";
|
|
13
|
-
OperationType[OperationType["OPERATION_TYPE_BATCH_UPDATE_SAME_VALUE"] = 7] = "OPERATION_TYPE_BATCH_UPDATE_SAME_VALUE";
|
|
14
|
-
})(OperationType || (OperationType = {}));
|
|
15
|
-
class TransactionOperation {
|
|
16
|
-
constructor(operationType, objectApiName, input) {
|
|
17
|
-
this.operationType = operationType;
|
|
18
|
-
this.objectApiName = objectApiName;
|
|
19
|
-
try {
|
|
20
|
-
this.input = JSON.stringify(input);
|
|
21
|
-
}
|
|
22
|
-
catch (e) {
|
|
23
|
-
throw new exceptions.InvalidParamError(e.message);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
exports.TransactionOperation = TransactionOperation;
|
|
28
|
-
class CreateOperation extends TransactionOperation {
|
|
29
|
-
constructor(objectApiName, input) {
|
|
30
|
-
super(OperationType.OPERATION_TYPE_CREATE, objectApiName, input);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
exports.CreateOperation = CreateOperation;
|
|
34
|
-
class UpdateOperation extends TransactionOperation {
|
|
35
|
-
constructor(objectApiName, input) {
|
|
36
|
-
super(OperationType.OPERATION_TYPE_UPDATE, objectApiName, input);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
exports.UpdateOperation = UpdateOperation;
|
|
40
|
-
class DeleteOperation extends TransactionOperation {
|
|
41
|
-
constructor(objectApiName, input) {
|
|
42
|
-
super(OperationType.OPERATION_TYPE_DELETE, objectApiName, input);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
exports.DeleteOperation = DeleteOperation;
|
|
46
|
-
class BatchCreateOperation extends TransactionOperation {
|
|
47
|
-
constructor(objectApiName, input) {
|
|
48
|
-
super(OperationType.OPERATION_TYPE_BATCH_CREATE, objectApiName, input);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
exports.BatchCreateOperation = BatchCreateOperation;
|
|
52
|
-
class BatchUpdateOperation extends TransactionOperation {
|
|
53
|
-
constructor(objectApiName, input) {
|
|
54
|
-
super(OperationType.OPERATION_TYPE_BATCH_UPDATE, objectApiName, input);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
exports.BatchUpdateOperation = BatchUpdateOperation;
|
|
58
|
-
class BatchDeleteOperation extends TransactionOperation {
|
|
59
|
-
constructor(objectApiName, input) {
|
|
60
|
-
super(OperationType.OPERATION_TYPE_BATCH_DELETE, objectApiName, input);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
exports.BatchDeleteOperation = BatchDeleteOperation;
|
|
64
|
-
class BatchUpdateSameValueOperation extends TransactionOperation {
|
|
65
|
-
constructor(objectApiName, input) {
|
|
66
|
-
super(OperationType.OPERATION_TYPE_BATCH_UPDATE_SAME_VALUE, objectApiName, input);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
exports.BatchUpdateSameValueOperation = BatchUpdateSameValueOperation;
|