protobufjs 8.6.1 → 8.6.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 (105) hide show
  1. package/LICENSE +39 -39
  2. package/README.md +441 -441
  3. package/dist/light/protobuf.js +8455 -8455
  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 +2999 -2999
  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 +10359 -10359
  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/README.md +70 -70
  16. package/ext/debug/README.md +4 -4
  17. package/ext/debug/index.js +71 -71
  18. package/ext/descriptor/README.md +5 -5
  19. package/ext/descriptor/index.d.ts +2 -2
  20. package/ext/descriptor/index.js +2 -2
  21. package/ext/descriptor.d.ts +87 -87
  22. package/ext/descriptor.js +1354 -1354
  23. package/ext/protojson.LICENSE +201 -201
  24. package/ext/protojson.d.ts +20 -20
  25. package/ext/protojson.js +925 -925
  26. package/ext/textformat.d.ts +19 -19
  27. package/ext/textformat.js +1256 -1256
  28. package/google/LICENSE +27 -27
  29. package/google/README.md +1 -1
  30. package/google/api/annotations.json +82 -82
  31. package/google/api/annotations.proto +10 -10
  32. package/google/api/http.json +85 -85
  33. package/google/api/http.proto +30 -30
  34. package/google/protobuf/api.json +117 -117
  35. package/google/protobuf/api.proto +33 -33
  36. package/google/protobuf/compiler/plugin.json +126 -126
  37. package/google/protobuf/compiler/plugin.proto +47 -47
  38. package/google/protobuf/descriptor.json +1381 -1381
  39. package/google/protobuf/descriptor.proto +534 -534
  40. package/google/protobuf/source_context.json +19 -19
  41. package/google/protobuf/source_context.proto +7 -7
  42. package/google/protobuf/type.json +201 -201
  43. package/google/protobuf/type.proto +89 -89
  44. package/index.d.ts +1 -1
  45. package/index.js +4 -4
  46. package/light.d.ts +2 -2
  47. package/light.js +3 -3
  48. package/minimal.d.ts +2 -2
  49. package/minimal.js +4 -4
  50. package/package.json +93 -93
  51. package/src/common.js +399 -399
  52. package/src/converter.js +344 -344
  53. package/src/decoder.js +208 -208
  54. package/src/encoder.js +111 -111
  55. package/src/enum.js +231 -231
  56. package/src/field.js +497 -497
  57. package/src/index-light.js +104 -104
  58. package/src/index-minimal.js +36 -36
  59. package/src/index.js +12 -12
  60. package/src/mapfield.js +136 -136
  61. package/src/message.js +137 -137
  62. package/src/method.js +175 -175
  63. package/src/namespace.js +565 -565
  64. package/src/object.js +382 -382
  65. package/src/oneof.js +225 -225
  66. package/src/parse.js +1068 -1068
  67. package/src/reader.js +543 -543
  68. package/src/reader_buffer.js +72 -72
  69. package/src/root.js +416 -416
  70. package/src/roots.js +18 -18
  71. package/src/rpc/service.js +148 -148
  72. package/src/rpc.js +36 -36
  73. package/src/service.js +198 -198
  74. package/src/tokenize.js +421 -421
  75. package/src/type.js +655 -655
  76. package/src/types.js +196 -196
  77. package/src/typescript.js +25 -25
  78. package/src/util/aspromise.d.ts +13 -13
  79. package/src/util/aspromise.js +52 -52
  80. package/src/util/base64.d.ts +32 -32
  81. package/src/util/base64.js +146 -146
  82. package/src/util/codegen.d.ts +31 -31
  83. package/src/util/codegen.js +113 -113
  84. package/src/util/eventemitter.d.ts +45 -45
  85. package/src/util/eventemitter.js +86 -86
  86. package/src/util/fetch.d.ts +56 -56
  87. package/src/util/fetch.js +112 -112
  88. package/src/util/float.d.ts +83 -83
  89. package/src/util/float.js +335 -335
  90. package/src/util/fs.js +11 -11
  91. package/src/util/longbits.js +200 -200
  92. package/src/util/minimal.js +515 -515
  93. package/src/util/path.d.ts +22 -22
  94. package/src/util/path.js +72 -72
  95. package/src/util/patterns.js +7 -7
  96. package/src/util/pool.d.ts +32 -32
  97. package/src/util/pool.js +48 -48
  98. package/src/util/utf8.d.ts +24 -24
  99. package/src/util/utf8.js +130 -130
  100. package/src/util.js +242 -242
  101. package/src/verifier.js +180 -180
  102. package/src/wrappers.js +106 -106
  103. package/src/writer.js +495 -495
  104. package/src/writer_buffer.js +102 -102
  105. package/tsconfig.json +6 -6
package/src/util.js CHANGED
@@ -1,242 +1,242 @@
1
- "use strict";
2
-
3
- /**
4
- * Various utility functions.
5
- * @namespace
6
- */
7
- var util = module.exports = require("./util/minimal");
8
-
9
- var roots = require("./roots");
10
-
11
- var Type, // cyclic
12
- Enum;
13
-
14
- util.codegen = require("./util/codegen");
15
- util.fetch = require("./util/fetch");
16
- util.path = require("./util/path");
17
- util.patterns = require("./util/patterns");
18
-
19
- var reservedRe = util.patterns.reservedRe;
20
-
21
- /**
22
- * Node's fs module if available.
23
- * @type {Object.<string,*>}
24
- */
25
- util.fs = require("./util/fs");
26
-
27
- /**
28
- * Converts an object's values to an array.
29
- * @param {Object.<string,*>} object Object to convert
30
- * @returns {Array.<*>} Converted array
31
- */
32
- util.toArray = function toArray(object) {
33
- if (object) {
34
- var keys = Object.keys(object),
35
- array = new Array(keys.length),
36
- index = 0;
37
- while (index < keys.length)
38
- array[index] = object[keys[index++]];
39
- return array;
40
- }
41
- return [];
42
- };
43
-
44
- /**
45
- * Converts an array of keys immediately followed by their respective value to an object, omitting undefined values.
46
- * @param {Array.<*>} array Array to convert
47
- * @returns {Object.<string,*>} Converted object
48
- */
49
- util.toObject = function toObject(array) {
50
- var object = {},
51
- index = 0;
52
- while (index < array.length) {
53
- var key = array[index++],
54
- val = array[index++];
55
- if (val !== undefined)
56
- object[key] = val;
57
- }
58
- return object;
59
- };
60
-
61
- /**
62
- * Tests whether the specified name is a reserved word in JS.
63
- * @param {string} name Name to test
64
- * @returns {boolean} `true` if reserved, otherwise `false`
65
- */
66
- util.isReserved = function isReserved(name) {
67
- return reservedRe.test(name);
68
- };
69
-
70
- /**
71
- * Returns a safe property accessor for the specified property name.
72
- * @param {string} prop Property name
73
- * @returns {string} Safe accessor
74
- */
75
- util.safeProp = function safeProp(prop) {
76
- if (!/^[$\w_]+$/.test(prop) || reservedRe.test(prop))
77
- return "[" + JSON.stringify(prop) + "]";
78
- return "." + prop;
79
- };
80
-
81
- /**
82
- * Converts the first character of a string to upper case.
83
- * @param {string} str String to convert
84
- * @returns {string} Converted string
85
- */
86
- util.ucFirst = function ucFirst(str) {
87
- return str.charAt(0).toUpperCase() + str.substring(1);
88
- };
89
-
90
- var camelCaseRe = /_([a-z])/g;
91
-
92
- /**
93
- * Converts a string to camel case.
94
- * @param {string} str String to convert
95
- * @returns {string} Converted string
96
- * @deprecated Use {@link util.jsonName} for protobuf field JSON names.
97
- */
98
- util.camelCase = function camelCase(str) {
99
- return str.substring(0, 1)
100
- + str.substring(1)
101
- .replace(camelCaseRe, function($0, $1) { return $1.toUpperCase(); });
102
- };
103
-
104
- /**
105
- * Converts a proto field name to its protoc-compatible JSON name.
106
- * @param {string} str Proto field name
107
- * @returns {string} JSON name
108
- */
109
- util.jsonName = function jsonName(str) {
110
- var result = "",
111
- upperNext = false,
112
- i = 0;
113
- for (; i < str.length; ++i) {
114
- var ch = str.charAt(i);
115
- if (ch === "_")
116
- upperNext = true;
117
- else if (upperNext) {
118
- result += ch.toUpperCase();
119
- upperNext = false;
120
- } else
121
- result += ch;
122
- }
123
- return result;
124
- };
125
-
126
- /**
127
- * Compares reflected fields by id.
128
- * @param {Field} a First field
129
- * @param {Field} b Second field
130
- * @returns {number} Comparison value
131
- */
132
- util.compareFieldsById = function compareFieldsById(a, b) {
133
- return a.id - b.id;
134
- };
135
-
136
- /**
137
- * Decorator helper for types (TypeScript).
138
- * @param {Constructor<T>} ctor Constructor function
139
- * @param {string} [typeName] Type name, defaults to the constructor's name
140
- * @returns {Type} Reflected type
141
- * @template T extends Message<T>
142
- * @property {Root} root Decorators root
143
- * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
144
- */
145
- util.decorateType = function decorateType(ctor, typeName) {
146
-
147
- /* istanbul ignore if */
148
- if (ctor.$type) {
149
- if (typeName && ctor.$type.name !== typeName) {
150
- util.decorateRoot.remove(ctor.$type);
151
- ctor.$type.name = typeName;
152
- util.decorateRoot.add(ctor.$type);
153
- }
154
- return ctor.$type;
155
- }
156
-
157
- /* istanbul ignore next */
158
- if (!Type)
159
- Type = require("./type");
160
-
161
- var type = new Type(typeName || ctor.name);
162
- util.decorateRoot.add(type);
163
- type.ctor = ctor; // sets up .encode, .decode etc.
164
- Object.defineProperty(ctor, "$type", { value: type, enumerable: false });
165
- Object.defineProperty(ctor.prototype, "$type", { value: type, enumerable: false });
166
- return type;
167
- };
168
-
169
- var decorateEnumIndex = 0;
170
-
171
- /**
172
- * Decorator helper for enums (TypeScript).
173
- * @param {Object} object Enum object
174
- * @returns {Enum} Reflected enum
175
- * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
176
- */
177
- util.decorateEnum = function decorateEnum(object) {
178
-
179
- /* istanbul ignore if */
180
- if (object.$type)
181
- return object.$type;
182
-
183
- /* istanbul ignore next */
184
- if (!Enum)
185
- Enum = require("./enum");
186
-
187
- var enm = new Enum("Enum" + decorateEnumIndex++, object);
188
- util.decorateRoot.add(enm);
189
- Object.defineProperty(object, "$type", { value: enm, enumerable: false });
190
- return enm;
191
- };
192
-
193
-
194
- /**
195
- * Sets the value of a property by property path. If a value already exists, it is turned to an array
196
- * @param {Object.<string,*>} dst Destination object
197
- * @param {string} path dot '.' delimited path of the property to set
198
- * @param {Object} value the value to set
199
- * @param {boolean|undefined} [ifNotSet] Sets the option only if it isn't currently set
200
- * @returns {Object.<string,*>} Destination object
201
- */
202
- util.setProperty = function setProperty(dst, path, value, ifNotSet) {
203
- function setProp(dst, path, value) {
204
- var part = path.shift();
205
- if (util.isUnsafeProperty(part))
206
- return dst;
207
- if (path.length > 0) {
208
- dst[part] = setProp(dst[part] || {}, path, value);
209
- } else {
210
- var prevValue = dst[part];
211
- if (prevValue && ifNotSet)
212
- return dst;
213
- if (prevValue)
214
- value = [].concat(prevValue).concat(value);
215
- dst[part] = value;
216
- }
217
- return dst;
218
- }
219
-
220
- if (typeof dst !== "object")
221
- throw TypeError("dst must be an object");
222
- if (!path)
223
- throw TypeError("path must be specified");
224
-
225
- path = path.split(".");
226
- if (path.length > util.recursionLimit)
227
- throw Error("max depth exceeded");
228
- return setProp(dst, path, value);
229
- };
230
-
231
- /**
232
- * Decorator root (TypeScript).
233
- * @name util.decorateRoot
234
- * @type {Root}
235
- * @readonly
236
- * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
237
- */
238
- Object.defineProperty(util, "decorateRoot", {
239
- get: function() {
240
- return roots["decorated"] || (roots["decorated"] = new (require("./root"))());
241
- }
242
- });
1
+ "use strict";
2
+
3
+ /**
4
+ * Various utility functions.
5
+ * @namespace
6
+ */
7
+ var util = module.exports = require("./util/minimal");
8
+
9
+ var roots = require("./roots");
10
+
11
+ var Type, // cyclic
12
+ Enum;
13
+
14
+ util.codegen = require("./util/codegen");
15
+ util.fetch = require("./util/fetch");
16
+ util.path = require("./util/path");
17
+ util.patterns = require("./util/patterns");
18
+
19
+ var reservedRe = util.patterns.reservedRe;
20
+
21
+ /**
22
+ * Node's fs module if available.
23
+ * @type {Object.<string,*>}
24
+ */
25
+ util.fs = require("./util/fs");
26
+
27
+ /**
28
+ * Converts an object's values to an array.
29
+ * @param {Object.<string,*>} object Object to convert
30
+ * @returns {Array.<*>} Converted array
31
+ */
32
+ util.toArray = function toArray(object) {
33
+ if (object) {
34
+ var keys = Object.keys(object),
35
+ array = new Array(keys.length),
36
+ index = 0;
37
+ while (index < keys.length)
38
+ array[index] = object[keys[index++]];
39
+ return array;
40
+ }
41
+ return [];
42
+ };
43
+
44
+ /**
45
+ * Converts an array of keys immediately followed by their respective value to an object, omitting undefined values.
46
+ * @param {Array.<*>} array Array to convert
47
+ * @returns {Object.<string,*>} Converted object
48
+ */
49
+ util.toObject = function toObject(array) {
50
+ var object = {},
51
+ index = 0;
52
+ while (index < array.length) {
53
+ var key = array[index++],
54
+ val = array[index++];
55
+ if (val !== undefined)
56
+ object[key] = val;
57
+ }
58
+ return object;
59
+ };
60
+
61
+ /**
62
+ * Tests whether the specified name is a reserved word in JS.
63
+ * @param {string} name Name to test
64
+ * @returns {boolean} `true` if reserved, otherwise `false`
65
+ */
66
+ util.isReserved = function isReserved(name) {
67
+ return reservedRe.test(name);
68
+ };
69
+
70
+ /**
71
+ * Returns a safe property accessor for the specified property name.
72
+ * @param {string} prop Property name
73
+ * @returns {string} Safe accessor
74
+ */
75
+ util.safeProp = function safeProp(prop) {
76
+ if (!/^[$\w_]+$/.test(prop) || reservedRe.test(prop))
77
+ return "[" + JSON.stringify(prop) + "]";
78
+ return "." + prop;
79
+ };
80
+
81
+ /**
82
+ * Converts the first character of a string to upper case.
83
+ * @param {string} str String to convert
84
+ * @returns {string} Converted string
85
+ */
86
+ util.ucFirst = function ucFirst(str) {
87
+ return str.charAt(0).toUpperCase() + str.substring(1);
88
+ };
89
+
90
+ var camelCaseRe = /_([a-z])/g;
91
+
92
+ /**
93
+ * Converts a string to camel case.
94
+ * @param {string} str String to convert
95
+ * @returns {string} Converted string
96
+ * @deprecated Use {@link util.jsonName} for protobuf field JSON names.
97
+ */
98
+ util.camelCase = function camelCase(str) {
99
+ return str.substring(0, 1)
100
+ + str.substring(1)
101
+ .replace(camelCaseRe, function($0, $1) { return $1.toUpperCase(); });
102
+ };
103
+
104
+ /**
105
+ * Converts a proto field name to its protoc-compatible JSON name.
106
+ * @param {string} str Proto field name
107
+ * @returns {string} JSON name
108
+ */
109
+ util.jsonName = function jsonName(str) {
110
+ var result = "",
111
+ upperNext = false,
112
+ i = 0;
113
+ for (; i < str.length; ++i) {
114
+ var ch = str.charAt(i);
115
+ if (ch === "_")
116
+ upperNext = true;
117
+ else if (upperNext) {
118
+ result += ch.toUpperCase();
119
+ upperNext = false;
120
+ } else
121
+ result += ch;
122
+ }
123
+ return result;
124
+ };
125
+
126
+ /**
127
+ * Compares reflected fields by id.
128
+ * @param {Field} a First field
129
+ * @param {Field} b Second field
130
+ * @returns {number} Comparison value
131
+ */
132
+ util.compareFieldsById = function compareFieldsById(a, b) {
133
+ return a.id - b.id;
134
+ };
135
+
136
+ /**
137
+ * Decorator helper for types (TypeScript).
138
+ * @param {Constructor<T>} ctor Constructor function
139
+ * @param {string} [typeName] Type name, defaults to the constructor's name
140
+ * @returns {Type} Reflected type
141
+ * @template T extends Message<T>
142
+ * @property {Root} root Decorators root
143
+ * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
144
+ */
145
+ util.decorateType = function decorateType(ctor, typeName) {
146
+
147
+ /* istanbul ignore if */
148
+ if (ctor.$type) {
149
+ if (typeName && ctor.$type.name !== typeName) {
150
+ util.decorateRoot.remove(ctor.$type);
151
+ ctor.$type.name = typeName;
152
+ util.decorateRoot.add(ctor.$type);
153
+ }
154
+ return ctor.$type;
155
+ }
156
+
157
+ /* istanbul ignore next */
158
+ if (!Type)
159
+ Type = require("./type");
160
+
161
+ var type = new Type(typeName || ctor.name);
162
+ util.decorateRoot.add(type);
163
+ type.ctor = ctor; // sets up .encode, .decode etc.
164
+ Object.defineProperty(ctor, "$type", { value: type, enumerable: false });
165
+ Object.defineProperty(ctor.prototype, "$type", { value: type, enumerable: false });
166
+ return type;
167
+ };
168
+
169
+ var decorateEnumIndex = 0;
170
+
171
+ /**
172
+ * Decorator helper for enums (TypeScript).
173
+ * @param {Object} object Enum object
174
+ * @returns {Enum} Reflected enum
175
+ * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
176
+ */
177
+ util.decorateEnum = function decorateEnum(object) {
178
+
179
+ /* istanbul ignore if */
180
+ if (object.$type)
181
+ return object.$type;
182
+
183
+ /* istanbul ignore next */
184
+ if (!Enum)
185
+ Enum = require("./enum");
186
+
187
+ var enm = new Enum("Enum" + decorateEnumIndex++, object);
188
+ util.decorateRoot.add(enm);
189
+ Object.defineProperty(object, "$type", { value: enm, enumerable: false });
190
+ return enm;
191
+ };
192
+
193
+
194
+ /**
195
+ * Sets the value of a property by property path. If a value already exists, it is turned to an array
196
+ * @param {Object.<string,*>} dst Destination object
197
+ * @param {string} path dot '.' delimited path of the property to set
198
+ * @param {Object} value the value to set
199
+ * @param {boolean|undefined} [ifNotSet] Sets the option only if it isn't currently set
200
+ * @returns {Object.<string,*>} Destination object
201
+ */
202
+ util.setProperty = function setProperty(dst, path, value, ifNotSet) {
203
+ function setProp(dst, path, value) {
204
+ var part = path.shift();
205
+ if (util.isUnsafeProperty(part))
206
+ return dst;
207
+ if (path.length > 0) {
208
+ dst[part] = setProp(dst[part] || {}, path, value);
209
+ } else {
210
+ var prevValue = dst[part];
211
+ if (prevValue && ifNotSet)
212
+ return dst;
213
+ if (prevValue)
214
+ value = [].concat(prevValue).concat(value);
215
+ dst[part] = value;
216
+ }
217
+ return dst;
218
+ }
219
+
220
+ if (typeof dst !== "object")
221
+ throw TypeError("dst must be an object");
222
+ if (!path)
223
+ throw TypeError("path must be specified");
224
+
225
+ path = path.split(".");
226
+ if (path.length > util.recursionLimit)
227
+ throw Error("max depth exceeded");
228
+ return setProp(dst, path, value);
229
+ };
230
+
231
+ /**
232
+ * Decorator root (TypeScript).
233
+ * @name util.decorateRoot
234
+ * @type {Root}
235
+ * @readonly
236
+ * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
237
+ */
238
+ Object.defineProperty(util, "decorateRoot", {
239
+ get: function() {
240
+ return roots["decorated"] || (roots["decorated"] = new (require("./root"))());
241
+ }
242
+ });