{"_id":"@bonfire-xmpp/apibridge","_rev":"4-dbf571758817fbf93ee7ecf9e9f93f71","name":"@bonfire-xmpp/apibridge","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"@bonfire-xmpp/apibridge","main":"index.js","version":"1.0.0","scripts":{"test":"jest"},"devDependencies":{"jest":"^27.1.1"},"gitHead":"3cde87967580971463972d3c5d95d4c9aedcc2ab","description":"The purpose of this module is to provide a minimal event and function call layer\r on top of generic duplex streams. Events can be listened on using the standard\r Node `EventEmitter` interface (on/off/once/emit), and asynchronous function \r calls can be ma","_id":"@bonfire-xmpp/apibridge@1.0.0","_nodeVersion":"15.10.0","_npmVersion":"7.5.3","dist":{"integrity":"sha512-k+t+QZ4MwOg8hQBTlcAqQakmcDAePR0SOQlF/+DCOpHco/WEQIL1SqpYnzhj6bt6p860mlrbzRToChbh4O+yFA==","shasum":"a7a233228e2fe1a7b220897cacce02b594588946","tarball":"https://registry.npmjs.org/@bonfire-xmpp/apibridge/-/apibridge-1.0.0.tgz","fileCount":5,"unpackedSize":15067,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhQ8khCRA9TVsSAnZWagAAd2QP/3ch/3AJ8h3y2M/klIg1\nR0x/7pjjahQlbeWJSKWAG6rpxdhIYElC74azGom5JUI4ZjkzmEcSgooIsB4R\nURHgSvblLReem7dObDKJ6bTgDOC5D85f/wfa0bTJxhAry+Fp3zga9IjIgT1A\nzKN9K4GvYT8/wnYLqb3Edfd/Ijl8z+lBnSLRGysMO19J4CzZrXQd98M5VJm3\nFchEItxUmqtt9JU1LTtGInmlFKiA4zZn2OTpavaYp4JrXYUiMnbDGasmzgrx\nK9ZEv2ktnI0/LMu43gEidZiXInvnT+n0yFq+gW1lqK88aMaUXsmLjTQy/bMq\n3Kx1g+Cy9Zl+R80Z1OnoUZLc0svea8hNm/kFSoU73ukTyVqISaE024K4T3si\nQwFx5Usa7BjkhZgGPW82SsHT2obXQqe5sP3kCjQ+9bxamhtBZUNzoaNjzGgZ\nQH7A2DQY9NchE/mYDiajmU0aS7V3o6OjudWZwhzYahDvYSje5fCYlKZYm8Ht\nmjV6sOciQCE8r2xnZKb3nrrQ2cwS2HJc++2KaWZnklrAIntaIbo/oPOcTWpC\n7hTgcZJyeAyjIePvKdTCfZ2o31A63otozsJm7TUDZ8dy+MFFb2aiear1XbHq\n+B8CHC/y4eEkh+2W6Fwb04LOkRxnqngOjVFLrLr0+UPOc3IIh59Evj2CHcWQ\nT/qq\r\n=hABf\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDozLp1bnPgWbypobW6j17zImW35Vk7jPtE0z3/TwqkSAIgJ4vPXe6YdcVr/JT2mIA5o+qkoJIaK8nP5TcsAG/b6tE="}]},"_npmUser":{"name":"00drip","email":"rxsunshine@protonmail.com"},"directories":{},"maintainers":[{"name":"00drip","email":"rxsunshine@protonmail.com"},{"name":"misterupkeep","email":"upkeep@airmail.cc"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/apibridge_1.0.0_1631832353056_0.4166786937179636"},"_hasShrinkwrap":false},"1.0.1":{"name":"@bonfire-xmpp/apibridge","main":"index.js","types":"index.d.ts","version":"1.0.1","scripts":{"test":"jest"},"devDependencies":{"jest":"^27.1.1"},"gitHead":"aa2b311e6d2c16a55505ad2ae807140ef35584ed","description":"The purpose of this module is to provide a minimal event and function call layer\r on top of generic duplex streams. Events can be listened on using the standard\r Node `EventEmitter` interface (on/off/once/emit), and asynchronous function \r calls can be ma","_id":"@bonfire-xmpp/apibridge@1.0.1","_nodeVersion":"15.10.0","_npmVersion":"7.5.3","dist":{"integrity":"sha512-qASZ46k6q5etuzlynIfB1FNbL+COoq5LllPLO4DaUegJpyMYWMa3NfmjmnU+kr4gHghLaEXzONQXDDzTJm1cQA==","shasum":"6ffc51a734b0826f03f91907839879d78848c7f1","tarball":"https://registry.npmjs.org/@bonfire-xmpp/apibridge/-/apibridge-1.0.1.tgz","fileCount":6,"unpackedSize":15638,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDebktl2QOwRs11+BzY9NJ8MyFjZ7h/11FfiLEeWGyucgIgEjyi7zfpu4Az2MPOu5OK3lPVL86R7e4okp85F/q7fUw="}]},"_npmUser":{"name":"00drip","email":"rxsunshine@protonmail.com"},"directories":{},"maintainers":[{"name":"00drip","email":"rxsunshine@protonmail.com"},{"name":"misterupkeep","email":"upkeep@airmail.cc"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/apibridge_1.0.1_1631933796803_0.9021068198171627"},"_hasShrinkwrap":false},"1.0.2":{"name":"@bonfire-xmpp/apibridge","main":"index.js","types":"index.d.ts","version":"1.0.2","scripts":{"test":"jest"},"devDependencies":{"jest":"^27.1.1"},"gitHead":"fbbce45e8dcc4d2083a5a79a119e27f7d6e47473","description":"The purpose of this module is to provide a minimal event and function call layer\r on top of generic duplex streams. Events can be listened on using the standard\r Node `EventEmitter` interface (on/off/once/emit), and asynchronous function \r calls can be ma","_id":"@bonfire-xmpp/apibridge@1.0.2","_nodeVersion":"15.10.0","_npmVersion":"7.5.3","dist":{"integrity":"sha512-ofxwzNN5T0J1dtj4Ov4CbUjiS7nt/e+FBcvl7NHuLT+pyBzveAPJzaqO8ymlOaqGQWyIhPx3+NfM0YxF95jCBA==","shasum":"de986e70f876cd2fa46e348ea4e6a9b69029bd71","tarball":"https://registry.npmjs.org/@bonfire-xmpp/apibridge/-/apibridge-1.0.2.tgz","fileCount":6,"unpackedSize":15707,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhzZcRCRA9TVsSAnZWagAAMscP/RZFL+C7usUpPFwNWIhy\n+IHmnuUhQnwDWzy0JLAwU3Rd00d/C5W3y42iasn2oFQ2E0xZXMLtv2CdUbbE\nx85EWEmnQQ/bvddiTA6peJ3EXOg0JSQ1zY6LLig7Q6UEjemC2dcE62DCbY4V\n6reSt/8isP4i/ggzL9Iy/HuB/IMa2QdgHjiQlbUlRlTVeUwnFE2dAoyVFX5J\n3+9zHp247FCnfAEdTW+FrsuuK6dKlVIqGC8EMmRY9+egd0c9X8vok4sgH9kR\n5Saty13rhCF0ce/6i8U2CbPh8mjFidr18Awcqofu15Kbz5ybjIsiy7bbSVBJ\n5c+RFOXjRYvMhHkwBs62hBOzjd1uZ9i0ez9kQvZslPis3BcO8f2471WcVECP\nDlQDwKGyNcKWjgjBBDm40cT4Y7iqvE+fWqO+Y6DIpWPXcCRTjyyywkt7duaa\nIzC7gEbv8R8zy0nJHqZsXJIe5ld2yejZn5m7sHCTStRQjNh77IRZebrsb59b\n0oG9du2IbZXpsALYAsKv37yWD0STF3dKX6FVabxUkEmY5xOnrYFNz6cFCZfg\nAGc3UiCfb6OpCMW13NVPatOQey3bDbKTCr8EdVXtCMWkU0glxkR/0l/ZO1K7\nA/47SwK+uhShQMM6iYyxn+GEOiw41//HuYuT4drcrMVTOdKLOy+6uRZ6u7qi\nFYHV\r\n=8ufZ\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDb5brPpZhjc39sN5Npqxa/MiXK8hGxN2wRU/P1YmNQzwIhALB7awjOsAClnqvc4csrpahFZmaQJyqg4aZC1DWtt2Q2"}]},"_npmUser":{"name":"00drip","email":"rxsunshine@protonmail.com"},"directories":{},"maintainers":[{"name":"00drip","email":"rxsunshine@protonmail.com"},{"name":"misterupkeep","email":"upkeep@airmail.cc"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/apibridge_1.0.2_1632933510490_0.1931415120461628"},"_hasShrinkwrap":false}},"time":{"created":"2021-09-16T22:45:53.010Z","1.0.0":"2021-09-16T22:45:53.209Z","modified":"2022-04-04T20:06:11.064Z","1.0.1":"2021-09-18T02:56:36.958Z","1.0.2":"2021-09-29T16:38:30.627Z"},"maintainers":[{"name":"00drip","email":"rxsunshine@protonmail.com"},{"name":"misterupkeep","email":"upkeep@airmail.cc"}],"description":"The purpose of this module is to provide a minimal event and function call layer\r on top of generic duplex streams. Events can be listened on using the standard\r Node `EventEmitter` interface (on/off/once/emit), and asynchronous function \r calls can be ma","readme":"# Bonfire API Bridge\r\n\r\n## Purpose\r\n\r\nThe purpose of this module is to provide a minimal event and function call layer\r\non top of generic duplex streams. Events can be listened on using the standard\r\nNode `EventEmitter` interface (on/off/once/emit), and asynchronous function \r\ncalls can be made which resolve to their return value. The transport is \r\ndelegated to user code, so the interface works whether you're sending raw \r\nJavaScript objects (as is the case in web workers and Node IPC) or sending \r\nmsgpack/JSON over the network.\r\n\r\n## Interface\r\n\r\nThe library exports a single class:\r\n\r\n```ts\r\nclass Bridge {\r\n  // --- Event API --- //\r\n\r\n  // Listens on a given event using a callback.\r\n  //   event:    Event name to listen on.\r\n  //   callback: Callback to receive events `e`.\r\n  on(event: string, callback: (e?: any) => void): void;\r\n\r\n  // Removes one listener or all listeners from a selected event.\r\n  //   event:    Event name to remove listener from.\r\n  //   callback: The callback to remove. If none are provided, \r\n  //             all callbacks are cleared from the given event.\r\n  off(event: string, callback?: (e?: any) => void): void;\r\n  \r\n  // Listens on a given event a maximum of one time.\r\n  //   event:    Event namme to listen on.\r\n  //   callback: Callback to receive events `e`.\r\n  once(event: string, callback: (e?: any) => void): void;\r\n\r\n  // Emits an event to all remote listeners.\r\n  //   event: Name of the event to trigger.\r\n  //   e:     Event payload.\r\n  emit(event: string, e: any): void;\r\n\r\n  // --- Function API --- //\r\n\r\n  // Defines a set of named functions which can be called remotely.\r\n  define(funcs: { \r\n    [funcname: string]: (...args: any) => any \r\n  }): void;\r\n\r\n  // A proxy mapping remote function names to callable local async\r\n  // functions. Exceptions thrown by remote functions will cause \r\n  // the returned promise to be rejected.\r\n  fn: { \r\n    [funcname: string]: (...args: any) => Promise<any> \r\n  };\r\n\r\n  // --- Channel Input/Output --- //\r\n\r\n  // Causes the bridge to handle an object received from the remote \r\n  // end of the channel.\r\n  //   frame: The frame received through the channel.\r\n  async feed(frame: Array<any>): void;\r\n\r\n  // The function called by the bridge internally to send a message \r\n  // through the channel. This should be implemented by the user.\r\n  onsend: (mesg: Array<any>) => void = mesg => {};\r\n}\r\n```\r\n\r\n## Example Code\r\n\r\n```js\r\nconst { Bridge } = require(\"@bonfire-xmpp/apibridge\");\r\n\r\nconst local = new Bridge();\r\nconst remote = new Bridge();\r\n\r\nlocal.onsend = data => {\r\n  remote.feed(data);\r\n};\r\nremote.onsend = data => {\r\n  local.feed(data);\r\n};\r\n\r\n// --- Function Calls --- //\r\n\r\ndst.define({\r\n  add(x, y) {\r\n    return x + y;\r\n  }\r\n});\r\n\r\nlocal.fn.add(1, 2).then(result => console.log(result));\r\n//> 3\r\n\r\n// --- Events --- //\r\n\r\n// listen specifically to my-event\r\nlocal.on(\"my-event\", e => {\r\n  console.log(e);\r\n});\r\n// listen to all events\r\nlocal.on(\"*\", (ename, e) => {\r\n  console.log(ename, e);\r\n});\r\nremote.emit(\"my-event\", 4);\r\n//> 4\r\n//> my-event 4\r\n```","readmeFilename":"README.md"}