Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/lib/api/schema/user-query.ts
1449 views
1
import { z } from "../framework";
2
3
import { FailedAPIOperationSchema } from "./common";
4
import { AccountIdSchema } from "./accounts/common";
5
import { ProjectIdSchema } from "./projects/common";
6
7
const ExampleUserQuerySchema = z.object({
8
accounts: z
9
.object({
10
account_id: AccountIdSchema.nullable(),
11
email_address: z.string().nullable(),
12
})
13
.describe(
14
`Used to query for the account id and e-mail address of the account corresponding to
15
the API key provided in this request.`,
16
),
17
});
18
19
const ExampleDirectoryListingSchema = z.object({
20
listings: z
21
.object({
22
project_id: ProjectIdSchema,
23
path: z
24
.string()
25
.nullable()
26
.describe("Path relative to user's `$HOME` directory."),
27
listing: z
28
.union([
29
z.null(),
30
z.array(
31
z.object({
32
name: z.string().describe("File name."),
33
size: z.number().min(0).describe("File size."),
34
mtime: z
35
.number()
36
.describe("Time at which the file was last modified."),
37
}),
38
),
39
])
40
.describe(
41
"This field should be `null` when querying for a list of files.",
42
),
43
})
44
.describe(
45
"Object containing project id and file path for which to list files.",
46
),
47
});
48
49
const GenericUserQuerySchema = z.any();
50
51
// OpenAPI spec
52
//
53
export const UserQueryInputSchema = z
54
.object({
55
query: z.union([
56
ExampleUserQuerySchema,
57
ExampleDirectoryListingSchema,
58
GenericUserQuerySchema.describe(
59
`Many other generic queries are supported; you can learn more about this endpoint
60
by viewing the corresponding CoCalc source code at
61
https://github.com/sagemathinc/cocalc/blob/master/src/packages/next/pages/api/v2/user-query.ts.`,
62
),
63
]),
64
})
65
.describe(
66
`Used to fetch or set data corresponding to a particular account. Generally speaking,
67
when \`null\` values are provided for a specific field, this endpoint acts as a
68
getter; otherwise, it acts as a setter for the provided fields.`,
69
);
70
71
export const UserQueryOutputSchema = z.union([
72
FailedAPIOperationSchema,
73
z.object({
74
query: z.union([
75
ExampleUserQuerySchema.describe(
76
`An example response for an e-mail address and account id query.`,
77
),
78
ExampleDirectoryListingSchema.describe(
79
"An example response for a directory listing query.",
80
),
81
GenericUserQuerySchema.describe(
82
`Generally, the object returned from this request mimics the structure of the
83
input query with fields populated as applicable. For more information on this
84
request, check out the corresponding CoCalc source code at
85
https://github.com/sagemathinc/cocalc/blob/master/src/packages/next/pages/api/v2/user-query.ts.`,
86
),
87
]),
88
}),
89
]);
90
91
export type UserQueryInput = z.infer<typeof UserQueryInputSchema>;
92
export type UserQueryOutput = z.infer<typeof UserQueryOutputSchema>;
93
94