{"_id":"@ableco/overpass","_rev":"2-77713e6a2fde30b007f06b13384f4126","name":"@ableco/overpass","dist-tags":{"latest":"0.8.3"},"versions":{"0.8.2":{"name":"@ableco/overpass","version":"0.8.2","description":"Redux-based hooks-powered bridge between JSON:API endpoints and React components","main":"dist/overpass.js","repository":{"type":"git","url":"git+https://github.com/ableco/overpass.git"},"scripts":{"build":"webpack","dev":"webpack --watch","pretest":"npm run build","test":"jest","prettify":"prettier --write \"**/*.{js,json}\"","lint":"eslint \"**/*.js\""},"types":"dist/main.d.ts","author":{"name":"Able co."},"license":"MIT","devDependencies":{"@ableco/eslint-config":"^0.3.0","@babel/core":"^7.13.14","@babel/preset-env":"^7.13.12","@babel/preset-react":"^7.13.13","@babel/preset-typescript":"^7.13.0","@testing-library/react":"^11.2.6","@types/jest":"^26.0.22","@types/pluralize":"0.0.29","@types/qs":"^6.9.6","@types/react":"^17.0.3","@types/react-redux":"^7.1.16","@typescript-eslint/eslint-plugin":"^4.22.0","@typescript-eslint/parser":"^4.22.0","core-js":"^3.10.0","eslint":"^7.23.0","fetch-mock":"^9.11.0","jest":"^26.6.3","node-fetch":"^2.6.1","prettier":"^2.2.1","react":"^16.14.0","react-dom":"^16.14.0","regenerator-runtime":"^0.13.7","ts-loader":"^8.1.0","typescript":"^4.2.4","webpack":"^4.46.0","webpack-cli":"^4.6.0"},"peerDependencies":{"react":"^16.12.0","react-dom":"^16.12.0"},"dependencies":{"deepmerge":"^4.2.2","fast-deep-equal":"^3.1.3","immer":"^9.0.1","pluralize":"^8.0.0","qs":"^6.10.1","re-reselect":"^4.0.0","react-redux":"^7.2.3","redux":"^4.0.5","redux-thunk":"^2.3.0","reselect":"^4.0.0","whatwg-fetch":"^3.6.2"},"gitHead":"e1a910ba9defd429cf7341e2f087552254459c73","bugs":{"url":"https://github.com/ableco/overpass/issues"},"homepage":"https://github.com/ableco/overpass#readme","_id":"@ableco/overpass@0.8.2","_nodeVersion":"12.22.10","_npmVersion":"6.14.16","dist":{"integrity":"sha512-KVRPyZhnfcZ8pL5Vn8utq6CTVVE65WfmAe1c52dltmAmRdC8u9/adZQ8RDORPtWe5JQNmEdbrOHZUyQIjyjf0w==","shasum":"0cff2e432d907567ce49a1697783e386d529e21f","tarball":"https://registry.npmjs.org/@ableco/overpass/-/overpass-0.8.2.tgz","fileCount":54,"unpackedSize":676539,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJiCnHbCRA9TVsSAnZWagAAC6EP/j0IPiWIc9zB3CVF/ao4\nGxfTKq7CFOVGGYQsiOz+C2U4+aYMg4hwaX2Vk38n+ehtbEiXN8d4BI+HdYs/\nPn++xelKsCo2cYwjgHsXqlqd5BCOJ0ijrZbeghjW9gHgEnunjK8Nrlof3Qvv\n6r2Q1IlnnioJvrK8H6/JNN+mv6evHOLkmcPNCGXAfLbCvTYnEC6bcbNGDSKf\nPjW9vO7P6KtK4Jl63h+dMvAwACor28A+s5mT+fHDRysnkFeOGW45NTTBWxQ3\nikvQOx3xT79gLIJnS36WyS2fxQLvptglnZY5b7t2GCg2gN1zEPuQIcrOQdwT\nNW+wkyiog4nmVizwRZq3v34QxByzTQTW9TqsWo8a6nRq3kafUqYnldu47G3p\n86pNGfPBv/MIGg1llIs2wJ3M+ywbZr/5fbrG2Mffq/Cl5qFSV7NNZZxtaHLN\ni4O1yf42yS0yjLgzTR8vvZQfPA6OplrY72uXB7vGalQE6YaeYsEUiUM1hQH6\nv5YxNTROWoTlEXgWOSOyTC+I+ROVWFg2S5Gq4tOhIlLgy+Q3Fnu7dbU++PC1\n54Abl+hMqpJMPOndYlx5Ckanvi32dAzuhSBuC9Moxz9c2w7T5Ozc15r0aRcj\ncZtF59Ys3Azk9V8QQQ+c5irqavIuxTplNwXZblpBYpSh+DdMd+HZ198tyYTz\nqEHt\r\n=nZ2F\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGXx0uCiM702C3KV38+lmcQ+QLeQpp77BFYtyvVQu/JKAiAClGjpYOGOR8I0LRuLX0AMCTz05tm9FTFyZj5ATS30og=="}]},"_npmUser":{"name":"ableco-npm","email":"npm@able.co"},"directories":{},"maintainers":[{"name":"ableco-npm","email":"npm@able.co"},{"name":"sergiodxa","email":"sergiodxa@gmail.com"},{"name":"arturopuente","email":"arturopuentevc@gmail.com"},{"name":"moisesnandres","email":"moisesnandres@hey.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/overpass_0.8.2_1644851675647_0.8139784544293285"},"_hasShrinkwrap":false},"0.8.3":{"name":"@ableco/overpass","version":"0.8.3","description":"Redux-based hooks-powered bridge between JSON:API endpoints and React components","main":"dist/overpass.js","repository":{"type":"git","url":"git+https://github.com/ableco/overpass.git"},"scripts":{"build":"webpack","dev":"webpack --watch","pretest":"npm run build","test":"jest","prettify":"prettier --write \"**/*.{js,json}\"","lint":"eslint \"**/*.js\""},"types":"dist/main.d.ts","author":{"name":"Able co."},"license":"MIT","devDependencies":{"@ableco/eslint-config":"^0.4.1","@babel/core":"^7.22.15","@babel/preset-env":"^7.22.15","@babel/preset-react":"^7.22.15","@babel/preset-typescript":"^7.22.15","@testing-library/react":"^11.2.6","@testing-library/react-hooks":"^8.0.1","@types/jest":"^26.0.22","@types/pluralize":"0.0.29","@types/qs":"^6.9.6","@types/react":"^17.0.3","@types/react-redux":"^7.1.16","@typescript-eslint/eslint-plugin":"^6.6.0","@typescript-eslint/parser":"^6.6.0","core-js":"^3.32.2","eslint":"^7.32.0","fetch-mock":"^9.11.0","jest":"^26.6.3","node-fetch":"^2.6.1","prettier":"^2.8.8","react":"^16.14.0","react-dom":"^16.14.0","regenerator-runtime":"^0.14.0","ts-loader":"^9.4.4","typescript":"^4.3.5","webpack":"^5.88.2","webpack-cli":"^5.1.4"},"peerDependencies":{"react":"^16.12.0","react-dom":"^16.12.0"},"dependencies":{"deepmerge":"^4.2.2","fast-deep-equal":"^3.1.3","immer":"^9.0.19","pluralize":"^8.0.0","qs":"^6.10.1","re-reselect":"^4.0.0","react-redux":"^8.1.2","redux":"^4.2.1","redux-thunk":"^2.4.2","reselect":"^4.0.0","whatwg-fetch":"^3.6.2"},"gitHead":"714db52026c249ab209fb2610dae9872d1c218e7","bugs":{"url":"https://github.com/ableco/overpass/issues"},"homepage":"https://github.com/ableco/overpass#readme","_id":"@ableco/overpass@0.8.3","_nodeVersion":"12.22.12","_npmVersion":"6.14.16","dist":{"integrity":"sha512-AXqa1tK7lIMy0PccRi4o6Jpv8awjq2f6MLS+MJl2vqWY22JCHN2dkl2lWzKVopK2epaT1W64iuS/+XbGtLy8/w==","shasum":"5027ca464f0de2acf9de72970cd42de3fdd3fa42","tarball":"https://registry.npmjs.org/@ableco/overpass/-/overpass-0.8.3.tgz","fileCount":65,"unpackedSize":804267,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHMIdcdbRzIfrNN2bouOPqSsuJ3Be4hOQPrDar44udrYAiBK8Lra/tY8Vq7DfBjLH/5Ahv9/ql1iKdE/asaAbC18Lg=="}]},"_npmUser":{"name":"ableco-npm","email":"npm@able.co"},"directories":{},"maintainers":[{"name":"ableco-npm","email":"npm@able.co"},{"name":"sergiodxa","email":"sergiodxa@gmail.com"},{"name":"arturopuente","email":"arturopuentevc@gmail.com"},{"name":"moisesnandres","email":"moisesnandres@hey.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/overpass_0.8.3_1694215992188_0.18443230226510066"},"_hasShrinkwrap":false}},"time":{"created":"2022-02-14T15:14:35.579Z","0.8.2":"2022-02-14T15:14:35.846Z","modified":"2023-09-08T23:33:12.669Z","0.8.3":"2023-09-08T23:33:12.430Z"},"maintainers":[{"name":"ableco-npm","email":"npm@able.co"},{"name":"sergiodxa","email":"sergiodxa@gmail.com"},{"name":"arturopuente","email":"arturopuentevc@gmail.com"},{"name":"moisesnandres","email":"moisesnandres@hey.com"}],"description":"Redux-based hooks-powered bridge between JSON:API endpoints and React components","homepage":"https://github.com/ableco/overpass#readme","repository":{"type":"git","url":"git+https://github.com/ableco/overpass.git"},"author":{"name":"Able co."},"bugs":{"url":"https://github.com/ableco/overpass/issues"},"license":"MIT","readme":"# Overpass\n\nRedux-based hooks-powered bridge between JSON:API endpoints and React components.\n\n## Installation\n\n### Using npm\n\n```sh\nnpm install @ableco/overpass\n```\n\n### Using yarn\n\n```sh\nyarn add @ableco/overpass\n```\n\n## Getting started\n\nTo map your application's JSON:API resources, define a `resources` object using `defineResources`:\n\n```js\nimport { defineResources } from \"@ableco/overpass\";\n\nconst resources = defineResources(({ resource }) => {\n  resource(\"categories\");\n  resource(\"products\");\n  resource(\"orders\");\n  resource(\"items\");\n});\n```\n\nThen, wrap your app with an `<OverpassProvider />` component. It will allow you to use Overpass across components in your application.\n\n`<OverpassProvider />` accepts a few props, as you will see later. Use the `resources` prop to let Overpass know how to store your resources:\n\n```jsx\nimport { defineResources } from \"@ableco/overpass\";\n\nconst resources = defineResources(({ resource }) => {\n  resource(\"categories\");\n  resource(\"products\");\n  resource(\"orders\");\n  resource(\"items\");\n});\n\n<OverpassProvider\n  api={{\n    apiPrefix: \"/api\",\n  }}\n  resources={resources}\n>\n  {/* your app */}\n</OverpassProvider>\n```\n\n## Usage\n\n### Fetching data\n\nThere are two ways to fetch data in Overpass. The first one is by fetching collections of resources, and the second one is by fetching single resources, known as entities.\n\n> **Note:** Overpass uses React hooks to work with the stored resources.\n\nTo fetch collections of entities, you can use `useFetchCollection`. The result of calling `useFetchCollection` is a function that can be used inside a `useEffect` hook:\n\n```jsx\nimport { useFetchCollection } from \"@ableco/overpass\";\n\nfunction CategoriesList() {\n  const fetchCategories = useFetchCollection(\"categories\");\n\n  useEffect(() => {\n    fetchCategories();\n  }, []);\n\n  return <div>{/* your component */}</div>;\n}\n```\n\nTo fetch a single entity, you can use `useFetchEntity`. Unlike `useFetchCollection`, `useFetchEntity` not only receives the entity's name but also a single entity's ID:\n\n```jsx\nimport { useFetchEntity } from \"@ableco/overpass\";\n\nfunction Product({ id }) {\n  const fetchProduct = useFetchEntity(\"products\", id);\n\n  useEffect(() => {\n    fetchProduct();\n  }, []);\n\n  return <div>{/* your component */}</div>;\n}\n```\n\n### Using fetched data\n\nAfter data is fetched with `useFetchCollection` or `useFetchEntity`, you can work with stored entities by using `useCollection` or `useEntity`:\n\n```jsx\nconst categories = useCollection(\"categories\");\nconst product = useEntity(\"products\", id);\n```\n\nYou can also filter collections or entities by a single attribute with `useFilteredCollection` or `useFilteredEntity`:\n\n```jsx\nconst categoryProducts = useFilteredCollection(\n  \"products\",\n  \"categoryId\",\n  categoryId,\n);\nconst mainProduct = useFilteredEntity(\"products\", \"mainProduct\", true);\n```\n\n### Mutating remotely\n\n> **Note:** The following hooks will make changes in your backend's database.\n\n#### Creating entities\n\nTo create an entity, Overpass provides a hook called `useCreateEntity`.\n\nThe function returned by `useCreateEntity` receives an object with the attributes for the entity to be created:\n\n```jsx\nconst createItem = useCreateEntity(\"items\");\n\nasync function addProductToCart(selectedProductId) {\n  await createItem({ productId: selectedProductId });\n}\n```\n\n#### Updating entities\n\n`useUpdateEntity` is an Overpass hook that receives two parameters, the resource's name and the ID of the entity to be updated.\n\nThe function returned by `useUpdateEntity` also receives an object with the attributes for the entity to be updated:\n\n```jsx\nconst updateItem = useUpdateEntity(\"items\", itemId);\n\nasync function updateCartItem(quantity) {\n  await updateItem({ quantity: quantity });\n};\n```\n\n#### Deleting entities\n\n`useDeleteEntity` lets you delete an entity. The function returned by `useDeleteEntity` receives the ID of the entity to be deleted:\n\n```jsx\nconst deleteItem = useDeleteEntity(\"items\");\n\nasync function removeCartItem(itemId) {\n  await deleteItem(itemId);\n};\n```\n\n## Testing\n\nRun the following command in a terminal:\n\n```sh\nnpm run test\n```\n\nOr this other one if you are using yarn:\n\n```sh\nyarn test\n```\n\n## Contributing\n\nContributions are welcome. Please check out the [Contributing guide](CONTRIBUTING.md) for the guidelines you need to follow.\n\nPlease read our [Code of Conduct](CODE_OF_CONDUCT.md) so that you can understand the kind of respectful behavior we expect from all participants.\n\n## License\n\nOverpass is released under the MIT license. See [LICENSE](LICENSE) for the full license text.\n","readmeFilename":"README.md"}