pocketbase-zod-schema 0.2.3 → 0.2.5
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.
- package/CHANGELOG.md +14 -0
- package/README.md +209 -24
- package/dist/cli/index.cjs +34 -0
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.d.cts +3 -1
- package/dist/cli/index.d.ts +3 -1
- package/dist/cli/index.js +34 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/migrate.cjs +34 -0
- package/dist/cli/migrate.cjs.map +1 -1
- package/dist/cli/migrate.js +34 -0
- package/dist/cli/migrate.js.map +1 -1
- package/dist/cli/utils/index.d.cts +3 -1
- package/dist/cli/utils/index.d.ts +3 -1
- package/dist/fields-YjcpBXVp.d.cts +348 -0
- package/dist/fields-YjcpBXVp.d.ts +348 -0
- package/dist/index.cjs +833 -694
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -4
- package/dist/index.d.ts +3 -4
- package/dist/index.js +818 -687
- package/dist/index.js.map +1 -1
- package/dist/migration/analyzer.cjs +34 -0
- package/dist/migration/analyzer.cjs.map +1 -1
- package/dist/migration/analyzer.d.cts +2 -1
- package/dist/migration/analyzer.d.ts +2 -1
- package/dist/migration/analyzer.js +34 -0
- package/dist/migration/analyzer.js.map +1 -1
- package/dist/migration/diff.d.cts +3 -1
- package/dist/migration/diff.d.ts +3 -1
- package/dist/migration/generator.d.cts +3 -1
- package/dist/migration/generator.d.ts +3 -1
- package/dist/migration/index.cjs +36 -0
- package/dist/migration/index.cjs.map +1 -1
- package/dist/migration/index.d.cts +2 -1
- package/dist/migration/index.d.ts +2 -1
- package/dist/migration/index.js +35 -1
- package/dist/migration/index.js.map +1 -1
- package/dist/migration/snapshot.cjs.map +1 -1
- package/dist/migration/snapshot.d.cts +3 -1
- package/dist/migration/snapshot.d.ts +3 -1
- package/dist/migration/snapshot.js.map +1 -1
- package/dist/migration/utils/index.cjs +16 -0
- package/dist/migration/utils/index.cjs.map +1 -1
- package/dist/migration/utils/index.d.cts +2 -2
- package/dist/migration/utils/index.d.ts +2 -2
- package/dist/migration/utils/index.js +15 -1
- package/dist/migration/utils/index.js.map +1 -1
- package/dist/mutator.cjs +2 -98
- package/dist/mutator.cjs.map +1 -1
- package/dist/mutator.d.cts +4 -31
- package/dist/mutator.d.ts +4 -31
- package/dist/mutator.js +2 -98
- package/dist/mutator.js.map +1 -1
- package/dist/schema.cjs +200 -78
- package/dist/schema.cjs.map +1 -1
- package/dist/schema.d.cts +1 -1
- package/dist/schema.d.ts +1 -1
- package/dist/schema.js +186 -72
- package/dist/schema.js.map +1 -1
- package/dist/{types-z1Dkjg8m.d.ts → types-LFBGHl9Y.d.ts} +2 -2
- package/dist/{types-BbTgmg6H.d.cts → types-mhQXWNi3.d.cts} +2 -2
- package/package.json +1 -6
- package/dist/types.cjs +0 -4
- package/dist/types.cjs.map +0 -1
- package/dist/types.d.cts +0 -14
- package/dist/types.d.ts +0 -14
- package/dist/types.js +0 -3
- package/dist/types.js.map +0 -1
- package/dist/user-BnFWg5tw.d.cts +0 -161
- package/dist/user-BnFWg5tw.d.ts +0 -161
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/migration/utils/pluralize.ts","../../../src/migration/utils/relation-detector.ts","../../../src/migration/utils/type-mapper.ts"],"names":["z"],"mappings":";;;AAQA,IAAM,aAAA,GAAwC;AAAA;AAAA,EAE5C,MAAA,EAAQ,QAAA;AAAA,EACR,MAAA,EAAQ,QAAA;AAAA,EACR,KAAA,EAAO,UAAA;AAAA,EACP,KAAA,EAAO,UAAA;AAAA,EACP,GAAA,EAAK,KAAA;AAAA,EACL,GAAA,EAAK,KAAA;AAAA,EACL,KAAA,EAAO,OAAA;AAAA,EACP,KAAA,EAAO,OAAA;AAAA,EACP,KAAA,EAAO,OAAA;AAAA,EACP,KAAA,EAAO,OAAA;AAAA,EACP,IAAA,EAAM,MAAA;AAAA,EACN,IAAA,EAAM,MAAA;A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AA;AAAA,IACA,MAAA;AAAA,IACA,aAAA;AAAA,IACA,KAAA;AAAA,IACA,OAAA;AAAA,IACA,SAAA;AAAA,IACA,OAAA;AAAA,IACA,SAAA;AAAA,IACA,MAAA;AAAA,IACA,UAAA;AAAA,IACA;AAAA,GACF;AACA,EAAA,OAAO,gBAAA,CAAiB,KAAK,CAAC,IAAA,KAAS,UAAU,WAAA,EAAY,CAAE,QAAA,CAAS,IAAI,CAAC,CAAA;AAC/E;AAMO,SAAS,kBAAkB,SAAA,EAA4B;AAC5D,EAAA,MAAM,cAAA,GAAiB;AAAA,IACrB,QAAA;AAAA,IACA,OAAA;AAAA,IACA,MAAA;AAAA,IACA,YAAA;AAAA,IACA,OAAA;AAAA,IACA,SAAA;AAAA,IACA,UAAA;AAAA,IACA,QAAA;AAAA,IACA,WAAA;AAAA,IACA,OAAA;AAAA,IACA,QAAA;AAAA,IACA,MAAA;AAAA,IACA,MAAA;AAAA,IACA;AAAA,GACF;AACA,EAAA,OAAO,cAAA,CAAe,KAAK,CAAC,IAAA,KAAS,UAAU,WAAA,EAAY,CAAE,QAAA,CAAS,IAAI,CAAC,CAAA;AAC7E;AAcO,SAAS,gBAAA,CAAiB,SAAuB,SAAA,EAAoC;AAC1F,EAAA,MAAM,IAAA,GAAO,sBAAA,CAAuB,OAAA,EAAS,SAAS,CAAA;AACtD,EAAA,MAAM,UAAA,GAAa,YAAY,OAAO,CAAA;AACtC,EAAA,MAAM,OAAA,GAAU,iCAAiC,OAAO,CAAA;AAExD,EAAA,OAAO;AAAA,IACL,IAAA;AAAA,IACA,UAAA;AAAA,IACA;AAAA,GACF;AACF","file":"index.js","sourcesContent":["/**\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/**\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"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/migration/utils/pluralize.ts","../../../src/migration/utils/relation-detector.ts","../../../src/schema/fields.ts","../../../src/migration/utils/type-mapper.ts"],"names":["z"],"mappings":";;;AAQA,IAAM,aAAA,GAAwC;AAAA;AAAA,EAE5C,MAAA,EAAQ,QAAA;AAAA,EACR,MAAA,EAAQ,QAAA;AAAA,EACR,KAAA,EAAO,UAAA;AAAA,EACP,KAAA,EAAO,UAAA;AAAA,EACP,GAAA,EAAK,KAAA;AAAA,EACL,GAA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,QAAA,CAAS,IAAI,CAAC,CAAA;AAC7E;AAcO,SAAS,gBAAA,CAAiB,SAAuB,SAAA,EAAoC;AAC1F,EAAA,MAAM,IAAA,GAAO,sBAAA,CAAuB,OAAA,EAAS,SAAS,CAAA;AACtD,EAAA,MAAM,UAAA,GAAa,YAAY,OAAO,CAAA;AACtC,EAAA,MAAM,OAAA,GAAU,iCAAiC,OAAO,CAAA;AAExD,EAAA,OAAO;AAAA,IACL,IAAA;AAAA,IACA,UAAA;AAAA,IACA;AAAA,GACF;AACF","file":"index.js","sourcesContent":["/**\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","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/**\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 */\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 * });\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 * 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"]}
|
package/dist/mutator.cjs
CHANGED
|
@@ -1,85 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
// src/schema/base.ts
|
|
6
|
-
var baseSchema = {
|
|
7
|
-
id: zod.z.string().describe("unique id"),
|
|
8
|
-
collectionId: zod.z.string().describe("collection id"),
|
|
9
|
-
collectionName: zod.z.string().describe("collection name"),
|
|
10
|
-
expand: zod.z.record(zod.z.any()).describe("expandable fields"),
|
|
11
|
-
created: zod.z.string().describe("creation timestamp"),
|
|
12
|
-
updated: zod.z.string().describe("last update timestamp")
|
|
13
|
-
};
|
|
14
|
-
({
|
|
15
|
-
...baseSchema,
|
|
16
|
-
created: zod.z.string().describe("creation timestamp"),
|
|
17
|
-
updated: zod.z.string().describe("last update timestamp")
|
|
18
|
-
});
|
|
19
|
-
({
|
|
20
|
-
...baseSchema,
|
|
21
|
-
thumbnailURL: zod.z.string().optional(),
|
|
22
|
-
imageFiles: zod.z.array(zod.z.string())
|
|
23
|
-
});
|
|
24
|
-
({
|
|
25
|
-
imageFiles: zod.z.array(zod.z.instanceof(File))
|
|
26
|
-
});
|
|
27
|
-
function defineCollection(config) {
|
|
28
|
-
const { collectionName, schema, permissions, indexes, type, ...futureOptions } = config;
|
|
29
|
-
const metadata = {
|
|
30
|
-
collectionName
|
|
31
|
-
};
|
|
32
|
-
if (type) {
|
|
33
|
-
metadata.type = type;
|
|
34
|
-
}
|
|
35
|
-
if (permissions) {
|
|
36
|
-
metadata.permissions = permissions;
|
|
37
|
-
}
|
|
38
|
-
if (indexes) {
|
|
39
|
-
metadata.indexes = indexes;
|
|
40
|
-
}
|
|
41
|
-
if (Object.keys(futureOptions).length > 0) {
|
|
42
|
-
Object.assign(metadata, futureOptions);
|
|
43
|
-
}
|
|
44
|
-
return schema.describe(JSON.stringify(metadata));
|
|
45
|
-
}
|
|
46
|
-
var UserInputSchema = zod.z.object({
|
|
47
|
-
name: zod.z.string().optional(),
|
|
48
|
-
email: zod.z.string().email(),
|
|
49
|
-
password: zod.z.string().min(8, "Password must be at least 8 characters"),
|
|
50
|
-
passwordConfirm: zod.z.string(),
|
|
51
|
-
avatar: zod.z.instanceof(File).optional()
|
|
52
|
-
});
|
|
53
|
-
var UserCollectionSchema = zod.z.object({
|
|
54
|
-
name: zod.z.string().optional(),
|
|
55
|
-
email: zod.z.string().email(),
|
|
56
|
-
password: zod.z.string().min(8, "Password must be at least 8 characters"),
|
|
57
|
-
avatar: zod.z.instanceof(File).optional()
|
|
58
|
-
});
|
|
59
|
-
var UserSchema = UserCollectionSchema.extend(baseSchema);
|
|
60
|
-
defineCollection({
|
|
61
|
-
collectionName: "users",
|
|
62
|
-
type: "auth",
|
|
63
|
-
schema: UserSchema,
|
|
64
|
-
permissions: {
|
|
65
|
-
// Users can list their own profile
|
|
66
|
-
listRule: "id = @request.auth.id",
|
|
67
|
-
// Users can view their own profile
|
|
68
|
-
viewRule: "id = @request.auth.id",
|
|
69
|
-
// Anyone can create an account (sign up)
|
|
70
|
-
createRule: "",
|
|
71
|
-
// Users can only update their own profile
|
|
72
|
-
updateRule: "id = @request.auth.id",
|
|
73
|
-
// Users can only delete their own account
|
|
74
|
-
deleteRule: "id = @request.auth.id"
|
|
75
|
-
// manageRule is null in PocketBase default (not set)
|
|
76
|
-
},
|
|
77
|
-
indexes: [
|
|
78
|
-
// PocketBase's default indexes for auth collections
|
|
79
|
-
"CREATE UNIQUE INDEX `idx_tokenKey__pb_users_auth_` ON `users` (`tokenKey`)",
|
|
80
|
-
"CREATE UNIQUE INDEX `idx_email__pb_users_auth_` ON `users` (`email`) WHERE `email` != ''"
|
|
81
|
-
]
|
|
82
|
-
});
|
|
3
|
+
// src/mutator/baseMutator.ts
|
|
83
4
|
var BaseMutator = class {
|
|
84
5
|
pb;
|
|
85
6
|
// Define a default property that subclasses will override
|
|
@@ -408,23 +329,6 @@ var BaseMutator = class {
|
|
|
408
329
|
}
|
|
409
330
|
};
|
|
410
331
|
|
|
411
|
-
|
|
412
|
-
var UserMutator = class extends BaseMutator {
|
|
413
|
-
setDefaults() {
|
|
414
|
-
return {
|
|
415
|
-
expand: [],
|
|
416
|
-
filter: [],
|
|
417
|
-
sort: ["-updated"]
|
|
418
|
-
};
|
|
419
|
-
}
|
|
420
|
-
getCollection() {
|
|
421
|
-
return this.pb.collection("Users");
|
|
422
|
-
}
|
|
423
|
-
async validateInput(input) {
|
|
424
|
-
return UserInputSchema.parse(input);
|
|
425
|
-
}
|
|
426
|
-
};
|
|
427
|
-
|
|
428
|
-
exports.UserMutator = UserMutator;
|
|
332
|
+
exports.BaseMutator = BaseMutator;
|
|
429
333
|
//# sourceMappingURL=mutator.cjs.map
|
|
430
334
|
//# sourceMappingURL=mutator.cjs.map
|
package/dist/mutator.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/schema/base.ts","../src/schema/user.ts","../src/mutator/baseMutator.ts","../src/mutator/userMutator.ts"],"names":["z"],"mappings":";;;;;AAOO,IAAM,UAAA,GAAa;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;AAAA,EACjD,OAAA,EAASA,KAAA,CAAE,MAAA,EAAO,CAAE,SAAS,uBAAuB;AACtD,CAAA;CAMwC;AAAA,EACtC,GAAG,UAAA;AAAA,EACH,OAAA,EAASA,KAAA,CAAE,MAAA,EAAO,CAAE,SAAS,oBAAoB,CAAA;AAAA,EACjD,OAAA,EAASA,KAAA,CAAE,MAAA,EAAO,CAAE,SAAS,uBAAuB;AACtD;CAMmC;AAAA,EACjC,GAAG,UAAA;AAAA,EACH,YAAA,EAAcA,KAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAClC,UAAA,EAAYA,KAAA,CAAE,KAAA,CAAMA,KAAA,CAAE,QAAQ;AAChC;CAOoC;AAAA,EAClC,YAAYA,KAAA,CAAE,KAAA,CAAMA,KAAA,CAAE,UAAA,CAAW,IAAI,CAAC;AACxC;AAmgBO,SAAS,iBAAiB,MAAA,EAA4C;AAC3E,EAAA,MAAM,EAAE,gBAAgB,MAAA,EAAQ,WAAA,EAAa,SAAS,IAAA,EAAM,GAAG,eAAc,GAAI,MAAA;A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ermissionSchema, 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\n/**\n * Creates a text field schema with optional constraints\n * @param options - Optional constraints for the text field\n */\nexport function textField(options?: { min?: number; max?: number; pattern?: RegExp }) {\n let schema = z.string();\n if (options?.min !== undefined) schema = schema.min(options.min);\n if (options?.max !== undefined) schema = schema.max(options.max);\n if (options?.pattern !== undefined) schema = schema.regex(options.pattern);\n return schema;\n}\n\n/**\n * Creates an email field schema\n * Maps to PocketBase 'email' field type\n */\nexport function emailField() {\n return z.string().email();\n}\n\n/**\n * Creates a URL field schema\n * Maps to PocketBase 'url' field type\n */\nexport function urlField() {\n return z.string().url();\n}\n\n/**\n * Creates a number field schema with optional constraints\n * @param options - Optional constraints for the number field\n */\nexport function numberField(options?: { min?: number; max?: number }) {\n let schema = z.number();\n if (options?.min !== undefined) schema = schema.min(options.min);\n if (options?.max !== undefined) schema = schema.max(options.max);\n return schema;\n}\n\n/**\n * Creates a boolean field schema\n * Maps to PocketBase 'bool' field type\n */\nexport function boolField() {\n return z.boolean();\n}\n\n/**\n * Creates a date field schema\n * Maps to PocketBase 'date' field type\n */\nexport function dateField() {\n return z.date();\n}\n\n/**\n * Creates a select field schema from enum values\n * Maps to PocketBase 'select' field type\n * @param values - Array of allowed string values\n */\nexport function selectField<T extends [string, ...string[]]>(values: T) {\n return z.enum(values);\n}\n\n/**\n * Creates a JSON field schema\n * Maps to PocketBase 'json' field type\n * @param schema - Optional Zod schema for the JSON structure\n */\nexport function jsonField<T extends z.ZodTypeAny>(schema?: T) {\n return schema ?? z.record(z.any());\n}\n\n/**\n * Creates a single file field schema for form input\n * Maps to PocketBase 'file' field type with maxSelect=1\n * Requires Node.js 20+ or browser environment with File API\n */\nexport function fileField() {\n return z.instanceof(File);\n}\n\n/**\n * Creates a multiple file field schema for form input\n * Maps to PocketBase 'file' field type with maxSelect>1\n * Requires Node.js 20+ or browser environment with File API\n * @param options - Optional constraints for the file field\n */\nexport function filesField(options?: { min?: number; max?: number }) {\n let schema = z.array(z.instanceof(File));\n if (options?.min !== undefined) schema = schema.min(options.min);\n if (options?.max !== undefined) schema = schema.max(options.max);\n return schema;\n}\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 * Creates an editor field schema (rich text)\n * Maps to PocketBase 'editor' field type\n */\nexport function editorField() {\n return z.string();\n}\n\n/**\n * Creates a geo point field schema\n * Maps to PocketBase 'geoPoint' field type\n */\nexport function geoPointField() {\n return z.object({\n lon: z.number(),\n lat: z.number(),\n });\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\";\nimport { baseSchema, defineCollection } from \"./base\";\n\n/** -- User Collections -- */\n// Input schema for forms (includes passwordConfirm for validation)\nexport const UserInputSchema = z.object({\n name: z.string().optional(),\n email: z.string().email(),\n password: z.string().min(8, \"Password must be at least 8 characters\"),\n passwordConfirm: z.string(),\n avatar: z.instanceof(File).optional(),\n});\n\n// Database schema (excludes passwordConfirm, includes avatar as file field)\nexport const UserCollectionSchema = z.object({\n name: z.string().optional(),\n email: z.string().email(),\n password: z.string().min(8, \"Password must be at least 8 characters\"),\n avatar: z.instanceof(File).optional(),\n});\n\n// Full schema with base fields for type inference (used in types.ts)\n// This includes id, collectionId, collectionName from baseSchema\nexport const UserSchema = UserCollectionSchema.extend(baseSchema);\n\n// Matches PocketBase's default users collection configuration\n// Using default export - the migration tool will automatically use this\nconst UserCollection = defineCollection({\n collectionName: \"users\",\n type: \"auth\",\n schema: UserSchema,\n permissions: {\n // Users can list their own profile\n listRule: \"id = @request.auth.id\",\n // Users can view their own profile\n viewRule: \"id = @request.auth.id\",\n // Anyone can create an account (sign up)\n createRule: \"\",\n // Users can only update their own profile\n updateRule: \"id = @request.auth.id\",\n // Users can only delete their own account\n deleteRule: \"id = @request.auth.id\",\n // manageRule is null in PocketBase default (not set)\n },\n indexes: [\n // PocketBase's default indexes for auth collections\n \"CREATE UNIQUE INDEX `idx_tokenKey__pb_users_auth_` ON `users` (`tokenKey`)\",\n \"CREATE UNIQUE INDEX `idx_email__pb_users_auth_` ON `users` (`email`) WHERE `email` != ''\",\n ],\n});\n\n// Default export - preferred pattern for schema files\n// The migration tool will automatically detect and use this\nexport default UserCollection;\n\n// Named export kept for backward compatibility and type inference\nexport { UserCollection };\n","import {\n RecordService,\n type ListResult,\n type RecordListOptions,\n type RecordModel,\n type RecordOptions,\n type RecordSubscribeOptions,\n type RecordSubscription,\n type UnsubscribeFunc,\n} from \"pocketbase\";\nimport type { TypedPocketBase } from \"../types\";\n\nexport interface MutatorOptions {\n expand: string[];\n filter: string[];\n sort: string[];\n}\n\n// T represents the output model type that extends RecordModel\n// InputType represents the input type for creation operations\nexport abstract class BaseMutator<T extends RecordModel, InputType> {\n protected pb: TypedPocketBase;\n\n // Define a default property that subclasses will override\n protected options: MutatorOptions = {\n expand: [],\n filter: [],\n sort: [],\n };\n\n constructor(pb: TypedPocketBase, options?: Partial<MutatorOptions>) {\n this.pb = pb;\n\n // Initialize with default options first\n this.initializeOptions();\n if (options) {\n this.overrideOptions(options);\n }\n }\n\n private initializeOptions(): void {\n this.options = this.setDefaults();\n }\n /**\n * Initialize options with class-specific defaults\n * Subclasses should override this instead of directly setting options\n */\n protected setDefaults(): MutatorOptions {\n return {\n expand: [],\n filter: [],\n sort: [],\n };\n }\n\n /**\n * Merge provided options with current options\n */\n protected overrideOptions(newOptions: Partial<MutatorOptions>): void {\n if (newOptions.expand !== undefined) {\n this.options.expand = newOptions.expand;\n }\n if (newOptions.filter !== undefined) {\n this.options.filter = newOptions.filter;\n }\n if (newOptions.sort !== undefined) {\n this.options.sort = newOptions.sort;\n }\n }\n\n /**\n * Get the collection instance\n */\n protected abstract getCollection(): RecordService<T>;\n\n toSnakeCase(str: string): string {\n return str\n .trim()\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \"_\")\n .replace(/^_|_$/g, \"\");\n }\n\n /**\n * Create a new entity\n */\n async create(input: InputType): Promise<T> {\n try {\n const data = await this.validateInput(input);\n const record = await this.entityCreate(data);\n return await this.processRecord(record);\n } catch (error) {\n return this.errorWrapper(error);\n }\n }\n\n /**\n * Update an existing entity\n */\n async update(id: string, input: Partial<T>): Promise<T> {\n try {\n const record = await this.entityUpdate(id, input);\n return await this.processRecord(record);\n } catch (error) {\n return this.errorWrapper(error);\n }\n }\n\n /**\n * Create or update entity (upsert)\n */\n async upsert(input: InputType & { id?: string }): Promise<T> {\n if (input?.id) {\n return await this.update(input.id, input as Partial<T>);\n }\n\n // Implementations should override this method if they need\n // more specific upsert logic like checking for existing entities\n return await this.create(input);\n }\n\n /**\n * Get entity by ID\n */\n async getById(id: string, expand?: string | string[]): Promise<T | null> {\n try {\n const record = await this.entityGetById(id, expand);\n return await this.processRecord(record);\n } catch (error) {\n return this.handleError(error, { allowNotFound: true });\n }\n }\n\n /**\n * Get first entity by filter\n */\n async getFirstByFilter(filter: string | string[], expand?: string | string[], sort?: string): Promise<T | null> {\n try {\n const record = await this.entityGetFirstByFilter(filter, expand, sort);\n return await this.processRecord(record);\n } catch (error) {\n return this.handleError(error, { allowNotFound: true });\n }\n }\n\n /**\n * Get list of entities\n */\n async getList(\n page = 1,\n perPage = 100,\n filter?: string | string[],\n sort?: string,\n expand?: string | string[]\n ): Promise<ListResult<T>> {\n try {\n const result = await this.entityGetList(page, perPage, filter, sort, expand);\n return await this.processListResult(result);\n } catch (error) {\n return this.errorWrapper(error);\n }\n }\n\n /**\n * Delete entity by ID\n */\n async delete(id: string): Promise<boolean> {\n try {\n return await this.entityDelete(id);\n } catch (error) {\n return this.handleError(error, { returnValue: false });\n }\n }\n\n /**\n * Process a single record before returning it\n * Can be overridden to handle special cases like mapped entities\n */\n protected async processRecord(record: T): Promise<T> {\n return record;\n }\n\n /**\n * Process a list result before returning it\n * Can be overridden to handle special cases like mapped entities\n */\n protected async processListResult(result: ListResult<T>): Promise<ListResult<T>> {\n // Process each item in the list\n const processedItems = await Promise.all(result.items.map((item) => this.processRecord(item)));\n\n return {\n ...result,\n items: processedItems,\n };\n }\n\n /**\n * Prepare expand parameter\n * Combines default expands with provided expands\n */\n protected prepareExpand(expand?: string | string[]): string | undefined {\n // Handle empty defaults case\n if (!this.options.expand.length && !expand) {\n return undefined;\n }\n\n // Convert all inputs to arrays for easy processing\n let expandArray: string[] = [...this.options.expand];\n\n if (expand) {\n // If expand is a string, split it and add the parts\n if (typeof expand === \"string\") {\n expandArray = expandArray.concat(expand.split(\",\").map((e) => e.trim()));\n }\n // If expand is already an array, concatenate\n else {\n expandArray = expandArray.concat(expand);\n }\n }\n\n // Filter out duplicates, empty strings, and undefined values\n const uniqueExpands = [...new Set(expandArray)].filter((e) => e !== \"\" && e !== undefined);\n\n // If no valid expands, return undefined\n if (!uniqueExpands.length) {\n return undefined;\n }\n\n // Join with comma and space\n return uniqueExpands.join(\",\");\n }\n\n /**\n * Prepare filter parameter\n * Combines default filters with provided filters\n */\n protected prepareFilter(filter?: string | string[]): string | undefined {\n // Handle empty case\n if (!this.options.filter.length && !filter) {\n return undefined;\n }\n\n // Convert all inputs to arrays for easy processing\n let filterArray: string[] = [...this.options.filter];\n\n if (filter) {\n // If filter is a string, add it as is (it might contain && already)\n if (typeof filter === \"string\") {\n if (filter) filterArray.push(filter);\n }\n // If filter is an array, concatenate\n else {\n filterArray = filterArray.concat(filter);\n }\n }\n\n // Filter out empty strings and undefined values\n const validFilters = filterArray.filter((f) => f !== \"\" && f !== undefined);\n\n // If no valid filters, return undefined\n if (!validFilters.length) {\n return undefined;\n }\n\n // Join with AND operator\n return validFilters.join(\"&&\");\n }\n\n /**\n * Prepare sort parameter\n * Uses provided sort or falls back to default sort\n */\n protected prepareSort(sort?: string): string | undefined {\n // If explicit sort is provided and not empty, use it (overriding defaults)\n if (sort && sort !== \"\") {\n return sort;\n }\n\n // If no explicit sort but we have defaults\n if (this.options.sort.length) {\n // Filter out empty and undefined values\n const validSorts = this.options.sort.filter((s) => s !== \"\" && s !== undefined);\n\n // If we have valid sort items after filtering\n if (validSorts.length) {\n return validSorts.join(\",\");\n }\n }\n\n // No sort specified\n return undefined;\n }\n\n /**\n * Perform the actual create operation\n */\n protected async entityCreate(data: InputType): Promise<T> {\n return await this.getCollection().create(data as Record<string, any>);\n }\n\n /**\n * Perform the actual update operation\n */\n protected async entityUpdate(id: string, data: Partial<T>): Promise<T> {\n return await this.getCollection().update(id, data);\n }\n\n /**\n * Perform the actual getById operation\n */\n protected async entityGetById(id: string, expand?: string | string[]): Promise<T> {\n const finalExpand = this.prepareExpand(expand);\n const options: RecordOptions = finalExpand ? { expand: finalExpand } : {};\n return await this.getCollection().getOne(id, options);\n }\n\n /**\n * Perform the actual getFirstByFilter operation\n */\n protected async entityGetFirstByFilter(\n filter: string | string[],\n expand?: string | string[],\n sort?: string\n ): Promise<T> {\n const finalFilter = this.prepareFilter(filter);\n const finalExpand = this.prepareExpand(expand);\n const finalSort = this.prepareSort(sort);\n\n const options: RecordListOptions = {};\n if (finalExpand) options.expand = finalExpand;\n if (finalSort) options.sort = finalSort;\n\n return await this.getCollection().getFirstListItem(finalFilter || \"\", options);\n }\n\n /**\n * Perform the actual getList operation\n * Returns a list result with items of type T\n */\n protected async entityGetList(\n page: number,\n perPage: number,\n filter?: string | string[],\n sort?: string,\n expand?: string | string[]\n ): Promise<ListResult<T>> {\n const finalFilter = this.prepareFilter(filter);\n const finalExpand = this.prepareExpand(expand);\n const finalSort = this.prepareSort(sort);\n\n const options: RecordListOptions = {};\n if (finalFilter) options.filter = finalFilter;\n if (finalExpand) options.expand = finalExpand;\n if (finalSort) options.sort = finalSort;\n\n return await this.getCollection().getList(page, perPage, options);\n }\n\n /**\n * Perform the actual delete operation\n */\n protected async entityDelete(id: string): Promise<boolean> {\n await this.getCollection().delete(id);\n return true;\n }\n\n /**\n * Error handler for common errors\n * @param error The error to handle\n * @param options Handler options\n * @returns The value to return if the error is handled, or throws if not handled\n */\n protected handleError<R>(\n error: any,\n options: {\n allowNotFound?: boolean;\n returnValue?: R;\n logError?: boolean;\n } = { logError: true }\n ): R {\n const { allowNotFound = false, returnValue, logError = true } = options;\n\n // Log the error if requested\n if (logError) {\n console.error(`Error in ${this.constructor.name}:`, error);\n }\n\n // Handle 404 errors if allowed\n if (allowNotFound && this.isNotFoundError(error)) {\n return null as R;\n }\n\n // Return specified value or rethrow\n if (returnValue !== undefined) {\n return returnValue;\n }\n\n // Rethrow the error\n throw error;\n }\n\n /**\n * Check if an error is a \"not found\" error\n */\n protected isNotFoundError(error: any): boolean {\n return (\n error instanceof Error && (error.message.includes(\"404\") || error.message.toLowerCase().includes(\"not found\"))\n );\n }\n\n /**\n * Standard error handling wrapper (legacy method, consider using handleError instead)\n */\n protected errorWrapper(error: any): never {\n console.error(`Error in ${this.constructor.name}:`, error);\n throw error;\n }\n\n /**\n * Validate input data before creating/updating\n * Should be implemented by child classes\n */\n protected abstract validateInput(input: InputType): Promise<InputType>;\n\n /**\n * Subscribe to changes on a specific record\n * @param id The ID of the record to subscribe to\n * @param callback Function to call when changes occur\n * @param expand Optional expand parameters\n * @returns Promise that resolves to an unsubscribe function\n */\n async subscribeToRecord(\n id: string,\n callback: (data: RecordSubscription<T>) => void,\n expand?: string | string[]\n ): Promise<UnsubscribeFunc> {\n const finalExpand = this.prepareExpand(expand);\n const options: RecordSubscribeOptions = finalExpand ? { expand: finalExpand } : {};\n\n return this.getCollection().subscribe(id, callback, options);\n }\n\n /**\n * Subscribe to changes on the entire collection\n * @param callback Function to call when changes occur\n * @param expand Optional expand parameters\n * @returns Promise that resolves to an unsubscribe function\n */\n async subscribeToCollection(\n callback: (data: RecordSubscription<T>) => void,\n expand?: string | string[]\n ): Promise<UnsubscribeFunc> {\n const finalExpand = this.prepareExpand(expand);\n const options: RecordSubscribeOptions = finalExpand ? { expand: finalExpand } : {};\n\n return this.getCollection().subscribe(\"*\", callback, options);\n }\n\n /**\n * Unsubscribe from a specific record's changes\n * @param id The ID of the record to unsubscribe from\n */\n unsubscribeFromRecord(id: string): void {\n this.getCollection().unsubscribe(id);\n }\n\n /**\n * Unsubscribe from collection-wide changes\n */\n unsubscribeFromCollection(): void {\n this.getCollection().unsubscribe(\"*\");\n }\n\n /**\n * Unsubscribe from all subscriptions in this collection\n */\n unsubscribeAll(): void {\n this.getCollection().unsubscribe();\n }\n}\n","import { UserInputSchema } from \"../schema\";\nimport type { UserInputType, UserType } from \"../types\";\nimport { BaseMutator, type MutatorOptions } from \"./baseMutator\";\n\nexport class UserMutator extends BaseMutator<UserType, UserInputType> {\n protected setDefaults(): MutatorOptions {\n return {\n expand: [],\n filter: [],\n sort: [\"-updated\"],\n };\n }\n\n protected getCollection() {\n return this.pb.collection(\"Users\");\n }\n\n protected async validateInput(input: UserInputType) {\n return UserInputSchema.parse(input);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/mutator/baseMutator.ts"],"names":[],"mappings":";;;AAmBO,IAAe,cAAf,MAA6D;AAAA,EACxD,EAAA;AAAA;AAAA,EAGA,OAAA,GAA0B;AAAA,IAClC,QAAQ,EAAC;AAAA,IACT,QAAQ,EAAC;AAAA,IACT,MAAM;AAAC,GACT;AAAA,EAEA,WAAA,CAAY,IAAgB,OAAA,EAAmC;AAC7D,IAAA,IAAA,CAAK,EAAA,GAAK,EAAA;AAGV,IAAA,IAAA,CAAK,iBAAA,EAAkB;AACvB,IAAA,IAAI,OAAA,EAAS;AACX,MAAA,IAAA,CAAK,gBAAgB,OAAO,CAAA;AAAA,IAC9B;AAAA,EACF;AAAA,EAEQ,iBAAA,GAA0B;AAChC,IAAA,IAAA,CAAK,OAAA,GAAU,KAAK,WAAA,EAAY;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA;AAAA,EAKU,WAAA,GAA8B;AACtC,IAAA,OAAO;AAAA,MACL,QAAQ,EAAC;AAAA,MACT,QAAQ,EAAC;AAAA,MACT,MAAM;AAAC,KACT;AAAA,EACF;AAAA;AAAA;AAAA;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AQ,WAAA,KAAgB,EAAC;AAEjF,IAAA,OAAO,KAAK,aAAA,EAAc,CAAE,SAAA,CAAU,EAAA,EAAI,UAAU,OAAO,CAAA;AAAA,EAC7D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,qBAAA,CACJ,QAAA,EACA,MAAA,EAC0B;AAC1B,IAAA,MAAM,WAAA,GAAc,IAAA,CAAK,aAAA,CAAc,MAAM,CAAA;AAC7C,IAAA,MAAM,UAAkC,WAAA,GAAc,EAAE,MAAA,EAAQ,WAAA,KAAgB,EAAC;AAEjF,IAAA,OAAO,KAAK,aAAA,EAAc,CAAE,SAAA,CAAU,GAAA,EAAK,UAAU,OAAO,CAAA;AAAA,EAC9D;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,sBAAsB,EAAA,EAAkB;AACtC,IAAA,IAAA,CAAK,aAAA,EAAc,CAAE,WAAA,CAAY,EAAE,CAAA;AAAA,EACrC;AAAA;AAAA;AAAA;AAAA,EAKA,yBAAA,GAAkC;AAChC,IAAA,IAAA,CAAK,aAAA,EAAc,CAAE,WAAA,CAAY,GAAG,CAAA;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA,EAKA,cAAA,GAAuB;AACrB,IAAA,IAAA,CAAK,aAAA,GAAgB,WAAA,EAAY;AAAA,EACnC;AACF","file":"mutator.cjs","sourcesContent":["import PocketBase, {\n RecordService,\n type ListResult,\n type RecordListOptions,\n type RecordModel,\n type RecordOptions,\n type RecordSubscribeOptions,\n type RecordSubscription,\n type UnsubscribeFunc,\n} from \"pocketbase\";\n\nexport interface MutatorOptions {\n expand: string[];\n filter: string[];\n sort: string[];\n}\n\n// T represents the output model type that extends RecordModel\n// InputType represents the input type for creation operations\nexport abstract class BaseMutator<T extends RecordModel, InputType> {\n protected pb: PocketBase;\n\n // Define a default property that subclasses will override\n protected options: MutatorOptions = {\n expand: [],\n filter: [],\n sort: [],\n };\n\n constructor(pb: PocketBase, options?: Partial<MutatorOptions>) {\n this.pb = pb;\n\n // Initialize with default options first\n this.initializeOptions();\n if (options) {\n this.overrideOptions(options);\n }\n }\n\n private initializeOptions(): void {\n this.options = this.setDefaults();\n }\n /**\n * Initialize options with class-specific defaults\n * Subclasses should override this instead of directly setting options\n */\n protected setDefaults(): MutatorOptions {\n return {\n expand: [],\n filter: [],\n sort: [],\n };\n }\n\n /**\n * Merge provided options with current options\n */\n protected overrideOptions(newOptions: Partial<MutatorOptions>): void {\n if (newOptions.expand !== undefined) {\n this.options.expand = newOptions.expand;\n }\n if (newOptions.filter !== undefined) {\n this.options.filter = newOptions.filter;\n }\n if (newOptions.sort !== undefined) {\n this.options.sort = newOptions.sort;\n }\n }\n\n /**\n * Get the collection instance\n */\n protected abstract getCollection(): RecordService<T>;\n\n toSnakeCase(str: string): string {\n return str\n .trim()\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \"_\")\n .replace(/^_|_$/g, \"\");\n }\n\n /**\n * Create a new entity\n */\n async create(input: InputType): Promise<T> {\n try {\n const data = await this.validateInput(input);\n const record = await this.entityCreate(data);\n return await this.processRecord(record);\n } catch (error) {\n return this.errorWrapper(error);\n }\n }\n\n /**\n * Update an existing entity\n */\n async update(id: string, input: Partial<T>): Promise<T> {\n try {\n const record = await this.entityUpdate(id, input);\n return await this.processRecord(record);\n } catch (error) {\n return this.errorWrapper(error);\n }\n }\n\n /**\n * Create or update entity (upsert)\n */\n async upsert(input: InputType & { id?: string }): Promise<T> {\n if (input?.id) {\n return await this.update(input.id, input as Partial<T>);\n }\n\n // Implementations should override this method if they need\n // more specific upsert logic like checking for existing entities\n return await this.create(input);\n }\n\n /**\n * Get entity by ID\n */\n async getById(id: string, expand?: string | string[]): Promise<T | null> {\n try {\n const record = await this.entityGetById(id, expand);\n return await this.processRecord(record);\n } catch (error) {\n return this.handleError(error, { allowNotFound: true });\n }\n }\n\n /**\n * Get first entity by filter\n */\n async getFirstByFilter(filter: string | string[], expand?: string | string[], sort?: string): Promise<T | null> {\n try {\n const record = await this.entityGetFirstByFilter(filter, expand, sort);\n return await this.processRecord(record);\n } catch (error) {\n return this.handleError(error, { allowNotFound: true });\n }\n }\n\n /**\n * Get list of entities\n */\n async getList(\n page = 1,\n perPage = 100,\n filter?: string | string[],\n sort?: string,\n expand?: string | string[]\n ): Promise<ListResult<T>> {\n try {\n const result = await this.entityGetList(page, perPage, filter, sort, expand);\n return await this.processListResult(result);\n } catch (error) {\n return this.errorWrapper(error);\n }\n }\n\n /**\n * Delete entity by ID\n */\n async delete(id: string): Promise<boolean> {\n try {\n return await this.entityDelete(id);\n } catch (error) {\n return this.handleError(error, { returnValue: false });\n }\n }\n\n /**\n * Process a single record before returning it\n * Can be overridden to handle special cases like mapped entities\n */\n protected async processRecord(record: T): Promise<T> {\n return record;\n }\n\n /**\n * Process a list result before returning it\n * Can be overridden to handle special cases like mapped entities\n */\n protected async processListResult(result: ListResult<T>): Promise<ListResult<T>> {\n // Process each item in the list\n const processedItems = await Promise.all(result.items.map((item) => this.processRecord(item)));\n\n return {\n ...result,\n items: processedItems,\n };\n }\n\n /**\n * Prepare expand parameter\n * Combines default expands with provided expands\n */\n protected prepareExpand(expand?: string | string[]): string | undefined {\n // Handle empty defaults case\n if (!this.options.expand.length && !expand) {\n return undefined;\n }\n\n // Convert all inputs to arrays for easy processing\n let expandArray: string[] = [...this.options.expand];\n\n if (expand) {\n // If expand is a string, split it and add the parts\n if (typeof expand === \"string\") {\n expandArray = expandArray.concat(expand.split(\",\").map((e) => e.trim()));\n }\n // If expand is already an array, concatenate\n else {\n expandArray = expandArray.concat(expand);\n }\n }\n\n // Filter out duplicates, empty strings, and undefined values\n const uniqueExpands = [...new Set(expandArray)].filter((e) => e !== \"\" && e !== undefined);\n\n // If no valid expands, return undefined\n if (!uniqueExpands.length) {\n return undefined;\n }\n\n // Join with comma and space\n return uniqueExpands.join(\",\");\n }\n\n /**\n * Prepare filter parameter\n * Combines default filters with provided filters\n */\n protected prepareFilter(filter?: string | string[]): string | undefined {\n // Handle empty case\n if (!this.options.filter.length && !filter) {\n return undefined;\n }\n\n // Convert all inputs to arrays for easy processing\n let filterArray: string[] = [...this.options.filter];\n\n if (filter) {\n // If filter is a string, add it as is (it might contain && already)\n if (typeof filter === \"string\") {\n if (filter) filterArray.push(filter);\n }\n // If filter is an array, concatenate\n else {\n filterArray = filterArray.concat(filter);\n }\n }\n\n // Filter out empty strings and undefined values\n const validFilters = filterArray.filter((f) => f !== \"\" && f !== undefined);\n\n // If no valid filters, return undefined\n if (!validFilters.length) {\n return undefined;\n }\n\n // Join with AND operator\n return validFilters.join(\"&&\");\n }\n\n /**\n * Prepare sort parameter\n * Uses provided sort or falls back to default sort\n */\n protected prepareSort(sort?: string): string | undefined {\n // If explicit sort is provided and not empty, use it (overriding defaults)\n if (sort && sort !== \"\") {\n return sort;\n }\n\n // If no explicit sort but we have defaults\n if (this.options.sort.length) {\n // Filter out empty and undefined values\n const validSorts = this.options.sort.filter((s) => s !== \"\" && s !== undefined);\n\n // If we have valid sort items after filtering\n if (validSorts.length) {\n return validSorts.join(\",\");\n }\n }\n\n // No sort specified\n return undefined;\n }\n\n /**\n * Perform the actual create operation\n */\n protected async entityCreate(data: InputType): Promise<T> {\n return await this.getCollection().create(data as Record<string, any>);\n }\n\n /**\n * Perform the actual update operation\n */\n protected async entityUpdate(id: string, data: Partial<T>): Promise<T> {\n return await this.getCollection().update(id, data);\n }\n\n /**\n * Perform the actual getById operation\n */\n protected async entityGetById(id: string, expand?: string | string[]): Promise<T> {\n const finalExpand = this.prepareExpand(expand);\n const options: RecordOptions = finalExpand ? { expand: finalExpand } : {};\n return await this.getCollection().getOne(id, options);\n }\n\n /**\n * Perform the actual getFirstByFilter operation\n */\n protected async entityGetFirstByFilter(\n filter: string | string[],\n expand?: string | string[],\n sort?: string\n ): Promise<T> {\n const finalFilter = this.prepareFilter(filter);\n const finalExpand = this.prepareExpand(expand);\n const finalSort = this.prepareSort(sort);\n\n const options: RecordListOptions = {};\n if (finalExpand) options.expand = finalExpand;\n if (finalSort) options.sort = finalSort;\n\n return await this.getCollection().getFirstListItem(finalFilter || \"\", options);\n }\n\n /**\n * Perform the actual getList operation\n * Returns a list result with items of type T\n */\n protected async entityGetList(\n page: number,\n perPage: number,\n filter?: string | string[],\n sort?: string,\n expand?: string | string[]\n ): Promise<ListResult<T>> {\n const finalFilter = this.prepareFilter(filter);\n const finalExpand = this.prepareExpand(expand);\n const finalSort = this.prepareSort(sort);\n\n const options: RecordListOptions = {};\n if (finalFilter) options.filter = finalFilter;\n if (finalExpand) options.expand = finalExpand;\n if (finalSort) options.sort = finalSort;\n\n return await this.getCollection().getList(page, perPage, options);\n }\n\n /**\n * Perform the actual delete operation\n */\n protected async entityDelete(id: string): Promise<boolean> {\n await this.getCollection().delete(id);\n return true;\n }\n\n /**\n * Error handler for common errors\n * @param error The error to handle\n * @param options Handler options\n * @returns The value to return if the error is handled, or throws if not handled\n */\n protected handleError<R>(\n error: any,\n options: {\n allowNotFound?: boolean;\n returnValue?: R;\n logError?: boolean;\n } = { logError: true }\n ): R {\n const { allowNotFound = false, returnValue, logError = true } = options;\n\n // Log the error if requested\n if (logError) {\n console.error(`Error in ${this.constructor.name}:`, error);\n }\n\n // Handle 404 errors if allowed\n if (allowNotFound && this.isNotFoundError(error)) {\n return null as R;\n }\n\n // Return specified value or rethrow\n if (returnValue !== undefined) {\n return returnValue;\n }\n\n // Rethrow the error\n throw error;\n }\n\n /**\n * Check if an error is a \"not found\" error\n */\n protected isNotFoundError(error: any): boolean {\n return (\n error instanceof Error && (error.message.includes(\"404\") || error.message.toLowerCase().includes(\"not found\"))\n );\n }\n\n /**\n * Standard error handling wrapper (legacy method, consider using handleError instead)\n */\n protected errorWrapper(error: any): never {\n console.error(`Error in ${this.constructor.name}:`, error);\n throw error;\n }\n\n /**\n * Validate input data before creating/updating\n * Should be implemented by child classes\n */\n protected abstract validateInput(input: InputType): Promise<InputType>;\n\n /**\n * Subscribe to changes on a specific record\n * @param id The ID of the record to subscribe to\n * @param callback Function to call when changes occur\n * @param expand Optional expand parameters\n * @returns Promise that resolves to an unsubscribe function\n */\n async subscribeToRecord(\n id: string,\n callback: (data: RecordSubscription<T>) => void,\n expand?: string | string[]\n ): Promise<UnsubscribeFunc> {\n const finalExpand = this.prepareExpand(expand);\n const options: RecordSubscribeOptions = finalExpand ? { expand: finalExpand } : {};\n\n return this.getCollection().subscribe(id, callback, options);\n }\n\n /**\n * Subscribe to changes on the entire collection\n * @param callback Function to call when changes occur\n * @param expand Optional expand parameters\n * @returns Promise that resolves to an unsubscribe function\n */\n async subscribeToCollection(\n callback: (data: RecordSubscription<T>) => void,\n expand?: string | string[]\n ): Promise<UnsubscribeFunc> {\n const finalExpand = this.prepareExpand(expand);\n const options: RecordSubscribeOptions = finalExpand ? { expand: finalExpand } : {};\n\n return this.getCollection().subscribe(\"*\", callback, options);\n }\n\n /**\n * Unsubscribe from a specific record's changes\n * @param id The ID of the record to unsubscribe from\n */\n unsubscribeFromRecord(id: string): void {\n this.getCollection().unsubscribe(id);\n }\n\n /**\n * Unsubscribe from collection-wide changes\n */\n unsubscribeFromCollection(): void {\n this.getCollection().unsubscribe(\"*\");\n }\n\n /**\n * Unsubscribe from all subscriptions in this collection\n */\n unsubscribeAll(): void {\n this.getCollection().unsubscribe();\n }\n}\n"]}
|
package/dist/mutator.d.cts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { RecordModel, RecordService, ListResult, RecordSubscription, UnsubscribeFunc } from 'pocketbase';
|
|
3
|
-
import { TypedPocketBase, UserType, UserInputType } from './types.cjs';
|
|
4
|
-
import 'zod';
|
|
5
|
-
import './user-BnFWg5tw.cjs';
|
|
1
|
+
import PocketBase, { RecordModel, RecordService, ListResult, RecordSubscription, UnsubscribeFunc } from 'pocketbase';
|
|
6
2
|
|
|
7
3
|
interface MutatorOptions {
|
|
8
4
|
expand: string[];
|
|
@@ -10,9 +6,9 @@ interface MutatorOptions {
|
|
|
10
6
|
sort: string[];
|
|
11
7
|
}
|
|
12
8
|
declare abstract class BaseMutator<T extends RecordModel, InputType> {
|
|
13
|
-
protected pb:
|
|
9
|
+
protected pb: PocketBase;
|
|
14
10
|
protected options: MutatorOptions;
|
|
15
|
-
constructor(pb:
|
|
11
|
+
constructor(pb: PocketBase, options?: Partial<MutatorOptions>);
|
|
16
12
|
private initializeOptions;
|
|
17
13
|
/**
|
|
18
14
|
* Initialize options with class-specific defaults
|
|
@@ -162,27 +158,4 @@ declare abstract class BaseMutator<T extends RecordModel, InputType> {
|
|
|
162
158
|
unsubscribeAll(): void;
|
|
163
159
|
}
|
|
164
160
|
|
|
165
|
-
|
|
166
|
-
protected setDefaults(): MutatorOptions;
|
|
167
|
-
protected getCollection(): PocketBase.RecordService<{
|
|
168
|
-
collectionName: string;
|
|
169
|
-
id: string;
|
|
170
|
-
collectionId: string;
|
|
171
|
-
expand: Record<string, any>;
|
|
172
|
-
created: string;
|
|
173
|
-
updated: string;
|
|
174
|
-
email: string;
|
|
175
|
-
password: string;
|
|
176
|
-
name?: string | undefined;
|
|
177
|
-
avatar?: File | undefined;
|
|
178
|
-
}>;
|
|
179
|
-
protected validateInput(input: UserInputType): Promise<{
|
|
180
|
-
email: string;
|
|
181
|
-
password: string;
|
|
182
|
-
passwordConfirm: string;
|
|
183
|
-
name?: string | undefined;
|
|
184
|
-
avatar?: File | undefined;
|
|
185
|
-
}>;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
export { UserMutator };
|
|
161
|
+
export { BaseMutator, type MutatorOptions };
|