protobufjs 8.0.1 → 8.0.2

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