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.
Files changed (98) hide show
  1. package/LICENSE +39 -39
  2. package/README.md +727 -727
  3. package/dist/light/protobuf.js +7724 -7352
  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 +9588 -9131
  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 -1052
  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 -738
  30. package/google/protobuf/descriptor.proto +535 -286
  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 -2792
  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 -112
  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 -241
  48. package/src/field.js +453 -432
  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 -139
  54. package/src/method.js +160 -160
  55. package/src/namespace.js +550 -434
  56. package/src/object.js +385 -330
  57. package/src/oneof.js +222 -222
  58. package/src/parse.js +1024 -944
  59. package/src/reader.js +426 -416
  60. package/src/reader_buffer.js +51 -51
  61. package/src/root.js +404 -384
  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 -168
  66. package/src/tokenize.js +421 -416
  67. package/src/type.js +625 -590
  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 -213
  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,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
- * 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
- service.comment = json.comment;
61
- return service;
62
- };
63
-
64
- /**
65
- * Converts this service to a service descriptor.
66
- * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
67
- * @returns {IService} Service descriptor
68
- */
69
- Service.prototype.toJSON = function toJSON(toJSONOptions) {
70
- var inherited = Namespace.prototype.toJSON.call(this, toJSONOptions);
71
- var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
72
- return util.toObject([
73
- "options" , inherited && inherited.options || undefined,
74
- "methods" , Namespace.arrayToJSON(this.methodsArray, toJSONOptions) || /* istanbul ignore next */ {},
75
- "nested" , inherited && inherited.nested || undefined,
76
- "comment" , keepComments ? this.comment : undefined
77
- ]);
78
- };
79
-
80
- /**
81
- * Methods of this service as an array for iteration.
82
- * @name Service#methodsArray
83
- * @type {Method[]}
84
- * @readonly
85
- */
86
- Object.defineProperty(Service.prototype, "methodsArray", {
87
- get: function() {
88
- return this._methodsArray || (this._methodsArray = util.toArray(this.methods));
89
- }
90
- });
91
-
92
- function clearCache(service) {
93
- service._methodsArray = null;
94
- return service;
95
- }
96
-
97
- /**
98
- * @override
99
- */
100
- Service.prototype.get = function get(name) {
101
- return this.methods[name]
102
- || Namespace.prototype.get.call(this, name);
103
- };
104
-
105
- /**
106
- * @override
107
- */
108
- Service.prototype.resolveAll = function resolveAll() {
109
- Namespace.prototype.resolve.call(this);
110
- var methods = this.methodsArray;
111
- for (var i = 0; i < methods.length; ++i)
112
- methods[i].resolve();
113
- return this;
114
- };
115
-
116
- /**
117
- * @override
118
- */
119
- Service.prototype.add = function add(object) {
120
-
121
- /* istanbul ignore if */
122
- if (this.get(object.name))
123
- throw Error("duplicate name '" + object.name + "' in " + this);
124
-
125
- if (object instanceof Method) {
126
- this.methods[object.name] = object;
127
- object.parent = this;
128
- return clearCache(this);
129
- }
130
- return Namespace.prototype.add.call(this, object);
131
- };
132
-
133
- /**
134
- * @override
135
- */
136
- Service.prototype.remove = function remove(object) {
137
- if (object instanceof Method) {
138
-
139
- /* istanbul ignore if */
140
- if (this.methods[object.name] !== object)
141
- throw Error(object + " is not a member of " + this);
142
-
143
- delete this.methods[object.name];
144
- object.parent = null;
145
- return clearCache(this);
146
- }
147
- return Namespace.prototype.remove.call(this, object);
148
- };
149
-
150
- /**
151
- * Creates a runtime service using the specified rpc implementation.
152
- * @param {RPCImpl} rpcImpl RPC implementation
153
- * @param {boolean} [requestDelimited=false] Whether requests are length-delimited
154
- * @param {boolean} [responseDelimited=false] Whether responses are length-delimited
155
- * @returns {rpc.Service} RPC service. Useful where requests and/or responses are streamed.
156
- */
157
- Service.prototype.create = function create(rpcImpl, requestDelimited, responseDelimited) {
158
- var rpcService = new rpc.Service(rpcImpl, requestDelimited, responseDelimited);
159
- for (var i = 0, method; i < /* initializes */ this.methodsArray.length; ++i) {
160
- var methodName = util.lcFirst((method = this._methodsArray[i]).resolve().name).replace(/[^$\w_]/g, "");
161
- rpcService[methodName] = util.codegen(["r","c"], util.isReserved(methodName) ? methodName + "_" : methodName)("return this.rpcCall(m,q,s,r,c)")({
162
- m: method,
163
- q: method.resolvedRequestType.ctor,
164
- s: method.resolvedResponseType.ctor
165
- });
166
- }
167
- return rpcService;
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
+ };