Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: added space to social schema #158

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/resource-discussions/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ export const socialApps = [
'medium',
'github',
'reddit',
'linkedin'
'linkedin',
'subid',
'polkaverse',
] as const
8 changes: 8 additions & 0 deletions packages/resource-discussions/src/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ export class ResourceGraph {
socialResourceTypes.profile,
socialResourceValues.id
)
this.graph.addDirectedEdge(
socialResourceTypes.space,
socialResourceValues.id
)

/**
* Chain
Expand Down Expand Up @@ -200,6 +204,10 @@ export class ResourceGraph {
chainResourceTypes.market,
chainResourceValues.id
)
this.graph.addDirectedEdge(
chainResourceTypes.creator,
chainResourceValues.id
)

return this
}
Expand Down
12 changes: 11 additions & 1 deletion packages/resource-discussions/src/types/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export const chainResourceTypes = {
account: 'account',
proposal: 'proposal',
market: 'market',
nft: 'nft'
nft: 'nft',
creator: 'creator'
} as const

export const chainResourceValueRequiredState = {
Expand Down Expand Up @@ -49,6 +50,7 @@ type ChainResourceType =
| 'proposal'
| 'market'
| 'nft'
| 'creator'

export type ChainResourceValue<R extends ChainResourceType> = R extends 'block'
? { blockNumber: BlockNumber }
Expand All @@ -62,6 +64,8 @@ export type ChainResourceValue<R extends ChainResourceType> = R extends 'block'
? { id: Id }
: R extends 'market'
? { id: Id }
: R extends 'creator'
? { id: Id }
: R extends 'nft'
? { collectionId: CollectionId; nftId?: NftId; standard?: Standard }
: never
Expand Down Expand Up @@ -100,6 +104,11 @@ type ChainNftResourceType = {
resourceValue: ChainResourceValue<'nft'>
}

type ChainCreatorResourceType = {
resourceType: 'creator'
resourceValue: ChainResourceValue<'creator'>
}

type ChainResourceTypeValueBase =
| ChainBlockResourceType
| ChainNftResourceType
Expand All @@ -111,6 +120,7 @@ type SubstrateChainResourceTypeValue =
| ChainResourceTypeValueBase
| ChainMarkerResourceType
| ChainProposalResourceType
| ChainCreatorResourceType

type EvmChainResourceTypeValue = ChainResourceTypeValueBase
type AnyChainResourceTypeValue =
Expand Down
12 changes: 10 additions & 2 deletions packages/resource-discussions/src/types/social.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { socialApps } from '../constants'

type SocialResourceType = 'post' | 'profile'
type SocialResourceType = 'post' | 'profile' | 'space'

export const socialResourceTypes = {
post: 'post',
profile: 'profile'
profile: 'profile',
space: 'space'
} as const

export const socialResourceValueRequiredState = {
Expand All @@ -19,6 +20,8 @@ export type SocialResourceValue<R extends SocialResourceType> = R extends 'post'
? { id: string }
: R extends 'profile'
? { id: string }
: R extends 'space'
? { id: string }
: never

type SocialPostResourceType = {
Expand All @@ -29,10 +32,15 @@ type SocialProfileResourceType = {
resourceType: 'profile'
resourceValue: SocialResourceValue<'profile'>
}
type SocialSpaceResourceType = {
resourceType: 'space'
resourceValue: SocialResourceValue<'space'>
}

type SocialResourceTypeValue =
| SocialPostResourceType
| SocialProfileResourceType
| SocialSpaceResourceType

export type SocialSchemaParameters = { schema: 'social' } & {
app: (typeof socialApps)[number] | string
Expand Down
1 change: 1 addition & 0 deletions packages/resource-discussions/src/utiils/chainUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export function initChainSubstrateAllNodesEdges(graph: Graph<NodeAttributes>) {
graph.addDirectedEdge(chainName, chainResourceTypes.token)
graph.addDirectedEdge(chainName, chainResourceTypes.nft)
graph.addDirectedEdge(chainName, chainResourceTypes.proposal)
graph.addDirectedEdge(chainName, chainResourceTypes.creator)
if (chainName === 'zeitgeist')
graph.addDirectedEdge(chainName, chainResourceTypes.market)
})
Expand Down
28 changes: 28 additions & 0 deletions packages/resource-discussions/tests/resourceLinking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,32 @@ describe('Resource Linking Unit', () => {
'Provided parameters for resource are invalid. Please, check field "schema".'
)
})

test('SocialResource should ingest parameters with "schema === social"', () => {
const resourceValue: Resource = new Resource({
schema: 'social',
app: 'subid',
resourceType: 'space',
resourceValue: {
id: 'spaceId'
}
})

const resourceCreator: Resource = new Resource({
schema: 'chain',
chainType: 'substrate',
chainName: 'subsocial',
resourceType: 'creator',
resourceValue: {
id: 'spaceId'
}
})

expect(resourceCreator.toResourceId()).toEqual(
'chain://chainType:substrate/chainName:subsocial/resourceType:creator/id:spaceId'
)
expect(resourceValue.toResourceId()).toEqual(
'social://app:subid/resourceType:space/id:spaceId'
)
})
})