ravendb
Version:
RavenDB client for Node.js
69 lines • 2.38 kB
JavaScript
import { StringUtil } from "../../../Utility/StringUtil.js";
import { throwError } from "../../../Exceptions/index.js";
import { RavenCommand } from "../../../Http/RavenCommand.js";
export class PutAttachmentOperation {
_documentId;
_name;
_stream;
_contentType;
_changeVector;
constructor(documentId, name, stream, contentType, changeVector) {
this._documentId = documentId;
this._name = name;
this._stream = stream;
this._contentType = contentType;
this._changeVector = changeVector;
}
getCommand(store, conventions, httpCache) {
return new PutAttachmentCommand(this._documentId, this._name, this._stream, this._contentType, this._changeVector);
}
get resultType() {
return "CommandResult";
}
}
export class PutAttachmentCommand extends RavenCommand {
_documentId;
_name;
_stream;
_contentType;
_changeVector;
constructor(documentId, name, stream, contentType, changeVector) {
super();
if (StringUtil.isNullOrWhitespace(documentId)) {
throwError("InvalidArgumentException", "DocumentId cannot be null or empty");
}
if (StringUtil.isNullOrWhitespace(name)) {
throwError("InvalidArgumentException", "Name cannot be null or empty");
}
this._documentId = documentId;
this._name = name;
this._stream = stream;
this._contentType = contentType;
this._changeVector = changeVector;
}
createRequest(node) {
let uri = node.url + "/databases/" + node.database
+ "/attachments?id=" + encodeURIComponent(this._documentId)
+ "&name=" + encodeURIComponent(this._name);
if (!StringUtil.isNullOrEmpty(this._contentType)) {
uri += "&contentType=" + encodeURIComponent(this._contentType);
}
const req = {
uri,
method: "PUT",
body: this._stream
};
this._addChangeVectorIfNotNull(this._changeVector, req);
return req;
}
async setResponseAsync(bodyStream, fromCache) {
let body = null;
this.result = await this._defaultPipeline(_ => body = _)
.process(bodyStream);
return body;
}
get isReadRequest() {
return false;
}
}
//# sourceMappingURL=PutAttachmentOperation.js.map