Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/next/lib/api/schema/bookmarks.ts
Views: 687
/*1* This file is part of CoCalc: Copyright © 2024 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { z } from "../framework";67import {8LoadStarredFilesBookmarksProps,9SaveStarredFilesBoookmarksProps,10} from "@cocalc/server/bookmarks/starred";11import { MAX_STARS, STARRED_FILES } from "@cocalc/util/consts/bookmarks";12import {13GetStarredBookmarks,14GetStarredBookmarksPayload,15SetStarredBookmarks,16} from "@cocalc/util/types/bookmarks";17import { ProjectIdSchema } from "./projects/common";1819const ERROR = z.object({20status: z.literal("error"),21error: z.string(),22});2324const COMMON_STARS = z.object({25project_id: ProjectIdSchema,26type: z.literal(STARRED_FILES),27});2829export const BookmarkSetInputSchema = COMMON_STARS.extend({30stars: z31.string()32.array()33.max(MAX_STARS)34.describe("List of file paths or IDs"),35}).describe("Set the list of starred items to the given list of stars.");3637export const BookmarkSetOutputSchema = z.union([38COMMON_STARS.merge(z.object({ status: z.literal("success") })),39ERROR,40]);4142export const BookmarkAddInputSchema = BookmarkSetInputSchema.describe(43"Add a list of starred items to the list of bookmarks.",44);45export const BookmarkAddOutputSchema = BookmarkSetOutputSchema;4647export const BookmarkRemoveInputSchema = BookmarkSetInputSchema.describe(48"Remove a list of starred items from the given list of bookmarks.",49);50export const BookmarkRemoveOutputSchema = BookmarkSetOutputSchema;5152export const BookmarkGetInputSchema = COMMON_STARS.describe(53"Get the list of starred items for the given project ID and your account.",54);55export const BookmarkGetOutputSchema = z.union([56z57.object({58status: z.literal("success"),59stars: z60.array(z.string())61.describe(62"Array of IDs or file path strings, as they are in the starred tabs flyout",63),64last_edited: z65.number()66.optional()67.describe("UNIX epoch timestamp, when bookmark was last edited"),68})69.merge(COMMON_STARS),70ERROR.merge(COMMON_STARS),71]);7273export type BookmarkSetInputType = z.infer<typeof BookmarkSetInputSchema>;74export type BookmarkSetOutputType = z.infer<typeof BookmarkSetOutputSchema>;75export type BookmarkAddInputType = z.infer<typeof BookmarkAddInputSchema>;76export type BookmarkAddOutputType = z.infer<typeof BookmarkRemoveOutputSchema>;77export type BookmarkRemoveInputType = z.infer<typeof BookmarkRemoveInputSchema>;78export type BookmarkRemoveOutputType = z.infer<typeof BookmarkAddOutputSchema>;79export type BookmarkGetInputType = z.infer<typeof BookmarkGetInputSchema>;80export type BookmarkGetOutputType = z.infer<typeof BookmarkGetOutputSchema>;8182// consistency checks83export const _1: Omit<SaveStarredFilesBoookmarksProps, "mode" | "account_id"> =84{} as Omit<BookmarkSetInputType, typeof STARRED_FILES>;8586export const _2: Omit<LoadStarredFilesBookmarksProps, "account_id"> =87{} as Omit<BookmarkGetInputType, typeof STARRED_FILES>;8889export const _3: BookmarkGetOutputType = {} as GetStarredBookmarks;9091export const _4: BookmarkSetInputType = {} as SetStarredBookmarks;9293export const _5: BookmarkGetInputType = {} as GetStarredBookmarksPayload;949596