@hocuspocus/common 3.4.3 → 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 (143) hide show
  1. package/dist/hocuspocus-common.cjs +443 -425
  2. package/dist/hocuspocus-common.cjs.map +1 -1
  3. package/dist/hocuspocus-common.esm.js +440 -424
  4. package/dist/hocuspocus-common.esm.js.map +1 -1
  5. package/dist/index.d.ts +100 -0
  6. package/dist/index.js +524 -0
  7. package/package.json +3 -3
  8. package/src/auth.ts +2 -1
  9. package/dist/node_modules/@tiptap/pm/model/index.d.ts +0 -1
  10. package/dist/node_modules/@tiptap/pm/state/index.d.ts +0 -1
  11. package/dist/node_modules/@tiptap/pm/transform/index.d.ts +0 -1
  12. package/dist/node_modules/@tiptap/pm/view/index.d.ts +0 -1
  13. package/dist/packages/common/src/CloseEvents.d.ts +0 -29
  14. package/dist/packages/common/src/auth.d.ts +0 -12
  15. package/dist/packages/common/src/awarenessStatesToArray.d.ts +0 -3
  16. package/dist/packages/common/src/index.d.ts +0 -4
  17. package/dist/packages/common/src/types.d.ts +0 -10
  18. package/dist/packages/extension-database/src/Database.d.ts +0 -30
  19. package/dist/packages/extension-database/src/index.d.ts +0 -1
  20. package/dist/packages/extension-logger/src/Logger.d.ts +0 -67
  21. package/dist/packages/extension-logger/src/index.d.ts +0 -1
  22. package/dist/packages/extension-redis/src/Redis.d.ts +0 -124
  23. package/dist/packages/extension-redis/src/index.d.ts +0 -1
  24. package/dist/packages/extension-s3/src/S3.d.ts +0 -44
  25. package/dist/packages/extension-s3/src/index.d.ts +0 -1
  26. package/dist/packages/extension-sqlite/src/SQLite.d.ts +0 -27
  27. package/dist/packages/extension-sqlite/src/index.d.ts +0 -1
  28. package/dist/packages/extension-throttle/src/index.d.ts +0 -30
  29. package/dist/packages/extension-webhook/src/index.d.ts +0 -56
  30. package/dist/packages/provider/src/EventEmitter.d.ts +0 -9
  31. package/dist/packages/provider/src/HocuspocusProvider.d.ts +0 -116
  32. package/dist/packages/provider/src/HocuspocusProviderWebsocket.d.ts +0 -114
  33. package/dist/packages/provider/src/IncomingMessage.d.ts +0 -17
  34. package/dist/packages/provider/src/MessageReceiver.d.ts +0 -12
  35. package/dist/packages/provider/src/MessageSender.d.ts +0 -9
  36. package/dist/packages/provider/src/OutgoingMessage.d.ts +0 -9
  37. package/dist/packages/provider/src/OutgoingMessages/AuthenticationMessage.d.ts +0 -8
  38. package/dist/packages/provider/src/OutgoingMessages/AwarenessMessage.d.ts +0 -9
  39. package/dist/packages/provider/src/OutgoingMessages/CloseMessage.d.ts +0 -9
  40. package/dist/packages/provider/src/OutgoingMessages/QueryAwarenessMessage.d.ts +0 -9
  41. package/dist/packages/provider/src/OutgoingMessages/StatelessMessage.d.ts +0 -8
  42. package/dist/packages/provider/src/OutgoingMessages/SyncStepOneMessage.d.ts +0 -9
  43. package/dist/packages/provider/src/OutgoingMessages/SyncStepTwoMessage.d.ts +0 -9
  44. package/dist/packages/provider/src/OutgoingMessages/UpdateMessage.d.ts +0 -8
  45. package/dist/packages/provider/src/index.d.ts +0 -3
  46. package/dist/packages/provider/src/types.d.ts +0 -92
  47. package/dist/packages/server/src/ClientConnection.d.ts +0 -63
  48. package/dist/packages/server/src/Connection.d.ts +0 -71
  49. package/dist/packages/server/src/DirectConnection.d.ts +0 -14
  50. package/dist/packages/server/src/Document.d.ts +0 -92
  51. package/dist/packages/server/src/Hocuspocus.d.ts +0 -80
  52. package/dist/packages/server/src/IncomingMessage.d.ts +0 -25
  53. package/dist/packages/server/src/MessageReceiver.d.ts +0 -11
  54. package/dist/packages/server/src/OutgoingMessage.d.ts +0 -23
  55. package/dist/packages/server/src/Server.d.ts +0 -32
  56. package/dist/packages/server/src/index.d.ts +0 -9
  57. package/dist/packages/server/src/types.d.ts +0 -342
  58. package/dist/packages/server/src/util/debounce.d.ts +0 -6
  59. package/dist/packages/server/src/util/getParameters.d.ts +0 -6
  60. package/dist/packages/transformer/src/Prosemirror.d.ts +0 -11
  61. package/dist/packages/transformer/src/Tiptap.d.ts +0 -10
  62. package/dist/packages/transformer/src/index.d.ts +0 -3
  63. package/dist/packages/transformer/src/types.d.ts +0 -5
  64. package/dist/playground/backend/src/default.d.ts +0 -1
  65. package/dist/playground/backend/src/deno.d.ts +0 -1
  66. package/dist/playground/backend/src/express.d.ts +0 -1
  67. package/dist/playground/backend/src/hono.d.ts +0 -1
  68. package/dist/playground/backend/src/koa.d.ts +0 -1
  69. package/dist/playground/backend/src/load-document.d.ts +0 -1
  70. package/dist/playground/backend/src/redis.d.ts +0 -1
  71. package/dist/playground/backend/src/s3-redis.d.ts +0 -1
  72. package/dist/playground/backend/src/s3.d.ts +0 -1
  73. package/dist/playground/backend/src/slow.d.ts +0 -1
  74. package/dist/playground/backend/src/tiptapcollab.d.ts +0 -1
  75. package/dist/playground/backend/src/webhook.d.ts +0 -1
  76. package/dist/playground/frontend/app/SocketContext1.d.ts +0 -2
  77. package/dist/playground/frontend/app/SocketContext2.d.ts +0 -2
  78. package/dist/playground/frontend/next.config.d.ts +0 -3
  79. package/dist/tests/extension-database/fetch.d.ts +0 -1
  80. package/dist/tests/extension-logger/onListen.d.ts +0 -1
  81. package/dist/tests/extension-redis/onAwarenessChange.d.ts +0 -1
  82. package/dist/tests/extension-redis/onChange.d.ts +0 -1
  83. package/dist/tests/extension-redis/onStateless.d.ts +0 -1
  84. package/dist/tests/extension-redis/onStoreDocument.d.ts +0 -1
  85. package/dist/tests/extension-s3/fetch.d.ts +0 -1
  86. package/dist/tests/extension-throttle/banning.d.ts +0 -1
  87. package/dist/tests/extension-throttle/configuration.d.ts +0 -1
  88. package/dist/tests/provider/hasUnsyncedChanges.d.ts +0 -1
  89. package/dist/tests/provider/observe.d.ts +0 -1
  90. package/dist/tests/provider/observeDeep.d.ts +0 -1
  91. package/dist/tests/provider/onAuthenticated.d.ts +0 -1
  92. package/dist/tests/provider/onAuthenticationFailed.d.ts +0 -1
  93. package/dist/tests/provider/onAwarenessChange.d.ts +0 -1
  94. package/dist/tests/provider/onAwarenessUpdate.d.ts +0 -1
  95. package/dist/tests/provider/onClose.d.ts +0 -1
  96. package/dist/tests/provider/onConnect.d.ts +0 -1
  97. package/dist/tests/provider/onDisconnect.d.ts +0 -1
  98. package/dist/tests/provider/onMessage.d.ts +0 -1
  99. package/dist/tests/provider/onOpen.d.ts +0 -1
  100. package/dist/tests/provider/onStateless.d.ts +0 -1
  101. package/dist/tests/provider/onSynced.d.ts +0 -1
  102. package/dist/tests/providerwebsocket/configuration.d.ts +0 -1
  103. package/dist/tests/server/address.d.ts +0 -1
  104. package/dist/tests/server/afterLoadDocument.d.ts +0 -1
  105. package/dist/tests/server/afterStoreDocument.d.ts +0 -1
  106. package/dist/tests/server/afterUnloadDocument.d.ts +0 -1
  107. package/dist/tests/server/beforeBroadcastStateless.d.ts +0 -1
  108. package/dist/tests/server/beforeHandleMessage.d.ts +0 -1
  109. package/dist/tests/server/beforeSync.d.ts +0 -1
  110. package/dist/tests/server/beforeUnloadDocument.d.ts +0 -1
  111. package/dist/tests/server/closeConnections.d.ts +0 -1
  112. package/dist/tests/server/getConnectionsCount.d.ts +0 -1
  113. package/dist/tests/server/getDocumentsCount.d.ts +0 -1
  114. package/dist/tests/server/listen.d.ts +0 -1
  115. package/dist/tests/server/onAuthenticate.d.ts +0 -1
  116. package/dist/tests/server/onAwarenessUpdate.d.ts +0 -1
  117. package/dist/tests/server/onChange.d.ts +0 -1
  118. package/dist/tests/server/onClose.d.ts +0 -1
  119. package/dist/tests/server/onConfigure.d.ts +0 -1
  120. package/dist/tests/server/onConnect.d.ts +0 -1
  121. package/dist/tests/server/onDestroy.d.ts +0 -1
  122. package/dist/tests/server/onDisconnect.d.ts +0 -1
  123. package/dist/tests/server/onListen.d.ts +0 -1
  124. package/dist/tests/server/onLoadDocument.d.ts +0 -1
  125. package/dist/tests/server/onRequest.d.ts +0 -1
  126. package/dist/tests/server/onStateless.d.ts +0 -1
  127. package/dist/tests/server/onStoreDocument.d.ts +0 -1
  128. package/dist/tests/server/onTokenSync.d.ts +0 -1
  129. package/dist/tests/server/onUpgrade.d.ts +0 -1
  130. package/dist/tests/server/openDirectConnection.d.ts +0 -1
  131. package/dist/tests/server/websocketError.d.ts +0 -1
  132. package/dist/tests/transformer/TiptapTransformer.d.ts +0 -1
  133. package/dist/tests/utils/createDirectory.d.ts +0 -1
  134. package/dist/tests/utils/flushRedis.d.ts +0 -1
  135. package/dist/tests/utils/index.d.ts +0 -9
  136. package/dist/tests/utils/newHocuspocus.d.ts +0 -2
  137. package/dist/tests/utils/newHocuspocusProvider.d.ts +0 -3
  138. package/dist/tests/utils/newHocuspocusProviderWebsocket.d.ts +0 -4
  139. package/dist/tests/utils/randomInteger.d.ts +0 -1
  140. package/dist/tests/utils/redisConnectionSettings.d.ts +0 -4
  141. package/dist/tests/utils/removeDirectory.d.ts +0 -1
  142. package/dist/tests/utils/retryableAssertion.d.ts +0 -2
  143. package/dist/tests/utils/sleep.d.ts +0 -1
@@ -1,509 +1,525 @@
1
+ //#region node_modules/lib0/math.js
1
2
  /**
2
- * Common Math expressions.
3
- *
4
- * @module math
5
- */
6
-
3
+ * Common Math expressions.
4
+ *
5
+ * @module math
6
+ */
7
7
  const floor = Math.floor;
8
-
9
8
  /**
10
- * @function
11
- * @param {number} a
12
- * @param {number} b
13
- * @return {number} The smaller element of a and b
14
- */
9
+ * @function
10
+ * @param {number} a
11
+ * @param {number} b
12
+ * @return {number} The smaller element of a and b
13
+ */
15
14
  const min = (a, b) => a < b ? a : b;
16
-
17
15
  /**
18
- * @function
19
- * @param {number} a
20
- * @param {number} b
21
- * @return {number} The bigger element of a and b
22
- */
16
+ * @function
17
+ * @param {number} a
18
+ * @param {number} b
19
+ * @return {number} The bigger element of a and b
20
+ */
23
21
  const max = (a, b) => a > b ? a : b;
22
+ const isNaN$1 = Number.isNaN;
24
23
 
25
- /* eslint-env browser */
26
-
24
+ //#endregion
25
+ //#region node_modules/lib0/binary.js
27
26
  const BIT8 = 128;
27
+ const BIT18 = 1 << 17;
28
+ const BIT19 = 1 << 18;
29
+ const BIT20 = 1 << 19;
30
+ const BIT21 = 1 << 20;
31
+ const BIT22 = 1 << 21;
32
+ const BIT23 = 1 << 22;
33
+ const BIT24 = 1 << 23;
34
+ const BIT25 = 1 << 24;
35
+ const BIT26 = 1 << 25;
36
+ const BIT27 = 1 << 26;
37
+ const BIT28 = 1 << 27;
38
+ const BIT29 = 1 << 28;
39
+ const BIT30 = 1 << 29;
40
+ const BIT31 = 1 << 30;
41
+ const BIT32 = 1 << 31;
28
42
  const BITS7 = 127;
29
-
30
- /**
31
- * Utility helpers for working with numbers.
32
- *
33
- * @module number
34
- */
35
-
36
-
43
+ const BITS17 = BIT18 - 1;
44
+ const BITS18 = BIT19 - 1;
45
+ const BITS19 = BIT20 - 1;
46
+ const BITS20 = BIT21 - 1;
47
+ const BITS21 = BIT22 - 1;
48
+ const BITS22 = BIT23 - 1;
49
+ const BITS23 = BIT24 - 1;
50
+ const BITS24 = BIT25 - 1;
51
+ const BITS25 = BIT26 - 1;
52
+ const BITS26 = BIT27 - 1;
53
+ const BITS27 = BIT28 - 1;
54
+ const BITS28 = BIT29 - 1;
55
+ const BITS29 = BIT30 - 1;
56
+ const BITS30 = BIT31 - 1;
57
+ /**
58
+ * @type {number}
59
+ */
60
+ const BITS31 = 2147483647;
61
+ /**
62
+ * @type {number}
63
+ */
64
+ const BITS32 = 4294967295;
65
+
66
+ //#endregion
67
+ //#region node_modules/lib0/number.js
68
+ /**
69
+ * Utility helpers for working with numbers.
70
+ *
71
+ * @module number
72
+ */
37
73
  const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER;
38
-
39
- /**
40
- * @param {string} str
41
- * @return {Uint8Array}
42
- */
43
- const _encodeUtf8Polyfill = str => {
44
- const encodedString = unescape(encodeURIComponent(str));
45
- const len = encodedString.length;
46
- const buf = new Uint8Array(len);
47
- for (let i = 0; i < len; i++) {
48
- buf[i] = /** @type {number} */ (encodedString.codePointAt(i));
49
- }
50
- return buf
74
+ const MIN_SAFE_INTEGER = Number.MIN_SAFE_INTEGER;
75
+ const LOWEST_INT32 = 1 << 31;
76
+ const HIGHEST_INT32 = BITS31;
77
+ const HIGHEST_UINT32 = BITS32;
78
+ /* c8 ignore next */
79
+ const isInteger = Number.isInteger || ((num) => typeof num === "number" && isFinite(num) && floor(num) === num);
80
+ const isNaN = Number.isNaN;
81
+ const parseInt = Number.parseInt;
82
+
83
+ //#endregion
84
+ //#region node_modules/lib0/string.js
85
+ /**
86
+ * Utility module to work with strings.
87
+ *
88
+ * @module string
89
+ */
90
+ const fromCharCode = String.fromCharCode;
91
+ const fromCodePoint = String.fromCodePoint;
92
+ /**
93
+ * The largest utf16 character.
94
+ * Corresponds to Uint8Array([255, 255]) or charcodeof(2x2^8)
95
+ */
96
+ const MAX_UTF16_CHARACTER = fromCharCode(65535);
97
+ /**
98
+ * @param {string} str
99
+ * @return {Uint8Array}
100
+ */
101
+ const _encodeUtf8Polyfill = (str) => {
102
+ const encodedString = unescape(encodeURIComponent(str));
103
+ const len = encodedString.length;
104
+ const buf = new Uint8Array(len);
105
+ for (let i = 0; i < len; i++) buf[i] = encodedString.codePointAt(i);
106
+ return buf;
51
107
  };
52
-
53
108
  /* c8 ignore next */
54
- const utf8TextEncoder = /** @type {TextEncoder} */ (typeof TextEncoder !== 'undefined' ? new TextEncoder() : null);
55
-
109
+ const utf8TextEncoder = typeof TextEncoder !== "undefined" ? new TextEncoder() : null;
56
110
  /**
57
- * @param {string} str
58
- * @return {Uint8Array}
59
- */
60
- const _encodeUtf8Native = str => utf8TextEncoder.encode(str);
61
-
111
+ * @param {string} str
112
+ * @return {Uint8Array}
113
+ */
114
+ const _encodeUtf8Native = (str) => utf8TextEncoder.encode(str);
62
115
  /**
63
- * @param {string} str
64
- * @return {Uint8Array}
65
- */
116
+ * @param {string} str
117
+ * @return {Uint8Array}
118
+ */
66
119
  /* c8 ignore next */
67
120
  const encodeUtf8 = utf8TextEncoder ? _encodeUtf8Native : _encodeUtf8Polyfill;
68
-
69
121
  /* c8 ignore next */
70
- let utf8TextDecoder = typeof TextDecoder === 'undefined' ? null : new TextDecoder('utf-8', { fatal: true, ignoreBOM: true });
71
-
122
+ let utf8TextDecoder = typeof TextDecoder === "undefined" ? null : new TextDecoder("utf-8", {
123
+ fatal: true,
124
+ ignoreBOM: true
125
+ });
72
126
  /* c8 ignore start */
73
- if (utf8TextDecoder && utf8TextDecoder.decode(new Uint8Array()).length === 1) {
74
- // Safari doesn't handle BOM correctly.
75
- // This fixes a bug in Safari 13.0.5 where it produces a BOM the first time it is called.
76
- // utf8TextDecoder.decode(new Uint8Array()).length === 1 on the first call and
77
- // utf8TextDecoder.decode(new Uint8Array()).length === 1 on the second call
78
- // Another issue is that from then on no BOM chars are recognized anymore
79
- /* c8 ignore next */
80
- utf8TextDecoder = null;
81
- }
82
-
83
- /**
84
- * Efficient schema-less binary encoding with support for variable length encoding.
85
- *
86
- * Use [lib0/encoding] with [lib0/decoding]. Every encoding function has a corresponding decoding function.
87
- *
88
- * Encodes numbers in little-endian order (least to most significant byte order)
89
- * and is compatible with Golang's binary encoding (https://golang.org/pkg/encoding/binary/)
90
- * which is also used in Protocol Buffers.
91
- *
92
- * ```js
93
- * // encoding step
94
- * const encoder = encoding.createEncoder()
95
- * encoding.writeVarUint(encoder, 256)
96
- * encoding.writeVarString(encoder, 'Hello world!')
97
- * const buf = encoding.toUint8Array(encoder)
98
- * ```
99
- *
100
- * ```js
101
- * // decoding step
102
- * const decoder = decoding.createDecoder(buf)
103
- * decoding.readVarUint(decoder) // => 256
104
- * decoding.readVarString(decoder) // => 'Hello world!'
105
- * decoding.hasContent(decoder) // => false - all data is read
106
- * ```
107
- *
108
- * @module encoding
109
- */
110
-
111
-
112
- /**
113
- * Write one byte to the encoder.
114
- *
115
- * @function
116
- * @param {Encoder} encoder
117
- * @param {number} num The byte that is to be encoded.
118
- */
127
+ if (utf8TextDecoder && utf8TextDecoder.decode(new Uint8Array()).length === 1)
128
+ /* c8 ignore next */
129
+ utf8TextDecoder = null;
130
+
131
+ //#endregion
132
+ //#region node_modules/lib0/encoding.js
133
+ /**
134
+ * Efficient schema-less binary encoding with support for variable length encoding.
135
+ *
136
+ * Use [lib0/encoding] with [lib0/decoding]. Every encoding function has a corresponding decoding function.
137
+ *
138
+ * Encodes numbers in little-endian order (least to most significant byte order)
139
+ * and is compatible with Golang's binary encoding (https://golang.org/pkg/encoding/binary/)
140
+ * which is also used in Protocol Buffers.
141
+ *
142
+ * ```js
143
+ * // encoding step
144
+ * const encoder = encoding.createEncoder()
145
+ * encoding.writeVarUint(encoder, 256)
146
+ * encoding.writeVarString(encoder, 'Hello world!')
147
+ * const buf = encoding.toUint8Array(encoder)
148
+ * ```
149
+ *
150
+ * ```js
151
+ * // decoding step
152
+ * const decoder = decoding.createDecoder(buf)
153
+ * decoding.readVarUint(decoder) // => 256
154
+ * decoding.readVarString(decoder) // => 'Hello world!'
155
+ * decoding.hasContent(decoder) // => false - all data is read
156
+ * ```
157
+ *
158
+ * @module encoding
159
+ */
160
+ /**
161
+ * Write one byte to the encoder.
162
+ *
163
+ * @function
164
+ * @param {Encoder} encoder
165
+ * @param {number} num The byte that is to be encoded.
166
+ */
119
167
  const write = (encoder, num) => {
120
- const bufferLen = encoder.cbuf.length;
121
- if (encoder.cpos === bufferLen) {
122
- encoder.bufs.push(encoder.cbuf);
123
- encoder.cbuf = new Uint8Array(bufferLen * 2);
124
- encoder.cpos = 0;
125
- }
126
- encoder.cbuf[encoder.cpos++] = num;
168
+ const bufferLen = encoder.cbuf.length;
169
+ if (encoder.cpos === bufferLen) {
170
+ encoder.bufs.push(encoder.cbuf);
171
+ encoder.cbuf = new Uint8Array(bufferLen * 2);
172
+ encoder.cpos = 0;
173
+ }
174
+ encoder.cbuf[encoder.cpos++] = num;
127
175
  };
128
-
129
176
  /**
130
- * Write a variable length unsigned integer. Max encodable integer is 2^53.
131
- *
132
- * @function
133
- * @param {Encoder} encoder
134
- * @param {number} num The number that is to be encoded.
135
- */
177
+ * Write a variable length unsigned integer. Max encodable integer is 2^53.
178
+ *
179
+ * @function
180
+ * @param {Encoder} encoder
181
+ * @param {number} num The number that is to be encoded.
182
+ */
136
183
  const writeVarUint = (encoder, num) => {
137
- while (num > BITS7) {
138
- write(encoder, BIT8 | (BITS7 & num));
139
- num = floor(num / 128); // shift >>> 7
140
- }
141
- write(encoder, BITS7 & num);
184
+ while (num > BITS7) {
185
+ write(encoder, BIT8 | BITS7 & num);
186
+ num = floor(num / 128);
187
+ }
188
+ write(encoder, BITS7 & num);
142
189
  };
143
-
144
190
  /**
145
- * A cache to store strings temporarily
146
- */
147
- const _strBuffer = new Uint8Array(30000);
191
+ * A cache to store strings temporarily
192
+ */
193
+ const _strBuffer = new Uint8Array(3e4);
148
194
  const _maxStrBSize = _strBuffer.length / 3;
149
-
150
195
  /**
151
- * Write a variable length string.
152
- *
153
- * @function
154
- * @param {Encoder} encoder
155
- * @param {String} str The string that is to be encoded.
156
- */
196
+ * Write a variable length string.
197
+ *
198
+ * @function
199
+ * @param {Encoder} encoder
200
+ * @param {String} str The string that is to be encoded.
201
+ */
157
202
  const _writeVarStringNative = (encoder, str) => {
158
- if (str.length < _maxStrBSize) {
159
- // We can encode the string into the existing buffer
160
- /* c8 ignore next */
161
- const written = utf8TextEncoder.encodeInto(str, _strBuffer).written || 0;
162
- writeVarUint(encoder, written);
163
- for (let i = 0; i < written; i++) {
164
- write(encoder, _strBuffer[i]);
165
- }
166
- } else {
167
- writeVarUint8Array(encoder, encodeUtf8(str));
168
- }
203
+ if (str.length < _maxStrBSize) {
204
+ /* c8 ignore next */
205
+ const written = utf8TextEncoder.encodeInto(str, _strBuffer).written || 0;
206
+ writeVarUint(encoder, written);
207
+ for (let i = 0; i < written; i++) write(encoder, _strBuffer[i]);
208
+ } else writeVarUint8Array(encoder, encodeUtf8(str));
169
209
  };
170
-
171
210
  /**
172
- * Write a variable length string.
173
- *
174
- * @function
175
- * @param {Encoder} encoder
176
- * @param {String} str The string that is to be encoded.
177
- */
211
+ * Write a variable length string.
212
+ *
213
+ * @function
214
+ * @param {Encoder} encoder
215
+ * @param {String} str The string that is to be encoded.
216
+ */
178
217
  const _writeVarStringPolyfill = (encoder, str) => {
179
- const encodedString = unescape(encodeURIComponent(str));
180
- const len = encodedString.length;
181
- writeVarUint(encoder, len);
182
- for (let i = 0; i < len; i++) {
183
- write(encoder, /** @type {number} */ (encodedString.codePointAt(i)));
184
- }
218
+ const encodedString = unescape(encodeURIComponent(str));
219
+ const len = encodedString.length;
220
+ writeVarUint(encoder, len);
221
+ for (let i = 0; i < len; i++) write(encoder, encodedString.codePointAt(i));
185
222
  };
186
-
187
223
  /**
188
- * Write a variable length string.
189
- *
190
- * @function
191
- * @param {Encoder} encoder
192
- * @param {String} str The string that is to be encoded.
193
- */
224
+ * Write a variable length string.
225
+ *
226
+ * @function
227
+ * @param {Encoder} encoder
228
+ * @param {String} str The string that is to be encoded.
229
+ */
194
230
  /* c8 ignore next */
195
- const writeVarString = (utf8TextEncoder && /** @type {any} */ (utf8TextEncoder).encodeInto) ? _writeVarStringNative : _writeVarStringPolyfill;
196
-
197
- /**
198
- * Append fixed-length Uint8Array to the encoder.
199
- *
200
- * @function
201
- * @param {Encoder} encoder
202
- * @param {Uint8Array} uint8Array
203
- */
231
+ const writeVarString = utf8TextEncoder && utf8TextEncoder.encodeInto ? _writeVarStringNative : _writeVarStringPolyfill;
232
+ /**
233
+ * Append fixed-length Uint8Array to the encoder.
234
+ *
235
+ * @function
236
+ * @param {Encoder} encoder
237
+ * @param {Uint8Array} uint8Array
238
+ */
204
239
  const writeUint8Array = (encoder, uint8Array) => {
205
- const bufferLen = encoder.cbuf.length;
206
- const cpos = encoder.cpos;
207
- const leftCopyLen = min(bufferLen - cpos, uint8Array.length);
208
- const rightCopyLen = uint8Array.length - leftCopyLen;
209
- encoder.cbuf.set(uint8Array.subarray(0, leftCopyLen), cpos);
210
- encoder.cpos += leftCopyLen;
211
- if (rightCopyLen > 0) {
212
- // Still something to write, write right half..
213
- // Append new buffer
214
- encoder.bufs.push(encoder.cbuf);
215
- // must have at least size of remaining buffer
216
- encoder.cbuf = new Uint8Array(max(bufferLen * 2, rightCopyLen));
217
- // copy array
218
- encoder.cbuf.set(uint8Array.subarray(leftCopyLen));
219
- encoder.cpos = rightCopyLen;
220
- }
240
+ const bufferLen = encoder.cbuf.length;
241
+ const cpos = encoder.cpos;
242
+ const leftCopyLen = min(bufferLen - cpos, uint8Array.length);
243
+ const rightCopyLen = uint8Array.length - leftCopyLen;
244
+ encoder.cbuf.set(uint8Array.subarray(0, leftCopyLen), cpos);
245
+ encoder.cpos += leftCopyLen;
246
+ if (rightCopyLen > 0) {
247
+ encoder.bufs.push(encoder.cbuf);
248
+ encoder.cbuf = new Uint8Array(max(bufferLen * 2, rightCopyLen));
249
+ encoder.cbuf.set(uint8Array.subarray(leftCopyLen));
250
+ encoder.cpos = rightCopyLen;
251
+ }
221
252
  };
222
-
223
253
  /**
224
- * Append an Uint8Array to Encoder.
225
- *
226
- * @function
227
- * @param {Encoder} encoder
228
- * @param {Uint8Array} uint8Array
229
- */
254
+ * Append an Uint8Array to Encoder.
255
+ *
256
+ * @function
257
+ * @param {Encoder} encoder
258
+ * @param {Uint8Array} uint8Array
259
+ */
230
260
  const writeVarUint8Array = (encoder, uint8Array) => {
231
- writeVarUint(encoder, uint8Array.byteLength);
232
- writeUint8Array(encoder, uint8Array);
261
+ writeVarUint(encoder, uint8Array.byteLength);
262
+ writeUint8Array(encoder, uint8Array);
233
263
  };
234
264
 
265
+ //#endregion
266
+ //#region node_modules/lib0/error.js
235
267
  /**
236
- * Error helpers.
237
- *
238
- * @module error
239
- */
240
-
268
+ * Error helpers.
269
+ *
270
+ * @module error
271
+ */
241
272
  /**
242
- * @param {string} s
243
- * @return {Error}
244
- */
273
+ * @param {string} s
274
+ * @return {Error}
275
+ */
245
276
  /* c8 ignore next */
246
- const create = s => new Error(s);
247
-
248
- /**
249
- * Efficient schema-less binary decoding with support for variable length encoding.
250
- *
251
- * Use [lib0/decoding] with [lib0/encoding]. Every encoding function has a corresponding decoding function.
252
- *
253
- * Encodes numbers in little-endian order (least to most significant byte order)
254
- * and is compatible with Golang's binary encoding (https://golang.org/pkg/encoding/binary/)
255
- * which is also used in Protocol Buffers.
256
- *
257
- * ```js
258
- * // encoding step
259
- * const encoder = encoding.createEncoder()
260
- * encoding.writeVarUint(encoder, 256)
261
- * encoding.writeVarString(encoder, 'Hello world!')
262
- * const buf = encoding.toUint8Array(encoder)
263
- * ```
264
- *
265
- * ```js
266
- * // decoding step
267
- * const decoder = decoding.createDecoder(buf)
268
- * decoding.readVarUint(decoder) // => 256
269
- * decoding.readVarString(decoder) // => 'Hello world!'
270
- * decoding.hasContent(decoder) // => false - all data is read
271
- * ```
272
- *
273
- * @module decoding
274
- */
275
-
276
-
277
- const errorUnexpectedEndOfArray = create('Unexpected end of array');
278
- const errorIntegerOutOfRange = create('Integer out of Range');
279
-
280
- /**
281
- * Create an Uint8Array view of the next `len` bytes and advance the position by `len`.
282
- *
283
- * Important: The Uint8Array still points to the underlying ArrayBuffer. Make sure to discard the result as soon as possible to prevent any memory leaks.
284
- * Use `buffer.copyUint8Array` to copy the result into a new Uint8Array.
285
- *
286
- * @function
287
- * @param {Decoder} decoder The decoder instance
288
- * @param {number} len The length of bytes to read
289
- * @return {Uint8Array}
290
- */
277
+ const create = (s) => new Error(s);
278
+
279
+ //#endregion
280
+ //#region node_modules/lib0/decoding.js
281
+ /**
282
+ * Efficient schema-less binary decoding with support for variable length encoding.
283
+ *
284
+ * Use [lib0/decoding] with [lib0/encoding]. Every encoding function has a corresponding decoding function.
285
+ *
286
+ * Encodes numbers in little-endian order (least to most significant byte order)
287
+ * and is compatible with Golang's binary encoding (https://golang.org/pkg/encoding/binary/)
288
+ * which is also used in Protocol Buffers.
289
+ *
290
+ * ```js
291
+ * // encoding step
292
+ * const encoder = encoding.createEncoder()
293
+ * encoding.writeVarUint(encoder, 256)
294
+ * encoding.writeVarString(encoder, 'Hello world!')
295
+ * const buf = encoding.toUint8Array(encoder)
296
+ * ```
297
+ *
298
+ * ```js
299
+ * // decoding step
300
+ * const decoder = decoding.createDecoder(buf)
301
+ * decoding.readVarUint(decoder) // => 256
302
+ * decoding.readVarString(decoder) // => 'Hello world!'
303
+ * decoding.hasContent(decoder) // => false - all data is read
304
+ * ```
305
+ *
306
+ * @module decoding
307
+ */
308
+ const errorUnexpectedEndOfArray = create("Unexpected end of array");
309
+ const errorIntegerOutOfRange = create("Integer out of Range");
310
+ /**
311
+ * Create an Uint8Array view of the next `len` bytes and advance the position by `len`.
312
+ *
313
+ * Important: The Uint8Array still points to the underlying ArrayBuffer. Make sure to discard the result as soon as possible to prevent any memory leaks.
314
+ * Use `buffer.copyUint8Array` to copy the result into a new Uint8Array.
315
+ *
316
+ * @function
317
+ * @param {Decoder} decoder The decoder instance
318
+ * @param {number} len The length of bytes to read
319
+ * @return {Uint8Array}
320
+ */
291
321
  const readUint8Array = (decoder, len) => {
292
- const view = new Uint8Array(decoder.arr.buffer, decoder.pos + decoder.arr.byteOffset, len);
293
- decoder.pos += len;
294
- return view
322
+ const view = new Uint8Array(decoder.arr.buffer, decoder.pos + decoder.arr.byteOffset, len);
323
+ decoder.pos += len;
324
+ return view;
295
325
  };
296
-
297
- /**
298
- * Read variable length Uint8Array.
299
- *
300
- * Important: The Uint8Array still points to the underlying ArrayBuffer. Make sure to discard the result as soon as possible to prevent any memory leaks.
301
- * Use `buffer.copyUint8Array` to copy the result into a new Uint8Array.
302
- *
303
- * @function
304
- * @param {Decoder} decoder
305
- * @return {Uint8Array}
306
- */
307
- const readVarUint8Array = decoder => readUint8Array(decoder, readVarUint(decoder));
308
-
309
326
  /**
310
- * Read one byte as unsigned integer.
311
- * @function
312
- * @param {Decoder} decoder The decoder instance
313
- * @return {number} Unsigned 8-bit integer
314
- */
315
- const readUint8 = decoder => decoder.arr[decoder.pos++];
316
-
317
- /**
318
- * Read unsigned integer (32bit) with variable length.
319
- * 1/8th of the storage is used as encoding overhead.
320
- * * numbers < 2^7 is stored in one bytlength
321
- * * numbers < 2^14 is stored in two bylength
322
- *
323
- * @function
324
- * @param {Decoder} decoder
325
- * @return {number} An unsigned integer.length
326
- */
327
- const readVarUint = decoder => {
328
- let num = 0;
329
- let mult = 1;
330
- const len = decoder.arr.length;
331
- while (decoder.pos < len) {
332
- const r = decoder.arr[decoder.pos++];
333
- // num = num | ((r & binary.BITS7) << len)
334
- num = num + (r & BITS7) * mult; // shift $r << (7*#iterations) and add it to num
335
- mult *= 128; // next iteration, shift 7 "more" to the left
336
- if (r < BIT8) {
337
- return num
338
- }
339
- /* c8 ignore start */
340
- if (num > MAX_SAFE_INTEGER) {
341
- throw errorIntegerOutOfRange
342
- }
343
- /* c8 ignore stop */
344
- }
345
- throw errorUnexpectedEndOfArray
327
+ * Read variable length Uint8Array.
328
+ *
329
+ * Important: The Uint8Array still points to the underlying ArrayBuffer. Make sure to discard the result as soon as possible to prevent any memory leaks.
330
+ * Use `buffer.copyUint8Array` to copy the result into a new Uint8Array.
331
+ *
332
+ * @function
333
+ * @param {Decoder} decoder
334
+ * @return {Uint8Array}
335
+ */
336
+ const readVarUint8Array = (decoder) => readUint8Array(decoder, readVarUint(decoder));
337
+ /**
338
+ * Read one byte as unsigned integer.
339
+ * @function
340
+ * @param {Decoder} decoder The decoder instance
341
+ * @return {number} Unsigned 8-bit integer
342
+ */
343
+ const readUint8 = (decoder) => decoder.arr[decoder.pos++];
344
+ /**
345
+ * Read unsigned integer (32bit) with variable length.
346
+ * 1/8th of the storage is used as encoding overhead.
347
+ * * numbers < 2^7 is stored in one bytlength
348
+ * * numbers < 2^14 is stored in two bylength
349
+ *
350
+ * @function
351
+ * @param {Decoder} decoder
352
+ * @return {number} An unsigned integer.length
353
+ */
354
+ const readVarUint = (decoder) => {
355
+ let num = 0;
356
+ let mult = 1;
357
+ const len = decoder.arr.length;
358
+ while (decoder.pos < len) {
359
+ const r = decoder.arr[decoder.pos++];
360
+ num = num + (r & BITS7) * mult;
361
+ mult *= 128;
362
+ if (r < BIT8) return num;
363
+ /* c8 ignore start */
364
+ if (num > MAX_SAFE_INTEGER) throw errorIntegerOutOfRange;
365
+ }
366
+ throw errorUnexpectedEndOfArray;
346
367
  };
347
-
348
368
  /**
349
- * We don't test this function anymore as we use native decoding/encoding by default now.
350
- * Better not modify this anymore..
351
- *
352
- * Transforming utf8 to a string is pretty expensive. The code performs 10x better
353
- * when String.fromCodePoint is fed with all characters as arguments.
354
- * But most environments have a maximum number of arguments per functions.
355
- * For effiency reasons we apply a maximum of 10000 characters at once.
356
- *
357
- * @function
358
- * @param {Decoder} decoder
359
- * @return {String} The read String.
360
- */
369
+ * We don't test this function anymore as we use native decoding/encoding by default now.
370
+ * Better not modify this anymore..
371
+ *
372
+ * Transforming utf8 to a string is pretty expensive. The code performs 10x better
373
+ * when String.fromCodePoint is fed with all characters as arguments.
374
+ * But most environments have a maximum number of arguments per functions.
375
+ * For effiency reasons we apply a maximum of 10000 characters at once.
376
+ *
377
+ * @function
378
+ * @param {Decoder} decoder
379
+ * @return {String} The read String.
380
+ */
361
381
  /* c8 ignore start */
362
- const _readVarStringPolyfill = decoder => {
363
- let remainingLen = readVarUint(decoder);
364
- if (remainingLen === 0) {
365
- return ''
366
- } else {
367
- let encodedString = String.fromCodePoint(readUint8(decoder)); // remember to decrease remainingLen
368
- if (--remainingLen < 100) { // do not create a Uint8Array for small strings
369
- while (remainingLen--) {
370
- encodedString += String.fromCodePoint(readUint8(decoder));
371
- }
372
- } else {
373
- while (remainingLen > 0) {
374
- const nextLen = remainingLen < 10000 ? remainingLen : 10000;
375
- // this is dangerous, we create a fresh array view from the existing buffer
376
- const bytes = decoder.arr.subarray(decoder.pos, decoder.pos + nextLen);
377
- decoder.pos += nextLen;
378
- // Starting with ES5.1 we can supply a generic array-like object as arguments
379
- encodedString += String.fromCodePoint.apply(null, /** @type {any} */ (bytes));
380
- remainingLen -= nextLen;
381
- }
382
- }
383
- return decodeURIComponent(escape(encodedString))
384
- }
382
+ const _readVarStringPolyfill = (decoder) => {
383
+ let remainingLen = readVarUint(decoder);
384
+ if (remainingLen === 0) return "";
385
+ else {
386
+ let encodedString = String.fromCodePoint(readUint8(decoder));
387
+ if (--remainingLen < 100) while (remainingLen--) encodedString += String.fromCodePoint(readUint8(decoder));
388
+ else while (remainingLen > 0) {
389
+ const nextLen = remainingLen < 1e4 ? remainingLen : 1e4;
390
+ const bytes = decoder.arr.subarray(decoder.pos, decoder.pos + nextLen);
391
+ decoder.pos += nextLen;
392
+ encodedString += String.fromCodePoint.apply(null, bytes);
393
+ remainingLen -= nextLen;
394
+ }
395
+ return decodeURIComponent(escape(encodedString));
396
+ }
385
397
  };
386
398
  /* c8 ignore stop */
387
-
388
- /**
389
- * @function
390
- * @param {Decoder} decoder
391
- * @return {String} The read String
392
- */
393
- const _readVarStringNative = decoder =>
394
- /** @type any */ (utf8TextDecoder).decode(readVarUint8Array(decoder));
395
-
396
399
  /**
397
- * Read string of variable length
398
- * * varUint is used to store the length of the string
399
- *
400
- * @function
401
- * @param {Decoder} decoder
402
- * @return {String} The read String
403
- *
404
- */
400
+ * @function
401
+ * @param {Decoder} decoder
402
+ * @return {String} The read String
403
+ */
404
+ const _readVarStringNative = (decoder) => utf8TextDecoder.decode(readVarUint8Array(decoder));
405
+ /**
406
+ * Read string of variable length
407
+ * * varUint is used to store the length of the string
408
+ *
409
+ * @function
410
+ * @param {Decoder} decoder
411
+ * @return {String} The read String
412
+ *
413
+ */
405
414
  /* c8 ignore next */
406
415
  const readVarString = utf8TextDecoder ? _readVarStringNative : _readVarStringPolyfill;
407
416
 
408
- var AuthMessageType;
409
- (function (AuthMessageType) {
410
- AuthMessageType[AuthMessageType["Token"] = 0] = "Token";
411
- AuthMessageType[AuthMessageType["PermissionDenied"] = 1] = "PermissionDenied";
412
- AuthMessageType[AuthMessageType["Authenticated"] = 2] = "Authenticated";
413
- })(AuthMessageType || (AuthMessageType = {}));
417
+ //#endregion
418
+ //#region packages/common/src/auth.ts
419
+ let AuthMessageType = /* @__PURE__ */ function(AuthMessageType) {
420
+ AuthMessageType[AuthMessageType["Token"] = 0] = "Token";
421
+ AuthMessageType[AuthMessageType["PermissionDenied"] = 1] = "PermissionDenied";
422
+ AuthMessageType[AuthMessageType["Authenticated"] = 2] = "Authenticated";
423
+ return AuthMessageType;
424
+ }({});
414
425
  const writeAuthentication = (encoder, auth) => {
415
- writeVarUint(encoder, AuthMessageType.Token);
416
- writeVarString(encoder, auth);
426
+ writeVarUint(encoder, AuthMessageType.Token);
427
+ writeVarString(encoder, auth);
417
428
  };
418
429
  const writePermissionDenied = (encoder, reason) => {
419
- writeVarUint(encoder, AuthMessageType.PermissionDenied);
420
- writeVarString(encoder, reason);
430
+ writeVarUint(encoder, AuthMessageType.PermissionDenied);
431
+ writeVarString(encoder, reason);
421
432
  };
422
433
  const writeAuthenticated = (encoder, scope) => {
423
- writeVarUint(encoder, AuthMessageType.Authenticated);
424
- writeVarString(encoder, scope);
434
+ writeVarUint(encoder, AuthMessageType.Authenticated);
435
+ writeVarString(encoder, scope);
425
436
  };
426
437
  const writeTokenSyncRequest = (encoder) => {
427
- writeVarUint(encoder, AuthMessageType.Token);
438
+ writeVarUint(encoder, AuthMessageType.Token);
428
439
  };
429
440
  const readAuthMessage = (decoder, sendToken, permissionDeniedHandler, authenticatedHandler) => {
430
- switch (readVarUint(decoder)) {
431
- case AuthMessageType.Token: {
432
- sendToken();
433
- break;
434
- }
435
- case AuthMessageType.PermissionDenied: {
436
- permissionDeniedHandler(readVarString(decoder));
437
- break;
438
- }
439
- case AuthMessageType.Authenticated: {
440
- authenticatedHandler(readVarString(decoder));
441
- break;
442
- }
443
- }
441
+ switch (readVarUint(decoder)) {
442
+ case AuthMessageType.Token:
443
+ sendToken();
444
+ break;
445
+ case AuthMessageType.PermissionDenied:
446
+ permissionDeniedHandler(readVarString(decoder));
447
+ break;
448
+ case AuthMessageType.Authenticated:
449
+ authenticatedHandler(readVarString(decoder));
450
+ break;
451
+ default:
452
+ }
444
453
  };
445
454
 
455
+ //#endregion
456
+ //#region packages/common/src/CloseEvents.ts
446
457
  /**
447
- * The server is terminating the connection because a data frame was received
448
- * that is too large.
449
- * See: https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code
450
- */
458
+ * The server is terminating the connection because a data frame was received
459
+ * that is too large.
460
+ * See: https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code
461
+ */
451
462
  const MessageTooBig = {
452
- code: 1009,
453
- reason: "Message Too Big",
463
+ code: 1009,
464
+ reason: "Message Too Big"
454
465
  };
455
466
  /**
456
- * The server successfully processed the request, asks that the requester reset
457
- * its document view, and is not returning any content.
458
- */
467
+ * The server successfully processed the request, asks that the requester reset
468
+ * its document view, and is not returning any content.
469
+ */
459
470
  const ResetConnection = {
460
- code: 4205,
461
- reason: "Reset Connection",
471
+ code: 4205,
472
+ reason: "Reset Connection"
462
473
  };
463
474
  /**
464
- * Similar to Forbidden, but specifically for use when authentication is required and has
465
- * failed or has not yet been provided.
466
- */
475
+ * Similar to Forbidden, but specifically for use when authentication is required and has
476
+ * failed or has not yet been provided.
477
+ */
467
478
  const Unauthorized = {
468
- code: 4401,
469
- reason: "Unauthorized",
479
+ code: 4401,
480
+ reason: "Unauthorized"
470
481
  };
471
482
  /**
472
- * The request contained valid data and was understood by the server, but the server
473
- * is refusing action.
474
- */
483
+ * The request contained valid data and was understood by the server, but the server
484
+ * is refusing action.
485
+ */
475
486
  const Forbidden = {
476
- code: 4403,
477
- reason: "Forbidden",
487
+ code: 4403,
488
+ reason: "Forbidden"
478
489
  };
479
490
  /**
480
- * The server timed out waiting for the request.
481
- */
491
+ * The server timed out waiting for the request.
492
+ */
482
493
  const ConnectionTimeout = {
483
- code: 4408,
484
- reason: "Connection Timeout",
494
+ code: 4408,
495
+ reason: "Connection Timeout"
485
496
  };
486
497
 
498
+ //#endregion
499
+ //#region packages/common/src/awarenessStatesToArray.ts
487
500
  const awarenessStatesToArray = (states) => {
488
- return Array.from(states.entries()).map(([key, value]) => {
489
- return {
490
- clientId: key,
491
- ...value,
492
- };
493
- });
501
+ return Array.from(states.entries()).map(([key, value]) => {
502
+ return {
503
+ clientId: key,
504
+ ...value
505
+ };
506
+ });
494
507
  };
495
508
 
496
- /**
497
- * State of the WebSocket connection.
498
- * https://developer.mozilla.org/de/docs/Web/API/WebSocket/readyState
499
- */
500
- var WsReadyStates;
501
- (function (WsReadyStates) {
502
- WsReadyStates[WsReadyStates["Connecting"] = 0] = "Connecting";
503
- WsReadyStates[WsReadyStates["Open"] = 1] = "Open";
504
- WsReadyStates[WsReadyStates["Closing"] = 2] = "Closing";
505
- WsReadyStates[WsReadyStates["Closed"] = 3] = "Closed";
506
- })(WsReadyStates || (WsReadyStates = {}));
507
-
509
+ //#endregion
510
+ //#region packages/common/src/types.ts
511
+ /**
512
+ * State of the WebSocket connection.
513
+ * https://developer.mozilla.org/de/docs/Web/API/WebSocket/readyState
514
+ */
515
+ let WsReadyStates = /* @__PURE__ */ function(WsReadyStates) {
516
+ WsReadyStates[WsReadyStates["Connecting"] = 0] = "Connecting";
517
+ WsReadyStates[WsReadyStates["Open"] = 1] = "Open";
518
+ WsReadyStates[WsReadyStates["Closing"] = 2] = "Closing";
519
+ WsReadyStates[WsReadyStates["Closed"] = 3] = "Closed";
520
+ return WsReadyStates;
521
+ }({});
522
+
523
+ //#endregion
508
524
  export { AuthMessageType, ConnectionTimeout, Forbidden, MessageTooBig, ResetConnection, Unauthorized, WsReadyStates, awarenessStatesToArray, readAuthMessage, writeAuthenticated, writeAuthentication, writePermissionDenied, writeTokenSyncRequest };
509
- //# sourceMappingURL=hocuspocus-common.esm.js.map
525
+ //# sourceMappingURL=hocuspocus-common.esm.js.map