Skip to content

Commit

Permalink
feat: partial arguments for generated hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
dalechyn committed Jan 30, 2024
1 parent 2d03f69 commit f183560
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 214 deletions.
8 changes: 8 additions & 0 deletions .changeset/stupid-sheep-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"wagemos-cosmoskit-nextjs": patch
"wagemos-graz-nextjs": patch
"@abstract-money/cli": patch
"@abstract-money/react": patch
---

Partial arguments for generated hooks
Original file line number Diff line number Diff line change
Expand Up @@ -41,87 +41,14 @@ export const bettingQueryKeys = {
args
}] as const)
};
export const bettingQueries = {
round: <TData = RoundResponse,>({
client,
args,
options
}: BettingRoundQuery<TData>): UseQueryOptions<RoundResponse, Error, TData> => ({
queryKey: bettingQueryKeys.round(client?.moduleId, args),
queryFn: () => client ? client.round({
roundId: args.roundId
}) : Promise.reject(new Error("Invalid client")),
...options,
enabled: !!client && (options?.enabled != undefined ? options.enabled : true)
}),
listRounds: <TData = RoundsResponse,>({
client,
args,
options
}: BettingListRoundsQuery<TData>): UseQueryOptions<RoundsResponse, Error, TData> => ({
queryKey: bettingQueryKeys.listRounds(client?.moduleId, args),
queryFn: () => client ? client.listRounds({
limit: args.limit,
startAfter: args.startAfter
}) : Promise.reject(new Error("Invalid client")),
...options,
enabled: !!client && (options?.enabled != undefined ? options.enabled : true)
}),
odds: <TData = OddsResponse,>({
client,
args,
options
}: BettingOddsQuery<TData>): UseQueryOptions<OddsResponse, Error, TData> => ({
queryKey: bettingQueryKeys.odds(client?.moduleId, args),
queryFn: () => client ? client.odds({
roundId: args.roundId,
teamId: args.teamId
}) : Promise.reject(new Error("Invalid client")),
...options,
enabled: !!client && (options?.enabled != undefined ? options.enabled : true)
}),
listOdds: <TData = ListOddsResponse,>({
client,
args,
options
}: BettingListOddsQuery<TData>): UseQueryOptions<ListOddsResponse, Error, TData> => ({
queryKey: bettingQueryKeys.listOdds(client?.moduleId, args),
queryFn: () => client ? client.listOdds({
roundId: args.roundId
}) : Promise.reject(new Error("Invalid client")),
...options,
enabled: !!client && (options?.enabled != undefined ? options.enabled : true)
}),
config: <TData = ConfigResponse,>({
client,
options
}: BettingConfigQuery<TData>): UseQueryOptions<ConfigResponse, Error, TData> => ({
queryKey: bettingQueryKeys.config(client?.moduleId),
queryFn: () => client ? client.config() : Promise.reject(new Error("Invalid client")),
...options,
enabled: !!client && (options?.enabled != undefined ? options.enabled : true)
}),
bets: <TData = BetsResponse,>({
client,
args,
options
}: BettingBetsQuery<TData>): UseQueryOptions<BetsResponse, Error, TData> => ({
queryKey: bettingQueryKeys.bets(client?.moduleId, args),
queryFn: () => client ? client.bets({
roundId: args.roundId
}) : Promise.reject(new Error("Invalid client")),
...options,
enabled: !!client && (options?.enabled != undefined ? options.enabled : true)
})
};
export interface BettingReactQuery<TResponse, TData = TResponse> {
client: BettingAppQueryClient | undefined;
options?: Omit<UseQueryOptions<TResponse, Error, TData>, "'queryKey' | 'queryFn' | 'initialData'"> & {
initialData?: undefined;
};
}
export interface BettingBetsQuery<TData> extends BettingReactQuery<BetsResponse, TData> {
args: {
args: undefined | {
roundId: number;
};
}
Expand All @@ -130,10 +57,9 @@ export function useBettingBetsQuery<TData = BetsResponse>({
args,
options
}: BettingBetsQuery<TData>) {
return useQuery<BetsResponse, Error, TData>(bettingQueryKeys.bets(client?.moduleId, args), () => client ? client.bets({
return useQuery<BetsResponse, Error, TData>(bettingQueryKeys.bets(client?.moduleId, args), () => client && args ? client.bets({
roundId: args.roundId
}) : Promise.reject(new Error("Invalid client")), { ...options,
enabled: !!client && (options?.enabled != undefined ? options.enabled : true)
}) : Promise.reject(new Error("Invalid client or args")), { ...options, enabled: !!args && !!client && (options?.enabled != undefined ? options.enabled : true)
});
}
export interface BettingConfigQuery<TData> extends BettingReactQuery<ConfigResponse, TData> {}
Expand All @@ -146,7 +72,7 @@ export function useBettingConfigQuery<TData = ConfigResponse>({
});
}
export interface BettingListOddsQuery<TData> extends BettingReactQuery<ListOddsResponse, TData> {
args: {
args: undefined | {
roundId: number;
};
}
Expand All @@ -155,14 +81,13 @@ export function useBettingListOddsQuery<TData = ListOddsResponse>({
args,
options
}: BettingListOddsQuery<TData>) {
return useQuery<ListOddsResponse, Error, TData>(bettingQueryKeys.listOdds(client?.moduleId, args), () => client ? client.listOdds({
return useQuery<ListOddsResponse, Error, TData>(bettingQueryKeys.listOdds(client?.moduleId, args), () => client && args ? client.listOdds({
roundId: args.roundId
}) : Promise.reject(new Error("Invalid client")), { ...options,
enabled: !!client && (options?.enabled != undefined ? options.enabled : true)
}) : Promise.reject(new Error("Invalid client or args")), { ...options, enabled: !!args && !!client && (options?.enabled != undefined ? options.enabled : true)
});
}
export interface BettingOddsQuery<TData> extends BettingReactQuery<OddsResponse, TData> {
args: {
args: undefined | {
roundId: number;
teamId: AccountId;
};
Expand All @@ -172,15 +97,14 @@ export function useBettingOddsQuery<TData = OddsResponse>({
args,
options
}: BettingOddsQuery<TData>) {
return useQuery<OddsResponse, Error, TData>(bettingQueryKeys.odds(client?.moduleId, args), () => client ? client.odds({
return useQuery<OddsResponse, Error, TData>(bettingQueryKeys.odds(client?.moduleId, args), () => client && args ? client.odds({
roundId: args.roundId,
teamId: args.teamId
}) : Promise.reject(new Error("Invalid client")), { ...options,
enabled: !!client && (options?.enabled != undefined ? options.enabled : true)
}) : Promise.reject(new Error("Invalid client or args")), { ...options, enabled: !!args && !!client && (options?.enabled != undefined ? options.enabled : true)
});
}
export interface BettingListRoundsQuery<TData> extends BettingReactQuery<RoundsResponse, TData> {
args: {
args: undefined | {
limit?: number;
startAfter?: number;
};
Expand All @@ -190,15 +114,14 @@ export function useBettingListRoundsQuery<TData = RoundsResponse>({
args,
options
}: BettingListRoundsQuery<TData>) {
return useQuery<RoundsResponse, Error, TData>(bettingQueryKeys.listRounds(client?.moduleId, args), () => client ? client.listRounds({
return useQuery<RoundsResponse, Error, TData>(bettingQueryKeys.listRounds(client?.moduleId, args), () => client && args ? client.listRounds({
limit: args.limit,
startAfter: args.startAfter
}) : Promise.reject(new Error("Invalid client")), { ...options,
enabled: !!client && (options?.enabled != undefined ? options.enabled : true)
}) : Promise.reject(new Error("Invalid client or args")), { ...options, enabled: !!args && !!client && (options?.enabled != undefined ? options.enabled : true)
});
}
export interface BettingRoundQuery<TData> extends BettingReactQuery<RoundResponse, TData> {
args: {
args: undefined | {
roundId: number;
};
}
Expand All @@ -207,10 +130,9 @@ export function useBettingRoundQuery<TData = RoundResponse>({
args,
options
}: BettingRoundQuery<TData>) {
return useQuery<RoundResponse, Error, TData>(bettingQueryKeys.round(client?.moduleId, args), () => client ? client.round({
return useQuery<RoundResponse, Error, TData>(bettingQueryKeys.round(client?.moduleId, args), () => client && args ? client.round({
roundId: args.roundId
}) : Promise.reject(new Error("Invalid client")), { ...options,
enabled: !!client && (options?.enabled != undefined ? options.enabled : true)
}) : Promise.reject(new Error("Invalid client or args")), { ...options, enabled: !!args && !!client && (options?.enabled != undefined ? options.enabled : true)
});
}
export interface BettingUpdateConfigMutation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,87 +41,14 @@ export const bettingQueryKeys = {
args
}] as const)
};
export const bettingQueries = {
round: <TData = RoundResponse,>({
client,
args,
options
}: BettingRoundQuery<TData>): UseQueryOptions<RoundResponse, Error, TData> => ({
queryKey: bettingQueryKeys.round(client?.moduleId, args),
queryFn: () => client ? client.round({
roundId: args.roundId
}) : Promise.reject(new Error("Invalid client")),
...options,
enabled: !!client && (options?.enabled != undefined ? options.enabled : true)
}),
listRounds: <TData = RoundsResponse,>({
client,
args,
options
}: BettingListRoundsQuery<TData>): UseQueryOptions<RoundsResponse, Error, TData> => ({
queryKey: bettingQueryKeys.listRounds(client?.moduleId, args),
queryFn: () => client ? client.listRounds({
limit: args.limit,
startAfter: args.startAfter
}) : Promise.reject(new Error("Invalid client")),
...options,
enabled: !!client && (options?.enabled != undefined ? options.enabled : true)
}),
odds: <TData = OddsResponse,>({
client,
args,
options
}: BettingOddsQuery<TData>): UseQueryOptions<OddsResponse, Error, TData> => ({
queryKey: bettingQueryKeys.odds(client?.moduleId, args),
queryFn: () => client ? client.odds({
roundId: args.roundId,
teamId: args.teamId
}) : Promise.reject(new Error("Invalid client")),
...options,
enabled: !!client && (options?.enabled != undefined ? options.enabled : true)
}),
listOdds: <TData = ListOddsResponse,>({
client,
args,
options
}: BettingListOddsQuery<TData>): UseQueryOptions<ListOddsResponse, Error, TData> => ({
queryKey: bettingQueryKeys.listOdds(client?.moduleId, args),
queryFn: () => client ? client.listOdds({
roundId: args.roundId
}) : Promise.reject(new Error("Invalid client")),
...options,
enabled: !!client && (options?.enabled != undefined ? options.enabled : true)
}),
config: <TData = ConfigResponse,>({
client,
options
}: BettingConfigQuery<TData>): UseQueryOptions<ConfigResponse, Error, TData> => ({
queryKey: bettingQueryKeys.config(client?.moduleId),
queryFn: () => client ? client.config() : Promise.reject(new Error("Invalid client")),
...options,
enabled: !!client && (options?.enabled != undefined ? options.enabled : true)
}),
bets: <TData = BetsResponse,>({
client,
args,
options
}: BettingBetsQuery<TData>): UseQueryOptions<BetsResponse, Error, TData> => ({
queryKey: bettingQueryKeys.bets(client?.moduleId, args),
queryFn: () => client ? client.bets({
roundId: args.roundId
}) : Promise.reject(new Error("Invalid client")),
...options,
enabled: !!client && (options?.enabled != undefined ? options.enabled : true)
})
};
export interface BettingReactQuery<TResponse, TData = TResponse> {
client: BettingAppQueryClient | undefined;
options?: Omit<UseQueryOptions<TResponse, Error, TData>, "'queryKey' | 'queryFn' | 'initialData'"> & {
initialData?: undefined;
};
}
export interface BettingBetsQuery<TData> extends BettingReactQuery<BetsResponse, TData> {
args: {
args: undefined | {
roundId: number;
};
}
Expand All @@ -130,10 +57,9 @@ export function useBettingBetsQuery<TData = BetsResponse>({
args,
options
}: BettingBetsQuery<TData>) {
return useQuery<BetsResponse, Error, TData>(bettingQueryKeys.bets(client?.moduleId, args), () => client ? client.bets({
return useQuery<BetsResponse, Error, TData>(bettingQueryKeys.bets(client?.moduleId, args), () => client && args ? client.bets({
roundId: args.roundId
}) : Promise.reject(new Error("Invalid client")), { ...options,
enabled: !!client && (options?.enabled != undefined ? options.enabled : true)
}) : Promise.reject(new Error("Invalid client or args")), { ...options, enabled: !!args && !!client && (options?.enabled != undefined ? options.enabled : true)
});
}
export interface BettingConfigQuery<TData> extends BettingReactQuery<ConfigResponse, TData> {}
Expand All @@ -146,7 +72,7 @@ export function useBettingConfigQuery<TData = ConfigResponse>({
});
}
export interface BettingListOddsQuery<TData> extends BettingReactQuery<ListOddsResponse, TData> {
args: {
args: undefined | {
roundId: number;
};
}
Expand All @@ -155,14 +81,13 @@ export function useBettingListOddsQuery<TData = ListOddsResponse>({
args,
options
}: BettingListOddsQuery<TData>) {
return useQuery<ListOddsResponse, Error, TData>(bettingQueryKeys.listOdds(client?.moduleId, args), () => client ? client.listOdds({
return useQuery<ListOddsResponse, Error, TData>(bettingQueryKeys.listOdds(client?.moduleId, args), () => client && args ? client.listOdds({
roundId: args.roundId
}) : Promise.reject(new Error("Invalid client")), { ...options,
enabled: !!client && (options?.enabled != undefined ? options.enabled : true)
}) : Promise.reject(new Error("Invalid client or args")), { ...options, enabled: !!args && !!client && (options?.enabled != undefined ? options.enabled : true)
});
}
export interface BettingOddsQuery<TData> extends BettingReactQuery<OddsResponse, TData> {
args: {
args: undefined | {
roundId: number;
teamId: AccountId;
};
Expand All @@ -172,15 +97,14 @@ export function useBettingOddsQuery<TData = OddsResponse>({
args,
options
}: BettingOddsQuery<TData>) {
return useQuery<OddsResponse, Error, TData>(bettingQueryKeys.odds(client?.moduleId, args), () => client ? client.odds({
return useQuery<OddsResponse, Error, TData>(bettingQueryKeys.odds(client?.moduleId, args), () => client && args ? client.odds({
roundId: args.roundId,
teamId: args.teamId
}) : Promise.reject(new Error("Invalid client")), { ...options,
enabled: !!client && (options?.enabled != undefined ? options.enabled : true)
}) : Promise.reject(new Error("Invalid client or args")), { ...options, enabled: !!args && !!client && (options?.enabled != undefined ? options.enabled : true)
});
}
export interface BettingListRoundsQuery<TData> extends BettingReactQuery<RoundsResponse, TData> {
args: {
args: undefined | {
limit?: number;
startAfter?: number;
};
Expand All @@ -190,15 +114,14 @@ export function useBettingListRoundsQuery<TData = RoundsResponse>({
args,
options
}: BettingListRoundsQuery<TData>) {
return useQuery<RoundsResponse, Error, TData>(bettingQueryKeys.listRounds(client?.moduleId, args), () => client ? client.listRounds({
return useQuery<RoundsResponse, Error, TData>(bettingQueryKeys.listRounds(client?.moduleId, args), () => client && args ? client.listRounds({
limit: args.limit,
startAfter: args.startAfter
}) : Promise.reject(new Error("Invalid client")), { ...options,
enabled: !!client && (options?.enabled != undefined ? options.enabled : true)
}) : Promise.reject(new Error("Invalid client or args")), { ...options, enabled: !!args && !!client && (options?.enabled != undefined ? options.enabled : true)
});
}
export interface BettingRoundQuery<TData> extends BettingReactQuery<RoundResponse, TData> {
args: {
args: undefined | {
roundId: number;
};
}
Expand All @@ -207,10 +130,9 @@ export function useBettingRoundQuery<TData = RoundResponse>({
args,
options
}: BettingRoundQuery<TData>) {
return useQuery<RoundResponse, Error, TData>(bettingQueryKeys.round(client?.moduleId, args), () => client ? client.round({
return useQuery<RoundResponse, Error, TData>(bettingQueryKeys.round(client?.moduleId, args), () => client && args ? client.round({
roundId: args.roundId
}) : Promise.reject(new Error("Invalid client")), { ...options,
enabled: !!client && (options?.enabled != undefined ? options.enabled : true)
}) : Promise.reject(new Error("Invalid client or args")), { ...options, enabled: !!args && !!client && (options?.enabled != undefined ? options.enabled : true)
});
}
export interface BettingUpdateConfigMutation {
Expand Down
Loading

0 comments on commit f183560

Please sign in to comment.