@libp2p/mplex 9.0.9-d5ef1c91 → 9.0.10-051154dd
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/README.md +2 -40
- package/dist/index.min.js +1 -1
- package/dist/src/index.d.ts +32 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +32 -0
- package/dist/src/index.js.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +33 -0
package/README.md
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# @libp2p/mplex <!-- omit in toc -->
|
2
|
-
|
3
1
|
[](http://libp2p.io/)
|
4
2
|
[](https://discuss.libp2p.io)
|
5
3
|
[](https://codecov.io/gh/libp2p/js-libp2p)
|
@@ -7,22 +5,13 @@
|
|
7
5
|
|
8
6
|
> JavaScript implementation of <https://github.com/libp2p/mplex>
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
- [Install](#install)
|
13
|
-
- [Browser `<script>` tag](#browser-script-tag)
|
14
|
-
- [Usage](#usage)
|
15
|
-
- [API Docs](#api-docs)
|
16
|
-
- [License](#license)
|
17
|
-
- [Contribution](#contribution)
|
18
|
-
|
19
|
-
## Install
|
8
|
+
# Install
|
20
9
|
|
21
10
|
```console
|
22
11
|
$ npm i @libp2p/mplex
|
23
12
|
```
|
24
13
|
|
25
|
-
|
14
|
+
## Browser `<script>` tag
|
26
15
|
|
27
16
|
Loading this module through a script tag will make it's exports available as `Libp2pMplex` in the global namespace.
|
28
17
|
|
@@ -30,33 +19,6 @@ Loading this module through a script tag will make it's exports available as `Li
|
|
30
19
|
<script src="https://unpkg.com/@libp2p/mplex/dist/index.min.js"></script>
|
31
20
|
```
|
32
21
|
|
33
|
-
[](https://github.com/libp2p/interface-stream-muxer)
|
34
|
-
|
35
|
-
## Usage
|
36
|
-
|
37
|
-
```js
|
38
|
-
import { mplex } from '@libp2p/mplex'
|
39
|
-
import { pipe } from 'it-pipe'
|
40
|
-
|
41
|
-
const factory = mplex()
|
42
|
-
|
43
|
-
const muxer = factory.createStreamMuxer(components, {
|
44
|
-
onStream: stream => { // Receive a duplex stream from the remote
|
45
|
-
// ...receive data from the remote and optionally send data back
|
46
|
-
},
|
47
|
-
onStreamEnd: stream => {
|
48
|
-
// ...handle any tracking you may need of stream closures
|
49
|
-
}
|
50
|
-
})
|
51
|
-
|
52
|
-
pipe(conn, muxer, conn) // conn is duplex connection to another peer
|
53
|
-
|
54
|
-
const stream = muxer.newStream() // Create a new duplex stream to the remote
|
55
|
-
|
56
|
-
// Use the duplex stream to send some data to the remote...
|
57
|
-
pipe([1, 2, 3], stream)
|
58
|
-
```
|
59
|
-
|
60
22
|
## API Docs
|
61
23
|
|
62
24
|
- <https://libp2p.github.io/js-libp2p/modules/_libp2p_mplex.html>
|
package/dist/index.min.js
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
expire = ?;`,d=[this.dbName,this.tableName,t,r,u,r,u]):(l=`INSERT INTO ??.?? VALUES (?, ?, ?)
|
6
6
|
ON DUPLICATE KEY UPDATE
|
7
7
|
points = IF(expire <= ?, ?, points + (?)),
|
8
|
-
expire = IF(expire <= ?, ?, expire);`,d=[this.dbName,this.tableName,t,r,u,h,r,r,h,u]),e.query(l,d,g=>{if(g)return e.rollback(),a(g);e.query("SELECT points, expire FROM ??.?? WHERE `key` = ?;",[this.dbName,this.tableName,t],(m,p)=>{if(m)return e.rollback(),a(m);e.query("COMMIT",f=>{if(f)return e.rollback(),a(f);o(p)})})})})})}_upsert(e,t,r,s=!1){return this.tableCreated?new Promise((n,o)=>{this._getConnection().then(a=>{this._upsertTransaction(a,e,t,r,s).then(c=>{n(c),this._releaseConnection(a)}).catch(c=>{o(c),this._releaseConnection(a)})}).catch(a=>{o(a)})}):Promise.reject(Error("Table is not created yet"))}_get(e){return this.tableCreated?new Promise((t,r)=>{this._getConnection().then(s=>{s.query("SELECT points, expire FROM ??.?? WHERE `key` = ? AND (`expire` > ? OR `expire` IS NULL)",[this.dbName,this.tableName,e,Date.now()],(n,o)=>{n?r(n):o.length===0?t(null):t(o),this._releaseConnection(s)})}).catch(s=>{r(s)})}):Promise.reject(Error("Table is not created yet"))}_delete(e){return this.tableCreated?new Promise((t,r)=>{this._getConnection().then(s=>{s.query("DELETE FROM ??.?? WHERE `key` = ?",[this.dbName,this.tableName,e],(n,o)=>{n?r(n):t(o.affectedRows>0),this._releaseConnection(s)})}).catch(s=>{r(s)})}):Promise.reject(Error("Table is not created yet"))}};lr.exports=He});var fr=w((Ko,dr)=>{var fs=te(),ms=k(),Ye=class extends fs{constructor(e,t=null){super(e),this.client=e.storeClient,this.clientType=e.storeType,this.tableName=e.tableName,this.schemaName=e.schemaName,this.clearExpiredByTimeout=e.clearExpiredByTimeout,this.tableCreated=e.tableCreated,this.tableCreated?typeof t=="function"&&t():this._createTable().then(()=>{this.tableCreated=!0,this.clearExpiredByTimeout&&this._clearExpiredHourAgo(),typeof t=="function"&&t()}).catch(r=>{if(typeof t=="function")t(r);else throw r})}_getTableIdentifier(){return this.schemaName?`"${this.schemaName}"."${this.tableName}"`:`"${this.tableName}"`}clearExpired(e){return new Promise(t=>{let r={name:"rlflx-clear-expired",text:`DELETE FROM ${this._getTableIdentifier()} WHERE expire < $1`,values:[e]};this._query(r).then(()=>{t()}).catch(()=>{t()})})}_clearExpiredHourAgo(){this._clearExpiredTimeoutId&&clearTimeout(this._clearExpiredTimeoutId),this._clearExpiredTimeoutId=setTimeout(()=>{this.clearExpired(Date.now()-36e5).then(()=>{this._clearExpiredHourAgo()})},3e5),this._clearExpiredTimeoutId.unref()}_getConnection(){switch(this.clientType){case"pool":return Promise.resolve(this.client);case"sequelize":return this.client.connectionManager.getConnection();case"knex":return this.client.client.acquireConnection();case"typeorm":return Promise.resolve(this.client.driver.master);default:return Promise.resolve(this.client)}}_releaseConnection(e){switch(this.clientType){case"pool":return!0;case"sequelize":return this.client.connectionManager.releaseConnection(e);case"knex":return this.client.client.releaseConnection(e);case"typeorm":return!0;default:return!0}}_createTable(){return new Promise((e,t)=>{this._query({text:this._getCreateTableStmt()}).then(()=>{e()}).catch(r=>{r.code==="23505"?e():t(r)})})}_getCreateTableStmt(){return`CREATE TABLE IF NOT EXISTS ${this._getTableIdentifier()} (
|
8
|
+
expire = IF(expire <= ?, ?, expire);`,d=[this.dbName,this.tableName,t,r,u,h,r,r,h,u]),e.query(l,d,g=>{if(g)return e.rollback(),a(g);e.query("SELECT points, expire FROM ??.?? WHERE `key` = ?;",[this.dbName,this.tableName,t],(m,p)=>{if(m)return e.rollback(),a(m);e.query("COMMIT",f=>{if(f)return e.rollback(),a(f);o(p)})})})})})}_upsert(e,t,r,s=!1){return this.tableCreated?new Promise((n,o)=>{this._getConnection().then(a=>{this._upsertTransaction(a,e,t,r,s).then(c=>{n(c),this._releaseConnection(a)}).catch(c=>{o(c),this._releaseConnection(a)})}).catch(a=>{o(a)})}):Promise.reject(Error("Table is not created yet"))}_get(e){return this.tableCreated?new Promise((t,r)=>{this._getConnection().then(s=>{s.query("SELECT points, expire FROM ??.?? WHERE `key` = ? AND (`expire` > ? OR `expire` IS NULL)",[this.dbName,this.tableName,e,Date.now()],(n,o)=>{n?r(n):o.length===0?t(null):t(o),this._releaseConnection(s)})}).catch(s=>{r(s)})}):Promise.reject(Error("Table is not created yet"))}_delete(e){return this.tableCreated?new Promise((t,r)=>{this._getConnection().then(s=>{s.query("DELETE FROM ??.?? WHERE `key` = ?",[this.dbName,this.tableName,e],(n,o)=>{n?r(n):t(o.affectedRows>0),this._releaseConnection(s)})}).catch(s=>{r(s)})}):Promise.reject(Error("Table is not created yet"))}};lr.exports=He});var fr=w((Ko,dr)=>{var fs=te(),ms=k(),Ye=class extends fs{constructor(e,t=null){super(e),this.client=e.storeClient,this.clientType=e.storeType,this.tableName=e.tableName,this.schemaName=e.schemaName,this.clearExpiredByTimeout=e.clearExpiredByTimeout,this.tableCreated=e.tableCreated,this.tableCreated?(this.clearExpiredByTimeout&&this._clearExpiredHourAgo(),typeof t=="function"&&t()):this._createTable().then(()=>{this.tableCreated=!0,this.clearExpiredByTimeout&&this._clearExpiredHourAgo(),typeof t=="function"&&t()}).catch(r=>{if(typeof t=="function")t(r);else throw r})}_getTableIdentifier(){return this.schemaName?`"${this.schemaName}"."${this.tableName}"`:`"${this.tableName}"`}clearExpired(e){return new Promise(t=>{let r={name:"rlflx-clear-expired",text:`DELETE FROM ${this._getTableIdentifier()} WHERE expire < $1`,values:[e]};this._query(r).then(()=>{t()}).catch(()=>{t()})})}_clearExpiredHourAgo(){this._clearExpiredTimeoutId&&clearTimeout(this._clearExpiredTimeoutId),this._clearExpiredTimeoutId=setTimeout(()=>{this.clearExpired(Date.now()-36e5).then(()=>{this._clearExpiredHourAgo()})},3e5),this._clearExpiredTimeoutId.unref()}_getConnection(){switch(this.clientType){case"pool":return Promise.resolve(this.client);case"sequelize":return this.client.connectionManager.getConnection();case"knex":return this.client.client.acquireConnection();case"typeorm":return Promise.resolve(this.client.driver.master);default:return Promise.resolve(this.client)}}_releaseConnection(e){switch(this.clientType){case"pool":return!0;case"sequelize":return this.client.connectionManager.releaseConnection(e);case"knex":return this.client.client.releaseConnection(e);case"typeorm":return!0;default:return!0}}_createTable(){return new Promise((e,t)=>{this._query({text:this._getCreateTableStmt()}).then(()=>{e()}).catch(r=>{r.code==="23505"?e():t(r)})})}_getCreateTableStmt(){return`CREATE TABLE IF NOT EXISTS ${this._getTableIdentifier()} (
|
9
9
|
key varchar(255) PRIMARY KEY,
|
10
10
|
points integer NOT NULL DEFAULT 0,
|
11
11
|
expire bigint
|
package/dist/src/index.d.ts
CHANGED
@@ -1,3 +1,35 @@
|
|
1
|
+
/**
|
2
|
+
* @packageDocumentation
|
3
|
+
*
|
4
|
+
* This is a [simple stream multiplexer(https://docs.libp2p.io/concepts/multiplex/mplex/) that has been deprecated.
|
5
|
+
*
|
6
|
+
* Please use [@chainsafe/libp2p-yamux](https://www.npmjs.com/package/@chainsafe/libp2p-yamux) instead.
|
7
|
+
*
|
8
|
+
* @example
|
9
|
+
*
|
10
|
+
* ```js
|
11
|
+
* import { mplex } from '@libp2p/mplex'
|
12
|
+
* import { pipe } from 'it-pipe'
|
13
|
+
*
|
14
|
+
* const factory = mplex()
|
15
|
+
*
|
16
|
+
* const muxer = factory.createStreamMuxer(components, {
|
17
|
+
* onStream: stream => { // Receive a duplex stream from the remote
|
18
|
+
* // ...receive data from the remote and optionally send data back
|
19
|
+
* },
|
20
|
+
* onStreamEnd: stream => {
|
21
|
+
* // ...handle any tracking you may need of stream closures
|
22
|
+
* }
|
23
|
+
* })
|
24
|
+
*
|
25
|
+
* pipe(conn, muxer, conn) // conn is duplex connection to another peer
|
26
|
+
*
|
27
|
+
* const stream = muxer.newStream() // Create a new duplex stream to the remote
|
28
|
+
*
|
29
|
+
* // Use the duplex stream to send some data to the remote...
|
30
|
+
* pipe([1, 2, 3], stream)
|
31
|
+
* ```
|
32
|
+
*/
|
1
33
|
import type { StreamMuxerFactory } from '@libp2p/interface/stream-muxer';
|
2
34
|
export interface MplexInit {
|
3
35
|
/**
|
package/dist/src/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAGH,OAAO,KAAK,EAAe,kBAAkB,EAAmB,MAAM,gCAAgC,CAAA;AAEtG,MAAM,WAAW,SAAS;IACxB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IAEnB;;;;;;OAMG;IACH,8BAA8B,CAAC,EAAE,MAAM,CAAA;IAEvC;;;;;;;;;OASG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAE1B;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAE3B;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAE5B;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAA;CAC7B;AAkBD,wBAAgB,KAAK,CAAE,IAAI,GAAE,SAAc,GAAG,MAAM,kBAAkB,CAErE"}
|
package/dist/src/index.js
CHANGED
@@ -1,3 +1,35 @@
|
|
1
|
+
/**
|
2
|
+
* @packageDocumentation
|
3
|
+
*
|
4
|
+
* This is a [simple stream multiplexer(https://docs.libp2p.io/concepts/multiplex/mplex/) that has been deprecated.
|
5
|
+
*
|
6
|
+
* Please use [@chainsafe/libp2p-yamux](https://www.npmjs.com/package/@chainsafe/libp2p-yamux) instead.
|
7
|
+
*
|
8
|
+
* @example
|
9
|
+
*
|
10
|
+
* ```js
|
11
|
+
* import { mplex } from '@libp2p/mplex'
|
12
|
+
* import { pipe } from 'it-pipe'
|
13
|
+
*
|
14
|
+
* const factory = mplex()
|
15
|
+
*
|
16
|
+
* const muxer = factory.createStreamMuxer(components, {
|
17
|
+
* onStream: stream => { // Receive a duplex stream from the remote
|
18
|
+
* // ...receive data from the remote and optionally send data back
|
19
|
+
* },
|
20
|
+
* onStreamEnd: stream => {
|
21
|
+
* // ...handle any tracking you may need of stream closures
|
22
|
+
* }
|
23
|
+
* })
|
24
|
+
*
|
25
|
+
* pipe(conn, muxer, conn) // conn is duplex connection to another peer
|
26
|
+
*
|
27
|
+
* const stream = muxer.newStream() // Create a new duplex stream to the remote
|
28
|
+
*
|
29
|
+
* // Use the duplex stream to send some data to the remote...
|
30
|
+
* pipe([1, 2, 3], stream)
|
31
|
+
* ```
|
32
|
+
*/
|
1
33
|
import { MplexStreamMuxer } from './mplex.js';
|
2
34
|
class Mplex {
|
3
35
|
protocol = '/mplex/6.7.0';
|
package/dist/src/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AA8D7C,MAAM,KAAK;IACF,QAAQ,GAAG,cAAc,CAAA;IACf,KAAK,CAAW;IAEjC,YAAa,OAAkB,EAAE;QAC/B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;IACnB,CAAC;IAED,iBAAiB,CAAE,OAAwB,EAAE;QAC3C,OAAO,IAAI,gBAAgB,CAAC;YAC1B,GAAG,IAAI;YACP,GAAG,IAAI,CAAC,KAAK;SACd,CAAC,CAAA;IACJ,CAAC;CACF;AAED,MAAM,UAAU,KAAK,CAAE,OAAkB,EAAE;IACzC,OAAO,GAAG,EAAE,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,CAAA;AAC9B,CAAC"}
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AA8D7C,MAAM,KAAK;IACF,QAAQ,GAAG,cAAc,CAAA;IACf,KAAK,CAAW;IAEjC,YAAa,OAAkB,EAAE;QAC/B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;IACnB,CAAC;IAED,iBAAiB,CAAE,OAAwB,EAAE;QAC3C,OAAO,IAAI,gBAAgB,CAAC;YAC1B,GAAG,IAAI;YACP,GAAG,IAAI,CAAC,KAAK;SACd,CAAC,CAAA;IACJ,CAAC;CACF;AAED,MAAM,UAAU,KAAK,CAAE,OAAkB,EAAE;IACzC,OAAO,GAAG,EAAE,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,CAAA;AAC9B,CAAC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@libp2p/mplex",
|
3
|
-
"version": "9.0.
|
3
|
+
"version": "9.0.10-051154dd",
|
4
4
|
"description": "JavaScript implementation of https://github.com/libp2p/mplex",
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/master/packages/stream-multiplexer-mplex#readme",
|
@@ -57,8 +57,8 @@
|
|
57
57
|
"test:electron-main": "aegir test -t electron-main"
|
58
58
|
},
|
59
59
|
"dependencies": {
|
60
|
-
"@libp2p/interface": "0.1.
|
61
|
-
"@libp2p/logger": "3.0.
|
60
|
+
"@libp2p/interface": "0.1.5-051154dd",
|
61
|
+
"@libp2p/logger": "3.0.5-051154dd",
|
62
62
|
"abortable-iterator": "^5.0.1",
|
63
63
|
"benchmark": "^2.1.4",
|
64
64
|
"it-batched-bytes": "^2.0.2",
|
@@ -70,7 +70,7 @@
|
|
70
70
|
"uint8arrays": "^4.0.6"
|
71
71
|
},
|
72
72
|
"devDependencies": {
|
73
|
-
"@libp2p/interface-compliance-tests": "4.1.
|
73
|
+
"@libp2p/interface-compliance-tests": "4.1.3-051154dd",
|
74
74
|
"aegir": "^41.0.2",
|
75
75
|
"cborg": "^4.0.3",
|
76
76
|
"delay": "^6.0.0",
|
package/src/index.ts
CHANGED
@@ -1,3 +1,36 @@
|
|
1
|
+
/**
|
2
|
+
* @packageDocumentation
|
3
|
+
*
|
4
|
+
* This is a [simple stream multiplexer(https://docs.libp2p.io/concepts/multiplex/mplex/) that has been deprecated.
|
5
|
+
*
|
6
|
+
* Please use [@chainsafe/libp2p-yamux](https://www.npmjs.com/package/@chainsafe/libp2p-yamux) instead.
|
7
|
+
*
|
8
|
+
* @example
|
9
|
+
*
|
10
|
+
* ```js
|
11
|
+
* import { mplex } from '@libp2p/mplex'
|
12
|
+
* import { pipe } from 'it-pipe'
|
13
|
+
*
|
14
|
+
* const factory = mplex()
|
15
|
+
*
|
16
|
+
* const muxer = factory.createStreamMuxer(components, {
|
17
|
+
* onStream: stream => { // Receive a duplex stream from the remote
|
18
|
+
* // ...receive data from the remote and optionally send data back
|
19
|
+
* },
|
20
|
+
* onStreamEnd: stream => {
|
21
|
+
* // ...handle any tracking you may need of stream closures
|
22
|
+
* }
|
23
|
+
* })
|
24
|
+
*
|
25
|
+
* pipe(conn, muxer, conn) // conn is duplex connection to another peer
|
26
|
+
*
|
27
|
+
* const stream = muxer.newStream() // Create a new duplex stream to the remote
|
28
|
+
*
|
29
|
+
* // Use the duplex stream to send some data to the remote...
|
30
|
+
* pipe([1, 2, 3], stream)
|
31
|
+
* ```
|
32
|
+
*/
|
33
|
+
|
1
34
|
import { MplexStreamMuxer } from './mplex.js'
|
2
35
|
import type { StreamMuxer, StreamMuxerFactory, StreamMuxerInit } from '@libp2p/interface/stream-muxer'
|
3
36
|
|