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