protobufjs 8.4.2 → 8.5.0
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/README.md +21 -3
- package/dist/light/protobuf.js +53 -17
- package/dist/light/protobuf.js.map +1 -1
- package/dist/light/protobuf.min.js +3 -3
- package/dist/light/protobuf.min.js.map +1 -1
- package/dist/minimal/protobuf.js +25 -7
- package/dist/minimal/protobuf.js.map +1 -1
- package/dist/minimal/protobuf.min.js +3 -3
- package/dist/minimal/protobuf.min.js.map +1 -1
- package/dist/protobuf.js +53 -17
- package/dist/protobuf.js.map +1 -1
- package/dist/protobuf.min.js +3 -3
- package/dist/protobuf.min.js.map +1 -1
- package/index.d.ts +22 -9
- package/package.json +3 -2
- package/src/converter.js +4 -2
- package/src/decoder.js +4 -2
- package/src/method.js +16 -2
- package/src/namespace.js +4 -4
- package/src/reader.js +12 -0
- package/src/roots.js +1 -1
- package/src/rpc/service.js +10 -4
package/index.d.ts
CHANGED
|
@@ -666,13 +666,16 @@ export class Method extends ReflectionObject {
|
|
|
666
666
|
requestType: string;
|
|
667
667
|
|
|
668
668
|
/** Whether requests are streamed or not. */
|
|
669
|
-
requestStream?:
|
|
669
|
+
requestStream?: true;
|
|
670
670
|
|
|
671
671
|
/** Response type. */
|
|
672
672
|
responseType: string;
|
|
673
673
|
|
|
674
674
|
/** Whether responses are streamed or not. */
|
|
675
|
-
responseStream?:
|
|
675
|
+
responseStream?: true;
|
|
676
|
+
|
|
677
|
+
/** gRPC-style method path. */
|
|
678
|
+
path: string;
|
|
676
679
|
|
|
677
680
|
/** Resolved request type. */
|
|
678
681
|
resolvedRequestType: (Type|null);
|
|
@@ -1204,6 +1207,9 @@ export class Reader {
|
|
|
1204
1207
|
/** Read buffer length. */
|
|
1205
1208
|
len: number;
|
|
1206
1209
|
|
|
1210
|
+
/** Whether to discard unknown fields while decoding. */
|
|
1211
|
+
discardUnknown: boolean;
|
|
1212
|
+
|
|
1207
1213
|
/**
|
|
1208
1214
|
* Creates a new reader using the specified buffer.
|
|
1209
1215
|
* @param buffer Buffer to read from
|
|
@@ -1326,6 +1332,9 @@ export class Reader {
|
|
|
1326
1332
|
/** Recursion limit. */
|
|
1327
1333
|
static recursionLimit: number;
|
|
1328
1334
|
|
|
1335
|
+
/** Whether readers discard unknown fields while decoding. */
|
|
1336
|
+
static discardUnknown: boolean;
|
|
1337
|
+
|
|
1329
1338
|
/**
|
|
1330
1339
|
* Skips the next element of the specified wire type.
|
|
1331
1340
|
* @param wireType Wire type received
|
|
@@ -1453,13 +1462,17 @@ export namespace rpc {
|
|
|
1453
1462
|
*/
|
|
1454
1463
|
type ServiceMethodCallback<TRes extends Message<TRes>> = (error: (Error|null), response?: TRes) => void;
|
|
1455
1464
|
|
|
1456
|
-
/**
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1465
|
+
/** A service method part of a {@link rpc.Service} as created by {@link Service.create}. */
|
|
1466
|
+
type ServiceMethod<TReq extends Message<TReq>, TRes extends Message<TRes>> = {
|
|
1467
|
+
(request: TReq|Properties<TReq>, callback: rpc.ServiceMethodCallback<TRes>): void;
|
|
1468
|
+
(request: TReq|Properties<TReq>): Promise<TRes>;
|
|
1469
|
+
readonly name: string;
|
|
1470
|
+
readonly path: string;
|
|
1471
|
+
readonly requestType: string;
|
|
1472
|
+
readonly responseType: string;
|
|
1473
|
+
readonly requestStream: true|undefined;
|
|
1474
|
+
readonly responseStream: true|undefined;
|
|
1475
|
+
};
|
|
1463
1476
|
|
|
1464
1477
|
/** An RPC service as returned by {@link Service#create}. */
|
|
1465
1478
|
class Service extends util.EventEmitter {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "protobufjs",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.5.0",
|
|
4
4
|
"versionScheme": "~",
|
|
5
5
|
"description": "Protocol Buffers for JavaScript & TypeScript.",
|
|
6
6
|
"author": "Daniel Wirtz <dcode+protobufjs@dcode.io>",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"bench": "node bench",
|
|
27
27
|
"build": "npm run build:bundle && npm run build:types",
|
|
28
28
|
"build:bundle": "gulp --gulpfile scripts/gulpfile.js",
|
|
29
|
+
"build:tests": "node ./scripts/gentests.js",
|
|
29
30
|
"build:types": "node cli/bin/pbts --main --global protobuf --out index.d.ts src/ && node cli/bin/pbts --main --import \"\\$protobuf=..\" --out ext/descriptor.generated.d.ts ext/descriptor.js && node cli/bin/pbts --main --out ext/textformat.generated.d.ts ext/textformat.js",
|
|
30
31
|
"coverage": "npm run coverage:test && npm run coverage:report",
|
|
31
32
|
"coverage:test": "nyc --silent tape -r ./lib/tape-adapter tests/*.js tests/node/*.js",
|
|
@@ -43,7 +44,7 @@
|
|
|
43
44
|
"test": "npm run test:sources && npm run test:types",
|
|
44
45
|
"test:sources": "tape -r ./lib/tape-adapter tests/*.js tests/node/*.js",
|
|
45
46
|
"test:types": "tsc tests/comp_typescript.ts --target es2019 --module commonjs --types node --lib es2019 --esModuleInterop --strictNullChecks --experimentalDecorators --emitDecoratorMetadata && tsc -p tsconfig.test-types.json",
|
|
46
|
-
"make": "npm run lint:sources && npm run build && npm run lint:types &&
|
|
47
|
+
"make": "npm run lint:sources && npm run build && npm run lint:types && npm run build:tests && npm test"
|
|
47
48
|
},
|
|
48
49
|
"dependencies": {
|
|
49
50
|
"long": "^5.3.2"
|
package/src/converter.js
CHANGED
|
@@ -42,7 +42,7 @@ function genValuePartial_fromObject(gen, field, fieldIndex, prop) {
|
|
|
42
42
|
} gen
|
|
43
43
|
("}");
|
|
44
44
|
} else gen
|
|
45
|
-
("if(
|
|
45
|
+
("if(!util.isObject(d%s))", prop)
|
|
46
46
|
("throw TypeError(%j)", field.fullName + ": object expected")
|
|
47
47
|
("m%s=types[%i].fromObject(d%s,q+1)", prop, fieldIndex, prop);
|
|
48
48
|
} else {
|
|
@@ -109,6 +109,8 @@ converter.fromObject = function fromObject(mtype) {
|
|
|
109
109
|
var gen = util.codegen(["d", "q"], mtype.name + "$fromObject")
|
|
110
110
|
("if(d instanceof C)")
|
|
111
111
|
("return d")
|
|
112
|
+
("if(!util.isObject(d))")
|
|
113
|
+
("throw TypeError(%j)", mtype.fullName + ": object expected")
|
|
112
114
|
("if(q===undefined)q=0")
|
|
113
115
|
("if(q>util.recursionLimit)")
|
|
114
116
|
("throw Error(\"max depth exceeded\")");
|
|
@@ -125,7 +127,7 @@ converter.fromObject = function fromObject(mtype) {
|
|
|
125
127
|
// Map fields
|
|
126
128
|
if (field.map) { gen
|
|
127
129
|
("if(d%s){", prop)
|
|
128
|
-
("if(
|
|
130
|
+
("if(!util.isObject(d%s))", prop)
|
|
129
131
|
("throw TypeError(%j)", field.fullName + ": object expected")
|
|
130
132
|
("m%s={}", prop)
|
|
131
133
|
("for(var ks=Object.keys(d%s),i=0;i<ks.length;++i){", prop);
|
package/src/decoder.js
CHANGED
|
@@ -186,8 +186,10 @@ function decoder(mtype) {
|
|
|
186
186
|
// Unknown fields
|
|
187
187
|
gen
|
|
188
188
|
("r.skipType(%s,q,t)", i ? "u" : "t&7")
|
|
189
|
-
("
|
|
190
|
-
|
|
189
|
+
("if(!r.discardUnknown){")
|
|
190
|
+
("util.makeProp(m,\"$unknowns\",false);")
|
|
191
|
+
("(m.$unknowns||(m.$unknowns=[])).push(r.raw(s,r.pos))")
|
|
192
|
+
("}")
|
|
191
193
|
("}")
|
|
192
194
|
("if(z!==undefined)")
|
|
193
195
|
("throw Error(\"missing end group\")");
|
package/src/method.js
CHANGED
|
@@ -61,7 +61,7 @@ function Method(name, type, requestType, responseType, requestStream, responseSt
|
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
63
|
* Whether requests are streamed or not.
|
|
64
|
-
* @type {
|
|
64
|
+
* @type {true|undefined}
|
|
65
65
|
*/
|
|
66
66
|
this.requestStream = requestStream ? true : undefined; // toJSON
|
|
67
67
|
|
|
@@ -73,10 +73,16 @@ function Method(name, type, requestType, responseType, requestStream, responseSt
|
|
|
73
73
|
|
|
74
74
|
/**
|
|
75
75
|
* Whether responses are streamed or not.
|
|
76
|
-
* @type {
|
|
76
|
+
* @type {true|undefined}
|
|
77
77
|
*/
|
|
78
78
|
this.responseStream = responseStream ? true : undefined; // toJSON
|
|
79
79
|
|
|
80
|
+
/**
|
|
81
|
+
* gRPC-style method path.
|
|
82
|
+
* @type {string}
|
|
83
|
+
*/
|
|
84
|
+
this.path = "/" + this.name;
|
|
85
|
+
|
|
80
86
|
/**
|
|
81
87
|
* Resolved request type.
|
|
82
88
|
* @type {Type|null}
|
|
@@ -154,6 +160,14 @@ Method.prototype.resolve = function resolve() {
|
|
|
154
160
|
if (this.resolved)
|
|
155
161
|
return this;
|
|
156
162
|
|
|
163
|
+
if (this.parent) {
|
|
164
|
+
var serviceName = this.parent.fullName;
|
|
165
|
+
if (serviceName.charAt(0) === ".")
|
|
166
|
+
serviceName = serviceName.substring(1);
|
|
167
|
+
this.path = "/" + serviceName + "/" + this.name;
|
|
168
|
+
} else
|
|
169
|
+
this.path = "/" + this.name;
|
|
170
|
+
|
|
157
171
|
this.resolvedRequestType = this.parent.lookupType(this.requestType);
|
|
158
172
|
this.resolvedResponseType = this.parent.lookupType(this.responseType);
|
|
159
173
|
|
package/src/namespace.js
CHANGED
|
@@ -426,14 +426,14 @@ Namespace.prototype.lookup = function lookup(path, filterTypes, parentAlreadyChe
|
|
|
426
426
|
if (path[0] === "")
|
|
427
427
|
return this.root.lookup(path.slice(1), filterTypes);
|
|
428
428
|
|
|
429
|
-
//
|
|
430
|
-
var found = this.
|
|
429
|
+
// Lookup at this namespace and below
|
|
430
|
+
var found = this._lookupImpl(path, flatPath);
|
|
431
431
|
if (found && (!filterTypes || filterTypes.indexOf(found.constructor) > -1)) {
|
|
432
432
|
return found;
|
|
433
433
|
}
|
|
434
434
|
|
|
435
|
-
//
|
|
436
|
-
found = this.
|
|
435
|
+
// Fall back to respective absolute path once relative scope has been checked (non-standard)
|
|
436
|
+
found = this.root._fullyQualifiedObjects && this.root._fullyQualifiedObjects["." + flatPath];
|
|
437
437
|
if (found && (!filterTypes || filterTypes.indexOf(found.constructor) > -1)) {
|
|
438
438
|
return found;
|
|
439
439
|
}
|
package/src/reader.js
CHANGED
|
@@ -38,6 +38,12 @@ function Reader(buffer) {
|
|
|
38
38
|
* @type {number}
|
|
39
39
|
*/
|
|
40
40
|
this.len = buffer.length;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Whether to discard unknown fields while decoding.
|
|
44
|
+
* @type {boolean}
|
|
45
|
+
*/
|
|
46
|
+
this.discardUnknown = Reader.discardUnknown;
|
|
41
47
|
}
|
|
42
48
|
|
|
43
49
|
var create_array = typeof Uint8Array !== "undefined"
|
|
@@ -450,6 +456,12 @@ Reader.prototype.skip = function skip(length) {
|
|
|
450
456
|
*/
|
|
451
457
|
Reader.recursionLimit = util.recursionLimit;
|
|
452
458
|
|
|
459
|
+
/**
|
|
460
|
+
* Whether readers discard unknown fields while decoding.
|
|
461
|
+
* @type {boolean}
|
|
462
|
+
*/
|
|
463
|
+
Reader.discardUnknown = false;
|
|
464
|
+
|
|
453
465
|
/**
|
|
454
466
|
* Skips the next element of the specified wire type.
|
|
455
467
|
* @param {number} wireType Wire type received
|
package/src/roots.js
CHANGED
package/src/rpc/service.js
CHANGED
|
@@ -23,10 +23,16 @@ var util = require("../util/minimal");
|
|
|
23
23
|
* @typedef rpc.ServiceMethod
|
|
24
24
|
* @template TReq extends Message<TReq>
|
|
25
25
|
* @template TRes extends Message<TRes>
|
|
26
|
-
* @type {
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
26
|
+
* @type {{
|
|
27
|
+
* (request: TReq|Properties<TReq>, callback: rpc.ServiceMethodCallback<TRes>): void;
|
|
28
|
+
* (request: TReq|Properties<TReq>): Promise<TRes>;
|
|
29
|
+
* readonly name: string;
|
|
30
|
+
* readonly path: string;
|
|
31
|
+
* readonly requestType: string;
|
|
32
|
+
* readonly responseType: string;
|
|
33
|
+
* readonly requestStream: true|undefined;
|
|
34
|
+
* readonly responseStream: true|undefined;
|
|
35
|
+
* }}
|
|
30
36
|
*/
|
|
31
37
|
|
|
32
38
|
/**
|