oak-backend-base 1.0.8 → 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/AppLoader.d.ts +6 -4
- package/lib/DbStore.d.ts +8 -6
- package/lib/DbStore.js +32 -4
- package/package.json +3 -3
package/lib/AppLoader.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
|
2
|
-
import { AppLoader as GeneralAppLoader,
|
|
2
|
+
import { AppLoader as GeneralAppLoader, EntityDict } from "oak-domain/lib/types";
|
|
3
|
+
import { DbStore } from "./DbStore";
|
|
3
4
|
import { MySQLConfiguration } from 'oak-db/lib/MySQL/types/Configuration';
|
|
4
|
-
|
|
5
|
+
import { AsyncContext } from "oak-domain/lib/store/AsyncRowStore";
|
|
6
|
+
export declare class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>> extends GeneralAppLoader<ED, Cxt> {
|
|
5
7
|
private dbStore;
|
|
6
8
|
private aspectDict;
|
|
7
9
|
private contextBuilder;
|
|
8
|
-
constructor(path: string, contextBuilder: (scene?: string) => (store:
|
|
10
|
+
constructor(path: string, contextBuilder: (scene?: string) => (store: DbStore<ED, Cxt>) => Promise<Cxt>, dbConfig: MySQLConfiguration);
|
|
9
11
|
mount(initialize?: true): Promise<void>;
|
|
10
12
|
unmount(): Promise<void>;
|
|
11
13
|
execAspect(name: string, context: Cxt, params?: any): Promise<any>;
|
|
12
14
|
initialize(dropIfExists?: boolean): Promise<void>;
|
|
13
|
-
getStore():
|
|
15
|
+
getStore(): DbStore<ED, Cxt>;
|
|
14
16
|
}
|
package/lib/DbStore.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { MysqlStore, MySqlSelectOption, MysqlOperateOption } from 'oak-db';
|
|
2
|
-
import { EntityDict,
|
|
2
|
+
import { EntityDict, StorageSchema, Trigger, Checker, SelectOption } from 'oak-domain/lib/types';
|
|
3
3
|
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
|
4
4
|
import { MySQLConfiguration } from 'oak-db/lib/MySQL/types/Configuration';
|
|
5
|
-
|
|
5
|
+
import { AsyncContext, AsyncRowStore } from 'oak-domain/lib/store/AsyncRowStore';
|
|
6
|
+
export declare class DbStore<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>> extends MysqlStore<ED, Cxt> implements AsyncRowStore<ED, Cxt> {
|
|
6
7
|
private executor;
|
|
7
|
-
constructor(storageSchema: StorageSchema<ED>, contextBuilder: (scene?: string) => (store:
|
|
8
|
-
protected
|
|
9
|
-
protected
|
|
8
|
+
constructor(storageSchema: StorageSchema<ED>, contextBuilder: (scene?: string) => (store: DbStore<ED, Cxt>) => Promise<AsyncContext<ED>>, mysqlConfiguration: MySQLConfiguration);
|
|
9
|
+
protected cascadeUpdateAsync<T extends keyof ED>(entity: T, operation: ED[T]['Operation'], context: AsyncContext<ED>, option: MysqlOperateOption): Promise<import("oak-domain/lib/types").OperationResult<ED>>;
|
|
10
|
+
protected cascadeSelectAsync<T extends keyof ED>(entity: T, selection: ED[T]["Selection"], context: AsyncContext<ED>, option: MySqlSelectOption): Promise<Partial<ED[T]['Schema']>[]>;
|
|
10
11
|
operate<T extends keyof ED>(entity: T, operation: ED[T]['Operation'], context: Cxt, option: MysqlOperateOption): Promise<import("oak-domain/lib/types").OperationResult<ED>>;
|
|
11
|
-
select<T extends keyof ED,
|
|
12
|
+
select<T extends keyof ED>(entity: T, selection: ED[T]['Selection'], context: Cxt, option: MySqlSelectOption): Promise<Partial<ED[T]["Schema"]>[]>;
|
|
13
|
+
count<T extends keyof ED>(entity: T, selection: Pick<ED[T]['Selection'], 'filter' | 'count'>, context: Cxt, option: SelectOption): Promise<number>;
|
|
12
14
|
registerTrigger<T extends keyof ED>(trigger: Trigger<ED, T, Cxt>): void;
|
|
13
15
|
registerChecker<T extends keyof ED>(checker: Checker<ED, T, Cxt>): void;
|
|
14
16
|
}
|
package/lib/DbStore.js
CHANGED
|
@@ -9,24 +9,24 @@ class DbStore extends oak_db_1.MysqlStore {
|
|
|
9
9
|
super(storageSchema, mysqlConfiguration);
|
|
10
10
|
this.executor = new TriggerExecutor_1.TriggerExecutor((scene) => contextBuilder(scene)(this));
|
|
11
11
|
}
|
|
12
|
-
async
|
|
12
|
+
async cascadeUpdateAsync(entity, operation, context, option) {
|
|
13
13
|
if (!option.blockTrigger) {
|
|
14
14
|
await this.executor.preOperation(entity, operation, context, option);
|
|
15
15
|
}
|
|
16
|
-
const result = super.
|
|
16
|
+
const result = super.cascadeUpdateAsync(entity, operation, context, option);
|
|
17
17
|
if (!option.blockTrigger) {
|
|
18
18
|
await this.executor.postOperation(entity, operation, context, option);
|
|
19
19
|
}
|
|
20
20
|
return result;
|
|
21
21
|
}
|
|
22
|
-
async
|
|
22
|
+
async cascadeSelectAsync(entity, selection, context, option) {
|
|
23
23
|
const selection2 = Object.assign({
|
|
24
24
|
action: 'select',
|
|
25
25
|
}, selection);
|
|
26
26
|
if (!option.blockTrigger) {
|
|
27
27
|
await this.executor.preOperation(entity, selection2, context, option);
|
|
28
28
|
}
|
|
29
|
-
const result = await super.
|
|
29
|
+
const result = await super.cascadeSelectAsync(entity, selection2, context, option);
|
|
30
30
|
if (!option.blockTrigger) {
|
|
31
31
|
await this.executor.postOperation(entity, selection2, context, option, result);
|
|
32
32
|
}
|
|
@@ -68,6 +68,34 @@ class DbStore extends oak_db_1.MysqlStore {
|
|
|
68
68
|
}
|
|
69
69
|
return result;
|
|
70
70
|
}
|
|
71
|
+
async count(entity, selection, context, option) {
|
|
72
|
+
const autoCommit = !context.getCurrentTxnId();
|
|
73
|
+
let result;
|
|
74
|
+
if (autoCommit) {
|
|
75
|
+
await context.begin();
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
const selection2 = Object.assign({
|
|
79
|
+
action: 'select',
|
|
80
|
+
}, selection);
|
|
81
|
+
if (!option.blockTrigger) {
|
|
82
|
+
await this.executor.preOperation(entity, selection2, context, option);
|
|
83
|
+
}
|
|
84
|
+
result = await super.count(entity, selection, context, option);
|
|
85
|
+
/* count应该不存在后trigger吧
|
|
86
|
+
if (!option.blockTrigger) {
|
|
87
|
+
await this.executor.postOperation(entity, selection2, context, option);
|
|
88
|
+
} */
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
await context.rollback();
|
|
92
|
+
throw err;
|
|
93
|
+
}
|
|
94
|
+
if (autoCommit) {
|
|
95
|
+
await context.commit();
|
|
96
|
+
}
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
71
99
|
registerTrigger(trigger) {
|
|
72
100
|
this.executor.registerTrigger(trigger);
|
|
73
101
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oak-backend-base",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "oak-backend-base",
|
|
5
5
|
"main": "lib/index",
|
|
6
6
|
"author": {
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"mysql": "^2.18.1",
|
|
20
20
|
"mysql2": "^2.3.3",
|
|
21
21
|
"oak-common-aspect": "1.0.5",
|
|
22
|
-
"oak-db": "^
|
|
23
|
-
"oak-domain": "^
|
|
22
|
+
"oak-db": "^2.0.2",
|
|
23
|
+
"oak-domain": "^2.0.1",
|
|
24
24
|
"uuid": "^8.3.2"
|
|
25
25
|
},
|
|
26
26
|
"license": "ISC",
|