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/util.js CHANGED
@@ -1,213 +1,215 @@
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
- * @param {boolean} overWrite whether or not to concatenate the values into an array or overwrite; defaults to false.
175
- * @returns {Object.<string,*>} Destination object
176
- */
177
- util.setProperty = function setProperty(dst, path, value) {
178
- function setProp(dst, path, value) {
179
- var part = path.shift();
180
- if (part === "__proto__" || part === "prototype") {
181
- return dst;
182
- }
183
- if (path.length > 0) {
184
- dst[part] = setProp(dst[part] || {}, path, value);
185
- } else {
186
- var prevValue = dst[part];
187
- if (prevValue)
188
- value = [].concat(prevValue).concat(value);
189
- dst[part] = value;
190
- }
191
- return dst;
192
- }
193
-
194
- if (typeof dst !== "object")
195
- throw TypeError("dst must be an object");
196
- if (!path)
197
- throw TypeError("path must be specified");
198
-
199
- path = path.split(".");
200
- return setProp(dst, path, value);
201
- };
202
-
203
- /**
204
- * Decorator root (TypeScript).
205
- * @name util.decorateRoot
206
- * @type {Root}
207
- * @readonly
208
- */
209
- Object.defineProperty(util, "decorateRoot", {
210
- get: function() {
211
- return roots["decorated"] || (roots["decorated"] = new (require("./root"))());
212
- }
213
- });
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
+ unsafePropertyRe = util.patterns.unsafePropertyRe;
21
+
22
+ /**
23
+ * Node's fs module if available.
24
+ * @type {Object.<string,*>}
25
+ */
26
+ util.fs = util.inquire("fs");
27
+
28
+ /**
29
+ * Converts an object's values to an array.
30
+ * @param {Object.<string,*>} object Object to convert
31
+ * @returns {Array.<*>} Converted array
32
+ */
33
+ util.toArray = function toArray(object) {
34
+ if (object) {
35
+ var keys = Object.keys(object),
36
+ array = new Array(keys.length),
37
+ index = 0;
38
+ while (index < keys.length)
39
+ array[index] = object[keys[index++]];
40
+ return array;
41
+ }
42
+ return [];
43
+ };
44
+
45
+ /**
46
+ * Converts an array of keys immediately followed by their respective value to an object, omitting undefined values.
47
+ * @param {Array.<*>} array Array to convert
48
+ * @returns {Object.<string,*>} Converted object
49
+ */
50
+ util.toObject = function toObject(array) {
51
+ var object = {},
52
+ index = 0;
53
+ while (index < array.length) {
54
+ var key = array[index++],
55
+ val = array[index++];
56
+ if (val !== undefined)
57
+ object[key] = val;
58
+ }
59
+ return object;
60
+ };
61
+
62
+ /**
63
+ * Tests whether the specified name is a reserved word in JS.
64
+ * @param {string} name Name to test
65
+ * @returns {boolean} `true` if reserved, otherwise `false`
66
+ */
67
+ util.isReserved = function isReserved(name) {
68
+ return reservedRe.test(name);
69
+ };
70
+
71
+ /**
72
+ * Returns a safe property accessor for the specified property name.
73
+ * @param {string} prop Property name
74
+ * @returns {string} Safe accessor
75
+ */
76
+ util.safeProp = function safeProp(prop) {
77
+ if (!/^[$\w_]+$/.test(prop) || reservedRe.test(prop))
78
+ return "[" + JSON.stringify(prop) + "]";
79
+ return "." + prop;
80
+ };
81
+
82
+ /**
83
+ * Converts the first character of a string to upper case.
84
+ * @param {string} str String to convert
85
+ * @returns {string} Converted string
86
+ */
87
+ util.ucFirst = function ucFirst(str) {
88
+ return str.charAt(0).toUpperCase() + str.substring(1);
89
+ };
90
+
91
+ var camelCaseRe = /_([a-z])/g;
92
+
93
+ /**
94
+ * Converts a string to camel case.
95
+ * @param {string} str String to convert
96
+ * @returns {string} Converted string
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
+ * Compares reflected fields by id.
106
+ * @param {Field} a First field
107
+ * @param {Field} b Second field
108
+ * @returns {number} Comparison value
109
+ */
110
+ util.compareFieldsById = function compareFieldsById(a, b) {
111
+ return a.id - b.id;
112
+ };
113
+
114
+ /**
115
+ * Decorator helper for types (TypeScript).
116
+ * @param {Constructor<T>} ctor Constructor function
117
+ * @param {string} [typeName] Type name, defaults to the constructor's name
118
+ * @returns {Type} Reflected type
119
+ * @template T extends Message<T>
120
+ * @property {Root} root Decorators root
121
+ */
122
+ util.decorateType = function decorateType(ctor, typeName) {
123
+
124
+ /* istanbul ignore if */
125
+ if (ctor.$type) {
126
+ if (typeName && ctor.$type.name !== typeName) {
127
+ util.decorateRoot.remove(ctor.$type);
128
+ ctor.$type.name = typeName;
129
+ util.decorateRoot.add(ctor.$type);
130
+ }
131
+ return ctor.$type;
132
+ }
133
+
134
+ /* istanbul ignore next */
135
+ if (!Type)
136
+ Type = require("./type");
137
+
138
+ var type = new Type(typeName || ctor.name);
139
+ util.decorateRoot.add(type);
140
+ type.ctor = ctor; // sets up .encode, .decode etc.
141
+ Object.defineProperty(ctor, "$type", { value: type, enumerable: false });
142
+ Object.defineProperty(ctor.prototype, "$type", { value: type, enumerable: false });
143
+ return type;
144
+ };
145
+
146
+ var decorateEnumIndex = 0;
147
+
148
+ /**
149
+ * Decorator helper for enums (TypeScript).
150
+ * @param {Object} object Enum object
151
+ * @returns {Enum} Reflected enum
152
+ */
153
+ util.decorateEnum = function decorateEnum(object) {
154
+
155
+ /* istanbul ignore if */
156
+ if (object.$type)
157
+ return object.$type;
158
+
159
+ /* istanbul ignore next */
160
+ if (!Enum)
161
+ Enum = require("./enum");
162
+
163
+ var enm = new Enum("Enum" + decorateEnumIndex++, object);
164
+ util.decorateRoot.add(enm);
165
+ Object.defineProperty(object, "$type", { value: enm, enumerable: false });
166
+ return enm;
167
+ };
168
+
169
+
170
+ /**
171
+ * Sets the value of a property by property path. If a value already exists, it is turned to an array
172
+ * @param {Object.<string,*>} dst Destination object
173
+ * @param {string} path dot '.' delimited path of the property to set
174
+ * @param {Object} value the value to set
175
+ * @param {boolean|undefined} [ifNotSet] Sets the option only if it isn't currently set
176
+ * @returns {Object.<string,*>} Destination object
177
+ */
178
+ util.setProperty = function setProperty(dst, path, value, ifNotSet) {
179
+ function setProp(dst, path, value) {
180
+ var part = path.shift();
181
+ if (unsafePropertyRe.test(part))
182
+ return dst;
183
+ if (path.length > 0) {
184
+ dst[part] = setProp(dst[part] || {}, path, value);
185
+ } else {
186
+ var prevValue = dst[part];
187
+ if (prevValue && ifNotSet)
188
+ return dst;
189
+ if (prevValue)
190
+ value = [].concat(prevValue).concat(value);
191
+ dst[part] = value;
192
+ }
193
+ return dst;
194
+ }
195
+
196
+ if (typeof dst !== "object")
197
+ throw TypeError("dst must be an object");
198
+ if (!path)
199
+ throw TypeError("path must be specified");
200
+
201
+ path = path.split(".");
202
+ return setProp(dst, path, value);
203
+ };
204
+
205
+ /**
206
+ * Decorator root (TypeScript).
207
+ * @name util.decorateRoot
208
+ * @type {Root}
209
+ * @readonly
210
+ */
211
+ Object.defineProperty(util, "decorateRoot", {
212
+ get: function() {
213
+ return roots["decorated"] || (roots["decorated"] = new (require("./root"))());
214
+ }
215
+ });