适配了domain的相关变化

This commit is contained in:
Xu Chang 2023-07-25 14:50:21 +08:00
parent dfd7a8f18a
commit bd62c3ce23
4 changed files with 8 additions and 24 deletions

View File

@ -7,8 +7,6 @@ const path_1 = require("path");
const node_schedule_1 = require("node-schedule"); const node_schedule_1 = require("node-schedule");
const actionDef_1 = require("oak-domain/lib/store/actionDef"); const actionDef_1 = require("oak-domain/lib/store/actionDef");
const lodash_1 = require("oak-domain/lib/utils/lodash"); const lodash_1 = require("oak-domain/lib/utils/lodash");
const checkers_1 = require("oak-domain/lib/checkers");
const triggers_1 = require("oak-domain/lib/triggers");
const uuid_1 = require("oak-domain/lib/utils/uuid"); const uuid_1 = require("oak-domain/lib/utils/uuid");
const types_1 = require("oak-domain/lib/types"); const types_1 = require("oak-domain/lib/types");
const DbStore_1 = require("./DbStore"); const DbStore_1 = require("./DbStore");
@ -86,20 +84,16 @@ class AppLoader extends types_1.AppLoader {
const checkers = this.requireSth('lib/checkers/index'); const checkers = this.requireSth('lib/checkers/index');
const authDict = this.requireSth('lib/auth/index'); const authDict = this.requireSth('lib/auth/index');
const { ActionDefDict } = require(`${this.path}/lib/oak-app-domain/ActionDefDict`); const { ActionDefDict } = require(`${this.path}/lib/oak-app-domain/ActionDefDict`);
const { triggers: adTriggers, checkers: adCheckers } = (0, actionDef_1.analyzeActionDefDict)(this.dbStore.getSchema(), ActionDefDict); const { triggers: adTriggers, checkers: adCheckers } = (0, actionDef_1.makeIntrinsicCTWs)(this.dbStore.getSchema(), ActionDefDict);
triggers.forEach((trigger) => this.dbStore.registerTrigger(trigger)); triggers.forEach((trigger) => this.dbStore.registerTrigger(trigger));
adTriggers.forEach((trigger) => this.dbStore.registerTrigger(trigger)); adTriggers.forEach((trigger) => this.dbStore.registerTrigger(trigger));
checkers.forEach((checker) => this.dbStore.registerChecker(checker)); checkers.forEach((checker) => this.dbStore.registerChecker(checker));
adCheckers.forEach((checker) => this.dbStore.registerChecker(checker)); adCheckers.forEach((checker) => this.dbStore.registerChecker(checker));
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));
} }
startWatchers() { startWatchers() {
const watchers = this.requireSth('lib/watchers/index'); const watchers = this.requireSth('lib/watchers/index');
const { ActionDefDict } = require(`${this.path}/lib/oak-app-domain/ActionDefDict`); const { ActionDefDict } = require(`${this.path}/lib/oak-app-domain/ActionDefDict`);
const { watchers: adWatchers } = (0, actionDef_1.analyzeActionDefDict)(this.dbStore.getSchema(), ActionDefDict); const { watchers: adWatchers } = (0, actionDef_1.makeIntrinsicCTWs)(this.dbStore.getSchema(), ActionDefDict);
const totalWatchers = watchers.concat(adWatchers); const totalWatchers = watchers.concat(adWatchers);
let count = 0; let count = 0;
const doWatchers = async () => { const doWatchers = async () => {

View File

@ -16,7 +16,6 @@ class DbStore extends oak_db_1.MysqlStore {
if (!option.blockTrigger) { if (!option.blockTrigger) {
await this.executor.preOperation(entity, operation, context, option); await this.executor.preOperation(entity, operation, context, option);
} }
await this.relationAuth.checkRelationAsync(entity, operation, context);
const result = await super.cascadeUpdateAsync(entity, operation, context, option); const result = await super.cascadeUpdateAsync(entity, operation, context, option);
if (!option.blockTrigger) { if (!option.blockTrigger) {
await this.executor.postOperation(entity, operation, context, option); await this.executor.postOperation(entity, operation, context, option);
@ -30,6 +29,7 @@ class DbStore extends oak_db_1.MysqlStore {
await context.begin(); await context.begin();
} }
try { try {
await this.relationAuth.checkRelationAsync(entity, operation, context);
result = await super.operate(entity, operation, context, option); result = await super.operate(entity, operation, context, option);
} }
catch (err) { catch (err) {

View File

@ -1,7 +1,7 @@
import { existsSync } from 'fs'; import { existsSync } from 'fs';
import { join } from 'path'; import { join } from 'path';
import { scheduleJob } from 'node-schedule'; import { scheduleJob } from 'node-schedule';
import { analyzeActionDefDict } from "oak-domain/lib/store/actionDef"; import { makeIntrinsicCTWs } from "oak-domain/lib/store/actionDef";
import { intersection } from 'oak-domain/lib/utils/lodash'; import { intersection } from 'oak-domain/lib/utils/lodash';
import { createDynamicCheckers } from 'oak-domain/lib/checkers'; import { createDynamicCheckers } from 'oak-domain/lib/checkers';
import { createDynamicTriggers } from 'oak-domain/lib/triggers'; import { createDynamicTriggers } from 'oak-domain/lib/triggers';
@ -106,7 +106,7 @@ export class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt extends Async
const authDict = this.requireSth('lib/auth/index'); const authDict = this.requireSth('lib/auth/index');
const { ActionDefDict } = require(`${this.path}/lib/oak-app-domain/ActionDefDict`); const { ActionDefDict } = require(`${this.path}/lib/oak-app-domain/ActionDefDict`);
const { triggers: adTriggers, checkers: adCheckers } = analyzeActionDefDict(this.dbStore.getSchema(), ActionDefDict); const { triggers: adTriggers, checkers: adCheckers } = makeIntrinsicCTWs(this.dbStore.getSchema(), ActionDefDict);
triggers.forEach( triggers.forEach(
(trigger: Trigger<ED, keyof ED, Cxt>) => this.dbStore.registerTrigger(trigger) (trigger: Trigger<ED, keyof ED, Cxt>) => this.dbStore.registerTrigger(trigger)
); );
@ -118,24 +118,14 @@ export class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt extends Async
); );
adCheckers.forEach( adCheckers.forEach(
(checker) => this.dbStore.registerChecker(checker) (checker) => this.dbStore.registerChecker(checker)
); );
const dynamicCheckers = createDynamicCheckers(this.dbStore.getSchema());
dynamicCheckers.forEach(
(checker) => this.dbStore.registerChecker(checker)
);
const dynamicTriggers = createDynamicTriggers(this.dbStore.getSchema());
dynamicTriggers.forEach(
(trigger) => this.dbStore.registerTrigger(trigger)
);
} }
startWatchers() { startWatchers() {
const watchers = this.requireSth('lib/watchers/index'); const watchers = this.requireSth('lib/watchers/index');
const { ActionDefDict } = require(`${this.path}/lib/oak-app-domain/ActionDefDict`); const { ActionDefDict } = require(`${this.path}/lib/oak-app-domain/ActionDefDict`);
const { watchers: adWatchers } = analyzeActionDefDict(this.dbStore.getSchema(), ActionDefDict); const { watchers: adWatchers } = makeIntrinsicCTWs(this.dbStore.getSchema(), ActionDefDict);
const totalWatchers = (<Watcher<ED, keyof ED, Cxt>[]>watchers).concat(adWatchers); const totalWatchers = (<Watcher<ED, keyof ED, Cxt>[]>watchers).concat(adWatchers);
let count = 0; let count = 0;

View File

@ -28,7 +28,6 @@ export class DbStore<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncCo
if (!option.blockTrigger) { if (!option.blockTrigger) {
await this.executor.preOperation(entity, operation, context, option); await this.executor.preOperation(entity, operation, context, option);
} }
await this.relationAuth.checkRelationAsync(entity, operation, context);
const result = await super.cascadeUpdateAsync(entity, operation, context, option); const result = await super.cascadeUpdateAsync(entity, operation, context, option);
if (!option.blockTrigger) { if (!option.blockTrigger) {
await this.executor.postOperation(entity, operation, context, option); await this.executor.postOperation(entity, operation, context, option);
@ -48,6 +47,7 @@ export class DbStore<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncCo
await context.begin(); await context.begin();
} }
try { try {
await this.relationAuth.checkRelationAsync(entity, operation, context);
result = await super.operate(entity, operation, context, option); result = await super.operate(entity, operation, context, option);
} }
catch (err) { catch (err) {