{"id":18469542,"url":"https://github.com/tricinel/cuddy","last_synced_at":"2025-05-07T07:51:21.036Z","repository":{"id":53083805,"uuid":"322282811","full_name":"tricinel/cuddy","owner":"tricinel","description":"An aggregation pipeline built in a functional programming style that lets you search, group, order and transform a collection.","archived":false,"fork":false,"pushed_at":"2021-12-27T16:46:37.000Z","size":740,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-18T06:44:38.768Z","etag":null,"topics":["aggregation","functional-programming","javascript","pipeline","query-builder","search","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/tricinel.png","metadata":{"files":{"readme":"Readme.md","changelog":"Changelog.md","contributing":"Contributing.md","funding":null,"license":"License.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-12-17T12:05:39.000Z","updated_at":"2021-12-27T16:46:40.000Z","dependencies_parsed_at":"2022-09-12T12:24:46.216Z","dependency_job_id":null,"html_url":"https://github.com/tricinel/cuddy","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tricinel%2Fcuddy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tricinel%2Fcuddy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tricinel%2Fcuddy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tricinel%2Fcuddy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tricinel","download_url":"https://codeload.github.com/tricinel/cuddy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252839282,"owners_count":21812084,"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":["aggregation","functional-programming","javascript","pipeline","query-builder","search","typescript"],"created_at":"2024-11-06T10:10:49.851Z","updated_at":"2025-05-07T07:51:21.010Z","avatar_url":"https://github.com/tricinel.png","language":"TypeScript","readme":"\u003ch1 align=\"center\"\u003ecuddy\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\u003cimg src=\"./cuddy-logo.png\" alt=\"crazy looking donkey\" /\u003e\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\u003cstrong\u003ecuddy\u003c/strong\u003e is an aggregation pipeline built in a functional programming style. If you ever wanted to search through a collection using logical operators, sort, group, transform and return only the fields you care about, then cuddy is for you.\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://img.shields.io/npm/v/cuddy?style=flat-square\" alt=\"npm version badge\" /\u003e\n  \u003cimg src=\"https://img.shields.io/circleci/build/github/tricinel/cuddy?label=circleci\u0026style=flat-square\" alt=\"npm version badge\" /\u003e\n  \u003cimg src=\"https://img.shields.io/node/v/cuddy?style=flat-square\" alt=\"node version badge\" /\u003e\n  \u003cimg src=\"https://img.shields.io/npm/l/cuddy.svg?style=flat-square\" alt=\"license version badge\" /\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\u003cem\u003eThe cuddy donkey logo designed by the talented \u003ca href=\"https://www.linkedin.com/in/lauradinulescu/\"\u003eLaura Dinulescu\u003c/a\u003e.\u003c/em\u003e\u003c/p\u003e\n\n## Install\n\nThis module is distributed via npm which is bundled with node and should be installed as one of your project's dependencies:\n\n`npm install cuddy --save` or `yarn add cuddy`\n\n### Usage\n\nImport cuddy and create the query.\n\n```js\nimport cuddy from 'cuddy';\nimport { copyFrom } from 'cuddy/transform/helpers';\n\nconst query = {\n  fields: ['title', 'permalink', 'runTime'],\n  match: {\n    in: { genre: 'Comedy', cast: 'Adam Sandler' },\n    eq: { lang: 'en' }\n  },\n  orderBy: {\n    reviews: 'asc'\n  },\n  groupBy: 'director',\n  transform: {\n    permalink: copyFrom('url')\n  },\n  limit: 2,\n  skip: 1\n};\n```\n\nThe above query translates into:\n\n- I want all the items where the `genre` contains `Comedy` and `cast` contains `Adam Sandler` and the `lang` is `en`.\n- I want only 2 results and I want to skip the first item in the list.\n- I want to order the items by `reviews` in ascending order.\n- I want to group the items by `director`.\n- I want to create a new field called `permalink` and set its value to that of the `url` field.\n- From all the fields of each item, I only want the `title`, `permalink` and `runTime`.\n\nNext, build the pipeline and aggregate your data.\n\n```js\nconst { aggregate } = cuddy(query, data);\nconst results = aggregate();\n```\n\nDepending on the shape of your data, the results could look like this:\n\n```json\n{\n  \"Robert Smigel\": [\n    {\n      \"title\": \"The Week Of\",\n      \"permalink\": \"https://www.imdb.com/title/tt6821012\",\n      \"runTime\": 116\n    }\n  ]\n}\n```\n\n\u003e For more query examples, see the [Books test cases](./src/__tests__/books.test.ts) and the associated [Books collection](./src/__mocks__/books.ts).\n\u003e\n\u003e If it looks like mongodb's query language, it's because lots of inspirations came from there. :)\n\n### Stages\n\nThe aggregation pipeline contains the following stages:\n\n- [Matching](./docs/match.md). Filter out any items that do not match the criteria.\n- [Sorting](./docs/sort.md). Sort the items in  the specified order.\n- [Pagination](./docs/pagination.md). Limit the number of results and/or skip over the first results.\n- [Grouping](./docs/group.md). Group the items by a specified field.\n- [Count](./docs/count.md). Count the items by a specified field.\n- [Project](./docs/project.md). Limit the fields that are returned for each item.\n- [Transform](./docs/transform.md). Transform existing properties and add new properties to the matched items.\n\n### Pipeline functions\n\nOnce you've built your pipeline, you can use it to aggregate your data and return results. Depending on whether you want one result, all of them or just a count of the total results, you will need to call the appropriate method:\n\n* `aggregate()` will return all the results from your query.\n* `first()` will return the first result in the list of results from your query.\n* `last()` will return the last result in the list of results from your query.\n* `count()` will return the total number of results from your query.\n* `explain()` will return an object explaining the set of steps resulted from your query. For details on the output, see the [Explanation](./docs/explain.md) section.\n\n#### Why cuddy?\n\n\u003e _noun_\n\u003e\n\u003e cud·​dy | \\ ˈku̇-dē\n\u003e\n\u003e Synonyms: donkey (British slang)\n\nThe donkey is used as a working animal and is considered the cheapest form of labor.\n\n#### Contributing\n\n- Run tests with `npm run test` or `yarn test`.\n- Run the lint with `npm run lint` or `yarn lint`.\n\nFor details, check out the [Contributing][./Contributing.md] guide.\n\n##### LICENSE\n\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftricinel%2Fcuddy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftricinel%2Fcuddy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftricinel%2Fcuddy/lists"}