MCPcopy Create free account
hub / github.com/effect-app/libs / mapMutation

Function mapMutation

packages/vue/src/makeClient.ts:1012–1067  ·  view source on GitHub ↗
(
    client: ClientFrom<M>,
    queryInvalidation?: (client: ClientFrom<M>) => QueryInvalidation<M>,
    invalidationResources?: InvalidationResourcesFor<M>
  )

Source from the content-addressed store, hash-verified

1010 >
1011 }
1012 )
1013 return mutations
1014 }
1015
1016 const mapMutation = <M extends RequestsAny>(
1017 client: ClientFrom<M>,
1018 queryInvalidation?: (client: ClientFrom<M>) => QueryInvalidation<M>,
1019 invalidationResources?: InvalidationResourcesFor<M>
1020 ) => {
1021 const Command = useCommand()
1022 const mutation = useMutation()
1023 const invalidation = queryInvalidation?.(client)
1024 const queryResources = makeQueryResources(invalidationResources)
1025 const mutations = Struct.keys(client).reduce(
1026 (acc, key) => {
1027 if (!(client[key].Request.type === "command" && !client[key].Request.stream)) {
1028 return acc
1029 }
1030 const fromRequestConfig = client[key].Request.config?.["invalidatesQueries"] as
1031 | InvalidationCallback<InvalidationResourcesFor<M>>
1032 | undefined
1033 const fromRequest = fromRequestConfig
1034 ? ((defaultKey: string[], _name: string, input?: unknown, output?: unknown) =>
1035 fromRequestConfig(
1036 defaultKey,
1037 queryResources as never,
1038 input,
1039 output as never
1040 ) as InvalidationEntry[])
1041 : undefined
1042 const mergedInvalidation = mergeInvalidation(fromRequest, invalidation?.[key])
1043 const makeProjectedMutation = (handler: any): any => {
1044 const mut: any = withDefaultInvalidation(mutation(handler), mergedInvalidation)
1045 return Object.assign(mut, {
1046 wrap: (options?: any) => Command.wrap({ mutate: mut, id: client[key].id }, options),
1047 fn: (options?: any) => Command.fn(client[key].id, options),
1048 project: (projectionSchema: any) => {
1049 const projected = {
1050 ...handler,
1051 handler: projectHandler(handler.handler, client[key].Request.success, projectionSchema)
1052 }
1053 return makeProjectedMutation(projected)
1054 }
1055 })
1056 }
1057 ;(acc as any)[camelCase(key) + "Mutation"] = makeProjectedMutation(client[key] as any)
1058 return acc
1059 },
1060 {} as {
1061 [
1062 Key in keyof typeof client as CommandHandler<typeof client[Key]> extends never ? never
1063 : `${ToCamel<string & Key>}Mutation`
1064 ]: MutationWithExtensions<
1065 RT | RTHooks,
1066 CommandHandler<typeof client[Key]>
1067 >
1068 }
1069 )

Callers 1

mapClientFunction · 0.85

Calls 5

makeQueryResourcesFunction · 0.85
mergeInvalidationFunction · 0.85
makeProjectedMutationFunction · 0.85
useCommandFunction · 0.70
useMutationFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…