arrakis-js
Version:
Arrakis Javascript client library
1,480 lines (1,461 loc) • 404 kB
JavaScript
var __defProp = Object.defineProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
// src/utils.ts
var GPS_EPOCH = (/* @__PURE__ */ new Date("1980-01-06T00:00:00Z")).getTime();
var LEAP_SECONDS = [
"1981-07-01",
"1982-07-01",
"1983-07-01",
"1985-07-01",
"1988-01-01",
"1990-01-01",
"1991-01-01",
"1992-07-01",
"1993-07-01",
"1994-07-01",
"1996-01-01",
"1997-07-01",
"1999-01-01",
"2006-01-01",
"2009-01-01",
"2012-07-01",
"2015-07-01",
"2017-01-01"
];
function calculateLeapSeconds(date) {
let totalLeapSeconds = 0;
for (const leapDate of LEAP_SECONDS) {
if (date >= new Date(leapDate)) {
totalLeapSeconds += 1;
} else {
break;
}
}
return totalLeapSeconds;
}
function gpsToUnix(gpsTime) {
if (typeof gpsTime !== "number" || isNaN(gpsTime)) {
throw new Error("GPS time must be a valid number");
}
const gpsDate = new Date(gpsTime + GPS_EPOCH);
const totalLeapSeconds = calculateLeapSeconds(gpsDate);
return gpsTime + GPS_EPOCH - totalLeapSeconds * 1e3;
}
function unixToGps(unixTime) {
if (typeof unixTime !== "number" || isNaN(unixTime)) {
throw new Error("Unix time must be a valid number");
}
const unixDate = new Date(unixTime);
const totalLeapSeconds = calculateLeapSeconds(unixDate);
return unixTime - GPS_EPOCH + totalLeapSeconds * 1e3;
}
// src/constants.ts
var DEFAULT_ARRAKIS_SERVER = "http://localhost:8000";
var MAX_SAMPLE_RATE = Number.MAX_SAFE_INTEGER;
// node_modules/tslib/tslib.es6.mjs
function __rest(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) {
return value instanceof P ? value : new P(function(resolve) {
resolve(value);
});
}
return new (P || (P = Promise))(function(resolve, reject) {
function fulfilled(value) {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
}
function rejected(value) {
try {
step(generator["throw"](value));
} catch (e) {
reject(e);
}
}
function step(result) {
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
}
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __values(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function() {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function __await(v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
}
function __asyncGenerator(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function() {
return this;
}, i;
function awaitReturn(f) {
return function(v) {
return Promise.resolve(v).then(f, reject);
};
}
function verb(n, f) {
if (g[n]) {
i[n] = function(v) {
return new Promise(function(a, b) {
q.push([n, v, a, b]) > 1 || resume(n, v);
});
};
if (f) i[n] = f(i[n]);
}
}
function resume(n, v) {
try {
step(g[n](v));
} catch (e) {
settle(q[0][3], e);
}
}
function step(r) {
r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
}
function fulfill(value) {
resume("next", value);
}
function reject(value) {
resume("throw", value);
}
function settle(f, v) {
if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]);
}
}
function __asyncDelegator(o) {
var i, p;
return i = {}, verb("next"), verb("throw", function(e) {
throw e;
}), verb("return"), i[Symbol.iterator] = function() {
return this;
}, i;
function verb(n, f) {
i[n] = o[n] ? function(v) {
return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v;
} : f;
}
}
function __asyncValues(o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() {
return this;
}, i);
function verb(n) {
i[n] = o[n] && function(v) {
return new Promise(function(resolve, reject) {
v = o[n](v), settle(resolve, reject, v.done, v.value);
});
};
}
function settle(resolve, reject, d, v) {
Promise.resolve(v).then(function(v2) {
resolve({ value: v2, done: d });
}, reject);
}
}
// node_modules/apache-arrow/util/buffer.mjs
var buffer_exports = {};
__export(buffer_exports, {
compareArrayLike: () => compareArrayLike,
joinUint8Arrays: () => joinUint8Arrays,
memcpy: () => memcpy,
rebaseValueOffsets: () => rebaseValueOffsets,
toArrayBufferView: () => toArrayBufferView,
toArrayBufferViewAsyncIterator: () => toArrayBufferViewAsyncIterator,
toArrayBufferViewIterator: () => toArrayBufferViewIterator,
toBigInt64Array: () => toBigInt64Array,
toBigUint64Array: () => toBigUint64Array,
toFloat32Array: () => toFloat32Array,
toFloat32ArrayAsyncIterator: () => toFloat32ArrayAsyncIterator,
toFloat32ArrayIterator: () => toFloat32ArrayIterator,
toFloat64Array: () => toFloat64Array,
toFloat64ArrayAsyncIterator: () => toFloat64ArrayAsyncIterator,
toFloat64ArrayIterator: () => toFloat64ArrayIterator,
toInt16Array: () => toInt16Array,
toInt16ArrayAsyncIterator: () => toInt16ArrayAsyncIterator,
toInt16ArrayIterator: () => toInt16ArrayIterator,
toInt32Array: () => toInt32Array,
toInt32ArrayAsyncIterator: () => toInt32ArrayAsyncIterator,
toInt32ArrayIterator: () => toInt32ArrayIterator,
toInt8Array: () => toInt8Array,
toInt8ArrayAsyncIterator: () => toInt8ArrayAsyncIterator,
toInt8ArrayIterator: () => toInt8ArrayIterator,
toUint16Array: () => toUint16Array,
toUint16ArrayAsyncIterator: () => toUint16ArrayAsyncIterator,
toUint16ArrayIterator: () => toUint16ArrayIterator,
toUint32Array: () => toUint32Array,
toUint32ArrayAsyncIterator: () => toUint32ArrayAsyncIterator,
toUint32ArrayIterator: () => toUint32ArrayIterator,
toUint8Array: () => toUint8Array,
toUint8ArrayAsyncIterator: () => toUint8ArrayAsyncIterator,
toUint8ArrayIterator: () => toUint8ArrayIterator,
toUint8ClampedArray: () => toUint8ClampedArray,
toUint8ClampedArrayAsyncIterator: () => toUint8ClampedArrayAsyncIterator,
toUint8ClampedArrayIterator: () => toUint8ClampedArrayIterator
});
// node_modules/apache-arrow/util/utf8.mjs
var decoder = new TextDecoder("utf-8");
var decodeUtf8 = (buffer) => decoder.decode(buffer);
var encoder = new TextEncoder();
var encodeUtf8 = (value) => encoder.encode(value);
// node_modules/apache-arrow/util/compat.mjs
var isNumber = (x) => typeof x === "number";
var isBoolean = (x) => typeof x === "boolean";
var isFunction = (x) => typeof x === "function";
var isObject = (x) => x != null && Object(x) === x;
var isPromise = (x) => {
return isObject(x) && isFunction(x.then);
};
var isIterable = (x) => {
return isObject(x) && isFunction(x[Symbol.iterator]);
};
var isAsyncIterable = (x) => {
return isObject(x) && isFunction(x[Symbol.asyncIterator]);
};
var isArrowJSON = (x) => {
return isObject(x) && isObject(x["schema"]);
};
var isIteratorResult = (x) => {
return isObject(x) && "done" in x && "value" in x;
};
var isFileHandle = (x) => {
return isObject(x) && isFunction(x["stat"]) && isNumber(x["fd"]);
};
var isFetchResponse = (x) => {
return isObject(x) && isReadableDOMStream(x["body"]);
};
var isReadableInterop = (x) => "_getDOMStream" in x && "_getNodeStream" in x;
var isWritableDOMStream = (x) => {
return isObject(x) && isFunction(x["abort"]) && isFunction(x["getWriter"]) && !isReadableInterop(x);
};
var isReadableDOMStream = (x) => {
return isObject(x) && isFunction(x["cancel"]) && isFunction(x["getReader"]) && !isReadableInterop(x);
};
var isWritableNodeStream = (x) => {
return isObject(x) && isFunction(x["end"]) && isFunction(x["write"]) && isBoolean(x["writable"]) && !isReadableInterop(x);
};
var isReadableNodeStream = (x) => {
return isObject(x) && isFunction(x["read"]) && isFunction(x["pipe"]) && isBoolean(x["readable"]) && !isReadableInterop(x);
};
var isFlatbuffersByteBuffer = (x) => {
return isObject(x) && isFunction(x["clear"]) && isFunction(x["bytes"]) && isFunction(x["position"]) && isFunction(x["setPosition"]) && isFunction(x["capacity"]) && isFunction(x["getBufferIdentifier"]) && isFunction(x["createLong"]);
};
// node_modules/apache-arrow/util/buffer.mjs
var SharedArrayBuf = typeof SharedArrayBuffer !== "undefined" ? SharedArrayBuffer : ArrayBuffer;
function collapseContiguousByteRanges(chunks) {
const result = chunks[0] ? [chunks[0]] : [];
let xOffset, yOffset, xLen, yLen;
for (let x, y, i = 0, j = 0, n = chunks.length; ++i < n; ) {
x = result[j];
y = chunks[i];
if (!x || !y || x.buffer !== y.buffer || y.byteOffset < x.byteOffset) {
y && (result[++j] = y);
continue;
}
({ byteOffset: xOffset, byteLength: xLen } = x);
({ byteOffset: yOffset, byteLength: yLen } = y);
if (xOffset + xLen < yOffset || yOffset + yLen < xOffset) {
y && (result[++j] = y);
continue;
}
result[j] = new Uint8Array(x.buffer, xOffset, yOffset - xOffset + yLen);
}
return result;
}
function memcpy(target, source, targetByteOffset = 0, sourceByteLength = source.byteLength) {
const targetByteLength = target.byteLength;
const dst = new Uint8Array(target.buffer, target.byteOffset, targetByteLength);
const src = new Uint8Array(source.buffer, source.byteOffset, Math.min(sourceByteLength, targetByteLength));
dst.set(src, targetByteOffset);
return target;
}
function joinUint8Arrays(chunks, size) {
const result = collapseContiguousByteRanges(chunks);
const byteLength = result.reduce((x, b) => x + b.byteLength, 0);
let source, sliced, buffer;
let offset = 0, index = -1;
const length = Math.min(size || Number.POSITIVE_INFINITY, byteLength);
for (const n = result.length; ++index < n; ) {
source = result[index];
sliced = source.subarray(0, Math.min(source.length, length - offset));
if (length <= offset + sliced.length) {
if (sliced.length < source.length) {
result[index] = source.subarray(sliced.length);
} else if (sliced.length === source.length) {
index++;
}
buffer ? memcpy(buffer, sliced, offset) : buffer = sliced;
break;
}
memcpy(buffer || (buffer = new Uint8Array(length)), sliced, offset);
offset += sliced.length;
}
return [buffer || new Uint8Array(0), result.slice(index), byteLength - (buffer ? buffer.byteLength : 0)];
}
function toArrayBufferView(ArrayBufferViewCtor, input) {
let value = isIteratorResult(input) ? input.value : input;
if (value instanceof ArrayBufferViewCtor) {
if (ArrayBufferViewCtor === Uint8Array) {
return new ArrayBufferViewCtor(value.buffer, value.byteOffset, value.byteLength);
}
return value;
}
if (!value) {
return new ArrayBufferViewCtor(0);
}
if (typeof value === "string") {
value = encodeUtf8(value);
}
if (value instanceof ArrayBuffer) {
return new ArrayBufferViewCtor(value);
}
if (value instanceof SharedArrayBuf) {
return new ArrayBufferViewCtor(value);
}
if (isFlatbuffersByteBuffer(value)) {
return toArrayBufferView(ArrayBufferViewCtor, value.bytes());
}
return !ArrayBuffer.isView(value) ? ArrayBufferViewCtor.from(value) : value.byteLength <= 0 ? new ArrayBufferViewCtor(0) : new ArrayBufferViewCtor(value.buffer, value.byteOffset, value.byteLength / ArrayBufferViewCtor.BYTES_PER_ELEMENT);
}
var toInt8Array = (input) => toArrayBufferView(Int8Array, input);
var toInt16Array = (input) => toArrayBufferView(Int16Array, input);
var toInt32Array = (input) => toArrayBufferView(Int32Array, input);
var toBigInt64Array = (input) => toArrayBufferView(BigInt64Array, input);
var toUint8Array = (input) => toArrayBufferView(Uint8Array, input);
var toUint16Array = (input) => toArrayBufferView(Uint16Array, input);
var toUint32Array = (input) => toArrayBufferView(Uint32Array, input);
var toBigUint64Array = (input) => toArrayBufferView(BigUint64Array, input);
var toFloat32Array = (input) => toArrayBufferView(Float32Array, input);
var toFloat64Array = (input) => toArrayBufferView(Float64Array, input);
var toUint8ClampedArray = (input) => toArrayBufferView(Uint8ClampedArray, input);
var pump = (iterator) => {
iterator.next();
return iterator;
};
function* toArrayBufferViewIterator(ArrayCtor, source) {
const wrap = function* (x) {
yield x;
};
const buffers = typeof source === "string" ? wrap(source) : ArrayBuffer.isView(source) ? wrap(source) : source instanceof ArrayBuffer ? wrap(source) : source instanceof SharedArrayBuf ? wrap(source) : !isIterable(source) ? wrap(source) : source;
yield* pump(function* (it) {
let r = null;
do {
r = it.next(yield toArrayBufferView(ArrayCtor, r));
} while (!r.done);
}(buffers[Symbol.iterator]()));
return new ArrayCtor();
}
var toInt8ArrayIterator = (input) => toArrayBufferViewIterator(Int8Array, input);
var toInt16ArrayIterator = (input) => toArrayBufferViewIterator(Int16Array, input);
var toInt32ArrayIterator = (input) => toArrayBufferViewIterator(Int32Array, input);
var toUint8ArrayIterator = (input) => toArrayBufferViewIterator(Uint8Array, input);
var toUint16ArrayIterator = (input) => toArrayBufferViewIterator(Uint16Array, input);
var toUint32ArrayIterator = (input) => toArrayBufferViewIterator(Uint32Array, input);
var toFloat32ArrayIterator = (input) => toArrayBufferViewIterator(Float32Array, input);
var toFloat64ArrayIterator = (input) => toArrayBufferViewIterator(Float64Array, input);
var toUint8ClampedArrayIterator = (input) => toArrayBufferViewIterator(Uint8ClampedArray, input);
function toArrayBufferViewAsyncIterator(ArrayCtor, source) {
return __asyncGenerator(this, arguments, function* toArrayBufferViewAsyncIterator_1() {
if (isPromise(source)) {
return yield __await(yield __await(yield* __asyncDelegator(__asyncValues(toArrayBufferViewAsyncIterator(ArrayCtor, yield __await(source))))));
}
const wrap = function(x) {
return __asyncGenerator(this, arguments, function* () {
yield yield __await(yield __await(x));
});
};
const emit = function(source2) {
return __asyncGenerator(this, arguments, function* () {
yield __await(yield* __asyncDelegator(__asyncValues(pump(function* (it) {
let r = null;
do {
r = it.next(yield r === null || r === void 0 ? void 0 : r.value);
} while (!r.done);
}(source2[Symbol.iterator]())))));
});
};
const buffers = typeof source === "string" ? wrap(source) : ArrayBuffer.isView(source) ? wrap(source) : source instanceof ArrayBuffer ? wrap(source) : source instanceof SharedArrayBuf ? wrap(source) : isIterable(source) ? emit(source) : !isAsyncIterable(source) ? wrap(source) : source;
yield __await(
// otherwise if AsyncIterable, use it
yield* __asyncDelegator(__asyncValues(pump(function(it) {
return __asyncGenerator(this, arguments, function* () {
let r = null;
do {
r = yield __await(it.next(yield yield __await(toArrayBufferView(ArrayCtor, r))));
} while (!r.done);
});
}(buffers[Symbol.asyncIterator]()))))
);
return yield __await(new ArrayCtor());
});
}
var toInt8ArrayAsyncIterator = (input) => toArrayBufferViewAsyncIterator(Int8Array, input);
var toInt16ArrayAsyncIterator = (input) => toArrayBufferViewAsyncIterator(Int16Array, input);
var toInt32ArrayAsyncIterator = (input) => toArrayBufferViewAsyncIterator(Int32Array, input);
var toUint8ArrayAsyncIterator = (input) => toArrayBufferViewAsyncIterator(Uint8Array, input);
var toUint16ArrayAsyncIterator = (input) => toArrayBufferViewAsyncIterator(Uint16Array, input);
var toUint32ArrayAsyncIterator = (input) => toArrayBufferViewAsyncIterator(Uint32Array, input);
var toFloat32ArrayAsyncIterator = (input) => toArrayBufferViewAsyncIterator(Float32Array, input);
var toFloat64ArrayAsyncIterator = (input) => toArrayBufferViewAsyncIterator(Float64Array, input);
var toUint8ClampedArrayAsyncIterator = (input) => toArrayBufferViewAsyncIterator(Uint8ClampedArray, input);
function rebaseValueOffsets(offset, length, valueOffsets) {
if (offset !== 0) {
valueOffsets = valueOffsets.slice(0, length);
for (let i = -1, n = valueOffsets.length; ++i < n; ) {
valueOffsets[i] += offset;
}
}
return valueOffsets.subarray(0, length);
}
function compareArrayLike(a, b) {
let i = 0;
const n = a.length;
if (n !== b.length) {
return false;
}
if (n > 0) {
do {
if (a[i] !== b[i]) {
return false;
}
} while (++i < n);
}
return true;
}
// node_modules/apache-arrow/io/adapters.mjs
var adapters_default = {
fromIterable(source) {
return pump2(fromIterable(source));
},
fromAsyncIterable(source) {
return pump2(fromAsyncIterable(source));
},
fromDOMStream(source) {
return pump2(fromDOMStream(source));
},
fromNodeStream(stream2) {
return pump2(fromNodeStream(stream2));
},
// @ts-ignore
toDOMStream(source, options) {
throw new Error(`"toDOMStream" not available in this environment`);
},
// @ts-ignore
toNodeStream(source, options) {
throw new Error(`"toNodeStream" not available in this environment`);
}
};
var pump2 = (iterator) => {
iterator.next();
return iterator;
};
function* fromIterable(source) {
let done, threw = false;
let buffers = [], buffer;
let cmd, size, bufferLength = 0;
function byteRange() {
if (cmd === "peek") {
return joinUint8Arrays(buffers, size)[0];
}
[buffer, buffers, bufferLength] = joinUint8Arrays(buffers, size);
return buffer;
}
({ cmd, size } = (yield /* @__PURE__ */ (() => null)()) || { cmd: "read", size: 0 });
const it = toUint8ArrayIterator(source)[Symbol.iterator]();
try {
do {
({ done, value: buffer } = Number.isNaN(size - bufferLength) ? it.next() : it.next(size - bufferLength));
if (!done && buffer.byteLength > 0) {
buffers.push(buffer);
bufferLength += buffer.byteLength;
}
if (done || size <= bufferLength) {
do {
({ cmd, size } = yield byteRange());
} while (size < bufferLength);
}
} while (!done);
} catch (e) {
(threw = true) && typeof it.throw === "function" && it.throw(e);
} finally {
threw === false && typeof it.return === "function" && it.return(null);
}
return null;
}
function fromAsyncIterable(source) {
return __asyncGenerator(this, arguments, function* fromAsyncIterable_1() {
let done, threw = false;
let buffers = [], buffer;
let cmd, size, bufferLength = 0;
function byteRange() {
if (cmd === "peek") {
return joinUint8Arrays(buffers, size)[0];
}
[buffer, buffers, bufferLength] = joinUint8Arrays(buffers, size);
return buffer;
}
({ cmd, size } = (yield yield __await(/* @__PURE__ */ (() => null)())) || { cmd: "read", size: 0 });
const it = toUint8ArrayAsyncIterator(source)[Symbol.asyncIterator]();
try {
do {
({ done, value: buffer } = Number.isNaN(size - bufferLength) ? yield __await(it.next()) : yield __await(it.next(size - bufferLength)));
if (!done && buffer.byteLength > 0) {
buffers.push(buffer);
bufferLength += buffer.byteLength;
}
if (done || size <= bufferLength) {
do {
({ cmd, size } = yield yield __await(byteRange()));
} while (size < bufferLength);
}
} while (!done);
} catch (e) {
(threw = true) && typeof it.throw === "function" && (yield __await(it.throw(e)));
} finally {
threw === false && typeof it.return === "function" && (yield __await(it.return(new Uint8Array(0))));
}
return yield __await(null);
});
}
function fromDOMStream(source) {
return __asyncGenerator(this, arguments, function* fromDOMStream_1() {
let done = false, threw = false;
let buffers = [], buffer;
let cmd, size, bufferLength = 0;
function byteRange() {
if (cmd === "peek") {
return joinUint8Arrays(buffers, size)[0];
}
[buffer, buffers, bufferLength] = joinUint8Arrays(buffers, size);
return buffer;
}
({ cmd, size } = (yield yield __await(/* @__PURE__ */ (() => null)())) || { cmd: "read", size: 0 });
const it = new AdaptiveByteReader(source);
try {
do {
({ done, value: buffer } = Number.isNaN(size - bufferLength) ? yield __await(it["read"]()) : yield __await(it["read"](size - bufferLength)));
if (!done && buffer.byteLength > 0) {
buffers.push(toUint8Array(buffer));
bufferLength += buffer.byteLength;
}
if (done || size <= bufferLength) {
do {
({ cmd, size } = yield yield __await(byteRange()));
} while (size < bufferLength);
}
} while (!done);
} catch (e) {
(threw = true) && (yield __await(it["cancel"](e)));
} finally {
threw === false ? yield __await(it["cancel"]()) : source["locked"] && it.releaseLock();
}
return yield __await(null);
});
}
var AdaptiveByteReader = class {
constructor(source) {
this.source = source;
this.reader = null;
this.reader = this.source["getReader"]();
this.reader["closed"].catch(() => {
});
}
get closed() {
return this.reader ? this.reader["closed"].catch(() => {
}) : Promise.resolve();
}
releaseLock() {
if (this.reader) {
this.reader.releaseLock();
}
this.reader = null;
}
cancel(reason) {
return __awaiter(this, void 0, void 0, function* () {
const { reader, source } = this;
reader && (yield reader["cancel"](reason).catch(() => {
}));
source && (source["locked"] && this.releaseLock());
});
}
read(size) {
return __awaiter(this, void 0, void 0, function* () {
if (size === 0) {
return { done: this.reader == null, value: new Uint8Array(0) };
}
const result = yield this.reader.read();
!result.done && (result.value = toUint8Array(result));
return result;
});
}
};
var onEvent = (stream2, event) => {
const handler = (_) => resolve([event, _]);
let resolve;
return [event, handler, new Promise((r) => (resolve = r) && stream2["once"](event, handler))];
};
function fromNodeStream(stream2) {
return __asyncGenerator(this, arguments, function* fromNodeStream_1() {
const events = [];
let event = "error";
let done = false, err = null;
let cmd, size, bufferLength = 0;
let buffers = [], buffer;
function byteRange() {
if (cmd === "peek") {
return joinUint8Arrays(buffers, size)[0];
}
[buffer, buffers, bufferLength] = joinUint8Arrays(buffers, size);
return buffer;
}
({ cmd, size } = (yield yield __await(/* @__PURE__ */ (() => null)())) || { cmd: "read", size: 0 });
if (stream2["isTTY"]) {
yield yield __await(new Uint8Array(0));
return yield __await(null);
}
try {
events[0] = onEvent(stream2, "end");
events[1] = onEvent(stream2, "error");
do {
events[2] = onEvent(stream2, "readable");
[event, err] = yield __await(Promise.race(events.map((x) => x[2])));
if (event === "error") {
break;
}
if (!(done = event === "end")) {
if (!Number.isFinite(size - bufferLength)) {
buffer = toUint8Array(stream2["read"]());
} else {
buffer = toUint8Array(stream2["read"](size - bufferLength));
if (buffer.byteLength < size - bufferLength) {
buffer = toUint8Array(stream2["read"]());
}
}
if (buffer.byteLength > 0) {
buffers.push(buffer);
bufferLength += buffer.byteLength;
}
}
if (done || size <= bufferLength) {
do {
({ cmd, size } = yield yield __await(byteRange()));
} while (size < bufferLength);
}
} while (!done);
} finally {
yield __await(cleanup(events, event === "error" ? err : null));
}
return yield __await(null);
function cleanup(events2, err2) {
buffer = buffers = null;
return new Promise((resolve, reject) => {
for (const [evt, fn] of events2) {
stream2["off"](evt, fn);
}
try {
const destroy = stream2["destroy"];
destroy && destroy.call(stream2, err2);
err2 = void 0;
} catch (e) {
err2 = e || err2;
} finally {
err2 != null ? reject(err2) : resolve();
}
});
}
});
}
// node_modules/apache-arrow/fb/metadata-version.mjs
var MetadataVersion;
(function(MetadataVersion2) {
MetadataVersion2[MetadataVersion2["V1"] = 0] = "V1";
MetadataVersion2[MetadataVersion2["V2"] = 1] = "V2";
MetadataVersion2[MetadataVersion2["V3"] = 2] = "V3";
MetadataVersion2[MetadataVersion2["V4"] = 3] = "V4";
MetadataVersion2[MetadataVersion2["V5"] = 4] = "V5";
})(MetadataVersion || (MetadataVersion = {}));
// node_modules/apache-arrow/fb/union-mode.mjs
var UnionMode;
(function(UnionMode2) {
UnionMode2[UnionMode2["Sparse"] = 0] = "Sparse";
UnionMode2[UnionMode2["Dense"] = 1] = "Dense";
})(UnionMode || (UnionMode = {}));
// node_modules/apache-arrow/fb/precision.mjs
var Precision;
(function(Precision2) {
Precision2[Precision2["HALF"] = 0] = "HALF";
Precision2[Precision2["SINGLE"] = 1] = "SINGLE";
Precision2[Precision2["DOUBLE"] = 2] = "DOUBLE";
})(Precision || (Precision = {}));
// node_modules/apache-arrow/fb/date-unit.mjs
var DateUnit;
(function(DateUnit2) {
DateUnit2[DateUnit2["DAY"] = 0] = "DAY";
DateUnit2[DateUnit2["MILLISECOND"] = 1] = "MILLISECOND";
})(DateUnit || (DateUnit = {}));
// node_modules/apache-arrow/fb/time-unit.mjs
var TimeUnit;
(function(TimeUnit2) {
TimeUnit2[TimeUnit2["SECOND"] = 0] = "SECOND";
TimeUnit2[TimeUnit2["MILLISECOND"] = 1] = "MILLISECOND";
TimeUnit2[TimeUnit2["MICROSECOND"] = 2] = "MICROSECOND";
TimeUnit2[TimeUnit2["NANOSECOND"] = 3] = "NANOSECOND";
})(TimeUnit || (TimeUnit = {}));
// node_modules/apache-arrow/fb/interval-unit.mjs
var IntervalUnit;
(function(IntervalUnit2) {
IntervalUnit2[IntervalUnit2["YEAR_MONTH"] = 0] = "YEAR_MONTH";
IntervalUnit2[IntervalUnit2["DAY_TIME"] = 1] = "DAY_TIME";
IntervalUnit2[IntervalUnit2["MONTH_DAY_NANO"] = 2] = "MONTH_DAY_NANO";
})(IntervalUnit || (IntervalUnit = {}));
// node_modules/flatbuffers/mjs/constants.js
var SIZEOF_SHORT = 2;
var SIZEOF_INT = 4;
var FILE_IDENTIFIER_LENGTH = 4;
var SIZE_PREFIX_LENGTH = 4;
// node_modules/flatbuffers/mjs/utils.js
var int32 = new Int32Array(2);
var float32 = new Float32Array(int32.buffer);
var float64 = new Float64Array(int32.buffer);
var isLittleEndian = new Uint16Array(new Uint8Array([1, 0]).buffer)[0] === 1;
// node_modules/flatbuffers/mjs/encoding.js
var Encoding;
(function(Encoding2) {
Encoding2[Encoding2["UTF8_BYTES"] = 1] = "UTF8_BYTES";
Encoding2[Encoding2["UTF16_STRING"] = 2] = "UTF16_STRING";
})(Encoding || (Encoding = {}));
// node_modules/flatbuffers/mjs/byte-buffer.js
var ByteBuffer = class _ByteBuffer {
/**
* Create a new ByteBuffer with a given array of bytes (`Uint8Array`)
*/
constructor(bytes_) {
this.bytes_ = bytes_;
this.position_ = 0;
this.text_decoder_ = new TextDecoder();
}
/**
* Create and allocate a new ByteBuffer with a given size.
*/
static allocate(byte_size) {
return new _ByteBuffer(new Uint8Array(byte_size));
}
clear() {
this.position_ = 0;
}
/**
* Get the underlying `Uint8Array`.
*/
bytes() {
return this.bytes_;
}
/**
* Get the buffer's position.
*/
position() {
return this.position_;
}
/**
* Set the buffer's position.
*/
setPosition(position) {
this.position_ = position;
}
/**
* Get the buffer's capacity.
*/
capacity() {
return this.bytes_.length;
}
readInt8(offset) {
return this.readUint8(offset) << 24 >> 24;
}
readUint8(offset) {
return this.bytes_[offset];
}
readInt16(offset) {
return this.readUint16(offset) << 16 >> 16;
}
readUint16(offset) {
return this.bytes_[offset] | this.bytes_[offset + 1] << 8;
}
readInt32(offset) {
return this.bytes_[offset] | this.bytes_[offset + 1] << 8 | this.bytes_[offset + 2] << 16 | this.bytes_[offset + 3] << 24;
}
readUint32(offset) {
return this.readInt32(offset) >>> 0;
}
readInt64(offset) {
return BigInt.asIntN(64, BigInt(this.readUint32(offset)) + (BigInt(this.readUint32(offset + 4)) << BigInt(32)));
}
readUint64(offset) {
return BigInt.asUintN(64, BigInt(this.readUint32(offset)) + (BigInt(this.readUint32(offset + 4)) << BigInt(32)));
}
readFloat32(offset) {
int32[0] = this.readInt32(offset);
return float32[0];
}
readFloat64(offset) {
int32[isLittleEndian ? 0 : 1] = this.readInt32(offset);
int32[isLittleEndian ? 1 : 0] = this.readInt32(offset + 4);
return float64[0];
}
writeInt8(offset, value) {
this.bytes_[offset] = value;
}
writeUint8(offset, value) {
this.bytes_[offset] = value;
}
writeInt16(offset, value) {
this.bytes_[offset] = value;
this.bytes_[offset + 1] = value >> 8;
}
writeUint16(offset, value) {
this.bytes_[offset] = value;
this.bytes_[offset + 1] = value >> 8;
}
writeInt32(offset, value) {
this.bytes_[offset] = value;
this.bytes_[offset + 1] = value >> 8;
this.bytes_[offset + 2] = value >> 16;
this.bytes_[offset + 3] = value >> 24;
}
writeUint32(offset, value) {
this.bytes_[offset] = value;
this.bytes_[offset + 1] = value >> 8;
this.bytes_[offset + 2] = value >> 16;
this.bytes_[offset + 3] = value >> 24;
}
writeInt64(offset, value) {
this.writeInt32(offset, Number(BigInt.asIntN(32, value)));
this.writeInt32(offset + 4, Number(BigInt.asIntN(32, value >> BigInt(32))));
}
writeUint64(offset, value) {
this.writeUint32(offset, Number(BigInt.asUintN(32, value)));
this.writeUint32(offset + 4, Number(BigInt.asUintN(32, value >> BigInt(32))));
}
writeFloat32(offset, value) {
float32[0] = value;
this.writeInt32(offset, int32[0]);
}
writeFloat64(offset, value) {
float64[0] = value;
this.writeInt32(offset, int32[isLittleEndian ? 0 : 1]);
this.writeInt32(offset + 4, int32[isLittleEndian ? 1 : 0]);
}
/**
* Return the file identifier. Behavior is undefined for FlatBuffers whose
* schema does not include a file_identifier (likely points at padding or the
* start of a the root vtable).
*/
getBufferIdentifier() {
if (this.bytes_.length < this.position_ + SIZEOF_INT + FILE_IDENTIFIER_LENGTH) {
throw new Error("FlatBuffers: ByteBuffer is too short to contain an identifier.");
}
let result = "";
for (let i = 0; i < FILE_IDENTIFIER_LENGTH; i++) {
result += String.fromCharCode(this.readInt8(this.position_ + SIZEOF_INT + i));
}
return result;
}
/**
* Look up a field in the vtable, return an offset into the object, or 0 if the
* field is not present.
*/
__offset(bb_pos, vtable_offset) {
const vtable = bb_pos - this.readInt32(bb_pos);
return vtable_offset < this.readInt16(vtable) ? this.readInt16(vtable + vtable_offset) : 0;
}
/**
* Initialize any Table-derived type to point to the union at the given offset.
*/
__union(t, offset) {
t.bb_pos = offset + this.readInt32(offset);
t.bb = this;
return t;
}
/**
* Create a JavaScript string from UTF-8 data stored inside the FlatBuffer.
* This allocates a new string and converts to wide chars upon each access.
*
* To avoid the conversion to string, pass Encoding.UTF8_BYTES as the
* "optionalEncoding" argument. This is useful for avoiding conversion when
* the data will just be packaged back up in another FlatBuffer later on.
*
* @param offset
* @param opt_encoding Defaults to UTF16_STRING
*/
__string(offset, opt_encoding) {
offset += this.readInt32(offset);
const length = this.readInt32(offset);
offset += SIZEOF_INT;
const utf8bytes = this.bytes_.subarray(offset, offset + length);
if (opt_encoding === Encoding.UTF8_BYTES)
return utf8bytes;
else
return this.text_decoder_.decode(utf8bytes);
}
/**
* Handle unions that can contain string as its member, if a Table-derived type then initialize it,
* if a string then return a new one
*
* WARNING: strings are immutable in JS so we can't change the string that the user gave us, this
* makes the behaviour of __union_with_string different compared to __union
*/
__union_with_string(o, offset) {
if (typeof o === "string") {
return this.__string(offset);
}
return this.__union(o, offset);
}
/**
* Retrieve the relative offset stored at "offset"
*/
__indirect(offset) {
return offset + this.readInt32(offset);
}
/**
* Get the start of data of a vector whose offset is stored at "offset" in this object.
*/
__vector(offset) {
return offset + this.readInt32(offset) + SIZEOF_INT;
}
/**
* Get the length of a vector whose offset is stored at "offset" in this object.
*/
__vector_len(offset) {
return this.readInt32(offset + this.readInt32(offset));
}
__has_identifier(ident) {
if (ident.length != FILE_IDENTIFIER_LENGTH) {
throw new Error("FlatBuffers: file identifier must be length " + FILE_IDENTIFIER_LENGTH);
}
for (let i = 0; i < FILE_IDENTIFIER_LENGTH; i++) {
if (ident.charCodeAt(i) != this.readInt8(this.position() + SIZEOF_INT + i)) {
return false;
}
}
return true;
}
/**
* A helper function for generating list for obj api
*/
createScalarList(listAccessor, listLength) {
const ret = [];
for (let i = 0; i < listLength; ++i) {
const val = listAccessor(i);
if (val !== null) {
ret.push(val);
}
}
return ret;
}
/**
* A helper function for generating list for obj api
* @param listAccessor function that accepts an index and return data at that index
* @param listLength listLength
* @param res result list
*/
createObjList(listAccessor, listLength) {
const ret = [];
for (let i = 0; i < listLength; ++i) {
const val = listAccessor(i);
if (val !== null) {
ret.push(val.unpack());
}
}
return ret;
}
};
// node_modules/flatbuffers/mjs/builder.js
var Builder = class _Builder {
/**
* Create a FlatBufferBuilder.
*/
constructor(opt_initial_size) {
this.minalign = 1;
this.vtable = null;
this.vtable_in_use = 0;
this.isNested = false;
this.object_start = 0;
this.vtables = [];
this.vector_num_elems = 0;
this.force_defaults = false;
this.string_maps = null;
this.text_encoder = new TextEncoder();
let initial_size;
if (!opt_initial_size) {
initial_size = 1024;
} else {
initial_size = opt_initial_size;
}
this.bb = ByteBuffer.allocate(initial_size);
this.space = initial_size;
}
clear() {
this.bb.clear();
this.space = this.bb.capacity();
this.minalign = 1;
this.vtable = null;
this.vtable_in_use = 0;
this.isNested = false;
this.object_start = 0;
this.vtables = [];
this.vector_num_elems = 0;
this.force_defaults = false;
this.string_maps = null;
}
/**
* In order to save space, fields that are set to their default value
* don't get serialized into the buffer. Forcing defaults provides a
* way to manually disable this optimization.
*
* @param forceDefaults true always serializes default values
*/
forceDefaults(forceDefaults) {
this.force_defaults = forceDefaults;
}
/**
* Get the ByteBuffer representing the FlatBuffer. Only call this after you've
* called finish(). The actual data starts at the ByteBuffer's current position,
* not necessarily at 0.
*/
dataBuffer() {
return this.bb;
}
/**
* Get the bytes representing the FlatBuffer. Only call this after you've
* called finish().
*/
asUint8Array() {
return this.bb.bytes().subarray(this.bb.position(), this.bb.position() + this.offset());
}
/**
* Prepare to write an element of `size` after `additional_bytes` have been
* written, e.g. if you write a string, you need to align such the int length
* field is aligned to 4 bytes, and the string data follows it directly. If all
* you need to do is alignment, `additional_bytes` will be 0.
*
* @param size This is the of the new element to write
* @param additional_bytes The padding size
*/
prep(size, additional_bytes) {
if (size > this.minalign) {
this.minalign = size;
}
const align_size = ~(this.bb.capacity() - this.space + additional_bytes) + 1 & size - 1;
while (this.space < align_size + size + additional_bytes) {
const old_buf_size = this.bb.capacity();
this.bb = _Builder.growByteBuffer(this.bb);
this.space += this.bb.capacity() - old_buf_size;
}
this.pad(align_size);
}
pad(byte_size) {
for (let i = 0; i < byte_size; i++) {
this.bb.writeInt8(--this.space, 0);
}
}
writeInt8(value) {
this.bb.writeInt8(this.space -= 1, value);
}
writeInt16(value) {
this.bb.writeInt16(this.space -= 2, value);
}
writeInt32(value) {
this.bb.writeInt32(this.space -= 4, value);
}
writeInt64(value) {
this.bb.writeInt64(this.space -= 8, value);
}
writeFloat32(value) {
this.bb.writeFloat32(this.space -= 4, value);
}
writeFloat64(value) {
this.bb.writeFloat64(this.space -= 8, value);
}
/**
* Add an `int8` to the buffer, properly aligned, and grows the buffer (if necessary).
* @param value The `int8` to add the buffer.
*/
addInt8(value) {
this.prep(1, 0);
this.writeInt8(value);
}
/**
* Add an `int16` to the buffer, properly aligned, and grows the buffer (if necessary).
* @param value The `int16` to add the buffer.
*/
addInt16(value) {
this.prep(2, 0);
this.writeInt16(value);
}
/**
* Add an `int32` to the buffer, properly aligned, and grows the buffer (if necessary).
* @param value The `int32` to add the buffer.
*/
addInt32(value) {
this.prep(4, 0);
this.writeInt32(value);
}
/**
* Add an `int64` to the buffer, properly aligned, and grows the buffer (if necessary).
* @param value The `int64` to add the buffer.
*/
addInt64(value) {
this.prep(8, 0);
this.writeInt64(value);
}
/**
* Add a `float32` to the buffer, properly aligned, and grows the buffer (if necessary).
* @param value The `float32` to add the buffer.
*/
addFloat32(value) {
this.prep(4, 0);
this.writeFloat32(value);
}
/**
* Add a `float64` to the buffer, properly aligned, and grows the buffer (if necessary).
* @param value The `float64` to add the buffer.
*/
addFloat64(value) {
this.prep(8, 0);
this.writeFloat64(value);
}
addFieldInt8(voffset, value, defaultValue) {
if (this.force_defaults || value != defaultValue) {
this.addInt8(value);
this.slot(voffset);
}
}
addFieldInt16(voffset, value, defaultValue) {
if (this.force_defaults || value != defaultValue) {
this.addInt16(value);
this.slot(voffset);
}
}
addFieldInt32(voffset, value, defaultValue) {
if (this.force_defaults || value != defaultValue) {
this.addInt32(value);
this.slot(voffset);
}
}
addFieldInt64(voffset, value, defaultValue) {
if (this.force_defaults || value !== defaultValue) {
this.addInt64(value);
this.slot(voffset);
}
}
addFieldFloat32(voffset, value, defaultValue) {
if (this.force_defaults || value != defaultValue) {
this.addFloat32(value);
this.slot(voffset);
}
}
addFieldFloat64(voffset, value, defaultValue) {
if (this.force_defaults || value != defaultValue) {
this.addFloat64(value);
this.slot(voffset);
}
}
addFieldOffset(voffset, value, defaultValue) {
if (this.force_defaults || value != defaultValue) {
this.addOffset(value);
this.slot(voffset);
}
}
/**
* Structs are stored inline, so nothing additional is being added. `d` is always 0.
*/
addFieldStruct(voffset, value, defaultValue) {
if (value != defaultValue) {
this.nested(value);
this.slot(voffset);
}
}
/**
* Structures are always stored inline, they need to be created right
* where they're used. You'll get this assertion failure if you
* created it elsewhere.
*/
nested(obj) {
if (obj != this.offset()) {
throw new TypeError("FlatBuffers: struct must be serialized inline.");
}
}
/**
* Should not be creating any other object, string or vector
* while an object is being constructed
*/
notNested() {
if (this.isNested) {
throw new TypeError("FlatBuffers: object serialization must not be nested.");
}
}
/**
* Set the current vtable at `voffset` to the current location in the buffer.
*/
slot(voffset) {
if (this.vtable !== null)
this.vtable[voffset] = this.offset();
}
/**
* @returns Offset relative to the end of the buffer.
*/
offset() {
return this.bb.capacity() - this.space;
}
/**
* Doubles the size of the backing ByteBuffer and copies the old data towards
* the end of the new buffer (since we build the buffer backwards).
*
* @param bb The current buffer with the existing data
* @returns A new byte buffer with the old data copied
* to it. The data is located at the end of the buffer.
*
* uint8Array.set() formally takes {Array<number>|ArrayBufferView}, so to pass
* it a uint8Array we need to suppress the type check:
* @suppress {checkTypes}
*/
static growByteBuffer(bb) {
const old_buf_size = bb.capacity();
if (old_buf_size & 3221225472) {
throw new Error("FlatBuffers: cannot grow buffer beyond 2 gigabytes.");
}
const new_buf_size = old_buf_size << 1;
const nbb = ByteBuffer.allocate(new_buf_size);
nbb.setPosition(new_buf_size - old_buf_size);
nbb.bytes().set(bb.bytes(), new_buf_size - old_buf_size);
return nbb;
}
/**
* Adds on offset, relative to where it will be written.
*
* @param offset The offset to add.
*/
addOffset(offset) {
this.prep(SIZEOF_INT, 0);
this.writeInt32(this.offset() - offset + SIZEOF_INT);
}
/**
* Start encoding a new object in the buffer. Users will not usually need to
* call this directly. The FlatBuffers compiler will generate helper methods
* that call this method internally.
*/
startObject(numfields) {
this.notNested();
if (this.vtable == null) {
this.vtable = [];
}
this.vtable_in_use = numfields;
for (let i = 0; i < numfields; i++) {
this.vtable[i] = 0;
}
this.isNested = true;
this.object_start = this.offset();
}
/**
* Finish off writing the object that is under construction.
*
* @returns The offset to the object inside `dataBuffer`
*/
endObject() {
if (this.vtable == null || !this.isNested) {
throw new Error("FlatBuffers: endObject called without startObject");
}
this.addInt32(0);
const vtableloc = this.offset();
let i = this.vtable_in_use - 1;
for (; i >= 0 && this.vtable[i] == 0; i--) {
}
const trimmed_size = i + 1;
for (; i >= 0; i--) {
this.addInt16(this.vtable[i] != 0 ? vtableloc - this.vtable[i] : 0);
}
const standard_fields = 2;
this.addInt16(vtableloc - this.object_start);
const len = (trimmed_size + standard_fields) * SIZEOF_SHORT;
this.addInt16(len);
let existing_vtable = 0;
const vt1 = this.space;
outer_loop: for (i = 0; i < this.vtables.length; i++) {
const vt2 = this.bb.capacity() - this.vtables[i];
if (len == this.bb.readInt16(vt2)) {
for (let j = SIZEOF_SHORT; j < len; j += SIZEOF_SHORT) {
if (this.bb.readInt16(vt1 + j) != this.bb.readInt16(vt2 + j)) {
continue outer_loop;
}
}
existing_vtable = this.vtables[i];
break;
}
}
if (existing_vtable) {
this.space = this.bb.capacity() - vtableloc;
this.bb.writeInt32(this.space, existing_vtable - vtableloc);
} else {
this.vtables.push(this.offset());
this.bb.writeInt32(this.bb.capacity() - vtableloc, this.offset() - vtableloc);
}
this.isNested = false;
return vtableloc;
}
/**
* Finalize a buffer, poiting to the given `root_table`.
*/
finish(root_table, opt_file_identifier, opt_size_prefix) {
const size_prefix = opt_size_prefix ? SIZE_PREFIX_LENGTH : 0;
if (opt_file_identifier) {
const file_identifier = opt_file_identifier;
this.prep(this.minalign, SIZEOF_INT + FILE_IDENTIFIER_LENGTH + size_prefix);
if (file_identifier.length != FILE_IDENTIFIER_LENGTH) {
throw new TypeError("FlatBuffers: file identifier must be length " + FILE_IDENTIFIER_LENGTH);
}
for (let i = FILE_IDENTIFIER_LENGTH - 1; i >= 0; i--) {
this.writeInt8(file_identifier.charCodeAt(i));
}
}
this.prep(this.minalign, SIZEOF_INT + size_prefix);
this.addOffset(root_table);
if (size_prefix) {
this.addInt32(this.bb.capacity() - this.space);
}
this.bb.setPosition(this.space);
}
/**
* Finalize a size prefixed buffer, pointing to the given `root_table`.
*/
finishSizePrefixed(root_table, opt_file_identifier) {
this.finish(root_table, opt_file_identifier, true);
}
/**
* This checks a required field has been set in a given table that has
* just been constructed.
*/
requiredField(table, field) {
const table_start = this.bb.capacity() - table;
const vtable_start = table_start - this.bb.readInt32(table_start);
const ok = field < this.bb.readInt16(vtable_start) && this.bb.readInt16(vtable_start + field) != 0;
if (!ok) {
throw new TypeError("FlatBuffers: field " + field + " must be set");
}
}
/**
* Start a new array/vector of objects. Users usually will not call
* this directly. The FlatBuffers compiler will create a start/end
* method for vector types in generated code.
*
* @param elem_size The size of each element in the array
* @param num_elems The number of elements in the array
* @param alignment The alignment of the array
*/
startVector(elem_size, num_elems, alignment) {
this.notNested();
this.vector_num_elems = num_elems;
this.prep(SIZEOF_INT, elem_size * num_elems);
this.prep(alignment, elem_size * num_elems);
}
/**
* Finish off the creation of an array and all its elements. The array must be
* created with `startVector`.
*
* @returns The offset at which the newly created array
* starts.
*/
endVector() {
this.writeInt32(this.vector_num_elems);
return this.offset();
}
/**
* Encode the string `s` in the buffer using UTF-8. If the string passed has
* already been seen, we return the offset of the already written string
*
* @param s The string to encode
* @return The offset in the buffer where the encoded string starts
*/
createSharedString(s) {
if (!s) {
return 0;
}
if (!this.string_maps) {
this.string_maps = /* @__PURE__ */ new Map();
}
if (this.string_maps.has(s)) {
return this.string_maps.get(s);
}
const offset = this.createString(s);
this.string_maps.set(s, offset);
return offset;
}
/**
* Encode the string `s` in the buffer using UTF-8. If a Uint8Array is passed
* instead of a string, it is assumed to contain valid UTF-8 encoded data.
*
* @param s The string to encode
* @return The offset in the buffer where the encoded string starts
*/
createString(s) {
if (s === null || s === void 0) {
return 0;
}
let utf8;
if (s instanceof Uint8Array) {
utf8 = s;
} else {
utf8 = this.text_encoder.encode(s);
}
this.addInt8(0);
this.startVector(1, utf8.length, 1);
this.bb.setPosition(this.space -= utf8.length);
this.bb.bytes().set(utf8, this.space);
return this.endVector();
}
/**
* Create a byte vector.
*
* @param v The bytes to add
* @returns The offset in the buffer where the byte vector starts
*/
createByteVector(v) {
if (v === null || v === void 0) {
return 0;
}
this.startVector(1, v.length, 1);
this.bb.setPosition(this.space -= v.length);
this.bb.bytes().set(v, this.space);
return this.endVector();
}
/**
* A helper function to pack an object
*
* @returns offset of obj
*/
createObjectOffset(obj)