mongodb-stitch
Version:
[](https://gitter.im/mongodb/stitch?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
61 lines • 3.2 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports", "../../internal/common/Base64", "../../internal/net/Method", "../../internal/net/StitchAuthDocRequest", "../../internal/net/StitchAuthRequest"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Base64_1 = require("../../internal/common/Base64");
var Method_1 = __importDefault(require("../../internal/net/Method"));
var StitchAuthDocRequest_1 = require("../../internal/net/StitchAuthDocRequest");
var StitchAuthRequest_1 = require("../../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_1.StitchAuthRequest.Builder();
reqBuilder
.withMethod(Method_1.default.GET)
.withPath(this.serviceRoutes.functionCallRoute +
("?stitch_request=" + encodeURIComponent(Base64_1.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_1.StitchAuthDocRequest.Builder();
reqBuilder
.withMethod(Method_1.default.POST)
.withPath(this.serviceRoutes.functionCallRoute);
reqBuilder.withDocument(body);
return reqBuilder.build();
};
return CoreStitchServiceClientImpl;
}());
exports.default = CoreStitchServiceClientImpl;
});
//# sourceMappingURL=CoreStitchServiceClientImpl.js.map