{"id":20759826,"url":"https://github.com/owsas/parse-offline","last_synced_at":"2025-04-30T05:21:31.686Z","repository":{"id":29581042,"uuid":"121903047","full_name":"owsas/parse-offline","owner":"owsas","description":"Parse JS SDK Addons for handling offline for PWAs","archived":false,"fork":false,"pushed_at":"2025-04-24T05:47:53.000Z","size":148,"stargazers_count":16,"open_issues_count":12,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-24T06:32:05.576Z","etag":null,"topics":["offline","parse","parse-js","parse-sdk","parse-server","pwa","pwa-apps"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/owsas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-02-18T00:00:11.000Z","updated_at":"2023-09-06T20:19:51.000Z","dependencies_parsed_at":"2023-01-14T15:14:18.345Z","dependency_job_id":"fe994879-984b-4ca2-8e33-ba5333d5f09d","html_url":"https://github.com/owsas/parse-offline","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/owsas%2Fparse-offline","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/owsas%2Fparse-offline/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/owsas%2Fparse-offline/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/owsas%2Fparse-offline/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/owsas","download_url":"https://codeload.github.com/owsas/parse-offline/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251645982,"owners_count":21620846,"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":["offline","parse","parse-js","parse-sdk","parse-server","pwa","pwa-apps"],"created_at":"2024-11-17T10:08:27.488Z","updated_at":"2025-04-30T05:21:31.667Z","avatar_url":"https://github.com/owsas.png","language":"TypeScript","funding_links":["https://patreon.com/owsas"],"categories":[],"sub_categories":[],"readme":"# Parse Offline\n\nParse JS SDK Addons for handling offline for PWAs\n\nBonus: No external dependencies\n\n\u003c!-- TOC --\u003e\n\n- [Parse Offline](#parse-offline)\n  - [The problem](#the-problem)\n  - [The solution](#the-solution)\n  - [How it works](#how-it-works)\n  - [Examples](#examples)\n    - [Basic](#basic)\n    - [Controlled cache time](#controlled-cache-time)\n    - [With custom cache key](#with-custom-cache-key)\n  - [Want to contribute?](#want-to-contribute)\n  - [Dev Features](#dev-features)\n  - [Credits](#credits)\n  - [License](#license)\n  - [Support us on Patreon](#support-us-on-patreon)\n\n\u003c!-- /TOC --\u003e\n\n## The problem\n\nWhen you develop applications with Parse, you constantly need to fetch the information from the remote server, affecting the offline experience.\n\n## The solution\n\nWith this addon for the Parse JS SDK, you can:\n\n* [x] Save query results in the `localStorage` for any class. With this, given a query, you could fetch its results and save them in the `localStorage` for later usage.\n\n* [x] Have a synced cache for your results in the `localStorage` for any class. So everytime you make a request, you can keep a local cache of the results, and display them when your app goes offline.\n\n* [ ] Edit/destroy objects, and save them when the app goes online.\n\n## How it works\n\nBecause the Parse JS SDK contacts your Parse Server via POST requests, and saves the user token in `localStorage`, it is currently not possible to handle retries via Service Worker. To solve this problem, the `localStorage` is used to save sets of results that you might need to see when the app goes offline. \n\n## Examples\n\nPlease be aware that the following examples are given in Typescript. The main difference between the Typescript and the Javascript examples is the way in which `parse` is imported.\n\nIn Typescript: \n```ts\nimport * as Parse from 'parse';\n```\n\nIn Javascript: \n```ts\nimport Parse from 'parse';\n```\n\n### Basic\nIn this example, we get a set of results from the database, and save them to the localStorage. To do this, we call `findWithFallbackAndCache` as follows:\n\n```ts\nimport * as Parse from 'parse';\nimport { ParseOffline } from 'parse-offline';\n\nconst query = new Parse.Query('Vehicle');\nconst results: Parse.Object[] = await ParseOffline.findWithFallbackAndCache({\n  query\n});\n```\n\n`findWithFallbackAndCache` always tries to fetch the most recent content, and only if the navigator is not online it returns the elements saved in the cache.\n\nThe results are saved in the `localStorage`, available in the key `_cache_:className`. So, you could do the following, to get the items saved in the browser's local storage:\n\n```ts\nlocalStorage.getItem('_cache_Vehicle'); // [{ ... }]\n```\n\n\n### Controlled cache time\n\nIn this example, we set a maximum age to the fetched results. If the results are still valid, they are returned. Else, the library returns an empty array. \n\n```ts\nimport * as Parse from 'parse';\nimport { ParseOffline } from 'parse-offline';\n\nconst ONE_WEEK = 60 * 60 * 24 * 7;\n\nconst query = new Parse.Query('Test');\nconst results: Parse.Object[] = await ParseOffline.findWithFallbackAndCache({\n  query,\n  options: { sessionToken: '123' },\n  maxAge: ONE_WEEK,\n});\n```\n\n### With custom cache key\n\nSometimes, you have different queries for the same class and you want to cache those results.\n\n```ts\nimport * as Parse from 'parse';\nimport { ParseOffline } from 'parse-offline';\n\n// Here we save a cache for the elements of the class Post\nconst query = new Parse.Query('Post');\nconst results: Parse.Object[] = await ParseOffline.findWithFallbackAndCache({\n  query,\n  localStorageKey: 'my-custom-key'\n});\n\n// Here we save another cache for the elements of the class Post\nconst query2 = new Parse.Query('Post');\nconst results2: Parse.Object[] = await ParseOffline.findWithFallbackAndCache({\n  query2,\n  localStorageKey: 'my-custom-key2'\n});\n```\n\nThe results do not collide because the `localStorageKey` is different.\n\n\n## Want to contribute?\n\nOpen a PR with your contribution and I'll be glad to merge it.\n\n## Dev Features\n* Testing with Jest\n* Linting out of the box (checks the style of your code), with TSLint\n* Build, prepublish and other scripts to help you to develop\n* Works with Typescript: Static typing for your JS Applications, reducing amount of runtime errors\n* Coverage out of the box, thanks to Jest\n* Uses deterministic module resolving, with Yarn\n\n## Credits\n\nDeveloped by Juan Camilo Guarín Peñaranda,  \nOtherwise SAS, Colombia  \n2018\n\n## License \n\nMIT.\n\n## Support us on Patreon\n[![patreon](./.repo/patreon.png)](https://patreon.com/owsas)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fowsas%2Fparse-offline","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fowsas%2Fparse-offline","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fowsas%2Fparse-offline/lists"}