oak-domain 5.1.9 → 5.1.10

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.
@@ -461,7 +461,7 @@ function outputIntializeDev(cwd, dependencies, briefNames, sourceFile, printer,
461
461
  }
462
462
  });
463
463
  // startRoutine
464
- if ((0, fs_1.existsSync)(join(destDir, 'routines', 'start'))) {
464
+ if ((0, fs_1.existsSync)(join(destDir, 'routines', 'start.js'))) {
465
465
  const variableName = `${briefNames[idx]}StartRoutines`;
466
466
  importStatements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, factory.createIdentifier(variableName), undefined), factory.createStringLiteral(join(dep, destDirName, 'routines/start')), undefined));
467
467
  if (objectDict.startRoutines) {
@@ -583,11 +583,30 @@ function outputFeatureIndex(dependencies, briefNames, sourceFile, printer, filen
583
583
  if (dependencies.length > 0) {
584
584
  const importStatements = [];
585
585
  const fdNames = [];
586
+ const adNames = [];
586
587
  dependencies.forEach((dep, idx) => {
587
588
  const fdName = `${(0, string_1.firstLetterUpperCase)(briefNames[idx])}FeatureDict`;
588
- importStatements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, factory.createIdentifier("FeatureDict"), factory.createIdentifier(fdName))])), factory.createStringLiteral(dep), undefined));
589
+ const adName = `${(0, string_1.firstLetterUpperCase)(briefNames[idx])}AspectDict`;
590
+ // 导入FeatureDict和AspectDict
591
+ importStatements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
592
+ factory.createImportSpecifier(false, factory.createIdentifier("FeatureDict"), factory.createIdentifier(fdName)),
593
+ factory.createImportSpecifier(false, factory.createIdentifier("AspectDict"), factory.createIdentifier(adName))
594
+ ])), factory.createStringLiteral(dep), undefined));
589
595
  fdNames.push(fdName);
596
+ adNames.push(adName);
590
597
  });
598
+ // 导入自己的AspectDict:import { AspectDict } from '../aspects/AspectDict';
599
+ importStatements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, factory.createIdentifier("AspectDict"), factory.createIdentifier("ProjectAspectDict"))])), factory.createStringLiteral("../aspects/AspectDict"), undefined),
600
+ // import { createService } from 'oak-frontend-base/es/aspects/AspectService';
601
+ factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, undefined, factory.createIdentifier("createService"))])), factory.createStringLiteral("oak-frontend-base/es/aspects/AspectService"), undefined));
602
+ // 创建一个这样的type: type MergeAspectDict = ProjectAspectDict & GenernalAspectDict<EntityDict>;
603
+ // 除了ProjectAspectDict,还有其他的AspectDict,需要<EntityDict>参数
604
+ const adTypeDeclaration = factory.createTypeAliasDeclaration(undefined, factory.createIdentifier("MergeAspectDict"), undefined, factory.createIntersectionTypeNode([
605
+ factory.createTypeReferenceNode(factory.createIdentifier("ProjectAspectDict"), undefined),
606
+ ...adNames.map(ad => {
607
+ return factory.createTypeReferenceNode(factory.createIdentifier(ad), [factory.createTypeReferenceNode(factory.createIdentifier("EntityDict"), undefined)]);
608
+ })
609
+ ]));
591
610
  let i = 0;
592
611
  while (true) {
593
612
  const stmt = statements[i];
@@ -599,7 +618,7 @@ function outputFeatureIndex(dependencies, briefNames, sourceFile, printer, filen
599
618
  const stmt3 = statements[i - 1], stmt4 = statements[i];
600
619
  (0, assert_1.default)(ts.isImportDeclaration(stmt3) && ts.isFunctionDeclaration(stmt4));
601
620
  const { name, parameters } = stmt4;
602
- (0, assert_1.default)(ts.isIdentifier(name) && name.text === 'create' && parameters.length === 1);
621
+ (0, assert_1.default)(name && ts.isIdentifier(name) && name.text === 'create' && parameters.length === 1);
603
622
  const [param] = parameters;
604
623
  const { name: paramName, type } = param;
605
624
  (0, assert_1.default)(ts.isIdentifier(paramName) && paramName.text === 'features' && ts.isTypeReferenceNode(type));
@@ -611,9 +630,43 @@ function outputFeatureIndex(dependencies, briefNames, sourceFile, printer, filen
611
630
  ]))
612
631
  ])
613
632
  });
633
+ const functionBlock = stmt4.body;
634
+ (0, assert_1.default)(functionBlock && ts.isBlock(functionBlock));
635
+ let returnI = 0;
636
+ while (true) {
637
+ const stmt = functionBlock.statements[returnI];
638
+ if (ts.isReturnStatement(stmt)) {
639
+ break;
640
+ }
641
+ returnI++;
642
+ }
643
+ // 在return之前,插入const aspect = createService<EntityDict, MergeAspectDict>(cache);
644
+ const aspectDeclaration = factory.createVariableStatement(undefined, factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("aspect"), undefined, undefined, factory.createCallExpression(factory.createIdentifier("createService"), [
645
+ factory.createTypeReferenceNode(factory.createIdentifier("EntityDict"), undefined),
646
+ factory.createTypeReferenceNode(factory.createIdentifier("MergeAspectDict"), undefined)
647
+ ], [factory.createIdentifier("cache")]))], ts.NodeFlags.Const));
648
+ const returnStmt = functionBlock.statements[returnI];
649
+ (0, assert_1.default)(returnStmt.expression && ts.isObjectLiteralExpression(returnStmt.expression));
650
+ // 在里面添加aspect
651
+ const { properties } = returnStmt.expression;
652
+ Object.assign(returnStmt.expression, {
653
+ properties: [
654
+ ...properties,
655
+ factory.createShorthandPropertyAssignment(factory.createIdentifier("aspect"))
656
+ ]
657
+ });
658
+ // 把aspectDeclaration 插入到return之前
659
+ const newFunctionStatements = [
660
+ ...functionBlock.statements.slice(0, returnI),
661
+ aspectDeclaration,
662
+ ...functionBlock.statements.slice(returnI)
663
+ ];
664
+ const newBlock = factory.createBlock(newFunctionStatements);
665
+ Object.assign(functionBlock, newBlock);
614
666
  statements2 = [
615
667
  ...statements.slice(0, i),
616
668
  ...importStatements,
669
+ adTypeDeclaration,
617
670
  ...statements.slice(i)
618
671
  ];
619
672
  if (isModule) {
@@ -34,6 +34,9 @@ export type ServerConfiguration = {
34
34
  methods?: string[];
35
35
  };
36
36
  internalExceptionMask?: string;
37
+ koaBody?: {
38
+ maxFileSize?: number;
39
+ };
37
40
  };
38
41
  /**
39
42
  * 前后台访问配置
@@ -52,6 +55,7 @@ export type AccessConfiguration = {
52
55
  ssl?: boolean;
53
56
  path?: string;
54
57
  };
58
+ timeout?: number;
55
59
  };
56
60
  /**
57
61
  * 业务逻辑的通用配置
@@ -19,6 +19,9 @@ export declare class OakException<ED extends EntityDict & BaseEntityDict> extend
19
19
  tag2?: boolean;
20
20
  tag3?: any;
21
21
  }
22
+ export declare class OakRequestTimeoutException<ED extends EntityDict & BaseEntityDict> extends OakException<ED> {
23
+ constructor(message?: string);
24
+ }
22
25
  export declare class OakMakeSureByMySelfException<ED extends EntityDict & BaseEntityDict> extends OakException<ED> {
23
26
  }
24
27
  export declare class OakPartialSuccess<ED extends EntityDict & BaseEntityDict> extends OakException<ED> {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeException = exports.OakSocketConnectException = exports.OakExternalException = exports.OakPreConditionUnsetException = exports.OakDeadlock = exports.OakCongruentRowExists = exports.OakRowLockedException = exports.OakUnloggedInException = exports.OakUserInvisibleException = exports.OakUserUnpermittedException = exports.OakAttrCantUpdateException = exports.OakAttrNotNullException = exports.OakInputIllegalException = exports.OakRowInconsistencyException = exports.OakClockDriftException = exports.OakServerProxyException = exports.OakNetworkException = exports.OakImportDataParseException = exports.OakUniqueViolationException = exports.OakUserException = exports.OakRowUnexistedException = exports.OakOperExistedException = exports.OakNoRelationDefException = exports.OakDataException = exports.OakPartialSuccess = exports.OakMakeSureByMySelfException = exports.OakException = void 0;
3
+ exports.makeException = exports.OakSocketConnectException = exports.OakExternalException = exports.OakPreConditionUnsetException = exports.OakDeadlock = exports.OakCongruentRowExists = exports.OakRowLockedException = exports.OakUnloggedInException = exports.OakUserInvisibleException = exports.OakUserUnpermittedException = exports.OakAttrCantUpdateException = exports.OakAttrNotNullException = exports.OakInputIllegalException = exports.OakRowInconsistencyException = exports.OakClockDriftException = exports.OakServerProxyException = exports.OakNetworkException = exports.OakImportDataParseException = exports.OakUniqueViolationException = exports.OakUserException = exports.OakRowUnexistedException = exports.OakOperExistedException = exports.OakNoRelationDefException = exports.OakDataException = exports.OakPartialSuccess = exports.OakMakeSureByMySelfException = exports.OakRequestTimeoutException = exports.OakException = void 0;
4
4
  const relation_1 = require("../store/relation");
5
5
  const lodash_1 = require("../utils/lodash");
6
6
  class OakException extends Error {
@@ -90,6 +90,13 @@ class OakException extends Error {
90
90
  tag3;
91
91
  }
92
92
  exports.OakException = OakException;
93
+ // 请求超时
94
+ class OakRequestTimeoutException extends OakException {
95
+ constructor(message) {
96
+ super(message || '请求超时');
97
+ }
98
+ }
99
+ exports.OakRequestTimeoutException = OakRequestTimeoutException;
93
100
  // 这个异常表示模块自己处理跨事务一致性,框架pass(在分布式数据传递时会用到)(backend-base老版本有使用先保留)
94
101
  class OakMakeSureByMySelfException extends OakException {
95
102
  }
@@ -495,6 +502,14 @@ function makeException(data) {
495
502
  e = new OakSocketConnectException(data.message);
496
503
  break;
497
504
  }
505
+ case 'OakPartialSuccess': {
506
+ e = new OakPartialSuccess(data.message);
507
+ break;
508
+ }
509
+ case 'OakRequestTimeoutException': {
510
+ e = new OakRequestTimeoutException(data.message);
511
+ break;
512
+ }
498
513
  default:
499
514
  return;
500
515
  }
@@ -76,6 +76,7 @@ export interface SyncRemoteConfig<ED extends EntityDict & BaseEntityDict, Cxt ex
76
76
  }[];
77
77
  reason: Error;
78
78
  }, context: Cxt) => Promise<void>;
79
+ timeout?: number;
79
80
  }
80
81
  export interface SyncSelfConfigBase<ED extends EntityDict & BaseEntityDict> {
81
82
  endpoint?: string;
@@ -17,6 +17,7 @@ export default class SimpleConnector<ED extends EntityDict & BaseEntityDict, Fro
17
17
  private serverSubscribePointUrl;
18
18
  private configuration;
19
19
  private makeException;
20
+ private timeout;
20
21
  constructor(configuration: AccessConfiguration, makeException: (exceptionData: any) => OakException<ED>);
21
22
  getCorsHeader(): string[];
22
23
  protected makeHeadersAndBody(name: string, data: any, context?: FrontCxt): Promise<{
@@ -82,4 +83,5 @@ export default class SimpleConnector<ED extends EntityDict & BaseEntityDict, Fro
82
83
  headers?: Record<string, string> | undefined;
83
84
  };
84
85
  getFullData(): Promise<{}>;
86
+ private fetchWithTimeout;
85
87
  }
@@ -18,9 +18,11 @@ class SimpleConnector {
18
18
  serverSubscribePointUrl;
19
19
  configuration;
20
20
  makeException;
21
+ timeout;
21
22
  constructor(configuration, makeException) {
22
23
  this.configuration = configuration;
23
- const { routerPrefixes, http } = configuration;
24
+ const { routerPrefixes, http, timeout } = configuration;
25
+ this.timeout = timeout || 5000;
24
26
  const { ssl, hostname, port, path } = http;
25
27
  const protocol = ssl ? 'https:' : 'http:';
26
28
  let serverUrl = `${protocol}//${hostname}`;
@@ -108,11 +110,11 @@ class SimpleConnector {
108
110
  const { headers, body } = await this.makeHeadersAndBody(name, params, context);
109
111
  let response;
110
112
  try {
111
- response = await global.fetch(this.serverAspectUrl, {
113
+ response = await this.fetchWithTimeout(this.serverAspectUrl, {
112
114
  method: 'POST',
113
115
  headers,
114
116
  body,
115
- });
117
+ }, this.timeout);
116
118
  }
117
119
  catch (err) {
118
120
  // fetch返回异常一定是网络异常
@@ -135,7 +137,7 @@ class SimpleConnector {
135
137
  async getSocketPoint() {
136
138
  let response;
137
139
  try {
138
- response = await global.fetch(this.serverSubscribePointUrl);
140
+ response = await this.fetchWithTimeout(this.serverSubscribePointUrl, {}, this.timeout);
139
141
  }
140
142
  catch (err) {
141
143
  throw new types_1.OakNetworkException();
@@ -231,5 +233,29 @@ class SimpleConnector {
231
233
  console.error('前后台模式下暂时不支持此操作,请到数据库查看数据');
232
234
  return {};
233
235
  }
236
+ async fetchWithTimeout(url, options, timeout = 5000) {
237
+ if (typeof AbortController === 'undefined') {
238
+ return global.fetch(url, options);
239
+ }
240
+ const controller = new AbortController();
241
+ const signal = controller.signal;
242
+ // 设置超时
243
+ const timeoutId = setTimeout(() => {
244
+ controller.abort();
245
+ }, timeout);
246
+ // 发起 fetch 请求并传递 signal
247
+ return global.fetch(url, Object.assign({}, options, { signal }))
248
+ .then(response => {
249
+ clearTimeout(timeoutId); // 如果请求成功,清除超时
250
+ return response;
251
+ })
252
+ .catch(error => {
253
+ clearTimeout(timeoutId); // 如果请求失败,清除超时
254
+ if (error.name === 'AbortError') {
255
+ throw new types_1.OakRequestTimeoutException();
256
+ }
257
+ throw error; // 其他错误
258
+ });
259
+ }
234
260
  }
235
261
  exports.default = SimpleConnector;
@@ -2,3 +2,33 @@
2
2
  * 计算地球上两点之间的球面距离
3
3
  */
4
4
  export declare function getDistanceBetweenPoints(lat1: number, lon1: number, lat2: number, lon2: number): number;
5
+ /**
6
+ * 百度坐标系 (BD-09) 与 火星坐标系 (GCJ-02)的转换
7
+ * 即 百度 转 谷歌、高德
8
+ * @param bd_lon
9
+ * @param bd_lat
10
+ * @returns {*[]}
11
+ */
12
+ export declare function bd09togcj02(coord: [number, number]): number[];
13
+ /**
14
+ * 火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换
15
+ * 即谷歌、高德 转 百度
16
+ * @param lng
17
+ * @param lat
18
+ * @returns {*[]}
19
+ */
20
+ export declare function gcj02tobd09(coord: [number, number]): number[];
21
+ /**
22
+ * WGS84转GCj02
23
+ * @param lng
24
+ * @param lat
25
+ * @returns {*[]}
26
+ */
27
+ export declare function wgs84togcj02(coord: [number, number]): number[];
28
+ /**
29
+ * GCJ02 转换为 WGS84
30
+ * @param lng
31
+ * @param lat
32
+ * @returns {*[]}
33
+ */
34
+ export declare function gcj02towgs84(coord: [number, number]): number[];
package/lib/utils/geo.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDistanceBetweenPoints = void 0;
3
+ exports.gcj02towgs84 = exports.wgs84togcj02 = exports.gcj02tobd09 = exports.bd09togcj02 = exports.getDistanceBetweenPoints = void 0;
4
4
  /**
5
5
  * 计算地球上两点之间的球面距离
6
6
  */
@@ -22,3 +22,125 @@ function getDistanceBetweenPoints(lat1, lon1, lat2, lon2) {
22
22
  return d * 1000;
23
23
  }
24
24
  exports.getDistanceBetweenPoints = getDistanceBetweenPoints;
25
+ //定义一些常量
26
+ const x_PI = 3.14159265358979324 * 3000.0 / 180.0;
27
+ const PI = 3.1415926535897932384626;
28
+ const a = 6378245.0;
29
+ const ee = 0.00669342162296594323;
30
+ function transformlat(lng, lat) {
31
+ let ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat + 0.2 * Math.sqrt(Math.abs(lng));
32
+ ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
33
+ ret += (20.0 * Math.sin(lat * PI) + 40.0 * Math.sin(lat / 3.0 * PI)) * 2.0 / 3.0;
34
+ ret += (160.0 * Math.sin(lat / 12.0 * PI) + 320 * Math.sin(lat * PI / 30.0)) * 2.0 / 3.0;
35
+ return ret;
36
+ }
37
+ ;
38
+ function transformlng(lng, lat) {
39
+ let ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * Math.sqrt(Math.abs(lng));
40
+ ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
41
+ ret += (20.0 * Math.sin(lng * PI) + 40.0 * Math.sin(lng / 3.0 * PI)) * 2.0 / 3.0;
42
+ ret += (150.0 * Math.sin(lng / 12.0 * PI) + 300.0 * Math.sin(lng / 30.0 * PI)) * 2.0 / 3.0;
43
+ return ret;
44
+ }
45
+ ;
46
+ /**
47
+ * 判断是否在国内,不在国内则不做偏移
48
+ * @param lng
49
+ * @param lat
50
+ * @returns {boolean}
51
+ */
52
+ function out_of_china(lng, lat) {
53
+ // 纬度3.86~53.55,经度73.66~135.05
54
+ return !(lng > 73.66 && lng < 135.05 && lat > 3.86 && lat < 53.55);
55
+ }
56
+ ;
57
+ /**
58
+ * 百度坐标系 (BD-09) 与 火星坐标系 (GCJ-02)的转换
59
+ * 即 百度 转 谷歌、高德
60
+ * @param bd_lon
61
+ * @param bd_lat
62
+ * @returns {*[]}
63
+ */
64
+ function bd09togcj02(coord) {
65
+ const [bd_lon, bd_lat] = coord;
66
+ const x = bd_lon - 0.0065;
67
+ const y = bd_lat - 0.006;
68
+ const z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_PI);
69
+ const theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_PI);
70
+ const gg_lng = z * Math.cos(theta);
71
+ const gg_lat = z * Math.sin(theta);
72
+ return [gg_lng, gg_lat];
73
+ }
74
+ exports.bd09togcj02 = bd09togcj02;
75
+ ;
76
+ /**
77
+ * 火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换
78
+ * 即谷歌、高德 转 百度
79
+ * @param lng
80
+ * @param lat
81
+ * @returns {*[]}
82
+ */
83
+ function gcj02tobd09(coord) {
84
+ const [lng, lat] = coord;
85
+ const z = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * x_PI);
86
+ const theta = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * x_PI);
87
+ const bd_lng = z * Math.cos(theta) + 0.0065;
88
+ const bd_lat = z * Math.sin(theta) + 0.006;
89
+ return [bd_lng, bd_lat];
90
+ }
91
+ exports.gcj02tobd09 = gcj02tobd09;
92
+ ;
93
+ /**
94
+ * WGS84转GCj02
95
+ * @param lng
96
+ * @param lat
97
+ * @returns {*[]}
98
+ */
99
+ function wgs84togcj02(coord) {
100
+ const [lng, lat] = coord;
101
+ if (out_of_china(lng, lat)) {
102
+ return [lng, lat];
103
+ }
104
+ else {
105
+ let dlat = transformlat(lng - 105.0, lat - 35.0);
106
+ let dlng = transformlng(lng - 105.0, lat - 35.0);
107
+ const radlat = lat / 180.0 * PI;
108
+ let magic = Math.sin(radlat);
109
+ magic = 1 - ee * magic * magic;
110
+ const sqrtmagic = Math.sqrt(magic);
111
+ dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * PI);
112
+ dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * PI);
113
+ const mglat = lat + dlat;
114
+ const mglng = lng + dlng;
115
+ return [mglng, mglat];
116
+ }
117
+ }
118
+ exports.wgs84togcj02 = wgs84togcj02;
119
+ ;
120
+ /**
121
+ * GCJ02 转换为 WGS84
122
+ * @param lng
123
+ * @param lat
124
+ * @returns {*[]}
125
+ */
126
+ function gcj02towgs84(coord) {
127
+ const [lng, lat] = coord;
128
+ if (out_of_china(lng, lat)) {
129
+ return [lng, lat];
130
+ }
131
+ else {
132
+ let dlat = transformlat(lng - 105.0, lat - 35.0);
133
+ let dlng = transformlng(lng - 105.0, lat - 35.0);
134
+ const radlat = lat / 180.0 * PI;
135
+ let magic = Math.sin(radlat);
136
+ magic = 1 - ee * magic * magic;
137
+ const sqrtmagic = Math.sqrt(magic);
138
+ dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * PI);
139
+ dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * PI);
140
+ const mglat = lat + dlat;
141
+ const mglng = lng + dlng;
142
+ return [lng * 2 - mglng, lat * 2 - mglat];
143
+ }
144
+ }
145
+ exports.gcj02towgs84 = gcj02towgs84;
146
+ ;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oak-domain",
3
- "version": "5.1.9",
3
+ "version": "5.1.10",
4
4
  "author": {
5
5
  "name": "XuChang"
6
6
  },