oak-domain 4.2.2 → 4.2.4
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/base-app-domain/ActionDefDict.d.ts +8 -8
- package/lib/base-app-domain/Oper/Schema.d.ts +158 -158
- package/lib/base-app-domain/Oper/Storage.js +56 -56
- package/lib/base-app-domain/User/Action.d.ts +11 -11
- package/lib/base-app-domain/User/Action.js +12 -12
- package/lib/base-app-domain/UserEntityGrant/Action.d.ts +5 -5
- package/lib/base-app-domain/UserEntityGrant/Action.js +5 -5
- package/lib/compiler/schemalBuilder.js +4167 -4167
- package/lib/entities/Oper.d.ts +12 -12
- package/lib/entities/Oper.js +36 -36
- package/lib/entities/User.d.ts +18 -18
- package/lib/entities/User.js +32 -32
- package/lib/index.d.ts +1 -1
- package/lib/index.js +3 -3
- package/lib/store/AsyncRowStore.d.ts +66 -66
- package/lib/store/CascadeStore.d.ts +109 -109
- package/lib/store/CascadeStore.js +1728 -1726
- package/lib/store/RelationAuth.js +1209 -1209
- package/lib/store/TriggerExecutor.js +468 -468
- package/lib/store/actionDef.js +278 -278
- package/lib/store/checker.js +487 -487
- package/lib/store/relation.d.ts +12 -12
- package/lib/store/relation.js +74 -74
- package/lib/triggers/index.d.ts +5 -5
- package/lib/triggers/index.js +28 -28
- package/lib/types/Configuration.d.ts +42 -42
- package/lib/types/Configuration.js +3 -3
- package/lib/types/Connector.d.ts +39 -38
- package/lib/types/Entity.d.ts +209 -209
- package/lib/types/Sync.d.ts +74 -69
- package/lib/types/Sync.js +9 -9
- package/lib/types/index.d.ts +27 -27
- package/lib/types/index.js +30 -30
- package/lib/utils/SimpleConnector.d.ts +81 -64
- package/lib/utils/SimpleConnector.js +217 -206
- package/lib/utils/assert.d.ts +5 -5
- package/lib/utils/projection.d.ts +4 -4
- package/lib/utils/relationPath.d.ts +31 -31
- package/lib/utils/relationPath.js +202 -202
- package/package.json +51 -51
- package/src/entities/ActionAuth.ts +41 -41
- package/src/entities/I18n.ts +45 -45
- package/src/entities/Modi.ts +69 -69
- package/src/entities/ModiEntity.ts +26 -26
- package/src/entities/Oper.ts +48 -48
- package/src/entities/OperEntity.ts +27 -27
- package/src/entities/Path.ts +43 -43
- package/src/entities/Relation.ts +43 -43
- package/src/entities/RelationAuth.ts +44 -44
- package/src/entities/User.ts +48 -48
- package/src/entities/UserEntityClaim.ts +29 -29
- package/src/entities/UserEntityGrant.ts +24 -24
- package/src/entities/UserRelation.ts +50 -50
package/lib/types/index.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./Action"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./Aspect"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./Auth"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./Context"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./DataType"), exports);
|
|
9
|
-
tslib_1.__exportStar(require("./Demand"), exports);
|
|
10
|
-
tslib_1.__exportStar(require("./Entity"), exports);
|
|
11
|
-
tslib_1.__exportStar(require("./Expression"), exports);
|
|
12
|
-
tslib_1.__exportStar(require("./Geo"), exports);
|
|
13
|
-
tslib_1.__exportStar(require("./Logger"), exports);
|
|
14
|
-
tslib_1.__exportStar(require("./Polyfill"), exports);
|
|
15
|
-
tslib_1.__exportStar(require("./RowStore"), exports);
|
|
16
|
-
tslib_1.__exportStar(require("./Storage"), exports);
|
|
17
|
-
tslib_1.__exportStar(require("./Trigger"), exports);
|
|
18
|
-
tslib_1.__exportStar(require("./Exception"), exports);
|
|
19
|
-
tslib_1.__exportStar(require("./Watcher"), exports);
|
|
20
|
-
tslib_1.__exportStar(require("./AppLoader"), exports);
|
|
21
|
-
tslib_1.__exportStar(require("./Connector"), exports);
|
|
22
|
-
tslib_1.__exportStar(require("./Timer"), exports);
|
|
23
|
-
tslib_1.__exportStar(require("./Port"), exports);
|
|
24
|
-
tslib_1.__exportStar(require("./Endpoint"), exports);
|
|
25
|
-
tslib_1.__exportStar(require("./Style"), exports);
|
|
26
|
-
tslib_1.__exportStar(require("./EntityDesc"), exports);
|
|
27
|
-
tslib_1.__exportStar(require("./Environment"), exports);
|
|
28
|
-
tslib_1.__exportStar(require("./Locale"), exports);
|
|
29
|
-
tslib_1.__exportStar(require("./Cluster"), exports);
|
|
30
|
-
tslib_1.__exportStar(require("./Sync"), exports);
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./Action"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./Aspect"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./Auth"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./Context"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./DataType"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./Demand"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./Entity"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./Expression"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./Geo"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./Logger"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("./Polyfill"), exports);
|
|
15
|
+
tslib_1.__exportStar(require("./RowStore"), exports);
|
|
16
|
+
tslib_1.__exportStar(require("./Storage"), exports);
|
|
17
|
+
tslib_1.__exportStar(require("./Trigger"), exports);
|
|
18
|
+
tslib_1.__exportStar(require("./Exception"), exports);
|
|
19
|
+
tslib_1.__exportStar(require("./Watcher"), exports);
|
|
20
|
+
tslib_1.__exportStar(require("./AppLoader"), exports);
|
|
21
|
+
tslib_1.__exportStar(require("./Connector"), exports);
|
|
22
|
+
tslib_1.__exportStar(require("./Timer"), exports);
|
|
23
|
+
tslib_1.__exportStar(require("./Port"), exports);
|
|
24
|
+
tslib_1.__exportStar(require("./Endpoint"), exports);
|
|
25
|
+
tslib_1.__exportStar(require("./Style"), exports);
|
|
26
|
+
tslib_1.__exportStar(require("./EntityDesc"), exports);
|
|
27
|
+
tslib_1.__exportStar(require("./Environment"), exports);
|
|
28
|
+
tslib_1.__exportStar(require("./Locale"), exports);
|
|
29
|
+
tslib_1.__exportStar(require("./Cluster"), exports);
|
|
30
|
+
tslib_1.__exportStar(require("./Sync"), exports);
|
|
@@ -1,64 +1,81 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { IncomingHttpHeaders } from "http";
|
|
3
|
-
import { SyncContext } from '../store/SyncRowStore';
|
|
4
|
-
import { Connector, EntityDict, OakException, OpRecord } from "../types";
|
|
5
|
-
type ServerOption = {
|
|
6
|
-
protocol: string;
|
|
7
|
-
hostname: string;
|
|
8
|
-
port?: number;
|
|
9
|
-
apiPath?: string;
|
|
10
|
-
};
|
|
11
|
-
export declare class SimpleConnector<ED extends EntityDict, FrontCxt extends SyncContext<ED>> implements Connector<ED, FrontCxt> {
|
|
12
|
-
static ASPECT_ROUTER: string;
|
|
13
|
-
static BRIDGE_ROUTER: string;
|
|
14
|
-
static SUBSCRIBE_ROUTER: string;
|
|
15
|
-
static SUBSCRIBE_POINT_ROUTER: string;
|
|
16
|
-
static ENDPOINT_ROUTER: string;
|
|
17
|
-
private serverAspectUrl;
|
|
18
|
-
private serverBridgeUrl;
|
|
19
|
-
private serverSubscribePointUrl;
|
|
20
|
-
private option;
|
|
21
|
-
private makeException;
|
|
22
|
-
constructor(option: ServerOption, makeException: (exceptionData: any) => OakException<ED>);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}>;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}>;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { IncomingHttpHeaders } from "http";
|
|
3
|
+
import { SyncContext } from '../store/SyncRowStore';
|
|
4
|
+
import { Connector, EntityDict, OakException, OpRecord } from "../types";
|
|
5
|
+
type ServerOption = {
|
|
6
|
+
protocol: string;
|
|
7
|
+
hostname: string;
|
|
8
|
+
port?: number;
|
|
9
|
+
apiPath?: string;
|
|
10
|
+
};
|
|
11
|
+
export declare class SimpleConnector<ED extends EntityDict, FrontCxt extends SyncContext<ED>> implements Connector<ED, FrontCxt> {
|
|
12
|
+
static ASPECT_ROUTER: string;
|
|
13
|
+
static BRIDGE_ROUTER: string;
|
|
14
|
+
static SUBSCRIBE_ROUTER: string;
|
|
15
|
+
static SUBSCRIBE_POINT_ROUTER: string;
|
|
16
|
+
static ENDPOINT_ROUTER: string;
|
|
17
|
+
private serverAspectUrl;
|
|
18
|
+
private serverBridgeUrl;
|
|
19
|
+
private serverSubscribePointUrl;
|
|
20
|
+
private option;
|
|
21
|
+
private makeException;
|
|
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
|
+
}>;
|
|
39
|
+
callAspect(name: string, params: any, context?: FrontCxt): Promise<{
|
|
40
|
+
result: any;
|
|
41
|
+
opRecords: any;
|
|
42
|
+
message: string | null;
|
|
43
|
+
} | {
|
|
44
|
+
result: ArrayBuffer;
|
|
45
|
+
message: string | null;
|
|
46
|
+
opRecords?: undefined;
|
|
47
|
+
}>;
|
|
48
|
+
getRouter(): string;
|
|
49
|
+
getSubscribeRouter(): string;
|
|
50
|
+
getSubscribePointRouter(): string;
|
|
51
|
+
getSubscribePoint(): Promise<{
|
|
52
|
+
url: any;
|
|
53
|
+
path: any;
|
|
54
|
+
}>;
|
|
55
|
+
getEndpointRouter(): string;
|
|
56
|
+
parseRequest(headers: IncomingHttpHeaders, body?: any, files?: any): {
|
|
57
|
+
contextString: string | undefined;
|
|
58
|
+
aspectName: string;
|
|
59
|
+
data: any;
|
|
60
|
+
};
|
|
61
|
+
serializeResult(result: any, opRecords: OpRecord<ED>[], headers: IncomingHttpHeaders, body: any, message?: string): Promise<{
|
|
62
|
+
body: any;
|
|
63
|
+
headers?: Record<string, any> | undefined;
|
|
64
|
+
}>;
|
|
65
|
+
serializeException(exception: OakException<ED>, headers: IncomingHttpHeaders, body: any): {
|
|
66
|
+
body: any;
|
|
67
|
+
headers?: Record<string, any> | undefined;
|
|
68
|
+
};
|
|
69
|
+
getBridgeRouter(): string;
|
|
70
|
+
/**
|
|
71
|
+
* 通过本地服务器桥接访问外部资源的url
|
|
72
|
+
* @param url
|
|
73
|
+
* @param headers
|
|
74
|
+
*/
|
|
75
|
+
makeBridgeUrl(url: string, headers?: Record<string, string>): string;
|
|
76
|
+
parseBridgeRequestQuery(urlParams: string): {
|
|
77
|
+
url: string;
|
|
78
|
+
headers?: Record<string, string> | undefined;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
export {};
|
|
@@ -1,206 +1,217 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SimpleConnector = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
6
|
-
const stream_1 = require("stream");
|
|
7
|
-
const url_1 = tslib_1.__importDefault(require("url"));
|
|
8
|
-
const types_1 = require("../types");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return {
|
|
83
|
-
result,
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return SimpleConnector.
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
return
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
return {
|
|
175
|
-
body: {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SimpleConnector = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
6
|
+
const stream_1 = require("stream");
|
|
7
|
+
const url_1 = tslib_1.__importDefault(require("url"));
|
|
8
|
+
const types_1 = require("../types");
|
|
9
|
+
class SimpleConnector {
|
|
10
|
+
static ASPECT_ROUTER = '/aspect';
|
|
11
|
+
static BRIDGE_ROUTER = '/bridge';
|
|
12
|
+
static SUBSCRIBE_ROUTER = process.env.OAK_SUBSCRIBE_ROUTER || '/subscribe';
|
|
13
|
+
static SUBSCRIBE_POINT_ROUTER = '/subscribePoint';
|
|
14
|
+
static ENDPOINT_ROUTER = '/endpoint';
|
|
15
|
+
serverAspectUrl;
|
|
16
|
+
serverBridgeUrl;
|
|
17
|
+
serverSubscribePointUrl;
|
|
18
|
+
option;
|
|
19
|
+
makeException;
|
|
20
|
+
constructor(option, makeException) {
|
|
21
|
+
this.option = option;
|
|
22
|
+
const { protocol, hostname, port, apiPath } = option;
|
|
23
|
+
let serverUrl = `${protocol}//${hostname}`;
|
|
24
|
+
if (typeof port === 'number') {
|
|
25
|
+
serverUrl += `:${port}`;
|
|
26
|
+
}
|
|
27
|
+
if (apiPath) {
|
|
28
|
+
(0, assert_1.default)(apiPath.startsWith('/'), 'apiPath前缀必须存在/');
|
|
29
|
+
serverUrl += apiPath;
|
|
30
|
+
}
|
|
31
|
+
this.serverAspectUrl = `${serverUrl}${SimpleConnector.ASPECT_ROUTER}`;
|
|
32
|
+
this.serverBridgeUrl = `${serverUrl}${SimpleConnector.BRIDGE_ROUTER}`;
|
|
33
|
+
this.serverSubscribePointUrl = `${serverUrl}${SimpleConnector.SUBSCRIBE_POINT_ROUTER}`;
|
|
34
|
+
this.makeException = makeException;
|
|
35
|
+
}
|
|
36
|
+
async makeHeadersAndBody(name, data, context) {
|
|
37
|
+
const cxtStr = context ? await context.toString() : '{}';
|
|
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
|
+
}
|
|
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) {
|
|
60
|
+
if (response.status > 299) {
|
|
61
|
+
const err = new types_1.OakServerProxyException(`网络请求返回status是${response.status}`);
|
|
62
|
+
throw err;
|
|
63
|
+
}
|
|
64
|
+
const message = response.headers.get('oak-message');
|
|
65
|
+
const responseType = response.headers.get('Content-Type') ||
|
|
66
|
+
response.headers.get('content-type');
|
|
67
|
+
if (responseType?.toLocaleLowerCase().match(/application\/json/i)) {
|
|
68
|
+
const { exception, result, opRecords } = await response.json();
|
|
69
|
+
if (exception) {
|
|
70
|
+
throw this.makeException(exception);
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
result,
|
|
74
|
+
opRecords,
|
|
75
|
+
message,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
else if (responseType
|
|
79
|
+
?.toLocaleLowerCase()
|
|
80
|
+
.match(/application\/octet-stream/i)) {
|
|
81
|
+
const result = await response.arrayBuffer();
|
|
82
|
+
return {
|
|
83
|
+
result,
|
|
84
|
+
message,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
throw new Error(`尚不支持的content-type类型${responseType}`);
|
|
89
|
+
}
|
|
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
|
+
}
|
|
107
|
+
getRouter() {
|
|
108
|
+
return SimpleConnector.ASPECT_ROUTER;
|
|
109
|
+
}
|
|
110
|
+
getSubscribeRouter() {
|
|
111
|
+
return SimpleConnector.SUBSCRIBE_ROUTER;
|
|
112
|
+
}
|
|
113
|
+
getSubscribePointRouter() {
|
|
114
|
+
return SimpleConnector.SUBSCRIBE_POINT_ROUTER;
|
|
115
|
+
}
|
|
116
|
+
async getSubscribePoint() {
|
|
117
|
+
let response;
|
|
118
|
+
try {
|
|
119
|
+
response = await global.fetch(this.serverSubscribePointUrl);
|
|
120
|
+
}
|
|
121
|
+
catch (err) {
|
|
122
|
+
throw new types_1.OakNetworkException();
|
|
123
|
+
}
|
|
124
|
+
if (response.status > 299) {
|
|
125
|
+
const err = new types_1.OakServerProxyException(`网络请求返回status是${response.status}`);
|
|
126
|
+
throw err;
|
|
127
|
+
}
|
|
128
|
+
const message = response.headers.get('oak-message');
|
|
129
|
+
const responseType = response.headers.get('Content-Type') ||
|
|
130
|
+
response.headers.get('content-type');
|
|
131
|
+
if (responseType?.toLocaleLowerCase().match(/application\/json/i)) {
|
|
132
|
+
const { url, path, port, namespace } = await response.json();
|
|
133
|
+
let url2 = url || `${this.option.protocol}//${this.option.hostname}`;
|
|
134
|
+
(0, assert_1.default)(port);
|
|
135
|
+
url2 += `:${port}`;
|
|
136
|
+
if (namespace) {
|
|
137
|
+
url2 += namespace;
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
url: url2,
|
|
141
|
+
path,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
throw new Error(`尚不支持的content-type类型${responseType}`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
getEndpointRouter() {
|
|
149
|
+
return SimpleConnector.ENDPOINT_ROUTER;
|
|
150
|
+
}
|
|
151
|
+
parseRequest(headers, body, files) {
|
|
152
|
+
const { 'oak-cxt': oakCxtStr, 'oak-aspect': aspectName } = headers;
|
|
153
|
+
(0, assert_1.default)(typeof oakCxtStr === 'string' || oakCxtStr === undefined);
|
|
154
|
+
(0, assert_1.default)(typeof aspectName === 'string');
|
|
155
|
+
return {
|
|
156
|
+
contextString: oakCxtStr,
|
|
157
|
+
aspectName,
|
|
158
|
+
/* data: !files ? body : {
|
|
159
|
+
data: body,
|
|
160
|
+
files,
|
|
161
|
+
}, */ // 下个版本再改
|
|
162
|
+
data: files ? Object.assign({}, body, files) : body,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
async serializeResult(result, opRecords, headers, body, message) {
|
|
166
|
+
if (result instanceof stream_1.Stream || result instanceof Buffer) {
|
|
167
|
+
return {
|
|
168
|
+
body: result,
|
|
169
|
+
headers: {
|
|
170
|
+
'oak-message': message,
|
|
171
|
+
},
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
body: {
|
|
176
|
+
result,
|
|
177
|
+
opRecords,
|
|
178
|
+
},
|
|
179
|
+
headers: {
|
|
180
|
+
'oak-message': message,
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
serializeException(exception, headers, body) {
|
|
185
|
+
return {
|
|
186
|
+
body: {
|
|
187
|
+
exception: exception.toString(),
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
getBridgeRouter() {
|
|
192
|
+
return SimpleConnector.BRIDGE_ROUTER;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* 通过本地服务器桥接访问外部资源的url
|
|
196
|
+
* @param url
|
|
197
|
+
* @param headers
|
|
198
|
+
*/
|
|
199
|
+
makeBridgeUrl(url, headers) {
|
|
200
|
+
// if (process.env.PROD !== 'true') {
|
|
201
|
+
// console.warn('在development下无法通过bridge访问资源,将直接访问,可能失败', url);
|
|
202
|
+
// return url;
|
|
203
|
+
// }
|
|
204
|
+
const encodeUrl = encodeURIComponent(url);
|
|
205
|
+
return `${this.serverBridgeUrl}?url=${encodeUrl}`;
|
|
206
|
+
}
|
|
207
|
+
parseBridgeRequestQuery(urlParams) {
|
|
208
|
+
const search = new url_1.default.URLSearchParams(urlParams);
|
|
209
|
+
const url = search.get('url');
|
|
210
|
+
const headers = search.get('headers');
|
|
211
|
+
return {
|
|
212
|
+
url,
|
|
213
|
+
headers: headers && JSON.parse(headers),
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
exports.SimpleConnector = SimpleConnector;
|
package/lib/utils/assert.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 防止assert打包体积过大,从这里引用
|
|
3
|
-
*/
|
|
4
|
-
import assert from 'assert';
|
|
5
|
-
export { assert, };
|
|
1
|
+
/**
|
|
2
|
+
* 防止assert打包体积过大,从这里引用
|
|
3
|
+
*/
|
|
4
|
+
import assert from 'assert';
|
|
5
|
+
export { assert, };
|