@streamr/trackerless-network 101.1.2 → 102.0.0-beta.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 (244) hide show
  1. package/dist/{src/proto → generated}/google/protobuf/any.d.ts +11 -4
  2. package/dist/generated/google/protobuf/any.js.map +1 -0
  3. package/dist/{src/proto → generated}/google/protobuf/empty.d.ts +0 -1
  4. package/dist/generated/google/protobuf/empty.js.map +1 -0
  5. package/dist/{src/proto → generated}/google/protobuf/timestamp.d.ts +9 -3
  6. package/dist/generated/google/protobuf/timestamp.js.map +1 -0
  7. package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.client.d.ts +9 -0
  8. package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.client.js +7 -0
  9. package/dist/generated/packages/dht/protos/DhtRpc.client.js.map +1 -0
  10. package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.d.ts +32 -8
  11. package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.js +23 -7
  12. package/dist/generated/packages/dht/protos/DhtRpc.js.map +1 -0
  13. package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.server.d.ts +5 -0
  14. package/dist/generated/packages/dht/protos/DhtRpc.server.js.map +1 -0
  15. package/dist/generated/packages/proto-rpc/protos/ProtoRpc.js.map +1 -0
  16. package/dist/generated/packages/trackerless-network/protos/NetworkRpc.client.js.map +1 -0
  17. package/dist/{src/proto → generated}/packages/trackerless-network/protos/NetworkRpc.d.ts +29 -5
  18. package/dist/{src/proto → generated}/packages/trackerless-network/protos/NetworkRpc.js +17 -3
  19. package/dist/generated/packages/trackerless-network/protos/NetworkRpc.js.map +1 -0
  20. package/dist/generated/packages/trackerless-network/protos/NetworkRpc.server.js.map +1 -0
  21. package/dist/package.json +10 -11
  22. package/dist/src/NetworkNode.d.ts +8 -7
  23. package/dist/src/NetworkNode.js +5 -3
  24. package/dist/src/NetworkNode.js.map +1 -1
  25. package/dist/src/NetworkStack.d.ts +2 -2
  26. package/dist/src/NetworkStack.js +7 -6
  27. package/dist/src/NetworkStack.js.map +1 -1
  28. package/dist/src/exports.d.ts +3 -2
  29. package/dist/src/exports.js +3 -2
  30. package/dist/src/exports.js.map +1 -1
  31. package/dist/src/logic/ContentDeliveryLayerNode.d.ts +5 -1
  32. package/dist/src/logic/ContentDeliveryLayerNode.js +30 -10
  33. package/dist/src/logic/ContentDeliveryLayerNode.js.map +1 -1
  34. package/dist/src/logic/ContentDeliveryManager.d.ts +8 -3
  35. package/dist/src/logic/ContentDeliveryManager.js +28 -7
  36. package/dist/src/logic/ContentDeliveryManager.js.map +1 -1
  37. package/dist/src/logic/ContentDeliveryRpcLocal.d.ts +3 -3
  38. package/dist/src/logic/ContentDeliveryRpcLocal.js +3 -3
  39. package/dist/src/logic/ContentDeliveryRpcLocal.js.map +1 -1
  40. package/dist/src/logic/ContentDeliveryRpcRemote.d.ts +5 -2
  41. package/dist/src/logic/ContentDeliveryRpcRemote.js +7 -0
  42. package/dist/src/logic/ContentDeliveryRpcRemote.js.map +1 -1
  43. package/dist/src/logic/ControlLayerNode.d.ts +1 -1
  44. package/dist/src/logic/DiscoveryLayerNode.d.ts +3 -3
  45. package/dist/src/logic/DuplicateMessageDetector.js +3 -3
  46. package/dist/src/logic/DuplicateMessageDetector.js.map +1 -1
  47. package/dist/src/logic/ExternalNetworkRpc.js.map +1 -1
  48. package/dist/src/logic/NodeList.js +2 -2
  49. package/dist/src/logic/NodeList.js.map +1 -1
  50. package/dist/src/logic/PeerDescriptorStoreManager.d.ts +1 -1
  51. package/dist/src/logic/PeerDescriptorStoreManager.js +1 -2
  52. package/dist/src/logic/PeerDescriptorStoreManager.js.map +1 -1
  53. package/dist/src/logic/StreamPartNetworkSplitAvoidance.js +4 -3
  54. package/dist/src/logic/StreamPartNetworkSplitAvoidance.js.map +1 -1
  55. package/dist/src/logic/createContentDeliveryLayerNode.js +1 -1
  56. package/dist/src/logic/createContentDeliveryLayerNode.js.map +1 -1
  57. package/dist/src/logic/inspect/InspectSession.d.ts +2 -2
  58. package/dist/src/logic/inspect/InspectSession.js +2 -2
  59. package/dist/src/logic/inspect/InspectSession.js.map +1 -1
  60. package/dist/src/logic/inspect/Inspector.d.ts +1 -1
  61. package/dist/src/logic/inspect/Inspector.js +4 -4
  62. package/dist/src/logic/inspect/Inspector.js.map +1 -1
  63. package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.d.ts +2 -2
  64. package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.js +9 -9
  65. package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.js.map +1 -1
  66. package/dist/src/logic/neighbor-discovery/HandshakeRpcRemote.d.ts +2 -2
  67. package/dist/src/logic/neighbor-discovery/HandshakeRpcRemote.js +5 -5
  68. package/dist/src/logic/neighbor-discovery/HandshakeRpcRemote.js.map +1 -1
  69. package/dist/src/logic/neighbor-discovery/Handshaker.js +14 -14
  70. package/dist/src/logic/neighbor-discovery/Handshaker.js.map +1 -1
  71. package/dist/src/logic/neighbor-discovery/NeighborFinder.js +5 -0
  72. package/dist/src/logic/neighbor-discovery/NeighborFinder.js.map +1 -1
  73. package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.js +5 -3
  74. package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.js.map +1 -1
  75. package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.d.ts +2 -2
  76. package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.js +4 -4
  77. package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.js.map +1 -1
  78. package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcRemote.d.ts +1 -1
  79. package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcRemote.js +1 -1
  80. package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcRemote.js.map +1 -1
  81. package/dist/src/logic/node-info/NodeInfoClient.d.ts +1 -1
  82. package/dist/src/logic/node-info/NodeInfoClient.js +1 -1
  83. package/dist/src/logic/node-info/NodeInfoClient.js.map +1 -1
  84. package/dist/src/logic/node-info/NodeInfoRpcLocal.d.ts +2 -2
  85. package/dist/src/logic/node-info/NodeInfoRpcLocal.js +1 -1
  86. package/dist/src/logic/node-info/NodeInfoRpcLocal.js.map +1 -1
  87. package/dist/src/logic/node-info/NodeInfoRpcRemote.d.ts +2 -2
  88. package/dist/src/logic/propagation/Propagation.d.ts +1 -1
  89. package/dist/src/logic/propagation/Propagation.js +0 -1
  90. package/dist/src/logic/propagation/Propagation.js.map +1 -1
  91. package/dist/src/logic/propagation/PropagationTaskStore.d.ts +1 -1
  92. package/dist/src/logic/proxy/ProxyClient.d.ts +4 -4
  93. package/dist/src/logic/proxy/ProxyClient.js +11 -7
  94. package/dist/src/logic/proxy/ProxyClient.js.map +1 -1
  95. package/dist/src/logic/proxy/ProxyConnectionRpcLocal.d.ts +4 -4
  96. package/dist/src/logic/proxy/ProxyConnectionRpcLocal.js +5 -5
  97. package/dist/src/logic/proxy/ProxyConnectionRpcLocal.js.map +1 -1
  98. package/dist/src/logic/proxy/ProxyConnectionRpcRemote.d.ts +4 -4
  99. package/dist/src/logic/proxy/ProxyConnectionRpcRemote.js +1 -1
  100. package/dist/src/logic/proxy/ProxyConnectionRpcRemote.js.map +1 -1
  101. package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.d.ts +4 -4
  102. package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js +4 -4
  103. package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js.map +1 -1
  104. package/dist/src/logic/temporary-connection/TemporaryConnectionRpcRemote.d.ts +1 -1
  105. package/dist/src/logic/temporary-connection/TemporaryConnectionRpcRemote.js +2 -2
  106. package/dist/src/logic/temporary-connection/TemporaryConnectionRpcRemote.js.map +1 -1
  107. package/dist/src/logic/utils.d.ts +1 -1
  108. package/dist/src/logic/utils.js +2 -2
  109. package/dist/src/logic/utils.js.map +1 -1
  110. package/dist/src/types.d.ts +6 -0
  111. package/dist/src/types.js +3 -0
  112. package/dist/src/types.js.map +1 -0
  113. package/dist/test/benchmark/first-message.js +3 -4
  114. package/dist/test/benchmark/first-message.js.map +1 -1
  115. package/dist/test/utils/utils.d.ts +4 -4
  116. package/dist/test/utils/utils.js +6 -5
  117. package/dist/test/utils/utils.js.map +1 -1
  118. package/jest.config.ts +13 -0
  119. package/karma-setup.js +7 -0
  120. package/karma.config.js +1 -1
  121. package/package.json +10 -11
  122. package/proto.sh +2 -2
  123. package/protos/NetworkRpc.proto +9 -4
  124. package/src/NetworkNode.ts +12 -9
  125. package/src/NetworkStack.ts +10 -10
  126. package/src/exports.ts +5 -3
  127. package/src/logic/ContentDeliveryLayerNode.ts +35 -11
  128. package/src/logic/ContentDeliveryManager.ts +41 -13
  129. package/src/logic/ContentDeliveryRpcLocal.ts +6 -6
  130. package/src/logic/ContentDeliveryRpcRemote.ts +12 -2
  131. package/src/logic/ControlLayerNode.ts +1 -1
  132. package/src/logic/DiscoveryLayerNode.ts +3 -3
  133. package/src/logic/DuplicateMessageDetector.ts +4 -4
  134. package/src/logic/ExternalNetworkRpc.ts +0 -1
  135. package/src/logic/NodeList.ts +4 -3
  136. package/src/logic/PeerDescriptorStoreManager.ts +1 -2
  137. package/src/logic/StreamPartNetworkSplitAvoidance.ts +5 -4
  138. package/src/logic/createContentDeliveryLayerNode.ts +3 -3
  139. package/src/logic/inspect/InspectSession.ts +5 -4
  140. package/src/logic/inspect/Inspector.ts +6 -6
  141. package/src/logic/neighbor-discovery/HandshakeRpcLocal.ts +13 -13
  142. package/src/logic/neighbor-discovery/HandshakeRpcRemote.ts +8 -8
  143. package/src/logic/neighbor-discovery/Handshaker.ts +15 -15
  144. package/src/logic/neighbor-discovery/NeighborFinder.ts +6 -1
  145. package/src/logic/neighbor-discovery/NeighborUpdateManager.ts +6 -4
  146. package/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.ts +7 -7
  147. package/src/logic/neighbor-discovery/NeighborUpdateRpcRemote.ts +4 -4
  148. package/src/logic/node-info/NodeInfoClient.ts +2 -2
  149. package/src/logic/node-info/NodeInfoRpcLocal.ts +2 -2
  150. package/src/logic/node-info/NodeInfoRpcRemote.ts +2 -2
  151. package/src/logic/propagation/Propagation.ts +1 -2
  152. package/src/logic/propagation/PropagationTaskStore.ts +1 -1
  153. package/src/logic/proxy/ProxyClient.ts +17 -12
  154. package/src/logic/proxy/ProxyConnectionRpcLocal.ts +10 -10
  155. package/src/logic/proxy/ProxyConnectionRpcRemote.ts +5 -5
  156. package/src/logic/temporary-connection/TemporaryConnectionRpcLocal.ts +9 -9
  157. package/src/logic/temporary-connection/TemporaryConnectionRpcRemote.ts +4 -4
  158. package/src/logic/utils.ts +4 -4
  159. package/src/types.ts +13 -0
  160. package/test/benchmark/first-message.ts +6 -5
  161. package/test/end-to-end/content-delivery-layer-node-with-real-connections.test.ts +11 -6
  162. package/test/end-to-end/external-network-rpc.test.ts +2 -2
  163. package/test/end-to-end/inspect.test.ts +5 -5
  164. package/test/end-to-end/proxy-and-full-node.test.ts +6 -6
  165. package/test/end-to-end/proxy-connections.test.ts +12 -14
  166. package/test/end-to-end/proxy-key-exchange.test.ts +11 -9
  167. package/test/end-to-end/webrtc-full-node-network.test.ts +7 -9
  168. package/test/end-to-end/websocket-full-node-network.test.ts +8 -10
  169. package/test/integration/ContentDeliveryLayerNode-Layer1Node-Latencies.test.ts +11 -11
  170. package/test/integration/ContentDeliveryLayerNode-Layer1Node.test.ts +10 -10
  171. package/test/integration/ContentDeliveryManager.test.ts +49 -25
  172. package/test/integration/ContentDeliveryRpcRemote.test.ts +8 -8
  173. package/test/integration/HandshakeRpcRemote.test.ts +2 -2
  174. package/test/integration/Handshakes.test.ts +21 -56
  175. package/test/integration/Inspect.test.ts +2 -2
  176. package/test/integration/NeighborUpdateRpcRemote.test.ts +2 -2
  177. package/test/integration/NetworkNode.test.ts +5 -4
  178. package/test/integration/NetworkRpc.test.ts +10 -10
  179. package/test/integration/NetworkStack.test.ts +4 -4
  180. package/test/integration/NodeInfoRpc.test.ts +9 -5
  181. package/test/integration/Propagation.test.ts +6 -6
  182. package/test/integration/joining-streams-on-offline-peers.test.ts +5 -5
  183. package/test/integration/stream-without-default-entrypoints.test.ts +8 -7
  184. package/test/integration/streamEntryPointReplacing.test.ts +5 -5
  185. package/test/types/global.d.ts +1 -0
  186. package/test/unit/ContentDeliveryLayerNode.test.ts +26 -14
  187. package/test/unit/ContentDeliveryManager.test.ts +10 -9
  188. package/test/unit/ContentDeliveryRpcLocal.test.ts +3 -3
  189. package/test/unit/DuplicateMessageDetector.test.ts +10 -10
  190. package/test/unit/ExternalNetworkRpc.test.ts +3 -3
  191. package/test/unit/HandshakeRpcLocal.test.ts +8 -21
  192. package/test/unit/Handshaker.test.ts +2 -2
  193. package/test/unit/InspectSession.test.ts +7 -4
  194. package/test/unit/Inspector.test.ts +5 -5
  195. package/test/unit/NeighborFinder.test.ts +5 -5
  196. package/test/unit/NeighborUpdateRpcLocal.test.ts +6 -6
  197. package/test/unit/NetworkNode.test.ts +5 -5
  198. package/test/unit/NodeList.test.ts +23 -23
  199. package/test/unit/PeerDescriptorStoreManager.test.ts +4 -4
  200. package/test/unit/Propagation.test.ts +8 -7
  201. package/test/unit/ProxyConnectionRpcRemote.test.ts +5 -5
  202. package/test/unit/StreamPartReconnect.test.ts +2 -2
  203. package/test/unit/TemporaryConnectionRpcLocal.test.ts +3 -3
  204. package/test/utils/mock/MockControlLayerNode.ts +5 -0
  205. package/test/utils/mock/MockNeighborUpdateManager.ts +1 -1
  206. package/test/utils/mock/MockTransport.ts +11 -0
  207. package/test/utils/utils.ts +10 -9
  208. package/tsconfig.browser.json +1 -0
  209. package/tsconfig.jest.json +2 -1
  210. package/tsconfig.json +3 -0
  211. package/tsconfig.node.json +1 -0
  212. package/.eslintignore +0 -7
  213. package/.eslintrc +0 -3
  214. package/dist/src/proto/google/protobuf/any.js.map +0 -1
  215. package/dist/src/proto/google/protobuf/empty.js.map +0 -1
  216. package/dist/src/proto/google/protobuf/timestamp.js.map +0 -1
  217. package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +0 -1
  218. package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +0 -1
  219. package/dist/src/proto/packages/dht/protos/DhtRpc.server.js.map +0 -1
  220. package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js.map +0 -1
  221. package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.client.js.map +0 -1
  222. package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.js.map +0 -1
  223. package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.server.js.map +0 -1
  224. package/jest.config.js +0 -5
  225. package/src/proto/google/protobuf/any.ts +0 -319
  226. package/src/proto/google/protobuf/empty.ts +0 -82
  227. package/src/proto/google/protobuf/timestamp.ts +0 -281
  228. package/src/proto/packages/dht/protos/DhtRpc.client.ts +0 -407
  229. package/src/proto/packages/dht/protos/DhtRpc.server.ts +0 -160
  230. package/src/proto/packages/dht/protos/DhtRpc.ts +0 -1244
  231. package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +0 -108
  232. package/src/proto/packages/trackerless-network/protos/NetworkRpc.client.ts +0 -218
  233. package/src/proto/packages/trackerless-network/protos/NetworkRpc.server.ts +0 -85
  234. package/src/proto/packages/trackerless-network/protos/NetworkRpc.ts +0 -752
  235. /package/dist/{src/proto → generated}/google/protobuf/any.js +0 -0
  236. /package/dist/{src/proto → generated}/google/protobuf/empty.js +0 -0
  237. /package/dist/{src/proto → generated}/google/protobuf/timestamp.js +0 -0
  238. /package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.server.js +0 -0
  239. /package/dist/{src/proto → generated}/packages/proto-rpc/protos/ProtoRpc.d.ts +0 -0
  240. /package/dist/{src/proto → generated}/packages/proto-rpc/protos/ProtoRpc.js +0 -0
  241. /package/dist/{src/proto → generated}/packages/trackerless-network/protos/NetworkRpc.client.d.ts +0 -0
  242. /package/dist/{src/proto → generated}/packages/trackerless-network/protos/NetworkRpc.client.js +0 -0
  243. /package/dist/{src/proto → generated}/packages/trackerless-network/protos/NetworkRpc.server.d.ts +0 -0
  244. /package/dist/{src/proto → generated}/packages/trackerless-network/protos/NetworkRpc.server.js +0 -0
@@ -1,319 +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/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 { isJsonObject } from "@protobuf-ts/runtime";
43
- import { typeofJsonValue } from "@protobuf-ts/runtime";
44
- import type { JsonValue } from "@protobuf-ts/runtime";
45
- import { jsonWriteOptions } from "@protobuf-ts/runtime";
46
- import type { JsonReadOptions } from "@protobuf-ts/runtime";
47
- import type { JsonWriteOptions } from "@protobuf-ts/runtime";
48
- import type { BinaryReadOptions } from "@protobuf-ts/runtime";
49
- import type { IMessageType } from "@protobuf-ts/runtime";
50
- import { MessageType } from "@protobuf-ts/runtime";
51
- /**
52
- * `Any` contains an arbitrary serialized protocol buffer message along with a
53
- * URL that describes the type of the serialized message.
54
- *
55
- * Protobuf library provides support to pack/unpack Any values in the form
56
- * of utility functions or additional generated methods of the Any type.
57
- *
58
- * Example 1: Pack and unpack a message in C++.
59
- *
60
- * Foo foo = ...;
61
- * Any any;
62
- * any.PackFrom(foo);
63
- * ...
64
- * if (any.UnpackTo(&foo)) {
65
- * ...
66
- * }
67
- *
68
- * Example 2: Pack and unpack a message in Java.
69
- *
70
- * Foo foo = ...;
71
- * Any any = Any.pack(foo);
72
- * ...
73
- * if (any.is(Foo.class)) {
74
- * foo = any.unpack(Foo.class);
75
- * }
76
- *
77
- * Example 3: Pack and unpack a message in Python.
78
- *
79
- * foo = Foo(...)
80
- * any = Any()
81
- * any.Pack(foo)
82
- * ...
83
- * if any.Is(Foo.DESCRIPTOR):
84
- * any.Unpack(foo)
85
- * ...
86
- *
87
- * Example 4: Pack and unpack a message in Go
88
- *
89
- * foo := &pb.Foo{...}
90
- * any, err := ptypes.MarshalAny(foo)
91
- * ...
92
- * foo := &pb.Foo{}
93
- * if err := ptypes.UnmarshalAny(any, foo); err != nil {
94
- * ...
95
- * }
96
- *
97
- * The pack methods provided by protobuf library will by default use
98
- * 'type.googleapis.com/full.type.name' as the type URL and the unpack
99
- * methods only use the fully qualified type name after the last '/'
100
- * in the type URL, for example "foo.bar.com/x/y.z" will yield type
101
- * name "y.z".
102
- *
103
- *
104
- * JSON
105
- * ====
106
- * The JSON representation of an `Any` value uses the regular
107
- * representation of the deserialized, embedded message, with an
108
- * additional field `@type` which contains the type URL. Example:
109
- *
110
- * package google.profile;
111
- * message Person {
112
- * string first_name = 1;
113
- * string last_name = 2;
114
- * }
115
- *
116
- * {
117
- * "@type": "type.googleapis.com/google.profile.Person",
118
- * "firstName": <string>,
119
- * "lastName": <string>
120
- * }
121
- *
122
- * If the embedded message type is well-known and has a custom JSON
123
- * representation, that representation will be embedded adding a field
124
- * `value` which holds the custom JSON in addition to the `@type`
125
- * field. Example (for message [google.protobuf.Duration][]):
126
- *
127
- * {
128
- * "@type": "type.googleapis.com/google.protobuf.Duration",
129
- * "value": "1.212s"
130
- * }
131
- *
132
- *
133
- * @generated from protobuf message google.protobuf.Any
134
- */
135
- export interface Any {
136
- /**
137
- * A URL/resource name that uniquely identifies the type of the serialized
138
- * protocol buffer message. This string must contain at least
139
- * one "/" character. The last segment of the URL's path must represent
140
- * the fully qualified name of the type (as in
141
- * `path/google.protobuf.Duration`). The name should be in a canonical form
142
- * (e.g., leading "." is not accepted).
143
- *
144
- * In practice, teams usually precompile into the binary all types that they
145
- * expect it to use in the context of Any. However, for URLs which use the
146
- * scheme `http`, `https`, or no scheme, one can optionally set up a type
147
- * server that maps type URLs to message definitions as follows:
148
- *
149
- * * If no scheme is provided, `https` is assumed.
150
- * * An HTTP GET on the URL must yield a [google.protobuf.Type][]
151
- * value in binary format, or produce an error.
152
- * * Applications are allowed to cache lookup results based on the
153
- * URL, or have them precompiled into a binary to avoid any
154
- * lookup. Therefore, binary compatibility needs to be preserved
155
- * on changes to types. (Use versioned type names to manage
156
- * breaking changes.)
157
- *
158
- * Note: this functionality is not currently available in the official
159
- * protobuf release, and it is not used for type URLs beginning with
160
- * type.googleapis.com.
161
- *
162
- * Schemes other than `http`, `https` (or the empty scheme) might be
163
- * used with implementation specific semantics.
164
- *
165
- *
166
- * @generated from protobuf field: string type_url = 1;
167
- */
168
- typeUrl: string;
169
- /**
170
- * Must be a valid serialized protocol buffer of the above specified type.
171
- *
172
- * @generated from protobuf field: bytes value = 2;
173
- */
174
- value: Uint8Array;
175
- }
176
- // @generated message type with reflection information, may provide speed optimized methods
177
- class Any$Type extends MessageType<Any> {
178
- constructor() {
179
- super("google.protobuf.Any", [
180
- { no: 1, name: "type_url", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
181
- { no: 2, name: "value", kind: "scalar", T: 12 /*ScalarType.BYTES*/ }
182
- ]);
183
- }
184
- /**
185
- * Pack the message into a new `Any`.
186
- *
187
- * Uses 'type.googleapis.com/full.type.name' as the type URL.
188
- */
189
- pack<T extends object>(message: T, type: IMessageType<T>): Any {
190
- return {
191
- typeUrl: this.typeNameToUrl(type.typeName), value: type.toBinary(message),
192
- };
193
- }
194
- /**
195
- * Unpack the message from the `Any`.
196
- */
197
- unpack<T extends object>(any: Any, type: IMessageType<T>, options?: Partial<BinaryReadOptions>): T {
198
- if (!this.contains(any, type))
199
- throw new Error("Cannot unpack google.protobuf.Any with typeUrl '" + any.typeUrl + "' as " + type.typeName + ".");
200
- return type.fromBinary(any.value, options);
201
- }
202
- /**
203
- * Does the given `Any` contain a packed message of the given type?
204
- */
205
- contains(any: Any, type: IMessageType<any> | string): boolean {
206
- if (!any.typeUrl.length)
207
- return false;
208
- let wants = typeof type == "string" ? type : type.typeName;
209
- let has = this.typeUrlToName(any.typeUrl);
210
- return wants === has;
211
- }
212
- /**
213
- * Convert the message to canonical JSON value.
214
- *
215
- * You have to provide the `typeRegistry` option so that the
216
- * packed message can be converted to JSON.
217
- *
218
- * The `typeRegistry` option is also required to read
219
- * `google.protobuf.Any` from JSON format.
220
- */
221
- internalJsonWrite(any: Any, options: JsonWriteOptions): JsonValue {
222
- if (any.typeUrl === "")
223
- return {};
224
- let typeName = this.typeUrlToName(any.typeUrl);
225
- let opt = jsonWriteOptions(options);
226
- let type = opt.typeRegistry?.find(t => t.typeName === typeName);
227
- if (!type)
228
- 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.");
229
- let value = type.fromBinary(any.value, { readUnknownField: false });
230
- let json = type.internalJsonWrite(value, opt);
231
- if (typeName.startsWith("google.protobuf.") || !isJsonObject(json))
232
- json = { value: json };
233
- json["@type"] = any.typeUrl;
234
- return json;
235
- }
236
- internalJsonRead(json: JsonValue, options: JsonReadOptions, target?: Any): Any {
237
- if (!isJsonObject(json))
238
- throw new globalThis.Error("Unable to parse google.protobuf.Any from JSON " + typeofJsonValue(json) + ".");
239
- if (typeof json["@type"] != "string" || json["@type"] == "")
240
- return this.create();
241
- let typeName = this.typeUrlToName(json["@type"]);
242
- let type = options?.typeRegistry?.find(t => t.typeName == typeName);
243
- if (!type)
244
- throw new globalThis.Error("Unable to parse google.protobuf.Any from JSON. The specified type " + typeName + " is not available in the type registry.");
245
- let value;
246
- if (typeName.startsWith("google.protobuf.") && json.hasOwnProperty("value"))
247
- value = type.fromJson(json["value"], options);
248
- else {
249
- let copy = Object.assign({}, json);
250
- delete copy["@type"];
251
- value = type.fromJson(copy, options);
252
- }
253
- if (target === undefined)
254
- target = this.create();
255
- target.typeUrl = json["@type"];
256
- target.value = type.toBinary(value);
257
- return target;
258
- }
259
- typeNameToUrl(name: string): string {
260
- if (!name.length)
261
- throw new Error("invalid type name: " + name);
262
- return "type.googleapis.com/" + name;
263
- }
264
- typeUrlToName(url: string): string {
265
- if (!url.length)
266
- throw new Error("invalid type url: " + url);
267
- let slash = url.lastIndexOf("/");
268
- let name = slash > 0 ? url.substring(slash + 1) : url;
269
- if (!name.length)
270
- throw new Error("invalid type url: " + url);
271
- return name;
272
- }
273
- create(value?: PartialMessage<Any>): Any {
274
- const message = globalThis.Object.create((this.messagePrototype!));
275
- message.typeUrl = "";
276
- message.value = new Uint8Array(0);
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();
@@ -1,82 +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/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 { MessageType } from "@protobuf-ts/runtime";
43
- /**
44
- * A generic empty message that you can re-use to avoid defining duplicated
45
- * empty messages in your APIs. A typical example is to use it as the request
46
- * or the response type of an API method. For instance:
47
- *
48
- * service Foo {
49
- * rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);
50
- * }
51
- *
52
- * The JSON representation for `Empty` is empty JSON object `{}`.
53
- *
54
- * @generated from protobuf message google.protobuf.Empty
55
- */
56
- export interface Empty {
57
- }
58
- // @generated message type with reflection information, may provide speed optimized methods
59
- class Empty$Type extends MessageType<Empty> {
60
- constructor() {
61
- super("google.protobuf.Empty", []);
62
- }
63
- create(value?: PartialMessage<Empty>): Empty {
64
- const message = globalThis.Object.create((this.messagePrototype!));
65
- if (value !== undefined)
66
- reflectionMergePartial<Empty>(this, message, value);
67
- return message;
68
- }
69
- internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: Empty): Empty {
70
- return target ?? this.create();
71
- }
72
- internalBinaryWrite(message: Empty, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter {
73
- let u = options.writeUnknownFields;
74
- if (u !== false)
75
- (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
76
- return writer;
77
- }
78
- }
79
- /**
80
- * @generated MessageType for protobuf message google.protobuf.Empty
81
- */
82
- export const Empty = new Empty$Type();
@@ -1,281 +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
- *
101
- * Example 5: Compute Timestamp from current time in Python.
102
- *
103
- * timestamp = Timestamp()
104
- * timestamp.GetCurrentTime()
105
- *
106
- * # JSON Mapping
107
- *
108
- * In JSON format, the Timestamp type is encoded as a string in the
109
- * [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the
110
- * format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z"
111
- * where {year} is always expressed using four digits while {month}, {day},
112
- * {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional
113
- * seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution),
114
- * are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone
115
- * is required. A proto3 JSON serializer should always use UTC (as indicated by
116
- * "Z") when printing the Timestamp type and a proto3 JSON parser should be
117
- * able to accept both UTC and other timezones (as indicated by an offset).
118
- *
119
- * For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past
120
- * 01:30 UTC on January 15, 2017.
121
- *
122
- * In JavaScript, one can convert a Date object to this format using the
123
- * standard
124
- * [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
125
- * method. In Python, a standard `datetime.datetime` object can be converted
126
- * to this format using
127
- * [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with
128
- * the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use
129
- * the Joda Time's [`ISODateTimeFormat.dateTime()`](
130
- * http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D
131
- * ) to obtain a formatter capable of generating timestamps in this format.
132
- *
133
- *
134
- *
135
- * @generated from protobuf message google.protobuf.Timestamp
136
- */
137
- export interface Timestamp {
138
- /**
139
- * Represents seconds of UTC time since Unix epoch
140
- * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
141
- * 9999-12-31T23:59:59Z inclusive.
142
- *
143
- * @generated from protobuf field: int64 seconds = 1;
144
- */
145
- seconds: number;
146
- /**
147
- * Non-negative fractions of a second at nanosecond resolution. Negative
148
- * second values with fractions must still have non-negative nanos values
149
- * that count forward in time. Must be from 0 to 999,999,999
150
- * inclusive.
151
- *
152
- * @generated from protobuf field: int32 nanos = 2;
153
- */
154
- nanos: number;
155
- }
156
- // @generated message type with reflection information, may provide speed optimized methods
157
- class Timestamp$Type extends MessageType<Timestamp> {
158
- constructor() {
159
- super("google.protobuf.Timestamp", [
160
- { no: 1, name: "seconds", kind: "scalar", T: 3 /*ScalarType.INT64*/, L: 2 /*LongType.NUMBER*/ },
161
- { no: 2, name: "nanos", kind: "scalar", T: 5 /*ScalarType.INT32*/ }
162
- ]);
163
- }
164
- /**
165
- * Creates a new `Timestamp` for the current time.
166
- */
167
- now(): Timestamp {
168
- const msg = this.create();
169
- const ms = Date.now();
170
- msg.seconds = PbLong.from(Math.floor(ms / 1000)).toNumber();
171
- msg.nanos = (ms % 1000) * 1000000;
172
- return msg;
173
- }
174
- /**
175
- * Converts a `Timestamp` to a JavaScript Date.
176
- */
177
- toDate(message: Timestamp): Date {
178
- return new Date(PbLong.from(message.seconds).toNumber() * 1000 + Math.ceil(message.nanos / 1000000));
179
- }
180
- /**
181
- * Converts a JavaScript Date to a `Timestamp`.
182
- */
183
- fromDate(date: Date): Timestamp {
184
- const msg = this.create();
185
- const ms = date.getTime();
186
- msg.seconds = PbLong.from(Math.floor(ms / 1000)).toNumber();
187
- msg.nanos = (ms % 1000) * 1000000;
188
- return msg;
189
- }
190
- /**
191
- * In JSON format, the `Timestamp` type is encoded as a string
192
- * in the RFC 3339 format.
193
- */
194
- internalJsonWrite(message: Timestamp, options: JsonWriteOptions): JsonValue {
195
- let ms = PbLong.from(message.seconds).toNumber() * 1000;
196
- if (ms < Date.parse("0001-01-01T00:00:00Z") || ms > Date.parse("9999-12-31T23:59:59Z"))
197
- throw new Error("Unable to encode Timestamp to JSON. Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive.");
198
- if (message.nanos < 0)
199
- throw new Error("Unable to encode invalid Timestamp to JSON. Nanos must not be negative.");
200
- let z = "Z";
201
- if (message.nanos > 0) {
202
- let nanosStr = (message.nanos + 1000000000).toString().substring(1);
203
- if (nanosStr.substring(3) === "000000")
204
- z = "." + nanosStr.substring(0, 3) + "Z";
205
- else if (nanosStr.substring(6) === "000")
206
- z = "." + nanosStr.substring(0, 6) + "Z";
207
- else
208
- z = "." + nanosStr + "Z";
209
- }
210
- return new Date(ms).toISOString().replace(".000Z", z);
211
- }
212
- /**
213
- * In JSON format, the `Timestamp` type is encoded as a string
214
- * in the RFC 3339 format.
215
- */
216
- internalJsonRead(json: JsonValue, options: JsonReadOptions, target?: Timestamp): Timestamp {
217
- if (typeof json !== "string")
218
- throw new Error("Unable to parse Timestamp from JSON " + typeofJsonValue(json) + ".");
219
- 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]))$/);
220
- if (!matches)
221
- throw new Error("Unable to parse Timestamp from JSON. Invalid format.");
222
- let ms = Date.parse(matches[1] + "-" + matches[2] + "-" + matches[3] + "T" + matches[4] + ":" + matches[5] + ":" + matches[6] + (matches[8] ? matches[8] : "Z"));
223
- if (Number.isNaN(ms))
224
- throw new Error("Unable to parse Timestamp from JSON. Invalid value.");
225
- if (ms < Date.parse("0001-01-01T00:00:00Z") || ms > Date.parse("9999-12-31T23:59:59Z"))
226
- 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.");
227
- if (!target)
228
- target = this.create();
229
- target.seconds = PbLong.from(ms / 1000).toNumber();
230
- target.nanos = 0;
231
- if (matches[7])
232
- target.nanos = (parseInt("1" + matches[7] + "0".repeat(9 - matches[7].length)) - 1000000000);
233
- return target;
234
- }
235
- create(value?: PartialMessage<Timestamp>): Timestamp {
236
- const message = globalThis.Object.create((this.messagePrototype!));
237
- message.seconds = 0;
238
- message.nanos = 0;
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();