oak-domain 5.1.29 → 5.1.30
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/compiler/schemalBuilder.d.ts +1 -1
- package/lib/compiler/schemalBuilder.js +71 -8
- package/lib/store/RelationAuth.js +4 -4
- package/lib/types/Configuration.d.ts +1 -0
- package/lib/types/Exception.d.ts +4 -2
- package/lib/types/Exception.js +11 -4
- package/lib/utils/geo.d.ts +1 -1
- package/lib/utils/geo.js +1 -1
- package/package.json +1 -1
|
@@ -13,7 +13,7 @@ declare const Schema: Record<string, {
|
|
|
13
13
|
inModi: boolean;
|
|
14
14
|
relations: false | string[];
|
|
15
15
|
extendsFrom: string[];
|
|
16
|
-
importAttrFrom: Record<string, [string, string | undefined]>;
|
|
16
|
+
importAttrFrom: Record<string, [string, string | undefined, string, string]>;
|
|
17
17
|
}>;
|
|
18
18
|
export declare function constructAttributes(entity: string): ts.PropertyAssignment[];
|
|
19
19
|
export declare function translateLocaleObject(locale: ts.ObjectLiteralExpression): Record<string, any>;
|
|
@@ -219,6 +219,43 @@ function addImportedFrom(moduleName, name, node) {
|
|
|
219
219
|
});
|
|
220
220
|
}
|
|
221
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* 计算编译后文件的正确导入路径
|
|
224
|
+
* @param sourceFilePath 源文件路径(相对于项目根目录),例如: 'src/entities/User.ts'
|
|
225
|
+
* @param outputFilePath 输出文件路径(相对于项目根目录),例如: 'src/oak-app-domain/User/_baseschema.ts'
|
|
226
|
+
* @param importPath 原始导入路径,例如: '../types/Config' 或 '@/utils/helper'
|
|
227
|
+
* @param projectRoot 项目根目录,默认为当前目录
|
|
228
|
+
* @returns 新的相对导入路径
|
|
229
|
+
*/
|
|
230
|
+
function resolveCompiledImportPath(sourceFilePath, outputFilePath, importPath, projectRoot = '.', relative) {
|
|
231
|
+
// 如果不是相对路径(例如 node_modules 的包或别名路径),直接返回
|
|
232
|
+
if (!importPath.startsWith('.')) {
|
|
233
|
+
return importPath;
|
|
234
|
+
}
|
|
235
|
+
if (sourceFilePath.startsWith("node_modules")) {
|
|
236
|
+
// 如果是node_modules下的文件,保持原有的处理逻辑
|
|
237
|
+
return importPath.startsWith('.') ? (relative
|
|
238
|
+
? path_1.default.join(relative, importPath).replace(/\\/g, '/')
|
|
239
|
+
: path_1.default.join('..', importPath).replace(/\\/g, '/')) : importPath;
|
|
240
|
+
}
|
|
241
|
+
// 1. 获取源文件所在目录
|
|
242
|
+
const sourceDir = path_1.default.dirname(sourceFilePath);
|
|
243
|
+
// 2. 解析原始导入路径,得到目标文件的绝对路径(相对于项目根目录)
|
|
244
|
+
const targetAbsolutePath = path_1.default.join(projectRoot, sourceDir, importPath);
|
|
245
|
+
const normalizedTargetPath = path_1.default.normalize(targetAbsolutePath);
|
|
246
|
+
// 3. 获取输出文件所在目录
|
|
247
|
+
const outputDir = path_1.default.dirname(outputFilePath);
|
|
248
|
+
const normalizedOutputDir = path_1.default.normalize(path_1.default.join(projectRoot, outputDir));
|
|
249
|
+
// 4. 计算从输出目录到目标文件的相对路径
|
|
250
|
+
let relativePath = path_1.default.relative(normalizedOutputDir, normalizedTargetPath);
|
|
251
|
+
// 5. 标准化路径分隔符为 '/'
|
|
252
|
+
relativePath = relativePath.replace(/\\/g, '/');
|
|
253
|
+
// 6. 确保相对路径以 './' 或 '../' 开头
|
|
254
|
+
if (!relativePath.startsWith('.')) {
|
|
255
|
+
relativePath = './' + relativePath;
|
|
256
|
+
}
|
|
257
|
+
return relativePath;
|
|
258
|
+
}
|
|
222
259
|
function analyzeExternalAttrImport(node, program, importAttrFrom, relativePath) {
|
|
223
260
|
const checker = program.getTypeChecker();
|
|
224
261
|
const symbol = checker.getSymbolAtLocation(node.typeName);
|
|
@@ -240,11 +277,19 @@ function analyzeExternalAttrImport(node, program, importAttrFrom, relativePath)
|
|
|
240
277
|
(0, assert_1.default)(importSpecifier, `未找到${name}的importSpecifier`);
|
|
241
278
|
const propertyName = importSpecifier.propertyName && importSpecifier.propertyName.text;
|
|
242
279
|
const importFrom = moduleSpecifier.text;
|
|
243
|
-
const importFromRelatively = importFrom.startsWith('.') ? (relativePath
|
|
244
|
-
|
|
245
|
-
|
|
280
|
+
// const importFromRelatively = importFrom.startsWith('.') ? (relativePath
|
|
281
|
+
// ? PathLib.join(
|
|
282
|
+
// relativePath,
|
|
283
|
+
// importFrom
|
|
284
|
+
// ).replace(/\\/g, '/')
|
|
285
|
+
// : PathLib.join(
|
|
286
|
+
// '..',
|
|
287
|
+
// importFrom
|
|
288
|
+
// ).replace(/\\/g, '/')) : importFrom;
|
|
289
|
+
const sourceFilePath = declaration.getSourceFile().fileName;
|
|
246
290
|
(0, lodash_1.assign)(importAttrFrom, {
|
|
247
|
-
[name]: [importFromRelatively, propertyName],
|
|
291
|
+
// [name]: [importFromRelatively, propertyName],
|
|
292
|
+
[name]: [importFrom, propertyName, sourceFilePath, relativePath],
|
|
248
293
|
});
|
|
249
294
|
}
|
|
250
295
|
else if (ts.isTypeAliasDeclaration(declaration)) {
|
|
@@ -3759,12 +3804,30 @@ function _outputBaseSchema(outputDir, printer) {
|
|
|
3759
3804
|
// 从外部引入的属性
|
|
3760
3805
|
const fromExternalImportAttrs = {};
|
|
3761
3806
|
for (const attr in importAttrFrom) {
|
|
3762
|
-
const [from, propertyName] = importAttrFrom[attr];
|
|
3763
|
-
if (fromExternalImportAttrs[from]) {
|
|
3764
|
-
|
|
3807
|
+
// const [from, propertyName] = importAttrFrom[attr];
|
|
3808
|
+
// if (fromExternalImportAttrs[from]) {
|
|
3809
|
+
// fromExternalImportAttrs[from].push([attr, propertyName]);
|
|
3810
|
+
// }
|
|
3811
|
+
// else {
|
|
3812
|
+
// fromExternalImportAttrs[from] = [[attr, propertyName]];
|
|
3813
|
+
// }
|
|
3814
|
+
const [from, propertyName, sourceFilePath, relative] = importAttrFrom[attr];
|
|
3815
|
+
// ===== 在这里进行路径转换 =====
|
|
3816
|
+
const outputFilePath = path_1.default.join(outputDir, entity, '_baseSchema.ts'); // 输出文件路径
|
|
3817
|
+
// 使用路径解析算法计算新的导入路径
|
|
3818
|
+
const newImportPath = resolveCompiledImportPath(path_1.default.relative(process.cwd(), sourceFilePath), path_1.default.relative(process.cwd(), outputFilePath), from, // 原始导入路径
|
|
3819
|
+
".", relative);
|
|
3820
|
+
// console.log('resolve import path:', {
|
|
3821
|
+
// sourceFilePath: PathLib.relative(process.cwd(), sourceFilePath),
|
|
3822
|
+
// outputFilePath: PathLib.relative(process.cwd(), outputFilePath),
|
|
3823
|
+
// from,
|
|
3824
|
+
// newImportPath,
|
|
3825
|
+
// });
|
|
3826
|
+
if (fromExternalImportAttrs[newImportPath]) {
|
|
3827
|
+
fromExternalImportAttrs[newImportPath].push([attr, propertyName]);
|
|
3765
3828
|
}
|
|
3766
3829
|
else {
|
|
3767
|
-
fromExternalImportAttrs[
|
|
3830
|
+
fromExternalImportAttrs[newImportPath] = [[attr, propertyName]];
|
|
3768
3831
|
}
|
|
3769
3832
|
}
|
|
3770
3833
|
for (const external in fromExternalImportAttrs) {
|
|
@@ -1120,12 +1120,12 @@ class RelationAuth {
|
|
|
1120
1120
|
if (result instanceof Promise) {
|
|
1121
1121
|
return result.then((r) => {
|
|
1122
1122
|
if (!r) {
|
|
1123
|
-
throw new types_1.OakDataInvisibleException(entity, operation);
|
|
1123
|
+
throw new types_1.OakDataInvisibleException(entity, operation, context.getCurrentUserId());
|
|
1124
1124
|
}
|
|
1125
1125
|
});
|
|
1126
1126
|
}
|
|
1127
1127
|
if (!result) {
|
|
1128
|
-
throw new types_1.OakDataInvisibleException(entity, operation);
|
|
1128
|
+
throw new types_1.OakDataInvisibleException(entity, operation, context.getCurrentUserId());
|
|
1129
1129
|
}
|
|
1130
1130
|
}
|
|
1131
1131
|
else {
|
|
@@ -1133,12 +1133,12 @@ class RelationAuth {
|
|
|
1133
1133
|
if (result instanceof Promise) {
|
|
1134
1134
|
return result.then((r) => {
|
|
1135
1135
|
if (!r) {
|
|
1136
|
-
throw new types_1.OakOperationUnpermittedException(entity, operation);
|
|
1136
|
+
throw new types_1.OakOperationUnpermittedException(entity, operation, context.getCurrentUserId());
|
|
1137
1137
|
}
|
|
1138
1138
|
});
|
|
1139
1139
|
}
|
|
1140
1140
|
if (!result) {
|
|
1141
|
-
throw new types_1.OakOperationUnpermittedException(entity, operation);
|
|
1141
|
+
throw new types_1.OakOperationUnpermittedException(entity, operation, context.getCurrentUserId());
|
|
1142
1142
|
}
|
|
1143
1143
|
}
|
|
1144
1144
|
}
|
|
@@ -56,6 +56,7 @@ export type ServerConfiguration = {
|
|
|
56
56
|
socket?: (ctx: Koa.ParameterizedContext<any, KoaRouter.IRouterParamContext<any, {}>, any>) => {
|
|
57
57
|
url: string;
|
|
58
58
|
} | undefined;
|
|
59
|
+
middleware?: Koa.Middleware[] | ((app: Koa<Koa.DefaultState, Koa.DefaultContext>) => Koa.Middleware[]);
|
|
59
60
|
};
|
|
60
61
|
/**
|
|
61
62
|
* 前后台访问配置
|
package/lib/types/Exception.d.ts
CHANGED
|
@@ -121,7 +121,8 @@ export declare class OakAttrCantUpdateException<ED extends EntityDict & BaseEnti
|
|
|
121
121
|
export declare class OakOperationUnpermittedException<ED extends EntityDict & BaseEntityDict, T extends keyof ED> extends OakUserException<ED> {
|
|
122
122
|
private entity;
|
|
123
123
|
private operation;
|
|
124
|
-
|
|
124
|
+
private userId?;
|
|
125
|
+
constructor(entity: T, operation: ED[T]['Selection'] | ED[T]['Operation'], userId?: string, message?: string, _module?: string, params?: Record<string, any>);
|
|
125
126
|
toString(): string;
|
|
126
127
|
}
|
|
127
128
|
/**
|
|
@@ -130,7 +131,8 @@ export declare class OakOperationUnpermittedException<ED extends EntityDict & Ba
|
|
|
130
131
|
export declare class OakDataInvisibleException<ED extends EntityDict & BaseEntityDict, T extends keyof ED> extends OakUserException<ED> {
|
|
131
132
|
private entity;
|
|
132
133
|
private operation;
|
|
133
|
-
|
|
134
|
+
private userId?;
|
|
135
|
+
constructor(entity: T, operation: ED[T]['Selection'] | ED[T]['Operation'], userId?: string, message?: string, _module?: string, params?: Record<string, any>);
|
|
134
136
|
toString(): string;
|
|
135
137
|
}
|
|
136
138
|
/**
|
package/lib/types/Exception.js
CHANGED
|
@@ -227,6 +227,7 @@ class OakInputIllegalException extends OakUserException {
|
|
|
227
227
|
entity;
|
|
228
228
|
constructor(entity, attributes, message, _module, params) {
|
|
229
229
|
super(message, _module, params || {
|
|
230
|
+
entity,
|
|
230
231
|
attributes: attributes.join(','),
|
|
231
232
|
});
|
|
232
233
|
this.entity = entity;
|
|
@@ -276,10 +277,12 @@ exports.OakAttrCantUpdateException = OakAttrCantUpdateException;
|
|
|
276
277
|
class OakOperationUnpermittedException extends OakUserException {
|
|
277
278
|
entity;
|
|
278
279
|
operation;
|
|
279
|
-
|
|
280
|
+
userId;
|
|
281
|
+
constructor(entity, operation, userId, message, _module, params) {
|
|
280
282
|
super(message || 'error::operationUnpermitted', _module || 'oak-domain', params);
|
|
281
283
|
this.entity = entity;
|
|
282
284
|
this.operation = operation;
|
|
285
|
+
this.userId = userId;
|
|
283
286
|
}
|
|
284
287
|
toString() {
|
|
285
288
|
const data = super.getSerialData();
|
|
@@ -287,6 +290,7 @@ class OakOperationUnpermittedException extends OakUserException {
|
|
|
287
290
|
...data,
|
|
288
291
|
entity: this.entity,
|
|
289
292
|
operation: this.operation,
|
|
293
|
+
userId: this.userId,
|
|
290
294
|
});
|
|
291
295
|
}
|
|
292
296
|
}
|
|
@@ -298,10 +302,12 @@ exports.OakOperationUnpermittedException = OakOperationUnpermittedException;
|
|
|
298
302
|
class OakDataInvisibleException extends OakUserException {
|
|
299
303
|
entity;
|
|
300
304
|
operation;
|
|
301
|
-
|
|
305
|
+
userId;
|
|
306
|
+
constructor(entity, operation, userId, message, _module, params) {
|
|
302
307
|
super(message || 'error::dataInvisible', _module || 'oak-domain', params);
|
|
303
308
|
this.entity = entity;
|
|
304
309
|
this.operation = operation;
|
|
310
|
+
this.userId = userId;
|
|
305
311
|
}
|
|
306
312
|
toString() {
|
|
307
313
|
const data = super.getSerialData();
|
|
@@ -309,6 +315,7 @@ class OakDataInvisibleException extends OakUserException {
|
|
|
309
315
|
...data,
|
|
310
316
|
entity: this.entity,
|
|
311
317
|
operation: this.operation,
|
|
318
|
+
userId: this.userId,
|
|
312
319
|
});
|
|
313
320
|
}
|
|
314
321
|
}
|
|
@@ -457,11 +464,11 @@ function makeException(data) {
|
|
|
457
464
|
break;
|
|
458
465
|
}
|
|
459
466
|
case 'OakOperationUnpermittedException': {
|
|
460
|
-
e = new OakOperationUnpermittedException(data.entity, data.operation, message, _module, params);
|
|
467
|
+
e = new OakOperationUnpermittedException(data.entity, data.operation, data.userId, message, _module, params);
|
|
461
468
|
break;
|
|
462
469
|
}
|
|
463
470
|
case 'OakDataInvisibleException': {
|
|
464
|
-
e = new OakDataInvisibleException(data.entity, data.operation, message, _module, params);
|
|
471
|
+
e = new OakDataInvisibleException(data.entity, data.operation, data.userId, message, _module, params);
|
|
465
472
|
break;
|
|
466
473
|
}
|
|
467
474
|
case 'OakUnloggedInException': {
|
package/lib/utils/geo.d.ts
CHANGED
package/lib/utils/geo.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.gcj02towgs84 = exports.wgs84togcj02 = exports.gcj02tobd09 = exports.bd09togcj02 = exports.getDistanceBetweenPoints = void 0;
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* 计算地球上两点之间的球面距离(单位:cm)
|
|
6
6
|
*/
|
|
7
7
|
function getDistanceBetweenPoints(lat1, lon1, lat2, lon2) {
|
|
8
8
|
// 转为弧度
|