oak-domain 4.2.2 → 4.2.3
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.
|
@@ -1308,6 +1308,7 @@ class CascadeStore extends RowStore_1.RowStore {
|
|
|
1308
1308
|
if (!option.dontCreateOper && !['oper', 'operEntity', 'modiEntity', 'modi'].includes(entity) && ids.length > 0) {
|
|
1309
1309
|
// 按照框架要求生成Oper和OperEntity这两个内置的对象
|
|
1310
1310
|
(0, assert_1.default)(operId);
|
|
1311
|
+
const operatorId = context.getCurrentUserId(true);
|
|
1311
1312
|
const createOper = {
|
|
1312
1313
|
id: 'dummy',
|
|
1313
1314
|
action: 'create',
|
|
@@ -1317,6 +1318,7 @@ class CascadeStore extends RowStore_1.RowStore {
|
|
|
1317
1318
|
data,
|
|
1318
1319
|
targetEntity: entity,
|
|
1319
1320
|
bornAt,
|
|
1321
|
+
operatorId,
|
|
1320
1322
|
operEntity$oper: {
|
|
1321
1323
|
id: 'dummy',
|
|
1322
1324
|
action: 'create',
|
package/lib/store/checker.js
CHANGED
|
@@ -152,7 +152,7 @@ function translateCheckerInSyncContext(checker) {
|
|
|
152
152
|
if ((0, filter_1.checkFilterContains)(entity, context, filter2, operationFilter, true)) {
|
|
153
153
|
return;
|
|
154
154
|
}
|
|
155
|
-
const e = new Exception_1.OakRowInconsistencyException(undefined, errMsg);
|
|
155
|
+
const e = new Exception_1.OakRowInconsistencyException(undefined, errMsg || 'row checker condition illegal');
|
|
156
156
|
throw e;
|
|
157
157
|
};
|
|
158
158
|
return {
|
|
@@ -402,7 +402,7 @@ function checkAttributeLegal(schema, entity, data) {
|
|
|
402
402
|
case 'enum': {
|
|
403
403
|
(0, assert_1.default)(enumeration);
|
|
404
404
|
if (!enumeration.includes(data[attr])) {
|
|
405
|
-
throw new Exception_1.OakInputIllegalException(entity, [attr], 'not in
|
|
405
|
+
throw new Exception_1.OakInputIllegalException(entity, [attr], 'not in enumeration');
|
|
406
406
|
}
|
|
407
407
|
break;
|
|
408
408
|
}
|
package/lib/types/Connector.d.ts
CHANGED
|
@@ -10,9 +10,10 @@ export interface Connector<ED extends EntityDict, FrontCxt extends SyncContext<E
|
|
|
10
10
|
message?: string | null;
|
|
11
11
|
}>;
|
|
12
12
|
getRouter: () => string;
|
|
13
|
-
|
|
13
|
+
parseRequest: (headers: IncomingHttpHeaders, body?: any, files?: any) => {
|
|
14
14
|
contextString?: string;
|
|
15
15
|
aspectName: string;
|
|
16
|
+
data?: any;
|
|
16
17
|
};
|
|
17
18
|
serializeResult: (result: any, opRecords: OpRecord<ED>[], headers: IncomingHttpHeaders, body: any, message?: string) => Promise<{
|
|
18
19
|
body: any;
|
package/lib/types/Sync.d.ts
CHANGED
|
@@ -32,14 +32,13 @@ export interface PushEntityDef<ED extends EntityDict & BaseEntityDict, T extends
|
|
|
32
32
|
recursive?: boolean;
|
|
33
33
|
relationName?: string;
|
|
34
34
|
actions?: ED[T]['Action'][];
|
|
35
|
+
/**
|
|
36
|
+
* 同步结果回调,根据接口的幂等原理,同步一定要完全成功再回调
|
|
37
|
+
*/
|
|
35
38
|
onSynchronized?: (result: {
|
|
36
39
|
action: ED[T]['Action'];
|
|
37
40
|
data: ED[T]['Operation']['data'];
|
|
38
|
-
|
|
39
|
-
userId: string;
|
|
40
|
-
rowIds: string[];
|
|
41
|
-
error?: Error;
|
|
42
|
-
}>;
|
|
41
|
+
rowIds: string[];
|
|
43
42
|
}, context: Cxt) => Promise<void>;
|
|
44
43
|
}
|
|
45
44
|
export interface SyncRemoteConfigBase<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>> {
|
|
@@ -20,6 +20,22 @@ export declare class SimpleConnector<ED extends EntityDict, FrontCxt extends Syn
|
|
|
20
20
|
private option;
|
|
21
21
|
private makeException;
|
|
22
22
|
constructor(option: ServerOption, makeException: (exceptionData: any) => OakException<ED>);
|
|
23
|
+
protected makeHeadersAndBody(name: string, data: any, context?: FrontCxt): Promise<{
|
|
24
|
+
headers: Record<string, string>;
|
|
25
|
+
body: FormData;
|
|
26
|
+
} | {
|
|
27
|
+
headers: HeadersInit;
|
|
28
|
+
body: string;
|
|
29
|
+
}>;
|
|
30
|
+
protected parseAspectResult(response: Response): Promise<{
|
|
31
|
+
result: any;
|
|
32
|
+
opRecords: any;
|
|
33
|
+
message: string | null;
|
|
34
|
+
} | {
|
|
35
|
+
result: ArrayBuffer;
|
|
36
|
+
message: string | null;
|
|
37
|
+
opRecords?: undefined;
|
|
38
|
+
}>;
|
|
23
39
|
callAspect(name: string, params: any, context?: FrontCxt): Promise<{
|
|
24
40
|
result: any;
|
|
25
41
|
opRecords: any;
|
|
@@ -37,9 +53,10 @@ export declare class SimpleConnector<ED extends EntityDict, FrontCxt extends Syn
|
|
|
37
53
|
path: any;
|
|
38
54
|
}>;
|
|
39
55
|
getEndpointRouter(): string;
|
|
40
|
-
|
|
56
|
+
parseRequest(headers: IncomingHttpHeaders, body?: any, files?: any): {
|
|
41
57
|
contextString: string | undefined;
|
|
42
58
|
aspectName: string;
|
|
59
|
+
data: any;
|
|
43
60
|
};
|
|
44
61
|
serializeResult(result: any, opRecords: OpRecord<ED>[], headers: IncomingHttpHeaders, body: any, message?: string): Promise<{
|
|
45
62
|
body: any;
|
|
@@ -6,20 +6,6 @@ const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
|
6
6
|
const stream_1 = require("stream");
|
|
7
7
|
const url_1 = tslib_1.__importDefault(require("url"));
|
|
8
8
|
const types_1 = require("../types");
|
|
9
|
-
function makeContentTypeAndBody(data) {
|
|
10
|
-
if (process.env.OAK_PLATFORM !== 'wechatMp') {
|
|
11
|
-
if (data instanceof FormData) {
|
|
12
|
-
return {
|
|
13
|
-
// contentType: 'multipart/form-data',
|
|
14
|
-
body: data,
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return {
|
|
19
|
-
contentType: 'application/json',
|
|
20
|
-
body: JSON.stringify(data),
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
9
|
class SimpleConnector {
|
|
24
10
|
static ASPECT_ROUTER = '/aspect';
|
|
25
11
|
static BRIDGE_ROUTER = '/bridge';
|
|
@@ -47,26 +33,30 @@ class SimpleConnector {
|
|
|
47
33
|
this.serverSubscribePointUrl = `${serverUrl}${SimpleConnector.SUBSCRIBE_POINT_ROUTER}`;
|
|
48
34
|
this.makeException = makeException;
|
|
49
35
|
}
|
|
50
|
-
async
|
|
36
|
+
async makeHeadersAndBody(name, data, context) {
|
|
51
37
|
const cxtStr = context ? await context.toString() : '{}';
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
body,
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
catch (err) {
|
|
67
|
-
// fetch返回异常一定是网络异常
|
|
68
|
-
throw new types_1.OakNetworkException(`请求[${this.serverAspectUrl}],发生网络异常`);
|
|
38
|
+
const headers = {
|
|
39
|
+
'oak-cxt': cxtStr,
|
|
40
|
+
'oak-aspect': name,
|
|
41
|
+
};
|
|
42
|
+
if (process.env.OAK_PLATFORM !== 'wechatMp') {
|
|
43
|
+
if (data instanceof FormData) {
|
|
44
|
+
return {
|
|
45
|
+
headers,
|
|
46
|
+
body: data,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
69
49
|
}
|
|
50
|
+
return {
|
|
51
|
+
headers: {
|
|
52
|
+
'Content-Type': 'application/json',
|
|
53
|
+
...headers,
|
|
54
|
+
},
|
|
55
|
+
body: JSON.stringify(data),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
;
|
|
59
|
+
async parseAspectResult(response) {
|
|
70
60
|
if (response.status > 299) {
|
|
71
61
|
const err = new types_1.OakServerProxyException(`网络请求返回status是${response.status}`);
|
|
72
62
|
throw err;
|
|
@@ -98,6 +88,22 @@ class SimpleConnector {
|
|
|
98
88
|
throw new Error(`尚不支持的content-type类型${responseType}`);
|
|
99
89
|
}
|
|
100
90
|
}
|
|
91
|
+
async callAspect(name, params, context) {
|
|
92
|
+
const { headers, body } = await this.makeHeadersAndBody(name, params, context);
|
|
93
|
+
let response;
|
|
94
|
+
try {
|
|
95
|
+
response = await global.fetch(this.serverAspectUrl, {
|
|
96
|
+
method: 'POST',
|
|
97
|
+
headers,
|
|
98
|
+
body,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
// fetch返回异常一定是网络异常
|
|
103
|
+
throw new types_1.OakNetworkException(`请求[${this.serverAspectUrl}],发生网络异常`);
|
|
104
|
+
}
|
|
105
|
+
return this.parseAspectResult(response);
|
|
106
|
+
}
|
|
101
107
|
getRouter() {
|
|
102
108
|
return SimpleConnector.ASPECT_ROUTER;
|
|
103
109
|
}
|
|
@@ -142,13 +148,18 @@ class SimpleConnector {
|
|
|
142
148
|
getEndpointRouter() {
|
|
143
149
|
return SimpleConnector.ENDPOINT_ROUTER;
|
|
144
150
|
}
|
|
145
|
-
|
|
151
|
+
parseRequest(headers, body, files) {
|
|
146
152
|
const { 'oak-cxt': oakCxtStr, 'oak-aspect': aspectName } = headers;
|
|
147
153
|
(0, assert_1.default)(typeof oakCxtStr === 'string' || oakCxtStr === undefined);
|
|
148
154
|
(0, assert_1.default)(typeof aspectName === 'string');
|
|
149
155
|
return {
|
|
150
156
|
contextString: oakCxtStr,
|
|
151
157
|
aspectName,
|
|
158
|
+
/* data: !files ? body : {
|
|
159
|
+
data: body,
|
|
160
|
+
files,
|
|
161
|
+
}, */ // 下个版本再改
|
|
162
|
+
data: files ? Object.assign({}, body, files) : body,
|
|
152
163
|
};
|
|
153
164
|
}
|
|
154
165
|
async serializeResult(result, opRecords, headers, body, message) {
|