pocketbase-zod-schema 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/cli/index.cjs +36 -32
  3. package/dist/cli/index.cjs.map +1 -1
  4. package/dist/cli/index.d.cts +2 -2
  5. package/dist/cli/index.d.ts +2 -2
  6. package/dist/cli/index.js +36 -32
  7. package/dist/cli/index.js.map +1 -1
  8. package/dist/cli/migrate.cjs +36 -32
  9. package/dist/cli/migrate.cjs.map +1 -1
  10. package/dist/cli/migrate.js +36 -32
  11. package/dist/cli/migrate.js.map +1 -1
  12. package/dist/cli/utils/index.d.cts +2 -2
  13. package/dist/cli/utils/index.d.ts +2 -2
  14. package/dist/{fields-RVj26U-O.d.cts → fields-DBBm06VU.d.cts} +34 -7
  15. package/dist/{fields-RVj26U-O.d.ts → fields-DBBm06VU.d.ts} +34 -7
  16. package/dist/index.cjs +125 -66
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +3 -3
  19. package/dist/index.d.ts +3 -3
  20. package/dist/index.js +125 -66
  21. package/dist/index.js.map +1 -1
  22. package/dist/migration/analyzer.cjs.map +1 -1
  23. package/dist/migration/analyzer.d.cts +2 -2
  24. package/dist/migration/analyzer.d.ts +2 -2
  25. package/dist/migration/analyzer.js.map +1 -1
  26. package/dist/migration/diff.d.cts +2 -2
  27. package/dist/migration/diff.d.ts +2 -2
  28. package/dist/migration/generator.cjs +70 -60
  29. package/dist/migration/generator.cjs.map +1 -1
  30. package/dist/migration/generator.d.cts +2 -2
  31. package/dist/migration/generator.d.ts +2 -2
  32. package/dist/migration/generator.js +70 -60
  33. package/dist/migration/generator.js.map +1 -1
  34. package/dist/migration/index.cjs +70 -60
  35. package/dist/migration/index.cjs.map +1 -1
  36. package/dist/migration/index.d.cts +3 -3
  37. package/dist/migration/index.d.ts +3 -3
  38. package/dist/migration/index.js +70 -60
  39. package/dist/migration/index.js.map +1 -1
  40. package/dist/migration/snapshot.d.cts +2 -2
  41. package/dist/migration/snapshot.d.ts +2 -2
  42. package/dist/migration/utils/index.cjs.map +1 -1
  43. package/dist/migration/utils/index.d.cts +2 -2
  44. package/dist/migration/utils/index.d.ts +2 -2
  45. package/dist/migration/utils/index.js.map +1 -1
  46. package/dist/schema.cjs +55 -6
  47. package/dist/schema.cjs.map +1 -1
  48. package/dist/schema.d.cts +1 -1
  49. package/dist/schema.d.ts +1 -1
  50. package/dist/schema.js +55 -6
  51. package/dist/schema.js.map +1 -1
  52. package/dist/{type-mapper-DaBe-1ph.d.cts → type-mapper-DsGgZwUo.d.cts} +1 -1
  53. package/dist/{type-mapper-CZzVeDj7.d.ts → type-mapper-Dvh4QTM-.d.ts} +1 -1
  54. package/dist/{types-D-Fsdn_O.d.cts → types-CVxPCgWX.d.cts} +1 -1
  55. package/dist/{types-CUVzgZ9k.d.ts → types-Dfp-NP2D.d.ts} +1 -1
  56. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../node_modules/tsup/assets/cjs_shims.js","../../src/schema/base.ts","../../src/schema/fields.ts","../../src/migration/errors.ts","../../src/utils/permission-templates.ts","../../src/migration/rule-validator.ts","../../src/migration/permission-analyzer.ts","../../src/migration/utils/pluralize.ts","../../src/migration/utils/relation-detector.ts","../../src/migration/utils/type-mapper.ts","../../src/migration/analyzer.ts","../../src/migration/utils/collection-id-generator.ts","../../src/migration/diff.ts","../../src/migration/generator.ts","../../src/migration/pocketbase-converter.ts","../../src/migration/migration-parser.ts","../../src/migration/snapshot.ts","../../src/migration/validation.ts","../../src/cli/utils/config.ts","../../src/cli/utils/logger.ts","../../src/cli/commands/generate.ts","../../src/cli/commands/status.ts","../../src/cli/migrate.ts"],"names":["z","path","isAuthCollection","fs","ext","required","options","fieldDef","relationMetadata","randomBytes","DEFAULT_CONFIG","mergeConfig","path2","fs2","hasChanges","extractFieldOptions","fs3","path3","fs4","path4","migrationContent","path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AAA,EAC9B;AAEA,EAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAChB,CAAC,CAAA;AAGD,IAAI,OAAA,CAAQ,IAAA,CAAK,MAAA,KAAW,CAAA,EAAG;AAC7B,EAAA,aAAA,EAAc;AACd,EAAA,OAAA,CAAQ,IAAA,EAAK;AACf;AAGA,OAAA,CAAQ,KAAA,CAAM,QAAQ,IAAI,CAAA","file":"migrate.cjs","sourcesContent":["// Shim globals in cjs bundle\n// There's a weird bug that esbuild will always inject importMetaUrl\n// if we export it as `const importMetaUrl = ... __filename ...`\n// But using a function will not cause this issue\n\nconst getImportMetaUrl = () => \n typeof document === \"undefined\" \n ? new URL(`file:${__filename}`).href \n : (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT') \n ? document.currentScript.src \n : new URL(\"main.js\", document.baseURI).href;\n\nexport const importMetaUrl = /* @__PURE__ */ getImportMetaUrl()\n","import { z } from \"zod\";\nimport type { PermissionSchema, PermissionTemplateConfig } from \"../utils/permissions\";\n\n/**\n * Base schema fields that PocketBase automatically adds to all records\n * These fields are managed by PocketBase and should not be set manually\n */\nexport const baseSchema = {\n id: z.string().describe(\"unique id\"),\n collectionId: z.string().describe(\"collection id\"),\n collectionName: z.string().describe(\"collection name\"),\n expand: z.record(z.any()).describe(\"expandable fields\"),\n created: z.string().describe(\"creation timestamp\"),\n updated: z.string().describe(\"last update timestamp\"),\n};\n\n/**\n * Extended base schema with timestamp fields\n * Includes created and updated autodate fields\n */\nexport const baseSchemaWithTimestamps = {\n ...baseSchema,\n created: z.string().describe(\"creation timestamp\"),\n updated: z.string().describe(\"last update timestamp\"),\n};\n\n/**\n * Base schema for image file collections\n * Extends base schema with thumbnail URL and image files array\n */\nexport const baseImageFileSchema = {\n ...baseSchema,\n thumbnailURL: z.string().optional(),\n imageFiles: z.array(z.string()),\n};\n\n/**\n * Input schema for image file uploads\n * Used in forms where users upload File objects\n * Requires Node.js 20+ or browser environment with File API\n */\nexport const inputImageFileSchema = {\n imageFiles: z.array(z.instanceof(File)),\n};\n\n/**\n * Helper constant for omitting image files from schemas\n * Used with Zod's .omit() method\n */\nexport const omitImageFilesSchema = {\n imageFiles: true,\n} as const;\n\n// ============================================================================\n// Common PocketBase Field Type Patterns\n// ============================================================================\n// Note: Field type helpers are now exported from ./fields.ts with PascalCase names\n// (e.g., TextField, EmailField, JSONField, etc.) to ensure consistent naming.\n\n// ============================================================================\n// Relation Field Helpers - Explicit Relationship Definitions\n// ============================================================================\n\n/**\n * Relation field configuration options\n */\nexport interface RelationConfig {\n /**\n * Target collection name (e.g., 'users', 'posts', 'tags')\n * This is the PocketBase collection that the relation points to\n */\n collection: string;\n\n /**\n * Whether to cascade delete related records when this record is deleted\n * @default false\n */\n cascadeDelete?: boolean;\n}\n\n/**\n * Multiple relation field configuration options\n */\nexport interface RelationsConfig extends RelationConfig {\n /**\n * Minimum number of relations required\n * @default 0\n */\n minSelect?: number;\n\n /**\n * Maximum number of relations allowed\n * @default 999\n */\n maxSelect?: number;\n}\n\n/**\n * Internal marker for relation metadata\n * Used by the analyzer to detect explicit relation definitions\n */\nconst RELATION_METADATA_KEY = \"__pocketbase_relation__\";\n\n/**\n * Creates a single relation field schema with explicit collection target\n * Maps to PocketBase 'relation' field type with maxSelect=1\n *\n * This is the recommended way to define relations - it's explicit and doesn't\n * rely on naming conventions.\n *\n * @param config - Relation configuration with target collection\n * @returns Zod string schema with relation metadata\n *\n * @example\n * // Single relation to users collection\n * const PostSchema = z.object({\n * title: z.string(),\n * author: RelationField({ collection: 'users' }),\n * });\n *\n * @example\n * // Relation with cascade delete\n * const CommentSchema = z.object({\n * content: z.string(),\n * post: RelationField({ collection: 'posts', cascadeDelete: true }),\n * });\n */\nexport function RelationField(config: RelationConfig) {\n const metadata = {\n [RELATION_METADATA_KEY]: {\n type: \"single\",\n collection: config.collection,\n cascadeDelete: config.cascadeDelete ?? false,\n maxSelect: 1,\n minSelect: 0,\n },\n };\n\n return z.string().describe(JSON.stringify(metadata));\n}\n\n/**\n * Creates a multiple relation field schema with explicit collection target\n * Maps to PocketBase 'relation' field type with maxSelect>1\n *\n * This is the recommended way to define multi-relations - it's explicit and\n * doesn't rely on naming conventions.\n *\n * @param config - Relations configuration with target collection and limits\n * @returns Zod array of strings schema with relation metadata\n *\n * @example\n * // Multiple relations to tags collection\n * const PostSchema = z.object({\n * title: z.string(),\n * tags: RelationsField({ collection: 'tags' }),\n * });\n *\n * @example\n * // Relations with min/max constraints\n * const ProjectSchema = z.object({\n * title: z.string(),\n * collaborators: RelationsField({\n * collection: 'users',\n * minSelect: 1,\n * maxSelect: 10,\n * }),\n * });\n */\nexport function RelationsField(config: RelationsConfig) {\n const metadata = {\n [RELATION_METADATA_KEY]: {\n type: \"multiple\",\n collection: config.collection,\n cascadeDelete: config.cascadeDelete ?? false,\n maxSelect: config.maxSelect ?? 999,\n minSelect: config.minSelect ?? 0,\n },\n };\n\n let schema = z.array(z.string());\n\n // Apply array constraints for Zod validation\n if (config.minSelect !== undefined) {\n schema = schema.min(config.minSelect);\n }\n if (config.maxSelect !== undefined) {\n schema = schema.max(config.maxSelect);\n }\n\n return schema.describe(JSON.stringify(metadata));\n}\n\n/**\n * Extracts relation metadata from a Zod type's description\n * Used internally by the analyzer to detect explicit relation definitions\n *\n * @param description - The Zod type's description string\n * @returns Relation metadata if present, null otherwise\n */\nexport function extractRelationMetadata(description: string | undefined): {\n type: \"single\" | \"multiple\";\n collection: string;\n cascadeDelete: boolean;\n maxSelect: number;\n minSelect: number;\n} | null {\n if (!description) return null;\n\n try {\n const parsed = JSON.parse(description);\n if (parsed[RELATION_METADATA_KEY]) {\n return parsed[RELATION_METADATA_KEY];\n }\n } catch {\n // Not JSON, ignore\n }\n\n return null;\n}\n\n/**\n * Attach permission metadata to a Zod schema\n *\n * This helper function allows you to define PocketBase API rules alongside your\n * entity schema definitions. The permissions are stored as metadata using Zod's\n * describe() method and will be extracted during migration generation.\n *\n * @param schema - The Zod schema to attach permissions to\n * @param config - Either a PermissionTemplateConfig (for template-based permissions)\n * or a PermissionSchema (for custom permissions)\n * @returns The schema with permission metadata attached\n *\n * @example\n * // Using a template\n * const ProjectSchema = withPermissions(\n * z.object({ title: z.string(), User: z.string() }),\n * { template: 'owner-only', ownerField: 'User' }\n * );\n *\n * @example\n * // Using custom rules\n * const ProjectSchema = withPermissions(\n * z.object({ title: z.string() }),\n * { listRule: '@request.auth.id != \"\"', viewRule: '' }\n * );\n *\n * @example\n * // Using template with custom rule overrides\n * const ProjectSchema = withPermissions(\n * z.object({ title: z.string(), User: z.string() }),\n * {\n * template: 'owner-only',\n * ownerField: 'User',\n * customRules: { listRule: '@request.auth.id != \"\"' }\n * }\n * );\n */\nexport function withPermissions<T extends z.ZodTypeAny>(\n schema: T,\n config: PermissionTemplateConfig | PermissionSchema\n): T {\n // Create metadata object with permissions config directly\n // The PermissionAnalyzer will handle resolving templates vs direct schemas\n const metadata = {\n permissions: config,\n };\n\n // Attach permission metadata to schema using Zod's describe() method\n // The metadata is serialized as JSON and stored in the schema's description\n return schema.describe(JSON.stringify(metadata)) as T;\n}\n\n/**\n * Attach index definitions to a Zod schema\n *\n * This helper function allows you to define PocketBase indexes alongside your\n * entity schema definitions. The indexes are stored as metadata using Zod's\n * describe() method and will be extracted during migration generation.\n *\n * @param schema - The Zod schema to attach indexes to\n * @param indexes - Array of PocketBase index SQL statements\n * @returns The schema with index metadata attached\n *\n * @example\n * // Define indexes for a user schema\n * const UserSchema = withIndexes(\n * withPermissions(\n * z.object({ name: z.string(), email: z.string().email() }),\n * userPermissions\n * ),\n * [\n * 'CREATE UNIQUE INDEX idx_users_email ON users (email)',\n * 'CREATE INDEX idx_users_name ON users (name)'\n * ]\n * );\n *\n * @example\n * // Single index\n * const ProjectSchema = withIndexes(\n * ProjectDatabaseSchema,\n * ['CREATE INDEX idx_projects_status ON projects (status)']\n * );\n */\nexport function withIndexes<T extends z.ZodTypeAny>(schema: T, indexes: string[]): T {\n // Extract existing metadata if present\n let existingMetadata: any = {};\n\n if (schema.description) {\n try {\n existingMetadata = JSON.parse(schema.description);\n } catch {\n // If description is not JSON, ignore it\n }\n }\n\n // Merge indexes with existing metadata\n const metadata = {\n ...existingMetadata,\n indexes,\n };\n\n // Attach metadata to schema using Zod's describe() method\n return schema.describe(JSON.stringify(metadata)) as T;\n}\n\n/**\n * Configuration options for defining a collection\n */\nexport interface CollectionConfig {\n /**\n * The name of the PocketBase collection\n * This will be used when generating migrations\n */\n collectionName: string;\n\n /**\n * The Zod schema definition for the collection\n */\n schema: z.ZodObject<any>;\n\n /**\n * Optional permission configuration\n * Can be a template-based config or custom permission rules\n */\n permissions?: PermissionTemplateConfig | PermissionSchema;\n\n /**\n * Optional array of index SQL statements\n * Example: ['CREATE UNIQUE INDEX idx_users_email ON users (email)']\n */\n indexes?: string[];\n\n /**\n * Optional collection type\n * - \"base\": Standard collection (default)\n * - \"auth\": Authentication collection with system auth fields\n *\n * If not specified, the type will be auto-detected based on field presence\n * (collections with both email and password fields are detected as auth)\n */\n type?: \"base\" | \"auth\";\n\n /**\n * Future extensibility - additional options can be added here\n */\n [key: string]: unknown;\n}\n\n/**\n * High-level wrapper for defining a PocketBase collection with all metadata\n *\n * This is the recommended way to define collections as it provides a single\n * entry point for collection name, schema, permissions, indexes, and future features.\n *\n * @param config - Collection configuration object\n * @returns The schema with all metadata attached\n *\n * @example\n * // Recommended: Use default export for clarity\n * const PostCollection = defineCollection({\n * collectionName: \"posts\",\n * schema: z.object({\n * title: z.string(),\n * content: z.string(),\n * author: RelationField({ collection: \"users\" }),\n * }),\n * permissions: {\n * template: \"owner-only\",\n * ownerField: \"author\",\n * },\n * });\n * export default PostCollection;\n *\n * @example\n * // Also supported: Named export (backward compatible)\n * export const PostCollection = defineCollection({\n * collectionName: \"posts\",\n * schema: z.object({\n * title: z.string(),\n * content: z.string(),\n * author: RelationField({ collection: \"users\" }),\n * }),\n * permissions: {\n * template: \"owner-only\",\n * ownerField: \"author\",\n * },\n * });\n *\n * @example\n * // Collection with permissions and indexes\n * export const UserSchema = defineCollection({\n * collectionName: \"users\",\n * schema: z.object({\n * name: z.string(),\n * email: z.string().email(),\n * }),\n * permissions: {\n * listRule: \"id = @request.auth.id\",\n * viewRule: \"id = @request.auth.id\",\n * createRule: \"\",\n * updateRule: \"id = @request.auth.id\",\n * deleteRule: \"id = @request.auth.id\",\n * },\n * indexes: [\n * \"CREATE UNIQUE INDEX idx_users_email ON users (email)\",\n * ],\n * });\n *\n * @example\n * // Collection with template and custom rule overrides\n * export const ProjectSchema = defineCollection({\n * collectionName: \"projects\",\n * schema: z.object({\n * title: z.string(),\n * owner: RelationField({ collection: \"users\" }),\n * }),\n * permissions: {\n * template: \"owner-only\",\n * ownerField: \"owner\",\n * customRules: {\n * listRule: '@request.auth.id != \"\"',\n * },\n * },\n * });\n */\nexport function defineCollection(config: CollectionConfig): z.ZodObject<any> {\n const { collectionName, schema, permissions, indexes, type, ...futureOptions } = config;\n\n // Build metadata object\n const metadata: any = {\n collectionName,\n };\n\n // Add type if provided\n if (type) {\n metadata.type = type;\n }\n\n // Add permissions if provided\n if (permissions) {\n metadata.permissions = permissions;\n }\n\n // Add indexes if provided\n if (indexes) {\n metadata.indexes = indexes;\n }\n\n // Add any future options\n if (Object.keys(futureOptions).length > 0) {\n Object.assign(metadata, futureOptions);\n }\n\n // Attach all metadata to schema using Zod's describe() method\n return schema.describe(JSON.stringify(metadata)) as z.ZodObject<any>;\n}\n","import { z } from \"zod\";\n\n// ============================================================================\n// Field Metadata System\n// ============================================================================\n\n/**\n * Internal marker for field metadata\n * Used by the migration generator to detect explicit field type definitions\n */\nexport const FIELD_METADATA_KEY = \"__pocketbase_field__\";\n\n/**\n * PocketBase field types\n */\nexport type PocketBaseFieldType =\n | \"text\"\n | \"email\"\n | \"url\"\n | \"editor\"\n | \"number\"\n | \"bool\"\n | \"date\"\n | \"autodate\"\n | \"select\"\n | \"relation\"\n | \"file\"\n | \"json\"\n | \"geoPoint\";\n\n/**\n * Field metadata structure embedded in Zod schema descriptions\n */\nexport interface FieldMetadata {\n type: PocketBaseFieldType;\n options?: Record<string, any>;\n}\n\n/**\n * Extracts field metadata from a Zod type's description\n * Used by the migration generator to detect explicit field type definitions\n *\n * @param description - The Zod type's description string\n * @returns Field metadata if present, null otherwise\n *\n * @example\n * const schema = TextField({ min: 1, max: 100 });\n * const metadata = extractFieldMetadata(schema.description);\n * // Returns: { type: \"text\", options: { min: 1, max: 100 } }\n */\nexport function extractFieldMetadata(description: string | undefined): FieldMetadata | null {\n if (!description) return null;\n\n try {\n const parsed = JSON.parse(description);\n if (parsed[FIELD_METADATA_KEY]) {\n return parsed[FIELD_METADATA_KEY];\n }\n } catch {\n // Not JSON, ignore\n }\n\n return null;\n}\n\n// ============================================================================\n// Field Options Interfaces\n// ============================================================================\n\n/**\n * Text field configuration options\n */\nexport interface TextFieldOptions {\n /**\n * Minimum length constraint\n */\n min?: number;\n\n /**\n * Maximum length constraint\n */\n max?: number;\n\n /**\n * Pattern constraint (regex)\n */\n pattern?: RegExp | string;\n\n /**\n * Auto-generate pattern for automatic value generation\n * Example: \"[A-Z]{3}-[0-9]{6}\" generates values like \"ABC-123456\"\n */\n autogeneratePattern?: string;\n}\n\n/**\n * Number field configuration options\n */\nexport interface NumberFieldOptions {\n /**\n * Minimum value constraint\n */\n min?: number;\n\n /**\n * Maximum value constraint\n */\n max?: number;\n\n /**\n * Whether to disallow decimal values (integers only)\n */\n noDecimal?: boolean;\n\n /**\n * Whether the field is required\n * @default false\n *\n * Note: In PocketBase, `required: true` for number fields means the value must be non-zero.\n * If you want to allow zero values (e.g., for progress: 0-100), keep this as `false`.\n * Set to `true` only if you want to enforce non-zero values.\n */\n required?: boolean;\n}\n\n/**\n * Date field configuration options\n */\nexport interface DateFieldOptions {\n /**\n * Minimum date constraint\n */\n min?: Date | string;\n\n /**\n * Maximum date constraint\n */\n max?: Date | string;\n}\n\n/**\n * Autodate field configuration options\n */\nexport interface AutodateFieldOptions {\n /**\n * Set date automatically on record creation\n * @default false\n */\n onCreate?: boolean;\n\n /**\n * Update date automatically on record update\n * @default false\n */\n onUpdate?: boolean;\n}\n\n/**\n * Select field configuration options\n */\nexport interface SelectFieldOptions {\n /**\n * Maximum number of selections allowed\n * If > 1, enables multiple selection\n * @default 1\n */\n maxSelect?: number;\n}\n\n/**\n * File field configuration options\n */\nexport interface FileFieldOptions {\n /**\n * Allowed MIME types\n * Example: [\"image/*\", \"application/pdf\"]\n */\n mimeTypes?: string[];\n\n /**\n * Maximum file size in bytes\n */\n maxSize?: number;\n\n /**\n * Thumbnail sizes to generate\n * Example: [\"100x100\", \"200x200\"]\n * Set to null to explicitly disable thumbnails\n */\n thumbs?: string[];\n\n /**\n * Whether the file is protected (requires auth to access)\n * @default false\n */\n protected?: boolean;\n}\n\n/**\n * Multiple files field configuration options\n */\nexport interface FilesFieldOptions extends FileFieldOptions {\n /**\n * Minimum number of files required\n */\n minSelect?: number;\n\n /**\n * Maximum number of files allowed\n */\n maxSelect?: number;\n}\n\n// ============================================================================\n// Field Helper Functions\n// ============================================================================\n\n/**\n * Creates a boolean field schema\n * Maps to PocketBase 'bool' field type\n *\n * @returns Zod boolean schema with PocketBase metadata\n *\n * @example\n * const ProductSchema = z.object({\n * active: BoolField(),\n * featured: BoolField().optional(),\n * });\n */\nexport function BoolField(): z.ZodBoolean {\n const metadata = {\n [FIELD_METADATA_KEY]: {\n type: \"bool\" as const,\n },\n };\n\n return z.boolean().describe(JSON.stringify(metadata));\n}\n\n/**\n * Creates a number field schema with optional constraints\n * Maps to PocketBase 'number' field type\n *\n * @param options - Optional constraints for the number field\n * @returns Zod number schema with PocketBase metadata\n *\n * @example\n * const ProductSchema = z.object({\n * price: NumberField({ min: 0 }),\n * quantity: NumberField({ min: 0, noDecimal: true }),\n * rating: NumberField({ min: 0, max: 5 }),\n * progress: NumberField({ min: 0, max: 100 }), // required defaults to false, allowing zero\n * score: NumberField({ min: 1, max: 10, required: true }), // requires non-zero value\n * });\n *\n * @remarks\n * By default, number fields are not required (`required: false`), which allows zero values.\n * In PocketBase, `required: true` for number fields means the value must be non-zero.\n * If you set `min: 0` and want to allow zero, keep `required: false` (the default).\n */\nexport function NumberField(options?: NumberFieldOptions): z.ZodNumber {\n // Validate options\n if (options?.min !== undefined && options?.max !== undefined) {\n if (options.min > options.max) {\n throw new Error(\"NumberField: min cannot be greater than max\");\n }\n }\n\n // Create base schema\n let schema = z.number();\n\n // Apply Zod validations\n if (options?.min !== undefined) {\n schema = schema.min(options.min);\n }\n if (options?.max !== undefined) {\n schema = schema.max(options.max);\n }\n\n // Build metadata\n const metadata = {\n [FIELD_METADATA_KEY]: {\n type: \"number\" as const,\n options: options || {},\n },\n };\n\n return schema.describe(JSON.stringify(metadata));\n}\n\n/**\n * Creates a text field schema with optional constraints\n * Maps to PocketBase 'text' field type\n *\n * @param options - Optional constraints for the text field\n * @returns Zod string schema with PocketBase metadata\n *\n * @example\n * const ProductSchema = z.object({\n * name: TextField({ min: 1, max: 200 }),\n * sku: TextField({ autogeneratePattern: \"[A-Z]{3}-[0-9]{6}\" }),\n * description: TextField({ max: 1000 }),\n * });\n */\nexport function TextField(options?: TextFieldOptions): z.ZodString {\n // Validate options\n if (options?.min !== undefined && options?.max !== undefined) {\n if (options.min > options.max) {\n throw new Error(\"TextField: min cannot be greater than max\");\n }\n }\n\n // Create base schema\n let schema = z.string();\n\n // Apply Zod validations\n if (options?.min !== undefined) {\n schema = schema.min(options.min);\n }\n if (options?.max !== undefined) {\n schema = schema.max(options.max);\n }\n if (options?.pattern !== undefined) {\n const pattern = options.pattern instanceof RegExp ? options.pattern : new RegExp(options.pattern);\n schema = schema.regex(pattern);\n }\n\n // Build metadata\n const metadata = {\n [FIELD_METADATA_KEY]: {\n type: \"text\" as const,\n options: options || {},\n },\n };\n\n return schema.describe(JSON.stringify(metadata));\n}\n\n/**\n * Creates an email field schema\n * Maps to PocketBase 'email' field type\n *\n * @returns Zod string schema with email validation and PocketBase metadata\n *\n * @example\n * const UserSchema = z.object({\n * email: EmailField(),\n * alternateEmail: EmailField().optional(),\n * });\n */\nexport function EmailField(): z.ZodString {\n const metadata = {\n [FIELD_METADATA_KEY]: {\n type: \"email\" as const,\n },\n };\n\n return z.string().email().describe(JSON.stringify(metadata));\n}\n\n/**\n * Creates a URL field schema\n * Maps to PocketBase 'url' field type\n *\n * @returns Zod string schema with URL validation and PocketBase metadata\n *\n * @example\n * const ProductSchema = z.object({\n * website: URLField(),\n * documentation: URLField().optional(),\n * });\n */\nexport function URLField(): z.ZodString {\n const metadata = {\n [FIELD_METADATA_KEY]: {\n type: \"url\" as const,\n },\n };\n\n return z.string().url().describe(JSON.stringify(metadata));\n}\n\n/**\n * Creates a rich text editor field schema\n * Maps to PocketBase 'editor' field type\n *\n * @returns Zod string schema with PocketBase metadata\n *\n * @example\n * const PostSchema = z.object({\n * content: EditorField(),\n * summary: EditorField().optional(),\n * });\n */\nexport function EditorField(): z.ZodString {\n const metadata = {\n [FIELD_METADATA_KEY]: {\n type: \"editor\" as const,\n },\n };\n\n return z.string().describe(JSON.stringify(metadata));\n}\n\n/**\n * Creates a date field schema with optional constraints\n * Maps to PocketBase 'date' field type\n *\n * @param options - Optional date constraints\n * @returns Zod string schema with PocketBase metadata\n *\n * @example\n * const EventSchema = z.object({\n * startDate: DateField(),\n * endDate: DateField({ min: new Date('2024-01-01') }),\n * releaseDate: DateField().optional(),\n * });\n */\nexport function DateField(options?: DateFieldOptions): z.ZodString {\n // Validate options\n if (options?.min !== undefined && options?.max !== undefined) {\n const minDate = typeof options.min === \"string\" ? new Date(options.min) : options.min;\n const maxDate = typeof options.max === \"string\" ? new Date(options.max) : options.max;\n if (minDate > maxDate) {\n throw new Error(\"DateField: min cannot be greater than max\");\n }\n }\n\n // Create base schema\n const schema = z.string();\n\n // Build metadata\n const metadata = {\n [FIELD_METADATA_KEY]: {\n type: \"date\" as const,\n options: options || {},\n },\n };\n\n return schema.describe(JSON.stringify(metadata));\n}\n\n/**\n * Creates an autodate field schema with automatic timestamp management\n * Maps to PocketBase 'autodate' field type\n *\n * @param options - Optional autodate configuration\n * @returns Zod string schema with PocketBase metadata\n *\n * @example\n * const PostSchema = z.object({\n * createdAt: AutodateField({ onCreate: true }),\n * updatedAt: AutodateField({ onUpdate: true }),\n * publishedAt: AutodateField({ onCreate: true, onUpdate: false }),\n * });\n */\nexport function AutodateField(options?: AutodateFieldOptions): z.ZodString {\n const schema = z.string();\n\n // Build metadata\n const metadata = {\n [FIELD_METADATA_KEY]: {\n type: \"autodate\" as const,\n options: options || {},\n },\n };\n\n return schema.describe(JSON.stringify(metadata));\n}\n\n/**\n * Creates a select field schema from enum values\n * Maps to PocketBase 'select' field type\n *\n * @param values - Array of allowed string values\n * @param options - Optional select configuration\n * @returns Zod enum or array schema with PocketBase metadata\n *\n * @example\n * // Single select\n * const PostSchema = z.object({\n * status: SelectField([\"draft\", \"published\", \"archived\"]),\n * });\n *\n * @example\n * // Multiple select\n * const ProductSchema = z.object({\n * categories: SelectField([\"electronics\", \"clothing\", \"food\"], { maxSelect: 3 }),\n * });\n */\nexport function SelectField<T extends [string, ...string[]]>(\n values: T,\n options?: SelectFieldOptions\n): z.ZodEnum<T> | z.ZodArray<z.ZodEnum<T>> {\n const enumSchema = z.enum(values);\n\n // Build metadata\n const metadata = {\n [FIELD_METADATA_KEY]: {\n type: \"select\" as const,\n options: {\n values,\n maxSelect: options?.maxSelect ?? 1,\n },\n },\n };\n\n // Return array schema if maxSelect > 1\n if (options?.maxSelect && options.maxSelect > 1) {\n return z.array(enumSchema).describe(JSON.stringify(metadata));\n }\n\n return enumSchema.describe(JSON.stringify(metadata));\n}\n\n/**\n * Creates a single file field schema\n * Maps to PocketBase 'file' field type with maxSelect=1\n *\n * @param options - Optional file constraints\n * @returns Zod File schema with PocketBase metadata\n *\n * @example\n * const ProductSchema = z.object({\n * thumbnail: FileField({ mimeTypes: [\"image/*\"], maxSize: 5242880 }),\n * document: FileField({ mimeTypes: [\"application/pdf\"] }),\n * });\n */\nexport function FileField(options?: FileFieldOptions): z.ZodType<File> {\n const schema = z.instanceof(File);\n\n // Build metadata\n const metadata = {\n [FIELD_METADATA_KEY]: {\n type: \"file\" as const,\n options: options || {},\n },\n };\n\n return schema.describe(JSON.stringify(metadata));\n}\n\n/**\n * Creates a multiple files field schema\n * Maps to PocketBase 'file' field type with maxSelect>1\n *\n * @param options - Optional file constraints\n * @returns Zod array of File schema with PocketBase metadata\n *\n * @example\n * const ProductSchema = z.object({\n * images: FilesField({ mimeTypes: [\"image/*\"], maxSelect: 5 }),\n * attachments: FilesField({ minSelect: 1, maxSelect: 10 }),\n * });\n */\nexport function FilesField(options?: FilesFieldOptions): z.ZodArray<z.ZodType<File>> {\n // Validate options\n if (options?.minSelect !== undefined && options?.maxSelect !== undefined) {\n if (options.minSelect > options.maxSelect) {\n throw new Error(\"FilesField: minSelect cannot be greater than maxSelect\");\n }\n }\n\n let schema = z.array(z.instanceof(File));\n\n // Apply Zod validations\n if (options?.minSelect !== undefined) {\n schema = schema.min(options.minSelect);\n }\n if (options?.maxSelect !== undefined) {\n schema = schema.max(options.maxSelect);\n }\n\n // Build metadata\n const metadata = {\n [FIELD_METADATA_KEY]: {\n type: \"file\" as const,\n options: options || {},\n },\n };\n\n return schema.describe(JSON.stringify(metadata));\n}\n\n/**\n * Creates a JSON field schema with optional inner schema validation\n * Maps to PocketBase 'json' field type\n *\n * @param schema - Optional Zod schema for the JSON structure\n * @returns Zod schema with PocketBase metadata\n *\n * @example\n * // Any JSON\n * const ProductSchema = z.object({\n * metadata: JSONField(),\n * });\n *\n * @example\n * // Typed JSON\n * const ProductSchema = z.object({\n * settings: JSONField(z.object({\n * theme: z.string(),\n * notifications: z.boolean(),\n * })),\n * });\n */\nexport function JSONField<T extends z.ZodTypeAny>(schema?: T): T | z.ZodRecord<z.ZodString, z.ZodAny> {\n const baseSchema = schema ?? z.record(z.string(), z.any());\n\n // Build metadata\n const metadata = {\n [FIELD_METADATA_KEY]: {\n type: \"json\" as const,\n },\n };\n\n return baseSchema.describe(JSON.stringify(metadata)) as T | z.ZodRecord<z.ZodString, z.ZodAny>;\n}\n\n/**\n * Creates a geographic point field schema\n * Maps to PocketBase 'geoPoint' field type\n *\n * @returns Zod object schema with lon/lat fields and PocketBase metadata\n *\n * @example\n * const LocationSchema = z.object({\n * coordinates: GeoPointField(),\n * homeLocation: GeoPointField().optional(),\n * });\n */\nexport function GeoPointField(): z.ZodObject<{\n lon: z.ZodNumber;\n lat: z.ZodNumber;\n}> {\n const schema = z.object({\n lon: z.number(),\n lat: z.number(),\n });\n\n // Build metadata\n const metadata = {\n [FIELD_METADATA_KEY]: {\n type: \"geoPoint\" as const,\n },\n };\n\n return schema.describe(JSON.stringify(metadata));\n}\n","/**\n * Custom error classes for migration tool\n * Provides specific error types for better error handling and user feedback\n */\n\n/**\n * Base error class for all migration-related errors\n */\nexport class MigrationError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"MigrationError\";\n Object.setPrototypeOf(this, MigrationError.prototype);\n }\n}\n\n/**\n * Error thrown when schema parsing fails\n * Used when Zod schemas cannot be parsed or are invalid\n */\nexport class SchemaParsingError extends MigrationError {\n public readonly filePath?: string;\n public readonly originalError?: Error;\n\n constructor(message: string, filePath?: string, originalError?: Error) {\n super(message);\n this.name = \"SchemaParsingError\";\n this.filePath = filePath;\n this.originalError = originalError;\n Object.setPrototypeOf(this, SchemaParsingError.prototype);\n }\n\n /**\n * Creates a formatted error message with file path and original error details\n */\n public getDetailedMessage(): string {\n const parts: string[] = [this.message];\n\n if (this.filePath) {\n parts.push(`\\nFile: ${this.filePath}`);\n }\n\n if (this.originalError) {\n parts.push(`\\nCause: ${this.originalError.message}`);\n }\n\n return parts.join(\"\");\n }\n}\n\n/**\n * Error thrown when snapshot operations fail\n * Used for snapshot file read/write/parse errors\n */\nexport class SnapshotError extends MigrationError {\n public readonly snapshotPath?: string;\n public readonly operation?: \"read\" | \"write\" | \"parse\" | \"validate\";\n public readonly originalError?: Error;\n\n constructor(\n message: string,\n snapshotPath?: string,\n operation?: \"read\" | \"write\" | \"parse\" | \"validate\",\n originalError?: Error\n ) {\n super(message);\n this.name = \"SnapshotError\";\n this.snapshotPath = snapshotPath;\n this.operation = operation;\n this.originalError = originalError;\n Object.setPrototypeOf(this, SnapshotError.prototype);\n }\n\n /**\n * Creates a formatted error message with snapshot path and operation details\n */\n public getDetailedMessage(): string {\n const parts: string[] = [this.message];\n\n if (this.operation) {\n parts.push(`\\nOperation: ${this.operation}`);\n }\n\n if (this.snapshotPath) {\n parts.push(`\\nSnapshot: ${this.snapshotPath}`);\n }\n\n if (this.originalError) {\n parts.push(`\\nCause: ${this.originalError.message}`);\n }\n\n return parts.join(\"\");\n }\n}\n\n/**\n * Error thrown when migration file generation fails\n * Used when migration files cannot be created or written\n */\nexport class MigrationGenerationError extends MigrationError {\n public readonly migrationPath?: string;\n public readonly originalError?: Error;\n\n constructor(message: string, migrationPath?: string, originalError?: Error) {\n super(message);\n this.name = \"MigrationGenerationError\";\n this.migrationPath = migrationPath;\n this.originalError = originalError;\n Object.setPrototypeOf(this, MigrationGenerationError.prototype);\n }\n\n /**\n * Creates a formatted error message with migration path and original error details\n */\n public getDetailedMessage(): string {\n const parts: string[] = [this.message];\n\n if (this.migrationPath) {\n parts.push(`\\nMigration: ${this.migrationPath}`);\n }\n\n if (this.originalError) {\n parts.push(`\\nCause: ${this.originalError.message}`);\n }\n\n return parts.join(\"\");\n }\n}\n\n/**\n * Error thrown when file system operations fail\n * Used for directory creation, file permissions, disk space issues\n */\nexport class FileSystemError extends MigrationError {\n public readonly path?: string;\n public readonly operation?: \"read\" | \"write\" | \"create\" | \"delete\" | \"access\";\n public readonly code?: string;\n public readonly originalError?: Error;\n\n constructor(\n message: string,\n path?: string,\n operation?: \"read\" | \"write\" | \"create\" | \"delete\" | \"access\",\n code?: string,\n originalError?: Error\n ) {\n super(message);\n this.name = \"FileSystemError\";\n this.path = path;\n this.operation = operation;\n this.code = code;\n this.originalError = originalError;\n Object.setPrototypeOf(this, FileSystemError.prototype);\n }\n\n /**\n * Creates a formatted error message with path, operation, and error code details\n */\n public getDetailedMessage(): string {\n const parts: string[] = [this.message];\n\n if (this.operation) {\n parts.push(`\\nOperation: ${this.operation}`);\n }\n\n if (this.path) {\n parts.push(`\\nPath: ${this.path}`);\n }\n\n if (this.code) {\n parts.push(`\\nError Code: ${this.code}`);\n }\n\n if (this.originalError) {\n parts.push(`\\nCause: ${this.originalError.message}`);\n }\n\n return parts.join(\"\");\n }\n}\n\n/**\n * Error thrown when configuration is invalid\n * Used for configuration file parsing, validation, and path resolution errors\n */\nexport class ConfigurationError extends MigrationError {\n public readonly configPath?: string;\n public readonly invalidFields?: string[];\n public readonly originalError?: Error;\n\n constructor(message: string, configPath?: string, invalidFields?: string[], originalError?: Error) {\n super(message);\n this.name = \"ConfigurationError\";\n this.configPath = configPath;\n this.invalidFields = invalidFields;\n this.originalError = originalError;\n Object.setPrototypeOf(this, ConfigurationError.prototype);\n }\n\n /**\n * Creates a formatted error message with configuration details\n */\n public getDetailedMessage(): string {\n const parts: string[] = [this.message];\n\n if (this.configPath) {\n parts.push(`\\nConfiguration File: ${this.configPath}`);\n }\n\n if (this.invalidFields && this.invalidFields.length > 0) {\n parts.push(`\\nInvalid Fields: ${this.invalidFields.join(\", \")}`);\n }\n\n if (this.originalError) {\n parts.push(`\\nCause: ${this.originalError.message}`);\n }\n\n return parts.join(\"\");\n }\n}\n\n/**\n * Error thrown when CLI command usage is incorrect\n * Used for invalid arguments, missing required options, etc.\n */\nexport class CLIUsageError extends MigrationError {\n public readonly command?: string;\n public readonly suggestion?: string;\n\n constructor(message: string, command?: string, suggestion?: string) {\n super(message);\n this.name = \"CLIUsageError\";\n this.command = command;\n this.suggestion = suggestion;\n Object.setPrototypeOf(this, CLIUsageError.prototype);\n }\n\n /**\n * Creates a formatted error message with usage suggestions\n */\n public getDetailedMessage(): string {\n const parts: string[] = [this.message];\n\n if (this.command) {\n parts.push(`\\nCommand: ${this.command}`);\n }\n\n if (this.suggestion) {\n parts.push(`\\nSuggestion: ${this.suggestion}`);\n }\n\n return parts.join(\"\");\n }\n}\n","import type { PermissionSchema, PermissionTemplateConfig, RuleExpression } from \"../utils/permissions\";\n\n/**\n * Predefined permission templates for common access control patterns\n */\nexport const PermissionTemplates = {\n /**\n * Public access - anyone can perform all operations\n */\n public: (): PermissionSchema => ({\n listRule: \"\",\n viewRule: \"\",\n createRule: \"\",\n updateRule: \"\",\n deleteRule: \"\",\n }),\n\n /**\n * Authenticated users only - requires valid authentication for all operations\n */\n authenticated: (): PermissionSchema => ({\n listRule: '@request.auth.id != \"\"',\n viewRule: '@request.auth.id != \"\"',\n createRule: '@request.auth.id != \"\"',\n updateRule: '@request.auth.id != \"\"',\n deleteRule: '@request.auth.id != \"\"',\n }),\n\n /**\n * Owner-only access - users can only manage their own records\n * @param ownerField - Name of the relation field pointing to user (default: 'User')\n */\n ownerOnly: (ownerField: string = \"User\"): PermissionSchema => ({\n listRule: `@request.auth.id != \"\" && ${ownerField} = @request.auth.id`,\n viewRule: `@request.auth.id != \"\" && ${ownerField} = @request.auth.id`,\n createRule: '@request.auth.id != \"\"',\n updateRule: `@request.auth.id != \"\" && ${ownerField} = @request.auth.id`,\n deleteRule: `@request.auth.id != \"\" && ${ownerField} = @request.auth.id`,\n }),\n\n /**\n * Admin/superuser only access\n * Assumes a 'role' field exists with 'admin' value\n * @param roleField - Name of the role field (default: 'role')\n */\n adminOnly: (roleField: string = \"role\"): PermissionSchema => ({\n listRule: `@request.auth.id != \"\" && @request.auth.${roleField} = \"admin\"`,\n viewRule: `@request.auth.id != \"\" && @request.auth.${roleField} = \"admin\"`,\n createRule: `@request.auth.id != \"\" && @request.auth.${roleField} = \"admin\"`,\n updateRule: `@request.auth.id != \"\" && @request.auth.${roleField} = \"admin\"`,\n deleteRule: `@request.auth.id != \"\" && @request.auth.${roleField} = \"admin\"`,\n }),\n\n /**\n * Public read, authenticated write\n * Anyone can list/view, but only authenticated users can create/update/delete\n */\n readPublic: (): PermissionSchema => ({\n listRule: \"\",\n viewRule: \"\",\n createRule: '@request.auth.id != \"\"',\n updateRule: '@request.auth.id != \"\"',\n deleteRule: '@request.auth.id != \"\"',\n }),\n\n /**\n * Locked access - only superusers can perform operations\n * All rules are set to null (locked)\n */\n locked: (): PermissionSchema => ({\n listRule: null,\n viewRule: null,\n createRule: null,\n updateRule: null,\n deleteRule: null,\n }),\n\n /**\n * Read-only authenticated - authenticated users can read, no write access\n */\n readOnlyAuthenticated: (): PermissionSchema => ({\n listRule: '@request.auth.id != \"\"',\n viewRule: '@request.auth.id != \"\"',\n createRule: null,\n updateRule: null,\n deleteRule: null,\n }),\n};\n\n/**\n * Resolve template configuration to concrete permission schema\n * @param config - Template configuration or direct permission schema\n * @returns Resolved permission schema with all rules defined\n */\nexport function resolveTemplate(config: PermissionTemplateConfig): PermissionSchema {\n let baseRules: PermissionSchema;\n\n switch (config.template) {\n case \"public\":\n baseRules = PermissionTemplates.public();\n break;\n case \"authenticated\":\n baseRules = PermissionTemplates.authenticated();\n break;\n case \"owner-only\":\n baseRules = PermissionTemplates.ownerOnly(config.ownerField);\n break;\n case \"admin-only\":\n baseRules = PermissionTemplates.adminOnly(config.roleField);\n break;\n case \"read-public\":\n baseRules = PermissionTemplates.readPublic();\n break;\n case \"custom\":\n baseRules = {};\n break;\n default: {\n // Exhaustive check - TypeScript will error if we miss a template type\n const _exhaustive: never = config.template;\n throw new Error(`Unknown template type: ${_exhaustive}`);\n }\n }\n\n // Merge with custom rules if provided (custom rules override template rules)\n return {\n ...baseRules,\n ...config.customRules,\n };\n}\n\n/**\n * Check if a configuration is a template config or direct permission schema\n * @param config - Configuration to check\n * @returns True if it's a template configuration\n */\nexport function isTemplateConfig(\n config: PermissionTemplateConfig | PermissionSchema\n): config is PermissionTemplateConfig {\n return \"template\" in config;\n}\n\n/**\n * Check if a configuration is a direct permission schema\n * @param config - Configuration to check\n * @returns True if it's a direct permission schema\n */\nexport function isPermissionSchema(config: PermissionTemplateConfig | PermissionSchema): config is PermissionSchema {\n return (\n \"listRule\" in config ||\n \"viewRule\" in config ||\n \"createRule\" in config ||\n \"updateRule\" in config ||\n \"deleteRule\" in config ||\n \"manageRule\" in config\n );\n}\n\n/**\n * Validation result for permission configuration\n */\nexport interface PermissionValidationResult {\n valid: boolean;\n errors: string[];\n warnings: string[];\n}\n\n/**\n * Validate a permission configuration\n * @param config - Permission configuration to validate\n * @param isAuthCollection - Whether this is for an auth collection\n * @returns Validation result\n */\nexport function validatePermissionConfig(\n config: PermissionTemplateConfig | PermissionSchema,\n isAuthCollection: boolean = false\n): PermissionValidationResult {\n const result: PermissionValidationResult = {\n valid: true,\n errors: [],\n warnings: [],\n };\n\n // Resolve to permission schema\n let permissions: PermissionSchema;\n if (isTemplateConfig(config)) {\n // Validate template config\n if (config.template === \"owner-only\" && !config.ownerField) {\n result.warnings.push(\"owner-only template without ownerField specified - using default 'User'\");\n }\n if (config.template === \"admin-only\" && !config.roleField) {\n result.warnings.push(\"admin-only template without roleField specified - using default 'role'\");\n }\n permissions = resolveTemplate(config);\n } else {\n permissions = config;\n }\n\n // Validate manageRule usage\n if (permissions.manageRule !== undefined && !isAuthCollection) {\n result.errors.push(\"manageRule is only valid for auth collections\");\n result.valid = false;\n }\n\n // Validate rule expressions\n const ruleTypes: (keyof PermissionSchema)[] = [\"listRule\", \"viewRule\", \"createRule\", \"updateRule\", \"deleteRule\"];\n if (isAuthCollection) {\n ruleTypes.push(\"manageRule\");\n }\n\n for (const ruleType of ruleTypes) {\n const rule = permissions[ruleType];\n if (rule !== undefined && rule !== null && rule !== \"\") {\n const ruleValidation = validateRuleExpression(rule);\n if (!ruleValidation.valid) {\n result.errors.push(`${ruleType}: ${ruleValidation.errors.join(\", \")}`);\n result.valid = false;\n }\n result.warnings.push(...ruleValidation.warnings.map((w) => `${ruleType}: ${w}`));\n }\n }\n\n return result;\n}\n\n/**\n * Validate a single rule expression for basic syntax\n * @param expression - Rule expression to validate\n * @returns Validation result\n */\nexport function validateRuleExpression(expression: RuleExpression): PermissionValidationResult {\n const result: PermissionValidationResult = {\n valid: true,\n errors: [],\n warnings: [],\n };\n\n // Null and empty string are always valid\n if (expression === null || expression === \"\") {\n return result;\n }\n\n // Check for balanced parentheses\n let parenCount = 0;\n for (const char of expression) {\n if (char === \"(\") parenCount++;\n if (char === \")\") parenCount--;\n if (parenCount < 0) {\n result.errors.push(\"Unbalanced parentheses\");\n result.valid = false;\n return result;\n }\n }\n if (parenCount !== 0) {\n result.errors.push(\"Unbalanced parentheses\");\n result.valid = false;\n }\n\n // Check for common mistakes\n if (expression.includes(\"==\")) {\n result.warnings.push(\"Use '=' instead of '==' for equality comparison\");\n }\n\n // Check for valid @request references\n const requestRefs = expression.match(/@request\\.[a-zA-Z_][a-zA-Z0-9_.]*/g) || [];\n for (const ref of requestRefs) {\n const isValid =\n ref.startsWith(\"@request.auth.\") ||\n ref === \"@request.method\" ||\n ref === \"@request.context\" ||\n ref.startsWith(\"@request.body.\") ||\n ref.startsWith(\"@request.query.\") ||\n ref.startsWith(\"@request.headers.\");\n\n if (!isValid) {\n result.errors.push(`Invalid @request reference: '${ref}'`);\n result.valid = false;\n }\n }\n\n return result;\n}\n\n/**\n * Create a custom permission schema with type safety\n * @param permissions - Partial permission schema\n * @returns Complete permission schema with null defaults\n */\nexport function createPermissions(permissions: Partial<PermissionSchema>): PermissionSchema {\n return {\n listRule: permissions.listRule ?? null,\n viewRule: permissions.viewRule ?? null,\n createRule: permissions.createRule ?? null,\n updateRule: permissions.updateRule ?? null,\n deleteRule: permissions.deleteRule ?? null,\n manageRule: permissions.manageRule ?? null,\n };\n}\n\n/**\n * Merge multiple permission schemas, with later schemas taking precedence\n * @param schemas - Permission schemas to merge\n * @returns Merged permission schema\n */\nexport function mergePermissions(...schemas: Partial<PermissionSchema>[]): PermissionSchema {\n const merged: PermissionSchema = {\n listRule: null,\n viewRule: null,\n createRule: null,\n updateRule: null,\n deleteRule: null,\n manageRule: null,\n };\n\n for (const schema of schemas) {\n if (schema.listRule !== undefined) merged.listRule = schema.listRule;\n if (schema.viewRule !== undefined) merged.viewRule = schema.viewRule;\n if (schema.createRule !== undefined) merged.createRule = schema.createRule;\n if (schema.updateRule !== undefined) merged.updateRule = schema.updateRule;\n if (schema.deleteRule !== undefined) merged.deleteRule = schema.deleteRule;\n if (schema.manageRule !== undefined) merged.manageRule = schema.manageRule;\n }\n\n return merged;\n}\n","/**\n * Rule validator for PocketBase API rule expressions\n *\n * Validates permission rule expressions against PocketBase syntax rules,\n * including field references, @request references, and basic syntax validation.\n */\n\nimport type { APIRuleType, RuleExpression } from \"../utils/permissions\";\nimport type { FieldDefinition } from \"./types\";\n\n/**\n * Validation result for rule expressions\n */\nexport interface RuleValidationResult {\n /** Whether the rule expression is valid */\n valid: boolean;\n\n /** List of validation errors */\n errors: string[];\n\n /** List of validation warnings */\n warnings: string[];\n\n /** List of field references found in the expression */\n fieldReferences: string[];\n}\n\n/**\n * Rule expression validator\n *\n * Validates PocketBase API rule expressions for:\n * - Field reference existence and validity\n * - @request reference syntax\n * - Basic expression syntax (parentheses, operators)\n * - Auth collection specific rules (manageRule)\n */\nexport class RuleValidator {\n private fields: Map<string, FieldDefinition>;\n private collectionName: string;\n private isAuthCollection: boolean;\n\n constructor(collectionName: string, fields: FieldDefinition[], isAuthCollection: boolean = false) {\n this.collectionName = collectionName;\n this.fields = new Map(fields.map((f) => [f.name, f]));\n this.isAuthCollection = isAuthCollection;\n\n // Add system fields that are always available in PocketBase\n this.addSystemFields();\n }\n\n /**\n * Add system fields that are always available in PocketBase collections\n * These fields are automatically added by PocketBase and can be referenced in rules\n */\n private addSystemFields(): void {\n // Base system fields available in all collections\n const systemFields: FieldDefinition[] = [\n { name: \"id\", type: \"text\", required: true, options: {} },\n { name: \"created\", type: \"date\", required: true, options: {} },\n { name: \"updated\", type: \"date\", required: true, options: {} },\n { name: \"collectionId\", type: \"text\", required: true, options: {} },\n { name: \"collectionName\", type: \"text\", required: true, options: {} },\n ];\n\n // Auth collection specific system fields\n if (this.isAuthCollection) {\n systemFields.push(\n { name: \"email\", type: \"email\", required: true, options: {} },\n { name: \"emailVisibility\", type: \"bool\", required: false, options: {} },\n { name: \"verified\", type: \"bool\", required: false, options: {} },\n { name: \"tokenKey\", type: \"text\", required: true, options: {} },\n { name: \"password\", type: \"text\", required: true, options: {} }\n );\n }\n\n // Add system fields to the fields map (don't overwrite user-defined fields)\n for (const field of systemFields) {\n if (!this.fields.has(field.name)) {\n this.fields.set(field.name, field);\n }\n }\n }\n\n /**\n * Validate a rule expression\n *\n * @param ruleType - The type of rule being validated\n * @param expression - The rule expression to validate\n * @returns Validation result with errors, warnings, and field references\n */\n validate(ruleType: APIRuleType, expression: RuleExpression): RuleValidationResult {\n const result: RuleValidationResult = {\n valid: true,\n errors: [],\n warnings: [],\n fieldReferences: [],\n };\n\n // Null means locked (superuser only) - always valid\n if (expression === null) {\n return result;\n }\n\n // Empty string means public - always valid but warn\n if (expression === \"\") {\n result.warnings.push(`${ruleType} is public - anyone can perform this operation`);\n return result;\n }\n\n // Validate manageRule only for auth collections\n if (ruleType === \"manageRule\" && !this.isAuthCollection) {\n result.valid = false;\n result.errors.push(\"manageRule is only valid for auth collections\");\n return result;\n }\n\n // Extract and validate field references\n const fieldRefs = this.extractFieldReferences(expression);\n result.fieldReferences = fieldRefs;\n\n for (const fieldRef of fieldRefs) {\n this.validateFieldReference(fieldRef, result);\n }\n\n // Validate @request references\n this.validateRequestReferences(expression, result);\n\n // Validate syntax patterns\n this.validateSyntax(expression, result);\n\n return result;\n }\n\n /**\n * Extract field references from expression\n *\n * Matches field names that are not @request references.\n * Handles dot notation for relations: user.email, post.author.name\n *\n * @param expression - The rule expression\n * @returns Array of unique field references\n */\n private extractFieldReferences(expression: string): string[] {\n const refs: string[] = [];\n\n // First, remove string literals and @request references to avoid matching them\n let cleaned = expression.replace(/\"[^\"]*\"/g, '\"\"').replace(/'[^']*'/g, \"''\");\n cleaned = cleaned.replace(/@request\\.[a-zA-Z_][a-zA-Z0-9_.]*/g, \"\");\n\n // Match field names (not starting with @)\n // Handles dot notation for relations: user.email, post.author.name\n const fieldPattern = /(?:^|[^@\\w])([a-zA-Z_][a-zA-Z0-9_]*(?:\\.[a-zA-Z_][a-zA-Z0-9_]*)*)(?=[^a-zA-Z0-9_.]|$)/g;\n\n let match;\n while ((match = fieldPattern.exec(cleaned)) !== null) {\n const ref = match[1];\n // Exclude PocketBase keywords and operators\n if (!this.isKeyword(ref)) {\n refs.push(ref);\n }\n }\n\n return [...new Set(refs)]; // Remove duplicates\n }\n\n /**\n * Check if a word is a PocketBase keyword\n *\n * @param word - The word to check\n * @returns True if the word is a keyword\n */\n private isKeyword(word: string): boolean {\n const keywords = [\"true\", \"false\", \"null\", \"AND\", \"OR\", \"NOT\", \"LIKE\", \"IN\"];\n return keywords.includes(word.toUpperCase());\n }\n\n /**\n * Validate a field reference exists in schema\n *\n * Checks if the root field exists and validates relation chains.\n * For nested references, warns about potential issues since we can't\n * validate across collections without loading related schemas.\n *\n * @param fieldRef - The field reference to validate (e.g., \"user\" or \"user.email\")\n * @param result - The validation result to update\n */\n private validateFieldReference(fieldRef: string, result: RuleValidationResult): void {\n const parts = fieldRef.split(\".\");\n const rootField = parts[0];\n\n if (!this.fields.has(rootField)) {\n result.errors.push(`Field '${rootField}' does not exist in collection '${this.collectionName}'`);\n result.valid = false;\n return;\n }\n\n // For nested references, validate relation chain\n if (parts.length > 1) {\n const field = this.fields.get(rootField)!;\n if (field.type !== \"relation\") {\n result.errors.push(`Field '${rootField}' is not a relation field, cannot access nested property '${parts[1]}'`);\n result.valid = false;\n } else {\n // Note: We can't validate nested fields without loading related schemas\n // This would require cross-schema validation\n result.warnings.push(\n `Nested field reference '${fieldRef}' - ensure target collection has field '${parts.slice(1).join(\".\")}'`\n );\n }\n }\n }\n\n /**\n * Validate @request references\n *\n * Checks that @request references follow valid PocketBase patterns:\n * - @request.auth.* - authenticated user data\n * - @request.body.* - request body fields\n * - @request.query.* - query parameters\n * - @request.headers.* - request headers\n * - @request.method - HTTP method\n * - @request.context - execution context\n *\n * @param expression - The rule expression\n * @param result - The validation result to update\n */\n private validateRequestReferences(expression: string, result: RuleValidationResult): void {\n // Find all @request references\n const requestRefs = expression.match(/@request\\.[a-zA-Z_][a-zA-Z0-9_.]*/g) || [];\n\n for (const ref of requestRefs) {\n // Check if the reference starts with a valid pattern\n const isValid =\n ref.startsWith(\"@request.auth.\") ||\n ref === \"@request.method\" ||\n ref === \"@request.context\" ||\n ref.startsWith(\"@request.body.\") ||\n ref.startsWith(\"@request.query.\") ||\n ref.startsWith(\"@request.headers.\");\n\n if (!isValid) {\n result.errors.push(`Invalid @request reference: '${ref}'`);\n result.valid = false;\n }\n }\n }\n\n /**\n * Validate basic syntax patterns\n *\n * Checks for:\n * - Balanced parentheses\n * - Common operator mistakes (== instead of =)\n *\n * @param expression - The rule expression\n * @param result - The validation result to update\n */\n private validateSyntax(expression: string, result: RuleValidationResult): void {\n // Check for balanced parentheses\n let parenCount = 0;\n for (const char of expression) {\n if (char === \"(\") parenCount++;\n if (char === \")\") parenCount--;\n if (parenCount < 0) {\n result.errors.push(\"Unbalanced parentheses in expression\");\n result.valid = false;\n return;\n }\n }\n if (parenCount !== 0) {\n result.errors.push(\"Unbalanced parentheses in expression\");\n result.valid = false;\n }\n\n // Warn about common mistakes\n if (expression.includes(\"==\")) {\n result.warnings.push(\"Use '=' instead of '==' for equality comparison in PocketBase rules\");\n }\n }\n}\n","/**\n * Permission analyzer for extracting and validating permissions from Zod schemas\n *\n * This module provides utilities to:\n * - Extract permission metadata from Zod schema descriptions\n * - Resolve template configurations to concrete permission schemas\n * - Validate permission rules against collection fields\n * - Merge permissions with default values\n */\n\nimport { resolveTemplate } from \"../utils/permission-templates\";\nimport type { APIRuleType, PermissionSchema, PermissionTemplateConfig } from \"../utils/permissions\";\nimport type { RuleValidationResult } from \"./rule-validator\";\nimport { RuleValidator } from \"./rule-validator\";\nimport type { FieldDefinition } from \"./types\";\n\n/**\n * Extract and analyze permissions from schema\n *\n * The PermissionAnalyzer class provides methods to work with permission\n * definitions attached to Zod schemas, including extraction, resolution,\n * validation, and normalization.\n */\nexport class PermissionAnalyzer {\n /**\n * Extract permission metadata from Zod schema description\n *\n * Zod schemas can have permission metadata attached via the describe() method.\n * This method parses the description and extracts the permission configuration.\n *\n * @param schemaDescription - The Zod schema description string\n * @returns Permission schema if found, null otherwise\n *\n * @example\n * ```typescript\n * const analyzer = new PermissionAnalyzer();\n * const permissions = analyzer.extractPermissions(schema.description);\n * ```\n */\n extractPermissions(schemaDescription: string | undefined): PermissionSchema | null {\n if (!schemaDescription) {\n return null;\n }\n\n try {\n const metadata = JSON.parse(schemaDescription);\n if (metadata.permissions) {\n return metadata.permissions;\n }\n } catch {\n // Not JSON or no permissions - this is expected for schemas without permissions\n return null;\n }\n\n return null;\n }\n\n /**\n * Resolve template configuration to concrete rules\n *\n * Takes either a template configuration or a direct permission schema\n * and returns a fully resolved permission schema with all rules defined.\n *\n * If the input is already a permission schema (has rule properties),\n * it's returned as-is. Otherwise, the template is resolved using the\n * template resolver.\n *\n * @param config - Template configuration or direct permission schema\n * @returns Resolved permission schema\n *\n * @example\n * ```typescript\n * const analyzer = new PermissionAnalyzer();\n *\n * // Resolve from template\n * const permissions = analyzer.resolvePermissions({\n * template: 'owner-only',\n * ownerField: 'User'\n * });\n *\n * // Or pass direct schema\n * const permissions = analyzer.resolvePermissions({\n * listRule: '@request.auth.id != \"\"',\n * viewRule: '@request.auth.id != \"\"'\n * });\n * ```\n */\n resolvePermissions(config: PermissionTemplateConfig | PermissionSchema): PermissionSchema {\n // If it's already a permission schema (has rule properties), return as-is\n if (\n \"listRule\" in config ||\n \"viewRule\" in config ||\n \"createRule\" in config ||\n \"updateRule\" in config ||\n \"deleteRule\" in config ||\n \"manageRule\" in config\n ) {\n return config as PermissionSchema;\n }\n\n // Otherwise resolve template\n return resolveTemplate(config as PermissionTemplateConfig);\n }\n\n /**\n * Validate all rules in a permission schema\n *\n * Validates each rule in the permission schema against the collection's\n * field definitions. Returns a map of validation results keyed by rule type.\n *\n * Only validates rules that are defined (not undefined). Undefined rules\n * are treated as null (locked) by default.\n *\n * @param collectionName - Name of the collection being validated\n * @param permissions - Permission schema to validate\n * @param fields - Collection field definitions\n * @param isAuthCollection - Whether this is an auth collection (allows manageRule)\n * @returns Map of validation results by rule type\n *\n * @example\n * ```typescript\n * const analyzer = new PermissionAnalyzer();\n * const results = analyzer.validatePermissions(\n * 'posts',\n * { listRule: '@request.auth.id != \"\"', viewRule: 'author = @request.auth.id' },\n * fields,\n * false\n * );\n *\n * for (const [ruleType, result] of results) {\n * if (!result.valid) {\n * console.error(`${ruleType} validation failed:`, result.errors);\n * }\n * }\n * ```\n */\n validatePermissions(\n collectionName: string,\n permissions: PermissionSchema,\n fields: FieldDefinition[],\n isAuthCollection: boolean = false\n ): Map<APIRuleType, RuleValidationResult> {\n const validator = new RuleValidator(collectionName, fields, isAuthCollection);\n const results = new Map<APIRuleType, RuleValidationResult>();\n\n // Define all possible rule types\n const ruleTypes: APIRuleType[] = [\"listRule\", \"viewRule\", \"createRule\", \"updateRule\", \"deleteRule\"];\n\n // Add manageRule for auth collections\n if (isAuthCollection) {\n ruleTypes.push(\"manageRule\");\n }\n\n // Validate each defined rule\n for (const ruleType of ruleTypes) {\n const expression = permissions[ruleType];\n if (expression !== undefined) {\n results.set(ruleType, validator.validate(ruleType, expression));\n }\n }\n\n return results;\n }\n\n /**\n * Merge permissions with defaults\n *\n * Ensures all rule types have a defined value. Undefined rules are set\n * to null (locked to superusers only), which is the PocketBase default.\n *\n * This is useful when generating migrations to ensure all rules are\n * explicitly set in the collection configuration.\n *\n * @param permissions - Permission schema (may have undefined rules)\n * @returns Permission schema with all rules defined (null if not specified)\n *\n * @example\n * ```typescript\n * const analyzer = new PermissionAnalyzer();\n * const merged = analyzer.mergeWithDefaults({\n * listRule: '@request.auth.id != \"\"'\n * // other rules undefined\n * });\n *\n * // Result:\n * // {\n * // listRule: '@request.auth.id != \"\"',\n * // viewRule: null,\n * // createRule: null,\n * // updateRule: null,\n * // deleteRule: null,\n * // manageRule: null\n * // }\n * ```\n */\n mergeWithDefaults(permissions: PermissionSchema): PermissionSchema {\n return {\n listRule: permissions.listRule ?? null,\n viewRule: permissions.viewRule ?? null,\n createRule: permissions.createRule ?? null,\n updateRule: permissions.updateRule ?? null,\n deleteRule: permissions.deleteRule ?? null,\n manageRule: permissions.manageRule ?? null,\n };\n }\n}\n","/**\n * Collection name pluralization utilities\n */\n\n/**\n * Special case pluralization rules\n * Maps singular forms to their plural forms\n */\nconst SPECIAL_CASES: Record<string, string> = {\n // Common irregular plurals\n person: \"people\",\n Person: \"People\",\n child: \"children\",\n Child: \"Children\",\n man: \"men\",\n Man: \"Men\",\n woman: \"women\",\n Woman: \"Women\",\n tooth: \"teeth\",\n Tooth: \"Teeth\",\n foot: \"feet\",\n Foot: \"Feet\",\n mouse: \"mice\",\n Mouse: \"Mice\",\n goose: \"geese\",\n Goose: \"Geese\",\n\n // Words ending in -y\n category: \"categories\",\n Category: \"Categories\",\n company: \"companies\",\n Company: \"Companies\",\n city: \"cities\",\n City: \"Cities\",\n country: \"countries\",\n Country: \"Countries\",\n story: \"stories\",\n Story: \"Stories\",\n party: \"parties\",\n Party: \"Parties\",\n family: \"families\",\n Family: \"Families\",\n activity: \"activities\",\n Activity: \"Activities\",\n priority: \"priorities\",\n Priority: \"Priorities\",\n\n // Words ending in -f or -fe\n life: \"lives\",\n Life: \"Lives\",\n wife: \"wives\",\n Wife: \"Wives\",\n knife: \"knives\",\n Knife: \"Knives\",\n leaf: \"leaves\",\n Leaf: \"Leaves\",\n shelf: \"shelves\",\n Shelf: \"Shelves\",\n half: \"halves\",\n Half: \"Halves\",\n\n // Words ending in -is\n analysis: \"analyses\",\n Analysis: \"Analyses\",\n basis: \"bases\",\n Basis: \"Bases\",\n crisis: \"crises\",\n Crisis: \"Crises\",\n thesis: \"theses\",\n Thesis: \"Theses\",\n\n // Words ending in -us\n cactus: \"cacti\",\n Cactus: \"Cacti\",\n focus: \"foci\",\n Focus: \"Foci\",\n fungus: \"fungi\",\n Fungus: \"Fungi\",\n nucleus: \"nuclei\",\n Nucleus: \"Nuclei\",\n radius: \"radii\",\n Radius: \"Radii\",\n\n // Words ending in -on\n phenomenon: \"phenomena\",\n Phenomenon: \"Phenomena\",\n criterion: \"criteria\",\n Criterion: \"Criteria\",\n\n // Words ending in -um\n datum: \"data\",\n Datum: \"Data\",\n medium: \"media\",\n Medium: \"Media\",\n curriculum: \"curricula\",\n Curriculum: \"Curricula\",\n\n // Unchanged plurals\n sheep: \"sheep\",\n Sheep: \"Sheep\",\n deer: \"deer\",\n Deer: \"Deer\",\n fish: \"fish\",\n Fish: \"Fish\",\n species: \"species\",\n Species: \"Species\",\n series: \"series\",\n Series: \"Series\",\n};\n\n/**\n * Pluralizes a singular noun to its plural form\n * Handles special cases and common English pluralization rules\n *\n * @param singular - The singular form of the noun\n * @returns The plural form of the noun\n */\nexport function pluralize(singular: string): string {\n // Check special cases first (before checking if already plural)\n if (SPECIAL_CASES[singular]) {\n return SPECIAL_CASES[singular];\n }\n\n // Check if it's already plural (ends with 's' and is longer than 3 chars)\n if (singular.length > 3 && singular.endsWith(\"s\") && !singular.endsWith(\"ss\")) {\n // Could already be plural, return as-is\n return singular;\n }\n\n // Preserve case for the transformation\n const lowerSingular = singular.toLowerCase();\n\n let plural: string;\n\n // Rule 1: Words ending in -s, -ss, -sh, -ch, -x, -z -> add -es\n if (/(?:s|ss|sh|ch|x|z)$/.test(lowerSingular)) {\n plural = singular + \"es\";\n }\n // Rule 2: Words ending in consonant + y -> change y to ies\n else if (/[^aeiou]y$/.test(lowerSingular)) {\n plural = singular.slice(0, -1) + \"ies\";\n }\n // Rule 3: Words ending in consonant + o -> add -es\n else if (/[^aeiou]o$/.test(lowerSingular)) {\n plural = singular + \"es\";\n }\n // Rule 4: Words ending in -f or -fe -> change to -ves\n else if (/fe?$/.test(lowerSingular)) {\n if (lowerSingular.endsWith(\"fe\")) {\n plural = singular.slice(0, -2) + \"ves\";\n } else {\n plural = singular.slice(0, -1) + \"ves\";\n }\n }\n // Rule 5: Default -> add -s\n else {\n plural = singular + \"s\";\n }\n\n return plural;\n}\n\n/**\n * Converts a singular entity name to a collection name\n * This is an alias for pluralize for better semantic clarity\n *\n * @param entityName - The singular entity name (e.g., \"User\", \"Project\")\n * @returns The collection name (e.g., \"Users\", \"Projects\")\n */\nexport function toCollectionName(entityName: string): string {\n return pluralize(entityName);\n}\n\n/**\n * Attempts to singularize a plural noun (reverse of pluralize)\n * Note: This is a best-effort implementation and may not handle all edge cases\n *\n * @param plural - The plural form of the noun\n * @returns The singular form of the noun\n */\nexport function singularize(plural: string): string {\n // Check reverse special cases\n for (const [singular, pluralForm] of Object.entries(SPECIAL_CASES)) {\n if (pluralForm === plural) {\n return singular;\n }\n }\n\n const lower = plural.toLowerCase();\n\n // Rule 1: Words ending in -ies -> change to -y\n if (lower.endsWith(\"ies\") && plural.length > 3) {\n return plural.slice(0, -3) + \"y\";\n }\n\n // Rule 2: Words ending in -ves -> change to -f or -fe\n if (lower.endsWith(\"ves\")) {\n // Try -fe first (more common)\n return plural.slice(0, -3) + \"fe\";\n }\n\n // Rule 3: Words ending in -ses, -shes, -ches, -xes, -zes -> remove -es\n if (/(?:ses|shes|ches|xes|zes)$/.test(lower)) {\n return plural.slice(0, -2);\n }\n\n // Rule 4: Words ending in -s -> remove -s\n if (lower.endsWith(\"s\") && plural.length > 1) {\n return plural.slice(0, -1);\n }\n\n // Default: return as-is\n return plural;\n}\n","/**\n * Relation field detection utilities\n */\n\nimport { z } from \"zod\";\nimport { pluralize } from \"./pluralize\";\n\n/**\n * Detects if a field is a single relation based on naming convention\n * Single relation: field name matches a collection name (e.g., \"User\" -> \"Users\" collection)\n */\nexport function isSingleRelationField(fieldName: string, zodType: z.ZodTypeAny): boolean {\n // Unwrap optional/nullable/default\n let unwrappedType = zodType;\n if (zodType instanceof z.ZodOptional) {\n unwrappedType = zodType._def.innerType;\n }\n if (unwrappedType instanceof z.ZodNullable) {\n unwrappedType = unwrappedType._def.innerType;\n }\n if (unwrappedType instanceof z.ZodDefault) {\n unwrappedType = unwrappedType._def.innerType;\n }\n\n // Must be a string type\n if (!(unwrappedType instanceof z.ZodString)) {\n return false;\n }\n\n // Field name should start with uppercase (convention for entity references)\n // and not be a common string field name\n const startsWithUppercase = /^[A-Z]/.test(fieldName);\n\n // Exclude common string fields that start with uppercase\n const commonStringFields = [\"Title\", \"Name\", \"Description\", \"Content\", \"Summary\", \"Status\", \"Type\"];\n const isCommonField = commonStringFields.includes(fieldName);\n\n return startsWithUppercase && !isCommonField;\n}\n\n/**\n * Detects if a field is a multiple relation based on naming convention\n * Multiple relation: field name is an array of strings ending with entity name\n * (e.g., \"SubscriberUsers\" -> \"Users\" collection)\n */\nexport function isMultipleRelationField(fieldName: string, zodType: z.ZodTypeAny): boolean {\n // Unwrap optional/nullable/default\n let unwrappedType = zodType;\n if (zodType instanceof z.ZodOptional) {\n unwrappedType = zodType._def.innerType;\n }\n if (unwrappedType instanceof z.ZodNullable) {\n unwrappedType = unwrappedType._def.innerType;\n }\n if (unwrappedType instanceof z.ZodDefault) {\n unwrappedType = unwrappedType._def.innerType;\n }\n\n // Must be an array type\n if (!(unwrappedType instanceof z.ZodArray)) {\n return false;\n }\n\n // Element type must be string\n const elementType = unwrappedType._def.type;\n if (!(elementType instanceof z.ZodString)) {\n return false;\n }\n\n // Field name should contain an uppercase letter (entity reference pattern)\n const hasUppercase = /[A-Z]/.test(fieldName);\n\n return hasUppercase;\n}\n\n/**\n * Resolves the target collection name from a relation field name\n * Examples:\n * - \"User\" -> \"Users\"\n * - \"SubscriberUsers\" -> \"Users\"\n * - \"Author\" -> \"Authors\"\n * - \"Category\" -> \"Categories\"\n */\nexport function resolveTargetCollection(fieldName: string): string {\n // For single relations, the field name is typically the entity name\n // For multiple relations, extract the entity name from the end\n\n // Check if field name ends with a known plural entity name\n // Common patterns: \"SubscriberUsers\", \"RelatedPosts\", \"Tags\"\n\n // Try to find the entity name by looking for uppercase letters\n const matches = fieldName.match(/[A-Z][a-z]+/g);\n\n if (!matches || matches.length === 0) {\n // Fallback: pluralize the entire field name\n return pluralize(fieldName);\n }\n\n // Take the last matched entity name (e.g., \"Users\" from \"SubscriberUsers\")\n const entityName = matches[matches.length - 1];\n\n // Pluralize the entity name to get collection name\n return pluralize(entityName);\n}\n\n/**\n * Detects if a field is any type of relation (single or multiple)\n */\nexport function isRelationField(fieldName: string, zodType: z.ZodTypeAny): boolean {\n return isSingleRelationField(fieldName, zodType) || isMultipleRelationField(fieldName, zodType);\n}\n\n/**\n * Gets the maximum number of relations allowed for a relation field\n * Returns 1 for single relations, or the max constraint for multiple relations\n */\nexport function getMaxSelect(fieldName: string, zodType: z.ZodTypeAny): number {\n if (isSingleRelationField(fieldName, zodType)) {\n return 1;\n }\n\n if (isMultipleRelationField(fieldName, zodType)) {\n // Unwrap to get to the array type\n let unwrappedType = zodType;\n if (zodType instanceof z.ZodOptional) {\n unwrappedType = zodType._def.innerType;\n }\n if (unwrappedType instanceof z.ZodNullable) {\n unwrappedType = unwrappedType._def.innerType;\n }\n if (unwrappedType instanceof z.ZodDefault) {\n unwrappedType = unwrappedType._def.innerType;\n }\n\n if (unwrappedType instanceof z.ZodArray) {\n // Access the checks array from the array definition\n const arrayDef = unwrappedType._def;\n if (arrayDef.maxLength) {\n return arrayDef.maxLength.value;\n }\n // Default to 999 for multiple relations without explicit max\n return 999;\n }\n }\n\n return 1;\n}\n\n/**\n * Gets the minimum number of relations required for a relation field\n * Returns 0 as default for all relation fields (single or multiple)\n * PocketBase always expects minSelect to be defined for relation fields\n */\nexport function getMinSelect(fieldName: string, zodType: z.ZodTypeAny): number {\n // For single relations, always return 0\n if (isSingleRelationField(fieldName, zodType)) {\n return 0;\n }\n\n // For multiple relations, check for explicit min constraint\n if (isMultipleRelationField(fieldName, zodType)) {\n // Unwrap to get to the array type\n let unwrappedType = zodType;\n if (zodType instanceof z.ZodOptional) {\n unwrappedType = zodType._def.innerType;\n }\n if (unwrappedType instanceof z.ZodNullable) {\n unwrappedType = unwrappedType._def.innerType;\n }\n if (unwrappedType instanceof z.ZodDefault) {\n unwrappedType = unwrappedType._def.innerType;\n }\n\n if (unwrappedType instanceof z.ZodArray) {\n // Access the minLength from the array definition\n const arrayDef = unwrappedType._def;\n if (arrayDef.minLength) {\n return arrayDef.minLength.value;\n }\n }\n }\n\n // Default to 0 for all relation fields\n return 0;\n}\n","/**\n * Zod to PocketBase type mapping utilities\n *\n * This module provides comprehensive mapping between Zod schema types\n * and PocketBase field types, including support for all PocketBase field types:\n * - text, email, url, editor\n * - number, bool\n * - date, autodate\n * - select (single/multiple)\n * - relation (single/multiple)\n * - file (single/multiple)\n * - json\n * - geoPoint\n */\n\nimport { z } from \"zod\";\nimport type { PocketBaseFieldType } from \"../types\";\n\n// Re-export extractFieldMetadata from fields.ts for backward compatibility\nexport { extractFieldMetadata, FIELD_METADATA_KEY } from \"../../schema/fields\";\nexport type { FieldMetadata } from \"../../schema/fields\";\n\n/**\n * All supported PocketBase field types\n */\nexport const POCKETBASE_FIELD_TYPES: readonly PocketBaseFieldType[] = [\n \"text\",\n \"email\",\n \"url\",\n \"number\",\n \"bool\",\n \"date\",\n \"select\",\n \"relation\",\n \"file\",\n \"json\",\n \"editor\",\n \"geoPoint\",\n \"autodate\",\n] as const;\n\n/**\n * Field type metadata for documentation and validation\n */\nexport interface FieldTypeInfo {\n type: PocketBaseFieldType;\n description: string;\n zodTypes: string[];\n supportsMultiple: boolean;\n}\n\n/**\n * Metadata about each PocketBase field type\n */\nexport const FIELD_TYPE_INFO: Record<PocketBaseFieldType, FieldTypeInfo> = {\n text: {\n type: \"text\",\n description: \"Plain text field\",\n zodTypes: [\"ZodString\"],\n supportsMultiple: false,\n },\n email: {\n type: \"email\",\n description: \"Email address field with validation\",\n zodTypes: [\"ZodString with email()\"],\n supportsMultiple: false,\n },\n url: {\n type: \"url\",\n description: \"URL field with validation\",\n zodTypes: [\"ZodString with url()\"],\n supportsMultiple: false,\n },\n editor: {\n type: \"editor\",\n description: \"Rich text editor field\",\n zodTypes: [\"ZodString\"],\n supportsMultiple: false,\n },\n number: {\n type: \"number\",\n description: \"Numeric field (integer or float)\",\n zodTypes: [\"ZodNumber\"],\n supportsMultiple: false,\n },\n bool: {\n type: \"bool\",\n description: \"Boolean field\",\n zodTypes: [\"ZodBoolean\"],\n supportsMultiple: false,\n },\n date: {\n type: \"date\",\n description: \"Date/datetime field\",\n zodTypes: [\"ZodDate\", \"ZodString with datetime format\"],\n supportsMultiple: false,\n },\n autodate: {\n type: \"autodate\",\n description: \"Auto-managed date field (created/updated)\",\n zodTypes: [\"ZodString\"],\n supportsMultiple: false,\n },\n select: {\n type: \"select\",\n description: \"Single or multiple select from predefined values\",\n zodTypes: [\"ZodEnum\", \"ZodArray<ZodEnum>\"],\n supportsMultiple: true,\n },\n relation: {\n type: \"relation\",\n description: \"Reference to another collection\",\n zodTypes: [\"ZodString\", \"ZodArray<ZodString>\"],\n supportsMultiple: true,\n },\n file: {\n type: \"file\",\n description: \"File upload field\",\n zodTypes: [\"File\", \"ZodArray<File>\"],\n supportsMultiple: true,\n },\n json: {\n type: \"json\",\n description: \"JSON data field\",\n zodTypes: [\"ZodRecord\", \"ZodObject\", \"ZodArray\"],\n supportsMultiple: false,\n },\n geoPoint: {\n type: \"geoPoint\",\n description: \"Geographic coordinates (lon, lat)\",\n zodTypes: [\"ZodObject with lon/lat\"],\n supportsMultiple: false,\n },\n};\n\n/**\n * Maps Zod string types to PocketBase field types\n */\nexport function mapZodStringType(zodType: z.ZodString): PocketBaseFieldType {\n const checks = (zodType as any)._def.checks || [];\n\n // Check for email validation\n const hasEmail = checks.some((check: any) => check.kind === \"email\");\n if (hasEmail) {\n return \"email\";\n }\n\n // Check for URL validation\n const hasUrl = checks.some((check: any) => check.kind === \"url\");\n if (hasUrl) {\n return \"url\";\n }\n\n // Check for datetime validation (could be date field)\n const hasDatetime = checks.some((check: any) => check.kind === \"datetime\");\n if (hasDatetime) {\n return \"date\";\n }\n\n // Default to text\n return \"text\";\n}\n\n/**\n * Maps Zod number types to PocketBase number type\n */\nexport function mapZodNumberType(_zodType: z.ZodNumber): PocketBaseFieldType {\n return \"number\";\n}\n\n/**\n * Maps Zod boolean types to PocketBase bool type\n */\nexport function mapZodBooleanType(_zodType: z.ZodBoolean): PocketBaseFieldType {\n return \"bool\";\n}\n\n/**\n * Maps Zod enum types to PocketBase select type\n */\nexport function mapZodEnumType(_zodType: z.ZodEnum<any>): PocketBaseFieldType {\n return \"select\";\n}\n\n/**\n * Maps Zod array types to appropriate PocketBase types\n * Arrays of strings could be relations or file fields depending on context\n */\nexport function mapZodArrayType(zodType: z.ZodArray<any>, _fieldName: string): PocketBaseFieldType {\n const elementType = zodType._def.type;\n\n // Check if it's an array of File instances (file upload)\n if (elementType instanceof z.ZodType) {\n const typeName = elementType._def.typeName;\n if (typeName === \"ZodType\" && (elementType as any)._def?.innerType?.name === \"File\") {\n return \"file\";\n }\n }\n\n // Check for instanceof File\n if (elementType._def?.typeName === \"ZodType\") {\n const checks = (elementType as any)._def?.checks || [];\n const isFileInstance = checks.some(\n (check: any) => check.kind === \"instanceof\" || (elementType as any)._def?.innerType?.name === \"File\"\n );\n if (isFileInstance) {\n return \"file\";\n }\n }\n\n // Array of strings - could be relation (will be determined by relation detector)\n if (elementType instanceof z.ZodString) {\n return \"relation\";\n }\n\n // Default to JSON for other array types\n return \"json\";\n}\n\n/**\n * Maps Zod date types to PocketBase date type\n */\nexport function mapZodDateType(_zodType: z.ZodDate): PocketBaseFieldType {\n return \"date\";\n}\n\n/**\n * Maps Zod record/object types to PocketBase JSON type\n */\nexport function mapZodRecordType(_zodType: z.ZodRecord | z.ZodObject<any>): PocketBaseFieldType {\n return \"json\";\n}\n\n/**\n * Main type mapping function that determines PocketBase field type from Zod type\n */\nexport function mapZodTypeToPocketBase(zodType: z.ZodTypeAny, fieldName: string): PocketBaseFieldType {\n // Handle optional and nullable types by unwrapping\n let unwrappedType = zodType;\n\n if (zodType instanceof z.ZodOptional) {\n unwrappedType = zodType._def.innerType;\n }\n\n if (unwrappedType instanceof z.ZodNullable) {\n unwrappedType = unwrappedType._def.innerType;\n }\n\n if (unwrappedType instanceof z.ZodDefault) {\n unwrappedType = unwrappedType._def.innerType;\n }\n\n // Check for ZodEffects (which is what z.instanceof() creates)\n if ((unwrappedType as any)._def?.typeName === \"ZodEffects\") {\n const effect = (unwrappedType as any)._def?.effect;\n\n // z.instanceof(File) creates a refinement effect\n // We need to check if this is a File instance check\n // The field name 'avatar', 'image', 'file', 'attachment' etc. are hints\n if (effect?.type === \"refinement\") {\n // Common file field names\n const fileFieldNames = [\"avatar\", \"image\", \"file\", \"attachment\", \"photo\", \"picture\", \"document\", \"upload\"];\n if (fileFieldNames.some((name) => fieldName.toLowerCase().includes(name))) {\n return \"file\";\n }\n }\n }\n\n // Check for instanceof File (z.instanceof(File)) - legacy check\n if ((unwrappedType as any)._def?.typeName === \"ZodType\") {\n const checks = (unwrappedType as any)._def?.checks || [];\n const innerType = (unwrappedType as any)._def?.innerType;\n\n // Check if it's instanceof File\n if (innerType?.name === \"File\" || checks.some((check: any) => check.kind === \"instanceof\")) {\n return \"file\";\n }\n }\n\n // Map based on Zod type\n if (unwrappedType instanceof z.ZodString) {\n return mapZodStringType(unwrappedType);\n }\n\n if (unwrappedType instanceof z.ZodNumber) {\n return mapZodNumberType(unwrappedType);\n }\n\n if (unwrappedType instanceof z.ZodBoolean) {\n return mapZodBooleanType(unwrappedType);\n }\n\n if (unwrappedType instanceof z.ZodEnum) {\n return mapZodEnumType(unwrappedType);\n }\n\n if (unwrappedType instanceof z.ZodArray) {\n return mapZodArrayType(unwrappedType, fieldName);\n }\n\n if (unwrappedType instanceof z.ZodDate) {\n return mapZodDateType(unwrappedType);\n }\n\n if (unwrappedType instanceof z.ZodRecord || unwrappedType instanceof z.ZodObject) {\n return mapZodRecordType(unwrappedType);\n }\n\n // Default to text for unknown types\n return \"text\";\n}\n\n/**\n * Extracts field options from Zod type (min, max, pattern, etc.)\n */\nexport function extractFieldOptions(zodType: z.ZodTypeAny): Record<string, any> {\n const options: Record<string, any> = {};\n\n // Unwrap optional/nullable/default\n let unwrappedType = zodType;\n if (zodType instanceof z.ZodOptional) {\n unwrappedType = zodType._def.innerType;\n }\n if (unwrappedType instanceof z.ZodNullable) {\n unwrappedType = unwrappedType._def.innerType;\n }\n if (unwrappedType instanceof z.ZodDefault) {\n unwrappedType = unwrappedType._def.innerType;\n }\n\n const checks = (unwrappedType as any)._def?.checks || [];\n\n // Extract string constraints\n if (unwrappedType instanceof z.ZodString) {\n for (const check of checks) {\n if (check.kind === \"min\") {\n options.min = check.value;\n }\n if (check.kind === \"max\") {\n options.max = check.value;\n }\n if (check.kind === \"regex\") {\n options.pattern = check.regex.source;\n }\n }\n }\n\n // Extract number constraints\n if (unwrappedType instanceof z.ZodNumber) {\n for (const check of checks) {\n if (check.kind === \"min\") {\n options.min = check.value;\n }\n if (check.kind === \"max\") {\n options.max = check.value;\n }\n }\n }\n\n // Extract enum values\n if (unwrappedType instanceof z.ZodEnum) {\n options.values = unwrappedType._def.values;\n }\n\n // Extract array constraints\n if (unwrappedType instanceof z.ZodArray) {\n const arrayChecks = (unwrappedType as any)._def?.checks || [];\n for (const check of arrayChecks) {\n if (check.kind === \"min\") {\n options.minSelect = check.value;\n }\n if (check.kind === \"max\") {\n options.maxSelect = check.value;\n }\n }\n }\n\n return options;\n}\n\n/**\n * Determines if a Zod field is required (not optional)\n */\nexport function isFieldRequired(zodType: z.ZodTypeAny): boolean {\n // Check if it's optional\n if (zodType instanceof z.ZodOptional) {\n return false;\n }\n\n // Check if it has a default value (makes it optional)\n if (zodType instanceof z.ZodDefault) {\n return false;\n }\n\n // Check for nullable (in PocketBase context, nullable means optional)\n if (zodType instanceof z.ZodNullable) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Unwraps a Zod type to get the inner type\n * Handles optional, nullable, and default wrappers\n */\nexport function unwrapZodType(zodType: z.ZodTypeAny): z.ZodTypeAny {\n let unwrapped = zodType;\n\n if (unwrapped instanceof z.ZodOptional) {\n unwrapped = unwrapped._def.innerType;\n }\n\n if (unwrapped instanceof z.ZodNullable) {\n unwrapped = unwrapped._def.innerType;\n }\n\n if (unwrapped instanceof z.ZodDefault) {\n unwrapped = unwrapped._def.innerType;\n }\n\n return unwrapped;\n}\n\n/**\n * Gets the default value from a Zod type if it has one\n */\nexport function getDefaultValue(zodType: z.ZodTypeAny): any {\n if (zodType instanceof z.ZodDefault) {\n return zodType._def.defaultValue();\n }\n return undefined;\n}\n\n/**\n * Checks if a Zod type is an array type\n */\nexport function isArrayType(zodType: z.ZodTypeAny): boolean {\n const unwrapped = unwrapZodType(zodType);\n return unwrapped instanceof z.ZodArray;\n}\n\n/**\n * Gets the element type of an array Zod type\n */\nexport function getArrayElementType(zodType: z.ZodTypeAny): z.ZodTypeAny | null {\n const unwrapped = unwrapZodType(zodType);\n if (unwrapped instanceof z.ZodArray) {\n return unwrapped._def.type;\n }\n return null;\n}\n\n/**\n * Checks if a Zod type represents a geo point (object with lon/lat)\n */\nexport function isGeoPointType(zodType: z.ZodTypeAny): boolean {\n const unwrapped = unwrapZodType(zodType);\n if (!(unwrapped instanceof z.ZodObject)) {\n return false;\n }\n\n const shape = unwrapped._def.shape();\n const hasLon = \"lon\" in shape && shape.lon instanceof z.ZodNumber;\n const hasLat = \"lat\" in shape && shape.lat instanceof z.ZodNumber;\n\n return hasLon && hasLat;\n}\n\n/**\n * Complete field options extracted from a Zod type\n */\nexport interface ExtractedFieldOptions {\n min?: number;\n max?: number;\n pattern?: string;\n values?: string[];\n minSelect?: number;\n maxSelect?: number;\n mimeTypes?: string[];\n maxSize?: number;\n thumbs?: string[];\n}\n\n/**\n * Extracts comprehensive field options from Zod type\n * Includes all constraints that can be mapped to PocketBase field options\n */\nexport function extractComprehensiveFieldOptions(zodType: z.ZodTypeAny): ExtractedFieldOptions {\n const options: ExtractedFieldOptions = {};\n const unwrapped = unwrapZodType(zodType);\n const checks = (unwrapped as any)._def?.checks || [];\n\n // Extract string constraints\n if (unwrapped instanceof z.ZodString) {\n for (const check of checks) {\n if (check.kind === \"min\") {\n options.min = check.value;\n }\n if (check.kind === \"max\") {\n options.max = check.value;\n }\n if (check.kind === \"regex\") {\n options.pattern = check.regex.source;\n }\n }\n }\n\n // Extract number constraints\n if (unwrapped instanceof z.ZodNumber) {\n for (const check of checks) {\n if (check.kind === \"min\") {\n options.min = check.value;\n }\n if (check.kind === \"max\") {\n options.max = check.value;\n }\n }\n }\n\n // Extract enum values\n if (unwrapped instanceof z.ZodEnum) {\n options.values = unwrapped._def.values;\n }\n\n // Extract array constraints\n if (unwrapped instanceof z.ZodArray) {\n const arrayDef = unwrapped._def;\n if (arrayDef.minLength) {\n options.minSelect = arrayDef.minLength.value;\n }\n if (arrayDef.maxLength) {\n options.maxSelect = arrayDef.maxLength.value;\n }\n\n // Check for enum element type\n const elementType = arrayDef.type;\n if (elementType instanceof z.ZodEnum) {\n options.values = elementType._def.values;\n }\n }\n\n return options;\n}\n\n/**\n * Determines if a field should be treated as an editor field\n * based on field name conventions\n */\nexport function isEditorField(fieldName: string): boolean {\n const editorFieldNames = [\n \"content\",\n \"body\",\n \"description\",\n \"bio\",\n \"about\",\n \"summary\",\n \"notes\",\n \"details\",\n \"html\",\n \"richtext\",\n \"editor\",\n ];\n return editorFieldNames.some((name) => fieldName.toLowerCase().includes(name));\n}\n\n/**\n * Determines if a field should be treated as a file field\n * based on field name conventions\n */\nexport function isFileFieldByName(fieldName: string): boolean {\n const fileFieldNames = [\n \"avatar\",\n \"image\",\n \"file\",\n \"attachment\",\n \"photo\",\n \"picture\",\n \"document\",\n \"upload\",\n \"thumbnail\",\n \"cover\",\n \"banner\",\n \"logo\",\n \"icon\",\n \"media\",\n ];\n return fileFieldNames.some((name) => fieldName.toLowerCase().includes(name));\n}\n\n/**\n * Gets the PocketBase field type with additional context\n */\nexport interface FieldTypeResult {\n type: PocketBaseFieldType;\n isMultiple: boolean;\n options: ExtractedFieldOptions;\n}\n\n/**\n * Comprehensive type mapping that returns full field information\n */\nexport function getFieldTypeInfo(zodType: z.ZodTypeAny, fieldName: string): FieldTypeResult {\n const type = mapZodTypeToPocketBase(zodType, fieldName);\n const isMultiple = isArrayType(zodType);\n const options = extractComprehensiveFieldOptions(zodType);\n\n return {\n type,\n isMultiple,\n options,\n };\n}\n","/**\n * Schema Analyzer - Parses Zod schemas and extracts field definitions\n *\n * This module provides a standalone, configurable schema analyzer that can be used\n * by consumer projects to parse Zod schemas and convert them to PocketBase collection schemas.\n */\n\nimport * as fs from \"fs\";\nimport * as path from \"path\";\nimport { z } from \"zod\";\nimport { extractRelationMetadata } from \"../schema/base\";\nimport { extractFieldMetadata } from \"../schema/fields\";\nimport type { PermissionSchema } from \"../utils/permissions\";\nimport { FileSystemError, SchemaParsingError } from \"./errors\";\nimport { PermissionAnalyzer } from \"./permission-analyzer\";\nimport type { CollectionSchema, FieldDefinition, SchemaDefinition } from \"./types\";\nimport { toCollectionName } from \"./utils/pluralize\";\nimport { getMaxSelect, getMinSelect, isRelationField, resolveTargetCollection } from \"./utils/relation-detector\";\nimport { extractFieldOptions, isFieldRequired, mapZodTypeToPocketBase } from \"./utils/type-mapper\";\n\n// Register tsx loader for TypeScript file support\n// This allows dynamic imports of .ts files to work\nlet tsxLoaderRegistered = false;\nasync function ensureTsxLoader(): Promise<void> {\n if (tsxLoaderRegistered) return;\n\n try {\n // Import tsx/esm to register the TypeScript loader hooks\n // This enables dynamic imports of .ts files in Node.js ESM\n await import(\"tsx/esm\");\n tsxLoaderRegistered = true;\n } catch {\n // tsx is not available - will handle in importSchemaModule\n tsxLoaderRegistered = false;\n }\n}\n\n/**\n * Configuration options for schema discovery and parsing\n */\nexport interface SchemaAnalyzerConfig {\n /**\n * Directory containing schema files (source or compiled)\n * Can be absolute or relative to workspaceRoot\n */\n schemaDir: string;\n\n /**\n * Workspace root directory for resolving relative paths\n * Defaults to process.cwd()\n */\n workspaceRoot?: string;\n\n /**\n * File patterns to exclude from schema discovery\n * Defaults to ['base.ts', 'index.ts', 'permissions.ts', 'permission-templates.ts']\n */\n excludePatterns?: string[];\n\n /**\n * File extensions to include in schema discovery\n * Defaults to ['.ts', '.js']\n */\n includeExtensions?: string[];\n\n /**\n * Schema export name patterns to look for\n * Defaults to ['Schema', 'InputSchema']\n */\n schemaPatterns?: string[];\n\n /**\n * Whether to use compiled JavaScript files instead of TypeScript source\n * When true, looks for .js files; when false, looks for .ts files\n * Defaults to true (use compiled files for dynamic import)\n */\n useCompiledFiles?: boolean;\n\n /**\n * Custom path transformation function for converting source paths to import paths\n * Useful for monorepo setups where source and dist directories differ\n * If not provided, uses the schemaDir directly\n */\n pathTransformer?: (sourcePath: string) => string;\n}\n\n/**\n * Default configuration values\n */\nconst DEFAULT_CONFIG: Required<Omit<SchemaAnalyzerConfig, \"schemaDir\" | \"pathTransformer\">> = {\n workspaceRoot: process.cwd(),\n excludePatterns: [\n \"base.ts\",\n \"index.ts\",\n \"permissions.ts\",\n \"permission-templates.ts\",\n \"base.js\",\n \"index.js\",\n \"permissions.js\",\n \"permission-templates.js\",\n ],\n includeExtensions: [\".ts\", \".js\"],\n schemaPatterns: [\"Schema\", \"InputSchema\", \"Collection\"],\n useCompiledFiles: true,\n};\n\n/**\n * Merges user config with defaults\n */\nfunction mergeConfig(\n config: SchemaAnalyzerConfig\n): Required<Omit<SchemaAnalyzerConfig, \"pathTransformer\">> & { pathTransformer?: (sourcePath: string) => string } {\n return {\n ...DEFAULT_CONFIG,\n ...config,\n excludePatterns: config.excludePatterns || DEFAULT_CONFIG.excludePatterns,\n includeExtensions: config.includeExtensions || DEFAULT_CONFIG.includeExtensions,\n schemaPatterns: config.schemaPatterns || DEFAULT_CONFIG.schemaPatterns,\n };\n}\n\n/**\n * Resolves the schema directory path\n */\nfunction resolveSchemaDir(config: SchemaAnalyzerConfig): string {\n const workspaceRoot = config.workspaceRoot || process.cwd();\n\n if (path.isAbsolute(config.schemaDir)) {\n return config.schemaDir;\n }\n\n return path.join(workspaceRoot, config.schemaDir);\n}\n\n/**\n * Discovers schema files in the specified directory\n * Filters based on configuration patterns\n *\n * @param config - Schema analyzer configuration\n * @returns Array of schema file paths (without extension)\n */\nexport function discoverSchemaFiles(config: SchemaAnalyzerConfig | string): string[] {\n // Support legacy string-only parameter\n const normalizedConfig: SchemaAnalyzerConfig = typeof config === \"string\" ? { schemaDir: config } : config;\n\n const mergedConfig = mergeConfig(normalizedConfig);\n const schemaDir = resolveSchemaDir(normalizedConfig);\n\n try {\n if (!fs.existsSync(schemaDir)) {\n throw new FileSystemError(`Schema directory not found: ${schemaDir}`, schemaDir, \"access\", \"ENOENT\");\n }\n\n const files = fs.readdirSync(schemaDir);\n\n // Filter files based on configuration\n const schemaFiles = files.filter((file) => {\n // Check extension\n const hasValidExtension = mergedConfig.includeExtensions.some((ext) => file.endsWith(ext));\n if (!hasValidExtension) return false;\n\n // Check exclusion patterns\n const isExcluded = mergedConfig.excludePatterns.some((pattern) => {\n // Support both exact match and glob-like patterns\n if (pattern.includes(\"*\")) {\n const regex = new RegExp(\"^\" + pattern.replace(/\\*/g, \".*\") + \"$\");\n return regex.test(file);\n }\n return file === pattern;\n });\n if (isExcluded) return false;\n\n return true;\n });\n\n // Return full paths without extension (for dynamic import)\n return schemaFiles.map((file) => {\n const ext = mergedConfig.includeExtensions.find((ext) => file.endsWith(ext)) || \".ts\";\n return path.join(schemaDir, file.replace(new RegExp(`\\\\${ext}$`), \"\"));\n });\n } catch (error) {\n if (error instanceof FileSystemError) {\n throw error;\n }\n\n const fsError = error as NodeJS.ErrnoException;\n if (fsError.code === \"EACCES\" || fsError.code === \"EPERM\") {\n throw new FileSystemError(\n `Permission denied reading schema directory: ${schemaDir}`,\n schemaDir,\n \"read\",\n fsError.code,\n error as Error\n );\n }\n\n throw new FileSystemError(\n `Failed to read schema directory: ${schemaDir}`,\n schemaDir,\n \"read\",\n fsError.code,\n error as Error\n );\n }\n}\n\n/**\n * Dynamically imports a schema module\n * Supports both JavaScript and TypeScript files using tsx\n *\n * @param filePath - Path to the schema file (without extension)\n * @param config - Optional configuration for path transformation\n * @returns The imported module\n */\nexport async function importSchemaModule(filePath: string, config?: SchemaAnalyzerConfig): Promise<any> {\n try {\n let importPath = filePath;\n\n // Apply path transformation if provided\n if (config?.pathTransformer) {\n importPath = config.pathTransformer(filePath);\n }\n\n // Determine the file extension to use\n // Try .js first (for compiled files), then .ts (for source files)\n let resolvedPath: string | null = null;\n const jsPath = `${importPath}.js`;\n const tsPath = `${importPath}.ts`;\n\n if (fs.existsSync(jsPath)) {\n resolvedPath = jsPath;\n } else if (fs.existsSync(tsPath)) {\n resolvedPath = tsPath;\n } else {\n // Default to .js extension for ESM import\n resolvedPath = jsPath;\n }\n\n // If it's a TypeScript file, ensure tsx loader is registered\n if (resolvedPath.endsWith(\".ts\")) {\n await ensureTsxLoader();\n\n // Check if tsx was successfully registered\n if (!tsxLoaderRegistered) {\n throw new SchemaParsingError(\n `Failed to import TypeScript schema file. The 'tsx' package is required to load TypeScript files.\\n` +\n `Please install tsx: npm install tsx (or yarn add tsx, or pnpm add tsx)\\n` +\n `Alternatively, compile your schema files to JavaScript first.`,\n filePath\n );\n }\n }\n\n // Convert to file URL for proper ESM import\n const fileUrl = new URL(`file://${path.resolve(resolvedPath)}`);\n\n // Use dynamic import to load the module\n // tsx/esm will handle TypeScript files automatically if registered\n const module = await import(fileUrl.href);\n return module;\n } catch (error) {\n // Check if we're trying to import a TypeScript file\n const tsPath = `${filePath}.ts`;\n const isTypeScriptFile = fs.existsSync(tsPath);\n\n if (isTypeScriptFile && error instanceof SchemaParsingError) {\n // Re-throw SchemaParsingError as-is (already has helpful message)\n throw error;\n }\n\n if (isTypeScriptFile) {\n throw new SchemaParsingError(\n `Failed to import TypeScript schema file. The 'tsx' package is required to load TypeScript files.\\n` +\n `Please install tsx: npm install tsx (or yarn add tsx, or pnpm add tsx)\\n` +\n `Alternatively, compile your schema files to JavaScript first.`,\n filePath,\n error as Error\n );\n }\n\n throw new SchemaParsingError(\n `Failed to import schema module. Make sure the schema files exist and are valid.`,\n filePath,\n error as Error\n );\n }\n}\n\n/**\n * Gets the collection name from a schema file path\n * Converts the filename (without extension) to a pluralized collection name\n *\n * @param filePath - Path to the schema file (with or without extension)\n * @returns The collection name\n */\nexport function getCollectionNameFromFile(filePath: string): string {\n // Remove both .ts and .js extensions if present\n const filename = path.basename(filePath).replace(/\\.(ts|js)$/, \"\");\n return toCollectionName(filename);\n}\n\n/**\n * Extracts the collection name from a Zod schema's metadata\n * Checks if the schema was created with defineCollection() which stores\n * the collection name in the schema description\n *\n * @param zodSchema - The Zod schema to extract collection name from\n * @returns The collection name if found in metadata, null otherwise\n */\nexport function extractCollectionNameFromSchema(zodSchema: z.ZodTypeAny): string | null {\n if (!zodSchema.description) {\n return null;\n }\n\n try {\n const metadata = JSON.parse(zodSchema.description);\n if (metadata.collectionName && typeof metadata.collectionName === \"string\") {\n return metadata.collectionName;\n }\n } catch {\n // Not JSON or no collectionName - this is expected for schemas without defineCollection\n }\n\n return null;\n}\n\n/**\n * Extracts the collection type from a Zod schema's metadata\n * Checks if the schema was created with defineCollection() which stores\n * the collection type in the schema description\n *\n * @param zodSchema - The Zod schema to extract collection type from\n * @returns The collection type (\"base\" | \"auth\") if found in metadata, null otherwise\n */\nexport function extractCollectionTypeFromSchema(zodSchema: z.ZodTypeAny): \"base\" | \"auth\" | null {\n if (!zodSchema.description) {\n return null;\n }\n\n try {\n const metadata = JSON.parse(zodSchema.description);\n if (metadata.type === \"base\" || metadata.type === \"auth\") {\n return metadata.type;\n }\n } catch {\n // Not JSON or no type - this is expected for schemas without explicit type\n }\n\n return null;\n}\n\n/**\n * Extracts Zod schema definitions from a module\n *\n * Detection priority (highest to lowest):\n * 1. Default export - recommended pattern for clarity and explicitness\n * 2. Named exports ending with \"Collection\" - contains metadata (indexes, permissions)\n * 3. Named exports ending with \"Schema\" - basic schema definitions\n * 4. Named exports ending with \"InputSchema\" - form input schemas\n *\n * @param module - The imported schema module\n * @param patterns - Schema name patterns to look for (default: ['Schema', 'InputSchema', 'Collection'])\n * @returns Object containing found schemas\n *\n * @example\n * // Recommended: Use default export\n * const UserCollection = defineCollection({ ... });\n * export default UserCollection;\n *\n * @example\n * // Also supported: Named export with pattern\n * export const UserCollection = defineCollection({ ... });\n */\nexport function extractSchemaDefinitions(\n module: any,\n patterns: string[] = [\"Schema\", \"InputSchema\", \"Collection\"]\n): { inputSchema?: z.ZodObject<any>; schema?: z.ZodObject<any> } {\n const result: { inputSchema?: z.ZodObject<any>; schema?: z.ZodObject<any> } = {};\n\n // Priority 1: Check for default export (highest priority, most explicit)\n // This allows each file to have one clear schema definition\n if (module.default instanceof z.ZodObject) {\n // Default export is always the primary schema\n result.schema = module.default as z.ZodObject<any>;\n // If we have a default export, we can return early as it takes precedence\n // But we still check for InputSchema for backward compatibility\n }\n\n // Priority 2: Look for named exports matching patterns (for backward compatibility)\n for (const [key, value] of Object.entries(module)) {\n // Skip default export as we already handled it\n if (key === \"default\") continue;\n\n // Check if it's a Zod schema\n if (value instanceof z.ZodObject) {\n // Check for InputSchema pattern (used for form validation)\n if (patterns.includes(\"InputSchema\") && key.endsWith(\"InputSchema\")) {\n result.inputSchema = value as z.ZodObject<any>;\n } else if (!result.schema) {\n // Only set schema if we haven't found one via default export\n if (patterns.includes(\"Collection\") && key.endsWith(\"Collection\")) {\n // Prefer Collection over Schema as it has metadata (indexes, permissions)\n result.schema = value as z.ZodObject<any>;\n } else if (patterns.includes(\"Schema\") && key.endsWith(\"Schema\") && !key.endsWith(\"InputSchema\")) {\n result.schema = value as z.ZodObject<any>;\n }\n }\n }\n }\n\n return result;\n}\n\n/**\n * Identifies whether to use InputSchema or Schema pattern\n * Prefers Schema over InputSchema as it includes base fields\n *\n * @param schemas - Object containing inputSchema and/or schema\n * @returns The schema to use for collection definition\n */\nexport function selectSchemaForCollection(schemas: {\n inputSchema?: z.ZodObject<any>;\n schema?: z.ZodObject<any>;\n}): z.ZodObject<any> | null {\n // Prefer the full Schema over InputSchema as it includes base fields\n if (schemas.schema) {\n return schemas.schema;\n }\n\n if (schemas.inputSchema) {\n return schemas.inputSchema;\n }\n\n return null;\n}\n\n/**\n * Extracts field definitions from a Zod object schema\n * Filters out base schema fields (id, collectionId, created, updated, expand)\n *\n * @param zodSchema - The Zod object schema\n * @param excludeFields - Additional fields to exclude (default: base schema fields)\n * @returns Array of field names and their Zod types\n */\nexport function extractFieldDefinitions(\n zodSchema: z.ZodObject<any>,\n excludeFields?: string[]\n): Array<{ name: string; zodType: z.ZodTypeAny }> {\n const shape = zodSchema.shape;\n const fields: Array<{ name: string; zodType: z.ZodTypeAny }> = [];\n\n // Base schema fields to exclude (these are system fields in PocketBase)\n const baseFields = [\"id\", \"collectionId\", \"collectionName\", \"created\", \"updated\", \"expand\"];\n\n // Additional fields to exclude (image file handling fields)\n const defaultExcludeFields = [\"thumbnailURL\", \"imageFiles\"];\n\n // Combine all exclusions\n const allExclusions = new Set([...baseFields, ...defaultExcludeFields, ...(excludeFields || [])]);\n\n for (const [fieldName, zodType] of Object.entries(shape)) {\n // Skip excluded fields\n if (!allExclusions.has(fieldName)) {\n fields.push({ name: fieldName, zodType: zodType as z.ZodTypeAny });\n }\n }\n\n return fields;\n}\n\n/**\n * Detects if a collection is an auth collection\n * Auth collections have email and password fields\n *\n * @param fields - Array of field definitions\n * @returns True if the collection is an auth collection\n */\nexport function isAuthCollection(fields: Array<{ name: string; zodType: z.ZodTypeAny }>): boolean {\n const fieldNames = fields.map((f) => f.name.toLowerCase());\n\n // Auth collections must have both email and password fields\n const hasEmail = fieldNames.includes(\"email\");\n const hasPassword = fieldNames.includes(\"password\");\n\n return hasEmail && hasPassword;\n}\n\n/**\n * Extracts validation constraints from Zod type\n * Includes min, max, required, unique, and other options\n *\n * @param fieldName - The field name\n * @param zodType - The Zod type\n * @returns Field definition with constraints\n */\nexport function buildFieldDefinition(fieldName: string, zodType: z.ZodTypeAny): FieldDefinition {\n // Check for explicit field metadata first (from field helper functions)\n const fieldMetadata = extractFieldMetadata(zodType.description);\n\n if (fieldMetadata) {\n // Use explicit metadata from field helpers\n // For number fields, default to required: false unless explicitly set\n // (because required: true in PocketBase means non-zero, which is often not desired)\n let required: boolean;\n if (fieldMetadata.type === \"number\") {\n // Check if required is explicitly set in options\n if (fieldMetadata.options?.required !== undefined) {\n required = fieldMetadata.options.required;\n } else {\n // Default to false for number fields to allow zero values\n // This allows zero values (e.g., progress: 0-100) unless explicitly set to required: true\n required = false;\n }\n } else {\n // For other field types, use standard logic\n required = isFieldRequired(zodType);\n }\n\n // Remove 'required' from options if present (it's a top-level property, not an option)\n const { required: _required, ...options } = fieldMetadata.options || {};\n\n const fieldDef: FieldDefinition = {\n name: fieldName,\n type: fieldMetadata.type,\n required,\n options: Object.keys(options).length > 0 ? options : undefined,\n };\n\n // If it's a relation type from metadata, we still need to extract relation config\n if (fieldMetadata.type === \"relation\") {\n const relationMetadata = extractRelationMetadata(zodType.description);\n if (relationMetadata) {\n fieldDef.relation = {\n collection: relationMetadata.collection,\n maxSelect: relationMetadata.maxSelect,\n minSelect: relationMetadata.minSelect,\n cascadeDelete: relationMetadata.cascadeDelete,\n };\n }\n }\n\n return fieldDef;\n }\n\n // Fall back to existing type inference logic\n const fieldType = mapZodTypeToPocketBase(zodType, fieldName);\n const required = isFieldRequired(zodType);\n const options = extractFieldOptions(zodType);\n\n const fieldDef: FieldDefinition = {\n name: fieldName,\n type: fieldType,\n required,\n options,\n };\n\n // Check for explicit relation metadata first (from relation() or relations() helpers)\n const relationMetadata = extractRelationMetadata(zodType.description);\n\n if (relationMetadata) {\n // Explicit relation definition found\n fieldDef.type = \"relation\";\n fieldDef.relation = {\n collection: relationMetadata.collection,\n maxSelect: relationMetadata.maxSelect,\n minSelect: relationMetadata.minSelect,\n cascadeDelete: relationMetadata.cascadeDelete,\n };\n\n // Clear out string-specific options that don't apply to relation fields\n fieldDef.options = undefined;\n }\n // Fall back to naming convention detection for backward compatibility\n else if (isRelationField(fieldName, zodType)) {\n // Override type to 'relation' for relation fields\n fieldDef.type = \"relation\";\n\n const targetCollection = resolveTargetCollection(fieldName);\n const maxSelect = getMaxSelect(fieldName, zodType);\n const minSelect = getMinSelect(fieldName, zodType);\n\n fieldDef.relation = {\n collection: targetCollection,\n maxSelect,\n minSelect,\n cascadeDelete: false, // Default to false, can be configured later\n };\n\n // Clear out string-specific options that don't apply to relation fields\n // Options like 'min', 'max', 'pattern' are from string validation and don't apply to relations\n if (fieldDef.options) {\n const { min: _min, max: _max, pattern: _pattern, ...relationSafeOptions } = fieldDef.options;\n fieldDef.options = Object.keys(relationSafeOptions).length ? relationSafeOptions : undefined;\n }\n }\n\n return fieldDef;\n}\n\n/**\n * Extracts index definitions from a Zod schema\n * Parses the schema description metadata to find index definitions\n *\n * @param schema - Zod schema with index metadata\n * @returns Array of index SQL statements or undefined\n */\nexport function extractIndexes(schema: z.ZodTypeAny): string[] | undefined {\n // Try to extract indexes from schema description\n const schemaDescription = schema.description;\n\n if (!schemaDescription) {\n return undefined;\n }\n\n try {\n const metadata = JSON.parse(schemaDescription);\n\n // Check if indexes are present in metadata\n if (metadata.indexes && Array.isArray(metadata.indexes)) {\n return metadata.indexes;\n }\n } catch {\n // If description is not valid JSON, return undefined\n }\n\n return undefined;\n}\n\n/**\n * Converts a Zod schema to a CollectionSchema interface\n *\n * @param collectionName - The name of the collection\n * @param zodSchema - The Zod object schema\n * @returns CollectionSchema definition\n */\nexport function convertZodSchemaToCollectionSchema(\n collectionName: string,\n zodSchema: z.ZodObject<any>\n): CollectionSchema {\n // Extract field definitions from Zod schema\n const rawFields = extractFieldDefinitions(zodSchema);\n\n // Determine collection type (auth or base)\n // Prefer explicit type from metadata, fall back to field detection\n const explicitType = extractCollectionTypeFromSchema(zodSchema);\n const collectionType = explicitType ?? (isAuthCollection(rawFields) ? \"auth\" : \"base\");\n\n // Build field definitions with constraints\n let fields: FieldDefinition[] = rawFields.map(({ name, zodType }) => buildFieldDefinition(name, zodType));\n\n // Exclude auth system fields for auth collections (PocketBase adds them automatically)\n if (collectionType === \"auth\") {\n const authSystemFieldNames = [\"email\", \"emailVisibility\", \"verified\", \"password\", \"tokenKey\"];\n fields = fields.filter((field) => !authSystemFieldNames.includes(field.name));\n }\n\n // Extract indexes from schema\n const indexes = extractIndexes(zodSchema) || [];\n\n // Extract and validate permissions from schema\n const permissionAnalyzer = new PermissionAnalyzer();\n let permissions: PermissionSchema | undefined = undefined;\n\n // Try to extract permissions from schema description\n const schemaDescription = zodSchema.description;\n const extractedPermissions = permissionAnalyzer.extractPermissions(schemaDescription);\n\n if (extractedPermissions) {\n // Resolve template configurations to concrete rules\n const resolvedPermissions = permissionAnalyzer.resolvePermissions(extractedPermissions);\n\n // Validate permissions against collection fields\n const validationResults = permissionAnalyzer.validatePermissions(\n collectionName,\n resolvedPermissions,\n fields,\n collectionType === \"auth\"\n );\n\n // Log validation errors and warnings\n for (const [ruleType, result] of validationResults) {\n if (!result.valid) {\n console.error(`[${collectionName}] Permission validation failed for ${ruleType}:`);\n result.errors.forEach((error) => console.error(` - ${error}`));\n }\n\n if (result.warnings.length > 0) {\n console.warn(`[${collectionName}] Permission warnings for ${ruleType}:`);\n result.warnings.forEach((warning) => console.warn(` - ${warning}`));\n }\n }\n\n // Merge with defaults to ensure all rules are defined\n permissions = permissionAnalyzer.mergeWithDefaults(resolvedPermissions);\n }\n\n // Build collection schema\n // Use extracted permissions for rules, falling back to nulls\n const collectionSchema: CollectionSchema = {\n name: collectionName,\n type: collectionType,\n fields,\n indexes,\n rules: {\n listRule: permissions?.listRule ?? null,\n viewRule: permissions?.viewRule ?? null,\n createRule: permissions?.createRule ?? null,\n updateRule: permissions?.updateRule ?? null,\n deleteRule: permissions?.deleteRule ?? null,\n manageRule: permissions?.manageRule ?? null,\n },\n permissions,\n };\n\n return collectionSchema;\n}\n\n/**\n * Builds a complete SchemaDefinition from schema files\n * Main entry point for the Schema Analyzer\n *\n * @param config - Schema analyzer configuration or path to schema directory\n * @returns Complete SchemaDefinition with all collections\n */\nexport async function buildSchemaDefinition(config: SchemaAnalyzerConfig | string): Promise<SchemaDefinition> {\n // Support legacy string-only parameter\n const normalizedConfig: SchemaAnalyzerConfig = typeof config === \"string\" ? { schemaDir: config } : config;\n\n const mergedConfig = mergeConfig(normalizedConfig);\n const collections = new Map<string, CollectionSchema>();\n\n // Discover schema files\n const schemaFiles = discoverSchemaFiles(normalizedConfig);\n\n if (schemaFiles.length === 0) {\n const schemaDir = resolveSchemaDir(normalizedConfig);\n throw new SchemaParsingError(\n `No schema files found in ${schemaDir}. Make sure you have schema files in the directory.`,\n schemaDir\n );\n }\n\n // Process each schema file\n for (const filePath of schemaFiles) {\n try {\n let importPath = filePath;\n\n // Apply path transformation if provided (for monorepo setups)\n if (normalizedConfig.pathTransformer) {\n importPath = normalizedConfig.pathTransformer(filePath);\n } else if (mergedConfig.useCompiledFiles) {\n // Default transformation: convert /src/ to /dist/ for compiled files\n // This is a common pattern but can be overridden with pathTransformer\n const distPath = filePath.replace(/\\/src\\//, \"/dist/\");\n // Only use dist path if it actually exists (i.e., files are compiled)\n // Otherwise, fall back to source path for TypeScript files\n if (fs.existsSync(`${distPath}.js`) || fs.existsSync(`${distPath}.mjs`)) {\n importPath = distPath;\n } else {\n // Files aren't compiled, use source path\n importPath = filePath;\n }\n }\n\n // Import the module\n const module = await importSchemaModule(importPath, normalizedConfig);\n\n // Extract schema definitions\n const schemas = extractSchemaDefinitions(module, mergedConfig.schemaPatterns);\n\n // Select the appropriate schema\n const zodSchema = selectSchemaForCollection(schemas);\n\n if (!zodSchema) {\n console.warn(`No valid schema found in ${filePath}, skipping...`);\n continue;\n }\n\n // Get collection name - prefer metadata from defineCollection(), fall back to filename\n const collectionNameFromSchema = extractCollectionNameFromSchema(zodSchema);\n const collectionName = collectionNameFromSchema ?? getCollectionNameFromFile(filePath);\n\n // Convert to CollectionSchema\n const collectionSchema = convertZodSchemaToCollectionSchema(collectionName, zodSchema);\n\n // Add to collections map\n collections.set(collectionName, collectionSchema);\n } catch (error) {\n // If it's already a SchemaParsingError, re-throw it\n if (error instanceof SchemaParsingError) {\n throw error;\n }\n\n // Otherwise, wrap it in a SchemaParsingError\n throw new SchemaParsingError(\n `Error processing schema file: ${error instanceof Error ? error.message : String(error)}`,\n filePath,\n error as Error\n );\n }\n }\n\n return { collections };\n}\n\n/**\n * Parses schema files and returns SchemaDefinition\n * Alias for buildSchemaDefinition for better semantic clarity\n *\n * @param config - Schema analyzer configuration or path to schema directory\n * @returns Complete SchemaDefinition with all collections\n */\nexport async function parseSchemaFiles(config: SchemaAnalyzerConfig | string): Promise<SchemaDefinition> {\n return buildSchemaDefinition(config);\n}\n\n/**\n * Creates a SchemaAnalyzer instance with the given configuration\n * Provides an object-oriented interface for schema analysis\n */\nexport class SchemaAnalyzer {\n private config: Required<Omit<SchemaAnalyzerConfig, \"pathTransformer\">> & {\n pathTransformer?: (sourcePath: string) => string;\n };\n\n constructor(config: SchemaAnalyzerConfig) {\n this.config = mergeConfig(config);\n }\n\n /**\n * Discovers schema files in the configured directory\n */\n discoverSchemaFiles(): string[] {\n return discoverSchemaFiles(this.config);\n }\n\n /**\n * Parses all schema files and returns a SchemaDefinition\n */\n async parseSchemaFiles(): Promise<SchemaDefinition> {\n return buildSchemaDefinition(this.config);\n }\n\n /**\n * Converts a single Zod schema to a CollectionSchema\n */\n convertZodSchemaToCollectionSchema(name: string, schema: z.ZodObject<any>): CollectionSchema {\n return convertZodSchemaToCollectionSchema(name, schema);\n }\n}\n","/**\n * Collection ID generation utilities for PocketBase migrations\n */\n\nimport { randomBytes } from \"crypto\";\n\n/**\n * Generates a unique collection ID in PocketBase format\n * Format: pb_ followed by 15 alphanumeric lowercase characters\n *\n * @returns A unique collection ID string (e.g., \"pb_a1b2c3d4e5f6g7h\")\n */\nexport function generateCollectionId(): string {\n const chars = \"abcdefghijklmnopqrstuvwxyz0123456789\";\n const idLength = 15;\n\n // Generate cryptographically secure random bytes\n const bytes = randomBytes(idLength);\n\n // Convert bytes to alphanumeric characters\n let id = \"pb_\";\n for (let i = 0; i < idLength; i++) {\n const index = bytes[i] % chars.length;\n id += chars[index];\n }\n\n return id;\n}\n\n/**\n * Registry to track generated collection IDs and ensure uniqueness within a migration batch\n */\nexport class CollectionIdRegistry {\n private ids: Set<string>;\n\n constructor() {\n this.ids = new Set<string>();\n }\n\n /**\n * Generates a unique collection ID for a given collection name\n * Retries up to 10 times if collision occurs (extremely rare)\n * Special case: returns \"_pb_users_auth_\" for users collection\n *\n * @param collectionName - The name of the collection (optional)\n * @returns A unique collection ID\n * @throws Error if unable to generate unique ID after max attempts\n */\n generate(collectionName?: string): string {\n // Special case: users collection always uses the constant\n if (collectionName && collectionName.toLowerCase() === \"users\") {\n const usersId = \"_pb_users_auth_\";\n if (!this.has(usersId)) {\n this.register(usersId);\n }\n return usersId;\n }\n\n const maxAttempts = 10;\n\n for (let attempt = 0; attempt < maxAttempts; attempt++) {\n const id = generateCollectionId();\n\n if (!this.has(id)) {\n this.register(id);\n return id;\n }\n }\n\n throw new Error(\"Failed to generate unique collection ID after maximum attempts\");\n }\n\n /**\n * Checks if an ID has already been registered\n *\n * @param id - The collection ID to check\n * @returns True if the ID exists in the registry\n */\n has(id: string): boolean {\n return this.ids.has(id);\n }\n\n /**\n * Registers a collection ID in the registry\n *\n * @param id - The collection ID to register\n */\n register(id: string): void {\n this.ids.add(id);\n }\n}\n","/**\n * Diff Engine component\n * Compares current schema with previous snapshot and identifies changes\n *\n * This module provides a standalone, configurable diff engine that can be used\n * by consumer projects to compare schema definitions and detect changes.\n */\n\nimport type {\n APIRuleType,\n CollectionModification,\n CollectionSchema,\n FieldChange,\n FieldDefinition,\n FieldModification,\n PermissionChange,\n RuleUpdate,\n SchemaDefinition,\n SchemaDiff,\n SchemaSnapshot,\n} from \"./types\";\nimport { CollectionIdRegistry } from \"./utils/collection-id-generator.js\";\n\n/**\n * Configuration options for the diff engine\n */\nexport interface DiffEngineConfig {\n /**\n * Whether to warn on collection deletions\n * Defaults to true\n */\n warnOnDelete?: boolean;\n\n /**\n * Whether to require --force flag for destructive changes\n * Defaults to true\n */\n requireForceForDestructive?: boolean;\n\n /**\n * Severity threshold for requiring force flag\n * 'high' = only collection/field deletions and type changes\n * 'medium' = includes making fields required\n * 'low' = includes any constraint changes\n * Defaults to 'high'\n */\n severityThreshold?: \"high\" | \"medium\" | \"low\";\n\n /**\n * Custom system collections to exclude from diff\n * These collections will not be created or deleted\n */\n systemCollections?: string[];\n\n /**\n * Custom system fields to exclude from user collection diffs\n * These fields will not be included in fieldsToAdd for the users collection\n */\n usersSystemFields?: string[];\n}\n\n/**\n * Default configuration values\n */\nconst DEFAULT_CONFIG: Required<DiffEngineConfig> = {\n warnOnDelete: true,\n requireForceForDestructive: true,\n severityThreshold: \"high\",\n systemCollections: [\"_mfas\", \"_otps\", \"_externalAuths\", \"_authOrigins\", \"_superusers\"],\n usersSystemFields: [\"id\", \"password\", \"tokenKey\", \"email\", \"emailVisibility\", \"verified\", \"created\", \"updated\"],\n};\n\n/**\n * Merges user config with defaults\n */\nfunction mergeConfig(config?: DiffEngineConfig): Required<DiffEngineConfig> {\n return {\n ...DEFAULT_CONFIG,\n ...config,\n };\n}\n\n/**\n * Destructive change information\n */\nexport interface DestructiveChange {\n type: \"collection_delete\" | \"field_delete\" | \"type_change\" | \"required_change\" | \"constraint_change\";\n severity: \"high\" | \"medium\" | \"low\";\n collection: string;\n field?: string;\n description: string;\n oldValue?: any;\n newValue?: any;\n}\n\n/**\n * Change summary for status reporting\n */\nexport interface ChangeSummary {\n totalChanges: number;\n collectionsToCreate: number;\n collectionsToDelete: number;\n collectionsToModify: number;\n fieldsToAdd: number;\n fieldsToRemove: number;\n fieldsToModify: number;\n indexChanges: number;\n ruleChanges: number;\n permissionChanges: number;\n destructiveChanges: DestructiveChange[];\n nonDestructiveChanges: string[];\n}\n\n/**\n * Checks if a collection is a PocketBase system collection\n * System collections are internal to PocketBase and should not be created or deleted\n *\n * @param collectionName - Name of the collection to check\n * @param config - Optional configuration with custom system collections\n * @returns True if the collection is a system collection\n */\nexport function isSystemCollection(collectionName: string, config?: DiffEngineConfig): boolean {\n const mergedConfig = mergeConfig(config);\n return mergedConfig.systemCollections.includes(collectionName);\n}\n\n/**\n * Returns the list of system field names for the users collection\n * These fields are automatically provided by PocketBase for auth collections\n * and should not be included when generating migrations for users collection extensions\n *\n * @param config - Optional configuration with custom system fields\n * @returns Set of system field names\n */\nexport function getUsersSystemFields(config?: DiffEngineConfig): Set<string> {\n const mergedConfig = mergeConfig(config);\n return new Set(mergedConfig.usersSystemFields);\n}\n\n/**\n * Filters system collections from a schema definition\n * Returns a new SchemaDefinition with only custom (non-system) collections\n *\n * @param schema - Schema definition to filter\n * @param config - Optional configuration\n * @returns Filtered SchemaDefinition without system collections\n */\nexport function filterSystemCollections(schema: SchemaDefinition, config?: DiffEngineConfig): SchemaDefinition {\n const filteredCollections = new Map<string, CollectionSchema>();\n\n for (const [collectionName, collectionSchema] of schema.collections) {\n if (!isSystemCollection(collectionName, config)) {\n filteredCollections.set(collectionName, collectionSchema);\n }\n }\n\n return {\n collections: filteredCollections,\n };\n}\n\n/**\n * Identifies new collections in schema that don't exist in snapshot\n *\n * @param currentSchema - Current schema definition\n * @param previousSnapshot - Previous schema snapshot\n * @returns Array of new collections\n */\nexport function findNewCollections(\n currentSchema: SchemaDefinition,\n previousSnapshot: SchemaSnapshot | null\n): CollectionSchema[] {\n const newCollections: CollectionSchema[] = [];\n\n // If no previous snapshot, all collections are new\n if (!previousSnapshot) {\n return Array.from(currentSchema.collections.values());\n }\n\n // Find collections in current schema that don't exist in snapshot\n for (const [collectionName, collectionSchema] of currentSchema.collections) {\n if (!previousSnapshot.collections.has(collectionName)) {\n newCollections.push(collectionSchema);\n }\n }\n\n return newCollections;\n}\n\n/**\n * Identifies collections removed from schema (exist in snapshot but not in current schema)\n *\n * @param currentSchema - Current schema definition\n * @param previousSnapshot - Previous schema snapshot\n * @returns Array of removed collections\n */\nexport function findRemovedCollections(\n currentSchema: SchemaDefinition,\n previousSnapshot: SchemaSnapshot | null\n): CollectionSchema[] {\n const removedCollections: CollectionSchema[] = [];\n\n // If no previous snapshot, nothing can be removed\n if (!previousSnapshot) {\n return removedCollections;\n }\n\n // Find collections in snapshot that don't exist in current schema\n for (const [collectionName, collectionSchema] of previousSnapshot.collections) {\n if (!currentSchema.collections.has(collectionName)) {\n removedCollections.push(collectionSchema);\n }\n }\n\n return removedCollections;\n}\n\n/**\n * Matches collections by name between current schema and snapshot\n * Returns pairs of [current, previous] for collections that exist in both\n *\n * @param currentSchema - Current schema definition\n * @param previousSnapshot - Previous schema snapshot\n * @returns Array of matched collection pairs\n */\nexport function matchCollectionsByName(\n currentSchema: SchemaDefinition,\n previousSnapshot: SchemaSnapshot | null\n): Array<[CollectionSchema, CollectionSchema]> {\n const matches: Array<[CollectionSchema, CollectionSchema]> = [];\n\n // If no previous snapshot, no matches possible\n if (!previousSnapshot) {\n return matches;\n }\n\n // Create a case-insensitive lookup map for previous collections\n const previousCollectionsLower = new Map<string, [string, CollectionSchema]>();\n for (const [name, collection] of previousSnapshot.collections) {\n previousCollectionsLower.set(name.toLowerCase(), [name, collection]);\n }\n\n // Find collections that exist in both current and previous (case-insensitive)\n for (const [collectionName, currentCollection] of currentSchema.collections) {\n const previousEntry = previousCollectionsLower.get(collectionName.toLowerCase());\n\n if (previousEntry) {\n const [, previousCollection] = previousEntry;\n matches.push([currentCollection, previousCollection]);\n }\n }\n\n return matches;\n}\n\n/**\n * Identifies new fields in current collection that don't exist in previous\n *\n * @param currentFields - Current collection fields\n * @param previousFields - Previous collection fields\n * @returns Array of new fields\n */\nexport function findNewFields(currentFields: FieldDefinition[], previousFields: FieldDefinition[]): FieldDefinition[] {\n const newFields: FieldDefinition[] = [];\n const previousFieldNames = new Set(previousFields.map((f) => f.name));\n\n for (const currentField of currentFields) {\n if (!previousFieldNames.has(currentField.name)) {\n newFields.push(currentField);\n }\n }\n\n return newFields;\n}\n\n/**\n * Identifies fields removed from current collection (exist in previous but not in current)\n *\n * @param currentFields - Current collection fields\n * @param previousFields - Previous collection fields\n * @returns Array of removed fields\n */\nexport function findRemovedFields(\n currentFields: FieldDefinition[],\n previousFields: FieldDefinition[]\n): FieldDefinition[] {\n const removedFields: FieldDefinition[] = [];\n const currentFieldNames = new Set(currentFields.map((f) => f.name));\n\n for (const previousField of previousFields) {\n if (!currentFieldNames.has(previousField.name)) {\n removedFields.push(previousField);\n }\n }\n\n return removedFields;\n}\n\n/**\n * Matches fields by name between current and previous collections\n * Returns pairs of [current, previous] for fields that exist in both\n *\n * @param currentFields - Current collection fields\n * @param previousFields - Previous collection fields\n * @returns Array of matched field pairs\n */\nexport function matchFieldsByName(\n currentFields: FieldDefinition[],\n previousFields: FieldDefinition[]\n): Array<[FieldDefinition, FieldDefinition]> {\n const matches: Array<[FieldDefinition, FieldDefinition]> = [];\n\n // Create a map of previous fields by name for efficient lookup\n const previousFieldMap = new Map<string, FieldDefinition>();\n for (const previousField of previousFields) {\n previousFieldMap.set(previousField.name, previousField);\n }\n\n // Find matching fields\n for (const currentField of currentFields) {\n const previousField = previousFieldMap.get(currentField.name);\n\n if (previousField) {\n matches.push([currentField, previousField]);\n }\n }\n\n return matches;\n}\n\n/**\n * Compares two values for equality, handling deep object comparison\n *\n * @param a - First value\n * @param b - Second value\n * @returns True if values are equal\n */\nfunction areValuesEqual(a: any, b: any): boolean {\n // Handle null/undefined\n if (a === b) return true;\n if (a == null || b == null) return false;\n\n // Handle arrays\n if (Array.isArray(a) && Array.isArray(b)) {\n if (a.length !== b.length) return false;\n return a.every((val, idx) => areValuesEqual(val, b[idx]));\n }\n\n // Handle objects\n if (typeof a === \"object\" && typeof b === \"object\") {\n const keysA = Object.keys(a);\n const keysB = Object.keys(b);\n\n if (keysA.length !== keysB.length) return false;\n\n return keysA.every((key) => areValuesEqual(a[key], b[key]));\n }\n\n // Primitive comparison\n return a === b;\n}\n\n/**\n * Compares field types between current and previous\n *\n * @param currentField - Current field definition\n * @param previousField - Previous field definition\n * @returns FieldChange if types differ, null otherwise\n */\nexport function compareFieldTypes(currentField: FieldDefinition, previousField: FieldDefinition): FieldChange | null {\n if (currentField.type !== previousField.type) {\n return {\n property: \"type\",\n oldValue: previousField.type,\n newValue: currentField.type,\n };\n }\n\n return null;\n}\n\n/**\n * Compares field constraints (required, unique) between current and previous\n *\n * @param currentField - Current field definition\n * @param previousField - Previous field definition\n * @returns Array of FieldChange for constraint differences\n */\nexport function compareFieldConstraints(currentField: FieldDefinition, previousField: FieldDefinition): FieldChange[] {\n const changes: FieldChange[] = [];\n\n // Compare required constraint\n if (currentField.required !== previousField.required) {\n changes.push({\n property: \"required\",\n oldValue: previousField.required,\n newValue: currentField.required,\n });\n }\n\n // Compare unique constraint\n if (currentField.unique !== previousField.unique) {\n changes.push({\n property: \"unique\",\n oldValue: previousField.unique,\n newValue: currentField.unique,\n });\n }\n\n return changes;\n}\n\n/**\n * Normalizes a field option value to account for PocketBase defaults\n * Returns the normalized value, treating default values as equivalent to undefined\n *\n * @param key - Option key name\n * @param value - Option value\n * @param fieldType - Field type\n * @returns Normalized value (undefined if it's a default value)\n */\nfunction normalizeOptionValue(key: string, value: any, fieldType: string): any {\n // maxSelect: 1 is the default for select and file fields\n if (key === \"maxSelect\" && value === 1 && (fieldType === \"select\" || fieldType === \"file\")) {\n return undefined; // Treat as undefined to match missing default\n }\n\n // maxSize: 0 is default for file fields\n if (key === \"maxSize\" && value === 0 && fieldType === \"file\") {\n return undefined;\n }\n\n // Empty arrays are defaults for file fields\n if (fieldType === \"file\") {\n if (key === \"mimeTypes\" && Array.isArray(value) && value.length === 0) {\n return undefined;\n }\n if (key === \"thumbs\" && Array.isArray(value) && value.length === 0) {\n return undefined;\n }\n if (key === \"protected\" && value === false) {\n return undefined;\n }\n }\n\n // Autodate defaults\n if (fieldType === \"autodate\") {\n if (key === \"onCreate\" && value === true) {\n return undefined;\n }\n if (key === \"onUpdate\" && value === false) {\n return undefined;\n }\n }\n\n return value;\n}\n\n/**\n * Compares field options (min, max, pattern, etc.) between current and previous\n *\n * @param currentField - Current field definition\n * @param previousField - Previous field definition\n * @returns Array of FieldChange for option differences\n */\nexport function compareFieldOptions(currentField: FieldDefinition, previousField: FieldDefinition): FieldChange[] {\n const changes: FieldChange[] = [];\n\n const currentOptions = currentField.options || {};\n const previousOptions = previousField.options || {};\n\n // Get all unique option keys\n const allKeys = new Set([...Object.keys(currentOptions), ...Object.keys(previousOptions)]);\n\n // Compare each option\n // Use currentField.type for normalization since types should match at this point\n // (type changes are handled separately in compareFieldTypes)\n const fieldType = currentField.type;\n\n for (const key of allKeys) {\n const currentValue = currentOptions[key];\n const previousValue = previousOptions[key];\n\n // Normalize values to account for default values\n // This ensures that maxSelect: 1 (default) is treated the same as undefined (missing default)\n const normalizedCurrent = normalizeOptionValue(key, currentValue, fieldType);\n const normalizedPrevious = normalizeOptionValue(key, previousValue, fieldType);\n\n // Handle undefined values - if both are undefined (or normalized to undefined), that's not a change\n if (normalizedCurrent === undefined && normalizedPrevious === undefined) {\n continue;\n }\n\n if (!areValuesEqual(normalizedCurrent, normalizedPrevious)) {\n changes.push({\n property: `options.${key}`,\n oldValue: previousValue,\n newValue: currentValue,\n });\n }\n }\n\n return changes;\n}\n\n/**\n * Compares relation configurations between current and previous\n *\n * @param currentField - Current field definition\n * @param previousField - Previous field definition\n * @returns Array of FieldChange for relation differences\n */\nexport function compareRelationConfigurations(\n currentField: FieldDefinition,\n previousField: FieldDefinition,\n collectionIdToName?: Map<string, string>\n): FieldChange[] {\n const changes: FieldChange[] = [];\n\n const currentRelation = currentField.relation;\n const previousRelation = previousField.relation;\n\n // If one has relation and other doesn't, that's a type change (handled elsewhere)\n if (!currentRelation && !previousRelation) {\n return changes;\n }\n\n if (!currentRelation || !previousRelation) {\n // This shouldn't happen if types match, but handle gracefully\n return changes;\n }\n\n // Compare relation properties\n // Note: collectionId should already be resolved to collection name during parsing\n // This normalization is just a safety net for edge cases\n const normalizeCollection = (collection: string): string => {\n if (!collection) return collection;\n\n // Resolve ID to name if possible\n if (collectionIdToName && collectionIdToName.has(collection)) {\n return collectionIdToName.get(collection)!;\n }\n\n // Handle expressions that might not have been parsed correctly\n const nameMatch = collection.match(/app\\.findCollectionByNameOrId\\s*\\(\\s*[\"']([^\"']+)[\"']\\s*\\)/);\n if (nameMatch) {\n return nameMatch[1];\n }\n return collection;\n };\n\n const normalizedCurrent = normalizeCollection(currentRelation.collection);\n // We resolve the ID from the previous relation (snapshot) to its name if available\n const normalizedPrevious = normalizeCollection(previousRelation.collection);\n\n // Only report a change if the normalized values differ\n // Use case-insensitive comparison for collection names\n if (normalizedCurrent.toLowerCase() !== normalizedPrevious.toLowerCase()) {\n changes.push({\n property: \"relation.collection\",\n oldValue: previousRelation.collection,\n newValue: currentRelation.collection,\n });\n }\n\n if (currentRelation.cascadeDelete !== previousRelation.cascadeDelete) {\n changes.push({\n property: \"relation.cascadeDelete\",\n oldValue: previousRelation.cascadeDelete,\n newValue: currentRelation.cascadeDelete,\n });\n }\n\n // Normalize maxSelect: 1 to undefined/null as it's often the default or treated as such\n const normalizeMax = (val: number | null | undefined) => (val === 1 ? null : val);\n const currentMax = normalizeMax(currentRelation.maxSelect);\n const previousMax = normalizeMax(previousRelation.maxSelect);\n\n // Use loose equality to handle null vs undefined\n if (currentMax != previousMax) {\n changes.push({\n property: \"relation.maxSelect\",\n oldValue: previousRelation.maxSelect,\n newValue: currentRelation.maxSelect,\n });\n }\n\n // Normalize minSelect: 0 to undefined/null\n const normalizeMin = (val: number | null | undefined) => (val === 0 ? null : val);\n const currentMin = normalizeMin(currentRelation.minSelect);\n const previousMin = normalizeMin(previousRelation.minSelect);\n\n if (currentMin != previousMin) {\n changes.push({\n property: \"relation.minSelect\",\n oldValue: previousRelation.minSelect,\n newValue: currentRelation.minSelect,\n });\n }\n\n return changes;\n}\n\n/**\n * Detects all changes between two field definitions\n * Combines type, constraint, option, and relation changes\n *\n * @param currentField - Current field definition\n * @param previousField - Previous field definition\n * @returns Array of all detected changes\n */\nexport function detectFieldChanges(\n currentField: FieldDefinition,\n previousField: FieldDefinition,\n collectionIdToName?: Map<string, string>\n): FieldChange[] {\n const changes: FieldChange[] = [];\n\n // Compare types\n const typeChange = compareFieldTypes(currentField, previousField);\n if (typeChange) {\n changes.push(typeChange);\n }\n\n // Compare constraints\n changes.push(...compareFieldConstraints(currentField, previousField));\n\n // Compare options\n changes.push(...compareFieldOptions(currentField, previousField));\n\n // Compare relation configurations (if applicable)\n if (currentField.type === \"relation\" && previousField.type === \"relation\") {\n changes.push(...compareRelationConfigurations(currentField, previousField, collectionIdToName));\n }\n\n return changes;\n}\n\n/**\n * Compares indexes between current and previous collections\n *\n * @param currentIndexes - Current collection indexes\n * @param previousIndexes - Previous collection indexes\n * @returns Object with indexes to add and remove\n */\nfunction compareIndexes(\n currentIndexes: string[] = [],\n previousIndexes: string[] = []\n): { indexesToAdd: string[]; indexesToRemove: string[] } {\n const currentSet = new Set(currentIndexes);\n const previousSet = new Set(previousIndexes);\n\n const indexesToAdd = currentIndexes.filter((idx) => !previousSet.has(idx));\n const indexesToRemove = previousIndexes.filter((idx) => !currentSet.has(idx));\n\n return { indexesToAdd, indexesToRemove };\n}\n\n/**\n * Compares API rules between current and previous collections\n *\n * @param currentRules - Current collection rules\n * @param previousRules - Previous collection rules\n * @returns Array of rule updates\n */\nfunction compareRules(\n currentRules: CollectionSchema[\"rules\"],\n previousRules: CollectionSchema[\"rules\"],\n currentPermissions?: CollectionSchema[\"permissions\"],\n previousPermissions?: CollectionSchema[\"permissions\"]\n): RuleUpdate[] {\n const updates: RuleUpdate[] = [];\n\n const ruleTypes: Array<keyof NonNullable<CollectionSchema[\"rules\"]>> = [\n \"listRule\",\n \"viewRule\",\n \"createRule\",\n \"updateRule\",\n \"deleteRule\",\n \"manageRule\",\n ];\n\n for (const ruleType of ruleTypes) {\n // Use rules if available, otherwise fall back to permissions (they're the same thing)\n const currentValue = currentRules?.[ruleType] ?? currentPermissions?.[ruleType] ?? null;\n const previousValue = previousRules?.[ruleType] ?? previousPermissions?.[ruleType] ?? null;\n\n if (currentValue !== previousValue) {\n updates.push({\n ruleType: ruleType as RuleUpdate[\"ruleType\"],\n oldValue: previousValue,\n newValue: currentValue,\n });\n }\n }\n\n return updates;\n}\n\n/**\n * Compares permissions between current and previous collections\n * Detects changes in permission rules defined in schema\n *\n * @param currentPermissions - Current collection permissions\n * @param previousPermissions - Previous collection permissions\n * @returns Array of permission changes\n */\nexport function comparePermissions(\n currentPermissions: CollectionSchema[\"permissions\"],\n previousPermissions: CollectionSchema[\"permissions\"]\n): PermissionChange[] {\n const changes: PermissionChange[] = [];\n\n const ruleTypes: APIRuleType[] = [\"listRule\", \"viewRule\", \"createRule\", \"updateRule\", \"deleteRule\", \"manageRule\"];\n\n for (const ruleType of ruleTypes) {\n const currentValue = currentPermissions?.[ruleType] ?? null;\n const previousValue = previousPermissions?.[ruleType] ?? null;\n\n // Compare permission values\n if (currentValue !== previousValue) {\n changes.push({\n ruleType,\n oldValue: previousValue,\n newValue: currentValue,\n });\n }\n }\n\n return changes;\n}\n\n/**\n * Compares fields between current and previous collections\n * Identifies new, removed, and modified fields\n * For the users collection, filters out system fields from fieldsToAdd\n *\n * @param currentCollection - Current collection schema\n * @param previousCollection - Previous collection schema\n * @param config - Optional configuration\n * @returns Object with field changes\n */\nfunction compareCollectionFields(\n currentCollection: CollectionSchema,\n previousCollection: CollectionSchema,\n config?: DiffEngineConfig,\n collectionIdToName?: Map<string, string>\n): {\n fieldsToAdd: FieldDefinition[];\n fieldsToRemove: FieldDefinition[];\n fieldsToModify: FieldModification[];\n} {\n let fieldsToAdd = findNewFields(currentCollection.fields, previousCollection.fields);\n const fieldsToRemove = findRemovedFields(currentCollection.fields, previousCollection.fields);\n const fieldsToModify: FieldModification[] = [];\n\n // For users collection, filter out system fields from fieldsToAdd\n // System fields are automatically provided by PocketBase and should not be in migrations\n if (currentCollection.name === \"users\") {\n const systemFields = getUsersSystemFields(config);\n fieldsToAdd = fieldsToAdd.filter((field) => !systemFields.has(field.name));\n }\n\n // Check for modified fields\n const matchedFields = matchFieldsByName(currentCollection.fields, previousCollection.fields);\n\n for (const [currentField, previousField] of matchedFields) {\n const changes = detectFieldChanges(currentField, previousField, collectionIdToName);\n\n if (changes.length > 0) {\n fieldsToModify.push({\n fieldName: currentField.name,\n currentDefinition: previousField,\n newDefinition: currentField,\n changes,\n });\n }\n }\n\n return { fieldsToAdd, fieldsToRemove, fieldsToModify };\n}\n\n/**\n * Builds a CollectionModification for a matched collection pair\n *\n * @param currentCollection - Current collection schema\n * @param previousCollection - Previous collection schema\n * @param config - Optional configuration\n * @returns CollectionModification object\n */\nfunction buildCollectionModification(\n currentCollection: CollectionSchema,\n previousCollection: CollectionSchema,\n config?: DiffEngineConfig,\n collectionIdToName?: Map<string, string>\n): CollectionModification {\n // Compare fields\n const { fieldsToAdd, fieldsToRemove, fieldsToModify } = compareCollectionFields(\n currentCollection,\n previousCollection,\n config,\n collectionIdToName\n );\n\n // Compare indexes\n const { indexesToAdd, indexesToRemove } = compareIndexes(currentCollection.indexes, previousCollection.indexes);\n\n // Compare rules (also check permissions as fallback since they're the same thing)\n const rulesToUpdate = compareRules(\n currentCollection.rules,\n previousCollection.rules,\n currentCollection.permissions,\n previousCollection.permissions\n );\n\n // Compare permissions\n const permissionsToUpdate = comparePermissions(currentCollection.permissions, previousCollection.permissions);\n\n return {\n collection: currentCollection.name,\n fieldsToAdd,\n fieldsToRemove,\n fieldsToModify,\n indexesToAdd,\n indexesToRemove,\n rulesToUpdate,\n permissionsToUpdate,\n };\n}\n\n/**\n * Checks if a collection modification has any actual changes\n *\n * @param modification - Collection modification to check\n * @returns True if there are any changes\n */\nfunction hasChanges(modification: CollectionModification): boolean {\n return (\n modification.fieldsToAdd.length > 0 ||\n modification.fieldsToRemove.length > 0 ||\n modification.fieldsToModify.length > 0 ||\n modification.indexesToAdd.length > 0 ||\n modification.indexesToRemove.length > 0 ||\n modification.rulesToUpdate.length > 0 ||\n modification.permissionsToUpdate.length > 0\n );\n}\n\n/**\n * Aggregates all detected changes into a SchemaDiff\n * Main entry point for diff comparison\n *\n * @param currentSchema - Current schema definition\n * @param previousSnapshot - Previous schema snapshot\n * @param config - Optional configuration\n * @returns Complete SchemaDiff with all changes\n */\nexport function aggregateChanges(\n currentSchema: SchemaDefinition,\n previousSnapshot: SchemaSnapshot | null,\n config?: DiffEngineConfig\n): SchemaDiff {\n // Build lookup map for ID -> Name from previous snapshot\n // This helps resolve relations where snapshot uses ID but schema uses Name\n const collectionIdToName = new Map<string, string>();\n if (previousSnapshot) {\n for (const [name, collection] of previousSnapshot.collections) {\n if (collection.id) {\n collectionIdToName.set(collection.id, name);\n }\n }\n }\n\n // Find new and removed collections\n const collectionsToCreate = findNewCollections(currentSchema, previousSnapshot);\n const collectionsToDelete = findRemovedCollections(currentSchema, previousSnapshot);\n\n // Filter out system collections from create and delete operations\n const filteredCollectionsToCreate = collectionsToCreate.filter(\n (collection) => !isSystemCollection(collection.name, config)\n );\n const filteredCollectionsToDelete = collectionsToDelete.filter(\n (collection) => !isSystemCollection(collection.name, config)\n );\n\n // Generate and assign collection IDs for new collections\n const registry = new CollectionIdRegistry();\n const collectionsWithIds = filteredCollectionsToCreate.map((collection) => {\n // If the collection already has an ID, register it and use it\n if (collection.id) {\n registry.register(collection.id);\n return collection;\n }\n\n // Generate a new ID for the collection (pass name for special handling)\n const id = registry.generate(collection.name);\n return {\n ...collection,\n id,\n };\n });\n\n // Find modified collections\n const collectionsToModify: CollectionModification[] = [];\n const matchedCollections = matchCollectionsByName(currentSchema, previousSnapshot);\n\n for (const [currentCollection, previousCollection] of matchedCollections) {\n const modification = buildCollectionModification(currentCollection, previousCollection, config, collectionIdToName);\n\n // Only include if there are actual changes\n // Note: We allow modifications to the users collection (non-system)\n if (hasChanges(modification)) {\n collectionsToModify.push(modification);\n }\n }\n\n return {\n collectionsToCreate: collectionsWithIds,\n collectionsToDelete: filteredCollectionsToDelete,\n collectionsToModify,\n };\n}\n\n/**\n * Detects destructive changes in a schema diff\n * Returns detailed information about each destructive change\n *\n * @param diff - Schema diff to analyze\n * @param config - Optional configuration for severity thresholds\n * @returns Array of destructive changes with severity information\n */\nexport function detectDestructiveChanges(diff: SchemaDiff, config?: DiffEngineConfig): DestructiveChange[] {\n const destructiveChanges: DestructiveChange[] = [];\n const mergedConfig = mergeConfig(config);\n\n // Collection deletions are always high severity\n for (const collection of diff.collectionsToDelete) {\n destructiveChanges.push({\n type: \"collection_delete\",\n severity: \"high\",\n collection: collection.name,\n description: `Delete collection: ${collection.name}`,\n });\n }\n\n // Analyze modifications\n for (const modification of diff.collectionsToModify) {\n const collectionName = modification.collection;\n\n // Field deletions are high severity\n for (const field of modification.fieldsToRemove) {\n destructiveChanges.push({\n type: \"field_delete\",\n severity: \"high\",\n collection: collectionName,\n field: field.name,\n description: `Delete field: ${collectionName}.${field.name}`,\n });\n }\n\n // Field modifications can be various severities\n for (const fieldMod of modification.fieldsToModify) {\n const typeChange = fieldMod.changes.find((c) => c.property === \"type\");\n const requiredChange = fieldMod.changes.find((c) => c.property === \"required\" && c.newValue === true);\n\n if (typeChange) {\n destructiveChanges.push({\n type: \"type_change\",\n severity: \"high\",\n collection: collectionName,\n field: fieldMod.fieldName,\n description: `Change field type: ${collectionName}.${fieldMod.fieldName} (${typeChange.oldValue} → ${typeChange.newValue})`,\n oldValue: typeChange.oldValue,\n newValue: typeChange.newValue,\n });\n }\n\n if (requiredChange && mergedConfig.severityThreshold !== \"high\") {\n destructiveChanges.push({\n type: \"required_change\",\n severity: \"medium\",\n collection: collectionName,\n field: fieldMod.fieldName,\n description: `Make field required: ${collectionName}.${fieldMod.fieldName}`,\n oldValue: false,\n newValue: true,\n });\n }\n\n // Other constraint changes at low severity\n if (mergedConfig.severityThreshold === \"low\") {\n const otherChanges = fieldMod.changes.filter((c) => c.property !== \"type\" && c.property !== \"required\");\n for (const change of otherChanges) {\n destructiveChanges.push({\n type: \"constraint_change\",\n severity: \"low\",\n collection: collectionName,\n field: fieldMod.fieldName,\n description: `Change constraint: ${collectionName}.${fieldMod.fieldName}.${change.property}`,\n oldValue: change.oldValue,\n newValue: change.newValue,\n });\n }\n }\n }\n }\n\n return destructiveChanges;\n}\n\n/**\n * Categorizes changes by severity\n * Returns object with destructive and non-destructive changes\n *\n * @param diff - Schema diff to categorize\n * @param config - Optional configuration\n * @returns Object with categorized changes\n */\nexport function categorizeChangesBySeverity(\n diff: SchemaDiff,\n _config?: DiffEngineConfig\n): {\n destructive: string[];\n nonDestructive: string[];\n} {\n const destructive: string[] = [];\n const nonDestructive: string[] = [];\n\n // Collection deletions are destructive\n for (const collection of diff.collectionsToDelete) {\n destructive.push(`Delete collection: ${collection.name}`);\n }\n\n // Collection creations are non-destructive\n for (const collection of diff.collectionsToCreate) {\n nonDestructive.push(`Create collection: ${collection.name}`);\n }\n\n // Analyze modifications\n for (const modification of diff.collectionsToModify) {\n const collectionName = modification.collection;\n\n // Field deletions are destructive\n for (const field of modification.fieldsToRemove) {\n destructive.push(`Delete field: ${collectionName}.${field.name}`);\n }\n\n // Field additions are non-destructive\n for (const field of modification.fieldsToAdd) {\n nonDestructive.push(`Add field: ${collectionName}.${field.name}`);\n }\n\n // Field modifications can be destructive or non-destructive\n for (const fieldMod of modification.fieldsToModify) {\n const hasTypeChange = fieldMod.changes.some((c) => c.property === \"type\");\n const hasRequiredChange = fieldMod.changes.some((c) => c.property === \"required\" && c.newValue === true);\n\n if (hasTypeChange) {\n destructive.push(\n `Change field type: ${collectionName}.${fieldMod.fieldName} (${fieldMod.changes.find((c) => c.property === \"type\")?.oldValue} → ${fieldMod.changes.find((c) => c.property === \"type\")?.newValue})`\n );\n } else if (hasRequiredChange) {\n destructive.push(`Make field required: ${collectionName}.${fieldMod.fieldName}`);\n } else {\n nonDestructive.push(`Modify field: ${collectionName}.${fieldMod.fieldName}`);\n }\n }\n\n // Index changes are generally non-destructive\n for (const _index of modification.indexesToAdd) {\n nonDestructive.push(`Add index: ${collectionName}`);\n }\n\n for (const _index of modification.indexesToRemove) {\n nonDestructive.push(`Remove index: ${collectionName}`);\n }\n\n // Rule changes are non-destructive\n for (const rule of modification.rulesToUpdate) {\n nonDestructive.push(`Update rule: ${collectionName}.${rule.ruleType}`);\n }\n }\n\n return { destructive, nonDestructive };\n}\n\n/**\n * Generates a summary of all changes in a diff\n * Useful for status reporting and user feedback\n *\n * @param diff - Schema diff to summarize\n * @param config - Optional configuration\n * @returns Change summary with counts and details\n */\nexport function generateChangeSummary(diff: SchemaDiff, config?: DiffEngineConfig): ChangeSummary {\n const destructiveChanges = detectDestructiveChanges(diff, config);\n const { nonDestructive } = categorizeChangesBySeverity(diff, config);\n\n let fieldsToAdd = 0;\n let fieldsToRemove = 0;\n let fieldsToModify = 0;\n let indexChanges = 0;\n let ruleChanges = 0;\n let permissionChanges = 0;\n\n for (const modification of diff.collectionsToModify) {\n fieldsToAdd += modification.fieldsToAdd.length;\n fieldsToRemove += modification.fieldsToRemove.length;\n fieldsToModify += modification.fieldsToModify.length;\n indexChanges += modification.indexesToAdd.length + modification.indexesToRemove.length;\n ruleChanges += modification.rulesToUpdate.length;\n permissionChanges += modification.permissionsToUpdate.length;\n }\n\n return {\n totalChanges: diff.collectionsToCreate.length + diff.collectionsToDelete.length + diff.collectionsToModify.length,\n collectionsToCreate: diff.collectionsToCreate.length,\n collectionsToDelete: diff.collectionsToDelete.length,\n collectionsToModify: diff.collectionsToModify.length,\n fieldsToAdd,\n fieldsToRemove,\n fieldsToModify,\n indexChanges,\n ruleChanges,\n permissionChanges,\n destructiveChanges,\n nonDestructiveChanges: nonDestructive,\n };\n}\n\n/**\n * Checks if a diff requires the --force flag based on configuration\n *\n * @param diff - Schema diff to check\n * @param config - Configuration with severity threshold\n * @returns True if force flag is required\n */\nexport function requiresForceFlag(diff: SchemaDiff, config?: DiffEngineConfig): boolean {\n const mergedConfig = mergeConfig(config);\n\n if (!mergedConfig.requireForceForDestructive) {\n return false;\n }\n\n const destructiveChanges = detectDestructiveChanges(diff, config);\n\n // Filter by severity threshold\n const relevantChanges = destructiveChanges.filter((change) => {\n switch (mergedConfig.severityThreshold) {\n case \"high\":\n return change.severity === \"high\";\n case \"medium\":\n return change.severity === \"high\" || change.severity === \"medium\";\n case \"low\":\n return true;\n default:\n return change.severity === \"high\";\n }\n });\n\n return relevantChanges.length > 0;\n}\n\n/**\n * Main comparison function\n * Compares current schema with previous snapshot and returns complete diff\n *\n * @param currentSchema - Current schema definition\n * @param previousSnapshot - Previous schema snapshot (null for first run)\n * @param config - Optional configuration\n * @returns Complete SchemaDiff with all detected changes\n */\nexport function compare(\n currentSchema: SchemaDefinition,\n previousSnapshot: SchemaSnapshot | null,\n config?: DiffEngineConfig\n): SchemaDiff {\n return aggregateChanges(currentSchema, previousSnapshot, config);\n}\n\n/**\n * DiffEngine class for object-oriented usage\n * Provides a stateful interface for schema comparison\n */\nexport class DiffEngine {\n private config: Required<DiffEngineConfig>;\n\n constructor(config?: DiffEngineConfig) {\n this.config = mergeConfig(config);\n }\n\n /**\n * Compares current schema with previous snapshot\n */\n compare(currentSchema: SchemaDefinition, previousSnapshot: SchemaSnapshot | null): SchemaDiff {\n return compare(currentSchema, previousSnapshot, this.config);\n }\n\n /**\n * Detects destructive changes in a diff\n */\n detectDestructiveChanges(diff: SchemaDiff): DestructiveChange[] {\n return detectDestructiveChanges(diff, this.config);\n }\n\n /**\n * Categorizes changes by severity\n */\n categorizeChangesBySeverity(diff: SchemaDiff): { destructive: string[]; nonDestructive: string[] } {\n return categorizeChangesBySeverity(diff, this.config);\n }\n\n /**\n * Generates a summary of changes\n */\n generateChangeSummary(diff: SchemaDiff): ChangeSummary {\n return generateChangeSummary(diff, this.config);\n }\n\n /**\n * Checks if force flag is required\n */\n requiresForceFlag(diff: SchemaDiff): boolean {\n return requiresForceFlag(diff, this.config);\n }\n}\n","/**\n * Migration Generator component\n * Creates PocketBase migration files based on detected differences\n *\n * This module provides a standalone, configurable migration generator that can be used\n * by consumer projects to generate PocketBase-compatible migration files.\n */\n\nimport * as fs from \"fs\";\nimport * as path from \"path\";\nimport { FileSystemError, MigrationGenerationError } from \"./errors\";\nimport type { CollectionOperation, CollectionSchema, FieldDefinition, FieldModification, SchemaDiff } from \"./types\";\n\n/**\n * Configuration options for the migration generator\n */\nexport interface MigrationGeneratorConfig {\n /**\n * Directory to write migration files\n */\n migrationDir: string;\n\n /**\n * Workspace root for resolving relative paths\n * Defaults to process.cwd()\n */\n workspaceRoot?: string;\n\n /**\n * Custom timestamp generator function\n * Defaults to Unix timestamp in seconds\n */\n timestampGenerator?: () => string;\n\n /**\n * Custom migration file template\n * Use {{UP_CODE}} and {{DOWN_CODE}} placeholders\n */\n template?: string;\n\n /**\n * Whether to include type reference comment\n * Defaults to true\n */\n includeTypeReference?: boolean;\n\n /**\n * Path to types.d.ts file for reference comment\n * Defaults to '../pb_data/types.d.ts'\n */\n typesPath?: string;\n}\n\n/**\n * Default migration template\n */\nconst DEFAULT_TEMPLATE = `/// <reference path=\"{{TYPES_PATH}}\" />\nmigrate((app) => {\n{{UP_CODE}}\n}, (app) => {\n{{DOWN_CODE}}\n});\n`;\n\n/**\n * Default configuration values\n */\nconst DEFAULT_CONFIG: Omit<Required<MigrationGeneratorConfig>, \"migrationDir\"> = {\n workspaceRoot: process.cwd(),\n timestampGenerator: () => Math.floor(Date.now() / 1000).toString(),\n template: DEFAULT_TEMPLATE,\n includeTypeReference: true,\n typesPath: \"../pb_data/types.d.ts\",\n};\n\n/**\n * Merges user config with defaults\n */\nfunction mergeConfig(config: MigrationGeneratorConfig): Required<MigrationGeneratorConfig> {\n return {\n ...DEFAULT_CONFIG,\n ...config,\n };\n}\n\n/**\n * Resolves the migration directory path\n */\nfunction resolveMigrationDir(config: MigrationGeneratorConfig): string {\n const workspaceRoot = config.workspaceRoot || process.cwd();\n\n if (path.isAbsolute(config.migrationDir)) {\n return config.migrationDir;\n }\n\n return path.join(workspaceRoot, config.migrationDir);\n}\n\n/**\n * Generates a timestamp for migration filename\n * Format: Unix timestamp in seconds (e.g., 1687801090)\n *\n * @param config - Optional configuration with custom timestamp generator\n * @returns Timestamp string\n */\nexport function generateTimestamp(config?: MigrationGeneratorConfig): string {\n if (config?.timestampGenerator) {\n return config.timestampGenerator();\n }\n return Math.floor(Date.now() / 1000).toString();\n}\n\n/**\n * Splits a SchemaDiff into individual collection operations\n * Each operation will generate a separate migration file\n *\n * @param diff - Schema diff containing all changes\n * @param baseTimestamp - Base timestamp for the first operation\n * @returns Array of collection operations\n */\nexport function splitDiffByCollection(diff: SchemaDiff, baseTimestamp: string): CollectionOperation[] {\n const operations: CollectionOperation[] = [];\n let currentTimestamp = parseInt(baseTimestamp, 10);\n\n // Split collectionsToCreate into individual operations\n for (const collection of diff.collectionsToCreate) {\n operations.push({\n type: \"create\",\n collection: collection,\n timestamp: currentTimestamp.toString(),\n });\n currentTimestamp += 1; // Increment by 1 second\n }\n\n // Split collectionsToModify into individual operations\n for (const modification of diff.collectionsToModify) {\n operations.push({\n type: \"modify\",\n collection: modification.collection,\n modifications: modification,\n timestamp: currentTimestamp.toString(),\n });\n currentTimestamp += 1; // Increment by 1 second\n }\n\n // Split collectionsToDelete into individual operations\n for (const collection of diff.collectionsToDelete) {\n operations.push({\n type: \"delete\",\n collection: collection.name || collection, // Handle both object and string\n timestamp: currentTimestamp.toString(),\n });\n currentTimestamp += 1; // Increment by 1 second\n }\n\n return operations;\n}\n\n/**\n * Generates migration filename for a collection operation\n * Format: {timestamp}_{operation}_{collection_name}.js\n *\n * @param operation - Collection operation\n * @returns Migration filename\n */\nexport function generateCollectionMigrationFilename(operation: CollectionOperation): string {\n const timestamp = operation.timestamp;\n const operationType = operation.type === \"modify\" ? \"updated\" : operation.type === \"create\" ? \"created\" : \"deleted\";\n\n // Get collection name\n let collectionName: string;\n if (typeof operation.collection === \"string\") {\n collectionName = operation.collection;\n } else {\n collectionName = operation.collection.name;\n }\n\n // Sanitize collection name for filename (replace spaces and special chars with underscores)\n const sanitizedName = collectionName.replace(/[^a-zA-Z0-9_]/g, \"_\").toLowerCase();\n\n return `${timestamp}_${operationType}_${sanitizedName}.js`;\n}\n\n/**\n * Increments a timestamp by 1 second\n * Ensures sequential ordering of migration files\n *\n * @param timestamp - Current timestamp string\n * @returns Incremented timestamp string\n */\nexport function incrementTimestamp(timestamp: string): string {\n const currentTimestamp = parseInt(timestamp, 10);\n return (currentTimestamp + 1).toString();\n}\n\n/**\n * Generates a human-readable description from the diff\n * Creates a concise summary of the main changes\n *\n * @param diff - Schema diff containing all changes\n * @returns Description string for filename\n */\nexport function generateMigrationDescription(diff: SchemaDiff): string {\n const parts: string[] = [];\n\n // Summarize collection changes\n if (diff.collectionsToCreate.length > 0) {\n if (diff.collectionsToCreate.length === 1) {\n parts.push(`created_${diff.collectionsToCreate[0].name}`);\n } else {\n parts.push(`created_${diff.collectionsToCreate.length}_collections`);\n }\n }\n\n if (diff.collectionsToDelete.length > 0) {\n if (diff.collectionsToDelete.length === 1) {\n parts.push(`deleted_${diff.collectionsToDelete[0].name}`);\n } else {\n parts.push(`deleted_${diff.collectionsToDelete.length}_collections`);\n }\n }\n\n if (diff.collectionsToModify.length > 0) {\n if (diff.collectionsToModify.length === 1) {\n parts.push(`updated_${diff.collectionsToModify[0].collection}`);\n } else {\n parts.push(`updated_${diff.collectionsToModify.length}_collections`);\n }\n }\n\n // Default description if no changes\n if (parts.length === 0) {\n return \"no_changes\";\n }\n\n // Join parts with underscores and limit length\n let description = parts.join(\"_\");\n\n // Truncate if too long (keep under 100 chars for filename)\n if (description.length > 80) {\n description = description.substring(0, 77) + \"...\";\n }\n\n return description;\n}\n\n/**\n * Generates the migration filename\n * Format: {timestamp}_{description}.js\n *\n * @param diff - Schema diff containing all changes\n * @param config - Optional configuration\n * @returns Migration filename\n */\nexport function generateMigrationFilename(diff: SchemaDiff, config?: MigrationGeneratorConfig): string {\n const timestamp = generateTimestamp(config);\n const description = generateMigrationDescription(diff);\n\n return `${timestamp}_${description}.js`;\n}\n\n/**\n * Creates the migration file structure with up and down functions\n *\n * @param upCode - Code for the up migration\n * @param downCode - Code for the down migration\n * @param config - Optional configuration with custom template\n * @returns Complete migration file content\n */\nexport function createMigrationFileStructure(\n upCode: string,\n downCode: string,\n config?: MigrationGeneratorConfig\n): string {\n const mergedConfig = config ? mergeConfig(config) : DEFAULT_CONFIG;\n let template = mergedConfig.template;\n\n // Replace placeholders\n template = template.replace(\"{{TYPES_PATH}}\", mergedConfig.typesPath);\n template = template.replace(\"{{UP_CODE}}\", upCode);\n template = template.replace(\"{{DOWN_CODE}}\", downCode);\n\n // Remove type reference if disabled\n if (!mergedConfig.includeTypeReference) {\n template = template.replace(/\\/\\/\\/ <reference path=\"[^\"]*\" \\/>\\n?/, \"\");\n }\n\n return template;\n}\n\n/**\n * Writes migration file to the specified directory\n * Creates directory if it doesn't exist\n *\n * @param migrationDir - Directory to write migration file\n * @param filename - Migration filename\n * @param content - Migration file content\n * @returns Full path to the created migration file\n */\nexport function writeMigrationFile(migrationDir: string, filename: string, content: string): string {\n try {\n // Ensure migration directory exists\n if (!fs.existsSync(migrationDir)) {\n try {\n fs.mkdirSync(migrationDir, { recursive: true });\n } catch (error) {\n const fsError = error as NodeJS.ErrnoException;\n if (fsError.code === \"EACCES\" || fsError.code === \"EPERM\") {\n throw new FileSystemError(\n `Permission denied creating migration directory. Check directory permissions.`,\n migrationDir,\n \"create\",\n fsError.code,\n error as Error\n );\n }\n throw new FileSystemError(\n `Failed to create migration directory: ${fsError.message}`,\n migrationDir,\n \"create\",\n fsError.code,\n error as Error\n );\n }\n }\n\n // Full path to migration file\n const filePath = path.join(migrationDir, filename);\n\n // Write migration file\n fs.writeFileSync(filePath, content, \"utf-8\");\n\n return filePath;\n } catch (error) {\n // If it's already a FileSystemError, re-throw it\n if (error instanceof FileSystemError) {\n throw error;\n }\n\n const fsError = error as NodeJS.ErrnoException;\n const filePath = path.join(migrationDir, filename);\n\n if (fsError.code === \"EACCES\" || fsError.code === \"EPERM\") {\n throw new FileSystemError(\n `Permission denied writing migration file. Check file and directory permissions.`,\n filePath,\n \"write\",\n fsError.code,\n error as Error\n );\n } else if (fsError.code === \"ENOSPC\") {\n throw new FileSystemError(\n `No space left on device when writing migration file.`,\n filePath,\n \"write\",\n fsError.code,\n error as Error\n );\n }\n\n throw new MigrationGenerationError(`Failed to write migration file: ${fsError.message}`, filePath, error as Error);\n }\n}\n\n/**\n * Formats a value for JavaScript code generation\n * Handles strings, numbers, booleans, null, arrays, and objects\n *\n * @param value - Value to format\n * @returns Formatted string representation\n */\nfunction formatValue(value: any): string {\n if (value === null || value === undefined) {\n return \"null\";\n }\n\n if (typeof value === \"string\") {\n // Use JSON.stringify to properly escape all special characters\n return JSON.stringify(value);\n }\n\n if (typeof value === \"number\" || typeof value === \"boolean\") {\n return String(value);\n }\n\n if (Array.isArray(value)) {\n // Use JSON.stringify for arrays to properly handle all special characters\n // Then format with spaces after commas to match expected test output\n return JSON.stringify(value).replace(/\",\"/g, '\", \"');\n }\n\n if (typeof value === \"object\") {\n const entries = Object.entries(value)\n .map(([k, v]) => `${k}: ${formatValue(v)}`)\n .join(\", \");\n return `{ ${entries} }`;\n }\n\n return String(value);\n}\n\n/**\n * Generates field definition object for collection creation\n * Creates the field configuration object used in Collection constructor\n *\n * @param field - Field definition\n * @param collectionIdMap - Map of collection names to their pre-generated IDs\n * @returns Field definition object as string\n */\nexport function generateFieldDefinitionObject(field: FieldDefinition, collectionIdMap?: Map<string, string>): string {\n const parts: string[] = [];\n\n // Add field name\n parts.push(` name: \"${field.name}\"`);\n\n // Add field type\n parts.push(` type: \"${field.type}\"`);\n\n // Add required flag\n parts.push(` required: ${field.required}`);\n\n // Add unique flag if present\n if (field.unique !== undefined) {\n parts.push(` unique: ${field.unique}`);\n }\n\n // Add explicit defaults for select fields\n if (field.type === \"select\") {\n // Always include maxSelect (default: 1)\n const maxSelect = field.options?.maxSelect ?? 1;\n parts.push(` maxSelect: ${maxSelect}`);\n\n // Always include values array (default: [])\n const values = field.options?.values ?? [];\n parts.push(` values: ${formatValue(values)}`);\n }\n\n // Add options if present (excluding select-specific options already handled)\n if (field.options && Object.keys(field.options).length > 0) {\n for (const [key, value] of Object.entries(field.options)) {\n // Skip select-specific options as they're handled above\n if (field.type === \"select\" && (key === \"maxSelect\" || key === \"values\")) {\n continue;\n }\n parts.push(` ${key}: ${formatValue(value)}`);\n }\n }\n\n // Add relation configuration if present\n if (field.relation) {\n // Use pre-generated collection ID from map if available\n // Otherwise fall back to runtime lookup (for existing collections not in the current diff)\n const isUsersCollection = field.relation.collection.toLowerCase() === \"users\";\n let collectionIdValue: string;\n\n if (isUsersCollection) {\n // Special case: users collection always uses the constant\n collectionIdValue = '\"_pb_users_auth_\"';\n } else if (collectionIdMap && collectionIdMap.has(field.relation.collection)) {\n // Use pre-generated ID from map\n collectionIdValue = `\"${collectionIdMap.get(field.relation.collection)}\"`;\n } else {\n // Fall back to runtime lookup for existing collections\n collectionIdValue = `app.findCollectionByNameOrId(\"${field.relation.collection}\").id`;\n }\n\n parts.push(` collectionId: ${collectionIdValue}`);\n\n // Always include maxSelect (default: 1)\n const maxSelect = field.relation.maxSelect ?? 1;\n parts.push(` maxSelect: ${maxSelect}`);\n\n // Always include minSelect (default: null)\n const minSelect = field.relation.minSelect ?? null;\n parts.push(` minSelect: ${minSelect}`);\n\n // Always include cascadeDelete (default: false)\n const cascadeDelete = field.relation.cascadeDelete ?? false;\n parts.push(` cascadeDelete: ${cascadeDelete}`);\n }\n\n return ` {\\n${parts.join(\",\\n\")},\\n }`;\n}\n\n/**\n * Generates fields array for collection creation\n *\n * @param fields - Array of field definitions\n * @param collectionIdMap - Map of collection names to their pre-generated IDs\n * @returns Fields array as string\n */\nexport function generateFieldsArray(fields: FieldDefinition[], collectionIdMap?: Map<string, string>): string {\n if (fields.length === 0) {\n return \"[]\";\n }\n\n const fieldObjects = fields.map((field) => generateFieldDefinitionObject(field, collectionIdMap));\n return `[\\n${fieldObjects.join(\",\\n\")},\\n ]`;\n}\n\n/**\n * Generates collection rules object\n *\n * @param rules - Collection rules\n * @returns Rules configuration as string\n */\nexport function generateCollectionRules(rules?: CollectionSchema[\"rules\"]): string {\n if (!rules) {\n return \"\";\n }\n\n const parts: string[] = [];\n\n if (rules.listRule !== undefined) {\n parts.push(`listRule: ${formatValue(rules.listRule)}`);\n }\n\n if (rules.viewRule !== undefined) {\n parts.push(`viewRule: ${formatValue(rules.viewRule)}`);\n }\n\n if (rules.createRule !== undefined) {\n parts.push(`createRule: ${formatValue(rules.createRule)}`);\n }\n\n if (rules.updateRule !== undefined) {\n parts.push(`updateRule: ${formatValue(rules.updateRule)}`);\n }\n\n if (rules.deleteRule !== undefined) {\n parts.push(`deleteRule: ${formatValue(rules.deleteRule)}`);\n }\n\n if (rules.manageRule !== undefined) {\n parts.push(`manageRule: ${formatValue(rules.manageRule)}`);\n }\n\n return parts.join(\",\\n \");\n}\n\n/**\n * Generates collection permissions object\n * Permissions are the same as rules but extracted from schema metadata\n *\n * @param permissions - Collection permissions\n * @returns Permissions configuration as string\n */\nexport function generateCollectionPermissions(permissions?: CollectionSchema[\"permissions\"]): string {\n if (!permissions) {\n return \"\";\n }\n\n const parts: string[] = [];\n\n if (permissions.listRule !== undefined) {\n parts.push(`listRule: ${formatValue(permissions.listRule)}`);\n }\n\n if (permissions.viewRule !== undefined) {\n parts.push(`viewRule: ${formatValue(permissions.viewRule)}`);\n }\n\n if (permissions.createRule !== undefined) {\n parts.push(`createRule: ${formatValue(permissions.createRule)}`);\n }\n\n if (permissions.updateRule !== undefined) {\n parts.push(`updateRule: ${formatValue(permissions.updateRule)}`);\n }\n\n if (permissions.deleteRule !== undefined) {\n parts.push(`deleteRule: ${formatValue(permissions.deleteRule)}`);\n }\n\n if (permissions.manageRule !== undefined) {\n parts.push(`manageRule: ${formatValue(permissions.manageRule)}`);\n }\n\n return parts.join(\",\\n \");\n}\n\n/**\n * Generates indexes array for collection creation\n *\n * @param indexes - Array of index definitions\n * @returns Indexes array as string\n */\nexport function generateIndexesArray(indexes?: string[]): string {\n if (!indexes || indexes.length === 0) {\n return \"[]\";\n }\n\n const indexStrings = indexes.map((idx) => JSON.stringify(idx));\n return `[\\n ${indexStrings.join(\",\\n \")},\\n ]`;\n}\n\n/**\n * Generates Collection constructor call for creating a new collection\n *\n * @param collection - Collection schema\n * @param varName - Variable name to use for the collection (default: 'collection')\n * @returns JavaScript code for creating the collection\n */\n/**\n * Generates system fields that are required for all PocketBase collections\n * These fields (id, created, updated) must be explicitly included in migrations\n *\n * @returns Array of system field definitions\n */\nfunction getSystemFields(): FieldDefinition[] {\n return [\n // id field - primary key, auto-generated\n {\n name: \"id\",\n type: \"text\",\n required: true,\n options: {\n autogeneratePattern: \"[a-z0-9]{15}\",\n hidden: false,\n id: \"text3208210256\",\n max: 15,\n min: 15,\n pattern: \"^[a-z0-9]+$\",\n presentable: false,\n primaryKey: true,\n system: true,\n },\n },\n // created field - autodate, set on creation\n {\n name: \"created\",\n type: \"autodate\",\n required: true,\n options: {\n hidden: false,\n id: \"autodate2990389176\",\n onCreate: true,\n onUpdate: false,\n presentable: false,\n system: false,\n },\n },\n // updated field - autodate, set on creation and update\n {\n name: \"updated\",\n type: \"autodate\",\n required: true,\n options: {\n hidden: false,\n id: \"autodate3332085495\",\n onCreate: true,\n onUpdate: true,\n presentable: false,\n system: false,\n },\n },\n ];\n}\n\nexport function generateCollectionCreation(\n collection: CollectionSchema,\n varName: string = \"collection\",\n isLast: boolean = false,\n collectionIdMap?: Map<string, string>\n): string {\n const lines: string[] = [];\n\n lines.push(` const ${varName} = new Collection({`);\n if (collection.id) {\n lines.push(` id: ${formatValue(collection.id)},`);\n }\n lines.push(` name: \"${collection.name}\",`);\n lines.push(` type: \"${collection.type}\",`);\n\n // Add permissions (preferred) or rules\n // Permissions take precedence if both are defined\n const permissionsCode = generateCollectionPermissions(collection.permissions);\n const rulesCode = generateCollectionRules(collection.rules);\n\n if (permissionsCode) {\n lines.push(` ${permissionsCode},`);\n } else if (rulesCode) {\n lines.push(` ${rulesCode},`);\n }\n\n // Prepend system fields (id, created, updated) to user-defined fields\n // These fields are required by PocketBase and must be explicitly included in migrations\n const systemFields = getSystemFields();\n const allFields = [...systemFields, ...collection.fields];\n\n // Add fields\n lines.push(` fields: ${generateFieldsArray(allFields, collectionIdMap)},`);\n\n // Add indexes\n lines.push(` indexes: ${generateIndexesArray(collection.indexes)},`);\n\n lines.push(` });`);\n lines.push(``);\n lines.push(isLast ? ` return app.save(${varName});` : ` app.save(${varName});`);\n\n return lines.join(\"\\n\");\n}\n\n/**\n * Gets the appropriate Field constructor name for a field type\n *\n * @param fieldType - PocketBase field type\n * @returns Field constructor name\n */\nfunction getFieldConstructorName(fieldType: string): string {\n const constructorMap: Record<string, string> = {\n text: \"TextField\",\n email: \"EmailField\",\n url: \"URLField\",\n number: \"NumberField\",\n bool: \"BoolField\",\n date: \"DateField\",\n select: \"SelectField\",\n relation: \"RelationField\",\n file: \"FileField\",\n json: \"JSONField\",\n };\n\n return constructorMap[fieldType] || \"TextField\";\n}\n\n/**\n * Generates field constructor options object\n *\n * @param field - Field definition\n * @param collectionIdMap - Map of collection names to their pre-generated IDs\n * @returns Options object as string\n */\nfunction generateFieldConstructorOptions(field: FieldDefinition, collectionIdMap?: Map<string, string>): string {\n const parts: string[] = [];\n\n // Add field name\n parts.push(` name: \"${field.name}\"`);\n\n // Add required flag\n parts.push(` required: ${field.required}`);\n\n // Add unique flag if present\n if (field.unique !== undefined) {\n parts.push(` unique: ${field.unique}`);\n }\n\n // Add explicit defaults for select fields\n if (field.type === \"select\") {\n // Always include maxSelect (default: 1)\n const maxSelect = field.options?.maxSelect ?? 1;\n parts.push(` maxSelect: ${maxSelect}`);\n\n // Always include values array (default: [])\n const values = field.options?.values ?? [];\n parts.push(` values: ${formatValue(values)}`);\n }\n\n // Add options if present (excluding select-specific options already handled)\n if (field.options && Object.keys(field.options).length > 0) {\n for (const [key, value] of Object.entries(field.options)) {\n // Skip select-specific options as they're handled above\n if (field.type === \"select\" && (key === \"maxSelect\" || key === \"values\")) {\n continue;\n }\n // Convert noDecimal to onlyInt for number fields (PocketBase uses onlyInt)\n if (field.type === \"number\" && key === \"noDecimal\") {\n parts.push(` onlyInt: ${formatValue(value)}`);\n } else {\n parts.push(` ${key}: ${formatValue(value)}`);\n }\n }\n }\n\n // Add relation-specific options\n if (field.relation && field.type === \"relation\") {\n // Use pre-generated collection ID from map if available\n // Otherwise fall back to runtime lookup (for existing collections not in the current diff)\n const isUsersCollection = field.relation.collection.toLowerCase() === \"users\";\n let collectionIdValue: string;\n\n if (isUsersCollection) {\n // Special case: users collection always uses the constant\n collectionIdValue = '\"_pb_users_auth_\"';\n } else if (collectionIdMap && collectionIdMap.has(field.relation.collection)) {\n // Use pre-generated ID from map\n collectionIdValue = `\"${collectionIdMap.get(field.relation.collection)}\"`;\n } else {\n // Fall back to runtime lookup for existing collections\n collectionIdValue = `app.findCollectionByNameOrId(\"${field.relation.collection}\").id`;\n }\n\n parts.push(` collectionId: ${collectionIdValue}`);\n\n // Always include maxSelect (default: 1)\n const maxSelect = field.relation.maxSelect ?? 1;\n parts.push(` maxSelect: ${maxSelect}`);\n\n // Always include minSelect (default: null)\n const minSelect = field.relation.minSelect ?? null;\n parts.push(` minSelect: ${minSelect}`);\n\n // Always include cascadeDelete (default: false)\n const cascadeDelete = field.relation.cascadeDelete ?? false;\n parts.push(` cascadeDelete: ${cascadeDelete}`);\n }\n\n return parts.join(\",\\n\");\n}\n\n/**\n * Generates code for adding a field to an existing collection\n * Uses the appropriate Field constructor based on field type\n *\n * @param collectionName - Name of the collection\n * @param field - Field definition to add\n * @param varName - Variable name to use for the collection (default: auto-generated)\n * @param isLast - Whether this is the last operation (will return the result)\n * @param collectionIdMap - Map of collection names to their pre-generated IDs\n * @returns JavaScript code for adding the field\n */\nexport function generateFieldAddition(\n collectionName: string,\n field: FieldDefinition,\n varName?: string,\n isLast: boolean = false,\n collectionIdMap?: Map<string, string>\n): string {\n const lines: string[] = [];\n const constructorName = getFieldConstructorName(field.type);\n const collectionVar = varName || `collection_${collectionName}_${field.name}`;\n\n lines.push(` const ${collectionVar} = app.findCollectionByNameOrId(\"${collectionName}\");`);\n lines.push(``);\n lines.push(` ${collectionVar}.fields.add(new ${constructorName}({`);\n lines.push(generateFieldConstructorOptions(field, collectionIdMap));\n lines.push(` }));`);\n lines.push(``);\n lines.push(isLast ? ` return app.save(${collectionVar});` : ` app.save(${collectionVar});`);\n\n return lines.join(\"\\n\");\n}\n\n/**\n * Generates code for modifying an existing field\n * Updates field properties based on detected changes\n *\n * @param collectionName - Name of the collection\n * @param modification - Field modification details\n * @param varName - Variable name to use for the collection (default: auto-generated)\n * @param isLast - Whether this is the last operation (will return the result)\n * @returns JavaScript code for modifying the field\n */\nexport function generateFieldModification(\n collectionName: string,\n modification: FieldModification,\n varName?: string,\n isLast: boolean = false\n): string {\n const lines: string[] = [];\n const collectionVar = varName || `collection_${collectionName}_${modification.fieldName}`;\n const fieldVar = `${collectionVar}_field`;\n\n lines.push(` const ${collectionVar} = app.findCollectionByNameOrId(\"${collectionName}\");`);\n lines.push(` const ${fieldVar} = ${collectionVar}.fields.getByName(\"${modification.fieldName}\");`);\n lines.push(``);\n\n // Apply each change\n for (const change of modification.changes) {\n if (change.property.startsWith(\"options.\")) {\n // Handle nested options properties\n const optionKey = change.property.replace(\"options.\", \"\");\n // In PocketBase, field properties are set directly on the field, not in an options object\n lines.push(` ${fieldVar}.${optionKey} = ${formatValue(change.newValue)};`);\n } else if (change.property.startsWith(\"relation.\")) {\n // Handle nested relation properties\n const relationKey = change.property.replace(\"relation.\", \"\");\n\n if (relationKey === \"collection\") {\n // Special handling for collection ID\n // Use case-insensitive check for \"users\" to handle both explicit and implicit relation definitions\n const isUsersCollection = String(change.newValue).toLowerCase() === \"users\";\n const collectionIdValue = isUsersCollection\n ? '\"_pb_users_auth_\"'\n : `app.findCollectionByNameOrId(\"${change.newValue}\").id`;\n lines.push(` ${fieldVar}.collectionId = ${collectionIdValue};`);\n } else {\n lines.push(` ${fieldVar}.${relationKey} = ${formatValue(change.newValue)};`);\n }\n } else {\n // Handle top-level properties\n lines.push(` ${fieldVar}.${change.property} = ${formatValue(change.newValue)};`);\n }\n }\n\n lines.push(``);\n lines.push(isLast ? ` return app.save(${collectionVar});` : ` app.save(${collectionVar});`);\n\n return lines.join(\"\\n\");\n}\n\n/**\n * Generates code for deleting a field from a collection\n *\n * @param collectionName - Name of the collection\n * @param fieldName - Name of the field to delete\n * @param varName - Variable name to use for the collection (default: auto-generated)\n * @param isLast - Whether this is the last operation (will return the result)\n * @returns JavaScript code for deleting the field\n */\nexport function generateFieldDeletion(\n collectionName: string,\n fieldName: string,\n varName?: string,\n isLast: boolean = false\n): string {\n const lines: string[] = [];\n const collectionVar = varName || `collection_${collectionName}_${fieldName}`;\n const fieldVar = `${collectionVar}_field`;\n\n lines.push(` const ${collectionVar} = app.findCollectionByNameOrId(\"${collectionName}\");`);\n lines.push(` const ${fieldVar} = ${collectionVar}.fields.getByName(\"${fieldName}\");`);\n lines.push(``);\n lines.push(` ${collectionVar}.fields.remove(${fieldVar}.id);`);\n lines.push(``);\n lines.push(isLast ? ` return app.save(${collectionVar});` : ` app.save(${collectionVar});`);\n\n return lines.join(\"\\n\");\n}\n\n/**\n * Generates code for adding an index to a collection\n *\n * @param collectionName - Name of the collection\n * @param index - Index SQL statement\n * @param varName - Variable name to use for the collection (default: auto-generated)\n * @param isLast - Whether this is the last operation (will return the result)\n * @returns JavaScript code for adding the index\n */\nfunction generateIndexAddition(\n collectionName: string,\n index: string,\n varName?: string,\n isLast: boolean = false\n): string {\n const lines: string[] = [];\n const collectionVar = varName || `collection_${collectionName}_idx`;\n\n lines.push(` const ${collectionVar} = app.findCollectionByNameOrId(\"${collectionName}\");`);\n lines.push(` ${collectionVar}.indexes.push(${JSON.stringify(index)});`);\n lines.push(isLast ? ` return app.save(${collectionVar});` : ` app.save(${collectionVar});`);\n\n return lines.join(\"\\n\");\n}\n\n/**\n * Generates code for removing an index from a collection\n *\n * @param collectionName - Name of the collection\n * @param index - Index SQL statement\n * @param varName - Variable name to use for the collection (default: auto-generated)\n * @param isLast - Whether this is the last operation (will return the result)\n * @returns JavaScript code for removing the index\n */\nfunction generateIndexRemoval(\n collectionName: string,\n index: string,\n varName?: string,\n isLast: boolean = false\n): string {\n const lines: string[] = [];\n const collectionVar = varName || `collection_${collectionName}_idx`;\n const indexVar = `${collectionVar}_indexToRemove`;\n\n lines.push(` const ${collectionVar} = app.findCollectionByNameOrId(\"${collectionName}\");`);\n lines.push(` const ${indexVar} = ${collectionVar}.indexes.findIndex(idx => idx === ${JSON.stringify(index)});`);\n lines.push(` if (${indexVar} !== -1) {`);\n lines.push(` ${collectionVar}.indexes.splice(${indexVar}, 1);`);\n lines.push(` }`);\n lines.push(isLast ? ` return app.save(${collectionVar});` : ` app.save(${collectionVar});`);\n\n return lines.join(\"\\n\");\n}\n\n/**\n * Generates code for updating collection rules\n *\n * @param collectionName - Name of the collection\n * @param ruleType - Type of rule to update\n * @param newValue - New rule value\n * @param varName - Variable name to use for the collection (default: auto-generated)\n * @param isLast - Whether this is the last operation (will return the result)\n * @returns JavaScript code for updating the rule\n */\nfunction generateRuleUpdate(\n collectionName: string,\n ruleType: string,\n newValue: string | null,\n varName?: string,\n isLast: boolean = false\n): string {\n const lines: string[] = [];\n const collectionVar = varName || `collection_${collectionName}_${ruleType}`;\n\n lines.push(` const ${collectionVar} = app.findCollectionByNameOrId(\"${collectionName}\");`);\n lines.push(` ${collectionVar}.${ruleType} = ${formatValue(newValue)};`);\n lines.push(isLast ? ` return app.save(${collectionVar});` : ` app.save(${collectionVar});`);\n\n return lines.join(\"\\n\");\n}\n\n/**\n * Generates code for updating collection permissions\n * Handles permission rule updates including manageRule for auth collections\n *\n * @param collectionName - Name of the collection\n * @param ruleType - Type of permission rule to update\n * @param newValue - New permission rule value\n * @param varName - Variable name to use for the collection (default: auto-generated)\n * @param isLast - Whether this is the last operation (will return the result)\n * @returns JavaScript code for updating the permission\n */\nexport function generatePermissionUpdate(\n collectionName: string,\n ruleType: string,\n newValue: string | null,\n varName?: string,\n isLast: boolean = false\n): string {\n const lines: string[] = [];\n const collectionVar = varName || `collection_${collectionName}_${ruleType}`;\n\n lines.push(` const ${collectionVar} = app.findCollectionByNameOrId(\"${collectionName}\");`);\n lines.push(` ${collectionVar}.${ruleType} = ${formatValue(newValue)};`);\n lines.push(isLast ? ` return app.save(${collectionVar});` : ` app.save(${collectionVar});`);\n\n return lines.join(\"\\n\");\n}\n\n/**\n * Generates code for deleting a collection\n *\n * @param collectionName - Name of the collection to delete\n * @param varName - Variable name to use for the collection (default: 'collection')\n * @param isLast - Whether this is the last operation (will return the result)\n * @returns JavaScript code for deleting the collection\n */\nfunction generateCollectionDeletion(\n collectionName: string,\n varName: string = \"collection\",\n isLast: boolean = false\n): string {\n const lines: string[] = [];\n\n lines.push(` const ${varName} = app.findCollectionByNameOrId(\"${collectionName}\");`);\n lines.push(isLast ? ` return app.delete(${varName});` : ` app.delete(${varName});`);\n\n return lines.join(\"\\n\");\n}\n\n/**\n * Generates the up migration code for a single collection operation\n * Handles create, modify, and delete operations\n *\n * @param operation - Collection operation to generate migration for\n * @param collectionIdMap - Map of collection names to their pre-generated IDs\n * @returns JavaScript code for up migration\n */\nexport function generateOperationUpMigration(\n operation: CollectionOperation,\n collectionIdMap: Map<string, string>\n): string {\n const lines: string[] = [];\n\n if (operation.type === \"create\") {\n // Handle collection creation\n const collection = operation.collection as CollectionSchema;\n const varName = `collection_${collection.name}`;\n lines.push(generateCollectionCreation(collection, varName, true, collectionIdMap));\n } else if (operation.type === \"modify\") {\n // Handle collection modification\n const modification = operation.modifications!;\n const collectionName =\n typeof operation.collection === \"string\"\n ? operation.collection\n : (operation.collection?.name ?? modification.collection);\n\n let operationCount = 0;\n const totalOperations =\n modification.fieldsToAdd.length +\n modification.fieldsToModify.length +\n modification.fieldsToRemove.length +\n modification.indexesToAdd.length +\n modification.indexesToRemove.length +\n modification.rulesToUpdate.length +\n modification.permissionsToUpdate.length;\n\n // Add new fields\n for (const field of modification.fieldsToAdd) {\n operationCount++;\n const varName = `collection_${collectionName}_add_${field.name}`;\n const isLast = operationCount === totalOperations;\n lines.push(generateFieldAddition(collectionName, field, varName, isLast, collectionIdMap));\n if (!isLast) lines.push(\"\");\n }\n\n // Modify existing fields\n for (const fieldMod of modification.fieldsToModify) {\n operationCount++;\n const varName = `collection_${collectionName}_modify_${fieldMod.fieldName}`;\n const isLast = operationCount === totalOperations;\n lines.push(generateFieldModification(collectionName, fieldMod, varName, isLast));\n if (!isLast) lines.push(\"\");\n }\n\n // Remove fields\n for (const field of modification.fieldsToRemove) {\n operationCount++;\n const varName = `collection_${collectionName}_remove_${field.name}`;\n const isLast = operationCount === totalOperations;\n lines.push(generateFieldDeletion(collectionName, field.name, varName, isLast));\n if (!isLast) lines.push(\"\");\n }\n\n // Add indexes\n for (let i = 0; i < modification.indexesToAdd.length; i++) {\n operationCount++;\n const index = modification.indexesToAdd[i];\n const varName = `collection_${collectionName}_addidx_${i}`;\n const isLast = operationCount === totalOperations;\n lines.push(generateIndexAddition(collectionName, index, varName, isLast));\n if (!isLast) lines.push(\"\");\n }\n\n // Remove indexes\n for (let i = 0; i < modification.indexesToRemove.length; i++) {\n operationCount++;\n const index = modification.indexesToRemove[i];\n const varName = `collection_${collectionName}_rmidx_${i}`;\n const isLast = operationCount === totalOperations;\n lines.push(generateIndexRemoval(collectionName, index, varName, isLast));\n if (!isLast) lines.push(\"\");\n }\n\n // Update permissions (preferred) or rules (fallback)\n if (modification.permissionsToUpdate && modification.permissionsToUpdate.length > 0) {\n for (const permission of modification.permissionsToUpdate) {\n operationCount++;\n const varName = `collection_${collectionName}_perm_${permission.ruleType}`;\n const isLast = operationCount === totalOperations;\n lines.push(generatePermissionUpdate(collectionName, permission.ruleType, permission.newValue, varName, isLast));\n if (!isLast) lines.push(\"\");\n }\n } else if (modification.rulesToUpdate.length > 0) {\n for (const rule of modification.rulesToUpdate) {\n operationCount++;\n const varName = `collection_${collectionName}_rule_${rule.ruleType}`;\n const isLast = operationCount === totalOperations;\n lines.push(generateRuleUpdate(collectionName, rule.ruleType, rule.newValue, varName, isLast));\n if (!isLast) lines.push(\"\");\n }\n }\n } else if (operation.type === \"delete\") {\n // Handle collection deletion\n const collectionName = typeof operation.collection === \"string\" ? operation.collection : operation.collection.name;\n const varName = `collection_${collectionName}`;\n lines.push(generateCollectionDeletion(collectionName, varName, true));\n }\n\n let code = lines.join(\"\\n\");\n\n // Find the last app.save() or app.delete() call and make it return the result\n // Match app.save(...) or app.delete(...) at the end of lines (not in comments or strings)\n const savePattern = /^(\\s*)app\\.save\\((\\w+)\\);$/gm;\n const deletePattern = /^(\\s*)app\\.delete\\((\\w+)\\);$/gm;\n\n const saveMatches = [...code.matchAll(savePattern)];\n const deleteMatches = [...code.matchAll(deletePattern)];\n\n // Combine all matches and find the last one by position\n const allMatches = [\n ...saveMatches.map((m) => ({ match: m, type: \"save\", index: m.index! })),\n ...deleteMatches.map((m) => ({ match: m, type: \"delete\", index: m.index! })),\n ].sort((a, b) => b.index - a.index); // Sort descending to get last match first\n\n if (allMatches.length > 0) {\n const lastMatch = allMatches[0];\n if (lastMatch.type === \"save\") {\n code =\n code.substring(0, lastMatch.match.index!) +\n lastMatch.match[1] +\n \"return app.save(\" +\n lastMatch.match[2] +\n \");\" +\n code.substring(lastMatch.match.index! + lastMatch.match[0].length);\n } else {\n code =\n code.substring(0, lastMatch.match.index!) +\n lastMatch.match[1] +\n \"return app.delete(\" +\n lastMatch.match[2] +\n \");\" +\n code.substring(lastMatch.match.index! + lastMatch.match[0].length);\n }\n }\n\n return code;\n}\n\n/**\n * Generates the down migration code for a single collection operation\n * Reverts the operation (inverse of up migration)\n *\n * @param operation - Collection operation to generate rollback for\n * @param collectionIdMap - Map of collection names to their pre-generated IDs\n * @returns JavaScript code for down migration\n */\nexport function generateOperationDownMigration(\n operation: CollectionOperation,\n collectionIdMap: Map<string, string>\n): string {\n const lines: string[] = [];\n\n if (operation.type === \"create\") {\n // Rollback: delete the created collection\n const collection = operation.collection as CollectionSchema;\n const varName = `collection_${collection.name}`;\n lines.push(generateCollectionDeletion(collection.name, varName, true));\n } else if (operation.type === \"modify\") {\n // Rollback: revert all modifications\n const modification = operation.modifications!;\n const collectionName =\n typeof operation.collection === \"string\"\n ? operation.collection\n : (operation.collection?.name ?? modification.collection);\n\n let operationCount = 0;\n const totalOperations =\n modification.fieldsToAdd.length +\n modification.fieldsToModify.length +\n modification.fieldsToRemove.length +\n modification.indexesToAdd.length +\n modification.indexesToRemove.length +\n modification.rulesToUpdate.length +\n modification.permissionsToUpdate.length;\n\n // Revert permissions (preferred) or rules (fallback)\n if (modification.permissionsToUpdate && modification.permissionsToUpdate.length > 0) {\n for (const permission of modification.permissionsToUpdate) {\n operationCount++;\n const varName = `collection_${collectionName}_revert_perm_${permission.ruleType}`;\n const isLast = operationCount === totalOperations;\n lines.push(generatePermissionUpdate(collectionName, permission.ruleType, permission.oldValue, varName, isLast));\n if (!isLast) lines.push(\"\");\n }\n } else if (modification.rulesToUpdate.length > 0) {\n for (const rule of modification.rulesToUpdate) {\n operationCount++;\n const varName = `collection_${collectionName}_revert_rule_${rule.ruleType}`;\n const isLast = operationCount === totalOperations;\n lines.push(generateRuleUpdate(collectionName, rule.ruleType, rule.oldValue, varName, isLast));\n if (!isLast) lines.push(\"\");\n }\n }\n\n // Revert index removals (add them back)\n for (let i = 0; i < modification.indexesToRemove.length; i++) {\n operationCount++;\n const index = modification.indexesToRemove[i];\n const varName = `collection_${collectionName}_restore_idx_${i}`;\n const isLast = operationCount === totalOperations;\n lines.push(generateIndexAddition(collectionName, index, varName, isLast));\n if (!isLast) lines.push(\"\");\n }\n\n // Revert index additions (remove them)\n for (let i = 0; i < modification.indexesToAdd.length; i++) {\n operationCount++;\n const index = modification.indexesToAdd[i];\n const varName = `collection_${collectionName}_revert_idx_${i}`;\n const isLast = operationCount === totalOperations;\n lines.push(generateIndexRemoval(collectionName, index, varName, isLast));\n if (!isLast) lines.push(\"\");\n }\n\n // Revert field removals (add them back)\n for (const field of modification.fieldsToRemove) {\n operationCount++;\n const varName = `collection_${collectionName}_restore_${field.name}`;\n const isLast = operationCount === totalOperations;\n lines.push(generateFieldAddition(collectionName, field, varName, isLast, collectionIdMap));\n if (!isLast) lines.push(\"\");\n }\n\n // Revert field modifications\n for (const fieldMod of modification.fieldsToModify) {\n operationCount++;\n // Create a reverse modification\n const reverseChanges = fieldMod.changes.map((change) => ({\n property: change.property,\n oldValue: change.newValue,\n newValue: change.oldValue,\n }));\n\n const reverseMod: FieldModification = {\n fieldName: fieldMod.fieldName,\n currentDefinition: fieldMod.newDefinition,\n newDefinition: fieldMod.currentDefinition,\n changes: reverseChanges,\n };\n\n const varName = `collection_${collectionName}_revert_${fieldMod.fieldName}`;\n const isLast = operationCount === totalOperations;\n lines.push(generateFieldModification(collectionName, reverseMod, varName, isLast));\n if (!isLast) lines.push(\"\");\n }\n\n // Revert field additions (remove them)\n for (const field of modification.fieldsToAdd) {\n operationCount++;\n const varName = `collection_${collectionName}_revert_add_${field.name}`;\n const isLast = operationCount === totalOperations;\n lines.push(generateFieldDeletion(collectionName, field.name, varName, isLast));\n if (!isLast) lines.push(\"\");\n }\n } else if (operation.type === \"delete\") {\n // Rollback: recreate the deleted collection\n const collection = operation.collection;\n if (typeof collection !== \"string\") {\n const varName = `collection_${collection.name}`;\n lines.push(generateCollectionCreation(collection, varName, true, collectionIdMap));\n }\n }\n\n let code = lines.join(\"\\n\");\n\n // Find the last app.save() or app.delete() call and make it return the result\n // Match app.save(...) or app.delete(...) at the end of lines (not in comments or strings)\n const savePattern = /^(\\s*)app\\.save\\((\\w+)\\);$/gm;\n const deletePattern = /^(\\s*)app\\.delete\\((\\w+)\\);$/gm;\n\n const saveMatches = [...code.matchAll(savePattern)];\n const deleteMatches = [...code.matchAll(deletePattern)];\n\n // Combine all matches and find the last one by position\n const allMatches = [\n ...saveMatches.map((m) => ({ match: m, type: \"save\", index: m.index! })),\n ...deleteMatches.map((m) => ({ match: m, type: \"delete\", index: m.index! })),\n ].sort((a, b) => b.index - a.index); // Sort descending to get last match first\n\n if (allMatches.length > 0) {\n const lastMatch = allMatches[0];\n if (lastMatch.type === \"save\") {\n code =\n code.substring(0, lastMatch.match.index!) +\n lastMatch.match[1] +\n \"return app.save(\" +\n lastMatch.match[2] +\n \");\" +\n code.substring(lastMatch.match.index! + lastMatch.match[0].length);\n } else {\n code =\n code.substring(0, lastMatch.match.index!) +\n lastMatch.match[1] +\n \"return app.delete(\" +\n lastMatch.match[2] +\n \");\" +\n code.substring(lastMatch.match.index! + lastMatch.match[0].length);\n }\n }\n\n return code;\n}\n\n/**\n * Generates the up migration function code\n * Applies all changes from the diff in the correct order\n *\n * @param diff - Schema diff containing all changes\n * @returns JavaScript code for up migration\n */\nexport function generateUpMigration(diff: SchemaDiff): string {\n const lines: string[] = [];\n\n // Add comment header\n lines.push(` // UP MIGRATION`);\n lines.push(``);\n\n // Build collection ID map from collections being created\n // This map will be used to resolve relation field references\n const collectionIdMap = new Map<string, string>();\n for (const collection of diff.collectionsToCreate) {\n if (collection.id) {\n collectionIdMap.set(collection.name, collection.id);\n }\n }\n\n // 1. Create new collections\n if (diff.collectionsToCreate.length > 0) {\n lines.push(` // Create new collections`);\n for (let i = 0; i < diff.collectionsToCreate.length; i++) {\n const collection = diff.collectionsToCreate[i];\n const varName = `collection_${collection.name}_create`;\n lines.push(generateCollectionCreation(collection, varName, false, collectionIdMap));\n lines.push(``);\n }\n }\n\n // 2. Modify existing collections\n if (diff.collectionsToModify.length > 0) {\n lines.push(` // Modify existing collections`);\n for (const modification of diff.collectionsToModify) {\n const collectionName = modification.collection;\n // Add new fields\n if (modification.fieldsToAdd.length > 0) {\n lines.push(` // Add fields to ${collectionName}`);\n for (const field of modification.fieldsToAdd) {\n const varName = `collection_${collectionName}_add_${field.name}`;\n lines.push(generateFieldAddition(collectionName, field, varName, false, collectionIdMap));\n lines.push(``);\n }\n }\n\n // Modify existing fields\n if (modification.fieldsToModify.length > 0) {\n lines.push(` // Modify fields in ${collectionName}`);\n for (const fieldMod of modification.fieldsToModify) {\n const varName = `collection_${collectionName}_modify_${fieldMod.fieldName}`;\n lines.push(generateFieldModification(collectionName, fieldMod, varName));\n lines.push(``);\n }\n }\n\n // Remove fields\n if (modification.fieldsToRemove.length > 0) {\n lines.push(` // Remove fields from ${collectionName}`);\n for (const field of modification.fieldsToRemove) {\n const varName = `collection_${collectionName}_remove_${field.name}`;\n lines.push(generateFieldDeletion(collectionName, field.name, varName));\n lines.push(``);\n }\n }\n\n // Add indexes\n if (modification.indexesToAdd.length > 0) {\n lines.push(` // Add indexes to ${collectionName}`);\n for (let i = 0; i < modification.indexesToAdd.length; i++) {\n const index = modification.indexesToAdd[i];\n const varName = `collection_${collectionName}_addidx_${i}`;\n lines.push(generateIndexAddition(collectionName, index, varName));\n lines.push(``);\n }\n }\n\n // Remove indexes\n if (modification.indexesToRemove.length > 0) {\n lines.push(` // Remove indexes from ${collectionName}`);\n for (let i = 0; i < modification.indexesToRemove.length; i++) {\n const index = modification.indexesToRemove[i];\n const varName = `collection_${collectionName}_rmidx_${i}`;\n lines.push(generateIndexRemoval(collectionName, index, varName));\n lines.push(``);\n }\n }\n\n // Update permissions (preferred) or rules (fallback)\n if (modification.permissionsToUpdate && modification.permissionsToUpdate.length > 0) {\n lines.push(` // Update permissions for ${collectionName}`);\n for (const permission of modification.permissionsToUpdate) {\n const varName = `collection_${collectionName}_perm_${permission.ruleType}`;\n lines.push(generatePermissionUpdate(collectionName, permission.ruleType, permission.newValue, varName));\n lines.push(``);\n }\n } else if (modification.rulesToUpdate.length > 0) {\n lines.push(` // Update rules for ${collectionName}`);\n for (const rule of modification.rulesToUpdate) {\n const varName = `collection_${collectionName}_rule_${rule.ruleType}`;\n lines.push(generateRuleUpdate(collectionName, rule.ruleType, rule.newValue, varName));\n lines.push(``);\n }\n }\n }\n }\n\n // 3. Delete collections\n if (diff.collectionsToDelete.length > 0) {\n lines.push(` // Delete collections`);\n for (let i = 0; i < diff.collectionsToDelete.length; i++) {\n const collection = diff.collectionsToDelete[i];\n const varName = `collection_${collection.name}_delete`;\n lines.push(generateCollectionDeletion(collection.name, varName));\n lines.push(``);\n }\n }\n\n // If no changes, add a comment\n if (lines.length === 2) {\n lines.push(` // No changes detected`);\n lines.push(``);\n }\n\n let code = lines.join(\"\\n\");\n\n // Find the last app.save() or app.delete() call and make it return the result\n // Match app.save(...) or app.delete(...) at the end of lines (not in comments or strings)\n const savePattern = /^(\\s*)app\\.save\\((\\w+)\\);$/gm;\n const deletePattern = /^(\\s*)app\\.delete\\((\\w+)\\);$/gm;\n\n const saveMatches = [...code.matchAll(savePattern)];\n const deleteMatches = [...code.matchAll(deletePattern)];\n\n // Combine all matches and find the last one by position\n const allMatches = [\n ...saveMatches.map((m) => ({ match: m, type: \"save\", index: m.index! })),\n ...deleteMatches.map((m) => ({ match: m, type: \"delete\", index: m.index! })),\n ].sort((a, b) => b.index - a.index); // Sort descending to get last match first\n\n if (allMatches.length > 0) {\n const lastMatch = allMatches[0];\n if (lastMatch.type === \"save\") {\n code =\n code.substring(0, lastMatch.match.index!) +\n lastMatch.match[1] +\n \"return app.save(\" +\n lastMatch.match[2] +\n \");\" +\n code.substring(lastMatch.match.index! + lastMatch.match[0].length);\n } else {\n code =\n code.substring(0, lastMatch.match.index!) +\n lastMatch.match[1] +\n \"return app.delete(\" +\n lastMatch.match[2] +\n \");\" +\n code.substring(lastMatch.match.index! + lastMatch.match[0].length);\n }\n }\n\n return code;\n}\n\n/**\n * Generates the down migration function code\n * Reverts all changes from the diff in reverse order\n *\n * @param diff - Schema diff containing all changes\n * @returns JavaScript code for down migration\n */\nexport function generateDownMigration(diff: SchemaDiff): string {\n const lines: string[] = [];\n\n // Add comment header\n lines.push(` // DOWN MIGRATION (ROLLBACK)`);\n lines.push(``);\n\n // Build collection ID map from collections being created (for rollback)\n // This map will be used to resolve relation field references\n const collectionIdMap = new Map<string, string>();\n for (const collection of diff.collectionsToCreate) {\n if (collection.id) {\n collectionIdMap.set(collection.name, collection.id);\n }\n }\n // Also include deleted collections that might have IDs\n for (const collection of diff.collectionsToDelete) {\n if (collection.id) {\n collectionIdMap.set(collection.name, collection.id);\n }\n }\n\n // Reverse order: delete -> modify -> create\n\n // 1. Recreate deleted collections\n if (diff.collectionsToDelete.length > 0) {\n lines.push(` // Recreate deleted collections`);\n for (let i = 0; i < diff.collectionsToDelete.length; i++) {\n const collection = diff.collectionsToDelete[i];\n const varName = `collection_${collection.name}_recreate`;\n lines.push(generateCollectionCreation(collection, varName, false, collectionIdMap));\n lines.push(``);\n }\n }\n\n // 2. Revert modifications (in reverse order)\n if (diff.collectionsToModify.length > 0) {\n lines.push(` // Revert modifications`);\n for (const modification of diff.collectionsToModify) {\n const collectionName = modification.collection;\n // Revert permissions (preferred) or rules (fallback)\n if (modification.permissionsToUpdate && modification.permissionsToUpdate.length > 0) {\n lines.push(` // Revert permissions for ${collectionName}`);\n for (const permission of modification.permissionsToUpdate) {\n const varName = `collection_${collectionName}_revert_perm_${permission.ruleType}`;\n lines.push(generatePermissionUpdate(collectionName, permission.ruleType, permission.oldValue, varName));\n lines.push(``);\n }\n } else if (modification.rulesToUpdate.length > 0) {\n lines.push(` // Revert rules for ${collectionName}`);\n for (const rule of modification.rulesToUpdate) {\n const varName = `collection_${collectionName}_revert_rule_${rule.ruleType}`;\n lines.push(generateRuleUpdate(collectionName, rule.ruleType, rule.oldValue, varName));\n lines.push(``);\n }\n }\n\n // Revert index removals (add them back)\n if (modification.indexesToRemove.length > 0) {\n lines.push(` // Restore indexes to ${collectionName}`);\n for (let i = 0; i < modification.indexesToRemove.length; i++) {\n const index = modification.indexesToRemove[i];\n const varName = `collection_${collectionName}_restore_idx_${i}`;\n lines.push(generateIndexAddition(collectionName, index, varName));\n lines.push(``);\n }\n }\n\n // Revert index additions (remove them)\n if (modification.indexesToAdd.length > 0) {\n lines.push(` // Remove indexes from ${collectionName}`);\n for (let i = 0; i < modification.indexesToAdd.length; i++) {\n const index = modification.indexesToAdd[i];\n const varName = `collection_${collectionName}_revert_idx_${i}`;\n lines.push(generateIndexRemoval(collectionName, index, varName));\n lines.push(``);\n }\n }\n\n // Revert field removals (add them back)\n if (modification.fieldsToRemove.length > 0) {\n lines.push(` // Restore fields to ${collectionName}`);\n for (const field of modification.fieldsToRemove) {\n const varName = `collection_${collectionName}_restore_${field.name}`;\n lines.push(generateFieldAddition(collectionName, field, varName, false, collectionIdMap));\n lines.push(``);\n }\n }\n\n // Revert field modifications\n if (modification.fieldsToModify.length > 0) {\n lines.push(` // Revert field modifications in ${collectionName}`);\n for (const fieldMod of modification.fieldsToModify) {\n // Create a reverse modification\n const reverseChanges = fieldMod.changes.map((change) => ({\n property: change.property,\n oldValue: change.newValue,\n newValue: change.oldValue,\n }));\n\n const reverseMod: FieldModification = {\n fieldName: fieldMod.fieldName,\n currentDefinition: fieldMod.newDefinition,\n newDefinition: fieldMod.currentDefinition,\n changes: reverseChanges,\n };\n\n const varName = `collection_${collectionName}_revert_${fieldMod.fieldName}`;\n lines.push(generateFieldModification(collectionName, reverseMod, varName));\n lines.push(``);\n }\n }\n\n // Revert field additions (remove them)\n if (modification.fieldsToAdd.length > 0) {\n lines.push(` // Remove added fields from ${collectionName}`);\n for (const field of modification.fieldsToAdd) {\n const varName = `collection_${collectionName}_revert_add_${field.name}`;\n lines.push(generateFieldDeletion(collectionName, field.name, varName));\n lines.push(``);\n }\n }\n }\n }\n\n // 3. Delete created collections\n if (diff.collectionsToCreate.length > 0) {\n lines.push(` // Delete created collections`);\n for (let i = 0; i < diff.collectionsToCreate.length; i++) {\n const collection = diff.collectionsToCreate[i];\n const varName = `collection_${collection.name}_rollback`;\n lines.push(generateCollectionDeletion(collection.name, varName));\n lines.push(``);\n }\n }\n\n // If no changes, add a comment\n if (lines.length === 2) {\n lines.push(` // No changes to revert`);\n lines.push(``);\n }\n\n let code = lines.join(\"\\n\");\n\n // Find the last app.save() or app.delete() call and make it return the result\n // Match app.save(...) or app.delete(...) at the end of lines (not in comments or strings)\n const savePattern = /^(\\s*)app\\.save\\((\\w+)\\);$/gm;\n const deletePattern = /^(\\s*)app\\.delete\\((\\w+)\\);$/gm;\n\n const saveMatches = [...code.matchAll(savePattern)];\n const deleteMatches = [...code.matchAll(deletePattern)];\n\n // Combine all matches and find the last one by position\n const allMatches = [\n ...saveMatches.map((m) => ({ match: m, type: \"save\", index: m.index! })),\n ...deleteMatches.map((m) => ({ match: m, type: \"delete\", index: m.index! })),\n ].sort((a, b) => b.index - a.index); // Sort descending to get last match first\n\n if (allMatches.length > 0) {\n const lastMatch = allMatches[0];\n if (lastMatch.type === \"save\") {\n code =\n code.substring(0, lastMatch.match.index!) +\n lastMatch.match[1] +\n \"return app.save(\" +\n lastMatch.match[2] +\n \");\" +\n code.substring(lastMatch.match.index! + lastMatch.match[0].length);\n } else {\n code =\n code.substring(0, lastMatch.match.index!) +\n lastMatch.match[1] +\n \"return app.delete(\" +\n lastMatch.match[2] +\n \");\" +\n code.substring(lastMatch.match.index! + lastMatch.match[0].length);\n }\n }\n\n return code;\n}\n\n/**\n * Main generation function\n * Generates migration files from schema diff (one file per collection operation)\n *\n * @param diff - Schema diff containing all changes\n * @param config - Migration generator configuration\n * @returns Array of paths to the generated migration files\n */\nexport function generate(diff: SchemaDiff, config: MigrationGeneratorConfig | string): string[] {\n // Support legacy string-only parameter (migration directory)\n const normalizedConfig: MigrationGeneratorConfig = typeof config === \"string\" ? { migrationDir: config } : config;\n\n try {\n const migrationDir = resolveMigrationDir(normalizedConfig);\n\n // Check if there are any changes\n const hasChanges =\n diff.collectionsToCreate.length > 0 || diff.collectionsToModify.length > 0 || diff.collectionsToDelete.length > 0;\n\n // If no changes, return empty array\n if (!hasChanges) {\n return [];\n }\n\n // Build collection ID map from collections being created\n const collectionIdMap = new Map<string, string>();\n for (const collection of diff.collectionsToCreate) {\n if (collection.id) {\n collectionIdMap.set(collection.name, collection.id);\n }\n }\n // Also include deleted collections that might have IDs (for rollback)\n for (const collection of diff.collectionsToDelete) {\n if (collection.id) {\n collectionIdMap.set(collection.name, collection.id);\n }\n }\n\n // Generate base timestamp\n const baseTimestamp = generateTimestamp(normalizedConfig);\n\n // Split diff into individual collection operations\n const operations = splitDiffByCollection(diff, baseTimestamp);\n\n // Generate migration file for each operation\n const filePaths: string[] = [];\n\n for (const operation of operations) {\n // Generate up and down migration code for this operation\n const upCode = generateOperationUpMigration(operation, collectionIdMap);\n const downCode = generateOperationDownMigration(operation, collectionIdMap);\n\n // Create migration file structure\n const content = createMigrationFileStructure(upCode, downCode, normalizedConfig);\n\n // Generate filename for this operation\n const filename = generateCollectionMigrationFilename(operation);\n\n // Write migration file\n const filePath = writeMigrationFile(migrationDir, filename, content);\n\n filePaths.push(filePath);\n }\n\n return filePaths;\n } catch (error) {\n // If it's already a MigrationGenerationError or FileSystemError, re-throw it\n if (error instanceof MigrationGenerationError || error instanceof FileSystemError) {\n throw error;\n }\n\n // Otherwise, wrap it in a MigrationGenerationError\n throw new MigrationGenerationError(\n `Failed to generate migration: ${error instanceof Error ? error.message : String(error)}`,\n normalizedConfig.migrationDir,\n error as Error\n );\n }\n}\n\n/**\n * MigrationGenerator class for object-oriented usage\n * Provides a stateful interface for migration generation\n */\nexport class MigrationGenerator {\n private config: Required<MigrationGeneratorConfig>;\n\n constructor(config: MigrationGeneratorConfig) {\n this.config = mergeConfig(config);\n }\n\n /**\n * Generates migration files from a schema diff\n * Returns array of file paths (one per collection operation)\n */\n generate(diff: SchemaDiff): string[] {\n return generate(diff, this.config);\n }\n\n /**\n * Generates the up migration code without writing to file\n */\n generateUpMigration(diff: SchemaDiff): string {\n return generateUpMigration(diff);\n }\n\n /**\n * Generates the down migration code without writing to file\n */\n generateDownMigration(diff: SchemaDiff): string {\n return generateDownMigration(diff);\n }\n\n /**\n * Generates a migration filename\n */\n generateMigrationFilename(diff: SchemaDiff): string {\n return generateMigrationFilename(diff, this.config);\n }\n}\n","/**\n * PocketBase Format Converter\n * Converts PocketBase collection objects to our internal CollectionSchema format\n *\n * This module handles conversion between PocketBase's native collection format\n * (as found in migration files and snapshots) and our internal schema representation.\n */\n\nimport { SnapshotError } from \"./errors\";\nimport type { CollectionSchema, SchemaSnapshot } from \"./types\";\n\nconst SNAPSHOT_VERSION = \"1.0.0\";\n\n/**\n * Resolves a collection ID to a collection name\n * Uses known constants and parses migration expressions to resolve IDs\n *\n * @param collectionId - The collection ID to resolve\n * @returns The collection name, or the original ID if it can't be resolved\n */\nexport function resolveCollectionIdToName(collectionId: string): string {\n // Special case: _pb_users_auth_ is the constant for users collection\n if (collectionId === \"_pb_users_auth_\") {\n return \"users\";\n }\n\n // Try to extract collection name from expressions like app.findCollectionByNameOrId(\"Name\").id\n const nameMatch = collectionId.match(/app\\.findCollectionByNameOrId\\s*\\(\\s*[\"']([^\"']+)[\"']\\s*\\)/);\n if (nameMatch) {\n return nameMatch[1];\n }\n\n // If we can't resolve it, return the original ID\n // This will cause a comparison issue, but it's better than failing\n return collectionId;\n}\n\n/**\n * Extracts field options from a PocketBase field object\n * Options can be placed directly on the field or in a nested options object\n * Direct properties take precedence over nested options\n *\n * @param pbField - PocketBase field object\n * @returns Merged options object\n */\nfunction extractFieldOptions(pbField: any): Record<string, any> {\n const options: Record<string, any> = {};\n\n // Start with nested options if present\n if (pbField.options && typeof pbField.options === \"object\") {\n Object.assign(options, pbField.options);\n }\n\n // Extract common field options from direct properties\n // These take precedence over nested options\n const directOptionKeys = [\n \"min\",\n \"max\",\n \"pattern\",\n \"noDecimal\", // text/number fields\n \"values\",\n \"maxSelect\", // select fields\n \"mimeTypes\",\n \"maxSize\",\n \"thumbs\",\n \"protected\", // file fields\n \"onCreate\",\n \"onUpdate\", // autodate fields\n \"exceptDomains\",\n \"onlyDomains\", // email/url fields\n ];\n\n for (const key of directOptionKeys) {\n if (pbField[key] !== undefined) {\n options[key] = pbField[key];\n }\n }\n\n return options;\n}\n\n/**\n * Converts a PocketBase collection object to CollectionSchema format\n *\n * @param pbCollection - PocketBase collection object from migration file\n * @returns CollectionSchema object\n */\nexport function convertPocketBaseCollection(pbCollection: any): CollectionSchema {\n const fields: any[] = [];\n\n // System field names that should always be excluded\n const systemFieldNames = [\"id\", \"created\", \"updated\", \"collectionId\", \"collectionName\", \"expand\"];\n\n // Auth collection system field names\n const authSystemFieldNames = [\"email\", \"emailVisibility\", \"verified\", \"password\", \"tokenKey\"];\n\n // Convert PocketBase fields to our FieldDefinition format\n if (pbCollection.fields && Array.isArray(pbCollection.fields)) {\n for (const pbField of pbCollection.fields) {\n // Skip system fields by checking both the system flag and field name\n // Some PocketBase exports mark created/updated as system: false\n if (pbField.system || systemFieldNames.includes(pbField.name)) {\n continue;\n }\n\n // Skip auth system fields for auth collections\n if (pbCollection.type === \"auth\" && authSystemFieldNames.includes(pbField.name)) {\n continue;\n }\n\n const field: any = {\n name: pbField.name,\n type: pbField.type,\n required: pbField.required || false,\n };\n\n // Extract options from both direct properties and nested options object\n field.options = extractFieldOptions(pbField);\n\n // Handle relation fields\n if (pbField.type === \"relation\") {\n // Support both formats: collectionId directly on field or in options\n const collectionId = pbField.collectionId || pbField.options?.collectionId || \"\";\n // Resolve collectionId to collection name\n // collectionId is a system field (like _pb_users_auth_), not the collection name\n // We need to resolve it to the actual collection name for comparison\n const collectionName = resolveCollectionIdToName(collectionId || \"\");\n field.relation = {\n collection: collectionName,\n cascadeDelete: pbField.cascadeDelete ?? pbField.options?.cascadeDelete ?? false,\n maxSelect: pbField.maxSelect ?? pbField.options?.maxSelect,\n minSelect: pbField.minSelect ?? pbField.options?.minSelect,\n };\n\n // Remove relation-specific properties from options\n // These belong in the relation object, not options\n delete field.options.maxSelect;\n delete field.options.minSelect;\n delete field.options.cascadeDelete;\n }\n\n // Clean up empty options object, but preserve values for select fields\n // If options only contains values for a select field, keep it\n const hasOnlyValues = Object.keys(field.options).length === 1 && field.options.values !== undefined;\n if (Object.keys(field.options).length === 0) {\n delete field.options;\n } else if (pbField.type === \"select\" && hasOnlyValues) {\n // Keep options object if it only contains values for a select field\n // This ensures values are preserved for comparison\n }\n\n fields.push(field);\n }\n }\n\n const schema: CollectionSchema = {\n name: pbCollection.name,\n type: pbCollection.type || \"base\",\n fields,\n };\n\n // Preserve collection ID if present (needed for relation resolution)\n if (pbCollection.id) {\n schema.id = pbCollection.id;\n }\n\n // Add indexes if present\n if (pbCollection.indexes && Array.isArray(pbCollection.indexes)) {\n schema.indexes = pbCollection.indexes;\n }\n\n // Add rules/permissions\n // Check if any rule properties exist on the collection object\n const hasAnyRule =\n pbCollection.listRule !== undefined ||\n pbCollection.viewRule !== undefined ||\n pbCollection.createRule !== undefined ||\n pbCollection.updateRule !== undefined ||\n pbCollection.deleteRule !== undefined ||\n pbCollection.manageRule !== undefined;\n\n if (hasAnyRule) {\n const rules: any = {};\n // Include rules even if they're null (null is a valid value)\n if (pbCollection.listRule !== undefined) rules.listRule = pbCollection.listRule;\n if (pbCollection.viewRule !== undefined) rules.viewRule = pbCollection.viewRule;\n if (pbCollection.createRule !== undefined) rules.createRule = pbCollection.createRule;\n if (pbCollection.updateRule !== undefined) rules.updateRule = pbCollection.updateRule;\n if (pbCollection.deleteRule !== undefined) rules.deleteRule = pbCollection.deleteRule;\n if (pbCollection.manageRule !== undefined) rules.manageRule = pbCollection.manageRule;\n\n schema.rules = rules;\n // Also set permissions to match rules (they're the same thing)\n schema.permissions = { ...rules };\n }\n\n return schema;\n}\n\n/**\n * Converts PocketBase migration format to SchemaSnapshot\n * Extracts the snapshot array from the migration file content\n *\n * @param migrationContent - Raw migration file content\n * @returns SchemaSnapshot with collections map\n */\nexport function convertPocketBaseMigration(migrationContent: string): SchemaSnapshot {\n try {\n // Extract the snapshot array from the migration file\n // The format is: migrate((app) => { const snapshot = [...]; ... })\n const snapshotMatch = migrationContent.match(/const\\s+snapshot\\s*=\\s*(\\[[\\s\\S]*?\\]);/);\n\n if (!snapshotMatch) {\n throw new Error(\"Could not find snapshot array in migration file\");\n }\n\n // Parse the snapshot array as JSON\n // We need to evaluate it as JavaScript since it's not pure JSON\n const snapshotArrayStr = snapshotMatch[1];\n let snapshotArray: any[];\n\n try {\n // Use Function constructor to safely evaluate the array\n // This is safer than eval() and works for our use case\n snapshotArray = new Function(`return ${snapshotArrayStr}`)();\n } catch (parseError) {\n throw new Error(`Failed to parse snapshot array: ${parseError}`);\n }\n\n if (!Array.isArray(snapshotArray)) {\n throw new Error(\"Snapshot is not an array\");\n }\n\n // Convert each collection to our format\n const collections = new Map<string, CollectionSchema>();\n\n for (const pbCollection of snapshotArray) {\n if (!pbCollection.name) {\n console.warn(\"Skipping collection without name\");\n continue;\n }\n\n const schema = convertPocketBaseCollection(pbCollection);\n collections.set(pbCollection.name, schema);\n }\n\n return {\n version: SNAPSHOT_VERSION,\n timestamp: new Date().toISOString(),\n collections,\n };\n } catch (error) {\n throw new SnapshotError(\n `Failed to convert PocketBase migration: ${error instanceof Error ? error.message : String(error)}`,\n undefined,\n \"parse\",\n error instanceof Error ? error : undefined\n );\n }\n}\n","/**\n * Migration File Parser\n * Parses PocketBase migration files to extract collection operations\n *\n * This module handles parsing migration files to extract:\n * - Collection creations (new Collection(...))\n * - Collection deletions (app.delete(...))\n * - Field modifications (field.property = value)\n */\n\nimport * as fs from \"fs\";\nimport * as path from \"path\";\nimport { convertPocketBaseCollection } from \"./pocketbase-converter\";\nimport type { CollectionSchema } from \"./types\";\n\n/**\n * Extracts timestamp from migration filename\n * Migration files are named: [timestamp]_[description].js\n *\n * @param filename - Migration filename\n * @returns Timestamp as number or null if not found\n */\nexport function extractTimestampFromFilename(filename: string): number | null {\n const match = filename.match(/^(\\d+)_/);\n if (match) {\n return parseInt(match[1], 10);\n }\n return null;\n}\n\n/**\n * Finds all migration files after a given snapshot timestamp\n * Excludes snapshot files themselves\n *\n * @param migrationsPath - Path to migrations directory\n * @param snapshotTimestamp - Timestamp of the snapshot file\n * @returns Array of migration file paths sorted by timestamp\n */\nexport function findMigrationsAfterSnapshot(migrationsPath: string, snapshotTimestamp: number): string[] {\n try {\n if (!fs.existsSync(migrationsPath)) {\n return [];\n }\n\n const files = fs.readdirSync(migrationsPath);\n const migrationFiles: { path: string; timestamp: number }[] = [];\n\n for (const file of files) {\n // Skip snapshot files\n if (file.endsWith(\"_collections_snapshot.js\") || file.endsWith(\"_snapshot.js\")) {\n continue;\n }\n\n // Skip non-JS files\n if (!file.endsWith(\".js\")) {\n continue;\n }\n\n const timestamp = extractTimestampFromFilename(file);\n if (timestamp && timestamp > snapshotTimestamp) {\n migrationFiles.push({\n path: path.join(migrationsPath, file),\n timestamp,\n });\n }\n }\n\n // Sort by timestamp (ascending order)\n migrationFiles.sort((a, b) => a.timestamp - b.timestamp);\n\n return migrationFiles.map((f) => f.path);\n } catch (error) {\n console.warn(`Error finding migrations after snapshot: ${error}`);\n return [];\n }\n}\n\n/**\n * Helper function to parse collection operations from migration content\n *\n * @param content - Migration content (should be just the UP migration)\n * @returns Object with collections to create and collections to delete\n */\nfunction parseMigrationOperationsFromContent(content: string): {\n collectionsToCreate: CollectionSchema[];\n collectionsToDelete: string[];\n} {\n const collectionsToCreate: CollectionSchema[] = [];\n const collectionsToDelete: string[] = [];\n\n try {\n // Extract collection definitions from `new Collection({...})`\n // Use a more robust approach: find all \"new Collection(\" and then parse until matching closing paren\n let searchIndex = 0;\n while (true) {\n const collectionStart = content.indexOf(\"new Collection(\", searchIndex);\n if (collectionStart === -1) {\n break;\n }\n\n // Find the opening brace after \"new Collection(\"\n const openParen = collectionStart + \"new Collection(\".length;\n let braceCount = 0;\n let parenCount = 1; // We're already inside the opening paren\n let inString = false;\n let stringChar = null;\n let i = openParen;\n\n // Skip whitespace to find the opening brace\n while (i < content.length && /\\s/.test(content[i])) {\n i++;\n }\n\n if (content[i] !== \"{\") {\n searchIndex = i + 1;\n continue;\n }\n\n const objectStart = i;\n braceCount = 1;\n i++;\n\n // Find the matching closing brace and paren\n while (i < content.length && (braceCount > 0 || parenCount > 0)) {\n const char = content[i];\n const prevChar = i > 0 ? content[i - 1] : \"\";\n\n // Handle strings\n if (!inString && (char === '\"' || char === \"'\")) {\n inString = true;\n stringChar = char;\n } else if (inString && char === stringChar && prevChar !== \"\\\\\") {\n inString = false;\n stringChar = null;\n }\n\n if (!inString) {\n if (char === \"{\") braceCount++;\n if (char === \"}\") braceCount--;\n if (char === \"(\") parenCount++;\n if (char === \")\") parenCount--;\n }\n\n i++;\n }\n\n if (braceCount === 0 && parenCount === 0) {\n const objectContent = content.substring(objectStart, i - 1); // -1 to exclude the closing paren\n try {\n // Use Function constructor to parse the JavaScript object\n const collectionObj = new Function(`return ${objectContent}`)();\n if (collectionObj && collectionObj.name) {\n const schema = convertPocketBaseCollection(collectionObj);\n collectionsToCreate.push(schema);\n }\n } catch (error) {\n // Skip malformed collection definitions\n console.warn(`Failed to parse collection definition: ${error}`);\n }\n }\n\n searchIndex = i;\n }\n\n // Extract collection deletions from `app.delete(...)`\n // Look for patterns like: app.delete(collection_xxx) or app.delete(app.findCollectionByNameOrId(\"name\"))\n const deleteMatches = content.matchAll(\n /app\\.delete\\s*\\(\\s*(?:collection_\\w+|app\\.findCollectionByNameOrId\\s*\\(\\s*[\"']([^\"']+)[\"']\\s*\\))\\s*\\)/g\n );\n for (const match of deleteMatches) {\n // If we have a collection name from findCollectionByNameOrId, use it\n if (match[1]) {\n collectionsToDelete.push(match[1]);\n } else {\n // Try to find the collection name from the variable name\n // Look backwards for the collection variable definition\n const varNameMatch = match[0].match(/collection_(\\w+)/);\n if (varNameMatch) {\n // Try to find the collection name from the variable definition\n const varName = `collection_${varNameMatch[1]}`;\n // Search backwards from the delete call to find the variable definition\n const deleteIndex = content.indexOf(match[0]);\n const beforeDelete = content.substring(0, deleteIndex);\n const varDefMatch = beforeDelete.match(\n new RegExp(`const\\\\s+${varName}\\\\s*=\\\\s*new\\\\s+Collection\\\\(\\\\s*(\\\\{[\\\\s\\\\S]*?\\\\})\\\\s*\\\\)`, \"g\")\n );\n if (varDefMatch && varDefMatch.length > 0) {\n // Find the collection definition (get the last match closest to the delete)\n const collectionDefMatch = beforeDelete.match(\n new RegExp(`const\\\\s+${varName}\\\\s*=\\\\s*new\\\\s+Collection\\\\(\\\\s*(\\\\{[\\\\s\\\\S]*?\\\\})\\\\s*\\\\)`)\n );\n if (collectionDefMatch) {\n try {\n const collectionDefStr = collectionDefMatch[1];\n const collectionObj = new Function(`return ${collectionDefStr}`)();\n if (collectionObj && collectionObj.name) {\n collectionsToDelete.push(collectionObj.name);\n }\n } catch {\n // Skip if we can't parse\n }\n }\n }\n }\n }\n }\n\n // Also look for direct collection name in findCollectionByNameOrId followed by delete\n const findAndDeleteMatches = content.matchAll(\n /app\\.findCollectionByNameOrId\\s*\\(\\s*[\"']([^\"']+)[\"']\\s*\\)[\\s\\S]*?app\\.delete/g\n );\n for (const match of findAndDeleteMatches) {\n collectionsToDelete.push(match[1]);\n }\n } catch (error) {\n console.warn(`Failed to parse migration operations from content: ${error}`);\n }\n\n return { collectionsToCreate, collectionsToDelete };\n}\n\n/**\n * Parses a migration file to extract collection operations\n * Extracts collections created with `new Collection(...)` and collections deleted with `app.delete(...)`\n * Only parses the UP migration (first function), not the down migration\n *\n * @param migrationContent - Raw migration file content\n * @returns Object with collections to create and collections to delete\n */\nexport function parseMigrationOperations(migrationContent: string): {\n collectionsToCreate: CollectionSchema[];\n collectionsToDelete: string[];\n} {\n try {\n // Extract only the UP migration (first function argument to migrate())\n // Find the migrate call and extract the first function body\n const migrateMatch = migrationContent.match(/migrate\\s*\\(\\s*/);\n if (!migrateMatch) {\n // If we can't find the migrate pattern, try to parse the whole file\n return parseMigrationOperationsFromContent(migrationContent);\n }\n\n const startIndex = migrateMatch.index! + migrateMatch[0].length;\n\n // Find the opening paren of the first function\n let i = startIndex;\n let parenCount = 0;\n let foundFirstParen = false;\n\n while (i < migrationContent.length) {\n const char = migrationContent[i];\n if (char === \"(\") {\n parenCount++;\n foundFirstParen = true;\n i++;\n break;\n }\n i++;\n }\n\n if (!foundFirstParen) {\n return parseMigrationOperationsFromContent(migrationContent);\n }\n\n // Skip the function parameters: (app) => {\n let inString = false;\n let stringChar = null;\n let foundBrace = false;\n let braceStart = -1;\n\n while (i < migrationContent.length && !foundBrace) {\n const char = migrationContent[i];\n const prevChar = i > 0 ? migrationContent[i - 1] : \"\";\n\n if (!inString && (char === '\"' || char === \"'\")) {\n inString = true;\n stringChar = char;\n } else if (inString && char === stringChar && prevChar !== \"\\\\\") {\n inString = false;\n stringChar = null;\n }\n\n if (!inString) {\n if (char === \"(\") parenCount++;\n if (char === \")\") {\n parenCount--;\n if (parenCount === 0) {\n // Found end of function parameters, look for =>\n i++;\n while (i < migrationContent.length && /\\s/.test(migrationContent[i])) {\n i++;\n }\n if (i < migrationContent.length - 1 && migrationContent[i] === \"=\" && migrationContent[i + 1] === \">\") {\n i += 2;\n while (i < migrationContent.length && /\\s/.test(migrationContent[i])) {\n i++;\n }\n if (i < migrationContent.length && migrationContent[i] === \"{\") {\n foundBrace = true;\n braceStart = i + 1;\n break;\n }\n }\n }\n }\n }\n i++;\n }\n\n if (!foundBrace || braceStart === -1) {\n return parseMigrationOperationsFromContent(migrationContent);\n }\n\n // Find the matching closing brace\n let braceCount = 1;\n i = braceStart;\n inString = false;\n stringChar = null;\n\n while (i < migrationContent.length && braceCount > 0) {\n const char = migrationContent[i];\n const prevChar = i > 0 ? migrationContent[i - 1] : \"\";\n\n if (!inString && (char === '\"' || char === \"'\")) {\n inString = true;\n stringChar = char;\n } else if (inString && char === stringChar && prevChar !== \"\\\\\") {\n inString = false;\n stringChar = null;\n }\n\n if (!inString) {\n if (char === \"{\") braceCount++;\n if (char === \"}\") braceCount--;\n }\n\n i++;\n }\n\n if (braceCount === 0) {\n const upMigrationContent = migrationContent.substring(braceStart, i - 1);\n return parseMigrationOperationsFromContent(upMigrationContent);\n }\n\n // Fallback: parse the whole file\n return parseMigrationOperationsFromContent(migrationContent);\n } catch (error) {\n console.warn(`Failed to parse migration operations: ${error}`);\n return { collectionsToCreate: [], collectionsToDelete: [] };\n }\n}\n","/**\n * Snapshot Manager\n * Handles saving and loading schema snapshots from JSON files\n *\n * This module provides a standalone, configurable snapshot manager that can be used\n * by consumer projects to manage schema snapshots. It focuses on JSON snapshot file\n * management, delegating migration file parsing and PocketBase format conversion\n * to specialized modules.\n */\n\nimport * as fs from \"fs\";\nimport * as path from \"path\";\nimport { FileSystemError, SnapshotError } from \"./errors\";\nimport {\n extractTimestampFromFilename,\n findMigrationsAfterSnapshot,\n parseMigrationOperations,\n} from \"./migration-parser\";\nimport { convertPocketBaseMigration } from \"./pocketbase-converter\";\nimport type { CollectionSchema, SchemaDefinition, SchemaSnapshot } from \"./types\";\n\nconst SNAPSHOT_VERSION = \"1.0.0\";\nconst DEFAULT_SNAPSHOT_FILENAME = \".migration-snapshot.json\";\n\n/**\n * Configuration for snapshot operations\n */\nexport interface SnapshotConfig {\n /**\n * Path to the snapshot file\n * Can be absolute or relative to workspaceRoot\n */\n snapshotPath?: string;\n\n /**\n * Workspace root directory for resolving relative paths\n * Defaults to process.cwd()\n */\n workspaceRoot?: string;\n\n /**\n * Path to the migrations directory for finding PocketBase snapshots\n */\n migrationsPath?: string;\n\n /**\n * Whether to auto-migrate old snapshot formats\n * Defaults to true\n */\n autoMigrate?: boolean;\n\n /**\n * Custom snapshot version for testing\n */\n version?: string;\n}\n\n/**\n * Snapshot format versions and their migration functions\n */\ninterface SnapshotMigration {\n fromVersion: string;\n toVersion: string;\n migrate: (data: any) => any;\n}\n\n/**\n * Registry of snapshot format migrations\n */\nconst SNAPSHOT_MIGRATIONS: SnapshotMigration[] = [\n // Add migrations here as the format evolves\n // Example:\n // {\n // fromVersion: '0.9.0',\n // toVersion: '1.0.0',\n // migrate: (data) => ({ ...data, newField: 'default' })\n // }\n];\n\n/**\n * Default configuration values\n */\nconst DEFAULT_CONFIG: Omit<Required<SnapshotConfig>, \"migrationsPath\"> & { migrationsPath?: string } = {\n snapshotPath: DEFAULT_SNAPSHOT_FILENAME,\n workspaceRoot: process.cwd(),\n autoMigrate: true,\n version: SNAPSHOT_VERSION,\n};\n\n/**\n * Merges user config with defaults\n */\nfunction mergeConfig(config: SnapshotConfig = {}): typeof DEFAULT_CONFIG {\n return {\n ...DEFAULT_CONFIG,\n ...config,\n };\n}\n\n/**\n * Gets the snapshot file path from configuration\n *\n * @param config - Snapshot configuration\n * @returns Absolute path to the snapshot file\n */\nexport function getSnapshotPath(config: SnapshotConfig = {}): string {\n const mergedConfig = mergeConfig(config);\n const workspaceRoot = mergedConfig.workspaceRoot;\n const snapshotFilename = mergedConfig.snapshotPath;\n\n // If snapshotPath is absolute, use it directly\n if (path.isAbsolute(snapshotFilename)) {\n return snapshotFilename;\n }\n\n // Otherwise, resolve relative to workspaceRoot\n return path.join(workspaceRoot, snapshotFilename);\n}\n\n/**\n * Checks if snapshot file exists\n *\n * @param config - Snapshot configuration\n * @returns True if snapshot file exists\n */\nexport function snapshotExists(config: SnapshotConfig = {}): boolean {\n try {\n const snapshotPath = getSnapshotPath(config);\n return fs.existsSync(snapshotPath);\n } catch {\n // If there's any error checking existence, treat as non-existent\n return false;\n }\n}\n\n/**\n * Handles file system errors with descriptive messages\n *\n * @param error - The error object\n * @param operation - The operation being performed\n * @param filePath - The file path involved\n * @throws SnapshotError or FileSystemError with descriptive message\n */\nfunction handleFileSystemError(error: any, operation: \"read\" | \"write\", filePath: string): never {\n const fsError = error as NodeJS.ErrnoException;\n\n if (fsError.code === \"ENOENT\") {\n throw new SnapshotError(`Snapshot file not found: ${filePath}`, filePath, operation, error);\n } else if (fsError.code === \"EACCES\" || fsError.code === \"EPERM\") {\n throw new FileSystemError(\n `Permission denied ${operation === \"read\" ? \"reading\" : \"writing\"} snapshot file. Check file permissions.`,\n filePath,\n operation,\n fsError.code,\n error\n );\n } else if (fsError.code === \"ENOSPC\") {\n throw new FileSystemError(\n `No space left on device when ${operation === \"read\" ? \"reading\" : \"writing\"} snapshot file.`,\n filePath,\n operation,\n fsError.code,\n error\n );\n } else {\n throw new SnapshotError(`Failed to ${operation} snapshot file: ${error.message}`, filePath, operation, error);\n }\n}\n\n/**\n * Serializes a Map to a plain object for JSON serialization\n *\n * @param map - Map to serialize\n * @returns Plain object representation\n */\nfunction serializeMap<K extends string, V>(map: Map<K, V>): Record<K, V> {\n const obj: Record<string, V> = {};\n for (const [key, value] of map.entries()) {\n obj[key] = value;\n }\n return obj as Record<K, V>;\n}\n\n/**\n * Deserializes a plain object to a Map\n *\n * @param obj - Plain object to deserialize\n * @returns Map representation\n */\nfunction deserializeMap<K extends string, V>(obj: Record<K, V>): Map<K, V> {\n const map = new Map<K, V>();\n for (const [key, value] of Object.entries(obj)) {\n map.set(key as K, value as V);\n }\n return map;\n}\n\n/**\n * Serializes SchemaDefinition to JSON format\n * Converts Map to plain object for JSON compatibility\n *\n * @param schema - Schema definition to serialize\n * @returns JSON-serializable object\n */\nfunction serializeSchemaDefinition(schema: SchemaDefinition): any {\n return {\n collections: serializeMap(schema.collections),\n };\n}\n\n/**\n * Adds version and timestamp metadata to snapshot\n *\n * @param schema - Schema definition\n * @param config - Optional configuration with custom version\n * @returns Snapshot with metadata\n */\nfunction addSnapshotMetadata(schema: SchemaDefinition, config?: SnapshotConfig): any {\n const mergedConfig = mergeConfig(config);\n return {\n version: mergedConfig.version,\n timestamp: new Date().toISOString(),\n ...serializeSchemaDefinition(schema),\n };\n}\n\n/**\n * Saves schema snapshot to file\n * Serializes SchemaDefinition to JSON with version and timestamp metadata\n * Writes with pretty printing for readability\n *\n * @param schema - Schema definition to save\n * @param config - Snapshot configuration\n */\nexport function saveSnapshot(schema: SchemaDefinition, config: SnapshotConfig = {}): void {\n const snapshotPath = getSnapshotPath(config);\n\n try {\n // Ensure directory exists\n const snapshotDir = path.dirname(snapshotPath);\n if (!fs.existsSync(snapshotDir)) {\n fs.mkdirSync(snapshotDir, { recursive: true });\n }\n\n // Add metadata and serialize\n const snapshotData = addSnapshotMetadata(schema, config);\n\n // Write with pretty printing (2 spaces indentation)\n const jsonContent = JSON.stringify(snapshotData, null, 2);\n fs.writeFileSync(snapshotPath, jsonContent, \"utf-8\");\n } catch (error) {\n handleFileSystemError(error, \"write\", snapshotPath);\n }\n}\n\n/**\n * Parses JSON and validates snapshot format\n *\n * @param jsonContent - Raw JSON content\n * @param snapshotPath - Path to snapshot file (for error messages)\n * @returns Parsed snapshot data\n */\nfunction parseAndValidateSnapshot(jsonContent: string, snapshotPath: string): any {\n try {\n const data = JSON.parse(jsonContent);\n\n // Validate required fields\n if (!data.version) {\n throw new SnapshotError(\n \"Snapshot file is missing version field. The snapshot may be corrupted.\",\n snapshotPath,\n \"validate\"\n );\n }\n\n if (!data.timestamp) {\n throw new SnapshotError(\n \"Snapshot file is missing timestamp field. The snapshot may be corrupted.\",\n snapshotPath,\n \"validate\"\n );\n }\n\n if (!data.collections) {\n throw new SnapshotError(\n \"Snapshot file is missing collections field. The snapshot may be corrupted.\",\n snapshotPath,\n \"validate\"\n );\n }\n\n return data;\n } catch (error) {\n if (error instanceof SnapshotError) {\n throw error;\n }\n\n if (error instanceof SyntaxError) {\n throw new SnapshotError(\n `Invalid JSON in snapshot file. The file may be corrupted or manually edited incorrectly.`,\n snapshotPath,\n \"parse\",\n error\n );\n }\n throw error;\n }\n}\n\n/**\n * Compares two version strings\n * Returns -1 if a < b, 0 if a == b, 1 if a > b\n */\nfunction compareVersions(a: string, b: string): number {\n const partsA = a.split(\".\").map(Number);\n const partsB = b.split(\".\").map(Number);\n\n for (let i = 0; i < Math.max(partsA.length, partsB.length); i++) {\n const numA = partsA[i] || 0;\n const numB = partsB[i] || 0;\n\n if (numA < numB) return -1;\n if (numA > numB) return 1;\n }\n\n return 0;\n}\n\n/**\n * Migrates old snapshot formats to current version\n * Applies migrations in sequence from old version to current\n *\n * @param data - Parsed snapshot data\n * @param config - Optional configuration\n * @returns Migrated snapshot data\n */\nfunction migrateSnapshotFormat(data: any, config?: SnapshotConfig): any {\n const mergedConfig = mergeConfig(config);\n const currentVersion = data.version;\n const targetVersion = mergedConfig.version;\n\n // If versions match, no migration needed\n if (currentVersion === targetVersion) {\n return data;\n }\n\n // If auto-migrate is disabled, just return the data with a warning\n if (!mergedConfig.autoMigrate) {\n console.warn(\n `Snapshot version ${currentVersion} differs from current ${targetVersion}, but auto-migrate is disabled.`\n );\n return data;\n }\n\n // Find and apply migrations in sequence\n let migratedData = { ...data };\n let currentMigrationVersion = currentVersion;\n\n // Sort migrations by fromVersion\n const sortedMigrations = [...SNAPSHOT_MIGRATIONS].sort((a, b) => compareVersions(a.fromVersion, b.fromVersion));\n\n for (const migration of sortedMigrations) {\n if (compareVersions(currentMigrationVersion, migration.fromVersion) === 0) {\n console.log(`Migrating snapshot from ${migration.fromVersion} to ${migration.toVersion}...`);\n migratedData = migration.migrate(migratedData);\n migratedData.version = migration.toVersion;\n currentMigrationVersion = migration.toVersion;\n }\n }\n\n // If we couldn't migrate to the target version, log a warning\n if (compareVersions(currentMigrationVersion, targetVersion) !== 0) {\n console.warn(`Unknown snapshot version ${currentVersion}, attempting to load anyway...`);\n }\n\n return migratedData;\n}\n\n/**\n * Deserializes snapshot data to SchemaSnapshot\n *\n * @param data - Parsed and validated snapshot data\n * @returns SchemaSnapshot object\n */\nfunction deserializeSnapshot(data: any): SchemaSnapshot {\n return {\n version: data.version,\n timestamp: data.timestamp,\n collections: deserializeMap<string, CollectionSchema>(data.collections),\n };\n}\n\n/**\n * Loads schema snapshot from file\n * Reads snapshot file, parses JSON, validates format, and handles migrations\n *\n * @param config - Snapshot configuration\n * @returns SchemaSnapshot object\n * @throws Error if snapshot file doesn't exist or is invalid\n */\nexport function loadSnapshot(config: SnapshotConfig = {}): SchemaSnapshot {\n const snapshotPath = getSnapshotPath(config);\n\n try {\n // Read file\n const jsonContent = fs.readFileSync(snapshotPath, \"utf-8\");\n\n // Parse and validate\n const data = parseAndValidateSnapshot(jsonContent, snapshotPath);\n\n // Migrate format if needed\n const migratedData = migrateSnapshotFormat(data, config);\n\n // Deserialize to SchemaSnapshot\n return deserializeSnapshot(migratedData);\n } catch (error) {\n // If it's already a SnapshotError or FileSystemError, re-throw it\n if (error instanceof SnapshotError || error instanceof FileSystemError) {\n throw error;\n }\n\n // If file doesn't exist, throw specific error\n if ((error as any).code === \"ENOENT\") {\n throw new SnapshotError(\n `Snapshot file not found. This may be the first migration run.`,\n snapshotPath,\n \"read\",\n error as Error\n );\n }\n\n // Handle other file system errors\n handleFileSystemError(error, \"read\", snapshotPath);\n }\n}\n\n/**\n * Merges base schema with custom snapshot\n * Base schema collections are preserved, custom collections are added\n * Custom collections override base collections if they have the same name\n *\n * @param baseSnapshot - PocketBase base schema\n * @param customSnapshot - User's custom schema snapshot (may be null)\n * @returns Merged SchemaSnapshot\n */\nexport function mergeSnapshots(baseSnapshot: SchemaSnapshot, customSnapshot: SchemaSnapshot | null): SchemaSnapshot {\n // If no custom snapshot, return base snapshot\n if (!customSnapshot) {\n return baseSnapshot;\n }\n\n // Create a new collections map starting with base collections\n const mergedCollections = new Map<string, CollectionSchema>(baseSnapshot.collections);\n\n // Add or override with custom collections\n for (const [name, schema] of customSnapshot.collections.entries()) {\n mergedCollections.set(name, schema);\n }\n\n return {\n version: customSnapshot.version || baseSnapshot.version,\n timestamp: customSnapshot.timestamp || baseSnapshot.timestamp,\n collections: mergedCollections,\n };\n}\n\n/**\n * Finds the most recent snapshot file in the migrations directory\n * Identifies snapshot files by naming pattern (e.g., *_collections_snapshot.js)\n *\n * @param migrationsPath - Path to pb_migrations directory\n * @returns Path to most recent snapshot file or null if none exist\n */\nexport function findLatestSnapshot(migrationsPath: string): string | null {\n try {\n // Check if migrations directory exists\n if (!fs.existsSync(migrationsPath)) {\n return null;\n }\n\n // Read all files in migrations directory\n const files = fs.readdirSync(migrationsPath);\n\n // Filter for snapshot files (files ending with _collections_snapshot.js or _snapshot.js)\n const snapshotFiles = files.filter(\n (file) => file.endsWith(\"_collections_snapshot.js\") || file.endsWith(\"_snapshot.js\")\n );\n\n if (snapshotFiles.length === 0) {\n return null;\n }\n\n // Sort by filename (timestamp prefix) to get most recent\n // Snapshot files are named with timestamp prefix: [timestamp]_collections_snapshot.js\n snapshotFiles.sort().reverse();\n\n // Return full path to most recent snapshot\n const latestSnapshot = snapshotFiles[0];\n if (!latestSnapshot) {\n return null;\n }\n return path.join(migrationsPath, latestSnapshot);\n } catch (error) {\n // If there's any error reading directory, return null\n console.warn(`Error finding latest snapshot: ${error}`);\n return null;\n }\n}\n\n/**\n * Applies migration operations to a snapshot state\n * Creates new collections and deletes collections as specified\n *\n * @param snapshot - Base snapshot state\n * @param operations - Migration operations to apply\n * @returns Updated snapshot with operations applied\n */\nfunction applyMigrationOperations(\n snapshot: SchemaSnapshot,\n operations: { collectionsToCreate: CollectionSchema[]; collectionsToDelete: string[] }\n): SchemaSnapshot {\n const updatedCollections = new Map(snapshot.collections);\n\n // Apply deletions first\n for (const collectionName of operations.collectionsToDelete) {\n updatedCollections.delete(collectionName);\n }\n\n // Apply creations/updates\n for (const collection of operations.collectionsToCreate) {\n updatedCollections.set(collection.name, collection);\n }\n\n return {\n ...snapshot,\n collections: updatedCollections,\n };\n}\n\n/**\n * Loads snapshot and applies all migrations that come after it\n * This gives us the current state of the database schema\n *\n * @param config - Snapshot configuration (must include migrationsPath)\n * @returns SchemaSnapshot object representing current state or null if snapshot doesn't exist\n */\nexport function loadSnapshotWithMigrations(config: SnapshotConfig = {}): SchemaSnapshot | null {\n const migrationsPath = config.migrationsPath;\n\n if (!migrationsPath) {\n return null;\n }\n\n // Check if migrationsPath is actually a file (for backward compatibility with tests)\n if (fs.existsSync(migrationsPath) && fs.statSync(migrationsPath).isFile()) {\n try {\n const migrationContent = fs.readFileSync(migrationsPath, \"utf-8\");\n return convertPocketBaseMigration(migrationContent);\n } catch (error) {\n console.warn(`Failed to load snapshot from ${migrationsPath}: ${error}`);\n return null;\n }\n }\n\n // It's a directory, find the latest snapshot\n const latestSnapshotPath = findLatestSnapshot(migrationsPath);\n\n if (!latestSnapshotPath) {\n // No snapshot found - return null (empty database)\n return null;\n }\n\n try {\n // Read and convert the PocketBase snapshot file\n const migrationContent = fs.readFileSync(latestSnapshotPath, \"utf-8\");\n let snapshot = convertPocketBaseMigration(migrationContent);\n\n // Extract timestamp from snapshot filename\n const snapshotFilename = path.basename(latestSnapshotPath);\n const snapshotTimestamp = extractTimestampFromFilename(snapshotFilename);\n\n if (snapshotTimestamp) {\n // Find all migration files after the snapshot\n const migrationFiles = findMigrationsAfterSnapshot(migrationsPath, snapshotTimestamp);\n\n // Apply each migration in order\n for (const migrationFile of migrationFiles) {\n try {\n const migrationContent = fs.readFileSync(migrationFile, \"utf-8\");\n const operations = parseMigrationOperations(migrationContent);\n snapshot = applyMigrationOperations(snapshot, operations);\n } catch (error) {\n console.warn(`Failed to apply migration ${migrationFile}: ${error}`);\n // Continue with other migrations even if one fails\n }\n }\n }\n\n return snapshot;\n } catch (error) {\n console.warn(`Failed to load snapshot from ${latestSnapshotPath}: ${error}`);\n return null;\n }\n}\n\n/**\n * Loads snapshot if it exists, returns null for first run\n * Convenience method that handles missing snapshot gracefully\n * Finds the most recent snapshot file from migrations directory\n * NOTE: This function only loads the snapshot, not migrations after it.\n * Use loadSnapshotWithMigrations() if you need the current state including migrations.\n *\n * @param config - Snapshot configuration (must include migrationsPath)\n * @returns SchemaSnapshot object or null if snapshot doesn't exist\n */\nexport function loadSnapshotIfExists(config: SnapshotConfig = {}): SchemaSnapshot | null {\n const migrationsPath = config.migrationsPath;\n\n if (!migrationsPath) {\n // No migrations path provided - return null\n return null;\n }\n\n // Check if migrationsPath is actually a file (for backward compatibility with tests)\n // If it's a file, treat it as a direct snapshot file path\n if (fs.existsSync(migrationsPath) && fs.statSync(migrationsPath).isFile()) {\n try {\n const migrationContent = fs.readFileSync(migrationsPath, \"utf-8\");\n return convertPocketBaseMigration(migrationContent);\n } catch (error) {\n console.warn(`Failed to load snapshot from ${migrationsPath}: ${error}`);\n return null;\n }\n }\n\n // It's a directory, find the latest snapshot\n const latestSnapshotPath = findLatestSnapshot(migrationsPath);\n\n if (latestSnapshotPath) {\n try {\n // Read and convert the PocketBase snapshot file\n const migrationContent = fs.readFileSync(latestSnapshotPath, \"utf-8\");\n return convertPocketBaseMigration(migrationContent);\n } catch (error) {\n console.warn(`Failed to load snapshot from ${latestSnapshotPath}: ${error}`);\n return null;\n }\n }\n\n // No snapshot found - return null (empty database)\n return null;\n}\n\n/**\n * Loads the base PocketBase schema from the initial migration file\n *\n * @param migrationPath - Path to pocketbase/pb_migrations/000000000_collections_snapshot.js\n * @returns SchemaSnapshot representing PocketBase's initial state\n * @throws SnapshotError if file not found or invalid format\n */\nexport function loadBaseMigration(migrationPath: string): SchemaSnapshot {\n try {\n // Check if file exists\n if (!fs.existsSync(migrationPath)) {\n throw new SnapshotError(\n `Base migration file not found: ${migrationPath}\\n\\n` +\n `This file should contain PocketBase's initial schema.\\n` +\n `Please ensure PocketBase is properly set up by running 'yarn setup'.\\n` +\n `If the file exists in a different location, update the configuration.`,\n migrationPath,\n \"read\"\n );\n }\n\n // Read the migration file\n const migrationContent = fs.readFileSync(migrationPath, \"utf-8\");\n\n // Convert to SchemaSnapshot\n const snapshot = convertPocketBaseMigration(migrationContent);\n\n return snapshot;\n } catch (error) {\n // If it's already a SnapshotError, re-throw it\n if (error instanceof SnapshotError) {\n throw error;\n }\n\n // Handle file system errors\n if ((error as any).code === \"ENOENT\") {\n throw new SnapshotError(\n `Base migration file not found: ${migrationPath}\\n\\n` +\n `This file should contain PocketBase's initial schema.\\n` +\n `Please ensure PocketBase is properly set up by running 'yarn setup'.`,\n migrationPath,\n \"read\",\n error as Error\n );\n }\n\n if ((error as any).code === \"EACCES\" || (error as any).code === \"EPERM\") {\n throw new FileSystemError(\n `Permission denied reading base migration file. Check file permissions.`,\n migrationPath,\n \"read\",\n (error as any).code,\n error as Error\n );\n }\n\n // Other errors\n throw new SnapshotError(\n `Failed to load base migration: ${error instanceof Error ? error.message : String(error)}`,\n migrationPath,\n \"read\",\n error instanceof Error ? error : undefined\n );\n }\n}\n\n/**\n * Gets the current snapshot version\n */\nexport function getSnapshotVersion(): string {\n return SNAPSHOT_VERSION;\n}\n\n/**\n * Validates a snapshot against the current version\n * Returns validation result with any issues found\n */\nexport function validateSnapshot(snapshot: SchemaSnapshot): { valid: boolean; issues: string[] } {\n const issues: string[] = [];\n\n // Check version\n if (!snapshot.version) {\n issues.push(\"Missing version field\");\n } else if (compareVersions(snapshot.version, SNAPSHOT_VERSION) > 0) {\n issues.push(`Snapshot version ${snapshot.version} is newer than supported version ${SNAPSHOT_VERSION}`);\n }\n\n // Check timestamp\n if (!snapshot.timestamp) {\n issues.push(\"Missing timestamp field\");\n }\n\n // Check collections\n if (!snapshot.collections) {\n issues.push(\"Missing collections field\");\n } else if (!(snapshot.collections instanceof Map)) {\n issues.push(\"Collections field is not a Map\");\n }\n\n return {\n valid: issues.length === 0,\n issues,\n };\n}\n\n/**\n * Re-exports convertPocketBaseMigration for backward compatibility\n */\nexport { convertPocketBaseMigration } from \"./pocketbase-converter\";\n\n/**\n * SnapshotManager class for object-oriented usage\n * Provides a stateful interface for snapshot management\n */\nexport class SnapshotManager {\n private config: SnapshotConfig;\n\n constructor(config: SnapshotConfig = {}) {\n this.config = mergeConfig(config);\n }\n\n /**\n * Loads the current snapshot\n */\n loadSnapshot(): SchemaSnapshot {\n return loadSnapshot(this.config);\n }\n\n /**\n * Saves a schema as a snapshot\n */\n saveSnapshot(schema: SchemaDefinition): void {\n saveSnapshot(schema, this.config);\n }\n\n /**\n * Loads snapshot if it exists, returns null otherwise\n */\n loadSnapshotIfExists(): SchemaSnapshot | null {\n return loadSnapshotIfExists(this.config);\n }\n\n /**\n * Checks if a snapshot exists\n */\n snapshotExists(): boolean {\n return snapshotExists(this.config);\n }\n\n /**\n * Converts a PocketBase migration to a snapshot\n */\n convertPocketBaseMigration(content: string): SchemaSnapshot {\n return convertPocketBaseMigration(content);\n }\n\n /**\n * Gets the snapshot file path\n */\n getSnapshotPath(): string {\n return getSnapshotPath(this.config);\n }\n\n /**\n * Validates a snapshot\n */\n validateSnapshot(snapshot: SchemaSnapshot): { valid: boolean; issues: string[] } {\n return validateSnapshot(snapshot);\n }\n}\n","/**\n * Validation and warning utilities for migration tool\n * Detects destructive changes and provides warnings\n */\n\nimport type { SchemaDiff } from \"./types\";\n\n/**\n * Types of destructive changes\n */\nexport enum DestructiveChangeType {\n COLLECTION_DELETION = \"collection_deletion\",\n FIELD_DELETION = \"field_deletion\",\n FIELD_TYPE_CHANGE = \"field_type_change\",\n FIELD_REQUIRED_CHANGE = \"field_required_change\",\n}\n\n/**\n * Represents a destructive change with details\n */\nexport interface DestructiveChange {\n type: DestructiveChangeType;\n description: string;\n collection: string;\n field?: string;\n details?: {\n oldValue?: any;\n newValue?: any;\n };\n severity: \"high\" | \"medium\" | \"low\";\n warning: string;\n}\n\n/**\n * Detects collection deletions\n *\n * @param diff - Schema diff\n * @returns Array of destructive changes for collection deletions\n */\nfunction detectCollectionDeletions(diff: SchemaDiff): DestructiveChange[] {\n const changes: DestructiveChange[] = [];\n\n for (const collection of diff.collectionsToDelete) {\n changes.push({\n type: DestructiveChangeType.COLLECTION_DELETION,\n description: `Delete collection: ${collection.name}`,\n collection: collection.name,\n severity: \"high\",\n warning: `All data in the \"${collection.name}\" collection will be permanently deleted.`,\n });\n }\n\n return changes;\n}\n\n/**\n * Detects field deletions\n *\n * @param diff - Schema diff\n * @returns Array of destructive changes for field deletions\n */\nfunction detectFieldDeletions(diff: SchemaDiff): DestructiveChange[] {\n const changes: DestructiveChange[] = [];\n\n for (const modification of diff.collectionsToModify) {\n for (const field of modification.fieldsToRemove) {\n changes.push({\n type: DestructiveChangeType.FIELD_DELETION,\n description: `Delete field: ${modification.collection}.${field.name}`,\n collection: modification.collection,\n field: field.name,\n severity: \"high\",\n warning: `All data in the \"${field.name}\" field of \"${modification.collection}\" will be permanently deleted.`,\n });\n }\n }\n\n return changes;\n}\n\n/**\n * Detects field type changes\n *\n * @param diff - Schema diff\n * @returns Array of destructive changes for field type changes\n */\nfunction detectFieldTypeChanges(diff: SchemaDiff): DestructiveChange[] {\n const changes: DestructiveChange[] = [];\n\n for (const modification of diff.collectionsToModify) {\n for (const fieldMod of modification.fieldsToModify) {\n const typeChange = fieldMod.changes.find((c) => c.property === \"type\");\n\n if (typeChange) {\n changes.push({\n type: DestructiveChangeType.FIELD_TYPE_CHANGE,\n description: `Change field type: ${modification.collection}.${fieldMod.fieldName}`,\n collection: modification.collection,\n field: fieldMod.fieldName,\n details: {\n oldValue: typeChange.oldValue,\n newValue: typeChange.newValue,\n },\n severity: \"high\",\n warning: `Changing field type from \"${typeChange.oldValue}\" to \"${typeChange.newValue}\" may cause data loss or conversion errors.`,\n });\n }\n }\n }\n\n return changes;\n}\n\n/**\n * Detects field required changes (making optional field required)\n *\n * @param diff - Schema diff\n * @returns Array of destructive changes for required field changes\n */\nfunction detectFieldRequiredChanges(diff: SchemaDiff): DestructiveChange[] {\n const changes: DestructiveChange[] = [];\n\n for (const modification of diff.collectionsToModify) {\n for (const fieldMod of modification.fieldsToModify) {\n const requiredChange = fieldMod.changes.find(\n (c) => c.property === \"required\" && c.newValue === true && c.oldValue === false\n );\n\n if (requiredChange) {\n changes.push({\n type: DestructiveChangeType.FIELD_REQUIRED_CHANGE,\n description: `Make field required: ${modification.collection}.${fieldMod.fieldName}`,\n collection: modification.collection,\n field: fieldMod.fieldName,\n details: {\n oldValue: false,\n newValue: true,\n },\n severity: \"medium\",\n warning: `Making \"${fieldMod.fieldName}\" required may cause issues with existing records that have null/empty values.`,\n });\n }\n }\n }\n\n return changes;\n}\n\n/**\n * Detects all destructive changes in a schema diff\n *\n * @param diff - Schema diff to analyze\n * @returns Array of all destructive changes\n */\nexport function detectDestructiveChanges(diff: SchemaDiff): DestructiveChange[] {\n const changes: DestructiveChange[] = [];\n\n // Detect collection deletions\n changes.push(...detectCollectionDeletions(diff));\n\n // Detect field deletions\n changes.push(...detectFieldDeletions(diff));\n\n // Detect field type changes\n changes.push(...detectFieldTypeChanges(diff));\n\n // Detect field required changes\n changes.push(...detectFieldRequiredChanges(diff));\n\n return changes;\n}\n\n/**\n * Checks if a diff contains any destructive changes\n *\n * @param diff - Schema diff to check\n * @returns True if there are destructive changes\n */\nexport function hasDestructiveChanges(diff: SchemaDiff): boolean {\n const changes = detectDestructiveChanges(diff);\n return changes.length > 0;\n}\n\n/**\n * Formats destructive changes for display\n * Groups changes by severity and provides clear warnings\n *\n * @param changes - Array of destructive changes\n * @returns Formatted string for display\n */\nexport function formatDestructiveChanges(changes: DestructiveChange[]): string {\n if (changes.length === 0) {\n return \"No destructive changes detected.\";\n }\n\n const lines: string[] = [];\n\n // Group by severity\n const highSeverity = changes.filter((c) => c.severity === \"high\");\n const mediumSeverity = changes.filter((c) => c.severity === \"medium\");\n const lowSeverity = changes.filter((c) => c.severity === \"low\");\n\n // Display high severity changes\n if (highSeverity.length > 0) {\n lines.push(\"🔴 HIGH SEVERITY CHANGES (Data Loss Risk):\");\n lines.push(\"\");\n for (const change of highSeverity) {\n lines.push(` • ${change.description}`);\n lines.push(` ⚠️ ${change.warning}`);\n if (change.details) {\n if (change.details.oldValue !== undefined && change.details.newValue !== undefined) {\n lines.push(` Old: ${change.details.oldValue} → New: ${change.details.newValue}`);\n }\n }\n lines.push(\"\");\n }\n }\n\n // Display medium severity changes\n if (mediumSeverity.length > 0) {\n lines.push(\"🟡 MEDIUM SEVERITY CHANGES (Potential Issues):\");\n lines.push(\"\");\n for (const change of mediumSeverity) {\n lines.push(` • ${change.description}`);\n lines.push(` ⚠️ ${change.warning}`);\n if (change.details) {\n if (change.details.oldValue !== undefined && change.details.newValue !== undefined) {\n lines.push(` Old: ${change.details.oldValue} → New: ${change.details.newValue}`);\n }\n }\n lines.push(\"\");\n }\n }\n\n // Display low severity changes\n if (lowSeverity.length > 0) {\n lines.push(\"🟢 LOW SEVERITY CHANGES:\");\n lines.push(\"\");\n for (const change of lowSeverity) {\n lines.push(` • ${change.description}`);\n lines.push(` ℹ️ ${change.warning}`);\n lines.push(\"\");\n }\n }\n\n return lines.join(\"\\n\");\n}\n\n/**\n * Generates a summary of destructive changes\n *\n * @param changes - Array of destructive changes\n * @returns Summary object with counts by severity\n */\nexport function summarizeDestructiveChanges(changes: DestructiveChange[]): {\n total: number;\n high: number;\n medium: number;\n low: number;\n} {\n return {\n total: changes.length,\n high: changes.filter((c) => c.severity === \"high\").length,\n medium: changes.filter((c) => c.severity === \"medium\").length,\n low: changes.filter((c) => c.severity === \"low\").length,\n };\n}\n\n/**\n * Checks if force flag is required for the given changes\n * Force is required if there are any high or medium severity changes\n *\n * @param changes - Array of destructive changes\n * @returns True if force flag should be required\n */\nexport function requiresForceFlag(changes: DestructiveChange[]): boolean {\n return changes.some((c) => c.severity === \"high\" || c.severity === \"medium\");\n}\n","/**\n * Configuration loader for migration tool\n * Handles loading and merging configuration from various sources\n */\n\nimport * as fs from \"fs\";\nimport * as path from \"path\";\nimport { ConfigurationError } from \"../../migration/errors.js\";\n\n/**\n * Migration tool configuration\n */\nexport interface MigrationConfig {\n schema: {\n directory: string;\n exclude: string[];\n };\n migrations: {\n directory: string;\n format: string;\n };\n diff: {\n warnOnDelete: boolean;\n requireForceForDestructive: boolean;\n };\n}\n\n/**\n * Partial configuration for merging\n */\nexport type PartialMigrationConfig = {\n schema?: Partial<MigrationConfig[\"schema\"]>;\n migrations?: Partial<MigrationConfig[\"migrations\"]>;\n diff?: Partial<MigrationConfig[\"diff\"]>;\n};\n\n/**\n * Configuration file names to search for\n */\nconst CONFIG_FILE_NAMES = [\n \"pocketbase-migrate.config.js\",\n \"pocketbase-migrate.config.mjs\",\n \"pocketbase-migrate.config.json\",\n \"migrate.config.js\",\n \"migrate.config.mjs\",\n \"migrate.config.json\",\n];\n\n/**\n * Default configuration values\n */\nconst DEFAULT_CONFIG: MigrationConfig = {\n schema: {\n directory: \"src/schema\",\n exclude: [\"base.ts\", \"index.ts\", \"permissions.ts\", \"permission-templates.ts\"],\n },\n migrations: {\n directory: \"pocketbase/pb_migrations\",\n format: \"timestamp_description\",\n },\n diff: {\n warnOnDelete: true,\n requireForceForDestructive: true,\n },\n};\n\n/**\n * Finds a configuration file in the given directory\n */\nfunction findConfigFile(directory: string): string | null {\n for (const fileName of CONFIG_FILE_NAMES) {\n const filePath = path.join(directory, fileName);\n if (fs.existsSync(filePath)) {\n return filePath;\n }\n }\n return null;\n}\n\n/**\n * Loads configuration from a JSON file\n */\nfunction loadJsonConfig(configPath: string): PartialMigrationConfig {\n try {\n const content = fs.readFileSync(configPath, \"utf-8\");\n return JSON.parse(content);\n } catch (error) {\n if (error instanceof SyntaxError) {\n throw new ConfigurationError(\"Invalid JSON syntax in configuration file\", configPath, undefined, error);\n }\n throw new ConfigurationError(\n \"Failed to read configuration file\",\n configPath,\n undefined,\n error instanceof Error ? error : undefined\n );\n }\n}\n\n/**\n * Loads configuration from a JavaScript file\n */\nasync function loadJsConfig(configPath: string): Promise<PartialMigrationConfig> {\n try {\n const fileUrl = `file://${configPath}`;\n const module = await import(fileUrl);\n return module.default || module;\n } catch (error) {\n throw new ConfigurationError(\n \"Failed to load JavaScript configuration file\",\n configPath,\n undefined,\n error instanceof Error ? error : undefined\n );\n }\n}\n\n/**\n * Loads configuration from file if it exists\n */\nasync function loadConfigFile(configPath: string): Promise<PartialMigrationConfig | null> {\n if (!fs.existsSync(configPath)) {\n return null;\n }\n\n const ext = path.extname(configPath).toLowerCase();\n\n if (ext === \".json\") {\n return loadJsonConfig(configPath);\n } else if (ext === \".js\" || ext === \".mjs\") {\n return loadJsConfig(configPath);\n } else {\n throw new ConfigurationError(`Unsupported configuration file format: ${ext}`, configPath, undefined);\n }\n}\n\n/**\n * Merges configuration objects with deep merge\n */\nfunction mergeConfig(base: MigrationConfig, override: PartialMigrationConfig): MigrationConfig {\n return {\n schema: { ...base.schema, ...override.schema },\n migrations: { ...base.migrations, ...override.migrations },\n diff: { ...base.diff, ...override.diff },\n };\n}\n\n/**\n * Loads configuration from environment variables\n */\nfunction loadConfigFromEnv(): PartialMigrationConfig {\n const config: PartialMigrationConfig = {};\n\n if (process.env.MIGRATION_SCHEMA_DIR) {\n config.schema = { directory: process.env.MIGRATION_SCHEMA_DIR };\n }\n\n if (process.env.MIGRATION_SCHEMA_EXCLUDE) {\n config.schema = {\n ...config.schema,\n exclude: process.env.MIGRATION_SCHEMA_EXCLUDE.split(\",\").map((s) => s.trim()),\n };\n }\n\n if (process.env.MIGRATION_OUTPUT_DIR) {\n config.migrations = { directory: process.env.MIGRATION_OUTPUT_DIR };\n }\n\n if (process.env.MIGRATION_REQUIRE_FORCE !== undefined) {\n config.diff = { requireForceForDestructive: process.env.MIGRATION_REQUIRE_FORCE === \"true\" };\n }\n\n return config;\n}\n\n/**\n * Loads configuration from CLI arguments\n */\nexport function loadConfigFromArgs(options: any): PartialMigrationConfig {\n const config: PartialMigrationConfig = {};\n\n if (options.output) {\n config.migrations = { directory: options.output };\n }\n\n if (options.schemaDir) {\n config.schema = { directory: options.schemaDir };\n }\n\n return config;\n}\n\n/**\n * Validates configuration values\n */\nfunction validateConfig(config: MigrationConfig, configPath?: string): void {\n const invalidFields: string[] = [];\n\n if (typeof config.schema.directory !== \"string\" || config.schema.directory.trim() === \"\") {\n invalidFields.push(\"schema.directory (must be a non-empty string)\");\n }\n\n if (!Array.isArray(config.schema.exclude)) {\n invalidFields.push(\"schema.exclude (must be an array of strings)\");\n }\n\n if (typeof config.migrations.directory !== \"string\" || config.migrations.directory.trim() === \"\") {\n invalidFields.push(\"migrations.directory (must be a non-empty string)\");\n }\n\n if (typeof config.diff.warnOnDelete !== \"boolean\") {\n invalidFields.push(\"diff.warnOnDelete (must be a boolean)\");\n }\n\n if (typeof config.diff.requireForceForDestructive !== \"boolean\") {\n invalidFields.push(\"diff.requireForceForDestructive (must be a boolean)\");\n }\n\n if (invalidFields.length > 0) {\n throw new ConfigurationError(\"Invalid configuration values\", configPath, invalidFields);\n }\n\n // Validate schema directory exists - try multiple locations\n const cwd = process.cwd();\n const possiblePaths = [\n path.resolve(cwd, config.schema.directory),\n path.resolve(cwd, \"shared\", config.schema.directory),\n ];\n\n const schemaDir = possiblePaths.find((p) => fs.existsSync(p));\n\n if (!schemaDir) {\n throw new ConfigurationError(`Schema directory not found. Tried: ${possiblePaths.join(\", \")}`, configPath, [\n \"schema.directory\",\n ]);\n }\n}\n\n/**\n * Loads and merges configuration from all sources\n * Priority: CLI args > Environment variables > Config file > Defaults\n */\nexport async function loadConfig(options: any = {}): Promise<MigrationConfig> {\n let config: MigrationConfig = { ...DEFAULT_CONFIG };\n let configFilePath: string | undefined;\n\n const cwd = process.cwd();\n\n // Check for explicit config path from CLI\n if (options.config) {\n const explicitPath = path.resolve(cwd, options.config);\n if (!fs.existsSync(explicitPath)) {\n throw new ConfigurationError(`Configuration file not found: ${explicitPath}`, explicitPath);\n }\n configFilePath = explicitPath;\n } else {\n // Search for config file in current directory and shared directory\n const searchDirs = [cwd, path.join(cwd, \"shared\")];\n\n for (const dir of searchDirs) {\n if (fs.existsSync(dir)) {\n const found = findConfigFile(dir);\n if (found) {\n configFilePath = found;\n break;\n }\n }\n }\n }\n\n // Load config file if found\n if (configFilePath) {\n const fileConfig = await loadConfigFile(configFilePath);\n if (fileConfig) {\n config = mergeConfig(config, fileConfig);\n }\n }\n\n // Merge environment variables\n const envConfig = loadConfigFromEnv();\n if (Object.keys(envConfig).length > 0) {\n config = mergeConfig(config, envConfig);\n }\n\n // Merge CLI arguments (highest priority)\n const argsConfig = loadConfigFromArgs(options);\n if (Object.keys(argsConfig).length > 0) {\n config = mergeConfig(config, argsConfig);\n }\n\n // Validate final configuration\n validateConfig(config, configFilePath);\n\n return config;\n}\n\n/**\n * Gets the absolute path to the schema directory\n */\nexport function getSchemaDirectory(config: MigrationConfig): string {\n const cwd = process.cwd();\n const possiblePaths = [\n path.resolve(cwd, config.schema.directory),\n path.resolve(cwd, \"shared\", config.schema.directory),\n ];\n\n return possiblePaths.find((p) => fs.existsSync(p)) || possiblePaths[0];\n}\n\n/**\n * Gets the absolute path to the migrations directory\n */\nexport function getMigrationsDirectory(config: MigrationConfig): string {\n const cwd = process.cwd();\n const possiblePaths = [\n path.resolve(cwd, config.migrations.directory),\n path.resolve(cwd, \"shared\", config.migrations.directory),\n ];\n\n return possiblePaths.find((p) => fs.existsSync(p)) || possiblePaths[0];\n}\n\n/**\n * Gets the default configuration\n */\nexport function getDefaultConfig(): MigrationConfig {\n return { ...DEFAULT_CONFIG };\n}\n\n/**\n * Creates a sample configuration file content\n */\nexport function getSampleConfig(format: \"json\" | \"js\"): string {\n if (format === \"json\") {\n return JSON.stringify(DEFAULT_CONFIG, null, 2);\n }\n\n return `/**\n * PocketBase Zod Migration Configuration\n * @type {import('pocketbase-zod-schema/cli').MigrationConfig}\n */\nexport default {\n schema: {\n directory: \"/src/schema\",\n exclude: [\"base.ts\", \"index.ts\", \"permissions.ts\", \"permission-templates.ts\"],\n },\n migrations: {\n directory: \"pocketbase/pb_migrations\",\n format: \"timestamp_description\",\n },\n diff: {\n warnOnDelete: true,\n requireForceForDestructive: true,\n },\n};\n`;\n}\n","/**\n * Logging utilities for CLI output\n * Provides colored console output and formatting helpers\n */\n\nimport chalk from \"chalk\";\nimport ora, { type Ora } from \"ora\";\nimport type { FieldChange, SchemaDiff } from \"../../migration/types.js\";\n\n/**\n * Verbosity levels for logging\n */\nexport type VerbosityLevel = \"quiet\" | \"normal\" | \"verbose\";\n\n/**\n * Current verbosity level\n */\nlet currentVerbosity: VerbosityLevel = \"normal\";\n\n/**\n * Sets the verbosity level for logging\n *\n * @param level - Verbosity level to set\n */\nexport function setVerbosity(level: VerbosityLevel): void {\n currentVerbosity = level;\n}\n\n/**\n * Gets the current verbosity level\n *\n * @returns Current verbosity level\n */\nexport function getVerbosity(): VerbosityLevel {\n return currentVerbosity;\n}\n\n/**\n * Checks if output should be shown based on verbosity\n *\n * @param requiredLevel - Minimum verbosity level required\n * @returns True if output should be shown\n */\nfunction shouldLog(requiredLevel: VerbosityLevel): boolean {\n const levels: VerbosityLevel[] = [\"quiet\", \"normal\", \"verbose\"];\n const currentIndex = levels.indexOf(currentVerbosity);\n const requiredIndex = levels.indexOf(requiredLevel);\n return currentIndex >= requiredIndex;\n}\n\n/**\n * Creates a spinner for long-running operations\n *\n * @param text - Initial spinner text\n * @returns Ora spinner instance\n */\nexport function createSpinner(text: string): Ora {\n // In quiet mode, create a silent spinner\n if (currentVerbosity === \"quiet\") {\n return ora({ text, isSilent: true });\n }\n return ora(text);\n}\n\n/**\n * Logs a success message in green\n *\n * @param message - Message to log\n */\nexport function logSuccess(message: string): void {\n if (shouldLog(\"normal\")) {\n console.log(chalk.green(\"✓\"), message);\n }\n}\n\n/**\n * Logs an error message in red\n * Always shown regardless of verbosity level\n *\n * @param message - Message to log\n */\nexport function logError(message: string): void {\n console.error(chalk.red(\"✗\"), message);\n}\n\n/**\n * Logs a warning message in yellow\n *\n * @param message - Message to log\n */\nexport function logWarning(message: string): void {\n if (shouldLog(\"normal\")) {\n console.warn(chalk.yellow(\"⚠\"), message);\n }\n}\n\n/**\n * Logs an info message in blue\n *\n * @param message - Message to log\n */\nexport function logInfo(message: string): void {\n if (shouldLog(\"normal\")) {\n console.log(chalk.blue(\"ℹ\"), message);\n }\n}\n\n/**\n * Logs a debug message in gray\n * Only shown in verbose mode\n *\n * @param message - Message to log\n */\nexport function logDebug(message: string): void {\n if (shouldLog(\"verbose\")) {\n console.log(chalk.gray(\"⚙\"), chalk.gray(message));\n }\n}\n\n/**\n * Logs a section header\n *\n * @param title - Section title\n */\nexport function logSection(title: string): void {\n if (shouldLog(\"normal\")) {\n console.log();\n console.log(chalk.bold.cyan(title));\n console.log(chalk.cyan(\"─\".repeat(title.length)));\n }\n}\n\n/**\n * Formats a field change for display\n *\n * @param change - Field change object\n * @returns Formatted string\n */\nfunction formatFieldChange(change: FieldChange): string {\n const oldValue = change.oldValue === null ? \"null\" : JSON.stringify(change.oldValue);\n const newValue = change.newValue === null ? \"null\" : JSON.stringify(change.newValue);\n\n return `${change.property}: ${chalk.red(oldValue)} → ${chalk.green(newValue)}`;\n}\n\n/**\n * Formats a change summary for display\n * Creates a formatted, colored summary of detected changes\n *\n * @param diff - Schema diff containing all changes\n * @returns Formatted summary string\n */\nexport function formatChangeSummary(diff: SchemaDiff): string {\n const lines: string[] = [];\n\n // Count total changes\n const totalCollectionsToCreate = diff.collectionsToCreate.length;\n const totalCollectionsToDelete = diff.collectionsToDelete.length;\n const totalCollectionsToModify = diff.collectionsToModify.length;\n\n const totalChanges = totalCollectionsToCreate + totalCollectionsToDelete + totalCollectionsToModify;\n\n if (totalChanges === 0) {\n return chalk.gray(\"No changes detected\");\n }\n\n lines.push(chalk.bold(`Found ${totalChanges} collection change(s):`));\n lines.push(\"\");\n\n // New collections\n if (totalCollectionsToCreate > 0) {\n lines.push(chalk.green.bold(`✓ ${totalCollectionsToCreate} collection(s) to create:`));\n for (const collection of diff.collectionsToCreate) {\n lines.push(chalk.green(` + ${collection.name} (${collection.type})`));\n lines.push(chalk.gray(` ${collection.fields.length} field(s)`));\n }\n lines.push(\"\");\n }\n\n // Deleted collections\n if (totalCollectionsToDelete > 0) {\n lines.push(chalk.red.bold(`✗ ${totalCollectionsToDelete} collection(s) to delete:`));\n for (const collection of diff.collectionsToDelete) {\n lines.push(chalk.red(` - ${collection.name}`));\n }\n lines.push(\"\");\n }\n\n // Modified collections\n if (totalCollectionsToModify > 0) {\n lines.push(chalk.yellow.bold(`⚡ ${totalCollectionsToModify} collection(s) to modify:`));\n\n for (const modification of diff.collectionsToModify) {\n lines.push(chalk.yellow(` ~ ${modification.collection}`));\n\n // Fields to add\n if (modification.fieldsToAdd.length > 0) {\n lines.push(chalk.green(` + ${modification.fieldsToAdd.length} field(s) to add:`));\n for (const field of modification.fieldsToAdd) {\n lines.push(chalk.green(` + ${field.name} (${field.type})`));\n }\n }\n\n // Fields to remove\n if (modification.fieldsToRemove.length > 0) {\n lines.push(chalk.red(` - ${modification.fieldsToRemove.length} field(s) to remove:`));\n for (const field of modification.fieldsToRemove) {\n lines.push(chalk.red(` - ${field.name}`));\n }\n }\n\n // Fields to modify\n if (modification.fieldsToModify.length > 0) {\n lines.push(chalk.yellow(` ~ ${modification.fieldsToModify.length} field(s) to modify:`));\n for (const fieldMod of modification.fieldsToModify) {\n lines.push(chalk.yellow(` ~ ${fieldMod.fieldName}`));\n for (const change of fieldMod.changes) {\n lines.push(chalk.gray(` ${formatFieldChange(change)}`));\n }\n }\n }\n\n // Indexes\n if (modification.indexesToAdd.length > 0) {\n lines.push(chalk.green(` + ${modification.indexesToAdd.length} index(es) to add`));\n }\n\n if (modification.indexesToRemove.length > 0) {\n lines.push(chalk.red(` - ${modification.indexesToRemove.length} index(es) to remove`));\n }\n\n // Rules\n if (modification.rulesToUpdate.length > 0) {\n lines.push(chalk.yellow(` ~ ${modification.rulesToUpdate.length} rule(s) to update`));\n }\n\n lines.push(\"\");\n }\n }\n\n return lines.join(\"\\n\");\n}\n\n/**\n * Displays a progress indicator for a long operation\n *\n * @param message - Progress message\n * @param operation - Async operation to perform\n * @returns Result of the operation\n */\nexport async function withProgress<T>(message: string, operation: () => Promise<T>): Promise<T> {\n const spinner = createSpinner(message).start();\n\n try {\n const result = await operation();\n spinner.succeed();\n return result;\n } catch (error) {\n spinner.fail();\n throw error;\n }\n}\n\n/**\n * Logs a step in a multi-step process\n *\n * @param step - Current step number\n * @param total - Total number of steps\n * @param message - Step description\n */\nexport function logStep(step: number, total: number, message: string): void {\n if (shouldLog(\"normal\")) {\n const progress = chalk.gray(`[${step}/${total}]`);\n console.log(progress, message);\n }\n}\n\n/**\n * Logs a list of items with bullet points\n *\n * @param items - Items to list\n * @param indent - Indentation level (default: 2)\n */\nexport function logList(items: string[], indent: number = 2): void {\n if (shouldLog(\"normal\")) {\n const padding = \" \".repeat(indent);\n for (const item of items) {\n console.log(`${padding}• ${item}`);\n }\n }\n}\n\n/**\n * Logs a key-value pair\n *\n * @param key - Key name\n * @param value - Value to display\n * @param indent - Indentation level (default: 2)\n */\nexport function logKeyValue(key: string, value: string, indent: number = 2): void {\n if (shouldLog(\"normal\")) {\n const padding = \" \".repeat(indent);\n console.log(`${padding}${chalk.gray(key + \":\")} ${value}`);\n }\n}\n\n/**\n * Logs a table of data\n *\n * @param headers - Column headers\n * @param rows - Data rows\n */\nexport function logTable(headers: string[], rows: string[][]): void {\n if (!shouldLog(\"normal\")) return;\n\n // Calculate column widths\n const widths = headers.map((h, i) => {\n const maxRowWidth = Math.max(...rows.map((r) => (r[i] || \"\").length));\n return Math.max(h.length, maxRowWidth);\n });\n\n // Print header\n const headerLine = headers.map((h, i) => h.padEnd(widths[i])).join(\" \");\n console.log(chalk.bold(headerLine));\n console.log(chalk.gray(\"─\".repeat(headerLine.length)));\n\n // Print rows\n for (const row of rows) {\n const rowLine = row.map((cell, i) => (cell || \"\").padEnd(widths[i])).join(\" \");\n console.log(rowLine);\n }\n}\n\n/**\n * Logs a box with a title and content\n *\n * @param title - Box title\n * @param content - Box content (array of lines)\n */\nexport function logBox(title: string, content: string[]): void {\n if (!shouldLog(\"normal\")) return;\n\n const maxWidth = Math.max(title.length, ...content.map((c) => c.length));\n const border = \"─\".repeat(maxWidth + 2);\n\n console.log();\n console.log(chalk.cyan(`┌${border}┐`));\n console.log(chalk.cyan(\"│ \") + chalk.bold(title.padEnd(maxWidth)) + chalk.cyan(\" │\"));\n console.log(chalk.cyan(`├${border}┤`));\n for (const line of content) {\n console.log(chalk.cyan(\"│ \") + line.padEnd(maxWidth) + chalk.cyan(\" │\"));\n }\n console.log(chalk.cyan(`└${border}┘`));\n}\n\n/**\n * Creates a progress bar string\n *\n * @param current - Current progress value\n * @param total - Total value\n * @param width - Bar width in characters (default: 20)\n * @returns Formatted progress bar string\n */\nexport function createProgressBar(current: number, total: number, width: number = 20): string {\n const percentage = Math.min(100, Math.round((current / total) * 100));\n const filled = Math.round((percentage / 100) * width);\n const empty = width - filled;\n\n const bar = chalk.green(\"█\".repeat(filled)) + chalk.gray(\"░\".repeat(empty));\n return `${bar} ${percentage}%`;\n}\n\n/**\n * Logs a timestamp with a message\n *\n * @param message - Message to log\n */\nexport function logTimestamp(message: string): void {\n if (shouldLog(\"verbose\")) {\n const timestamp = new Date().toISOString();\n console.log(chalk.gray(`[${timestamp}]`), message);\n }\n}\n\n/**\n * Formats a duration in milliseconds to a human-readable string\n *\n * @param ms - Duration in milliseconds\n * @returns Formatted duration string\n */\nexport function formatDuration(ms: number): string {\n if (ms < 1000) {\n return `${ms}ms`;\n } else if (ms < 60000) {\n return `${(ms / 1000).toFixed(1)}s`;\n } else {\n const minutes = Math.floor(ms / 60000);\n const seconds = Math.round((ms % 60000) / 1000);\n return `${minutes}m ${seconds}s`;\n }\n}\n\n/**\n * Logs a timed operation result\n *\n * @param message - Operation description\n * @param startTime - Start time from Date.now()\n */\nexport function logTimed(message: string, startTime: number): void {\n if (shouldLog(\"normal\")) {\n const duration = Date.now() - startTime;\n console.log(chalk.green(\"✓\"), message, chalk.gray(`(${formatDuration(duration)})`));\n }\n}\n\n/**\n * Status output interface for JSON output mode\n */\nexport interface StatusOutput {\n status: \"up-to-date\" | \"changes-pending\" | \"first-time-setup\";\n collections: {\n current: number;\n snapshot: number;\n };\n changes: {\n create: number;\n delete: number;\n modify: number;\n };\n destructive: boolean;\n}\n\n/**\n * Formats status output as JSON\n *\n * @param output - Status output object\n * @returns JSON string\n */\nexport function formatStatusJson(output: StatusOutput): string {\n return JSON.stringify(output, null, 2);\n}\n","/**\n * Generate command implementation\n * Generates migrations from schema changes\n */\n\nimport { Command } from \"commander\";\nimport * as path from \"path\";\nimport { parseSchemaFiles } from \"../../migration/analyzer.js\";\nimport { compare } from \"../../migration/diff.js\";\nimport {\n ConfigurationError,\n FileSystemError,\n MigrationGenerationError,\n SchemaParsingError,\n SnapshotError,\n} from \"../../migration/errors.js\";\nimport { generate } from \"../../migration/generator.js\";\nimport { loadSnapshotWithMigrations } from \"../../migration/snapshot.js\";\nimport {\n detectDestructiveChanges,\n formatDestructiveChanges,\n requiresForceFlag,\n summarizeDestructiveChanges,\n} from \"../../migration/validation.js\";\nimport { getMigrationsDirectory, getSchemaDirectory, loadConfig, type MigrationConfig } from \"../utils/config.js\";\nimport {\n formatChangeSummary,\n logDebug,\n logError,\n logInfo,\n logSection,\n logSuccess,\n logWarning,\n setVerbosity,\n withProgress,\n} from \"../utils/logger.js\";\n\n/**\n * Checks if there are any changes in the diff\n *\n * @param diff - Schema diff to check\n * @returns True if there are changes\n */\nfunction hasChanges(diff: any): boolean {\n return (\n diff.collectionsToCreate.length > 0 || diff.collectionsToDelete.length > 0 || diff.collectionsToModify.length > 0\n );\n}\n\n/**\n * Handles destructive changes with warnings and force flag\n *\n * @param diff - Schema diff containing changes\n * @param config - Migration configuration\n * @param force - Force flag from CLI\n * @returns True if should proceed, false otherwise\n */\nfunction handleDestructiveChanges(diff: any, config: MigrationConfig, force: boolean): boolean {\n // Detect destructive changes\n const destructiveChanges = detectDestructiveChanges(diff);\n\n if (destructiveChanges.length === 0) {\n return true; // No destructive changes, proceed\n }\n\n // Display destructive changes warning\n logSection(\"⚠️ Destructive Changes Detected\");\n console.log();\n\n // Format and display destructive changes\n console.log(formatDestructiveChanges(destructiveChanges));\n\n // Display summary\n const summary = summarizeDestructiveChanges(destructiveChanges);\n console.log(\"Summary:\");\n console.log(` Total: ${summary.total} destructive change(s)`);\n if (summary.high > 0) {\n console.log(` High Severity: ${summary.high}`);\n }\n if (summary.medium > 0) {\n console.log(` Medium Severity: ${summary.medium}`);\n }\n if (summary.low > 0) {\n console.log(` Low Severity: ${summary.low}`);\n }\n console.log();\n\n // Check if force flag is required\n const forceRequired = config.diff.requireForceForDestructive && requiresForceFlag(destructiveChanges);\n\n if (forceRequired && !force) {\n logError(\"Destructive changes require the --force flag to proceed.\");\n console.log();\n logInfo(\"To proceed with these changes, run the command again with --force:\");\n console.log(\" yarn migrate:generate --force\");\n console.log();\n logWarning(\"⚠️ WARNING: Using --force will apply these changes and may result in data loss!\");\n return false;\n }\n\n if (force) {\n logWarning(\"Proceeding with destructive changes (--force flag provided)\");\n console.log();\n }\n\n return true;\n}\n\n/**\n * Executes the generate command\n *\n * @param options - Command options\n */\nexport async function executeGenerate(options: any): Promise<void> {\n try {\n // Set verbosity based on global options\n const parentOpts = options.parent?.opts?.() || {};\n if (parentOpts.verbose) {\n setVerbosity(\"verbose\");\n } else if (parentOpts.quiet) {\n setVerbosity(\"quiet\");\n }\n\n logDebug(\"Starting migration generation...\");\n logDebug(`Options: ${JSON.stringify(options, null, 2)}`);\n\n // Load configuration\n const config = await loadConfig(options);\n\n // Get paths\n const schemaDir = getSchemaDirectory(config);\n const migrationsDir = getMigrationsDirectory(config);\n\n logSection(\"🔍 Analyzing Schema\");\n\n // Parse schema files with full config (including exclude patterns)\n const analyzerConfig = {\n schemaDir,\n excludePatterns: config.schema.exclude,\n useCompiledFiles: false, // Use source files since we're in development/testing\n };\n const currentSchema = await withProgress(\"Parsing Zod schemas...\", () => parseSchemaFiles(analyzerConfig));\n\n logSuccess(`Found ${currentSchema.collections.size} collection(s)`);\n\n // Load previous snapshot from migrations directory and apply subsequent migrations\n logInfo(\"Loading previous snapshot...\");\n const previousSnapshot = loadSnapshotWithMigrations({\n migrationsPath: migrationsDir,\n workspaceRoot: process.cwd(),\n });\n\n if (!previousSnapshot) {\n logInfo(\"No previous snapshot found - treating as empty database (first-time generation)\");\n } else {\n logSuccess(\"Loaded previous snapshot as base reference\");\n }\n\n // Compare schemas\n logSection(\"📊 Comparing Schemas\");\n const diff = compare(currentSchema, previousSnapshot);\n\n // Check if there are any changes\n if (!hasChanges(diff)) {\n logInfo(\"No changes detected\");\n console.log();\n logSuccess(\"Schema is up to date!\");\n return;\n }\n\n // Display change summary\n console.log();\n console.log(formatChangeSummary(diff));\n\n // Handle destructive changes\n if (!handleDestructiveChanges(diff, config, options.force)) {\n process.exit(1);\n }\n\n // Generate migration\n logSection(\"📝 Generating Migration\");\n\n const migrationPaths = await withProgress(\"Creating migration file...\", () =>\n Promise.resolve(generate(diff, migrationsDir))\n );\n\n if (migrationPaths.length === 0) {\n logWarning(\"No migration files were generated (no changes detected).\");\n return;\n }\n\n if (migrationPaths.length === 1) {\n logSuccess(`Migration file created: ${path.basename(migrationPaths[0])}`);\n } else {\n logSuccess(`Created ${migrationPaths.length} migration files`);\n }\n\n // Note: Snapshot is embedded in the generated migration file\n // No separate snapshot file needed\n\n // Display next steps\n logSection(\"✅ Next Steps\");\n console.log();\n console.log(\" 1. Review the generated migration file(s):\");\n migrationPaths.forEach((migrationPath) => {\n console.log(` ${migrationPath}`);\n });\n console.log();\n console.log(\" 2. Apply the migration by running PocketBase:\");\n console.log(\" yarn pb\");\n console.log();\n console.log(\" Or apply migrations manually:\");\n console.log(\" cd pb && ./pocketbase migrate up\");\n console.log();\n } catch (error) {\n // Handle specific error types with helpful messages\n if (error instanceof SchemaParsingError) {\n logError(\"Schema Parsing Error\");\n console.error();\n console.error(error.getDetailedMessage());\n console.error();\n logInfo(\"Suggestions:\");\n console.log(\" • Make sure your schema files are valid Zod schemas\");\n console.log(' • Run \"yarn build\" in the shared workspace to compile TypeScript files');\n console.log(' • Check that schema files export schemas ending with \"Schema\" or \"InputSchema\"');\n } else if (error instanceof SnapshotError) {\n logError(\"Snapshot Error\");\n console.error();\n console.error(error.getDetailedMessage());\n console.error();\n logInfo(\"Suggestions:\");\n console.log(\" • Check that the snapshot file is not corrupted\");\n console.log(\" • Verify file permissions for the snapshot file\");\n console.log(\" • If this is the first run, this error should not occur\");\n } else if (error instanceof MigrationGenerationError) {\n logError(\"Migration Generation Error\");\n console.error();\n console.error(error.getDetailedMessage());\n console.error();\n logInfo(\"Suggestions:\");\n console.log(\" • Check that the migration directory exists and is writable\");\n console.log(\" • Verify you have sufficient disk space\");\n console.log(\" • Check file permissions for the migration directory\");\n } else if (error instanceof FileSystemError) {\n logError(\"File System Error\");\n console.error();\n console.error(error.getDetailedMessage());\n console.error();\n logInfo(\"Suggestions:\");\n console.log(\" • Check file and directory permissions\");\n console.log(\" • Verify you have sufficient disk space\");\n console.log(\" • Ensure the paths are correct and accessible\");\n } else if (error instanceof ConfigurationError) {\n logError(\"Configuration Error\");\n console.error();\n console.error(error.getDetailedMessage());\n console.error();\n logInfo(\"Suggestions:\");\n console.log(\" • Check your configuration file syntax\");\n console.log(\" • Verify all paths are correct and accessible\");\n console.log(\" • Run with --verbose flag for more details\");\n } else {\n // Generic error handling\n logError(`Failed to generate migration: ${error}`);\n if (error instanceof Error && error.stack) {\n console.error();\n console.error(error.stack);\n }\n }\n\n console.error();\n process.exit(1);\n }\n}\n\n/**\n * Creates the generate command\n *\n * @returns Commander command instance\n */\nexport function createGenerateCommand(): Command {\n return new Command(\"generate\")\n .description(\"Generate a migration from schema changes\")\n .option(\"-o, --output <directory>\", \"Output directory for migration files\")\n .option(\"-f, --force\", \"Force generation even with destructive changes\", false)\n .option(\"--dry-run\", \"Show what would be generated without creating files\", false)\n .option(\"--schema-dir <directory>\", \"Directory containing Zod schema files\")\n .addHelpText(\n \"after\",\n `\nExamples:\n $ pocketbase-migrate generate Generate migration from schema changes\n $ pocketbase-migrate generate --force Force generation with destructive changes\n $ pocketbase-migrate generate --dry-run Preview changes without generating files\n $ pocketbase-migrate generate -o ./migrations Specify output directory\n`\n )\n .action(executeGenerate);\n}\n","/**\n * Status command implementation\n * Shows current migration status without generating files\n */\n\nimport chalk from \"chalk\";\nimport { Command } from \"commander\";\nimport { parseSchemaFiles } from \"../../migration/analyzer.js\";\nimport { categorizeChangesBySeverity, compare } from \"../../migration/diff.js\";\nimport { ConfigurationError, SchemaParsingError, SnapshotError } from \"../../migration/errors.js\";\nimport { loadSnapshotWithMigrations } from \"../../migration/snapshot.js\";\nimport type { SchemaDiff } from \"../../migration/types.js\";\nimport { getMigrationsDirectory, getSchemaDirectory, loadConfig } from \"../utils/config.js\";\nimport {\n formatChangeSummary,\n formatStatusJson,\n logDebug,\n logError,\n logInfo,\n logKeyValue,\n logSection,\n logSuccess,\n logTable,\n setVerbosity,\n withProgress,\n type StatusOutput,\n} from \"../utils/logger.js\";\n\n/**\n * Checks if there are any changes in the diff\n *\n * @param diff - Schema diff to check\n * @returns True if there are changes\n */\nfunction hasChanges(diff: SchemaDiff): boolean {\n return (\n diff.collectionsToCreate.length > 0 || diff.collectionsToDelete.length > 0 || diff.collectionsToModify.length > 0\n );\n}\n\n/**\n * Checks if there are any destructive changes\n *\n * @param diff - Schema diff to check\n * @returns True if there are destructive changes\n */\nfunction hasDestructiveChanges(diff: SchemaDiff): boolean {\n const { destructive } = categorizeChangesBySeverity(diff);\n return destructive.length > 0;\n}\n\n/**\n * Creates a status output object for JSON mode\n *\n * @param status - Status type\n * @param currentCount - Current schema collection count\n * @param snapshotCount - Snapshot collection count\n * @param diff - Schema diff (optional)\n * @returns Status output object\n */\nfunction createStatusOutput(\n status: StatusOutput[\"status\"],\n currentCount: number,\n snapshotCount: number,\n diff?: SchemaDiff\n): StatusOutput {\n return {\n status,\n collections: {\n current: currentCount,\n snapshot: snapshotCount,\n },\n changes: {\n create: diff?.collectionsToCreate.length ?? 0,\n delete: diff?.collectionsToDelete.length ?? 0,\n modify: diff?.collectionsToModify.length ?? 0,\n },\n destructive: diff ? hasDestructiveChanges(diff) : false,\n };\n}\n\n/**\n * Displays destructive changes summary\n *\n * @param diff - Schema diff containing changes\n */\nfunction displayDestructiveChangesSummary(diff: SchemaDiff): void {\n const { destructive, nonDestructive } = categorizeChangesBySeverity(diff);\n\n if (destructive.length > 0) {\n logSection(\"⚠️ Destructive Changes\");\n console.log();\n for (const change of destructive) {\n console.log(chalk.red(` ${change}`));\n }\n console.log();\n }\n\n if (nonDestructive.length > 0) {\n logSection(\"✓ Non-Destructive Changes\");\n console.log();\n for (const change of nonDestructive) {\n console.log(chalk.green(` ${change}`));\n }\n console.log();\n }\n}\n\n/**\n * Displays a detailed change table\n *\n * @param diff - Schema diff containing changes\n */\nfunction displayChangeTable(diff: SchemaDiff): void {\n const rows: string[][] = [];\n\n // Add collections to create\n for (const collection of diff.collectionsToCreate) {\n rows.push([\n chalk.green(\"+\"),\n collection.name,\n collection.type,\n `${collection.fields.length} fields`,\n chalk.green(\"Create\"),\n ]);\n }\n\n // Add collections to delete\n for (const collection of diff.collectionsToDelete) {\n rows.push([chalk.red(\"-\"), collection.name, collection.type || \"base\", \"-\", chalk.red(\"Delete\")]);\n }\n\n // Add collections to modify\n for (const mod of diff.collectionsToModify) {\n const changes: string[] = [];\n if (mod.fieldsToAdd.length > 0) changes.push(`+${mod.fieldsToAdd.length} fields`);\n if (mod.fieldsToRemove.length > 0) changes.push(`-${mod.fieldsToRemove.length} fields`);\n if (mod.fieldsToModify.length > 0) changes.push(`~${mod.fieldsToModify.length} fields`);\n if (mod.indexesToAdd.length > 0) changes.push(`+${mod.indexesToAdd.length} indexes`);\n if (mod.indexesToRemove.length > 0) changes.push(`-${mod.indexesToRemove.length} indexes`);\n if (mod.rulesToUpdate.length > 0) changes.push(`~${mod.rulesToUpdate.length} rules`);\n\n rows.push([chalk.yellow(\"~\"), mod.collection, \"-\", changes.join(\", \") || \"No changes\", chalk.yellow(\"Modify\")]);\n }\n\n if (rows.length > 0) {\n logTable([\"\", \"Collection\", \"Type\", \"Changes\", \"Action\"], rows);\n }\n}\n\n/**\n * Executes the status command\n *\n * @param options - Command options\n */\nexport async function executeStatus(options: any): Promise<void> {\n const isJsonMode = options.json === true;\n\n try {\n // Set verbosity based on global options (quiet in JSON mode)\n if (isJsonMode) {\n setVerbosity(\"quiet\");\n } else {\n const parentOpts = options.parent?.opts?.() || {};\n if (parentOpts.verbose) {\n setVerbosity(\"verbose\");\n } else if (parentOpts.quiet) {\n setVerbosity(\"quiet\");\n }\n }\n\n logDebug(\"Checking migration status...\");\n logDebug(`Options: ${JSON.stringify(options, null, 2)}`);\n\n // Load configuration\n const config = await loadConfig(options);\n\n // Get paths\n const schemaDir = getSchemaDirectory(config);\n const migrationsDir = getMigrationsDirectory(config);\n\n logSection(\"🔍 Checking Migration Status\");\n\n // Parse schema files with full config (including exclude patterns)\n const analyzerConfig = {\n schemaDir,\n excludePatterns: config.schema.exclude,\n useCompiledFiles: false, // Use source files since we're in development/testing\n };\n const currentSchema = await withProgress(\"Parsing Zod schemas...\", () => parseSchemaFiles(analyzerConfig));\n\n logSuccess(`Found ${currentSchema.collections.size} collection(s) in schema`);\n\n // Load previous snapshot from migrations directory and apply subsequent migrations\n logInfo(\"Loading previous snapshot...\");\n const previousSnapshot = loadSnapshotWithMigrations({\n migrationsPath: migrationsDir,\n workspaceRoot: process.cwd(),\n });\n\n // Handle first-time setup\n if (!previousSnapshot) {\n if (isJsonMode) {\n const output = createStatusOutput(\"first-time-setup\", currentSchema.collections.size, 0);\n console.log(formatStatusJson(output));\n return;\n }\n\n logSection(\"🆕 First-Time Setup Detected\");\n console.log();\n logInfo(\"No previous snapshot found. This appears to be a first-time setup.\");\n console.log();\n logKeyValue(\"Collections in schema\", String(currentSchema.collections.size));\n console.log();\n logInfo('Run \"pocketbase-migrate generate\" to create the initial migration.');\n return;\n }\n\n logSuccess(`Loaded snapshot with ${previousSnapshot.collections.size} collection(s)`);\n\n // Compare schemas\n logSection(\"📊 Schema Comparison\");\n const diff = compare(currentSchema, previousSnapshot);\n\n // Check if there are any changes\n if (!hasChanges(diff)) {\n if (isJsonMode) {\n const output = createStatusOutput(\n \"up-to-date\",\n currentSchema.collections.size,\n previousSnapshot.collections.size,\n diff\n );\n console.log(formatStatusJson(output));\n return;\n }\n\n console.log();\n logSuccess(\"✓ Schema is in sync with snapshot\");\n logInfo(\"No pending changes detected\");\n console.log();\n logKeyValue(\"Collections\", String(currentSchema.collections.size));\n return;\n }\n\n // Handle JSON output mode\n if (isJsonMode) {\n const output = createStatusOutput(\n \"changes-pending\",\n currentSchema.collections.size,\n previousSnapshot.collections.size,\n diff\n );\n console.log(formatStatusJson(output));\n return;\n }\n\n // Display change summary\n console.log();\n console.log(formatChangeSummary(diff));\n\n // Display change table in verbose mode\n logDebug(\"Detailed change table:\");\n displayChangeTable(diff);\n\n // Display categorized changes\n displayDestructiveChangesSummary(diff);\n\n // Display next steps\n logSection(\"📝 Next Steps\");\n console.log();\n console.log(\" To generate a migration for these changes, run:\");\n console.log(chalk.cyan(\" pocketbase-migrate generate\"));\n console.log();\n\n const { destructive } = categorizeChangesBySeverity(diff);\n if (destructive.length > 0) {\n console.log(chalk.yellow(\" ⚠️ Destructive changes detected. Use --force flag when generating:\"));\n console.log(chalk.cyan(\" pocketbase-migrate generate --force\"));\n console.log();\n }\n } catch (error) {\n // Handle specific error types with helpful messages\n if (error instanceof SchemaParsingError) {\n logError(\"Schema Parsing Error\");\n console.error();\n console.error(error.getDetailedMessage());\n console.error();\n logInfo(\"Suggestions:\");\n console.log(\" • Make sure your schema files are valid Zod schemas\");\n console.log(' • Check that schema files export schemas ending with \"Schema\" or \"InputSchema\"');\n } else if (error instanceof SnapshotError) {\n logError(\"Snapshot Error\");\n console.error();\n console.error(error.getDetailedMessage());\n console.error();\n logInfo(\"Suggestions:\");\n console.log(\" • Check that the snapshot file is not corrupted\");\n console.log(\" • Verify file permissions for the snapshot file\");\n } else if (error instanceof ConfigurationError) {\n logError(\"Configuration Error\");\n console.error();\n console.error(error.getDetailedMessage());\n console.error();\n logInfo(\"Suggestions:\");\n console.log(\" • Check your configuration file syntax\");\n console.log(\" • Verify all paths are correct and accessible\");\n } else {\n logError(`Failed to check status: ${error}`);\n if (error instanceof Error && error.stack) {\n console.error(error.stack);\n }\n }\n process.exit(1);\n }\n}\n\n/**\n * Creates the status command\n *\n * @returns Commander command instance\n */\nexport function createStatusCommand(): Command {\n return new Command(\"status\")\n .description(\"Show current migration status without generating files\")\n .option(\"--schema-dir <directory>\", \"Directory containing Zod schema files\")\n .option(\"--json\", \"Output status as JSON for programmatic use\", false)\n .addHelpText(\n \"after\",\n `\nExamples:\n $ pocketbase-migrate status Check for pending schema changes\n $ pocketbase-migrate status --json Output status as JSON\n $ pocketbase-migrate status --verbose Show detailed status information\n`\n )\n .action(executeStatus);\n}\n","#!/usr/bin/env node\n\n/**\n * CLI entry point for the migration tool\n * Schema-driven PocketBase migration generator\n */\n\n// Register tsx loader for TypeScript file support\n// This must be imported first to enable TypeScript file loading via dynamic imports\n// tsx/esm registers hooks that allow Node.js to handle .ts files in dynamic imports\nimport \"tsx/esm\";\n\nimport chalk from \"chalk\";\nimport { Command } from \"commander\";\nimport { readFileSync } from \"fs\";\nimport { dirname, join } from \"path\";\nimport { fileURLToPath } from \"url\";\nimport { createGenerateCommand } from \"./commands/generate.js\";\nimport { createStatusCommand } from \"./commands/status.js\";\n\n// Get package version from package.json\nfunction getVersion(): string {\n try {\n // Get the directory of the current file\n const __filename = fileURLToPath(import.meta.url);\n const __dirname = dirname(__filename);\n\n // Resolve path to package.json (works from both src and dist)\n // From dist/cli/migrate.js -> ../../package.json\n // From src/cli/migrate.ts -> ../../package.json\n const packageJsonPath = join(__dirname, \"../../package.json\");\n const packageJson = JSON.parse(readFileSync(packageJsonPath, \"utf-8\"));\n return packageJson.version || \"0.0.0\";\n } catch {\n // Fallback version if package.json cannot be read\n console.warn(\"Warning: Could not read version from package.json\");\n return \"0.0.0\";\n }\n}\n\nconst VERSION = getVersion();\n\n/**\n * Display banner with tool name and version\n */\nfunction displayBanner(): void {\n console.log();\n console.log(chalk.cyan.bold(\" PocketBase Zod Migration Tool\"));\n console.log(chalk.gray(` Version ${VERSION}`));\n console.log();\n}\n\n/**\n * Main CLI program\n */\nconst program = new Command();\n\n// Configure main program\nprogram\n .name(\"pocketbase-migrate\")\n .description(\n \"Schema-driven PocketBase migration tool\\n\\nGenerate type-safe migrations from Zod schemas for PocketBase applications.\"\n )\n .version(VERSION, \"-v, --version\", \"Output the current version\")\n .option(\"-c, --config <path>\", \"Path to configuration file\")\n .option(\"--verbose\", \"Enable verbose output\")\n .option(\"--quiet\", \"Suppress non-essential output\")\n .option(\"--no-color\", \"Disable colored output\")\n .hook(\"preAction\", (thisCommand) => {\n // Handle global options before any command runs\n const opts = thisCommand.opts();\n\n // Handle no-color option\n if (opts.color === false) {\n chalk.level = 0;\n }\n\n // Display banner unless quiet mode\n if (!opts.quiet) {\n displayBanner();\n }\n });\n\n// Add commands\nprogram.addCommand(createGenerateCommand());\nprogram.addCommand(createStatusCommand());\n\n// Add examples to help output\nprogram.addHelpText(\n \"after\",\n `\n${chalk.bold(\"Examples:\")}\n $ pocketbase-migrate status Check for pending schema changes\n $ pocketbase-migrate generate Generate migration from schema changes\n $ pocketbase-migrate generate --force Generate migration with destructive changes\n $ pocketbase-migrate --help Show this help message\n\n${chalk.bold(\"Configuration:\")}\n The tool looks for configuration in the following order:\n 1. CLI arguments (highest priority)\n 2. Environment variables (MIGRATION_SCHEMA_DIR, MIGRATION_OUTPUT_DIR, etc.)\n 3. Configuration file (migrate.config.js)\n 4. Default values\n\n${chalk.bold(\"Documentation:\")}\n For more information, visit: https://github.com/dastron/pocketbase-zod-schema\n`\n);\n\n// Custom error handling\nprogram.exitOverride((err) => {\n /**\n * Commander throws on help/version when exitOverride is enabled.\n * The error codes differ by commander version (e.g. \"commander.helpDisplayed\").\n * Respect the exitCode whenever it is provided.\n */\n const anyErr = err as any;\n\n // Common help/version codes across commander versions\n if (anyErr?.code === \"commander.help\" || anyErr?.code === \"commander.helpDisplayed\") {\n process.exit(0);\n }\n if (anyErr?.code === \"commander.version\") {\n process.exit(0);\n }\n\n // Prefer commander-provided exitCode if present\n if (typeof anyErr?.exitCode === \"number\") {\n process.exit(anyErr.exitCode);\n }\n\n process.exit(1);\n});\n\n// Display help if no command provided\nif (process.argv.length === 2) {\n displayBanner();\n program.help();\n}\n\n// Parse command line arguments\nprogram.parse(process.argv);\n"]}
1
+ {"version":3,"sources":["../../../node_modules/tsup/assets/cjs_shims.js","../../src/schema/base.ts","../../src/schema/fields.ts","../../src/migration/errors.ts","../../src/utils/permission-templates.ts","../../src/migration/rule-validator.ts","../../src/migration/permission-analyzer.ts","../../src/migration/utils/pluralize.ts","../../src/migration/utils/relation-detector.ts","../../src/migration/utils/type-mapper.ts","../../src/migration/analyzer.ts","../../src/migration/utils/collection-id-generator.ts","../../src/migration/diff.ts","../../src/migration/generator.ts","../../src/migration/pocketbase-converter.ts","../../src/migration/migration-parser.ts","../../src/migration/snapshot.ts","../../src/migration/validation.ts","../../src/cli/utils/config.ts","../../src/cli/utils/logger.ts","../../src/cli/commands/generate.ts","../../src/cli/commands/status.ts","../../src/cli/migrate.ts"],"names":["z","path","isAuthCollection","fs","ext","required","options","fieldDef","relationMetadata","randomBytes","DEFAULT_CONFIG","mergeConfig","path2","fs2","hasChanges","extractFieldOptions","fs3","path3","fs4","path4","migrationContent","path5","fs5","ora","chalk","path6","Command","__filename","fileURLToPath","dirname","join","readFileSync"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,IAAM,gBAAA,GAAmB,MACvB,OAAO,QAAA,KAAa,WAAA,GAChB,IAAI,GAAA,CAAI,CAAA,KAAA,EAAQ,UAAU,CAAA,CAAE,CAAA,CAAE,IAAA,GAC7B,QAAA,CAAS,aAAA,IAAiB,QAAA,CAAS,aAAA,CAAc,OAAA,CAAQ,WAAA,EAAY,KAAM,QAAA,GAC1E,QAAA,CAAS,aAAA,CAAc,GAAA,GACvB,IAAI,GAAA,CAAI,SAAA,EAAW,QAAA,CAAS,OAAO,CAAA,CAAE,IAAA;AAEtC,IAAM,gCAAgC,gBAAA,EAAiB;CCLpC;AAAA,EACxB,EAAA,EAAIA,KAAA,CAAE,MAAA,EAAO,CAAE,SAAS,WAAW,CAAA;AAAA,EACnC,YAAA,EAAcA,KAAA,CAAE,MAAA,EAAO,CAAE,SAAS,eAAe,CAAA;AAAA,EACjD,cAAA,EAAgBA,KAAA,CAAE,MAAA,EAAO,CAAE,SAAS,iBAAiB,CAAA;AAAA,EACrD,MAAA,EAAQA,MAAE,MAAA,CAAOA,KAAA,CAAE,KAAK,CAAA,CAAE,SAAS,mBAAmB,CAAA;AAAA,EACtD,OAAA,EAASA,KAAA,CAAE,MAAA,EAAO,CAAE,SAAS,oBAAoB,CAAA;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A,sBAAAA,CAAM,IAAA,CAAK,gBAAgB,CAAC;AAAA;AAAA;AAG9B,CAAA;AAGA,OAAA,CAAQ,YAAA,CAAa,CAAC,GAAA,KAAQ;AAM5B,EAAA,MAAM,MAAA,GAAS,GAAA;AAGf,EAAA,IAAI,MAAA,EAAQ,IAAA,KAAS,gBAAA,IAAoB,MAAA,EAAQ,SAAS,yBAAA,EAA2B;AACnF,IAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,EAChB;AACA,EAAA,IAAI,MAAA,EAAQ,SAAS,mBAAA,EAAqB;AACxC,IAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,EAChB;AAGA,EAAA,IAAI,OAAO,MAAA,EAAQ,QAAA,KAAa,QAAA,EAAU;AACxC,IAAA,OAAA,CAAQ,IAAA,CAAK,OAAO,QAAQ,CAAA;AAAA,EAC9B;AAEA,EAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAChB,CAAC,CAAA;AAGD,IAAI,OAAA,CAAQ,IAAA,CAAK,MAAA,KAAW,CAAA,EAAG;AAC7B,EAAA,aAAA,EAAc;AACd,EAAA,OAAA,CAAQ,IAAA,EAAK;AACf;AAGA,OAAA,CAAQ,KAAA,CAAM,QAAQ,IAAI,CAAA","file":"migrate.cjs","sourcesContent":["// Shim globals in cjs bundle\n// There's a weird bug that esbuild will always inject importMetaUrl\n// if we export it as `const importMetaUrl = ... __filename ...`\n// But using a function will not cause this issue\n\nconst getImportMetaUrl = () => \n typeof document === \"undefined\" \n ? new URL(`file:${__filename}`).href \n : (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT') \n ? document.currentScript.src \n : new URL(\"main.js\", document.baseURI).href;\n\nexport const importMetaUrl = /* @__PURE__ */ getImportMetaUrl()\n","import { z } from \"zod\";\nimport type { PermissionSchema, PermissionTemplateConfig } from \"../utils/permissions\";\n\n/**\n * Base schema fields that PocketBase automatically adds to all records\n * These fields are managed by PocketBase and should not be set manually\n */\nexport const baseSchema = {\n id: z.string().describe(\"unique id\"),\n collectionId: z.string().describe(\"collection id\"),\n collectionName: z.string().describe(\"collection name\"),\n expand: z.record(z.any()).describe(\"expandable fields\"),\n created: z.string().describe(\"creation timestamp\"),\n updated: z.string().describe(\"last update timestamp\"),\n};\n\n/**\n * Extended base schema with timestamp fields\n * Includes created and updated autodate fields\n */\nexport const baseSchemaWithTimestamps = {\n ...baseSchema,\n created: z.string().describe(\"creation timestamp\"),\n updated: z.string().describe(\"last update timestamp\"),\n};\n\n/**\n * Base schema for image file collections\n * Extends base schema with thumbnail URL and image files array\n */\nexport const baseImageFileSchema = {\n ...baseSchema,\n thumbnailURL: z.string().optional(),\n imageFiles: z.array(z.string()),\n};\n\n/**\n * Input schema for image file uploads\n * Used in forms where users upload File objects\n * Requires Node.js 20+ or browser environment with File API\n */\nexport const inputImageFileSchema = {\n imageFiles: z.array(z.instanceof(File)),\n};\n\n/**\n * Helper constant for omitting image files from schemas\n * Used with Zod's .omit() method\n */\nexport const omitImageFilesSchema = {\n imageFiles: true,\n} as const;\n\n// ============================================================================\n// Common PocketBase Field Type Patterns\n// ============================================================================\n// Note: Field type helpers are now exported from ./fields.ts with PascalCase names\n// (e.g., TextField, EmailField, JSONField, etc.) to ensure consistent naming.\n\n// ============================================================================\n// Relation Field Helpers - Explicit Relationship Definitions\n// ============================================================================\n\n/**\n * Relation field configuration options\n */\nexport interface RelationConfig {\n /**\n * Target collection name (e.g., 'users', 'posts', 'tags')\n * This is the PocketBase collection that the relation points to\n */\n collection: string;\n\n /**\n * Whether to cascade delete related records when this record is deleted\n * @default false\n */\n cascadeDelete?: boolean;\n}\n\n/**\n * Multiple relation field configuration options\n */\nexport interface RelationsConfig extends RelationConfig {\n /**\n * Minimum number of relations required\n * @default 0\n */\n minSelect?: number;\n\n /**\n * Maximum number of relations allowed\n * @default 999\n */\n maxSelect?: number;\n}\n\n/**\n * Internal marker for relation metadata\n * Used by the analyzer to detect explicit relation definitions\n */\nconst RELATION_METADATA_KEY = \"__pocketbase_relation__\";\n\n/**\n * Creates a single relation field schema with explicit collection target\n * Maps to PocketBase 'relation' field type with maxSelect=1\n *\n * This is the recommended way to define relations - it's explicit and doesn't\n * rely on naming conventions.\n *\n * @param config - Relation configuration with target collection\n * @returns Zod string schema with relation metadata\n *\n * @example\n * // Single relation to users collection\n * const PostSchema = z.object({\n * title: z.string(),\n * author: RelationField({ collection: 'users' }),\n * });\n *\n * @example\n * // Relation with cascade delete\n * const CommentSchema = z.object({\n * content: z.string(),\n * post: RelationField({ collection: 'posts', cascadeDelete: true }),\n * });\n */\nexport function RelationField(config: RelationConfig) {\n const metadata = {\n [RELATION_METADATA_KEY]: {\n type: \"single\",\n collection: config.collection,\n cascadeDelete: config.cascadeDelete ?? false,\n maxSelect: 1,\n minSelect: 0,\n },\n };\n\n return z.string().describe(JSON.stringify(metadata));\n}\n\n/**\n * Creates a multiple relation field schema with explicit collection target\n * Maps to PocketBase 'relation' field type with maxSelect>1\n *\n * This is the recommended way to define multi-relations - it's explicit and\n * doesn't rely on naming conventions.\n *\n * @param config - Relations configuration with target collection and limits\n * @returns Zod array of strings schema with relation metadata\n *\n * @example\n * // Multiple relations to tags collection\n * const PostSchema = z.object({\n * title: z.string(),\n * tags: RelationsField({ collection: 'tags' }),\n * });\n *\n * @example\n * // Relations with min/max constraints\n * const ProjectSchema = z.object({\n * title: z.string(),\n * collaborators: RelationsField({\n * collection: 'users',\n * minSelect: 1,\n * maxSelect: 10,\n * }),\n * });\n */\nexport function RelationsField(config: RelationsConfig) {\n const metadata = {\n [RELATION_METADATA_KEY]: {\n type: \"multiple\",\n collection: config.collection,\n cascadeDelete: config.cascadeDelete ?? false,\n maxSelect: config.maxSelect ?? 999,\n minSelect: config.minSelect ?? 0,\n },\n };\n\n let schema = z.array(z.string());\n\n // Apply array constraints for Zod validation\n if (config.minSelect !== undefined) {\n schema = schema.min(config.minSelect);\n }\n if (config.maxSelect !== undefined) {\n schema = schema.max(config.maxSelect);\n }\n\n return schema.describe(JSON.stringify(metadata));\n}\n\n/**\n * Extracts relation metadata from a Zod type's description\n * Used internally by the analyzer to detect explicit relation definitions\n *\n * @param description - The Zod type's description string\n * @returns Relation metadata if present, null otherwise\n */\nexport function extractRelationMetadata(description: string | undefined): {\n type: \"single\" | \"multiple\";\n collection: string;\n cascadeDelete: boolean;\n maxSelect: number;\n minSelect: number;\n} | null {\n if (!description) return null;\n\n try {\n const parsed = JSON.parse(description);\n if (parsed[RELATION_METADATA_KEY]) {\n return parsed[RELATION_METADATA_KEY];\n }\n } catch {\n // Not JSON, ignore\n }\n\n return null;\n}\n\n/**\n * Attach permission metadata to a Zod schema\n *\n * This helper function allows you to define PocketBase API rules alongside your\n * entity schema definitions. The permissions are stored as metadata using Zod's\n * describe() method and will be extracted during migration generation.\n *\n * @param schema - The Zod schema to attach permissions to\n * @param config - Either a PermissionTemplateConfig (for template-based permissions)\n * or a PermissionSchema (for custom permissions)\n * @returns The schema with permission metadata attached\n *\n * @example\n * // Using a template\n * const ProjectSchema = withPermissions(\n * z.object({ title: z.string(), User: z.string() }),\n * { template: 'owner-only', ownerField: 'User' }\n * );\n *\n * @example\n * // Using custom rules\n * const ProjectSchema = withPermissions(\n * z.object({ title: z.string() }),\n * { listRule: '@request.auth.id != \"\"', viewRule: '' }\n * );\n *\n * @example\n * // Using template with custom rule overrides\n * const ProjectSchema = withPermissions(\n * z.object({ title: z.string(), User: z.string() }),\n * {\n * template: 'owner-only',\n * ownerField: 'User',\n * customRules: { listRule: '@request.auth.id != \"\"' }\n * }\n * );\n */\nexport function withPermissions<T extends z.ZodTypeAny>(\n schema: T,\n config: PermissionTemplateConfig | PermissionSchema\n): T {\n // Create metadata object with permissions config directly\n // The PermissionAnalyzer will handle resolving templates vs direct schemas\n const metadata = {\n permissions: config,\n };\n\n // Attach permission metadata to schema using Zod's describe() method\n // The metadata is serialized as JSON and stored in the schema's description\n return schema.describe(JSON.stringify(metadata)) as T;\n}\n\n/**\n * Attach index definitions to a Zod schema\n *\n * This helper function allows you to define PocketBase indexes alongside your\n * entity schema definitions. The indexes are stored as metadata using Zod's\n * describe() method and will be extracted during migration generation.\n *\n * @param schema - The Zod schema to attach indexes to\n * @param indexes - Array of PocketBase index SQL statements\n * @returns The schema with index metadata attached\n *\n * @example\n * // Define indexes for a user schema\n * const UserSchema = withIndexes(\n * withPermissions(\n * z.object({ name: z.string(), email: z.string().email() }),\n * userPermissions\n * ),\n * [\n * 'CREATE UNIQUE INDEX idx_users_email ON users (email)',\n * 'CREATE INDEX idx_users_name ON users (name)'\n * ]\n * );\n *\n * @example\n * // Single index\n * const ProjectSchema = withIndexes(\n * ProjectDatabaseSchema,\n * ['CREATE INDEX idx_projects_status ON projects (status)']\n * );\n */\nexport function withIndexes<T extends z.ZodTypeAny>(schema: T, indexes: string[]): T {\n // Extract existing metadata if present\n let existingMetadata: any = {};\n\n if (schema.description) {\n try {\n existingMetadata = JSON.parse(schema.description);\n } catch {\n // If description is not JSON, ignore it\n }\n }\n\n // Merge indexes with existing metadata\n const metadata = {\n ...existingMetadata,\n indexes,\n };\n\n // Attach metadata to schema using Zod's describe() method\n return schema.describe(JSON.stringify(metadata)) as T;\n}\n\n/**\n * Configuration options for defining a collection\n */\nexport interface CollectionConfig {\n /**\n * The name of the PocketBase collection\n * This will be used when generating migrations\n */\n collectionName: string;\n\n /**\n * The Zod schema definition for the collection\n */\n schema: z.ZodObject<any>;\n\n /**\n * Optional permission configuration\n * Can be a template-based config or custom permission rules\n */\n permissions?: PermissionTemplateConfig | PermissionSchema;\n\n /**\n * Optional array of index SQL statements\n * Example: ['CREATE UNIQUE INDEX idx_users_email ON users (email)']\n */\n indexes?: string[];\n\n /**\n * Optional collection type\n * - \"base\": Standard collection (default)\n * - \"auth\": Authentication collection with system auth fields\n *\n * If not specified, the type will be auto-detected based on field presence\n * (collections with both email and password fields are detected as auth)\n */\n type?: \"base\" | \"auth\";\n\n /**\n * Future extensibility - additional options can be added here\n */\n [key: string]: unknown;\n}\n\n/**\n * High-level wrapper for defining a PocketBase collection with all metadata\n *\n * This is the recommended way to define collections as it provides a single\n * entry point for collection name, schema, permissions, indexes, and future features.\n *\n * @param config - Collection configuration object\n * @returns The schema with all metadata attached\n *\n * @example\n * // Recommended: Use default export for clarity\n * const PostCollection = defineCollection({\n * collectionName: \"posts\",\n * schema: z.object({\n * title: z.string(),\n * content: z.string(),\n * author: RelationField({ collection: \"users\" }),\n * }),\n * permissions: {\n * template: \"owner-only\",\n * ownerField: \"author\",\n * },\n * });\n * export default PostCollection;\n *\n * @example\n * // Also supported: Named export (backward compatible)\n * export const PostCollection = defineCollection({\n * collectionName: \"posts\",\n * schema: z.object({\n * title: z.string(),\n * content: z.string(),\n * author: RelationField({ collection: \"users\" }),\n * }),\n * permissions: {\n * template: \"owner-only\",\n * ownerField: \"author\",\n * },\n * });\n *\n * @example\n * // Collection with permissions and indexes\n * export const UserSchema = defineCollection({\n * collectionName: \"users\",\n * schema: z.object({\n * name: z.string(),\n * email: z.string().email(),\n * }),\n * permissions: {\n * listRule: \"id = @request.auth.id\",\n * viewRule: \"id = @request.auth.id\",\n * createRule: \"\",\n * updateRule: \"id = @request.auth.id\",\n * deleteRule: \"id = @request.auth.id\",\n * },\n * indexes: [\n * \"CREATE UNIQUE INDEX idx_users_email ON users (email)\",\n * ],\n * });\n *\n * @example\n * // Collection with template and custom rule overrides\n * export const ProjectSchema = defineCollection({\n * collectionName: \"projects\",\n * schema: z.object({\n * title: z.string(),\n * owner: RelationField({ collection: \"users\" }),\n * }),\n * permissions: {\n * template: \"owner-only\",\n * ownerField: \"owner\",\n * customRules: {\n * listRule: '@request.auth.id != \"\"',\n * },\n * },\n * });\n */\nexport function defineCollection(config: CollectionConfig): z.ZodObject<any> {\n const { collectionName, schema, permissions, indexes, type, ...futureOptions } = config;\n\n // Build metadata object\n const metadata: any = {\n collectionName,\n };\n\n // Add type if provided\n if (type) {\n metadata.type = type;\n }\n\n // Add permissions if provided\n if (permissions) {\n metadata.permissions = permissions;\n }\n\n // Add indexes if provided\n if (indexes) {\n metadata.indexes = indexes;\n }\n\n // Add any future options\n if (Object.keys(futureOptions).length > 0) {\n Object.assign(metadata, futureOptions);\n }\n\n // Attach all metadata to schema using Zod's describe() method\n return schema.describe(JSON.stringify(metadata)) as z.ZodObject<any>;\n}\n","import { z } from \"zod\";\n\n// ============================================================================\n// Field Metadata System\n// ============================================================================\n\n/**\n * Internal marker for field metadata\n * Used by the migration generator to detect explicit field type definitions\n */\nexport const FIELD_METADATA_KEY = \"__pocketbase_field__\";\n\n/**\n * PocketBase field types\n */\nexport type PocketBaseFieldType =\n | \"text\"\n | \"email\"\n | \"url\"\n | \"editor\"\n | \"number\"\n | \"bool\"\n | \"date\"\n | \"autodate\"\n | \"select\"\n | \"relation\"\n | \"file\"\n | \"json\"\n | \"geoPoint\";\n\n/**\n * Field metadata structure embedded in Zod schema descriptions\n */\nexport interface FieldMetadata {\n type: PocketBaseFieldType;\n options?: Record<string, any>;\n}\n\n/**\n * Extracts field metadata from a Zod type's description\n * Used by the migration generator to detect explicit field type definitions\n *\n * @param description - The Zod type's description string\n * @returns Field metadata if present, null otherwise\n *\n * @example\n * const schema = TextField({ min: 1, max: 100 });\n * const metadata = extractFieldMetadata(schema.description);\n * // Returns: { type: \"text\", options: { min: 1, max: 100 } }\n */\nexport function extractFieldMetadata(description: string | undefined): FieldMetadata | null {\n if (!description) return null;\n\n try {\n const parsed = JSON.parse(description);\n if (parsed[FIELD_METADATA_KEY]) {\n return parsed[FIELD_METADATA_KEY];\n }\n } catch {\n // Not JSON, ignore\n }\n\n return null;\n}\n\n// ============================================================================\n// Field Options Interfaces\n// ============================================================================\n\n/**\n * Text field configuration options\n */\nexport interface TextFieldOptions {\n /**\n * Minimum length constraint\n */\n min?: number;\n\n /**\n * Maximum length constraint\n */\n max?: number;\n\n /**\n * Pattern constraint (regex)\n */\n pattern?: RegExp | string;\n\n /**\n * Auto-generate pattern for automatic value generation\n * Example: \"[A-Z]{3}-[0-9]{6}\" generates values like \"ABC-123456\"\n */\n autogeneratePattern?: string;\n}\n\n/**\n * Number field configuration options\n */\nexport interface NumberFieldOptions {\n /**\n * Minimum value constraint\n */\n min?: number;\n\n /**\n * Maximum value constraint\n */\n max?: number;\n\n /**\n * Whether to disallow decimal values (integers only)\n */\n noDecimal?: boolean;\n\n /**\n * Whether the field is required\n * @default false\n *\n * Note: In PocketBase, `required: true` for number fields means the value must be non-zero.\n * If you want to allow zero values (e.g., for progress: 0-100), keep this as `false`.\n * Set to `true` only if you want to enforce non-zero values.\n */\n required?: boolean;\n}\n\n/**\n * Date field configuration options\n */\nexport interface DateFieldOptions {\n /**\n * Minimum date constraint\n */\n min?: Date | string;\n\n /**\n * Maximum date constraint\n */\n max?: Date | string;\n}\n\n/**\n * Autodate field configuration options\n */\nexport interface AutodateFieldOptions {\n /**\n * Set date automatically on record creation\n * @default false\n */\n onCreate?: boolean;\n\n /**\n * Update date automatically on record update\n * @default false\n */\n onUpdate?: boolean;\n}\n\n/**\n * Select field configuration options\n */\nexport interface SelectFieldOptions {\n /**\n * Maximum number of selections allowed\n * If > 1, enables multiple selection\n * @default 1\n */\n maxSelect?: number;\n}\n\n/**\n * Human-friendly byte size input.\n *\n * - Use a number for raw bytes (e.g. `5242880`)\n * - Use a string with unit suffix for kibibytes/mebibytes/gibibytes (e.g. `\"5M\"`, `\"1G\"`)\n *\n * Supported suffixes: `K`, `M`, `G` (case-insensitive).\n */\nexport type ByteSize = number | `${number}${\"K\" | \"M\" | \"G\" | \"k\" | \"m\" | \"g\"}`;\n\n/**\n * File field configuration options\n */\nexport interface FileFieldOptions {\n /**\n * Allowed MIME types\n * Example: [\"image/*\", \"application/pdf\"]\n */\n mimeTypes?: string[];\n\n /**\n * Maximum file size.\n *\n * - Provide a number for raw bytes\n * - Or use a string with `K`, `M`, `G` suffix (case-insensitive)\n *\n * Max allowed is `8G`.\n *\n * @example\n * maxSize: 5242880\n * maxSize: \"5M\"\n * maxSize: \"1G\"\n */\n maxSize?: ByteSize;\n\n /**\n * Thumbnail sizes to generate\n * Example: [\"100x100\", \"200x200\"]\n * Set to null to explicitly disable thumbnails\n */\n thumbs?: string[];\n\n /**\n * Whether the file is protected (requires auth to access)\n * @default false\n */\n protected?: boolean;\n}\n\n/**\n * Multiple files field configuration options\n */\nexport interface FilesFieldOptions extends FileFieldOptions {\n /**\n * Minimum number of files required\n */\n minSelect?: number;\n\n /**\n * Maximum number of files allowed\n */\n maxSelect?: number;\n}\n\nconst MAX_FILE_SIZE_BYTES = 8 * 1024 * 1024 * 1024; // 8G\n\nfunction parseByteSizeToBytes(value: ByteSize, context: string): number {\n let bytes: number;\n\n if (typeof value === \"number\") {\n if (!Number.isFinite(value)) {\n throw new Error(`${context}: maxSize must be a finite number of bytes`);\n }\n bytes = Math.round(value);\n } else {\n const trimmed = value.trim();\n const match = /^(\\d+(?:\\.\\d+)?)\\s*([KMG])$/i.exec(trimmed);\n if (!match) {\n throw new Error(`${context}: maxSize string must be like \"10K\", \"5M\", or \"1G\" (case-insensitive)`);\n }\n\n const amount = Number(match[1]);\n const unit = match[2].toUpperCase() as \"K\" | \"M\" | \"G\";\n\n if (!Number.isFinite(amount)) {\n throw new Error(`${context}: maxSize must be a valid number`);\n }\n\n const multiplier = unit === \"K\" ? 1024 : unit === \"M\" ? 1024 * 1024 : 1024 * 1024 * 1024;\n bytes = Math.round(amount * multiplier);\n }\n\n if (bytes < 0) {\n throw new Error(`${context}: maxSize must be >= 0`);\n }\n\n if (bytes > MAX_FILE_SIZE_BYTES) {\n throw new Error(`${context}: maxSize cannot exceed 8G (${MAX_FILE_SIZE_BYTES} bytes)`);\n }\n\n return bytes;\n}\n\nfunction normalizeFileFieldOptions(\n options: FileFieldOptions | undefined,\n context: string\n): FileFieldOptions | undefined {\n if (!options) return options;\n if (options.maxSize === undefined) return options;\n\n return {\n ...options,\n // PocketBase expects bytes; normalize any human-friendly inputs to bytes here.\n maxSize: parseByteSizeToBytes(options.maxSize, context),\n };\n}\n\n// ============================================================================\n// Field Helper Functions\n// ============================================================================\n\n/**\n * Creates a boolean field schema\n * Maps to PocketBase 'bool' field type\n *\n * @returns Zod boolean schema with PocketBase metadata\n *\n * @example\n * const ProductSchema = z.object({\n * active: BoolField(),\n * featured: BoolField().optional(),\n * });\n */\nexport function BoolField(): z.ZodBoolean {\n const metadata = {\n [FIELD_METADATA_KEY]: {\n type: \"bool\" as const,\n },\n };\n\n return z.boolean().describe(JSON.stringify(metadata));\n}\n\n/**\n * Creates a number field schema with optional constraints\n * Maps to PocketBase 'number' field type\n *\n * @param options - Optional constraints for the number field\n * @returns Zod number schema with PocketBase metadata\n *\n * @example\n * const ProductSchema = z.object({\n * price: NumberField({ min: 0 }),\n * quantity: NumberField({ min: 0, noDecimal: true }),\n * rating: NumberField({ min: 0, max: 5 }),\n * progress: NumberField({ min: 0, max: 100 }), // required defaults to false, allowing zero\n * score: NumberField({ min: 1, max: 10, required: true }), // requires non-zero value\n * });\n *\n * @remarks\n * By default, number fields are not required (`required: false`), which allows zero values.\n * In PocketBase, `required: true` for number fields means the value must be non-zero.\n * If you set `min: 0` and want to allow zero, keep `required: false` (the default).\n */\nexport function NumberField(options?: NumberFieldOptions): z.ZodNumber {\n // Validate options\n if (options?.min !== undefined && options?.max !== undefined) {\n if (options.min > options.max) {\n throw new Error(\"NumberField: min cannot be greater than max\");\n }\n }\n\n // Create base schema\n let schema = z.number();\n\n // Apply Zod validations\n if (options?.min !== undefined) {\n schema = schema.min(options.min);\n }\n if (options?.max !== undefined) {\n schema = schema.max(options.max);\n }\n\n // Build metadata\n const metadata = {\n [FIELD_METADATA_KEY]: {\n type: \"number\" as const,\n options: options || {},\n },\n };\n\n return schema.describe(JSON.stringify(metadata));\n}\n\n/**\n * Creates a text field schema with optional constraints\n * Maps to PocketBase 'text' field type\n *\n * @param options - Optional constraints for the text field\n * @returns Zod string schema with PocketBase metadata\n *\n * @example\n * const ProductSchema = z.object({\n * name: TextField({ min: 1, max: 200 }),\n * sku: TextField({ autogeneratePattern: \"[A-Z]{3}-[0-9]{6}\" }),\n * description: TextField({ max: 1000 }),\n * });\n */\nexport function TextField(options?: TextFieldOptions): z.ZodString {\n // Validate options\n if (options?.min !== undefined && options?.max !== undefined) {\n if (options.min > options.max) {\n throw new Error(\"TextField: min cannot be greater than max\");\n }\n }\n\n // Create base schema\n let schema = z.string();\n\n // Apply Zod validations\n if (options?.min !== undefined) {\n schema = schema.min(options.min);\n }\n if (options?.max !== undefined) {\n schema = schema.max(options.max);\n }\n if (options?.pattern !== undefined) {\n const pattern = options.pattern instanceof RegExp ? options.pattern : new RegExp(options.pattern);\n schema = schema.regex(pattern);\n }\n\n // Build metadata\n const metadata = {\n [FIELD_METADATA_KEY]: {\n type: \"text\" as const,\n options: options || {},\n },\n };\n\n return schema.describe(JSON.stringify(metadata));\n}\n\n/**\n * Creates an email field schema\n * Maps to PocketBase 'email' field type\n *\n * @returns Zod string schema with email validation and PocketBase metadata\n *\n * @example\n * const UserSchema = z.object({\n * email: EmailField(),\n * alternateEmail: EmailField().optional(),\n * });\n */\nexport function EmailField(): z.ZodString {\n const metadata = {\n [FIELD_METADATA_KEY]: {\n type: \"email\" as const,\n },\n };\n\n return z.string().email().describe(JSON.stringify(metadata));\n}\n\n/**\n * Creates a URL field schema\n * Maps to PocketBase 'url' field type\n *\n * @returns Zod string schema with URL validation and PocketBase metadata\n *\n * @example\n * const ProductSchema = z.object({\n * website: URLField(),\n * documentation: URLField().optional(),\n * });\n */\nexport function URLField(): z.ZodString {\n const metadata = {\n [FIELD_METADATA_KEY]: {\n type: \"url\" as const,\n },\n };\n\n return z.string().url().describe(JSON.stringify(metadata));\n}\n\n/**\n * Creates a rich text editor field schema\n * Maps to PocketBase 'editor' field type\n *\n * @returns Zod string schema with PocketBase metadata\n *\n * @example\n * const PostSchema = z.object({\n * content: EditorField(),\n * summary: EditorField().optional(),\n * });\n */\nexport function EditorField(): z.ZodString {\n const metadata = {\n [FIELD_METADATA_KEY]: {\n type: \"editor\" as const,\n },\n };\n\n return z.string().describe(JSON.stringify(metadata));\n}\n\n/**\n * Creates a date field schema with optional constraints\n * Maps to PocketBase 'date' field type\n *\n * @param options - Optional date constraints\n * @returns Zod string schema with PocketBase metadata\n *\n * @example\n * const EventSchema = z.object({\n * startDate: DateField(),\n * endDate: DateField({ min: new Date('2024-01-01') }),\n * releaseDate: DateField().optional(),\n * });\n */\nexport function DateField(options?: DateFieldOptions): z.ZodString {\n // Validate options\n if (options?.min !== undefined && options?.max !== undefined) {\n const minDate = typeof options.min === \"string\" ? new Date(options.min) : options.min;\n const maxDate = typeof options.max === \"string\" ? new Date(options.max) : options.max;\n if (minDate > maxDate) {\n throw new Error(\"DateField: min cannot be greater than max\");\n }\n }\n\n // Create base schema\n const schema = z.string();\n\n // Build metadata\n const metadata = {\n [FIELD_METADATA_KEY]: {\n type: \"date\" as const,\n options: options || {},\n },\n };\n\n return schema.describe(JSON.stringify(metadata));\n}\n\n/**\n * Creates an autodate field schema with automatic timestamp management\n * Maps to PocketBase 'autodate' field type\n *\n * @param options - Optional autodate configuration\n * @returns Zod string schema with PocketBase metadata\n *\n * @example\n * const PostSchema = z.object({\n * createdAt: AutodateField({ onCreate: true }),\n * updatedAt: AutodateField({ onUpdate: true }),\n * publishedAt: AutodateField({ onCreate: true, onUpdate: false }),\n * });\n */\nexport function AutodateField(options?: AutodateFieldOptions): z.ZodString {\n const schema = z.string();\n\n // Build metadata\n const metadata = {\n [FIELD_METADATA_KEY]: {\n type: \"autodate\" as const,\n options: options || {},\n },\n };\n\n return schema.describe(JSON.stringify(metadata));\n}\n\n/**\n * Creates a select field schema from enum values\n * Maps to PocketBase 'select' field type\n *\n * @param values - Array of allowed string values\n * @param options - Optional select configuration\n * @returns Zod enum or array schema with PocketBase metadata\n *\n * @example\n * // Single select\n * const PostSchema = z.object({\n * status: SelectField([\"draft\", \"published\", \"archived\"]),\n * });\n *\n * @example\n * // Multiple select\n * const ProductSchema = z.object({\n * categories: SelectField([\"electronics\", \"clothing\", \"food\"], { maxSelect: 3 }),\n * });\n */\nexport function SelectField<T extends [string, ...string[]]>(\n values: T,\n options?: SelectFieldOptions\n): z.ZodEnum<T> | z.ZodArray<z.ZodEnum<T>> {\n const enumSchema = z.enum(values);\n\n // Build metadata\n const metadata = {\n [FIELD_METADATA_KEY]: {\n type: \"select\" as const,\n options: {\n values,\n maxSelect: options?.maxSelect ?? 1,\n },\n },\n };\n\n // Return array schema if maxSelect > 1\n if (options?.maxSelect && options.maxSelect > 1) {\n return z.array(enumSchema).describe(JSON.stringify(metadata));\n }\n\n return enumSchema.describe(JSON.stringify(metadata));\n}\n\n/**\n * Creates a single file field schema\n * Maps to PocketBase 'file' field type with maxSelect=1\n *\n * @param options - Optional file constraints\n * @returns Zod schema that accepts File on input and returns string when reading from database\n *\n * @example\n * const ProductSchema = z.object({\n * thumbnail: FileField({ mimeTypes: [\"image/*\"], maxSize: 5242880 }),\n * document: FileField({ mimeTypes: [\"application/pdf\"] }),\n * });\n *\n * @remarks\n * - When creating/updating records: accepts File objects\n * - When reading from PocketBase: returns string (filename)\n */\nexport function FileField(options?: FileFieldOptions): z.ZodType<string, z.ZodTypeDef, File | string> {\n // Accept File for input (when creating/updating) or string (when reading from DB)\n // Output is always string (as returned by PocketBase)\n const schema = z.preprocess((val) => {\n // If it's a File, return its name (or empty string if no name)\n // If it's already a string (from DB), return as-is\n return val instanceof File ? val.name || \"\" : val;\n }, z.string()) as z.ZodType<string, z.ZodTypeDef, File | string>;\n\n const normalizedOptions = normalizeFileFieldOptions(options, \"FileField\");\n\n // Build metadata\n const metadata = {\n [FIELD_METADATA_KEY]: {\n type: \"file\" as const,\n options: normalizedOptions || {},\n },\n };\n\n return schema.describe(JSON.stringify(metadata));\n}\n\n/**\n * Creates a multiple files field schema\n * Maps to PocketBase 'file' field type with maxSelect>1\n *\n * @param options - Optional file constraints\n * @returns Zod array schema that accepts File[] on input and returns string[] when reading from database\n *\n * @example\n * const ProductSchema = z.object({\n * images: FilesField({ mimeTypes: [\"image/*\"], maxSelect: 5 }),\n * attachments: FilesField({ minSelect: 1, maxSelect: 10 }),\n * });\n *\n * @remarks\n * - When creating/updating records: accepts File[]\n * - When reading from PocketBase: returns string[] (filenames)\n */\nexport function FilesField(options?: FilesFieldOptions): z.ZodType<string[], z.ZodTypeDef, (File | string)[]> {\n // Validate options\n if (options?.minSelect !== undefined && options?.maxSelect !== undefined) {\n if (options.minSelect > options.maxSelect) {\n throw new Error(\"FilesField: minSelect cannot be greater than maxSelect\");\n }\n }\n\n // Accept File[] for input (when creating/updating) or string[] (when reading from DB)\n // Output is always string[] (as returned by PocketBase)\n let baseArraySchema = z.array(z.string());\n\n // Apply Zod validations first\n if (options?.minSelect !== undefined) {\n baseArraySchema = baseArraySchema.min(options.minSelect);\n }\n if (options?.maxSelect !== undefined) {\n baseArraySchema = baseArraySchema.max(options.maxSelect);\n }\n\n const schema = z.preprocess((val) => {\n // Handle array of Files or strings\n if (Array.isArray(val)) {\n return val.map((item) => (item instanceof File ? item.name || \"\" : item));\n }\n return val;\n }, baseArraySchema);\n\n const normalizedOptions = normalizeFileFieldOptions(options, \"FilesField\");\n\n // Build metadata\n const metadata = {\n [FIELD_METADATA_KEY]: {\n type: \"file\" as const,\n options: normalizedOptions || {},\n },\n };\n\n return schema.describe(JSON.stringify(metadata)) as z.ZodType<string[], z.ZodTypeDef, (File | string)[]>;\n}\n\n/**\n * Creates a JSON field schema with optional inner schema validation\n * Maps to PocketBase 'json' field type\n *\n * @param schema - Optional Zod schema for the JSON structure\n * @returns Zod schema with PocketBase metadata\n *\n * @example\n * // Any JSON\n * const ProductSchema = z.object({\n * metadata: JSONField(),\n * });\n *\n * @example\n * // Typed JSON\n * const ProductSchema = z.object({\n * settings: JSONField(z.object({\n * theme: z.string(),\n * notifications: z.boolean(),\n * })),\n * });\n */\nexport function JSONField<T extends z.ZodTypeAny>(schema?: T): T | z.ZodRecord<z.ZodString, z.ZodAny> {\n const baseSchema = schema ?? z.record(z.string(), z.any());\n\n // Build metadata\n const metadata = {\n [FIELD_METADATA_KEY]: {\n type: \"json\" as const,\n },\n };\n\n return baseSchema.describe(JSON.stringify(metadata)) as T | z.ZodRecord<z.ZodString, z.ZodAny>;\n}\n\n/**\n * Creates a geographic point field schema\n * Maps to PocketBase 'geoPoint' field type\n *\n * @returns Zod object schema with lon/lat fields and PocketBase metadata\n *\n * @example\n * const LocationSchema = z.object({\n * coordinates: GeoPointField(),\n * homeLocation: GeoPointField().optional(),\n * });\n */\nexport function GeoPointField(): z.ZodObject<{\n lon: z.ZodNumber;\n lat: z.ZodNumber;\n}> {\n const schema = z.object({\n lon: z.number(),\n lat: z.number(),\n });\n\n // Build metadata\n const metadata = {\n [FIELD_METADATA_KEY]: {\n type: \"geoPoint\" as const,\n },\n };\n\n return schema.describe(JSON.stringify(metadata));\n}\n","/**\n * Custom error classes for migration tool\n * Provides specific error types for better error handling and user feedback\n */\n\n/**\n * Base error class for all migration-related errors\n */\nexport class MigrationError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"MigrationError\";\n Object.setPrototypeOf(this, MigrationError.prototype);\n }\n}\n\n/**\n * Error thrown when schema parsing fails\n * Used when Zod schemas cannot be parsed or are invalid\n */\nexport class SchemaParsingError extends MigrationError {\n public readonly filePath?: string;\n public readonly originalError?: Error;\n\n constructor(message: string, filePath?: string, originalError?: Error) {\n super(message);\n this.name = \"SchemaParsingError\";\n this.filePath = filePath;\n this.originalError = originalError;\n Object.setPrototypeOf(this, SchemaParsingError.prototype);\n }\n\n /**\n * Creates a formatted error message with file path and original error details\n */\n public getDetailedMessage(): string {\n const parts: string[] = [this.message];\n\n if (this.filePath) {\n parts.push(`\\nFile: ${this.filePath}`);\n }\n\n if (this.originalError) {\n parts.push(`\\nCause: ${this.originalError.message}`);\n }\n\n return parts.join(\"\");\n }\n}\n\n/**\n * Error thrown when snapshot operations fail\n * Used for snapshot file read/write/parse errors\n */\nexport class SnapshotError extends MigrationError {\n public readonly snapshotPath?: string;\n public readonly operation?: \"read\" | \"write\" | \"parse\" | \"validate\";\n public readonly originalError?: Error;\n\n constructor(\n message: string,\n snapshotPath?: string,\n operation?: \"read\" | \"write\" | \"parse\" | \"validate\",\n originalError?: Error\n ) {\n super(message);\n this.name = \"SnapshotError\";\n this.snapshotPath = snapshotPath;\n this.operation = operation;\n this.originalError = originalError;\n Object.setPrototypeOf(this, SnapshotError.prototype);\n }\n\n /**\n * Creates a formatted error message with snapshot path and operation details\n */\n public getDetailedMessage(): string {\n const parts: string[] = [this.message];\n\n if (this.operation) {\n parts.push(`\\nOperation: ${this.operation}`);\n }\n\n if (this.snapshotPath) {\n parts.push(`\\nSnapshot: ${this.snapshotPath}`);\n }\n\n if (this.originalError) {\n parts.push(`\\nCause: ${this.originalError.message}`);\n }\n\n return parts.join(\"\");\n }\n}\n\n/**\n * Error thrown when migration file generation fails\n * Used when migration files cannot be created or written\n */\nexport class MigrationGenerationError extends MigrationError {\n public readonly migrationPath?: string;\n public readonly originalError?: Error;\n\n constructor(message: string, migrationPath?: string, originalError?: Error) {\n super(message);\n this.name = \"MigrationGenerationError\";\n this.migrationPath = migrationPath;\n this.originalError = originalError;\n Object.setPrototypeOf(this, MigrationGenerationError.prototype);\n }\n\n /**\n * Creates a formatted error message with migration path and original error details\n */\n public getDetailedMessage(): string {\n const parts: string[] = [this.message];\n\n if (this.migrationPath) {\n parts.push(`\\nMigration: ${this.migrationPath}`);\n }\n\n if (this.originalError) {\n parts.push(`\\nCause: ${this.originalError.message}`);\n }\n\n return parts.join(\"\");\n }\n}\n\n/**\n * Error thrown when file system operations fail\n * Used for directory creation, file permissions, disk space issues\n */\nexport class FileSystemError extends MigrationError {\n public readonly path?: string;\n public readonly operation?: \"read\" | \"write\" | \"create\" | \"delete\" | \"access\";\n public readonly code?: string;\n public readonly originalError?: Error;\n\n constructor(\n message: string,\n path?: string,\n operation?: \"read\" | \"write\" | \"create\" | \"delete\" | \"access\",\n code?: string,\n originalError?: Error\n ) {\n super(message);\n this.name = \"FileSystemError\";\n this.path = path;\n this.operation = operation;\n this.code = code;\n this.originalError = originalError;\n Object.setPrototypeOf(this, FileSystemError.prototype);\n }\n\n /**\n * Creates a formatted error message with path, operation, and error code details\n */\n public getDetailedMessage(): string {\n const parts: string[] = [this.message];\n\n if (this.operation) {\n parts.push(`\\nOperation: ${this.operation}`);\n }\n\n if (this.path) {\n parts.push(`\\nPath: ${this.path}`);\n }\n\n if (this.code) {\n parts.push(`\\nError Code: ${this.code}`);\n }\n\n if (this.originalError) {\n parts.push(`\\nCause: ${this.originalError.message}`);\n }\n\n return parts.join(\"\");\n }\n}\n\n/**\n * Error thrown when configuration is invalid\n * Used for configuration file parsing, validation, and path resolution errors\n */\nexport class ConfigurationError extends MigrationError {\n public readonly configPath?: string;\n public readonly invalidFields?: string[];\n public readonly originalError?: Error;\n\n constructor(message: string, configPath?: string, invalidFields?: string[], originalError?: Error) {\n super(message);\n this.name = \"ConfigurationError\";\n this.configPath = configPath;\n this.invalidFields = invalidFields;\n this.originalError = originalError;\n Object.setPrototypeOf(this, ConfigurationError.prototype);\n }\n\n /**\n * Creates a formatted error message with configuration details\n */\n public getDetailedMessage(): string {\n const parts: string[] = [this.message];\n\n if (this.configPath) {\n parts.push(`\\nConfiguration File: ${this.configPath}`);\n }\n\n if (this.invalidFields && this.invalidFields.length > 0) {\n parts.push(`\\nInvalid Fields: ${this.invalidFields.join(\", \")}`);\n }\n\n if (this.originalError) {\n parts.push(`\\nCause: ${this.originalError.message}`);\n }\n\n return parts.join(\"\");\n }\n}\n\n/**\n * Error thrown when CLI command usage is incorrect\n * Used for invalid arguments, missing required options, etc.\n */\nexport class CLIUsageError extends MigrationError {\n public readonly command?: string;\n public readonly suggestion?: string;\n\n constructor(message: string, command?: string, suggestion?: string) {\n super(message);\n this.name = \"CLIUsageError\";\n this.command = command;\n this.suggestion = suggestion;\n Object.setPrototypeOf(this, CLIUsageError.prototype);\n }\n\n /**\n * Creates a formatted error message with usage suggestions\n */\n public getDetailedMessage(): string {\n const parts: string[] = [this.message];\n\n if (this.command) {\n parts.push(`\\nCommand: ${this.command}`);\n }\n\n if (this.suggestion) {\n parts.push(`\\nSuggestion: ${this.suggestion}`);\n }\n\n return parts.join(\"\");\n }\n}\n","import type { PermissionSchema, PermissionTemplateConfig, RuleExpression } from \"../utils/permissions\";\n\n/**\n * Predefined permission templates for common access control patterns\n */\nexport const PermissionTemplates = {\n /**\n * Public access - anyone can perform all operations\n */\n public: (): PermissionSchema => ({\n listRule: \"\",\n viewRule: \"\",\n createRule: \"\",\n updateRule: \"\",\n deleteRule: \"\",\n }),\n\n /**\n * Authenticated users only - requires valid authentication for all operations\n */\n authenticated: (): PermissionSchema => ({\n listRule: '@request.auth.id != \"\"',\n viewRule: '@request.auth.id != \"\"',\n createRule: '@request.auth.id != \"\"',\n updateRule: '@request.auth.id != \"\"',\n deleteRule: '@request.auth.id != \"\"',\n }),\n\n /**\n * Owner-only access - users can only manage their own records\n * @param ownerField - Name of the relation field pointing to user (default: 'User')\n */\n ownerOnly: (ownerField: string = \"User\"): PermissionSchema => ({\n listRule: `@request.auth.id != \"\" && ${ownerField} = @request.auth.id`,\n viewRule: `@request.auth.id != \"\" && ${ownerField} = @request.auth.id`,\n createRule: '@request.auth.id != \"\"',\n updateRule: `@request.auth.id != \"\" && ${ownerField} = @request.auth.id`,\n deleteRule: `@request.auth.id != \"\" && ${ownerField} = @request.auth.id`,\n }),\n\n /**\n * Admin/superuser only access\n * Assumes a 'role' field exists with 'admin' value\n * @param roleField - Name of the role field (default: 'role')\n */\n adminOnly: (roleField: string = \"role\"): PermissionSchema => ({\n listRule: `@request.auth.id != \"\" && @request.auth.${roleField} = \"admin\"`,\n viewRule: `@request.auth.id != \"\" && @request.auth.${roleField} = \"admin\"`,\n createRule: `@request.auth.id != \"\" && @request.auth.${roleField} = \"admin\"`,\n updateRule: `@request.auth.id != \"\" && @request.auth.${roleField} = \"admin\"`,\n deleteRule: `@request.auth.id != \"\" && @request.auth.${roleField} = \"admin\"`,\n }),\n\n /**\n * Public read, authenticated write\n * Anyone can list/view, but only authenticated users can create/update/delete\n */\n readPublic: (): PermissionSchema => ({\n listRule: \"\",\n viewRule: \"\",\n createRule: '@request.auth.id != \"\"',\n updateRule: '@request.auth.id != \"\"',\n deleteRule: '@request.auth.id != \"\"',\n }),\n\n /**\n * Locked access - only superusers can perform operations\n * All rules are set to null (locked)\n */\n locked: (): PermissionSchema => ({\n listRule: null,\n viewRule: null,\n createRule: null,\n updateRule: null,\n deleteRule: null,\n }),\n\n /**\n * Read-only authenticated - authenticated users can read, no write access\n */\n readOnlyAuthenticated: (): PermissionSchema => ({\n listRule: '@request.auth.id != \"\"',\n viewRule: '@request.auth.id != \"\"',\n createRule: null,\n updateRule: null,\n deleteRule: null,\n }),\n};\n\n/**\n * Resolve template configuration to concrete permission schema\n * @param config - Template configuration or direct permission schema\n * @returns Resolved permission schema with all rules defined\n */\nexport function resolveTemplate(config: PermissionTemplateConfig): PermissionSchema {\n let baseRules: PermissionSchema;\n\n switch (config.template) {\n case \"public\":\n baseRules = PermissionTemplates.public();\n break;\n case \"authenticated\":\n baseRules = PermissionTemplates.authenticated();\n break;\n case \"owner-only\":\n baseRules = PermissionTemplates.ownerOnly(config.ownerField);\n break;\n case \"admin-only\":\n baseRules = PermissionTemplates.adminOnly(config.roleField);\n break;\n case \"read-public\":\n baseRules = PermissionTemplates.readPublic();\n break;\n case \"custom\":\n baseRules = {};\n break;\n default: {\n // Exhaustive check - TypeScript will error if we miss a template type\n const _exhaustive: never = config.template;\n throw new Error(`Unknown template type: ${_exhaustive}`);\n }\n }\n\n // Merge with custom rules if provided (custom rules override template rules)\n return {\n ...baseRules,\n ...config.customRules,\n };\n}\n\n/**\n * Check if a configuration is a template config or direct permission schema\n * @param config - Configuration to check\n * @returns True if it's a template configuration\n */\nexport function isTemplateConfig(\n config: PermissionTemplateConfig | PermissionSchema\n): config is PermissionTemplateConfig {\n return \"template\" in config;\n}\n\n/**\n * Check if a configuration is a direct permission schema\n * @param config - Configuration to check\n * @returns True if it's a direct permission schema\n */\nexport function isPermissionSchema(config: PermissionTemplateConfig | PermissionSchema): config is PermissionSchema {\n return (\n \"listRule\" in config ||\n \"viewRule\" in config ||\n \"createRule\" in config ||\n \"updateRule\" in config ||\n \"deleteRule\" in config ||\n \"manageRule\" in config\n );\n}\n\n/**\n * Validation result for permission configuration\n */\nexport interface PermissionValidationResult {\n valid: boolean;\n errors: string[];\n warnings: string[];\n}\n\n/**\n * Validate a permission configuration\n * @param config - Permission configuration to validate\n * @param isAuthCollection - Whether this is for an auth collection\n * @returns Validation result\n */\nexport function validatePermissionConfig(\n config: PermissionTemplateConfig | PermissionSchema,\n isAuthCollection: boolean = false\n): PermissionValidationResult {\n const result: PermissionValidationResult = {\n valid: true,\n errors: [],\n warnings: [],\n };\n\n // Resolve to permission schema\n let permissions: PermissionSchema;\n if (isTemplateConfig(config)) {\n // Validate template config\n if (config.template === \"owner-only\" && !config.ownerField) {\n result.warnings.push(\"owner-only template without ownerField specified - using default 'User'\");\n }\n if (config.template === \"admin-only\" && !config.roleField) {\n result.warnings.push(\"admin-only template without roleField specified - using default 'role'\");\n }\n permissions = resolveTemplate(config);\n } else {\n permissions = config;\n }\n\n // Validate manageRule usage\n if (permissions.manageRule !== undefined && !isAuthCollection) {\n result.errors.push(\"manageRule is only valid for auth collections\");\n result.valid = false;\n }\n\n // Validate rule expressions\n const ruleTypes: (keyof PermissionSchema)[] = [\"listRule\", \"viewRule\", \"createRule\", \"updateRule\", \"deleteRule\"];\n if (isAuthCollection) {\n ruleTypes.push(\"manageRule\");\n }\n\n for (const ruleType of ruleTypes) {\n const rule = permissions[ruleType];\n if (rule !== undefined && rule !== null && rule !== \"\") {\n const ruleValidation = validateRuleExpression(rule);\n if (!ruleValidation.valid) {\n result.errors.push(`${ruleType}: ${ruleValidation.errors.join(\", \")}`);\n result.valid = false;\n }\n result.warnings.push(...ruleValidation.warnings.map((w) => `${ruleType}: ${w}`));\n }\n }\n\n return result;\n}\n\n/**\n * Validate a single rule expression for basic syntax\n * @param expression - Rule expression to validate\n * @returns Validation result\n */\nexport function validateRuleExpression(expression: RuleExpression): PermissionValidationResult {\n const result: PermissionValidationResult = {\n valid: true,\n errors: [],\n warnings: [],\n };\n\n // Null and empty string are always valid\n if (expression === null || expression === \"\") {\n return result;\n }\n\n // Check for balanced parentheses\n let parenCount = 0;\n for (const char of expression) {\n if (char === \"(\") parenCount++;\n if (char === \")\") parenCount--;\n if (parenCount < 0) {\n result.errors.push(\"Unbalanced parentheses\");\n result.valid = false;\n return result;\n }\n }\n if (parenCount !== 0) {\n result.errors.push(\"Unbalanced parentheses\");\n result.valid = false;\n }\n\n // Check for common mistakes\n if (expression.includes(\"==\")) {\n result.warnings.push(\"Use '=' instead of '==' for equality comparison\");\n }\n\n // Check for valid @request references\n const requestRefs = expression.match(/@request\\.[a-zA-Z_][a-zA-Z0-9_.]*/g) || [];\n for (const ref of requestRefs) {\n const isValid =\n ref.startsWith(\"@request.auth.\") ||\n ref === \"@request.method\" ||\n ref === \"@request.context\" ||\n ref.startsWith(\"@request.body.\") ||\n ref.startsWith(\"@request.query.\") ||\n ref.startsWith(\"@request.headers.\");\n\n if (!isValid) {\n result.errors.push(`Invalid @request reference: '${ref}'`);\n result.valid = false;\n }\n }\n\n return result;\n}\n\n/**\n * Create a custom permission schema with type safety\n * @param permissions - Partial permission schema\n * @returns Complete permission schema with null defaults\n */\nexport function createPermissions(permissions: Partial<PermissionSchema>): PermissionSchema {\n return {\n listRule: permissions.listRule ?? null,\n viewRule: permissions.viewRule ?? null,\n createRule: permissions.createRule ?? null,\n updateRule: permissions.updateRule ?? null,\n deleteRule: permissions.deleteRule ?? null,\n manageRule: permissions.manageRule ?? null,\n };\n}\n\n/**\n * Merge multiple permission schemas, with later schemas taking precedence\n * @param schemas - Permission schemas to merge\n * @returns Merged permission schema\n */\nexport function mergePermissions(...schemas: Partial<PermissionSchema>[]): PermissionSchema {\n const merged: PermissionSchema = {\n listRule: null,\n viewRule: null,\n createRule: null,\n updateRule: null,\n deleteRule: null,\n manageRule: null,\n };\n\n for (const schema of schemas) {\n if (schema.listRule !== undefined) merged.listRule = schema.listRule;\n if (schema.viewRule !== undefined) merged.viewRule = schema.viewRule;\n if (schema.createRule !== undefined) merged.createRule = schema.createRule;\n if (schema.updateRule !== undefined) merged.updateRule = schema.updateRule;\n if (schema.deleteRule !== undefined) merged.deleteRule = schema.deleteRule;\n if (schema.manageRule !== undefined) merged.manageRule = schema.manageRule;\n }\n\n return merged;\n}\n","/**\n * Rule validator for PocketBase API rule expressions\n *\n * Validates permission rule expressions against PocketBase syntax rules,\n * including field references, @request references, and basic syntax validation.\n */\n\nimport type { APIRuleType, RuleExpression } from \"../utils/permissions\";\nimport type { FieldDefinition } from \"./types\";\n\n/**\n * Validation result for rule expressions\n */\nexport interface RuleValidationResult {\n /** Whether the rule expression is valid */\n valid: boolean;\n\n /** List of validation errors */\n errors: string[];\n\n /** List of validation warnings */\n warnings: string[];\n\n /** List of field references found in the expression */\n fieldReferences: string[];\n}\n\n/**\n * Rule expression validator\n *\n * Validates PocketBase API rule expressions for:\n * - Field reference existence and validity\n * - @request reference syntax\n * - Basic expression syntax (parentheses, operators)\n * - Auth collection specific rules (manageRule)\n */\nexport class RuleValidator {\n private fields: Map<string, FieldDefinition>;\n private collectionName: string;\n private isAuthCollection: boolean;\n\n constructor(collectionName: string, fields: FieldDefinition[], isAuthCollection: boolean = false) {\n this.collectionName = collectionName;\n this.fields = new Map(fields.map((f) => [f.name, f]));\n this.isAuthCollection = isAuthCollection;\n\n // Add system fields that are always available in PocketBase\n this.addSystemFields();\n }\n\n /**\n * Add system fields that are always available in PocketBase collections\n * These fields are automatically added by PocketBase and can be referenced in rules\n */\n private addSystemFields(): void {\n // Base system fields available in all collections\n const systemFields: FieldDefinition[] = [\n { name: \"id\", type: \"text\", required: true, options: {} },\n { name: \"created\", type: \"date\", required: true, options: {} },\n { name: \"updated\", type: \"date\", required: true, options: {} },\n { name: \"collectionId\", type: \"text\", required: true, options: {} },\n { name: \"collectionName\", type: \"text\", required: true, options: {} },\n ];\n\n // Auth collection specific system fields\n if (this.isAuthCollection) {\n systemFields.push(\n { name: \"email\", type: \"email\", required: true, options: {} },\n { name: \"emailVisibility\", type: \"bool\", required: false, options: {} },\n { name: \"verified\", type: \"bool\", required: false, options: {} },\n { name: \"tokenKey\", type: \"text\", required: true, options: {} },\n { name: \"password\", type: \"text\", required: true, options: {} }\n );\n }\n\n // Add system fields to the fields map (don't overwrite user-defined fields)\n for (const field of systemFields) {\n if (!this.fields.has(field.name)) {\n this.fields.set(field.name, field);\n }\n }\n }\n\n /**\n * Validate a rule expression\n *\n * @param ruleType - The type of rule being validated\n * @param expression - The rule expression to validate\n * @returns Validation result with errors, warnings, and field references\n */\n validate(ruleType: APIRuleType, expression: RuleExpression): RuleValidationResult {\n const result: RuleValidationResult = {\n valid: true,\n errors: [],\n warnings: [],\n fieldReferences: [],\n };\n\n // Null means locked (superuser only) - always valid\n if (expression === null) {\n return result;\n }\n\n // Empty string means public - always valid but warn\n if (expression === \"\") {\n result.warnings.push(`${ruleType} is public - anyone can perform this operation`);\n return result;\n }\n\n // Validate manageRule only for auth collections\n if (ruleType === \"manageRule\" && !this.isAuthCollection) {\n result.valid = false;\n result.errors.push(\"manageRule is only valid for auth collections\");\n return result;\n }\n\n // Extract and validate field references\n const fieldRefs = this.extractFieldReferences(expression);\n result.fieldReferences = fieldRefs;\n\n for (const fieldRef of fieldRefs) {\n this.validateFieldReference(fieldRef, result);\n }\n\n // Validate @request references\n this.validateRequestReferences(expression, result);\n\n // Validate syntax patterns\n this.validateSyntax(expression, result);\n\n return result;\n }\n\n /**\n * Extract field references from expression\n *\n * Matches field names that are not @request references.\n * Handles dot notation for relations: user.email, post.author.name\n *\n * @param expression - The rule expression\n * @returns Array of unique field references\n */\n private extractFieldReferences(expression: string): string[] {\n const refs: string[] = [];\n\n // First, remove string literals and @request references to avoid matching them\n let cleaned = expression.replace(/\"[^\"]*\"/g, '\"\"').replace(/'[^']*'/g, \"''\");\n cleaned = cleaned.replace(/@request\\.[a-zA-Z_][a-zA-Z0-9_.]*/g, \"\");\n\n // Match field names (not starting with @)\n // Handles dot notation for relations: user.email, post.author.name\n const fieldPattern = /(?:^|[^@\\w])([a-zA-Z_][a-zA-Z0-9_]*(?:\\.[a-zA-Z_][a-zA-Z0-9_]*)*)(?=[^a-zA-Z0-9_.]|$)/g;\n\n let match;\n while ((match = fieldPattern.exec(cleaned)) !== null) {\n const ref = match[1];\n // Exclude PocketBase keywords and operators\n if (!this.isKeyword(ref)) {\n refs.push(ref);\n }\n }\n\n return [...new Set(refs)]; // Remove duplicates\n }\n\n /**\n * Check if a word is a PocketBase keyword\n *\n * @param word - The word to check\n * @returns True if the word is a keyword\n */\n private isKeyword(word: string): boolean {\n const keywords = [\"true\", \"false\", \"null\", \"AND\", \"OR\", \"NOT\", \"LIKE\", \"IN\"];\n return keywords.includes(word.toUpperCase());\n }\n\n /**\n * Validate a field reference exists in schema\n *\n * Checks if the root field exists and validates relation chains.\n * For nested references, warns about potential issues since we can't\n * validate across collections without loading related schemas.\n *\n * @param fieldRef - The field reference to validate (e.g., \"user\" or \"user.email\")\n * @param result - The validation result to update\n */\n private validateFieldReference(fieldRef: string, result: RuleValidationResult): void {\n const parts = fieldRef.split(\".\");\n const rootField = parts[0];\n\n if (!this.fields.has(rootField)) {\n result.errors.push(`Field '${rootField}' does not exist in collection '${this.collectionName}'`);\n result.valid = false;\n return;\n }\n\n // For nested references, validate relation chain\n if (parts.length > 1) {\n const field = this.fields.get(rootField)!;\n if (field.type !== \"relation\") {\n result.errors.push(`Field '${rootField}' is not a relation field, cannot access nested property '${parts[1]}'`);\n result.valid = false;\n } else {\n // Note: We can't validate nested fields without loading related schemas\n // This would require cross-schema validation\n result.warnings.push(\n `Nested field reference '${fieldRef}' - ensure target collection has field '${parts.slice(1).join(\".\")}'`\n );\n }\n }\n }\n\n /**\n * Validate @request references\n *\n * Checks that @request references follow valid PocketBase patterns:\n * - @request.auth.* - authenticated user data\n * - @request.body.* - request body fields\n * - @request.query.* - query parameters\n * - @request.headers.* - request headers\n * - @request.method - HTTP method\n * - @request.context - execution context\n *\n * @param expression - The rule expression\n * @param result - The validation result to update\n */\n private validateRequestReferences(expression: string, result: RuleValidationResult): void {\n // Find all @request references\n const requestRefs = expression.match(/@request\\.[a-zA-Z_][a-zA-Z0-9_.]*/g) || [];\n\n for (const ref of requestRefs) {\n // Check if the reference starts with a valid pattern\n const isValid =\n ref.startsWith(\"@request.auth.\") ||\n ref === \"@request.method\" ||\n ref === \"@request.context\" ||\n ref.startsWith(\"@request.body.\") ||\n ref.startsWith(\"@request.query.\") ||\n ref.startsWith(\"@request.headers.\");\n\n if (!isValid) {\n result.errors.push(`Invalid @request reference: '${ref}'`);\n result.valid = false;\n }\n }\n }\n\n /**\n * Validate basic syntax patterns\n *\n * Checks for:\n * - Balanced parentheses\n * - Common operator mistakes (== instead of =)\n *\n * @param expression - The rule expression\n * @param result - The validation result to update\n */\n private validateSyntax(expression: string, result: RuleValidationResult): void {\n // Check for balanced parentheses\n let parenCount = 0;\n for (const char of expression) {\n if (char === \"(\") parenCount++;\n if (char === \")\") parenCount--;\n if (parenCount < 0) {\n result.errors.push(\"Unbalanced parentheses in expression\");\n result.valid = false;\n return;\n }\n }\n if (parenCount !== 0) {\n result.errors.push(\"Unbalanced parentheses in expression\");\n result.valid = false;\n }\n\n // Warn about common mistakes\n if (expression.includes(\"==\")) {\n result.warnings.push(\"Use '=' instead of '==' for equality comparison in PocketBase rules\");\n }\n }\n}\n","/**\n * Permission analyzer for extracting and validating permissions from Zod schemas\n *\n * This module provides utilities to:\n * - Extract permission metadata from Zod schema descriptions\n * - Resolve template configurations to concrete permission schemas\n * - Validate permission rules against collection fields\n * - Merge permissions with default values\n */\n\nimport { resolveTemplate } from \"../utils/permission-templates\";\nimport type { APIRuleType, PermissionSchema, PermissionTemplateConfig } from \"../utils/permissions\";\nimport type { RuleValidationResult } from \"./rule-validator\";\nimport { RuleValidator } from \"./rule-validator\";\nimport type { FieldDefinition } from \"./types\";\n\n/**\n * Extract and analyze permissions from schema\n *\n * The PermissionAnalyzer class provides methods to work with permission\n * definitions attached to Zod schemas, including extraction, resolution,\n * validation, and normalization.\n */\nexport class PermissionAnalyzer {\n /**\n * Extract permission metadata from Zod schema description\n *\n * Zod schemas can have permission metadata attached via the describe() method.\n * This method parses the description and extracts the permission configuration.\n *\n * @param schemaDescription - The Zod schema description string\n * @returns Permission schema if found, null otherwise\n *\n * @example\n * ```typescript\n * const analyzer = new PermissionAnalyzer();\n * const permissions = analyzer.extractPermissions(schema.description);\n * ```\n */\n extractPermissions(schemaDescription: string | undefined): PermissionSchema | null {\n if (!schemaDescription) {\n return null;\n }\n\n try {\n const metadata = JSON.parse(schemaDescription);\n if (metadata.permissions) {\n return metadata.permissions;\n }\n } catch {\n // Not JSON or no permissions - this is expected for schemas without permissions\n return null;\n }\n\n return null;\n }\n\n /**\n * Resolve template configuration to concrete rules\n *\n * Takes either a template configuration or a direct permission schema\n * and returns a fully resolved permission schema with all rules defined.\n *\n * If the input is already a permission schema (has rule properties),\n * it's returned as-is. Otherwise, the template is resolved using the\n * template resolver.\n *\n * @param config - Template configuration or direct permission schema\n * @returns Resolved permission schema\n *\n * @example\n * ```typescript\n * const analyzer = new PermissionAnalyzer();\n *\n * // Resolve from template\n * const permissions = analyzer.resolvePermissions({\n * template: 'owner-only',\n * ownerField: 'User'\n * });\n *\n * // Or pass direct schema\n * const permissions = analyzer.resolvePermissions({\n * listRule: '@request.auth.id != \"\"',\n * viewRule: '@request.auth.id != \"\"'\n * });\n * ```\n */\n resolvePermissions(config: PermissionTemplateConfig | PermissionSchema): PermissionSchema {\n // If it's already a permission schema (has rule properties), return as-is\n if (\n \"listRule\" in config ||\n \"viewRule\" in config ||\n \"createRule\" in config ||\n \"updateRule\" in config ||\n \"deleteRule\" in config ||\n \"manageRule\" in config\n ) {\n return config as PermissionSchema;\n }\n\n // Otherwise resolve template\n return resolveTemplate(config as PermissionTemplateConfig);\n }\n\n /**\n * Validate all rules in a permission schema\n *\n * Validates each rule in the permission schema against the collection's\n * field definitions. Returns a map of validation results keyed by rule type.\n *\n * Only validates rules that are defined (not undefined). Undefined rules\n * are treated as null (locked) by default.\n *\n * @param collectionName - Name of the collection being validated\n * @param permissions - Permission schema to validate\n * @param fields - Collection field definitions\n * @param isAuthCollection - Whether this is an auth collection (allows manageRule)\n * @returns Map of validation results by rule type\n *\n * @example\n * ```typescript\n * const analyzer = new PermissionAnalyzer();\n * const results = analyzer.validatePermissions(\n * 'posts',\n * { listRule: '@request.auth.id != \"\"', viewRule: 'author = @request.auth.id' },\n * fields,\n * false\n * );\n *\n * for (const [ruleType, result] of results) {\n * if (!result.valid) {\n * console.error(`${ruleType} validation failed:`, result.errors);\n * }\n * }\n * ```\n */\n validatePermissions(\n collectionName: string,\n permissions: PermissionSchema,\n fields: FieldDefinition[],\n isAuthCollection: boolean = false\n ): Map<APIRuleType, RuleValidationResult> {\n const validator = new RuleValidator(collectionName, fields, isAuthCollection);\n const results = new Map<APIRuleType, RuleValidationResult>();\n\n // Define all possible rule types\n const ruleTypes: APIRuleType[] = [\"listRule\", \"viewRule\", \"createRule\", \"updateRule\", \"deleteRule\"];\n\n // Add manageRule for auth collections\n if (isAuthCollection) {\n ruleTypes.push(\"manageRule\");\n }\n\n // Validate each defined rule\n for (const ruleType of ruleTypes) {\n const expression = permissions[ruleType];\n if (expression !== undefined) {\n results.set(ruleType, validator.validate(ruleType, expression));\n }\n }\n\n return results;\n }\n\n /**\n * Merge permissions with defaults\n *\n * Ensures all rule types have a defined value. Undefined rules are set\n * to null (locked to superusers only), which is the PocketBase default.\n *\n * This is useful when generating migrations to ensure all rules are\n * explicitly set in the collection configuration.\n *\n * @param permissions - Permission schema (may have undefined rules)\n * @returns Permission schema with all rules defined (null if not specified)\n *\n * @example\n * ```typescript\n * const analyzer = new PermissionAnalyzer();\n * const merged = analyzer.mergeWithDefaults({\n * listRule: '@request.auth.id != \"\"'\n * // other rules undefined\n * });\n *\n * // Result:\n * // {\n * // listRule: '@request.auth.id != \"\"',\n * // viewRule: null,\n * // createRule: null,\n * // updateRule: null,\n * // deleteRule: null,\n * // manageRule: null\n * // }\n * ```\n */\n mergeWithDefaults(permissions: PermissionSchema): PermissionSchema {\n return {\n listRule: permissions.listRule ?? null,\n viewRule: permissions.viewRule ?? null,\n createRule: permissions.createRule ?? null,\n updateRule: permissions.updateRule ?? null,\n deleteRule: permissions.deleteRule ?? null,\n manageRule: permissions.manageRule ?? null,\n };\n }\n}\n","/**\n * Collection name pluralization utilities\n */\n\n/**\n * Special case pluralization rules\n * Maps singular forms to their plural forms\n */\nconst SPECIAL_CASES: Record<string, string> = {\n // Common irregular plurals\n person: \"people\",\n Person: \"People\",\n child: \"children\",\n Child: \"Children\",\n man: \"men\",\n Man: \"Men\",\n woman: \"women\",\n Woman: \"Women\",\n tooth: \"teeth\",\n Tooth: \"Teeth\",\n foot: \"feet\",\n Foot: \"Feet\",\n mouse: \"mice\",\n Mouse: \"Mice\",\n goose: \"geese\",\n Goose: \"Geese\",\n\n // Words ending in -y\n category: \"categories\",\n Category: \"Categories\",\n company: \"companies\",\n Company: \"Companies\",\n city: \"cities\",\n City: \"Cities\",\n country: \"countries\",\n Country: \"Countries\",\n story: \"stories\",\n Story: \"Stories\",\n party: \"parties\",\n Party: \"Parties\",\n family: \"families\",\n Family: \"Families\",\n activity: \"activities\",\n Activity: \"Activities\",\n priority: \"priorities\",\n Priority: \"Priorities\",\n\n // Words ending in -f or -fe\n life: \"lives\",\n Life: \"Lives\",\n wife: \"wives\",\n Wife: \"Wives\",\n knife: \"knives\",\n Knife: \"Knives\",\n leaf: \"leaves\",\n Leaf: \"Leaves\",\n shelf: \"shelves\",\n Shelf: \"Shelves\",\n half: \"halves\",\n Half: \"Halves\",\n\n // Words ending in -is\n analysis: \"analyses\",\n Analysis: \"Analyses\",\n basis: \"bases\",\n Basis: \"Bases\",\n crisis: \"crises\",\n Crisis: \"Crises\",\n thesis: \"theses\",\n Thesis: \"Theses\",\n\n // Words ending in -us\n cactus: \"cacti\",\n Cactus: \"Cacti\",\n focus: \"foci\",\n Focus: \"Foci\",\n fungus: \"fungi\",\n Fungus: \"Fungi\",\n nucleus: \"nuclei\",\n Nucleus: \"Nuclei\",\n radius: \"radii\",\n Radius: \"Radii\",\n\n // Words ending in -on\n phenomenon: \"phenomena\",\n Phenomenon: \"Phenomena\",\n criterion: \"criteria\",\n Criterion: \"Criteria\",\n\n // Words ending in -um\n datum: \"data\",\n Datum: \"Data\",\n medium: \"media\",\n Medium: \"Media\",\n curriculum: \"curricula\",\n Curriculum: \"Curricula\",\n\n // Unchanged plurals\n sheep: \"sheep\",\n Sheep: \"Sheep\",\n deer: \"deer\",\n Deer: \"Deer\",\n fish: \"fish\",\n Fish: \"Fish\",\n species: \"species\",\n Species: \"Species\",\n series: \"series\",\n Series: \"Series\",\n};\n\n/**\n * Pluralizes a singular noun to its plural form\n * Handles special cases and common English pluralization rules\n *\n * @param singular - The singular form of the noun\n * @returns The plural form of the noun\n */\nexport function pluralize(singular: string): string {\n // Check special cases first (before checking if already plural)\n if (SPECIAL_CASES[singular]) {\n return SPECIAL_CASES[singular];\n }\n\n // Check if it's already plural (ends with 's' and is longer than 3 chars)\n if (singular.length > 3 && singular.endsWith(\"s\") && !singular.endsWith(\"ss\")) {\n // Could already be plural, return as-is\n return singular;\n }\n\n // Preserve case for the transformation\n const lowerSingular = singular.toLowerCase();\n\n let plural: string;\n\n // Rule 1: Words ending in -s, -ss, -sh, -ch, -x, -z -> add -es\n if (/(?:s|ss|sh|ch|x|z)$/.test(lowerSingular)) {\n plural = singular + \"es\";\n }\n // Rule 2: Words ending in consonant + y -> change y to ies\n else if (/[^aeiou]y$/.test(lowerSingular)) {\n plural = singular.slice(0, -1) + \"ies\";\n }\n // Rule 3: Words ending in consonant + o -> add -es\n else if (/[^aeiou]o$/.test(lowerSingular)) {\n plural = singular + \"es\";\n }\n // Rule 4: Words ending in -f or -fe -> change to -ves\n else if (/fe?$/.test(lowerSingular)) {\n if (lowerSingular.endsWith(\"fe\")) {\n plural = singular.slice(0, -2) + \"ves\";\n } else {\n plural = singular.slice(0, -1) + \"ves\";\n }\n }\n // Rule 5: Default -> add -s\n else {\n plural = singular + \"s\";\n }\n\n return plural;\n}\n\n/**\n * Converts a singular entity name to a collection name\n * This is an alias for pluralize for better semantic clarity\n *\n * @param entityName - The singular entity name (e.g., \"User\", \"Project\")\n * @returns The collection name (e.g., \"Users\", \"Projects\")\n */\nexport function toCollectionName(entityName: string): string {\n return pluralize(entityName);\n}\n\n/**\n * Attempts to singularize a plural noun (reverse of pluralize)\n * Note: This is a best-effort implementation and may not handle all edge cases\n *\n * @param plural - The plural form of the noun\n * @returns The singular form of the noun\n */\nexport function singularize(plural: string): string {\n // Check reverse special cases\n for (const [singular, pluralForm] of Object.entries(SPECIAL_CASES)) {\n if (pluralForm === plural) {\n return singular;\n }\n }\n\n const lower = plural.toLowerCase();\n\n // Rule 1: Words ending in -ies -> change to -y\n if (lower.endsWith(\"ies\") && plural.length > 3) {\n return plural.slice(0, -3) + \"y\";\n }\n\n // Rule 2: Words ending in -ves -> change to -f or -fe\n if (lower.endsWith(\"ves\")) {\n // Try -fe first (more common)\n return plural.slice(0, -3) + \"fe\";\n }\n\n // Rule 3: Words ending in -ses, -shes, -ches, -xes, -zes -> remove -es\n if (/(?:ses|shes|ches|xes|zes)$/.test(lower)) {\n return plural.slice(0, -2);\n }\n\n // Rule 4: Words ending in -s -> remove -s\n if (lower.endsWith(\"s\") && plural.length > 1) {\n return plural.slice(0, -1);\n }\n\n // Default: return as-is\n return plural;\n}\n","/**\n * Relation field detection utilities\n */\n\nimport { z } from \"zod\";\nimport { pluralize } from \"./pluralize\";\n\n/**\n * Detects if a field is a single relation based on naming convention\n * Single relation: field name matches a collection name (e.g., \"User\" -> \"Users\" collection)\n */\nexport function isSingleRelationField(fieldName: string, zodType: z.ZodTypeAny): boolean {\n // Unwrap optional/nullable/default\n let unwrappedType = zodType;\n if (zodType instanceof z.ZodOptional) {\n unwrappedType = zodType._def.innerType;\n }\n if (unwrappedType instanceof z.ZodNullable) {\n unwrappedType = unwrappedType._def.innerType;\n }\n if (unwrappedType instanceof z.ZodDefault) {\n unwrappedType = unwrappedType._def.innerType;\n }\n\n // Must be a string type\n if (!(unwrappedType instanceof z.ZodString)) {\n return false;\n }\n\n // Field name should start with uppercase (convention for entity references)\n // and not be a common string field name\n const startsWithUppercase = /^[A-Z]/.test(fieldName);\n\n // Exclude common string fields that start with uppercase\n const commonStringFields = [\"Title\", \"Name\", \"Description\", \"Content\", \"Summary\", \"Status\", \"Type\"];\n const isCommonField = commonStringFields.includes(fieldName);\n\n return startsWithUppercase && !isCommonField;\n}\n\n/**\n * Detects if a field is a multiple relation based on naming convention\n * Multiple relation: field name is an array of strings ending with entity name\n * (e.g., \"SubscriberUsers\" -> \"Users\" collection)\n */\nexport function isMultipleRelationField(fieldName: string, zodType: z.ZodTypeAny): boolean {\n // Unwrap optional/nullable/default\n let unwrappedType = zodType;\n if (zodType instanceof z.ZodOptional) {\n unwrappedType = zodType._def.innerType;\n }\n if (unwrappedType instanceof z.ZodNullable) {\n unwrappedType = unwrappedType._def.innerType;\n }\n if (unwrappedType instanceof z.ZodDefault) {\n unwrappedType = unwrappedType._def.innerType;\n }\n\n // Must be an array type\n if (!(unwrappedType instanceof z.ZodArray)) {\n return false;\n }\n\n // Element type must be string\n const elementType = unwrappedType._def.type;\n if (!(elementType instanceof z.ZodString)) {\n return false;\n }\n\n // Field name should contain an uppercase letter (entity reference pattern)\n const hasUppercase = /[A-Z]/.test(fieldName);\n\n return hasUppercase;\n}\n\n/**\n * Resolves the target collection name from a relation field name\n * Examples:\n * - \"User\" -> \"Users\"\n * - \"SubscriberUsers\" -> \"Users\"\n * - \"Author\" -> \"Authors\"\n * - \"Category\" -> \"Categories\"\n */\nexport function resolveTargetCollection(fieldName: string): string {\n // For single relations, the field name is typically the entity name\n // For multiple relations, extract the entity name from the end\n\n // Check if field name ends with a known plural entity name\n // Common patterns: \"SubscriberUsers\", \"RelatedPosts\", \"Tags\"\n\n // Try to find the entity name by looking for uppercase letters\n const matches = fieldName.match(/[A-Z][a-z]+/g);\n\n if (!matches || matches.length === 0) {\n // Fallback: pluralize the entire field name\n return pluralize(fieldName);\n }\n\n // Take the last matched entity name (e.g., \"Users\" from \"SubscriberUsers\")\n const entityName = matches[matches.length - 1];\n\n // Pluralize the entity name to get collection name\n return pluralize(entityName);\n}\n\n/**\n * Detects if a field is any type of relation (single or multiple)\n */\nexport function isRelationField(fieldName: string, zodType: z.ZodTypeAny): boolean {\n return isSingleRelationField(fieldName, zodType) || isMultipleRelationField(fieldName, zodType);\n}\n\n/**\n * Gets the maximum number of relations allowed for a relation field\n * Returns 1 for single relations, or the max constraint for multiple relations\n */\nexport function getMaxSelect(fieldName: string, zodType: z.ZodTypeAny): number {\n if (isSingleRelationField(fieldName, zodType)) {\n return 1;\n }\n\n if (isMultipleRelationField(fieldName, zodType)) {\n // Unwrap to get to the array type\n let unwrappedType = zodType;\n if (zodType instanceof z.ZodOptional) {\n unwrappedType = zodType._def.innerType;\n }\n if (unwrappedType instanceof z.ZodNullable) {\n unwrappedType = unwrappedType._def.innerType;\n }\n if (unwrappedType instanceof z.ZodDefault) {\n unwrappedType = unwrappedType._def.innerType;\n }\n\n if (unwrappedType instanceof z.ZodArray) {\n // Access the checks array from the array definition\n const arrayDef = unwrappedType._def;\n if (arrayDef.maxLength) {\n return arrayDef.maxLength.value;\n }\n // Default to 999 for multiple relations without explicit max\n return 999;\n }\n }\n\n return 1;\n}\n\n/**\n * Gets the minimum number of relations required for a relation field\n * Returns 0 as default for all relation fields (single or multiple)\n * PocketBase always expects minSelect to be defined for relation fields\n */\nexport function getMinSelect(fieldName: string, zodType: z.ZodTypeAny): number {\n // For single relations, always return 0\n if (isSingleRelationField(fieldName, zodType)) {\n return 0;\n }\n\n // For multiple relations, check for explicit min constraint\n if (isMultipleRelationField(fieldName, zodType)) {\n // Unwrap to get to the array type\n let unwrappedType = zodType;\n if (zodType instanceof z.ZodOptional) {\n unwrappedType = zodType._def.innerType;\n }\n if (unwrappedType instanceof z.ZodNullable) {\n unwrappedType = unwrappedType._def.innerType;\n }\n if (unwrappedType instanceof z.ZodDefault) {\n unwrappedType = unwrappedType._def.innerType;\n }\n\n if (unwrappedType instanceof z.ZodArray) {\n // Access the minLength from the array definition\n const arrayDef = unwrappedType._def;\n if (arrayDef.minLength) {\n return arrayDef.minLength.value;\n }\n }\n }\n\n // Default to 0 for all relation fields\n return 0;\n}\n","/**\n * Zod to PocketBase type mapping utilities\n *\n * This module provides comprehensive mapping between Zod schema types\n * and PocketBase field types, including support for all PocketBase field types:\n * - text, email, url, editor\n * - number, bool\n * - date, autodate\n * - select (single/multiple)\n * - relation (single/multiple)\n * - file (single/multiple)\n * - json\n * - geoPoint\n */\n\nimport { z } from \"zod\";\nimport type { PocketBaseFieldType } from \"../types\";\n\n// Re-export extractFieldMetadata from fields.ts for backward compatibility\nexport { extractFieldMetadata, FIELD_METADATA_KEY } from \"../../schema/fields\";\nexport type { FieldMetadata } from \"../../schema/fields\";\n\n/**\n * All supported PocketBase field types\n */\nexport const POCKETBASE_FIELD_TYPES: readonly PocketBaseFieldType[] = [\n \"text\",\n \"email\",\n \"url\",\n \"number\",\n \"bool\",\n \"date\",\n \"select\",\n \"relation\",\n \"file\",\n \"json\",\n \"editor\",\n \"geoPoint\",\n \"autodate\",\n] as const;\n\n/**\n * Field type metadata for documentation and validation\n */\nexport interface FieldTypeInfo {\n type: PocketBaseFieldType;\n description: string;\n zodTypes: string[];\n supportsMultiple: boolean;\n}\n\n/**\n * Metadata about each PocketBase field type\n */\nexport const FIELD_TYPE_INFO: Record<PocketBaseFieldType, FieldTypeInfo> = {\n text: {\n type: \"text\",\n description: \"Plain text field\",\n zodTypes: [\"ZodString\"],\n supportsMultiple: false,\n },\n email: {\n type: \"email\",\n description: \"Email address field with validation\",\n zodTypes: [\"ZodString with email()\"],\n supportsMultiple: false,\n },\n url: {\n type: \"url\",\n description: \"URL field with validation\",\n zodTypes: [\"ZodString with url()\"],\n supportsMultiple: false,\n },\n editor: {\n type: \"editor\",\n description: \"Rich text editor field\",\n zodTypes: [\"ZodString\"],\n supportsMultiple: false,\n },\n number: {\n type: \"number\",\n description: \"Numeric field (integer or float)\",\n zodTypes: [\"ZodNumber\"],\n supportsMultiple: false,\n },\n bool: {\n type: \"bool\",\n description: \"Boolean field\",\n zodTypes: [\"ZodBoolean\"],\n supportsMultiple: false,\n },\n date: {\n type: \"date\",\n description: \"Date/datetime field\",\n zodTypes: [\"ZodDate\", \"ZodString with datetime format\"],\n supportsMultiple: false,\n },\n autodate: {\n type: \"autodate\",\n description: \"Auto-managed date field (created/updated)\",\n zodTypes: [\"ZodString\"],\n supportsMultiple: false,\n },\n select: {\n type: \"select\",\n description: \"Single or multiple select from predefined values\",\n zodTypes: [\"ZodEnum\", \"ZodArray<ZodEnum>\"],\n supportsMultiple: true,\n },\n relation: {\n type: \"relation\",\n description: \"Reference to another collection\",\n zodTypes: [\"ZodString\", \"ZodArray<ZodString>\"],\n supportsMultiple: true,\n },\n file: {\n type: \"file\",\n description: \"File upload field\",\n zodTypes: [\"File\", \"ZodArray<File>\"],\n supportsMultiple: true,\n },\n json: {\n type: \"json\",\n description: \"JSON data field\",\n zodTypes: [\"ZodRecord\", \"ZodObject\", \"ZodArray\"],\n supportsMultiple: false,\n },\n geoPoint: {\n type: \"geoPoint\",\n description: \"Geographic coordinates (lon, lat)\",\n zodTypes: [\"ZodObject with lon/lat\"],\n supportsMultiple: false,\n },\n};\n\n/**\n * Maps Zod string types to PocketBase field types\n */\nexport function mapZodStringType(zodType: z.ZodString): PocketBaseFieldType {\n const checks = (zodType as any)._def.checks || [];\n\n // Check for email validation\n const hasEmail = checks.some((check: any) => check.kind === \"email\");\n if (hasEmail) {\n return \"email\";\n }\n\n // Check for URL validation\n const hasUrl = checks.some((check: any) => check.kind === \"url\");\n if (hasUrl) {\n return \"url\";\n }\n\n // Check for datetime validation (could be date field)\n const hasDatetime = checks.some((check: any) => check.kind === \"datetime\");\n if (hasDatetime) {\n return \"date\";\n }\n\n // Default to text\n return \"text\";\n}\n\n/**\n * Maps Zod number types to PocketBase number type\n */\nexport function mapZodNumberType(_zodType: z.ZodNumber): PocketBaseFieldType {\n return \"number\";\n}\n\n/**\n * Maps Zod boolean types to PocketBase bool type\n */\nexport function mapZodBooleanType(_zodType: z.ZodBoolean): PocketBaseFieldType {\n return \"bool\";\n}\n\n/**\n * Maps Zod enum types to PocketBase select type\n */\nexport function mapZodEnumType(_zodType: z.ZodEnum<any>): PocketBaseFieldType {\n return \"select\";\n}\n\n/**\n * Maps Zod array types to appropriate PocketBase types\n * Arrays of strings could be relations or file fields depending on context\n */\nexport function mapZodArrayType(zodType: z.ZodArray<any>, _fieldName: string): PocketBaseFieldType {\n const elementType = zodType._def.type;\n\n // Check if it's an array of File instances (file upload)\n if (elementType instanceof z.ZodType) {\n const typeName = elementType._def.typeName;\n if (typeName === \"ZodType\" && (elementType as any)._def?.innerType?.name === \"File\") {\n return \"file\";\n }\n }\n\n // Check for instanceof File\n if (elementType._def?.typeName === \"ZodType\") {\n const checks = (elementType as any)._def?.checks || [];\n const isFileInstance = checks.some(\n (check: any) => check.kind === \"instanceof\" || (elementType as any)._def?.innerType?.name === \"File\"\n );\n if (isFileInstance) {\n return \"file\";\n }\n }\n\n // Array of strings - could be relation (will be determined by relation detector)\n if (elementType instanceof z.ZodString) {\n return \"relation\";\n }\n\n // Default to JSON for other array types\n return \"json\";\n}\n\n/**\n * Maps Zod date types to PocketBase date type\n */\nexport function mapZodDateType(_zodType: z.ZodDate): PocketBaseFieldType {\n return \"date\";\n}\n\n/**\n * Maps Zod record/object types to PocketBase JSON type\n */\nexport function mapZodRecordType(_zodType: z.ZodRecord | z.ZodObject<any>): PocketBaseFieldType {\n return \"json\";\n}\n\n/**\n * Main type mapping function that determines PocketBase field type from Zod type\n */\nexport function mapZodTypeToPocketBase(zodType: z.ZodTypeAny, fieldName: string): PocketBaseFieldType {\n // Handle optional and nullable types by unwrapping\n let unwrappedType = zodType;\n\n if (zodType instanceof z.ZodOptional) {\n unwrappedType = zodType._def.innerType;\n }\n\n if (unwrappedType instanceof z.ZodNullable) {\n unwrappedType = unwrappedType._def.innerType;\n }\n\n if (unwrappedType instanceof z.ZodDefault) {\n unwrappedType = unwrappedType._def.innerType;\n }\n\n // Check for ZodEffects (which is what z.instanceof() creates)\n if ((unwrappedType as any)._def?.typeName === \"ZodEffects\") {\n const effect = (unwrappedType as any)._def?.effect;\n\n // z.instanceof(File) creates a refinement effect\n // We need to check if this is a File instance check\n // The field name 'avatar', 'image', 'file', 'attachment' etc. are hints\n if (effect?.type === \"refinement\") {\n // Common file field names\n const fileFieldNames = [\"avatar\", \"image\", \"file\", \"attachment\", \"photo\", \"picture\", \"document\", \"upload\"];\n if (fileFieldNames.some((name) => fieldName.toLowerCase().includes(name))) {\n return \"file\";\n }\n }\n }\n\n // Check for instanceof File (z.instanceof(File)) - legacy check\n if ((unwrappedType as any)._def?.typeName === \"ZodType\") {\n const checks = (unwrappedType as any)._def?.checks || [];\n const innerType = (unwrappedType as any)._def?.innerType;\n\n // Check if it's instanceof File\n if (innerType?.name === \"File\" || checks.some((check: any) => check.kind === \"instanceof\")) {\n return \"file\";\n }\n }\n\n // Map based on Zod type\n if (unwrappedType instanceof z.ZodString) {\n return mapZodStringType(unwrappedType);\n }\n\n if (unwrappedType instanceof z.ZodNumber) {\n return mapZodNumberType(unwrappedType);\n }\n\n if (unwrappedType instanceof z.ZodBoolean) {\n return mapZodBooleanType(unwrappedType);\n }\n\n if (unwrappedType instanceof z.ZodEnum) {\n return mapZodEnumType(unwrappedType);\n }\n\n if (unwrappedType instanceof z.ZodArray) {\n return mapZodArrayType(unwrappedType, fieldName);\n }\n\n if (unwrappedType instanceof z.ZodDate) {\n return mapZodDateType(unwrappedType);\n }\n\n if (unwrappedType instanceof z.ZodRecord || unwrappedType instanceof z.ZodObject) {\n return mapZodRecordType(unwrappedType);\n }\n\n // Default to text for unknown types\n return \"text\";\n}\n\n/**\n * Extracts field options from Zod type (min, max, pattern, etc.)\n */\nexport function extractFieldOptions(zodType: z.ZodTypeAny): Record<string, any> {\n const options: Record<string, any> = {};\n\n // Unwrap optional/nullable/default\n let unwrappedType = zodType;\n if (zodType instanceof z.ZodOptional) {\n unwrappedType = zodType._def.innerType;\n }\n if (unwrappedType instanceof z.ZodNullable) {\n unwrappedType = unwrappedType._def.innerType;\n }\n if (unwrappedType instanceof z.ZodDefault) {\n unwrappedType = unwrappedType._def.innerType;\n }\n\n const checks = (unwrappedType as any)._def?.checks || [];\n\n // Extract string constraints\n if (unwrappedType instanceof z.ZodString) {\n for (const check of checks) {\n if (check.kind === \"min\") {\n options.min = check.value;\n }\n if (check.kind === \"max\") {\n options.max = check.value;\n }\n if (check.kind === \"regex\") {\n options.pattern = check.regex.source;\n }\n }\n }\n\n // Extract number constraints\n if (unwrappedType instanceof z.ZodNumber) {\n for (const check of checks) {\n if (check.kind === \"min\") {\n options.min = check.value;\n }\n if (check.kind === \"max\") {\n options.max = check.value;\n }\n }\n }\n\n // Extract enum values\n if (unwrappedType instanceof z.ZodEnum) {\n options.values = unwrappedType._def.values;\n }\n\n // Extract array constraints\n if (unwrappedType instanceof z.ZodArray) {\n const arrayChecks = (unwrappedType as any)._def?.checks || [];\n for (const check of arrayChecks) {\n if (check.kind === \"min\") {\n options.minSelect = check.value;\n }\n if (check.kind === \"max\") {\n options.maxSelect = check.value;\n }\n }\n }\n\n return options;\n}\n\n/**\n * Determines if a Zod field is required (not optional)\n */\nexport function isFieldRequired(zodType: z.ZodTypeAny): boolean {\n // Check if it's optional\n if (zodType instanceof z.ZodOptional) {\n return false;\n }\n\n // Check if it has a default value (makes it optional)\n if (zodType instanceof z.ZodDefault) {\n return false;\n }\n\n // Check for nullable (in PocketBase context, nullable means optional)\n if (zodType instanceof z.ZodNullable) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Unwraps a Zod type to get the inner type\n * Handles optional, nullable, and default wrappers\n */\nexport function unwrapZodType(zodType: z.ZodTypeAny): z.ZodTypeAny {\n let unwrapped = zodType;\n\n if (unwrapped instanceof z.ZodOptional) {\n unwrapped = unwrapped._def.innerType;\n }\n\n if (unwrapped instanceof z.ZodNullable) {\n unwrapped = unwrapped._def.innerType;\n }\n\n if (unwrapped instanceof z.ZodDefault) {\n unwrapped = unwrapped._def.innerType;\n }\n\n return unwrapped;\n}\n\n/**\n * Gets the default value from a Zod type if it has one\n */\nexport function getDefaultValue(zodType: z.ZodTypeAny): any {\n if (zodType instanceof z.ZodDefault) {\n return zodType._def.defaultValue();\n }\n return undefined;\n}\n\n/**\n * Checks if a Zod type is an array type\n */\nexport function isArrayType(zodType: z.ZodTypeAny): boolean {\n const unwrapped = unwrapZodType(zodType);\n return unwrapped instanceof z.ZodArray;\n}\n\n/**\n * Gets the element type of an array Zod type\n */\nexport function getArrayElementType(zodType: z.ZodTypeAny): z.ZodTypeAny | null {\n const unwrapped = unwrapZodType(zodType);\n if (unwrapped instanceof z.ZodArray) {\n return unwrapped._def.type;\n }\n return null;\n}\n\n/**\n * Checks if a Zod type represents a geo point (object with lon/lat)\n */\nexport function isGeoPointType(zodType: z.ZodTypeAny): boolean {\n const unwrapped = unwrapZodType(zodType);\n if (!(unwrapped instanceof z.ZodObject)) {\n return false;\n }\n\n const shape = unwrapped._def.shape();\n const hasLon = \"lon\" in shape && shape.lon instanceof z.ZodNumber;\n const hasLat = \"lat\" in shape && shape.lat instanceof z.ZodNumber;\n\n return hasLon && hasLat;\n}\n\n/**\n * Complete field options extracted from a Zod type\n */\nexport interface ExtractedFieldOptions {\n min?: number;\n max?: number;\n pattern?: string;\n values?: string[];\n minSelect?: number;\n maxSelect?: number;\n mimeTypes?: string[];\n maxSize?: number;\n thumbs?: string[];\n}\n\n/**\n * Extracts comprehensive field options from Zod type\n * Includes all constraints that can be mapped to PocketBase field options\n */\nexport function extractComprehensiveFieldOptions(zodType: z.ZodTypeAny): ExtractedFieldOptions {\n const options: ExtractedFieldOptions = {};\n const unwrapped = unwrapZodType(zodType);\n const checks = (unwrapped as any)._def?.checks || [];\n\n // Extract string constraints\n if (unwrapped instanceof z.ZodString) {\n for (const check of checks) {\n if (check.kind === \"min\") {\n options.min = check.value;\n }\n if (check.kind === \"max\") {\n options.max = check.value;\n }\n if (check.kind === \"regex\") {\n options.pattern = check.regex.source;\n }\n }\n }\n\n // Extract number constraints\n if (unwrapped instanceof z.ZodNumber) {\n for (const check of checks) {\n if (check.kind === \"min\") {\n options.min = check.value;\n }\n if (check.kind === \"max\") {\n options.max = check.value;\n }\n }\n }\n\n // Extract enum values\n if (unwrapped instanceof z.ZodEnum) {\n options.values = unwrapped._def.values;\n }\n\n // Extract array constraints\n if (unwrapped instanceof z.ZodArray) {\n const arrayDef = unwrapped._def;\n if (arrayDef.minLength) {\n options.minSelect = arrayDef.minLength.value;\n }\n if (arrayDef.maxLength) {\n options.maxSelect = arrayDef.maxLength.value;\n }\n\n // Check for enum element type\n const elementType = arrayDef.type;\n if (elementType instanceof z.ZodEnum) {\n options.values = elementType._def.values;\n }\n }\n\n return options;\n}\n\n/**\n * Determines if a field should be treated as an editor field\n * based on field name conventions\n */\nexport function isEditorField(fieldName: string): boolean {\n const editorFieldNames = [\n \"content\",\n \"body\",\n \"description\",\n \"bio\",\n \"about\",\n \"summary\",\n \"notes\",\n \"details\",\n \"html\",\n \"richtext\",\n \"editor\",\n ];\n return editorFieldNames.some((name) => fieldName.toLowerCase().includes(name));\n}\n\n/**\n * Determines if a field should be treated as a file field\n * based on field name conventions\n */\nexport function isFileFieldByName(fieldName: string): boolean {\n const fileFieldNames = [\n \"avatar\",\n \"image\",\n \"file\",\n \"attachment\",\n \"photo\",\n \"picture\",\n \"document\",\n \"upload\",\n \"thumbnail\",\n \"cover\",\n \"banner\",\n \"logo\",\n \"icon\",\n \"media\",\n ];\n return fileFieldNames.some((name) => fieldName.toLowerCase().includes(name));\n}\n\n/**\n * Gets the PocketBase field type with additional context\n */\nexport interface FieldTypeResult {\n type: PocketBaseFieldType;\n isMultiple: boolean;\n options: ExtractedFieldOptions;\n}\n\n/**\n * Comprehensive type mapping that returns full field information\n */\nexport function getFieldTypeInfo(zodType: z.ZodTypeAny, fieldName: string): FieldTypeResult {\n const type = mapZodTypeToPocketBase(zodType, fieldName);\n const isMultiple = isArrayType(zodType);\n const options = extractComprehensiveFieldOptions(zodType);\n\n return {\n type,\n isMultiple,\n options,\n };\n}\n","/**\n * Schema Analyzer - Parses Zod schemas and extracts field definitions\n *\n * This module provides a standalone, configurable schema analyzer that can be used\n * by consumer projects to parse Zod schemas and convert them to PocketBase collection schemas.\n */\n\nimport * as fs from \"fs\";\nimport * as path from \"path\";\nimport { z } from \"zod\";\nimport { extractRelationMetadata } from \"../schema/base\";\nimport { extractFieldMetadata } from \"../schema/fields\";\nimport type { PermissionSchema } from \"../utils/permissions\";\nimport { FileSystemError, SchemaParsingError } from \"./errors\";\nimport { PermissionAnalyzer } from \"./permission-analyzer\";\nimport type { CollectionSchema, FieldDefinition, SchemaDefinition } from \"./types\";\nimport { toCollectionName } from \"./utils/pluralize\";\nimport { getMaxSelect, getMinSelect, isRelationField, resolveTargetCollection } from \"./utils/relation-detector\";\nimport { extractFieldOptions, isFieldRequired, mapZodTypeToPocketBase } from \"./utils/type-mapper\";\n\n// Register tsx loader for TypeScript file support\n// This allows dynamic imports of .ts files to work\nlet tsxLoaderRegistered = false;\nasync function ensureTsxLoader(): Promise<void> {\n if (tsxLoaderRegistered) return;\n\n try {\n // Import tsx/esm to register the TypeScript loader hooks\n // This enables dynamic imports of .ts files in Node.js ESM\n await import(\"tsx/esm\");\n tsxLoaderRegistered = true;\n } catch {\n // tsx is not available - will handle in importSchemaModule\n tsxLoaderRegistered = false;\n }\n}\n\n/**\n * Configuration options for schema discovery and parsing\n */\nexport interface SchemaAnalyzerConfig {\n /**\n * Directory containing schema files (source or compiled)\n * Can be absolute or relative to workspaceRoot\n */\n schemaDir: string;\n\n /**\n * Workspace root directory for resolving relative paths\n * Defaults to process.cwd()\n */\n workspaceRoot?: string;\n\n /**\n * File patterns to exclude from schema discovery\n * Defaults to ['base.ts', 'index.ts', 'permissions.ts', 'permission-templates.ts']\n */\n excludePatterns?: string[];\n\n /**\n * File extensions to include in schema discovery\n * Defaults to ['.ts', '.js']\n */\n includeExtensions?: string[];\n\n /**\n * Schema export name patterns to look for\n * Defaults to ['Schema', 'InputSchema']\n */\n schemaPatterns?: string[];\n\n /**\n * Whether to use compiled JavaScript files instead of TypeScript source\n * When true, looks for .js files; when false, looks for .ts files\n * Defaults to true (use compiled files for dynamic import)\n */\n useCompiledFiles?: boolean;\n\n /**\n * Custom path transformation function for converting source paths to import paths\n * Useful for monorepo setups where source and dist directories differ\n * If not provided, uses the schemaDir directly\n */\n pathTransformer?: (sourcePath: string) => string;\n}\n\n/**\n * Default configuration values\n */\nconst DEFAULT_CONFIG: Required<Omit<SchemaAnalyzerConfig, \"schemaDir\" | \"pathTransformer\">> = {\n workspaceRoot: process.cwd(),\n excludePatterns: [\n \"base.ts\",\n \"index.ts\",\n \"permissions.ts\",\n \"permission-templates.ts\",\n \"base.js\",\n \"index.js\",\n \"permissions.js\",\n \"permission-templates.js\",\n ],\n includeExtensions: [\".ts\", \".js\"],\n schemaPatterns: [\"Schema\", \"InputSchema\", \"Collection\"],\n useCompiledFiles: true,\n};\n\n/**\n * Merges user config with defaults\n */\nfunction mergeConfig(\n config: SchemaAnalyzerConfig\n): Required<Omit<SchemaAnalyzerConfig, \"pathTransformer\">> & { pathTransformer?: (sourcePath: string) => string } {\n return {\n ...DEFAULT_CONFIG,\n ...config,\n excludePatterns: config.excludePatterns || DEFAULT_CONFIG.excludePatterns,\n includeExtensions: config.includeExtensions || DEFAULT_CONFIG.includeExtensions,\n schemaPatterns: config.schemaPatterns || DEFAULT_CONFIG.schemaPatterns,\n };\n}\n\n/**\n * Resolves the schema directory path\n */\nfunction resolveSchemaDir(config: SchemaAnalyzerConfig): string {\n const workspaceRoot = config.workspaceRoot || process.cwd();\n\n if (path.isAbsolute(config.schemaDir)) {\n return config.schemaDir;\n }\n\n return path.join(workspaceRoot, config.schemaDir);\n}\n\n/**\n * Discovers schema files in the specified directory\n * Filters based on configuration patterns\n *\n * @param config - Schema analyzer configuration\n * @returns Array of schema file paths (without extension)\n */\nexport function discoverSchemaFiles(config: SchemaAnalyzerConfig | string): string[] {\n // Support legacy string-only parameter\n const normalizedConfig: SchemaAnalyzerConfig = typeof config === \"string\" ? { schemaDir: config } : config;\n\n const mergedConfig = mergeConfig(normalizedConfig);\n const schemaDir = resolveSchemaDir(normalizedConfig);\n\n try {\n if (!fs.existsSync(schemaDir)) {\n throw new FileSystemError(`Schema directory not found: ${schemaDir}`, schemaDir, \"access\", \"ENOENT\");\n }\n\n const files = fs.readdirSync(schemaDir);\n\n // Filter files based on configuration\n const schemaFiles = files.filter((file) => {\n // Check extension\n const hasValidExtension = mergedConfig.includeExtensions.some((ext) => file.endsWith(ext));\n if (!hasValidExtension) return false;\n\n // Check exclusion patterns\n const isExcluded = mergedConfig.excludePatterns.some((pattern) => {\n // Support both exact match and glob-like patterns\n if (pattern.includes(\"*\")) {\n const regex = new RegExp(\"^\" + pattern.replace(/\\*/g, \".*\") + \"$\");\n return regex.test(file);\n }\n return file === pattern;\n });\n if (isExcluded) return false;\n\n return true;\n });\n\n // Return full paths without extension (for dynamic import)\n return schemaFiles.map((file) => {\n const ext = mergedConfig.includeExtensions.find((ext) => file.endsWith(ext)) || \".ts\";\n return path.join(schemaDir, file.replace(new RegExp(`\\\\${ext}$`), \"\"));\n });\n } catch (error) {\n if (error instanceof FileSystemError) {\n throw error;\n }\n\n const fsError = error as NodeJS.ErrnoException;\n if (fsError.code === \"EACCES\" || fsError.code === \"EPERM\") {\n throw new FileSystemError(\n `Permission denied reading schema directory: ${schemaDir}`,\n schemaDir,\n \"read\",\n fsError.code,\n error as Error\n );\n }\n\n throw new FileSystemError(\n `Failed to read schema directory: ${schemaDir}`,\n schemaDir,\n \"read\",\n fsError.code,\n error as Error\n );\n }\n}\n\n/**\n * Dynamically imports a schema module\n * Supports both JavaScript and TypeScript files using tsx\n *\n * @param filePath - Path to the schema file (without extension)\n * @param config - Optional configuration for path transformation\n * @returns The imported module\n */\nexport async function importSchemaModule(filePath: string, config?: SchemaAnalyzerConfig): Promise<any> {\n try {\n let importPath = filePath;\n\n // Apply path transformation if provided\n if (config?.pathTransformer) {\n importPath = config.pathTransformer(filePath);\n }\n\n // Determine the file extension to use\n // Try .js first (for compiled files), then .ts (for source files)\n let resolvedPath: string | null = null;\n const jsPath = `${importPath}.js`;\n const tsPath = `${importPath}.ts`;\n\n if (fs.existsSync(jsPath)) {\n resolvedPath = jsPath;\n } else if (fs.existsSync(tsPath)) {\n resolvedPath = tsPath;\n } else {\n // Default to .js extension for ESM import\n resolvedPath = jsPath;\n }\n\n // If it's a TypeScript file, ensure tsx loader is registered\n if (resolvedPath.endsWith(\".ts\")) {\n await ensureTsxLoader();\n\n // Check if tsx was successfully registered\n if (!tsxLoaderRegistered) {\n throw new SchemaParsingError(\n `Failed to import TypeScript schema file. The 'tsx' package is required to load TypeScript files.\\n` +\n `Please install tsx: npm install tsx (or yarn add tsx, or pnpm add tsx)\\n` +\n `Alternatively, compile your schema files to JavaScript first.`,\n filePath\n );\n }\n }\n\n // Convert to file URL for proper ESM import\n const fileUrl = new URL(`file://${path.resolve(resolvedPath)}`);\n\n // Use dynamic import to load the module\n // tsx/esm will handle TypeScript files automatically if registered\n const module = await import(fileUrl.href);\n return module;\n } catch (error) {\n // Check if we're trying to import a TypeScript file\n const tsPath = `${filePath}.ts`;\n const isTypeScriptFile = fs.existsSync(tsPath);\n\n if (isTypeScriptFile && error instanceof SchemaParsingError) {\n // Re-throw SchemaParsingError as-is (already has helpful message)\n throw error;\n }\n\n if (isTypeScriptFile) {\n throw new SchemaParsingError(\n `Failed to import TypeScript schema file. The 'tsx' package is required to load TypeScript files.\\n` +\n `Please install tsx: npm install tsx (or yarn add tsx, or pnpm add tsx)\\n` +\n `Alternatively, compile your schema files to JavaScript first.`,\n filePath,\n error as Error\n );\n }\n\n throw new SchemaParsingError(\n `Failed to import schema module. Make sure the schema files exist and are valid.`,\n filePath,\n error as Error\n );\n }\n}\n\n/**\n * Gets the collection name from a schema file path\n * Converts the filename (without extension) to a pluralized collection name\n *\n * @param filePath - Path to the schema file (with or without extension)\n * @returns The collection name\n */\nexport function getCollectionNameFromFile(filePath: string): string {\n // Remove both .ts and .js extensions if present\n const filename = path.basename(filePath).replace(/\\.(ts|js)$/, \"\");\n return toCollectionName(filename);\n}\n\n/**\n * Extracts the collection name from a Zod schema's metadata\n * Checks if the schema was created with defineCollection() which stores\n * the collection name in the schema description\n *\n * @param zodSchema - The Zod schema to extract collection name from\n * @returns The collection name if found in metadata, null otherwise\n */\nexport function extractCollectionNameFromSchema(zodSchema: z.ZodTypeAny): string | null {\n if (!zodSchema.description) {\n return null;\n }\n\n try {\n const metadata = JSON.parse(zodSchema.description);\n if (metadata.collectionName && typeof metadata.collectionName === \"string\") {\n return metadata.collectionName;\n }\n } catch {\n // Not JSON or no collectionName - this is expected for schemas without defineCollection\n }\n\n return null;\n}\n\n/**\n * Extracts the collection type from a Zod schema's metadata\n * Checks if the schema was created with defineCollection() which stores\n * the collection type in the schema description\n *\n * @param zodSchema - The Zod schema to extract collection type from\n * @returns The collection type (\"base\" | \"auth\") if found in metadata, null otherwise\n */\nexport function extractCollectionTypeFromSchema(zodSchema: z.ZodTypeAny): \"base\" | \"auth\" | null {\n if (!zodSchema.description) {\n return null;\n }\n\n try {\n const metadata = JSON.parse(zodSchema.description);\n if (metadata.type === \"base\" || metadata.type === \"auth\") {\n return metadata.type;\n }\n } catch {\n // Not JSON or no type - this is expected for schemas without explicit type\n }\n\n return null;\n}\n\n/**\n * Extracts Zod schema definitions from a module\n *\n * Detection priority (highest to lowest):\n * 1. Default export - recommended pattern for clarity and explicitness\n * 2. Named exports ending with \"Collection\" - contains metadata (indexes, permissions)\n * 3. Named exports ending with \"Schema\" - basic schema definitions\n * 4. Named exports ending with \"InputSchema\" - form input schemas\n *\n * @param module - The imported schema module\n * @param patterns - Schema name patterns to look for (default: ['Schema', 'InputSchema', 'Collection'])\n * @returns Object containing found schemas\n *\n * @example\n * // Recommended: Use default export\n * const UserCollection = defineCollection({ ... });\n * export default UserCollection;\n *\n * @example\n * // Also supported: Named export with pattern\n * export const UserCollection = defineCollection({ ... });\n */\nexport function extractSchemaDefinitions(\n module: any,\n patterns: string[] = [\"Schema\", \"InputSchema\", \"Collection\"]\n): { inputSchema?: z.ZodObject<any>; schema?: z.ZodObject<any> } {\n const result: { inputSchema?: z.ZodObject<any>; schema?: z.ZodObject<any> } = {};\n\n // Priority 1: Check for default export (highest priority, most explicit)\n // This allows each file to have one clear schema definition\n if (module.default instanceof z.ZodObject) {\n // Default export is always the primary schema\n result.schema = module.default as z.ZodObject<any>;\n // If we have a default export, we can return early as it takes precedence\n // But we still check for InputSchema for backward compatibility\n }\n\n // Priority 2: Look for named exports matching patterns (for backward compatibility)\n for (const [key, value] of Object.entries(module)) {\n // Skip default export as we already handled it\n if (key === \"default\") continue;\n\n // Check if it's a Zod schema\n if (value instanceof z.ZodObject) {\n // Check for InputSchema pattern (used for form validation)\n if (patterns.includes(\"InputSchema\") && key.endsWith(\"InputSchema\")) {\n result.inputSchema = value as z.ZodObject<any>;\n } else if (!result.schema) {\n // Only set schema if we haven't found one via default export\n if (patterns.includes(\"Collection\") && key.endsWith(\"Collection\")) {\n // Prefer Collection over Schema as it has metadata (indexes, permissions)\n result.schema = value as z.ZodObject<any>;\n } else if (patterns.includes(\"Schema\") && key.endsWith(\"Schema\") && !key.endsWith(\"InputSchema\")) {\n result.schema = value as z.ZodObject<any>;\n }\n }\n }\n }\n\n return result;\n}\n\n/**\n * Identifies whether to use InputSchema or Schema pattern\n * Prefers Schema over InputSchema as it includes base fields\n *\n * @param schemas - Object containing inputSchema and/or schema\n * @returns The schema to use for collection definition\n */\nexport function selectSchemaForCollection(schemas: {\n inputSchema?: z.ZodObject<any>;\n schema?: z.ZodObject<any>;\n}): z.ZodObject<any> | null {\n // Prefer the full Schema over InputSchema as it includes base fields\n if (schemas.schema) {\n return schemas.schema;\n }\n\n if (schemas.inputSchema) {\n return schemas.inputSchema;\n }\n\n return null;\n}\n\n/**\n * Extracts field definitions from a Zod object schema\n * Filters out base schema fields (id, collectionId, created, updated, expand)\n *\n * @param zodSchema - The Zod object schema\n * @param excludeFields - Additional fields to exclude (default: base schema fields)\n * @returns Array of field names and their Zod types\n */\nexport function extractFieldDefinitions(\n zodSchema: z.ZodObject<any>,\n excludeFields?: string[]\n): Array<{ name: string; zodType: z.ZodTypeAny }> {\n const shape = zodSchema.shape;\n const fields: Array<{ name: string; zodType: z.ZodTypeAny }> = [];\n\n // Base schema fields to exclude (these are system fields in PocketBase)\n const baseFields = [\"id\", \"collectionId\", \"collectionName\", \"created\", \"updated\", \"expand\"];\n\n // Additional fields to exclude (image file handling fields)\n const defaultExcludeFields = [\"thumbnailURL\", \"imageFiles\"];\n\n // Combine all exclusions\n const allExclusions = new Set([...baseFields, ...defaultExcludeFields, ...(excludeFields || [])]);\n\n for (const [fieldName, zodType] of Object.entries(shape)) {\n // Skip excluded fields\n if (!allExclusions.has(fieldName)) {\n fields.push({ name: fieldName, zodType: zodType as z.ZodTypeAny });\n }\n }\n\n return fields;\n}\n\n/**\n * Detects if a collection is an auth collection\n * Auth collections have email and password fields\n *\n * @param fields - Array of field definitions\n * @returns True if the collection is an auth collection\n */\nexport function isAuthCollection(fields: Array<{ name: string; zodType: z.ZodTypeAny }>): boolean {\n const fieldNames = fields.map((f) => f.name.toLowerCase());\n\n // Auth collections must have both email and password fields\n const hasEmail = fieldNames.includes(\"email\");\n const hasPassword = fieldNames.includes(\"password\");\n\n return hasEmail && hasPassword;\n}\n\n/**\n * Extracts validation constraints from Zod type\n * Includes min, max, required, unique, and other options\n *\n * @param fieldName - The field name\n * @param zodType - The Zod type\n * @returns Field definition with constraints\n */\nexport function buildFieldDefinition(fieldName: string, zodType: z.ZodTypeAny): FieldDefinition {\n // Check for explicit field metadata first (from field helper functions)\n const fieldMetadata = extractFieldMetadata(zodType.description);\n\n if (fieldMetadata) {\n // Use explicit metadata from field helpers\n // For number fields, default to required: false unless explicitly set\n // (because required: true in PocketBase means non-zero, which is often not desired)\n let required: boolean;\n if (fieldMetadata.type === \"number\") {\n // Check if required is explicitly set in options\n if (fieldMetadata.options?.required !== undefined) {\n required = fieldMetadata.options.required;\n } else {\n // Default to false for number fields to allow zero values\n // This allows zero values (e.g., progress: 0-100) unless explicitly set to required: true\n required = false;\n }\n } else {\n // For other field types, use standard logic\n required = isFieldRequired(zodType);\n }\n\n // Remove 'required' from options if present (it's a top-level property, not an option)\n const { required: _required, ...options } = fieldMetadata.options || {};\n\n const fieldDef: FieldDefinition = {\n name: fieldName,\n type: fieldMetadata.type,\n required,\n options: Object.keys(options).length > 0 ? options : undefined,\n };\n\n // If it's a relation type from metadata, we still need to extract relation config\n if (fieldMetadata.type === \"relation\") {\n const relationMetadata = extractRelationMetadata(zodType.description);\n if (relationMetadata) {\n fieldDef.relation = {\n collection: relationMetadata.collection,\n maxSelect: relationMetadata.maxSelect,\n minSelect: relationMetadata.minSelect,\n cascadeDelete: relationMetadata.cascadeDelete,\n };\n }\n }\n\n return fieldDef;\n }\n\n // Fall back to existing type inference logic\n const fieldType = mapZodTypeToPocketBase(zodType, fieldName);\n const required = isFieldRequired(zodType);\n const options = extractFieldOptions(zodType);\n\n const fieldDef: FieldDefinition = {\n name: fieldName,\n type: fieldType,\n required,\n options,\n };\n\n // Check for explicit relation metadata first (from relation() or relations() helpers)\n const relationMetadata = extractRelationMetadata(zodType.description);\n\n if (relationMetadata) {\n // Explicit relation definition found\n fieldDef.type = \"relation\";\n fieldDef.relation = {\n collection: relationMetadata.collection,\n maxSelect: relationMetadata.maxSelect,\n minSelect: relationMetadata.minSelect,\n cascadeDelete: relationMetadata.cascadeDelete,\n };\n\n // Clear out string-specific options that don't apply to relation fields\n fieldDef.options = undefined;\n }\n // Fall back to naming convention detection for backward compatibility\n else if (isRelationField(fieldName, zodType)) {\n // Override type to 'relation' for relation fields\n fieldDef.type = \"relation\";\n\n const targetCollection = resolveTargetCollection(fieldName);\n const maxSelect = getMaxSelect(fieldName, zodType);\n const minSelect = getMinSelect(fieldName, zodType);\n\n fieldDef.relation = {\n collection: targetCollection,\n maxSelect,\n minSelect,\n cascadeDelete: false, // Default to false, can be configured later\n };\n\n // Clear out string-specific options that don't apply to relation fields\n // Options like 'min', 'max', 'pattern' are from string validation and don't apply to relations\n if (fieldDef.options) {\n const { min: _min, max: _max, pattern: _pattern, ...relationSafeOptions } = fieldDef.options;\n fieldDef.options = Object.keys(relationSafeOptions).length ? relationSafeOptions : undefined;\n }\n }\n\n return fieldDef;\n}\n\n/**\n * Extracts index definitions from a Zod schema\n * Parses the schema description metadata to find index definitions\n *\n * @param schema - Zod schema with index metadata\n * @returns Array of index SQL statements or undefined\n */\nexport function extractIndexes(schema: z.ZodTypeAny): string[] | undefined {\n // Try to extract indexes from schema description\n const schemaDescription = schema.description;\n\n if (!schemaDescription) {\n return undefined;\n }\n\n try {\n const metadata = JSON.parse(schemaDescription);\n\n // Check if indexes are present in metadata\n if (metadata.indexes && Array.isArray(metadata.indexes)) {\n return metadata.indexes;\n }\n } catch {\n // If description is not valid JSON, return undefined\n }\n\n return undefined;\n}\n\n/**\n * Converts a Zod schema to a CollectionSchema interface\n *\n * @param collectionName - The name of the collection\n * @param zodSchema - The Zod object schema\n * @returns CollectionSchema definition\n */\nexport function convertZodSchemaToCollectionSchema(\n collectionName: string,\n zodSchema: z.ZodObject<any>\n): CollectionSchema {\n // Extract field definitions from Zod schema\n const rawFields = extractFieldDefinitions(zodSchema);\n\n // Determine collection type (auth or base)\n // Prefer explicit type from metadata, fall back to field detection\n const explicitType = extractCollectionTypeFromSchema(zodSchema);\n const collectionType = explicitType ?? (isAuthCollection(rawFields) ? \"auth\" : \"base\");\n\n // Build field definitions with constraints\n let fields: FieldDefinition[] = rawFields.map(({ name, zodType }) => buildFieldDefinition(name, zodType));\n\n // Exclude auth system fields for auth collections (PocketBase adds them automatically)\n if (collectionType === \"auth\") {\n const authSystemFieldNames = [\"email\", \"emailVisibility\", \"verified\", \"password\", \"tokenKey\"];\n fields = fields.filter((field) => !authSystemFieldNames.includes(field.name));\n }\n\n // Extract indexes from schema\n const indexes = extractIndexes(zodSchema) || [];\n\n // Extract and validate permissions from schema\n const permissionAnalyzer = new PermissionAnalyzer();\n let permissions: PermissionSchema | undefined = undefined;\n\n // Try to extract permissions from schema description\n const schemaDescription = zodSchema.description;\n const extractedPermissions = permissionAnalyzer.extractPermissions(schemaDescription);\n\n if (extractedPermissions) {\n // Resolve template configurations to concrete rules\n const resolvedPermissions = permissionAnalyzer.resolvePermissions(extractedPermissions);\n\n // Validate permissions against collection fields\n const validationResults = permissionAnalyzer.validatePermissions(\n collectionName,\n resolvedPermissions,\n fields,\n collectionType === \"auth\"\n );\n\n // Log validation errors and warnings\n for (const [ruleType, result] of validationResults) {\n if (!result.valid) {\n console.error(`[${collectionName}] Permission validation failed for ${ruleType}:`);\n result.errors.forEach((error) => console.error(` - ${error}`));\n }\n\n if (result.warnings.length > 0) {\n console.warn(`[${collectionName}] Permission warnings for ${ruleType}:`);\n result.warnings.forEach((warning) => console.warn(` - ${warning}`));\n }\n }\n\n // Merge with defaults to ensure all rules are defined\n permissions = permissionAnalyzer.mergeWithDefaults(resolvedPermissions);\n }\n\n // Build collection schema\n // Use extracted permissions for rules, falling back to nulls\n const collectionSchema: CollectionSchema = {\n name: collectionName,\n type: collectionType,\n fields,\n indexes,\n rules: {\n listRule: permissions?.listRule ?? null,\n viewRule: permissions?.viewRule ?? null,\n createRule: permissions?.createRule ?? null,\n updateRule: permissions?.updateRule ?? null,\n deleteRule: permissions?.deleteRule ?? null,\n manageRule: permissions?.manageRule ?? null,\n },\n permissions,\n };\n\n return collectionSchema;\n}\n\n/**\n * Builds a complete SchemaDefinition from schema files\n * Main entry point for the Schema Analyzer\n *\n * @param config - Schema analyzer configuration or path to schema directory\n * @returns Complete SchemaDefinition with all collections\n */\nexport async function buildSchemaDefinition(config: SchemaAnalyzerConfig | string): Promise<SchemaDefinition> {\n // Support legacy string-only parameter\n const normalizedConfig: SchemaAnalyzerConfig = typeof config === \"string\" ? { schemaDir: config } : config;\n\n const mergedConfig = mergeConfig(normalizedConfig);\n const collections = new Map<string, CollectionSchema>();\n\n // Discover schema files\n const schemaFiles = discoverSchemaFiles(normalizedConfig);\n\n if (schemaFiles.length === 0) {\n const schemaDir = resolveSchemaDir(normalizedConfig);\n throw new SchemaParsingError(\n `No schema files found in ${schemaDir}. Make sure you have schema files in the directory.`,\n schemaDir\n );\n }\n\n // Process each schema file\n for (const filePath of schemaFiles) {\n try {\n let importPath = filePath;\n\n // Apply path transformation if provided (for monorepo setups)\n if (normalizedConfig.pathTransformer) {\n importPath = normalizedConfig.pathTransformer(filePath);\n } else if (mergedConfig.useCompiledFiles) {\n // Default transformation: convert /src/ to /dist/ for compiled files\n // This is a common pattern but can be overridden with pathTransformer\n const distPath = filePath.replace(/\\/src\\//, \"/dist/\");\n // Only use dist path if it actually exists (i.e., files are compiled)\n // Otherwise, fall back to source path for TypeScript files\n if (fs.existsSync(`${distPath}.js`) || fs.existsSync(`${distPath}.mjs`)) {\n importPath = distPath;\n } else {\n // Files aren't compiled, use source path\n importPath = filePath;\n }\n }\n\n // Import the module\n const module = await importSchemaModule(importPath, normalizedConfig);\n\n // Extract schema definitions\n const schemas = extractSchemaDefinitions(module, mergedConfig.schemaPatterns);\n\n // Select the appropriate schema\n const zodSchema = selectSchemaForCollection(schemas);\n\n if (!zodSchema) {\n console.warn(`No valid schema found in ${filePath}, skipping...`);\n continue;\n }\n\n // Get collection name - prefer metadata from defineCollection(), fall back to filename\n const collectionNameFromSchema = extractCollectionNameFromSchema(zodSchema);\n const collectionName = collectionNameFromSchema ?? getCollectionNameFromFile(filePath);\n\n // Convert to CollectionSchema\n const collectionSchema = convertZodSchemaToCollectionSchema(collectionName, zodSchema);\n\n // Add to collections map\n collections.set(collectionName, collectionSchema);\n } catch (error) {\n // If it's already a SchemaParsingError, re-throw it\n if (error instanceof SchemaParsingError) {\n throw error;\n }\n\n // Otherwise, wrap it in a SchemaParsingError\n throw new SchemaParsingError(\n `Error processing schema file: ${error instanceof Error ? error.message : String(error)}`,\n filePath,\n error as Error\n );\n }\n }\n\n return { collections };\n}\n\n/**\n * Parses schema files and returns SchemaDefinition\n * Alias for buildSchemaDefinition for better semantic clarity\n *\n * @param config - Schema analyzer configuration or path to schema directory\n * @returns Complete SchemaDefinition with all collections\n */\nexport async function parseSchemaFiles(config: SchemaAnalyzerConfig | string): Promise<SchemaDefinition> {\n return buildSchemaDefinition(config);\n}\n\n/**\n * Creates a SchemaAnalyzer instance with the given configuration\n * Provides an object-oriented interface for schema analysis\n */\nexport class SchemaAnalyzer {\n private config: Required<Omit<SchemaAnalyzerConfig, \"pathTransformer\">> & {\n pathTransformer?: (sourcePath: string) => string;\n };\n\n constructor(config: SchemaAnalyzerConfig) {\n this.config = mergeConfig(config);\n }\n\n /**\n * Discovers schema files in the configured directory\n */\n discoverSchemaFiles(): string[] {\n return discoverSchemaFiles(this.config);\n }\n\n /**\n * Parses all schema files and returns a SchemaDefinition\n */\n async parseSchemaFiles(): Promise<SchemaDefinition> {\n return buildSchemaDefinition(this.config);\n }\n\n /**\n * Converts a single Zod schema to a CollectionSchema\n */\n convertZodSchemaToCollectionSchema(name: string, schema: z.ZodObject<any>): CollectionSchema {\n return convertZodSchemaToCollectionSchema(name, schema);\n }\n}\n","/**\n * Collection ID generation utilities for PocketBase migrations\n */\n\nimport { randomBytes } from \"crypto\";\n\n/**\n * Generates a unique collection ID in PocketBase format\n * Format: pb_ followed by 15 alphanumeric lowercase characters\n *\n * @returns A unique collection ID string (e.g., \"pb_a1b2c3d4e5f6g7h\")\n */\nexport function generateCollectionId(): string {\n const chars = \"abcdefghijklmnopqrstuvwxyz0123456789\";\n const idLength = 15;\n\n // Generate cryptographically secure random bytes\n const bytes = randomBytes(idLength);\n\n // Convert bytes to alphanumeric characters\n let id = \"pb_\";\n for (let i = 0; i < idLength; i++) {\n const index = bytes[i] % chars.length;\n id += chars[index];\n }\n\n return id;\n}\n\n/**\n * Registry to track generated collection IDs and ensure uniqueness within a migration batch\n */\nexport class CollectionIdRegistry {\n private ids: Set<string>;\n\n constructor() {\n this.ids = new Set<string>();\n }\n\n /**\n * Generates a unique collection ID for a given collection name\n * Retries up to 10 times if collision occurs (extremely rare)\n * Special case: returns \"_pb_users_auth_\" for users collection\n *\n * @param collectionName - The name of the collection (optional)\n * @returns A unique collection ID\n * @throws Error if unable to generate unique ID after max attempts\n */\n generate(collectionName?: string): string {\n // Special case: users collection always uses the constant\n if (collectionName && collectionName.toLowerCase() === \"users\") {\n const usersId = \"_pb_users_auth_\";\n if (!this.has(usersId)) {\n this.register(usersId);\n }\n return usersId;\n }\n\n const maxAttempts = 10;\n\n for (let attempt = 0; attempt < maxAttempts; attempt++) {\n const id = generateCollectionId();\n\n if (!this.has(id)) {\n this.register(id);\n return id;\n }\n }\n\n throw new Error(\"Failed to generate unique collection ID after maximum attempts\");\n }\n\n /**\n * Checks if an ID has already been registered\n *\n * @param id - The collection ID to check\n * @returns True if the ID exists in the registry\n */\n has(id: string): boolean {\n return this.ids.has(id);\n }\n\n /**\n * Registers a collection ID in the registry\n *\n * @param id - The collection ID to register\n */\n register(id: string): void {\n this.ids.add(id);\n }\n}\n","/**\n * Diff Engine component\n * Compares current schema with previous snapshot and identifies changes\n *\n * This module provides a standalone, configurable diff engine that can be used\n * by consumer projects to compare schema definitions and detect changes.\n */\n\nimport type {\n APIRuleType,\n CollectionModification,\n CollectionSchema,\n FieldChange,\n FieldDefinition,\n FieldModification,\n PermissionChange,\n RuleUpdate,\n SchemaDefinition,\n SchemaDiff,\n SchemaSnapshot,\n} from \"./types\";\nimport { CollectionIdRegistry } from \"./utils/collection-id-generator.js\";\n\n/**\n * Configuration options for the diff engine\n */\nexport interface DiffEngineConfig {\n /**\n * Whether to warn on collection deletions\n * Defaults to true\n */\n warnOnDelete?: boolean;\n\n /**\n * Whether to require --force flag for destructive changes\n * Defaults to true\n */\n requireForceForDestructive?: boolean;\n\n /**\n * Severity threshold for requiring force flag\n * 'high' = only collection/field deletions and type changes\n * 'medium' = includes making fields required\n * 'low' = includes any constraint changes\n * Defaults to 'high'\n */\n severityThreshold?: \"high\" | \"medium\" | \"low\";\n\n /**\n * Custom system collections to exclude from diff\n * These collections will not be created or deleted\n */\n systemCollections?: string[];\n\n /**\n * Custom system fields to exclude from user collection diffs\n * These fields will not be included in fieldsToAdd for the users collection\n */\n usersSystemFields?: string[];\n}\n\n/**\n * Default configuration values\n */\nconst DEFAULT_CONFIG: Required<DiffEngineConfig> = {\n warnOnDelete: true,\n requireForceForDestructive: true,\n severityThreshold: \"high\",\n systemCollections: [\"_mfas\", \"_otps\", \"_externalAuths\", \"_authOrigins\", \"_superusers\"],\n usersSystemFields: [\"id\", \"password\", \"tokenKey\", \"email\", \"emailVisibility\", \"verified\", \"created\", \"updated\"],\n};\n\n/**\n * Merges user config with defaults\n */\nfunction mergeConfig(config?: DiffEngineConfig): Required<DiffEngineConfig> {\n return {\n ...DEFAULT_CONFIG,\n ...config,\n };\n}\n\n/**\n * Destructive change information\n */\nexport interface DestructiveChange {\n type: \"collection_delete\" | \"field_delete\" | \"type_change\" | \"required_change\" | \"constraint_change\";\n severity: \"high\" | \"medium\" | \"low\";\n collection: string;\n field?: string;\n description: string;\n oldValue?: any;\n newValue?: any;\n}\n\n/**\n * Change summary for status reporting\n */\nexport interface ChangeSummary {\n totalChanges: number;\n collectionsToCreate: number;\n collectionsToDelete: number;\n collectionsToModify: number;\n fieldsToAdd: number;\n fieldsToRemove: number;\n fieldsToModify: number;\n indexChanges: number;\n ruleChanges: number;\n permissionChanges: number;\n destructiveChanges: DestructiveChange[];\n nonDestructiveChanges: string[];\n}\n\n/**\n * Checks if a collection is a PocketBase system collection\n * System collections are internal to PocketBase and should not be created or deleted\n *\n * @param collectionName - Name of the collection to check\n * @param config - Optional configuration with custom system collections\n * @returns True if the collection is a system collection\n */\nexport function isSystemCollection(collectionName: string, config?: DiffEngineConfig): boolean {\n const mergedConfig = mergeConfig(config);\n return mergedConfig.systemCollections.includes(collectionName);\n}\n\n/**\n * Returns the list of system field names for the users collection\n * These fields are automatically provided by PocketBase for auth collections\n * and should not be included when generating migrations for users collection extensions\n *\n * @param config - Optional configuration with custom system fields\n * @returns Set of system field names\n */\nexport function getUsersSystemFields(config?: DiffEngineConfig): Set<string> {\n const mergedConfig = mergeConfig(config);\n return new Set(mergedConfig.usersSystemFields);\n}\n\n/**\n * Filters system collections from a schema definition\n * Returns a new SchemaDefinition with only custom (non-system) collections\n *\n * @param schema - Schema definition to filter\n * @param config - Optional configuration\n * @returns Filtered SchemaDefinition without system collections\n */\nexport function filterSystemCollections(schema: SchemaDefinition, config?: DiffEngineConfig): SchemaDefinition {\n const filteredCollections = new Map<string, CollectionSchema>();\n\n for (const [collectionName, collectionSchema] of schema.collections) {\n if (!isSystemCollection(collectionName, config)) {\n filteredCollections.set(collectionName, collectionSchema);\n }\n }\n\n return {\n collections: filteredCollections,\n };\n}\n\n/**\n * Identifies new collections in schema that don't exist in snapshot\n *\n * @param currentSchema - Current schema definition\n * @param previousSnapshot - Previous schema snapshot\n * @returns Array of new collections\n */\nexport function findNewCollections(\n currentSchema: SchemaDefinition,\n previousSnapshot: SchemaSnapshot | null\n): CollectionSchema[] {\n const newCollections: CollectionSchema[] = [];\n\n // If no previous snapshot, all collections are new\n if (!previousSnapshot) {\n return Array.from(currentSchema.collections.values());\n }\n\n // Find collections in current schema that don't exist in snapshot\n for (const [collectionName, collectionSchema] of currentSchema.collections) {\n if (!previousSnapshot.collections.has(collectionName)) {\n newCollections.push(collectionSchema);\n }\n }\n\n return newCollections;\n}\n\n/**\n * Identifies collections removed from schema (exist in snapshot but not in current schema)\n *\n * @param currentSchema - Current schema definition\n * @param previousSnapshot - Previous schema snapshot\n * @returns Array of removed collections\n */\nexport function findRemovedCollections(\n currentSchema: SchemaDefinition,\n previousSnapshot: SchemaSnapshot | null\n): CollectionSchema[] {\n const removedCollections: CollectionSchema[] = [];\n\n // If no previous snapshot, nothing can be removed\n if (!previousSnapshot) {\n return removedCollections;\n }\n\n // Find collections in snapshot that don't exist in current schema\n for (const [collectionName, collectionSchema] of previousSnapshot.collections) {\n if (!currentSchema.collections.has(collectionName)) {\n removedCollections.push(collectionSchema);\n }\n }\n\n return removedCollections;\n}\n\n/**\n * Matches collections by name between current schema and snapshot\n * Returns pairs of [current, previous] for collections that exist in both\n *\n * @param currentSchema - Current schema definition\n * @param previousSnapshot - Previous schema snapshot\n * @returns Array of matched collection pairs\n */\nexport function matchCollectionsByName(\n currentSchema: SchemaDefinition,\n previousSnapshot: SchemaSnapshot | null\n): Array<[CollectionSchema, CollectionSchema]> {\n const matches: Array<[CollectionSchema, CollectionSchema]> = [];\n\n // If no previous snapshot, no matches possible\n if (!previousSnapshot) {\n return matches;\n }\n\n // Create a case-insensitive lookup map for previous collections\n const previousCollectionsLower = new Map<string, [string, CollectionSchema]>();\n for (const [name, collection] of previousSnapshot.collections) {\n previousCollectionsLower.set(name.toLowerCase(), [name, collection]);\n }\n\n // Find collections that exist in both current and previous (case-insensitive)\n for (const [collectionName, currentCollection] of currentSchema.collections) {\n const previousEntry = previousCollectionsLower.get(collectionName.toLowerCase());\n\n if (previousEntry) {\n const [, previousCollection] = previousEntry;\n matches.push([currentCollection, previousCollection]);\n }\n }\n\n return matches;\n}\n\n/**\n * Identifies new fields in current collection that don't exist in previous\n *\n * @param currentFields - Current collection fields\n * @param previousFields - Previous collection fields\n * @returns Array of new fields\n */\nexport function findNewFields(currentFields: FieldDefinition[], previousFields: FieldDefinition[]): FieldDefinition[] {\n const newFields: FieldDefinition[] = [];\n const previousFieldNames = new Set(previousFields.map((f) => f.name));\n\n for (const currentField of currentFields) {\n if (!previousFieldNames.has(currentField.name)) {\n newFields.push(currentField);\n }\n }\n\n return newFields;\n}\n\n/**\n * Identifies fields removed from current collection (exist in previous but not in current)\n *\n * @param currentFields - Current collection fields\n * @param previousFields - Previous collection fields\n * @returns Array of removed fields\n */\nexport function findRemovedFields(\n currentFields: FieldDefinition[],\n previousFields: FieldDefinition[]\n): FieldDefinition[] {\n const removedFields: FieldDefinition[] = [];\n const currentFieldNames = new Set(currentFields.map((f) => f.name));\n\n for (const previousField of previousFields) {\n if (!currentFieldNames.has(previousField.name)) {\n removedFields.push(previousField);\n }\n }\n\n return removedFields;\n}\n\n/**\n * Matches fields by name between current and previous collections\n * Returns pairs of [current, previous] for fields that exist in both\n *\n * @param currentFields - Current collection fields\n * @param previousFields - Previous collection fields\n * @returns Array of matched field pairs\n */\nexport function matchFieldsByName(\n currentFields: FieldDefinition[],\n previousFields: FieldDefinition[]\n): Array<[FieldDefinition, FieldDefinition]> {\n const matches: Array<[FieldDefinition, FieldDefinition]> = [];\n\n // Create a map of previous fields by name for efficient lookup\n const previousFieldMap = new Map<string, FieldDefinition>();\n for (const previousField of previousFields) {\n previousFieldMap.set(previousField.name, previousField);\n }\n\n // Find matching fields\n for (const currentField of currentFields) {\n const previousField = previousFieldMap.get(currentField.name);\n\n if (previousField) {\n matches.push([currentField, previousField]);\n }\n }\n\n return matches;\n}\n\n/**\n * Compares two values for equality, handling deep object comparison\n *\n * @param a - First value\n * @param b - Second value\n * @returns True if values are equal\n */\nfunction areValuesEqual(a: any, b: any): boolean {\n // Handle null/undefined\n if (a === b) return true;\n if (a == null || b == null) return false;\n\n // Handle arrays\n if (Array.isArray(a) && Array.isArray(b)) {\n if (a.length !== b.length) return false;\n return a.every((val, idx) => areValuesEqual(val, b[idx]));\n }\n\n // Handle objects\n if (typeof a === \"object\" && typeof b === \"object\") {\n const keysA = Object.keys(a);\n const keysB = Object.keys(b);\n\n if (keysA.length !== keysB.length) return false;\n\n return keysA.every((key) => areValuesEqual(a[key], b[key]));\n }\n\n // Primitive comparison\n return a === b;\n}\n\n/**\n * Compares field types between current and previous\n *\n * @param currentField - Current field definition\n * @param previousField - Previous field definition\n * @returns FieldChange if types differ, null otherwise\n */\nexport function compareFieldTypes(currentField: FieldDefinition, previousField: FieldDefinition): FieldChange | null {\n if (currentField.type !== previousField.type) {\n return {\n property: \"type\",\n oldValue: previousField.type,\n newValue: currentField.type,\n };\n }\n\n return null;\n}\n\n/**\n * Compares field constraints (required, unique) between current and previous\n *\n * @param currentField - Current field definition\n * @param previousField - Previous field definition\n * @returns Array of FieldChange for constraint differences\n */\nexport function compareFieldConstraints(currentField: FieldDefinition, previousField: FieldDefinition): FieldChange[] {\n const changes: FieldChange[] = [];\n\n // Compare required constraint\n if (currentField.required !== previousField.required) {\n changes.push({\n property: \"required\",\n oldValue: previousField.required,\n newValue: currentField.required,\n });\n }\n\n // Compare unique constraint\n if (currentField.unique !== previousField.unique) {\n changes.push({\n property: \"unique\",\n oldValue: previousField.unique,\n newValue: currentField.unique,\n });\n }\n\n return changes;\n}\n\n/**\n * Normalizes a field option value to account for PocketBase defaults\n * Returns the normalized value, treating default values as equivalent to undefined\n *\n * @param key - Option key name\n * @param value - Option value\n * @param fieldType - Field type\n * @returns Normalized value (undefined if it's a default value)\n */\nfunction normalizeOptionValue(key: string, value: any, fieldType: string): any {\n // maxSelect: 1 is the default for select and file fields\n if (key === \"maxSelect\" && value === 1 && (fieldType === \"select\" || fieldType === \"file\")) {\n return undefined; // Treat as undefined to match missing default\n }\n\n // maxSize: 0 is default for file fields\n if (key === \"maxSize\" && value === 0 && fieldType === \"file\") {\n return undefined;\n }\n\n // Empty arrays are defaults for file fields\n if (fieldType === \"file\") {\n if (key === \"mimeTypes\" && Array.isArray(value) && value.length === 0) {\n return undefined;\n }\n if (key === \"thumbs\" && Array.isArray(value) && value.length === 0) {\n return undefined;\n }\n if (key === \"protected\" && value === false) {\n return undefined;\n }\n }\n\n // Autodate defaults\n if (fieldType === \"autodate\") {\n if (key === \"onCreate\" && value === true) {\n return undefined;\n }\n if (key === \"onUpdate\" && value === false) {\n return undefined;\n }\n }\n\n return value;\n}\n\n/**\n * Compares field options (min, max, pattern, etc.) between current and previous\n *\n * @param currentField - Current field definition\n * @param previousField - Previous field definition\n * @returns Array of FieldChange for option differences\n */\nexport function compareFieldOptions(currentField: FieldDefinition, previousField: FieldDefinition): FieldChange[] {\n const changes: FieldChange[] = [];\n\n const currentOptions = currentField.options || {};\n const previousOptions = previousField.options || {};\n\n // Get all unique option keys\n const allKeys = new Set([...Object.keys(currentOptions), ...Object.keys(previousOptions)]);\n\n // Compare each option\n // Use currentField.type for normalization since types should match at this point\n // (type changes are handled separately in compareFieldTypes)\n const fieldType = currentField.type;\n\n for (const key of allKeys) {\n const currentValue = currentOptions[key];\n const previousValue = previousOptions[key];\n\n // Normalize values to account for default values\n // This ensures that maxSelect: 1 (default) is treated the same as undefined (missing default)\n const normalizedCurrent = normalizeOptionValue(key, currentValue, fieldType);\n const normalizedPrevious = normalizeOptionValue(key, previousValue, fieldType);\n\n // Handle undefined values - if both are undefined (or normalized to undefined), that's not a change\n if (normalizedCurrent === undefined && normalizedPrevious === undefined) {\n continue;\n }\n\n if (!areValuesEqual(normalizedCurrent, normalizedPrevious)) {\n changes.push({\n property: `options.${key}`,\n oldValue: previousValue,\n newValue: currentValue,\n });\n }\n }\n\n return changes;\n}\n\n/**\n * Compares relation configurations between current and previous\n *\n * @param currentField - Current field definition\n * @param previousField - Previous field definition\n * @returns Array of FieldChange for relation differences\n */\nexport function compareRelationConfigurations(\n currentField: FieldDefinition,\n previousField: FieldDefinition,\n collectionIdToName?: Map<string, string>\n): FieldChange[] {\n const changes: FieldChange[] = [];\n\n const currentRelation = currentField.relation;\n const previousRelation = previousField.relation;\n\n // If one has relation and other doesn't, that's a type change (handled elsewhere)\n if (!currentRelation && !previousRelation) {\n return changes;\n }\n\n if (!currentRelation || !previousRelation) {\n // This shouldn't happen if types match, but handle gracefully\n return changes;\n }\n\n // Compare relation properties\n // Note: collectionId should already be resolved to collection name during parsing\n // This normalization is just a safety net for edge cases\n const normalizeCollection = (collection: string): string => {\n if (!collection) return collection;\n\n // Resolve ID to name if possible\n if (collectionIdToName && collectionIdToName.has(collection)) {\n return collectionIdToName.get(collection)!;\n }\n\n // Handle expressions that might not have been parsed correctly\n const nameMatch = collection.match(/app\\.findCollectionByNameOrId\\s*\\(\\s*[\"']([^\"']+)[\"']\\s*\\)/);\n if (nameMatch) {\n return nameMatch[1];\n }\n return collection;\n };\n\n const normalizedCurrent = normalizeCollection(currentRelation.collection);\n // We resolve the ID from the previous relation (snapshot) to its name if available\n const normalizedPrevious = normalizeCollection(previousRelation.collection);\n\n // Only report a change if the normalized values differ\n // Use case-insensitive comparison for collection names\n if (normalizedCurrent.toLowerCase() !== normalizedPrevious.toLowerCase()) {\n changes.push({\n property: \"relation.collection\",\n oldValue: previousRelation.collection,\n newValue: currentRelation.collection,\n });\n }\n\n if (currentRelation.cascadeDelete !== previousRelation.cascadeDelete) {\n changes.push({\n property: \"relation.cascadeDelete\",\n oldValue: previousRelation.cascadeDelete,\n newValue: currentRelation.cascadeDelete,\n });\n }\n\n // Normalize maxSelect: 1 to undefined/null as it's often the default or treated as such\n const normalizeMax = (val: number | null | undefined) => (val === 1 ? null : val);\n const currentMax = normalizeMax(currentRelation.maxSelect);\n const previousMax = normalizeMax(previousRelation.maxSelect);\n\n // Use loose equality to handle null vs undefined\n if (currentMax != previousMax) {\n changes.push({\n property: \"relation.maxSelect\",\n oldValue: previousRelation.maxSelect,\n newValue: currentRelation.maxSelect,\n });\n }\n\n // Normalize minSelect: 0 to undefined/null\n const normalizeMin = (val: number | null | undefined) => (val === 0 ? null : val);\n const currentMin = normalizeMin(currentRelation.minSelect);\n const previousMin = normalizeMin(previousRelation.minSelect);\n\n if (currentMin != previousMin) {\n changes.push({\n property: \"relation.minSelect\",\n oldValue: previousRelation.minSelect,\n newValue: currentRelation.minSelect,\n });\n }\n\n return changes;\n}\n\n/**\n * Detects all changes between two field definitions\n * Combines type, constraint, option, and relation changes\n *\n * @param currentField - Current field definition\n * @param previousField - Previous field definition\n * @returns Array of all detected changes\n */\nexport function detectFieldChanges(\n currentField: FieldDefinition,\n previousField: FieldDefinition,\n collectionIdToName?: Map<string, string>\n): FieldChange[] {\n const changes: FieldChange[] = [];\n\n // Compare types\n const typeChange = compareFieldTypes(currentField, previousField);\n if (typeChange) {\n changes.push(typeChange);\n }\n\n // Compare constraints\n changes.push(...compareFieldConstraints(currentField, previousField));\n\n // Compare options\n changes.push(...compareFieldOptions(currentField, previousField));\n\n // Compare relation configurations (if applicable)\n if (currentField.type === \"relation\" && previousField.type === \"relation\") {\n changes.push(...compareRelationConfigurations(currentField, previousField, collectionIdToName));\n }\n\n return changes;\n}\n\n/**\n * Compares indexes between current and previous collections\n *\n * @param currentIndexes - Current collection indexes\n * @param previousIndexes - Previous collection indexes\n * @returns Object with indexes to add and remove\n */\nfunction compareIndexes(\n currentIndexes: string[] = [],\n previousIndexes: string[] = []\n): { indexesToAdd: string[]; indexesToRemove: string[] } {\n const currentSet = new Set(currentIndexes);\n const previousSet = new Set(previousIndexes);\n\n const indexesToAdd = currentIndexes.filter((idx) => !previousSet.has(idx));\n const indexesToRemove = previousIndexes.filter((idx) => !currentSet.has(idx));\n\n return { indexesToAdd, indexesToRemove };\n}\n\n/**\n * Compares API rules between current and previous collections\n *\n * @param currentRules - Current collection rules\n * @param previousRules - Previous collection rules\n * @returns Array of rule updates\n */\nfunction compareRules(\n currentRules: CollectionSchema[\"rules\"],\n previousRules: CollectionSchema[\"rules\"],\n currentPermissions?: CollectionSchema[\"permissions\"],\n previousPermissions?: CollectionSchema[\"permissions\"]\n): RuleUpdate[] {\n const updates: RuleUpdate[] = [];\n\n const ruleTypes: Array<keyof NonNullable<CollectionSchema[\"rules\"]>> = [\n \"listRule\",\n \"viewRule\",\n \"createRule\",\n \"updateRule\",\n \"deleteRule\",\n \"manageRule\",\n ];\n\n for (const ruleType of ruleTypes) {\n // Use rules if available, otherwise fall back to permissions (they're the same thing)\n const currentValue = currentRules?.[ruleType] ?? currentPermissions?.[ruleType] ?? null;\n const previousValue = previousRules?.[ruleType] ?? previousPermissions?.[ruleType] ?? null;\n\n if (currentValue !== previousValue) {\n updates.push({\n ruleType: ruleType as RuleUpdate[\"ruleType\"],\n oldValue: previousValue,\n newValue: currentValue,\n });\n }\n }\n\n return updates;\n}\n\n/**\n * Compares permissions between current and previous collections\n * Detects changes in permission rules defined in schema\n *\n * @param currentPermissions - Current collection permissions\n * @param previousPermissions - Previous collection permissions\n * @returns Array of permission changes\n */\nexport function comparePermissions(\n currentPermissions: CollectionSchema[\"permissions\"],\n previousPermissions: CollectionSchema[\"permissions\"]\n): PermissionChange[] {\n const changes: PermissionChange[] = [];\n\n const ruleTypes: APIRuleType[] = [\"listRule\", \"viewRule\", \"createRule\", \"updateRule\", \"deleteRule\", \"manageRule\"];\n\n for (const ruleType of ruleTypes) {\n const currentValue = currentPermissions?.[ruleType] ?? null;\n const previousValue = previousPermissions?.[ruleType] ?? null;\n\n // Compare permission values\n if (currentValue !== previousValue) {\n changes.push({\n ruleType,\n oldValue: previousValue,\n newValue: currentValue,\n });\n }\n }\n\n return changes;\n}\n\n/**\n * Compares fields between current and previous collections\n * Identifies new, removed, and modified fields\n * For the users collection, filters out system fields from fieldsToAdd\n *\n * @param currentCollection - Current collection schema\n * @param previousCollection - Previous collection schema\n * @param config - Optional configuration\n * @returns Object with field changes\n */\nfunction compareCollectionFields(\n currentCollection: CollectionSchema,\n previousCollection: CollectionSchema,\n config?: DiffEngineConfig,\n collectionIdToName?: Map<string, string>\n): {\n fieldsToAdd: FieldDefinition[];\n fieldsToRemove: FieldDefinition[];\n fieldsToModify: FieldModification[];\n} {\n let fieldsToAdd = findNewFields(currentCollection.fields, previousCollection.fields);\n const fieldsToRemove = findRemovedFields(currentCollection.fields, previousCollection.fields);\n const fieldsToModify: FieldModification[] = [];\n\n // For users collection, filter out system fields from fieldsToAdd\n // System fields are automatically provided by PocketBase and should not be in migrations\n if (currentCollection.name === \"users\") {\n const systemFields = getUsersSystemFields(config);\n fieldsToAdd = fieldsToAdd.filter((field) => !systemFields.has(field.name));\n }\n\n // Check for modified fields\n const matchedFields = matchFieldsByName(currentCollection.fields, previousCollection.fields);\n\n for (const [currentField, previousField] of matchedFields) {\n const changes = detectFieldChanges(currentField, previousField, collectionIdToName);\n\n if (changes.length > 0) {\n fieldsToModify.push({\n fieldName: currentField.name,\n currentDefinition: previousField,\n newDefinition: currentField,\n changes,\n });\n }\n }\n\n return { fieldsToAdd, fieldsToRemove, fieldsToModify };\n}\n\n/**\n * Builds a CollectionModification for a matched collection pair\n *\n * @param currentCollection - Current collection schema\n * @param previousCollection - Previous collection schema\n * @param config - Optional configuration\n * @returns CollectionModification object\n */\nfunction buildCollectionModification(\n currentCollection: CollectionSchema,\n previousCollection: CollectionSchema,\n config?: DiffEngineConfig,\n collectionIdToName?: Map<string, string>\n): CollectionModification {\n // Compare fields\n const { fieldsToAdd, fieldsToRemove, fieldsToModify } = compareCollectionFields(\n currentCollection,\n previousCollection,\n config,\n collectionIdToName\n );\n\n // Compare indexes\n const { indexesToAdd, indexesToRemove } = compareIndexes(currentCollection.indexes, previousCollection.indexes);\n\n // Compare rules (also check permissions as fallback since they're the same thing)\n const rulesToUpdate = compareRules(\n currentCollection.rules,\n previousCollection.rules,\n currentCollection.permissions,\n previousCollection.permissions\n );\n\n // Compare permissions\n const permissionsToUpdate = comparePermissions(currentCollection.permissions, previousCollection.permissions);\n\n return {\n collection: currentCollection.name,\n fieldsToAdd,\n fieldsToRemove,\n fieldsToModify,\n indexesToAdd,\n indexesToRemove,\n rulesToUpdate,\n permissionsToUpdate,\n };\n}\n\n/**\n * Checks if a collection modification has any actual changes\n *\n * @param modification - Collection modification to check\n * @returns True if there are any changes\n */\nfunction hasChanges(modification: CollectionModification): boolean {\n return (\n modification.fieldsToAdd.length > 0 ||\n modification.fieldsToRemove.length > 0 ||\n modification.fieldsToModify.length > 0 ||\n modification.indexesToAdd.length > 0 ||\n modification.indexesToRemove.length > 0 ||\n modification.rulesToUpdate.length > 0 ||\n modification.permissionsToUpdate.length > 0\n );\n}\n\n/**\n * Aggregates all detected changes into a SchemaDiff\n * Main entry point for diff comparison\n *\n * @param currentSchema - Current schema definition\n * @param previousSnapshot - Previous schema snapshot\n * @param config - Optional configuration\n * @returns Complete SchemaDiff with all changes\n */\nexport function aggregateChanges(\n currentSchema: SchemaDefinition,\n previousSnapshot: SchemaSnapshot | null,\n config?: DiffEngineConfig\n): SchemaDiff {\n // Build lookup map for ID -> Name from previous snapshot\n // This helps resolve relations where snapshot uses ID but schema uses Name\n const collectionIdToName = new Map<string, string>();\n if (previousSnapshot) {\n for (const [name, collection] of previousSnapshot.collections) {\n if (collection.id) {\n collectionIdToName.set(collection.id, name);\n }\n }\n }\n\n // Find new and removed collections\n const collectionsToCreate = findNewCollections(currentSchema, previousSnapshot);\n const collectionsToDelete = findRemovedCollections(currentSchema, previousSnapshot);\n\n // Filter out system collections from create and delete operations\n const filteredCollectionsToCreate = collectionsToCreate.filter(\n (collection) => !isSystemCollection(collection.name, config)\n );\n const filteredCollectionsToDelete = collectionsToDelete.filter(\n (collection) => !isSystemCollection(collection.name, config)\n );\n\n // Generate and assign collection IDs for new collections\n const registry = new CollectionIdRegistry();\n const collectionsWithIds = filteredCollectionsToCreate.map((collection) => {\n // If the collection already has an ID, register it and use it\n if (collection.id) {\n registry.register(collection.id);\n return collection;\n }\n\n // Generate a new ID for the collection (pass name for special handling)\n const id = registry.generate(collection.name);\n return {\n ...collection,\n id,\n };\n });\n\n // Find modified collections\n const collectionsToModify: CollectionModification[] = [];\n const matchedCollections = matchCollectionsByName(currentSchema, previousSnapshot);\n\n for (const [currentCollection, previousCollection] of matchedCollections) {\n const modification = buildCollectionModification(currentCollection, previousCollection, config, collectionIdToName);\n\n // Only include if there are actual changes\n // Note: We allow modifications to the users collection (non-system)\n if (hasChanges(modification)) {\n collectionsToModify.push(modification);\n }\n }\n\n return {\n collectionsToCreate: collectionsWithIds,\n collectionsToDelete: filteredCollectionsToDelete,\n collectionsToModify,\n };\n}\n\n/**\n * Detects destructive changes in a schema diff\n * Returns detailed information about each destructive change\n *\n * @param diff - Schema diff to analyze\n * @param config - Optional configuration for severity thresholds\n * @returns Array of destructive changes with severity information\n */\nexport function detectDestructiveChanges(diff: SchemaDiff, config?: DiffEngineConfig): DestructiveChange[] {\n const destructiveChanges: DestructiveChange[] = [];\n const mergedConfig = mergeConfig(config);\n\n // Collection deletions are always high severity\n for (const collection of diff.collectionsToDelete) {\n destructiveChanges.push({\n type: \"collection_delete\",\n severity: \"high\",\n collection: collection.name,\n description: `Delete collection: ${collection.name}`,\n });\n }\n\n // Analyze modifications\n for (const modification of diff.collectionsToModify) {\n const collectionName = modification.collection;\n\n // Field deletions are high severity\n for (const field of modification.fieldsToRemove) {\n destructiveChanges.push({\n type: \"field_delete\",\n severity: \"high\",\n collection: collectionName,\n field: field.name,\n description: `Delete field: ${collectionName}.${field.name}`,\n });\n }\n\n // Field modifications can be various severities\n for (const fieldMod of modification.fieldsToModify) {\n const typeChange = fieldMod.changes.find((c) => c.property === \"type\");\n const requiredChange = fieldMod.changes.find((c) => c.property === \"required\" && c.newValue === true);\n\n if (typeChange) {\n destructiveChanges.push({\n type: \"type_change\",\n severity: \"high\",\n collection: collectionName,\n field: fieldMod.fieldName,\n description: `Change field type: ${collectionName}.${fieldMod.fieldName} (${typeChange.oldValue} → ${typeChange.newValue})`,\n oldValue: typeChange.oldValue,\n newValue: typeChange.newValue,\n });\n }\n\n if (requiredChange && mergedConfig.severityThreshold !== \"high\") {\n destructiveChanges.push({\n type: \"required_change\",\n severity: \"medium\",\n collection: collectionName,\n field: fieldMod.fieldName,\n description: `Make field required: ${collectionName}.${fieldMod.fieldName}`,\n oldValue: false,\n newValue: true,\n });\n }\n\n // Other constraint changes at low severity\n if (mergedConfig.severityThreshold === \"low\") {\n const otherChanges = fieldMod.changes.filter((c) => c.property !== \"type\" && c.property !== \"required\");\n for (const change of otherChanges) {\n destructiveChanges.push({\n type: \"constraint_change\",\n severity: \"low\",\n collection: collectionName,\n field: fieldMod.fieldName,\n description: `Change constraint: ${collectionName}.${fieldMod.fieldName}.${change.property}`,\n oldValue: change.oldValue,\n newValue: change.newValue,\n });\n }\n }\n }\n }\n\n return destructiveChanges;\n}\n\n/**\n * Categorizes changes by severity\n * Returns object with destructive and non-destructive changes\n *\n * @param diff - Schema diff to categorize\n * @param config - Optional configuration\n * @returns Object with categorized changes\n */\nexport function categorizeChangesBySeverity(\n diff: SchemaDiff,\n _config?: DiffEngineConfig\n): {\n destructive: string[];\n nonDestructive: string[];\n} {\n const destructive: string[] = [];\n const nonDestructive: string[] = [];\n\n // Collection deletions are destructive\n for (const collection of diff.collectionsToDelete) {\n destructive.push(`Delete collection: ${collection.name}`);\n }\n\n // Collection creations are non-destructive\n for (const collection of diff.collectionsToCreate) {\n nonDestructive.push(`Create collection: ${collection.name}`);\n }\n\n // Analyze modifications\n for (const modification of diff.collectionsToModify) {\n const collectionName = modification.collection;\n\n // Field deletions are destructive\n for (const field of modification.fieldsToRemove) {\n destructive.push(`Delete field: ${collectionName}.${field.name}`);\n }\n\n // Field additions are non-destructive\n for (const field of modification.fieldsToAdd) {\n nonDestructive.push(`Add field: ${collectionName}.${field.name}`);\n }\n\n // Field modifications can be destructive or non-destructive\n for (const fieldMod of modification.fieldsToModify) {\n const hasTypeChange = fieldMod.changes.some((c) => c.property === \"type\");\n const hasRequiredChange = fieldMod.changes.some((c) => c.property === \"required\" && c.newValue === true);\n\n if (hasTypeChange) {\n destructive.push(\n `Change field type: ${collectionName}.${fieldMod.fieldName} (${fieldMod.changes.find((c) => c.property === \"type\")?.oldValue} → ${fieldMod.changes.find((c) => c.property === \"type\")?.newValue})`\n );\n } else if (hasRequiredChange) {\n destructive.push(`Make field required: ${collectionName}.${fieldMod.fieldName}`);\n } else {\n nonDestructive.push(`Modify field: ${collectionName}.${fieldMod.fieldName}`);\n }\n }\n\n // Index changes are generally non-destructive\n for (const _index of modification.indexesToAdd) {\n nonDestructive.push(`Add index: ${collectionName}`);\n }\n\n for (const _index of modification.indexesToRemove) {\n nonDestructive.push(`Remove index: ${collectionName}`);\n }\n\n // Rule changes are non-destructive\n for (const rule of modification.rulesToUpdate) {\n nonDestructive.push(`Update rule: ${collectionName}.${rule.ruleType}`);\n }\n }\n\n return { destructive, nonDestructive };\n}\n\n/**\n * Generates a summary of all changes in a diff\n * Useful for status reporting and user feedback\n *\n * @param diff - Schema diff to summarize\n * @param config - Optional configuration\n * @returns Change summary with counts and details\n */\nexport function generateChangeSummary(diff: SchemaDiff, config?: DiffEngineConfig): ChangeSummary {\n const destructiveChanges = detectDestructiveChanges(diff, config);\n const { nonDestructive } = categorizeChangesBySeverity(diff, config);\n\n let fieldsToAdd = 0;\n let fieldsToRemove = 0;\n let fieldsToModify = 0;\n let indexChanges = 0;\n let ruleChanges = 0;\n let permissionChanges = 0;\n\n for (const modification of diff.collectionsToModify) {\n fieldsToAdd += modification.fieldsToAdd.length;\n fieldsToRemove += modification.fieldsToRemove.length;\n fieldsToModify += modification.fieldsToModify.length;\n indexChanges += modification.indexesToAdd.length + modification.indexesToRemove.length;\n ruleChanges += modification.rulesToUpdate.length;\n permissionChanges += modification.permissionsToUpdate.length;\n }\n\n return {\n totalChanges: diff.collectionsToCreate.length + diff.collectionsToDelete.length + diff.collectionsToModify.length,\n collectionsToCreate: diff.collectionsToCreate.length,\n collectionsToDelete: diff.collectionsToDelete.length,\n collectionsToModify: diff.collectionsToModify.length,\n fieldsToAdd,\n fieldsToRemove,\n fieldsToModify,\n indexChanges,\n ruleChanges,\n permissionChanges,\n destructiveChanges,\n nonDestructiveChanges: nonDestructive,\n };\n}\n\n/**\n * Checks if a diff requires the --force flag based on configuration\n *\n * @param diff - Schema diff to check\n * @param config - Configuration with severity threshold\n * @returns True if force flag is required\n */\nexport function requiresForceFlag(diff: SchemaDiff, config?: DiffEngineConfig): boolean {\n const mergedConfig = mergeConfig(config);\n\n if (!mergedConfig.requireForceForDestructive) {\n return false;\n }\n\n const destructiveChanges = detectDestructiveChanges(diff, config);\n\n // Filter by severity threshold\n const relevantChanges = destructiveChanges.filter((change) => {\n switch (mergedConfig.severityThreshold) {\n case \"high\":\n return change.severity === \"high\";\n case \"medium\":\n return change.severity === \"high\" || change.severity === \"medium\";\n case \"low\":\n return true;\n default:\n return change.severity === \"high\";\n }\n });\n\n return relevantChanges.length > 0;\n}\n\n/**\n * Main comparison function\n * Compares current schema with previous snapshot and returns complete diff\n *\n * @param currentSchema - Current schema definition\n * @param previousSnapshot - Previous schema snapshot (null for first run)\n * @param config - Optional configuration\n * @returns Complete SchemaDiff with all detected changes\n */\nexport function compare(\n currentSchema: SchemaDefinition,\n previousSnapshot: SchemaSnapshot | null,\n config?: DiffEngineConfig\n): SchemaDiff {\n return aggregateChanges(currentSchema, previousSnapshot, config);\n}\n\n/**\n * DiffEngine class for object-oriented usage\n * Provides a stateful interface for schema comparison\n */\nexport class DiffEngine {\n private config: Required<DiffEngineConfig>;\n\n constructor(config?: DiffEngineConfig) {\n this.config = mergeConfig(config);\n }\n\n /**\n * Compares current schema with previous snapshot\n */\n compare(currentSchema: SchemaDefinition, previousSnapshot: SchemaSnapshot | null): SchemaDiff {\n return compare(currentSchema, previousSnapshot, this.config);\n }\n\n /**\n * Detects destructive changes in a diff\n */\n detectDestructiveChanges(diff: SchemaDiff): DestructiveChange[] {\n return detectDestructiveChanges(diff, this.config);\n }\n\n /**\n * Categorizes changes by severity\n */\n categorizeChangesBySeverity(diff: SchemaDiff): { destructive: string[]; nonDestructive: string[] } {\n return categorizeChangesBySeverity(diff, this.config);\n }\n\n /**\n * Generates a summary of changes\n */\n generateChangeSummary(diff: SchemaDiff): ChangeSummary {\n return generateChangeSummary(diff, this.config);\n }\n\n /**\n * Checks if force flag is required\n */\n requiresForceFlag(diff: SchemaDiff): boolean {\n return requiresForceFlag(diff, this.config);\n }\n}\n","/**\n * Migration Generator component\n * Creates PocketBase migration files based on detected differences\n *\n * This module provides a standalone, configurable migration generator that can be used\n * by consumer projects to generate PocketBase-compatible migration files.\n */\n\nimport * as fs from \"fs\";\nimport * as path from \"path\";\nimport { FileSystemError, MigrationGenerationError } from \"./errors\";\nimport type { CollectionOperation, CollectionSchema, FieldDefinition, FieldModification, SchemaDiff } from \"./types\";\n\n/**\n * Configuration options for the migration generator\n */\nexport interface MigrationGeneratorConfig {\n /**\n * Directory to write migration files\n */\n migrationDir: string;\n\n /**\n * Workspace root for resolving relative paths\n * Defaults to process.cwd()\n */\n workspaceRoot?: string;\n\n /**\n * Custom timestamp generator function\n * Defaults to Unix timestamp in seconds\n */\n timestampGenerator?: () => string;\n\n /**\n * Custom migration file template\n * Use {{UP_CODE}} and {{DOWN_CODE}} placeholders\n */\n template?: string;\n\n /**\n * Whether to include type reference comment\n * Defaults to true\n */\n includeTypeReference?: boolean;\n\n /**\n * Path to types.d.ts file for reference comment\n * Defaults to '../pb_data/types.d.ts'\n */\n typesPath?: string;\n}\n\n/**\n * Default migration template\n */\nconst DEFAULT_TEMPLATE = `/// <reference path=\"{{TYPES_PATH}}\" />\nmigrate((app) => {\n{{UP_CODE}}\n}, (app) => {\n{{DOWN_CODE}}\n});\n`;\n\n/**\n * Default configuration values\n */\nconst DEFAULT_CONFIG: Omit<Required<MigrationGeneratorConfig>, \"migrationDir\"> = {\n workspaceRoot: process.cwd(),\n timestampGenerator: () => Math.floor(Date.now() / 1000).toString(),\n template: DEFAULT_TEMPLATE,\n includeTypeReference: true,\n typesPath: \"../pb_data/types.d.ts\",\n};\n\n/**\n * Merges user config with defaults\n */\nfunction mergeConfig(config: MigrationGeneratorConfig): Required<MigrationGeneratorConfig> {\n return {\n ...DEFAULT_CONFIG,\n ...config,\n };\n}\n\n/**\n * Resolves the migration directory path\n */\nfunction resolveMigrationDir(config: MigrationGeneratorConfig): string {\n const workspaceRoot = config.workspaceRoot || process.cwd();\n\n if (path.isAbsolute(config.migrationDir)) {\n return config.migrationDir;\n }\n\n return path.join(workspaceRoot, config.migrationDir);\n}\n\n/**\n * Generates a timestamp for migration filename\n * Format: Unix timestamp in seconds (e.g., 1687801090)\n *\n * @param config - Optional configuration with custom timestamp generator\n * @returns Timestamp string\n */\nexport function generateTimestamp(config?: MigrationGeneratorConfig): string {\n if (config?.timestampGenerator) {\n return config.timestampGenerator();\n }\n return Math.floor(Date.now() / 1000).toString();\n}\n\n/**\n * Splits a SchemaDiff into individual collection operations\n * Each operation will generate a separate migration file\n *\n * @param diff - Schema diff containing all changes\n * @param baseTimestamp - Base timestamp for the first operation\n * @returns Array of collection operations\n */\nexport function splitDiffByCollection(diff: SchemaDiff, baseTimestamp: string): CollectionOperation[] {\n const operations: CollectionOperation[] = [];\n let currentTimestamp = parseInt(baseTimestamp, 10);\n\n // Split collectionsToCreate into individual operations\n for (const collection of diff.collectionsToCreate) {\n operations.push({\n type: \"create\",\n collection: collection,\n timestamp: currentTimestamp.toString(),\n });\n currentTimestamp += 1; // Increment by 1 second\n }\n\n // Split collectionsToModify into individual operations\n for (const modification of diff.collectionsToModify) {\n operations.push({\n type: \"modify\",\n collection: modification.collection,\n modifications: modification,\n timestamp: currentTimestamp.toString(),\n });\n currentTimestamp += 1; // Increment by 1 second\n }\n\n // Split collectionsToDelete into individual operations\n for (const collection of diff.collectionsToDelete) {\n operations.push({\n type: \"delete\",\n collection: collection.name || collection, // Handle both object and string\n timestamp: currentTimestamp.toString(),\n });\n currentTimestamp += 1; // Increment by 1 second\n }\n\n return operations;\n}\n\n/**\n * Generates migration filename for a collection operation\n * Format: {timestamp}_{operation}_{collection_name}.js\n *\n * @param operation - Collection operation\n * @returns Migration filename\n */\nexport function generateCollectionMigrationFilename(operation: CollectionOperation): string {\n const timestamp = operation.timestamp;\n const operationType = operation.type === \"modify\" ? \"updated\" : operation.type === \"create\" ? \"created\" : \"deleted\";\n\n // Get collection name\n let collectionName: string;\n if (typeof operation.collection === \"string\") {\n collectionName = operation.collection;\n } else {\n collectionName = operation.collection.name;\n }\n\n // Sanitize collection name for filename (replace spaces and special chars with underscores)\n const sanitizedName = collectionName.replace(/[^a-zA-Z0-9_]/g, \"_\").toLowerCase();\n\n return `${timestamp}_${operationType}_${sanitizedName}.js`;\n}\n\n/**\n * Increments a timestamp by 1 second\n * Ensures sequential ordering of migration files\n *\n * @param timestamp - Current timestamp string\n * @returns Incremented timestamp string\n */\nexport function incrementTimestamp(timestamp: string): string {\n const currentTimestamp = parseInt(timestamp, 10);\n return (currentTimestamp + 1).toString();\n}\n\n/**\n * Generates a human-readable description from the diff\n * Creates a concise summary of the main changes\n *\n * @param diff - Schema diff containing all changes\n * @returns Description string for filename\n */\nexport function generateMigrationDescription(diff: SchemaDiff): string {\n const parts: string[] = [];\n\n // Summarize collection changes\n if (diff.collectionsToCreate.length > 0) {\n if (diff.collectionsToCreate.length === 1) {\n parts.push(`created_${diff.collectionsToCreate[0].name}`);\n } else {\n parts.push(`created_${diff.collectionsToCreate.length}_collections`);\n }\n }\n\n if (diff.collectionsToDelete.length > 0) {\n if (diff.collectionsToDelete.length === 1) {\n parts.push(`deleted_${diff.collectionsToDelete[0].name}`);\n } else {\n parts.push(`deleted_${diff.collectionsToDelete.length}_collections`);\n }\n }\n\n if (diff.collectionsToModify.length > 0) {\n if (diff.collectionsToModify.length === 1) {\n parts.push(`updated_${diff.collectionsToModify[0].collection}`);\n } else {\n parts.push(`updated_${diff.collectionsToModify.length}_collections`);\n }\n }\n\n // Default description if no changes\n if (parts.length === 0) {\n return \"no_changes\";\n }\n\n // Join parts with underscores and limit length\n let description = parts.join(\"_\");\n\n // Truncate if too long (keep under 100 chars for filename)\n if (description.length > 80) {\n description = description.substring(0, 77) + \"...\";\n }\n\n return description;\n}\n\n/**\n * Generates the migration filename\n * Format: {timestamp}_{description}.js\n *\n * @param diff - Schema diff containing all changes\n * @param config - Optional configuration\n * @returns Migration filename\n */\nexport function generateMigrationFilename(diff: SchemaDiff, config?: MigrationGeneratorConfig): string {\n const timestamp = generateTimestamp(config);\n const description = generateMigrationDescription(diff);\n\n return `${timestamp}_${description}.js`;\n}\n\n/**\n * Creates the migration file structure with up and down functions\n *\n * @param upCode - Code for the up migration\n * @param downCode - Code for the down migration\n * @param config - Optional configuration with custom template\n * @returns Complete migration file content\n */\nexport function createMigrationFileStructure(\n upCode: string,\n downCode: string,\n config?: MigrationGeneratorConfig\n): string {\n const mergedConfig = config ? mergeConfig(config) : DEFAULT_CONFIG;\n let template = mergedConfig.template;\n\n // Replace placeholders\n template = template.replace(\"{{TYPES_PATH}}\", mergedConfig.typesPath);\n template = template.replace(\"{{UP_CODE}}\", upCode);\n template = template.replace(\"{{DOWN_CODE}}\", downCode);\n\n // Remove type reference if disabled\n if (!mergedConfig.includeTypeReference) {\n template = template.replace(/\\/\\/\\/ <reference path=\"[^\"]*\" \\/>\\n?/, \"\");\n }\n\n return template;\n}\n\n/**\n * Writes migration file to the specified directory\n * Creates directory if it doesn't exist\n *\n * @param migrationDir - Directory to write migration file\n * @param filename - Migration filename\n * @param content - Migration file content\n * @returns Full path to the created migration file\n */\nexport function writeMigrationFile(migrationDir: string, filename: string, content: string): string {\n try {\n // Ensure migration directory exists\n if (!fs.existsSync(migrationDir)) {\n try {\n fs.mkdirSync(migrationDir, { recursive: true });\n } catch (error) {\n const fsError = error as NodeJS.ErrnoException;\n if (fsError.code === \"EACCES\" || fsError.code === \"EPERM\") {\n throw new FileSystemError(\n `Permission denied creating migration directory. Check directory permissions.`,\n migrationDir,\n \"create\",\n fsError.code,\n error as Error\n );\n }\n throw new FileSystemError(\n `Failed to create migration directory: ${fsError.message}`,\n migrationDir,\n \"create\",\n fsError.code,\n error as Error\n );\n }\n }\n\n // Full path to migration file\n const filePath = path.join(migrationDir, filename);\n\n // Write migration file\n fs.writeFileSync(filePath, content, \"utf-8\");\n\n return filePath;\n } catch (error) {\n // If it's already a FileSystemError, re-throw it\n if (error instanceof FileSystemError) {\n throw error;\n }\n\n const fsError = error as NodeJS.ErrnoException;\n const filePath = path.join(migrationDir, filename);\n\n if (fsError.code === \"EACCES\" || fsError.code === \"EPERM\") {\n throw new FileSystemError(\n `Permission denied writing migration file. Check file and directory permissions.`,\n filePath,\n \"write\",\n fsError.code,\n error as Error\n );\n } else if (fsError.code === \"ENOSPC\") {\n throw new FileSystemError(\n `No space left on device when writing migration file.`,\n filePath,\n \"write\",\n fsError.code,\n error as Error\n );\n }\n\n throw new MigrationGenerationError(`Failed to write migration file: ${fsError.message}`, filePath, error as Error);\n }\n}\n\n/**\n * Formats a value for JavaScript code generation\n * Handles strings, numbers, booleans, null, arrays, and objects\n *\n * @param value - Value to format\n * @returns Formatted string representation\n */\nfunction formatValue(value: any): string {\n if (value === null || value === undefined) {\n return \"null\";\n }\n\n if (typeof value === \"string\") {\n // Use JSON.stringify to properly escape all special characters\n return JSON.stringify(value);\n }\n\n if (typeof value === \"number\" || typeof value === \"boolean\") {\n return String(value);\n }\n\n if (Array.isArray(value)) {\n // Use JSON.stringify for arrays to properly handle all special characters\n // Then format with spaces after commas to match expected test output\n return JSON.stringify(value).replace(/\",\"/g, '\", \"');\n }\n\n if (typeof value === \"object\") {\n const entries = Object.entries(value)\n .filter(([_k, v]) => v !== undefined) // Omit undefined values\n .map(([k, v]) => `${k}: ${formatValue(v)}`)\n .join(\", \");\n return `{ ${entries} }`;\n }\n\n return String(value);\n}\n\n/**\n * Generates field definition object for collection creation\n * Creates the field configuration object used in Collection constructor\n *\n * @param field - Field definition\n * @param collectionIdMap - Map of collection names to their pre-generated IDs\n * @returns Field definition object as string\n */\nexport function generateFieldDefinitionObject(field: FieldDefinition, collectionIdMap?: Map<string, string>): string {\n const parts: string[] = [];\n\n // Add field name\n parts.push(` name: \"${field.name}\"`);\n\n // Add field type\n parts.push(` type: \"${field.type}\"`);\n\n // Add required flag\n parts.push(` required: ${field.required}`);\n\n // Add unique flag if present\n if (field.unique !== undefined) {\n parts.push(` unique: ${field.unique}`);\n }\n\n // Add explicit defaults for select fields\n if (field.type === \"select\") {\n // Always include maxSelect (default: 1)\n const maxSelect = field.options?.maxSelect ?? 1;\n parts.push(` maxSelect: ${maxSelect}`);\n\n // Always include values array (default: [])\n const values = field.options?.values ?? [];\n parts.push(` values: ${formatValue(values)}`);\n }\n\n // Add options if present (excluding select-specific options already handled)\n if (field.options && Object.keys(field.options).length > 0) {\n for (const [key, value] of Object.entries(field.options)) {\n // Skip select-specific options as they're handled above\n if (field.type === \"select\" && (key === \"maxSelect\" || key === \"values\")) {\n continue;\n }\n parts.push(` ${key}: ${formatValue(value)}`);\n }\n }\n\n // Add relation configuration if present\n if (field.relation) {\n // Use pre-generated collection ID from map if available\n // Otherwise fall back to runtime lookup (for existing collections not in the current diff)\n const isUsersCollection = field.relation.collection.toLowerCase() === \"users\";\n let collectionIdValue: string;\n\n if (isUsersCollection) {\n // Special case: users collection always uses the constant\n collectionIdValue = '\"_pb_users_auth_\"';\n } else if (collectionIdMap && collectionIdMap.has(field.relation.collection)) {\n // Use pre-generated ID from map\n collectionIdValue = `\"${collectionIdMap.get(field.relation.collection)}\"`;\n } else {\n // Fall back to runtime lookup for existing collections\n collectionIdValue = `app.findCollectionByNameOrId(\"${field.relation.collection}\").id`;\n }\n\n parts.push(` collectionId: ${collectionIdValue}`);\n\n // Always include maxSelect (default: 1)\n const maxSelect = field.relation.maxSelect ?? 1;\n parts.push(` maxSelect: ${maxSelect}`);\n\n // Always include minSelect (default: null)\n const minSelect = field.relation.minSelect ?? null;\n parts.push(` minSelect: ${minSelect}`);\n\n // Always include cascadeDelete (default: false)\n const cascadeDelete = field.relation.cascadeDelete ?? false;\n parts.push(` cascadeDelete: ${cascadeDelete}`);\n }\n\n return ` {\\n${parts.join(\",\\n\")},\\n }`;\n}\n\n/**\n * Generates fields array for collection creation\n *\n * @param fields - Array of field definitions\n * @param collectionIdMap - Map of collection names to their pre-generated IDs\n * @returns Fields array as string\n */\nexport function generateFieldsArray(fields: FieldDefinition[], collectionIdMap?: Map<string, string>): string {\n if (fields.length === 0) {\n return \"[]\";\n }\n\n const fieldObjects = fields.map((field) => generateFieldDefinitionObject(field, collectionIdMap));\n return `[\\n${fieldObjects.join(\",\\n\")},\\n ]`;\n}\n\n/**\n * Generates collection rules object\n *\n * @param rules - Collection rules\n * @returns Rules configuration as string\n */\nexport function generateCollectionRules(rules?: CollectionSchema[\"rules\"]): string {\n if (!rules) {\n return \"\";\n }\n\n const parts: string[] = [];\n\n if (rules.listRule !== undefined) {\n parts.push(`listRule: ${formatValue(rules.listRule)}`);\n }\n\n if (rules.viewRule !== undefined) {\n parts.push(`viewRule: ${formatValue(rules.viewRule)}`);\n }\n\n if (rules.createRule !== undefined) {\n parts.push(`createRule: ${formatValue(rules.createRule)}`);\n }\n\n if (rules.updateRule !== undefined) {\n parts.push(`updateRule: ${formatValue(rules.updateRule)}`);\n }\n\n if (rules.deleteRule !== undefined) {\n parts.push(`deleteRule: ${formatValue(rules.deleteRule)}`);\n }\n\n if (rules.manageRule !== undefined) {\n parts.push(`manageRule: ${formatValue(rules.manageRule)}`);\n }\n\n return parts.join(\",\\n \");\n}\n\n/**\n * Generates collection permissions object\n * Permissions are the same as rules but extracted from schema metadata\n *\n * @param permissions - Collection permissions\n * @returns Permissions configuration as string\n */\nexport function generateCollectionPermissions(permissions?: CollectionSchema[\"permissions\"]): string {\n if (!permissions) {\n return \"\";\n }\n\n const parts: string[] = [];\n\n if (permissions.listRule !== undefined) {\n parts.push(`listRule: ${formatValue(permissions.listRule)}`);\n }\n\n if (permissions.viewRule !== undefined) {\n parts.push(`viewRule: ${formatValue(permissions.viewRule)}`);\n }\n\n if (permissions.createRule !== undefined) {\n parts.push(`createRule: ${formatValue(permissions.createRule)}`);\n }\n\n if (permissions.updateRule !== undefined) {\n parts.push(`updateRule: ${formatValue(permissions.updateRule)}`);\n }\n\n if (permissions.deleteRule !== undefined) {\n parts.push(`deleteRule: ${formatValue(permissions.deleteRule)}`);\n }\n\n if (permissions.manageRule !== undefined) {\n parts.push(`manageRule: ${formatValue(permissions.manageRule)}`);\n }\n\n return parts.join(\",\\n \");\n}\n\n/**\n * Generates indexes array for collection creation\n *\n * @param indexes - Array of index definitions\n * @returns Indexes array as string\n */\nexport function generateIndexesArray(indexes?: string[]): string {\n if (!indexes || indexes.length === 0) {\n return \"[]\";\n }\n\n const indexStrings = indexes.map((idx) => JSON.stringify(idx));\n return `[\\n ${indexStrings.join(\",\\n \")},\\n ]`;\n}\n\n/**\n * Generates Collection constructor call for creating a new collection\n *\n * @param collection - Collection schema\n * @param varName - Variable name to use for the collection (default: 'collection')\n * @returns JavaScript code for creating the collection\n */\n/**\n * Generates system fields that are required for all PocketBase collections\n * These fields (id, created, updated) must be explicitly included in migrations\n *\n * @returns Array of system field definitions\n */\nfunction getSystemFields(): FieldDefinition[] {\n return [\n // id field - primary key, auto-generated\n {\n name: \"id\",\n type: \"text\",\n required: true,\n options: {\n autogeneratePattern: \"[a-z0-9]{15}\",\n hidden: false,\n id: \"text3208210256\",\n max: 15,\n min: 15,\n pattern: \"^[a-z0-9]+$\",\n presentable: false,\n primaryKey: true,\n system: true,\n },\n },\n // created field - autodate, set on creation\n {\n name: \"created\",\n type: \"autodate\",\n required: true,\n options: {\n hidden: false,\n id: \"autodate2990389176\",\n onCreate: true,\n onUpdate: false,\n presentable: false,\n system: false,\n },\n },\n // updated field - autodate, set on creation and update\n {\n name: \"updated\",\n type: \"autodate\",\n required: true,\n options: {\n hidden: false,\n id: \"autodate3332085495\",\n onCreate: true,\n onUpdate: true,\n presentable: false,\n system: false,\n },\n },\n ];\n}\n\nexport function generateCollectionCreation(\n collection: CollectionSchema,\n varName: string = \"collection\",\n isLast: boolean = false,\n collectionIdMap?: Map<string, string>\n): string {\n const lines: string[] = [];\n\n lines.push(` const ${varName} = new Collection({`);\n if (collection.id) {\n lines.push(` id: ${formatValue(collection.id)},`);\n }\n lines.push(` name: \"${collection.name}\",`);\n lines.push(` type: \"${collection.type}\",`);\n\n // Add permissions (preferred) or rules\n // Permissions take precedence if both are defined\n const permissionsCode = generateCollectionPermissions(collection.permissions);\n const rulesCode = generateCollectionRules(collection.rules);\n\n if (permissionsCode) {\n lines.push(` ${permissionsCode},`);\n } else if (rulesCode) {\n lines.push(` ${rulesCode},`);\n }\n\n // Prepend system fields (id, created, updated) to user-defined fields\n // These fields are required by PocketBase and must be explicitly included in migrations\n const systemFields = getSystemFields();\n const allFields = [...systemFields, ...collection.fields];\n\n // Add fields\n lines.push(` fields: ${generateFieldsArray(allFields, collectionIdMap)},`);\n\n // Add indexes\n lines.push(` indexes: ${generateIndexesArray(collection.indexes)},`);\n\n lines.push(` });`);\n lines.push(``);\n lines.push(isLast ? ` return app.save(${varName});` : ` app.save(${varName});`);\n\n return lines.join(\"\\n\");\n}\n\n/**\n * Gets the appropriate Field constructor name for a field type\n *\n * @param fieldType - PocketBase field type\n * @returns Field constructor name\n */\nfunction getFieldConstructorName(fieldType: string): string {\n const constructorMap: Record<string, string> = {\n text: \"TextField\",\n email: \"EmailField\",\n url: \"URLField\",\n number: \"NumberField\",\n bool: \"BoolField\",\n date: \"DateField\",\n select: \"SelectField\",\n relation: \"RelationField\",\n file: \"FileField\",\n json: \"JSONField\",\n };\n\n return constructorMap[fieldType] || \"TextField\";\n}\n\n/**\n * Generates field constructor options object\n *\n * @param field - Field definition\n * @param collectionIdMap - Map of collection names to their pre-generated IDs\n * @returns Options object as string\n */\nfunction generateFieldConstructorOptions(field: FieldDefinition, collectionIdMap?: Map<string, string>): string {\n const parts: string[] = [];\n\n // Add field name\n parts.push(` name: \"${field.name}\"`);\n\n // Add required flag\n parts.push(` required: ${field.required}`);\n\n // Add unique flag if present\n if (field.unique !== undefined) {\n parts.push(` unique: ${field.unique}`);\n }\n\n // Add explicit defaults for select fields\n if (field.type === \"select\") {\n // Always include maxSelect (default: 1)\n const maxSelect = field.options?.maxSelect ?? 1;\n parts.push(` maxSelect: ${maxSelect}`);\n\n // Always include values array (default: [])\n const values = field.options?.values ?? [];\n parts.push(` values: ${formatValue(values)}`);\n }\n\n // Add options if present (excluding select-specific options already handled)\n if (field.options && Object.keys(field.options).length > 0) {\n for (const [key, value] of Object.entries(field.options)) {\n // Skip select-specific options as they're handled above\n if (field.type === \"select\" && (key === \"maxSelect\" || key === \"values\")) {\n continue;\n }\n // Convert noDecimal to onlyInt for number fields (PocketBase uses onlyInt)\n if (field.type === \"number\" && key === \"noDecimal\") {\n parts.push(` onlyInt: ${formatValue(value)}`);\n } else {\n parts.push(` ${key}: ${formatValue(value)}`);\n }\n }\n }\n\n // Add relation-specific options\n if (field.relation && field.type === \"relation\") {\n // Use pre-generated collection ID from map if available\n // Otherwise fall back to runtime lookup (for existing collections not in the current diff)\n const isUsersCollection = field.relation.collection.toLowerCase() === \"users\";\n let collectionIdValue: string;\n\n if (isUsersCollection) {\n // Special case: users collection always uses the constant\n collectionIdValue = '\"_pb_users_auth_\"';\n } else if (collectionIdMap && collectionIdMap.has(field.relation.collection)) {\n // Use pre-generated ID from map\n collectionIdValue = `\"${collectionIdMap.get(field.relation.collection)}\"`;\n } else {\n // Fall back to runtime lookup for existing collections\n collectionIdValue = `app.findCollectionByNameOrId(\"${field.relation.collection}\").id`;\n }\n\n parts.push(` collectionId: ${collectionIdValue}`);\n\n // Always include maxSelect (default: 1)\n const maxSelect = field.relation.maxSelect ?? 1;\n parts.push(` maxSelect: ${maxSelect}`);\n\n // Always include minSelect (default: null)\n const minSelect = field.relation.minSelect ?? null;\n parts.push(` minSelect: ${minSelect}`);\n\n // Always include cascadeDelete (default: false)\n const cascadeDelete = field.relation.cascadeDelete ?? false;\n parts.push(` cascadeDelete: ${cascadeDelete}`);\n }\n\n return parts.join(\",\\n\");\n}\n\n/**\n * Generates code for adding a field to an existing collection\n * Uses the appropriate Field constructor based on field type\n *\n * @param collectionName - Name of the collection\n * @param field - Field definition to add\n * @param varName - Variable name to use for the collection (default: auto-generated)\n * @param isLast - Whether this is the last operation (will return the result)\n * @param collectionIdMap - Map of collection names to their pre-generated IDs\n * @returns JavaScript code for adding the field\n */\nexport function generateFieldAddition(\n collectionName: string,\n field: FieldDefinition,\n varName?: string,\n isLast: boolean = false,\n collectionIdMap?: Map<string, string>\n): string {\n const lines: string[] = [];\n const constructorName = getFieldConstructorName(field.type);\n const collectionVar = varName || `collection_${collectionName}_${field.name}`;\n\n lines.push(` const ${collectionVar} = app.findCollectionByNameOrId(\"${collectionName}\");`);\n lines.push(``);\n lines.push(` ${collectionVar}.fields.add(new ${constructorName}({`);\n lines.push(generateFieldConstructorOptions(field, collectionIdMap));\n lines.push(` }));`);\n lines.push(``);\n lines.push(isLast ? ` return app.save(${collectionVar});` : ` app.save(${collectionVar});`);\n\n return lines.join(\"\\n\");\n}\n\n/**\n * Generates code for modifying an existing field\n * Updates field properties based on detected changes\n *\n * @param collectionName - Name of the collection\n * @param modification - Field modification details\n * @param varName - Variable name to use for the collection (default: auto-generated)\n * @param isLast - Whether this is the last operation (will return the result)\n * @returns JavaScript code for modifying the field\n */\nexport function generateFieldModification(\n collectionName: string,\n modification: FieldModification,\n varName?: string,\n isLast: boolean = false\n): string {\n const lines: string[] = [];\n const collectionVar = varName || `collection_${collectionName}_${modification.fieldName}`;\n const fieldVar = `${collectionVar}_field`;\n\n lines.push(` const ${collectionVar} = app.findCollectionByNameOrId(\"${collectionName}\");`);\n lines.push(` const ${fieldVar} = ${collectionVar}.fields.getByName(\"${modification.fieldName}\");`);\n lines.push(``);\n\n // Apply each change\n for (const change of modification.changes) {\n if (change.property.startsWith(\"options.\")) {\n // Handle nested options properties\n const optionKey = change.property.replace(\"options.\", \"\");\n // In PocketBase, field properties are set directly on the field, not in an options object\n lines.push(` ${fieldVar}.${optionKey} = ${formatValue(change.newValue)};`);\n } else if (change.property.startsWith(\"relation.\")) {\n // Handle nested relation properties\n const relationKey = change.property.replace(\"relation.\", \"\");\n\n if (relationKey === \"collection\") {\n // Special handling for collection ID\n // Use case-insensitive check for \"users\" to handle both explicit and implicit relation definitions\n const isUsersCollection = String(change.newValue).toLowerCase() === \"users\";\n const collectionIdValue = isUsersCollection\n ? '\"_pb_users_auth_\"'\n : `app.findCollectionByNameOrId(\"${change.newValue}\").id`;\n lines.push(` ${fieldVar}.collectionId = ${collectionIdValue};`);\n } else {\n lines.push(` ${fieldVar}.${relationKey} = ${formatValue(change.newValue)};`);\n }\n } else {\n // Handle top-level properties\n lines.push(` ${fieldVar}.${change.property} = ${formatValue(change.newValue)};`);\n }\n }\n\n lines.push(``);\n lines.push(isLast ? ` return app.save(${collectionVar});` : ` app.save(${collectionVar});`);\n\n return lines.join(\"\\n\");\n}\n\n/**\n * Generates code for deleting a field from a collection\n *\n * @param collectionName - Name of the collection\n * @param fieldName - Name of the field to delete\n * @param varName - Variable name to use for the collection (default: auto-generated)\n * @param isLast - Whether this is the last operation (will return the result)\n * @returns JavaScript code for deleting the field\n */\nexport function generateFieldDeletion(\n collectionName: string,\n fieldName: string,\n varName?: string,\n isLast: boolean = false\n): string {\n const lines: string[] = [];\n const collectionVar = varName || `collection_${collectionName}_${fieldName}`;\n\n lines.push(` const ${collectionVar} = app.findCollectionByNameOrId(\"${collectionName}\");`);\n lines.push(``);\n lines.push(` ${collectionVar}.fields.removeByName(\"${fieldName}\");`);\n lines.push(``);\n lines.push(isLast ? ` return app.save(${collectionVar});` : ` app.save(${collectionVar});`);\n\n return lines.join(\"\\n\");\n}\n\n/**\n * Generates code for adding an index to a collection\n *\n * @param collectionName - Name of the collection\n * @param index - Index SQL statement\n * @param varName - Variable name to use for the collection (default: auto-generated)\n * @param isLast - Whether this is the last operation (will return the result)\n * @returns JavaScript code for adding the index\n */\nfunction generateIndexAddition(\n collectionName: string,\n index: string,\n varName?: string,\n isLast: boolean = false\n): string {\n const lines: string[] = [];\n const collectionVar = varName || `collection_${collectionName}_idx`;\n\n lines.push(` const ${collectionVar} = app.findCollectionByNameOrId(\"${collectionName}\");`);\n lines.push(` ${collectionVar}.indexes.push(${JSON.stringify(index)});`);\n lines.push(isLast ? ` return app.save(${collectionVar});` : ` app.save(${collectionVar});`);\n\n return lines.join(\"\\n\");\n}\n\n/**\n * Generates code for removing an index from a collection\n *\n * @param collectionName - Name of the collection\n * @param index - Index SQL statement\n * @param varName - Variable name to use for the collection (default: auto-generated)\n * @param isLast - Whether this is the last operation (will return the result)\n * @returns JavaScript code for removing the index\n */\nfunction generateIndexRemoval(\n collectionName: string,\n index: string,\n varName?: string,\n isLast: boolean = false\n): string {\n const lines: string[] = [];\n const collectionVar = varName || `collection_${collectionName}_idx`;\n const indexVar = `${collectionVar}_indexToRemove`;\n\n lines.push(` const ${collectionVar} = app.findCollectionByNameOrId(\"${collectionName}\");`);\n lines.push(` const ${indexVar} = ${collectionVar}.indexes.findIndex(idx => idx === ${JSON.stringify(index)});`);\n lines.push(` if (${indexVar} !== -1) {`);\n lines.push(` ${collectionVar}.indexes.splice(${indexVar}, 1);`);\n lines.push(` }`);\n lines.push(isLast ? ` return app.save(${collectionVar});` : ` app.save(${collectionVar});`);\n\n return lines.join(\"\\n\");\n}\n\n/**\n * Generates code for updating collection rules\n *\n * @param collectionName - Name of the collection\n * @param ruleType - Type of rule to update\n * @param newValue - New rule value\n * @param varName - Variable name to use for the collection (default: auto-generated)\n * @param isLast - Whether this is the last operation (will return the result)\n * @returns JavaScript code for updating the rule\n */\nfunction generateRuleUpdate(\n collectionName: string,\n ruleType: string,\n newValue: string | null,\n varName?: string,\n isLast: boolean = false\n): string {\n const lines: string[] = [];\n const collectionVar = varName || `collection_${collectionName}_${ruleType}`;\n\n lines.push(` const ${collectionVar} = app.findCollectionByNameOrId(\"${collectionName}\");`);\n lines.push(` ${collectionVar}.${ruleType} = ${formatValue(newValue)};`);\n lines.push(isLast ? ` return app.save(${collectionVar});` : ` app.save(${collectionVar});`);\n\n return lines.join(\"\\n\");\n}\n\n/**\n * Generates code for updating collection permissions\n * Handles permission rule updates including manageRule for auth collections\n *\n * @param collectionName - Name of the collection\n * @param ruleType - Type of permission rule to update\n * @param newValue - New permission rule value\n * @param varName - Variable name to use for the collection (default: auto-generated)\n * @param isLast - Whether this is the last operation (will return the result)\n * @returns JavaScript code for updating the permission\n */\nexport function generatePermissionUpdate(\n collectionName: string,\n ruleType: string,\n newValue: string | null,\n varName?: string,\n isLast: boolean = false\n): string {\n const lines: string[] = [];\n const collectionVar = varName || `collection_${collectionName}_${ruleType}`;\n\n lines.push(` const ${collectionVar} = app.findCollectionByNameOrId(\"${collectionName}\");`);\n lines.push(` ${collectionVar}.${ruleType} = ${formatValue(newValue)};`);\n lines.push(isLast ? ` return app.save(${collectionVar});` : ` app.save(${collectionVar});`);\n\n return lines.join(\"\\n\");\n}\n\n/**\n * Generates code for deleting a collection\n *\n * @param collectionName - Name of the collection to delete\n * @param varName - Variable name to use for the collection (default: 'collection')\n * @param isLast - Whether this is the last operation (will return the result)\n * @returns JavaScript code for deleting the collection\n */\nfunction generateCollectionDeletion(\n collectionName: string,\n varName: string = \"collection\",\n isLast: boolean = false\n): string {\n const lines: string[] = [];\n\n lines.push(` const ${varName} = app.findCollectionByNameOrId(\"${collectionName}\");`);\n lines.push(isLast ? ` return app.delete(${varName});` : ` app.delete(${varName});`);\n\n return lines.join(\"\\n\");\n}\n\n/**\n * Generates the up migration code for a single collection operation\n * Handles create, modify, and delete operations\n *\n * @param operation - Collection operation to generate migration for\n * @param collectionIdMap - Map of collection names to their pre-generated IDs\n * @returns JavaScript code for up migration\n */\nexport function generateOperationUpMigration(\n operation: CollectionOperation,\n collectionIdMap: Map<string, string>\n): string {\n const lines: string[] = [];\n\n if (operation.type === \"create\") {\n // Handle collection creation\n const collection = operation.collection as CollectionSchema;\n const varName = `collection_${collection.name}`;\n lines.push(generateCollectionCreation(collection, varName, true, collectionIdMap));\n } else if (operation.type === \"modify\") {\n // Handle collection modification\n const modification = operation.modifications!;\n const collectionName =\n typeof operation.collection === \"string\"\n ? operation.collection\n : (operation.collection?.name ?? modification.collection);\n\n let operationCount = 0;\n const totalOperations =\n modification.fieldsToAdd.length +\n modification.fieldsToModify.length +\n modification.fieldsToRemove.length +\n modification.indexesToAdd.length +\n modification.indexesToRemove.length +\n modification.rulesToUpdate.length +\n modification.permissionsToUpdate.length;\n\n // Add new fields\n for (const field of modification.fieldsToAdd) {\n operationCount++;\n const varName = `collection_${collectionName}_add_${field.name}`;\n const isLast = operationCount === totalOperations;\n lines.push(generateFieldAddition(collectionName, field, varName, isLast, collectionIdMap));\n if (!isLast) lines.push(\"\");\n }\n\n // Modify existing fields\n for (const fieldMod of modification.fieldsToModify) {\n operationCount++;\n const varName = `collection_${collectionName}_modify_${fieldMod.fieldName}`;\n const isLast = operationCount === totalOperations;\n lines.push(generateFieldModification(collectionName, fieldMod, varName, isLast));\n if (!isLast) lines.push(\"\");\n }\n\n // Remove fields\n for (const field of modification.fieldsToRemove) {\n operationCount++;\n const varName = `collection_${collectionName}_remove_${field.name}`;\n const isLast = operationCount === totalOperations;\n lines.push(generateFieldDeletion(collectionName, field.name, varName, isLast));\n if (!isLast) lines.push(\"\");\n }\n\n // Add indexes\n for (let i = 0; i < modification.indexesToAdd.length; i++) {\n operationCount++;\n const index = modification.indexesToAdd[i];\n const varName = `collection_${collectionName}_addidx_${i}`;\n const isLast = operationCount === totalOperations;\n lines.push(generateIndexAddition(collectionName, index, varName, isLast));\n if (!isLast) lines.push(\"\");\n }\n\n // Remove indexes\n for (let i = 0; i < modification.indexesToRemove.length; i++) {\n operationCount++;\n const index = modification.indexesToRemove[i];\n const varName = `collection_${collectionName}_rmidx_${i}`;\n const isLast = operationCount === totalOperations;\n lines.push(generateIndexRemoval(collectionName, index, varName, isLast));\n if (!isLast) lines.push(\"\");\n }\n\n // Update permissions (preferred) or rules (fallback)\n if (modification.permissionsToUpdate && modification.permissionsToUpdate.length > 0) {\n for (const permission of modification.permissionsToUpdate) {\n operationCount++;\n const varName = `collection_${collectionName}_perm_${permission.ruleType}`;\n const isLast = operationCount === totalOperations;\n lines.push(generatePermissionUpdate(collectionName, permission.ruleType, permission.newValue, varName, isLast));\n if (!isLast) lines.push(\"\");\n }\n } else if (modification.rulesToUpdate.length > 0) {\n for (const rule of modification.rulesToUpdate) {\n operationCount++;\n const varName = `collection_${collectionName}_rule_${rule.ruleType}`;\n const isLast = operationCount === totalOperations;\n lines.push(generateRuleUpdate(collectionName, rule.ruleType, rule.newValue, varName, isLast));\n if (!isLast) lines.push(\"\");\n }\n }\n } else if (operation.type === \"delete\") {\n // Handle collection deletion\n const collectionName = typeof operation.collection === \"string\" ? operation.collection : operation.collection.name;\n const varName = `collection_${collectionName}`;\n lines.push(generateCollectionDeletion(collectionName, varName, true));\n }\n\n let code = lines.join(\"\\n\");\n\n // Check if there's already a return statement in the code\n // If so, skip post-processing to avoid duplicate returns\n const hasReturnStatement = /return\\s+app\\.(save|delete)\\(/m.test(code);\n\n if (!hasReturnStatement) {\n // Find the last app.save() or app.delete() call and make it return the result\n // Match app.save(...) or app.delete(...) at the end of lines (not in comments or strings)\n const savePattern = /^(\\s*)app\\.save\\((\\w+)\\);$/gm;\n const deletePattern = /^(\\s*)app\\.delete\\((\\w+)\\);$/gm;\n\n const saveMatches = [...code.matchAll(savePattern)];\n const deleteMatches = [...code.matchAll(deletePattern)];\n\n // Combine all matches and find the last one by position\n const allMatches = [\n ...saveMatches.map((m) => ({ match: m, type: \"save\", index: m.index! })),\n ...deleteMatches.map((m) => ({ match: m, type: \"delete\", index: m.index! })),\n ].sort((a, b) => b.index - a.index); // Sort descending to get last match first\n\n if (allMatches.length > 0) {\n const lastMatch = allMatches[0];\n if (lastMatch.type === \"save\") {\n code =\n code.substring(0, lastMatch.match.index!) +\n lastMatch.match[1] +\n \"return app.save(\" +\n lastMatch.match[2] +\n \");\" +\n code.substring(lastMatch.match.index! + lastMatch.match[0].length);\n } else {\n code =\n code.substring(0, lastMatch.match.index!) +\n lastMatch.match[1] +\n \"return app.delete(\" +\n lastMatch.match[2] +\n \");\" +\n code.substring(lastMatch.match.index! + lastMatch.match[0].length);\n }\n }\n }\n\n return code;\n}\n\n/**\n * Generates the down migration code for a single collection operation\n * Reverts the operation (inverse of up migration)\n *\n * @param operation - Collection operation to generate rollback for\n * @param collectionIdMap - Map of collection names to their pre-generated IDs\n * @returns JavaScript code for down migration\n */\nexport function generateOperationDownMigration(\n operation: CollectionOperation,\n collectionIdMap: Map<string, string>\n): string {\n const lines: string[] = [];\n\n if (operation.type === \"create\") {\n // Rollback: delete the created collection\n const collection = operation.collection as CollectionSchema;\n const varName = `collection_${collection.name}`;\n lines.push(generateCollectionDeletion(collection.name, varName, true));\n } else if (operation.type === \"modify\") {\n // Rollback: revert all modifications\n const modification = operation.modifications!;\n const collectionName =\n typeof operation.collection === \"string\"\n ? operation.collection\n : (operation.collection?.name ?? modification.collection);\n\n let operationCount = 0;\n const totalOperations =\n modification.fieldsToAdd.length +\n modification.fieldsToModify.length +\n modification.fieldsToRemove.length +\n modification.indexesToAdd.length +\n modification.indexesToRemove.length +\n modification.rulesToUpdate.length +\n modification.permissionsToUpdate.length;\n\n // Revert permissions (preferred) or rules (fallback)\n if (modification.permissionsToUpdate && modification.permissionsToUpdate.length > 0) {\n for (const permission of modification.permissionsToUpdate) {\n operationCount++;\n const varName = `collection_${collectionName}_revert_perm_${permission.ruleType}`;\n const isLast = operationCount === totalOperations;\n lines.push(generatePermissionUpdate(collectionName, permission.ruleType, permission.oldValue, varName, isLast));\n if (!isLast) lines.push(\"\");\n }\n } else if (modification.rulesToUpdate.length > 0) {\n for (const rule of modification.rulesToUpdate) {\n operationCount++;\n const varName = `collection_${collectionName}_revert_rule_${rule.ruleType}`;\n const isLast = operationCount === totalOperations;\n lines.push(generateRuleUpdate(collectionName, rule.ruleType, rule.oldValue, varName, isLast));\n if (!isLast) lines.push(\"\");\n }\n }\n\n // Revert index removals (add them back)\n for (let i = 0; i < modification.indexesToRemove.length; i++) {\n operationCount++;\n const index = modification.indexesToRemove[i];\n const varName = `collection_${collectionName}_restore_idx_${i}`;\n const isLast = operationCount === totalOperations;\n lines.push(generateIndexAddition(collectionName, index, varName, isLast));\n if (!isLast) lines.push(\"\");\n }\n\n // Revert index additions (remove them)\n for (let i = 0; i < modification.indexesToAdd.length; i++) {\n operationCount++;\n const index = modification.indexesToAdd[i];\n const varName = `collection_${collectionName}_revert_idx_${i}`;\n const isLast = operationCount === totalOperations;\n lines.push(generateIndexRemoval(collectionName, index, varName, isLast));\n if (!isLast) lines.push(\"\");\n }\n\n // Revert field removals (add them back)\n for (const field of modification.fieldsToRemove) {\n operationCount++;\n const varName = `collection_${collectionName}_restore_${field.name}`;\n const isLast = operationCount === totalOperations;\n lines.push(generateFieldAddition(collectionName, field, varName, isLast, collectionIdMap));\n if (!isLast) lines.push(\"\");\n }\n\n // Revert field modifications\n for (const fieldMod of modification.fieldsToModify) {\n operationCount++;\n // Create a reverse modification\n const reverseChanges = fieldMod.changes.map((change) => ({\n property: change.property,\n oldValue: change.newValue,\n newValue: change.oldValue,\n }));\n\n const reverseMod: FieldModification = {\n fieldName: fieldMod.fieldName,\n currentDefinition: fieldMod.newDefinition,\n newDefinition: fieldMod.currentDefinition,\n changes: reverseChanges,\n };\n\n const varName = `collection_${collectionName}_revert_${fieldMod.fieldName}`;\n const isLast = operationCount === totalOperations;\n lines.push(generateFieldModification(collectionName, reverseMod, varName, isLast));\n if (!isLast) lines.push(\"\");\n }\n\n // Revert field additions (remove them)\n for (const field of modification.fieldsToAdd) {\n operationCount++;\n const varName = `collection_${collectionName}_revert_add_${field.name}`;\n const isLast = operationCount === totalOperations;\n lines.push(generateFieldDeletion(collectionName, field.name, varName, isLast));\n if (!isLast) lines.push(\"\");\n }\n } else if (operation.type === \"delete\") {\n // Rollback: recreate the deleted collection\n const collection = operation.collection;\n if (typeof collection !== \"string\") {\n const varName = `collection_${collection.name}`;\n lines.push(generateCollectionCreation(collection, varName, true, collectionIdMap));\n }\n }\n\n let code = lines.join(\"\\n\");\n\n // Check if there's already a return statement in the code\n // If so, skip post-processing to avoid duplicate returns\n const hasReturnStatement = /return\\s+app\\.(save|delete)\\(/m.test(code);\n\n if (!hasReturnStatement) {\n // Find the last app.save() or app.delete() call and make it return the result\n // Match app.save(...) or app.delete(...) at the end of lines (not in comments or strings)\n const savePattern = /^(\\s*)app\\.save\\((\\w+)\\);$/gm;\n const deletePattern = /^(\\s*)app\\.delete\\((\\w+)\\);$/gm;\n\n const saveMatches = [...code.matchAll(savePattern)];\n const deleteMatches = [...code.matchAll(deletePattern)];\n\n // Combine all matches and find the last one by position\n const allMatches = [\n ...saveMatches.map((m) => ({ match: m, type: \"save\", index: m.index! })),\n ...deleteMatches.map((m) => ({ match: m, type: \"delete\", index: m.index! })),\n ].sort((a, b) => b.index - a.index); // Sort descending to get last match first\n\n if (allMatches.length > 0) {\n const lastMatch = allMatches[0];\n if (lastMatch.type === \"save\") {\n code =\n code.substring(0, lastMatch.match.index!) +\n lastMatch.match[1] +\n \"return app.save(\" +\n lastMatch.match[2] +\n \");\" +\n code.substring(lastMatch.match.index! + lastMatch.match[0].length);\n } else {\n code =\n code.substring(0, lastMatch.match.index!) +\n lastMatch.match[1] +\n \"return app.delete(\" +\n lastMatch.match[2] +\n \");\" +\n code.substring(lastMatch.match.index! + lastMatch.match[0].length);\n }\n }\n }\n\n return code;\n}\n\n/**\n * Generates the up migration function code\n * Applies all changes from the diff in the correct order\n *\n * @param diff - Schema diff containing all changes\n * @returns JavaScript code for up migration\n */\nexport function generateUpMigration(diff: SchemaDiff): string {\n const lines: string[] = [];\n\n // Add comment header\n lines.push(` // UP MIGRATION`);\n lines.push(``);\n\n // Build collection ID map from collections being created\n // This map will be used to resolve relation field references\n const collectionIdMap = new Map<string, string>();\n for (const collection of diff.collectionsToCreate) {\n if (collection.id) {\n collectionIdMap.set(collection.name, collection.id);\n }\n }\n\n // 1. Create new collections\n if (diff.collectionsToCreate.length > 0) {\n lines.push(` // Create new collections`);\n for (let i = 0; i < diff.collectionsToCreate.length; i++) {\n const collection = diff.collectionsToCreate[i];\n const varName = `collection_${collection.name}_create`;\n lines.push(generateCollectionCreation(collection, varName, false, collectionIdMap));\n lines.push(``);\n }\n }\n\n // 2. Modify existing collections\n if (diff.collectionsToModify.length > 0) {\n lines.push(` // Modify existing collections`);\n for (const modification of diff.collectionsToModify) {\n const collectionName = modification.collection;\n // Add new fields\n if (modification.fieldsToAdd.length > 0) {\n lines.push(` // Add fields to ${collectionName}`);\n for (const field of modification.fieldsToAdd) {\n const varName = `collection_${collectionName}_add_${field.name}`;\n lines.push(generateFieldAddition(collectionName, field, varName, false, collectionIdMap));\n lines.push(``);\n }\n }\n\n // Modify existing fields\n if (modification.fieldsToModify.length > 0) {\n lines.push(` // Modify fields in ${collectionName}`);\n for (const fieldMod of modification.fieldsToModify) {\n const varName = `collection_${collectionName}_modify_${fieldMod.fieldName}`;\n lines.push(generateFieldModification(collectionName, fieldMod, varName));\n lines.push(``);\n }\n }\n\n // Remove fields\n if (modification.fieldsToRemove.length > 0) {\n lines.push(` // Remove fields from ${collectionName}`);\n for (const field of modification.fieldsToRemove) {\n const varName = `collection_${collectionName}_remove_${field.name}`;\n lines.push(generateFieldDeletion(collectionName, field.name, varName));\n lines.push(``);\n }\n }\n\n // Add indexes\n if (modification.indexesToAdd.length > 0) {\n lines.push(` // Add indexes to ${collectionName}`);\n for (let i = 0; i < modification.indexesToAdd.length; i++) {\n const index = modification.indexesToAdd[i];\n const varName = `collection_${collectionName}_addidx_${i}`;\n lines.push(generateIndexAddition(collectionName, index, varName));\n lines.push(``);\n }\n }\n\n // Remove indexes\n if (modification.indexesToRemove.length > 0) {\n lines.push(` // Remove indexes from ${collectionName}`);\n for (let i = 0; i < modification.indexesToRemove.length; i++) {\n const index = modification.indexesToRemove[i];\n const varName = `collection_${collectionName}_rmidx_${i}`;\n lines.push(generateIndexRemoval(collectionName, index, varName));\n lines.push(``);\n }\n }\n\n // Update permissions (preferred) or rules (fallback)\n if (modification.permissionsToUpdate && modification.permissionsToUpdate.length > 0) {\n lines.push(` // Update permissions for ${collectionName}`);\n for (const permission of modification.permissionsToUpdate) {\n const varName = `collection_${collectionName}_perm_${permission.ruleType}`;\n lines.push(generatePermissionUpdate(collectionName, permission.ruleType, permission.newValue, varName));\n lines.push(``);\n }\n } else if (modification.rulesToUpdate.length > 0) {\n lines.push(` // Update rules for ${collectionName}`);\n for (const rule of modification.rulesToUpdate) {\n const varName = `collection_${collectionName}_rule_${rule.ruleType}`;\n lines.push(generateRuleUpdate(collectionName, rule.ruleType, rule.newValue, varName));\n lines.push(``);\n }\n }\n }\n }\n\n // 3. Delete collections\n if (diff.collectionsToDelete.length > 0) {\n lines.push(` // Delete collections`);\n for (let i = 0; i < diff.collectionsToDelete.length; i++) {\n const collection = diff.collectionsToDelete[i];\n const varName = `collection_${collection.name}_delete`;\n lines.push(generateCollectionDeletion(collection.name, varName));\n lines.push(``);\n }\n }\n\n // If no changes, add a comment\n if (lines.length === 2) {\n lines.push(` // No changes detected`);\n lines.push(``);\n }\n\n let code = lines.join(\"\\n\");\n\n // Check if there's already a return statement in the code\n // If so, skip post-processing to avoid duplicate returns\n const hasReturnStatement = /return\\s+app\\.(save|delete)\\(/m.test(code);\n\n if (!hasReturnStatement) {\n // Find the last app.save() or app.delete() call and make it return the result\n // Match app.save(...) or app.delete(...) at the end of lines (not in comments or strings)\n const savePattern = /^(\\s*)app\\.save\\((\\w+)\\);$/gm;\n const deletePattern = /^(\\s*)app\\.delete\\((\\w+)\\);$/gm;\n\n const saveMatches = [...code.matchAll(savePattern)];\n const deleteMatches = [...code.matchAll(deletePattern)];\n\n // Combine all matches and find the last one by position\n const allMatches = [\n ...saveMatches.map((m) => ({ match: m, type: \"save\", index: m.index! })),\n ...deleteMatches.map((m) => ({ match: m, type: \"delete\", index: m.index! })),\n ].sort((a, b) => b.index - a.index); // Sort descending to get last match first\n\n if (allMatches.length > 0) {\n const lastMatch = allMatches[0];\n if (lastMatch.type === \"save\") {\n code =\n code.substring(0, lastMatch.match.index!) +\n lastMatch.match[1] +\n \"return app.save(\" +\n lastMatch.match[2] +\n \");\" +\n code.substring(lastMatch.match.index! + lastMatch.match[0].length);\n } else {\n code =\n code.substring(0, lastMatch.match.index!) +\n lastMatch.match[1] +\n \"return app.delete(\" +\n lastMatch.match[2] +\n \");\" +\n code.substring(lastMatch.match.index! + lastMatch.match[0].length);\n }\n }\n }\n\n return code;\n}\n\n/**\n * Generates the down migration function code\n * Reverts all changes from the diff in reverse order\n *\n * @param diff - Schema diff containing all changes\n * @returns JavaScript code for down migration\n */\nexport function generateDownMigration(diff: SchemaDiff): string {\n const lines: string[] = [];\n\n // Add comment header\n lines.push(` // DOWN MIGRATION (ROLLBACK)`);\n lines.push(``);\n\n // Build collection ID map from collections being created (for rollback)\n // This map will be used to resolve relation field references\n const collectionIdMap = new Map<string, string>();\n for (const collection of diff.collectionsToCreate) {\n if (collection.id) {\n collectionIdMap.set(collection.name, collection.id);\n }\n }\n // Also include deleted collections that might have IDs\n for (const collection of diff.collectionsToDelete) {\n if (collection.id) {\n collectionIdMap.set(collection.name, collection.id);\n }\n }\n\n // Reverse order: delete -> modify -> create\n\n // 1. Recreate deleted collections\n if (diff.collectionsToDelete.length > 0) {\n lines.push(` // Recreate deleted collections`);\n for (let i = 0; i < diff.collectionsToDelete.length; i++) {\n const collection = diff.collectionsToDelete[i];\n const varName = `collection_${collection.name}_recreate`;\n lines.push(generateCollectionCreation(collection, varName, false, collectionIdMap));\n lines.push(``);\n }\n }\n\n // 2. Revert modifications (in reverse order)\n if (diff.collectionsToModify.length > 0) {\n lines.push(` // Revert modifications`);\n for (const modification of diff.collectionsToModify) {\n const collectionName = modification.collection;\n // Revert permissions (preferred) or rules (fallback)\n if (modification.permissionsToUpdate && modification.permissionsToUpdate.length > 0) {\n lines.push(` // Revert permissions for ${collectionName}`);\n for (const permission of modification.permissionsToUpdate) {\n const varName = `collection_${collectionName}_revert_perm_${permission.ruleType}`;\n lines.push(generatePermissionUpdate(collectionName, permission.ruleType, permission.oldValue, varName));\n lines.push(``);\n }\n } else if (modification.rulesToUpdate.length > 0) {\n lines.push(` // Revert rules for ${collectionName}`);\n for (const rule of modification.rulesToUpdate) {\n const varName = `collection_${collectionName}_revert_rule_${rule.ruleType}`;\n lines.push(generateRuleUpdate(collectionName, rule.ruleType, rule.oldValue, varName));\n lines.push(``);\n }\n }\n\n // Revert index removals (add them back)\n if (modification.indexesToRemove.length > 0) {\n lines.push(` // Restore indexes to ${collectionName}`);\n for (let i = 0; i < modification.indexesToRemove.length; i++) {\n const index = modification.indexesToRemove[i];\n const varName = `collection_${collectionName}_restore_idx_${i}`;\n lines.push(generateIndexAddition(collectionName, index, varName));\n lines.push(``);\n }\n }\n\n // Revert index additions (remove them)\n if (modification.indexesToAdd.length > 0) {\n lines.push(` // Remove indexes from ${collectionName}`);\n for (let i = 0; i < modification.indexesToAdd.length; i++) {\n const index = modification.indexesToAdd[i];\n const varName = `collection_${collectionName}_revert_idx_${i}`;\n lines.push(generateIndexRemoval(collectionName, index, varName));\n lines.push(``);\n }\n }\n\n // Revert field removals (add them back)\n if (modification.fieldsToRemove.length > 0) {\n lines.push(` // Restore fields to ${collectionName}`);\n for (const field of modification.fieldsToRemove) {\n const varName = `collection_${collectionName}_restore_${field.name}`;\n lines.push(generateFieldAddition(collectionName, field, varName, false, collectionIdMap));\n lines.push(``);\n }\n }\n\n // Revert field modifications\n if (modification.fieldsToModify.length > 0) {\n lines.push(` // Revert field modifications in ${collectionName}`);\n for (const fieldMod of modification.fieldsToModify) {\n // Create a reverse modification\n const reverseChanges = fieldMod.changes.map((change) => ({\n property: change.property,\n oldValue: change.newValue,\n newValue: change.oldValue,\n }));\n\n const reverseMod: FieldModification = {\n fieldName: fieldMod.fieldName,\n currentDefinition: fieldMod.newDefinition,\n newDefinition: fieldMod.currentDefinition,\n changes: reverseChanges,\n };\n\n const varName = `collection_${collectionName}_revert_${fieldMod.fieldName}`;\n lines.push(generateFieldModification(collectionName, reverseMod, varName));\n lines.push(``);\n }\n }\n\n // Revert field additions (remove them)\n if (modification.fieldsToAdd.length > 0) {\n lines.push(` // Remove added fields from ${collectionName}`);\n for (const field of modification.fieldsToAdd) {\n const varName = `collection_${collectionName}_revert_add_${field.name}`;\n lines.push(generateFieldDeletion(collectionName, field.name, varName));\n lines.push(``);\n }\n }\n }\n }\n\n // 3. Delete created collections\n if (diff.collectionsToCreate.length > 0) {\n lines.push(` // Delete created collections`);\n for (let i = 0; i < diff.collectionsToCreate.length; i++) {\n const collection = diff.collectionsToCreate[i];\n const varName = `collection_${collection.name}_rollback`;\n lines.push(generateCollectionDeletion(collection.name, varName));\n lines.push(``);\n }\n }\n\n // If no changes, add a comment\n if (lines.length === 2) {\n lines.push(` // No changes to revert`);\n lines.push(``);\n }\n\n let code = lines.join(\"\\n\");\n\n // Check if there's already a return statement in the code\n // If so, skip post-processing to avoid duplicate returns\n const hasReturnStatement = /return\\s+app\\.(save|delete)\\(/m.test(code);\n\n if (!hasReturnStatement) {\n // Find the last app.save() or app.delete() call and make it return the result\n // Match app.save(...) or app.delete(...) at the end of lines (not in comments or strings)\n const savePattern = /^(\\s*)app\\.save\\((\\w+)\\);$/gm;\n const deletePattern = /^(\\s*)app\\.delete\\((\\w+)\\);$/gm;\n\n const saveMatches = [...code.matchAll(savePattern)];\n const deleteMatches = [...code.matchAll(deletePattern)];\n\n // Combine all matches and find the last one by position\n const allMatches = [\n ...saveMatches.map((m) => ({ match: m, type: \"save\", index: m.index! })),\n ...deleteMatches.map((m) => ({ match: m, type: \"delete\", index: m.index! })),\n ].sort((a, b) => b.index - a.index); // Sort descending to get last match first\n\n if (allMatches.length > 0) {\n const lastMatch = allMatches[0];\n if (lastMatch.type === \"save\") {\n code =\n code.substring(0, lastMatch.match.index!) +\n lastMatch.match[1] +\n \"return app.save(\" +\n lastMatch.match[2] +\n \");\" +\n code.substring(lastMatch.match.index! + lastMatch.match[0].length);\n } else {\n code =\n code.substring(0, lastMatch.match.index!) +\n lastMatch.match[1] +\n \"return app.delete(\" +\n lastMatch.match[2] +\n \");\" +\n code.substring(lastMatch.match.index! + lastMatch.match[0].length);\n }\n }\n }\n\n return code;\n}\n\n/**\n * Main generation function\n * Generates migration files from schema diff (one file per collection operation)\n *\n * @param diff - Schema diff containing all changes\n * @param config - Migration generator configuration\n * @returns Array of paths to the generated migration files\n */\nexport function generate(diff: SchemaDiff, config: MigrationGeneratorConfig | string): string[] {\n // Support legacy string-only parameter (migration directory)\n const normalizedConfig: MigrationGeneratorConfig = typeof config === \"string\" ? { migrationDir: config } : config;\n\n try {\n const migrationDir = resolveMigrationDir(normalizedConfig);\n\n // Check if there are any changes\n const hasChanges =\n diff.collectionsToCreate.length > 0 || diff.collectionsToModify.length > 0 || diff.collectionsToDelete.length > 0;\n\n // If no changes, return empty array\n if (!hasChanges) {\n return [];\n }\n\n // Build collection ID map from collections being created\n const collectionIdMap = new Map<string, string>();\n for (const collection of diff.collectionsToCreate) {\n if (collection.id) {\n collectionIdMap.set(collection.name, collection.id);\n }\n }\n // Also include deleted collections that might have IDs (for rollback)\n for (const collection of diff.collectionsToDelete) {\n if (collection.id) {\n collectionIdMap.set(collection.name, collection.id);\n }\n }\n\n // Generate base timestamp\n const baseTimestamp = generateTimestamp(normalizedConfig);\n\n // Split diff into individual collection operations\n const operations = splitDiffByCollection(diff, baseTimestamp);\n\n // Generate migration file for each operation\n const filePaths: string[] = [];\n\n for (const operation of operations) {\n // Generate up and down migration code for this operation\n const upCode = generateOperationUpMigration(operation, collectionIdMap);\n const downCode = generateOperationDownMigration(operation, collectionIdMap);\n\n // Create migration file structure\n const content = createMigrationFileStructure(upCode, downCode, normalizedConfig);\n\n // Generate filename for this operation\n const filename = generateCollectionMigrationFilename(operation);\n\n // Write migration file\n const filePath = writeMigrationFile(migrationDir, filename, content);\n\n filePaths.push(filePath);\n }\n\n return filePaths;\n } catch (error) {\n // If it's already a MigrationGenerationError or FileSystemError, re-throw it\n if (error instanceof MigrationGenerationError || error instanceof FileSystemError) {\n throw error;\n }\n\n // Otherwise, wrap it in a MigrationGenerationError\n throw new MigrationGenerationError(\n `Failed to generate migration: ${error instanceof Error ? error.message : String(error)}`,\n normalizedConfig.migrationDir,\n error as Error\n );\n }\n}\n\n/**\n * MigrationGenerator class for object-oriented usage\n * Provides a stateful interface for migration generation\n */\nexport class MigrationGenerator {\n private config: Required<MigrationGeneratorConfig>;\n\n constructor(config: MigrationGeneratorConfig) {\n this.config = mergeConfig(config);\n }\n\n /**\n * Generates migration files from a schema diff\n * Returns array of file paths (one per collection operation)\n */\n generate(diff: SchemaDiff): string[] {\n return generate(diff, this.config);\n }\n\n /**\n * Generates the up migration code without writing to file\n */\n generateUpMigration(diff: SchemaDiff): string {\n return generateUpMigration(diff);\n }\n\n /**\n * Generates the down migration code without writing to file\n */\n generateDownMigration(diff: SchemaDiff): string {\n return generateDownMigration(diff);\n }\n\n /**\n * Generates a migration filename\n */\n generateMigrationFilename(diff: SchemaDiff): string {\n return generateMigrationFilename(diff, this.config);\n }\n}\n","/**\n * PocketBase Format Converter\n * Converts PocketBase collection objects to our internal CollectionSchema format\n *\n * This module handles conversion between PocketBase's native collection format\n * (as found in migration files and snapshots) and our internal schema representation.\n */\n\nimport { SnapshotError } from \"./errors\";\nimport type { CollectionSchema, SchemaSnapshot } from \"./types\";\n\nconst SNAPSHOT_VERSION = \"1.0.0\";\n\n/**\n * Resolves a collection ID to a collection name\n * Uses known constants and parses migration expressions to resolve IDs\n *\n * @param collectionId - The collection ID to resolve\n * @returns The collection name, or the original ID if it can't be resolved\n */\nexport function resolveCollectionIdToName(collectionId: string): string {\n // Special case: _pb_users_auth_ is the constant for users collection\n if (collectionId === \"_pb_users_auth_\") {\n return \"users\";\n }\n\n // Try to extract collection name from expressions like app.findCollectionByNameOrId(\"Name\").id\n const nameMatch = collectionId.match(/app\\.findCollectionByNameOrId\\s*\\(\\s*[\"']([^\"']+)[\"']\\s*\\)/);\n if (nameMatch) {\n return nameMatch[1];\n }\n\n // If we can't resolve it, return the original ID\n // This will cause a comparison issue, but it's better than failing\n return collectionId;\n}\n\n/**\n * Extracts field options from a PocketBase field object\n * Options can be placed directly on the field or in a nested options object\n * Direct properties take precedence over nested options\n *\n * @param pbField - PocketBase field object\n * @returns Merged options object\n */\nfunction extractFieldOptions(pbField: any): Record<string, any> {\n const options: Record<string, any> = {};\n\n // Start with nested options if present\n if (pbField.options && typeof pbField.options === \"object\") {\n Object.assign(options, pbField.options);\n }\n\n // Extract common field options from direct properties\n // These take precedence over nested options\n const directOptionKeys = [\n \"min\",\n \"max\",\n \"pattern\",\n \"noDecimal\", // text/number fields\n \"values\",\n \"maxSelect\", // select fields\n \"mimeTypes\",\n \"maxSize\",\n \"thumbs\",\n \"protected\", // file fields\n \"onCreate\",\n \"onUpdate\", // autodate fields\n \"exceptDomains\",\n \"onlyDomains\", // email/url fields\n ];\n\n for (const key of directOptionKeys) {\n if (pbField[key] !== undefined) {\n options[key] = pbField[key];\n }\n }\n\n return options;\n}\n\n/**\n * Converts a PocketBase collection object to CollectionSchema format\n *\n * @param pbCollection - PocketBase collection object from migration file\n * @returns CollectionSchema object\n */\nexport function convertPocketBaseCollection(pbCollection: any): CollectionSchema {\n const fields: any[] = [];\n\n // System field names that should always be excluded\n const systemFieldNames = [\"id\", \"created\", \"updated\", \"collectionId\", \"collectionName\", \"expand\"];\n\n // Auth collection system field names\n const authSystemFieldNames = [\"email\", \"emailVisibility\", \"verified\", \"password\", \"tokenKey\"];\n\n // Convert PocketBase fields to our FieldDefinition format\n if (pbCollection.fields && Array.isArray(pbCollection.fields)) {\n for (const pbField of pbCollection.fields) {\n // Skip system fields by checking both the system flag and field name\n // Some PocketBase exports mark created/updated as system: false\n if (pbField.system || systemFieldNames.includes(pbField.name)) {\n continue;\n }\n\n // Skip auth system fields for auth collections\n if (pbCollection.type === \"auth\" && authSystemFieldNames.includes(pbField.name)) {\n continue;\n }\n\n const field: any = {\n name: pbField.name,\n type: pbField.type,\n required: pbField.required || false,\n };\n\n // Extract options from both direct properties and nested options object\n field.options = extractFieldOptions(pbField);\n\n // Handle relation fields\n if (pbField.type === \"relation\") {\n // Support both formats: collectionId directly on field or in options\n const collectionId = pbField.collectionId || pbField.options?.collectionId || \"\";\n // Resolve collectionId to collection name\n // collectionId is a system field (like _pb_users_auth_), not the collection name\n // We need to resolve it to the actual collection name for comparison\n const collectionName = resolveCollectionIdToName(collectionId || \"\");\n field.relation = {\n collection: collectionName,\n cascadeDelete: pbField.cascadeDelete ?? pbField.options?.cascadeDelete ?? false,\n maxSelect: pbField.maxSelect ?? pbField.options?.maxSelect,\n minSelect: pbField.minSelect ?? pbField.options?.minSelect,\n };\n\n // Remove relation-specific properties from options\n // These belong in the relation object, not options\n delete field.options.maxSelect;\n delete field.options.minSelect;\n delete field.options.cascadeDelete;\n }\n\n // Clean up empty options object, but preserve values for select fields\n // If options only contains values for a select field, keep it\n const hasOnlyValues = Object.keys(field.options).length === 1 && field.options.values !== undefined;\n if (Object.keys(field.options).length === 0) {\n delete field.options;\n } else if (pbField.type === \"select\" && hasOnlyValues) {\n // Keep options object if it only contains values for a select field\n // This ensures values are preserved for comparison\n }\n\n fields.push(field);\n }\n }\n\n const schema: CollectionSchema = {\n name: pbCollection.name,\n type: pbCollection.type || \"base\",\n fields,\n };\n\n // Preserve collection ID if present (needed for relation resolution)\n if (pbCollection.id) {\n schema.id = pbCollection.id;\n }\n\n // Add indexes if present\n if (pbCollection.indexes && Array.isArray(pbCollection.indexes)) {\n schema.indexes = pbCollection.indexes;\n }\n\n // Add rules/permissions\n // Check if any rule properties exist on the collection object\n const hasAnyRule =\n pbCollection.listRule !== undefined ||\n pbCollection.viewRule !== undefined ||\n pbCollection.createRule !== undefined ||\n pbCollection.updateRule !== undefined ||\n pbCollection.deleteRule !== undefined ||\n pbCollection.manageRule !== undefined;\n\n if (hasAnyRule) {\n const rules: any = {};\n // Include rules even if they're null (null is a valid value)\n if (pbCollection.listRule !== undefined) rules.listRule = pbCollection.listRule;\n if (pbCollection.viewRule !== undefined) rules.viewRule = pbCollection.viewRule;\n if (pbCollection.createRule !== undefined) rules.createRule = pbCollection.createRule;\n if (pbCollection.updateRule !== undefined) rules.updateRule = pbCollection.updateRule;\n if (pbCollection.deleteRule !== undefined) rules.deleteRule = pbCollection.deleteRule;\n if (pbCollection.manageRule !== undefined) rules.manageRule = pbCollection.manageRule;\n\n schema.rules = rules;\n // Also set permissions to match rules (they're the same thing)\n schema.permissions = { ...rules };\n }\n\n return schema;\n}\n\n/**\n * Converts PocketBase migration format to SchemaSnapshot\n * Extracts the snapshot array from the migration file content\n *\n * @param migrationContent - Raw migration file content\n * @returns SchemaSnapshot with collections map\n */\nexport function convertPocketBaseMigration(migrationContent: string): SchemaSnapshot {\n try {\n // Extract the snapshot array from the migration file\n // The format is: migrate((app) => { const snapshot = [...]; ... })\n const snapshotMatch = migrationContent.match(/const\\s+snapshot\\s*=\\s*(\\[[\\s\\S]*?\\]);/);\n\n if (!snapshotMatch) {\n throw new Error(\"Could not find snapshot array in migration file\");\n }\n\n // Parse the snapshot array as JSON\n // We need to evaluate it as JavaScript since it's not pure JSON\n const snapshotArrayStr = snapshotMatch[1];\n let snapshotArray: any[];\n\n try {\n // Use Function constructor to safely evaluate the array\n // This is safer than eval() and works for our use case\n snapshotArray = new Function(`return ${snapshotArrayStr}`)();\n } catch (parseError) {\n throw new Error(`Failed to parse snapshot array: ${parseError}`);\n }\n\n if (!Array.isArray(snapshotArray)) {\n throw new Error(\"Snapshot is not an array\");\n }\n\n // Convert each collection to our format\n const collections = new Map<string, CollectionSchema>();\n\n for (const pbCollection of snapshotArray) {\n if (!pbCollection.name) {\n console.warn(\"Skipping collection without name\");\n continue;\n }\n\n const schema = convertPocketBaseCollection(pbCollection);\n collections.set(pbCollection.name, schema);\n }\n\n return {\n version: SNAPSHOT_VERSION,\n timestamp: new Date().toISOString(),\n collections,\n };\n } catch (error) {\n throw new SnapshotError(\n `Failed to convert PocketBase migration: ${error instanceof Error ? error.message : String(error)}`,\n undefined,\n \"parse\",\n error instanceof Error ? error : undefined\n );\n }\n}\n","/**\n * Migration File Parser\n * Parses PocketBase migration files to extract collection operations\n *\n * This module handles parsing migration files to extract:\n * - Collection creations (new Collection(...))\n * - Collection deletions (app.delete(...))\n * - Field modifications (field.property = value)\n */\n\nimport * as fs from \"fs\";\nimport * as path from \"path\";\nimport { convertPocketBaseCollection } from \"./pocketbase-converter\";\nimport type { CollectionSchema } from \"./types\";\n\n/**\n * Extracts timestamp from migration filename\n * Migration files are named: [timestamp]_[description].js\n *\n * @param filename - Migration filename\n * @returns Timestamp as number or null if not found\n */\nexport function extractTimestampFromFilename(filename: string): number | null {\n const match = filename.match(/^(\\d+)_/);\n if (match) {\n return parseInt(match[1], 10);\n }\n return null;\n}\n\n/**\n * Finds all migration files after a given snapshot timestamp\n * Excludes snapshot files themselves\n *\n * @param migrationsPath - Path to migrations directory\n * @param snapshotTimestamp - Timestamp of the snapshot file\n * @returns Array of migration file paths sorted by timestamp\n */\nexport function findMigrationsAfterSnapshot(migrationsPath: string, snapshotTimestamp: number): string[] {\n try {\n if (!fs.existsSync(migrationsPath)) {\n return [];\n }\n\n const files = fs.readdirSync(migrationsPath);\n const migrationFiles: { path: string; timestamp: number }[] = [];\n\n for (const file of files) {\n // Skip snapshot files\n if (file.endsWith(\"_collections_snapshot.js\") || file.endsWith(\"_snapshot.js\")) {\n continue;\n }\n\n // Skip non-JS files\n if (!file.endsWith(\".js\")) {\n continue;\n }\n\n const timestamp = extractTimestampFromFilename(file);\n if (timestamp && timestamp > snapshotTimestamp) {\n migrationFiles.push({\n path: path.join(migrationsPath, file),\n timestamp,\n });\n }\n }\n\n // Sort by timestamp (ascending order)\n migrationFiles.sort((a, b) => a.timestamp - b.timestamp);\n\n return migrationFiles.map((f) => f.path);\n } catch (error) {\n console.warn(`Error finding migrations after snapshot: ${error}`);\n return [];\n }\n}\n\n/**\n * Helper function to parse collection operations from migration content\n *\n * @param content - Migration content (should be just the UP migration)\n * @returns Object with collections to create and collections to delete\n */\nfunction parseMigrationOperationsFromContent(content: string): {\n collectionsToCreate: CollectionSchema[];\n collectionsToDelete: string[];\n} {\n const collectionsToCreate: CollectionSchema[] = [];\n const collectionsToDelete: string[] = [];\n\n try {\n // Extract collection definitions from `new Collection({...})`\n // Use a more robust approach: find all \"new Collection(\" and then parse until matching closing paren\n let searchIndex = 0;\n while (true) {\n const collectionStart = content.indexOf(\"new Collection(\", searchIndex);\n if (collectionStart === -1) {\n break;\n }\n\n // Find the opening brace after \"new Collection(\"\n const openParen = collectionStart + \"new Collection(\".length;\n let braceCount = 0;\n let parenCount = 1; // We're already inside the opening paren\n let inString = false;\n let stringChar = null;\n let i = openParen;\n\n // Skip whitespace to find the opening brace\n while (i < content.length && /\\s/.test(content[i])) {\n i++;\n }\n\n if (content[i] !== \"{\") {\n searchIndex = i + 1;\n continue;\n }\n\n const objectStart = i;\n braceCount = 1;\n i++;\n\n // Find the matching closing brace and paren\n while (i < content.length && (braceCount > 0 || parenCount > 0)) {\n const char = content[i];\n const prevChar = i > 0 ? content[i - 1] : \"\";\n\n // Handle strings\n if (!inString && (char === '\"' || char === \"'\")) {\n inString = true;\n stringChar = char;\n } else if (inString && char === stringChar && prevChar !== \"\\\\\") {\n inString = false;\n stringChar = null;\n }\n\n if (!inString) {\n if (char === \"{\") braceCount++;\n if (char === \"}\") braceCount--;\n if (char === \"(\") parenCount++;\n if (char === \")\") parenCount--;\n }\n\n i++;\n }\n\n if (braceCount === 0 && parenCount === 0) {\n const objectContent = content.substring(objectStart, i - 1); // -1 to exclude the closing paren\n try {\n // Use Function constructor to parse the JavaScript object\n const collectionObj = new Function(`return ${objectContent}`)();\n if (collectionObj && collectionObj.name) {\n const schema = convertPocketBaseCollection(collectionObj);\n collectionsToCreate.push(schema);\n }\n } catch (error) {\n // Skip malformed collection definitions\n console.warn(`Failed to parse collection definition: ${error}`);\n }\n }\n\n searchIndex = i;\n }\n\n // Extract collection deletions from `app.delete(...)`\n // Look for patterns like: app.delete(collection_xxx) or app.delete(app.findCollectionByNameOrId(\"name\"))\n const deleteMatches = content.matchAll(\n /app\\.delete\\s*\\(\\s*(?:collection_\\w+|app\\.findCollectionByNameOrId\\s*\\(\\s*[\"']([^\"']+)[\"']\\s*\\))\\s*\\)/g\n );\n for (const match of deleteMatches) {\n // If we have a collection name from findCollectionByNameOrId, use it\n if (match[1]) {\n collectionsToDelete.push(match[1]);\n } else {\n // Try to find the collection name from the variable name\n // Look backwards for the collection variable definition\n const varNameMatch = match[0].match(/collection_(\\w+)/);\n if (varNameMatch) {\n // Try to find the collection name from the variable definition\n const varName = `collection_${varNameMatch[1]}`;\n // Search backwards from the delete call to find the variable definition\n const deleteIndex = content.indexOf(match[0]);\n const beforeDelete = content.substring(0, deleteIndex);\n const varDefMatch = beforeDelete.match(\n new RegExp(`const\\\\s+${varName}\\\\s*=\\\\s*new\\\\s+Collection\\\\(\\\\s*(\\\\{[\\\\s\\\\S]*?\\\\})\\\\s*\\\\)`, \"g\")\n );\n if (varDefMatch && varDefMatch.length > 0) {\n // Find the collection definition (get the last match closest to the delete)\n const collectionDefMatch = beforeDelete.match(\n new RegExp(`const\\\\s+${varName}\\\\s*=\\\\s*new\\\\s+Collection\\\\(\\\\s*(\\\\{[\\\\s\\\\S]*?\\\\})\\\\s*\\\\)`)\n );\n if (collectionDefMatch) {\n try {\n const collectionDefStr = collectionDefMatch[1];\n const collectionObj = new Function(`return ${collectionDefStr}`)();\n if (collectionObj && collectionObj.name) {\n collectionsToDelete.push(collectionObj.name);\n }\n } catch {\n // Skip if we can't parse\n }\n }\n }\n }\n }\n }\n\n // Also look for direct collection name in findCollectionByNameOrId followed by delete\n const findAndDeleteMatches = content.matchAll(\n /app\\.findCollectionByNameOrId\\s*\\(\\s*[\"']([^\"']+)[\"']\\s*\\)[\\s\\S]*?app\\.delete/g\n );\n for (const match of findAndDeleteMatches) {\n collectionsToDelete.push(match[1]);\n }\n } catch (error) {\n console.warn(`Failed to parse migration operations from content: ${error}`);\n }\n\n return { collectionsToCreate, collectionsToDelete };\n}\n\n/**\n * Parses a migration file to extract collection operations\n * Extracts collections created with `new Collection(...)` and collections deleted with `app.delete(...)`\n * Only parses the UP migration (first function), not the down migration\n *\n * @param migrationContent - Raw migration file content\n * @returns Object with collections to create and collections to delete\n */\nexport function parseMigrationOperations(migrationContent: string): {\n collectionsToCreate: CollectionSchema[];\n collectionsToDelete: string[];\n} {\n try {\n // Extract only the UP migration (first function argument to migrate())\n // Find the migrate call and extract the first function body\n const migrateMatch = migrationContent.match(/migrate\\s*\\(\\s*/);\n if (!migrateMatch) {\n // If we can't find the migrate pattern, try to parse the whole file\n return parseMigrationOperationsFromContent(migrationContent);\n }\n\n const startIndex = migrateMatch.index! + migrateMatch[0].length;\n\n // Find the opening paren of the first function\n let i = startIndex;\n let parenCount = 0;\n let foundFirstParen = false;\n\n while (i < migrationContent.length) {\n const char = migrationContent[i];\n if (char === \"(\") {\n parenCount++;\n foundFirstParen = true;\n i++;\n break;\n }\n i++;\n }\n\n if (!foundFirstParen) {\n return parseMigrationOperationsFromContent(migrationContent);\n }\n\n // Skip the function parameters: (app) => {\n let inString = false;\n let stringChar = null;\n let foundBrace = false;\n let braceStart = -1;\n\n while (i < migrationContent.length && !foundBrace) {\n const char = migrationContent[i];\n const prevChar = i > 0 ? migrationContent[i - 1] : \"\";\n\n if (!inString && (char === '\"' || char === \"'\")) {\n inString = true;\n stringChar = char;\n } else if (inString && char === stringChar && prevChar !== \"\\\\\") {\n inString = false;\n stringChar = null;\n }\n\n if (!inString) {\n if (char === \"(\") parenCount++;\n if (char === \")\") {\n parenCount--;\n if (parenCount === 0) {\n // Found end of function parameters, look for =>\n i++;\n while (i < migrationContent.length && /\\s/.test(migrationContent[i])) {\n i++;\n }\n if (i < migrationContent.length - 1 && migrationContent[i] === \"=\" && migrationContent[i + 1] === \">\") {\n i += 2;\n while (i < migrationContent.length && /\\s/.test(migrationContent[i])) {\n i++;\n }\n if (i < migrationContent.length && migrationContent[i] === \"{\") {\n foundBrace = true;\n braceStart = i + 1;\n break;\n }\n }\n }\n }\n }\n i++;\n }\n\n if (!foundBrace || braceStart === -1) {\n return parseMigrationOperationsFromContent(migrationContent);\n }\n\n // Find the matching closing brace\n let braceCount = 1;\n i = braceStart;\n inString = false;\n stringChar = null;\n\n while (i < migrationContent.length && braceCount > 0) {\n const char = migrationContent[i];\n const prevChar = i > 0 ? migrationContent[i - 1] : \"\";\n\n if (!inString && (char === '\"' || char === \"'\")) {\n inString = true;\n stringChar = char;\n } else if (inString && char === stringChar && prevChar !== \"\\\\\") {\n inString = false;\n stringChar = null;\n }\n\n if (!inString) {\n if (char === \"{\") braceCount++;\n if (char === \"}\") braceCount--;\n }\n\n i++;\n }\n\n if (braceCount === 0) {\n const upMigrationContent = migrationContent.substring(braceStart, i - 1);\n return parseMigrationOperationsFromContent(upMigrationContent);\n }\n\n // Fallback: parse the whole file\n return parseMigrationOperationsFromContent(migrationContent);\n } catch (error) {\n console.warn(`Failed to parse migration operations: ${error}`);\n return { collectionsToCreate: [], collectionsToDelete: [] };\n }\n}\n","/**\n * Snapshot Manager\n * Handles saving and loading schema snapshots from JSON files\n *\n * This module provides a standalone, configurable snapshot manager that can be used\n * by consumer projects to manage schema snapshots. It focuses on JSON snapshot file\n * management, delegating migration file parsing and PocketBase format conversion\n * to specialized modules.\n */\n\nimport * as fs from \"fs\";\nimport * as path from \"path\";\nimport { FileSystemError, SnapshotError } from \"./errors\";\nimport {\n extractTimestampFromFilename,\n findMigrationsAfterSnapshot,\n parseMigrationOperations,\n} from \"./migration-parser\";\nimport { convertPocketBaseMigration } from \"./pocketbase-converter\";\nimport type { CollectionSchema, SchemaDefinition, SchemaSnapshot } from \"./types\";\n\nconst SNAPSHOT_VERSION = \"1.0.0\";\nconst DEFAULT_SNAPSHOT_FILENAME = \".migration-snapshot.json\";\n\n/**\n * Configuration for snapshot operations\n */\nexport interface SnapshotConfig {\n /**\n * Path to the snapshot file\n * Can be absolute or relative to workspaceRoot\n */\n snapshotPath?: string;\n\n /**\n * Workspace root directory for resolving relative paths\n * Defaults to process.cwd()\n */\n workspaceRoot?: string;\n\n /**\n * Path to the migrations directory for finding PocketBase snapshots\n */\n migrationsPath?: string;\n\n /**\n * Whether to auto-migrate old snapshot formats\n * Defaults to true\n */\n autoMigrate?: boolean;\n\n /**\n * Custom snapshot version for testing\n */\n version?: string;\n}\n\n/**\n * Snapshot format versions and their migration functions\n */\ninterface SnapshotMigration {\n fromVersion: string;\n toVersion: string;\n migrate: (data: any) => any;\n}\n\n/**\n * Registry of snapshot format migrations\n */\nconst SNAPSHOT_MIGRATIONS: SnapshotMigration[] = [\n // Add migrations here as the format evolves\n // Example:\n // {\n // fromVersion: '0.9.0',\n // toVersion: '1.0.0',\n // migrate: (data) => ({ ...data, newField: 'default' })\n // }\n];\n\n/**\n * Default configuration values\n */\nconst DEFAULT_CONFIG: Omit<Required<SnapshotConfig>, \"migrationsPath\"> & { migrationsPath?: string } = {\n snapshotPath: DEFAULT_SNAPSHOT_FILENAME,\n workspaceRoot: process.cwd(),\n autoMigrate: true,\n version: SNAPSHOT_VERSION,\n};\n\n/**\n * Merges user config with defaults\n */\nfunction mergeConfig(config: SnapshotConfig = {}): typeof DEFAULT_CONFIG {\n return {\n ...DEFAULT_CONFIG,\n ...config,\n };\n}\n\n/**\n * Gets the snapshot file path from configuration\n *\n * @param config - Snapshot configuration\n * @returns Absolute path to the snapshot file\n */\nexport function getSnapshotPath(config: SnapshotConfig = {}): string {\n const mergedConfig = mergeConfig(config);\n const workspaceRoot = mergedConfig.workspaceRoot;\n const snapshotFilename = mergedConfig.snapshotPath;\n\n // If snapshotPath is absolute, use it directly\n if (path.isAbsolute(snapshotFilename)) {\n return snapshotFilename;\n }\n\n // Otherwise, resolve relative to workspaceRoot\n return path.join(workspaceRoot, snapshotFilename);\n}\n\n/**\n * Checks if snapshot file exists\n *\n * @param config - Snapshot configuration\n * @returns True if snapshot file exists\n */\nexport function snapshotExists(config: SnapshotConfig = {}): boolean {\n try {\n const snapshotPath = getSnapshotPath(config);\n return fs.existsSync(snapshotPath);\n } catch {\n // If there's any error checking existence, treat as non-existent\n return false;\n }\n}\n\n/**\n * Handles file system errors with descriptive messages\n *\n * @param error - The error object\n * @param operation - The operation being performed\n * @param filePath - The file path involved\n * @throws SnapshotError or FileSystemError with descriptive message\n */\nfunction handleFileSystemError(error: any, operation: \"read\" | \"write\", filePath: string): never {\n const fsError = error as NodeJS.ErrnoException;\n\n if (fsError.code === \"ENOENT\") {\n throw new SnapshotError(`Snapshot file not found: ${filePath}`, filePath, operation, error);\n } else if (fsError.code === \"EACCES\" || fsError.code === \"EPERM\") {\n throw new FileSystemError(\n `Permission denied ${operation === \"read\" ? \"reading\" : \"writing\"} snapshot file. Check file permissions.`,\n filePath,\n operation,\n fsError.code,\n error\n );\n } else if (fsError.code === \"ENOSPC\") {\n throw new FileSystemError(\n `No space left on device when ${operation === \"read\" ? \"reading\" : \"writing\"} snapshot file.`,\n filePath,\n operation,\n fsError.code,\n error\n );\n } else {\n throw new SnapshotError(`Failed to ${operation} snapshot file: ${error.message}`, filePath, operation, error);\n }\n}\n\n/**\n * Serializes a Map to a plain object for JSON serialization\n *\n * @param map - Map to serialize\n * @returns Plain object representation\n */\nfunction serializeMap<K extends string, V>(map: Map<K, V>): Record<K, V> {\n const obj: Record<string, V> = {};\n for (const [key, value] of map.entries()) {\n obj[key] = value;\n }\n return obj as Record<K, V>;\n}\n\n/**\n * Deserializes a plain object to a Map\n *\n * @param obj - Plain object to deserialize\n * @returns Map representation\n */\nfunction deserializeMap<K extends string, V>(obj: Record<K, V>): Map<K, V> {\n const map = new Map<K, V>();\n for (const [key, value] of Object.entries(obj)) {\n map.set(key as K, value as V);\n }\n return map;\n}\n\n/**\n * Serializes SchemaDefinition to JSON format\n * Converts Map to plain object for JSON compatibility\n *\n * @param schema - Schema definition to serialize\n * @returns JSON-serializable object\n */\nfunction serializeSchemaDefinition(schema: SchemaDefinition): any {\n return {\n collections: serializeMap(schema.collections),\n };\n}\n\n/**\n * Adds version and timestamp metadata to snapshot\n *\n * @param schema - Schema definition\n * @param config - Optional configuration with custom version\n * @returns Snapshot with metadata\n */\nfunction addSnapshotMetadata(schema: SchemaDefinition, config?: SnapshotConfig): any {\n const mergedConfig = mergeConfig(config);\n return {\n version: mergedConfig.version,\n timestamp: new Date().toISOString(),\n ...serializeSchemaDefinition(schema),\n };\n}\n\n/**\n * Saves schema snapshot to file\n * Serializes SchemaDefinition to JSON with version and timestamp metadata\n * Writes with pretty printing for readability\n *\n * @param schema - Schema definition to save\n * @param config - Snapshot configuration\n */\nexport function saveSnapshot(schema: SchemaDefinition, config: SnapshotConfig = {}): void {\n const snapshotPath = getSnapshotPath(config);\n\n try {\n // Ensure directory exists\n const snapshotDir = path.dirname(snapshotPath);\n if (!fs.existsSync(snapshotDir)) {\n fs.mkdirSync(snapshotDir, { recursive: true });\n }\n\n // Add metadata and serialize\n const snapshotData = addSnapshotMetadata(schema, config);\n\n // Write with pretty printing (2 spaces indentation)\n const jsonContent = JSON.stringify(snapshotData, null, 2);\n fs.writeFileSync(snapshotPath, jsonContent, \"utf-8\");\n } catch (error) {\n handleFileSystemError(error, \"write\", snapshotPath);\n }\n}\n\n/**\n * Parses JSON and validates snapshot format\n *\n * @param jsonContent - Raw JSON content\n * @param snapshotPath - Path to snapshot file (for error messages)\n * @returns Parsed snapshot data\n */\nfunction parseAndValidateSnapshot(jsonContent: string, snapshotPath: string): any {\n try {\n const data = JSON.parse(jsonContent);\n\n // Validate required fields\n if (!data.version) {\n throw new SnapshotError(\n \"Snapshot file is missing version field. The snapshot may be corrupted.\",\n snapshotPath,\n \"validate\"\n );\n }\n\n if (!data.timestamp) {\n throw new SnapshotError(\n \"Snapshot file is missing timestamp field. The snapshot may be corrupted.\",\n snapshotPath,\n \"validate\"\n );\n }\n\n if (!data.collections) {\n throw new SnapshotError(\n \"Snapshot file is missing collections field. The snapshot may be corrupted.\",\n snapshotPath,\n \"validate\"\n );\n }\n\n return data;\n } catch (error) {\n if (error instanceof SnapshotError) {\n throw error;\n }\n\n if (error instanceof SyntaxError) {\n throw new SnapshotError(\n `Invalid JSON in snapshot file. The file may be corrupted or manually edited incorrectly.`,\n snapshotPath,\n \"parse\",\n error\n );\n }\n throw error;\n }\n}\n\n/**\n * Compares two version strings\n * Returns -1 if a < b, 0 if a == b, 1 if a > b\n */\nfunction compareVersions(a: string, b: string): number {\n const partsA = a.split(\".\").map(Number);\n const partsB = b.split(\".\").map(Number);\n\n for (let i = 0; i < Math.max(partsA.length, partsB.length); i++) {\n const numA = partsA[i] || 0;\n const numB = partsB[i] || 0;\n\n if (numA < numB) return -1;\n if (numA > numB) return 1;\n }\n\n return 0;\n}\n\n/**\n * Migrates old snapshot formats to current version\n * Applies migrations in sequence from old version to current\n *\n * @param data - Parsed snapshot data\n * @param config - Optional configuration\n * @returns Migrated snapshot data\n */\nfunction migrateSnapshotFormat(data: any, config?: SnapshotConfig): any {\n const mergedConfig = mergeConfig(config);\n const currentVersion = data.version;\n const targetVersion = mergedConfig.version;\n\n // If versions match, no migration needed\n if (currentVersion === targetVersion) {\n return data;\n }\n\n // If auto-migrate is disabled, just return the data with a warning\n if (!mergedConfig.autoMigrate) {\n console.warn(\n `Snapshot version ${currentVersion} differs from current ${targetVersion}, but auto-migrate is disabled.`\n );\n return data;\n }\n\n // Find and apply migrations in sequence\n let migratedData = { ...data };\n let currentMigrationVersion = currentVersion;\n\n // Sort migrations by fromVersion\n const sortedMigrations = [...SNAPSHOT_MIGRATIONS].sort((a, b) => compareVersions(a.fromVersion, b.fromVersion));\n\n for (const migration of sortedMigrations) {\n if (compareVersions(currentMigrationVersion, migration.fromVersion) === 0) {\n console.log(`Migrating snapshot from ${migration.fromVersion} to ${migration.toVersion}...`);\n migratedData = migration.migrate(migratedData);\n migratedData.version = migration.toVersion;\n currentMigrationVersion = migration.toVersion;\n }\n }\n\n // If we couldn't migrate to the target version, log a warning\n if (compareVersions(currentMigrationVersion, targetVersion) !== 0) {\n console.warn(`Unknown snapshot version ${currentVersion}, attempting to load anyway...`);\n }\n\n return migratedData;\n}\n\n/**\n * Deserializes snapshot data to SchemaSnapshot\n *\n * @param data - Parsed and validated snapshot data\n * @returns SchemaSnapshot object\n */\nfunction deserializeSnapshot(data: any): SchemaSnapshot {\n return {\n version: data.version,\n timestamp: data.timestamp,\n collections: deserializeMap<string, CollectionSchema>(data.collections),\n };\n}\n\n/**\n * Loads schema snapshot from file\n * Reads snapshot file, parses JSON, validates format, and handles migrations\n *\n * @param config - Snapshot configuration\n * @returns SchemaSnapshot object\n * @throws Error if snapshot file doesn't exist or is invalid\n */\nexport function loadSnapshot(config: SnapshotConfig = {}): SchemaSnapshot {\n const snapshotPath = getSnapshotPath(config);\n\n try {\n // Read file\n const jsonContent = fs.readFileSync(snapshotPath, \"utf-8\");\n\n // Parse and validate\n const data = parseAndValidateSnapshot(jsonContent, snapshotPath);\n\n // Migrate format if needed\n const migratedData = migrateSnapshotFormat(data, config);\n\n // Deserialize to SchemaSnapshot\n return deserializeSnapshot(migratedData);\n } catch (error) {\n // If it's already a SnapshotError or FileSystemError, re-throw it\n if (error instanceof SnapshotError || error instanceof FileSystemError) {\n throw error;\n }\n\n // If file doesn't exist, throw specific error\n if ((error as any).code === \"ENOENT\") {\n throw new SnapshotError(\n `Snapshot file not found. This may be the first migration run.`,\n snapshotPath,\n \"read\",\n error as Error\n );\n }\n\n // Handle other file system errors\n handleFileSystemError(error, \"read\", snapshotPath);\n }\n}\n\n/**\n * Merges base schema with custom snapshot\n * Base schema collections are preserved, custom collections are added\n * Custom collections override base collections if they have the same name\n *\n * @param baseSnapshot - PocketBase base schema\n * @param customSnapshot - User's custom schema snapshot (may be null)\n * @returns Merged SchemaSnapshot\n */\nexport function mergeSnapshots(baseSnapshot: SchemaSnapshot, customSnapshot: SchemaSnapshot | null): SchemaSnapshot {\n // If no custom snapshot, return base snapshot\n if (!customSnapshot) {\n return baseSnapshot;\n }\n\n // Create a new collections map starting with base collections\n const mergedCollections = new Map<string, CollectionSchema>(baseSnapshot.collections);\n\n // Add or override with custom collections\n for (const [name, schema] of customSnapshot.collections.entries()) {\n mergedCollections.set(name, schema);\n }\n\n return {\n version: customSnapshot.version || baseSnapshot.version,\n timestamp: customSnapshot.timestamp || baseSnapshot.timestamp,\n collections: mergedCollections,\n };\n}\n\n/**\n * Finds the most recent snapshot file in the migrations directory\n * Identifies snapshot files by naming pattern (e.g., *_collections_snapshot.js)\n *\n * @param migrationsPath - Path to pb_migrations directory\n * @returns Path to most recent snapshot file or null if none exist\n */\nexport function findLatestSnapshot(migrationsPath: string): string | null {\n try {\n // Check if migrations directory exists\n if (!fs.existsSync(migrationsPath)) {\n return null;\n }\n\n // Read all files in migrations directory\n const files = fs.readdirSync(migrationsPath);\n\n // Filter for snapshot files (files ending with _collections_snapshot.js or _snapshot.js)\n const snapshotFiles = files.filter(\n (file) => file.endsWith(\"_collections_snapshot.js\") || file.endsWith(\"_snapshot.js\")\n );\n\n if (snapshotFiles.length === 0) {\n return null;\n }\n\n // Sort by filename (timestamp prefix) to get most recent\n // Snapshot files are named with timestamp prefix: [timestamp]_collections_snapshot.js\n snapshotFiles.sort().reverse();\n\n // Return full path to most recent snapshot\n const latestSnapshot = snapshotFiles[0];\n if (!latestSnapshot) {\n return null;\n }\n return path.join(migrationsPath, latestSnapshot);\n } catch (error) {\n // If there's any error reading directory, return null\n console.warn(`Error finding latest snapshot: ${error}`);\n return null;\n }\n}\n\n/**\n * Applies migration operations to a snapshot state\n * Creates new collections and deletes collections as specified\n *\n * @param snapshot - Base snapshot state\n * @param operations - Migration operations to apply\n * @returns Updated snapshot with operations applied\n */\nfunction applyMigrationOperations(\n snapshot: SchemaSnapshot,\n operations: { collectionsToCreate: CollectionSchema[]; collectionsToDelete: string[] }\n): SchemaSnapshot {\n const updatedCollections = new Map(snapshot.collections);\n\n // Apply deletions first\n for (const collectionName of operations.collectionsToDelete) {\n updatedCollections.delete(collectionName);\n }\n\n // Apply creations/updates\n for (const collection of operations.collectionsToCreate) {\n updatedCollections.set(collection.name, collection);\n }\n\n return {\n ...snapshot,\n collections: updatedCollections,\n };\n}\n\n/**\n * Loads snapshot and applies all migrations that come after it\n * This gives us the current state of the database schema\n *\n * @param config - Snapshot configuration (must include migrationsPath)\n * @returns SchemaSnapshot object representing current state or null if snapshot doesn't exist\n */\nexport function loadSnapshotWithMigrations(config: SnapshotConfig = {}): SchemaSnapshot | null {\n const migrationsPath = config.migrationsPath;\n\n if (!migrationsPath) {\n return null;\n }\n\n // Check if migrationsPath is actually a file (for backward compatibility with tests)\n if (fs.existsSync(migrationsPath) && fs.statSync(migrationsPath).isFile()) {\n try {\n const migrationContent = fs.readFileSync(migrationsPath, \"utf-8\");\n return convertPocketBaseMigration(migrationContent);\n } catch (error) {\n console.warn(`Failed to load snapshot from ${migrationsPath}: ${error}`);\n return null;\n }\n }\n\n // It's a directory, find the latest snapshot\n const latestSnapshotPath = findLatestSnapshot(migrationsPath);\n\n if (!latestSnapshotPath) {\n // No snapshot found - return null (empty database)\n return null;\n }\n\n try {\n // Read and convert the PocketBase snapshot file\n const migrationContent = fs.readFileSync(latestSnapshotPath, \"utf-8\");\n let snapshot = convertPocketBaseMigration(migrationContent);\n\n // Extract timestamp from snapshot filename\n const snapshotFilename = path.basename(latestSnapshotPath);\n const snapshotTimestamp = extractTimestampFromFilename(snapshotFilename);\n\n if (snapshotTimestamp) {\n // Find all migration files after the snapshot\n const migrationFiles = findMigrationsAfterSnapshot(migrationsPath, snapshotTimestamp);\n\n // Apply each migration in order\n for (const migrationFile of migrationFiles) {\n try {\n const migrationContent = fs.readFileSync(migrationFile, \"utf-8\");\n const operations = parseMigrationOperations(migrationContent);\n snapshot = applyMigrationOperations(snapshot, operations);\n } catch (error) {\n console.warn(`Failed to apply migration ${migrationFile}: ${error}`);\n // Continue with other migrations even if one fails\n }\n }\n }\n\n return snapshot;\n } catch (error) {\n console.warn(`Failed to load snapshot from ${latestSnapshotPath}: ${error}`);\n return null;\n }\n}\n\n/**\n * Loads snapshot if it exists, returns null for first run\n * Convenience method that handles missing snapshot gracefully\n * Finds the most recent snapshot file from migrations directory\n * NOTE: This function only loads the snapshot, not migrations after it.\n * Use loadSnapshotWithMigrations() if you need the current state including migrations.\n *\n * @param config - Snapshot configuration (must include migrationsPath)\n * @returns SchemaSnapshot object or null if snapshot doesn't exist\n */\nexport function loadSnapshotIfExists(config: SnapshotConfig = {}): SchemaSnapshot | null {\n const migrationsPath = config.migrationsPath;\n\n if (!migrationsPath) {\n // No migrations path provided - return null\n return null;\n }\n\n // Check if migrationsPath is actually a file (for backward compatibility with tests)\n // If it's a file, treat it as a direct snapshot file path\n if (fs.existsSync(migrationsPath) && fs.statSync(migrationsPath).isFile()) {\n try {\n const migrationContent = fs.readFileSync(migrationsPath, \"utf-8\");\n return convertPocketBaseMigration(migrationContent);\n } catch (error) {\n console.warn(`Failed to load snapshot from ${migrationsPath}: ${error}`);\n return null;\n }\n }\n\n // It's a directory, find the latest snapshot\n const latestSnapshotPath = findLatestSnapshot(migrationsPath);\n\n if (latestSnapshotPath) {\n try {\n // Read and convert the PocketBase snapshot file\n const migrationContent = fs.readFileSync(latestSnapshotPath, \"utf-8\");\n return convertPocketBaseMigration(migrationContent);\n } catch (error) {\n console.warn(`Failed to load snapshot from ${latestSnapshotPath}: ${error}`);\n return null;\n }\n }\n\n // No snapshot found - return null (empty database)\n return null;\n}\n\n/**\n * Loads the base PocketBase schema from the initial migration file\n *\n * @param migrationPath - Path to pocketbase/pb_migrations/000000000_collections_snapshot.js\n * @returns SchemaSnapshot representing PocketBase's initial state\n * @throws SnapshotError if file not found or invalid format\n */\nexport function loadBaseMigration(migrationPath: string): SchemaSnapshot {\n try {\n // Check if file exists\n if (!fs.existsSync(migrationPath)) {\n throw new SnapshotError(\n `Base migration file not found: ${migrationPath}\\n\\n` +\n `This file should contain PocketBase's initial schema.\\n` +\n `Please ensure PocketBase is properly set up by running 'yarn setup'.\\n` +\n `If the file exists in a different location, update the configuration.`,\n migrationPath,\n \"read\"\n );\n }\n\n // Read the migration file\n const migrationContent = fs.readFileSync(migrationPath, \"utf-8\");\n\n // Convert to SchemaSnapshot\n const snapshot = convertPocketBaseMigration(migrationContent);\n\n return snapshot;\n } catch (error) {\n // If it's already a SnapshotError, re-throw it\n if (error instanceof SnapshotError) {\n throw error;\n }\n\n // Handle file system errors\n if ((error as any).code === \"ENOENT\") {\n throw new SnapshotError(\n `Base migration file not found: ${migrationPath}\\n\\n` +\n `This file should contain PocketBase's initial schema.\\n` +\n `Please ensure PocketBase is properly set up by running 'yarn setup'.`,\n migrationPath,\n \"read\",\n error as Error\n );\n }\n\n if ((error as any).code === \"EACCES\" || (error as any).code === \"EPERM\") {\n throw new FileSystemError(\n `Permission denied reading base migration file. Check file permissions.`,\n migrationPath,\n \"read\",\n (error as any).code,\n error as Error\n );\n }\n\n // Other errors\n throw new SnapshotError(\n `Failed to load base migration: ${error instanceof Error ? error.message : String(error)}`,\n migrationPath,\n \"read\",\n error instanceof Error ? error : undefined\n );\n }\n}\n\n/**\n * Gets the current snapshot version\n */\nexport function getSnapshotVersion(): string {\n return SNAPSHOT_VERSION;\n}\n\n/**\n * Validates a snapshot against the current version\n * Returns validation result with any issues found\n */\nexport function validateSnapshot(snapshot: SchemaSnapshot): { valid: boolean; issues: string[] } {\n const issues: string[] = [];\n\n // Check version\n if (!snapshot.version) {\n issues.push(\"Missing version field\");\n } else if (compareVersions(snapshot.version, SNAPSHOT_VERSION) > 0) {\n issues.push(`Snapshot version ${snapshot.version} is newer than supported version ${SNAPSHOT_VERSION}`);\n }\n\n // Check timestamp\n if (!snapshot.timestamp) {\n issues.push(\"Missing timestamp field\");\n }\n\n // Check collections\n if (!snapshot.collections) {\n issues.push(\"Missing collections field\");\n } else if (!(snapshot.collections instanceof Map)) {\n issues.push(\"Collections field is not a Map\");\n }\n\n return {\n valid: issues.length === 0,\n issues,\n };\n}\n\n/**\n * Re-exports convertPocketBaseMigration for backward compatibility\n */\nexport { convertPocketBaseMigration } from \"./pocketbase-converter\";\n\n/**\n * SnapshotManager class for object-oriented usage\n * Provides a stateful interface for snapshot management\n */\nexport class SnapshotManager {\n private config: SnapshotConfig;\n\n constructor(config: SnapshotConfig = {}) {\n this.config = mergeConfig(config);\n }\n\n /**\n * Loads the current snapshot\n */\n loadSnapshot(): SchemaSnapshot {\n return loadSnapshot(this.config);\n }\n\n /**\n * Saves a schema as a snapshot\n */\n saveSnapshot(schema: SchemaDefinition): void {\n saveSnapshot(schema, this.config);\n }\n\n /**\n * Loads snapshot if it exists, returns null otherwise\n */\n loadSnapshotIfExists(): SchemaSnapshot | null {\n return loadSnapshotIfExists(this.config);\n }\n\n /**\n * Checks if a snapshot exists\n */\n snapshotExists(): boolean {\n return snapshotExists(this.config);\n }\n\n /**\n * Converts a PocketBase migration to a snapshot\n */\n convertPocketBaseMigration(content: string): SchemaSnapshot {\n return convertPocketBaseMigration(content);\n }\n\n /**\n * Gets the snapshot file path\n */\n getSnapshotPath(): string {\n return getSnapshotPath(this.config);\n }\n\n /**\n * Validates a snapshot\n */\n validateSnapshot(snapshot: SchemaSnapshot): { valid: boolean; issues: string[] } {\n return validateSnapshot(snapshot);\n }\n}\n","/**\n * Validation and warning utilities for migration tool\n * Detects destructive changes and provides warnings\n */\n\nimport type { SchemaDiff } from \"./types\";\n\n/**\n * Types of destructive changes\n */\nexport enum DestructiveChangeType {\n COLLECTION_DELETION = \"collection_deletion\",\n FIELD_DELETION = \"field_deletion\",\n FIELD_TYPE_CHANGE = \"field_type_change\",\n FIELD_REQUIRED_CHANGE = \"field_required_change\",\n}\n\n/**\n * Represents a destructive change with details\n */\nexport interface DestructiveChange {\n type: DestructiveChangeType;\n description: string;\n collection: string;\n field?: string;\n details?: {\n oldValue?: any;\n newValue?: any;\n };\n severity: \"high\" | \"medium\" | \"low\";\n warning: string;\n}\n\n/**\n * Detects collection deletions\n *\n * @param diff - Schema diff\n * @returns Array of destructive changes for collection deletions\n */\nfunction detectCollectionDeletions(diff: SchemaDiff): DestructiveChange[] {\n const changes: DestructiveChange[] = [];\n\n for (const collection of diff.collectionsToDelete) {\n changes.push({\n type: DestructiveChangeType.COLLECTION_DELETION,\n description: `Delete collection: ${collection.name}`,\n collection: collection.name,\n severity: \"high\",\n warning: `All data in the \"${collection.name}\" collection will be permanently deleted.`,\n });\n }\n\n return changes;\n}\n\n/**\n * Detects field deletions\n *\n * @param diff - Schema diff\n * @returns Array of destructive changes for field deletions\n */\nfunction detectFieldDeletions(diff: SchemaDiff): DestructiveChange[] {\n const changes: DestructiveChange[] = [];\n\n for (const modification of diff.collectionsToModify) {\n for (const field of modification.fieldsToRemove) {\n changes.push({\n type: DestructiveChangeType.FIELD_DELETION,\n description: `Delete field: ${modification.collection}.${field.name}`,\n collection: modification.collection,\n field: field.name,\n severity: \"high\",\n warning: `All data in the \"${field.name}\" field of \"${modification.collection}\" will be permanently deleted.`,\n });\n }\n }\n\n return changes;\n}\n\n/**\n * Detects field type changes\n *\n * @param diff - Schema diff\n * @returns Array of destructive changes for field type changes\n */\nfunction detectFieldTypeChanges(diff: SchemaDiff): DestructiveChange[] {\n const changes: DestructiveChange[] = [];\n\n for (const modification of diff.collectionsToModify) {\n for (const fieldMod of modification.fieldsToModify) {\n const typeChange = fieldMod.changes.find((c) => c.property === \"type\");\n\n if (typeChange) {\n changes.push({\n type: DestructiveChangeType.FIELD_TYPE_CHANGE,\n description: `Change field type: ${modification.collection}.${fieldMod.fieldName}`,\n collection: modification.collection,\n field: fieldMod.fieldName,\n details: {\n oldValue: typeChange.oldValue,\n newValue: typeChange.newValue,\n },\n severity: \"high\",\n warning: `Changing field type from \"${typeChange.oldValue}\" to \"${typeChange.newValue}\" may cause data loss or conversion errors.`,\n });\n }\n }\n }\n\n return changes;\n}\n\n/**\n * Detects field required changes (making optional field required)\n *\n * @param diff - Schema diff\n * @returns Array of destructive changes for required field changes\n */\nfunction detectFieldRequiredChanges(diff: SchemaDiff): DestructiveChange[] {\n const changes: DestructiveChange[] = [];\n\n for (const modification of diff.collectionsToModify) {\n for (const fieldMod of modification.fieldsToModify) {\n const requiredChange = fieldMod.changes.find(\n (c) => c.property === \"required\" && c.newValue === true && c.oldValue === false\n );\n\n if (requiredChange) {\n changes.push({\n type: DestructiveChangeType.FIELD_REQUIRED_CHANGE,\n description: `Make field required: ${modification.collection}.${fieldMod.fieldName}`,\n collection: modification.collection,\n field: fieldMod.fieldName,\n details: {\n oldValue: false,\n newValue: true,\n },\n severity: \"medium\",\n warning: `Making \"${fieldMod.fieldName}\" required may cause issues with existing records that have null/empty values.`,\n });\n }\n }\n }\n\n return changes;\n}\n\n/**\n * Detects all destructive changes in a schema diff\n *\n * @param diff - Schema diff to analyze\n * @returns Array of all destructive changes\n */\nexport function detectDestructiveChanges(diff: SchemaDiff): DestructiveChange[] {\n const changes: DestructiveChange[] = [];\n\n // Detect collection deletions\n changes.push(...detectCollectionDeletions(diff));\n\n // Detect field deletions\n changes.push(...detectFieldDeletions(diff));\n\n // Detect field type changes\n changes.push(...detectFieldTypeChanges(diff));\n\n // Detect field required changes\n changes.push(...detectFieldRequiredChanges(diff));\n\n return changes;\n}\n\n/**\n * Checks if a diff contains any destructive changes\n *\n * @param diff - Schema diff to check\n * @returns True if there are destructive changes\n */\nexport function hasDestructiveChanges(diff: SchemaDiff): boolean {\n const changes = detectDestructiveChanges(diff);\n return changes.length > 0;\n}\n\n/**\n * Formats destructive changes for display\n * Groups changes by severity and provides clear warnings\n *\n * @param changes - Array of destructive changes\n * @returns Formatted string for display\n */\nexport function formatDestructiveChanges(changes: DestructiveChange[]): string {\n if (changes.length === 0) {\n return \"No destructive changes detected.\";\n }\n\n const lines: string[] = [];\n\n // Group by severity\n const highSeverity = changes.filter((c) => c.severity === \"high\");\n const mediumSeverity = changes.filter((c) => c.severity === \"medium\");\n const lowSeverity = changes.filter((c) => c.severity === \"low\");\n\n // Display high severity changes\n if (highSeverity.length > 0) {\n lines.push(\"🔴 HIGH SEVERITY CHANGES (Data Loss Risk):\");\n lines.push(\"\");\n for (const change of highSeverity) {\n lines.push(` • ${change.description}`);\n lines.push(` ⚠️ ${change.warning}`);\n if (change.details) {\n if (change.details.oldValue !== undefined && change.details.newValue !== undefined) {\n lines.push(` Old: ${change.details.oldValue} → New: ${change.details.newValue}`);\n }\n }\n lines.push(\"\");\n }\n }\n\n // Display medium severity changes\n if (mediumSeverity.length > 0) {\n lines.push(\"🟡 MEDIUM SEVERITY CHANGES (Potential Issues):\");\n lines.push(\"\");\n for (const change of mediumSeverity) {\n lines.push(` • ${change.description}`);\n lines.push(` ⚠️ ${change.warning}`);\n if (change.details) {\n if (change.details.oldValue !== undefined && change.details.newValue !== undefined) {\n lines.push(` Old: ${change.details.oldValue} → New: ${change.details.newValue}`);\n }\n }\n lines.push(\"\");\n }\n }\n\n // Display low severity changes\n if (lowSeverity.length > 0) {\n lines.push(\"🟢 LOW SEVERITY CHANGES:\");\n lines.push(\"\");\n for (const change of lowSeverity) {\n lines.push(` • ${change.description}`);\n lines.push(` ℹ️ ${change.warning}`);\n lines.push(\"\");\n }\n }\n\n return lines.join(\"\\n\");\n}\n\n/**\n * Generates a summary of destructive changes\n *\n * @param changes - Array of destructive changes\n * @returns Summary object with counts by severity\n */\nexport function summarizeDestructiveChanges(changes: DestructiveChange[]): {\n total: number;\n high: number;\n medium: number;\n low: number;\n} {\n return {\n total: changes.length,\n high: changes.filter((c) => c.severity === \"high\").length,\n medium: changes.filter((c) => c.severity === \"medium\").length,\n low: changes.filter((c) => c.severity === \"low\").length,\n };\n}\n\n/**\n * Checks if force flag is required for the given changes\n * Force is required if there are any high or medium severity changes\n *\n * @param changes - Array of destructive changes\n * @returns True if force flag should be required\n */\nexport function requiresForceFlag(changes: DestructiveChange[]): boolean {\n return changes.some((c) => c.severity === \"high\" || c.severity === \"medium\");\n}\n","/**\n * Configuration loader for migration tool\n * Handles loading and merging configuration from various sources\n */\n\nimport * as fs from \"fs\";\nimport * as path from \"path\";\nimport { ConfigurationError } from \"../../migration/errors.js\";\n\n/**\n * Migration tool configuration\n */\nexport interface MigrationConfig {\n schema: {\n directory: string;\n exclude: string[];\n };\n migrations: {\n directory: string;\n format: string;\n };\n diff: {\n warnOnDelete: boolean;\n requireForceForDestructive: boolean;\n };\n}\n\n/**\n * Partial configuration for merging\n */\nexport type PartialMigrationConfig = {\n schema?: Partial<MigrationConfig[\"schema\"]>;\n migrations?: Partial<MigrationConfig[\"migrations\"]>;\n diff?: Partial<MigrationConfig[\"diff\"]>;\n};\n\n/**\n * Configuration file names to search for\n */\nconst CONFIG_FILE_NAMES = [\n \"pocketbase-migrate.config.js\",\n \"pocketbase-migrate.config.mjs\",\n \"pocketbase-migrate.config.json\",\n \"migrate.config.js\",\n \"migrate.config.mjs\",\n \"migrate.config.json\",\n];\n\n/**\n * Default configuration values\n */\nconst DEFAULT_CONFIG: MigrationConfig = {\n schema: {\n directory: \"src/schema\",\n exclude: [\"base.ts\", \"index.ts\", \"permissions.ts\", \"permission-templates.ts\"],\n },\n migrations: {\n directory: \"pocketbase/pb_migrations\",\n format: \"timestamp_description\",\n },\n diff: {\n warnOnDelete: true,\n requireForceForDestructive: true,\n },\n};\n\n/**\n * Finds a configuration file in the given directory\n */\nfunction findConfigFile(directory: string): string | null {\n for (const fileName of CONFIG_FILE_NAMES) {\n const filePath = path.join(directory, fileName);\n if (fs.existsSync(filePath)) {\n return filePath;\n }\n }\n return null;\n}\n\n/**\n * Loads configuration from a JSON file\n */\nfunction loadJsonConfig(configPath: string): PartialMigrationConfig {\n try {\n const content = fs.readFileSync(configPath, \"utf-8\");\n return JSON.parse(content);\n } catch (error) {\n if (error instanceof SyntaxError) {\n throw new ConfigurationError(\"Invalid JSON syntax in configuration file\", configPath, undefined, error);\n }\n throw new ConfigurationError(\n \"Failed to read configuration file\",\n configPath,\n undefined,\n error instanceof Error ? error : undefined\n );\n }\n}\n\n/**\n * Loads configuration from a JavaScript file\n */\nasync function loadJsConfig(configPath: string): Promise<PartialMigrationConfig> {\n try {\n const fileUrl = `file://${configPath}`;\n const module = await import(fileUrl);\n return module.default || module;\n } catch (error) {\n throw new ConfigurationError(\n \"Failed to load JavaScript configuration file\",\n configPath,\n undefined,\n error instanceof Error ? error : undefined\n );\n }\n}\n\n/**\n * Loads configuration from file if it exists\n */\nasync function loadConfigFile(configPath: string): Promise<PartialMigrationConfig | null> {\n if (!fs.existsSync(configPath)) {\n return null;\n }\n\n const ext = path.extname(configPath).toLowerCase();\n\n if (ext === \".json\") {\n return loadJsonConfig(configPath);\n } else if (ext === \".js\" || ext === \".mjs\") {\n return loadJsConfig(configPath);\n } else {\n throw new ConfigurationError(`Unsupported configuration file format: ${ext}`, configPath, undefined);\n }\n}\n\n/**\n * Merges configuration objects with deep merge\n */\nfunction mergeConfig(base: MigrationConfig, override: PartialMigrationConfig): MigrationConfig {\n return {\n schema: { ...base.schema, ...override.schema },\n migrations: { ...base.migrations, ...override.migrations },\n diff: { ...base.diff, ...override.diff },\n };\n}\n\n/**\n * Loads configuration from environment variables\n */\nfunction loadConfigFromEnv(): PartialMigrationConfig {\n const config: PartialMigrationConfig = {};\n\n if (process.env.MIGRATION_SCHEMA_DIR) {\n config.schema = { directory: process.env.MIGRATION_SCHEMA_DIR };\n }\n\n if (process.env.MIGRATION_SCHEMA_EXCLUDE) {\n config.schema = {\n ...config.schema,\n exclude: process.env.MIGRATION_SCHEMA_EXCLUDE.split(\",\").map((s) => s.trim()),\n };\n }\n\n if (process.env.MIGRATION_OUTPUT_DIR) {\n config.migrations = { directory: process.env.MIGRATION_OUTPUT_DIR };\n }\n\n if (process.env.MIGRATION_REQUIRE_FORCE !== undefined) {\n config.diff = { requireForceForDestructive: process.env.MIGRATION_REQUIRE_FORCE === \"true\" };\n }\n\n return config;\n}\n\n/**\n * Loads configuration from CLI arguments\n */\nexport function loadConfigFromArgs(options: any): PartialMigrationConfig {\n const config: PartialMigrationConfig = {};\n\n if (options.output) {\n config.migrations = { directory: options.output };\n }\n\n if (options.schemaDir) {\n config.schema = { directory: options.schemaDir };\n }\n\n return config;\n}\n\n/**\n * Validates configuration values\n */\nfunction validateConfig(config: MigrationConfig, configPath?: string): void {\n const invalidFields: string[] = [];\n\n if (typeof config.schema.directory !== \"string\" || config.schema.directory.trim() === \"\") {\n invalidFields.push(\"schema.directory (must be a non-empty string)\");\n }\n\n if (!Array.isArray(config.schema.exclude)) {\n invalidFields.push(\"schema.exclude (must be an array of strings)\");\n }\n\n if (typeof config.migrations.directory !== \"string\" || config.migrations.directory.trim() === \"\") {\n invalidFields.push(\"migrations.directory (must be a non-empty string)\");\n }\n\n if (typeof config.diff.warnOnDelete !== \"boolean\") {\n invalidFields.push(\"diff.warnOnDelete (must be a boolean)\");\n }\n\n if (typeof config.diff.requireForceForDestructive !== \"boolean\") {\n invalidFields.push(\"diff.requireForceForDestructive (must be a boolean)\");\n }\n\n if (invalidFields.length > 0) {\n throw new ConfigurationError(\"Invalid configuration values\", configPath, invalidFields);\n }\n\n // Validate schema directory exists - try multiple locations\n const cwd = process.cwd();\n const possiblePaths = [\n path.resolve(cwd, config.schema.directory),\n path.resolve(cwd, \"shared\", config.schema.directory),\n ];\n\n const schemaDir = possiblePaths.find((p) => fs.existsSync(p));\n\n if (!schemaDir) {\n throw new ConfigurationError(`Schema directory not found. Tried: ${possiblePaths.join(\", \")}`, configPath, [\n \"schema.directory\",\n ]);\n }\n}\n\n/**\n * Loads and merges configuration from all sources\n * Priority: CLI args > Environment variables > Config file > Defaults\n */\nexport async function loadConfig(options: any = {}): Promise<MigrationConfig> {\n let config: MigrationConfig = { ...DEFAULT_CONFIG };\n let configFilePath: string | undefined;\n\n const cwd = process.cwd();\n\n // Check for explicit config path from CLI\n if (options.config) {\n const explicitPath = path.resolve(cwd, options.config);\n if (!fs.existsSync(explicitPath)) {\n throw new ConfigurationError(`Configuration file not found: ${explicitPath}`, explicitPath);\n }\n configFilePath = explicitPath;\n } else {\n // Search for config file in current directory and shared directory\n const searchDirs = [cwd, path.join(cwd, \"shared\")];\n\n for (const dir of searchDirs) {\n if (fs.existsSync(dir)) {\n const found = findConfigFile(dir);\n if (found) {\n configFilePath = found;\n break;\n }\n }\n }\n }\n\n // Load config file if found\n if (configFilePath) {\n const fileConfig = await loadConfigFile(configFilePath);\n if (fileConfig) {\n config = mergeConfig(config, fileConfig);\n }\n }\n\n // Merge environment variables\n const envConfig = loadConfigFromEnv();\n if (Object.keys(envConfig).length > 0) {\n config = mergeConfig(config, envConfig);\n }\n\n // Merge CLI arguments (highest priority)\n const argsConfig = loadConfigFromArgs(options);\n if (Object.keys(argsConfig).length > 0) {\n config = mergeConfig(config, argsConfig);\n }\n\n // Validate final configuration\n validateConfig(config, configFilePath);\n\n return config;\n}\n\n/**\n * Gets the absolute path to the schema directory\n */\nexport function getSchemaDirectory(config: MigrationConfig): string {\n const cwd = process.cwd();\n const possiblePaths = [\n path.resolve(cwd, config.schema.directory),\n path.resolve(cwd, \"shared\", config.schema.directory),\n ];\n\n return possiblePaths.find((p) => fs.existsSync(p)) || possiblePaths[0];\n}\n\n/**\n * Gets the absolute path to the migrations directory\n */\nexport function getMigrationsDirectory(config: MigrationConfig): string {\n const cwd = process.cwd();\n const possiblePaths = [\n path.resolve(cwd, config.migrations.directory),\n path.resolve(cwd, \"shared\", config.migrations.directory),\n ];\n\n return possiblePaths.find((p) => fs.existsSync(p)) || possiblePaths[0];\n}\n\n/**\n * Gets the default configuration\n */\nexport function getDefaultConfig(): MigrationConfig {\n return { ...DEFAULT_CONFIG };\n}\n\n/**\n * Creates a sample configuration file content\n */\nexport function getSampleConfig(format: \"json\" | \"js\"): string {\n if (format === \"json\") {\n return JSON.stringify(DEFAULT_CONFIG, null, 2);\n }\n\n return `/**\n * PocketBase Zod Migration Configuration\n * @type {import('pocketbase-zod-schema/cli').MigrationConfig}\n */\nexport default {\n schema: {\n directory: \"/src/schema\",\n exclude: [\"base.ts\", \"index.ts\", \"permissions.ts\", \"permission-templates.ts\"],\n },\n migrations: {\n directory: \"pocketbase/pb_migrations\",\n format: \"timestamp_description\",\n },\n diff: {\n warnOnDelete: true,\n requireForceForDestructive: true,\n },\n};\n`;\n}\n","/**\n * Logging utilities for CLI output\n * Provides colored console output and formatting helpers\n */\n\nimport chalk from \"chalk\";\nimport ora, { type Ora } from \"ora\";\nimport type { FieldChange, SchemaDiff } from \"../../migration/types.js\";\n\n/**\n * Verbosity levels for logging\n */\nexport type VerbosityLevel = \"quiet\" | \"normal\" | \"verbose\";\n\n/**\n * Current verbosity level\n */\nlet currentVerbosity: VerbosityLevel = \"normal\";\n\n/**\n * Sets the verbosity level for logging\n *\n * @param level - Verbosity level to set\n */\nexport function setVerbosity(level: VerbosityLevel): void {\n currentVerbosity = level;\n}\n\n/**\n * Gets the current verbosity level\n *\n * @returns Current verbosity level\n */\nexport function getVerbosity(): VerbosityLevel {\n return currentVerbosity;\n}\n\n/**\n * Checks if output should be shown based on verbosity\n *\n * @param requiredLevel - Minimum verbosity level required\n * @returns True if output should be shown\n */\nfunction shouldLog(requiredLevel: VerbosityLevel): boolean {\n const levels: VerbosityLevel[] = [\"quiet\", \"normal\", \"verbose\"];\n const currentIndex = levels.indexOf(currentVerbosity);\n const requiredIndex = levels.indexOf(requiredLevel);\n return currentIndex >= requiredIndex;\n}\n\n/**\n * Creates a spinner for long-running operations\n *\n * @param text - Initial spinner text\n * @returns Ora spinner instance\n */\nexport function createSpinner(text: string): Ora {\n // In quiet mode, create a silent spinner\n if (currentVerbosity === \"quiet\") {\n return ora({ text, isSilent: true });\n }\n return ora(text);\n}\n\n/**\n * Logs a success message in green\n *\n * @param message - Message to log\n */\nexport function logSuccess(message: string): void {\n if (shouldLog(\"normal\")) {\n console.log(chalk.green(\"✓\"), message);\n }\n}\n\n/**\n * Logs an error message in red\n * Always shown regardless of verbosity level\n *\n * @param message - Message to log\n */\nexport function logError(message: string): void {\n console.error(chalk.red(\"✗\"), message);\n}\n\n/**\n * Logs a warning message in yellow\n *\n * @param message - Message to log\n */\nexport function logWarning(message: string): void {\n if (shouldLog(\"normal\")) {\n console.warn(chalk.yellow(\"⚠\"), message);\n }\n}\n\n/**\n * Logs an info message in blue\n *\n * @param message - Message to log\n */\nexport function logInfo(message: string): void {\n if (shouldLog(\"normal\")) {\n console.log(chalk.blue(\"ℹ\"), message);\n }\n}\n\n/**\n * Logs a debug message in gray\n * Only shown in verbose mode\n *\n * @param message - Message to log\n */\nexport function logDebug(message: string): void {\n if (shouldLog(\"verbose\")) {\n console.log(chalk.gray(\"⚙\"), chalk.gray(message));\n }\n}\n\n/**\n * Logs a section header\n *\n * @param title - Section title\n */\nexport function logSection(title: string): void {\n if (shouldLog(\"normal\")) {\n console.log();\n console.log(chalk.bold.cyan(title));\n console.log(chalk.cyan(\"─\".repeat(title.length)));\n }\n}\n\n/**\n * Formats a field change for display\n *\n * @param change - Field change object\n * @returns Formatted string\n */\nfunction formatFieldChange(change: FieldChange): string {\n const oldValue = change.oldValue === null ? \"null\" : JSON.stringify(change.oldValue);\n const newValue = change.newValue === null ? \"null\" : JSON.stringify(change.newValue);\n\n return `${change.property}: ${chalk.red(oldValue)} → ${chalk.green(newValue)}`;\n}\n\n/**\n * Formats a change summary for display\n * Creates a formatted, colored summary of detected changes\n *\n * @param diff - Schema diff containing all changes\n * @returns Formatted summary string\n */\nexport function formatChangeSummary(diff: SchemaDiff): string {\n const lines: string[] = [];\n\n // Count total changes\n const totalCollectionsToCreate = diff.collectionsToCreate.length;\n const totalCollectionsToDelete = diff.collectionsToDelete.length;\n const totalCollectionsToModify = diff.collectionsToModify.length;\n\n const totalChanges = totalCollectionsToCreate + totalCollectionsToDelete + totalCollectionsToModify;\n\n if (totalChanges === 0) {\n return chalk.gray(\"No changes detected\");\n }\n\n lines.push(chalk.bold(`Found ${totalChanges} collection change(s):`));\n lines.push(\"\");\n\n // New collections\n if (totalCollectionsToCreate > 0) {\n lines.push(chalk.green.bold(`✓ ${totalCollectionsToCreate} collection(s) to create:`));\n for (const collection of diff.collectionsToCreate) {\n lines.push(chalk.green(` + ${collection.name} (${collection.type})`));\n lines.push(chalk.gray(` ${collection.fields.length} field(s)`));\n }\n lines.push(\"\");\n }\n\n // Deleted collections\n if (totalCollectionsToDelete > 0) {\n lines.push(chalk.red.bold(`✗ ${totalCollectionsToDelete} collection(s) to delete:`));\n for (const collection of diff.collectionsToDelete) {\n lines.push(chalk.red(` - ${collection.name}`));\n }\n lines.push(\"\");\n }\n\n // Modified collections\n if (totalCollectionsToModify > 0) {\n lines.push(chalk.yellow.bold(`⚡ ${totalCollectionsToModify} collection(s) to modify:`));\n\n for (const modification of diff.collectionsToModify) {\n lines.push(chalk.yellow(` ~ ${modification.collection}`));\n\n // Fields to add\n if (modification.fieldsToAdd.length > 0) {\n lines.push(chalk.green(` + ${modification.fieldsToAdd.length} field(s) to add:`));\n for (const field of modification.fieldsToAdd) {\n lines.push(chalk.green(` + ${field.name} (${field.type})`));\n }\n }\n\n // Fields to remove\n if (modification.fieldsToRemove.length > 0) {\n lines.push(chalk.red(` - ${modification.fieldsToRemove.length} field(s) to remove:`));\n for (const field of modification.fieldsToRemove) {\n lines.push(chalk.red(` - ${field.name}`));\n }\n }\n\n // Fields to modify\n if (modification.fieldsToModify.length > 0) {\n lines.push(chalk.yellow(` ~ ${modification.fieldsToModify.length} field(s) to modify:`));\n for (const fieldMod of modification.fieldsToModify) {\n lines.push(chalk.yellow(` ~ ${fieldMod.fieldName}`));\n for (const change of fieldMod.changes) {\n lines.push(chalk.gray(` ${formatFieldChange(change)}`));\n }\n }\n }\n\n // Indexes\n if (modification.indexesToAdd.length > 0) {\n lines.push(chalk.green(` + ${modification.indexesToAdd.length} index(es) to add`));\n }\n\n if (modification.indexesToRemove.length > 0) {\n lines.push(chalk.red(` - ${modification.indexesToRemove.length} index(es) to remove`));\n }\n\n // Rules\n if (modification.rulesToUpdate.length > 0) {\n lines.push(chalk.yellow(` ~ ${modification.rulesToUpdate.length} rule(s) to update`));\n }\n\n lines.push(\"\");\n }\n }\n\n return lines.join(\"\\n\");\n}\n\n/**\n * Displays a progress indicator for a long operation\n *\n * @param message - Progress message\n * @param operation - Async operation to perform\n * @returns Result of the operation\n */\nexport async function withProgress<T>(message: string, operation: () => Promise<T>): Promise<T> {\n const spinner = createSpinner(message).start();\n\n try {\n const result = await operation();\n spinner.succeed();\n return result;\n } catch (error) {\n spinner.fail();\n throw error;\n }\n}\n\n/**\n * Logs a step in a multi-step process\n *\n * @param step - Current step number\n * @param total - Total number of steps\n * @param message - Step description\n */\nexport function logStep(step: number, total: number, message: string): void {\n if (shouldLog(\"normal\")) {\n const progress = chalk.gray(`[${step}/${total}]`);\n console.log(progress, message);\n }\n}\n\n/**\n * Logs a list of items with bullet points\n *\n * @param items - Items to list\n * @param indent - Indentation level (default: 2)\n */\nexport function logList(items: string[], indent: number = 2): void {\n if (shouldLog(\"normal\")) {\n const padding = \" \".repeat(indent);\n for (const item of items) {\n console.log(`${padding}• ${item}`);\n }\n }\n}\n\n/**\n * Logs a key-value pair\n *\n * @param key - Key name\n * @param value - Value to display\n * @param indent - Indentation level (default: 2)\n */\nexport function logKeyValue(key: string, value: string, indent: number = 2): void {\n if (shouldLog(\"normal\")) {\n const padding = \" \".repeat(indent);\n console.log(`${padding}${chalk.gray(key + \":\")} ${value}`);\n }\n}\n\n/**\n * Logs a table of data\n *\n * @param headers - Column headers\n * @param rows - Data rows\n */\nexport function logTable(headers: string[], rows: string[][]): void {\n if (!shouldLog(\"normal\")) return;\n\n // Calculate column widths\n const widths = headers.map((h, i) => {\n const maxRowWidth = Math.max(...rows.map((r) => (r[i] || \"\").length));\n return Math.max(h.length, maxRowWidth);\n });\n\n // Print header\n const headerLine = headers.map((h, i) => h.padEnd(widths[i])).join(\" \");\n console.log(chalk.bold(headerLine));\n console.log(chalk.gray(\"─\".repeat(headerLine.length)));\n\n // Print rows\n for (const row of rows) {\n const rowLine = row.map((cell, i) => (cell || \"\").padEnd(widths[i])).join(\" \");\n console.log(rowLine);\n }\n}\n\n/**\n * Logs a box with a title and content\n *\n * @param title - Box title\n * @param content - Box content (array of lines)\n */\nexport function logBox(title: string, content: string[]): void {\n if (!shouldLog(\"normal\")) return;\n\n const maxWidth = Math.max(title.length, ...content.map((c) => c.length));\n const border = \"─\".repeat(maxWidth + 2);\n\n console.log();\n console.log(chalk.cyan(`┌${border}┐`));\n console.log(chalk.cyan(\"│ \") + chalk.bold(title.padEnd(maxWidth)) + chalk.cyan(\" │\"));\n console.log(chalk.cyan(`├${border}┤`));\n for (const line of content) {\n console.log(chalk.cyan(\"│ \") + line.padEnd(maxWidth) + chalk.cyan(\" │\"));\n }\n console.log(chalk.cyan(`└${border}┘`));\n}\n\n/**\n * Creates a progress bar string\n *\n * @param current - Current progress value\n * @param total - Total value\n * @param width - Bar width in characters (default: 20)\n * @returns Formatted progress bar string\n */\nexport function createProgressBar(current: number, total: number, width: number = 20): string {\n const percentage = Math.min(100, Math.round((current / total) * 100));\n const filled = Math.round((percentage / 100) * width);\n const empty = width - filled;\n\n const bar = chalk.green(\"█\".repeat(filled)) + chalk.gray(\"░\".repeat(empty));\n return `${bar} ${percentage}%`;\n}\n\n/**\n * Logs a timestamp with a message\n *\n * @param message - Message to log\n */\nexport function logTimestamp(message: string): void {\n if (shouldLog(\"verbose\")) {\n const timestamp = new Date().toISOString();\n console.log(chalk.gray(`[${timestamp}]`), message);\n }\n}\n\n/**\n * Formats a duration in milliseconds to a human-readable string\n *\n * @param ms - Duration in milliseconds\n * @returns Formatted duration string\n */\nexport function formatDuration(ms: number): string {\n if (ms < 1000) {\n return `${ms}ms`;\n } else if (ms < 60000) {\n return `${(ms / 1000).toFixed(1)}s`;\n } else {\n const minutes = Math.floor(ms / 60000);\n const seconds = Math.round((ms % 60000) / 1000);\n return `${minutes}m ${seconds}s`;\n }\n}\n\n/**\n * Logs a timed operation result\n *\n * @param message - Operation description\n * @param startTime - Start time from Date.now()\n */\nexport function logTimed(message: string, startTime: number): void {\n if (shouldLog(\"normal\")) {\n const duration = Date.now() - startTime;\n console.log(chalk.green(\"✓\"), message, chalk.gray(`(${formatDuration(duration)})`));\n }\n}\n\n/**\n * Status output interface for JSON output mode\n */\nexport interface StatusOutput {\n status: \"up-to-date\" | \"changes-pending\" | \"first-time-setup\";\n collections: {\n current: number;\n snapshot: number;\n };\n changes: {\n create: number;\n delete: number;\n modify: number;\n };\n destructive: boolean;\n}\n\n/**\n * Formats status output as JSON\n *\n * @param output - Status output object\n * @returns JSON string\n */\nexport function formatStatusJson(output: StatusOutput): string {\n return JSON.stringify(output, null, 2);\n}\n","/**\n * Generate command implementation\n * Generates migrations from schema changes\n */\n\nimport { Command } from \"commander\";\nimport * as path from \"path\";\nimport { parseSchemaFiles } from \"../../migration/analyzer.js\";\nimport { compare } from \"../../migration/diff.js\";\nimport {\n ConfigurationError,\n FileSystemError,\n MigrationGenerationError,\n SchemaParsingError,\n SnapshotError,\n} from \"../../migration/errors.js\";\nimport { generate } from \"../../migration/generator.js\";\nimport { loadSnapshotWithMigrations } from \"../../migration/snapshot.js\";\nimport {\n detectDestructiveChanges,\n formatDestructiveChanges,\n requiresForceFlag,\n summarizeDestructiveChanges,\n} from \"../../migration/validation.js\";\nimport { getMigrationsDirectory, getSchemaDirectory, loadConfig, type MigrationConfig } from \"../utils/config.js\";\nimport {\n formatChangeSummary,\n logDebug,\n logError,\n logInfo,\n logSection,\n logSuccess,\n logWarning,\n setVerbosity,\n withProgress,\n} from \"../utils/logger.js\";\n\n/**\n * Checks if there are any changes in the diff\n *\n * @param diff - Schema diff to check\n * @returns True if there are changes\n */\nfunction hasChanges(diff: any): boolean {\n return (\n diff.collectionsToCreate.length > 0 || diff.collectionsToDelete.length > 0 || diff.collectionsToModify.length > 0\n );\n}\n\n/**\n * Handles destructive changes with warnings and force flag\n *\n * @param diff - Schema diff containing changes\n * @param config - Migration configuration\n * @param force - Force flag from CLI\n * @returns True if should proceed, false otherwise\n */\nfunction handleDestructiveChanges(diff: any, config: MigrationConfig, force: boolean): boolean {\n // Detect destructive changes\n const destructiveChanges = detectDestructiveChanges(diff);\n\n if (destructiveChanges.length === 0) {\n return true; // No destructive changes, proceed\n }\n\n // Display destructive changes warning\n logSection(\"⚠️ Destructive Changes Detected\");\n console.log();\n\n // Format and display destructive changes\n console.log(formatDestructiveChanges(destructiveChanges));\n\n // Display summary\n const summary = summarizeDestructiveChanges(destructiveChanges);\n console.log(\"Summary:\");\n console.log(` Total: ${summary.total} destructive change(s)`);\n if (summary.high > 0) {\n console.log(` High Severity: ${summary.high}`);\n }\n if (summary.medium > 0) {\n console.log(` Medium Severity: ${summary.medium}`);\n }\n if (summary.low > 0) {\n console.log(` Low Severity: ${summary.low}`);\n }\n console.log();\n\n // Check if force flag is required\n const forceRequired = config.diff.requireForceForDestructive && requiresForceFlag(destructiveChanges);\n\n if (forceRequired && !force) {\n logError(\"Destructive changes require the --force flag to proceed.\");\n console.log();\n logInfo(\"To proceed with these changes, run the command again with --force:\");\n console.log(\" yarn migrate:generate --force\");\n console.log();\n logWarning(\"⚠️ WARNING: Using --force will apply these changes and may result in data loss!\");\n return false;\n }\n\n if (force) {\n logWarning(\"Proceeding with destructive changes (--force flag provided)\");\n console.log();\n }\n\n return true;\n}\n\n/**\n * Executes the generate command\n *\n * @param options - Command options\n */\nexport async function executeGenerate(options: any): Promise<void> {\n try {\n // Set verbosity based on global options\n const parentOpts = options.parent?.opts?.() || {};\n if (parentOpts.verbose) {\n setVerbosity(\"verbose\");\n } else if (parentOpts.quiet) {\n setVerbosity(\"quiet\");\n }\n\n logDebug(\"Starting migration generation...\");\n logDebug(`Options: ${JSON.stringify(options, null, 2)}`);\n\n // Load configuration\n const config = await loadConfig(options);\n\n // Get paths\n const schemaDir = getSchemaDirectory(config);\n const migrationsDir = getMigrationsDirectory(config);\n\n logSection(\"🔍 Analyzing Schema\");\n\n // Parse schema files with full config (including exclude patterns)\n const analyzerConfig = {\n schemaDir,\n excludePatterns: config.schema.exclude,\n useCompiledFiles: false, // Use source files since we're in development/testing\n };\n const currentSchema = await withProgress(\"Parsing Zod schemas...\", () => parseSchemaFiles(analyzerConfig));\n\n logSuccess(`Found ${currentSchema.collections.size} collection(s)`);\n\n // Load previous snapshot from migrations directory and apply subsequent migrations\n logInfo(\"Loading previous snapshot...\");\n const previousSnapshot = loadSnapshotWithMigrations({\n migrationsPath: migrationsDir,\n workspaceRoot: process.cwd(),\n });\n\n if (!previousSnapshot) {\n logInfo(\"No previous snapshot found - treating as empty database (first-time generation)\");\n } else {\n logSuccess(\"Loaded previous snapshot as base reference\");\n }\n\n // Compare schemas\n logSection(\"📊 Comparing Schemas\");\n const diff = compare(currentSchema, previousSnapshot);\n\n // Check if there are any changes\n if (!hasChanges(diff)) {\n logInfo(\"No changes detected\");\n console.log();\n logSuccess(\"Schema is up to date!\");\n return;\n }\n\n // Display change summary\n console.log();\n console.log(formatChangeSummary(diff));\n\n // Handle destructive changes\n if (!handleDestructiveChanges(diff, config, options.force)) {\n process.exit(1);\n }\n\n // Generate migration\n logSection(\"📝 Generating Migration\");\n\n const migrationPaths = await withProgress(\"Creating migration file...\", () =>\n Promise.resolve(generate(diff, migrationsDir))\n );\n\n if (migrationPaths.length === 0) {\n logWarning(\"No migration files were generated (no changes detected).\");\n return;\n }\n\n if (migrationPaths.length === 1) {\n logSuccess(`Migration file created: ${path.basename(migrationPaths[0])}`);\n } else {\n logSuccess(`Created ${migrationPaths.length} migration files`);\n }\n\n // Note: Snapshot is embedded in the generated migration file\n // No separate snapshot file needed\n\n // Display next steps\n logSection(\"✅ Next Steps\");\n console.log();\n console.log(\" 1. Review the generated migration file(s):\");\n migrationPaths.forEach((migrationPath) => {\n console.log(` ${migrationPath}`);\n });\n console.log();\n console.log(\" 2. Apply the migration by running PocketBase:\");\n console.log(\" yarn pb\");\n console.log();\n console.log(\" Or apply migrations manually:\");\n console.log(\" cd pb && ./pocketbase migrate up\");\n console.log();\n } catch (error) {\n // Handle specific error types with helpful messages\n if (error instanceof SchemaParsingError) {\n logError(\"Schema Parsing Error\");\n console.error();\n console.error(error.getDetailedMessage());\n console.error();\n logInfo(\"Suggestions:\");\n console.log(\" • Make sure your schema files are valid Zod schemas\");\n console.log(' • Run \"yarn build\" in the shared workspace to compile TypeScript files');\n console.log(' • Check that schema files export schemas ending with \"Schema\" or \"InputSchema\"');\n } else if (error instanceof SnapshotError) {\n logError(\"Snapshot Error\");\n console.error();\n console.error(error.getDetailedMessage());\n console.error();\n logInfo(\"Suggestions:\");\n console.log(\" • Check that the snapshot file is not corrupted\");\n console.log(\" • Verify file permissions for the snapshot file\");\n console.log(\" • If this is the first run, this error should not occur\");\n } else if (error instanceof MigrationGenerationError) {\n logError(\"Migration Generation Error\");\n console.error();\n console.error(error.getDetailedMessage());\n console.error();\n logInfo(\"Suggestions:\");\n console.log(\" • Check that the migration directory exists and is writable\");\n console.log(\" • Verify you have sufficient disk space\");\n console.log(\" • Check file permissions for the migration directory\");\n } else if (error instanceof FileSystemError) {\n logError(\"File System Error\");\n console.error();\n console.error(error.getDetailedMessage());\n console.error();\n logInfo(\"Suggestions:\");\n console.log(\" • Check file and directory permissions\");\n console.log(\" • Verify you have sufficient disk space\");\n console.log(\" • Ensure the paths are correct and accessible\");\n } else if (error instanceof ConfigurationError) {\n logError(\"Configuration Error\");\n console.error();\n console.error(error.getDetailedMessage());\n console.error();\n logInfo(\"Suggestions:\");\n console.log(\" • Check your configuration file syntax\");\n console.log(\" • Verify all paths are correct and accessible\");\n console.log(\" • Run with --verbose flag for more details\");\n } else {\n // Generic error handling\n logError(`Failed to generate migration: ${error}`);\n if (error instanceof Error && error.stack) {\n console.error();\n console.error(error.stack);\n }\n }\n\n console.error();\n process.exit(1);\n }\n}\n\n/**\n * Creates the generate command\n *\n * @returns Commander command instance\n */\nexport function createGenerateCommand(): Command {\n return new Command(\"generate\")\n .description(\"Generate a migration from schema changes\")\n .option(\"-o, --output <directory>\", \"Output directory for migration files\")\n .option(\"-f, --force\", \"Force generation even with destructive changes\", false)\n .option(\"--dry-run\", \"Show what would be generated without creating files\", false)\n .option(\"--schema-dir <directory>\", \"Directory containing Zod schema files\")\n .addHelpText(\n \"after\",\n `\nExamples:\n $ pocketbase-migrate generate Generate migration from schema changes\n $ pocketbase-migrate generate --force Force generation with destructive changes\n $ pocketbase-migrate generate --dry-run Preview changes without generating files\n $ pocketbase-migrate generate -o ./migrations Specify output directory\n`\n )\n .action(executeGenerate);\n}\n","/**\n * Status command implementation\n * Shows current migration status without generating files\n */\n\nimport chalk from \"chalk\";\nimport { Command } from \"commander\";\nimport { parseSchemaFiles } from \"../../migration/analyzer.js\";\nimport { categorizeChangesBySeverity, compare } from \"../../migration/diff.js\";\nimport { ConfigurationError, SchemaParsingError, SnapshotError } from \"../../migration/errors.js\";\nimport { loadSnapshotWithMigrations } from \"../../migration/snapshot.js\";\nimport type { SchemaDiff } from \"../../migration/types.js\";\nimport { getMigrationsDirectory, getSchemaDirectory, loadConfig } from \"../utils/config.js\";\nimport {\n formatChangeSummary,\n formatStatusJson,\n logDebug,\n logError,\n logInfo,\n logKeyValue,\n logSection,\n logSuccess,\n logTable,\n setVerbosity,\n withProgress,\n type StatusOutput,\n} from \"../utils/logger.js\";\n\n/**\n * Checks if there are any changes in the diff\n *\n * @param diff - Schema diff to check\n * @returns True if there are changes\n */\nfunction hasChanges(diff: SchemaDiff): boolean {\n return (\n diff.collectionsToCreate.length > 0 || diff.collectionsToDelete.length > 0 || diff.collectionsToModify.length > 0\n );\n}\n\n/**\n * Checks if there are any destructive changes\n *\n * @param diff - Schema diff to check\n * @returns True if there are destructive changes\n */\nfunction hasDestructiveChanges(diff: SchemaDiff): boolean {\n const { destructive } = categorizeChangesBySeverity(diff);\n return destructive.length > 0;\n}\n\n/**\n * Creates a status output object for JSON mode\n *\n * @param status - Status type\n * @param currentCount - Current schema collection count\n * @param snapshotCount - Snapshot collection count\n * @param diff - Schema diff (optional)\n * @returns Status output object\n */\nfunction createStatusOutput(\n status: StatusOutput[\"status\"],\n currentCount: number,\n snapshotCount: number,\n diff?: SchemaDiff\n): StatusOutput {\n return {\n status,\n collections: {\n current: currentCount,\n snapshot: snapshotCount,\n },\n changes: {\n create: diff?.collectionsToCreate.length ?? 0,\n delete: diff?.collectionsToDelete.length ?? 0,\n modify: diff?.collectionsToModify.length ?? 0,\n },\n destructive: diff ? hasDestructiveChanges(diff) : false,\n };\n}\n\n/**\n * Displays destructive changes summary\n *\n * @param diff - Schema diff containing changes\n */\nfunction displayDestructiveChangesSummary(diff: SchemaDiff): void {\n const { destructive, nonDestructive } = categorizeChangesBySeverity(diff);\n\n if (destructive.length > 0) {\n logSection(\"⚠️ Destructive Changes\");\n console.log();\n for (const change of destructive) {\n console.log(chalk.red(` ${change}`));\n }\n console.log();\n }\n\n if (nonDestructive.length > 0) {\n logSection(\"✓ Non-Destructive Changes\");\n console.log();\n for (const change of nonDestructive) {\n console.log(chalk.green(` ${change}`));\n }\n console.log();\n }\n}\n\n/**\n * Displays a detailed change table\n *\n * @param diff - Schema diff containing changes\n */\nfunction displayChangeTable(diff: SchemaDiff): void {\n const rows: string[][] = [];\n\n // Add collections to create\n for (const collection of diff.collectionsToCreate) {\n rows.push([\n chalk.green(\"+\"),\n collection.name,\n collection.type,\n `${collection.fields.length} fields`,\n chalk.green(\"Create\"),\n ]);\n }\n\n // Add collections to delete\n for (const collection of diff.collectionsToDelete) {\n rows.push([chalk.red(\"-\"), collection.name, collection.type || \"base\", \"-\", chalk.red(\"Delete\")]);\n }\n\n // Add collections to modify\n for (const mod of diff.collectionsToModify) {\n const changes: string[] = [];\n if (mod.fieldsToAdd.length > 0) changes.push(`+${mod.fieldsToAdd.length} fields`);\n if (mod.fieldsToRemove.length > 0) changes.push(`-${mod.fieldsToRemove.length} fields`);\n if (mod.fieldsToModify.length > 0) changes.push(`~${mod.fieldsToModify.length} fields`);\n if (mod.indexesToAdd.length > 0) changes.push(`+${mod.indexesToAdd.length} indexes`);\n if (mod.indexesToRemove.length > 0) changes.push(`-${mod.indexesToRemove.length} indexes`);\n if (mod.rulesToUpdate.length > 0) changes.push(`~${mod.rulesToUpdate.length} rules`);\n\n rows.push([chalk.yellow(\"~\"), mod.collection, \"-\", changes.join(\", \") || \"No changes\", chalk.yellow(\"Modify\")]);\n }\n\n if (rows.length > 0) {\n logTable([\"\", \"Collection\", \"Type\", \"Changes\", \"Action\"], rows);\n }\n}\n\n/**\n * Executes the status command\n *\n * @param options - Command options\n */\nexport async function executeStatus(options: any): Promise<void> {\n const isJsonMode = options.json === true;\n\n try {\n // Set verbosity based on global options (quiet in JSON mode)\n if (isJsonMode) {\n setVerbosity(\"quiet\");\n } else {\n const parentOpts = options.parent?.opts?.() || {};\n if (parentOpts.verbose) {\n setVerbosity(\"verbose\");\n } else if (parentOpts.quiet) {\n setVerbosity(\"quiet\");\n }\n }\n\n logDebug(\"Checking migration status...\");\n logDebug(`Options: ${JSON.stringify(options, null, 2)}`);\n\n // Load configuration\n const config = await loadConfig(options);\n\n // Get paths\n const schemaDir = getSchemaDirectory(config);\n const migrationsDir = getMigrationsDirectory(config);\n\n logSection(\"🔍 Checking Migration Status\");\n\n // Parse schema files with full config (including exclude patterns)\n const analyzerConfig = {\n schemaDir,\n excludePatterns: config.schema.exclude,\n useCompiledFiles: false, // Use source files since we're in development/testing\n };\n const currentSchema = await withProgress(\"Parsing Zod schemas...\", () => parseSchemaFiles(analyzerConfig));\n\n logSuccess(`Found ${currentSchema.collections.size} collection(s) in schema`);\n\n // Load previous snapshot from migrations directory and apply subsequent migrations\n logInfo(\"Loading previous snapshot...\");\n const previousSnapshot = loadSnapshotWithMigrations({\n migrationsPath: migrationsDir,\n workspaceRoot: process.cwd(),\n });\n\n // Handle first-time setup\n if (!previousSnapshot) {\n if (isJsonMode) {\n const output = createStatusOutput(\"first-time-setup\", currentSchema.collections.size, 0);\n console.log(formatStatusJson(output));\n return;\n }\n\n logSection(\"🆕 First-Time Setup Detected\");\n console.log();\n logInfo(\"No previous snapshot found. This appears to be a first-time setup.\");\n console.log();\n logKeyValue(\"Collections in schema\", String(currentSchema.collections.size));\n console.log();\n logInfo('Run \"pocketbase-migrate generate\" to create the initial migration.');\n return;\n }\n\n logSuccess(`Loaded snapshot with ${previousSnapshot.collections.size} collection(s)`);\n\n // Compare schemas\n logSection(\"📊 Schema Comparison\");\n const diff = compare(currentSchema, previousSnapshot);\n\n // Check if there are any changes\n if (!hasChanges(diff)) {\n if (isJsonMode) {\n const output = createStatusOutput(\n \"up-to-date\",\n currentSchema.collections.size,\n previousSnapshot.collections.size,\n diff\n );\n console.log(formatStatusJson(output));\n return;\n }\n\n console.log();\n logSuccess(\"✓ Schema is in sync with snapshot\");\n logInfo(\"No pending changes detected\");\n console.log();\n logKeyValue(\"Collections\", String(currentSchema.collections.size));\n return;\n }\n\n // Handle JSON output mode\n if (isJsonMode) {\n const output = createStatusOutput(\n \"changes-pending\",\n currentSchema.collections.size,\n previousSnapshot.collections.size,\n diff\n );\n console.log(formatStatusJson(output));\n return;\n }\n\n // Display change summary\n console.log();\n console.log(formatChangeSummary(diff));\n\n // Display change table in verbose mode\n logDebug(\"Detailed change table:\");\n displayChangeTable(diff);\n\n // Display categorized changes\n displayDestructiveChangesSummary(diff);\n\n // Display next steps\n logSection(\"📝 Next Steps\");\n console.log();\n console.log(\" To generate a migration for these changes, run:\");\n console.log(chalk.cyan(\" pocketbase-migrate generate\"));\n console.log();\n\n const { destructive } = categorizeChangesBySeverity(diff);\n if (destructive.length > 0) {\n console.log(chalk.yellow(\" ⚠️ Destructive changes detected. Use --force flag when generating:\"));\n console.log(chalk.cyan(\" pocketbase-migrate generate --force\"));\n console.log();\n }\n } catch (error) {\n // Handle specific error types with helpful messages\n if (error instanceof SchemaParsingError) {\n logError(\"Schema Parsing Error\");\n console.error();\n console.error(error.getDetailedMessage());\n console.error();\n logInfo(\"Suggestions:\");\n console.log(\" • Make sure your schema files are valid Zod schemas\");\n console.log(' • Check that schema files export schemas ending with \"Schema\" or \"InputSchema\"');\n } else if (error instanceof SnapshotError) {\n logError(\"Snapshot Error\");\n console.error();\n console.error(error.getDetailedMessage());\n console.error();\n logInfo(\"Suggestions:\");\n console.log(\" • Check that the snapshot file is not corrupted\");\n console.log(\" • Verify file permissions for the snapshot file\");\n } else if (error instanceof ConfigurationError) {\n logError(\"Configuration Error\");\n console.error();\n console.error(error.getDetailedMessage());\n console.error();\n logInfo(\"Suggestions:\");\n console.log(\" • Check your configuration file syntax\");\n console.log(\" • Verify all paths are correct and accessible\");\n } else {\n logError(`Failed to check status: ${error}`);\n if (error instanceof Error && error.stack) {\n console.error(error.stack);\n }\n }\n process.exit(1);\n }\n}\n\n/**\n * Creates the status command\n *\n * @returns Commander command instance\n */\nexport function createStatusCommand(): Command {\n return new Command(\"status\")\n .description(\"Show current migration status without generating files\")\n .option(\"--schema-dir <directory>\", \"Directory containing Zod schema files\")\n .option(\"--json\", \"Output status as JSON for programmatic use\", false)\n .addHelpText(\n \"after\",\n `\nExamples:\n $ pocketbase-migrate status Check for pending schema changes\n $ pocketbase-migrate status --json Output status as JSON\n $ pocketbase-migrate status --verbose Show detailed status information\n`\n )\n .action(executeStatus);\n}\n","#!/usr/bin/env node\n\n/**\n * CLI entry point for the migration tool\n * Schema-driven PocketBase migration generator\n */\n\n// Register tsx loader for TypeScript file support\n// This must be imported first to enable TypeScript file loading via dynamic imports\n// tsx/esm registers hooks that allow Node.js to handle .ts files in dynamic imports\nimport \"tsx/esm\";\n\nimport chalk from \"chalk\";\nimport { Command } from \"commander\";\nimport { readFileSync } from \"fs\";\nimport { dirname, join } from \"path\";\nimport { fileURLToPath } from \"url\";\nimport { createGenerateCommand } from \"./commands/generate.js\";\nimport { createStatusCommand } from \"./commands/status.js\";\n\n// Get package version from package.json\nfunction getVersion(): string {\n try {\n // Get the directory of the current file\n const __filename = fileURLToPath(import.meta.url);\n const __dirname = dirname(__filename);\n\n // Resolve path to package.json (works from both src and dist)\n // From dist/cli/migrate.js -> ../../package.json\n // From src/cli/migrate.ts -> ../../package.json\n const packageJsonPath = join(__dirname, \"../../package.json\");\n const packageJson = JSON.parse(readFileSync(packageJsonPath, \"utf-8\"));\n return packageJson.version || \"0.0.0\";\n } catch {\n // Fallback version if package.json cannot be read\n console.warn(\"Warning: Could not read version from package.json\");\n return \"0.0.0\";\n }\n}\n\nconst VERSION = getVersion();\n\n/**\n * Display banner with tool name and version\n */\nfunction displayBanner(): void {\n console.log();\n console.log(chalk.cyan.bold(\" PocketBase Zod Migration Tool\"));\n console.log(chalk.gray(` Version ${VERSION}`));\n console.log();\n}\n\n/**\n * Main CLI program\n */\nconst program = new Command();\n\n// Configure main program\nprogram\n .name(\"pocketbase-migrate\")\n .description(\n \"Schema-driven PocketBase migration tool\\n\\nGenerate type-safe migrations from Zod schemas for PocketBase applications.\"\n )\n .version(VERSION, \"-v, --version\", \"Output the current version\")\n .option(\"-c, --config <path>\", \"Path to configuration file\")\n .option(\"--verbose\", \"Enable verbose output\")\n .option(\"--quiet\", \"Suppress non-essential output\")\n .option(\"--no-color\", \"Disable colored output\")\n .hook(\"preAction\", (thisCommand) => {\n // Handle global options before any command runs\n const opts = thisCommand.opts();\n\n // Handle no-color option\n if (opts.color === false) {\n chalk.level = 0;\n }\n\n // Display banner unless quiet mode\n if (!opts.quiet) {\n displayBanner();\n }\n });\n\n// Add commands\nprogram.addCommand(createGenerateCommand());\nprogram.addCommand(createStatusCommand());\n\n// Add examples to help output\nprogram.addHelpText(\n \"after\",\n `\n${chalk.bold(\"Examples:\")}\n $ pocketbase-migrate status Check for pending schema changes\n $ pocketbase-migrate generate Generate migration from schema changes\n $ pocketbase-migrate generate --force Generate migration with destructive changes\n $ pocketbase-migrate --help Show this help message\n\n${chalk.bold(\"Configuration:\")}\n The tool looks for configuration in the following order:\n 1. CLI arguments (highest priority)\n 2. Environment variables (MIGRATION_SCHEMA_DIR, MIGRATION_OUTPUT_DIR, etc.)\n 3. Configuration file (migrate.config.js)\n 4. Default values\n\n${chalk.bold(\"Documentation:\")}\n For more information, visit: https://github.com/dastron/pocketbase-zod-schema\n`\n);\n\n// Custom error handling\nprogram.exitOverride((err) => {\n /**\n * Commander throws on help/version when exitOverride is enabled.\n * The error codes differ by commander version (e.g. \"commander.helpDisplayed\").\n * Respect the exitCode whenever it is provided.\n */\n const anyErr = err as any;\n\n // Common help/version codes across commander versions\n if (anyErr?.code === \"commander.help\" || anyErr?.code === \"commander.helpDisplayed\") {\n process.exit(0);\n }\n if (anyErr?.code === \"commander.version\") {\n process.exit(0);\n }\n\n // Prefer commander-provided exitCode if present\n if (typeof anyErr?.exitCode === \"number\") {\n process.exit(anyErr.exitCode);\n }\n\n process.exit(1);\n});\n\n// Display help if no command provided\nif (process.argv.length === 2) {\n displayBanner();\n program.help();\n}\n\n// Parse command line arguments\nprogram.parse(process.argv);\n"]}