{"id":23277642,"url":"https://github.com/sonirico/naps","last_synced_at":"2025-08-21T10:32:23.992Z","repository":{"id":57643329,"uuid":"452090672","full_name":"sonirico/naps","owner":"sonirico","description":"chain nats servers with transformation \u0026 processing pipelines","archived":false,"fork":false,"pushed_at":"2022-02-27T19:43:52.000Z","size":21,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-20T04:43:02.920Z","etag":null,"topics":["deno","embedded-systems","javascript","nats","nats-client","nats-messaging","nats-server","nats-streaming","natsio","pipeline","processing","proxy-server"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/naps","language":"Rust","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/sonirico.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-01-26T00:37:19.000Z","updated_at":"2024-02-06T04:51:38.000Z","dependencies_parsed_at":"2022-09-08T08:51:09.407Z","dependency_job_id":null,"html_url":"https://github.com/sonirico/naps","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonirico%2Fnaps","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonirico%2Fnaps/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonirico%2Fnaps/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonirico%2Fnaps/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sonirico","download_url":"https://codeload.github.com/sonirico/naps/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230507051,"owners_count":18236944,"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":["deno","embedded-systems","javascript","nats","nats-client","nats-messaging","nats-server","nats-streaming","natsio","pipeline","processing","proxy-server"],"created_at":"2024-12-19T22:13:36.348Z","updated_at":"2024-12-19T22:13:37.434Z","avatar_url":"https://github.com/sonirico.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NATS proxy service\n\nSimple tool to forward specific topics from one [nats.io](https://github.com/nats-io/nats-server) cluster to the same server or \nanother. Provides support to process messages with [deno](https://github.com/denoland/deno) Javascript or\nTypeScript code.\n\n### Example\n\nImagine that we use nats.io to relay events for every confirmed or\ncanceled order in our shopping platform:\n\n```sh\n./naps --source nats://aws:4222 --destination nats://aks:4222 --topics \"orders.\u003e\"\n```\n\n### Processing Example\n\nIf the `--script` flag is present, `naps` will spawn a `Deno` runtime with all v8\ncapabilities plus promises and all event loop goodies, allowing you to, for example, only\nkeep the _confirmed_ ones and  relay them to the `myapp.orders.confirmed`. You only have to code a `recv` function\nwith the following signature:\n\n```typescript\ninterface RecvResult {\n    topic: string,\n    msg: string\n};\n\nfunction recv(topic: string, data: Uint8Array): boolean | RecvResult {\n    //... your code here...\n}\n```\n\n- If the function returns `true`, the message will be simply forwarded to the same topic. **Do note** that the message\n  will end up twice in the topic\n- If the function returns `false`, this message will be discarded\n- Finally, when `RecvResult` is returned, that data will be sent over the nats wire.\n\nExample command:\n\n```sh\n./naps --source nats://aws:4222 --destination nats://aks:4222 --topics \"myapp.v1.orders\" --script \"\n    import { Buffer } from 'http://deno.land/x/node_buffer/index.ts';\n    \n    interface Order {\n        status: 'confirmed' | 'canceled',\n        user: string,\n        amount: number,\n        item: any\n    };\n    \n    function processOrder(data: Buffer): RecvResult {\n        const orderRaw = data.toString();\n        const order = JSON.parse(orderRaw) as Order;\n        \n        // Skip orders that are not confirmed\n        if (order.status !== 'confirmed') {\n            return false;\n        }\n        return {\n            topic: 'myapp.v1.orders.confirmed',\n            msg: orderRaw\n        };\n    }\n\n    function recv(topic, uint8array) {\n        switch (topic) {\n            case \"myapp.v1.orders\":\n                return processOrder(Buffer.from(uint8array))\n            default:\n                // nothing to do...\n        }\n    }\n\"\n```\n\n# Thanks\n\n- Thanks to the rust community for such a good documentation and wide range of libraries which have made this journey\n  far easier.\n- Thanks to the [denoland](https://github.com/denoland/deno) community for pointing me into the right direction. Specially [Andreu Botella](https://github.com/andreubotella), denoland \n  contributor who patiently answered all my questions and guided me to a decent solution. Many thanks, man!\n\n# TODOs\n\n- Support for NATS TLS connections\n- JetStream \n- Feature Sagas by allowing to return multiple `RecvResult` when employing _deno_ runtime\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsonirico%2Fnaps","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsonirico%2Fnaps","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsonirico%2Fnaps/lists"}