Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exploring ES modules support #1

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions javascript/net/grpc/web/abstractclientbase.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,17 @@
*
* @author [email protected] (Stanley Cheung)
*/
goog.module('grpc.web.AbstractClientBase');

goog.module.declareLegacyNamespace();


const ClientReadableStream = goog.require('grpc.web.ClientReadableStream');
const Error = goog.require('grpc.web.Error');
const MethodDescriptor = goog.require('grpc.web.MethodDescriptor');
const MethodType = goog.require('grpc.web.MethodType');
import { ClientReadableStream } from "./clientreadablestream.js";
import { Error } from "./error.js";
import { MethodDescriptor } from "./methoddescriptor.js";
import { MethodType } from "./methodtype.js";


/**
* This interface represents a grpc-web client
* @interface
*/
const AbstractClientBase = class {
export const AbstractClientBase = class {
constructor() {}

/**
Expand Down Expand Up @@ -145,7 +140,3 @@ AbstractClientBase.MethodInfo = class {
this.responseDeserializeFn = responseDeserializeFn;
}
};



exports = AbstractClientBase;
9 changes: 1 addition & 8 deletions javascript/net/grpc/web/calloptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
* @fileoverview grpc.web.CallOptions
*/

goog.module('grpc.web.CallOptions');
goog.module.declareLegacyNamespace();

/**
* The collection of runtime options for a new RPC call.
* @unrestricted
*/
class CallOptions {
export class CallOptions {
/**
* @param {!Object<string, !Object>=} options
*/
Expand Down Expand Up @@ -60,7 +57,3 @@ class CallOptions {
return Object.keys(this.properties_);
}
}



exports = CallOptions;
9 changes: 2 additions & 7 deletions javascript/net/grpc/web/clientoptions.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
goog.module('grpc.web.ClientOptions');
goog.module.declareLegacyNamespace();

const {StreamInterceptor, UnaryInterceptor} = goog.require('grpc.web.Interceptor');
import { StreamInterceptor, UnaryInterceptor } from "./interceptor.js";


/**
* Options that are availavle during the client construction.
* @record
*/
class ClientOptions {
export class ClientOptions {
constructor() {
/**
* Whether to use the HttpCors library to pack http headers into a special
Expand Down Expand Up @@ -46,5 +43,3 @@ class ClientOptions {
this.format;
}
}

exports = ClientOptions;
10 changes: 1 addition & 9 deletions javascript/net/grpc/web/clientreadablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@
*
* @author [email protected] (Stanley Cheung)
*/
goog.module('grpc.web.ClientReadableStream');

goog.module.declareLegacyNamespace();



/**
Expand All @@ -39,7 +35,7 @@ goog.module.declareLegacyNamespace();
* @template RESPONSE
* @interface
*/
const ClientReadableStream = function() {};
export const ClientReadableStream = function() {};


/**
Expand Down Expand Up @@ -69,7 +65,3 @@ ClientReadableStream.prototype.removeListener = goog.abstractMethod;
* Close the stream.
*/
ClientReadableStream.prototype.cancel = goog.abstractMethod;



exports = ClientReadableStream;
12 changes: 3 additions & 9 deletions javascript/net/grpc/web/clientunarycallimpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
* calls.
*/

goog.module('grpc.web.ClientUnaryCallImpl');

goog.module.declareLegacyNamespace();

const ClientReadableStream = goog.require('grpc.web.ClientReadableStream');
import { ClientReadableStream } from "./clientreadablestream.js";

/**
* @implements {ClientReadableStream<RESPONSE>}
* @template RESPONSE
*/
class ClientUnaryCallImpl {
export class ClientUnaryCallImpl {
/**
* @param {!ClientReadableStream<RESPONSE>} stream
*/
Expand Down Expand Up @@ -46,6 +42,4 @@ class ClientUnaryCallImpl {
cancel() {
this.stream.cancel();
}
}

exports = ClientUnaryCallImpl;
}
9 changes: 1 addition & 8 deletions javascript/net/grpc/web/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,10 @@
*
* @author [email protected] (Stanley Cheung)
*/
goog.module('grpc.web.Error');

goog.module.declareLegacyNamespace();

const Metadata = goog.require('grpc.web.Metadata');


/** @record */
function Error() {}
export function Error() {}

/** @export {(number|undefined)} */
Error.prototype.code;
Expand All @@ -40,5 +35,3 @@ Error.prototype.message;

/** @export {(?Metadata|undefined)} */
Error.prototype.metadata;

exports = Error;
13 changes: 4 additions & 9 deletions javascript/net/grpc/web/genericclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@
* @fileoverview base interface for grpc web GenericClient.
*/

goog.module('grpc.web.GenericClient');
goog.module.declareLegacyNamespace();

const MethodDescriptor = goog.require('grpc.web.MethodDescriptor');
const Request = goog.require('grpc.web.Request');
const UnaryResponse = goog.require('grpc.web.UnaryResponse');
import { MethodDescriptor } from "./methoddescriptor.js"
import { Request } from "./request.js"
import { UnaryResponse } from "./unaryresponse.js"

/**
* @interface
*/
const GenericClient = function() {};
export const GenericClient = function() {};


/**
Expand All @@ -37,5 +34,3 @@ GenericClient.prototype.unaryCall = function(request) {};
* @abstract
*/
GenericClient.prototype.call = function(requestMessage, methodDescriptor) {};

exports = GenericClient;
12 changes: 3 additions & 9 deletions javascript/net/grpc/web/generictransportinterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,13 @@
*
* @author [email protected] (Stanley Cheung)
*/
goog.module('grpc.web.GenericTransportInterface');

goog.module.declareLegacyNamespace();


const NodeReadableStream = goog.require('goog.net.streams.NodeReadableStream');
const XhrIo = goog.require('goog.net.XhrIo');

import { NodeReadableStream } from "goog.net.streams.NodeReadableStream"; // @TODO resolve
import { XhrIo } from "goog.net.XhrIo"; // @TODO resolve

/**
* @typedef {{
* nodeReadableStream: (?NodeReadableStream|undefined),
* xhr: (?XhrIo|undefined),
* }}
*/
exports.GenericTransportInterface;
export const GenericTransportInterface;
49 changes: 21 additions & 28 deletions javascript/net/grpc/web/grpcwebclientbase.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,32 @@
*
* @author [email protected] (Stanley Cheung)
*/
goog.module('grpc.web.GrpcWebClientBase');

goog.module.declareLegacyNamespace();


const AbstractClientBase = goog.require('grpc.web.AbstractClientBase');
const ClientOptions = goog.requireType('grpc.web.ClientOptions');
const ClientReadableStream = goog.require('grpc.web.ClientReadableStream');
const ClientUnaryCallImpl = goog.require('grpc.web.ClientUnaryCallImpl');
const Error = goog.require('grpc.web.Error');
const GrpcWebClientReadableStream = goog.require('grpc.web.GrpcWebClientReadableStream');
const HttpCors = goog.require('goog.net.rpc.HttpCors');
const MethodDescriptor = goog.requireType('grpc.web.MethodDescriptor');
const MethodType = goog.require('grpc.web.MethodType');
const Request = goog.require('grpc.web.Request');
const StatusCode = goog.require('grpc.web.StatusCode');
const XhrIo = goog.require('goog.net.XhrIo');
const googCrypt = goog.require('goog.crypt.base64');
const {Status} = goog.require('grpc.web.Status');
const {StreamInterceptor, UnaryInterceptor} = goog.require('grpc.web.Interceptor');



import { HttpCors } from "goog.net.rpc.HttpCors"; // @TODO resolve
import { XhrIo } from "goog.net.XhrIo"; // @TODO resolve
import { googCrypt } from "goog.crypt.base64"; // @TODO resolve

import { AbstractClientBase } from "./abstractclientbase.js";
import { ClientOptions } from "./clientoptions.js";
import { ClientReadableStream } from "./clientreadablestream.js";
import { ClientUnaryCallImpl } from "./clientunarycallimpl.js";
import { Error } from "./error.js";
import { GrpcWebClientReadableStream } from "./grpcwebclientreadablestream.js";
import { MethodDescriptor } from "./methoddescriptor.js";
import { MethodType } from "./methodtype.js";
import { Request } from "./request.js";
import { StatusCode } from "./statuscode.js";
import { Status } from "./status";
import { StreamInterceptor, UnaryInterceptor} from "./interceptor.js";



export const GrpcWebClientBaseOptions = ClientOptions;
/**
* Base class for gRPC web client using the application/grpc-web wire format
* @implements {AbstractClientBase}
* @unrestricted
*/
class GrpcWebClientBase {
export class GrpcWebClientBase {
/**
* @param {!ClientOptions=} options
*/
Expand Down Expand Up @@ -369,7 +366,3 @@ class GrpcWebClientBase {
return curInvoker;
}
}



exports = GrpcWebClientBase;
38 changes: 14 additions & 24 deletions javascript/net/grpc/web/grpcwebclientreadablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,19 @@
*
* @author [email protected] (Stanley Cheung)
*/
goog.module('grpc.web.GrpcWebClientReadableStream');

goog.module.declareLegacyNamespace();


const ClientReadableStream = goog.require('grpc.web.ClientReadableStream');
const ErrorCode = goog.require('goog.net.ErrorCode');
const EventType = goog.require('goog.net.EventType');
const GrpcWebError = goog.require('grpc.web.Error');
const GrpcWebStreamParser = goog.require('grpc.web.GrpcWebStreamParser');
const StatusCode = goog.require('grpc.web.StatusCode');
const XhrIo = goog.require('goog.net.XhrIo');
const events = goog.require('goog.events');
const googCrypt = goog.require('goog.crypt.base64');
const googString = goog.require('goog.string');
const {GenericTransportInterface} = goog.require('grpc.web.GenericTransportInterface');
const {Status} = goog.require('grpc.web.Status');


import { ErrorCode } from "goog.net.ErrorCode"; // @TODO resolve
import { EventType } from "goog.net.EventType"; // @TODO resolve
import { XhrIo } from "goog.net.XhrIo"; // @TODO resolve
import { events } from "goog.events"; // @TODO resolve
import { googCrypt } from "goog.crypt.base64"; // @TODO resolve
import { googString } from "goog.string"; // @TODO resolve

import { ClientReadableStream } from "./clientreadablestream.js"
import { GrpcWebError } from "./error.js"
import { GrpcWebStreamParser } from "./grpcwebstreamparser.js"
import { StatusCode } from "./statuscode.js"
import { GenericTransportInterface } from "./generictransportinterface.js"
import { Status } from "./status.js"

const GRPC_STATUS = 'grpc-status';
const GRPC_STATUS_MESSAGE = 'grpc-message';
Expand All @@ -61,7 +55,7 @@ const EXCLUDED_RESPONSE_HEADERS =
* @final
* @unrestricted
*/
class GrpcWebClientReadableStream {
export class GrpcWebClientReadableStream {
/**
* @param {!GenericTransportInterface} genericTransportInterface The
* GenericTransportInterface
Expand Down Expand Up @@ -441,7 +435,3 @@ class GrpcWebClientReadableStream {
}
}
}



exports = GrpcWebClientReadableStream;
17 changes: 3 additions & 14 deletions javascript/net/grpc/web/grpcwebstreamparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,15 @@
*
* Result: [ { 0x00 : <message1 }, { 0x00 : <message2> }, { 0x80 : trailers } ]
*/
goog.module('grpc.web.GrpcWebStreamParser');

goog.module.declareLegacyNamespace();


const StreamParser = goog.require('goog.net.streams.StreamParser');
const asserts = goog.require('goog.asserts');


import { StreamParser } from "goog.net.streams.StreamParser"; // @TODO resolve
import { asserts } from "goog.asserts"; // @TODO resolve

/**
* The default grpc-web stream parser.
* @implements {StreamParser}
* @final
*/
class GrpcWebStreamParser {
export class GrpcWebStreamParser {
constructor() {
/**
* The current error message, if any.
Expand Down Expand Up @@ -288,7 +281,3 @@ Parser.prototype.error_ = function(inputBytes, pos, errorMsg) {
'With input:\n' + inputBytes;
throw new Error(this.errorMessage_);
};



exports = GrpcWebStreamParser;
12 changes: 12 additions & 0 deletions javascript/net/grpc/web/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export { Metadata } from "./metadata.js"
export { AbstractClientBase } from "./abstractclientbase.js"
export { ClientReadableStream } from "./clientreadablestream.js"
export { StreamInterceptor, UnaryInterceptor } from "./interceptor.js"
export { CallOptions } from "./calloptions.js"
export { MethodDescriptor } from "./methoddescriptor.js"
export { Request } from "./request.js"
export { UnaryResponse } from "./unaryresponse.js"
export { GrpcWebClientBase, GrpcWebClientBaseOptions } from "./grpcwebclientbase.js"
export { Error } from "./error.js"
export { Status } from "./status.js"
export { StatusCode } from "./statuscode.js"
Loading