@powerhousedao/vetra-builder-package 0.0.17 → 0.0.18
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/dist/document-models/builder-account/gen/document-model.js +1 -1
- package/dist/document-models/builder-account/gen/profile/actions.d.ts +5 -5
- package/dist/document-models/builder-account/gen/profile/creators.d.ts +3 -3
- package/dist/document-models/builder-account/gen/profile/creators.js +1 -1
- package/dist/document-models/builder-account/gen/profile/object.d.ts +2 -2
- package/dist/document-models/builder-account/gen/profile/object.js +3 -3
- package/dist/document-models/builder-account/gen/profile/operations.d.ts +2 -2
- package/dist/document-models/builder-account/gen/reducer.js +3 -3
- package/dist/document-models/builder-account/gen/schema/types.d.ts +1 -1
- package/dist/document-models/builder-account/gen/schema/zod.js +1 -1
- package/dist/document-models/builder-account/index.d.ts +1 -1
- package/dist/document-models/builder-account/src/reducers/profile.js +4 -0
- package/dist/document-models/builder-team/gen/actions.d.ts +9 -0
- package/dist/document-models/builder-team/gen/actions.js +4 -0
- package/dist/document-models/builder-team/gen/creators.d.ts +4 -0
- package/dist/document-models/builder-team/gen/creators.js +4 -0
- package/dist/document-models/builder-team/gen/document-model.d.ts +2 -0
- package/dist/document-models/builder-team/gen/document-model.js +212 -0
- package/dist/document-models/builder-team/gen/index.d.ts +7 -0
- package/dist/document-models/builder-team/gen/index.js +6 -0
- package/dist/document-models/builder-team/gen/member/actions.d.ts +15 -0
- package/dist/document-models/builder-team/gen/member/actions.js +1 -0
- package/dist/document-models/builder-team/gen/member/creators.d.ts +5 -0
- package/dist/document-models/builder-team/gen/member/creators.js +5 -0
- package/dist/document-models/builder-team/gen/member/error.d.ts +1 -0
- package/dist/document-models/builder-team/gen/member/error.js +1 -0
- package/dist/document-models/builder-team/gen/member/object.d.ts +8 -0
- package/dist/document-models/builder-team/gen/member/object.js +13 -0
- package/dist/document-models/builder-team/gen/member/operations.d.ts +8 -0
- package/dist/document-models/builder-team/gen/member/operations.js +1 -0
- package/dist/document-models/builder-team/gen/object.d.ts +20 -0
- package/dist/document-models/builder-team/gen/object.js +36 -0
- package/dist/document-models/builder-team/gen/packages/actions.d.ts +15 -0
- package/dist/document-models/builder-team/gen/packages/actions.js +1 -0
- package/dist/document-models/builder-team/gen/packages/creators.d.ts +5 -0
- package/dist/document-models/builder-team/gen/packages/creators.js +5 -0
- package/dist/document-models/builder-team/gen/packages/error.d.ts +1 -0
- package/dist/document-models/builder-team/gen/packages/error.js +1 -0
- package/dist/document-models/builder-team/gen/packages/object.d.ts +8 -0
- package/dist/document-models/builder-team/gen/packages/object.js +13 -0
- package/dist/document-models/builder-team/gen/packages/operations.d.ts +8 -0
- package/dist/document-models/builder-team/gen/packages/operations.js +1 -0
- package/dist/document-models/builder-team/gen/ph-factories.d.ts +26 -0
- package/dist/document-models/builder-team/gen/ph-factories.js +62 -0
- package/dist/document-models/builder-team/gen/profile/actions.d.ts +23 -0
- package/dist/document-models/builder-team/gen/profile/actions.js +1 -0
- package/dist/document-models/builder-team/gen/profile/creators.d.ts +7 -0
- package/dist/document-models/builder-team/gen/profile/creators.js +7 -0
- package/dist/document-models/builder-team/gen/profile/error.d.ts +1 -0
- package/dist/document-models/builder-team/gen/profile/error.js +1 -0
- package/dist/document-models/builder-team/gen/profile/object.d.ts +10 -0
- package/dist/document-models/builder-team/gen/profile/object.js +19 -0
- package/dist/document-models/builder-team/gen/profile/operations.d.ts +10 -0
- package/dist/document-models/builder-team/gen/profile/operations.js +1 -0
- package/dist/document-models/builder-team/gen/reducer.d.ts +4 -0
- package/dist/document-models/builder-team/gen/reducer.js +75 -0
- package/dist/document-models/builder-team/gen/schema/index.d.ts +2 -0
- package/dist/document-models/builder-team/gen/schema/index.js +2 -0
- package/dist/document-models/builder-team/gen/schema/types.d.ts +247 -0
- package/dist/document-models/builder-team/gen/schema/types.js +1 -0
- package/dist/document-models/builder-team/gen/schema/zod.d.ts +29 -0
- package/dist/document-models/builder-team/gen/schema/zod.js +148 -0
- package/dist/document-models/builder-team/gen/spaces/actions.d.ts +15 -0
- package/dist/document-models/builder-team/gen/spaces/actions.js +1 -0
- package/dist/document-models/builder-team/gen/spaces/creators.d.ts +5 -0
- package/dist/document-models/builder-team/gen/spaces/creators.js +5 -0
- package/dist/document-models/builder-team/gen/spaces/error.d.ts +1 -0
- package/dist/document-models/builder-team/gen/spaces/error.js +1 -0
- package/dist/document-models/builder-team/gen/spaces/object.d.ts +8 -0
- package/dist/document-models/builder-team/gen/spaces/object.js +13 -0
- package/dist/document-models/builder-team/gen/spaces/operations.d.ts +8 -0
- package/dist/document-models/builder-team/gen/spaces/operations.js +1 -0
- package/dist/document-models/builder-team/gen/types.d.ts +9 -0
- package/dist/document-models/builder-team/gen/types.js +1 -0
- package/dist/document-models/builder-team/gen/utils.d.ts +21 -0
- package/dist/document-models/builder-team/gen/utils.js +54 -0
- package/dist/document-models/builder-team/index.d.ts +37 -0
- package/dist/document-models/builder-team/index.js +21 -0
- package/dist/document-models/builder-team/src/reducers/member.d.ts +2 -0
- package/dist/document-models/builder-team/src/reducers/member.js +30 -0
- package/dist/document-models/builder-team/src/reducers/packages.d.ts +2 -0
- package/dist/document-models/builder-team/src/reducers/packages.js +40 -0
- package/dist/document-models/builder-team/src/reducers/profile.d.ts +2 -0
- package/dist/document-models/builder-team/src/reducers/profile.js +26 -0
- package/dist/document-models/builder-team/src/reducers/spaces.d.ts +2 -0
- package/dist/document-models/builder-team/src/reducers/spaces.js +34 -0
- package/dist/document-models/builder-team/src/tests/document-model.test.d.ts +5 -0
- package/dist/document-models/builder-team/src/tests/document-model.test.js +18 -0
- package/dist/document-models/builder-team/src/tests/member.test.d.ts +5 -0
- package/dist/document-models/builder-team/src/tests/member.test.js +40 -0
- package/dist/document-models/builder-team/src/tests/packages.test.d.ts +5 -0
- package/dist/document-models/builder-team/src/tests/packages.test.js +40 -0
- package/dist/document-models/builder-team/src/tests/profile.test.d.ts +5 -0
- package/dist/document-models/builder-team/src/tests/profile.test.js +56 -0
- package/dist/document-models/builder-team/src/tests/spaces.test.d.ts +5 -0
- package/dist/document-models/builder-team/src/tests/spaces.test.js +40 -0
- package/dist/document-models/builder-team/src/utils.d.ts +1 -0
- package/dist/document-models/builder-team/src/utils.js +1 -0
- package/dist/document-models/index.d.ts +1 -1
- package/dist/document-models/index.js +1 -1
- package/dist/editors/builder-team-editor/components/Header.d.ts +8 -0
- package/dist/editors/builder-team-editor/components/Header.js +5 -0
- package/dist/editors/builder-team-editor/components/MembersSection.d.ts +14 -0
- package/dist/editors/builder-team-editor/components/MembersSection.js +152 -0
- package/dist/editors/builder-team-editor/components/PackageForm.d.ts +8 -0
- package/dist/editors/builder-team-editor/components/PackageForm.js +92 -0
- package/dist/editors/builder-team-editor/components/PackageItem.d.ts +11 -0
- package/dist/editors/builder-team-editor/components/PackageItem.js +99 -0
- package/dist/editors/builder-team-editor/components/ProfileSection.d.ts +17 -0
- package/dist/editors/builder-team-editor/components/ProfileSection.js +5 -0
- package/dist/editors/builder-team-editor/components/QuickStats.d.ts +7 -0
- package/dist/editors/builder-team-editor/components/QuickStats.js +5 -0
- package/dist/editors/builder-team-editor/components/SpaceForm.d.ts +9 -0
- package/dist/editors/builder-team-editor/components/SpaceForm.js +11 -0
- package/dist/editors/builder-team-editor/components/SpaceItem.d.ts +21 -0
- package/dist/editors/builder-team-editor/components/SpaceItem.js +12 -0
- package/dist/editors/builder-team-editor/components/SpacesSection.d.ts +22 -0
- package/dist/editors/builder-team-editor/components/SpacesSection.js +14 -0
- package/dist/editors/builder-team-editor/config.d.ts +6 -0
- package/dist/editors/builder-team-editor/config.js +11 -0
- package/dist/editors/builder-team-editor/editor.d.ts +3 -0
- package/dist/editors/builder-team-editor/editor.js +73 -0
- package/dist/editors/builder-team-editor/hooks/useMemberHandlers.d.ts +12 -0
- package/dist/editors/builder-team-editor/hooks/useMemberHandlers.js +27 -0
- package/dist/editors/builder-team-editor/hooks/usePackageHandlers.d.ts +11 -0
- package/dist/editors/builder-team-editor/hooks/usePackageHandlers.js +49 -0
- package/dist/editors/builder-team-editor/hooks/useProfileHandlers.d.ts +14 -0
- package/dist/editors/builder-team-editor/hooks/useProfileHandlers.js +38 -0
- package/dist/editors/builder-team-editor/hooks/useSpaceHandlers.d.ts +15 -0
- package/dist/editors/builder-team-editor/hooks/useSpaceHandlers.js +82 -0
- package/dist/editors/builder-team-editor/index.d.ts +2 -0
- package/dist/editors/builder-team-editor/index.js +11 -0
- package/dist/editors/hooks/useBuilderTeamDocument.d.ts +3 -0
- package/dist/editors/hooks/useBuilderTeamDocument.js +8 -0
- package/dist/editors/index.d.ts +1 -1
- package/dist/editors/index.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/powerhouse.manifest.json +21 -6
- package/dist/processors/factory.d.ts +0 -4
- package/dist/processors/factory.js +3 -3
- package/dist/processors/index.d.ts +2 -2
- package/dist/processors/index.js +2 -2
- package/dist/processors/old_vetra-builder-relational-db-processor/factory.d.ts +3 -0
- package/dist/processors/old_vetra-builder-relational-db-processor/factory.js +22 -0
- package/dist/processors/old_vetra-builder-relational-db-processor/index.d.ts +9 -0
- package/dist/processors/old_vetra-builder-relational-db-processor/index.js +32 -0
- package/dist/processors/old_vetra-builder-relational-db-processor/migrations.d.ts +3 -0
- package/dist/processors/old_vetra-builder-relational-db-processor/migrations.js +14 -0
- package/dist/processors/old_vetra-builder-relational-db-processor/schema.d.ts +7 -0
- package/dist/processors/old_vetra-builder-relational-db-processor/schema.js +1 -0
- package/dist/processors/vetra-builder-relational-db-processor/builder-team-handlers.d.ts +22 -0
- package/dist/processors/vetra-builder-relational-db-processor/builder-team-handlers.js +261 -0
- package/dist/processors/vetra-builder-relational-db-processor/database-helpers.d.ts +39 -0
- package/dist/processors/vetra-builder-relational-db-processor/database-helpers.js +144 -0
- package/dist/processors/vetra-builder-relational-db-processor/factory.d.ts +3 -0
- package/dist/processors/vetra-builder-relational-db-processor/factory.js +23 -0
- package/dist/processors/vetra-builder-relational-db-processor/index.d.ts +13 -0
- package/dist/processors/vetra-builder-relational-db-processor/index.js +53 -0
- package/dist/processors/vetra-builder-relational-db-processor/migrations.d.ts +3 -0
- package/dist/processors/vetra-builder-relational-db-processor/migrations.js +155 -0
- package/dist/processors/vetra-builder-relational-db-processor/schema.d.ts +66 -0
- package/dist/processors/vetra-builder-relational-db-processor/schema.js +1 -0
- package/dist/processors/vetra-builder-relational-db-processor/types.d.ts +32 -0
- package/dist/processors/vetra-builder-relational-db-processor/types.js +1 -0
- package/dist/style.css +36 -28
- package/dist/subgraphs/builder-account/resolvers.js +3 -3
- package/dist/subgraphs/builder-account/schema.js +4 -4
- package/dist/subgraphs/builder-team/index.d.ts +10 -0
- package/dist/subgraphs/builder-team/index.js +11 -0
- package/dist/subgraphs/builder-team/resolvers.d.ts +2 -0
- package/dist/subgraphs/builder-team/resolvers.js +240 -0
- package/dist/subgraphs/builder-team/schema.d.ts +2 -0
- package/dist/subgraphs/builder-team/schema.js +228 -0
- package/dist/subgraphs/index.d.ts +2 -2
- package/dist/subgraphs/index.js +3 -2
- package/dist/subgraphs/vetra-builders/index.d.ts +10 -0
- package/dist/subgraphs/vetra-builders/index.js +11 -0
- package/dist/subgraphs/vetra-builders/resolvers.d.ts +2 -0
- package/dist/subgraphs/vetra-builders/resolvers.js +144 -0
- package/dist/subgraphs/vetra-builders/schema.d.ts +2 -0
- package/dist/subgraphs/vetra-builders/schema.js +79 -0
- package/dist/subgraphs/vetra-builders-bkp/index.d.ts +10 -0
- package/dist/subgraphs/vetra-builders-bkp/index.js +11 -0
- package/dist/subgraphs/vetra-builders-bkp/resolvers.d.ts +2 -0
- package/dist/subgraphs/vetra-builders-bkp/resolvers.js +10 -0
- package/dist/subgraphs/vetra-builders-bkp/schema.d.ts +2 -0
- package/dist/subgraphs/vetra-builders-bkp/schema.js +9 -0
- package/dist/utils/nano-id.d.ts +1 -0
- package/dist/utils/nano-id.js +4 -0
- package/package.json +4 -2
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { RelationalDbProcessor } from "document-drive/processors/relational";
|
|
2
|
+
import { up } from "./migrations.js";
|
|
3
|
+
export class VetraBuilderRelationalDbProcessorProcessor extends RelationalDbProcessor {
|
|
4
|
+
static getNamespace(driveId) {
|
|
5
|
+
// Default namespace: `${this.name}_${driveId.replaceAll("-", "_")}`
|
|
6
|
+
return super.getNamespace(driveId);
|
|
7
|
+
}
|
|
8
|
+
async initAndUpgrade() {
|
|
9
|
+
await up(this.relationalDb);
|
|
10
|
+
}
|
|
11
|
+
async onStrands(strands) {
|
|
12
|
+
if (strands.length === 0) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
for (const strand of strands) {
|
|
16
|
+
if (strand.operations.length === 0) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
for (const operation of strand.operations) {
|
|
20
|
+
await this.relationalDb
|
|
21
|
+
.insertInto("todo")
|
|
22
|
+
.values({
|
|
23
|
+
task: `${strand.documentId}-${operation.index}: ${operation.action.type}`,
|
|
24
|
+
status: true,
|
|
25
|
+
})
|
|
26
|
+
.onConflict((oc) => oc.column("task").doNothing())
|
|
27
|
+
.execute();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async onDisconnect() { }
|
|
32
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export async function up(db) {
|
|
2
|
+
// Create table
|
|
3
|
+
await db.schema
|
|
4
|
+
.createTable("todo")
|
|
5
|
+
.addColumn("task", "varchar(255)")
|
|
6
|
+
.addColumn("status", "boolean")
|
|
7
|
+
.addPrimaryKeyConstraint("todo_pkey", ["task"])
|
|
8
|
+
.ifNotExists()
|
|
9
|
+
.execute();
|
|
10
|
+
}
|
|
11
|
+
export async function down(db) {
|
|
12
|
+
// drop table
|
|
13
|
+
await db.schema.dropTable("todo").execute();
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { DB } from "./schema.js";
|
|
2
|
+
import type { IRelationalDb } from "document-drive";
|
|
3
|
+
import { type BuilderTeamState, type BuilderTeamAction } from "document-models/builder-team/index.js";
|
|
4
|
+
export declare class BuilderTeamHandlers {
|
|
5
|
+
private db;
|
|
6
|
+
private dbHelpers;
|
|
7
|
+
constructor(db: IRelationalDb<DB>);
|
|
8
|
+
handleBuilderTeamOperation(documentId: string, action: BuilderTeamAction, state: BuilderTeamState, driveId?: string): Promise<void>;
|
|
9
|
+
private handleSetLogo;
|
|
10
|
+
private handleSetProfileName;
|
|
11
|
+
private handleSetSlug;
|
|
12
|
+
private handleSetProfileDescription;
|
|
13
|
+
private handleUpdateSocials;
|
|
14
|
+
private handleAddMember;
|
|
15
|
+
private handleRemoveMember;
|
|
16
|
+
private handleAddSpace;
|
|
17
|
+
private handleDeleteSpace;
|
|
18
|
+
private handleUpdateSpaceInfo;
|
|
19
|
+
private handleAddPackage;
|
|
20
|
+
private handleUpdatePackageInfo;
|
|
21
|
+
private handleDeletePackage;
|
|
22
|
+
}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { DatabaseHelpers } from "./database-helpers.js";
|
|
2
|
+
export class BuilderTeamHandlers {
|
|
3
|
+
db;
|
|
4
|
+
dbHelpers;
|
|
5
|
+
constructor(db) {
|
|
6
|
+
this.db = db;
|
|
7
|
+
this.dbHelpers = new DatabaseHelpers(db);
|
|
8
|
+
}
|
|
9
|
+
async handleBuilderTeamOperation(documentId, action, state, driveId) {
|
|
10
|
+
switch (action.type) {
|
|
11
|
+
// Profile operations
|
|
12
|
+
case "SET_LOGO":
|
|
13
|
+
await this.handleSetLogo(documentId, action, state);
|
|
14
|
+
break;
|
|
15
|
+
case "SET_TEAM_NAME":
|
|
16
|
+
await this.handleSetProfileName(documentId, action, state);
|
|
17
|
+
break;
|
|
18
|
+
case "SET_SLUG":
|
|
19
|
+
await this.handleSetSlug(documentId, action, state);
|
|
20
|
+
break;
|
|
21
|
+
case "SET_DESCRIPTION":
|
|
22
|
+
await this.handleSetProfileDescription(documentId, action, state);
|
|
23
|
+
break;
|
|
24
|
+
case "SET_SOCIALS":
|
|
25
|
+
await this.handleUpdateSocials(documentId, action, state);
|
|
26
|
+
break;
|
|
27
|
+
// Members operations
|
|
28
|
+
case "ADD_MEMBER":
|
|
29
|
+
await this.handleAddMember(documentId, action, state);
|
|
30
|
+
break;
|
|
31
|
+
case "REMOVE_MEMBER":
|
|
32
|
+
await this.handleRemoveMember(documentId, action, state);
|
|
33
|
+
break;
|
|
34
|
+
// Spaces operations
|
|
35
|
+
case "ADD_SPACE":
|
|
36
|
+
await this.handleAddSpace(documentId, action, state);
|
|
37
|
+
break;
|
|
38
|
+
case "REMOVE_SPACE":
|
|
39
|
+
await this.handleDeleteSpace(documentId, action, state);
|
|
40
|
+
break;
|
|
41
|
+
case "UPDATE_SPACE_INFO":
|
|
42
|
+
await this.handleUpdateSpaceInfo(documentId, action, state);
|
|
43
|
+
break;
|
|
44
|
+
// case "REORDER_SPACES":
|
|
45
|
+
// await this.handleReorderSpaces(documentId, action, state);
|
|
46
|
+
// break;
|
|
47
|
+
// Packages operations
|
|
48
|
+
case "ADD_PACKAGE":
|
|
49
|
+
await this.handleAddPackage(documentId, action, state);
|
|
50
|
+
break;
|
|
51
|
+
case "REMOVE_PACKAGE":
|
|
52
|
+
await this.handleDeletePackage(documentId, action, state);
|
|
53
|
+
break;
|
|
54
|
+
case "UPDATE_PACKAGE_INFO":
|
|
55
|
+
await this.handleUpdatePackageInfo(documentId, action, state);
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Profile operations
|
|
60
|
+
async handleSetLogo(documentId, action, state) {
|
|
61
|
+
await this.dbHelpers.ensureBuilderAccountExistsAndIsNotdeleted(documentId);
|
|
62
|
+
await this.dbHelpers.updateBuilderAccount(documentId, {
|
|
63
|
+
profile_logo: action.input.logo,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
async handleSetProfileName(documentId, action, state) {
|
|
67
|
+
await this.dbHelpers.ensureBuilderAccountExistsAndIsNotdeleted(documentId);
|
|
68
|
+
await this.dbHelpers.updateBuilderAccount(documentId, {
|
|
69
|
+
profile_name: action.input.name,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
async handleSetSlug(documentId, action, state) {
|
|
73
|
+
await this.dbHelpers.ensureBuilderAccountExistsAndIsNotdeleted(documentId);
|
|
74
|
+
await this.dbHelpers.updateBuilderAccount(documentId, {
|
|
75
|
+
profile_slug: action.input.slug,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
async handleSetProfileDescription(documentId, action, state) {
|
|
79
|
+
await this.dbHelpers.ensureBuilderAccountExistsAndIsNotdeleted(documentId);
|
|
80
|
+
await this.dbHelpers.updateBuilderAccount(documentId, {
|
|
81
|
+
profile_description: action.input.description,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
async handleUpdateSocials(documentId, action, state) {
|
|
85
|
+
await this.dbHelpers.ensureBuilderAccountExistsAndIsNotdeleted(documentId);
|
|
86
|
+
await this.dbHelpers.updateBuilderAccount(documentId, {
|
|
87
|
+
profile_socials_x: action.input.xProfile,
|
|
88
|
+
profile_socials_github: action.input.github,
|
|
89
|
+
profile_socials_website: action.input.website,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
// Members operations
|
|
93
|
+
async handleAddMember(documentId, action, state) {
|
|
94
|
+
await this.dbHelpers.ensureBuilderAccountExistsAndIsNotdeleted(documentId);
|
|
95
|
+
if (!action.input.id)
|
|
96
|
+
return;
|
|
97
|
+
const memberExists = await this.dbHelpers.memberExists(documentId, action.input.id);
|
|
98
|
+
if (!memberExists) {
|
|
99
|
+
await this.db
|
|
100
|
+
.insertInto("builder_team_members")
|
|
101
|
+
.values({
|
|
102
|
+
id: action.input.id,
|
|
103
|
+
builder_team_id: documentId,
|
|
104
|
+
eth_address: "",
|
|
105
|
+
created_at: new Date(),
|
|
106
|
+
})
|
|
107
|
+
.execute();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async handleRemoveMember(documentId, action, state) {
|
|
111
|
+
if (!action.input.id)
|
|
112
|
+
return;
|
|
113
|
+
await this.db
|
|
114
|
+
.deleteFrom("builder_team_members")
|
|
115
|
+
.where("builder_team_id", "=", documentId)
|
|
116
|
+
.where("eth_address", "=", action.input.id)
|
|
117
|
+
.execute();
|
|
118
|
+
}
|
|
119
|
+
// Spaces operations
|
|
120
|
+
async handleAddSpace(documentId, action, state) {
|
|
121
|
+
await this.dbHelpers.ensureBuilderAccountExistsAndIsNotdeleted(documentId);
|
|
122
|
+
await this.db
|
|
123
|
+
.insertInto("builder_team_spaces")
|
|
124
|
+
.values({
|
|
125
|
+
id: action.input.id,
|
|
126
|
+
builder_team_id: documentId,
|
|
127
|
+
title: "",
|
|
128
|
+
description: "",
|
|
129
|
+
sort_order: 0,
|
|
130
|
+
created_at: new Date(),
|
|
131
|
+
updated_at: new Date(),
|
|
132
|
+
})
|
|
133
|
+
.onConflict((oc) => oc.column("id").doNothing())
|
|
134
|
+
.execute();
|
|
135
|
+
}
|
|
136
|
+
async handleDeleteSpace(documentId, action, state) {
|
|
137
|
+
await this.db
|
|
138
|
+
.deleteFrom("builder_team_spaces")
|
|
139
|
+
.where("id", "=", action.input.id)
|
|
140
|
+
.where("builder_team_id", "=", documentId)
|
|
141
|
+
.execute();
|
|
142
|
+
}
|
|
143
|
+
async handleUpdateSpaceInfo(documentId, action, state) {
|
|
144
|
+
const updates = {};
|
|
145
|
+
// Only include fields that are provided
|
|
146
|
+
if (action.input.title !== undefined) {
|
|
147
|
+
updates.title = action.input.title;
|
|
148
|
+
}
|
|
149
|
+
if (action.input.description !== undefined) {
|
|
150
|
+
updates.description = action.input.description;
|
|
151
|
+
}
|
|
152
|
+
// Only update if there are actual changes
|
|
153
|
+
if (Object.keys(updates).length > 0) {
|
|
154
|
+
await this.dbHelpers.updateBuilderSpace(action.input.id, documentId, updates);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
// private async handleReorderSpaces(
|
|
158
|
+
// documentId: string,
|
|
159
|
+
// action: ReorderSpacesAction,
|
|
160
|
+
// state: BuilderAccountState
|
|
161
|
+
// ): Promise<void> {
|
|
162
|
+
// const { ids, insertAfter } = action.input;
|
|
163
|
+
// for (let i = 0; i < ids.length; i++) {
|
|
164
|
+
// const spaceId = ids[i];
|
|
165
|
+
// const sortOrder = insertAfter !== null ? Number(insertAfter) + i + 1 : i;
|
|
166
|
+
// await this.dbHelpers.updateBuilderSpace(spaceId, documentId, {
|
|
167
|
+
// sort_order: sortOrder,
|
|
168
|
+
// });
|
|
169
|
+
// }
|
|
170
|
+
// }
|
|
171
|
+
// Packages operations
|
|
172
|
+
async handleAddPackage(documentId, action, state) {
|
|
173
|
+
await this.db
|
|
174
|
+
.insertInto("builder_team_packages")
|
|
175
|
+
.values({
|
|
176
|
+
id: `${action.input.id}`,
|
|
177
|
+
space_id: action.input.spaceId,
|
|
178
|
+
title: "",
|
|
179
|
+
description: "",
|
|
180
|
+
category: "",
|
|
181
|
+
author_name: "",
|
|
182
|
+
author_website: "",
|
|
183
|
+
github_url: "",
|
|
184
|
+
npm_url: "",
|
|
185
|
+
vetra_drive_url: "",
|
|
186
|
+
drive_id: "",
|
|
187
|
+
sort_order: 0,
|
|
188
|
+
created_at: new Date(),
|
|
189
|
+
updated_at: new Date(),
|
|
190
|
+
})
|
|
191
|
+
.onConflict((oc) => oc.column("id").doNothing())
|
|
192
|
+
.execute();
|
|
193
|
+
// // Add keywords if provided
|
|
194
|
+
// if (action.input.keywords && action.input.keywords.length > 0) {
|
|
195
|
+
// for (const keyword of action.input.keywords) {
|
|
196
|
+
// await this.db
|
|
197
|
+
// .insertInto("builder_package_keywords")
|
|
198
|
+
// .values({
|
|
199
|
+
// id: `${packageId}-${keyword}`,
|
|
200
|
+
// package_id: packageId,
|
|
201
|
+
// label: keyword,
|
|
202
|
+
// created_at: new Date(),
|
|
203
|
+
// })
|
|
204
|
+
// .execute();
|
|
205
|
+
// }
|
|
206
|
+
// }
|
|
207
|
+
}
|
|
208
|
+
async handleUpdatePackageInfo(documentId, action, state) {
|
|
209
|
+
const updates = {};
|
|
210
|
+
// Map input fields to database columns, only include provided fields
|
|
211
|
+
if (action.input.title !== undefined) {
|
|
212
|
+
updates.title = action.input.title;
|
|
213
|
+
}
|
|
214
|
+
if (action.input.description !== undefined) {
|
|
215
|
+
updates.description = action.input.description;
|
|
216
|
+
}
|
|
217
|
+
if (action.input.github !== undefined) {
|
|
218
|
+
updates.github_url = action.input.github;
|
|
219
|
+
}
|
|
220
|
+
if (action.input.npm !== undefined) {
|
|
221
|
+
updates.npm_url = action.input.npm;
|
|
222
|
+
}
|
|
223
|
+
if (action.input.vetraDriveUrl !== undefined) {
|
|
224
|
+
updates.vetra_drive_url = action.input.vetraDriveUrl;
|
|
225
|
+
}
|
|
226
|
+
if (action.input.spaceId !== undefined) {
|
|
227
|
+
updates.space_id = action.input.spaceId;
|
|
228
|
+
}
|
|
229
|
+
// Note: phid is not stored in the packages table, and id is the WHERE condition
|
|
230
|
+
// Only update if there are actual changes
|
|
231
|
+
if (Object.keys(updates).length > 0) {
|
|
232
|
+
await this.dbHelpers.updateBuilderPackage(action.input.id, updates);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
// private async handleReorderPackages(
|
|
236
|
+
// documentId: string,
|
|
237
|
+
// action: ReorderPackagesAction,
|
|
238
|
+
// state: BuilderAccountState
|
|
239
|
+
// ): Promise<void> {
|
|
240
|
+
// const { ids, insertAfter, spaceId } = action.input;
|
|
241
|
+
// for (let i = 0; i < ids.length; i++) {
|
|
242
|
+
// const packageId = ids[i];
|
|
243
|
+
// const sortOrder = insertAfter !== null ? Number(insertAfter) + i + 1 : i;
|
|
244
|
+
// await this.db
|
|
245
|
+
// .updateTable("builder_packages")
|
|
246
|
+
// .set({
|
|
247
|
+
// sort_order: sortOrder,
|
|
248
|
+
// updated_at: new Date(),
|
|
249
|
+
// })
|
|
250
|
+
// .where("id", "=", packageId)
|
|
251
|
+
// .where("space_id", "=", spaceId)
|
|
252
|
+
// .execute();
|
|
253
|
+
// }
|
|
254
|
+
// }
|
|
255
|
+
async handleDeletePackage(documentId, action, state) {
|
|
256
|
+
await this.db
|
|
257
|
+
.deleteFrom("builder_team_packages")
|
|
258
|
+
.where("id", "=", action.input.id)
|
|
259
|
+
.execute();
|
|
260
|
+
}
|
|
261
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { IRelationalDb } from "document-drive";
|
|
2
|
+
import type { DB } from "./schema.js";
|
|
3
|
+
export declare class DatabaseHelpers {
|
|
4
|
+
private db;
|
|
5
|
+
constructor(db: IRelationalDb<DB>);
|
|
6
|
+
/**
|
|
7
|
+
* Ensures a package exists in the database, creating it if it doesn't
|
|
8
|
+
*/
|
|
9
|
+
ensurePackageExists(documentId: string, driveId: string): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Check if a document ID is marked as deleted
|
|
12
|
+
*/
|
|
13
|
+
private isDocumentDeleted;
|
|
14
|
+
/**
|
|
15
|
+
* Ensures a builder account exists in the database, creating it if it doesn't
|
|
16
|
+
* Throws an error if the document was previously deleted
|
|
17
|
+
*/
|
|
18
|
+
ensureBuilderAccountExistsAndIsNotdeleted(documentId: string): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Updates a package with the provided data
|
|
21
|
+
*/
|
|
22
|
+
updatePackage(documentId: string, updates: Record<string, any>): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Updates a builder account with the provided data
|
|
25
|
+
*/
|
|
26
|
+
updateBuilderAccount(documentId: string, updates: Record<string, any>): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Updates a builder space with the provided data
|
|
29
|
+
*/
|
|
30
|
+
updateBuilderSpace(spaceId: string, documentId: string, updates: Record<string, any>): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Updates a builder package with the provided data
|
|
33
|
+
*/
|
|
34
|
+
updateBuilderPackage(packageId: string, updates: Record<string, any>): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Checks if a member already exists for a builder account
|
|
37
|
+
*/
|
|
38
|
+
memberExists(documentId: string, ethAddress: string): Promise<boolean>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
export class DatabaseHelpers {
|
|
2
|
+
db;
|
|
3
|
+
constructor(db) {
|
|
4
|
+
this.db = db;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Ensures a package exists in the database, creating it if it doesn't
|
|
8
|
+
*/
|
|
9
|
+
async ensurePackageExists(documentId, driveId) {
|
|
10
|
+
const existing = await this.db
|
|
11
|
+
.selectFrom("builder_team_packages")
|
|
12
|
+
.select("id")
|
|
13
|
+
.where("id", "=", documentId)
|
|
14
|
+
.executeTakeFirst();
|
|
15
|
+
if (!existing) {
|
|
16
|
+
await this.db
|
|
17
|
+
.insertInto("builder_team_packages")
|
|
18
|
+
.values({
|
|
19
|
+
id: documentId,
|
|
20
|
+
drive_id: driveId,
|
|
21
|
+
author_name: "",
|
|
22
|
+
title: "",
|
|
23
|
+
space_id: "",
|
|
24
|
+
})
|
|
25
|
+
.execute();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Check if a document ID is marked as deleted
|
|
30
|
+
*/
|
|
31
|
+
async isDocumentDeleted(documentId) {
|
|
32
|
+
try {
|
|
33
|
+
const result = await this.db
|
|
34
|
+
.selectFrom("deleted_files")
|
|
35
|
+
.select("id")
|
|
36
|
+
.where("document_id", "=", documentId)
|
|
37
|
+
.executeTakeFirst();
|
|
38
|
+
return !!result;
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
console.error("Error checking if document is deleted:", error);
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Ensures a builder account exists in the database, creating it if it doesn't
|
|
47
|
+
* Throws an error if the document was previously deleted
|
|
48
|
+
*/
|
|
49
|
+
async ensureBuilderAccountExistsAndIsNotdeleted(documentId) {
|
|
50
|
+
// Check if the document was deleted
|
|
51
|
+
const isDeleted = await this.isDocumentDeleted(documentId);
|
|
52
|
+
if (isDeleted) {
|
|
53
|
+
throw new Error(`Builder account with document ID ${documentId} was previously deleted and cannot be accessed`);
|
|
54
|
+
}
|
|
55
|
+
const existing = await this.db
|
|
56
|
+
.selectFrom("builder_teams")
|
|
57
|
+
.select("id")
|
|
58
|
+
.where("id", "=", documentId)
|
|
59
|
+
.executeTakeFirst();
|
|
60
|
+
if (!existing) {
|
|
61
|
+
await this.db
|
|
62
|
+
.insertInto("builder_teams")
|
|
63
|
+
.values({
|
|
64
|
+
id: documentId,
|
|
65
|
+
profile_name: "",
|
|
66
|
+
profile_slug: "",
|
|
67
|
+
profile_logo: null,
|
|
68
|
+
profile_description: null,
|
|
69
|
+
profile_socials_x: null,
|
|
70
|
+
profile_socials_github: null,
|
|
71
|
+
profile_socials_website: null,
|
|
72
|
+
created_at: new Date(),
|
|
73
|
+
updated_at: new Date(),
|
|
74
|
+
})
|
|
75
|
+
.onConflict((oc) => oc.column("id").doNothing())
|
|
76
|
+
.execute();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Updates a package with the provided data
|
|
81
|
+
*/
|
|
82
|
+
async updatePackage(documentId, updates) {
|
|
83
|
+
await this.db
|
|
84
|
+
.updateTable("builder_team_packages")
|
|
85
|
+
.set({
|
|
86
|
+
...updates,
|
|
87
|
+
updated_at: new Date(),
|
|
88
|
+
})
|
|
89
|
+
.where("id", "=", documentId)
|
|
90
|
+
.execute();
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Updates a builder account with the provided data
|
|
94
|
+
*/
|
|
95
|
+
async updateBuilderAccount(documentId, updates) {
|
|
96
|
+
await this.db
|
|
97
|
+
.updateTable("builder_teams")
|
|
98
|
+
.set({
|
|
99
|
+
...updates,
|
|
100
|
+
updated_at: new Date(),
|
|
101
|
+
})
|
|
102
|
+
.where("id", "=", documentId)
|
|
103
|
+
.execute();
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Updates a builder space with the provided data
|
|
107
|
+
*/
|
|
108
|
+
async updateBuilderSpace(spaceId, documentId, updates) {
|
|
109
|
+
await this.db
|
|
110
|
+
.updateTable("builder_team_spaces")
|
|
111
|
+
.set({
|
|
112
|
+
...updates,
|
|
113
|
+
updated_at: new Date(),
|
|
114
|
+
})
|
|
115
|
+
.where("id", "=", spaceId)
|
|
116
|
+
.where("builder_team_id", "=", documentId)
|
|
117
|
+
.execute();
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Updates a builder package with the provided data
|
|
121
|
+
*/
|
|
122
|
+
async updateBuilderPackage(packageId, updates) {
|
|
123
|
+
await this.db
|
|
124
|
+
.updateTable("builder_team_packages")
|
|
125
|
+
.set({
|
|
126
|
+
...updates,
|
|
127
|
+
updated_at: new Date(),
|
|
128
|
+
})
|
|
129
|
+
.where("id", "=", packageId)
|
|
130
|
+
.execute();
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Checks if a member already exists for a builder account
|
|
134
|
+
*/
|
|
135
|
+
async memberExists(documentId, ethAddress) {
|
|
136
|
+
const existing = await this.db
|
|
137
|
+
.selectFrom("builder_team_members")
|
|
138
|
+
.select("id")
|
|
139
|
+
.where("builder_team_id", "=", documentId)
|
|
140
|
+
.where("eth_address", "=", ethAddress)
|
|
141
|
+
.executeTakeFirst();
|
|
142
|
+
return !!existing;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type IProcessorHostModule, type ProcessorRecord } from "document-drive/processors/types";
|
|
2
|
+
import { type PHDocumentHeader } from "document-model";
|
|
3
|
+
export declare const vetraBuilderTeamRelationalDbProcessorFactory: (module: IProcessorHostModule) => (driveHeader: PHDocumentHeader) => Promise<ProcessorRecord[]>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { VetraBuilderRelationalDbProcessor } from "./index.js";
|
|
2
|
+
export const vetraBuilderTeamRelationalDbProcessorFactory = (module) => async (driveHeader) => {
|
|
3
|
+
// Create a namespace for the processor and the provided drive id
|
|
4
|
+
const namespace = VetraBuilderRelationalDbProcessor.getNamespace(driveHeader.id);
|
|
5
|
+
// Create a namespaced db for the processor
|
|
6
|
+
const store = await module.relationalDb.createNamespace(namespace);
|
|
7
|
+
// Create a filter for the processor
|
|
8
|
+
const filter = {
|
|
9
|
+
branch: ["main"],
|
|
10
|
+
documentId: ["*"],
|
|
11
|
+
documentType: ["powerhouse/builder-team", "powerhouse/document-drive"],
|
|
12
|
+
scope: ["global"],
|
|
13
|
+
};
|
|
14
|
+
// Create the processor
|
|
15
|
+
const processor = new VetraBuilderRelationalDbProcessor(namespace, filter, store);
|
|
16
|
+
console.log("vetraBuilderRelationalDbProcessorFactory", processor);
|
|
17
|
+
return [
|
|
18
|
+
{
|
|
19
|
+
processor,
|
|
20
|
+
filter,
|
|
21
|
+
},
|
|
22
|
+
];
|
|
23
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { IRelationalDb } from "document-drive";
|
|
2
|
+
import { RelationalDbProcessor, type RelationalDbProcessorFilter } from "document-drive/processors/relational";
|
|
3
|
+
import { type InternalTransmitterUpdate } from "document-drive/server/listener/transmitter/internal";
|
|
4
|
+
import { type DB } from "./schema.js";
|
|
5
|
+
export declare class VetraBuilderRelationalDbProcessor extends RelationalDbProcessor<DB> {
|
|
6
|
+
static getNamespace(driveId: string): string;
|
|
7
|
+
private builderTeamHandlers;
|
|
8
|
+
constructor(_namespace: string, _filter: RelationalDbProcessorFilter, relationalDb: IRelationalDb<DB>);
|
|
9
|
+
initAndUpgrade(): Promise<void>;
|
|
10
|
+
onStrands(strands: InternalTransmitterUpdate[]): Promise<void>;
|
|
11
|
+
private handleDocumentDriveOperation;
|
|
12
|
+
onDisconnect(): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { RelationalDbProcessor, } from "document-drive/processors/relational";
|
|
2
|
+
import { BuilderTeamHandlers } from "./builder-team-handlers.js";
|
|
3
|
+
import { up } from "./migrations.js";
|
|
4
|
+
export class VetraBuilderRelationalDbProcessor extends RelationalDbProcessor {
|
|
5
|
+
static getNamespace(driveId) {
|
|
6
|
+
// Default namespace: `${this.name}_${driveId.replaceAll("-", "_")}`
|
|
7
|
+
return super.getNamespace(driveId);
|
|
8
|
+
}
|
|
9
|
+
builderTeamHandlers;
|
|
10
|
+
constructor(_namespace, _filter, relationalDb) {
|
|
11
|
+
super(_namespace, _filter, relationalDb);
|
|
12
|
+
this.builderTeamHandlers = new BuilderTeamHandlers(relationalDb);
|
|
13
|
+
}
|
|
14
|
+
async initAndUpgrade() {
|
|
15
|
+
await up(this.relationalDb);
|
|
16
|
+
}
|
|
17
|
+
async onStrands(strands) {
|
|
18
|
+
if (strands.length === 0) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
for (const strand of strands) {
|
|
22
|
+
if (strand.operations.length === 0) {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
console.log("onStrands", strand);
|
|
26
|
+
for (const operation of strand.operations) {
|
|
27
|
+
if (strand.documentType.includes("powerhouse/document-drive")) {
|
|
28
|
+
await this.handleDocumentDriveOperation(strand.documentId, strand.driveId, operation.action, operation.state);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
await this.builderTeamHandlers.handleBuilderTeamOperation(strand.documentId, operation.action, operation.state);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async handleDocumentDriveOperation(documentId, driveId = "", action, state) {
|
|
37
|
+
switch (action.type) {
|
|
38
|
+
case "DELETE_NODE":
|
|
39
|
+
await this.relationalDb
|
|
40
|
+
.insertInto("deleted_files")
|
|
41
|
+
.values({
|
|
42
|
+
id: documentId + "-" + action.input.id,
|
|
43
|
+
document_id: action.input.id,
|
|
44
|
+
drive_id: driveId,
|
|
45
|
+
deleted_at: new Date(),
|
|
46
|
+
})
|
|
47
|
+
.onConflict((oc) => oc.column("id").doNothing())
|
|
48
|
+
.execute();
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async onDisconnect() { }
|
|
53
|
+
}
|