Skip to content

Commit

Permalink
feat: added space to social schema
Browse files Browse the repository at this point in the history
  • Loading branch information
mckrava committed Oct 11, 2023
1 parent ee027a6 commit 841f38e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
4 changes: 4 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
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
15 changes: 15 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,19 @@ 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'
}
})

expect(resourceValue.toResourceId()).toEqual(
'social://app:subid/resourceType:space/id:spaceId'
)
})
})

0 comments on commit 841f38e

Please sign in to comment.