CAKE20

AI Web PaaS

Built-in functions

This is a Cake20 Runtime function used without import in website server code.

Runtime global functions

  • app: Provides current website ID, name, domain, full URL, Runtime, timezone and DB information.
  • db: A dedicated Prisma Client that automatically reflects the model type for each website.
  • fetchGet and fetchPost: Make HTTP requests in the same way in UI, server, and tests.
  • now, toDate, textDate and startOfToday: Provide common date creation, conversion and display.
  • auth: Provides login, logout, current user and permission checking.
  • mail: Send email using the website SMTP settings.
  • payment: Provides Toss, Stripe and PayPal payment/refund/webhook verification.
  • storage: Read, save, and delete files in files or Object Storage.
  • excel.open, excel.download, and excel.save: Read, download, or save single-sheet row data as XLSX.
  • job.<file> and job.$get: Register asynchronous tasks and query their status.
  • z: Zod-based schema builder used for API input validation and *.db.ts model declaration.
  • defineApi, defineHook and defineTask: Clearly declare the type of the handler.

Server-only functions are available in server/api, server/routes, server/hooks, server/tasks and servers. Used in the shared function that is called.

Download XLSX immediately

  • excel.download(name, rows) returns an XLSX download Response immediately.
  • It does not write to storage, so generated downloads do not accumulate.
  • Prefer excel.download for downloads completed in the current API or route request.
  • name must be an .xlsx file name, not a path.
  • For asynchronous jobs whose request has ended, persist the result with excel.save and define a cleanup policy.
export default async () => {
  const rows = [
    ["ID", "Name", "Joined"],
    [1, "Cafe", new Date()],
    [2, "User", new Date()]
  ];
  return excel.download("users.xlsx", rows);
};

Persist XLSX

  • Rows support strings, numbers, booleans, Date values, and empty cells.
  • Workbook, styling, formulas, and multiple-sheet editing are not supported.
  • excel.save(path, rows) saves to storage and returns path, byte size and, if possible, a public URL.
  • Use excel.save only when the file must be reopened or shared later.
  • The save path must end with .xlsx and website file size limits apply.
  • XLSX saved in files may be made public, so do not include passwords or private information.
export default async () => {
  const rows = [
    ["ID", "Name", "Joined"],
    [1, "Cafe", new Date()],
    [2, "User", new Date()]
  ];
  return excel.save("exports/users.xlsx", rows);
};

Read XLSX

  • excel.open(path) reads a file from storage and returns rows from its first sheet.
  • If the file does not exist or has an extension other than .xlsx, an error will be raised.
  • The uploaded XLSX is first saved to files with storage.put and then read with excel.open.
  • Worker performs XLSX conversion; styles and formula metadata are not returned.
export default async () => {
  return excel.open("imports/users.xlsx");
};

file function

  • All permanently created files are managed by storage.
  • fs import·require, Bun.file, and Bun.write cannot be used in website source code.
  • excel.open and excel.save use the same storage and capacity limits; excel.download does not persist a file.
  • Objects in files can be provided as public URLs, so no sensitive information is stored.
  • Runtime default features are not added back to the website package.json dependencies.
await storage.put("reports/data.json", JSON.stringify(data));
const content = await storage.get("reports/data.json");
const exists = await storage.has("reports/data.json");
const url = storage.url("reports/data.json");
await storage.remove("reports/data.json");