{"id":20812529,"url":"https://github.com/superstreamlabs/memphis-functions.js","last_synced_at":"2026-04-29T03:02:48.749Z","repository":{"id":208785981,"uuid":"722440630","full_name":"superstreamlabs/memphis-functions.js","owner":"superstreamlabs","description":null,"archived":false,"fork":false,"pushed_at":"2024-01-07T21:52:02.000Z","size":40,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-12-30T11:20:36.159Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/superstreamlabs.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":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-23T06:43:22.000Z","updated_at":"2023-11-23T07:07:50.000Z","dependencies_parsed_at":"2024-05-07T12:46:31.701Z","dependency_job_id":"fe5d92b3-5caf-445f-9a54-571abb786a7c","html_url":"https://github.com/superstreamlabs/memphis-functions.js","commit_stats":null,"previous_names":["memphisdev/memphis-functions.js","superstreamlabs/memphis-functions.js"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/superstreamlabs/memphis-functions.js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/superstreamlabs%2Fmemphis-functions.js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/superstreamlabs%2Fmemphis-functions.js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/superstreamlabs%2Fmemphis-functions.js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/superstreamlabs%2Fmemphis-functions.js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/superstreamlabs","download_url":"https://codeload.github.com/superstreamlabs/memphis-functions.js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/superstreamlabs%2Fmemphis-functions.js/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32408446,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T02:37:21.628Z","status":"ssl_error","status_checked_at":"2026-04-29T02:36:50.947Z","response_time":110,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2024-11-17T20:55:18.628Z","updated_at":"2026-04-29T03:02:48.728Z","avatar_url":"https://github.com/superstreamlabs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Github (6)](https://github.com/memphisdev/memphis/assets/107035359/bc2feafc-946c-4569-ab8d-836bc0181890)](https://www.functions.memphis.dev/)\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://memphis.dev/discord\"\u003e\u003cimg src=\"https://img.shields.io/discord/963333392844328961?color=6557ff\u0026label=discord\" alt=\"Discord\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/memphisdev/memphis/issues?q=is%3Aissue+is%3Aclosed\"\u003e\u003cimg src=\"https://img.shields.io/github/issues-closed/memphisdev/memphis?color=6557ff\"\u003e\u003c/a\u003e \n  \u003cimg src=\"https://img.shields.io/npm/dw/memphis-dev?color=ffc633\u0026label=installations\"\u003e\n\u003ca href=\"https://github.com/memphisdev/memphis/blob/master/CODE_OF_CONDUCT.md\"\u003e\u003cimg src=\"https://img.shields.io/badge/Code%20of%20Conduct-v1.0-ff69b4.svg?color=ffc633\" alt=\"Code Of Conduct\"\u003e\u003c/a\u003e \n\u003cimg alt=\"GitHub release (latest by date)\" src=\"https://img.shields.io/github/v/release/memphisdev/memphis?color=61dfc6\"\u003e\n\u003cimg src=\"https://img.shields.io/github/last-commit/memphisdev/memphis?color=61dfc6\u0026label=last%20commit\"\u003e\n\u003c/p\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \n  \u003cimg width=\"200\" alt=\"CNCF Silver Member\" src=\"https://www.cncf.io/wp-content/uploads/2022/07/cncf-white-logo.svg#gh-dark-mode-only\"\u003e\n  \n\u003c/div\u003e\n \n \u003cb\u003e\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://memphis.dev/pricing/\"\u003eCloud\u003c/a\u003e - \u003ca href=\"https://memphis.dev/docs/\"\u003eDocs\u003c/a\u003e - \u003ca href=\"https://twitter.com/Memphis_Dev\"\u003eX\u003c/a\u003e - \u003ca href=\"https://www.youtube.com/channel/UCVdMDLCSxXOqtgrBaRUHKKg\"\u003eYouTube\u003c/a\u003e\n\u003c/p\u003e\u003c/b\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n  \u003ch4\u003e\n\n**[Memphis.dev](https://memphis.dev)** is more than a broker. It's a new streaming stack.\u003cbr\u003e\nMemphis.dev is a highly scalable event streaming and processing engine.\u003cbr\u003e\n\n  \u003c/h4\u003e\n  \n\u003c/div\u003e\n\n## ![20](https://user-images.githubusercontent.com/70286779/220196529-abb958d2-5c58-4c33-b5e0-40f5446515ad.png) About\n\nBefore Memphis came along, handling ingestion and processing of events on a large scale took months to adopt and was a capability reserved for the top 20% of mega-companies. Now, Memphis opens the door for the other 80% to unleash their event and data streaming superpowers quickly, easily, and with great cost-effectiveness.\n\nThis repository is responsible for the Memphis Functions Javascript SDK\n\n## Installation\n\n```sh\n$ npm install memphis-functions\n```\n\n## Importing\n\nFor Javascript, you can choose to use the import or required keyword. This library exports a singleton instance of `memphis` with which you can consume and produce messages.\n\n```js\nconst { memphis } = require('memphis-functions');\n```\n\n### Creating a Memphis function\nMemphis provides a `createFunction` utility for more easily creating Memphis Functions. \n\nThe user-created `eventHandler` will be called for every message in the given batch of events. The user's `eventHandler` will take in a `payload` as a Uint8Array, `headers` as an object, and `inputs` as an object, and should return an object with keys `{ processedMessage, processedHeaders }`. The returned `processedMessage` should be a Uint8Array, and `processedHeaders` should be an object.\n\nThe user function should throw an exception if the message processing has failed. If any exception is thrown (deliberately or by a failed operation), the message will be sent to the dead letter station.\n\nIf the returned `processedMessage` and `processedHeaders` are `null`, then the message will be skipped and will not be sent to the station or dead letter station.\n\n\u003e Make sure to encode the `processedMessage` Uint8Array object with utf-8 encoding!\n\nThis example function takes the Uint8Array object `payload` and decodes it from base64 encoding so that it may be processed.\n\n```javascript\nconst { memphis } = require(\"memphis-functions\");\n\nexports.handler = async (event) =\u003e {\n    return await memphis.createFunction(event, eventHandler);\n};\n\nfunction eventHandler(payload, headers, inputs) {\n    const decodedPayload = payload.toString('utf-8');\n    const asJson = JSON.parse(decodedPayload);\n    asJson.modified = true;\n\n    return {\n        processedMessage: Buffer.from(JSON.stringify(asJson), 'utf-8'),\n        processedHeaders: headers\n    };\n}\n```\n\nA user created `eventHandler` may also be async:\n\n```javascript\nconst { memphis } = require(\"memphis-functions\");\n\nexports.handler = async (event) =\u003e {\n    return await memphis.createFunction(event, eventHandler);\n};\n\nasync function eventHandler(payload, headers, inputs) {\n    const decodedPayload = payload.toString('utf-8');\n    const asJson = JSON.parse(decodedPayload);\n    asJson.modified = true;\n\n    return {\n        processedMessage: Buffer.from(JSON.stringify(asJson), 'utf-8'),\n        processedHeaders: headers\n    };\n}\n```\n\nThe `asJson` can be used to get a json payload instead of a `Uint8Array`:\n\n```javascript\nconst { memphis } = require(\"memphis-functions\");\n\nexports.handler = async (event) =\u003e {\n    return await memphis.createFunction(event, eventHandler, asJson = true);\n};\n\nasync function eventHandler(payload, headers, inputs) {\n    payload[\"modified\"] = true;\n\n    return {\n        processedMessage: payload,\n        processedHeaders: headers\n    };\n}\n```\n\nIf the user wants to have a message that they would like to validate and send to the dead letter station if the validation fails, then the user can throw an exception. In the following example, the field `check` is a boolean. The following function will send any messages that fail the `check` to the dead letter station.\n\n```javascript\nconst { memphis } = require(\"memphis-functions\");\n\nexports.handler = async (event) =\u003e {\n    return await memphis.createFunction(event, eventHandler);\n};\n\nasync function eventHandler(payload, headers, inputs) {\n    const decodedPayload = payload.toString('utf-8');\n    const asJson = JSON.parse(decodedPayload);\n\n    if (!asJson.check) {\n        throw new Error(\"Validation Failed!\");\n    }\n\n    return {\n        processedMessage: Buffer.from(JSON.stringify(asJson), 'utf-8'),\n        processedHeaders: headers\n    };\n}\n```\n\nIf a user would rather just skip the message and not have it be sent to the station or dead letter station, the user could instead return `{ processedMessage: null, processedHeaders: null }`.\n\n```javascript\nconst { memphis } = require(\"memphis-functions\");\n\nexports.handler = async (event) =\u003e {\n    return await memphis.createFunction(event, eventHandler);\n};\n\nfunction eventHandler(payload, headers, inputs) {\n    const decodedPayload = payload.toString('utf-8');\n    const asJson = JSON.parse(decodedPayload);\n\n    if (!asJson.check) {\n        return { processedMessage: null, processedHeaders: null };\n    }\n\n    return {\n        processedMessage: Buffer.from(JSON.stringify(asJson), 'utf-8'),\n        processedHeaders: headers\n    };\n}\n```\n\nLLastly, if the user is using another data format like Protocol Buffers, the user may simply decode the `payload` into that format instead of JSON. The following example will be using the [protobufjs](https://github.com/protobufjs/protobuf.js/) package. Assuming we have a .proto definition like this: \n\n```proto\nsyntax = \"proto3\";\npackage protobuf_example;\n\nmessage Message{\n    string data_field = 1;\n}\n```\n\nWe can decode this and get the data_field out like this:\n\n```javascript\nconst { memphis } = require(\"memphis-functions\");\n\nexports.handler = async (event) =\u003e {\n    return await memphis.createFunction(event, eventHandler);\n};\n\nfunction eventHandler(payload, headers, inputs) {\n    const root = await protobuf.load(\"./message.proto\");\n    const Message = root.lookupType('protobuf_example.Message');\n\n    const my_message = Message.decode(payload)\n\n    // data_field gets translated to dataField by the library...\n    // Arbitrarily changing the data field\n    my_message.dataField = \"My new data\"\n    \n    // .finish() returns a Uint8Array so it may just be returned as the processedMessage\n    return {\n      \"processedMessage\" : Message.encode(my_message).finish(),\n      \"processedHeaders\" : headers\n    }\n}\n\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuperstreamlabs%2Fmemphis-functions.js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsuperstreamlabs%2Fmemphis-functions.js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuperstreamlabs%2Fmemphis-functions.js/lists"}