{"bugs":{"url":"https://github.com/streamr-dev/streamr-client-protocol-js/issues"},"dist":{"shasum":"f3ccd6996dd745866285dc801978dcf8178281c1","tarball":"https://registry.npmjs.org/streamr-client-protocol/-/streamr-client-protocol-3.0.0-0.tgz","fileCount":128,"integrity":"sha512-L5Ct2pgQkRigUGI6nk86+lC9ftWIAyIRcY8n9kt1k8yRlwti6QHHwg3ib7FidhmG4wjHDjouTbe1wKdazmUXRw==","signatures":[{"sig":"MEUCIQCqi4hDyYaQcS1eGVDHDZOG3OpkPmML7UluBpAZPMsuJgIgQ6d3bRahaZPwdMQDp5e3xfEqIWCM+tbszgZiBadA3fo=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1538921,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJd0o2SCRA9TVsSAnZWagAAkC4P/jTwLf3IXAzkNUqQxzNe\neJc75EgWaKkz2WnlHZhFrJ8/2CGsK5l9X7XQb8tDbHeWzLLt7pDS+g4d5X04\n63Ll3DW9lFCib113cpn8kqu8MDIXoIOOlw/BDJnNBMUBvFFEva5bAGjr7tNi\nV5i74NWlXhNkXq2XfUl+3O3NQX8WZrBRRuuLStxZngL9XpKMIm1ZNwb2UAlS\nIZOpcwkWYy19u60wymjktqwYhWDs0c8M7Fw7VPZIH8WrqDBYGZ5Z7hp9ooMO\n43QdU9+YLnrQSn8nfXHmVIPBbXCFD5MGeDQwyeEPNt54tWfQGlSu7w0578Uo\ncBWGsPvM+GOPGFA1Zk7E4USResSdj/3Ob/Z5wy7VIqOsgpNsWYvn0HnbUntK\ndaiErENjM9ABg7I14TCPev+nD4aMpap+oOkOxqOJNv5szzTXLfiJ8Vp1J0VC\nQ9so6L3Zadvg5nHkCF+/xfQqGTKS0a1Y3KhZu1jbHrTwZ+tX4Fz72rnaMIk4\nX68zI895ygUbsvMTQ4DfsXwbNcQXRmj0gF6c9VaF2EySHl3olGulMBY1D9Qc\nKyG9HMDnWV959xsBBjBvCAGTnmchbrb7XMS/4AsDkgjckWhNkrx3tuRF/hvI\nwWrJsYAgdXdOSw4D2td7Rtt+WEclUs7Om5VYJc0EyWl3gNNAhR3gxW1MWVHc\nUMaE\r\n=p9rF\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/streamr-client-protocol.js","name":"streamr-client-protocol","author":{"name":"Streamr"},"module":"src/index.js","readme":"[![Build Status](https://travis-ci.com/streamr-dev/streamr-client-protocol-js.svg?branch=master)](https://travis-ci.com/streamr-dev/streamr-client-protocol-js)\n\nThis repository contains ES6 JS implementations of the Streamr [protocol](PROTOCOL.md) messages. This is shared code used by:\n \n - [streamr-client-javascript](https://github.com/streamr-dev/streamr-client-javascript)\n - [data-api](https://github.com/streamr-dev/data-api)\n - [broker](https://github.com/streamr-dev/broker)\n \n This package is available on npm as `streamr-client-protocol`.\n\n### Usage\n\nThis section describes how to use the Javascript implementation of the [protocol](PROTOCOL.md).\n\n#### Creating messages from arguments\n\nEvery message type from both the Control Layer and the Message Layer is defined as a class and has a static `create` method that takes class-specific arguments to build an instance of the latest version of the message type. The arguments for each message type are defined in the [protocol documentation](PROTOCOL.md) and in the definition of the `create` method.\n\nThis example shows how to build a `StreamMessage` and encapsulate it in a  `UnicastMessage`.\n\n```javascript\nconst content = {\n    foo: 'bar',\n}\n// arguments in order: stream id, stream partition, timestamp, sequence number, publisher id, message chain id,\n// previous message reference, content type, content, signature type, signature\nconst streamMessage = StreamMessage.create(['streamId', 0, Date.now(), 0, 'publisherId', 'msgChainId'],\n                                             null, StreamMessage.CONTENT_TYPES.JSON, content,\n                                             StreamMessage.SIGNATURE_TYPES.NONE, null)\nconst unicastMessage = UnicastMessage.create(\"subscriptionId\", streamMessage)\n```\n\n#### Serializing messages to JSON arrays or strings\n\nEvery message type from both the Control Layer and the Message Layer has a `serialize` method that takes different optional arguments depending on the message type. For every message type, the first argument is the version of the resulting serialized message. By default, it serializes to the latest version of the message type and the result is a string.\n\n```javascript\nconst streamMessage = StreamMessage.create(...)\nstreamMessage.serialize()\n// > '[30,[\"streamId\",0,1529549961116,\"publisherId\",\"msgChainId\"],null,27,{\"foo\":\"bar\"},0,null]'\nstreamMessage.serialize(29, {\n    stringify: false\n})\n// > [29, 'streamId', 0, 1529549961116, 0, 1529549961116, null, 27, {valid: \"json\"}, 0, null, null]\n\nconst subscribeRequest = SubscribeRequest.create('streamId', 0, 'sessionToken')\nsubscribeRequest.serialize()\n// > '[1,9,\"streamId\",0,\"sessionToken\"]'\n```\n\n#### Parsing messages from JSON arrays or strings\n\nFor deserialization, use the static `deserialize` method that is present in `ControlMessage` for the ControlLayer and `StreamMessageFactory` for the Message Layer. The `deserialize` method accepts both strings and arrays as input.\n\nThe Message Layer only has one type of message (`StreamMessage`), so we know that the `deserialize` function will return a `StreamMessage` and all the functions and fields of this class can be used. Some functions might be defined only for some specific versions like `StreamMessageV30`, in that case use the `version` field to differentiate.\n\n```javascript\nconst serializedMessage = '[30,[\"streamId\",0,1529549961116,\"publisherId\",\"msgChainId\"],null,27,{\"foo\":\"bar\"},0,null]'\nconst streamMessage = StreamMessageFactory.deserialize(serializedMessage)\n// use functions/fields present in all versions\nif (streamMessage.version === 30) {\n    // treat it as a StreamMessageV30\n} else if (streamMessage.version === 29) {\n    // treat it as a StreamMessageV29\n}\n``` \n\nOn the other hand, the Control Layer has many different message types. So we can only know that the `deserialize` method will return a `ControlMessage`. We can use the `type` field to differentiate.\n\n```javascript\nconst serializedMessage = '[1,9,\"streamId\",0,\"sessionToken\"]'\nconst controlMessage = ControlMessage.deserialize(serializedMessage)\nif (controlMessage.type === UnicastMessage.TYPE) {\n    //treat it as a UnicastMessage\n} else if (controlMessage.type === SubscribeRequest.TYPE) {\n    //treat it as a SubscribeRequest\n} else if (...) {\n    \n} else {\n    throw new Error(`Unknown type: ${controlMessage.type}`)\n}\n```\n","engines":{"node":">= 8"},"gitHead":"5faf02f89ffb59494b39636ebc8cd8e1c5e6d0df","license":"Apache-2.0","scripts":{"dev":"webpack --progress --colors --watch","test":"jest","build":"NODE_ENV=production webpack","eslint":"eslint src/** test/**","prepare":"npm run build","pretest":"npm run eslint"},"_npmUser":{"name":"harbu","email":"harbuzen@gmail.com"},"homepage":"https://github.com/streamr-dev/streamr-client-protocol-js#readme","repository":{"url":"git://github.com/streamr-dev/streamr-client-protocol-js.git","type":"git"},"_npmVersion":"6.11.3","description":"JavaScript classes implementing the Streamr client-to-node protocol","directories":{"test":"test"},"maintainers":[{"name":"fonty1","email":"mr.matto@gmail.com"},{"name":"harbu","email":"harbuzen@gmail.com"},{"name":"hpihkala","email":"henri.pihkala@streamr.com"},{"name":"jtakalai","email":"juuso.takalainen@streamr.com"},{"name":"juhah","email":"juha.haavisto@streamr.com"},{"name":"juslesan","email":"santeri.juslenius@gmail.com"},{"name":"jwolff","email":"jwolff@isentropy.com"},{"name":"kare","email":"kare.nuorteva@me.com"},{"name":"mariusz_io","email":"mariusz@mariusz.io"},{"name":"mirpo","email":"miroslavpokrovskiy@gmail.com"},{"name":"mk_streamr","email":"mikhael.santos@streamr.com"},{"name":"mmartinmo","email":"martin.moravek@streamr.com"},{"name":"mthambipillai","email":"melkiorthambipillai@gmail.com"},{"name":"pzsavola","email":"petri.savolainen@spaceify.net"},{"name":"timoxley","email":"secoif@gmail.com"},{"name":"tumppi","email":"tuomas.koponen@streamr.com"}],"_nodeVersion":"10.17.0","dependencies":{"heap":"^0.2.6","debug":"^3.1.0","eventemitter3":"^4.0.0","@babel/runtime-corejs3":"^7.4.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"chai":"^4.1.2","jest":"^24.8.0","sinon":"^6.3.5","eslint":"^4.19.1","lodash":"^4.17.10","core-js":"^3.1.3","webpack":"^3.10.0","@babel/cli":"^7.4.4","babel-jest":"^24.8.0","@babel/core":"^7.4.5","babel-eslint":"^10.0.1","babel-loader":"^8.0.0","array-shuffle":"^1.0.1","eslint-loader":"^1.9.0","@babel/preset-env":"^7.4.5","eslint-plugin-react":"^7.7.0","eslint-config-airbnb":"^16.1.0","eslint-plugin-import":"^2.10.0","eslint-config-streamr":"^1.1.7","eslint-plugin-flowtype":"^2.46.1","eslint-plugin-jsx-a11y":"^6.0.3","uglifyjs-webpack-plugin":"^1.2.4","@babel/plugin-transform-runtime":"^7.4.4","@babel/plugin-syntax-import-meta":"^7.2.0","@babel/plugin-proposal-json-strings":"^7.2.0","@babel/plugin-syntax-dynamic-import":"^7.2.0","@babel/plugin-proposal-function-sent":"^7.2.0","@babel/plugin-proposal-class-properties":"^7.4.4","@babel/plugin-proposal-numeric-separator":"^7.2.0","@babel/plugin-proposal-throw-expressions":"^7.2.0","@babel/plugin-proposal-export-namespace-from":"^7.2.0"},"_npmOperationalInternal":{"tmp":"tmp/streamr-client-protocol_3.0.0-0_1574079890216_0.5087422908956827","host":"s3://npm-registry-packages"},"_id":"streamr-client-protocol@3.0.0-0","version":"3.0.0-0"}