@pond-ts/react 0.5.1 → 0.5.3
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/useCurrent.d.ts +9 -26
- package/dist/useCurrent.d.ts.map +1 -1
- package/dist/useCurrent.js +7 -6
- package/dist/useCurrent.js.map +1 -1
- package/package.json +1 -1
package/dist/useCurrent.d.ts
CHANGED
|
@@ -1,21 +1,5 @@
|
|
|
1
|
-
import type { AggregateMap,
|
|
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;
|
|
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
|
|
41
|
-
*
|
|
42
|
-
*
|
|
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):
|
|
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
|
package/dist/useCurrent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCurrent.d.ts","sourceRoot":"","sources":["../src/useCurrent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EACZ,
|
|
1
|
+
{"version":3,"file":"useCurrent.d.ts","sourceRoot":"","sources":["../src/useCurrent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,UAAU,EACV,YAAY,EACZ,YAAY,EACb,MAAM,SAAS,CAAC;AACjB,OAAO,EAEL,KAAK,cAAc,EACnB,KAAK,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"}
|
package/dist/useCurrent.js
CHANGED
|
@@ -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;
|
|
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
|
|
17
|
-
*
|
|
18
|
-
*
|
|
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);
|
package/dist/useCurrent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCurrent.js","sourceRoot":"","sources":["../src/useCurrent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"useCurrent.js","sourceRoot":"","sources":["../src/useCurrent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAQhC,OAAO,EACL,WAAW,GAGZ,MAAM,kBAAkB,CAAC;AAW1B;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,UAAU,CAIxB,MAAgD,EAChD,OAAgB,EAChB,OAA2B;IAE3B,MAAM,IAAI,GAAG,WAAW,CAAC,MAAM,EAAE,OAAO,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"}
|