mirror of https://github.com/grpc/grpc-web.git
Add @interface MethodDescroptorInterface
This commit is contained in:
parent
f1e3cbff5f
commit
dfa6e478f2
|
|
@ -182,6 +182,7 @@ closure_js_library(
|
|||
name = "requester",
|
||||
srcs = [
|
||||
"methoddescriptor.js",
|
||||
"methoddescriptorinterface.js",
|
||||
"request.js",
|
||||
"requestinternal.js",
|
||||
"unaryresponse.js",
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ goog.module.declareLegacyNamespace();
|
|||
|
||||
const CallOptions = goog.require('grpc.web.CallOptions');
|
||||
const Metadata = goog.requireType('grpc.web.Metadata');
|
||||
const MethodDescriptorInterface = goog.requireType('grpc.web.MethodDescriptorInterface');
|
||||
const MethodType = goog.requireType('grpc.web.MethodType');
|
||||
const Request = goog.requireType('grpc.web.Request');
|
||||
const RequestInternal = goog.require('grpc.web.RequestInternal');
|
||||
|
|
@ -16,50 +17,51 @@ const UnaryResponse = goog.requireType('grpc.web.UnaryResponse');
|
|||
const UnaryResponseInternal = goog.require('grpc.web.UnaryResponseInternal');
|
||||
const {Status} = goog.requireType('grpc.web.Status');
|
||||
|
||||
/** @template REQUEST, RESPONSE */
|
||||
class MethodDescriptor {
|
||||
/**
|
||||
* @param {string} name
|
||||
* @param {!MethodType} methodType
|
||||
* @param {function(new: REQUEST, ...)} requestType
|
||||
* @param {function(new: RESPONSE, ...)} responseType
|
||||
* @param {function(REQUEST): ?} requestSerializeFn
|
||||
* @param {function(?): RESPONSE} responseDeserializeFn
|
||||
*/
|
||||
constructor(
|
||||
name, methodType, requestType, responseType, requestSerializeFn,
|
||||
responseDeserializeFn) {
|
||||
/** @const */
|
||||
this.name = name;
|
||||
/** @const */
|
||||
this.methodType = methodType;
|
||||
/** @const */
|
||||
this.requestType = requestType;
|
||||
/** @const */
|
||||
this.responseType = responseType;
|
||||
/** @const */
|
||||
this.requestSerializeFn = requestSerializeFn;
|
||||
/** @const */
|
||||
this.responseDeserializeFn = responseDeserializeFn;
|
||||
}
|
||||
/**
|
||||
* @constructor
|
||||
* @final
|
||||
* @implements {MethodDescriptorInterface}
|
||||
* @template REQUEST, RESPONSE
|
||||
* @param {string} name
|
||||
* @param {?MethodType} methodType
|
||||
* @param {function(new: REQUEST, ?Array=)} requestType
|
||||
* @param {function(new: RESPONSE, ?Array=)} responseType
|
||||
* @param {function(REQUEST): ?} requestSerializeFn
|
||||
* @param {function(?): RESPONSE} responseDeserializeFn
|
||||
*/
|
||||
const MethodDescriptor = function(
|
||||
name, methodType, requestType, responseType, requestSerializeFn,
|
||||
responseDeserializeFn) {
|
||||
/** @const */
|
||||
this.name = name;
|
||||
/** @const */
|
||||
this.methodType = methodType;
|
||||
/** @const */
|
||||
this.requestType = requestType;
|
||||
/** @const */
|
||||
this.responseType = responseType;
|
||||
/** @const */
|
||||
this.requestSerializeFn = requestSerializeFn;
|
||||
/** @const */
|
||||
this.responseDeserializeFn = responseDeserializeFn;
|
||||
};
|
||||
|
||||
/**
|
||||
* @template REQUEST, RESPONSE
|
||||
* @param {REQUEST} requestMessage
|
||||
* @param {!Metadata=} metadata
|
||||
* @param {!CallOptions=} callOptions
|
||||
* @return {!Request<REQUEST, RESPONSE>}
|
||||
*/
|
||||
createRequest(
|
||||
requestMessage, metadata = {}, callOptions = new CallOptions()) {
|
||||
return new RequestInternal(requestMessage, this, metadata, callOptions);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @override
|
||||
* @param {REQUEST} requestMessage
|
||||
* @param {!Metadata=} metadata
|
||||
* @param {!CallOptions=} callOptions
|
||||
* @return {!Request<REQUEST, RESPONSE>}
|
||||
*/
|
||||
MethodDescriptor.prototype.createRequest = function(
|
||||
requestMessage, metadata = {}, callOptions = new CallOptions()) {
|
||||
return new RequestInternal(requestMessage, this, metadata, callOptions);
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @template REQUEST, RESPONSE
|
||||
* @override
|
||||
* @param {RESPONSE} responseMessage
|
||||
* @param {!Metadata=} metadata
|
||||
* @param {?Status=} status
|
||||
|
|
|
|||
|
|
@ -0,0 +1,63 @@
|
|||
/**
|
||||
* @fileoverview Description of this file.
|
||||
*
|
||||
* A templated class that is used to address gRPC Web requests.
|
||||
*/
|
||||
|
||||
goog.module('grpc.web.MethodDescriptorInterface');
|
||||
goog.module.declareLegacyNamespace();
|
||||
|
||||
const CallOptions = goog.requireType('grpc.web.CallOptions');
|
||||
const Metadata = goog.requireType('grpc.web.Metadata');
|
||||
const MethodType = goog.requireType('grpc.web.MethodType');
|
||||
const Request = goog.requireType('grpc.web.Request');
|
||||
const UnaryResponse = goog.requireType('grpc.web.UnaryResponse');
|
||||
const {Status} = goog.requireType('grpc.web.Status');
|
||||
|
||||
/**
|
||||
* @interface
|
||||
* @template REQUEST, RESPONSE
|
||||
*/
|
||||
const MethodDescriptorInterface = function() {};
|
||||
|
||||
/** @type {string} */
|
||||
MethodDescriptorInterface.prototype.name;
|
||||
|
||||
/** @type {?MethodType} */
|
||||
MethodDescriptorInterface.prototype.methodType;
|
||||
|
||||
/** @type {function(new: REQUEST, ?Array=)} */
|
||||
MethodDescriptorInterface.prototype.requestType;
|
||||
|
||||
/** @type {function(new: RESPONSE, ?Array=)} */
|
||||
MethodDescriptorInterface.prototype.responseType;
|
||||
|
||||
/** @type {function(REQUEST): ?} */
|
||||
MethodDescriptorInterface.prototype.requestSerializeFn;
|
||||
|
||||
/** @type {function(?): RESPONSE} */
|
||||
MethodDescriptorInterface.prototype.responseDeserializeFn;
|
||||
|
||||
/**
|
||||
* @template REQUEST, RESPONSE
|
||||
* @param {REQUEST} requestMessage
|
||||
* @param {!Metadata=} metadata
|
||||
* @param {!CallOptions=} callOptions
|
||||
* @return {!Request<REQUEST, RESPONSE>}
|
||||
*/
|
||||
MethodDescriptorInterface.prototype.createRequest = function(
|
||||
requestMessage, metadata, callOptions) {};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @template REQUEST, RESPONSE
|
||||
* @param {RESPONSE} responseMessage
|
||||
* @param {!Metadata=} metadata
|
||||
* @param {?Status=} status
|
||||
* @return {!UnaryResponse<REQUEST, RESPONSE>}
|
||||
*/
|
||||
MethodDescriptorInterface.prototype.createUnaryResponse = function(
|
||||
responseMessage, metadata, status) {};
|
||||
|
||||
exports = MethodDescriptorInterface;
|
||||
Loading…
Reference in New Issue