pocketbase-zod-schema 0.1.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 (94) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/LICENSE +21 -0
  3. package/README.md +167 -0
  4. package/dist/cli/index.cjs +3383 -0
  5. package/dist/cli/index.cjs.map +1 -0
  6. package/dist/cli/index.d.cts +30 -0
  7. package/dist/cli/index.d.ts +30 -0
  8. package/dist/cli/index.js +3331 -0
  9. package/dist/cli/index.js.map +1 -0
  10. package/dist/cli/migrate.cjs +3380 -0
  11. package/dist/cli/migrate.cjs.map +1 -0
  12. package/dist/cli/migrate.d.cts +1 -0
  13. package/dist/cli/migrate.d.ts +1 -0
  14. package/dist/cli/migrate.js +3353 -0
  15. package/dist/cli/migrate.js.map +1 -0
  16. package/dist/cli/utils/index.cjs +540 -0
  17. package/dist/cli/utils/index.cjs.map +1 -0
  18. package/dist/cli/utils/index.d.cts +232 -0
  19. package/dist/cli/utils/index.d.ts +232 -0
  20. package/dist/cli/utils/index.js +487 -0
  21. package/dist/cli/utils/index.js.map +1 -0
  22. package/dist/enums.cjs +19 -0
  23. package/dist/enums.cjs.map +1 -0
  24. package/dist/enums.d.cts +6 -0
  25. package/dist/enums.d.ts +6 -0
  26. package/dist/enums.js +17 -0
  27. package/dist/enums.js.map +1 -0
  28. package/dist/index.cjs +4900 -0
  29. package/dist/index.cjs.map +1 -0
  30. package/dist/index.d.cts +18 -0
  31. package/dist/index.d.ts +18 -0
  32. package/dist/index.js +4726 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/migration/analyzer.cjs +1267 -0
  35. package/dist/migration/analyzer.cjs.map +1 -0
  36. package/dist/migration/analyzer.d.cts +186 -0
  37. package/dist/migration/analyzer.d.ts +186 -0
  38. package/dist/migration/analyzer.js +1232 -0
  39. package/dist/migration/analyzer.js.map +1 -0
  40. package/dist/migration/diff.cjs +557 -0
  41. package/dist/migration/diff.cjs.map +1 -0
  42. package/dist/migration/diff.d.cts +291 -0
  43. package/dist/migration/diff.d.ts +291 -0
  44. package/dist/migration/diff.js +534 -0
  45. package/dist/migration/diff.js.map +1 -0
  46. package/dist/migration/generator.cjs +778 -0
  47. package/dist/migration/generator.cjs.map +1 -0
  48. package/dist/migration/generator.d.cts +225 -0
  49. package/dist/migration/generator.d.ts +225 -0
  50. package/dist/migration/generator.js +737 -0
  51. package/dist/migration/generator.js.map +1 -0
  52. package/dist/migration/index.cjs +3390 -0
  53. package/dist/migration/index.cjs.map +1 -0
  54. package/dist/migration/index.d.cts +103 -0
  55. package/dist/migration/index.d.ts +103 -0
  56. package/dist/migration/index.js +3265 -0
  57. package/dist/migration/index.js.map +1 -0
  58. package/dist/migration/snapshot.cjs +609 -0
  59. package/dist/migration/snapshot.cjs.map +1 -0
  60. package/dist/migration/snapshot.d.cts +167 -0
  61. package/dist/migration/snapshot.d.ts +167 -0
  62. package/dist/migration/snapshot.js +575 -0
  63. package/dist/migration/snapshot.js.map +1 -0
  64. package/dist/migration/utils/index.cjs +672 -0
  65. package/dist/migration/utils/index.cjs.map +1 -0
  66. package/dist/migration/utils/index.d.cts +207 -0
  67. package/dist/migration/utils/index.d.ts +207 -0
  68. package/dist/migration/utils/index.js +641 -0
  69. package/dist/migration/utils/index.js.map +1 -0
  70. package/dist/mutator.cjs +427 -0
  71. package/dist/mutator.cjs.map +1 -0
  72. package/dist/mutator.d.cts +190 -0
  73. package/dist/mutator.d.ts +190 -0
  74. package/dist/mutator.js +425 -0
  75. package/dist/mutator.js.map +1 -0
  76. package/dist/permissions-ZHafVSIx.d.cts +71 -0
  77. package/dist/permissions-ZHafVSIx.d.ts +71 -0
  78. package/dist/schema.cjs +430 -0
  79. package/dist/schema.cjs.map +1 -0
  80. package/dist/schema.d.cts +316 -0
  81. package/dist/schema.d.ts +316 -0
  82. package/dist/schema.js +396 -0
  83. package/dist/schema.js.map +1 -0
  84. package/dist/types-BbTgmg6H.d.cts +91 -0
  85. package/dist/types-z1Dkjg8m.d.ts +91 -0
  86. package/dist/types.cjs +4 -0
  87. package/dist/types.cjs.map +1 -0
  88. package/dist/types.d.cts +14 -0
  89. package/dist/types.d.ts +14 -0
  90. package/dist/types.js +3 -0
  91. package/dist/types.js.map +1 -0
  92. package/dist/user-jS1aYoeD.d.cts +123 -0
  93. package/dist/user-jS1aYoeD.d.ts +123 -0
  94. package/package.json +165 -0
@@ -0,0 +1,641 @@
1
+ import { z } from 'zod';
2
+
3
+ // src/migration/utils/pluralize.ts
4
+ var SPECIAL_CASES = {
5
+ // Common irregular plurals
6
+ person: "people",
7
+ Person: "People",
8
+ child: "children",
9
+ Child: "Children",
10
+ man: "men",
11
+ Man: "Men",
12
+ woman: "women",
13
+ Woman: "Women",
14
+ tooth: "teeth",
15
+ Tooth: "Teeth",
16
+ foot: "feet",
17
+ Foot: "Feet",
18
+ mouse: "mice",
19
+ Mouse: "Mice",
20
+ goose: "geese",
21
+ Goose: "Geese",
22
+ // Words ending in -y
23
+ category: "categories",
24
+ Category: "Categories",
25
+ company: "companies",
26
+ Company: "Companies",
27
+ city: "cities",
28
+ City: "Cities",
29
+ country: "countries",
30
+ Country: "Countries",
31
+ story: "stories",
32
+ Story: "Stories",
33
+ party: "parties",
34
+ Party: "Parties",
35
+ family: "families",
36
+ Family: "Families",
37
+ activity: "activities",
38
+ Activity: "Activities",
39
+ priority: "priorities",
40
+ Priority: "Priorities",
41
+ // Words ending in -f or -fe
42
+ life: "lives",
43
+ Life: "Lives",
44
+ wife: "wives",
45
+ Wife: "Wives",
46
+ knife: "knives",
47
+ Knife: "Knives",
48
+ leaf: "leaves",
49
+ Leaf: "Leaves",
50
+ shelf: "shelves",
51
+ Shelf: "Shelves",
52
+ half: "halves",
53
+ Half: "Halves",
54
+ // Words ending in -is
55
+ analysis: "analyses",
56
+ Analysis: "Analyses",
57
+ basis: "bases",
58
+ Basis: "Bases",
59
+ crisis: "crises",
60
+ Crisis: "Crises",
61
+ thesis: "theses",
62
+ Thesis: "Theses",
63
+ // Words ending in -us
64
+ cactus: "cacti",
65
+ Cactus: "Cacti",
66
+ focus: "foci",
67
+ Focus: "Foci",
68
+ fungus: "fungi",
69
+ Fungus: "Fungi",
70
+ nucleus: "nuclei",
71
+ Nucleus: "Nuclei",
72
+ radius: "radii",
73
+ Radius: "Radii",
74
+ // Words ending in -on
75
+ phenomenon: "phenomena",
76
+ Phenomenon: "Phenomena",
77
+ criterion: "criteria",
78
+ Criterion: "Criteria",
79
+ // Words ending in -um
80
+ datum: "data",
81
+ Datum: "Data",
82
+ medium: "media",
83
+ Medium: "Media",
84
+ curriculum: "curricula",
85
+ Curriculum: "Curricula",
86
+ // Unchanged plurals
87
+ sheep: "sheep",
88
+ Sheep: "Sheep",
89
+ deer: "deer",
90
+ Deer: "Deer",
91
+ fish: "fish",
92
+ Fish: "Fish",
93
+ species: "species",
94
+ Species: "Species",
95
+ series: "series",
96
+ Series: "Series"
97
+ };
98
+ function pluralize(singular) {
99
+ if (SPECIAL_CASES[singular]) {
100
+ return SPECIAL_CASES[singular];
101
+ }
102
+ if (singular.length > 3 && singular.endsWith("s") && !singular.endsWith("ss")) {
103
+ return singular;
104
+ }
105
+ const lowerSingular = singular.toLowerCase();
106
+ let plural;
107
+ if (/(?:s|ss|sh|ch|x|z)$/.test(lowerSingular)) {
108
+ plural = singular + "es";
109
+ } else if (/[^aeiou]y$/.test(lowerSingular)) {
110
+ plural = singular.slice(0, -1) + "ies";
111
+ } else if (/[^aeiou]o$/.test(lowerSingular)) {
112
+ plural = singular + "es";
113
+ } else if (/fe?$/.test(lowerSingular)) {
114
+ if (lowerSingular.endsWith("fe")) {
115
+ plural = singular.slice(0, -2) + "ves";
116
+ } else {
117
+ plural = singular.slice(0, -1) + "ves";
118
+ }
119
+ } else {
120
+ plural = singular + "s";
121
+ }
122
+ return plural;
123
+ }
124
+ function toCollectionName(entityName) {
125
+ return pluralize(entityName);
126
+ }
127
+ function singularize(plural) {
128
+ for (const [singular, pluralForm] of Object.entries(SPECIAL_CASES)) {
129
+ if (pluralForm === plural) {
130
+ return singular;
131
+ }
132
+ }
133
+ const lower = plural.toLowerCase();
134
+ if (lower.endsWith("ies") && plural.length > 3) {
135
+ return plural.slice(0, -3) + "y";
136
+ }
137
+ if (lower.endsWith("ves")) {
138
+ return plural.slice(0, -3) + "fe";
139
+ }
140
+ if (/(?:ses|shes|ches|xes|zes)$/.test(lower)) {
141
+ return plural.slice(0, -2);
142
+ }
143
+ if (lower.endsWith("s") && plural.length > 1) {
144
+ return plural.slice(0, -1);
145
+ }
146
+ return plural;
147
+ }
148
+ function isSingleRelationField(fieldName, zodType) {
149
+ let unwrappedType = zodType;
150
+ if (zodType instanceof z.ZodOptional) {
151
+ unwrappedType = zodType._def.innerType;
152
+ }
153
+ if (unwrappedType instanceof z.ZodNullable) {
154
+ unwrappedType = unwrappedType._def.innerType;
155
+ }
156
+ if (unwrappedType instanceof z.ZodDefault) {
157
+ unwrappedType = unwrappedType._def.innerType;
158
+ }
159
+ if (!(unwrappedType instanceof z.ZodString)) {
160
+ return false;
161
+ }
162
+ const startsWithUppercase = /^[A-Z]/.test(fieldName);
163
+ const commonStringFields = ["Title", "Name", "Description", "Content", "Summary", "Status", "Type"];
164
+ const isCommonField = commonStringFields.includes(fieldName);
165
+ return startsWithUppercase && !isCommonField;
166
+ }
167
+ function isMultipleRelationField(fieldName, zodType) {
168
+ let unwrappedType = zodType;
169
+ if (zodType instanceof z.ZodOptional) {
170
+ unwrappedType = zodType._def.innerType;
171
+ }
172
+ if (unwrappedType instanceof z.ZodNullable) {
173
+ unwrappedType = unwrappedType._def.innerType;
174
+ }
175
+ if (unwrappedType instanceof z.ZodDefault) {
176
+ unwrappedType = unwrappedType._def.innerType;
177
+ }
178
+ if (!(unwrappedType instanceof z.ZodArray)) {
179
+ return false;
180
+ }
181
+ const elementType = unwrappedType._def.type;
182
+ if (!(elementType instanceof z.ZodString)) {
183
+ return false;
184
+ }
185
+ const hasUppercase = /[A-Z]/.test(fieldName);
186
+ return hasUppercase;
187
+ }
188
+ function resolveTargetCollection(fieldName) {
189
+ const matches = fieldName.match(/[A-Z][a-z]+/g);
190
+ if (!matches || matches.length === 0) {
191
+ return pluralize(fieldName);
192
+ }
193
+ const entityName = matches[matches.length - 1];
194
+ return pluralize(entityName);
195
+ }
196
+ function isRelationField(fieldName, zodType) {
197
+ return isSingleRelationField(fieldName, zodType) || isMultipleRelationField(fieldName, zodType);
198
+ }
199
+ function getMaxSelect(fieldName, zodType) {
200
+ if (isSingleRelationField(fieldName, zodType)) {
201
+ return 1;
202
+ }
203
+ if (isMultipleRelationField(fieldName, zodType)) {
204
+ let unwrappedType = zodType;
205
+ if (zodType instanceof z.ZodOptional) {
206
+ unwrappedType = zodType._def.innerType;
207
+ }
208
+ if (unwrappedType instanceof z.ZodNullable) {
209
+ unwrappedType = unwrappedType._def.innerType;
210
+ }
211
+ if (unwrappedType instanceof z.ZodDefault) {
212
+ unwrappedType = unwrappedType._def.innerType;
213
+ }
214
+ if (unwrappedType instanceof z.ZodArray) {
215
+ const arrayDef = unwrappedType._def;
216
+ if (arrayDef.maxLength) {
217
+ return arrayDef.maxLength.value;
218
+ }
219
+ return 999;
220
+ }
221
+ }
222
+ return 1;
223
+ }
224
+ function getMinSelect(fieldName, zodType) {
225
+ if (!isMultipleRelationField(fieldName, zodType)) {
226
+ return void 0;
227
+ }
228
+ let unwrappedType = zodType;
229
+ if (zodType instanceof z.ZodOptional) {
230
+ unwrappedType = zodType._def.innerType;
231
+ }
232
+ if (unwrappedType instanceof z.ZodNullable) {
233
+ unwrappedType = unwrappedType._def.innerType;
234
+ }
235
+ if (unwrappedType instanceof z.ZodDefault) {
236
+ unwrappedType = unwrappedType._def.innerType;
237
+ }
238
+ if (unwrappedType instanceof z.ZodArray) {
239
+ const arrayDef = unwrappedType._def;
240
+ if (arrayDef.minLength) {
241
+ return arrayDef.minLength.value;
242
+ }
243
+ }
244
+ return void 0;
245
+ }
246
+ var POCKETBASE_FIELD_TYPES = [
247
+ "text",
248
+ "email",
249
+ "url",
250
+ "number",
251
+ "bool",
252
+ "date",
253
+ "select",
254
+ "relation",
255
+ "file",
256
+ "json",
257
+ "editor",
258
+ "geoPoint",
259
+ "autodate"
260
+ ];
261
+ var FIELD_TYPE_INFO = {
262
+ text: {
263
+ type: "text",
264
+ description: "Plain text field",
265
+ zodTypes: ["ZodString"],
266
+ supportsMultiple: false
267
+ },
268
+ email: {
269
+ type: "email",
270
+ description: "Email address field with validation",
271
+ zodTypes: ["ZodString with email()"],
272
+ supportsMultiple: false
273
+ },
274
+ url: {
275
+ type: "url",
276
+ description: "URL field with validation",
277
+ zodTypes: ["ZodString with url()"],
278
+ supportsMultiple: false
279
+ },
280
+ editor: {
281
+ type: "editor",
282
+ description: "Rich text editor field",
283
+ zodTypes: ["ZodString"],
284
+ supportsMultiple: false
285
+ },
286
+ number: {
287
+ type: "number",
288
+ description: "Numeric field (integer or float)",
289
+ zodTypes: ["ZodNumber"],
290
+ supportsMultiple: false
291
+ },
292
+ bool: {
293
+ type: "bool",
294
+ description: "Boolean field",
295
+ zodTypes: ["ZodBoolean"],
296
+ supportsMultiple: false
297
+ },
298
+ date: {
299
+ type: "date",
300
+ description: "Date/datetime field",
301
+ zodTypes: ["ZodDate", "ZodString with datetime format"],
302
+ supportsMultiple: false
303
+ },
304
+ autodate: {
305
+ type: "autodate",
306
+ description: "Auto-managed date field (created/updated)",
307
+ zodTypes: ["ZodString"],
308
+ supportsMultiple: false
309
+ },
310
+ select: {
311
+ type: "select",
312
+ description: "Single or multiple select from predefined values",
313
+ zodTypes: ["ZodEnum", "ZodArray<ZodEnum>"],
314
+ supportsMultiple: true
315
+ },
316
+ relation: {
317
+ type: "relation",
318
+ description: "Reference to another collection",
319
+ zodTypes: ["ZodString", "ZodArray<ZodString>"],
320
+ supportsMultiple: true
321
+ },
322
+ file: {
323
+ type: "file",
324
+ description: "File upload field",
325
+ zodTypes: ["File", "ZodArray<File>"],
326
+ supportsMultiple: true
327
+ },
328
+ json: {
329
+ type: "json",
330
+ description: "JSON data field",
331
+ zodTypes: ["ZodRecord", "ZodObject", "ZodArray"],
332
+ supportsMultiple: false
333
+ },
334
+ geoPoint: {
335
+ type: "geoPoint",
336
+ description: "Geographic coordinates (lon, lat)",
337
+ zodTypes: ["ZodObject with lon/lat"],
338
+ supportsMultiple: false
339
+ }
340
+ };
341
+ function mapZodStringType(zodType) {
342
+ const checks = zodType._def.checks || [];
343
+ const hasEmail = checks.some((check) => check.kind === "email");
344
+ if (hasEmail) {
345
+ return "email";
346
+ }
347
+ const hasUrl = checks.some((check) => check.kind === "url");
348
+ if (hasUrl) {
349
+ return "url";
350
+ }
351
+ const hasDatetime = checks.some((check) => check.kind === "datetime");
352
+ if (hasDatetime) {
353
+ return "date";
354
+ }
355
+ return "text";
356
+ }
357
+ function mapZodNumberType(_zodType) {
358
+ return "number";
359
+ }
360
+ function mapZodBooleanType(_zodType) {
361
+ return "bool";
362
+ }
363
+ function mapZodEnumType(_zodType) {
364
+ return "select";
365
+ }
366
+ function mapZodArrayType(zodType, _fieldName) {
367
+ const elementType = zodType._def.type;
368
+ if (elementType instanceof z.ZodType) {
369
+ const typeName = elementType._def.typeName;
370
+ if (typeName === "ZodType" && elementType._def?.innerType?.name === "File") {
371
+ return "file";
372
+ }
373
+ }
374
+ if (elementType._def?.typeName === "ZodType") {
375
+ const checks = elementType._def?.checks || [];
376
+ const isFileInstance = checks.some(
377
+ (check) => check.kind === "instanceof" || elementType._def?.innerType?.name === "File"
378
+ );
379
+ if (isFileInstance) {
380
+ return "file";
381
+ }
382
+ }
383
+ if (elementType instanceof z.ZodString) {
384
+ return "relation";
385
+ }
386
+ return "json";
387
+ }
388
+ function mapZodDateType(_zodType) {
389
+ return "date";
390
+ }
391
+ function mapZodRecordType(_zodType) {
392
+ return "json";
393
+ }
394
+ function mapZodTypeToPocketBase(zodType, fieldName) {
395
+ let unwrappedType = zodType;
396
+ if (zodType instanceof z.ZodOptional) {
397
+ unwrappedType = zodType._def.innerType;
398
+ }
399
+ if (unwrappedType instanceof z.ZodNullable) {
400
+ unwrappedType = unwrappedType._def.innerType;
401
+ }
402
+ if (unwrappedType instanceof z.ZodDefault) {
403
+ unwrappedType = unwrappedType._def.innerType;
404
+ }
405
+ if (unwrappedType._def?.typeName === "ZodEffects") {
406
+ const effect = unwrappedType._def?.effect;
407
+ if (effect?.type === "refinement") {
408
+ const fileFieldNames = ["avatar", "image", "file", "attachment", "photo", "picture", "document", "upload"];
409
+ if (fileFieldNames.some((name) => fieldName.toLowerCase().includes(name))) {
410
+ return "file";
411
+ }
412
+ }
413
+ }
414
+ if (unwrappedType._def?.typeName === "ZodType") {
415
+ const checks = unwrappedType._def?.checks || [];
416
+ const innerType = unwrappedType._def?.innerType;
417
+ if (innerType?.name === "File" || checks.some((check) => check.kind === "instanceof")) {
418
+ return "file";
419
+ }
420
+ }
421
+ if (unwrappedType instanceof z.ZodString) {
422
+ return mapZodStringType(unwrappedType);
423
+ }
424
+ if (unwrappedType instanceof z.ZodNumber) {
425
+ return mapZodNumberType();
426
+ }
427
+ if (unwrappedType instanceof z.ZodBoolean) {
428
+ return mapZodBooleanType();
429
+ }
430
+ if (unwrappedType instanceof z.ZodEnum) {
431
+ return mapZodEnumType();
432
+ }
433
+ if (unwrappedType instanceof z.ZodArray) {
434
+ return mapZodArrayType(unwrappedType);
435
+ }
436
+ if (unwrappedType instanceof z.ZodDate) {
437
+ return mapZodDateType();
438
+ }
439
+ if (unwrappedType instanceof z.ZodRecord || unwrappedType instanceof z.ZodObject) {
440
+ return mapZodRecordType();
441
+ }
442
+ return "text";
443
+ }
444
+ function extractFieldOptions(zodType) {
445
+ const options = {};
446
+ let unwrappedType = zodType;
447
+ if (zodType instanceof z.ZodOptional) {
448
+ unwrappedType = zodType._def.innerType;
449
+ }
450
+ if (unwrappedType instanceof z.ZodNullable) {
451
+ unwrappedType = unwrappedType._def.innerType;
452
+ }
453
+ if (unwrappedType instanceof z.ZodDefault) {
454
+ unwrappedType = unwrappedType._def.innerType;
455
+ }
456
+ const checks = unwrappedType._def?.checks || [];
457
+ if (unwrappedType instanceof z.ZodString) {
458
+ for (const check of checks) {
459
+ if (check.kind === "min") {
460
+ options.min = check.value;
461
+ }
462
+ if (check.kind === "max") {
463
+ options.max = check.value;
464
+ }
465
+ if (check.kind === "regex") {
466
+ options.pattern = check.regex.source;
467
+ }
468
+ }
469
+ }
470
+ if (unwrappedType instanceof z.ZodNumber) {
471
+ for (const check of checks) {
472
+ if (check.kind === "min") {
473
+ options.min = check.value;
474
+ }
475
+ if (check.kind === "max") {
476
+ options.max = check.value;
477
+ }
478
+ }
479
+ }
480
+ if (unwrappedType instanceof z.ZodEnum) {
481
+ options.values = unwrappedType._def.values;
482
+ }
483
+ if (unwrappedType instanceof z.ZodArray) {
484
+ const arrayChecks = unwrappedType._def?.checks || [];
485
+ for (const check of arrayChecks) {
486
+ if (check.kind === "min") {
487
+ options.minSelect = check.value;
488
+ }
489
+ if (check.kind === "max") {
490
+ options.maxSelect = check.value;
491
+ }
492
+ }
493
+ }
494
+ return options;
495
+ }
496
+ function isFieldRequired(zodType) {
497
+ if (zodType instanceof z.ZodOptional) {
498
+ return false;
499
+ }
500
+ if (zodType instanceof z.ZodDefault) {
501
+ return false;
502
+ }
503
+ if (zodType instanceof z.ZodNullable) {
504
+ return false;
505
+ }
506
+ return true;
507
+ }
508
+ function unwrapZodType(zodType) {
509
+ let unwrapped = zodType;
510
+ if (unwrapped instanceof z.ZodOptional) {
511
+ unwrapped = unwrapped._def.innerType;
512
+ }
513
+ if (unwrapped instanceof z.ZodNullable) {
514
+ unwrapped = unwrapped._def.innerType;
515
+ }
516
+ if (unwrapped instanceof z.ZodDefault) {
517
+ unwrapped = unwrapped._def.innerType;
518
+ }
519
+ return unwrapped;
520
+ }
521
+ function getDefaultValue(zodType) {
522
+ if (zodType instanceof z.ZodDefault) {
523
+ return zodType._def.defaultValue();
524
+ }
525
+ return void 0;
526
+ }
527
+ function isArrayType(zodType) {
528
+ const unwrapped = unwrapZodType(zodType);
529
+ return unwrapped instanceof z.ZodArray;
530
+ }
531
+ function getArrayElementType(zodType) {
532
+ const unwrapped = unwrapZodType(zodType);
533
+ if (unwrapped instanceof z.ZodArray) {
534
+ return unwrapped._def.type;
535
+ }
536
+ return null;
537
+ }
538
+ function isGeoPointType(zodType) {
539
+ const unwrapped = unwrapZodType(zodType);
540
+ if (!(unwrapped instanceof z.ZodObject)) {
541
+ return false;
542
+ }
543
+ const shape = unwrapped._def.shape();
544
+ const hasLon = "lon" in shape && shape.lon instanceof z.ZodNumber;
545
+ const hasLat = "lat" in shape && shape.lat instanceof z.ZodNumber;
546
+ return hasLon && hasLat;
547
+ }
548
+ function extractComprehensiveFieldOptions(zodType) {
549
+ const options = {};
550
+ const unwrapped = unwrapZodType(zodType);
551
+ const checks = unwrapped._def?.checks || [];
552
+ if (unwrapped instanceof z.ZodString) {
553
+ for (const check of checks) {
554
+ if (check.kind === "min") {
555
+ options.min = check.value;
556
+ }
557
+ if (check.kind === "max") {
558
+ options.max = check.value;
559
+ }
560
+ if (check.kind === "regex") {
561
+ options.pattern = check.regex.source;
562
+ }
563
+ }
564
+ }
565
+ if (unwrapped instanceof z.ZodNumber) {
566
+ for (const check of checks) {
567
+ if (check.kind === "min") {
568
+ options.min = check.value;
569
+ }
570
+ if (check.kind === "max") {
571
+ options.max = check.value;
572
+ }
573
+ }
574
+ }
575
+ if (unwrapped instanceof z.ZodEnum) {
576
+ options.values = unwrapped._def.values;
577
+ }
578
+ if (unwrapped instanceof z.ZodArray) {
579
+ const arrayDef = unwrapped._def;
580
+ if (arrayDef.minLength) {
581
+ options.minSelect = arrayDef.minLength.value;
582
+ }
583
+ if (arrayDef.maxLength) {
584
+ options.maxSelect = arrayDef.maxLength.value;
585
+ }
586
+ const elementType = arrayDef.type;
587
+ if (elementType instanceof z.ZodEnum) {
588
+ options.values = elementType._def.values;
589
+ }
590
+ }
591
+ return options;
592
+ }
593
+ function isEditorField(fieldName) {
594
+ const editorFieldNames = [
595
+ "content",
596
+ "body",
597
+ "description",
598
+ "bio",
599
+ "about",
600
+ "summary",
601
+ "notes",
602
+ "details",
603
+ "html",
604
+ "richtext",
605
+ "editor"
606
+ ];
607
+ return editorFieldNames.some((name) => fieldName.toLowerCase().includes(name));
608
+ }
609
+ function isFileFieldByName(fieldName) {
610
+ const fileFieldNames = [
611
+ "avatar",
612
+ "image",
613
+ "file",
614
+ "attachment",
615
+ "photo",
616
+ "picture",
617
+ "document",
618
+ "upload",
619
+ "thumbnail",
620
+ "cover",
621
+ "banner",
622
+ "logo",
623
+ "icon",
624
+ "media"
625
+ ];
626
+ return fileFieldNames.some((name) => fieldName.toLowerCase().includes(name));
627
+ }
628
+ function getFieldTypeInfo(zodType, fieldName) {
629
+ const type = mapZodTypeToPocketBase(zodType, fieldName);
630
+ const isMultiple = isArrayType(zodType);
631
+ const options = extractComprehensiveFieldOptions(zodType);
632
+ return {
633
+ type,
634
+ isMultiple,
635
+ options
636
+ };
637
+ }
638
+
639
+ export { FIELD_TYPE_INFO, POCKETBASE_FIELD_TYPES, extractComprehensiveFieldOptions, extractFieldOptions, getArrayElementType, getDefaultValue, getFieldTypeInfo, getMaxSelect, getMinSelect, isArrayType, isEditorField, isFieldRequired, isFileFieldByName, isGeoPointType, isMultipleRelationField, isRelationField, isSingleRelationField, mapZodArrayType, mapZodBooleanType, mapZodDateType, mapZodEnumType, mapZodNumberType, mapZodRecordType, mapZodStringType, mapZodTypeToPocketBase, pluralize, resolveTargetCollection, singularize, toCollectionName, unwrapZodType };
640
+ //# sourceMappingURL=index.js.map
641
+ //# sourceMappingURL=index.js.map