pocketbase-zod-schema 0.3.0 → 0.3.2

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.
Files changed (66) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/cli/index.cjs +175 -50
  3. package/dist/cli/index.cjs.map +1 -1
  4. package/dist/cli/index.d.cts +2 -2
  5. package/dist/cli/index.d.ts +2 -2
  6. package/dist/cli/index.js +175 -50
  7. package/dist/cli/index.js.map +1 -1
  8. package/dist/cli/migrate.cjs +175 -50
  9. package/dist/cli/migrate.cjs.map +1 -1
  10. package/dist/cli/migrate.js +175 -50
  11. package/dist/cli/migrate.js.map +1 -1
  12. package/dist/cli/utils/index.d.cts +2 -2
  13. package/dist/cli/utils/index.d.ts +2 -2
  14. package/dist/{fields-UcOPu1OQ.d.cts → fields-DBBm06VU.d.cts} +35 -7
  15. package/dist/{fields-UcOPu1OQ.d.ts → fields-DBBm06VU.d.ts} +35 -7
  16. package/dist/index.cjs +264 -84
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +3 -3
  19. package/dist/index.d.ts +3 -3
  20. package/dist/index.js +264 -84
  21. package/dist/index.js.map +1 -1
  22. package/dist/migration/analyzer.cjs.map +1 -1
  23. package/dist/migration/analyzer.d.cts +2 -2
  24. package/dist/migration/analyzer.d.ts +2 -2
  25. package/dist/migration/analyzer.js.map +1 -1
  26. package/dist/migration/diff.cjs +77 -26
  27. package/dist/migration/diff.cjs.map +1 -1
  28. package/dist/migration/diff.d.cts +4 -4
  29. package/dist/migration/diff.d.ts +4 -4
  30. package/dist/migration/diff.js +77 -26
  31. package/dist/migration/diff.js.map +1 -1
  32. package/dist/migration/generator.cjs +81 -34
  33. package/dist/migration/generator.cjs.map +1 -1
  34. package/dist/migration/generator.d.cts +2 -2
  35. package/dist/migration/generator.d.ts +2 -2
  36. package/dist/migration/generator.js +81 -34
  37. package/dist/migration/generator.js.map +1 -1
  38. package/dist/migration/index.cjs +209 -78
  39. package/dist/migration/index.cjs.map +1 -1
  40. package/dist/migration/index.d.cts +3 -3
  41. package/dist/migration/index.d.ts +3 -3
  42. package/dist/migration/index.js +209 -78
  43. package/dist/migration/index.js.map +1 -1
  44. package/dist/migration/snapshot.cjs +51 -18
  45. package/dist/migration/snapshot.cjs.map +1 -1
  46. package/dist/migration/snapshot.d.cts +2 -2
  47. package/dist/migration/snapshot.d.ts +2 -2
  48. package/dist/migration/snapshot.js +51 -18
  49. package/dist/migration/snapshot.js.map +1 -1
  50. package/dist/migration/utils/index.cjs +5 -3
  51. package/dist/migration/utils/index.cjs.map +1 -1
  52. package/dist/migration/utils/index.d.cts +4 -4
  53. package/dist/migration/utils/index.d.ts +4 -4
  54. package/dist/migration/utils/index.js +5 -3
  55. package/dist/migration/utils/index.js.map +1 -1
  56. package/dist/schema.cjs +55 -6
  57. package/dist/schema.cjs.map +1 -1
  58. package/dist/schema.d.cts +1 -1
  59. package/dist/schema.d.ts +1 -1
  60. package/dist/schema.js +55 -6
  61. package/dist/schema.js.map +1 -1
  62. package/dist/{type-mapper-DrQmtznD.d.cts → type-mapper-DsGgZwUo.d.cts} +1 -1
  63. package/dist/{type-mapper-n231Fspm.d.ts → type-mapper-Dvh4QTM-.d.ts} +1 -1
  64. package/dist/{types-YoBjsa-A.d.cts → types-CVxPCgWX.d.cts} +1 -1
  65. package/dist/{types-Ds3NQvny.d.ts → types-Dfp-NP2D.d.ts} +1 -1
  66. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  import { Ora } from 'ora';
2
- import { e as SchemaDiff } from '../../types-YoBjsa-A.cjs';
3
- import '../../fields-UcOPu1OQ.cjs';
2
+ import { e as SchemaDiff } from '../../types-CVxPCgWX.cjs';
3
+ import '../../fields-DBBm06VU.cjs';
4
4
  import 'zod';
5
5
  import '../../permissions-ZHafVSIx.cjs';
6
6
 
@@ -1,6 +1,6 @@
1
1
  import { Ora } from 'ora';
2
- import { e as SchemaDiff } from '../../types-Ds3NQvny.js';
3
- import '../../fields-UcOPu1OQ.js';
2
+ import { e as SchemaDiff } from '../../types-Dfp-NP2D.js';
3
+ import '../../fields-DBBm06VU.js';
4
4
  import 'zod';
5
5
  import '../../permissions-ZHafVSIx.js';
6
6
 
@@ -116,6 +116,15 @@ interface SelectFieldOptions {
116
116
  */
117
117
  maxSelect?: number;
118
118
  }
119
+ /**
120
+ * Human-friendly byte size input.
121
+ *
122
+ * - Use a number for raw bytes (e.g. `5242880`)
123
+ * - Use a string with unit suffix for kibibytes/mebibytes/gibibytes (e.g. `"5M"`, `"1G"`)
124
+ *
125
+ * Supported suffixes: `K`, `M`, `G` (case-insensitive).
126
+ */
127
+ type ByteSize = number | `${number}${"K" | "M" | "G" | "k" | "m" | "g"}`;
119
128
  /**
120
129
  * File field configuration options
121
130
  */
@@ -126,12 +135,23 @@ interface FileFieldOptions {
126
135
  */
127
136
  mimeTypes?: string[];
128
137
  /**
129
- * Maximum file size in bytes
138
+ * Maximum file size.
139
+ *
140
+ * - Provide a number for raw bytes
141
+ * - Or use a string with `K`, `M`, `G` suffix (case-insensitive)
142
+ *
143
+ * Max allowed is `8G`.
144
+ *
145
+ * @example
146
+ * maxSize: 5242880
147
+ * maxSize: "5M"
148
+ * maxSize: "1G"
130
149
  */
131
- maxSize?: number;
150
+ maxSize?: ByteSize;
132
151
  /**
133
152
  * Thumbnail sizes to generate
134
153
  * Example: ["100x100", "200x200"]
154
+ * Set to null to explicitly disable thumbnails
135
155
  */
136
156
  thumbs?: string[];
137
157
  /**
@@ -298,29 +318,37 @@ declare function SelectField<T extends [string, ...string[]]>(values: T, options
298
318
  * Maps to PocketBase 'file' field type with maxSelect=1
299
319
  *
300
320
  * @param options - Optional file constraints
301
- * @returns Zod File schema with PocketBase metadata
321
+ * @returns Zod schema that accepts File on input and returns string when reading from database
302
322
  *
303
323
  * @example
304
324
  * const ProductSchema = z.object({
305
325
  * thumbnail: FileField({ mimeTypes: ["image/*"], maxSize: 5242880 }),
306
326
  * document: FileField({ mimeTypes: ["application/pdf"] }),
307
327
  * });
328
+ *
329
+ * @remarks
330
+ * - When creating/updating records: accepts File objects
331
+ * - When reading from PocketBase: returns string (filename)
308
332
  */
309
- declare function FileField(options?: FileFieldOptions): z.ZodType<File>;
333
+ declare function FileField(options?: FileFieldOptions): z.ZodType<string, z.ZodTypeDef, File | string>;
310
334
  /**
311
335
  * Creates a multiple files field schema
312
336
  * Maps to PocketBase 'file' field type with maxSelect>1
313
337
  *
314
338
  * @param options - Optional file constraints
315
- * @returns Zod array of File schema with PocketBase metadata
339
+ * @returns Zod array schema that accepts File[] on input and returns string[] when reading from database
316
340
  *
317
341
  * @example
318
342
  * const ProductSchema = z.object({
319
343
  * images: FilesField({ mimeTypes: ["image/*"], maxSelect: 5 }),
320
344
  * attachments: FilesField({ minSelect: 1, maxSelect: 10 }),
321
345
  * });
346
+ *
347
+ * @remarks
348
+ * - When creating/updating records: accepts File[]
349
+ * - When reading from PocketBase: returns string[] (filenames)
322
350
  */
323
- declare function FilesField(options?: FilesFieldOptions): z.ZodArray<z.ZodType<File>>;
351
+ declare function FilesField(options?: FilesFieldOptions): z.ZodType<string[], z.ZodTypeDef, (File | string)[]>;
324
352
  /**
325
353
  * Creates a JSON field schema with optional inner schema validation
326
354
  * Maps to PocketBase 'json' field type
@@ -361,4 +389,4 @@ declare function GeoPointField(): z.ZodObject<{
361
389
  lat: z.ZodNumber;
362
390
  }>;
363
391
 
364
- 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 };
392
+ export { type AutodateFieldOptions as A, type ByteSize 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, BoolField as d, extractFieldMetadata as e, NumberField as f, TextField as g, EditorField as h, DateField as i, AutodateField as j, SelectField as k, FileField as l, FilesField as m };
@@ -116,6 +116,15 @@ interface SelectFieldOptions {
116
116
  */
117
117
  maxSelect?: number;
118
118
  }
119
+ /**
120
+ * Human-friendly byte size input.
121
+ *
122
+ * - Use a number for raw bytes (e.g. `5242880`)
123
+ * - Use a string with unit suffix for kibibytes/mebibytes/gibibytes (e.g. `"5M"`, `"1G"`)
124
+ *
125
+ * Supported suffixes: `K`, `M`, `G` (case-insensitive).
126
+ */
127
+ type ByteSize = number | `${number}${"K" | "M" | "G" | "k" | "m" | "g"}`;
119
128
  /**
120
129
  * File field configuration options
121
130
  */
@@ -126,12 +135,23 @@ interface FileFieldOptions {
126
135
  */
127
136
  mimeTypes?: string[];
128
137
  /**
129
- * Maximum file size in bytes
138
+ * Maximum file size.
139
+ *
140
+ * - Provide a number for raw bytes
141
+ * - Or use a string with `K`, `M`, `G` suffix (case-insensitive)
142
+ *
143
+ * Max allowed is `8G`.
144
+ *
145
+ * @example
146
+ * maxSize: 5242880
147
+ * maxSize: "5M"
148
+ * maxSize: "1G"
130
149
  */
131
- maxSize?: number;
150
+ maxSize?: ByteSize;
132
151
  /**
133
152
  * Thumbnail sizes to generate
134
153
  * Example: ["100x100", "200x200"]
154
+ * Set to null to explicitly disable thumbnails
135
155
  */
136
156
  thumbs?: string[];
137
157
  /**
@@ -298,29 +318,37 @@ declare function SelectField<T extends [string, ...string[]]>(values: T, options
298
318
  * Maps to PocketBase 'file' field type with maxSelect=1
299
319
  *
300
320
  * @param options - Optional file constraints
301
- * @returns Zod File schema with PocketBase metadata
321
+ * @returns Zod schema that accepts File on input and returns string when reading from database
302
322
  *
303
323
  * @example
304
324
  * const ProductSchema = z.object({
305
325
  * thumbnail: FileField({ mimeTypes: ["image/*"], maxSize: 5242880 }),
306
326
  * document: FileField({ mimeTypes: ["application/pdf"] }),
307
327
  * });
328
+ *
329
+ * @remarks
330
+ * - When creating/updating records: accepts File objects
331
+ * - When reading from PocketBase: returns string (filename)
308
332
  */
309
- declare function FileField(options?: FileFieldOptions): z.ZodType<File>;
333
+ declare function FileField(options?: FileFieldOptions): z.ZodType<string, z.ZodTypeDef, File | string>;
310
334
  /**
311
335
  * Creates a multiple files field schema
312
336
  * Maps to PocketBase 'file' field type with maxSelect>1
313
337
  *
314
338
  * @param options - Optional file constraints
315
- * @returns Zod array of File schema with PocketBase metadata
339
+ * @returns Zod array schema that accepts File[] on input and returns string[] when reading from database
316
340
  *
317
341
  * @example
318
342
  * const ProductSchema = z.object({
319
343
  * images: FilesField({ mimeTypes: ["image/*"], maxSelect: 5 }),
320
344
  * attachments: FilesField({ minSelect: 1, maxSelect: 10 }),
321
345
  * });
346
+ *
347
+ * @remarks
348
+ * - When creating/updating records: accepts File[]
349
+ * - When reading from PocketBase: returns string[] (filenames)
322
350
  */
323
- declare function FilesField(options?: FilesFieldOptions): z.ZodArray<z.ZodType<File>>;
351
+ declare function FilesField(options?: FilesFieldOptions): z.ZodType<string[], z.ZodTypeDef, (File | string)[]>;
324
352
  /**
325
353
  * Creates a JSON field schema with optional inner schema validation
326
354
  * Maps to PocketBase 'json' field type
@@ -361,4 +389,4 @@ declare function GeoPointField(): z.ZodObject<{
361
389
  lat: z.ZodNumber;
362
390
  }>;
363
391
 
364
- 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 };
392
+ export { type AutodateFieldOptions as A, type ByteSize 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, BoolField as d, extractFieldMetadata as e, NumberField as f, TextField as g, EditorField as h, DateField as i, AutodateField as j, SelectField as k, FileField as l, FilesField as m };