适配新的声明
This commit is contained in:
parent
447eedfedc
commit
10f677a26d
|
|
@ -1,14 +1,16 @@
|
|||
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
||||
import { AppLoader as GeneralAppLoader, RowStore, Context, EntityDict } from "oak-domain/lib/types";
|
||||
import { AppLoader as GeneralAppLoader, EntityDict } from "oak-domain/lib/types";
|
||||
import { DbStore } from "./DbStore";
|
||||
import { MySQLConfiguration } from 'oak-db/lib/MySQL/types/Configuration';
|
||||
export declare class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>> extends GeneralAppLoader<ED, Cxt> {
|
||||
import { AsyncContext } from "oak-domain/lib/store/AsyncRowStore";
|
||||
export declare class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>> extends GeneralAppLoader<ED, Cxt> {
|
||||
private dbStore;
|
||||
private aspectDict;
|
||||
private contextBuilder;
|
||||
constructor(path: string, contextBuilder: (scene?: string) => (store: RowStore<ED, Cxt>) => Promise<Cxt>, dbConfig: MySQLConfiguration);
|
||||
constructor(path: string, contextBuilder: (scene?: string) => (store: DbStore<ED, Cxt>) => Promise<Cxt>, dbConfig: MySQLConfiguration);
|
||||
mount(initialize?: true): Promise<void>;
|
||||
unmount(): Promise<void>;
|
||||
execAspect(name: string, context: Cxt, params?: any): Promise<any>;
|
||||
initialize(dropIfExists?: boolean): Promise<void>;
|
||||
getStore(): RowStore<ED, Cxt>;
|
||||
getStore(): DbStore<ED, Cxt>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,15 @@
|
|||
import { MysqlStore, MySqlSelectOption, MysqlOperateOption } from 'oak-db';
|
||||
import { EntityDict, Context, StorageSchema, SelectionResult, Trigger, Checker, SelectRowShape, RowStore } from 'oak-domain/lib/types';
|
||||
import { EntityDict, StorageSchema, Trigger, Checker } from 'oak-domain/lib/types';
|
||||
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
||||
import { MySQLConfiguration } from 'oak-db/lib/MySQL/types/Configuration';
|
||||
export declare class DbStore<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>> extends MysqlStore<ED, Cxt> {
|
||||
import { AsyncContext, AsyncRowStore } from 'oak-domain/lib/store/AsyncRowStore';
|
||||
export declare class DbStore<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>> extends MysqlStore<ED, Cxt> implements AsyncRowStore<ED, Cxt> {
|
||||
private executor;
|
||||
constructor(storageSchema: StorageSchema<ED>, contextBuilder: (scene?: string) => (store: RowStore<ED, Cxt>) => Promise<Cxt>, mysqlConfiguration: MySQLConfiguration);
|
||||
protected cascadeUpdate<T extends keyof ED>(entity: T, operation: ED[T]['Create'] | ED[T]['Update'] | ED[T]['Remove'], context: Cxt, option: MysqlOperateOption): Promise<import("oak-domain/lib/types").OperationResult<ED>>;
|
||||
protected cascadeSelect<T extends keyof ED, S extends ED[T]["Selection"]>(entity: T, selection: S, context: Cxt, option: MySqlSelectOption): Promise<SelectRowShape<ED[T]['Schema'], S['data']>[]>;
|
||||
constructor(storageSchema: StorageSchema<ED>, contextBuilder: (scene?: string) => (store: DbStore<ED, Cxt>) => Promise<AsyncContext<ED>>, mysqlConfiguration: MySQLConfiguration);
|
||||
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>>;
|
||||
protected cascadeSelectAsync<T extends keyof ED>(entity: T, selection: ED[T]["Selection"], context: AsyncContext<ED>, option: MySqlSelectOption): Promise<Partial<ED[T]['Schema']>[]>;
|
||||
operate<T extends keyof ED>(entity: T, operation: ED[T]['Operation'], context: Cxt, option: MysqlOperateOption): Promise<import("oak-domain/lib/types").OperationResult<ED>>;
|
||||
select<T extends keyof ED, S extends ED[T]['Selection']>(entity: T, selection: S, context: Cxt, option: MySqlSelectOption): Promise<SelectionResult<ED[T]["Schema"], S["data"]>>;
|
||||
select<T extends keyof ED>(entity: T, selection: ED[T]['Selection'], context: Cxt, option: MySqlSelectOption): Promise<Partial<ED[T]["Schema"]>[]>;
|
||||
registerTrigger<T extends keyof ED>(trigger: Trigger<ED, T, Cxt>): void;
|
||||
registerChecker<T extends keyof ED>(checker: Checker<ED, T, Cxt>): void;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,24 +9,24 @@ class DbStore extends oak_db_1.MysqlStore {
|
|||
super(storageSchema, mysqlConfiguration);
|
||||
this.executor = new TriggerExecutor_1.TriggerExecutor((scene) => contextBuilder(scene)(this));
|
||||
}
|
||||
async cascadeUpdate(entity, operation, context, option) {
|
||||
async cascadeUpdateAsync(entity, operation, context, option) {
|
||||
if (!option.blockTrigger) {
|
||||
await this.executor.preOperation(entity, operation, context, option);
|
||||
}
|
||||
const result = super.cascadeUpdate(entity, operation, context, option);
|
||||
const result = super.cascadeUpdateAsync(entity, operation, context, option);
|
||||
if (!option.blockTrigger) {
|
||||
await this.executor.postOperation(entity, operation, context, option);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
async cascadeSelect(entity, selection, context, option) {
|
||||
async cascadeSelectAsync(entity, selection, context, option) {
|
||||
const selection2 = Object.assign({
|
||||
action: 'select',
|
||||
}, selection);
|
||||
if (!option.blockTrigger) {
|
||||
await this.executor.preOperation(entity, selection2, context, option);
|
||||
}
|
||||
const result = await super.cascadeSelect(entity, selection2, context, option);
|
||||
const result = await super.cascadeSelectAsync(entity, selection2, context, option);
|
||||
if (!option.blockTrigger) {
|
||||
await this.executor.postOperation(entity, selection2, context, option, result);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,8 +6,9 @@ import { AppLoader as GeneralAppLoader, Trigger, Checker, Aspect, RowStore, Cont
|
|||
import { DbStore } from "./DbStore";
|
||||
import generalAspectDict from 'oak-common-aspect/lib/index';
|
||||
import { MySQLConfiguration } from 'oak-db/lib/MySQL/types/Configuration';
|
||||
import { AsyncContext } from "oak-domain/lib/store/AsyncRowStore";
|
||||
|
||||
function initTriggers<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>>(dbStore: DbStore<ED, Cxt>, path: string) {
|
||||
function initTriggers<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>>(dbStore: DbStore<ED, Cxt>, path: string) {
|
||||
const { triggers } = require(`${path}/lib/triggers/index`);
|
||||
const { checkers } = require(`${path}/lib/checkers/index`);
|
||||
const { ActionDefDict } = require(`${path}/lib/oak-app-domain/ActionDefDict`);
|
||||
|
|
@ -38,11 +39,11 @@ function initTriggers<ED extends EntityDict & BaseEntityDict, Cxt extends Contex
|
|||
}
|
||||
|
||||
|
||||
export class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>> extends GeneralAppLoader<ED, Cxt> {
|
||||
export class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>> extends GeneralAppLoader<ED, Cxt> {
|
||||
private dbStore: DbStore<ED, Cxt>;
|
||||
private aspectDict: Record<string, Aspect<ED, Cxt>>;
|
||||
private contextBuilder: (scene?: string) => (store: RowStore<ED, Cxt>) => Promise<Cxt>;
|
||||
constructor(path: string, contextBuilder: (scene?: string) => (store: RowStore<ED, Cxt>) => Promise<Cxt>, dbConfig: MySQLConfiguration) {
|
||||
private contextBuilder: (scene?: string) => (store: DbStore<ED, Cxt>) => Promise<Cxt>;
|
||||
constructor(path: string, contextBuilder: (scene?: string) => (store: DbStore<ED, Cxt>) => Promise<Cxt>, dbConfig: MySQLConfiguration) {
|
||||
super(path);
|
||||
const { storageSchema } = require(`${path}/lib/oak-app-domain/Storage`);
|
||||
this.aspectDict = Object.assign({}, generalAspectDict, require(`${path}/lib/aspects/index`).aspectDict);
|
||||
|
|
@ -95,7 +96,7 @@ export class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt extends Conte
|
|||
this.dbStore.disconnect();
|
||||
}
|
||||
|
||||
getStore(): RowStore<ED, Cxt> {
|
||||
getStore(): DbStore<ED, Cxt> {
|
||||
return this.dbStore;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,31 +1,32 @@
|
|||
import { MysqlStore, MySqlSelectOption, MysqlOperateOption } from 'oak-db';
|
||||
import { EntityDict, Context, StorageSchema, SelectionResult, Trigger, Checker, SelectRowShape, RowStore } from 'oak-domain/lib/types';
|
||||
import { EntityDict, Context, StorageSchema, Trigger, Checker, RowStore } from 'oak-domain/lib/types';
|
||||
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
||||
import { TriggerExecutor } from 'oak-domain/lib/store/TriggerExecutor';
|
||||
import { MySQLConfiguration, } from 'oak-db/lib/MySQL/types/Configuration';
|
||||
import { AsyncContext, AsyncRowStore } from 'oak-domain/lib/store/AsyncRowStore';
|
||||
|
||||
|
||||
export class DbStore<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>> extends MysqlStore<ED, Cxt> {
|
||||
private executor: TriggerExecutor<ED, Cxt>;
|
||||
export class DbStore<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>> extends MysqlStore<ED, Cxt> implements AsyncRowStore<ED, Cxt> {
|
||||
private executor: TriggerExecutor<ED>;
|
||||
|
||||
constructor(storageSchema: StorageSchema<ED>, contextBuilder: (scene?: string) => (store: RowStore<ED, Cxt>) => Promise<Cxt>, mysqlConfiguration: MySQLConfiguration) {
|
||||
constructor(storageSchema: StorageSchema<ED>, contextBuilder: (scene?: string) => (store: DbStore<ED, Cxt>) => Promise<AsyncContext<ED>>, mysqlConfiguration: MySQLConfiguration) {
|
||||
super(storageSchema, mysqlConfiguration);
|
||||
this.executor = new TriggerExecutor((scene) => contextBuilder(scene)(this));
|
||||
}
|
||||
|
||||
|
||||
protected async cascadeUpdate<T extends keyof ED>(entity: T, operation: ED[T]['Create'] | ED[T]['Update'] | ED[T]['Remove'], context: Cxt, option: MysqlOperateOption) {
|
||||
protected async cascadeUpdateAsync<T extends keyof ED>(entity: T, operation: ED[T]['Operation'], context: AsyncContext<ED>, option: MysqlOperateOption) {
|
||||
if (!option.blockTrigger) {
|
||||
await this.executor.preOperation(entity, operation, context, option);
|
||||
}
|
||||
const result = super.cascadeUpdate(entity, operation, context, option);
|
||||
const result = super.cascadeUpdateAsync(entity, operation, context, option);
|
||||
if (!option.blockTrigger) {
|
||||
await this.executor.postOperation(entity, operation, context, option);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected async cascadeSelect<T extends keyof ED, S extends ED[T]["Selection"]>(entity: T, selection: S, context: Cxt, option: MySqlSelectOption): Promise<SelectRowShape<ED[T]['Schema'], S['data']>[]> {
|
||||
protected async cascadeSelectAsync<T extends keyof ED>(entity: T, selection: ED[T]["Selection"], context: AsyncContext<ED>, option: MySqlSelectOption): Promise<Partial<ED[T]['Schema']>[]> {
|
||||
const selection2 = Object.assign({
|
||||
action: 'select',
|
||||
}, selection) as ED[T]['Operation'];
|
||||
|
|
@ -33,7 +34,7 @@ export class DbStore<ED extends EntityDict & BaseEntityDict, Cxt extends Context
|
|||
if (!option.blockTrigger) {
|
||||
await this.executor.preOperation(entity, selection2, context, option);
|
||||
}
|
||||
const result = await super.cascadeSelect(entity, selection2 as any, context, option);
|
||||
const result = await super.cascadeSelectAsync(entity, selection2, context, option);
|
||||
if (!option.blockTrigger) {
|
||||
await this.executor.postOperation(entity, selection2, context, option, result);
|
||||
}
|
||||
|
|
@ -64,9 +65,9 @@ export class DbStore<ED extends EntityDict & BaseEntityDict, Cxt extends Context
|
|||
return result;
|
||||
}
|
||||
|
||||
async select<T extends keyof ED, S extends ED[T]['Selection']>(
|
||||
async select<T extends keyof ED>(
|
||||
entity: T,
|
||||
selection: S,
|
||||
selection: ED[T]['Selection'],
|
||||
context: Cxt,
|
||||
option: MySqlSelectOption
|
||||
) {
|
||||
|
|
@ -74,7 +75,7 @@ export class DbStore<ED extends EntityDict & BaseEntityDict, Cxt extends Context
|
|||
if (autoCommit) {
|
||||
await context.begin();
|
||||
}
|
||||
let result: SelectionResult<ED[T]['Schema'], S['data']>;
|
||||
let result: Partial<ED[T]['Schema']>[];
|
||||
|
||||
try {
|
||||
result = await super.select(entity, selection, context, option);
|
||||
|
|
|
|||
Loading…
Reference in New Issue