protobufjs 7.6.2 → 7.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -2489,14 +2489,6 @@ export namespace util {
2489
2489
  */
2490
2490
  function fetch(path: string, options?: IFetchOptions): Promise<(string|Uint8Array)>;
2491
2491
 
2492
- /**
2493
- * Requires a module only if available.
2494
- * @param moduleName Module to require
2495
- * @returns Required module if available and not empty, otherwise `null`
2496
- * @deprecated Legacy optional require helper. Will be removed in a future release.
2497
- */
2498
- function inquire(moduleName: string): object;
2499
-
2500
2492
  /** A minimal path module to resolve Unix, Windows and URL paths alike. */
2501
2493
  namespace path {
2502
2494
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "protobufjs",
3
- "version": "7.6.2",
3
+ "version": "7.6.4",
4
4
  "versionScheme": "~",
5
5
  "description": "Protocol Buffers for JavaScript (& TypeScript).",
6
6
  "author": "Daniel Wirtz <dcode+protobufjs@dcode.io>",
@@ -37,7 +37,7 @@
37
37
  "bench": "node bench",
38
38
  "build": "npm run build:bundle && npm run build:types",
39
39
  "build:bundle": "gulp --gulpfile scripts/gulpfile.js",
40
- "build:types": "node cli/bin/pbts --main --global protobuf --out index.d.ts src/ lib/aspromise/index.js lib/base64/index.js lib/codegen/index.js lib/eventemitter/index.js lib/float/index.js lib/fetch/index.js lib/inquire/index.js lib/path/index.js lib/pool/index.js lib/utf8/index.js",
40
+ "build:types": "node cli/bin/pbts --main --global protobuf --out index.d.ts src/ lib/aspromise/index.js lib/base64/index.js lib/codegen/index.js lib/eventemitter/index.js lib/float/index.js lib/fetch/index.js lib/path/index.js lib/pool/index.js lib/utf8/index.js",
41
41
  "changelog": "node scripts/changelog -w",
42
42
  "coverage": "npm run coverage:test && npm run coverage:report",
43
43
  "coverage:test": "nyc --silent tape -r ./lib/tape-adapter tests/*.js tests/node/*.js",
@@ -63,7 +63,6 @@
63
63
  "@protobufjs/eventemitter": "^1.1.1",
64
64
  "@protobufjs/fetch": "^1.1.1",
65
65
  "@protobufjs/float": "^1.0.2",
66
- "@protobufjs/inquire": "^1.1.2",
67
66
  "@protobufjs/path": "^1.1.2",
68
67
  "@protobufjs/pool": "^1.1.0",
69
68
  "@protobufjs/utf8": "^1.1.1",
package/src/converter.js CHANGED
@@ -107,14 +107,15 @@ converter.fromObject = function fromObject(mtype) {
107
107
  var fields = mtype.fieldsArray;
108
108
  var gen = util.codegen(["d", "n"], mtype.name + "$fromObject")
109
109
  ("if(d instanceof this.ctor)")
110
- ("return d")
110
+ ("return d");
111
+ if (!fields.length) return gen
112
+ ("return new this.ctor");
113
+ gen
111
114
  ("if(!util.isObject(d))")
112
115
  ("throw TypeError(%j)", mtype.fullName + ": object expected")
113
116
  ("if(n===undefined)n=0")
114
117
  ("if(n>util.recursionLimit)")
115
118
  ("throw Error(\"maximum nesting depth exceeded\")");
116
- if (!fields.length) return gen
117
- ("return new this.ctor");
118
119
  gen
119
120
  ("var m=new this.ctor");
120
121
  for (var i = 0; i < fields.length; ++i) {
@@ -302,7 +303,7 @@ converter.toObject = function toObject(mtype) {
302
303
  genValuePartial_toObject(gen, field, /* sorted */ index, prop + "[j]")
303
304
  ("}");
304
305
  } else { gen
305
- ("if(m%s!=null&&m.hasOwnProperty(%j)){", prop, field.name); // !== undefined && !== null
306
+ ("if(m%s!=null&&Object.hasOwnProperty.call(m,%j)){", prop, field.name); // !== undefined && !== null
306
307
  genValuePartial_toObject(gen, field, /* sorted */ index, prop);
307
308
  if (field.partOf) gen
308
309
  ("if(o.oneofs)")
package/src/decoder.js CHANGED
@@ -125,7 +125,7 @@ function decoder(mtype) {
125
125
  for (i = 0; i < mtype._fieldsArray.length; ++i) {
126
126
  var rfield = mtype._fieldsArray[i];
127
127
  if (rfield.required) gen
128
- ("if(!m.hasOwnProperty(%j))", rfield.name)
128
+ ("if(!Object.hasOwnProperty.call(m,%j))", rfield.name)
129
129
  ("throw util.ProtocolError(%j,{instance:m})", missing(rfield));
130
130
  }
131
131
 
package/src/service.js CHANGED
@@ -9,8 +9,6 @@ var Method = require("./method"),
9
9
  util = require("./util"),
10
10
  rpc = require("./rpc");
11
11
 
12
- var reservedRe = util.patterns.reservedRe;
13
-
14
12
  /**
15
13
  * Constructs a new service instance.
16
14
  * @classdesc Reflected service.
@@ -185,11 +183,11 @@ Service.prototype.create = function create(rpcImpl, requestDelimited, responseDe
185
183
  var rpcService = new rpc.Service(rpcImpl, requestDelimited, responseDelimited);
186
184
  for (var i = 0, method; i < /* initializes */ this.methodsArray.length; ++i) {
187
185
  var methodName = util.lcFirst((method = this._methodsArray[i]).resolve().name).replace(/[^$\w_]/g, "");
188
- rpcService[methodName] = util.codegen(["r","c"], reservedRe.test(methodName) ? methodName + "_" : methodName)("return this.rpcCall(m,q,s,r,c)")({
189
- m: method,
190
- q: method.resolvedRequestType.ctor,
191
- s: method.resolvedResponseType.ctor
192
- });
186
+ rpcService[methodName] = (function(method, requestType, responseType) {
187
+ return function rpcMethod(request, callback) {
188
+ return rpc.Service.prototype.rpcCall.call(this, method, requestType, responseType, request, callback);
189
+ };
190
+ })(method, method.resolvedRequestType.ctor, method.resolvedResponseType.ctor);
193
191
  }
194
192
  return rpcService;
195
193
  };
package/src/type.js CHANGED
@@ -373,7 +373,7 @@ Type.prototype.add = function add(object) {
373
373
  throw Error("duplicate id " + object.id + " in " + this);
374
374
  if (this.isReservedId(object.id))
375
375
  throw Error("id " + object.id + " is reserved in " + this);
376
- if (this.isReservedName(object.name))
376
+ if (this.isReservedName(object.name) || object.name.charAt(0) === "$")
377
377
  throw Error("name '" + object.name + "' is reserved in " + this);
378
378
  if (object.name === "__proto__")
379
379
  return this;
@@ -386,6 +386,8 @@ Type.prototype.add = function add(object) {
386
386
  return clearCache(this);
387
387
  }
388
388
  if (object instanceof OneOf) {
389
+ if (object.name.charAt(0) === "$")
390
+ throw Error("name '" + object.name + "' is reserved in " + this);
389
391
  if (object.name === "__proto__")
390
392
  return this;
391
393
  if (!this.oneofs)
@@ -13,9 +13,6 @@ util.EventEmitter = require("@protobufjs/eventemitter");
13
13
  // float handling accross browsers
14
14
  util.float = require("@protobufjs/float");
15
15
 
16
- // requires modules optionally and hides the call from bundlers
17
- util.inquire = require("@protobufjs/inquire");
18
-
19
16
  // converts to / from utf8 encoded strings
20
17
  util.utf8 = require("@protobufjs/utf8");
21
18
 
@@ -119,7 +116,7 @@ util.isset =
119
116
  */
120
117
  util.isSet = function isSet(obj, prop) {
121
118
  var value = obj[prop];
122
- if (value != null && obj.hasOwnProperty(prop)) // eslint-disable-line eqeqeq, no-prototype-builtins
119
+ if (value != null && Object.hasOwnProperty.call(obj, prop)) // eslint-disable-line eqeqeq
123
120
  return typeof value !== "object" || (Array.isArray(value) ? value.length : Object.keys(value).length) > 0;
124
121
  return false;
125
122
  };
package/src/verifier.js CHANGED
@@ -138,7 +138,7 @@ function verifier(mtype) {
138
138
  ref = "m" + util.safeProp(field.name);
139
139
 
140
140
  if (field.optional) gen
141
- ("if(%s!=null&&m.hasOwnProperty(%j)){", ref, field.name); // !== undefined && !== null
141
+ ("if(%s!=null&&Object.hasOwnProperty.call(m,%j)){", ref, field.name); // !== undefined && !== null
142
142
 
143
143
  // map fields
144
144
  if (field.map) { gen