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