oak-domain 4.5.0 → 5.0.0
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 +1 -1
- package/lib/base-app-domain/ActionDefDict.js +4 -4
- package/lib/base-app-domain/I18n/Storage.js +0 -1
- package/lib/base-app-domain/Modi/Action.d.ts +1 -1
- package/lib/base-app-domain/Modi/Action.js +2 -2
- package/lib/base-app-domain/Modi/Style.d.ts +3 -0
- package/lib/base-app-domain/Modi/Style.js +16 -0
- package/lib/base-app-domain/ModiEntity/Schema.d.ts +14 -0
- package/lib/base-app-domain/OperEntity/Schema.d.ts +14 -0
- package/lib/base-app-domain/StyleDict.d.ts +3 -0
- package/lib/base-app-domain/StyleDict.js +9 -0
- package/lib/base-app-domain/User/Action.d.ts +1 -1
- package/lib/base-app-domain/User/Action.js +2 -2
- package/lib/base-app-domain/User/Style.d.ts +3 -0
- package/lib/base-app-domain/User/Style.js +14 -0
- package/lib/base-app-domain/index.d.ts +1 -0
- package/lib/base-app-domain/index.js +1 -0
- package/lib/compiler/dependencyBuilder.d.ts +21 -0
- package/lib/compiler/dependencyBuilder.js +873 -0
- package/lib/compiler/env.d.ts +1 -1
- package/lib/compiler/env.js +2 -8
- package/lib/compiler/localeBuilder.js +13 -7
- package/lib/compiler/routerBuilder.js +29 -44
- package/lib/compiler/schemalBuilder.js +67 -8
- package/lib/entities/I18n.js +0 -3
- package/lib/entities/Modi.js +13 -0
- package/lib/entities/User.js +11 -0
- package/lib/store/IntrinsicCheckers.d.ts +2 -2
- package/lib/store/IntrinsicCheckers.js +83 -17
- package/lib/store/IntrinsicLogics.d.ts +2 -2
- package/lib/store/IntrinsicLogics.js +3 -3
- package/lib/store/filter.d.ts +47 -0
- package/lib/store/filter.js +49 -6
- package/lib/types/Action.d.ts +1 -1
- package/lib/types/Configuration.d.ts +42 -7
- package/lib/types/Configuration.js +0 -1
- package/lib/types/Connector.d.ts +3 -0
- package/lib/types/EntityDesc.d.ts +10 -3
- package/lib/types/Style.d.ts +35 -6
- package/lib/utils/SimpleConnector.d.ts +6 -10
- package/lib/utils/SimpleConnector.js +33 -20
- package/lib/utils/assert.d.ts +1 -0
- package/lib/utils/lodash.d.ts +10 -1
- package/lib/utils/lodash.js +27 -1
- package/lib/utils/module/combine.common.d.ts +15 -0
- package/lib/utils/module/combine.common.js +27 -0
- package/lib/utils/module/combine.d.ts +1 -0
- package/lib/utils/module/combine.dev.d.ts +17 -0
- package/lib/utils/module/combine.dev.js +55 -0
- package/lib/utils/module/combine.js +4 -0
- package/lib/utils/module/combine.prod.d.ts +8 -0
- package/lib/utils/module/combine.prod.js +8 -0
- package/lib/utils/module/combine.server.d.ts +17 -0
- package/lib/utils/module/combine.server.js +55 -0
- package/lib/utils/relationPath.js +1 -1
- package/package.json +1 -1
- package/src/entities/ActionAuth.ts +41 -41
- package/src/entities/I18n.ts +0 -3
- package/src/entities/Modi.ts +13 -0
- package/src/entities/ModiEntity.ts +26 -26
- 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 +12 -1
- package/src/entities/UserEntityClaim.ts +29 -29
- package/src/entities/UserEntityGrant.ts +24 -24
- package/src/entities/UserRelation.ts +50 -50
- package/lib/actions/relation.d.ts +0 -5
- package/lib/actions/relation.js +0 -25
- package/lib/base-app-domain/UserEntityGrant/Action.d.ts +0 -5
- package/lib/base-app-domain/UserEntityGrant/Action.js +0 -5
package/lib/store/filter.d.ts
CHANGED
|
@@ -4,6 +4,14 @@ import { AsyncContext } from './AsyncRowStore';
|
|
|
4
4
|
import { SyncContext } from './SyncRowStore';
|
|
5
5
|
export declare function translateCreateDataToFilter<ED extends EntityDict & BaseEntityDict, T extends keyof ED>(schema: StorageSchema<ED>, entity: T, data: ED[T]['CreateSingle']['data'], allowUnrecoganized: boolean): ED[T]["Selection"]["filter"];
|
|
6
6
|
export declare function combineFilters<ED extends EntityDict & BaseEntityDict, T extends keyof ED>(entity: T, schema: StorageSchema<ED>, filters: Array<ED[T]['Selection']['filter']>, union?: true): ED[T]["Selection"]["filter"] | undefined;
|
|
7
|
+
type DeducedFilter<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = {
|
|
8
|
+
entity: T;
|
|
9
|
+
filter: ED[T]['Selection']['filter'];
|
|
10
|
+
};
|
|
11
|
+
type DeducedFilterCombination<ED extends EntityDict & BaseEntityDict> = {
|
|
12
|
+
$or?: (DeducedFilterCombination<ED> | DeducedFilter<ED, keyof ED>)[];
|
|
13
|
+
$and?: (DeducedFilterCombination<ED> | DeducedFilter<ED, keyof ED>)[];
|
|
14
|
+
};
|
|
7
15
|
/**
|
|
8
16
|
* 在以下判断相容或相斥的过程中,相容/相斥的事实标准是:满足两个条件的查询集合是否被包容/互斥,但如果两个filter在逻辑上相容或者相斥,在事实上不一定相容或者相斥
|
|
9
17
|
* 例如:{ a: 1 } 和 { a: { $ne: 1 } } 是明显不相容的查询,但如果数据为空集,则这两个查询并不能否定其相容
|
|
@@ -35,6 +43,44 @@ export declare function combineFilters<ED extends EntityDict & BaseEntityDict, T
|
|
|
35
43
|
* @attention: 1)这里的测试不够充分,有些算子之间的相容或相斥可能有遗漏, 2)有新的算子加入需要修改代码
|
|
36
44
|
*/
|
|
37
45
|
export declare function judgeValueRelation(value1: any, value2: any, contained: boolean): boolean | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* 根据filter对compared查询的各个条件进行逐项分析
|
|
48
|
+
* @param entity
|
|
49
|
+
* @param schema
|
|
50
|
+
* @param filter
|
|
51
|
+
* @param compared
|
|
52
|
+
* @param contained
|
|
53
|
+
* @returns
|
|
54
|
+
* sureAttributes中包含被判定肯定相容或肯定不相斥的属性(不用再继续判定了)
|
|
55
|
+
* uncertainAttributes中包含的是无法判定结果的属性
|
|
56
|
+
* totalAndDeducedFilters包含的是判定过程中推论的相容的充分条件(and关系)
|
|
57
|
+
* totalOrDeducedFilters包含的是判定过程中推论的相斥的充分条件(or关系)
|
|
58
|
+
*/
|
|
59
|
+
export declare function analyzeFilterRelation<ED extends EntityDict & BaseEntityDict, T extends keyof ED>(entity: T, schema: StorageSchema<ED>, filter: NonNullable<ED[T]['Selection']['filter']>, compared: NonNullable<ED[T]['Selection']['filter']>, contained: boolean): boolean | {
|
|
60
|
+
totalAndDeducedFilters: (DeducedFilterCombination<ED> | DeducedFilter<ED, T>)[];
|
|
61
|
+
totalOrDeducedFilters: (DeducedFilterCombination<ED> | DeducedFilter<ED, T>)[];
|
|
62
|
+
uncertainAttributes: string[];
|
|
63
|
+
sureAttributes: string[];
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
*
|
|
67
|
+
* 判断filter是否包含contained中的查询条件,即filter查询的结果一定是contained查询结果的子集
|
|
68
|
+
* filter = {
|
|
69
|
+
* a: 1
|
|
70
|
+
* b: 2,
|
|
71
|
+
* c: 3,
|
|
72
|
+
* },
|
|
73
|
+
* conditionalFilter = {
|
|
74
|
+
* a: 1
|
|
75
|
+
* }
|
|
76
|
+
* 则包含
|
|
77
|
+
* @param entity
|
|
78
|
+
* @param schema
|
|
79
|
+
* @param filter
|
|
80
|
+
* @param contained
|
|
81
|
+
* @returns
|
|
82
|
+
*/
|
|
83
|
+
export declare function contains<ED extends EntityDict & BaseEntityDict, T extends keyof ED>(entity: T, schema: StorageSchema<ED>, filter: ED[T]['Selection']['filter'], contained: ED[T]['Selection']['filter']): boolean | DeducedFilterCombination<ED>;
|
|
38
84
|
/**
|
|
39
85
|
* 从filter中判断是否有确定的id对象,如果有则返回这些id,没有返回空数组
|
|
40
86
|
* @param filter
|
|
@@ -84,3 +130,4 @@ export declare function checkFilterRepel<ED extends EntityDict & BaseEntityDict,
|
|
|
84
130
|
* @param filter
|
|
85
131
|
*/
|
|
86
132
|
export declare function translateFilterToObjectPredicate(filter: Record<string, any>): {};
|
|
133
|
+
export {};
|
package/lib/store/filter.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.translateFilterToObjectPredicate = exports.checkFilterRepel = exports.checkFilterContains = exports.makeTreeDescendantFilter = exports.makeTreeAncestorFilter = exports.same = exports.getRelevantIds = exports.judgeValueRelation = exports.combineFilters = exports.translateCreateDataToFilter = void 0;
|
|
3
|
+
exports.translateFilterToObjectPredicate = exports.checkFilterRepel = exports.checkFilterContains = exports.makeTreeDescendantFilter = exports.makeTreeAncestorFilter = exports.same = exports.getRelevantIds = exports.contains = exports.analyzeFilterRelation = exports.judgeValueRelation = exports.combineFilters = exports.translateCreateDataToFilter = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
6
6
|
const types_1 = require("../types");
|
|
@@ -43,9 +43,24 @@ function addFilterSegment(entity, schema, ...filters) {
|
|
|
43
43
|
if (!filter[attr]) {
|
|
44
44
|
filter[attr] = value;
|
|
45
45
|
}
|
|
46
|
-
//
|
|
46
|
+
// 优化两个都等值且相等
|
|
47
47
|
else if (filter[attr] === value) {
|
|
48
48
|
}
|
|
49
|
+
// value定义的查询被当前查询包含
|
|
50
|
+
else if (contains(entity, schema, {
|
|
51
|
+
[attr]: value,
|
|
52
|
+
}, {
|
|
53
|
+
[attr]: filter[attr],
|
|
54
|
+
}) === true) {
|
|
55
|
+
filter[attr] = value;
|
|
56
|
+
}
|
|
57
|
+
// 当前查询被value所定义的查询包含
|
|
58
|
+
else if (contains(entity, schema, {
|
|
59
|
+
[attr]: filter[attr],
|
|
60
|
+
}, {
|
|
61
|
+
[attr]: value
|
|
62
|
+
}) == true) {
|
|
63
|
+
}
|
|
49
64
|
else {
|
|
50
65
|
addIntoAnd({
|
|
51
66
|
[attr]: value,
|
|
@@ -1041,15 +1056,20 @@ function judgeFilterSingleAttrRelation(entity, schema, attr, filter, compared, c
|
|
|
1041
1056
|
// 到这里说明无法直接判断此attr上的相容或者相斥,也无法把判定推断到更深层的算子之上
|
|
1042
1057
|
return;
|
|
1043
1058
|
}
|
|
1044
|
-
/**
|
|
1059
|
+
/**
|
|
1060
|
+
* 根据filter对compared查询的各个条件进行逐项分析
|
|
1045
1061
|
* @param entity
|
|
1046
1062
|
* @param schema
|
|
1047
1063
|
* @param filter
|
|
1048
1064
|
* @param compared
|
|
1049
|
-
* @param contained
|
|
1050
|
-
* @returns
|
|
1065
|
+
* @param contained
|
|
1066
|
+
* @returns
|
|
1067
|
+
* sureAttributes中包含被判定肯定相容或肯定不相斥的属性(不用再继续判定了)
|
|
1068
|
+
* uncertainAttributes中包含的是无法判定结果的属性
|
|
1069
|
+
* totalAndDeducedFilters包含的是判定过程中推论的相容的充分条件(and关系)
|
|
1070
|
+
* totalOrDeducedFilters包含的是判定过程中推论的相斥的充分条件(or关系)
|
|
1051
1071
|
*/
|
|
1052
|
-
function
|
|
1072
|
+
function analyzeFilterRelation(entity, schema, filter, compared, contained) {
|
|
1053
1073
|
const totalAndDeducedFilters = [];
|
|
1054
1074
|
const totalOrDeducedFilters = [];
|
|
1055
1075
|
const uncertainAttributes = [];
|
|
@@ -1239,6 +1259,28 @@ function judgeFilterRelation(entity, schema, filter, compared, contained) {
|
|
|
1239
1259
|
}
|
|
1240
1260
|
}
|
|
1241
1261
|
}
|
|
1262
|
+
return {
|
|
1263
|
+
totalAndDeducedFilters,
|
|
1264
|
+
totalOrDeducedFilters,
|
|
1265
|
+
uncertainAttributes,
|
|
1266
|
+
sureAttributes,
|
|
1267
|
+
};
|
|
1268
|
+
}
|
|
1269
|
+
exports.analyzeFilterRelation = analyzeFilterRelation;
|
|
1270
|
+
/** 判断filter条件对compared条件是否相容或相斥
|
|
1271
|
+
* @param entity
|
|
1272
|
+
* @param schema
|
|
1273
|
+
* @param filter
|
|
1274
|
+
* @param compared
|
|
1275
|
+
* @param contained: true代表判定filter包容compared(filter的查询结果是compared查询结果的子集), false代表判定filter与compared相斥(filter的查询结果与compared没有交集)
|
|
1276
|
+
* @returns 返回true说明肯定相容(相斥),返回false说明无法判定相容(相斥),返回DeducedFilterCombination说明需要进一步判断此推断的条件
|
|
1277
|
+
*/
|
|
1278
|
+
function judgeFilterRelation(entity, schema, filter, compared, contained) {
|
|
1279
|
+
const result = analyzeFilterRelation(entity, schema, filter, compared, contained);
|
|
1280
|
+
if (typeof result === 'boolean') {
|
|
1281
|
+
return result;
|
|
1282
|
+
}
|
|
1283
|
+
const { sureAttributes, uncertainAttributes, totalAndDeducedFilters, totalOrDeducedFilters, } = result;
|
|
1242
1284
|
if (contained) {
|
|
1243
1285
|
if (sureAttributes.length === Object.keys(compared).length) {
|
|
1244
1286
|
return true;
|
|
@@ -1296,6 +1338,7 @@ function contains(entity, schema, filter, contained) {
|
|
|
1296
1338
|
return judgeFilterRelation(entity, schema, filter, contained, true);
|
|
1297
1339
|
// return false;
|
|
1298
1340
|
}
|
|
1341
|
+
exports.contains = contains;
|
|
1299
1342
|
/**
|
|
1300
1343
|
* 判断filter1和filter2是否相斥,即filter1和filter2查询的结果一定没有交集
|
|
1301
1344
|
* filter1 = {
|
package/lib/types/Action.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export type ActionDef<A extends Action, S extends State> = {
|
|
|
8
8
|
};
|
|
9
9
|
is?: S;
|
|
10
10
|
};
|
|
11
|
-
export type
|
|
11
|
+
export type ActionDefDict<E extends EntityDict> = {
|
|
12
12
|
[T in keyof E]?: {
|
|
13
13
|
[A in keyof E[T]['OpSchema']]?: ActionDef<string, string>;
|
|
14
14
|
};
|
|
@@ -1,25 +1,33 @@
|
|
|
1
|
+
import { AuthDeduceRelationMap, EntityDict } from './Entity';
|
|
2
|
+
import { EntityDict as BaseEntityDict } from "../base-app-domain";
|
|
3
|
+
import { AsyncContext } from '../store/AsyncRowStore';
|
|
4
|
+
import { SyncConfig } from "./Sync";
|
|
5
|
+
import { AttrUpdateMatrix } from './EntityDesc';
|
|
6
|
+
import { ActionDefDict } from './Action';
|
|
7
|
+
import { StyleDict } from './Style';
|
|
1
8
|
/**
|
|
2
|
-
*
|
|
9
|
+
* 后台配置
|
|
3
10
|
*/
|
|
4
|
-
export type ServerConfiguration = {
|
|
11
|
+
export type ServerConfiguration<ED extends BaseEntityDict & EntityDict, Cxt extends AsyncContext<ED>> = {
|
|
5
12
|
database: {
|
|
6
13
|
type: 'mysql';
|
|
7
14
|
host: string;
|
|
8
15
|
database: string;
|
|
9
|
-
port
|
|
16
|
+
port?: number;
|
|
10
17
|
user: string;
|
|
11
18
|
password?: string;
|
|
12
19
|
connectionLimit: number;
|
|
13
20
|
charset: "utf8mb4_general_ci";
|
|
14
21
|
};
|
|
15
|
-
|
|
16
|
-
|
|
22
|
+
workDir: {
|
|
23
|
+
path: string;
|
|
17
24
|
};
|
|
25
|
+
sync?: SyncConfig<ED, Cxt>;
|
|
18
26
|
};
|
|
19
27
|
/**
|
|
20
|
-
*
|
|
28
|
+
* 前后台访问配置
|
|
21
29
|
*/
|
|
22
|
-
export type
|
|
30
|
+
export type AccessConfiguration = {
|
|
23
31
|
routerPrefixes?: {
|
|
24
32
|
aspect?: string;
|
|
25
33
|
endpoint?: string;
|
|
@@ -27,6 +35,33 @@ export type ProjectConfiguration = {
|
|
|
27
35
|
getSubscribePoint?: string;
|
|
28
36
|
bridge?: string;
|
|
29
37
|
};
|
|
38
|
+
http: {
|
|
39
|
+
hostname: string;
|
|
40
|
+
port?: number;
|
|
41
|
+
ssl?: boolean;
|
|
42
|
+
path?: string;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* 业务逻辑的通用配置
|
|
47
|
+
*/
|
|
48
|
+
export type CommonConfiguration<ED extends BaseEntityDict & EntityDict> = {
|
|
49
|
+
attrUpdateMatrix: AttrUpdateMatrix<ED>;
|
|
50
|
+
actionDefDict: ActionDefDict<ED>;
|
|
51
|
+
authDeduceRelationMap: AuthDeduceRelationMap<ED>;
|
|
52
|
+
selectFreeEntities?: (keyof ED)[];
|
|
53
|
+
updateFreeDict?: {
|
|
54
|
+
[A in keyof ED]?: string[];
|
|
55
|
+
};
|
|
56
|
+
cacheSavedEntities?: (keyof ED)[];
|
|
57
|
+
cacheKeepFreshPeriod?: number;
|
|
58
|
+
};
|
|
59
|
+
export type DependencyConfiguration = string[];
|
|
60
|
+
/**
|
|
61
|
+
* 渲染相关定义
|
|
62
|
+
*/
|
|
63
|
+
export type RenderConfiguration<ED extends BaseEntityDict & EntityDict> = {
|
|
64
|
+
styleDict: StyleDict<ED>;
|
|
30
65
|
};
|
|
31
66
|
/**
|
|
32
67
|
* 编译环境配置
|
package/lib/types/Connector.d.ts
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { LocaleDef } from './Locale';
|
|
2
2
|
import { Index } from './Storage';
|
|
3
3
|
import { EntityShape, Configuration, EntityDict } from './Entity';
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import { StyleDesc } from './Style';
|
|
5
|
+
export type EntityDesc<Schema extends EntityShape, Action extends string = '', Relation extends string = '', V extends Record<string, string> = {
|
|
6
|
+
['##oak_illegal##']: '';
|
|
7
|
+
}> = {
|
|
8
|
+
locales: LocaleDef<Schema, Action, Relation, keyof V extends '##oak_illegal##' ? {} : V>;
|
|
6
9
|
indexes?: Index<Schema>[];
|
|
7
10
|
configuration?: Configuration;
|
|
8
11
|
recursiveDepth?: number;
|
|
9
|
-
}
|
|
12
|
+
} & (Action extends '' ? (keyof V extends '##oak_illegal##' ? {} : {
|
|
13
|
+
style: StyleDesc<Action, V>;
|
|
14
|
+
}) : {
|
|
15
|
+
style: StyleDesc<Action, V>;
|
|
16
|
+
});
|
|
10
17
|
export type AttrUpdateMatrix<ED extends EntityDict> = {
|
|
11
18
|
[T in keyof ED]?: {
|
|
12
19
|
[A in keyof ED[T]['Update']['data']]?: {
|
package/lib/types/Style.d.ts
CHANGED
|
@@ -1,11 +1,40 @@
|
|
|
1
|
-
import { EntityDict } from './Entity';
|
|
1
|
+
import { EntityDict, GeneralEntityShape } from './Entity';
|
|
2
2
|
import { EntityDict as BaseEntityDict } from '../base-app-domain';
|
|
3
|
-
type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
type Color = `#${string}`;
|
|
4
|
+
type IconName = string;
|
|
5
|
+
export type StyleDesc<Action extends string = '', V extends Record<string, string> = {
|
|
6
|
+
['##oak_illegal##']: '';
|
|
7
|
+
}> = Action extends '' ? (keyof V extends '##oak_illegal##' ? {} : {
|
|
8
|
+
color: {
|
|
9
|
+
[A in keyof V]: {
|
|
10
|
+
[E in V[A]]: Color;
|
|
8
11
|
};
|
|
9
12
|
};
|
|
13
|
+
}) : (keyof V extends '##oak_illegal##' ? {
|
|
14
|
+
icon: {
|
|
15
|
+
[A in Action]?: IconName;
|
|
16
|
+
};
|
|
17
|
+
} : {
|
|
18
|
+
icon: {
|
|
19
|
+
[A in Action]?: IconName;
|
|
20
|
+
};
|
|
21
|
+
color: {
|
|
22
|
+
[A in keyof V]: {
|
|
23
|
+
[E in V[A]]: Color;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
export type StyleDef<ED extends GeneralEntityShape, Action extends string> = {
|
|
28
|
+
color?: {
|
|
29
|
+
[A in keyof ED]?: {
|
|
30
|
+
[E in ED[A]]?: Color;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
icon?: {
|
|
34
|
+
[A in Action]?: IconName;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
export type StyleDict<ED extends BaseEntityDict & EntityDict> = {
|
|
38
|
+
[T in keyof ED]?: StyleDef<ED[T]['OpSchema'], ED[T]['Action']>;
|
|
10
39
|
};
|
|
11
40
|
export {};
|
|
@@ -2,24 +2,20 @@
|
|
|
2
2
|
import { IncomingHttpHeaders } from "http";
|
|
3
3
|
import { SyncContext } from '../store/SyncRowStore';
|
|
4
4
|
import { Connector, EntityDict, OakException, OpRecord } from "../types";
|
|
5
|
-
|
|
6
|
-
|
|
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> {
|
|
5
|
+
import { AccessConfiguration } from '../types/Configuration';
|
|
6
|
+
export default class SimpleConnector<ED extends EntityDict, FrontCxt extends SyncContext<ED>> implements Connector<ED, FrontCxt> {
|
|
12
7
|
static ASPECT_ROUTER: string;
|
|
13
8
|
static BRIDGE_ROUTER: string;
|
|
14
9
|
static SUBSCRIBE_ROUTER: string;
|
|
15
10
|
static SUBSCRIBE_POINT_ROUTER: string;
|
|
16
11
|
static ENDPOINT_ROUTER: string;
|
|
12
|
+
private serverUrl;
|
|
17
13
|
private serverAspectUrl;
|
|
18
14
|
private serverBridgeUrl;
|
|
19
15
|
private serverSubscribePointUrl;
|
|
20
|
-
private
|
|
16
|
+
private configuration;
|
|
21
17
|
private makeException;
|
|
22
|
-
constructor(
|
|
18
|
+
constructor(configuration: AccessConfiguration, makeException: (exceptionData: any) => OakException<ED>);
|
|
23
19
|
protected makeHeadersAndBody(name: string, data: any, context?: FrontCxt): Promise<{
|
|
24
20
|
headers: Record<string, string>;
|
|
25
21
|
body: FormData;
|
|
@@ -77,5 +73,5 @@ export declare class SimpleConnector<ED extends EntityDict, FrontCxt extends Syn
|
|
|
77
73
|
url: string;
|
|
78
74
|
headers?: Record<string, string> | undefined;
|
|
79
75
|
};
|
|
76
|
+
getFullData(): Promise<{}>;
|
|
80
77
|
}
|
|
81
|
-
export {};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SimpleConnector = void 0;
|
|
4
3
|
const tslib_1 = require("tslib");
|
|
5
4
|
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
6
5
|
const stream_1 = require("stream");
|
|
@@ -12,25 +11,34 @@ class SimpleConnector {
|
|
|
12
11
|
static SUBSCRIBE_ROUTER = process.env.OAK_SUBSCRIBE_ROUTER || '/subscribe';
|
|
13
12
|
static SUBSCRIBE_POINT_ROUTER = '/subscribePoint';
|
|
14
13
|
static ENDPOINT_ROUTER = '/endpoint';
|
|
14
|
+
serverUrl;
|
|
15
15
|
serverAspectUrl;
|
|
16
16
|
serverBridgeUrl;
|
|
17
17
|
serverSubscribePointUrl;
|
|
18
|
-
|
|
18
|
+
configuration;
|
|
19
19
|
makeException;
|
|
20
|
-
constructor(
|
|
21
|
-
this.
|
|
22
|
-
const {
|
|
20
|
+
constructor(configuration, makeException) {
|
|
21
|
+
this.configuration = configuration;
|
|
22
|
+
const { routerPrefixes, http } = configuration;
|
|
23
|
+
const { ssl, hostname, port, path } = http;
|
|
24
|
+
const protocol = ssl ? 'https:' : 'http:';
|
|
23
25
|
let serverUrl = `${protocol}//${hostname}`;
|
|
26
|
+
this.serverUrl = serverUrl;
|
|
24
27
|
if (typeof port === 'number') {
|
|
25
28
|
serverUrl += `:${port}`;
|
|
26
29
|
}
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
if (path) {
|
|
31
|
+
if (path.startsWith('/')) {
|
|
32
|
+
serverUrl += path;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
serverUrl += `/${path}`;
|
|
36
|
+
}
|
|
30
37
|
}
|
|
31
|
-
this.serverAspectUrl = `${serverUrl}${SimpleConnector.ASPECT_ROUTER}`;
|
|
32
|
-
this.serverBridgeUrl = `${serverUrl}${SimpleConnector.BRIDGE_ROUTER}`;
|
|
33
|
-
this.serverSubscribePointUrl = `${serverUrl}${
|
|
38
|
+
this.serverAspectUrl = `${serverUrl}${routerPrefixes?.aspect || SimpleConnector.ASPECT_ROUTER}`;
|
|
39
|
+
this.serverBridgeUrl = `${serverUrl}${routerPrefixes?.bridge || SimpleConnector.BRIDGE_ROUTER}`;
|
|
40
|
+
this.serverSubscribePointUrl = `${serverUrl}${routerPrefixes?.getSubscribePoint ||
|
|
41
|
+
SimpleConnector.SUBSCRIBE_POINT_ROUTER}`;
|
|
34
42
|
this.makeException = makeException;
|
|
35
43
|
}
|
|
36
44
|
async makeHeadersAndBody(name, data, context) {
|
|
@@ -100,18 +108,18 @@ class SimpleConnector {
|
|
|
100
108
|
}
|
|
101
109
|
catch (err) {
|
|
102
110
|
// fetch返回异常一定是网络异常
|
|
103
|
-
throw new types_1.OakNetworkException(
|
|
111
|
+
throw new types_1.OakNetworkException(`接口请求时发生网络异常`);
|
|
104
112
|
}
|
|
105
113
|
return this.parseAspectResult(response);
|
|
106
114
|
}
|
|
107
115
|
getRouter() {
|
|
108
|
-
return SimpleConnector.ASPECT_ROUTER;
|
|
116
|
+
return this.configuration.routerPrefixes?.aspect || SimpleConnector.ASPECT_ROUTER;
|
|
109
117
|
}
|
|
110
118
|
getSubscribeRouter() {
|
|
111
|
-
return SimpleConnector.SUBSCRIBE_ROUTER;
|
|
119
|
+
return this.configuration.routerPrefixes?.subscribe || SimpleConnector.SUBSCRIBE_ROUTER;
|
|
112
120
|
}
|
|
113
121
|
getSubscribePointRouter() {
|
|
114
|
-
return SimpleConnector.SUBSCRIBE_POINT_ROUTER;
|
|
122
|
+
return this.configuration.routerPrefixes?.getSubscribePoint || SimpleConnector.SUBSCRIBE_POINT_ROUTER;
|
|
115
123
|
}
|
|
116
124
|
async getSubscribePoint() {
|
|
117
125
|
let response;
|
|
@@ -130,9 +138,10 @@ class SimpleConnector {
|
|
|
130
138
|
response.headers.get('content-type');
|
|
131
139
|
if (responseType?.toLocaleLowerCase().match(/application\/json/i)) {
|
|
132
140
|
const { url, path, port, namespace } = await response.json();
|
|
133
|
-
let url2 = url ||
|
|
134
|
-
|
|
135
|
-
|
|
141
|
+
let url2 = url || this.serverUrl;
|
|
142
|
+
if (port) {
|
|
143
|
+
url2 += `:${port}`;
|
|
144
|
+
}
|
|
136
145
|
if (namespace) {
|
|
137
146
|
url2 += namespace;
|
|
138
147
|
}
|
|
@@ -146,7 +155,7 @@ class SimpleConnector {
|
|
|
146
155
|
}
|
|
147
156
|
}
|
|
148
157
|
getEndpointRouter() {
|
|
149
|
-
return SimpleConnector.ENDPOINT_ROUTER;
|
|
158
|
+
return this.configuration.routerPrefixes?.endpoint || SimpleConnector.ENDPOINT_ROUTER;
|
|
150
159
|
}
|
|
151
160
|
parseRequest(headers, body, files) {
|
|
152
161
|
const { 'oak-cxt': oakCxtStr, 'oak-aspect': aspectName } = headers;
|
|
@@ -213,5 +222,9 @@ class SimpleConnector {
|
|
|
213
222
|
headers: headers && JSON.parse(headers),
|
|
214
223
|
};
|
|
215
224
|
}
|
|
225
|
+
async getFullData() {
|
|
226
|
+
console.error('前后台模式下暂时不支持此操作,请到数据库查看数据');
|
|
227
|
+
return {};
|
|
228
|
+
}
|
|
216
229
|
}
|
|
217
|
-
exports.
|
|
230
|
+
exports.default = SimpleConnector;
|
package/lib/utils/assert.d.ts
CHANGED
package/lib/utils/lodash.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ import intersection from 'lodash/intersection';
|
|
|
12
12
|
import intersectionBy from 'lodash/intersectionBy';
|
|
13
13
|
import omit from 'lodash/omit';
|
|
14
14
|
import merge from 'lodash/merge';
|
|
15
|
+
import mergeWith from 'lodash/mergeWith';
|
|
15
16
|
import cloneDeep from 'lodash/cloneDeep';
|
|
16
17
|
import pick from 'lodash/pick';
|
|
17
18
|
import isEqual from 'lodash/isEqual';
|
|
@@ -21,4 +22,12 @@ import differenceBy from 'lodash/differenceBy';
|
|
|
21
22
|
import groupBy from 'lodash/groupBy';
|
|
22
23
|
import unionBy from 'lodash/unionBy';
|
|
23
24
|
import pullAll from 'lodash/pullAll';
|
|
24
|
-
|
|
25
|
+
/**
|
|
26
|
+
* merge两个对象,遇到array时使用连接合并
|
|
27
|
+
* @param object
|
|
28
|
+
* @param source
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
31
|
+
declare function mergeConcatArray(object: any, source: any): any;
|
|
32
|
+
declare function mergeConcatMany<T>(array: Array<T>): T;
|
|
33
|
+
export { unset, pull, uniq, uniqBy, get, set, intersection, intersectionBy, omit, merge, mergeWith, mergeConcatArray, mergeConcatMany, cloneDeep, pick, isEqual, union, difference, differenceBy, groupBy, unionBy, pullAll, };
|
package/lib/utils/lodash.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pullAll = exports.unionBy = exports.groupBy = exports.differenceBy = exports.difference = exports.union = exports.isEqual = exports.pick = exports.cloneDeep = exports.merge = exports.omit = exports.intersectionBy = exports.intersection = exports.set = exports.get = exports.uniqBy = exports.uniq = exports.pull = exports.unset = void 0;
|
|
3
|
+
exports.pullAll = exports.unionBy = exports.groupBy = exports.differenceBy = exports.difference = exports.union = exports.isEqual = exports.pick = exports.cloneDeep = exports.mergeConcatMany = exports.mergeConcatArray = exports.mergeWith = exports.merge = exports.omit = exports.intersectionBy = exports.intersection = exports.set = exports.get = exports.uniqBy = exports.uniq = exports.pull = exports.unset = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
/**
|
|
6
6
|
* 避免lodash打包体积过大
|
|
@@ -26,6 +26,8 @@ const omit_1 = tslib_1.__importDefault(require("lodash/omit"));
|
|
|
26
26
|
exports.omit = omit_1.default;
|
|
27
27
|
const merge_1 = tslib_1.__importDefault(require("lodash/merge"));
|
|
28
28
|
exports.merge = merge_1.default;
|
|
29
|
+
const mergeWith_1 = tslib_1.__importDefault(require("lodash/mergeWith"));
|
|
30
|
+
exports.mergeWith = mergeWith_1.default;
|
|
29
31
|
const cloneDeep_1 = tslib_1.__importDefault(require("lodash/cloneDeep"));
|
|
30
32
|
exports.cloneDeep = cloneDeep_1.default;
|
|
31
33
|
const pick_1 = tslib_1.__importDefault(require("lodash/pick"));
|
|
@@ -44,3 +46,27 @@ const unionBy_1 = tslib_1.__importDefault(require("lodash/unionBy"));
|
|
|
44
46
|
exports.unionBy = unionBy_1.default;
|
|
45
47
|
const pullAll_1 = tslib_1.__importDefault(require("lodash/pullAll"));
|
|
46
48
|
exports.pullAll = pullAll_1.default;
|
|
49
|
+
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
50
|
+
/**
|
|
51
|
+
* merge两个对象,遇到array时使用连接合并
|
|
52
|
+
* @param object
|
|
53
|
+
* @param source
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
function mergeConcatArray(object, source) {
|
|
57
|
+
if (object instanceof Array) {
|
|
58
|
+
(0, assert_1.default)(source instanceof Array, '合并的对象必须结构一致');
|
|
59
|
+
return (0, uniq_1.default)(object.concat(source));
|
|
60
|
+
}
|
|
61
|
+
return (0, mergeWith_1.default)(object, source, (objValue, srcValue) => {
|
|
62
|
+
if (objValue instanceof Array) {
|
|
63
|
+
(0, assert_1.default)(srcValue instanceof Array, '合并的对象必须结构一致');
|
|
64
|
+
return (0, uniq_1.default)(objValue.concat(srcValue));
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
exports.mergeConcatArray = mergeConcatArray;
|
|
69
|
+
function mergeConcatMany(array) {
|
|
70
|
+
return array.reduce((prev, current) => mergeConcatArray(prev, current));
|
|
71
|
+
}
|
|
72
|
+
exports.mergeConcatMany = mergeConcatMany;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AsyncContext } from "../../store/AsyncRowStore";
|
|
2
|
+
import { SyncContext } from "../../store/SyncRowStore";
|
|
3
|
+
import { EntityDict } from "../../types/Entity";
|
|
4
|
+
import { EntityDict as BaseEntityDict } from '../../base-app-domain';
|
|
5
|
+
import { Checker } from '../../types/Auth';
|
|
6
|
+
import { CommonConfiguration } from '../../types/Configuration';
|
|
7
|
+
/**
|
|
8
|
+
* 合并引入模块中的checker和common
|
|
9
|
+
* @param modules
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export default function combineBaseModules<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED> | SyncContext<ED>>(...modules: string[]): {
|
|
13
|
+
checkers: Array<Checker<ED, keyof ED, Cxt>>;
|
|
14
|
+
common: CommonConfiguration<ED>;
|
|
15
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const lodash_1 = require("../../utils/lodash");
|
|
5
|
+
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
6
|
+
/**
|
|
7
|
+
* 合并引入模块中的checker和common
|
|
8
|
+
* @param modules
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
function combineBaseModules(...modules) {
|
|
12
|
+
// 合并模块中的checker/common
|
|
13
|
+
return modules.map((module) => {
|
|
14
|
+
const checkers = require(`${module}/lib/checkers`).default;
|
|
15
|
+
const common = require(`${module}/lib/configuration`).default;
|
|
16
|
+
(0, assert_1.default)(checkers instanceof Array, `${module}模块中的checkers不是数组`);
|
|
17
|
+
(0, assert_1.default)(typeof common === 'object', `${module}模块中的common配置不是对象`);
|
|
18
|
+
return {
|
|
19
|
+
checkers,
|
|
20
|
+
common,
|
|
21
|
+
};
|
|
22
|
+
}).reduce((prev, current) => ({
|
|
23
|
+
checkers: (0, lodash_1.mergeConcatArray)(prev.checkers, current.checkers),
|
|
24
|
+
common: (0, lodash_1.mergeConcatArray)(prev.common, current.common),
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
exports.default = combineBaseModules;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './combine.dev';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AsyncContext } from "../../store/AsyncRowStore";
|
|
2
|
+
import { SyncContext } from "../../store/SyncRowStore";
|
|
3
|
+
import { EntityDict } from "../../types/Entity";
|
|
4
|
+
import { EntityDict as BaseEntityDict } from '../../base-app-domain';
|
|
5
|
+
import { Aspect, Exportation, Importation, Routine, Timer, Trigger, Watcher } from '../../types';
|
|
6
|
+
export default function combineModuleDev<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>>(...modules: string[]): {
|
|
7
|
+
aspectDict: Record<string, Aspect<ED, Cxt>>;
|
|
8
|
+
data: { [T in keyof ED]?: ED[T]["OpSchema"][] | undefined; };
|
|
9
|
+
importations: Importation<ED, keyof ED, string, Cxt>;
|
|
10
|
+
exportations: Exportation<ED, keyof ED, string, Cxt>;
|
|
11
|
+
watchers: Watcher<ED, keyof ED, Cxt>[];
|
|
12
|
+
timers: Timer<ED, keyof ED, Cxt>[];
|
|
13
|
+
startRoutines: Routine<ED, keyof ED, Cxt>[];
|
|
14
|
+
triggers: Trigger<ED, keyof ED, Cxt>[];
|
|
15
|
+
checkers: import("../../types").Checker<ED, keyof ED, never>[];
|
|
16
|
+
common: import("../../types/Configuration").CommonConfiguration<ED>;
|
|
17
|
+
};
|