Examples
Real-world usage examples for Plasma
Server Function (TanStack Start)
import { } from '@tanstack/react-start'
import { } from './client'
import { } from './adapters'
export const = ().(async () => {
const [, ] = await .('get-users')
if () throw
return ()
})File upload with form-data
const [, ] = await .('upload-avatar', , {
: 'form-data',
})Public endpoint
const [, ] = await .('login', , {
: false,
})Advanced Usage
import { } from "./constants/status";
import { } from "@tanstack/react-start";
import { } from "zod";
import { } from "./lib/time";
import { } from "./utils/http";
import { } from "./utils/routes";
export const = ({ : "POST" })
.((: FormData) => {
if (!( instanceof )) {
throw new ("Expected FormData");
}
const = .("segment")?.().(" - ")[0];
const = {
,
: .("employee-who-covers") || ,
: .("days"),
};
return ["upload-vacation"]..();
})
.(async ({ : { , , } }) => {
const = new ();
const = new ().();
const = `${}-12-31` as ;
const = {
: ,
: .,
: .,
: "-",
: ,
: ,
: ,
: .((: any) => ()).(),
};
const [, ] = await .("upload-vacation", , {
: "form-data",
});
if () {
if ( instanceof ) {
return {
: false,
: "Invalid payload data",
: "",
};
}
throw ;
}
if (. !== 201) {
return {
: false,
: "No se pudieron procesar las vacaciones. Intenta más tarde.",
};
}
return {
: true,
};
});