From ebd8936dae85d84bd8e7ec797800c3cee18e85ad Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Thu, 7 May 2020 15:09:25 +0200 Subject: [PATCH] fix --- lib/classes/GraphStream.ts | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/classes/GraphStream.ts b/lib/classes/GraphStream.ts index edb6ad7..159130b 100644 --- a/lib/classes/GraphStream.ts +++ b/lib/classes/GraphStream.ts @@ -3,6 +3,7 @@ import { Transform } from 'stream'; import { GraphStreamJSON } from '../interfaces/GraphStreamJSON'; import { GraphStreamCommand } from '../enums/GraphStreamCommand'; +import { validate_name } from '../Helper'; interface Stringable { // eslint-disable-next-line @typescript-eslint/naming-convention @@ -119,24 +120,26 @@ export class GraphStream extends Transform { return super.write (JSON.stringify (instr), 'utf-8'); } - public create_node (name: string): boolean { - return this.write ({ type: 'cn', args: [ name ] }); + public create_node (name: string): string { + const node_name = validate_name (name); + this.write ({ type: 'cn', args: [ node_name ] }); + return `${this.path}_${node_name}`; } - public end_node (): boolean { - return this.write ({ type: 'en', args: [] }); + public end_node (): void { + this.write ({ type: 'en', args: [] }); } - public create_graph (name: string, type: 'u'|'d'|'s' = 's'): boolean { + public create_graph (name: string, type: 'u'|'d'|'s' = 's'): void { const instr_type = `c${type}g` as GraphStreamCommand; - return this.write ({ type: instr_type, args: [ name ] }); + this.write ({ type: instr_type, args: [ validate_name (name) ] }); } - public end_graph (): boolean { - return this.write ({ type: 'eg', args: [] }); + public end_graph (): void { + this.write ({ type: 'eg', args: [] }); } - public attributes (attrs: Record): boolean { + public attributes (attrs: Record): void { const solved = []; for (const attr of Object.keys (attrs)) { const val = attrs[attr].toString (); @@ -145,11 +148,11 @@ export class GraphStream extends Transform { else solved.push (`${attr} = "${val}"`); } - return this.write ({ type: 'at', args: solved }); + this.write ({ type: 'at', args: solved }); } - public create_edge (origin: string, target: string): boolean { - return this.write ({ + public create_edge (origin: string, target: string): void { + this.write ({ type: 'ce', args: [ origin,