@depup/apollo__protobufjs 1.2.7-depup.0

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 (113) hide show
  1. package/LICENSE +39 -0
  2. package/README.md +32 -0
  3. package/bin/pbjs +6 -0
  4. package/bin/pbts +6 -0
  5. package/changes.json +14 -0
  6. package/cli/LICENSE +33 -0
  7. package/cli/README.md +11 -0
  8. package/cli/bin/pbjs +6 -0
  9. package/cli/bin/pbts +6 -0
  10. package/cli/index.d.ts +3 -0
  11. package/cli/index.js +3 -0
  12. package/cli/lib/tsd-jsdoc/LICENSE +21 -0
  13. package/cli/lib/tsd-jsdoc/README.md +23 -0
  14. package/cli/lib/tsd-jsdoc/plugin.js +21 -0
  15. package/cli/lib/tsd-jsdoc/publish.js +693 -0
  16. package/cli/lib/tsd-jsdoc.json +18 -0
  17. package/cli/package.json +7 -0
  18. package/cli/package.standalone.json +32 -0
  19. package/cli/pbjs.d.ts +9 -0
  20. package/cli/pbjs.js +331 -0
  21. package/cli/pbts.d.ts +9 -0
  22. package/cli/pbts.js +198 -0
  23. package/cli/targets/json-module.js +38 -0
  24. package/cli/targets/json.js +8 -0
  25. package/cli/targets/proto.js +326 -0
  26. package/cli/targets/proto2.js +10 -0
  27. package/cli/targets/proto3.js +10 -0
  28. package/cli/targets/static-module.js +29 -0
  29. package/cli/targets/static.js +709 -0
  30. package/cli/util.js +183 -0
  31. package/cli/wrappers/amd.js +7 -0
  32. package/cli/wrappers/closure.js +7 -0
  33. package/cli/wrappers/commonjs.js +7 -0
  34. package/cli/wrappers/default.js +15 -0
  35. package/cli/wrappers/es6.js +5 -0
  36. package/dist/README.md +31 -0
  37. package/dist/light/README.md +31 -0
  38. package/dist/light/protobuf.js +7198 -0
  39. package/dist/light/protobuf.js.map +1 -0
  40. package/dist/light/protobuf.min.js +7 -0
  41. package/dist/light/protobuf.min.js.map +1 -0
  42. package/dist/minimal/README.md +31 -0
  43. package/dist/minimal/protobuf.js +2675 -0
  44. package/dist/minimal/protobuf.js.map +1 -0
  45. package/dist/minimal/protobuf.min.js +7 -0
  46. package/dist/minimal/protobuf.min.js.map +1 -0
  47. package/dist/protobuf.js +8775 -0
  48. package/dist/protobuf.js.map +1 -0
  49. package/dist/protobuf.min.js +7 -0
  50. package/dist/protobuf.min.js.map +1 -0
  51. package/ext/debug/README.md +4 -0
  52. package/ext/debug/index.js +71 -0
  53. package/ext/descriptor/README.md +72 -0
  54. package/ext/descriptor/index.d.ts +191 -0
  55. package/ext/descriptor/index.js +1052 -0
  56. package/ext/descriptor/test.js +54 -0
  57. package/google/LICENSE +27 -0
  58. package/google/README.md +1 -0
  59. package/google/api/annotations.json +83 -0
  60. package/google/api/annotations.proto +11 -0
  61. package/google/api/http.json +86 -0
  62. package/google/api/http.proto +31 -0
  63. package/google/protobuf/api.json +118 -0
  64. package/google/protobuf/api.proto +34 -0
  65. package/google/protobuf/descriptor.json +739 -0
  66. package/google/protobuf/descriptor.proto +286 -0
  67. package/google/protobuf/source_context.json +20 -0
  68. package/google/protobuf/source_context.proto +7 -0
  69. package/google/protobuf/type.json +202 -0
  70. package/google/protobuf/type.proto +89 -0
  71. package/index.d.ts +2628 -0
  72. package/index.js +4 -0
  73. package/light.d.ts +2 -0
  74. package/light.js +4 -0
  75. package/minimal.d.ts +2 -0
  76. package/minimal.js +4 -0
  77. package/package.json +147 -0
  78. package/scripts/postinstall.js +35 -0
  79. package/src/common.js +399 -0
  80. package/src/converter.js +304 -0
  81. package/src/decoder.js +106 -0
  82. package/src/encoder.js +119 -0
  83. package/src/enum.js +181 -0
  84. package/src/field.js +379 -0
  85. package/src/index-light.js +104 -0
  86. package/src/index-minimal.js +36 -0
  87. package/src/index.js +12 -0
  88. package/src/mapfield.js +126 -0
  89. package/src/message.js +139 -0
  90. package/src/method.js +151 -0
  91. package/src/namespace.js +433 -0
  92. package/src/object.js +200 -0
  93. package/src/oneof.js +203 -0
  94. package/src/parse.js +761 -0
  95. package/src/reader.js +405 -0
  96. package/src/reader_buffer.js +44 -0
  97. package/src/root.js +353 -0
  98. package/src/roots.js +18 -0
  99. package/src/rpc/service.js +142 -0
  100. package/src/rpc.js +36 -0
  101. package/src/service.js +167 -0
  102. package/src/tokenize.js +397 -0
  103. package/src/type.js +589 -0
  104. package/src/types.js +196 -0
  105. package/src/typescript.jsdoc +22 -0
  106. package/src/util/longbits.js +200 -0
  107. package/src/util/minimal.js +406 -0
  108. package/src/util.js +178 -0
  109. package/src/verifier.js +191 -0
  110. package/src/wrappers.js +83 -0
  111. package/src/writer.js +459 -0
  112. package/src/writer_buffer.js +81 -0
  113. package/tsconfig.json +7 -0
@@ -0,0 +1,191 @@
1
+ "use strict";
2
+ module.exports = verifier;
3
+
4
+ var Enum = require("./enum"),
5
+ util = require("./util");
6
+
7
+ function invalid(field, expected) {
8
+ return field.name + ": " + expected + (field.repeated && expected !== "array" ? "[]" : field.map && expected !== "object" ? "{k:"+field.keyType+"}" : "") + " expected";
9
+ }
10
+
11
+ /**
12
+ * Generates a partial value verifier.
13
+ * @param {Codegen} gen Codegen instance
14
+ * @param {Field} field Reflected field
15
+ * @param {number} fieldIndex Field index
16
+ * @param {string} ref Variable reference
17
+ * @returns {Codegen} Codegen instance
18
+ * @ignore
19
+ */
20
+ function genVerifyValue(gen, field, fieldIndex, ref) {
21
+ /* eslint-disable no-unexpected-multiline */
22
+ if (field.resolvedType) {
23
+ if (field.resolvedType instanceof Enum) { gen
24
+ ("switch(%s){", ref)
25
+ ("default:")
26
+ ("return%j", invalid(field, "enum value"));
27
+ for (var keys = Object.keys(field.resolvedType.values), j = 0; j < keys.length; ++j) gen
28
+ ("case %i:", field.resolvedType.values[keys[j]]);
29
+ gen
30
+ ("break")
31
+ ("}");
32
+ } else {
33
+ gen
34
+ ("{")
35
+ ("var e=types[%i].verify(%s);", fieldIndex, ref)
36
+ ("if(e)")
37
+ ("return%j+e", field.name + ".")
38
+ ("}");
39
+ }
40
+ } else {
41
+ switch (field.type) {
42
+ case "int32":
43
+ case "uint32":
44
+ case "sint32":
45
+ case "fixed32":
46
+ case "sfixed32": gen
47
+ ("if(!util.isInteger(%s))", ref)
48
+ ("return%j", invalid(field, "integer"));
49
+ break;
50
+ case "int64":
51
+ case "uint64":
52
+ case "sint64":
53
+ case "fixed64":
54
+ case "sfixed64": gen
55
+ ("if(!util.isInteger(%s)&&!(%s&&util.isInteger(%s.low)&&util.isInteger(%s.high)))", ref, ref, ref, ref)
56
+ ("return%j", invalid(field, "integer|Long"));
57
+ break;
58
+ case "float":
59
+ case "double": gen
60
+ ("if(typeof %s!==\"number\")", ref)
61
+ ("return%j", invalid(field, "number"));
62
+ break;
63
+ case "bool": gen
64
+ ("if(typeof %s!==\"boolean\")", ref)
65
+ ("return%j", invalid(field, "boolean"));
66
+ break;
67
+ case "string": gen
68
+ ("if(!util.isString(%s))", ref)
69
+ ("return%j", invalid(field, "string"));
70
+ break;
71
+ case "bytes": gen
72
+ ("if(!(%s&&typeof %s.length===\"number\"||util.isString(%s)))", ref, ref, ref)
73
+ ("return%j", invalid(field, "buffer"));
74
+ break;
75
+ }
76
+ }
77
+ return gen;
78
+ /* eslint-enable no-unexpected-multiline */
79
+ }
80
+
81
+ /**
82
+ * Generates a partial key verifier.
83
+ * @param {Codegen} gen Codegen instance
84
+ * @param {Field} field Reflected field
85
+ * @param {string} ref Variable reference
86
+ * @returns {Codegen} Codegen instance
87
+ * @ignore
88
+ */
89
+ function genVerifyKey(gen, field, ref) {
90
+ /* eslint-disable no-unexpected-multiline */
91
+ switch (field.keyType) {
92
+ case "int32":
93
+ case "uint32":
94
+ case "sint32":
95
+ case "fixed32":
96
+ case "sfixed32": gen
97
+ ("if(!util.key32Re.test(%s))", ref)
98
+ ("return%j", invalid(field, "integer key"));
99
+ break;
100
+ case "int64":
101
+ case "uint64":
102
+ case "sint64":
103
+ case "fixed64":
104
+ case "sfixed64": gen
105
+ ("if(!util.key64Re.test(%s))", ref) // see comment above: x is ok, d is not
106
+ ("return%j", invalid(field, "integer|Long key"));
107
+ break;
108
+ case "bool": gen
109
+ ("if(!util.key2Re.test(%s))", ref)
110
+ ("return%j", invalid(field, "boolean key"));
111
+ break;
112
+ }
113
+ return gen;
114
+ /* eslint-enable no-unexpected-multiline */
115
+ }
116
+
117
+ /**
118
+ * Generates a verifier specific to the specified message type.
119
+ * @param {Type} mtype Message type
120
+ * @returns {Codegen} Codegen instance
121
+ */
122
+ function verifier(mtype) {
123
+ /* eslint-disable no-unexpected-multiline */
124
+
125
+ var gen = util.codegen(["m"], mtype.name + "$verify")
126
+ ("if(typeof m!==\"object\"||m===null)")
127
+ ("return%j", "object expected");
128
+ var oneofs = mtype.oneofsArray,
129
+ seenFirstField = {};
130
+ if (oneofs.length) gen
131
+ ("var p={}");
132
+
133
+ for (var i = 0; i < /* initializes */ mtype.fieldsArray.length; ++i) {
134
+ var field = mtype._fieldsArray[i].resolve(),
135
+ ref = "m" + util.safeProp(field.name);
136
+
137
+ if (field.optional) gen
138
+ ("if(%s!=null&&m.hasOwnProperty(%j)){", ref, field.name); // !== undefined && !== null
139
+
140
+ // map fields
141
+ if (field.map) { gen
142
+ ("if(!util.isObject(%s))", ref)
143
+ ("return%j", invalid(field, "object"))
144
+ ("var k=Object.keys(%s)", ref)
145
+ ("for(var i=0;i<k.length;++i){");
146
+ genVerifyKey(gen, field, "k[i]");
147
+ genVerifyValue(gen, field, i, ref + "[k[i]]")
148
+ ("}");
149
+
150
+ // repeated fields
151
+ } else if (field.repeated) {
152
+ var arrayRef = ref;
153
+ if (field.useToArray()) {
154
+ arrayRef = "array" + field.id;
155
+ gen("var %s", arrayRef);
156
+ gen("if (%s!=null&&%s.toArray) { %s = %s.toArray() } else { %s = %s }",
157
+ ref, ref, arrayRef, ref, arrayRef, ref);
158
+ }
159
+ gen
160
+ ("if(!Array.isArray(%s))", arrayRef)
161
+ ("return%j", invalid(field, "array"))
162
+ ("for(var i=0;i<%s.length;++i){", arrayRef);
163
+ if (field.preEncoded()) {
164
+ gen("if (!(%s instanceof Uint8Array)) {", arrayRef + "[i]")
165
+ }
166
+ genVerifyValue(gen, field, i, arrayRef + "[i]")
167
+ if (field.preEncoded()) {
168
+ gen("}");
169
+ }
170
+ gen("}");
171
+
172
+ // required or present fields
173
+ } else {
174
+ if (field.partOf) {
175
+ var oneofProp = util.safeProp(field.partOf.name);
176
+ if (seenFirstField[field.partOf.name] === 1) gen
177
+ ("if(p%s===1)", oneofProp)
178
+ ("return%j", field.partOf.name + ": multiple values");
179
+ seenFirstField[field.partOf.name] = 1;
180
+ gen
181
+ ("p%s=1", oneofProp);
182
+ }
183
+ genVerifyValue(gen, field, i, ref);
184
+ }
185
+ if (field.optional) gen
186
+ ("}");
187
+ }
188
+ return gen
189
+ ("return null");
190
+ /* eslint-enable no-unexpected-multiline */
191
+ }
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Wrappers for common types.
5
+ * @type {Object.<string,IWrapper>}
6
+ * @const
7
+ */
8
+ var wrappers = exports;
9
+
10
+ var Message = require("./message");
11
+
12
+ /**
13
+ * From object converter part of an {@link IWrapper}.
14
+ * @typedef WrapperFromObjectConverter
15
+ * @type {function}
16
+ * @param {Object.<string,*>} object Plain object
17
+ * @returns {Message<{}>} Message instance
18
+ * @this Type
19
+ */
20
+
21
+ /**
22
+ * To object converter part of an {@link IWrapper}.
23
+ * @typedef WrapperToObjectConverter
24
+ * @type {function}
25
+ * @param {Message<{}>} message Message instance
26
+ * @param {IConversionOptions} [options] Conversion options
27
+ * @returns {Object.<string,*>} Plain object
28
+ * @this Type
29
+ */
30
+
31
+ /**
32
+ * Common type wrapper part of {@link wrappers}.
33
+ * @interface IWrapper
34
+ * @property {WrapperFromObjectConverter} [fromObject] From object converter
35
+ * @property {WrapperToObjectConverter} [toObject] To object converter
36
+ */
37
+
38
+ // Custom wrapper for Any
39
+ wrappers[".google.protobuf.Any"] = {
40
+
41
+ fromObject: function(object) {
42
+
43
+ // unwrap value type if mapped
44
+ if (object && object["@type"]) {
45
+ var type = this.lookup(object["@type"]);
46
+ /* istanbul ignore else */
47
+ if (type) {
48
+ // type_url does not accept leading "."
49
+ var type_url = object["@type"].charAt(0) === "." ?
50
+ object["@type"].substr(1) : object["@type"];
51
+ // type_url prefix is optional, but path seperator is required
52
+ return this.create({
53
+ type_url: "/" + type_url,
54
+ value: type.encode(type.fromObject(object)).finish()
55
+ });
56
+ }
57
+ }
58
+
59
+ return this.fromObject(object);
60
+ },
61
+
62
+ toObject: function(message, options) {
63
+
64
+ // decode value if requested and unmapped
65
+ if (options && options.json && message.type_url && message.value) {
66
+ // Only use fully qualified type name after the last '/'
67
+ var name = message.type_url.substring(message.type_url.lastIndexOf("/") + 1);
68
+ var type = this.lookup(name);
69
+ /* istanbul ignore else */
70
+ if (type)
71
+ message = type.decode(message.value);
72
+ }
73
+
74
+ // wrap value if unmapped
75
+ if (!(message instanceof this.ctor) && message instanceof Message) {
76
+ var object = message.$type.toObject(message, options);
77
+ object["@type"] = message.$type.fullName;
78
+ return object;
79
+ }
80
+
81
+ return this.toObject(message, options);
82
+ }
83
+ };