From d9fe9f2e3c66ed573b296b4bc82fbf724097926a Mon Sep 17 00:00:00 2001 From: Xc Date: Wed, 20 Mar 2024 12:11:31 +0800 Subject: [PATCH] =?UTF-8?q?checkOperation=E4=BB=8D=E7=84=B6=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E8=BF=94=E5=9B=9EOakException?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- es/features/cache.d.ts | 3 ++- es/features/cache.js | 2 +- es/features/contextMenuFactory.js | 2 +- es/features/runningTree.js | 8 -------- es/page.mp.js | 5 +++-- es/page.react.d.ts | 4 ++-- es/page.react.js | 5 +++-- es/types/Page.d.ts | 6 +++--- lib/features/cache.d.ts | 3 ++- lib/features/cache.js | 2 +- lib/features/contextMenuFactory.js | 2 +- lib/features/runningTree.js | 8 -------- lib/page.mp.js | 5 +++-- lib/page.react.d.ts | 4 ++-- lib/page.react.js | 5 +++-- lib/types/Page.d.ts | 6 +++--- src/features/cache.ts | 2 +- src/features/contextMenuFactory.ts | 2 +- src/features/runningTree.ts | 9 --------- src/page.mp.ts | 5 +++-- src/page.react.tsx | 5 +++-- src/types/Page.ts | 6 +++--- 22 files changed, 41 insertions(+), 58 deletions(-) diff --git a/es/features/cache.d.ts b/es/features/cache.d.ts index 29af116d..99cbde1d 100644 --- a/es/features/cache.d.ts +++ b/es/features/cache.d.ts @@ -3,6 +3,7 @@ import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain'; import { CommonAspectDict } from 'oak-common-aspect'; import { Feature } from '../types/Feature'; import { CacheStore } from '../cacheStore/CacheStore'; +import { OakUserException } from 'oak-domain/lib/types/Exception'; import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore'; import { SyncContext } from 'oak-domain/lib/store/SyncRowStore'; import { LocalStorage } from './localStorage'; @@ -93,7 +94,7 @@ export declare class Cache; redoOperation(opers: Array<{ entity: keyof ED; operation: ED[keyof ED]['Operation']; diff --git a/es/features/cache.js b/es/features/cache.js index 5ae3d9af..5deeed00 100644 --- a/es/features/cache.js +++ b/es/features/cache.js @@ -349,7 +349,7 @@ export class Cache extends Feature { if (!(err instanceof OakUserException)) { throw err; } - return false; + return err; } } redoOperation(opers) { diff --git a/es/features/contextMenuFactory.js b/es/features/contextMenuFactory.js index 54ddd78e..c90910a8 100644 --- a/es/features/contextMenuFactory.js +++ b/es/features/contextMenuFactory.js @@ -108,7 +108,7 @@ export class ContextMenuFactory extends Feature { 'row', ]); if (checkResult) { - result = checkResult; + result = checkResult === true; break; } } diff --git a/es/features/runningTree.js b/es/features/runningTree.js index 78a37fdd..12caa555 100644 --- a/es/features/runningTree.js +++ b/es/features/runningTree.js @@ -1889,14 +1889,6 @@ export class RunningTree extends Feature { assert(node instanceof ListNode || node instanceof SingleNode); return node.getIntrinsticFilters(); } - /* tryExecute(path: string) { - const node = this.findNode(path); - const operations = node?.composeOperations(); - if (operations && operations.length > 0) { - return this.cache.tryRedoOperations(operations); - } - return false; - } */ getOperations(path) { const node = this.findNode(path); const operations = node?.composeOperations(); diff --git a/es/page.mp.js b/es/page.mp.js index 22009d50..48b41bef 100644 --- a/es/page.mp.js +++ b/es/page.mp.js @@ -217,8 +217,9 @@ const oakBehavior = Behavior({ if (operations) { for (const oper of operations) { const { entity, operation } = oper; - if (!this.checkOperation(entity, operation)) { - return false; + const result = this.checkOperation(entity, operation); + if (result !== true) { + return result; } } return true; diff --git a/es/page.react.d.ts b/es/page.react.d.ts index 4c159ae9..b5208236 100644 --- a/es/page.react.d.ts +++ b/es/page.react.d.ts @@ -77,8 +77,8 @@ export declare function createComponent; isDirty(path?: string | undefined): boolean; getFreshValue(path?: string | undefined): Partial | Partial[] | undefined; - checkOperation(entity: T2_2, operation: Omit, checkerTypes?: (CheckerType | "relation")[] | undefined): boolean; - tryExecute(path?: string | undefined): boolean; + checkOperation(entity: T2_2, operation: Omit, checkerTypes?: (CheckerType | "relation")[] | undefined): boolean | import("oak-domain/lib/types").OakUserException; + tryExecute(path?: string | undefined): boolean | import("oak-domain/lib/types").OakUserException; getOperations(path?: string | undefined): { entity: keyof ED; operation: ED[keyof ED]["Operation"]; diff --git a/es/page.react.js b/es/page.react.js index 30405386..45e24209 100644 --- a/es/page.react.js +++ b/es/page.react.js @@ -188,8 +188,9 @@ class OakComponentBase extends React.PureComponent { if (operations) { for (const oper of operations) { const { entity, operation } = oper; - if (!this.checkOperation(entity, operation)) { - return false; + const result = this.checkOperation(entity, operation); + if (result !== true) { + return result; } } return true; diff --git a/es/types/Page.d.ts b/es/types/Page.d.ts index bf470208..284fcd12 100644 --- a/es/types/Page.d.ts +++ b/es/types/Page.d.ts @@ -1,6 +1,6 @@ /// /// -import { Aspect, EntityDict, CheckerType, AggregationResult, OpRecord } from "oak-domain/lib/types"; +import { Aspect, EntityDict, CheckerType, AggregationResult, OpRecord, OakUserException } from "oak-domain/lib/types"; import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain'; import { CommonAspectDict } from 'oak-common-aspect'; import { Feature } from './Feature'; @@ -168,8 +168,8 @@ export type OakCommonComponentMethods boolean; - tryExecute: (path?: string) => boolean | Error; + }, checkerTypes?: (CheckerType | 'relation')[]) => boolean | OakUserException; + tryExecute: (path?: string) => boolean | OakUserException; getOperations: (path?: string) => { operation: ED[T]['Operation']; entity: T; diff --git a/lib/features/cache.d.ts b/lib/features/cache.d.ts index 29af116d..99cbde1d 100644 --- a/lib/features/cache.d.ts +++ b/lib/features/cache.d.ts @@ -3,6 +3,7 @@ import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain'; import { CommonAspectDict } from 'oak-common-aspect'; import { Feature } from '../types/Feature'; import { CacheStore } from '../cacheStore/CacheStore'; +import { OakUserException } from 'oak-domain/lib/types/Exception'; import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore'; import { SyncContext } from 'oak-domain/lib/store/SyncRowStore'; import { LocalStorage } from './localStorage'; @@ -93,7 +94,7 @@ export declare class Cache; redoOperation(opers: Array<{ entity: keyof ED; operation: ED[keyof ED]['Operation']; diff --git a/lib/features/cache.js b/lib/features/cache.js index ff2b3f16..ad4296ff 100644 --- a/lib/features/cache.js +++ b/lib/features/cache.js @@ -352,7 +352,7 @@ class Cache extends Feature_1.Feature { if (!(err instanceof Exception_1.OakUserException)) { throw err; } - return false; + return err; } } redoOperation(opers) { diff --git a/lib/features/contextMenuFactory.js b/lib/features/contextMenuFactory.js index 89c0b528..e0455cfa 100644 --- a/lib/features/contextMenuFactory.js +++ b/lib/features/contextMenuFactory.js @@ -111,7 +111,7 @@ class ContextMenuFactory extends Feature_1.Feature { 'row', ]); if (checkResult) { - result = checkResult; + result = checkResult === true; break; } } diff --git a/lib/features/runningTree.js b/lib/features/runningTree.js index 08183381..d6381151 100644 --- a/lib/features/runningTree.js +++ b/lib/features/runningTree.js @@ -1892,14 +1892,6 @@ class RunningTree extends Feature_1.Feature { (0, assert_1.assert)(node instanceof ListNode || node instanceof SingleNode); return node.getIntrinsticFilters(); } - /* tryExecute(path: string) { - const node = this.findNode(path); - const operations = node?.composeOperations(); - if (operations && operations.length > 0) { - return this.cache.tryRedoOperations(operations); - } - return false; - } */ getOperations(path) { const node = this.findNode(path); const operations = node?.composeOperations(); diff --git a/lib/page.mp.js b/lib/page.mp.js index d5101213..a325d6b7 100644 --- a/lib/page.mp.js +++ b/lib/page.mp.js @@ -220,8 +220,9 @@ const oakBehavior = Behavior({ if (operations) { for (const oper of operations) { const { entity, operation } = oper; - if (!this.checkOperation(entity, operation)) { - return false; + const result = this.checkOperation(entity, operation); + if (result !== true) { + return result; } } return true; diff --git a/lib/page.react.d.ts b/lib/page.react.d.ts index 4c159ae9..b5208236 100644 --- a/lib/page.react.d.ts +++ b/lib/page.react.d.ts @@ -77,8 +77,8 @@ export declare function createComponent; isDirty(path?: string | undefined): boolean; getFreshValue(path?: string | undefined): Partial | Partial[] | undefined; - checkOperation(entity: T2_2, operation: Omit, checkerTypes?: (CheckerType | "relation")[] | undefined): boolean; - tryExecute(path?: string | undefined): boolean; + checkOperation(entity: T2_2, operation: Omit, checkerTypes?: (CheckerType | "relation")[] | undefined): boolean | import("oak-domain/lib/types").OakUserException; + tryExecute(path?: string | undefined): boolean | import("oak-domain/lib/types").OakUserException; getOperations(path?: string | undefined): { entity: keyof ED; operation: ED[keyof ED]["Operation"]; diff --git a/lib/page.react.js b/lib/page.react.js index a824d930..843433ad 100644 --- a/lib/page.react.js +++ b/lib/page.react.js @@ -193,8 +193,9 @@ class OakComponentBase extends react_1.default.PureComponent { if (operations) { for (const oper of operations) { const { entity, operation } = oper; - if (!this.checkOperation(entity, operation)) { - return false; + const result = this.checkOperation(entity, operation); + if (result !== true) { + return result; } } return true; diff --git a/lib/types/Page.d.ts b/lib/types/Page.d.ts index bf470208..284fcd12 100644 --- a/lib/types/Page.d.ts +++ b/lib/types/Page.d.ts @@ -1,6 +1,6 @@ /// /// -import { Aspect, EntityDict, CheckerType, AggregationResult, OpRecord } from "oak-domain/lib/types"; +import { Aspect, EntityDict, CheckerType, AggregationResult, OpRecord, OakUserException } from "oak-domain/lib/types"; import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain'; import { CommonAspectDict } from 'oak-common-aspect'; import { Feature } from './Feature'; @@ -168,8 +168,8 @@ export type OakCommonComponentMethods boolean; - tryExecute: (path?: string) => boolean | Error; + }, checkerTypes?: (CheckerType | 'relation')[]) => boolean | OakUserException; + tryExecute: (path?: string) => boolean | OakUserException; getOperations: (path?: string) => { operation: ED[T]['Operation']; entity: T; diff --git a/src/features/cache.ts b/src/features/cache.ts index 21eac5ae..8048a76d 100644 --- a/src/features/cache.ts +++ b/src/features/cache.ts @@ -486,7 +486,7 @@ export class Cache< if (!(err instanceof OakUserException)) { throw err; } - return false; + return err as OakUserException; } } diff --git a/src/features/contextMenuFactory.ts b/src/features/contextMenuFactory.ts index dd8cc1c0..14fe9e94 100644 --- a/src/features/contextMenuFactory.ts +++ b/src/features/contextMenuFactory.ts @@ -174,7 +174,7 @@ export class ContextMenuFactory< ); if (checkResult) { - result = checkResult; + result = checkResult === true; break; } } diff --git a/src/features/runningTree.ts b/src/features/runningTree.ts index 22ea5c00..c4b5539a 100644 --- a/src/features/runningTree.ts +++ b/src/features/runningTree.ts @@ -2341,15 +2341,6 @@ export class RunningTree< return node.getIntrinsticFilters(); } - /* tryExecute(path: string) { - const node = this.findNode(path); - const operations = node?.composeOperations(); - if (operations && operations.length > 0) { - return this.cache.tryRedoOperations(operations); - } - return false; - } */ - getOperations(path: string) { const node = this.findNode(path); const operations = node?.composeOperations(); diff --git a/src/page.mp.ts b/src/page.mp.ts index 430e395d..5dd108e0 100644 --- a/src/page.mp.ts +++ b/src/page.mp.ts @@ -363,8 +363,9 @@ const oakBehavior = Behavior< if (operations) { for (const oper of operations) { const { entity, operation } = oper; - if (!this.checkOperation(entity, operation)) { - return false; + const result = this.checkOperation(entity, operation); + if (result !== true) { + return result; } } return true; diff --git a/src/page.react.tsx b/src/page.react.tsx index 384b5e69..678585f0 100644 --- a/src/page.react.tsx +++ b/src/page.react.tsx @@ -366,8 +366,9 @@ abstract class OakComponentBase< if (operations) { for (const oper of operations) { const { entity, operation } = oper; - if (!this.checkOperation(entity, operation)) { - return false; + const result = this.checkOperation(entity, operation); + if (result !== true) { + return result; } } return true; diff --git a/src/types/Page.ts b/src/types/Page.ts index d82f6e8f..dca01cac 100644 --- a/src/types/Page.ts +++ b/src/types/Page.ts @@ -1,4 +1,4 @@ -import { Aspect, EntityDict, CheckerType, AggregationResult, SubDataDef, OpRecord } from "oak-domain/lib/types"; +import { Aspect, EntityDict, CheckerType, AggregationResult, SubDataDef, OpRecord, OakUserException } from "oak-domain/lib/types"; import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain'; import { CommonAspectDict } from 'oak-common-aspect'; import { Feature } from './Feature'; @@ -397,8 +397,8 @@ export type OakCommonComponentMethods< filter?: ED[T2]['Operation']['filter'], }, checkerTypes?: (CheckerType | 'relation')[] - ) => boolean; - tryExecute: (path?: string) => boolean | Error; + ) => boolean | OakUserException; + tryExecute: (path?: string) => boolean | OakUserException; getOperations: ( path?: string ) => { operation: ED[T]['Operation']; entity: T }[] | undefined;