Skip to content

Commit

Permalink
Composedb model updates (#2409)
Browse files Browse the repository at this point in the history
* chore(): composedb model updates

* chore(): propagate changes to apps
  • Loading branch information
kenshyx committed Sep 19, 2024
1 parent 282596a commit 4a7cdc1
Show file tree
Hide file tree
Showing 47 changed files with 668 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export const useBlocksPublishing = (props: UseBlocksPublishingProps) => {
const [isNsfw, setIsNsfw] = React.useState(false);
const [editorTags, setEditorTags] = React.useState([]);
const { getCorePlugins } = useRootComponentProps();
const [appInfo, setAppInfo] = React.useState<{
appID: string;
appVersionID: string;
}>();

React.useLayoutEffect(() => {
if (getCorePlugins()) {
Expand All @@ -59,6 +63,67 @@ export const useBlocksPublishing = (props: UseBlocksPublishingProps) => {

const defaultTextBlock = availableBlocks.find(block => block.propertyType === DEFAULT_TEXT_BLOCK);

React.useEffect(() => {
let shouldFetch = true;
const fetchAppInfo = async () => {
const info = await sdk.current.services.gql.getAPI().GetAppsByPublisherDID({
id: sdk.current.services.gql.indexingDID,
filters: { where: { name: { equalTo: '@akashaorg/app-antenna' } } },
last: 1,
});
if (info.node && 'akashaAppList' in info.node) {
return {
appID: info.node.akashaAppList.edges[0].node.id,
appVersionID: info.node.akashaAppList.edges[0].node.releases.edges[0].node.id,
};
}
};
fetchAppInfo().then(r => shouldFetch && setAppInfo(r));

return () => {
shouldFetch = false;
};
}, []);

React.useEffect(() => {
if (!blocksInUse.length) return;
if (blocksInUse.every(bl => bl.status === 'success') && appInfo) {
const tagLabelType = sdk.current.services.gql.labelTypes.TAG;
const tags = editorTags.map(tagName => {
return {
labelType: tagLabelType,
value: tagName,
};
});
const beamContent: AkashaBeamInput = {
active: true,
nsfw: isNsfw,
tags: tags,
content: blocksInUse.map(blockData => ({
blockID: blockData.response?.blockID,
order: blockData.order,
})),
createdAt: new Date().toISOString(),
appID: appInfo.appID,
appVersionID: appInfo.appVersionID,
};

if (createBeamQuery.loading || createBeamQuery.error) return;
if (createBeamQuery.called) return;

createBeam({
variables: {
i: {
content: beamContent,
},
},
}).then(resp => {
setBlocksInUse([]);
setIsPublishing(false);
});
}
}, [blocksInUse, appInfo, editorTags, isNsfw, createBeam, createBeamQuery]);

// always add the default block
React.useEffect(() => {
if (blocksInUse.length === 0) {
Expand Down Expand Up @@ -93,6 +158,8 @@ export const useBlocksPublishing = (props: UseBlocksPublishingProps) => {
order: blockData.order,
})),
createdAt: new Date().toISOString(),
appID: appInfo.appID,
appVersionID: appInfo.appVersionID,
};

if (createBeamQuery.loading || createBeamQuery.error) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,24 @@ const EditProfilePage: React.FC<EditProfilePageProps> = props => {
publishProfileData: PublishProfileData,
profileImages: Pick<PartialAkashaProfileInput, 'avatar' | 'background'>,
) => {
createProfileMutation({
const info = await sdk.services.gql.getAPI().GetAppsByPublisherDID({
id: sdk.services.gql.indexingDID,
filters: { where: { name: { equalTo: '@akashaorg/app-profile' } } },
last: 1,
});
if (!info.node || !('akashaAppList' in info.node)) {
throw new Error('@akashaorg/app-profile not found');
}
return createProfileMutation({
variables: {
i: {
content: {
name: publishProfileData.name,
description: publishProfileData.bio,
links: publishProfileData.links.map(link => ({ href: link })),
nsfw: publishProfileData.nsfw,
appID: info.node.akashaAppList.edges[0].node.id,
appVersionID: info.node.akashaAppList.edges[0].node.releases.edges[0].node.id,
createdAt: new Date().toISOString(),
...profileImages,
},
Expand All @@ -144,7 +154,8 @@ const EditProfilePage: React.FC<EditProfilePageProps> = props => {
name: publishProfileData.name,
description: publishProfileData.bio,
links: publishProfileData.links.map(link => ({ href: link })),
nsfw: publishProfileData.nsfw,
// composedDB strips immutable fields on update
// nsfw: publishProfileData.nsfw,
...profileImages,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ export const LatestTopics: React.FC<LatestTopicsProps> = props => {
},
},
onCompleted: data => {
subscriptionId.current = data.createAkashaProfileInterests?.document.id;
subscriptionId.current = data.setAkashaProfileInterests?.document.id;

const returnedData = data.createAkashaProfileInterests?.document.topics.map(
const returnedData = data.setAkashaProfileInterests?.document.topics.map(
topic => topic.value,
);

Expand Down
4 changes: 2 additions & 2 deletions libs/composedb/composites/akasha-app-links.graphql
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
interface AkashaAppReleaseInterface @loadModel(id: "kjzl6hvfrbw6c5shugmcfmrivuunrdzvrnku3ktetuvz6zzv69fnktunigc2lgj") {
interface AkashaAppReleaseInterface @loadModel(id: "kjzl6hvfrbw6c8lieadu4bugco13jdp0j9agrrsflezai2uuhtzkv97xnantmdu") {
id: ID!
}

type AkashaApp @loadModel(id: "kjzl6hvfrbw6c82w3gtimssknrieiq7j7kcq50g0vinko9jb3z005q72kdw6lpr") {
type AkashaApp @loadModel(id: "kjzl6hvfrbw6c54ufn6whf1z78go3l03fxnmlh8fj4vw90r6q2ugbo8m2yjhj68") {
id: ID!
releases: [AkashaAppReleaseInterface] @relationFrom(model: "AkashaAppReleaseInterface", property: "applicationID")
releasesCount: Int! @relationCountFrom(model: "AkashaAppReleaseInterface", property: "applicationID")
Expand Down
2 changes: 1 addition & 1 deletion libs/composedb/composites/akasha-app-release.graphql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
interface AkashaAppInterface @loadModel(id: "kjzl6hvfrbw6c86gj8z6avu2zk6ykczk5t1sgb8waul05g4lr5nd5zy1l7t3ajt") {
interface AkashaAppInterface @loadModel(id: "kjzl6hvfrbw6c7mp2kgev6yk8hrxqkwj28l92a74x3p6wi1gcms00yx9ckxsokn") {
id: ID!
}

Expand Down
4 changes: 2 additions & 2 deletions libs/composedb/composites/akasha-beam-links.graphql
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

interface AkashaReflectInterface @loadModel(id: "kjzl6hvfrbw6c6qb11x4adb625uyxl7zmrd947qdhidxppkhk56atsjtjh3tv28") {
interface AkashaReflectInterface @loadModel(id: "kjzl6hvfrbw6c9aglcacfejq5fxzy0pxc8eraoyy03b9lv2mlx5o9u85zqnrhf5") {
id: ID!
}

type AkashaBeam @loadModel(id: "kjzl6hvfrbw6c9eqxi4g8esw3rgl88z0enck6ztyk46kyzpj4vxqddfpihkrlty") {
type AkashaBeam @loadModel(id: "kjzl6hvfrbw6c7abwbe0gvpjuny4tja628bb73t65imu5k62eg8k3rm2g63v8bw") {
id: ID!
reflections: [AkashaReflectInterface] @relationFrom(model: "AkashaReflectInterface", property: "beamID")
reflectionsCount: Int! @relationCountFrom(model: "AkashaReflectInterface", property: "beamID")
Expand Down
22 changes: 19 additions & 3 deletions libs/composedb/composites/akasha-beam.graphql
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
interface AkashaContentBlockInterface @loadModel(id: "kjzl6hvfrbw6c9zxtxl9ou1i86lqo2inne8dqvyi83f26p695s98mhkw40mwwsv") {
interface AkashaContentBlockInterface @loadModel(id: "kjzl6hvfrbw6camingc354x7fs0zfvcdntuls7514mom4gpzntbv0gtyaeqduwg") {
id: ID!
}

interface AkashaAppReleaseInterface @loadModel(id: "kjzl6hvfrbw6c8lieadu4bugco13jdp0j9agrrsflezai2uuhtzkv97xnantmdu") {
id: ID!
}

interface AkashaAppInterface @loadModel(id: "kjzl6hvfrbw6c7mp2kgev6yk8hrxqkwj28l92a74x3p6wi1gcms00yx9ckxsokn") {
id: ID!

}

type BeamBlockRecord{
order: Int! @int(min: 0, max: 10)
Expand All @@ -21,7 +29,7 @@ type BeamLabeled{
}

interface AkashaBeamInterface
@createModel(description: "AKASHA Beam interface") {
@createModel(description: "AKASHA Beam interface v0.1.0") {
author: DID! @documentAccount
content: [BeamBlockRecord!]! @list(maxLength: 10) @immutable
tags: [BeamLabeled] @list(maxLength: 10) @immutable
Expand All @@ -31,10 +39,14 @@ interface AkashaBeamInterface
active: Boolean!
createdAt: DateTime! @immutable
nsfw: Boolean
appVersionID: StreamID! @documentReference(model: "AkashaAppReleaseInterface") @immutable
appVersion: AkashaAppReleaseInterface! @relationDocument(property: "appVersionID")
appID: StreamID! @documentReference(model: "AkashaAppInterface") @immutable
app: AkashaAppInterface! @relationDocument(property: "appID")
}

type AkashaBeam implements AkashaBeamInterface
@createModel(accountRelation: LIST, description: "AKASHA Beam v0.4.0")
@createModel(accountRelation: LIST, description: "AKASHA Beam v0.5.0")
@createIndex(fields:[{path:["active"]}])
@createIndex(fields:[{path:["createdAt"]}])
@createIndex(fields:[{path:["nsfw"]}])
Expand All @@ -48,4 +60,8 @@ type AkashaBeam implements AkashaBeamInterface
active: Boolean!
createdAt: DateTime! @immutable
nsfw: Boolean
appVersionID: StreamID! @documentReference(model: "AkashaAppReleaseInterface") @immutable
appVersion: AkashaAppReleaseInterface! @relationDocument(property: "appVersionID")
appID: StreamID! @documentReference(model: "AkashaAppInterface") @immutable
app: AkashaAppInterface! @relationDocument(property: "appID")
}
22 changes: 19 additions & 3 deletions libs/composedb/composites/akasha-beam.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
export default function compose(akashaContentBlockIdInterface){
export default function compose(akashaContentBlockIdInterface, akashaAppIdInterface, akashaAppReleaseIdInterface){
return `interface AkashaContentBlockInterface @loadModel(id: "${akashaContentBlockIdInterface}") {
id: ID!
}
interface AkashaAppReleaseInterface @loadModel(id: "${ akashaAppReleaseIdInterface }") {
id: ID!
}
interface AkashaAppInterface @loadModel(id: "${ akashaAppIdInterface }") {
id: ID!
}
type BeamBlockRecord{
order: Int! @int(min: 0, max: 10)
Expand All @@ -22,7 +30,7 @@ type BeamLabeled{
}
interface AkashaBeamInterface
@createModel(description: "AKASHA Beam interface") {
@createModel(description: "AKASHA Beam interface v0.1.0") {
author: DID! @documentAccount
content: [BeamBlockRecord!]! @list(maxLength: 10) @immutable
tags: [BeamLabeled] @list(maxLength: 10) @immutable
Expand All @@ -32,10 +40,14 @@ interface AkashaBeamInterface
active: Boolean!
createdAt: DateTime! @immutable
nsfw: Boolean
appVersionID: StreamID! @documentReference(model: "AkashaAppReleaseInterface") @immutable
appVersion: AkashaAppReleaseInterface! @relationDocument(property: "appVersionID")
appID: StreamID! @documentReference(model: "AkashaAppInterface") @immutable
app: AkashaAppInterface! @relationDocument(property: "appID")
}
type AkashaBeam implements AkashaBeamInterface
@createModel(accountRelation: LIST, description: "AKASHA Beam v0.4.0")
@createModel(accountRelation: LIST, description: "AKASHA Beam v0.5.0")
@createIndex(fields:[{path:["active"]}])
@createIndex(fields:[{path:["createdAt"]}])
@createIndex(fields:[{path:["nsfw"]}])
Expand All @@ -49,6 +61,10 @@ type AkashaBeam implements AkashaBeamInterface
active: Boolean!
createdAt: DateTime! @immutable
nsfw: Boolean
appVersionID: StreamID! @documentReference(model: "AkashaAppReleaseInterface") @immutable
appVersion: AkashaAppReleaseInterface! @relationDocument(property: "appVersionID")
appID: StreamID! @documentReference(model: "AkashaAppInterface") @immutable
app: AkashaAppInterface! @relationDocument(property: "appID")
}
`
}
Expand Down
2 changes: 1 addition & 1 deletion libs/composedb/composites/akasha-content-block.graphql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
interface AkashaAppReleaseInterface @loadModel(id: "kjzl6hvfrbw6c5shugmcfmrivuunrdzvrnku3ktetuvz6zzv69fnktunigc2lgj") {
interface AkashaAppReleaseInterface @loadModel(id: "kjzl6hvfrbw6c8lieadu4bugco13jdp0j9agrrsflezai2uuhtzkv97xnantmdu") {
id: ID!
}

Expand Down
4 changes: 2 additions & 2 deletions libs/composedb/composites/akasha-follow.graphql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
interface AkashaProfileInterface @loadModel(id: "kjzl6hvfrbw6caajs6qkzc286dy6slgraq9dcgfw0m681dq5nh52djd0p9ngbct"){
interface AkashaProfileInterface @loadModel(id: "kjzl6hvfrbw6c8iuza101yr8ovi9pu4qub5ghbeqhr1g15xv6xm1bkeuof4dxxd"){
id: ID!
}

Expand All @@ -11,7 +11,7 @@ interface AkashaProfileInterface @loadModel(id: "kjzl6hvfrbw6caajs6qkzc286dy6slg
}

type AkashaFollow implements AkashaFollowInterface
@createModel(accountRelation: SET, description: "Following list v0.4.0", accountRelationFields: ["profileID"])
@createModel(accountRelation: SET, description: "Following list v0.5.0", accountRelationFields: ["profileID"])
@createIndex(fields:[{path:["isFollowing"]}])
@createIndex(fields:[{path:["profileID"]}])
@createIndex(fields:[{path:["profileID"]}, {path:["isFollowing"]}])
Expand Down
2 changes: 1 addition & 1 deletion libs/composedb/composites/akasha-follow.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function compose(akashaProfileIdInterface){
}
type AkashaFollow implements AkashaFollowInterface
@createModel(accountRelation: SET, description: "Following list v0.4.0", accountRelationFields: ["profileID"])
@createModel(accountRelation: SET, description: "Following list v0.5.0", accountRelationFields: ["profileID"])
@createIndex(fields:[{path:["isFollowing"]}])
@createIndex(fields:[{path:["profileID"]}])
@createIndex(fields:[{path:["profileID"]}, {path:["isFollowing"]}])
Expand Down
4 changes: 2 additions & 2 deletions libs/composedb/composites/akasha-profile-links.graphql
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
interface AkashaFollowInterface @loadModel(id: "kjzl6hvfrbw6calrvwg964obomy7bymp65be4zwpagdjms6bm067pakecsx61st") {
interface AkashaFollowInterface @loadModel(id: "kjzl6hvfrbw6cb893zwezpclu033att8nq0oatc21cns6ryr1dubpfeczla9xml") {
id: ID!
}


type AkashaProfile @loadModel(id: "kjzl6hvfrbw6cagktk50tp31ec5nycbhzcpi0mmideporowub9qe7ee3lgml511") {
type AkashaProfile @loadModel(id: "kjzl6hvfrbw6c95s98ss8nidzuteyvjy5eipc0ov71gpt7wt6e4za6qnzqt3ccd") {
id: ID!
followers: [AkashaFollowInterface] @relationFrom(model: "AkashaFollowInterface", property: "profileID")
followersCount: Int! @relationCountFrom(model: "AkashaFollowInterface", property: "profileID")
Expand Down
23 changes: 19 additions & 4 deletions libs/composedb/composites/akasha-profile.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ type ProfileLabeled{
value: String! @string(minLength:2, maxLength: 60)
}

interface AkashaAppReleaseInterface @loadModel(id: "kjzl6hvfrbw6c8lieadu4bugco13jdp0j9agrrsflezai2uuhtzkv97xnantmdu") {
id: ID!
}

interface AkashaAppInterface @loadModel(id: "kjzl6hvfrbw6c7mp2kgev6yk8hrxqkwj28l92a74x3p6wi1gcms00yx9ckxsokn") {
id: ID!

}

interface AkashaProfileInterestsInterface
@createModel(description: "AKASHA Profile interests interface") {
topics: [ProfileLabeled!]! @list(maxLength: 100)
Expand All @@ -30,7 +39,7 @@ type AkashaProfileInterests implements AkashaProfileInterestsInterface
did: DID! @documentAccount
}

interface AkashaProfileInterface @createModel(description: "AKASHA Profile interface") {
interface AkashaProfileInterface @createModel(description: "AKASHA Profile interface v0.1.1") {
name: String! @string(minLength: 3, maxLength: 50)
avatar: ProfileImageVersions
description: String @string(maxLength: 200)
Expand All @@ -39,10 +48,14 @@ interface AkashaProfileInterface @createModel(description: "AKASHA Profile inter
did: DID! @documentAccount
createdAt: DateTime! @immutable
nsfw: Boolean @immutable
appVersionID: StreamID! @documentReference(model: "AkashaAppReleaseInterface") @immutable
appVersion: AkashaAppReleaseInterface! @relationDocument(property: "appVersionID")
appID: StreamID! @documentReference(model: "AkashaAppInterface") @immutable
app: AkashaAppInterface! @relationDocument(property: "appID")
}

type AkashaProfile implements AkashaProfileInterface
@createModel(accountRelation: SINGLE, description: "AKASHA profile v0.4.0")
@createModel(accountRelation: SINGLE, description: "AKASHA profile v0.5.1")
@createIndex(fields:[{path:["name"]}])
@createIndex(fields:[{path:["createdAt"]}])
@createIndex(fields:[{path:["nsfw"]}])
Expand All @@ -56,6 +69,8 @@ type AkashaProfile implements AkashaProfileInterface
did: DID! @documentAccount
createdAt: DateTime! @immutable
nsfw: Boolean @immutable
appVersionID: StreamID! @documentReference(model: "AkashaAppReleaseInterface") @immutable
appVersion: AkashaAppReleaseInterface! @relationDocument(property: "appVersionID")
appID: StreamID! @documentReference(model: "AkashaAppInterface") @immutable
app: AkashaAppInterface! @relationDocument(property: "appID")
}


Loading

0 comments on commit 4a7cdc1

Please sign in to comment.