metrickit 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/LICENSE +21 -0
- package/README.md +379 -0
- package/dist/cache-redis.d.ts +10 -0
- package/dist/cache-redis.js +24 -0
- package/dist/cache-utils.d.ts +5 -0
- package/dist/cache.d.ts +18 -0
- package/dist/catalog.d.ts +12 -0
- package/dist/define-metric.d.ts +37 -0
- package/dist/engine.d.ts +200 -0
- package/dist/filters/default-metadata.d.ts +28 -0
- package/dist/filters/index.d.ts +3 -0
- package/dist/filters/parse.d.ts +7 -0
- package/dist/filters/types.d.ts +19 -0
- package/dist/frontend/catalog.d.ts +24 -0
- package/dist/frontend/dashboard.d.ts +12 -0
- package/dist/frontend/format.d.ts +10 -0
- package/dist/frontend/index.d.ts +10 -0
- package/dist/frontend/markers.d.ts +19 -0
- package/dist/frontend/renderers.d.ts +14 -0
- package/dist/frontend/requests.d.ts +17 -0
- package/dist/frontend/stream-state.d.ts +14 -0
- package/dist/frontend/time.d.ts +5 -0
- package/dist/frontend/transport.d.ts +19 -0
- package/dist/frontend/types.d.ts +108 -0
- package/dist/frontend.d.ts +1 -0
- package/dist/frontend.js +752 -0
- package/dist/helpers/clickhouse.d.ts +27 -0
- package/dist/helpers/distribution.d.ts +15 -0
- package/dist/helpers/index.d.ts +6 -0
- package/dist/helpers/metric-type.d.ts +21 -0
- package/dist/helpers/pivot.d.ts +15 -0
- package/dist/helpers/prisma.d.ts +20 -0
- package/dist/helpers/timeseries.d.ts +6 -0
- package/dist/helpers.d.ts +1 -0
- package/dist/helpers.js +668 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +1322 -0
- package/dist/orpc.d.ts +36 -0
- package/dist/orpc.js +1157 -0
- package/dist/registry.d.ts +269 -0
- package/dist/run-metrics.d.ts +14 -0
- package/dist/schemas/index.d.ts +4 -0
- package/dist/schemas/inputs.d.ts +19 -0
- package/dist/schemas/metric-type.d.ts +7 -0
- package/dist/schemas/output.d.ts +842 -0
- package/dist/schemas/time.d.ts +24 -0
- package/dist/time.d.ts +6 -0
- package/dist/type-guards.d.ts +7 -0
- package/package.json +91 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { TimeGranularity } from '../schemas/index.ts';
|
|
2
|
+
declare const CLICKHOUSE_GRANULARITY_FUNCTIONS: {
|
|
3
|
+
readonly hour: "toStartOfHour";
|
|
4
|
+
readonly day: "toStartOfDay";
|
|
5
|
+
readonly week: "toStartOfWeek";
|
|
6
|
+
readonly month: "toStartOfMonth";
|
|
7
|
+
readonly quarter: "toStartOfQuarter";
|
|
8
|
+
readonly year: "toStartOfYear";
|
|
9
|
+
};
|
|
10
|
+
export type ClickhouseGranularityFunction = (typeof CLICKHOUSE_GRANULARITY_FUNCTIONS)[TimeGranularity];
|
|
11
|
+
export declare function getClickhouseGranularity(granularity: TimeGranularity): ClickhouseGranularityFunction;
|
|
12
|
+
export declare function buildClickhouseBucketExpr(columnName: string, granularity: TimeGranularity): string;
|
|
13
|
+
export type DayBoundary = 'start' | 'end';
|
|
14
|
+
export declare function toClickhouseDatetime(date: Date, boundary?: DayBoundary): string;
|
|
15
|
+
export declare function buildClickhouseTimeParams(filters: {
|
|
16
|
+
from?: Date;
|
|
17
|
+
to?: Date;
|
|
18
|
+
}): {
|
|
19
|
+
from?: string;
|
|
20
|
+
to?: string;
|
|
21
|
+
};
|
|
22
|
+
export declare function buildClickhouseTimeWhere(columnName: string, options: {
|
|
23
|
+
from?: boolean;
|
|
24
|
+
to?: boolean;
|
|
25
|
+
}): string;
|
|
26
|
+
export declare function parseClickhouseBucketToTimestamp(bucket: string): number;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DistributionOutput, DistributionChartType } from '../schemas/index.ts';
|
|
2
|
+
export interface SegmentInput<Key extends string = string> {
|
|
3
|
+
key: Key;
|
|
4
|
+
label: string;
|
|
5
|
+
value: number;
|
|
6
|
+
}
|
|
7
|
+
export interface DistributionOptions {
|
|
8
|
+
chartType?: DistributionChartType;
|
|
9
|
+
}
|
|
10
|
+
export declare function calculateDistribution<const Segments extends readonly SegmentInput[]>(segments: Segments, options?: DistributionOptions): DistributionOutput<Segments[number]['key']>;
|
|
11
|
+
export declare function calculateDistributionFromGroups<TKey extends string, TGroup extends {
|
|
12
|
+
_count: {
|
|
13
|
+
_all: number;
|
|
14
|
+
};
|
|
15
|
+
} & Record<TKey, string>>(groups: TGroup[], keyField: TKey, labelMap?: Record<string, string>, options?: DistributionOptions): DistributionOutput<TGroup[TKey]>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { getClickhouseGranularity, buildClickhouseBucketExpr, toClickhouseDatetime, buildClickhouseTimeParams, buildClickhouseTimeWhere, parseClickhouseBucketToTimestamp, type ClickhouseGranularityFunction, type DayBoundary } from './clickhouse.ts';
|
|
2
|
+
export { buildTimeRangeWhere, buildTimeRangeWhereObject, buildScopedTimeWhere, type TimeRangeWhere } from './prisma.ts';
|
|
3
|
+
export { calculateDistribution, calculateDistributionFromGroups, type SegmentInput, type DistributionOptions } from './distribution.ts';
|
|
4
|
+
export { mapBucketsToPoints, createEmptyPoints } from './timeseries.ts';
|
|
5
|
+
export { resolveMetricType, calculateMetricModeValue, getMetricModeLabel, getBucketCountForMetricMode } from './metric-type.ts';
|
|
6
|
+
export { createPivotMatrix, addPivotCell, computePivotTotals, formatPivotBucketLabel, buildPivotOutput } from './pivot.ts';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { MetricType } from '../schemas/metric-type.ts';
|
|
2
|
+
export declare function resolveMetricType(metric: MetricType | undefined, defaultMetric: MetricType): MetricType;
|
|
3
|
+
export declare function calculateMetricModeValue(args: {
|
|
4
|
+
total: number;
|
|
5
|
+
averageDivisor: number;
|
|
6
|
+
metric: MetricType | undefined;
|
|
7
|
+
defaultMetric: MetricType;
|
|
8
|
+
bucketCount?: number;
|
|
9
|
+
postProcess?: (value: number) => number;
|
|
10
|
+
}): number;
|
|
11
|
+
export declare function getMetricModeLabel<Labels extends Record<MetricType, string>>(args: {
|
|
12
|
+
metric: MetricType | undefined;
|
|
13
|
+
defaultMetric: MetricType;
|
|
14
|
+
labels: Labels;
|
|
15
|
+
}): Labels[MetricType];
|
|
16
|
+
export declare function getBucketCountForMetricMode(args: {
|
|
17
|
+
metric: MetricType | undefined;
|
|
18
|
+
defaultMetric: MetricType;
|
|
19
|
+
from: Date;
|
|
20
|
+
to: Date;
|
|
21
|
+
}): number | undefined;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { TimeGranularity } from '../schemas/index.ts';
|
|
2
|
+
import { type PivotOutput, type PivotTotals } from '../schemas/index.ts';
|
|
3
|
+
export declare function createPivotMatrix(rowCount: number, columnCount: number): number[][];
|
|
4
|
+
export declare function addPivotCell(values: number[][], rowIndex: number, columnIndex: number, delta: number): void;
|
|
5
|
+
export declare function computePivotTotals(values: number[][]): PivotTotals;
|
|
6
|
+
export declare function formatPivotBucketLabel(bucket: Date, granularity: TimeGranularity): string;
|
|
7
|
+
export declare function buildPivotOutput(args: {
|
|
8
|
+
rowDimension: PivotOutput['rowDimension'];
|
|
9
|
+
columnDimension: PivotOutput['columnDimension'];
|
|
10
|
+
rows: string[];
|
|
11
|
+
columns: string[];
|
|
12
|
+
values: number[][];
|
|
13
|
+
cellTooltips?: string[][];
|
|
14
|
+
totals?: PivotTotals;
|
|
15
|
+
}): PivotOutput;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface TimeRangeWhere {
|
|
2
|
+
gte?: Date;
|
|
3
|
+
lte?: Date;
|
|
4
|
+
}
|
|
5
|
+
export declare function buildTimeRangeWhere(filters: {
|
|
6
|
+
from?: Date;
|
|
7
|
+
to?: Date;
|
|
8
|
+
}): TimeRangeWhere | undefined;
|
|
9
|
+
export declare function buildTimeRangeWhereObject<T extends string>(columnName: T, filters: {
|
|
10
|
+
from?: Date;
|
|
11
|
+
to?: Date;
|
|
12
|
+
}): {
|
|
13
|
+
[K in T]?: TimeRangeWhere;
|
|
14
|
+
};
|
|
15
|
+
export declare function buildScopedTimeWhere<TIdColumn extends string>(idColumn: TIdColumn, timeColumn: string, filters: {
|
|
16
|
+
scopeIds?: string[];
|
|
17
|
+
scopeId?: string;
|
|
18
|
+
from?: Date;
|
|
19
|
+
to?: Date;
|
|
20
|
+
}): Record<string, unknown>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { TimeGranularity } from '../schemas/index.ts';
|
|
2
|
+
import type { TimeSeriesPoint } from '../schemas/output.ts';
|
|
3
|
+
export declare function mapBucketsToPoints<T extends {
|
|
4
|
+
bucket?: string;
|
|
5
|
+
}>(buckets: Date[], rows: T[], valueExtractor: (row: T) => number): TimeSeriesPoint[];
|
|
6
|
+
export declare function createEmptyPoints(from: Date, to: Date, granularity: TimeGranularity): TimeSeriesPoint[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './helpers/index.ts';
|