{"id":15540444,"url":"https://github.com/poteto/ember-ja-query","last_synced_at":"2025-11-09T18:30:18.802Z","repository":{"id":57158518,"uuid":"68667679","full_name":"poteto/ember-ja-query","owner":"poteto","description":"JSON API response query interface","archived":false,"fork":false,"pushed_at":"2016-09-20T18:42:05.000Z","size":21,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-26T17:20:29.234Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/poteto.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-20T02:52:57.000Z","updated_at":"2017-03-25T10:46:49.000Z","dependencies_parsed_at":"2022-09-07T18:32:17.249Z","dependency_job_id":null,"html_url":"https://github.com/poteto/ember-ja-query","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/poteto%2Fember-ja-query","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poteto%2Fember-ja-query/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poteto%2Fember-ja-query/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poteto%2Fember-ja-query/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/poteto","download_url":"https://codeload.github.com/poteto/ember-ja-query/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239576793,"owners_count":19662113,"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-10-02T12:13:47.525Z","updated_at":"2025-11-09T18:30:18.763Z","avatar_url":"https://github.com/poteto.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ember-ja-query ![Download count all time](https://img.shields.io/npm/dt/ember-ja-query.svg) [![CircleCI](https://circleci.com/gh/poteto/ember-ja-query.svg?style=shield)](https://circleci.com/gh/poteto/ember-ja-query) [![npm version](https://badge.fury.io/js/ember-ja-query.svg)](https://badge.fury.io/js/ember-ja-query) [![Ember Observer Score](http://emberobserver.com/badges/ember-ja-query.svg)](http://emberobserver.com/addons/ember-ja-query)\n\n`JaQuery` is a query interface around a [JSON-API](http://jsonapi.org/) (JA) object or array response that provides conveniences in tests. For example, this is useful if you need to work with (e.g. filter, find) canned JA responses via [`Pretender`](https://github.com/pretenderjs/pretender) and [`ember-cli-pretender`](https://github.com/rwjblue/ember-cli-pretender).\n\nIt will not be included in non-test environment builds.\n\n```\nember install ember-ja-query\n```\n\n## Usage\n\nWrap your response with `JaQuery`:\n\n```js\nimport JaQuery from 'my-app/tests/ember-ja-query';\nimport objectResponse from '...';\nimport arrayResponse from '...';\n\nlet user = new JaQuery(objectResponse);\nlet users = new JaQuery(arrayResponse);\n```\n\nYou can wrap a JA response for both a single item or many items. Once wrapped, you can query the response like you would any Ember Object:\n\n```js\n// top level keys\nwrapped.get('id') // \"1\";\nwrapped.get('type') // \"user\";\n\n// attributes\nwrapped.get('firstName') // \"Ricky\";\n\n// relationships\nwrapped.get('job') // {id: \"1\", type: \"jobs\"};\n\n// included relationships\nwrapped.get('job.name') // \"ceo\"\n```\n\nIf wrapping an array response, [supported array methods](#supported-array-methods) will \"just work\", but note that these will return the JA response and not the `JaQuery` child object:\n\n```js\nlet ceo = wrapped.filter((user) =\u003e user.get('job.id') === '1');\nlet ceo = wrapped.filterBy('id', '1');\nlet ceo = wrapped.findBy('job.name', 'ceo');\nlet employees = wrapped.rejectBy('id', '1');\n```\n\nYou can opt-out of this behaviour by setting `shouldUnwrapArrayMethods` to `false`. Array methods will then return the result wrapped in a `JaQuery` object.\n\nUsing with `ember-cli-pretender` in an acceptance test:\n\n```js\nimport { test } from 'qunit';\nimport Pretender from 'Pretender';\nimport moduleForAcceptance from 'my-app/tests/helpers/module-for-acceptance';\nimport JaQuery from 'my-app/tests/ember-ja-query';\nimport usersResponse from '...';\n\nmoduleForAcceptance('Acceptance | some/route', {\n  beforeEach() {\n    this.server = new Pretender(function() {\n      this.get(users, function({ queryParams }) {\n        let { firstName } = queryParams;\n        let data = new JaQuery(usersResponse).filterBy('firstName', firstName);\n\n        return [200, { 'Content-Type': 'application/json' }, JSON.stringify(data));\n      });\n    })\n  },\n  afterEach() {\n    this.server.shutdown();\n  }\n});\n\ntest('it should ...', function(assert) {\n  visit('/users');\n\n  andThen(() =\u003e assert.ok(...);\n});\n```\n\n## API\n\n* Properties\n  + [`shouldUnwrapArrayMethods`](#shouldunwraparraymethods)\n  + [`response`](#response)\n  + [`data`](#data)\n  + [`included`](#included)\n  + [`links`](#links)\n  + [`attributes`](#attributes)\n  + [`relationships`](#relationships)\n  + [`isObject`](#isobject)\n  + [`isArray`](#isarray)\n  + [`hasIncluded`](#hasincluded)\n  + [`hasRelationships`](#hasrelationships)\n* Methods\n  + [`get`](#get)\n  + [`unwrap`](#unwrap)\n\n### Supported array methods\nIn addition to the above, if you wrap an array response, these array methods are available to use on the `JaQuery` object:\n\n- `filter`\n- `filterBy`\n- `find`\n- `findBy`\n- `reject`\n- `rejectBy`\n\n#### `shouldUnwrapArrayMethods`\n\nDefaults to `true`. \n\nIf `true`, array methods will unwrap the response (returning the actual JA JSON response(s) that come back from that array method). \n\n```js\nwrapped.filter((user) =\u003e user.get('job.id') === 1);\n\n// returns:\n{\n  \"data\": [\n    {\n      \"id\": \"1\",\n      \"type\": \"event\",\n      \"attributes\": {\n        ...\n      },\n      \"relationships\": {\n        ...\n      }\n    }\n  ]\n}\n```\n\nSet to `false` prior to calling an array method to opt-out of this and instead return the wrapped child object:\n\n```js\nwrapped.set('shouldUnwrapArrayMethods', false);\nlet user = wrapped.findBy('id', '1'); // Class\nuser.get('job.name'); // \"ceo\"\n```\n\n**[⬆️ back to top](#api)**\n\n#### `response`\n\nAlias for the original JA response.\n\n**[⬆️ back to top](#api)**\n\n#### `data`\n\nAlias for the `data` key on the JA response.\n\n**[⬆️ back to top](#api)**\n\n#### `included`\n\nAlias for the `included` key on the JA response.\n\n**[⬆️ back to top](#api)**\n\n#### `links`\n\nAlias for the `links` key on the JA response.\n\n**[⬆️ back to top](#api)**\n\n#### `attributes`\n\nAlias for the `attributes` key on the JA response.\n\n**[⬆️ back to top](#api)**\n\n#### `relationships`\n\nAlias for the `relationships` key on the JA response. \n\n**[⬆️ back to top](#api)**\n\n#### `isObject`\n\nReturns `true` if the wrapped response is an object response.\n\n**[⬆️ back to top](#api)**\n\n#### `isArray`\n\nReturns `true` if the wrapped response is an array response.\n\n**[⬆️ back to top](#api)**\n\n#### `hasIncluded`\n\nReturns `true` if the wrapped response has included relationships..\n\n**[⬆️ back to top](#api)**\n\n#### `hasRelationships`\n\nReturns `true` if the wrapped response has relationships.\n\n**[⬆️ back to top](#api)**\n\n#### `get`\n\nGet a property from a single object response.\n\n```js\nlet wrapped = new JaQuery(response);\nwrapped.get('firstName'); // \"Jim Bob\"\n```\n\n**[⬆️ back to top](#api)**\n\n#### `unwrap`\n\nReturns the original JA response. Optionally, pass in a function and the JA response will be wrapped with it.\n\n```js\nlet wrapped = new JaQuery(response);\nlet log = (x) =\u003e { console.log(x); };\nwrapped.unwrap(log);\n```\n\n**[⬆️ back to top](#api)**\n\n## Installation\n\n* `git clone \u003crepository-url\u003e` this repository\n* `cd ember-ja-query`\n* `npm install`\n* `bower install`\n\n## Running\n\n* `ember serve`\n* Visit your app at [http://localhost:4200](http://localhost:4200).\n\n## Running Tests\n\n* `npm test` (Runs `ember try:each` to test your addon against multiple Ember versions)\n* `ember test`\n* `ember test --server`\n\n## Building\n\n* `ember build`\n\nFor more information on using ember-cli, visit [http://ember-cli.com/](http://ember-cli.com/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoteto%2Fember-ja-query","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpoteto%2Fember-ja-query","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoteto%2Fember-ja-query/lists"}