Skip to content

Commit c128c89

Browse files
committed
return type
1 parent 003a6cf commit c128c89

4 files changed

Lines changed: 44 additions & 1 deletion

File tree

.changeset/add-space-type.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@graphprotocol/hypergraph": patch
3+
"@graphprotocol/hypergraph-react": patch
4+
---
5+
6+
Add `type` field to `PublicSpace` type returned by `Space.findManyPublic()` and `usePublicSpaces()`. The type is either `"PERSONAL"` or `"DAO"`.

.claude/settings.local.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
"Bash(pnpm typecheck:*)",
66
"Bash(pnpm check:*)",
77
"Bash(pnpm --filter events test:script:*)",
8-
"Bash(pnpm test:*)"
8+
"Bash(pnpm test:*)",
9+
"Bash(pnpm vitest:*)",
10+
"Bash(pnpm changeset:*)",
11+
"Bash(npx tsc:*)"
912
],
1013
"deny": [],
1114
"ask": []

packages/hypergraph/src/space/find-many-public.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { request } from 'graphql-request';
66

77
const spaceFields = `
88
id
9+
type
910
page {
1011
name
1112
relationsList(filter: {
@@ -53,8 +54,16 @@ query editorSpaces($accountId: UUID!) {
5354
}
5455
`;
5556

57+
export const SpaceTypeSchema = EffectSchema.Union(
58+
EffectSchema.Literal('PERSONAL'),
59+
EffectSchema.Literal('DAO'),
60+
);
61+
62+
export type SpaceType = typeof SpaceTypeSchema.Type;
63+
5664
export const PublicSpaceSchema = EffectSchema.Struct({
5765
id: EffectSchema.String,
66+
type: SpaceTypeSchema,
5867
name: EffectSchema.String,
5968
avatar: EffectSchema.optional(EffectSchema.String),
6069
editorIds: EffectSchema.Array(EffectSchema.String),
@@ -66,6 +75,7 @@ export type PublicSpace = typeof PublicSpaceSchema.Type;
6675
type SpacesQueryResult = {
6776
spaces?: {
6877
id: string;
78+
type: 'PERSONAL' | 'DAO';
6979
page: {
7080
name?: string | null;
7181
relationsList?: {
@@ -120,6 +130,7 @@ export const parseSpacesQueryResult = (queryResult: SpacesQueryResult) => {
120130
for (const space of spaces) {
121131
const rawSpace: Record<string, unknown> = {
122132
id: space.id,
133+
type: space.type,
123134
name: space.page?.name ?? undefined,
124135
avatar: getAvatarFromSpace(space),
125136
editorIds: getEditorIdsFromSpace(space),

packages/hypergraph/test/space/find-many-public.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@ import { parseSpacesQueryResult } from '../../src/space/find-many-public.js';
33

44
const buildQuerySpace = ({
55
id = 'space-id',
6+
type = 'PERSONAL',
67
name = 'Space name',
78
avatar,
89
editorsList = [],
910
membersList = [],
1011
}: {
1112
id?: string;
13+
type?: 'PERSONAL' | 'DAO';
1214
name?: string | null;
1315
avatar?: string | null;
1416
editorsList?: { memberSpaceId: string }[];
1517
membersList?: { memberSpaceId: string }[];
1618
} = {}) => {
1719
return {
1820
id,
21+
type,
1922
page: {
2023
name,
2124
relationsList:
@@ -51,6 +54,7 @@ describe('parseSpacesQueryResult', () => {
5154
expect(data).toEqual([
5255
{
5356
id: 'space-1',
57+
type: 'PERSONAL',
5458
name: 'Space 1',
5559
avatar: 'https://example.com/avatar.png',
5660
editorIds: [],
@@ -68,13 +72,30 @@ describe('parseSpacesQueryResult', () => {
6872
expect(data).toEqual([
6973
{
7074
id: 'space-2',
75+
type: 'PERSONAL',
7176
name: 'Space 2',
7277
editorIds: [],
7378
memberIds: [],
7479
},
7580
]);
7681
});
7782

83+
it('parses DAO type', () => {
84+
const { data } = parseSpacesQueryResult({
85+
spaces: [buildQuerySpace({ id: 'space-dao', type: 'DAO', name: 'DAO Space' })],
86+
});
87+
88+
expect(data).toEqual([
89+
{
90+
id: 'space-dao',
91+
type: 'DAO',
92+
name: 'DAO Space',
93+
editorIds: [],
94+
memberIds: [],
95+
},
96+
]);
97+
});
98+
7899
it('filters invalid data', () => {
79100
const { data, invalidSpaces } = parseSpacesQueryResult({
80101
spaces: [
@@ -86,6 +107,7 @@ describe('parseSpacesQueryResult', () => {
86107
expect(data).toEqual([
87108
{
88109
id: 'space-valid',
110+
type: 'PERSONAL',
89111
name: 'Space valid',
90112
avatar: 'https://example.com/a.png',
91113
editorIds: [],
@@ -111,6 +133,7 @@ describe('parseSpacesQueryResult', () => {
111133
expect(data).toEqual([
112134
{
113135
id: 'space-with-members',
136+
type: 'PERSONAL',
114137
name: 'Space with members',
115138
editorIds: ['editor-1', 'editor-2'],
116139
memberIds: ['member-1'],

0 commit comments

Comments
 (0)