@unblind/react 0.1.0-alpha.13 → 0.1.0-alpha.14

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/dist/index.d.mts CHANGED
@@ -67,6 +67,16 @@ interface TooltipItem {
67
67
  attributes?: Record<string, string>;
68
68
  }
69
69
  type TooltipLayout = "auto" | "group-by-metric" | "flat";
70
+ /**
71
+ * Formats for rendering attribute and metric names.
72
+ * @example
73
+ * nodejs.eventloop.p50
74
+ * ```
75
+ * original: "nodejs.eventloop.p50"
76
+ * suffix: "p50"
77
+ * title: "Nodejs Eventloop P50"
78
+ * ```
79
+ */
70
80
  type TooltipFormat = "original" | "suffix" | "title";
71
81
  interface TooltipProps {
72
82
  timestamp: number;
@@ -218,7 +228,7 @@ interface ChartVisualConfig {
218
228
  */
219
229
  colors?: Colors;
220
230
  /**
221
- * Optional order for rendering results.
231
+ * Optional labeling order.
222
232
  * Defaults to false
223
233
  */
224
234
  sortByValues?: boolean;
@@ -246,7 +256,7 @@ interface TooltipConfig {
246
256
  * Allows consumers to override internal UI components used for
247
257
  * loading, empty, and error states.
248
258
  *
249
- * Overrides can be provided globally via UnblindScope or
259
+ * Overrides can be provided globally via Scope or
250
260
  * locally per component.
251
261
  *
252
262
  * This API customizes presentation only; component state and data
@@ -259,7 +269,7 @@ type Appearance = {
259
269
  Empty?: React.ComponentType;
260
270
  Tooltip?: React.ComponentType<TooltipProps>;
261
271
  };
262
- } & ChartVisualConfig;
272
+ };
263
273
  type ThresholdLevel = "info" | "warning" | "error" | "ok";
264
274
  type ThresholdLineType = "line" | "dashed" | "bold";
265
275
  type LineThreshold = {
@@ -277,7 +287,7 @@ type RangeThreshold = {
277
287
  };
278
288
  type Threshold = LineThreshold | RangeThreshold;
279
289
 
280
- type UnblindScopeConfig = TimeseriesQueryConfig & {
290
+ type ScopeConfig = TimeseriesQueryConfig & ChartVisualConfig & {
281
291
  /**
282
292
  * Optional appearance configuration for all components
283
293
  * within this scope.
@@ -290,7 +300,7 @@ type UnblindScopeConfig = TimeseriesQueryConfig & {
290
300
  *
291
301
  * @example
292
302
  * ```tsx
293
- * <UnblindScope
303
+ * <Scope
294
304
  * appearance={{
295
305
  * components: {
296
306
  * Loading: CustomLoading,
@@ -299,16 +309,16 @@ type UnblindScopeConfig = TimeseriesQueryConfig & {
299
309
  * }}
300
310
  * >
301
311
  * <App />
302
- * </UnblindScope>
312
+ * </Scope>
303
313
  * ```
304
314
  */
305
315
  appearance?: Appearance;
306
316
  };
307
- type UnblindScopeProps = UnblindScopeConfig & {
317
+ type ScopeProps = ScopeConfig & {
308
318
  children?: React$1.ReactNode;
309
319
  };
310
320
  /**
311
- * UnblindScope provides scoped configuration for all Unblind components (charts, logs, etc).
321
+ * Scope provides scoped configuration for all Unblind components (charts, logs, etc).
312
322
  * This includes default time ranges, intervals, attributes, groupBy, operator, appearance, and colors.
313
323
  *
314
324
  * When nested, child scopes inherit defaults from parent scopes and can override specific values.
@@ -317,26 +327,26 @@ type UnblindScopeProps = UnblindScopeConfig & {
317
327
  *
318
328
  * @example
319
329
  * ```tsx
320
- * import { UnblindScope } from '@unblind/react';
330
+ * import { Scope } from '@unblind/react';
321
331
  *
322
332
  * function App() {
323
333
  * return (
324
- * <UnblindScope
334
+ * <Scope
325
335
  * appearance={{ components: { Loading: CustomLoading } }}
326
336
  * timeRange="24h"
327
337
  * >
328
338
  * // Components here use 24h and CustomLoading
329
339
  *
330
- * <UnblindScope timeRange="1h">
340
+ * <Scope timeRange="1h">
331
341
  * // Components here use 1h but still inherit CustomLoading
332
- * </UnblindScope>
333
- * </UnblindScope>
342
+ * </Scope>
343
+ * </Scope>
334
344
  * );
335
345
  * }
336
346
  * ```
337
347
  */
338
- declare function UnblindScope({ children, timeRange, startTime, endTime, interval, attributes, groupBy, operator, appearance, }: UnblindScopeProps): react_jsx_runtime.JSX.Element;
339
- type UseScopeReturn = TimeseriesQueryConfig & {
348
+ declare function Scope({ children, timeRange, startTime, endTime, interval, attributes, groupBy, operator, appearance, tooltip, }: ScopeProps): react_jsx_runtime.JSX.Element;
349
+ type UseScopeReturn = TimeseriesQueryConfig & ChartVisualConfig & {
340
350
  timeRange: TimeRange;
341
351
  appearance: {
342
352
  components: {
@@ -345,14 +355,10 @@ type UseScopeReturn = TimeseriesQueryConfig & {
345
355
  Empty: React$1.ComponentType;
346
356
  Tooltip?: React$1.ComponentType<TooltipProps>;
347
357
  };
348
- colors?: Colors;
349
- sortByValues?: boolean;
350
- fill?: boolean;
351
- tooltip?: TooltipConfig;
352
358
  };
353
359
  };
354
360
  /**
355
- * Hook to access the scoped configuration from UnblindScope.
361
+ * Hook to access the scoped configuration from Scope.
356
362
  * Returns all configuration including time range, attributes,
357
363
  * groupBy, operator, colors, and UI components.
358
364
  *
@@ -366,13 +372,13 @@ type UseScopeReturn = TimeseriesQueryConfig & {
366
372
  */
367
373
  declare function useScope(): UseScopeReturn;
368
374
 
369
- type UnblindProviderProps = UnblindClientProviderProps & UnblindScopeProps & {
375
+ type UnblindProviderProps = UnblindClientProviderProps & ScopeProps & {
370
376
  children?: React.ReactNode;
371
377
  };
372
378
  /**
373
379
  * UnblindProvider is required for all Unblind hooks to work.
374
380
  * It sets up both the QueryClientProvider (for React Query) and the Unblind configuration context.
375
- * This is a convenience wrapper around UnblindClientProvider and UnblindScope.
381
+ * This is a convenience wrapper around `UnblindClientProvider` and `Scope`.
376
382
  *
377
383
  * @example
378
384
  * ```tsx
@@ -387,7 +393,7 @@ type UnblindProviderProps = UnblindClientProviderProps & UnblindScopeProps & {
387
393
  * }
388
394
  * ```
389
395
  */
390
- declare function UnblindProvider({ children, queryClient, apiBaseUrl, fetchImpl, timeRange, startTime, endTime, interval, attributes, groupBy, operator, appearance, }: UnblindProviderProps): react_jsx_runtime.JSX.Element;
396
+ declare function UnblindProvider({ children, queryClient, apiBaseUrl, fetchImpl, timeRange, startTime, endTime, interval, attributes, groupBy, operator, appearance, tooltip, colors, sortByValues, }: UnblindProviderProps): react_jsx_runtime.JSX.Element;
391
397
 
392
398
  interface UseMetricsReturn {
393
399
  metrics: MetricMetadataList | undefined;
@@ -478,11 +484,20 @@ interface UseLogsReturn {
478
484
  */
479
485
  declare function useLogs({ timeRange, filters, startTime, endTime, }: UseLogsParams): UseLogsReturn;
480
486
 
481
- type TimeseriesProps = Exclude<TimeseriesQueryConfig, "startTime" | "endTime" | "timeRange"> & {
487
+ type TimeseriesProps = Exclude<TimeseriesQueryConfig, "startTime" | "endTime" | "timeRange"> & ChartVisualConfig & {
482
488
  /**
483
489
  * Metric name(s) to display in the chart.
484
490
  *
485
- * Optional: a single string name.
491
+ * @example Single metric
492
+ * ```jsx
493
+ * <Timeseries metrics="nodejs.eventloop.p50" />
494
+ * ```
495
+ *
496
+ * @example
497
+ * Multiple metrics
498
+ * ```jsx
499
+ * <Timeseries metrics={["nodejs.eventloop.p50", "..."]} />
500
+ * ```
486
501
  */
487
502
  metrics: Array<string> | string;
488
503
  /**
@@ -523,27 +538,28 @@ type TimeseriesProps = Exclude<TimeseriesQueryConfig, "startTime" | "endTime" |
523
538
  appearance?: Appearance;
524
539
  };
525
540
  /**
526
- * Timeseries component that displays time series data for the given metrics.
527
- * It uses values from the UnblindProvider for timeRange, attributes, groupBy, and operator
528
- * if not explicitly provided as props.
541
+ * Displays a time series chart.
542
+ * Uses values from <UnblindProvider> or <Scope>
543
+ * when they are not explicitly provided as props.
529
544
  *
530
- * @example Using [UnblindProvider]
545
+ * @example
531
546
  * ```tsx
532
- * <UnblindProvider timeRange="1h">
533
- * <Timeseries metrics={["host.cpu"]} />
534
- * <Timeseries metrics={["host.memory"]} />
535
- * </UnblindProvider>
547
+ * <Timeseries
548
+ * metrics="host.cpu"
549
+ * attributes={{ "host.region": ["us-east-2"] }}
550
+ * groupBy=["host.name"]
551
+ * />
536
552
  * ```
537
553
  *
538
- * @example Using <UnblindScope>
554
+ * @example Using `<Scope>`
539
555
  * ```tsx
540
- * <UnblindScope timeRange="1h">
541
- * <Timeseries metrics={["host.cpu"]} />
542
- * <Timeseries metrics={["host.memory"]} />
543
- * </UnblindScope>
556
+ * <Scope timeRange="1h">
557
+ * <Timeseries metrics="host.cpu" />
558
+ * <Timeseries metrics="host.memory" />
559
+ * </Scope>
544
560
  * ```
545
561
  */
546
- declare function Timeseries({ metrics, operator: propOperator, attributes: propAttributes, groupBy: propGroupBy, interval: propInterval, type, className, appearance: propAppearance, unit: propUnit, thresholds: propThresholds, min: propMin, max: propMax, }: TimeseriesProps): react_jsx_runtime.JSX.Element;
562
+ declare function Timeseries({ metrics, operator: propOperator, attributes: propAttributes, groupBy: propGroupBy, interval: propInterval, type, className, appearance: propAppearance, unit: propUnit, thresholds: propThresholds, min: propMin, max: propMax, colors: propColors, tooltip: propTooltip, sortByValues: propSortByValues, fill: propFill, }: TimeseriesProps): react_jsx_runtime.JSX.Element;
547
563
 
548
564
  interface ChartProps extends ChartVisualConfig {
549
565
  times: Array<number>;
@@ -568,4 +584,4 @@ declare function Empty(): react_jsx_runtime.JSX.Element;
568
584
  declare function Error(): react_jsx_runtime.JSX.Element;
569
585
  declare function Loading(): react_jsx_runtime.JSX.Element;
570
586
 
571
- export { type AggregationOperator, type Appearance, type AttributeWithValue, Chart, type ChartProps, type ChartType, type ChartVisualConfig, type Colors, Empty, Error, type Interval, Loading, type Log, type MetricMetadata, type MetricMetadataList, type MetricType, type PaginatedResponse, type Serie, type Severity, type TimeConfig, type TimeRange, Timeseries, type TimeseriesProps, type TimeseriesQuery, type TimeseriesQueryConfig, type TooltipProps, type UnblindClientConfig, UnblindProvider, type UnblindProviderProps, UnblindScope, type UnblindScopeConfig, type UnblindScopeProps, type Usage, type UseLogsParams, type UseLogsReturn, type UseMetricsReturn, type UseScopeReturn, type UseTimeseriesParams, type UseTimeseriesReturn, type UseUsageParams, type UseUsageReturn, useLogs, useMetrics, useRefresh, useScope, useTimeseries, useUsage };
587
+ export { type AggregationOperator, type Appearance, type AttributeWithValue, Chart, type ChartProps, type ChartType, type ChartVisualConfig, type Colors, Empty, Error, type Interval, Loading, type Log, type MetricMetadata, type MetricMetadataList, type MetricType, type PaginatedResponse, Scope, type ScopeConfig, type ScopeProps, type Serie, type Severity, type TimeConfig, type TimeRange, Timeseries, type TimeseriesProps, type TimeseriesQuery, type TimeseriesQueryConfig, type TooltipProps, type UnblindClientConfig, UnblindProvider, type UnblindProviderProps, type Usage, type UseLogsParams, type UseLogsReturn, type UseMetricsReturn, type UseScopeReturn, type UseTimeseriesParams, type UseTimeseriesReturn, type UseUsageParams, type UseUsageReturn, useLogs, useMetrics, useRefresh, useScope, useTimeseries, useUsage };
package/dist/index.d.ts CHANGED
@@ -67,6 +67,16 @@ interface TooltipItem {
67
67
  attributes?: Record<string, string>;
68
68
  }
69
69
  type TooltipLayout = "auto" | "group-by-metric" | "flat";
70
+ /**
71
+ * Formats for rendering attribute and metric names.
72
+ * @example
73
+ * nodejs.eventloop.p50
74
+ * ```
75
+ * original: "nodejs.eventloop.p50"
76
+ * suffix: "p50"
77
+ * title: "Nodejs Eventloop P50"
78
+ * ```
79
+ */
70
80
  type TooltipFormat = "original" | "suffix" | "title";
71
81
  interface TooltipProps {
72
82
  timestamp: number;
@@ -218,7 +228,7 @@ interface ChartVisualConfig {
218
228
  */
219
229
  colors?: Colors;
220
230
  /**
221
- * Optional order for rendering results.
231
+ * Optional labeling order.
222
232
  * Defaults to false
223
233
  */
224
234
  sortByValues?: boolean;
@@ -246,7 +256,7 @@ interface TooltipConfig {
246
256
  * Allows consumers to override internal UI components used for
247
257
  * loading, empty, and error states.
248
258
  *
249
- * Overrides can be provided globally via UnblindScope or
259
+ * Overrides can be provided globally via Scope or
250
260
  * locally per component.
251
261
  *
252
262
  * This API customizes presentation only; component state and data
@@ -259,7 +269,7 @@ type Appearance = {
259
269
  Empty?: React.ComponentType;
260
270
  Tooltip?: React.ComponentType<TooltipProps>;
261
271
  };
262
- } & ChartVisualConfig;
272
+ };
263
273
  type ThresholdLevel = "info" | "warning" | "error" | "ok";
264
274
  type ThresholdLineType = "line" | "dashed" | "bold";
265
275
  type LineThreshold = {
@@ -277,7 +287,7 @@ type RangeThreshold = {
277
287
  };
278
288
  type Threshold = LineThreshold | RangeThreshold;
279
289
 
280
- type UnblindScopeConfig = TimeseriesQueryConfig & {
290
+ type ScopeConfig = TimeseriesQueryConfig & ChartVisualConfig & {
281
291
  /**
282
292
  * Optional appearance configuration for all components
283
293
  * within this scope.
@@ -290,7 +300,7 @@ type UnblindScopeConfig = TimeseriesQueryConfig & {
290
300
  *
291
301
  * @example
292
302
  * ```tsx
293
- * <UnblindScope
303
+ * <Scope
294
304
  * appearance={{
295
305
  * components: {
296
306
  * Loading: CustomLoading,
@@ -299,16 +309,16 @@ type UnblindScopeConfig = TimeseriesQueryConfig & {
299
309
  * }}
300
310
  * >
301
311
  * <App />
302
- * </UnblindScope>
312
+ * </Scope>
303
313
  * ```
304
314
  */
305
315
  appearance?: Appearance;
306
316
  };
307
- type UnblindScopeProps = UnblindScopeConfig & {
317
+ type ScopeProps = ScopeConfig & {
308
318
  children?: React$1.ReactNode;
309
319
  };
310
320
  /**
311
- * UnblindScope provides scoped configuration for all Unblind components (charts, logs, etc).
321
+ * Scope provides scoped configuration for all Unblind components (charts, logs, etc).
312
322
  * This includes default time ranges, intervals, attributes, groupBy, operator, appearance, and colors.
313
323
  *
314
324
  * When nested, child scopes inherit defaults from parent scopes and can override specific values.
@@ -317,26 +327,26 @@ type UnblindScopeProps = UnblindScopeConfig & {
317
327
  *
318
328
  * @example
319
329
  * ```tsx
320
- * import { UnblindScope } from '@unblind/react';
330
+ * import { Scope } from '@unblind/react';
321
331
  *
322
332
  * function App() {
323
333
  * return (
324
- * <UnblindScope
334
+ * <Scope
325
335
  * appearance={{ components: { Loading: CustomLoading } }}
326
336
  * timeRange="24h"
327
337
  * >
328
338
  * // Components here use 24h and CustomLoading
329
339
  *
330
- * <UnblindScope timeRange="1h">
340
+ * <Scope timeRange="1h">
331
341
  * // Components here use 1h but still inherit CustomLoading
332
- * </UnblindScope>
333
- * </UnblindScope>
342
+ * </Scope>
343
+ * </Scope>
334
344
  * );
335
345
  * }
336
346
  * ```
337
347
  */
338
- declare function UnblindScope({ children, timeRange, startTime, endTime, interval, attributes, groupBy, operator, appearance, }: UnblindScopeProps): react_jsx_runtime.JSX.Element;
339
- type UseScopeReturn = TimeseriesQueryConfig & {
348
+ declare function Scope({ children, timeRange, startTime, endTime, interval, attributes, groupBy, operator, appearance, tooltip, }: ScopeProps): react_jsx_runtime.JSX.Element;
349
+ type UseScopeReturn = TimeseriesQueryConfig & ChartVisualConfig & {
340
350
  timeRange: TimeRange;
341
351
  appearance: {
342
352
  components: {
@@ -345,14 +355,10 @@ type UseScopeReturn = TimeseriesQueryConfig & {
345
355
  Empty: React$1.ComponentType;
346
356
  Tooltip?: React$1.ComponentType<TooltipProps>;
347
357
  };
348
- colors?: Colors;
349
- sortByValues?: boolean;
350
- fill?: boolean;
351
- tooltip?: TooltipConfig;
352
358
  };
353
359
  };
354
360
  /**
355
- * Hook to access the scoped configuration from UnblindScope.
361
+ * Hook to access the scoped configuration from Scope.
356
362
  * Returns all configuration including time range, attributes,
357
363
  * groupBy, operator, colors, and UI components.
358
364
  *
@@ -366,13 +372,13 @@ type UseScopeReturn = TimeseriesQueryConfig & {
366
372
  */
367
373
  declare function useScope(): UseScopeReturn;
368
374
 
369
- type UnblindProviderProps = UnblindClientProviderProps & UnblindScopeProps & {
375
+ type UnblindProviderProps = UnblindClientProviderProps & ScopeProps & {
370
376
  children?: React.ReactNode;
371
377
  };
372
378
  /**
373
379
  * UnblindProvider is required for all Unblind hooks to work.
374
380
  * It sets up both the QueryClientProvider (for React Query) and the Unblind configuration context.
375
- * This is a convenience wrapper around UnblindClientProvider and UnblindScope.
381
+ * This is a convenience wrapper around `UnblindClientProvider` and `Scope`.
376
382
  *
377
383
  * @example
378
384
  * ```tsx
@@ -387,7 +393,7 @@ type UnblindProviderProps = UnblindClientProviderProps & UnblindScopeProps & {
387
393
  * }
388
394
  * ```
389
395
  */
390
- declare function UnblindProvider({ children, queryClient, apiBaseUrl, fetchImpl, timeRange, startTime, endTime, interval, attributes, groupBy, operator, appearance, }: UnblindProviderProps): react_jsx_runtime.JSX.Element;
396
+ declare function UnblindProvider({ children, queryClient, apiBaseUrl, fetchImpl, timeRange, startTime, endTime, interval, attributes, groupBy, operator, appearance, tooltip, colors, sortByValues, }: UnblindProviderProps): react_jsx_runtime.JSX.Element;
391
397
 
392
398
  interface UseMetricsReturn {
393
399
  metrics: MetricMetadataList | undefined;
@@ -478,11 +484,20 @@ interface UseLogsReturn {
478
484
  */
479
485
  declare function useLogs({ timeRange, filters, startTime, endTime, }: UseLogsParams): UseLogsReturn;
480
486
 
481
- type TimeseriesProps = Exclude<TimeseriesQueryConfig, "startTime" | "endTime" | "timeRange"> & {
487
+ type TimeseriesProps = Exclude<TimeseriesQueryConfig, "startTime" | "endTime" | "timeRange"> & ChartVisualConfig & {
482
488
  /**
483
489
  * Metric name(s) to display in the chart.
484
490
  *
485
- * Optional: a single string name.
491
+ * @example Single metric
492
+ * ```jsx
493
+ * <Timeseries metrics="nodejs.eventloop.p50" />
494
+ * ```
495
+ *
496
+ * @example
497
+ * Multiple metrics
498
+ * ```jsx
499
+ * <Timeseries metrics={["nodejs.eventloop.p50", "..."]} />
500
+ * ```
486
501
  */
487
502
  metrics: Array<string> | string;
488
503
  /**
@@ -523,27 +538,28 @@ type TimeseriesProps = Exclude<TimeseriesQueryConfig, "startTime" | "endTime" |
523
538
  appearance?: Appearance;
524
539
  };
525
540
  /**
526
- * Timeseries component that displays time series data for the given metrics.
527
- * It uses values from the UnblindProvider for timeRange, attributes, groupBy, and operator
528
- * if not explicitly provided as props.
541
+ * Displays a time series chart.
542
+ * Uses values from <UnblindProvider> or <Scope>
543
+ * when they are not explicitly provided as props.
529
544
  *
530
- * @example Using [UnblindProvider]
545
+ * @example
531
546
  * ```tsx
532
- * <UnblindProvider timeRange="1h">
533
- * <Timeseries metrics={["host.cpu"]} />
534
- * <Timeseries metrics={["host.memory"]} />
535
- * </UnblindProvider>
547
+ * <Timeseries
548
+ * metrics="host.cpu"
549
+ * attributes={{ "host.region": ["us-east-2"] }}
550
+ * groupBy=["host.name"]
551
+ * />
536
552
  * ```
537
553
  *
538
- * @example Using <UnblindScope>
554
+ * @example Using `<Scope>`
539
555
  * ```tsx
540
- * <UnblindScope timeRange="1h">
541
- * <Timeseries metrics={["host.cpu"]} />
542
- * <Timeseries metrics={["host.memory"]} />
543
- * </UnblindScope>
556
+ * <Scope timeRange="1h">
557
+ * <Timeseries metrics="host.cpu" />
558
+ * <Timeseries metrics="host.memory" />
559
+ * </Scope>
544
560
  * ```
545
561
  */
546
- declare function Timeseries({ metrics, operator: propOperator, attributes: propAttributes, groupBy: propGroupBy, interval: propInterval, type, className, appearance: propAppearance, unit: propUnit, thresholds: propThresholds, min: propMin, max: propMax, }: TimeseriesProps): react_jsx_runtime.JSX.Element;
562
+ declare function Timeseries({ metrics, operator: propOperator, attributes: propAttributes, groupBy: propGroupBy, interval: propInterval, type, className, appearance: propAppearance, unit: propUnit, thresholds: propThresholds, min: propMin, max: propMax, colors: propColors, tooltip: propTooltip, sortByValues: propSortByValues, fill: propFill, }: TimeseriesProps): react_jsx_runtime.JSX.Element;
547
563
 
548
564
  interface ChartProps extends ChartVisualConfig {
549
565
  times: Array<number>;
@@ -568,4 +584,4 @@ declare function Empty(): react_jsx_runtime.JSX.Element;
568
584
  declare function Error(): react_jsx_runtime.JSX.Element;
569
585
  declare function Loading(): react_jsx_runtime.JSX.Element;
570
586
 
571
- export { type AggregationOperator, type Appearance, type AttributeWithValue, Chart, type ChartProps, type ChartType, type ChartVisualConfig, type Colors, Empty, Error, type Interval, Loading, type Log, type MetricMetadata, type MetricMetadataList, type MetricType, type PaginatedResponse, type Serie, type Severity, type TimeConfig, type TimeRange, Timeseries, type TimeseriesProps, type TimeseriesQuery, type TimeseriesQueryConfig, type TooltipProps, type UnblindClientConfig, UnblindProvider, type UnblindProviderProps, UnblindScope, type UnblindScopeConfig, type UnblindScopeProps, type Usage, type UseLogsParams, type UseLogsReturn, type UseMetricsReturn, type UseScopeReturn, type UseTimeseriesParams, type UseTimeseriesReturn, type UseUsageParams, type UseUsageReturn, useLogs, useMetrics, useRefresh, useScope, useTimeseries, useUsage };
587
+ export { type AggregationOperator, type Appearance, type AttributeWithValue, Chart, type ChartProps, type ChartType, type ChartVisualConfig, type Colors, Empty, Error, type Interval, Loading, type Log, type MetricMetadata, type MetricMetadataList, type MetricType, type PaginatedResponse, Scope, type ScopeConfig, type ScopeProps, type Serie, type Severity, type TimeConfig, type TimeRange, Timeseries, type TimeseriesProps, type TimeseriesQuery, type TimeseriesQueryConfig, type TooltipProps, type UnblindClientConfig, UnblindProvider, type UnblindProviderProps, type Usage, type UseLogsParams, type UseLogsReturn, type UseMetricsReturn, type UseScopeReturn, type UseTimeseriesParams, type UseTimeseriesReturn, type UseUsageParams, type UseUsageReturn, useLogs, useMetrics, useRefresh, useScope, useTimeseries, useUsage };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var it=Object.create;var J=Object.defineProperty;var nt=Object.getOwnPropertyDescriptor;var at=Object.getOwnPropertyNames;var st=Object.getPrototypeOf,lt=Object.prototype.hasOwnProperty;var ut=(e,t)=>{for(var r in t)J(e,r,{get:t[r],enumerable:!0})},ye=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of at(t))!lt.call(e,o)&&o!==r&&J(e,o,{get:()=>t[o],enumerable:!(i=nt(t,o))||i.enumerable});return e};var Z=(e,t,r)=>(r=e!=null?it(st(e)):{},ye(t||!e||!e.__esModule?J(r,"default",{value:e,enumerable:!0}):r,e)),ct=e=>ye(J({},"__esModule",{value:!0}),e);var Gt={};ut(Gt,{Chart:()=>ue,Empty:()=>ee,Error:()=>te,Loading:()=>re,Timeseries:()=>ot,UnblindProvider:()=>Ce,UnblindScope:()=>oe,useLogs:()=>Ee,useMetrics:()=>ke,useRefresh:()=>pe,useScope:()=>G,useTimeseries:()=>ie,useUsage:()=>Ue});module.exports=ct(Gt);var q=require("@tanstack/react-query"),V=require("react"),ce=require("react/jsx-runtime"),Te=(0,V.createContext)(void 0);function ve({children:e,queryClient:t,queryClientConfig:r,apiBaseUrl:i="/api/unblind",fetchImpl:o}){let s=(0,V.useMemo)(()=>{if(t)return t;let n={refetchOnWindowFocus:!1,refetchOnReconnect:!1,refetchOnMount:!1},l={defaultOptions:{queries:n}};return r?new q.QueryClient({...r,defaultOptions:{...r.defaultOptions,queries:{...n,...r.defaultOptions?.queries}}}):new q.QueryClient(l)},[t,r]),a=(0,V.useMemo)(()=>({apiBaseUrl:i,fetchImpl:o}),[i,o]);return(0,ce.jsx)(q.QueryClientProvider,{client:s,children:(0,ce.jsx)(Te.Provider,{value:a,children:e})})}function O(){let e=(0,V.useContext)(Te);if(!e)throw new Error("useUnblindConfig must be used within an UnblindClientProvider. Please wrap your app or component tree with <UnblindClientProvider>.");return e}function pe(){let e=(0,q.useQueryClient)();return(0,V.useCallback)(async()=>{await e.refetchQueries({queryKey:["unblind","timeseries"]})},[e])}var B=require("react");var I=require("react/jsx-runtime");function ee(){return(0,I.jsx)("div",{className:"ub-default",children:(0,I.jsxs)("div",{className:"ub-empty-content",children:[(0,I.jsx)("div",{className:"ub-empty-icon-wrapper",children:(0,I.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",className:"ub-icon",children:(0,I.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 6v6h4.5m4.5 0a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z"})})}),(0,I.jsx)("p",{className:"ub-empty-text","data-text":"No data available for this time range"})]})})}function te(){return(0,I.jsx)("div",{className:"ub-error"})}function re(){return(0,I.jsx)("div",{className:"ub-default","data-text":"Loading"})}var xe=require("react/jsx-runtime"),me=(0,B.createContext)(void 0);function oe({children:e,timeRange:t,startTime:r,endTime:i,interval:o,attributes:s,groupBy:a,operator:n,appearance:l}){let u=(0,B.useContext)(me),m=l?.components?.Loading,d=l?.components?.Error,c=l?.components?.Tooltip,p=l?.tooltip?.layout,h=l?.tooltip?.format,g=l?.tooltip?.hideAttributes,b=l?.tooltip?.hideAttributeKey,f=l?.tooltip?.hideMetric,v=(0,B.useMemo)(()=>({components:{...m&&{Loading:m},...d&&{Error:d},...c&&{Tooltip:c}},tooltip:{layout:p,format:h,hideAttributes:g,hideAttributeKey:b,hideMetric:f}}),[m,d,c,p,h,g,b,f]),T=(0,B.useMemo)(()=>({timeRange:t??u?.timeRange,startTime:r??u?.startTime,endTime:i??u?.endTime,interval:o??u?.interval,attributes:s??u?.attributes,groupBy:a??u?.groupBy,operator:n??u?.operator,appearance:v??u?.appearance}),[t,r,i,o,s,a,n,v,u]);return(0,xe.jsx)(me.Provider,{value:T,children:e})}var pt="6h";function G(){let e=(0,B.useContext)(me);return{timeRange:e?.timeRange||pt,startTime:e?.startTime,endTime:e?.endTime,interval:e?.interval,attributes:e?.attributes,groupBy:e?.groupBy,operator:e?.operator,appearance:{components:{Loading:e?.appearance?.components?.Loading??re,Error:e?.appearance?.components?.Error??te,Empty:e?.appearance?.components?.Empty??ee,Tooltip:e?.appearance?.components?.Tooltip},colors:e?.appearance?.colors,tooltip:e?.appearance?.tooltip}}}var de=require("react/jsx-runtime");function Ce({children:e,queryClient:t,apiBaseUrl:r,fetchImpl:i,timeRange:o,startTime:s,endTime:a,interval:n,attributes:l,groupBy:u,operator:m,appearance:d}){return(0,de.jsx)(ve,{queryClient:t,apiBaseUrl:r,fetchImpl:i,children:(0,de.jsx)(oe,{timeRange:o,startTime:s,endTime:a,interval:n,attributes:l,groupBy:u,operator:m,appearance:d,children:e})})}var Pe=require("@tanstack/react-query");function ke(){let{apiBaseUrl:e,fetchImpl:t=fetch}=O(),r=(0,Pe.useQuery)({queryKey:["unblind","metrics"],queryFn:async()=>{let i=await t(`${e}/metrics`,{headers:{"Content-Type":"application/json"}});if(!i.ok)throw new Error("Error loading metrics metadata");if(i.status===200){let{data:o}=await i.json();return o}else throw new Error("Unexpected status code")}});return{metrics:r.data,isLoading:r.isLoading,hasError:r.isError,refetch:r.refetch}}var Ae=require("@tanstack/react-query"),j=require("react");var we=Z(require("ms"));function mt(e){let t=Math.floor(Date.now()/1e3);return[t-Math.floor((0,we.default)(e)/1e3),t]}function _(e,t,r){let i,o;if(typeof t=="number"&&typeof r=="number")i=t,o=r;else if(e){let[s,a]=mt(e);i=s,o=a}else throw new Error("Either timeRange or both startTime and endTime must be provided");return[i,o]}function ie({queries:e,timeRange:t,startTime:r,endTime:i,interval:o}){let{apiBaseUrl:s,fetchImpl:a=fetch}=O(),n=(0,j.useMemo)(()=>e.map(T=>T.metrics.join(",")).join(","),[e]),l=(0,j.useMemo)(()=>e.map(T=>{let C=T.attributes;if(!C)return"";let k=Object.keys(C);return k.length===0?"":k.map(x=>x+":"+C[x]?.join(",")).join(",")}).join(","),[e]),u=(0,j.useMemo)(()=>e.map(T=>T.operator),[e]),m=(0,j.useMemo)(()=>e.map(T=>T.groupBy).join(", "),[e]),c=(0,Ae.useQuery)({queryKey:["unblind","timeseries",n,l,r,i,t,o,u,m],queryFn:async()=>{if(!n)throw new Error("Missing required parameters");if(n.length===0)throw new Error("No series provided");let[T,C]=_(t,r,i),k={queries:e,startTime:T,endTime:C,interval:o},x=await a(`${s}/tenants/timeseries`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(k)});if(!x.ok)throw new Error("Error fetching metric");let{series:R,times:M,metadata:w}=await x.json();if(!R)throw console.error("Series not found"),new Error("Series not found");return{series:R,times:M,metadata:w}},enabled:!!n&&(typeof r=="number"&&typeof i=="number"||!!t)}),{metadata:p,series:h,times:g}=(0,j.useMemo)(()=>c.data?{series:c.data.series,times:c.data.times,metadata:c.data.metadata}:{series:[],times:[],metadata:{}},[c]),b=c.isLoading,f=c.isFetching,v=c.isError;return{data:{series:h,times:g,metadata:p},isLoading:b,isFetching:f,hasError:v,refetch:c.refetch}}var Se=require("@tanstack/react-query"),Re=require("react");function Ue({timeRange:e,startTime:t,endTime:r}){let{apiBaseUrl:i,fetchImpl:o=fetch}=O(),a=(0,Se.useQuery)({queryKey:["unblind","usage",e,t,r],queryFn:async()=>{let[m,d]=_(e,t,r),c=`${i}/tenants/usage`,p=await o(c,{headers:{"Content-Type":"application/json"},body:JSON.stringify({startTime:m,endTime:d})});if(!p.ok)throw new Error("Error fetching usage");let{data:h}=await p.json();if(!h)throw new Error("usage not found");return h},enabled:typeof t=="number"&&typeof r=="number"||!!e}),n=(0,Re.useMemo)(()=>a.data?a.data||[]:[],[a]),l=a.isLoading||a.isRefetching,u=a.isError;return{usage:n,isLoading:l,hasError:u,refetch:a.refetch}}var Le=require("@tanstack/react-query"),Me=require("react");function Ee({timeRange:e,filters:t,startTime:r,endTime:i}){let{apiBaseUrl:o,fetchImpl:s=fetch}=O(),a=typeof r=="number"&&typeof i=="number"||!!e,n=(0,Le.useInfiniteQuery)({queryKey:["unblind","logs",e,t.map(u=>u.name+":"+u.value).sort().join(",")],queryFn:async({pageParam:u})=>{let m=t.reduce((x,R)=>(x[R.name]||(x[R.name]=[]),x[R.name].push(R.value),x),{}),{body:d=[],severity:c=[],"service.name":p=[],"trace.id":h=[],"span.id":g=[],...b}=m,[f,v]=_(e,r,i),T=await s(`${o}/tenants/logs`,{method:"POST",body:JSON.stringify({filter:{attributes:b,body:d,severity:c,traceId:h,spanId:g,service:p},startTime:f,endTime:v,pagination:{page:u}}),headers:{"Content-Type":"application/json"}});if(!T.ok)throw new Error("Error fetching logs");let{data:C,next_page:k}=await T.json();if(!C)throw new Error("logs not found");return{data:C,next_page:k}},enabled:a,initialPageParam:void 0,getNextPageParam:u=>u.next_page});return{logs:(0,Me.useMemo)(()=>n.data?n.data.pages.flatMap(u=>u.data||[]):[],[n.data]),isLoading:n.isLoading,hasError:n.isError,hasNextPage:n.hasNextPage??!1,fetchNextPage:n.fetchNextPage,isFetchingNextPage:n.isFetchingNextPage,refetch:n.refetch}}var rt=require("react");var le=require("react"),et=Z(require("uplot"));var ne=e=>"value"in e,W=e=>"from"in e&&"to"in e;var X=Z(require("uplot")),je=require("@unblind/units");var z=require("@unblind/units");var S={millisecond:1,second:1e3,minute:6e4,hour:36e5,day:864e5,month:24192e5,year:31536e6},$={second:[1,2,5,10,15,30],minute:[1,2,5,10,15,30],hour:[1,2,3,4,6,8,12],day:[1,2,3,7,14],month:[1,2,3,6],year:[1,2,5,10,20,50,100]};function dt(e,t,r,i){if(t>7*S.day){let o=z.systemDateFormats.interval.year,s=Math.round(S.year/S.day)*S.day;return Math.round(t/S.day)*S.day===s?o=z.systemDateFormats.interval.year:t<=S.year?o=z.systemDateFormats.interval.month:o=z.systemDateFormats.interval.day,e.map(n=>(0,z.dateTimeFormat)(n,{format:o,timeZone:i}))}return e.map(o=>{let s=new Date(o),a=t<S.minute,n=t<S.second,l=s.toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit",hour12:!1,timeZone:i});return(l==="00:00"||l==="24:00")&&!a&&!n?s.toLocaleDateString(void 0,{day:"2-digit",month:"short",timeZone:i}):s.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",second:a?"2-digit":void 0,fractionalSecondDigits:n?3:void 0,hour12:!1,timeZone:i})})}function De(e){let t=[{size:S.second/1e3,increments:$.second},{size:S.minute/1e3,increments:$.minute},{size:S.hour/1e3,increments:$.hour},{size:S.day/1e3,increments:$.day},{size:S.month/1e3,increments:$.month},{size:S.year/1e3,increments:$.year}];for(let o of t)for(let s of o.increments){let a=o.size*s;if(a>=e)return{increment:a*1e3,multiplier:s}}let r=t[t.length-1],i=r.increments[r.increments.length-1];return{increment:r.size*i*1e3,multiplier:i}}function Ne(e,t,r){return[t,r]}function ht(e,t,r,i){let o=r-t,s=e.width,a=Math.floor(s/100),n=o/a,{increment:l,multiplier:u}=De(n),m=l/1e3,d=[];if(o<12*3600){let p=Math.ceil(t/m)*m;for(;p<=r;p+=m)d.push(p);return d}if(o<3*86400){if(l>=6*3600*1e3){let h=l/1e3/3600,g=new Date(t*1e3);if(i==="UTC"){let f=g.getUTCHours(),v=Math.floor(f/h)*h;g.setUTCHours(v,0,0,0)}else{let f=g.getHours(),v=Math.floor(f/h)*h;g.setHours(v,0,0,0)}let b=g.getTime()/1e3;for(b<t&&(b+=m);b<=r;)d.push(b),b+=m;return d}let p=Math.ceil(t/m)*m;for(;p<=r;p+=m)d.push(p);return d}if(l>=S.day){let p=new Date(t*1e3);i==="UTC"?(p.setUTCHours(0,0,0,0),p.getTime()/1e3<t&&p.setUTCDate(p.getUTCDate()+u)):(p.setHours(0,0,0,0),p.getTime()/1e3<t&&p.setDate(p.getDate()+u));let h=p.getTime()/1e3;for(;h<=r;)d.push(h),i==="UTC"?p.setUTCDate(p.getUTCDate()+u):p.setDate(p.getDate()+u),h=p.getTime()/1e3;return d}let c=Math.ceil(t/m)*m;for(;c<=r;c+=m)d.push(c);return d}function Ie(e,t,r){return t.length===0?[]:t.map((i,o)=>o===0||o===t.length-1?(0,z.dateTimeFormatTimeAgo)(i*1e3,{timeZone:r}):"")}function ft(e,t,r){let i=e.scales.x,o=((i?.max??0)-(i?.min??0))*1e3,s=Math.floor(e.width/100),a=o/1e3/s,{increment:n}=De(a),l=t.map(u=>u*1e3);return dt(l,n,o,r)}function Ve(e,t,r=!1){let i=r?(a,n,l,u)=>Ne(a,l,u):(a,n,l,u)=>ht(a,l,u,t),o=r?(a,n)=>Ie(a,n,t):(a,n)=>ft(a,n,t),s=r?(a,n,l,u,m)=>{let c=document.createElement("canvas").getContext("2d");if(!c)return 0;c.font=H(e);let p=Ie(a,Ne(a,l,u),t),h=Math.max(c.measureText(p[0]||"").width,c.measureText(p[1]||"").width);return Math.ceil(h/2)+15}:void 0;return{font:H(e),labelFont:H(e),grid:{show:!1,width:.5},ticks:{width:.5},splits:i,values:o,size:20}}var He=Z(require("uplot"));var Q=require("@floating-ui/dom"),Oe=require("react-dom/client"),bt=4,gt=8,he=class{overlay=null;reactRoot=null;renderedUplot=null;initialize(){this.overlay||(this.overlay=document.createElement("div"),this.overlay.id="unblind-tooltip-overlay",this.overlay.style.display="none",this.overlay.style.position="fixed",this.overlay.style.pointerEvents="none",this.overlay.style.zIndex="9999",document.body.appendChild(this.overlay),this.reactRoot=(0,Oe.createRoot)(this.overlay))}getOverlay(){return this.overlay}render(t,r){this.reactRoot?(this.reactRoot.render(r),this.renderedUplot=t):this.renderedUplot=null}show(){this.overlay&&(this.overlay.style.display="block")}hide(t){if(t!==this.renderedUplot){console.warn("Hide call plot");return}this.overlay&&(this.overlay.style.display="none"),this.render(null,null)}getRenderedUplot(){return this.renderedUplot}async positionTooltip(t){let r=this.getOverlay();if(r){let{x:i,y:o}=await(0,Q.computePosition)({getBoundingClientRect:()=>({x:t.left,y:t.top,width:0,height:0,top:t.top,left:t.left,right:t.left,bottom:t.top})},r,{placement:"top-start",strategy:"fixed",middleware:[(0,Q.offset)({mainAxis:bt,crossAxis:gt}),(0,Q.flip)()]});r.style.left=`${i}px`,r.style.top=`${o}px`}}},L=new he;var fe=require("@unblind/units"),be=require("react");var y=require("react/jsx-runtime");function qe(e){return e.metric.displayName||e.metric.name||(typeof e.serie.label=="string"?e.serie.label:e.serie.label?.textContent||"Unknown")}function ze(e){let t=e.attributes||{};if(t["service.name"])return String(t["service.name"]);let i=Object.keys(t)[0];return i?String(t[i]):"z-fallback"}function Fe(e){return[...e].sort((t,r)=>(Number(r.value)||0)-(Number(t.value)||0))}function Be(e){return[...e].sort((t,r)=>ze(t).localeCompare(ze(r)))}function yt(e){let t={};return e.forEach(r=>{let i=qe(r);t[i]||(t[i]=[]),t[i].push(r)}),t}function Tt(e,t,r,i="original"){if(r==="flat")return[{label:"",items:t?Fe(e):Be(e)}];let o=yt(e);return Object.keys(o).sort((a,n)=>a.localeCompare(n)).map(a=>{let n=o[a];if(!n)return{label:ae(a,i),items:[]};let l=t?Fe(n):Be(n);return{label:ae(a,i),items:l}})}function ae(e,t,r){switch(t){case"suffix":{let i=e.split(/[._-]/),o=i[i.length-1]||"";return r?o:o.charAt(0).toUpperCase()+o.slice(1).toLowerCase()}case"title":return e.split(/[._-]/).map(i=>r?i:i.charAt(0).toUpperCase()+i.slice(1).toLowerCase()).join(" ");default:return e}}function vt(e,t){if(t&&t!=="auto")return t;let r=e.some(o=>o.attributes&&Object.keys(o.attributes).length>0),i=new Set(e.map(qe));return r&&i.size>=1?"group-by-metric":"flat"}function Ke({hideAttributeKey:e,attribute:t,format:r,isLastAttribute:i}){let[o,s]=t;return(0,y.jsxs)("div",{className:"ub-tooltip-item-attribute-container",children:[(0,y.jsxs)("div",{className:e?"ub-tooltip-item-hidden-attribute-key":"ub-tooltip-item-attribute-with-key",children:[!e&&(0,y.jsxs)("span",{className:"ub-tooltip-item-attribute-key",children:[ae(o,r),":"]}),(0,y.jsx)("span",{className:"ub-tooltip-item-attribute-value",children:s})]}),!i&&e&&(0,y.jsx)("span",{"data-text":", ",className:"ub-tooltip-item-attribute-divider"})]})}function xt({item:e,hideMetric:t,hideAttributeKey:r,hideAttributes:i,format:o}){let a=Object.entries(e.attributes||{}),n=a.length>0&&!i;return i&&t&&console.warn("Invalid configuration. Attributes and metrics are hidden."),(0,y.jsxs)("div",{className:"ub-tooltip-item-row",children:[(0,y.jsxs)("div",{className:"ub-tooltip-item-left"+(t?" ub-tooltip-item-hidden-metric":""),children:[(0,y.jsxs)("div",{className:"ub-tooltip-item-heading",children:[(0,y.jsx)("span",{className:"ub-tooltip-item-dot",style:{backgroundColor:e.color}}),t?(0,y.jsx)("div",{className:"ub-tooltip-item-attributes",children:a.map((l,u)=>(0,y.jsx)(Ke,{hideAttributeKey:r,attribute:l,format:o,isLastAttribute:u>=a.length-1},"attr_"+l[0]))}):(0,y.jsx)("span",{className:n?"ub-tooltip-item-metric-name-label":"ub-tooltip-item-metric-name",children:ae(e.metric.name,o)})]}),n&&!t&&(0,y.jsx)("div",{className:"ub-tooltip-item-attributes",children:a.map((l,u)=>(0,y.jsx)(Ke,{hideAttributeKey:r,attribute:l,format:o,isLastAttribute:u>=a.length-1},"attr_"+l[0]))})]}),(0,y.jsx)("div",{className:"ub-tooltip-item-value",children:e.formattedValue??(0,y.jsx)("span",{className:"ub-tooltip-item-value--empty",children:"\u2014"})})]})}function Ct({className:e="ub-tooltip-divider",...t}){return(0,y.jsx)("hr",{role:"presentation",...t,className:e})}function Pt({group:e,groupIdx:t,hideAttributeKey:r,hideMetric:i,hideAttributes:o,format:s,hideGroupLabel:a}){return(0,y.jsxs)("div",{className:"ub-tooltip-group",children:[!a&&(0,y.jsx)("div",{className:`ub-tooltip-group-header${t>0?" ub-tooltip-group-header--separator":""}`,children:e.label}),(0,y.jsx)("div",{className:"ub-tooltip-items",children:e.items.map((n,l)=>(0,y.jsx)(xt,{item:n,format:s,hideAttributeKey:r,hideMetric:i,hideAttributes:o},`item-${t}-${l}`))})]},e.label)}function Ge({timestamp:e,items:t,timeZone:r,spansMultipleDays:i,sortByValues:o,format:s="original",layout:a="flat",hideAttributeKey:n,hideMetric:l,hideAttributes:u}){let m=i?(0,fe.dateTimeFormat)(e*1e3,{format:"MMM DD, HH:mm",timeZone:r}):(0,fe.dateTimeFormat)(e*1e3,{format:"HH:mm",timeZone:r}),d=(0,be.useMemo)(()=>vt(t,a),[t,a]),c=d==="flat",h=typeof l=="boolean"?l:d==="group-by-metric",g=typeof n=="boolean"?n:!1,b=typeof u=="boolean"?u:!1,f=(0,be.useMemo)(()=>Tt(t,o,d,s),[t,o,d,s]);return(0,y.jsxs)("div",{className:"ub-tooltip",children:[(0,y.jsx)("div",{className:"ub-tooltip-datetime",children:m}),(0,y.jsx)(Ct,{}),f.length>0?(0,y.jsx)("div",{className:"ub-tooltip-content",children:f.map((v,T)=>(0,y.jsx)(Pt,{group:v,groupIdx:T,hideAttributeKey:g,hideMetric:h,hideAttributes:b,hideGroupLabel:c,format:s},v.label))}):(0,y.jsx)("div",{className:"ub-tooltip-no-data",children:"No data available"})]})}var ge=require("react/jsx-runtime");function kt(e,t){if(!e||e.length===0)return!1;let r=e[0],i=e[e.length-1];if(r==null||i==null)return!1;let o=new Date(r*1e3),s=new Date(i*1e3),a=n=>t==="UTC"?`${n.getUTCFullYear()}-${n.getUTCMonth()}-${n.getUTCDate()}`:n.toLocaleDateString(void 0,{timeZone:t});return a(o)!==a(s)}function wt(e,t){let r=!1;for(let o=1;o<e.series.length;o++)if(e.data[o]?.[t]!=null){r=!0;break}if(r)return t;let i=e.data[0].length;for(let o=1;t+o<i||t-o>=0;o++){let s=t-o,a=t+o;if(s>=0){for(let n=1;n<e.series.length;n++)if(e.data[n]?.[s]!=null)return s}if(a<i){for(let n=1;n<e.series.length;n++)if(e.data[n]?.[a]!=null)return a}}return t}function At(e,t,r,i,o,s){let a=!1,n=[];for(let l=1;l<e.series.length;l++){let u=e.data[l]?.[t]??null;if(i&&u!=null&&l>1){let b=e.data[l-1]?.[t]??0;u=u-b}let m=e.series[l],d=s?.[l-1];if(!d){console.warn("Original serie not found");continue}let c=o[d.metric];if(!c){console.warn("Metric metadata not found");continue}let p=m?.stroke,h=typeof p=="function"?p(He.default,l):p??"#ffffff00",g=u==null?void 0:r?r(u):String(u);d?.attributes&&Object.keys(d?.attributes).length>0&&(a=!0),n.push({metric:c,color:h,value:u===null?void 0:u,formattedValue:g,attributes:d?.attributes,serie:m})}return{items:n,hasAttributes:a}}function _e(e,t,r,i,o,s,a,n,l,u,m,d){let c,p,h,g=!1;function b(){let f=c.getBoundingClientRect();p=f.left,h=f.top}return{hooks:{init:f=>{L.initialize(),c=f.over,window.addEventListener("scroll",b,!0),window.addEventListener("resize",b),c.onmouseenter=()=>{g=!0,L.show()},c.onmouseleave=()=>{g=!1,L.getRenderedUplot()===f&&L.hide(f)},b()},setSize:()=>{b()},setCursor:f=>{let{left:v,top:T,idx:C}=f.cursor;if(!g||C==null){L.getRenderedUplot()===f&&L.hide(f);return}let x=f.data[0],R=kt(x,o),M=wt(f,C),w=f.data[0][M];if(w===void 0)return;let{items:E}=At(f,M,e,t,r,a);L.show();let D=s,F=D?(0,ge.jsx)(D,{timestamp:w,items:E,timeZone:o}):(0,ge.jsx)(Ge,{timestamp:w,items:E,timeZone:o,spansMultipleDays:R,stacked:t,sortByValues:i,layout:n,format:l,hideAttributeKey:u,hideAttributes:m,hideMetric:d});L.render(f,F),L.positionTooltip({left:(v||0)+p,top:(T||0)+h})},destroy(f){window.removeEventListener("scroll",b,!0),window.removeEventListener("resize",b),c&&(c.onmouseenter=null,c.onmouseleave=null),L.getRenderedUplot()===f&&L.hide(f)}}}}var se=["oklch(0.70 0.24 293)","oklch(0.85 0.18 95)","oklch(0.65 0.25 255)","oklch(0.72 0.26 27)","oklch(0.70 0.22 150)","oklch(0.78 0.18 50)","oklch(0.72 0.18 215)","oklch(0.70 0.27 301)","oklch(0.75 0.20 90)","oklch(0.68 0.23 277)","oklch(0.70 0.18 193)","oklch(0.68 0.25 4)"],H=e=>`${getComputedStyle(document.documentElement).getPropertyValue("--ub-chart-font-size").trim()} ${e}`,$e=(e,t)=>{let r=e;return t&&t.unit&&t.unit.code&&t.unit.code!=="1"&&(!r&&t.unit?r=t.unit.code:r&&t.unit.code!==r&&(r=void 0)),r};function St(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&Array.isArray(e.fill)&&Array.isArray(e.border)}function Rt(e){return Array.isArray(e)}var Qe=(e,t,r,i,o,s)=>{if(r)return Rt(r)?r[t]:St(r)?s?r.fill[t]:r.border[t]:r(e,t,i,s);let a=s?`--ub-chart-serie-color-fill-${t+1}`:`--ub-chart-serie-color-${t+1}`,n=o.getPropertyValue(a).trim();return n||(s&&(i==="step"||i==="line"||i==="spline")?`oklch(from ${se[t%se.length]} l c h / 0.4)`:se[t%se.length])},Ut=e=>{let t=X.default.paths.bars({size:[.6,100],radius:0,gap:0}),r=X.default.paths.linear({alignGaps:0}),i=X.default.paths.spline({alignGaps:1}),o=X.default.paths.stepped({alignGaps:1});switch(e){case"line":return r;case"bar":return t;case"area":return r;case"step":return o;case"spline":return i;default:return r}},Lt=(e,t,r,i,o)=>Qe(e,t,r,i,o,!0),Mt=(e,t)=>{switch(e){case"bar":return 1;case"line":return t?1.5:2;case"spline":return t?1.5:2;case"area":return 1;case"step":return 1.5;default:return 1}},Et=(e,t,r)=>{if(t<0||r<0)return[t,r];let i=e.posToVal(t,"x"),o=e.data[0];if(!o||o.length===0)return[t,r];let s=0,a=0,n=o.length-1;for(;n-a>1;){let p=Math.floor((a+n)/2),h=o[p];h!=null&&h<i?a=p:n=p}let l=o[a],u=o[n];l!=null&&u!=null?s=Math.abs(l-i)<Math.abs(u-i)?a:n:l!=null?s=a:u!=null&&(s=n);let m=s;for(let p=s;p>=0;p--){let h=!1;for(let g=1;g<e.data.length;g++){let b=e.data[g];if(b&&b[p]!=null){h=!0;break}}if(h){m=p;break}}let d=o[m];return d==null?[t,r]:[e.valToPos(d,"x"),r]},Nt=(e,t)=>{let r=t.getPropertyValue("--ub-chart-font-color").trim(),i=t.getPropertyValue("--ub-chart-grid-color").trim(),o=e.axes?.[0],s=e.axes?.[1];return o&&(o.stroke=r,o.grid?o.grid.stroke=i:o.grid={stroke:i}),s&&(s.stroke=r,s.grid?s.grid.stroke=i:s.grid={stroke:i}),e},It=(e,t)=>e.getPropertyValue(`--ub-chart-threshold-${t}`).trim()||e.getPropertyValue("--ub-chart-threshold-default").trim(),Dt=(e,t)=>e.getPropertyValue(`--ub-chart-threshold-${t}-fill`).trim()||e.getPropertyValue("--ub-chart-threshold-default-fill").trim(),Vt=e=>{switch(e){case"bold":return 2;case"line":return 1;case"dashed":return 1;default:return 1}},Ot=e=>e==="line"?void 0:[5,5],zt=(e,t)=>{if(t){let r=[];return t.forEach(i=>{let o={label:i.label,stroke:It(e,i.level),width:Vt(),dash:Ot(i.type),points:{show:!1,size:0},spanGaps:!0,show:!0,auto:!1};ne(i)||r.push(o),r.push(o)}),r}else return[]},Ft=(e,t,r,i)=>{if(!i||!i.some(s=>W(s)))return t.bands;let o=i.map((s,a)=>W(s)?{series:[e.length+a*2+1,e.length+a*2+2],fill:Dt(r,s.level),dir:1}:null).filter(s=>s!==null);return[...t.bands,...o]},Bt=(e,t,r,i,o,s,a)=>{let n=Mt(t,i);return[{},...e.map((l,u)=>({label:l.metric,stroke:Qe(l,u,r,t,s),width:n,points:{show:!1},spanGaps:!0,paths:Ut(t),fill:i||o?Lt(l,u,r,t,s):void 0})),...zt(s,a)]},Kt=e=>{if(typeof e=="string"){let t=String(e).toLowerCase().trim();if(t==="by")return"bytes";if(t.startsWith("{")&&t.endsWith("}"))return"short"}return e},We=(e,t,r,i,o,s,a,n,l,u,m,d,c,p,h,g,b,f,v,T,C)=>{let k=window.getComputedStyle(e),x=k.fontFamily,R=e?.clientWidth??1050,M=e?.clientHeight??250,w=Kt(i),E=(0,je.getValueFormat)(w==="1"?null:w),D=U=>{let A=E(U,Number.isInteger(U)?0:2);return A.text+(A.suffix?.trim()||"")},F={width:R,height:M,scales:{y:{range:Xe(i,T,C)}},plugins:[_e(D,a,t,u,m,d,o,h,p,g,b,f)],padding:c?[10,15,10,15]:[8,15,8,15],cursor:{y:!1,sync:{key:"_"},drag:{setScale:!0,x:!0,y:!1},move:Et},series:Bt(o,s,n,l,a,k,v),bands:Ft(o,r,k,v),axes:[Ve(x,m,c),Ye(E,x)],legend:{show:!1}};return Nt(F,k)};var Je=(e,t=4)=>{let r=e/t,i=Math.pow(10,Math.floor(Math.log10(r))),o=r/i,s;return o>5?s=10*i:o>2?s=5*i:o>1?s=2*i:s=i,Math.ceil(e/s)*s},P=(e,t)=>typeof e=="number"?e:t,Xe=(e,t,r)=>(i,o,s)=>{if(o===0&&s===0)return[P(t,0),P(r,100)];let a=1,n=s*(1+a),l=o<0?o*(1+a):o*(1-a);if(e==="percent"||e==="percentunit")return s>100?o<0?[P(t,l),P(r,n)]:[P(t,0),P(r,n)]:o<0?[P(t,l),P(r,100)]:[P(t,0),P(r,100)];if(s<=.9999)return o<=0?[P(t,l),P(r,1)]:[P(t,0),P(r,1)];let u=Je(n),m=Je(Math.abs(l));return o<0?[P(r,-m),P(r,u)]:[P(t,0),P(r,u)]},qt=(e,t,r,i)=>{let o=e.axes[r];if(i>1)return o?._size;let s=(o?.ticks?.size||0)+(o?.gap||0),a=(t??[]).reduce((n,l)=>l.length>n.length?l:n,"");return a!=""&&(e.ctx.font=o?.font?.[0]??e.ctx.font,s+=e.ctx.measureText(a).width/devicePixelRatio),Math.ceil(s)};function Ye(e,t){return{gap:0,font:H(t),labelFont:H(t),grid:{show:!0,width:.5},ticks:{width:.5},values:(r,i)=>i.map(o=>{let s=e(o);return s.text+(s.suffix?.trim()||"")}),size:qt,space:60}}function Ze(e,t){let r=[],i=e[0],o=i.length,s=Array(o).fill(0),a=[i];return e.forEach((n,l)=>{l!==0&&(t?a.push(n):a.push(n.map((u,m)=>s[m]=s[m]+(u||0))))}),e.forEach((n,l)=>{l===0||t||r.push({series:[e.findIndex((u,m)=>m>l),l]})}),{data:a,bands:r.filter(n=>n.series[1]>-1)}}var tt=require("react/jsx-runtime");function ue(e){let{times:t,series:r,metadata:i,type:o,className:s,timeZone:a,options:n,tooltip:l,colors:u,tooltipComponent:m,sortByValues:d=!1,unit:c,fill:p=!1,thresholds:h,min:g,max:b}=e,{layout:f,format:v,hideAttributeKey:T,hideAttributes:C,hideMetric:k}=l||{},x=(0,le.useRef)(null),R=G(),M=u||R.appearance.colors;return(0,le.useEffect)(()=>{if(!r||r.length===0){console.warn("No series provided");return}let w=[t],E=c;r.forEach(N=>{let Y=i[N.metric];c||(E=$e(E,Y)),w.push(N.values)}),h&&h.forEach(N=>{ne(N)?w.push(new Array(t.length).fill(N.value)):W(N)&&(w.push(new Array(t.length).fill(N.from)),w.push(new Array(t.length).fill(N.to)))});let D=o==="bar"||o==="area",F=Ze(w,!D),U=x.current,A=null;if(U){let N=We(U,i,F,E,r,o,D,M,p,d,a,m,!1,v,f,T,C,k,h,g,b);A=new et.default({...N,...n},F.data,U);let Y=new ResizeObserver(()=>{A?.setSize({width:U.clientWidth,height:U.clientHeight})});return Y.observe(U),()=>{A?.destroy(),Y.disconnect()}}},[r,t,o,i,a,m,M,p,d,c,v,f,T,C,k,h,g,b]),(0,tt.jsx)("div",{ref:x,className:"ub-chart-container"+(s?` ${s}`:"")})}var K=require("react/jsx-runtime");function ot({metrics:e,operator:t,attributes:r,groupBy:i,interval:o,type:s="line",className:a,appearance:n,unit:l,thresholds:u,min:m,max:d}){let c=G(),p=o??c.interval,h=r??c.attributes,g=i??c.groupBy,b=t??c.operator,f=n?.colors??c.appearance.colors,v=typeof n?.sortByValues=="boolean"?n?.sortByValues:c.appearance.sortByValues,T=typeof n?.fill=="boolean"?n.fill:c.appearance.fill,C=n?.components?.Tooltip??c.appearance.components.Tooltip,k=(0,rt.useMemo)(()=>({layout:n?.tooltip?.layout??c.appearance.tooltip?.layout,format:n?.tooltip?.format??c.appearance.tooltip?.format,hideAttributes:n?.tooltip?.hideAttributes??c.appearance.tooltip?.hideAttributes,hideAttributeKey:n?.tooltip?.hideAttributeKey??c.appearance.tooltip?.hideAttributeKey,hideMetric:n?.tooltip?.hideMetric??c.appearance.tooltip?.hideMetric}),[n?.tooltip?.layout,n?.tooltip?.format,n?.tooltip?.hideAttributes,n?.tooltip?.hideAttributeKey,n?.tooltip?.hideMetric,c.appearance.tooltip?.layout,c.appearance.tooltip?.format,c.appearance.tooltip?.hideAttributes,c.appearance.tooltip?.hideAttributeKey,c.appearance.tooltip?.hideMetric]),{isLoading:x,data:R,hasError:M}=ie({queries:(Array.isArray(e)?e:[e]).map(A=>({metrics:[A],operator:b,attributes:h,groupBy:g})),timeRange:c.timeRange,startTime:c.startTime,endTime:c.endTime,interval:p}),{series:w,times:E,metadata:D}=R,F=w.every(A=>A.isEmpty),U=`ub-chart-container${a?` ${a}`:""}`;if(x){let A=n?.components?.Loading??c.appearance.components.Loading;return(0,K.jsx)("div",{className:U,children:(0,K.jsx)(A,{})})}if(F){let A=n?.components?.Empty??c.appearance.components.Empty;return(0,K.jsx)("div",{className:U,children:(0,K.jsx)(A,{})})}if(M){let A=n?.components?.Error??c.appearance.components.Error;return(0,K.jsx)("div",{className:U,children:(0,K.jsx)(A,{})})}return(0,K.jsx)(ue,{times:E,series:w,metadata:D,type:s,className:a,tooltip:k,colors:f,sortByValues:v,unit:l,fill:T,tooltipComponent:C,thresholds:u,min:m,max:d})}0&&(module.exports={Chart,Empty,Error,Loading,Timeseries,UnblindProvider,UnblindScope,useLogs,useMetrics,useRefresh,useScope,useTimeseries,useUsage});
1
+ "use strict";var at=Object.create;var Z=Object.defineProperty;var st=Object.getOwnPropertyDescriptor;var lt=Object.getOwnPropertyNames;var ut=Object.getPrototypeOf,ct=Object.prototype.hasOwnProperty;var pt=(e,t)=>{for(var r in t)Z(e,r,{get:t[r],enumerable:!0})},ve=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of lt(t))!ct.call(e,o)&&o!==r&&Z(e,o,{get:()=>t[o],enumerable:!(i=st(t,o))||i.enumerable});return e};var ee=(e,t,r)=>(r=e!=null?at(ut(e)):{},ve(t||!e||!e.__esModule?Z(r,"default",{value:e,enumerable:!0}):r,e)),mt=e=>ve(Z({},"__esModule",{value:!0}),e);var _t={};pt(_t,{Chart:()=>ce,Empty:()=>te,Error:()=>re,Loading:()=>oe,Scope:()=>ie,Timeseries:()=>nt,UnblindProvider:()=>ke,useLogs:()=>Ie,useMetrics:()=>Ae,useRefresh:()=>de,useScope:()=>H,useTimeseries:()=>ne,useUsage:()=>Me});module.exports=mt(_t);var G=require("@tanstack/react-query"),D=require("react"),me=require("react/jsx-runtime"),xe=(0,D.createContext)(void 0);function Ce({children:e,queryClient:t,queryClientConfig:r,apiBaseUrl:i="/api/unblind",fetchImpl:o}){let s=(0,D.useMemo)(()=>{if(t)return t;let a={refetchOnWindowFocus:!1,refetchOnReconnect:!1,refetchOnMount:!1},l={defaultOptions:{queries:a}};return r?new G.QueryClient({...r,defaultOptions:{...r.defaultOptions,queries:{...a,...r.defaultOptions?.queries}}}):new G.QueryClient(l)},[t,r]),n=(0,D.useMemo)(()=>({apiBaseUrl:i,fetchImpl:o}),[i,o]);return(0,me.jsx)(G.QueryClientProvider,{client:s,children:(0,me.jsx)(xe.Provider,{value:n,children:e})})}function O(){let e=(0,D.useContext)(xe);if(!e)throw new Error("useUnblindConfig must be used within an UnblindClientProvider. Please wrap your app or component tree with <UnblindClientProvider>.");return e}function de(){let e=(0,G.useQueryClient)();return(0,D.useCallback)(async()=>{await e.refetchQueries({queryKey:["unblind","timeseries"]})},[e])}var K=require("react");var N=require("react/jsx-runtime");function te(){return(0,N.jsx)("div",{className:"ub-default",children:(0,N.jsxs)("div",{className:"ub-empty-content",children:[(0,N.jsx)("div",{className:"ub-empty-icon-wrapper",children:(0,N.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",className:"ub-icon",children:(0,N.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 6v6h4.5m4.5 0a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z"})})}),(0,N.jsx)("p",{className:"ub-empty-text","data-text":"No data available for this time range"})]})})}function re(){return(0,N.jsx)("div",{className:"ub-error"})}function oe(){return(0,N.jsx)("div",{className:"ub-default","data-text":"Loading"})}var Pe=require("react/jsx-runtime"),he=(0,K.createContext)(void 0);function ie({children:e,timeRange:t,startTime:r,endTime:i,interval:o,attributes:s,groupBy:n,operator:a,appearance:l,tooltip:c}){let m=(0,K.useContext)(he),h=l?.components?.Loading,d=l?.components?.Error,u=l?.components?.Tooltip,f=c?.layout,b=c?.format,p=c?.hideAttributes,g=c?.hideAttributeKey,v=c?.hideMetric,T=(0,K.useMemo)(()=>({components:{...h&&{Loading:h},...d&&{Error:d},...u&&{Tooltip:u}},tooltip:{layout:f,format:b,hideAttributes:p,hideAttributeKey:g,hideMetric:v}}),[h,d,u,f,b,p,g,v]),x=(0,K.useMemo)(()=>({timeRange:t??m?.timeRange,startTime:r??m?.startTime,endTime:i??m?.endTime,interval:o??m?.interval,attributes:s??m?.attributes,groupBy:n??m?.groupBy,operator:a??m?.operator,appearance:T??m?.appearance}),[t,r,i,o,s,n,a,T,m]);return(0,Pe.jsx)(he.Provider,{value:x,children:e})}var dt="6h";function H(){let e=(0,K.useContext)(he);return{timeRange:e?.timeRange||dt,startTime:e?.startTime,endTime:e?.endTime,interval:e?.interval,attributes:e?.attributes,groupBy:e?.groupBy,operator:e?.operator,colors:e?.colors,sortByValues:e?.sortByValues,fill:e?.fill,tooltip:e?.tooltip,appearance:{components:{Loading:e?.appearance?.components?.Loading??oe,Error:e?.appearance?.components?.Error??re,Empty:e?.appearance?.components?.Empty??te,Tooltip:e?.appearance?.components?.Tooltip}}}}var fe=require("react/jsx-runtime");function ke({children:e,queryClient:t,apiBaseUrl:r,fetchImpl:i,timeRange:o,startTime:s,endTime:n,interval:a,attributes:l,groupBy:c,operator:m,appearance:h,tooltip:d,colors:u,sortByValues:f}){return(0,fe.jsx)(Ce,{queryClient:t,apiBaseUrl:r,fetchImpl:i,children:(0,fe.jsx)(ie,{timeRange:o,startTime:s,endTime:n,interval:a,attributes:l,groupBy:c,operator:m,appearance:h,tooltip:d,colors:u,sortByValues:f,children:e})})}var we=require("@tanstack/react-query");function Ae(){let{apiBaseUrl:e,fetchImpl:t=fetch}=O(),r=(0,we.useQuery)({queryKey:["unblind","metrics"],queryFn:async()=>{let i=await t(`${e}/metrics`,{headers:{"Content-Type":"application/json"}});if(!i.ok)throw new Error("Error loading metrics metadata");if(i.status===200){let{data:o}=await i.json();return o}else throw new Error("Unexpected status code")}});return{metrics:r.data,isLoading:r.isLoading,hasError:r.isError,refetch:r.refetch}}var Re=require("@tanstack/react-query"),Q=require("react");var Se=ee(require("ms"));function ht(e){let t=Math.floor(Date.now()/1e3);return[t-Math.floor((0,Se.default)(e)/1e3),t]}function $(e,t,r){let i,o;if(typeof t=="number"&&typeof r=="number")i=t,o=r;else if(e){let[s,n]=ht(e);i=s,o=n}else throw new Error("Either timeRange or both startTime and endTime must be provided");return[i,o]}function ne({queries:e,timeRange:t,startTime:r,endTime:i,interval:o}){let{apiBaseUrl:s,fetchImpl:n=fetch}=O(),a=(0,Q.useMemo)(()=>e.map(T=>T.metrics.join(",")).join(","),[e]),l=(0,Q.useMemo)(()=>e.map(T=>{let x=T.attributes;if(!x)return"";let k=Object.keys(x);return k.length===0?"":k.map(C=>C+":"+x[C]?.join(",")).join(",")}).join(","),[e]),c=(0,Q.useMemo)(()=>e.map(T=>T.operator),[e]),m=(0,Q.useMemo)(()=>e.map(T=>T.groupBy).join(", "),[e]),d=(0,Re.useQuery)({queryKey:["unblind","timeseries",a,l,r,i,t,o,c,m],queryFn:async()=>{if(!a)throw new Error("Missing required parameters");if(a.length===0)throw new Error("No series provided");let[T,x]=$(t,r,i),k={queries:e,startTime:T,endTime:x,interval:o},C=await n(`${s}/tenants/timeseries`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(k)});if(!C.ok)throw new Error("Error fetching metric");let{series:S,times:M,metadata:w}=await C.json();if(!S)throw console.error("Series not found"),new Error("Series not found");return{series:S,times:M,metadata:w}},enabled:!!a&&(typeof r=="number"&&typeof i=="number"||!!t)}),{metadata:u,series:f,times:b}=(0,Q.useMemo)(()=>d.data?{series:d.data.series,times:d.data.times,metadata:d.data.metadata}:{series:[],times:[],metadata:{}},[d]),p=d.isLoading,g=d.isFetching,v=d.isError;return{data:{series:f,times:b,metadata:u},isLoading:p,isFetching:g,hasError:v,refetch:d.refetch}}var Ue=require("@tanstack/react-query"),Le=require("react");function Me({timeRange:e,startTime:t,endTime:r}){let{apiBaseUrl:i,fetchImpl:o=fetch}=O(),n=(0,Ue.useQuery)({queryKey:["unblind","usage",e,t,r],queryFn:async()=>{let[m,h]=$(e,t,r),d=`${i}/tenants/usage`,u=await o(d,{headers:{"Content-Type":"application/json"},body:JSON.stringify({startTime:m,endTime:h})});if(!u.ok)throw new Error("Error fetching usage");let{data:f}=await u.json();if(!f)throw new Error("usage not found");return f},enabled:typeof t=="number"&&typeof r=="number"||!!e}),a=(0,Le.useMemo)(()=>n.data?n.data||[]:[],[n]),l=n.isLoading||n.isRefetching,c=n.isError;return{usage:a,isLoading:l,hasError:c,refetch:n.refetch}}var Ee=require("@tanstack/react-query"),Ne=require("react");function Ie({timeRange:e,filters:t,startTime:r,endTime:i}){let{apiBaseUrl:o,fetchImpl:s=fetch}=O(),n=typeof r=="number"&&typeof i=="number"||!!e,a=(0,Ee.useInfiniteQuery)({queryKey:["unblind","logs",e,t.map(c=>c.name+":"+c.value).sort().join(",")],queryFn:async({pageParam:c})=>{let m=t.reduce((C,S)=>(C[S.name]||(C[S.name]=[]),C[S.name].push(S.value),C),{}),{body:h=[],severity:d=[],"service.name":u=[],"trace.id":f=[],"span.id":b=[],...p}=m,[g,v]=$(e,r,i),T=await s(`${o}/tenants/logs`,{method:"POST",body:JSON.stringify({filter:{attributes:p,body:h,severity:d,traceId:f,spanId:b,service:u},startTime:g,endTime:v,pagination:{page:c}}),headers:{"Content-Type":"application/json"}});if(!T.ok)throw new Error("Error fetching logs");let{data:x,next_page:k}=await T.json();if(!x)throw new Error("logs not found");return{data:x,next_page:k}},enabled:n,initialPageParam:void 0,getNextPageParam:c=>c.next_page});return{logs:(0,Ne.useMemo)(()=>a.data?a.data.pages.flatMap(c=>c.data||[]):[],[a.data]),isLoading:a.isLoading,hasError:a.isError,hasNextPage:a.hasNextPage??!1,fetchNextPage:a.fetchNextPage,isFetchingNextPage:a.isFetchingNextPage,refetch:a.refetch}}var it=require("react");var ue=require("react"),rt=ee(require("uplot"));var ae=e=>"value"in e,Y=e=>"from"in e&&"to"in e;var J=ee(require("uplot")),Qe=require("@unblind/units");var z=require("@unblind/units");var A={millisecond:1,second:1e3,minute:6e4,hour:36e5,day:864e5,month:24192e5,year:31536e6},W={second:[1,2,5,10,15,30],minute:[1,2,5,10,15,30],hour:[1,2,3,4,6,8,12],day:[1,2,3,7,14],month:[1,2,3,6],year:[1,2,5,10,20,50,100]};function ft(e,t,r,i){if(t>7*A.day){let o=z.systemDateFormats.interval.year,s=Math.round(A.year/A.day)*A.day;return Math.round(t/A.day)*A.day===s?o=z.systemDateFormats.interval.year:t<=A.year?o=z.systemDateFormats.interval.month:o=z.systemDateFormats.interval.day,e.map(a=>(0,z.dateTimeFormat)(a,{format:o,timeZone:i}))}return e.map(o=>{let s=new Date(o),n=t<A.minute,a=t<A.second,l=s.toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit",hour12:!1,timeZone:i});return(l==="00:00"||l==="24:00")&&!n&&!a?s.toLocaleDateString(void 0,{day:"2-digit",month:"short",timeZone:i}):s.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",second:n?"2-digit":void 0,fractionalSecondDigits:a?3:void 0,hour12:!1,timeZone:i})})}function Oe(e){let t=[{size:A.second/1e3,increments:W.second},{size:A.minute/1e3,increments:W.minute},{size:A.hour/1e3,increments:W.hour},{size:A.day/1e3,increments:W.day},{size:A.month/1e3,increments:W.month},{size:A.year/1e3,increments:W.year}];for(let o of t)for(let s of o.increments){let n=o.size*s;if(n>=e)return{increment:n*1e3,multiplier:s}}let r=t[t.length-1],i=r.increments[r.increments.length-1];return{increment:r.size*i*1e3,multiplier:i}}function Ve(e,t,r){return[t,r]}function gt(e,t,r,i){let o=r-t,s=e.width,n=Math.floor(s/100),a=o/n,{increment:l,multiplier:c}=Oe(a),m=l/1e3,h=[];if(o<12*3600){let u=Math.ceil(t/m)*m;for(;u<=r;u+=m)h.push(u);return h}if(o<3*86400){if(l>=6*3600*1e3){let f=l/1e3/3600,b=new Date(t*1e3);if(i==="UTC"){let g=b.getUTCHours(),v=Math.floor(g/f)*f;b.setUTCHours(v,0,0,0)}else{let g=b.getHours(),v=Math.floor(g/f)*f;b.setHours(v,0,0,0)}let p=b.getTime()/1e3;for(p<t&&(p+=m);p<=r;)h.push(p),p+=m;return h}let u=Math.ceil(t/m)*m;for(;u<=r;u+=m)h.push(u);return h}if(l>=A.day){let u=new Date(t*1e3);i==="UTC"?(u.setUTCHours(0,0,0,0),u.getTime()/1e3<t&&u.setUTCDate(u.getUTCDate()+c)):(u.setHours(0,0,0,0),u.getTime()/1e3<t&&u.setDate(u.getDate()+c));let f=u.getTime()/1e3;for(;f<=r;)h.push(f),i==="UTC"?u.setUTCDate(u.getUTCDate()+c):u.setDate(u.getDate()+c),f=u.getTime()/1e3;return h}let d=Math.ceil(t/m)*m;for(;d<=r;d+=m)h.push(d);return h}function De(e,t,r){return t.length===0?[]:t.map((i,o)=>o===0||o===t.length-1?(0,z.dateTimeFormatTimeAgo)(i*1e3,{timeZone:r}):"")}function bt(e,t,r){let i=e.scales.x,o=((i?.max??0)-(i?.min??0))*1e3,s=Math.floor(e.width/100),n=o/1e3/s,{increment:a}=Oe(n),l=t.map(c=>c*1e3);return ft(l,a,o,r)}function ze(e,t,r=!1){let i=r?(n,a,l,c)=>Ve(n,l,c):(n,a,l,c)=>gt(n,l,c,t),o=r?(n,a)=>De(n,a,t):(n,a)=>bt(n,a,t),s=r?(n,a,l,c,m)=>{let d=document.createElement("canvas").getContext("2d");if(!d)return 0;d.font=_(e);let u=De(n,Ve(n,l,c),t),f=Math.max(d.measureText(u[0]||"").width,d.measureText(u[1]||"").width);return Math.ceil(f/2)+15}:void 0;return{font:_(e),labelFont:_(e),grid:{show:!1,width:.5},ticks:{width:.5},splits:i,values:o,size:20}}var je=ee(require("uplot"));var X=require("@floating-ui/dom"),Fe=require("react-dom/client"),yt=4,Tt=8,ge=class{overlay=null;reactRoot=null;renderedUplot=null;initialize(){this.overlay||(this.overlay=document.createElement("div"),this.overlay.id="unblind-tooltip-overlay",this.overlay.style.display="none",this.overlay.style.position="fixed",this.overlay.style.pointerEvents="none",this.overlay.style.zIndex="9999",document.body.appendChild(this.overlay),this.reactRoot=(0,Fe.createRoot)(this.overlay))}getOverlay(){return this.overlay}render(t,r){this.reactRoot?(this.reactRoot.render(r),this.renderedUplot=t):this.renderedUplot=null}show(){this.overlay&&(this.overlay.style.display="block")}hide(t){if(t!==this.renderedUplot){console.warn("Hide call plot");return}this.overlay&&(this.overlay.style.display="none"),this.render(null,null)}getRenderedUplot(){return this.renderedUplot}async positionTooltip(t){let r=this.getOverlay();if(r){let{x:i,y:o}=await(0,X.computePosition)({getBoundingClientRect:()=>({x:t.left,y:t.top,width:0,height:0,top:t.top,left:t.left,right:t.left,bottom:t.top})},r,{placement:"top-start",strategy:"fixed",middleware:[(0,X.offset)({mainAxis:yt,crossAxis:Tt}),(0,X.flip)()]});r.style.left=`${i}px`,r.style.top=`${o}px`}}},L=new ge;var be=require("@unblind/units"),ye=require("react");var y=require("react/jsx-runtime");function He(e){return e.metric.displayName||e.metric.name||(typeof e.serie.label=="string"?e.serie.label:e.serie.label?.textContent||"Unknown")}function Be(e){let t=e.attributes||{};if(t["service.name"])return String(t["service.name"]);let i=Object.keys(t)[0];return i?String(t[i]):"z-fallback"}function Ke(e){return[...e].sort((t,r)=>(Number(r.value)||0)-(Number(t.value)||0))}function qe(e){return[...e].sort((t,r)=>Be(t).localeCompare(Be(r)))}function vt(e){let t={};return e.forEach(r=>{let i=He(r);t[i]||(t[i]=[]),t[i].push(r)}),t}function xt(e,t,r,i="original"){if(r==="flat")return[{label:"",items:t?Ke(e):qe(e)}];let o=vt(e);return Object.keys(o).sort((n,a)=>n.localeCompare(a)).map(n=>{let a=o[n];if(!a)return{label:se(n,i),items:[]};let l=t?Ke(a):qe(a);return{label:se(n,i),items:l}})}function se(e,t,r){switch(t){case"suffix":{let i=e.split(/[._-]/),o=i[i.length-1]||"";return r?o:o.charAt(0).toUpperCase()+o.slice(1).toLowerCase()}case"title":return e.split(/[._-]/).map(i=>r?i:i.charAt(0).toUpperCase()+i.slice(1).toLowerCase()).join(" ");default:return e}}function Ct(e,t){if(t&&t!=="auto")return t;let r=e.some(o=>o.attributes&&Object.keys(o.attributes).length>0),i=new Set(e.map(He));return r&&i.size>=1?"group-by-metric":"flat"}function Ge({hideAttributeKey:e,attribute:t,format:r,isLastAttribute:i}){let[o,s]=t;return(0,y.jsxs)("div",{className:"ub-tooltip-item-attribute-container",children:[(0,y.jsxs)("div",{className:e?"ub-tooltip-item-hidden-attribute-key":"ub-tooltip-item-attribute-with-key",children:[!e&&(0,y.jsxs)("span",{className:"ub-tooltip-item-attribute-key",children:[se(o,r),":"]}),(0,y.jsx)("span",{className:"ub-tooltip-item-attribute-value",children:s})]}),!i&&e&&(0,y.jsx)("span",{"data-text":", ",className:"ub-tooltip-item-attribute-divider"})]})}function Pt({item:e,hideMetric:t,hideAttributeKey:r,hideAttributes:i,format:o}){let n=Object.entries(e.attributes||{}),a=n.length>0&&!i;return i&&t&&console.warn("Invalid configuration. Attributes and metrics are hidden."),(0,y.jsxs)("div",{className:"ub-tooltip-item-row",children:[(0,y.jsxs)("div",{className:"ub-tooltip-item-left"+(t?" ub-tooltip-item-hidden-metric":""),children:[(0,y.jsxs)("div",{className:"ub-tooltip-item-heading",children:[(0,y.jsx)("span",{className:"ub-tooltip-item-dot",style:{backgroundColor:e.color}}),t?(0,y.jsx)("div",{className:"ub-tooltip-item-attributes",children:n.map((l,c)=>(0,y.jsx)(Ge,{hideAttributeKey:r,attribute:l,format:o,isLastAttribute:c>=n.length-1},"attr_"+l[0]))}):(0,y.jsx)("span",{className:a?"ub-tooltip-item-metric-name-label":"ub-tooltip-item-metric-name",children:se(e.metric.name,o)})]}),a&&!t&&(0,y.jsx)("div",{className:"ub-tooltip-item-attributes",children:n.map((l,c)=>(0,y.jsx)(Ge,{hideAttributeKey:r,attribute:l,format:o,isLastAttribute:c>=n.length-1},"attr_"+l[0]))})]}),(0,y.jsx)("div",{className:"ub-tooltip-item-value",children:e.formattedValue??(0,y.jsx)("span",{className:"ub-tooltip-item-value--empty",children:"\u2014"})})]})}function kt({className:e="ub-tooltip-divider",...t}){return(0,y.jsx)("hr",{role:"presentation",...t,className:e})}function wt({group:e,groupIdx:t,hideAttributeKey:r,hideMetric:i,hideAttributes:o,format:s,hideGroupLabel:n}){return(0,y.jsxs)("div",{className:"ub-tooltip-group",children:[!n&&(0,y.jsx)("div",{className:`ub-tooltip-group-header${t>0?" ub-tooltip-group-header--separator":""}`,children:e.label}),(0,y.jsx)("div",{className:"ub-tooltip-items",children:e.items.map((a,l)=>(0,y.jsx)(Pt,{item:a,format:s,hideAttributeKey:r,hideMetric:i,hideAttributes:o},`item-${t}-${l}`))})]},e.label)}function _e({timestamp:e,items:t,timeZone:r,spansMultipleDays:i,sortByValues:o,format:s="original",layout:n="flat",hideAttributeKey:a,hideMetric:l,hideAttributes:c}){let m=i?(0,be.dateTimeFormat)(e*1e3,{format:"MMM DD, HH:mm",timeZone:r}):(0,be.dateTimeFormat)(e*1e3,{format:"HH:mm",timeZone:r}),h=(0,ye.useMemo)(()=>Ct(t,n),[t,n]),d=h==="flat",f=typeof l=="boolean"?l:h==="group-by-metric",b=typeof a=="boolean"?a:!1,p=typeof c=="boolean"?c:!1,g=(0,ye.useMemo)(()=>xt(t,o,h,s),[t,o,h,s]);return(0,y.jsxs)("div",{className:"ub-tooltip",children:[(0,y.jsx)("div",{className:"ub-tooltip-datetime",children:m}),(0,y.jsx)(kt,{}),g.length>0?(0,y.jsx)("div",{className:"ub-tooltip-content",children:g.map((v,T)=>(0,y.jsx)(wt,{group:v,groupIdx:T,hideAttributeKey:b,hideMetric:f,hideAttributes:p,hideGroupLabel:d,format:s},v.label))}):(0,y.jsx)("div",{className:"ub-tooltip-no-data",children:"No data available"})]})}var Te=require("react/jsx-runtime");function At(e,t){if(!e||e.length===0)return!1;let r=e[0],i=e[e.length-1];if(r==null||i==null)return!1;let o=new Date(r*1e3),s=new Date(i*1e3),n=a=>t==="UTC"?`${a.getUTCFullYear()}-${a.getUTCMonth()}-${a.getUTCDate()}`:a.toLocaleDateString(void 0,{timeZone:t});return n(o)!==n(s)}function St(e,t){let r=!1;for(let o=1;o<e.series.length;o++)if(e.data[o]?.[t]!=null){r=!0;break}if(r)return t;let i=e.data[0].length;for(let o=1;t+o<i||t-o>=0;o++){let s=t-o,n=t+o;if(s>=0){for(let a=1;a<e.series.length;a++)if(e.data[a]?.[s]!=null)return s}if(n<i){for(let a=1;a<e.series.length;a++)if(e.data[a]?.[n]!=null)return n}}return t}function Rt(e,t,r,i,o,s){let n=!1,a=[];for(let l=1;l<e.series.length;l++){let c=e.data[l]?.[t]??null;if(i&&c!=null&&l>1){let p=e.data[l-1]?.[t]??0;c=c-p}let m=e.series[l],h=s?.[l-1];if(!h){console.warn("Original serie not found");continue}let d=o[h.metric];if(!d){console.warn("Metric metadata not found");continue}let u=m?.stroke,f=typeof u=="function"?u(je.default,l):u??"#ffffff00",b=c==null?void 0:r?r(c):String(c);h?.attributes&&Object.keys(h?.attributes).length>0&&(n=!0),a.push({metric:d,color:f,value:c===null?void 0:c,formattedValue:b,attributes:h?.attributes,serie:m})}return{items:a,hasAttributes:n}}function $e(e,t,r,i,o,s,n,a,l,c,m,h){let d,u,f,b=!1;function p(){let g=d.getBoundingClientRect();u=g.left,f=g.top}return{hooks:{init:g=>{L.initialize(),d=g.over,window.addEventListener("scroll",p,!0),window.addEventListener("resize",p),d.onmouseenter=()=>{b=!0,L.show()},d.onmouseleave=()=>{b=!1,L.getRenderedUplot()===g&&L.hide(g)},p()},setSize:()=>{p()},setCursor:g=>{let{left:v,top:T,idx:x}=g.cursor;if(!b||x==null){L.getRenderedUplot()===g&&L.hide(g);return}let C=g.data[0],S=At(C,o),M=St(g,x),w=g.data[0][M];if(w===void 0)return;let{items:E}=Rt(g,M,e,t,r,n);L.show();let I=s,F=I?(0,Te.jsx)(I,{timestamp:w,items:E,timeZone:o}):(0,Te.jsx)(_e,{timestamp:w,items:E,timeZone:o,spansMultipleDays:S,stacked:t,sortByValues:i,layout:a,format:l,hideAttributeKey:c,hideAttributes:m,hideMetric:h});L.render(g,F),L.positionTooltip({left:(v||0)+u,top:(T||0)+f})},destroy(g){window.removeEventListener("scroll",p,!0),window.removeEventListener("resize",p),d&&(d.onmouseenter=null,d.onmouseleave=null),L.getRenderedUplot()===g&&L.hide(g)}}}}var le=["oklch(0.70 0.24 293)","oklch(0.85 0.18 95)","oklch(0.65 0.25 255)","oklch(0.72 0.26 27)","oklch(0.70 0.22 150)","oklch(0.78 0.18 50)","oklch(0.72 0.18 215)","oklch(0.70 0.27 301)","oklch(0.75 0.20 90)","oklch(0.68 0.23 277)","oklch(0.70 0.18 193)","oklch(0.68 0.25 4)"],_=e=>`${getComputedStyle(document.documentElement).getPropertyValue("--ub-chart-font-size").trim()} ${e}`,We=(e,t)=>{let r=e;return t&&t.unit&&t.unit.code&&t.unit.code!=="1"&&(!r&&t.unit?r=t.unit.code:r&&t.unit.code!==r&&(r=void 0)),r};function Ut(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&Array.isArray(e.fill)&&Array.isArray(e.border)}function Lt(e){return Array.isArray(e)}var Xe=(e,t,r,i,o,s)=>{if(r)return Lt(r)?r[t]:Ut(r)?s?r.fill[t]:r.border[t]:r(e,t,i,s);let n=s?`--ub-chart-serie-color-fill-${t+1}`:`--ub-chart-serie-color-${t+1}`,a=o.getPropertyValue(n).trim();return a||(s&&(i==="step"||i==="line"||i==="spline")?`oklch(from ${le[t%le.length]} l c h / 0.4)`:le[t%le.length])},Mt=e=>{let t=J.default.paths.bars({size:[.6,100],radius:0,gap:0}),r=J.default.paths.linear({alignGaps:0}),i=J.default.paths.spline({alignGaps:1}),o=J.default.paths.stepped({alignGaps:1});switch(e){case"line":return r;case"bar":return t;case"area":return r;case"step":return o;case"spline":return i;default:return r}},Et=(e,t,r,i,o)=>Xe(e,t,r,i,o,!0),Nt=(e,t)=>{switch(e){case"bar":return 1;case"line":return t?1.5:2;case"spline":return t?1.5:2;case"area":return 1;case"step":return 1.5;default:return 1}},It=(e,t,r)=>{if(t<0||r<0)return[t,r];let i=e.posToVal(t,"x"),o=e.data[0];if(!o||o.length===0)return[t,r];let s=0,n=0,a=o.length-1;for(;a-n>1;){let u=Math.floor((n+a)/2),f=o[u];f!=null&&f<i?n=u:a=u}let l=o[n],c=o[a];l!=null&&c!=null?s=Math.abs(l-i)<Math.abs(c-i)?n:a:l!=null?s=n:c!=null&&(s=a);let m=s;for(let u=s;u>=0;u--){let f=!1;for(let b=1;b<e.data.length;b++){let p=e.data[b];if(p&&p[u]!=null){f=!0;break}}if(f){m=u;break}}let h=o[m];return h==null?[t,r]:[e.valToPos(h,"x"),r]},Vt=(e,t)=>{let r=t.getPropertyValue("--ub-chart-font-color").trim(),i=t.getPropertyValue("--ub-chart-grid-color").trim(),o=e.axes?.[0],s=e.axes?.[1];return o&&(o.stroke=r,o.grid?o.grid.stroke=i:o.grid={stroke:i}),s&&(s.stroke=r,s.grid?s.grid.stroke=i:s.grid={stroke:i}),e},Dt=(e,t)=>e.getPropertyValue(`--ub-chart-threshold-${t}`).trim()||e.getPropertyValue("--ub-chart-threshold-default").trim(),Ot=(e,t)=>e.getPropertyValue(`--ub-chart-threshold-${t}-fill`).trim()||e.getPropertyValue("--ub-chart-threshold-default-fill").trim(),zt=e=>{switch(e){case"bold":return 2;case"line":return 1;case"dashed":return 1;default:return 1}},Ft=e=>e==="line"?void 0:[5,5],Bt=(e,t)=>{if(t){let r=[];return t.forEach(i=>{let o={label:i.label,stroke:Dt(e,i.level),width:zt(),dash:Ft(i.type),points:{show:!1,size:0},spanGaps:!0,show:!0,auto:!1};ae(i)||r.push(o),r.push(o)}),r}else return[]},Kt=(e,t,r,i)=>{if(!i||!i.some(s=>Y(s)))return t.bands;let o=i.map((s,n)=>Y(s)?{series:[e.length+n*2+1,e.length+n*2+2],fill:Ot(r,s.level),dir:1}:null).filter(s=>s!==null);return[...t.bands,...o]},qt=(e,t,r,i,o,s,n)=>{let a=Nt(t,i);return[{},...e.map((l,c)=>({label:l.metric,stroke:Xe(l,c,r,t,s),width:a,points:{show:!1},spanGaps:!0,paths:Mt(t),fill:i||o?Et(l,c,r,t,s):void 0})),...Bt(s,n)]},Gt=e=>{if(typeof e=="string"){let t=String(e).toLowerCase().trim();if(t==="by")return"bytes";if(t.startsWith("{")&&t.endsWith("}"))return"short"}return e},Ye=(e,t,r,i,o,s,n,a,l,c,m,h,d,u,f,b,p,g,v,T,x)=>{let k=window.getComputedStyle(e),C=k.fontFamily,S=e?.clientWidth??1050,M=e?.clientHeight??250,w=Gt(i),E=(0,Qe.getValueFormat)(w==="1"?null:w),I=R=>{let B=E(R,Number.isInteger(R)?0:2);return B.text+(B.suffix?.trim()||"")},F={width:S,height:M,scales:{y:{range:Je(i,T,x)}},plugins:[$e(I,n,t,c,m,h,o,f,u,b,p,g)],padding:d?[10,15,10,15]:[8,15,8,15],cursor:{y:!1,sync:{key:"_"},drag:{setScale:!0,x:!0,y:!1},move:It},series:qt(o,s,a,l,n,k,v),bands:Kt(o,r,k,v),axes:[ze(C,m,d),Ze(E,C)],legend:{show:!1}};return Vt(F,k)};var et=(e,t=4)=>{let r=e/t,i=Math.pow(10,Math.floor(Math.log10(r))),o=r/i,s;return o>5?s=10*i:o>2?s=5*i:o>1?s=2*i:s=i,Math.ceil(e/s)*s},P=(e,t)=>typeof e=="number"?e:t,Je=(e,t,r)=>(i,o,s)=>{if(o===0&&s===0)return[P(t,0),P(r,100)];let n=1,a=s*(1+n),l=o<0?o*(1+n):o*(1-n);if(e==="percent"||e==="percentunit")return s>100?o<0?[P(t,l),P(r,a)]:[P(t,0),P(r,a)]:o<0?[P(t,l),P(r,100)]:[P(t,0),P(r,100)];if(s<=.9999)return o<=0?[P(t,l),P(r,1)]:[P(t,0),P(r,1)];let c=et(a),m=et(Math.abs(l));return o<0?[P(r,-m),P(r,c)]:[P(t,0),P(r,c)]},Ht=(e,t,r,i)=>{let o=e.axes[r];if(i>1)return o?._size;let s=(o?.ticks?.size||0)+(o?.gap||0),n=(t??[]).reduce((a,l)=>l.length>a.length?l:a,"");return n!=""&&(e.ctx.font=o?.font?.[0]??e.ctx.font,s+=e.ctx.measureText(n).width/devicePixelRatio),Math.ceil(s)};function Ze(e,t){return{gap:0,font:_(t),labelFont:_(t),grid:{show:!0,width:.5},ticks:{width:.5},values:(r,i)=>i.map(o=>{let s=e(o);return s.text+(s.suffix?.trim()||"")}),size:Ht,space:60}}function tt(e,t){let r=[],i=e[0],o=i.length,s=Array(o).fill(0),n=[i];return e.forEach((a,l)=>{l!==0&&(t?n.push(a):n.push(a.map((c,m)=>s[m]=s[m]+(c||0))))}),e.forEach((a,l)=>{l===0||t||r.push({series:[e.findIndex((c,m)=>m>l),l]})}),{data:n,bands:r.filter(a=>a.series[1]>-1)}}var ot=require("react/jsx-runtime");function ce(e){let{times:t,series:r,metadata:i,type:o,className:s,timeZone:n,options:a,tooltip:l,colors:c,tooltipComponent:m,sortByValues:h=!1,unit:d,fill:u=!1,thresholds:f,min:b,max:p}=e,{layout:g,format:v,hideAttributeKey:T,hideAttributes:x,hideMetric:k}=l||{},C=(0,ue.useRef)(null),S=H(),M=c||S.colors;return(0,ue.useEffect)(()=>{if(!r||r.length===0){console.warn("No series provided");return}let w=[t],E=d;r.forEach(U=>{let j=i[U.metric];d||(E=We(E,j)),w.push(U.values)}),f&&f.forEach(U=>{ae(U)?w.push(new Array(t.length).fill(U.value)):Y(U)&&(w.push(new Array(t.length).fill(U.from)),w.push(new Array(t.length).fill(U.to)))});let I=o==="bar"||o==="area",F=tt(w,!I),R=C.current,B=null;if(R){let U=Ye(R,i,F,E,r,o,I,M,u,h,n,m,!1,v,g,T,x,k,f,b,p);B=new rt.default({...U,...a},F.data,R);let j=new ResizeObserver(()=>{B?.setSize({width:R.clientWidth,height:R.clientHeight})});return j.observe(R),()=>{B?.destroy(),j.disconnect()}}},[r,t,o,i,n,m,M,u,h,d,v,g,T,x,k,f,b,p]),(0,ot.jsx)("div",{ref:C,className:"ub-chart-container"+(s?` ${s}`:"")})}var q=require("react/jsx-runtime");function nt({metrics:e,operator:t,attributes:r,groupBy:i,interval:o,type:s="line",className:n,appearance:a,unit:l,thresholds:c,min:m,max:h,colors:d,tooltip:u,sortByValues:f,fill:b}){let p=H(),g=o??p.interval,v=r??p.attributes,T=i??p.groupBy,x=t??p.operator,k=d??p.colors,C=typeof f=="boolean"?f:p.sortByValues,S=typeof b=="boolean"?b:p.fill,M=a?.components?.Tooltip??p.appearance.components.Tooltip,w=(0,it.useMemo)(()=>({layout:u?.layout??p.tooltip?.layout,format:u?.format??p.tooltip?.format,hideAttributes:u?.hideAttributes??p.tooltip?.hideAttributes,hideAttributeKey:u?.hideAttributeKey??p.tooltip?.hideAttributeKey,hideMetric:u?.hideMetric??p.tooltip?.hideMetric}),[u?.layout,u?.format,u?.hideAttributes,u?.hideAttributeKey,u?.hideMetric,p.tooltip?.layout,p.tooltip?.format,p.tooltip?.hideAttributes,p.tooltip?.hideAttributeKey,p.tooltip?.hideMetric]),{isLoading:E,data:I,hasError:F}=ne({queries:(Array.isArray(e)?e:[e]).map(V=>({metrics:[V],operator:x,attributes:v,groupBy:T})),timeRange:p.timeRange,startTime:p.startTime,endTime:p.endTime,interval:g}),{series:R,times:B,metadata:U}=I,j=R.every(V=>V.isEmpty),pe=`ub-chart-container${n?` ${n}`:""}`;if(E){let V=a?.components?.Loading??p.appearance.components.Loading;return(0,q.jsx)("div",{className:pe,children:(0,q.jsx)(V,{})})}if(j){let V=a?.components?.Empty??p.appearance.components.Empty;return(0,q.jsx)("div",{className:pe,children:(0,q.jsx)(V,{})})}if(F){let V=a?.components?.Error??p.appearance.components.Error;return(0,q.jsx)("div",{className:pe,children:(0,q.jsx)(V,{})})}return(0,q.jsx)(ce,{times:B,series:R,metadata:U,type:s,className:n,tooltip:w,colors:k,sortByValues:C,unit:l,fill:S,tooltipComponent:M,thresholds:c,min:m,max:h})}0&&(module.exports={Chart,Empty,Error,Loading,Scope,Timeseries,UnblindProvider,useLogs,useMetrics,useRefresh,useScope,useTimeseries,useUsage});
2
2
  //# sourceMappingURL=index.js.map