Back to home page

EIC code displayed by LXR

 
 

    


Warning, /firebird/packages/firebird-core/src/model/data-exchange.ts is written in an unsupported language. File is not indexed.

0001 
0002 import {Event} from "./event";
0003 
0004 /**
0005  * A complete DEX document: the object form of a .firebird.json file.
0006  *
0007  * Reads and writes DEX version 1.0 only. Older 0.04 files fail loudly with a
0008  * pointer to the one-shot upgrade command — there is no fallback reader.
0009  */
0010 export class DataExchange  {
0011 
0012   static readonly supportedVersion = "1.0";
0013 
0014   version: string = DataExchange.supportedVersion;
0015   origin: any = {}
0016   events: Event[] = []
0017 
0018 
0019   toDexObject() {
0020     let objEntries:any[] = [];
0021     for(const entry of this.events) {
0022       objEntries.push(entry.toDexObject());
0023     }
0024     return {
0025       type: "firebird-dex-json",
0026       version: this.version,
0027       origin: this.origin,
0028       events: objEntries
0029     }
0030   }
0031 
0032   static fromDexObj(obj: any): DataExchange {
0033     const version = String(obj?.["version"] ?? "");
0034     if (version !== DataExchange.supportedVersion) {
0035       throw new Error(
0036         `Unsupported DEX version '${version}': this build reads DEX ${DataExchange.supportedVersion} only. ` +
0037         `Convert older files once with: pyrobird upgrade <in> <out>`);
0038     }
0039     let result = new DataExchange();
0040     result.version = version;
0041     result.origin = obj["origin"];
0042     for(const objEntry of obj["events"]) {
0043       result.events.push(Event.fromDexObject(objEntry));
0044     }
0045     return result;
0046   }
0047 }