@hocuspocus/common 3.0.4-rc.0 → 3.0.6-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 (50) hide show
  1. package/dist/hocuspocus-common.cjs.map +1 -1
  2. package/dist/hocuspocus-common.esm.js.map +1 -1
  3. package/dist/packages/common/src/auth.d.ts +1 -1
  4. package/dist/packages/common/src/index.d.ts +4 -4
  5. package/dist/packages/extension-database/src/index.d.ts +1 -1
  6. package/dist/packages/extension-logger/src/index.d.ts +1 -1
  7. package/dist/packages/extension-redis/src/Redis.d.ts +0 -2
  8. package/dist/packages/extension-redis/src/index.d.ts +1 -1
  9. package/dist/packages/extension-sqlite/src/index.d.ts +1 -1
  10. package/dist/packages/extension-throttle/src/index.d.ts +0 -1
  11. package/dist/packages/extension-webhook/src/index.d.ts +0 -1
  12. package/dist/packages/provider/src/HocuspocusProvider.d.ts +4 -4
  13. package/dist/packages/provider/src/HocuspocusProviderWebsocket.d.ts +4 -4
  14. package/dist/packages/provider/src/IncomingMessage.d.ts +2 -2
  15. package/dist/packages/provider/src/MessageReceiver.d.ts +2 -2
  16. package/dist/packages/provider/src/MessageSender.d.ts +2 -2
  17. package/dist/packages/provider/src/OutgoingMessage.d.ts +2 -2
  18. package/dist/packages/provider/src/OutgoingMessages/AuthenticationMessage.d.ts +3 -3
  19. package/dist/packages/provider/src/OutgoingMessages/AwarenessMessage.d.ts +3 -3
  20. package/dist/packages/provider/src/OutgoingMessages/CloseMessage.d.ts +3 -3
  21. package/dist/packages/provider/src/OutgoingMessages/QueryAwarenessMessage.d.ts +3 -3
  22. package/dist/packages/provider/src/OutgoingMessages/StatelessMessage.d.ts +3 -3
  23. package/dist/packages/provider/src/OutgoingMessages/SyncStepOneMessage.d.ts +3 -3
  24. package/dist/packages/provider/src/OutgoingMessages/SyncStepTwoMessage.d.ts +3 -3
  25. package/dist/packages/provider/src/OutgoingMessages/UpdateMessage.d.ts +3 -3
  26. package/dist/packages/provider/src/index.d.ts +3 -3
  27. package/dist/packages/provider/src/types.d.ts +8 -8
  28. package/dist/packages/server/src/ClientConnection.d.ts +3 -5
  29. package/dist/packages/server/src/Connection.d.ts +13 -5
  30. package/dist/packages/server/src/DirectConnection.d.ts +3 -3
  31. package/dist/packages/server/src/Document.d.ts +1 -1
  32. package/dist/packages/server/src/Hocuspocus.d.ts +4 -5
  33. package/dist/packages/server/src/IncomingMessage.d.ts +4 -3
  34. package/dist/packages/server/src/MessageReceiver.d.ts +5 -5
  35. package/dist/packages/server/src/OutgoingMessage.d.ts +1 -1
  36. package/dist/packages/server/src/Server.d.ts +1 -2
  37. package/dist/packages/server/src/index.d.ts +9 -9
  38. package/dist/packages/server/src/types.d.ts +28 -9
  39. package/dist/packages/server/src/util/getParameters.d.ts +0 -2
  40. package/dist/packages/transformer/src/Prosemirror.d.ts +1 -1
  41. package/dist/packages/transformer/src/Tiptap.d.ts +1 -1
  42. package/dist/packages/transformer/src/index.d.ts +3 -3
  43. package/dist/playground/frontend/app/SocketContext.d.ts +2 -0
  44. package/dist/playground/frontend/next.config.d.ts +3 -0
  45. package/dist/tests/utils/index.d.ts +9 -9
  46. package/dist/tests/utils/newHocuspocusProviderWebsocket.d.ts +1 -1
  47. package/package.json +2 -2
  48. package/src/index.ts +4 -4
  49. package/dist/playground/frontend/vite.config.d.ts +0 -2
  50. /package/dist/{playground/frontend/src/main.d.ts → tests/server/beforeSync.d.ts} +0 -0
@@ -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';
@@ -1,20 +1,16 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- /// <reference types="node" />
4
- /// <reference types="node" />
5
1
  import type { IncomingHttpHeaders, IncomingMessage, ServerResponse } from 'http';
6
2
  import type { URLSearchParams } from 'url';
7
3
  import type { Awareness } from 'y-protocols/awareness';
8
- import type Connection from './Connection.js';
9
- import type Document from './Document.js';
10
- import type { Hocuspocus } from './Hocuspocus.js';
4
+ import type Connection from './Connection.ts';
5
+ import type Document from './Document.ts';
6
+ import type { Hocuspocus } from './Hocuspocus.ts';
11
7
  export declare enum MessageType {
12
8
  Unknown = -1,
13
9
  Sync = 0,
14
10
  Awareness = 1,
15
11
  Auth = 2,
16
12
  QueryAwareness = 3,
17
- SyncReply = 4,
13
+ SyncReply = 4,// same as Sync, but won't trigger another 'SyncStep1'
18
14
  Stateless = 5,
19
15
  BroadcastStateless = 6,
20
16
  CLOSE = 7,
@@ -42,6 +38,7 @@ export interface Extension {
42
38
  onLoadDocument?(data: onLoadDocumentPayload): Promise<any>;
43
39
  afterLoadDocument?(data: afterLoadDocumentPayload): Promise<any>;
44
40
  beforeHandleMessage?(data: beforeHandleMessagePayload): Promise<any>;
41
+ beforeSync?(data: beforeSyncPayload): Promise<any>;
45
42
  beforeBroadcastStateless?(data: beforeBroadcastStatelessPayload): Promise<any>;
46
43
  onStateless?(payload: onStatelessPayload): Promise<any>;
47
44
  onChange?(data: onChangePayload): Promise<any>;
@@ -54,7 +51,7 @@ export interface Extension {
54
51
  afterUnloadDocument?(data: afterUnloadDocumentPayload): Promise<any>;
55
52
  onDestroy?(data: onDestroyPayload): Promise<any>;
56
53
  }
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
+ export type HookName = 'onConfigure' | 'onListen' | 'onUpgrade' | 'onConnect' | 'connected' | 'onAuthenticate' | 'onCreateDocument' | 'onLoadDocument' | 'afterLoadDocument' | 'beforeHandleMessage' | 'beforeBroadcastStateless' | 'beforeSync' | 'onStateless' | 'onChange' | 'onStoreDocument' | 'afterStoreDocument' | 'onAwarenessUpdate' | 'onRequest' | 'onDisconnect' | 'beforeUnloadDocument' | 'afterUnloadDocument' | 'onDestroy';
58
55
  export type HookPayloadByName = {
59
56
  onConfigure: onConfigurePayload;
60
57
  onListen: onListenPayload;
@@ -67,6 +64,7 @@ export type HookPayloadByName = {
67
64
  afterLoadDocument: afterLoadDocumentPayload;
68
65
  beforeHandleMessage: beforeHandleMessagePayload;
69
66
  beforeBroadcastStateless: beforeBroadcastStatelessPayload;
67
+ beforeSync: beforeSyncPayload;
70
68
  onStateless: onStatelessPayload;
71
69
  onChange: onChangePayload;
72
70
  onStoreDocument: onStoreDocumentPayload;
@@ -211,6 +209,27 @@ export interface beforeHandleMessagePayload {
211
209
  socketId: string;
212
210
  connection: Connection;
213
211
  }
212
+ export interface beforeSyncPayload {
213
+ clientsCount: number;
214
+ context: any;
215
+ document: Document;
216
+ documentName: string;
217
+ connection: Connection;
218
+ /**
219
+ * The y-protocols/sync message type
220
+ * @example
221
+ * 0: SyncStep1
222
+ * 1: SyncStep2
223
+ * 2: YjsUpdate
224
+ *
225
+ * @see https://github.com/yjs/y-protocols/blob/master/sync.js#L13-L40
226
+ */
227
+ type: number;
228
+ /**
229
+ * The payload of the y-sync message.
230
+ */
231
+ payload: Uint8Array;
232
+ }
214
233
  export interface beforeBroadcastStatelessPayload {
215
234
  document: Document;
216
235
  documentName: string;
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import type { IncomingMessage } from 'http';
4
2
  import { URLSearchParams } from 'url';
5
3
  /**
@@ -1,6 +1,6 @@
1
1
  import { Doc } from 'yjs';
2
2
  import { Schema } from '@tiptap/pm/model';
3
- import type { Transformer } from './types.js';
3
+ import type { Transformer } from './types.ts';
4
4
  declare class Prosemirror implements Transformer {
5
5
  defaultSchema: Schema;
6
6
  schema(schema: Schema): Prosemirror;
@@ -1,6 +1,6 @@
1
1
  import type { Doc } from 'yjs';
2
2
  import type { Extensions } from '@tiptap/core';
3
- import type { Transformer } from './types.js';
3
+ import type { Transformer } from './types.ts';
4
4
  export declare class Tiptap implements Transformer {
5
5
  defaultExtensions: Extensions;
6
6
  extensions(extensions: Extensions): Tiptap;
@@ -1,3 +1,3 @@
1
- export * from './Prosemirror.js';
2
- export * from './Tiptap.js';
3
- export * from './types.js';
1
+ export * from './Prosemirror.ts';
2
+ export * from './Tiptap.ts';
3
+ export * from './types.ts';
@@ -0,0 +1,2 @@
1
+ import type { HocuspocusProviderWebsocket } from "@hocuspocus/provider";
2
+ export declare const SocketContext: import("react").Context<HocuspocusProviderWebsocket | null>;
@@ -0,0 +1,3 @@
1
+ import type { NextConfig } from "next";
2
+ declare const nextConfig: NextConfig;
3
+ export default nextConfig;
@@ -1,9 +1,9 @@
1
- export * from './createDirectory.js';
2
- export * from './flushRedis.js';
3
- export * from './newHocuspocus.js';
4
- export * from './newHocuspocusProvider.js';
5
- export * from './newHocuspocusProviderWebsocket.js';
6
- export * from './randomInteger.js';
7
- export * from './redisConnectionSettings.js';
8
- export * from './removeDirectory.js';
9
- export * from './sleep.js';
1
+ export * from './createDirectory.ts';
2
+ export * from './flushRedis.ts';
3
+ export * from './newHocuspocus.ts';
4
+ export * from './newHocuspocusProvider.ts';
5
+ export * from './newHocuspocusProviderWebsocket.ts';
6
+ export * from './randomInteger.ts';
7
+ export * from './redisConnectionSettings.ts';
8
+ export * from './removeDirectory.ts';
9
+ export * from './sleep.ts';
@@ -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/common",
3
3
  "description": "shared code for multiple Hocuspocus packages",
4
- "version": "3.0.4-rc.0",
4
+ "version": "3.0.6-rc.0",
5
5
  "homepage": "https://hocuspocus.dev",
6
6
  "keywords": [
7
7
  "hocuspocus"
@@ -13,7 +13,7 @@
13
13
  "types": "dist/packages/common/src/index.d.ts",
14
14
  "exports": {
15
15
  "source": {
16
- "import": "./src"
16
+ "import": "./src/index.ts"
17
17
  },
18
18
  "default": {
19
19
  "import": "./dist/hocuspocus-common.esm.js",
package/src/index.ts CHANGED
@@ -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,2 +0,0 @@
1
- declare const _default: import("vite").UserConfig;
2
- export default _default;