-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpocketbase-schema.type.ts
More file actions
101 lines (96 loc) · 2.18 KB
/
Copy pathpocketbase-schema.type.ts
File metadata and controls
101 lines (96 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import { z } from "astro/zod";
/**
* Entry for a collections schema in PocketBase.
*/
export const pocketBaseSchemaEntry = z.object({
/**
* Flag to indicate if the field is hidden.
* Hidden fields are not returned in the API response.
*/
hidden: z.optional(z.boolean()),
/**
* Name of the field.
*/
name: z.string(),
/**
* Type of the field.
*/
type: z.enum([
"text",
"editor",
"number",
"bool",
"email",
"url",
"date",
"autodate",
"select",
"file",
"relation",
"json",
"geoPoint",
"password"
]),
/**
* Whether the field is required.
*/
required: z.optional(z.boolean()),
/**
* Values for a select field.
* This is only present if the field type is "select".
*/
values: z.optional(z.array(z.string())),
/**
* Maximum number of values for a select field.
* This is only present on "select", "relation", and "file" fields.
*/
maxSelect: z.optional(z.number()),
/**
* Whether the field is filled when the entry is created.
* This is only present on "autodate" fields.
*/
onCreate: z.optional(z.boolean()),
/**
* Whether the field is updated when the entry is updated.
* This is only present on "autodate" fields.
*/
onUpdate: z.optional(z.boolean()),
/**
* Id of the associated collection that the relation is referencing.
* This is only present on "relation" fields.
*/
collectionId: z.optional(z.string())
});
/**
* Entry for a collections schema in PocketBase.
*/
export type PocketBaseSchemaEntry = z.infer<typeof pocketBaseSchemaEntry>;
/**
* Schema for a PocketBase collection.
*/
export const pocketBaseCollection = z.object({
/**
* Id of the collection.
*/
id: z.string(),
/**
* Name of the collection.
*/
name: z.string(),
/**
* Type of the collection.
*/
type: z.enum(["base", "view", "auth"]),
/**
* Schema of the collection.
*/
fields: z.array(pocketBaseSchemaEntry)
});
/**
* Type for a PocketBase collection.
*/
export type PocketBaseCollection = z.infer<typeof pocketBaseCollection>;
/**
* Schema for an entire PocketBase database.
*/
export const pocketBaseDatabase = z.array(pocketBaseCollection);