{"version":3,"file":"validation.mjs","names":[],"sources":["../../src/utils/validation.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { isValidSuiAddress } from '@mysten/sui/utils';\nimport { ValidationError, ConfigurationError } from './errors.js';\n\n/**\n * @description Validate that a required configuration value is set\n * @param {T | undefined} value - The value to validate\n * @param {string} errorMessage - Error message if validation fails\n * @returns {T} The validated value\n * @throws {ConfigurationError} If the value is not set\n */\nexport function validateRequired<T>(value: T | undefined, errorMessage: string): T {\n\tif (value === undefined || value === null) {\n\t\tthrow new ConfigurationError(errorMessage);\n\t}\n\treturn value;\n}\n\n/**\n * @description Validate that a Sui address is valid\n * @param {string} address - The address to validate\n * @param {string} [fieldName] - Name of the field for error messages (default 'Address')\n * @returns {string} The validated address\n * @throws {ValidationError} If the address is invalid\n */\nexport function validateAddress(address: string, fieldName: string = 'Address'): string {\n\tif (!isValidSuiAddress(address)) {\n\t\tthrow new ValidationError(`${fieldName} must be a valid Sui address`);\n\t}\n\treturn address;\n}\n\n/**\n * @description Validate that a number is positive\n * @param {number} value - The value to validate\n * @param {string} fieldName - Name of the field for error messages\n * @returns {number} The validated value\n * @throws {ValidationError} If the value is not positive\n */\nexport function validatePositiveNumber(value: number, fieldName: string): number {\n\tif (value <= 0) {\n\t\tthrow new ValidationError(`${fieldName} must be a positive number`);\n\t}\n\treturn value;\n}\n\n/**\n * @description Validate that a number is non-negative\n * @param {number} value - The value to validate\n * @param {string} fieldName - Name of the field for error messages\n * @returns {number} The validated value\n * @throws {ValidationError} If the value is negative\n */\nexport function validateNonNegativeNumber(value: number, fieldName: string): number {\n\tif (value < 0) {\n\t\tthrow new ValidationError(`${fieldName} must be non-negative`);\n\t}\n\treturn value;\n}\n\n/**\n * @description Validate that a value is within a specified range\n * @param {number} value - The value to validate\n * @param {number} min - Minimum allowed value (inclusive)\n * @param {number} max - Maximum allowed value (inclusive)\n * @param {string} fieldName - Name of the field for error messages\n * @returns {number} The validated value\n * @throws {ValidationError} If the value is outside the range\n */\nexport function validateRange(value: number, min: number, max: number, fieldName: string): number {\n\tif (value < min || value > max) {\n\t\tthrow new ValidationError(`${fieldName} must be between ${min} and ${max}`);\n\t}\n\treturn value;\n}\n\n/**\n * @description Validate array is not empty\n * @param {T[]} array - The array to validate\n * @param {string} fieldName - Name of the field for error messages\n * @returns {T[]} The validated array\n * @throws {ValidationError} If the array is empty\n */\nexport function validateNonEmptyArray<T>(array: T[], fieldName: string): T[] {\n\tif (!array || array.length === 0) {\n\t\tthrow new ValidationError(`${fieldName} cannot be empty`);\n\t}\n\treturn array;\n}\n"],"mappings":";;;;;;;;;;;AAaA,SAAgB,iBAAoB,OAAsB,cAAyB;AAClF,KAAI,UAAU,UAAa,UAAU,KACpC,OAAM,IAAI,mBAAmB,aAAa;AAE3C,QAAO;;;;;;;;;AAUR,SAAgB,gBAAgB,SAAiB,YAAoB,WAAmB;AACvF,KAAI,CAAC,kBAAkB,QAAQ,CAC9B,OAAM,IAAI,gBAAgB,GAAG,UAAU,8BAA8B;AAEtE,QAAO;;;;;;;;;AAUR,SAAgB,uBAAuB,OAAe,WAA2B;AAChF,KAAI,SAAS,EACZ,OAAM,IAAI,gBAAgB,GAAG,UAAU,4BAA4B;AAEpE,QAAO;;;;;;;;;AAUR,SAAgB,0BAA0B,OAAe,WAA2B;AACnF,KAAI,QAAQ,EACX,OAAM,IAAI,gBAAgB,GAAG,UAAU,uBAAuB;AAE/D,QAAO;;;;;;;;;;;AAYR,SAAgB,cAAc,OAAe,KAAa,KAAa,WAA2B;AACjG,KAAI,QAAQ,OAAO,QAAQ,IAC1B,OAAM,IAAI,gBAAgB,GAAG,UAAU,mBAAmB,IAAI,OAAO,MAAM;AAE5E,QAAO;;;;;;;;;AAUR,SAAgB,sBAAyB,OAAY,WAAwB;AAC5E,KAAI,CAAC,SAAS,MAAM,WAAW,EAC9B,OAAM,IAAI,gBAAgB,GAAG,UAAU,kBAAkB;AAE1D,QAAO"}