@streamr/dht 102.0.0-beta.0 → 102.0.0-beta.2

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 (264) hide show
  1. package/dist/generated/packages/dht/protos/DhtRpc.d.ts +16 -8
  2. package/dist/generated/packages/dht/protos/DhtRpc.js +7 -5
  3. package/dist/generated/packages/dht/protos/DhtRpc.js.map +1 -1
  4. package/dist/package.json +15 -16
  5. package/dist/src/connection/ConnectionManager.js +18 -8
  6. package/dist/src/connection/ConnectionManager.js.map +1 -1
  7. package/dist/src/connection/Handshaker.d.ts +1 -1
  8. package/dist/src/connection/Handshaker.js +9 -5
  9. package/dist/src/connection/Handshaker.js.map +1 -1
  10. package/dist/src/connection/ManagedConnection.js +17 -7
  11. package/dist/src/connection/ManagedConnection.js.map +1 -1
  12. package/dist/src/connection/connectivityChecker.js +20 -10
  13. package/dist/src/connection/connectivityChecker.js.map +1 -1
  14. package/dist/src/connection/connectivityRequestHandler.js +3 -3
  15. package/dist/src/connection/connectivityRequestHandler.js.map +1 -1
  16. package/dist/src/connection/simulator/Simulator.js +3 -2
  17. package/dist/src/connection/simulator/Simulator.js.map +1 -1
  18. package/dist/src/connection/simulator/pings.d.ts +1 -1
  19. package/dist/src/connection/simulator/pings.js +3 -3
  20. package/dist/src/connection/simulator/pings.js.map +1 -1
  21. package/dist/src/connection/webrtc/NodeWebrtcConnection.js +0 -2
  22. package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
  23. package/dist/src/connection/webrtc/WebrtcConnector.js +19 -9
  24. package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
  25. package/dist/src/connection/webrtc/iceServerAsString.js +1 -2
  26. package/dist/src/connection/webrtc/iceServerAsString.js.map +1 -1
  27. package/dist/src/connection/websocket/AbstractWebsocketClientConnection.d.ts +0 -2
  28. package/dist/src/connection/websocket/WebsocketClientConnectorRpcLocal.d.ts +0 -1
  29. package/dist/src/connection/websocket/WebsocketServerConnection.d.ts +0 -1
  30. package/dist/src/connection/websocket/WebsocketServerConnector.js +28 -18
  31. package/dist/src/connection/websocket/WebsocketServerConnector.js.map +1 -1
  32. package/dist/src/dht/DhtNode.d.ts +1 -0
  33. package/dist/src/dht/DhtNode.js +3 -2
  34. package/dist/src/dht/DhtNode.js.map +1 -1
  35. package/dist/src/dht/DhtNodeRpcLocal.d.ts +1 -1
  36. package/dist/src/dht/PeerManager.d.ts +2 -1
  37. package/dist/src/dht/PeerManager.js +2 -1
  38. package/dist/src/dht/PeerManager.js.map +1 -1
  39. package/dist/src/dht/contact/SortedContactList.js +1 -1
  40. package/dist/src/dht/contact/SortedContactList.js.map +1 -1
  41. package/dist/src/dht/discovery/DiscoverySession.d.ts +0 -1
  42. package/dist/src/dht/discovery/PeerDiscovery.d.ts +0 -1
  43. package/dist/src/dht/discovery/RingDiscoverySession.d.ts +0 -1
  44. package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +2 -2
  45. package/dist/src/dht/routing/DuplicateDetector.js.map +1 -1
  46. package/dist/src/dht/routing/RoutingSession.js +2 -2
  47. package/dist/src/dht/routing/RoutingSession.js.map +1 -1
  48. package/dist/src/dht/routing/RoutingTablesCache.d.ts +1 -1
  49. package/dist/src/dht/store/LocalDataStore.js +1 -1
  50. package/dist/src/dht/store/LocalDataStore.js.map +1 -1
  51. package/dist/src/dht/store/StoreManager.d.ts +1 -1
  52. package/dist/src/dht/store/StoreRpcLocal.d.ts +1 -1
  53. package/dist/src/helpers/AddressTools.js +2 -3
  54. package/dist/src/helpers/AddressTools.js.map +1 -1
  55. package/dist/src/helpers/debugHelpers.js +2 -2
  56. package/dist/src/helpers/debugHelpers.js.map +1 -1
  57. package/dist/src/helpers/protoClasses.d.ts +1 -1
  58. package/dist/src/helpers/protoClasses.js.map +1 -1
  59. package/dist/src/helpers/protoToString.js +1 -2
  60. package/dist/src/helpers/protoToString.js.map +1 -1
  61. package/dist/src/helpers/version.d.ts +1 -1
  62. package/dist/src/helpers/version.js +4 -4
  63. package/dist/src/helpers/version.js.map +1 -1
  64. package/eslint.config.mjs +12 -0
  65. package/jest.config.ts +12 -0
  66. package/package.json +15 -16
  67. package/protos/DhtRpc.proto +6 -4
  68. package/.eslintignore +0 -5
  69. package/.eslintrc +0 -3
  70. package/generated/google/protobuf/any.ts +0 -326
  71. package/generated/google/protobuf/empty.ts +0 -81
  72. package/generated/google/protobuf/timestamp.ts +0 -287
  73. package/generated/packages/dht/protos/DhtRpc.client.ts +0 -419
  74. package/generated/packages/dht/protos/DhtRpc.server.ts +0 -165
  75. package/generated/packages/dht/protos/DhtRpc.ts +0 -1266
  76. package/generated/packages/proto-rpc/protos/ProtoRpc.ts +0 -108
  77. package/jest.config.js +0 -5
  78. package/src/connection/Connection.ts +0 -28
  79. package/src/connection/ConnectionLockRpcLocal.ts +0 -78
  80. package/src/connection/ConnectionLockRpcRemote.ts +0 -64
  81. package/src/connection/ConnectionLockStates.ts +0 -131
  82. package/src/connection/ConnectionManager.ts +0 -661
  83. package/src/connection/ConnectionsView.ts +0 -8
  84. package/src/connection/ConnectorFacade.ts +0 -217
  85. package/src/connection/Handshaker.ts +0 -205
  86. package/src/connection/IConnection.ts +0 -40
  87. package/src/connection/ManagedConnection.ts +0 -113
  88. package/src/connection/OutputBuffer.ts +0 -28
  89. package/src/connection/PendingConnection.ts +0 -68
  90. package/src/connection/connectivityChecker.ts +0 -108
  91. package/src/connection/connectivityRequestHandler.ts +0 -116
  92. package/src/connection/simulator/Simulator.ts +0 -368
  93. package/src/connection/simulator/SimulatorConnection.ts +0 -137
  94. package/src/connection/simulator/SimulatorConnector.ts +0 -98
  95. package/src/connection/simulator/SimulatorTransport.ts +0 -15
  96. package/src/connection/simulator/pings.ts +0 -42
  97. package/src/connection/webrtc/BrowserWebrtcConnection.ts +0 -242
  98. package/src/connection/webrtc/IWebrtcConnection.ts +0 -24
  99. package/src/connection/webrtc/NodeWebrtcConnection.ts +0 -247
  100. package/src/connection/webrtc/WebrtcConnector.ts +0 -234
  101. package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +0 -108
  102. package/src/connection/webrtc/WebrtcConnectorRpcRemote.ts +0 -60
  103. package/src/connection/webrtc/iceServerAsString.ts +0 -15
  104. package/src/connection/websocket/AbstractWebsocketClientConnection.ts +0 -122
  105. package/src/connection/websocket/AutoCertifierClientFacade.ts +0 -89
  106. package/src/connection/websocket/BrowserWebsocketClientConnection.ts +0 -44
  107. package/src/connection/websocket/NodeWebsocketClientConnection.ts +0 -39
  108. package/src/connection/websocket/WebsocketClientConnector.ts +0 -119
  109. package/src/connection/websocket/WebsocketClientConnectorRpcLocal.ts +0 -38
  110. package/src/connection/websocket/WebsocketClientConnectorRpcRemote.ts +0 -19
  111. package/src/connection/websocket/WebsocketServer.ts +0 -164
  112. package/src/connection/websocket/WebsocketServerConnection.ts +0 -109
  113. package/src/connection/websocket/WebsocketServerConnector.ts +0 -286
  114. package/src/dht/DhtNode.ts +0 -678
  115. package/src/dht/DhtNodeRpcLocal.ts +0 -84
  116. package/src/dht/DhtNodeRpcRemote.ts +0 -107
  117. package/src/dht/ExternalApiRpcLocal.ts +0 -58
  118. package/src/dht/ExternalApiRpcRemote.ts +0 -41
  119. package/src/dht/PeerManager.ts +0 -303
  120. package/src/dht/contact/Contact.ts +0 -19
  121. package/src/dht/contact/ContactList.ts +0 -43
  122. package/src/dht/contact/RandomContactList.ts +0 -56
  123. package/src/dht/contact/RingContactList.ts +0 -143
  124. package/src/dht/contact/RpcRemote.ts +0 -72
  125. package/src/dht/contact/SortedContactList.ts +0 -173
  126. package/src/dht/contact/getClosestNodes.ts +0 -24
  127. package/src/dht/contact/ringIdentifiers.ts +0 -62
  128. package/src/dht/discovery/DiscoverySession.ts +0 -129
  129. package/src/dht/discovery/PeerDiscovery.ts +0 -244
  130. package/src/dht/discovery/RingDiscoverySession.ts +0 -148
  131. package/src/dht/recursive-operation/RecursiveOperationManager.ts +0 -251
  132. package/src/dht/recursive-operation/RecursiveOperationRpcLocal.ts +0 -34
  133. package/src/dht/recursive-operation/RecursiveOperationRpcRemote.ts +0 -43
  134. package/src/dht/recursive-operation/RecursiveOperationSession.ts +0 -231
  135. package/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.ts +0 -35
  136. package/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.ts +0 -30
  137. package/src/dht/routing/DuplicateDetector.ts +0 -34
  138. package/src/dht/routing/Router.ts +0 -246
  139. package/src/dht/routing/RouterRpcLocal.ts +0 -78
  140. package/src/dht/routing/RouterRpcRemote.ts +0 -80
  141. package/src/dht/routing/RoutingSession.ts +0 -243
  142. package/src/dht/routing/RoutingTablesCache.ts +0 -60
  143. package/src/dht/routing/getPreviousPeer.ts +0 -6
  144. package/src/dht/store/LocalDataStore.ts +0 -84
  145. package/src/dht/store/StoreManager.ts +0 -170
  146. package/src/dht/store/StoreRpcLocal.ts +0 -89
  147. package/src/dht/store/StoreRpcRemote.ts +0 -32
  148. package/src/exports.ts +0 -33
  149. package/src/helpers/AddressTools.ts +0 -28
  150. package/src/helpers/Connectivity.ts +0 -19
  151. package/src/helpers/browser/isBrowserEnvironment.ts +0 -1
  152. package/src/helpers/browser/isBrowserEnvironment_override.ts +0 -3
  153. package/src/helpers/createPeerDescriptor.ts +0 -57
  154. package/src/helpers/createPeerDescriptorSignaturePayload.ts +0 -28
  155. package/src/helpers/debugHelpers.ts +0 -9
  156. package/src/helpers/errors.ts +0 -49
  157. package/src/helpers/offering.ts +0 -15
  158. package/src/helpers/protoClasses.ts +0 -57
  159. package/src/helpers/protoToString.ts +0 -21
  160. package/src/helpers/version.ts +0 -32
  161. package/src/identifiers.ts +0 -29
  162. package/src/rpc-protocol/DhtCallContext.ts +0 -14
  163. package/src/rpc-protocol/DhtRpcOptions.ts +0 -10
  164. package/src/transport/ITransport.ts +0 -37
  165. package/src/transport/ListeningRpcCommunicator.ts +0 -32
  166. package/src/transport/RoutingRpcCommunicator.ts +0 -66
  167. package/src/types/ServiceID.ts +0 -1
  168. package/src/types/textencoding.d.ts +0 -6
  169. package/test/benchmark/Find.test.ts +0 -72
  170. package/test/benchmark/KademliaCorrectness.test.ts +0 -114
  171. package/test/benchmark/RingCorrectness.test.ts +0 -157
  172. package/test/benchmark/SortedContactListBenchmark.test.ts +0 -108
  173. package/test/benchmark/WebsocketServerMemoryLeak.test.ts +0 -41
  174. package/test/benchmark/hybrid-network-simulation/RingContactList.test.ts +0 -71
  175. package/test/end-to-end/GeoIpLayer0.test.ts +0 -55
  176. package/test/end-to-end/Layer0-Layer1.test.ts +0 -93
  177. package/test/end-to-end/Layer0.test.ts +0 -76
  178. package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +0 -110
  179. package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +0 -137
  180. package/test/end-to-end/Layer0Webrtc.test.ts +0 -85
  181. package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +0 -82
  182. package/test/end-to-end/Layer1-Scale-Webrtc.test.ts +0 -76
  183. package/test/end-to-end/RecoveryFromFailedAutoCertification.test.ts +0 -52
  184. package/test/end-to-end/WebsocketConnectionRequest.test.ts +0 -69
  185. package/test/end-to-end/memory-leak.test.ts +0 -80
  186. package/test/integration/ConnectionLocking.test.ts +0 -182
  187. package/test/integration/ConnectionManager.test.ts +0 -528
  188. package/test/integration/ConnectivityChecking.test.ts +0 -53
  189. package/test/integration/DhtJoinPeerDiscovery.test.ts +0 -49
  190. package/test/integration/DhtNode.test.ts +0 -66
  191. package/test/integration/DhtNodeExternalAPI.test.ts +0 -48
  192. package/test/integration/DhtNodeRpcRemote.test.ts +0 -66
  193. package/test/integration/DhtRpc.test.ts +0 -121
  194. package/test/integration/Find.test.ts +0 -45
  195. package/test/integration/GeoIpConnectivityChecking.test.ts +0 -72
  196. package/test/integration/Layer1-scale.test.ts +0 -189
  197. package/test/integration/Mock-Layer1-Layer0.test.ts +0 -85
  198. package/test/integration/MultipleEntryPointJoining.test.ts +0 -105
  199. package/test/integration/ReplicateData.test.ts +0 -104
  200. package/test/integration/RouteMessage.test.ts +0 -230
  201. package/test/integration/RouterRpcRemote.test.ts +0 -77
  202. package/test/integration/SimultaneousConnections.test.ts +0 -316
  203. package/test/integration/Store.test.ts +0 -85
  204. package/test/integration/StoreAndDelete.test.ts +0 -77
  205. package/test/integration/StoreOnDhtWithThreeNodes.test.ts +0 -59
  206. package/test/integration/StoreOnDhtWithTwoNodes.test.ts +0 -51
  207. package/test/integration/StoreRpcRemote.test.ts +0 -54
  208. package/test/integration/WebrtcConnectionManagement.test.ts +0 -219
  209. package/test/integration/WebrtcConnectorRpc.test.ts +0 -125
  210. package/test/integration/Websocket.test.ts +0 -65
  211. package/test/integration/WebsocketClientConnectorRpc.test.ts +0 -69
  212. package/test/integration/WebsocketConnectionManagement.test.ts +0 -191
  213. package/test/integration/rpc-connections-over-webrtc.test.ts +0 -158
  214. package/test/kademlia-simulation/data/nodeids.json +0 -13002
  215. package/test/kademlia-simulation/data/orderedneighbors.json +0 -1001
  216. package/test/types/global.d.ts +0 -1
  217. package/test/unit/AddressTools.test.ts +0 -44
  218. package/test/unit/AutoCertifierClientFacade.test.ts +0 -58
  219. package/test/unit/ConnectionManager.test.ts +0 -65
  220. package/test/unit/ConnectivityHelpers.test.ts +0 -61
  221. package/test/unit/DiscoverySession.test.ts +0 -87
  222. package/test/unit/DuplicateDetector.test.ts +0 -31
  223. package/test/unit/Handshaker.test.ts +0 -169
  224. package/test/unit/ListeningRpcCommunicator.test.ts +0 -52
  225. package/test/unit/LocalDataStore.test.ts +0 -108
  226. package/test/unit/ManagedConnection.test.ts +0 -58
  227. package/test/unit/PeerManager.test.ts +0 -93
  228. package/test/unit/PendingConnection.test.ts +0 -57
  229. package/test/unit/ProtobufMessage.test.ts +0 -21
  230. package/test/unit/RandomContactList.test.ts +0 -58
  231. package/test/unit/RecursiveOperationManager.test.ts +0 -161
  232. package/test/unit/RecursiveOperationSession.test.ts +0 -68
  233. package/test/unit/Router.test.ts +0 -137
  234. package/test/unit/RoutingSession.test.ts +0 -79
  235. package/test/unit/SortedContactList.test.ts +0 -115
  236. package/test/unit/StoreManager.test.ts +0 -146
  237. package/test/unit/StoreRpcLocal.test.ts +0 -167
  238. package/test/unit/WebrtcConnection.test.ts +0 -29
  239. package/test/unit/WebrtcConnector.test.ts +0 -56
  240. package/test/unit/WebsocketClientConnector.test.ts +0 -101
  241. package/test/unit/WebsocketServer.test.ts +0 -66
  242. package/test/unit/WebsocketServerConnector.test.ts +0 -102
  243. package/test/unit/connectivityRequestHandler.test.ts +0 -104
  244. package/test/unit/createPeerDescriptor.test.ts +0 -69
  245. package/test/unit/customMatchers.test.ts +0 -16
  246. package/test/unit/getClosestNodes.test.ts +0 -30
  247. package/test/unit/version.test.ts +0 -18
  248. package/test/unit/webrtcReplaceInternalIpWithExternalIp.test.ts +0 -18
  249. package/test/utils/FakeConnectorFacade.ts +0 -41
  250. package/test/utils/FakeRpcCommunicator.ts +0 -23
  251. package/test/utils/FakeTransport.ts +0 -79
  252. package/test/utils/customMatchers.ts +0 -71
  253. package/test/utils/mock/MockConnection.ts +0 -26
  254. package/test/utils/mock/MockConnectionsView.ts +0 -18
  255. package/test/utils/mock/MockRouter.ts +0 -62
  256. package/test/utils/mock/MockRpcCommunicator.ts +0 -7
  257. package/test/utils/mock/MockTransport.ts +0 -26
  258. package/test/utils/mock/mockDataEntry.ts +0 -38
  259. package/test/utils/topology.ts +0 -80
  260. package/test/utils/utils.ts +0 -268
  261. package/tsconfig.browser.json +0 -17
  262. package/tsconfig.jest.json +0 -25
  263. package/tsconfig.json +0 -3
  264. package/tsconfig.node.json +0 -24
@@ -1,287 +0,0 @@
1
- // @generated by protobuf-ts 2.9.4 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 { typeofJsonValue } from "@protobuf-ts/runtime";
44
- import type { JsonValue } from "@protobuf-ts/runtime";
45
- import type { JsonReadOptions } from "@protobuf-ts/runtime";
46
- import type { JsonWriteOptions } from "@protobuf-ts/runtime";
47
- import { PbLong } from "@protobuf-ts/runtime";
48
- import { MessageType } from "@protobuf-ts/runtime";
49
- /**
50
- * A Timestamp represents a point in time independent of any time zone or local
51
- * calendar, encoded as a count of seconds and fractions of seconds at
52
- * nanosecond resolution. The count is relative to an epoch at UTC midnight on
53
- * January 1, 1970, in the proleptic Gregorian calendar which extends the
54
- * Gregorian calendar backwards to year one.
55
- *
56
- * All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap
57
- * second table is needed for interpretation, using a [24-hour linear
58
- * smear](https://developers.google.com/time/smear).
59
- *
60
- * The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By
61
- * restricting to that range, we ensure that we can convert to and from [RFC
62
- * 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings.
63
- *
64
- * # Examples
65
- *
66
- * Example 1: Compute Timestamp from POSIX `time()`.
67
- *
68
- * Timestamp timestamp;
69
- * timestamp.set_seconds(time(NULL));
70
- * timestamp.set_nanos(0);
71
- *
72
- * Example 2: Compute Timestamp from POSIX `gettimeofday()`.
73
- *
74
- * struct timeval tv;
75
- * gettimeofday(&tv, NULL);
76
- *
77
- * Timestamp timestamp;
78
- * timestamp.set_seconds(tv.tv_sec);
79
- * timestamp.set_nanos(tv.tv_usec * 1000);
80
- *
81
- * Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`.
82
- *
83
- * FILETIME ft;
84
- * GetSystemTimeAsFileTime(&ft);
85
- * UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
86
- *
87
- * // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z
88
- * // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z.
89
- * Timestamp timestamp;
90
- * timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL));
91
- * timestamp.set_nanos((INT32) ((ticks % 10000000) * 100));
92
- *
93
- * Example 4: Compute Timestamp from Java `System.currentTimeMillis()`.
94
- *
95
- * long millis = System.currentTimeMillis();
96
- *
97
- * Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000)
98
- * .setNanos((int) ((millis % 1000) * 1000000)).build();
99
- *
100
- * Example 5: Compute Timestamp from Java `Instant.now()`.
101
- *
102
- * Instant now = Instant.now();
103
- *
104
- * Timestamp timestamp =
105
- * Timestamp.newBuilder().setSeconds(now.getEpochSecond())
106
- * .setNanos(now.getNano()).build();
107
- *
108
- * Example 6: Compute Timestamp from current time in Python.
109
- *
110
- * timestamp = Timestamp()
111
- * timestamp.GetCurrentTime()
112
- *
113
- * # JSON Mapping
114
- *
115
- * In JSON format, the Timestamp type is encoded as a string in the
116
- * [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the
117
- * format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z"
118
- * where {year} is always expressed using four digits while {month}, {day},
119
- * {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional
120
- * seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution),
121
- * are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone
122
- * is required. A proto3 JSON serializer should always use UTC (as indicated by
123
- * "Z") when printing the Timestamp type and a proto3 JSON parser should be
124
- * able to accept both UTC and other timezones (as indicated by an offset).
125
- *
126
- * For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past
127
- * 01:30 UTC on January 15, 2017.
128
- *
129
- * In JavaScript, one can convert a Date object to this format using the
130
- * standard
131
- * [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
132
- * method. In Python, a standard `datetime.datetime` object can be converted
133
- * to this format using
134
- * [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with
135
- * the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use
136
- * the Joda Time's [`ISODateTimeFormat.dateTime()`](
137
- * http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime()
138
- * ) to obtain a formatter capable of generating timestamps in this format.
139
- *
140
- *
141
- * @generated from protobuf message google.protobuf.Timestamp
142
- */
143
- export interface Timestamp {
144
- /**
145
- * Represents seconds of UTC time since Unix epoch
146
- * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
147
- * 9999-12-31T23:59:59Z inclusive.
148
- *
149
- * @generated from protobuf field: int64 seconds = 1;
150
- */
151
- seconds: number;
152
- /**
153
- * Non-negative fractions of a second at nanosecond resolution. Negative
154
- * second values with fractions must still have non-negative nanos values
155
- * that count forward in time. Must be from 0 to 999,999,999
156
- * inclusive.
157
- *
158
- * @generated from protobuf field: int32 nanos = 2;
159
- */
160
- nanos: number;
161
- }
162
- // @generated message type with reflection information, may provide speed optimized methods
163
- class Timestamp$Type extends MessageType<Timestamp> {
164
- constructor() {
165
- super("google.protobuf.Timestamp", [
166
- { no: 1, name: "seconds", kind: "scalar", T: 3 /*ScalarType.INT64*/, L: 2 /*LongType.NUMBER*/ },
167
- { no: 2, name: "nanos", kind: "scalar", T: 5 /*ScalarType.INT32*/ }
168
- ]);
169
- }
170
- /**
171
- * Creates a new `Timestamp` for the current time.
172
- */
173
- now(): Timestamp {
174
- const msg = this.create();
175
- const ms = Date.now();
176
- msg.seconds = PbLong.from(Math.floor(ms / 1000)).toNumber();
177
- msg.nanos = (ms % 1000) * 1000000;
178
- return msg;
179
- }
180
- /**
181
- * Converts a `Timestamp` to a JavaScript Date.
182
- */
183
- toDate(message: Timestamp): Date {
184
- return new Date(PbLong.from(message.seconds).toNumber() * 1000 + Math.ceil(message.nanos / 1000000));
185
- }
186
- /**
187
- * Converts a JavaScript Date to a `Timestamp`.
188
- */
189
- fromDate(date: Date): Timestamp {
190
- const msg = this.create();
191
- const ms = date.getTime();
192
- msg.seconds = PbLong.from(Math.floor(ms / 1000)).toNumber();
193
- msg.nanos = (ms % 1000) * 1000000;
194
- return msg;
195
- }
196
- /**
197
- * In JSON format, the `Timestamp` type is encoded as a string
198
- * in the RFC 3339 format.
199
- */
200
- internalJsonWrite(message: Timestamp, options: JsonWriteOptions): JsonValue {
201
- let ms = PbLong.from(message.seconds).toNumber() * 1000;
202
- if (ms < Date.parse("0001-01-01T00:00:00Z") || ms > Date.parse("9999-12-31T23:59:59Z"))
203
- throw new Error("Unable to encode Timestamp to JSON. Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive.");
204
- if (message.nanos < 0)
205
- throw new Error("Unable to encode invalid Timestamp to JSON. Nanos must not be negative.");
206
- let z = "Z";
207
- if (message.nanos > 0) {
208
- let nanosStr = (message.nanos + 1000000000).toString().substring(1);
209
- if (nanosStr.substring(3) === "000000")
210
- z = "." + nanosStr.substring(0, 3) + "Z";
211
- else if (nanosStr.substring(6) === "000")
212
- z = "." + nanosStr.substring(0, 6) + "Z";
213
- else
214
- z = "." + nanosStr + "Z";
215
- }
216
- return new Date(ms).toISOString().replace(".000Z", z);
217
- }
218
- /**
219
- * In JSON format, the `Timestamp` type is encoded as a string
220
- * in the RFC 3339 format.
221
- */
222
- internalJsonRead(json: JsonValue, options: JsonReadOptions, target?: Timestamp): Timestamp {
223
- if (typeof json !== "string")
224
- throw new Error("Unable to parse Timestamp from JSON " + typeofJsonValue(json) + ".");
225
- 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]))$/);
226
- if (!matches)
227
- throw new Error("Unable to parse Timestamp from JSON. Invalid format.");
228
- let ms = Date.parse(matches[1] + "-" + matches[2] + "-" + matches[3] + "T" + matches[4] + ":" + matches[5] + ":" + matches[6] + (matches[8] ? matches[8] : "Z"));
229
- if (Number.isNaN(ms))
230
- throw new Error("Unable to parse Timestamp from JSON. Invalid value.");
231
- if (ms < Date.parse("0001-01-01T00:00:00Z") || ms > Date.parse("9999-12-31T23:59:59Z"))
232
- 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.");
233
- if (!target)
234
- target = this.create();
235
- target.seconds = PbLong.from(ms / 1000).toNumber();
236
- target.nanos = 0;
237
- if (matches[7])
238
- target.nanos = (parseInt("1" + matches[7] + "0".repeat(9 - matches[7].length)) - 1000000000);
239
- return target;
240
- }
241
- create(value?: PartialMessage<Timestamp>): Timestamp {
242
- const message = globalThis.Object.create((this.messagePrototype!));
243
- message.seconds = 0;
244
- message.nanos = 0;
245
- if (value !== undefined)
246
- reflectionMergePartial<Timestamp>(this, message, value);
247
- return message;
248
- }
249
- internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: Timestamp): Timestamp {
250
- let message = target ?? this.create(), end = reader.pos + length;
251
- while (reader.pos < end) {
252
- let [fieldNo, wireType] = reader.tag();
253
- switch (fieldNo) {
254
- case /* int64 seconds */ 1:
255
- message.seconds = reader.int64().toNumber();
256
- break;
257
- case /* int32 nanos */ 2:
258
- message.nanos = reader.int32();
259
- break;
260
- default:
261
- let u = options.readUnknownField;
262
- if (u === "throw")
263
- throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
264
- let d = reader.skip(wireType);
265
- if (u !== false)
266
- (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
267
- }
268
- }
269
- return message;
270
- }
271
- internalBinaryWrite(message: Timestamp, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter {
272
- /* int64 seconds = 1; */
273
- if (message.seconds !== 0)
274
- writer.tag(1, WireType.Varint).int64(message.seconds);
275
- /* int32 nanos = 2; */
276
- if (message.nanos !== 0)
277
- writer.tag(2, WireType.Varint).int32(message.nanos);
278
- let u = options.writeUnknownFields;
279
- if (u !== false)
280
- (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
281
- return writer;
282
- }
283
- }
284
- /**
285
- * @generated MessageType for protobuf message google.protobuf.Timestamp
286
- */
287
- export const Timestamp = new Timestamp$Type();