@node-flow/core
Advanced tools
Comparing version 0.0.1-alpha.9 to 0.0.1-alpha.10
@@ -22,3 +22,6 @@ /// <reference types="node" /> | ||
} | ||
export declare type NodeFlowEvent = any; | ||
export declare type NodeFlowEvent = { | ||
id: string; | ||
payload?: any; | ||
}; | ||
export declare class Flow extends EventEmitter { | ||
@@ -52,10 +55,2 @@ id: string; | ||
*/ | ||
initEvent(): void; | ||
/** | ||
* | ||
*/ | ||
handleFlowStateChange(): void; | ||
/** | ||
* | ||
*/ | ||
handleNodeComplete(err: any, event: NodeFlowEvent): Promise<void>; | ||
@@ -62,0 +57,0 @@ /** |
@@ -38,8 +38,6 @@ "use strict"; | ||
constructor(opt) { | ||
flowLogger.info('[T] flow constructor'); | ||
flowLogger.trace('flow constructor flowData: ', JSON.stringify(opt)); | ||
super(); | ||
this.nodeMap = {}; | ||
this.nodeList = []; | ||
const { name = 'untitled', nodes = [], id = (0, uuid_1.v4)(), state = FlowState.CREATE, activateNodeIdx = -1, event = { _id: (0, uuid_1.v4)() } } = opt; | ||
const { name = 'untitled', nodes = [], id = (0, uuid_1.v4)(), state = FlowState.CREATE, activateNodeIdx = -1, event = { id: (0, uuid_1.v4)() } } = opt; | ||
this.name = name; | ||
@@ -51,5 +49,5 @@ this.id = id; | ||
this.logger = logger_1.default.getLogger(`FLOW ${this.id}`); | ||
this.initEvent(); | ||
this.logger.info('[T] flow constructor'); | ||
this.logger.trace('flow constructor flowData: ', JSON.stringify(opt)); | ||
this.createNodes(nodes); | ||
this.save(); | ||
} | ||
@@ -90,14 +88,2 @@ /** | ||
*/ | ||
initEvent() { | ||
this.on(FlowEvent.STATE_CHANGE, this.handleFlowStateChange.bind(this)); | ||
} | ||
/** | ||
* | ||
*/ | ||
handleFlowStateChange() { | ||
this.save(); | ||
} | ||
/** | ||
* | ||
*/ | ||
handleNodeComplete(err, event) { | ||
@@ -108,4 +94,2 @@ return __awaiter(this, void 0, void 0, function* () { | ||
this.state = FlowState.END; | ||
else | ||
yield this.save(); | ||
}); | ||
@@ -183,4 +167,3 @@ } | ||
const node = this.nodeList[this.activateNodeIdx]; | ||
node.activate(this.event); | ||
yield this.save(); | ||
yield node.activate(this.event); | ||
this.emit(FlowEvent.NEXT, this); | ||
@@ -187,0 +170,0 @@ return node; |
export { Flow, FlowData, FlowEvent, FlowState, NodeFlowEvent } from './flow'; | ||
export { Node, NodeData, NodeEvent, NodeState, registerNode } from './node'; | ||
export { Node, NodeData, NodeEvent, NodeState, registerNode, INode } from './node'; | ||
export { logger } from './logger'; |
@@ -14,3 +14,2 @@ /// <reference types="node" /> | ||
state?: NodeState; | ||
scope?: string; | ||
} | ||
@@ -27,3 +26,6 @@ export declare enum NodeEvent { | ||
} | ||
export declare class Node<T extends NodeData> extends EventEmitter { | ||
export interface INode { | ||
run: (e: NodeFlowEvent) => Promise<NodeFlowEvent>; | ||
} | ||
export declare class Node<T extends NodeData> extends EventEmitter implements INode { | ||
protected options: T; | ||
@@ -35,3 +37,2 @@ static type: string; | ||
nodeState: NodeState; | ||
scope: string; | ||
logger: Logger; | ||
@@ -41,8 +42,5 @@ static checkout(node: string): Node<NodeData>; | ||
constructor(options: T); | ||
initEvent(): void; | ||
handleNodeStateChange(): Promise<void>; | ||
activate(event: NodeFlowEvent): Promise<void>; | ||
run(event: NodeFlowEvent): any; | ||
run(event: NodeFlowEvent): Promise<NodeFlowEvent>; | ||
complete(err: null | any, event: NodeFlowEvent): void; | ||
setScope(event: NodeFlowEvent, value: any): void; | ||
serialize(): NodeData; | ||
@@ -49,0 +47,0 @@ save(): Promise<void>; |
@@ -45,7 +45,5 @@ "use strict"; | ||
constructor(options) { | ||
nodeLogger.info('[T] node constructor'); | ||
nodeLogger.trace('node constructor', JSON.stringify(options)); | ||
super(); | ||
this.options = options; | ||
const { type, name = 'untitled', id = (0, uuid_1.v4)(), state = NodeState.CREATE, scope } = this.options; | ||
const { type, name = 'untitled', id = (0, uuid_1.v4)(), state = NodeState.CREATE } = this.options; | ||
this.type = type; | ||
@@ -55,6 +53,5 @@ this.name = name; | ||
this.nodeState = state; | ||
this.scope = scope || id; | ||
this.logger = logger_1.default.getLogger(`NODE ${this.id}`); | ||
this.initEvent(); | ||
this.save(); | ||
this.logger.info('[T] node constructor'); | ||
this.logger.trace('node constructor', JSON.stringify(options)); | ||
} | ||
@@ -83,10 +80,2 @@ static checkout(node) { | ||
} | ||
initEvent() { | ||
this.on(NodeEvent.STATE_CHANGE, this.handleNodeStateChange.bind(this)); | ||
} | ||
handleNodeStateChange() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield this.save(); | ||
}); | ||
} | ||
activate(event) { | ||
@@ -102,3 +91,3 @@ return __awaiter(this, void 0, void 0, function* () { | ||
catch (e) { | ||
this.complete(e, null); | ||
this.complete(e, event); | ||
} | ||
@@ -108,5 +97,7 @@ }); | ||
run(event) { | ||
// do something ... | ||
event[this.options.scope || this.id] = 'Hello world'; | ||
return event; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// do something ... | ||
event.payload = 'Hello world'; | ||
return event; | ||
}); | ||
} | ||
@@ -119,5 +110,2 @@ complete(err, event) { | ||
} | ||
setScope(event, value) { | ||
event[this.scope || this.id] = value; | ||
} | ||
serialize() { | ||
@@ -129,3 +117,2 @@ return { | ||
type: this.type, | ||
scope: this.scope | ||
}; | ||
@@ -132,0 +119,0 @@ } |
{ | ||
"name": "@node-flow/core", | ||
"version": "0.0.1-alpha.9", | ||
"version": "0.0.1-alpha.10", | ||
"description": "> TODO: description", | ||
@@ -44,3 +44,3 @@ "author": "wayne <me@waynegong.cn>", | ||
}, | ||
"gitHead": "2fdb3e75405ac5a53037bd4cd54575ff3b9ab383" | ||
"gitHead": "a6e8f2029fb726cda66eac84e1122d83367ff80c" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24340
624