@pond-ts/react 0.5.1 → 0.5.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.
@@ -1,21 +1,5 @@
1
- import type { AggregateMap, AggregateReducer, DurationInput, LiveSource, NormalizedValueForKind, ScalarKind, SeriesSchema, ValueColumnsForSchema } from 'pond-ts';
1
+ import type { AggregateMap, DurationInput, LiveSource, ReduceResult, SeriesSchema } from 'pond-ts';
2
2
  import { type SnapshotSource, type UseSnapshotOptions } from './useSnapshot.js';
3
- /**
4
- * Narrowed per-entry output for `useCurrent`. Derives each field's value
5
- * type from the source column kind and the reducer name so callers don't
6
- * have to `as`-cast. Numeric reducers (`'sum'`, `'avg'`, `'count'`) emit
7
- * `number`; `'unique'` and `` `top${number}` `` emit
8
- * `ReadonlyArray<ScalarValue>`; other reducers (including custom
9
- * functions) fall back to the source column kind.
10
- */
11
- type CurrentResult<S extends SeriesSchema, Mapping> = {
12
- [K in keyof Mapping & string]: NormalizedValueForKind<K extends ValueColumnsForSchema<S>[number]['name'] ? Mapping[K] extends 'sum' | 'avg' | 'count' ? 'number' : Mapping[K] extends 'unique' | `top${number}` ? 'array' : CurrentColumnKind<S, K> : ScalarKind> | undefined;
13
- };
14
- type CurrentColumnKind<S extends SeriesSchema, K extends string> = Extract<ValueColumnsForSchema<S>[number], {
15
- name: K;
16
- }> extends {
17
- kind: infer Kind extends ScalarKind;
18
- } ? Kind : ScalarKind;
19
3
  export interface UseCurrentOptions extends UseSnapshotOptions {
20
4
  /**
21
5
  * Trailing window to evaluate the mapping over, expressed as a
@@ -28,21 +12,20 @@ export interface UseCurrentOptions extends UseSnapshotOptions {
28
12
  * Subscribe to a live source and return the current value of a reducer
29
13
  * mapping, updated on a throttle. Equivalent to
30
14
  * `useSnapshot(src).tail(tail).reduce(mapping)` but with one subscription,
31
- * one memo, and narrow per-entry types.
15
+ * one memo, and narrow per-entry types inherited from
16
+ * `TimeSeries.reduce`.
32
17
  *
33
18
  * ```ts
34
19
  * const current = useCurrent(live, { cpu: 'avg', host: 'unique' });
35
- * // ^ { cpu: number | undefined; host: ReadonlyArray<ScalarValue> | undefined }
20
+ * // ^ { cpu: number | undefined;
21
+ * // host: ReadonlyArray<ScalarValue> | undefined }
36
22
  *
37
23
  * const recent = useCurrent(live, { cpu: 'p95' }, { tail: '30s' });
38
24
  * ```
39
25
  *
40
- * Returns an empty-result object (every mapped field set to the
41
- * reducer's empty-bucket value) while the source has no events — the
42
- * shape of the return is stable regardless of source state, so
43
- * destructuring is always safe.
26
+ * Returns a stable-shape object while the source has no events (every
27
+ * mapped field is `undefined`), so destructuring on first render is
28
+ * safe.
44
29
  */
45
- export declare function useCurrent<S extends SeriesSchema, const Mapping extends AggregateMap<S>>(source: SnapshotSource<S> | LiveSource<S> | null, mapping: Mapping, options?: UseCurrentOptions): CurrentResult<S, Mapping>;
46
- export type _UseCurrentReducerHint = AggregateReducer;
47
- export {};
30
+ export declare function useCurrent<S extends SeriesSchema, const Mapping extends AggregateMap<S>>(source: SnapshotSource<S> | LiveSource<S> | null, mapping: Mapping, options?: UseCurrentOptions): ReduceResult<S, Mapping>;
48
31
  //# sourceMappingURL=useCurrent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useCurrent.d.ts","sourceRoot":"","sources":["../src/useCurrent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EAEhB,aAAa,EACb,UAAU,EACV,sBAAsB,EACtB,UAAU,EACV,YAAY,EACZ,qBAAqB,EACtB,MAAM,SAAS,CAAC;AACjB,OAAO,EAEL,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACxB,MAAM,kBAAkB,CAAC;AAE1B;;;;;;;GAOG;AACH,KAAK,aAAa,CAAC,CAAC,SAAS,YAAY,EAAE,OAAO,IAAI;KACnD,CAAC,IAAI,MAAM,OAAO,GAAG,MAAM,GACxB,sBAAsB,CACpB,CAAC,SAAS,qBAAqB,CAAC,CAAC,CAA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AAK,kBAAkB,EACxB,MAAM,kBAAkB,CAAC;AAE1B,MAAM,WAAW,iBAAkB,SAAQ,kBAAkB;IAC3D;;;;OAIG;IACH,IAAI,CAAC,EAAE,aAAa,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,UAAU,CACxB,CAAC,SAAS,YAAY,EACtB,KAAK,CAAC,OAAO,SAAS,YAAY,CAAC,CAAC,CAAC,EAErC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,EAChD,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,iBAAiB,GAC1B,YAAY,CAAC,CAAC,EAAE,OAAO,CAAC,CAe1B"}
@@ -4,19 +4,20 @@ import { useSnapshot, } from './useSnapshot.js';
4
4
  * Subscribe to a live source and return the current value of a reducer
5
5
  * mapping, updated on a throttle. Equivalent to
6
6
  * `useSnapshot(src).tail(tail).reduce(mapping)` but with one subscription,
7
- * one memo, and narrow per-entry types.
7
+ * one memo, and narrow per-entry types inherited from
8
+ * `TimeSeries.reduce`.
8
9
  *
9
10
  * ```ts
10
11
  * const current = useCurrent(live, { cpu: 'avg', host: 'unique' });
11
- * // ^ { cpu: number | undefined; host: ReadonlyArray<ScalarValue> | undefined }
12
+ * // ^ { cpu: number | undefined;
13
+ * // host: ReadonlyArray<ScalarValue> | undefined }
12
14
  *
13
15
  * const recent = useCurrent(live, { cpu: 'p95' }, { tail: '30s' });
14
16
  * ```
15
17
  *
16
- * Returns an empty-result object (every mapped field set to the
17
- * reducer's empty-bucket value) while the source has no events — the
18
- * shape of the return is stable regardless of source state, so
19
- * destructuring is always safe.
18
+ * Returns a stable-shape object while the source has no events (every
19
+ * mapped field is `undefined`), so destructuring on first render is
20
+ * safe.
20
21
  */
21
22
  export function useCurrent(source, mapping, options) {
22
23
  const snap = useSnapshot(source, options);
@@ -1 +1 @@
1
- {"version":3,"file":"useCurrent.js","sourceRoot":"","sources":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O,CAAC,CAAC;IAC1C,MAAM,OAAO,GAAG,OAAO,EAAE,IAAI,CAAC;IAE9B,OAAO,OAAO,CAAC,GAAG,EAAE;QAClB,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,+DAA+D;YAC/D,gBAAgB;YAChB,MAAM,KAAK,GAA4B,EAAE,CAAC;YAC1C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;gBAAE,KAAK,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;YAC/D,OAAO,KAAiC,CAAC;QAC3C,CAAC;QACD,MAAM,MAAM,GAAG,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACjE,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,CAA6B,CAAC;IAC5D,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;AAC/B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pond-ts/react",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "React hooks for pond-ts live time series",
5
5
  "license": "MIT",
6
6
  "repository": {