@hocuspocus/server
Advanced tools
Comparing version 2.12.3 to 2.13.0
@@ -29,2 +29,3 @@ /// <reference types="node" /> | ||
configuration: Configuration; | ||
loadingDocuments: Map<string, Promise<Document>>; | ||
documents: Map<string, Document>; | ||
@@ -91,2 +92,3 @@ server?: HocuspocusServer; | ||
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, connection: ConnectionConfiguration, context?: any): Promise<Document>; | ||
storeDocumentHooks(document: Document, hookPayload: onStoreDocumentPayload): Promise<void>; | ||
@@ -93,0 +95,0 @@ /** |
{ | ||
"name": "@hocuspocus/server", | ||
"description": "plug & play collaboration backend", | ||
"version": "2.12.3", | ||
"version": "2.13.0", | ||
"homepage": "https://hocuspocus.dev", | ||
@@ -32,3 +32,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@hocuspocus/common": "^2.12.3", | ||
"@hocuspocus/common": "^2.13.0", | ||
"async-lock": "^1.3.1", | ||
@@ -35,0 +35,0 @@ "kleur": "^4.1.4", |
@@ -75,2 +75,4 @@ import { IncomingMessage } from 'http' | ||
loadingDocuments: Map<string, Promise<Document>> = new Map() | ||
documents: Map<string, Document> = new Map() | ||
@@ -419,10 +421,29 @@ | ||
public async createDocument(documentName: string, request: Partial<Pick<IncomingMessage, 'headers' | 'url'>>, socketId: string, connection: ConnectionConfiguration, context?: any): Promise<Document> { | ||
if (this.documents.has(documentName)) { | ||
const document = this.documents.get(documentName) | ||
const existingLoadingDoc = this.loadingDocuments.get(documentName) | ||
if (document) { | ||
return document | ||
} | ||
if (existingLoadingDoc) { | ||
return existingLoadingDoc | ||
} | ||
const existingDoc = this.documents.get(documentName) | ||
if (existingDoc) { | ||
return Promise.resolve(existingDoc) | ||
} | ||
const loadDocPromise = this.loadDocument(documentName, request, socketId, connection, context) | ||
this.loadingDocuments.set(documentName, loadDocPromise) | ||
try { | ||
await loadDocPromise | ||
this.loadingDocuments.delete(documentName) | ||
} catch (e) { | ||
this.loadingDocuments.delete(documentName) | ||
throw e | ||
} | ||
return loadDocPromise | ||
} | ||
async loadDocument(documentName: string, request: Partial<Pick<IncomingMessage, 'headers' | 'url'>>, socketId: string, connection: ConnectionConfiguration, context?: any): Promise<Document> { | ||
const requestHeaders = request.headers ?? {} | ||
@@ -429,0 +450,0 @@ const requestParameters = getParameters(request) |
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
821107
9699
Updated@hocuspocus/common@^2.13.0