适配新的改动
This commit is contained in:
parent
1794923682
commit
dfd7a8f18a
|
|
@ -41,21 +41,44 @@ class AppLoader extends types_1.AppLoader {
|
|||
const inter = (0, lodash_1.intersection)(Object.keys(sthOut), Object.keys(sth2));
|
||||
if (inter.length > 0) {
|
||||
console.warn(`${(0, path_1.join)(this.path, 'node_modules', this.externalDependencies[idx], filePath)}中的default输出对象中的key值【${inter.join(',')}】与其它对应路径输出的key值有冲突,请仔细检查避免错误`);
|
||||
inter.forEach((ele) => {
|
||||
if (sth2[ele] instanceof Array && sthOut[ele]) {
|
||||
(0, assert_1.default)(sthOut[ele] instanceof Array, `${(0, path_1.join)(this.path, 'node_modules', this.externalDependencies[idx], filePath)}中的default输出对象的${ele}键值是数组,但之前的相应对象的${ele}却不是,请仔细检查以避免错误`);
|
||||
console.warn(`${(0, path_1.join)(this.path, 'node_modules', this.externalDependencies[idx], filePath)}中的default输出对象中的key值【${ele}】与其它对应路径输出的key值【${ele}】将以数组格式进行合并,请仔细检查避免错误`);
|
||||
sth2[ele].push(...sthOut[ele]);
|
||||
}
|
||||
else if (!(sth2[ele] instanceof Array) && sthOut[ele]) {
|
||||
(0, assert_1.default)(!(sthOut[ele] instanceof Array), `${(0, path_1.join)(this.path, 'node_modules', this.externalDependencies[idx], filePath)}中的default输出对象的${ele}键值不是数组,但之前的相应对象的${ele}却是,请仔细检查以避免错误`);
|
||||
console.warn(`${(0, path_1.join)(this.path, 'node_modules', this.externalDependencies[idx], filePath)}中的default输出对象中的key值【${ele}】将对与其它对应路径输出的key值【${ele}】进行覆盖,请仔细检查避免错误`);
|
||||
}
|
||||
});
|
||||
}
|
||||
Object.assign(sthOut, sth2);
|
||||
});
|
||||
const inter = (0, lodash_1.intersection)(Object.keys(sthOut), Object.keys(sth));
|
||||
(0, assert_1.default)(inter.length === 0, `项目${filePath}中的default输出与第三方库中的输出在键值${inter.join(',')}上冲突,请处理`);
|
||||
if (inter.length > 0) {
|
||||
inter.forEach((ele) => {
|
||||
if (sth[ele] instanceof Array && sthOut[ele]) {
|
||||
(0, assert_1.default)(sthOut[ele] instanceof Array, `项目${filePath}中的default输出对象的${ele}键值是数组,但之前的相应对象的${ele}却不是,请仔细检查以避免错误`);
|
||||
console.warn(`项目${filePath}中的default输出对象中的key值【${ele}】与其它引用包该路径输出的key值【${ele}】将以数组格式进行合并,请仔细检查避免错误`);
|
||||
sth[ele].push(...sthOut[ele]);
|
||||
}
|
||||
else if (!(sth[ele] instanceof Array) && sthOut[ele]) {
|
||||
(0, assert_1.default)(!(sthOut[ele] instanceof Array), `项目${filePath}中的default输出对象的${ele}键值不是数组,但之前的相应对象的${ele}却是,请仔细检查以避免错误`);
|
||||
console.warn(`项目${filePath}中的default输出对象中的key值【${ele}】将对其它引用包该路径输出的key值【${ele}】进行覆盖,请仔细检查避免错误`);
|
||||
}
|
||||
});
|
||||
}
|
||||
Object.assign(sthOut, sth);
|
||||
return sthOut;
|
||||
}
|
||||
constructor(path, contextBuilder, dbConfig) {
|
||||
super(path);
|
||||
const { storageSchema } = require(`${path}/lib/oak-app-domain/Storage`);
|
||||
const { ActionCascadePathGraph, RelationCascadePathGraph } = require(`${path}/lib/oak-app-domain/Relation`);
|
||||
const { ActionCascadePathGraph, RelationCascadePathGraph, selectFreeEntities, deducedRelationMap } = require(`${path}/lib/oak-app-domain/Relation`);
|
||||
this.externalDependencies = require(`${path}/lib/config/externalDependencies`).default;
|
||||
this.aspectDict = Object.assign({}, index_1.default, this.requireSth('lib/aspects/index'));
|
||||
this.dbStore = new DbStore_1.DbStore(storageSchema, contextBuilder, dbConfig, ActionCascadePathGraph, RelationCascadePathGraph);
|
||||
this.dbStore = new DbStore_1.DbStore(storageSchema, contextBuilder, dbConfig, ActionCascadePathGraph, RelationCascadePathGraph, deducedRelationMap, selectFreeEntities);
|
||||
this.contextBuilder = contextBuilder;
|
||||
}
|
||||
initTriggers() {
|
||||
|
|
@ -68,8 +91,7 @@ class AppLoader extends types_1.AppLoader {
|
|||
adTriggers.forEach((trigger) => this.dbStore.registerTrigger(trigger));
|
||||
checkers.forEach((checker) => this.dbStore.registerChecker(checker));
|
||||
adCheckers.forEach((checker) => this.dbStore.registerChecker(checker));
|
||||
// todo cascadeRemoveTrigger要挪到Schema定义里
|
||||
const dynamicCheckers = (0, checkers_1.createDynamicCheckers)(this.dbStore.getSchema(), {});
|
||||
const dynamicCheckers = (0, checkers_1.createDynamicCheckers)(this.dbStore.getSchema());
|
||||
dynamicCheckers.forEach((checker) => this.dbStore.registerChecker(checker));
|
||||
const dynamicTriggers = (0, triggers_1.createDynamicTriggers)(this.dbStore.getSchema());
|
||||
dynamicTriggers.forEach((trigger) => this.dbStore.registerTrigger(trigger));
|
||||
|
|
|
|||
|
|
@ -1,16 +1,12 @@
|
|||
import { MysqlStore, MySqlSelectOption, MysqlOperateOption } from 'oak-db';
|
||||
import { EntityDict, StorageSchema, Trigger, Checker, SelectOption, AuthCascadePath } from 'oak-domain/lib/types';
|
||||
import { EntityDict, StorageSchema, Trigger, Checker, AuthDeduceRelationMap, SelectOption, AuthCascadePath } 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';
|
||||
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;
|
||||
private relationAuth;
|
||||
constructor(storageSchema: StorageSchema<ED>, contextBuilder: (scene?: string) => (store: DbStore<ED, Cxt>) => Promise<Cxt>, mysqlConfiguration: MySQLConfiguration, actionCascadeGraph: AuthCascadePath<ED>[], relationCascadeGraph: AuthCascadePath<ED>[]);
|
||||
/**
|
||||
* relationAuth中需要缓存一些维表的数据
|
||||
*/
|
||||
private initRelationAuthTriggers;
|
||||
constructor(storageSchema: StorageSchema<ED>, contextBuilder: (scene?: string) => (store: DbStore<ED, Cxt>) => Promise<Cxt>, mysqlConfiguration: MySQLConfiguration, actionCascadeGraph: AuthCascadePath<ED>[], relationCascadeGraph: AuthCascadePath<ED>[], authDeduceRelationMap: AuthDeduceRelationMap<ED>, selectFreeEntities: (keyof ED)[]);
|
||||
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>>;
|
||||
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>(entity: T, selection: ED[T]['Selection'], context: Cxt, option: MySqlSelectOption): Promise<Partial<ED[T]["Schema"]>[]>;
|
||||
|
|
|
|||
|
|
@ -7,42 +7,10 @@ const RelationAuth_1 = require("oak-domain/lib/store/RelationAuth");
|
|||
class DbStore extends oak_db_1.MysqlStore {
|
||||
executor;
|
||||
relationAuth;
|
||||
constructor(storageSchema, contextBuilder, mysqlConfiguration, actionCascadeGraph, relationCascadeGraph) {
|
||||
constructor(storageSchema, contextBuilder, mysqlConfiguration, actionCascadeGraph, relationCascadeGraph, authDeduceRelationMap, selectFreeEntities) {
|
||||
super(storageSchema, mysqlConfiguration);
|
||||
this.executor = new TriggerExecutor_1.TriggerExecutor((scene) => contextBuilder(scene)(this));
|
||||
this.relationAuth = new RelationAuth_1.RelationAuth(actionCascadeGraph, relationCascadeGraph, storageSchema);
|
||||
this.initRelationAuthTriggers(contextBuilder);
|
||||
}
|
||||
/**
|
||||
* relationAuth中需要缓存一些维表的数据
|
||||
*/
|
||||
async initRelationAuthTriggers(contextBuilder) {
|
||||
const context = await contextBuilder()(this);
|
||||
const freeActionAuths = await this.select('freeActionAuth', {
|
||||
data: {
|
||||
id: 1,
|
||||
deActions: 1,
|
||||
destEntity: 1,
|
||||
},
|
||||
}, context, {
|
||||
dontCollect: true,
|
||||
});
|
||||
this.relationAuth.setFreeActionAuths(freeActionAuths);
|
||||
const directActionAuths = await this.select('directActionAuth', {
|
||||
data: {
|
||||
id: 1,
|
||||
rootEntity: 1,
|
||||
path: 1,
|
||||
deActions: 1,
|
||||
destEntity: 1,
|
||||
},
|
||||
}, context, {
|
||||
dontCollect: true,
|
||||
});
|
||||
this.relationAuth.setDirectionActionAuths(directActionAuths);
|
||||
await context.commit();
|
||||
const triggers = this.relationAuth.getAuthDataTriggers();
|
||||
triggers.forEach((trigger) => this.registerTrigger(trigger));
|
||||
this.relationAuth = new RelationAuth_1.RelationAuth(storageSchema, actionCascadeGraph, relationCascadeGraph, authDeduceRelationMap, selectFreeEntities);
|
||||
}
|
||||
async cascadeUpdateAsync(entity, operation, context, option) {
|
||||
if (!option.blockTrigger) {
|
||||
|
|
@ -83,10 +51,12 @@ class DbStore extends oak_db_1.MysqlStore {
|
|||
Object.assign(selection, {
|
||||
action: 'select',
|
||||
});
|
||||
await this.relationAuth.checkRelationAsync(entity, selection, context);
|
||||
if (!option.blockTrigger) {
|
||||
await this.executor.preOperation(entity, selection, context, option);
|
||||
}
|
||||
if (!option.dontCollect) {
|
||||
await this.relationAuth.checkRelationAsync(entity, selection, context);
|
||||
}
|
||||
try {
|
||||
result = await super.select(entity, selection, context, option);
|
||||
if (!option.blockTrigger) {
|
||||
|
|
|
|||
|
|
@ -93,10 +93,10 @@ export class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt extends Async
|
|||
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`);
|
||||
const { ActionCascadePathGraph, RelationCascadePathGraph } = require(`${path}/lib/oak-app-domain/Relation`);
|
||||
const { ActionCascadePathGraph, RelationCascadePathGraph, selectFreeEntities, deducedRelationMap } = require(`${path}/lib/oak-app-domain/Relation`);
|
||||
this.externalDependencies = require(`${path}/lib/config/externalDependencies`).default;
|
||||
this.aspectDict = Object.assign({}, generalAspectDict, this.requireSth('lib/aspects/index'));
|
||||
this.dbStore = new DbStore<ED, Cxt>(storageSchema, contextBuilder, dbConfig, ActionCascadePathGraph, RelationCascadePathGraph);
|
||||
this.dbStore = new DbStore<ED, Cxt>(storageSchema, contextBuilder, dbConfig, ActionCascadePathGraph, RelationCascadePathGraph, deducedRelationMap, selectFreeEntities);
|
||||
this.contextBuilder = contextBuilder;
|
||||
}
|
||||
|
||||
|
|
@ -120,8 +120,7 @@ export class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt extends Async
|
|||
(checker) => this.dbStore.registerChecker(checker)
|
||||
);
|
||||
|
||||
// todo cascadeRemoveTrigger要挪到Schema定义里
|
||||
const dynamicCheckers = createDynamicCheckers(this.dbStore.getSchema(), {});
|
||||
const dynamicCheckers = createDynamicCheckers(this.dbStore.getSchema());
|
||||
dynamicCheckers.forEach(
|
||||
(checker) => this.dbStore.registerChecker(checker)
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { MysqlStore, MySqlSelectOption, MysqlOperateOption } from 'oak-db';
|
||||
import { EntityDict, Context, StorageSchema, Trigger, Checker, RowStore, SelectOption, AuthCascadePath } from 'oak-domain/lib/types';
|
||||
import { EntityDict, Context, StorageSchema, Trigger, Checker, AuthDeduceRelationMap, SelectOption, AuthCascadePath } 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';
|
||||
|
|
@ -16,50 +16,12 @@ export class DbStore<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncCo
|
|||
contextBuilder: (scene?: string) => (store: DbStore<ED, Cxt>) => Promise<Cxt>,
|
||||
mysqlConfiguration: MySQLConfiguration,
|
||||
actionCascadeGraph: AuthCascadePath<ED>[],
|
||||
relationCascadeGraph: AuthCascadePath<ED>[]) {
|
||||
relationCascadeGraph: AuthCascadePath<ED>[],
|
||||
authDeduceRelationMap: AuthDeduceRelationMap<ED>,
|
||||
selectFreeEntities: (keyof ED)[]) {
|
||||
super(storageSchema, mysqlConfiguration);
|
||||
this.executor = new TriggerExecutor((scene) => contextBuilder(scene)(this));
|
||||
this.relationAuth = new RelationAuth(actionCascadeGraph, relationCascadeGraph, storageSchema);
|
||||
this.initRelationAuthTriggers(contextBuilder);
|
||||
}
|
||||
|
||||
/**
|
||||
* relationAuth中需要缓存一些维表的数据
|
||||
*/
|
||||
private async initRelationAuthTriggers(contextBuilder: (scene?: string) => (store: DbStore<ED, Cxt>) => Promise<Cxt>) {
|
||||
const context = await contextBuilder()(this);
|
||||
await context.begin();
|
||||
|
||||
// 先direct后free,因为RelationAuth中会根据free判断是否完成
|
||||
const directActionAuths = await this.select('directActionAuth', {
|
||||
data: {
|
||||
id: 1,
|
||||
sourceEntity: 1,
|
||||
path: 1,
|
||||
deActions: 1,
|
||||
destEntity: 1,
|
||||
},
|
||||
}, context, {
|
||||
dontCollect: true,
|
||||
});
|
||||
this.relationAuth.setDirectionActionAuths(directActionAuths as ED['directActionAuth']['OpSchema'][]);
|
||||
const freeActionAuths = await this.select('freeActionAuth', {
|
||||
data: {
|
||||
id: 1,
|
||||
deActions: 1,
|
||||
destEntity: 1,
|
||||
},
|
||||
}, context, {
|
||||
dontCollect: true,
|
||||
});
|
||||
this.relationAuth.setFreeActionAuths(freeActionAuths as ED['freeActionAuth']['OpSchema'][]);
|
||||
|
||||
await context.commit();
|
||||
|
||||
const triggers = this.relationAuth.getAuthDataTriggers<Cxt>();
|
||||
triggers.forEach(
|
||||
(trigger) => this.registerTrigger(trigger)
|
||||
);
|
||||
this.relationAuth = new RelationAuth(storageSchema, actionCascadeGraph, relationCascadeGraph, authDeduceRelationMap, selectFreeEntities);
|
||||
}
|
||||
|
||||
protected async cascadeUpdateAsync<T extends keyof ED>(entity: T, operation: ED[T]['Operation'], context: AsyncContext<ED>, option: MysqlOperateOption) {
|
||||
|
|
@ -114,10 +76,12 @@ export class DbStore<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncCo
|
|||
Object.assign(selection, {
|
||||
action: 'select',
|
||||
});
|
||||
await this.relationAuth.checkRelationAsync(entity, selection, context);
|
||||
if (!option.blockTrigger) {
|
||||
await this.executor.preOperation(entity, selection as ED[T]['Operation'], context, option);
|
||||
}
|
||||
if (!option.dontCollect) {
|
||||
await this.relationAuth.checkRelationAsync(entity, selection, context);
|
||||
}
|
||||
try {
|
||||
result = await super.select(entity, selection, context, option);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue