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,316 @@
1
+ import { z } from 'zod';
2
+ import { b as PermissionTemplateConfig, P as PermissionSchema, R as RuleExpression } from './permissions-ZHafVSIx.cjs';
3
+ export { A as APIRuleType, a as PermissionTemplate } from './permissions-ZHafVSIx.cjs';
4
+ export { P as ProjectInputSchema, a as ProjectSchema, U as UserInputSchema, b as UserSchema } from './user-jS1aYoeD.cjs';
5
+
6
+ /**
7
+ * Base schema fields that PocketBase automatically adds to all records
8
+ * These fields are managed by PocketBase and should not be set manually
9
+ */
10
+ declare const baseSchema: {
11
+ id: z.ZodString;
12
+ collectionId: z.ZodString;
13
+ collectionName: z.ZodString;
14
+ expand: z.ZodRecord<z.ZodString, z.ZodAny>;
15
+ };
16
+ /**
17
+ * Extended base schema with timestamp fields
18
+ * Includes created and updated autodate fields
19
+ */
20
+ declare const baseSchemaWithTimestamps: {
21
+ created: z.ZodString;
22
+ updated: z.ZodString;
23
+ id: z.ZodString;
24
+ collectionId: z.ZodString;
25
+ collectionName: z.ZodString;
26
+ expand: z.ZodRecord<z.ZodString, z.ZodAny>;
27
+ };
28
+ /**
29
+ * Base schema for image file collections
30
+ * Extends base schema with thumbnail URL and image files array
31
+ */
32
+ declare const baseImageFileSchema: {
33
+ thumbnailURL: z.ZodOptional<z.ZodString>;
34
+ imageFiles: z.ZodArray<z.ZodString, "many">;
35
+ id: z.ZodString;
36
+ collectionId: z.ZodString;
37
+ collectionName: z.ZodString;
38
+ expand: z.ZodRecord<z.ZodString, z.ZodAny>;
39
+ };
40
+ /**
41
+ * Input schema for image file uploads
42
+ * Used in forms where users upload File objects
43
+ * Requires Node.js 20+ or browser environment with File API
44
+ */
45
+ declare const inputImageFileSchema: {
46
+ imageFiles: z.ZodArray<z.ZodType<File, z.ZodTypeDef, File>, "many">;
47
+ };
48
+ /**
49
+ * Helper constant for omitting image files from schemas
50
+ * Used with Zod's .omit() method
51
+ */
52
+ declare const omitImageFilesSchema: {
53
+ readonly imageFiles: true;
54
+ };
55
+ /**
56
+ * Creates a text field schema with optional constraints
57
+ * @param options - Optional constraints for the text field
58
+ */
59
+ declare function textField(options?: {
60
+ min?: number;
61
+ max?: number;
62
+ pattern?: RegExp;
63
+ }): z.ZodString;
64
+ /**
65
+ * Creates an email field schema
66
+ * Maps to PocketBase 'email' field type
67
+ */
68
+ declare function emailField(): z.ZodString;
69
+ /**
70
+ * Creates a URL field schema
71
+ * Maps to PocketBase 'url' field type
72
+ */
73
+ declare function urlField(): z.ZodString;
74
+ /**
75
+ * Creates a number field schema with optional constraints
76
+ * @param options - Optional constraints for the number field
77
+ */
78
+ declare function numberField(options?: {
79
+ min?: number;
80
+ max?: number;
81
+ }): z.ZodNumber;
82
+ /**
83
+ * Creates a boolean field schema
84
+ * Maps to PocketBase 'bool' field type
85
+ */
86
+ declare function boolField(): z.ZodBoolean;
87
+ /**
88
+ * Creates a date field schema
89
+ * Maps to PocketBase 'date' field type
90
+ */
91
+ declare function dateField(): z.ZodDate;
92
+ /**
93
+ * Creates a select field schema from enum values
94
+ * Maps to PocketBase 'select' field type
95
+ * @param values - Array of allowed string values
96
+ */
97
+ declare function selectField<T extends [string, ...string[]]>(values: T): z.ZodEnum<z.Writeable<T>>;
98
+ /**
99
+ * Creates a JSON field schema
100
+ * Maps to PocketBase 'json' field type
101
+ * @param schema - Optional Zod schema for the JSON structure
102
+ */
103
+ declare function jsonField<T extends z.ZodTypeAny>(schema?: T): z.ZodRecord<z.ZodString, z.ZodAny> | T;
104
+ /**
105
+ * Creates a single file field schema for form input
106
+ * Maps to PocketBase 'file' field type with maxSelect=1
107
+ * Requires Node.js 20+ or browser environment with File API
108
+ */
109
+ declare function fileField(): z.ZodType<File, z.ZodTypeDef, File>;
110
+ /**
111
+ * Creates a multiple file field schema for form input
112
+ * Maps to PocketBase 'file' field type with maxSelect>1
113
+ * Requires Node.js 20+ or browser environment with File API
114
+ * @param options - Optional constraints for the file field
115
+ */
116
+ declare function filesField(options?: {
117
+ min?: number;
118
+ max?: number;
119
+ }): z.ZodArray<z.ZodType<File, z.ZodTypeDef, File>, "many">;
120
+ /**
121
+ * Creates a single relation field schema
122
+ * Maps to PocketBase 'relation' field type with maxSelect=1
123
+ * Field name should start with uppercase to be detected as relation
124
+ */
125
+ declare function relationField(): z.ZodString;
126
+ /**
127
+ * Creates a multiple relation field schema
128
+ * Maps to PocketBase 'relation' field type with maxSelect>1
129
+ * Field name should contain uppercase to be detected as relation
130
+ * @param options - Optional constraints for the relation field
131
+ */
132
+ declare function relationsField(options?: {
133
+ min?: number;
134
+ max?: number;
135
+ }): z.ZodArray<z.ZodString, "many">;
136
+ /**
137
+ * Creates an editor field schema (rich text)
138
+ * Maps to PocketBase 'editor' field type
139
+ */
140
+ declare function editorField(): z.ZodString;
141
+ /**
142
+ * Creates a geo point field schema
143
+ * Maps to PocketBase 'geoPoint' field type
144
+ */
145
+ declare function geoPointField(): z.ZodObject<{
146
+ lon: z.ZodNumber;
147
+ lat: z.ZodNumber;
148
+ }, "strip", z.ZodTypeAny, {
149
+ lon: number;
150
+ lat: number;
151
+ }, {
152
+ lon: number;
153
+ lat: number;
154
+ }>;
155
+ /**
156
+ * Attach permission metadata to a Zod schema
157
+ *
158
+ * This helper function allows you to define PocketBase API rules alongside your
159
+ * entity schema definitions. The permissions are stored as metadata using Zod's
160
+ * describe() method and will be extracted during migration generation.
161
+ *
162
+ * @param schema - The Zod schema to attach permissions to
163
+ * @param config - Either a PermissionTemplateConfig (for template-based permissions)
164
+ * or a PermissionSchema (for custom permissions)
165
+ * @returns The schema with permission metadata attached
166
+ *
167
+ * @example
168
+ * // Using a template
169
+ * const ProjectSchema = withPermissions(
170
+ * z.object({ title: z.string(), User: z.string() }),
171
+ * { template: 'owner-only', ownerField: 'User' }
172
+ * );
173
+ *
174
+ * @example
175
+ * // Using custom rules
176
+ * const ProjectSchema = withPermissions(
177
+ * z.object({ title: z.string() }),
178
+ * { listRule: '@request.auth.id != ""', viewRule: '' }
179
+ * );
180
+ *
181
+ * @example
182
+ * // Using template with custom rule overrides
183
+ * const ProjectSchema = withPermissions(
184
+ * z.object({ title: z.string(), User: z.string() }),
185
+ * {
186
+ * template: 'owner-only',
187
+ * ownerField: 'User',
188
+ * customRules: { listRule: '@request.auth.id != ""' }
189
+ * }
190
+ * );
191
+ */
192
+ declare function withPermissions<T extends z.ZodTypeAny>(schema: T, config: PermissionTemplateConfig | PermissionSchema): T;
193
+ /**
194
+ * Attach index definitions to a Zod schema
195
+ *
196
+ * This helper function allows you to define PocketBase indexes alongside your
197
+ * entity schema definitions. The indexes are stored as metadata using Zod's
198
+ * describe() method and will be extracted during migration generation.
199
+ *
200
+ * @param schema - The Zod schema to attach indexes to
201
+ * @param indexes - Array of PocketBase index SQL statements
202
+ * @returns The schema with index metadata attached
203
+ *
204
+ * @example
205
+ * // Define indexes for a user schema
206
+ * const UserSchema = withIndexes(
207
+ * withPermissions(
208
+ * z.object({ name: z.string(), email: z.string().email() }),
209
+ * userPermissions
210
+ * ),
211
+ * [
212
+ * 'CREATE UNIQUE INDEX idx_users_email ON users (email)',
213
+ * 'CREATE INDEX idx_users_name ON users (name)'
214
+ * ]
215
+ * );
216
+ *
217
+ * @example
218
+ * // Single index
219
+ * const ProjectSchema = withIndexes(
220
+ * ProjectDatabaseSchema,
221
+ * ['CREATE INDEX idx_projects_status ON projects (status)']
222
+ * );
223
+ */
224
+ declare function withIndexes<T extends z.ZodTypeAny>(schema: T, indexes: string[]): T;
225
+
226
+ /**
227
+ * Predefined permission templates for common access control patterns
228
+ */
229
+ declare const PermissionTemplates: {
230
+ /**
231
+ * Public access - anyone can perform all operations
232
+ */
233
+ public: () => PermissionSchema;
234
+ /**
235
+ * Authenticated users only - requires valid authentication for all operations
236
+ */
237
+ authenticated: () => PermissionSchema;
238
+ /**
239
+ * Owner-only access - users can only manage their own records
240
+ * @param ownerField - Name of the relation field pointing to user (default: 'User')
241
+ */
242
+ ownerOnly: (ownerField?: string) => PermissionSchema;
243
+ /**
244
+ * Admin/superuser only access
245
+ * Assumes a 'role' field exists with 'admin' value
246
+ * @param roleField - Name of the role field (default: 'role')
247
+ */
248
+ adminOnly: (roleField?: string) => PermissionSchema;
249
+ /**
250
+ * Public read, authenticated write
251
+ * Anyone can list/view, but only authenticated users can create/update/delete
252
+ */
253
+ readPublic: () => PermissionSchema;
254
+ /**
255
+ * Locked access - only superusers can perform operations
256
+ * All rules are set to null (locked)
257
+ */
258
+ locked: () => PermissionSchema;
259
+ /**
260
+ * Read-only authenticated - authenticated users can read, no write access
261
+ */
262
+ readOnlyAuthenticated: () => PermissionSchema;
263
+ };
264
+ /**
265
+ * Resolve template configuration to concrete permission schema
266
+ * @param config - Template configuration or direct permission schema
267
+ * @returns Resolved permission schema with all rules defined
268
+ */
269
+ declare function resolveTemplate(config: PermissionTemplateConfig): PermissionSchema;
270
+ /**
271
+ * Check if a configuration is a template config or direct permission schema
272
+ * @param config - Configuration to check
273
+ * @returns True if it's a template configuration
274
+ */
275
+ declare function isTemplateConfig(config: PermissionTemplateConfig | PermissionSchema): config is PermissionTemplateConfig;
276
+ /**
277
+ * Check if a configuration is a direct permission schema
278
+ * @param config - Configuration to check
279
+ * @returns True if it's a direct permission schema
280
+ */
281
+ declare function isPermissionSchema(config: PermissionTemplateConfig | PermissionSchema): config is PermissionSchema;
282
+ /**
283
+ * Validation result for permission configuration
284
+ */
285
+ interface PermissionValidationResult {
286
+ valid: boolean;
287
+ errors: string[];
288
+ warnings: string[];
289
+ }
290
+ /**
291
+ * Validate a permission configuration
292
+ * @param config - Permission configuration to validate
293
+ * @param isAuthCollection - Whether this is for an auth collection
294
+ * @returns Validation result
295
+ */
296
+ declare function validatePermissionConfig(config: PermissionTemplateConfig | PermissionSchema, isAuthCollection?: boolean): PermissionValidationResult;
297
+ /**
298
+ * Validate a single rule expression for basic syntax
299
+ * @param expression - Rule expression to validate
300
+ * @returns Validation result
301
+ */
302
+ declare function validateRuleExpression(expression: RuleExpression): PermissionValidationResult;
303
+ /**
304
+ * Create a custom permission schema with type safety
305
+ * @param permissions - Partial permission schema
306
+ * @returns Complete permission schema with null defaults
307
+ */
308
+ declare function createPermissions(permissions: Partial<PermissionSchema>): PermissionSchema;
309
+ /**
310
+ * Merge multiple permission schemas, with later schemas taking precedence
311
+ * @param schemas - Permission schemas to merge
312
+ * @returns Merged permission schema
313
+ */
314
+ declare function mergePermissions(...schemas: Partial<PermissionSchema>[]): PermissionSchema;
315
+
316
+ export { PermissionSchema, PermissionTemplateConfig, PermissionTemplates, type PermissionValidationResult, RuleExpression, baseImageFileSchema, baseSchema, baseSchemaWithTimestamps, boolField, createPermissions, dateField, editorField, emailField, fileField, filesField, geoPointField, inputImageFileSchema, isPermissionSchema, isTemplateConfig, jsonField, mergePermissions, numberField, omitImageFilesSchema, relationField, relationsField, resolveTemplate, selectField, textField, urlField, validatePermissionConfig, validateRuleExpression, withIndexes, withPermissions };
@@ -0,0 +1,316 @@
1
+ import { z } from 'zod';
2
+ import { b as PermissionTemplateConfig, P as PermissionSchema, R as RuleExpression } from './permissions-ZHafVSIx.js';
3
+ export { A as APIRuleType, a as PermissionTemplate } from './permissions-ZHafVSIx.js';
4
+ export { P as ProjectInputSchema, a as ProjectSchema, U as UserInputSchema, b as UserSchema } from './user-jS1aYoeD.js';
5
+
6
+ /**
7
+ * Base schema fields that PocketBase automatically adds to all records
8
+ * These fields are managed by PocketBase and should not be set manually
9
+ */
10
+ declare const baseSchema: {
11
+ id: z.ZodString;
12
+ collectionId: z.ZodString;
13
+ collectionName: z.ZodString;
14
+ expand: z.ZodRecord<z.ZodString, z.ZodAny>;
15
+ };
16
+ /**
17
+ * Extended base schema with timestamp fields
18
+ * Includes created and updated autodate fields
19
+ */
20
+ declare const baseSchemaWithTimestamps: {
21
+ created: z.ZodString;
22
+ updated: z.ZodString;
23
+ id: z.ZodString;
24
+ collectionId: z.ZodString;
25
+ collectionName: z.ZodString;
26
+ expand: z.ZodRecord<z.ZodString, z.ZodAny>;
27
+ };
28
+ /**
29
+ * Base schema for image file collections
30
+ * Extends base schema with thumbnail URL and image files array
31
+ */
32
+ declare const baseImageFileSchema: {
33
+ thumbnailURL: z.ZodOptional<z.ZodString>;
34
+ imageFiles: z.ZodArray<z.ZodString, "many">;
35
+ id: z.ZodString;
36
+ collectionId: z.ZodString;
37
+ collectionName: z.ZodString;
38
+ expand: z.ZodRecord<z.ZodString, z.ZodAny>;
39
+ };
40
+ /**
41
+ * Input schema for image file uploads
42
+ * Used in forms where users upload File objects
43
+ * Requires Node.js 20+ or browser environment with File API
44
+ */
45
+ declare const inputImageFileSchema: {
46
+ imageFiles: z.ZodArray<z.ZodType<File, z.ZodTypeDef, File>, "many">;
47
+ };
48
+ /**
49
+ * Helper constant for omitting image files from schemas
50
+ * Used with Zod's .omit() method
51
+ */
52
+ declare const omitImageFilesSchema: {
53
+ readonly imageFiles: true;
54
+ };
55
+ /**
56
+ * Creates a text field schema with optional constraints
57
+ * @param options - Optional constraints for the text field
58
+ */
59
+ declare function textField(options?: {
60
+ min?: number;
61
+ max?: number;
62
+ pattern?: RegExp;
63
+ }): z.ZodString;
64
+ /**
65
+ * Creates an email field schema
66
+ * Maps to PocketBase 'email' field type
67
+ */
68
+ declare function emailField(): z.ZodString;
69
+ /**
70
+ * Creates a URL field schema
71
+ * Maps to PocketBase 'url' field type
72
+ */
73
+ declare function urlField(): z.ZodString;
74
+ /**
75
+ * Creates a number field schema with optional constraints
76
+ * @param options - Optional constraints for the number field
77
+ */
78
+ declare function numberField(options?: {
79
+ min?: number;
80
+ max?: number;
81
+ }): z.ZodNumber;
82
+ /**
83
+ * Creates a boolean field schema
84
+ * Maps to PocketBase 'bool' field type
85
+ */
86
+ declare function boolField(): z.ZodBoolean;
87
+ /**
88
+ * Creates a date field schema
89
+ * Maps to PocketBase 'date' field type
90
+ */
91
+ declare function dateField(): z.ZodDate;
92
+ /**
93
+ * Creates a select field schema from enum values
94
+ * Maps to PocketBase 'select' field type
95
+ * @param values - Array of allowed string values
96
+ */
97
+ declare function selectField<T extends [string, ...string[]]>(values: T): z.ZodEnum<z.Writeable<T>>;
98
+ /**
99
+ * Creates a JSON field schema
100
+ * Maps to PocketBase 'json' field type
101
+ * @param schema - Optional Zod schema for the JSON structure
102
+ */
103
+ declare function jsonField<T extends z.ZodTypeAny>(schema?: T): z.ZodRecord<z.ZodString, z.ZodAny> | T;
104
+ /**
105
+ * Creates a single file field schema for form input
106
+ * Maps to PocketBase 'file' field type with maxSelect=1
107
+ * Requires Node.js 20+ or browser environment with File API
108
+ */
109
+ declare function fileField(): z.ZodType<File, z.ZodTypeDef, File>;
110
+ /**
111
+ * Creates a multiple file field schema for form input
112
+ * Maps to PocketBase 'file' field type with maxSelect>1
113
+ * Requires Node.js 20+ or browser environment with File API
114
+ * @param options - Optional constraints for the file field
115
+ */
116
+ declare function filesField(options?: {
117
+ min?: number;
118
+ max?: number;
119
+ }): z.ZodArray<z.ZodType<File, z.ZodTypeDef, File>, "many">;
120
+ /**
121
+ * Creates a single relation field schema
122
+ * Maps to PocketBase 'relation' field type with maxSelect=1
123
+ * Field name should start with uppercase to be detected as relation
124
+ */
125
+ declare function relationField(): z.ZodString;
126
+ /**
127
+ * Creates a multiple relation field schema
128
+ * Maps to PocketBase 'relation' field type with maxSelect>1
129
+ * Field name should contain uppercase to be detected as relation
130
+ * @param options - Optional constraints for the relation field
131
+ */
132
+ declare function relationsField(options?: {
133
+ min?: number;
134
+ max?: number;
135
+ }): z.ZodArray<z.ZodString, "many">;
136
+ /**
137
+ * Creates an editor field schema (rich text)
138
+ * Maps to PocketBase 'editor' field type
139
+ */
140
+ declare function editorField(): z.ZodString;
141
+ /**
142
+ * Creates a geo point field schema
143
+ * Maps to PocketBase 'geoPoint' field type
144
+ */
145
+ declare function geoPointField(): z.ZodObject<{
146
+ lon: z.ZodNumber;
147
+ lat: z.ZodNumber;
148
+ }, "strip", z.ZodTypeAny, {
149
+ lon: number;
150
+ lat: number;
151
+ }, {
152
+ lon: number;
153
+ lat: number;
154
+ }>;
155
+ /**
156
+ * Attach permission metadata to a Zod schema
157
+ *
158
+ * This helper function allows you to define PocketBase API rules alongside your
159
+ * entity schema definitions. The permissions are stored as metadata using Zod's
160
+ * describe() method and will be extracted during migration generation.
161
+ *
162
+ * @param schema - The Zod schema to attach permissions to
163
+ * @param config - Either a PermissionTemplateConfig (for template-based permissions)
164
+ * or a PermissionSchema (for custom permissions)
165
+ * @returns The schema with permission metadata attached
166
+ *
167
+ * @example
168
+ * // Using a template
169
+ * const ProjectSchema = withPermissions(
170
+ * z.object({ title: z.string(), User: z.string() }),
171
+ * { template: 'owner-only', ownerField: 'User' }
172
+ * );
173
+ *
174
+ * @example
175
+ * // Using custom rules
176
+ * const ProjectSchema = withPermissions(
177
+ * z.object({ title: z.string() }),
178
+ * { listRule: '@request.auth.id != ""', viewRule: '' }
179
+ * );
180
+ *
181
+ * @example
182
+ * // Using template with custom rule overrides
183
+ * const ProjectSchema = withPermissions(
184
+ * z.object({ title: z.string(), User: z.string() }),
185
+ * {
186
+ * template: 'owner-only',
187
+ * ownerField: 'User',
188
+ * customRules: { listRule: '@request.auth.id != ""' }
189
+ * }
190
+ * );
191
+ */
192
+ declare function withPermissions<T extends z.ZodTypeAny>(schema: T, config: PermissionTemplateConfig | PermissionSchema): T;
193
+ /**
194
+ * Attach index definitions to a Zod schema
195
+ *
196
+ * This helper function allows you to define PocketBase indexes alongside your
197
+ * entity schema definitions. The indexes are stored as metadata using Zod's
198
+ * describe() method and will be extracted during migration generation.
199
+ *
200
+ * @param schema - The Zod schema to attach indexes to
201
+ * @param indexes - Array of PocketBase index SQL statements
202
+ * @returns The schema with index metadata attached
203
+ *
204
+ * @example
205
+ * // Define indexes for a user schema
206
+ * const UserSchema = withIndexes(
207
+ * withPermissions(
208
+ * z.object({ name: z.string(), email: z.string().email() }),
209
+ * userPermissions
210
+ * ),
211
+ * [
212
+ * 'CREATE UNIQUE INDEX idx_users_email ON users (email)',
213
+ * 'CREATE INDEX idx_users_name ON users (name)'
214
+ * ]
215
+ * );
216
+ *
217
+ * @example
218
+ * // Single index
219
+ * const ProjectSchema = withIndexes(
220
+ * ProjectDatabaseSchema,
221
+ * ['CREATE INDEX idx_projects_status ON projects (status)']
222
+ * );
223
+ */
224
+ declare function withIndexes<T extends z.ZodTypeAny>(schema: T, indexes: string[]): T;
225
+
226
+ /**
227
+ * Predefined permission templates for common access control patterns
228
+ */
229
+ declare const PermissionTemplates: {
230
+ /**
231
+ * Public access - anyone can perform all operations
232
+ */
233
+ public: () => PermissionSchema;
234
+ /**
235
+ * Authenticated users only - requires valid authentication for all operations
236
+ */
237
+ authenticated: () => PermissionSchema;
238
+ /**
239
+ * Owner-only access - users can only manage their own records
240
+ * @param ownerField - Name of the relation field pointing to user (default: 'User')
241
+ */
242
+ ownerOnly: (ownerField?: string) => PermissionSchema;
243
+ /**
244
+ * Admin/superuser only access
245
+ * Assumes a 'role' field exists with 'admin' value
246
+ * @param roleField - Name of the role field (default: 'role')
247
+ */
248
+ adminOnly: (roleField?: string) => PermissionSchema;
249
+ /**
250
+ * Public read, authenticated write
251
+ * Anyone can list/view, but only authenticated users can create/update/delete
252
+ */
253
+ readPublic: () => PermissionSchema;
254
+ /**
255
+ * Locked access - only superusers can perform operations
256
+ * All rules are set to null (locked)
257
+ */
258
+ locked: () => PermissionSchema;
259
+ /**
260
+ * Read-only authenticated - authenticated users can read, no write access
261
+ */
262
+ readOnlyAuthenticated: () => PermissionSchema;
263
+ };
264
+ /**
265
+ * Resolve template configuration to concrete permission schema
266
+ * @param config - Template configuration or direct permission schema
267
+ * @returns Resolved permission schema with all rules defined
268
+ */
269
+ declare function resolveTemplate(config: PermissionTemplateConfig): PermissionSchema;
270
+ /**
271
+ * Check if a configuration is a template config or direct permission schema
272
+ * @param config - Configuration to check
273
+ * @returns True if it's a template configuration
274
+ */
275
+ declare function isTemplateConfig(config: PermissionTemplateConfig | PermissionSchema): config is PermissionTemplateConfig;
276
+ /**
277
+ * Check if a configuration is a direct permission schema
278
+ * @param config - Configuration to check
279
+ * @returns True if it's a direct permission schema
280
+ */
281
+ declare function isPermissionSchema(config: PermissionTemplateConfig | PermissionSchema): config is PermissionSchema;
282
+ /**
283
+ * Validation result for permission configuration
284
+ */
285
+ interface PermissionValidationResult {
286
+ valid: boolean;
287
+ errors: string[];
288
+ warnings: string[];
289
+ }
290
+ /**
291
+ * Validate a permission configuration
292
+ * @param config - Permission configuration to validate
293
+ * @param isAuthCollection - Whether this is for an auth collection
294
+ * @returns Validation result
295
+ */
296
+ declare function validatePermissionConfig(config: PermissionTemplateConfig | PermissionSchema, isAuthCollection?: boolean): PermissionValidationResult;
297
+ /**
298
+ * Validate a single rule expression for basic syntax
299
+ * @param expression - Rule expression to validate
300
+ * @returns Validation result
301
+ */
302
+ declare function validateRuleExpression(expression: RuleExpression): PermissionValidationResult;
303
+ /**
304
+ * Create a custom permission schema with type safety
305
+ * @param permissions - Partial permission schema
306
+ * @returns Complete permission schema with null defaults
307
+ */
308
+ declare function createPermissions(permissions: Partial<PermissionSchema>): PermissionSchema;
309
+ /**
310
+ * Merge multiple permission schemas, with later schemas taking precedence
311
+ * @param schemas - Permission schemas to merge
312
+ * @returns Merged permission schema
313
+ */
314
+ declare function mergePermissions(...schemas: Partial<PermissionSchema>[]): PermissionSchema;
315
+
316
+ export { PermissionSchema, PermissionTemplateConfig, PermissionTemplates, type PermissionValidationResult, RuleExpression, baseImageFileSchema, baseSchema, baseSchemaWithTimestamps, boolField, createPermissions, dateField, editorField, emailField, fileField, filesField, geoPointField, inputImageFileSchema, isPermissionSchema, isTemplateConfig, jsonField, mergePermissions, numberField, omitImageFilesSchema, relationField, relationsField, resolveTemplate, selectField, textField, urlField, validatePermissionConfig, validateRuleExpression, withIndexes, withPermissions };