From fe51046b8b0d713dae3b40fca270eddd9e68d26b Mon Sep 17 00:00:00 2001 From: _Kerman Date: Tue, 19 Dec 2023 12:49:49 +0800 Subject: [PATCH] fix: add `ctorName` to avoid crash in production mode --- packages/northstar/src/blocks/component/block.ts | 2 ++ packages/northstar/src/blocks/special/FuncBlockBase.r.ts | 2 ++ packages/northstar/src/blocks/special/do.r.ts | 2 ++ packages/northstar/src/blocks/special/expr.ts | 2 ++ packages/northstar/src/blocks/special/if.r.ts | 2 ++ packages/northstar/src/blocks/special/imp.ts | 2 ++ packages/northstar/src/blocks/special/root.r.ts | 2 ++ packages/northstar/src/blocks/special/state.ts | 2 ++ packages/northstar/src/blocks/special/stateSetter.r.ts | 2 ++ packages/northstar/src/blocks/special/string.ts | 2 ++ packages/northstar/src/blocks/special/validator.ts | 6 ++++-- packages/northstar/src/blocks/special/view.r.ts | 2 ++ packages/visual-flow/src/components/block/RectBlock.r.ts | 2 ++ packages/visual-flow/src/components/line/BasicLine.ts | 2 ++ packages/visual-flow/src/components/socket/MultiInSocket.ts | 5 ++++- .../visual-flow/src/components/socket/MultiOutSocket.ts | 2 ++ .../visual-flow/src/components/socket/SingleInSocket.ts | 2 ++ .../visual-flow/src/components/socket/SingleOutSocket.ts | 2 ++ packages/visual-flow/src/model/block.ts | 4 +++- packages/visual-flow/src/model/line.ts | 4 +++- packages/visual-flow/src/model/socket.ts | 4 +++- 21 files changed, 49 insertions(+), 6 deletions(-) diff --git a/packages/northstar/src/blocks/component/block.ts b/packages/northstar/src/blocks/component/block.ts index 731420b..b43ec44 100644 --- a/packages/northstar/src/blocks/component/block.ts +++ b/packages/northstar/src/blocks/component/block.ts @@ -24,6 +24,8 @@ import { getProps } from "./getProps"; import { updatePlugins } from "./updatePlugins"; export class ComponentBlock extends RectBlock { + ctorName: string = "ComponentBlock"; + cloneTo(target: this): this { super.cloneTo(target); target.setComponentType(this.componentType, this.info); diff --git a/packages/northstar/src/blocks/special/FuncBlockBase.r.ts b/packages/northstar/src/blocks/special/FuncBlockBase.r.ts index b860fd7..4df8a2b 100644 --- a/packages/northstar/src/blocks/special/FuncBlockBase.r.ts +++ b/packages/northstar/src/blocks/special/FuncBlockBase.r.ts @@ -31,6 +31,8 @@ export abstract class FuncBlockBase extends RectBlock implements SpecialBlock { cloneTo(target: this): this { super.cloneTo(target); target.inputValue.value = this.inputValue.value; + target.outputDirection = this.outputDirection; + target.slotsDirection = this.slotsDirection; return target; } diff --git a/packages/northstar/src/blocks/special/do.r.ts b/packages/northstar/src/blocks/special/do.r.ts index 6c5d30d..83c5213 100644 --- a/packages/northstar/src/blocks/special/do.r.ts +++ b/packages/northstar/src/blocks/special/do.r.ts @@ -22,6 +22,8 @@ const WIDTH = 70; const HEIGHT = 30; export class DoBlock extends RectBlock { + ctorName: string = "DoBlock"; + cloneTo(target: this): this { super.cloneTo(target); target.thenNum = this.thenNum; diff --git a/packages/northstar/src/blocks/special/expr.ts b/packages/northstar/src/blocks/special/expr.ts index 1ef3bdf..985cd3d 100644 --- a/packages/northstar/src/blocks/special/expr.ts +++ b/packages/northstar/src/blocks/special/expr.ts @@ -3,6 +3,8 @@ import { blockCtors } from "@quasi-dev/visual-flow"; import { FuncBlockBase } from "./FuncBlockBase.r"; export class ExprBlock extends FuncBlockBase { + ctorName: string = "ExprBlock"; + type: FuncBlockTypes = "expr"; label = "expression"; outputLabel = "value"; diff --git a/packages/northstar/src/blocks/special/if.r.ts b/packages/northstar/src/blocks/special/if.r.ts index d025e37..cb854e0 100644 --- a/packages/northstar/src/blocks/special/if.r.ts +++ b/packages/northstar/src/blocks/special/if.r.ts @@ -21,6 +21,8 @@ import { import { SpecialBlock } from "./base"; export class IfElseBlock extends RectBlock implements SpecialBlock { + ctorName: string = "IfElseBlock"; + cloneTo(target: this): this { super.cloneTo(target); target.hasElse = this.hasElse; diff --git a/packages/northstar/src/blocks/special/imp.ts b/packages/northstar/src/blocks/special/imp.ts index e482553..13174e9 100644 --- a/packages/northstar/src/blocks/special/imp.ts +++ b/packages/northstar/src/blocks/special/imp.ts @@ -21,6 +21,8 @@ import { import { FuncBlockBase } from "./FuncBlockBase.r"; export class ImpBlock extends FuncBlockBase { + ctorName: string = "ImpBlock"; + cloneTo(target: this): this { super.cloneTo(target); target.hasThen = this.hasThen; diff --git a/packages/northstar/src/blocks/special/root.r.ts b/packages/northstar/src/blocks/special/root.r.ts index f5d9cff..d91234c 100644 --- a/packages/northstar/src/blocks/special/root.r.ts +++ b/packages/northstar/src/blocks/special/root.r.ts @@ -14,6 +14,8 @@ import { SpecialBlock } from "./base"; import { currentProject } from "../../project"; export class RootBlock extends RectBlock implements SpecialBlock { + ctorName: string = "RootBlock"; + boardWidth = 200; boardHeight = 50; diff --git a/packages/northstar/src/blocks/special/state.ts b/packages/northstar/src/blocks/special/state.ts index 5500f92..f04e87b 100644 --- a/packages/northstar/src/blocks/special/state.ts +++ b/packages/northstar/src/blocks/special/state.ts @@ -4,6 +4,8 @@ import { ExprBlock } from "./expr"; import { StateSetterBlock } from "./stateSetter.r"; export class StateBlock extends ExprBlock { + ctorName: string = "StateBlock"; + label = "state"; type: FuncBlockTypes = "state"; placeholder = "initial value"; diff --git a/packages/northstar/src/blocks/special/stateSetter.r.ts b/packages/northstar/src/blocks/special/stateSetter.r.ts index a6f269d..2560df4 100644 --- a/packages/northstar/src/blocks/special/stateSetter.r.ts +++ b/packages/northstar/src/blocks/special/stateSetter.r.ts @@ -16,6 +16,8 @@ import { multiInSocketToOutput } from "../../utils/toOutput"; import { ExprBlock } from "./expr"; export class StateSetterBlock extends ExprBlock { + ctorName: string = "StateSetterBlock"; + type: FuncBlockTypes = "state-setter"; label = "state setter"; placeholder = "expr"; diff --git a/packages/northstar/src/blocks/special/string.ts b/packages/northstar/src/blocks/special/string.ts index ea21c3e..06d98d6 100644 --- a/packages/northstar/src/blocks/special/string.ts +++ b/packages/northstar/src/blocks/special/string.ts @@ -3,6 +3,8 @@ import { blockCtors } from "@quasi-dev/visual-flow"; import { FuncBlockBase } from "./FuncBlockBase.r"; export class StringBlock extends FuncBlockBase { + ctorName: string = "StringBlock"; + type: FuncBlockTypes = "string"; label = "string template"; diff --git a/packages/northstar/src/blocks/special/validator.ts b/packages/northstar/src/blocks/special/validator.ts index 587c1d8..8c3370c 100644 --- a/packages/northstar/src/blocks/special/validator.ts +++ b/packages/northstar/src/blocks/special/validator.ts @@ -1,8 +1,10 @@ -import { Direction, Socket, blockCtors } from "@quasi-dev/visual-flow"; -import { FuncBlockBase } from "./FuncBlockBase.r"; import { FuncBlockTypes, ValidatorBlockOutput } from "@quasi-dev/compiler"; +import { Direction, blockCtors } from "@quasi-dev/visual-flow"; +import { FuncBlockBase } from "./FuncBlockBase.r"; export class ValidatorBlock extends FuncBlockBase { + ctorName: string = "ValidatorBlock"; + label = "validator"; type: FuncBlockTypes = "validator"; placeholder = "expression"; diff --git a/packages/northstar/src/blocks/special/view.r.ts b/packages/northstar/src/blocks/special/view.r.ts index 397a765..8c00d88 100644 --- a/packages/northstar/src/blocks/special/view.r.ts +++ b/packages/northstar/src/blocks/special/view.r.ts @@ -13,6 +13,8 @@ import { singleInSocketToOutput } from "../../utils/toOutput"; import { SpecialBlock } from "./base"; export class ViewBlock extends RectBlock implements SpecialBlock { + ctorName: string = "ViewBlock"; + cloneTo(target: this): this { super.cloneTo(target); target.viewName = this.viewName; diff --git a/packages/visual-flow/src/components/block/RectBlock.r.ts b/packages/visual-flow/src/components/block/RectBlock.r.ts index 380f3f8..f92447f 100644 --- a/packages/visual-flow/src/components/block/RectBlock.r.ts +++ b/packages/visual-flow/src/components/block/RectBlock.r.ts @@ -7,6 +7,8 @@ import styles from "./RectBlock.styles"; const SOCKET_PADDING_SCALE = -0.1; export abstract class RectBlock extends Block { + ctorName: string = "RectBlock"; + cloneTo(target: this): this { target.boardWidth = this.boardWidth; target.boardHeight = this.boardHeight; diff --git a/packages/visual-flow/src/components/line/BasicLine.ts b/packages/visual-flow/src/components/line/BasicLine.ts index 7bcf989..52f77f6 100644 --- a/packages/visual-flow/src/components/line/BasicLine.ts +++ b/packages/visual-flow/src/components/line/BasicLine.ts @@ -17,6 +17,8 @@ function getCtrlPointOffset(delta: number) { } export class BasicLine extends Line { + ctorName: string = "BasicLine"; + clone(): Line { const line = new BasicLine(); line.type = this.type; diff --git a/packages/visual-flow/src/components/socket/MultiInSocket.ts b/packages/visual-flow/src/components/socket/MultiInSocket.ts index 2d313f3..74fb1d9 100644 --- a/packages/visual-flow/src/components/socket/MultiInSocket.ts +++ b/packages/visual-flow/src/components/socket/MultiInSocket.ts @@ -1,8 +1,11 @@ -import { Direction, LINE_END_OFFSET, Point } from "../.."; import { Line, Socket } from "../../model"; import { socketCtors } from "../../recorder"; +import { Direction, Point } from "../../types"; +import { LINE_END_OFFSET } from "../line"; export class MultiInSocket extends Socket { + ctorName: string = "MultiInSocket"; + connectedLines: Line[] = []; get allConnectedLines(): Line[] { diff --git a/packages/visual-flow/src/components/socket/MultiOutSocket.ts b/packages/visual-flow/src/components/socket/MultiOutSocket.ts index 11ec579..37dde04 100644 --- a/packages/visual-flow/src/components/socket/MultiOutSocket.ts +++ b/packages/visual-flow/src/components/socket/MultiOutSocket.ts @@ -3,6 +3,8 @@ import { socketCtors } from "../../recorder"; import { BasicLine } from "../line"; export class MultiOutSocket extends Socket { + ctorName: string = "MultiOutSocket"; + connectedLines: Line[] = []; connectTo(line: Line): void { diff --git a/packages/visual-flow/src/components/socket/SingleInSocket.ts b/packages/visual-flow/src/components/socket/SingleInSocket.ts index f0a3c42..fbcf5a6 100644 --- a/packages/visual-flow/src/components/socket/SingleInSocket.ts +++ b/packages/visual-flow/src/components/socket/SingleInSocket.ts @@ -2,6 +2,8 @@ import { Line, Socket } from "../../model"; import { socketCtors } from "../../recorder"; export class SingleInSocket extends Socket { + ctorName: string = "SingleInSocket"; + connectedLine: Line | null = null; get allConnectedLines(): Line[] { diff --git a/packages/visual-flow/src/components/socket/SingleOutSocket.ts b/packages/visual-flow/src/components/socket/SingleOutSocket.ts index 0378b0a..9bc9637 100644 --- a/packages/visual-flow/src/components/socket/SingleOutSocket.ts +++ b/packages/visual-flow/src/components/socket/SingleOutSocket.ts @@ -4,6 +4,8 @@ import { BasicLine } from "../line"; import { PATH_OUT_ELIPSE, PATH_OUT_RECT } from "./constants"; export class SingleOutSocket extends Socket { + ctorName: string = "SingleOutSocket"; + connectedLine: Line | null = null; get allConnectedLines(): Line[] { diff --git a/packages/visual-flow/src/model/block.ts b/packages/visual-flow/src/model/block.ts index 644cf54..5a611c5 100644 --- a/packages/visual-flow/src/model/block.ts +++ b/packages/visual-flow/src/model/block.ts @@ -23,6 +23,8 @@ export type UseSocket = ( export type UsedSockets = [string, Socket][]; export abstract class Block extends ModelBase { + abstract ctorName: string; + abstract cloneTo(target: this): this; clone() { return this.cloneTo(new (this.constructor as any)()); @@ -402,7 +404,7 @@ export abstract class Block extends ModelBase { protected abstract exportData(): any; exportRecord(): BlockRecord { return { - ctor: this.constructor.name, + ctor: this.ctorName, id: this.id, boardX: this.boardX, boardY: this.boardY, diff --git a/packages/visual-flow/src/model/line.ts b/packages/visual-flow/src/model/line.ts index d6f84bf..964e4bd 100644 --- a/packages/visual-flow/src/model/line.ts +++ b/packages/visual-flow/src/model/line.ts @@ -41,6 +41,8 @@ const defaultColors: Record = { }; export abstract class Line extends ModelBase { + abstract ctorName: string; + abstract clone(): Line; graph: Graph; @@ -186,7 +188,7 @@ export abstract class Line extends ModelBase { protected abstract exportData(): any; exportRecord(): LineRecord { return { - ctor: this.constructor.name, + ctor: this.ctorName, id: this.id, type: this.type, socketAId: this.a.id, diff --git a/packages/visual-flow/src/model/socket.ts b/packages/visual-flow/src/model/socket.ts index c2c3b1a..c0de8fa 100644 --- a/packages/visual-flow/src/model/socket.ts +++ b/packages/visual-flow/src/model/socket.ts @@ -6,6 +6,8 @@ import { Graph } from "./graph"; import { Line } from "./line"; export abstract class Socket extends ModelBase { + abstract ctorName: string; + get graph(): Graph { return this.block.graph; } @@ -86,7 +88,7 @@ export abstract class Socket extends ModelBase { protected abstract exportData(): any; exportRecord(): SocketRecord { return { - ctor: this.constructor.name, + ctor: this.ctorName, id: this.id, type: this.type, direction: this.direction,