oak-domain 1.1.14 → 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 +22 -22
- package/lib/base-app-domain/ModiEntity/Schema.d.ts +17 -17
- package/lib/base-app-domain/Oper/Schema.d.ts +17 -17
- package/lib/base-app-domain/OperEntity/Schema.d.ts +18 -18
- package/lib/base-app-domain/User/Schema.d.ts +15 -15
- package/lib/checkers/index.d.ts +4 -2
- package/lib/compiler/schemalBuilder.js +10 -10
- 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 +954 -995
- 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 -134
- 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 +394 -2
- 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/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/Entity.d.ts +20 -15
- package/lib/types/Entity.js +9 -2
- package/lib/types/Exception.js +11 -11
- package/lib/types/RowStore.d.ts +2 -13
- package/lib/types/RowStore.js +1 -6
- 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/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.js +1 -1
- 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/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(allowUnloggedIn?: boolean): 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/Entity.d.ts
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
import { GenericAction } from '../actions/action';
|
|
2
|
-
import {
|
|
3
|
-
import { OneOf
|
|
2
|
+
import { ExprOp, MakeFilter, NodeId } from './Demand';
|
|
3
|
+
import { OneOf } from './Polyfill';
|
|
4
4
|
import { PrimaryKey, Sequence } from './DataType';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
declare type
|
|
8
|
-
|
|
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;
|
|
9
20
|
export declare const initinctiveAttributes: string[];
|
|
10
21
|
export declare type Filter<A extends string, F extends Object | undefined = undefined> = {
|
|
11
22
|
filter?: A extends 'create' ? undefined : F;
|
|
@@ -78,14 +89,14 @@ export interface OtmSubProjection extends Omit<DeduceSelection<any>, 'action'> {
|
|
|
78
89
|
declare type DeduceProjection<SH extends GeneralEntityShape> = {
|
|
79
90
|
'#id'?: NodeId;
|
|
80
91
|
} & {
|
|
81
|
-
[K in keyof SH]?:
|
|
92
|
+
[K in keyof SH]?: number | OtmSubProjection | any;
|
|
82
93
|
} & Partial<ExprOp<keyof SH>>;
|
|
83
94
|
export declare type AttrFilter<SH extends GeneralEntityShape> = {
|
|
84
95
|
[K in keyof SH]: any;
|
|
85
96
|
};
|
|
86
97
|
export declare type DeduceFilter<SH extends GeneralEntityShape> = MakeFilter<AttrFilter<SH> & ExprOp<keyof SH>>;
|
|
87
98
|
export declare type DeduceSorterAttr<SH extends GeneralEntityShape> = OneOf<{
|
|
88
|
-
[K: string]:
|
|
99
|
+
[K: string]: number | object | undefined;
|
|
89
100
|
} & ExprOp<keyof SH>>;
|
|
90
101
|
export declare type DeduceSorterItem<SH extends GeneralEntityShape> = {
|
|
91
102
|
$attr: DeduceSorterAttr<SH>;
|
|
@@ -109,7 +120,7 @@ export declare type DeduceRemoveOperationData<SH extends GeneralEntityShape> = {
|
|
|
109
120
|
[A in keyof Omit<SH, InstinctiveAttributes>]?: any;
|
|
110
121
|
};
|
|
111
122
|
export declare type DeduceRemoveOperation<SH extends GeneralEntityShape> = Operation<'remove', DeduceRemoveOperationData<SH>, DeduceFilter<SH>, DeduceSorter<SH>>;
|
|
112
|
-
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>;
|
|
113
124
|
export declare type CreateOpResult<ED extends EntityDict, T extends keyof ED> = {
|
|
114
125
|
a: 'c';
|
|
115
126
|
e: T;
|
|
@@ -140,12 +151,6 @@ export declare type OperationResult<ED extends EntityDict> = {
|
|
|
140
151
|
[A in ED[K]['Action']]?: number;
|
|
141
152
|
};
|
|
142
153
|
};
|
|
143
|
-
export declare type SelectRowShape<E extends GeneralEntityShape, P extends DeduceProjection<GeneralEntityShape>> = {
|
|
144
|
-
[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);
|
|
145
|
-
};
|
|
146
|
-
export declare type SelectionResult<E extends GeneralEntityShape, P extends DeduceProjection<GeneralEntityShape>> = {
|
|
147
|
-
result: Array<SelectRowShape<E, P>>;
|
|
148
|
-
};
|
|
149
154
|
export declare type ActionType = 'readOnly' | 'appendOnly' | 'excludeUpdate' | 'excludeRemove' | 'crud';
|
|
150
155
|
export declare type Configuration = {
|
|
151
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.js
CHANGED
|
@@ -212,37 +212,37 @@ exports.OakDeadlock = OakDeadlock;
|
|
|
212
212
|
function makeException(data) {
|
|
213
213
|
var name = data.name;
|
|
214
214
|
switch (name) {
|
|
215
|
-
case OakException
|
|
215
|
+
case 'OakException': {
|
|
216
216
|
return new OakException(data.message);
|
|
217
217
|
}
|
|
218
|
-
case OakUserException
|
|
218
|
+
case 'OakUserException': {
|
|
219
219
|
return new OakUserException(data.message);
|
|
220
220
|
}
|
|
221
|
-
case OakExternalException
|
|
221
|
+
case 'OakExternalException': {
|
|
222
222
|
return new OakExternalException(data.message);
|
|
223
223
|
}
|
|
224
|
-
case OakRowInconsistencyException
|
|
224
|
+
case 'OakRowInconsistencyException': {
|
|
225
225
|
return new OakRowInconsistencyException(data.data, data.message);
|
|
226
226
|
}
|
|
227
|
-
case OakInputIllegalException
|
|
227
|
+
case 'OakInputIllegalException': {
|
|
228
228
|
return new OakInputIllegalException(data.entity, data.attributes, data.message);
|
|
229
229
|
}
|
|
230
|
-
case OakUserUnpermittedException
|
|
230
|
+
case 'OakUserUnpermittedException': {
|
|
231
231
|
return new OakUserUnpermittedException(data.message);
|
|
232
232
|
}
|
|
233
|
-
case OakUnloggedInException
|
|
233
|
+
case 'OakUnloggedInException': {
|
|
234
234
|
return new OakUnloggedInException(data.message);
|
|
235
235
|
}
|
|
236
|
-
case OakCongruentRowExists
|
|
236
|
+
case 'OakCongruentRowExists': {
|
|
237
237
|
return new OakCongruentRowExists(data.entity, data.data, data.message);
|
|
238
238
|
}
|
|
239
|
-
case OakRowLockedException
|
|
239
|
+
case 'OakRowLockedException': {
|
|
240
240
|
return new OakRowLockedException(data.message);
|
|
241
241
|
}
|
|
242
|
-
case OakRowUnexistedException
|
|
242
|
+
case 'OakRowUnexistedException': {
|
|
243
243
|
return new OakRowUnexistedException(data.rows);
|
|
244
244
|
}
|
|
245
|
-
case OakDeadlock
|
|
245
|
+
case 'OakDeadlock': {
|
|
246
246
|
return new OakDeadlock(data.message);
|
|
247
247
|
}
|
|
248
248
|
default:
|
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/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 {};
|
package/lib/types/Trigger.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Executor = void 0;
|
|
4
3
|
;
|
|
5
4
|
;
|
|
6
5
|
;
|
|
@@ -14,11 +13,27 @@ exports.Executor = void 0;
|
|
|
14
13
|
;
|
|
15
14
|
;
|
|
16
15
|
;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
;
|
|
17
|
+
/* export abstract class Executor<ED extends EntityDict, Cxt extends AsyncContext<ED>> {
|
|
18
|
+
static dataAttr: TriggerDataAttribute = '$$triggerData$$';
|
|
19
|
+
static timestampAttr: TriggerTimestampAttribute = '$$triggerTimestamp$$';
|
|
20
|
+
|
|
21
|
+
abstract registerTrigger<T extends keyof ED>(trigger: Trigger<ED, T>): void;
|
|
22
|
+
|
|
23
|
+
abstract preOperation<T extends keyof ED>(
|
|
24
|
+
entity: T,
|
|
25
|
+
operation: ED[T]['Operation'] | ED[T]['Selection'] & { action: 'select' },
|
|
26
|
+
context: Cxt,
|
|
27
|
+
option: OperateOption | SelectOption
|
|
28
|
+
): Promise<void>;
|
|
29
|
+
|
|
30
|
+
abstract postOperation<T extends keyof ED>(
|
|
31
|
+
entity: T,
|
|
32
|
+
operation: ED[T]['Operation'] | ED[T]['Selection'] & { action: 'select' },
|
|
33
|
+
context: Cxt,
|
|
34
|
+
option: OperateOption | SelectOption,
|
|
35
|
+
result?: SelectRowShape<ED[T]['Schema'], ED[T]['Selection']['data']>[]
|
|
36
|
+
): Promise<void>;
|
|
37
|
+
|
|
38
|
+
abstract checkpoint(context: Cxt, timestamp: number): Promise<number>; // 将所有在timestamp之前存在不一致的数据进行恢复
|
|
39
|
+
} */
|
package/lib/types/Watcher.d.ts
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Context } from "./Context";
|
|
1
|
+
import { AsyncContext } from "../store/AsyncRowStore";
|
|
3
2
|
import { EntityDict, OperationResult } from "./Entity";
|
|
4
3
|
declare type ActionData<ED extends EntityDict, T extends keyof ED> = ED[T]['Update']['data'] | ED[T]['Remove']['data'];
|
|
5
4
|
export interface BBWatcher<ED extends EntityDict, T extends keyof ED> {
|
|
6
5
|
name: string;
|
|
7
6
|
entity: T;
|
|
8
|
-
filter: ED[T]['Selection']['filter'] | (() =>
|
|
7
|
+
filter: ED[T]['Selection']['filter'] | (() => ED[T]['Selection']['filter']);
|
|
9
8
|
action: ED[T]['Operation']['action'];
|
|
10
|
-
actionData: ActionData<ED, T> | (() =>
|
|
9
|
+
actionData: ActionData<ED, T> | (() => ActionData<ED, T>);
|
|
11
10
|
}
|
|
12
|
-
export interface WBWatcher<ED extends EntityDict, T extends keyof ED, Cxt extends
|
|
11
|
+
export interface WBWatcher<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>> {
|
|
13
12
|
name: string;
|
|
14
13
|
entity: T;
|
|
15
14
|
filter: ED[T]['Selection']['filter'] | (() => Promise<ED[T]['Selection']['filter']>);
|
|
16
|
-
projection:
|
|
17
|
-
fn: (context: Cxt, data:
|
|
15
|
+
projection: ED[T]['Selection']['data'] | (() => Promise<ED[T]['Selection']['data']>);
|
|
16
|
+
fn: (context: Cxt, data: Partial<ED[T]['Schema']>[]) => Promise<OperationResult<ED>>;
|
|
18
17
|
}
|
|
19
|
-
export declare type Watcher<ED extends EntityDict, T extends keyof ED, Cxt extends
|
|
18
|
+
export declare type Watcher<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>> = BBWatcher<ED, T> | WBWatcher<ED, T, Cxt>;
|
|
20
19
|
export {};
|
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { IncomingHttpHeaders } from "http";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
3
|
+
import { AsyncContext, AsyncRowStore } from '../store/AsyncRowStore';
|
|
4
|
+
import { SyncContext } from '../store/SyncRowStore';
|
|
5
|
+
import { Connector, EntityDict, OakException, OpRecord } from "../types";
|
|
6
|
+
export declare class SimpleConnector<ED extends EntityDict, BackCxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>> extends Connector<ED, BackCxt, FrontCxt> {
|
|
6
7
|
static ROUTER: string;
|
|
7
8
|
private serverUrl;
|
|
8
9
|
private makeException;
|
|
9
10
|
private contextBuilder;
|
|
10
|
-
constructor(serverUrl: string, makeException: (exceptionData: any) => OakException, contextBuilder: (str: string | undefined) => (store:
|
|
11
|
-
callAspect(name: string, params: any, context:
|
|
11
|
+
constructor(serverUrl: string, makeException: (exceptionData: any) => OakException, contextBuilder: (str: string | undefined) => (store: AsyncRowStore<ED, BackCxt>) => Promise<BackCxt>);
|
|
12
|
+
callAspect(name: string, params: any, context: FrontCxt): Promise<{
|
|
12
13
|
result: any;
|
|
13
14
|
opRecords: OpRecord<ED>[];
|
|
14
15
|
}>;
|
|
15
16
|
getRouter(): string;
|
|
16
|
-
parseRequest(headers: IncomingHttpHeaders, body: any, store:
|
|
17
|
+
parseRequest(headers: IncomingHttpHeaders, body: any, store: AsyncRowStore<ED, BackCxt>): Promise<{
|
|
17
18
|
name: string;
|
|
18
19
|
params: any;
|
|
19
|
-
context:
|
|
20
|
+
context: BackCxt;
|
|
20
21
|
}>;
|
|
21
|
-
serializeResult(result: any, context:
|
|
22
|
+
serializeResult(result: any, context: BackCxt, headers: IncomingHttpHeaders, body: any): {
|
|
22
23
|
body: any;
|
|
23
24
|
headers?: Record<string, any> | undefined;
|
|
24
25
|
};
|
|
@@ -24,9 +24,8 @@ var SimpleConnector = /** @class */ (function (_super) {
|
|
|
24
24
|
var cxtStr, _a, contentType, body, response, err, _b, exception, result, opRecords;
|
|
25
25
|
return tslib_1.__generator(this, function (_c) {
|
|
26
26
|
switch (_c.label) {
|
|
27
|
-
case 0:
|
|
28
|
-
|
|
29
|
-
cxtStr = _c.sent();
|
|
27
|
+
case 0:
|
|
28
|
+
cxtStr = context.toString();
|
|
30
29
|
_a = makeContentTypeAndBody(params), contentType = _a.contentType, body = _a.body;
|
|
31
30
|
return [4 /*yield*/, global.fetch(this.serverUrl, {
|
|
32
31
|
method: 'POST',
|
|
@@ -37,14 +36,14 @@ var SimpleConnector = /** @class */ (function (_super) {
|
|
|
37
36
|
},
|
|
38
37
|
body: body,
|
|
39
38
|
})];
|
|
40
|
-
case
|
|
39
|
+
case 1:
|
|
41
40
|
response = _c.sent();
|
|
42
41
|
if (response.status > 299) {
|
|
43
42
|
err = new types_1.OakExternalException("\u7F51\u7EDC\u8BF7\u6C42\u8FD4\u56DE\u5F02\u5E38\uFF0Cstatus\u662F".concat(response.status));
|
|
44
43
|
throw err;
|
|
45
44
|
}
|
|
46
45
|
return [4 /*yield*/, response.json()];
|
|
47
|
-
case
|
|
46
|
+
case 2:
|
|
48
47
|
_b = _c.sent(), exception = _b.exception, result = _b.result, opRecords = _b.opRecords;
|
|
49
48
|
if (exception) {
|
|
50
49
|
throw this.makeException(exception);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getRandomValues(length: number): Promise<Uint8Array>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRandomValues = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var node_crypto_1 = require("node:crypto");
|
|
6
|
+
function getRandomValues(length) {
|
|
7
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
8
|
+
return tslib_1.__generator(this, function (_a) {
|
|
9
|
+
if (length > 65536) {
|
|
10
|
+
throw new Error('Can only request a maximum of 65536 bytes');
|
|
11
|
+
}
|
|
12
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
13
|
+
(0, node_crypto_1.randomBytes)(length, function (err, buf) {
|
|
14
|
+
if (err) {
|
|
15
|
+
reject(err);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
resolve(new Uint8Array(buf));
|
|
19
|
+
});
|
|
20
|
+
})];
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
exports.getRandomValues = getRandomValues;
|