mongodb-stitch
Version:
[](https://gitter.im/mongodb/stitch?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
61 lines • 2.5 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { StitchRequest } from "./StitchRequest";
import Headers from "./Headers";
import ContentTypes from "./ContentTypes";
import { EJSON } from "bson";
var StitchDocRequest = (function (_super) {
__extends(StitchDocRequest, _super);
function StitchDocRequest(request, document) {
var _this = _super.call(this, request.method, request.path, request.headers, request.startedAt, request.body) || this;
_this.document = document;
return _this;
}
Object.defineProperty(StitchDocRequest.prototype, "builder", {
get: function () {
return new StitchDocRequest.Builder(this);
},
enumerable: true,
configurable: true
});
return StitchDocRequest;
}(StitchRequest));
export { StitchDocRequest };
(function (StitchDocRequest) {
var Builder = (function (_super) {
__extends(Builder, _super);
function Builder(request) {
var _this = _super.call(this, request) || this;
if (request !== undefined) {
_this.document = request.document;
}
return _this;
}
Builder.prototype.withDocument = function (document) {
this.document = document;
return this;
};
Builder.prototype.build = function () {
if (this.document === undefined || !(this.document instanceof Object)) {
throw new Error("document must be set");
}
if (this.headers === undefined) {
this.withHeaders({});
}
this.headers[Headers.CONTENT_TYPE] = ContentTypes.APPLICATION_JSON;
this.withBody(EJSON.stringify(this.document, { relaxed: false }));
return new StitchDocRequest(_super.prototype.build.call(this), this.document);
};
return Builder;
}(StitchRequest.Builder));
StitchDocRequest.Builder = Builder;
})(StitchDocRequest || (StitchDocRequest = {}));
//# sourceMappingURL=StitchDocRequest.js.map