Skip to content

Commit

Permalink
changed protobuf generation to 'commonjs_strict' (#127)
Browse files Browse the repository at this point in the history
* Changed protobuf generation to use 'commonjs_strict' eliminating the 'global' variable generated by the closure compiler.

* bumping version for release
  • Loading branch information
aricart authored Jul 16, 2019
1 parent bdf9606 commit a7b43c4
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 44 deletions.
34 changes: 17 additions & 17 deletions lib/pb/protocol_pb.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@

var jspb = require('google-protobuf');
var goog = jspb;
var global = Function('return this')();

goog.exportSymbol('proto.pb.Ack', null, global);
goog.exportSymbol('proto.pb.CloseRequest', null, global);
goog.exportSymbol('proto.pb.CloseResponse', null, global);
goog.exportSymbol('proto.pb.ConnectRequest', null, global);
goog.exportSymbol('proto.pb.ConnectResponse', null, global);
goog.exportSymbol('proto.pb.MsgProto', null, global);
goog.exportSymbol('proto.pb.Ping', null, global);
goog.exportSymbol('proto.pb.PingResponse', null, global);
goog.exportSymbol('proto.pb.PubAck', null, global);
goog.exportSymbol('proto.pb.PubMsg', null, global);
goog.exportSymbol('proto.pb.StartPosition', null, global);
goog.exportSymbol('proto.pb.SubscriptionRequest', null, global);
goog.exportSymbol('proto.pb.SubscriptionResponse', null, global);
goog.exportSymbol('proto.pb.UnsubscribeRequest', null, global);
var proto = {};

goog.exportSymbol('pb.Ack', null, proto);
goog.exportSymbol('pb.CloseRequest', null, proto);
goog.exportSymbol('pb.CloseResponse', null, proto);
goog.exportSymbol('pb.ConnectRequest', null, proto);
goog.exportSymbol('pb.ConnectResponse', null, proto);
goog.exportSymbol('pb.MsgProto', null, proto);
goog.exportSymbol('pb.Ping', null, proto);
goog.exportSymbol('pb.PingResponse', null, proto);
goog.exportSymbol('pb.PubAck', null, proto);
goog.exportSymbol('pb.PubMsg', null, proto);
goog.exportSymbol('pb.StartPosition', null, proto);
goog.exportSymbol('pb.SubscriptionRequest', null, proto);
goog.exportSymbol('pb.SubscriptionResponse', null, proto);
goog.exportSymbol('pb.UnsubscribeRequest', null, proto);
/**
* Generated by JsPbCodeGenerator.
* @param {Array=} opt_data Optional initial data array, typically from a
Expand Down Expand Up @@ -3239,4 +3239,4 @@ proto.pb.StartPosition = {
FIRST: 4
};

goog.object.extend(exports, proto.pb);
goog.object.extend(exports, proto);
48 changes: 24 additions & 24 deletions lib/stan.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const util = require('util'),
/**
* Constants
*/
const VERSION = '0.2.4',
const VERSION = '0.2.6',
DEFAULT_PORT = 4222,
DEFAULT_PRE = 'nats://localhost:',
DEFAULT_URI = DEFAULT_PRE + DEFAULT_PORT,
Expand Down Expand Up @@ -292,7 +292,7 @@ Stan.prototype.createConnection = function() {
this.pingInbox = nats.createInbox();
this.pingSubscription = this.nc.subscribe(this.pingInbox, (msg) => {
if (msg) {
const pingResponse = proto.PingResponse.deserializeBinary(Buffer.from(msg, 'binary'));
const pingResponse = proto.pb.PingResponse.deserializeBinary(Buffer.from(msg, 'binary'));
const err = pingResponse.getError();
if (err) {
this.closeWithError('connection_lost', err);
Expand All @@ -307,7 +307,7 @@ Stan.prototype.createConnection = function() {
const discoverSubject = this.options.discoverPrefix + '.' + this.clusterID;
//noinspection JSUnresolvedFunction
this.connId = Buffer.from(nuid.next(), "utf8");
const req = new proto.ConnectRequest();
const req = new proto.pb.ConnectRequest();
req.setClientId(this.clientID);
req.setHeartbeatInbox(hbInbox);
req.setProtocol(PROTOCOL_ONE);
Expand All @@ -326,7 +326,7 @@ Stan.prototype.createConnection = function() {
return;
}

const cr = proto.ConnectResponse.deserializeBinary(Buffer.from(msg, 'binary'));
const cr = proto.pb.ConnectResponse.deserializeBinary(Buffer.from(msg, 'binary'));
if (cr.getError() !== "") {
this.closeWithError('error', cr.getError());
return;
Expand All @@ -346,7 +346,7 @@ Stan.prototype.createConnection = function() {
this.stanPingInterval = cr.getPingInterval() * 1000;
this.stanMaxPingOut = cr.getPingMaxOut();

const ping = new proto.Ping();
const ping = new proto.pb.Ping();
ping.setConnId(this.connId);
this.pingBytes = Buffer.from(ping.serializeBinary());

Expand Down Expand Up @@ -467,7 +467,7 @@ Stan.prototype.close = function() {
this.cleanupOnClose(new Error(CONN_CLOSED));
//noinspection JSUnresolvedFunction
if (this.nc && this.closeRequests) {
const req = new proto.CloseRequest();
const req = new proto.pb.CloseRequest();
req.setClientId(this.clientID);
this.nc.requestOne(this.closeRequests, Buffer.from(req.serializeBinary()), {}, this.options.connectTimeout, (msgOrError) => {
const nc = this.nc;
Expand All @@ -478,7 +478,7 @@ Stan.prototype.close = function() {
// if we get an error here, we simply show it in the close notification as there's not much we can do here.
closeError = msgOrError;
} else {
const cr = proto.CloseResponse.deserializeBinary(Buffer.from(msgOrError, 'binary'));
const cr = proto.pb.CloseResponse.deserializeBinary(Buffer.from(msgOrError, 'binary'));
const err = cr.getError();
if (err && err.length > 0) {
// if the protocol returned an error there's nothing for us to handle, pass it as an arg to close notification.
Expand Down Expand Up @@ -507,7 +507,7 @@ Stan.prototype.close = function() {
Stan.prototype.processAck = function() {
return (msg) => {
//noinspection JSUnresolvedVariable
const pa = proto.PubAck.deserializeBinary(Buffer.from(msg, 'binary'));
const pa = proto.pb.PubAck.deserializeBinary(Buffer.from(msg, 'binary'));
const guid = pa.getGuid();
const a = this.removeAck(guid);
if (a && a.ah) {
Expand Down Expand Up @@ -569,7 +569,7 @@ Stan.prototype.publish = function(subject, data, ackHandler) {
const subj = this.pubPrefix + '.' + subject;
const peGUID = nuid.next();
//noinspection JSUnresolvedFunction
const pe = new proto.PubMsg();
const pe = new proto.pb.PubMsg();
pe.setClientId(this.clientID);
pe.setConnId(this.connId);
pe.setGuid(peGUID);
Expand Down Expand Up @@ -652,7 +652,7 @@ Stan.prototype.subscribe = function(subject, qGroup, options) {

this.subMap[retVal.inbox] = retVal;
retVal.inboxSub = this.nc.subscribe(retVal.inbox, this.processMsg());
const sr = new proto.SubscriptionRequest();
const sr = new proto.pb.SubscriptionRequest();
sr.setClientId(this.clientID);
sr.setSubject(subject);
sr.setQGroup(retVal.qGroup || '');
Expand All @@ -663,10 +663,10 @@ Stan.prototype.subscribe = function(subject, qGroup, options) {
sr.setDurableName(retVal.opts.durableName || '');

switch (sr.getStartPosition()) {
case proto.StartPosition.TIME_DELTA_START:
case proto.pb.StartPosition.TIME_DELTA_START:
sr.setStartTimeDelta(retVal.opts.startTime);
break;
case proto.StartPosition.SEQUENCE_START:
case proto.pb.StartPosition.SEQUENCE_START:
sr.setStartSequence(retVal.opts.startSequence);
break;
}
Expand All @@ -682,7 +682,7 @@ Stan.prototype.subscribe = function(subject, qGroup, options) {
return;
}
//noinspection JSUnresolvedVariable
const r = proto.SubscriptionResponse.deserializeBinary(Buffer.from(msg, 'binary'));
const r = proto.pb.SubscriptionResponse.deserializeBinary(Buffer.from(msg, 'binary'));
const err = r.getError();
if (err && err.length !== 0) {
retVal.emit('error', new Error(err));
Expand Down Expand Up @@ -816,7 +816,7 @@ Subscription.prototype.closeOrUnsubscribe = function(doClose) {

sc.nc.unsubscribe(this.inboxSub);
//noinspection JSUnresolvedFunction
const ur = new proto.UnsubscribeRequest();
const ur = new proto.pb.UnsubscribeRequest();
ur.setClientId(sc.clientID);
ur.setSubject(this.subject);
ur.setInbox(this.ackInbox);
Expand All @@ -834,7 +834,7 @@ Subscription.prototype.closeOrUnsubscribe = function(doClose) {
return;
}
//noinspection JSUnresolvedVariable
const r = proto.SubscriptionResponse.deserializeBinary(Buffer.from(msg, 'binary'));
const r = proto.pb.SubscriptionResponse.deserializeBinary(Buffer.from(msg, 'binary'));
err = r.getError();
if (err && err.length > 0) {
this.emit('error', new Error(r.getError()));
Expand All @@ -856,7 +856,7 @@ Stan.prototype.processMsg = function() {
const sub = this.subMap[subject];
try {
//noinspection JSUnresolvedVariable
const m = proto.MsgProto.deserializeBinary(Buffer.from(rawMsg, 'binary'));
const m = proto.pb.MsgProto.deserializeBinary(Buffer.from(rawMsg, 'binary'));
if (sub === undefined || !this.nc) {
return;
}
Expand Down Expand Up @@ -973,7 +973,7 @@ Message.prototype.maybeAutoAck = function() {
*/
Message.prototype.ack = function() {
if (!this.subscription.isClosed()) {
const ack = new proto.Ack();
const ack = new proto.pb.Ack();
ack.setSubject(this.getSubject());
ack.setSequence(this.getSequence());
this.stanClient.nc.publish(this.subscription.ackInbox, Buffer.from(ack.serializeBinary()));
Expand All @@ -998,7 +998,7 @@ Message.prototype.getConnectionID = function() {
* LAST_RECEIVED, TIME_DELTA_START, SEQUENCE_START, FIRST)
* @type {StartPosition}
*/
exports.StartPosition = proto.StartPosition;
exports.StartPosition = proto.pb.StartPosition;

function SubscriptionOptions(durableName, maxInFlight, ackWait, startPosition, startSequence, startTime, manualAcks) {
// DurableName, if set will survive client restarts.
Expand All @@ -1007,7 +1007,7 @@ function SubscriptionOptions(durableName, maxInFlight, ackWait, startPosition, s
this.maxInFlight = maxInFlight || DEFAULT_MAX_IN_FLIGHT;
// Controls the time the cluster will wait for an ACK for a given message.
this.ackWait = ackWait || DEFAULT_ACK_WAIT;
// StartPosition enum from proto.
// StartPosition enum from proto.pb
this.startPosition = startPosition;
// Optional start sequence number.
this.startSequence = startSequence;
Expand Down Expand Up @@ -1045,7 +1045,7 @@ SubscriptionOptions.prototype.setStartAt = function(startPosition) {
};

SubscriptionOptions.prototype.setStartAtSequence = function(sequence) {
this.startPosition = proto.StartPosition.SEQUENCE_START;
this.startPosition = proto.pb.StartPosition.SEQUENCE_START;
this.startSequence = sequence;
return this;
};
Expand All @@ -1056,7 +1056,7 @@ SubscriptionOptions.prototype.setStartAtSequence = function(sequence) {
* @return {SubscriptionOptions}
*/
SubscriptionOptions.prototype.setStartTime = function(date) {
this.startPosition = proto.StartPosition.TIME_DELTA_START;
this.startPosition = proto.pb.StartPosition.TIME_DELTA_START;
// server expects values in ns
this.startTime = (Date.now() - date.valueOf()) * 1000000;
return this;
Expand All @@ -1067,7 +1067,7 @@ SubscriptionOptions.prototype.setStartTime = function(date) {
* @return {SubscriptionOptions}
*/
SubscriptionOptions.prototype.setStartAtTimeDelta = function(millis) {
this.startPosition = proto.StartPosition.TIME_DELTA_START;
this.startPosition = proto.pb.StartPosition.TIME_DELTA_START;
//noinspection JSUnresolvedFunction
// server expects values in ns
this.startTime = millis * 1000000;
Expand All @@ -1079,7 +1079,7 @@ SubscriptionOptions.prototype.setStartAtTimeDelta = function(millis) {
* @return {SubscriptionOptions}
*/
SubscriptionOptions.prototype.setStartWithLastReceived = function() {
this.startPosition = proto.StartPosition.LAST_RECEIVED;
this.startPosition = proto.pb.StartPosition.LAST_RECEIVED;
return this;
};

Expand All @@ -1088,7 +1088,7 @@ SubscriptionOptions.prototype.setStartWithLastReceived = function() {
* @return {SubscriptionOptions}
*/
SubscriptionOptions.prototype.setDeliverAllAvailable = function() {
this.startPosition = proto.StartPosition.FIRST;
this.startPosition = proto.pb.StartPosition.FIRST;
return this;
};

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-nats-streaming",
"version": "0.2.4",
"version": "0.2.6",
"description": "Node.js client for NATS Streaming, a lightweight, high-performance cloud native messaging system",
"keywords": [
"nats",
Expand Down Expand Up @@ -34,7 +34,7 @@
"depcheck": "dependency-check . lib/*",
"depcheck:unused": "dependency-check ./package.json --unused --no-dev lib/*",
"fmt": "js-beautify -n --config crockford.jscsrc -r lib/stan.js test/*.js test/support/*.js examples/* bench/*.js",
"gen": "protoc --js_out=import_style=commonjs,binary:. lib/pb/protocol.proto",
"gen": "protoc --js_out=import_style=commonjs_strict,binary:. lib/pb/protocol.proto",
"lint": "eslint ./lib/stan.js ./examples ./bench ./test",
"test": "npm run depcheck && npm run depcheck:unused && npm run lint && npm run test:unit",
"test:unit": "mkdir -p reports/ && NODE_ENV=test multi='spec=- xunit=reports/mocha-xunit.xml' nyc mocha --timeout 10000 --slow 750",
Expand Down
2 changes: 1 addition & 1 deletion test/basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe('Basics', () => {
});
nc.on('connect', () => {
nc.subscribe(stan.pubPrefix + ".hello", (msg) => {
const pm = proto.PubMsg.deserializeBinary(new Uint8Array(msg));
const pm = proto.pb.PubMsg.deserializeBinary(new Uint8Array(msg));
const pm_cid = pm.getClientId();
clientID.should.be.equal(pm_cid);
const pm_connid = Buffer.from(pm.getConnId()).toString('utf8');
Expand Down

0 comments on commit a7b43c4

Please sign in to comment.