@dialectlabs/monitor
Advanced tools
Comparing version 1.2.3 to 1.2.4
@@ -35,2 +35,6 @@ import { SubscriberEvent, SubscriberState } from './data-model'; | ||
} | ||
export interface Diff<E> { | ||
added: E[]; | ||
removed: E[]; | ||
} | ||
/** | ||
@@ -40,2 +44,3 @@ * A set of commonly-used pipelines | ||
export declare class Pipelines { | ||
static diff<T extends object, E extends object>(compareBy: (e1: E, e2: E) => boolean, rateLimit?: RateLimit): TransformationPipeline<E[], T, Diff<E>>; | ||
static threshold<T extends object>(trigger: Trigger, rateLimit?: RateLimit): TransformationPipeline<number, T, number>; | ||
@@ -42,0 +47,0 @@ static averageInFixedSizeWindowThreshold<T extends object>(window: FixedSizeWindow, trigger: Trigger, rateLimit?: RateLimit): TransformationPipeline<number, T, number>; |
@@ -22,2 +22,24 @@ "use strict"; | ||
class Pipelines { | ||
static diff(compareBy, rateLimit) { | ||
return Pipelines.createNew((upstream) => upstream | ||
.pipe(transformation_pipeline_operators_1.Operators.Window.fixedSizeSliding(2)) | ||
.pipe(transformation_pipeline_operators_1.Operators.Transform.filter((it) => it.length == 2)) | ||
.pipe(transformation_pipeline_operators_1.Operators.Transform.map(([d1, d2]) => { | ||
const added = d2.value.filter((e2) => !d1.value.find((e1) => compareBy(e1, e2))); | ||
const removed = d1.value.filter((e1) => !d2.value.find((e2) => compareBy(e1, e2))); | ||
const diff = { | ||
added, | ||
removed, | ||
}; | ||
const data = { | ||
value: diff, | ||
context: d2.context, | ||
}; | ||
return data; | ||
})) | ||
.pipe(transformation_pipeline_operators_1.Operators.Transform.filter(({ value: { added, removed } }) => added.length + removed.length > 0)) | ||
.pipe(rateLimit | ||
? transformation_pipeline_operators_1.Operators.FlowControl.rateLimit(rateLimit.timeSpan) | ||
: transformation_pipeline_operators_1.Operators.Transform.identity())); | ||
} | ||
static threshold(trigger, rateLimit) { | ||
@@ -24,0 +46,0 @@ const triggerOperator = createTriggerOperator(trigger); |
{ | ||
"name": "@dialectlabs/monitor", | ||
"version": "1.2.3", | ||
"version": "1.2.4", | ||
"repository": "git@github.com:dialectlabs/monitor.git", | ||
@@ -5,0 +5,0 @@ "author": "dialectlabs", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
106793
59
2173