@hocuspocus/common 3.4.6-rc.0 → 3.4.6-rc.2
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.
- package/package.json +1 -1
- package/dist/index.js +0 -524
package/package.json
CHANGED
package/dist/index.js
DELETED
|
@@ -1,524 +0,0 @@
|
|
|
1
|
-
//#region node_modules/lib0/math.js
|
|
2
|
-
/**
|
|
3
|
-
* Common Math expressions.
|
|
4
|
-
*
|
|
5
|
-
* @module math
|
|
6
|
-
*/
|
|
7
|
-
const floor = Math.floor;
|
|
8
|
-
/**
|
|
9
|
-
* @function
|
|
10
|
-
* @param {number} a
|
|
11
|
-
* @param {number} b
|
|
12
|
-
* @return {number} The smaller element of a and b
|
|
13
|
-
*/
|
|
14
|
-
const min = (a, b) => a < b ? a : b;
|
|
15
|
-
/**
|
|
16
|
-
* @function
|
|
17
|
-
* @param {number} a
|
|
18
|
-
* @param {number} b
|
|
19
|
-
* @return {number} The bigger element of a and b
|
|
20
|
-
*/
|
|
21
|
-
const max = (a, b) => a > b ? a : b;
|
|
22
|
-
const isNaN$1 = Number.isNaN;
|
|
23
|
-
|
|
24
|
-
//#endregion
|
|
25
|
-
//#region node_modules/lib0/binary.js
|
|
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;
|
|
42
|
-
const BITS7 = 127;
|
|
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
|
-
*/
|
|
73
|
-
const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER;
|
|
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;
|
|
107
|
-
};
|
|
108
|
-
/* c8 ignore next */
|
|
109
|
-
const utf8TextEncoder = typeof TextEncoder !== "undefined" ? new TextEncoder() : null;
|
|
110
|
-
/**
|
|
111
|
-
* @param {string} str
|
|
112
|
-
* @return {Uint8Array}
|
|
113
|
-
*/
|
|
114
|
-
const _encodeUtf8Native = (str) => utf8TextEncoder.encode(str);
|
|
115
|
-
/**
|
|
116
|
-
* @param {string} str
|
|
117
|
-
* @return {Uint8Array}
|
|
118
|
-
*/
|
|
119
|
-
/* c8 ignore next */
|
|
120
|
-
const encodeUtf8 = utf8TextEncoder ? _encodeUtf8Native : _encodeUtf8Polyfill;
|
|
121
|
-
/* c8 ignore next */
|
|
122
|
-
let utf8TextDecoder = typeof TextDecoder === "undefined" ? null : new TextDecoder("utf-8", {
|
|
123
|
-
fatal: true,
|
|
124
|
-
ignoreBOM: true
|
|
125
|
-
});
|
|
126
|
-
/* c8 ignore start */
|
|
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
|
-
*/
|
|
167
|
-
const write = (encoder, 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;
|
|
175
|
-
};
|
|
176
|
-
/**
|
|
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
|
-
*/
|
|
183
|
-
const writeVarUint = (encoder, num) => {
|
|
184
|
-
while (num > BITS7) {
|
|
185
|
-
write(encoder, BIT8 | BITS7 & num);
|
|
186
|
-
num = floor(num / 128);
|
|
187
|
-
}
|
|
188
|
-
write(encoder, BITS7 & num);
|
|
189
|
-
};
|
|
190
|
-
/**
|
|
191
|
-
* A cache to store strings temporarily
|
|
192
|
-
*/
|
|
193
|
-
const _strBuffer = new Uint8Array(3e4);
|
|
194
|
-
const _maxStrBSize = _strBuffer.length / 3;
|
|
195
|
-
/**
|
|
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
|
-
*/
|
|
202
|
-
const _writeVarStringNative = (encoder, str) => {
|
|
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));
|
|
209
|
-
};
|
|
210
|
-
/**
|
|
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
|
-
*/
|
|
217
|
-
const _writeVarStringPolyfill = (encoder, str) => {
|
|
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));
|
|
222
|
-
};
|
|
223
|
-
/**
|
|
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
|
-
*/
|
|
230
|
-
/* c8 ignore next */
|
|
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
|
-
*/
|
|
239
|
-
const writeUint8Array = (encoder, uint8Array) => {
|
|
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
|
-
}
|
|
252
|
-
};
|
|
253
|
-
/**
|
|
254
|
-
* Append an Uint8Array to Encoder.
|
|
255
|
-
*
|
|
256
|
-
* @function
|
|
257
|
-
* @param {Encoder} encoder
|
|
258
|
-
* @param {Uint8Array} uint8Array
|
|
259
|
-
*/
|
|
260
|
-
const writeVarUint8Array = (encoder, uint8Array) => {
|
|
261
|
-
writeVarUint(encoder, uint8Array.byteLength);
|
|
262
|
-
writeUint8Array(encoder, uint8Array);
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
//#endregion
|
|
266
|
-
//#region node_modules/lib0/error.js
|
|
267
|
-
/**
|
|
268
|
-
* Error helpers.
|
|
269
|
-
*
|
|
270
|
-
* @module error
|
|
271
|
-
*/
|
|
272
|
-
/**
|
|
273
|
-
* @param {string} s
|
|
274
|
-
* @return {Error}
|
|
275
|
-
*/
|
|
276
|
-
/* c8 ignore next */
|
|
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
|
-
*/
|
|
321
|
-
const readUint8Array = (decoder, len) => {
|
|
322
|
-
const view = new Uint8Array(decoder.arr.buffer, decoder.pos + decoder.arr.byteOffset, len);
|
|
323
|
-
decoder.pos += len;
|
|
324
|
-
return view;
|
|
325
|
-
};
|
|
326
|
-
/**
|
|
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;
|
|
367
|
-
};
|
|
368
|
-
/**
|
|
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
|
-
*/
|
|
381
|
-
/* c8 ignore start */
|
|
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
|
-
}
|
|
397
|
-
};
|
|
398
|
-
/* c8 ignore stop */
|
|
399
|
-
/**
|
|
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
|
-
*/
|
|
414
|
-
/* c8 ignore next */
|
|
415
|
-
const readVarString = utf8TextDecoder ? _readVarStringNative : _readVarStringPolyfill;
|
|
416
|
-
|
|
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
|
-
}({});
|
|
425
|
-
const writeAuthentication = (encoder, auth) => {
|
|
426
|
-
writeVarUint(encoder, AuthMessageType.Token);
|
|
427
|
-
writeVarString(encoder, auth);
|
|
428
|
-
};
|
|
429
|
-
const writePermissionDenied = (encoder, reason) => {
|
|
430
|
-
writeVarUint(encoder, AuthMessageType.PermissionDenied);
|
|
431
|
-
writeVarString(encoder, reason);
|
|
432
|
-
};
|
|
433
|
-
const writeAuthenticated = (encoder, scope) => {
|
|
434
|
-
writeVarUint(encoder, AuthMessageType.Authenticated);
|
|
435
|
-
writeVarString(encoder, scope);
|
|
436
|
-
};
|
|
437
|
-
const writeTokenSyncRequest = (encoder) => {
|
|
438
|
-
writeVarUint(encoder, AuthMessageType.Token);
|
|
439
|
-
};
|
|
440
|
-
const readAuthMessage = (decoder, sendToken, permissionDeniedHandler, authenticatedHandler) => {
|
|
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
|
-
}
|
|
453
|
-
};
|
|
454
|
-
|
|
455
|
-
//#endregion
|
|
456
|
-
//#region packages/common/src/CloseEvents.ts
|
|
457
|
-
/**
|
|
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
|
-
*/
|
|
462
|
-
const MessageTooBig = {
|
|
463
|
-
code: 1009,
|
|
464
|
-
reason: "Message Too Big"
|
|
465
|
-
};
|
|
466
|
-
/**
|
|
467
|
-
* The server successfully processed the request, asks that the requester reset
|
|
468
|
-
* its document view, and is not returning any content.
|
|
469
|
-
*/
|
|
470
|
-
const ResetConnection = {
|
|
471
|
-
code: 4205,
|
|
472
|
-
reason: "Reset Connection"
|
|
473
|
-
};
|
|
474
|
-
/**
|
|
475
|
-
* Similar to Forbidden, but specifically for use when authentication is required and has
|
|
476
|
-
* failed or has not yet been provided.
|
|
477
|
-
*/
|
|
478
|
-
const Unauthorized = {
|
|
479
|
-
code: 4401,
|
|
480
|
-
reason: "Unauthorized"
|
|
481
|
-
};
|
|
482
|
-
/**
|
|
483
|
-
* The request contained valid data and was understood by the server, but the server
|
|
484
|
-
* is refusing action.
|
|
485
|
-
*/
|
|
486
|
-
const Forbidden = {
|
|
487
|
-
code: 4403,
|
|
488
|
-
reason: "Forbidden"
|
|
489
|
-
};
|
|
490
|
-
/**
|
|
491
|
-
* The server timed out waiting for the request.
|
|
492
|
-
*/
|
|
493
|
-
const ConnectionTimeout = {
|
|
494
|
-
code: 4408,
|
|
495
|
-
reason: "Connection Timeout"
|
|
496
|
-
};
|
|
497
|
-
|
|
498
|
-
//#endregion
|
|
499
|
-
//#region packages/common/src/awarenessStatesToArray.ts
|
|
500
|
-
const awarenessStatesToArray = (states) => {
|
|
501
|
-
return Array.from(states.entries()).map(([key, value]) => {
|
|
502
|
-
return {
|
|
503
|
-
clientId: key,
|
|
504
|
-
...value
|
|
505
|
-
};
|
|
506
|
-
});
|
|
507
|
-
};
|
|
508
|
-
|
|
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
|
|
524
|
-
export { AuthMessageType, ConnectionTimeout, Forbidden, MessageTooBig, ResetConnection, Unauthorized, WsReadyStates, awarenessStatesToArray, readAuthMessage, writeAuthenticated, writeAuthentication, writePermissionDenied, writeTokenSyncRequest };
|