This commit is contained in:
dela
2026-02-21 18:27:49 +08:00
parent 0ac4b23f07
commit 5dc86ccfbf
270 changed files with 49508 additions and 4636 deletions

View File

@@ -0,0 +1,16 @@
export interface KeyDecoder {
canBeCached(byteLength: number): boolean;
decode(bytes: Uint8Array, inputOffset: number, byteLength: number): string;
}
export declare class CachedKeyDecoder implements KeyDecoder {
hit: number;
miss: number;
private readonly caches;
readonly maxKeyLength: number;
readonly maxLengthPerKey: number;
constructor(maxKeyLength?: number, maxLengthPerKey?: number);
canBeCached(byteLength: number): boolean;
private find;
private store;
decode(bytes: Uint8Array, inputOffset: number, byteLength: number): string;
}

View File

@@ -0,0 +1,62 @@
import { utf8DecodeJs } from "./utils/utf8.mjs";
const DEFAULT_MAX_KEY_LENGTH = 16;
const DEFAULT_MAX_LENGTH_PER_KEY = 16;
export class CachedKeyDecoder {
hit = 0;
miss = 0;
caches;
maxKeyLength;
maxLengthPerKey;
constructor(maxKeyLength = DEFAULT_MAX_KEY_LENGTH, maxLengthPerKey = DEFAULT_MAX_LENGTH_PER_KEY) {
this.maxKeyLength = maxKeyLength;
this.maxLengthPerKey = maxLengthPerKey;
// avoid `new Array(N)`, which makes a sparse array,
// because a sparse array is typically slower than a non-sparse array.
this.caches = [];
for (let i = 0; i < this.maxKeyLength; i++) {
this.caches.push([]);
}
}
canBeCached(byteLength) {
return byteLength > 0 && byteLength <= this.maxKeyLength;
}
find(bytes, inputOffset, byteLength) {
const records = this.caches[byteLength - 1];
FIND_CHUNK: for (const record of records) {
const recordBytes = record.bytes;
for (let j = 0; j < byteLength; j++) {
if (recordBytes[j] !== bytes[inputOffset + j]) {
continue FIND_CHUNK;
}
}
return record.str;
}
return null;
}
store(bytes, value) {
const records = this.caches[bytes.length - 1];
const record = { bytes, str: value };
if (records.length >= this.maxLengthPerKey) {
// `records` are full!
// Set `record` to an arbitrary position.
records[(Math.random() * records.length) | 0] = record;
}
else {
records.push(record);
}
}
decode(bytes, inputOffset, byteLength) {
const cachedValue = this.find(bytes, inputOffset, byteLength);
if (cachedValue != null) {
this.hit++;
return cachedValue;
}
this.miss++;
const str = utf8DecodeJs(bytes, inputOffset, byteLength);
// Ensure to copy a slice of bytes because the bytes may be a NodeJS Buffer and Buffer#slice() returns a reference to its internal ArrayBuffer.
const slicedCopyOfBytes = Uint8Array.prototype.slice.call(bytes, inputOffset, inputOffset + byteLength);
this.store(slicedCopyOfBytes, str);
return str;
}
}
//# sourceMappingURL=CachedKeyDecoder.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"CachedKeyDecodermjs","sourceRoot":"","sources":["../src/CachedKeyDecoder.ts"],"names":[],"mappings":"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"}

View File

@@ -0,0 +1,3 @@
export declare class DecodeError extends Error {
constructor(message: string);
}

14
node_modules/@msgpack/msgpack/dist.esm/DecodeError.mjs generated vendored Normal file
View File

@@ -0,0 +1,14 @@
export class DecodeError extends Error {
constructor(message) {
super(message);
// fix the prototype chain in a cross-platform way
const proto = Object.create(DecodeError.prototype);
Object.setPrototypeOf(this, proto);
Object.defineProperty(this, "name", {
configurable: true,
enumerable: false,
value: DecodeError.name,
});
}
}
//# sourceMappingURL=DecodeError.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"DecodeErrormjs","sourceRoot":"","sources":["../src/DecodeError.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpC,YAAY,OAAe,EAAE;QAC3B,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,kDAAkD;QAClD,MAAM,KAAK,GAAiC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;QACjF,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAEnC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE;YAClC,YAAY,EAAE,IAAI;YAClB,UAAU,EAAE,KAAK;YACjB,KAAK,EAAE,WAAW,CAAC,IAAI;SACxB,CAAC,CAAC;IAAA,CACJ;CACF"}

136
node_modules/@msgpack/msgpack/dist.esm/Decoder.d.ts generated vendored Normal file
View File

@@ -0,0 +1,136 @@
import type { ContextOf } from "./context.ts";
import type { ExtensionCodecType } from "./ExtensionCodec.ts";
import type { KeyDecoder } from "./CachedKeyDecoder.ts";
export type DecoderOptions<ContextType = undefined> = Readonly<Partial<{
extensionCodec: ExtensionCodecType<ContextType>;
/**
* Decodes Int64 and Uint64 as bigint if it's set to true.
* Depends on ES2020's {@link DataView#getBigInt64} and
* {@link DataView#getBigUint64}.
*
* Defaults to false.
*/
useBigInt64: boolean;
/**
* By default, string values will be decoded as UTF-8 strings. However, if this option is true,
* string values will be returned as Uint8Arrays without additional decoding.
*
* This is useful if the strings may contain invalid UTF-8 sequences.
*
* Note that this option only applies to string values, not map keys. Additionally, when
* enabled, raw string length is limited by the maxBinLength option.
*/
rawStrings: boolean;
/**
* Maximum string length.
*
* Defaults to 4_294_967_295 (UINT32_MAX).
*/
maxStrLength: number;
/**
* Maximum binary length.
*
* Defaults to 4_294_967_295 (UINT32_MAX).
*/
maxBinLength: number;
/**
* Maximum array length.
*
* Defaults to 4_294_967_295 (UINT32_MAX).
*/
maxArrayLength: number;
/**
* Maximum map length.
*
* Defaults to 4_294_967_295 (UINT32_MAX).
*/
maxMapLength: number;
/**
* Maximum extension length.
*
* Defaults to 4_294_967_295 (UINT32_MAX).
*/
maxExtLength: number;
/**
* An object key decoder. Defaults to the shared instance of {@link CachedKeyDecoder}.
* `null` is a special value to disable the use of the key decoder at all.
*/
keyDecoder: KeyDecoder | null;
/**
* A function to convert decoded map key to a valid JS key type.
*
* Defaults to a function that throws an error if the key is not a string or a number.
*/
mapKeyConverter: (key: unknown) => MapKeyType;
}>> & ContextOf<ContextType>;
type MapKeyType = string | number;
export declare class Decoder<ContextType = undefined> {
private readonly extensionCodec;
private readonly context;
private readonly useBigInt64;
private readonly rawStrings;
private readonly maxStrLength;
private readonly maxBinLength;
private readonly maxArrayLength;
private readonly maxMapLength;
private readonly maxExtLength;
private readonly keyDecoder;
private readonly mapKeyConverter;
private totalPos;
private pos;
private view;
private bytes;
private headByte;
private readonly stack;
private entered;
constructor(options?: DecoderOptions<ContextType>);
private clone;
private reinitializeState;
private setBuffer;
private appendBuffer;
private hasRemaining;
private createExtraByteError;
/**
* @throws {@link DecodeError}
* @throws {@link RangeError}
*/
decode(buffer: ArrayLike<number> | ArrayBufferView | ArrayBufferLike): unknown;
decodeMulti(buffer: ArrayLike<number> | ArrayBufferView | ArrayBufferLike): Generator<unknown, void, unknown>;
decodeAsync(stream: AsyncIterable<ArrayLike<number> | ArrayBufferView | ArrayBufferLike>): Promise<unknown>;
decodeArrayStream(stream: AsyncIterable<ArrayLike<number> | ArrayBufferView | ArrayBufferLike>): AsyncGenerator<unknown, void, unknown>;
decodeStream(stream: AsyncIterable<ArrayLike<number> | ArrayBufferView | ArrayBufferLike>): AsyncGenerator<unknown, void, unknown>;
private decodeMultiAsync;
private doDecodeSync;
private readHeadByte;
private complete;
private readArraySize;
private pushMapState;
private pushArrayState;
private decodeString;
/**
* @throws {@link RangeError}
*/
private decodeUtf8String;
private stateIsMapKey;
/**
* @throws {@link RangeError}
*/
private decodeBinary;
private decodeExtension;
private lookU8;
private lookU16;
private lookU32;
private readU8;
private readI8;
private readU16;
private readI16;
private readU32;
private readI32;
private readU64;
private readI64;
private readU64AsBigInt;
private readI64AsBigInt;
private readF32;
private readF64;
}
export {};

734
node_modules/@msgpack/msgpack/dist.esm/Decoder.mjs generated vendored Normal file
View File

@@ -0,0 +1,734 @@
import { prettyByte } from "./utils/prettyByte.mjs";
import { ExtensionCodec } from "./ExtensionCodec.mjs";
import { getInt64, getUint64, UINT32_MAX } from "./utils/int.mjs";
import { utf8Decode } from "./utils/utf8.mjs";
import { ensureUint8Array } from "./utils/typedArrays.mjs";
import { CachedKeyDecoder } from "./CachedKeyDecoder.mjs";
import { DecodeError } from "./DecodeError.mjs";
const STATE_ARRAY = "array";
const STATE_MAP_KEY = "map_key";
const STATE_MAP_VALUE = "map_value";
const mapKeyConverter = (key) => {
if (typeof key === "string" || typeof key === "number") {
return key;
}
throw new DecodeError("The type of key must be string or number but " + typeof key);
};
class StackPool {
stack = [];
stackHeadPosition = -1;
get length() {
return this.stackHeadPosition + 1;
}
top() {
return this.stack[this.stackHeadPosition];
}
pushArrayState(size) {
const state = this.getUninitializedStateFromPool();
state.type = STATE_ARRAY;
state.position = 0;
state.size = size;
state.array = new Array(size);
}
pushMapState(size) {
const state = this.getUninitializedStateFromPool();
state.type = STATE_MAP_KEY;
state.readCount = 0;
state.size = size;
state.map = {};
}
getUninitializedStateFromPool() {
this.stackHeadPosition++;
if (this.stackHeadPosition === this.stack.length) {
const partialState = {
type: undefined,
size: 0,
array: undefined,
position: 0,
readCount: 0,
map: undefined,
key: null,
};
this.stack.push(partialState);
}
return this.stack[this.stackHeadPosition];
}
release(state) {
const topStackState = this.stack[this.stackHeadPosition];
if (topStackState !== state) {
throw new Error("Invalid stack state. Released state is not on top of the stack.");
}
if (state.type === STATE_ARRAY) {
const partialState = state;
partialState.size = 0;
partialState.array = undefined;
partialState.position = 0;
partialState.type = undefined;
}
if (state.type === STATE_MAP_KEY || state.type === STATE_MAP_VALUE) {
const partialState = state;
partialState.size = 0;
partialState.map = undefined;
partialState.readCount = 0;
partialState.type = undefined;
}
this.stackHeadPosition--;
}
reset() {
this.stack.length = 0;
this.stackHeadPosition = -1;
}
}
const HEAD_BYTE_REQUIRED = -1;
const EMPTY_VIEW = new DataView(new ArrayBuffer(0));
const EMPTY_BYTES = new Uint8Array(EMPTY_VIEW.buffer);
try {
// IE11: The spec says it should throw RangeError,
// IE11: but in IE11 it throws TypeError.
EMPTY_VIEW.getInt8(0);
}
catch (e) {
if (!(e instanceof RangeError)) {
throw new Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access");
}
}
const MORE_DATA = new RangeError("Insufficient data");
const sharedCachedKeyDecoder = new CachedKeyDecoder();
export class Decoder {
extensionCodec;
context;
useBigInt64;
rawStrings;
maxStrLength;
maxBinLength;
maxArrayLength;
maxMapLength;
maxExtLength;
keyDecoder;
mapKeyConverter;
totalPos = 0;
pos = 0;
view = EMPTY_VIEW;
bytes = EMPTY_BYTES;
headByte = HEAD_BYTE_REQUIRED;
stack = new StackPool();
entered = false;
constructor(options) {
this.extensionCodec = options?.extensionCodec ?? ExtensionCodec.defaultCodec;
this.context = options?.context; // needs a type assertion because EncoderOptions has no context property when ContextType is undefined
this.useBigInt64 = options?.useBigInt64 ?? false;
this.rawStrings = options?.rawStrings ?? false;
this.maxStrLength = options?.maxStrLength ?? UINT32_MAX;
this.maxBinLength = options?.maxBinLength ?? UINT32_MAX;
this.maxArrayLength = options?.maxArrayLength ?? UINT32_MAX;
this.maxMapLength = options?.maxMapLength ?? UINT32_MAX;
this.maxExtLength = options?.maxExtLength ?? UINT32_MAX;
this.keyDecoder = options?.keyDecoder !== undefined ? options.keyDecoder : sharedCachedKeyDecoder;
this.mapKeyConverter = options?.mapKeyConverter ?? mapKeyConverter;
}
clone() {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
return new Decoder({
extensionCodec: this.extensionCodec,
context: this.context,
useBigInt64: this.useBigInt64,
rawStrings: this.rawStrings,
maxStrLength: this.maxStrLength,
maxBinLength: this.maxBinLength,
maxArrayLength: this.maxArrayLength,
maxMapLength: this.maxMapLength,
maxExtLength: this.maxExtLength,
keyDecoder: this.keyDecoder,
});
}
reinitializeState() {
this.totalPos = 0;
this.headByte = HEAD_BYTE_REQUIRED;
this.stack.reset();
// view, bytes, and pos will be re-initialized in setBuffer()
}
setBuffer(buffer) {
const bytes = ensureUint8Array(buffer);
this.bytes = bytes;
this.view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
this.pos = 0;
}
appendBuffer(buffer) {
if (this.headByte === HEAD_BYTE_REQUIRED && !this.hasRemaining(1)) {
this.setBuffer(buffer);
}
else {
const remainingData = this.bytes.subarray(this.pos);
const newData = ensureUint8Array(buffer);
// concat remainingData + newData
const newBuffer = new Uint8Array(remainingData.length + newData.length);
newBuffer.set(remainingData);
newBuffer.set(newData, remainingData.length);
this.setBuffer(newBuffer);
}
}
hasRemaining(size) {
return this.view.byteLength - this.pos >= size;
}
createExtraByteError(posToShow) {
const { view, pos } = this;
return new RangeError(`Extra ${view.byteLength - pos} of ${view.byteLength} byte(s) found at buffer[${posToShow}]`);
}
/**
* @throws {@link DecodeError}
* @throws {@link RangeError}
*/
decode(buffer) {
if (this.entered) {
const instance = this.clone();
return instance.decode(buffer);
}
try {
this.entered = true;
this.reinitializeState();
this.setBuffer(buffer);
const object = this.doDecodeSync();
if (this.hasRemaining(1)) {
throw this.createExtraByteError(this.pos);
}
return object;
}
finally {
this.entered = false;
}
}
*decodeMulti(buffer) {
if (this.entered) {
const instance = this.clone();
yield* instance.decodeMulti(buffer);
return;
}
try {
this.entered = true;
this.reinitializeState();
this.setBuffer(buffer);
while (this.hasRemaining(1)) {
yield this.doDecodeSync();
}
}
finally {
this.entered = false;
}
}
async decodeAsync(stream) {
if (this.entered) {
const instance = this.clone();
return instance.decodeAsync(stream);
}
try {
this.entered = true;
let decoded = false;
let object;
for await (const buffer of stream) {
if (decoded) {
this.entered = false;
throw this.createExtraByteError(this.totalPos);
}
this.appendBuffer(buffer);
try {
object = this.doDecodeSync();
decoded = true;
}
catch (e) {
if (!(e instanceof RangeError)) {
throw e; // rethrow
}
// fallthrough
}
this.totalPos += this.pos;
}
if (decoded) {
if (this.hasRemaining(1)) {
throw this.createExtraByteError(this.totalPos);
}
return object;
}
const { headByte, pos, totalPos } = this;
throw new RangeError(`Insufficient data in parsing ${prettyByte(headByte)} at ${totalPos} (${pos} in the current buffer)`);
}
finally {
this.entered = false;
}
}
decodeArrayStream(stream) {
return this.decodeMultiAsync(stream, true);
}
decodeStream(stream) {
return this.decodeMultiAsync(stream, false);
}
async *decodeMultiAsync(stream, isArray) {
if (this.entered) {
const instance = this.clone();
yield* instance.decodeMultiAsync(stream, isArray);
return;
}
try {
this.entered = true;
let isArrayHeaderRequired = isArray;
let arrayItemsLeft = -1;
for await (const buffer of stream) {
if (isArray && arrayItemsLeft === 0) {
throw this.createExtraByteError(this.totalPos);
}
this.appendBuffer(buffer);
if (isArrayHeaderRequired) {
arrayItemsLeft = this.readArraySize();
isArrayHeaderRequired = false;
this.complete();
}
try {
while (true) {
yield this.doDecodeSync();
if (--arrayItemsLeft === 0) {
break;
}
}
}
catch (e) {
if (!(e instanceof RangeError)) {
throw e; // rethrow
}
// fallthrough
}
this.totalPos += this.pos;
}
}
finally {
this.entered = false;
}
}
doDecodeSync() {
DECODE: while (true) {
const headByte = this.readHeadByte();
let object;
if (headByte >= 0xe0) {
// negative fixint (111x xxxx) 0xe0 - 0xff
object = headByte - 0x100;
}
else if (headByte < 0xc0) {
if (headByte < 0x80) {
// positive fixint (0xxx xxxx) 0x00 - 0x7f
object = headByte;
}
else if (headByte < 0x90) {
// fixmap (1000 xxxx) 0x80 - 0x8f
const size = headByte - 0x80;
if (size !== 0) {
this.pushMapState(size);
this.complete();
continue DECODE;
}
else {
object = {};
}
}
else if (headByte < 0xa0) {
// fixarray (1001 xxxx) 0x90 - 0x9f
const size = headByte - 0x90;
if (size !== 0) {
this.pushArrayState(size);
this.complete();
continue DECODE;
}
else {
object = [];
}
}
else {
// fixstr (101x xxxx) 0xa0 - 0xbf
const byteLength = headByte - 0xa0;
object = this.decodeString(byteLength, 0);
}
}
else if (headByte === 0xc0) {
// nil
object = null;
}
else if (headByte === 0xc2) {
// false
object = false;
}
else if (headByte === 0xc3) {
// true
object = true;
}
else if (headByte === 0xca) {
// float 32
object = this.readF32();
}
else if (headByte === 0xcb) {
// float 64
object = this.readF64();
}
else if (headByte === 0xcc) {
// uint 8
object = this.readU8();
}
else if (headByte === 0xcd) {
// uint 16
object = this.readU16();
}
else if (headByte === 0xce) {
// uint 32
object = this.readU32();
}
else if (headByte === 0xcf) {
// uint 64
if (this.useBigInt64) {
object = this.readU64AsBigInt();
}
else {
object = this.readU64();
}
}
else if (headByte === 0xd0) {
// int 8
object = this.readI8();
}
else if (headByte === 0xd1) {
// int 16
object = this.readI16();
}
else if (headByte === 0xd2) {
// int 32
object = this.readI32();
}
else if (headByte === 0xd3) {
// int 64
if (this.useBigInt64) {
object = this.readI64AsBigInt();
}
else {
object = this.readI64();
}
}
else if (headByte === 0xd9) {
// str 8
const byteLength = this.lookU8();
object = this.decodeString(byteLength, 1);
}
else if (headByte === 0xda) {
// str 16
const byteLength = this.lookU16();
object = this.decodeString(byteLength, 2);
}
else if (headByte === 0xdb) {
// str 32
const byteLength = this.lookU32();
object = this.decodeString(byteLength, 4);
}
else if (headByte === 0xdc) {
// array 16
const size = this.readU16();
if (size !== 0) {
this.pushArrayState(size);
this.complete();
continue DECODE;
}
else {
object = [];
}
}
else if (headByte === 0xdd) {
// array 32
const size = this.readU32();
if (size !== 0) {
this.pushArrayState(size);
this.complete();
continue DECODE;
}
else {
object = [];
}
}
else if (headByte === 0xde) {
// map 16
const size = this.readU16();
if (size !== 0) {
this.pushMapState(size);
this.complete();
continue DECODE;
}
else {
object = {};
}
}
else if (headByte === 0xdf) {
// map 32
const size = this.readU32();
if (size !== 0) {
this.pushMapState(size);
this.complete();
continue DECODE;
}
else {
object = {};
}
}
else if (headByte === 0xc4) {
// bin 8
const size = this.lookU8();
object = this.decodeBinary(size, 1);
}
else if (headByte === 0xc5) {
// bin 16
const size = this.lookU16();
object = this.decodeBinary(size, 2);
}
else if (headByte === 0xc6) {
// bin 32
const size = this.lookU32();
object = this.decodeBinary(size, 4);
}
else if (headByte === 0xd4) {
// fixext 1
object = this.decodeExtension(1, 0);
}
else if (headByte === 0xd5) {
// fixext 2
object = this.decodeExtension(2, 0);
}
else if (headByte === 0xd6) {
// fixext 4
object = this.decodeExtension(4, 0);
}
else if (headByte === 0xd7) {
// fixext 8
object = this.decodeExtension(8, 0);
}
else if (headByte === 0xd8) {
// fixext 16
object = this.decodeExtension(16, 0);
}
else if (headByte === 0xc7) {
// ext 8
const size = this.lookU8();
object = this.decodeExtension(size, 1);
}
else if (headByte === 0xc8) {
// ext 16
const size = this.lookU16();
object = this.decodeExtension(size, 2);
}
else if (headByte === 0xc9) {
// ext 32
const size = this.lookU32();
object = this.decodeExtension(size, 4);
}
else {
throw new DecodeError(`Unrecognized type byte: ${prettyByte(headByte)}`);
}
this.complete();
const stack = this.stack;
while (stack.length > 0) {
// arrays and maps
const state = stack.top();
if (state.type === STATE_ARRAY) {
state.array[state.position] = object;
state.position++;
if (state.position === state.size) {
object = state.array;
stack.release(state);
}
else {
continue DECODE;
}
}
else if (state.type === STATE_MAP_KEY) {
if (object === "__proto__") {
throw new DecodeError("The key __proto__ is not allowed");
}
state.key = this.mapKeyConverter(object);
state.type = STATE_MAP_VALUE;
continue DECODE;
}
else {
// it must be `state.type === State.MAP_VALUE` here
state.map[state.key] = object;
state.readCount++;
if (state.readCount === state.size) {
object = state.map;
stack.release(state);
}
else {
state.key = null;
state.type = STATE_MAP_KEY;
continue DECODE;
}
}
}
return object;
}
}
readHeadByte() {
if (this.headByte === HEAD_BYTE_REQUIRED) {
this.headByte = this.readU8();
// console.log("headByte", prettyByte(this.headByte));
}
return this.headByte;
}
complete() {
this.headByte = HEAD_BYTE_REQUIRED;
}
readArraySize() {
const headByte = this.readHeadByte();
switch (headByte) {
case 0xdc:
return this.readU16();
case 0xdd:
return this.readU32();
default: {
if (headByte < 0xa0) {
return headByte - 0x90;
}
else {
throw new DecodeError(`Unrecognized array type byte: ${prettyByte(headByte)}`);
}
}
}
}
pushMapState(size) {
if (size > this.maxMapLength) {
throw new DecodeError(`Max length exceeded: map length (${size}) > maxMapLengthLength (${this.maxMapLength})`);
}
this.stack.pushMapState(size);
}
pushArrayState(size) {
if (size > this.maxArrayLength) {
throw new DecodeError(`Max length exceeded: array length (${size}) > maxArrayLength (${this.maxArrayLength})`);
}
this.stack.pushArrayState(size);
}
decodeString(byteLength, headerOffset) {
if (!this.rawStrings || this.stateIsMapKey()) {
return this.decodeUtf8String(byteLength, headerOffset);
}
return this.decodeBinary(byteLength, headerOffset);
}
/**
* @throws {@link RangeError}
*/
decodeUtf8String(byteLength, headerOffset) {
if (byteLength > this.maxStrLength) {
throw new DecodeError(`Max length exceeded: UTF-8 byte length (${byteLength}) > maxStrLength (${this.maxStrLength})`);
}
if (this.bytes.byteLength < this.pos + headerOffset + byteLength) {
throw MORE_DATA;
}
const offset = this.pos + headerOffset;
let object;
if (this.stateIsMapKey() && this.keyDecoder?.canBeCached(byteLength)) {
object = this.keyDecoder.decode(this.bytes, offset, byteLength);
}
else {
object = utf8Decode(this.bytes, offset, byteLength);
}
this.pos += headerOffset + byteLength;
return object;
}
stateIsMapKey() {
if (this.stack.length > 0) {
const state = this.stack.top();
return state.type === STATE_MAP_KEY;
}
return false;
}
/**
* @throws {@link RangeError}
*/
decodeBinary(byteLength, headOffset) {
if (byteLength > this.maxBinLength) {
throw new DecodeError(`Max length exceeded: bin length (${byteLength}) > maxBinLength (${this.maxBinLength})`);
}
if (!this.hasRemaining(byteLength + headOffset)) {
throw MORE_DATA;
}
const offset = this.pos + headOffset;
const object = this.bytes.subarray(offset, offset + byteLength);
this.pos += headOffset + byteLength;
return object;
}
decodeExtension(size, headOffset) {
if (size > this.maxExtLength) {
throw new DecodeError(`Max length exceeded: ext length (${size}) > maxExtLength (${this.maxExtLength})`);
}
const extType = this.view.getInt8(this.pos + headOffset);
const data = this.decodeBinary(size, headOffset + 1 /* extType */);
return this.extensionCodec.decode(data, extType, this.context);
}
lookU8() {
return this.view.getUint8(this.pos);
}
lookU16() {
return this.view.getUint16(this.pos);
}
lookU32() {
return this.view.getUint32(this.pos);
}
readU8() {
const value = this.view.getUint8(this.pos);
this.pos++;
return value;
}
readI8() {
const value = this.view.getInt8(this.pos);
this.pos++;
return value;
}
readU16() {
const value = this.view.getUint16(this.pos);
this.pos += 2;
return value;
}
readI16() {
const value = this.view.getInt16(this.pos);
this.pos += 2;
return value;
}
readU32() {
const value = this.view.getUint32(this.pos);
this.pos += 4;
return value;
}
readI32() {
const value = this.view.getInt32(this.pos);
this.pos += 4;
return value;
}
readU64() {
const value = getUint64(this.view, this.pos);
this.pos += 8;
return value;
}
readI64() {
const value = getInt64(this.view, this.pos);
this.pos += 8;
return value;
}
readU64AsBigInt() {
const value = this.view.getBigUint64(this.pos);
this.pos += 8;
return value;
}
readI64AsBigInt() {
const value = this.view.getBigInt64(this.pos);
this.pos += 8;
return value;
}
readF32() {
const value = this.view.getFloat32(this.pos);
this.pos += 4;
return value;
}
readF64() {
const value = this.view.getFloat64(this.pos);
this.pos += 8;
return value;
}
}
//# sourceMappingURL=Decoder.mjs.map

File diff suppressed because one or more lines are too long

114
node_modules/@msgpack/msgpack/dist.esm/Encoder.d.ts generated vendored Normal file
View File

@@ -0,0 +1,114 @@
import type { ContextOf } from "./context.ts";
import type { ExtensionCodecType } from "./ExtensionCodec.ts";
export declare const DEFAULT_MAX_DEPTH = 100;
export declare const DEFAULT_INITIAL_BUFFER_SIZE = 2048;
export type EncoderOptions<ContextType = undefined> = Partial<Readonly<{
extensionCodec: ExtensionCodecType<ContextType>;
/**
* Encodes bigint as Int64 or Uint64 if it's set to true.
* {@link forceIntegerToFloat} does not affect bigint.
* Depends on ES2020's {@link DataView#setBigInt64} and
* {@link DataView#setBigUint64}.
*
* Defaults to false.
*/
useBigInt64: boolean;
/**
* The maximum depth in nested objects and arrays.
*
* Defaults to 100.
*/
maxDepth: number;
/**
* The initial size of the internal buffer.
*
* Defaults to 2048.
*/
initialBufferSize: number;
/**
* If `true`, the keys of an object is sorted. In other words, the encoded
* binary is canonical and thus comparable to another encoded binary.
*
* Defaults to `false`. If enabled, it spends more time in encoding objects.
*/
sortKeys: boolean;
/**
* If `true`, non-integer numbers are encoded in float32, not in float64 (the default).
*
* Only use it if precisions don't matter.
*
* Defaults to `false`.
*/
forceFloat32: boolean;
/**
* If `true`, an object property with `undefined` value are ignored.
* e.g. `{ foo: undefined }` will be encoded as `{}`, as `JSON.stringify()` does.
*
* Defaults to `false`. If enabled, it spends more time in encoding objects.
*/
ignoreUndefined: boolean;
/**
* If `true`, integer numbers are encoded as floating point numbers,
* with the `forceFloat32` option taken into account.
*
* Defaults to `false`.
*/
forceIntegerToFloat: boolean;
}>> & ContextOf<ContextType>;
export declare class Encoder<ContextType = undefined> {
private readonly extensionCodec;
private readonly context;
private readonly useBigInt64;
private readonly maxDepth;
private readonly initialBufferSize;
private readonly sortKeys;
private readonly forceFloat32;
private readonly ignoreUndefined;
private readonly forceIntegerToFloat;
private pos;
private view;
private bytes;
private entered;
constructor(options?: EncoderOptions<ContextType>);
private clone;
private reinitializeState;
/**
* This is almost equivalent to {@link Encoder#encode}, but it returns an reference of the encoder's internal buffer and thus much faster than {@link Encoder#encode}.
*
* @returns Encodes the object and returns a shared reference the encoder's internal buffer.
*/
encodeSharedRef(object: unknown): Uint8Array<ArrayBuffer>;
/**
* @returns Encodes the object and returns a copy of the encoder's internal buffer.
*/
encode(object: unknown): Uint8Array<ArrayBuffer>;
private doEncode;
private ensureBufferSizeToWrite;
private resizeBuffer;
private encodeNil;
private encodeBoolean;
private encodeNumber;
private encodeNumberAsFloat;
private encodeBigInt64;
private writeStringHeader;
private encodeString;
private encodeObject;
private encodeBinary;
private encodeArray;
private countWithoutUndefined;
private encodeMap;
private encodeExtension;
private writeU8;
private writeU8a;
private writeI8;
private writeU16;
private writeI16;
private writeU32;
private writeI32;
private writeF32;
private writeF64;
private writeU64;
private writeI64;
private writeBigUint64;
private writeBigInt64;
}

494
node_modules/@msgpack/msgpack/dist.esm/Encoder.mjs generated vendored Normal file
View File

@@ -0,0 +1,494 @@
import { utf8Count, utf8Encode } from "./utils/utf8.mjs";
import { ExtensionCodec } from "./ExtensionCodec.mjs";
import { setInt64, setUint64 } from "./utils/int.mjs";
import { ensureUint8Array } from "./utils/typedArrays.mjs";
export const DEFAULT_MAX_DEPTH = 100;
export const DEFAULT_INITIAL_BUFFER_SIZE = 2048;
export class Encoder {
extensionCodec;
context;
useBigInt64;
maxDepth;
initialBufferSize;
sortKeys;
forceFloat32;
ignoreUndefined;
forceIntegerToFloat;
pos;
view;
bytes;
entered = false;
constructor(options) {
this.extensionCodec = options?.extensionCodec ?? ExtensionCodec.defaultCodec;
this.context = options?.context; // needs a type assertion because EncoderOptions has no context property when ContextType is undefined
this.useBigInt64 = options?.useBigInt64 ?? false;
this.maxDepth = options?.maxDepth ?? DEFAULT_MAX_DEPTH;
this.initialBufferSize = options?.initialBufferSize ?? DEFAULT_INITIAL_BUFFER_SIZE;
this.sortKeys = options?.sortKeys ?? false;
this.forceFloat32 = options?.forceFloat32 ?? false;
this.ignoreUndefined = options?.ignoreUndefined ?? false;
this.forceIntegerToFloat = options?.forceIntegerToFloat ?? false;
this.pos = 0;
this.view = new DataView(new ArrayBuffer(this.initialBufferSize));
this.bytes = new Uint8Array(this.view.buffer);
}
clone() {
// Because of slightly special argument `context`,
// type assertion is needed.
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
return new Encoder({
extensionCodec: this.extensionCodec,
context: this.context,
useBigInt64: this.useBigInt64,
maxDepth: this.maxDepth,
initialBufferSize: this.initialBufferSize,
sortKeys: this.sortKeys,
forceFloat32: this.forceFloat32,
ignoreUndefined: this.ignoreUndefined,
forceIntegerToFloat: this.forceIntegerToFloat,
});
}
reinitializeState() {
this.pos = 0;
}
/**
* This is almost equivalent to {@link Encoder#encode}, but it returns an reference of the encoder's internal buffer and thus much faster than {@link Encoder#encode}.
*
* @returns Encodes the object and returns a shared reference the encoder's internal buffer.
*/
encodeSharedRef(object) {
if (this.entered) {
const instance = this.clone();
return instance.encodeSharedRef(object);
}
try {
this.entered = true;
this.reinitializeState();
this.doEncode(object, 1);
return this.bytes.subarray(0, this.pos);
}
finally {
this.entered = false;
}
}
/**
* @returns Encodes the object and returns a copy of the encoder's internal buffer.
*/
encode(object) {
if (this.entered) {
const instance = this.clone();
return instance.encode(object);
}
try {
this.entered = true;
this.reinitializeState();
this.doEncode(object, 1);
return this.bytes.slice(0, this.pos);
}
finally {
this.entered = false;
}
}
doEncode(object, depth) {
if (depth > this.maxDepth) {
throw new Error(`Too deep objects in depth ${depth}`);
}
if (object == null) {
this.encodeNil();
}
else if (typeof object === "boolean") {
this.encodeBoolean(object);
}
else if (typeof object === "number") {
if (!this.forceIntegerToFloat) {
this.encodeNumber(object);
}
else {
this.encodeNumberAsFloat(object);
}
}
else if (typeof object === "string") {
this.encodeString(object);
}
else if (this.useBigInt64 && typeof object === "bigint") {
this.encodeBigInt64(object);
}
else {
this.encodeObject(object, depth);
}
}
ensureBufferSizeToWrite(sizeToWrite) {
const requiredSize = this.pos + sizeToWrite;
if (this.view.byteLength < requiredSize) {
this.resizeBuffer(requiredSize * 2);
}
}
resizeBuffer(newSize) {
const newBuffer = new ArrayBuffer(newSize);
const newBytes = new Uint8Array(newBuffer);
const newView = new DataView(newBuffer);
newBytes.set(this.bytes);
this.view = newView;
this.bytes = newBytes;
}
encodeNil() {
this.writeU8(0xc0);
}
encodeBoolean(object) {
if (object === false) {
this.writeU8(0xc2);
}
else {
this.writeU8(0xc3);
}
}
encodeNumber(object) {
if (!this.forceIntegerToFloat && Number.isSafeInteger(object)) {
if (object >= 0) {
if (object < 0x80) {
// positive fixint
this.writeU8(object);
}
else if (object < 0x100) {
// uint 8
this.writeU8(0xcc);
this.writeU8(object);
}
else if (object < 0x10000) {
// uint 16
this.writeU8(0xcd);
this.writeU16(object);
}
else if (object < 0x100000000) {
// uint 32
this.writeU8(0xce);
this.writeU32(object);
}
else if (!this.useBigInt64) {
// uint 64
this.writeU8(0xcf);
this.writeU64(object);
}
else {
this.encodeNumberAsFloat(object);
}
}
else {
if (object >= -0x20) {
// negative fixint
this.writeU8(0xe0 | (object + 0x20));
}
else if (object >= -0x80) {
// int 8
this.writeU8(0xd0);
this.writeI8(object);
}
else if (object >= -0x8000) {
// int 16
this.writeU8(0xd1);
this.writeI16(object);
}
else if (object >= -0x80000000) {
// int 32
this.writeU8(0xd2);
this.writeI32(object);
}
else if (!this.useBigInt64) {
// int 64
this.writeU8(0xd3);
this.writeI64(object);
}
else {
this.encodeNumberAsFloat(object);
}
}
}
else {
this.encodeNumberAsFloat(object);
}
}
encodeNumberAsFloat(object) {
if (this.forceFloat32) {
// float 32
this.writeU8(0xca);
this.writeF32(object);
}
else {
// float 64
this.writeU8(0xcb);
this.writeF64(object);
}
}
encodeBigInt64(object) {
if (object >= BigInt(0)) {
// uint 64
this.writeU8(0xcf);
this.writeBigUint64(object);
}
else {
// int 64
this.writeU8(0xd3);
this.writeBigInt64(object);
}
}
writeStringHeader(byteLength) {
if (byteLength < 32) {
// fixstr
this.writeU8(0xa0 + byteLength);
}
else if (byteLength < 0x100) {
// str 8
this.writeU8(0xd9);
this.writeU8(byteLength);
}
else if (byteLength < 0x10000) {
// str 16
this.writeU8(0xda);
this.writeU16(byteLength);
}
else if (byteLength < 0x100000000) {
// str 32
this.writeU8(0xdb);
this.writeU32(byteLength);
}
else {
throw new Error(`Too long string: ${byteLength} bytes in UTF-8`);
}
}
encodeString(object) {
const maxHeaderSize = 1 + 4;
const byteLength = utf8Count(object);
this.ensureBufferSizeToWrite(maxHeaderSize + byteLength);
this.writeStringHeader(byteLength);
utf8Encode(object, this.bytes, this.pos);
this.pos += byteLength;
}
encodeObject(object, depth) {
// try to encode objects with custom codec first of non-primitives
const ext = this.extensionCodec.tryToEncode(object, this.context);
if (ext != null) {
this.encodeExtension(ext);
}
else if (Array.isArray(object)) {
this.encodeArray(object, depth);
}
else if (ArrayBuffer.isView(object)) {
this.encodeBinary(object);
}
else if (typeof object === "object") {
this.encodeMap(object, depth);
}
else {
// symbol, function and other special object come here unless extensionCodec handles them.
throw new Error(`Unrecognized object: ${Object.prototype.toString.apply(object)}`);
}
}
encodeBinary(object) {
const size = object.byteLength;
if (size < 0x100) {
// bin 8
this.writeU8(0xc4);
this.writeU8(size);
}
else if (size < 0x10000) {
// bin 16
this.writeU8(0xc5);
this.writeU16(size);
}
else if (size < 0x100000000) {
// bin 32
this.writeU8(0xc6);
this.writeU32(size);
}
else {
throw new Error(`Too large binary: ${size}`);
}
const bytes = ensureUint8Array(object);
this.writeU8a(bytes);
}
encodeArray(object, depth) {
const size = object.length;
if (size < 16) {
// fixarray
this.writeU8(0x90 + size);
}
else if (size < 0x10000) {
// array 16
this.writeU8(0xdc);
this.writeU16(size);
}
else if (size < 0x100000000) {
// array 32
this.writeU8(0xdd);
this.writeU32(size);
}
else {
throw new Error(`Too large array: ${size}`);
}
for (const item of object) {
this.doEncode(item, depth + 1);
}
}
countWithoutUndefined(object, keys) {
let count = 0;
for (const key of keys) {
if (object[key] !== undefined) {
count++;
}
}
return count;
}
encodeMap(object, depth) {
const keys = Object.keys(object);
if (this.sortKeys) {
keys.sort();
}
const size = this.ignoreUndefined ? this.countWithoutUndefined(object, keys) : keys.length;
if (size < 16) {
// fixmap
this.writeU8(0x80 + size);
}
else if (size < 0x10000) {
// map 16
this.writeU8(0xde);
this.writeU16(size);
}
else if (size < 0x100000000) {
// map 32
this.writeU8(0xdf);
this.writeU32(size);
}
else {
throw new Error(`Too large map object: ${size}`);
}
for (const key of keys) {
const value = object[key];
if (!(this.ignoreUndefined && value === undefined)) {
this.encodeString(key);
this.doEncode(value, depth + 1);
}
}
}
encodeExtension(ext) {
if (typeof ext.data === "function") {
const data = ext.data(this.pos + 6);
const size = data.length;
if (size >= 0x100000000) {
throw new Error(`Too large extension object: ${size}`);
}
this.writeU8(0xc9);
this.writeU32(size);
this.writeI8(ext.type);
this.writeU8a(data);
return;
}
const size = ext.data.length;
if (size === 1) {
// fixext 1
this.writeU8(0xd4);
}
else if (size === 2) {
// fixext 2
this.writeU8(0xd5);
}
else if (size === 4) {
// fixext 4
this.writeU8(0xd6);
}
else if (size === 8) {
// fixext 8
this.writeU8(0xd7);
}
else if (size === 16) {
// fixext 16
this.writeU8(0xd8);
}
else if (size < 0x100) {
// ext 8
this.writeU8(0xc7);
this.writeU8(size);
}
else if (size < 0x10000) {
// ext 16
this.writeU8(0xc8);
this.writeU16(size);
}
else if (size < 0x100000000) {
// ext 32
this.writeU8(0xc9);
this.writeU32(size);
}
else {
throw new Error(`Too large extension object: ${size}`);
}
this.writeI8(ext.type);
this.writeU8a(ext.data);
}
writeU8(value) {
this.ensureBufferSizeToWrite(1);
this.view.setUint8(this.pos, value);
this.pos++;
}
writeU8a(values) {
const size = values.length;
this.ensureBufferSizeToWrite(size);
this.bytes.set(values, this.pos);
this.pos += size;
}
writeI8(value) {
this.ensureBufferSizeToWrite(1);
this.view.setInt8(this.pos, value);
this.pos++;
}
writeU16(value) {
this.ensureBufferSizeToWrite(2);
this.view.setUint16(this.pos, value);
this.pos += 2;
}
writeI16(value) {
this.ensureBufferSizeToWrite(2);
this.view.setInt16(this.pos, value);
this.pos += 2;
}
writeU32(value) {
this.ensureBufferSizeToWrite(4);
this.view.setUint32(this.pos, value);
this.pos += 4;
}
writeI32(value) {
this.ensureBufferSizeToWrite(4);
this.view.setInt32(this.pos, value);
this.pos += 4;
}
writeF32(value) {
this.ensureBufferSizeToWrite(4);
this.view.setFloat32(this.pos, value);
this.pos += 4;
}
writeF64(value) {
this.ensureBufferSizeToWrite(8);
this.view.setFloat64(this.pos, value);
this.pos += 8;
}
writeU64(value) {
this.ensureBufferSizeToWrite(8);
setUint64(this.view, this.pos, value);
this.pos += 8;
}
writeI64(value) {
this.ensureBufferSizeToWrite(8);
setInt64(this.view, this.pos, value);
this.pos += 8;
}
writeBigUint64(value) {
this.ensureBufferSizeToWrite(8);
this.view.setBigUint64(this.pos, value);
this.pos += 8;
}
writeBigInt64(value) {
this.ensureBufferSizeToWrite(8);
this.view.setBigInt64(this.pos, value);
this.pos += 8;
}
}
//# sourceMappingURL=Encoder.mjs.map

File diff suppressed because one or more lines are too long

8
node_modules/@msgpack/msgpack/dist.esm/ExtData.d.ts generated vendored Normal file
View File

@@ -0,0 +1,8 @@
/**
* ExtData is used to handle Extension Types that are not registered to ExtensionCodec.
*/
export declare class ExtData {
readonly type: number;
readonly data: Uint8Array | ((pos: number) => Uint8Array);
constructor(type: number, data: Uint8Array | ((pos: number) => Uint8Array));
}

12
node_modules/@msgpack/msgpack/dist.esm/ExtData.mjs generated vendored Normal file
View File

@@ -0,0 +1,12 @@
/**
* ExtData is used to handle Extension Types that are not registered to ExtensionCodec.
*/
export class ExtData {
type;
data;
constructor(type, data) {
this.type = type;
this.data = data;
}
}
//# sourceMappingURL=ExtData.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"ExtDatamjs","sourceRoot":"","sources":["../src/ExtData.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,OAAO;IACT,IAAI,CAAS;IACb,IAAI,CAA6C;IAE1D,YAAY,IAAY,EAAE,IAAgD,EAAE;QAC1E,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAAA,CAClB;CACF"}

View File

@@ -0,0 +1,24 @@
import { ExtData } from "./ExtData.ts";
export type ExtensionDecoderType<ContextType> = (data: Uint8Array, extensionType: number, context: ContextType) => unknown;
export type ExtensionEncoderType<ContextType> = (input: unknown, context: ContextType) => Uint8Array | ((dataPos: number) => Uint8Array) | null;
export type ExtensionCodecType<ContextType> = {
__brand?: ContextType;
tryToEncode(object: unknown, context: ContextType): ExtData | null;
decode(data: Uint8Array, extType: number, context: ContextType): unknown;
};
export declare class ExtensionCodec<ContextType = undefined> implements ExtensionCodecType<ContextType> {
static readonly defaultCodec: ExtensionCodecType<undefined>;
__brand?: ContextType;
private readonly builtInEncoders;
private readonly builtInDecoders;
private readonly encoders;
private readonly decoders;
constructor();
register({ type, encode, decode }: {
type: number;
encode: ExtensionEncoderType<ContextType>;
decode: ExtensionDecoderType<ContextType>;
}): void;
tryToEncode(object: unknown, context: ContextType): ExtData | null;
decode(data: Uint8Array, type: number, context: ContextType): unknown;
}

View File

@@ -0,0 +1,72 @@
// ExtensionCodec to handle MessagePack extensions
import { ExtData } from "./ExtData.mjs";
import { timestampExtension } from "./timestamp.mjs";
export class ExtensionCodec {
static defaultCodec = new ExtensionCodec();
// ensures ExtensionCodecType<X> matches ExtensionCodec<X>
// this will make type errors a lot more clear
// eslint-disable-next-line @typescript-eslint/naming-convention
__brand;
// built-in extensions
builtInEncoders = [];
builtInDecoders = [];
// custom extensions
encoders = [];
decoders = [];
constructor() {
this.register(timestampExtension);
}
register({ type, encode, decode, }) {
if (type >= 0) {
// custom extensions
this.encoders[type] = encode;
this.decoders[type] = decode;
}
else {
// built-in extensions
const index = -1 - type;
this.builtInEncoders[index] = encode;
this.builtInDecoders[index] = decode;
}
}
tryToEncode(object, context) {
// built-in extensions
for (let i = 0; i < this.builtInEncoders.length; i++) {
const encodeExt = this.builtInEncoders[i];
if (encodeExt != null) {
const data = encodeExt(object, context);
if (data != null) {
const type = -1 - i;
return new ExtData(type, data);
}
}
}
// custom extensions
for (let i = 0; i < this.encoders.length; i++) {
const encodeExt = this.encoders[i];
if (encodeExt != null) {
const data = encodeExt(object, context);
if (data != null) {
const type = i;
return new ExtData(type, data);
}
}
}
if (object instanceof ExtData) {
// to keep ExtData as is
return object;
}
return null;
}
decode(data, type, context) {
const decodeExt = type < 0 ? this.builtInDecoders[-1 - type] : this.decoders[type];
if (decodeExt) {
return decodeExt(data, type, context);
}
else {
// decode() does not fail, returns ExtData instead.
return new ExtData(type, data);
}
}
}
//# sourceMappingURL=ExtensionCodec.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"ExtensionCodecmjs","sourceRoot":"","sources":["../src/ExtensionCodec.ts"],"names":[],"mappings":"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"}

9
node_modules/@msgpack/msgpack/dist.esm/context.d.ts generated vendored Normal file
View File

@@ -0,0 +1,9 @@
type SplitTypes<T, U> = U extends T ? (Exclude<T, U> extends never ? T : Exclude<T, U>) : T;
export type SplitUndefined<T> = SplitTypes<T, undefined>;
export type ContextOf<ContextType> = ContextType extends undefined ? object : {
/**
* Custom user-defined data, read/writable
*/
context: ContextType;
};
export {};

2
node_modules/@msgpack/msgpack/dist.esm/context.mjs generated vendored Normal file
View File

@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=context.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"contextmjs","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":""}

20
node_modules/@msgpack/msgpack/dist.esm/decode.d.ts generated vendored Normal file
View File

@@ -0,0 +1,20 @@
import type { DecoderOptions } from "./Decoder.ts";
import type { SplitUndefined } from "./context.ts";
/**
* It decodes a single MessagePack object in a buffer.
*
* This is a synchronous decoding function.
* See other variants for asynchronous decoding: {@link decodeAsync}, {@link decodeMultiStream}, or {@link decodeArrayStream}.
*
* @throws {@link RangeError} if the buffer is incomplete, including the case where the buffer is empty.
* @throws {@link DecodeError} if the buffer contains invalid data.
*/
export declare function decode<ContextType = undefined>(buffer: ArrayLike<number> | ArrayBufferView | ArrayBufferLike, options?: DecoderOptions<SplitUndefined<ContextType>>): unknown;
/**
* It decodes multiple MessagePack objects in a buffer.
* This is corresponding to {@link decodeMultiStream}.
*
* @throws {@link RangeError} if the buffer is incomplete, including the case where the buffer is empty.
* @throws {@link DecodeError} if the buffer contains invalid data.
*/
export declare function decodeMulti<ContextType = undefined>(buffer: ArrayLike<number> | BufferSource, options?: DecoderOptions<SplitUndefined<ContextType>>): Generator<unknown, void, unknown>;

26
node_modules/@msgpack/msgpack/dist.esm/decode.mjs generated vendored Normal file
View File

@@ -0,0 +1,26 @@
import { Decoder } from "./Decoder.mjs";
/**
* It decodes a single MessagePack object in a buffer.
*
* This is a synchronous decoding function.
* See other variants for asynchronous decoding: {@link decodeAsync}, {@link decodeMultiStream}, or {@link decodeArrayStream}.
*
* @throws {@link RangeError} if the buffer is incomplete, including the case where the buffer is empty.
* @throws {@link DecodeError} if the buffer contains invalid data.
*/
export function decode(buffer, options) {
const decoder = new Decoder(options);
return decoder.decode(buffer);
}
/**
* It decodes multiple MessagePack objects in a buffer.
* This is corresponding to {@link decodeMultiStream}.
*
* @throws {@link RangeError} if the buffer is incomplete, including the case where the buffer is empty.
* @throws {@link DecodeError} if the buffer contains invalid data.
*/
export function decodeMulti(buffer, options) {
const decoder = new Decoder(options);
return decoder.decodeMulti(buffer);
}
//# sourceMappingURL=decode.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"decodemjs","sourceRoot":"","sources":["../src/decode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAIvC;;;;;;;;GAQG;AACH,MAAM,UAAU,MAAM,CACpB,MAA6D,EAC7D,OAAqD,EAC5C;IACT,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IACrC,OAAO,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAAA,CAC/B;AAED;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CACzB,MAAwC,EACxC,OAAqD,EAClB;IACnC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IACrC,OAAO,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;AAAA,CACpC"}

View File

@@ -0,0 +1,18 @@
import type { DecoderOptions } from "./Decoder.ts";
import type { ReadableStreamLike } from "./utils/stream.ts";
import type { SplitUndefined } from "./context.ts";
/**
* @throws {@link RangeError} if the buffer is incomplete, including the case where the buffer is empty.
* @throws {@link DecodeError} if the buffer contains invalid data.
*/
export declare function decodeAsync<ContextType = undefined>(streamLike: ReadableStreamLike<ArrayLike<number> | BufferSource>, options?: DecoderOptions<SplitUndefined<ContextType>>): Promise<unknown>;
/**
* @throws {@link RangeError} if the buffer is incomplete, including the case where the buffer is empty.
* @throws {@link DecodeError} if the buffer contains invalid data.
*/
export declare function decodeArrayStream<ContextType>(streamLike: ReadableStreamLike<ArrayLike<number> | BufferSource>, options?: DecoderOptions<SplitUndefined<ContextType>>): AsyncGenerator<unknown, void, unknown>;
/**
* @throws {@link RangeError} if the buffer is incomplete, including the case where the buffer is empty.
* @throws {@link DecodeError} if the buffer contains invalid data.
*/
export declare function decodeMultiStream<ContextType>(streamLike: ReadableStreamLike<ArrayLike<number> | BufferSource>, options?: DecoderOptions<SplitUndefined<ContextType>>): AsyncGenerator<unknown, void, unknown>;

30
node_modules/@msgpack/msgpack/dist.esm/decodeAsync.mjs generated vendored Normal file
View File

@@ -0,0 +1,30 @@
import { Decoder } from "./Decoder.mjs";
import { ensureAsyncIterable } from "./utils/stream.mjs";
/**
* @throws {@link RangeError} if the buffer is incomplete, including the case where the buffer is empty.
* @throws {@link DecodeError} if the buffer contains invalid data.
*/
export async function decodeAsync(streamLike, options) {
const stream = ensureAsyncIterable(streamLike);
const decoder = new Decoder(options);
return decoder.decodeAsync(stream);
}
/**
* @throws {@link RangeError} if the buffer is incomplete, including the case where the buffer is empty.
* @throws {@link DecodeError} if the buffer contains invalid data.
*/
export function decodeArrayStream(streamLike, options) {
const stream = ensureAsyncIterable(streamLike);
const decoder = new Decoder(options);
return decoder.decodeArrayStream(stream);
}
/**
* @throws {@link RangeError} if the buffer is incomplete, including the case where the buffer is empty.
* @throws {@link DecodeError} if the buffer contains invalid data.
*/
export function decodeMultiStream(streamLike, options) {
const stream = ensureAsyncIterable(streamLike);
const decoder = new Decoder(options);
return decoder.decodeStream(stream);
}
//# sourceMappingURL=decodeAsync.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"decodeAsyncmjs","sourceRoot":"","sources":["../src/decodeAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAKxD;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,UAAgE,EAChE,OAAqD,EACnC;IAClB,MAAM,MAAM,GAAG,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAC/C,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IACrC,OAAO,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;AAAA,CACpC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAC/B,UAAgE,EAChE,OAAqD,EACb;IACxC,MAAM,MAAM,GAAG,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAC/C,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IACrC,OAAO,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;AAAA,CAC1C;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAC/B,UAAgE,EAChE,OAAqD,EACb;IACxC,MAAM,MAAM,GAAG,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAC/C,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IACrC,OAAO,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;AAAA,CACrC"}

9
node_modules/@msgpack/msgpack/dist.esm/encode.d.ts generated vendored Normal file
View File

@@ -0,0 +1,9 @@
import type { EncoderOptions } from "./Encoder.ts";
import type { SplitUndefined } from "./context.ts";
/**
* It encodes `value` in the MessagePack format and
* returns a byte buffer.
*
* The returned buffer is a slice of a larger `ArrayBuffer`, so you have to use its `#byteOffset` and `#byteLength` in order to convert it to another typed arrays including NodeJS `Buffer`.
*/
export declare function encode<ContextType = undefined>(value: unknown, options?: EncoderOptions<SplitUndefined<ContextType>>): Uint8Array<ArrayBuffer>;

12
node_modules/@msgpack/msgpack/dist.esm/encode.mjs generated vendored Normal file
View File

@@ -0,0 +1,12 @@
import { Encoder } from "./Encoder.mjs";
/**
* It encodes `value` in the MessagePack format and
* returns a byte buffer.
*
* The returned buffer is a slice of a larger `ArrayBuffer`, so you have to use its `#byteOffset` and `#byteLength` in order to convert it to another typed arrays including NodeJS `Buffer`.
*/
export function encode(value, options) {
const encoder = new Encoder(options);
return encoder.encodeSharedRef(value);
}
//# sourceMappingURL=encode.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"encodemjs","sourceRoot":"","sources":["../src/encode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAIvC;;;;;GAKG;AACH,MAAM,UAAU,MAAM,CACpB,KAAc,EACd,OAAqD,EAC5B;IACzB,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IACrC,OAAO,OAAO,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;AAAA,CACvC"}

24
node_modules/@msgpack/msgpack/dist.esm/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,24 @@
import { encode } from "./encode.ts";
export { encode };
import { decode, decodeMulti } from "./decode.ts";
export { decode, decodeMulti };
import { decodeAsync, decodeArrayStream, decodeMultiStream } from "./decodeAsync.ts";
export { decodeAsync, decodeArrayStream, decodeMultiStream };
import { Decoder } from "./Decoder.ts";
export { Decoder };
import type { DecoderOptions } from "./Decoder.ts";
export type { DecoderOptions };
import { DecodeError } from "./DecodeError.ts";
export { DecodeError };
import { Encoder } from "./Encoder.ts";
export { Encoder };
import type { EncoderOptions } from "./Encoder.ts";
export type { EncoderOptions };
import { ExtensionCodec } from "./ExtensionCodec.ts";
export { ExtensionCodec };
import type { ExtensionCodecType, ExtensionDecoderType, ExtensionEncoderType } from "./ExtensionCodec.ts";
export type { ExtensionCodecType, ExtensionDecoderType, ExtensionEncoderType };
import { ExtData } from "./ExtData.ts";
export { ExtData };
import { EXT_TIMESTAMP, encodeDateToTimeSpec, encodeTimeSpecToTimestamp, decodeTimestampToTimeSpec, encodeTimestampExtension, decodeTimestampExtension } from "./timestamp.ts";
export { EXT_TIMESTAMP, encodeDateToTimeSpec, encodeTimeSpecToTimestamp, decodeTimestampToTimeSpec, encodeTimestampExtension, decodeTimestampExtension, };

21
node_modules/@msgpack/msgpack/dist.esm/index.mjs generated vendored Normal file
View File

@@ -0,0 +1,21 @@
// Main Functions:
import { encode } from "./encode.mjs";
export { encode };
import { decode, decodeMulti } from "./decode.mjs";
export { decode, decodeMulti };
import { decodeAsync, decodeArrayStream, decodeMultiStream } from "./decodeAsync.mjs";
export { decodeAsync, decodeArrayStream, decodeMultiStream };
import { Decoder } from "./Decoder.mjs";
export { Decoder };
import { DecodeError } from "./DecodeError.mjs";
export { DecodeError };
import { Encoder } from "./Encoder.mjs";
export { Encoder };
// Utilities for Extension Types:
import { ExtensionCodec } from "./ExtensionCodec.mjs";
export { ExtensionCodec };
import { ExtData } from "./ExtData.mjs";
export { ExtData };
import { EXT_TIMESTAMP, encodeDateToTimeSpec, encodeTimeSpecToTimestamp, decodeTimestampToTimeSpec, encodeTimestampExtension, decodeTimestampExtension, } from "./timestamp.mjs";
export { EXT_TIMESTAMP, encodeDateToTimeSpec, encodeTimeSpecToTimestamp, decodeTimestampToTimeSpec, encodeTimestampExtension, decodeTimestampExtension, };
//# sourceMappingURL=index.mjs.map

1
node_modules/@msgpack/msgpack/dist.esm/index.mjs.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"indexmjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kBAAkB;AAElB,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,CAAC;AAElB,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;AAE/B,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrF,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,CAAC;AAE7D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,CAAC;AAGnB,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,CAAC;AAEvB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,CAAC;AAInB,iCAAiC;AAEjC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,CAAC;AAG1B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,CAAC;AAEnB,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,yBAAyB,EACzB,yBAAyB,EACzB,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,yBAAyB,EACzB,yBAAyB,EACzB,wBAAwB,EACxB,wBAAwB,GACzB,CAAC"}

15
node_modules/@msgpack/msgpack/dist.esm/timestamp.d.ts generated vendored Normal file
View File

@@ -0,0 +1,15 @@
export declare const EXT_TIMESTAMP = -1;
export type TimeSpec = {
sec: number;
nsec: number;
};
export declare function encodeTimeSpecToTimestamp({ sec, nsec }: TimeSpec): Uint8Array;
export declare function encodeDateToTimeSpec(date: Date): TimeSpec;
export declare function encodeTimestampExtension(object: unknown): Uint8Array | null;
export declare function decodeTimestampToTimeSpec(data: Uint8Array): TimeSpec;
export declare function decodeTimestampExtension(data: Uint8Array): Date;
export declare const timestampExtension: {
type: number;
encode: typeof encodeTimestampExtension;
decode: typeof decodeTimestampExtension;
};

96
node_modules/@msgpack/msgpack/dist.esm/timestamp.mjs generated vendored Normal file
View File

@@ -0,0 +1,96 @@
// https://github.com/msgpack/msgpack/blob/master/spec.md#timestamp-extension-type
import { DecodeError } from "./DecodeError.mjs";
import { getInt64, setInt64 } from "./utils/int.mjs";
export const EXT_TIMESTAMP = -1;
const TIMESTAMP32_MAX_SEC = 0x100000000 - 1; // 32-bit unsigned int
const TIMESTAMP64_MAX_SEC = 0x400000000 - 1; // 34-bit unsigned int
export function encodeTimeSpecToTimestamp({ sec, nsec }) {
if (sec >= 0 && nsec >= 0 && sec <= TIMESTAMP64_MAX_SEC) {
// Here sec >= 0 && nsec >= 0
if (nsec === 0 && sec <= TIMESTAMP32_MAX_SEC) {
// timestamp 32 = { sec32 (unsigned) }
const rv = new Uint8Array(4);
const view = new DataView(rv.buffer);
view.setUint32(0, sec);
return rv;
}
else {
// timestamp 64 = { nsec30 (unsigned), sec34 (unsigned) }
const secHigh = sec / 0x100000000;
const secLow = sec & 0xffffffff;
const rv = new Uint8Array(8);
const view = new DataView(rv.buffer);
// nsec30 | secHigh2
view.setUint32(0, (nsec << 2) | (secHigh & 0x3));
// secLow32
view.setUint32(4, secLow);
return rv;
}
}
else {
// timestamp 96 = { nsec32 (unsigned), sec64 (signed) }
const rv = new Uint8Array(12);
const view = new DataView(rv.buffer);
view.setUint32(0, nsec);
setInt64(view, 4, sec);
return rv;
}
}
export function encodeDateToTimeSpec(date) {
const msec = date.getTime();
const sec = Math.floor(msec / 1e3);
const nsec = (msec - sec * 1e3) * 1e6;
// Normalizes { sec, nsec } to ensure nsec is unsigned.
const nsecInSec = Math.floor(nsec / 1e9);
return {
sec: sec + nsecInSec,
nsec: nsec - nsecInSec * 1e9,
};
}
export function encodeTimestampExtension(object) {
if (object instanceof Date) {
const timeSpec = encodeDateToTimeSpec(object);
return encodeTimeSpecToTimestamp(timeSpec);
}
else {
return null;
}
}
export function decodeTimestampToTimeSpec(data) {
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
// data may be 32, 64, or 96 bits
switch (data.byteLength) {
case 4: {
// timestamp 32 = { sec32 }
const sec = view.getUint32(0);
const nsec = 0;
return { sec, nsec };
}
case 8: {
// timestamp 64 = { nsec30, sec34 }
const nsec30AndSecHigh2 = view.getUint32(0);
const secLow32 = view.getUint32(4);
const sec = (nsec30AndSecHigh2 & 0x3) * 0x100000000 + secLow32;
const nsec = nsec30AndSecHigh2 >>> 2;
return { sec, nsec };
}
case 12: {
// timestamp 96 = { nsec32 (unsigned), sec64 (signed) }
const sec = getInt64(view, 4);
const nsec = view.getUint32(0);
return { sec, nsec };
}
default:
throw new DecodeError(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${data.length}`);
}
}
export function decodeTimestampExtension(data) {
const timeSpec = decodeTimestampToTimeSpec(data);
return new Date(timeSpec.sec * 1e3 + timeSpec.nsec / 1e6);
}
export const timestampExtension = {
type: EXT_TIMESTAMP,
encode: encodeTimestampExtension,
decode: decodeTimestampExtension,
};
//# sourceMappingURL=timestamp.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"timestampmjs","sourceRoot":"","sources":["../src/timestamp.ts"],"names":[],"mappings":"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"}

View File

@@ -0,0 +1 @@
{"version":"7.0.0-dev.20251225.1","root":["../src/cachedkeydecoder.ts","../src/decodeerror.ts","../src/decoder.ts","../src/encoder.ts","../src/extdata.ts","../src/extensioncodec.ts","../src/context.ts","../src/decode.ts","../src/decodeasync.ts","../src/encode.ts","../src/index.ts","../src/timestamp.ts","../src/utils/int.ts","../src/utils/prettybyte.ts","../src/utils/stream.ts","../src/utils/typedarrays.ts","../src/utils/utf8.ts"]}

View File

@@ -0,0 +1,5 @@
export declare const UINT32_MAX = 4294967295;
export declare function setUint64(view: DataView, offset: number, value: number): void;
export declare function setInt64(view: DataView, offset: number, value: number): void;
export declare function getInt64(view: DataView, offset: number): number;
export declare function getUint64(view: DataView, offset: number): number;

27
node_modules/@msgpack/msgpack/dist.esm/utils/int.mjs generated vendored Normal file
View File

@@ -0,0 +1,27 @@
// Integer Utility
export const UINT32_MAX = 4294967295;
// DataView extension to handle int64 / uint64,
// where the actual range is 53-bits integer (a.k.a. safe integer)
export function setUint64(view, offset, value) {
const high = value / 4294967296;
const low = value; // high bits are truncated by DataView
view.setUint32(offset, high);
view.setUint32(offset + 4, low);
}
export function setInt64(view, offset, value) {
const high = Math.floor(value / 4294967296);
const low = value; // high bits are truncated by DataView
view.setUint32(offset, high);
view.setUint32(offset + 4, low);
}
export function getInt64(view, offset) {
const high = view.getInt32(offset);
const low = view.getUint32(offset + 4);
return high * 4294967296 + low;
}
export function getUint64(view, offset) {
const high = view.getUint32(offset);
const low = view.getUint32(offset + 4);
return high * 4294967296 + low;
}
//# sourceMappingURL=int.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"intmjs","sourceRoot":"","sources":["../../src/utils/int.ts"],"names":[],"mappings":"AAAA,kBAAkB;AAElB,MAAM,CAAC,MAAM,UAAU,GAAG,UAAW,CAAC;AAEtC,+CAA+C;AAC/C,kEAAkE;AAElE,MAAM,UAAU,SAAS,CAAC,IAAc,EAAE,MAAc,EAAE,KAAa,EAAQ;IAC7E,MAAM,IAAI,GAAG,KAAK,GAAG,UAAa,CAAC;IACnC,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,sCAAsC;IACzD,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC7B,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;AAAA,CACjC;AAED,MAAM,UAAU,QAAQ,CAAC,IAAc,EAAE,MAAc,EAAE,KAAa,EAAQ;IAC5E,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,UAAa,CAAC,CAAC;IAC/C,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,sCAAsC;IACzD,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC7B,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;AAAA,CACjC;AAED,MAAM,UAAU,QAAQ,CAAC,IAAc,EAAE,MAAc,EAAU;IAC/D,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACnC,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACvC,OAAO,IAAI,GAAG,UAAa,GAAG,GAAG,CAAC;AAAA,CACnC;AAED,MAAM,UAAU,SAAS,CAAC,IAAc,EAAE,MAAc,EAAU;IAChE,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACpC,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACvC,OAAO,IAAI,GAAG,UAAa,GAAG,GAAG,CAAC;AAAA,CACnC"}

View File

@@ -0,0 +1 @@
export declare function prettyByte(byte: number): string;

View File

@@ -0,0 +1,4 @@
export function prettyByte(byte) {
return `${byte < 0 ? "-" : ""}0x${Math.abs(byte).toString(16).padStart(2, "0")}`;
}
//# sourceMappingURL=prettyByte.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"prettyBytemjs","sourceRoot":"","sources":["../../src/utils/prettyByte.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,UAAU,CAAC,IAAY,EAAU;IAC/C,OAAO,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;AAAA,CAClF"}

View File

@@ -0,0 +1,4 @@
export type ReadableStreamLike<T> = AsyncIterable<T> | ReadableStream<T>;
export declare function isAsyncIterable<T>(object: ReadableStreamLike<T>): object is AsyncIterable<T>;
export declare function asyncIterableFromStream<T>(stream: ReadableStream<T>): AsyncIterable<T>;
export declare function ensureAsyncIterable<T>(streamLike: ReadableStreamLike<T>): AsyncIterable<T>;

View File

@@ -0,0 +1,28 @@
// utility for whatwg streams
export function isAsyncIterable(object) {
return object[Symbol.asyncIterator] != null;
}
export async function* asyncIterableFromStream(stream) {
const reader = stream.getReader();
try {
while (true) {
const { done, value } = await reader.read();
if (done) {
return;
}
yield value;
}
}
finally {
reader.releaseLock();
}
}
export function ensureAsyncIterable(streamLike) {
if (isAsyncIterable(streamLike)) {
return streamLike;
}
else {
return asyncIterableFromStream(streamLike);
}
}
//# sourceMappingURL=stream.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"streammjs","sourceRoot":"","sources":["../../src/utils/stream.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAQ7B,MAAM,UAAU,eAAe,CAAI,MAA6B,EAA8B;IAC5F,OAAQ,MAAc,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,IAAI,CAAC;AAAA,CACtD;AAED,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,uBAAuB,CAAI,MAAyB,EAAoB;IAC7F,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;IAElC,IAAI,CAAC;QACH,OAAO,IAAI,EAAE,CAAC;YACZ,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;YAC5C,IAAI,IAAI,EAAE,CAAC;gBACT,OAAO;YACT,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,WAAW,EAAE,CAAC;IACvB,CAAC;AAAA,CACF;AAED,MAAM,UAAU,mBAAmB,CAAI,UAAiC,EAAoB;IAC1F,IAAI,eAAe,CAAC,UAAU,CAAC,EAAE,CAAC;QAChC,OAAO,UAAU,CAAC;IACpB,CAAC;SAAM,CAAC;QACN,OAAO,uBAAuB,CAAC,UAAU,CAAC,CAAC;IAC7C,CAAC;AAAA,CACF"}

View File

@@ -0,0 +1 @@
export declare function ensureUint8Array(buffer: ArrayLike<number> | Uint8Array<ArrayBufferLike> | ArrayBufferView | ArrayBufferLike): Uint8Array<ArrayBufferLike>;

View File

@@ -0,0 +1,19 @@
function isArrayBufferLike(buffer) {
return (buffer instanceof ArrayBuffer || (typeof SharedArrayBuffer !== "undefined" && buffer instanceof SharedArrayBuffer));
}
export function ensureUint8Array(buffer) {
if (buffer instanceof Uint8Array) {
return buffer;
}
else if (ArrayBuffer.isView(buffer)) {
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
}
else if (isArrayBufferLike(buffer)) {
return new Uint8Array(buffer);
}
else {
// ArrayLike<number>
return Uint8Array.from(buffer);
}
}
//# sourceMappingURL=typedArrays.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"typedArraysmjs","sourceRoot":"","sources":["../../src/utils/typedArrays.ts"],"names":[],"mappings":"AAAA,SAAS,iBAAiB,CAAC,MAAe,EAA6B;IACrE,OAAO,CACL,MAAM,YAAY,WAAW,IAAI,CAAC,OAAO,iBAAiB,KAAK,WAAW,IAAI,MAAM,YAAY,iBAAiB,CAAC,CACnH,CAAC;AAAA,CACH;AAED,MAAM,UAAU,gBAAgB,CAC9B,MAA2F,EAC9D;IAC7B,IAAI,MAAM,YAAY,UAAU,EAAE,CAAC;QACjC,OAAO,MAAM,CAAC;IAChB,CAAC;SAAM,IAAI,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;QACtC,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;IAC7E,CAAC;SAAM,IAAI,iBAAiB,CAAC,MAAM,CAAC,EAAE,CAAC;QACrC,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;SAAM,CAAC;QACN,oBAAoB;QACpB,OAAO,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;AAAA,CACF"}

View File

@@ -0,0 +1,7 @@
export declare function utf8Count(str: string): number;
export declare function utf8EncodeJs(str: string, output: Uint8Array, outputOffset: number): void;
export declare function utf8EncodeTE(str: string, output: Uint8Array, outputOffset: number): void;
export declare function utf8Encode(str: string, output: Uint8Array, outputOffset: number): void;
export declare function utf8DecodeJs(bytes: Uint8Array, inputOffset: number, byteLength: number): string;
export declare function utf8DecodeTD(bytes: Uint8Array, inputOffset: number, byteLength: number): string;
export declare function utf8Decode(bytes: Uint8Array, inputOffset: number, byteLength: number): string;

168
node_modules/@msgpack/msgpack/dist.esm/utils/utf8.mjs generated vendored Normal file
View File

@@ -0,0 +1,168 @@
export function utf8Count(str) {
const strLength = str.length;
let byteLength = 0;
let pos = 0;
while (pos < strLength) {
let value = str.charCodeAt(pos++);
if ((value & 0xffffff80) === 0) {
// 1-byte
byteLength++;
continue;
}
else if ((value & 0xfffff800) === 0) {
// 2-bytes
byteLength += 2;
}
else {
// handle surrogate pair
if (value >= 0xd800 && value <= 0xdbff) {
// high surrogate
if (pos < strLength) {
const extra = str.charCodeAt(pos);
if ((extra & 0xfc00) === 0xdc00) {
++pos;
value = ((value & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000;
}
}
}
if ((value & 0xffff0000) === 0) {
// 3-byte
byteLength += 3;
}
else {
// 4-byte
byteLength += 4;
}
}
}
return byteLength;
}
export function utf8EncodeJs(str, output, outputOffset) {
const strLength = str.length;
let offset = outputOffset;
let pos = 0;
while (pos < strLength) {
let value = str.charCodeAt(pos++);
if ((value & 0xffffff80) === 0) {
// 1-byte
output[offset++] = value;
continue;
}
else if ((value & 0xfffff800) === 0) {
// 2-bytes
output[offset++] = ((value >> 6) & 0x1f) | 0xc0;
}
else {
// handle surrogate pair
if (value >= 0xd800 && value <= 0xdbff) {
// high surrogate
if (pos < strLength) {
const extra = str.charCodeAt(pos);
if ((extra & 0xfc00) === 0xdc00) {
++pos;
value = ((value & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000;
}
}
}
if ((value & 0xffff0000) === 0) {
// 3-byte
output[offset++] = ((value >> 12) & 0x0f) | 0xe0;
output[offset++] = ((value >> 6) & 0x3f) | 0x80;
}
else {
// 4-byte
output[offset++] = ((value >> 18) & 0x07) | 0xf0;
output[offset++] = ((value >> 12) & 0x3f) | 0x80;
output[offset++] = ((value >> 6) & 0x3f) | 0x80;
}
}
output[offset++] = (value & 0x3f) | 0x80;
}
}
// TextEncoder and TextDecoder are standardized in whatwg encoding:
// https://encoding.spec.whatwg.org/
// and available in all the modern browsers:
// https://caniuse.com/textencoder
// They are available in Node.js since v12 LTS as well:
// https://nodejs.org/api/globals.html#textencoder
const sharedTextEncoder = new TextEncoder();
// This threshold should be determined by benchmarking, which might vary in engines and input data.
// Run `npx ts-node benchmark/encode-string.ts` for details.
const TEXT_ENCODER_THRESHOLD = 50;
export function utf8EncodeTE(str, output, outputOffset) {
sharedTextEncoder.encodeInto(str, output.subarray(outputOffset));
}
export function utf8Encode(str, output, outputOffset) {
if (str.length > TEXT_ENCODER_THRESHOLD) {
utf8EncodeTE(str, output, outputOffset);
}
else {
utf8EncodeJs(str, output, outputOffset);
}
}
const CHUNK_SIZE = 4096;
export function utf8DecodeJs(bytes, inputOffset, byteLength) {
let offset = inputOffset;
const end = offset + byteLength;
const units = [];
let result = "";
while (offset < end) {
const byte1 = bytes[offset++];
if ((byte1 & 0x80) === 0) {
// 1 byte
units.push(byte1);
}
else if ((byte1 & 0xe0) === 0xc0) {
// 2 bytes
const byte2 = bytes[offset++] & 0x3f;
units.push(((byte1 & 0x1f) << 6) | byte2);
}
else if ((byte1 & 0xf0) === 0xe0) {
// 3 bytes
const byte2 = bytes[offset++] & 0x3f;
const byte3 = bytes[offset++] & 0x3f;
units.push(((byte1 & 0x1f) << 12) | (byte2 << 6) | byte3);
}
else if ((byte1 & 0xf8) === 0xf0) {
// 4 bytes
const byte2 = bytes[offset++] & 0x3f;
const byte3 = bytes[offset++] & 0x3f;
const byte4 = bytes[offset++] & 0x3f;
let unit = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0c) | (byte3 << 0x06) | byte4;
if (unit > 0xffff) {
unit -= 0x10000;
units.push(((unit >>> 10) & 0x3ff) | 0xd800);
unit = 0xdc00 | (unit & 0x3ff);
}
units.push(unit);
}
else {
units.push(byte1);
}
if (units.length >= CHUNK_SIZE) {
result += String.fromCharCode(...units);
units.length = 0;
}
}
if (units.length > 0) {
result += String.fromCharCode(...units);
}
return result;
}
const sharedTextDecoder = new TextDecoder();
// This threshold should be determined by benchmarking, which might vary in engines and input data.
// Run `npx ts-node benchmark/decode-string.ts` for details.
const TEXT_DECODER_THRESHOLD = 200;
export function utf8DecodeTD(bytes, inputOffset, byteLength) {
const stringBytes = bytes.subarray(inputOffset, inputOffset + byteLength);
return sharedTextDecoder.decode(stringBytes);
}
export function utf8Decode(bytes, inputOffset, byteLength) {
if (byteLength > TEXT_DECODER_THRESHOLD) {
return utf8DecodeTD(bytes, inputOffset, byteLength);
}
else {
return utf8DecodeJs(bytes, inputOffset, byteLength);
}
}
//# sourceMappingURL=utf8.mjs.map

File diff suppressed because one or more lines are too long