{"id":13493525,"url":"https://github.com/metarhia/metacom","last_synced_at":"2025-04-12T22:19:17.665Z","repository":{"id":31868132,"uuid":"129932987","full_name":"metarhia/metacom","owner":"metarhia","description":"RPC communication protocol for Metarhia stack 🔌","archived":false,"fork":false,"pushed_at":"2025-03-12T15:30:19.000Z","size":898,"stargazers_count":80,"open_issues_count":40,"forks_count":42,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-04-12T22:18:49.218Z","etag":null,"topics":["api","client","hacktoberfest","highload","impress","ipc","json","meta-edu","metarhia","node","nodejs","protocol","rest","rpc","server","stream","tcp","websocket","ws","wss"],"latest_commit_sha":null,"homepage":"https://metarhia.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/metarhia.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"patreon":"tshemsedinov"}},"created_at":"2018-04-17T16:19:40.000Z","updated_at":"2025-03-12T15:30:23.000Z","dependencies_parsed_at":"2023-11-15T02:46:09.241Z","dependency_job_id":"5feebd99-a518-47b0-96ea-4999404eadbf","html_url":"https://github.com/metarhia/metacom","commit_stats":{"total_commits":277,"total_committers":21,"mean_commits":13.19047619047619,"dds":"0.15162454873646214","last_synced_commit":"f1e3f69baafc4625f5223bb3eaaf490990e9c1ac"},"previous_names":[],"tags_count":58,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metarhia%2Fmetacom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metarhia%2Fmetacom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metarhia%2Fmetacom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metarhia%2Fmetacom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/metarhia","download_url":"https://codeload.github.com/metarhia/metacom/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248638024,"owners_count":21137586,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","client","hacktoberfest","highload","impress","ipc","json","meta-edu","metarhia","node","nodejs","protocol","rest","rpc","server","stream","tcp","websocket","ws","wss"],"created_at":"2024-07-31T19:01:16.143Z","updated_at":"2025-04-12T22:19:17.624Z","avatar_url":"https://github.com/metarhia.png","language":"JavaScript","funding_links":["https://patreon.com/tshemsedinov"],"categories":["JavaScript"],"sub_categories":[],"readme":"# Metacom Communication Protocol for Metarhia\n\n[![ci status](https://github.com/metarhia/metacom/workflows/Testing%20CI/badge.svg)](https://github.com/metarhia/metacom/actions?query=workflow%3A%22Testing+CI%22+branch%3Amaster)\n[![snyk](https://snyk.io/test/github/metarhia/metacom/badge.svg)](https://snyk.io/test/github/metarhia/metacom)\n[![npm version](https://badge.fury.io/js/metacom.svg)](https://badge.fury.io/js/metacom)\n[![npm downloads/month](https://img.shields.io/npm/dm/metacom.svg)](https://www.npmjs.com/package/metacom)\n[![npm downloads](https://img.shields.io/npm/dt/metacom.svg)](https://www.npmjs.com/package/metacom)\n\nMetacom protocol specification:\nhttps://github.com/metarhia/Contracts/blob/master/doc/Metacom.md\n\n```js\nimport { Metacom } from 'metacom';\n// const { Metacom } = require('metacom'); // for backend\n\nconst metacom = Metacom.create('ws://domainname.com:8000');\nconst { api } = metacom;\ntry {\n  await metacom.load('auth'); // Load `auth` interface\n  await api.auth.status(); // Check session status\n} catch (err) {\n  await api.auth.signIn({ login: 'marcus', password: 'marcus' });\n}\nawait metacom.load('example'); // Load `example` interface\nconst result = api.example.methodName({ arg1, arg2 });\n```\n\n## Streams over Websocket\n\n### Example: big file upload\n\nCreate `uploadFile` function on the client:\n\n```js\nconst metacom = Metacom.create('ws://example.com/api');\n\nconst uploadFile = async (file) =\u003e {\n  // createBlobUploader creates streamId and inits file reader for convenience\n  const uploader = metacom.createBlobUploader(file);\n  // Prepare backend file consumer\n  await metacom.api.files.upload({\n    streamId: uploader.streamId,\n    name: file.name,\n  });\n  // Start uploading stream and wait for its end\n  await uploader.upload();\n  return { uploadedFile: file };\n};\n```\n\nCreate API method to init file destination:\n\n```js\n// api/files/upload.js\nasync ({ streamId, name }) =\u003e {\n  const filePath = `./application/resources/${name}`;\n  // Get incoming stream by streamId sent from client\n  const readable = context.client.getStream(streamId);\n  // Create nodejs stream to write file on server\n  const writable = node.fs.createWriteStream(filePath);\n  // Pipe metacom readable to nodejs writable\n  readable.pipe(writable);\n  return { result: 'Stream initialized' };\n};\n```\n\n### Example: big file download\n\nCreate `downloadFile` function on the client:\n\n```js\nconst metacom = Metacom.create('ws://example.com/api');\n\nconst downloadFile = async (name) =\u003e {\n  // Init backend file producer to get streamId\n  const { streamId } = await metacom.api.files.download({ name });\n  // Get metacom readable stream\n  const readable = await metacom.getStream(streamId);\n  // Convert stream to blob to make a file on the client\n  const blob = await readable.toBlob();\n  return new File([blob], name);\n};\n```\n\nCreate API method to init file source:\n\n```js\n// api/files/download.js\nasync ({ name }) =\u003e {\n  const filePath = `./application/resources/${name}`;\n  // Create nodejs readable stream to read a file\n  const readable = node.fs.createReadStream(filePath);\n  // Get file size\n  const { size } = await node.fsp.stat(filePath);\n  // Create metacom writable stream\n  const writable = context.client.createStream(name, size);\n  // Pipe nodejs readable to metacom writable\n  readable.pipe(writable);\n  return { streamId: writable.streamId };\n};\n```\n\n## License \u0026 Contributors\n\nCopyright (c) 2018-2024 [Metarhia contributors](https://github.com/metarhia/metacom/graphs/contributors).\nMetacom is [MIT licensed](./LICENSE).\\\nMetacom is a part of [Metarhia](https://github.com/metarhia) technology stack.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetarhia%2Fmetacom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmetarhia%2Fmetacom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetarhia%2Fmetacom/lists"}