oak-domain 2.3.1 → 2.4.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/actions/relation.d.ts +4 -0
- package/lib/actions/relation.js +36 -0
- package/lib/base-app-domain/Modi/Schema.d.ts +2 -4
- package/lib/base-app-domain/ModiEntity/Schema.d.ts +2 -4
- package/lib/base-app-domain/Oper/Schema.d.ts +2 -4
- package/lib/base-app-domain/OperEntity/Schema.d.ts +2 -4
- package/lib/base-app-domain/User/Schema.d.ts +2 -4
- package/lib/checkers/index.d.ts +2 -2
- package/lib/checkers/index.js +4 -2
- package/lib/compiler/schemalBuilder.js +87 -31
- package/lib/store/CascadeStore.d.ts +4 -4
- package/lib/store/TriggerExecutor.js +45 -26
- package/lib/store/checker.d.ts +10 -4
- package/lib/store/checker.js +342 -232
- package/lib/store/filter.d.ts +11 -2
- package/lib/store/filter.js +40 -25
- package/lib/store/modi.js +0 -8
- package/lib/store/relation.d.ts +1 -1
- package/lib/store/relation.js +1 -1
- package/lib/types/Action.d.ts +5 -1
- package/lib/types/Auth.d.ts +26 -26
- package/lib/types/Endpoint.d.ts +10 -0
- package/lib/types/Endpoint.js +3 -0
- package/lib/types/Entity.d.ts +55 -69
- package/lib/types/Entity.js +0 -1
- package/lib/types/Exception.d.ts +5 -0
- package/lib/types/Exception.js +16 -1
- package/lib/types/Expression.d.ts +24 -2
- package/lib/types/Expression.js +27 -2
- package/lib/types/Port.d.ts +17 -0
- package/lib/types/Port.js +2 -0
- package/lib/types/Storage.d.ts +4 -4
- package/lib/types/Trigger.d.ts +2 -2
- package/lib/types/index.d.ts +2 -0
- package/lib/types/index.js +2 -0
- package/lib/utils/date.d.ts +1 -0
- package/lib/utils/date.js +18 -0
- package/package.json +2 -2
package/lib/store/filter.d.ts
CHANGED
|
@@ -96,5 +96,14 @@ export declare function makeTreeAncestorFilter<ED extends EntityDict, T extends
|
|
|
96
96
|
* @param level
|
|
97
97
|
*/
|
|
98
98
|
export declare function makeTreeDescendantFilter<ED extends EntityDict, T extends keyof ED>(entity: T, parentKey: string, filter: ED[T]['Selection']['filter'], level?: number, includeAll?: boolean, includeSelf?: boolean): ED[T]['Selection']['filter'];
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
/**
|
|
100
|
+
* 检查filter是否包含contained(filter查询的数据一定满足contained)
|
|
101
|
+
* @param entity
|
|
102
|
+
* @param context
|
|
103
|
+
* @param contained
|
|
104
|
+
* @param filter
|
|
105
|
+
* @param dataCompare
|
|
106
|
+
* @returns
|
|
107
|
+
*/
|
|
108
|
+
export declare function checkFilterContains<ED extends EntityDict, T extends keyof ED, Cxt extends SyncContext<ED> | AsyncContext<ED>>(entity: T, context: Cxt, contained: ED[T]['Selection']['filter'], filter?: ED[T]['Selection']['filter'], dataCompare?: true): boolean | Promise<boolean>;
|
|
109
|
+
export declare function checkFilterRepel<ED extends EntityDict, T extends keyof ED, Cxt extends SyncContext<ED> | AsyncContext<ED>>(entity: T, context: Cxt, filter1: ED[T]['Selection']['filter'], filter2: ED[T]['Selection']['filter'], dataCompare?: true): boolean | Promise<boolean>;
|
package/lib/store/filter.js
CHANGED
|
@@ -828,7 +828,16 @@ function makeTreeDescendantFilter(entity, parentKey, filter, level, includeAll,
|
|
|
828
828
|
return currentLevelInFilter;
|
|
829
829
|
}
|
|
830
830
|
exports.makeTreeDescendantFilter = makeTreeDescendantFilter;
|
|
831
|
-
|
|
831
|
+
/**
|
|
832
|
+
* 检查filter是否包含contained(filter查询的数据一定满足contained)
|
|
833
|
+
* @param entity
|
|
834
|
+
* @param context
|
|
835
|
+
* @param contained
|
|
836
|
+
* @param filter
|
|
837
|
+
* @param dataCompare
|
|
838
|
+
* @returns
|
|
839
|
+
*/
|
|
840
|
+
function checkFilterContains(entity, context, contained, filter, dataCompare) {
|
|
832
841
|
if (!filter) {
|
|
833
842
|
throw new types_1.OakRowInconsistencyException();
|
|
834
843
|
}
|
|
@@ -837,23 +846,26 @@ function checkFilterContains(entity, context, contained, filter) {
|
|
|
837
846
|
if (contains(entity, schema, filter, contained)) {
|
|
838
847
|
return true;
|
|
839
848
|
}
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
849
|
+
if (dataCompare) {
|
|
850
|
+
// 再判断加上了conditionalFilter后取得的行数是否缩减
|
|
851
|
+
var filter2 = combineFilters([filter, {
|
|
852
|
+
$not: contained,
|
|
853
|
+
}]);
|
|
854
|
+
var count = context.count(entity, {
|
|
855
|
+
filter: filter2,
|
|
856
|
+
}, {
|
|
857
|
+
dontCollect: true,
|
|
858
|
+
blockTrigger: true,
|
|
859
|
+
});
|
|
860
|
+
if (count instanceof Promise) {
|
|
861
|
+
return count.then(function (count2) { return count2 === 0; });
|
|
862
|
+
}
|
|
863
|
+
return count === 0;
|
|
852
864
|
}
|
|
853
|
-
return
|
|
865
|
+
return false;
|
|
854
866
|
}
|
|
855
867
|
exports.checkFilterContains = checkFilterContains;
|
|
856
|
-
function checkFilterRepel(entity, context, filter1, filter2) {
|
|
868
|
+
function checkFilterRepel(entity, context, filter1, filter2, dataCompare) {
|
|
857
869
|
if (!filter2) {
|
|
858
870
|
throw new types_1.OakRowInconsistencyException();
|
|
859
871
|
}
|
|
@@ -863,16 +875,19 @@ function checkFilterRepel(entity, context, filter1, filter2) {
|
|
|
863
875
|
return true;
|
|
864
876
|
}
|
|
865
877
|
// 再判断两者同时成立时取得的行数是否为0
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
878
|
+
if (dataCompare) {
|
|
879
|
+
var filter3 = combineFilters([filter2, filter1]);
|
|
880
|
+
var count = context.count(entity, {
|
|
881
|
+
filter: filter3,
|
|
882
|
+
}, {
|
|
883
|
+
dontCollect: true,
|
|
884
|
+
blockTrigger: true,
|
|
885
|
+
});
|
|
886
|
+
if (count instanceof Promise) {
|
|
887
|
+
return count.then(function (count2) { return count2 === 0; });
|
|
888
|
+
}
|
|
889
|
+
return count === 0;
|
|
875
890
|
}
|
|
876
|
-
return
|
|
891
|
+
return false;
|
|
877
892
|
}
|
|
878
893
|
exports.checkFilterRepel = checkFilterRepel;
|
package/lib/store/modi.js
CHANGED
|
@@ -58,14 +58,6 @@ function abandonModis(filter, context, option) {
|
|
|
58
58
|
_d.action = 'abandon',
|
|
59
59
|
_d.data = {},
|
|
60
60
|
_d.filter = filter,
|
|
61
|
-
_d.sorter = [
|
|
62
|
-
{
|
|
63
|
-
$attr: {
|
|
64
|
-
$$createAt$$: 1,
|
|
65
|
-
},
|
|
66
|
-
$direction: 'asc',
|
|
67
|
-
}
|
|
68
|
-
],
|
|
69
61
|
_d), Object.assign({}, option, {
|
|
70
62
|
blockTrigger: false,
|
|
71
63
|
})]))];
|
package/lib/store/relation.d.ts
CHANGED
|
@@ -10,4 +10,4 @@ import { StorageSchema } from "../types/Storage";
|
|
|
10
10
|
*/
|
|
11
11
|
export declare function judgeRelation<ED extends {
|
|
12
12
|
[E: string]: EntityDef;
|
|
13
|
-
}>(schema: StorageSchema<ED>, entity: keyof ED, attr: string): string |
|
|
13
|
+
}>(schema: StorageSchema<ED>, entity: keyof ED, attr: string): string | 1 | 2 | string[] | 0;
|
package/lib/store/relation.js
CHANGED
|
@@ -59,7 +59,7 @@ function judgeRelation(schema, entity, attr) {
|
|
|
59
59
|
return 2;
|
|
60
60
|
}
|
|
61
61
|
else {
|
|
62
|
-
(0, assert_1.default)(Entity_1.initinctiveAttributes.includes(attr), "".concat(attr, "\u5C5E\u6027\u627E\u4E0D\u5230"));
|
|
62
|
+
(0, assert_1.default)(Entity_1.initinctiveAttributes.includes(attr), "".concat(entity, "\u5BF9\u8C61\u4E2D\u7684").concat(attr, "\u5C5E\u6027\u627E\u4E0D\u5230"));
|
|
63
63
|
return 1;
|
|
64
64
|
}
|
|
65
65
|
}
|
package/lib/types/Action.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { EntityDict } from "./Entity";
|
|
1
|
+
import { CascadeRelationItem, EntityDict } from "./Entity";
|
|
2
|
+
import { GenericAction } from '../actions/action';
|
|
2
3
|
export declare type Action = string;
|
|
3
4
|
export declare type State = string;
|
|
4
5
|
export declare type ActionDef<A extends Action, S extends State> = {
|
|
@@ -12,3 +13,6 @@ export declare type ActionDictOfEntityDict<E extends EntityDict> = {
|
|
|
12
13
|
[A in keyof E[T]['OpSchema']]?: ActionDef<string, string>;
|
|
13
14
|
};
|
|
14
15
|
};
|
|
16
|
+
export declare type CascadeActionAuth<A extends Action = ''> = {
|
|
17
|
+
[K in A | GenericAction]?: CascadeRelationItem | (CascadeRelationItem | CascadeRelationItem[])[];
|
|
18
|
+
};
|
package/lib/types/Auth.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { CascadeActionAuth, CascadeRelationAuth } from ".";
|
|
1
2
|
import { AsyncContext } from "../store/AsyncRowStore";
|
|
2
3
|
import { SyncContext } from "../store/SyncRowStore";
|
|
3
4
|
import { EntityDict, OperateOption, SelectOption } from "../types/Entity";
|
|
4
|
-
|
|
5
|
-
export declare type CheckerType = 'relation' | 'row' | 'data' | 'expression' | 'expressionRelation';
|
|
5
|
+
export declare type CheckerType = 'relation' | 'row' | 'data' | 'logical' | 'logicalRelation';
|
|
6
6
|
/**
|
|
7
7
|
* conditionalFilter是指该action发生时,operation所操作的行中有满足conditionalFilter的行
|
|
8
8
|
* 被转化成trigger的filter条件,详细可看trigger中的说明
|
|
@@ -12,55 +12,55 @@ export declare type DataChecker<ED extends EntityDict, T extends keyof ED, Cxt e
|
|
|
12
12
|
type: 'data';
|
|
13
13
|
entity: T;
|
|
14
14
|
action: Omit<ED[T]['Action'], 'remove'> | Array<Omit<ED[T]['Action'], 'remove'>>;
|
|
15
|
-
checker: (data: ED[T]['Create']['data'] | ED[T]['Update']['data'], context: Cxt) => void
|
|
16
|
-
conditionalFilter?: ED[T]['Update']['filter'] | ((operation: ED[T]['Operation'], context: Cxt, option: OperateOption) => ED[T]['Update']['filter']);
|
|
15
|
+
checker: (data: ED[T]['Create']['data'] | ED[T]['Update']['data'], context: Cxt) => void | Promise<void>;
|
|
16
|
+
conditionalFilter?: ED[T]['Update']['filter'] | ((operation: ED[T]['Operation'], context: Cxt, option: OperateOption) => ED[T]['Update']['filter'] | Promise<ED[T]['Selection']['filter']>);
|
|
17
17
|
};
|
|
18
18
|
export declare type RowChecker<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = {
|
|
19
19
|
priority?: number;
|
|
20
20
|
type: 'row';
|
|
21
21
|
entity: T;
|
|
22
22
|
action: Omit<ED[T]['Action'], 'create'> | Array<Omit<ED[T]['Action'], 'create'>>;
|
|
23
|
-
filter: ED[T]['Selection']['filter'] | ((operation: ED[T]['Operation'] | ED[T]['Selection'], context: Cxt, option: OperateOption | SelectOption) => ED[T]['Selection']['filter']);
|
|
23
|
+
filter: ED[T]['Selection']['filter'] | ((operation: ED[T]['Operation'] | ED[T]['Selection'], context: Cxt, option: OperateOption | SelectOption) => ED[T]['Selection']['filter'] | Promise<ED[T]['Selection']['filter']>);
|
|
24
24
|
errMsg?: string;
|
|
25
25
|
inconsistentRows?: {
|
|
26
26
|
entity: keyof ED;
|
|
27
27
|
selection: (filter?: ED[T]['Selection']['filter']) => ED[keyof ED]['Selection'];
|
|
28
28
|
};
|
|
29
|
-
conditionalFilter?: ED[T]['Update']['filter'] | ((operation: ED[T]['Operation'], context: Cxt, option: OperateOption) => ED[T]['Update']['filter']);
|
|
29
|
+
conditionalFilter?: ED[T]['Update']['filter'] | ((operation: ED[T]['Operation'], context: Cxt, option: OperateOption) => ED[T]['Update']['filter'] | Promise<ED[T]['Update']['filter']>);
|
|
30
30
|
};
|
|
31
31
|
export declare type RelationChecker<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = {
|
|
32
32
|
priority?: number;
|
|
33
33
|
type: 'relation';
|
|
34
34
|
entity: T;
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
when?: 'after';
|
|
36
|
+
action: ED[T]['Action'] | Array<ED[T]['Action']>;
|
|
37
|
+
relationFilter: (operation: ED[T]['Operation'] | ED[T]['Selection'], context: Cxt, option: OperateOption | SelectOption) => ED[T]['Selection']['filter'] | Promise<ED[T]['Selection']['filter']>;
|
|
37
38
|
errMsg: string;
|
|
38
|
-
conditionalFilter?: ED[T]['Update']['filter'] | ((operation: ED[T]['Operation'], context: Cxt, option: OperateOption) => ED[T]['Update']['filter']);
|
|
39
|
+
conditionalFilter?: ED[T]['Update']['filter'] | ((operation: ED[T]['Operation'], context: Cxt, option: OperateOption) => ED[T]['Update']['filter'] | Promise<ED[T]['Selection']['filter']>);
|
|
39
40
|
};
|
|
40
|
-
export declare type
|
|
41
|
+
export declare type LogicalChecker<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = {
|
|
41
42
|
priority?: number;
|
|
42
|
-
type: '
|
|
43
|
+
type: 'logical';
|
|
44
|
+
when?: 'after';
|
|
43
45
|
entity: T;
|
|
44
46
|
action: ED[T]['Action'] | Array<ED[T]['Action']>;
|
|
45
|
-
|
|
46
|
-
entity: T2;
|
|
47
|
-
expr: RefOrExpression<keyof ED[T2]['OpSchema']>;
|
|
48
|
-
filter: ED[T2]['Selection']['filter'];
|
|
49
|
-
} | undefined | string;
|
|
50
|
-
errMsg: string;
|
|
47
|
+
checker: (operation: ED[T]['Operation'] | ED[T]['Selection'], context: Cxt, option: OperateOption | SelectOption) => void | Promise<void>;
|
|
51
48
|
conditionalFilter?: ED[T]['Update']['filter'] | ((operation: ED[T]['Operation'], context: Cxt, option: OperateOption) => ED[T]['Update']['filter']);
|
|
52
49
|
};
|
|
53
|
-
export declare type
|
|
50
|
+
export declare type LogicalRelationChecker<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = {
|
|
54
51
|
priority?: number;
|
|
55
|
-
type: '
|
|
52
|
+
type: 'logicalRelation';
|
|
53
|
+
when?: 'after';
|
|
56
54
|
entity: T;
|
|
57
55
|
action: ED[T]['Action'] | Array<ED[T]['Action']>;
|
|
58
|
-
|
|
59
|
-
entity: T2;
|
|
60
|
-
expr: RefOrExpression<keyof ED[T2]['OpSchema']>;
|
|
61
|
-
filter: ED[T2]['Selection']['filter'];
|
|
62
|
-
} | undefined | string;
|
|
63
|
-
errMsg: string;
|
|
56
|
+
checker: (operation: ED[T]['Operation'] | ED[T]['Selection'], context: Cxt, option: OperateOption | SelectOption) => void | Promise<void>;
|
|
64
57
|
conditionalFilter?: ED[T]['Update']['filter'] | ((operation: ED[T]['Operation'], context: Cxt, option: OperateOption) => ED[T]['Update']['filter']);
|
|
65
58
|
};
|
|
66
|
-
export declare type Checker<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = DataChecker<ED, T, Cxt> | RowChecker<ED, T, Cxt> | RelationChecker<ED, T, Cxt> |
|
|
59
|
+
export declare type Checker<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = DataChecker<ED, T, Cxt> | RowChecker<ED, T, Cxt> | RelationChecker<ED, T, Cxt> | LogicalChecker<ED, T, Cxt> | LogicalRelationChecker<ED, T, Cxt>;
|
|
60
|
+
export declare type AuthDef<ED extends EntityDict, T extends keyof ED> = {
|
|
61
|
+
relationAuth?: CascadeRelationAuth<NonNullable<ED[T]['Relation']>>;
|
|
62
|
+
actionAuth?: CascadeActionAuth<ED[T]['Action']>;
|
|
63
|
+
};
|
|
64
|
+
export declare type AuthDefDict<ED extends EntityDict> = {
|
|
65
|
+
[K in keyof ED]?: AuthDef<ED, K>;
|
|
66
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { IncomingHttpHeaders, IncomingMessage } from "http";
|
|
3
|
+
import { AsyncContext } from "../store/AsyncRowStore";
|
|
4
|
+
import { EntityDict } from "./Entity";
|
|
5
|
+
export interface Endpoint<ED extends EntityDict, BackCxt extends AsyncContext<ED>> {
|
|
6
|
+
name: string;
|
|
7
|
+
params?: string[];
|
|
8
|
+
method: 'get' | 'post' | 'put' | 'delete';
|
|
9
|
+
fn: (context: BackCxt, params: Record<string, string>, headers: IncomingHttpHeaders, req: IncomingMessage, body?: any) => Promise<any>;
|
|
10
|
+
}
|
package/lib/types/Entity.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { GenericAction } from '../actions/action';
|
|
2
|
-
import { ExprOp, MakeFilter, NodeId } from './Demand';
|
|
3
|
-
import { OneOf } from './Polyfill';
|
|
4
1
|
import { PrimaryKey, Sequence } from './DataType';
|
|
5
2
|
declare type TriggerDataAttributeType = '$$triggerData$$';
|
|
6
3
|
declare type TriggerTimestampAttributeType = '$$triggerTimestamp$$';
|
|
@@ -18,7 +15,7 @@ export declare const DeleteAtAttribute = "$$deleteAt$$";
|
|
|
18
15
|
export declare const SeqAttribute = "$$seq$$";
|
|
19
16
|
export declare type InstinctiveAttributes = PrimaryKeyAttributeType | CreateAtAttributeType | UpdateAtAttributeType | DeleteAtAttributeType | TriggerDataAttributeType | TriggerTimestampAttributeType | SeqAttributeType;
|
|
20
17
|
export declare const initinctiveAttributes: string[];
|
|
21
|
-
|
|
18
|
+
declare type FilterPart<A extends string, F extends Object | undefined> = {
|
|
22
19
|
filter?: A extends 'create' ? undefined : F;
|
|
23
20
|
indexFrom?: A extends 'create' ? undefined : number;
|
|
24
21
|
count?: A extends 'create' ? undefined : number;
|
|
@@ -44,16 +41,15 @@ export declare type OperateOption = {
|
|
|
44
41
|
export declare type FormUpdateData<SH extends GeneralEntityShape> = Partial<{
|
|
45
42
|
[K in keyof Omit<SH, InstinctiveAttributes>]: SH[K] | null;
|
|
46
43
|
}>;
|
|
47
|
-
export declare type FormCreateData<SH extends GeneralEntityShape> = Omit<SH, InstinctiveAttributes
|
|
44
|
+
export declare type FormCreateData<SH extends GeneralEntityShape> = Partial<Omit<SH, InstinctiveAttributes>> & {
|
|
48
45
|
id: string;
|
|
49
46
|
};
|
|
50
|
-
export declare type Operation<A extends
|
|
47
|
+
export declare type Operation<A extends string, D extends Projection, F extends Filter | undefined = undefined, S extends Sorter | undefined = undefined> = {
|
|
51
48
|
id?: string;
|
|
52
49
|
action: A;
|
|
53
|
-
data:
|
|
54
|
-
sorter?:
|
|
55
|
-
} &
|
|
56
|
-
export declare type Selection<DATA extends Object, FILTER extends Object | undefined = undefined, SORT extends Object | undefined = undefined> = Operation<'select', DATA, FILTER, SORT>;
|
|
50
|
+
data: D;
|
|
51
|
+
sorter?: S;
|
|
52
|
+
} & FilterPart<A, F>;
|
|
57
53
|
export interface EntityShape {
|
|
58
54
|
id: PrimaryKey;
|
|
59
55
|
$$seq$$: Sequence;
|
|
@@ -61,8 +57,6 @@ export interface EntityShape {
|
|
|
61
57
|
$$updateAt$$: number | Date;
|
|
62
58
|
$$deleteAt$$?: number | Date | null;
|
|
63
59
|
}
|
|
64
|
-
export interface FileCarrierEntityShape extends EntityShape {
|
|
65
|
-
}
|
|
66
60
|
interface GeneralEntityShape extends EntityShape {
|
|
67
61
|
[K: string]: any;
|
|
68
62
|
}
|
|
@@ -72,28 +66,24 @@ export interface EntityDef {
|
|
|
72
66
|
OpSchema: GeneralEntityShape;
|
|
73
67
|
Action: string;
|
|
74
68
|
ParticularAction?: string;
|
|
75
|
-
Selection: Omit<
|
|
76
|
-
Aggregation: Omit<DeduceAggregation<
|
|
77
|
-
Operation:
|
|
78
|
-
Create:
|
|
79
|
-
CreateSingle:
|
|
80
|
-
CreateMulti:
|
|
81
|
-
Update:
|
|
82
|
-
Remove:
|
|
69
|
+
Selection: Omit<Operation<'select', Projection, Filter, Sorter>, 'action'>;
|
|
70
|
+
Aggregation: Omit<DeduceAggregation<Projection, Filter, Sorter>, 'action'>;
|
|
71
|
+
Operation: CUDOperation;
|
|
72
|
+
Create: CreateOperation;
|
|
73
|
+
CreateSingle: CreateSingleOperation;
|
|
74
|
+
CreateMulti: CreateMultipleOperation;
|
|
75
|
+
Update: UpdateOperation;
|
|
76
|
+
Remove: RemoveOperation;
|
|
77
|
+
Relation?: string;
|
|
83
78
|
}
|
|
84
79
|
export interface EntityDict {
|
|
85
80
|
[E: string]: EntityDef;
|
|
86
81
|
}
|
|
87
|
-
export interface OtmSubProjection extends Omit<
|
|
82
|
+
export interface OtmSubProjection extends Omit<Operation<'select', any, any, any>, 'action'> {
|
|
88
83
|
$entity: string;
|
|
89
84
|
}
|
|
90
|
-
declare type DeduceProjection<SH extends GeneralEntityShape> = {
|
|
91
|
-
'#id'?: NodeId;
|
|
92
|
-
} & {
|
|
93
|
-
[K in keyof SH]?: number | OtmSubProjection | any;
|
|
94
|
-
} & Partial<ExprOp<keyof SH | string>>;
|
|
95
85
|
export declare type AggregationOp = `#max-${number}` | `#min-${number}` | `#avg-${number}` | `#count-${number}` | `#sum-${number}`;
|
|
96
|
-
export declare type DeduceAggregationData<
|
|
86
|
+
export declare type DeduceAggregationData<P extends Projection> = {
|
|
97
87
|
[A in AggregationOp]?: P;
|
|
98
88
|
} & {
|
|
99
89
|
'#aggr'?: P;
|
|
@@ -104,36 +94,40 @@ export declare type AggregationResult<SH extends GeneralEntityShape> = Array<{
|
|
|
104
94
|
'#data'?: Partial<SH>;
|
|
105
95
|
}>;
|
|
106
96
|
export declare type AttrFilter<SH extends GeneralEntityShape> = {
|
|
107
|
-
[K in keyof SH]
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
$attr: DeduceSorterAttr<SH>;
|
|
97
|
+
[K in keyof SH]?: any;
|
|
98
|
+
};
|
|
99
|
+
declare type SortAttr = {
|
|
100
|
+
[K: string]: any;
|
|
101
|
+
};
|
|
102
|
+
declare type SorterItem = {
|
|
103
|
+
$attr: SortAttr;
|
|
115
104
|
$direction?: "asc" | "desc";
|
|
116
105
|
};
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
106
|
+
declare type Sorter = Array<SorterItem>;
|
|
107
|
+
declare type Filter = {
|
|
108
|
+
[K: string]: any;
|
|
109
|
+
};
|
|
110
|
+
declare type Projection = {
|
|
111
|
+
[K: string]: any;
|
|
112
|
+
};
|
|
113
|
+
export declare type DeduceAggregation<P extends Projection, F extends Filter, S extends Sorter> = Omit<Operation<'aggregate', DeduceAggregationData<P>, F, S>, 'action'>;
|
|
114
|
+
declare type CreateOperationData = {
|
|
121
115
|
id: string;
|
|
122
|
-
|
|
123
|
-
[k in keyof Omit<SH, InstinctiveAttributes>]?: any;
|
|
116
|
+
[K: string]: any;
|
|
124
117
|
};
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
118
|
+
declare type CreateSingleOperation = Operation<'create', CreateOperationData, undefined, undefined>;
|
|
119
|
+
declare type CreateMultipleOperation = Operation<'create', Array<CreateOperationData>, undefined, undefined>;
|
|
120
|
+
declare type CreateOperation = CreateSingleOperation | CreateMultipleOperation;
|
|
121
|
+
declare type UpdateOperationData = {
|
|
122
|
+
id?: never;
|
|
123
|
+
[k: string]: any;
|
|
130
124
|
};
|
|
131
|
-
export declare type
|
|
132
|
-
|
|
133
|
-
[
|
|
125
|
+
export declare type UpdateOperation = Operation<string, UpdateOperationData, Filter, Sorter>;
|
|
126
|
+
declare type RemoveOperationData = {
|
|
127
|
+
[k: string]: any;
|
|
134
128
|
};
|
|
135
|
-
export declare type
|
|
136
|
-
export declare type
|
|
129
|
+
export declare type RemoveOperation = Operation<'remove', RemoveOperationData, Filter, Sorter>;
|
|
130
|
+
export declare type CUDOperation = CreateOperation | UpdateOperation | RemoveOperation;
|
|
137
131
|
export declare type CreateOpResult<ED extends EntityDict, T extends keyof ED> = {
|
|
138
132
|
a: 'c';
|
|
139
133
|
e: T;
|
|
@@ -142,17 +136,24 @@ export declare type CreateOpResult<ED extends EntityDict, T extends keyof ED> =
|
|
|
142
136
|
export declare type UpdateOpResult<ED extends EntityDict, T extends keyof ED> = {
|
|
143
137
|
a: 'u';
|
|
144
138
|
e: T;
|
|
145
|
-
d:
|
|
146
|
-
f?:
|
|
139
|
+
d: UpdateOperationData;
|
|
140
|
+
f?: Filter;
|
|
147
141
|
};
|
|
148
142
|
export declare type RemoveOpResult<ED extends EntityDict, T extends keyof ED> = {
|
|
149
143
|
a: 'r';
|
|
150
144
|
e: T;
|
|
151
|
-
f?:
|
|
145
|
+
f?: Filter;
|
|
152
146
|
};
|
|
153
147
|
export declare type RelationHierarchy<R extends string> = {
|
|
154
148
|
[K in R]?: R[];
|
|
155
149
|
};
|
|
150
|
+
export declare type CascadeRelationItem = {
|
|
151
|
+
cascadePath: string;
|
|
152
|
+
relations?: string[];
|
|
153
|
+
};
|
|
154
|
+
export declare type CascadeRelationAuth<R extends string> = {
|
|
155
|
+
[K in R]?: CascadeRelationItem | (CascadeRelationItem | CascadeRelationItem[])[];
|
|
156
|
+
};
|
|
156
157
|
export declare type SelectOpResult<ED extends EntityDict> = {
|
|
157
158
|
a: 's';
|
|
158
159
|
d: {
|
|
@@ -172,19 +173,4 @@ export declare type Configuration = {
|
|
|
172
173
|
actionType?: ActionType;
|
|
173
174
|
static?: boolean;
|
|
174
175
|
};
|
|
175
|
-
export declare type Exportation<ED extends EntityDict, T extends keyof ED, K extends string> = {
|
|
176
|
-
name: string;
|
|
177
|
-
id: string;
|
|
178
|
-
entity: T;
|
|
179
|
-
projection: ED[T]['Selection']['data'];
|
|
180
|
-
headers: K[];
|
|
181
|
-
fn: (data: ED[T]['Schema']) => Partial<Record<K, string | number | boolean | null>>;
|
|
182
|
-
};
|
|
183
|
-
export declare type Importation<ED extends EntityDict, T extends keyof ED, K extends string> = {
|
|
184
|
-
name: string;
|
|
185
|
-
id: string;
|
|
186
|
-
entity: T;
|
|
187
|
-
headers: K[];
|
|
188
|
-
fn: (data: Partial<Record<K, string | number | boolean>>) => ED[T]['CreateSingle']['data'];
|
|
189
|
-
};
|
|
190
176
|
export {};
|
package/lib/types/Entity.js
CHANGED
package/lib/types/Exception.d.ts
CHANGED
|
@@ -5,6 +5,11 @@ export declare class OakException extends Error {
|
|
|
5
5
|
}
|
|
6
6
|
export declare class OakDataException extends OakException {
|
|
7
7
|
}
|
|
8
|
+
export declare class OakImportDataParseException extends OakException {
|
|
9
|
+
line: number;
|
|
10
|
+
header?: string;
|
|
11
|
+
constructor(message: string, line: number, header?: string);
|
|
12
|
+
}
|
|
8
13
|
export declare class OakOperExistedException extends OakDataException {
|
|
9
14
|
}
|
|
10
15
|
export declare class OakRowUnexistedException extends OakDataException {
|
package/lib/types/Exception.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeException = exports.OakDeadlock = exports.OakCongruentRowExists = exports.OakRowLockedException = exports.OakUnloggedInException = exports.OakUserUnpermittedException = exports.OakInputIllegalException = exports.OakRowInconsistencyException = exports.OakUserException = exports.OakExternalException = exports.OakRowUnexistedException = exports.OakOperExistedException = exports.OakDataException = exports.OakException = void 0;
|
|
3
|
+
exports.makeException = exports.OakDeadlock = exports.OakCongruentRowExists = exports.OakRowLockedException = exports.OakUnloggedInException = exports.OakUserUnpermittedException = exports.OakInputIllegalException = exports.OakRowInconsistencyException = exports.OakUserException = exports.OakExternalException = exports.OakRowUnexistedException = exports.OakOperExistedException = exports.OakImportDataParseException = exports.OakDataException = exports.OakException = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var OakException = /** @class */ (function (_super) {
|
|
6
6
|
tslib_1.__extends(OakException, _super);
|
|
@@ -36,6 +36,18 @@ var OakDataException = /** @class */ (function (_super) {
|
|
|
36
36
|
return OakDataException;
|
|
37
37
|
}(OakException));
|
|
38
38
|
exports.OakDataException = OakDataException;
|
|
39
|
+
var OakImportDataParseException = /** @class */ (function (_super) {
|
|
40
|
+
tslib_1.__extends(OakImportDataParseException, _super);
|
|
41
|
+
// message必传,描述具体错误的数据内容
|
|
42
|
+
function OakImportDataParseException(message, line, header) {
|
|
43
|
+
var _this = _super.call(this, message) || this;
|
|
44
|
+
_this.line = line;
|
|
45
|
+
_this.header = header;
|
|
46
|
+
return _this;
|
|
47
|
+
}
|
|
48
|
+
return OakImportDataParseException;
|
|
49
|
+
}(OakException));
|
|
50
|
+
exports.OakImportDataParseException = OakImportDataParseException;
|
|
39
51
|
var OakOperExistedException = /** @class */ (function (_super) {
|
|
40
52
|
tslib_1.__extends(OakOperExistedException, _super);
|
|
41
53
|
function OakOperExistedException() {
|
|
@@ -245,6 +257,9 @@ function makeException(data) {
|
|
|
245
257
|
case 'OakDeadlock': {
|
|
246
258
|
return new OakDeadlock(data.message);
|
|
247
259
|
}
|
|
260
|
+
case 'OakImportDataParseException': {
|
|
261
|
+
return new OakImportDataParseException(data.message, data.line, data.header);
|
|
262
|
+
}
|
|
248
263
|
default:
|
|
249
264
|
return;
|
|
250
265
|
}
|
|
@@ -4,7 +4,7 @@ export declare type RefOrExpression<A> = RefAttr<A> | Expression<A>;
|
|
|
4
4
|
declare type MathType<A> = RefOrExpression<A> | number;
|
|
5
5
|
declare type StringType<A> = RefOrExpression<A> | string;
|
|
6
6
|
interface Add<A> {
|
|
7
|
-
$add: (MathType<A>
|
|
7
|
+
$add: (MathType<A>)[];
|
|
8
8
|
}
|
|
9
9
|
interface Subtract<A> {
|
|
10
10
|
$subtract: [MathType<A>, MathType<A>];
|
|
@@ -111,6 +111,10 @@ interface DateFloor<A> {
|
|
|
111
111
|
$dateFloor: [RefOrExpression<A> | Date | number, 'y' | 'M' | 'd' | 'h' | 'm' | 's'];
|
|
112
112
|
}
|
|
113
113
|
declare type DateExpression<A> = DateYear<A> | DateMonth<A> | DateWeekday<A> | DateWeekOfYear<A> | DateDay<A> | DateDayOfYear<A> | DateDayOfMonth<A> | DateDayOfWeek<A> | DateDiff<A> | DateCeiling<A> | DateFloor<A>;
|
|
114
|
+
interface StringConcat<A> {
|
|
115
|
+
$concat: StringType<A>[];
|
|
116
|
+
}
|
|
117
|
+
declare type StringExpression<A> = StringConcat<A>;
|
|
114
118
|
interface GeoContains<A> {
|
|
115
119
|
$contains: [RefOrExpression<A> | Geo, RefOrExpression<A> | Geo];
|
|
116
120
|
}
|
|
@@ -118,7 +122,23 @@ interface GeoDistance<A> {
|
|
|
118
122
|
$distance: [RefOrExpression<A> | Geo, RefOrExpression<A> | Geo];
|
|
119
123
|
}
|
|
120
124
|
declare type GeoExpression<A> = GeoContains<A> | GeoDistance<A>;
|
|
121
|
-
|
|
125
|
+
interface AggrCountExpression<A> {
|
|
126
|
+
$$count: RefOrExpression<A>;
|
|
127
|
+
}
|
|
128
|
+
interface AggrSumExpression<A> {
|
|
129
|
+
$$sum: RefOrExpression<A>;
|
|
130
|
+
}
|
|
131
|
+
interface AggrMaxExpression<A> {
|
|
132
|
+
$$max: RefOrExpression<A>;
|
|
133
|
+
}
|
|
134
|
+
interface AggrMinExpression<A> {
|
|
135
|
+
$$min: RefOrExpression<A>;
|
|
136
|
+
}
|
|
137
|
+
interface AggrAvgExpression<A> {
|
|
138
|
+
$$avg: RefOrExpression<A>;
|
|
139
|
+
}
|
|
140
|
+
export declare type AggrExpression<A> = AggrAvgExpression<A> | AggrCountExpression<A> | AggrSumExpression<A> | AggrMaxExpression<A> | AggrMinExpression<A>;
|
|
141
|
+
export declare type Expression<A> = GeoExpression<A> | DateExpression<A> | LogicExpression<A> | BoolExpression<A> | CompareExpression<A> | MathExpression<A> | StringExpression<A> | AggrExpression<A>;
|
|
122
142
|
export declare type ExpressionConstant = Geo | number | Date | string | boolean;
|
|
123
143
|
export declare function isGeoExpression<A>(expression: any): expression is GeoExpression<A>;
|
|
124
144
|
export declare function isDateExpression<A>(expression: any): expression is DateExpression<A>;
|
|
@@ -126,6 +146,8 @@ export declare function isLogicExpression<A>(expression: any): expression is Log
|
|
|
126
146
|
export declare function isBoolExpression<A>(expression: any): expression is BoolExpression<A>;
|
|
127
147
|
export declare function isCompareExpression<A>(expression: any): expression is CompareExpression<A>;
|
|
128
148
|
export declare function isMathExpression<A>(expression: any): expression is MathExpression<A>;
|
|
149
|
+
export declare function isStringExpression<A>(expression: any): expression is StringExpression<A>;
|
|
150
|
+
export declare function isAggrExpression<A>(expression: any): expression is AggrExpression<A>;
|
|
129
151
|
export declare function isExpression<A>(expression: any): expression is Expression<A>;
|
|
130
152
|
export declare function opMultipleParams(op: string): boolean;
|
|
131
153
|
export declare function execOp(op: string, params: any, obscure?: boolean): ExpressionConstant;
|
package/lib/types/Expression.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAttrRefInExpression = exports.execOp = exports.opMultipleParams = exports.isExpression = exports.isMathExpression = exports.isCompareExpression = exports.isBoolExpression = exports.isLogicExpression = exports.isDateExpression = exports.isGeoExpression = void 0;
|
|
3
|
+
exports.getAttrRefInExpression = exports.execOp = exports.opMultipleParams = exports.isExpression = exports.isAggrExpression = exports.isStringExpression = exports.isMathExpression = exports.isCompareExpression = exports.isBoolExpression = exports.isLogicExpression = exports.isDateExpression = exports.isGeoExpression = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var assert_1 = tslib_1.__importDefault(require("assert"));
|
|
6
6
|
var dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
|
@@ -42,6 +42,7 @@ dayjs_1.default.extend(dayOfYear_1.default);
|
|
|
42
42
|
;
|
|
43
43
|
;
|
|
44
44
|
;
|
|
45
|
+
;
|
|
45
46
|
function isGeoExpression(expression) {
|
|
46
47
|
if (Object.keys(expression).length == 1) {
|
|
47
48
|
var op = Object.keys(expression)[0];
|
|
@@ -105,13 +106,34 @@ function isMathExpression(expression) {
|
|
|
105
106
|
return false;
|
|
106
107
|
}
|
|
107
108
|
exports.isMathExpression = isMathExpression;
|
|
109
|
+
function isStringExpression(expression) {
|
|
110
|
+
if (Object.keys(expression).length == 1) {
|
|
111
|
+
var op = Object.keys(expression)[0];
|
|
112
|
+
if (['$concat'].includes(op)) {
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
exports.isStringExpression = isStringExpression;
|
|
119
|
+
function isAggrExpression(expression) {
|
|
120
|
+
if (Object.keys(expression).length == 1) {
|
|
121
|
+
var op = Object.keys(expression)[0];
|
|
122
|
+
if (['$$max', '$$min', '$$sum', '$$avg', '$$count'].includes(op)) {
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
exports.isAggrExpression = isAggrExpression;
|
|
108
129
|
function isExpression(expression) {
|
|
109
130
|
return typeof expression === 'object' && Object.keys(expression).length === 1 && Object.keys(expression)[0].startsWith('$');
|
|
110
131
|
}
|
|
111
132
|
exports.isExpression = isExpression;
|
|
112
133
|
function opMultipleParams(op) {
|
|
113
134
|
return !['$year', '$month', '$weekday', '$weekOfYear', '$day', '$dayOfMonth',
|
|
114
|
-
'$dayOfWeek', '$dayOfYear', '$not', '$true', '$false', '$abs',
|
|
135
|
+
'$dayOfWeek', '$dayOfYear', '$not', '$true', '$false', '$abs',
|
|
136
|
+
'$round', '$floor', '$ceil', '$$max', '$$min', '$$sum', '$$avg', '$$count'].includes(op);
|
|
115
137
|
}
|
|
116
138
|
exports.opMultipleParams = opMultipleParams;
|
|
117
139
|
function execOp(op, params, obscure) {
|
|
@@ -341,6 +363,9 @@ function execOp(op, params, obscure) {
|
|
|
341
363
|
case '$contains': {
|
|
342
364
|
throw new Error('$contains类型未实现');
|
|
343
365
|
}
|
|
366
|
+
case '$concat': {
|
|
367
|
+
return params.join('');
|
|
368
|
+
}
|
|
344
369
|
default: {
|
|
345
370
|
(0, assert_1.default)(false, "\u4E0D\u80FD\u8BC6\u522B\u7684expression\u8FD0\u7B97\u7B26\uFF1A".concat(op));
|
|
346
371
|
}
|