@hocuspocus/provider 3.0.4-rc.0 → 3.0.7-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 (67) hide show
  1. package/dist/hocuspocus-provider.cjs +22 -16
  2. package/dist/hocuspocus-provider.cjs.map +1 -1
  3. package/dist/hocuspocus-provider.esm.js +22 -16
  4. package/dist/hocuspocus-provider.esm.js.map +1 -1
  5. package/dist/packages/common/src/auth.d.ts +1 -1
  6. package/dist/packages/common/src/index.d.ts +4 -4
  7. package/dist/packages/extension-database/src/index.d.ts +1 -1
  8. package/dist/packages/extension-logger/src/index.d.ts +1 -1
  9. package/dist/packages/extension-redis/src/Redis.d.ts +0 -2
  10. package/dist/packages/extension-redis/src/index.d.ts +1 -1
  11. package/dist/packages/extension-sqlite/src/index.d.ts +1 -1
  12. package/dist/packages/extension-throttle/src/index.d.ts +0 -1
  13. package/dist/packages/extension-webhook/src/index.d.ts +0 -1
  14. package/dist/packages/provider/src/HocuspocusProvider.d.ts +9 -7
  15. package/dist/packages/provider/src/HocuspocusProviderWebsocket.d.ts +4 -6
  16. package/dist/packages/provider/src/IncomingMessage.d.ts +2 -2
  17. package/dist/packages/provider/src/MessageReceiver.d.ts +2 -2
  18. package/dist/packages/provider/src/MessageSender.d.ts +2 -2
  19. package/dist/packages/provider/src/OutgoingMessage.d.ts +2 -2
  20. package/dist/packages/provider/src/OutgoingMessages/AuthenticationMessage.d.ts +3 -3
  21. package/dist/packages/provider/src/OutgoingMessages/AwarenessMessage.d.ts +3 -3
  22. package/dist/packages/provider/src/OutgoingMessages/CloseMessage.d.ts +3 -3
  23. package/dist/packages/provider/src/OutgoingMessages/QueryAwarenessMessage.d.ts +3 -3
  24. package/dist/packages/provider/src/OutgoingMessages/StatelessMessage.d.ts +3 -3
  25. package/dist/packages/provider/src/OutgoingMessages/SyncStepOneMessage.d.ts +3 -3
  26. package/dist/packages/provider/src/OutgoingMessages/SyncStepTwoMessage.d.ts +3 -3
  27. package/dist/packages/provider/src/OutgoingMessages/UpdateMessage.d.ts +3 -3
  28. package/dist/packages/provider/src/index.d.ts +3 -3
  29. package/dist/packages/provider/src/types.d.ts +14 -108
  30. package/dist/packages/server/src/ClientConnection.d.ts +3 -5
  31. package/dist/packages/server/src/Connection.d.ts +13 -5
  32. package/dist/packages/server/src/DirectConnection.d.ts +3 -3
  33. package/dist/packages/server/src/Document.d.ts +1 -1
  34. package/dist/packages/server/src/Hocuspocus.d.ts +4 -5
  35. package/dist/packages/server/src/IncomingMessage.d.ts +4 -3
  36. package/dist/packages/server/src/MessageReceiver.d.ts +5 -5
  37. package/dist/packages/server/src/OutgoingMessage.d.ts +1 -1
  38. package/dist/packages/server/src/Server.d.ts +1 -2
  39. package/dist/packages/server/src/index.d.ts +9 -9
  40. package/dist/packages/server/src/types.d.ts +28 -9
  41. package/dist/packages/server/src/util/getParameters.d.ts +0 -2
  42. package/dist/packages/transformer/src/Prosemirror.d.ts +1 -1
  43. package/dist/packages/transformer/src/Tiptap.d.ts +1 -1
  44. package/dist/packages/transformer/src/index.d.ts +3 -3
  45. package/dist/playground/frontend/app/SocketContext.d.ts +2 -0
  46. package/dist/playground/frontend/next.config.d.ts +3 -0
  47. package/dist/tests/utils/index.d.ts +9 -9
  48. package/dist/tests/utils/newHocuspocusProviderWebsocket.d.ts +1 -1
  49. package/package.json +3 -3
  50. package/src/HocuspocusProvider.ts +42 -24
  51. package/src/HocuspocusProviderWebsocket.ts +8 -16
  52. package/src/IncomingMessage.ts +1 -1
  53. package/src/MessageReceiver.ts +4 -4
  54. package/src/MessageSender.ts +1 -1
  55. package/src/OutgoingMessage.ts +1 -1
  56. package/src/OutgoingMessages/AuthenticationMessage.ts +3 -3
  57. package/src/OutgoingMessages/AwarenessMessage.ts +3 -3
  58. package/src/OutgoingMessages/CloseMessage.ts +3 -3
  59. package/src/OutgoingMessages/QueryAwarenessMessage.ts +3 -3
  60. package/src/OutgoingMessages/StatelessMessage.ts +3 -3
  61. package/src/OutgoingMessages/SyncStepOneMessage.ts +3 -3
  62. package/src/OutgoingMessages/SyncStepTwoMessage.ts +3 -3
  63. package/src/OutgoingMessages/UpdateMessage.ts +3 -3
  64. package/src/index.ts +3 -3
  65. package/src/types.ts +16 -134
  66. package/dist/playground/frontend/vite.config.d.ts +0 -2
  67. /package/dist/{playground/frontend/src/main.d.ts → tests/server/beforeSync.d.ts} +0 -0
@@ -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,4 +1,4 @@
1
- export * from './auth.js';
2
- export * from './CloseEvents.js';
3
- export * from './awarenessStatesToArray.js';
4
- export * from './types.js';
1
+ export * from './auth.ts';
2
+ export * from './CloseEvents.ts';
3
+ export * from './awarenessStatesToArray.ts';
4
+ export * from './types.ts';
@@ -1 +1 @@
1
- export * from './Database.js';
1
+ export * from './Database.ts';
@@ -1 +1 @@
1
- export * from './Logger.js';
1
+ export * from './Logger.ts';
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import type { ClusterNode, ClusterOptions, RedisOptions } from 'ioredis';
4
2
  import RedisClient from 'ioredis';
5
3
  import Redlock from 'redlock';
@@ -1 +1 @@
1
- export * from './Redis.js';
1
+ export * from './Redis.ts';
@@ -1 +1 @@
1
- export * from './SQLite.js';
1
+ export * from './SQLite.ts';
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import type { Extension, onConnectPayload } from '@hocuspocus/server';
3
2
  export interface ThrottleConfiguration {
4
3
  throttle: number | null | false;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import type { Extension, onChangePayload, onConnectPayload, onLoadDocumentPayload, onDisconnectPayload } from '@hocuspocus/server';
3
2
  import type { Doc } from 'yjs';
4
3
  import type { Transformer } from '@hocuspocus/transformer';
@@ -1,10 +1,10 @@
1
1
  import type { Event, MessageEvent } from 'ws';
2
2
  import { Awareness } from 'y-protocols/awareness';
3
3
  import * as Y from 'yjs';
4
- import EventEmitter from './EventEmitter.js';
5
- import type { CompleteHocuspocusProviderWebsocketConfiguration } from './HocuspocusProviderWebsocket.js';
6
- import { HocuspocusProviderWebsocket } from './HocuspocusProviderWebsocket.js';
7
- import type { ConstructableOutgoingMessage, onAuthenticationFailedParameters, onAwarenessChangeParameters, onAwarenessUpdateParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatelessParameters, onSyncedParameters } from './types.js';
4
+ import EventEmitter from './EventEmitter.ts';
5
+ import type { CompleteHocuspocusProviderWebsocketConfiguration } from './HocuspocusProviderWebsocket.ts';
6
+ import { HocuspocusProviderWebsocket } from './HocuspocusProviderWebsocket.ts';
7
+ import type { ConstructableOutgoingMessage, onAuthenticatedParameters, onAuthenticationFailedParameters, onAwarenessChangeParameters, onAwarenessUpdateParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatelessParameters, onSyncedParameters, onUnsyncedChangesParameters } from './types.ts';
8
8
  export type HocuspocusProviderConfiguration = Required<Pick<CompleteHocuspocusProviderConfiguration, 'name'>> & Partial<CompleteHocuspocusProviderConfiguration> & (Required<Pick<CompleteHocuspocusProviderWebsocketConfiguration, 'url'>> | Required<Pick<CompleteHocuspocusProviderConfiguration, 'websocketProvider'>>);
9
9
  export interface CompleteHocuspocusProviderConfiguration {
10
10
  /**
@@ -36,7 +36,7 @@ export interface CompleteHocuspocusProviderConfiguration {
36
36
  * Force syncing the document in the defined interval.
37
37
  */
38
38
  forceSyncInterval: false | number;
39
- onAuthenticated: () => void;
39
+ onAuthenticated: (data: onAuthenticatedParameters) => void;
40
40
  onAuthenticationFailed: (data: onAuthenticationFailedParameters) => void;
41
41
  onOpen: (data: onOpenParameters) => void;
42
42
  onConnect: () => void;
@@ -49,6 +49,7 @@ export interface CompleteHocuspocusProviderConfiguration {
49
49
  onAwarenessUpdate: (data: onAwarenessUpdateParameters) => void;
50
50
  onAwarenessChange: (data: onAwarenessChangeParameters) => void;
51
51
  onStateless: (data: onStatelessParameters) => void;
52
+ onUnsyncedChanges: (data: onUnsyncedChangesParameters) => void;
52
53
  }
53
54
  export declare class AwarenessError extends Error {
54
55
  code: number;
@@ -60,7 +61,7 @@ export declare class HocuspocusProvider extends EventEmitter {
60
61
  isAuthenticated: boolean;
61
62
  authorizedScope: string | undefined;
62
63
  manageSocket: boolean;
63
- private isAttached;
64
+ private _isAttached;
64
65
  intervals: any;
65
66
  constructor(configuration: HocuspocusProviderConfiguration);
66
67
  boundDocumentUpdateHandler: (update: Uint8Array, origin: any) => void;
@@ -74,6 +75,7 @@ export declare class HocuspocusProvider extends EventEmitter {
74
75
  forwardDestroy: (e: any) => this;
75
76
  setConfiguration(configuration?: Partial<HocuspocusProviderConfiguration>): void;
76
77
  get document(): Y.Doc;
78
+ get isAttached(): boolean;
77
79
  get awareness(): Awareness | null;
78
80
  get hasUnsyncedChanges(): boolean;
79
81
  private resetUnsyncedChanges;
@@ -94,7 +96,7 @@ export declare class HocuspocusProvider extends EventEmitter {
94
96
  get synced(): boolean;
95
97
  set synced(state: boolean);
96
98
  receiveStateless(payload: string): void;
97
- connect(): Promise<void>;
99
+ connect(): Promise<unknown>;
98
100
  disconnect(): void;
99
101
  onOpen(event: Event): Promise<void>;
100
102
  getToken(): Promise<string | null>;
@@ -1,8 +1,8 @@
1
1
  import type { MessageEvent, Event } from 'ws';
2
- import EventEmitter from './EventEmitter.js';
3
- import type { HocuspocusProvider } from './HocuspocusProvider.js';
4
- import type { onAwarenessChangeParameters, onAwarenessUpdateParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatusParameters } from './types.js';
5
- import { WebSocketStatus } from './types.js';
2
+ import EventEmitter from './EventEmitter.ts';
3
+ import type { HocuspocusProvider } from './HocuspocusProvider.ts';
4
+ import type { onAwarenessChangeParameters, onAwarenessUpdateParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatusParameters } from './types.ts';
5
+ import { WebSocketStatus } from './types.ts';
6
6
  export type HocusPocusWebSocket = WebSocket & {
7
7
  identifier: string;
8
8
  };
@@ -95,9 +95,7 @@ export declare class HocuspocusProviderWebsocket extends EventEmitter {
95
95
  } | null;
96
96
  constructor(configuration: HocuspocusProviderWebsocketConfiguration);
97
97
  receivedOnOpenPayload?: Event | undefined;
98
- receivedOnStatusPayload?: onStatusParameters | undefined;
99
98
  onOpen(event: Event): Promise<void>;
100
- onStatus(data: onStatusParameters): Promise<void>;
101
99
  attach(provider: HocuspocusProvider): void;
102
100
  detach(provider: HocuspocusProvider): void;
103
101
  setConfiguration(configuration?: Partial<HocuspocusProviderWebsocketConfiguration>): void;
@@ -1,6 +1,6 @@
1
1
  import type { Decoder } from 'lib0/decoding';
2
2
  import type { Encoder } from 'lib0/encoding';
3
- import type { MessageType } from './types.js';
3
+ import type { MessageType } from './types.ts';
4
4
  export declare class IncomingMessage {
5
5
  data: any;
6
6
  encoder: Encoder;
@@ -9,7 +9,7 @@ export declare class IncomingMessage {
9
9
  peekVarString(): string;
10
10
  readVarUint(): MessageType;
11
11
  readVarString(): string;
12
- readVarUint8Array(): Uint8Array;
12
+ readVarUint8Array(): Uint8Array<ArrayBufferLike>;
13
13
  writeVarUint(type: MessageType): void;
14
14
  writeVarString(string: string): void;
15
15
  writeVarUint8Array(data: Uint8Array): void;
@@ -1,5 +1,5 @@
1
- import type { HocuspocusProvider } from './HocuspocusProvider.js';
2
- import type { IncomingMessage } from './IncomingMessage.js';
1
+ import type { HocuspocusProvider } from './HocuspocusProvider.ts';
2
+ import type { IncomingMessage } from './IncomingMessage.ts';
3
3
  export declare class MessageReceiver {
4
4
  message: IncomingMessage;
5
5
  constructor(message: IncomingMessage);
@@ -1,10 +1,10 @@
1
1
  import type { Encoder } from 'lib0/encoding';
2
- import type { ConstructableOutgoingMessage } from './types.js';
2
+ import type { ConstructableOutgoingMessage } from './types.ts';
3
3
  export declare class MessageSender {
4
4
  encoder: Encoder;
5
5
  message: any;
6
6
  constructor(Message: ConstructableOutgoingMessage, args?: any);
7
- create(): Uint8Array;
7
+ create(): Uint8Array<ArrayBufferLike>;
8
8
  send(webSocket: any): void;
9
9
  broadcast(channel: string): void;
10
10
  }
@@ -1,9 +1,9 @@
1
1
  import type { Encoder } from 'lib0/encoding';
2
- import type { MessageType, OutgoingMessageArguments, OutgoingMessageInterface } from './types.js';
2
+ import type { MessageType, OutgoingMessageArguments, OutgoingMessageInterface } from './types.ts';
3
3
  export declare class OutgoingMessage implements OutgoingMessageInterface {
4
4
  encoder: Encoder;
5
5
  type?: MessageType;
6
6
  constructor();
7
7
  get(args: Partial<OutgoingMessageArguments>): Encoder | undefined;
8
- toUint8Array(): Uint8Array;
8
+ toUint8Array(): Uint8Array<ArrayBufferLike>;
9
9
  }
@@ -1,6 +1,6 @@
1
- import type { OutgoingMessageArguments } from '../types.js';
2
- import { MessageType } from '../types.js';
3
- import { OutgoingMessage } from '../OutgoingMessage.js';
1
+ import type { OutgoingMessageArguments } from '../types.ts';
2
+ import { MessageType } from '../types.ts';
3
+ import { OutgoingMessage } from '../OutgoingMessage.ts';
4
4
  export declare class AuthenticationMessage extends OutgoingMessage {
5
5
  type: MessageType;
6
6
  description: string;
@@ -1,7 +1,7 @@
1
1
  import * as encoding from 'lib0/encoding';
2
- import type { OutgoingMessageArguments } from '../types.js';
3
- import { MessageType } from '../types.js';
4
- import { OutgoingMessage } from '../OutgoingMessage.js';
2
+ import type { OutgoingMessageArguments } from '../types.ts';
3
+ import { MessageType } from '../types.ts';
4
+ import { OutgoingMessage } from '../OutgoingMessage.ts';
5
5
  export declare class AwarenessMessage extends OutgoingMessage {
6
6
  type: MessageType;
7
7
  description: string;
@@ -1,7 +1,7 @@
1
1
  import * as encoding from 'lib0/encoding';
2
- import type { OutgoingMessageArguments } from '../types.js';
3
- import { MessageType } from '../types.js';
4
- import { OutgoingMessage } from '../OutgoingMessage.js';
2
+ import type { OutgoingMessageArguments } from '../types.ts';
3
+ import { MessageType } from '../types.ts';
4
+ import { OutgoingMessage } from '../OutgoingMessage.ts';
5
5
  export declare class CloseMessage extends OutgoingMessage {
6
6
  type: MessageType;
7
7
  description: string;
@@ -1,7 +1,7 @@
1
1
  import * as encoding from 'lib0/encoding';
2
- import type { OutgoingMessageArguments } from '../types.js';
3
- import { MessageType } from '../types.js';
4
- import { OutgoingMessage } from '../OutgoingMessage.js';
2
+ import type { OutgoingMessageArguments } from '../types.ts';
3
+ import { MessageType } from '../types.ts';
4
+ import { OutgoingMessage } from '../OutgoingMessage.ts';
5
5
  export declare class QueryAwarenessMessage extends OutgoingMessage {
6
6
  type: MessageType;
7
7
  description: string;
@@ -1,6 +1,6 @@
1
- import type { OutgoingMessageArguments } from '../types.js';
2
- import { MessageType } from '../types.js';
3
- import { OutgoingMessage } from '../OutgoingMessage.js';
1
+ import type { OutgoingMessageArguments } from '../types.ts';
2
+ import { MessageType } from '../types.ts';
3
+ import { OutgoingMessage } from '../OutgoingMessage.ts';
4
4
  export declare class StatelessMessage extends OutgoingMessage {
5
5
  type: MessageType;
6
6
  description: string;
@@ -1,7 +1,7 @@
1
1
  import * as encoding from 'lib0/encoding';
2
- import type { OutgoingMessageArguments } from '../types.js';
3
- import { MessageType } from '../types.js';
4
- import { OutgoingMessage } from '../OutgoingMessage.js';
2
+ import type { OutgoingMessageArguments } from '../types.ts';
3
+ import { MessageType } from '../types.ts';
4
+ import { OutgoingMessage } from '../OutgoingMessage.ts';
5
5
  export declare class SyncStepOneMessage extends OutgoingMessage {
6
6
  type: MessageType;
7
7
  description: string;
@@ -1,7 +1,7 @@
1
1
  import * as encoding from 'lib0/encoding';
2
- import type { OutgoingMessageArguments } from '../types.js';
3
- import { MessageType } from '../types.js';
4
- import { OutgoingMessage } from '../OutgoingMessage.js';
2
+ import type { OutgoingMessageArguments } from '../types.ts';
3
+ import { MessageType } from '../types.ts';
4
+ import { OutgoingMessage } from '../OutgoingMessage.ts';
5
5
  export declare class SyncStepTwoMessage extends OutgoingMessage {
6
6
  type: MessageType;
7
7
  description: string;
@@ -1,6 +1,6 @@
1
- import type { OutgoingMessageArguments } from '../types.js';
2
- import { MessageType } from '../types.js';
3
- import { OutgoingMessage } from '../OutgoingMessage.js';
1
+ import type { OutgoingMessageArguments } from '../types.ts';
2
+ import { MessageType } from '../types.ts';
3
+ import { OutgoingMessage } from '../OutgoingMessage.ts';
4
4
  export declare class UpdateMessage extends OutgoingMessage {
5
5
  type: MessageType;
6
6
  description: string;
@@ -1,3 +1,3 @@
1
- export * from './HocuspocusProvider.js';
2
- export * from './HocuspocusProviderWebsocket.js';
3
- export * from './types.js';
1
+ export * from './HocuspocusProvider.ts';
2
+ export * from './HocuspocusProviderWebsocket.ts';
3
+ export * from './types.ts';
@@ -3,14 +3,14 @@ import type { Event, MessageEvent } from 'ws';
3
3
  import type { Awareness } from 'y-protocols/awareness';
4
4
  import type * as Y from 'yjs';
5
5
  import type { CloseEvent } from '@hocuspocus/common';
6
- import type { IncomingMessage } from './IncomingMessage.js';
7
- import type { OutgoingMessage } from './OutgoingMessage.js';
8
- import type { AuthenticationMessage } from './OutgoingMessages/AuthenticationMessage.js';
9
- import type { AwarenessMessage } from './OutgoingMessages/AwarenessMessage.js';
10
- import type { QueryAwarenessMessage } from './OutgoingMessages/QueryAwarenessMessage.js';
11
- import type { SyncStepOneMessage } from './OutgoingMessages/SyncStepOneMessage.js';
12
- import type { SyncStepTwoMessage } from './OutgoingMessages/SyncStepTwoMessage.js';
13
- import type { UpdateMessage } from './OutgoingMessages/UpdateMessage.js';
6
+ import type { IncomingMessage } from './IncomingMessage.ts';
7
+ import type { OutgoingMessage } from './OutgoingMessage.ts';
8
+ import type { AuthenticationMessage } from './OutgoingMessages/AuthenticationMessage.ts';
9
+ import type { AwarenessMessage } from './OutgoingMessages/AwarenessMessage.ts';
10
+ import type { QueryAwarenessMessage } from './OutgoingMessages/QueryAwarenessMessage.ts';
11
+ import type { SyncStepOneMessage } from './OutgoingMessages/SyncStepOneMessage.ts';
12
+ import type { SyncStepTwoMessage } from './OutgoingMessages/SyncStepTwoMessage.ts';
13
+ import type { UpdateMessage } from './OutgoingMessages/UpdateMessage.ts';
14
14
  export declare enum MessageType {
15
15
  Sync = 0,
16
16
  Awareness = 1,
@@ -49,6 +49,9 @@ export type ConstructableOutgoingMessage = Constructable<AuthenticationMessage>
49
49
  export type onAuthenticationFailedParameters = {
50
50
  reason: string;
51
51
  };
52
+ export type onAuthenticatedParameters = {
53
+ scope: 'read-write' | 'readonly';
54
+ };
52
55
  export type onOpenParameters = {
53
56
  event: Event;
54
57
  };
@@ -65,6 +68,9 @@ export type onStatusParameters = {
65
68
  export type onSyncedParameters = {
66
69
  state: boolean;
67
70
  };
71
+ export type onUnsyncedChangesParameters = {
72
+ number: number;
73
+ };
68
74
  export type onDisconnectParameters = {
69
75
  event: CloseEvent;
70
76
  };
@@ -84,103 +90,3 @@ export type StatesArray = {
84
90
  clientId: number;
85
91
  [key: string | number]: any;
86
92
  }[];
87
- export type TCollabThread<Data = any, CommentData = any> = {
88
- id: string;
89
- createdAt: number;
90
- updatedAt: number;
91
- deletedAt: number | null;
92
- resolvedAt?: string;
93
- comments: TCollabComment<CommentData>[];
94
- deletedComments: TCollabComment<CommentData>[];
95
- data: Data;
96
- };
97
- export type TCollabComment<Data = any> = {
98
- id: string;
99
- createdAt: string;
100
- updatedAt: string;
101
- deletedAt?: string;
102
- data: Data;
103
- content: any;
104
- };
105
- export type THistoryVersion = {
106
- name?: string;
107
- version: number;
108
- date: number;
109
- };
110
- export type THistoryConfiguration = {
111
- autoVersioning: boolean;
112
- currentVersion: number;
113
- stateCaptured: number;
114
- };
115
- export type THistoryAction = THistoryDocumentRevertAction | THistoryVersionCreateAction | THistoryVersionPreviewAction;
116
- export type THistoryDocumentRevertAction = {
117
- action: 'document.revert';
118
- /**
119
- * if changes haven't been persisted to a version yet, we'll create one with the specified name,
120
- * expect when `false` is passed.
121
- */
122
- currentVersionName?: string | false;
123
- /**
124
- * Name of the version that is created after the revert. Pass `false` to avoid generating a new version.
125
- */
126
- newVersionName?: string | false;
127
- };
128
- export type THistoryVersionCreateAction = {
129
- action: 'version.create';
130
- name?: string;
131
- };
132
- export type THistoryVersionPreviewAction = {
133
- action: 'version.preview';
134
- version: number;
135
- };
136
- export type THistoryEvent = THistoryVersionPreviewEvent | THistoryVersionCreatedEvent | THistoryDocumentRevertedEvent;
137
- export type THistoryVersionCreatedEvent = {
138
- event: 'version.created';
139
- version: number;
140
- };
141
- export type THistoryVersionPreviewEvent = {
142
- event: 'version.preview';
143
- version: number;
144
- ydoc: string;
145
- };
146
- export type THistoryDocumentRevertedEvent = {
147
- event: 'document.reverted';
148
- version: number;
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,11 +1,9 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import type { IncomingMessage } from 'http';
4
2
  import { type CloseEvent } from '@hocuspocus/common';
5
3
  import type WebSocket from 'ws';
6
- import type Document from './Document.js';
7
- import type { Hocuspocus } from './Hocuspocus.js';
8
- import type { onDisconnectPayload } from './types.js';
4
+ import type Document from './Document.ts';
5
+ import type { Hocuspocus } from './Hocuspocus.ts';
6
+ import type { onDisconnectPayload } from './types.ts';
9
7
  /**
10
8
  * The `ClientConnection` class is responsible for handling an incoming WebSocket
11
9
  *
@@ -1,15 +1,19 @@
1
- /// <reference types="node" />
2
1
  import type { IncomingMessage as HTTPIncomingMessage } from 'http';
3
- import type WebSocket from 'ws';
4
2
  import { type CloseEvent } from '@hocuspocus/common';
5
- import type Document from './Document.js';
6
- import type { onStatelessPayload } from './types.js';
3
+ import type WebSocket from 'ws';
4
+ import type Document from './Document.ts';
5
+ import type { beforeSyncPayload, onStatelessPayload } from './types.ts';
7
6
  export declare class Connection {
8
7
  webSocket: WebSocket;
9
8
  context: any;
10
9
  document: Document;
11
10
  request: HTTPIncomingMessage;
12
- callbacks: any;
11
+ callbacks: {
12
+ onClose: ((document: Document, event?: CloseEvent) => void)[];
13
+ beforeHandleMessage: (connection: Connection, update: Uint8Array) => Promise<void>;
14
+ beforeSync: (connection: Connection, payload: Pick<beforeSyncPayload, "type" | "payload">) => Promise<void>;
15
+ statelessCallback: (payload: onStatelessPayload) => Promise<void>;
16
+ };
13
17
  socketId: string;
14
18
  readOnly: boolean;
15
19
  /**
@@ -28,6 +32,10 @@ export declare class Connection {
28
32
  * Set a callback that will be triggered before an message is handled
29
33
  */
30
34
  beforeHandleMessage(callback: (connection: Connection, update: Uint8Array) => Promise<any>): Connection;
35
+ /**
36
+ * Set a callback that will be triggered before a sync message is handled
37
+ */
38
+ beforeSync(callback: (connection: Connection, payload: Pick<beforeSyncPayload, 'type' | 'payload'>) => Promise<any>): Connection;
31
39
  /**
32
40
  * Send the given message
33
41
  */
@@ -1,6 +1,6 @@
1
- import type Document from './Document.js';
2
- import type { Hocuspocus } from './Hocuspocus.js';
3
- import type { DirectConnection as DirectConnectionInterface } from './types.js';
1
+ import type Document from './Document.ts';
2
+ import type { Hocuspocus } from './Hocuspocus.ts';
3
+ import type { DirectConnection as DirectConnectionInterface } from './types.ts';
4
4
  export declare class DirectConnection implements DirectConnectionInterface {
5
5
  document: Document | null;
6
6
  instance: Hocuspocus;
@@ -1,7 +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 Connection from './Connection.js';
4
+ import type Connection from './Connection.ts';
5
5
  export declare class Document extends Doc {
6
6
  awareness: Awareness;
7
7
  callbacks: {
@@ -1,10 +1,9 @@
1
- /// <reference types="node" />
2
1
  import type { IncomingMessage } from 'http';
3
2
  import type WebSocket from 'ws';
4
- import type { Server } from './Server.js';
5
- import { DirectConnection } from './DirectConnection.js';
6
- import Document from './Document.js';
7
- import type { Configuration, ConnectionConfiguration, HookName, HookPayloadByName, onStoreDocumentPayload } from './types.js';
3
+ import { DirectConnection } from './DirectConnection.ts';
4
+ import Document from './Document.ts';
5
+ import type { Server } from './Server.ts';
6
+ import type { Configuration, ConnectionConfiguration, HookName, HookPayloadByName, onStoreDocumentPayload } from './types.ts';
8
7
  export declare const defaultConfiguration: {
9
8
  name: null;
10
9
  timeout: number;
@@ -1,6 +1,6 @@
1
1
  import type { Decoder } from 'lib0/decoding';
2
2
  import type { Encoder } from 'lib0/encoding';
3
- import type { MessageType } from './types.js';
3
+ import type { MessageType } from './types.ts';
4
4
  export declare class IncomingMessage {
5
5
  /**
6
6
  * Access to the received message.
@@ -14,10 +14,11 @@ export declare class IncomingMessage {
14
14
  private encoderInternal?;
15
15
  constructor(input: any);
16
16
  get encoder(): Encoder;
17
- readVarUint8Array(): Uint8Array;
17
+ readVarUint8Array(): Uint8Array<ArrayBufferLike>;
18
+ peekVarUint8Array(): Uint8Array<ArrayBufferLike>;
18
19
  readVarUint(): number;
19
20
  readVarString(): string;
20
- toUint8Array(): Uint8Array;
21
+ toUint8Array(): Uint8Array<ArrayBufferLike>;
21
22
  writeVarUint(type: MessageType): void;
22
23
  writeVarString(string: string): void;
23
24
  get length(): number;
@@ -1,11 +1,11 @@
1
- import type Connection from './Connection.js';
2
- import type Document from './Document.js';
3
- import type { IncomingMessage } from './IncomingMessage.js';
1
+ import type Connection from './Connection.ts';
2
+ import type Document from './Document.ts';
3
+ import type { IncomingMessage } from './IncomingMessage.ts';
4
4
  export declare class MessageReceiver {
5
5
  message: IncomingMessage;
6
6
  defaultTransactionOrigin?: string;
7
7
  constructor(message: IncomingMessage, defaultTransactionOrigin?: string);
8
- apply(document: Document, connection?: Connection, reply?: (message: Uint8Array) => void): void;
9
- readSyncMessage(message: IncomingMessage, document: Document, connection?: Connection, reply?: (message: Uint8Array) => void, requestFirstSync?: boolean): 0 | 1 | 2;
8
+ apply(document: Document, connection?: Connection, reply?: (message: Uint8Array) => void): Promise<void>;
9
+ readSyncMessage(message: IncomingMessage, document: Document, connection?: Connection, reply?: (message: Uint8Array) => void, requestFirstSync?: boolean): Promise<0 | 1 | 2>;
10
10
  applyQueryAwarenessMessage(document: Document, reply?: (message: Uint8Array) => void): void;
11
11
  }
@@ -1,6 +1,6 @@
1
1
  import type { Encoder } from 'lib0/encoding';
2
2
  import type { Awareness } from 'y-protocols/awareness';
3
- import type Document from './Document.js';
3
+ import type Document from './Document.ts';
4
4
  export declare class OutgoingMessage {
5
5
  encoder: Encoder;
6
6
  type?: number;
@@ -1,8 +1,7 @@
1
- /// <reference types="node" />
2
1
  import type { IncomingMessage, Server as HTTPServer, ServerResponse } from 'http';
3
2
  import { WebSocketServer } from 'ws';
4
3
  import type { AddressInfo, ServerOptions } from 'ws';
5
- import { Hocuspocus } from './Hocuspocus.js';
4
+ import { Hocuspocus } from './Hocuspocus.ts';
6
5
  import type { Configuration } from './types';
7
6
  export interface ServerConfiguration extends Configuration {
8
7
  port?: number;
@@ -1,9 +1,9 @@
1
- export * from './Connection.js';
2
- export * from './Document.js';
3
- export * from './Hocuspocus.js';
4
- export * from './IncomingMessage.js';
5
- export * from './MessageReceiver.js';
6
- export * from './OutgoingMessage.js';
7
- export * from './Server.js';
8
- export * from './types.js';
9
- export * from './util/debounce.js';
1
+ export * from './Connection.ts';
2
+ export * from './Document.ts';
3
+ export * from './Hocuspocus.ts';
4
+ export * from './IncomingMessage.ts';
5
+ export * from './MessageReceiver.ts';
6
+ export * from './OutgoingMessage.ts';
7
+ export * from './Server.ts';
8
+ export * from './types.ts';
9
+ export * from './util/debounce.ts';