AtUri.parseStrict constructor

AtUri.parseStrict(
  1. String uri
)

Returns the new instance of parsed AT URI after validating uri with ensureValidAtUri.

Unlike AtUri.parse, this factory enforces the full AT URI syntax rules: the URI must start with at://, the authority must be a valid handle or DID, the first path segment (if any) must be a valid NSID, the second path segment (if any) must be a valid Record Key, and so on.

Note that ensureValidAtUri itself intentionally does not validate the record key segment, matching the official atproto implementation; the record key check here mirrors the official strict AT URI parsing behavior.

Throws an InvalidAtUriError if uri is not a valid AT URI.

Implementation

factory AtUri.parseStrict(final String uri) {
  ensureValidAtUri(uri);

  final atUri = CheckedAtUri(uri);

  final rkey = atUri.rkeyOrNull;
  if (rkey != null) {
    try {
      ensureValidRecordKey(rkey);
    } on InvalidRecordKeyError catch (e) {
      throw InvalidAtUriError(
        'ATURI requires second path segment (if supplied) to be a valid '
        'record key: ${e.message}',
      );
    }
  }

  return atUri;
}