lib/core/queueHandler.js
function validateMessageFormat(message) {
  function validateTypeStructure(message) {
    const typeParts = message.type.split('.'),
      baseType = typeParts[0],
      typeDepth = typeParts.length;

    if (typeDepth > 2)
      throw new Error(
        'Message type has too many dot separated sections: ' + message.type
      );

    const previousDepth = messageTypeDepths[baseType];

    if (previousDepth && previousDepth !== typeDepth) {
      throw new Error(
        `All messages of type ${baseType} must have the same structure. ` +
          `${
            message.type
          } has ${typeDepth} part(s), but earlier messages had ${previousDepth} part(s).`
      );
    }

    messageTypeDepths[baseType] = typeDepth;
  }

  function validatePageSummary(message) {
    const type = message.type;
    if (!type.endsWith('.pageSummary')) return;

    if (!message.url)
      throw new Error(`Page summary message (${type}) didn't specify a url`);

    if (!message.group)
      throw new Error(`Page summary message (${type}) didn't specify a group.`);
  }

  function validateSummaryMessage(message) {
    const type = message.type;
    if (!type.endsWith('.summary')) return;

    if (message.url)
      throw new Error(
        `Summary message (${type}) shouldn't be url specific, use .pageSummary instead.`
      );

    if (!message.group)
      throw new Error(`Summary message (${type}) didn't specify a group.`);

    const groups = groupsPerSummaryType[type] || [];
    if (groups.includes(message.group)) {
      throw new Error(
        `Multiple summary messages of type ${type} and group ${message.group}`
      );
    }
    groupsPerSummaryType[type] = groups.concat(message.group);
  }

  validateTypeStructure(message);
  validatePageSummary(message);
  validateSummaryMessage(message);
}
function validateMessageFormat(message) {
  function validateTypeStructure(message) {
    const typeParts = message.type.split('.'),
      baseType = typeParts[0],
      typeDepth = typeParts.length;

    if (typeDepth > 2)
      throw new Error(
        'Message type has too many dot separated sections: ' + message.type
      );

    const previousDepth = messageTypeDepths[baseType];

    if (previousDepth && previousDepth !== typeDepth) {
      throw new Error(
        `All messages of type ${baseType} must have the same structure. ` +
          `${
            message.type
          } has ${typeDepth} part(s), but earlier messages had ${previousDepth} part(s).`
      );
    }

    messageTypeDepths[baseType] = typeDepth;
  }

  function validatePageSummary(message) {
    const type = message.type;
    if (!type.endsWith('.pageSummary')) return;

    if (!message.url)
      throw new Error(`Page summary message (${type}) didn't specify a url`);

    if (!message.group)
      throw new Error(`Page summary message (${type}) didn't specify a group.`);
  }

  function validateSummaryMessage(message) {
    const type = message.type;
    if (!type.endsWith('.summary')) return;

    if (message.url)
      throw new Error(
        `Summary message (${type}) shouldn't be url specific, use .pageSummary instead.`
      );

    if (!message.group)
      throw new Error(`Summary message (${type}) didn't specify a group.`);

    const groups = groupsPerSummaryType[type] || [];
    if (groups.includes(message.group)) {
      throw new Error(
        `Multiple summary messages of type ${type} and group ${message.group}`
      );
    }
    groupsPerSummaryType[type] = groups.concat(message.group);
  }

  validateTypeStructure(message);
  validatePageSummary(message);
  validateSummaryMessage(message);
}
function validateMessageFormat ( message ) { function validateTypeStructure ( message ) { const typeParts = message . type . split ( '.' ) , baseType = typeParts [ 0 ] , typeDepth = typeParts . length ; if ( typeDepth > 2 ) throw new Error ( 'Message type has too many dot separated sections: ' + message . type ) ; const previousDepth = messageTypeDepths [ baseType ] ; if ( previousDepth && previousDepth !== typeDepth ) { throw new Error ( ` ${ baseType } ` + ` ${ message . type } ${ typeDepth } ${ previousDepth } ` ) ; } messageTypeDepths [ baseType ] = typeDepth ; } function validatePageSummary ( message ) { const type = message . type ; if ( ! type . endsWith ( '.pageSummary' ) ) return ; if ( ! message . url ) throw new Error ( ` ${ type } ` ) ; if ( ! message . group ) throw new Error ( ` ${ type } ` ) ; } function validateSummaryMessage ( message ) { const type = message . type ; if ( ! type . endsWith ( '.summary' ) ) return ; if ( message . url ) throw new Error ( ` ${ type } ` ) ; if ( ! message . group ) throw new Error ( ` ${ type } ` ) ; const groups = groupsPerSummaryType [ type ] || [ ] ; if ( groups . includes ( message . group ) ) { throw new Error ( ` ${ type } ${ message . group } ` ) ; } groupsPerSummaryType [ type ] = groups . concat ( message . group ) ; } validateTypeStructure ( message ) ; validatePageSummary ( message ) ; validateSummaryMessage ( message ) ; }
Check some message format best practices that applies to sitespeed.io.
Throws an error if message doesn't follow the rules.
@param message the message to check
Check some message format best practices that applies to sitespeed . io . Throws an error if message doesn t follow the rules .