@hocuspocus/provider 1.0.0-alpha.24 → 1.0.0-alpha.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hocuspocus-provider.cjs +297 -65
- package/dist/hocuspocus-provider.cjs.map +1 -1
- package/dist/hocuspocus-provider.esm.js +297 -66
- package/dist/hocuspocus-provider.esm.js.map +1 -1
- package/dist/{shared/protocols → packages/common/src}/auth.d.ts +0 -0
- package/dist/packages/common/src/index.d.ts +1 -0
- package/dist/packages/extension-database/src/Database.d.ts +36 -0
- package/dist/packages/extension-database/src/index.d.ts +1 -0
- package/dist/packages/extension-logger/src/Logger.d.ts +2 -8
- package/dist/packages/extension-sqlite/src/SQLite.d.ts +26 -0
- package/dist/packages/extension-sqlite/src/index.d.ts +1 -0
- package/dist/packages/extension-webhook/src/index.d.ts +1 -1
- package/dist/packages/provider/src/HocuspocusCloudProvider.d.ts +10 -0
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +1 -1
- package/dist/packages/provider/src/index.d.ts +1 -0
- package/dist/packages/server/src/Hocuspocus.d.ts +8 -6
- package/dist/packages/server/src/types.d.ts +12 -0
- package/dist/{demos/backend/src/express.d.ts → playground/backend/src/default.d.ts} +0 -0
- package/dist/{demos/backend/src/koa.d.ts → playground/backend/src/express.d.ts} +0 -0
- package/dist/{demos/backend/src/load-document.d.ts → playground/backend/src/koa.d.ts} +0 -0
- package/dist/{demos/backend/src/minimal.d.ts → playground/backend/src/load-document.d.ts} +0 -0
- package/dist/{demos → playground}/backend/src/monitor.d.ts +0 -0
- package/dist/{demos → playground}/backend/src/redis.d.ts +0 -0
- package/dist/{demos → playground}/backend/src/slow.d.ts +0 -0
- package/dist/{demos → playground}/backend/src/webhook.d.ts +0 -0
- package/package.json +5 -8
- package/src/HocuspocusCloudProvider.ts +26 -0
- package/src/HocuspocusProvider.ts +10 -2
- package/src/MessageReceiver.ts +1 -1
- package/src/OutgoingMessages/AuthenticationMessage.ts +1 -1
- package/src/index.ts +1 -0
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './auth';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Extension, onChangePayload, onLoadDocumentPayload } from '@hocuspocus/server';
|
|
3
|
+
export interface DatabaseConfiguration {
|
|
4
|
+
/**
|
|
5
|
+
* Pass a Promise to retrieve updates from your database. The Promise should resolve to
|
|
6
|
+
* an array of items with Y.js-compatible binary data.
|
|
7
|
+
*/
|
|
8
|
+
fetchUpdates: ({ documentName }: {
|
|
9
|
+
documentName: string;
|
|
10
|
+
}) => Promise<Uint8Array[]>;
|
|
11
|
+
/**
|
|
12
|
+
* Pass a function to store updates in your database.
|
|
13
|
+
*/
|
|
14
|
+
storeUpdate: ({ update, documentName }: {
|
|
15
|
+
update: Buffer;
|
|
16
|
+
documentName: string;
|
|
17
|
+
}) => void;
|
|
18
|
+
}
|
|
19
|
+
export declare class Database implements Extension {
|
|
20
|
+
/**
|
|
21
|
+
* Default configuration
|
|
22
|
+
*/
|
|
23
|
+
configuration: DatabaseConfiguration;
|
|
24
|
+
/**
|
|
25
|
+
* Constructor
|
|
26
|
+
*/
|
|
27
|
+
constructor(configuration: Partial<DatabaseConfiguration>);
|
|
28
|
+
/**
|
|
29
|
+
* Get stored data from the database.
|
|
30
|
+
*/
|
|
31
|
+
onLoadDocument({ document, documentName }: onLoadDocumentPayload): Promise<any>;
|
|
32
|
+
/**
|
|
33
|
+
* Store new updates in the database.
|
|
34
|
+
*/
|
|
35
|
+
onChange({ document, documentName }: onChangePayload): Promise<void>;
|
|
36
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Database';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Extension, onChangePayload, onConfigurePayload, onConnectPayload, onLoadDocumentPayload, onDestroyPayload, onDisconnectPayload,
|
|
1
|
+
import { Extension, onChangePayload, onConfigurePayload, onConnectPayload, onLoadDocumentPayload, onDestroyPayload, onDisconnectPayload, onRequestPayload, onUpgradePayload } from '@hocuspocus/server';
|
|
2
2
|
export interface LoggerConfiguration {
|
|
3
3
|
/**
|
|
4
4
|
* Prepend all logging message with a string.
|
|
@@ -30,10 +30,6 @@ export interface LoggerConfiguration {
|
|
|
30
30
|
* Whether to log something for the `onRequest` hook.
|
|
31
31
|
*/
|
|
32
32
|
onRequest: boolean;
|
|
33
|
-
/**
|
|
34
|
-
* Whether to log something for the `onListen` hook.
|
|
35
|
-
*/
|
|
36
|
-
onListen: boolean;
|
|
37
33
|
/**
|
|
38
34
|
* Whether to log something for the `onDestroy` hook.
|
|
39
35
|
*/
|
|
@@ -54,15 +50,13 @@ export declare class Logger implements Extension {
|
|
|
54
50
|
* Constructor
|
|
55
51
|
*/
|
|
56
52
|
constructor(configuration?: Partial<LoggerConfiguration>);
|
|
53
|
+
onConfigure(data: onConfigurePayload): Promise<void>;
|
|
57
54
|
onLoadDocument(data: onLoadDocumentPayload): Promise<void>;
|
|
58
55
|
onChange(data: onChangePayload): Promise<void>;
|
|
59
56
|
onConnect(data: onConnectPayload): Promise<void>;
|
|
60
57
|
onDisconnect(data: onDisconnectPayload): Promise<void>;
|
|
61
58
|
onUpgrade(data: onUpgradePayload): Promise<void>;
|
|
62
59
|
onRequest(data: onRequestPayload): Promise<void>;
|
|
63
|
-
onListen(data: onListenPayload): Promise<void>;
|
|
64
60
|
onDestroy(data: onDestroyPayload): Promise<void>;
|
|
65
|
-
onConfigure(data: onConfigurePayload): Promise<void>;
|
|
66
|
-
private logRawText;
|
|
67
61
|
private log;
|
|
68
62
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Database, DatabaseConfiguration } from '@hocuspocus/extension-database';
|
|
2
|
+
import sqlite3 from 'sqlite3';
|
|
3
|
+
export interface SQLiteConfiguration extends DatabaseConfiguration {
|
|
4
|
+
/**
|
|
5
|
+
* Valid values are filenames, ":memory:" for an anonymous in-memory database and an empty
|
|
6
|
+
* string for an anonymous disk-based database. Anonymous databases are not persisted and
|
|
7
|
+
* when closing the database handle, their contents are lost.
|
|
8
|
+
*
|
|
9
|
+
* https://github.com/mapbox/node-sqlite3/wiki/API#new-sqlite3databasefilename-mode-callback
|
|
10
|
+
*/
|
|
11
|
+
database: string;
|
|
12
|
+
/**
|
|
13
|
+
* The database schema to create.
|
|
14
|
+
*/
|
|
15
|
+
schema: string;
|
|
16
|
+
}
|
|
17
|
+
export declare class SQLite extends Database {
|
|
18
|
+
db?: sqlite3.Database;
|
|
19
|
+
configuration: SQLiteConfiguration;
|
|
20
|
+
/**
|
|
21
|
+
* Constructor
|
|
22
|
+
*/
|
|
23
|
+
constructor(configuration?: Partial<SQLiteConfiguration>);
|
|
24
|
+
onListen(): Promise<void>;
|
|
25
|
+
onConfigure(): Promise<void>;
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SQLite';
|
|
@@ -42,7 +42,7 @@ export declare class Webhook implements Extension {
|
|
|
42
42
|
/**
|
|
43
43
|
* Send a request to the given url containing the given data
|
|
44
44
|
*/
|
|
45
|
-
sendRequest(event: Events, payload: any): Promise<AxiosResponse<
|
|
45
|
+
sendRequest(event: Events, payload: any): Promise<AxiosResponse<any, any>>;
|
|
46
46
|
/**
|
|
47
47
|
* onChange hook
|
|
48
48
|
*/
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { HocuspocusProvider, HocuspocusProviderOptions } from './HocuspocusProvider';
|
|
2
|
+
export interface HocuspocusCloudProviderOptions extends HocuspocusProviderOptions {
|
|
3
|
+
/**
|
|
4
|
+
* A Hocuspocus Cloud key, get one here: https://hocuspocus.cloud/
|
|
5
|
+
*/
|
|
6
|
+
key: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class HocuspocusCloudProvider extends HocuspocusProvider {
|
|
9
|
+
constructor(options: HocuspocusCloudProviderOptions);
|
|
10
|
+
}
|
|
@@ -130,7 +130,7 @@ export declare class HocuspocusProvider extends EventEmitter {
|
|
|
130
130
|
get awareness(): Awareness;
|
|
131
131
|
checkConnection(): void;
|
|
132
132
|
forceSync(): void;
|
|
133
|
-
|
|
133
|
+
registerEventListeners(): void;
|
|
134
134
|
documentUpdateHandler(update: Uint8Array, origin: any): void;
|
|
135
135
|
awarenessUpdateHandler({ added, updated, removed }: any, origin: any): void;
|
|
136
136
|
permissionDeniedHandler(reason: string): void;
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import WebSocket, { WebSocketServer } from 'ws';
|
|
3
3
|
import { IncomingMessage, Server as HTTPServer } from 'http';
|
|
4
|
-
import { Configuration } from './types';
|
|
4
|
+
import { Configuration, Hook } from './types';
|
|
5
5
|
import { MessageLogger } from './Debugger';
|
|
6
|
+
import { onListenPayload } from '.';
|
|
6
7
|
export declare const defaultConfiguration: {
|
|
7
8
|
name: null;
|
|
8
9
|
port: number;
|
|
9
10
|
timeout: number;
|
|
11
|
+
quiet: boolean;
|
|
10
12
|
};
|
|
11
13
|
/**
|
|
12
|
-
* Hocuspocus
|
|
14
|
+
* Hocuspocus Server
|
|
13
15
|
*/
|
|
14
16
|
export declare class Hocuspocus {
|
|
15
17
|
configuration: Configuration;
|
|
@@ -25,7 +27,8 @@ export declare class Hocuspocus {
|
|
|
25
27
|
/**
|
|
26
28
|
* Start the server
|
|
27
29
|
*/
|
|
28
|
-
listen(): Promise<void>;
|
|
30
|
+
listen(portOrCallback?: number | ((data: onListenPayload) => Promise<any>) | null, callback?: any): Promise<void>;
|
|
31
|
+
private showStartScreen;
|
|
29
32
|
/**
|
|
30
33
|
* Get the total number of active documents
|
|
31
34
|
*/
|
|
@@ -64,9 +67,8 @@ export declare class Hocuspocus {
|
|
|
64
67
|
/**
|
|
65
68
|
* Run the given hook on all configured extensions
|
|
66
69
|
* Runs the given callback after each hook
|
|
67
|
-
* @private
|
|
68
70
|
*/
|
|
69
|
-
|
|
71
|
+
hooks(name: Hook, payload: any, callback?: Function | null): Promise<any>;
|
|
70
72
|
/**
|
|
71
73
|
* Get parameters by the given request
|
|
72
74
|
* @private
|
|
@@ -76,7 +78,7 @@ export declare class Hocuspocus {
|
|
|
76
78
|
* Get document name by the given request
|
|
77
79
|
* @private
|
|
78
80
|
*/
|
|
79
|
-
private
|
|
81
|
+
private getDocumentNameFromRequest;
|
|
80
82
|
enableDebugging(): void;
|
|
81
83
|
enableMessageLogging(): void;
|
|
82
84
|
disableLogging(): void;
|
|
@@ -67,6 +67,18 @@ export interface Configuration extends Extension {
|
|
|
67
67
|
* Defines in which interval the server sends a ping, and closes the connection when no pong is sent back.
|
|
68
68
|
*/
|
|
69
69
|
timeout: number;
|
|
70
|
+
/**
|
|
71
|
+
* By default, the servers show a start screen. If passed false, the server will start quietly.
|
|
72
|
+
*/
|
|
73
|
+
quiet: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Function which returns the (customized) document name based on the request
|
|
76
|
+
*/
|
|
77
|
+
getDocumentName?(data: {
|
|
78
|
+
documentName: string;
|
|
79
|
+
request: IncomingMessage;
|
|
80
|
+
requestParameters: URLSearchParams;
|
|
81
|
+
}): string | Promise<string>;
|
|
70
82
|
}
|
|
71
83
|
export interface onAuthenticatePayload {
|
|
72
84
|
documentName: string;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hocuspocus/provider",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.28",
|
|
4
4
|
"description": "hocuspocus provider",
|
|
5
5
|
"homepage": "https://hocuspocus.dev",
|
|
6
6
|
"keywords": [
|
|
@@ -28,13 +28,10 @@
|
|
|
28
28
|
"dist"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@lifeomic/attempt": "^3.0.
|
|
32
|
-
"lib0": "^0.2.
|
|
31
|
+
"@lifeomic/attempt": "^3.0.1",
|
|
32
|
+
"lib0": "^0.2.43",
|
|
33
33
|
"y-protocols": "^1.0.5",
|
|
34
|
-
"yjs": "^13.5.
|
|
34
|
+
"yjs": "^13.5.22"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
37
|
-
"publishConfig": {
|
|
38
|
-
"access": "public"
|
|
39
|
-
}
|
|
36
|
+
"gitHead": "8ffe8d8f4d10ba33f4f203806bd1d4415bef5dc3"
|
|
40
37
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { HocuspocusProvider, HocuspocusProviderOptions } from './HocuspocusProvider'
|
|
2
|
+
|
|
3
|
+
export interface HocuspocusCloudProviderOptions extends HocuspocusProviderOptions {
|
|
4
|
+
/**
|
|
5
|
+
* A Hocuspocus Cloud key, get one here: https://hocuspocus.cloud/
|
|
6
|
+
*/
|
|
7
|
+
key: string,
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class HocuspocusCloudProvider extends HocuspocusProvider {
|
|
11
|
+
constructor(options: HocuspocusCloudProviderOptions) {
|
|
12
|
+
if (!options.url) {
|
|
13
|
+
options.url = 'wss://connect.hocuspocus.cloud'
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (options.key) {
|
|
17
|
+
if (!options.parameters) {
|
|
18
|
+
options.parameters = {}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
options.parameters.key = options.key
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
super(options as HocuspocusProviderOptions)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -195,6 +195,7 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
195
195
|
super()
|
|
196
196
|
this.setOptions(options)
|
|
197
197
|
|
|
198
|
+
this.options.document = options.document ? options.document : new Y.Doc()
|
|
198
199
|
this.options.awareness = options.awareness ? options.awareness : new Awareness(this.document)
|
|
199
200
|
this.options.WebSocketPolyfill = options.WebSocketPolyfill ? options.WebSocketPolyfill : WebSocket
|
|
200
201
|
|
|
@@ -222,7 +223,7 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
222
223
|
|
|
223
224
|
this.document.on('update', this.documentUpdateHandler.bind(this))
|
|
224
225
|
this.awareness.on('update', this.awarenessUpdateHandler.bind(this))
|
|
225
|
-
this.
|
|
226
|
+
this.registerEventListeners()
|
|
226
227
|
|
|
227
228
|
this.intervals.connectionChecker = setInterval(
|
|
228
229
|
this.checkConnection.bind(this),
|
|
@@ -357,11 +358,12 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
357
358
|
this.send(SyncStepOneMessage, { document: this.document })
|
|
358
359
|
}
|
|
359
360
|
|
|
360
|
-
|
|
361
|
+
registerEventListeners() {
|
|
361
362
|
if (typeof window === 'undefined') {
|
|
362
363
|
return
|
|
363
364
|
}
|
|
364
365
|
|
|
366
|
+
window.addEventListener('online', this.connect.bind(this))
|
|
365
367
|
window.addEventListener('beforeunload', () => {
|
|
366
368
|
removeAwarenessStates(this.awareness, [this.document.clientID], 'window unload')
|
|
367
369
|
})
|
|
@@ -579,6 +581,12 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
579
581
|
this.document.off('update', this.documentUpdateHandler)
|
|
580
582
|
|
|
581
583
|
this.removeAllListeners()
|
|
584
|
+
|
|
585
|
+
if (typeof window === 'undefined') {
|
|
586
|
+
return
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
window.removeEventListener('online', this.connect.bind(this))
|
|
582
590
|
}
|
|
583
591
|
|
|
584
592
|
get broadcastChannel() {
|
package/src/MessageReceiver.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as awarenessProtocol from 'y-protocols/awareness'
|
|
2
2
|
import { readSyncMessage, messageYjsSyncStep2 } from 'y-protocols/sync'
|
|
3
|
+
import { readAuthMessage } from '@hocuspocus/common'
|
|
3
4
|
import { MessageType } from './types'
|
|
4
5
|
import { HocuspocusProvider } from './HocuspocusProvider'
|
|
5
6
|
import { IncomingMessage } from './IncomingMessage'
|
|
6
|
-
import { readAuthMessage } from '../../../shared/protocols/auth'
|
|
7
7
|
import { OutgoingMessage } from './OutgoingMessage'
|
|
8
8
|
|
|
9
9
|
export class MessageReceiver {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { writeVarUint } from 'lib0/encoding'
|
|
2
|
-
import { writeAuthentication } from '
|
|
2
|
+
import { writeAuthentication } from '@hocuspocus/common'
|
|
3
3
|
import { MessageType, OutgoingMessageArguments } from '../types'
|
|
4
4
|
import { OutgoingMessage } from '../OutgoingMessage'
|
|
5
5
|
|
package/src/index.ts
CHANGED