@hocuspocus/extension-database 3.4.4 → 3.4.5-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 (142) hide show
  1. package/dist/hocuspocus-database.cjs +63 -58
  2. package/dist/hocuspocus-database.cjs.map +1 -1
  3. package/dist/hocuspocus-database.esm.js +35 -38
  4. package/dist/hocuspocus-database.esm.js.map +1 -1
  5. package/dist/index.d.ts +34 -0
  6. package/dist/index.js +37 -0
  7. package/package.json +4 -4
  8. package/dist/node_modules/@tiptap/pm/model/index.d.ts +0 -1
  9. package/dist/node_modules/@tiptap/pm/state/index.d.ts +0 -1
  10. package/dist/node_modules/@tiptap/pm/transform/index.d.ts +0 -1
  11. package/dist/node_modules/@tiptap/pm/view/index.d.ts +0 -1
  12. package/dist/packages/common/src/CloseEvents.d.ts +0 -29
  13. package/dist/packages/common/src/auth.d.ts +0 -13
  14. package/dist/packages/common/src/awarenessStatesToArray.d.ts +0 -3
  15. package/dist/packages/common/src/index.d.ts +0 -4
  16. package/dist/packages/common/src/types.d.ts +0 -10
  17. package/dist/packages/extension-database/src/Database.d.ts +0 -30
  18. package/dist/packages/extension-database/src/index.d.ts +0 -1
  19. package/dist/packages/extension-logger/src/Logger.d.ts +0 -67
  20. package/dist/packages/extension-logger/src/index.d.ts +0 -1
  21. package/dist/packages/extension-redis/src/Redis.d.ts +0 -124
  22. package/dist/packages/extension-redis/src/index.d.ts +0 -1
  23. package/dist/packages/extension-s3/src/S3.d.ts +0 -44
  24. package/dist/packages/extension-s3/src/index.d.ts +0 -1
  25. package/dist/packages/extension-sqlite/src/SQLite.d.ts +0 -27
  26. package/dist/packages/extension-sqlite/src/index.d.ts +0 -1
  27. package/dist/packages/extension-throttle/src/index.d.ts +0 -30
  28. package/dist/packages/extension-webhook/src/index.d.ts +0 -56
  29. package/dist/packages/provider/src/EventEmitter.d.ts +0 -9
  30. package/dist/packages/provider/src/HocuspocusProvider.d.ts +0 -116
  31. package/dist/packages/provider/src/HocuspocusProviderWebsocket.d.ts +0 -119
  32. package/dist/packages/provider/src/IncomingMessage.d.ts +0 -17
  33. package/dist/packages/provider/src/MessageReceiver.d.ts +0 -12
  34. package/dist/packages/provider/src/MessageSender.d.ts +0 -9
  35. package/dist/packages/provider/src/OutgoingMessage.d.ts +0 -9
  36. package/dist/packages/provider/src/OutgoingMessages/AuthenticationMessage.d.ts +0 -8
  37. package/dist/packages/provider/src/OutgoingMessages/AwarenessMessage.d.ts +0 -9
  38. package/dist/packages/provider/src/OutgoingMessages/CloseMessage.d.ts +0 -9
  39. package/dist/packages/provider/src/OutgoingMessages/QueryAwarenessMessage.d.ts +0 -9
  40. package/dist/packages/provider/src/OutgoingMessages/StatelessMessage.d.ts +0 -8
  41. package/dist/packages/provider/src/OutgoingMessages/SyncStepOneMessage.d.ts +0 -9
  42. package/dist/packages/provider/src/OutgoingMessages/SyncStepTwoMessage.d.ts +0 -9
  43. package/dist/packages/provider/src/OutgoingMessages/UpdateMessage.d.ts +0 -8
  44. package/dist/packages/provider/src/index.d.ts +0 -3
  45. package/dist/packages/provider/src/types.d.ts +0 -93
  46. package/dist/packages/server/src/ClientConnection.d.ts +0 -63
  47. package/dist/packages/server/src/Connection.d.ts +0 -75
  48. package/dist/packages/server/src/DirectConnection.d.ts +0 -14
  49. package/dist/packages/server/src/Document.d.ts +0 -92
  50. package/dist/packages/server/src/Hocuspocus.d.ts +0 -80
  51. package/dist/packages/server/src/IncomingMessage.d.ts +0 -25
  52. package/dist/packages/server/src/MessageReceiver.d.ts +0 -11
  53. package/dist/packages/server/src/OutgoingMessage.d.ts +0 -23
  54. package/dist/packages/server/src/Server.d.ts +0 -32
  55. package/dist/packages/server/src/index.d.ts +0 -9
  56. package/dist/packages/server/src/types.d.ts +0 -342
  57. package/dist/packages/server/src/util/debounce.d.ts +0 -6
  58. package/dist/packages/server/src/util/getParameters.d.ts +0 -6
  59. package/dist/packages/transformer/src/Prosemirror.d.ts +0 -11
  60. package/dist/packages/transformer/src/Tiptap.d.ts +0 -10
  61. package/dist/packages/transformer/src/index.d.ts +0 -3
  62. package/dist/packages/transformer/src/types.d.ts +0 -5
  63. package/dist/playground/backend/src/default.d.ts +0 -1
  64. package/dist/playground/backend/src/deno.d.ts +0 -1
  65. package/dist/playground/backend/src/express.d.ts +0 -1
  66. package/dist/playground/backend/src/hono.d.ts +0 -1
  67. package/dist/playground/backend/src/koa.d.ts +0 -1
  68. package/dist/playground/backend/src/load-document.d.ts +0 -1
  69. package/dist/playground/backend/src/redis.d.ts +0 -1
  70. package/dist/playground/backend/src/s3-redis.d.ts +0 -1
  71. package/dist/playground/backend/src/s3.d.ts +0 -1
  72. package/dist/playground/backend/src/slow.d.ts +0 -1
  73. package/dist/playground/backend/src/tiptapcollab.d.ts +0 -1
  74. package/dist/playground/backend/src/webhook.d.ts +0 -1
  75. package/dist/playground/frontend/app/SocketContext1.d.ts +0 -2
  76. package/dist/playground/frontend/app/SocketContext2.d.ts +0 -2
  77. package/dist/playground/frontend/next.config.d.ts +0 -3
  78. package/dist/tests/extension-database/fetch.d.ts +0 -1
  79. package/dist/tests/extension-logger/onListen.d.ts +0 -1
  80. package/dist/tests/extension-redis/onAwarenessChange.d.ts +0 -1
  81. package/dist/tests/extension-redis/onChange.d.ts +0 -1
  82. package/dist/tests/extension-redis/onStateless.d.ts +0 -1
  83. package/dist/tests/extension-redis/onStoreDocument.d.ts +0 -1
  84. package/dist/tests/extension-s3/fetch.d.ts +0 -1
  85. package/dist/tests/extension-throttle/banning.d.ts +0 -1
  86. package/dist/tests/extension-throttle/configuration.d.ts +0 -1
  87. package/dist/tests/provider/hasUnsyncedChanges.d.ts +0 -1
  88. package/dist/tests/provider/observe.d.ts +0 -1
  89. package/dist/tests/provider/observeDeep.d.ts +0 -1
  90. package/dist/tests/provider/onAuthenticated.d.ts +0 -1
  91. package/dist/tests/provider/onAuthenticationFailed.d.ts +0 -1
  92. package/dist/tests/provider/onAwarenessChange.d.ts +0 -1
  93. package/dist/tests/provider/onAwarenessUpdate.d.ts +0 -1
  94. package/dist/tests/provider/onClose.d.ts +0 -1
  95. package/dist/tests/provider/onConnect.d.ts +0 -1
  96. package/dist/tests/provider/onDisconnect.d.ts +0 -1
  97. package/dist/tests/provider/onMessage.d.ts +0 -1
  98. package/dist/tests/provider/onOpen.d.ts +0 -1
  99. package/dist/tests/provider/onStateless.d.ts +0 -1
  100. package/dist/tests/provider/onSynced.d.ts +0 -1
  101. package/dist/tests/providerwebsocket/configuration.d.ts +0 -1
  102. package/dist/tests/server/address.d.ts +0 -1
  103. package/dist/tests/server/afterLoadDocument.d.ts +0 -1
  104. package/dist/tests/server/afterStoreDocument.d.ts +0 -1
  105. package/dist/tests/server/afterUnloadDocument.d.ts +0 -1
  106. package/dist/tests/server/beforeBroadcastStateless.d.ts +0 -1
  107. package/dist/tests/server/beforeHandleMessage.d.ts +0 -1
  108. package/dist/tests/server/beforeSync.d.ts +0 -1
  109. package/dist/tests/server/beforeUnloadDocument.d.ts +0 -1
  110. package/dist/tests/server/closeConnections.d.ts +0 -1
  111. package/dist/tests/server/getConnectionsCount.d.ts +0 -1
  112. package/dist/tests/server/getDocumentsCount.d.ts +0 -1
  113. package/dist/tests/server/listen.d.ts +0 -1
  114. package/dist/tests/server/onAuthenticate.d.ts +0 -1
  115. package/dist/tests/server/onAwarenessUpdate.d.ts +0 -1
  116. package/dist/tests/server/onChange.d.ts +0 -1
  117. package/dist/tests/server/onClose.d.ts +0 -1
  118. package/dist/tests/server/onConfigure.d.ts +0 -1
  119. package/dist/tests/server/onConnect.d.ts +0 -1
  120. package/dist/tests/server/onDestroy.d.ts +0 -1
  121. package/dist/tests/server/onDisconnect.d.ts +0 -1
  122. package/dist/tests/server/onListen.d.ts +0 -1
  123. package/dist/tests/server/onLoadDocument.d.ts +0 -1
  124. package/dist/tests/server/onRequest.d.ts +0 -1
  125. package/dist/tests/server/onStateless.d.ts +0 -1
  126. package/dist/tests/server/onStoreDocument.d.ts +0 -1
  127. package/dist/tests/server/onTokenSync.d.ts +0 -1
  128. package/dist/tests/server/onUpgrade.d.ts +0 -1
  129. package/dist/tests/server/openDirectConnection.d.ts +0 -1
  130. package/dist/tests/server/websocketError.d.ts +0 -1
  131. package/dist/tests/transformer/TiptapTransformer.d.ts +0 -1
  132. package/dist/tests/utils/createDirectory.d.ts +0 -1
  133. package/dist/tests/utils/flushRedis.d.ts +0 -1
  134. package/dist/tests/utils/index.d.ts +0 -9
  135. package/dist/tests/utils/newHocuspocus.d.ts +0 -2
  136. package/dist/tests/utils/newHocuspocusProvider.d.ts +0 -3
  137. package/dist/tests/utils/newHocuspocusProviderWebsocket.d.ts +0 -4
  138. package/dist/tests/utils/randomInteger.d.ts +0 -1
  139. package/dist/tests/utils/redisConnectionSettings.d.ts +0 -4
  140. package/dist/tests/utils/removeDirectory.d.ts +0 -1
  141. package/dist/tests/utils/retryableAssertion.d.ts +0 -2
  142. package/dist/tests/utils/sleep.d.ts +0 -1
@@ -1,62 +1,67 @@
1
- 'use strict';
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ //#region \0rolldown/runtime.js
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
+ key = keys[i];
13
+ if (!__hasOwnProp.call(to, key) && key !== except) {
14
+ __defProp(to, key, {
15
+ get: ((k) => from[k]).bind(null, key),
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ }
20
+ }
21
+ return to;
22
+ };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
24
+ value: mod,
25
+ enumerable: true
26
+ }) : target, mod));
2
27
 
3
- var Y = require('yjs');
28
+ //#endregion
29
+ let yjs = require("yjs");
30
+ yjs = __toESM(yjs);
4
31
 
5
- function _interopNamespaceDefault(e) {
6
- var n = Object.create(null);
7
- if (e) {
8
- Object.keys(e).forEach(function (k) {
9
- if (k !== 'default') {
10
- var d = Object.getOwnPropertyDescriptor(e, k);
11
- Object.defineProperty(n, k, d.get ? d : {
12
- enumerable: true,
13
- get: function () { return e[k]; }
14
- });
15
- }
16
- });
17
- }
18
- n.default = e;
19
- return Object.freeze(n);
20
- }
21
-
22
- var Y__namespace = /*#__PURE__*/_interopNamespaceDefault(Y);
23
-
24
- class Database {
25
- /**
26
- * Constructor
27
- */
28
- constructor(configuration) {
29
- /**
30
- * Default configuration
31
- */
32
- this.configuration = {
33
- fetch: async () => null,
34
- store: async () => { },
35
- };
36
- this.configuration = {
37
- ...this.configuration,
38
- ...configuration,
39
- };
40
- }
41
- /**
42
- * Get stored data from the database.
43
- */
44
- async onLoadDocument(data) {
45
- const update = await this.configuration.fetch(data);
46
- if (update) {
47
- Y__namespace.applyUpdate(data.document, update);
48
- }
49
- }
50
- /**
51
- * Store new updates in the database.
52
- */
53
- async onStoreDocument(data) {
54
- await this.configuration.store({
55
- ...data,
56
- state: Buffer.from(Y__namespace.encodeStateAsUpdate(data.document)),
57
- });
58
- }
59
- }
32
+ //#region packages/extension-database/src/Database.ts
33
+ var Database = class {
34
+ /**
35
+ * Constructor
36
+ */
37
+ constructor(configuration) {
38
+ this.configuration = {
39
+ fetch: async () => null,
40
+ store: async () => {}
41
+ };
42
+ this.configuration = {
43
+ ...this.configuration,
44
+ ...configuration
45
+ };
46
+ }
47
+ /**
48
+ * Get stored data from the database.
49
+ */
50
+ async onLoadDocument(data) {
51
+ const update = await this.configuration.fetch(data);
52
+ if (update) yjs.applyUpdate(data.document, update);
53
+ }
54
+ /**
55
+ * Store new updates in the database.
56
+ */
57
+ async onStoreDocument(data) {
58
+ await this.configuration.store({
59
+ ...data,
60
+ state: Buffer.from(yjs.encodeStateAsUpdate(data.document))
61
+ });
62
+ }
63
+ };
60
64
 
65
+ //#endregion
61
66
  exports.Database = Database;
62
- //# sourceMappingURL=hocuspocus-database.cjs.map
67
+ //# sourceMappingURL=hocuspocus-database.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"hocuspocus-database.cjs","sources":["../src/Database.ts"],"sourcesContent":[null],"names":["Y"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;MAqBa,QAAQ,CAAA;AASpB;;AAEG;AACH,IAAA,WAAA,CAAY,aAA6C,EAAA;AAXzD;;AAEG;AACH,QAAA,IAAA,CAAA,aAAa,GAA0B;AACtC,YAAA,KAAK,EAAE,YAAY,IAAI;AACvB,YAAA,KAAK,EAAE,eAAc;SACrB;QAMA,IAAI,CAAC,aAAa,GAAG;YACpB,GAAG,IAAI,CAAC,aAAa;AACrB,YAAA,GAAG,aAAa;SAChB;;AAGF;;AAEG;IACH,MAAM,cAAc,CAAC,IAA2B,EAAA;QAC/C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC;QAEnD,IAAI,MAAM,EAAE;YACXA,YAAC,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC;;;AAItC;;AAEG;IACH,MAAM,eAAe,CAAC,IAAqB,EAAA;AAC1C,QAAA,MAAM,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC;AAC9B,YAAA,GAAG,IAAI;AACP,YAAA,KAAK,EAAE,MAAM,CAAC,IAAI,CAACA,YAAC,CAAC,mBAAmB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACxD,SAAA,CAAC;;AAEH;;;;"}
1
+ {"version":3,"file":"hocuspocus-database.cjs","names":["Y"],"sources":["../src/Database.ts"],"sourcesContent":["import type {\n\tExtension,\n\tonChangePayload,\n\tonLoadDocumentPayload,\n\tstorePayload,\n\tfetchPayload,\n} from \"@hocuspocus/server\";\nimport * as Y from \"yjs\";\n\nexport interface DatabaseConfiguration {\n\t/**\n\t * Pass a Promise to retrieve updates from your database. The Promise should resolve to\n\t * an array of items with Y.js-compatible binary data.\n\t */\n\tfetch: (data: fetchPayload) => Promise<Uint8Array | null>;\n\t/**\n\t * Pass a function to store updates in your database.\n\t */\n\tstore: (data: storePayload) => Promise<void>;\n}\n\nexport class Database implements Extension {\n\t/**\n\t * Default configuration\n\t */\n\tconfiguration: DatabaseConfiguration = {\n\t\tfetch: async () => null,\n\t\tstore: async () => {},\n\t};\n\n\t/**\n\t * Constructor\n\t */\n\tconstructor(configuration: Partial<DatabaseConfiguration>) {\n\t\tthis.configuration = {\n\t\t\t...this.configuration,\n\t\t\t...configuration,\n\t\t};\n\t}\n\n\t/**\n\t * Get stored data from the database.\n\t */\n\tasync onLoadDocument(data: onLoadDocumentPayload): Promise<any> {\n\t\tconst update = await this.configuration.fetch(data);\n\n\t\tif (update) {\n\t\t\tY.applyUpdate(data.document, update);\n\t\t}\n\t}\n\n\t/**\n\t * Store new updates in the database.\n\t */\n\tasync onStoreDocument(data: onChangePayload) {\n\t\tawait this.configuration.store({\n\t\t\t...data,\n\t\t\tstate: Buffer.from(Y.encodeStateAsUpdate(data.document)),\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,IAAa,WAAb,MAA2C;;;;CAY1C,YAAY,eAA+C;uBARpB;GACtC,OAAO,YAAY;GACnB,OAAO,YAAY;GACnB;AAMA,OAAK,gBAAgB;GACpB,GAAG,KAAK;GACR,GAAG;GACH;;;;;CAMF,MAAM,eAAe,MAA2C;EAC/D,MAAM,SAAS,MAAM,KAAK,cAAc,MAAM,KAAK;AAEnD,MAAI,OACH,KAAE,YAAY,KAAK,UAAU,OAAO;;;;;CAOtC,MAAM,gBAAgB,MAAuB;AAC5C,QAAM,KAAK,cAAc,MAAM;GAC9B,GAAG;GACH,OAAO,OAAO,KAAKA,IAAE,oBAAoB,KAAK,SAAS,CAAC;GACxD,CAAC"}
@@ -1,41 +1,38 @@
1
- import * as Y from 'yjs';
1
+ import * as Y from "yjs";
2
2
 
3
- class Database {
4
- /**
5
- * Constructor
6
- */
7
- constructor(configuration) {
8
- /**
9
- * Default configuration
10
- */
11
- this.configuration = {
12
- fetch: async () => null,
13
- store: async () => { },
14
- };
15
- this.configuration = {
16
- ...this.configuration,
17
- ...configuration,
18
- };
19
- }
20
- /**
21
- * Get stored data from the database.
22
- */
23
- async onLoadDocument(data) {
24
- const update = await this.configuration.fetch(data);
25
- if (update) {
26
- Y.applyUpdate(data.document, update);
27
- }
28
- }
29
- /**
30
- * Store new updates in the database.
31
- */
32
- async onStoreDocument(data) {
33
- await this.configuration.store({
34
- ...data,
35
- state: Buffer.from(Y.encodeStateAsUpdate(data.document)),
36
- });
37
- }
38
- }
3
+ //#region packages/extension-database/src/Database.ts
4
+ var Database = class {
5
+ /**
6
+ * Constructor
7
+ */
8
+ constructor(configuration) {
9
+ this.configuration = {
10
+ fetch: async () => null,
11
+ store: async () => {}
12
+ };
13
+ this.configuration = {
14
+ ...this.configuration,
15
+ ...configuration
16
+ };
17
+ }
18
+ /**
19
+ * Get stored data from the database.
20
+ */
21
+ async onLoadDocument(data) {
22
+ const update = await this.configuration.fetch(data);
23
+ if (update) Y.applyUpdate(data.document, update);
24
+ }
25
+ /**
26
+ * Store new updates in the database.
27
+ */
28
+ async onStoreDocument(data) {
29
+ await this.configuration.store({
30
+ ...data,
31
+ state: Buffer.from(Y.encodeStateAsUpdate(data.document))
32
+ });
33
+ }
34
+ };
39
35
 
36
+ //#endregion
40
37
  export { Database };
41
- //# sourceMappingURL=hocuspocus-database.esm.js.map
38
+ //# sourceMappingURL=hocuspocus-database.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hocuspocus-database.esm.js","sources":["../src/Database.ts"],"sourcesContent":[null],"names":[],"mappings":";;MAqBa,QAAQ,CAAA;AASpB;;AAEG;AACH,IAAA,WAAA,CAAY,aAA6C,EAAA;AAXzD;;AAEG;AACH,QAAA,IAAA,CAAA,aAAa,GAA0B;AACtC,YAAA,KAAK,EAAE,YAAY,IAAI;AACvB,YAAA,KAAK,EAAE,eAAc;SACrB;QAMA,IAAI,CAAC,aAAa,GAAG;YACpB,GAAG,IAAI,CAAC,aAAa;AACrB,YAAA,GAAG,aAAa;SAChB;;AAGF;;AAEG;IACH,MAAM,cAAc,CAAC,IAA2B,EAAA;QAC/C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC;QAEnD,IAAI,MAAM,EAAE;YACX,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC;;;AAItC;;AAEG;IACH,MAAM,eAAe,CAAC,IAAqB,EAAA;AAC1C,QAAA,MAAM,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC;AAC9B,YAAA,GAAG,IAAI;AACP,YAAA,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,mBAAmB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACxD,SAAA,CAAC;;AAEH;;;;"}
1
+ {"version":3,"file":"hocuspocus-database.esm.js","names":[],"sources":["../src/Database.ts"],"sourcesContent":["import type {\n\tExtension,\n\tonChangePayload,\n\tonLoadDocumentPayload,\n\tstorePayload,\n\tfetchPayload,\n} from \"@hocuspocus/server\";\nimport * as Y from \"yjs\";\n\nexport interface DatabaseConfiguration {\n\t/**\n\t * Pass a Promise to retrieve updates from your database. The Promise should resolve to\n\t * an array of items with Y.js-compatible binary data.\n\t */\n\tfetch: (data: fetchPayload) => Promise<Uint8Array | null>;\n\t/**\n\t * Pass a function to store updates in your database.\n\t */\n\tstore: (data: storePayload) => Promise<void>;\n}\n\nexport class Database implements Extension {\n\t/**\n\t * Default configuration\n\t */\n\tconfiguration: DatabaseConfiguration = {\n\t\tfetch: async () => null,\n\t\tstore: async () => {},\n\t};\n\n\t/**\n\t * Constructor\n\t */\n\tconstructor(configuration: Partial<DatabaseConfiguration>) {\n\t\tthis.configuration = {\n\t\t\t...this.configuration,\n\t\t\t...configuration,\n\t\t};\n\t}\n\n\t/**\n\t * Get stored data from the database.\n\t */\n\tasync onLoadDocument(data: onLoadDocumentPayload): Promise<any> {\n\t\tconst update = await this.configuration.fetch(data);\n\n\t\tif (update) {\n\t\t\tY.applyUpdate(data.document, update);\n\t\t}\n\t}\n\n\t/**\n\t * Store new updates in the database.\n\t */\n\tasync onStoreDocument(data: onChangePayload) {\n\t\tawait this.configuration.store({\n\t\t\t...data,\n\t\t\tstate: Buffer.from(Y.encodeStateAsUpdate(data.document)),\n\t\t});\n\t}\n}\n"],"mappings":";;;AAqBA,IAAa,WAAb,MAA2C;;;;CAY1C,YAAY,eAA+C;uBARpB;GACtC,OAAO,YAAY;GACnB,OAAO,YAAY;GACnB;AAMA,OAAK,gBAAgB;GACpB,GAAG,KAAK;GACR,GAAG;GACH;;;;;CAMF,MAAM,eAAe,MAA2C;EAC/D,MAAM,SAAS,MAAM,KAAK,cAAc,MAAM,KAAK;AAEnD,MAAI,OACH,GAAE,YAAY,KAAK,UAAU,OAAO;;;;;CAOtC,MAAM,gBAAgB,MAAuB;AAC5C,QAAM,KAAK,cAAc,MAAM;GAC9B,GAAG;GACH,OAAO,OAAO,KAAK,EAAE,oBAAoB,KAAK,SAAS,CAAC;GACxD,CAAC"}
@@ -0,0 +1,34 @@
1
+ import { Extension, fetchPayload, onChangePayload, onLoadDocumentPayload, storePayload } from "@hocuspocus/server";
2
+
3
+ //#region packages/extension-database/src/Database.d.ts
4
+ interface DatabaseConfiguration {
5
+ /**
6
+ * Pass a Promise to retrieve updates from your database. The Promise should resolve to
7
+ * an array of items with Y.js-compatible binary data.
8
+ */
9
+ fetch: (data: fetchPayload) => Promise<Uint8Array | null>;
10
+ /**
11
+ * Pass a function to store updates in your database.
12
+ */
13
+ store: (data: storePayload) => Promise<void>;
14
+ }
15
+ declare class Database implements Extension {
16
+ /**
17
+ * Default configuration
18
+ */
19
+ configuration: DatabaseConfiguration;
20
+ /**
21
+ * Constructor
22
+ */
23
+ constructor(configuration: Partial<DatabaseConfiguration>);
24
+ /**
25
+ * Get stored data from the database.
26
+ */
27
+ onLoadDocument(data: onLoadDocumentPayload): Promise<any>;
28
+ /**
29
+ * Store new updates in the database.
30
+ */
31
+ onStoreDocument(data: onChangePayload): Promise<void>;
32
+ }
33
+ //#endregion
34
+ export { Database, DatabaseConfiguration };
package/dist/index.js ADDED
@@ -0,0 +1,37 @@
1
+ import * as Y from "yjs";
2
+
3
+ //#region packages/extension-database/src/Database.ts
4
+ var Database = class {
5
+ /**
6
+ * Constructor
7
+ */
8
+ constructor(configuration) {
9
+ this.configuration = {
10
+ fetch: async () => null,
11
+ store: async () => {}
12
+ };
13
+ this.configuration = {
14
+ ...this.configuration,
15
+ ...configuration
16
+ };
17
+ }
18
+ /**
19
+ * Get stored data from the database.
20
+ */
21
+ async onLoadDocument(data) {
22
+ const update = await this.configuration.fetch(data);
23
+ if (update) Y.applyUpdate(data.document, update);
24
+ }
25
+ /**
26
+ * Store new updates in the database.
27
+ */
28
+ async onStoreDocument(data) {
29
+ await this.configuration.store({
30
+ ...data,
31
+ state: Buffer.from(Y.encodeStateAsUpdate(data.document))
32
+ });
33
+ }
34
+ };
35
+
36
+ //#endregion
37
+ export { Database };
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.4.4",
4
+ "version": "3.4.5-rc.0",
5
5
  "homepage": "https://hocuspocus.dev",
6
6
  "keywords": [
7
7
  "hocuspocus",
@@ -11,7 +11,7 @@
11
11
  "type": "module",
12
12
  "main": "dist/hocuspocus-database.cjs",
13
13
  "module": "dist/hocuspocus-database.esm.js",
14
- "types": "dist/packages/extension-database/src/index.d.ts",
14
+ "types": "dist/index.d.ts",
15
15
  "exports": {
16
16
  "source": {
17
17
  "import": "./src/index.ts"
@@ -19,7 +19,7 @@
19
19
  "default": {
20
20
  "import": "./dist/hocuspocus-database.esm.js",
21
21
  "require": "./dist/hocuspocus-database.cjs",
22
- "types": "./dist/packages/extension-database/src/index.d.ts"
22
+ "types": "./dist/index.d.ts"
23
23
  }
24
24
  },
25
25
  "files": [
@@ -27,7 +27,7 @@
27
27
  "dist"
28
28
  ],
29
29
  "dependencies": {
30
- "@hocuspocus/server": "^3.4.4"
30
+ "@hocuspocus/server": "^3.4.5-rc.0"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "yjs": "^13.6.8"
@@ -1 +0,0 @@
1
- export * from 'prosemirror-model';
@@ -1 +0,0 @@
1
- export * from 'prosemirror-state';
@@ -1 +0,0 @@
1
- export * from 'prosemirror-transform';
@@ -1 +0,0 @@
1
- export * from 'prosemirror-view';
@@ -1,29 +0,0 @@
1
- export interface CloseEvent {
2
- code: number;
3
- reason: string;
4
- }
5
- /**
6
- * The server is terminating the connection because a data frame was received
7
- * that is too large.
8
- * See: https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code
9
- */
10
- export declare const MessageTooBig: CloseEvent;
11
- /**
12
- * The server successfully processed the request, asks that the requester reset
13
- * its document view, and is not returning any content.
14
- */
15
- export declare const ResetConnection: CloseEvent;
16
- /**
17
- * Similar to Forbidden, but specifically for use when authentication is required and has
18
- * failed or has not yet been provided.
19
- */
20
- export declare const Unauthorized: CloseEvent;
21
- /**
22
- * The request contained valid data and was understood by the server, but the server
23
- * is refusing action.
24
- */
25
- export declare const Forbidden: CloseEvent;
26
- /**
27
- * The server timed out waiting for the request.
28
- */
29
- export declare const ConnectionTimeout: CloseEvent;
@@ -1,13 +0,0 @@
1
- import * as encoding from "lib0/encoding";
2
- import * as decoding from "lib0/decoding";
3
- import type { AuthorizedScope } from "../../provider/src";
4
- export declare enum AuthMessageType {
5
- Token = 0,
6
- PermissionDenied = 1,
7
- Authenticated = 2
8
- }
9
- export declare const writeAuthentication: (encoder: encoding.Encoder, auth: string) => void;
10
- export declare const writePermissionDenied: (encoder: encoding.Encoder, reason: string) => void;
11
- export declare const writeAuthenticated: (encoder: encoding.Encoder, scope: AuthorizedScope) => void;
12
- export declare const writeTokenSyncRequest: (encoder: encoding.Encoder) => void;
13
- export declare const readAuthMessage: (decoder: decoding.Decoder, sendToken: () => void, permissionDeniedHandler: (reason: string) => void, authenticatedHandler: (scope: string) => void) => void;
@@ -1,3 +0,0 @@
1
- export declare const awarenessStatesToArray: (states: Map<number, Record<string, any>>) => {
2
- clientId: number;
3
- }[];
@@ -1,4 +0,0 @@
1
- export * from "./auth.ts";
2
- export * from "./CloseEvents.ts";
3
- export * from "./awarenessStatesToArray.ts";
4
- export * from "./types.ts";
@@ -1,10 +0,0 @@
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,30 +0,0 @@
1
- import type { Extension, onChangePayload, onLoadDocumentPayload, storePayload, fetchPayload } from "@hocuspocus/server";
2
- export interface DatabaseConfiguration {
3
- /**
4
- * Pass a Promise to retrieve updates from your database. The Promise should resolve to
5
- * an array of items with Y.js-compatible binary data.
6
- */
7
- fetch: (data: fetchPayload) => Promise<Uint8Array | null>;
8
- /**
9
- * Pass a function to store updates in your database.
10
- */
11
- store: (data: storePayload) => Promise<void>;
12
- }
13
- export declare class Database implements Extension {
14
- /**
15
- * Default configuration
16
- */
17
- configuration: DatabaseConfiguration;
18
- /**
19
- * Constructor
20
- */
21
- constructor(configuration: Partial<DatabaseConfiguration>);
22
- /**
23
- * Get stored data from the database.
24
- */
25
- onLoadDocument(data: onLoadDocumentPayload): Promise<any>;
26
- /**
27
- * Store new updates in the database.
28
- */
29
- onStoreDocument(data: onChangePayload): Promise<void>;
30
- }
@@ -1 +0,0 @@
1
- export * from "./Database.ts";
@@ -1,67 +0,0 @@
1
- import type { Extension, onChangePayload, onConfigurePayload, onConnectPayload, onLoadDocumentPayload, onDestroyPayload, onDisconnectPayload, onRequestPayload, onUpgradePayload } from "@hocuspocus/server";
2
- export interface LoggerConfiguration {
3
- /**
4
- * Prepend all logging message with a string.
5
- *
6
- * @deprecated
7
- */
8
- prefix: null | string;
9
- /**
10
- * Whether to log something for the `onLoadDocument` hook.
11
- */
12
- onLoadDocument: boolean;
13
- /**
14
- * Whether to log something for the `onChange` hook.
15
- */
16
- onChange: boolean;
17
- /**
18
- * Whether to log something for the `onStoreDocument` hook.
19
- */
20
- onStoreDocument: boolean;
21
- /**
22
- * Whether to log something for the `onConnect` hook.
23
- */
24
- onConnect: boolean;
25
- /**
26
- * Whether to log something for the `onDisconnect` hook.
27
- */
28
- onDisconnect: boolean;
29
- /**
30
- * Whether to log something for the `onUpgrade` hook.
31
- */
32
- onUpgrade: boolean;
33
- /**
34
- * Whether to log something for the `onRequest` hook.
35
- */
36
- onRequest: boolean;
37
- /**
38
- * Whether to log something for the `onDestroy` hook.
39
- */
40
- onDestroy: boolean;
41
- /**
42
- * Whether to log something for the `onConfigure` hook.
43
- */
44
- onConfigure: boolean;
45
- /**
46
- * A log function, if none is provided output will go to console
47
- */
48
- log: (...args: any[]) => void;
49
- }
50
- export declare class Logger implements Extension {
51
- name: string | null;
52
- configuration: LoggerConfiguration;
53
- /**
54
- * Constructor
55
- */
56
- constructor(configuration?: Partial<LoggerConfiguration>);
57
- onConfigure(data: onConfigurePayload): Promise<void>;
58
- onLoadDocument(data: onLoadDocumentPayload): Promise<void>;
59
- onChange(data: onChangePayload): Promise<void>;
60
- onStoreDocument(data: onDisconnectPayload): Promise<void>;
61
- onConnect(data: onConnectPayload): Promise<void>;
62
- onDisconnect(data: onDisconnectPayload): Promise<void>;
63
- onUpgrade(data: onUpgradePayload): Promise<void>;
64
- onRequest(data: onRequestPayload): Promise<void>;
65
- onDestroy(data: onDestroyPayload): Promise<void>;
66
- private log;
67
- }
@@ -1 +0,0 @@
1
- export * from "./Logger.ts";
@@ -1,124 +0,0 @@
1
- import type { Extension, Hocuspocus, afterLoadDocumentPayload, afterStoreDocumentPayload, afterUnloadDocumentPayload, beforeBroadcastStatelessPayload, beforeUnloadDocumentPayload, onAwarenessUpdatePayload, onChangePayload, onConfigurePayload, onStoreDocumentPayload } from "@hocuspocus/server";
2
- import { type ExecutionResult, type Lock, Redlock } from "@sesamecare-oss/redlock";
3
- import type { Cluster, ClusterNode, ClusterOptions, RedisOptions } from "ioredis";
4
- import RedisClient from "ioredis";
5
- export type RedisInstance = RedisClient | Cluster;
6
- export interface Configuration {
7
- /**
8
- * Redis port
9
- */
10
- port: number;
11
- /**
12
- * Redis host
13
- */
14
- host: string;
15
- /**
16
- * Redis Cluster
17
- */
18
- nodes?: ClusterNode[];
19
- /**
20
- * Duplicate from an existed Redis instance
21
- */
22
- redis?: RedisInstance;
23
- /**
24
- * Redis instance creator
25
- */
26
- createClient?: () => RedisInstance;
27
- /**
28
- * Options passed directly to Redis constructor
29
- *
30
- * https://github.com/luin/ioredis/blob/master/API.md#new-redisport-host-options
31
- */
32
- options?: ClusterOptions | RedisOptions;
33
- /**
34
- * An unique instance name, required to filter messages in Redis.
35
- * If none is provided an unique id is generated.
36
- */
37
- identifier: string;
38
- /**
39
- * Namespace for Redis keys, if none is provided 'hocuspocus' is used
40
- */
41
- prefix: string;
42
- /**
43
- * The maximum time for the Redis lock in ms (in case it can’t be released).
44
- */
45
- lockTimeout: number;
46
- /**
47
- * A delay before onDisconnect is executed. This allows last minute updates'
48
- * sync messages to be received by the subscription before it's closed.
49
- */
50
- disconnectDelay: number;
51
- }
52
- export declare class Redis implements Extension {
53
- /**
54
- * Make sure to give that extension a higher priority, so
55
- * the `onStoreDocument` hook is able to intercept the chain,
56
- * before documents are stored to the database.
57
- */
58
- priority: number;
59
- configuration: Configuration;
60
- redisTransactionOrigin: string;
61
- pub: RedisInstance;
62
- sub: RedisInstance;
63
- instance: Hocuspocus;
64
- redlock: Redlock;
65
- locks: Map<string, {
66
- lock: Lock;
67
- release?: Promise<ExecutionResult>;
68
- }>;
69
- messagePrefix: Buffer;
70
- private pendingAfterStoreDocumentResolves;
71
- constructor(configuration: Partial<Configuration>);
72
- onConfigure({ instance }: onConfigurePayload): Promise<void>;
73
- private getKey;
74
- private pubKey;
75
- private subKey;
76
- private lockKey;
77
- private encodeMessage;
78
- private decodeMessage;
79
- /**
80
- * Once a document is loaded, subscribe to the channel in Redis.
81
- */
82
- afterLoadDocument({ documentName, document, }: afterLoadDocumentPayload): Promise<unknown>;
83
- /**
84
- * Publish the first sync step through Redis.
85
- */
86
- private publishFirstSyncStep;
87
- /**
88
- * Let’s ask Redis who is connected already.
89
- */
90
- private requestAwarenessFromOtherInstances;
91
- /**
92
- * Before the document is stored, make sure to set a lock in Redis.
93
- * That’s meant to avoid conflicts with other instances trying to store the document.
94
- */
95
- onStoreDocument({ documentName }: onStoreDocumentPayload): Promise<void>;
96
- /**
97
- * Release the Redis lock, so other instances can store documents.
98
- */
99
- afterStoreDocument({ documentName, socketId, }: afterStoreDocumentPayload): Promise<void>;
100
- /**
101
- * Handle awareness update messages received directly by this Hocuspocus instance.
102
- */
103
- onAwarenessUpdate({ documentName, awareness, added, updated, removed, document, }: onAwarenessUpdatePayload): Promise<number | undefined>;
104
- /**
105
- * Handle incoming messages published on subscribed document channels.
106
- * Note that this will also include messages from ourselves as it is not possible
107
- * in Redis to filter these.
108
- */
109
- private handleIncomingMessage;
110
- /**
111
- * if the ydoc changed, we'll need to inform other Hocuspocus servers about it.
112
- */
113
- onChange(data: onChangePayload): Promise<any>;
114
- /**
115
- * Delay unloading to allow syncs to finish
116
- */
117
- beforeUnloadDocument(data: beforeUnloadDocumentPayload): Promise<void>;
118
- afterUnloadDocument(data: afterUnloadDocumentPayload): Promise<void>;
119
- beforeBroadcastStateless(data: beforeBroadcastStatelessPayload): Promise<number>;
120
- /**
121
- * Kill the Redlock connection immediately.
122
- */
123
- onDestroy(): Promise<void>;
124
- }
@@ -1 +0,0 @@
1
- export * from "./Redis.ts";