pocketbase-zod-schema 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/README.md +209 -24
- package/dist/cli/index.cjs +34 -0
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.d.cts +3 -1
- package/dist/cli/index.d.ts +3 -1
- package/dist/cli/index.js +34 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/migrate.cjs +34 -0
- package/dist/cli/migrate.cjs.map +1 -1
- package/dist/cli/migrate.js +34 -0
- package/dist/cli/migrate.js.map +1 -1
- package/dist/cli/utils/index.d.cts +3 -1
- package/dist/cli/utils/index.d.ts +3 -1
- package/dist/fields-YjcpBXVp.d.cts +348 -0
- package/dist/fields-YjcpBXVp.d.ts +348 -0
- package/dist/index.cjs +222 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +208 -1
- package/dist/index.js.map +1 -1
- package/dist/migration/analyzer.cjs +34 -0
- package/dist/migration/analyzer.cjs.map +1 -1
- package/dist/migration/analyzer.d.cts +2 -1
- package/dist/migration/analyzer.d.ts +2 -1
- package/dist/migration/analyzer.js +34 -0
- package/dist/migration/analyzer.js.map +1 -1
- package/dist/migration/diff.d.cts +3 -1
- package/dist/migration/diff.d.ts +3 -1
- package/dist/migration/generator.d.cts +3 -1
- package/dist/migration/generator.d.ts +3 -1
- package/dist/migration/index.cjs +36 -0
- package/dist/migration/index.cjs.map +1 -1
- package/dist/migration/index.d.cts +2 -1
- package/dist/migration/index.d.ts +2 -1
- package/dist/migration/index.js +35 -1
- package/dist/migration/index.js.map +1 -1
- package/dist/migration/snapshot.cjs.map +1 -1
- package/dist/migration/snapshot.d.cts +3 -1
- package/dist/migration/snapshot.d.ts +3 -1
- package/dist/migration/snapshot.js.map +1 -1
- package/dist/migration/utils/index.cjs +16 -0
- package/dist/migration/utils/index.cjs.map +1 -1
- package/dist/migration/utils/index.d.cts +2 -2
- package/dist/migration/utils/index.d.ts +2 -2
- package/dist/migration/utils/index.js +15 -1
- package/dist/migration/utils/index.js.map +1 -1
- package/dist/schema.cjs +200 -0
- package/dist/schema.cjs.map +1 -1
- package/dist/schema.d.cts +1 -0
- package/dist/schema.d.ts +1 -0
- package/dist/schema.js +186 -1
- package/dist/schema.js.map +1 -1
- package/dist/{types-z1Dkjg8m.d.ts → types-LFBGHl9Y.d.ts} +2 -2
- package/dist/{types-BbTgmg6H.d.cts → types-mhQXWNi3.d.cts} +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Internal marker for field metadata
|
|
5
|
+
* Used by the migration generator to detect explicit field type definitions
|
|
6
|
+
*/
|
|
7
|
+
declare const FIELD_METADATA_KEY = "__pocketbase_field__";
|
|
8
|
+
/**
|
|
9
|
+
* PocketBase field types
|
|
10
|
+
*/
|
|
11
|
+
type PocketBaseFieldType = "text" | "email" | "url" | "editor" | "number" | "bool" | "date" | "autodate" | "select" | "relation" | "file" | "json" | "geoPoint";
|
|
12
|
+
/**
|
|
13
|
+
* Field metadata structure embedded in Zod schema descriptions
|
|
14
|
+
*/
|
|
15
|
+
interface FieldMetadata {
|
|
16
|
+
type: PocketBaseFieldType;
|
|
17
|
+
options?: Record<string, any>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Extracts field metadata from a Zod type's description
|
|
21
|
+
* Used by the migration generator to detect explicit field type definitions
|
|
22
|
+
*
|
|
23
|
+
* @param description - The Zod type's description string
|
|
24
|
+
* @returns Field metadata if present, null otherwise
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* const schema = TextField({ min: 1, max: 100 });
|
|
28
|
+
* const metadata = extractFieldMetadata(schema.description);
|
|
29
|
+
* // Returns: { type: "text", options: { min: 1, max: 100 } }
|
|
30
|
+
*/
|
|
31
|
+
declare function extractFieldMetadata(description: string | undefined): FieldMetadata | null;
|
|
32
|
+
/**
|
|
33
|
+
* Text field configuration options
|
|
34
|
+
*/
|
|
35
|
+
interface TextFieldOptions {
|
|
36
|
+
/**
|
|
37
|
+
* Minimum length constraint
|
|
38
|
+
*/
|
|
39
|
+
min?: number;
|
|
40
|
+
/**
|
|
41
|
+
* Maximum length constraint
|
|
42
|
+
*/
|
|
43
|
+
max?: number;
|
|
44
|
+
/**
|
|
45
|
+
* Pattern constraint (regex)
|
|
46
|
+
*/
|
|
47
|
+
pattern?: RegExp | string;
|
|
48
|
+
/**
|
|
49
|
+
* Auto-generate pattern for automatic value generation
|
|
50
|
+
* Example: "[A-Z]{3}-[0-9]{6}" generates values like "ABC-123456"
|
|
51
|
+
*/
|
|
52
|
+
autogeneratePattern?: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Number field configuration options
|
|
56
|
+
*/
|
|
57
|
+
interface NumberFieldOptions {
|
|
58
|
+
/**
|
|
59
|
+
* Minimum value constraint
|
|
60
|
+
*/
|
|
61
|
+
min?: number;
|
|
62
|
+
/**
|
|
63
|
+
* Maximum value constraint
|
|
64
|
+
*/
|
|
65
|
+
max?: number;
|
|
66
|
+
/**
|
|
67
|
+
* Whether to disallow decimal values (integers only)
|
|
68
|
+
*/
|
|
69
|
+
noDecimal?: boolean;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Date field configuration options
|
|
73
|
+
*/
|
|
74
|
+
interface DateFieldOptions {
|
|
75
|
+
/**
|
|
76
|
+
* Minimum date constraint
|
|
77
|
+
*/
|
|
78
|
+
min?: Date | string;
|
|
79
|
+
/**
|
|
80
|
+
* Maximum date constraint
|
|
81
|
+
*/
|
|
82
|
+
max?: Date | string;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Autodate field configuration options
|
|
86
|
+
*/
|
|
87
|
+
interface AutodateFieldOptions {
|
|
88
|
+
/**
|
|
89
|
+
* Set date automatically on record creation
|
|
90
|
+
* @default false
|
|
91
|
+
*/
|
|
92
|
+
onCreate?: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Update date automatically on record update
|
|
95
|
+
* @default false
|
|
96
|
+
*/
|
|
97
|
+
onUpdate?: boolean;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Select field configuration options
|
|
101
|
+
*/
|
|
102
|
+
interface SelectFieldOptions {
|
|
103
|
+
/**
|
|
104
|
+
* Maximum number of selections allowed
|
|
105
|
+
* If > 1, enables multiple selection
|
|
106
|
+
* @default 1
|
|
107
|
+
*/
|
|
108
|
+
maxSelect?: number;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* File field configuration options
|
|
112
|
+
*/
|
|
113
|
+
interface FileFieldOptions {
|
|
114
|
+
/**
|
|
115
|
+
* Allowed MIME types
|
|
116
|
+
* Example: ["image/*", "application/pdf"]
|
|
117
|
+
*/
|
|
118
|
+
mimeTypes?: string[];
|
|
119
|
+
/**
|
|
120
|
+
* Maximum file size in bytes
|
|
121
|
+
*/
|
|
122
|
+
maxSize?: number;
|
|
123
|
+
/**
|
|
124
|
+
* Thumbnail sizes to generate
|
|
125
|
+
* Example: ["100x100", "200x200"]
|
|
126
|
+
*/
|
|
127
|
+
thumbs?: string[];
|
|
128
|
+
/**
|
|
129
|
+
* Whether the file is protected (requires auth to access)
|
|
130
|
+
* @default false
|
|
131
|
+
*/
|
|
132
|
+
protected?: boolean;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Multiple files field configuration options
|
|
136
|
+
*/
|
|
137
|
+
interface FilesFieldOptions extends FileFieldOptions {
|
|
138
|
+
/**
|
|
139
|
+
* Minimum number of files required
|
|
140
|
+
*/
|
|
141
|
+
minSelect?: number;
|
|
142
|
+
/**
|
|
143
|
+
* Maximum number of files allowed
|
|
144
|
+
*/
|
|
145
|
+
maxSelect?: number;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Creates a boolean field schema
|
|
149
|
+
* Maps to PocketBase 'bool' field type
|
|
150
|
+
*
|
|
151
|
+
* @returns Zod boolean schema with PocketBase metadata
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* const ProductSchema = z.object({
|
|
155
|
+
* active: BoolField(),
|
|
156
|
+
* featured: BoolField().optional(),
|
|
157
|
+
* });
|
|
158
|
+
*/
|
|
159
|
+
declare function BoolField(): z.ZodBoolean;
|
|
160
|
+
/**
|
|
161
|
+
* Creates a number field schema with optional constraints
|
|
162
|
+
* Maps to PocketBase 'number' field type
|
|
163
|
+
*
|
|
164
|
+
* @param options - Optional constraints for the number field
|
|
165
|
+
* @returns Zod number schema with PocketBase metadata
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* const ProductSchema = z.object({
|
|
169
|
+
* price: NumberField({ min: 0 }),
|
|
170
|
+
* quantity: NumberField({ min: 0, noDecimal: true }),
|
|
171
|
+
* rating: NumberField({ min: 0, max: 5 }),
|
|
172
|
+
* });
|
|
173
|
+
*/
|
|
174
|
+
declare function NumberField(options?: NumberFieldOptions): z.ZodNumber;
|
|
175
|
+
/**
|
|
176
|
+
* Creates a text field schema with optional constraints
|
|
177
|
+
* Maps to PocketBase 'text' field type
|
|
178
|
+
*
|
|
179
|
+
* @param options - Optional constraints for the text field
|
|
180
|
+
* @returns Zod string schema with PocketBase metadata
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* const ProductSchema = z.object({
|
|
184
|
+
* name: TextField({ min: 1, max: 200 }),
|
|
185
|
+
* sku: TextField({ autogeneratePattern: "[A-Z]{3}-[0-9]{6}" }),
|
|
186
|
+
* description: TextField({ max: 1000 }),
|
|
187
|
+
* });
|
|
188
|
+
*/
|
|
189
|
+
declare function TextField(options?: TextFieldOptions): z.ZodString;
|
|
190
|
+
/**
|
|
191
|
+
* Creates an email field schema
|
|
192
|
+
* Maps to PocketBase 'email' field type
|
|
193
|
+
*
|
|
194
|
+
* @returns Zod string schema with email validation and PocketBase metadata
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* const UserSchema = z.object({
|
|
198
|
+
* email: EmailField(),
|
|
199
|
+
* alternateEmail: EmailField().optional(),
|
|
200
|
+
* });
|
|
201
|
+
*/
|
|
202
|
+
declare function EmailField(): z.ZodString;
|
|
203
|
+
/**
|
|
204
|
+
* Creates a URL field schema
|
|
205
|
+
* Maps to PocketBase 'url' field type
|
|
206
|
+
*
|
|
207
|
+
* @returns Zod string schema with URL validation and PocketBase metadata
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* const ProductSchema = z.object({
|
|
211
|
+
* website: URLField(),
|
|
212
|
+
* documentation: URLField().optional(),
|
|
213
|
+
* });
|
|
214
|
+
*/
|
|
215
|
+
declare function URLField(): z.ZodString;
|
|
216
|
+
/**
|
|
217
|
+
* Creates a rich text editor field schema
|
|
218
|
+
* Maps to PocketBase 'editor' field type
|
|
219
|
+
*
|
|
220
|
+
* @returns Zod string schema with PocketBase metadata
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* const PostSchema = z.object({
|
|
224
|
+
* content: EditorField(),
|
|
225
|
+
* summary: EditorField().optional(),
|
|
226
|
+
* });
|
|
227
|
+
*/
|
|
228
|
+
declare function EditorField(): z.ZodString;
|
|
229
|
+
/**
|
|
230
|
+
* Creates a date field schema with optional constraints
|
|
231
|
+
* Maps to PocketBase 'date' field type
|
|
232
|
+
*
|
|
233
|
+
* @param options - Optional date constraints
|
|
234
|
+
* @returns Zod string schema with PocketBase metadata
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* const EventSchema = z.object({
|
|
238
|
+
* startDate: DateField(),
|
|
239
|
+
* endDate: DateField({ min: new Date('2024-01-01') }),
|
|
240
|
+
* releaseDate: DateField().optional(),
|
|
241
|
+
* });
|
|
242
|
+
*/
|
|
243
|
+
declare function DateField(options?: DateFieldOptions): z.ZodString;
|
|
244
|
+
/**
|
|
245
|
+
* Creates an autodate field schema with automatic timestamp management
|
|
246
|
+
* Maps to PocketBase 'autodate' field type
|
|
247
|
+
*
|
|
248
|
+
* @param options - Optional autodate configuration
|
|
249
|
+
* @returns Zod string schema with PocketBase metadata
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* const PostSchema = z.object({
|
|
253
|
+
* createdAt: AutodateField({ onCreate: true }),
|
|
254
|
+
* updatedAt: AutodateField({ onUpdate: true }),
|
|
255
|
+
* publishedAt: AutodateField({ onCreate: true, onUpdate: false }),
|
|
256
|
+
* });
|
|
257
|
+
*/
|
|
258
|
+
declare function AutodateField(options?: AutodateFieldOptions): z.ZodString;
|
|
259
|
+
/**
|
|
260
|
+
* Creates a select field schema from enum values
|
|
261
|
+
* Maps to PocketBase 'select' field type
|
|
262
|
+
*
|
|
263
|
+
* @param values - Array of allowed string values
|
|
264
|
+
* @param options - Optional select configuration
|
|
265
|
+
* @returns Zod enum or array schema with PocketBase metadata
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* // Single select
|
|
269
|
+
* const PostSchema = z.object({
|
|
270
|
+
* status: SelectField(["draft", "published", "archived"]),
|
|
271
|
+
* });
|
|
272
|
+
*
|
|
273
|
+
* @example
|
|
274
|
+
* // Multiple select
|
|
275
|
+
* const ProductSchema = z.object({
|
|
276
|
+
* categories: SelectField(["electronics", "clothing", "food"], { maxSelect: 3 }),
|
|
277
|
+
* });
|
|
278
|
+
*/
|
|
279
|
+
declare function SelectField<T extends [string, ...string[]]>(values: T, options?: SelectFieldOptions): z.ZodEnum<T> | z.ZodArray<z.ZodEnum<T>>;
|
|
280
|
+
/**
|
|
281
|
+
* Creates a single file field schema
|
|
282
|
+
* Maps to PocketBase 'file' field type with maxSelect=1
|
|
283
|
+
*
|
|
284
|
+
* @param options - Optional file constraints
|
|
285
|
+
* @returns Zod File schema with PocketBase metadata
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* const ProductSchema = z.object({
|
|
289
|
+
* thumbnail: FileField({ mimeTypes: ["image/*"], maxSize: 5242880 }),
|
|
290
|
+
* document: FileField({ mimeTypes: ["application/pdf"] }),
|
|
291
|
+
* });
|
|
292
|
+
*/
|
|
293
|
+
declare function FileField(options?: FileFieldOptions): z.ZodType<File>;
|
|
294
|
+
/**
|
|
295
|
+
* Creates a multiple files field schema
|
|
296
|
+
* Maps to PocketBase 'file' field type with maxSelect>1
|
|
297
|
+
*
|
|
298
|
+
* @param options - Optional file constraints
|
|
299
|
+
* @returns Zod array of File schema with PocketBase metadata
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* const ProductSchema = z.object({
|
|
303
|
+
* images: FilesField({ mimeTypes: ["image/*"], maxSelect: 5 }),
|
|
304
|
+
* attachments: FilesField({ minSelect: 1, maxSelect: 10 }),
|
|
305
|
+
* });
|
|
306
|
+
*/
|
|
307
|
+
declare function FilesField(options?: FilesFieldOptions): z.ZodArray<z.ZodType<File>>;
|
|
308
|
+
/**
|
|
309
|
+
* Creates a JSON field schema with optional inner schema validation
|
|
310
|
+
* Maps to PocketBase 'json' field type
|
|
311
|
+
*
|
|
312
|
+
* @param schema - Optional Zod schema for the JSON structure
|
|
313
|
+
* @returns Zod schema with PocketBase metadata
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* // Any JSON
|
|
317
|
+
* const ProductSchema = z.object({
|
|
318
|
+
* metadata: JSONField(),
|
|
319
|
+
* });
|
|
320
|
+
*
|
|
321
|
+
* @example
|
|
322
|
+
* // Typed JSON
|
|
323
|
+
* const ProductSchema = z.object({
|
|
324
|
+
* settings: JSONField(z.object({
|
|
325
|
+
* theme: z.string(),
|
|
326
|
+
* notifications: z.boolean(),
|
|
327
|
+
* })),
|
|
328
|
+
* });
|
|
329
|
+
*/
|
|
330
|
+
declare function JSONField<T extends z.ZodTypeAny>(schema?: T): T | z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
331
|
+
/**
|
|
332
|
+
* Creates a geographic point field schema
|
|
333
|
+
* Maps to PocketBase 'geoPoint' field type
|
|
334
|
+
*
|
|
335
|
+
* @returns Zod object schema with lon/lat fields and PocketBase metadata
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
* const LocationSchema = z.object({
|
|
339
|
+
* coordinates: GeoPointField(),
|
|
340
|
+
* homeLocation: GeoPointField().optional(),
|
|
341
|
+
* });
|
|
342
|
+
*/
|
|
343
|
+
declare function GeoPointField(): z.ZodObject<{
|
|
344
|
+
lon: z.ZodNumber;
|
|
345
|
+
lat: z.ZodNumber;
|
|
346
|
+
}>;
|
|
347
|
+
|
|
348
|
+
export { type AutodateFieldOptions as A, BoolField as B, type DateFieldOptions as D, EmailField as E, FIELD_METADATA_KEY as F, GeoPointField as G, JSONField as J, type NumberFieldOptions as N, type PocketBaseFieldType as P, type SelectFieldOptions as S, type TextFieldOptions as T, URLField as U, type FieldMetadata as a, type FileFieldOptions as b, type FilesFieldOptions as c, NumberField as d, extractFieldMetadata as e, TextField as f, EditorField as g, DateField as h, AutodateField as i, SelectField as j, FileField as k, FilesField as l };
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Internal marker for field metadata
|
|
5
|
+
* Used by the migration generator to detect explicit field type definitions
|
|
6
|
+
*/
|
|
7
|
+
declare const FIELD_METADATA_KEY = "__pocketbase_field__";
|
|
8
|
+
/**
|
|
9
|
+
* PocketBase field types
|
|
10
|
+
*/
|
|
11
|
+
type PocketBaseFieldType = "text" | "email" | "url" | "editor" | "number" | "bool" | "date" | "autodate" | "select" | "relation" | "file" | "json" | "geoPoint";
|
|
12
|
+
/**
|
|
13
|
+
* Field metadata structure embedded in Zod schema descriptions
|
|
14
|
+
*/
|
|
15
|
+
interface FieldMetadata {
|
|
16
|
+
type: PocketBaseFieldType;
|
|
17
|
+
options?: Record<string, any>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Extracts field metadata from a Zod type's description
|
|
21
|
+
* Used by the migration generator to detect explicit field type definitions
|
|
22
|
+
*
|
|
23
|
+
* @param description - The Zod type's description string
|
|
24
|
+
* @returns Field metadata if present, null otherwise
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* const schema = TextField({ min: 1, max: 100 });
|
|
28
|
+
* const metadata = extractFieldMetadata(schema.description);
|
|
29
|
+
* // Returns: { type: "text", options: { min: 1, max: 100 } }
|
|
30
|
+
*/
|
|
31
|
+
declare function extractFieldMetadata(description: string | undefined): FieldMetadata | null;
|
|
32
|
+
/**
|
|
33
|
+
* Text field configuration options
|
|
34
|
+
*/
|
|
35
|
+
interface TextFieldOptions {
|
|
36
|
+
/**
|
|
37
|
+
* Minimum length constraint
|
|
38
|
+
*/
|
|
39
|
+
min?: number;
|
|
40
|
+
/**
|
|
41
|
+
* Maximum length constraint
|
|
42
|
+
*/
|
|
43
|
+
max?: number;
|
|
44
|
+
/**
|
|
45
|
+
* Pattern constraint (regex)
|
|
46
|
+
*/
|
|
47
|
+
pattern?: RegExp | string;
|
|
48
|
+
/**
|
|
49
|
+
* Auto-generate pattern for automatic value generation
|
|
50
|
+
* Example: "[A-Z]{3}-[0-9]{6}" generates values like "ABC-123456"
|
|
51
|
+
*/
|
|
52
|
+
autogeneratePattern?: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Number field configuration options
|
|
56
|
+
*/
|
|
57
|
+
interface NumberFieldOptions {
|
|
58
|
+
/**
|
|
59
|
+
* Minimum value constraint
|
|
60
|
+
*/
|
|
61
|
+
min?: number;
|
|
62
|
+
/**
|
|
63
|
+
* Maximum value constraint
|
|
64
|
+
*/
|
|
65
|
+
max?: number;
|
|
66
|
+
/**
|
|
67
|
+
* Whether to disallow decimal values (integers only)
|
|
68
|
+
*/
|
|
69
|
+
noDecimal?: boolean;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Date field configuration options
|
|
73
|
+
*/
|
|
74
|
+
interface DateFieldOptions {
|
|
75
|
+
/**
|
|
76
|
+
* Minimum date constraint
|
|
77
|
+
*/
|
|
78
|
+
min?: Date | string;
|
|
79
|
+
/**
|
|
80
|
+
* Maximum date constraint
|
|
81
|
+
*/
|
|
82
|
+
max?: Date | string;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Autodate field configuration options
|
|
86
|
+
*/
|
|
87
|
+
interface AutodateFieldOptions {
|
|
88
|
+
/**
|
|
89
|
+
* Set date automatically on record creation
|
|
90
|
+
* @default false
|
|
91
|
+
*/
|
|
92
|
+
onCreate?: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Update date automatically on record update
|
|
95
|
+
* @default false
|
|
96
|
+
*/
|
|
97
|
+
onUpdate?: boolean;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Select field configuration options
|
|
101
|
+
*/
|
|
102
|
+
interface SelectFieldOptions {
|
|
103
|
+
/**
|
|
104
|
+
* Maximum number of selections allowed
|
|
105
|
+
* If > 1, enables multiple selection
|
|
106
|
+
* @default 1
|
|
107
|
+
*/
|
|
108
|
+
maxSelect?: number;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* File field configuration options
|
|
112
|
+
*/
|
|
113
|
+
interface FileFieldOptions {
|
|
114
|
+
/**
|
|
115
|
+
* Allowed MIME types
|
|
116
|
+
* Example: ["image/*", "application/pdf"]
|
|
117
|
+
*/
|
|
118
|
+
mimeTypes?: string[];
|
|
119
|
+
/**
|
|
120
|
+
* Maximum file size in bytes
|
|
121
|
+
*/
|
|
122
|
+
maxSize?: number;
|
|
123
|
+
/**
|
|
124
|
+
* Thumbnail sizes to generate
|
|
125
|
+
* Example: ["100x100", "200x200"]
|
|
126
|
+
*/
|
|
127
|
+
thumbs?: string[];
|
|
128
|
+
/**
|
|
129
|
+
* Whether the file is protected (requires auth to access)
|
|
130
|
+
* @default false
|
|
131
|
+
*/
|
|
132
|
+
protected?: boolean;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Multiple files field configuration options
|
|
136
|
+
*/
|
|
137
|
+
interface FilesFieldOptions extends FileFieldOptions {
|
|
138
|
+
/**
|
|
139
|
+
* Minimum number of files required
|
|
140
|
+
*/
|
|
141
|
+
minSelect?: number;
|
|
142
|
+
/**
|
|
143
|
+
* Maximum number of files allowed
|
|
144
|
+
*/
|
|
145
|
+
maxSelect?: number;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Creates a boolean field schema
|
|
149
|
+
* Maps to PocketBase 'bool' field type
|
|
150
|
+
*
|
|
151
|
+
* @returns Zod boolean schema with PocketBase metadata
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* const ProductSchema = z.object({
|
|
155
|
+
* active: BoolField(),
|
|
156
|
+
* featured: BoolField().optional(),
|
|
157
|
+
* });
|
|
158
|
+
*/
|
|
159
|
+
declare function BoolField(): z.ZodBoolean;
|
|
160
|
+
/**
|
|
161
|
+
* Creates a number field schema with optional constraints
|
|
162
|
+
* Maps to PocketBase 'number' field type
|
|
163
|
+
*
|
|
164
|
+
* @param options - Optional constraints for the number field
|
|
165
|
+
* @returns Zod number schema with PocketBase metadata
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* const ProductSchema = z.object({
|
|
169
|
+
* price: NumberField({ min: 0 }),
|
|
170
|
+
* quantity: NumberField({ min: 0, noDecimal: true }),
|
|
171
|
+
* rating: NumberField({ min: 0, max: 5 }),
|
|
172
|
+
* });
|
|
173
|
+
*/
|
|
174
|
+
declare function NumberField(options?: NumberFieldOptions): z.ZodNumber;
|
|
175
|
+
/**
|
|
176
|
+
* Creates a text field schema with optional constraints
|
|
177
|
+
* Maps to PocketBase 'text' field type
|
|
178
|
+
*
|
|
179
|
+
* @param options - Optional constraints for the text field
|
|
180
|
+
* @returns Zod string schema with PocketBase metadata
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* const ProductSchema = z.object({
|
|
184
|
+
* name: TextField({ min: 1, max: 200 }),
|
|
185
|
+
* sku: TextField({ autogeneratePattern: "[A-Z]{3}-[0-9]{6}" }),
|
|
186
|
+
* description: TextField({ max: 1000 }),
|
|
187
|
+
* });
|
|
188
|
+
*/
|
|
189
|
+
declare function TextField(options?: TextFieldOptions): z.ZodString;
|
|
190
|
+
/**
|
|
191
|
+
* Creates an email field schema
|
|
192
|
+
* Maps to PocketBase 'email' field type
|
|
193
|
+
*
|
|
194
|
+
* @returns Zod string schema with email validation and PocketBase metadata
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* const UserSchema = z.object({
|
|
198
|
+
* email: EmailField(),
|
|
199
|
+
* alternateEmail: EmailField().optional(),
|
|
200
|
+
* });
|
|
201
|
+
*/
|
|
202
|
+
declare function EmailField(): z.ZodString;
|
|
203
|
+
/**
|
|
204
|
+
* Creates a URL field schema
|
|
205
|
+
* Maps to PocketBase 'url' field type
|
|
206
|
+
*
|
|
207
|
+
* @returns Zod string schema with URL validation and PocketBase metadata
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* const ProductSchema = z.object({
|
|
211
|
+
* website: URLField(),
|
|
212
|
+
* documentation: URLField().optional(),
|
|
213
|
+
* });
|
|
214
|
+
*/
|
|
215
|
+
declare function URLField(): z.ZodString;
|
|
216
|
+
/**
|
|
217
|
+
* Creates a rich text editor field schema
|
|
218
|
+
* Maps to PocketBase 'editor' field type
|
|
219
|
+
*
|
|
220
|
+
* @returns Zod string schema with PocketBase metadata
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* const PostSchema = z.object({
|
|
224
|
+
* content: EditorField(),
|
|
225
|
+
* summary: EditorField().optional(),
|
|
226
|
+
* });
|
|
227
|
+
*/
|
|
228
|
+
declare function EditorField(): z.ZodString;
|
|
229
|
+
/**
|
|
230
|
+
* Creates a date field schema with optional constraints
|
|
231
|
+
* Maps to PocketBase 'date' field type
|
|
232
|
+
*
|
|
233
|
+
* @param options - Optional date constraints
|
|
234
|
+
* @returns Zod string schema with PocketBase metadata
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* const EventSchema = z.object({
|
|
238
|
+
* startDate: DateField(),
|
|
239
|
+
* endDate: DateField({ min: new Date('2024-01-01') }),
|
|
240
|
+
* releaseDate: DateField().optional(),
|
|
241
|
+
* });
|
|
242
|
+
*/
|
|
243
|
+
declare function DateField(options?: DateFieldOptions): z.ZodString;
|
|
244
|
+
/**
|
|
245
|
+
* Creates an autodate field schema with automatic timestamp management
|
|
246
|
+
* Maps to PocketBase 'autodate' field type
|
|
247
|
+
*
|
|
248
|
+
* @param options - Optional autodate configuration
|
|
249
|
+
* @returns Zod string schema with PocketBase metadata
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* const PostSchema = z.object({
|
|
253
|
+
* createdAt: AutodateField({ onCreate: true }),
|
|
254
|
+
* updatedAt: AutodateField({ onUpdate: true }),
|
|
255
|
+
* publishedAt: AutodateField({ onCreate: true, onUpdate: false }),
|
|
256
|
+
* });
|
|
257
|
+
*/
|
|
258
|
+
declare function AutodateField(options?: AutodateFieldOptions): z.ZodString;
|
|
259
|
+
/**
|
|
260
|
+
* Creates a select field schema from enum values
|
|
261
|
+
* Maps to PocketBase 'select' field type
|
|
262
|
+
*
|
|
263
|
+
* @param values - Array of allowed string values
|
|
264
|
+
* @param options - Optional select configuration
|
|
265
|
+
* @returns Zod enum or array schema with PocketBase metadata
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* // Single select
|
|
269
|
+
* const PostSchema = z.object({
|
|
270
|
+
* status: SelectField(["draft", "published", "archived"]),
|
|
271
|
+
* });
|
|
272
|
+
*
|
|
273
|
+
* @example
|
|
274
|
+
* // Multiple select
|
|
275
|
+
* const ProductSchema = z.object({
|
|
276
|
+
* categories: SelectField(["electronics", "clothing", "food"], { maxSelect: 3 }),
|
|
277
|
+
* });
|
|
278
|
+
*/
|
|
279
|
+
declare function SelectField<T extends [string, ...string[]]>(values: T, options?: SelectFieldOptions): z.ZodEnum<T> | z.ZodArray<z.ZodEnum<T>>;
|
|
280
|
+
/**
|
|
281
|
+
* Creates a single file field schema
|
|
282
|
+
* Maps to PocketBase 'file' field type with maxSelect=1
|
|
283
|
+
*
|
|
284
|
+
* @param options - Optional file constraints
|
|
285
|
+
* @returns Zod File schema with PocketBase metadata
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* const ProductSchema = z.object({
|
|
289
|
+
* thumbnail: FileField({ mimeTypes: ["image/*"], maxSize: 5242880 }),
|
|
290
|
+
* document: FileField({ mimeTypes: ["application/pdf"] }),
|
|
291
|
+
* });
|
|
292
|
+
*/
|
|
293
|
+
declare function FileField(options?: FileFieldOptions): z.ZodType<File>;
|
|
294
|
+
/**
|
|
295
|
+
* Creates a multiple files field schema
|
|
296
|
+
* Maps to PocketBase 'file' field type with maxSelect>1
|
|
297
|
+
*
|
|
298
|
+
* @param options - Optional file constraints
|
|
299
|
+
* @returns Zod array of File schema with PocketBase metadata
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* const ProductSchema = z.object({
|
|
303
|
+
* images: FilesField({ mimeTypes: ["image/*"], maxSelect: 5 }),
|
|
304
|
+
* attachments: FilesField({ minSelect: 1, maxSelect: 10 }),
|
|
305
|
+
* });
|
|
306
|
+
*/
|
|
307
|
+
declare function FilesField(options?: FilesFieldOptions): z.ZodArray<z.ZodType<File>>;
|
|
308
|
+
/**
|
|
309
|
+
* Creates a JSON field schema with optional inner schema validation
|
|
310
|
+
* Maps to PocketBase 'json' field type
|
|
311
|
+
*
|
|
312
|
+
* @param schema - Optional Zod schema for the JSON structure
|
|
313
|
+
* @returns Zod schema with PocketBase metadata
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* // Any JSON
|
|
317
|
+
* const ProductSchema = z.object({
|
|
318
|
+
* metadata: JSONField(),
|
|
319
|
+
* });
|
|
320
|
+
*
|
|
321
|
+
* @example
|
|
322
|
+
* // Typed JSON
|
|
323
|
+
* const ProductSchema = z.object({
|
|
324
|
+
* settings: JSONField(z.object({
|
|
325
|
+
* theme: z.string(),
|
|
326
|
+
* notifications: z.boolean(),
|
|
327
|
+
* })),
|
|
328
|
+
* });
|
|
329
|
+
*/
|
|
330
|
+
declare function JSONField<T extends z.ZodTypeAny>(schema?: T): T | z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
331
|
+
/**
|
|
332
|
+
* Creates a geographic point field schema
|
|
333
|
+
* Maps to PocketBase 'geoPoint' field type
|
|
334
|
+
*
|
|
335
|
+
* @returns Zod object schema with lon/lat fields and PocketBase metadata
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
* const LocationSchema = z.object({
|
|
339
|
+
* coordinates: GeoPointField(),
|
|
340
|
+
* homeLocation: GeoPointField().optional(),
|
|
341
|
+
* });
|
|
342
|
+
*/
|
|
343
|
+
declare function GeoPointField(): z.ZodObject<{
|
|
344
|
+
lon: z.ZodNumber;
|
|
345
|
+
lat: z.ZodNumber;
|
|
346
|
+
}>;
|
|
347
|
+
|
|
348
|
+
export { type AutodateFieldOptions as A, BoolField as B, type DateFieldOptions as D, EmailField as E, FIELD_METADATA_KEY as F, GeoPointField as G, JSONField as J, type NumberFieldOptions as N, type PocketBaseFieldType as P, type SelectFieldOptions as S, type TextFieldOptions as T, URLField as U, type FieldMetadata as a, type FileFieldOptions as b, type FilesFieldOptions as c, NumberField as d, extractFieldMetadata as e, TextField as f, EditorField as g, DateField as h, AutodateField as i, SelectField as j, FileField as k, FilesField as l };
|