mongodb-stitch
Version:
[](https://gitter.im/mongodb/stitch?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
46 lines • 2.21 kB
JavaScript
import { base64Encode } from "../../internal/common/Base64";
import Method from "../../internal/net/Method";
import { StitchAuthDocRequest } from "../../internal/net/StitchAuthDocRequest";
import { StitchAuthRequest } from "../../internal/net/StitchAuthRequest";
var CoreStitchServiceClientImpl = (function () {
function CoreStitchServiceClientImpl(requestClient, routes, name) {
this.requestClient = requestClient;
this.serviceRoutes = routes;
this.serviceName = name;
}
CoreStitchServiceClientImpl.prototype.callFunction = function (name, args, decoder) {
return this.requestClient.doAuthenticatedRequestWithDecoder(this.getCallServiceFunctionRequest(name, args), decoder);
};
CoreStitchServiceClientImpl.prototype.streamFunction = function (name, args, decoder) {
return this.requestClient.openAuthenticatedStreamWithDecoder(this.getStreamServiceFunctionRequest(name, args), decoder);
};
CoreStitchServiceClientImpl.prototype.getStreamServiceFunctionRequest = function (name, args) {
var body = { name: name };
if (this.serviceName !== undefined) {
body["service"] = this.serviceName;
}
body["arguments"] = args;
var reqBuilder = new StitchAuthRequest.Builder();
reqBuilder
.withMethod(Method.GET)
.withPath(this.serviceRoutes.functionCallRoute +
("?stitch_request=" + encodeURIComponent(base64Encode(JSON.stringify(body)))));
return reqBuilder.build();
};
CoreStitchServiceClientImpl.prototype.getCallServiceFunctionRequest = function (name, args) {
var body = { name: name };
if (this.serviceName !== undefined) {
body["service"] = this.serviceName;
}
body["arguments"] = args;
var reqBuilder = new StitchAuthDocRequest.Builder();
reqBuilder
.withMethod(Method.POST)
.withPath(this.serviceRoutes.functionCallRoute);
reqBuilder.withDocument(body);
return reqBuilder.build();
};
return CoreStitchServiceClientImpl;
}());
export default CoreStitchServiceClientImpl;
//# sourceMappingURL=CoreStitchServiceClientImpl.js.map