@powerhousedao/academy 5.1.0-dev.9 → 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 (75) hide show
  1. package/CHANGELOG.md +43 -1108
  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 +9 -118
  7. package/docs/academy/01-GetStarted/02-DefineToDoListDocumentModel.md +28 -110
  8. package/docs/academy/01-GetStarted/03-ImplementOperationReducers.md +145 -191
  9. package/docs/academy/01-GetStarted/04-BuildToDoListEditor.md +218 -0
  10. package/docs/academy/{02-MasteryTrack/01-BuilderEnvironment → 01-GetStarted}/05-VetraStudio.md +6 -48
  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 +76 -255
  26. package/docs/academy/03-ExampleUsecases/Chatroom/04-ImplementOperationReducers.md +160 -281
  27. package/docs/academy/03-ExampleUsecases/Chatroom/05-ImplementChatroomEditor.md +35 -188
  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 +12 -49
  40. package/src/css/custom.css +18 -26
  41. package/docs/academy/01-GetStarted/04-WriteDocumentModelTests.md +0 -378
  42. package/docs/academy/01-GetStarted/05-BuildToDoListEditor.md +0 -560
  43. package/docs/academy/03-ExampleUsecases/TodoList/00-GetTheStarterCode.md +0 -24
  44. package/docs/academy/03-ExampleUsecases/TodoList/01-GenerateTodoListDocumentModel.md +0 -211
  45. package/docs/academy/03-ExampleUsecases/TodoList/02-ImplementTodoListDocumentModelReducerOperationHandlers.md +0 -171
  46. package/docs/academy/03-ExampleUsecases/TodoList/03-AddTestsForTodoListActions.md +0 -462
  47. package/docs/academy/03-ExampleUsecases/TodoList/04-GenerateTodoListDocumentEditor.md +0 -45
  48. package/docs/academy/03-ExampleUsecases/TodoList/05-ImplementTodoListDocumentEditorUIComponents.md +0 -422
  49. package/docs/academy/03-ExampleUsecases/TodoList/06-GenerateTodoDriveExplorer.md +0 -61
  50. package/docs/academy/03-ExampleUsecases/TodoList/07-AddSharedComponentForShowingTodoListStats.md +0 -384
  51. package/docs/academy/03-ExampleUsecases/TodoList/_category_.json +0 -8
  52. package/docs/academy/03-ExampleUsecases/VetraPackageLibrary/VetraPackageLibrary.md +0 -7
  53. package/docs/academy/03-ExampleUsecases/VetraPackageLibrary/_category_.json +0 -9
  54. package/docs/academy/04-APIReferences/06-VetraRemoteDrive.md +0 -160
  55. package/docs/academy/04-APIReferences/renown-sdk/00-Overview.md +0 -316
  56. package/docs/academy/04-APIReferences/renown-sdk/01-Authentication.md +0 -672
  57. package/docs/academy/04-APIReferences/renown-sdk/02-APIReference.md +0 -957
  58. package/docs/academy/04-APIReferences/renown-sdk/_category_.json +0 -8
  59. package/docs/academy/10-TodoListTutorial/02-ImplementTodoListDocumentModelReducerOperationHandlers.md +0 -171
  60. package/docs/academy/10-TodoListTutorial/03-AddTestsForTodoListActions.md +0 -462
  61. package/docs/academy/10-TodoListTutorial/05-ImplementTodoListDocumentEditorUIComponents.md +0 -422
  62. package/docs/academy/10-TodoListTutorial/07-AddSharedComponentForShowingTodoListStats.md +0 -370
  63. package/static/img/Vetra-logo-dark.svg +0 -11
  64. package/static/img/vetra-logo-light.svg +0 -11
  65. /package/docs/academy/{02-MasteryTrack/01-BuilderEnvironment → 01-GetStarted}/images/Modules.png +0 -0
  66. /package/docs/academy/{02-MasteryTrack/01-BuilderEnvironment → 01-GetStarted}/images/VetraStudioDrive.png +0 -0
  67. /package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/06-DocumentTools/{02-RevisionHistoryTimeline/360/237/232/247" → 02-RevisionHistoryTimeline} +0 -0
  68. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /01-WhatIsADocumentModel" → 01-WhatIsADocumentModel} +0 -0
  69. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /02-DAOandDocumentsModelsQ+A" → 02-DAOandDocumentsModelsQ+A} +0 -0
  70. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /02-domain-modeling" → 02-domain-modeling} +0 -0
  71. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /03-BenefitsOfDocumentModels" → 03-BenefitsOfDocumentModels} +0 -0
  72. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /04-UtilitiesAndTips" → 04-UtilitiesAndTips} +0 -0
  73. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /05-best-practices" → 05-best-practices} +0 -0
  74. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /_category_.json" → _category_.json} +0 -0
  75. /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,100 +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.
6
+ Before you start, make sure you have the Connect application running.
37
7
 
38
- </details>
8
+ ## Chatroom document model schema
39
9
 
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.
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.
41
11
 
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
- ```
49
-
50
- ## ChatRoom document specification
51
-
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.**
54
-
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
65
- # The state of our ChatRoom
19
+ # Defines a GraphQL type for the state of the chatroom document
66
20
  type ChatRoomState {
67
- id: OID! # Unique identifier for the chat-room
68
- name: String! # Name of the chat-room
69
- description: String # Optional description of the chat-room
70
- createdAt: DateTime! # Timestamp of when the chat-room was created
71
- createdBy: ID! # Agent ID of the user who created the chat-room
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
72
26
  messages: [Message!]! # List of messages in the chat-room
73
27
  }
74
28
 
75
- # A single message in the chat-room
29
+ # Defines a GraphQL type for the state of a message
76
30
  type Message {
77
- id: OID! # Unique identifier for the message
78
- sender: Sender! # Agent details of the message sender
79
- content: String # Message content
80
- sentAt: DateTime! # Timestamp of when the message was sent
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
81
35
  reactions: [Reaction!] # Reactions to the message
82
36
  }
83
37
 
84
- # The sender of a message
38
+ # Defines a GraphQL type for the state of a sender
85
39
  type Sender {
86
- id: ID! # Unique identifier for the sender
40
+ id: ID! # Unique identifier for the sender
87
41
  name: String
88
- avatarUrl: URL # Allows us to pull the ENS and/or NFT of the person's profile
42
+ avatarUrl: URL # Allows us to pull the ENS and/or nft of the persons profile
89
43
  }
90
44
 
91
- # A reaction to a message
45
+ # Defines a GraphQL type for the state of a reaction to a message
92
46
  type Reaction {
93
- type: ReactionType! # Type of reaction (one of the predefined emoji)
94
- reactedBy: [ID!]! # Agent IDs of users who reacted
47
+ type: ReactionType! # Type of reaction (one of the predefined emoji)
48
+ reactedBy: [ID!]! # Agent ID of the user who reacted
95
49
  }
96
50
 
97
- # The predefined emoji reactions
51
+ # Defines the various predefined emojis to react to a message
98
52
  enum ReactionType {
99
53
  THUMBS_UP
100
54
  THUMBS_DOWN
@@ -102,72 +56,38 @@ enum ReactionType {
102
56
  HEART
103
57
  CRY
104
58
  }
59
+ ```
105
60
 
106
- type ChatRoomState {
107
- id: OID!
108
- name: String!
109
- description: String
110
- createdAt: DateTime
111
- createdBy: ID
112
- messages: [Message!]!
113
- }
114
-
115
- type Message {
116
- id: OID!
117
- sender: Sender!
118
- content: String
119
- sentAt: DateTime!
120
- reactions: [Reaction!]
121
- }
122
-
123
- type Sender {
124
- id: ID!
125
- name: String
126
- avatarUrl: URL
127
- }
128
-
129
- type Reaction {
130
- type: ReactionType!
131
- reactedBy: [ID!]!
132
- }
133
-
134
- enum ReactionType {
135
- THUMBS_UP
136
- THUMBS_DOWN
137
- LAUGH
138
- HEART
139
- CRY
140
- }
61
+ ## Operations schema (See next steps)
141
62
 
142
- # messages
63
+ ```graphql
64
+ # add_message
143
65
 
144
66
  input AddMessageInput {
145
- messageId: OID!
146
- sender: SenderInput!
147
- 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
148
70
  sentAt: DateTime!
149
71
  }
150
72
 
151
73
  input SenderInput {
152
- id: ID!
74
+ id: ID! # Unique identifier for the sender
153
75
  name: String
154
- avatarUrl: URL
76
+ avatarUrl: URL # Allows us to pull the ENS and/or nft of the persons profile
155
77
  }
156
78
 
157
79
  input AddEmojiReactionInput {
158
- messageId: OID!
159
- reactedBy: ID!
160
- 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)
161
83
  }
162
84
 
163
85
  input RemoveEmojiReactionInput {
164
- messageId: OID!
165
- senderId: ID!
166
- 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)
167
89
  }
168
90
 
169
- # settings
170
-
171
91
  input EditChatNameInput {
172
92
  name: String
173
93
  }
@@ -177,154 +97,55 @@ input EditChatDescriptionInput {
177
97
  }
178
98
  ```
179
99
 
180
- </details>
100
+ ## Define the document model
181
101
 
182
- <details>
183
- <summary>Messages Module: Operations schema of our ChatRoom Messages</summary>
102
+ To be able to define the document model, you need to open the Chatroom document model editor in Connect.
184
103
 
185
- ```graphql
186
- # Add a new message to the chat-room
187
- input AddMessageInput {
188
- messageId: OID! # ID of the message being added
189
- sender: SenderInput! # Sender information
190
- content: String! # Content of the message
191
- sentAt: DateTime! # Timestamp when the message was sent
192
- }
104
+ The steps below show you how to do this:
193
105
 
194
- # Sender information for a message
195
- input SenderInput {
196
- id: ID! # Unique identifier for the sender
197
- name: String
198
- avatarUrl: URL # Avatar URL for the sender
199
- }
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.
200
108
 
201
- # Add an emoji reaction to a message
202
- input AddEmojiReactionInput {
203
- messageId: OID! # ID of the message to react to
204
- reactedBy: ID! # ID of the user adding the reaction
205
- type: ReactionType! # Type of the reaction (emoji)
206
- }
207
-
208
- # Remove an emoji reaction from a message
209
- input RemoveEmojiReactionInput {
210
- messageId: OID! # ID of the message to remove reaction from
211
- senderId: ID! # ID of the user removing the reaction
212
- type: ReactionType! # Type of the reaction (emoji)
213
- }
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.
214
110
 
111
+ ![Chatroom Document Model Form Metadata](image-2.png)
215
112
 
216
- </details>
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.
217
114
 
115
+ ```json
116
+ {
117
+ "id": "",
118
+ "name": "",
119
+ "description": null,
120
+ "createdAt": null,
121
+ "createdBy": null,
122
+ "messages": []
123
+ }
124
+ ```
218
125
 
219
- <details>
220
- <summary>Settings Module: Operations schema of our ChatRoom Settings</summary>
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:
221
129
 
222
- # Edit the chat-room name
223
- input EditChatNameInput {
224
- name: String
130
+ ```graphql
131
+ input AddMessageInput {
132
+ messageId: OID!
133
+ sender: SenderInput!
134
+ content: String!
135
+ sentAt: DateTime!
225
136
  }
226
137
 
227
- # Edit the chat-room description
228
- input EditChatDescriptionInput {
229
- description: String
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
230
142
  }
231
143
  ```
232
144
 
233
- </details>
234
-
235
- ## Define the document model specification
236
-
237
- To define the document model, you need to open the document model editor in Connect.
238
-
239
- ### Steps to define your document model:
240
-
241
- 1. In the Connect application, click on **'ChatRoom' Document** to open the document model specification editor.
242
-
243
- 2. You'll be presented with a form to fill in metadata about the document model. Fill in the details in the respective fields.
244
-
245
- 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.
246
-
247
- ![Chatroom Document Model Form Metadata](image-2.png)
248
-
249
- 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.
250
-
251
- 4. Verify that your **Global State Initial Value** looks like this:
252
-
253
- ```json
254
- {
255
- "name": "",
256
- "description": null,
257
- "createdAt": null,
258
- "createdBy": null,
259
- "messages": []
260
- }
261
- ```
262
-
263
- 5. Below the editor, find the input field `Add module`. Create and name a module for organizing your input operations. Name the module `general_operations`. Press enter.
264
-
265
- 6. Now there is a new field, called `Add operation`. Here you will add each input operation to the module, one by one.
266
-
267
- 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 **Operations Schema** section and paste them in the editor:
268
-
269
- ```graphql
270
- input AddMessageInput {
271
- messageId: OID!
272
- sender: SenderInput!
273
- content: String!
274
- sentAt: DateTime!
275
- }
276
-
277
- input SenderInput {
278
- id: ID!
279
- name: String
280
- avatarUrl: URL
281
- }
282
- ```
283
-
284
- 8. Repeat step 7 for the other input operations: `ADD_EMOJI_REACTION`, `REMOVE_EMOJI_REACTION`, `EDIT_CHAT_NAME`, and `EDIT_CHAT_DESCRIPTION`. Note that you only need to add the operation name (e.g., `ADD_EMOJI_REACTION`) without the `Input` suffix—it will be generated automatically.
285
-
286
- 9. Add reducer exceptions to the `ADD_MESSAGE` operation for validation: `MessageContentCannotBeEmpty` and `MessageContentExceedsTheMaximumLength`. These will be used later to validate messages.
287
-
288
- 10. 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.
289
148
 
290
149
  Check the screenshot below to verify the complete implementation:
291
150
 
292
151
  ![Chatroom Document Model](image-3.png)
293
-
294
- ## Verify your document model generation
295
-
296
- After running `ph generate ChatRoom.phd`, your project should have the following structure in `document-models/chat-room/`:
297
-
298
- ```
299
- document-models/chat-room/
300
- ├── gen/ # Auto-generated code (don't edit)
301
- │ ├── actions.ts
302
- │ ├── creators.ts # Action creator functions
303
- │ ├── types.ts # TypeScript type definitions
304
- │ ├── reducer.ts
305
- │ └── general-operations/
306
- │ └── operations.ts # Operation type definitions
307
- ├── src/ # Your custom implementation
308
- │ ├── reducers/
309
- │ │ └── general-operations.ts # Reducer functions (to implement next)
310
- │ └── tests/
311
- │ └── general-operations.test.ts # Test file scaffolding
312
- ├── chat-room.json # Document model specification
313
- └── schema.graphql # GraphQL schema
314
- ```
315
-
316
- ### Compare with reference
317
-
318
- Verify your generated files match the expected structure:
319
-
320
- ```bash
321
- # Compare your generated files with the reference
322
- git diff tutorial/main -- document-models/chat-room/
323
-
324
- # List what was generated in the reference
325
- git ls-tree -r --name-only tutorial/main document-models/chat-room/
326
- ```
327
-
328
- ## Up next: Reducers
329
-
330
- 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.