@bufbuild/protobuf 0.0.1-alpha.1

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 (146) hide show
  1. package/README.md +6 -0
  2. package/dist/cjs/binary-encoding.js +434 -0
  3. package/dist/cjs/binary-format.js +2 -0
  4. package/dist/cjs/descriptor-registry.js +518 -0
  5. package/dist/cjs/descriptor-set.js +557 -0
  6. package/dist/cjs/enum.js +2 -0
  7. package/dist/cjs/field-list.js +2 -0
  8. package/dist/cjs/field.js +40 -0
  9. package/dist/cjs/google/protobuf/any_pb.js +280 -0
  10. package/dist/cjs/google/protobuf/api_pb.js +383 -0
  11. package/dist/cjs/google/protobuf/compiler/plugin_pb.js +334 -0
  12. package/dist/cjs/google/protobuf/descriptor_pb.js +2311 -0
  13. package/dist/cjs/google/protobuf/duration_pb.js +201 -0
  14. package/dist/cjs/google/protobuf/empty_pb.js +72 -0
  15. package/dist/cjs/google/protobuf/field_mask_pb.js +347 -0
  16. package/dist/cjs/google/protobuf/source_context_pb.js +74 -0
  17. package/dist/cjs/google/protobuf/struct_pb.js +288 -0
  18. package/dist/cjs/google/protobuf/timestamp_pb.js +271 -0
  19. package/dist/cjs/google/protobuf/type_pb.js +613 -0
  20. package/dist/cjs/google/protobuf/wrappers_pb.js +658 -0
  21. package/dist/cjs/google/varint.js +280 -0
  22. package/dist/cjs/index.js +148 -0
  23. package/dist/cjs/json-format.js +2 -0
  24. package/dist/cjs/message-type.js +2 -0
  25. package/dist/cjs/message.js +98 -0
  26. package/dist/cjs/private/assert.js +52 -0
  27. package/dist/cjs/private/base64.js +118 -0
  28. package/dist/cjs/private/binary-format-common.js +253 -0
  29. package/dist/cjs/private/binary-format-proto2.js +120 -0
  30. package/dist/cjs/private/binary-format-proto3.js +102 -0
  31. package/dist/cjs/private/enum.js +70 -0
  32. package/dist/cjs/private/field-list.js +62 -0
  33. package/dist/cjs/private/field-wrapper.js +25 -0
  34. package/dist/cjs/private/field.js +34 -0
  35. package/dist/cjs/private/json-format-common.js +482 -0
  36. package/dist/cjs/private/json-format-proto2.js +100 -0
  37. package/dist/cjs/private/json-format-proto3.js +103 -0
  38. package/dist/cjs/private/message-type.js +37 -0
  39. package/dist/cjs/private/names.js +101 -0
  40. package/dist/cjs/private/options-map.js +2 -0
  41. package/dist/cjs/private/proto-runtime.js +24 -0
  42. package/dist/cjs/private/scalars.js +138 -0
  43. package/dist/cjs/private/util-common.js +229 -0
  44. package/dist/cjs/private/util.js +2 -0
  45. package/dist/cjs/proto-int64.js +121 -0
  46. package/dist/cjs/proto2.js +86 -0
  47. package/dist/cjs/proto3.js +99 -0
  48. package/dist/cjs/service-type.js +43 -0
  49. package/dist/cjs/type-registry.js +42 -0
  50. package/dist/esm/binary-encoding.js +434 -0
  51. package/dist/esm/binary-format.js +1 -0
  52. package/dist/esm/descriptor-registry.js +521 -0
  53. package/dist/esm/descriptor-set.js +517 -0
  54. package/dist/esm/enum.js +1 -0
  55. package/dist/esm/field-list.js +1 -0
  56. package/dist/esm/field.js +37 -0
  57. package/dist/esm/google/protobuf/any_pb.js +276 -0
  58. package/dist/esm/google/protobuf/api_pb.js +350 -0
  59. package/dist/esm/google/protobuf/compiler/plugin_pb.js +318 -0
  60. package/dist/esm/google/protobuf/descriptor_pb.js +2213 -0
  61. package/dist/esm/google/protobuf/duration_pb.js +197 -0
  62. package/dist/esm/google/protobuf/empty_pb.js +68 -0
  63. package/dist/esm/google/protobuf/field_mask_pb.js +343 -0
  64. package/dist/esm/google/protobuf/source_context_pb.js +70 -0
  65. package/dist/esm/google/protobuf/struct_pb.js +282 -0
  66. package/dist/esm/google/protobuf/timestamp_pb.js +267 -0
  67. package/dist/esm/google/protobuf/type_pb.js +569 -0
  68. package/dist/esm/google/protobuf/wrappers_pb.js +574 -0
  69. package/dist/esm/google/varint.js +265 -0
  70. package/dist/esm/index.js +24 -0
  71. package/dist/esm/json-format.js +1 -0
  72. package/dist/esm/message-type.js +1 -0
  73. package/dist/esm/message.js +94 -0
  74. package/dist/esm/private/assert.js +41 -0
  75. package/dist/esm/private/base64.js +113 -0
  76. package/dist/esm/private/binary-format-common.js +243 -0
  77. package/dist/esm/private/binary-format-proto2.js +87 -0
  78. package/dist/esm/private/binary-format-proto3.js +74 -0
  79. package/dist/esm/private/enum.js +64 -0
  80. package/dist/esm/private/field-list.js +58 -0
  81. package/dist/esm/private/field-wrapper.js +20 -0
  82. package/dist/esm/private/field.js +27 -0
  83. package/dist/esm/private/json-format-common.js +473 -0
  84. package/dist/esm/private/json-format-proto2.js +90 -0
  85. package/dist/esm/private/json-format-proto3.js +89 -0
  86. package/dist/esm/private/message-type.js +33 -0
  87. package/dist/esm/private/names.js +90 -0
  88. package/dist/esm/private/options-map.js +1 -0
  89. package/dist/esm/private/proto-runtime.js +15 -0
  90. package/dist/esm/private/scalars.js +129 -0
  91. package/dist/esm/private/util-common.js +207 -0
  92. package/dist/esm/private/util.js +1 -0
  93. package/dist/esm/proto-int64.js +118 -0
  94. package/dist/esm/proto2.js +77 -0
  95. package/dist/esm/proto3.js +90 -0
  96. package/dist/esm/service-type.js +37 -0
  97. package/dist/esm/type-registry.js +38 -0
  98. package/dist/types/binary-encoding.d.ts +421 -0
  99. package/dist/types/binary-format.d.ts +109 -0
  100. package/dist/types/descriptor-registry.d.ts +42 -0
  101. package/dist/types/descriptor-set.d.ts +171 -0
  102. package/dist/types/enum.d.ts +31 -0
  103. package/dist/types/field-list.d.ts +27 -0
  104. package/dist/types/field.d.ts +295 -0
  105. package/dist/types/google/protobuf/any_pb.d.ts +167 -0
  106. package/dist/types/google/protobuf/api_pb.d.ts +296 -0
  107. package/dist/types/google/protobuf/compiler/plugin_pb.d.ts +294 -0
  108. package/dist/types/google/protobuf/descriptor_pb.d.ts +1959 -0
  109. package/dist/types/google/protobuf/duration_pb.d.ts +117 -0
  110. package/dist/types/google/protobuf/empty_pb.d.ts +44 -0
  111. package/dist/types/google/protobuf/field_mask_pb.d.ts +243 -0
  112. package/dist/types/google/protobuf/source_context_pb.d.ts +44 -0
  113. package/dist/types/google/protobuf/struct_pb.d.ts +205 -0
  114. package/dist/types/google/protobuf/timestamp_pb.d.ts +151 -0
  115. package/dist/types/google/protobuf/type_pb.d.ts +482 -0
  116. package/dist/types/google/protobuf/wrappers_pb.d.ts +379 -0
  117. package/dist/types/google/varint.d.ts +65 -0
  118. package/dist/types/index.d.ts +53 -0
  119. package/dist/types/json-format.d.ts +129 -0
  120. package/dist/types/message-type.d.ts +58 -0
  121. package/dist/types/message.d.ts +124 -0
  122. package/dist/types/private/assert.d.ts +19 -0
  123. package/dist/types/private/base64.d.ts +18 -0
  124. package/dist/types/private/binary-format-common.d.ts +38 -0
  125. package/dist/types/private/binary-format-proto2.d.ts +2 -0
  126. package/dist/types/private/binary-format-proto3.d.ts +2 -0
  127. package/dist/types/private/enum.d.ts +29 -0
  128. package/dist/types/private/field-list.d.ts +25 -0
  129. package/dist/types/private/field-wrapper.d.ts +27 -0
  130. package/dist/types/private/field.d.ts +15 -0
  131. package/dist/types/private/json-format-common.d.ts +30 -0
  132. package/dist/types/private/json-format-proto2.d.ts +2 -0
  133. package/dist/types/private/json-format-proto3.d.ts +2 -0
  134. package/dist/types/private/message-type.d.ts +15 -0
  135. package/dist/types/private/names.d.ts +19 -0
  136. package/dist/types/private/options-map.d.ts +7 -0
  137. package/dist/types/private/proto-runtime.d.ts +55 -0
  138. package/dist/types/private/scalars.d.ts +33 -0
  139. package/dist/types/private/util-common.d.ts +5 -0
  140. package/dist/types/private/util.d.ts +55 -0
  141. package/dist/types/proto-int64.d.ts +94 -0
  142. package/dist/types/proto2.d.ts +4 -0
  143. package/dist/types/proto3.d.ts +4 -0
  144. package/dist/types/service-type.d.ts +118 -0
  145. package/dist/types/type-registry.d.ts +37 -0
  146. package/package.json +31 -0
@@ -0,0 +1,288 @@
1
+ "use strict";
2
+ /* eslint-disable */
3
+ // @generated by protoc-gen-es v0.0.1-alpha.1 with parameter "bootstrap_wkt=true,ts_nocheck=false"
4
+ // @generated from file google/protobuf/struct.proto (package google.protobuf, syntax proto3)
5
+ //
6
+ // Protocol Buffers - Google's data interchange format
7
+ // Copyright 2008 Google Inc. All rights reserved.
8
+ // https://developers.google.com/protocol-buffers/
9
+ //
10
+ // Redistribution and use in source and binary forms, with or without
11
+ // modification, are permitted provided that the following conditions are
12
+ // met:
13
+ //
14
+ // * Redistributions of source code must retain the above copyright
15
+ // notice, this list of conditions and the following disclaimer.
16
+ // * Redistributions in binary form must reproduce the above
17
+ // copyright notice, this list of conditions and the following disclaimer
18
+ // in the documentation and/or other materials provided with the
19
+ // distribution.
20
+ // * Neither the name of Google Inc. nor the names of its
21
+ // contributors may be used to endorse or promote products derived from
22
+ // this software without specific prior written permission.
23
+ //
24
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.ListValue = exports.Value = exports.Struct = exports.NullValue = void 0;
37
+ const index_js_1 = require("../../index.js");
38
+ /**
39
+ * `NullValue` is a singleton enumeration to represent the null value for the
40
+ * `Value` type union.
41
+ *
42
+ * The JSON representation for `NullValue` is JSON `null`.
43
+ *
44
+ * @generated from enum google.protobuf.NullValue
45
+ */
46
+ var NullValue;
47
+ (function (NullValue) {
48
+ /**
49
+ * Null value.
50
+ *
51
+ * @generated from enum value: NULL_VALUE = 0;
52
+ */
53
+ NullValue[(NullValue["NULL_VALUE"] = 0)] = "NULL_VALUE";
54
+ })((NullValue = exports.NullValue || (exports.NullValue = {})));
55
+ // Retrieve enum metadata with: proto3.getEnumType(NullValue)
56
+ index_js_1.proto3.util.setEnumType(NullValue, "google.protobuf.NullValue", [
57
+ { no: 0, name: "NULL_VALUE" },
58
+ ]);
59
+ /**
60
+ * `Struct` represents a structured data value, consisting of fields
61
+ * which map to dynamically typed values. In some languages, `Struct`
62
+ * might be supported by a native representation. For example, in
63
+ * scripting languages like JS a struct is represented as an
64
+ * object. The details of that representation are described together
65
+ * with the proto support for the language.
66
+ *
67
+ * The JSON representation for `Struct` is JSON object.
68
+ *
69
+ * @generated from message google.protobuf.Struct
70
+ */
71
+ class Struct extends index_js_1.Message {
72
+ constructor(data) {
73
+ super();
74
+ /**
75
+ * Unordered map of dynamically typed values.
76
+ *
77
+ * @generated from field: map<string, google.protobuf.Value> fields = 1;
78
+ */
79
+ this.fields = {};
80
+ index_js_1.proto3.util.initPartial(data, this);
81
+ }
82
+ toJson(options) {
83
+ const json = {};
84
+ for (const [k, v] of Object.entries(this.fields)) {
85
+ json[k] = v.toJson(options);
86
+ }
87
+ return json;
88
+ }
89
+ fromJson(json, options) {
90
+ if (typeof json != "object" || json == null || Array.isArray(json)) {
91
+ throw new Error(
92
+ "cannot decode google.protobuf.Struct from JSON " +
93
+ index_js_1.proto3.json.debug(json)
94
+ );
95
+ }
96
+ for (const [k, v] of Object.entries(json)) {
97
+ this.fields[k] = Value.fromJson(v);
98
+ }
99
+ return this;
100
+ }
101
+ static fromBinary(bytes, options) {
102
+ return new Struct().fromBinary(bytes, options);
103
+ }
104
+ static fromJson(jsonValue, options) {
105
+ return new Struct().fromJson(jsonValue, options);
106
+ }
107
+ static fromJsonString(jsonString, options) {
108
+ return new Struct().fromJsonString(jsonString, options);
109
+ }
110
+ static equals(a, b) {
111
+ return index_js_1.proto3.util.equals(Struct, a, b);
112
+ }
113
+ }
114
+ exports.Struct = Struct;
115
+ Struct.runtime = index_js_1.proto3;
116
+ Struct.typeName = "google.protobuf.Struct";
117
+ Struct.fields = index_js_1.proto3.util.newFieldList(() => [
118
+ {
119
+ no: 1,
120
+ name: "fields",
121
+ kind: "map",
122
+ K: 9 /* ScalarType.STRING */,
123
+ V: { kind: "message", T: Value },
124
+ },
125
+ ]);
126
+ /**
127
+ * `Value` represents a dynamically typed value which can be either
128
+ * null, a number, a string, a boolean, a recursive struct value, or a
129
+ * list of values. A producer of value is expected to set one of these
130
+ * variants. Absence of any variant indicates an error.
131
+ *
132
+ * The JSON representation for `Value` is JSON value.
133
+ *
134
+ * @generated from message google.protobuf.Value
135
+ */
136
+ class Value extends index_js_1.Message {
137
+ constructor(data) {
138
+ super();
139
+ /**
140
+ * The kind of value.
141
+ *
142
+ * @generated from oneof google.protobuf.Value.kind
143
+ */
144
+ this.kind = { case: undefined };
145
+ index_js_1.proto3.util.initPartial(data, this);
146
+ }
147
+ toJson(options) {
148
+ switch (this.kind.case) {
149
+ case "nullValue":
150
+ return null;
151
+ case "boolValue":
152
+ case "numberValue":
153
+ case "stringValue":
154
+ return this.kind.value;
155
+ case "structValue":
156
+ case "listValue":
157
+ return this.kind.value.toJson({ ...options, emitDefaultValues: true });
158
+ }
159
+ throw new Error("google.protobuf.Value must have a value");
160
+ }
161
+ fromJson(json, options) {
162
+ switch (typeof json) {
163
+ case "number":
164
+ this.kind = { case: "numberValue", value: json };
165
+ break;
166
+ case "string":
167
+ this.kind = { case: "stringValue", value: json };
168
+ break;
169
+ case "boolean":
170
+ this.kind = { case: "boolValue", value: json };
171
+ break;
172
+ case "object":
173
+ if (json === null) {
174
+ this.kind = { case: "nullValue", value: NullValue.NULL_VALUE };
175
+ } else if (Array.isArray(json)) {
176
+ this.kind = { case: "listValue", value: ListValue.fromJson(json) };
177
+ } else {
178
+ this.kind = { case: "structValue", value: Struct.fromJson(json) };
179
+ }
180
+ break;
181
+ default:
182
+ throw new Error(
183
+ "cannot decode google.protobuf.Value from JSON " +
184
+ index_js_1.proto3.json.debug(json)
185
+ );
186
+ }
187
+ return this;
188
+ }
189
+ static fromBinary(bytes, options) {
190
+ return new Value().fromBinary(bytes, options);
191
+ }
192
+ static fromJson(jsonValue, options) {
193
+ return new Value().fromJson(jsonValue, options);
194
+ }
195
+ static fromJsonString(jsonString, options) {
196
+ return new Value().fromJsonString(jsonString, options);
197
+ }
198
+ static equals(a, b) {
199
+ return index_js_1.proto3.util.equals(Value, a, b);
200
+ }
201
+ }
202
+ exports.Value = Value;
203
+ Value.runtime = index_js_1.proto3;
204
+ Value.typeName = "google.protobuf.Value";
205
+ Value.fields = index_js_1.proto3.util.newFieldList(() => [
206
+ {
207
+ no: 1,
208
+ name: "null_value",
209
+ kind: "enum",
210
+ T: index_js_1.proto3.getEnumType(NullValue),
211
+ oneof: "kind",
212
+ },
213
+ {
214
+ no: 2,
215
+ name: "number_value",
216
+ kind: "scalar",
217
+ T: 1 /* ScalarType.DOUBLE */,
218
+ oneof: "kind",
219
+ },
220
+ {
221
+ no: 3,
222
+ name: "string_value",
223
+ kind: "scalar",
224
+ T: 9 /* ScalarType.STRING */,
225
+ oneof: "kind",
226
+ },
227
+ {
228
+ no: 4,
229
+ name: "bool_value",
230
+ kind: "scalar",
231
+ T: 8 /* ScalarType.BOOL */,
232
+ oneof: "kind",
233
+ },
234
+ { no: 5, name: "struct_value", kind: "message", T: Struct, oneof: "kind" },
235
+ { no: 6, name: "list_value", kind: "message", T: ListValue, oneof: "kind" },
236
+ ]);
237
+ /**
238
+ * `ListValue` is a wrapper around a repeated field of values.
239
+ *
240
+ * The JSON representation for `ListValue` is JSON array.
241
+ *
242
+ * @generated from message google.protobuf.ListValue
243
+ */
244
+ class ListValue extends index_js_1.Message {
245
+ constructor(data) {
246
+ super();
247
+ /**
248
+ * Repeated field of dynamically typed values.
249
+ *
250
+ * @generated from field: repeated google.protobuf.Value values = 1;
251
+ */
252
+ this.values = [];
253
+ index_js_1.proto3.util.initPartial(data, this);
254
+ }
255
+ toJson(options) {
256
+ return this.values.map((v) => v.toJson());
257
+ }
258
+ fromJson(json, options) {
259
+ if (!Array.isArray(json)) {
260
+ throw new Error(
261
+ "cannot decode google.protobuf.ListValue from JSON " +
262
+ index_js_1.proto3.json.debug(json)
263
+ );
264
+ }
265
+ for (let e of json) {
266
+ this.values.push(Value.fromJson(e));
267
+ }
268
+ return this;
269
+ }
270
+ static fromBinary(bytes, options) {
271
+ return new ListValue().fromBinary(bytes, options);
272
+ }
273
+ static fromJson(jsonValue, options) {
274
+ return new ListValue().fromJson(jsonValue, options);
275
+ }
276
+ static fromJsonString(jsonString, options) {
277
+ return new ListValue().fromJsonString(jsonString, options);
278
+ }
279
+ static equals(a, b) {
280
+ return index_js_1.proto3.util.equals(ListValue, a, b);
281
+ }
282
+ }
283
+ exports.ListValue = ListValue;
284
+ ListValue.runtime = index_js_1.proto3;
285
+ ListValue.typeName = "google.protobuf.ListValue";
286
+ ListValue.fields = index_js_1.proto3.util.newFieldList(() => [
287
+ { no: 1, name: "values", kind: "message", T: Value, repeated: true },
288
+ ]);
@@ -0,0 +1,271 @@
1
+ "use strict";
2
+ /* eslint-disable */
3
+ // @generated by protoc-gen-es v0.0.1-alpha.1 with parameter "bootstrap_wkt=true,ts_nocheck=false"
4
+ // @generated from file google/protobuf/timestamp.proto (package google.protobuf, syntax proto3)
5
+ //
6
+ // Protocol Buffers - Google's data interchange format
7
+ // Copyright 2008 Google Inc. All rights reserved.
8
+ // https://developers.google.com/protocol-buffers/
9
+ //
10
+ // Redistribution and use in source and binary forms, with or without
11
+ // modification, are permitted provided that the following conditions are
12
+ // met:
13
+ //
14
+ // * Redistributions of source code must retain the above copyright
15
+ // notice, this list of conditions and the following disclaimer.
16
+ // * Redistributions in binary form must reproduce the above
17
+ // copyright notice, this list of conditions and the following disclaimer
18
+ // in the documentation and/or other materials provided with the
19
+ // distribution.
20
+ // * Neither the name of Google Inc. nor the names of its
21
+ // contributors may be used to endorse or promote products derived from
22
+ // this software without specific prior written permission.
23
+ //
24
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.Timestamp = void 0;
37
+ const index_js_1 = require("../../index.js");
38
+ /**
39
+ * A Timestamp represents a point in time independent of any time zone or local
40
+ * calendar, encoded as a count of seconds and fractions of seconds at
41
+ * nanosecond resolution. The count is relative to an epoch at UTC midnight on
42
+ * January 1, 1970, in the proleptic Gregorian calendar which extends the
43
+ * Gregorian calendar backwards to year one.
44
+ *
45
+ * All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap
46
+ * second table is needed for interpretation, using a [24-hour linear
47
+ * smear](https://developers.google.com/time/smear).
48
+ *
49
+ * The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By
50
+ * restricting to that range, we ensure that we can convert to and from [RFC
51
+ * 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings.
52
+ *
53
+ * # Examples
54
+ *
55
+ * Example 1: Compute Timestamp from POSIX `time()`.
56
+ *
57
+ * Timestamp timestamp;
58
+ * timestamp.set_seconds(time(NULL));
59
+ * timestamp.set_nanos(0);
60
+ *
61
+ * Example 2: Compute Timestamp from POSIX `gettimeofday()`.
62
+ *
63
+ * struct timeval tv;
64
+ * gettimeofday(&tv, NULL);
65
+ *
66
+ * Timestamp timestamp;
67
+ * timestamp.set_seconds(tv.tv_sec);
68
+ * timestamp.set_nanos(tv.tv_usec * 1000);
69
+ *
70
+ * Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`.
71
+ *
72
+ * FILETIME ft;
73
+ * GetSystemTimeAsFileTime(&ft);
74
+ * UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
75
+ *
76
+ * // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z
77
+ * // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z.
78
+ * Timestamp timestamp;
79
+ * timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL));
80
+ * timestamp.set_nanos((INT32) ((ticks % 10000000) * 100));
81
+ *
82
+ * Example 4: Compute Timestamp from Java `System.currentTimeMillis()`.
83
+ *
84
+ * long millis = System.currentTimeMillis();
85
+ *
86
+ * Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000)
87
+ * .setNanos((int) ((millis % 1000) * 1000000)).build();
88
+ *
89
+ *
90
+ * Example 5: Compute Timestamp from Java `Instant.now()`.
91
+ *
92
+ * Instant now = Instant.now();
93
+ *
94
+ * Timestamp timestamp =
95
+ * Timestamp.newBuilder().setSeconds(now.getEpochSecond())
96
+ * .setNanos(now.getNano()).build();
97
+ *
98
+ *
99
+ * Example 6: Compute Timestamp from current time in Python.
100
+ *
101
+ * timestamp = Timestamp()
102
+ * timestamp.GetCurrentTime()
103
+ *
104
+ * # JSON Mapping
105
+ *
106
+ * In JSON format, the Timestamp type is encoded as a string in the
107
+ * [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the
108
+ * format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z"
109
+ * where {year} is always expressed using four digits while {month}, {day},
110
+ * {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional
111
+ * seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution),
112
+ * are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone
113
+ * is required. A proto3 JSON serializer should always use UTC (as indicated by
114
+ * "Z") when printing the Timestamp type and a proto3 JSON parser should be
115
+ * able to accept both UTC and other timezones (as indicated by an offset).
116
+ *
117
+ * For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past
118
+ * 01:30 UTC on January 15, 2017.
119
+ *
120
+ * In JavaScript, one can convert a Date object to this format using the
121
+ * standard
122
+ * [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
123
+ * method. In Python, a standard `datetime.datetime` object can be converted
124
+ * to this format using
125
+ * [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with
126
+ * the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use
127
+ * the Joda Time's [`ISODateTimeFormat.dateTime()`](
128
+ * http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D
129
+ * ) to obtain a formatter capable of generating timestamps in this format.
130
+ *
131
+ *
132
+ *
133
+ * @generated from message google.protobuf.Timestamp
134
+ */
135
+ class Timestamp extends index_js_1.Message {
136
+ constructor(data) {
137
+ super();
138
+ /**
139
+ * Represents seconds of UTC time since Unix epoch
140
+ * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
141
+ * 9999-12-31T23:59:59Z inclusive.
142
+ *
143
+ * @generated from field: int64 seconds = 1;
144
+ */
145
+ this.seconds = index_js_1.protoInt64.zero;
146
+ /**
147
+ * Non-negative fractions of a second at nanosecond resolution. Negative
148
+ * second values with fractions must still have non-negative nanos values
149
+ * that count forward in time. Must be from 0 to 999,999,999
150
+ * inclusive.
151
+ *
152
+ * @generated from field: int32 nanos = 2;
153
+ */
154
+ this.nanos = 0;
155
+ index_js_1.proto3.util.initPartial(data, this);
156
+ }
157
+ fromJson(json, options) {
158
+ if (typeof json !== "string") {
159
+ throw new Error(
160
+ `cannot decode google.protobuf.Timestamp from JSON: ${index_js_1.proto3.json.debug(
161
+ json
162
+ )}`
163
+ );
164
+ }
165
+ const matches = json.match(
166
+ /^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(?:Z|\.([0-9]{3,9})Z|([+-][0-9][0-9]:[0-9][0-9]))$/
167
+ );
168
+ if (!matches) {
169
+ throw new Error(
170
+ `cannot decode google.protobuf.Timestamp from JSON: invalid RFC 3339 string`
171
+ );
172
+ }
173
+ const ms = Date.parse(
174
+ matches[1] +
175
+ "-" +
176
+ matches[2] +
177
+ "-" +
178
+ matches[3] +
179
+ "T" +
180
+ matches[4] +
181
+ ":" +
182
+ matches[5] +
183
+ ":" +
184
+ matches[6] +
185
+ (matches[8] ? matches[8] : "Z")
186
+ );
187
+ if (Number.isNaN(ms)) {
188
+ throw new Error(
189
+ `cannot decode google.protobuf.Timestamp from JSON: invalid RFC 3339 string`
190
+ );
191
+ }
192
+ if (
193
+ ms < Date.parse("0001-01-01T00:00:00Z") ||
194
+ ms > Date.parse("9999-12-31T23:59:59Z")
195
+ ) {
196
+ throw new Error(
197
+ `cannot decode message google.protobuf.Timestamp from JSON: must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive`
198
+ );
199
+ }
200
+ this.seconds = index_js_1.protoInt64.parse(ms / 1000);
201
+ this.nanos = 0;
202
+ if (matches[7]) {
203
+ this.nanos =
204
+ parseInt("1" + matches[7] + "0".repeat(9 - matches[7].length)) -
205
+ 1000000000;
206
+ }
207
+ return this;
208
+ }
209
+ toJson(options) {
210
+ const ms = Number(this.seconds) * 1000;
211
+ if (
212
+ ms < Date.parse("0001-01-01T00:00:00Z") ||
213
+ ms > Date.parse("9999-12-31T23:59:59Z")
214
+ ) {
215
+ throw new Error(
216
+ `cannot encode google.protobuf.Timestamp to JSON: must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive`
217
+ );
218
+ }
219
+ if (this.nanos < 0) {
220
+ throw new Error(
221
+ `cannot encode google.protobuf.Timestamp to JSON: nanos must not be negative`
222
+ );
223
+ }
224
+ let z = "Z";
225
+ if (this.nanos > 0) {
226
+ const nanosStr = (this.nanos + 1000000000).toString().substring(1);
227
+ if (nanosStr.substring(3) === "000000") {
228
+ z = "." + nanosStr.substring(0, 3) + "Z";
229
+ } else if (nanosStr.substring(6) === "000") {
230
+ z = "." + nanosStr.substring(0, 6) + "Z";
231
+ } else {
232
+ z = "." + nanosStr + "Z";
233
+ }
234
+ }
235
+ return new Date(ms).toISOString().replace(".000Z", z);
236
+ }
237
+ toDate() {
238
+ return new Date(
239
+ Number(this.seconds) * 1000 + Math.ceil(this.nanos / 1000000)
240
+ );
241
+ }
242
+ static now() {
243
+ return Timestamp.fromDate(new Date());
244
+ }
245
+ static fromDate(date) {
246
+ const ms = date.getTime();
247
+ return new Timestamp({
248
+ seconds: index_js_1.protoInt64.parse(Math.floor(ms / 1000)),
249
+ nanos: (ms % 1000) * 1000000,
250
+ });
251
+ }
252
+ static fromBinary(bytes, options) {
253
+ return new Timestamp().fromBinary(bytes, options);
254
+ }
255
+ static fromJson(jsonValue, options) {
256
+ return new Timestamp().fromJson(jsonValue, options);
257
+ }
258
+ static fromJsonString(jsonString, options) {
259
+ return new Timestamp().fromJsonString(jsonString, options);
260
+ }
261
+ static equals(a, b) {
262
+ return index_js_1.proto3.util.equals(Timestamp, a, b);
263
+ }
264
+ }
265
+ exports.Timestamp = Timestamp;
266
+ Timestamp.runtime = index_js_1.proto3;
267
+ Timestamp.typeName = "google.protobuf.Timestamp";
268
+ Timestamp.fields = index_js_1.proto3.util.newFieldList(() => [
269
+ { no: 1, name: "seconds", kind: "scalar", T: 3 /* ScalarType.INT64 */ },
270
+ { no: 2, name: "nanos", kind: "scalar", T: 5 /* ScalarType.INT32 */ },
271
+ ]);