@nlozgachev/pipelined 0.47.0 → 0.49.0

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/core.d.mts CHANGED
@@ -1,7 +1,8 @@
1
- import { M as Maybe, R as Result, T as Task } from './Validation-v38R0qH-.mjs';
2
- export { E as Equality, a as Err, F as Failed, N as None, O as Ok, b as Ordering, P as Passed, S as Some, c as TaskMaybe, d as TaskResult, e as TaskValidation, V as Validation } from './Validation-v38R0qH-.mjs';
3
- import { o as WithValue, i as WithLog, D as Deferred, h as WithKind, e as WithError, R as RetryOptions, b as TimeoutOptions, n as WithTimeout, j as WithMinInterval, c as WithCooldown, W as WithConcurrency, m as WithSize, d as WithDuration, k as WithN, g as WithFirst, l as WithSecond } from './InternalTypes-CLE7qlOc.mjs';
4
- import { Duration } from './types.mjs';
1
+ import { M as Maybe, R as Result, T as Task } from './Validation-D-aARYlP.mjs';
2
+ export { E as Equality, a as Err, F as Failed, N as None, O as Ok, b as Ordering, P as Passed, S as Some, c as TaskMaybe, d as TaskResult, e as TaskValidation, V as Validation } from './Validation-D-aARYlP.mjs';
3
+ import { o as WithValue, i as WithLog, D as Deferred, h as WithKind, e as WithError, R as RetryOptions, b as TimeoutOptions, n as WithTimeout, j as WithMinInterval, c as WithCooldown, W as WithConcurrency, m as WithSize, d as WithDuration, k as WithN, g as WithFirst, l as WithSecond } from './InternalTypes-CDiDBAY4.mjs';
4
+ import { D as Duration } from './Duration-B8joKzro.mjs';
5
+ import './types.mjs';
5
6
 
6
7
  /**
7
8
  * A type that can combine two values of type `A` into one, with a neutral starting value.
@@ -96,6 +97,18 @@ declare namespace Combinable {
96
97
  * ```
97
98
  */
98
99
  const fold: <A>(c: Combinable<A>) => (data: readonly A[]) => A;
100
+ /**
101
+ * Derives a `Combinable` for a record of fields from field-level `Combinable` instances.
102
+ *
103
+ * @example
104
+ * ```ts
105
+ * const StatsCombinable = Combinable.struct({
106
+ * count: Combinable.sum,
107
+ * tags: Combinable.array<string>(),
108
+ * });
109
+ * ```
110
+ */
111
+ const struct: <R extends Record<string, unknown>>(fields: { [K in keyof R]: Combinable<R[K]>; }) => Combinable<R>;
99
112
  }
100
113
 
101
114
  /**
@@ -432,6 +445,17 @@ declare namespace Logged {
432
445
  * ```
433
446
  */
434
447
  const bind: <K extends string, W, A, B>(key: K, f: (a: A) => Logged<W, B>) => (data: Logged<W, A>) => Logged<W, A & { [P in K]: B; }>;
448
+ /**
449
+ * Focuses a Logged computation's value transformation using a Lens.
450
+ *
451
+ * @example
452
+ * ```ts
453
+ * const nameLens = Lens.from.property<{ name: string }>()("name");
454
+ * const logged = Logged.from.value<string, { name: string }>({ name: "alice" });
455
+ * pipe(logged, Logged.focus(nameLens)(s => s.toUpperCase()));
456
+ * ```
457
+ */
458
+ const focus: <S, A>(lens: Lens<S, A>) => <W>(f: (a: A) => A) => (data: Logged<W, S>) => Logged<W, S>;
435
459
  }
436
460
 
437
461
  type MaybeRetry<E, O> = O extends {
@@ -1465,6 +1489,23 @@ declare namespace Predicate {
1465
1489
  */
1466
1490
  const Refinement: <A, B extends A>(r: Refinement<A, B>) => Predicate<A>;
1467
1491
  }
1492
+ /**
1493
+ * Performs declarative conditional branching over `[predicate, handler]` pairs,
1494
+ * returning the handler result of the first matching predicate or evaluating the fallback.
1495
+ *
1496
+ * @example
1497
+ * ```ts
1498
+ * const classifyNumber = Predicate.match(
1499
+ * [
1500
+ * [(n: number) => n < 0, () => "negative"],
1501
+ * [(n: number) => n === 0, () => "zero"],
1502
+ * ],
1503
+ * () => "positive",
1504
+ * );
1505
+ * classifyNumber(-5); // "negative"
1506
+ * ```
1507
+ */
1508
+ const match: <A, B>(branches: ReadonlyArray<readonly [Predicate<A>, (a: A) => B]>, fallback: (a: A) => B) => (a: A) => B;
1468
1509
  }
1469
1510
 
1470
1511
  /**
@@ -1813,36 +1854,88 @@ declare namespace RemoteData {
1813
1854
  namespace make {
1814
1855
  /**
1815
1856
  * Creates a NotAsked RemoteData.
1857
+ *
1858
+ * @example
1859
+ * ```ts
1860
+ * RemoteData.make.notAsked(); // NotAsked
1861
+ * ```
1816
1862
  */
1817
1863
  const notAsked: () => NotAsked;
1818
1864
  /**
1819
1865
  * Creates a Loading RemoteData.
1866
+ *
1867
+ * @example
1868
+ * ```ts
1869
+ * RemoteData.make.loading(); // Loading
1870
+ * ```
1820
1871
  */
1821
1872
  const loading: () => Loading;
1822
1873
  /**
1823
1874
  * Creates a Failure RemoteData with the given error.
1875
+ *
1876
+ * @example
1877
+ * ```ts
1878
+ * RemoteData.make.failure("Network error"); // Failure("Network error")
1879
+ * ```
1824
1880
  */
1825
1881
  const failure: <E>(error: E) => Failure<E>;
1826
1882
  /**
1827
1883
  * Creates a Success RemoteData with the given value.
1884
+ *
1885
+ * @example
1886
+ * ```ts
1887
+ * RemoteData.make.success(42); // Success(42)
1888
+ * ```
1828
1889
  */
1829
1890
  const success: <A>(value: A) => Success<A>;
1830
1891
  }
1831
1892
  namespace is {
1832
1893
  /**
1833
1894
  * Type guard that checks if a RemoteData is NotAsked.
1895
+ *
1896
+ * @example
1897
+ * ```ts
1898
+ * const data = RemoteData.make.notAsked();
1899
+ * if (RemoteData.is.notAsked(data)) {
1900
+ * console.log("Data fetch not initiated");
1901
+ * }
1902
+ * ```
1834
1903
  */
1835
1904
  const notAsked: <E, A>(data: RemoteData<E, A>) => data is NotAsked;
1836
1905
  /**
1837
1906
  * Type guard that checks if a RemoteData is Loading.
1907
+ *
1908
+ * @example
1909
+ * ```ts
1910
+ * const data = RemoteData.make.loading();
1911
+ * if (RemoteData.is.loading(data)) {
1912
+ * console.log("Data is loading");
1913
+ * }
1914
+ * ```
1838
1915
  */
1839
1916
  const loading: <E, A>(data: RemoteData<E, A>) => data is Loading;
1840
1917
  /**
1841
1918
  * Type guard that checks if a RemoteData is Failure.
1919
+ *
1920
+ * @example
1921
+ * ```ts
1922
+ * const data = RemoteData.make.failure("Failed");
1923
+ * if (RemoteData.is.failure(data)) {
1924
+ * console.log(data.error); // "Failed"
1925
+ * }
1926
+ * ```
1842
1927
  */
1843
1928
  const failure: <E, A>(data: RemoteData<E, A>) => data is Failure<E>;
1844
1929
  /**
1845
1930
  * Type guard that checks if a RemoteData is Success.
1931
+ *
1932
+ * @example
1933
+ * ```ts
1934
+ * const data = RemoteData.make.success(42);
1935
+ * if (RemoteData.is.success(data)) {
1936
+ * console.log(data.value); // 42
1937
+ * }
1938
+ * ```
1846
1939
  */
1847
1940
  const success: <E, A>(data: RemoteData<E, A>) => data is Success<A>;
1848
1941
  }
@@ -1877,7 +1970,7 @@ declare namespace RemoteData {
1877
1970
  * );
1878
1971
  * ```
1879
1972
  */
1880
- const chain: <E, A, B>(f: (a: A) => RemoteData<E, B>) => (data: RemoteData<E, A>) => RemoteData<E, B>;
1973
+ const chain: <E1, E2, A, B>(f: (a: A) => RemoteData<E2, B>) => (data: RemoteData<E1, A>) => RemoteData<E1 | E2, B>;
1881
1974
  /**
1882
1975
  * Applies a function wrapped in a RemoteData to a value wrapped in a RemoteData.
1883
1976
  *
@@ -2003,7 +2096,7 @@ declare namespace RemoteData {
2003
2096
  *
2004
2097
  * @example
2005
2098
  * ```ts
2006
- * const result = await Task.Result.tryCatch(fetchUser, String)();
2099
+ * const result = await Task.Result.tryCatch(fetchUser, { onError: String })();
2007
2100
  * setState(RemoteData.from.Result(result)); // Success(user) or Failure(msg)
2008
2101
  * ```
2009
2102
  */
@@ -2053,7 +2146,7 @@ declare namespace RemoteData {
2053
2146
  * @example
2054
2147
  * ```ts
2055
2148
  * const dbResource = Resource.from.handlers(
2056
- * Task.Result.tryCatch(() => openConnection(config), (e) => new DbError(e)),
2149
+ * Task.Result.tryCatch(() => openConnection(config), { onError: (e) => new DbError(e) }),
2057
2150
  * (conn) => Task.from.Promise(() => conn.close())
2058
2151
  * );
2059
2152
  *
@@ -2076,7 +2169,7 @@ declare namespace Resource {
2076
2169
  * @example
2077
2170
  * ```ts
2078
2171
  * const fileResource = Resource.from.handlers(
2079
- * Task.Result.tryCatch(() => fs.promises.open("data.csv", "r"), toFileError),
2172
+ * Task.Result.tryCatch(() => fs.promises.open("data.csv", "r"), { onError: toFileError }),
2080
2173
  * (handle) => Task.from.Promise(() => handle.close())
2081
2174
  * );
2082
2175
  * ```
@@ -2344,6 +2437,170 @@ declare namespace State {
2344
2437
  * ```
2345
2438
  */
2346
2439
  const bind: <K extends string, S, A, B>(key: K, f: (a: A) => State<S, B>) => (data: State<S, A>) => State<S, A & { [P in K]: B; }>;
2440
+ /**
2441
+ * Focuses a State computation on a sub-state using a Lens.
2442
+ *
2443
+ * @example
2444
+ * ```ts
2445
+ * type AppState = { count: number; name: string };
2446
+ * const countLens = Lens.from.property<AppState>()("count");
2447
+ * const increment = State.modify((c: number) => c + 1);
2448
+ * const focusedProgram = pipe(increment, State.focus(countLens));
2449
+ * ```
2450
+ */
2451
+ const focus: <S, A>(lens: Lens<S, A>) => <B>(stateOp: State<A, B>) => State<S, B>;
2452
+ }
2453
+
2454
+ /**
2455
+ * An event stream pipeline for a typed message schema `S`.
2456
+ *
2457
+ * `Stream` provides typed event emission, sequence matching, state reduction,
2458
+ * and structural stream forwarding.
2459
+ *
2460
+ * @example
2461
+ * ```ts
2462
+ * type AppMessages = {
2463
+ * userLoggedIn: { userId: string };
2464
+ * checkoutStarted: { amount: number };
2465
+ * };
2466
+ *
2467
+ * const appStream = Stream.make<AppMessages>();
2468
+ *
2469
+ * const subscription = Stream.listen(
2470
+ * appStream,
2471
+ * ["userLoggedIn", "checkoutStarted"],
2472
+ * { ordered: true }
2473
+ * ).reduce(
2474
+ * (msg, state) => {
2475
+ * if (msg.kind === "checkoutStarted") {
2476
+ * return { count: state.count + 1 };
2477
+ * }
2478
+ * return state;
2479
+ * },
2480
+ * { count: 0 }
2481
+ * );
2482
+ *
2483
+ * Stream.emit(appStream, {
2484
+ * kind: "userLoggedIn",
2485
+ * value: { userId: "user-1" },
2486
+ * });
2487
+ * ```
2488
+ */
2489
+ type Stream<S extends Record<string, unknown>> = {
2490
+ readonly options?: Stream.Options;
2491
+ /** @internal */
2492
+ readonly _listeners: Set<(msg: Stream.Message<S>) => void>;
2493
+ };
2494
+ declare namespace Stream {
2495
+ /**
2496
+ * Message payload emitted across a Stream.
2497
+ */
2498
+ type Message<S extends Record<string, unknown>> = {
2499
+ [K in keyof S & string]: WithKind<K> & WithValue<S[K]>;
2500
+ }[keyof S & string];
2501
+ /**
2502
+ * Options for constructing a `Stream` instance.
2503
+ */
2504
+ type Options = {
2505
+ readonly name?: string;
2506
+ readonly onError?: (error: unknown) => void;
2507
+ };
2508
+ /**
2509
+ * Options for sequence matching and listener execution.
2510
+ */
2511
+ type SequenceOptions<S extends Record<string, unknown>> = {
2512
+ /** Match events in exact array sequence order (default: false). */
2513
+ readonly ordered?: boolean;
2514
+ /** Match sequence strictly consecutively without intermediary events (default: false). */
2515
+ readonly strict?: boolean;
2516
+ /** Automatically unsubscribe after the first match/cycle completes (default: false). */
2517
+ readonly once?: boolean;
2518
+ /** Event kind(s) that reset sequence tracking to index 0. */
2519
+ readonly reset?: (keyof S & string) | ReadonlyArray<keyof S & string>;
2520
+ };
2521
+ /**
2522
+ * Handle for an active stateful subscription.
2523
+ */
2524
+ type Subscription<State> = {
2525
+ readonly unsubscribe: () => void;
2526
+ readonly getState: () => State;
2527
+ };
2528
+ /**
2529
+ * Options for structural stream forwarding.
2530
+ */
2531
+ type ForwardOptions<S extends Record<string, unknown>> = {
2532
+ readonly from: Stream<S>;
2533
+ readonly to: Stream<S> | ReadonlyArray<Stream<S>>;
2534
+ readonly only?: ReadonlyArray<keyof S & string>;
2535
+ };
2536
+ /**
2537
+ * Builder handle returned by `Stream.listen`.
2538
+ */
2539
+ type ListenerBuilder<S extends Record<string, unknown>> = {
2540
+ /**
2541
+ * Stateful reduction over events/sequences.
2542
+ */
2543
+ readonly reduce: <State>(reducer: (msg: Message<S>, state: State) => State, initialState: State) => Subscription<State>;
2544
+ /**
2545
+ * Stateless side-effect execution.
2546
+ */
2547
+ readonly tap: (effect: (msg: Message<S>) => void) => () => void;
2548
+ };
2549
+ /**
2550
+ * Constructs a new `Stream` instance.
2551
+ *
2552
+ * @example
2553
+ * ```ts
2554
+ * const stream = Stream.make<AppMessages>({ name: "app" });
2555
+ * ```
2556
+ */
2557
+ const make: <S extends Record<string, unknown>>(options?: Options) => Stream<S>;
2558
+ /**
2559
+ * Emits a message payload to one or more target streams.
2560
+ *
2561
+ * @example
2562
+ * ```ts
2563
+ * Stream.emit(streamA, {
2564
+ * kind: "userLoggedIn",
2565
+ * value: { userId: "user-1" },
2566
+ * });
2567
+ *
2568
+ * Stream.emit([streamA, streamB], {
2569
+ * kind: "userLoggedIn",
2570
+ * value: { userId: "user-1" },
2571
+ * });
2572
+ * ```
2573
+ */
2574
+ const emit: <S extends Record<string, unknown>, K extends keyof S & string>(target: Stream<S> | ReadonlyArray<Stream<S>>, message: WithKind<K> & WithValue<S[K]>) => void;
2575
+ /**
2576
+ * Forwards messages from one stream to another (or multiple).
2577
+ *
2578
+ * @example
2579
+ * ```ts
2580
+ * const stop = Stream.forward({
2581
+ * from: authStream,
2582
+ * to: analyticsStream,
2583
+ * only: ["userLoggedIn"],
2584
+ * });
2585
+ * ```
2586
+ */
2587
+ const forward: <S extends Record<string, unknown>>(options: ForwardOptions<S>) => () => void;
2588
+ /**
2589
+ * Initiates listener registration on a stream for specific event kind(s) or sequence.
2590
+ *
2591
+ * @example
2592
+ * ```ts
2593
+ * const sub = Stream.listen(
2594
+ * appStream,
2595
+ * ["userLoggedIn", "checkoutStarted"],
2596
+ * { ordered: true }
2597
+ * ).reduce(
2598
+ * (msg, state) => ({ count: state.count + 1 }),
2599
+ * { count: 0 }
2600
+ * );
2601
+ * ```
2602
+ */
2603
+ const listen: <S extends Record<string, unknown>, K extends keyof S & string>(stream: Stream<S>, events: K | ReadonlyArray<K>, options?: SequenceOptions<S>) => ListenerBuilder<S>;
2347
2604
  }
2348
2605
 
2349
2606
  type TheseFirst<T> = WithKind<"First"> & WithFirst<T>;
@@ -2406,23 +2663,61 @@ declare namespace These {
2406
2663
  namespace is {
2407
2664
  /**
2408
2665
  * Type guard — checks if a These holds only a first value.
2666
+ *
2667
+ * @example
2668
+ * ```ts
2669
+ * const val = These.make.first(42);
2670
+ * if (These.is.first(val)) {
2671
+ * console.log(val.first); // 42
2672
+ * }
2673
+ * ```
2409
2674
  */
2410
2675
  const first: <A, B>(data: These<A, B>) => data is TheseFirst<A>;
2411
2676
  /**
2412
2677
  * Type guard — checks if a These holds only a second value.
2678
+ *
2679
+ * @example
2680
+ * ```ts
2681
+ * const val = These.make.second("warning");
2682
+ * if (These.is.second(val)) {
2683
+ * console.log(val.second); // "warning"
2684
+ * }
2685
+ * ```
2413
2686
  */
2414
2687
  const second: <A, B>(data: These<A, B>) => data is TheseSecond<B>;
2415
2688
  /**
2416
2689
  * Type guard — checks if a These holds both values simultaneously.
2690
+ *
2691
+ * @example
2692
+ * ```ts
2693
+ * const val = These.make.both(42, "warning");
2694
+ * if (These.is.both(val)) {
2695
+ * console.log(val.first, val.second); // 42 "warning"
2696
+ * }
2697
+ * ```
2417
2698
  */
2418
2699
  const both: <A, B>(data: These<A, B>) => data is TheseBoth<A, B>;
2419
2700
  }
2420
2701
  /**
2421
2702
  * Returns true if the These contains a first value (First or Both).
2703
+ *
2704
+ * @example
2705
+ * ```ts
2706
+ * These.hasFirst(These.make.first(42)); // true
2707
+ * These.hasFirst(These.make.both(42, "warn"));// true
2708
+ * These.hasFirst(These.make.second("warn")); // false
2709
+ * ```
2422
2710
  */
2423
2711
  const hasFirst: <A, B>(data: These<A, B>) => data is TheseFirst<A> | TheseBoth<A, B>;
2424
2712
  /**
2425
2713
  * Returns true if the These contains a second value (Second or Both).
2714
+ *
2715
+ * @example
2716
+ * ```ts
2717
+ * These.hasSecond(These.make.second("warn")); // true
2718
+ * These.hasSecond(These.make.both(42, "warn"));// true
2719
+ * These.hasSecond(These.make.first(42)); // false
2720
+ * ```
2426
2721
  */
2427
2722
  const hasSecond: <A, B>(data: These<A, B>) => data is TheseSecond<B> | TheseBoth<A, B>;
2428
2723
  /**
@@ -2716,4 +3011,4 @@ declare namespace Tuple {
2716
3011
  const tap: <A, B>(f: (a: A, b: B) => void) => (tuple: Tuple<A, B>) => Tuple<A, B>;
2717
3012
  }
2718
3013
 
2719
- export { Combinable, Deferred, type Failure, Lazy, Lens, type Loading, Logged, Maybe, type NotAsked, Op, Optional, Predicate, Reader, Refinement, RemoteData, Resource, Result, State, type Success, Task, These, type TheseBoth, type TheseFirst, type TheseSecond, Tuple };
3014
+ export { Combinable, Deferred, type Failure, Lazy, Lens, type Loading, Logged, Maybe, type NotAsked, Op, Optional, Predicate, Reader, Refinement, RemoteData, Resource, Result, State, Stream, type Success, Task, These, type TheseBoth, type TheseFirst, type TheseSecond, Tuple };