@brimdata/zealot
Version:
The Javascript Client for Zed Lakes
90 lines (89 loc) • 2.64 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
decode: ()=>decode,
encode: ()=>encode
});
const _context = require("./zed/context");
const _index = /*#__PURE__*/ _interopRequireWildcard(require("./zed/index"));
function _getRequireWildcardCache(nodeInterop) {
if (typeof WeakMap !== "function") return null;
var cacheBabelInterop = new WeakMap();
var cacheNodeInterop = new WeakMap();
return (_getRequireWildcardCache = function(nodeInterop) {
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
})(nodeInterop);
}
function _interopRequireWildcard(obj, nodeInterop) {
if (!nodeInterop && obj && obj.__esModule) {
return obj;
}
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
return {
default: obj
};
}
var cache = _getRequireWildcardCache(nodeInterop);
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {};
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
for(var key in obj){
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
if (desc && (desc.get || desc.set)) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
}
newObj.default = obj;
if (cache) {
cache.set(obj, newObj);
}
return newObj;
}
function decode(data, opts = {}) {
const defaults = {
context: _context.DefaultContext
};
const options = {
...defaults,
...opts
};
const { context } = options;
if (Array.isArray(data)) {
return context.decode(data, options.stream);
} else if ("path" in data) {
return context.decodeField(data);
} else {
return context.decodeOne(data, options.stream);
}
}
function encode(data, opts = {}) {
const defaults = {
context: _context.DefaultContext
};
const options = {
...defaults,
...opts
};
const { context } = options;
if (Array.isArray(data)) {
return context.encode(data);
} else if (data instanceof _index.Field) {
return context.encodeField(data);
} else {
return context.encodeOne(data);
}
}