@powerhousedao/academy 5.1.0-staging.0 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/CHANGELOG.md +46 -1148
  2. package/blog/BeyondCommunication-ABlueprintForDevelopment.md +1 -2
  3. package/blog/TheChallengeOfChange.md +0 -1
  4. package/docs/academy/00-EthereumArgentinaHackathon.md +207 -0
  5. package/docs/academy/01-GetStarted/00-ExploreDemoPackage.mdx +27 -24
  6. package/docs/academy/01-GetStarted/01-CreateNewPowerhouseProject.md +10 -155
  7. package/docs/academy/01-GetStarted/02-DefineToDoListDocumentModel.md +35 -122
  8. package/docs/academy/01-GetStarted/03-ImplementOperationReducers.md +155 -178
  9. package/docs/academy/01-GetStarted/04-BuildToDoListEditor.md +218 -0
  10. package/docs/academy/{02-MasteryTrack/01-BuilderEnvironment → 01-GetStarted}/05-VetraStudio.md +22 -62
  11. package/docs/academy/01-GetStarted/06-ReactorMCP.md +58 -0
  12. package/docs/academy/01-GetStarted/_04-BuildToDoListEditor +1 -1
  13. package/docs/academy/02-MasteryTrack/01-BuilderEnvironment/03-BuilderTools.md +2 -2
  14. package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/02-SpecifyTheStateSchema.md +44 -75
  15. package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/03-SpecifyDocumentOperations.md +22 -28
  16. package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/04-UseTheDocumentModelGenerator.md +31 -28
  17. package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/05-ImplementDocumentReducers.md +206 -211
  18. package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/06-ImplementDocumentModelTests.md +62 -176
  19. package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/07-ExampleToDoListRepository.md +0 -21
  20. package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/01-BuildingDocumentEditors.md +319 -309
  21. package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/06-DocumentTools/00-DocumentToolbar.mdx +0 -4
  22. package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/06-DocumentTools/01-OperationHistory.md +0 -4
  23. package/docs/academy/02-MasteryTrack/05-Launch/04-ConfigureEnvironment.md +1 -1
  24. package/docs/academy/03-ExampleUsecases/Chatroom/02-CreateNewPowerhouseProject.md +35 -111
  25. package/docs/academy/03-ExampleUsecases/Chatroom/03-DefineChatroomDocumentModel.md +79 -195
  26. package/docs/academy/03-ExampleUsecases/Chatroom/04-ImplementOperationReducers.md +241 -435
  27. package/docs/academy/03-ExampleUsecases/Chatroom/05-ImplementChatroomEditor.md +27 -388
  28. package/docs/academy/03-ExampleUsecases/Chatroom/06-LaunchALocalReactor.md +7 -95
  29. package/docs/academy/03-ExampleUsecases/Chatroom/_category_.json +1 -1
  30. package/docs/academy/04-APIReferences/00-PowerhouseCLI.md +2 -6
  31. package/docs/academy/04-APIReferences/01-ReactHooks.md +501 -291
  32. package/docs/academy/05-Architecture/00-PowerhouseArchitecture.md +39 -7
  33. package/docs/academy/05-Architecture/02-ReferencingMonorepoPackages +65 -0
  34. package/docs/academy/05-Architecture/04-MovingBeyondCRUD +61 -0
  35. package/docs/academy/06-ComponentLibrary/00-DocumentEngineering.md +24 -72
  36. package/docs/academy/08-Glossary.md +0 -7
  37. package/docusaurus.config.ts +3 -28
  38. package/package.json +1 -1
  39. package/sidebars.ts +13 -49
  40. package/src/css/custom.css +18 -26
  41. package/docs/academy/01-GetStarted/04-WriteDocumentModelTests.md +0 -425
  42. package/docs/academy/01-GetStarted/05-BuildToDoListEditor.md +0 -557
  43. package/docs/academy/02-MasteryTrack/01-BuilderEnvironment/images/Modules.png +0 -0
  44. package/docs/academy/02-MasteryTrack/01-BuilderEnvironment/images/VetraStudioDrive.png +0 -0
  45. package/docs/academy/02-MasteryTrack/05-Launch/05-DockerDeployment.md +0 -384
  46. package/docs/academy/03-ExampleUsecases/TodoList/00-GetTheStarterCode.md +0 -24
  47. package/docs/academy/03-ExampleUsecases/TodoList/01-GenerateTodoListDocumentModel.md +0 -211
  48. package/docs/academy/03-ExampleUsecases/TodoList/02-ImplementTodoListDocumentModelReducerOperationHandlers.md +0 -171
  49. package/docs/academy/03-ExampleUsecases/TodoList/03-AddTestsForTodoListActions.md +0 -462
  50. package/docs/academy/03-ExampleUsecases/TodoList/04-GenerateTodoListDocumentEditor.md +0 -45
  51. package/docs/academy/03-ExampleUsecases/TodoList/05-ImplementTodoListDocumentEditorUIComponents.md +0 -422
  52. package/docs/academy/03-ExampleUsecases/TodoList/06-GenerateTodoDriveExplorer.md +0 -61
  53. package/docs/academy/03-ExampleUsecases/TodoList/07-AddSharedComponentForShowingTodoListStats.md +0 -384
  54. package/docs/academy/03-ExampleUsecases/TodoList/_category_.json +0 -8
  55. package/docs/academy/03-ExampleUsecases/VetraPackageLibrary/VetraPackageLibrary.md +0 -7
  56. package/docs/academy/03-ExampleUsecases/VetraPackageLibrary/_category_.json +0 -9
  57. package/docs/academy/04-APIReferences/06-VetraRemoteDrive.md +0 -160
  58. package/docs/academy/04-APIReferences/renown-sdk/00-Overview.md +0 -316
  59. package/docs/academy/04-APIReferences/renown-sdk/01-Authentication.md +0 -672
  60. package/docs/academy/04-APIReferences/renown-sdk/02-APIReference.md +0 -957
  61. package/docs/academy/04-APIReferences/renown-sdk/_category_.json +0 -8
  62. package/docs/academy/10-TodoListTutorial/02-ImplementTodoListDocumentModelReducerOperationHandlers.md +0 -171
  63. package/docs/academy/10-TodoListTutorial/03-AddTestsForTodoListActions.md +0 -462
  64. package/docs/academy/10-TodoListTutorial/05-ImplementTodoListDocumentEditorUIComponents.md +0 -422
  65. package/docs/academy/10-TodoListTutorial/07-AddSharedComponentForShowingTodoListStats.md +0 -370
  66. package/static/img/Vetra-logo-dark.svg +0 -11
  67. package/static/img/vetra-logo-light.svg +0 -11
  68. /package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/06-DocumentTools/{02-RevisionHistoryTimeline/360/237/232/247" → 02-RevisionHistoryTimeline} +0 -0
  69. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /01-WhatIsADocumentModel" → 01-WhatIsADocumentModel} +0 -0
  70. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /02-DAOandDocumentsModelsQ+A" → 02-DAOandDocumentsModelsQ+A} +0 -0
  71. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /02-domain-modeling" → 02-domain-modeling} +0 -0
  72. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /03-BenefitsOfDocumentModels" → 03-BenefitsOfDocumentModels} +0 -0
  73. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /04-UtilitiesAndTips" → 04-UtilitiesAndTips} +0 -0
  74. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /05-best-practices" → 05-best-practices} +0 -0
  75. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /_category_.json" → _category_.json} +0 -0
  76. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /three-data-layers.png" → three-data-layers.png} +0 -0
@@ -1,9 +1,5 @@
1
1
  # Document Toolbar
2
2
 
3
- :::warning Work in Progress
4
- This documentation is still being written and may be incomplete.
5
- :::
6
-
7
3
  The Document Toolbar is a central component in Powerhouse Connect, appearing at the top of every document view. It provides quick access to a variety of tools and functions designed to streamline your workflow and enhance document management.
8
4
 
9
5
  <figure className="image-container">
@@ -63,10 +63,6 @@ You can also view the committer's address for each revision, supporting full tra
63
63
 
64
64
  ![Committer Address Popup](./images/committer-address-popup.png)
65
65
 
66
-
67
- :::warning Work in Progress
68
- This remainder of this documentation is still being written and may be incomplete.
69
- :::
70
66
  ## Replay, branch, and merge (under development)
71
67
 
72
68
  - **Replay:** When you load a document, the system replays all operations to build its state.
@@ -75,7 +75,7 @@ PH_CONNECT_ARBITRUM_ALLOW_LIST=""
75
75
  PH_CONNECT_RWA_ALLOW_LIST=""
76
76
  PH_CONNECT_HIDE_DOCUMENT_MODEL_SELECTION_SETTINGS="true"
77
77
 
78
- PH_CONNECT_RENOWN_URL="https://www.renown.id"
78
+ PH_CONNECT_RENOWN_URL="https://auth.renown.id"
79
79
  PH_CONNECT_RENOWN_NETWORK_ID="eip155"
80
80
  PH_CONNECT_RENOWN_CHAIN_ID=1
81
81
  PH_CONNECT_DISABLED_EDITORS="powerhouse/document-drive"
@@ -1,112 +1,46 @@
1
- # Create a new chatroom project
1
+ # Create New Powerhouse Project
2
2
 
3
- :::tip Tutorial Repository
4
- 📦 **Reference Code**: [chatroom-demo](https://github.com/powerhouse-inc/chatroom-demo)
3
+ :::tip **Prerequisites**
5
4
 
6
- This tutorial has a complete reference implementation available. You can:
7
- - View the complete code for each step
8
- - Clone and compare your implementation
9
- - Use `git diff` to compare your code with the reference
10
- :::
11
-
12
- <details>
13
- <summary>📖 How to use this tutorial</summary>
14
-
15
- This tutorial is designed for you to **build your own project from scratch** while having access to reference code.
16
-
17
- ### Setup: Create your project and connect to tutorial repo
18
-
19
- 1. **Create your project** following the tutorial:
20
- ```bash
21
- mkdir ph-projects
22
- cd ph-projects
23
- ph init
24
- # When prompted, enter project name: ChatRoom
25
- cd ChatRoom
26
- ```
27
-
28
- 2. **Add the tutorial repository as a remote** to access reference code:
29
- ```bash
30
- git remote add tutorial https://github.com/powerhouse-inc/chatroom-demo.git
31
- git fetch tutorial --prune
32
- ```
33
-
34
- 3. **Create your own branch** to keep your work organized:
35
- ```bash
36
- git checkout -b my-chatroom-project
37
- ```
38
-
39
- Now you have access to the complete reference implementation while working on your own code!
40
-
41
- ### Compare your work with the reference
42
-
43
- At any point, compare what you've built with the reference:
44
-
45
- ```bash
46
- # Compare your current work with the reference
47
- git diff tutorial/main
48
-
49
- # Compare specific files
50
- git diff tutorial/main -- package.json
51
- ```
52
-
53
- ### If you get stuck
54
-
55
- Reset your code to match the reference:
56
-
57
- ```bash
58
- # Reset to reference (WARNING: loses your changes)
59
- git reset --hard tutorial/main
60
- ```
61
-
62
- </details>
63
-
64
- ## Overview
65
-
66
- This tutorial guides you through creating a **ChatRoom** application using Powerhouse.
67
- A Powerhouse project primarily consists of a document model and its editor. The ChatRoom demonstrates real-time collaboration features where users can post messages and react with emojis.
68
-
69
- ## Prerequisites
70
-
71
- - Powerhouse CLI installed: `pnpm install -g ph-cmd` or `npm install -g ph-cmd`
72
- - node.js 22 and a package manager (pnpm or npm) installed
5
+ - Powerhouse CLI installed: `pnpm install -g ph-cmd`
6
+ - node.js 22 and pnpm installed
73
7
  - Visual Studio Code (or your preferred IDE)
74
8
  - Terminal/Command Prompt access
75
9
 
76
10
  If you need help with installing the prerequisites you can visit our page [prerequisites](/academy/MasteryTrack/BuilderEnvironment/Prerequisites)
11
+ :::
77
12
 
78
- ## Quick start
79
-
80
- Create a new Powerhouse project with a single command:
13
+ To create a new Powerhouse Document Model Library project, you can use the `ph init` command in your terminal. This command will create a new project in the current directory.
14
+ This command will create a new project in the current directory. You can run the command in the terminal window of your OS or you open the newly installed VSCode and run the command in the terminal window of VSCode.Make sure the terminal reflects the directory where you want to create the new project.
81
15
 
82
16
  ```bash
83
- ph init
17
+ mkdir ph-projects
18
+ cd ph-projects
84
19
  ```
85
20
 
86
- ## Before you begin
21
+ This essentially opens that folder and places you in it.
87
22
 
88
- 1. Open your terminal (either your system terminal or IDE's integrated terminal)
89
- 2. Optionally, create a folder first to keep your Powerhouse projects:
23
+ Once you've navigated to the directory where you want to create the new project and in your terminal, run the following command:
90
24
 
91
- ```bash
92
- mkdir ph-projects
93
- cd ph-projects
94
- ```
25
+ ```bash
26
+ ph init
27
+ ```
95
28
 
96
- 3. Ensure you're in the correct directory before running the `ph init` command.
97
- In the terminal, you will be asked to enter the project name. Fill in the project name and press Enter.
29
+ In the terminal, you will be asked to enter the project name. Fill in the project name and press enter. Make sure to pay attention to the capitalization of our name `ChatRoom` as it will influence your code generation.
98
30
 
99
- ```bash
100
- you@yourmachine:~/ph-projects % ph init
31
+ ```bash
32
+ you@yourmachine:~/Powerhouse$ ph init
101
33
 
102
- ? What is the project name? ‣ ChatRoom
103
- ```
34
+ ? What is the project name? ‣ ChatRoom
35
+ ```
104
36
 
105
37
  Once the project is created, you will see the following output:
106
38
 
107
39
  ```bash
108
- Initialized empty Git repository in /Users/you/ph-projects/ChatRoom/.git/
109
- The installation is done!
40
+ The installation is done!
41
+
42
+ You can start by typing:
43
+ cd ChatRoom
110
44
  ```
111
45
 
112
46
  Navigate to the newly created project directory:
@@ -115,9 +49,9 @@ Navigate to the newly created project directory:
115
49
  cd ChatRoom
116
50
  ```
117
51
 
118
- ## Develop your document model in Connect
52
+ Once you are in the project directory, now you can run the `ph connect` command to instantiate a local version of the Connect application to start building your document model.
119
53
 
120
- Once in the project directory, run the `ph connect` command to start a local instance of the Connect application. This allows you to start your document model specification document.
54
+ Run the following command to start the Connect application:
121
55
 
122
56
  ```bash
123
57
  ph connect
@@ -126,36 +60,26 @@ ph connect
126
60
  The Connect application will start and you will see the following output:
127
61
 
128
62
  ```bash
63
+ you@yourmachine:~/Powerhouse/chatroom$ ph run connect
64
+
65
+ > Chatroom@1.0.0 connect
66
+ > connect --config-file ./powerhouse.config.json
67
+
68
+ Watching local document models at '/home/you/Powerhouse/ChatRoom/document-models'...
69
+ Watching local document editors at '/home/you/Powerhouse/ChatRoom/editors'...
129
70
  ➜ Local: http://localhost:3000/
130
- ➜ Network: http://192.168.5.110:3000/
131
71
  ➜ press h + enter to show help
132
72
  ```
133
73
 
134
74
  A new browser window will open and you will see the Connect application. If it doesn't open automatically, you can open it manually by navigating to `http://localhost:3000/` in your browser.
135
75
 
136
- :::tip
137
- If your local drive is not present, navigate to Settings in the bottom left corner. Settings > Danger Zone > Clear Storage.
138
- Clear the storage of your localhost application as it might have an old session cached.
139
- :::
76
+ If you don't have a local drive created yet, create one using the Generic Drive Explorer app.
140
77
 
141
- 4. Move into your local drive.
142
- Create a new document model by clicking the `DocumentModel` button, found in the 'New Document' section at the bottom of the page. Name your document `ChatRoom` (PascalCase, no spaces or hyphens).
78
+ Open your Local Drive and create a new document model by clicking the `DocumentModel` button in the "New Document" section. The GIF below shows where to click.
143
79
 
144
- **Pay close attention to capitalization, as it influences code generation.**
145
80
 
146
81
  ![Create New Document Model](./images/ChatRoomConnectApp.gif)
147
82
 
148
- If you've followed the steps correctly, you'll have an empty `ChatRoom` document where you can define the **'Document Specifications'**.
149
-
150
- ## Verify your setup
151
-
152
- At this point, your project structure should include:
153
-
154
- - Empty `document-models/`, `editors/`, `processors/`, and `subgraphs/` directories
155
- - Configuration files: `powerhouse.config.json`, `powerhouse.manifest.json`
156
- - Package management files: `package.json`, `pnpm-lock.yaml`
157
- - Build configuration: `tsconfig.json`, `vite.config.ts`, `vitest.config.ts`
158
-
159
- ## Up next
83
+ If you followed the steps correctly, you should have an empty document model created called `ChatRoom`.
160
84
 
161
85
  In the next tutorial, you will learn how to design your document model and export it to be later used in your Powerhouse project.
@@ -1,95 +1,54 @@
1
- # Write the document specification
1
+ # Define the chatroom document model
2
2
 
3
- :::tip Tutorial Repository
4
- 📦 **Reference Code**: [chatroom-demo](https://github.com/powerhouse-inc/chatroom-demo)
3
+ In this tutorial, you will learn how to design your document model and export it to be later used in your Powerhouse project.
4
+ If you don't have a document model created yet, have a look at the previous steps of this tutorial to create a new document model.
5
5
 
6
- This tutorial step has a corresponding implementation in the repository. After completing this step, your project will have a document model specification with:
7
- - Document model specification files (`chat-room.json`, `schema.graphql`)
8
- - Auto-generated TypeScript types and action creators
9
- - Reducer scaffolding ready for implementation
10
- :::
11
-
12
- <details>
13
- <summary>📖 How to use this tutorial</summary>
14
-
15
- **Prerequisites**: Complete step 1 and set up the tutorial remote (see previous step).
16
-
17
- ### Compare your generated code
18
-
19
- After running `ph generate ChatRoom.phd`, compare with the reference:
20
-
21
- ```bash
22
- # Compare all generated files with the reference
23
- git diff tutorial/main -- document-models/chat-room/
24
-
25
- # View a specific file from the reference
26
- git show tutorial/main:document-models/chat-room/schema.graphql
27
- ```
28
-
29
- ### Visual comparison with GitHub Desktop
30
-
31
- After making a commit, use GitHub Desktop for visual diff:
32
- 1. **Branch** menu → **"Compare to Branch..."**
33
- 2. Select `tutorial/main`
34
- 3. Review all file differences in the visual interface
35
-
36
- See step 1 for detailed GitHub Desktop instructions.
37
-
38
- </details>
39
-
40
- In this tutorial, you will learn how to define the specifications for a **ChatRoom** document model within the Connect application using its GraphQL schema, and then export the resulting document model specification document for your Powerhouse project.
41
-
42
- If you don't have a document specification file created yet, have a look at the previous step of this tutorial to create a new document specification.
43
-
44
- Before you start, make sure you have the Connect application running locally with the command:
45
-
46
- ```bash
47
- ph connect
48
- ```
6
+ Before you start, make sure you have the Connect application running.
49
7
 
50
- ## ChatRoom document specification
8
+ ## Chatroom document model schema
51
9
 
52
- Make sure you have named your document model `ChatRoom` (PascalCase, no spaces or hyphens).
53
- **Pay close attention to capitalization, as it influences code generation.**
10
+ We use GraphQL Schema Definition Language (SDL) to define the document model schema. Below, you can see the SDL for the `ChatRoom` document model.
54
11
 
55
- We use the **GraphQL Schema Definition Language** (SDL) to define the schema for the document model. Below, you can see the SDL for the `ChatRoom` document model.
56
-
57
- :::info
58
- This schema defines the **data structure** of the document model and the types involved in its operations. Documents in Powerhouse leverage **event sourcing principles**, where every state transition is represented by an operation. GraphQL input types describe operations, ensuring that user intents are captured effectively.
12
+ :::info **The State Schema**
13
+ This schema contains the data structure of the document model and the basic operations that can be performed on the document model. For more in depth information please visit [State Schema](/academy/MasteryTrack/DocumentModelCreation/SpecifyTheStateSchema)
59
14
  :::
60
15
 
61
- <details>
62
- <summary>State schema of our ChatRoom</summary>
16
+ ## State schema (See next steps)
63
17
 
64
18
  ```graphql
19
+ # Defines a GraphQL type for the state of the chatroom document
65
20
  type ChatRoomState {
66
- id: OID!
67
- name: String!
68
- description: String
69
- createdAt: DateTime
70
- createdBy: ID
71
- messages: [Message!]!
21
+ id: OID! # Unique identifier for the chat-room
22
+ name: String! # Name of the chat-room
23
+ description: String # Optional description of the chat-room
24
+ createdAt: DateTime! # Timestamp of when the chat-room was created
25
+ createdBy: ID! # Agent ID of the user who created the chat-room
26
+ messages: [Message!]! # List of messages in the chat-room
72
27
  }
73
28
 
29
+ # Defines a GraphQL type for the state of a message
74
30
  type Message {
75
- id: OID!
76
- sender: Sender!
77
- content: String
78
- sentAt: DateTime!
79
- reactions: [Reaction!]
31
+ id: OID! # Unique identifier for the message
32
+ sender: Sender! # Agent details of the message sender
33
+ content: String # Message content
34
+ sentAt: DateTime! # Timestamp of when the message was sent
35
+ reactions: [Reaction!] # Reactions to the message
80
36
  }
81
37
 
38
+ # Defines a GraphQL type for the state of a sender
82
39
  type Sender {
83
- id: ID!
40
+ id: ID! # Unique identifier for the sender
84
41
  name: String
85
- avatarUrl: URL
42
+ avatarUrl: URL # Allows us to pull the ENS and/or nft of the persons profile
86
43
  }
87
44
 
45
+ # Defines a GraphQL type for the state of a reaction to a message
88
46
  type Reaction {
89
- type: ReactionType!
90
- reactedBy: [ID!]!
47
+ type: ReactionType! # Type of reaction (one of the predefined emoji)
48
+ reactedBy: [ID!]! # Agent ID of the user who reacted
91
49
  }
92
50
 
51
+ # Defines the various predefined emojis to react to a message
93
52
  enum ReactionType {
94
53
  THUMBS_UP
95
54
  THUMBS_DOWN
@@ -99,169 +58,94 @@ enum ReactionType {
99
58
  }
100
59
  ```
101
60
 
102
- </details>
103
-
104
- <details>
105
- <summary>Messages Module: Operations for ChatRoom Messages</summary>
61
+ ## Operations schema (See next steps)
106
62
 
107
63
  ```graphql
108
- # Add a new message to the chat-room
64
+ # add_message
65
+
109
66
  input AddMessageInput {
110
- messageId: OID!
111
- sender: SenderInput!
112
- content: String!
67
+ messageId: OID! # ID of the message that is being added
68
+ sender: SenderInput! # ID of the user sending the message
69
+ content: String! # Content of the message
113
70
  sentAt: DateTime!
114
71
  }
115
72
 
116
- # Sender information for a message
117
73
  input SenderInput {
118
- id: ID!
74
+ id: ID! # Unique identifier for the sender
119
75
  name: String
120
- avatarUrl: URL
76
+ avatarUrl: URL # Allows us to pull the ENS and/or nft of the persons profile
121
77
  }
122
78
 
123
- # Add an emoji reaction to a message
124
79
  input AddEmojiReactionInput {
125
- messageId: OID!
126
- reactedBy: ID!
127
- type: ReactionType!
80
+ messageId: OID! # ID of the message to which the reaction is being added
81
+ reactedBy: ID! # ID of the user adding the reaction
82
+ type: ReactionType! # Type of the reaction (emoji)
128
83
  }
129
84
 
130
- # Remove an emoji reaction from a message
131
85
  input RemoveEmojiReactionInput {
132
- messageId: OID!
133
- senderId: ID!
134
- type: ReactionType!
86
+ messageId: OID! # ID of the message to which the reaction is being removed
87
+ senderId: ID! # ID of the user that is removing the reaction
88
+ type: ReactionType! # Type of the reaction (emoji)
135
89
  }
136
- ```
137
-
138
- </details>
139
90
 
140
- <details>
141
- <summary>Settings Module: Operations for ChatRoom Settings</summary>
142
-
143
- ```graphql
144
- # Edit the chat-room name
145
91
  input EditChatNameInput {
146
92
  name: String
147
93
  }
148
94
 
149
- # Edit the chat-room description
150
95
  input EditChatDescriptionInput {
151
96
  description: String
152
97
  }
153
98
  ```
154
99
 
155
- </details>
156
-
157
- ## Define the document model specification
158
-
159
- To define the document model, you need to open the document model editor in Connect.
100
+ ## Define the document model
160
101
 
161
- ### Steps to define your document model:
102
+ To be able to define the document model, you need to open the Chatroom document model editor in Connect.
162
103
 
163
- 1. In the Connect application, click on **'ChatRoom' Document** to open the document model specification editor.
104
+ The steps below show you how to do this:
164
105
 
165
- 2. You'll be presented with a form to fill in metadata about the document model. Fill in the details in the respective fields.
106
+ 1. In the Connect application, click on the `ChatRoom` document model you've created in the previous step, to open the document model editor.
107
+ 2. You'll be welcomed with a form to fill, this is metadata about the document model, fill in the details in the fields.
166
108
 
167
- In the **Document Type** field, type `powerhouse/chat-room` (lowercase with hyphen). This defines the new type of document that will be created with this document model specification.
109
+ In the `Document Type` field, type `powerhouse/chat-room`. This defines the new type of document that will be created with this document model.
168
110
 
169
111
  ![Chatroom Document Model Form Metadata](image-2.png)
170
112
 
171
- 3. In the code editor, you can see the SDL for the document model. Replace the existing SDL template with the SDL defined in the **State Schema** section above. Only copy and paste the types, leaving the inputs for the next step. You can press the 'Sync with schema' button to set the initial state of your document model based on your Schema Definition Language.
113
+ 3. In the code editor, you can see the SDL for the document model. Replace the existing SDL with the SDL defined in the [State Schema](#state-schema) section above. Only copy and paste the types, leaving the inputs for the next step. You can however already press 'Sync with schema' button to set the initial state of your document model based on your Schema Definition Language. Verify that your Global State Initial Value looks like this.
172
114
 
173
- 4. Verify that your **Global State Initial Value** looks like this:
174
-
175
- ```json
176
- {
177
- "name": "",
178
- "description": null,
179
- "createdAt": null,
180
- "createdBy": null,
181
- "messages": []
182
- }
183
- ```
184
-
185
- 5. Below the editor, find the input field `Add module`. Create the first module for message-related operations. Name the module `messages`. Press enter.
186
-
187
- 6. Now there is a new field, called `Add operation`. Here you will add each input operation to the module, one by one.
188
-
189
- 7. Inside the `Add operation` field, type `ADD_MESSAGE` and press enter. A small editor will appear underneath with an empty input type that you need to fill. Copy the `AddMessageInput` and `SenderInput` from the **Messages Module** section and paste them in the editor:
190
-
191
- ```graphql
192
- input AddMessageInput {
193
- messageId: OID!
194
- sender: SenderInput!
195
- content: String!
196
- sentAt: DateTime!
197
- }
198
-
199
- input SenderInput {
200
- id: ID!
201
- name: String
202
- avatarUrl: URL
203
- }
204
- ```
205
-
206
- 8. Add the remaining message operations to the `messages` module: `ADD_EMOJI_REACTION` and `REMOVE_EMOJI_REACTION`. Note that you only need to add the operation name (e.g., `ADD_EMOJI_REACTION`) without the `Input` suffix—it will be generated automatically.
115
+ ```json
116
+ {
117
+ "id": "",
118
+ "name": "",
119
+ "description": null,
120
+ "createdAt": null,
121
+ "createdBy": null,
122
+ "messages": []
123
+ }
124
+ ```
207
125
 
208
- 9. Add reducer exceptions to the `ADD_MESSAGE` operation for validation: `MessageContentCannotBeEmpty` and `MessageNotFound`. These will be used later to validate messages.
126
+ 4. Below the editor, there is an input field **'Add module'**. You need to create and name a module that the input operations will be added to. In this case, we will name the module **'general_operations'**. Press enter.
127
+ 5. Now there is a new field, called **'Add operation'**. Here you will have to add each input operation to the module, one by one.
128
+ 6. Inside the **'Add operation'** field, type **'ADD_MESSAGE'** and press enter. A small editor will appear under with an empty input type that you have to fill. Copy the first input type from the [Operations Schema](#operations-schema) section and paste it in the editor. The editor should look like this:
209
129
 
210
- 10. Create a second module called `settings` for the chat room configuration operations.
130
+ ```graphql
131
+ input AddMessageInput {
132
+ messageId: OID!
133
+ sender: SenderInput!
134
+ content: String!
135
+ sentAt: DateTime!
136
+ }
211
137
 
212
- 11. Add the settings operations to the `settings` module: `EDIT_CHAT_NAME` and `EDIT_CHAT_DESCRIPTION`.
138
+ input SenderInput {
139
+ id: ID! # Unique identifier for the sender
140
+ name: String
141
+ avatarUrl: URL # Allows us to pull the ENS and/or nft of the persons profile
142
+ }
143
+ ```
213
144
 
214
- 12. Once you have added all the input operations, click the `Export` button at the top right of the editor to save the document model specification to your local machine. Save the file in the root of your Powerhouse project.
145
+ 7. Repeat step 6 for the other input operations based on the [Operations Schema](#operations-schema). If you noticed, you only need to add the name `(ADD_EMOJI_REACTION, EDIT_CHAT_NAME, etc)` of the operation without the `input` suffix. Then it will be generated once you press enter.
146
+ 8. Let's just add a couple more reducer exceptions to the `ADD_MESSAGE` operation which we'll be using later to avoid empty messages or messages exceeding a maximum lenght. Add `MessageContentCannotBeEmpty` and `MessageContentExceedsTheMaximumLenght` to the reducer exceptions of `ADD_MESSAGE`
147
+ 9. Once you have added all the input operations, click on the `Export` button, at the top right of the editor, to save the document model on your local machine. Ideally you already save your file in the root of your powerhouse project on your machine.
215
148
 
216
149
  Check the screenshot below to verify the complete implementation:
217
150
 
218
151
  ![Chatroom Document Model](image-3.png)
219
-
220
- ## Verify your document model generation
221
-
222
- After running `ph generate ChatRoom.phd`, your project should have the following structure in `document-models/chat-room/`:
223
-
224
- ```
225
- document-models/chat-room/
226
- ├── gen/ # Auto-generated code (don't edit)
227
- │ ├── actions.ts
228
- │ ├── creators.ts # Action creator functions
229
- │ ├── types.ts # TypeScript type definitions
230
- │ ├── reducer.ts
231
- │ ├── messages/ # Messages module
232
- │ │ ├── actions.ts
233
- │ │ ├── creators.ts
234
- │ │ ├── error.ts # Error classes for validation
235
- │ │ └── operations.ts
236
- │ └── settings/ # Settings module
237
- │ ├── actions.ts
238
- │ ├── creators.ts
239
- │ ├── error.ts
240
- │ └── operations.ts
241
- ├── src/ # Your custom implementation
242
- │ ├── reducers/
243
- │ │ ├── messages.ts # Message operation reducers
244
- │ │ └── settings.ts # Settings operation reducers
245
- │ └── tests/
246
- │ ├── document-model.test.ts # Document model tests
247
- │ ├── messages.test.ts # Messages operation tests
248
- │ └── settings.test.ts # Settings operation tests
249
- ├── chat-room.json # Document model specification
250
- └── schema.graphql # GraphQL schema
251
- ```
252
-
253
- ### Compare with reference
254
-
255
- Verify your generated files match the expected structure:
256
-
257
- ```bash
258
- # Compare your generated files with the reference
259
- git diff tutorial/main -- document-models/chat-room/
260
-
261
- # List what was generated in the reference
262
- git ls-tree -r --name-only tutorial/main document-models/chat-room/
263
- ```
264
-
265
- ## Up next: Reducers
266
-
267
- In the next step, you'll learn how to implement the runtime logic that will use the `ChatRoom` document model specification you've just created and exported.