Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dialectlabs/monitor

Package Overview
Dependencies
Maintainers
4
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dialectlabs/monitor - npm Package Compare versions

Comparing version 0.1.22 to 0.1.23

lib/cjs/internal/broadcast-monitor.d.ts

2

examples/006-increase-trigger.ts

@@ -26,3 +26,3 @@ import {

const monitor: Monitor<DataPool> = Monitors.builder({
subscriberRepository: new DummySubscriberRepository(1),
subscriberRepository: new DummySubscriberRepository(2),
notificationSink: new ConsoleNotificationSink(),

@@ -29,0 +29,0 @@ })

@@ -13,4 +13,5 @@ import { Duration } from 'luxon';

createUnicastMonitor<T extends object>(dataSource: PollableDataSource<T>, datasourceTransformationPipelines: DataSourceTransformationPipeline<T>[], pollInterval?: Duration): Monitor<T>;
createBroadcastMonitor<T extends object>(dataSource: PollableDataSource<T>, datasourceTransformationPipelines: DataSourceTransformationPipeline<T>[], pollInterval?: Duration): Monitor<T>;
createSubscriberEventMonitor(dataSourceTransformationPipelines: DataSourceTransformationPipeline<SubscriberEvent>[]): Monitor<SubscriberEvent>;
private toPushyDataSource;
}

@@ -10,2 +10,3 @@ "use strict";

const rxjs_1 = require("rxjs");
const broadcast_monitor_1 = require("./broadcast-monitor");
class DefaultMonitorFactory {

@@ -40,2 +41,8 @@ constructor({ dialectProgram, monitorKeypair, notificationSink, subscriberRepository, }) {

}
createBroadcastMonitor(dataSource, datasourceTransformationPipelines, pollInterval = luxon_1.Duration.fromObject({ seconds: 10 })) {
const pushyDataSource = this.toPushyDataSource(dataSource, pollInterval, this.subscriberRepository);
const broadcastMonitor = new broadcast_monitor_1.BroadcastMonitor(pushyDataSource, datasourceTransformationPipelines, this.notificationSink, this.subscriberRepository);
this.shutdownHooks.push(() => broadcastMonitor.stop());
return broadcastMonitor;
}
createSubscriberEventMonitor(dataSourceTransformationPipelines) {

@@ -42,0 +49,0 @@ const dataSource = new rxjs_1.Observable((subscriber) => this.subscriberRepository.subscribe((resourceId) => subscriber.next({

@@ -1,2 +0,2 @@

import { AddTransformationsStep, BuildStep, ChooseDataSourceStep, DefineDataSourceStep, MonitorBuilderProps, Transformation } from '../monitor-builder';
import { AddTransformationsStep, BuildStep, ChooseDataSourceStep, DefineDataSourceStep, DispatchStrategy, MonitorBuilderProps, Transformation } from '../monitor-builder';
import { SubscriberEvent } from '../data-model';

@@ -34,7 +34,7 @@ import { DataSourceTransformationPipeline, PollableDataSource } from '../ports';

dataSourceTransformationPipelines: DataSourceTransformationPipeline<T>[];
dispatchStrategy?: 'unicast';
dispatchStrategy?: DispatchStrategy;
constructor(monitorBuilderState: MonitorsBuilderState<T>);
transform<V>(transformation: Transformation<T, V>): AddTransformationsStep<T>;
dispatch(strategy?: 'unicast'): BuildStep<T>;
dispatch(strategy: DispatchStrategy): BuildStep<T>;
}
export {};

@@ -69,3 +69,3 @@ "use strict";

}
dispatch(strategy = 'unicast') {
dispatch(strategy) {
this.dispatchStrategy = strategy;

@@ -115,4 +115,12 @@ return new BuildStepImpl(this.monitorBuilderState);

}
return monitor_api_1.Monitors.factory(builderProps).createUnicastMonitor(pollableDataSource, dataSourceTransformationPipelines, pollInterval);
switch (addTransformationsStep.dispatchStrategy) {
case 'broadcast':
return monitor_api_1.Monitors.factory(builderProps).createBroadcastMonitor(pollableDataSource, dataSourceTransformationPipelines, pollInterval);
case 'unicast':
return monitor_api_1.Monitors.factory(builderProps).createUnicastMonitor(pollableDataSource, dataSourceTransformationPipelines, pollInterval);
default:
throw new Error('Unknown dispatchStrategy: ' +
addTransformationsStep.dispatchStrategy);
}
}
}

@@ -76,3 +76,3 @@ import { Duration } from 'luxon';

*/
export declare type DispatchStrategy = 'unicast';
export declare type DispatchStrategy = 'unicast' | 'broadcast';
export interface AddTransformationsStep<T extends object> {

@@ -79,0 +79,0 @@ /**

@@ -15,3 +15,4 @@ import { Keypair } from '@solana/web3.js';

createUnicastMonitor<T extends object>(dataSource: PollableDataSource<T>, transformationPipelines: DataSourceTransformationPipeline<T>[], pollInterval: Duration): Monitor<T>;
createBroadcastMonitor<T extends object>(dataSource: PollableDataSource<T>, transformationPipelines: DataSourceTransformationPipeline<T>[], pollInterval: Duration): Monitor<T>;
createSubscriberEventMonitor(eventDetectionPipelines: DataSourceTransformationPipeline<SubscriberEvent>[]): Monitor<SubscriberEvent>;
}
{
"name": "@dialectlabs/monitor",
"version": "0.1.22",
"version": "0.1.23",
"repository": "git@github.com:dialectlabs/monitor.git",
"author": "dialectlabs",
"license": "MIT",
"license": "Apache-2.0",
"module": "./lib/cjs/index.js",

@@ -8,0 +8,0 @@ "main": "./lib/cjs/index.js",

@@ -30,2 +30,142 @@ # Monitor

## Usage
Dialect's monitor is best learned by example. This section describes how to use Dialect monitor to build a monitoring apps by showing you various example apps in the `examples/` folder of this repository. Follow along in this section, & refer to the code in those examples.
Examples start from real application that is utilizing solana blockchain and dialect program, then we provide some examples
that don't utilize solana as a dependency to run for development simplicity.
### 000-real-monitoring-service
This example emulates e2e scenario for monitoring some on chain resources for a set of subscribers and has 2 parts:
1) Client that emulates several users subscribing for dialect notifications from a monitoring service
2) Server that monitors some data on chain for a set of monitoring service subscribers
The server implementation is provided below
```typescript
import { Monitor, Monitors, Pipelines, ResourceId, SourceData } from '@dialectlabs/monitor';
import { Duration } from 'luxon';
type DataType = {
cratio: number;
healthRatio: number;
};
const monitor: Monitor<DataType> = Monitors.builder({
dialectProgram: // ... set a dialect program,
monitorKeypair: // ... set a keypair used to send notifications,
})
.defineDataSource<DataType>()
.poll((subscribers: ResourceId[]) => {
const sourceData: SourceData<DataType>[] = // ... extract data from chain for set of subscribers
return Promise.resolve(sourceData);
}, Duration.fromObject({ seconds: 3 }))
.transform<number>({
keys: ['cratio'], // select a subset of attrributes from DataType
pipelines: [
// Send notification each time when value falling below the threshold
Pipelines.threshold(
{
type: 'falling-edge',
threshold: 0.5,
},
{
// Define message when trigger fired
messageBuilder: (value) =>
`Your cratio = ${value} below warning threshold`,
},
// ... Optionally you can limit rate of the messages
{
type: 'throttle-time',
timeSpan: Duration.fromObject({ minutes: 5 }),
},
),
],
})
.dispatch('unicast')
.build();
monitor.start();
// ...
```
Please follow the instructions below to run the example
#### Step 1. Run a solana validator node with dialect program
Please follow the instructions in https://github.com/dialectlabs/protocol#local-development
#### Step 2. generate a new keypair for monitoring service and fund it
```bash
export your_path=~/projects/dialect
solana-keygen new --outfile ${your_path}/monitoring-service-dev-local-key.json
solana-keygen pubkey ${your_path}/monitoring-service-dev-local-key.json > ${your_path}/monitoring-service-dev-local-key.pub
solana -k ${your_path}/monitoring-service-dev-local-key.json airdrop 3
```
#### Step 2. Start server
```bash
cd examples
export your_path=~/projects/dialect
MONITORING_SERVICE_PRIVATE_KEY=$(cat ${your_path}/monitoring-service-dev-local-key.json) ts-node ./000.2-real-monoring-service-server.ts
```
#### Step 3. Start client
```bash
cd examples
export your_path=~/projects/dialect
MONITORING_SERVICE_PUBLIC_KEY=$(solana address --keypair ${your_path}/monitoring-service-dev-local-key.json) ts-node ./000.1-real-monoring-service-client.ts
```
#### Step 4. Look at client logs for notifications
When both client and server are started, server will start polling data and notifying subscribers
### 001-data-source-monitor
Shows an example of how to define custom data source, transform data and generate notifications Doesn't exchange data
with on-chain program for development simplicity.
#### Start this example
```bash
cd examples
ts-node ./001-data-source-monitor.ts
```
### 002-subscribers-monitor
Shows an example of how subscribe to events about subscriber state changes and generate notifications. Useful e.g. for
sending new subscriber greetings or cleaning some data when subscriber removed. Doesn't exchange data with on-chain
program for development simplicity.
### Start this example
```bash
cd examples
ts-node ./002-subscribers-monitor.ts
```
### 003-custom-subscriber-repository
Shows an example of how to define custom subscriber repository instead of getting this data from on-chain program
accounts. Useful for local development.
### 004-custom-notification-sink
Shows an example of how to define notification sink instead of sending notifications via on-chain program. Useful for
local development.
### 005-custom-pipelines-using-operators
Shows an example of how to develop an analytical pipeline using a set of subsequent more low-level transformation
operators.
If you're interested in developing on Dialect while making live changes to the library, see the Development section below.
## Development

@@ -57,2 +197,2 @@

After getting familiar with https://github.com/dialectlabs/monitor/blob/main/examples/README.md and examples you'll be ready to implement a new monitoring service.
After getting familiar with https://github.com/dialectlabs/monitor/blob/main/examples/README.md and examples you'll be ready to implement a new monitoring service.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc