copyDocument method

Future copyDocument(
  1. String? sourceId,
  2. String? destinationId, [
  3. String? rev
])

Copies the source document to the destination document with an optional revision. NOTE this method uses the CouchDB COPY method which is not standard HTTP.

Implementation

Future<dynamic> copyDocument(String? sourceId, String? destinationId,
    [String? rev]) {
  if (sourceId == null) {
    return _raiseException(WiltException.copyDocNoSrcId);
  }

  if (destinationId == null) {
    return _raiseException(WiltException.copyDocNoDestId);
  }

  var url = sourceId;

  // Create the special COPY header
  final headers = <String, String>{};
  var destination = destinationId;
  if (rev != null) {
    destination = '$destinationId?rev=$rev';
  }
  headers['Destination'] = destination;

  url = _conditionUrl(url);
  return _httpRequest('COPY_DOCUMENT', url, headers: headers);
}