mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-10 19:16:55 +02:00
Merge main into proxy branch (formatting and docs)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import type { ActionInvocation, ActionMetadata } from '@yaakapp-internal/proxy-lib';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { rpc } from '../lib/rpc';
|
||||
import type { ActionInvocation, ActionMetadata } from "@yaakapp-internal/proxy-lib";
|
||||
import { useEffect, useState } from "react";
|
||||
import { rpc } from "../lib/rpc";
|
||||
|
||||
/** Look up metadata for a specific action invocation. */
|
||||
export function useActionMetadata(action: ActionInvocation): ActionMetadata | null {
|
||||
@@ -23,7 +23,7 @@ let cachedActions: [ActionInvocation, ActionMetadata][] | null = null;
|
||||
/** Fetch and cache all action metadata. */
|
||||
async function getActions(): Promise<[ActionInvocation, ActionMetadata][]> {
|
||||
if (!cachedActions) {
|
||||
const { actions } = await rpc('list_actions', {});
|
||||
const { actions } = await rpc("list_actions", {});
|
||||
cachedActions = actions;
|
||||
}
|
||||
return cachedActions;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { RpcEventSchema } from '@yaakapp-internal/proxy-lib';
|
||||
import { useEffect } from 'react';
|
||||
import { listen } from '../lib/rpc';
|
||||
import type { RpcEventSchema } from "@yaakapp-internal/proxy-lib";
|
||||
import { useEffect } from "react";
|
||||
import { listen } from "../lib/rpc";
|
||||
|
||||
/**
|
||||
* Subscribe to an RPC event. Cleans up automatically on unmount.
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { type UseMutationOptions, useMutation } from '@tanstack/react-query';
|
||||
import type { RpcSchema } from '@yaakapp-internal/proxy-lib';
|
||||
import { minPromiseMillis } from '@yaakapp-internal/ui';
|
||||
import type { Req, Res } from '../lib/rpc';
|
||||
import { rpc } from '../lib/rpc';
|
||||
import { type UseMutationOptions, useMutation } from "@tanstack/react-query";
|
||||
import type { RpcSchema } from "@yaakapp-internal/proxy-lib";
|
||||
import { minPromiseMillis } from "@yaakapp-internal/ui";
|
||||
import type { Req, Res } from "../lib/rpc";
|
||||
import { rpc } from "../lib/rpc";
|
||||
|
||||
/**
|
||||
* React Query mutation wrapper for RPC commands.
|
||||
*/
|
||||
export function useRpcMutation<K extends keyof RpcSchema>(
|
||||
cmd: K,
|
||||
opts?: Omit<UseMutationOptions<Res<K>, Error, Req<K>>, 'mutationFn'>,
|
||||
opts?: Omit<UseMutationOptions<Res<K>, Error, Req<K>>, "mutationFn">,
|
||||
) {
|
||||
return useMutation<Res<K>, Error, Req<K>>({
|
||||
mutationFn: (payload) => minPromiseMillis(rpc(cmd, payload)),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { type UseQueryOptions, useQuery } from '@tanstack/react-query';
|
||||
import type { RpcSchema } from '@yaakapp-internal/proxy-lib';
|
||||
import type { Req, Res } from '../lib/rpc';
|
||||
import { rpc } from '../lib/rpc';
|
||||
import { type UseQueryOptions, useQuery } from "@tanstack/react-query";
|
||||
import type { RpcSchema } from "@yaakapp-internal/proxy-lib";
|
||||
import type { Req, Res } from "../lib/rpc";
|
||||
import { rpc } from "../lib/rpc";
|
||||
|
||||
/**
|
||||
* React Query wrapper for RPC commands.
|
||||
@@ -10,7 +10,7 @@ import { rpc } from '../lib/rpc';
|
||||
export function useRpcQuery<K extends keyof RpcSchema>(
|
||||
cmd: K,
|
||||
payload: Req<K>,
|
||||
opts?: Omit<UseQueryOptions<Res<K>>, 'queryKey' | 'queryFn'>,
|
||||
opts?: Omit<UseQueryOptions<Res<K>>, "queryKey" | "queryFn">,
|
||||
) {
|
||||
return useQuery<Res<K>>({
|
||||
queryKey: [cmd, payload],
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { type UseQueryOptions, useQueryClient } from '@tanstack/react-query';
|
||||
import type { RpcEventSchema, RpcSchema } from '@yaakapp-internal/proxy-lib';
|
||||
import type { Req, Res } from '../lib/rpc';
|
||||
import { useRpcEvent } from './useRpcEvent';
|
||||
import { useRpcQuery } from './useRpcQuery';
|
||||
import { type UseQueryOptions, useQueryClient } from "@tanstack/react-query";
|
||||
import type { RpcEventSchema, RpcSchema } from "@yaakapp-internal/proxy-lib";
|
||||
import type { Req, Res } from "../lib/rpc";
|
||||
import { useRpcEvent } from "./useRpcEvent";
|
||||
import { useRpcQuery } from "./useRpcQuery";
|
||||
|
||||
/**
|
||||
* Combines useRpcQuery with an event listener that invalidates the query
|
||||
@@ -11,7 +11,7 @@ import { useRpcQuery } from './useRpcQuery';
|
||||
export function useRpcQueryWithEvent<
|
||||
K extends keyof RpcSchema,
|
||||
E extends keyof RpcEventSchema & string,
|
||||
>(cmd: K, payload: Req<K>, event: E, opts?: Omit<UseQueryOptions<Res<K>>, 'queryKey' | 'queryFn'>) {
|
||||
>(cmd: K, payload: Req<K>, event: E, opts?: Omit<UseQueryOptions<Res<K>>, "queryKey" | "queryFn">) {
|
||||
const queryClient = useQueryClient();
|
||||
const query = useRpcQuery(cmd, payload, opts);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user