@hocuspocus/extension-database 3.0.0-rc.0 → 3.0.4-rc.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.
Files changed (32) hide show
  1. package/dist/hocuspocus-database.cjs +17 -10603
  2. package/dist/hocuspocus-database.cjs.map +1 -1
  3. package/dist/hocuspocus-database.esm.js +3 -10608
  4. package/dist/hocuspocus-database.esm.js.map +1 -1
  5. package/dist/packages/common/src/auth.d.ts +1 -1
  6. package/dist/packages/extension-redis/src/Redis.d.ts +8 -2
  7. package/dist/packages/extension-throttle/src/index.d.ts +1 -0
  8. package/dist/packages/extension-webhook/src/index.d.ts +1 -0
  9. package/dist/packages/provider/src/HocuspocusProvider.d.ts +11 -33
  10. package/dist/packages/provider/src/HocuspocusProviderWebsocket.d.ts +0 -4
  11. package/dist/packages/provider/src/MessageReceiver.d.ts +0 -2
  12. package/dist/packages/provider/src/index.d.ts +0 -2
  13. package/dist/packages/provider/src/types.d.ts +42 -2
  14. package/dist/packages/server/src/ClientConnection.d.ts +15 -5
  15. package/dist/packages/server/src/Connection.d.ts +3 -17
  16. package/dist/packages/server/src/DirectConnection.d.ts +1 -1
  17. package/dist/packages/server/src/Document.d.ts +1 -5
  18. package/dist/packages/server/src/Hocuspocus.d.ts +3 -11
  19. package/dist/packages/server/src/MessageReceiver.d.ts +1 -3
  20. package/dist/packages/server/src/OutgoingMessage.d.ts +1 -0
  21. package/dist/packages/server/src/Server.d.ts +3 -2
  22. package/dist/packages/server/src/index.d.ts +0 -1
  23. package/dist/packages/server/src/types.d.ts +20 -11
  24. package/dist/packages/server/src/util/getParameters.d.ts +2 -0
  25. package/dist/tests/utils/newHocuspocusProvider.d.ts +2 -2
  26. package/dist/tests/utils/newHocuspocusProviderWebsocket.d.ts +1 -1
  27. package/package.json +2 -2
  28. package/dist/packages/provider/src/TiptapCollabProvider.d.ts +0 -64
  29. package/dist/packages/provider/src/TiptapCollabProviderWebsocket.d.ts +0 -20
  30. package/dist/packages/server/src/Debugger.d.ts +0 -14
  31. package/dist/tests/server/getMessageLogs.d.ts +0 -1
  32. package/dist/tests/server/requiresAuthentication.d.ts +0 -1
@@ -2,5 +2,5 @@ import * as encoding from 'lib0/encoding';
2
2
  import * as decoding from 'lib0/decoding';
3
3
  export declare const writeAuthentication: (encoder: encoding.Encoder, auth: string) => void;
4
4
  export declare const writePermissionDenied: (encoder: encoding.Encoder, reason: string) => void;
5
- export declare const writeAuthenticated: (encoder: encoding.Encoder, scope: "readonly" | "read-write") => void;
5
+ export declare const writeAuthenticated: (encoder: encoding.Encoder, scope: 'readonly' | 'read-write') => void;
6
6
  export declare const readAuthMessage: (decoder: decoding.Decoder, permissionDeniedHandler: (reason: string) => void, authenticatedHandler: (scope: string) => void) => void;
@@ -1,8 +1,9 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
1
3
  import type { ClusterNode, ClusterOptions, RedisOptions } from 'ioredis';
2
4
  import RedisClient from 'ioredis';
3
5
  import Redlock from 'redlock';
4
6
  import type { Extension, afterLoadDocumentPayload, afterStoreDocumentPayload, onDisconnectPayload, onStoreDocumentPayload, onAwarenessUpdatePayload, onChangePayload, onConfigurePayload, beforeBroadcastStatelessPayload, Hocuspocus } from '@hocuspocus/server';
5
- import { Debugger } from '@hocuspocus/server';
6
7
  export type RedisInstance = RedisClient.Cluster | RedisClient.Redis;
7
8
  export interface Configuration {
8
9
  /**
@@ -64,8 +65,13 @@ export declare class Redis implements Extension {
64
65
  instance: Hocuspocus;
65
66
  redlock: Redlock;
66
67
  locks: Map<string, Redlock.Lock>;
67
- logger: Debugger;
68
68
  messagePrefix: Buffer;
69
+ /**
70
+ * When we have a high frequency of updates to a document we don't need tons of setTimeouts
71
+ * piling up, so we'll track them to keep it to the most recent per document.
72
+ */
73
+ private pendingDisconnects;
74
+ private pendingAfterStoreDocumentResolves;
69
75
  constructor(configuration: Partial<Configuration>);
70
76
  onConfigure({ instance }: onConfigurePayload): Promise<void>;
71
77
  private getKey;
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import type { Extension, onConnectPayload } from '@hocuspocus/server';
2
3
  export interface ThrottleConfiguration {
3
4
  throttle: number | null | false;
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import type { Extension, onChangePayload, onConnectPayload, onLoadDocumentPayload, onDisconnectPayload } from '@hocuspocus/server';
2
3
  import type { Doc } from 'yjs';
3
4
  import type { Transformer } from '@hocuspocus/transformer';
@@ -1,11 +1,10 @@
1
- import * as mutex from 'lib0/mutex';
2
- import type { CloseEvent, Event, MessageEvent } from 'ws';
1
+ import type { Event, MessageEvent } from 'ws';
3
2
  import { Awareness } from 'y-protocols/awareness';
4
3
  import * as Y from 'yjs';
5
4
  import EventEmitter from './EventEmitter.js';
6
5
  import type { CompleteHocuspocusProviderWebsocketConfiguration } from './HocuspocusProviderWebsocket.js';
7
6
  import { HocuspocusProviderWebsocket } from './HocuspocusProviderWebsocket.js';
8
- import type { ConstructableOutgoingMessage, onAuthenticationFailedParameters, onAwarenessChangeParameters, onAwarenessUpdateParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatelessParameters, onStatusParameters, onSyncedParameters } from './types.js';
7
+ import type { ConstructableOutgoingMessage, onAuthenticationFailedParameters, onAwarenessChangeParameters, onAwarenessUpdateParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatelessParameters, onSyncedParameters } from './types.js';
9
8
  export type HocuspocusProviderConfiguration = Required<Pick<CompleteHocuspocusProviderConfiguration, 'name'>> & Partial<CompleteHocuspocusProviderConfiguration> & (Required<Pick<CompleteHocuspocusProviderWebsocketConfiguration, 'url'>> | Required<Pick<CompleteHocuspocusProviderConfiguration, 'websocketProvider'>>);
10
9
  export interface CompleteHocuspocusProviderConfiguration {
11
10
  /**
@@ -16,10 +15,6 @@ export interface CompleteHocuspocusProviderConfiguration {
16
15
  * The actual Y.js document
17
16
  */
18
17
  document: Y.Doc;
19
- /**
20
- * Pass false to disable broadcasting between browser tabs.
21
- */
22
- broadcast: boolean;
23
18
  /**
24
19
  * An Awareness instance to keep the presence state of all clients.
25
20
  *
@@ -33,12 +28,6 @@ export interface CompleteHocuspocusProviderConfiguration {
33
28
  * A token that’s sent to the backend for authentication purposes.
34
29
  */
35
30
  token: string | (() => string) | (() => Promise<string>) | null;
36
- /**
37
- * URL parameters that should be added.
38
- */
39
- parameters: {
40
- [key: string]: any;
41
- };
42
31
  /**
43
32
  * Hocuspocus websocket provider
44
33
  */
@@ -53,7 +42,6 @@ export interface CompleteHocuspocusProviderConfiguration {
53
42
  onConnect: () => void;
54
43
  onMessage: (data: onMessageParameters) => void;
55
44
  onOutgoingMessage: (data: onOutgoingMessageParameters) => void;
56
- onStatus: (data: onStatusParameters) => void;
57
45
  onSynced: (data: onSyncedParameters) => void;
58
46
  onDisconnect: (data: onDisconnectParameters) => void;
59
47
  onClose: (data: onCloseParameters) => void;
@@ -61,37 +49,26 @@ export interface CompleteHocuspocusProviderConfiguration {
61
49
  onAwarenessUpdate: (data: onAwarenessUpdateParameters) => void;
62
50
  onAwarenessChange: (data: onAwarenessChangeParameters) => void;
63
51
  onStateless: (data: onStatelessParameters) => void;
64
- /**
65
- * Don’t output any warnings.
66
- */
67
- quiet: boolean;
68
- /**
69
- * Pass `false` to start the connection manually.
70
- */
71
- connect: boolean;
72
- /**
73
- * Pass `false` to close the connection manually.
74
- */
75
- preserveConnection: boolean;
76
52
  }
77
53
  export declare class AwarenessError extends Error {
78
54
  code: number;
79
55
  }
80
56
  export declare class HocuspocusProvider extends EventEmitter {
81
57
  configuration: CompleteHocuspocusProviderConfiguration;
82
- subscribedToBroadcastChannel: boolean;
83
58
  isSynced: boolean;
84
59
  unsyncedChanges: number;
85
60
  isAuthenticated: boolean;
86
61
  authorizedScope: string | undefined;
87
- mux: mutex.mutex;
62
+ manageSocket: boolean;
63
+ private isAttached;
88
64
  intervals: any;
89
65
  constructor(configuration: HocuspocusProviderConfiguration);
66
+ boundDocumentUpdateHandler: (update: Uint8Array, origin: any) => void;
67
+ boundAwarenessUpdateHandler: ({ added, updated, removed }: any, origin: any) => void;
90
68
  boundPageHide: () => void;
91
69
  boundOnOpen: (event: Event) => Promise<void>;
92
- boundOnClose: (event: CloseEvent) => void;
70
+ boundOnClose: () => void;
93
71
  forwardConnect: (e: any) => this;
94
- forwardOpen: (e: any) => this;
95
72
  forwardClose: (e: any) => this;
96
73
  forwardDisconnect: (e: any) => this;
97
74
  forwardDestroy: (e: any) => this;
@@ -117,16 +94,17 @@ export declare class HocuspocusProvider extends EventEmitter {
117
94
  get synced(): boolean;
118
95
  set synced(state: boolean);
119
96
  receiveStateless(payload: string): void;
120
- get isAuthenticationRequired(): boolean;
121
97
  connect(): Promise<void>;
122
98
  disconnect(): void;
123
99
  onOpen(event: Event): Promise<void>;
124
100
  getToken(): Promise<string | null>;
125
101
  startSync(): void;
126
- send(message: ConstructableOutgoingMessage, args: any, broadcast?: boolean): void;
102
+ send(message: ConstructableOutgoingMessage, args: any): void;
127
103
  onMessage(event: MessageEvent): void;
128
- onClose(event: CloseEvent): void;
104
+ onClose(): void;
129
105
  destroy(): void;
106
+ detach(): void;
107
+ attach(): void;
130
108
  permissionDeniedHandler(reason: string): void;
131
109
  authenticatedHandler(scope: string): void;
132
110
  setAwarenessField(key: string, value: any): void;
@@ -72,10 +72,6 @@ export interface CompleteHocuspocusProviderWebsocketConfiguration {
72
72
  onDestroy: () => void;
73
73
  onAwarenessUpdate: (data: onAwarenessUpdateParameters) => void;
74
74
  onAwarenessChange: (data: onAwarenessChangeParameters) => void;
75
- /**
76
- * Don’t output any warnings.
77
- */
78
- quiet: boolean;
79
75
  /**
80
76
  * Map of attached providers keyed by documentName.
81
77
  */
@@ -2,9 +2,7 @@ import type { HocuspocusProvider } from './HocuspocusProvider.js';
2
2
  import type { IncomingMessage } from './IncomingMessage.js';
3
3
  export declare class MessageReceiver {
4
4
  message: IncomingMessage;
5
- broadcasted: boolean;
6
5
  constructor(message: IncomingMessage);
7
- setBroadcasted(value: boolean): this;
8
6
  apply(provider: HocuspocusProvider, emitSynced: boolean): void;
9
7
  private applySyncMessage;
10
8
  applySyncStatusMessage(provider: HocuspocusProvider, applied: boolean): void;
@@ -1,5 +1,3 @@
1
1
  export * from './HocuspocusProvider.js';
2
- export * from './TiptapCollabProvider.js';
3
- export * from './TiptapCollabProviderWebsocket.js';
4
2
  export * from './HocuspocusProviderWebsocket.js';
5
3
  export * from './types.js';
@@ -88,14 +88,17 @@ export type TCollabThread<Data = any, CommentData = any> = {
88
88
  id: string;
89
89
  createdAt: number;
90
90
  updatedAt: number;
91
+ deletedAt: number | null;
91
92
  resolvedAt?: string;
92
93
  comments: TCollabComment<CommentData>[];
94
+ deletedComments: TCollabComment<CommentData>[];
93
95
  data: Data;
94
96
  };
95
97
  export type TCollabComment<Data = any> = {
96
98
  id: string;
97
- createdAt: number;
98
- updatedAt: number;
99
+ createdAt: string;
100
+ updatedAt: string;
101
+ deletedAt?: string;
99
102
  data: Data;
100
103
  content: any;
101
104
  };
@@ -144,3 +147,40 @@ export type THistoryDocumentRevertedEvent = {
144
147
  event: 'document.reverted';
145
148
  version: number;
146
149
  };
150
+ export type DeleteCommentOptions = {
151
+ /**
152
+ * If `true`, the thread will also be deleted if the deleted comment was the first comment in the thread.
153
+ */
154
+ deleteThread?: boolean;
155
+ /**
156
+ * If `true`, will remove the content of the deleted comment
157
+ */
158
+ deleteContent?: boolean;
159
+ };
160
+ export type DeleteThreadOptions = {
161
+ /**
162
+ * If `true`, will remove the comments on the thread,
163
+ * otherwise will only mark the thread as deleted
164
+ * and keep the comments
165
+ * @default false
166
+ */
167
+ deleteComments?: boolean;
168
+ /**
169
+ * If `true`, will forcefully remove the thread and all comments,
170
+ * otherwise will only mark the thread as deleted
171
+ * and keep the comments
172
+ * @default false
173
+ */
174
+ force?: boolean;
175
+ };
176
+ /**
177
+ * The type of thread
178
+ */
179
+ export type ThreadType = 'archived' | 'unarchived';
180
+ export type GetThreadsOptions = {
181
+ /**
182
+ * The types of threads to get
183
+ * @default ['unarchived']
184
+ */
185
+ types?: Array<ThreadType>;
186
+ };
@@ -1,6 +1,8 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
1
3
  import type { IncomingMessage } from 'http';
4
+ import { type CloseEvent } from '@hocuspocus/common';
2
5
  import type WebSocket from 'ws';
3
- import type { Debugger } from './Debugger.js';
4
6
  import type Document from './Document.js';
5
7
  import type { Hocuspocus } from './Hocuspocus.js';
6
8
  import type { onDisconnectPayload } from './types.js';
@@ -15,7 +17,6 @@ export declare class ClientConnection {
15
17
  private readonly request;
16
18
  private readonly documentProvider;
17
19
  private readonly hooks;
18
- private readonly debuggerTool;
19
20
  private readonly opts;
20
21
  private readonly defaultContext;
21
22
  private readonly documentConnections;
@@ -23,8 +24,10 @@ export declare class ClientConnection {
23
24
  private readonly documentConnectionsEstablished;
24
25
  private readonly hookPayloads;
25
26
  private readonly callbacks;
26
- private readonly closeIdleConnectionTimeout;
27
27
  private readonly socketId;
28
+ timeout: number;
29
+ pingInterval: NodeJS.Timeout;
30
+ pongReceived: boolean;
28
31
  /**
29
32
  * The `ClientConnection` class receives incoming WebSocket connections,
30
33
  * runs all hooks:
@@ -37,10 +40,17 @@ export declare class ClientConnection {
37
40
  */
38
41
  constructor(websocket: WebSocket, request: IncomingMessage, documentProvider: {
39
42
  createDocument: Hocuspocus['createDocument'];
40
- }, hooks: Hocuspocus['hooks'], debuggerTool: Debugger, opts: {
41
- requiresAuthentication: boolean;
43
+ }, hooks: Hocuspocus['hooks'], opts: {
42
44
  timeout: number;
43
45
  }, defaultContext?: any);
46
+ private handleWebsocketClose;
47
+ close(event?: CloseEvent): void;
48
+ handlePong: () => void;
49
+ /**
50
+ * Check if pong was received and close the connection otherwise
51
+ * @private
52
+ */
53
+ private check;
44
54
  /**
45
55
  * Set a callback that will be triggered when the connection is closed
46
56
  */
@@ -1,30 +1,21 @@
1
+ /// <reference types="node" />
1
2
  import type { IncomingMessage as HTTPIncomingMessage } from 'http';
2
- import AsyncLock from 'async-lock';
3
3
  import type WebSocket from 'ws';
4
- import type { CloseEvent } from '@hocuspocus/common';
4
+ import { type CloseEvent } from '@hocuspocus/common';
5
5
  import type Document from './Document.js';
6
- import type { Debugger } from './Debugger.js';
7
6
  import type { onStatelessPayload } from './types.js';
8
7
  export declare class Connection {
9
8
  webSocket: WebSocket;
10
9
  context: any;
11
10
  document: Document;
12
- pingInterval: NodeJS.Timeout;
13
- pongReceived: boolean;
14
11
  request: HTTPIncomingMessage;
15
- timeout: number;
16
12
  callbacks: any;
17
13
  socketId: string;
18
- lock: AsyncLock;
19
14
  readOnly: boolean;
20
- logger: Debugger;
21
15
  /**
22
16
  * Constructor.
23
17
  */
24
- constructor(connection: WebSocket, request: HTTPIncomingMessage, document: Document, timeout: number, socketId: string, context: any, readOnly: boolean | undefined, logger: Debugger);
25
- boundClose: (event?: CloseEvent) => void;
26
- boundHandlePong: () => void;
27
- handlePong(): void;
18
+ constructor(connection: WebSocket, request: HTTPIncomingMessage, document: Document, socketId: string, context: any, readOnly?: boolean);
28
19
  /**
29
20
  * Set a callback that will be triggered when the connection is closed
30
21
  */
@@ -49,11 +40,6 @@ export declare class Connection {
49
40
  * Graceful wrapper around the WebSocket close method.
50
41
  */
51
42
  close(event?: CloseEvent): void;
52
- /**
53
- * Check if pong was received and close the connection otherwise
54
- * @private
55
- */
56
- private check;
57
43
  /**
58
44
  * Send the current document awareness to the client, if any
59
45
  * @private
@@ -9,6 +9,6 @@ export declare class DirectConnection implements DirectConnectionInterface {
9
9
  * Constructor.
10
10
  */
11
11
  constructor(document: Document, instance: Hocuspocus, context?: any);
12
- transact(transaction: (document: Document) => void, transactionOrigin?: any): Promise<void>;
12
+ transact(transaction: (document: Document) => void): Promise<void>;
13
13
  disconnect(): Promise<void>;
14
14
  }
@@ -1,9 +1,7 @@
1
1
  import type WebSocket from 'ws';
2
2
  import { Awareness } from 'y-protocols/awareness';
3
3
  import { Doc } from 'yjs';
4
- import type { mutex } from 'lib0/mutex.js';
5
4
  import type Connection from './Connection.js';
6
- import type { Debugger } from './Debugger.js';
7
5
  export declare class Document extends Doc {
8
6
  awareness: Awareness;
9
7
  callbacks: {
@@ -16,14 +14,12 @@ export declare class Document extends Doc {
16
14
  }>;
17
15
  directConnectionsCount: number;
18
16
  name: string;
19
- mux: mutex;
20
- logger?: Debugger;
21
17
  isLoading: boolean;
22
18
  isDestroyed: boolean;
23
19
  /**
24
20
  * Constructor.
25
21
  */
26
- constructor(name: string, logger?: Debugger, yDocOptions?: object);
22
+ constructor(name: string, yDocOptions?: object);
27
23
  /**
28
24
  * Check if the Document (XMLFragment or Map) is empty
29
25
  */
@@ -1,7 +1,7 @@
1
+ /// <reference types="node" />
1
2
  import type { IncomingMessage } from 'http';
2
3
  import type WebSocket from 'ws';
3
4
  import type { Server } from './Server.js';
4
- import { Debugger } from './Debugger.js';
5
5
  import { DirectConnection } from './DirectConnection.js';
6
6
  import Document from './Document.js';
7
7
  import type { Configuration, ConnectionConfiguration, HookName, HookPayloadByName, onStoreDocumentPayload } from './types.js';
@@ -22,7 +22,6 @@ export declare class Hocuspocus {
22
22
  loadingDocuments: Map<string, Promise<Document>>;
23
23
  documents: Map<string, Document>;
24
24
  server?: Server;
25
- debugger: Debugger;
26
25
  debouncer: {
27
26
  debounce: (id: string, func: Function, debounce: number, maxDebounce: number) => any;
28
27
  isDebounced: (id: string) => boolean;
@@ -33,7 +32,6 @@ export declare class Hocuspocus {
33
32
  * Configure Hocuspocus
34
33
  */
35
34
  configure(configuration: Partial<Configuration>): Hocuspocus;
36
- get requiresAuthentication(): boolean;
37
35
  /**
38
36
  * Get the total number of active documents
39
37
  */
@@ -68,19 +66,13 @@ export declare class Hocuspocus {
68
66
  * Create a new document by the given request
69
67
  */
70
68
  createDocument(documentName: string, request: Partial<Pick<IncomingMessage, 'headers' | 'url'>>, socketId: string, connection: ConnectionConfiguration, context?: any): Promise<Document>;
71
- loadDocument(documentName: string, request: Partial<Pick<IncomingMessage, 'headers' | 'url'>>, socketId: string, connection: ConnectionConfiguration, context?: any): Promise<Document>;
69
+ loadDocument(documentName: string, request: Partial<Pick<IncomingMessage, 'headers' | 'url'>>, socketId: string, connectionConfig: ConnectionConfiguration, context?: any): Promise<Document>;
72
70
  storeDocumentHooks(document: Document, hookPayload: onStoreDocumentPayload, immediately?: boolean): any;
73
71
  /**
74
72
  * Run the given hook on all configured extensions.
75
73
  * Runs the given callback after each hook.
76
74
  */
77
75
  hooks<T extends HookName>(name: T, payload: HookPayloadByName[T], callback?: Function | null): Promise<any>;
78
- unloadDocument(document: Document): void;
79
- enableDebugging(): void;
80
- enableMessageLogging(): void;
81
- disableLogging(): void;
82
- disableDebugging(): void;
83
- flushMessageLogs(): this;
84
- getMessageLogs(): any[];
76
+ unloadDocument(document: Document): Promise<any>;
85
77
  openDirectConnection(documentName: string, context?: any): Promise<DirectConnection>;
86
78
  }
@@ -1,12 +1,10 @@
1
1
  import type Connection from './Connection.js';
2
- import type { Debugger } from './Debugger.js';
3
2
  import type Document from './Document.js';
4
3
  import type { IncomingMessage } from './IncomingMessage.js';
5
4
  export declare class MessageReceiver {
6
5
  message: IncomingMessage;
7
- logger: Debugger;
8
6
  defaultTransactionOrigin?: string;
9
- constructor(message: IncomingMessage, logger: Debugger, defaultTransactionOrigin?: string);
7
+ constructor(message: IncomingMessage, defaultTransactionOrigin?: string);
10
8
  apply(document: Document, connection?: Connection, reply?: (message: Uint8Array) => void): void;
11
9
  readSyncMessage(message: IncomingMessage, document: Document, connection?: Connection, reply?: (message: Uint8Array) => void, requestFirstSync?: boolean): 0 | 1 | 2;
12
10
  applyQueryAwarenessMessage(document: Document, reply?: (message: Uint8Array) => void): void;
@@ -17,5 +17,6 @@ export declare class OutgoingMessage {
17
17
  writeStateless(payload: string): OutgoingMessage;
18
18
  writeBroadcastStateless(payload: string): OutgoingMessage;
19
19
  writeSyncStatus(updateSaved: boolean): OutgoingMessage;
20
+ writeCloseMessage(reason: string): OutgoingMessage;
20
21
  toUint8Array(): Uint8Array;
21
22
  }
@@ -1,6 +1,7 @@
1
+ /// <reference types="node" />
1
2
  import type { IncomingMessage, Server as HTTPServer, ServerResponse } from 'http';
2
- import type { AddressInfo } from 'ws';
3
3
  import { WebSocketServer } from 'ws';
4
+ import type { AddressInfo, ServerOptions } from 'ws';
4
5
  import { Hocuspocus } from './Hocuspocus.js';
5
6
  import type { Configuration } from './types';
6
7
  export interface ServerConfiguration extends Configuration {
@@ -18,7 +19,7 @@ export declare class Server {
18
19
  webSocketServer: WebSocketServer;
19
20
  hocuspocus: Hocuspocus;
20
21
  configuration: ServerConfiguration;
21
- constructor(configuration?: Partial<ServerConfiguration>);
22
+ constructor(configuration?: Partial<ServerConfiguration>, websocketOptions?: ServerOptions);
22
23
  setupWebsocketConnection: () => void;
23
24
  setupHttpUpgrade: () => void;
24
25
  requestHandler: (request: IncomingMessage, response: ServerResponse) => Promise<void>;
@@ -1,5 +1,4 @@
1
1
  export * from './Connection.js';
2
- export * from './Debugger.js';
3
2
  export * from './Document.js';
4
3
  export * from './Hocuspocus.js';
5
4
  export * from './IncomingMessage.js';
@@ -1,3 +1,7 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ /// <reference types="node" />
1
5
  import type { IncomingHttpHeaders, IncomingMessage, ServerResponse } from 'http';
2
6
  import type { URLSearchParams } from 'url';
3
7
  import type { Awareness } from 'y-protocols/awareness';
@@ -10,7 +14,7 @@ export declare enum MessageType {
10
14
  Awareness = 1,
11
15
  Auth = 2,
12
16
  QueryAwareness = 3,
13
- SyncReply = 4,// same as Sync, but won't trigger another 'SyncStep1'
17
+ SyncReply = 4,
14
18
  Stateless = 5,
15
19
  BroadcastStateless = 6,
16
20
  CLOSE = 7,
@@ -23,7 +27,6 @@ export interface AwarenessUpdate {
23
27
  }
24
28
  export interface ConnectionConfiguration {
25
29
  readOnly: boolean;
26
- requiresAuthentication: boolean;
27
30
  isAuthenticated: boolean;
28
31
  }
29
32
  export interface Extension {
@@ -47,10 +50,11 @@ export interface Extension {
47
50
  onAwarenessUpdate?(data: onAwarenessUpdatePayload): Promise<any>;
48
51
  onRequest?(data: onRequestPayload): Promise<any>;
49
52
  onDisconnect?(data: onDisconnectPayload): Promise<any>;
53
+ beforeUnloadDocument?(data: beforeUnloadDocumentPayload): Promise<any>;
50
54
  afterUnloadDocument?(data: afterUnloadDocumentPayload): Promise<any>;
51
55
  onDestroy?(data: onDestroyPayload): Promise<any>;
52
56
  }
53
- export type HookName = 'onConfigure' | 'onListen' | 'onUpgrade' | 'onConnect' | 'connected' | 'onAuthenticate' | 'onCreateDocument' | 'onLoadDocument' | 'afterLoadDocument' | 'beforeHandleMessage' | 'beforeBroadcastStateless' | 'onStateless' | 'onChange' | 'onStoreDocument' | 'afterStoreDocument' | 'onAwarenessUpdate' | 'onRequest' | 'onDisconnect' | 'afterUnloadDocument' | 'onDestroy';
57
+ export type HookName = 'onConfigure' | 'onListen' | 'onUpgrade' | 'onConnect' | 'connected' | 'onAuthenticate' | 'onCreateDocument' | 'onLoadDocument' | 'afterLoadDocument' | 'beforeHandleMessage' | 'beforeBroadcastStateless' | 'onStateless' | 'onChange' | 'onStoreDocument' | 'afterStoreDocument' | 'onAwarenessUpdate' | 'onRequest' | 'onDisconnect' | 'beforeUnloadDocument' | 'afterUnloadDocument' | 'onDestroy';
54
58
  export type HookPayloadByName = {
55
59
  onConfigure: onConfigurePayload;
56
60
  onListen: onListenPayload;
@@ -71,6 +75,7 @@ export type HookPayloadByName = {
71
75
  onRequest: onRequestPayload;
72
76
  onDisconnect: onDisconnectPayload;
73
77
  afterUnloadDocument: afterUnloadDocumentPayload;
78
+ beforeUnloadDocument: beforeUnloadDocumentPayload;
74
79
  onDestroy: onDestroyPayload;
75
80
  };
76
81
  export interface Configuration extends Extension {
@@ -130,7 +135,7 @@ export interface onAuthenticatePayload {
130
135
  request: IncomingMessage;
131
136
  socketId: string;
132
137
  token: string;
133
- connection: ConnectionConfiguration;
138
+ connectionConfig: ConnectionConfiguration;
134
139
  }
135
140
  export interface onCreateDocumentPayload {
136
141
  context: any;
@@ -139,7 +144,7 @@ export interface onCreateDocumentPayload {
139
144
  requestHeaders: IncomingHttpHeaders;
140
145
  requestParameters: URLSearchParams;
141
146
  socketId: string;
142
- connection: ConnectionConfiguration;
147
+ connectionConfig: ConnectionConfiguration;
143
148
  }
144
149
  export interface onConnectPayload {
145
150
  context: any;
@@ -149,7 +154,7 @@ export interface onConnectPayload {
149
154
  requestHeaders: IncomingHttpHeaders;
150
155
  requestParameters: URLSearchParams;
151
156
  socketId: string;
152
- connection: ConnectionConfiguration;
157
+ connectionConfig: ConnectionConfiguration;
153
158
  }
154
159
  export interface connectedPayload {
155
160
  context: any;
@@ -159,8 +164,8 @@ export interface connectedPayload {
159
164
  requestHeaders: IncomingHttpHeaders;
160
165
  requestParameters: URLSearchParams;
161
166
  socketId: string;
162
- connection: ConnectionConfiguration;
163
- connectionInstance: Connection;
167
+ connectionConfig: ConnectionConfiguration;
168
+ connection: Connection;
164
169
  }
165
170
  export interface onLoadDocumentPayload {
166
171
  context: any;
@@ -170,7 +175,7 @@ export interface onLoadDocumentPayload {
170
175
  requestHeaders: IncomingHttpHeaders;
171
176
  requestParameters: URLSearchParams;
172
177
  socketId: string;
173
- connection: ConnectionConfiguration;
178
+ connectionConfig: ConnectionConfiguration;
174
179
  }
175
180
  export interface afterLoadDocumentPayload {
176
181
  context: any;
@@ -180,7 +185,7 @@ export interface afterLoadDocumentPayload {
180
185
  requestHeaders: IncomingHttpHeaders;
181
186
  requestParameters: URLSearchParams;
182
187
  socketId: string;
183
- connection: ConnectionConfiguration;
188
+ connectionConfig: ConnectionConfiguration;
184
189
  }
185
190
  export interface onChangePayload {
186
191
  clientsCount: number;
@@ -250,7 +255,7 @@ export interface fetchPayload {
250
255
  requestHeaders: IncomingHttpHeaders;
251
256
  requestParameters: URLSearchParams;
252
257
  socketId: string;
253
- connection: ConnectionConfiguration;
258
+ connectionConfig: ConnectionConfiguration;
254
259
  }
255
260
  export interface storePayload extends onStoreDocumentPayload {
256
261
  state: Buffer;
@@ -293,6 +298,10 @@ export interface afterUnloadDocumentPayload {
293
298
  instance: Hocuspocus;
294
299
  documentName: string;
295
300
  }
301
+ export interface beforeUnloadDocumentPayload {
302
+ instance: Hocuspocus;
303
+ documentName: string;
304
+ }
296
305
  export interface DirectConnection {
297
306
  transact(transaction: (document: Document) => void): Promise<void>;
298
307
  disconnect(): void;
@@ -1,3 +1,5 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
1
3
  import type { IncomingMessage } from 'http';
2
4
  import { URLSearchParams } from 'url';
3
5
  /**
@@ -1,3 +1,3 @@
1
- import { HocuspocusProvider, type HocuspocusProviderConfiguration, type HocuspocusProviderWebsocketConfiguration } from '@hocuspocus/provider';
1
+ import { HocuspocusProvider, type HocuspocusProviderConfiguration, type HocuspocusProviderWebsocket, type HocuspocusProviderWebsocketConfiguration } from '@hocuspocus/provider';
2
2
  import type { Hocuspocus } from '@hocuspocus/server';
3
- export declare const newHocuspocusProvider: (server: Hocuspocus, options?: Partial<HocuspocusProviderConfiguration>, websocketOptions?: Partial<HocuspocusProviderWebsocketConfiguration>) => HocuspocusProvider;
3
+ export declare const newHocuspocusProvider: (server: Hocuspocus, options?: Partial<HocuspocusProviderConfiguration>, websocketOptions?: Partial<HocuspocusProviderWebsocketConfiguration>, websocketProvider?: HocuspocusProviderWebsocket) => HocuspocusProvider;
@@ -1,4 +1,4 @@
1
1
  import type { HocuspocusProviderWebsocketConfiguration } from '@hocuspocus/provider';
2
2
  import { HocuspocusProviderWebsocket } from '@hocuspocus/provider';
3
3
  import type { Hocuspocus } from '@hocuspocus/server';
4
- export declare const newHocuspocusProviderWebsocket: (hocuspocus: Hocuspocus, options?: Partial<Omit<HocuspocusProviderWebsocketConfiguration, "url">>) => HocuspocusProviderWebsocket;
4
+ export declare const newHocuspocusProviderWebsocket: (hocuspocus: Hocuspocus, options?: Partial<Omit<HocuspocusProviderWebsocketConfiguration, 'url'>>) => HocuspocusProviderWebsocket;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hocuspocus/extension-database",
3
3
  "description": "a generic Hocuspocus persistence driver for the database",
4
- "version": "3.0.0-rc.0",
4
+ "version": "3.0.4-rc.0",
5
5
  "homepage": "https://hocuspocus.dev",
6
6
  "keywords": [
7
7
  "hocuspocus",
@@ -27,7 +27,7 @@
27
27
  "dist"
28
28
  ],
29
29
  "dependencies": {
30
- "@hocuspocus/server": "^3.0.0-rc.0"
30
+ "@hocuspocus/server": "^3.0.4-rc.0"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "yjs": "^13.6.8"