@streamr/node 100.0.0-rc.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 (238) hide show
  1. package/LICENSE +78 -0
  2. package/README.md +54 -0
  3. package/bin/broker.ts +36 -0
  4. package/bin/config-wizard.js +4 -0
  5. package/bin/config-wizard.ts +17 -0
  6. package/bin/delete-expired-data.ts +41 -0
  7. package/bin/entry-point.ts +27 -0
  8. package/configs/development-1.env.json +68 -0
  9. package/configs/development-2.env.json +53 -0
  10. package/configs/development-3.env.json +53 -0
  11. package/configs/development-prod-resend.env.json +21 -0
  12. package/configs/docker-1.env.json +72 -0
  13. package/configs/docker-2.env.json +58 -0
  14. package/configs/docker-3.env.json +58 -0
  15. package/configuration.md +38 -0
  16. package/dist/bin/broker.d.ts +2 -0
  17. package/dist/bin/broker.js +42 -0
  18. package/dist/bin/broker.js.map +1 -0
  19. package/dist/bin/config-wizard.d.ts +2 -0
  20. package/dist/bin/config-wizard.js +22 -0
  21. package/dist/bin/config-wizard.js.map +1 -0
  22. package/dist/bin/delete-expired-data.d.ts +2 -0
  23. package/dist/bin/delete-expired-data.js +44 -0
  24. package/dist/bin/delete-expired-data.js.map +1 -0
  25. package/dist/bin/entry-point.d.ts +2 -0
  26. package/dist/bin/entry-point.js +28 -0
  27. package/dist/bin/entry-point.js.map +1 -0
  28. package/dist/package.json +78 -0
  29. package/dist/src/Plugin.d.ts +33 -0
  30. package/dist/src/Plugin.js +43 -0
  31. package/dist/src/Plugin.js.map +1 -0
  32. package/dist/src/apiAuthentication.d.ts +4 -0
  33. package/dist/src/apiAuthentication.js +16 -0
  34. package/dist/src/apiAuthentication.js.map +1 -0
  35. package/dist/src/broker.d.ts +8 -0
  36. package/dist/src/broker.js +69 -0
  37. package/dist/src/broker.js.map +1 -0
  38. package/dist/src/config/ConfigWizard.d.ts +5 -0
  39. package/dist/src/config/ConfigWizard.js +466 -0
  40. package/dist/src/config/ConfigWizard.js.map +1 -0
  41. package/dist/src/config/config.d.ts +26 -0
  42. package/dist/src/config/config.js +92 -0
  43. package/dist/src/config/config.js.map +1 -0
  44. package/dist/src/config/config.schema.json +86 -0
  45. package/dist/src/config/definitions.schema.json +35 -0
  46. package/dist/src/config/migration.d.ts +6 -0
  47. package/dist/src/config/migration.js +210 -0
  48. package/dist/src/config/migration.js.map +1 -0
  49. package/dist/src/config/validateConfig.d.ts +4 -0
  50. package/dist/src/config/validateConfig.js +40 -0
  51. package/dist/src/config/validateConfig.js.map +1 -0
  52. package/dist/src/exports.d.ts +3 -0
  53. package/dist/src/exports.js +6 -0
  54. package/dist/src/exports.js.map +1 -0
  55. package/dist/src/helpers/PayloadFormat.d.ts +19 -0
  56. package/dist/src/helpers/PayloadFormat.js +85 -0
  57. package/dist/src/helpers/PayloadFormat.js.map +1 -0
  58. package/dist/src/helpers/applyPluginClientConfigs.d.ts +3 -0
  59. package/dist/src/helpers/applyPluginClientConfigs.js +29 -0
  60. package/dist/src/helpers/applyPluginClientConfigs.js.map +1 -0
  61. package/dist/src/helpers/fetchOrThrow.d.ts +2 -0
  62. package/dist/src/helpers/fetchOrThrow.js +20 -0
  63. package/dist/src/helpers/fetchOrThrow.js.map +1 -0
  64. package/dist/src/helpers/generateMnemonicFromAddress.d.ts +5 -0
  65. package/dist/src/helpers/generateMnemonicFromAddress.js +16 -0
  66. package/dist/src/helpers/generateMnemonicFromAddress.js.map +1 -0
  67. package/dist/src/helpers/multiply.d.ts +1 -0
  68. package/dist/src/helpers/multiply.js +10 -0
  69. package/dist/src/helpers/multiply.js.map +1 -0
  70. package/dist/src/helpers/parser.d.ts +9 -0
  71. package/dist/src/helpers/parser.js +62 -0
  72. package/dist/src/helpers/parser.js.map +1 -0
  73. package/dist/src/helpers/partitions.d.ts +8 -0
  74. package/dist/src/helpers/partitions.js +32 -0
  75. package/dist/src/helpers/partitions.js.map +1 -0
  76. package/dist/src/helpers/weightedSample.d.ts +16 -0
  77. package/dist/src/helpers/weightedSample.js +35 -0
  78. package/dist/src/helpers/weightedSample.js.map +1 -0
  79. package/dist/src/httpServer.d.ts +16 -0
  80. package/dist/src/httpServer.js +71 -0
  81. package/dist/src/httpServer.js.map +1 -0
  82. package/dist/src/pluginRegistry.d.ts +3 -0
  83. package/dist/src/pluginRegistry.js +35 -0
  84. package/dist/src/pluginRegistry.js.map +1 -0
  85. package/dist/src/plugins/consoleMetrics/ConsoleMetricsPlugin.d.ts +12 -0
  86. package/dist/src/plugins/consoleMetrics/ConsoleMetricsPlugin.js +36 -0
  87. package/dist/src/plugins/consoleMetrics/ConsoleMetricsPlugin.js.map +1 -0
  88. package/dist/src/plugins/consoleMetrics/config.schema.json +18 -0
  89. package/dist/src/plugins/http/HttpPlugin.d.ts +8 -0
  90. package/dist/src/plugins/http/HttpPlugin.js +23 -0
  91. package/dist/src/plugins/http/HttpPlugin.js.map +1 -0
  92. package/dist/src/plugins/http/config.schema.json +12 -0
  93. package/dist/src/plugins/http/publishEndpoint.d.ts +3 -0
  94. package/dist/src/plugins/http/publishEndpoint.js +72 -0
  95. package/dist/src/plugins/http/publishEndpoint.js.map +1 -0
  96. package/dist/src/plugins/info/InfoPlugin.d.ts +9 -0
  97. package/dist/src/plugins/info/InfoPlugin.js +31 -0
  98. package/dist/src/plugins/info/InfoPlugin.js.map +1 -0
  99. package/dist/src/plugins/info/config.schema.json +12 -0
  100. package/dist/src/plugins/mqtt/Bridge.d.ts +40 -0
  101. package/dist/src/plugins/mqtt/Bridge.js +136 -0
  102. package/dist/src/plugins/mqtt/Bridge.js.map +1 -0
  103. package/dist/src/plugins/mqtt/MqttPlugin.d.ts +14 -0
  104. package/dist/src/plugins/mqtt/MqttPlugin.js +30 -0
  105. package/dist/src/plugins/mqtt/MqttPlugin.js.map +1 -0
  106. package/dist/src/plugins/mqtt/MqttServer.d.ts +22 -0
  107. package/dist/src/plugins/mqtt/MqttServer.js +109 -0
  108. package/dist/src/plugins/mqtt/MqttServer.js.map +1 -0
  109. package/dist/src/plugins/mqtt/config.schema.json +26 -0
  110. package/dist/src/plugins/operator/ConsistentHashRing.d.ts +20 -0
  111. package/dist/src/plugins/operator/ConsistentHashRing.js +64 -0
  112. package/dist/src/plugins/operator/ConsistentHashRing.js.map +1 -0
  113. package/dist/src/plugins/operator/ContractFacade.d.ts +80 -0
  114. package/dist/src/plugins/operator/ContractFacade.js +364 -0
  115. package/dist/src/plugins/operator/ContractFacade.js.map +1 -0
  116. package/dist/src/plugins/operator/MaintainTopologyHelper.d.ts +23 -0
  117. package/dist/src/plugins/operator/MaintainTopologyHelper.js +75 -0
  118. package/dist/src/plugins/operator/MaintainTopologyHelper.js.map +1 -0
  119. package/dist/src/plugins/operator/MaintainTopologyService.d.ts +11 -0
  120. package/dist/src/plugins/operator/MaintainTopologyService.js +57 -0
  121. package/dist/src/plugins/operator/MaintainTopologyService.js.map +1 -0
  122. package/dist/src/plugins/operator/OperatorFleetState.d.ts +33 -0
  123. package/dist/src/plugins/operator/OperatorFleetState.js +112 -0
  124. package/dist/src/plugins/operator/OperatorFleetState.js.map +1 -0
  125. package/dist/src/plugins/operator/OperatorPlugin.d.ts +50 -0
  126. package/dist/src/plugins/operator/OperatorPlugin.js +159 -0
  127. package/dist/src/plugins/operator/OperatorPlugin.js.map +1 -0
  128. package/dist/src/plugins/operator/StreamPartAssignments.d.ts +28 -0
  129. package/dist/src/plugins/operator/StreamPartAssignments.js +104 -0
  130. package/dist/src/plugins/operator/StreamPartAssignments.js.map +1 -0
  131. package/dist/src/plugins/operator/announceNodeToContract.d.ts +3 -0
  132. package/dist/src/plugins/operator/announceNodeToContract.js +39 -0
  133. package/dist/src/plugins/operator/announceNodeToContract.js.map +1 -0
  134. package/dist/src/plugins/operator/announceNodeToStream.d.ts +3 -0
  135. package/dist/src/plugins/operator/announceNodeToStream.js +25 -0
  136. package/dist/src/plugins/operator/announceNodeToStream.js.map +1 -0
  137. package/dist/src/plugins/operator/checkOperatorValueBreach.d.ts +2 -0
  138. package/dist/src/plugins/operator/checkOperatorValueBreach.js +21 -0
  139. package/dist/src/plugins/operator/checkOperatorValueBreach.js.map +1 -0
  140. package/dist/src/plugins/operator/closeExpiredFlags.d.ts +3 -0
  141. package/dist/src/plugins/operator/closeExpiredFlags.js +24 -0
  142. package/dist/src/plugins/operator/closeExpiredFlags.js.map +1 -0
  143. package/dist/src/plugins/operator/config.schema.json +152 -0
  144. package/dist/src/plugins/operator/createIsLeaderFn.d.ts +4 -0
  145. package/dist/src/plugins/operator/createIsLeaderFn.js +14 -0
  146. package/dist/src/plugins/operator/createIsLeaderFn.js.map +1 -0
  147. package/dist/src/plugins/operator/fetchRedundancyFactor.d.ts +2 -0
  148. package/dist/src/plugins/operator/fetchRedundancyFactor.js +43 -0
  149. package/dist/src/plugins/operator/fetchRedundancyFactor.js.map +1 -0
  150. package/dist/src/plugins/operator/formCoordinationStreamId.d.ts +3 -0
  151. package/dist/src/plugins/operator/formCoordinationStreamId.js +9 -0
  152. package/dist/src/plugins/operator/formCoordinationStreamId.js.map +1 -0
  153. package/dist/src/plugins/operator/heartbeatUtils.d.ts +67 -0
  154. package/dist/src/plugins/operator/heartbeatUtils.js +26 -0
  155. package/dist/src/plugins/operator/heartbeatUtils.js.map +1 -0
  156. package/dist/src/plugins/operator/inspectOverTime.d.ts +22 -0
  157. package/dist/src/plugins/operator/inspectOverTime.js +146 -0
  158. package/dist/src/plugins/operator/inspectOverTime.js.map +1 -0
  159. package/dist/src/plugins/operator/inspectRandomNode.d.ts +8 -0
  160. package/dist/src/plugins/operator/inspectRandomNode.js +44 -0
  161. package/dist/src/plugins/operator/inspectRandomNode.js.map +1 -0
  162. package/dist/src/plugins/operator/inspectionUtils.d.ts +23 -0
  163. package/dist/src/plugins/operator/inspectionUtils.js +120 -0
  164. package/dist/src/plugins/operator/inspectionUtils.js.map +1 -0
  165. package/dist/src/plugins/operator/maintainOperatorValue.d.ts +2 -0
  166. package/dist/src/plugins/operator/maintainOperatorValue.js +21 -0
  167. package/dist/src/plugins/operator/maintainOperatorValue.js.map +1 -0
  168. package/dist/src/plugins/operator/reviewSuspectNode.d.ts +24 -0
  169. package/dist/src/plugins/operator/reviewSuspectNode.js +56 -0
  170. package/dist/src/plugins/operator/reviewSuspectNode.js.map +1 -0
  171. package/dist/src/plugins/storage/Batch.d.ts +51 -0
  172. package/dist/src/plugins/storage/Batch.js +121 -0
  173. package/dist/src/plugins/storage/Batch.js.map +1 -0
  174. package/dist/src/plugins/storage/BatchManager.d.ts +27 -0
  175. package/dist/src/plugins/storage/BatchManager.js +117 -0
  176. package/dist/src/plugins/storage/BatchManager.js.map +1 -0
  177. package/dist/src/plugins/storage/Bucket.d.ts +23 -0
  178. package/dist/src/plugins/storage/Bucket.js +90 -0
  179. package/dist/src/plugins/storage/Bucket.js.map +1 -0
  180. package/dist/src/plugins/storage/BucketManager.d.ts +56 -0
  181. package/dist/src/plugins/storage/BucketManager.js +306 -0
  182. package/dist/src/plugins/storage/BucketManager.js.map +1 -0
  183. package/dist/src/plugins/storage/DataQueryFormat.d.ts +10 -0
  184. package/dist/src/plugins/storage/DataQueryFormat.js +51 -0
  185. package/dist/src/plugins/storage/DataQueryFormat.js.map +1 -0
  186. package/dist/src/plugins/storage/DeleteExpiredCmd.d.ts +28 -0
  187. package/dist/src/plugins/storage/DeleteExpiredCmd.js +155 -0
  188. package/dist/src/plugins/storage/DeleteExpiredCmd.js.map +1 -0
  189. package/dist/src/plugins/storage/SetMembershipSynchronizer.d.ts +33 -0
  190. package/dist/src/plugins/storage/SetMembershipSynchronizer.js +102 -0
  191. package/dist/src/plugins/storage/SetMembershipSynchronizer.js.map +1 -0
  192. package/dist/src/plugins/storage/Storage.d.ts +47 -0
  193. package/dist/src/plugins/storage/Storage.js +459 -0
  194. package/dist/src/plugins/storage/Storage.js.map +1 -0
  195. package/dist/src/plugins/storage/StorageConfig.d.ts +43 -0
  196. package/dist/src/plugins/storage/StorageConfig.js +83 -0
  197. package/dist/src/plugins/storage/StorageConfig.js.map +1 -0
  198. package/dist/src/plugins/storage/StorageEventListener.d.ts +17 -0
  199. package/dist/src/plugins/storage/StorageEventListener.js +46 -0
  200. package/dist/src/plugins/storage/StorageEventListener.js.map +1 -0
  201. package/dist/src/plugins/storage/StoragePlugin.d.ts +32 -0
  202. package/dist/src/plugins/storage/StoragePlugin.js +103 -0
  203. package/dist/src/plugins/storage/StoragePlugin.js.map +1 -0
  204. package/dist/src/plugins/storage/StoragePoller.d.ts +15 -0
  205. package/dist/src/plugins/storage/StoragePoller.js +47 -0
  206. package/dist/src/plugins/storage/StoragePoller.js.map +1 -0
  207. package/dist/src/plugins/storage/config.schema.json +88 -0
  208. package/dist/src/plugins/storage/dataMetadataEndpoint.d.ts +3 -0
  209. package/dist/src/plugins/storage/dataMetadataEndpoint.js +35 -0
  210. package/dist/src/plugins/storage/dataMetadataEndpoint.js.map +1 -0
  211. package/dist/src/plugins/storage/dataQueryEndpoint.d.ts +6 -0
  212. package/dist/src/plugins/storage/dataQueryEndpoint.js +181 -0
  213. package/dist/src/plugins/storage/dataQueryEndpoint.js.map +1 -0
  214. package/dist/src/plugins/storage/storageConfigEndpoint.d.ts +3 -0
  215. package/dist/src/plugins/storage/storageConfigEndpoint.js +31 -0
  216. package/dist/src/plugins/storage/storageConfigEndpoint.js.map +1 -0
  217. package/dist/src/plugins/subscriber/SubscriberPlugin.d.ts +16 -0
  218. package/dist/src/plugins/subscriber/SubscriberPlugin.js +22 -0
  219. package/dist/src/plugins/subscriber/SubscriberPlugin.js.map +1 -0
  220. package/dist/src/plugins/subscriber/config.schema.json +31 -0
  221. package/dist/src/plugins/websocket/Connection.d.ts +9 -0
  222. package/dist/src/plugins/websocket/Connection.js +45 -0
  223. package/dist/src/plugins/websocket/Connection.js.map +1 -0
  224. package/dist/src/plugins/websocket/PublishConnection.d.ts +12 -0
  225. package/dist/src/plugins/websocket/PublishConnection.js +46 -0
  226. package/dist/src/plugins/websocket/PublishConnection.js.map +1 -0
  227. package/dist/src/plugins/websocket/SubscribeConnection.d.ts +13 -0
  228. package/dist/src/plugins/websocket/SubscribeConnection.js +50 -0
  229. package/dist/src/plugins/websocket/SubscribeConnection.js.map +1 -0
  230. package/dist/src/plugins/websocket/WebsocketPlugin.d.ts +19 -0
  231. package/dist/src/plugins/websocket/WebsocketPlugin.js +26 -0
  232. package/dist/src/plugins/websocket/WebsocketPlugin.js.map +1 -0
  233. package/dist/src/plugins/websocket/WebsocketServer.d.ts +16 -0
  234. package/dist/src/plugins/websocket/WebsocketServer.js +132 -0
  235. package/dist/src/plugins/websocket/WebsocketServer.js.map +1 -0
  236. package/dist/src/plugins/websocket/config.schema.json +51 -0
  237. package/package.json +78 -0
  238. package/plugins.md +318 -0
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StorageEventListener = void 0;
4
+ const utils_1 = require("@streamr/utils");
5
+ const logger = new utils_1.Logger(module);
6
+ /**
7
+ * Hooks up to StreamrClient event listener to learn about
8
+ * stream assignment and removal events in real-time.
9
+ */
10
+ class StorageEventListener {
11
+ clusterId;
12
+ streamrClient;
13
+ onEvent;
14
+ onAddToStorageNode;
15
+ onRemoveFromStorageNode;
16
+ constructor(clusterId, streamrClient, onEvent) {
17
+ this.clusterId = clusterId;
18
+ this.streamrClient = streamrClient;
19
+ this.onEvent = onEvent;
20
+ this.onAddToStorageNode = (event) => this.handleEvent(event, 'added');
21
+ this.onRemoveFromStorageNode = (event) => this.handleEvent(event, 'removed');
22
+ }
23
+ async handleEvent(event, type) {
24
+ if (event.nodeAddress !== this.clusterId) {
25
+ return;
26
+ }
27
+ logger.info('Received StorageNodeAssignmentEvent', { type, event });
28
+ try {
29
+ const stream = await this.streamrClient.getStream(event.streamId);
30
+ this.onEvent(stream, type, event.blockNumber);
31
+ }
32
+ catch (err) {
33
+ logger.warn('Encountered error handling StorageNodeAssignmentEvent', { err, event, type });
34
+ }
35
+ }
36
+ start() {
37
+ this.streamrClient.on('addToStorageNode', this.onAddToStorageNode);
38
+ this.streamrClient.on('removeFromStorageNode', this.onRemoveFromStorageNode);
39
+ }
40
+ destroy() {
41
+ this.streamrClient.off('addToStorageNode', this.onAddToStorageNode);
42
+ this.streamrClient.off('removeFromStorageNode', this.onRemoveFromStorageNode);
43
+ }
44
+ }
45
+ exports.StorageEventListener = StorageEventListener;
46
+ //# sourceMappingURL=StorageEventListener.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StorageEventListener.js","sourceRoot":"","sources":["../../../../src/plugins/storage/StorageEventListener.ts"],"names":[],"mappings":";;;AACA,0CAAwD;AAExD,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAEjC;;;GAGG;AACH,MAAa,oBAAoB;IACZ,SAAS,CAAiB;IAC1B,aAAa,CAAe;IAC5B,OAAO,CAAoE;IAC3E,kBAAkB,CAA6C;IAC/D,uBAAuB,CAA6C;IAErF,YACI,SAA0B,EAC1B,aAA4B,EAC5B,OAA2E;QAE3E,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;QAClC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,kBAAkB,GAAG,CAAC,KAAiC,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QACjG,IAAI,CAAC,uBAAuB,GAAG,CAAC,KAAiC,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;IAC5G,CAAC;IAEO,KAAK,CAAC,WAAW,CAAC,KAAiC,EAAE,IAAyB;QAClF,IAAI,KAAK,CAAC,WAAW,KAAK,IAAI,CAAC,SAAS,EAAE,CAAC;YACvC,OAAM;QACV,CAAC;QACD,MAAM,CAAC,IAAI,CAAC,qCAAqC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAA;QACnE,IAAI,CAAC;YACD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;YACjE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,WAAW,CAAC,CAAA;QACjD,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,MAAM,CAAC,IAAI,CAAC,uDAAuD,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;QAC9F,CAAC;IACL,CAAC;IAED,KAAK;QACD,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,kBAAkB,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAA;QAClE,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,uBAAuB,EAAE,IAAI,CAAC,uBAAuB,CAAC,CAAA;IAChF,CAAC;IAED,OAAO;QACH,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,kBAAkB,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAA;QACnE,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,uBAAuB,EAAE,IAAI,CAAC,uBAAuB,CAAC,CAAA;IACjF,CAAC;CACJ;AAzCD,oDAyCC"}
@@ -0,0 +1,32 @@
1
+ import { EthereumAddress } from '@streamr/utils';
2
+ import { Schema } from 'ajv';
3
+ import { StreamrClient } from '@streamr/sdk';
4
+ import { ApiPluginConfig, Plugin } from '../../Plugin';
5
+ export interface StoragePluginConfig extends ApiPluginConfig {
6
+ cassandra: {
7
+ hosts: string[];
8
+ username: string;
9
+ password: string;
10
+ keyspace: string;
11
+ datacenter: string;
12
+ };
13
+ storageConfig: {
14
+ refreshInterval: number;
15
+ };
16
+ cluster: {
17
+ clusterAddress?: EthereumAddress;
18
+ clusterSize: number;
19
+ myIndexInCluster: number;
20
+ };
21
+ }
22
+ export declare class StoragePlugin extends Plugin<StoragePluginConfig> {
23
+ private streamrClient?;
24
+ private cassandra?;
25
+ private storageConfig?;
26
+ private messageListener?;
27
+ start(streamrClient: StreamrClient): Promise<void>;
28
+ stop(): Promise<void>;
29
+ getConfigSchema(): Schema;
30
+ private startCassandraStorage;
31
+ private startStorageConfig;
32
+ }
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.StoragePlugin = void 0;
7
+ const protocol_1 = require("@streamr/protocol");
8
+ const utils_1 = require("@streamr/utils");
9
+ const sdk_1 = require("@streamr/sdk");
10
+ const Plugin_1 = require("../../Plugin");
11
+ const Storage_1 = require("./Storage");
12
+ const StorageConfig_1 = require("./StorageConfig");
13
+ const config_schema_json_1 = __importDefault(require("./config.schema.json"));
14
+ const dataMetadataEndpoint_1 = require("./dataMetadataEndpoint");
15
+ const dataQueryEndpoint_1 = require("./dataQueryEndpoint");
16
+ const storageConfigEndpoint_1 = require("./storageConfigEndpoint");
17
+ const logger = new utils_1.Logger(module);
18
+ const isStorableMessage = (msg) => {
19
+ return msg.messageType === protocol_1.StreamMessageType.MESSAGE;
20
+ };
21
+ class StoragePlugin extends Plugin_1.Plugin {
22
+ streamrClient;
23
+ cassandra;
24
+ storageConfig;
25
+ messageListener;
26
+ async start(streamrClient) {
27
+ this.streamrClient = streamrClient;
28
+ const clusterId = this.pluginConfig.cluster.clusterAddress ?? await this.streamrClient.getAddress();
29
+ const assignmentStream = await this.streamrClient.getStream((0, sdk_1.formStorageNodeAssignmentStreamId)(clusterId));
30
+ const metricsContext = (await (this.streamrClient.getNode())).getMetricsContext();
31
+ this.cassandra = await this.startCassandraStorage(metricsContext);
32
+ this.storageConfig = await this.startStorageConfig(clusterId, assignmentStream);
33
+ this.messageListener = (msg) => {
34
+ if (isStorableMessage(msg) && this.storageConfig.hasStreamPart(msg.getStreamPartID())) {
35
+ this.cassandra.store(msg);
36
+ }
37
+ };
38
+ const node = await this.streamrClient.getNode();
39
+ node.addMessageListener(this.messageListener);
40
+ this.addHttpServerEndpoint((0, dataQueryEndpoint_1.createDataQueryEndpoint)(this.cassandra, metricsContext));
41
+ this.addHttpServerEndpoint((0, dataMetadataEndpoint_1.createDataMetadataEndpoint)(this.cassandra));
42
+ this.addHttpServerEndpoint((0, storageConfigEndpoint_1.createStorageConfigEndpoint)(this.storageConfig));
43
+ }
44
+ async stop() {
45
+ const node = await this.streamrClient.getNode();
46
+ node.removeMessageListener(this.messageListener);
47
+ await Promise.all(Array.from(this.storageConfig.getStreamParts()).map((streamPart) => node.leave(streamPart)));
48
+ await this.cassandra.close();
49
+ this.storageConfig.destroy();
50
+ }
51
+ // eslint-disable-next-line class-methods-use-this
52
+ getConfigSchema() {
53
+ return config_schema_json_1.default;
54
+ }
55
+ async startCassandraStorage(metricsContext) {
56
+ const cassandraStorage = await (0, Storage_1.startCassandraStorage)({
57
+ contactPoints: [...this.pluginConfig.cassandra.hosts],
58
+ localDataCenter: this.pluginConfig.cassandra.datacenter,
59
+ keyspace: this.pluginConfig.cassandra.keyspace,
60
+ username: this.pluginConfig.cassandra.username,
61
+ password: this.pluginConfig.cassandra.password,
62
+ opts: {
63
+ useTtl: false
64
+ }
65
+ });
66
+ cassandraStorage.enableMetrics(metricsContext);
67
+ return cassandraStorage;
68
+ }
69
+ async startStorageConfig(clusterId, assignmentStream) {
70
+ const node = await this.streamrClient.getNode();
71
+ const storageConfig = new StorageConfig_1.StorageConfig(clusterId, this.pluginConfig.cluster.clusterSize, this.pluginConfig.cluster.myIndexInCluster, this.pluginConfig.storageConfig.refreshInterval, this.streamrClient, {
72
+ onStreamPartAdded: async (streamPart) => {
73
+ try {
74
+ await node.join(streamPart, { minCount: 1, timeout: 5000 }); // best-effort, can time out
75
+ }
76
+ catch (_e) {
77
+ // no-op
78
+ }
79
+ try {
80
+ await assignmentStream.publish({
81
+ streamPart
82
+ });
83
+ logger.debug('Published message to assignment stream', {
84
+ assignmentStreamId: assignmentStream.id
85
+ });
86
+ }
87
+ catch (err) {
88
+ logger.warn('Failed to publish to assignment stream', {
89
+ assignmentStreamId: assignmentStream.id,
90
+ err
91
+ });
92
+ }
93
+ },
94
+ onStreamPartRemoved: (streamPart) => {
95
+ (0, utils_1.executeSafePromise)(() => node.leave(streamPart));
96
+ }
97
+ });
98
+ await storageConfig.start();
99
+ return storageConfig;
100
+ }
101
+ }
102
+ exports.StoragePlugin = StoragePlugin;
103
+ //# sourceMappingURL=StoragePlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StoragePlugin.js","sourceRoot":"","sources":["../../../../src/plugins/storage/StoragePlugin.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAoE;AACpE,0CAA4F;AAE5F,sCAAuF;AACvF,yCAAsD;AACtD,uCAA0D;AAC1D,mDAA+C;AAC/C,8EAAuD;AACvD,iEAAmE;AACnE,2DAA6D;AAC7D,mEAAqE;AAErE,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAqBjC,MAAM,iBAAiB,GAAG,CAAC,GAAkB,EAAW,EAAE;IACtD,OAAO,GAAG,CAAC,WAAW,KAAK,4BAAiB,CAAC,OAAO,CAAA;AACxD,CAAC,CAAA;AAED,MAAa,aAAc,SAAQ,eAA2B;IAElD,aAAa,CAAgB;IAC7B,SAAS,CAAU;IACnB,aAAa,CAAgB;IAC7B,eAAe,CAA+B;IAEtD,KAAK,CAAC,KAAK,CAAC,aAA4B;QACpC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;QAClC,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,cAAc,IAAI,MAAM,IAAI,CAAC,aAAa,CAAC,UAAU,EAAE,CAAA;QACnG,MAAM,gBAAgB,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,IAAA,uCAAiC,EAAC,SAAS,CAAC,CAAC,CAAA;QACzG,MAAM,cAAc,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,OAA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AC;oBACD,MAAM,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAA,CAAC,4BAA4B;gBAC5F,CAAC;gBAAC,OAAO,EAAE,EAAE,CAAC;oBACV,QAAQ;gBACZ,CAAC;gBACD,IAAI,CAAC;oBACD,MAAM,gBAAgB,CAAC,OAAO,CAAC;wBAC3B,UAAU;qBACb,CAAC,CAAA;oBACF,MAAM,CAAC,KAAK,CAAC,wCAAwC,EAAE;wBACnD,kBAAkB,EAAE,gBAAgB,CAAC,EAAE;qBAC1C,CAAC,CAAA;gBACN,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACX,MAAM,CAAC,IAAI,CAAC,wCAAwC,EAAE;wBAClD,kBAAkB,EAAE,gBAAgB,CAAC,EAAE;wBACvC,GAAG;qBACN,CAAC,CAAA;gBACN,CAAC;YACL,CAAC;YACD,mBAAmB,EAAE,CAAC,UAAU,EAAE,EAAE;gBAChC,IAAA,0BAAkB,EAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAA;YACpD,CAAC;SACJ,CACJ,CAAA;QACD,MAAM,aAAa,CAAC,KAAK,EAAE,CAAA;QAC3B,OAAO,aAAa,CAAA;IACxB,CAAC;CACJ;AA3FD,sCA2FC"}
@@ -0,0 +1,15 @@
1
+ /// <reference types="node" />
2
+ import { Stream, StreamrClient } from '@streamr/sdk';
3
+ /**
4
+ * Polls full state of storage node assignments on an interval.
5
+ */
6
+ export declare class StoragePoller {
7
+ private readonly clusterId;
8
+ private readonly pollInterval;
9
+ private readonly streamrClient;
10
+ private readonly onNewSnapshot;
11
+ constructor(clusterId: string, pollInterval: number, streamrClient: StreamrClient, onNewSnapshot: (streams: Stream[], block: number) => void);
12
+ start(abortSignal: AbortSignal): Promise<void>;
13
+ poll(): Promise<void>;
14
+ private tryPoll;
15
+ }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StoragePoller = void 0;
4
+ const utils_1 = require("@streamr/utils");
5
+ const logger = new utils_1.Logger(module);
6
+ /**
7
+ * Polls full state of storage node assignments on an interval.
8
+ */
9
+ class StoragePoller {
10
+ clusterId;
11
+ pollInterval;
12
+ streamrClient;
13
+ onNewSnapshot;
14
+ constructor(clusterId, pollInterval, streamrClient, onNewSnapshot) {
15
+ this.clusterId = clusterId;
16
+ this.pollInterval = pollInterval;
17
+ this.streamrClient = streamrClient;
18
+ this.onNewSnapshot = onNewSnapshot;
19
+ }
20
+ async start(abortSignal) {
21
+ if (this.pollInterval > 0) {
22
+ await (0, utils_1.scheduleAtInterval)(() => this.tryPoll(), this.pollInterval, true, abortSignal);
23
+ }
24
+ else {
25
+ await this.tryPoll();
26
+ }
27
+ }
28
+ async poll() {
29
+ logger.info('Polling');
30
+ const { streams, blockNumber } = await this.streamrClient.getStoredStreams(this.clusterId);
31
+ logger.info('Polled', {
32
+ foundStreams: streams.length,
33
+ blockNumber
34
+ });
35
+ this.onNewSnapshot(streams, blockNumber);
36
+ }
37
+ async tryPoll() {
38
+ try {
39
+ await this.poll();
40
+ }
41
+ catch (err) {
42
+ logger.warn('Failed to poll full state', err);
43
+ }
44
+ }
45
+ }
46
+ exports.StoragePoller = StoragePoller;
47
+ //# sourceMappingURL=StoragePoller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StoragePoller.js","sourceRoot":"","sources":["../../../../src/plugins/storage/StoragePoller.ts"],"names":[],"mappings":";;;AACA,0CAA2D;AAE3D,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAEjC;;GAEG;AACH,MAAa,aAAa;IACL,SAAS,CAAQ;IACjB,YAAY,CAAQ;IACpB,aAAa,CAAe;IAC5B,aAAa,CAA4C;IAE1E,YACI,SAAiB,EACjB,YAAoB,EACpB,aAA4B,EAC5B,aAAyD;QAEzD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;QAChC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;QAClC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;IACtC,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,WAAwB;QAChC,IAAI,IAAI,CAAC,YAAY,GAAG,CAAC,EAAE,CAAC;YACxB,MAAM,IAAA,0BAAkB,EAAC,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,EAAE,WAAW,CAAC,CAAA;QACxF,CAAC;aAAM,CAAC;YACJ,MAAM,IAAI,CAAC,OAAO,EAAE,CAAA;QACxB,CAAC;IACL,CAAC;IAED,KAAK,CAAC,IAAI;QACN,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;QACtB,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,gBAAgB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;QAC1F,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE;YAClB,YAAY,EAAE,OAAO,CAAC,MAAM;YAC5B,WAAW;SACd,CAAC,CAAA;QACF,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,WAAW,CAAC,CAAA;IAC5C,CAAC;IAEO,KAAK,CAAC,OAAO;QACjB,IAAI,CAAC;YACD,MAAM,IAAI,CAAC,IAAI,EAAE,CAAA;QACrB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,MAAM,CAAC,IAAI,CAAC,2BAA2B,EAAE,GAAG,CAAC,CAAA;QACjD,CAAC;IACL,CAAC;CACJ;AA3CD,sCA2CC"}
@@ -0,0 +1,88 @@
1
+ {
2
+ "$id": "config.schema.json",
3
+ "$schema": "http://json-schema.org/draft-07/schema#",
4
+ "type": "object",
5
+ "description": "Storage plugin configuration",
6
+ "required": [
7
+ "cassandra",
8
+ "storageConfig"
9
+ ],
10
+ "additionalProperties": false,
11
+ "properties": {
12
+ "cassandra": {
13
+ "type": "object",
14
+ "description": "Apache Cassandra configuration",
15
+ "required": [
16
+ "hosts",
17
+ "username",
18
+ "password",
19
+ "keyspace",
20
+ "datacenter"
21
+ ],
22
+ "additionalProperties": false,
23
+ "properties": {
24
+ "hosts": {
25
+ "type": "array",
26
+ "items": {
27
+ "type": "string",
28
+ "format": "hostname"
29
+ },
30
+ "minItems": 1,
31
+ "uniqueItems": true
32
+ },
33
+ "username": {
34
+ "type": "string"
35
+ },
36
+ "password": {
37
+ "type": "string"
38
+ },
39
+ "keyspace": {
40
+ "type": "string"
41
+ },
42
+ "datacenter": {
43
+ "type": "string"
44
+ }
45
+ }
46
+ },
47
+ "storageConfig": {
48
+ "type": "object",
49
+ "properties": {
50
+ "refreshInterval": {
51
+ "type": "integer",
52
+ "description": "Interval (in milliseconds) in which to refresh storage config from Core API (0 = disable)"
53
+ }
54
+ },
55
+ "additionalProperties": false,
56
+ "default": {
57
+ "refreshInterval": 600000
58
+ }
59
+ },
60
+ "cluster": {
61
+ "type": "object",
62
+ "description": "Storage node cluster config",
63
+ "required": [
64
+ "clusterSize",
65
+ "myIndexInCluster"
66
+ ],
67
+ "additionalProperties": false,
68
+ "properties": {
69
+ "clusterAddress": {
70
+ "type": "string"
71
+ },
72
+ "clusterSize": {
73
+ "type": "number"
74
+ },
75
+ "myIndexInCluster": {
76
+ "type": "number"
77
+ }
78
+ },
79
+ "default": {
80
+ "clusterSize": 1,
81
+ "myIndexInCluster": 0
82
+ }
83
+ },
84
+ "apiAuthentication": {
85
+ "$ref": "definitions.schema.json#/definitions/apiAuthenticationOverride"
86
+ }
87
+ }
88
+ }
@@ -0,0 +1,3 @@
1
+ import { HttpServerEndpoint } from '../../Plugin';
2
+ import { Storage } from './Storage';
3
+ export declare const createDataMetadataEndpoint: (cassandraStorage: Storage) => HttpServerEndpoint;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createDataMetadataEndpoint = void 0;
4
+ const parseIntIfExists = (x) => {
5
+ return x === undefined ? undefined : parseInt(x);
6
+ };
7
+ const createHandler = (cassandraStorage) => {
8
+ return async (req, res) => {
9
+ const streamId = req.params.id;
10
+ const partition = parseIntIfExists(req.params.partition);
11
+ if (Number.isNaN(partition) || partition === undefined) {
12
+ const errMsg = `Path parameter "partition" not a number: ${req.params.partition}`;
13
+ res.status(400).send({
14
+ error: errMsg
15
+ });
16
+ return;
17
+ }
18
+ const out = {
19
+ totalBytes: await cassandraStorage.getTotalBytesInStream(streamId, partition),
20
+ totalMessages: await cassandraStorage.getNumberOfMessagesInStream(streamId, partition),
21
+ firstMessage: await cassandraStorage.getFirstMessageTimestampInStream(streamId, partition),
22
+ lastMessage: await cassandraStorage.getLastMessageTimestampInStream(streamId, partition)
23
+ };
24
+ res.status(200).send(out);
25
+ };
26
+ };
27
+ const createDataMetadataEndpoint = (cassandraStorage) => {
28
+ return {
29
+ path: '/streams/:id/metadata/partitions/:partition',
30
+ method: 'get',
31
+ requestHandlers: [createHandler(cassandraStorage)]
32
+ };
33
+ };
34
+ exports.createDataMetadataEndpoint = createDataMetadataEndpoint;
35
+ //# sourceMappingURL=dataMetadataEndpoint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dataMetadataEndpoint.js","sourceRoot":"","sources":["../../../../src/plugins/storage/dataMetadataEndpoint.ts"],"names":[],"mappings":";;;AAIA,MAAM,gBAAgB,GAAG,CAAC,CAAqB,EAAsB,EAAE;IACnE,OAAO,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;AACpD,CAAC,CAAA;AAED,MAAM,aAAa,GAAG,CAAC,gBAAyB,EAAkB,EAAE;IAChE,OAAO,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,EAAE;QACzC,MAAM,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAA;QAC9B,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;QACxD,IAAI,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YACrD,MAAM,MAAM,GAAG,4CAA4C,GAAG,CAAC,MAAM,CAAC,SAAS,EAAE,CAAA;YACjF,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBACjB,KAAK,EAAE,MAAM;aAChB,CAAC,CAAA;YACF,OAAM;QACV,CAAC;QACD,MAAM,GAAG,GAAG;YACR,UAAU,EAAE,MAAM,gBAAgB,CAAC,qBAAqB,CAAC,QAAQ,EAAE,SAAS,CAAC;YAC7E,aAAa,EAAE,MAAM,gBAAgB,CAAC,2BAA2B,CAAC,QAAQ,EAAE,SAAS,CAAC;YACtF,YAAY,EAAE,MAAM,gBAAgB,CAAC,gCAAgC,CAAC,QAAQ,EAAE,SAAS,CAAC;YAC1F,WAAW,EAAE,MAAM,gBAAgB,CAAC,+BAA+B,CAAC,QAAQ,EAAE,SAAS,CAAC;SAC3F,CAAA;QACD,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAC7B,CAAC,CAAA;AACL,CAAC,CAAA;AAEM,MAAM,0BAA0B,GAAG,CAAC,gBAAyB,EAAsB,EAAE;IACxF,OAAO;QACH,IAAI,EAAE,6CAA6C;QACnD,MAAM,EAAE,KAAK;QACb,eAAe,EAAE,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC;KACrD,CAAA;AACL,CAAC,CAAA;AANY,QAAA,0BAA0B,8BAMtC"}
@@ -0,0 +1,6 @@
1
+ import { MetricsContext } from '@streamr/utils';
2
+ import { Storage } from './Storage';
3
+ import { HttpServerEndpoint } from '../../Plugin';
4
+ export declare const MIN_SEQUENCE_NUMBER_VALUE = 0;
5
+ export declare const MAX_SEQUENCE_NUMBER_VALUE = 2147483647;
6
+ export declare const createDataQueryEndpoint: (storage: Storage, metricsContext: MetricsContext) => HttpServerEndpoint;
@@ -0,0 +1,181 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createDataQueryEndpoint = exports.MAX_SEQUENCE_NUMBER_VALUE = exports.MIN_SEQUENCE_NUMBER_VALUE = void 0;
4
+ const utils_1 = require("@streamr/utils");
5
+ const stream_1 = require("stream");
6
+ const DataQueryFormat_1 = require("./DataQueryFormat");
7
+ const logger = new utils_1.Logger(module);
8
+ // TODO: move this to protocol-js
9
+ exports.MIN_SEQUENCE_NUMBER_VALUE = 0;
10
+ exports.MAX_SEQUENCE_NUMBER_VALUE = 2147483647;
11
+ class ResponseTransform extends stream_1.Transform {
12
+ format;
13
+ firstMessage = true;
14
+ constructor(format) {
15
+ super({
16
+ writableObjectMode: true
17
+ });
18
+ this.format = format;
19
+ }
20
+ _transform(input, _encoding, done) {
21
+ if (this.firstMessage) {
22
+ this.firstMessage = false;
23
+ if (this.format.header !== undefined) {
24
+ this.push(this.format.header);
25
+ }
26
+ }
27
+ else {
28
+ if (this.format.delimiter !== undefined) {
29
+ this.push(this.format.delimiter);
30
+ }
31
+ }
32
+ this.push(this.format.formatMessage(input));
33
+ done();
34
+ }
35
+ _flush(done) {
36
+ if (this.firstMessage) {
37
+ if (this.format.header !== undefined) {
38
+ this.push(this.format.header);
39
+ }
40
+ }
41
+ if (this.format.footer !== undefined) {
42
+ this.push(this.format.footer);
43
+ }
44
+ done();
45
+ }
46
+ }
47
+ function parseIntIfExists(x) {
48
+ return x === undefined ? undefined : parseInt(x);
49
+ }
50
+ const sendSuccess = (data, format, streamId, res) => {
51
+ data.once('data', () => {
52
+ res.writeHead(200, {
53
+ 'Content-Type': format.contentType
54
+ });
55
+ });
56
+ data.once('error', () => {
57
+ if (!res.headersSent) {
58
+ res.status(500).json({
59
+ error: 'Failed to fetch data!'
60
+ });
61
+ }
62
+ });
63
+ (0, stream_1.pipeline)(data, new ResponseTransform(format), res, (err) => {
64
+ if ((err !== undefined) && (err !== null)) {
65
+ logger.error('Encountered error in pipeline', {
66
+ streamId,
67
+ err
68
+ });
69
+ }
70
+ });
71
+ };
72
+ const sendError = (message, res) => {
73
+ res.status(400).json({
74
+ error: message
75
+ });
76
+ };
77
+ const handleLast = (req, streamId, partition, format, res, storage, metrics) => {
78
+ metrics.resendLastQueriesPerSecond.record(1);
79
+ const count = req.query.count === undefined ? 1 : parseIntIfExists(req.query.count);
80
+ if (Number.isNaN(count)) {
81
+ sendError(`Query parameter "count" not a number: ${req.query.count}`, res);
82
+ return;
83
+ }
84
+ const data = storage.requestLast(streamId, partition, count);
85
+ sendSuccess(data, format, streamId, res);
86
+ };
87
+ const handleFrom = (req, streamId, partition, format, res, storage, metrics) => {
88
+ metrics.resendFromQueriesPerSecond.record(1);
89
+ const fromTimestamp = parseIntIfExists(req.query.fromTimestamp);
90
+ const fromSequenceNumber = parseIntIfExists(req.query.fromSequenceNumber) ?? exports.MIN_SEQUENCE_NUMBER_VALUE;
91
+ const { publisherId } = req.query;
92
+ if (fromTimestamp === undefined) {
93
+ sendError('Query parameter "fromTimestamp" required.', res);
94
+ return;
95
+ }
96
+ if (Number.isNaN(fromTimestamp)) {
97
+ sendError(`Query parameter "fromTimestamp" not a number: ${req.query.fromTimestamp}`, res);
98
+ return;
99
+ }
100
+ const data = storage.requestFrom(streamId, partition, fromTimestamp, fromSequenceNumber, publisherId);
101
+ sendSuccess(data, format, streamId, res);
102
+ };
103
+ const handleRange = (req, streamId, partition, format, res, storage, metrics) => {
104
+ metrics.resendRangeQueriesPerSecond.record(1);
105
+ const fromTimestamp = parseIntIfExists(req.query.fromTimestamp);
106
+ const toTimestamp = parseIntIfExists(req.query.toTimestamp);
107
+ const fromSequenceNumber = parseIntIfExists(req.query.fromSequenceNumber) ?? exports.MIN_SEQUENCE_NUMBER_VALUE;
108
+ const toSequenceNumber = parseIntIfExists(req.query.toSequenceNumber) ?? exports.MAX_SEQUENCE_NUMBER_VALUE;
109
+ const { publisherId, msgChainId } = req.query;
110
+ if (req.query.fromOffset !== undefined || req.query.toOffset !== undefined) {
111
+ sendError('Query parameters "fromOffset" and "toOffset" are no longer supported. Please use "fromTimestamp" and "toTimestamp".', res);
112
+ return;
113
+ }
114
+ if (fromTimestamp === undefined) {
115
+ sendError('Query parameter "fromTimestamp" required.', res);
116
+ return;
117
+ }
118
+ if (Number.isNaN(fromTimestamp)) {
119
+ sendError(`Query parameter "fromTimestamp" not a number: ${req.query.fromTimestamp}`, res);
120
+ return;
121
+ }
122
+ if (toTimestamp === undefined) {
123
+ // eslint-disable-next-line max-len
124
+ sendError('Query parameter "toTimestamp" required as well. To request all messages since a timestamp, use the endpoint /streams/:id/data/partitions/:partition/from', res);
125
+ return;
126
+ }
127
+ if (Number.isNaN(toTimestamp)) {
128
+ sendError(`Query parameter "toTimestamp" not a number: ${req.query.toTimestamp}`, res);
129
+ return;
130
+ }
131
+ if ((publisherId && !msgChainId) || (!publisherId && msgChainId)) {
132
+ sendError('Invalid combination of "publisherId" and "msgChainId"', res);
133
+ return;
134
+ }
135
+ const data = storage.requestRange(streamId, partition, fromTimestamp, fromSequenceNumber, toTimestamp, toSequenceNumber, publisherId, msgChainId);
136
+ sendSuccess(data, format, streamId, res);
137
+ };
138
+ const createHandler = (storage, metrics) => {
139
+ return (req, res) => {
140
+ if (Number.isNaN(parseInt(req.params.partition))) {
141
+ sendError(`Path parameter "partition" not a number: ${req.params.partition}`, res);
142
+ return;
143
+ }
144
+ const format = (0, DataQueryFormat_1.getFormat)(req.query.format);
145
+ if (format === undefined) {
146
+ sendError(`Query parameter "format" is invalid: ${req.query.format}`, res);
147
+ return;
148
+ }
149
+ const streamId = req.params.id;
150
+ const partition = parseInt(req.params.partition);
151
+ switch (req.params.resendType) {
152
+ case 'last':
153
+ handleLast(req, streamId, partition, format, res, storage, metrics);
154
+ break;
155
+ case 'from':
156
+ handleFrom(req, streamId, partition, format, res, storage, metrics);
157
+ break;
158
+ case 'range':
159
+ handleRange(req, streamId, partition, format, res, storage, metrics);
160
+ break;
161
+ default:
162
+ sendError('Unknown resend type', res);
163
+ break;
164
+ }
165
+ };
166
+ };
167
+ const createDataQueryEndpoint = (storage, metricsContext) => {
168
+ const metrics = {
169
+ resendLastQueriesPerSecond: new utils_1.RateMetric(),
170
+ resendFromQueriesPerSecond: new utils_1.RateMetric(),
171
+ resendRangeQueriesPerSecond: new utils_1.RateMetric()
172
+ };
173
+ metricsContext.addMetrics('broker.plugin.storage', metrics);
174
+ return {
175
+ path: `/streams/:id/data/partitions/:partition/:resendType`,
176
+ method: 'get',
177
+ requestHandlers: [createHandler(storage, metrics)]
178
+ };
179
+ };
180
+ exports.createDataQueryEndpoint = createDataQueryEndpoint;
181
+ //# sourceMappingURL=dataQueryEndpoint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dataQueryEndpoint.js","sourceRoot":"","sources":["../../../../src/plugins/storage/dataQueryEndpoint.ts"],"names":[],"mappings":";;;AAIA,0CAAsF;AACtF,mCAAsD;AAEtD,uDAAqD;AAGrD,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAEjC,iCAAiC;AACpB,QAAA,yBAAyB,GAAG,CAAC,CAAA;AAC7B,QAAA,yBAAyB,GAAG,UAAU,CAAA;AAEnD,MAAM,iBAAkB,SAAQ,kBAAS;IAErC,MAAM,CAAQ;IACd,YAAY,GAAG,IAAI,CAAA;IAEnB,YAAY,MAAc;QACtB,KAAK,CAAC;YACF,kBAAkB,EAAE,IAAI;SAC3B,CAAC,CAAA;QACF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACxB,CAAC;IAEQ,UAAU,CAAC,KAAiB,EAAE,SAAiB,EAAE,IAAgB;QACtE,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACpB,IAAI,CAAC,YAAY,GAAG,KAAK,CAAA;YACzB,IAAI,IAAI,CA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CAAC,CAAA;QAChD,QAAQ,GAAG,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;YAC5B,KAAK,MAAM;gBACP,UAAU,CAAC,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;gBACnE,MAAK;YACT,KAAK,MAAM;gBACP,UAAU,CAAC,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;gBACnE,MAAK;YACT,KAAK,OAAO;gBACR,WAAW,CAAC,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;gBACpE,MAAK;YACT;gBACI,SAAS,CAAC,qBAAqB,EAAE,GAAG,CAAC,CAAA;gBACrC,MAAK;QACb,CAAC;IACL,CAAC,CAAA;AACL,CAAC,CAAA;AAEM,MAAM,uBAAuB,GAAG,CAAC,OAAgB,EAAE,cAA8B,EAAsB,EAAE;IAC5G,MAAM,OAAO,GAAG;QACZ,0BAA0B,EAAE,IAAI,kBAAU,EAAE;QAC5C,0BAA0B,EAAE,IAAI,kBAAU,EAAE;QAC5C,2BAA2B,EAAE,IAAI,kBAAU,EAAE;KAChD,CAAA;IACD,cAAc,CAAC,UAAU,CAAC,uBAAuB,EAAE,OAAO,CAAC,CAAA;IAC3D,OAAO;QACH,IAAI,EAAE,qDAAqD;QAC3D,MAAM,EAAE,KAAK;QACb,eAAe,EAAE,CAAC,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;KACrD,CAAA;AACL,CAAC,CAAA;AAZY,QAAA,uBAAuB,2BAYnC"}
@@ -0,0 +1,3 @@
1
+ import { StorageConfig } from './StorageConfig';
2
+ import { HttpServerEndpoint } from '../../Plugin';
3
+ export declare const createStorageConfigEndpoint: (storageConfig: StorageConfig) => HttpServerEndpoint;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createStorageConfigEndpoint = void 0;
4
+ const protocol_1 = require("@streamr/protocol");
5
+ const createHandler = (storageConfig) => {
6
+ return (req, res) => {
7
+ const { id, partition } = req.params;
8
+ const isValidPartition = !Number.isNaN(parseInt(partition));
9
+ if (isValidPartition) {
10
+ const found = storageConfig.hasStreamPart((0, protocol_1.toStreamPartID)((0, protocol_1.toStreamID)(id), Number(partition)));
11
+ if (found) {
12
+ res.status(200).send({});
13
+ }
14
+ else {
15
+ res.status(404).end();
16
+ }
17
+ }
18
+ else {
19
+ res.status(400).send('Partition is not a number: ' + partition);
20
+ }
21
+ };
22
+ };
23
+ const createStorageConfigEndpoint = (storageConfig) => {
24
+ return {
25
+ path: '/streams/:id/storage/partitions/:partition',
26
+ method: 'get',
27
+ requestHandlers: [createHandler(storageConfig)]
28
+ };
29
+ };
30
+ exports.createStorageConfigEndpoint = createStorageConfigEndpoint;
31
+ //# sourceMappingURL=storageConfigEndpoint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storageConfigEndpoint.js","sourceRoot":"","sources":["../../../../src/plugins/storage/storageConfigEndpoint.ts"],"names":[],"mappings":";;;AAEA,gDAA8D;AAG9D,MAAM,aAAa,GAAG,CAAC,aAA4B,EAAkB,EAAE;IACnE,OAAO,CAAC,GAAY,EAAE,GAAa,EAAE,EAAE;QACnC,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,GAAG,GAAG,CAAC,MAAM,CAAA;QACpC,MAAM,gBAAgB,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAA;QAC3D,IAAI,gBAAgB,EAAE,CAAC;YACnB,MAAM,KAAK,GAAG,aAAa,CAAC,aAAa,CAAC,IAAA,yBAAc,EAAC,IAAA,qBAAU,EAAC,EAAE,CAAC,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;YAC5F,IAAI,KAAK,EAAE,CAAC;gBACR,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;YAC5B,CAAC;iBAAM,CAAC;gBACJ,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAA;YACzB,CAAC;QACL,CAAC;aAAM,CAAC;YACJ,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,6BAA6B,GAAG,SAAS,CAAC,CAAA;QACnE,CAAC;IACL,CAAC,CAAA;AACL,CAAC,CAAA;AAEM,MAAM,2BAA2B,GAAG,CAAC,aAA4B,EAAsB,EAAE;IAC5F,OAAO;QACH,IAAI,EAAE,4CAA4C;QAClD,MAAM,EAAE,KAAK;QACb,eAAe,EAAE,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC;KAClD,CAAA;AACL,CAAC,CAAA;AANY,QAAA,2BAA2B,+BAMvC"}