1.0.2发布前修改依赖
This commit is contained in:
parent
05371da3cc
commit
a7c2d98d42
|
|
@ -1,6 +1,7 @@
|
|||
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
||||
import { AppLoader as GeneralAppLoader, RowStore, Context, EntityDict } from "oak-domain/lib/types";
|
||||
import { MySQLConfiguration } from 'oak-db/lib/MySQL/types/Configuration';
|
||||
export declare class AppLoader<ED extends EntityDict, Cxt extends Context<ED>> extends GeneralAppLoader<ED, Cxt> {
|
||||
export declare class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>> extends GeneralAppLoader<ED, Cxt> {
|
||||
private dbStore;
|
||||
private aspectDict;
|
||||
private contextBuilder;
|
||||
|
|
|
|||
|
|
@ -58,7 +58,10 @@ class AppLoader extends types_1.AppLoader {
|
|||
await this.dbStore.operate(entity, {
|
||||
data: rows,
|
||||
action: 'create',
|
||||
}, context);
|
||||
}, context, {
|
||||
dontCollect: true,
|
||||
dontCreateOper: true,
|
||||
});
|
||||
console.log(`data in ${entity} initialized!`);
|
||||
}
|
||||
await context.commit();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { RowStore } from 'oak-domain/lib/types';
|
||||
import { GeneralRuntimeContext } from 'oak-general-business';
|
||||
import { EntityDict } from 'oak-general-business/lib/general-app-domain';
|
||||
export declare class Context<ED extends EntityDict> extends GeneralRuntimeContext<ED> {
|
||||
static FromCxtStr(cxtStr?: string): <ED extends EntityDict>(store: RowStore<ED, Context<ED>>) => Context<ED>;
|
||||
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
||||
export declare class Context<ED extends EntityDict & BaseEntityDict> extends GeneralRuntimeContext<ED> {
|
||||
static FromCxtStr(cxtStr?: string): <ED extends EntityDict & BaseEntityDict>(store: RowStore<ED, Context<ED>>) => Context<ED>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
import { MysqlStore, MySqlSelectOption, MysqlOperateOption } from 'oak-db';
|
||||
import { EntityDict, Context, StorageSchema, SelectionResult, Trigger, Checker, SelectRowShape, RowStore } 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, Cxt extends Context<ED>> extends MysqlStore<ED, Cxt> {
|
||||
export declare class DbStore<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>> extends MysqlStore<ED, Cxt> {
|
||||
private executor;
|
||||
constructor(storageSchema: StorageSchema<ED>, contextBuilder: (scene?: string) => (store: RowStore<ED, Cxt>) => 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']>[]>;
|
||||
operate<T extends keyof ED>(entity: T, operation: ED[T]['Operation'], context: Cxt, params?: 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, params?: MySqlSelectOption): Promise<SelectionResult<ED[T]["Schema"], S["data"]>>;
|
||||
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']>[]>;
|
||||
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"]>>;
|
||||
registerTrigger<T extends keyof ED>(trigger: Trigger<ED, T, Cxt>): void;
|
||||
registerChecker<T extends keyof ED>(checker: Checker<ED, T, Cxt>): void;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,32 +10,36 @@ class DbStore extends oak_db_1.MysqlStore {
|
|||
this.executor = new TriggerExecutor_1.TriggerExecutor(async (scene) => contextBuilder(scene)(this));
|
||||
}
|
||||
async cascadeUpdate(entity, operation, context, option) {
|
||||
await this.executor.preOperation(entity, operation, context, option);
|
||||
if (!option.blockTrigger) {
|
||||
await this.executor.preOperation(entity, operation, context, option);
|
||||
}
|
||||
const result = super.cascadeUpdate(entity, operation, context, option);
|
||||
await this.executor.postOperation(entity, operation, context, option);
|
||||
if (!option.blockTrigger) {
|
||||
await this.executor.postOperation(entity, operation, context, option);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
async cascadeSelect(entity, selection, context, option) {
|
||||
const selection2 = Object.assign({
|
||||
action: 'select',
|
||||
}, selection);
|
||||
if (!option?.ignoreTrigger) {
|
||||
if (!option.blockTrigger) {
|
||||
await this.executor.preOperation(entity, selection2, context, option);
|
||||
}
|
||||
const result = await super.cascadeSelect(entity, selection2, context, option);
|
||||
if (!option?.ignoreTrigger) {
|
||||
if (!option.blockTrigger) {
|
||||
await this.executor.postOperation(entity, selection2, context, option, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
async operate(entity, operation, context, params) {
|
||||
async operate(entity, operation, context, option) {
|
||||
const autoCommit = !context.getCurrentTxnId();
|
||||
let result;
|
||||
if (autoCommit) {
|
||||
await context.begin();
|
||||
}
|
||||
try {
|
||||
result = await super.operate(entity, operation, context, params);
|
||||
result = await super.operate(entity, operation, context, option);
|
||||
}
|
||||
catch (err) {
|
||||
await context.rollback();
|
||||
|
|
@ -46,14 +50,14 @@ class DbStore extends oak_db_1.MysqlStore {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
async select(entity, selection, context, params) {
|
||||
async select(entity, selection, context, option) {
|
||||
const autoCommit = !context.getCurrentTxnId();
|
||||
if (autoCommit) {
|
||||
await context.begin();
|
||||
}
|
||||
let result;
|
||||
try {
|
||||
result = await super.select(entity, selection, context, params);
|
||||
result = await super.select(entity, selection, context, option);
|
||||
}
|
||||
catch (err) {
|
||||
await context.rollback();
|
||||
|
|
|
|||
|
|
@ -20,10 +20,10 @@
|
|||
"lodash": "^4.17.21",
|
||||
"mysql": "^2.18.1",
|
||||
"mysql2": "^2.3.3",
|
||||
"oak-db": "file:../oak-db",
|
||||
"oak-domain": "file:../oak-domain",
|
||||
"oak-general-business": "file:../oak-general-business",
|
||||
"oak-common-aspect": "file:../oak-common-aspect",
|
||||
"oak-db": "^1.0.2",
|
||||
"oak-domain": "^1.1.0",
|
||||
"oak-general-business": "^1.0.5",
|
||||
"oak-common-aspect": "^1.0.3",
|
||||
"uuid": "^8.3.2"
|
||||
},
|
||||
"license": "ISC",
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import { analyzeActionDefDict } from "oak-domain/lib/store/actionDef";
|
||||
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
||||
import { AppLoader as GeneralAppLoader, Trigger, Checker, Aspect, RowStore, Context, EntityDict } from "oak-domain/lib/types";
|
||||
import { DbStore } from "./DbStore";
|
||||
import generalAspectDict from 'oak-common-aspect/lib/index';
|
||||
import { MySQLConfiguration } from 'oak-db/lib/MySQL/types/Configuration';
|
||||
|
||||
function initTriggers<ED extends EntityDict, Cxt extends Context<ED>>(dbStore: DbStore<ED, Cxt>, path: string) {
|
||||
function initTriggers<ED extends EntityDict & BaseEntityDict, Cxt extends Context<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`);
|
||||
|
|
@ -25,7 +26,7 @@ function initTriggers<ED extends EntityDict, Cxt extends Context<ED>>(dbStore: D
|
|||
}
|
||||
|
||||
|
||||
export class AppLoader<ED extends EntityDict, Cxt extends Context<ED>> extends GeneralAppLoader<ED, Cxt> {
|
||||
export class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt extends Context<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>) => Cxt;
|
||||
|
|
@ -72,7 +73,10 @@ export class AppLoader<ED extends EntityDict, Cxt extends Context<ED>> extends G
|
|||
await this.dbStore.operate(entity as keyof ED, {
|
||||
data: rows,
|
||||
action: 'create',
|
||||
} as any, context);
|
||||
} as any, context, {
|
||||
dontCollect: true,
|
||||
dontCreateOper: true,
|
||||
});
|
||||
console.log(`data in ${entity} initialized!`);
|
||||
}
|
||||
await context.commit();
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
import { RowStore } from 'oak-domain/lib/types';
|
||||
import { GeneralRuntimeContext } from 'oak-general-business';
|
||||
import { EntityDict } from 'oak-general-business/lib/general-app-domain';
|
||||
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
||||
|
||||
export class Context<ED extends EntityDict> extends GeneralRuntimeContext<ED> {
|
||||
export class Context<ED extends EntityDict & BaseEntityDict> extends GeneralRuntimeContext<ED> {
|
||||
static FromCxtStr(cxtStr?: string){
|
||||
const {
|
||||
token,
|
||||
|
|
@ -13,7 +14,7 @@ export class Context<ED extends EntityDict> extends GeneralRuntimeContext<ED> {
|
|||
applicationId: undefined,
|
||||
scene: undefined,
|
||||
};
|
||||
return <ED extends EntityDict>(store: RowStore<ED, Context<ED>>) => {
|
||||
return <ED extends EntityDict & BaseEntityDict>(store: RowStore<ED, Context<ED>>) => {
|
||||
const context = new Context<ED>(store, applicationId);
|
||||
context.setScene(scene);
|
||||
context.setToken(token);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import { MysqlStore, MySqlSelectOption, MysqlOperateOption } from 'oak-db';
|
||||
import { EntityDict, Context, StorageSchema, OperateOption, SelectionResult, Trigger, Checker, SelectRowShape, RowStore } from 'oak-domain/lib/types';
|
||||
import { EntityDict, Context, StorageSchema, SelectionResult, Trigger, Checker, SelectRowShape, 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';
|
||||
|
||||
|
||||
export class DbStore<ED extends EntityDict, Cxt extends Context<ED>> extends MysqlStore<ED, Cxt> {
|
||||
export class DbStore<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>> extends MysqlStore<ED, Cxt> {
|
||||
private executor: TriggerExecutor<ED, Cxt>;
|
||||
|
||||
constructor(storageSchema: StorageSchema<ED>, contextBuilder: (scene?: string) => (store: RowStore<ED, Cxt>) => Cxt, mysqlConfiguration: MySQLConfiguration) {
|
||||
|
|
@ -13,23 +14,27 @@ export class DbStore<ED extends EntityDict, Cxt extends Context<ED>> extends Mys
|
|||
}
|
||||
|
||||
|
||||
protected async cascadeUpdate<T extends keyof ED>(entity: T, operation: ED[T]['Create'] | ED[T]['Update'] | ED[T]['Remove'], context: Cxt, option?: MysqlOperateOption) {
|
||||
await this.executor.preOperation(entity, operation, context, option);
|
||||
protected async cascadeUpdate<T extends keyof ED>(entity: T, operation: ED[T]['Create'] | ED[T]['Update'] | ED[T]['Remove'], context: Cxt, option: MysqlOperateOption) {
|
||||
if (!option.blockTrigger) {
|
||||
await this.executor.preOperation(entity, operation, context, option);
|
||||
}
|
||||
const result = super.cascadeUpdate(entity, operation, context, option);
|
||||
await this.executor.postOperation(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 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']>[]> {
|
||||
const selection2 = Object.assign({
|
||||
action: 'select',
|
||||
}, selection) as ED[T]['Operation'];
|
||||
|
||||
if (!option?.ignoreTrigger) {
|
||||
if (!option.blockTrigger) {
|
||||
await this.executor.preOperation(entity, selection2, context, option);
|
||||
}
|
||||
const result = await super.cascadeSelect(entity, selection2 as any, context, option);
|
||||
if (!option?.ignoreTrigger) {
|
||||
if (!option.blockTrigger) {
|
||||
await this.executor.postOperation(entity, selection2, context, option, result);
|
||||
}
|
||||
return result;
|
||||
|
|
@ -39,7 +44,7 @@ export class DbStore<ED extends EntityDict, Cxt extends Context<ED>> extends Mys
|
|||
entity: T,
|
||||
operation: ED[T]['Operation'],
|
||||
context: Cxt,
|
||||
params?: MysqlOperateOption
|
||||
option: MysqlOperateOption
|
||||
) {
|
||||
const autoCommit = !context.getCurrentTxnId();
|
||||
let result;
|
||||
|
|
@ -47,7 +52,7 @@ export class DbStore<ED extends EntityDict, Cxt extends Context<ED>> extends Mys
|
|||
await context.begin();
|
||||
}
|
||||
try {
|
||||
result = await super.operate(entity, operation, context, params);
|
||||
result = await super.operate(entity, operation, context, option);
|
||||
}
|
||||
catch (err) {
|
||||
await context.rollback();
|
||||
|
|
@ -63,7 +68,7 @@ export class DbStore<ED extends EntityDict, Cxt extends Context<ED>> extends Mys
|
|||
entity: T,
|
||||
selection: S,
|
||||
context: Cxt,
|
||||
params?: MySqlSelectOption
|
||||
option: MySqlSelectOption
|
||||
) {
|
||||
const autoCommit = !context.getCurrentTxnId();
|
||||
if (autoCommit) {
|
||||
|
|
@ -72,7 +77,7 @@ export class DbStore<ED extends EntityDict, Cxt extends Context<ED>> extends Mys
|
|||
let result: SelectionResult<ED[T]['Schema'], S['data']>;
|
||||
|
||||
try {
|
||||
result = await super.select(entity, selection, context, params);
|
||||
result = await super.select(entity, selection, context, option);
|
||||
}
|
||||
catch (err) {
|
||||
await context.rollback();
|
||||
|
|
|
|||
Loading…
Reference in New Issue