lib0 0.2.66 → 0.2.68
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/bin/0serve.d.ts +3 -0
- package/bin/0serve.d.ts.map +1 -0
- package/bin/0serve.js +88 -0
- package/bin/gendocs.d.ts +2 -0
- package/bin/gendocs.d.ts.map +1 -0
- package/bin/gendocs.js +17 -4
- package/bin/gentesthtml.d.ts +3 -0
- package/bin/gentesthtml.d.ts.map +1 -0
- package/bin/gentesthtml.js +29 -15
- package/cache.d.ts +1 -1
- package/cache.d.ts.map +1 -1
- package/coverage/tmp/coverage-53209-1678990177518-0.json +1 -0
- package/crypto/aes-gcm.d.ts +1 -1
- package/crypto/aes-gcm.d.ts.map +1 -1
- package/crypto/aes-gcm.js +1 -6
- package/crypto/common.d.ts +2 -0
- package/crypto/common.d.ts.map +1 -0
- package/crypto/common.js +10 -0
- package/crypto/ecdsa.d.ts +1 -1
- package/crypto/ecdsa.d.ts.map +1 -1
- package/crypto/ecdsa.js +1 -7
- package/crypto/rsa-oaep.d.ts +3 -3
- package/crypto/rsa-oaep.d.ts.map +1 -1
- package/crypto/rsa-oaep.js +5 -8
- package/dist/bin/0serve.d.ts +3 -0
- package/dist/bin/0serve.d.ts.map +1 -0
- package/dist/bin/gendocs.d.ts +2 -0
- package/dist/bin/gendocs.d.ts.map +1 -0
- package/dist/bin/gentesthtml.d.ts +3 -0
- package/dist/bin/gentesthtml.d.ts.map +1 -0
- package/dist/cache.d.ts +1 -1
- package/dist/cache.d.ts.map +1 -1
- package/dist/crypto/aes-gcm.d.ts +1 -1
- package/dist/crypto/aes-gcm.d.ts.map +1 -1
- package/dist/crypto/common.d.ts +2 -0
- package/dist/crypto/common.d.ts.map +1 -0
- package/dist/crypto/ecdsa.d.ts +1 -1
- package/dist/crypto/ecdsa.d.ts.map +1 -1
- package/dist/crypto/rsa-oaep.d.ts +3 -3
- package/dist/crypto/rsa-oaep.d.ts.map +1 -1
- package/dist/environment.test.d.ts +1 -0
- package/dist/index.cjs +1 -1
- package/dist/object.d.ts +3 -3
- package/dist/rollup.config.d.ts +1 -1
- package/dist/tree.test.d.ts +1 -0
- package/dist/{websocket-85f1d597.cjs → websocket-e861ab50.cjs} +2 -2
- package/dist/websocket-e861ab50.cjs.map +1 -0
- package/dist/websocket.cjs +1 -1
- package/dist/websocket.d.ts +2 -2
- package/dist/websocket.d.ts.map +1 -1
- package/environment.test.d.ts +1 -0
- package/object.d.ts +3 -3
- package/package.json +5 -5
- package/rollup.config.d.ts +1 -1
- package/test.html +3 -2
- package/tree.test.d.ts +1 -0
- package/websocket.d.ts +2 -2
- package/websocket.d.ts.map +1 -1
- package/websocket.js +1 -1
- package/coverage/tmp/coverage-29418-1678525324823-0.json +0 -1
- package/dist/websocket-85f1d597.cjs.map +0 -1
package/crypto/aes-gcm.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
export { exportKey } from "./common.js";
|
|
1
2
|
export function encrypt(key: CryptoKey, data: Uint8Array): Promise<Uint8Array>;
|
|
2
3
|
export function decrypt(key: CryptoKey, data: Uint8Array): PromiseLike<Uint8Array>;
|
|
3
|
-
export function exportKey(key: CryptoKey): Promise<JsonWebKey>;
|
|
4
4
|
export function importKey(jwk: any, usages?: Usages | undefined, extractable?: boolean | undefined): Promise<CryptoKey>;
|
|
5
5
|
export function deriveKey(secret: Uint8Array | string, salt: Uint8Array | string, { extractable, usages }?: {
|
|
6
6
|
extractable?: boolean | undefined;
|
package/crypto/aes-gcm.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aes-gcm.d.ts","sourceRoot":"","sources":["aes-gcm.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"aes-gcm.d.ts","sourceRoot":"","sources":["aes-gcm.js"],"names":[],"mappings":";AAuBO,6BAHI,SAAS,QACT,UAAU,uBAkBpB;AAWM,6BAJI,SAAS,QACT,UAAU,GACT,YAAY,UAAU,CAAC,CAclC;AAOM,+BAJI,GAAG,sFAUb;AAmBM,kCANI,UAAU,GAAC,MAAM,QACjB,UAAU,GAAC,MAAM;IAEF,WAAW;IACZ,MAAM;uBA0B9B;qBA3GY,MAAM,SAAS,GAAC,SAAS,CAAC"}
|
package/crypto/aes-gcm.js
CHANGED
|
@@ -6,6 +6,7 @@ import * as encoding from '../encoding.js'
|
|
|
6
6
|
import * as decoding from '../decoding.js'
|
|
7
7
|
import * as webcrypto from 'lib0/webcrypto'
|
|
8
8
|
import * as string from '../string.js'
|
|
9
|
+
export { exportKey } from './common.js'
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* @typedef {Array<'encrypt'|'decrypt'>} Usages
|
|
@@ -61,12 +62,6 @@ export const decrypt = (key, data) => {
|
|
|
61
62
|
).then(data => new Uint8Array(data))
|
|
62
63
|
}
|
|
63
64
|
|
|
64
|
-
/**
|
|
65
|
-
* @param {CryptoKey} key
|
|
66
|
-
*/
|
|
67
|
-
export const exportKey = key =>
|
|
68
|
-
webcrypto.subtle.exportKey('jwk', key)
|
|
69
|
-
|
|
70
65
|
/**
|
|
71
66
|
* @param {any} jwk
|
|
72
67
|
* @param {Usages} [usages]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["common.js"],"names":[],"mappings":"AAKO,+BAFI,SAAS,uBAMnB"}
|
package/crypto/common.js
ADDED
package/crypto/ecdsa.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { exportKey } from "./common.js";
|
|
2
2
|
export function sign(key: CryptoKey, data: Uint8Array): PromiseLike<Uint8Array>;
|
|
3
3
|
export function verify(key: CryptoKey, signature: Uint8Array, data: Uint8Array): PromiseLike<boolean>;
|
|
4
4
|
export function generateKeyPair({ extractable, usages }?: {
|
package/crypto/ecdsa.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ecdsa.d.ts","sourceRoot":"","sources":["ecdsa.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ecdsa.d.ts","sourceRoot":"","sources":["ecdsa.js"],"names":[],"mappings":";AAyBO,0BAJI,SAAS,QACT,UAAU,GACT,YAAY,UAAU,CAAC,CAWlC;AAYM,4BALI,SAAS,aACT,UAAU,QACV,UAAU,GACT,YAAY,OAAO,CAAC,CAY/B;AAQM;IAHmB,WAAW;IACZ,MAAM;2BAU5B;AAQI,+BALI,GAAG;IAEY,WAAW;IACZ,MAAM;uBAQ9B;qBA9EY,MAAM,MAAM,GAAC,QAAQ,CAAC"}
|
package/crypto/ecdsa.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import * as webcrypto from 'lib0/webcrypto'
|
|
6
|
+
export { exportKey } from './common.js'
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* @typedef {Array<'sign'|'verify'>} Usages
|
|
@@ -13,13 +14,6 @@ import * as webcrypto from 'lib0/webcrypto'
|
|
|
13
14
|
*/
|
|
14
15
|
const defaultUsages = ['sign', 'verify']
|
|
15
16
|
|
|
16
|
-
/**
|
|
17
|
-
* @param {CryptoKey} key
|
|
18
|
-
*/
|
|
19
|
-
export const exportKey = key => {
|
|
20
|
-
return webcrypto.subtle.exportKey('jwk', key)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
17
|
/**
|
|
24
18
|
* @experimental The API is not final!
|
|
25
19
|
*
|
package/crypto/rsa-oaep.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { exportKey } from "./common.js";
|
|
2
|
+
export function encrypt(key: CryptoKey, data: Uint8Array): PromiseLike<Uint8Array>;
|
|
2
3
|
export function decrypt(key: CryptoKey, data: Uint8Array): PromiseLike<Uint8Array>;
|
|
3
|
-
export function
|
|
4
|
-
export function generateKey({ extractable, usages }?: {
|
|
4
|
+
export function generateKeyPair({ extractable, usages }?: {
|
|
5
5
|
extractable?: boolean | undefined;
|
|
6
6
|
usages?: Usages | undefined;
|
|
7
7
|
}): Promise<CryptoKeyPair>;
|
package/crypto/rsa-oaep.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsa-oaep.d.ts","sourceRoot":"","sources":["rsa-oaep.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rsa-oaep.d.ts","sourceRoot":"","sources":["rsa-oaep.js"],"names":[],"mappings":";AAuBO,6BAJI,SAAS,QACT,UAAU,GACT,YAAY,UAAU,CAAC,CASC;AAW7B,6BAJI,SAAS,QACT,UAAU,GACT,YAAY,UAAU,CAAC,CASG;AAQ/B;IAJmB,WAAW;IACZ,MAAM;IACnB,QAAQ,aAAa,CAAC,CAY/B;AAQI,+BALI,GAAG;IAEY,WAAW;IACZ,MAAM;uBAQ9B;qBAxEY,MAAM,SAAS,GAAC,SAAS,CAAC"}
|
package/crypto/rsa-oaep.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import * as webcrypto from 'lib0/webcrypto'
|
|
6
|
+
export { exportKey } from './common.js'
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* @typedef {Array<'encrypt'|'decrypt'>} Usages
|
|
@@ -18,6 +19,7 @@ const defaultUsages = ['encrypt', 'decrypt']
|
|
|
18
19
|
*
|
|
19
20
|
* @param {CryptoKey} key
|
|
20
21
|
* @param {Uint8Array} data
|
|
22
|
+
* @return {PromiseLike<Uint8Array>}
|
|
21
23
|
*/
|
|
22
24
|
export const encrypt = (key, data) =>
|
|
23
25
|
webcrypto.subtle.encrypt(
|
|
@@ -26,7 +28,7 @@ export const encrypt = (key, data) =>
|
|
|
26
28
|
},
|
|
27
29
|
key,
|
|
28
30
|
data
|
|
29
|
-
)
|
|
31
|
+
).then(buf => new Uint8Array(buf))
|
|
30
32
|
|
|
31
33
|
/**
|
|
32
34
|
* @experimental The API is not final!
|
|
@@ -46,18 +48,13 @@ export const decrypt = (key, data) =>
|
|
|
46
48
|
data
|
|
47
49
|
).then(data => new Uint8Array(data))
|
|
48
50
|
|
|
49
|
-
/**
|
|
50
|
-
* @param {CryptoKey} key
|
|
51
|
-
*/
|
|
52
|
-
export const exportKey = key =>
|
|
53
|
-
webcrypto.subtle.exportKey('jwk', key)
|
|
54
|
-
|
|
55
51
|
/**
|
|
56
52
|
* @param {Object} opts
|
|
57
53
|
* @param {boolean} [opts.extractable]
|
|
58
54
|
* @param {Usages} [opts.usages]
|
|
55
|
+
* @return {Promise<CryptoKeyPair>}
|
|
59
56
|
*/
|
|
60
|
-
export const
|
|
57
|
+
export const generateKeyPair = ({ extractable = false, usages = defaultUsages } = {}) =>
|
|
61
58
|
webcrypto.subtle.generateKey(
|
|
62
59
|
{
|
|
63
60
|
name: 'RSA-OAEP',
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"0serve.d.ts","sourceRoot":"","sources":["../../bin/0serve.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gendocs.d.ts","sourceRoot":"","sources":["../../bin/gendocs.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gentesthtml.d.ts","sourceRoot":"","sources":["../../bin/gentesthtml.js"],"names":[],"mappings":""}
|
package/dist/cache.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export function set<K, V>(cache: Cache<K, V>, key: K, value: V): void;
|
|
|
21
21
|
export function get<K, V>(cache: Cache<K, V>, key: K): V | undefined;
|
|
22
22
|
export function refreshTimeout<K, V>(cache: Cache<K, V>, key: K): void;
|
|
23
23
|
export function getAsync<K, V>(cache: Cache<K, V>, key: K): V | Promise<V> | undefined;
|
|
24
|
-
export function remove<K, V>(cache: Cache<K, V>, key: K): V | undefined;
|
|
24
|
+
export function remove<K, V>(cache: Cache<K, V>, key: K): NonNullable<V> | undefined;
|
|
25
25
|
export function setIfUndefined<K, V>(cache: Cache<K, V>, key: K, init: () => Promise<V>, removeNull?: boolean): V | Promise<V>;
|
|
26
26
|
export function create(timeout: number): Cache<any, any>;
|
|
27
27
|
import * as list from "./list.js";
|
package/dist/cache.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../cache.js"],"names":[],"mappings":"AAsCA;;GAEG;AACH;IACE;;OAEG;IACH,qBAFW,MAAM,EAYhB;IATC,gBAAsB;IACtB;;OAEG;IACH,IAFS,KAAK,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAER;IACvB;;OAEG;IACH,MAFU,IAAI,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAEL;CAE3B;AAQM,uDAFK,MAAM,CAUjB;AASM,sEAcN;AAwBM,qEAGN;AAQM,uEASN;AAYM,uFAGN;AAQM,
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../cache.js"],"names":[],"mappings":"AAsCA;;GAEG;AACH;IACE;;OAEG;IACH,qBAFW,MAAM,EAYhB;IATC,gBAAsB;IACtB;;OAEG;IACH,IAFS,KAAK,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAER;IACvB;;OAEG;IACH,MAFU,IAAI,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAEL;CAE3B;AAQM,uDAFK,MAAM,CAUjB;AASM,sEAcN;AAwBM,qEAGN;AAQM,uEASN;AAYM,uFAGN;AAQM,qFAON;AAWM,sGAHI,OAAO,kBAwBjB;AAKM,gCAFI,MAAM,mBAEkC;;AAjMnD;;;;GAIG;AACH,qCAFgB,IAAI,CAAC,QAAQ;IAG3B;;;OAGG;IACH,iBAHW,CAAC,OACD,CAAC,GAAG,QAAQ,CAAC,CAAC,EAcxB;IAXC;;OAEG;IACH,yBAAgB;IAChB;;OAEG;IACH,yBAAgB;IAChB,gBAAiC;IACjC,oBAAc;IACd,OAAc;CAEjB"}
|
package/dist/crypto/aes-gcm.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
export { exportKey } from "./common.js";
|
|
1
2
|
export function encrypt(key: CryptoKey, data: Uint8Array): Promise<Uint8Array>;
|
|
2
3
|
export function decrypt(key: CryptoKey, data: Uint8Array): PromiseLike<Uint8Array>;
|
|
3
|
-
export function exportKey(key: CryptoKey): Promise<JsonWebKey>;
|
|
4
4
|
export function importKey(jwk: any, usages?: Usages | undefined, extractable?: boolean | undefined): Promise<CryptoKey>;
|
|
5
5
|
export function deriveKey(secret: Uint8Array | string, salt: Uint8Array | string, { extractable, usages }?: {
|
|
6
6
|
extractable?: boolean | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aes-gcm.d.ts","sourceRoot":"","sources":["../../crypto/aes-gcm.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"aes-gcm.d.ts","sourceRoot":"","sources":["../../crypto/aes-gcm.js"],"names":[],"mappings":";AAuBO,6BAHI,SAAS,QACT,UAAU,uBAkBpB;AAWM,6BAJI,SAAS,QACT,UAAU,GACT,YAAY,UAAU,CAAC,CAclC;AAOM,+BAJI,GAAG,sFAUb;AAmBM,kCANI,UAAU,GAAC,MAAM,QACjB,UAAU,GAAC,MAAM;IAEF,WAAW;IACZ,MAAM;uBA0B9B;qBA3GY,MAAM,SAAS,GAAC,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../crypto/common.js"],"names":[],"mappings":"AAKO,+BAFI,SAAS,uBAMnB"}
|
package/dist/crypto/ecdsa.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { exportKey } from "./common.js";
|
|
2
2
|
export function sign(key: CryptoKey, data: Uint8Array): PromiseLike<Uint8Array>;
|
|
3
3
|
export function verify(key: CryptoKey, signature: Uint8Array, data: Uint8Array): PromiseLike<boolean>;
|
|
4
4
|
export function generateKeyPair({ extractable, usages }?: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ecdsa.d.ts","sourceRoot":"","sources":["../../crypto/ecdsa.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ecdsa.d.ts","sourceRoot":"","sources":["../../crypto/ecdsa.js"],"names":[],"mappings":";AAyBO,0BAJI,SAAS,QACT,UAAU,GACT,YAAY,UAAU,CAAC,CAWlC;AAYM,4BALI,SAAS,aACT,UAAU,QACV,UAAU,GACT,YAAY,OAAO,CAAC,CAY/B;AAQM;IAHmB,WAAW;IACZ,MAAM;2BAU5B;AAQI,+BALI,GAAG;IAEY,WAAW;IACZ,MAAM;uBAQ9B;qBA9EY,MAAM,MAAM,GAAC,QAAQ,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { exportKey } from "./common.js";
|
|
2
|
+
export function encrypt(key: CryptoKey, data: Uint8Array): PromiseLike<Uint8Array>;
|
|
2
3
|
export function decrypt(key: CryptoKey, data: Uint8Array): PromiseLike<Uint8Array>;
|
|
3
|
-
export function
|
|
4
|
-
export function generateKey({ extractable, usages }?: {
|
|
4
|
+
export function generateKeyPair({ extractable, usages }?: {
|
|
5
5
|
extractable?: boolean | undefined;
|
|
6
6
|
usages?: Usages | undefined;
|
|
7
7
|
}): Promise<CryptoKeyPair>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsa-oaep.d.ts","sourceRoot":"","sources":["../../crypto/rsa-oaep.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rsa-oaep.d.ts","sourceRoot":"","sources":["../../crypto/rsa-oaep.js"],"names":[],"mappings":";AAuBO,6BAJI,SAAS,QACT,UAAU,GACT,YAAY,UAAU,CAAC,CASC;AAW7B,6BAJI,SAAS,QACT,UAAU,GACT,YAAY,UAAU,CAAC,CASG;AAQ/B;IAJmB,WAAW;IACZ,MAAM;IACnB,QAAQ,aAAa,CAAC,CAY/B;AAQI,+BALI,GAAG;IAEY,WAAW;IACZ,MAAM;uBAQ9B;qBAxEY,MAAM,SAAS,GAAC,SAAS,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -32,7 +32,7 @@ var string = require('./string-b1bee84b.cjs');
|
|
|
32
32
|
var symbol = require('./symbol-c5caa724.cjs');
|
|
33
33
|
var time = require('./time-bc2081b9.cjs');
|
|
34
34
|
var tree = require('./tree-9f3c8837.cjs');
|
|
35
|
-
var websocket = require('./websocket-
|
|
35
|
+
var websocket = require('./websocket-e861ab50.cjs');
|
|
36
36
|
require('./storage.cjs');
|
|
37
37
|
require('./metric.cjs');
|
|
38
38
|
require('./observable.cjs');
|
package/dist/object.d.ts
CHANGED
|
@@ -5,9 +5,9 @@ export function create(): {
|
|
|
5
5
|
* Object.assign
|
|
6
6
|
*/
|
|
7
7
|
export const assign: {
|
|
8
|
-
<T, U>(target: T, source: U): T & U;
|
|
9
|
-
<T_1, U_1, V>(target: T_1, source1: U_1, source2: V): T_1 & U_1 & V;
|
|
10
|
-
<T_2, U_2, V_1, W>(target: T_2, source1: U_2, source2: V_1, source3: W): T_2 & U_2 & V_1 & W;
|
|
8
|
+
<T extends {}, U>(target: T, source: U): T & U;
|
|
9
|
+
<T_1 extends {}, U_1, V>(target: T_1, source1: U_1, source2: V): T_1 & U_1 & V;
|
|
10
|
+
<T_2 extends {}, U_2, V_1, W>(target: T_2, source1: U_2, source2: V_1, source3: W): T_2 & U_2 & V_1 & W;
|
|
11
11
|
(target: object, ...sources: any[]): any;
|
|
12
12
|
};
|
|
13
13
|
/**
|
package/dist/rollup.config.d.ts
CHANGED
package/dist/tree.test.d.ts
CHANGED
|
@@ -86,7 +86,7 @@ const setupWS = (wsclient) => {
|
|
|
86
86
|
class WebsocketClient extends observable.Observable {
|
|
87
87
|
/**
|
|
88
88
|
* @param {string} url
|
|
89
|
-
* @param {object}
|
|
89
|
+
* @param {object} opts
|
|
90
90
|
* @param {'arraybuffer' | 'blob' | null} [opts.binaryType] Set `ws.binaryType`
|
|
91
91
|
*/
|
|
92
92
|
constructor (url, { binaryType } = {}) {
|
|
@@ -153,4 +153,4 @@ var websocket = /*#__PURE__*/Object.freeze({
|
|
|
153
153
|
|
|
154
154
|
exports.WebsocketClient = WebsocketClient;
|
|
155
155
|
exports.websocket = websocket;
|
|
156
|
-
//# sourceMappingURL=websocket-
|
|
156
|
+
//# sourceMappingURL=websocket-e861ab50.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket-e861ab50.cjs","sources":["../websocket.js"],"sourcesContent":["/* eslint-env browser */\n\n/**\n * Tiny websocket connection handler.\n *\n * Implements exponential backoff reconnects, ping/pong, and a nice event system using [lib0/observable].\n *\n * @module websocket\n */\n\nimport { Observable } from './observable.js'\nimport * as time from './time.js'\nimport * as math from './math.js'\n\nconst reconnectTimeoutBase = 1200\nconst maxReconnectTimeout = 2500\n// @todo - this should depend on awareness.outdatedTime\nconst messageReconnectTimeout = 30000\n\n/**\n * @param {WebsocketClient} wsclient\n */\nconst setupWS = (wsclient) => {\n if (wsclient.shouldConnect && wsclient.ws === null) {\n const websocket = new WebSocket(wsclient.url)\n const binaryType = wsclient.binaryType\n /**\n * @type {any}\n */\n let pingTimeout = null\n if (binaryType) {\n websocket.binaryType = binaryType\n }\n wsclient.ws = websocket\n wsclient.connecting = true\n wsclient.connected = false\n websocket.onmessage = event => {\n wsclient.lastMessageReceived = time.getUnixTime()\n const data = event.data\n const message = typeof data === 'string' ? JSON.parse(data) : data\n if (message && message.type === 'pong') {\n clearTimeout(pingTimeout)\n pingTimeout = setTimeout(sendPing, messageReconnectTimeout / 2)\n }\n wsclient.emit('message', [message, wsclient])\n }\n /**\n * @param {any} error\n */\n const onclose = error => {\n if (wsclient.ws !== null) {\n wsclient.ws = null\n wsclient.connecting = false\n if (wsclient.connected) {\n wsclient.connected = false\n wsclient.emit('disconnect', [{ type: 'disconnect', error }, wsclient])\n } else {\n wsclient.unsuccessfulReconnects++\n }\n // Start with no reconnect timeout and increase timeout by\n // log10(wsUnsuccessfulReconnects).\n // The idea is to increase reconnect timeout slowly and have no reconnect\n // timeout at the beginning (log(1) = 0)\n setTimeout(setupWS, math.min(math.log10(wsclient.unsuccessfulReconnects + 1) * reconnectTimeoutBase, maxReconnectTimeout), wsclient)\n }\n clearTimeout(pingTimeout)\n }\n const sendPing = () => {\n if (wsclient.ws === websocket) {\n wsclient.send({\n type: 'ping'\n })\n }\n }\n websocket.onclose = () => onclose(null)\n websocket.onerror = error => onclose(error)\n websocket.onopen = () => {\n wsclient.lastMessageReceived = time.getUnixTime()\n wsclient.connecting = false\n wsclient.connected = true\n wsclient.unsuccessfulReconnects = 0\n wsclient.emit('connect', [{ type: 'connect' }, wsclient])\n // set ping\n pingTimeout = setTimeout(sendPing, messageReconnectTimeout / 2)\n }\n }\n}\n\n/**\n * @extends Observable<string>\n */\nexport class WebsocketClient extends Observable {\n /**\n * @param {string} url\n * @param {object} opts\n * @param {'arraybuffer' | 'blob' | null} [opts.binaryType] Set `ws.binaryType`\n */\n constructor (url, { binaryType } = {}) {\n super()\n this.url = url\n /**\n * @type {WebSocket?}\n */\n this.ws = null\n this.binaryType = binaryType || null\n this.connected = false\n this.connecting = false\n this.unsuccessfulReconnects = 0\n this.lastMessageReceived = 0\n /**\n * Whether to connect to other peers or not\n * @type {boolean}\n */\n this.shouldConnect = true\n this._checkInterval = setInterval(() => {\n if (this.connected && messageReconnectTimeout < time.getUnixTime() - this.lastMessageReceived) {\n // no message received in a long time - not even your own awareness\n // updates (which are updated every 15 seconds)\n /** @type {WebSocket} */ (this.ws).close()\n }\n }, messageReconnectTimeout / 2)\n setupWS(this)\n }\n\n /**\n * @param {any} message\n */\n send (message) {\n if (this.ws) {\n this.ws.send(JSON.stringify(message))\n }\n }\n\n destroy () {\n clearInterval(this._checkInterval)\n this.disconnect()\n super.destroy()\n }\n\n disconnect () {\n this.shouldConnect = false\n if (this.ws !== null) {\n this.ws.close()\n }\n }\n\n connect () {\n this.shouldConnect = true\n if (!this.connected && this.ws === null) {\n setupWS(this)\n }\n }\n}\n"],"names":["time.getUnixTime","math.min","math.log10","Observable"],"mappings":";;;;;;AAAA;AAaA;AACA,MAAM,oBAAoB,GAAG,KAAI;AACjC,MAAM,mBAAmB,GAAG,KAAI;AAChC;AACA,MAAM,uBAAuB,GAAG,MAAK;AACrC;AACA;AACA;AACA;AACA,MAAM,OAAO,GAAG,CAAC,QAAQ,KAAK;AAC9B,EAAE,IAAI,QAAQ,CAAC,aAAa,IAAI,QAAQ,CAAC,EAAE,KAAK,IAAI,EAAE;AACtD,IAAI,MAAM,SAAS,GAAG,IAAI,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAC;AACjD,IAAI,MAAM,UAAU,GAAG,QAAQ,CAAC,WAAU;AAC1C;AACA;AACA;AACA,IAAI,IAAI,WAAW,GAAG,KAAI;AAC1B,IAAI,IAAI,UAAU,EAAE;AACpB,MAAM,SAAS,CAAC,UAAU,GAAG,WAAU;AACvC,KAAK;AACL,IAAI,QAAQ,CAAC,EAAE,GAAG,UAAS;AAC3B,IAAI,QAAQ,CAAC,UAAU,GAAG,KAAI;AAC9B,IAAI,QAAQ,CAAC,SAAS,GAAG,MAAK;AAC9B,IAAI,SAAS,CAAC,SAAS,GAAG,KAAK,IAAI;AACnC,MAAM,QAAQ,CAAC,mBAAmB,GAAGA,gBAAgB,GAAE;AACvD,MAAM,MAAM,IAAI,GAAG,KAAK,CAAC,KAAI;AAC7B,MAAM,MAAM,OAAO,GAAG,OAAO,IAAI,KAAK,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,KAAI;AACxE,MAAM,IAAI,OAAO,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE;AAC9C,QAAQ,YAAY,CAAC,WAAW,EAAC;AACjC,QAAQ,WAAW,GAAG,UAA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AK,GAAE;AAClD,OAAO;AACP,KAAK,EAAE,uBAAuB,GAAG,CAAC,EAAC;AACnC,IAAI,OAAO,CAAC,IAAI,EAAC;AACjB,GAAG;AACH;AACA;AACA;AACA;AACA,EAAE,IAAI,CAAC,CAAC,OAAO,EAAE;AACjB,IAAI,IAAI,IAAI,CAAC,EAAE,EAAE;AACjB,MAAM,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAC;AAC3C,KAAK;AACL,GAAG;AACH;AACA,EAAE,OAAO,CAAC,GAAG;AACb,IAAI,aAAa,CAAC,IAAI,CAAC,cAAc,EAAC;AACtC,IAAI,IAAI,CAAC,UAAU,GAAE;AACrB,IAAI,KAAK,CAAC,OAAO,GAAE;AACnB,GAAG;AACH;AACA,EAAE,UAAU,CAAC,GAAG;AAChB,IAAI,IAAI,CAAC,aAAa,GAAG,MAAK;AAC9B,IAAI,IAAI,IAAI,CAAC,EAAE,KAAK,IAAI,EAAE;AAC1B,MAAM,IAAI,CAAC,EAAE,CAAC,KAAK,GAAE;AACrB,KAAK;AACL,GAAG;AACH;AACA,EAAE,OAAO,CAAC,GAAG;AACb,IAAI,IAAI,CAAC,aAAa,GAAG,KAAI;AAC7B,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,EAAE,KAAK,IAAI,EAAE;AAC7C,MAAM,OAAO,CAAC,IAAI,EAAC;AACnB,KAAK;AACL,GAAG;AACH;;;;;;;;;;"}
|
package/dist/websocket.cjs
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
require('./observable.cjs');
|
|
6
6
|
require('./time-bc2081b9.cjs');
|
|
7
7
|
require('./math-08e068f9.cjs');
|
|
8
|
-
var websocket = require('./websocket-
|
|
8
|
+
var websocket = require('./websocket-e861ab50.cjs');
|
|
9
9
|
require('./map-9a5915e4.cjs');
|
|
10
10
|
require('./set-0f209abb.cjs');
|
|
11
11
|
require('./array-a1682de6.cjs');
|
package/dist/websocket.d.ts
CHANGED
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
export class WebsocketClient extends Observable<string> {
|
|
5
5
|
/**
|
|
6
6
|
* @param {string} url
|
|
7
|
-
* @param {object}
|
|
7
|
+
* @param {object} opts
|
|
8
8
|
* @param {'arraybuffer' | 'blob' | null} [opts.binaryType] Set `ws.binaryType`
|
|
9
9
|
*/
|
|
10
10
|
constructor(url: string, { binaryType }?: {
|
|
11
11
|
binaryType?: "arraybuffer" | "blob" | null | undefined;
|
|
12
|
-
}
|
|
12
|
+
});
|
|
13
13
|
url: string;
|
|
14
14
|
/**
|
|
15
15
|
* @type {WebSocket?}
|
package/dist/websocket.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"websocket.d.ts","sourceRoot":"","sources":["../websocket.js"],"names":[],"mappings":"AAwFA;;GAEG;AACH;IACE;;;;OAIG;IACH,iBAJW,MAAM
|
|
1
|
+
{"version":3,"file":"websocket.d.ts","sourceRoot":"","sources":["../websocket.js"],"names":[],"mappings":"AAwFA;;GAEG;AACH;IACE;;;;OAIG;IACH,iBAJW,MAAM;QAE+B,UAAU;OA2BzD;IAvBC,YAAc;IACd;;OAEG;IACH,IAFU,SAAS,QAEL;IACd,0CAAoC;IACpC,mBAAsB;IACtB,oBAAuB;IACvB,+BAA+B;IAC/B,4BAA4B;IAC5B;;;OAGG;IACH,eAFU,OAAO,CAEQ;IACzB,6BAM+B;IAIjC;;OAEG;IACH,cAFW,GAAG,QAMb;IAQD,mBAKC;IAED,gBAKC;CACF"}
|
package/environment.test.d.ts
CHANGED
package/object.d.ts
CHANGED
|
@@ -5,9 +5,9 @@ export function create(): {
|
|
|
5
5
|
* Object.assign
|
|
6
6
|
*/
|
|
7
7
|
export const assign: {
|
|
8
|
-
<T, U>(target: T, source: U): T & U;
|
|
9
|
-
<T_1, U_1, V>(target: T_1, source1: U_1, source2: V): T_1 & U_1 & V;
|
|
10
|
-
<T_2, U_2, V_1, W>(target: T_2, source1: U_2, source2: V_1, source3: W): T_2 & U_2 & V_1 & W;
|
|
8
|
+
<T extends {}, U>(target: T, source: U): T & U;
|
|
9
|
+
<T_1 extends {}, U_1, V>(target: T_1, source1: U_1, source2: V): T_1 & U_1 & V;
|
|
10
|
+
<T_2 extends {}, U_2, V_1, W>(target: T_2, source1: U_2, source2: V_1, source3: W): T_2 & U_2 & V_1 & W;
|
|
11
11
|
(target: object, ...sources: any[]): any;
|
|
12
12
|
};
|
|
13
13
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lib0",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.68",
|
|
4
4
|
"description": "",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"url": "https://github.com/sponsors/dmonad"
|
|
13
13
|
},
|
|
14
14
|
"bin": {
|
|
15
|
-
"0gentesthtml": "./bin/gentesthtml.js"
|
|
15
|
+
"0gentesthtml": "./bin/gentesthtml.js",
|
|
16
|
+
"0serve": "./bin/0serve.js"
|
|
16
17
|
},
|
|
17
18
|
"exports": {
|
|
18
19
|
"./package.json": "./package.json",
|
|
@@ -414,7 +415,6 @@
|
|
|
414
415
|
"devDependencies": {
|
|
415
416
|
"@types/node": "^18.14.0",
|
|
416
417
|
"c8": "^7.13.0",
|
|
417
|
-
"http-server": "^0.12.3",
|
|
418
418
|
"jsdoc-api": "^8.0.0",
|
|
419
419
|
"jsdoc-plugin-typescript": "^2.2.1",
|
|
420
420
|
"rollup": "^2.42.1",
|
|
@@ -425,7 +425,7 @@
|
|
|
425
425
|
"clean": "rm -rf dist *.d.ts */*.d.ts *.d.ts.map */*.d.ts.map",
|
|
426
426
|
"types": "tsc --outDir .",
|
|
427
427
|
"dist": "rollup -c",
|
|
428
|
-
"debug": "npm run gentesthtml &&
|
|
428
|
+
"debug": "npm run gentesthtml && npx 0serve -o test.html",
|
|
429
429
|
"test": "c8 --check-coverage --lines 100 --branches 100 --functions 100 --statements 100 node --unhandled-rejections=strict ./test.js --repetition-time 50 --production",
|
|
430
430
|
"test-inspect": "node --inspect-brk --unhandled-rejections=strict ./test.js --repetition-time 50 --production",
|
|
431
431
|
"test-extensive": "node test.js && npm test -- --repetition-time 30000 --extensive",
|
|
@@ -435,7 +435,7 @@
|
|
|
435
435
|
"gendocs": "node ./bin/gendocs.js",
|
|
436
436
|
"preversion": "npm run clean && npm run lint && npm run test && npm run types && npm run dist && git add README.md",
|
|
437
437
|
"postpublish": "npm run clean",
|
|
438
|
-
"gentesthtml": "node ./bin/gentesthtml.js > test.html"
|
|
438
|
+
"gentesthtml": "node ./bin/gentesthtml.js --script test.js > test.html"
|
|
439
439
|
},
|
|
440
440
|
"repository": {
|
|
441
441
|
"type": "git",
|
package/rollup.config.d.ts
CHANGED
package/test.html
CHANGED
|
@@ -146,12 +146,13 @@
|
|
|
146
146
|
"lib0/webcrypto": "./webcrypto.browser.js",
|
|
147
147
|
"isomorphic.js": "./node_modules/isomorphic.js/browser.mjs",
|
|
148
148
|
"isomorphic.js/package.json": "./node_modules/isomorphic.js/package.json"
|
|
149
|
-
}
|
|
149
|
+
},
|
|
150
|
+
"scopes": {}
|
|
150
151
|
}
|
|
151
152
|
</script>
|
|
152
153
|
</head>
|
|
153
154
|
<body>
|
|
154
|
-
<script type="module" src="
|
|
155
|
+
<script type="module" src="test.js"></script>
|
|
155
156
|
</body>
|
|
156
157
|
</html>
|
|
157
158
|
|
package/tree.test.d.ts
CHANGED
package/websocket.d.ts
CHANGED
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
export class WebsocketClient extends Observable<string> {
|
|
5
5
|
/**
|
|
6
6
|
* @param {string} url
|
|
7
|
-
* @param {object}
|
|
7
|
+
* @param {object} opts
|
|
8
8
|
* @param {'arraybuffer' | 'blob' | null} [opts.binaryType] Set `ws.binaryType`
|
|
9
9
|
*/
|
|
10
10
|
constructor(url: string, { binaryType }?: {
|
|
11
11
|
binaryType?: "arraybuffer" | "blob" | null | undefined;
|
|
12
|
-
}
|
|
12
|
+
});
|
|
13
13
|
url: string;
|
|
14
14
|
/**
|
|
15
15
|
* @type {WebSocket?}
|
package/websocket.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"websocket.d.ts","sourceRoot":"","sources":["websocket.js"],"names":[],"mappings":"AAwFA;;GAEG;AACH;IACE;;;;OAIG;IACH,iBAJW,MAAM
|
|
1
|
+
{"version":3,"file":"websocket.d.ts","sourceRoot":"","sources":["websocket.js"],"names":[],"mappings":"AAwFA;;GAEG;AACH;IACE;;;;OAIG;IACH,iBAJW,MAAM;QAE+B,UAAU;OA2BzD;IAvBC,YAAc;IACd;;OAEG;IACH,IAFU,SAAS,QAEL;IACd,0CAAoC;IACpC,mBAAsB;IACtB,oBAAuB;IACvB,+BAA+B;IAC/B,4BAA4B;IAC5B;;;OAGG;IACH,eAFU,OAAO,CAEQ;IACzB,6BAM+B;IAIjC;;OAEG;IACH,cAFW,GAAG,QAMb;IAQD,mBAKC;IAED,gBAKC;CACF"}
|
package/websocket.js
CHANGED
|
@@ -92,7 +92,7 @@ const setupWS = (wsclient) => {
|
|
|
92
92
|
export class WebsocketClient extends Observable {
|
|
93
93
|
/**
|
|
94
94
|
* @param {string} url
|
|
95
|
-
* @param {object}
|
|
95
|
+
* @param {object} opts
|
|
96
96
|
* @param {'arraybuffer' | 'blob' | null} [opts.binaryType] Set `ws.binaryType`
|
|
97
97
|
*/
|
|
98
98
|
constructor (url, { binaryType } = {}) {
|