@hocuspocus/server
Advanced tools
Comparing version 2.5.0-rc.0 to 2.5.0
@@ -0,1 +1,2 @@ | ||
/// <reference types="node" /> | ||
import RedisClient, { ClusterNode, ClusterOptions, RedisOptions } from 'ioredis'; | ||
@@ -59,2 +60,3 @@ import Redlock from 'redlock'; | ||
configuration: Configuration; | ||
redisTransactionOrigin: string; | ||
pub: RedisInstance; | ||
@@ -66,2 +68,3 @@ sub: RedisInstance; | ||
logger: Debugger; | ||
messagePrefix: Buffer; | ||
constructor(configuration: Partial<Configuration>); | ||
@@ -73,2 +76,4 @@ onConfigure({ instance }: onConfigurePayload): Promise<void>; | ||
private lockKey; | ||
private encodeMessage; | ||
private decodeMessage; | ||
/** | ||
@@ -100,3 +105,3 @@ * Once a document is loaded, subscribe to the channel in Redis. | ||
/** | ||
* Handle incoming messages published on all subscribed document channels. | ||
* Handle incoming messages published on subscribed document channels. | ||
* Note that this will also include messages from ourselves as it is not possible | ||
@@ -103,0 +108,0 @@ * in Redis to filter these. |
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import { IncomingMessage } from 'http'; | ||
@@ -32,2 +31,3 @@ import WebSocket, { AddressInfo } from 'ws'; | ||
debugger: Debugger; | ||
debounce: (id: string, func: Function, debounce: number, maxDebounce: number) => void; | ||
constructor(configuration?: Partial<Configuration>); | ||
@@ -82,11 +82,3 @@ /** | ||
private handleDocumentUpdate; | ||
timers: Map<string, { | ||
timeout: NodeJS.Timeout; | ||
start: number; | ||
}>; | ||
/** | ||
* debounce the given function, using the given identifier | ||
*/ | ||
debounce(id: string, func: Function, immediately?: boolean): void; | ||
/** | ||
* Create a new document by the given request | ||
@@ -93,0 +85,0 @@ */ |
@@ -9,1 +9,2 @@ export * from './Connection.js'; | ||
export * from './types.js'; | ||
export * from './util/debounce.js'; |
@@ -8,3 +8,4 @@ import Connection from './Connection.js'; | ||
logger: Debugger; | ||
constructor(message: IncomingMessage, logger: Debugger); | ||
defaultTransactionOrigin?: string; | ||
constructor(message: IncomingMessage, logger: Debugger, defaultTransactionOrigin?: string); | ||
apply(document: Document, connection?: Connection, reply?: (message: Uint8Array) => void): void; | ||
@@ -11,0 +12,0 @@ readSyncMessage(message: IncomingMessage, document: Document, connection?: Connection, reply?: (message: Uint8Array) => void, requestFirstSync?: boolean): 0 | 1 | 2; |
@@ -126,12 +126,3 @@ /// <reference types="node" /> | ||
}; | ||
/** | ||
* Function which returns the (customized) document name based on the request | ||
*/ | ||
getDocumentName?(data: getDocumentNamePayload): string | Promise<string>; | ||
} | ||
export interface getDocumentNamePayload { | ||
documentName: string; | ||
request: IncomingMessage; | ||
requestParameters: URLSearchParams; | ||
} | ||
export interface onStatelessPayload { | ||
@@ -138,0 +129,0 @@ connection: Connection; |
{ | ||
"name": "@hocuspocus/server", | ||
"description": "plug & play collaboration backend", | ||
"version": "2.5.0-rc.0", | ||
"version": "2.5.0", | ||
"homepage": "https://hocuspocus.dev", | ||
@@ -32,3 +32,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@hocuspocus/common": "^2.5.0-rc.0", | ||
"@hocuspocus/common": "^2.5.0", | ||
"async-lock": "^1.3.1", | ||
@@ -35,0 +35,0 @@ "kleur": "^4.1.4", |
@@ -31,2 +31,3 @@ import { IncomingMessage } from 'http' | ||
import { getParameters } from './util/getParameters.js' | ||
import { useDebounce } from './util/debounce' | ||
@@ -79,2 +80,4 @@ export const defaultConfiguration = { | ||
debounce = useDebounce() | ||
constructor(configuration?: Partial<Configuration>) { | ||
@@ -333,5 +336,10 @@ if (configuration) { | ||
if (!document.isLoading) { | ||
this.debounce(`onStoreDocument-${document.name}`, () => { | ||
this.storeDocumentHooks(document, hookPayload) | ||
}, this.configuration.unloadImmediately) | ||
this.debounce( | ||
`onStoreDocument-${document.name}`, | ||
() => { | ||
this.storeDocumentHooks(document, hookPayload) | ||
}, | ||
this.configuration.unloadImmediately ? 0 : this.configuration.debounce, | ||
this.configuration.maxDebounce, | ||
) | ||
} else { | ||
@@ -376,43 +384,13 @@ // Remove document from memory immediately | ||
this.debounce(`onStoreDocument-${document.name}`, () => { | ||
this.storeDocumentHooks(document, hookPayload) | ||
}) | ||
this.debounce( | ||
`onStoreDocument-${document.name}`, | ||
() => { | ||
this.storeDocumentHooks(document, hookPayload) | ||
}, | ||
this.configuration.debounce, | ||
this.configuration.maxDebounce, | ||
) | ||
} | ||
timers: Map<string, { | ||
timeout: NodeJS.Timeout, | ||
start: number | ||
}> = new Map() | ||
/** | ||
* debounce the given function, using the given identifier | ||
*/ | ||
debounce(id: string, func: Function, immediately = false) { | ||
const old = this.timers.get(id) | ||
const start = old?.start || Date.now() | ||
const run = () => { | ||
this.timers.delete(id) | ||
func() | ||
} | ||
if (old?.timeout) { | ||
clearTimeout(old.timeout) | ||
} | ||
if (immediately) { | ||
return run() | ||
} | ||
if (Date.now() - start >= this.configuration.maxDebounce) { | ||
return run() | ||
} | ||
this.timers.set(id, { | ||
start, | ||
timeout: setTimeout(run, this.configuration.debounce), | ||
}) | ||
} | ||
/** | ||
* Create a new document by the given request | ||
@@ -419,0 +397,0 @@ */ |
@@ -9,1 +9,2 @@ export * from './Connection.js' | ||
export * from './types.js' | ||
export * from './util/debounce.js' |
@@ -26,5 +26,8 @@ import * as decoding from 'lib0/decoding' | ||
constructor(message: IncomingMessage, logger: Debugger) { | ||
defaultTransactionOrigin?: string | ||
constructor(message: IncomingMessage, logger: Debugger, defaultTransactionOrigin?: string) { | ||
this.message = message | ||
this.logger = logger | ||
this.defaultTransactionOrigin = defaultTransactionOrigin | ||
} | ||
@@ -183,3 +186,3 @@ | ||
readSyncStep2(message.decoder, document, connection) | ||
readSyncStep2(message.decoder, document, connection ?? this.defaultTransactionOrigin) | ||
@@ -186,0 +189,0 @@ if (connection) { |
@@ -151,15 +151,5 @@ import { | ||
}, | ||
/** | ||
* Function which returns the (customized) document name based on the request | ||
*/ | ||
getDocumentName?(data: getDocumentNamePayload): string | Promise<string>, | ||
} | ||
export interface getDocumentNamePayload { | ||
documentName: string, | ||
request: IncomingMessage, | ||
requestParameters: URLSearchParams, | ||
} | ||
export interface onStatelessPayload { | ||
@@ -166,0 +156,0 @@ connection: Connection, |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
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
819174
9656
0
144
Updated@hocuspocus/common@^2.5.0