UNPKG

@flexvertex/flexvertex-driver

Version:

The official FlexVertex Node.js driver

76 lines (60 loc) 2.01 kB
import { JSONParse, JSONStringify } from 'json-with-bigint'; import { FlexResult } from '../schema/FlexResult.js'; import { FlexObject } from '../objects/FlexObject.js'; import { FlexConnection } from '../connections/FlexConnection.js'; /** * Represents a segment tuple, containing a source object, connection, target object, and direction. * FlexSegments are typically used within a {@link FlexJourney}. * @hideconstructor */ export class FlexSegment extends FlexResult { #schema; #sourceObj; #connection; #targetObj; #direction; constructor(schema, segmentObj) { super(segmentObj); if(!(schema === undefined)) this.#schema = schema; if(!(segmentObj === undefined)) { // console.log("segmentObj = " + JSONStringify(segmentObj)); if(!(segmentObj.Source === undefined)) { this.#sourceObj = FlexObject.createFromObject(schema, segmentObj.Source); } else console.log("FlexSegment source is undefined!"); if(!(segmentObj.Connection === undefined)) { this.#connection = FlexConnection.createFromObject(schema, segmentObj.Connection); } if(!(segmentObj.Target === undefined)) { this.#targetObj = FlexObject.createFromObject(schema, segmentObj.Target); } if(!(segmentObj.Direction === undefined)) { this.#direction = segmentObj.Direction; } } } get schema() { return this.#schema; } /** * @property {FlexObject} source - Returns this FlexSegment's source object */ get source() { return this.#sourceObj; } /** * @property {FlexConnection} connection - Returns this FlexSegment's connection object */ get connection() { return this.#connection; } /** * @property {FlexObject} target - Returns this FlexSegment's target object */ get target() { return this.#targetObj; } /** * @property {string} direction - Returns this FlexSegment's directionality: 'Both', 'From', or 'To' */ get direction() { return this.#direction; } }