{"id":21522221,"url":"https://github.com/greguz/mutent","last_synced_at":"2025-04-09T22:23:06.845Z","repository":{"id":55633373,"uuid":"224846615","full_name":"greguz/mutent","owner":"greguz","description":"An agnostic solution to work with any Datastore","archived":false,"fork":false,"pushed_at":"2024-02-15T06:55:38.000Z","size":981,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-03-15T08:48:57.408Z","etag":null,"topics":["collection","database","datastore","entity","javascript"],"latest_commit_sha":null,"homepage":"https://greguz.github.io/mutent/","language":"JavaScript","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/greguz.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,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2019-11-29T12:04:42.000Z","updated_at":"2023-11-28T20:31:48.000Z","dependencies_parsed_at":"2023-01-22T17:15:18.059Z","dependency_job_id":"10b5918b-b144-4776-9d21-b25ccaf43179","html_url":"https://github.com/greguz/mutent","commit_stats":{"total_commits":538,"total_committers":2,"mean_commits":269.0,"dds":0.005576208178438624,"last_synced_commit":"00ed2c56a45ad1ad53b2fc7e5cc9e5591a79e36a"},"previous_names":[],"tags_count":47,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greguz%2Fmutent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greguz%2Fmutent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greguz%2Fmutent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greguz%2Fmutent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/greguz","download_url":"https://codeload.github.com/greguz/mutent/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248120794,"owners_count":21051017,"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":["collection","database","datastore","entity","javascript"],"created_at":"2024-11-24T01:09:38.222Z","updated_at":"2025-04-09T22:23:06.821Z","avatar_url":"https://github.com/greguz.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mutent\n\n[![npm](https://img.shields.io/npm/v/mutent)](https://www.npmjs.com/package/mutent)\n![npm package minimized gzipped size (select exports)](https://img.shields.io/bundlejs/size/mutent)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n[![Actions Status](https://github.com/greguz/mutent/workflows/ci/badge.svg)](https://github.com/greguz/mutent/actions)\n[![Coverage Status](https://coveralls.io/repos/github/greguz/mutent/badge.svg?branch=master)](https://coveralls.io/github/greguz/mutent?branch=master)\n![GitHub](https://img.shields.io/github/license/greguz/mutent)\n\nMutent is an agnostic solution to work with any Datastore.\n\n## Features\n\n- **Zero dependencies**: small footprint.\n- **Pure ES2018 code**: any environment that can run ES2018 code can directly include this module. Downgrading with tools like [Babel](https://babeljs.io/) is still possible.\n- **Extensible**: a powerful hooks system in place.\n- **Agnostic**: can be configured to work with any Datastore through Adapters.\n- **TypeScript**: type declarations are included.\n- **ESM**: support native ESM.\n- **CommonJS**: support old Node.js runtimes (`require`).\n- **Well tested**: code coverage above 95%.\n\n## Installation\n\n```\nnpm install --save mutent\n```\n\n## Documentation\n\nStart from the [Quickstart](https://greguz.github.io/mutent/) section.\n\n## Example\n\n```javascript\nimport { Store } from 'mutent'\n\n// Define simple array adapter (persist entities inside the array)\nclass ArrayAdapter {\n  constructor(array = []) {\n    this.array = array\n  }\n\n  find(predicate) {\n    return this.array.find(predicate)\n  }\n\n  filter(predicate) {\n    return this.array.filter(predicate)\n  }\n\n  create(data) {\n    this.array.push(data)\n  }\n\n  update(oldData, newData) {\n    this.array.splice(\n      this.array.findIndex(entity =\u003e entity === oldData),\n      1,\n      newData\n    )\n  }\n\n  delete(data) {\n    this.array.splice(\n      this.array.findIndex(entity =\u003e entity === data),\n      1\n    )\n  }\n}\n\nasync function foo() {\n  // Our \"datastore\"\n  const database = []\n\n  // Create mutent store\n  const store = new Store({\n    adapter: new ArrayAdapter(database)\n  })\n\n  // Create a new entity\n  const dexter = await store\n    .create({\n      name: 'Dexter',\n      protagonist: true\n    })\n    .unwrap()\n  console.log(dexter) // Dexter\n  console.log(database) // Dexter\n\n  // Create multiple entities\n  const family = await store\n    .create([\n      {\n        name: 'Dee Dee',\n        protagonist: true\n      },\n      { name: 'Mom' },\n      { name: 'Dad' }\n    ])\n    .unwrap()\n  console.log(family) // Dee Dee, Mom, Dad\n  console.log(database) // Dexter, Dee Dee, Mom, Dad\n\n  // Find one entity\n  const firstProtagonist = await store\n    .find(entity =\u003e entity.protagonist) // Declare adapter query\n    .unwrap()\n  console.log(firstProtagonist) // Dexter\n\n  // Filter entities\n  const allProtagonists = await store\n    .filter(entity =\u003e entity.protagonist) // Declare adapter query\n    .unwrap()\n  console.log(allProtagonists) // Dexter, Dee Dee\n\n  // Update\n  const newDexter = await store\n    .find(entity =\u003e entity.name === 'Dexter') // Declare adapter query\n    .update(entity =\u003e ({ ...entity, surname: 'McPherson' })) // Declare entity mutation\n    .unwrap()\n  console.log(newDexter) // Dexter McPherson\n  console.log(database) // Dexter McPherson, Dee Dee, Mom, Dad\n\n  // Assign (update)\n  const newDeeDee = await store\n    .find(entity =\u003e entity.name === 'Dee Dee') // Declare adapter query\n    .assign({ surname: 'McPherson' }) // Update with Object.assign()\n    .unwrap()\n  console.log(newDeeDee) // Dee Dee McPherson\n  console.log(database) // Dexter McPherson, Dee Dee McPherson, Mom, Dad\n\n  // Delete entities\n  const deletedParents = await store\n    .filter(entity =\u003e !entity.protagonist) // Declare adapter query\n    .delete() // Tell mutent we want to delete matching entities\n    .unwrap()\n  console.log(deletedParents) // Mom, Dad\n  console.log(database) // Dexter, Dee Dee\n}\n\nfoo().catch(err =\u003e console.error(err))\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreguz%2Fmutent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgreguz%2Fmutent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreguz%2Fmutent/lists"}