{"name":"abstract-extension","version":"3.1.0","description":"Small abstraction to help build out user defined extension messages in an RPC system","main":"index.js","dependencies":{"codecs":"^2.0.0"},"devDependencies":{"standard":"^14.3.1","tape":"^4.11.0"},"scripts":{"test":"standard && tape test.js"},"repository":{"type":"git","url":"git+https://github.com/mafintosh/abstract-extension.git"},"author":{"name":"Mathias Buus","url":"@mafintosh"},"license":"MIT","bugs":{"url":"https://github.com/mafintosh/abstract-extension/issues"},"homepage":"https://github.com/mafintosh/abstract-extension","gitHead":"fab8ba9c091ab9d7c1af121043085cd2ce8036a9","_id":"abstract-extension@3.1.0","_nodeVersion":"12.13.0","_npmVersion":"6.12.1","dist":{"integrity":"sha512-IhhwBFoP2l4xm0gp/YGzOfkie28OCT0X3OG4k9Zari/cM92QUU1tluUIBdhVrGXF8KrFGd8x9snuz152j6yi6A==","shasum":"104da6e40765216d60688e31ee17fed6f4ed2196","tarball":"http://registry-npm.ywwl.com/abstract-extension/download/abstract-extension-3.1.0.tgz","fileCount":5,"unpackedSize":9032,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJd3SHACRA9TVsSAnZWagAAWS4P/j25V+O18y0nwA5iM4XG\nZx/7dE+fmgDfNY2OGfTKPA6R4t+DsEm9sSiA8okZVyml8Xn8jfp6gUFc2/+n\njb7lBkECG9P1xpN5lqA30B2n/0QsnuyxWB2hheuGQCVAGIYK4sDflLh2gxym\ng/ei0w3xFparOD9t89tvXXraXCWyq/SygGhr+AszGyM/2JDFpNEFYLMAABeN\ndDfpk0Uq3ER1MSDFtFkGlVxPWONRhHPwdd+ltSpGT4HKbZ2CU7YbLB2R8Cc7\ndKuWOnSuWrBgrYSPYFLQmXzrNrE/exHebAhvm8nkW5y3k7pWGBOGmoAWiKp+\nVEPudagZB6nTQI0EH+7HPKypU1GDra8Jmnb2RSTSt/Nf3cSNOXdGanEvDhua\nDpqzrznOBrCVChFPsCgfRKAGcVY8Ve8JSnujpZBs90S+7E6Tt2TSbwMaHA6l\nYCRAwpG8kV1dnIOSnWl4LHiSP8wzVtMX5QykJ+OwtrGcVJzhQ2+x4HKPkEW1\nADgDU0Uij3Sw/szVhe5s+4DSPnGwVc4Mg8KhEIS/gLD8ghAgc1qYCuvqDwQh\nspwwKd7C8VACujZDQqm/9mEnSU9eflwfvrnlfslzPhnj3laWZbPqTA57LHO6\nTCO+L1MlglJ/yhwAeqEaIvuKAJ3cIEcJ7JP7mRstj1D4mvWqhu6V/isvaPQL\ntYTl\r\n=lU57\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCSf/MkOx1kzHiNbQsT75hUSo6QmhpVvOps1B0k0V1QogIgAh14Y/wKJ9OVSbkahRDnInoCaAndrG/jAt6Dlho35ZM="}],"size":3377,"noattachment":false,"key":"/abstract-extension/-/abstract-extension-3.1.0.tgz"},"maintainers":[{"name":"mafintosh","email":"mathiasbuus@gmail.com"}],"_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/abstract-extension_3.1.0_1574773184354_0.43591839516460906"},"_hasShrinkwrap":false,"readme":"# abstract-extension\n\nSmall abstraction to help build out user defined extension messages in an RPC system.\n\n```\nnpm install abstract-extension\n```\n\nSee [hypercore](https://github.com/mafintosh/hypercore) and [hypercore-protocol](https://github.com/mafintosh/hypercore-protocol)\nfor a full example on how to use this\n\n## API\n\n#### `const AbstractExtension = require('abstract-extension')`\n\nImports the AbstractExtension class. You should extend this and add the functionality you need.\n\n#### `abstractExtension.destroy()`\n\nDetroy an extension instance. Removes the message from the local pairing instance.\n\n#### `abstractExtension.id`\n\nThe local id of the message. Send this over the wire instead of the message name after exchanging the initial message names.\n\n#### `const bool = abstractExtension.remoteSupports()`\n\nTrue if the remote also supports this message. Note that nothing bad will having from sending a message the remote does not support.\n\n#### `const buffer = abstractExtension.encode(message)`\n\nEncode a message to a buffer based on the message encoding.\n\n#### `const local = AbstractExtension.createLocal(handlers)`\n\nCreate a local message pairing instance.\n\nWhenever the messages are updated `local.onextensionupdate()` will be called if provided.\n\n#### `const msg = local.add(name, handlers)`\n\nAdd a new message. `name` should be the string name of a message.\n\n* `handlers.encoding` is an optional encoding for the message payload. Can be either `json`, `utf-8`, `binary` or any abstract encoding.\n* `handlers.onmessage(message, context)` is called when a message has been received and pairing.\n* `handlers.onerror(error, context)` is called when a message fails to decode.\n\n#### `const list = local.names()`\n\nReturns a sorted list of message names. You need to pass this to another remote pairing instance somehow.\n\n#### `const remote = local.remote()`\n\nCall this to setup remote pairing.\n\n#### `remote.update(localNames)`\n\nPass the names of another instance to setup the pairing\n\n#### `remote.onmessage(id, message, [context])`\n\nPair the remote id with the corresponding local message and call the onmessage handler.\nOptionally pass a context object that is simply passed along to the `message.onmessage` function\n\n## License\n\nMIT\n","publish_time":1574773184451,"_cnpm_publish_time":1574773184451,"dist-tags":{"latest":"3.1.1"}}