@flexvertex/flexvertex-driver
Version:
The official FlexVertex Node.js driver
116 lines (88 loc) • 3.82 kB
JavaScript
import axios from 'axios';
import { Buffer } from 'node:buffer';
import { JSONParse, JSONStringify } from 'json-with-bigint';
import { FlexObject } from '../objects/FlexObject.js';
/**
* Represents a FlexVertex FlexConnection object.
*/
export class FlexConnection extends FlexObject
{
#flexSchema;
#originKey;
#destinationKey;
#options = { };
static #determineClassName(options)
{
if(options === undefined) return "sysclass:FlexConnection";
else
{
if(options.class === undefined) return "sysclass:FlexConnection";
else return options.class;
}
}
constructor(flexSchema, originKey, destinationKey, options)
{
super(flexSchema, FlexConnection.#determineClassName(options));
this.#flexSchema = flexSchema;
//console.log("--FlexConnection() originKey = " + originKey);
//console.log("--FlexConnection() options = " + JSONStringify(options));
if(originKey === undefined) throw "FlexConnection() originKey is undefined!";
this.#originKey = originKey;
if(destinationKey === undefined) throw "FlexConnection() destinationKey is undefined!";
this.#destinationKey = destinationKey;
this.#options = options;
}
static createFromObject(schema, o)
{
if(schema === undefined) throw "FlexConnection.createFromObject() schema is undefined!";
if(o === undefined) throw "FlexConnection.createFromObject() object is undefined!";
if(o.Metadata === undefined) throw "FlexConnection.createFromObject() Metadata is undefined!";
if(o.Metadata.Class === undefined) throw "FlexConnection.createFromObject() Metadata.Class is undefined!";
if(o.OriginKey === undefined) throw "FlexConnection.createFromObject() Metadata.OriginKey is undefined!";
if(o.DestinationKey === undefined) throw "FlexConnection.createFromObject() object.DestinationKey is undefined!";
let cx = new FlexConnection(schema, o.OriginKey, o.DestinationKey, {class:o.Metadata.Class});
if(!(o.Attributes === undefined))
cx.attributes = o.Attributes;
if(!(o.Properties === undefined))
cx.properties = o.Properties;
if(!(o.Metadata.ObjectKey === undefined))
cx.objectKey = o.Metadata.ObjectKey;
return cx;
}
get originKey() { return this.#originKey; }
set originKey(org) { this.#originKey = org; }
get destinationKey() { return this.#destinationKey; }
set destinationKey(dst) { this.#destinationKey = dst; }
// get objectKey() { return this.#objectKey; }
// set objectKey(key) { this.#objectKey = key; }
get options() { return this.#options; }
set options(jsonProps) { Object.assign(this.#options, jsonProps); }
/*
async connectTo(obj)
{
}
*/
getObject()
{
// console.log("FlexConnection getObject() calling isNew()..");
if(this.isNew())
{
//console.log("FlexConnection getObject() originKey = " + this.#originKey);
//console.log("FlexConnection getObject() options = " + JSONStringify(this.#options));
return { Class: this.className, UniqueID: this.uniqueID, OriginKey: this.#originKey, DestinationKey: this.#destinationKey, Options: this.#options, Attributes: this.attributes, Properties: this.properties };
}
else
{
return { ObjectKey: this.objectKey, UniqueID: this.uniqueID, Attributes: this.attributes, Properties: this.properties };
//return { objectKey: this.objectKey, uniqueID: this.uniqueID, originKey: this.#originKey, destinationKey: this.#destinationKey, options: this.#options, attributes: this.attributes, properties: this.properties };
}
}
// async save()
save()
{
if(this.#flexSchema === undefined) throw "FlexConnection.save() The FlexSchema is undefined!";
// await this.#flexSchema.addSavingConnection(this);
this.#flexSchema.addSavingConnection(this);
// await this.#flexSchema.saveObject(this);
}
}