Validates a grant file with comprehensive schema and business rule checking.
This function provides flexible validation with TypeScript overloads:
throwOnError
is false (or { throwOnError: false }
), returns a detailed validation resultthrowOnError
is true (default), throws specific errors or returns the validated grantThe grant file data to validate (unknown type for safety)
Validation options including grantee, operation, files, etc.
Either a GrantFile (when throwing) or GrantValidationResult (when not throwing)
// Throwing mode (default) - returns GrantFile or throws
const grant = validateGrant(data, {
grantee: '0x123...',
operation: 'llm_inference',
});
// Non-throwing mode - returns validation result
const result = validateGrant(data, {
grantee: '0x123...',
throwOnError: false
});
if (result.valid) {
console.log('Grant is valid:', result.grant);
} else {
console.log('Validation errors:', result.errors);
}
Validates a grant file with comprehensive schema and business rule checking.
This function provides flexible validation with TypeScript overloads:
throwOnError
is false (or { throwOnError: false }
), returns a detailed validation resultthrowOnError
is true (default), throws specific errors or returns the validated grantThe grant file data to validate (unknown type for safety)
Optional
options: Validation options including grantee, operation, files, etc.
Either a GrantFile (when throwing) or GrantValidationResult (when not throwing)
// Throwing mode (default) - returns GrantFile or throws
const grant = validateGrant(data, {
grantee: '0x123...',
operation: 'llm_inference',
});
// Non-throwing mode - returns validation result
const result = validateGrant(data, {
grantee: '0x123...',
throwOnError: false
});
if (result.valid) {
console.log('Grant is valid:', result.grant);
} else {
console.log('Validation errors:', result.errors);
}
Implementation function for grant validation with flexible return types
Param: data
The grant file data to validate
Param: options
Validation configuration options
Returns
Either a GrantFile or GrantValidationResult depending on throwOnError setting