UNPKG

@brimdata/zealot

Version:

The Javascript Client for Zed Lakes

62 lines (61 loc) 1.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "ZedMap", { enumerable: true, get: ()=>ZedMap }); const _typeIp = require("../types/type-ip"); const _isNull = require("../utils/is-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 ZedMap { toString() { if ((0, _isNull.isNull)(this.value)) return "null"; const contents = Array.from(this.value.entries()).map(([key, value])=>{ const sep = isIPv6(key) ? " :" : ":"; return key.toString() + sep + value.toString(); }).join(","); return `|{${contents}}|`; } serialize(stream) { if ((0, _isNull.isNull)(this.value)) return null; return Array.from(this.value.entries()).map(([k, v])=>{ return [ stream.encodeValue(k), stream.encodeValue(v) ]; }); } isUnset() { return (0, _isNull.isNull)(this.value); } toJS(opts = {}) { if ((0, _isNull.isNull)(this.value)) return null; return new Map(Array.from(this.value.entries()).map(([k, v])=>[ k.toJS(opts), v.toJS(opts) ])); } constructor(type, value){ _defineProperty(this, "type", void 0); _defineProperty(this, "value", void 0); this.type = type; this.value = value; } } function isIPv6(v) { return v.type === _typeIp.TypeIp && v.toString().includes(":"); }