validate static method

void validate(
  1. Map<String, dynamic> config
)

Checks the optional geodata section without changing config.

Every asset URL must use HTTPS. Enabled schedules additionally require at most 100 assets with .dat targets and recognized constant intervals of at least one minute. Throws ArgumentError for malformed inspected fields. Core validates remaining cron grammar, paths, native capabilities and download/decoded-size limits.

Implementation

static void validate(Map<String, dynamic> config) {
  final value = readXraySchemaField(config, 'geodata');
  if (value == null) return;
  if (value is! Map<String, dynamic>) {
    throw ArgumentError('Xray geodata must be a JSON object');
  }
  final cron = readXraySchemaField(value, 'cron');
  if (cron != null && cron is! String) {
    throw ArgumentError('Xray geodata cron must be a string');
  }
  if (cron == '') {
    throw ArgumentError(
        'Xray geodata cron must not be empty; omit it to disable scheduling');
  }
  final outbound = readXraySchemaField(value, 'outbound');
  if (outbound != null && outbound is! String) {
    throw ArgumentError('Xray geodata outbound must be a string');
  }
  final rawAssets = readXraySchemaField(value, 'assets');
  if (rawAssets != null && rawAssets is! List) {
    throw ArgumentError('Xray geodata assets must be an array');
  }
  final assets = rawAssets as List? ?? const [];
  final active = cron is String && cron.isNotEmpty;
  if (active && assets.length > 100) {
    throw ArgumentError('Xray geodata supports at most 100 assets');
  }
  if (active) {
    final delay = _constantDelayNanoseconds(cron);
    if (delay != null && delay < BigInt.from(60000000000)) {
      throw ArgumentError(
          'Xray geodata interval must be at least one minute');
    }
  }
  for (var index = 0; index < assets.length; index++) {
    final asset = assets[index];
    if (asset is! Map<String, dynamic>) {
      throw ArgumentError(
          'Xray geodata asset at index $index must be an object');
    }
    final url = readXraySchemaField(asset, 'url');
    final uri = url is String ? Uri.tryParse(url) : null;
    // Build validates URLs even when cron is absent/empty. Do not include
    // URLs or local file values in exceptions or diagnostic reports.
    if (uri == null ||
        uri.scheme != 'https' ||
        !uri.hasAuthority ||
        uri.host.isEmpty) {
      throw ArgumentError(
          'Xray geodata asset at index $index requires an HTTPS URL');
    }
    final file = readXraySchemaField(asset, 'file');
    if (file != null && file is! String) {
      throw ArgumentError(
          'Xray geodata asset at index $index has an invalid file type');
    }
    if (active && (file is! String || !file.toLowerCase().endsWith('.dat'))) {
      throw ArgumentError(
          'Xray geodata asset at index $index requires a .dat file');
    }
  }
}