{"id":28396234,"url":"https://github.com/ssbc/scuttle-inject","last_synced_at":"2025-08-02T01:42:41.614Z","repository":{"id":65412211,"uuid":"137700670","full_name":"ssbc/scuttle-inject","owner":"ssbc","description":null,"archived":false,"fork":false,"pushed_at":"2019-01-11T20:59:22.000Z","size":12,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-07-30T16:24:34.657Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ssbc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-18T01:50:20.000Z","updated_at":"2021-03-13T22:26:49.000Z","dependencies_parsed_at":"2023-01-22T07:35:13.551Z","dependency_job_id":null,"html_url":"https://github.com/ssbc/scuttle-inject","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/ssbc/scuttle-inject","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssbc%2Fscuttle-inject","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssbc%2Fscuttle-inject/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssbc%2Fscuttle-inject/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssbc%2Fscuttle-inject/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ssbc","download_url":"https://codeload.github.com/ssbc/scuttle-inject/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssbc%2Fscuttle-inject/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268326460,"owners_count":24232478,"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","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":"2025-05-31T21:37:27.550Z","updated_at":"2025-08-02T01:42:41.571Z","avatar_url":"https://github.com/ssbc.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Scuttle-inject\n\nTakes a particular sort of nested tree of methods and returns a version of that tree which has a scuttlebutt server injected into each method.\n\nThis pattern means you only need to inject a scuttlebot once, makes it easier to test your methods, and handles being able to inject different sorts of server for you.\n\n## Example usage\n\n```js\n// methods.js\nmodule.exports = {\n  async: {\n    publishPoll: function (server) {\n      return function (opts, cb) {\n        // check the opts before publishing\n        const cleanOpts = clean(opts) \n\n        server.publish(cleanOpts, cb)\n      }\n    },\n    // getPoll: (key, cb) =\u003e {}\n  },\n  pull: {\n    myPolls: function (server) {\n      return function (opts) {\n        const defaultQuery = { ... }\n        const query = Object.assign({}, defaultQuery, opts)\n\n        return server.query.read(opts)\n      }\n    }\n    // openPolls: (opts) =\u003e {},\n    // closedPolls: (opts) =\u003e {}\n  }\n}\n```\n\nInjecting server once (somehwhere high-level):\n```js\nconst inject = require('scuttle-inject')\ncosnt methods = require('./methods')\n\nconst scuttle = inject(methods, server)\n// assume you're in a context where you have a server\n```\n\nUsing the scuttle helper:\n```\nconst opts = { ... }\nscuttle.async.publishPoll(opts, cb)\n```\n\n## API\n\n`inject(server, methods, pluginDeps)`\n\n- `server` - a `scuttlebot` server, an `ssb-client` connection to a server, or an observeable which will resolve into a server connection (such as Patchcore's `sbot.obs.connection`)\n\n- `methods` - an Object nested at least 2 levels deep, where there must be one layer which specifies the `type` of method. Valid types are : `sync`, `async`, `pull`, `obs`\n\n- `pluginDeps` (optional) - an Array of plugins apis the scuttlebot must have for your methods to work. e.g. `['query']` will check that `sbot.query` has methods which are accessible.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fssbc%2Fscuttle-inject","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fssbc%2Fscuttle-inject","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fssbc%2Fscuttle-inject/lists"}