{"id":14848281,"url":"https://github.com/iopipe/turtle","last_synced_at":"2025-08-23T00:31:06.121Z","repository":{"id":66369704,"uuid":"46544519","full_name":"iopipe/turtle","owner":"iopipe","description":"Turtle - functional composition for building lambda architectures in NodeJS","archived":false,"fork":false,"pushed_at":"2018-02-08T01:03:45.000Z","size":119,"stargazers_count":153,"open_issues_count":8,"forks_count":9,"subscribers_count":17,"default_branch":"master","last_synced_at":"2024-05-18T21:55:25.584Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/iopipe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2015-11-20T06:42:27.000Z","updated_at":"2024-04-14T23:27:51.000Z","dependencies_parsed_at":"2023-04-04T21:03:33.613Z","dependency_job_id":null,"html_url":"https://github.com/iopipe/turtle","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/iopipe%2Fturtle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iopipe%2Fturtle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iopipe%2Fturtle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iopipe%2Fturtle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iopipe","download_url":"https://codeload.github.com/iopipe/turtle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230650720,"owners_count":18259305,"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":[],"created_at":"2024-09-19T13:01:51.236Z","updated_at":"2024-12-20T22:18:05.946Z","avatar_url":"https://github.com/iopipe.png","language":"JavaScript","funding_links":[],"categories":["Frameworks"],"sub_categories":[],"readme":"Turtle\n---------------------------------------\n[![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg?maxAge=2592000)](https://gitter.im/iopipe/iopipe)\n\nApache 2.0 licensed.\n\nTurtle is a toolkit for building and orchestrating event-driven and\nserverless applications. These apps may run anywhere, either locally or,\nvia execution drivers, in the cloud. It's turtles all the way down.\n\nExecution drivers exist for:\n\n - AWS Lambda\n\nDrivers are planned (or in development) for:\n\n - Google Cloud Functions\n - Azure Functions\n - Docker (Engine \u0026 Swarm)\n\nTurtle can:\n\n * Chain AWS Lambda Functions and local functions.\n * Convert NodeJS functions into serverless functions.\n * Compose applications with HTTP APIs.\n * Parallelize data into serverless workers (scatter \u0026 gather).\n\n# CLI\n\nUse the [Turtle CLI](https://github.com/iopipe/turtle-golang) to create and\nexport npm modules, share code, \u0026 provide runtime of magnetic functions.\nThe CLI is still in early development, with our NodeJS SDK being more\nmature.\n\nFind, download, and/or contribute to this tool in the [CLI repo](https://github.com/iopipe/turtle-golang).\n\n# SDK\n\n### NodeJS SDK:\n\nThe NodeJS SDK provides a generic callback chaining mechanism which allows\nmixing HTTP(S) requests/POSTs, and function calls. Callbacks\nreceive the return of the previous function call or HTTP body.\n\nThe callback variable received by a function is also an AWS Lambda-compatible\n\"context\" object. Because of this, you can chain standard callback-based NodeJS\nfunctions, and functions written for AWS Lambda.\n\n#### Installation\n\nInstallation of the NodeJS module is easy via npm:\n\n```\n$ npm install @iopipe/turtle\n```\n\nOur CLI is still in early development and may be found on the releases\npage, with further instructions in the [CLI\nrepo](https://github.com/iopipe/iopipe-golang).\n\n#### Basic usage:\n\n```javascript\n/* Create a Lambda function which returns event.key + 1. */\nvar turtle = require(\"@iopipe/turtle\")()\n\nexports.handle = turtle.define(\n  (event, context) =\u003e {\n    context.succeed(event.key + 1)\n  }\n)\n```\n\n#### Context argument\n\nThe context argument operates as both a callback and\nan object with several methods, similar to the same\nargument passed to AWS Lambda functions.\n\nDevelopers may call `context()` directly, with its argument\npassed as the event to the next function, or may call its\nmethods.\n\nContext Methods:\n\n - context.done(err, data)\n - context.succeed(data)\n - context.fail(err)\n\n\nExample of using context.fail to pass errors:\n\n```javascript\nvar turtle = require(\"@iopipe/turtle\")()\n\nexports.handle = turtle.define(\n  (event, context) =\u003e {\n    try {\n      throw \"Ford, you're turning into a penguin. Stop it!\"\n    }\n    catch (err) {\n      context.fail(err)\n    }\n  }\n)\n```\n\n#### Function Composition\n\nTurtle supports the composition of functions, HTTP endpoints,\nand modules, taken from functional-programming and flow-based\nprogramming models. This simplifies code-reuse and works as\nglue between algorithms.\n\nThere is (some) compatibility with [Rambda](http://ramdajs.com) for\nfunction composition \u0026 developing functional applications.\n\nBy using function composition, you will gain additional insights\nand increased granularity when utilizing (upcoming) telementry features.\n\nExample:\n\n```javascript\n/* Return event.int + 1, square the result,\n   print, then return the result. */\nexports.handle = turtle.define(\n  (event, context) =\u003e {\n    context(event.int + 1)\n\t},\n  (event, context) =\u003e {\n    context(Math.pow(event, 2))\n\t},\n  (event, context) =\u003e {\n    console.log(event)\n    context(event)\n\t}\n)\n```\n\n#### HTTP endpoints as \"functions\"\n\nThe first argument to `define`, if a URL, is fetched via an HTTP get\nrequest. Any URL string specified elsewhere in the argument list to\n`define` is sent a POST rqeuest.\n\nThis first example fetches data from a URL, then performs a POST request\nto another.\n\n```javascript\nexports.handle = turtle.define(\"http://localhost/get-data\",\n                               \"http://localhost/post-data\")\n```\n\nIt's possible to use Turtle to fetch from a URL and perform data\ntransformations via composition as follows:\n\n```javascript\nexports.handle = turtle.define(\n  \"http://localhost/get-data\",\n  (data, callback) =\u003e {\n    console.log(\"Fetched data: \" + data)\n  }\n)\n```\n\nOften, users will need to use Turtle to fetch a URL somewhere in\nthe middle of a composition and will need to use functional tools\nsuch as `turtle.fetch`. The following example also uses\n`turtle.property`, which extracts a key from an ECMAscript `Object`:\n\n```javascript\nexports.handle = turtle.define(\n  turtle.property(\"url\"),\n  turtle.fetch,\n  (data, callback) =\u003e {\n    console.log(\"Fetched data: \" + data)\n  }\n)\n```\n\n#### Scatter \u0026 Gather\n\nTurtle also acts as a client to serverless infrastructure allowing\nthe use of scatter \u0026 gather patterns such as map-reduce.\n\nBelow we initialize an AWS Lambda Client where a Lambda function may\nbe specified by its Amazon [URN](https://en.wikipedia.org/wiki/Uniform_Resource_Name)\nand included in the execution chain:\n\n```javascript\nvar turtle = require(\"@iopipe/turtle\")()\nvar turtle_aws = require(\"@iopipe/turtle\")(\n  exec_driver: 'aws'\n  exec_driver_opts: {\n    region: 'us-west-1',\n    access_key: 'itsasecrettoeverybody',\n    secret_key: 'itsasecrettoeverybody'\n  }\n)\nvar crypto = require(\"crypto\")\n\nexport.handler = turtle_aws.define(\"urn:someLambdaFunction\",\n                                   \"urn:anotherLambdaFunction\",\n                                   turtle.property(\"property-of-result\"),\n                                   turtle.fetch, // fetch that as a URL\n                                   (event, callback) =\u003e {\n                                      callback(JSON.parse(event))\n                                   },\n                                   turtle.map(\n                                     iopipe_aws.define(\n                                       \"urn:spawn_this_on_aws_for_each_value_in_parallel\"\n                                     )\n                                   ))\n```\n\nFor more information on using the NodeJS SDK, please refer to its documentation:\n***https://github.com/iopipe/iopipe/blob/master/docs/nodejs.md***\n\n### Go SDK:\n\nBundled with the [Turtle CLI](https://github.com/iopipe/turtle-golang) is\na Go SDK, still in early development.\n\n---------\nSecurity\n---------\n\nApplications are executed in individual virtual machines\nwhenever allowed by the executing environment.\nThe definition of a virtual machine here is lax,\nsuch that it may describe a Javascript VM,\na Linux container, or a hardware-assisted x86\nvirtual machine. Users should exercise caution\nwhen running community contributed code.\n\nIt is a project priority to make fetching, publishing,\nand execution of functions secure for a\nproduction-ready 1.0.0 release.\n\nModules are fetched and stored using sha256 hashes,\nproviding an advantage over module-hosting mechanisms\nwhich are based simply on a name and version. Future\nversions of Turtle will likely implement TUF for\nstate-of-the-art software assurance.\n\nContact security@iopipe.com for questions.\n\n-------\nLICENSE\n-------\n\nApache 2.0. Copyright 2016. IOpipe, Inc.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiopipe%2Fturtle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiopipe%2Fturtle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiopipe%2Fturtle/lists"}