profiles.ts•10 kB
/**
* Generated by orval v7.2.0 🍺
* Do not edit manually.
* storyden
* Storyden social API for building community driven platforms.
The Storyden API does not adhere to semantic versioning but instead applies a rolling strategy with deprecations and minimal breaking changes. This has been done mainly for a simpler development process and it may be changed to a more fixed versioning strategy in the future. Ultimately, the primary way Storyden tracks versions is dates, there are no set release tags currently.
* OpenAPI spec version: v1.25.8-canary
*/
import useSwr from "swr";
import type { Arguments, Key, SWRConfiguration } from "swr";
import useSWRMutation from "swr/mutation";
import type { SWRMutationConfiguration } from "swr/mutation";
import { fetcher } from "../client";
import type {
InternalServerErrorResponse,
NotFoundResponse,
NotModifiedResponse,
ProfileFollowersGetOKResponse,
ProfileFollowersGetParams,
ProfileFollowingGetOKResponse,
ProfileFollowingGetParams,
ProfileGetOKResponse,
ProfileListOKResponse,
ProfileListParams,
UnauthorisedResponse,
} from "../openapi-schema";
/**
* Query and search profiles.
*/
export const profileList = (params?: ProfileListParams) => {
return fetcher<ProfileListOKResponse>({
url: `/profiles`,
method: "GET",
params,
});
};
export const getProfileListKey = (params?: ProfileListParams) =>
[`/profiles`, ...(params ? [params] : [])] as const;
export type ProfileListQueryResult = NonNullable<
Awaited<ReturnType<typeof profileList>>
>;
export type ProfileListQueryError =
| UnauthorisedResponse
| NotFoundResponse
| InternalServerErrorResponse;
export const useProfileList = <
TError =
| UnauthorisedResponse
| NotFoundResponse
| InternalServerErrorResponse,
>(
params?: ProfileListParams,
options?: {
swr?: SWRConfiguration<Awaited<ReturnType<typeof profileList>>, TError> & {
swrKey?: Key;
enabled?: boolean;
};
},
) => {
const { swr: swrOptions } = options ?? {};
const isEnabled = swrOptions?.enabled !== false;
const swrKey =
swrOptions?.swrKey ??
(() => (isEnabled ? getProfileListKey(params) : null));
const swrFn = () => profileList(params);
const query = useSwr<Awaited<ReturnType<typeof swrFn>>, TError>(
swrKey,
swrFn,
swrOptions,
);
return {
swrKey,
...query,
};
};
/**
* Get a public profile by ID.
*/
export const profileGet = (accountHandle: string) => {
return fetcher<ProfileGetOKResponse>({
url: `/profiles/${accountHandle}`,
method: "GET",
});
};
export const getProfileGetKey = (accountHandle: string) =>
[`/profiles/${accountHandle}`] as const;
export type ProfileGetQueryResult = NonNullable<
Awaited<ReturnType<typeof profileGet>>
>;
export type ProfileGetQueryError =
| NotModifiedResponse
| UnauthorisedResponse
| NotFoundResponse
| InternalServerErrorResponse;
export const useProfileGet = <
TError =
| NotModifiedResponse
| UnauthorisedResponse
| NotFoundResponse
| InternalServerErrorResponse,
>(
accountHandle: string,
options?: {
swr?: SWRConfiguration<Awaited<ReturnType<typeof profileGet>>, TError> & {
swrKey?: Key;
enabled?: boolean;
};
},
) => {
const { swr: swrOptions } = options ?? {};
const isEnabled = swrOptions?.enabled !== false && !!accountHandle;
const swrKey =
swrOptions?.swrKey ??
(() => (isEnabled ? getProfileGetKey(accountHandle) : null));
const swrFn = () => profileGet(accountHandle);
const query = useSwr<Awaited<ReturnType<typeof swrFn>>, TError>(
swrKey,
swrFn,
swrOptions,
);
return {
swrKey,
...query,
};
};
/**
* Get the followers and following details for a profile.
*/
export const profileFollowersGet = (
accountHandle: string,
params?: ProfileFollowersGetParams,
) => {
return fetcher<ProfileFollowersGetOKResponse>({
url: `/profiles/${accountHandle}/followers`,
method: "GET",
params,
});
};
export const getProfileFollowersGetKey = (
accountHandle: string,
params?: ProfileFollowersGetParams,
) =>
[
`/profiles/${accountHandle}/followers`,
...(params ? [params] : []),
] as const;
export type ProfileFollowersGetQueryResult = NonNullable<
Awaited<ReturnType<typeof profileFollowersGet>>
>;
export type ProfileFollowersGetQueryError =
| UnauthorisedResponse
| NotFoundResponse
| InternalServerErrorResponse;
export const useProfileFollowersGet = <
TError =
| UnauthorisedResponse
| NotFoundResponse
| InternalServerErrorResponse,
>(
accountHandle: string,
params?: ProfileFollowersGetParams,
options?: {
swr?: SWRConfiguration<
Awaited<ReturnType<typeof profileFollowersGet>>,
TError
> & { swrKey?: Key; enabled?: boolean };
},
) => {
const { swr: swrOptions } = options ?? {};
const isEnabled = swrOptions?.enabled !== false && !!accountHandle;
const swrKey =
swrOptions?.swrKey ??
(() =>
isEnabled ? getProfileFollowersGetKey(accountHandle, params) : null);
const swrFn = () => profileFollowersGet(accountHandle, params);
const query = useSwr<Awaited<ReturnType<typeof swrFn>>, TError>(
swrKey,
swrFn,
swrOptions,
);
return {
swrKey,
...query,
};
};
/**
* Follow the specified profile as the authenticated account.
*/
export const profileFollowersAdd = (accountHandle: string) => {
return fetcher<void>({
url: `/profiles/${accountHandle}/followers`,
method: "PUT",
});
};
export const getProfileFollowersAddMutationFetcher = (
accountHandle: string,
) => {
return (_: Key, __: { arg: Arguments }): Promise<void> => {
return profileFollowersAdd(accountHandle);
};
};
export const getProfileFollowersAddMutationKey = (accountHandle: string) =>
[`/profiles/${accountHandle}/followers`] as const;
export type ProfileFollowersAddMutationResult = NonNullable<
Awaited<ReturnType<typeof profileFollowersAdd>>
>;
export type ProfileFollowersAddMutationError =
| UnauthorisedResponse
| NotFoundResponse
| InternalServerErrorResponse;
export const useProfileFollowersAdd = <
TError =
| UnauthorisedResponse
| NotFoundResponse
| InternalServerErrorResponse,
>(
accountHandle: string,
options?: {
swr?: SWRMutationConfiguration<
Awaited<ReturnType<typeof profileFollowersAdd>>,
TError,
Key,
Arguments,
Awaited<ReturnType<typeof profileFollowersAdd>>
> & { swrKey?: string };
},
) => {
const { swr: swrOptions } = options ?? {};
const swrKey =
swrOptions?.swrKey ?? getProfileFollowersAddMutationKey(accountHandle);
const swrFn = getProfileFollowersAddMutationFetcher(accountHandle);
const query = useSWRMutation(swrKey, swrFn, swrOptions);
return {
swrKey,
...query,
};
};
/**
* Unfollow the specified profile as the authenticated account.
*/
export const profileFollowersRemove = (accountHandle: string) => {
return fetcher<void>({
url: `/profiles/${accountHandle}/followers`,
method: "DELETE",
});
};
export const getProfileFollowersRemoveMutationFetcher = (
accountHandle: string,
) => {
return (_: Key, __: { arg: Arguments }): Promise<void> => {
return profileFollowersRemove(accountHandle);
};
};
export const getProfileFollowersRemoveMutationKey = (accountHandle: string) =>
[`/profiles/${accountHandle}/followers`] as const;
export type ProfileFollowersRemoveMutationResult = NonNullable<
Awaited<ReturnType<typeof profileFollowersRemove>>
>;
export type ProfileFollowersRemoveMutationError =
| UnauthorisedResponse
| NotFoundResponse
| InternalServerErrorResponse;
export const useProfileFollowersRemove = <
TError =
| UnauthorisedResponse
| NotFoundResponse
| InternalServerErrorResponse,
>(
accountHandle: string,
options?: {
swr?: SWRMutationConfiguration<
Awaited<ReturnType<typeof profileFollowersRemove>>,
TError,
Key,
Arguments,
Awaited<ReturnType<typeof profileFollowersRemove>>
> & { swrKey?: string };
},
) => {
const { swr: swrOptions } = options ?? {};
const swrKey =
swrOptions?.swrKey ?? getProfileFollowersRemoveMutationKey(accountHandle);
const swrFn = getProfileFollowersRemoveMutationFetcher(accountHandle);
const query = useSWRMutation(swrKey, swrFn, swrOptions);
return {
swrKey,
...query,
};
};
/**
* Get the profiles that this account is following.
*/
export const profileFollowingGet = (
accountHandle: string,
params?: ProfileFollowingGetParams,
) => {
return fetcher<ProfileFollowingGetOKResponse>({
url: `/profiles/${accountHandle}/following`,
method: "GET",
params,
});
};
export const getProfileFollowingGetKey = (
accountHandle: string,
params?: ProfileFollowingGetParams,
) =>
[
`/profiles/${accountHandle}/following`,
...(params ? [params] : []),
] as const;
export type ProfileFollowingGetQueryResult = NonNullable<
Awaited<ReturnType<typeof profileFollowingGet>>
>;
export type ProfileFollowingGetQueryError =
| NotModifiedResponse
| UnauthorisedResponse
| NotFoundResponse
| InternalServerErrorResponse;
export const useProfileFollowingGet = <
TError =
| NotModifiedResponse
| UnauthorisedResponse
| NotFoundResponse
| InternalServerErrorResponse,
>(
accountHandle: string,
params?: ProfileFollowingGetParams,
options?: {
swr?: SWRConfiguration<
Awaited<ReturnType<typeof profileFollowingGet>>,
TError
> & { swrKey?: Key; enabled?: boolean };
},
) => {
const { swr: swrOptions } = options ?? {};
const isEnabled = swrOptions?.enabled !== false && !!accountHandle;
const swrKey =
swrOptions?.swrKey ??
(() =>
isEnabled ? getProfileFollowingGetKey(accountHandle, params) : null);
const swrFn = () => profileFollowingGet(accountHandle, params);
const query = useSwr<Awaited<ReturnType<typeof swrFn>>, TError>(
swrKey,
swrFn,
swrOptions,
);
return {
swrKey,
...query,
};
};