@hocuspocus/extension-throttle 1.1.0 → 2.0.0-alpha.0

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.
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { IncomingMessage, ServerResponse } from 'http';
3
- import WebSocket, { WebSocketServer } from 'ws';
4
3
  import { Socket } from 'net';
4
+ import WebSocket, { WebSocketServer } from 'ws';
5
5
  import { Storage } from './Storage';
6
6
  export interface Configuration {
7
7
  password: string | undefined;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
- import { Extension, onChangePayload, onConfigurePayload, onLoadDocumentPayload, onDisconnectPayload, onRequestPayload, onUpgradePayload, connectedPayload } from '@hocuspocus/server';
3
2
  import { IncomingMessage, ServerResponse } from 'http';
3
+ import { Extension, onChangePayload, onConfigurePayload, onLoadDocumentPayload, onDisconnectPayload, onRequestPayload, onUpgradePayload, connectedPayload } from '@hocuspocus/server';
4
4
  import WebSocket from 'ws';
5
5
  import { Storage } from './Storage';
6
6
  import { Dashboard } from './Dashboard';
@@ -1,5 +1,6 @@
1
1
  import { HocuspocusProvider, HocuspocusProviderConfiguration } from './HocuspocusProvider';
2
- export declare type HocuspocusCloudProviderConfiguration = Required<Pick<HocuspocusProviderConfiguration, 'name'>> & Partial<HocuspocusProviderConfiguration> & AdditionalHocuspocusCloudProviderConfiguration;
2
+ import { HocuspocusProviderWebsocketConfiguration } from './HocuspocusProviderWebsocket';
3
+ export declare type HocuspocusCloudProviderConfiguration = Required<Pick<HocuspocusProviderConfiguration, 'name'>> & Partial<HocuspocusProviderConfiguration> & Partial<Pick<HocuspocusProviderWebsocketConfiguration, 'url'>> & AdditionalHocuspocusCloudProviderConfiguration;
3
4
  export interface AdditionalHocuspocusCloudProviderConfiguration {
4
5
  /**
5
6
  * A Hocuspocus Cloud key, get one here: https://hocuspocus.cloud/
@@ -1,16 +1,13 @@
1
1
  import * as Y from 'yjs';
2
2
  import { Awareness } from 'y-protocols/awareness';
3
3
  import * as mutex from 'lib0/mutex';
4
- import type { Event, CloseEvent, MessageEvent } from 'ws';
4
+ import type { CloseEvent, Event, MessageEvent } from 'ws';
5
5
  import EventEmitter from './EventEmitter';
6
6
  import { ConstructableOutgoingMessage, onAuthenticationFailedParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatelessParameters, onStatusParameters, onSyncedParameters, WebSocketStatus } from './types';
7
+ import { HocuspocusProviderWebsocket } from './HocuspocusProviderWebsocket';
7
8
  import { onAwarenessChangeParameters, onAwarenessUpdateParameters } from '.';
8
- export declare type HocuspocusProviderConfiguration = Required<Pick<CompleteHocuspocusProviderConfiguration, 'url' | 'name'>> & Partial<CompleteHocuspocusProviderConfiguration>;
9
+ export declare type HocuspocusProviderConfiguration = Required<Pick<CompleteHocuspocusProviderConfiguration, 'name' | 'websocketProvider'>> & Partial<CompleteHocuspocusProviderConfiguration>;
9
10
  export interface CompleteHocuspocusProviderConfiguration {
10
- /**
11
- * URL of your @hocuspocus/server instance
12
- */
13
- url: string;
14
11
  /**
15
12
  * The identifier/name of your document
16
13
  */
@@ -19,10 +16,6 @@ export interface CompleteHocuspocusProviderConfiguration {
19
16
  * The actual Y.js document
20
17
  */
21
18
  document: Y.Doc;
22
- /**
23
- * Pass `false` to start the connection manually.
24
- */
25
- connect: boolean;
26
19
  /**
27
20
  * Pass false to disable broadcasting between browser tabs.
28
21
  */
@@ -42,49 +35,13 @@ export interface CompleteHocuspocusProviderConfiguration {
42
35
  [key: string]: any;
43
36
  };
44
37
  /**
45
- * An optional WebSocket polyfill, for example for Node.js
38
+ * Hocuspocus websocket provider
46
39
  */
47
- WebSocketPolyfill: any;
40
+ websocketProvider: HocuspocusProviderWebsocket;
48
41
  /**
49
42
  * Force syncing the document in the defined interval.
50
43
  */
51
44
  forceSyncInterval: false | number;
52
- /**
53
- * Disconnect when no message is received for the defined amount of milliseconds.
54
- */
55
- messageReconnectTimeout: number;
56
- /**
57
- * The delay between each attempt in milliseconds. You can provide a factor to have the delay grow exponentially.
58
- */
59
- delay: number;
60
- /**
61
- * The intialDelay is the amount of time to wait before making the first attempt. This option should typically be 0 since you typically want the first attempt to happen immediately.
62
- */
63
- initialDelay: number;
64
- /**
65
- * The factor option is used to grow the delay exponentially.
66
- */
67
- factor: number;
68
- /**
69
- * The maximum number of attempts or 0 if there is no limit on number of attempts.
70
- */
71
- maxAttempts: number;
72
- /**
73
- * minDelay is used to set a lower bound of delay when jitter is enabled. This property has no effect if jitter is disabled.
74
- */
75
- minDelay: number;
76
- /**
77
- * The maxDelay option is used to set an upper bound for the delay when factor is enabled. A value of 0 can be provided if there should be no upper bound when calculating delay.
78
- */
79
- maxDelay: number;
80
- /**
81
- * If jitter is true then the calculated delay will be a random integer value between minDelay and the calculated delay for the current iteration.
82
- */
83
- jitter: boolean;
84
- /**
85
- * A timeout in milliseconds. If timeout is non-zero then a timer is set using setTimeout. If the timeout is triggered then future attempts will be aborted.
86
- */
87
- timeout: number;
88
45
  onAuthenticated: () => void;
89
46
  onAuthenticationFailed: (data: onAuthenticationFailedParameters) => void;
90
47
  onOpen: (data: onOpenParameters) => void;
@@ -107,32 +64,18 @@ export interface CompleteHocuspocusProviderConfiguration {
107
64
  export declare class HocuspocusProvider extends EventEmitter {
108
65
  configuration: CompleteHocuspocusProviderConfiguration;
109
66
  subscribedToBroadcastChannel: boolean;
110
- webSocket: WebSocket | null;
111
- shouldConnect: boolean;
112
- status: WebSocketStatus;
113
67
  isSynced: boolean;
114
68
  unsyncedChanges: number;
69
+ status: WebSocketStatus;
115
70
  isAuthenticated: boolean;
116
- lastMessageReceived: number;
117
71
  mux: mutex.mutex;
118
72
  intervals: any;
119
- connectionAttempt: {
120
- resolve: (value?: any) => void;
121
- reject: (reason?: any) => void;
122
- } | null;
123
73
  constructor(configuration: HocuspocusProviderConfiguration);
74
+ onStatus({ status }: onStatusParameters): void;
124
75
  setConfiguration(configuration?: Partial<HocuspocusProviderConfiguration>): void;
125
- boundConnect: () => Promise<unknown>;
126
- cancelWebsocketRetry?: () => void;
127
- connect(): Promise<unknown>;
128
- createWebSocketConnection(): Promise<unknown>;
129
- resolveConnectionAttempt(): void;
130
- stopConnectionAttempt(): void;
131
- rejectConnectionAttempt(): void;
132
76
  get document(): Y.Doc;
133
77
  get awareness(): Awareness;
134
78
  get hasUnsyncedChanges(): boolean;
135
- checkConnection(): void;
136
79
  forceSync(): void;
137
80
  boundBeforeUnload: () => void;
138
81
  beforeUnload(): void;
@@ -140,10 +83,6 @@ export declare class HocuspocusProvider extends EventEmitter {
140
83
  sendStateless(payload: string): void;
141
84
  documentUpdateHandler(update: Uint8Array, origin: any): void;
142
85
  awarenessUpdateHandler({ added, updated, removed }: any, origin: any): void;
143
- permissionDeniedHandler(reason: string): void;
144
- authenticatedHandler(): void;
145
- get serverUrl(): string;
146
- get url(): string;
147
86
  get synced(): boolean;
148
87
  set synced(state: boolean);
149
88
  receiveStateless(payload: string): void;
@@ -152,10 +91,12 @@ export declare class HocuspocusProvider extends EventEmitter {
152
91
  onOpen(event: Event): Promise<void>;
153
92
  getToken(): Promise<string | null>;
154
93
  startSync(): void;
155
- send(Message: ConstructableOutgoingMessage, args: any, broadcast?: boolean): void;
94
+ send(message: ConstructableOutgoingMessage, args: any, broadcast?: boolean): void;
156
95
  onMessage(event: MessageEvent): void;
157
96
  onClose(event: CloseEvent): void;
158
97
  destroy(): void;
98
+ permissionDeniedHandler(reason: string): void;
99
+ authenticatedHandler(): void;
159
100
  get broadcastChannel(): string;
160
101
  boundBroadcastChannelSubscriber: (data: ArrayBuffer) => void;
161
102
  broadcastChannelSubscriber(data: ArrayBuffer): void;
@@ -0,0 +1,115 @@
1
+ import * as mutex from 'lib0/mutex';
2
+ import type { MessageEvent } from 'ws';
3
+ import { Event } from 'ws';
4
+ import EventEmitter from './EventEmitter';
5
+ import { onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatusParameters, WebSocketStatus } from './types';
6
+ import { HocuspocusProvider, onAwarenessChangeParameters, onAwarenessUpdateParameters } from '.';
7
+ export declare type HocuspocusProviderWebsocketConfiguration = Required<Pick<CompleteHocuspocusProviderWebsocketConfiguration, 'url'>> & Partial<CompleteHocuspocusProviderWebsocketConfiguration>;
8
+ export interface CompleteHocuspocusProviderWebsocketConfiguration {
9
+ /**
10
+ * URL of your @hocuspocus/server instance
11
+ */
12
+ url: string;
13
+ /**
14
+ * Pass `false` to start the connection manually.
15
+ */
16
+ connect: boolean;
17
+ /**
18
+ * URL parameters that should be added.
19
+ */
20
+ parameters: {
21
+ [key: string]: any;
22
+ };
23
+ /**
24
+ * An optional WebSocket polyfill, for example for Node.js
25
+ */
26
+ WebSocketPolyfill: any;
27
+ /**
28
+ * Disconnect when no message is received for the defined amount of milliseconds.
29
+ */
30
+ messageReconnectTimeout: number;
31
+ /**
32
+ * The delay between each attempt in milliseconds. You can provide a factor to have the delay grow exponentially.
33
+ */
34
+ delay: number;
35
+ /**
36
+ * The intialDelay is the amount of time to wait before making the first attempt. This option should typically be 0 since you typically want the first attempt to happen immediately.
37
+ */
38
+ initialDelay: number;
39
+ /**
40
+ * The factor option is used to grow the delay exponentially.
41
+ */
42
+ factor: number;
43
+ /**
44
+ * The maximum number of attempts or 0 if there is no limit on number of attempts.
45
+ */
46
+ maxAttempts: number;
47
+ /**
48
+ * minDelay is used to set a lower bound of delay when jitter is enabled. This property has no effect if jitter is disabled.
49
+ */
50
+ minDelay: number;
51
+ /**
52
+ * The maxDelay option is used to set an upper bound for the delay when factor is enabled. A value of 0 can be provided if there should be no upper bound when calculating delay.
53
+ */
54
+ maxDelay: number;
55
+ /**
56
+ * If jitter is true then the calculated delay will be a random integer value between minDelay and the calculated delay for the current iteration.
57
+ */
58
+ jitter: boolean;
59
+ /**
60
+ * A timeout in milliseconds. If timeout is non-zero then a timer is set using setTimeout. If the timeout is triggered then future attempts will be aborted.
61
+ */
62
+ timeout: number;
63
+ onOpen: (data: onOpenParameters) => void;
64
+ onConnect: () => void;
65
+ onMessage: (data: onMessageParameters) => void;
66
+ onOutgoingMessage: (data: onOutgoingMessageParameters) => void;
67
+ onStatus: (data: onStatusParameters) => void;
68
+ onDisconnect: (data: onDisconnectParameters) => void;
69
+ onClose: (data: onCloseParameters) => void;
70
+ onDestroy: () => void;
71
+ onAwarenessUpdate: (data: onAwarenessUpdateParameters) => void;
72
+ onAwarenessChange: (data: onAwarenessChangeParameters) => void;
73
+ /**
74
+ * Don’t output any warnings.
75
+ */
76
+ quiet: boolean;
77
+ }
78
+ export declare class HocuspocusProviderWebsocket extends EventEmitter {
79
+ configuration: CompleteHocuspocusProviderWebsocketConfiguration;
80
+ subscribedToBroadcastChannel: boolean;
81
+ webSocket: WebSocket | null;
82
+ shouldConnect: boolean;
83
+ status: WebSocketStatus;
84
+ lastMessageReceived: number;
85
+ mux: mutex.mutex;
86
+ intervals: any;
87
+ connectionAttempt: {
88
+ resolve: (value?: any) => void;
89
+ reject: (reason?: any) => void;
90
+ } | null;
91
+ constructor(configuration: HocuspocusProviderWebsocketConfiguration);
92
+ receivedOnOpenPayload?: Event | undefined;
93
+ receivedOnStatusPayload?: onStatusParameters | undefined;
94
+ onOpen(event: Event): Promise<void>;
95
+ onStatus(data: onStatusParameters): Promise<void>;
96
+ attach(provider: HocuspocusProvider): void;
97
+ detach(provider: HocuspocusProvider): void;
98
+ setConfiguration(configuration?: Partial<HocuspocusProviderWebsocketConfiguration>): void;
99
+ boundConnect: () => Promise<unknown>;
100
+ cancelWebsocketRetry?: () => void;
101
+ connect(): Promise<unknown>;
102
+ createWebSocketConnection(): Promise<unknown>;
103
+ onMessage(event: MessageEvent): void;
104
+ resolveConnectionAttempt(): void;
105
+ stopConnectionAttempt(): void;
106
+ rejectConnectionAttempt(): void;
107
+ checkConnection(): void;
108
+ registerEventListeners(): void;
109
+ get serverUrl(): string;
110
+ get url(): string;
111
+ disconnect(): void;
112
+ send(message: any): void;
113
+ onClose({ event }: onCloseParameters): void;
114
+ destroy(): void;
115
+ }
@@ -7,8 +7,10 @@ export declare class IncomingMessage {
7
7
  decoder: Decoder;
8
8
  constructor(data: any);
9
9
  readVarUint(): MessageType;
10
+ readVarString(): string;
10
11
  readVarUint8Array(): Uint8Array;
11
12
  writeVarUint(type: MessageType): void;
13
+ writeVarString(string: string): void;
12
14
  writeVarUint8Array(data: Uint8Array): void;
13
15
  length(): number;
14
16
  }
@@ -1,3 +1,4 @@
1
1
  export * from './HocuspocusProvider';
2
2
  export * from './HocuspocusCloudProvider';
3
+ export * from './HocuspocusProviderWebsocket';
3
4
  export * from './types';
@@ -27,6 +27,7 @@ export interface OutgoingMessageInterface {
27
27
  type?: MessageType;
28
28
  }
29
29
  export interface OutgoingMessageArguments {
30
+ documentName: string;
30
31
  token: string;
31
32
  document: Y.Doc;
32
33
  awareness: Awareness;
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
+ import { IncomingMessage as HTTPIncomingMessage } from 'http';
2
3
  import AsyncLock from 'async-lock';
3
4
  import WebSocket from 'ws';
4
- import { IncomingMessage as HTTPIncomingMessage } from 'http';
5
5
  import { CloseEvent } from '@hocuspocus/common';
6
6
  import Document from './Document';
7
7
  import { Debugger } from './Debugger';
@@ -62,15 +62,5 @@ export declare class Connection {
62
62
  * @private
63
63
  */
64
64
  private handleMessage;
65
- /**
66
- * Get the underlying connection instance
67
- * @deprecated
68
- */
69
- get instance(): WebSocket;
70
- /**
71
- * Get the underlying connection instance
72
- * @deprecated
73
- */
74
- get connection(): WebSocket;
75
65
  }
76
66
  export default Connection;
@@ -1,10 +1,9 @@
1
1
  /// <reference types="node" />
2
- import WebSocket, { AddressInfo, WebSocketServer } from 'ws';
3
2
  import { IncomingMessage, Server as HTTPServer } from 'http';
4
- import { Configuration, HookName, HookPayload } from './types';
3
+ import WebSocket, { AddressInfo, WebSocketServer } from 'ws';
4
+ import { Configuration, HookName, HookPayload, onListenPayload } from './types';
5
5
  import Document from './Document';
6
6
  import { Debugger } from './Debugger';
7
- import { onListenPayload } from '.';
8
7
  export declare const defaultConfiguration: {
9
8
  name: null;
10
9
  port: number;
@@ -68,7 +67,7 @@ export declare class Hocuspocus {
68
67
  * … and if nothings fails it’ll fully establish the connection and
69
68
  * load the Document then.
70
69
  */
71
- handleConnection(incoming: WebSocket, request: IncomingMessage, documentName: string, context?: any): void;
70
+ handleConnection(incoming: WebSocket, request: IncomingMessage, context?: any): void;
72
71
  /**
73
72
  * Handle update of the given document
74
73
  */
@@ -98,10 +97,6 @@ export declare class Hocuspocus {
98
97
  * Get parameters by the given request
99
98
  */
100
99
  private static getParameters;
101
- /**
102
- * Get document name by the given request
103
- */
104
- private getDocumentNameFromRequest;
105
100
  enableDebugging(): void;
106
101
  enableMessageLogging(): void;
107
102
  disableLogging(): void;
@@ -16,5 +16,6 @@ export declare class IncomingMessage {
16
16
  readVarString(): string;
17
17
  toUint8Array(): Uint8Array;
18
18
  writeVarUint(type: MessageType): void;
19
+ writeVarString(string: string): void;
19
20
  get length(): number;
20
21
  }
@@ -1,4 +1,3 @@
1
- import { Awareness } from 'y-protocols/awareness';
2
1
  import Connection from './Connection';
3
2
  import { IncomingMessage } from './IncomingMessage';
4
3
  import { Debugger } from './Debugger';
@@ -9,5 +8,5 @@ export declare class MessageReceiver {
9
8
  constructor(message: IncomingMessage, logger: Debugger);
10
9
  apply(document: Document, connection?: Connection, reply?: (message: Uint8Array) => void): void;
11
10
  readSyncMessage(message: IncomingMessage, document: Document, connection?: Connection, reply?: (message: Uint8Array) => void, requestFirstSync?: boolean): 0 | 2 | 1;
12
- applyQueryAwarenessMessage(awareness: Awareness, reply?: (message: Uint8Array) => void): void;
11
+ applyQueryAwarenessMessage(document: Document, reply?: (message: Uint8Array) => void): void;
13
12
  }
@@ -5,7 +5,7 @@ export declare class OutgoingMessage {
5
5
  encoder: Encoder;
6
6
  type?: number;
7
7
  category?: string;
8
- constructor();
8
+ constructor(documentName: string);
9
9
  createSyncMessage(): OutgoingMessage;
10
10
  createSyncReplyMessage(): OutgoingMessage;
11
11
  createAwarenessUpdateMessage(awareness: Awareness, changedClients?: Array<any>): OutgoingMessage;
@@ -2,6 +2,7 @@ export * from './createDirectory';
2
2
  export * from './flushRedis';
3
3
  export * from './newHocuspocus';
4
4
  export * from './newHocuspocusProvider';
5
+ export * from './newHocuspocusProviderWebsocket';
5
6
  export * from './randomInteger';
6
7
  export * from './redisConnectionSettings';
7
8
  export * from './removeDirectory';
@@ -1,3 +1,3 @@
1
- import { HocuspocusProvider, HocuspocusProviderConfiguration } from '@hocuspocus/provider';
1
+ import { HocuspocusProvider, HocuspocusProviderConfiguration, HocuspocusProviderWebsocketConfiguration } from '@hocuspocus/provider';
2
2
  import { Hocuspocus } from '@hocuspocus/server';
3
- export declare const newHocuspocusProvider: (server: Hocuspocus, options?: Partial<Omit<HocuspocusProviderConfiguration, 'url'>>) => HocuspocusProvider;
3
+ export declare const newHocuspocusProvider: (server: Hocuspocus, options?: Partial<HocuspocusProviderConfiguration>, websocketOptions?: Partial<HocuspocusProviderWebsocketConfiguration>) => HocuspocusProvider;
@@ -0,0 +1,3 @@
1
+ import { HocuspocusProviderWebsocket, HocuspocusProviderWebsocketConfiguration } from '@hocuspocus/provider';
2
+ import { Hocuspocus } from '@hocuspocus/server';
3
+ export declare const newHocuspocusProviderWebsocket: (server: Hocuspocus, options?: Partial<Omit<HocuspocusProviderWebsocketConfiguration, 'url'>>) => HocuspocusProviderWebsocket;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hocuspocus/extension-throttle",
3
- "version": "1.1.0",
3
+ "version": "2.0.0-alpha.0",
4
4
  "description": "hocuspocus throttle extension",
5
5
  "homepage": "https://hocuspocus.dev",
6
6
  "keywords": [
@@ -27,7 +27,7 @@
27
27
  "dist"
28
28
  ],
29
29
  "dependencies": {
30
- "@hocuspocus/server": "^1.1.0"
30
+ "@hocuspocus/server": "^2.0.0-alpha.0"
31
31
  },
32
32
  "gitHead": "b3454a4ca289a84ddfb7fa5607a2d4b8d5c37e9d"
33
33
  }
@@ -1 +0,0 @@
1
- export {};