UNPKG

@brimdata/zealot

Version:

The Javascript Client for Zed Lakes

55 lines (54 loc) 1.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "TypeUnion", { enumerable: true, get: ()=>TypeUnion }); const _union = require("../values/union"); const _typeNull = require("./type-null"); function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } class TypeUnion { static stringify(types) { return `(${types.map((t)=>t.toString()).join(",")})`; } create(value, stream) { if (value === null) { return new _union.Union(this, _typeNull.TypeNull, null, null); } else { const index = parseInt(value[0]); const innerType = this.types[index]; const innerValue = innerType.create(value[1], stream); return new _union.Union(this, innerType, index, innerValue); } } serialize(stream) { return { kind: "union", types: this.types.map((t)=>stream.encodeType(t)) }; } toString() { return `(${this.types.map((t)=>t.toString()).join(",")})`; } constructor(types){ _defineProperty(this, "types", void 0); _defineProperty(this, "kind", void 0); _defineProperty(this, "id", void 0); this.types = types; this.kind = "union"; } }