CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/lib/api/schema/common.ts
Views: 687
1
import { z } from "../framework";
2
3
const BasicallyAnHTTP204 = <T extends string>(status: T) =>
4
z.object({
5
status: z.enum([status]).describe(
6
`Indicates the status of this operation; if the operation was successful, the
7
value of this field is always set to \`${status}\`.`,
8
),
9
});
10
11
export const OkAPIOperationSchema = BasicallyAnHTTP204("ok");
12
export const SuccessfulAPIOperationSchema = BasicallyAnHTTP204("success");
13
14
export const FailedAPIOperationSchema = z.object({
15
error: z.string().describe("Error message if something goes badly wrong."),
16
});
17
18
export type FailedAPIOperation = z.infer<typeof FailedAPIOperationSchema>;
19
export type SuccessfulAPIOperation = z.infer<
20
typeof SuccessfulAPIOperationSchema
21
>;
22
export type OkAPIOperation = z.infer<typeof OkAPIOperationSchema>;
23
24
export const RequestNoCacheSchema = z
25
.boolean()
26
.describe(
27
"**Administrators only**. Disables database caching for this query.",
28
)
29
.optional();
30
31
export type RequestNoCache = z.infer<typeof RequestNoCacheSchema>;
32
33
export const LimitResultsSchema = z
34
.number()
35
.min(1)
36
.describe("Limits the number of returned results.");
37
38
export type LimitResults = z.infer<typeof LimitResultsSchema>;
39
40
export const SkipResultsSchema = z
41
.number()
42
.min(1)
43
.describe("Skips the first `n` results.");
44
45
export type SkipResults = z.infer<typeof SkipResultsSchema>;
46
47