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