diff --git a/src/api/__tests__/entityQuerySync.test.js b/src/api/__tests__/entityQuerySync.test.js index 5381f0e3..9c8db2b8 100644 --- a/src/api/__tests__/entityQuerySync.test.js +++ b/src/api/__tests__/entityQuerySync.test.js @@ -2,7 +2,6 @@ import { beforeEach, describe, expect, test, vi } from 'vitest'; const mockRequest = vi.fn(); const mockPatchAndRefetchActiveQuery = vi.fn(() => Promise.resolve()); -const mockFetchWithEntityPolicy = vi.fn(); const mockApplyCurrentUser = vi.fn((json) => ({ id: json.id || 'usr_me', ...json })); const mockApplyUser = vi.fn((json) => ({ ...json })); @@ -24,22 +23,12 @@ vi.mock('../../stores', () => ({ })); vi.mock('../../queries', () => ({ - entityQueryPolicies: { - user: { staleTime: 20000, gcTime: 90000, retry: 1, refetchOnWindowFocus: false }, - avatar: { staleTime: 60000, gcTime: 300000, retry: 1, refetchOnWindowFocus: false }, - world: { staleTime: 60000, gcTime: 300000, retry: 1, refetchOnWindowFocus: false }, - worldCollection: { staleTime: 60000, gcTime: 300000, retry: 1, refetchOnWindowFocus: false }, - instance: { staleTime: 0, gcTime: 10000, retry: 0, refetchOnWindowFocus: false } - }, - fetchWithEntityPolicy: (...args) => mockFetchWithEntityPolicy(...args), patchAndRefetchActiveQuery: (...args) => mockPatchAndRefetchActiveQuery(...args), queryKeys: { user: (userId) => ['user', userId], avatar: (avatarId) => ['avatar', avatarId], - world: (worldId) => ['world', worldId], - worldsByUser: (params) => ['worlds', 'user', params.userId, params], - instance: (worldId, instanceId) => ['instance', worldId, instanceId] + world: (worldId) => ['world', worldId] } })); @@ -88,26 +77,4 @@ describe('entity mutation query sync', () => { ); }); - test('getCachedWorlds uses policy wrapper for world list data', async () => { - mockFetchWithEntityPolicy.mockResolvedValue({ - data: { - json: [{ id: 'wrld_1' }], - params: { userId: 'usr_me', n: 50, offset: 0 } - }, - cache: true - }); - - const args = await worldRequest.getCachedWorlds({ - userId: 'usr_me', - n: 50, - offset: 0, - sort: 'updated', - order: 'descending', - user: 'me', - releaseStatus: 'all' - }); - - expect(mockFetchWithEntityPolicy).toHaveBeenCalled(); - expect(args.cache).toBe(true); - }); }); diff --git a/src/api/__tests__/favoriteQuerySync.test.js b/src/api/__tests__/favoriteQuerySync.test.js index 11cb2bd4..a9570f0b 100644 --- a/src/api/__tests__/favoriteQuerySync.test.js +++ b/src/api/__tests__/favoriteQuerySync.test.js @@ -1,7 +1,6 @@ import { beforeEach, describe, expect, test, vi } from 'vitest'; const mockRequest = vi.fn(); -const mockFetchWithEntityPolicy = vi.fn(); const mockInvalidateQueries = vi.fn().mockResolvedValue(); const mockHandleFavoriteAdd = vi.fn(); const mockHandleFavoriteDelete = vi.fn(); @@ -24,24 +23,8 @@ vi.mock('../../stores', () => ({ })); vi.mock('../../queries', () => ({ - entityQueryPolicies: { - favoriteCollection: { - staleTime: 60000, - gcTime: 300000, - retry: 1, - refetchOnWindowFocus: false - } - }, - fetchWithEntityPolicy: (...args) => mockFetchWithEntityPolicy(...args), queryClient: { invalidateQueries: (...args) => mockInvalidateQueries(...args) - }, - queryKeys: { - favoriteLimits: () => ['favorite', 'limits'], - favorites: (params) => ['favorite', 'items', params], - favoriteGroups: (params) => ['favorite', 'groups', params], - favoriteWorlds: (params) => ['favorite', 'worlds', params], - favoriteAvatars: (params) => ['favorite', 'avatars', params] } })); @@ -52,21 +35,6 @@ describe('favorite query sync', () => { vi.clearAllMocks(); }); - test('cached favorite reads go through fetchWithEntityPolicy', async () => { - mockFetchWithEntityPolicy.mockResolvedValue({ - data: { json: [], params: { n: 300, offset: 0 } }, - cache: true - }); - - const args = await favoriteRequest.getCachedFavorites({ - n: 300, - offset: 0 - }); - - expect(mockFetchWithEntityPolicy).toHaveBeenCalled(); - expect(args.cache).toBe(true); - }); - test('favorite mutations invalidate active favorite queries', async () => { mockRequest.mockResolvedValue({ ok: true }); diff --git a/src/api/__tests__/friendQuerySync.test.js b/src/api/__tests__/friendQuerySync.test.js index 2a39b0c6..bc656b5c 100644 --- a/src/api/__tests__/friendQuerySync.test.js +++ b/src/api/__tests__/friendQuerySync.test.js @@ -1,7 +1,6 @@ import { beforeEach, describe, expect, test, vi } from 'vitest'; const mockRequest = vi.fn(); -const mockFetchWithEntityPolicy = vi.fn(); const mockInvalidateQueries = vi.fn().mockResolvedValue(); const mockApplyUser = vi.fn((json) => json); @@ -16,20 +15,8 @@ vi.mock('../../stores/user', () => ({ })); vi.mock('../../queries', () => ({ - entityQueryPolicies: { - friendList: { - staleTime: 20000, - gcTime: 90000, - retry: 1, - refetchOnWindowFocus: false - } - }, - fetchWithEntityPolicy: (...args) => mockFetchWithEntityPolicy(...args), queryClient: { invalidateQueries: (...args) => mockInvalidateQueries(...args) - }, - queryKeys: { - friends: (params) => ['friends', params] } })); @@ -40,22 +27,6 @@ describe('friend query sync', () => { vi.clearAllMocks(); }); - test('getCachedFriends uses query policy wrapper', async () => { - mockFetchWithEntityPolicy.mockResolvedValue({ - data: { - json: [{ id: 'usr_1', displayName: 'A' }], - params: { n: 50, offset: 0 } - }, - cache: true - }); - - const args = await friendRequest.getCachedFriends({ n: 50, offset: 0 }); - - expect(mockFetchWithEntityPolicy).toHaveBeenCalled(); - expect(args.cache).toBe(true); - expect(args.json[0].id).toBe('usr_1'); - }); - test('friend mutations invalidate active friends queries', async () => { mockRequest.mockResolvedValue({ ok: true }); diff --git a/src/api/__tests__/groupQuerySync.test.js b/src/api/__tests__/groupQuerySync.test.js index 08cf43cb..8967cfff 100644 --- a/src/api/__tests__/groupQuerySync.test.js +++ b/src/api/__tests__/groupQuerySync.test.js @@ -1,7 +1,6 @@ import { beforeEach, describe, expect, test, vi } from 'vitest'; const mockRequest = vi.fn(); -const mockFetchWithEntityPolicy = vi.fn(); const mockInvalidateQueries = vi.fn().mockResolvedValue(); const mockApplyGroup = vi.fn((json) => json); @@ -19,32 +18,8 @@ vi.mock('../../stores', () => ({ })); vi.mock('../../queries', () => ({ - entityQueryPolicies: { - group: { - staleTime: 60000, - gcTime: 300000, - retry: 1, - refetchOnWindowFocus: false - }, - groupCollection: { - staleTime: 60000, - gcTime: 300000, - retry: 1, - refetchOnWindowFocus: false - } - }, - fetchWithEntityPolicy: (...args) => mockFetchWithEntityPolicy(...args), queryClient: { invalidateQueries: (...args) => mockInvalidateQueries(...args) - }, - queryKeys: { - group: (groupId, includeRoles) => ['group', groupId, Boolean(includeRoles)], - groupPosts: (params) => ['group', params.groupId, 'posts', params], - groupMember: (params) => ['group', params.groupId, 'member', params.userId], - groupMembers: (params) => ['group', params.groupId, 'members', params], - groupGallery: (params) => ['group', params.groupId, 'gallery', params.galleryId, params], - groupCalendar: (groupId) => ['group', groupId, 'calendar'], - groupCalendarEvent: (params) => ['group', params.groupId, 'calendarEvent', params.eventId] } })); @@ -55,29 +30,6 @@ describe('group query sync', () => { vi.clearAllMocks(); }); - test('cached group resources use fetchWithEntityPolicy', async () => { - mockFetchWithEntityPolicy.mockResolvedValue({ - data: { json: [], params: { groupId: 'grp_1', n: 100, offset: 0 } }, - cache: true - }); - - const a = await groupRequest.getCachedGroupMembers({ - groupId: 'grp_1', - n: 100, - offset: 0, - sort: 'joinedAt:desc' - }); - const b = await groupRequest.getCachedGroupGallery({ - groupId: 'grp_1', - galleryId: 'gal_1', - n: 100, - offset: 0 - }); - - expect(mockFetchWithEntityPolicy).toHaveBeenCalledTimes(2); - expect(a.cache && b.cache).toBe(true); - }); - test('group mutations invalidate scoped active group queries', async () => { mockRequest.mockResolvedValue({ ok: true }); diff --git a/src/api/__tests__/mediaQuerySync.test.js b/src/api/__tests__/mediaQuerySync.test.js index 00693267..18186d6a 100644 --- a/src/api/__tests__/mediaQuerySync.test.js +++ b/src/api/__tests__/mediaQuerySync.test.js @@ -1,7 +1,6 @@ import { beforeEach, describe, expect, test, vi } from 'vitest'; const mockRequest = vi.fn(); -const mockFetchWithEntityPolicy = vi.fn(); const mockInvalidateQueries = vi.fn().mockResolvedValue(); const mockRemoveQueries = vi.fn(); @@ -16,27 +15,6 @@ vi.mock('../../stores', () => ({ })); vi.mock('../../queries', () => ({ - entityQueryPolicies: { - galleryCollection: { - staleTime: 60000, - gcTime: 300000, - retry: 1, - refetchOnWindowFocus: false - }, - inventoryCollection: { - staleTime: 20000, - gcTime: 120000, - retry: 1, - refetchOnWindowFocus: false - }, - fileObject: { - staleTime: 60000, - gcTime: 300000, - retry: 1, - refetchOnWindowFocus: false - } - }, - fetchWithEntityPolicy: (...args) => mockFetchWithEntityPolicy(...args), queryClient: { invalidateQueries: (...args) => mockInvalidateQueries(...args), removeQueries: (...args) => mockRemoveQueries(...args) @@ -51,7 +29,6 @@ vi.mock('../../queries', () => ({ } })); -import inventoryRequest from '../inventory'; import miscRequest from '../misc'; import vrcPlusIconRequest from '../vrcPlusIcon'; import vrcPlusImageRequest from '../vrcPlusImage'; @@ -61,25 +38,6 @@ describe('media and inventory query sync', () => { vi.clearAllMocks(); }); - test('cached media/inventory reads go through fetchWithEntityPolicy', async () => { - mockFetchWithEntityPolicy.mockResolvedValue({ - data: { json: [], params: {} }, - cache: true - }); - - const a = await vrcPlusIconRequest.getCachedFileList({ tag: 'icon', n: 100 }); - const b = await vrcPlusImageRequest.getCachedPrints({ n: 100 }); - const c = await inventoryRequest.getCachedInventoryItems({ - n: 100, - offset: 0, - order: 'newest' - }); - const d = await miscRequest.getCachedFile({ fileId: 'file_1' }); - - expect(mockFetchWithEntityPolicy).toHaveBeenCalledTimes(4); - expect(a.cache && b.cache && c.cache && d.cache).toBe(true); - }); - test('media mutations invalidate gallery queries and file delete removes file query', async () => { mockRequest.mockResolvedValue({ ok: true }); diff --git a/src/api/__tests__/queryRequest.test.js b/src/api/__tests__/queryRequest.test.js new file mode 100644 index 00000000..498fb858 --- /dev/null +++ b/src/api/__tests__/queryRequest.test.js @@ -0,0 +1,174 @@ +import { beforeEach, describe, expect, test, vi } from 'vitest'; + +const mockFetchWithEntityPolicy = vi.fn(); +const mockGetUser = vi.fn(); +const mockGetWorlds = vi.fn(); +const mockGetGroupCalendar = vi.fn(); + +vi.mock('../../queries', () => ({ + entityQueryPolicies: { + user: { staleTime: 20000, gcTime: 90000, retry: 1, refetchOnWindowFocus: false }, + worldCollection: { staleTime: 60000, gcTime: 300000, retry: 1, refetchOnWindowFocus: false }, + groupCollection: { staleTime: 60000, gcTime: 300000, retry: 1, refetchOnWindowFocus: false }, + avatar: { staleTime: 60000, gcTime: 300000, retry: 1, refetchOnWindowFocus: false }, + world: { staleTime: 60000, gcTime: 300000, retry: 1, refetchOnWindowFocus: false }, + group: { staleTime: 60000, gcTime: 300000, retry: 1, refetchOnWindowFocus: false }, + friendList: { staleTime: 20000, gcTime: 90000, retry: 1, refetchOnWindowFocus: false }, + favoriteCollection: { staleTime: 60000, gcTime: 300000, retry: 1, refetchOnWindowFocus: false }, + galleryCollection: { staleTime: 60000, gcTime: 300000, retry: 1, refetchOnWindowFocus: false }, + inventoryCollection: { staleTime: 20000, gcTime: 120000, retry: 1, refetchOnWindowFocus: false }, + fileObject: { staleTime: 60000, gcTime: 300000, retry: 1, refetchOnWindowFocus: false } + }, + fetchWithEntityPolicy: (...args) => mockFetchWithEntityPolicy(...args), + queryKeys: { + user: (userId) => ['user', userId], + worldsByUser: (params) => ['worlds', 'user', params.userId, params], + groupCalendar: (groupId) => ['group', groupId, 'calendar'], + avatar: (avatarId) => ['avatar', avatarId], + world: (worldId) => ['world', worldId], + group: (groupId, includeRoles) => ['group', groupId, Boolean(includeRoles)], + groupPosts: (params) => ['group', params.groupId, 'posts', params], + groupMember: (params) => ['group', params.groupId, 'member', params.userId], + groupMembers: (params) => ['group', params.groupId, 'members', params], + groupGallery: (params) => ['group', params.groupId, 'gallery', params.galleryId, params], + groupCalendarEvent: (params) => ['group', params.groupId, 'calendarEvent', params.eventId], + friends: (params) => ['friends', params], + favoriteLimits: () => ['favorite', 'limits'], + favorites: (params) => ['favorite', 'items', params], + favoriteGroups: (params) => ['favorite', 'groups', params], + favoriteWorlds: (params) => ['favorite', 'worlds', params], + favoriteAvatars: (params) => ['favorite', 'avatars', params], + galleryFiles: (params) => ['gallery', 'files', params], + prints: (params) => ['gallery', 'prints', params], + print: (printId) => ['gallery', 'print', printId], + userInventoryItem: (params) => ['inventory', 'item', params.userId, params.inventoryId], + inventoryItems: (params) => ['inventory', 'items', params], + file: (fileId) => ['file', fileId] + } +})); + +vi.mock('../user', () => ({ + default: { + getUser: (...args) => mockGetUser(...args) + } +})); + +vi.mock('../world', () => ({ + default: { + getWorlds: (...args) => mockGetWorlds(...args), + getWorld: vi.fn() + } +})); + +vi.mock('../group', () => ({ + default: { + getGroupCalendar: (...args) => mockGetGroupCalendar(...args), + getGroup: vi.fn(), + getGroupPosts: vi.fn(), + getGroupMember: vi.fn(), + getGroupMembers: vi.fn(), + getGroupGallery: vi.fn(), + getGroupCalendarEvent: vi.fn() + } +})); + +vi.mock('../avatar', () => ({ default: { getAvatar: vi.fn() } })); +vi.mock('../friend', () => ({ default: { getFriends: vi.fn() } })); +vi.mock('../favorite', () => ({ + default: { + getFavoriteLimits: vi.fn(), + getFavorites: vi.fn(), + getFavoriteGroups: vi.fn(), + getFavoriteWorlds: vi.fn(), + getFavoriteAvatars: vi.fn() + } +})); +vi.mock('../vrcPlusIcon', () => ({ default: { getFileList: vi.fn() } })); +vi.mock('../vrcPlusImage', () => ({ + default: { getPrints: vi.fn(), getPrint: vi.fn() } +})); +vi.mock('../inventory', () => ({ + default: { getUserInventoryItem: vi.fn(), getInventoryItems: vi.fn() } +})); +vi.mock('../misc', () => ({ default: { getFile: vi.fn() } })); + +import queryRequest from '../queryRequest'; + +describe('queryRequest', () => { + beforeEach(() => { + vi.clearAllMocks(); + }); + + test('routes user fetch through policy wrapper and returns cache marker', async () => { + const data = { json: { id: 'usr_1' }, params: { userId: 'usr_1' } }; + mockGetUser.mockResolvedValue(data); + mockFetchWithEntityPolicy.mockImplementation(async ({ queryFn }) => ({ + data: await queryFn(), + cache: true + })); + + const args = await queryRequest.fetch('user', { userId: 'usr_1' }); + + expect(mockFetchWithEntityPolicy).toHaveBeenCalledWith( + expect.objectContaining({ + queryKey: ['user', 'usr_1'] + }) + ); + expect(args.cache).toBe(true); + expect(args.json.id).toBe('usr_1'); + }); + + test('supports worldsByUser option routing', async () => { + const params = { + userId: 'usr_me', + n: 50, + offset: 0, + sort: 'updated', + order: 'descending', + user: 'me', + releaseStatus: 'all', + option: 'featured' + }; + mockGetWorlds.mockResolvedValue({ json: [], params }); + mockFetchWithEntityPolicy.mockImplementation(async ({ queryFn }) => ({ + data: await queryFn(), + cache: false + })); + + await queryRequest.fetch('worldsByUser', params); + + expect(mockGetWorlds).toHaveBeenCalledWith(params, 'featured'); + expect(mockFetchWithEntityPolicy).toHaveBeenCalledWith( + expect.objectContaining({ + queryKey: ['worlds', 'user', 'usr_me', params] + }) + ); + }); + + test('supports groupCalendar resource shape', async () => { + mockGetGroupCalendar.mockResolvedValue({ + json: { results: [] }, + params: { groupId: 'grp_1' } + }); + mockFetchWithEntityPolicy.mockImplementation(async ({ queryFn }) => ({ + data: await queryFn(), + cache: false + })); + + await queryRequest.fetch('groupCalendar', { groupId: 'grp_1' }); + + expect(mockGetGroupCalendar).toHaveBeenCalledWith('grp_1'); + expect(mockFetchWithEntityPolicy).toHaveBeenCalledWith( + expect.objectContaining({ + queryKey: ['group', 'grp_1', 'calendar'] + }) + ); + }); + + test('throws on unknown resource', async () => { + await expect( + // @ts-expect-error verifying runtime guard + queryRequest.fetch('missing_resource', {}) + ).rejects.toThrow('Unknown query resource'); + }); +}); diff --git a/src/api/avatar.js b/src/api/avatar.js index af782d5c..cf4a3146 100644 --- a/src/api/avatar.js +++ b/src/api/avatar.js @@ -1,11 +1,6 @@ +import { patchAndRefetchActiveQuery, queryKeys } from '../queries'; import { request } from '../service/request'; import { useUserStore } from '../stores'; -import { - entityQueryPolicies, - fetchWithEntityPolicy, - patchAndRefetchActiveQuery, - queryKeys -} from '../queries'; const avatarReq = { /** @@ -23,22 +18,6 @@ const avatarReq = { }); }, - /** - * Fetch avatar from query cache if fresh. Otherwise, calls API. - * @param {{avatarId: string}} params - * @returns {Promise<{json: any, ref?: any, cache?: boolean, params: {avatarId: string}}>} - */ - getCachedAvatar(params) { - return fetchWithEntityPolicy({ - queryKey: queryKeys.avatar(params.avatarId), - policy: entityQueryPolicies.avatar, - queryFn: () => avatarReq.getAvatar(params) - }).then(({ data, cache }) => ({ - ...data, - cache - })); - }, - /** * @type {import('../types/api/avatar').GetAvatars} */ @@ -72,7 +51,10 @@ const avatarReq = { queryKey: queryKeys.avatar(params.id), nextData: args }).catch((err) => { - console.error('Failed to refresh avatar query after mutation:', err); + console.error( + 'Failed to refresh avatar query after mutation:', + err + ); }); return args; }); @@ -112,7 +94,7 @@ const avatarReq = { /** * @param {{ avatarId: string }} params - * @return { Promise<{json: any, params}> } + * @returns { Promise<{json: any, params}> } */ selectFallbackAvatar(params) { const userStore = useUserStore(); @@ -144,7 +126,7 @@ const avatarReq = { /** * @param {{ avatarId: string }} params - * @return { Promise<{json: any, params}> } + * @returns { Promise<{json: any, params}> } */ deleteAvatar(params) { return request(`avatars/${params.avatarId}`, { @@ -247,6 +229,8 @@ const avatarReq = { /** * @param {{ imageData: string, avatarId: string }} + * @param imageData + * @param avatarId * @returns {Promise<{json: any, params}>} */ uploadAvatarGalleryImage(imageData, avatarId) { diff --git a/src/api/favorite.js b/src/api/favorite.js index c1446782..8fdefded 100644 --- a/src/api/favorite.js +++ b/src/api/favorite.js @@ -1,16 +1,17 @@ import { useFavoriteStore, useUserStore } from '../stores'; +import { queryClient } from '../queries'; import { request } from '../service/request'; -import { - entityQueryPolicies, - fetchWithEntityPolicy, - queryClient, - queryKeys -} from '../queries'; +/** + * + */ function getCurrentUserId() { return useUserStore().currentUser.id; } +/** + * + */ function refetchActiveFavoriteQueries() { queryClient .invalidateQueries({ @@ -34,17 +35,6 @@ const favoriteReq = { }); }, - getCachedFavoriteLimits() { - return fetchWithEntityPolicy({ - queryKey: queryKeys.favoriteLimits(), - policy: entityQueryPolicies.favoriteCollection, - queryFn: () => favoriteReq.getFavoriteLimits() - }).then(({ data, cache }) => ({ - ...data, - cache - })); - }, - /** * @type {import('../types/api/favorite').GetFavorites} */ @@ -61,17 +51,6 @@ const favoriteReq = { }); }, - getCachedFavorites(params) { - return fetchWithEntityPolicy({ - queryKey: queryKeys.favorites(params), - policy: entityQueryPolicies.favoriteCollection, - queryFn: () => favoriteReq.getFavorites(params) - }).then(({ data, cache }) => ({ - ...data, - cache - })); - }, - /** * @type {import('../types/api/favorite').AddFavorite} */ @@ -92,7 +71,7 @@ const favoriteReq = { /** * @param {{ objectId: string }} params - * @return { Promise<{json: any, params}> } + * @returns { Promise<{json: any, params}> } */ deleteFavorite(params) { return request(`favorites/${params.objectId}`, { @@ -110,7 +89,7 @@ const favoriteReq = { /** * @param {{ n: number, offset: number, type: string }} params - * @return { Promise<{json: any, params}> } + * @returns { Promise<{json: any, params}> } */ getFavoriteGroups(params) { return request('favorite/groups', { @@ -125,21 +104,10 @@ const favoriteReq = { }); }, - getCachedFavoriteGroups(params) { - return fetchWithEntityPolicy({ - queryKey: queryKeys.favoriteGroups(params), - policy: entityQueryPolicies.favoriteCollection, - queryFn: () => favoriteReq.getFavoriteGroups(params) - }).then(({ data, cache }) => ({ - ...data, - cache - })); - }, - /** * * @param {{ type: string, group: string, displayName?: string, visibility?: string }} params group is a name - * @return { Promise<{json: any, params}> } + * @returns { Promise<{json: any, params}> } */ saveFavoriteGroup(params) { return request( @@ -163,7 +131,7 @@ const favoriteReq = { * type: string, * group: string * }} params - * @return { Promise<{json: any, params}> } + * @returns { Promise<{json: any, params}> } */ clearFavoriteGroup(params) { return request( @@ -199,17 +167,6 @@ const favoriteReq = { }); }, - getCachedFavoriteWorlds(params) { - return fetchWithEntityPolicy({ - queryKey: queryKeys.favoriteWorlds(params), - policy: entityQueryPolicies.favoriteCollection, - queryFn: () => favoriteReq.getFavoriteWorlds(params) - }).then(({ data, cache }) => ({ - ...data, - cache - })); - }, - /** * @type {import('../types/api/favorite').GetFavoriteAvatars} */ @@ -224,17 +181,6 @@ const favoriteReq = { }; return args; }); - }, - - getCachedFavoriteAvatars(params) { - return fetchWithEntityPolicy({ - queryKey: queryKeys.favoriteAvatars(params), - policy: entityQueryPolicies.favoriteCollection, - queryFn: () => favoriteReq.getFavoriteAvatars(params) - }).then(({ data, cache }) => ({ - ...data, - cache - })); } }; diff --git a/src/api/friend.js b/src/api/friend.js index 4ae1f9d4..ff317b2f 100644 --- a/src/api/friend.js +++ b/src/api/friend.js @@ -1,12 +1,10 @@ +import { queryClient } from '../queries'; import { request } from '../service/request'; import { useUserStore } from '../stores/user'; -import { - entityQueryPolicies, - fetchWithEntityPolicy, - queryClient, - queryKeys -} from '../queries'; +/** + * + */ function refetchActiveFriendListQueries() { queryClient .invalidateQueries({ @@ -44,22 +42,6 @@ const friendReq = { }); }, - /** - * Fetch friends from query cache if still fresh. Otherwise, calls API. - * @param {{ n: number, offset: number, offline?: boolean }} params - * @returns {Promise<{json: any, params: { n: number, offset: number, offline?: boolean }, cache?: boolean}>} - */ - getCachedFriends(params) { - return fetchWithEntityPolicy({ - queryKey: queryKeys.friends(params), - policy: entityQueryPolicies.friendList, - queryFn: () => friendReq.getFriends(params) - }).then(({ data, cache }) => ({ - ...data, - cache - })); - }, - /** * @param {{ userId: string }} params * @returns {Promise<{json: any, params: { userId: string }}>} @@ -96,6 +78,7 @@ const friendReq = { /** * @param {{ userId: string }} params + * @param customMsg * @returns {Promise<{json: any, params: { userId: string }}>} */ deleteFriend(params, customMsg) { diff --git a/src/api/group.js b/src/api/group.js index f19ead15..fdbdead5 100644 --- a/src/api/group.js +++ b/src/api/group.js @@ -1,16 +1,18 @@ import { useGroupStore, useUserStore } from '../stores'; +import { queryClient } from '../queries'; import { request } from '../service/request'; -import { - entityQueryPolicies, - fetchWithEntityPolicy, - queryClient, - queryKeys -} from '../queries'; +/** + * + */ function getCurrentUserId() { return useUserStore().currentUser.id; } +/** + * + * @param groupId + */ function refetchActiveGroupScope(groupId) { if (!groupId) { return; @@ -47,7 +49,7 @@ const groupReq = { /** * @param {{ groupId: string }} params - * @return { Promise<{json: any, params}> } + * @returns { Promise<{json: any, params}> } */ cancelGroupRequest(params) { return request(`groups/${params.groupId}/requests`, { @@ -63,7 +65,7 @@ const groupReq = { /** * @param {{ groupId: string, postId: string }} params - * @return { Promise<{json: any, params}> } + * @returns { Promise<{json: any, params}> } */ deleteGroupPost(params) { return request(`groups/${params.groupId}/posts/${params.postId}`, { @@ -87,35 +89,18 @@ const groupReq = { includeRoles: params.includeRoles || false } }).then((json) => { + const groupStore = useGroupStore(); const args = { json, params }; + args.ref = groupStore.applyGroup(json); return args; }); }, - /** - * - * @param {{ groupId: string }} params - * @return { Promise<{json: any, ref: any, cache?: boolean, params}> } - */ - getCachedGroup(params) { - return fetchWithEntityPolicy({ - queryKey: queryKeys.group(params.groupId, params.includeRoles), - policy: entityQueryPolicies.group, - queryFn: () => groupReq.getGroup(params).then((args) => { - const groupStore = useGroupStore(); - args.ref = groupStore.applyGroup(args.json); - return args; - }) - }).then(({ data, cache }) => ({ - ...data, - cache - })); - }, /** * @param {{ userId: string }} params - * @return { Promise<{json: any, params}> } + * @returns { Promise<{json: any, params}> } */ getRepresentedGroup(params) { return request(`users/${params.userId}/groups/represented`, { @@ -130,7 +115,7 @@ const groupReq = { }, /** * @param {{ userId: string }} params - * @return { Promise<{json: any, params}> } + * @returns { Promise<{json: any, params}> } */ getGroups(params) { return request(`users/${params.userId}/groups`, { @@ -145,7 +130,7 @@ const groupReq = { }, /** * @param {{ groupId: string }} params - * @return { Promise<{json: any, params}> } + * @returns { Promise<{json: any, params}> } */ joinGroup(params) { return request(`groups/${params.groupId}/join`, { @@ -161,7 +146,7 @@ const groupReq = { }, /** * @param {{ groupId: string }} params - * @return { Promise<{json: any, params}> } + * @returns { Promise<{json: any, params}> } */ leaveGroup(params) { return request(`groups/${params.groupId}/leave`, { @@ -177,7 +162,7 @@ const groupReq = { }, /** * @param {{ query: string }} params - * @return { Promise<{json: any, params}> } + * @returns { Promise<{json: any, params}> } */ groupStrictsearch(params) { return request(`groups/strictsearch`, { @@ -199,7 +184,10 @@ const groupReq = { isSubscribedToAnnouncements: bool, managerNotes: string } - */ + * @param userId + * @param groupId + * @param params + */ setGroupMemberProps(userId, groupId, params) { return request(`groups/${groupId}/members/${userId}`, { method: 'PUT', @@ -221,7 +209,7 @@ const groupReq = { * groupId: string, * roleId: string * }} params - * @return { Promise<{json: any, params}> } + * @returns { Promise<{json: any, params}> } */ addGroupMemberRole(params) { return request( @@ -244,7 +232,7 @@ const groupReq = { * groupId: string, * roleId: string * }} params - * @return { Promise<{json: any, params}> } + * @returns { Promise<{json: any, params}> } */ removeGroupMemberRole(params) { return request( @@ -278,7 +266,7 @@ const groupReq = { n: number, offset: number }} params - * @return { Promise<{json: any, params}> } + * @returns { Promise<{json: any, params}> } */ getGroupPosts(params) { return request(`groups/${params.groupId}/posts`, { @@ -292,16 +280,6 @@ const groupReq = { return args; }); }, - getCachedGroupPosts(params) { - return fetchWithEntityPolicy({ - queryKey: queryKeys.groupPosts(params), - policy: entityQueryPolicies.groupCollection, - queryFn: () => groupReq.getGroupPosts(params) - }).then(({ data, cache }) => ({ - ...data, - cache - })); - }, editGroupPost(params) { return request(`groups/${params.groupId}/posts/${params.postId}`, { method: 'PUT', @@ -333,7 +311,7 @@ const groupReq = { * groupId: string, * userId: string * }} params - * @return { Promise<{json: any, params, ref?: any}> } + * @returns { Promise<{json: any, params, ref?: any}> } */ getGroupMember(params) { return request(`groups/${params.groupId}/members/${params.userId}`, { @@ -346,23 +324,13 @@ const groupReq = { return args; }); }, - getCachedGroupMember(params) { - return fetchWithEntityPolicy({ - queryKey: queryKeys.groupMember(params), - policy: entityQueryPolicies.groupCollection, - queryFn: () => groupReq.getGroupMember(params) - }).then(({ data, cache }) => ({ - ...data, - cache - })); - }, /** * @param {{ * groupId: string, * n: number, * offset: number * }} params - * @return { Promise<{json: any, params}> } + * @returns { Promise<{json: any, params}> } */ getGroupMembers(params) { return request(`groups/${params.groupId}/members`, { @@ -376,16 +344,6 @@ const groupReq = { return args; }); }, - getCachedGroupMembers(params) { - return fetchWithEntityPolicy({ - queryKey: queryKeys.groupMembers(params), - policy: entityQueryPolicies.groupCollection, - queryFn: () => groupReq.getGroupMembers(params) - }).then(({ data, cache }) => ({ - ...data, - cache - })); - }, /** * @param {{ * groupId: string, @@ -393,7 +351,7 @@ const groupReq = { * n: number, * offset: number * }} params - * @return { Promise<{json: any, params}> } + * @returns { Promise<{json: any, params}> } */ getGroupMembersSearch(params) { return request(`groups/${params.groupId}/members/search`, { @@ -411,7 +369,7 @@ const groupReq = { * @param {{ * groupId: string * }} params - * @return { Promise<{json: any, params}> } + * @returns { Promise<{json: any, params}> } */ blockGroup(params) { return request(`groups/${params.groupId}/block`, { @@ -430,7 +388,7 @@ const groupReq = { * groupId: string, * userId: string * }} params - * @return { Promise<{json: any, params}> } + * @returns { Promise<{json: any, params}> } */ unblockGroup(params) { return request(`groups/${params.groupId}/members/${params.userId}`, { @@ -449,7 +407,7 @@ const groupReq = { * groupId: string, * userId: string * }} params - * @return { Promise<{json: any, params}> } + * @returns { Promise<{json: any, params}> } */ sendGroupInvite(params) { return request(`groups/${params.groupId}/invites`, { @@ -470,7 +428,7 @@ const groupReq = { * groupId: string, * userId: string * }} params - * @return { Promise<{json: any, params}> } + * @returns { Promise<{json: any, params}> } */ kickGroupMember(params) { return request(`groups/${params.groupId}/members/${params.userId}`, { @@ -486,7 +444,7 @@ const groupReq = { }, /** * @param {{ groupId: string, userId: string }} params - * @return { Promise<{json: any, params}> } + * @returns { Promise<{json: any, params}> } */ banGroupMember(params) { return request(`groups/${params.groupId}/bans`, { @@ -517,7 +475,7 @@ const groupReq = { }, /** * @param {{ groupId: string, userId: string }} params - * @return { Promise<{json: any, params}> } + * @returns { Promise<{json: any, params}> } */ deleteSentGroupInvite(params) { return request(`groups/${params.groupId}/invites/${params.userId}`, { @@ -601,7 +559,7 @@ const groupReq = { }, /** * @param {{ groupId: string }} params - * @return { Promise<{json: any, params}> } + * @returns { Promise<{json: any, params}> } */ getGroupAuditLogTypes(params) { return request(`groups/${params.groupId}/auditLogTypes`, { @@ -615,8 +573,8 @@ const groupReq = { }); }, /** - * @param {{ groupId: string, n: number, offset: number, eventTypes?: array }} params - * @return { Promise<{json: any, params}> } + * @param {{groupId: string, n: number, offset: number, eventTypes?: Array}} params + * @returns { Promise<{json: any, params}> } */ getGroupLogs(params) { return request(`groups/${params.groupId}/auditLogs`, { @@ -632,7 +590,7 @@ const groupReq = { }, /** * @param {{ groupId: string }} params - * @return { Promise<{json: any, params}> } + * @returns { Promise<{json: any, params}> } */ getGroupInvites(params) { return request(`groups/${params.groupId}/invites`, { @@ -648,7 +606,7 @@ const groupReq = { }, /** * @param {{ groupId: string }} params - * @return { Promise<{json: any, params}> } + * @returns { Promise<{json: any, params}> } */ getGroupJoinRequests(params) { return request(`groups/${params.groupId}/requests`, { @@ -664,7 +622,7 @@ const groupReq = { }, /** * @param {{ groupId: string }} params - * @return { Promise<{json: any, params}> } + * @returns { Promise<{json: any, params}> } */ getGroupInstances(params) { return request( @@ -682,7 +640,7 @@ const groupReq = { }, /** * @param {{ groupId: string }} params - * @return { Promise<{json: any, params}> } + * @returns { Promise<{json: any, params}> } */ getGroupRoles(params) { return request(`groups/${params.groupId}/roles`, { @@ -715,7 +673,7 @@ const groupReq = { order: string, sortBy: string }} params - * @return { Promise<{json: any, params}> } + * @returns { Promise<{json: any, params}> } */ groupSearch(params) { return request(`groups`, { @@ -736,7 +694,7 @@ const groupReq = { n: number, offset: number }} params - * @return { Promise<{json: any, params}> } + * @returns { Promise<{json: any, params}> } */ getGroupGallery(params) { return request( @@ -756,16 +714,6 @@ const groupReq = { return args; }); }, - getCachedGroupGallery(params) { - return fetchWithEntityPolicy({ - queryKey: queryKeys.groupGallery(params), - policy: entityQueryPolicies.groupCollection, - queryFn: () => groupReq.getGroupGallery(params) - }).then(({ data, cache }) => ({ - ...data, - cache - })); - }, getGroupCalendar(groupId) { return request(`calendar/${groupId}`, { @@ -780,23 +728,13 @@ const groupReq = { return args; }); }, - getCachedGroupCalendar(groupId) { - return fetchWithEntityPolicy({ - queryKey: queryKeys.groupCalendar(groupId), - policy: entityQueryPolicies.groupCollection, - queryFn: () => groupReq.getGroupCalendar(groupId) - }).then(({ data, cache }) => ({ - ...data, - cache - })); - }, /** * @param {{ groupId: string, eventId: string }} params - * @return { Promise<{json: any, params}> } + * @returns { Promise<{json: any, params}> } */ getGroupCalendarEvent(params) { return request(`calendar/${params.groupId}/${params.eventId}`, { @@ -809,17 +747,6 @@ const groupReq = { return args; }); }, - getCachedGroupCalendarEvent(params) { - return fetchWithEntityPolicy({ - queryKey: queryKeys.groupCalendarEvent(params), - policy: entityQueryPolicies.groupCollection, - queryFn: () => groupReq.getGroupCalendarEvent(params) - }).then(({ data, cache }) => ({ - ...data, - cache - })); - }, - /** * @type {import('../types/api/group').GetCalendars} */ diff --git a/src/api/index.js b/src/api/index.js index a06b2bff..8a9f26ba 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -19,6 +19,7 @@ import miscRequest from './misc'; import notificationRequest from './notification'; import playerModerationRequest from './playerModeration'; import propRequest from './prop'; +import queryRequest from './queryRequest'; import userRequest from './user'; import vrcPlusIconRequest from './vrcPlusIcon'; import vrcPlusImageRequest from './vrcPlusImage'; @@ -43,7 +44,8 @@ window.request = { groupRequest, inventoryRequest, propRequest, - imageRequest + imageRequest, + queryRequest }; export { @@ -65,5 +67,6 @@ export { groupRequest, inventoryRequest, propRequest, - imageRequest + imageRequest, + queryRequest }; diff --git a/src/api/instance.js b/src/api/instance.js index baeb79ac..682380a7 100644 --- a/src/api/instance.js +++ b/src/api/instance.js @@ -3,12 +3,6 @@ import { toast } from 'vue-sonner'; import { i18n } from '../plugin/i18n'; import { request } from '../service/request'; import { useInstanceStore } from '../stores'; -import { - entityQueryPolicies, - fetchWithEntityPolicy, - patchAndRefetchActiveQuery, - queryKeys -} from '../queries'; const instanceReq = { /** @@ -28,21 +22,6 @@ const instanceReq = { }); }, - /** - * @param {{worldId: string, instanceId: string}} params - * @returns {Promise<{json: any, ref: any, cache?: boolean, params}>} - */ - getCachedInstance(params) { - return fetchWithEntityPolicy({ - queryKey: queryKeys.instance(params.worldId, params.instanceId), - policy: entityQueryPolicies.instance, - queryFn: () => instanceReq.getInstance(params) - }).then(({ data, cache }) => ({ - ...data, - cache - })); - }, - /** * @type {import('../types/api/instance').CreateInstance} */ @@ -57,15 +36,6 @@ const instanceReq = { params }; args.ref = instanceStore.applyInstance(json); - patchAndRefetchActiveQuery({ - queryKey: queryKeys.instance(args.ref.worldId, args.ref.instanceId), - nextData: args - }).catch((err) => { - console.error( - 'Failed to refresh instance query after instance creation:', - err - ); - }); return args; }); }, @@ -108,15 +78,6 @@ const instanceReq = { params }; args.ref = instanceStore.applyInstance(json); - patchAndRefetchActiveQuery({ - queryKey: queryKeys.instance(args.ref.worldId, args.ref.instanceId), - nextData: args - }).catch((err) => { - console.error( - 'Failed to refresh instance query after short-name resolve:', - err - ); - }); return args; }); }, diff --git a/src/api/inventory.js b/src/api/inventory.js index 2b9a61da..5318290a 100644 --- a/src/api/inventory.js +++ b/src/api/inventory.js @@ -1,11 +1,9 @@ +import { queryClient } from '../queries'; import { request } from '../service/request'; -import { - entityQueryPolicies, - fetchWithEntityPolicy, - queryClient, - queryKeys -} from '../queries'; +/** + * + */ function refetchActiveInventoryQueries() { queryClient .invalidateQueries({ @@ -37,17 +35,6 @@ const inventoryReq = { }); }, - getCachedUserInventoryItem(params) { - return fetchWithEntityPolicy({ - queryKey: queryKeys.userInventoryItem(params), - policy: entityQueryPolicies.inventoryCollection, - queryFn: () => inventoryReq.getUserInventoryItem(params) - }).then(({ data, cache }) => ({ - ...data, - cache - })); - }, - /** * @param {{ inventoryId: string }} params * @returns {Promise<{json: any, params}>} @@ -82,17 +69,6 @@ const inventoryReq = { }); }, - getCachedInventoryItems(params) { - return fetchWithEntityPolicy({ - queryKey: queryKeys.inventoryItems(params), - policy: entityQueryPolicies.inventoryCollection, - queryFn: () => inventoryReq.getInventoryItems(params) - }).then(({ data, cache }) => ({ - ...data, - cache - })); - }, - /** * @param {{ inventoryId: string }} params * @returns {Promise<{json: any, params}>} diff --git a/src/api/misc.js b/src/api/misc.js index 3c2d601f..510bbfc6 100644 --- a/src/api/misc.js +++ b/src/api/misc.js @@ -1,12 +1,10 @@ +import { queryClient, queryKeys } from '../queries'; import { request } from '../service/request'; import { useUserStore } from '../stores'; -import { - entityQueryPolicies, - fetchWithEntityPolicy, - queryClient, - queryKeys -} from '../queries'; +/** + * + */ function getCurrentUserId() { return useUserStore().currentUser.id; } @@ -24,17 +22,6 @@ const miscReq = { }); }, - getCachedFile(params) { - return fetchWithEntityPolicy({ - queryKey: queryKeys.file(params.fileId), - policy: entityQueryPolicies.fileObject, - queryFn: () => miscReq.getFile(params) - }).then(({ data, cache }) => ({ - ...data, - cache - })); - }, - saveNote(params) { return request('userNotes', { method: 'POST', @@ -55,7 +42,7 @@ const miscReq = { * reason: string, * type: string * }} params - * @return { Promise<{json: any, params}> } + * @returns { Promise<{json: any, params}> } */ reportUser(params) { return request(`feedback/${params.userId}/user`, { @@ -80,7 +67,7 @@ const miscReq = { * version: number, * variant: string * }} params - * @return { Promise<{json: any, params}> } + * @returns { Promise<{json: any, params}> } */ getFileAnalysis(params) { return request( @@ -218,6 +205,7 @@ const miscReq = { }, /** + * @param params * @params {{ userId: string, emojiId: string diff --git a/src/api/queryRequest.js b/src/api/queryRequest.js new file mode 100644 index 00000000..d197945f --- /dev/null +++ b/src/api/queryRequest.js @@ -0,0 +1,163 @@ +import { + entityQueryPolicies, + fetchWithEntityPolicy, + queryKeys +} from '../queries'; + +import avatarRequest from './avatar'; +import favoriteRequest from './favorite'; +import friendRequest from './friend'; +import groupRequest from './group'; +import inventoryRequest from './inventory'; +import miscRequest from './misc'; +import userRequest from './user'; +import vrcPlusIconRequest from './vrcPlusIcon'; +import vrcPlusImageRequest from './vrcPlusImage'; +import worldRequest from './world'; + +const registry = Object.freeze({ + user: { + key: (params) => queryKeys.user(params.userId), + policy: entityQueryPolicies.user, + queryFn: (params) => userRequest.getUser(params) + }, + avatar: { + key: (params) => queryKeys.avatar(params.avatarId), + policy: entityQueryPolicies.avatar, + queryFn: (params) => avatarRequest.getAvatar(params) + }, + world: { + key: (params) => queryKeys.world(params.worldId), + policy: entityQueryPolicies.world, + queryFn: (params) => worldRequest.getWorld(params) + }, + worldsByUser: { + key: (params) => queryKeys.worldsByUser(params), + policy: entityQueryPolicies.worldCollection, + queryFn: (params) => + worldRequest.getWorlds(params, params.option || undefined) + }, + group: { + key: (params) => queryKeys.group(params.groupId, params.includeRoles), + policy: entityQueryPolicies.group, + queryFn: (params) => groupRequest.getGroup(params) + }, + groupPosts: { + key: (params) => queryKeys.groupPosts(params), + policy: entityQueryPolicies.groupCollection, + queryFn: (params) => groupRequest.getGroupPosts(params) + }, + groupMember: { + key: (params) => queryKeys.groupMember(params), + policy: entityQueryPolicies.groupCollection, + queryFn: (params) => groupRequest.getGroupMember(params) + }, + groupMembers: { + key: (params) => queryKeys.groupMembers(params), + policy: entityQueryPolicies.groupCollection, + queryFn: (params) => groupRequest.getGroupMembers(params) + }, + groupGallery: { + key: (params) => queryKeys.groupGallery(params), + policy: entityQueryPolicies.groupCollection, + queryFn: (params) => groupRequest.getGroupGallery(params) + }, + groupCalendar: { + key: (params) => queryKeys.groupCalendar(params.groupId), + policy: entityQueryPolicies.groupCollection, + queryFn: (params) => groupRequest.getGroupCalendar(params.groupId) + }, + groupCalendarEvent: { + key: (params) => queryKeys.groupCalendarEvent(params), + policy: entityQueryPolicies.groupCollection, + queryFn: (params) => groupRequest.getGroupCalendarEvent(params) + }, + friends: { + key: (params) => queryKeys.friends(params), + policy: entityQueryPolicies.friendList, + queryFn: (params) => friendRequest.getFriends(params) + }, + favoriteLimits: { + key: () => queryKeys.favoriteLimits(), + policy: entityQueryPolicies.favoriteCollection, + queryFn: () => favoriteRequest.getFavoriteLimits() + }, + favorites: { + key: (params) => queryKeys.favorites(params), + policy: entityQueryPolicies.favoriteCollection, + queryFn: (params) => favoriteRequest.getFavorites(params) + }, + favoriteGroups: { + key: (params) => queryKeys.favoriteGroups(params), + policy: entityQueryPolicies.favoriteCollection, + queryFn: (params) => favoriteRequest.getFavoriteGroups(params) + }, + favoriteWorlds: { + key: (params) => queryKeys.favoriteWorlds(params), + policy: entityQueryPolicies.favoriteCollection, + queryFn: (params) => favoriteRequest.getFavoriteWorlds(params) + }, + favoriteAvatars: { + key: (params) => queryKeys.favoriteAvatars(params), + policy: entityQueryPolicies.favoriteCollection, + queryFn: (params) => favoriteRequest.getFavoriteAvatars(params) + }, + galleryFiles: { + key: (params) => queryKeys.galleryFiles(params), + policy: entityQueryPolicies.galleryCollection, + queryFn: (params) => vrcPlusIconRequest.getFileList(params) + }, + prints: { + key: (params) => queryKeys.prints(params), + policy: entityQueryPolicies.galleryCollection, + queryFn: (params) => vrcPlusImageRequest.getPrints(params) + }, + print: { + key: (params) => queryKeys.print(params.printId), + policy: entityQueryPolicies.galleryCollection, + queryFn: (params) => vrcPlusImageRequest.getPrint(params) + }, + userInventoryItem: { + key: (params) => queryKeys.userInventoryItem(params), + policy: entityQueryPolicies.inventoryCollection, + queryFn: (params) => inventoryRequest.getUserInventoryItem(params) + }, + inventoryItems: { + key: (params) => queryKeys.inventoryItems(params), + policy: entityQueryPolicies.inventoryCollection, + queryFn: (params) => inventoryRequest.getInventoryItems(params) + }, + file: { + key: (params) => queryKeys.file(params.fileId), + policy: entityQueryPolicies.fileObject, + queryFn: (params) => miscRequest.getFile(params) + } +}); + +const queryRequest = { + /** + * @template T + * @param {keyof typeof registry} resource + * @param {any} [params] + * @returns {Promise} + */ + async fetch(resource, params = {}) { + const entry = registry[resource]; + if (!entry) { + throw new Error(`Unknown query resource: ${String(resource)}`); + } + + const { data, cache } = await fetchWithEntityPolicy({ + queryKey: entry.key(params), + policy: entry.policy, + queryFn: () => entry.queryFn(params) + }); + + return { + ...data, + cache + }; + } +}; + +export default queryRequest; diff --git a/src/api/user.js b/src/api/user.js index 2f96bf03..b59ac367 100644 --- a/src/api/user.js +++ b/src/api/user.js @@ -1,11 +1,6 @@ +import { patchAndRefetchActiveQuery, queryKeys } from '../queries'; import { request } from '../service/request'; import { useUserStore } from '../stores'; -import { - entityQueryPolicies, - fetchWithEntityPolicy, - patchAndRefetchActiveQuery, - queryKeys -} from '../queries'; /** * @returns {string} @@ -40,21 +35,6 @@ const userReq = { }); }, - /** - * Fetch user from cache if they're in it. Otherwise, calls API. - * @type {import('../types/api/user').GetCachedUser} - */ - getCachedUser(params) { - return fetchWithEntityPolicy({ - queryKey: queryKeys.user(params.userId), - policy: entityQueryPolicies.user, - queryFn: () => userReq.getUser(params) - }).then(({ data, cache }) => ({ - ...data, - cache - })); - }, - /** * @type {import('../types/api/user').GetUsers} */ @@ -147,7 +127,10 @@ const userReq = { queryKey: queryKeys.user(args.ref.id), nextData: args }).catch((err) => { - console.error('Failed to refresh user query after mutation:', err); + console.error( + 'Failed to refresh user query after mutation:', + err + ); }); return args; }); diff --git a/src/api/vrcPlusIcon.js b/src/api/vrcPlusIcon.js index ddd9c114..f7f5e02f 100644 --- a/src/api/vrcPlusIcon.js +++ b/src/api/vrcPlusIcon.js @@ -1,11 +1,9 @@ +import { queryClient } from '../queries'; import { request } from '../service/request'; -import { - entityQueryPolicies, - fetchWithEntityPolicy, - queryClient, - queryKeys -} from '../queries'; +/** + * + */ function refetchActiveGalleryQueries() { queryClient .invalidateQueries({ @@ -31,17 +29,6 @@ const VRCPlusIconsReq = { }); }, - getCachedFileList(params) { - return fetchWithEntityPolicy({ - queryKey: queryKeys.galleryFiles(params), - policy: entityQueryPolicies.galleryCollection, - queryFn: () => VRCPlusIconsReq.getFileList(params) - }).then(({ data, cache }) => ({ - ...data, - cache - })); - }, - deleteFile(fileId) { return request(`file/${fileId}`, { method: 'DELETE' diff --git a/src/api/vrcPlusImage.js b/src/api/vrcPlusImage.js index 88596972..330cab9a 100644 --- a/src/api/vrcPlusImage.js +++ b/src/api/vrcPlusImage.js @@ -1,16 +1,17 @@ +import { queryClient } from '../queries'; import { request } from '../service/request'; import { useUserStore } from '../stores'; -import { - entityQueryPolicies, - fetchWithEntityPolicy, - queryClient, - queryKeys -} from '../queries'; +/** + * + */ function getCurrentUserId() { return useUserStore().currentUser.id; } +/** + * + */ function refetchActiveGalleryQueries() { queryClient .invalidateQueries({ @@ -70,17 +71,6 @@ const vrcPlusImageReq = { }); }, - getCachedPrints(params) { - return fetchWithEntityPolicy({ - queryKey: queryKeys.prints(params), - policy: entityQueryPolicies.galleryCollection, - queryFn: () => vrcPlusImageReq.getPrints(params) - }).then(({ data, cache }) => ({ - ...data, - cache - })); - }, - deletePrint(printId) { return request(`prints/${printId}`, { method: 'DELETE' @@ -122,17 +112,6 @@ const vrcPlusImageReq = { }); }, - getCachedPrint(params) { - return fetchWithEntityPolicy({ - queryKey: queryKeys.print(params.printId), - policy: entityQueryPolicies.galleryCollection, - queryFn: () => vrcPlusImageReq.getPrint(params) - }).then(({ data, cache }) => ({ - ...data, - cache - })); - }, - uploadEmoji(imageData, params) { return request('file/image', { uploadImage: true, diff --git a/src/api/world.js b/src/api/world.js index c01f8c1c..89189595 100644 --- a/src/api/world.js +++ b/src/api/world.js @@ -1,11 +1,6 @@ +import { patchAndRefetchActiveQuery, queryKeys } from '../queries'; import { request } from '../service/request'; import { useWorldStore } from '../stores'; -import { - entityQueryPolicies, - fetchWithEntityPolicy, - patchAndRefetchActiveQuery, - queryKeys -} from '../queries'; const worldReq = { /** @@ -25,21 +20,6 @@ const worldReq = { }); }, - /** - * @param {{worldId: string}} params - * @returns {Promise<{json: any, ref: any, cache?: boolean, params}>} - */ - getCachedWorld(params) { - return fetchWithEntityPolicy({ - queryKey: queryKeys.world(params.worldId), - policy: entityQueryPolicies.world, - queryFn: () => worldReq.getWorld(params) - }).then(({ data, cache }) => ({ - ...data, - cache - })); - }, - /** * @type {import('../types/api/world').GetWorlds} */ @@ -64,24 +44,6 @@ const worldReq = { return args; }); }, - /** - * @param {object} params - * @param {string} [option] - * @returns {Promise<{json: any, cache?: boolean, params: any, option?: string}>} - */ - getCachedWorlds(params, option) { - return fetchWithEntityPolicy({ - queryKey: queryKeys.worldsByUser({ - ...params, - option: option || '' - }), - policy: entityQueryPolicies.worldCollection, - queryFn: () => worldReq.getWorlds(params, option) - }).then(({ data, cache }) => ({ - ...data, - cache - })); - }, /** * @param {{worldId: string}} params * @returns {Promise<{json: any, params}>} @@ -116,7 +78,10 @@ const worldReq = { queryKey: queryKeys.world(args.ref.id), nextData: args }).catch((err) => { - console.error('Failed to refresh world query after mutation:', err); + console.error( + 'Failed to refresh world query after mutation:', + err + ); }); return args; }); @@ -141,7 +106,10 @@ const worldReq = { queryKey: queryKeys.world(args.ref.id), nextData: args }).catch((err) => { - console.error('Failed to refresh world query after publish:', err); + console.error( + 'Failed to refresh world query after publish:', + err + ); }); return args; }); @@ -166,7 +134,10 @@ const worldReq = { queryKey: queryKeys.world(args.ref.id), nextData: args }).catch((err) => { - console.error('Failed to refresh world query after unpublish:', err); + console.error( + 'Failed to refresh world query after unpublish:', + err + ); }); return args; }); diff --git a/src/components/DisplayName.vue b/src/components/DisplayName.vue index cd98b84c..2eea3781 100644 --- a/src/components/DisplayName.vue +++ b/src/components/DisplayName.vue @@ -5,8 +5,8 @@