Socket
Socket
Sign inDemoInstall

@hocuspocus/common

Package Overview
Dependencies
Maintainers
4
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hocuspocus/common - npm Package Compare versions

Comparing version 2.0.1 to 2.0.2

dist/playground/backend/src/tiptapcollab.d.ts

358

dist/hocuspocus-common.esm.js

@@ -30,9 +30,36 @@ /**

/* istanbul ignore next */
/** @type {TextEncoder} */ (typeof TextEncoder !== 'undefined' ? new TextEncoder() : null);
/**
* @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
};
/* istanbul ignore next */
/* c8 ignore next */
const utf8TextEncoder = /** @type {TextEncoder} */ (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 });
/* istanbul ignore next */
/* c8 ignore start */
if (utf8TextDecoder && utf8TextDecoder.decode(new Uint8Array()).length === 1) {

@@ -44,3 +71,3 @@ // Safari doesn't handle BOM correctly.

// Another issue is that from then on no BOM chars are recognized anymore
/* istanbul ignore next */
/* c8 ignore next */
utf8TextDecoder = null;

@@ -63,3 +90,3 @@ }

*/
const create = () => new Map();
const create$1 = () => new Map();

@@ -77,6 +104,6 @@ /**

*/
/* istanbul ignore next */
/* c8 ignore next */
const undefinedToNull = v => v === undefined ? null : v;
/* global localStorage, addEventListener */
/* eslint-env browser */

@@ -91,3 +118,3 @@ /**

/* istanbul ignore next */
/* c8 ignore start */
class VarStoragePolyfill {

@@ -113,4 +140,4 @@ constructor () {

}
/* c8 ignore stop */
/* istanbul ignore next */
/**

@@ -122,5 +149,5 @@ * @type {any}

/* c8 ignore start */
try {
// if the same-origin rule is violated, accessing localStorage might thrown an error
/* istanbul ignore next */
if (typeof localStorage !== 'undefined') {

@@ -131,10 +158,28 @@ _localStorage = localStorage;

} catch (e) { }
/* c8 ignore stop */
/* istanbul ignore next */
/**
* This is basically localStorage in browser, or a polyfill in nodejs
*/
/* c8 ignore next */
const varStorage = _localStorage;
/**
* Common functions and function call helpers.
*
* @module function
*/
/**
* @template V
* @template {V} OPTS
*
* @param {V} value
* @param {Array<OPTS>} options
*/
// @ts-ignore
const isOneOf = (value, options) => options.includes(value);
/* c8 ignore stop */
/**
* Isomorphic module to work access the environment (query params, env variables).

@@ -145,7 +190,10 @@ *

/* istanbul ignore next */
/* c8 ignore next */
// @ts-ignore
const isNode = typeof process !== 'undefined' && process.release && /node|io\.js/.test(process.release.name);
/* istanbul ignore next */
typeof navigator !== 'undefined' ? /Mac/.test(navigator.platform) : false;
const isNode = typeof process !== 'undefined' && process.release &&
/node|io\.js/.test(process.release.name);
/* c8 ignore next 3 */
typeof navigator !== 'undefined'
? /Mac/.test(navigator.platform)
: false;

@@ -157,10 +205,9 @@ /**

/* istanbul ignore next */
/* c8 ignore start */
const computeParams = () => {
if (params === undefined) {
if (isNode) {
params = create();
params = create$1();
const pargs = process.argv;
let currParamName = null;
/* istanbul ignore next */
for (let i = 0; i < pargs.length; i++) {

@@ -183,7 +230,6 @@ const parg = pargs[i];

}
// in ReactNative for example this would not be true (unless connected to the Remote Debugger)
// in ReactNative for example this would not be true (unless connected to the Remote Debugger)
} else if (typeof location === 'object') {
params = create()
// eslint-disable-next-line no-undef
;(location.search || '?').slice(1).split('&').forEach(kv => {
params = create$1(); // eslint-disable-next-line no-undef
(location.search || '?').slice(1).split('&').forEach((kv) => {
if (kv.length !== 0) {

@@ -196,3 +242,3 @@ const [key, value] = kv.split('=');

} else {
params = create();
params = create$1();
}

@@ -202,2 +248,3 @@ }

};
/* c8 ignore stop */

@@ -208,5 +255,4 @@ /**

*/
/* istanbul ignore next */
const hasParam = name => computeParams().has(name);
// export const getArgs = name => computeParams() && args
/* c8 ignore next */
const hasParam = (name) => computeParams().has(name);

@@ -217,4 +263,7 @@ /**

*/
/* istanbul ignore next */
const getVariable = name => isNode ? undefinedToNull(process.env[name.toUpperCase()]) : undefinedToNull(varStorage.getItem(name));
/* c8 ignore next 4 */
const getVariable = (name) =>
isNode
? undefinedToNull(process.env[name.toUpperCase()])
: undefinedToNull(varStorage.getItem(name));

@@ -225,8 +274,22 @@ /**

*/
/* istanbul ignore next */
const hasConf = name => hasParam('--' + name) || getVariable(name) !== null;
/* c8 ignore next 2 */
const hasConf = (name) =>
hasParam('--' + name) || getVariable(name) !== null;
/* istanbul ignore next */
/* c8 ignore next */
hasConf('production');
/* c8 ignore next 2 */
const forceColor = isNode &&
isOneOf(process.env.FORCE_COLOR, ['true', '1', '2']);
/* c8 ignore start */
!hasParam('no-colors') &&
(!isNode || process.stdout.isTTY || forceColor) && (
!isNode || hasParam('color') || forceColor ||
getVariable('COLORTERM') !== null ||
(getVariable('TERM') || '').includes('color')
);
/* c8 ignore stop */
/* eslint-env browser */

@@ -237,2 +300,47 @@ const BIT8 = 128;

/**
* 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;
/**
* Utility helpers for working with numbers.
*
* @module number
*/
const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER;
/**
* Error helpers.
*
* @module error
*/
/**
* @param {string} s
* @return {Error}
*/
/* c8 ignore next */
const create = s => new Error(s);
/**
* Efficient schema-less binary decoding with support for variable length encoding.

@@ -248,3 +356,3 @@ *

* // encoding step
* const encoder = new encoding.createEncoder()
* const encoder = encoding.createEncoder()
* encoding.writeVarUint(encoder, 256)

@@ -257,3 +365,3 @@ * encoding.writeVarString(encoder, 'Hello world!')

* // decoding step
* const decoder = new decoding.createDecoder(buf)
* const decoder = decoding.createDecoder(buf)
* decoding.readVarUint(decoder) // => 256

@@ -267,3 +375,35 @@ * decoding.readVarString(decoder) // => 'Hello world!'

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 = createUint8ArrayViewFromArrayBuffer(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.

@@ -288,20 +428,24 @@ * @function

let num = 0;
let len = 0;
while (true) {
let mult = 1;
const len = decoder.arr.length;
while (decoder.pos < len) {
const r = decoder.arr[decoder.pos++];
num = num | ((r & BITS7) << len);
len += 7;
// 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 >>> 0 // return unsigned number!
return num
}
/* istanbul ignore if */
if (len > 35) {
throw new Error('Integer out of range!')
/* c8 ignore start */
if (num > MAX_SAFE_INTEGER) {
throw errorIntegerOutOfRange
}
/* c8 ignore stop */
}
throw errorUnexpectedEndOfArray
};
/**
* Read string of variable length
* * varUint is used to store the length of the string
* We don't test this function anymore as we use native decoding/encoding by default now.
* Better not modify this anymore..
*

@@ -317,3 +461,4 @@ * Transforming utf8 to a string is pretty expensive. The code performs 10x better

*/
const readVarString = decoder => {
/* c8 ignore start */
const _readVarStringPolyfill = decoder => {
let remainingLen = readVarUint(decoder);

@@ -342,4 +487,40 @@ if (remainingLen === 0) {

};
/* c8 ignore stop */
/**
* @function
* @param {Decoder} decoder
* @return {String} The read String
*/
const _readVarStringNative = decoder =>
/** @type any */ (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;
/**
* Utility functions to work with buffers (Uint8Array).
*
* @module buffer
*/
/**
* Create Uint8Array with initial content from buffer
*
* @param {ArrayBuffer} buffer
* @param {number} byteOffset
* @param {number} length
*/
const createUint8ArrayViewFromArrayBuffer = (buffer, byteOffset, length) => new Uint8Array(buffer, byteOffset, length);
/**
* Efficient schema-less binary encoding with support for variable length encoding.

@@ -355,3 +536,3 @@ *

* // encoding step
* const encoder = new encoding.createEncoder()
* const encoder = encoding.createEncoder()
* encoding.writeVarUint(encoder, 256)

@@ -364,3 +545,3 @@ * encoding.writeVarString(encoder, 'Hello world!')

* // decoding step
* const decoder = new decoding.createDecoder(buf)
* const decoder = decoding.createDecoder(buf)
* decoding.readVarUint(decoder) // => 256

@@ -392,6 +573,4 @@ * decoding.readVarString(decoder) // => 'Hello world!'

/**
* Write a variable length unsigned integer.
* Write a variable length unsigned integer. Max encodable integer is 2^53.
*
* Encodes integers in the range from [0, 4294967295] / [0, 0xffffffff]. (max 32 bit unsigned integer)
*
* @function

@@ -404,3 +583,3 @@ * @param {Encoder} encoder

write(encoder, BIT8 | (BITS7 & num));
num >>>= 7;
num = floor(num / 128); // shift >>> 7
}

@@ -411,2 +590,8 @@ write(encoder, BITS7 & num);

/**
* A cache to store strings temporarily
*/
const _strBuffer = new Uint8Array(30000);
const _maxStrBSize = _strBuffer.length / 3;
/**
* Write a variable length string.

@@ -418,3 +603,24 @@ *

*/
const writeVarString = (encoder, str) => {
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));
}
};
/**
* 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));

@@ -428,2 +634,50 @@ const len = encodedString.length;

/**
* 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;
/**
* 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;
}
};
/**
* Append an Uint8Array to Encoder.
*
* @function
* @param {Encoder} encoder
* @param {Uint8Array} uint8Array
*/
const writeVarUint8Array = (encoder, uint8Array) => {
writeVarUint(encoder, uint8Array.byteLength);
writeUint8Array(encoder, uint8Array);
};
var AuthMessageType;

@@ -430,0 +684,0 @@ (function (AuthMessageType) {

2

dist/packages/server/src/Connection.d.ts

@@ -42,3 +42,3 @@ /// <reference types="node" />

*/
beforeHandleMessage(callback: (payload: Document, update: Uint8Array) => Promise<any>): Connection;
beforeHandleMessage(callback: (connection: Connection, update: Uint8Array) => Promise<any>): Connection;
/**

@@ -45,0 +45,0 @@ * Send the given message

@@ -10,4 +10,4 @@ import Connection from './Connection';

apply(document: Document, connection?: Connection, reply?: (message: Uint8Array) => void): void;
readSyncMessage(message: IncomingMessage, document: Document, connection?: Connection, reply?: (message: Uint8Array) => void, requestFirstSync?: boolean): 0 | 1 | 2;
readSyncMessage(message: IncomingMessage, document: Document, connection?: Connection, reply?: (message: Uint8Array) => void, requestFirstSync?: boolean): 0 | 2 | 1;
applyQueryAwarenessMessage(document: Document, reply?: (message: Uint8Array) => void): void;
}

@@ -179,2 +179,3 @@ /// <reference types="node" />

socketId: string;
connection: Connection;
}

@@ -181,0 +182,0 @@ export interface beforeBroadcastStatelessPayload {

{
"name": "@hocuspocus/common",
"description": "shared code for multiple Hocuspocus packages",
"version": "2.0.1",
"version": "2.0.2",
"homepage": "https://hocuspocus.dev",

@@ -6,0 +6,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc