{"version":3,"file":"get-field-value.mjs","names":[],"sources":["../../../../../../../@warlock.js/seal/src/helpers/get-field-value.ts"],"sourcesContent":["import { get } from \"@mongez/reinforcements\";\r\nimport type { ContextualSchemaRule, SchemaContext } from \"../types\";\r\n\r\n/**\r\n * Get field value based on scope from rule options\r\n *\r\n * This utility extracts a field value from either the global context or sibling context\r\n * based on the `scope` option in the rule's context.\r\n *\r\n * @param rule - The contextual schema rule containing options with:\r\n *   - `field` (or custom fieldKey): The field name to extract\r\n *   - `scope` (optional): Either \"global\" (default) or \"sibling\"\r\n * @param context - The schema validation context containing allValues and parent\r\n * @param fieldKey - The key in rule.context.options that contains the field name (defaults to \"field\")\r\n *\r\n * @returns The value of the specified field from the appropriate source\r\n *\r\n * @example\r\n * // In a validation rule with scope support:\r\n * async validate(value: any, context) {\r\n *   const otherFieldValue = getFieldValue(this, context);\r\n *   // Extracts from context.allValues if scope is \"global\"\r\n *   // Extracts from context.parent if scope is \"sibling\"\r\n * }\r\n *\r\n * @example\r\n * // Using a custom field key:\r\n * async validate(value: any, context) {\r\n *   const compareValue = getFieldValue(this, context, \"compareField\");\r\n *   // Looks for rule.context.options.compareField instead of .field\r\n * }\r\n *\r\n * @remarks\r\n * - **Global scope** (`scope: \"global\"`): Searches the entire input data (context.allValues)\r\n * - **Sibling scope** (`scope: \"sibling\"`): Searches only within the parent object (context.parent)\r\n * - Uses `@mongez/reinforcements.get()` to support nested paths (e.g., \"user.email\")\r\n */\r\nexport function getFieldValue(\r\n  rule: ContextualSchemaRule,\r\n  context: SchemaContext,\r\n  fieldKey = \"field\",\r\n) {\r\n  const field = rule.context.options[fieldKey];\r\n  const scope = rule.context.options.scope || \"global\";\r\n  const source = scope === \"sibling\" ? context.parent : context.allValues;\r\n  return get(source, field);\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,SAAgB,cACd,MACA,SACA,WAAW,SACX;CACA,MAAM,QAAQ,KAAK,QAAQ,QAAQ;CAGnC,OAAO,KAFO,KAAK,QAAQ,QAAQ,SAAS,cACnB,YAAY,QAAQ,SAAS,QAAQ,WAC3C,KAAK;AAC1B"}