getRevision method

Future<RevisionResponse> getRevision(
  1. String kref
)
inherited

Gets a revision by its kref URI, with optional tag/time resolution.

kref can include the revision number (e.g., '?r=1'), or a tag (?t=/?tag=) or timestamp (?time=) query parameter. When a tag or time is present the kref is resolved via resolveKref; otherwise the revision is fetched directly.

Implementation

Future<RevisionResponse> getRevision(String kref) async {
  var baseKref = kref;
  String? tag;
  String? time;

  final queryIndex = kref.indexOf('?');
  if (queryIndex >= 0) {
    baseKref = kref.substring(0, queryIndex);
    final params = kref.substring(queryIndex + 1).split('&');
    for (final param in params) {
      if (param.startsWith('t=') || param.startsWith('tag=')) {
        tag = param.substring(param.indexOf('=') + 1);
      } else if (param.startsWith('time=')) {
        time = param.substring(param.indexOf('=') + 1);
        // Validate time format (YYYYMMDDHHMM).
        if (!RegExp(r'^\d{12}$').hasMatch(time)) {
          throw const KumihoError('time must be in YYYYMMDDHHMM format');
        }
      }
    }
  }

  if (tag != null || time != null) {
    // Resolve the base (item) kref with the supplied constraints.
    return resolveKref(baseKref, tag: tag, time: time);
  }

  final request = KrefRequest()..kref = Kref(uri: kref);
  final response = await stub.getRevision(request, options: callOptions);
  return response;
}