| 12345678910111213141516171819202122232425262728293031323334353637 |
- // noinspection JSCheckFunctionSignatures
- export const characterQueryKeys = {
- root: ["characterList"],
- options: () => [...characterQueryKeys.root, "options"],
- byId: (id) => ["character", id]
- }
- export const characterListQuery = defineQueryOptions({
- key: characterQueryKeys.root,
- query: () => useEmit("character:list")
- })
- export const characterOptionsQuery = defineQueryOptions({
- key: characterQueryKeys.options,
- query: () => useEmit("character:options")
- })
- export const characterByIdQuery = defineQueryOptions((id) => ({
- key: characterQueryKeys.byId(id),
- query: async () => {
- const { data: characterList } = await usePrefetchCharacterList()
- if (_isNil(characterList) || _isEmpty(characterList)) {
- throw new QueryError("error fetching characterList", { key: characterQueryKeys.byId(id) })
- }
- const character = _find(characterList, { id })
- if (_isNil(character)) {
- throw new QueryError(`character with id ${id} not found`, { key: characterQueryKeys.byId(id) })
- }
- return character
- }
- }))
|