protobufjs 8.0.3-experimental → 8.0.3
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/LICENSE +39 -39
- package/README.md +727 -727
- package/dist/light/protobuf.js +7724 -7352
- 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 +2606 -2546
- 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 +9588 -9131
- package/dist/protobuf.js.map +1 -1
- package/dist/protobuf.min.js +3 -3
- package/dist/protobuf.min.js.map +1 -1
- package/ext/debug/README.md +4 -4
- package/ext/debug/index.js +71 -71
- package/ext/descriptor/README.md +72 -72
- package/ext/descriptor/index.d.ts +195 -191
- package/ext/descriptor/index.js +1181 -1052
- package/ext/descriptor/test.js +54 -54
- package/google/LICENSE +27 -27
- package/google/README.md +1 -1
- package/google/api/annotations.json +82 -82
- package/google/api/annotations.proto +10 -10
- package/google/api/http.json +85 -85
- package/google/api/http.proto +30 -30
- package/google/protobuf/api.json +117 -117
- package/google/protobuf/api.proto +33 -33
- package/google/protobuf/descriptor.json +1381 -738
- package/google/protobuf/descriptor.proto +535 -286
- package/google/protobuf/source_context.json +19 -19
- package/google/protobuf/source_context.proto +7 -7
- package/google/protobuf/type.json +201 -201
- package/google/protobuf/type.proto +89 -89
- package/index.d.ts +2817 -2792
- package/index.js +4 -4
- package/light.d.ts +2 -2
- package/light.js +3 -3
- package/minimal.d.ts +2 -2
- package/minimal.js +4 -4
- package/package.json +96 -112
- package/scripts/postinstall.js +32 -32
- package/src/common.js +399 -399
- package/src/converter.js +310 -301
- package/src/decoder.js +135 -127
- package/src/encoder.js +100 -100
- package/src/enum.js +226 -241
- package/src/field.js +453 -432
- package/src/index-light.js +104 -104
- package/src/index-minimal.js +36 -36
- package/src/index.js +12 -12
- package/src/mapfield.js +126 -126
- package/src/message.js +139 -139
- package/src/method.js +160 -160
- package/src/namespace.js +550 -434
- package/src/object.js +385 -330
- package/src/oneof.js +222 -222
- package/src/parse.js +1024 -944
- package/src/reader.js +426 -416
- package/src/reader_buffer.js +51 -51
- package/src/root.js +404 -384
- package/src/roots.js +17 -17
- package/src/rpc/service.js +142 -142
- package/src/rpc.js +36 -36
- package/src/service.js +193 -168
- package/src/tokenize.js +421 -416
- package/src/type.js +625 -590
- package/src/types.js +196 -196
- package/src/typescript.jsdoc +15 -15
- package/src/util/aspromise.d.ts +13 -0
- package/src/util/aspromise.js +52 -0
- package/src/util/base64.d.ts +32 -0
- package/src/util/base64.js +139 -0
- package/src/util/codegen.d.ts +31 -0
- package/src/util/codegen.js +113 -0
- package/src/util/eventemitter.d.ts +45 -0
- package/src/util/eventemitter.js +84 -0
- package/src/util/fetch.d.ts +56 -0
- package/src/util/fetch.js +114 -0
- package/src/util/float.d.ts +83 -0
- package/src/util/float.js +335 -0
- package/src/util/inquire.d.ts +9 -0
- package/src/util/inquire.js +37 -0
- package/src/util/longbits.js +200 -200
- package/src/util/minimal.js +461 -438
- package/src/util/path.d.ts +22 -0
- package/src/util/path.js +72 -0
- package/src/util/patterns.js +8 -0
- package/src/util/pool.d.ts +32 -0
- package/src/util/pool.js +48 -0
- package/src/util/utf8.d.ts +24 -0
- package/src/util/utf8.js +104 -0
- package/src/util.js +215 -213
- package/src/verifier.js +180 -177
- package/src/wrappers.js +103 -102
- package/src/writer.js +465 -465
- package/src/writer_buffer.js +85 -85
- package/tsconfig.json +8 -8
package/src/service.js
CHANGED
|
@@ -1,168 +1,193 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
module.exports = Service;
|
|
3
|
-
|
|
4
|
-
// extends Namespace
|
|
5
|
-
var Namespace = require("./namespace");
|
|
6
|
-
((Service.prototype = Object.create(Namespace.prototype)).constructor = Service).className = "Service";
|
|
7
|
-
|
|
8
|
-
var Method = require("./method"),
|
|
9
|
-
util = require("./util"),
|
|
10
|
-
rpc = require("./rpc");
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*
|
|
16
|
-
* @
|
|
17
|
-
* @
|
|
18
|
-
* @
|
|
19
|
-
* @
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
*
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
*
|
|
42
|
-
* @
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
*
|
|
49
|
-
* @
|
|
50
|
-
* @
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
module.exports = Service;
|
|
3
|
+
|
|
4
|
+
// extends Namespace
|
|
5
|
+
var Namespace = require("./namespace");
|
|
6
|
+
((Service.prototype = Object.create(Namespace.prototype)).constructor = Service).className = "Service";
|
|
7
|
+
|
|
8
|
+
var Method = require("./method"),
|
|
9
|
+
util = require("./util"),
|
|
10
|
+
rpc = require("./rpc");
|
|
11
|
+
|
|
12
|
+
var reservedRe = util.patterns.reservedRe;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Constructs a new service instance.
|
|
16
|
+
* @classdesc Reflected service.
|
|
17
|
+
* @extends NamespaceBase
|
|
18
|
+
* @constructor
|
|
19
|
+
* @param {string} name Service name
|
|
20
|
+
* @param {Object.<string,*>} [options] Service options
|
|
21
|
+
* @throws {TypeError} If arguments are invalid
|
|
22
|
+
*/
|
|
23
|
+
function Service(name, options) {
|
|
24
|
+
Namespace.call(this, name, options);
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Service methods.
|
|
28
|
+
* @type {Object.<string,Method>}
|
|
29
|
+
*/
|
|
30
|
+
this.methods = {}; // toJSON, marker
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Cached methods as an array.
|
|
34
|
+
* @type {Method[]|null}
|
|
35
|
+
* @private
|
|
36
|
+
*/
|
|
37
|
+
this._methodsArray = null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Service descriptor.
|
|
42
|
+
* @interface IService
|
|
43
|
+
* @extends INamespace
|
|
44
|
+
* @property {Object.<string,IMethod>} methods Method descriptors
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Constructs a service from a service descriptor.
|
|
49
|
+
* @param {string} name Service name
|
|
50
|
+
* @param {IService} json Service descriptor
|
|
51
|
+
* @returns {Service} Created service
|
|
52
|
+
* @throws {TypeError} If arguments are invalid
|
|
53
|
+
*/
|
|
54
|
+
Service.fromJSON = function fromJSON(name, json) {
|
|
55
|
+
var service = new Service(name, json.options);
|
|
56
|
+
/* istanbul ignore else */
|
|
57
|
+
if (json.methods)
|
|
58
|
+
for (var names = Object.keys(json.methods), i = 0; i < names.length; ++i)
|
|
59
|
+
service.add(Method.fromJSON(names[i], json.methods[names[i]]));
|
|
60
|
+
if (json.nested)
|
|
61
|
+
service.addJSON(json.nested);
|
|
62
|
+
if (json.edition)
|
|
63
|
+
service._edition = json.edition;
|
|
64
|
+
service.comment = json.comment;
|
|
65
|
+
service._defaultEdition = "proto3"; // For backwards-compatibility.
|
|
66
|
+
return service;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Converts this service to a service descriptor.
|
|
71
|
+
* @param {IToJSONOptions} [toJSONOptions] JSON conversion options
|
|
72
|
+
* @returns {IService} Service descriptor
|
|
73
|
+
*/
|
|
74
|
+
Service.prototype.toJSON = function toJSON(toJSONOptions) {
|
|
75
|
+
var inherited = Namespace.prototype.toJSON.call(this, toJSONOptions);
|
|
76
|
+
var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
|
|
77
|
+
return util.toObject([
|
|
78
|
+
"edition" , this._editionToJSON(),
|
|
79
|
+
"options" , inherited && inherited.options || undefined,
|
|
80
|
+
"methods" , Namespace.arrayToJSON(this.methodsArray, toJSONOptions) || /* istanbul ignore next */ {},
|
|
81
|
+
"nested" , inherited && inherited.nested || undefined,
|
|
82
|
+
"comment" , keepComments ? this.comment : undefined
|
|
83
|
+
]);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Methods of this service as an array for iteration.
|
|
88
|
+
* @name Service#methodsArray
|
|
89
|
+
* @type {Method[]}
|
|
90
|
+
* @readonly
|
|
91
|
+
*/
|
|
92
|
+
Object.defineProperty(Service.prototype, "methodsArray", {
|
|
93
|
+
get: function() {
|
|
94
|
+
return this._methodsArray || (this._methodsArray = util.toArray(this.methods));
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
function clearCache(service) {
|
|
99
|
+
service._methodsArray = null;
|
|
100
|
+
return service;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* @override
|
|
105
|
+
*/
|
|
106
|
+
Service.prototype.get = function get(name) {
|
|
107
|
+
return Object.prototype.hasOwnProperty.call(this.methods, name)
|
|
108
|
+
? this.methods[name]
|
|
109
|
+
: Namespace.prototype.get.call(this, name);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* @override
|
|
114
|
+
*/
|
|
115
|
+
Service.prototype.resolveAll = function resolveAll() {
|
|
116
|
+
if (!this._needsRecursiveResolve) return this;
|
|
117
|
+
|
|
118
|
+
Namespace.prototype.resolve.call(this);
|
|
119
|
+
var methods = this.methodsArray;
|
|
120
|
+
for (var i = 0; i < methods.length; ++i)
|
|
121
|
+
methods[i].resolve();
|
|
122
|
+
return this;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* @override
|
|
127
|
+
*/
|
|
128
|
+
Service.prototype._resolveFeaturesRecursive = function _resolveFeaturesRecursive(edition) {
|
|
129
|
+
if (!this._needsRecursiveFeatureResolution) return this;
|
|
130
|
+
|
|
131
|
+
edition = this._edition || edition;
|
|
132
|
+
|
|
133
|
+
Namespace.prototype._resolveFeaturesRecursive.call(this, edition);
|
|
134
|
+
this.methodsArray.forEach(method => {
|
|
135
|
+
method._resolveFeaturesRecursive(edition);
|
|
136
|
+
});
|
|
137
|
+
return this;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* @override
|
|
142
|
+
*/
|
|
143
|
+
Service.prototype.add = function add(object) {
|
|
144
|
+
/* istanbul ignore if */
|
|
145
|
+
if (this.get(object.name))
|
|
146
|
+
throw Error("duplicate name '" + object.name + "' in " + this);
|
|
147
|
+
|
|
148
|
+
if (object instanceof Method) {
|
|
149
|
+
if (object.name === "__proto__")
|
|
150
|
+
return this;
|
|
151
|
+
this.methods[object.name] = object;
|
|
152
|
+
object.parent = this;
|
|
153
|
+
return clearCache(this);
|
|
154
|
+
}
|
|
155
|
+
return Namespace.prototype.add.call(this, object);
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* @override
|
|
160
|
+
*/
|
|
161
|
+
Service.prototype.remove = function remove(object) {
|
|
162
|
+
if (object instanceof Method) {
|
|
163
|
+
|
|
164
|
+
/* istanbul ignore if */
|
|
165
|
+
if (this.methods[object.name] !== object)
|
|
166
|
+
throw Error(object + " is not a member of " + this);
|
|
167
|
+
|
|
168
|
+
delete this.methods[object.name];
|
|
169
|
+
object.parent = null;
|
|
170
|
+
return clearCache(this);
|
|
171
|
+
}
|
|
172
|
+
return Namespace.prototype.remove.call(this, object);
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Creates a runtime service using the specified rpc implementation.
|
|
177
|
+
* @param {RPCImpl} rpcImpl RPC implementation
|
|
178
|
+
* @param {boolean} [requestDelimited=false] Whether requests are length-delimited
|
|
179
|
+
* @param {boolean} [responseDelimited=false] Whether responses are length-delimited
|
|
180
|
+
* @returns {rpc.Service} RPC service. Useful where requests and/or responses are streamed.
|
|
181
|
+
*/
|
|
182
|
+
Service.prototype.create = function create(rpcImpl, requestDelimited, responseDelimited) {
|
|
183
|
+
var rpcService = new rpc.Service(rpcImpl, requestDelimited, responseDelimited);
|
|
184
|
+
for (var i = 0, method; i < /* initializes */ this.methodsArray.length; ++i) {
|
|
185
|
+
var methodName = util.lcFirst((method = this._methodsArray[i]).resolve().name).replace(/[^$\w_]/g, "");
|
|
186
|
+
rpcService[methodName] = util.codegen(["r","c"], reservedRe.test(methodName) ? methodName + "_" : methodName)("return this.rpcCall(m,q,s,r,c)")({
|
|
187
|
+
m: method,
|
|
188
|
+
q: method.resolvedRequestType.ctor,
|
|
189
|
+
s: method.resolvedResponseType.ctor
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
return rpcService;
|
|
193
|
+
};
|