@powerhousedao/academy 3.3.0-dev.5 → 3.3.0-dev.6
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.
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
## 3.3.0-dev.6 (2025-07-10)
|
|
2
|
+
|
|
3
|
+
### 🚀 Features
|
|
4
|
+
|
|
5
|
+
- **codegen:** support loading migration typescript file ([d3cc1957b](https://github.com/powerhouse-inc/powerhouse/commit/d3cc1957b))
|
|
6
|
+
|
|
7
|
+
### 🩹 Fixes
|
|
8
|
+
|
|
9
|
+
- **academy:** build ([88681db3d](https://github.com/powerhouse-inc/powerhouse/commit/88681db3d))
|
|
10
|
+
- **codegen,ph-cli:** make schema-file optional and updated generate help text ([adad303a8](https://github.com/powerhouse-inc/powerhouse/commit/adad303a8))
|
|
11
|
+
|
|
12
|
+
### ❤️ Thank You
|
|
13
|
+
|
|
14
|
+
- acaldas
|
|
15
|
+
- Frank
|
|
16
|
+
|
|
1
17
|
## 3.3.0-dev.5 (2025-07-09)
|
|
2
18
|
|
|
3
19
|
This was a version bump only for @powerhousedao/academy to align it with other projects, there were no code changes.
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# Build a Todo-List processor
|
|
2
|
+
|
|
3
|
+
1. Generate the processor
|
|
4
|
+
2. Define your database schema
|
|
5
|
+
3. Customize the processor to your needs
|
|
6
|
+
4. Test your processor
|
|
7
|
+
5. Use the operational store in Frontend and Subgraph
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## Generate the Processor
|
|
11
|
+
|
|
12
|
+
In order to generate the processor you need to run the following command:
|
|
13
|
+
```bash
|
|
14
|
+
ph generate --processor todo-processor --processor-type operational --document-types powerhouse/todolist
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Define your database schema
|
|
18
|
+
|
|
19
|
+
in the migrations.ts file in your processor directory you can find the up and down methods which are being executed when the processor gets installed or removed.
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { type IOperationalStore } from "document-drive/processors/types"
|
|
23
|
+
|
|
24
|
+
export async function up(db: IOperationalStore): Promise<void> {
|
|
25
|
+
// Create table
|
|
26
|
+
await db.schema
|
|
27
|
+
.createTable("todo")
|
|
28
|
+
.addColumn("name", "varchar(255)")
|
|
29
|
+
.addColumn("completed", "boolean")
|
|
30
|
+
.addPrimaryKeyConstraint("todo_pkey", ["name"])
|
|
31
|
+
.ifNotExists()
|
|
32
|
+
.execute();
|
|
33
|
+
|
|
34
|
+
const tables = await db.introspection.getTables();
|
|
35
|
+
console.log(tables);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function down(db: IOperationalStore): Promise<void> {
|
|
39
|
+
// drop table
|
|
40
|
+
await db.schema.dropTable("todo").execute();
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
when you finished defining your database model you can generate the types for typescript from it with the following command:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
ph generate --migration-file processors/todo-indexer/migrations.js --schema-file processors/todo-indexer/schema.ts
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
## Customize the processor
|
|
52
|
+
|
|
53
|
+
the index file contains the processor itsself with the default template:
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import {
|
|
57
|
+
OperationalProcessor,
|
|
58
|
+
type OperationalProcessorFilter,
|
|
59
|
+
} from "document-drive/processors/operational-processor";
|
|
60
|
+
import { type InternalTransmitterUpdate } from "document-drive/server/listener/transmitter/internal";
|
|
61
|
+
import { up } from "./migrations.js";
|
|
62
|
+
import { type DB } from "./schema.js";
|
|
63
|
+
import type { ToDoListDocument } from "../../document-models/to-do-list/index.js";
|
|
64
|
+
|
|
65
|
+
type DocumentType = ToDoListDocument;
|
|
66
|
+
|
|
67
|
+
export class TodoIndexerProcessor extends OperationalProcessor<DB> {
|
|
68
|
+
get filter(): OperationalProcessorFilter {
|
|
69
|
+
return {
|
|
70
|
+
branch: ["main"],
|
|
71
|
+
documentId: ["*"],
|
|
72
|
+
documentType: ["powerhouse/todolist"],
|
|
73
|
+
scope: ["global"],
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async initAndUpgrade(): Promise<void> {
|
|
78
|
+
await up(this.operationalStore);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async onStrands(
|
|
82
|
+
strands: InternalTransmitterUpdate<DocumentType>[],
|
|
83
|
+
): Promise<void> {
|
|
84
|
+
if (strands.length === 0) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
for (const strand of strands) {
|
|
89
|
+
if (strand.operations.length === 0) {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
for (const operation of strand.operations) {
|
|
94
|
+
console.log(">>> ", operation.type);
|
|
95
|
+
await this.operationalStore
|
|
96
|
+
.insertInto("todo")
|
|
97
|
+
.values({
|
|
98
|
+
task: strand.documentId,
|
|
99
|
+
status: true,
|
|
100
|
+
})
|
|
101
|
+
.execute();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async onDisconnect() {}
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
As you can see you can define with the filter options when the processor is executed.
|
|
111
|
+
In this case the processor is called when an operation on a powerhouse/todolist document was processed.
|
|
112
|
+
The operations and the corresponding states will be passed to the onStrands method.
|
|
113
|
+
|
|
114
|
+
Furthermore the Processor contains an initAndUpgrade function which is called when the processor is being activated. Next to the init there is also an onDisconnect function which is called when the processor is beging removed. The template of the operational database processor contains the up method of the migrations.ts file.
|
|
115
|
+
|
|
116
|
+
Finally there is the onStrands method. Here you can update your operational database based upon your needs.
|
|
117
|
+
|
|
118
|
+
## test the processor
|
|
119
|
+
|
|
120
|
+
.... todo
|
|
121
|
+
|
|
122
|
+
## use the operational database
|
|
123
|
+
|
|
124
|
+
### subgraph
|
|
125
|
+
|
|
126
|
+
1. generate subgraph with
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
ph generate --subgraph <subgraph-name>
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
open ```./subgraphs/<subgraph-name>/index.ts```
|
|
133
|
+
|
|
134
|
+
define the following:
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
```
|
|
138
|
+
resolvers = {
|
|
139
|
+
Query: {
|
|
140
|
+
todoList: {
|
|
141
|
+
resolve: async (parent, args, context, info) => {
|
|
142
|
+
const todoList = await this.operationalStore.selectFrom("todo").selectAll().execute();
|
|
143
|
+
return todoList
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
typeDefs = gql`
|
|
150
|
+
type Query {
|
|
151
|
+
type Todo {
|
|
152
|
+
name: String!
|
|
153
|
+
completed: Boolean!
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
todoList: [Todo!]!
|
|
157
|
+
}
|
|
158
|
+
`;
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
you can simply do sql requests with the provided operationalstore in the class for example
|
|
162
|
+
```ts
|
|
163
|
+
await this.operationalStore.selectFrom("todo").selectAll().execute();
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### useOperationalStore Hook
|
|
167
|
+
|
|
168
|
+
.....
|
|
169
|
+
|
|
@@ -378,6 +378,10 @@ Options:
|
|
|
378
378
|
|
|
379
379
|
-d, --drive-editor <name> Generate a drive editor with the specified name.
|
|
380
380
|
|
|
381
|
+
--migration-file <path> Path to the migration file when running 'ph generate
|
|
382
|
+
|
|
383
|
+
--schema-file <path> Path to the output file. Defaults to 'schema.ts' at the same directory of the migration file.
|
|
384
|
+
|
|
381
385
|
Examples:
|
|
382
386
|
$ ph generate # Generate code using defaults
|
|
383
387
|
$ ph generate my-document-model.zip # Generate from a specific model zip file
|
|
@@ -388,6 +392,7 @@ Examples:
|
|
|
388
392
|
$ ph generate --drive-editor custom-drive-explorer # Generate a custom drive editor
|
|
389
393
|
$ ph generate -s MySubgraph # Generate with a specific subgraph
|
|
390
394
|
$ ph generate --skip-format # Generate without formatting
|
|
395
|
+
$ ph generate --migration-file ./migrations.ts # Generate types for an Operational Processor
|
|
391
396
|
```
|
|
392
397
|
|
|
393
398
|
## Inspect
|