@hocuspocus/common
Advanced tools
+100
| //#region node_modules/lib0/encoding.d.ts | ||
| /** | ||
| * A BinaryEncoder handles the encoding to an Uint8Array. | ||
| */ | ||
| declare class Encoder { | ||
| cpos: number; | ||
| cbuf: Uint8Array; | ||
| /** | ||
| * @type {Array<Uint8Array>} | ||
| */ | ||
| bufs: Array<Uint8Array>; | ||
| } | ||
| //#endregion | ||
| //#region node_modules/lib0/decoding.d.ts | ||
| /** | ||
| * A Decoder handles the decoding of an Uint8Array. | ||
| */ | ||
| declare class Decoder { | ||
| /** | ||
| * @param {Uint8Array} uint8Array Binary data to decode | ||
| */ | ||
| constructor(uint8Array: Uint8Array); | ||
| /** | ||
| * Decoding target. | ||
| * | ||
| * @type {Uint8Array} | ||
| */ | ||
| arr: Uint8Array; | ||
| /** | ||
| * Current decoding position. | ||
| * | ||
| * @type {number} | ||
| */ | ||
| pos: number; | ||
| } | ||
| //#endregion | ||
| //#region packages/provider/src/types.d.ts | ||
| type AuthorizedScope = "read-write" | "readonly"; | ||
| //#endregion | ||
| //#region packages/common/src/auth.d.ts | ||
| declare enum AuthMessageType { | ||
| Token = 0, | ||
| PermissionDenied = 1, | ||
| Authenticated = 2 | ||
| } | ||
| declare const writeAuthentication: (encoder: Encoder, auth: string) => void; | ||
| declare const writePermissionDenied: (encoder: Encoder, reason: string) => void; | ||
| declare const writeAuthenticated: (encoder: Encoder, scope: AuthorizedScope) => void; | ||
| declare const writeTokenSyncRequest: (encoder: Encoder) => void; | ||
| declare const readAuthMessage: (decoder: Decoder, sendToken: () => void, permissionDeniedHandler: (reason: string) => void, authenticatedHandler: (scope: string) => void) => void; | ||
| //#endregion | ||
| //#region packages/common/src/CloseEvents.d.ts | ||
| interface CloseEvent { | ||
| code: number; | ||
| reason: string; | ||
| } | ||
| /** | ||
| * The server is terminating the connection because a data frame was received | ||
| * that is too large. | ||
| * See: https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code | ||
| */ | ||
| declare const MessageTooBig: CloseEvent; | ||
| /** | ||
| * The server successfully processed the request, asks that the requester reset | ||
| * its document view, and is not returning any content. | ||
| */ | ||
| declare const ResetConnection: CloseEvent; | ||
| /** | ||
| * Similar to Forbidden, but specifically for use when authentication is required and has | ||
| * failed or has not yet been provided. | ||
| */ | ||
| declare const Unauthorized: CloseEvent; | ||
| /** | ||
| * The request contained valid data and was understood by the server, but the server | ||
| * is refusing action. | ||
| */ | ||
| declare const Forbidden: CloseEvent; | ||
| /** | ||
| * The server timed out waiting for the request. | ||
| */ | ||
| declare const ConnectionTimeout: CloseEvent; | ||
| //#endregion | ||
| //#region packages/common/src/awarenessStatesToArray.d.ts | ||
| declare const awarenessStatesToArray: (states: Map<number, Record<string, any>>) => { | ||
| clientId: number; | ||
| }[]; | ||
| //#endregion | ||
| //#region packages/common/src/types.d.ts | ||
| /** | ||
| * State of the WebSocket connection. | ||
| * https://developer.mozilla.org/de/docs/Web/API/WebSocket/readyState | ||
| */ | ||
| declare enum WsReadyStates { | ||
| Connecting = 0, | ||
| Open = 1, | ||
| Closing = 2, | ||
| Closed = 3 | ||
| } | ||
| //#endregion | ||
| export { AuthMessageType, CloseEvent, ConnectionTimeout, Forbidden, MessageTooBig, ResetConnection, Unauthorized, WsReadyStates, awarenessStatesToArray, readAuthMessage, writeAuthenticated, writeAuthentication, writePermissionDenied, writeTokenSyncRequest }; |
+524
| //#region node_modules/lib0/math.js | ||
| /** | ||
| * Common Math expressions. | ||
| * | ||
| * @module math | ||
| */ | ||
| const floor = Math.floor; | ||
| /** | ||
| * @function | ||
| * @param {number} a | ||
| * @param {number} b | ||
| * @return {number} The smaller element of a and b | ||
| */ | ||
| const min = (a, b) => a < b ? a : b; | ||
| /** | ||
| * @function | ||
| * @param {number} a | ||
| * @param {number} b | ||
| * @return {number} The bigger element of a and b | ||
| */ | ||
| const max = (a, b) => a > b ? a : b; | ||
| const isNaN$1 = Number.isNaN; | ||
| //#endregion | ||
| //#region node_modules/lib0/binary.js | ||
| const BIT8 = 128; | ||
| const BIT18 = 1 << 17; | ||
| const BIT19 = 1 << 18; | ||
| const BIT20 = 1 << 19; | ||
| const BIT21 = 1 << 20; | ||
| const BIT22 = 1 << 21; | ||
| const BIT23 = 1 << 22; | ||
| const BIT24 = 1 << 23; | ||
| const BIT25 = 1 << 24; | ||
| const BIT26 = 1 << 25; | ||
| const BIT27 = 1 << 26; | ||
| const BIT28 = 1 << 27; | ||
| const BIT29 = 1 << 28; | ||
| const BIT30 = 1 << 29; | ||
| const BIT31 = 1 << 30; | ||
| const BIT32 = 1 << 31; | ||
| const BITS7 = 127; | ||
| const BITS17 = BIT18 - 1; | ||
| const BITS18 = BIT19 - 1; | ||
| const BITS19 = BIT20 - 1; | ||
| const BITS20 = BIT21 - 1; | ||
| const BITS21 = BIT22 - 1; | ||
| const BITS22 = BIT23 - 1; | ||
| const BITS23 = BIT24 - 1; | ||
| const BITS24 = BIT25 - 1; | ||
| const BITS25 = BIT26 - 1; | ||
| const BITS26 = BIT27 - 1; | ||
| const BITS27 = BIT28 - 1; | ||
| const BITS28 = BIT29 - 1; | ||
| const BITS29 = BIT30 - 1; | ||
| const BITS30 = BIT31 - 1; | ||
| /** | ||
| * @type {number} | ||
| */ | ||
| const BITS31 = 2147483647; | ||
| /** | ||
| * @type {number} | ||
| */ | ||
| const BITS32 = 4294967295; | ||
| //#endregion | ||
| //#region node_modules/lib0/number.js | ||
| /** | ||
| * Utility helpers for working with numbers. | ||
| * | ||
| * @module number | ||
| */ | ||
| const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER; | ||
| const MIN_SAFE_INTEGER = Number.MIN_SAFE_INTEGER; | ||
| const LOWEST_INT32 = 1 << 31; | ||
| const HIGHEST_INT32 = BITS31; | ||
| const HIGHEST_UINT32 = BITS32; | ||
| /* c8 ignore next */ | ||
| const isInteger = Number.isInteger || ((num) => typeof num === "number" && isFinite(num) && floor(num) === num); | ||
| const isNaN = Number.isNaN; | ||
| const parseInt = Number.parseInt; | ||
| //#endregion | ||
| //#region node_modules/lib0/string.js | ||
| /** | ||
| * Utility module to work with strings. | ||
| * | ||
| * @module string | ||
| */ | ||
| const fromCharCode = String.fromCharCode; | ||
| const fromCodePoint = String.fromCodePoint; | ||
| /** | ||
| * The largest utf16 character. | ||
| * Corresponds to Uint8Array([255, 255]) or charcodeof(2x2^8) | ||
| */ | ||
| const MAX_UTF16_CHARACTER = fromCharCode(65535); | ||
| /** | ||
| * @param {string} str | ||
| * @return {Uint8Array} | ||
| */ | ||
| const _encodeUtf8Polyfill = (str) => { | ||
| const encodedString = unescape(encodeURIComponent(str)); | ||
| const len = encodedString.length; | ||
| const buf = new Uint8Array(len); | ||
| for (let i = 0; i < len; i++) buf[i] = encodedString.codePointAt(i); | ||
| return buf; | ||
| }; | ||
| /* c8 ignore next */ | ||
| const utf8TextEncoder = typeof TextEncoder !== "undefined" ? new TextEncoder() : null; | ||
| /** | ||
| * @param {string} str | ||
| * @return {Uint8Array} | ||
| */ | ||
| const _encodeUtf8Native = (str) => utf8TextEncoder.encode(str); | ||
| /** | ||
| * @param {string} str | ||
| * @return {Uint8Array} | ||
| */ | ||
| /* c8 ignore next */ | ||
| const encodeUtf8 = utf8TextEncoder ? _encodeUtf8Native : _encodeUtf8Polyfill; | ||
| /* c8 ignore next */ | ||
| let utf8TextDecoder = typeof TextDecoder === "undefined" ? null : new TextDecoder("utf-8", { | ||
| fatal: true, | ||
| ignoreBOM: true | ||
| }); | ||
| /* c8 ignore start */ | ||
| if (utf8TextDecoder && utf8TextDecoder.decode(new Uint8Array()).length === 1) | ||
| /* c8 ignore next */ | ||
| utf8TextDecoder = null; | ||
| //#endregion | ||
| //#region node_modules/lib0/encoding.js | ||
| /** | ||
| * Efficient schema-less binary encoding with support for variable length encoding. | ||
| * | ||
| * Use [lib0/encoding] with [lib0/decoding]. Every encoding function has a corresponding decoding function. | ||
| * | ||
| * Encodes numbers in little-endian order (least to most significant byte order) | ||
| * and is compatible with Golang's binary encoding (https://golang.org/pkg/encoding/binary/) | ||
| * which is also used in Protocol Buffers. | ||
| * | ||
| * ```js | ||
| * // encoding step | ||
| * const encoder = encoding.createEncoder() | ||
| * encoding.writeVarUint(encoder, 256) | ||
| * encoding.writeVarString(encoder, 'Hello world!') | ||
| * const buf = encoding.toUint8Array(encoder) | ||
| * ``` | ||
| * | ||
| * ```js | ||
| * // decoding step | ||
| * const decoder = decoding.createDecoder(buf) | ||
| * decoding.readVarUint(decoder) // => 256 | ||
| * decoding.readVarString(decoder) // => 'Hello world!' | ||
| * decoding.hasContent(decoder) // => false - all data is read | ||
| * ``` | ||
| * | ||
| * @module encoding | ||
| */ | ||
| /** | ||
| * Write one byte to the encoder. | ||
| * | ||
| * @function | ||
| * @param {Encoder} encoder | ||
| * @param {number} num The byte that is to be encoded. | ||
| */ | ||
| const write = (encoder, num) => { | ||
| const bufferLen = encoder.cbuf.length; | ||
| if (encoder.cpos === bufferLen) { | ||
| encoder.bufs.push(encoder.cbuf); | ||
| encoder.cbuf = new Uint8Array(bufferLen * 2); | ||
| encoder.cpos = 0; | ||
| } | ||
| encoder.cbuf[encoder.cpos++] = num; | ||
| }; | ||
| /** | ||
| * Write a variable length unsigned integer. Max encodable integer is 2^53. | ||
| * | ||
| * @function | ||
| * @param {Encoder} encoder | ||
| * @param {number} num The number that is to be encoded. | ||
| */ | ||
| const writeVarUint = (encoder, num) => { | ||
| while (num > BITS7) { | ||
| write(encoder, BIT8 | BITS7 & num); | ||
| num = floor(num / 128); | ||
| } | ||
| write(encoder, BITS7 & num); | ||
| }; | ||
| /** | ||
| * A cache to store strings temporarily | ||
| */ | ||
| const _strBuffer = new Uint8Array(3e4); | ||
| const _maxStrBSize = _strBuffer.length / 3; | ||
| /** | ||
| * Write a variable length string. | ||
| * | ||
| * @function | ||
| * @param {Encoder} encoder | ||
| * @param {String} str The string that is to be encoded. | ||
| */ | ||
| const _writeVarStringNative = (encoder, str) => { | ||
| if (str.length < _maxStrBSize) { | ||
| /* c8 ignore next */ | ||
| const written = utf8TextEncoder.encodeInto(str, _strBuffer).written || 0; | ||
| writeVarUint(encoder, written); | ||
| for (let i = 0; i < written; i++) write(encoder, _strBuffer[i]); | ||
| } else writeVarUint8Array(encoder, encodeUtf8(str)); | ||
| }; | ||
| /** | ||
| * Write a variable length string. | ||
| * | ||
| * @function | ||
| * @param {Encoder} encoder | ||
| * @param {String} str The string that is to be encoded. | ||
| */ | ||
| const _writeVarStringPolyfill = (encoder, str) => { | ||
| const encodedString = unescape(encodeURIComponent(str)); | ||
| const len = encodedString.length; | ||
| writeVarUint(encoder, len); | ||
| for (let i = 0; i < len; i++) write(encoder, encodedString.codePointAt(i)); | ||
| }; | ||
| /** | ||
| * Write a variable length string. | ||
| * | ||
| * @function | ||
| * @param {Encoder} encoder | ||
| * @param {String} str The string that is to be encoded. | ||
| */ | ||
| /* c8 ignore next */ | ||
| const writeVarString = utf8TextEncoder && utf8TextEncoder.encodeInto ? _writeVarStringNative : _writeVarStringPolyfill; | ||
| /** | ||
| * Append fixed-length Uint8Array to the encoder. | ||
| * | ||
| * @function | ||
| * @param {Encoder} encoder | ||
| * @param {Uint8Array} uint8Array | ||
| */ | ||
| const writeUint8Array = (encoder, uint8Array) => { | ||
| const bufferLen = encoder.cbuf.length; | ||
| const cpos = encoder.cpos; | ||
| const leftCopyLen = min(bufferLen - cpos, uint8Array.length); | ||
| const rightCopyLen = uint8Array.length - leftCopyLen; | ||
| encoder.cbuf.set(uint8Array.subarray(0, leftCopyLen), cpos); | ||
| encoder.cpos += leftCopyLen; | ||
| if (rightCopyLen > 0) { | ||
| encoder.bufs.push(encoder.cbuf); | ||
| encoder.cbuf = new Uint8Array(max(bufferLen * 2, rightCopyLen)); | ||
| encoder.cbuf.set(uint8Array.subarray(leftCopyLen)); | ||
| encoder.cpos = rightCopyLen; | ||
| } | ||
| }; | ||
| /** | ||
| * Append an Uint8Array to Encoder. | ||
| * | ||
| * @function | ||
| * @param {Encoder} encoder | ||
| * @param {Uint8Array} uint8Array | ||
| */ | ||
| const writeVarUint8Array = (encoder, uint8Array) => { | ||
| writeVarUint(encoder, uint8Array.byteLength); | ||
| writeUint8Array(encoder, uint8Array); | ||
| }; | ||
| //#endregion | ||
| //#region node_modules/lib0/error.js | ||
| /** | ||
| * Error helpers. | ||
| * | ||
| * @module error | ||
| */ | ||
| /** | ||
| * @param {string} s | ||
| * @return {Error} | ||
| */ | ||
| /* c8 ignore next */ | ||
| const create = (s) => new Error(s); | ||
| //#endregion | ||
| //#region node_modules/lib0/decoding.js | ||
| /** | ||
| * Efficient schema-less binary decoding with support for variable length encoding. | ||
| * | ||
| * Use [lib0/decoding] with [lib0/encoding]. Every encoding function has a corresponding decoding function. | ||
| * | ||
| * Encodes numbers in little-endian order (least to most significant byte order) | ||
| * and is compatible with Golang's binary encoding (https://golang.org/pkg/encoding/binary/) | ||
| * which is also used in Protocol Buffers. | ||
| * | ||
| * ```js | ||
| * // encoding step | ||
| * const encoder = encoding.createEncoder() | ||
| * encoding.writeVarUint(encoder, 256) | ||
| * encoding.writeVarString(encoder, 'Hello world!') | ||
| * const buf = encoding.toUint8Array(encoder) | ||
| * ``` | ||
| * | ||
| * ```js | ||
| * // decoding step | ||
| * const decoder = decoding.createDecoder(buf) | ||
| * decoding.readVarUint(decoder) // => 256 | ||
| * decoding.readVarString(decoder) // => 'Hello world!' | ||
| * decoding.hasContent(decoder) // => false - all data is read | ||
| * ``` | ||
| * | ||
| * @module decoding | ||
| */ | ||
| const errorUnexpectedEndOfArray = create("Unexpected end of array"); | ||
| const errorIntegerOutOfRange = create("Integer out of Range"); | ||
| /** | ||
| * Create an Uint8Array view of the next `len` bytes and advance the position by `len`. | ||
| * | ||
| * Important: The Uint8Array still points to the underlying ArrayBuffer. Make sure to discard the result as soon as possible to prevent any memory leaks. | ||
| * Use `buffer.copyUint8Array` to copy the result into a new Uint8Array. | ||
| * | ||
| * @function | ||
| * @param {Decoder} decoder The decoder instance | ||
| * @param {number} len The length of bytes to read | ||
| * @return {Uint8Array} | ||
| */ | ||
| const readUint8Array = (decoder, len) => { | ||
| const view = new Uint8Array(decoder.arr.buffer, decoder.pos + decoder.arr.byteOffset, len); | ||
| decoder.pos += len; | ||
| return view; | ||
| }; | ||
| /** | ||
| * Read variable length Uint8Array. | ||
| * | ||
| * Important: The Uint8Array still points to the underlying ArrayBuffer. Make sure to discard the result as soon as possible to prevent any memory leaks. | ||
| * Use `buffer.copyUint8Array` to copy the result into a new Uint8Array. | ||
| * | ||
| * @function | ||
| * @param {Decoder} decoder | ||
| * @return {Uint8Array} | ||
| */ | ||
| const readVarUint8Array = (decoder) => readUint8Array(decoder, readVarUint(decoder)); | ||
| /** | ||
| * Read one byte as unsigned integer. | ||
| * @function | ||
| * @param {Decoder} decoder The decoder instance | ||
| * @return {number} Unsigned 8-bit integer | ||
| */ | ||
| const readUint8 = (decoder) => decoder.arr[decoder.pos++]; | ||
| /** | ||
| * Read unsigned integer (32bit) with variable length. | ||
| * 1/8th of the storage is used as encoding overhead. | ||
| * * numbers < 2^7 is stored in one bytlength | ||
| * * numbers < 2^14 is stored in two bylength | ||
| * | ||
| * @function | ||
| * @param {Decoder} decoder | ||
| * @return {number} An unsigned integer.length | ||
| */ | ||
| const readVarUint = (decoder) => { | ||
| let num = 0; | ||
| let mult = 1; | ||
| const len = decoder.arr.length; | ||
| while (decoder.pos < len) { | ||
| const r = decoder.arr[decoder.pos++]; | ||
| num = num + (r & BITS7) * mult; | ||
| mult *= 128; | ||
| if (r < BIT8) return num; | ||
| /* c8 ignore start */ | ||
| if (num > MAX_SAFE_INTEGER) throw errorIntegerOutOfRange; | ||
| } | ||
| throw errorUnexpectedEndOfArray; | ||
| }; | ||
| /** | ||
| * We don't test this function anymore as we use native decoding/encoding by default now. | ||
| * Better not modify this anymore.. | ||
| * | ||
| * Transforming utf8 to a string is pretty expensive. The code performs 10x better | ||
| * when String.fromCodePoint is fed with all characters as arguments. | ||
| * But most environments have a maximum number of arguments per functions. | ||
| * For effiency reasons we apply a maximum of 10000 characters at once. | ||
| * | ||
| * @function | ||
| * @param {Decoder} decoder | ||
| * @return {String} The read String. | ||
| */ | ||
| /* c8 ignore start */ | ||
| const _readVarStringPolyfill = (decoder) => { | ||
| let remainingLen = readVarUint(decoder); | ||
| if (remainingLen === 0) return ""; | ||
| else { | ||
| let encodedString = String.fromCodePoint(readUint8(decoder)); | ||
| if (--remainingLen < 100) while (remainingLen--) encodedString += String.fromCodePoint(readUint8(decoder)); | ||
| else while (remainingLen > 0) { | ||
| const nextLen = remainingLen < 1e4 ? remainingLen : 1e4; | ||
| const bytes = decoder.arr.subarray(decoder.pos, decoder.pos + nextLen); | ||
| decoder.pos += nextLen; | ||
| encodedString += String.fromCodePoint.apply(null, bytes); | ||
| remainingLen -= nextLen; | ||
| } | ||
| return decodeURIComponent(escape(encodedString)); | ||
| } | ||
| }; | ||
| /* c8 ignore stop */ | ||
| /** | ||
| * @function | ||
| * @param {Decoder} decoder | ||
| * @return {String} The read String | ||
| */ | ||
| const _readVarStringNative = (decoder) => utf8TextDecoder.decode(readVarUint8Array(decoder)); | ||
| /** | ||
| * Read string of variable length | ||
| * * varUint is used to store the length of the string | ||
| * | ||
| * @function | ||
| * @param {Decoder} decoder | ||
| * @return {String} The read String | ||
| * | ||
| */ | ||
| /* c8 ignore next */ | ||
| const readVarString = utf8TextDecoder ? _readVarStringNative : _readVarStringPolyfill; | ||
| //#endregion | ||
| //#region packages/common/src/auth.ts | ||
| let AuthMessageType = /* @__PURE__ */ function(AuthMessageType) { | ||
| AuthMessageType[AuthMessageType["Token"] = 0] = "Token"; | ||
| AuthMessageType[AuthMessageType["PermissionDenied"] = 1] = "PermissionDenied"; | ||
| AuthMessageType[AuthMessageType["Authenticated"] = 2] = "Authenticated"; | ||
| return AuthMessageType; | ||
| }({}); | ||
| const writeAuthentication = (encoder, auth) => { | ||
| writeVarUint(encoder, AuthMessageType.Token); | ||
| writeVarString(encoder, auth); | ||
| }; | ||
| const writePermissionDenied = (encoder, reason) => { | ||
| writeVarUint(encoder, AuthMessageType.PermissionDenied); | ||
| writeVarString(encoder, reason); | ||
| }; | ||
| const writeAuthenticated = (encoder, scope) => { | ||
| writeVarUint(encoder, AuthMessageType.Authenticated); | ||
| writeVarString(encoder, scope); | ||
| }; | ||
| const writeTokenSyncRequest = (encoder) => { | ||
| writeVarUint(encoder, AuthMessageType.Token); | ||
| }; | ||
| const readAuthMessage = (decoder, sendToken, permissionDeniedHandler, authenticatedHandler) => { | ||
| switch (readVarUint(decoder)) { | ||
| case AuthMessageType.Token: | ||
| sendToken(); | ||
| break; | ||
| case AuthMessageType.PermissionDenied: | ||
| permissionDeniedHandler(readVarString(decoder)); | ||
| break; | ||
| case AuthMessageType.Authenticated: | ||
| authenticatedHandler(readVarString(decoder)); | ||
| break; | ||
| default: | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region packages/common/src/CloseEvents.ts | ||
| /** | ||
| * The server is terminating the connection because a data frame was received | ||
| * that is too large. | ||
| * See: https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code | ||
| */ | ||
| const MessageTooBig = { | ||
| code: 1009, | ||
| reason: "Message Too Big" | ||
| }; | ||
| /** | ||
| * The server successfully processed the request, asks that the requester reset | ||
| * its document view, and is not returning any content. | ||
| */ | ||
| const ResetConnection = { | ||
| code: 4205, | ||
| reason: "Reset Connection" | ||
| }; | ||
| /** | ||
| * Similar to Forbidden, but specifically for use when authentication is required and has | ||
| * failed or has not yet been provided. | ||
| */ | ||
| const Unauthorized = { | ||
| code: 4401, | ||
| reason: "Unauthorized" | ||
| }; | ||
| /** | ||
| * The request contained valid data and was understood by the server, but the server | ||
| * is refusing action. | ||
| */ | ||
| const Forbidden = { | ||
| code: 4403, | ||
| reason: "Forbidden" | ||
| }; | ||
| /** | ||
| * The server timed out waiting for the request. | ||
| */ | ||
| const ConnectionTimeout = { | ||
| code: 4408, | ||
| reason: "Connection Timeout" | ||
| }; | ||
| //#endregion | ||
| //#region packages/common/src/awarenessStatesToArray.ts | ||
| const awarenessStatesToArray = (states) => { | ||
| return Array.from(states.entries()).map(([key, value]) => { | ||
| return { | ||
| clientId: key, | ||
| ...value | ||
| }; | ||
| }); | ||
| }; | ||
| //#endregion | ||
| //#region packages/common/src/types.ts | ||
| /** | ||
| * State of the WebSocket connection. | ||
| * https://developer.mozilla.org/de/docs/Web/API/WebSocket/readyState | ||
| */ | ||
| let WsReadyStates = /* @__PURE__ */ function(WsReadyStates) { | ||
| WsReadyStates[WsReadyStates["Connecting"] = 0] = "Connecting"; | ||
| WsReadyStates[WsReadyStates["Open"] = 1] = "Open"; | ||
| WsReadyStates[WsReadyStates["Closing"] = 2] = "Closing"; | ||
| WsReadyStates[WsReadyStates["Closed"] = 3] = "Closed"; | ||
| return WsReadyStates; | ||
| }({}); | ||
| //#endregion | ||
| export { AuthMessageType, ConnectionTimeout, Forbidden, MessageTooBig, ResetConnection, Unauthorized, WsReadyStates, awarenessStatesToArray, readAuthMessage, writeAuthenticated, writeAuthentication, writePermissionDenied, writeTokenSyncRequest }; |
+427
-409
@@ -1,510 +0,527 @@ | ||
| 'use strict'; | ||
| Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); | ||
| //#region node_modules/lib0/math.js | ||
| /** | ||
| * Common Math expressions. | ||
| * | ||
| * @module math | ||
| */ | ||
| * Common Math expressions. | ||
| * | ||
| * @module math | ||
| */ | ||
| const floor = Math.floor; | ||
| /** | ||
| * @function | ||
| * @param {number} a | ||
| * @param {number} b | ||
| * @return {number} The smaller element of a and b | ||
| */ | ||
| * @function | ||
| * @param {number} a | ||
| * @param {number} b | ||
| * @return {number} The smaller element of a and b | ||
| */ | ||
| const min = (a, b) => a < b ? a : b; | ||
| /** | ||
| * @function | ||
| * @param {number} a | ||
| * @param {number} b | ||
| * @return {number} The bigger element of a and b | ||
| */ | ||
| * @function | ||
| * @param {number} a | ||
| * @param {number} b | ||
| * @return {number} The bigger element of a and b | ||
| */ | ||
| const max = (a, b) => a > b ? a : b; | ||
| const isNaN$1 = Number.isNaN; | ||
| /* eslint-env browser */ | ||
| //#endregion | ||
| //#region node_modules/lib0/binary.js | ||
| const BIT8 = 128; | ||
| const BIT18 = 1 << 17; | ||
| const BIT19 = 1 << 18; | ||
| const BIT20 = 1 << 19; | ||
| const BIT21 = 1 << 20; | ||
| const BIT22 = 1 << 21; | ||
| const BIT23 = 1 << 22; | ||
| const BIT24 = 1 << 23; | ||
| const BIT25 = 1 << 24; | ||
| const BIT26 = 1 << 25; | ||
| const BIT27 = 1 << 26; | ||
| const BIT28 = 1 << 27; | ||
| const BIT29 = 1 << 28; | ||
| const BIT30 = 1 << 29; | ||
| const BIT31 = 1 << 30; | ||
| const BIT32 = 1 << 31; | ||
| const BITS7 = 127; | ||
| const BITS17 = BIT18 - 1; | ||
| const BITS18 = BIT19 - 1; | ||
| const BITS19 = BIT20 - 1; | ||
| const BITS20 = BIT21 - 1; | ||
| const BITS21 = BIT22 - 1; | ||
| const BITS22 = BIT23 - 1; | ||
| const BITS23 = BIT24 - 1; | ||
| const BITS24 = BIT25 - 1; | ||
| const BITS25 = BIT26 - 1; | ||
| const BITS26 = BIT27 - 1; | ||
| const BITS27 = BIT28 - 1; | ||
| const BITS28 = BIT29 - 1; | ||
| const BITS29 = BIT30 - 1; | ||
| const BITS30 = BIT31 - 1; | ||
| /** | ||
| * @type {number} | ||
| */ | ||
| const BITS31 = 2147483647; | ||
| /** | ||
| * @type {number} | ||
| */ | ||
| const BITS32 = 4294967295; | ||
| //#endregion | ||
| //#region node_modules/lib0/number.js | ||
| /** | ||
| * Utility helpers for working with numbers. | ||
| * | ||
| * @module number | ||
| */ | ||
| * Utility helpers for working with numbers. | ||
| * | ||
| * @module number | ||
| */ | ||
| const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER; | ||
| const MIN_SAFE_INTEGER = Number.MIN_SAFE_INTEGER; | ||
| const LOWEST_INT32 = 1 << 31; | ||
| const HIGHEST_INT32 = BITS31; | ||
| const HIGHEST_UINT32 = BITS32; | ||
| /* c8 ignore next */ | ||
| const isInteger = Number.isInteger || ((num) => typeof num === "number" && isFinite(num) && floor(num) === num); | ||
| const isNaN = Number.isNaN; | ||
| const parseInt = Number.parseInt; | ||
| //#endregion | ||
| //#region node_modules/lib0/string.js | ||
| /** | ||
| * @param {string} str | ||
| * @return {Uint8Array} | ||
| */ | ||
| const _encodeUtf8Polyfill = str => { | ||
| const encodedString = unescape(encodeURIComponent(str)); | ||
| const len = encodedString.length; | ||
| const buf = new Uint8Array(len); | ||
| for (let i = 0; i < len; i++) { | ||
| buf[i] = /** @type {number} */ (encodedString.codePointAt(i)); | ||
| } | ||
| return buf | ||
| * Utility module to work with strings. | ||
| * | ||
| * @module string | ||
| */ | ||
| const fromCharCode = String.fromCharCode; | ||
| const fromCodePoint = String.fromCodePoint; | ||
| /** | ||
| * The largest utf16 character. | ||
| * Corresponds to Uint8Array([255, 255]) or charcodeof(2x2^8) | ||
| */ | ||
| const MAX_UTF16_CHARACTER = fromCharCode(65535); | ||
| /** | ||
| * @param {string} str | ||
| * @return {Uint8Array} | ||
| */ | ||
| const _encodeUtf8Polyfill = (str) => { | ||
| const encodedString = unescape(encodeURIComponent(str)); | ||
| const len = encodedString.length; | ||
| const buf = new Uint8Array(len); | ||
| for (let i = 0; i < len; i++) buf[i] = encodedString.codePointAt(i); | ||
| return buf; | ||
| }; | ||
| /* c8 ignore next */ | ||
| const utf8TextEncoder = /** @type {TextEncoder} */ (typeof TextEncoder !== 'undefined' ? new TextEncoder() : null); | ||
| const utf8TextEncoder = typeof TextEncoder !== "undefined" ? new TextEncoder() : null; | ||
| /** | ||
| * @param {string} str | ||
| * @return {Uint8Array} | ||
| */ | ||
| const _encodeUtf8Native = str => utf8TextEncoder.encode(str); | ||
| * @param {string} str | ||
| * @return {Uint8Array} | ||
| */ | ||
| const _encodeUtf8Native = (str) => utf8TextEncoder.encode(str); | ||
| /** | ||
| * @param {string} str | ||
| * @return {Uint8Array} | ||
| */ | ||
| * @param {string} str | ||
| * @return {Uint8Array} | ||
| */ | ||
| /* c8 ignore next */ | ||
| const encodeUtf8 = utf8TextEncoder ? _encodeUtf8Native : _encodeUtf8Polyfill; | ||
| /* c8 ignore next */ | ||
| let utf8TextDecoder = typeof TextDecoder === 'undefined' ? null : new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }); | ||
| let utf8TextDecoder = typeof TextDecoder === "undefined" ? null : new TextDecoder("utf-8", { | ||
| fatal: true, | ||
| ignoreBOM: true | ||
| }); | ||
| /* c8 ignore start */ | ||
| if (utf8TextDecoder && utf8TextDecoder.decode(new Uint8Array()).length === 1) { | ||
| // Safari doesn't handle BOM correctly. | ||
| // This fixes a bug in Safari 13.0.5 where it produces a BOM the first time it is called. | ||
| // utf8TextDecoder.decode(new Uint8Array()).length === 1 on the first call and | ||
| // utf8TextDecoder.decode(new Uint8Array()).length === 1 on the second call | ||
| // Another issue is that from then on no BOM chars are recognized anymore | ||
| /* c8 ignore next */ | ||
| utf8TextDecoder = null; | ||
| } | ||
| if (utf8TextDecoder && utf8TextDecoder.decode(new Uint8Array()).length === 1) | ||
| /* c8 ignore next */ | ||
| utf8TextDecoder = null; | ||
| //#endregion | ||
| //#region node_modules/lib0/encoding.js | ||
| /** | ||
| * Efficient schema-less binary encoding with support for variable length encoding. | ||
| * | ||
| * Use [lib0/encoding] with [lib0/decoding]. Every encoding function has a corresponding decoding function. | ||
| * | ||
| * Encodes numbers in little-endian order (least to most significant byte order) | ||
| * and is compatible with Golang's binary encoding (https://golang.org/pkg/encoding/binary/) | ||
| * which is also used in Protocol Buffers. | ||
| * | ||
| * ```js | ||
| * // encoding step | ||
| * const encoder = encoding.createEncoder() | ||
| * encoding.writeVarUint(encoder, 256) | ||
| * encoding.writeVarString(encoder, 'Hello world!') | ||
| * const buf = encoding.toUint8Array(encoder) | ||
| * ``` | ||
| * | ||
| * ```js | ||
| * // decoding step | ||
| * const decoder = decoding.createDecoder(buf) | ||
| * decoding.readVarUint(decoder) // => 256 | ||
| * decoding.readVarString(decoder) // => 'Hello world!' | ||
| * decoding.hasContent(decoder) // => false - all data is read | ||
| * ``` | ||
| * | ||
| * @module encoding | ||
| */ | ||
| * Efficient schema-less binary encoding with support for variable length encoding. | ||
| * | ||
| * Use [lib0/encoding] with [lib0/decoding]. Every encoding function has a corresponding decoding function. | ||
| * | ||
| * Encodes numbers in little-endian order (least to most significant byte order) | ||
| * and is compatible with Golang's binary encoding (https://golang.org/pkg/encoding/binary/) | ||
| * which is also used in Protocol Buffers. | ||
| * | ||
| * ```js | ||
| * // encoding step | ||
| * const encoder = encoding.createEncoder() | ||
| * encoding.writeVarUint(encoder, 256) | ||
| * encoding.writeVarString(encoder, 'Hello world!') | ||
| * const buf = encoding.toUint8Array(encoder) | ||
| * ``` | ||
| * | ||
| * ```js | ||
| * // decoding step | ||
| * const decoder = decoding.createDecoder(buf) | ||
| * decoding.readVarUint(decoder) // => 256 | ||
| * decoding.readVarString(decoder) // => 'Hello world!' | ||
| * decoding.hasContent(decoder) // => false - all data is read | ||
| * ``` | ||
| * | ||
| * @module encoding | ||
| */ | ||
| /** | ||
| * Write one byte to the encoder. | ||
| * | ||
| * @function | ||
| * @param {Encoder} encoder | ||
| * @param {number} num The byte that is to be encoded. | ||
| */ | ||
| * Write one byte to the encoder. | ||
| * | ||
| * @function | ||
| * @param {Encoder} encoder | ||
| * @param {number} num The byte that is to be encoded. | ||
| */ | ||
| const write = (encoder, num) => { | ||
| const bufferLen = encoder.cbuf.length; | ||
| if (encoder.cpos === bufferLen) { | ||
| encoder.bufs.push(encoder.cbuf); | ||
| encoder.cbuf = new Uint8Array(bufferLen * 2); | ||
| encoder.cpos = 0; | ||
| } | ||
| encoder.cbuf[encoder.cpos++] = num; | ||
| const bufferLen = encoder.cbuf.length; | ||
| if (encoder.cpos === bufferLen) { | ||
| encoder.bufs.push(encoder.cbuf); | ||
| encoder.cbuf = new Uint8Array(bufferLen * 2); | ||
| encoder.cpos = 0; | ||
| } | ||
| encoder.cbuf[encoder.cpos++] = num; | ||
| }; | ||
| /** | ||
| * Write a variable length unsigned integer. Max encodable integer is 2^53. | ||
| * | ||
| * @function | ||
| * @param {Encoder} encoder | ||
| * @param {number} num The number that is to be encoded. | ||
| */ | ||
| * Write a variable length unsigned integer. Max encodable integer is 2^53. | ||
| * | ||
| * @function | ||
| * @param {Encoder} encoder | ||
| * @param {number} num The number that is to be encoded. | ||
| */ | ||
| const writeVarUint = (encoder, num) => { | ||
| while (num > BITS7) { | ||
| write(encoder, BIT8 | (BITS7 & num)); | ||
| num = floor(num / 128); // shift >>> 7 | ||
| } | ||
| write(encoder, BITS7 & num); | ||
| while (num > BITS7) { | ||
| write(encoder, BIT8 | BITS7 & num); | ||
| num = floor(num / 128); | ||
| } | ||
| write(encoder, BITS7 & num); | ||
| }; | ||
| /** | ||
| * A cache to store strings temporarily | ||
| */ | ||
| const _strBuffer = new Uint8Array(30000); | ||
| * A cache to store strings temporarily | ||
| */ | ||
| const _strBuffer = new Uint8Array(3e4); | ||
| const _maxStrBSize = _strBuffer.length / 3; | ||
| /** | ||
| * Write a variable length string. | ||
| * | ||
| * @function | ||
| * @param {Encoder} encoder | ||
| * @param {String} str The string that is to be encoded. | ||
| */ | ||
| * Write a variable length string. | ||
| * | ||
| * @function | ||
| * @param {Encoder} encoder | ||
| * @param {String} str The string that is to be encoded. | ||
| */ | ||
| const _writeVarStringNative = (encoder, str) => { | ||
| if (str.length < _maxStrBSize) { | ||
| // We can encode the string into the existing buffer | ||
| /* c8 ignore next */ | ||
| const written = utf8TextEncoder.encodeInto(str, _strBuffer).written || 0; | ||
| writeVarUint(encoder, written); | ||
| for (let i = 0; i < written; i++) { | ||
| write(encoder, _strBuffer[i]); | ||
| } | ||
| } else { | ||
| writeVarUint8Array(encoder, encodeUtf8(str)); | ||
| } | ||
| if (str.length < _maxStrBSize) { | ||
| /* c8 ignore next */ | ||
| const written = utf8TextEncoder.encodeInto(str, _strBuffer).written || 0; | ||
| writeVarUint(encoder, written); | ||
| for (let i = 0; i < written; i++) write(encoder, _strBuffer[i]); | ||
| } else writeVarUint8Array(encoder, encodeUtf8(str)); | ||
| }; | ||
| /** | ||
| * Write a variable length string. | ||
| * | ||
| * @function | ||
| * @param {Encoder} encoder | ||
| * @param {String} str The string that is to be encoded. | ||
| */ | ||
| * Write a variable length string. | ||
| * | ||
| * @function | ||
| * @param {Encoder} encoder | ||
| * @param {String} str The string that is to be encoded. | ||
| */ | ||
| const _writeVarStringPolyfill = (encoder, str) => { | ||
| const encodedString = unescape(encodeURIComponent(str)); | ||
| const len = encodedString.length; | ||
| writeVarUint(encoder, len); | ||
| for (let i = 0; i < len; i++) { | ||
| write(encoder, /** @type {number} */ (encodedString.codePointAt(i))); | ||
| } | ||
| const encodedString = unescape(encodeURIComponent(str)); | ||
| const len = encodedString.length; | ||
| writeVarUint(encoder, len); | ||
| for (let i = 0; i < len; i++) write(encoder, encodedString.codePointAt(i)); | ||
| }; | ||
| /** | ||
| * Write a variable length string. | ||
| * | ||
| * @function | ||
| * @param {Encoder} encoder | ||
| * @param {String} str The string that is to be encoded. | ||
| */ | ||
| * Write a variable length string. | ||
| * | ||
| * @function | ||
| * @param {Encoder} encoder | ||
| * @param {String} str The string that is to be encoded. | ||
| */ | ||
| /* c8 ignore next */ | ||
| const writeVarString = (utf8TextEncoder && /** @type {any} */ (utf8TextEncoder).encodeInto) ? _writeVarStringNative : _writeVarStringPolyfill; | ||
| const writeVarString = utf8TextEncoder && utf8TextEncoder.encodeInto ? _writeVarStringNative : _writeVarStringPolyfill; | ||
| /** | ||
| * Append fixed-length Uint8Array to the encoder. | ||
| * | ||
| * @function | ||
| * @param {Encoder} encoder | ||
| * @param {Uint8Array} uint8Array | ||
| */ | ||
| * Append fixed-length Uint8Array to the encoder. | ||
| * | ||
| * @function | ||
| * @param {Encoder} encoder | ||
| * @param {Uint8Array} uint8Array | ||
| */ | ||
| const writeUint8Array = (encoder, uint8Array) => { | ||
| const bufferLen = encoder.cbuf.length; | ||
| const cpos = encoder.cpos; | ||
| const leftCopyLen = min(bufferLen - cpos, uint8Array.length); | ||
| const rightCopyLen = uint8Array.length - leftCopyLen; | ||
| encoder.cbuf.set(uint8Array.subarray(0, leftCopyLen), cpos); | ||
| encoder.cpos += leftCopyLen; | ||
| if (rightCopyLen > 0) { | ||
| // Still something to write, write right half.. | ||
| // Append new buffer | ||
| encoder.bufs.push(encoder.cbuf); | ||
| // must have at least size of remaining buffer | ||
| encoder.cbuf = new Uint8Array(max(bufferLen * 2, rightCopyLen)); | ||
| // copy array | ||
| encoder.cbuf.set(uint8Array.subarray(leftCopyLen)); | ||
| encoder.cpos = rightCopyLen; | ||
| } | ||
| const bufferLen = encoder.cbuf.length; | ||
| const cpos = encoder.cpos; | ||
| const leftCopyLen = min(bufferLen - cpos, uint8Array.length); | ||
| const rightCopyLen = uint8Array.length - leftCopyLen; | ||
| encoder.cbuf.set(uint8Array.subarray(0, leftCopyLen), cpos); | ||
| encoder.cpos += leftCopyLen; | ||
| if (rightCopyLen > 0) { | ||
| encoder.bufs.push(encoder.cbuf); | ||
| encoder.cbuf = new Uint8Array(max(bufferLen * 2, rightCopyLen)); | ||
| encoder.cbuf.set(uint8Array.subarray(leftCopyLen)); | ||
| encoder.cpos = rightCopyLen; | ||
| } | ||
| }; | ||
| /** | ||
| * Append an Uint8Array to Encoder. | ||
| * | ||
| * @function | ||
| * @param {Encoder} encoder | ||
| * @param {Uint8Array} uint8Array | ||
| */ | ||
| * Append an Uint8Array to Encoder. | ||
| * | ||
| * @function | ||
| * @param {Encoder} encoder | ||
| * @param {Uint8Array} uint8Array | ||
| */ | ||
| const writeVarUint8Array = (encoder, uint8Array) => { | ||
| writeVarUint(encoder, uint8Array.byteLength); | ||
| writeUint8Array(encoder, uint8Array); | ||
| writeVarUint(encoder, uint8Array.byteLength); | ||
| writeUint8Array(encoder, uint8Array); | ||
| }; | ||
| //#endregion | ||
| //#region node_modules/lib0/error.js | ||
| /** | ||
| * Error helpers. | ||
| * | ||
| * @module error | ||
| */ | ||
| * Error helpers. | ||
| * | ||
| * @module error | ||
| */ | ||
| /** | ||
| * @param {string} s | ||
| * @return {Error} | ||
| */ | ||
| * @param {string} s | ||
| * @return {Error} | ||
| */ | ||
| /* c8 ignore next */ | ||
| const create = s => new Error(s); | ||
| const create = (s) => new Error(s); | ||
| //#endregion | ||
| //#region node_modules/lib0/decoding.js | ||
| /** | ||
| * Efficient schema-less binary decoding with support for variable length encoding. | ||
| * | ||
| * Use [lib0/decoding] with [lib0/encoding]. Every encoding function has a corresponding decoding function. | ||
| * | ||
| * Encodes numbers in little-endian order (least to most significant byte order) | ||
| * and is compatible with Golang's binary encoding (https://golang.org/pkg/encoding/binary/) | ||
| * which is also used in Protocol Buffers. | ||
| * | ||
| * ```js | ||
| * // encoding step | ||
| * const encoder = encoding.createEncoder() | ||
| * encoding.writeVarUint(encoder, 256) | ||
| * encoding.writeVarString(encoder, 'Hello world!') | ||
| * const buf = encoding.toUint8Array(encoder) | ||
| * ``` | ||
| * | ||
| * ```js | ||
| * // decoding step | ||
| * const decoder = decoding.createDecoder(buf) | ||
| * decoding.readVarUint(decoder) // => 256 | ||
| * decoding.readVarString(decoder) // => 'Hello world!' | ||
| * decoding.hasContent(decoder) // => false - all data is read | ||
| * ``` | ||
| * | ||
| * @module decoding | ||
| */ | ||
| const errorUnexpectedEndOfArray = create('Unexpected end of array'); | ||
| const errorIntegerOutOfRange = create('Integer out of Range'); | ||
| * Efficient schema-less binary decoding with support for variable length encoding. | ||
| * | ||
| * Use [lib0/decoding] with [lib0/encoding]. Every encoding function has a corresponding decoding function. | ||
| * | ||
| * Encodes numbers in little-endian order (least to most significant byte order) | ||
| * and is compatible with Golang's binary encoding (https://golang.org/pkg/encoding/binary/) | ||
| * which is also used in Protocol Buffers. | ||
| * | ||
| * ```js | ||
| * // encoding step | ||
| * const encoder = encoding.createEncoder() | ||
| * encoding.writeVarUint(encoder, 256) | ||
| * encoding.writeVarString(encoder, 'Hello world!') | ||
| * const buf = encoding.toUint8Array(encoder) | ||
| * ``` | ||
| * | ||
| * ```js | ||
| * // decoding step | ||
| * const decoder = decoding.createDecoder(buf) | ||
| * decoding.readVarUint(decoder) // => 256 | ||
| * decoding.readVarString(decoder) // => 'Hello world!' | ||
| * decoding.hasContent(decoder) // => false - all data is read | ||
| * ``` | ||
| * | ||
| * @module decoding | ||
| */ | ||
| const errorUnexpectedEndOfArray = create("Unexpected end of array"); | ||
| const errorIntegerOutOfRange = create("Integer out of Range"); | ||
| /** | ||
| * Create an Uint8Array view of the next `len` bytes and advance the position by `len`. | ||
| * | ||
| * Important: The Uint8Array still points to the underlying ArrayBuffer. Make sure to discard the result as soon as possible to prevent any memory leaks. | ||
| * Use `buffer.copyUint8Array` to copy the result into a new Uint8Array. | ||
| * | ||
| * @function | ||
| * @param {Decoder} decoder The decoder instance | ||
| * @param {number} len The length of bytes to read | ||
| * @return {Uint8Array} | ||
| */ | ||
| * Create an Uint8Array view of the next `len` bytes and advance the position by `len`. | ||
| * | ||
| * Important: The Uint8Array still points to the underlying ArrayBuffer. Make sure to discard the result as soon as possible to prevent any memory leaks. | ||
| * Use `buffer.copyUint8Array` to copy the result into a new Uint8Array. | ||
| * | ||
| * @function | ||
| * @param {Decoder} decoder The decoder instance | ||
| * @param {number} len The length of bytes to read | ||
| * @return {Uint8Array} | ||
| */ | ||
| const readUint8Array = (decoder, len) => { | ||
| const view = new Uint8Array(decoder.arr.buffer, decoder.pos + decoder.arr.byteOffset, len); | ||
| decoder.pos += len; | ||
| return view | ||
| const view = new Uint8Array(decoder.arr.buffer, decoder.pos + decoder.arr.byteOffset, len); | ||
| decoder.pos += len; | ||
| return view; | ||
| }; | ||
| /** | ||
| * Read variable length Uint8Array. | ||
| * | ||
| * Important: The Uint8Array still points to the underlying ArrayBuffer. Make sure to discard the result as soon as possible to prevent any memory leaks. | ||
| * Use `buffer.copyUint8Array` to copy the result into a new Uint8Array. | ||
| * | ||
| * @function | ||
| * @param {Decoder} decoder | ||
| * @return {Uint8Array} | ||
| */ | ||
| const readVarUint8Array = decoder => readUint8Array(decoder, readVarUint(decoder)); | ||
| * Read variable length Uint8Array. | ||
| * | ||
| * Important: The Uint8Array still points to the underlying ArrayBuffer. Make sure to discard the result as soon as possible to prevent any memory leaks. | ||
| * Use `buffer.copyUint8Array` to copy the result into a new Uint8Array. | ||
| * | ||
| * @function | ||
| * @param {Decoder} decoder | ||
| * @return {Uint8Array} | ||
| */ | ||
| const readVarUint8Array = (decoder) => readUint8Array(decoder, readVarUint(decoder)); | ||
| /** | ||
| * Read one byte as unsigned integer. | ||
| * @function | ||
| * @param {Decoder} decoder The decoder instance | ||
| * @return {number} Unsigned 8-bit integer | ||
| */ | ||
| const readUint8 = decoder => decoder.arr[decoder.pos++]; | ||
| * Read one byte as unsigned integer. | ||
| * @function | ||
| * @param {Decoder} decoder The decoder instance | ||
| * @return {number} Unsigned 8-bit integer | ||
| */ | ||
| const readUint8 = (decoder) => decoder.arr[decoder.pos++]; | ||
| /** | ||
| * Read unsigned integer (32bit) with variable length. | ||
| * 1/8th of the storage is used as encoding overhead. | ||
| * * numbers < 2^7 is stored in one bytlength | ||
| * * numbers < 2^14 is stored in two bylength | ||
| * | ||
| * @function | ||
| * @param {Decoder} decoder | ||
| * @return {number} An unsigned integer.length | ||
| */ | ||
| const readVarUint = decoder => { | ||
| let num = 0; | ||
| let mult = 1; | ||
| const len = decoder.arr.length; | ||
| while (decoder.pos < len) { | ||
| const r = decoder.arr[decoder.pos++]; | ||
| // num = num | ((r & binary.BITS7) << len) | ||
| num = num + (r & BITS7) * mult; // shift $r << (7*#iterations) and add it to num | ||
| mult *= 128; // next iteration, shift 7 "more" to the left | ||
| if (r < BIT8) { | ||
| return num | ||
| } | ||
| /* c8 ignore start */ | ||
| if (num > MAX_SAFE_INTEGER) { | ||
| throw errorIntegerOutOfRange | ||
| } | ||
| /* c8 ignore stop */ | ||
| } | ||
| throw errorUnexpectedEndOfArray | ||
| * Read unsigned integer (32bit) with variable length. | ||
| * 1/8th of the storage is used as encoding overhead. | ||
| * * numbers < 2^7 is stored in one bytlength | ||
| * * numbers < 2^14 is stored in two bylength | ||
| * | ||
| * @function | ||
| * @param {Decoder} decoder | ||
| * @return {number} An unsigned integer.length | ||
| */ | ||
| const readVarUint = (decoder) => { | ||
| let num = 0; | ||
| let mult = 1; | ||
| const len = decoder.arr.length; | ||
| while (decoder.pos < len) { | ||
| const r = decoder.arr[decoder.pos++]; | ||
| num = num + (r & BITS7) * mult; | ||
| mult *= 128; | ||
| if (r < BIT8) return num; | ||
| /* c8 ignore start */ | ||
| if (num > MAX_SAFE_INTEGER) throw errorIntegerOutOfRange; | ||
| } | ||
| throw errorUnexpectedEndOfArray; | ||
| }; | ||
| /** | ||
| * We don't test this function anymore as we use native decoding/encoding by default now. | ||
| * Better not modify this anymore.. | ||
| * | ||
| * Transforming utf8 to a string is pretty expensive. The code performs 10x better | ||
| * when String.fromCodePoint is fed with all characters as arguments. | ||
| * But most environments have a maximum number of arguments per functions. | ||
| * For effiency reasons we apply a maximum of 10000 characters at once. | ||
| * | ||
| * @function | ||
| * @param {Decoder} decoder | ||
| * @return {String} The read String. | ||
| */ | ||
| * We don't test this function anymore as we use native decoding/encoding by default now. | ||
| * Better not modify this anymore.. | ||
| * | ||
| * Transforming utf8 to a string is pretty expensive. The code performs 10x better | ||
| * when String.fromCodePoint is fed with all characters as arguments. | ||
| * But most environments have a maximum number of arguments per functions. | ||
| * For effiency reasons we apply a maximum of 10000 characters at once. | ||
| * | ||
| * @function | ||
| * @param {Decoder} decoder | ||
| * @return {String} The read String. | ||
| */ | ||
| /* c8 ignore start */ | ||
| const _readVarStringPolyfill = decoder => { | ||
| let remainingLen = readVarUint(decoder); | ||
| if (remainingLen === 0) { | ||
| return '' | ||
| } else { | ||
| let encodedString = String.fromCodePoint(readUint8(decoder)); // remember to decrease remainingLen | ||
| if (--remainingLen < 100) { // do not create a Uint8Array for small strings | ||
| while (remainingLen--) { | ||
| encodedString += String.fromCodePoint(readUint8(decoder)); | ||
| } | ||
| } else { | ||
| while (remainingLen > 0) { | ||
| const nextLen = remainingLen < 10000 ? remainingLen : 10000; | ||
| // this is dangerous, we create a fresh array view from the existing buffer | ||
| const bytes = decoder.arr.subarray(decoder.pos, decoder.pos + nextLen); | ||
| decoder.pos += nextLen; | ||
| // Starting with ES5.1 we can supply a generic array-like object as arguments | ||
| encodedString += String.fromCodePoint.apply(null, /** @type {any} */ (bytes)); | ||
| remainingLen -= nextLen; | ||
| } | ||
| } | ||
| return decodeURIComponent(escape(encodedString)) | ||
| } | ||
| const _readVarStringPolyfill = (decoder) => { | ||
| let remainingLen = readVarUint(decoder); | ||
| if (remainingLen === 0) return ""; | ||
| else { | ||
| let encodedString = String.fromCodePoint(readUint8(decoder)); | ||
| if (--remainingLen < 100) while (remainingLen--) encodedString += String.fromCodePoint(readUint8(decoder)); | ||
| else while (remainingLen > 0) { | ||
| const nextLen = remainingLen < 1e4 ? remainingLen : 1e4; | ||
| const bytes = decoder.arr.subarray(decoder.pos, decoder.pos + nextLen); | ||
| decoder.pos += nextLen; | ||
| encodedString += String.fromCodePoint.apply(null, bytes); | ||
| remainingLen -= nextLen; | ||
| } | ||
| return decodeURIComponent(escape(encodedString)); | ||
| } | ||
| }; | ||
| /* c8 ignore stop */ | ||
| /** | ||
| * @function | ||
| * @param {Decoder} decoder | ||
| * @return {String} The read String | ||
| */ | ||
| const _readVarStringNative = decoder => | ||
| /** @type any */ (utf8TextDecoder).decode(readVarUint8Array(decoder)); | ||
| * @function | ||
| * @param {Decoder} decoder | ||
| * @return {String} The read String | ||
| */ | ||
| const _readVarStringNative = (decoder) => utf8TextDecoder.decode(readVarUint8Array(decoder)); | ||
| /** | ||
| * Read string of variable length | ||
| * * varUint is used to store the length of the string | ||
| * | ||
| * @function | ||
| * @param {Decoder} decoder | ||
| * @return {String} The read String | ||
| * | ||
| */ | ||
| * Read string of variable length | ||
| * * varUint is used to store the length of the string | ||
| * | ||
| * @function | ||
| * @param {Decoder} decoder | ||
| * @return {String} The read String | ||
| * | ||
| */ | ||
| /* c8 ignore next */ | ||
| const readVarString = utf8TextDecoder ? _readVarStringNative : _readVarStringPolyfill; | ||
| exports.AuthMessageType = void 0; | ||
| (function (AuthMessageType) { | ||
| AuthMessageType[AuthMessageType["Token"] = 0] = "Token"; | ||
| AuthMessageType[AuthMessageType["PermissionDenied"] = 1] = "PermissionDenied"; | ||
| AuthMessageType[AuthMessageType["Authenticated"] = 2] = "Authenticated"; | ||
| })(exports.AuthMessageType || (exports.AuthMessageType = {})); | ||
| //#endregion | ||
| //#region packages/common/src/auth.ts | ||
| let AuthMessageType = /* @__PURE__ */ function(AuthMessageType) { | ||
| AuthMessageType[AuthMessageType["Token"] = 0] = "Token"; | ||
| AuthMessageType[AuthMessageType["PermissionDenied"] = 1] = "PermissionDenied"; | ||
| AuthMessageType[AuthMessageType["Authenticated"] = 2] = "Authenticated"; | ||
| return AuthMessageType; | ||
| }({}); | ||
| const writeAuthentication = (encoder, auth) => { | ||
| writeVarUint(encoder, exports.AuthMessageType.Token); | ||
| writeVarString(encoder, auth); | ||
| writeVarUint(encoder, AuthMessageType.Token); | ||
| writeVarString(encoder, auth); | ||
| }; | ||
| const writePermissionDenied = (encoder, reason) => { | ||
| writeVarUint(encoder, exports.AuthMessageType.PermissionDenied); | ||
| writeVarString(encoder, reason); | ||
| writeVarUint(encoder, AuthMessageType.PermissionDenied); | ||
| writeVarString(encoder, reason); | ||
| }; | ||
| const writeAuthenticated = (encoder, scope) => { | ||
| writeVarUint(encoder, exports.AuthMessageType.Authenticated); | ||
| writeVarString(encoder, scope); | ||
| writeVarUint(encoder, AuthMessageType.Authenticated); | ||
| writeVarString(encoder, scope); | ||
| }; | ||
| const writeTokenSyncRequest = (encoder) => { | ||
| writeVarUint(encoder, exports.AuthMessageType.Token); | ||
| writeVarUint(encoder, AuthMessageType.Token); | ||
| }; | ||
| const readAuthMessage = (decoder, sendToken, permissionDeniedHandler, authenticatedHandler) => { | ||
| switch (readVarUint(decoder)) { | ||
| case exports.AuthMessageType.Token: { | ||
| sendToken(); | ||
| break; | ||
| } | ||
| case exports.AuthMessageType.PermissionDenied: { | ||
| permissionDeniedHandler(readVarString(decoder)); | ||
| break; | ||
| } | ||
| case exports.AuthMessageType.Authenticated: { | ||
| authenticatedHandler(readVarString(decoder)); | ||
| break; | ||
| } | ||
| } | ||
| switch (readVarUint(decoder)) { | ||
| case AuthMessageType.Token: | ||
| sendToken(); | ||
| break; | ||
| case AuthMessageType.PermissionDenied: | ||
| permissionDeniedHandler(readVarString(decoder)); | ||
| break; | ||
| case AuthMessageType.Authenticated: | ||
| authenticatedHandler(readVarString(decoder)); | ||
| break; | ||
| default: | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region packages/common/src/CloseEvents.ts | ||
| /** | ||
| * The server is terminating the connection because a data frame was received | ||
| * that is too large. | ||
| * See: https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code | ||
| */ | ||
| * The server is terminating the connection because a data frame was received | ||
| * that is too large. | ||
| * See: https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code | ||
| */ | ||
| const MessageTooBig = { | ||
| code: 1009, | ||
| reason: "Message Too Big", | ||
| code: 1009, | ||
| reason: "Message Too Big" | ||
| }; | ||
| /** | ||
| * The server successfully processed the request, asks that the requester reset | ||
| * its document view, and is not returning any content. | ||
| */ | ||
| * The server successfully processed the request, asks that the requester reset | ||
| * its document view, and is not returning any content. | ||
| */ | ||
| const ResetConnection = { | ||
| code: 4205, | ||
| reason: "Reset Connection", | ||
| code: 4205, | ||
| reason: "Reset Connection" | ||
| }; | ||
| /** | ||
| * Similar to Forbidden, but specifically for use when authentication is required and has | ||
| * failed or has not yet been provided. | ||
| */ | ||
| * Similar to Forbidden, but specifically for use when authentication is required and has | ||
| * failed or has not yet been provided. | ||
| */ | ||
| const Unauthorized = { | ||
| code: 4401, | ||
| reason: "Unauthorized", | ||
| code: 4401, | ||
| reason: "Unauthorized" | ||
| }; | ||
| /** | ||
| * The request contained valid data and was understood by the server, but the server | ||
| * is refusing action. | ||
| */ | ||
| * The request contained valid data and was understood by the server, but the server | ||
| * is refusing action. | ||
| */ | ||
| const Forbidden = { | ||
| code: 4403, | ||
| reason: "Forbidden", | ||
| code: 4403, | ||
| reason: "Forbidden" | ||
| }; | ||
| /** | ||
| * The server timed out waiting for the request. | ||
| */ | ||
| * The server timed out waiting for the request. | ||
| */ | ||
| const ConnectionTimeout = { | ||
| code: 4408, | ||
| reason: "Connection Timeout", | ||
| code: 4408, | ||
| reason: "Connection Timeout" | ||
| }; | ||
| //#endregion | ||
| //#region packages/common/src/awarenessStatesToArray.ts | ||
| const awarenessStatesToArray = (states) => { | ||
| return Array.from(states.entries()).map(([key, value]) => { | ||
| return { | ||
| clientId: key, | ||
| ...value, | ||
| }; | ||
| }); | ||
| return Array.from(states.entries()).map(([key, value]) => { | ||
| return { | ||
| clientId: key, | ||
| ...value | ||
| }; | ||
| }); | ||
| }; | ||
| //#endregion | ||
| //#region packages/common/src/types.ts | ||
| /** | ||
| * State of the WebSocket connection. | ||
| * https://developer.mozilla.org/de/docs/Web/API/WebSocket/readyState | ||
| */ | ||
| exports.WsReadyStates = void 0; | ||
| (function (WsReadyStates) { | ||
| WsReadyStates[WsReadyStates["Connecting"] = 0] = "Connecting"; | ||
| WsReadyStates[WsReadyStates["Open"] = 1] = "Open"; | ||
| WsReadyStates[WsReadyStates["Closing"] = 2] = "Closing"; | ||
| WsReadyStates[WsReadyStates["Closed"] = 3] = "Closed"; | ||
| })(exports.WsReadyStates || (exports.WsReadyStates = {})); | ||
| * State of the WebSocket connection. | ||
| * https://developer.mozilla.org/de/docs/Web/API/WebSocket/readyState | ||
| */ | ||
| let WsReadyStates = /* @__PURE__ */ function(WsReadyStates) { | ||
| WsReadyStates[WsReadyStates["Connecting"] = 0] = "Connecting"; | ||
| WsReadyStates[WsReadyStates["Open"] = 1] = "Open"; | ||
| WsReadyStates[WsReadyStates["Closing"] = 2] = "Closing"; | ||
| WsReadyStates[WsReadyStates["Closed"] = 3] = "Closed"; | ||
| return WsReadyStates; | ||
| }({}); | ||
| //#endregion | ||
| exports.AuthMessageType = AuthMessageType; | ||
| exports.ConnectionTimeout = ConnectionTimeout; | ||
@@ -515,2 +532,3 @@ exports.Forbidden = Forbidden; | ||
| exports.Unauthorized = Unauthorized; | ||
| exports.WsReadyStates = WsReadyStates; | ||
| exports.awarenessStatesToArray = awarenessStatesToArray; | ||
@@ -522,2 +540,2 @@ exports.readAuthMessage = readAuthMessage; | ||
| exports.writeTokenSyncRequest = writeTokenSyncRequest; | ||
| //# sourceMappingURL=hocuspocus-common.cjs.map | ||
| //# sourceMappingURL=hocuspocus-common.cjs.map |
+424
-408
@@ -0,509 +1,525 @@ | ||
| //#region node_modules/lib0/math.js | ||
| /** | ||
| * Common Math expressions. | ||
| * | ||
| * @module math | ||
| */ | ||
| * Common Math expressions. | ||
| * | ||
| * @module math | ||
| */ | ||
| const floor = Math.floor; | ||
| /** | ||
| * @function | ||
| * @param {number} a | ||
| * @param {number} b | ||
| * @return {number} The smaller element of a and b | ||
| */ | ||
| * @function | ||
| * @param {number} a | ||
| * @param {number} b | ||
| * @return {number} The smaller element of a and b | ||
| */ | ||
| const min = (a, b) => a < b ? a : b; | ||
| /** | ||
| * @function | ||
| * @param {number} a | ||
| * @param {number} b | ||
| * @return {number} The bigger element of a and b | ||
| */ | ||
| * @function | ||
| * @param {number} a | ||
| * @param {number} b | ||
| * @return {number} The bigger element of a and b | ||
| */ | ||
| const max = (a, b) => a > b ? a : b; | ||
| const isNaN$1 = Number.isNaN; | ||
| /* eslint-env browser */ | ||
| //#endregion | ||
| //#region node_modules/lib0/binary.js | ||
| const BIT8 = 128; | ||
| const BIT18 = 1 << 17; | ||
| const BIT19 = 1 << 18; | ||
| const BIT20 = 1 << 19; | ||
| const BIT21 = 1 << 20; | ||
| const BIT22 = 1 << 21; | ||
| const BIT23 = 1 << 22; | ||
| const BIT24 = 1 << 23; | ||
| const BIT25 = 1 << 24; | ||
| const BIT26 = 1 << 25; | ||
| const BIT27 = 1 << 26; | ||
| const BIT28 = 1 << 27; | ||
| const BIT29 = 1 << 28; | ||
| const BIT30 = 1 << 29; | ||
| const BIT31 = 1 << 30; | ||
| const BIT32 = 1 << 31; | ||
| const BITS7 = 127; | ||
| const BITS17 = BIT18 - 1; | ||
| const BITS18 = BIT19 - 1; | ||
| const BITS19 = BIT20 - 1; | ||
| const BITS20 = BIT21 - 1; | ||
| const BITS21 = BIT22 - 1; | ||
| const BITS22 = BIT23 - 1; | ||
| const BITS23 = BIT24 - 1; | ||
| const BITS24 = BIT25 - 1; | ||
| const BITS25 = BIT26 - 1; | ||
| const BITS26 = BIT27 - 1; | ||
| const BITS27 = BIT28 - 1; | ||
| const BITS28 = BIT29 - 1; | ||
| const BITS29 = BIT30 - 1; | ||
| const BITS30 = BIT31 - 1; | ||
| /** | ||
| * @type {number} | ||
| */ | ||
| const BITS31 = 2147483647; | ||
| /** | ||
| * @type {number} | ||
| */ | ||
| const BITS32 = 4294967295; | ||
| //#endregion | ||
| //#region node_modules/lib0/number.js | ||
| /** | ||
| * Utility helpers for working with numbers. | ||
| * | ||
| * @module number | ||
| */ | ||
| * Utility helpers for working with numbers. | ||
| * | ||
| * @module number | ||
| */ | ||
| const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER; | ||
| const MIN_SAFE_INTEGER = Number.MIN_SAFE_INTEGER; | ||
| const LOWEST_INT32 = 1 << 31; | ||
| const HIGHEST_INT32 = BITS31; | ||
| const HIGHEST_UINT32 = BITS32; | ||
| /* c8 ignore next */ | ||
| const isInteger = Number.isInteger || ((num) => typeof num === "number" && isFinite(num) && floor(num) === num); | ||
| const isNaN = Number.isNaN; | ||
| const parseInt = Number.parseInt; | ||
| //#endregion | ||
| //#region node_modules/lib0/string.js | ||
| /** | ||
| * @param {string} str | ||
| * @return {Uint8Array} | ||
| */ | ||
| const _encodeUtf8Polyfill = str => { | ||
| const encodedString = unescape(encodeURIComponent(str)); | ||
| const len = encodedString.length; | ||
| const buf = new Uint8Array(len); | ||
| for (let i = 0; i < len; i++) { | ||
| buf[i] = /** @type {number} */ (encodedString.codePointAt(i)); | ||
| } | ||
| return buf | ||
| * Utility module to work with strings. | ||
| * | ||
| * @module string | ||
| */ | ||
| const fromCharCode = String.fromCharCode; | ||
| const fromCodePoint = String.fromCodePoint; | ||
| /** | ||
| * The largest utf16 character. | ||
| * Corresponds to Uint8Array([255, 255]) or charcodeof(2x2^8) | ||
| */ | ||
| const MAX_UTF16_CHARACTER = fromCharCode(65535); | ||
| /** | ||
| * @param {string} str | ||
| * @return {Uint8Array} | ||
| */ | ||
| const _encodeUtf8Polyfill = (str) => { | ||
| const encodedString = unescape(encodeURIComponent(str)); | ||
| const len = encodedString.length; | ||
| const buf = new Uint8Array(len); | ||
| for (let i = 0; i < len; i++) buf[i] = encodedString.codePointAt(i); | ||
| return buf; | ||
| }; | ||
| /* c8 ignore next */ | ||
| const utf8TextEncoder = /** @type {TextEncoder} */ (typeof TextEncoder !== 'undefined' ? new TextEncoder() : null); | ||
| const utf8TextEncoder = typeof TextEncoder !== "undefined" ? new TextEncoder() : null; | ||
| /** | ||
| * @param {string} str | ||
| * @return {Uint8Array} | ||
| */ | ||
| const _encodeUtf8Native = str => utf8TextEncoder.encode(str); | ||
| * @param {string} str | ||
| * @return {Uint8Array} | ||
| */ | ||
| const _encodeUtf8Native = (str) => utf8TextEncoder.encode(str); | ||
| /** | ||
| * @param {string} str | ||
| * @return {Uint8Array} | ||
| */ | ||
| * @param {string} str | ||
| * @return {Uint8Array} | ||
| */ | ||
| /* c8 ignore next */ | ||
| const encodeUtf8 = utf8TextEncoder ? _encodeUtf8Native : _encodeUtf8Polyfill; | ||
| /* c8 ignore next */ | ||
| let utf8TextDecoder = typeof TextDecoder === 'undefined' ? null : new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }); | ||
| let utf8TextDecoder = typeof TextDecoder === "undefined" ? null : new TextDecoder("utf-8", { | ||
| fatal: true, | ||
| ignoreBOM: true | ||
| }); | ||
| /* c8 ignore start */ | ||
| if (utf8TextDecoder && utf8TextDecoder.decode(new Uint8Array()).length === 1) { | ||
| // Safari doesn't handle BOM correctly. | ||
| // This fixes a bug in Safari 13.0.5 where it produces a BOM the first time it is called. | ||
| // utf8TextDecoder.decode(new Uint8Array()).length === 1 on the first call and | ||
| // utf8TextDecoder.decode(new Uint8Array()).length === 1 on the second call | ||
| // Another issue is that from then on no BOM chars are recognized anymore | ||
| /* c8 ignore next */ | ||
| utf8TextDecoder = null; | ||
| } | ||
| if (utf8TextDecoder && utf8TextDecoder.decode(new Uint8Array()).length === 1) | ||
| /* c8 ignore next */ | ||
| utf8TextDecoder = null; | ||
| //#endregion | ||
| //#region node_modules/lib0/encoding.js | ||
| /** | ||
| * Efficient schema-less binary encoding with support for variable length encoding. | ||
| * | ||
| * Use [lib0/encoding] with [lib0/decoding]. Every encoding function has a corresponding decoding function. | ||
| * | ||
| * Encodes numbers in little-endian order (least to most significant byte order) | ||
| * and is compatible with Golang's binary encoding (https://golang.org/pkg/encoding/binary/) | ||
| * which is also used in Protocol Buffers. | ||
| * | ||
| * ```js | ||
| * // encoding step | ||
| * const encoder = encoding.createEncoder() | ||
| * encoding.writeVarUint(encoder, 256) | ||
| * encoding.writeVarString(encoder, 'Hello world!') | ||
| * const buf = encoding.toUint8Array(encoder) | ||
| * ``` | ||
| * | ||
| * ```js | ||
| * // decoding step | ||
| * const decoder = decoding.createDecoder(buf) | ||
| * decoding.readVarUint(decoder) // => 256 | ||
| * decoding.readVarString(decoder) // => 'Hello world!' | ||
| * decoding.hasContent(decoder) // => false - all data is read | ||
| * ``` | ||
| * | ||
| * @module encoding | ||
| */ | ||
| * Efficient schema-less binary encoding with support for variable length encoding. | ||
| * | ||
| * Use [lib0/encoding] with [lib0/decoding]. Every encoding function has a corresponding decoding function. | ||
| * | ||
| * Encodes numbers in little-endian order (least to most significant byte order) | ||
| * and is compatible with Golang's binary encoding (https://golang.org/pkg/encoding/binary/) | ||
| * which is also used in Protocol Buffers. | ||
| * | ||
| * ```js | ||
| * // encoding step | ||
| * const encoder = encoding.createEncoder() | ||
| * encoding.writeVarUint(encoder, 256) | ||
| * encoding.writeVarString(encoder, 'Hello world!') | ||
| * const buf = encoding.toUint8Array(encoder) | ||
| * ``` | ||
| * | ||
| * ```js | ||
| * // decoding step | ||
| * const decoder = decoding.createDecoder(buf) | ||
| * decoding.readVarUint(decoder) // => 256 | ||
| * decoding.readVarString(decoder) // => 'Hello world!' | ||
| * decoding.hasContent(decoder) // => false - all data is read | ||
| * ``` | ||
| * | ||
| * @module encoding | ||
| */ | ||
| /** | ||
| * Write one byte to the encoder. | ||
| * | ||
| * @function | ||
| * @param {Encoder} encoder | ||
| * @param {number} num The byte that is to be encoded. | ||
| */ | ||
| * Write one byte to the encoder. | ||
| * | ||
| * @function | ||
| * @param {Encoder} encoder | ||
| * @param {number} num The byte that is to be encoded. | ||
| */ | ||
| const write = (encoder, num) => { | ||
| const bufferLen = encoder.cbuf.length; | ||
| if (encoder.cpos === bufferLen) { | ||
| encoder.bufs.push(encoder.cbuf); | ||
| encoder.cbuf = new Uint8Array(bufferLen * 2); | ||
| encoder.cpos = 0; | ||
| } | ||
| encoder.cbuf[encoder.cpos++] = num; | ||
| const bufferLen = encoder.cbuf.length; | ||
| if (encoder.cpos === bufferLen) { | ||
| encoder.bufs.push(encoder.cbuf); | ||
| encoder.cbuf = new Uint8Array(bufferLen * 2); | ||
| encoder.cpos = 0; | ||
| } | ||
| encoder.cbuf[encoder.cpos++] = num; | ||
| }; | ||
| /** | ||
| * Write a variable length unsigned integer. Max encodable integer is 2^53. | ||
| * | ||
| * @function | ||
| * @param {Encoder} encoder | ||
| * @param {number} num The number that is to be encoded. | ||
| */ | ||
| * Write a variable length unsigned integer. Max encodable integer is 2^53. | ||
| * | ||
| * @function | ||
| * @param {Encoder} encoder | ||
| * @param {number} num The number that is to be encoded. | ||
| */ | ||
| const writeVarUint = (encoder, num) => { | ||
| while (num > BITS7) { | ||
| write(encoder, BIT8 | (BITS7 & num)); | ||
| num = floor(num / 128); // shift >>> 7 | ||
| } | ||
| write(encoder, BITS7 & num); | ||
| while (num > BITS7) { | ||
| write(encoder, BIT8 | BITS7 & num); | ||
| num = floor(num / 128); | ||
| } | ||
| write(encoder, BITS7 & num); | ||
| }; | ||
| /** | ||
| * A cache to store strings temporarily | ||
| */ | ||
| const _strBuffer = new Uint8Array(30000); | ||
| * A cache to store strings temporarily | ||
| */ | ||
| const _strBuffer = new Uint8Array(3e4); | ||
| const _maxStrBSize = _strBuffer.length / 3; | ||
| /** | ||
| * Write a variable length string. | ||
| * | ||
| * @function | ||
| * @param {Encoder} encoder | ||
| * @param {String} str The string that is to be encoded. | ||
| */ | ||
| * Write a variable length string. | ||
| * | ||
| * @function | ||
| * @param {Encoder} encoder | ||
| * @param {String} str The string that is to be encoded. | ||
| */ | ||
| const _writeVarStringNative = (encoder, str) => { | ||
| if (str.length < _maxStrBSize) { | ||
| // We can encode the string into the existing buffer | ||
| /* c8 ignore next */ | ||
| const written = utf8TextEncoder.encodeInto(str, _strBuffer).written || 0; | ||
| writeVarUint(encoder, written); | ||
| for (let i = 0; i < written; i++) { | ||
| write(encoder, _strBuffer[i]); | ||
| } | ||
| } else { | ||
| writeVarUint8Array(encoder, encodeUtf8(str)); | ||
| } | ||
| if (str.length < _maxStrBSize) { | ||
| /* c8 ignore next */ | ||
| const written = utf8TextEncoder.encodeInto(str, _strBuffer).written || 0; | ||
| writeVarUint(encoder, written); | ||
| for (let i = 0; i < written; i++) write(encoder, _strBuffer[i]); | ||
| } else writeVarUint8Array(encoder, encodeUtf8(str)); | ||
| }; | ||
| /** | ||
| * Write a variable length string. | ||
| * | ||
| * @function | ||
| * @param {Encoder} encoder | ||
| * @param {String} str The string that is to be encoded. | ||
| */ | ||
| * Write a variable length string. | ||
| * | ||
| * @function | ||
| * @param {Encoder} encoder | ||
| * @param {String} str The string that is to be encoded. | ||
| */ | ||
| const _writeVarStringPolyfill = (encoder, str) => { | ||
| const encodedString = unescape(encodeURIComponent(str)); | ||
| const len = encodedString.length; | ||
| writeVarUint(encoder, len); | ||
| for (let i = 0; i < len; i++) { | ||
| write(encoder, /** @type {number} */ (encodedString.codePointAt(i))); | ||
| } | ||
| const encodedString = unescape(encodeURIComponent(str)); | ||
| const len = encodedString.length; | ||
| writeVarUint(encoder, len); | ||
| for (let i = 0; i < len; i++) write(encoder, encodedString.codePointAt(i)); | ||
| }; | ||
| /** | ||
| * Write a variable length string. | ||
| * | ||
| * @function | ||
| * @param {Encoder} encoder | ||
| * @param {String} str The string that is to be encoded. | ||
| */ | ||
| * Write a variable length string. | ||
| * | ||
| * @function | ||
| * @param {Encoder} encoder | ||
| * @param {String} str The string that is to be encoded. | ||
| */ | ||
| /* c8 ignore next */ | ||
| const writeVarString = (utf8TextEncoder && /** @type {any} */ (utf8TextEncoder).encodeInto) ? _writeVarStringNative : _writeVarStringPolyfill; | ||
| const writeVarString = utf8TextEncoder && utf8TextEncoder.encodeInto ? _writeVarStringNative : _writeVarStringPolyfill; | ||
| /** | ||
| * Append fixed-length Uint8Array to the encoder. | ||
| * | ||
| * @function | ||
| * @param {Encoder} encoder | ||
| * @param {Uint8Array} uint8Array | ||
| */ | ||
| * Append fixed-length Uint8Array to the encoder. | ||
| * | ||
| * @function | ||
| * @param {Encoder} encoder | ||
| * @param {Uint8Array} uint8Array | ||
| */ | ||
| const writeUint8Array = (encoder, uint8Array) => { | ||
| const bufferLen = encoder.cbuf.length; | ||
| const cpos = encoder.cpos; | ||
| const leftCopyLen = min(bufferLen - cpos, uint8Array.length); | ||
| const rightCopyLen = uint8Array.length - leftCopyLen; | ||
| encoder.cbuf.set(uint8Array.subarray(0, leftCopyLen), cpos); | ||
| encoder.cpos += leftCopyLen; | ||
| if (rightCopyLen > 0) { | ||
| // Still something to write, write right half.. | ||
| // Append new buffer | ||
| encoder.bufs.push(encoder.cbuf); | ||
| // must have at least size of remaining buffer | ||
| encoder.cbuf = new Uint8Array(max(bufferLen * 2, rightCopyLen)); | ||
| // copy array | ||
| encoder.cbuf.set(uint8Array.subarray(leftCopyLen)); | ||
| encoder.cpos = rightCopyLen; | ||
| } | ||
| const bufferLen = encoder.cbuf.length; | ||
| const cpos = encoder.cpos; | ||
| const leftCopyLen = min(bufferLen - cpos, uint8Array.length); | ||
| const rightCopyLen = uint8Array.length - leftCopyLen; | ||
| encoder.cbuf.set(uint8Array.subarray(0, leftCopyLen), cpos); | ||
| encoder.cpos += leftCopyLen; | ||
| if (rightCopyLen > 0) { | ||
| encoder.bufs.push(encoder.cbuf); | ||
| encoder.cbuf = new Uint8Array(max(bufferLen * 2, rightCopyLen)); | ||
| encoder.cbuf.set(uint8Array.subarray(leftCopyLen)); | ||
| encoder.cpos = rightCopyLen; | ||
| } | ||
| }; | ||
| /** | ||
| * Append an Uint8Array to Encoder. | ||
| * | ||
| * @function | ||
| * @param {Encoder} encoder | ||
| * @param {Uint8Array} uint8Array | ||
| */ | ||
| * Append an Uint8Array to Encoder. | ||
| * | ||
| * @function | ||
| * @param {Encoder} encoder | ||
| * @param {Uint8Array} uint8Array | ||
| */ | ||
| const writeVarUint8Array = (encoder, uint8Array) => { | ||
| writeVarUint(encoder, uint8Array.byteLength); | ||
| writeUint8Array(encoder, uint8Array); | ||
| writeVarUint(encoder, uint8Array.byteLength); | ||
| writeUint8Array(encoder, uint8Array); | ||
| }; | ||
| //#endregion | ||
| //#region node_modules/lib0/error.js | ||
| /** | ||
| * Error helpers. | ||
| * | ||
| * @module error | ||
| */ | ||
| * Error helpers. | ||
| * | ||
| * @module error | ||
| */ | ||
| /** | ||
| * @param {string} s | ||
| * @return {Error} | ||
| */ | ||
| * @param {string} s | ||
| * @return {Error} | ||
| */ | ||
| /* c8 ignore next */ | ||
| const create = s => new Error(s); | ||
| const create = (s) => new Error(s); | ||
| //#endregion | ||
| //#region node_modules/lib0/decoding.js | ||
| /** | ||
| * Efficient schema-less binary decoding with support for variable length encoding. | ||
| * | ||
| * Use [lib0/decoding] with [lib0/encoding]. Every encoding function has a corresponding decoding function. | ||
| * | ||
| * Encodes numbers in little-endian order (least to most significant byte order) | ||
| * and is compatible with Golang's binary encoding (https://golang.org/pkg/encoding/binary/) | ||
| * which is also used in Protocol Buffers. | ||
| * | ||
| * ```js | ||
| * // encoding step | ||
| * const encoder = encoding.createEncoder() | ||
| * encoding.writeVarUint(encoder, 256) | ||
| * encoding.writeVarString(encoder, 'Hello world!') | ||
| * const buf = encoding.toUint8Array(encoder) | ||
| * ``` | ||
| * | ||
| * ```js | ||
| * // decoding step | ||
| * const decoder = decoding.createDecoder(buf) | ||
| * decoding.readVarUint(decoder) // => 256 | ||
| * decoding.readVarString(decoder) // => 'Hello world!' | ||
| * decoding.hasContent(decoder) // => false - all data is read | ||
| * ``` | ||
| * | ||
| * @module decoding | ||
| */ | ||
| const errorUnexpectedEndOfArray = create('Unexpected end of array'); | ||
| const errorIntegerOutOfRange = create('Integer out of Range'); | ||
| * Efficient schema-less binary decoding with support for variable length encoding. | ||
| * | ||
| * Use [lib0/decoding] with [lib0/encoding]. Every encoding function has a corresponding decoding function. | ||
| * | ||
| * Encodes numbers in little-endian order (least to most significant byte order) | ||
| * and is compatible with Golang's binary encoding (https://golang.org/pkg/encoding/binary/) | ||
| * which is also used in Protocol Buffers. | ||
| * | ||
| * ```js | ||
| * // encoding step | ||
| * const encoder = encoding.createEncoder() | ||
| * encoding.writeVarUint(encoder, 256) | ||
| * encoding.writeVarString(encoder, 'Hello world!') | ||
| * const buf = encoding.toUint8Array(encoder) | ||
| * ``` | ||
| * | ||
| * ```js | ||
| * // decoding step | ||
| * const decoder = decoding.createDecoder(buf) | ||
| * decoding.readVarUint(decoder) // => 256 | ||
| * decoding.readVarString(decoder) // => 'Hello world!' | ||
| * decoding.hasContent(decoder) // => false - all data is read | ||
| * ``` | ||
| * | ||
| * @module decoding | ||
| */ | ||
| const errorUnexpectedEndOfArray = create("Unexpected end of array"); | ||
| const errorIntegerOutOfRange = create("Integer out of Range"); | ||
| /** | ||
| * Create an Uint8Array view of the next `len` bytes and advance the position by `len`. | ||
| * | ||
| * Important: The Uint8Array still points to the underlying ArrayBuffer. Make sure to discard the result as soon as possible to prevent any memory leaks. | ||
| * Use `buffer.copyUint8Array` to copy the result into a new Uint8Array. | ||
| * | ||
| * @function | ||
| * @param {Decoder} decoder The decoder instance | ||
| * @param {number} len The length of bytes to read | ||
| * @return {Uint8Array} | ||
| */ | ||
| * Create an Uint8Array view of the next `len` bytes and advance the position by `len`. | ||
| * | ||
| * Important: The Uint8Array still points to the underlying ArrayBuffer. Make sure to discard the result as soon as possible to prevent any memory leaks. | ||
| * Use `buffer.copyUint8Array` to copy the result into a new Uint8Array. | ||
| * | ||
| * @function | ||
| * @param {Decoder} decoder The decoder instance | ||
| * @param {number} len The length of bytes to read | ||
| * @return {Uint8Array} | ||
| */ | ||
| const readUint8Array = (decoder, len) => { | ||
| const view = new Uint8Array(decoder.arr.buffer, decoder.pos + decoder.arr.byteOffset, len); | ||
| decoder.pos += len; | ||
| return view | ||
| const view = new Uint8Array(decoder.arr.buffer, decoder.pos + decoder.arr.byteOffset, len); | ||
| decoder.pos += len; | ||
| return view; | ||
| }; | ||
| /** | ||
| * Read variable length Uint8Array. | ||
| * | ||
| * Important: The Uint8Array still points to the underlying ArrayBuffer. Make sure to discard the result as soon as possible to prevent any memory leaks. | ||
| * Use `buffer.copyUint8Array` to copy the result into a new Uint8Array. | ||
| * | ||
| * @function | ||
| * @param {Decoder} decoder | ||
| * @return {Uint8Array} | ||
| */ | ||
| const readVarUint8Array = decoder => readUint8Array(decoder, readVarUint(decoder)); | ||
| * Read variable length Uint8Array. | ||
| * | ||
| * Important: The Uint8Array still points to the underlying ArrayBuffer. Make sure to discard the result as soon as possible to prevent any memory leaks. | ||
| * Use `buffer.copyUint8Array` to copy the result into a new Uint8Array. | ||
| * | ||
| * @function | ||
| * @param {Decoder} decoder | ||
| * @return {Uint8Array} | ||
| */ | ||
| const readVarUint8Array = (decoder) => readUint8Array(decoder, readVarUint(decoder)); | ||
| /** | ||
| * Read one byte as unsigned integer. | ||
| * @function | ||
| * @param {Decoder} decoder The decoder instance | ||
| * @return {number} Unsigned 8-bit integer | ||
| */ | ||
| const readUint8 = decoder => decoder.arr[decoder.pos++]; | ||
| * Read one byte as unsigned integer. | ||
| * @function | ||
| * @param {Decoder} decoder The decoder instance | ||
| * @return {number} Unsigned 8-bit integer | ||
| */ | ||
| const readUint8 = (decoder) => decoder.arr[decoder.pos++]; | ||
| /** | ||
| * Read unsigned integer (32bit) with variable length. | ||
| * 1/8th of the storage is used as encoding overhead. | ||
| * * numbers < 2^7 is stored in one bytlength | ||
| * * numbers < 2^14 is stored in two bylength | ||
| * | ||
| * @function | ||
| * @param {Decoder} decoder | ||
| * @return {number} An unsigned integer.length | ||
| */ | ||
| const readVarUint = decoder => { | ||
| let num = 0; | ||
| let mult = 1; | ||
| const len = decoder.arr.length; | ||
| while (decoder.pos < len) { | ||
| const r = decoder.arr[decoder.pos++]; | ||
| // num = num | ((r & binary.BITS7) << len) | ||
| num = num + (r & BITS7) * mult; // shift $r << (7*#iterations) and add it to num | ||
| mult *= 128; // next iteration, shift 7 "more" to the left | ||
| if (r < BIT8) { | ||
| return num | ||
| } | ||
| /* c8 ignore start */ | ||
| if (num > MAX_SAFE_INTEGER) { | ||
| throw errorIntegerOutOfRange | ||
| } | ||
| /* c8 ignore stop */ | ||
| } | ||
| throw errorUnexpectedEndOfArray | ||
| * Read unsigned integer (32bit) with variable length. | ||
| * 1/8th of the storage is used as encoding overhead. | ||
| * * numbers < 2^7 is stored in one bytlength | ||
| * * numbers < 2^14 is stored in two bylength | ||
| * | ||
| * @function | ||
| * @param {Decoder} decoder | ||
| * @return {number} An unsigned integer.length | ||
| */ | ||
| const readVarUint = (decoder) => { | ||
| let num = 0; | ||
| let mult = 1; | ||
| const len = decoder.arr.length; | ||
| while (decoder.pos < len) { | ||
| const r = decoder.arr[decoder.pos++]; | ||
| num = num + (r & BITS7) * mult; | ||
| mult *= 128; | ||
| if (r < BIT8) return num; | ||
| /* c8 ignore start */ | ||
| if (num > MAX_SAFE_INTEGER) throw errorIntegerOutOfRange; | ||
| } | ||
| throw errorUnexpectedEndOfArray; | ||
| }; | ||
| /** | ||
| * We don't test this function anymore as we use native decoding/encoding by default now. | ||
| * Better not modify this anymore.. | ||
| * | ||
| * Transforming utf8 to a string is pretty expensive. The code performs 10x better | ||
| * when String.fromCodePoint is fed with all characters as arguments. | ||
| * But most environments have a maximum number of arguments per functions. | ||
| * For effiency reasons we apply a maximum of 10000 characters at once. | ||
| * | ||
| * @function | ||
| * @param {Decoder} decoder | ||
| * @return {String} The read String. | ||
| */ | ||
| * We don't test this function anymore as we use native decoding/encoding by default now. | ||
| * Better not modify this anymore.. | ||
| * | ||
| * Transforming utf8 to a string is pretty expensive. The code performs 10x better | ||
| * when String.fromCodePoint is fed with all characters as arguments. | ||
| * But most environments have a maximum number of arguments per functions. | ||
| * For effiency reasons we apply a maximum of 10000 characters at once. | ||
| * | ||
| * @function | ||
| * @param {Decoder} decoder | ||
| * @return {String} The read String. | ||
| */ | ||
| /* c8 ignore start */ | ||
| const _readVarStringPolyfill = decoder => { | ||
| let remainingLen = readVarUint(decoder); | ||
| if (remainingLen === 0) { | ||
| return '' | ||
| } else { | ||
| let encodedString = String.fromCodePoint(readUint8(decoder)); // remember to decrease remainingLen | ||
| if (--remainingLen < 100) { // do not create a Uint8Array for small strings | ||
| while (remainingLen--) { | ||
| encodedString += String.fromCodePoint(readUint8(decoder)); | ||
| } | ||
| } else { | ||
| while (remainingLen > 0) { | ||
| const nextLen = remainingLen < 10000 ? remainingLen : 10000; | ||
| // this is dangerous, we create a fresh array view from the existing buffer | ||
| const bytes = decoder.arr.subarray(decoder.pos, decoder.pos + nextLen); | ||
| decoder.pos += nextLen; | ||
| // Starting with ES5.1 we can supply a generic array-like object as arguments | ||
| encodedString += String.fromCodePoint.apply(null, /** @type {any} */ (bytes)); | ||
| remainingLen -= nextLen; | ||
| } | ||
| } | ||
| return decodeURIComponent(escape(encodedString)) | ||
| } | ||
| const _readVarStringPolyfill = (decoder) => { | ||
| let remainingLen = readVarUint(decoder); | ||
| if (remainingLen === 0) return ""; | ||
| else { | ||
| let encodedString = String.fromCodePoint(readUint8(decoder)); | ||
| if (--remainingLen < 100) while (remainingLen--) encodedString += String.fromCodePoint(readUint8(decoder)); | ||
| else while (remainingLen > 0) { | ||
| const nextLen = remainingLen < 1e4 ? remainingLen : 1e4; | ||
| const bytes = decoder.arr.subarray(decoder.pos, decoder.pos + nextLen); | ||
| decoder.pos += nextLen; | ||
| encodedString += String.fromCodePoint.apply(null, bytes); | ||
| remainingLen -= nextLen; | ||
| } | ||
| return decodeURIComponent(escape(encodedString)); | ||
| } | ||
| }; | ||
| /* c8 ignore stop */ | ||
| /** | ||
| * @function | ||
| * @param {Decoder} decoder | ||
| * @return {String} The read String | ||
| */ | ||
| const _readVarStringNative = decoder => | ||
| /** @type any */ (utf8TextDecoder).decode(readVarUint8Array(decoder)); | ||
| * @function | ||
| * @param {Decoder} decoder | ||
| * @return {String} The read String | ||
| */ | ||
| const _readVarStringNative = (decoder) => utf8TextDecoder.decode(readVarUint8Array(decoder)); | ||
| /** | ||
| * Read string of variable length | ||
| * * varUint is used to store the length of the string | ||
| * | ||
| * @function | ||
| * @param {Decoder} decoder | ||
| * @return {String} The read String | ||
| * | ||
| */ | ||
| * Read string of variable length | ||
| * * varUint is used to store the length of the string | ||
| * | ||
| * @function | ||
| * @param {Decoder} decoder | ||
| * @return {String} The read String | ||
| * | ||
| */ | ||
| /* c8 ignore next */ | ||
| const readVarString = utf8TextDecoder ? _readVarStringNative : _readVarStringPolyfill; | ||
| var AuthMessageType; | ||
| (function (AuthMessageType) { | ||
| AuthMessageType[AuthMessageType["Token"] = 0] = "Token"; | ||
| AuthMessageType[AuthMessageType["PermissionDenied"] = 1] = "PermissionDenied"; | ||
| AuthMessageType[AuthMessageType["Authenticated"] = 2] = "Authenticated"; | ||
| })(AuthMessageType || (AuthMessageType = {})); | ||
| //#endregion | ||
| //#region packages/common/src/auth.ts | ||
| let AuthMessageType = /* @__PURE__ */ function(AuthMessageType) { | ||
| AuthMessageType[AuthMessageType["Token"] = 0] = "Token"; | ||
| AuthMessageType[AuthMessageType["PermissionDenied"] = 1] = "PermissionDenied"; | ||
| AuthMessageType[AuthMessageType["Authenticated"] = 2] = "Authenticated"; | ||
| return AuthMessageType; | ||
| }({}); | ||
| const writeAuthentication = (encoder, auth) => { | ||
| writeVarUint(encoder, AuthMessageType.Token); | ||
| writeVarString(encoder, auth); | ||
| writeVarUint(encoder, AuthMessageType.Token); | ||
| writeVarString(encoder, auth); | ||
| }; | ||
| const writePermissionDenied = (encoder, reason) => { | ||
| writeVarUint(encoder, AuthMessageType.PermissionDenied); | ||
| writeVarString(encoder, reason); | ||
| writeVarUint(encoder, AuthMessageType.PermissionDenied); | ||
| writeVarString(encoder, reason); | ||
| }; | ||
| const writeAuthenticated = (encoder, scope) => { | ||
| writeVarUint(encoder, AuthMessageType.Authenticated); | ||
| writeVarString(encoder, scope); | ||
| writeVarUint(encoder, AuthMessageType.Authenticated); | ||
| writeVarString(encoder, scope); | ||
| }; | ||
| const writeTokenSyncRequest = (encoder) => { | ||
| writeVarUint(encoder, AuthMessageType.Token); | ||
| writeVarUint(encoder, AuthMessageType.Token); | ||
| }; | ||
| const readAuthMessage = (decoder, sendToken, permissionDeniedHandler, authenticatedHandler) => { | ||
| switch (readVarUint(decoder)) { | ||
| case AuthMessageType.Token: { | ||
| sendToken(); | ||
| break; | ||
| } | ||
| case AuthMessageType.PermissionDenied: { | ||
| permissionDeniedHandler(readVarString(decoder)); | ||
| break; | ||
| } | ||
| case AuthMessageType.Authenticated: { | ||
| authenticatedHandler(readVarString(decoder)); | ||
| break; | ||
| } | ||
| } | ||
| switch (readVarUint(decoder)) { | ||
| case AuthMessageType.Token: | ||
| sendToken(); | ||
| break; | ||
| case AuthMessageType.PermissionDenied: | ||
| permissionDeniedHandler(readVarString(decoder)); | ||
| break; | ||
| case AuthMessageType.Authenticated: | ||
| authenticatedHandler(readVarString(decoder)); | ||
| break; | ||
| default: | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region packages/common/src/CloseEvents.ts | ||
| /** | ||
| * The server is terminating the connection because a data frame was received | ||
| * that is too large. | ||
| * See: https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code | ||
| */ | ||
| * The server is terminating the connection because a data frame was received | ||
| * that is too large. | ||
| * See: https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code | ||
| */ | ||
| const MessageTooBig = { | ||
| code: 1009, | ||
| reason: "Message Too Big", | ||
| code: 1009, | ||
| reason: "Message Too Big" | ||
| }; | ||
| /** | ||
| * The server successfully processed the request, asks that the requester reset | ||
| * its document view, and is not returning any content. | ||
| */ | ||
| * The server successfully processed the request, asks that the requester reset | ||
| * its document view, and is not returning any content. | ||
| */ | ||
| const ResetConnection = { | ||
| code: 4205, | ||
| reason: "Reset Connection", | ||
| code: 4205, | ||
| reason: "Reset Connection" | ||
| }; | ||
| /** | ||
| * Similar to Forbidden, but specifically for use when authentication is required and has | ||
| * failed or has not yet been provided. | ||
| */ | ||
| * Similar to Forbidden, but specifically for use when authentication is required and has | ||
| * failed or has not yet been provided. | ||
| */ | ||
| const Unauthorized = { | ||
| code: 4401, | ||
| reason: "Unauthorized", | ||
| code: 4401, | ||
| reason: "Unauthorized" | ||
| }; | ||
| /** | ||
| * The request contained valid data and was understood by the server, but the server | ||
| * is refusing action. | ||
| */ | ||
| * The request contained valid data and was understood by the server, but the server | ||
| * is refusing action. | ||
| */ | ||
| const Forbidden = { | ||
| code: 4403, | ||
| reason: "Forbidden", | ||
| code: 4403, | ||
| reason: "Forbidden" | ||
| }; | ||
| /** | ||
| * The server timed out waiting for the request. | ||
| */ | ||
| * The server timed out waiting for the request. | ||
| */ | ||
| const ConnectionTimeout = { | ||
| code: 4408, | ||
| reason: "Connection Timeout", | ||
| code: 4408, | ||
| reason: "Connection Timeout" | ||
| }; | ||
| //#endregion | ||
| //#region packages/common/src/awarenessStatesToArray.ts | ||
| const awarenessStatesToArray = (states) => { | ||
| return Array.from(states.entries()).map(([key, value]) => { | ||
| return { | ||
| clientId: key, | ||
| ...value, | ||
| }; | ||
| }); | ||
| return Array.from(states.entries()).map(([key, value]) => { | ||
| return { | ||
| clientId: key, | ||
| ...value | ||
| }; | ||
| }); | ||
| }; | ||
| //#endregion | ||
| //#region packages/common/src/types.ts | ||
| /** | ||
| * State of the WebSocket connection. | ||
| * https://developer.mozilla.org/de/docs/Web/API/WebSocket/readyState | ||
| */ | ||
| var WsReadyStates; | ||
| (function (WsReadyStates) { | ||
| WsReadyStates[WsReadyStates["Connecting"] = 0] = "Connecting"; | ||
| WsReadyStates[WsReadyStates["Open"] = 1] = "Open"; | ||
| WsReadyStates[WsReadyStates["Closing"] = 2] = "Closing"; | ||
| WsReadyStates[WsReadyStates["Closed"] = 3] = "Closed"; | ||
| })(WsReadyStates || (WsReadyStates = {})); | ||
| * State of the WebSocket connection. | ||
| * https://developer.mozilla.org/de/docs/Web/API/WebSocket/readyState | ||
| */ | ||
| let WsReadyStates = /* @__PURE__ */ function(WsReadyStates) { | ||
| WsReadyStates[WsReadyStates["Connecting"] = 0] = "Connecting"; | ||
| WsReadyStates[WsReadyStates["Open"] = 1] = "Open"; | ||
| WsReadyStates[WsReadyStates["Closing"] = 2] = "Closing"; | ||
| WsReadyStates[WsReadyStates["Closed"] = 3] = "Closed"; | ||
| return WsReadyStates; | ||
| }({}); | ||
| //#endregion | ||
| export { AuthMessageType, ConnectionTimeout, Forbidden, MessageTooBig, ResetConnection, Unauthorized, WsReadyStates, awarenessStatesToArray, readAuthMessage, writeAuthenticated, writeAuthentication, writePermissionDenied, writeTokenSyncRequest }; | ||
| //# sourceMappingURL=hocuspocus-common.esm.js.map | ||
| //# sourceMappingURL=hocuspocus-common.esm.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"hocuspocus-common.esm.js","sources":["../../../node_modules/lib0/math.js","../../../node_modules/lib0/binary.js","../../../node_modules/lib0/number.js","../../../node_modules/lib0/string.js","../../../node_modules/lib0/encoding.js","../../../node_modules/lib0/error.js","../../../node_modules/lib0/decoding.js","../src/auth.ts","../src/CloseEvents.ts","../src/awarenessStatesToArray.ts","../src/types.ts"],"sourcesContent":["/**\n * Common Math expressions.\n *\n * @module math\n */\n\nexport const floor = Math.floor\nexport const ceil = Math.ceil\nexport const abs = Math.abs\nexport const imul = Math.imul\nexport const round = Math.round\nexport const log10 = Math.log10\nexport const log2 = Math.log2\nexport const log = Math.log\nexport const sqrt = Math.sqrt\n\n/**\n * @function\n * @param {number} a\n * @param {number} b\n * @return {number} The sum of a and b\n */\nexport const add = (a, b) => a + b\n\n/**\n * @function\n * @param {number} a\n * @param {number} b\n * @return {number} The smaller element of a and b\n */\nexport const min = (a, b) => a < b ? a : b\n\n/**\n * @function\n * @param {number} a\n * @param {number} b\n * @return {number} The bigger element of a and b\n */\nexport const max = (a, b) => a > b ? a : b\n\nexport const isNaN = Number.isNaN\n\nexport const pow = Math.pow\n/**\n * Base 10 exponential function. Returns the value of 10 raised to the power of pow.\n *\n * @param {number} exp\n * @return {number}\n */\nexport const exp10 = exp => Math.pow(10, exp)\n\nexport const sign = Math.sign\n\n/**\n * @param {number} n\n * @return {boolean} Wether n is negative. This function also differentiates between -0 and +0\n */\nexport const isNegativeZero = n => n !== 0 ? n < 0 : 1 / n < 0\n","/* eslint-env browser */\n\n/**\n * Binary data constants.\n *\n * @module binary\n */\n\n/**\n * n-th bit activated.\n *\n * @type {number}\n */\nexport const BIT1 = 1\nexport const BIT2 = 2\nexport const BIT3 = 4\nexport const BIT4 = 8\nexport const BIT5 = 16\nexport const BIT6 = 32\nexport const BIT7 = 64\nexport const BIT8 = 128\nexport const BIT9 = 256\nexport const BIT10 = 512\nexport const BIT11 = 1024\nexport const BIT12 = 2048\nexport const BIT13 = 4096\nexport const BIT14 = 8192\nexport const BIT15 = 16384\nexport const BIT16 = 32768\nexport const BIT17 = 65536\nexport const BIT18 = 1 << 17\nexport const BIT19 = 1 << 18\nexport const BIT20 = 1 << 19\nexport const BIT21 = 1 << 20\nexport const BIT22 = 1 << 21\nexport const BIT23 = 1 << 22\nexport const BIT24 = 1 << 23\nexport const BIT25 = 1 << 24\nexport const BIT26 = 1 << 25\nexport const BIT27 = 1 << 26\nexport const BIT28 = 1 << 27\nexport const BIT29 = 1 << 28\nexport const BIT30 = 1 << 29\nexport const BIT31 = 1 << 30\nexport const BIT32 = 1 << 31\n\n/**\n * First n bits activated.\n *\n * @type {number}\n */\nexport const BITS0 = 0\nexport const BITS1 = 1\nexport const BITS2 = 3\nexport const BITS3 = 7\nexport const BITS4 = 15\nexport const BITS5 = 31\nexport const BITS6 = 63\nexport const BITS7 = 127\nexport const BITS8 = 255\nexport const BITS9 = 511\nexport const BITS10 = 1023\nexport const BITS11 = 2047\nexport const BITS12 = 4095\nexport const BITS13 = 8191\nexport const BITS14 = 16383\nexport const BITS15 = 32767\nexport const BITS16 = 65535\nexport const BITS17 = BIT18 - 1\nexport const BITS18 = BIT19 - 1\nexport const BITS19 = BIT20 - 1\nexport const BITS20 = BIT21 - 1\nexport const BITS21 = BIT22 - 1\nexport const BITS22 = BIT23 - 1\nexport const BITS23 = BIT24 - 1\nexport const BITS24 = BIT25 - 1\nexport const BITS25 = BIT26 - 1\nexport const BITS26 = BIT27 - 1\nexport const BITS27 = BIT28 - 1\nexport const BITS28 = BIT29 - 1\nexport const BITS29 = BIT30 - 1\nexport const BITS30 = BIT31 - 1\n/**\n * @type {number}\n */\nexport const BITS31 = 0x7FFFFFFF\n/**\n * @type {number}\n */\nexport const BITS32 = 0xFFFFFFFF\n","/**\n * Utility helpers for working with numbers.\n *\n * @module number\n */\n\nimport * as math from './math.js'\nimport * as binary from './binary.js'\n\nexport const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER\nexport const MIN_SAFE_INTEGER = Number.MIN_SAFE_INTEGER\n\nexport const LOWEST_INT32 = 1 << 31\nexport const HIGHEST_INT32 = binary.BITS31\nexport const HIGHEST_UINT32 = binary.BITS32\n\n/* c8 ignore next */\nexport const isInteger = Number.isInteger || (num => typeof num === 'number' && isFinite(num) && math.floor(num) === num)\nexport const isNaN = Number.isNaN\nexport const parseInt = Number.parseInt\n\n/**\n * Count the number of \"1\" bits in an unsigned 32bit number.\n *\n * Super fun bitcount algorithm by Brian Kernighan.\n *\n * @param {number} n\n */\nexport const countBits = n => {\n n &= binary.BITS32\n let count = 0\n while (n) {\n n &= (n - 1)\n count++\n }\n return count\n}\n","import * as array from './array.js'\n\n/**\n * Utility module to work with strings.\n *\n * @module string\n */\n\nexport const fromCharCode = String.fromCharCode\nexport const fromCodePoint = String.fromCodePoint\n\n/**\n * The largest utf16 character.\n * Corresponds to Uint8Array([255, 255]) or charcodeof(2x2^8)\n */\nexport const MAX_UTF16_CHARACTER = fromCharCode(65535)\n\n/**\n * @param {string} s\n * @return {string}\n */\nconst toLowerCase = s => s.toLowerCase()\n\nconst trimLeftRegex = /^\\s*/g\n\n/**\n * @param {string} s\n * @return {string}\n */\nexport const trimLeft = s => s.replace(trimLeftRegex, '')\n\nconst fromCamelCaseRegex = /([A-Z])/g\n\n/**\n * @param {string} s\n * @param {string} separator\n * @return {string}\n */\nexport const fromCamelCase = (s, separator) => trimLeft(s.replace(fromCamelCaseRegex, match => `${separator}${toLowerCase(match)}`))\n\n/**\n * Compute the utf8ByteLength\n * @param {string} str\n * @return {number}\n */\nexport const utf8ByteLength = str => unescape(encodeURIComponent(str)).length\n\n/**\n * @param {string} str\n * @return {Uint8Array}\n */\nexport const _encodeUtf8Polyfill = str => {\n const encodedString = unescape(encodeURIComponent(str))\n const len = encodedString.length\n const buf = new Uint8Array(len)\n for (let i = 0; i < len; i++) {\n buf[i] = /** @type {number} */ (encodedString.codePointAt(i))\n }\n return buf\n}\n\n/* c8 ignore next */\nexport const utf8TextEncoder = /** @type {TextEncoder} */ (typeof TextEncoder !== 'undefined' ? new TextEncoder() : null)\n\n/**\n * @param {string} str\n * @return {Uint8Array}\n */\nexport const _encodeUtf8Native = str => utf8TextEncoder.encode(str)\n\n/**\n * @param {string} str\n * @return {Uint8Array}\n */\n/* c8 ignore next */\nexport const encodeUtf8 = utf8TextEncoder ? _encodeUtf8Native : _encodeUtf8Polyfill\n\n/**\n * @param {Uint8Array} buf\n * @return {string}\n */\nexport const _decodeUtf8Polyfill = buf => {\n let remainingLen = buf.length\n let encodedString = ''\n let bufPos = 0\n while (remainingLen > 0) {\n const nextLen = remainingLen < 10000 ? remainingLen : 10000\n const bytes = buf.subarray(bufPos, bufPos + nextLen)\n bufPos += nextLen\n // Starting with ES5.1 we can supply a generic array-like object as arguments\n encodedString += String.fromCodePoint.apply(null, /** @type {any} */ (bytes))\n remainingLen -= nextLen\n }\n return decodeURIComponent(escape(encodedString))\n}\n\n/* c8 ignore next */\nexport let utf8TextDecoder = typeof TextDecoder === 'undefined' ? null : new TextDecoder('utf-8', { fatal: true, ignoreBOM: true })\n\n/* c8 ignore start */\nif (utf8TextDecoder && utf8TextDecoder.decode(new Uint8Array()).length === 1) {\n // Safari doesn't handle BOM correctly.\n // This fixes a bug in Safari 13.0.5 where it produces a BOM the first time it is called.\n // utf8TextDecoder.decode(new Uint8Array()).length === 1 on the first call and\n // utf8TextDecoder.decode(new Uint8Array()).length === 1 on the second call\n // Another issue is that from then on no BOM chars are recognized anymore\n /* c8 ignore next */\n utf8TextDecoder = null\n}\n/* c8 ignore stop */\n\n/**\n * @param {Uint8Array} buf\n * @return {string}\n */\nexport const _decodeUtf8Native = buf => /** @type {TextDecoder} */ (utf8TextDecoder).decode(buf)\n\n/**\n * @param {Uint8Array} buf\n * @return {string}\n */\n/* c8 ignore next */\nexport const decodeUtf8 = utf8TextDecoder ? _decodeUtf8Native : _decodeUtf8Polyfill\n\n/**\n * @param {string} str The initial string\n * @param {number} index Starting position\n * @param {number} remove Number of characters to remove\n * @param {string} insert New content to insert\n */\nexport const splice = (str, index, remove, insert = '') => str.slice(0, index) + insert + str.slice(index + remove)\n\n/**\n * @param {string} source\n * @param {number} n\n */\nexport const repeat = (source, n) => array.unfold(n, () => source).join('')\n","/**\n * Efficient schema-less binary encoding with support for variable length encoding.\n *\n * Use [lib0/encoding] with [lib0/decoding]. Every encoding function has a corresponding decoding function.\n *\n * Encodes numbers in little-endian order (least to most significant byte order)\n * and is compatible with Golang's binary encoding (https://golang.org/pkg/encoding/binary/)\n * which is also used in Protocol Buffers.\n *\n * ```js\n * // encoding step\n * const encoder = encoding.createEncoder()\n * encoding.writeVarUint(encoder, 256)\n * encoding.writeVarString(encoder, 'Hello world!')\n * const buf = encoding.toUint8Array(encoder)\n * ```\n *\n * ```js\n * // decoding step\n * const decoder = decoding.createDecoder(buf)\n * decoding.readVarUint(decoder) // => 256\n * decoding.readVarString(decoder) // => 'Hello world!'\n * decoding.hasContent(decoder) // => false - all data is read\n * ```\n *\n * @module encoding\n */\n\nimport * as math from './math.js'\nimport * as number from './number.js'\nimport * as binary from './binary.js'\nimport * as string from './string.js'\nimport * as array from './array.js'\n\n/**\n * A BinaryEncoder handles the encoding to an Uint8Array.\n */\nexport class Encoder {\n constructor () {\n this.cpos = 0\n this.cbuf = new Uint8Array(100)\n /**\n * @type {Array<Uint8Array>}\n */\n this.bufs = []\n }\n}\n\n/**\n * @function\n * @return {Encoder}\n */\nexport const createEncoder = () => new Encoder()\n\n/**\n * @param {function(Encoder):void} f\n */\nexport const encode = (f) => {\n const encoder = createEncoder()\n f(encoder)\n return toUint8Array(encoder)\n}\n\n/**\n * The current length of the encoded data.\n *\n * @function\n * @param {Encoder} encoder\n * @return {number}\n */\nexport const length = encoder => {\n let len = encoder.cpos\n for (let i = 0; i < encoder.bufs.length; i++) {\n len += encoder.bufs[i].length\n }\n return len\n}\n\n/**\n * Check whether encoder is empty.\n *\n * @function\n * @param {Encoder} encoder\n * @return {boolean}\n */\nexport const hasContent = encoder => encoder.cpos > 0 || encoder.bufs.length > 0\n\n/**\n * Transform to Uint8Array.\n *\n * @function\n * @param {Encoder} encoder\n * @return {Uint8Array} The created ArrayBuffer.\n */\nexport const toUint8Array = encoder => {\n const uint8arr = new Uint8Array(length(encoder))\n let curPos = 0\n for (let i = 0; i < encoder.bufs.length; i++) {\n const d = encoder.bufs[i]\n uint8arr.set(d, curPos)\n curPos += d.length\n }\n uint8arr.set(new Uint8Array(encoder.cbuf.buffer, 0, encoder.cpos), curPos)\n return uint8arr\n}\n\n/**\n * Verify that it is possible to write `len` bytes wtihout checking. If\n * necessary, a new Buffer with the required length is attached.\n *\n * @param {Encoder} encoder\n * @param {number} len\n */\nexport const verifyLen = (encoder, len) => {\n const bufferLen = encoder.cbuf.length\n if (bufferLen - encoder.cpos < len) {\n encoder.bufs.push(new Uint8Array(encoder.cbuf.buffer, 0, encoder.cpos))\n encoder.cbuf = new Uint8Array(math.max(bufferLen, len) * 2)\n encoder.cpos = 0\n }\n}\n\n/**\n * Write one byte to the encoder.\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} num The byte that is to be encoded.\n */\nexport const write = (encoder, num) => {\n const bufferLen = encoder.cbuf.length\n if (encoder.cpos === bufferLen) {\n encoder.bufs.push(encoder.cbuf)\n encoder.cbuf = new Uint8Array(bufferLen * 2)\n encoder.cpos = 0\n }\n encoder.cbuf[encoder.cpos++] = num\n}\n\n/**\n * Write one byte at a specific position.\n * Position must already be written (i.e. encoder.length > pos)\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} pos Position to which to write data\n * @param {number} num Unsigned 8-bit integer\n */\nexport const set = (encoder, pos, num) => {\n let buffer = null\n // iterate all buffers and adjust position\n for (let i = 0; i < encoder.bufs.length && buffer === null; i++) {\n const b = encoder.bufs[i]\n if (pos < b.length) {\n buffer = b // found buffer\n } else {\n pos -= b.length\n }\n }\n if (buffer === null) {\n // use current buffer\n buffer = encoder.cbuf\n }\n buffer[pos] = num\n}\n\n/**\n * Write one byte as an unsigned integer.\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} num The number that is to be encoded.\n */\nexport const writeUint8 = write\n\n/**\n * Write one byte as an unsigned Integer at a specific location.\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} pos The location where the data will be written.\n * @param {number} num The number that is to be encoded.\n */\nexport const setUint8 = set\n\n/**\n * Write two bytes as an unsigned integer.\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} num The number that is to be encoded.\n */\nexport const writeUint16 = (encoder, num) => {\n write(encoder, num & binary.BITS8)\n write(encoder, (num >>> 8) & binary.BITS8)\n}\n/**\n * Write two bytes as an unsigned integer at a specific location.\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} pos The location where the data will be written.\n * @param {number} num The number that is to be encoded.\n */\nexport const setUint16 = (encoder, pos, num) => {\n set(encoder, pos, num & binary.BITS8)\n set(encoder, pos + 1, (num >>> 8) & binary.BITS8)\n}\n\n/**\n * Write two bytes as an unsigned integer\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} num The number that is to be encoded.\n */\nexport const writeUint32 = (encoder, num) => {\n for (let i = 0; i < 4; i++) {\n write(encoder, num & binary.BITS8)\n num >>>= 8\n }\n}\n\n/**\n * Write two bytes as an unsigned integer in big endian order.\n * (most significant byte first)\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} num The number that is to be encoded.\n */\nexport const writeUint32BigEndian = (encoder, num) => {\n for (let i = 3; i >= 0; i--) {\n write(encoder, (num >>> (8 * i)) & binary.BITS8)\n }\n}\n\n/**\n * Write two bytes as an unsigned integer at a specific location.\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} pos The location where the data will be written.\n * @param {number} num The number that is to be encoded.\n */\nexport const setUint32 = (encoder, pos, num) => {\n for (let i = 0; i < 4; i++) {\n set(encoder, pos + i, num & binary.BITS8)\n num >>>= 8\n }\n}\n\n/**\n * Write a variable length unsigned integer. Max encodable integer is 2^53.\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} num The number that is to be encoded.\n */\nexport const writeVarUint = (encoder, num) => {\n while (num > binary.BITS7) {\n write(encoder, binary.BIT8 | (binary.BITS7 & num))\n num = math.floor(num / 128) // shift >>> 7\n }\n write(encoder, binary.BITS7 & num)\n}\n\n/**\n * Write a variable length integer.\n *\n * We use the 7th bit instead for signaling that this is a negative number.\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} num The number that is to be encoded.\n */\nexport const writeVarInt = (encoder, num) => {\n const isNegative = math.isNegativeZero(num)\n if (isNegative) {\n num = -num\n }\n // |- whether to continue reading |- whether is negative |- number\n write(encoder, (num > binary.BITS6 ? binary.BIT8 : 0) | (isNegative ? binary.BIT7 : 0) | (binary.BITS6 & num))\n num = math.floor(num / 64) // shift >>> 6\n // We don't need to consider the case of num === 0 so we can use a different\n // pattern here than above.\n while (num > 0) {\n write(encoder, (num > binary.BITS7 ? binary.BIT8 : 0) | (binary.BITS7 & num))\n num = math.floor(num / 128) // shift >>> 7\n }\n}\n\n/**\n * A cache to store strings temporarily\n */\nconst _strBuffer = new Uint8Array(30000)\nconst _maxStrBSize = _strBuffer.length / 3\n\n/**\n * Write a variable length string.\n *\n * @function\n * @param {Encoder} encoder\n * @param {String} str The string that is to be encoded.\n */\nexport const _writeVarStringNative = (encoder, str) => {\n if (str.length < _maxStrBSize) {\n // We can encode the string into the existing buffer\n /* c8 ignore next */\n const written = string.utf8TextEncoder.encodeInto(str, _strBuffer).written || 0\n writeVarUint(encoder, written)\n for (let i = 0; i < written; i++) {\n write(encoder, _strBuffer[i])\n }\n } else {\n writeVarUint8Array(encoder, string.encodeUtf8(str))\n }\n}\n\n/**\n * Write a variable length string.\n *\n * @function\n * @param {Encoder} encoder\n * @param {String} str The string that is to be encoded.\n */\nexport const _writeVarStringPolyfill = (encoder, str) => {\n const encodedString = unescape(encodeURIComponent(str))\n const len = encodedString.length\n writeVarUint(encoder, len)\n for (let i = 0; i < len; i++) {\n write(encoder, /** @type {number} */ (encodedString.codePointAt(i)))\n }\n}\n\n/**\n * Write a variable length string.\n *\n * @function\n * @param {Encoder} encoder\n * @param {String} str The string that is to be encoded.\n */\n/* c8 ignore next */\nexport const writeVarString = (string.utf8TextEncoder && /** @type {any} */ (string.utf8TextEncoder).encodeInto) ? _writeVarStringNative : _writeVarStringPolyfill\n\n/**\n * Write a string terminated by a special byte sequence. This is not very performant and is\n * generally discouraged. However, the resulting byte arrays are lexiographically ordered which\n * makes this a nice feature for databases.\n *\n * The string will be encoded using utf8 and then terminated and escaped using writeTerminatingUint8Array.\n *\n * @function\n * @param {Encoder} encoder\n * @param {String} str The string that is to be encoded.\n */\nexport const writeTerminatedString = (encoder, str) =>\n writeTerminatedUint8Array(encoder, string.encodeUtf8(str))\n\n/**\n * Write a terminating Uint8Array. Note that this is not performant and is generally\n * discouraged. There are few situations when this is needed.\n *\n * We use 0x0 as a terminating character. 0x1 serves as an escape character for 0x0 and 0x1.\n *\n * Example: [0,1,2] is encoded to [1,0,1,1,2,0]. 0x0, and 0x1 needed to be escaped using 0x1. Then\n * the result is terminated using the 0x0 character.\n *\n * This is basically how many systems implement null terminated strings. However, we use an escape\n * character 0x1 to avoid issues and potenial attacks on our database (if this is used as a key\n * encoder for NoSql databases).\n *\n * @function\n * @param {Encoder} encoder\n * @param {Uint8Array} buf The string that is to be encoded.\n */\nexport const writeTerminatedUint8Array = (encoder, buf) => {\n for (let i = 0; i < buf.length; i++) {\n const b = buf[i]\n if (b === 0 || b === 1) {\n write(encoder, 1)\n }\n write(encoder, buf[i])\n }\n write(encoder, 0)\n}\n\n/**\n * Write the content of another Encoder.\n *\n * @TODO: can be improved!\n * - Note: Should consider that when appending a lot of small Encoders, we should rather clone than referencing the old structure.\n * Encoders start with a rather big initial buffer.\n *\n * @function\n * @param {Encoder} encoder The enUint8Arr\n * @param {Encoder} append The BinaryEncoder to be written.\n */\nexport const writeBinaryEncoder = (encoder, append) => writeUint8Array(encoder, toUint8Array(append))\n\n/**\n * Append fixed-length Uint8Array to the encoder.\n *\n * @function\n * @param {Encoder} encoder\n * @param {Uint8Array} uint8Array\n */\nexport const writeUint8Array = (encoder, uint8Array) => {\n const bufferLen = encoder.cbuf.length\n const cpos = encoder.cpos\n const leftCopyLen = math.min(bufferLen - cpos, uint8Array.length)\n const rightCopyLen = uint8Array.length - leftCopyLen\n encoder.cbuf.set(uint8Array.subarray(0, leftCopyLen), cpos)\n encoder.cpos += leftCopyLen\n if (rightCopyLen > 0) {\n // Still something to write, write right half..\n // Append new buffer\n encoder.bufs.push(encoder.cbuf)\n // must have at least size of remaining buffer\n encoder.cbuf = new Uint8Array(math.max(bufferLen * 2, rightCopyLen))\n // copy array\n encoder.cbuf.set(uint8Array.subarray(leftCopyLen))\n encoder.cpos = rightCopyLen\n }\n}\n\n/**\n * Append an Uint8Array to Encoder.\n *\n * @function\n * @param {Encoder} encoder\n * @param {Uint8Array} uint8Array\n */\nexport const writeVarUint8Array = (encoder, uint8Array) => {\n writeVarUint(encoder, uint8Array.byteLength)\n writeUint8Array(encoder, uint8Array)\n}\n\n/**\n * Create an DataView of the next `len` bytes. Use it to write data after\n * calling this function.\n *\n * ```js\n * // write float32 using DataView\n * const dv = writeOnDataView(encoder, 4)\n * dv.setFloat32(0, 1.1)\n * // read float32 using DataView\n * const dv = readFromDataView(encoder, 4)\n * dv.getFloat32(0) // => 1.100000023841858 (leaving it to the reader to find out why this is the correct result)\n * ```\n *\n * @param {Encoder} encoder\n * @param {number} len\n * @return {DataView}\n */\nexport const writeOnDataView = (encoder, len) => {\n verifyLen(encoder, len)\n const dview = new DataView(encoder.cbuf.buffer, encoder.cpos, len)\n encoder.cpos += len\n return dview\n}\n\n/**\n * @param {Encoder} encoder\n * @param {number} num\n */\nexport const writeFloat32 = (encoder, num) => writeOnDataView(encoder, 4).setFloat32(0, num, false)\n\n/**\n * @param {Encoder} encoder\n * @param {number} num\n */\nexport const writeFloat64 = (encoder, num) => writeOnDataView(encoder, 8).setFloat64(0, num, false)\n\n/**\n * @param {Encoder} encoder\n * @param {bigint} num\n */\nexport const writeBigInt64 = (encoder, num) => /** @type {any} */ (writeOnDataView(encoder, 8)).setBigInt64(0, num, false)\n\n/**\n * @param {Encoder} encoder\n * @param {bigint} num\n */\nexport const writeBigUint64 = (encoder, num) => /** @type {any} */ (writeOnDataView(encoder, 8)).setBigUint64(0, num, false)\n\nconst floatTestBed = new DataView(new ArrayBuffer(4))\n/**\n * Check if a number can be encoded as a 32 bit float.\n *\n * @param {number} num\n * @return {boolean}\n */\nconst isFloat32 = num => {\n floatTestBed.setFloat32(0, num)\n return floatTestBed.getFloat32(0) === num\n}\n\n/**\n * Encode data with efficient binary format.\n *\n * Differences to JSON:\n * • Transforms data to a binary format (not to a string)\n * • Encodes undefined, NaN, and ArrayBuffer (these can't be represented in JSON)\n * • Numbers are efficiently encoded either as a variable length integer, as a\n * 32 bit float, as a 64 bit float, or as a 64 bit bigint.\n *\n * Encoding table:\n *\n * | Data Type | Prefix | Encoding Method | Comment |\n * | ------------------- | -------- | ------------------ | ------- |\n * | undefined | 127 | | Functions, symbol, and everything that cannot be identified is encoded as undefined |\n * | null | 126 | | |\n * | integer | 125 | writeVarInt | Only encodes 32 bit signed integers |\n * | float32 | 124 | writeFloat32 | |\n * | float64 | 123 | writeFloat64 | |\n * | bigint | 122 | writeBigInt64 | |\n * | boolean (false) | 121 | | True and false are different data types so we save the following byte |\n * | boolean (true) | 120 | | - 0b01111000 so the last bit determines whether true or false |\n * | string | 119 | writeVarString | |\n * | object<string,any> | 118 | custom | Writes {length} then {length} key-value pairs |\n * | array<any> | 117 | custom | Writes {length} then {length} json values |\n * | Uint8Array | 116 | writeVarUint8Array | We use Uint8Array for any kind of binary data |\n *\n * Reasons for the decreasing prefix:\n * We need the first bit for extendability (later we may want to encode the\n * prefix with writeVarUint). The remaining 7 bits are divided as follows:\n * [0-30] the beginning of the data range is used for custom purposes\n * (defined by the function that uses this library)\n * [31-127] the end of the data range is used for data encoding by\n * lib0/encoding.js\n *\n * @param {Encoder} encoder\n * @param {undefined|null|number|bigint|boolean|string|Object<string,any>|Array<any>|Uint8Array} data\n */\nexport const writeAny = (encoder, data) => {\n switch (typeof data) {\n case 'string':\n // TYPE 119: STRING\n write(encoder, 119)\n writeVarString(encoder, data)\n break\n case 'number':\n if (number.isInteger(data) && math.abs(data) <= binary.BITS31) {\n // TYPE 125: INTEGER\n write(encoder, 125)\n writeVarInt(encoder, data)\n } else if (isFloat32(data)) {\n // TYPE 124: FLOAT32\n write(encoder, 124)\n writeFloat32(encoder, data)\n } else {\n // TYPE 123: FLOAT64\n write(encoder, 123)\n writeFloat64(encoder, data)\n }\n break\n case 'bigint':\n // TYPE 122: BigInt\n write(encoder, 122)\n writeBigInt64(encoder, data)\n break\n case 'object':\n if (data === null) {\n // TYPE 126: null\n write(encoder, 126)\n } else if (array.isArray(data)) {\n // TYPE 117: Array\n write(encoder, 117)\n writeVarUint(encoder, data.length)\n for (let i = 0; i < data.length; i++) {\n writeAny(encoder, data[i])\n }\n } else if (data instanceof Uint8Array) {\n // TYPE 116: ArrayBuffer\n write(encoder, 116)\n writeVarUint8Array(encoder, data)\n } else {\n // TYPE 118: Object\n write(encoder, 118)\n const keys = Object.keys(data)\n writeVarUint(encoder, keys.length)\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i]\n writeVarString(encoder, key)\n writeAny(encoder, data[key])\n }\n }\n break\n case 'boolean':\n // TYPE 120/121: boolean (true/false)\n write(encoder, data ? 120 : 121)\n break\n default:\n // TYPE 127: undefined\n write(encoder, 127)\n }\n}\n\n/**\n * Now come a few stateful encoder that have their own classes.\n */\n\n/**\n * Basic Run Length Encoder - a basic compression implementation.\n *\n * Encodes [1,1,1,7] to [1,3,7,1] (3 times 1, 1 time 7). This encoder might do more harm than good if there are a lot of values that are not repeated.\n *\n * It was originally used for image compression. Cool .. article http://csbruce.com/cbm/transactor/pdfs/trans_v7_i06.pdf\n *\n * @note T must not be null!\n *\n * @template T\n */\nexport class RleEncoder extends Encoder {\n /**\n * @param {function(Encoder, T):void} writer\n */\n constructor (writer) {\n super()\n /**\n * The writer\n */\n this.w = writer\n /**\n * Current state\n * @type {T|null}\n */\n this.s = null\n this.count = 0\n }\n\n /**\n * @param {T} v\n */\n write (v) {\n if (this.s === v) {\n this.count++\n } else {\n if (this.count > 0) {\n // flush counter, unless this is the first value (count = 0)\n writeVarUint(this, this.count - 1) // since count is always > 0, we can decrement by one. non-standard encoding ftw\n }\n this.count = 1\n // write first value\n this.w(this, v)\n this.s = v\n }\n }\n}\n\n/**\n * Basic diff decoder using variable length encoding.\n *\n * Encodes the values [3, 1100, 1101, 1050, 0] to [3, 1097, 1, -51, -1050] using writeVarInt.\n */\nexport class IntDiffEncoder extends Encoder {\n /**\n * @param {number} start\n */\n constructor (start) {\n super()\n /**\n * Current state\n * @type {number}\n */\n this.s = start\n }\n\n /**\n * @param {number} v\n */\n write (v) {\n writeVarInt(this, v - this.s)\n this.s = v\n }\n}\n\n/**\n * A combination of IntDiffEncoder and RleEncoder.\n *\n * Basically first writes the IntDiffEncoder and then counts duplicate diffs using RleEncoding.\n *\n * Encodes the values [1,1,1,2,3,4,5,6] as [1,1,0,2,1,5] (RLE([1,0,0,1,1,1,1,1]) ⇒ RleIntDiff[1,1,0,2,1,5])\n */\nexport class RleIntDiffEncoder extends Encoder {\n /**\n * @param {number} start\n */\n constructor (start) {\n super()\n /**\n * Current state\n * @type {number}\n */\n this.s = start\n this.count = 0\n }\n\n /**\n * @param {number} v\n */\n write (v) {\n if (this.s === v && this.count > 0) {\n this.count++\n } else {\n if (this.count > 0) {\n // flush counter, unless this is the first value (count = 0)\n writeVarUint(this, this.count - 1) // since count is always > 0, we can decrement by one. non-standard encoding ftw\n }\n this.count = 1\n // write first value\n writeVarInt(this, v - this.s)\n this.s = v\n }\n }\n}\n\n/**\n * @param {UintOptRleEncoder} encoder\n */\nconst flushUintOptRleEncoder = encoder => {\n if (encoder.count > 0) {\n // flush counter, unless this is the first value (count = 0)\n // case 1: just a single value. set sign to positive\n // case 2: write several values. set sign to negative to indicate that there is a length coming\n writeVarInt(encoder.encoder, encoder.count === 1 ? encoder.s : -encoder.s)\n if (encoder.count > 1) {\n writeVarUint(encoder.encoder, encoder.count - 2) // since count is always > 1, we can decrement by one. non-standard encoding ftw\n }\n }\n}\n\n/**\n * Optimized Rle encoder that does not suffer from the mentioned problem of the basic Rle encoder.\n *\n * Internally uses VarInt encoder to write unsigned integers. If the input occurs multiple times, we write\n * write it as a negative number. The UintOptRleDecoder then understands that it needs to read a count.\n *\n * Encodes [1,2,3,3,3] as [1,2,-3,3] (once 1, once 2, three times 3)\n */\nexport class UintOptRleEncoder {\n constructor () {\n this.encoder = new Encoder()\n /**\n * @type {number}\n */\n this.s = 0\n this.count = 0\n }\n\n /**\n * @param {number} v\n */\n write (v) {\n if (this.s === v) {\n this.count++\n } else {\n flushUintOptRleEncoder(this)\n this.count = 1\n this.s = v\n }\n }\n\n /**\n * Flush the encoded state and transform this to a Uint8Array.\n *\n * Note that this should only be called once.\n */\n toUint8Array () {\n flushUintOptRleEncoder(this)\n return toUint8Array(this.encoder)\n }\n}\n\n/**\n * Increasing Uint Optimized RLE Encoder\n *\n * The RLE encoder counts the number of same occurences of the same value.\n * The IncUintOptRle encoder counts if the value increases.\n * I.e. 7, 8, 9, 10 will be encoded as [-7, 4]. 1, 3, 5 will be encoded\n * as [1, 3, 5].\n */\nexport class IncUintOptRleEncoder {\n constructor () {\n this.encoder = new Encoder()\n /**\n * @type {number}\n */\n this.s = 0\n this.count = 0\n }\n\n /**\n * @param {number} v\n */\n write (v) {\n if (this.s + this.count === v) {\n this.count++\n } else {\n flushUintOptRleEncoder(this)\n this.count = 1\n this.s = v\n }\n }\n\n /**\n * Flush the encoded state and transform this to a Uint8Array.\n *\n * Note that this should only be called once.\n */\n toUint8Array () {\n flushUintOptRleEncoder(this)\n return toUint8Array(this.encoder)\n }\n}\n\n/**\n * @param {IntDiffOptRleEncoder} encoder\n */\nconst flushIntDiffOptRleEncoder = encoder => {\n if (encoder.count > 0) {\n // 31 bit making up the diff | wether to write the counter\n // const encodedDiff = encoder.diff << 1 | (encoder.count === 1 ? 0 : 1)\n const encodedDiff = encoder.diff * 2 + (encoder.count === 1 ? 0 : 1)\n // flush counter, unless this is the first value (count = 0)\n // case 1: just a single value. set first bit to positive\n // case 2: write several values. set first bit to negative to indicate that there is a length coming\n writeVarInt(encoder.encoder, encodedDiff)\n if (encoder.count > 1) {\n writeVarUint(encoder.encoder, encoder.count - 2) // since count is always > 1, we can decrement by one. non-standard encoding ftw\n }\n }\n}\n\n/**\n * A combination of the IntDiffEncoder and the UintOptRleEncoder.\n *\n * The count approach is similar to the UintDiffOptRleEncoder, but instead of using the negative bitflag, it encodes\n * in the LSB whether a count is to be read. Therefore this Encoder only supports 31 bit integers!\n *\n * Encodes [1, 2, 3, 2] as [3, 1, 6, -1] (more specifically [(1 << 1) | 1, (3 << 0) | 0, -1])\n *\n * Internally uses variable length encoding. Contrary to normal UintVar encoding, the first byte contains:\n * * 1 bit that denotes whether the next value is a count (LSB)\n * * 1 bit that denotes whether this value is negative (MSB - 1)\n * * 1 bit that denotes whether to continue reading the variable length integer (MSB)\n *\n * Therefore, only five bits remain to encode diff ranges.\n *\n * Use this Encoder only when appropriate. In most cases, this is probably a bad idea.\n */\nexport class IntDiffOptRleEncoder {\n constructor () {\n this.encoder = new Encoder()\n /**\n * @type {number}\n */\n this.s = 0\n this.count = 0\n this.diff = 0\n }\n\n /**\n * @param {number} v\n */\n write (v) {\n if (this.diff === v - this.s) {\n this.s = v\n this.count++\n } else {\n flushIntDiffOptRleEncoder(this)\n this.count = 1\n this.diff = v - this.s\n this.s = v\n }\n }\n\n /**\n * Flush the encoded state and transform this to a Uint8Array.\n *\n * Note that this should only be called once.\n */\n toUint8Array () {\n flushIntDiffOptRleEncoder(this)\n return toUint8Array(this.encoder)\n }\n}\n\n/**\n * Optimized String Encoder.\n *\n * Encoding many small strings in a simple Encoder is not very efficient. The function call to decode a string takes some time and creates references that must be eventually deleted.\n * In practice, when decoding several million small strings, the GC will kick in more and more often to collect orphaned string objects (or maybe there is another reason?).\n *\n * This string encoder solves the above problem. All strings are concatenated and written as a single string using a single encoding call.\n *\n * The lengths are encoded using a UintOptRleEncoder.\n */\nexport class StringEncoder {\n constructor () {\n /**\n * @type {Array<string>}\n */\n this.sarr = []\n this.s = ''\n this.lensE = new UintOptRleEncoder()\n }\n\n /**\n * @param {string} string\n */\n write (string) {\n this.s += string\n if (this.s.length > 19) {\n this.sarr.push(this.s)\n this.s = ''\n }\n this.lensE.write(string.length)\n }\n\n toUint8Array () {\n const encoder = new Encoder()\n this.sarr.push(this.s)\n this.s = ''\n writeVarString(encoder, this.sarr.join(''))\n writeUint8Array(encoder, this.lensE.toUint8Array())\n return toUint8Array(encoder)\n }\n}\n","/**\n * Error helpers.\n *\n * @module error\n */\n\n/**\n * @param {string} s\n * @return {Error}\n */\n/* c8 ignore next */\nexport const create = s => new Error(s)\n\n/**\n * @throws {Error}\n * @return {never}\n */\n/* c8 ignore next 3 */\nexport const methodUnimplemented = () => {\n throw create('Method unimplemented')\n}\n\n/**\n * @throws {Error}\n * @return {never}\n */\n/* c8 ignore next 3 */\nexport const unexpectedCase = () => {\n throw create('Unexpected case')\n}\n","/**\n * Efficient schema-less binary decoding with support for variable length encoding.\n *\n * Use [lib0/decoding] with [lib0/encoding]. Every encoding function has a corresponding decoding function.\n *\n * Encodes numbers in little-endian order (least to most significant byte order)\n * and is compatible with Golang's binary encoding (https://golang.org/pkg/encoding/binary/)\n * which is also used in Protocol Buffers.\n *\n * ```js\n * // encoding step\n * const encoder = encoding.createEncoder()\n * encoding.writeVarUint(encoder, 256)\n * encoding.writeVarString(encoder, 'Hello world!')\n * const buf = encoding.toUint8Array(encoder)\n * ```\n *\n * ```js\n * // decoding step\n * const decoder = decoding.createDecoder(buf)\n * decoding.readVarUint(decoder) // => 256\n * decoding.readVarString(decoder) // => 'Hello world!'\n * decoding.hasContent(decoder) // => false - all data is read\n * ```\n *\n * @module decoding\n */\n\nimport * as binary from './binary.js'\nimport * as math from './math.js'\nimport * as number from './number.js'\nimport * as string from './string.js'\nimport * as error from './error.js'\nimport * as encoding from './encoding.js'\n\nconst errorUnexpectedEndOfArray = error.create('Unexpected end of array')\nconst errorIntegerOutOfRange = error.create('Integer out of Range')\n\n/**\n * A Decoder handles the decoding of an Uint8Array.\n */\nexport class Decoder {\n /**\n * @param {Uint8Array} uint8Array Binary data to decode\n */\n constructor (uint8Array) {\n /**\n * Decoding target.\n *\n * @type {Uint8Array}\n */\n this.arr = uint8Array\n /**\n * Current decoding position.\n *\n * @type {number}\n */\n this.pos = 0\n }\n}\n\n/**\n * @function\n * @param {Uint8Array} uint8Array\n * @return {Decoder}\n */\nexport const createDecoder = uint8Array => new Decoder(uint8Array)\n\n/**\n * @function\n * @param {Decoder} decoder\n * @return {boolean}\n */\nexport const hasContent = decoder => decoder.pos !== decoder.arr.length\n\n/**\n * Clone a decoder instance.\n * Optionally set a new position parameter.\n *\n * @function\n * @param {Decoder} decoder The decoder instance\n * @param {number} [newPos] Defaults to current position\n * @return {Decoder} A clone of `decoder`\n */\nexport const clone = (decoder, newPos = decoder.pos) => {\n const _decoder = createDecoder(decoder.arr)\n _decoder.pos = newPos\n return _decoder\n}\n\n/**\n * Create an Uint8Array view of the next `len` bytes and advance the position by `len`.\n *\n * Important: The Uint8Array still points to the underlying ArrayBuffer. Make sure to discard the result as soon as possible to prevent any memory leaks.\n * Use `buffer.copyUint8Array` to copy the result into a new Uint8Array.\n *\n * @function\n * @param {Decoder} decoder The decoder instance\n * @param {number} len The length of bytes to read\n * @return {Uint8Array}\n */\nexport const readUint8Array = (decoder, len) => {\n const view = new Uint8Array(decoder.arr.buffer, decoder.pos + decoder.arr.byteOffset, len)\n decoder.pos += len\n return view\n}\n\n/**\n * Read variable length Uint8Array.\n *\n * Important: The Uint8Array still points to the underlying ArrayBuffer. Make sure to discard the result as soon as possible to prevent any memory leaks.\n * Use `buffer.copyUint8Array` to copy the result into a new Uint8Array.\n *\n * @function\n * @param {Decoder} decoder\n * @return {Uint8Array}\n */\nexport const readVarUint8Array = decoder => readUint8Array(decoder, readVarUint(decoder))\n\n/**\n * Read the rest of the content as an ArrayBuffer\n * @function\n * @param {Decoder} decoder\n * @return {Uint8Array}\n */\nexport const readTailAsUint8Array = decoder => readUint8Array(decoder, decoder.arr.length - decoder.pos)\n\n/**\n * Skip one byte, jump to the next position.\n * @function\n * @param {Decoder} decoder The decoder instance\n * @return {number} The next position\n */\nexport const skip8 = decoder => decoder.pos++\n\n/**\n * Read one byte as unsigned integer.\n * @function\n * @param {Decoder} decoder The decoder instance\n * @return {number} Unsigned 8-bit integer\n */\nexport const readUint8 = decoder => decoder.arr[decoder.pos++]\n\n/**\n * Read 2 bytes as unsigned integer.\n *\n * @function\n * @param {Decoder} decoder\n * @return {number} An unsigned integer.\n */\nexport const readUint16 = decoder => {\n const uint =\n decoder.arr[decoder.pos] +\n (decoder.arr[decoder.pos + 1] << 8)\n decoder.pos += 2\n return uint\n}\n\n/**\n * Read 4 bytes as unsigned integer.\n *\n * @function\n * @param {Decoder} decoder\n * @return {number} An unsigned integer.\n */\nexport const readUint32 = decoder => {\n const uint =\n (decoder.arr[decoder.pos] +\n (decoder.arr[decoder.pos + 1] << 8) +\n (decoder.arr[decoder.pos + 2] << 16) +\n (decoder.arr[decoder.pos + 3] << 24)) >>> 0\n decoder.pos += 4\n return uint\n}\n\n/**\n * Read 4 bytes as unsigned integer in big endian order.\n * (most significant byte first)\n *\n * @function\n * @param {Decoder} decoder\n * @return {number} An unsigned integer.\n */\nexport const readUint32BigEndian = decoder => {\n const uint =\n (decoder.arr[decoder.pos + 3] +\n (decoder.arr[decoder.pos + 2] << 8) +\n (decoder.arr[decoder.pos + 1] << 16) +\n (decoder.arr[decoder.pos] << 24)) >>> 0\n decoder.pos += 4\n return uint\n}\n\n/**\n * Look ahead without incrementing the position\n * to the next byte and read it as unsigned integer.\n *\n * @function\n * @param {Decoder} decoder\n * @return {number} An unsigned integer.\n */\nexport const peekUint8 = decoder => decoder.arr[decoder.pos]\n\n/**\n * Look ahead without incrementing the position\n * to the next byte and read it as unsigned integer.\n *\n * @function\n * @param {Decoder} decoder\n * @return {number} An unsigned integer.\n */\nexport const peekUint16 = decoder =>\n decoder.arr[decoder.pos] +\n (decoder.arr[decoder.pos + 1] << 8)\n\n/**\n * Look ahead without incrementing the position\n * to the next byte and read it as unsigned integer.\n *\n * @function\n * @param {Decoder} decoder\n * @return {number} An unsigned integer.\n */\nexport const peekUint32 = decoder => (\n decoder.arr[decoder.pos] +\n (decoder.arr[decoder.pos + 1] << 8) +\n (decoder.arr[decoder.pos + 2] << 16) +\n (decoder.arr[decoder.pos + 3] << 24)\n) >>> 0\n\n/**\n * Read unsigned integer (32bit) with variable length.\n * 1/8th of the storage is used as encoding overhead.\n * * numbers < 2^7 is stored in one bytlength\n * * numbers < 2^14 is stored in two bylength\n *\n * @function\n * @param {Decoder} decoder\n * @return {number} An unsigned integer.length\n */\nexport const readVarUint = decoder => {\n let num = 0\n let mult = 1\n const len = decoder.arr.length\n while (decoder.pos < len) {\n const r = decoder.arr[decoder.pos++]\n // num = num | ((r & binary.BITS7) << len)\n num = num + (r & binary.BITS7) * mult // shift $r << (7*#iterations) and add it to num\n mult *= 128 // next iteration, shift 7 \"more\" to the left\n if (r < binary.BIT8) {\n return num\n }\n /* c8 ignore start */\n if (num > number.MAX_SAFE_INTEGER) {\n throw errorIntegerOutOfRange\n }\n /* c8 ignore stop */\n }\n throw errorUnexpectedEndOfArray\n}\n\n/**\n * Read signed integer (32bit) with variable length.\n * 1/8th of the storage is used as encoding overhead.\n * * numbers < 2^7 is stored in one bytlength\n * * numbers < 2^14 is stored in two bylength\n * @todo This should probably create the inverse ~num if number is negative - but this would be a breaking change.\n *\n * @function\n * @param {Decoder} decoder\n * @return {number} An unsigned integer.length\n */\nexport const readVarInt = decoder => {\n let r = decoder.arr[decoder.pos++]\n let num = r & binary.BITS6\n let mult = 64\n const sign = (r & binary.BIT7) > 0 ? -1 : 1\n if ((r & binary.BIT8) === 0) {\n // don't continue reading\n return sign * num\n }\n const len = decoder.arr.length\n while (decoder.pos < len) {\n r = decoder.arr[decoder.pos++]\n // num = num | ((r & binary.BITS7) << len)\n num = num + (r & binary.BITS7) * mult\n mult *= 128\n if (r < binary.BIT8) {\n return sign * num\n }\n /* c8 ignore start */\n if (num > number.MAX_SAFE_INTEGER) {\n throw errorIntegerOutOfRange\n }\n /* c8 ignore stop */\n }\n throw errorUnexpectedEndOfArray\n}\n\n/**\n * Look ahead and read varUint without incrementing position\n *\n * @function\n * @param {Decoder} decoder\n * @return {number}\n */\nexport const peekVarUint = decoder => {\n const pos = decoder.pos\n const s = readVarUint(decoder)\n decoder.pos = pos\n return s\n}\n\n/**\n * Look ahead and read varUint without incrementing position\n *\n * @function\n * @param {Decoder} decoder\n * @return {number}\n */\nexport const peekVarInt = decoder => {\n const pos = decoder.pos\n const s = readVarInt(decoder)\n decoder.pos = pos\n return s\n}\n\n/**\n * We don't test this function anymore as we use native decoding/encoding by default now.\n * Better not modify this anymore..\n *\n * Transforming utf8 to a string is pretty expensive. The code performs 10x better\n * when String.fromCodePoint is fed with all characters as arguments.\n * But most environments have a maximum number of arguments per functions.\n * For effiency reasons we apply a maximum of 10000 characters at once.\n *\n * @function\n * @param {Decoder} decoder\n * @return {String} The read String.\n */\n/* c8 ignore start */\nexport const _readVarStringPolyfill = decoder => {\n let remainingLen = readVarUint(decoder)\n if (remainingLen === 0) {\n return ''\n } else {\n let encodedString = String.fromCodePoint(readUint8(decoder)) // remember to decrease remainingLen\n if (--remainingLen < 100) { // do not create a Uint8Array for small strings\n while (remainingLen--) {\n encodedString += String.fromCodePoint(readUint8(decoder))\n }\n } else {\n while (remainingLen > 0) {\n const nextLen = remainingLen < 10000 ? remainingLen : 10000\n // this is dangerous, we create a fresh array view from the existing buffer\n const bytes = decoder.arr.subarray(decoder.pos, decoder.pos + nextLen)\n decoder.pos += nextLen\n // Starting with ES5.1 we can supply a generic array-like object as arguments\n encodedString += String.fromCodePoint.apply(null, /** @type {any} */ (bytes))\n remainingLen -= nextLen\n }\n }\n return decodeURIComponent(escape(encodedString))\n }\n}\n/* c8 ignore stop */\n\n/**\n * @function\n * @param {Decoder} decoder\n * @return {String} The read String\n */\nexport const _readVarStringNative = decoder =>\n /** @type any */ (string.utf8TextDecoder).decode(readVarUint8Array(decoder))\n\n/**\n * Read string of variable length\n * * varUint is used to store the length of the string\n *\n * @function\n * @param {Decoder} decoder\n * @return {String} The read String\n *\n */\n/* c8 ignore next */\nexport const readVarString = string.utf8TextDecoder ? _readVarStringNative : _readVarStringPolyfill\n\n/**\n * @param {Decoder} decoder\n * @return {Uint8Array}\n */\nexport const readTerminatedUint8Array = decoder => {\n const encoder = encoding.createEncoder()\n let b\n while (true) {\n b = readUint8(decoder)\n if (b === 0) {\n return encoding.toUint8Array(encoder)\n }\n if (b === 1) {\n b = readUint8(decoder)\n }\n encoding.write(encoder, b)\n }\n}\n\n/**\n * @param {Decoder} decoder\n * @return {string}\n */\nexport const readTerminatedString = decoder => string.decodeUtf8(readTerminatedUint8Array(decoder))\n\n/**\n * Look ahead and read varString without incrementing position\n *\n * @function\n * @param {Decoder} decoder\n * @return {string}\n */\nexport const peekVarString = decoder => {\n const pos = decoder.pos\n const s = readVarString(decoder)\n decoder.pos = pos\n return s\n}\n\n/**\n * @param {Decoder} decoder\n * @param {number} len\n * @return {DataView}\n */\nexport const readFromDataView = (decoder, len) => {\n const dv = new DataView(decoder.arr.buffer, decoder.arr.byteOffset + decoder.pos, len)\n decoder.pos += len\n return dv\n}\n\n/**\n * @param {Decoder} decoder\n */\nexport const readFloat32 = decoder => readFromDataView(decoder, 4).getFloat32(0, false)\n\n/**\n * @param {Decoder} decoder\n */\nexport const readFloat64 = decoder => readFromDataView(decoder, 8).getFloat64(0, false)\n\n/**\n * @param {Decoder} decoder\n */\nexport const readBigInt64 = decoder => /** @type {any} */ (readFromDataView(decoder, 8)).getBigInt64(0, false)\n\n/**\n * @param {Decoder} decoder\n */\nexport const readBigUint64 = decoder => /** @type {any} */ (readFromDataView(decoder, 8)).getBigUint64(0, false)\n\n/**\n * @type {Array<function(Decoder):any>}\n */\nconst readAnyLookupTable = [\n decoder => undefined, // CASE 127: undefined\n decoder => null, // CASE 126: null\n readVarInt, // CASE 125: integer\n readFloat32, // CASE 124: float32\n readFloat64, // CASE 123: float64\n readBigInt64, // CASE 122: bigint\n decoder => false, // CASE 121: boolean (false)\n decoder => true, // CASE 120: boolean (true)\n readVarString, // CASE 119: string\n decoder => { // CASE 118: object<string,any>\n const len = readVarUint(decoder)\n /**\n * @type {Object<string,any>}\n */\n const obj = {}\n for (let i = 0; i < len; i++) {\n const key = readVarString(decoder)\n obj[key] = readAny(decoder)\n }\n return obj\n },\n decoder => { // CASE 117: array<any>\n const len = readVarUint(decoder)\n const arr = []\n for (let i = 0; i < len; i++) {\n arr.push(readAny(decoder))\n }\n return arr\n },\n readVarUint8Array // CASE 116: Uint8Array\n]\n\n/**\n * @param {Decoder} decoder\n */\nexport const readAny = decoder => readAnyLookupTable[127 - readUint8(decoder)](decoder)\n\n/**\n * T must not be null.\n *\n * @template T\n */\nexport class RleDecoder extends Decoder {\n /**\n * @param {Uint8Array} uint8Array\n * @param {function(Decoder):T} reader\n */\n constructor (uint8Array, reader) {\n super(uint8Array)\n /**\n * The reader\n */\n this.reader = reader\n /**\n * Current state\n * @type {T|null}\n */\n this.s = null\n this.count = 0\n }\n\n read () {\n if (this.count === 0) {\n this.s = this.reader(this)\n if (hasContent(this)) {\n this.count = readVarUint(this) + 1 // see encoder implementation for the reason why this is incremented\n } else {\n this.count = -1 // read the current value forever\n }\n }\n this.count--\n return /** @type {T} */ (this.s)\n }\n}\n\nexport class IntDiffDecoder extends Decoder {\n /**\n * @param {Uint8Array} uint8Array\n * @param {number} start\n */\n constructor (uint8Array, start) {\n super(uint8Array)\n /**\n * Current state\n * @type {number}\n */\n this.s = start\n }\n\n /**\n * @return {number}\n */\n read () {\n this.s += readVarInt(this)\n return this.s\n }\n}\n\nexport class RleIntDiffDecoder extends Decoder {\n /**\n * @param {Uint8Array} uint8Array\n * @param {number} start\n */\n constructor (uint8Array, start) {\n super(uint8Array)\n /**\n * Current state\n * @type {number}\n */\n this.s = start\n this.count = 0\n }\n\n /**\n * @return {number}\n */\n read () {\n if (this.count === 0) {\n this.s += readVarInt(this)\n if (hasContent(this)) {\n this.count = readVarUint(this) + 1 // see encoder implementation for the reason why this is incremented\n } else {\n this.count = -1 // read the current value forever\n }\n }\n this.count--\n return /** @type {number} */ (this.s)\n }\n}\n\nexport class UintOptRleDecoder extends Decoder {\n /**\n * @param {Uint8Array} uint8Array\n */\n constructor (uint8Array) {\n super(uint8Array)\n /**\n * @type {number}\n */\n this.s = 0\n this.count = 0\n }\n\n read () {\n if (this.count === 0) {\n this.s = readVarInt(this)\n // if the sign is negative, we read the count too, otherwise count is 1\n const isNegative = math.isNegativeZero(this.s)\n this.count = 1\n if (isNegative) {\n this.s = -this.s\n this.count = readVarUint(this) + 2\n }\n }\n this.count--\n return /** @type {number} */ (this.s)\n }\n}\n\nexport class IncUintOptRleDecoder extends Decoder {\n /**\n * @param {Uint8Array} uint8Array\n */\n constructor (uint8Array) {\n super(uint8Array)\n /**\n * @type {number}\n */\n this.s = 0\n this.count = 0\n }\n\n read () {\n if (this.count === 0) {\n this.s = readVarInt(this)\n // if the sign is negative, we read the count too, otherwise count is 1\n const isNegative = math.isNegativeZero(this.s)\n this.count = 1\n if (isNegative) {\n this.s = -this.s\n this.count = readVarUint(this) + 2\n }\n }\n this.count--\n return /** @type {number} */ (this.s++)\n }\n}\n\nexport class IntDiffOptRleDecoder extends Decoder {\n /**\n * @param {Uint8Array} uint8Array\n */\n constructor (uint8Array) {\n super(uint8Array)\n /**\n * @type {number}\n */\n this.s = 0\n this.count = 0\n this.diff = 0\n }\n\n /**\n * @return {number}\n */\n read () {\n if (this.count === 0) {\n const diff = readVarInt(this)\n // if the first bit is set, we read more data\n const hasCount = diff & 1\n this.diff = math.floor(diff / 2) // shift >> 1\n this.count = 1\n if (hasCount) {\n this.count = readVarUint(this) + 2\n }\n }\n this.s += this.diff\n this.count--\n return this.s\n }\n}\n\nexport class StringDecoder {\n /**\n * @param {Uint8Array} uint8Array\n */\n constructor (uint8Array) {\n this.decoder = new UintOptRleDecoder(uint8Array)\n this.str = readVarString(this.decoder)\n /**\n * @type {number}\n */\n this.spos = 0\n }\n\n /**\n * @return {string}\n */\n read () {\n const end = this.spos + this.decoder.read()\n const res = this.str.slice(this.spos, end)\n this.spos = end\n return res\n }\n}\n",null,null,null,null],"names":["binary.BITS7","binary.BIT8","math.floor","string.utf8TextEncoder","string.encodeUtf8","math.min","math.max","error.create","number.MAX_SAFE_INTEGER","string.utf8TextDecoder","encoding.writeVarUint","encoding.writeVarString","decoding.readVarUint","decoding.readVarString"],"mappings":"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","x_google_ignoreList":[0,1,2,3,4,5,6]} | ||
| {"version":3,"file":"hocuspocus-common.esm.js","names":["isNaN","binary.BITS31","binary.BITS32","math.floor","binary.BITS7","binary.BIT8","math.floor","string.encodeUtf8","string.utf8TextEncoder","math.min","math.max","error.create","binary.BITS7","binary.BIT8","number.MAX_SAFE_INTEGER","string.utf8TextDecoder","decoding.readVarUint","decoding.readVarString"],"sources":["../../../node_modules/lib0/math.js","../../../node_modules/lib0/binary.js","../../../node_modules/lib0/number.js","../../../node_modules/lib0/string.js","../../../node_modules/lib0/encoding.js","../../../node_modules/lib0/error.js","../../../node_modules/lib0/decoding.js","../src/auth.ts","../src/CloseEvents.ts","../src/awarenessStatesToArray.ts","../src/types.ts"],"sourcesContent":["/**\n * Common Math expressions.\n *\n * @module math\n */\n\nexport const floor = Math.floor\nexport const ceil = Math.ceil\nexport const abs = Math.abs\nexport const imul = Math.imul\nexport const round = Math.round\nexport const log10 = Math.log10\nexport const log2 = Math.log2\nexport const log = Math.log\nexport const sqrt = Math.sqrt\n\n/**\n * @function\n * @param {number} a\n * @param {number} b\n * @return {number} The sum of a and b\n */\nexport const add = (a, b) => a + b\n\n/**\n * @function\n * @param {number} a\n * @param {number} b\n * @return {number} The smaller element of a and b\n */\nexport const min = (a, b) => a < b ? a : b\n\n/**\n * @function\n * @param {number} a\n * @param {number} b\n * @return {number} The bigger element of a and b\n */\nexport const max = (a, b) => a > b ? a : b\n\nexport const isNaN = Number.isNaN\n\nexport const pow = Math.pow\n/**\n * Base 10 exponential function. Returns the value of 10 raised to the power of pow.\n *\n * @param {number} exp\n * @return {number}\n */\nexport const exp10 = exp => Math.pow(10, exp)\n\nexport const sign = Math.sign\n\n/**\n * @param {number} n\n * @return {boolean} Wether n is negative. This function also differentiates between -0 and +0\n */\nexport const isNegativeZero = n => n !== 0 ? n < 0 : 1 / n < 0\n","/* eslint-env browser */\n\n/**\n * Binary data constants.\n *\n * @module binary\n */\n\n/**\n * n-th bit activated.\n *\n * @type {number}\n */\nexport const BIT1 = 1\nexport const BIT2 = 2\nexport const BIT3 = 4\nexport const BIT4 = 8\nexport const BIT5 = 16\nexport const BIT6 = 32\nexport const BIT7 = 64\nexport const BIT8 = 128\nexport const BIT9 = 256\nexport const BIT10 = 512\nexport const BIT11 = 1024\nexport const BIT12 = 2048\nexport const BIT13 = 4096\nexport const BIT14 = 8192\nexport const BIT15 = 16384\nexport const BIT16 = 32768\nexport const BIT17 = 65536\nexport const BIT18 = 1 << 17\nexport const BIT19 = 1 << 18\nexport const BIT20 = 1 << 19\nexport const BIT21 = 1 << 20\nexport const BIT22 = 1 << 21\nexport const BIT23 = 1 << 22\nexport const BIT24 = 1 << 23\nexport const BIT25 = 1 << 24\nexport const BIT26 = 1 << 25\nexport const BIT27 = 1 << 26\nexport const BIT28 = 1 << 27\nexport const BIT29 = 1 << 28\nexport const BIT30 = 1 << 29\nexport const BIT31 = 1 << 30\nexport const BIT32 = 1 << 31\n\n/**\n * First n bits activated.\n *\n * @type {number}\n */\nexport const BITS0 = 0\nexport const BITS1 = 1\nexport const BITS2 = 3\nexport const BITS3 = 7\nexport const BITS4 = 15\nexport const BITS5 = 31\nexport const BITS6 = 63\nexport const BITS7 = 127\nexport const BITS8 = 255\nexport const BITS9 = 511\nexport const BITS10 = 1023\nexport const BITS11 = 2047\nexport const BITS12 = 4095\nexport const BITS13 = 8191\nexport const BITS14 = 16383\nexport const BITS15 = 32767\nexport const BITS16 = 65535\nexport const BITS17 = BIT18 - 1\nexport const BITS18 = BIT19 - 1\nexport const BITS19 = BIT20 - 1\nexport const BITS20 = BIT21 - 1\nexport const BITS21 = BIT22 - 1\nexport const BITS22 = BIT23 - 1\nexport const BITS23 = BIT24 - 1\nexport const BITS24 = BIT25 - 1\nexport const BITS25 = BIT26 - 1\nexport const BITS26 = BIT27 - 1\nexport const BITS27 = BIT28 - 1\nexport const BITS28 = BIT29 - 1\nexport const BITS29 = BIT30 - 1\nexport const BITS30 = BIT31 - 1\n/**\n * @type {number}\n */\nexport const BITS31 = 0x7FFFFFFF\n/**\n * @type {number}\n */\nexport const BITS32 = 0xFFFFFFFF\n","/**\n * Utility helpers for working with numbers.\n *\n * @module number\n */\n\nimport * as math from './math.js'\nimport * as binary from './binary.js'\n\nexport const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER\nexport const MIN_SAFE_INTEGER = Number.MIN_SAFE_INTEGER\n\nexport const LOWEST_INT32 = 1 << 31\nexport const HIGHEST_INT32 = binary.BITS31\nexport const HIGHEST_UINT32 = binary.BITS32\n\n/* c8 ignore next */\nexport const isInteger = Number.isInteger || (num => typeof num === 'number' && isFinite(num) && math.floor(num) === num)\nexport const isNaN = Number.isNaN\nexport const parseInt = Number.parseInt\n\n/**\n * Count the number of \"1\" bits in an unsigned 32bit number.\n *\n * Super fun bitcount algorithm by Brian Kernighan.\n *\n * @param {number} n\n */\nexport const countBits = n => {\n n &= binary.BITS32\n let count = 0\n while (n) {\n n &= (n - 1)\n count++\n }\n return count\n}\n","import * as array from './array.js'\n\n/**\n * Utility module to work with strings.\n *\n * @module string\n */\n\nexport const fromCharCode = String.fromCharCode\nexport const fromCodePoint = String.fromCodePoint\n\n/**\n * The largest utf16 character.\n * Corresponds to Uint8Array([255, 255]) or charcodeof(2x2^8)\n */\nexport const MAX_UTF16_CHARACTER = fromCharCode(65535)\n\n/**\n * @param {string} s\n * @return {string}\n */\nconst toLowerCase = s => s.toLowerCase()\n\nconst trimLeftRegex = /^\\s*/g\n\n/**\n * @param {string} s\n * @return {string}\n */\nexport const trimLeft = s => s.replace(trimLeftRegex, '')\n\nconst fromCamelCaseRegex = /([A-Z])/g\n\n/**\n * @param {string} s\n * @param {string} separator\n * @return {string}\n */\nexport const fromCamelCase = (s, separator) => trimLeft(s.replace(fromCamelCaseRegex, match => `${separator}${toLowerCase(match)}`))\n\n/**\n * Compute the utf8ByteLength\n * @param {string} str\n * @return {number}\n */\nexport const utf8ByteLength = str => unescape(encodeURIComponent(str)).length\n\n/**\n * @param {string} str\n * @return {Uint8Array}\n */\nexport const _encodeUtf8Polyfill = str => {\n const encodedString = unescape(encodeURIComponent(str))\n const len = encodedString.length\n const buf = new Uint8Array(len)\n for (let i = 0; i < len; i++) {\n buf[i] = /** @type {number} */ (encodedString.codePointAt(i))\n }\n return buf\n}\n\n/* c8 ignore next */\nexport const utf8TextEncoder = /** @type {TextEncoder} */ (typeof TextEncoder !== 'undefined' ? new TextEncoder() : null)\n\n/**\n * @param {string} str\n * @return {Uint8Array}\n */\nexport const _encodeUtf8Native = str => utf8TextEncoder.encode(str)\n\n/**\n * @param {string} str\n * @return {Uint8Array}\n */\n/* c8 ignore next */\nexport const encodeUtf8 = utf8TextEncoder ? _encodeUtf8Native : _encodeUtf8Polyfill\n\n/**\n * @param {Uint8Array} buf\n * @return {string}\n */\nexport const _decodeUtf8Polyfill = buf => {\n let remainingLen = buf.length\n let encodedString = ''\n let bufPos = 0\n while (remainingLen > 0) {\n const nextLen = remainingLen < 10000 ? remainingLen : 10000\n const bytes = buf.subarray(bufPos, bufPos + nextLen)\n bufPos += nextLen\n // Starting with ES5.1 we can supply a generic array-like object as arguments\n encodedString += String.fromCodePoint.apply(null, /** @type {any} */ (bytes))\n remainingLen -= nextLen\n }\n return decodeURIComponent(escape(encodedString))\n}\n\n/* c8 ignore next */\nexport let utf8TextDecoder = typeof TextDecoder === 'undefined' ? null : new TextDecoder('utf-8', { fatal: true, ignoreBOM: true })\n\n/* c8 ignore start */\nif (utf8TextDecoder && utf8TextDecoder.decode(new Uint8Array()).length === 1) {\n // Safari doesn't handle BOM correctly.\n // This fixes a bug in Safari 13.0.5 where it produces a BOM the first time it is called.\n // utf8TextDecoder.decode(new Uint8Array()).length === 1 on the first call and\n // utf8TextDecoder.decode(new Uint8Array()).length === 1 on the second call\n // Another issue is that from then on no BOM chars are recognized anymore\n /* c8 ignore next */\n utf8TextDecoder = null\n}\n/* c8 ignore stop */\n\n/**\n * @param {Uint8Array} buf\n * @return {string}\n */\nexport const _decodeUtf8Native = buf => /** @type {TextDecoder} */ (utf8TextDecoder).decode(buf)\n\n/**\n * @param {Uint8Array} buf\n * @return {string}\n */\n/* c8 ignore next */\nexport const decodeUtf8 = utf8TextDecoder ? _decodeUtf8Native : _decodeUtf8Polyfill\n\n/**\n * @param {string} str The initial string\n * @param {number} index Starting position\n * @param {number} remove Number of characters to remove\n * @param {string} insert New content to insert\n */\nexport const splice = (str, index, remove, insert = '') => str.slice(0, index) + insert + str.slice(index + remove)\n\n/**\n * @param {string} source\n * @param {number} n\n */\nexport const repeat = (source, n) => array.unfold(n, () => source).join('')\n","/**\n * Efficient schema-less binary encoding with support for variable length encoding.\n *\n * Use [lib0/encoding] with [lib0/decoding]. Every encoding function has a corresponding decoding function.\n *\n * Encodes numbers in little-endian order (least to most significant byte order)\n * and is compatible with Golang's binary encoding (https://golang.org/pkg/encoding/binary/)\n * which is also used in Protocol Buffers.\n *\n * ```js\n * // encoding step\n * const encoder = encoding.createEncoder()\n * encoding.writeVarUint(encoder, 256)\n * encoding.writeVarString(encoder, 'Hello world!')\n * const buf = encoding.toUint8Array(encoder)\n * ```\n *\n * ```js\n * // decoding step\n * const decoder = decoding.createDecoder(buf)\n * decoding.readVarUint(decoder) // => 256\n * decoding.readVarString(decoder) // => 'Hello world!'\n * decoding.hasContent(decoder) // => false - all data is read\n * ```\n *\n * @module encoding\n */\n\nimport * as math from './math.js'\nimport * as number from './number.js'\nimport * as binary from './binary.js'\nimport * as string from './string.js'\nimport * as array from './array.js'\n\n/**\n * A BinaryEncoder handles the encoding to an Uint8Array.\n */\nexport class Encoder {\n constructor () {\n this.cpos = 0\n this.cbuf = new Uint8Array(100)\n /**\n * @type {Array<Uint8Array>}\n */\n this.bufs = []\n }\n}\n\n/**\n * @function\n * @return {Encoder}\n */\nexport const createEncoder = () => new Encoder()\n\n/**\n * @param {function(Encoder):void} f\n */\nexport const encode = (f) => {\n const encoder = createEncoder()\n f(encoder)\n return toUint8Array(encoder)\n}\n\n/**\n * The current length of the encoded data.\n *\n * @function\n * @param {Encoder} encoder\n * @return {number}\n */\nexport const length = encoder => {\n let len = encoder.cpos\n for (let i = 0; i < encoder.bufs.length; i++) {\n len += encoder.bufs[i].length\n }\n return len\n}\n\n/**\n * Check whether encoder is empty.\n *\n * @function\n * @param {Encoder} encoder\n * @return {boolean}\n */\nexport const hasContent = encoder => encoder.cpos > 0 || encoder.bufs.length > 0\n\n/**\n * Transform to Uint8Array.\n *\n * @function\n * @param {Encoder} encoder\n * @return {Uint8Array} The created ArrayBuffer.\n */\nexport const toUint8Array = encoder => {\n const uint8arr = new Uint8Array(length(encoder))\n let curPos = 0\n for (let i = 0; i < encoder.bufs.length; i++) {\n const d = encoder.bufs[i]\n uint8arr.set(d, curPos)\n curPos += d.length\n }\n uint8arr.set(new Uint8Array(encoder.cbuf.buffer, 0, encoder.cpos), curPos)\n return uint8arr\n}\n\n/**\n * Verify that it is possible to write `len` bytes wtihout checking. If\n * necessary, a new Buffer with the required length is attached.\n *\n * @param {Encoder} encoder\n * @param {number} len\n */\nexport const verifyLen = (encoder, len) => {\n const bufferLen = encoder.cbuf.length\n if (bufferLen - encoder.cpos < len) {\n encoder.bufs.push(new Uint8Array(encoder.cbuf.buffer, 0, encoder.cpos))\n encoder.cbuf = new Uint8Array(math.max(bufferLen, len) * 2)\n encoder.cpos = 0\n }\n}\n\n/**\n * Write one byte to the encoder.\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} num The byte that is to be encoded.\n */\nexport const write = (encoder, num) => {\n const bufferLen = encoder.cbuf.length\n if (encoder.cpos === bufferLen) {\n encoder.bufs.push(encoder.cbuf)\n encoder.cbuf = new Uint8Array(bufferLen * 2)\n encoder.cpos = 0\n }\n encoder.cbuf[encoder.cpos++] = num\n}\n\n/**\n * Write one byte at a specific position.\n * Position must already be written (i.e. encoder.length > pos)\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} pos Position to which to write data\n * @param {number} num Unsigned 8-bit integer\n */\nexport const set = (encoder, pos, num) => {\n let buffer = null\n // iterate all buffers and adjust position\n for (let i = 0; i < encoder.bufs.length && buffer === null; i++) {\n const b = encoder.bufs[i]\n if (pos < b.length) {\n buffer = b // found buffer\n } else {\n pos -= b.length\n }\n }\n if (buffer === null) {\n // use current buffer\n buffer = encoder.cbuf\n }\n buffer[pos] = num\n}\n\n/**\n * Write one byte as an unsigned integer.\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} num The number that is to be encoded.\n */\nexport const writeUint8 = write\n\n/**\n * Write one byte as an unsigned Integer at a specific location.\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} pos The location where the data will be written.\n * @param {number} num The number that is to be encoded.\n */\nexport const setUint8 = set\n\n/**\n * Write two bytes as an unsigned integer.\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} num The number that is to be encoded.\n */\nexport const writeUint16 = (encoder, num) => {\n write(encoder, num & binary.BITS8)\n write(encoder, (num >>> 8) & binary.BITS8)\n}\n/**\n * Write two bytes as an unsigned integer at a specific location.\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} pos The location where the data will be written.\n * @param {number} num The number that is to be encoded.\n */\nexport const setUint16 = (encoder, pos, num) => {\n set(encoder, pos, num & binary.BITS8)\n set(encoder, pos + 1, (num >>> 8) & binary.BITS8)\n}\n\n/**\n * Write two bytes as an unsigned integer\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} num The number that is to be encoded.\n */\nexport const writeUint32 = (encoder, num) => {\n for (let i = 0; i < 4; i++) {\n write(encoder, num & binary.BITS8)\n num >>>= 8\n }\n}\n\n/**\n * Write two bytes as an unsigned integer in big endian order.\n * (most significant byte first)\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} num The number that is to be encoded.\n */\nexport const writeUint32BigEndian = (encoder, num) => {\n for (let i = 3; i >= 0; i--) {\n write(encoder, (num >>> (8 * i)) & binary.BITS8)\n }\n}\n\n/**\n * Write two bytes as an unsigned integer at a specific location.\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} pos The location where the data will be written.\n * @param {number} num The number that is to be encoded.\n */\nexport const setUint32 = (encoder, pos, num) => {\n for (let i = 0; i < 4; i++) {\n set(encoder, pos + i, num & binary.BITS8)\n num >>>= 8\n }\n}\n\n/**\n * Write a variable length unsigned integer. Max encodable integer is 2^53.\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} num The number that is to be encoded.\n */\nexport const writeVarUint = (encoder, num) => {\n while (num > binary.BITS7) {\n write(encoder, binary.BIT8 | (binary.BITS7 & num))\n num = math.floor(num / 128) // shift >>> 7\n }\n write(encoder, binary.BITS7 & num)\n}\n\n/**\n * Write a variable length integer.\n *\n * We use the 7th bit instead for signaling that this is a negative number.\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} num The number that is to be encoded.\n */\nexport const writeVarInt = (encoder, num) => {\n const isNegative = math.isNegativeZero(num)\n if (isNegative) {\n num = -num\n }\n // |- whether to continue reading |- whether is negative |- number\n write(encoder, (num > binary.BITS6 ? binary.BIT8 : 0) | (isNegative ? binary.BIT7 : 0) | (binary.BITS6 & num))\n num = math.floor(num / 64) // shift >>> 6\n // We don't need to consider the case of num === 0 so we can use a different\n // pattern here than above.\n while (num > 0) {\n write(encoder, (num > binary.BITS7 ? binary.BIT8 : 0) | (binary.BITS7 & num))\n num = math.floor(num / 128) // shift >>> 7\n }\n}\n\n/**\n * A cache to store strings temporarily\n */\nconst _strBuffer = new Uint8Array(30000)\nconst _maxStrBSize = _strBuffer.length / 3\n\n/**\n * Write a variable length string.\n *\n * @function\n * @param {Encoder} encoder\n * @param {String} str The string that is to be encoded.\n */\nexport const _writeVarStringNative = (encoder, str) => {\n if (str.length < _maxStrBSize) {\n // We can encode the string into the existing buffer\n /* c8 ignore next */\n const written = string.utf8TextEncoder.encodeInto(str, _strBuffer).written || 0\n writeVarUint(encoder, written)\n for (let i = 0; i < written; i++) {\n write(encoder, _strBuffer[i])\n }\n } else {\n writeVarUint8Array(encoder, string.encodeUtf8(str))\n }\n}\n\n/**\n * Write a variable length string.\n *\n * @function\n * @param {Encoder} encoder\n * @param {String} str The string that is to be encoded.\n */\nexport const _writeVarStringPolyfill = (encoder, str) => {\n const encodedString = unescape(encodeURIComponent(str))\n const len = encodedString.length\n writeVarUint(encoder, len)\n for (let i = 0; i < len; i++) {\n write(encoder, /** @type {number} */ (encodedString.codePointAt(i)))\n }\n}\n\n/**\n * Write a variable length string.\n *\n * @function\n * @param {Encoder} encoder\n * @param {String} str The string that is to be encoded.\n */\n/* c8 ignore next */\nexport const writeVarString = (string.utf8TextEncoder && /** @type {any} */ (string.utf8TextEncoder).encodeInto) ? _writeVarStringNative : _writeVarStringPolyfill\n\n/**\n * Write a string terminated by a special byte sequence. This is not very performant and is\n * generally discouraged. However, the resulting byte arrays are lexiographically ordered which\n * makes this a nice feature for databases.\n *\n * The string will be encoded using utf8 and then terminated and escaped using writeTerminatingUint8Array.\n *\n * @function\n * @param {Encoder} encoder\n * @param {String} str The string that is to be encoded.\n */\nexport const writeTerminatedString = (encoder, str) =>\n writeTerminatedUint8Array(encoder, string.encodeUtf8(str))\n\n/**\n * Write a terminating Uint8Array. Note that this is not performant and is generally\n * discouraged. There are few situations when this is needed.\n *\n * We use 0x0 as a terminating character. 0x1 serves as an escape character for 0x0 and 0x1.\n *\n * Example: [0,1,2] is encoded to [1,0,1,1,2,0]. 0x0, and 0x1 needed to be escaped using 0x1. Then\n * the result is terminated using the 0x0 character.\n *\n * This is basically how many systems implement null terminated strings. However, we use an escape\n * character 0x1 to avoid issues and potenial attacks on our database (if this is used as a key\n * encoder for NoSql databases).\n *\n * @function\n * @param {Encoder} encoder\n * @param {Uint8Array} buf The string that is to be encoded.\n */\nexport const writeTerminatedUint8Array = (encoder, buf) => {\n for (let i = 0; i < buf.length; i++) {\n const b = buf[i]\n if (b === 0 || b === 1) {\n write(encoder, 1)\n }\n write(encoder, buf[i])\n }\n write(encoder, 0)\n}\n\n/**\n * Write the content of another Encoder.\n *\n * @TODO: can be improved!\n * - Note: Should consider that when appending a lot of small Encoders, we should rather clone than referencing the old structure.\n * Encoders start with a rather big initial buffer.\n *\n * @function\n * @param {Encoder} encoder The enUint8Arr\n * @param {Encoder} append The BinaryEncoder to be written.\n */\nexport const writeBinaryEncoder = (encoder, append) => writeUint8Array(encoder, toUint8Array(append))\n\n/**\n * Append fixed-length Uint8Array to the encoder.\n *\n * @function\n * @param {Encoder} encoder\n * @param {Uint8Array} uint8Array\n */\nexport const writeUint8Array = (encoder, uint8Array) => {\n const bufferLen = encoder.cbuf.length\n const cpos = encoder.cpos\n const leftCopyLen = math.min(bufferLen - cpos, uint8Array.length)\n const rightCopyLen = uint8Array.length - leftCopyLen\n encoder.cbuf.set(uint8Array.subarray(0, leftCopyLen), cpos)\n encoder.cpos += leftCopyLen\n if (rightCopyLen > 0) {\n // Still something to write, write right half..\n // Append new buffer\n encoder.bufs.push(encoder.cbuf)\n // must have at least size of remaining buffer\n encoder.cbuf = new Uint8Array(math.max(bufferLen * 2, rightCopyLen))\n // copy array\n encoder.cbuf.set(uint8Array.subarray(leftCopyLen))\n encoder.cpos = rightCopyLen\n }\n}\n\n/**\n * Append an Uint8Array to Encoder.\n *\n * @function\n * @param {Encoder} encoder\n * @param {Uint8Array} uint8Array\n */\nexport const writeVarUint8Array = (encoder, uint8Array) => {\n writeVarUint(encoder, uint8Array.byteLength)\n writeUint8Array(encoder, uint8Array)\n}\n\n/**\n * Create an DataView of the next `len` bytes. Use it to write data after\n * calling this function.\n *\n * ```js\n * // write float32 using DataView\n * const dv = writeOnDataView(encoder, 4)\n * dv.setFloat32(0, 1.1)\n * // read float32 using DataView\n * const dv = readFromDataView(encoder, 4)\n * dv.getFloat32(0) // => 1.100000023841858 (leaving it to the reader to find out why this is the correct result)\n * ```\n *\n * @param {Encoder} encoder\n * @param {number} len\n * @return {DataView}\n */\nexport const writeOnDataView = (encoder, len) => {\n verifyLen(encoder, len)\n const dview = new DataView(encoder.cbuf.buffer, encoder.cpos, len)\n encoder.cpos += len\n return dview\n}\n\n/**\n * @param {Encoder} encoder\n * @param {number} num\n */\nexport const writeFloat32 = (encoder, num) => writeOnDataView(encoder, 4).setFloat32(0, num, false)\n\n/**\n * @param {Encoder} encoder\n * @param {number} num\n */\nexport const writeFloat64 = (encoder, num) => writeOnDataView(encoder, 8).setFloat64(0, num, false)\n\n/**\n * @param {Encoder} encoder\n * @param {bigint} num\n */\nexport const writeBigInt64 = (encoder, num) => /** @type {any} */ (writeOnDataView(encoder, 8)).setBigInt64(0, num, false)\n\n/**\n * @param {Encoder} encoder\n * @param {bigint} num\n */\nexport const writeBigUint64 = (encoder, num) => /** @type {any} */ (writeOnDataView(encoder, 8)).setBigUint64(0, num, false)\n\nconst floatTestBed = new DataView(new ArrayBuffer(4))\n/**\n * Check if a number can be encoded as a 32 bit float.\n *\n * @param {number} num\n * @return {boolean}\n */\nconst isFloat32 = num => {\n floatTestBed.setFloat32(0, num)\n return floatTestBed.getFloat32(0) === num\n}\n\n/**\n * Encode data with efficient binary format.\n *\n * Differences to JSON:\n * • Transforms data to a binary format (not to a string)\n * • Encodes undefined, NaN, and ArrayBuffer (these can't be represented in JSON)\n * • Numbers are efficiently encoded either as a variable length integer, as a\n * 32 bit float, as a 64 bit float, or as a 64 bit bigint.\n *\n * Encoding table:\n *\n * | Data Type | Prefix | Encoding Method | Comment |\n * | ------------------- | -------- | ------------------ | ------- |\n * | undefined | 127 | | Functions, symbol, and everything that cannot be identified is encoded as undefined |\n * | null | 126 | | |\n * | integer | 125 | writeVarInt | Only encodes 32 bit signed integers |\n * | float32 | 124 | writeFloat32 | |\n * | float64 | 123 | writeFloat64 | |\n * | bigint | 122 | writeBigInt64 | |\n * | boolean (false) | 121 | | True and false are different data types so we save the following byte |\n * | boolean (true) | 120 | | - 0b01111000 so the last bit determines whether true or false |\n * | string | 119 | writeVarString | |\n * | object<string,any> | 118 | custom | Writes {length} then {length} key-value pairs |\n * | array<any> | 117 | custom | Writes {length} then {length} json values |\n * | Uint8Array | 116 | writeVarUint8Array | We use Uint8Array for any kind of binary data |\n *\n * Reasons for the decreasing prefix:\n * We need the first bit for extendability (later we may want to encode the\n * prefix with writeVarUint). The remaining 7 bits are divided as follows:\n * [0-30] the beginning of the data range is used for custom purposes\n * (defined by the function that uses this library)\n * [31-127] the end of the data range is used for data encoding by\n * lib0/encoding.js\n *\n * @param {Encoder} encoder\n * @param {undefined|null|number|bigint|boolean|string|Object<string,any>|Array<any>|Uint8Array} data\n */\nexport const writeAny = (encoder, data) => {\n switch (typeof data) {\n case 'string':\n // TYPE 119: STRING\n write(encoder, 119)\n writeVarString(encoder, data)\n break\n case 'number':\n if (number.isInteger(data) && math.abs(data) <= binary.BITS31) {\n // TYPE 125: INTEGER\n write(encoder, 125)\n writeVarInt(encoder, data)\n } else if (isFloat32(data)) {\n // TYPE 124: FLOAT32\n write(encoder, 124)\n writeFloat32(encoder, data)\n } else {\n // TYPE 123: FLOAT64\n write(encoder, 123)\n writeFloat64(encoder, data)\n }\n break\n case 'bigint':\n // TYPE 122: BigInt\n write(encoder, 122)\n writeBigInt64(encoder, data)\n break\n case 'object':\n if (data === null) {\n // TYPE 126: null\n write(encoder, 126)\n } else if (array.isArray(data)) {\n // TYPE 117: Array\n write(encoder, 117)\n writeVarUint(encoder, data.length)\n for (let i = 0; i < data.length; i++) {\n writeAny(encoder, data[i])\n }\n } else if (data instanceof Uint8Array) {\n // TYPE 116: ArrayBuffer\n write(encoder, 116)\n writeVarUint8Array(encoder, data)\n } else {\n // TYPE 118: Object\n write(encoder, 118)\n const keys = Object.keys(data)\n writeVarUint(encoder, keys.length)\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i]\n writeVarString(encoder, key)\n writeAny(encoder, data[key])\n }\n }\n break\n case 'boolean':\n // TYPE 120/121: boolean (true/false)\n write(encoder, data ? 120 : 121)\n break\n default:\n // TYPE 127: undefined\n write(encoder, 127)\n }\n}\n\n/**\n * Now come a few stateful encoder that have their own classes.\n */\n\n/**\n * Basic Run Length Encoder - a basic compression implementation.\n *\n * Encodes [1,1,1,7] to [1,3,7,1] (3 times 1, 1 time 7). This encoder might do more harm than good if there are a lot of values that are not repeated.\n *\n * It was originally used for image compression. Cool .. article http://csbruce.com/cbm/transactor/pdfs/trans_v7_i06.pdf\n *\n * @note T must not be null!\n *\n * @template T\n */\nexport class RleEncoder extends Encoder {\n /**\n * @param {function(Encoder, T):void} writer\n */\n constructor (writer) {\n super()\n /**\n * The writer\n */\n this.w = writer\n /**\n * Current state\n * @type {T|null}\n */\n this.s = null\n this.count = 0\n }\n\n /**\n * @param {T} v\n */\n write (v) {\n if (this.s === v) {\n this.count++\n } else {\n if (this.count > 0) {\n // flush counter, unless this is the first value (count = 0)\n writeVarUint(this, this.count - 1) // since count is always > 0, we can decrement by one. non-standard encoding ftw\n }\n this.count = 1\n // write first value\n this.w(this, v)\n this.s = v\n }\n }\n}\n\n/**\n * Basic diff decoder using variable length encoding.\n *\n * Encodes the values [3, 1100, 1101, 1050, 0] to [3, 1097, 1, -51, -1050] using writeVarInt.\n */\nexport class IntDiffEncoder extends Encoder {\n /**\n * @param {number} start\n */\n constructor (start) {\n super()\n /**\n * Current state\n * @type {number}\n */\n this.s = start\n }\n\n /**\n * @param {number} v\n */\n write (v) {\n writeVarInt(this, v - this.s)\n this.s = v\n }\n}\n\n/**\n * A combination of IntDiffEncoder and RleEncoder.\n *\n * Basically first writes the IntDiffEncoder and then counts duplicate diffs using RleEncoding.\n *\n * Encodes the values [1,1,1,2,3,4,5,6] as [1,1,0,2,1,5] (RLE([1,0,0,1,1,1,1,1]) ⇒ RleIntDiff[1,1,0,2,1,5])\n */\nexport class RleIntDiffEncoder extends Encoder {\n /**\n * @param {number} start\n */\n constructor (start) {\n super()\n /**\n * Current state\n * @type {number}\n */\n this.s = start\n this.count = 0\n }\n\n /**\n * @param {number} v\n */\n write (v) {\n if (this.s === v && this.count > 0) {\n this.count++\n } else {\n if (this.count > 0) {\n // flush counter, unless this is the first value (count = 0)\n writeVarUint(this, this.count - 1) // since count is always > 0, we can decrement by one. non-standard encoding ftw\n }\n this.count = 1\n // write first value\n writeVarInt(this, v - this.s)\n this.s = v\n }\n }\n}\n\n/**\n * @param {UintOptRleEncoder} encoder\n */\nconst flushUintOptRleEncoder = encoder => {\n if (encoder.count > 0) {\n // flush counter, unless this is the first value (count = 0)\n // case 1: just a single value. set sign to positive\n // case 2: write several values. set sign to negative to indicate that there is a length coming\n writeVarInt(encoder.encoder, encoder.count === 1 ? encoder.s : -encoder.s)\n if (encoder.count > 1) {\n writeVarUint(encoder.encoder, encoder.count - 2) // since count is always > 1, we can decrement by one. non-standard encoding ftw\n }\n }\n}\n\n/**\n * Optimized Rle encoder that does not suffer from the mentioned problem of the basic Rle encoder.\n *\n * Internally uses VarInt encoder to write unsigned integers. If the input occurs multiple times, we write\n * write it as a negative number. The UintOptRleDecoder then understands that it needs to read a count.\n *\n * Encodes [1,2,3,3,3] as [1,2,-3,3] (once 1, once 2, three times 3)\n */\nexport class UintOptRleEncoder {\n constructor () {\n this.encoder = new Encoder()\n /**\n * @type {number}\n */\n this.s = 0\n this.count = 0\n }\n\n /**\n * @param {number} v\n */\n write (v) {\n if (this.s === v) {\n this.count++\n } else {\n flushUintOptRleEncoder(this)\n this.count = 1\n this.s = v\n }\n }\n\n /**\n * Flush the encoded state and transform this to a Uint8Array.\n *\n * Note that this should only be called once.\n */\n toUint8Array () {\n flushUintOptRleEncoder(this)\n return toUint8Array(this.encoder)\n }\n}\n\n/**\n * Increasing Uint Optimized RLE Encoder\n *\n * The RLE encoder counts the number of same occurences of the same value.\n * The IncUintOptRle encoder counts if the value increases.\n * I.e. 7, 8, 9, 10 will be encoded as [-7, 4]. 1, 3, 5 will be encoded\n * as [1, 3, 5].\n */\nexport class IncUintOptRleEncoder {\n constructor () {\n this.encoder = new Encoder()\n /**\n * @type {number}\n */\n this.s = 0\n this.count = 0\n }\n\n /**\n * @param {number} v\n */\n write (v) {\n if (this.s + this.count === v) {\n this.count++\n } else {\n flushUintOptRleEncoder(this)\n this.count = 1\n this.s = v\n }\n }\n\n /**\n * Flush the encoded state and transform this to a Uint8Array.\n *\n * Note that this should only be called once.\n */\n toUint8Array () {\n flushUintOptRleEncoder(this)\n return toUint8Array(this.encoder)\n }\n}\n\n/**\n * @param {IntDiffOptRleEncoder} encoder\n */\nconst flushIntDiffOptRleEncoder = encoder => {\n if (encoder.count > 0) {\n // 31 bit making up the diff | wether to write the counter\n // const encodedDiff = encoder.diff << 1 | (encoder.count === 1 ? 0 : 1)\n const encodedDiff = encoder.diff * 2 + (encoder.count === 1 ? 0 : 1)\n // flush counter, unless this is the first value (count = 0)\n // case 1: just a single value. set first bit to positive\n // case 2: write several values. set first bit to negative to indicate that there is a length coming\n writeVarInt(encoder.encoder, encodedDiff)\n if (encoder.count > 1) {\n writeVarUint(encoder.encoder, encoder.count - 2) // since count is always > 1, we can decrement by one. non-standard encoding ftw\n }\n }\n}\n\n/**\n * A combination of the IntDiffEncoder and the UintOptRleEncoder.\n *\n * The count approach is similar to the UintDiffOptRleEncoder, but instead of using the negative bitflag, it encodes\n * in the LSB whether a count is to be read. Therefore this Encoder only supports 31 bit integers!\n *\n * Encodes [1, 2, 3, 2] as [3, 1, 6, -1] (more specifically [(1 << 1) | 1, (3 << 0) | 0, -1])\n *\n * Internally uses variable length encoding. Contrary to normal UintVar encoding, the first byte contains:\n * * 1 bit that denotes whether the next value is a count (LSB)\n * * 1 bit that denotes whether this value is negative (MSB - 1)\n * * 1 bit that denotes whether to continue reading the variable length integer (MSB)\n *\n * Therefore, only five bits remain to encode diff ranges.\n *\n * Use this Encoder only when appropriate. In most cases, this is probably a bad idea.\n */\nexport class IntDiffOptRleEncoder {\n constructor () {\n this.encoder = new Encoder()\n /**\n * @type {number}\n */\n this.s = 0\n this.count = 0\n this.diff = 0\n }\n\n /**\n * @param {number} v\n */\n write (v) {\n if (this.diff === v - this.s) {\n this.s = v\n this.count++\n } else {\n flushIntDiffOptRleEncoder(this)\n this.count = 1\n this.diff = v - this.s\n this.s = v\n }\n }\n\n /**\n * Flush the encoded state and transform this to a Uint8Array.\n *\n * Note that this should only be called once.\n */\n toUint8Array () {\n flushIntDiffOptRleEncoder(this)\n return toUint8Array(this.encoder)\n }\n}\n\n/**\n * Optimized String Encoder.\n *\n * Encoding many small strings in a simple Encoder is not very efficient. The function call to decode a string takes some time and creates references that must be eventually deleted.\n * In practice, when decoding several million small strings, the GC will kick in more and more often to collect orphaned string objects (or maybe there is another reason?).\n *\n * This string encoder solves the above problem. All strings are concatenated and written as a single string using a single encoding call.\n *\n * The lengths are encoded using a UintOptRleEncoder.\n */\nexport class StringEncoder {\n constructor () {\n /**\n * @type {Array<string>}\n */\n this.sarr = []\n this.s = ''\n this.lensE = new UintOptRleEncoder()\n }\n\n /**\n * @param {string} string\n */\n write (string) {\n this.s += string\n if (this.s.length > 19) {\n this.sarr.push(this.s)\n this.s = ''\n }\n this.lensE.write(string.length)\n }\n\n toUint8Array () {\n const encoder = new Encoder()\n this.sarr.push(this.s)\n this.s = ''\n writeVarString(encoder, this.sarr.join(''))\n writeUint8Array(encoder, this.lensE.toUint8Array())\n return toUint8Array(encoder)\n }\n}\n","/**\n * Error helpers.\n *\n * @module error\n */\n\n/**\n * @param {string} s\n * @return {Error}\n */\n/* c8 ignore next */\nexport const create = s => new Error(s)\n\n/**\n * @throws {Error}\n * @return {never}\n */\n/* c8 ignore next 3 */\nexport const methodUnimplemented = () => {\n throw create('Method unimplemented')\n}\n\n/**\n * @throws {Error}\n * @return {never}\n */\n/* c8 ignore next 3 */\nexport const unexpectedCase = () => {\n throw create('Unexpected case')\n}\n","/**\n * Efficient schema-less binary decoding with support for variable length encoding.\n *\n * Use [lib0/decoding] with [lib0/encoding]. Every encoding function has a corresponding decoding function.\n *\n * Encodes numbers in little-endian order (least to most significant byte order)\n * and is compatible with Golang's binary encoding (https://golang.org/pkg/encoding/binary/)\n * which is also used in Protocol Buffers.\n *\n * ```js\n * // encoding step\n * const encoder = encoding.createEncoder()\n * encoding.writeVarUint(encoder, 256)\n * encoding.writeVarString(encoder, 'Hello world!')\n * const buf = encoding.toUint8Array(encoder)\n * ```\n *\n * ```js\n * // decoding step\n * const decoder = decoding.createDecoder(buf)\n * decoding.readVarUint(decoder) // => 256\n * decoding.readVarString(decoder) // => 'Hello world!'\n * decoding.hasContent(decoder) // => false - all data is read\n * ```\n *\n * @module decoding\n */\n\nimport * as binary from './binary.js'\nimport * as math from './math.js'\nimport * as number from './number.js'\nimport * as string from './string.js'\nimport * as error from './error.js'\nimport * as encoding from './encoding.js'\n\nconst errorUnexpectedEndOfArray = error.create('Unexpected end of array')\nconst errorIntegerOutOfRange = error.create('Integer out of Range')\n\n/**\n * A Decoder handles the decoding of an Uint8Array.\n */\nexport class Decoder {\n /**\n * @param {Uint8Array} uint8Array Binary data to decode\n */\n constructor (uint8Array) {\n /**\n * Decoding target.\n *\n * @type {Uint8Array}\n */\n this.arr = uint8Array\n /**\n * Current decoding position.\n *\n * @type {number}\n */\n this.pos = 0\n }\n}\n\n/**\n * @function\n * @param {Uint8Array} uint8Array\n * @return {Decoder}\n */\nexport const createDecoder = uint8Array => new Decoder(uint8Array)\n\n/**\n * @function\n * @param {Decoder} decoder\n * @return {boolean}\n */\nexport const hasContent = decoder => decoder.pos !== decoder.arr.length\n\n/**\n * Clone a decoder instance.\n * Optionally set a new position parameter.\n *\n * @function\n * @param {Decoder} decoder The decoder instance\n * @param {number} [newPos] Defaults to current position\n * @return {Decoder} A clone of `decoder`\n */\nexport const clone = (decoder, newPos = decoder.pos) => {\n const _decoder = createDecoder(decoder.arr)\n _decoder.pos = newPos\n return _decoder\n}\n\n/**\n * Create an Uint8Array view of the next `len` bytes and advance the position by `len`.\n *\n * Important: The Uint8Array still points to the underlying ArrayBuffer. Make sure to discard the result as soon as possible to prevent any memory leaks.\n * Use `buffer.copyUint8Array` to copy the result into a new Uint8Array.\n *\n * @function\n * @param {Decoder} decoder The decoder instance\n * @param {number} len The length of bytes to read\n * @return {Uint8Array}\n */\nexport const readUint8Array = (decoder, len) => {\n const view = new Uint8Array(decoder.arr.buffer, decoder.pos + decoder.arr.byteOffset, len)\n decoder.pos += len\n return view\n}\n\n/**\n * Read variable length Uint8Array.\n *\n * Important: The Uint8Array still points to the underlying ArrayBuffer. Make sure to discard the result as soon as possible to prevent any memory leaks.\n * Use `buffer.copyUint8Array` to copy the result into a new Uint8Array.\n *\n * @function\n * @param {Decoder} decoder\n * @return {Uint8Array}\n */\nexport const readVarUint8Array = decoder => readUint8Array(decoder, readVarUint(decoder))\n\n/**\n * Read the rest of the content as an ArrayBuffer\n * @function\n * @param {Decoder} decoder\n * @return {Uint8Array}\n */\nexport const readTailAsUint8Array = decoder => readUint8Array(decoder, decoder.arr.length - decoder.pos)\n\n/**\n * Skip one byte, jump to the next position.\n * @function\n * @param {Decoder} decoder The decoder instance\n * @return {number} The next position\n */\nexport const skip8 = decoder => decoder.pos++\n\n/**\n * Read one byte as unsigned integer.\n * @function\n * @param {Decoder} decoder The decoder instance\n * @return {number} Unsigned 8-bit integer\n */\nexport const readUint8 = decoder => decoder.arr[decoder.pos++]\n\n/**\n * Read 2 bytes as unsigned integer.\n *\n * @function\n * @param {Decoder} decoder\n * @return {number} An unsigned integer.\n */\nexport const readUint16 = decoder => {\n const uint =\n decoder.arr[decoder.pos] +\n (decoder.arr[decoder.pos + 1] << 8)\n decoder.pos += 2\n return uint\n}\n\n/**\n * Read 4 bytes as unsigned integer.\n *\n * @function\n * @param {Decoder} decoder\n * @return {number} An unsigned integer.\n */\nexport const readUint32 = decoder => {\n const uint =\n (decoder.arr[decoder.pos] +\n (decoder.arr[decoder.pos + 1] << 8) +\n (decoder.arr[decoder.pos + 2] << 16) +\n (decoder.arr[decoder.pos + 3] << 24)) >>> 0\n decoder.pos += 4\n return uint\n}\n\n/**\n * Read 4 bytes as unsigned integer in big endian order.\n * (most significant byte first)\n *\n * @function\n * @param {Decoder} decoder\n * @return {number} An unsigned integer.\n */\nexport const readUint32BigEndian = decoder => {\n const uint =\n (decoder.arr[decoder.pos + 3] +\n (decoder.arr[decoder.pos + 2] << 8) +\n (decoder.arr[decoder.pos + 1] << 16) +\n (decoder.arr[decoder.pos] << 24)) >>> 0\n decoder.pos += 4\n return uint\n}\n\n/**\n * Look ahead without incrementing the position\n * to the next byte and read it as unsigned integer.\n *\n * @function\n * @param {Decoder} decoder\n * @return {number} An unsigned integer.\n */\nexport const peekUint8 = decoder => decoder.arr[decoder.pos]\n\n/**\n * Look ahead without incrementing the position\n * to the next byte and read it as unsigned integer.\n *\n * @function\n * @param {Decoder} decoder\n * @return {number} An unsigned integer.\n */\nexport const peekUint16 = decoder =>\n decoder.arr[decoder.pos] +\n (decoder.arr[decoder.pos + 1] << 8)\n\n/**\n * Look ahead without incrementing the position\n * to the next byte and read it as unsigned integer.\n *\n * @function\n * @param {Decoder} decoder\n * @return {number} An unsigned integer.\n */\nexport const peekUint32 = decoder => (\n decoder.arr[decoder.pos] +\n (decoder.arr[decoder.pos + 1] << 8) +\n (decoder.arr[decoder.pos + 2] << 16) +\n (decoder.arr[decoder.pos + 3] << 24)\n) >>> 0\n\n/**\n * Read unsigned integer (32bit) with variable length.\n * 1/8th of the storage is used as encoding overhead.\n * * numbers < 2^7 is stored in one bytlength\n * * numbers < 2^14 is stored in two bylength\n *\n * @function\n * @param {Decoder} decoder\n * @return {number} An unsigned integer.length\n */\nexport const readVarUint = decoder => {\n let num = 0\n let mult = 1\n const len = decoder.arr.length\n while (decoder.pos < len) {\n const r = decoder.arr[decoder.pos++]\n // num = num | ((r & binary.BITS7) << len)\n num = num + (r & binary.BITS7) * mult // shift $r << (7*#iterations) and add it to num\n mult *= 128 // next iteration, shift 7 \"more\" to the left\n if (r < binary.BIT8) {\n return num\n }\n /* c8 ignore start */\n if (num > number.MAX_SAFE_INTEGER) {\n throw errorIntegerOutOfRange\n }\n /* c8 ignore stop */\n }\n throw errorUnexpectedEndOfArray\n}\n\n/**\n * Read signed integer (32bit) with variable length.\n * 1/8th of the storage is used as encoding overhead.\n * * numbers < 2^7 is stored in one bytlength\n * * numbers < 2^14 is stored in two bylength\n * @todo This should probably create the inverse ~num if number is negative - but this would be a breaking change.\n *\n * @function\n * @param {Decoder} decoder\n * @return {number} An unsigned integer.length\n */\nexport const readVarInt = decoder => {\n let r = decoder.arr[decoder.pos++]\n let num = r & binary.BITS6\n let mult = 64\n const sign = (r & binary.BIT7) > 0 ? -1 : 1\n if ((r & binary.BIT8) === 0) {\n // don't continue reading\n return sign * num\n }\n const len = decoder.arr.length\n while (decoder.pos < len) {\n r = decoder.arr[decoder.pos++]\n // num = num | ((r & binary.BITS7) << len)\n num = num + (r & binary.BITS7) * mult\n mult *= 128\n if (r < binary.BIT8) {\n return sign * num\n }\n /* c8 ignore start */\n if (num > number.MAX_SAFE_INTEGER) {\n throw errorIntegerOutOfRange\n }\n /* c8 ignore stop */\n }\n throw errorUnexpectedEndOfArray\n}\n\n/**\n * Look ahead and read varUint without incrementing position\n *\n * @function\n * @param {Decoder} decoder\n * @return {number}\n */\nexport const peekVarUint = decoder => {\n const pos = decoder.pos\n const s = readVarUint(decoder)\n decoder.pos = pos\n return s\n}\n\n/**\n * Look ahead and read varUint without incrementing position\n *\n * @function\n * @param {Decoder} decoder\n * @return {number}\n */\nexport const peekVarInt = decoder => {\n const pos = decoder.pos\n const s = readVarInt(decoder)\n decoder.pos = pos\n return s\n}\n\n/**\n * We don't test this function anymore as we use native decoding/encoding by default now.\n * Better not modify this anymore..\n *\n * Transforming utf8 to a string is pretty expensive. The code performs 10x better\n * when String.fromCodePoint is fed with all characters as arguments.\n * But most environments have a maximum number of arguments per functions.\n * For effiency reasons we apply a maximum of 10000 characters at once.\n *\n * @function\n * @param {Decoder} decoder\n * @return {String} The read String.\n */\n/* c8 ignore start */\nexport const _readVarStringPolyfill = decoder => {\n let remainingLen = readVarUint(decoder)\n if (remainingLen === 0) {\n return ''\n } else {\n let encodedString = String.fromCodePoint(readUint8(decoder)) // remember to decrease remainingLen\n if (--remainingLen < 100) { // do not create a Uint8Array for small strings\n while (remainingLen--) {\n encodedString += String.fromCodePoint(readUint8(decoder))\n }\n } else {\n while (remainingLen > 0) {\n const nextLen = remainingLen < 10000 ? remainingLen : 10000\n // this is dangerous, we create a fresh array view from the existing buffer\n const bytes = decoder.arr.subarray(decoder.pos, decoder.pos + nextLen)\n decoder.pos += nextLen\n // Starting with ES5.1 we can supply a generic array-like object as arguments\n encodedString += String.fromCodePoint.apply(null, /** @type {any} */ (bytes))\n remainingLen -= nextLen\n }\n }\n return decodeURIComponent(escape(encodedString))\n }\n}\n/* c8 ignore stop */\n\n/**\n * @function\n * @param {Decoder} decoder\n * @return {String} The read String\n */\nexport const _readVarStringNative = decoder =>\n /** @type any */ (string.utf8TextDecoder).decode(readVarUint8Array(decoder))\n\n/**\n * Read string of variable length\n * * varUint is used to store the length of the string\n *\n * @function\n * @param {Decoder} decoder\n * @return {String} The read String\n *\n */\n/* c8 ignore next */\nexport const readVarString = string.utf8TextDecoder ? _readVarStringNative : _readVarStringPolyfill\n\n/**\n * @param {Decoder} decoder\n * @return {Uint8Array}\n */\nexport const readTerminatedUint8Array = decoder => {\n const encoder = encoding.createEncoder()\n let b\n while (true) {\n b = readUint8(decoder)\n if (b === 0) {\n return encoding.toUint8Array(encoder)\n }\n if (b === 1) {\n b = readUint8(decoder)\n }\n encoding.write(encoder, b)\n }\n}\n\n/**\n * @param {Decoder} decoder\n * @return {string}\n */\nexport const readTerminatedString = decoder => string.decodeUtf8(readTerminatedUint8Array(decoder))\n\n/**\n * Look ahead and read varString without incrementing position\n *\n * @function\n * @param {Decoder} decoder\n * @return {string}\n */\nexport const peekVarString = decoder => {\n const pos = decoder.pos\n const s = readVarString(decoder)\n decoder.pos = pos\n return s\n}\n\n/**\n * @param {Decoder} decoder\n * @param {number} len\n * @return {DataView}\n */\nexport const readFromDataView = (decoder, len) => {\n const dv = new DataView(decoder.arr.buffer, decoder.arr.byteOffset + decoder.pos, len)\n decoder.pos += len\n return dv\n}\n\n/**\n * @param {Decoder} decoder\n */\nexport const readFloat32 = decoder => readFromDataView(decoder, 4).getFloat32(0, false)\n\n/**\n * @param {Decoder} decoder\n */\nexport const readFloat64 = decoder => readFromDataView(decoder, 8).getFloat64(0, false)\n\n/**\n * @param {Decoder} decoder\n */\nexport const readBigInt64 = decoder => /** @type {any} */ (readFromDataView(decoder, 8)).getBigInt64(0, false)\n\n/**\n * @param {Decoder} decoder\n */\nexport const readBigUint64 = decoder => /** @type {any} */ (readFromDataView(decoder, 8)).getBigUint64(0, false)\n\n/**\n * @type {Array<function(Decoder):any>}\n */\nconst readAnyLookupTable = [\n decoder => undefined, // CASE 127: undefined\n decoder => null, // CASE 126: null\n readVarInt, // CASE 125: integer\n readFloat32, // CASE 124: float32\n readFloat64, // CASE 123: float64\n readBigInt64, // CASE 122: bigint\n decoder => false, // CASE 121: boolean (false)\n decoder => true, // CASE 120: boolean (true)\n readVarString, // CASE 119: string\n decoder => { // CASE 118: object<string,any>\n const len = readVarUint(decoder)\n /**\n * @type {Object<string,any>}\n */\n const obj = {}\n for (let i = 0; i < len; i++) {\n const key = readVarString(decoder)\n obj[key] = readAny(decoder)\n }\n return obj\n },\n decoder => { // CASE 117: array<any>\n const len = readVarUint(decoder)\n const arr = []\n for (let i = 0; i < len; i++) {\n arr.push(readAny(decoder))\n }\n return arr\n },\n readVarUint8Array // CASE 116: Uint8Array\n]\n\n/**\n * @param {Decoder} decoder\n */\nexport const readAny = decoder => readAnyLookupTable[127 - readUint8(decoder)](decoder)\n\n/**\n * T must not be null.\n *\n * @template T\n */\nexport class RleDecoder extends Decoder {\n /**\n * @param {Uint8Array} uint8Array\n * @param {function(Decoder):T} reader\n */\n constructor (uint8Array, reader) {\n super(uint8Array)\n /**\n * The reader\n */\n this.reader = reader\n /**\n * Current state\n * @type {T|null}\n */\n this.s = null\n this.count = 0\n }\n\n read () {\n if (this.count === 0) {\n this.s = this.reader(this)\n if (hasContent(this)) {\n this.count = readVarUint(this) + 1 // see encoder implementation for the reason why this is incremented\n } else {\n this.count = -1 // read the current value forever\n }\n }\n this.count--\n return /** @type {T} */ (this.s)\n }\n}\n\nexport class IntDiffDecoder extends Decoder {\n /**\n * @param {Uint8Array} uint8Array\n * @param {number} start\n */\n constructor (uint8Array, start) {\n super(uint8Array)\n /**\n * Current state\n * @type {number}\n */\n this.s = start\n }\n\n /**\n * @return {number}\n */\n read () {\n this.s += readVarInt(this)\n return this.s\n }\n}\n\nexport class RleIntDiffDecoder extends Decoder {\n /**\n * @param {Uint8Array} uint8Array\n * @param {number} start\n */\n constructor (uint8Array, start) {\n super(uint8Array)\n /**\n * Current state\n * @type {number}\n */\n this.s = start\n this.count = 0\n }\n\n /**\n * @return {number}\n */\n read () {\n if (this.count === 0) {\n this.s += readVarInt(this)\n if (hasContent(this)) {\n this.count = readVarUint(this) + 1 // see encoder implementation for the reason why this is incremented\n } else {\n this.count = -1 // read the current value forever\n }\n }\n this.count--\n return /** @type {number} */ (this.s)\n }\n}\n\nexport class UintOptRleDecoder extends Decoder {\n /**\n * @param {Uint8Array} uint8Array\n */\n constructor (uint8Array) {\n super(uint8Array)\n /**\n * @type {number}\n */\n this.s = 0\n this.count = 0\n }\n\n read () {\n if (this.count === 0) {\n this.s = readVarInt(this)\n // if the sign is negative, we read the count too, otherwise count is 1\n const isNegative = math.isNegativeZero(this.s)\n this.count = 1\n if (isNegative) {\n this.s = -this.s\n this.count = readVarUint(this) + 2\n }\n }\n this.count--\n return /** @type {number} */ (this.s)\n }\n}\n\nexport class IncUintOptRleDecoder extends Decoder {\n /**\n * @param {Uint8Array} uint8Array\n */\n constructor (uint8Array) {\n super(uint8Array)\n /**\n * @type {number}\n */\n this.s = 0\n this.count = 0\n }\n\n read () {\n if (this.count === 0) {\n this.s = readVarInt(this)\n // if the sign is negative, we read the count too, otherwise count is 1\n const isNegative = math.isNegativeZero(this.s)\n this.count = 1\n if (isNegative) {\n this.s = -this.s\n this.count = readVarUint(this) + 2\n }\n }\n this.count--\n return /** @type {number} */ (this.s++)\n }\n}\n\nexport class IntDiffOptRleDecoder extends Decoder {\n /**\n * @param {Uint8Array} uint8Array\n */\n constructor (uint8Array) {\n super(uint8Array)\n /**\n * @type {number}\n */\n this.s = 0\n this.count = 0\n this.diff = 0\n }\n\n /**\n * @return {number}\n */\n read () {\n if (this.count === 0) {\n const diff = readVarInt(this)\n // if the first bit is set, we read more data\n const hasCount = diff & 1\n this.diff = math.floor(diff / 2) // shift >> 1\n this.count = 1\n if (hasCount) {\n this.count = readVarUint(this) + 2\n }\n }\n this.s += this.diff\n this.count--\n return this.s\n }\n}\n\nexport class StringDecoder {\n /**\n * @param {Uint8Array} uint8Array\n */\n constructor (uint8Array) {\n this.decoder = new UintOptRleDecoder(uint8Array)\n this.str = readVarString(this.decoder)\n /**\n * @type {number}\n */\n this.spos = 0\n }\n\n /**\n * @return {string}\n */\n read () {\n const end = this.spos + this.decoder.read()\n const res = this.str.slice(this.spos, end)\n this.spos = end\n return res\n }\n}\n","import * as encoding from \"lib0/encoding\";\nimport * as decoding from \"lib0/decoding\";\nimport type {AuthorizedScope} from \"../../provider/src\"\n\nexport enum AuthMessageType {\n\tToken = 0,\n\tPermissionDenied = 1,\n\tAuthenticated = 2,\n}\n\nexport const writeAuthentication = (\n\tencoder: encoding.Encoder,\n\tauth: string,\n) => {\n\tencoding.writeVarUint(encoder, AuthMessageType.Token);\n\tencoding.writeVarString(encoder, auth);\n};\n\nexport const writePermissionDenied = (\n\tencoder: encoding.Encoder,\n\treason: string,\n) => {\n\tencoding.writeVarUint(encoder, AuthMessageType.PermissionDenied);\n\tencoding.writeVarString(encoder, reason);\n};\n\nexport const writeAuthenticated = (\n\tencoder: encoding.Encoder,\n\tscope: AuthorizedScope,\n) => {\n\tencoding.writeVarUint(encoder, AuthMessageType.Authenticated);\n\tencoding.writeVarString(encoder, scope);\n};\n\nexport const writeTokenSyncRequest = (\n\tencoder: encoding.Encoder,\n) => {\n\tencoding.writeVarUint(encoder, AuthMessageType.Token);\n};\n\nexport const readAuthMessage = (\n\tdecoder: decoding.Decoder,\n\tsendToken: () => void,\n\tpermissionDeniedHandler: (reason: string) => void,\n\tauthenticatedHandler: (scope: string) => void,\n) => {\n\tswitch (decoding.readVarUint(decoder)) {\n\t\tcase AuthMessageType.Token: {\n\t\t\tsendToken();\n\t\t\tbreak;\n\t\t}\n\t\tcase AuthMessageType.PermissionDenied: {\n\t\t\tpermissionDeniedHandler(decoding.readVarString(decoder));\n\t\t\tbreak;\n\t\t}\n\t\tcase AuthMessageType.Authenticated: {\n\t\t\tauthenticatedHandler(decoding.readVarString(decoder));\n\t\t\tbreak;\n\t\t}\n\t\tdefault:\n\t}\n};\n","export interface CloseEvent {\n\tcode: number;\n\treason: string;\n}\n\n/**\n * The server is terminating the connection because a data frame was received\n * that is too large.\n * See: https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code\n */\nexport const MessageTooBig: CloseEvent = {\n\tcode: 1009,\n\treason: \"Message Too Big\",\n};\n\n/**\n * The server successfully processed the request, asks that the requester reset\n * its document view, and is not returning any content.\n */\nexport const ResetConnection: CloseEvent = {\n\tcode: 4205,\n\treason: \"Reset Connection\",\n};\n\n/**\n * Similar to Forbidden, but specifically for use when authentication is required and has\n * failed or has not yet been provided.\n */\nexport const Unauthorized: CloseEvent = {\n\tcode: 4401,\n\treason: \"Unauthorized\",\n};\n\n/**\n * The request contained valid data and was understood by the server, but the server\n * is refusing action.\n */\nexport const Forbidden: CloseEvent = {\n\tcode: 4403,\n\treason: \"Forbidden\",\n};\n\n/**\n * The server timed out waiting for the request.\n */\nexport const ConnectionTimeout: CloseEvent = {\n\tcode: 4408,\n\treason: \"Connection Timeout\",\n};\n","export const awarenessStatesToArray = (\n\tstates: Map<number, Record<string, any>>,\n) => {\n\treturn Array.from(states.entries()).map(([key, value]) => {\n\t\treturn {\n\t\t\tclientId: key,\n\t\t\t...value,\n\t\t};\n\t});\n};\n","/**\n * State of the WebSocket connection.\n * https://developer.mozilla.org/de/docs/Web/API/WebSocket/readyState\n */\nexport enum WsReadyStates {\n\tConnecting = 0,\n\tOpen = 1,\n\tClosing = 2,\n\tClosed = 3,\n}\n"],"x_google_ignoreList":[0,1,2,3,4,5,6],"mappings":"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"} |
+3
-3
| { | ||
| "name": "@hocuspocus/common", | ||
| "description": "shared code for multiple Hocuspocus packages", | ||
| "version": "3.4.4", | ||
| "version": "3.4.5-rc.0", | ||
| "homepage": "https://hocuspocus.dev", | ||
@@ -13,3 +13,3 @@ "keywords": [ | ||
| "module": "dist/hocuspocus-common.esm.js", | ||
| "types": "dist/packages/common/src/index.d.ts", | ||
| "types": "dist/index.d.ts", | ||
| "exports": { | ||
@@ -22,3 +22,3 @@ "source": { | ||
| "require": "./dist/hocuspocus-common.cjs", | ||
| "types": "./dist/packages/common/src/index.d.ts" | ||
| "types": "./dist/index.d.ts" | ||
| } | ||
@@ -25,0 +25,0 @@ }, |
| export * from 'prosemirror-model'; |
| export * from 'prosemirror-state'; |
| export * from 'prosemirror-transform'; |
| export * from 'prosemirror-view'; |
| import * as encoding from "lib0/encoding"; | ||
| import * as decoding from "lib0/decoding"; | ||
| import type { AuthorizedScope } from "../../provider/src"; | ||
| export declare enum AuthMessageType { | ||
| Token = 0, | ||
| PermissionDenied = 1, | ||
| Authenticated = 2 | ||
| } | ||
| export declare const writeAuthentication: (encoder: encoding.Encoder, auth: string) => void; | ||
| export declare const writePermissionDenied: (encoder: encoding.Encoder, reason: string) => void; | ||
| export declare const writeAuthenticated: (encoder: encoding.Encoder, scope: AuthorizedScope) => void; | ||
| export declare const writeTokenSyncRequest: (encoder: encoding.Encoder) => void; | ||
| export declare const readAuthMessage: (decoder: decoding.Decoder, sendToken: () => void, permissionDeniedHandler: (reason: string) => void, authenticatedHandler: (scope: string) => void) => void; |
| export declare const awarenessStatesToArray: (states: Map<number, Record<string, any>>) => { | ||
| clientId: number; | ||
| }[]; |
| export interface CloseEvent { | ||
| code: number; | ||
| reason: string; | ||
| } | ||
| /** | ||
| * The server is terminating the connection because a data frame was received | ||
| * that is too large. | ||
| * See: https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code | ||
| */ | ||
| export declare const MessageTooBig: CloseEvent; | ||
| /** | ||
| * The server successfully processed the request, asks that the requester reset | ||
| * its document view, and is not returning any content. | ||
| */ | ||
| export declare const ResetConnection: CloseEvent; | ||
| /** | ||
| * Similar to Forbidden, but specifically for use when authentication is required and has | ||
| * failed or has not yet been provided. | ||
| */ | ||
| export declare const Unauthorized: CloseEvent; | ||
| /** | ||
| * The request contained valid data and was understood by the server, but the server | ||
| * is refusing action. | ||
| */ | ||
| export declare const Forbidden: CloseEvent; | ||
| /** | ||
| * The server timed out waiting for the request. | ||
| */ | ||
| export declare const ConnectionTimeout: CloseEvent; |
| export * from "./auth.ts"; | ||
| export * from "./CloseEvents.ts"; | ||
| export * from "./awarenessStatesToArray.ts"; | ||
| export * from "./types.ts"; |
| /** | ||
| * State of the WebSocket connection. | ||
| * https://developer.mozilla.org/de/docs/Web/API/WebSocket/readyState | ||
| */ | ||
| export declare enum WsReadyStates { | ||
| Connecting = 0, | ||
| Open = 1, | ||
| Closing = 2, | ||
| Closed = 3 | ||
| } |
| import type { Extension, onChangePayload, onLoadDocumentPayload, storePayload, fetchPayload } from "@hocuspocus/server"; | ||
| export interface DatabaseConfiguration { | ||
| /** | ||
| * Pass a Promise to retrieve updates from your database. The Promise should resolve to | ||
| * an array of items with Y.js-compatible binary data. | ||
| */ | ||
| fetch: (data: fetchPayload) => Promise<Uint8Array | null>; | ||
| /** | ||
| * Pass a function to store updates in your database. | ||
| */ | ||
| store: (data: storePayload) => Promise<void>; | ||
| } | ||
| export declare class Database implements Extension { | ||
| /** | ||
| * Default configuration | ||
| */ | ||
| configuration: DatabaseConfiguration; | ||
| /** | ||
| * Constructor | ||
| */ | ||
| constructor(configuration: Partial<DatabaseConfiguration>); | ||
| /** | ||
| * Get stored data from the database. | ||
| */ | ||
| onLoadDocument(data: onLoadDocumentPayload): Promise<any>; | ||
| /** | ||
| * Store new updates in the database. | ||
| */ | ||
| onStoreDocument(data: onChangePayload): Promise<void>; | ||
| } |
| export * from "./Database.ts"; |
| export * from "./Logger.ts"; |
| import type { Extension, onChangePayload, onConfigurePayload, onConnectPayload, onLoadDocumentPayload, onDestroyPayload, onDisconnectPayload, onRequestPayload, onUpgradePayload } from "@hocuspocus/server"; | ||
| export interface LoggerConfiguration { | ||
| /** | ||
| * Prepend all logging message with a string. | ||
| * | ||
| * @deprecated | ||
| */ | ||
| prefix: null | string; | ||
| /** | ||
| * Whether to log something for the `onLoadDocument` hook. | ||
| */ | ||
| onLoadDocument: boolean; | ||
| /** | ||
| * Whether to log something for the `onChange` hook. | ||
| */ | ||
| onChange: boolean; | ||
| /** | ||
| * Whether to log something for the `onStoreDocument` hook. | ||
| */ | ||
| onStoreDocument: boolean; | ||
| /** | ||
| * Whether to log something for the `onConnect` hook. | ||
| */ | ||
| onConnect: boolean; | ||
| /** | ||
| * Whether to log something for the `onDisconnect` hook. | ||
| */ | ||
| onDisconnect: boolean; | ||
| /** | ||
| * Whether to log something for the `onUpgrade` hook. | ||
| */ | ||
| onUpgrade: boolean; | ||
| /** | ||
| * Whether to log something for the `onRequest` hook. | ||
| */ | ||
| onRequest: boolean; | ||
| /** | ||
| * Whether to log something for the `onDestroy` hook. | ||
| */ | ||
| onDestroy: boolean; | ||
| /** | ||
| * Whether to log something for the `onConfigure` hook. | ||
| */ | ||
| onConfigure: boolean; | ||
| /** | ||
| * A log function, if none is provided output will go to console | ||
| */ | ||
| log: (...args: any[]) => void; | ||
| } | ||
| export declare class Logger implements Extension { | ||
| name: string | null; | ||
| configuration: LoggerConfiguration; | ||
| /** | ||
| * Constructor | ||
| */ | ||
| constructor(configuration?: Partial<LoggerConfiguration>); | ||
| onConfigure(data: onConfigurePayload): Promise<void>; | ||
| onLoadDocument(data: onLoadDocumentPayload): Promise<void>; | ||
| onChange(data: onChangePayload): Promise<void>; | ||
| onStoreDocument(data: onDisconnectPayload): Promise<void>; | ||
| onConnect(data: onConnectPayload): Promise<void>; | ||
| onDisconnect(data: onDisconnectPayload): Promise<void>; | ||
| onUpgrade(data: onUpgradePayload): Promise<void>; | ||
| onRequest(data: onRequestPayload): Promise<void>; | ||
| onDestroy(data: onDestroyPayload): Promise<void>; | ||
| private log; | ||
| } |
| export * from "./Redis.ts"; |
| import type { Extension, Hocuspocus, afterLoadDocumentPayload, afterStoreDocumentPayload, afterUnloadDocumentPayload, beforeBroadcastStatelessPayload, beforeUnloadDocumentPayload, onAwarenessUpdatePayload, onChangePayload, onConfigurePayload, onStoreDocumentPayload } from "@hocuspocus/server"; | ||
| import { type ExecutionResult, type Lock, Redlock } from "@sesamecare-oss/redlock"; | ||
| import type { Cluster, ClusterNode, ClusterOptions, RedisOptions } from "ioredis"; | ||
| import RedisClient from "ioredis"; | ||
| export type RedisInstance = RedisClient | Cluster; | ||
| export interface Configuration { | ||
| /** | ||
| * Redis port | ||
| */ | ||
| port: number; | ||
| /** | ||
| * Redis host | ||
| */ | ||
| host: string; | ||
| /** | ||
| * Redis Cluster | ||
| */ | ||
| nodes?: ClusterNode[]; | ||
| /** | ||
| * Duplicate from an existed Redis instance | ||
| */ | ||
| redis?: RedisInstance; | ||
| /** | ||
| * Redis instance creator | ||
| */ | ||
| createClient?: () => RedisInstance; | ||
| /** | ||
| * Options passed directly to Redis constructor | ||
| * | ||
| * https://github.com/luin/ioredis/blob/master/API.md#new-redisport-host-options | ||
| */ | ||
| options?: ClusterOptions | RedisOptions; | ||
| /** | ||
| * An unique instance name, required to filter messages in Redis. | ||
| * If none is provided an unique id is generated. | ||
| */ | ||
| identifier: string; | ||
| /** | ||
| * Namespace for Redis keys, if none is provided 'hocuspocus' is used | ||
| */ | ||
| prefix: string; | ||
| /** | ||
| * The maximum time for the Redis lock in ms (in case it can’t be released). | ||
| */ | ||
| lockTimeout: number; | ||
| /** | ||
| * A delay before onDisconnect is executed. This allows last minute updates' | ||
| * sync messages to be received by the subscription before it's closed. | ||
| */ | ||
| disconnectDelay: number; | ||
| } | ||
| export declare class Redis implements Extension { | ||
| /** | ||
| * Make sure to give that extension a higher priority, so | ||
| * the `onStoreDocument` hook is able to intercept the chain, | ||
| * before documents are stored to the database. | ||
| */ | ||
| priority: number; | ||
| configuration: Configuration; | ||
| redisTransactionOrigin: string; | ||
| pub: RedisInstance; | ||
| sub: RedisInstance; | ||
| instance: Hocuspocus; | ||
| redlock: Redlock; | ||
| locks: Map<string, { | ||
| lock: Lock; | ||
| release?: Promise<ExecutionResult>; | ||
| }>; | ||
| messagePrefix: Buffer; | ||
| private pendingAfterStoreDocumentResolves; | ||
| constructor(configuration: Partial<Configuration>); | ||
| onConfigure({ instance }: onConfigurePayload): Promise<void>; | ||
| private getKey; | ||
| private pubKey; | ||
| private subKey; | ||
| private lockKey; | ||
| private encodeMessage; | ||
| private decodeMessage; | ||
| /** | ||
| * Once a document is loaded, subscribe to the channel in Redis. | ||
| */ | ||
| afterLoadDocument({ documentName, document, }: afterLoadDocumentPayload): Promise<unknown>; | ||
| /** | ||
| * Publish the first sync step through Redis. | ||
| */ | ||
| private publishFirstSyncStep; | ||
| /** | ||
| * Let’s ask Redis who is connected already. | ||
| */ | ||
| private requestAwarenessFromOtherInstances; | ||
| /** | ||
| * Before the document is stored, make sure to set a lock in Redis. | ||
| * That’s meant to avoid conflicts with other instances trying to store the document. | ||
| */ | ||
| onStoreDocument({ documentName }: onStoreDocumentPayload): Promise<void>; | ||
| /** | ||
| * Release the Redis lock, so other instances can store documents. | ||
| */ | ||
| afterStoreDocument({ documentName, socketId, }: afterStoreDocumentPayload): Promise<void>; | ||
| /** | ||
| * Handle awareness update messages received directly by this Hocuspocus instance. | ||
| */ | ||
| onAwarenessUpdate({ documentName, awareness, added, updated, removed, document, }: onAwarenessUpdatePayload): Promise<number | undefined>; | ||
| /** | ||
| * Handle incoming messages published on subscribed document channels. | ||
| * Note that this will also include messages from ourselves as it is not possible | ||
| * in Redis to filter these. | ||
| */ | ||
| private handleIncomingMessage; | ||
| /** | ||
| * if the ydoc changed, we'll need to inform other Hocuspocus servers about it. | ||
| */ | ||
| onChange(data: onChangePayload): Promise<any>; | ||
| /** | ||
| * Delay unloading to allow syncs to finish | ||
| */ | ||
| beforeUnloadDocument(data: beforeUnloadDocumentPayload): Promise<void>; | ||
| afterUnloadDocument(data: afterUnloadDocumentPayload): Promise<void>; | ||
| beforeBroadcastStateless(data: beforeBroadcastStatelessPayload): Promise<number>; | ||
| /** | ||
| * Kill the Redlock connection immediately. | ||
| */ | ||
| onDestroy(): Promise<void>; | ||
| } |
| export * from "./S3.ts"; |
| import type { DatabaseConfiguration } from "@hocuspocus/extension-database"; | ||
| import { Database } from "@hocuspocus/extension-database"; | ||
| import { S3Client } from "@aws-sdk/client-s3"; | ||
| export interface S3Configuration extends DatabaseConfiguration { | ||
| /** | ||
| * AWS S3 region | ||
| */ | ||
| region?: string; | ||
| /** | ||
| * S3 bucket name | ||
| */ | ||
| bucket: string; | ||
| /** | ||
| * S3 key prefix for documents (optional) | ||
| */ | ||
| prefix?: string; | ||
| /** | ||
| * AWS credentials | ||
| */ | ||
| credentials?: { | ||
| accessKeyId: string; | ||
| secretAccessKey: string; | ||
| }; | ||
| /** | ||
| * S3 endpoint URL (for S3-compatible services like MinIO) | ||
| */ | ||
| endpoint?: string; | ||
| /** | ||
| * Force path style URLs (required for MinIO) | ||
| */ | ||
| forcePathStyle?: boolean; | ||
| /** | ||
| * Custom S3 client | ||
| */ | ||
| s3Client?: S3Client; | ||
| } | ||
| export declare class S3 extends Database { | ||
| private s3Client?; | ||
| configuration: S3Configuration; | ||
| constructor(configuration: Partial<S3Configuration>); | ||
| private getObjectKey; | ||
| onConfigure(): Promise<void>; | ||
| onListen(): Promise<void>; | ||
| } |
| export * from "./SQLite.ts"; |
| import type { DatabaseConfiguration } from "@hocuspocus/extension-database"; | ||
| import { Database } from "@hocuspocus/extension-database"; | ||
| import sqlite3 from "sqlite3"; | ||
| export declare const schema = "CREATE TABLE IF NOT EXISTS \"documents\" (\n \"name\" varchar(255) NOT NULL,\n \"data\" blob NOT NULL,\n UNIQUE(name)\n)"; | ||
| export declare const selectQuery = "\n SELECT data FROM \"documents\" WHERE name = $name ORDER BY rowid DESC\n"; | ||
| export declare const upsertQuery = "\n INSERT INTO \"documents\" (\"name\", \"data\") VALUES ($name, $data)\n ON CONFLICT(name) DO UPDATE SET data = $data\n"; | ||
| export interface SQLiteConfiguration extends DatabaseConfiguration { | ||
| /** | ||
| * Valid values are filenames, ":memory:" for an anonymous in-memory database and an empty | ||
| * string for an anonymous disk-based database. Anonymous databases are not persisted and | ||
| * when closing the database handle, their contents are lost. | ||
| * | ||
| * https://github.com/mapbox/node-sqlite3/wiki/API#new-sqlite3databasefilename-mode-callback | ||
| */ | ||
| database: string; | ||
| /** | ||
| * The database schema to create. | ||
| */ | ||
| schema: string; | ||
| } | ||
| export declare class SQLite extends Database { | ||
| db?: sqlite3.Database; | ||
| configuration: SQLiteConfiguration; | ||
| constructor(configuration?: Partial<SQLiteConfiguration>); | ||
| onConfigure(): Promise<void>; | ||
| onListen(): Promise<void>; | ||
| } |
| import type { Extension, onConnectPayload } from "@hocuspocus/server"; | ||
| export interface ThrottleConfiguration { | ||
| throttle: number | null | false; | ||
| consideredSeconds: number; | ||
| banTime: number; | ||
| cleanupInterval: number; | ||
| } | ||
| export declare class Throttle implements Extension { | ||
| configuration: ThrottleConfiguration; | ||
| connectionsByIp: Map<string, Array<number>>; | ||
| bannedIps: Map<string, number>; | ||
| cleanupInterval?: NodeJS.Timeout; | ||
| /** | ||
| * Constructor | ||
| */ | ||
| constructor(configuration?: Partial<ThrottleConfiguration>); | ||
| onDestroy(): Promise<void>; | ||
| clearMaps(): void; | ||
| isBanned(ip: string): boolean; | ||
| /** | ||
| * Throttle requests | ||
| * @private | ||
| */ | ||
| private throttle; | ||
| /** | ||
| * onConnect hook | ||
| * @param data | ||
| */ | ||
| onConnect(data: onConnectPayload): Promise<any>; | ||
| } |
| import type { Extension, onChangePayload, onConnectPayload, onDisconnectPayload, onLoadDocumentPayload } from "@hocuspocus/server"; | ||
| import type { Transformer } from "@hocuspocus/transformer"; | ||
| import type { Doc } from "yjs"; | ||
| export declare enum Events { | ||
| onChange = "change", | ||
| onConnect = "connect", | ||
| onCreate = "create", | ||
| onDisconnect = "disconnect" | ||
| } | ||
| export interface Configuration { | ||
| debounce: number | false | null; | ||
| debounceMaxWait: number; | ||
| secret: string; | ||
| transformer: Transformer | { | ||
| toYdoc: (document: any) => Doc; | ||
| fromYdoc: (document: Doc) => any; | ||
| }; | ||
| url: string; | ||
| events: Array<Events>; | ||
| } | ||
| export declare class Webhook implements Extension { | ||
| configuration: Configuration; | ||
| debounced: Map<string, { | ||
| timeout: NodeJS.Timeout; | ||
| start: number; | ||
| }>; | ||
| /** | ||
| * Constructor | ||
| */ | ||
| constructor(configuration?: Partial<Configuration>); | ||
| /** | ||
| * Create a signature for the response body | ||
| */ | ||
| createSignature(body: string): string; | ||
| /** | ||
| * debounce the given function, using the given identifier | ||
| */ | ||
| debounce(id: string, func: Function): void; | ||
| /** | ||
| * Send a request to the given url containing the given data | ||
| */ | ||
| sendRequest(event: Events, payload: any): Promise<import("axios").AxiosResponse<any, any, {}>>; | ||
| /** | ||
| * onChange hook | ||
| */ | ||
| onChange(data: onChangePayload): Promise<void>; | ||
| /** | ||
| * onLoadDocument hook | ||
| */ | ||
| onLoadDocument(data: onLoadDocumentPayload): Promise<void>; | ||
| /** | ||
| * onConnect hook | ||
| */ | ||
| onConnect(data: onConnectPayload): Promise<any>; | ||
| onDisconnect(data: onDisconnectPayload): Promise<void>; | ||
| } |
| export default class EventEmitter { | ||
| callbacks: { | ||
| [key: string]: Function[]; | ||
| }; | ||
| on(event: string, fn: Function): this; | ||
| protected emit(event: string, ...args: any): this; | ||
| off(event: string, fn?: Function): this; | ||
| removeAllListeners(): void; | ||
| } |
| import type { Event, MessageEvent } from "ws"; | ||
| import { Awareness } from "y-protocols/awareness"; | ||
| import * as Y from "yjs"; | ||
| import EventEmitter from "./EventEmitter.ts"; | ||
| import type { CompleteHocuspocusProviderWebsocketConfiguration } from "./HocuspocusProviderWebsocket.ts"; | ||
| import { HocuspocusProviderWebsocket } from "./HocuspocusProviderWebsocket.ts"; | ||
| import type { AuthorizedScope, ConstructableOutgoingMessage, onAuthenticatedParameters, onAuthenticationFailedParameters, onAwarenessChangeParameters, onAwarenessUpdateParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatelessParameters, onStatusParameters, onSyncedParameters, onUnsyncedChangesParameters } from "./types.ts"; | ||
| export type HocuspocusProviderConfiguration = Required<Pick<CompleteHocuspocusProviderConfiguration, "name">> & Partial<CompleteHocuspocusProviderConfiguration> & ((Required<Pick<CompleteHocuspocusProviderWebsocketConfiguration, "url">> & Partial<Pick<CompleteHocuspocusProviderWebsocketConfiguration, "preserveTrailingSlash">>) | Required<Pick<CompleteHocuspocusProviderConfiguration, "websocketProvider">>); | ||
| export interface CompleteHocuspocusProviderConfiguration { | ||
| /** | ||
| * The identifier/name of your document | ||
| */ | ||
| name: string; | ||
| /** | ||
| * The actual Y.js document | ||
| */ | ||
| document: Y.Doc; | ||
| /** | ||
| * An Awareness instance to keep the presence state of all clients. | ||
| * | ||
| * You can disable sharing awareness information by passing `null`. | ||
| * Note that having no awareness information shared across all connections will break our ping checks | ||
| * and thus trigger reconnects. You should always have at least one Provider with enabled awareness per | ||
| * socket connection, or ensure that the Provider receives messages before running into `HocuspocusProviderWebsocket.messageReconnectTimeout`. | ||
| */ | ||
| awareness: Awareness | null; | ||
| /** | ||
| * A token that’s sent to the backend for authentication purposes. | ||
| */ | ||
| token: string | (() => string) | (() => Promise<string>) | null; | ||
| /** | ||
| * Hocuspocus websocket provider | ||
| */ | ||
| websocketProvider: HocuspocusProviderWebsocket; | ||
| /** | ||
| * Force syncing the document in the defined interval. | ||
| */ | ||
| forceSyncInterval: false | number; | ||
| onAuthenticated: (data: onAuthenticatedParameters) => void; | ||
| onAuthenticationFailed: (data: onAuthenticationFailedParameters) => void; | ||
| onOpen: (data: onOpenParameters) => void; | ||
| onConnect: () => void; | ||
| onStatus: (data: onStatusParameters) => void; | ||
| onMessage: (data: onMessageParameters) => void; | ||
| onOutgoingMessage: (data: onOutgoingMessageParameters) => void; | ||
| onSynced: (data: onSyncedParameters) => void; | ||
| onDisconnect: (data: onDisconnectParameters) => void; | ||
| onClose: (data: onCloseParameters) => void; | ||
| onDestroy: () => void; | ||
| onAwarenessUpdate: (data: onAwarenessUpdateParameters) => void; | ||
| onAwarenessChange: (data: onAwarenessChangeParameters) => void; | ||
| onStateless: (data: onStatelessParameters) => void; | ||
| onUnsyncedChanges: (data: onUnsyncedChangesParameters) => void; | ||
| } | ||
| export declare class AwarenessError extends Error { | ||
| code: number; | ||
| } | ||
| export declare class HocuspocusProvider extends EventEmitter { | ||
| configuration: CompleteHocuspocusProviderConfiguration; | ||
| isSynced: boolean; | ||
| unsyncedChanges: number; | ||
| isAuthenticated: boolean; | ||
| authorizedScope: AuthorizedScope | undefined; | ||
| manageSocket: boolean; | ||
| private _isAttached; | ||
| intervals: any; | ||
| constructor(configuration: HocuspocusProviderConfiguration); | ||
| boundDocumentUpdateHandler: (update: Uint8Array, origin: any) => void; | ||
| boundAwarenessUpdateHandler: ({ added, updated, removed }: any, origin: any) => void; | ||
| boundPageHide: () => void; | ||
| boundOnOpen: (event: Event) => Promise<void>; | ||
| boundOnClose: () => void; | ||
| forwardConnect: () => this; | ||
| forwardStatus: (e: onStatusParameters) => this; | ||
| forwardClose: (e: onCloseParameters) => this; | ||
| forwardDisconnect: (e: onDisconnectParameters) => this; | ||
| forwardDestroy: () => this; | ||
| setConfiguration(configuration?: Partial<HocuspocusProviderConfiguration>): void; | ||
| get document(): Y.Doc; | ||
| get isAttached(): boolean; | ||
| get awareness(): Awareness | null; | ||
| get hasUnsyncedChanges(): boolean; | ||
| private resetUnsyncedChanges; | ||
| incrementUnsyncedChanges(): void; | ||
| decrementUnsyncedChanges(): void; | ||
| forceSync(): void; | ||
| pageHide(): void; | ||
| registerEventListeners(): void; | ||
| sendStateless(payload: string): void; | ||
| sendToken(): Promise<void>; | ||
| documentUpdateHandler(update: Uint8Array, origin: any): void; | ||
| awarenessUpdateHandler({ added, updated, removed }: any, origin: any): void; | ||
| /** | ||
| * Indicates whether a first handshake with the server has been established | ||
| * | ||
| * Note: this does not mean all updates from the client have been persisted to the backend. For this, | ||
| * use `hasUnsyncedChanges`. | ||
| */ | ||
| get synced(): boolean; | ||
| set synced(state: boolean); | ||
| receiveStateless(payload: string): void; | ||
| connect(): Promise<unknown>; | ||
| disconnect(): void; | ||
| onOpen(event: Event): Promise<void>; | ||
| getToken(): Promise<string | null>; | ||
| startSync(): void; | ||
| send(message: ConstructableOutgoingMessage, args: any): void; | ||
| onMessage(event: MessageEvent): void; | ||
| onClose(): void; | ||
| destroy(): void; | ||
| detach(): void; | ||
| attach(): void; | ||
| permissionDeniedHandler(reason: string): void; | ||
| authenticatedHandler(scope: string): void; | ||
| setAwarenessField(key: string, value: any): void; | ||
| } |
| import type { Event, MessageEvent } from "ws"; | ||
| import EventEmitter from "./EventEmitter.ts"; | ||
| import type { HocuspocusProvider } from "./HocuspocusProvider.ts"; | ||
| import { WebSocketStatus, type onAwarenessChangeParameters, type onAwarenessUpdateParameters, type onCloseParameters, type onDisconnectParameters, type onMessageParameters, type onOpenParameters, type onOutgoingMessageParameters, type onStatusParameters } from "./types.ts"; | ||
| export type HocuspocusWebSocket = WebSocket & { | ||
| identifier: string; | ||
| }; | ||
| export type HocusPocusWebSocket = HocuspocusWebSocket; | ||
| export type HocuspocusProviderWebsocketConfiguration = Required<Pick<CompleteHocuspocusProviderWebsocketConfiguration, "url">> & Partial<CompleteHocuspocusProviderWebsocketConfiguration>; | ||
| export interface CompleteHocuspocusProviderWebsocketConfiguration { | ||
| /** | ||
| * Whether to connect automatically when creating the provider instance. Default=true | ||
| */ | ||
| autoConnect: boolean; | ||
| /** | ||
| * URL of your @hocuspocus/server instance | ||
| */ | ||
| url: string; | ||
| /** | ||
| * By default, trailing slashes are removed from the URL. Set this to true | ||
| * to preserve trailing slashes if your server configuration requires them. | ||
| */ | ||
| preserveTrailingSlash: boolean; | ||
| /** | ||
| * An optional WebSocket polyfill, for example for Node.js | ||
| */ | ||
| WebSocketPolyfill: any; | ||
| /** | ||
| * Disconnect when no message is received for the defined amount of milliseconds. | ||
| */ | ||
| messageReconnectTimeout: number; | ||
| /** | ||
| * The delay between each attempt in milliseconds. You can provide a factor to have the delay grow exponentially. | ||
| */ | ||
| delay: number; | ||
| /** | ||
| * The initialDelay is the amount of time to wait before making the first attempt. This option should typically be 0 since you typically want the first attempt to happen immediately. | ||
| */ | ||
| initialDelay: number; | ||
| /** | ||
| * The factor option is used to grow the delay exponentially. | ||
| */ | ||
| factor: number; | ||
| /** | ||
| * The maximum number of attempts or 0 if there is no limit on number of attempts. | ||
| */ | ||
| maxAttempts: number; | ||
| /** | ||
| * minDelay is used to set a lower bound of delay when jitter is enabled. This property has no effect if jitter is disabled. | ||
| */ | ||
| minDelay: number; | ||
| /** | ||
| * The maxDelay option is used to set an upper bound for the delay when factor is enabled. A value of 0 can be provided if there should be no upper bound when calculating delay. | ||
| */ | ||
| maxDelay: number; | ||
| /** | ||
| * If jitter is true then the calculated delay will be a random integer value between minDelay and the calculated delay for the current iteration. | ||
| */ | ||
| jitter: boolean; | ||
| /** | ||
| * A timeout in milliseconds. If timeout is non-zero then a timer is set using setTimeout. If the timeout is triggered then future attempts will be aborted. | ||
| */ | ||
| timeout: number; | ||
| handleTimeout: (() => Promise<unknown>) | null; | ||
| onOpen: (data: onOpenParameters) => void; | ||
| onConnect: () => void; | ||
| onMessage: (data: onMessageParameters) => void; | ||
| onOutgoingMessage: (data: onOutgoingMessageParameters) => void; | ||
| onStatus: (data: onStatusParameters) => void; | ||
| onDisconnect: (data: onDisconnectParameters) => void; | ||
| onClose: (data: onCloseParameters) => void; | ||
| onDestroy: () => void; | ||
| onAwarenessUpdate: (data: onAwarenessUpdateParameters) => void; | ||
| onAwarenessChange: (data: onAwarenessChangeParameters) => void; | ||
| /** | ||
| * Map of attached providers keyed by documentName. | ||
| */ | ||
| providerMap: Map<string, HocuspocusProvider>; | ||
| } | ||
| export declare class HocuspocusProviderWebsocket extends EventEmitter { | ||
| private messageQueue; | ||
| configuration: CompleteHocuspocusProviderWebsocketConfiguration; | ||
| webSocket: HocusPocusWebSocket | null; | ||
| webSocketHandlers: { | ||
| [key: string]: any; | ||
| }; | ||
| shouldConnect: boolean; | ||
| status: WebSocketStatus; | ||
| lastMessageReceived: number; | ||
| identifier: number; | ||
| intervals: any; | ||
| connectionAttempt: { | ||
| resolve: (value?: any) => void; | ||
| reject: (reason?: any) => void; | ||
| } | null; | ||
| constructor(configuration: HocuspocusProviderWebsocketConfiguration); | ||
| receivedOnOpenPayload?: Event | undefined; | ||
| onOpen(event: Event): Promise<void>; | ||
| attach(provider: HocuspocusProvider): void; | ||
| detach(provider: HocuspocusProvider): void; | ||
| setConfiguration(configuration?: Partial<HocuspocusProviderWebsocketConfiguration>): void; | ||
| cancelWebsocketRetry?: () => void; | ||
| connect(): Promise<unknown>; | ||
| attachWebSocketListeners(ws: HocusPocusWebSocket, reject: Function): void; | ||
| cleanupWebSocket(): void; | ||
| createWebSocketConnection(): Promise<unknown>; | ||
| onMessage(event: MessageEvent): void; | ||
| resolveConnectionAttempt(): void; | ||
| stopConnectionAttempt(): void; | ||
| rejectConnectionAttempt(): void; | ||
| closeTries: number; | ||
| checkConnection(): void; | ||
| get serverUrl(): string; | ||
| get url(): string; | ||
| disconnect(): void; | ||
| send(message: any): void; | ||
| onClose({ event }: onCloseParameters): void; | ||
| destroy(): void; | ||
| } |
| import type { Decoder } from "lib0/decoding"; | ||
| import type { Encoder } from "lib0/encoding"; | ||
| import type { MessageType } from "./types.ts"; | ||
| export declare class IncomingMessage { | ||
| data: any; | ||
| encoder: Encoder; | ||
| decoder: Decoder; | ||
| constructor(data: any); | ||
| peekVarString(): string; | ||
| readVarUint(): MessageType; | ||
| readVarString(): string; | ||
| readVarUint8Array(): Uint8Array<ArrayBufferLike>; | ||
| writeVarUint(type: MessageType): void; | ||
| writeVarString(string: string): void; | ||
| writeVarUint8Array(data: Uint8Array): void; | ||
| length(): number; | ||
| } |
| export * from "./HocuspocusProvider.ts"; | ||
| export * from "./HocuspocusProviderWebsocket.ts"; | ||
| export * from "./types.ts"; |
| import type { HocuspocusProvider } from "./HocuspocusProvider.ts"; | ||
| import type { IncomingMessage } from "./IncomingMessage.ts"; | ||
| export declare class MessageReceiver { | ||
| message: IncomingMessage; | ||
| constructor(message: IncomingMessage); | ||
| apply(provider: HocuspocusProvider, emitSynced: boolean): void; | ||
| private applySyncMessage; | ||
| applySyncStatusMessage(provider: HocuspocusProvider, applied: boolean): void; | ||
| private applyAwarenessMessage; | ||
| private applyAuthMessage; | ||
| private applyQueryAwarenessMessage; | ||
| } |
| import type { Encoder } from "lib0/encoding"; | ||
| import type { ConstructableOutgoingMessage } from "./types.ts"; | ||
| export declare class MessageSender { | ||
| encoder: Encoder; | ||
| message: any; | ||
| constructor(Message: ConstructableOutgoingMessage, args?: any); | ||
| create(): Uint8Array<ArrayBufferLike>; | ||
| send(webSocket: any): void; | ||
| } |
| import type { Encoder } from "lib0/encoding"; | ||
| import type { MessageType, OutgoingMessageArguments, OutgoingMessageInterface } from "./types.ts"; | ||
| export declare class OutgoingMessage implements OutgoingMessageInterface { | ||
| encoder: Encoder; | ||
| type?: MessageType; | ||
| constructor(); | ||
| get(args: Partial<OutgoingMessageArguments>): Encoder | undefined; | ||
| toUint8Array(): Uint8Array<ArrayBufferLike>; | ||
| } |
| import type { OutgoingMessageArguments } from "../types.ts"; | ||
| import { MessageType } from "../types.ts"; | ||
| import { OutgoingMessage } from "../OutgoingMessage.ts"; | ||
| export declare class AuthenticationMessage extends OutgoingMessage { | ||
| type: MessageType; | ||
| description: string; | ||
| get(args: Partial<OutgoingMessageArguments>): import("lib0/encoding").Encoder; | ||
| } |
| import * as encoding from "lib0/encoding"; | ||
| import type { OutgoingMessageArguments } from "../types.ts"; | ||
| import { MessageType } from "../types.ts"; | ||
| import { OutgoingMessage } from "../OutgoingMessage.ts"; | ||
| export declare class AwarenessMessage extends OutgoingMessage { | ||
| type: MessageType; | ||
| description: string; | ||
| get(args: Partial<OutgoingMessageArguments>): encoding.Encoder; | ||
| } |
| import * as encoding from "lib0/encoding"; | ||
| import type { OutgoingMessageArguments } from "../types.ts"; | ||
| import { MessageType } from "../types.ts"; | ||
| import { OutgoingMessage } from "../OutgoingMessage.ts"; | ||
| export declare class CloseMessage extends OutgoingMessage { | ||
| type: MessageType; | ||
| description: string; | ||
| get(args: Partial<OutgoingMessageArguments>): encoding.Encoder; | ||
| } |
| import * as encoding from "lib0/encoding"; | ||
| import type { OutgoingMessageArguments } from "../types.ts"; | ||
| import { MessageType } from "../types.ts"; | ||
| import { OutgoingMessage } from "../OutgoingMessage.ts"; | ||
| export declare class QueryAwarenessMessage extends OutgoingMessage { | ||
| type: MessageType; | ||
| description: string; | ||
| get(args: Partial<OutgoingMessageArguments>): encoding.Encoder; | ||
| } |
| import type { OutgoingMessageArguments } from "../types.ts"; | ||
| import { MessageType } from "../types.ts"; | ||
| import { OutgoingMessage } from "../OutgoingMessage.ts"; | ||
| export declare class StatelessMessage extends OutgoingMessage { | ||
| type: MessageType; | ||
| description: string; | ||
| get(args: Partial<OutgoingMessageArguments>): import("lib0/encoding").Encoder; | ||
| } |
| import * as encoding from "lib0/encoding"; | ||
| import type { OutgoingMessageArguments } from "../types.ts"; | ||
| import { MessageType } from "../types.ts"; | ||
| import { OutgoingMessage } from "../OutgoingMessage.ts"; | ||
| export declare class SyncStepOneMessage extends OutgoingMessage { | ||
| type: MessageType; | ||
| description: string; | ||
| get(args: Partial<OutgoingMessageArguments>): encoding.Encoder; | ||
| } |
| import * as encoding from "lib0/encoding"; | ||
| import type { OutgoingMessageArguments } from "../types.ts"; | ||
| import { MessageType } from "../types.ts"; | ||
| import { OutgoingMessage } from "../OutgoingMessage.ts"; | ||
| export declare class SyncStepTwoMessage extends OutgoingMessage { | ||
| type: MessageType; | ||
| description: string; | ||
| get(args: Partial<OutgoingMessageArguments>): encoding.Encoder; | ||
| } |
| import type { OutgoingMessageArguments } from "../types.ts"; | ||
| import { MessageType } from "../types.ts"; | ||
| import { OutgoingMessage } from "../OutgoingMessage.ts"; | ||
| export declare class UpdateMessage extends OutgoingMessage { | ||
| type: MessageType; | ||
| description: string; | ||
| get(args: Partial<OutgoingMessageArguments>): import("lib0/encoding").Encoder; | ||
| } |
| import type { Encoder } from "lib0/encoding"; | ||
| import type { Event, MessageEvent } from "ws"; | ||
| import type { Awareness } from "y-protocols/awareness"; | ||
| import type * as Y from "yjs"; | ||
| import type { CloseEvent } from "@hocuspocus/common"; | ||
| import type { IncomingMessage } from "./IncomingMessage.ts"; | ||
| import type { OutgoingMessage } from "./OutgoingMessage.ts"; | ||
| import type { AuthenticationMessage } from "./OutgoingMessages/AuthenticationMessage.ts"; | ||
| import type { AwarenessMessage } from "./OutgoingMessages/AwarenessMessage.ts"; | ||
| import type { QueryAwarenessMessage } from "./OutgoingMessages/QueryAwarenessMessage.ts"; | ||
| import type { SyncStepOneMessage } from "./OutgoingMessages/SyncStepOneMessage.ts"; | ||
| import type { SyncStepTwoMessage } from "./OutgoingMessages/SyncStepTwoMessage.ts"; | ||
| import type { UpdateMessage } from "./OutgoingMessages/UpdateMessage.ts"; | ||
| export declare enum MessageType { | ||
| Sync = 0, | ||
| Awareness = 1, | ||
| Auth = 2, | ||
| QueryAwareness = 3, | ||
| Stateless = 5, | ||
| CLOSE = 7, | ||
| SyncStatus = 8 | ||
| } | ||
| export declare enum WebSocketStatus { | ||
| Connecting = "connecting", | ||
| Connected = "connected", | ||
| Disconnected = "disconnected" | ||
| } | ||
| export type AuthorizedScope = "read-write" | "readonly"; | ||
| export interface OutgoingMessageInterface { | ||
| encoder: Encoder; | ||
| type?: MessageType; | ||
| } | ||
| export interface OutgoingMessageArguments { | ||
| documentName: string; | ||
| token: string; | ||
| document: Y.Doc; | ||
| awareness: Awareness; | ||
| clients: number[]; | ||
| states: Map<number, { | ||
| [key: string]: any; | ||
| }>; | ||
| update: any; | ||
| payload: string; | ||
| encoder: Encoder; | ||
| } | ||
| export interface Constructable<T> { | ||
| new (...args: any): T; | ||
| } | ||
| export type ConstructableOutgoingMessage = Constructable<AuthenticationMessage> | Constructable<AwarenessMessage> | Constructable<QueryAwarenessMessage> | Constructable<SyncStepOneMessage> | Constructable<SyncStepTwoMessage> | Constructable<UpdateMessage>; | ||
| export type onAuthenticationFailedParameters = { | ||
| reason: string; | ||
| }; | ||
| export type onAuthenticatedParameters = { | ||
| scope: AuthorizedScope; | ||
| }; | ||
| export type onOpenParameters = { | ||
| event: Event; | ||
| }; | ||
| export type onMessageParameters = { | ||
| event: MessageEvent; | ||
| message: IncomingMessage; | ||
| }; | ||
| export type onOutgoingMessageParameters = { | ||
| message: OutgoingMessage; | ||
| }; | ||
| export type onStatusParameters = { | ||
| status: WebSocketStatus; | ||
| }; | ||
| export type onSyncedParameters = { | ||
| state: boolean; | ||
| }; | ||
| export type onUnsyncedChangesParameters = { | ||
| number: number; | ||
| }; | ||
| export type onDisconnectParameters = { | ||
| event: CloseEvent; | ||
| }; | ||
| export type onCloseParameters = { | ||
| event: CloseEvent; | ||
| }; | ||
| export type onAwarenessUpdateParameters = { | ||
| states: StatesArray; | ||
| }; | ||
| export type onAwarenessChangeParameters = { | ||
| states: StatesArray; | ||
| }; | ||
| export type onStatelessParameters = { | ||
| payload: string; | ||
| }; | ||
| export type StatesArray = { | ||
| clientId: number; | ||
| [key: string | number]: any; | ||
| }[]; |
| import type { IncomingMessage } from "node:http"; | ||
| import { type CloseEvent } from "@hocuspocus/common"; | ||
| import type WebSocket from "ws"; | ||
| import type Document from "./Document.ts"; | ||
| import type { Hocuspocus } from "./Hocuspocus.ts"; | ||
| import type { onDisconnectPayload } from "./types.ts"; | ||
| /** | ||
| * The `ClientConnection` class is responsible for handling an incoming WebSocket | ||
| * | ||
| * TODO-refactor: | ||
| * - use event handlers instead of calling hooks directly, hooks should probably be called from Hocuspocus.ts | ||
| */ | ||
| export declare class ClientConnection { | ||
| private readonly websocket; | ||
| private readonly request; | ||
| private readonly documentProvider; | ||
| private readonly hooks; | ||
| private readonly opts; | ||
| private readonly defaultContext; | ||
| private readonly documentConnections; | ||
| private readonly incomingMessageQueue; | ||
| private readonly documentConnectionsEstablished; | ||
| private readonly hookPayloads; | ||
| private readonly callbacks; | ||
| private readonly socketId; | ||
| timeout: number; | ||
| pingInterval: NodeJS.Timeout; | ||
| pongReceived: boolean; | ||
| /** | ||
| * The `ClientConnection` class receives incoming WebSocket connections, | ||
| * runs all hooks: | ||
| * | ||
| * - onConnect for all connections | ||
| * - onAuthenticate only if required | ||
| * | ||
| * … and if nothings fails it’ll fully establish the connection and | ||
| * load the Document then. | ||
| */ | ||
| constructor(websocket: WebSocket, request: IncomingMessage, documentProvider: { | ||
| createDocument: Hocuspocus["createDocument"]; | ||
| }, hooks: Hocuspocus["hooks"], opts: { | ||
| timeout: number; | ||
| }, defaultContext?: any); | ||
| private handleWebsocketClose; | ||
| close(event?: CloseEvent): void; | ||
| handlePong: () => void; | ||
| /** | ||
| * Check if pong was received and close the connection otherwise | ||
| * @private | ||
| */ | ||
| private check; | ||
| /** | ||
| * Set a callback that will be triggered when the connection is closed | ||
| */ | ||
| onClose(callback: (document: Document, payload: onDisconnectPayload) => void): ClientConnection; | ||
| /** | ||
| * Create a new connection by the given request and document | ||
| */ | ||
| private createConnection; | ||
| private setUpNewConnection; | ||
| private handleQueueingMessage; | ||
| private messageHandler; | ||
| } |
| import type { IncomingMessage as HTTPIncomingMessage } from "node:http"; | ||
| import { type CloseEvent } from "@hocuspocus/common"; | ||
| import type WebSocket from "ws"; | ||
| import type Document from "./Document.ts"; | ||
| import type { beforeSyncPayload, onStatelessPayload } from "./types.ts"; | ||
| export declare class Connection { | ||
| webSocket: WebSocket; | ||
| context: any; | ||
| document: Document; | ||
| request: HTTPIncomingMessage; | ||
| callbacks: { | ||
| onClose: ((document: Document, event?: CloseEvent) => void)[]; | ||
| beforeHandleMessage: (connection: Connection, update: Uint8Array) => Promise<void>; | ||
| beforeSync: (connection: Connection, payload: Pick<beforeSyncPayload, "type" | "payload">) => Promise<void>; | ||
| statelessCallback: (payload: onStatelessPayload) => Promise<void>; | ||
| onTokenSyncCallback: (payload: { | ||
| token: string; | ||
| }) => Promise<void>; | ||
| }; | ||
| socketId: string; | ||
| readOnly: boolean; | ||
| /** | ||
| * Constructor. | ||
| */ | ||
| constructor(connection: WebSocket, request: HTTPIncomingMessage, document: Document, socketId: string, context: any, readOnly?: boolean); | ||
| /** | ||
| * Set a callback that will be triggered when the connection is closed | ||
| */ | ||
| onClose(callback: (document: Document, event?: CloseEvent) => void): Connection; | ||
| /** | ||
| * Set a callback that will be triggered when an stateless message is received | ||
| */ | ||
| onStatelessCallback(callback: (payload: onStatelessPayload) => Promise<void>): Connection; | ||
| /** | ||
| * Set a callback that will be triggered before an message is handled | ||
| */ | ||
| beforeHandleMessage(callback: (connection: Connection, update: Uint8Array) => Promise<any>): Connection; | ||
| /** | ||
| * Set a callback that will be triggered before a sync message is handled | ||
| */ | ||
| beforeSync(callback: (connection: Connection, payload: Pick<beforeSyncPayload, "type" | "payload">) => Promise<any>): Connection; | ||
| /** | ||
| * Set a callback that will be triggered when on token sync message is received | ||
| */ | ||
| onTokenSyncCallback(callback: (payload: { | ||
| token: string; | ||
| }) => Promise<void>): Connection; | ||
| /** | ||
| * Send the given message | ||
| */ | ||
| send(message: any): void; | ||
| /** | ||
| * Send a stateless message with payload | ||
| */ | ||
| sendStateless(payload: string): void; | ||
| /** | ||
| * Request current token from the client | ||
| */ | ||
| requestToken(): void; | ||
| /** | ||
| * Graceful wrapper around the WebSocket close method. | ||
| */ | ||
| close(event?: CloseEvent): void; | ||
| /** | ||
| * Send the current document awareness to the client, if any | ||
| * @private | ||
| */ | ||
| private sendCurrentAwareness; | ||
| /** | ||
| * Handle an incoming message | ||
| * @public | ||
| */ | ||
| handleMessage(data: Uint8Array): void; | ||
| } | ||
| export default Connection; |
| import type Document from "./Document.ts"; | ||
| import type { Hocuspocus } from "./Hocuspocus.ts"; | ||
| import type { DirectConnection as DirectConnectionInterface } from "./types.ts"; | ||
| export declare class DirectConnection implements DirectConnectionInterface { | ||
| document: Document | null; | ||
| instance: Hocuspocus; | ||
| context: any; | ||
| /** | ||
| * Constructor. | ||
| */ | ||
| constructor(document: Document, instance: Hocuspocus, context?: any); | ||
| transact(transaction: (document: Document) => void): Promise<void>; | ||
| disconnect(): Promise<void>; | ||
| } |
| import { Mutex } from "async-mutex"; | ||
| import type WebSocket from "ws"; | ||
| import { Awareness } from "y-protocols/awareness"; | ||
| import { Doc } from "yjs"; | ||
| import type Connection from "./Connection.ts"; | ||
| export declare class Document extends Doc { | ||
| awareness: Awareness; | ||
| callbacks: { | ||
| onUpdate: (document: Document, connection: Connection, update: Uint8Array) => void; | ||
| beforeBroadcastStateless: (document: Document, stateless: string) => void; | ||
| }; | ||
| connections: Map<WebSocket, { | ||
| clients: Set<any>; | ||
| connection: Connection; | ||
| }>; | ||
| directConnectionsCount: number; | ||
| name: string; | ||
| isLoading: boolean; | ||
| isDestroyed: boolean; | ||
| saveMutex: Mutex; | ||
| lastChangeTime: number; | ||
| /** | ||
| * Constructor. | ||
| */ | ||
| constructor(name: string, yDocOptions?: object); | ||
| /** | ||
| * Check if the Document (XMLFragment or Map) is empty | ||
| */ | ||
| isEmpty(fieldName: string): boolean; | ||
| /** | ||
| * Merge the given document(s) into this one | ||
| */ | ||
| merge(documents: Doc | Array<Doc>): Document; | ||
| /** | ||
| * Set a callback that will be triggered when the document is updated | ||
| */ | ||
| onUpdate(callback: (document: Document, connection: Connection, update: Uint8Array) => void): Document; | ||
| /** | ||
| * Set a callback that will be triggered before a stateless message is broadcasted | ||
| */ | ||
| beforeBroadcastStateless(callback: (document: Document, stateless: string) => void): Document; | ||
| /** | ||
| * Register a connection and a set of clients on this document keyed by the | ||
| * underlying websocket connection | ||
| */ | ||
| addConnection(connection: Connection): Document; | ||
| /** | ||
| * Is the given connection registered on this document | ||
| */ | ||
| hasConnection(connection: Connection): boolean; | ||
| /** | ||
| * Remove the given connection from this document | ||
| */ | ||
| removeConnection(connection: Connection): Document; | ||
| addDirectConnection(): Document; | ||
| removeDirectConnection(): Document; | ||
| /** | ||
| * Get the number of active connections for this document | ||
| */ | ||
| getConnectionsCount(): number; | ||
| /** | ||
| * Get an array of registered connections | ||
| */ | ||
| getConnections(): Array<Connection>; | ||
| /** | ||
| * Get the client ids for the given connection instance | ||
| */ | ||
| getClients(connectionInstance: WebSocket): Set<any>; | ||
| /** | ||
| * Has the document awareness states | ||
| */ | ||
| hasAwarenessStates(): boolean; | ||
| /** | ||
| * Apply the given awareness update | ||
| */ | ||
| applyAwarenessUpdate(connection: Connection, update: Uint8Array): Document; | ||
| /** | ||
| * Handle an awareness update and sync changes to clients | ||
| * @private | ||
| */ | ||
| private handleAwarenessUpdate; | ||
| /** | ||
| * Handle an updated document and sync changes to clients | ||
| */ | ||
| private handleUpdate; | ||
| /** | ||
| * Broadcast stateless message to all connections | ||
| */ | ||
| broadcastStateless(payload: string, filter?: (conn: Connection) => boolean): void; | ||
| destroy(): void; | ||
| } | ||
| export default Document; |
| import type { IncomingMessage } from "node:http"; | ||
| import type WebSocket from "ws"; | ||
| import { DirectConnection } from "./DirectConnection.ts"; | ||
| import Document from "./Document.ts"; | ||
| import type { Server } from "./Server.ts"; | ||
| import type { Configuration, ConnectionConfiguration, HookName, HookPayloadByName, onStoreDocumentPayload } from "./types.ts"; | ||
| export declare const defaultConfiguration: { | ||
| name: null; | ||
| timeout: number; | ||
| debounce: number; | ||
| maxDebounce: number; | ||
| quiet: boolean; | ||
| yDocOptions: { | ||
| gc: boolean; | ||
| gcFilter: () => boolean; | ||
| }; | ||
| unloadImmediately: boolean; | ||
| }; | ||
| export declare class Hocuspocus { | ||
| configuration: Configuration; | ||
| loadingDocuments: Map<string, Promise<Document>>; | ||
| unloadingDocuments: Map<string, Promise<void>>; | ||
| documents: Map<string, Document>; | ||
| server?: Server; | ||
| debouncer: { | ||
| debounce: (id: string, func: () => any | Promise<() => any>, debounce: number, maxDebounce: number) => Promise<any>; | ||
| isDebounced: (id: string) => boolean; | ||
| isCurrentlyExecuting: (id: string) => boolean; | ||
| executeNow: (id: string) => any; | ||
| }; | ||
| constructor(configuration?: Partial<Configuration>); | ||
| /** | ||
| * Configure Hocuspocus | ||
| */ | ||
| configure(configuration: Partial<Configuration>): Hocuspocus; | ||
| /** | ||
| * Get the total number of active documents | ||
| */ | ||
| getDocumentsCount(): number; | ||
| /** | ||
| * Get the total number of active connections | ||
| */ | ||
| getConnectionsCount(): number; | ||
| /** | ||
| * Force close one or more connections | ||
| */ | ||
| closeConnections(documentName?: string): void; | ||
| /** | ||
| * The `handleConnection` method receives incoming WebSocket connections, | ||
| * runs all hooks: | ||
| * | ||
| * - onConnect for all connections | ||
| * - onAuthenticate only if required | ||
| * | ||
| * … and if nothing fails it’ll fully establish the connection and | ||
| * load the Document then. | ||
| */ | ||
| handleConnection(incoming: WebSocket, request: IncomingMessage, defaultContext?: any): void; | ||
| /** | ||
| * Handle update of the given document | ||
| * | ||
| * "connection" is not necessarily type "Connection", it's the Yjs "origin" (which is "Connection" if | ||
| * the update is incoming from the provider, but can be anything if the updates is originated from an extension. | ||
| */ | ||
| private handleDocumentUpdate; | ||
| /** | ||
| * Create a new document by the given request | ||
| */ | ||
| createDocument(documentName: string, request: Partial<Pick<IncomingMessage, "headers" | "url">>, socketId: string, connection: ConnectionConfiguration, context?: any): Promise<Document>; | ||
| loadDocument(documentName: string, request: Partial<Pick<IncomingMessage, "headers" | "url">>, socketId: string, connectionConfig: ConnectionConfiguration, context?: any): Promise<Document>; | ||
| storeDocumentHooks(document: Document, hookPayload: onStoreDocumentPayload, immediately?: boolean): Promise<any>; | ||
| /** | ||
| * Run the given hook on all configured extensions. | ||
| * Runs the given callback after each hook. | ||
| */ | ||
| hooks<T extends HookName>(name: T, payload: HookPayloadByName[T], callback?: Function | null): Promise<any>; | ||
| shouldUnloadDocument(document: Document): boolean; | ||
| unloadDocument(document: Document): Promise<any>; | ||
| openDirectConnection(documentName: string, context?: any): Promise<DirectConnection>; | ||
| } |
| import type { Decoder } from "lib0/decoding"; | ||
| import type { Encoder } from "lib0/encoding"; | ||
| import type { MessageType } from "./types.ts"; | ||
| export declare class IncomingMessage { | ||
| /** | ||
| * Access to the received message. | ||
| */ | ||
| decoder: Decoder; | ||
| /** | ||
| * Private encoder; can be undefined. | ||
| * | ||
| * Lazy creation of the encoder speeds up IncomingMessages that need only a decoder. | ||
| */ | ||
| private encoderInternal?; | ||
| constructor(input: any); | ||
| get encoder(): Encoder; | ||
| readVarUint8Array(): Uint8Array<ArrayBufferLike>; | ||
| peekVarUint8Array(): Uint8Array<ArrayBufferLike>; | ||
| readVarUint(): number; | ||
| readVarString(): string; | ||
| toUint8Array(): Uint8Array<ArrayBufferLike>; | ||
| writeVarUint(type: MessageType): void; | ||
| writeVarString(string: string): void; | ||
| get length(): number; | ||
| } |
| export * from "./Connection.ts"; | ||
| export * from "./Document.ts"; | ||
| export * from "./Hocuspocus.ts"; | ||
| export * from "./IncomingMessage.ts"; | ||
| export * from "./MessageReceiver.ts"; | ||
| export * from "./OutgoingMessage.ts"; | ||
| export * from "./Server.ts"; | ||
| export * from "./types.ts"; | ||
| export * from "./util/debounce.ts"; |
| import type Connection from "./Connection.ts"; | ||
| import type Document from "./Document.ts"; | ||
| import type { IncomingMessage } from "./IncomingMessage.ts"; | ||
| export declare class MessageReceiver { | ||
| message: IncomingMessage; | ||
| defaultTransactionOrigin?: string; | ||
| constructor(message: IncomingMessage, defaultTransactionOrigin?: string); | ||
| apply(document: Document, connection?: Connection, reply?: (message: Uint8Array) => void): void; | ||
| readSyncMessage(message: IncomingMessage, document: Document, connection?: Connection, reply?: (message: Uint8Array) => void, requestFirstSync?: boolean): 0 | 2 | 1; | ||
| applyQueryAwarenessMessage(document: Document, reply?: (message: Uint8Array) => void): void; | ||
| } |
| import type { Encoder } from "lib0/encoding"; | ||
| import type { Awareness } from "y-protocols/awareness"; | ||
| import type Document from "./Document.ts"; | ||
| export declare class OutgoingMessage { | ||
| encoder: Encoder; | ||
| type?: number; | ||
| category?: string; | ||
| constructor(documentName: string); | ||
| createSyncMessage(): OutgoingMessage; | ||
| createSyncReplyMessage(): OutgoingMessage; | ||
| createAwarenessUpdateMessage(awareness: Awareness, changedClients?: Array<any>): OutgoingMessage; | ||
| writeQueryAwareness(): OutgoingMessage; | ||
| writeTokenSyncRequest(): OutgoingMessage; | ||
| writeAuthenticated(readonly: boolean): OutgoingMessage; | ||
| writePermissionDenied(reason: string): OutgoingMessage; | ||
| writeFirstSyncStepFor(document: Document): OutgoingMessage; | ||
| writeUpdate(update: Uint8Array): OutgoingMessage; | ||
| writeStateless(payload: string): OutgoingMessage; | ||
| writeBroadcastStateless(payload: string): OutgoingMessage; | ||
| writeSyncStatus(updateSaved: boolean): OutgoingMessage; | ||
| writeCloseMessage(reason: string): OutgoingMessage; | ||
| toUint8Array(): Uint8Array; | ||
| } |
| import type { Server as HTTPServer, IncomingMessage, ServerResponse } from "node:http"; | ||
| import { WebSocketServer } from "ws"; | ||
| import type { AddressInfo, ServerOptions } from "ws"; | ||
| import { Hocuspocus } from "./Hocuspocus.ts"; | ||
| import type { Configuration } from "./types.ts"; | ||
| export interface ServerConfiguration extends Configuration { | ||
| port?: number; | ||
| address?: string; | ||
| stopOnSignals?: boolean; | ||
| } | ||
| export declare const defaultServerConfiguration: { | ||
| port: number; | ||
| address: string; | ||
| stopOnSignals: boolean; | ||
| }; | ||
| export declare class Server { | ||
| httpServer: HTTPServer; | ||
| webSocketServer: WebSocketServer; | ||
| hocuspocus: Hocuspocus; | ||
| configuration: ServerConfiguration; | ||
| constructor(configuration?: Partial<ServerConfiguration>, websocketOptions?: ServerOptions); | ||
| setupWebsocketConnection: () => void; | ||
| setupHttpUpgrade: () => void; | ||
| requestHandler: (request: IncomingMessage, response: ServerResponse) => Promise<void>; | ||
| listen(port?: number, callback?: any): Promise<Hocuspocus>; | ||
| get address(): AddressInfo; | ||
| destroy(): Promise<any>; | ||
| get URL(): string; | ||
| get webSocketURL(): string; | ||
| get httpURL(): string; | ||
| private showStartScreen; | ||
| } |
| import type { IncomingHttpHeaders, IncomingMessage, ServerResponse } from "node:http"; | ||
| import type { URLSearchParams } from "node:url"; | ||
| import type { Awareness } from "y-protocols/awareness"; | ||
| import type Connection from "./Connection.ts"; | ||
| import type Document from "./Document.ts"; | ||
| import type { Hocuspocus } from "./Hocuspocus.ts"; | ||
| export declare enum MessageType { | ||
| Unknown = -1, | ||
| Sync = 0, | ||
| Awareness = 1, | ||
| Auth = 2, | ||
| QueryAwareness = 3, | ||
| SyncReply = 4,// same as Sync, but won't trigger another 'SyncStep1' | ||
| Stateless = 5, | ||
| BroadcastStateless = 6, | ||
| CLOSE = 7, | ||
| SyncStatus = 8 | ||
| } | ||
| export interface AwarenessUpdate { | ||
| added: Array<any>; | ||
| updated: Array<any>; | ||
| removed: Array<any>; | ||
| } | ||
| export interface ConnectionConfiguration { | ||
| readOnly: boolean; | ||
| isAuthenticated: boolean; | ||
| } | ||
| export interface Extension { | ||
| priority?: number; | ||
| extensionName?: string; | ||
| onConfigure?(data: onConfigurePayload): Promise<any>; | ||
| onListen?(data: onListenPayload): Promise<any>; | ||
| onUpgrade?(data: onUpgradePayload): Promise<any>; | ||
| onConnect?(data: onConnectPayload): Promise<any>; | ||
| connected?(data: connectedPayload): Promise<any>; | ||
| onAuthenticate?(data: onAuthenticatePayload): Promise<any>; | ||
| onTokenSync?(data: onTokenSyncPayload): Promise<any>; | ||
| onCreateDocument?(data: onCreateDocumentPayload): Promise<any>; | ||
| onLoadDocument?(data: onLoadDocumentPayload): Promise<any>; | ||
| afterLoadDocument?(data: afterLoadDocumentPayload): Promise<any>; | ||
| beforeHandleMessage?(data: beforeHandleMessagePayload): Promise<any>; | ||
| beforeSync?(data: beforeSyncPayload): Promise<any>; | ||
| beforeBroadcastStateless?(data: beforeBroadcastStatelessPayload): Promise<any>; | ||
| onStateless?(payload: onStatelessPayload): Promise<any>; | ||
| onChange?(data: onChangePayload): Promise<any>; | ||
| onStoreDocument?(data: onStoreDocumentPayload): Promise<any>; | ||
| afterStoreDocument?(data: afterStoreDocumentPayload): Promise<any>; | ||
| onAwarenessUpdate?(data: onAwarenessUpdatePayload): Promise<any>; | ||
| onRequest?(data: onRequestPayload): Promise<any>; | ||
| onDisconnect?(data: onDisconnectPayload): Promise<any>; | ||
| beforeUnloadDocument?(data: beforeUnloadDocumentPayload): Promise<any>; | ||
| afterUnloadDocument?(data: afterUnloadDocumentPayload): Promise<any>; | ||
| onDestroy?(data: onDestroyPayload): Promise<any>; | ||
| } | ||
| export type HookName = "onConfigure" | "onListen" | "onUpgrade" | "onConnect" | "connected" | "onAuthenticate" | "onTokenSync" | "onCreateDocument" | "onLoadDocument" | "afterLoadDocument" | "beforeHandleMessage" | "beforeBroadcastStateless" | "beforeSync" | "onStateless" | "onChange" | "onStoreDocument" | "afterStoreDocument" | "onAwarenessUpdate" | "onRequest" | "onDisconnect" | "beforeUnloadDocument" | "afterUnloadDocument" | "onDestroy"; | ||
| export type HookPayloadByName = { | ||
| onConfigure: onConfigurePayload; | ||
| onListen: onListenPayload; | ||
| onUpgrade: onUpgradePayload; | ||
| onConnect: onConnectPayload; | ||
| connected: connectedPayload; | ||
| onAuthenticate: onAuthenticatePayload; | ||
| onTokenSync: onTokenSyncPayload; | ||
| onCreateDocument: onCreateDocumentPayload; | ||
| onLoadDocument: onLoadDocumentPayload; | ||
| afterLoadDocument: afterLoadDocumentPayload; | ||
| beforeHandleMessage: beforeHandleMessagePayload; | ||
| beforeBroadcastStateless: beforeBroadcastStatelessPayload; | ||
| beforeSync: beforeSyncPayload; | ||
| onStateless: onStatelessPayload; | ||
| onChange: onChangePayload; | ||
| onStoreDocument: onStoreDocumentPayload; | ||
| afterStoreDocument: afterStoreDocumentPayload; | ||
| onAwarenessUpdate: onAwarenessUpdatePayload; | ||
| onRequest: onRequestPayload; | ||
| onDisconnect: onDisconnectPayload; | ||
| afterUnloadDocument: afterUnloadDocumentPayload; | ||
| beforeUnloadDocument: beforeUnloadDocumentPayload; | ||
| onDestroy: onDestroyPayload; | ||
| }; | ||
| export interface Configuration extends Extension { | ||
| /** | ||
| * A name for the instance, used for logging. | ||
| */ | ||
| name: string | null; | ||
| /** | ||
| * A list of hocuspocus extensions. | ||
| */ | ||
| extensions: Array<Extension>; | ||
| /** | ||
| * Defines in which interval the server sends a ping, and closes the connection when no pong is sent back. | ||
| */ | ||
| timeout: number; | ||
| /** | ||
| * Debounces the call of the `onStoreDocument` hook for the given amount of time in ms. | ||
| * Otherwise every single update would be persisted. | ||
| */ | ||
| debounce: number; | ||
| /** | ||
| * Makes sure to call `onStoreDocument` at least in the given amount of time (ms). | ||
| */ | ||
| maxDebounce: number; | ||
| /** | ||
| * By default, the servers show a start screen. If passed false, the server will start quietly. | ||
| */ | ||
| quiet: boolean; | ||
| /** | ||
| * If set to false, respects the debounce time of `onStoreDocument` before unloading a document. | ||
| * Otherwise, the document will be unloaded immediately. | ||
| * | ||
| * This prevents a client from DOSing the server by repeatedly connecting and disconnecting when | ||
| * your onStoreDocument is rate-limited. | ||
| */ | ||
| unloadImmediately: boolean; | ||
| /** | ||
| * options to pass to the ydoc document | ||
| */ | ||
| yDocOptions: { | ||
| gc: boolean; | ||
| gcFilter: () => boolean; | ||
| }; | ||
| } | ||
| export interface onStatelessPayload { | ||
| connection: Connection; | ||
| documentName: string; | ||
| document: Document; | ||
| payload: string; | ||
| } | ||
| export interface onAuthenticatePayload { | ||
| context: any; | ||
| documentName: string; | ||
| instance: Hocuspocus; | ||
| requestHeaders: IncomingHttpHeaders; | ||
| requestParameters: URLSearchParams; | ||
| request: IncomingMessage; | ||
| socketId: string; | ||
| token: string; | ||
| connectionConfig: ConnectionConfiguration; | ||
| } | ||
| export interface onTokenSyncPayload { | ||
| context: any; | ||
| document: Document; | ||
| documentName: string; | ||
| instance: Hocuspocus; | ||
| requestHeaders: IncomingHttpHeaders; | ||
| requestParameters: URLSearchParams; | ||
| socketId: string; | ||
| token: string; | ||
| connectionConfig: ConnectionConfiguration; | ||
| connection: Connection; | ||
| } | ||
| export interface onCreateDocumentPayload { | ||
| context: any; | ||
| documentName: string; | ||
| instance: Hocuspocus; | ||
| requestHeaders: IncomingHttpHeaders; | ||
| requestParameters: URLSearchParams; | ||
| socketId: string; | ||
| connectionConfig: ConnectionConfiguration; | ||
| } | ||
| export interface onConnectPayload { | ||
| context: any; | ||
| documentName: string; | ||
| instance: Hocuspocus; | ||
| request: IncomingMessage; | ||
| requestHeaders: IncomingHttpHeaders; | ||
| requestParameters: URLSearchParams; | ||
| socketId: string; | ||
| connectionConfig: ConnectionConfiguration; | ||
| } | ||
| export interface connectedPayload { | ||
| context: any; | ||
| documentName: string; | ||
| instance: Hocuspocus; | ||
| request: IncomingMessage; | ||
| requestHeaders: IncomingHttpHeaders; | ||
| requestParameters: URLSearchParams; | ||
| socketId: string; | ||
| connectionConfig: ConnectionConfiguration; | ||
| connection: Connection; | ||
| } | ||
| export interface onLoadDocumentPayload { | ||
| context: any; | ||
| document: Document; | ||
| documentName: string; | ||
| instance: Hocuspocus; | ||
| requestHeaders: IncomingHttpHeaders; | ||
| requestParameters: URLSearchParams; | ||
| socketId: string; | ||
| connectionConfig: ConnectionConfiguration; | ||
| } | ||
| export interface afterLoadDocumentPayload { | ||
| context: any; | ||
| document: Document; | ||
| documentName: string; | ||
| instance: Hocuspocus; | ||
| requestHeaders: IncomingHttpHeaders; | ||
| requestParameters: URLSearchParams; | ||
| socketId: string; | ||
| connectionConfig: ConnectionConfiguration; | ||
| } | ||
| export interface onChangePayload { | ||
| clientsCount: number; | ||
| context: any; | ||
| document: Document; | ||
| documentName: string; | ||
| instance: Hocuspocus; | ||
| requestHeaders: IncomingHttpHeaders; | ||
| requestParameters: URLSearchParams; | ||
| update: Uint8Array; | ||
| socketId: string; | ||
| transactionOrigin: any; | ||
| } | ||
| export interface beforeHandleMessagePayload { | ||
| clientsCount: number; | ||
| context: any; | ||
| document: Document; | ||
| documentName: string; | ||
| instance: Hocuspocus; | ||
| requestHeaders: IncomingHttpHeaders; | ||
| requestParameters: URLSearchParams; | ||
| update: Uint8Array; | ||
| socketId: string; | ||
| connection: Connection; | ||
| } | ||
| export interface beforeSyncPayload { | ||
| clientsCount: number; | ||
| context: any; | ||
| document: Document; | ||
| documentName: string; | ||
| connection: Connection; | ||
| /** | ||
| * The y-protocols/sync message type | ||
| * @example | ||
| * 0: SyncStep1 | ||
| * 1: SyncStep2 | ||
| * 2: YjsUpdate | ||
| * | ||
| * @see https://github.com/yjs/y-protocols/blob/master/sync.js#L13-L40 | ||
| */ | ||
| type: number; | ||
| /** | ||
| * The payload of the y-sync message. | ||
| */ | ||
| payload: Uint8Array; | ||
| } | ||
| export interface beforeBroadcastStatelessPayload { | ||
| document: Document; | ||
| documentName: string; | ||
| payload: string; | ||
| } | ||
| export interface onStoreDocumentPayload { | ||
| clientsCount: number; | ||
| context: any; | ||
| document: Document; | ||
| documentName: string; | ||
| instance: Hocuspocus; | ||
| requestHeaders: IncomingHttpHeaders; | ||
| requestParameters: URLSearchParams; | ||
| socketId: string; | ||
| transactionOrigin?: any; | ||
| } | ||
| export interface afterStoreDocumentPayload extends onStoreDocumentPayload { | ||
| } | ||
| export interface onAwarenessUpdatePayload { | ||
| context: any; | ||
| document: Document; | ||
| documentName: string; | ||
| instance: Hocuspocus; | ||
| requestHeaders: IncomingHttpHeaders; | ||
| requestParameters: URLSearchParams; | ||
| socketId: string; | ||
| added: number[]; | ||
| updated: number[]; | ||
| removed: number[]; | ||
| awareness: Awareness; | ||
| states: StatesArray; | ||
| } | ||
| export type StatesArray = { | ||
| clientId: number; | ||
| [key: string | number]: any; | ||
| }[]; | ||
| export interface fetchPayload { | ||
| context: any; | ||
| document: Document; | ||
| documentName: string; | ||
| instance: Hocuspocus; | ||
| requestHeaders: IncomingHttpHeaders; | ||
| requestParameters: URLSearchParams; | ||
| socketId: string; | ||
| connectionConfig: ConnectionConfiguration; | ||
| } | ||
| export interface storePayload extends onStoreDocumentPayload { | ||
| state: Buffer; | ||
| } | ||
| export interface onDisconnectPayload { | ||
| clientsCount: number; | ||
| context: any; | ||
| document: Document; | ||
| documentName: string; | ||
| instance: Hocuspocus; | ||
| requestHeaders: IncomingHttpHeaders; | ||
| requestParameters: URLSearchParams; | ||
| socketId: string; | ||
| } | ||
| export interface onRequestPayload { | ||
| request: IncomingMessage; | ||
| response: ServerResponse; | ||
| instance: Hocuspocus; | ||
| } | ||
| export interface onUpgradePayload { | ||
| request: IncomingMessage; | ||
| socket: any; | ||
| head: any; | ||
| instance: Hocuspocus; | ||
| } | ||
| export interface onListenPayload { | ||
| instance: Hocuspocus; | ||
| configuration: Configuration; | ||
| port: number; | ||
| } | ||
| export interface onDestroyPayload { | ||
| instance: Hocuspocus; | ||
| } | ||
| export interface onConfigurePayload { | ||
| instance: Hocuspocus; | ||
| configuration: Configuration; | ||
| version: string; | ||
| } | ||
| export interface afterUnloadDocumentPayload { | ||
| instance: Hocuspocus; | ||
| documentName: string; | ||
| } | ||
| export interface beforeUnloadDocumentPayload { | ||
| instance: Hocuspocus; | ||
| documentName: string; | ||
| document: Document; | ||
| } | ||
| export interface DirectConnection { | ||
| transact(transaction: (document: Document) => void): Promise<void>; | ||
| disconnect(): void; | ||
| } |
| export declare const useDebounce: () => { | ||
| debounce: (id: string, func: () => any | Promise<() => any>, debounce: number, maxDebounce: number) => Promise<any>; | ||
| isDebounced: (id: string) => boolean; | ||
| isCurrentlyExecuting: (id: string) => boolean; | ||
| executeNow: (id: string) => any; | ||
| }; |
| import type { IncomingMessage } from "node:http"; | ||
| import { URLSearchParams } from "node:url"; | ||
| /** | ||
| * Get parameters by the given request | ||
| */ | ||
| export declare function getParameters(request?: Pick<IncomingMessage, "url">): URLSearchParams; |
| export * from "./Prosemirror.ts"; | ||
| export * from "./Tiptap.ts"; | ||
| export * from "./types.ts"; |
| import { Doc } from "yjs"; | ||
| import { Schema } from "@tiptap/pm/model"; | ||
| import type { Transformer } from "./types.ts"; | ||
| declare class Prosemirror implements Transformer { | ||
| defaultSchema: Schema; | ||
| schema(schema: Schema): Prosemirror; | ||
| fromYdoc(document: Doc, fieldName?: string | Array<string>): any; | ||
| toYdoc(document: any, fieldName?: string | Array<string>, schema?: Schema): Doc; | ||
| } | ||
| export declare const ProsemirrorTransformer: Prosemirror; | ||
| export {}; |
| import type { Doc } from "yjs"; | ||
| import type { Extensions } from "@tiptap/core"; | ||
| import type { Transformer } from "./types.ts"; | ||
| export declare class Tiptap implements Transformer { | ||
| defaultExtensions: Extensions; | ||
| extensions(extensions: Extensions): Tiptap; | ||
| fromYdoc(document: Doc, fieldName?: string | Array<string>): any; | ||
| toYdoc(document: any, fieldName?: string | Array<string>, extensions?: Extensions): Doc; | ||
| } | ||
| export declare const TiptapTransformer: Tiptap; |
| import type { Doc } from "yjs"; | ||
| export interface Transformer { | ||
| fromYdoc: (document: Doc, fieldName?: string | Array<string>) => any; | ||
| toYdoc: (document: any, fieldName: string) => Doc; | ||
| } |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| import type { HocuspocusProviderWebsocket } from "@hocuspocus/provider"; | ||
| export declare const SocketContext1: import("react").Context<HocuspocusProviderWebsocket | null>; |
| import type { HocuspocusProviderWebsocket } from "@hocuspocus/provider"; | ||
| export declare const SocketContext2: import("react").Context<HocuspocusProviderWebsocket | null>; |
| import type { NextConfig } from "next"; | ||
| declare const nextConfig: NextConfig; | ||
| export default nextConfig; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export declare const createDirectory: (dir: string) => void; |
| export declare const flushRedis: () => Promise<string>; |
| export * from './createDirectory.ts'; | ||
| export * from './flushRedis.ts'; | ||
| export * from './newHocuspocus.ts'; | ||
| export * from './newHocuspocusProvider.ts'; | ||
| export * from './newHocuspocusProviderWebsocket.ts'; | ||
| export * from './randomInteger.ts'; | ||
| export * from './redisConnectionSettings.ts'; | ||
| export * from './removeDirectory.ts'; | ||
| export * from './sleep.ts'; |
| import type { ServerConfiguration } from '@hocuspocus/server'; | ||
| export declare const newHocuspocus: (options?: Partial<ServerConfiguration>) => Promise<import("@hocuspocus/server").Hocuspocus>; |
| import { HocuspocusProvider, type HocuspocusProviderConfiguration, type HocuspocusProviderWebsocket, type HocuspocusProviderWebsocketConfiguration } from '@hocuspocus/provider'; | ||
| import type { Hocuspocus } from '@hocuspocus/server'; | ||
| export declare const newHocuspocusProvider: (server: Hocuspocus, options?: Partial<HocuspocusProviderConfiguration>, websocketOptions?: Partial<HocuspocusProviderWebsocketConfiguration>, websocketProvider?: HocuspocusProviderWebsocket) => HocuspocusProvider; |
| import type { HocuspocusProviderWebsocketConfiguration } from '@hocuspocus/provider'; | ||
| import { HocuspocusProviderWebsocket } from '@hocuspocus/provider'; | ||
| import type { Hocuspocus } from '@hocuspocus/server'; | ||
| export declare const newHocuspocusProviderWebsocket: (hocuspocus: Hocuspocus, options?: Partial<Omit<HocuspocusProviderWebsocketConfiguration, "url">>) => HocuspocusProviderWebsocket; |
| export declare const randomInteger: (min: number, max: number) => number; |
| export declare const redisConnectionSettings: { | ||
| host: string; | ||
| port: number; | ||
| }; |
| export declare const removeDirectory: (dir: string) => void; |
| import type { ExecutionContext } from 'ava'; | ||
| export declare const retryableAssertion: (t: ExecutionContext, recoverableTry: (tt: ExecutionContext) => void) => Promise<void>; |
| export declare const sleep: (time: number) => Promise<unknown>; |
Sorry, the diff of this file is too big to display
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
181597
-20.77%13
-91.1%1774
-38.53%1
Infinity%5
25%