{"_id":"@coboxcoop/repository","_rev":"2-52fe2dd64d171690a9163c46114fb7dc","name":"@coboxcoop/repository","dist-tags":{"latest":"1.0.1-alpha.1"},"versions":{"1.0.0-alpha.1":{"name":"@coboxcoop/repository","version":"1.0.0-alpha.1","description":"a simple repository pattern for caching, creating, loading collections","author":{"name":"magma-collective"},"license":"AGPL-3.0-or-later","main":"index.js","directories":{"test":"test"},"scripts":{"test":"tape test/**/*.test.js | tap-spec"},"dependencies":{"call-me-maybe":"^1.0.1","debug":"^4.1.1","hypercore-crypto":"^1.0.0","js-yaml":"^3.13.1","mutexify":"^1.3.0","thunky":"^1.1.0"},"devDependencies":{"proxyquire":"^2.1.3","random-words":"^1.1.1","rimraf":"^3.0.0","sinon":"^9.0.2","tap-spec":"^5.0.0","tape":"^4.11.0","tape-plus":"^1.0.0","tmp":"^0.1.0"},"repository":{"type":"git","url":"git+https://gitlab.com/coboxcoop/repository.git"},"bugs":{"url":"https://gitlab.com/coboxcoop/repository/issues"},"homepage":"https://cobox.cloud","_id":"@coboxcoop/repository@1.0.0-alpha.1","_nodeVersion":"12.16.3","_npmVersion":"6.14.4","dist":{"integrity":"sha512-0Gr81jYiOmLoueJqCgxw6DysCtoOJ3ppiqq0RZlIFx82U+LuWPfT4H68rGsFSYay6ioEWA/RoTjX1/PXwnaHTA==","shasum":"b644a65c8fb52871290f89651546ea6c848a2100","tarball":"https://registry.npmjs.org/@coboxcoop/repository/-/repository-1.0.0-alpha.1.tgz","fileCount":8,"unpackedSize":56874,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfIbHWCRA9TVsSAnZWagAAhvgP/0gW/LBtstMopdyHarEX\ncEgV/McN84QsuT3EDLRkdMxix27jjw2FiOEmkySjPOhbKZjNIhYtL3odxQuc\n83Dr3jT/3IG0Hhyg/lpC5LRJDc64xyVNtdR+QZjmldANLBpOYMQUd1SifgfQ\n/dtEOjE12kPQPkeFU05ZUAkrejGuKrOtJf0uRusElfZTvaT+yodTxjn/CUYV\n8XWpl8xDBPAcO9NpoMK0mbUw0ZhcXU9PcJSB+tdoRL50YEoUcZ4orTEpNx+F\niy0M8fanxaIep6lH3H7fFlqGOK+kdqbGZfXGSQ7rUBLGsczzkUu4qMCV6TtS\nbzjimcFm7vgrPBpE5xvA7atUFL2ycALW8gE59fvh+Brb4PTsraam7EKdGH2M\nhWP/QjamGe78FlvTEDTdorBdMQfNFZVQ3k6alKG1vYlKIayH52a/uhiC29ct\nt/95wh2WW+yUI/Y/gscnJS1OgLEyooQsn3S5mZ9FO2qfN9qxkIWNWpDbmdhO\nCPPhu06JtFpqgQfmZcpcdWm4Cz17vX39zR7Vtb0VWcA5IzvVtjs1r/N3Oevf\nZAwi9nxLvXgJ27IOt1+xjHplbjRwRtvgD5BnWKV41bVI0x7tfysUNyBjz/1F\ngYwSus3uj5WUgVu3pBK7qdOdpEnVof9NNCiUuJFaKv597LNBvs6iJhKBra/q\n/Gq+\r\n=jXVI\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCXzVPlkEq7WB5Dq2xHaCoTIgP8p9saRiCS77ISp7hvcQIgQU49XTz4p6KM20E28UTIvC7YBLOebtJ2aHAIi5ec/Zo="}]},"maintainers":[{"name":"ameba23","email":"ameba23@systemli.org"},{"name":"kyphae","email":"kieran@tenthousandthings.org.uk"}],"_npmUser":{"name":"kyphae","email":"kieran@tenthousandthings.org.uk"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/repository_1.0.0-alpha.1_1596043733769_0.42433819800287154"},"_hasShrinkwrap":false},"1.0.1-alpha.1":{"name":"@coboxcoop/repository","version":"1.0.1-alpha.1","description":"a simple repository pattern for caching, creating, loading collections","author":{"name":"magma-collective"},"license":"AGPL-3.0-or-later","main":"index.js","directories":{"test":"test"},"scripts":{"test":"tape test/**/*.test.js | tap-spec"},"dependencies":{"@coboxcoop/logger":"^1.0.0-alpha.1","call-me-maybe":"^1.0.1","debug":"^4.1.1","hypercore-crypto":"^1.0.0","js-yaml":"^3.13.1","mutexify":"^1.3.0","thunky":"^1.1.0"},"devDependencies":{"proxyquire":"^2.1.3","random-words":"^1.1.1","rimraf":"^3.0.0","sinon":"^9.0.2","tap-spec":"^5.0.0","tape":"^4.11.0","tape-plus":"^1.0.0","tmp":"^0.1.0"},"repository":{"type":"git","url":"git+https://gitlab.com/coboxcoop/repository.git"},"bugs":{"url":"https://gitlab.com/coboxcoop/repository/issues"},"homepage":"https://cobox.cloud","_id":"@coboxcoop/repository@1.0.1-alpha.1","_nodeVersion":"12.16.3","_npmVersion":"6.14.4","dist":{"integrity":"sha512-XdOvNfnimMNev8mKYuEUsqda7KaYtNhIHpopvwzpOa82c2A4OLbGgkLo7THXUucME09BK3UfrYvNodIT1kehgg==","shasum":"82e8a3956699073f064d2ac839b860317f4defc1","tarball":"https://registry.npmjs.org/@coboxcoop/repository/-/repository-1.0.1-alpha.1.tgz","fileCount":8,"unpackedSize":56917,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfIcRcCRA9TVsSAnZWagAAFjYP/1Dsv/jF+D51RRMLx2X9\nXxRapXWrpsdZLoHA3U4inJYKM4dzVXqZMGJsLTmGkbHB+nBSiZO6uI02CXwu\nVrg07PIrpTA5A4p2yNbaHaS//Yaq56fdEZ6n4+ItFXmCYmRNYAfqQSrq/VYe\nyO9JvMk2mUGjaUKeJFAc9OKaKi3KZKuUjYZ/CYqZnGROODPA+b9nozSI7PBq\naDzwkNE2TBl6Q6jLJt8QUdlzfNhBN44mxZ4f3GP7EDebDx0vdwM9A5UABSqQ\n8lqW4DDu+iV6OBIETg0iRxTk+jGEhheRDViI/yCrryhmzL6g+Gb9gTqOEzcW\npgdUbuf7FgsNUa8xA4Ee22Wfl3GCx56dDAYy5yz7zqYPuIMKtiI67kUtnobs\nmTparEDIg0XFniQd2m/hk5KxXvkcN2GdQufCYfdlR/4k1VEHc1t4p5Y0jnJ+\nhzEu+V34D/vBIA27NkCTrxnhgKEVwubOzyNJdx23OFBX8LxHOI7vK6mppfLw\n6o6nmCZtBXfPoIHDR0QbGe7Uu+wu6feaY+9xQFBDJrqMnkz6M7GLZiRXyiWG\njqvtWlzZDLpepWGehogm3T7Afmx9MN+ECmcoxG83bNo7AUfMKDvGAsAgr1Xv\n3KPqT20z0ohoYOhfNQLw6dhtQEY72I3x/UIfU9NhElnplWZ0WgOAPPFj505C\noPM7\r\n=WeDt\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDi+wbx7e+v9q20veVPTYVe1SBStytHCKfBkH+iceECrwIgcvJjuVj0zAQ0sMuXLnhQx5DiUZTuyxPueyQPnbox3yU="}]},"maintainers":[{"name":"ameba23","email":"ameba23@systemli.org"},{"name":"kyphae","email":"kieran@tenthousandthings.org.uk"}],"_npmUser":{"name":"kyphae","email":"kieran@tenthousandthings.org.uk"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/repository_1.0.1-alpha.1_1596048475975_0.3608760671961604"},"_hasShrinkwrap":false}},"time":{"created":"2020-07-29T17:28:53.566Z","1.0.0-alpha.1":"2020-07-29T17:28:53.911Z","modified":"2022-04-04T23:54:03.167Z","1.0.1-alpha.1":"2020-07-29T18:47:56.106Z"},"maintainers":[{"name":"ameba23","email":"ameba23@systemli.org"},{"name":"kyphae","email":"kieran@tenthousandthings.org.uk"}],"description":"a simple repository pattern for caching, creating, loading collections","homepage":"https://cobox.cloud","repository":{"type":"git","url":"git+https://gitlab.com/coboxcoop/repository.git"},"author":{"name":"magma-collective"},"bugs":{"url":"https://gitlab.com/coboxcoop/repository/issues"},"license":"AGPL-3.0-or-later","readme":"# Repository\n\n<div align=\"center\">\n  <img src=\"https://cobox.cloud/src/svg/logo.svg\">\n</div>\n\n[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)\n\n## Table of Contents\n\n  - [About](#about)\n  - [Install](#install)\n  - [Usage](#usage)\n  - [API](#api)\n  - [Contributing](#contributing)\n  - [License](#license)\n\n## About\n**CoBox** is an encrypted p2p file system and distributed back-up tool. [README](https://gitlab.com/coboxcoop/readme) provides a map of the project.\n\n`repository` provides a simple repository pattern for caching, creating, loading and saving the following models:\n\n* [@coboxcoop/space](https://gitlab.com/coboxcoop/space)\n* [@coboxcoop/replicator](https://gitlab.com/coboxcoop/replicator)\n* [@coboxcoop/superusers](https://gitlab.com/coboxcoop/superusers)\n\n### Why?\n\nIn CoBox we're using this to load each multifeed and kappa-core instance and cache them in this repository. This ensures that our indexes are always up to date by calling the ready function on each instance before returning the instance itself. The basic querying functionality allows for our controllers to pass a set of parameters to a `where` or `findBy` function and match on that basis.\n\nCurrently supports matching parameters based on the following types:\n* Buffers\n* Strings\n\n## Install\n\n```\nnpm i -g @coboxcoop/schemas\n\n```\n\n## Usage\n\n```\nconst Repository = require('@coboxcoop/repository')\n\nconst repository = Repository(storage, factory, opts)\n```\n\nAll `opts` get passed down to the instance generated by the factory.\n\nHere's an example of what a controller would look like using `@coboxcoop/repository`:\n\n```js\nconst Repository = require('@coboxcoop/repository')\n\n// Suppose a POST create has been sent with the following parameters\nvar params = {\n  name: 'myspace',\n  address: '4cef27e9702ae90c07056aa88cb4527a7037368311c0b0ed58db28344613ebd6'\n}\n\nfunction SpacesController () {\n  const spaces = Repository('path/to/yaml/file/for/spaces', createSpace, { onCreate })\n\n  return { create }\n\n  async function create (request, response) {\n    try {\n      await spaces.ready()\n      var space = await spaces.create(request.params)\n      response.send('success! you created a space')\n    } catch (err) {\n      if (err.found) return response.send('validation failed: space with these parameters already exists')\n    }\n  }\n\n  function onCreate (entry, cb) {\n    // callback executes just before caching, but after building\n  }\n}\n```\n\n## API\n\nAll functions can be called either with a callback as the last argument, or using async/await (i.e. they return a promise).\n\n### `repository.all()`\nGet all entries\n\n### `repository.where(attributes)`\nGet all entries that match the strongly matches the attributes provided (will ignore if one or more attributes doesn't match while but others match)\n\n### `repository.findBy(attributes)`\nGet first entry that matches attributes provided (same as where but returns the first one)\n\n### `repository.create(attributes)`\nUse the factory function provided to build an instance and cache it. `ready` function expected on the entry class produced by the factory.\n\n### `repository.ready()`\nLoad and get all entries ready. should always be called first.\n\n### `repository.close()`\nGracefully close all entries. `close` function expected on the entry class produced by the factory\n\n### `repository.save()`\nPersist all entries to a YAML file. create one if it doesn't exist already.\n\n### `repository.load()`\nLoad all entries from the YAML file.\n\n\n## Contributing\n\nPRs accepted.\n\nSmall note: If editing the README, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.\n\n# License\n\n[`AGPL-3.0-or-later`](./LICENSE)\n","readmeFilename":"README.md"}