@hocuspocus/extension-database 1.0.0-alpha.1 → 1.0.0-alpha.12

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 (87) hide show
  1. package/dist/hocuspocus-database.cjs +10 -10
  2. package/dist/hocuspocus-database.cjs.map +1 -1
  3. package/dist/hocuspocus-database.esm.js +10 -10
  4. package/dist/hocuspocus-database.esm.js.map +1 -1
  5. package/dist/packages/common/src/CloseEvents.d.ts +23 -0
  6. package/dist/packages/common/src/awarenessStatesToArray.d.ts +3 -0
  7. package/dist/packages/common/src/index.d.ts +3 -0
  8. package/dist/packages/common/src/types.d.ts +10 -0
  9. package/dist/packages/extension-database/src/Database.d.ts +5 -9
  10. package/dist/packages/extension-logger/src/Logger.d.ts +5 -0
  11. package/dist/packages/extension-monitor/src/Collector.d.ts +0 -2
  12. package/dist/packages/extension-monitor/src/index.d.ts +2 -2
  13. package/dist/packages/extension-sqlite/src/SQLite.d.ts +4 -4
  14. package/dist/packages/extension-throttle/src/index.d.ts +6 -2
  15. package/dist/packages/extension-webhook/src/index.d.ts +1 -2
  16. package/dist/packages/provider/src/EventEmitter.d.ts +1 -1
  17. package/dist/packages/provider/src/HocuspocusCloudProvider.d.ts +4 -3
  18. package/dist/packages/provider/src/HocuspocusProvider.d.ts +24 -26
  19. package/dist/packages/provider/src/index.d.ts +0 -1
  20. package/dist/packages/provider/src/types.d.ts +43 -0
  21. package/dist/packages/server/src/Connection.d.ts +5 -5
  22. package/dist/packages/server/src/Debugger.d.ts +1 -2
  23. package/dist/packages/server/src/Document.d.ts +8 -5
  24. package/dist/packages/server/src/Hocuspocus.d.ts +32 -14
  25. package/dist/packages/server/src/MessageReceiver.d.ts +8 -5
  26. package/dist/packages/server/src/OutgoingMessage.d.ts +1 -0
  27. package/dist/packages/server/src/index.d.ts +7 -0
  28. package/dist/packages/server/src/types.d.ts +92 -34
  29. package/dist/tests/extension-logger/onListen.d.ts +1 -0
  30. package/dist/tests/extension-redis/onLoadDocument.d.ts +1 -0
  31. package/dist/tests/extension-redis/onSynced.d.ts +1 -0
  32. package/dist/tests/extension-redis-rewrite/closeConnections.d.ts +1 -0
  33. package/dist/tests/extension-redis-rewrite/getConnectionCount.d.ts +1 -0
  34. package/dist/tests/extension-redis-rewrite/getDocumentsCount.d.ts +1 -0
  35. package/dist/tests/extension-redis-rewrite/onAwarenessChange.d.ts +1 -0
  36. package/dist/tests/extension-redis-rewrite/onChange.d.ts +1 -0
  37. package/dist/tests/extension-redis-rewrite/onStoreDocument.d.ts +1 -0
  38. package/dist/tests/extension-rocksdb/onLoadDocument.d.ts +1 -0
  39. package/dist/tests/extension-throttle/configuration.d.ts +1 -0
  40. package/dist/tests/provider/configuration.d.ts +1 -0
  41. package/dist/tests/provider/observe.d.ts +1 -0
  42. package/dist/tests/provider/observeDeep.d.ts +1 -0
  43. package/dist/tests/provider/onAuthenticated.d.ts +1 -0
  44. package/dist/tests/provider/onAuthenticationFailed.d.ts +1 -0
  45. package/dist/tests/provider/onAwarenessChange.d.ts +1 -0
  46. package/dist/tests/provider/onAwarenessUpdate.d.ts +1 -0
  47. package/dist/tests/provider/onClose.d.ts +1 -0
  48. package/dist/tests/provider/onConnect.d.ts +1 -0
  49. package/dist/tests/provider/onDisconnect.d.ts +1 -0
  50. package/dist/tests/provider/onMessage.d.ts +1 -0
  51. package/dist/tests/provider/onOpen.d.ts +1 -0
  52. package/dist/tests/provider/onSynced.d.ts +1 -0
  53. package/dist/tests/server/address.d.ts +1 -0
  54. package/dist/tests/server/afterStoreDocument.d.ts +1 -0
  55. package/dist/tests/server/closeConnections.d.ts +1 -0
  56. package/dist/tests/server/getConnectionsCount.d.ts +1 -0
  57. package/dist/tests/server/getDocumentName.d.ts +1 -0
  58. package/dist/tests/server/getDocumentsCount.d.ts +1 -0
  59. package/dist/tests/server/getMessageLogs.d.ts +1 -0
  60. package/dist/tests/server/listen.d.ts +1 -0
  61. package/dist/tests/server/onAuthenticate.d.ts +1 -0
  62. package/dist/tests/server/onAwarenessUpdate.d.ts +1 -0
  63. package/dist/tests/server/onChange.d.ts +1 -0
  64. package/dist/tests/server/onConfigure.d.ts +1 -0
  65. package/dist/tests/server/onConnect.d.ts +1 -0
  66. package/dist/tests/server/onDestroy.d.ts +1 -0
  67. package/dist/tests/server/onDisconnect.d.ts +1 -0
  68. package/dist/tests/server/onListen.d.ts +1 -0
  69. package/dist/tests/server/onLoadDocument.d.ts +1 -0
  70. package/dist/tests/server/onRequest.d.ts +1 -0
  71. package/dist/tests/server/onStoreDocument.d.ts +1 -0
  72. package/dist/tests/server/onUpgrade.d.ts +1 -0
  73. package/dist/tests/server/requiresAuthentication.d.ts +1 -0
  74. package/dist/tests/transformer/TiptapTransformer.d.ts +1 -0
  75. package/dist/tests/utils/createDirectory.d.ts +1 -0
  76. package/dist/tests/utils/flushRedis.d.ts +1 -0
  77. package/dist/tests/utils/index.d.ts +7 -0
  78. package/dist/tests/utils/newHocuspocus.d.ts +2 -0
  79. package/dist/tests/utils/newHocuspocusProvider.d.ts +3 -0
  80. package/dist/tests/utils/redisConnectionSettings.d.ts +4 -0
  81. package/dist/tests/utils/removeDirectory.d.ts +1 -0
  82. package/dist/tests/utils/sleep.d.ts +1 -0
  83. package/package.json +4 -4
  84. package/src/Database.ts +17 -16
  85. package/dist/packages/provider/src/utils/awarenessStatesToArray.d.ts +0 -4
  86. package/dist/packages/provider/src/utils/index.d.ts +0 -1
  87. package/dist/packages/server/src/CloseEvents.d.ts +0 -4
@@ -33,8 +33,8 @@ class Database {
33
33
  * Default configuration
34
34
  */
35
35
  this.configuration = {
36
- fetchUpdates: async () => [],
37
- storeUpdate: async () => null,
36
+ fetch: async () => null,
37
+ store: async () => null,
38
38
  };
39
39
  this.configuration = {
40
40
  ...this.configuration,
@@ -45,20 +45,20 @@ class Database {
45
45
  * Get stored data from the database.
46
46
  */
47
47
  async onLoadDocument({ document, documentName }) {
48
- const updates = await this.configuration.fetchUpdates({ documentName });
49
- if (updates && updates.length) {
50
- updates.forEach((update) => {
51
- Y__namespace.applyUpdate(document, update);
52
- });
48
+ const update = await this.configuration.fetch({ documentName });
49
+ if (update) {
50
+ Y__namespace.applyUpdate(document, update);
53
51
  }
54
52
  return document;
55
53
  }
56
54
  /**
57
55
  * Store new updates in the database.
58
56
  */
59
- async onChange({ document, documentName }) {
60
- const update = Buffer.from(Y__namespace.encodeStateAsUpdate(document));
61
- return this.configuration.storeUpdate({ update, documentName });
57
+ async onStoreDocument(data) {
58
+ return this.configuration.store({
59
+ ...data,
60
+ state: Buffer.from(Y__namespace.encodeStateAsUpdate(data.document)),
61
+ });
62
62
  }
63
63
  }
64
64
 
@@ -1 +1 @@
1
- {"version":3,"file":"hocuspocus-database.cjs","sources":["../src/Database.ts"],"sourcesContent":["import { Extension, onChangePayload, onLoadDocumentPayload } from '@hocuspocus/server'\nimport * as Y from 'yjs'\n\nexport interface DatabaseConfiguration {\n /**\n * Pass a Promise to retrieve updates from your database. The Promise should resolve to\n * an array of items with Y.js-compatible binary data.\n */\n fetchUpdates: ({ documentName }: { documentName: string}) => Promise<Uint8Array[]>,\n /**\n * Pass a function to store updates in your database.\n */\n storeUpdate: ({ update, documentName }: { update: Buffer, documentName: string}) => void,\n}\n\nexport class Database implements Extension {\n /**\n * Default configuration\n */\n configuration: DatabaseConfiguration = {\n fetchUpdates: async () => [],\n storeUpdate: async () => null,\n }\n\n /**\n * Constructor\n */\n constructor(configuration: Partial<DatabaseConfiguration>) {\n this.configuration = {\n ...this.configuration,\n ...configuration,\n }\n }\n\n /**\n * Get stored data from the database.\n */\n async onLoadDocument({ document, documentName }: onLoadDocumentPayload): Promise<any> {\n const updates = await this.configuration.fetchUpdates({ documentName })\n\n if (updates && updates.length) {\n updates.forEach((update: any) => {\n Y.applyUpdate(document, update)\n })\n }\n\n return document\n }\n\n /**\n * Store new updates in the database.\n */\n async onChange({ document, documentName }: onChangePayload) {\n const update = Buffer.from(\n Y.encodeStateAsUpdate(document),\n )\n\n return this.configuration.storeUpdate({ update, documentName })\n }\n}\n"],"names":["Y"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;MAea,QAAQ;;;;IAYnB,YAAY,aAA6C;;;;QARzD,kBAAa,GAA0B;YACrC,YAAY,EAAE,YAAY,EAAE;YAC5B,WAAW,EAAE,YAAY,IAAI;SAC9B,CAAA;QAMC,IAAI,CAAC,aAAa,GAAG;YACnB,GAAG,IAAI,CAAC,aAAa;YACrB,GAAG,aAAa;SACjB,CAAA;KACF;;;;IAKD,MAAM,cAAc,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAyB;QACpE,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,EAAE,YAAY,EAAE,CAAC,CAAA;QAEvE,IAAI,OAAO,IAAI,OAAO,CAAC,MAAM,EAAE;YAC7B,OAAO,CAAC,OAAO,CAAC,CAAC,MAAW;gBAC1BA,YAAC,CAAC,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;aAChC,CAAC,CAAA;SACH;QAED,OAAO,QAAQ,CAAA;KAChB;;;;IAKD,MAAM,QAAQ,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAmB;QACxD,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CACxBA,YAAC,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAChC,CAAA;QAED,OAAO,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,CAAA;KAChE;;;;;"}
1
+ {"version":3,"file":"hocuspocus-database.cjs","sources":["../src/Database.ts"],"sourcesContent":["import {\n Extension, onChangePayload, onLoadDocumentPayload, storePayload,\n} from '@hocuspocus/server'\nimport * as Y from 'yjs'\n\nexport interface DatabaseConfiguration {\n /**\n * Pass a Promise to retrieve updates from your database. The Promise should resolve to\n * an array of items with Y.js-compatible binary data.\n */\n fetch: ({ documentName }: { documentName: string}) => Promise<Uint8Array | null>,\n /**\n * Pass a function to store updates in your database.\n */\n store: (data: storePayload) => void,\n}\n\nexport class Database implements Extension {\n /**\n * Default configuration\n */\n configuration: DatabaseConfiguration = {\n fetch: async () => null,\n store: async () => null,\n }\n\n /**\n * Constructor\n */\n constructor(configuration: Partial<DatabaseConfiguration>) {\n this.configuration = {\n ...this.configuration,\n ...configuration,\n }\n }\n\n /**\n * Get stored data from the database.\n */\n async onLoadDocument({ document, documentName }: onLoadDocumentPayload): Promise<any> {\n const update = await this.configuration.fetch({ documentName })\n\n if (update) {\n Y.applyUpdate(document, update)\n }\n\n return document\n }\n\n /**\n * Store new updates in the database.\n */\n async onStoreDocument(data: onChangePayload) {\n return this.configuration.store({\n ...data,\n state: Buffer.from(\n Y.encodeStateAsUpdate(data.document),\n ),\n })\n }\n}\n"],"names":["Y"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;MAiBa,QAAQ,CAAA;AASnB;;AAEG;AACH,IAAA,WAAA,CAAY,aAA6C,EAAA;AAXzD;;AAEG;AACH,QAAA,IAAA,CAAA,aAAa,GAA0B;AACrC,YAAA,KAAK,EAAE,YAAY,IAAI;AACvB,YAAA,KAAK,EAAE,YAAY,IAAI;SACxB,CAAA;QAMC,IAAI,CAAC,aAAa,GAAG;YACnB,GAAG,IAAI,CAAC,aAAa;AACrB,YAAA,GAAG,aAAa;SACjB,CAAA;KACF;AAED;;AAEG;AACH,IAAA,MAAM,cAAc,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAyB,EAAA;AACpE,QAAA,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,YAAY,EAAE,CAAC,CAAA;AAE/D,QAAA,IAAI,MAAM,EAAE;AACV,YAAAA,YAAC,CAAC,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;AAChC,SAAA;AAED,QAAA,OAAO,QAAQ,CAAA;KAChB;AAED;;AAEG;IACH,MAAM,eAAe,CAAC,IAAqB,EAAA;AACzC,QAAA,OAAO,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC;AAC9B,YAAA,GAAG,IAAI;AACP,YAAA,KAAK,EAAE,MAAM,CAAC,IAAI,CAChBA,YAAC,CAAC,mBAAmB,CAAC,IAAI,CAAC,QAAQ,CAAC,CACrC;AACF,SAAA,CAAC,CAAA;KACH;AACF;;;;"}
@@ -9,8 +9,8 @@ class Database {
9
9
  * Default configuration
10
10
  */
11
11
  this.configuration = {
12
- fetchUpdates: async () => [],
13
- storeUpdate: async () => null,
12
+ fetch: async () => null,
13
+ store: async () => null,
14
14
  };
15
15
  this.configuration = {
16
16
  ...this.configuration,
@@ -21,20 +21,20 @@ class Database {
21
21
  * Get stored data from the database.
22
22
  */
23
23
  async onLoadDocument({ document, documentName }) {
24
- const updates = await this.configuration.fetchUpdates({ documentName });
25
- if (updates && updates.length) {
26
- updates.forEach((update) => {
27
- Y.applyUpdate(document, update);
28
- });
24
+ const update = await this.configuration.fetch({ documentName });
25
+ if (update) {
26
+ Y.applyUpdate(document, update);
29
27
  }
30
28
  return document;
31
29
  }
32
30
  /**
33
31
  * Store new updates in the database.
34
32
  */
35
- async onChange({ document, documentName }) {
36
- const update = Buffer.from(Y.encodeStateAsUpdate(document));
37
- return this.configuration.storeUpdate({ update, documentName });
33
+ async onStoreDocument(data) {
34
+ return this.configuration.store({
35
+ ...data,
36
+ state: Buffer.from(Y.encodeStateAsUpdate(data.document)),
37
+ });
38
38
  }
39
39
  }
40
40
 
@@ -1 +1 @@
1
- {"version":3,"file":"hocuspocus-database.esm.js","sources":["../src/Database.ts"],"sourcesContent":["import { Extension, onChangePayload, onLoadDocumentPayload } from '@hocuspocus/server'\nimport * as Y from 'yjs'\n\nexport interface DatabaseConfiguration {\n /**\n * Pass a Promise to retrieve updates from your database. The Promise should resolve to\n * an array of items with Y.js-compatible binary data.\n */\n fetchUpdates: ({ documentName }: { documentName: string}) => Promise<Uint8Array[]>,\n /**\n * Pass a function to store updates in your database.\n */\n storeUpdate: ({ update, documentName }: { update: Buffer, documentName: string}) => void,\n}\n\nexport class Database implements Extension {\n /**\n * Default configuration\n */\n configuration: DatabaseConfiguration = {\n fetchUpdates: async () => [],\n storeUpdate: async () => null,\n }\n\n /**\n * Constructor\n */\n constructor(configuration: Partial<DatabaseConfiguration>) {\n this.configuration = {\n ...this.configuration,\n ...configuration,\n }\n }\n\n /**\n * Get stored data from the database.\n */\n async onLoadDocument({ document, documentName }: onLoadDocumentPayload): Promise<any> {\n const updates = await this.configuration.fetchUpdates({ documentName })\n\n if (updates && updates.length) {\n updates.forEach((update: any) => {\n Y.applyUpdate(document, update)\n })\n }\n\n return document\n }\n\n /**\n * Store new updates in the database.\n */\n async onChange({ document, documentName }: onChangePayload) {\n const update = Buffer.from(\n Y.encodeStateAsUpdate(document),\n )\n\n return this.configuration.storeUpdate({ update, documentName })\n }\n}\n"],"names":[],"mappings":";;MAea,QAAQ;;;;IAYnB,YAAY,aAA6C;;;;QARzD,kBAAa,GAA0B;YACrC,YAAY,EAAE,YAAY,EAAE;YAC5B,WAAW,EAAE,YAAY,IAAI;SAC9B,CAAA;QAMC,IAAI,CAAC,aAAa,GAAG;YACnB,GAAG,IAAI,CAAC,aAAa;YACrB,GAAG,aAAa;SACjB,CAAA;KACF;;;;IAKD,MAAM,cAAc,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAyB;QACpE,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,EAAE,YAAY,EAAE,CAAC,CAAA;QAEvE,IAAI,OAAO,IAAI,OAAO,CAAC,MAAM,EAAE;YAC7B,OAAO,CAAC,OAAO,CAAC,CAAC,MAAW;gBAC1B,CAAC,CAAC,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;aAChC,CAAC,CAAA;SACH;QAED,OAAO,QAAQ,CAAA;KAChB;;;;IAKD,MAAM,QAAQ,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAmB;QACxD,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CACxB,CAAC,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAChC,CAAA;QAED,OAAO,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,CAAA;KAChE;;;;;"}
1
+ {"version":3,"file":"hocuspocus-database.esm.js","sources":["../src/Database.ts"],"sourcesContent":["import {\n Extension, onChangePayload, onLoadDocumentPayload, storePayload,\n} from '@hocuspocus/server'\nimport * as Y from 'yjs'\n\nexport interface DatabaseConfiguration {\n /**\n * Pass a Promise to retrieve updates from your database. The Promise should resolve to\n * an array of items with Y.js-compatible binary data.\n */\n fetch: ({ documentName }: { documentName: string}) => Promise<Uint8Array | null>,\n /**\n * Pass a function to store updates in your database.\n */\n store: (data: storePayload) => void,\n}\n\nexport class Database implements Extension {\n /**\n * Default configuration\n */\n configuration: DatabaseConfiguration = {\n fetch: async () => null,\n store: async () => null,\n }\n\n /**\n * Constructor\n */\n constructor(configuration: Partial<DatabaseConfiguration>) {\n this.configuration = {\n ...this.configuration,\n ...configuration,\n }\n }\n\n /**\n * Get stored data from the database.\n */\n async onLoadDocument({ document, documentName }: onLoadDocumentPayload): Promise<any> {\n const update = await this.configuration.fetch({ documentName })\n\n if (update) {\n Y.applyUpdate(document, update)\n }\n\n return document\n }\n\n /**\n * Store new updates in the database.\n */\n async onStoreDocument(data: onChangePayload) {\n return this.configuration.store({\n ...data,\n state: Buffer.from(\n Y.encodeStateAsUpdate(data.document),\n ),\n })\n }\n}\n"],"names":[],"mappings":";;MAiBa,QAAQ,CAAA;AASnB;;AAEG;AACH,IAAA,WAAA,CAAY,aAA6C,EAAA;AAXzD;;AAEG;AACH,QAAA,IAAA,CAAA,aAAa,GAA0B;AACrC,YAAA,KAAK,EAAE,YAAY,IAAI;AACvB,YAAA,KAAK,EAAE,YAAY,IAAI;SACxB,CAAA;QAMC,IAAI,CAAC,aAAa,GAAG;YACnB,GAAG,IAAI,CAAC,aAAa;AACrB,YAAA,GAAG,aAAa;SACjB,CAAA;KACF;AAED;;AAEG;AACH,IAAA,MAAM,cAAc,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAyB,EAAA;AACpE,QAAA,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,YAAY,EAAE,CAAC,CAAA;AAE/D,QAAA,IAAI,MAAM,EAAE;AACV,YAAA,CAAC,CAAC,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;AAChC,SAAA;AAED,QAAA,OAAO,QAAQ,CAAA;KAChB;AAED;;AAEG;IACH,MAAM,eAAe,CAAC,IAAqB,EAAA;AACzC,QAAA,OAAO,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC;AAC9B,YAAA,GAAG,IAAI;AACP,YAAA,KAAK,EAAE,MAAM,CAAC,IAAI,CAChB,CAAC,CAAC,mBAAmB,CAAC,IAAI,CAAC,QAAQ,CAAC,CACrC;AACF,SAAA,CAAC,CAAA;KACH;AACF;;;;"}
@@ -0,0 +1,23 @@
1
+ export interface CloseEvent {
2
+ code: number;
3
+ reason: string;
4
+ }
5
+ /**
6
+ * The server successfully processed the request, asks that the requester reset
7
+ * its document view, and is not returning any content.
8
+ */
9
+ export declare const ResetConnection: CloseEvent;
10
+ /**
11
+ * Similar to Forbidden, but specifically for use when authentication is required and has
12
+ * failed or has not yet been provided.
13
+ */
14
+ export declare const Unauthorized: CloseEvent;
15
+ /**
16
+ * The request contained valid data and was understood by the server, but the server
17
+ * is refusing action.
18
+ */
19
+ export declare const Forbidden: CloseEvent;
20
+ /**
21
+ * The server timed out waiting for the request.
22
+ */
23
+ export declare const ConnectionTimeout: CloseEvent;
@@ -0,0 +1,3 @@
1
+ export declare const awarenessStatesToArray: (states: Map<number, Record<string, any>>) => {
2
+ clientId: number;
3
+ }[];
@@ -1 +1,4 @@
1
1
  export * from './auth';
2
+ export * from './CloseEvents';
3
+ export * from './awarenessStatesToArray';
4
+ export * from './types';
@@ -0,0 +1,10 @@
1
+ /**
2
+ * State of the WebSocket connection.
3
+ * https://developer.mozilla.org/de/docs/Web/API/WebSocket/readyState
4
+ */
5
+ export declare enum WsReadyStates {
6
+ Connecting = 0,
7
+ Open = 1,
8
+ Closing = 2,
9
+ Closed = 3
10
+ }
@@ -1,20 +1,16 @@
1
- /// <reference types="node" />
2
- import { Extension, onChangePayload, onLoadDocumentPayload } from '@hocuspocus/server';
1
+ import { Extension, onChangePayload, onLoadDocumentPayload, storePayload } from '@hocuspocus/server';
3
2
  export interface DatabaseConfiguration {
4
3
  /**
5
4
  * Pass a Promise to retrieve updates from your database. The Promise should resolve to
6
5
  * an array of items with Y.js-compatible binary data.
7
6
  */
8
- fetchUpdates: ({ documentName }: {
7
+ fetch: ({ documentName }: {
9
8
  documentName: string;
10
- }) => Promise<Uint8Array[]>;
9
+ }) => Promise<Uint8Array | null>;
11
10
  /**
12
11
  * Pass a function to store updates in your database.
13
12
  */
14
- storeUpdate: ({ update, documentName }: {
15
- update: Buffer;
16
- documentName: string;
17
- }) => void;
13
+ store: (data: storePayload) => void;
18
14
  }
19
15
  export declare class Database implements Extension {
20
16
  /**
@@ -32,5 +28,5 @@ export declare class Database implements Extension {
32
28
  /**
33
29
  * Store new updates in the database.
34
30
  */
35
- onChange({ document, documentName }: onChangePayload): Promise<void>;
31
+ onStoreDocument(data: onChangePayload): Promise<void>;
36
32
  }
@@ -14,6 +14,10 @@ export interface LoggerConfiguration {
14
14
  * Whether to log something for the `onChange` hook.
15
15
  */
16
16
  onChange: boolean;
17
+ /**
18
+ * Whether to log something for the `onStoreDocument` hook.
19
+ */
20
+ onStoreDocument: boolean;
17
21
  /**
18
22
  * Whether to log something for the `onConnect` hook.
19
23
  */
@@ -53,6 +57,7 @@ export declare class Logger implements Extension {
53
57
  onConfigure(data: onConfigurePayload): Promise<void>;
54
58
  onLoadDocument(data: onLoadDocumentPayload): Promise<void>;
55
59
  onChange(data: onChangePayload): Promise<void>;
60
+ onStoreDocument(data: onDisconnectPayload): Promise<void>;
56
61
  onConnect(data: onConnectPayload): Promise<void>;
57
62
  onDisconnect(data: onDisconnectPayload): Promise<void>;
58
63
  onUpgrade(data: onUpgradePayload): Promise<void>;
@@ -3,7 +3,6 @@ import { Configuration, onConnectPayload, onDisconnectPayload, onLoadDocumentPay
3
3
  export declare class Collector {
4
4
  serverConfiguration: Partial<Configuration>;
5
5
  version: string;
6
- yjsVersion: string;
7
6
  connections: {};
8
7
  messages: {};
9
8
  messageCounter: number;
@@ -56,7 +55,6 @@ export declare class Collector {
56
55
  platform: NodeJS.Platform;
57
56
  started: string;
58
57
  version: string;
59
- yjsVersion: string;
60
58
  }>;
61
59
  private static readableYDoc;
62
60
  }
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { Extension, onChangePayload, onConfigurePayload, onConnectPayload, onLoadDocumentPayload, onDisconnectPayload, onRequestPayload, onUpgradePayload } from '@hocuspocus/server';
2
+ import { Extension, onChangePayload, onConfigurePayload, onLoadDocumentPayload, onDisconnectPayload, onRequestPayload, onUpgradePayload, connectedPayload } from '@hocuspocus/server';
3
3
  import { IncomingMessage, ServerResponse } from 'http';
4
4
  import WebSocket from 'ws';
5
5
  import { Storage } from './Storage';
@@ -30,7 +30,7 @@ export declare class Monitor implements Extension {
30
30
  handleConnection(websocket: WebSocket, request: IncomingMessage): void | undefined;
31
31
  onRequest({ request, response }: onRequestPayload): Promise<void>;
32
32
  onUpgrade({ request, socket, head }: onUpgradePayload): Promise<void>;
33
- onConnect(data: onConnectPayload): Promise<void>;
33
+ connected(data: connectedPayload): Promise<void>;
34
34
  onDisconnect(data: onDisconnectPayload): Promise<void>;
35
35
  onLoadDocument(data: onLoadDocumentPayload): Promise<void>;
36
36
  onChange(data: onChangePayload): Promise<void>;
@@ -1,5 +1,8 @@
1
1
  import { Database, DatabaseConfiguration } from '@hocuspocus/extension-database';
2
2
  import sqlite3 from 'sqlite3';
3
+ export declare const schema = "CREATE TABLE IF NOT EXISTS \"documents\" (\n \"name\" varchar(255) NOT NULL,\n \"data\" blob NOT NULL,\n UNIQUE(name)\n)";
4
+ export declare const selectQuery = "\n SELECT data FROM \"documents\" WHERE name = $name ORDER BY rowid DESC\n";
5
+ export declare const upsertQuery = "\n INSERT INTO \"documents\" (\"name\", \"data\") VALUES ($name, $data)\n ON CONFLICT(name) DO UPDATE SET data = $data\n";
3
6
  export interface SQLiteConfiguration extends DatabaseConfiguration {
4
7
  /**
5
8
  * Valid values are filenames, ":memory:" for an anonymous in-memory database and an empty
@@ -17,10 +20,7 @@ export interface SQLiteConfiguration extends DatabaseConfiguration {
17
20
  export declare class SQLite extends Database {
18
21
  db?: sqlite3.Database;
19
22
  configuration: SQLiteConfiguration;
20
- /**
21
- * Constructor
22
- */
23
23
  constructor(configuration?: Partial<SQLiteConfiguration>);
24
- onListen(): Promise<void>;
25
24
  onConfigure(): Promise<void>;
25
+ onListen(): Promise<void>;
26
26
  }
@@ -1,12 +1,16 @@
1
1
  import { Extension, onConnectPayload } from '@hocuspocus/server';
2
- export interface Configuration {
2
+ export interface ThrottleConfiguration {
3
3
  throttle: number | null | false;
4
4
  banTime: number;
5
5
  }
6
6
  export declare class Throttle implements Extension {
7
- configuration: Configuration;
7
+ configuration: ThrottleConfiguration;
8
8
  connectionsByIp: Map<string, Array<number>>;
9
9
  bannedIps: Map<string, number>;
10
+ /**
11
+ * Constructor
12
+ */
13
+ constructor(configuration?: Partial<ThrottleConfiguration>);
10
14
  /**
11
15
  * Throttle requests
12
16
  * @private
@@ -3,7 +3,6 @@ import { Extension, onChangePayload, onConnectPayload, onLoadDocumentPayload, on
3
3
  import { Doc } from 'yjs';
4
4
  import { Transformer } from '@hocuspocus/transformer';
5
5
  import { AxiosResponse } from 'axios';
6
- import Timeout = NodeJS.Timeout;
7
6
  export declare enum Events {
8
7
  onChange = "change",
9
8
  onConnect = "connect",
@@ -24,7 +23,7 @@ export interface Configuration {
24
23
  export declare class Webhook implements Extension {
25
24
  configuration: Configuration;
26
25
  debounced: Map<string, {
27
- timeout: Timeout;
26
+ timeout: NodeJS.Timeout;
28
27
  start: number;
29
28
  }>;
30
29
  /**
@@ -5,5 +5,5 @@ export default class EventEmitter {
5
5
  on(event: string, fn: Function): this;
6
6
  protected emit(event: string, ...args: any): this;
7
7
  off(event: string, fn?: Function): this;
8
- protected removeAllListeners(): void;
8
+ removeAllListeners(): void;
9
9
  }
@@ -1,10 +1,11 @@
1
- import { HocuspocusProvider, HocuspocusProviderOptions } from './HocuspocusProvider';
2
- export interface HocuspocusCloudProviderOptions extends HocuspocusProviderOptions {
1
+ import { HocuspocusProvider, HocuspocusProviderConfiguration } from './HocuspocusProvider';
2
+ export declare type HocuspocusCloudProviderConfiguration = Required<Pick<HocuspocusProviderConfiguration, 'name'>> & Partial<HocuspocusProviderConfiguration> & AdditionalHocuspocusCloudProviderConfiguration;
3
+ export interface AdditionalHocuspocusCloudProviderConfiguration {
3
4
  /**
4
5
  * A Hocuspocus Cloud key, get one here: https://hocuspocus.cloud/
5
6
  */
6
7
  key: string;
7
8
  }
8
9
  export declare class HocuspocusCloudProvider extends HocuspocusProvider {
9
- constructor(options: HocuspocusCloudProviderOptions);
10
+ constructor(configuration: HocuspocusCloudProviderConfiguration);
10
11
  }
@@ -1,16 +1,12 @@
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 { Event, CloseEvent, MessageEvent } from 'ws';
4
+ import type { Event, CloseEvent, MessageEvent } from 'ws';
5
5
  import EventEmitter from './EventEmitter';
6
- import { OutgoingMessage } from './OutgoingMessage';
7
- import { ConstructableOutgoingMessage } from './types';
8
- export declare enum WebSocketStatus {
9
- Connecting = "connecting",
10
- Connected = "connected",
11
- Disconnected = "disconnected"
12
- }
13
- export interface HocuspocusProviderOptions {
6
+ import { ConstructableOutgoingMessage, onAuthenticationFailedParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatusParameters, onSyncedParameters, WebSocketStatus } from './types';
7
+ import { onAwarenessChangeParameters, onAwarenessUpdateParameters } from '.';
8
+ export declare type HocuspocusProviderConfiguration = Required<Pick<CompleteHocuspocusProviderConfiguration, 'url' | 'name'>> & Partial<CompleteHocuspocusProviderConfiguration>;
9
+ export interface CompleteHocuspocusProviderConfiguration {
14
10
  /**
15
11
  * URL of your @hocuspocus/server instance
16
12
  */
@@ -90,23 +86,25 @@ export interface HocuspocusProviderOptions {
90
86
  */
91
87
  timeout: number;
92
88
  onAuthenticated: () => void;
93
- onAuthenticationFailed: ({ reason }: {
94
- reason: string;
95
- }) => void;
96
- onOpen: (event: Event) => void;
89
+ onAuthenticationFailed: (data: onAuthenticationFailedParameters) => void;
90
+ onOpen: (data: onOpenParameters) => void;
97
91
  onConnect: () => void;
98
- onMessage: (event: MessageEvent) => void;
99
- onOutgoingMessage: (message: OutgoingMessage) => void;
100
- onStatus: (status: any) => void;
101
- onSynced: () => void;
102
- onDisconnect: (event: CloseEvent) => void;
103
- onClose: (event: CloseEvent) => void;
92
+ onMessage: (data: onMessageParameters) => void;
93
+ onOutgoingMessage: (data: onOutgoingMessageParameters) => void;
94
+ onStatus: (data: onStatusParameters) => void;
95
+ onSynced: (data: onSyncedParameters) => void;
96
+ onDisconnect: (data: onDisconnectParameters) => void;
97
+ onClose: (data: onCloseParameters) => void;
104
98
  onDestroy: () => void;
105
- onAwarenessUpdate: (states: any) => void;
106
- onAwarenessChange: (states: any) => void;
99
+ onAwarenessUpdate: (data: onAwarenessUpdateParameters) => void;
100
+ onAwarenessChange: (data: onAwarenessChangeParameters) => void;
101
+ /**
102
+ * Don’t output any warnings.
103
+ */
104
+ quiet: boolean;
107
105
  }
108
106
  export declare class HocuspocusProvider extends EventEmitter {
109
- options: HocuspocusProviderOptions;
107
+ configuration: CompleteHocuspocusProviderConfiguration;
110
108
  subscribedToBroadcastChannel: boolean;
111
109
  webSocket: WebSocket | null;
112
110
  shouldConnect: boolean;
@@ -120,11 +118,12 @@ export declare class HocuspocusProvider extends EventEmitter {
120
118
  resolve: (value?: any) => void;
121
119
  reject: (reason?: any) => void;
122
120
  } | null;
123
- constructor(options?: Partial<HocuspocusProviderOptions>);
124
- setOptions(options?: Partial<HocuspocusProviderOptions>): void;
121
+ constructor(configuration: HocuspocusProviderConfiguration);
122
+ setConfiguration(configuration?: Partial<HocuspocusProviderConfiguration>): void;
125
123
  connect(): Promise<void>;
126
124
  createWebSocketConnection(): Promise<unknown>;
127
125
  resolveConnectionAttempt(): void;
126
+ stopConnectionAttempt(): void;
128
127
  rejectConnectionAttempt(): void;
129
128
  get document(): Y.Doc;
130
129
  get awareness(): Awareness;
@@ -141,9 +140,8 @@ export declare class HocuspocusProvider extends EventEmitter {
141
140
  set synced(state: boolean);
142
141
  get isAuthenticationRequired(): boolean;
143
142
  disconnect(): void;
144
- onOpen(event: Event): void;
143
+ onOpen(event: Event): Promise<void>;
145
144
  getToken(): Promise<string | null>;
146
- webSocketConnectionEstablished(): Promise<void>;
147
145
  startSync(): void;
148
146
  send(Message: ConstructableOutgoingMessage, args: any, broadcast?: boolean): void;
149
147
  onMessage(event: MessageEvent): void;
@@ -1,4 +1,3 @@
1
1
  export * from './HocuspocusProvider';
2
2
  export * from './HocuspocusCloudProvider';
3
3
  export * from './types';
4
- export * from './utils';
@@ -1,18 +1,26 @@
1
1
  import { Awareness } from 'y-protocols/awareness';
2
2
  import * as Y from 'yjs';
3
3
  import { Encoder } from 'lib0/encoding';
4
+ import type { Event, CloseEvent, MessageEvent } from 'ws';
4
5
  import { AuthenticationMessage } from './OutgoingMessages/AuthenticationMessage';
5
6
  import { AwarenessMessage } from './OutgoingMessages/AwarenessMessage';
6
7
  import { QueryAwarenessMessage } from './OutgoingMessages/QueryAwarenessMessage';
7
8
  import { SyncStepOneMessage } from './OutgoingMessages/SyncStepOneMessage';
8
9
  import { SyncStepTwoMessage } from './OutgoingMessages/SyncStepTwoMessage';
9
10
  import { UpdateMessage } from './OutgoingMessages/UpdateMessage';
11
+ import { IncomingMessage } from './IncomingMessage';
12
+ import { OutgoingMessage } from './OutgoingMessage';
10
13
  export declare enum MessageType {
11
14
  Sync = 0,
12
15
  Awareness = 1,
13
16
  Auth = 2,
14
17
  QueryAwareness = 3
15
18
  }
19
+ export declare enum WebSocketStatus {
20
+ Connecting = "connecting",
21
+ Connected = "connected",
22
+ Disconnected = "disconnected"
23
+ }
16
24
  export interface OutgoingMessageInterface {
17
25
  encoder: Encoder;
18
26
  type?: MessageType;
@@ -32,3 +40,38 @@ export interface Constructable<T> {
32
40
  new (...args: any): T;
33
41
  }
34
42
  export declare type ConstructableOutgoingMessage = Constructable<AuthenticationMessage> | Constructable<AwarenessMessage> | Constructable<QueryAwarenessMessage> | Constructable<SyncStepOneMessage> | Constructable<SyncStepTwoMessage> | Constructable<UpdateMessage>;
43
+ export declare type onAuthenticationFailedParameters = {
44
+ reason: string;
45
+ };
46
+ export declare type onOpenParameters = {
47
+ event: Event;
48
+ };
49
+ export declare type onMessageParameters = {
50
+ event: MessageEvent;
51
+ message: IncomingMessage;
52
+ };
53
+ export declare type onOutgoingMessageParameters = {
54
+ message: OutgoingMessage;
55
+ };
56
+ export declare type onStatusParameters = {
57
+ status: WebSocketStatus;
58
+ };
59
+ export declare type onSyncedParameters = {
60
+ state: boolean;
61
+ };
62
+ export declare type onDisconnectParameters = {
63
+ event: CloseEvent;
64
+ };
65
+ export declare type onCloseParameters = {
66
+ event: CloseEvent;
67
+ };
68
+ export declare type onAwarenessUpdateParameters = {
69
+ states: StatesArray;
70
+ };
71
+ export declare type onAwarenessChangeParameters = {
72
+ states: StatesArray;
73
+ };
74
+ export declare type StatesArray = {
75
+ clientId: number;
76
+ [key: string | number]: any;
77
+ }[];
@@ -2,10 +2,10 @@
2
2
  import AsyncLock from 'async-lock';
3
3
  import WebSocket from 'ws';
4
4
  import { IncomingMessage as HTTPIncomingMessage } from 'http';
5
+ import { CloseEvent } from '@hocuspocus/common';
5
6
  import Document from './Document';
6
- import { CloseEvent } from './types';
7
- import { MessageLogger } from './Debugger';
8
- declare class Connection {
7
+ import { Debugger } from './Debugger';
8
+ export declare class Connection {
9
9
  webSocket: WebSocket;
10
10
  context: any;
11
11
  document: Document;
@@ -17,11 +17,11 @@ declare class Connection {
17
17
  socketId: string;
18
18
  lock: AsyncLock;
19
19
  readOnly: Boolean;
20
- debugger: MessageLogger;
20
+ logger: Debugger;
21
21
  /**
22
22
  * Constructor.
23
23
  */
24
- constructor(connection: WebSocket, request: HTTPIncomingMessage, document: Document, timeout: number, socketId: string, context: any, readOnly?: boolean);
24
+ constructor(connection: WebSocket, request: HTTPIncomingMessage, document: Document, timeout: number, socketId: string, context: any, readOnly: boolean | undefined, logger: Debugger);
25
25
  /**
26
26
  * Set a callback that will be triggered when the connection is closed
27
27
  */
@@ -1,4 +1,4 @@
1
- export declare class MessageLogger {
1
+ export declare class Debugger {
2
2
  logs: any[];
3
3
  listen: boolean;
4
4
  output: boolean;
@@ -12,4 +12,3 @@ export declare class MessageLogger {
12
12
  logs: any[];
13
13
  };
14
14
  }
15
- export declare const Debugger: MessageLogger;
@@ -3,20 +3,23 @@ import { Awareness } from 'y-protocols/awareness';
3
3
  import { Doc } from 'yjs';
4
4
  import { mutex } from 'lib0/mutex.js';
5
5
  import Connection from './Connection';
6
- import { MessageLogger } from './Debugger';
7
- declare class Document extends Doc {
6
+ import { Debugger } from './Debugger';
7
+ export declare class Document extends Doc {
8
8
  awareness: Awareness;
9
9
  callbacks: {
10
10
  onUpdate: (document: Document, connection: Connection, update: Uint8Array) => void;
11
11
  };
12
- connections: Map<any, any>;
12
+ connections: Map<WebSocket, {
13
+ clients: Set<any>;
14
+ connection: Connection;
15
+ }>;
13
16
  name: string;
14
17
  mux: mutex;
15
- debugger: MessageLogger;
18
+ logger: Debugger;
16
19
  /**
17
20
  * Constructor.
18
21
  */
19
- constructor(name: string);
22
+ constructor(name: string, logger: Debugger);
20
23
  /**
21
24
  * Check if the Document is empty
22
25
  */