From 75171581ce0005fc80703d99bad86a6c60432c77 Mon Sep 17 00:00:00 2001 From: Paul d'Aoust Date: Mon, 8 Apr 2024 10:19:58 -0700 Subject: [PATCH] many edits to Holo enabling guide -- fixes, ToC, rearranging for flow --- src/pages/resources/enable-holo.md | 465 ++++++++++++++++++----------- 1 file changed, 288 insertions(+), 177 deletions(-) diff --git a/src/pages/resources/enable-holo.md b/src/pages/resources/enable-holo.md index 24fb7580b..1283910f8 100644 --- a/src/pages/resources/enable-holo.md +++ b/src/pages/resources/enable-holo.md @@ -1,33 +1,88 @@ --- title: Enable Apps for Holo Hosting +tocData: + - text: Intro + href: intro + - text: Get started + href: get-started + - text: Get started from scaffolding tool + href: get-started-from-scaffolding-tool + children: + - text: DNA + href: scaffold-dna + - text: UI + href: scaffold-ui + - text: Testing + href: testing + - text: Migrate from a pure Holochain app + href: migrate-from-a-pure-holochain-app + children: + - text: UI + href: migrate-ui + - text: Building and testing + href: building-and-testing + - text: Deploy + href: deploy + - text: Deploy a UI + href: deploy-a-ui + - text: Deploy a hApp to the Holo network + href: deploy-a-h-app-to-the-holo-network + - text: Holo core concepts and further documentation + href: holo-core-concepts-and-further-documentation + - text: Holo architecture + href: holo-architecture + - text: Client-conductor separation + href: client-conductor-separation + children: + - text: Sign-up, sign-in, sign-out + href: sign-up-sign-in-sign-out + - text: Handling connection state + href: handling-connection-state + - text: hApp paradigm + href: h-app-paradigm + children: + - text: Multi-tenant conductor + href: multi-tenant-conductor + - text: Providing high-uptime nodes + href: providing-high-uptime-nodes + - text: Serving data to anonymous users + href: serving-data-to-anonymous-users + - text: Implementing read-only cells + href: implementing-read-only-cells + - text: Anonymous zome function access + href: anonymous-zome-function-access + - text: Next steps + href: next-steps --- -!!! info Requires Holochain 0.2 -The Holo hosting network runs the unstable Holochain 0.2 on all its nodes, so you'll need to make sure that your hApp is compatible with 0.2. The scaffolding tool commands in this guide will set up the proper dependencies for you. If you're starting with an existing hApp or have used the scaffolding tool commands in the [Get Started guide](/get-started/), you'll need to upgrade your hApp manually. +!!! info Requires Holochain 0.3 +The Holo hosting network runs the unstable Holochain 0.3 on all its nodes, so you'll need to make sure that your hApp is compatible with 0.3. The scaffolding tool commands in this guide will set up the proper dependencies for you. If you're starting with an existing hApp or have used the scaffolding tool commands in the [Get Started guide](/get-started/), you'll need to upgrade your hApp manually. !!! -## Intro +::: intro +This guide will help you build a Holo-enabled hApp from scratch or enable your existing hApp to be deployed on Holo. +::: Holo is cloud hosting for Holochain. Holo helps you enable your users to experience your Holochain application with the simplicity of a web browser and without maintaining a node. A core distinction versus running nodes on the traditional cloud is that Holo provides the key management and signing infrastructure for users' keys to be held client-side, so your users always have full agency. -## Get started - -Holo hosting is for Holochain applications. It is assumed that you have familiarity with Holochain and have installed the pre-requisites from step 2 of the [Get Started guide](/get-started/). +We assume you're familiar with Holochain and have installed the pre-requisites from step 2 of the [Get Started guide](/get-started/). -There are two pathways in this section --- scaffolding a new hApp or migrating an existing hApp. Both pathways contain largely the same information, so choose the pathway that best applies to your situation. +There are two pathways in this section --- [**scaffolding a new hApp**](#get-started-from-scaffolding-tool) or [**migrating an existing hApp**](migrate-from-a-pure-holochain-app). Both pathways contain largely the same information, so choose the one that best applies to your situation. -In both cases there are no required DNA changes for Holo Hosting --- only UI changes. However, Holo operates under a different context and we highly recommend that you read the [Holo Core Concepts](#holo-core-concepts-and-further-documentation), in particular the section on anonymous access, as this **will need DNA changes to enable certain features**. +In both cases there are no required DNA changes for Holo Hosting --- only UI changes. However, Holo operates under a different context and we highly recommend that you read the [Holo core concepts](#holo-core-concepts-and-further-documentation), in particular the section on anonymous access, as this **will need DNA changes to enable certain features**. ## Get started from scaffolding tool -In this section we'll create a simple to-do app. Our commentary will focus on the UI differences compared to a pure Holochain context. If you need more information about creating a DNA, please refer to the [Holochain getting started guide](/get-started/#4-zero-to-built-creating-a-forum-app) +In this section we'll create a simple to-do app. Our commentary will focus on the UI differences compared to a pure Holochain context. If you need more information about creating a DNA, please refer to the [Holochain getting started guide](/get-started/#4-zero-to-built-creating-a-forum-app). + +### DNA {#scaffold-dna} -The Holochain scaffolding tool provides a `--holo` flag for scaffolding a hApp whose UI is compatible with both Holo hosting and pure Holochain environments. Additionally, because the Holo hosting infrastructure currently runs the unstable Holochain 0.2, you'll need to override the Holochain version that the scaffolding tool targets. Run the tool **with these flags** by typing in your terminal: +The Holochain scaffolding tool provides a `--holo` flag for scaffolding a hApp whose UI is compatible with both Holo hosting and pure Holochain environments. Additionally, because the Holo hosting infrastructure currently runs the unstable Holochain 0.3, you'll need to override the Holochain version that the scaffolding tool targets. Run the tool **with these flags** by typing in your terminal: -```shellsession -nix run --override-input versions 'github:holochain/holochain?dir=versions/0_2' github:holochain/holochain#hc-scaffold -- web-app --holo +```shell +nix run --override-input versions 'github:holochain/holochain?dir=versions/weekly' github:holochain/holochain#hc-scaffold -- web-app --holo ``` You should then see: @@ -69,13 +124,13 @@ Choose `Yes` and press Enter. You should then see `Setting up nix development environment...` with some details of what is being added, followed by instructions of next steps for setting up the development environment for your hApp and continuing to scaffold more of its elements. Let's follow those instructions. First, enter the hApp project directory: -```shellsession +```shell cd super_todos ``` Now enter the nix development shell (which makes all scaffolding tools as well as the Holochain binaries directly available from the command line) with: -```shellsession +```shell nix develop ``` @@ -89,68 +144,13 @@ Holochain development shell spawned. Type exit to leave. Finally, install the `npm` dependencies with: -```shellsession +```shell npm install ``` -### UI - -The biggest difference between a Holo application and a pure Holochain application is in the UI. The scaffolding tool should automatically have generated everything required here, so we'll simply point out the primary differences, which will all be in `App.vue`. - -In a Holo setting we use the [`@holo-host/web-sdk`](https://www.npmjs.com/package/@holo-host/web-sdk) library instead of `@holochain/client`. WebSDK provides an instance of `AppAgentWebsocket`, which is almost the same as `AppWebsocket`. - -```typescript -import WebSdk from '@holo-host/web-sdk'; -import type { AgentState } from '@holo-host/web-sdk'; -``` - -Holo hApps provide an authentication form for users to generate in-browser keys and install [cells](/resources/glossary/#cell) on the network. This form is customizable --- here we set the name of the app. - -```typescript -if (this.IS_HOLO) { - const client: WebSdk = await WebSdk.connect({ - chaperoneUrl: import.meta.env.VITE_APP_CHAPERONE_URL, - authFormCustomization: { - appName: 'super_todos', - } - }); - - client.on('agent-state', (agent_state: AgentState) => { - this.loading = !agent_state.isAvailable || agent_state.isAnonymous - }); - - client.signUp({ cancellable: false }); - - this.client = client -} else { - // We pass '' as url because it will dynamically be replaced in launcher environments - this.client = await AppAgentWebsocket.connect('', 'vue-default'); - this.loading = false; -} -``` - -Because there is the concept of "logging in", we also need a log out option to clear user keys from the client. - -```html - -``` - -```typescript -async logout () { - await (this.client as WebSdk).signOut(); - await (this.client as WebSdk).signIn({ cancellable: false }); -} -``` +Now let's create a new DNA using the scaffolding tool, which is now directly available in the shell. Type: -Now let's continue scaffolding our happ by creating a new DNA using the scaffolding tool, which is now directly available in the shell. Type: - -```shellsession +```shell hc scaffold dna ``` @@ -176,11 +176,11 @@ DNA "todos" scaffolded! ``` ::: -DNAs are [comprised of code modules](/concepts/2_application_architecture/), which we call zomes. A DNA should have at least two zomes, an *integrity zome* which declares the data structures and validation code, and a *coordinator zome* which contains, among other things, the API functions your UI will call to access your DNA. +DNAs are [composed of code modules](/concepts/2_application_architecture/), which we call zomes. A DNA should have at least two zomes, an *integrity zome* which declares the data structures and validation code, and a *coordinator zome* which contains, among other things, the API functions your UI will call to access your DNA. Create your DNA's first pair of zomes with: -```shellsession +```shell hc scaffold zome ``` @@ -206,7 +206,7 @@ Press Enter to select `Integrity/coordinator zome-pair`. You should t Type in a name for the zome. In this case you can just use the same name as the DNA, `todos`. You should then see: -```shellsession +```shell ? Scaffold integrity zome in folder "dnas/todos/zomes/integrity/"? (y/n) › ``` @@ -227,13 +227,13 @@ Now we get to the really exciting part! In the next steps you will specify your In this to-do hApp, every to-do item is stored as an [entry](/resources/glossary/#entry). Add a new entry definition with: -```shellsession +```shell hc scaffold entry-type ``` You should see: -```shellsession +```shell ✔ Entry type name (snake_case): · ``` @@ -264,7 +264,7 @@ Which fields should the entry contain? ``` ::: -The scaffolding tool is smart about adding different data type fields to your entry. For this example, you will just have a text field describing the to-do item. Press Enter to select `String`. +For this example, you will just have a text field describing the to-do item. Press Enter to select `String`. You should see: @@ -330,7 +330,7 @@ Entry type "todo_item" scaffolded! The final step is create a collection that can be used to retrieve all of the to-do items that users create. To create a collection, type: -```shellsession +```shell hc scaffold collection ``` @@ -342,7 +342,7 @@ Collection name (snake_case, eg. "all_posts"): › ``` ::: -Enter `my_todos` and press Enter. You should then see: +Enter `todos_by_author` and press Enter. You should then see: ::: output-block ```text @@ -365,20 +365,113 @@ Press Enter. You should then see: ::: output-block ```text -Collection "my_todos" scaffolded! +Collection "todos_by_author" scaffolded! ``` ::: +### UI {#scaffold-ui} + +The biggest difference between a Holo application and a pure Holochain application is in the UI. The scaffolding tool should automatically have generated everything required here, so we'll simply point out the primary differences, which will all be in `ui/src/App.vue`. + +Open up this file in your favorite text editor now and follow along! + +In a Holo setting we use the [`@holo-host/web-sdk`](https://www.npmjs.com/package/@holo-host/web-sdk) library instead of `@holochain/client`. Web SDK provides its own implementation of `AppAgentWebsocket`, which is almost the same as the one provided by `@holochain/client`. Scroll down to the beginning of the `