oak-domain 3.0.2 → 3.0.4
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/action.d.ts +8 -8
- package/lib/actions/action.js +2 -2
- package/lib/actions/relation.d.ts +1 -1
- package/lib/actions/relation.js +9 -22
- package/lib/base-app-domain/ActionAuth/Schema.d.ts +68 -42
- package/lib/base-app-domain/ActionAuth/Storage.js +12 -15
- package/lib/base-app-domain/ActionDefDict.d.ts +2 -3
- package/lib/base-app-domain/ActionDefDict.js +3 -5
- package/lib/base-app-domain/EntityDict.d.ts +5 -1
- package/lib/base-app-domain/I18n/Schema.d.ts +24 -24
- package/lib/base-app-domain/I18n/Storage.js +5 -5
- package/lib/base-app-domain/Modi/Action.d.ts +4 -4
- package/lib/base-app-domain/Modi/Action.js +3 -3
- package/lib/base-app-domain/Modi/Schema.d.ts +24 -24
- package/lib/base-app-domain/Modi/Storage.js +3 -3
- package/lib/base-app-domain/ModiEntity/Schema.d.ts +128 -55
- package/lib/base-app-domain/ModiEntity/Storage.js +2 -2
- package/lib/base-app-domain/Oper/Schema.d.ts +30 -29
- package/lib/base-app-domain/Oper/Storage.js +1 -1
- package/lib/base-app-domain/OperEntity/Schema.d.ts +126 -53
- package/lib/base-app-domain/OperEntity/Storage.js +2 -2
- package/lib/base-app-domain/Path/Schema.d.ts +149 -0
- package/lib/base-app-domain/Path/Schema.js +2 -0
- package/lib/base-app-domain/Path/Storage.d.ts +3 -0
- package/lib/base-app-domain/Path/Storage.js +54 -0
- package/lib/base-app-domain/Relation/Schema.d.ts +34 -34
- package/lib/base-app-domain/Relation/Storage.js +6 -6
- package/lib/base-app-domain/Relation.d.ts +0 -8
- package/lib/base-app-domain/Relation.js +1 -7
- package/lib/base-app-domain/RelationAuth/Schema.d.ts +74 -40
- package/lib/base-app-domain/RelationAuth/Storage.js +9 -11
- package/lib/base-app-domain/Storage.js +20 -16
- package/lib/base-app-domain/User/Action.d.ts +4 -4
- package/lib/base-app-domain/User/Action.js +3 -3
- package/lib/base-app-domain/User/Schema.d.ts +40 -27
- package/lib/base-app-domain/User/Storage.js +1 -1
- package/lib/base-app-domain/UserEntityClaim/Schema.d.ts +264 -0
- package/lib/base-app-domain/UserEntityClaim/Schema.js +2 -0
- package/lib/base-app-domain/UserEntityClaim/Storage.d.ts +3 -0
- package/lib/base-app-domain/UserEntityClaim/Storage.js +37 -0
- package/lib/base-app-domain/UserEntityGrant/Action.d.ts +2 -2
- package/lib/base-app-domain/UserEntityGrant/Schema.d.ts +55 -81
- package/lib/base-app-domain/UserEntityGrant/Storage.js +7 -11
- package/lib/base-app-domain/UserRelation/Schema.d.ts +50 -36
- package/lib/base-app-domain/UserRelation/Storage.js +7 -7
- package/lib/base-app-domain/_SubQuery.d.ts +45 -15
- package/lib/base-app-domain/index.js +1 -1
- package/lib/checkers/index.js +6 -7
- package/lib/compiler/env.js +16 -18
- package/lib/compiler/localeBuilder.js +83 -79
- package/lib/compiler/schemalBuilder.d.ts +16 -0
- package/lib/compiler/schemalBuilder.js +1160 -1378
- package/lib/entities/ActionAuth.d.ts +3 -5
- package/lib/entities/ActionAuth.js +9 -7
- package/lib/entities/I18n.js +1 -1
- package/lib/entities/Modi.js +2 -2
- package/lib/entities/ModiEntity.js +1 -1
- package/lib/entities/Oper.js +1 -1
- package/lib/entities/OperEntity.js +1 -1
- package/lib/entities/Path.d.ts +8 -0
- package/lib/entities/Path.js +35 -0
- package/lib/entities/Relation.js +1 -1
- package/lib/entities/RelationAuth.d.ts +2 -2
- package/lib/entities/RelationAuth.js +1 -1
- package/lib/entities/User.js +2 -2
- package/lib/entities/UserEntityClaim.d.ts +13 -0
- package/lib/entities/UserEntityClaim.js +17 -0
- package/lib/entities/UserEntityGrant.d.ts +5 -4
- package/lib/entities/UserEntityGrant.js +4 -7
- package/lib/entities/UserRelation.js +1 -1
- package/lib/index.d.ts +23 -0
- package/lib/index.js +37 -0
- package/lib/store/AsyncRowStore.d.ts +2 -1
- package/lib/store/AsyncRowStore.js +75 -149
- package/lib/store/CascadeStore.js +968 -1341
- package/lib/store/RelationAuth.d.ts +9 -16
- package/lib/store/RelationAuth.js +752 -910
- package/lib/store/SyncRowStore.d.ts +1 -1
- package/lib/store/SyncRowStore.js +27 -26
- package/lib/store/TriggerExecutor.d.ts +17 -10
- package/lib/store/TriggerExecutor.js +350 -423
- package/lib/store/actionAuth.js +13 -28
- package/lib/store/actionDef.js +142 -215
- package/lib/store/checker.js +225 -361
- package/lib/store/filter.d.ts +2 -3
- package/lib/store/filter.js +451 -589
- package/lib/store/modi.js +116 -177
- package/lib/store/relation.js +17 -17
- package/lib/timers/oper.d.ts +1 -1
- package/lib/timers/oper.js +44 -47
- package/lib/timers/vaccum.d.ts +2 -2
- package/lib/timers/vaccum.js +100 -165
- package/lib/triggers/index.js +1 -1
- package/lib/types/Action.d.ts +7 -7
- package/lib/types/AppLoader.d.ts +8 -2
- package/lib/types/AppLoader.js +4 -4
- package/lib/types/Auth.d.ts +15 -19
- package/lib/types/Connector.d.ts +19 -14
- package/lib/types/Connector.js +0 -7
- package/lib/types/DataType.d.ts +19 -18
- package/lib/types/DataType.js +1 -1
- package/lib/types/Demand.d.ts +25 -25
- package/lib/types/Endpoint.d.ts +1 -1
- package/lib/types/Entity.d.ts +62 -53
- package/lib/types/Entity.js +4 -3
- package/lib/types/EntityDesc.d.ts +2 -1
- package/lib/types/Environment.d.ts +4 -4
- package/lib/types/Exception.d.ts +34 -2
- package/lib/types/Exception.js +214 -197
- package/lib/types/Expression.d.ts +14 -14
- package/lib/types/Expression.js +54 -87
- package/lib/types/Geo.d.ts +6 -6
- package/lib/types/Locale.d.ts +5 -5
- package/lib/types/Polyfill.d.ts +9 -9
- package/lib/types/Port.d.ts +4 -4
- package/lib/types/RowStore.d.ts +3 -3
- package/lib/types/RowStore.js +18 -19
- package/lib/types/Storage.d.ts +5 -4
- package/lib/types/Style.d.ts +2 -2
- package/lib/types/Timer.d.ts +3 -3
- package/lib/types/Trigger.d.ts +30 -14
- package/lib/types/Trigger.js +6 -2
- package/lib/types/Watcher.d.ts +2 -2
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +2 -1
- package/lib/types/schema/DataTypes.d.ts +7 -7
- package/lib/utils/SimpleConnector.d.ts +26 -10
- package/lib/utils/SimpleConnector.js +167 -141
- package/lib/utils/assert.js +2 -2
- package/lib/utils/concurrent.d.ts +1 -1
- package/lib/utils/concurrent.js +31 -57
- package/lib/utils/date.js +2 -2
- package/lib/utils/geo.js +8 -8
- package/lib/utils/lodash.d.ts +3 -1
- package/lib/utils/lodash.js +21 -34
- package/lib/utils/mask.js +12 -13
- package/lib/utils/money.d.ts +1 -1
- package/lib/utils/money.js +22 -11
- package/lib/utils/projection.d.ts +4 -0
- package/lib/utils/projection.js +15 -0
- package/lib/utils/random/random.js +11 -16
- package/lib/utils/random/random.mp.js +7 -18
- package/lib/utils/random/random.web.js +6 -12
- package/lib/utils/string.d.ts +4 -4
- package/lib/utils/string.js +19 -32
- package/lib/utils/url.js +5 -4
- package/lib/utils/uuid.d.ts +1 -1
- package/lib/utils/uuid.js +46 -85
- package/lib/utils/validator.d.ts +4 -3
- package/lib/utils/validator.js +35 -32
- package/lib/utils/version.js +6 -6
- package/package.json +7 -7
- package/src/entities/ActionAuth.ts +10 -10
- package/src/entities/Path.ts +43 -0
- package/src/entities/RelationAuth.ts +2 -1
- package/src/entities/UserEntityClaim.ts +30 -0
- package/src/entities/UserEntityGrant.ts +9 -12
package/lib/types/Trigger.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { AsyncContext } from "../store/AsyncRowStore";
|
|
|
4
4
|
import { SyncContext } from "../store/SyncRowStore";
|
|
5
5
|
import { EntityDict, OperateOption } from "../types/Entity";
|
|
6
6
|
import { EntityShape } from "../types/Entity";
|
|
7
|
+
export type ModiTurn = 'create' | 'apply' | 'both';
|
|
7
8
|
/**
|
|
8
9
|
* 优先级越小,越早执行。定义在1~99之间
|
|
9
10
|
*/
|
|
@@ -11,6 +12,9 @@ export declare const TRIGGER_MIN_PRIORITY = 1;
|
|
|
11
12
|
export declare const TRIGGER_DEFAULT_PRIORITY = 25;
|
|
12
13
|
export declare const TRIGGER_MAX_PRIORITY = 50;
|
|
13
14
|
export declare const CHECKER_MAX_PRIORITY = 99;
|
|
15
|
+
/**
|
|
16
|
+
* logical可能会更改row和data的值,应当最先执行,data和row不能修改相关的值,如果要修改,手动置priority小一点以确保安全
|
|
17
|
+
*/
|
|
14
18
|
export declare const CHECKER_PRIORITY_MAP: Record<CheckerType, number>;
|
|
15
19
|
interface TriggerBase<ED extends EntityDict, T extends keyof ED> {
|
|
16
20
|
checkerType?: CheckerType;
|
|
@@ -20,19 +24,23 @@ interface TriggerBase<ED extends EntityDict, T extends keyof ED> {
|
|
|
20
24
|
}
|
|
21
25
|
export interface CreateTriggerBase<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> extends TriggerBase<ED, T> {
|
|
22
26
|
action: 'create';
|
|
27
|
+
mt?: ModiTurn;
|
|
23
28
|
check?: (operation: ED[T]['Create']) => boolean;
|
|
24
|
-
fn: (event: {
|
|
25
|
-
operation: ED[T]['Create'];
|
|
26
|
-
}, context: Cxt, option: OperateOption) => Promise<number> | number;
|
|
27
29
|
}
|
|
28
30
|
export interface CreateTriggerInTxn<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> extends CreateTriggerBase<ED, T, Cxt> {
|
|
29
31
|
when: 'before' | 'after';
|
|
32
|
+
fn: (event: {
|
|
33
|
+
operation: ED[T]['Create'];
|
|
34
|
+
}, context: Cxt, option: OperateOption) => Promise<number> | number;
|
|
30
35
|
}
|
|
31
36
|
export interface CreateTriggerCrossTxn<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> extends CreateTriggerBase<ED, T, Cxt> {
|
|
32
37
|
when: 'commit';
|
|
33
38
|
strict?: 'takeEasy' | 'makeSure';
|
|
39
|
+
fn: (event: {
|
|
40
|
+
rows: ED[T]['OpSchema'][];
|
|
41
|
+
}, context: Cxt, option: OperateOption) => Promise<number> | number;
|
|
34
42
|
}
|
|
35
|
-
export
|
|
43
|
+
export type CreateTrigger<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = CreateTriggerInTxn<ED, T, Cxt> | CreateTriggerCrossTxn<ED, T, Cxt>;
|
|
36
44
|
/**
|
|
37
45
|
* update trigger如果带有filter,说明只对存在限定条件的行起作用。此时系统在进行相应动作时,
|
|
38
46
|
* 会判定当前动作的filter条件和trigger所定义的filter是否有交集(即有同时满足两个条件的行)
|
|
@@ -41,20 +49,24 @@ export declare type CreateTrigger<ED extends EntityDict, T extends keyof ED, Cxt
|
|
|
41
49
|
export interface UpdateTriggerBase<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> extends TriggerBase<ED, T> {
|
|
42
50
|
action: Exclude<ED[T]['Action'], GenericAction> | 'update' | Array<Exclude<ED[T]['Action'], GenericAction> | 'update'>;
|
|
43
51
|
attributes?: keyof ED[T]['OpSchema'] | Array<keyof ED[T]['OpSchema']>;
|
|
52
|
+
mt?: ModiTurn;
|
|
44
53
|
check?: (operation: ED[T]['Update']) => boolean;
|
|
45
|
-
fn: (event: {
|
|
46
|
-
operation: ED[T]['Update'];
|
|
47
|
-
}, context: Cxt, option: OperateOption) => Promise<number> | number;
|
|
48
54
|
filter?: ED[T]['Update']['filter'] | ((operation: ED[T]['Update'], context: Cxt, option: OperateOption) => ED[T]['Update']['filter'] | Promise<ED[T]['Update']['filter']>);
|
|
49
55
|
}
|
|
50
56
|
export interface UpdateTriggerInTxn<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> extends UpdateTriggerBase<ED, T, Cxt> {
|
|
51
57
|
when: 'before' | 'after';
|
|
58
|
+
fn: (event: {
|
|
59
|
+
operation: ED[T]['Update'];
|
|
60
|
+
}, context: Cxt, option: OperateOption) => Promise<number> | number;
|
|
52
61
|
}
|
|
53
62
|
export interface UpdateTriggerCrossTxn<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> extends UpdateTriggerBase<ED, T, Cxt> {
|
|
54
63
|
when: 'commit';
|
|
55
64
|
strict?: 'takeEasy' | 'makeSure';
|
|
65
|
+
fn: (event: {
|
|
66
|
+
rows: ED[T]['OpSchema'][];
|
|
67
|
+
}, context: Cxt, option: OperateOption) => Promise<number> | number;
|
|
56
68
|
}
|
|
57
|
-
export
|
|
69
|
+
export type UpdateTrigger<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = UpdateTriggerInTxn<ED, T, Cxt> | UpdateTriggerCrossTxn<ED, T, Cxt>;
|
|
58
70
|
/**
|
|
59
71
|
* 同update trigger一样,remove trigger如果带有filter,说明只对存在限定条件的行起作用。此时系统在进行相应动作时,
|
|
60
72
|
* 会判定当前动作的filter条件和trigger所定义的filter是否有交集(即有同时满足两个条件的行)
|
|
@@ -62,20 +74,24 @@ export declare type UpdateTrigger<ED extends EntityDict, T extends keyof ED, Cxt
|
|
|
62
74
|
*/
|
|
63
75
|
export interface RemoveTriggerBase<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> extends TriggerBase<ED, T> {
|
|
64
76
|
action: 'remove';
|
|
77
|
+
mt?: ModiTurn;
|
|
65
78
|
check?: (operation: ED[T]['Remove']) => boolean;
|
|
66
|
-
fn: (event: {
|
|
67
|
-
operation: ED[T]['Remove'];
|
|
68
|
-
}, context: Cxt, option: OperateOption) => Promise<number> | number;
|
|
69
79
|
filter?: ED[T]['Remove']['filter'] | ((operation: ED[T]['Remove'], context: Cxt, option: OperateOption) => ED[T]['Remove']['filter'] | Promise<ED[T]['Remove']['filter']>);
|
|
70
80
|
}
|
|
71
81
|
export interface RemoveTriggerInTxn<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> extends RemoveTriggerBase<ED, T, Cxt> {
|
|
72
82
|
when: 'before' | 'after';
|
|
83
|
+
fn: (event: {
|
|
84
|
+
operation: ED[T]['Remove'];
|
|
85
|
+
}, context: Cxt, option: OperateOption) => Promise<number> | number;
|
|
73
86
|
}
|
|
74
87
|
export interface RemoveTriggerCrossTxn<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> extends RemoveTriggerBase<ED, T, Cxt> {
|
|
75
88
|
when: 'commit';
|
|
76
89
|
strict?: 'takeEasy' | 'makeSure';
|
|
90
|
+
fn: (event: {
|
|
91
|
+
rows: ED[T]['OpSchema'][];
|
|
92
|
+
}, context: Cxt, option: OperateOption) => Promise<number> | number;
|
|
77
93
|
}
|
|
78
|
-
export
|
|
94
|
+
export type RemoveTrigger<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = RemoveTriggerInTxn<ED, T, Cxt> | RemoveTriggerCrossTxn<ED, T, Cxt>;
|
|
79
95
|
export interface SelectTriggerBase<ED extends EntityDict, T extends keyof ED> extends TriggerBase<ED, T> {
|
|
80
96
|
action: 'select';
|
|
81
97
|
}
|
|
@@ -96,8 +112,8 @@ export interface SelectTriggerAfter<ED extends EntityDict, T extends keyof ED, C
|
|
|
96
112
|
result: Partial<ED[T]['Schema']>[];
|
|
97
113
|
}, context: Cxt, params?: SelectOption) => Promise<number> | number;
|
|
98
114
|
}
|
|
99
|
-
export
|
|
100
|
-
export
|
|
115
|
+
export type SelectTrigger<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = SelectTriggerBefore<ED, T, Cxt> | SelectTriggerAfter<ED, T, Cxt>;
|
|
116
|
+
export 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>;
|
|
101
117
|
export interface TriggerEntityShape extends EntityShape {
|
|
102
118
|
$$triggerData$$?: {
|
|
103
119
|
name: string;
|
package/lib/types/Trigger.js
CHANGED
|
@@ -8,12 +8,16 @@ exports.TRIGGER_MIN_PRIORITY = 1;
|
|
|
8
8
|
exports.TRIGGER_DEFAULT_PRIORITY = 25;
|
|
9
9
|
exports.TRIGGER_MAX_PRIORITY = 50;
|
|
10
10
|
exports.CHECKER_MAX_PRIORITY = 99;
|
|
11
|
+
/**
|
|
12
|
+
* logical可能会更改row和data的值,应当最先执行,data和row不能修改相关的值,如果要修改,手动置priority小一点以确保安全
|
|
13
|
+
*/
|
|
11
14
|
exports.CHECKER_PRIORITY_MAP = {
|
|
15
|
+
logical: 33,
|
|
12
16
|
row: 51,
|
|
13
17
|
data: 61,
|
|
18
|
+
logicalData: 61,
|
|
14
19
|
relation: 71,
|
|
15
|
-
logicalRelation:
|
|
16
|
-
logical: 73,
|
|
20
|
+
logicalRelation: 71,
|
|
17
21
|
};
|
|
18
22
|
;
|
|
19
23
|
;
|
package/lib/types/Watcher.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AsyncContext } from "../store/AsyncRowStore";
|
|
2
2
|
import { EntityDict, OperationResult } from "./Entity";
|
|
3
|
-
|
|
3
|
+
type ActionData<ED extends EntityDict, T extends keyof ED> = ED[T]['Update']['data'] | ED[T]['Remove']['data'];
|
|
4
4
|
export interface BBWatcher<ED extends EntityDict, T extends keyof ED> {
|
|
5
5
|
name: string;
|
|
6
6
|
entity: T;
|
|
@@ -15,5 +15,5 @@ export interface WBWatcher<ED extends EntityDict, T extends keyof ED, Cxt extend
|
|
|
15
15
|
projection: ED[T]['Selection']['data'] | (() => Promise<ED[T]['Selection']['data']>);
|
|
16
16
|
fn: (context: Cxt, data: Partial<ED[T]['Schema']>[]) => Promise<OperationResult<ED>>;
|
|
17
17
|
}
|
|
18
|
-
export
|
|
18
|
+
export type Watcher<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>> = BBWatcher<ED, T> | WBWatcher<ED, T, Cxt>;
|
|
19
19
|
export {};
|
package/lib/types/index.d.ts
CHANGED
package/lib/types/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./Action"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./Aspect"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./Auth"), exports);
|
|
@@ -25,3 +25,4 @@ tslib_1.__exportStar(require("./Endpoint"), exports);
|
|
|
25
25
|
tslib_1.__exportStar(require("./Style"), exports);
|
|
26
26
|
tslib_1.__exportStar(require("./EntityDesc"), exports);
|
|
27
27
|
tslib_1.__exportStar(require("./Environment"), exports);
|
|
28
|
+
tslib_1.__exportStar(require("./Locale"), exports);
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Column types used for @PrimaryGeneratedColumn() decorator.
|
|
3
3
|
*/
|
|
4
|
-
export
|
|
4
|
+
export type PrimaryGeneratedColumnType = "int" | "int2" | "int4" | "int8" | "integer" | "tinyint" | "smallint" | "mediumint" | "bigint" | "dec" | "decimal" | "smalldecimal" | "fixed" | "numeric" | "number";
|
|
5
5
|
/**
|
|
6
6
|
* Column types where spatial properties are used.
|
|
7
7
|
*/
|
|
8
|
-
export
|
|
8
|
+
export type SpatialColumnType = "geometry" | "geography" | "st_geometry" | "st_point";
|
|
9
9
|
/**
|
|
10
10
|
* Column types where precision and scale properties are used.
|
|
11
11
|
*/
|
|
12
|
-
export
|
|
12
|
+
export type WithPrecisionColumnType = "float" | "double" | "dec" | "decimal" | "smalldecimal" | "fixed" | "numeric" | "real" | "double precision" | "number" | "datetime" | "datetime2" | "datetimeoffset" | "time" | "time with time zone" | "time without time zone" | "timestamp" | "timestamp without time zone" | "timestamp with time zone" | "timestamp with local time zone";
|
|
13
13
|
/**
|
|
14
14
|
* Column types where column length is used.
|
|
15
15
|
*/
|
|
16
|
-
export
|
|
17
|
-
export
|
|
16
|
+
export type WithLengthColumnType = "character varying" | "varying character" | "char varying" | "nvarchar" | "national varchar" | "character" | "native character" | "varchar" | "char" | "nchar" | "national char" | "varchar2" | "nvarchar2" | "alphanum" | "shorttext" | "raw" | "binary" | "varbinary" | "string";
|
|
17
|
+
export type WithWidthColumnType = "tinyint" | "smallint" | "mediumint" | "int" | "bigint";
|
|
18
18
|
/**
|
|
19
19
|
* All other regular column types.
|
|
20
20
|
*/
|
|
21
|
-
export
|
|
21
|
+
export type SimpleColumnType = "simple-array" | "simple-json" | "simple-enum" | "int2" | "integer" | "int4" | "int8" | "int64" | "unsigned big int" | "float" | "float4" | "float8" | "smallmoney" | "money" | "boolean" | "bool" | "tinyblob" | "tinytext" | "mediumblob" | "mediumtext" | "blob" | "text" | "ntext" | "citext" | "hstore" | "longblob" | "longtext" | "alphanum" | "shorttext" | "bytes" | "bytea" | "long" | "raw" | "long raw" | "bfile" | "clob" | "nclob" | "image" | "timetz" | "timestamptz" | "timestamp with local time zone" | "smalldatetime" | "date" | "interval year to month" | "interval day to second" | "interval" | "year" | "seconddate" | "point" | "line" | "lseg" | "box" | "circle" | "path" | "polygon" | "geography" | "geometry" | "linestring" | "multipoint" | "multilinestring" | "multipolygon" | "geometrycollection" | "st_geometry" | "st_point" | "int4range" | "int8range" | "numrange" | "tsrange" | "tstzrange" | "daterange" | "enum" | "set" | "cidr" | "inet" | "macaddr" | "bit" | "bit varying" | "varbit" | "tsvector" | "tsquery" | "uuid" | "xml" | "json" | "jsonb" | "varbinary" | "hierarchyid" | "sql_variant" | "rowid" | "urowid" | "uniqueidentifier" | "rowversion" | "array" | "cube" | "ltree" | "object" | "array" | "function" | "sequence";
|
|
22
22
|
/**
|
|
23
23
|
* Any column type column can be.
|
|
24
24
|
*/
|
|
25
|
-
export
|
|
25
|
+
export type DataType = WithPrecisionColumnType | WithLengthColumnType | WithWidthColumnType | SpatialColumnType | SimpleColumnType;
|
|
26
26
|
export interface DataTypeParams {
|
|
27
27
|
length?: number;
|
|
28
28
|
width?: number;
|
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { IncomingHttpHeaders } from "http";
|
|
3
|
-
import { AsyncContext, AsyncRowStore } from '../store/AsyncRowStore';
|
|
4
3
|
import { SyncContext } from '../store/SyncRowStore';
|
|
5
|
-
import { Connector, EntityDict, OakException } from "../types";
|
|
6
|
-
|
|
4
|
+
import { Connector, EntityDict, OakException, OpRecord } from "../types";
|
|
5
|
+
type ServerOption = {
|
|
6
|
+
protocol: string;
|
|
7
|
+
hostname: string;
|
|
8
|
+
port?: number;
|
|
9
|
+
apiPath?: string;
|
|
10
|
+
};
|
|
11
|
+
export declare class SimpleConnector<ED extends EntityDict, FrontCxt extends SyncContext<ED>> implements Connector<ED, FrontCxt> {
|
|
7
12
|
static ASPECT_ROUTER: string;
|
|
8
13
|
static BRIDGE_ROUTER: string;
|
|
14
|
+
static SUBSCRIBE_ROUTER: string;
|
|
15
|
+
static SUBSCRIBE_POINT_ROUTER: string;
|
|
16
|
+
static ENDPOINT_ROUTER: string;
|
|
9
17
|
private serverAspectUrl;
|
|
10
18
|
private serverBridgeUrl;
|
|
19
|
+
private serverSubscribePointUrl;
|
|
20
|
+
private option;
|
|
11
21
|
private makeException;
|
|
12
|
-
|
|
13
|
-
constructor(serverUrl: string, makeException: (exceptionData: any) => OakException<ED>, contextBuilder: (str: string | undefined) => (store: AsyncRowStore<ED, BackCxt>) => Promise<BackCxt>);
|
|
22
|
+
constructor(option: ServerOption, makeException: (exceptionData: any) => OakException<ED>);
|
|
14
23
|
callAspect(name: string, params: any, context: FrontCxt): Promise<{
|
|
15
24
|
result: any;
|
|
16
25
|
opRecords: any;
|
|
@@ -21,12 +30,18 @@ export declare class SimpleConnector<ED extends EntityDict, BackCxt extends Asyn
|
|
|
21
30
|
opRecords?: undefined;
|
|
22
31
|
}>;
|
|
23
32
|
getRouter(): string;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
33
|
+
getSubscribeRouter(): string;
|
|
34
|
+
getSubscribePointRouter(): string;
|
|
35
|
+
getSubscribePoint(): Promise<{
|
|
36
|
+
url: any;
|
|
37
|
+
path: any;
|
|
28
38
|
}>;
|
|
29
|
-
|
|
39
|
+
getEndpointRouter(): string;
|
|
40
|
+
parseRequestHeaders(headers: IncomingHttpHeaders): {
|
|
41
|
+
contextString: string | undefined;
|
|
42
|
+
aspectName: string;
|
|
43
|
+
};
|
|
44
|
+
serializeResult(result: any, opRecords: OpRecord<ED>[], headers: IncomingHttpHeaders, body: any, message?: string): Promise<{
|
|
30
45
|
body: any;
|
|
31
46
|
headers?: Record<string, any> | undefined;
|
|
32
47
|
}>;
|
|
@@ -46,3 +61,4 @@ export declare class SimpleConnector<ED extends EntityDict, BackCxt extends Asyn
|
|
|
46
61
|
headers?: Record<string, string> | undefined;
|
|
47
62
|
};
|
|
48
63
|
}
|
|
64
|
+
export {};
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SimpleConnector = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
6
|
+
const stream_1 = require("stream");
|
|
7
|
+
const url_1 = tslib_1.__importDefault(require("url"));
|
|
8
|
+
const types_1 = require("../types");
|
|
9
9
|
function makeContentTypeAndBody(data) {
|
|
10
|
-
//
|
|
11
10
|
if (process.env.OAK_PLATFORM !== 'wechatMp') {
|
|
12
11
|
if (data instanceof FormData) {
|
|
13
12
|
return {
|
|
@@ -21,160 +20,187 @@ function makeContentTypeAndBody(data) {
|
|
|
21
20
|
body: JSON.stringify(data),
|
|
22
21
|
};
|
|
23
22
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
class SimpleConnector {
|
|
24
|
+
static ASPECT_ROUTER = '/aspect';
|
|
25
|
+
static BRIDGE_ROUTER = '/bridge';
|
|
26
|
+
static SUBSCRIBE_ROUTER = '/subscribe';
|
|
27
|
+
static SUBSCRIBE_POINT_ROUTER = '/subscribePoint';
|
|
28
|
+
static ENDPOINT_ROUTER = '/endpoint';
|
|
29
|
+
serverAspectUrl;
|
|
30
|
+
serverBridgeUrl;
|
|
31
|
+
serverSubscribePointUrl;
|
|
32
|
+
option;
|
|
33
|
+
makeException;
|
|
34
|
+
constructor(option, makeException) {
|
|
35
|
+
this.option = option;
|
|
36
|
+
const { protocol, hostname, port, apiPath } = option;
|
|
37
|
+
let serverUrl = `${protocol}//${hostname}`;
|
|
38
|
+
if (typeof port === 'number') {
|
|
39
|
+
serverUrl += `:${port}`;
|
|
40
|
+
}
|
|
41
|
+
if (apiPath) {
|
|
42
|
+
(0, assert_1.default)(apiPath.startsWith('/'), 'apiPath前缀必须存在/');
|
|
43
|
+
serverUrl += apiPath;
|
|
44
|
+
}
|
|
45
|
+
this.serverAspectUrl = `${serverUrl}${SimpleConnector.ASPECT_ROUTER}`;
|
|
46
|
+
this.serverBridgeUrl = `${serverUrl}${SimpleConnector.BRIDGE_ROUTER}`;
|
|
47
|
+
this.serverSubscribePointUrl = `${serverUrl}${SimpleConnector.SUBSCRIBE_POINT_ROUTER}`;
|
|
48
|
+
this.makeException = makeException;
|
|
33
49
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
'Content-Type': contentType,
|
|
49
|
-
}),
|
|
50
|
-
body: body,
|
|
51
|
-
})];
|
|
52
|
-
case 1:
|
|
53
|
-
response = _c.sent();
|
|
54
|
-
if (response.status > 299) {
|
|
55
|
-
err = new types_1.OakExternalException("\u7F51\u7EDC\u8BF7\u6C42\u8FD4\u56DE\u5F02\u5E38\uFF0Cstatus\u662F".concat(response.status));
|
|
56
|
-
throw err;
|
|
57
|
-
}
|
|
58
|
-
message = response.headers.get('oak-message');
|
|
59
|
-
responseType = response.headers.get('Content-Type') || response.headers.get('content-type');
|
|
60
|
-
if (!(responseType === null || responseType === void 0 ? void 0 : responseType.toLocaleLowerCase().match(/application\/json/i))) return [3 /*break*/, 3];
|
|
61
|
-
return [4 /*yield*/, response.json()];
|
|
62
|
-
case 2:
|
|
63
|
-
_b = _c.sent(), exception = _b.exception, result = _b.result, opRecords = _b.opRecords;
|
|
64
|
-
if (exception) {
|
|
65
|
-
throw this.makeException(exception);
|
|
66
|
-
}
|
|
67
|
-
return [2 /*return*/, {
|
|
68
|
-
result: result,
|
|
69
|
-
opRecords: opRecords,
|
|
70
|
-
message: message,
|
|
71
|
-
}];
|
|
72
|
-
case 3:
|
|
73
|
-
if (!(responseType === null || responseType === void 0 ? void 0 : responseType.toLocaleLowerCase().match(/application\/octet-stream/i))) return [3 /*break*/, 5];
|
|
74
|
-
return [4 /*yield*/, response.arrayBuffer()];
|
|
75
|
-
case 4:
|
|
76
|
-
result = _c.sent();
|
|
77
|
-
return [2 /*return*/, {
|
|
78
|
-
result: result,
|
|
79
|
-
message: message,
|
|
80
|
-
}];
|
|
81
|
-
case 5: throw new Error("\u5C1A\u4E0D\u652F\u6301\u7684content-type\u7C7B\u578B".concat(responseType));
|
|
82
|
-
}
|
|
50
|
+
async callAspect(name, params, context) {
|
|
51
|
+
const cxtStr = context.toString();
|
|
52
|
+
const { contentType, body } = makeContentTypeAndBody(params);
|
|
53
|
+
let response;
|
|
54
|
+
try {
|
|
55
|
+
response = await global.fetch(this.serverAspectUrl, {
|
|
56
|
+
method: 'POST',
|
|
57
|
+
headers: Object.assign({
|
|
58
|
+
'oak-cxt': cxtStr,
|
|
59
|
+
'oak-aspect': name,
|
|
60
|
+
}, contentType && {
|
|
61
|
+
'Content-Type': contentType,
|
|
62
|
+
}),
|
|
63
|
+
body,
|
|
83
64
|
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
65
|
+
}
|
|
66
|
+
catch (err) {
|
|
67
|
+
// fetch返回异常一定是网络异常
|
|
68
|
+
throw new types_1.OakNetworkException();
|
|
69
|
+
}
|
|
70
|
+
if (response.status > 299) {
|
|
71
|
+
const err = new types_1.OakServerProxyException(`网络请求返回status是${response.status}`);
|
|
72
|
+
throw err;
|
|
73
|
+
}
|
|
74
|
+
const message = response.headers.get('oak-message');
|
|
75
|
+
const responseType = response.headers.get('Content-Type') ||
|
|
76
|
+
response.headers.get('content-type');
|
|
77
|
+
if (responseType?.toLocaleLowerCase().match(/application\/json/i)) {
|
|
78
|
+
const { exception, result, opRecords } = await response.json();
|
|
79
|
+
if (exception) {
|
|
80
|
+
throw this.makeException(exception);
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
result,
|
|
84
|
+
opRecords,
|
|
85
|
+
message,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
else if (responseType
|
|
89
|
+
?.toLocaleLowerCase()
|
|
90
|
+
.match(/application\/octet-stream/i)) {
|
|
91
|
+
const result = await response.arrayBuffer();
|
|
92
|
+
return {
|
|
93
|
+
result,
|
|
94
|
+
message,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
throw new Error(`尚不支持的content-type类型${responseType}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
getRouter() {
|
|
87
102
|
return SimpleConnector.ASPECT_ROUTER;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
103
|
+
}
|
|
104
|
+
getSubscribeRouter() {
|
|
105
|
+
return SimpleConnector.SUBSCRIBE_ROUTER;
|
|
106
|
+
}
|
|
107
|
+
getSubscribePointRouter() {
|
|
108
|
+
return SimpleConnector.SUBSCRIBE_POINT_ROUTER;
|
|
109
|
+
}
|
|
110
|
+
async getSubscribePoint() {
|
|
111
|
+
let response;
|
|
112
|
+
try {
|
|
113
|
+
response = await global.fetch(this.serverSubscribePointUrl);
|
|
114
|
+
}
|
|
115
|
+
catch (err) {
|
|
116
|
+
throw new types_1.OakNetworkException();
|
|
117
|
+
}
|
|
118
|
+
if (response.status > 299) {
|
|
119
|
+
const err = new types_1.OakServerProxyException(`网络请求返回status是${response.status}`);
|
|
120
|
+
throw err;
|
|
121
|
+
}
|
|
122
|
+
const message = response.headers.get('oak-message');
|
|
123
|
+
const responseType = response.headers.get('Content-Type') ||
|
|
124
|
+
response.headers.get('content-type');
|
|
125
|
+
if (responseType?.toLocaleLowerCase().match(/application\/json/i)) {
|
|
126
|
+
const { url, path, port, namespace } = await response.json();
|
|
127
|
+
let url2 = url || `${this.option.protocol}//${this.option.hostname}`;
|
|
128
|
+
(0, assert_1.default)(port);
|
|
129
|
+
url2 += `:${port}`;
|
|
130
|
+
if (namespace) {
|
|
131
|
+
url2 += namespace;
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
url: url2,
|
|
135
|
+
path,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
throw new Error(`尚不支持的content-type类型${responseType}`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
getEndpointRouter() {
|
|
143
|
+
return SimpleConnector.ENDPOINT_ROUTER;
|
|
144
|
+
}
|
|
145
|
+
parseRequestHeaders(headers) {
|
|
146
|
+
const { 'oak-cxt': oakCxtStr, 'oak-aspect': aspectName } = headers;
|
|
147
|
+
(0, assert_1.default)(typeof oakCxtStr === 'string' || oakCxtStr === undefined);
|
|
148
|
+
(0, assert_1.default)(typeof aspectName === 'string');
|
|
149
|
+
return {
|
|
150
|
+
contextString: oakCxtStr,
|
|
151
|
+
aspectName,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
async serializeResult(result, opRecords, headers, body, message) {
|
|
155
|
+
if (result instanceof stream_1.Stream || result instanceof Buffer) {
|
|
156
|
+
return {
|
|
157
|
+
body: result,
|
|
158
|
+
headers: {
|
|
159
|
+
'oak-message': message,
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
body: {
|
|
165
|
+
result,
|
|
166
|
+
opRecords,
|
|
167
|
+
},
|
|
168
|
+
headers: {
|
|
169
|
+
'oak-message': message,
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
serializeException(exception, headers, body) {
|
|
138
174
|
return {
|
|
139
175
|
body: {
|
|
140
176
|
exception: exception.toString(),
|
|
141
177
|
},
|
|
142
178
|
};
|
|
143
|
-
}
|
|
144
|
-
|
|
179
|
+
}
|
|
180
|
+
getBridgeRouter() {
|
|
145
181
|
return SimpleConnector.BRIDGE_ROUTER;
|
|
146
|
-
}
|
|
182
|
+
}
|
|
147
183
|
/**
|
|
148
184
|
* 通过本地服务器桥接访问外部资源的url
|
|
149
185
|
* @param url
|
|
150
186
|
* @param headers
|
|
151
187
|
*/
|
|
152
|
-
|
|
188
|
+
makeBridgeUrl(url, headers) {
|
|
153
189
|
// if (process.env.PROD !== 'true') {
|
|
154
190
|
// console.warn('在development下无法通过bridge访问资源,将直接访问,可能失败', url);
|
|
155
191
|
// return url;
|
|
156
192
|
// }
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
// }
|
|
165
|
-
return "".concat(this.serverBridgeUrl, "?url=").concat(encodeUrl);
|
|
166
|
-
};
|
|
167
|
-
SimpleConnector.prototype.parseBridgeRequestQuery = function (urlParams) {
|
|
168
|
-
var search = new url_1.default.URLSearchParams(urlParams);
|
|
169
|
-
var url = search.get('url');
|
|
170
|
-
var headers = search.get('headers');
|
|
193
|
+
const encodeUrl = encodeURIComponent(url);
|
|
194
|
+
return `${this.serverBridgeUrl}?url=${encodeUrl}`;
|
|
195
|
+
}
|
|
196
|
+
parseBridgeRequestQuery(urlParams) {
|
|
197
|
+
const search = new url_1.default.URLSearchParams(urlParams);
|
|
198
|
+
const url = search.get('url');
|
|
199
|
+
const headers = search.get('headers');
|
|
171
200
|
return {
|
|
172
|
-
url
|
|
201
|
+
url,
|
|
173
202
|
headers: headers && JSON.parse(headers),
|
|
174
203
|
};
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
SimpleConnector.BRIDGE_ROUTER = '/bridge';
|
|
178
|
-
return SimpleConnector;
|
|
179
|
-
}(types_1.Connector));
|
|
204
|
+
}
|
|
205
|
+
}
|
|
180
206
|
exports.SimpleConnector = SimpleConnector;
|
package/lib/utils/assert.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.assert = void 0;
|
|
4
|
-
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
5
|
/**
|
|
6
6
|
* 防止assert打包体积过大,从这里引用
|
|
7
7
|
*/
|
|
8
|
-
|
|
8
|
+
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
9
9
|
exports.assert = assert_1.default;
|