Socket
Socket
Sign inDemoInstall

@hocuspocus/server

Package Overview
Dependencies
Maintainers
4
Versions
114
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hocuspocus/server - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

dist/packages/provider/src/OutgoingMessages/StatelessMessage.d.ts

24

dist/packages/extension-redis/src/Redis.d.ts

@@ -1,4 +0,5 @@

import RedisClient from 'ioredis';
import RedisClient, { ClusterNode, ClusterOptions, RedisOptions } from 'ioredis';
import Redlock from 'redlock';
import { Document, Extension, afterLoadDocumentPayload, afterStoreDocumentPayload, onDisconnectPayload, onStoreDocumentPayload, onAwarenessUpdatePayload, onChangePayload, Debugger, onConfigurePayload, onListenPayload } from '@hocuspocus/server';
import { Document, Extension, afterLoadDocumentPayload, afterStoreDocumentPayload, onDisconnectPayload, onStoreDocumentPayload, onAwarenessUpdatePayload, onChangePayload, Debugger, onConfigurePayload, onListenPayload, beforeBroadcastStatelessPayload } from '@hocuspocus/server';
export declare type RedisInstance = RedisClient.Cluster | RedisClient.Redis;
export interface Configuration {

@@ -14,2 +15,14 @@ /**

/**
* Redis Cluster
*/
nodes?: ClusterNode[];
/**
* Duplicate from an existed Redis instance
*/
redis?: RedisInstance;
/**
* Redis instance creator
*/
createClient?: () => RedisInstance;
/**
* Options passed directly to Redis constructor

@@ -19,3 +32,3 @@ *

*/
options?: RedisClient.RedisOptions;
options?: ClusterOptions | RedisOptions;
/**

@@ -43,4 +56,4 @@ * An unique instance name, required to filter messages in Redis.

configuration: Configuration;
pub: RedisClient.Redis;
sub: RedisClient.Redis;
pub: RedisInstance;
sub: RedisInstance;
documents: Map<string, Document>;

@@ -97,2 +110,3 @@ redlock: Redlock;

onDisconnect: ({ documentName, clientsCount }: onDisconnectPayload) => Promise<void>;
beforeBroadcastStateless(data: beforeBroadcastStatelessPayload): Promise<number>;
/**

@@ -99,0 +113,0 @@ * Kill the Redlock connection immediately.

@@ -6,3 +6,3 @@ import * as Y from 'yjs';

import EventEmitter from './EventEmitter';
import { ConstructableOutgoingMessage, onAuthenticationFailedParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatusParameters, onSyncedParameters, WebSocketStatus } from './types';
import { ConstructableOutgoingMessage, onAuthenticationFailedParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatelessParameters, onStatusParameters, onSyncedParameters, WebSocketStatus } from './types';
import { onAwarenessChangeParameters, onAwarenessUpdateParameters } from '.';

@@ -102,2 +102,3 @@ export declare type HocuspocusProviderConfiguration = Required<Pick<CompleteHocuspocusProviderConfiguration, 'url' | 'name'>> & Partial<CompleteHocuspocusProviderConfiguration>;

onAwarenessChange: (data: onAwarenessChangeParameters) => void;
onStateless: (data: onStatelessParameters) => void;
/**

@@ -141,2 +142,3 @@ * Don’t output any warnings.

registerEventListeners(): void;
sendStateless(payload: string): void;
documentUpdateHandler(update: Uint8Array, origin: any): void;

@@ -150,2 +152,3 @@ awarenessUpdateHandler({ added, updated, removed }: any, origin: any): void;

set synced(state: boolean);
receiveStateless(payload: string): void;
get isAuthenticationRequired(): boolean;

@@ -152,0 +155,0 @@ disconnect(): void;

@@ -17,3 +17,4 @@ import { Awareness } from 'y-protocols/awareness';

Auth = 2,
QueryAwareness = 3
QueryAwareness = 3,
Stateless = 5
}

@@ -38,2 +39,3 @@ export declare enum WebSocketStatus {

update: any;
payload: string;
encoder: Encoder;

@@ -76,2 +78,5 @@ }

};
export declare type onStatelessParameters = {
payload: string;
};
export declare type StatesArray = {

@@ -78,0 +83,0 @@ clientId: number;

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

import { Debugger } from './Debugger';
import { onStatelessPayload } from './types';
export declare class Connection {

@@ -31,2 +32,6 @@ webSocket: WebSocket;

/**
* 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

@@ -40,2 +45,6 @@ */

/**
* Send a stateless message with payload
*/
sendStateless(payload: string): void;
/**
* Graceful wrapper around the WebSocket close method.

@@ -42,0 +51,0 @@ */

@@ -11,2 +11,3 @@ import WebSocket from 'ws';

onUpdate: (document: Document, connection: Connection, update: Uint8Array) => void;
beforeBroadcastStateless: (document: Document, stateless: string) => void;
};

@@ -38,2 +39,6 @@ connections: Map<WebSocket, {

/**
* 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

@@ -80,3 +85,7 @@ * underlying websocket connection

private handleUpdate;
/**
* Broadcast stateless message to all connections
*/
broadcastStateless(payload: string): void;
}
export default Document;

@@ -16,2 +16,3 @@ import { Decoder } from 'lib0/decoding';

readVarUint(): number;
readVarString(): string;
toUint8Array(): Uint8Array;

@@ -18,0 +19,0 @@ writeVarUint(type: MessageType): void;

@@ -17,3 +17,5 @@ import { Encoder } from 'lib0/encoding';

writeUpdate(update: Uint8Array): OutgoingMessage;
writeStateless(payload: string): OutgoingMessage;
writeBroadcastStateless(payload: string): OutgoingMessage;
toUint8Array(): Uint8Array;
}

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

import { Hocuspocus } from './Hocuspocus';
import Connection from './Connection';
export declare enum MessageType {

@@ -14,3 +15,5 @@ Unknown = -1,

QueryAwareness = 3,
SyncReply = 4
SyncReply = 4,
Stateless = 5,
BroadcastStateless = 6
}

@@ -38,2 +41,4 @@ export interface AwarenessUpdate {

beforeHandleMessage?(data: beforeHandleMessagePayload): Promise<any>;
beforeBroadcastStateless?(data: beforeBroadcastStatelessPayload): Promise<any>;
onStateless?(payload: onStatelessPayload): Promise<any>;
onChange?(data: onChangePayload): Promise<any>;

@@ -47,4 +52,4 @@ onStoreDocument?(data: onStoreDocumentPayload): Promise<any>;

}
export declare type HookName = 'onConfigure' | 'onListen' | 'onUpgrade' | 'onConnect' | 'connected' | 'onAuthenticate' | 'onLoadDocument' | 'afterLoadDocument' | 'beforeHandleMessage' | 'onChange' | 'onStoreDocument' | 'afterStoreDocument' | 'onAwarenessUpdate' | 'onRequest' | 'onDisconnect' | 'onDestroy';
export declare type HookPayload = onConfigurePayload | onListenPayload | onUpgradePayload | onConnectPayload | connectedPayload | onAuthenticatePayload | onLoadDocumentPayload | onChangePayload | onStoreDocumentPayload | afterStoreDocumentPayload | onAwarenessUpdatePayload | onRequestPayload | onDisconnectPayload | onDestroyPayload;
export declare type HookName = 'onConfigure' | 'onListen' | 'onUpgrade' | 'onConnect' | 'connected' | 'onAuthenticate' | 'onLoadDocument' | 'afterLoadDocument' | 'beforeHandleMessage' | 'beforeBroadcastStateless' | 'onStateless' | 'onChange' | 'onStoreDocument' | 'afterStoreDocument' | 'onAwarenessUpdate' | 'onRequest' | 'onDisconnect' | 'onDestroy';
export declare type HookPayload = onConfigurePayload | onListenPayload | onUpgradePayload | onConnectPayload | connectedPayload | onAuthenticatePayload | onLoadDocumentPayload | onStatelessPayload | beforeHandleMessagePayload | beforeBroadcastStatelessPayload | onChangePayload | onStoreDocumentPayload | afterStoreDocumentPayload | onAwarenessUpdatePayload | onRequestPayload | onDisconnectPayload | onDestroyPayload;
export interface Configuration extends Extension {

@@ -101,2 +106,8 @@ /**

}
export interface onStatelessPayload {
connection: Connection;
documentName: string;
document: Document;
payload: string;
}
export interface onAuthenticatePayload {

@@ -171,2 +182,7 @@ documentName: string;

}
export interface beforeBroadcastStatelessPayload {
document: Document;
documentName: string;
payload: string;
}
export interface onStoreDocumentPayload {

@@ -173,0 +189,0 @@ clientsCount: number;

import { Doc } from 'yjs';
import { Schema } from 'prosemirror-model';
import { Schema } from '@tiptap/pm/model';
import { Transformer } from './types';

@@ -4,0 +4,0 @@ declare class Prosemirror implements Transformer {

{
"name": "@hocuspocus/server",
"description": "plug & play collaboration backend",
"version": "1.0.2",
"version": "1.1.0",
"homepage": "https://hocuspocus.dev",

@@ -31,3 +31,3 @@ "keywords": [

"dependencies": {
"@hocuspocus/common": "^1.0.2",
"@hocuspocus/common": "^1.1.0",
"@types/async-lock": "^1.1.3",

@@ -34,0 +34,0 @@ "@types/uuid": "^9.0.0",

@@ -12,3 +12,3 @@ import AsyncLock from 'async-lock'

import { Debugger } from './Debugger'
import { beforeHandleMessagePayload } from './types'
import { onStatelessPayload } from './types'

@@ -34,2 +34,3 @@ export class Connection {

beforeHandleMessage: (document: Document, update: Uint8Array) => Promise,
statelessCallback: () => Promise,
}

@@ -91,2 +92,11 @@

/**
* Set a callback that will be triggered when an stateless message is received
*/
onStatelessCallback(callback: (payload: onStatelessPayload) => Promise<void>): Connection {
this.callbacks.statelessCallback = callback
return this
}
/**
* Set a callback that will be triggered before an message is handled

@@ -121,2 +131,20 @@ */

/**
* Send a stateless message with payload
*/
public sendStateless(payload: string): void {
const message = new OutgoingMessage()
.writeStateless(payload)
this.logger.log({
direction: 'out',
type: message.type,
category: message.category,
})
this.send(
message.toUint8Array(),
)
}
/**
* Graceful wrapper around the WebSocket close method.

@@ -123,0 +151,0 @@ */

@@ -17,2 +17,3 @@ import WebSocket from 'ws'

onUpdate: (document: Document, connection: Connection, update: Uint8Array) => {},
beforeBroadcastStateless: (document: Document, stateless: string) => {},
}

@@ -81,2 +82,11 @@

/**
* Set a callback that will be triggered before a stateless message is broadcasted
*/
beforeBroadcastStateless(callback: (document: Document, stateless: string) => void): Document {
this.callbacks.beforeBroadcastStateless = callback
return this
}
/**
* Register a connection and a set of clients on this document keyed by the

@@ -220,4 +230,15 @@ * underlying websocket connection

}
/**
* Broadcast stateless message to all connections
*/
public broadcastStateless(payload: string): void {
this.callbacks.beforeBroadcastStateless(this, payload)
this.getConnections().forEach(connection => {
connection.sendStateless(payload)
})
}
}
export default Document

@@ -22,3 +22,5 @@ import * as decoding from 'lib0/decoding'

AwarenessUpdate,
HookPayload, beforeHandleMessagePayload,
HookPayload,
beforeHandleMessagePayload,
beforeBroadcastStatelessPayload,
} from './types'

@@ -59,2 +61,4 @@ import Document from './Document'

beforeHandleMessage: () => new Promise(r => r(null)),
beforeBroadcastStateless: () => new Promise(r => r(null)),
onStateless: () => new Promise(r => r(null)),
onChange: () => new Promise(r => r(null)),

@@ -117,2 +121,4 @@ onLoadDocument: () => new Promise(r => r(null)),

beforeHandleMessage: this.configuration.beforeHandleMessage,
beforeBroadcastStateless: this.configuration.beforeBroadcastStateless,
onStateless: this.configuration.onStateless,
onChange: this.configuration.onChange,

@@ -656,2 +662,12 @@ onStoreDocument: this.configuration.onStoreDocument,

document.beforeBroadcastStateless((document: Document, stateless: string) => {
const hookPayload: beforeBroadcastStatelessPayload = {
document,
documentName: document.name,
payload: stateless,
}
this.hooks('beforeBroadcastStateless', hookPayload)
})
document.awareness.on('update', (update: AwarenessUpdate) => {

@@ -730,2 +746,12 @@ this.hooks('onAwarenessUpdate', {

})
instance.onStatelessCallback(payload => {
return this.hooks('onStateless', payload)
.catch(error => {
if (error?.message) {
throw error
}
})
})
instance.beforeHandleMessage((document, update) => {

@@ -732,0 +758,0 @@ const hookPayload: beforeHandleMessagePayload = {

@@ -6,2 +6,3 @@ import {

readVarUint8Array,
readVarString,
} from 'lib0/decoding'

@@ -45,2 +46,6 @@ import {

readVarString() {
return readVarString(this.decoder)
}
toUint8Array() {

@@ -47,0 +52,0 @@ return toUint8Array(this.encoder)

@@ -10,2 +10,3 @@ import {

import { applyAwarenessUpdate, Awareness } from 'y-protocols/awareness'
import { readVarString } from 'lib0/decoding'
import { MessageType } from './types'

@@ -69,2 +70,20 @@ import Connection from './Connection'

break
case MessageType.Stateless:
connection?.callbacks.statelessCallback({
connection,
documentName: document.name,
document,
payload: readVarString(message.decoder),
})
break
case MessageType.BroadcastStateless:
document.getConnections().forEach(connection => {
connection.sendStateless(message.readVarString())
})
break
default:

@@ -71,0 +90,0 @@ // Do nothing

@@ -5,2 +5,3 @@ import {

toUint8Array,
writeVarString,
writeVarUint,

@@ -104,2 +105,20 @@ writeVarUint8Array,

writeStateless(payload: string): OutgoingMessage {
this.category = 'Stateless'
writeVarUint(this.encoder, MessageType.Stateless)
writeVarString(this.encoder, payload)
return this
}
writeBroadcastStateless(payload: string): OutgoingMessage {
this.category = 'Stateless'
writeVarUint(this.encoder, MessageType.BroadcastStateless)
writeVarString(this.encoder, payload)
return this
}
toUint8Array(): Uint8Array {

@@ -106,0 +125,0 @@ return toUint8Array(this.encoder)

@@ -9,2 +9,3 @@ import {

import { Hocuspocus } from './Hocuspocus'
import Connection from './Connection'

@@ -18,2 +19,4 @@ export enum MessageType {

SyncReply = 4, // same as Sync, but won't trigger another 'SyncStep1'
Stateless = 5,
BroadcastStateless = 6,
}

@@ -44,2 +47,4 @@

beforeHandleMessage?(data: beforeHandleMessagePayload): Promise<any>,
beforeBroadcastStateless?(data: beforeBroadcastStatelessPayload): Promise<any>,
onStateless?(payload: onStatelessPayload): Promise<any>;
onChange?(data: onChangePayload): Promise<any>,

@@ -64,2 +69,4 @@ onStoreDocument?(data: onStoreDocumentPayload): Promise<any>,

'beforeHandleMessage' |
'beforeBroadcastStateless' |
'onStateless' |
'onChange' |

@@ -81,2 +88,5 @@ 'onStoreDocument' |

onLoadDocumentPayload |
onStatelessPayload |
beforeHandleMessagePayload |
beforeBroadcastStatelessPayload |
onChangePayload |

@@ -144,2 +154,9 @@ onStoreDocumentPayload |

export interface onStatelessPayload {
connection: Connection,
documentName: string,
document: Document,
payload: string,
}
export interface onAuthenticatePayload {

@@ -221,2 +238,8 @@ documentName: string,

export interface beforeBroadcastStatelessPayload {
document: Document,
documentName: string,
payload: string,
}
export interface onStoreDocumentPayload {

@@ -223,0 +246,0 @@ clientsCount: number,

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 too big to display

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