oak-domain 1.1.13 → 2.0.1
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/Modi/Schema.d.ts +29 -32
- package/lib/base-app-domain/ModiEntity/Schema.d.ts +24 -27
- package/lib/base-app-domain/Oper/Schema.d.ts +24 -27
- package/lib/base-app-domain/OperEntity/Schema.d.ts +25 -28
- package/lib/base-app-domain/User/Schema.d.ts +22 -25
- package/lib/checkers/index.d.ts +4 -2
- package/lib/compiler/schemalBuilder.js +22 -24
- package/lib/store/AsyncRowStore.d.ts +45 -0
- package/lib/store/{UniversalContext.js → AsyncRowStore.js} +39 -29
- package/lib/store/CascadeStore.d.ts +46 -20
- package/lib/store/CascadeStore.js +960 -996
- package/lib/store/SyncRowStore.d.ts +26 -0
- package/lib/store/SyncRowStore.js +45 -0
- package/lib/store/TriggerExecutor.d.ts +14 -14
- package/lib/store/TriggerExecutor.js +225 -238
- package/lib/store/actionDef.d.ts +5 -4
- package/lib/store/actionDef.js +44 -133
- package/lib/store/checker.d.ts +6 -0
- package/lib/store/checker.js +165 -0
- package/lib/store/filter.d.ts +5 -0
- package/lib/store/filter.js +395 -3
- package/lib/store/modi.d.ts +7 -6
- package/lib/store/modi.js +35 -46
- package/lib/store/relation.d.ts +1 -1
- package/lib/store/selection.js +1 -0
- package/lib/triggers/index.d.ts +4 -3
- package/lib/triggers/modi.d.ts +2 -2
- package/lib/triggers/modi.js +5 -5
- package/lib/types/AppLoader.d.ts +3 -3
- package/lib/types/Aspect.d.ts +3 -3
- package/lib/types/Auth.d.ts +25 -22
- package/lib/types/Connector.d.ts +7 -7
- package/lib/types/Context.d.ts +4 -14
- package/lib/types/DataType.d.ts +1 -0
- package/lib/types/Entity.d.ts +26 -18
- package/lib/types/Entity.js +9 -2
- package/lib/types/Exception.d.ts +6 -1
- package/lib/types/Exception.js +30 -13
- package/lib/types/RowStore.d.ts +2 -13
- package/lib/types/RowStore.js +1 -6
- package/lib/types/Storage.d.ts +1 -0
- package/lib/types/Trigger.d.ts +32 -48
- package/lib/types/Trigger.js +24 -9
- package/lib/types/Watcher.d.ts +7 -8
- package/lib/types/schema/DataTypes.d.ts +1 -1
- package/lib/utils/SimpleConnector.d.ts +9 -8
- package/lib/utils/SimpleConnector.js +4 -5
- package/lib/utils/random/random.d.ts +1 -0
- package/lib/utils/random/random.js +24 -0
- package/lib/utils/random/random.mp.d.ts +1 -0
- package/lib/utils/random/random.mp.js +25 -0
- package/lib/utils/random/random.web.d.ts +1 -0
- package/lib/utils/random/random.web.js +17 -0
- package/lib/utils/string.d.ts +20 -0
- package/lib/utils/string.js +60 -1
- package/lib/utils/uuid.d.ts +10 -0
- package/lib/utils/uuid.js +172 -1
- package/lib/utils/validator.d.ts +2 -2
- package/lib/utils/validator.js +5 -5
- package/package.json +5 -3
- package/lib/OakError.d.ts +0 -7
- package/lib/OakError.js +0 -15
- package/lib/compiler/utils.d.ts +0 -2
- package/lib/compiler/utils.js +0 -11
- package/lib/entities/Action.d.ts +0 -12
- package/lib/entities/Action.js +0 -17
- package/lib/entities/Ooperation.d.ts +0 -12
- package/lib/entities/Ooperation.js +0 -17
- package/lib/entities/Update.d.ts +0 -9
- package/lib/entities/Update.js +0 -44
- package/lib/entities/Uupdate.d.ts +0 -9
- package/lib/entities/Uupdate.js +0 -44
- package/lib/store/UniversalContext.d.ts +0 -32
- package/lib/store/action.d.ts +0 -6
- package/lib/store/action.js +0 -14
- package/lib/store/projection.d.ts +0 -7
- package/lib/store/projection.js +0 -211
- package/lib/store/watchers.d.ts +0 -2
- package/lib/store/watchers.js +0 -32
package/lib/triggers/modi.js
CHANGED
|
@@ -16,7 +16,7 @@ var triggers = [
|
|
|
16
16
|
switch (_c.label) {
|
|
17
17
|
case 0:
|
|
18
18
|
filter = operation.filter;
|
|
19
|
-
return [4 /*yield*/, context.
|
|
19
|
+
return [4 /*yield*/, context.select('modi', {
|
|
20
20
|
data: {
|
|
21
21
|
id: 1,
|
|
22
22
|
action: 1,
|
|
@@ -25,9 +25,9 @@ var triggers = [
|
|
|
25
25
|
targetEntity: 1,
|
|
26
26
|
},
|
|
27
27
|
filter: filter,
|
|
28
|
-
},
|
|
28
|
+
}, option)];
|
|
29
29
|
case 1:
|
|
30
|
-
modies =
|
|
30
|
+
modies = _c.sent();
|
|
31
31
|
_c.label = 2;
|
|
32
32
|
case 2:
|
|
33
33
|
_c.trys.push([2, 7, 8, 9]);
|
|
@@ -37,12 +37,12 @@ var triggers = [
|
|
|
37
37
|
if (!!modies_1_1.done) return [3 /*break*/, 6];
|
|
38
38
|
modi = modies_1_1.value;
|
|
39
39
|
targetEntity = modi.targetEntity, id = modi.id, action = modi.action, data = modi.data, filter_1 = modi.filter;
|
|
40
|
-
return [4 /*yield*/, context.
|
|
40
|
+
return [4 /*yield*/, context.operate(targetEntity, {
|
|
41
41
|
id: id,
|
|
42
42
|
action: action,
|
|
43
43
|
data: data,
|
|
44
44
|
filter: filter_1,
|
|
45
|
-
},
|
|
45
|
+
}, Object.assign({}, option, {
|
|
46
46
|
blockTrigger: true,
|
|
47
47
|
}))];
|
|
48
48
|
case 4:
|
package/lib/types/AppLoader.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AsyncContext, AsyncRowStore } from "../store/AsyncRowStore";
|
|
2
2
|
import { EntityDict } from "./Entity";
|
|
3
|
-
export declare abstract class AppLoader<ED extends EntityDict, Cxt extends
|
|
3
|
+
export declare abstract class AppLoader<ED extends EntityDict, Cxt extends AsyncContext<ED>> {
|
|
4
4
|
protected path: string;
|
|
5
5
|
constructor(path: string);
|
|
6
6
|
abstract execAspect(name: string, context: Cxt, params?: any): Promise<any>;
|
|
7
7
|
abstract initialize(dropIfExists?: boolean): Promise<void>;
|
|
8
8
|
abstract mount(): Promise<void>;
|
|
9
9
|
abstract unmount(): Promise<void>;
|
|
10
|
-
abstract getStore():
|
|
10
|
+
abstract getStore(): AsyncRowStore<ED, Cxt>;
|
|
11
11
|
}
|
package/lib/types/Aspect.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { EntityDict } from "./Entity";
|
|
2
|
-
import { Context } from './Context';
|
|
3
2
|
import { OpRecord } from "./Entity";
|
|
4
|
-
|
|
3
|
+
import { AsyncContext } from "../store/AsyncRowStore";
|
|
4
|
+
export interface Aspect<ED extends EntityDict, Cxt extends AsyncContext<ED>> {
|
|
5
5
|
(params: any, context: Cxt): Promise<any>;
|
|
6
6
|
}
|
|
7
|
-
export interface AspectWrapper<ED extends EntityDict, Cxt extends
|
|
7
|
+
export interface AspectWrapper<ED extends EntityDict, Cxt extends AsyncContext<ED>, AD extends Record<string, Aspect<ED, Cxt>>> {
|
|
8
8
|
exec: <T extends keyof AD>(name: T, params: Parameters<AD[T]>[0]) => Promise<{
|
|
9
9
|
result: Awaited<ReturnType<AD[T]>>;
|
|
10
10
|
opRecords: OpRecord<ED>[];
|
package/lib/types/Auth.d.ts
CHANGED
|
@@ -1,28 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
export declare type
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { AsyncContext } from "../store/AsyncRowStore";
|
|
2
|
+
import { SyncContext } from "../store/SyncRowStore";
|
|
3
|
+
import { EntityDict, OperateOption, SelectOption } from "../types/Entity";
|
|
4
|
+
export declare type DataChecker<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = {
|
|
5
|
+
priority?: number;
|
|
6
|
+
type: 'data';
|
|
7
7
|
entity: T;
|
|
8
|
-
|
|
8
|
+
action: Omit<ED[T]['Action'], 'remove'>;
|
|
9
|
+
checker: (data: ED[T]['Create']['data'] | ED[T]['Update']['data'], context: Cxt) => void;
|
|
9
10
|
};
|
|
10
|
-
export declare type
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
export declare type RowChecker<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = {
|
|
12
|
+
priority?: number;
|
|
13
|
+
type: 'row';
|
|
13
14
|
entity: T;
|
|
14
|
-
|
|
15
|
+
action: Omit<ED[T]['Action'], 'create'> | Array<Omit<ED[T]['Action'], 'create'>>;
|
|
16
|
+
filter: ED[T]['Selection']['filter'] | ((context: Cxt, option: OperateOption | SelectOption) => ED[T]['Selection']['filter']);
|
|
17
|
+
errMsg?: string;
|
|
18
|
+
inconsistentRows?: {
|
|
19
|
+
entity: keyof ED;
|
|
20
|
+
selection: (filter?: ED[T]['Selection']['filter']) => ED[keyof ED]['Selection'];
|
|
21
|
+
};
|
|
15
22
|
};
|
|
16
|
-
export declare type
|
|
17
|
-
|
|
18
|
-
|
|
23
|
+
export declare type RelationChecker<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = {
|
|
24
|
+
priority?: number;
|
|
25
|
+
type: 'relation';
|
|
19
26
|
entity: T;
|
|
20
|
-
|
|
27
|
+
action: Omit<ED[T]['Action'], 'create'> | Array<Omit<ED[T]['Action'], 'create'>>;
|
|
28
|
+
relationFilter: (context: Cxt, option: OperateOption | SelectOption) => ED[T]['Selection']['filter'];
|
|
29
|
+
errMsg: string;
|
|
21
30
|
};
|
|
22
|
-
export declare type
|
|
23
|
-
type: CheckerType;
|
|
24
|
-
action: 'select';
|
|
25
|
-
entity: T;
|
|
26
|
-
checker: SelectTriggerBefore<ED, T, Cxt>['fn'];
|
|
27
|
-
};
|
|
28
|
-
export declare type Checker<ED extends EntityDict, T extends keyof ED, Cxt extends Context<ED>> = CreateChecker<ED, T, Cxt> | UpdateChecker<ED, T, Cxt> | RemoveChecker<ED, T, Cxt> | SelectChecker<ED, T, Cxt>;
|
|
31
|
+
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>;
|
package/lib/types/Connector.d.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { IncomingHttpHeaders } from "http";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { AsyncContext, AsyncRowStore } from "../store/AsyncRowStore";
|
|
4
|
+
import { SyncContext } from "../store/SyncRowStore";
|
|
5
5
|
import { EntityDict, OpRecord } from "./Entity";
|
|
6
6
|
import { OakException } from "./Exception";
|
|
7
|
-
export declare abstract class Connector<ED extends EntityDict,
|
|
8
|
-
abstract callAspect(name: string, params: any, context:
|
|
7
|
+
export declare abstract class Connector<ED extends EntityDict, BackCxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>> {
|
|
8
|
+
abstract callAspect(name: string, params: any, context: FrontCxt): Promise<{
|
|
9
9
|
result: any;
|
|
10
10
|
opRecords: OpRecord<ED>[];
|
|
11
11
|
}>;
|
|
12
12
|
abstract getRouter(): string;
|
|
13
|
-
abstract parseRequest(headers: IncomingHttpHeaders, body: any, store:
|
|
13
|
+
abstract parseRequest(headers: IncomingHttpHeaders, body: any, store: AsyncRowStore<ED, BackCxt>): Promise<{
|
|
14
14
|
name: string;
|
|
15
15
|
params: any;
|
|
16
|
-
context:
|
|
16
|
+
context: BackCxt;
|
|
17
17
|
}>;
|
|
18
|
-
abstract serializeResult(result: any, context:
|
|
18
|
+
abstract serializeResult(result: any, context: BackCxt, headers: IncomingHttpHeaders, body: any): {
|
|
19
19
|
body: any;
|
|
20
20
|
headers?: Record<string, any>;
|
|
21
21
|
};
|
package/lib/types/Context.d.ts
CHANGED
|
@@ -1,16 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import { RowStore } from './RowStore';
|
|
3
|
-
export interface Context<ED extends EntityDict> {
|
|
4
|
-
opRecords: OpRecord<ED>[];
|
|
5
|
-
rowStore: RowStore<ED, this>;
|
|
6
|
-
begin(options?: object): Promise<void>;
|
|
7
|
-
commit(): Promise<void>;
|
|
8
|
-
rollback(): Promise<void>;
|
|
1
|
+
export interface Context {
|
|
9
2
|
getCurrentTxnId(): string | undefined;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
setScene(scene?: string): void;
|
|
14
|
-
getCurrentUserId(): Promise<string | undefined>;
|
|
15
|
-
getHeader(key: string): string | string[] | undefined;
|
|
3
|
+
getCurrentUserId(allowUnloggedIn?: boolean): string | undefined;
|
|
4
|
+
isRoot(): boolean;
|
|
5
|
+
toString(): string;
|
|
16
6
|
}
|
package/lib/types/DataType.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export declare type Datetime = number | Date;
|
|
|
11
11
|
export declare type Boolean = boolean;
|
|
12
12
|
export declare type PrimaryKey = string;
|
|
13
13
|
export declare type ForeignKey<E extends string> = string;
|
|
14
|
+
export declare type Sequence = string;
|
|
14
15
|
export { Geo, SingleGeo } from './Geo';
|
|
15
16
|
export declare type DataTypes = number | string | Datetime | Geo | Object | SingleGeo;
|
|
16
17
|
export declare const types: string[];
|
package/lib/types/Entity.d.ts
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
import { GenericAction } from '../actions/action';
|
|
2
|
-
import {
|
|
3
|
-
import { OneOf
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
declare type
|
|
7
|
-
|
|
2
|
+
import { ExprOp, MakeFilter, NodeId } from './Demand';
|
|
3
|
+
import { OneOf } from './Polyfill';
|
|
4
|
+
import { PrimaryKey, Sequence } from './DataType';
|
|
5
|
+
declare type TriggerDataAttributeType = '$$triggerData$$';
|
|
6
|
+
declare type TriggerTimestampAttributeType = '$$triggerTimestamp$$';
|
|
7
|
+
declare type PrimaryKeyAttributeType = 'id';
|
|
8
|
+
declare type CreateAtAttributeType = '$$createAt$$';
|
|
9
|
+
declare type UpdateAtAttributeType = '$$updateAt$$';
|
|
10
|
+
declare type DeleteAtAttributeType = '$$deleteAt$$';
|
|
11
|
+
declare type SeqAttributeType = '$$seq$$';
|
|
12
|
+
export declare const TriggerDataAttribute = "$$triggerData$$";
|
|
13
|
+
export declare const TriggerTimestampAttribute = "$$triggerTimestamp$$";
|
|
14
|
+
export declare const PrimaryKeyAttribute = "id";
|
|
15
|
+
export declare const CreateAtAttribute = "$$createAt$$";
|
|
16
|
+
export declare const UpdateAtAttribute = "$$updateAt$$";
|
|
17
|
+
export declare const DeleteAtAttribute = "$$deleteAt$$";
|
|
18
|
+
export declare const SeqAttribute = "$$seq$$";
|
|
19
|
+
export declare type InstinctiveAttributes = PrimaryKeyAttributeType | CreateAtAttributeType | UpdateAtAttributeType | DeleteAtAttributeType | TriggerDataAttributeType | TriggerTimestampAttributeType | SeqAttributeType;
|
|
8
20
|
export declare const initinctiveAttributes: string[];
|
|
9
21
|
export declare type Filter<A extends string, F extends Object | undefined = undefined> = {
|
|
10
22
|
filter?: A extends 'create' ? undefined : F;
|
|
@@ -23,6 +35,7 @@ export declare type OperateOption = {
|
|
|
23
35
|
blockTrigger?: true;
|
|
24
36
|
dontCollect?: boolean;
|
|
25
37
|
dontCreateOper?: boolean;
|
|
38
|
+
dontCreateModi?: boolean;
|
|
26
39
|
allowExists?: boolean;
|
|
27
40
|
modiParentId?: string;
|
|
28
41
|
modiParentEntity?: string;
|
|
@@ -35,14 +48,15 @@ export declare type FormCreateData<SH extends GeneralEntityShape> = Omit<SH, Ins
|
|
|
35
48
|
id: string;
|
|
36
49
|
};
|
|
37
50
|
export declare type Operation<A extends GenericAction | string, DATA extends Object, FILTER extends Object | undefined = undefined, SORTER extends Object | undefined = undefined> = {
|
|
38
|
-
id
|
|
51
|
+
id?: string;
|
|
39
52
|
action: A;
|
|
40
53
|
data: DATA;
|
|
41
54
|
sorter?: SORTER;
|
|
42
55
|
} & Filter<A, FILTER>;
|
|
43
|
-
export declare type Selection<DATA extends Object, FILTER extends Object | undefined = undefined, SORT extends Object | undefined = undefined> =
|
|
56
|
+
export declare type Selection<DATA extends Object, FILTER extends Object | undefined = undefined, SORT extends Object | undefined = undefined> = Operation<'select', DATA, FILTER, SORT>;
|
|
44
57
|
export interface EntityShape {
|
|
45
|
-
id:
|
|
58
|
+
id: PrimaryKey;
|
|
59
|
+
$$seq$$: Sequence;
|
|
46
60
|
$$createAt$$: number | Date;
|
|
47
61
|
$$updateAt$$: number | Date;
|
|
48
62
|
$$deleteAt$$?: number | Date | null;
|
|
@@ -75,14 +89,14 @@ export interface OtmSubProjection extends Omit<DeduceSelection<any>, 'action'> {
|
|
|
75
89
|
declare type DeduceProjection<SH extends GeneralEntityShape> = {
|
|
76
90
|
'#id'?: NodeId;
|
|
77
91
|
} & {
|
|
78
|
-
[K in keyof SH]?:
|
|
92
|
+
[K in keyof SH]?: number | OtmSubProjection | any;
|
|
79
93
|
} & Partial<ExprOp<keyof SH>>;
|
|
80
94
|
export declare type AttrFilter<SH extends GeneralEntityShape> = {
|
|
81
95
|
[K in keyof SH]: any;
|
|
82
96
|
};
|
|
83
97
|
export declare type DeduceFilter<SH extends GeneralEntityShape> = MakeFilter<AttrFilter<SH> & ExprOp<keyof SH>>;
|
|
84
98
|
export declare type DeduceSorterAttr<SH extends GeneralEntityShape> = OneOf<{
|
|
85
|
-
[K: string]:
|
|
99
|
+
[K: string]: number | object | undefined;
|
|
86
100
|
} & ExprOp<keyof SH>>;
|
|
87
101
|
export declare type DeduceSorterItem<SH extends GeneralEntityShape> = {
|
|
88
102
|
$attr: DeduceSorterAttr<SH>;
|
|
@@ -106,7 +120,7 @@ export declare type DeduceRemoveOperationData<SH extends GeneralEntityShape> = {
|
|
|
106
120
|
[A in keyof Omit<SH, InstinctiveAttributes>]?: any;
|
|
107
121
|
};
|
|
108
122
|
export declare type DeduceRemoveOperation<SH extends GeneralEntityShape> = Operation<'remove', DeduceRemoveOperationData<SH>, DeduceFilter<SH>, DeduceSorter<SH>>;
|
|
109
|
-
export declare type DeduceOperation<SH extends GeneralEntityShape> = DeduceCreateOperation<SH> | DeduceUpdateOperation<SH> | DeduceRemoveOperation<SH
|
|
123
|
+
export declare type DeduceOperation<SH extends GeneralEntityShape> = DeduceCreateOperation<SH> | DeduceUpdateOperation<SH> | DeduceRemoveOperation<SH>;
|
|
110
124
|
export declare type CreateOpResult<ED extends EntityDict, T extends keyof ED> = {
|
|
111
125
|
a: 'c';
|
|
112
126
|
e: T;
|
|
@@ -137,12 +151,6 @@ export declare type OperationResult<ED extends EntityDict> = {
|
|
|
137
151
|
[A in ED[K]['Action']]?: number;
|
|
138
152
|
};
|
|
139
153
|
};
|
|
140
|
-
export declare type SelectRowShape<E extends GeneralEntityShape, P extends DeduceProjection<GeneralEntityShape>> = {
|
|
141
|
-
[K in keyof P]: K extends ExpressionKey ? any : (K extends keyof E ? (P[K] extends 1 | undefined ? E[K] : (P[K] extends OtmSubProjection ? SelectRowShape<Required<E>[K][0], P[K]['data']>[] | Array<never> : (K extends OptionalKeys<E> ? SelectRowShape<NonNullable<Required<E>[K]>, P[K]> | null : SelectRowShape<NonNullable<Required<E>[K]>, P[K]>))) : never);
|
|
142
|
-
};
|
|
143
|
-
export declare type SelectionResult<E extends GeneralEntityShape, P extends DeduceProjection<GeneralEntityShape>> = {
|
|
144
|
-
result: Array<SelectRowShape<E, P>>;
|
|
145
|
-
};
|
|
146
154
|
export declare type ActionType = 'readOnly' | 'appendOnly' | 'excludeUpdate' | 'excludeRemove' | 'crud';
|
|
147
155
|
export declare type Configuration = {
|
|
148
156
|
actionType?: ActionType;
|
package/lib/types/Entity.js
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.initinctiveAttributes = void 0;
|
|
4
|
-
exports.
|
|
3
|
+
exports.initinctiveAttributes = exports.SeqAttribute = exports.DeleteAtAttribute = exports.UpdateAtAttribute = exports.CreateAtAttribute = exports.PrimaryKeyAttribute = exports.TriggerTimestampAttribute = exports.TriggerDataAttribute = void 0;
|
|
4
|
+
exports.TriggerDataAttribute = '$$triggerData$$';
|
|
5
|
+
exports.TriggerTimestampAttribute = '$$triggerTimestamp$$';
|
|
6
|
+
exports.PrimaryKeyAttribute = 'id';
|
|
7
|
+
exports.CreateAtAttribute = '$$createAt$$';
|
|
8
|
+
exports.UpdateAtAttribute = '$$updateAt$$';
|
|
9
|
+
exports.DeleteAtAttribute = '$$deleteAt$$';
|
|
10
|
+
exports.SeqAttribute = '$$seq$$';
|
|
11
|
+
exports.initinctiveAttributes = [exports.PrimaryKeyAttribute, exports.TriggerDataAttribute, exports.TriggerTimestampAttribute, exports.CreateAtAttribute, exports.UpdateAtAttribute, exports.DeleteAtAttribute, exports.SeqAttribute];
|
|
5
12
|
;
|
|
6
13
|
;
|
|
7
14
|
;
|
package/lib/types/Exception.d.ts
CHANGED
|
@@ -38,7 +38,9 @@ export declare class OakRowInconsistencyException<ED extends EntityDict> extends
|
|
|
38
38
|
*/
|
|
39
39
|
export declare class OakInputIllegalException extends OakUserException {
|
|
40
40
|
private attributes;
|
|
41
|
-
|
|
41
|
+
private entity;
|
|
42
|
+
constructor(entity: string, attributes: string[], message?: string);
|
|
43
|
+
getEntity(): string;
|
|
42
44
|
getAttributes(): string[];
|
|
43
45
|
addAttributesPrefix(prefix: string): void;
|
|
44
46
|
toString(): string;
|
|
@@ -71,6 +73,9 @@ export declare class OakCongruentRowExists<ED extends EntityDict, T extends keyo
|
|
|
71
73
|
getEntity(): T;
|
|
72
74
|
toString(): string;
|
|
73
75
|
}
|
|
76
|
+
export declare class OakDeadlock extends OakUserException {
|
|
77
|
+
constructor(message?: string | undefined);
|
|
78
|
+
}
|
|
74
79
|
export declare function makeException(data: {
|
|
75
80
|
name: string;
|
|
76
81
|
message?: string;
|
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.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.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);
|
|
@@ -109,11 +109,15 @@ exports.OakRowInconsistencyException = OakRowInconsistencyException;
|
|
|
109
109
|
*/
|
|
110
110
|
var OakInputIllegalException = /** @class */ (function (_super) {
|
|
111
111
|
tslib_1.__extends(OakInputIllegalException, _super);
|
|
112
|
-
function OakInputIllegalException(attributes, message) {
|
|
112
|
+
function OakInputIllegalException(entity, attributes, message) {
|
|
113
113
|
var _this = _super.call(this, message) || this;
|
|
114
|
+
_this.entity = entity;
|
|
114
115
|
_this.attributes = attributes;
|
|
115
116
|
return _this;
|
|
116
117
|
}
|
|
118
|
+
OakInputIllegalException.prototype.getEntity = function () {
|
|
119
|
+
return this.entity;
|
|
120
|
+
};
|
|
117
121
|
OakInputIllegalException.prototype.getAttributes = function () {
|
|
118
122
|
return this.attributes;
|
|
119
123
|
};
|
|
@@ -122,6 +126,7 @@ var OakInputIllegalException = /** @class */ (function (_super) {
|
|
|
122
126
|
};
|
|
123
127
|
OakInputIllegalException.prototype.toString = function () {
|
|
124
128
|
return JSON.stringify({
|
|
129
|
+
entity: this.entity,
|
|
125
130
|
name: this.constructor.name,
|
|
126
131
|
message: this.message,
|
|
127
132
|
attributes: this.attributes,
|
|
@@ -195,39 +200,51 @@ var OakCongruentRowExists = /** @class */ (function (_super) {
|
|
|
195
200
|
return OakCongruentRowExists;
|
|
196
201
|
}(OakUserException));
|
|
197
202
|
exports.OakCongruentRowExists = OakCongruentRowExists;
|
|
203
|
+
var OakDeadlock = /** @class */ (function (_super) {
|
|
204
|
+
tslib_1.__extends(OakDeadlock, _super);
|
|
205
|
+
function OakDeadlock(message) {
|
|
206
|
+
return _super.call(this, message || '发现死锁') || this;
|
|
207
|
+
}
|
|
208
|
+
return OakDeadlock;
|
|
209
|
+
}(OakUserException));
|
|
210
|
+
exports.OakDeadlock = OakDeadlock;
|
|
211
|
+
;
|
|
198
212
|
function makeException(data) {
|
|
199
213
|
var name = data.name;
|
|
200
214
|
switch (name) {
|
|
201
|
-
case OakException
|
|
215
|
+
case 'OakException': {
|
|
202
216
|
return new OakException(data.message);
|
|
203
217
|
}
|
|
204
|
-
case OakUserException
|
|
218
|
+
case 'OakUserException': {
|
|
205
219
|
return new OakUserException(data.message);
|
|
206
220
|
}
|
|
207
|
-
case OakExternalException
|
|
221
|
+
case 'OakExternalException': {
|
|
208
222
|
return new OakExternalException(data.message);
|
|
209
223
|
}
|
|
210
|
-
case OakRowInconsistencyException
|
|
224
|
+
case 'OakRowInconsistencyException': {
|
|
211
225
|
return new OakRowInconsistencyException(data.data, data.message);
|
|
212
226
|
}
|
|
213
|
-
case OakInputIllegalException
|
|
214
|
-
return new OakInputIllegalException(data.attributes, data.message);
|
|
227
|
+
case 'OakInputIllegalException': {
|
|
228
|
+
return new OakInputIllegalException(data.entity, data.attributes, data.message);
|
|
215
229
|
}
|
|
216
|
-
case OakUserUnpermittedException
|
|
230
|
+
case 'OakUserUnpermittedException': {
|
|
217
231
|
return new OakUserUnpermittedException(data.message);
|
|
218
232
|
}
|
|
219
|
-
case OakUnloggedInException
|
|
233
|
+
case 'OakUnloggedInException': {
|
|
220
234
|
return new OakUnloggedInException(data.message);
|
|
221
235
|
}
|
|
222
|
-
case OakCongruentRowExists
|
|
236
|
+
case 'OakCongruentRowExists': {
|
|
223
237
|
return new OakCongruentRowExists(data.entity, data.data, data.message);
|
|
224
238
|
}
|
|
225
|
-
case OakRowLockedException
|
|
239
|
+
case 'OakRowLockedException': {
|
|
226
240
|
return new OakRowLockedException(data.message);
|
|
227
241
|
}
|
|
228
|
-
case OakRowUnexistedException
|
|
242
|
+
case 'OakRowUnexistedException': {
|
|
229
243
|
return new OakRowUnexistedException(data.rows);
|
|
230
244
|
}
|
|
245
|
+
case 'OakDeadlock': {
|
|
246
|
+
return new OakDeadlock(data.message);
|
|
247
|
+
}
|
|
231
248
|
default:
|
|
232
249
|
return;
|
|
233
250
|
}
|
package/lib/types/RowStore.d.ts
CHANGED
|
@@ -1,22 +1,11 @@
|
|
|
1
|
-
import { OperationResult,
|
|
2
|
-
import { Context } from './Context';
|
|
1
|
+
import { OperationResult, EntityDict } from './Entity';
|
|
3
2
|
import { StorageSchema } from './Storage';
|
|
4
|
-
import { OakErrorDefDict } from '../OakError';
|
|
5
|
-
import { SelectOption } from '.';
|
|
6
3
|
export declare type TxnOption = {
|
|
7
4
|
isolationLevel: 'repeatable read' | 'serializable';
|
|
8
5
|
};
|
|
9
|
-
export declare abstract class RowStore<ED extends EntityDict
|
|
10
|
-
static $$LEVEL: string;
|
|
11
|
-
static $$CODES: OakErrorDefDict;
|
|
6
|
+
export declare abstract class RowStore<ED extends EntityDict> {
|
|
12
7
|
protected storageSchema: StorageSchema<ED>;
|
|
13
|
-
abstract operate<T extends keyof ED, OP extends OperateOption>(entity: T, operation: ED[T]['Operation'], context: Cxt, option: OP): Promise<OperationResult<ED>>;
|
|
14
|
-
abstract select<T extends keyof ED, S extends ED[T]['Selection'], OP extends SelectOption>(entity: T, selection: S, context: Cxt, option: OP): Promise<SelectionResult<ED[T]['Schema'], S['data']>>;
|
|
15
|
-
abstract count<T extends keyof ED, OP extends SelectOption>(entity: T, selection: Pick<ED[T]['Selection'], 'filter' | 'count'>, context: Cxt, option: OP): Promise<number>;
|
|
16
8
|
constructor(storageSchema: StorageSchema<ED>);
|
|
17
|
-
abstract begin(option?: TxnOption): Promise<string>;
|
|
18
|
-
abstract commit(txnId: string): Promise<void>;
|
|
19
|
-
abstract rollback(txnId: string): Promise<void>;
|
|
20
9
|
getSchema(): StorageSchema<ED>;
|
|
21
10
|
mergeOperationResult(result: OperationResult<ED>, toBeMerged: OperationResult<ED>): void;
|
|
22
11
|
mergeMultipleResults(toBeMerged: OperationResult<ED>[]): OperationResult<ED>;
|
package/lib/types/RowStore.js
CHANGED
|
@@ -28,12 +28,7 @@ var RowStore = /** @class */ (function () {
|
|
|
28
28
|
toBeMerged.forEach(function (ele) { return _this.mergeOperationResult(result, ele); });
|
|
29
29
|
return result;
|
|
30
30
|
};
|
|
31
|
-
RowStore.$$LEVEL = 'store';
|
|
32
|
-
RowStore.$$CODES = {
|
|
33
|
-
primaryKeyConfilict: [1, '主键重复'],
|
|
34
|
-
expressionUnresolved: [2, '表达式无法计算完成'],
|
|
35
|
-
nodeIdRepeated: [3, '查询或投影中的nodeId重复'],
|
|
36
|
-
};
|
|
37
31
|
return RowStore;
|
|
38
32
|
}());
|
|
39
33
|
exports.RowStore = RowStore;
|
|
34
|
+
;
|
package/lib/types/Storage.d.ts
CHANGED
package/lib/types/Trigger.d.ts
CHANGED
|
@@ -1,89 +1,84 @@
|
|
|
1
|
-
import { SelectOption
|
|
1
|
+
import { SelectOption } from ".";
|
|
2
2
|
import { GenericAction } from "../actions/action";
|
|
3
|
+
import { AsyncContext } from "../store/AsyncRowStore";
|
|
4
|
+
import { SyncContext } from "../store/SyncRowStore";
|
|
3
5
|
import { EntityDict, OperateOption } from "../types/Entity";
|
|
4
|
-
import { EntityShape
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export interface CreateTriggerBase<ED extends EntityDict, T extends keyof ED, Cxt extends Context<ED>> {
|
|
6
|
+
import { EntityShape } from "../types/Entity";
|
|
7
|
+
export declare type CheckerType = 'relation' | 'row' | 'data';
|
|
8
|
+
interface TriggerBase<ED extends EntityDict, T extends keyof ED> {
|
|
8
9
|
checkerType?: CheckerType;
|
|
9
10
|
entity: T;
|
|
10
11
|
name: string;
|
|
12
|
+
priority?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface CreateTriggerBase<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> extends TriggerBase<ED, T> {
|
|
11
15
|
action: 'create';
|
|
12
16
|
check?: (operation: ED[T]['Create']) => boolean;
|
|
13
17
|
fn: (event: {
|
|
14
18
|
operation: ED[T]['Create'];
|
|
15
|
-
}, context: Cxt, option: OperateOption) => Promise<number
|
|
19
|
+
}, context: Cxt, option: OperateOption) => Promise<number> | number;
|
|
16
20
|
}
|
|
17
|
-
export interface CreateTriggerInTxn<ED extends EntityDict, T extends keyof ED, Cxt extends
|
|
21
|
+
export interface CreateTriggerInTxn<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> extends CreateTriggerBase<ED, T, Cxt> {
|
|
18
22
|
when: 'before' | 'after';
|
|
19
23
|
}
|
|
20
|
-
export interface CreateTriggerCrossTxn<ED extends EntityDict, T extends keyof ED, Cxt extends
|
|
24
|
+
export interface CreateTriggerCrossTxn<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> extends CreateTriggerBase<ED, T, Cxt> {
|
|
21
25
|
when: 'commit';
|
|
22
26
|
strict?: 'takeEasy' | 'makeSure';
|
|
23
27
|
}
|
|
24
|
-
export declare type CreateTrigger<ED extends EntityDict, T extends keyof ED, Cxt extends
|
|
25
|
-
export interface UpdateTriggerBase<ED extends EntityDict, T extends keyof ED, Cxt extends
|
|
26
|
-
checkerType?: CheckerType;
|
|
27
|
-
entity: T;
|
|
28
|
-
name: string;
|
|
28
|
+
export declare type CreateTrigger<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = CreateTriggerInTxn<ED, T, Cxt> | CreateTriggerCrossTxn<ED, T, Cxt>;
|
|
29
|
+
export interface UpdateTriggerBase<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> extends TriggerBase<ED, T> {
|
|
29
30
|
action: Exclude<ED[T]['Action'], GenericAction> | 'update' | Array<Exclude<ED[T]['Action'], GenericAction> | 'update'>;
|
|
30
31
|
attributes?: keyof ED[T]['OpSchema'] | Array<keyof ED[T]['OpSchema']>;
|
|
31
32
|
check?: (operation: ED[T]['Update']) => boolean;
|
|
32
33
|
fn: (event: {
|
|
33
34
|
operation: ED[T]['Update'];
|
|
34
|
-
}, context: Cxt, option: OperateOption) => Promise<number
|
|
35
|
+
}, context: Cxt, option: OperateOption) => Promise<number> | number;
|
|
35
36
|
}
|
|
36
|
-
export interface UpdateTriggerInTxn<ED extends EntityDict, T extends keyof ED, Cxt extends
|
|
37
|
+
export interface UpdateTriggerInTxn<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> extends UpdateTriggerBase<ED, T, Cxt> {
|
|
37
38
|
when: 'before' | 'after';
|
|
38
39
|
}
|
|
39
|
-
export interface UpdateTriggerCrossTxn<ED extends EntityDict, T extends keyof ED, Cxt extends
|
|
40
|
+
export interface UpdateTriggerCrossTxn<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> extends UpdateTriggerBase<ED, T, Cxt> {
|
|
40
41
|
when: 'commit';
|
|
41
42
|
strict?: 'takeEasy' | 'makeSure';
|
|
42
43
|
}
|
|
43
|
-
export declare type UpdateTrigger<ED extends EntityDict, T extends keyof ED, Cxt extends
|
|
44
|
-
export interface RemoveTriggerBase<ED extends EntityDict, T extends keyof ED, Cxt extends
|
|
45
|
-
checkerType?: CheckerType;
|
|
46
|
-
entity: T;
|
|
47
|
-
name: string;
|
|
44
|
+
export declare type UpdateTrigger<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = UpdateTriggerInTxn<ED, T, Cxt> | UpdateTriggerCrossTxn<ED, T, Cxt>;
|
|
45
|
+
export interface RemoveTriggerBase<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> extends TriggerBase<ED, T> {
|
|
48
46
|
action: 'remove';
|
|
49
47
|
check?: (operation: ED[T]['Remove']) => boolean;
|
|
50
48
|
fn: (event: {
|
|
51
49
|
operation: ED[T]['Remove'];
|
|
52
|
-
}, context: Cxt, option: OperateOption) => Promise<number
|
|
50
|
+
}, context: Cxt, option: OperateOption) => Promise<number> | number;
|
|
53
51
|
}
|
|
54
|
-
export interface RemoveTriggerInTxn<ED extends EntityDict, T extends keyof ED, Cxt extends
|
|
52
|
+
export interface RemoveTriggerInTxn<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> extends RemoveTriggerBase<ED, T, Cxt> {
|
|
55
53
|
when: 'before' | 'after';
|
|
56
54
|
}
|
|
57
|
-
export interface RemoveTriggerCrossTxn<ED extends EntityDict, T extends keyof ED, Cxt extends
|
|
55
|
+
export interface RemoveTriggerCrossTxn<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> extends RemoveTriggerBase<ED, T, Cxt> {
|
|
58
56
|
when: 'commit';
|
|
59
57
|
strict?: 'takeEasy' | 'makeSure';
|
|
60
58
|
}
|
|
61
|
-
export declare type RemoveTrigger<ED extends EntityDict, T extends keyof ED, Cxt extends
|
|
62
|
-
export interface SelectTriggerBase<ED extends EntityDict, T extends keyof ED> {
|
|
63
|
-
checkerType?: undefined;
|
|
64
|
-
entity: T;
|
|
65
|
-
name: string;
|
|
59
|
+
export declare type RemoveTrigger<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = RemoveTriggerInTxn<ED, T, Cxt> | RemoveTriggerCrossTxn<ED, T, Cxt>;
|
|
60
|
+
export interface SelectTriggerBase<ED extends EntityDict, T extends keyof ED> extends TriggerBase<ED, T> {
|
|
66
61
|
action: 'select';
|
|
67
62
|
}
|
|
68
63
|
/**
|
|
69
64
|
* selection似乎不需要支持跨事务?没想清楚
|
|
70
65
|
* todo by Xc
|
|
71
66
|
*/
|
|
72
|
-
export interface SelectTriggerBefore<ED extends EntityDict, T extends keyof ED, Cxt extends
|
|
67
|
+
export interface SelectTriggerBefore<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> extends SelectTriggerBase<ED, T> {
|
|
73
68
|
when: 'before';
|
|
74
69
|
fn: (event: {
|
|
75
70
|
operation: ED[T]['Selection'];
|
|
76
|
-
}, context: Cxt, params?: SelectOption) => Promise<number
|
|
71
|
+
}, context: Cxt, params?: SelectOption) => Promise<number> | number;
|
|
77
72
|
}
|
|
78
|
-
export interface SelectTriggerAfter<ED extends EntityDict, T extends keyof ED, Cxt extends
|
|
73
|
+
export interface SelectTriggerAfter<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> extends SelectTriggerBase<ED, T> {
|
|
79
74
|
when: 'after';
|
|
80
75
|
fn: (event: {
|
|
81
76
|
operation: ED[T]['Selection'];
|
|
82
|
-
result:
|
|
83
|
-
}, context: Cxt, params?: SelectOption) => Promise<number
|
|
77
|
+
result: Partial<ED[T]['Schema']>[];
|
|
78
|
+
}, context: Cxt, params?: SelectOption) => Promise<number> | number;
|
|
84
79
|
}
|
|
85
|
-
export declare type SelectTrigger<ED extends EntityDict, T extends keyof ED, Cxt extends
|
|
86
|
-
export declare type Trigger<ED extends EntityDict, T extends keyof ED, Cxt extends
|
|
80
|
+
export declare type SelectTrigger<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = SelectTriggerBefore<ED, T, Cxt> | SelectTriggerAfter<ED, T, Cxt>;
|
|
81
|
+
export declare type Trigger<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = CreateTrigger<ED, T, Cxt> | UpdateTrigger<ED, T, Cxt> | RemoveTrigger<ED, T, Cxt> | SelectTrigger<ED, T, Cxt>;
|
|
87
82
|
export interface TriggerEntityShape extends EntityShape {
|
|
88
83
|
$$triggerData$$?: {
|
|
89
84
|
name: string;
|
|
@@ -91,15 +86,4 @@ export interface TriggerEntityShape extends EntityShape {
|
|
|
91
86
|
};
|
|
92
87
|
$$triggerTimestamp$$?: number;
|
|
93
88
|
}
|
|
94
|
-
export
|
|
95
|
-
static dataAttr: TriggerDataAttribute;
|
|
96
|
-
static timestampAttr: TriggerTimestampAttribute;
|
|
97
|
-
abstract registerTrigger<T extends keyof ED>(trigger: Trigger<ED, T, Cxt>): void;
|
|
98
|
-
abstract preOperation<T extends keyof ED>(entity: T, operation: ED[T]['Operation'] | ED[T]['Selection'] & {
|
|
99
|
-
action: 'select';
|
|
100
|
-
}, context: Cxt, option: OperateOption | SelectOption): Promise<void>;
|
|
101
|
-
abstract postOperation<T extends keyof ED>(entity: T, operation: ED[T]['Operation'] | ED[T]['Selection'] & {
|
|
102
|
-
action: 'select';
|
|
103
|
-
}, context: Cxt, option: OperateOption | SelectOption, result?: SelectRowShape<ED[T]['Schema'], ED[T]['Selection']['data']>[]): Promise<void>;
|
|
104
|
-
abstract checkpoint(context: Cxt, timestamp: number): Promise<number>;
|
|
105
|
-
}
|
|
89
|
+
export {};
|