protobufjs 7.3.2 → 7.3.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 (77) hide show
  1. package/LICENSE +39 -39
  2. package/README.md +727 -727
  3. package/ext/debug/README.md +4 -4
  4. package/ext/debug/index.js +71 -71
  5. package/ext/descriptor/README.md +72 -72
  6. package/ext/descriptor/index.d.ts +191 -191
  7. package/ext/descriptor/index.js +1052 -1052
  8. package/ext/descriptor/test.js +54 -54
  9. package/google/LICENSE +27 -27
  10. package/google/README.md +1 -1
  11. package/google/api/annotations.json +82 -82
  12. package/google/api/annotations.proto +10 -10
  13. package/google/api/http.json +85 -85
  14. package/google/api/http.proto +30 -30
  15. package/google/protobuf/api.json +117 -117
  16. package/google/protobuf/api.proto +33 -33
  17. package/google/protobuf/descriptor.json +738 -738
  18. package/google/protobuf/descriptor.proto +286 -286
  19. package/google/protobuf/source_context.json +19 -19
  20. package/google/protobuf/source_context.proto +7 -7
  21. package/google/protobuf/type.json +201 -201
  22. package/google/protobuf/type.proto +89 -89
  23. package/index.d.ts +2741 -2741
  24. package/index.js +4 -4
  25. package/light.d.ts +2 -2
  26. package/light.js +3 -3
  27. package/minimal.d.ts +2 -2
  28. package/minimal.js +4 -4
  29. package/package.json +111 -111
  30. package/scripts/postinstall.js +32 -32
  31. package/src/common.js +399 -399
  32. package/src/converter.js +301 -301
  33. package/src/decoder.js +129 -129
  34. package/src/encoder.js +100 -100
  35. package/src/enum.js +198 -198
  36. package/src/field.js +377 -377
  37. package/src/index-light.js +104 -104
  38. package/src/index-minimal.js +36 -36
  39. package/src/index.js +12 -12
  40. package/src/mapfield.js +126 -126
  41. package/src/message.js +138 -138
  42. package/src/method.js +160 -160
  43. package/src/namespace.js +433 -433
  44. package/src/object.js +243 -243
  45. package/src/oneof.js +203 -203
  46. package/src/parse.js +893 -889
  47. package/src/reader.js +416 -416
  48. package/src/reader_buffer.js +51 -51
  49. package/src/root.js +368 -368
  50. package/src/roots.js +18 -18
  51. package/src/rpc/service.js +142 -142
  52. package/src/rpc.js +36 -36
  53. package/src/service.js +167 -167
  54. package/src/tokenize.js +416 -416
  55. package/src/type.js +589 -589
  56. package/src/types.js +196 -196
  57. package/src/typescript.jsdoc +15 -15
  58. package/src/util/longbits.js +200 -200
  59. package/src/util/minimal.js +438 -438
  60. package/src/util.js +212 -212
  61. package/src/verifier.js +176 -176
  62. package/src/wrappers.js +102 -102
  63. package/src/writer.js +465 -465
  64. package/src/writer_buffer.js +85 -85
  65. package/tsconfig.json +7 -7
  66. package/dist/light/protobuf.js +0 -7381
  67. package/dist/light/protobuf.js.map +0 -1
  68. package/dist/light/protobuf.min.js +0 -8
  69. package/dist/light/protobuf.min.js.map +0 -1
  70. package/dist/minimal/protobuf.js +0 -2736
  71. package/dist/minimal/protobuf.js.map +0 -1
  72. package/dist/minimal/protobuf.min.js +0 -8
  73. package/dist/minimal/protobuf.min.js.map +0 -1
  74. package/dist/protobuf.js +0 -9105
  75. package/dist/protobuf.js.map +0 -1
  76. package/dist/protobuf.min.js +0 -8
  77. package/dist/protobuf.min.js.map +0 -1
package/src/util.js CHANGED
@@ -1,212 +1,212 @@
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("@protobufjs/codegen");
15
- util.fetch = require("@protobufjs/fetch");
16
- util.path = require("@protobufjs/path");
17
-
18
- /**
19
- * Node's fs module if available.
20
- * @type {Object.<string,*>}
21
- */
22
- util.fs = util.inquire("fs");
23
-
24
- /**
25
- * Converts an object's values to an array.
26
- * @param {Object.<string,*>} object Object to convert
27
- * @returns {Array.<*>} Converted array
28
- */
29
- util.toArray = function toArray(object) {
30
- if (object) {
31
- var keys = Object.keys(object),
32
- array = new Array(keys.length),
33
- index = 0;
34
- while (index < keys.length)
35
- array[index] = object[keys[index++]];
36
- return array;
37
- }
38
- return [];
39
- };
40
-
41
- /**
42
- * Converts an array of keys immediately followed by their respective value to an object, omitting undefined values.
43
- * @param {Array.<*>} array Array to convert
44
- * @returns {Object.<string,*>} Converted object
45
- */
46
- util.toObject = function toObject(array) {
47
- var object = {},
48
- index = 0;
49
- while (index < array.length) {
50
- var key = array[index++],
51
- val = array[index++];
52
- if (val !== undefined)
53
- object[key] = val;
54
- }
55
- return object;
56
- };
57
-
58
- var safePropBackslashRe = /\\/g,
59
- safePropQuoteRe = /"/g;
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 /^(?:do|if|in|for|let|new|try|var|case|else|enum|eval|false|null|this|true|void|with|break|catch|class|const|super|throw|while|yield|delete|export|import|public|return|static|switch|typeof|default|extends|finally|package|private|continue|debugger|function|arguments|interface|protected|implements|instanceof)$/.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) || util.isReserved(prop))
77
- return "[\"" + prop.replace(safePropBackslashRe, "\\\\").replace(safePropQuoteRe, "\\\"") + "\"]";
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
- */
97
- util.camelCase = function camelCase(str) {
98
- return str.substring(0, 1)
99
- + str.substring(1)
100
- .replace(camelCaseRe, function($0, $1) { return $1.toUpperCase(); });
101
- };
102
-
103
- /**
104
- * Compares reflected fields by id.
105
- * @param {Field} a First field
106
- * @param {Field} b Second field
107
- * @returns {number} Comparison value
108
- */
109
- util.compareFieldsById = function compareFieldsById(a, b) {
110
- return a.id - b.id;
111
- };
112
-
113
- /**
114
- * Decorator helper for types (TypeScript).
115
- * @param {Constructor<T>} ctor Constructor function
116
- * @param {string} [typeName] Type name, defaults to the constructor's name
117
- * @returns {Type} Reflected type
118
- * @template T extends Message<T>
119
- * @property {Root} root Decorators root
120
- */
121
- util.decorateType = function decorateType(ctor, typeName) {
122
-
123
- /* istanbul ignore if */
124
- if (ctor.$type) {
125
- if (typeName && ctor.$type.name !== typeName) {
126
- util.decorateRoot.remove(ctor.$type);
127
- ctor.$type.name = typeName;
128
- util.decorateRoot.add(ctor.$type);
129
- }
130
- return ctor.$type;
131
- }
132
-
133
- /* istanbul ignore next */
134
- if (!Type)
135
- Type = require("./type");
136
-
137
- var type = new Type(typeName || ctor.name);
138
- util.decorateRoot.add(type);
139
- type.ctor = ctor; // sets up .encode, .decode etc.
140
- Object.defineProperty(ctor, "$type", { value: type, enumerable: false });
141
- Object.defineProperty(ctor.prototype, "$type", { value: type, enumerable: false });
142
- return type;
143
- };
144
-
145
- var decorateEnumIndex = 0;
146
-
147
- /**
148
- * Decorator helper for enums (TypeScript).
149
- * @param {Object} object Enum object
150
- * @returns {Enum} Reflected enum
151
- */
152
- util.decorateEnum = function decorateEnum(object) {
153
-
154
- /* istanbul ignore if */
155
- if (object.$type)
156
- return object.$type;
157
-
158
- /* istanbul ignore next */
159
- if (!Enum)
160
- Enum = require("./enum");
161
-
162
- var enm = new Enum("Enum" + decorateEnumIndex++, object);
163
- util.decorateRoot.add(enm);
164
- Object.defineProperty(object, "$type", { value: enm, enumerable: false });
165
- return enm;
166
- };
167
-
168
-
169
- /**
170
- * Sets the value of a property by property path. If a value already exists, it is turned to an array
171
- * @param {Object.<string,*>} dst Destination object
172
- * @param {string} path dot '.' delimited path of the property to set
173
- * @param {Object} value the value to set
174
- * @returns {Object.<string,*>} Destination object
175
- */
176
- util.setProperty = function setProperty(dst, path, value) {
177
- function setProp(dst, path, value) {
178
- var part = path.shift();
179
- if (part === "__proto__" || part === "prototype") {
180
- return dst;
181
- }
182
- if (path.length > 0) {
183
- dst[part] = setProp(dst[part] || {}, path, value);
184
- } else {
185
- var prevValue = dst[part];
186
- if (prevValue)
187
- value = [].concat(prevValue).concat(value);
188
- dst[part] = value;
189
- }
190
- return dst;
191
- }
192
-
193
- if (typeof dst !== "object")
194
- throw TypeError("dst must be an object");
195
- if (!path)
196
- throw TypeError("path must be specified");
197
-
198
- path = path.split(".");
199
- return setProp(dst, path, value);
200
- };
201
-
202
- /**
203
- * Decorator root (TypeScript).
204
- * @name util.decorateRoot
205
- * @type {Root}
206
- * @readonly
207
- */
208
- Object.defineProperty(util, "decorateRoot", {
209
- get: function() {
210
- return roots["decorated"] || (roots["decorated"] = new (require("./root"))());
211
- }
212
- });
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("@protobufjs/codegen");
15
+ util.fetch = require("@protobufjs/fetch");
16
+ util.path = require("@protobufjs/path");
17
+
18
+ /**
19
+ * Node's fs module if available.
20
+ * @type {Object.<string,*>}
21
+ */
22
+ util.fs = util.inquire("fs");
23
+
24
+ /**
25
+ * Converts an object's values to an array.
26
+ * @param {Object.<string,*>} object Object to convert
27
+ * @returns {Array.<*>} Converted array
28
+ */
29
+ util.toArray = function toArray(object) {
30
+ if (object) {
31
+ var keys = Object.keys(object),
32
+ array = new Array(keys.length),
33
+ index = 0;
34
+ while (index < keys.length)
35
+ array[index] = object[keys[index++]];
36
+ return array;
37
+ }
38
+ return [];
39
+ };
40
+
41
+ /**
42
+ * Converts an array of keys immediately followed by their respective value to an object, omitting undefined values.
43
+ * @param {Array.<*>} array Array to convert
44
+ * @returns {Object.<string,*>} Converted object
45
+ */
46
+ util.toObject = function toObject(array) {
47
+ var object = {},
48
+ index = 0;
49
+ while (index < array.length) {
50
+ var key = array[index++],
51
+ val = array[index++];
52
+ if (val !== undefined)
53
+ object[key] = val;
54
+ }
55
+ return object;
56
+ };
57
+
58
+ var safePropBackslashRe = /\\/g,
59
+ safePropQuoteRe = /"/g;
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 /^(?:do|if|in|for|let|new|try|var|case|else|enum|eval|false|null|this|true|void|with|break|catch|class|const|super|throw|while|yield|delete|export|import|public|return|static|switch|typeof|default|extends|finally|package|private|continue|debugger|function|arguments|interface|protected|implements|instanceof)$/.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) || util.isReserved(prop))
77
+ return "[\"" + prop.replace(safePropBackslashRe, "\\\\").replace(safePropQuoteRe, "\\\"") + "\"]";
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
+ */
97
+ util.camelCase = function camelCase(str) {
98
+ return str.substring(0, 1)
99
+ + str.substring(1)
100
+ .replace(camelCaseRe, function($0, $1) { return $1.toUpperCase(); });
101
+ };
102
+
103
+ /**
104
+ * Compares reflected fields by id.
105
+ * @param {Field} a First field
106
+ * @param {Field} b Second field
107
+ * @returns {number} Comparison value
108
+ */
109
+ util.compareFieldsById = function compareFieldsById(a, b) {
110
+ return a.id - b.id;
111
+ };
112
+
113
+ /**
114
+ * Decorator helper for types (TypeScript).
115
+ * @param {Constructor<T>} ctor Constructor function
116
+ * @param {string} [typeName] Type name, defaults to the constructor's name
117
+ * @returns {Type} Reflected type
118
+ * @template T extends Message<T>
119
+ * @property {Root} root Decorators root
120
+ */
121
+ util.decorateType = function decorateType(ctor, typeName) {
122
+
123
+ /* istanbul ignore if */
124
+ if (ctor.$type) {
125
+ if (typeName && ctor.$type.name !== typeName) {
126
+ util.decorateRoot.remove(ctor.$type);
127
+ ctor.$type.name = typeName;
128
+ util.decorateRoot.add(ctor.$type);
129
+ }
130
+ return ctor.$type;
131
+ }
132
+
133
+ /* istanbul ignore next */
134
+ if (!Type)
135
+ Type = require("./type");
136
+
137
+ var type = new Type(typeName || ctor.name);
138
+ util.decorateRoot.add(type);
139
+ type.ctor = ctor; // sets up .encode, .decode etc.
140
+ Object.defineProperty(ctor, "$type", { value: type, enumerable: false });
141
+ Object.defineProperty(ctor.prototype, "$type", { value: type, enumerable: false });
142
+ return type;
143
+ };
144
+
145
+ var decorateEnumIndex = 0;
146
+
147
+ /**
148
+ * Decorator helper for enums (TypeScript).
149
+ * @param {Object} object Enum object
150
+ * @returns {Enum} Reflected enum
151
+ */
152
+ util.decorateEnum = function decorateEnum(object) {
153
+
154
+ /* istanbul ignore if */
155
+ if (object.$type)
156
+ return object.$type;
157
+
158
+ /* istanbul ignore next */
159
+ if (!Enum)
160
+ Enum = require("./enum");
161
+
162
+ var enm = new Enum("Enum" + decorateEnumIndex++, object);
163
+ util.decorateRoot.add(enm);
164
+ Object.defineProperty(object, "$type", { value: enm, enumerable: false });
165
+ return enm;
166
+ };
167
+
168
+
169
+ /**
170
+ * Sets the value of a property by property path. If a value already exists, it is turned to an array
171
+ * @param {Object.<string,*>} dst Destination object
172
+ * @param {string} path dot '.' delimited path of the property to set
173
+ * @param {Object} value the value to set
174
+ * @returns {Object.<string,*>} Destination object
175
+ */
176
+ util.setProperty = function setProperty(dst, path, value) {
177
+ function setProp(dst, path, value) {
178
+ var part = path.shift();
179
+ if (part === "__proto__" || part === "prototype") {
180
+ return dst;
181
+ }
182
+ if (path.length > 0) {
183
+ dst[part] = setProp(dst[part] || {}, path, value);
184
+ } else {
185
+ var prevValue = dst[part];
186
+ if (prevValue)
187
+ value = [].concat(prevValue).concat(value);
188
+ dst[part] = value;
189
+ }
190
+ return dst;
191
+ }
192
+
193
+ if (typeof dst !== "object")
194
+ throw TypeError("dst must be an object");
195
+ if (!path)
196
+ throw TypeError("path must be specified");
197
+
198
+ path = path.split(".");
199
+ return setProp(dst, path, value);
200
+ };
201
+
202
+ /**
203
+ * Decorator root (TypeScript).
204
+ * @name util.decorateRoot
205
+ * @type {Root}
206
+ * @readonly
207
+ */
208
+ Object.defineProperty(util, "decorateRoot", {
209
+ get: function() {
210
+ return roots["decorated"] || (roots["decorated"] = new (require("./root"))());
211
+ }
212
+ });