@hocuspocus/server
Advanced tools
Comparing version 1.0.0-alpha.85 to 1.0.0-alpha.86
@@ -1,2 +0,2 @@ | ||
import { Extension, onChangePayload, onConfigurePayload, onConnectPayload, onLoadDocumentPayload, onDestroyPayload, onDisconnectPayload, onListenPayload, onRequestPayload, onUpgradePayload } from '@hocuspocus/server'; | ||
import { Extension, onChangePayload, onConfigurePayload, onConnectPayload, onLoadDocumentPayload, onDestroyPayload, onDisconnectPayload, onRequestPayload, onUpgradePayload } from '@hocuspocus/server'; | ||
export interface LoggerConfiguration { | ||
@@ -34,6 +34,2 @@ /** | ||
/** | ||
* Whether to log something for the `onListen` hook. | ||
*/ | ||
onListen: boolean; | ||
/** | ||
* Whether to log something for the `onDestroy` hook. | ||
@@ -58,2 +54,3 @@ */ | ||
constructor(configuration?: Partial<LoggerConfiguration>); | ||
onConfigure(data: onConfigurePayload): Promise<void>; | ||
onLoadDocument(data: onLoadDocumentPayload): Promise<void>; | ||
@@ -65,7 +62,4 @@ onChange(data: onChangePayload): Promise<void>; | ||
onRequest(data: onRequestPayload): Promise<void>; | ||
onListen(data: onListenPayload): Promise<void>; | ||
onDestroy(data: onDestroyPayload): Promise<void>; | ||
onConfigure(data: onConfigurePayload): Promise<void>; | ||
private logRawText; | ||
private log; | ||
} |
@@ -6,2 +6,3 @@ /// <reference types="node" /> | ||
import { MessageLogger } from './Debugger'; | ||
import { onListenPayload } from '.'; | ||
export declare const defaultConfiguration: { | ||
@@ -11,5 +12,6 @@ name: null; | ||
timeout: number; | ||
quiet: boolean; | ||
}; | ||
/** | ||
* Hocuspocus server | ||
* Hocuspocus Server | ||
*/ | ||
@@ -30,3 +32,4 @@ export declare class Hocuspocus { | ||
*/ | ||
listen(): Promise<void>; | ||
listen(portOrCallback?: number | ((data: onListenPayload) => Promise<any>) | null, callback?: any): Promise<void>; | ||
private showStartScreen; | ||
/** | ||
@@ -33,0 +36,0 @@ * Get the total number of active documents |
@@ -71,2 +71,6 @@ /// <reference types="node" /> | ||
/** | ||
* By default, the servers show a start screen. If passed false, the server will start quietly. | ||
*/ | ||
quiet: boolean; | ||
/** | ||
* Function which returns the (customized) document name based on the request | ||
@@ -73,0 +77,0 @@ */ |
{ | ||
"name": "@hocuspocus/server", | ||
"description": "plug & play collaboration backend", | ||
"version": "1.0.0-alpha.85", | ||
"version": "1.0.0-alpha.86", | ||
"homepage": "https://hocuspocus.dev", | ||
@@ -31,3 +31,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@hocuspocus/common": "^1.0.0-alpha.2", | ||
"@hocuspocus/common": "^1.0.0-alpha.3", | ||
"@types/async-lock": "^1.1.2", | ||
@@ -37,2 +37,3 @@ "@types/uuid": "^8.3.0", | ||
"async-lock": "^1.2.8", | ||
"chalk": "^5.0.0", | ||
"lib0": "^0.2.41", | ||
@@ -43,3 +44,3 @@ "uuid": "^8.3.2", | ||
}, | ||
"gitHead": "63a50dd02286693b5025ac385c3fb4afd6b29050" | ||
"gitHead": "505fc82451201ef77847dc5bc9e92edb498dcb8e" | ||
} |
@@ -7,2 +7,3 @@ import * as decoding from 'lib0/decoding' | ||
import { v4 as uuid } from 'uuid' | ||
import chalk from 'chalk' | ||
import { | ||
@@ -15,4 +16,5 @@ MessageType, Configuration, ConnectionConfig, WsReadyStates, Hook, | ||
import { OutgoingMessage } from './OutgoingMessage' | ||
import packageJson from '../package.json' | ||
import meta from '../package.json' | ||
import { Debugger, MessageLogger } from './Debugger' | ||
import { onListenPayload } from '.' | ||
@@ -23,2 +25,3 @@ export const defaultConfiguration = { | ||
timeout: 30000, | ||
quiet: false, | ||
} | ||
@@ -29,3 +32,3 @@ | ||
/** | ||
* Hocuspocus server | ||
* Hocuspocus Server | ||
*/ | ||
@@ -92,3 +95,3 @@ export class Hocuspocus { | ||
configuration: this.configuration, | ||
version: packageJson.version, | ||
version: meta.version, | ||
yjsVersion: null, | ||
@@ -110,3 +113,22 @@ instance: this, | ||
*/ | ||
async listen(): Promise<void> { | ||
async listen( | ||
portOrCallback: number | ((data: onListenPayload) => Promise<any>) | null = null, | ||
callback: any = null, | ||
): Promise<void> { | ||
if (typeof portOrCallback === 'number') { | ||
this.configuration.port = portOrCallback | ||
} | ||
if (typeof portOrCallback === 'function') { | ||
this.configuration.extensions.push({ | ||
onListen: portOrCallback, | ||
}) | ||
} | ||
if (typeof callback === 'function') { | ||
this.configuration.extensions.push({ | ||
onListen: callback, | ||
}) | ||
} | ||
const webSocketServer = new WebSocketServer({ noServer: true }) | ||
@@ -161,2 +183,6 @@ | ||
server.listen(this.configuration.port, () => { | ||
if (!this.configuration.quiet && process.env.NODE_ENV !== 'testing') { | ||
this.showStartScreen() | ||
} | ||
this.hooks('onListen', { port: this.configuration.port }) | ||
@@ -169,2 +195,34 @@ .then(() => resolve()) | ||
private showStartScreen() { | ||
const name = this.configuration.name ? ` (${this.configuration.name})` : '' | ||
console.log() | ||
console.log(` ${chalk.cyan(`Hocuspocus v${meta.version}${name}`)}${chalk.green(' running at:')}`) | ||
console.log() | ||
console.log(` > HTTP: ${chalk.cyan(`http://127.0.0.1:${this.configuration.port}`)}`) | ||
console.log(` > WebSocket: ws://127.0.0.1:${this.configuration.port}`) | ||
const extensions = this.configuration?.extensions.map(extension => { | ||
return extension.constructor?.name | ||
}) | ||
.filter(name => name) | ||
.filter(name => name !== 'Object') | ||
if (!extensions.length) { | ||
return | ||
} | ||
console.log() | ||
console.log(' Extensions:') | ||
extensions | ||
.forEach(name => { | ||
console.log(` - ${name}`) | ||
}) | ||
console.log() | ||
console.log(` ${chalk.green('Ready.')}`) | ||
console.log() | ||
} | ||
/** | ||
@@ -171,0 +229,0 @@ * Get the total number of active documents |
@@ -89,2 +89,6 @@ import { | ||
/** | ||
* By default, the servers show a start screen. If passed false, the server will start quietly. | ||
*/ | ||
quiet: boolean, | ||
/** | ||
* Function which returns the (customized) document name based on the request | ||
@@ -91,0 +95,0 @@ */ |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
538863
6497
10
3
+ Addedchalk@^5.0.0
+ Addedchalk@5.3.0(transitive)