@streamr/trackerless-network 0.0.1-tatum.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 (262) hide show
  1. package/.eslintignore +7 -0
  2. package/.eslintrc +3 -0
  3. package/README.md +6 -0
  4. package/bin/bootstrap-node.ts +73 -0
  5. package/bin/full-node-webrtc.ts +102 -0
  6. package/bin/full-node-websocket.ts +102 -0
  7. package/bin/network.ts +43 -0
  8. package/dist/package.json +53 -0
  9. package/dist/src/NameDirectory.d.ts +5 -0
  10. package/dist/src/NameDirectory.js +44 -0
  11. package/dist/src/NameDirectory.js.map +1 -0
  12. package/dist/src/NetworkNode.d.ts +35 -0
  13. package/dist/src/NetworkNode.js +130 -0
  14. package/dist/src/NetworkNode.js.map +1 -0
  15. package/dist/src/NetworkStack.d.ts +32 -0
  16. package/dist/src/NetworkStack.js +108 -0
  17. package/dist/src/NetworkStack.js.map +1 -0
  18. package/dist/src/exports.d.ts +6 -0
  19. package/dist/src/exports.js +12 -0
  20. package/dist/src/exports.js.map +1 -0
  21. package/dist/src/identifiers.d.ts +1 -0
  22. package/dist/src/identifiers.js +3 -0
  23. package/dist/src/identifiers.js.map +1 -0
  24. package/dist/src/logic/DuplicateMessageDetector.d.ts +55 -0
  25. package/dist/src/logic/DuplicateMessageDetector.js +155 -0
  26. package/dist/src/logic/DuplicateMessageDetector.js.map +1 -0
  27. package/dist/src/logic/ILayer0.d.ts +13 -0
  28. package/dist/src/logic/ILayer0.js +3 -0
  29. package/dist/src/logic/ILayer0.js.map +1 -0
  30. package/dist/src/logic/IStreamNode.d.ts +12 -0
  31. package/dist/src/logic/IStreamNode.js +3 -0
  32. package/dist/src/logic/IStreamNode.js.map +1 -0
  33. package/dist/src/logic/PeerList.d.ts +27 -0
  34. package/dist/src/logic/PeerList.js +84 -0
  35. package/dist/src/logic/PeerList.js.map +1 -0
  36. package/dist/src/logic/RandomGraphNode.d.ts +68 -0
  37. package/dist/src/logic/RandomGraphNode.js +201 -0
  38. package/dist/src/logic/RandomGraphNode.js.map +1 -0
  39. package/dist/src/logic/Remote.d.ts +9 -0
  40. package/dist/src/logic/Remote.js +15 -0
  41. package/dist/src/logic/Remote.js.map +1 -0
  42. package/dist/src/logic/RemoteRandomGraphNode.d.ts +8 -0
  43. package/dist/src/logic/RemoteRandomGraphNode.js +35 -0
  44. package/dist/src/logic/RemoteRandomGraphNode.js.map +1 -0
  45. package/dist/src/logic/StreamEntryPointDiscovery.d.ts +36 -0
  46. package/dist/src/logic/StreamEntryPointDiscovery.js +179 -0
  47. package/dist/src/logic/StreamEntryPointDiscovery.js.map +1 -0
  48. package/dist/src/logic/StreamNodeServer.d.ts +20 -0
  49. package/dist/src/logic/StreamNodeServer.js +26 -0
  50. package/dist/src/logic/StreamNodeServer.js.map +1 -0
  51. package/dist/src/logic/StreamrNode.d.ts +76 -0
  52. package/dist/src/logic/StreamrNode.js +303 -0
  53. package/dist/src/logic/StreamrNode.js.map +1 -0
  54. package/dist/src/logic/createRandomGraphNode.d.ts +5 -0
  55. package/dist/src/logic/createRandomGraphNode.js +110 -0
  56. package/dist/src/logic/createRandomGraphNode.js.map +1 -0
  57. package/dist/src/logic/inspect/InspectSession.d.ts +18 -0
  58. package/dist/src/logic/inspect/InspectSession.js +38 -0
  59. package/dist/src/logic/inspect/InspectSession.js.map +1 -0
  60. package/dist/src/logic/inspect/Inspector.d.ts +33 -0
  61. package/dist/src/logic/inspect/Inspector.js +63 -0
  62. package/dist/src/logic/inspect/Inspector.js.map +1 -0
  63. package/dist/src/logic/neighbor-discovery/Handshaker.d.ts +35 -0
  64. package/dist/src/logic/neighbor-discovery/Handshaker.js +121 -0
  65. package/dist/src/logic/neighbor-discovery/Handshaker.js.map +1 -0
  66. package/dist/src/logic/neighbor-discovery/HandshakerServer.d.ts +30 -0
  67. package/dist/src/logic/neighbor-discovery/HandshakerServer.js +78 -0
  68. package/dist/src/logic/neighbor-discovery/HandshakerServer.js.map +1 -0
  69. package/dist/src/logic/neighbor-discovery/NeighborFinder.d.ts +23 -0
  70. package/dist/src/logic/neighbor-discovery/NeighborFinder.js +44 -0
  71. package/dist/src/logic/neighbor-discovery/NeighborFinder.js.map +1 -0
  72. package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.d.ts +30 -0
  73. package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.js +42 -0
  74. package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.js.map +1 -0
  75. package/dist/src/logic/neighbor-discovery/NeighborUpdateManagerServer.d.ts +20 -0
  76. package/dist/src/logic/neighbor-discovery/NeighborUpdateManagerServer.js +42 -0
  77. package/dist/src/logic/neighbor-discovery/NeighborUpdateManagerServer.js.map +1 -0
  78. package/dist/src/logic/neighbor-discovery/RemoteHandshaker.d.ts +12 -0
  79. package/dist/src/logic/neighbor-discovery/RemoteHandshaker.js +54 -0
  80. package/dist/src/logic/neighbor-discovery/RemoteHandshaker.js.map +1 -0
  81. package/dist/src/logic/neighbor-discovery/RemoteNeighborUpdateManager.d.ts +11 -0
  82. package/dist/src/logic/neighbor-discovery/RemoteNeighborUpdateManager.js +37 -0
  83. package/dist/src/logic/neighbor-discovery/RemoteNeighborUpdateManager.js.map +1 -0
  84. package/dist/src/logic/propagation/FifoMapWithTTL.d.ts +36 -0
  85. package/dist/src/logic/propagation/FifoMapWithTTL.js +81 -0
  86. package/dist/src/logic/propagation/FifoMapWithTTL.js.map +1 -0
  87. package/dist/src/logic/propagation/Propagation.d.ts +31 -0
  88. package/dist/src/logic/propagation/Propagation.js +64 -0
  89. package/dist/src/logic/propagation/Propagation.js.map +1 -0
  90. package/dist/src/logic/propagation/PropagationTaskStore.d.ts +21 -0
  91. package/dist/src/logic/propagation/PropagationTaskStore.js +32 -0
  92. package/dist/src/logic/propagation/PropagationTaskStore.js.map +1 -0
  93. package/dist/src/logic/protocol-integration/stream-message/ContentMessageTranslator.d.ts +5 -0
  94. package/dist/src/logic/protocol-integration/stream-message/ContentMessageTranslator.js +17 -0
  95. package/dist/src/logic/protocol-integration/stream-message/ContentMessageTranslator.js.map +1 -0
  96. package/dist/src/logic/protocol-integration/stream-message/GroupKeyRequestTranslator.d.ts +6 -0
  97. package/dist/src/logic/protocol-integration/stream-message/GroupKeyRequestTranslator.js +27 -0
  98. package/dist/src/logic/protocol-integration/stream-message/GroupKeyRequestTranslator.js.map +1 -0
  99. package/dist/src/logic/protocol-integration/stream-message/GroupKeyResponseTranslator.d.ts +6 -0
  100. package/dist/src/logic/protocol-integration/stream-message/GroupKeyResponseTranslator.js +33 -0
  101. package/dist/src/logic/protocol-integration/stream-message/GroupKeyResponseTranslator.js.map +1 -0
  102. package/dist/src/logic/protocol-integration/stream-message/StreamMessageTranslator.d.ts +6 -0
  103. package/dist/src/logic/protocol-integration/stream-message/StreamMessageTranslator.js +109 -0
  104. package/dist/src/logic/protocol-integration/stream-message/StreamMessageTranslator.js.map +1 -0
  105. package/dist/src/logic/proxy/ProxyStreamConnectionClient.d.ts +44 -0
  106. package/dist/src/logic/proxy/ProxyStreamConnectionClient.js +189 -0
  107. package/dist/src/logic/proxy/ProxyStreamConnectionClient.js.map +1 -0
  108. package/dist/src/logic/proxy/ProxyStreamConnectionServer.d.ts +34 -0
  109. package/dist/src/logic/proxy/ProxyStreamConnectionServer.js +64 -0
  110. package/dist/src/logic/proxy/ProxyStreamConnectionServer.js.map +1 -0
  111. package/dist/src/logic/proxy/RemoteProxyServer.d.ts +7 -0
  112. package/dist/src/logic/proxy/RemoteProxyServer.js +36 -0
  113. package/dist/src/logic/proxy/RemoteProxyServer.js.map +1 -0
  114. package/dist/src/logic/temporary-connection/RemoteTemporaryConnectionRpcServer.d.ts +6 -0
  115. package/dist/src/logic/temporary-connection/RemoteTemporaryConnectionRpcServer.js +28 -0
  116. package/dist/src/logic/temporary-connection/RemoteTemporaryConnectionRpcServer.js.map +1 -0
  117. package/dist/src/logic/temporary-connection/TemporaryConnectionRpcServer.d.ts +20 -0
  118. package/dist/src/logic/temporary-connection/TemporaryConnectionRpcServer.js +29 -0
  119. package/dist/src/logic/temporary-connection/TemporaryConnectionRpcServer.js.map +1 -0
  120. package/dist/src/logic/utils.d.ts +3 -0
  121. package/dist/src/logic/utils.js +16 -0
  122. package/dist/src/logic/utils.js.map +1 -0
  123. package/dist/src/proto/google/protobuf/any.d.ts +173 -0
  124. package/dist/src/proto/google/protobuf/any.js +155 -0
  125. package/dist/src/proto/google/protobuf/any.js.map +1 -0
  126. package/dist/src/proto/google/protobuf/empty.d.ts +32 -0
  127. package/dist/src/proto/google/protobuf/empty.js +34 -0
  128. package/dist/src/proto/google/protobuf/empty.js.map +1 -0
  129. package/dist/src/proto/google/protobuf/timestamp.d.ts +149 -0
  130. package/dist/src/proto/google/protobuf/timestamp.js +136 -0
  131. package/dist/src/proto/google/protobuf/timestamp.js.map +1 -0
  132. package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +320 -0
  133. package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +245 -0
  134. package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -0
  135. package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +1089 -0
  136. package/dist/src/proto/packages/dht/protos/DhtRpc.js +710 -0
  137. package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -0
  138. package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +145 -0
  139. package/dist/src/proto/packages/dht/protos/DhtRpc.server.js +3 -0
  140. package/dist/src/proto/packages/dht/protos/DhtRpc.server.js.map +1 -0
  141. package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.d.ts +87 -0
  142. package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js +66 -0
  143. package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js.map +1 -0
  144. package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.client.d.ts +156 -0
  145. package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.client.js +122 -0
  146. package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.client.js.map +1 -0
  147. package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.d.ts +524 -0
  148. package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.js +350 -0
  149. package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.js.map +1 -0
  150. package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.server.d.ts +65 -0
  151. package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.server.js +3 -0
  152. package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.server.js.map +1 -0
  153. package/dist/test/benchmark/first-message.d.ts +1 -0
  154. package/dist/test/benchmark/first-message.js +137 -0
  155. package/dist/test/benchmark/first-message.js.map +1 -0
  156. package/dist/test/utils/utils.d.ts +12 -0
  157. package/dist/test/utils/utils.js +86 -0
  158. package/dist/test/utils/utils.js.map +1 -0
  159. package/jest.config.js +36 -0
  160. package/karma.config.js +20 -0
  161. package/log.txt +501 -0
  162. package/package.json +53 -0
  163. package/proto.sh +2 -0
  164. package/protos/NetworkRpc.proto +161 -0
  165. package/src/NameDirectory.ts +44 -0
  166. package/src/NetworkNode.ts +169 -0
  167. package/src/NetworkStack.ts +144 -0
  168. package/src/exports.ts +6 -0
  169. package/src/identifiers.ts +1 -0
  170. package/src/logic/DuplicateMessageDetector.ts +167 -0
  171. package/src/logic/ILayer0.ts +14 -0
  172. package/src/logic/IStreamNode.ts +17 -0
  173. package/src/logic/PeerList.ts +106 -0
  174. package/src/logic/RandomGraphNode.ts +310 -0
  175. package/src/logic/Remote.ts +19 -0
  176. package/src/logic/RemoteRandomGraphNode.ts +39 -0
  177. package/src/logic/StreamEntryPointDiscovery.ts +221 -0
  178. package/src/logic/StreamNodeServer.ts +44 -0
  179. package/src/logic/StreamrNode.ts +416 -0
  180. package/src/logic/createRandomGraphNode.ts +114 -0
  181. package/src/logic/inspect/InspectSession.ts +49 -0
  182. package/src/logic/inspect/Inspector.ts +89 -0
  183. package/src/logic/neighbor-discovery/Handshaker.ts +180 -0
  184. package/src/logic/neighbor-discovery/HandshakerServer.ts +99 -0
  185. package/src/logic/neighbor-discovery/NeighborFinder.ts +61 -0
  186. package/src/logic/neighbor-discovery/NeighborUpdateManager.ts +67 -0
  187. package/src/logic/neighbor-discovery/NeighborUpdateManagerServer.ts +61 -0
  188. package/src/logic/neighbor-discovery/RemoteHandshaker.ts +64 -0
  189. package/src/logic/neighbor-discovery/RemoteNeighborUpdateManager.ts +41 -0
  190. package/src/logic/propagation/FifoMapWithTTL.ts +108 -0
  191. package/src/logic/propagation/Propagation.ts +83 -0
  192. package/src/logic/propagation/PropagationTaskStore.ts +40 -0
  193. package/src/logic/protocol-integration/stream-message/ContentMessageTranslator.ts +16 -0
  194. package/src/logic/protocol-integration/stream-message/GroupKeyRequestTranslator.ts +28 -0
  195. package/src/logic/protocol-integration/stream-message/GroupKeyResponseTranslator.ts +38 -0
  196. package/src/logic/protocol-integration/stream-message/StreamMessageTranslator.ts +142 -0
  197. package/src/logic/proxy/ProxyStreamConnectionClient.ts +255 -0
  198. package/src/logic/proxy/ProxyStreamConnectionServer.ts +97 -0
  199. package/src/logic/proxy/RemoteProxyServer.ts +36 -0
  200. package/src/logic/temporary-connection/RemoteTemporaryConnectionRpcServer.ts +27 -0
  201. package/src/logic/temporary-connection/TemporaryConnectionRpcServer.ts +50 -0
  202. package/src/logic/utils.ts +17 -0
  203. package/src/proto/google/protobuf/any.ts +319 -0
  204. package/src/proto/google/protobuf/empty.ts +84 -0
  205. package/src/proto/google/protobuf/timestamp.ts +281 -0
  206. package/src/proto/packages/dht/protos/DhtRpc.client.ts +373 -0
  207. package/src/proto/packages/dht/protos/DhtRpc.server.ts +148 -0
  208. package/src/proto/packages/dht/protos/DhtRpc.ts +1399 -0
  209. package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +108 -0
  210. package/src/proto/packages/trackerless-network/protos/NetworkRpc.client.ts +176 -0
  211. package/src/proto/packages/trackerless-network/protos/NetworkRpc.server.ts +68 -0
  212. package/src/proto/packages/trackerless-network/protos/NetworkRpc.ts +667 -0
  213. package/test/benchmark/first-message.ts +155 -0
  214. package/test/end-to-end/inspect.test.ts +119 -0
  215. package/test/end-to-end/proxy-and-full-node.test.ts +140 -0
  216. package/test/end-to-end/proxy-connections.test.ts +228 -0
  217. package/test/end-to-end/proxy-key-exchange.test.ts +142 -0
  218. package/test/end-to-end/random-graph-with-real-connections.test.ts +154 -0
  219. package/test/end-to-end/webrtc-full-node-network.test.ts +97 -0
  220. package/test/end-to-end/websocket-full-node-network.test.ts +93 -0
  221. package/test/integration/Handshakes.test.ts +167 -0
  222. package/test/integration/Inspect.test.ts +102 -0
  223. package/test/integration/NetworkNode.test.ts +99 -0
  224. package/test/integration/NetworkRpc.test.ts +61 -0
  225. package/test/integration/NetworkStack.test.ts +74 -0
  226. package/test/integration/NetworkStackStoppedDuringStart.test.ts +45 -0
  227. package/test/integration/Propagation.test.ts +79 -0
  228. package/test/integration/RandomGraphNode-Layer1Node-Latencies.test.ts +141 -0
  229. package/test/integration/RandomGraphNode-Layer1Node.test.ts +226 -0
  230. package/test/integration/RemoteHandshaker.test.ts +78 -0
  231. package/test/integration/RemoteNeighborUpdateManager.test.ts +82 -0
  232. package/test/integration/RemoteRandomGraphNode.test.ts +102 -0
  233. package/test/integration/StreamrNode.test.ts +145 -0
  234. package/test/integration/stream-without-default-entrypoints.test.ts +132 -0
  235. package/test/unit/ContentMessageTranslator.test.ts +20 -0
  236. package/test/unit/DuplicateMessageDetector.test.ts +192 -0
  237. package/test/unit/FifoMapWithTtl.test.ts +229 -0
  238. package/test/unit/GroupKeyRequestTranslator.test.ts +36 -0
  239. package/test/unit/GroupKeyResponseTranslator.test.ts +39 -0
  240. package/test/unit/Handshaker.test.ts +63 -0
  241. package/test/unit/HandshakerServer.test.ts +123 -0
  242. package/test/unit/InspectSession.test.ts +78 -0
  243. package/test/unit/Inspector.test.ts +57 -0
  244. package/test/unit/NeighborFinder.test.ts +48 -0
  245. package/test/unit/NumberPair.test.ts +22 -0
  246. package/test/unit/PeerList.test.ts +150 -0
  247. package/test/unit/Propagation.test.ts +134 -0
  248. package/test/unit/RandomGraphNode.test.ts +73 -0
  249. package/test/unit/StreamEntrypointDiscovery.test.ts +152 -0
  250. package/test/unit/StreamMessageTranslator.test.ts +67 -0
  251. package/test/unit/StreamNodeServer.test.ts +63 -0
  252. package/test/unit/StreamrNode.test.ts +74 -0
  253. package/test/utils/mock/MockHandshaker.ts +15 -0
  254. package/test/utils/mock/MockLayer0.ts +71 -0
  255. package/test/utils/mock/MockLayer1.ts +6 -0
  256. package/test/utils/mock/MockNeighborFinder.ts +19 -0
  257. package/test/utils/mock/MockNeighborUpdateManager.ts +21 -0
  258. package/test/utils/mock/Transport.ts +25 -0
  259. package/test/utils/utils.ts +104 -0
  260. package/tsconfig.browser.json +12 -0
  261. package/tsconfig.jest.json +15 -0
  262. package/tsconfig.node.json +18 -0
@@ -0,0 +1,319 @@
1
+ // @generated by protobuf-ts 2.8.2 with parameter server_generic,generate_dependencies,long_type_number
2
+ // @generated from protobuf file "google/protobuf/any.proto" (package "google.protobuf", syntax proto3)
3
+ // tslint:disable
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
+ //
35
+ import type { BinaryWriteOptions } from "@protobuf-ts/runtime";
36
+ import type { IBinaryWriter } from "@protobuf-ts/runtime";
37
+ import { WireType } from "@protobuf-ts/runtime";
38
+ import type { IBinaryReader } from "@protobuf-ts/runtime";
39
+ import { UnknownFieldHandler } from "@protobuf-ts/runtime";
40
+ import type { PartialMessage } from "@protobuf-ts/runtime";
41
+ import { reflectionMergePartial } from "@protobuf-ts/runtime";
42
+ import { MESSAGE_TYPE } from "@protobuf-ts/runtime";
43
+ import { isJsonObject } from "@protobuf-ts/runtime";
44
+ import { typeofJsonValue } from "@protobuf-ts/runtime";
45
+ import type { JsonValue } from "@protobuf-ts/runtime";
46
+ import { jsonWriteOptions } from "@protobuf-ts/runtime";
47
+ import type { JsonReadOptions } from "@protobuf-ts/runtime";
48
+ import type { JsonWriteOptions } from "@protobuf-ts/runtime";
49
+ import type { BinaryReadOptions } from "@protobuf-ts/runtime";
50
+ import type { IMessageType } from "@protobuf-ts/runtime";
51
+ import { MessageType } from "@protobuf-ts/runtime";
52
+ /**
53
+ * `Any` contains an arbitrary serialized protocol buffer message along with a
54
+ * URL that describes the type of the serialized message.
55
+ *
56
+ * Protobuf library provides support to pack/unpack Any values in the form
57
+ * of utility functions or additional generated methods of the Any type.
58
+ *
59
+ * Example 1: Pack and unpack a message in C++.
60
+ *
61
+ * Foo foo = ...;
62
+ * Any any;
63
+ * any.PackFrom(foo);
64
+ * ...
65
+ * if (any.UnpackTo(&foo)) {
66
+ * ...
67
+ * }
68
+ *
69
+ * Example 2: Pack and unpack a message in Java.
70
+ *
71
+ * Foo foo = ...;
72
+ * Any any = Any.pack(foo);
73
+ * ...
74
+ * if (any.is(Foo.class)) {
75
+ * foo = any.unpack(Foo.class);
76
+ * }
77
+ *
78
+ * Example 3: Pack and unpack a message in Python.
79
+ *
80
+ * foo = Foo(...)
81
+ * any = Any()
82
+ * any.Pack(foo)
83
+ * ...
84
+ * if any.Is(Foo.DESCRIPTOR):
85
+ * any.Unpack(foo)
86
+ * ...
87
+ *
88
+ * Example 4: Pack and unpack a message in Go
89
+ *
90
+ * foo := &pb.Foo{...}
91
+ * any, err := ptypes.MarshalAny(foo)
92
+ * ...
93
+ * foo := &pb.Foo{}
94
+ * if err := ptypes.UnmarshalAny(any, foo); err != nil {
95
+ * ...
96
+ * }
97
+ *
98
+ * The pack methods provided by protobuf library will by default use
99
+ * 'type.googleapis.com/full.type.name' as the type URL and the unpack
100
+ * methods only use the fully qualified type name after the last '/'
101
+ * in the type URL, for example "foo.bar.com/x/y.z" will yield type
102
+ * name "y.z".
103
+ *
104
+ *
105
+ * JSON
106
+ * ====
107
+ * The JSON representation of an `Any` value uses the regular
108
+ * representation of the deserialized, embedded message, with an
109
+ * additional field `@type` which contains the type URL. Example:
110
+ *
111
+ * package google.profile;
112
+ * message Person {
113
+ * string first_name = 1;
114
+ * string last_name = 2;
115
+ * }
116
+ *
117
+ * {
118
+ * "@type": "type.googleapis.com/google.profile.Person",
119
+ * "firstName": <string>,
120
+ * "lastName": <string>
121
+ * }
122
+ *
123
+ * If the embedded message type is well-known and has a custom JSON
124
+ * representation, that representation will be embedded adding a field
125
+ * `value` which holds the custom JSON in addition to the `@type`
126
+ * field. Example (for message [google.protobuf.Duration][]):
127
+ *
128
+ * {
129
+ * "@type": "type.googleapis.com/google.protobuf.Duration",
130
+ * "value": "1.212s"
131
+ * }
132
+ *
133
+ *
134
+ * @generated from protobuf message google.protobuf.Any
135
+ */
136
+ export interface Any {
137
+ /**
138
+ * A URL/resource name that uniquely identifies the type of the serialized
139
+ * protocol buffer message. This string must contain at least
140
+ * one "/" character. The last segment of the URL's path must represent
141
+ * the fully qualified name of the type (as in
142
+ * `path/google.protobuf.Duration`). The name should be in a canonical form
143
+ * (e.g., leading "." is not accepted).
144
+ *
145
+ * In practice, teams usually precompile into the binary all types that they
146
+ * expect it to use in the context of Any. However, for URLs which use the
147
+ * scheme `http`, `https`, or no scheme, one can optionally set up a type
148
+ * server that maps type URLs to message definitions as follows:
149
+ *
150
+ * * If no scheme is provided, `https` is assumed.
151
+ * * An HTTP GET on the URL must yield a [google.protobuf.Type][]
152
+ * value in binary format, or produce an error.
153
+ * * Applications are allowed to cache lookup results based on the
154
+ * URL, or have them precompiled into a binary to avoid any
155
+ * lookup. Therefore, binary compatibility needs to be preserved
156
+ * on changes to types. (Use versioned type names to manage
157
+ * breaking changes.)
158
+ *
159
+ * Note: this functionality is not currently available in the official
160
+ * protobuf release, and it is not used for type URLs beginning with
161
+ * type.googleapis.com.
162
+ *
163
+ * Schemes other than `http`, `https` (or the empty scheme) might be
164
+ * used with implementation specific semantics.
165
+ *
166
+ *
167
+ * @generated from protobuf field: string type_url = 1;
168
+ */
169
+ typeUrl: string;
170
+ /**
171
+ * Must be a valid serialized protocol buffer of the above specified type.
172
+ *
173
+ * @generated from protobuf field: bytes value = 2;
174
+ */
175
+ value: Uint8Array;
176
+ }
177
+ // @generated message type with reflection information, may provide speed optimized methods
178
+ class Any$Type extends MessageType<Any> {
179
+ constructor() {
180
+ super("google.protobuf.Any", [
181
+ { no: 1, name: "type_url", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
182
+ { no: 2, name: "value", kind: "scalar", T: 12 /*ScalarType.BYTES*/ }
183
+ ]);
184
+ }
185
+ /**
186
+ * Pack the message into a new `Any`.
187
+ *
188
+ * Uses 'type.googleapis.com/full.type.name' as the type URL.
189
+ */
190
+ pack<T extends object>(message: T, type: IMessageType<T>): Any {
191
+ return {
192
+ typeUrl: this.typeNameToUrl(type.typeName), value: type.toBinary(message),
193
+ };
194
+ }
195
+ /**
196
+ * Unpack the message from the `Any`.
197
+ */
198
+ unpack<T extends object>(any: Any, type: IMessageType<T>, options?: Partial<BinaryReadOptions>): T {
199
+ if (!this.contains(any, type))
200
+ throw new Error("Cannot unpack google.protobuf.Any with typeUrl '" + any.typeUrl + "' as " + type.typeName + ".");
201
+ return type.fromBinary(any.value, options);
202
+ }
203
+ /**
204
+ * Does the given `Any` contain a packed message of the given type?
205
+ */
206
+ contains(any: Any, type: IMessageType<any> | string): boolean {
207
+ if (!any.typeUrl.length)
208
+ return false;
209
+ let wants = typeof type == "string" ? type : type.typeName;
210
+ let has = this.typeUrlToName(any.typeUrl);
211
+ return wants === has;
212
+ }
213
+ /**
214
+ * Convert the message to canonical JSON value.
215
+ *
216
+ * You have to provide the `typeRegistry` option so that the
217
+ * packed message can be converted to JSON.
218
+ *
219
+ * The `typeRegistry` option is also required to read
220
+ * `google.protobuf.Any` from JSON format.
221
+ */
222
+ internalJsonWrite(any: Any, options: JsonWriteOptions): JsonValue {
223
+ if (any.typeUrl === "")
224
+ return {};
225
+ let typeName = this.typeUrlToName(any.typeUrl);
226
+ let opt = jsonWriteOptions(options);
227
+ let type = opt.typeRegistry?.find(t => t.typeName === typeName);
228
+ if (!type)
229
+ throw new globalThis.Error("Unable to convert google.protobuf.Any with typeUrl '" + any.typeUrl + "' to JSON. The specified type " + typeName + " is not available in the type registry.");
230
+ let value = type.fromBinary(any.value, { readUnknownField: false });
231
+ let json = type.internalJsonWrite(value, opt);
232
+ if (typeName.startsWith("google.protobuf.") || !isJsonObject(json))
233
+ json = { value: json };
234
+ json["@type"] = any.typeUrl;
235
+ return json;
236
+ }
237
+ internalJsonRead(json: JsonValue, options: JsonReadOptions, target?: Any): Any {
238
+ if (!isJsonObject(json))
239
+ throw new globalThis.Error("Unable to parse google.protobuf.Any from JSON " + typeofJsonValue(json) + ".");
240
+ if (typeof json["@type"] != "string" || json["@type"] == "")
241
+ return this.create();
242
+ let typeName = this.typeUrlToName(json["@type"]);
243
+ let type = options?.typeRegistry?.find(t => t.typeName == typeName);
244
+ if (!type)
245
+ throw new globalThis.Error("Unable to parse google.protobuf.Any from JSON. The specified type " + typeName + " is not available in the type registry.");
246
+ let value;
247
+ if (typeName.startsWith("google.protobuf.") && json.hasOwnProperty("value"))
248
+ value = type.fromJson(json["value"], options);
249
+ else {
250
+ let copy = Object.assign({}, json);
251
+ delete copy["@type"];
252
+ value = type.fromJson(copy, options);
253
+ }
254
+ if (target === undefined)
255
+ target = this.create();
256
+ target.typeUrl = json["@type"];
257
+ target.value = type.toBinary(value);
258
+ return target;
259
+ }
260
+ typeNameToUrl(name: string): string {
261
+ if (!name.length)
262
+ throw new Error("invalid type name: " + name);
263
+ return "type.googleapis.com/" + name;
264
+ }
265
+ typeUrlToName(url: string): string {
266
+ if (!url.length)
267
+ throw new Error("invalid type url: " + url);
268
+ let slash = url.lastIndexOf("/");
269
+ let name = slash > 0 ? url.substring(slash + 1) : url;
270
+ if (!name.length)
271
+ throw new Error("invalid type url: " + url);
272
+ return name;
273
+ }
274
+ create(value?: PartialMessage<Any>): Any {
275
+ const message = { typeUrl: "", value: new Uint8Array(0) };
276
+ globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this });
277
+ if (value !== undefined)
278
+ reflectionMergePartial<Any>(this, message, value);
279
+ return message;
280
+ }
281
+ internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: Any): Any {
282
+ let message = target ?? this.create(), end = reader.pos + length;
283
+ while (reader.pos < end) {
284
+ let [fieldNo, wireType] = reader.tag();
285
+ switch (fieldNo) {
286
+ case /* string type_url */ 1:
287
+ message.typeUrl = reader.string();
288
+ break;
289
+ case /* bytes value */ 2:
290
+ message.value = reader.bytes();
291
+ break;
292
+ default:
293
+ let u = options.readUnknownField;
294
+ if (u === "throw")
295
+ throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
296
+ let d = reader.skip(wireType);
297
+ if (u !== false)
298
+ (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
299
+ }
300
+ }
301
+ return message;
302
+ }
303
+ internalBinaryWrite(message: Any, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter {
304
+ /* string type_url = 1; */
305
+ if (message.typeUrl !== "")
306
+ writer.tag(1, WireType.LengthDelimited).string(message.typeUrl);
307
+ /* bytes value = 2; */
308
+ if (message.value.length)
309
+ writer.tag(2, WireType.LengthDelimited).bytes(message.value);
310
+ let u = options.writeUnknownFields;
311
+ if (u !== false)
312
+ (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
313
+ return writer;
314
+ }
315
+ }
316
+ /**
317
+ * @generated MessageType for protobuf message google.protobuf.Any
318
+ */
319
+ export const Any = new Any$Type();
@@ -0,0 +1,84 @@
1
+ // @generated by protobuf-ts 2.8.2 with parameter server_generic,generate_dependencies,long_type_number
2
+ // @generated from protobuf file "google/protobuf/empty.proto" (package "google.protobuf", syntax proto3)
3
+ // tslint:disable
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
+ //
35
+ import type { BinaryWriteOptions } from "@protobuf-ts/runtime";
36
+ import type { IBinaryWriter } from "@protobuf-ts/runtime";
37
+ import { UnknownFieldHandler } from "@protobuf-ts/runtime";
38
+ import type { BinaryReadOptions } from "@protobuf-ts/runtime";
39
+ import type { IBinaryReader } from "@protobuf-ts/runtime";
40
+ import type { PartialMessage } from "@protobuf-ts/runtime";
41
+ import { reflectionMergePartial } from "@protobuf-ts/runtime";
42
+ import { MESSAGE_TYPE } from "@protobuf-ts/runtime";
43
+ import { MessageType } from "@protobuf-ts/runtime";
44
+ /**
45
+ * A generic empty message that you can re-use to avoid defining duplicated
46
+ * empty messages in your APIs. A typical example is to use it as the request
47
+ * or the response type of an API method. For instance:
48
+ *
49
+ * service Foo {
50
+ * rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);
51
+ * }
52
+ *
53
+ * The JSON representation for `Empty` is empty JSON object `{}`.
54
+ *
55
+ * @generated from protobuf message google.protobuf.Empty
56
+ */
57
+ export interface Empty {
58
+ }
59
+ // @generated message type with reflection information, may provide speed optimized methods
60
+ class Empty$Type extends MessageType<Empty> {
61
+ constructor() {
62
+ super("google.protobuf.Empty", []);
63
+ }
64
+ create(value?: PartialMessage<Empty>): Empty {
65
+ const message = {};
66
+ globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this });
67
+ if (value !== undefined)
68
+ reflectionMergePartial<Empty>(this, message, value);
69
+ return message;
70
+ }
71
+ internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: Empty): Empty {
72
+ return target ?? this.create();
73
+ }
74
+ internalBinaryWrite(message: Empty, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter {
75
+ let u = options.writeUnknownFields;
76
+ if (u !== false)
77
+ (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
78
+ return writer;
79
+ }
80
+ }
81
+ /**
82
+ * @generated MessageType for protobuf message google.protobuf.Empty
83
+ */
84
+ export const Empty = new Empty$Type();
@@ -0,0 +1,281 @@
1
+ // @generated by protobuf-ts 2.8.2 with parameter server_generic,generate_dependencies,long_type_number
2
+ // @generated from protobuf file "google/protobuf/timestamp.proto" (package "google.protobuf", syntax proto3)
3
+ // tslint:disable
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
+ //
35
+ import type { BinaryWriteOptions } from "@protobuf-ts/runtime";
36
+ import type { IBinaryWriter } from "@protobuf-ts/runtime";
37
+ import { WireType } from "@protobuf-ts/runtime";
38
+ import type { BinaryReadOptions } from "@protobuf-ts/runtime";
39
+ import type { IBinaryReader } from "@protobuf-ts/runtime";
40
+ import { UnknownFieldHandler } from "@protobuf-ts/runtime";
41
+ import type { PartialMessage } from "@protobuf-ts/runtime";
42
+ import { reflectionMergePartial } from "@protobuf-ts/runtime";
43
+ import { MESSAGE_TYPE } from "@protobuf-ts/runtime";
44
+ import { typeofJsonValue } from "@protobuf-ts/runtime";
45
+ import type { JsonValue } from "@protobuf-ts/runtime";
46
+ import type { JsonReadOptions } from "@protobuf-ts/runtime";
47
+ import type { JsonWriteOptions } from "@protobuf-ts/runtime";
48
+ import { PbLong } from "@protobuf-ts/runtime";
49
+ import { MessageType } from "@protobuf-ts/runtime";
50
+ /**
51
+ * A Timestamp represents a point in time independent of any time zone or local
52
+ * calendar, encoded as a count of seconds and fractions of seconds at
53
+ * nanosecond resolution. The count is relative to an epoch at UTC midnight on
54
+ * January 1, 1970, in the proleptic Gregorian calendar which extends the
55
+ * Gregorian calendar backwards to year one.
56
+ *
57
+ * All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap
58
+ * second table is needed for interpretation, using a [24-hour linear
59
+ * smear](https://developers.google.com/time/smear).
60
+ *
61
+ * The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By
62
+ * restricting to that range, we ensure that we can convert to and from [RFC
63
+ * 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings.
64
+ *
65
+ * # Examples
66
+ *
67
+ * Example 1: Compute Timestamp from POSIX `time()`.
68
+ *
69
+ * Timestamp timestamp;
70
+ * timestamp.set_seconds(time(NULL));
71
+ * timestamp.set_nanos(0);
72
+ *
73
+ * Example 2: Compute Timestamp from POSIX `gettimeofday()`.
74
+ *
75
+ * struct timeval tv;
76
+ * gettimeofday(&tv, NULL);
77
+ *
78
+ * Timestamp timestamp;
79
+ * timestamp.set_seconds(tv.tv_sec);
80
+ * timestamp.set_nanos(tv.tv_usec * 1000);
81
+ *
82
+ * Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`.
83
+ *
84
+ * FILETIME ft;
85
+ * GetSystemTimeAsFileTime(&ft);
86
+ * UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
87
+ *
88
+ * // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z
89
+ * // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z.
90
+ * Timestamp timestamp;
91
+ * timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL));
92
+ * timestamp.set_nanos((INT32) ((ticks % 10000000) * 100));
93
+ *
94
+ * Example 4: Compute Timestamp from Java `System.currentTimeMillis()`.
95
+ *
96
+ * long millis = System.currentTimeMillis();
97
+ *
98
+ * Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000)
99
+ * .setNanos((int) ((millis % 1000) * 1000000)).build();
100
+ *
101
+ *
102
+ * Example 5: Compute Timestamp from current time in Python.
103
+ *
104
+ * timestamp = Timestamp()
105
+ * timestamp.GetCurrentTime()
106
+ *
107
+ * # JSON Mapping
108
+ *
109
+ * In JSON format, the Timestamp type is encoded as a string in the
110
+ * [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the
111
+ * format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z"
112
+ * where {year} is always expressed using four digits while {month}, {day},
113
+ * {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional
114
+ * seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution),
115
+ * are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone
116
+ * is required. A proto3 JSON serializer should always use UTC (as indicated by
117
+ * "Z") when printing the Timestamp type and a proto3 JSON parser should be
118
+ * able to accept both UTC and other timezones (as indicated by an offset).
119
+ *
120
+ * For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past
121
+ * 01:30 UTC on January 15, 2017.
122
+ *
123
+ * In JavaScript, one can convert a Date object to this format using the
124
+ * standard
125
+ * [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
126
+ * method. In Python, a standard `datetime.datetime` object can be converted
127
+ * to this format using
128
+ * [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with
129
+ * the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use
130
+ * the Joda Time's [`ISODateTimeFormat.dateTime()`](
131
+ * http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D
132
+ * ) to obtain a formatter capable of generating timestamps in this format.
133
+ *
134
+ *
135
+ *
136
+ * @generated from protobuf message google.protobuf.Timestamp
137
+ */
138
+ export interface Timestamp {
139
+ /**
140
+ * Represents seconds of UTC time since Unix epoch
141
+ * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
142
+ * 9999-12-31T23:59:59Z inclusive.
143
+ *
144
+ * @generated from protobuf field: int64 seconds = 1;
145
+ */
146
+ seconds: number;
147
+ /**
148
+ * Non-negative fractions of a second at nanosecond resolution. Negative
149
+ * second values with fractions must still have non-negative nanos values
150
+ * that count forward in time. Must be from 0 to 999,999,999
151
+ * inclusive.
152
+ *
153
+ * @generated from protobuf field: int32 nanos = 2;
154
+ */
155
+ nanos: number;
156
+ }
157
+ // @generated message type with reflection information, may provide speed optimized methods
158
+ class Timestamp$Type extends MessageType<Timestamp> {
159
+ constructor() {
160
+ super("google.protobuf.Timestamp", [
161
+ { no: 1, name: "seconds", kind: "scalar", T: 3 /*ScalarType.INT64*/, L: 2 /*LongType.NUMBER*/ },
162
+ { no: 2, name: "nanos", kind: "scalar", T: 5 /*ScalarType.INT32*/ }
163
+ ]);
164
+ }
165
+ /**
166
+ * Creates a new `Timestamp` for the current time.
167
+ */
168
+ now(): Timestamp {
169
+ const msg = this.create();
170
+ const ms = Date.now();
171
+ msg.seconds = PbLong.from(Math.floor(ms / 1000)).toNumber();
172
+ msg.nanos = (ms % 1000) * 1000000;
173
+ return msg;
174
+ }
175
+ /**
176
+ * Converts a `Timestamp` to a JavaScript Date.
177
+ */
178
+ toDate(message: Timestamp): Date {
179
+ return new Date(PbLong.from(message.seconds).toNumber() * 1000 + Math.ceil(message.nanos / 1000000));
180
+ }
181
+ /**
182
+ * Converts a JavaScript Date to a `Timestamp`.
183
+ */
184
+ fromDate(date: Date): Timestamp {
185
+ const msg = this.create();
186
+ const ms = date.getTime();
187
+ msg.seconds = PbLong.from(Math.floor(ms / 1000)).toNumber();
188
+ msg.nanos = (ms % 1000) * 1000000;
189
+ return msg;
190
+ }
191
+ /**
192
+ * In JSON format, the `Timestamp` type is encoded as a string
193
+ * in the RFC 3339 format.
194
+ */
195
+ internalJsonWrite(message: Timestamp, options: JsonWriteOptions): JsonValue {
196
+ let ms = PbLong.from(message.seconds).toNumber() * 1000;
197
+ if (ms < Date.parse("0001-01-01T00:00:00Z") || ms > Date.parse("9999-12-31T23:59:59Z"))
198
+ throw new Error("Unable to encode Timestamp to JSON. Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive.");
199
+ if (message.nanos < 0)
200
+ throw new Error("Unable to encode invalid Timestamp to JSON. Nanos must not be negative.");
201
+ let z = "Z";
202
+ if (message.nanos > 0) {
203
+ let nanosStr = (message.nanos + 1000000000).toString().substring(1);
204
+ if (nanosStr.substring(3) === "000000")
205
+ z = "." + nanosStr.substring(0, 3) + "Z";
206
+ else if (nanosStr.substring(6) === "000")
207
+ z = "." + nanosStr.substring(0, 6) + "Z";
208
+ else
209
+ z = "." + nanosStr + "Z";
210
+ }
211
+ return new Date(ms).toISOString().replace(".000Z", z);
212
+ }
213
+ /**
214
+ * In JSON format, the `Timestamp` type is encoded as a string
215
+ * in the RFC 3339 format.
216
+ */
217
+ internalJsonRead(json: JsonValue, options: JsonReadOptions, target?: Timestamp): Timestamp {
218
+ if (typeof json !== "string")
219
+ throw new Error("Unable to parse Timestamp from JSON " + typeofJsonValue(json) + ".");
220
+ let matches = json.match(/^([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]))$/);
221
+ if (!matches)
222
+ throw new Error("Unable to parse Timestamp from JSON. Invalid format.");
223
+ let ms = Date.parse(matches[1] + "-" + matches[2] + "-" + matches[3] + "T" + matches[4] + ":" + matches[5] + ":" + matches[6] + (matches[8] ? matches[8] : "Z"));
224
+ if (Number.isNaN(ms))
225
+ throw new Error("Unable to parse Timestamp from JSON. Invalid value.");
226
+ if (ms < Date.parse("0001-01-01T00:00:00Z") || ms > Date.parse("9999-12-31T23:59:59Z"))
227
+ throw new globalThis.Error("Unable to parse Timestamp from JSON. Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive.");
228
+ if (!target)
229
+ target = this.create();
230
+ target.seconds = PbLong.from(ms / 1000).toNumber();
231
+ target.nanos = 0;
232
+ if (matches[7])
233
+ target.nanos = (parseInt("1" + matches[7] + "0".repeat(9 - matches[7].length)) - 1000000000);
234
+ return target;
235
+ }
236
+ create(value?: PartialMessage<Timestamp>): Timestamp {
237
+ const message = { seconds: 0, nanos: 0 };
238
+ globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this });
239
+ if (value !== undefined)
240
+ reflectionMergePartial<Timestamp>(this, message, value);
241
+ return message;
242
+ }
243
+ internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: Timestamp): Timestamp {
244
+ let message = target ?? this.create(), end = reader.pos + length;
245
+ while (reader.pos < end) {
246
+ let [fieldNo, wireType] = reader.tag();
247
+ switch (fieldNo) {
248
+ case /* int64 seconds */ 1:
249
+ message.seconds = reader.int64().toNumber();
250
+ break;
251
+ case /* int32 nanos */ 2:
252
+ message.nanos = reader.int32();
253
+ break;
254
+ default:
255
+ let u = options.readUnknownField;
256
+ if (u === "throw")
257
+ throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
258
+ let d = reader.skip(wireType);
259
+ if (u !== false)
260
+ (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
261
+ }
262
+ }
263
+ return message;
264
+ }
265
+ internalBinaryWrite(message: Timestamp, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter {
266
+ /* int64 seconds = 1; */
267
+ if (message.seconds !== 0)
268
+ writer.tag(1, WireType.Varint).int64(message.seconds);
269
+ /* int32 nanos = 2; */
270
+ if (message.nanos !== 0)
271
+ writer.tag(2, WireType.Varint).int32(message.nanos);
272
+ let u = options.writeUnknownFields;
273
+ if (u !== false)
274
+ (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
275
+ return writer;
276
+ }
277
+ }
278
+ /**
279
+ * @generated MessageType for protobuf message google.protobuf.Timestamp
280
+ */
281
+ export const Timestamp = new Timestamp$Type();