(
queryInvalidation?: (client: ClientFrom<M>) => QueryInvalidation<M>,
invalidationResources?: InvalidationResourcesFor<M>
)
| 1069 | ) |
| 1070 | return mutations |
| 1071 | } |
| 1072 | |
| 1073 | // make available .query, .suspense and .mutate for each operation |
| 1074 | // and a .helpers with all mutations and queries |
| 1075 | const mapClient = <M extends RequestsAny>( |
| 1076 | queryInvalidation?: (client: ClientFrom<M>) => QueryInvalidation<M>, |
| 1077 | invalidationResources?: InvalidationResourcesFor<M> |
| 1078 | ) => |
| 1079 | ( |
| 1080 | client: ClientFrom<M> |
| 1081 | ) => { |
| 1082 | const Command = useCommand() |
| 1083 | const mutation = useMutation() |
| 1084 | const invalidation = queryInvalidation?.(client) |
| 1085 | const queryResources = makeQueryResources(invalidationResources) |
| 1086 | const extended = Struct.keys(client).reduce( |
| 1087 | (acc, key) => { |
| 1088 | const handler = client[key] |
| 1089 | const requestType = handler.Request.type |
| 1090 | const isStream = handler.Request.stream |
| 1091 | const fn = Command.fn(client[key].id) |
| 1092 | const h_ = handler.handler |
| 1093 | const request = h_ |
| 1094 | ;(acc as any)[key] = Object.assign( |
| 1095 | isQueryHandler(handler) |
| 1096 | ? { |
| 1097 | ...handler, |
| 1098 | request, |
| 1099 | ...queryHelpersFor(handler), |
| 1100 | project: projectQueryFor(handler) |
| 1101 | } |
| 1102 | : isStreamQueryHandler(handler) |
| 1103 | ? { |
| 1104 | ...client[key], |
| 1105 | request, |
| 1106 | ...streamQueryHelpersFor(handler) |
| 1107 | } |
| 1108 | : requestType === "command" && isStream |
| 1109 | ? (() => { |
| 1110 | const fromRequestConfig = client[key].Request.config?.["invalidatesQueries"] as |
| 1111 | | InvalidationCallback<InvalidationResourcesFor<M>> |
| 1112 | | undefined |
| 1113 | const fromRequest = fromRequestConfig |
| 1114 | ? ((defaultKey: string[], _name: string, input?: unknown, output?: unknown) => |
| 1115 | fromRequestConfig( |
| 1116 | defaultKey, |
| 1117 | queryResources as never, |
| 1118 | input, |
| 1119 | output as never |
| 1120 | ) as InvalidationEntry[]) |
| 1121 | : undefined |
| 1122 | const mergedInvalidation = mergeInvalidation(fromRequest, invalidation?.[key]) |
| 1123 | const streamCmd = useCommand() |
| 1124 | return { |
| 1125 | ...client[key], |
| 1126 | request, |
| 1127 | query: useStreamQuery(client[key] as any), |
| 1128 | fn: (options?: any) => streamCmd.streamFn(client[key].id as any, options), |
no test coverage detected
searching dependent graphs…