lib/types.js
function Field(schema, opts) {
  var name = schema.name;
  if (typeof name != 'string' || !isValidName(name)) {
    throw new Error(f('invalid field name: %s', name));
  }

  this.name = name;
  this.type = Type.forSchema(schema.type, opts);
  this.aliases = schema.aliases || [];
  this.doc = schema.doc !== undefined ? '' + schema.doc : undefined;

  this._order = (function (order) {
    switch (order) {
      case 'ascending':
        return 1;
      case 'descending':
        return -1;
      case 'ignore':
        return 0;
      default:
        throw new Error(f('invalid order: %j', order));
    }
  })(schema.order === undefined ? 'ascending' : schema.order);

  var value = schema['default'];
  if (value !== undefined) {
    // We need to convert defaults back to a valid format (unions are
    // disallowed in default definitions, only the first type of each union is
    // allowed instead).
    // http://apache-avro.679487.n3.nabble.com/field-union-default-in-Java-td1175327.html
    var type = this.type;
    var val = type._copy(value, {coerce: 2, wrap: 2});
    // The clone call above will throw an error if the default is invalid.
    if (isPrimitive(type.typeName) && type.typeName !== 'bytes') {
      // These are immutable.
      this.defaultValue = function () { return val; };
    } else {
      this.defaultValue = function () { return type._copy(val); };
    }
  }

  Object.freeze(this);
}
function Field(schema, opts) {
  var name = schema.name;
  if (typeof name != 'string' || !isValidName(name)) {
    throw new Error(f('invalid field name: %s', name));
  }

  this.name = name;
  this.type = Type.forSchema(schema.type, opts);
  this.aliases = schema.aliases || [];
  this.doc = schema.doc !== undefined ? '' + schema.doc : undefined;

  this._order = (function (order) {
    switch (order) {
      case 'ascending':
        return 1;
      case 'descending':
        return -1;
      case 'ignore':
        return 0;
      default:
        throw new Error(f('invalid order: %j', order));
    }
  })(schema.order === undefined ? 'ascending' : schema.order);

  var value = schema['default'];
  if (value !== undefined) {
    // We need to convert defaults back to a valid format (unions are
    // disallowed in default definitions, only the first type of each union is
    // allowed instead).
    // http://apache-avro.679487.n3.nabble.com/field-union-default-in-Java-td1175327.html
    var type = this.type;
    var val = type._copy(value, {coerce: 2, wrap: 2});
    // The clone call above will throw an error if the default is invalid.
    if (isPrimitive(type.typeName) && type.typeName !== 'bytes') {
      // These are immutable.
      this.defaultValue = function () { return val; };
    } else {
      this.defaultValue = function () { return type._copy(val); };
    }
  }

  Object.freeze(this);
}
function Field ( schema , opts ) { var name = schema . name ; if ( typeof name != 'string' || ! isValidName ( name ) ) { throw new Error ( f ( 'invalid field name: %s' , name ) ) ; } this . name = name ; this . type = Type . forSchema ( schema . type , opts ) ; this . aliases = schema . aliases || [ ] ; this . doc = schema . doc !== undefined ? '' + schema . doc : undefined ; this . _order = ( function ( order ) { switch ( order ) { case 'ascending' : return 1 ; case 'descending' : return - 1 ; case 'ignore' : return 0 ; default : throw new Error ( f ( 'invalid order: %j' , order ) ) ; } } ) ( schema . order === undefined ? 'ascending' : schema . order ) ; var value = schema [ 'default' ] ; if ( value !== undefined ) { // We need to convert defaults back to a valid format (unions are // disallowed in default definitions, only the first type of each union is // allowed instead). // http://apache-avro.679487.n3.nabble.com/field-union-default-in-Java-td1175327.html var type = this . type ; var val = type . _copy ( value , { coerce : 2 , wrap : 2 } ) ; // The clone call above will throw an error if the default is invalid. if ( isPrimitive ( type . typeName ) && type . typeName !== 'bytes' ) { // These are immutable. this . defaultValue = function ( ) { return val ; } ; } else { this . defaultValue = function ( ) { return type . _copy ( val ) ; } ; } } Object . freeze ( this ) ; }
A record field.
A record field .