{"id":20109794,"url":"https://github.com/hyper63/tour","last_synced_at":"2025-05-06T10:31:38.222Z","repository":{"id":44656112,"uuid":"336077641","full_name":"hyper63/tour","owner":"hyper63","description":null,"archived":false,"fork":false,"pushed_at":"2022-02-01T20:11:09.000Z","size":372,"stargazers_count":4,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-01T10:20:52.525Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/hyper63.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}},"created_at":"2021-02-04T20:44:05.000Z","updated_at":"2024-05-01T10:20:52.526Z","dependencies_parsed_at":"2022-07-24T21:02:19.192Z","dependency_job_id":null,"html_url":"https://github.com/hyper63/tour","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyper63%2Ftour","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyper63%2Ftour/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyper63%2Ftour/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyper63%2Ftour/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hyper63","download_url":"https://codeload.github.com/hyper63/tour/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224499930,"owners_count":17321605,"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-11-13T18:09:27.468Z","updated_at":"2024-11-13T18:09:28.522Z","avatar_url":"https://github.com/hyper63.png","language":"JavaScript","readme":"\u003ch1 align=\"center\"\u003eTour of hyper ⚡️\u003c/h1\u003e\n\n👋 Hello!\n\nWelcome to the tour of the hyper services, in this tour, we will guide you through the \n📦 data service, 💲 cache service, and 🔎 search service. You will get a feel for how they work.\n\nIn this tour, we will walk through the hyper api methods for data, cache, and search\n\n---\n\n## Table of Contents\n\n- [Setup](#setup)\n- [Data](#data)\n- [Cache](#cache)\n- [Search](#search)\n\n## Getting Started\n\nBefore we get started, you need to clone this repository: https://github.com/hyper63/tour \nThen you need to make sure you have NodeJS v16 or greater installed https://nodejs.org. And a code editor \nwith a terminal. VS Code is a good choice. https://code.visualstudio.com\n\n### Prerequisites\n\n* NodeJS v16+ https://nodejs.org\n* Editor https://code.visualstudio.com\n* Github Account https://github.com\n* git https://git-scm.org\n\n## Setup\n\nThe first thing we need to do, is to go to https://dashboard.hyper.io and login with our github account, once on the dashboard applications view, click the `add application` button. To create a new hyper app.\n\n\u003e A hyper app is a specific api service for a given name. It called an app because most of the time, this will be your API service layer for the application you are building and you would have one hyper app per application and environment.\n\nOpen a terminal to this directory and set up your HYPER env variable. In this directory create a new file called `.env` and in this file, you will want to copy the `connection-string` from the hyper dashboard of the new app you created and paste it as the value of the `HYPER` env variable.\n\n.env\n\n``` text\nHYPER=[paste your connection string here]\n```\n\n\u003e How do I get my connection string? Go to https://dashboard.hyper.io login with your github account, and then click on the application you created for this workshop, while viewing the app view, click the document icon to the left of the connection-string label. This will copy the string to your clipboard, now you can paste in your `.env` file.\n\nThen run \n\n``` sh\nnpm install\nnpm install hyper-connect\n```\n\nOpen the `index.js` file in your editor, everytime you type, you should see the results appear in your terminal.\n\n\u003e NOTE: after each section, there will be a note to `clear the sandbox` this means to delete all of the code between the `\u003csandbox\u003e\u003c/sandbox\u003e`\n\n---\n\n## Data\n\nadd a document\n\nLets add a document to our new store, we have these movie documents \nalready created above. Using the put command, we will re-create\nthe data store, and then using the post command we will create a\nnew document.\n\nIn between the `\u003csandbox\u003e\u003c/sandbox\u003e` comments add the following\ncommands.\n\n``` js\nconst result = await hyper.data.add({\n  id: 'ghostbusters',\n  type: 'movie',\n  title: 'Ghostbusters',\n  year: '1984',\n  genres: ['action', 'comedy']\n})\n\nconsole.log(result)\n```\n\n\u003e Save `index.js`\n\nexpected output\n\n``` sh\n#\u003e { ok: true, id: 'ghostbusters' }\n```\n\n\u003e NOTE: clear the sandbox \n\nget a document\n\nNow that we saved a document, lets get the document by id\n\n``` js\nconst result = await hyper.data.get('ghostbusters')\nconsole.log(result)\n```\n\n\u003e Save `index.js`\n\nexpected output\n\n``` js\n{\n  id: 'ghostbusters',\n  type: 'movie',\n  title: 'Ghostbusters',\n  year: '1984',\n  genres: ['action', 'comedy']\n}\n```\n\n\u003e NOTE: clear sandbox\n\nupdate a document\n\nWe can update a document using the put method.\n\n``` js\nlet ghostbusters = await hyper.data.get('ghostbusters')\nghostbusters = {...ghostbusters, poster: 'ghostbusters.jpg'}\n// update document\nconst result = await hyper.data.update('ghostbusters', ghostbusters)\nconsole.log(result)\n```\n\n\u003e Save `index.js`\n\nexpected output\n\n```\n{\"ok\":true,\"id\":\"ghostbusters\"}\n```\n\n\u003e NOTE: clear sandbox\n\nremove a document\n\nWe can also remove documents, by sending a `DELETE` command.\n\n``` js\nconst result = await hyper.data.remove('ghostbusters')\nconsole.log(result)\n```\n\n\u003e Save `index.js`\n\nexpected output\n\n``` json\n{\"ok\":true,\"id\":\"ghostbusters\"}\n```\n\n\u003e NOTE: clear sandbox\n\nquery a document\n\nhyper63 uses a powerful object structured query language similar to \nmongodb, on the backend it transforms it to the appropriate query for \nthe given database.\n\nYou can view all of the options here: https://docs.hyper63.com/query-selector\n\nIn this tutorial, we will do a search on document type and year\nless than 2000.\n\n\n``` js\nconst result = await hyper.data.bulk(movies)\nconsole.log(result)\nconst { docs } = await hyper.data.query({\n  type: 'movie',\n  year: {\n    $lt: '2012'\n  }\n})\n\nconsole.log(docs)\n```\n\n\u003e Save `index.js`\n\nexpected output\n\n``` js\n{\n  ok: true,\n  results: [\n    { ok: true, id: 'ghostbusters' },\n    { ok: true, id: 'avengers' },\n    { ok: true, id: 'dune' }\n  ]\n}\n\n[\n  { type: 'movie', name: 'Avengers', year: '2011', id: 'avengers' },\n  {\n    type: 'movie',\n    name: 'Ghostbusters',\n    year: '1984',\n    id: 'ghostbusters'\n  }\n]\n```\n\n\u003e NOTE: clear sandbox\n\n\nSummary\n\nThis is a quick tour through the data api, you can read more about the data api at our documentation site: https://docs.hyper.io/cloud\n\n---\n\n## Cache\n\nThe cache service, gives you a common interface to a cache service, whether it is memory, redis, or elastic cache. You can use the same api to manage key/value objects in a lighting fast cache.\n\nadd a key/value pair\n\na cache contains a key and a value,\nthe key must be a string, and a value,\nwhich can be any json parsable value.\n\n``` js\nconst result = await hyper.cache.add('action-2012-avengers', \n  { type: 'movie', title: 'Avengers', year: '2012', id: 'avengers' })\n\nconsole.log(result)\n```\n\n\u003e save `index.js`\n\nexpected output\n\n``` sh\n{ \"ok\": true }\n```\n\n\nremove a key/value pair\n\n``` js\nconst result = await hyper.cache.remove('action-2012-avengers')\nconsole.log(result)\n```\n\n\u003e NOTE: save `index.js`\n\nexpected output\n\n\n``` sh\n#\u003e { \"ok\": true }\n```\n\n\u003e NOTE: clear sandbox\n\nquery a key/value pair\n\nYou can run a simple query for a set of keys by using a simple match pattern.\n\n```\nabc* = starts with abc\n*xyz = ends with xyz\nabc*xyz = starts with abc and ends with xyz\n```\n\nTo demonstrate, we will add a couple of key/value pairs \nto the cache.\n\n``` js\nconst result1 = await hyper.cache.add('action-2012-avengers', {\n  \"id\": \"avengers\",\n  \"type\": \"movie\",\n  \"title\": \"Avengers\",\n  \"year\": \"2012\"\n})\n\nconst result2 = await hyper.cache.add('action-1984-ghostbusters', {\n  \"id\": \"ghostbusters\",\n  \"type\": \"movie\",\n  \"title\": \"Ghostbusters\",\n  \"year\": \"1984\"\n})\n\nconsole.log(result1)\nconsole.log(result2)\n```\n\n\u003e NOTE: save `index.js`\n\nexpected output\n\n\u003e NOTE: clear sandbox\n\nNext we will query for all keys that start with action.\n\n``` js\nconst result = await hyper.cache.query('action*')\nconsole.log(result.docs)\n```\n\n\u003e Save `index.js`\n\nexpected output \n\n``` sh\n[\n  {\n    key: 'action-2012-avengers',\n    value: { id: 'avengers', type: 'movie', title: 'Avengers', year: '2012' }\n  },\n  {\n    key: 'action-1984-ghostbusters',\n    value: {\n      id: 'ghostbusters',\n      type: 'movie',\n      title: 'Ghostbusters',\n      year: '1984'\n    }\n  }\n]\n```\n\n\u003e NOTE: clear sandbox\n\nWe can also query for all keys that end with 1984\n\n``` js\nconst result = await hyper.cache.query('*1984*')\nconsole.log(result.docs)\n```\n\n\u003e Save `index.js`\n\nexpected output\n\n``` sh\n[\n  {\n    key: 'action-1984-ghostbusters',\n    value: {\n      id: 'ghostbusters',\n      type: 'movie',\n      title: 'Ghostbusters',\n      year: '1984'\n    }\n  }\n]\n```\n\n\u003e NOTE: clear sandbox\n\nSummary\n\nThis has been a quick introduction to the cache service, with these basic mechanics you can compose functions to create complex caching patterns to keep your applications responsive as they increase in traffic and need to scale.\n\nFor more information about the cache service, check out our docs, at https://docs.hyper63.com/cache-api\n\n---\n\n## Search\n\nThe search service allows you to create a search index specifying the fields you would\nlike to index in each document you provide to the search index. Then it the service gives you the create, read, update and delete commands, for basic search document management. Finally, the search service provides a query command to `search` your index with free text.\n\ncreate a search index\n\nJust like creating a data store or a cache we use a `put` to create a search index, the one difference, is that we have to provide a mapping object, this object tells the search index, which fields in the documents that we will be posting to the index will be used for the search. The property name to let the index know what fields to index is called `fields` and it takes an `array` of `strings` which should match your property names. You can optionally add another property called `storeFields` this property tells the search index what properties to return with the search results.\n\nadd Documents\n\nIn order to search for documents, you need to add them to your search index, we can do that by using `post` one document at a time, or we can use the `_bulk` action to post a collection of documents.\n\n\nLets add our movies as search documents.\n\n``` js\nconst result = await hyper.search.load(movies)\nconsole.log(result)\n```\n\n\u003e NOTE: save `index.js`\n\nexpected output\n\n``` sh\n{\n  ok: true,\n  results: [ { index: [Object] }, { index: [Object] }, { index: [Object] } ]\n}\n```\n\n\u003e NOTE: clear sandbox\n\nquery Index\n\nNow that we have our search index created with some documents, lets do a query. A query is a `_query` command that we post to the service. In this command, we need to provide a json body that contains a property called `query`, we can optionally add other properties, like `term` and `filter`, but for now, lets just do a simple query. The query property takes a string that is used to match the search documents.\n\n``` js\nconst result = await hyper.search.query('1984')\nconsole.log(result)\n```\n\n\u003e NOTE: save `index.js`\n\nexpected output\n\n``` sh\n\n{\n  ok: true,\n  matches: [\n    {\n      id: 'ghostbusters',\n      type: 'movie',\n      title: 'Ghostbusters',\n      year: '1984'\n    }\n  ]\n}\n```\n\n\u003e NOTE: clear sandbox\n\nLets do another query, this time on the title.\n\n``` js\nconst result = await hyper.search.query('Ghostbusters')\nconsole.log(result)\n```\n\n\u003e NOTE: save `index.js`\n\nexpected output\n\n``` sh\n{\n  ok: true,\n  matches: [\n    {\n      id: 'ghostbusters',\n      type: 'movie',\n      title: 'Ghostbusters',\n      year: '1984'\n    }\n  ]\n}\n```\n\n\u003e NOTE: clear sandbox\n\nSummary\n\nThe search service provides a simple and easy to use interface to create search indexes, add/remove documents and query documents using free text. It is a powerful tool for any application and with hyper63 it comes inside the box. For more details about the search service checkout the documentation: https://docs.hyper63.com/search-api\n\n\n### Conclusion\n\nWell, that concludes the tour of the hyper63 service offering for now, we will be adding our storage service to the tour shortly, and more services will be included in the future. If you have a service you would like to see as part of hyper63, go to the discussions board and post your request: https://github.com/hyper63/hyper/discussions\n\nIf you have any problems with this tour feel free to post an issue on https://github.com/hyper63/tour/issues, or submit a pull request to https://github.com/hyper63/tour.\n\nIf you enjoyed this tour, give our project a star: https://github.com/hyper63/hyper63 or post a tweet referencing `@_hyper_io`\n\n👋 Until next time, have a great day! 🐶⚡\n\n---\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyper63%2Ftour","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhyper63%2Ftour","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyper63%2Ftour/lists"}