pocketbase-zod-schema 0.2.4 → 0.3.0

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 (67) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +209 -24
  3. package/dist/cli/index.cjs +406 -294
  4. package/dist/cli/index.cjs.map +1 -1
  5. package/dist/cli/index.d.cts +3 -1
  6. package/dist/cli/index.d.ts +3 -1
  7. package/dist/cli/index.js +406 -294
  8. package/dist/cli/index.js.map +1 -1
  9. package/dist/cli/migrate.cjs +406 -294
  10. package/dist/cli/migrate.cjs.map +1 -1
  11. package/dist/cli/migrate.js +406 -294
  12. package/dist/cli/migrate.js.map +1 -1
  13. package/dist/cli/utils/index.d.cts +3 -1
  14. package/dist/cli/utils/index.d.ts +3 -1
  15. package/dist/fields-UcOPu1OQ.d.cts +364 -0
  16. package/dist/fields-UcOPu1OQ.d.ts +364 -0
  17. package/dist/index.cjs +633 -112
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +4 -3
  20. package/dist/index.d.ts +4 -3
  21. package/dist/index.js +619 -101
  22. package/dist/index.js.map +1 -1
  23. package/dist/migration/analyzer.cjs +44 -0
  24. package/dist/migration/analyzer.cjs.map +1 -1
  25. package/dist/migration/analyzer.d.cts +2 -1
  26. package/dist/migration/analyzer.d.ts +2 -1
  27. package/dist/migration/analyzer.js +44 -0
  28. package/dist/migration/analyzer.js.map +1 -1
  29. package/dist/migration/diff.cjs +76 -1
  30. package/dist/migration/diff.cjs.map +1 -1
  31. package/dist/migration/diff.d.cts +3 -1
  32. package/dist/migration/diff.d.ts +3 -1
  33. package/dist/migration/diff.js +76 -1
  34. package/dist/migration/diff.js.map +1 -1
  35. package/dist/migration/generator.cjs +323 -46
  36. package/dist/migration/generator.cjs.map +1 -1
  37. package/dist/migration/generator.d.cts +60 -11
  38. package/dist/migration/generator.d.ts +60 -11
  39. package/dist/migration/generator.js +319 -47
  40. package/dist/migration/generator.js.map +1 -1
  41. package/dist/migration/index.cjs +433 -47
  42. package/dist/migration/index.cjs.map +1 -1
  43. package/dist/migration/index.d.cts +3 -2
  44. package/dist/migration/index.d.ts +3 -2
  45. package/dist/migration/index.js +432 -48
  46. package/dist/migration/index.js.map +1 -1
  47. package/dist/migration/snapshot.cjs.map +1 -1
  48. package/dist/migration/snapshot.d.cts +3 -1
  49. package/dist/migration/snapshot.d.ts +3 -1
  50. package/dist/migration/snapshot.js.map +1 -1
  51. package/dist/migration/utils/index.cjs +80 -0
  52. package/dist/migration/utils/index.cjs.map +1 -1
  53. package/dist/migration/utils/index.d.cts +39 -202
  54. package/dist/migration/utils/index.d.ts +39 -202
  55. package/dist/migration/utils/index.js +77 -1
  56. package/dist/migration/utils/index.js.map +1 -1
  57. package/dist/schema.cjs +200 -61
  58. package/dist/schema.cjs.map +1 -1
  59. package/dist/schema.d.cts +2 -85
  60. package/dist/schema.d.ts +2 -85
  61. package/dist/schema.js +186 -50
  62. package/dist/schema.js.map +1 -1
  63. package/dist/type-mapper-DrQmtznD.d.cts +208 -0
  64. package/dist/type-mapper-n231Fspm.d.ts +208 -0
  65. package/dist/{types-z1Dkjg8m.d.ts → types-Ds3NQvny.d.ts} +33 -2
  66. package/dist/{types-BbTgmg6H.d.cts → types-YoBjsa-A.d.cts} +33 -2
  67. package/package.json +1 -1
@@ -0,0 +1,208 @@
1
+ import { z } from 'zod';
2
+ import { P as PocketBaseFieldType } from './fields-UcOPu1OQ.cjs';
3
+
4
+ /**
5
+ * Collection name pluralization utilities
6
+ */
7
+ /**
8
+ * Pluralizes a singular noun to its plural form
9
+ * Handles special cases and common English pluralization rules
10
+ *
11
+ * @param singular - The singular form of the noun
12
+ * @returns The plural form of the noun
13
+ */
14
+ declare function pluralize(singular: string): string;
15
+ /**
16
+ * Converts a singular entity name to a collection name
17
+ * This is an alias for pluralize for better semantic clarity
18
+ *
19
+ * @param entityName - The singular entity name (e.g., "User", "Project")
20
+ * @returns The collection name (e.g., "Users", "Projects")
21
+ */
22
+ declare function toCollectionName(entityName: string): string;
23
+ /**
24
+ * Attempts to singularize a plural noun (reverse of pluralize)
25
+ * Note: This is a best-effort implementation and may not handle all edge cases
26
+ *
27
+ * @param plural - The plural form of the noun
28
+ * @returns The singular form of the noun
29
+ */
30
+ declare function singularize(plural: string): string;
31
+
32
+ /**
33
+ * Relation field detection utilities
34
+ */
35
+
36
+ /**
37
+ * Detects if a field is a single relation based on naming convention
38
+ * Single relation: field name matches a collection name (e.g., "User" -> "Users" collection)
39
+ */
40
+ declare function isSingleRelationField(fieldName: string, zodType: z.ZodTypeAny): boolean;
41
+ /**
42
+ * Detects if a field is a multiple relation based on naming convention
43
+ * Multiple relation: field name is an array of strings ending with entity name
44
+ * (e.g., "SubscriberUsers" -> "Users" collection)
45
+ */
46
+ declare function isMultipleRelationField(fieldName: string, zodType: z.ZodTypeAny): boolean;
47
+ /**
48
+ * Resolves the target collection name from a relation field name
49
+ * Examples:
50
+ * - "User" -> "Users"
51
+ * - "SubscriberUsers" -> "Users"
52
+ * - "Author" -> "Authors"
53
+ * - "Category" -> "Categories"
54
+ */
55
+ declare function resolveTargetCollection(fieldName: string): string;
56
+ /**
57
+ * Detects if a field is any type of relation (single or multiple)
58
+ */
59
+ declare function isRelationField(fieldName: string, zodType: z.ZodTypeAny): boolean;
60
+ /**
61
+ * Gets the maximum number of relations allowed for a relation field
62
+ * Returns 1 for single relations, or the max constraint for multiple relations
63
+ */
64
+ declare function getMaxSelect(fieldName: string, zodType: z.ZodTypeAny): number;
65
+ /**
66
+ * Gets the minimum number of relations required for a relation field
67
+ * Returns 0 as default for all relation fields (single or multiple)
68
+ * PocketBase always expects minSelect to be defined for relation fields
69
+ */
70
+ declare function getMinSelect(fieldName: string, zodType: z.ZodTypeAny): number;
71
+
72
+ /**
73
+ * Zod to PocketBase type mapping utilities
74
+ *
75
+ * This module provides comprehensive mapping between Zod schema types
76
+ * and PocketBase field types, including support for all PocketBase field types:
77
+ * - text, email, url, editor
78
+ * - number, bool
79
+ * - date, autodate
80
+ * - select (single/multiple)
81
+ * - relation (single/multiple)
82
+ * - file (single/multiple)
83
+ * - json
84
+ * - geoPoint
85
+ */
86
+
87
+ /**
88
+ * All supported PocketBase field types
89
+ */
90
+ declare const POCKETBASE_FIELD_TYPES: readonly PocketBaseFieldType[];
91
+ /**
92
+ * Field type metadata for documentation and validation
93
+ */
94
+ interface FieldTypeInfo {
95
+ type: PocketBaseFieldType;
96
+ description: string;
97
+ zodTypes: string[];
98
+ supportsMultiple: boolean;
99
+ }
100
+ /**
101
+ * Metadata about each PocketBase field type
102
+ */
103
+ declare const FIELD_TYPE_INFO: Record<PocketBaseFieldType, FieldTypeInfo>;
104
+ /**
105
+ * Maps Zod string types to PocketBase field types
106
+ */
107
+ declare function mapZodStringType(zodType: z.ZodString): PocketBaseFieldType;
108
+ /**
109
+ * Maps Zod number types to PocketBase number type
110
+ */
111
+ declare function mapZodNumberType(_zodType: z.ZodNumber): PocketBaseFieldType;
112
+ /**
113
+ * Maps Zod boolean types to PocketBase bool type
114
+ */
115
+ declare function mapZodBooleanType(_zodType: z.ZodBoolean): PocketBaseFieldType;
116
+ /**
117
+ * Maps Zod enum types to PocketBase select type
118
+ */
119
+ declare function mapZodEnumType(_zodType: z.ZodEnum<any>): PocketBaseFieldType;
120
+ /**
121
+ * Maps Zod array types to appropriate PocketBase types
122
+ * Arrays of strings could be relations or file fields depending on context
123
+ */
124
+ declare function mapZodArrayType(zodType: z.ZodArray<any>, _fieldName: string): PocketBaseFieldType;
125
+ /**
126
+ * Maps Zod date types to PocketBase date type
127
+ */
128
+ declare function mapZodDateType(_zodType: z.ZodDate): PocketBaseFieldType;
129
+ /**
130
+ * Maps Zod record/object types to PocketBase JSON type
131
+ */
132
+ declare function mapZodRecordType(_zodType: z.ZodRecord | z.ZodObject<any>): PocketBaseFieldType;
133
+ /**
134
+ * Main type mapping function that determines PocketBase field type from Zod type
135
+ */
136
+ declare function mapZodTypeToPocketBase(zodType: z.ZodTypeAny, fieldName: string): PocketBaseFieldType;
137
+ /**
138
+ * Extracts field options from Zod type (min, max, pattern, etc.)
139
+ */
140
+ declare function extractFieldOptions(zodType: z.ZodTypeAny): Record<string, any>;
141
+ /**
142
+ * Determines if a Zod field is required (not optional)
143
+ */
144
+ declare function isFieldRequired(zodType: z.ZodTypeAny): boolean;
145
+ /**
146
+ * Unwraps a Zod type to get the inner type
147
+ * Handles optional, nullable, and default wrappers
148
+ */
149
+ declare function unwrapZodType(zodType: z.ZodTypeAny): z.ZodTypeAny;
150
+ /**
151
+ * Gets the default value from a Zod type if it has one
152
+ */
153
+ declare function getDefaultValue(zodType: z.ZodTypeAny): any;
154
+ /**
155
+ * Checks if a Zod type is an array type
156
+ */
157
+ declare function isArrayType(zodType: z.ZodTypeAny): boolean;
158
+ /**
159
+ * Gets the element type of an array Zod type
160
+ */
161
+ declare function getArrayElementType(zodType: z.ZodTypeAny): z.ZodTypeAny | null;
162
+ /**
163
+ * Checks if a Zod type represents a geo point (object with lon/lat)
164
+ */
165
+ declare function isGeoPointType(zodType: z.ZodTypeAny): boolean;
166
+ /**
167
+ * Complete field options extracted from a Zod type
168
+ */
169
+ interface ExtractedFieldOptions {
170
+ min?: number;
171
+ max?: number;
172
+ pattern?: string;
173
+ values?: string[];
174
+ minSelect?: number;
175
+ maxSelect?: number;
176
+ mimeTypes?: string[];
177
+ maxSize?: number;
178
+ thumbs?: string[];
179
+ }
180
+ /**
181
+ * Extracts comprehensive field options from Zod type
182
+ * Includes all constraints that can be mapped to PocketBase field options
183
+ */
184
+ declare function extractComprehensiveFieldOptions(zodType: z.ZodTypeAny): ExtractedFieldOptions;
185
+ /**
186
+ * Determines if a field should be treated as an editor field
187
+ * based on field name conventions
188
+ */
189
+ declare function isEditorField(fieldName: string): boolean;
190
+ /**
191
+ * Determines if a field should be treated as a file field
192
+ * based on field name conventions
193
+ */
194
+ declare function isFileFieldByName(fieldName: string): boolean;
195
+ /**
196
+ * Gets the PocketBase field type with additional context
197
+ */
198
+ interface FieldTypeResult {
199
+ type: PocketBaseFieldType;
200
+ isMultiple: boolean;
201
+ options: ExtractedFieldOptions;
202
+ }
203
+ /**
204
+ * Comprehensive type mapping that returns full field information
205
+ */
206
+ declare function getFieldTypeInfo(zodType: z.ZodTypeAny, fieldName: string): FieldTypeResult;
207
+
208
+ export { isEditorField as A, isFileFieldByName as B, type FieldTypeResult as C, getFieldTypeInfo as D, type ExtractedFieldOptions as E, type FieldTypeInfo as F, POCKETBASE_FIELD_TYPES as P, isMultipleRelationField as a, isRelationField as b, getMinSelect as c, FIELD_TYPE_INFO as d, mapZodNumberType as e, mapZodBooleanType as f, getMaxSelect as g, mapZodEnumType as h, isSingleRelationField as i, mapZodArrayType as j, mapZodDateType as k, mapZodRecordType as l, mapZodStringType as m, mapZodTypeToPocketBase as n, extractFieldOptions as o, pluralize as p, isFieldRequired as q, resolveTargetCollection as r, singularize as s, toCollectionName as t, unwrapZodType as u, getDefaultValue as v, isArrayType as w, getArrayElementType as x, isGeoPointType as y, extractComprehensiveFieldOptions as z };
@@ -0,0 +1,208 @@
1
+ import { z } from 'zod';
2
+ import { P as PocketBaseFieldType } from './fields-UcOPu1OQ.js';
3
+
4
+ /**
5
+ * Collection name pluralization utilities
6
+ */
7
+ /**
8
+ * Pluralizes a singular noun to its plural form
9
+ * Handles special cases and common English pluralization rules
10
+ *
11
+ * @param singular - The singular form of the noun
12
+ * @returns The plural form of the noun
13
+ */
14
+ declare function pluralize(singular: string): string;
15
+ /**
16
+ * Converts a singular entity name to a collection name
17
+ * This is an alias for pluralize for better semantic clarity
18
+ *
19
+ * @param entityName - The singular entity name (e.g., "User", "Project")
20
+ * @returns The collection name (e.g., "Users", "Projects")
21
+ */
22
+ declare function toCollectionName(entityName: string): string;
23
+ /**
24
+ * Attempts to singularize a plural noun (reverse of pluralize)
25
+ * Note: This is a best-effort implementation and may not handle all edge cases
26
+ *
27
+ * @param plural - The plural form of the noun
28
+ * @returns The singular form of the noun
29
+ */
30
+ declare function singularize(plural: string): string;
31
+
32
+ /**
33
+ * Relation field detection utilities
34
+ */
35
+
36
+ /**
37
+ * Detects if a field is a single relation based on naming convention
38
+ * Single relation: field name matches a collection name (e.g., "User" -> "Users" collection)
39
+ */
40
+ declare function isSingleRelationField(fieldName: string, zodType: z.ZodTypeAny): boolean;
41
+ /**
42
+ * Detects if a field is a multiple relation based on naming convention
43
+ * Multiple relation: field name is an array of strings ending with entity name
44
+ * (e.g., "SubscriberUsers" -> "Users" collection)
45
+ */
46
+ declare function isMultipleRelationField(fieldName: string, zodType: z.ZodTypeAny): boolean;
47
+ /**
48
+ * Resolves the target collection name from a relation field name
49
+ * Examples:
50
+ * - "User" -> "Users"
51
+ * - "SubscriberUsers" -> "Users"
52
+ * - "Author" -> "Authors"
53
+ * - "Category" -> "Categories"
54
+ */
55
+ declare function resolveTargetCollection(fieldName: string): string;
56
+ /**
57
+ * Detects if a field is any type of relation (single or multiple)
58
+ */
59
+ declare function isRelationField(fieldName: string, zodType: z.ZodTypeAny): boolean;
60
+ /**
61
+ * Gets the maximum number of relations allowed for a relation field
62
+ * Returns 1 for single relations, or the max constraint for multiple relations
63
+ */
64
+ declare function getMaxSelect(fieldName: string, zodType: z.ZodTypeAny): number;
65
+ /**
66
+ * Gets the minimum number of relations required for a relation field
67
+ * Returns 0 as default for all relation fields (single or multiple)
68
+ * PocketBase always expects minSelect to be defined for relation fields
69
+ */
70
+ declare function getMinSelect(fieldName: string, zodType: z.ZodTypeAny): number;
71
+
72
+ /**
73
+ * Zod to PocketBase type mapping utilities
74
+ *
75
+ * This module provides comprehensive mapping between Zod schema types
76
+ * and PocketBase field types, including support for all PocketBase field types:
77
+ * - text, email, url, editor
78
+ * - number, bool
79
+ * - date, autodate
80
+ * - select (single/multiple)
81
+ * - relation (single/multiple)
82
+ * - file (single/multiple)
83
+ * - json
84
+ * - geoPoint
85
+ */
86
+
87
+ /**
88
+ * All supported PocketBase field types
89
+ */
90
+ declare const POCKETBASE_FIELD_TYPES: readonly PocketBaseFieldType[];
91
+ /**
92
+ * Field type metadata for documentation and validation
93
+ */
94
+ interface FieldTypeInfo {
95
+ type: PocketBaseFieldType;
96
+ description: string;
97
+ zodTypes: string[];
98
+ supportsMultiple: boolean;
99
+ }
100
+ /**
101
+ * Metadata about each PocketBase field type
102
+ */
103
+ declare const FIELD_TYPE_INFO: Record<PocketBaseFieldType, FieldTypeInfo>;
104
+ /**
105
+ * Maps Zod string types to PocketBase field types
106
+ */
107
+ declare function mapZodStringType(zodType: z.ZodString): PocketBaseFieldType;
108
+ /**
109
+ * Maps Zod number types to PocketBase number type
110
+ */
111
+ declare function mapZodNumberType(_zodType: z.ZodNumber): PocketBaseFieldType;
112
+ /**
113
+ * Maps Zod boolean types to PocketBase bool type
114
+ */
115
+ declare function mapZodBooleanType(_zodType: z.ZodBoolean): PocketBaseFieldType;
116
+ /**
117
+ * Maps Zod enum types to PocketBase select type
118
+ */
119
+ declare function mapZodEnumType(_zodType: z.ZodEnum<any>): PocketBaseFieldType;
120
+ /**
121
+ * Maps Zod array types to appropriate PocketBase types
122
+ * Arrays of strings could be relations or file fields depending on context
123
+ */
124
+ declare function mapZodArrayType(zodType: z.ZodArray<any>, _fieldName: string): PocketBaseFieldType;
125
+ /**
126
+ * Maps Zod date types to PocketBase date type
127
+ */
128
+ declare function mapZodDateType(_zodType: z.ZodDate): PocketBaseFieldType;
129
+ /**
130
+ * Maps Zod record/object types to PocketBase JSON type
131
+ */
132
+ declare function mapZodRecordType(_zodType: z.ZodRecord | z.ZodObject<any>): PocketBaseFieldType;
133
+ /**
134
+ * Main type mapping function that determines PocketBase field type from Zod type
135
+ */
136
+ declare function mapZodTypeToPocketBase(zodType: z.ZodTypeAny, fieldName: string): PocketBaseFieldType;
137
+ /**
138
+ * Extracts field options from Zod type (min, max, pattern, etc.)
139
+ */
140
+ declare function extractFieldOptions(zodType: z.ZodTypeAny): Record<string, any>;
141
+ /**
142
+ * Determines if a Zod field is required (not optional)
143
+ */
144
+ declare function isFieldRequired(zodType: z.ZodTypeAny): boolean;
145
+ /**
146
+ * Unwraps a Zod type to get the inner type
147
+ * Handles optional, nullable, and default wrappers
148
+ */
149
+ declare function unwrapZodType(zodType: z.ZodTypeAny): z.ZodTypeAny;
150
+ /**
151
+ * Gets the default value from a Zod type if it has one
152
+ */
153
+ declare function getDefaultValue(zodType: z.ZodTypeAny): any;
154
+ /**
155
+ * Checks if a Zod type is an array type
156
+ */
157
+ declare function isArrayType(zodType: z.ZodTypeAny): boolean;
158
+ /**
159
+ * Gets the element type of an array Zod type
160
+ */
161
+ declare function getArrayElementType(zodType: z.ZodTypeAny): z.ZodTypeAny | null;
162
+ /**
163
+ * Checks if a Zod type represents a geo point (object with lon/lat)
164
+ */
165
+ declare function isGeoPointType(zodType: z.ZodTypeAny): boolean;
166
+ /**
167
+ * Complete field options extracted from a Zod type
168
+ */
169
+ interface ExtractedFieldOptions {
170
+ min?: number;
171
+ max?: number;
172
+ pattern?: string;
173
+ values?: string[];
174
+ minSelect?: number;
175
+ maxSelect?: number;
176
+ mimeTypes?: string[];
177
+ maxSize?: number;
178
+ thumbs?: string[];
179
+ }
180
+ /**
181
+ * Extracts comprehensive field options from Zod type
182
+ * Includes all constraints that can be mapped to PocketBase field options
183
+ */
184
+ declare function extractComprehensiveFieldOptions(zodType: z.ZodTypeAny): ExtractedFieldOptions;
185
+ /**
186
+ * Determines if a field should be treated as an editor field
187
+ * based on field name conventions
188
+ */
189
+ declare function isEditorField(fieldName: string): boolean;
190
+ /**
191
+ * Determines if a field should be treated as a file field
192
+ * based on field name conventions
193
+ */
194
+ declare function isFileFieldByName(fieldName: string): boolean;
195
+ /**
196
+ * Gets the PocketBase field type with additional context
197
+ */
198
+ interface FieldTypeResult {
199
+ type: PocketBaseFieldType;
200
+ isMultiple: boolean;
201
+ options: ExtractedFieldOptions;
202
+ }
203
+ /**
204
+ * Comprehensive type mapping that returns full field information
205
+ */
206
+ declare function getFieldTypeInfo(zodType: z.ZodTypeAny, fieldName: string): FieldTypeResult;
207
+
208
+ export { isEditorField as A, isFileFieldByName as B, type FieldTypeResult as C, getFieldTypeInfo as D, type ExtractedFieldOptions as E, type FieldTypeInfo as F, POCKETBASE_FIELD_TYPES as P, isMultipleRelationField as a, isRelationField as b, getMinSelect as c, FIELD_TYPE_INFO as d, mapZodNumberType as e, mapZodBooleanType as f, getMaxSelect as g, mapZodEnumType as h, isSingleRelationField as i, mapZodArrayType as j, mapZodDateType as k, mapZodRecordType as l, mapZodStringType as m, mapZodTypeToPocketBase as n, extractFieldOptions as o, pluralize as p, isFieldRequired as q, resolveTargetCollection as r, singularize as s, toCollectionName as t, unwrapZodType as u, getDefaultValue as v, isArrayType as w, getArrayElementType as x, isGeoPointType as y, extractComprehensiveFieldOptions as z };
@@ -1,9 +1,9 @@
1
+ import { P as PocketBaseFieldType } from './fields-UcOPu1OQ.js';
1
2
  import { A as APIRuleType } from './permissions-ZHafVSIx.js';
2
3
 
3
4
  /**
4
5
  * Shared types for migration tool
5
6
  */
6
- type PocketBaseFieldType = "text" | "email" | "url" | "number" | "bool" | "date" | "select" | "relation" | "file" | "json" | "editor" | "geoPoint" | "autodate";
7
7
 
8
8
  interface FieldDefinition {
9
9
  name: string;
@@ -21,6 +21,13 @@ interface FieldDefinition {
21
21
  interface CollectionSchema {
22
22
  name: string;
23
23
  type: "base" | "auth";
24
+ /**
25
+ * Pre-generated collection ID for use in migrations
26
+ * Format: pb_ followed by 15 alphanumeric lowercase characters
27
+ * Special case: "_pb_users_auth_" for users collection
28
+ * This ID is generated during migration creation to avoid runtime lookups
29
+ */
30
+ id?: string;
24
31
  fields: FieldDefinition[];
25
32
  indexes?: string[];
26
33
  rules?: {
@@ -87,5 +94,29 @@ interface SchemaDiff {
87
94
  collectionsToDelete: any[];
88
95
  collectionsToModify: CollectionModification[];
89
96
  }
97
+ /**
98
+ * Represents a single collection operation for file splitting
99
+ * Each operation will generate a separate migration file
100
+ */
101
+ interface CollectionOperation {
102
+ /**
103
+ * Type of operation being performed
104
+ */
105
+ type: "create" | "modify" | "delete";
106
+ /**
107
+ * Collection being operated on
108
+ * For create/modify: CollectionSchema
109
+ * For delete: collection name as string
110
+ */
111
+ collection: CollectionSchema | string;
112
+ /**
113
+ * Modifications to apply (only for 'modify' operations)
114
+ */
115
+ modifications?: CollectionModification;
116
+ /**
117
+ * Timestamp for this operation's migration file
118
+ */
119
+ timestamp: string;
120
+ }
90
121
 
91
- export type { CollectionSchema as C, FieldDefinition as F, PocketBaseFieldType as P, RuleUpdate as R, SchemaDefinition as S, SchemaSnapshot as a, FieldChange as b, FieldModification as c, PermissionChange as d, CollectionModification as e, SchemaDiff as f };
122
+ export type { CollectionSchema as C, FieldDefinition as F, PermissionChange as P, RuleUpdate as R, SchemaDefinition as S, SchemaSnapshot as a, FieldChange as b, FieldModification as c, CollectionModification as d, SchemaDiff as e, CollectionOperation as f };
@@ -1,9 +1,9 @@
1
+ import { P as PocketBaseFieldType } from './fields-UcOPu1OQ.cjs';
1
2
  import { A as APIRuleType } from './permissions-ZHafVSIx.cjs';
2
3
 
3
4
  /**
4
5
  * Shared types for migration tool
5
6
  */
6
- type PocketBaseFieldType = "text" | "email" | "url" | "number" | "bool" | "date" | "select" | "relation" | "file" | "json" | "editor" | "geoPoint" | "autodate";
7
7
 
8
8
  interface FieldDefinition {
9
9
  name: string;
@@ -21,6 +21,13 @@ interface FieldDefinition {
21
21
  interface CollectionSchema {
22
22
  name: string;
23
23
  type: "base" | "auth";
24
+ /**
25
+ * Pre-generated collection ID for use in migrations
26
+ * Format: pb_ followed by 15 alphanumeric lowercase characters
27
+ * Special case: "_pb_users_auth_" for users collection
28
+ * This ID is generated during migration creation to avoid runtime lookups
29
+ */
30
+ id?: string;
24
31
  fields: FieldDefinition[];
25
32
  indexes?: string[];
26
33
  rules?: {
@@ -87,5 +94,29 @@ interface SchemaDiff {
87
94
  collectionsToDelete: any[];
88
95
  collectionsToModify: CollectionModification[];
89
96
  }
97
+ /**
98
+ * Represents a single collection operation for file splitting
99
+ * Each operation will generate a separate migration file
100
+ */
101
+ interface CollectionOperation {
102
+ /**
103
+ * Type of operation being performed
104
+ */
105
+ type: "create" | "modify" | "delete";
106
+ /**
107
+ * Collection being operated on
108
+ * For create/modify: CollectionSchema
109
+ * For delete: collection name as string
110
+ */
111
+ collection: CollectionSchema | string;
112
+ /**
113
+ * Modifications to apply (only for 'modify' operations)
114
+ */
115
+ modifications?: CollectionModification;
116
+ /**
117
+ * Timestamp for this operation's migration file
118
+ */
119
+ timestamp: string;
120
+ }
90
121
 
91
- export type { CollectionSchema as C, FieldDefinition as F, PocketBaseFieldType as P, RuleUpdate as R, SchemaDefinition as S, SchemaSnapshot as a, FieldChange as b, FieldModification as c, PermissionChange as d, CollectionModification as e, SchemaDiff as f };
122
+ export type { CollectionSchema as C, FieldDefinition as F, PermissionChange as P, RuleUpdate as R, SchemaDefinition as S, SchemaSnapshot as a, FieldChange as b, FieldModification as c, CollectionModification as d, SchemaDiff as e, CollectionOperation as f };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pocketbase-zod-schema",
3
- "version": "0.2.4",
3
+ "version": "0.3.0",
4
4
  "description": "PocketBase migration generator using Zod schemas for type-safe database migrations",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",