@nlozgachev/pipelined 0.40.0 → 0.41.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/Duration-BTeT9D-q.d.mts +127 -0
- package/dist/Duration-BTeT9D-q.d.ts +127 -0
- package/dist/{Task-uupX7xd9.d.ts → Task-BprUabHP.d.mts} +3 -2
- package/dist/{Task-DcXhCZYg.d.mts → Task-Dt3ZMen6.d.ts} +3 -2
- package/dist/{chunk-4R4XUP4M.mjs → chunk-COGQKPIP.mjs} +3 -3
- package/dist/{chunk-5AFEEFE4.mjs → chunk-GBB6LVLI.mjs} +2 -2
- package/dist/{chunk-3Q5UBRYB.mjs → chunk-TCE2UETM.mjs} +88 -4
- package/dist/{chunk-BQKKTTJS.mjs → chunk-V37OUM35.mjs} +3 -2
- package/dist/composition.d.mts +128 -1
- package/dist/composition.d.ts +128 -1
- package/dist/composition.js +111 -4
- package/dist/composition.mjs +2 -1
- package/dist/core.d.mts +5 -4
- package/dist/core.d.ts +5 -4
- package/dist/core.js +2 -2
- package/dist/core.mjs +2 -2
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +117 -34
- package/dist/index.mjs +4 -4
- package/dist/types.d.mts +2 -126
- package/dist/types.d.ts +2 -126
- package/dist/types.mjs +1 -1
- package/dist/utils.d.mts +13 -1
- package/dist/utils.d.ts +13 -1
- package/dist/utils.js +2 -1
- package/dist/utils.mjs +3 -3
- package/package.json +1 -1
package/dist/composition.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { D as Duration } from './Duration-BTeT9D-q.js';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Composes functions from right to left, returning a new function.
|
|
3
5
|
* This is the traditional mathematical function composition: (f . g)(x) = f(g(x))
|
|
@@ -617,7 +619,132 @@ interface pipe {
|
|
|
617
619
|
*
|
|
618
620
|
* @see {@link Maybe.tap} for Maybe-specific tap that only runs on Some
|
|
619
621
|
*/
|
|
620
|
-
declare
|
|
622
|
+
declare function tap<A>(f: (a: A) => void): (a: A) => A;
|
|
623
|
+
declare namespace tap {
|
|
624
|
+
/**
|
|
625
|
+
* Configuration options for {@link tap.log}.
|
|
626
|
+
*/
|
|
627
|
+
type LogOptions<A> = {
|
|
628
|
+
/**
|
|
629
|
+
* An optional label prefix for the log output (e.g., `[label]: value`).
|
|
630
|
+
*/
|
|
631
|
+
readonly label?: string;
|
|
632
|
+
/**
|
|
633
|
+
* The logging destination function. Defaults to `console.log`.
|
|
634
|
+
*/
|
|
635
|
+
readonly logger?: (message: string) => void;
|
|
636
|
+
/**
|
|
637
|
+
* A custom formatter function to convert the piped value to a string.
|
|
638
|
+
* Defaults to `JSON.stringify` for objects and `String(value)` for primitives.
|
|
639
|
+
*/
|
|
640
|
+
readonly formatter?: (value: A) => string;
|
|
641
|
+
};
|
|
642
|
+
/**
|
|
643
|
+
* Configuration options for {@link tap.inspect}.
|
|
644
|
+
*/
|
|
645
|
+
type InspectOptions = {
|
|
646
|
+
/**
|
|
647
|
+
* An optional label prefix for the inspect output (e.g., `[label]: value`).
|
|
648
|
+
*/
|
|
649
|
+
readonly label?: string;
|
|
650
|
+
/**
|
|
651
|
+
* The maximum depth to recurse when formatting the object.
|
|
652
|
+
* Defaults to `null` (infinite depth).
|
|
653
|
+
*/
|
|
654
|
+
readonly depth?: number;
|
|
655
|
+
/**
|
|
656
|
+
* Whether to colorize the output using ANSI color codes.
|
|
657
|
+
* Defaults to `true`.
|
|
658
|
+
*/
|
|
659
|
+
readonly colors?: boolean;
|
|
660
|
+
};
|
|
661
|
+
/**
|
|
662
|
+
* Configuration options for {@link tap.async}.
|
|
663
|
+
*/
|
|
664
|
+
type AsyncOptions = {
|
|
665
|
+
/**
|
|
666
|
+
* A callback to handle exceptions thrown by the async side-effect.
|
|
667
|
+
* Defaults to logging via `console.error`.
|
|
668
|
+
*/
|
|
669
|
+
readonly onError?: (error: unknown) => void;
|
|
670
|
+
};
|
|
671
|
+
/**
|
|
672
|
+
* Configuration options for {@link tap.time}, enforcing mutual exclusivity
|
|
673
|
+
* between console logging and custom handlers.
|
|
674
|
+
*/
|
|
675
|
+
type TimeConfig = {
|
|
676
|
+
label: string;
|
|
677
|
+
onFinish?: never;
|
|
678
|
+
} | {
|
|
679
|
+
onFinish: (duration: Duration) => void;
|
|
680
|
+
label?: never;
|
|
681
|
+
};
|
|
682
|
+
/**
|
|
683
|
+
* Logs the piped value to the console or a custom logger, returning the value unchanged.
|
|
684
|
+
*
|
|
685
|
+
* @example
|
|
686
|
+
* ```ts
|
|
687
|
+
* pipe(
|
|
688
|
+
* 42,
|
|
689
|
+
* tap.log(), // logs: 42
|
|
690
|
+
* tap.log({ label: "Count" }) // logs: [Count]: 42
|
|
691
|
+
* );
|
|
692
|
+
* ```
|
|
693
|
+
*/
|
|
694
|
+
const log: <A>(options?: LogOptions<A>) => (a: A) => A;
|
|
695
|
+
/**
|
|
696
|
+
* Performs a deep structured inspect formatting on the piped value, returning it unchanged.
|
|
697
|
+
* In Node.js environments, this utilizes Node's `node:util` `inspect` utility.
|
|
698
|
+
*
|
|
699
|
+
* @example
|
|
700
|
+
* ```ts
|
|
701
|
+
* pipe(
|
|
702
|
+
* { user: { name: "Alice", details: { age: 30 } } },
|
|
703
|
+
* tap.inspect({ label: "User Object", depth: 2 })
|
|
704
|
+
* );
|
|
705
|
+
* ```
|
|
706
|
+
*/
|
|
707
|
+
const inspect: <A>(options?: InspectOptions) => (a: A) => A;
|
|
708
|
+
/**
|
|
709
|
+
* Triggers a fire-and-forget asynchronous side effect in the background,
|
|
710
|
+
* returning the piped value immediately and synchronously.
|
|
711
|
+
* Any errors thrown by the async function are caught and forwarded to `onError`.
|
|
712
|
+
*
|
|
713
|
+
* @example
|
|
714
|
+
* ```ts
|
|
715
|
+
* pipe(
|
|
716
|
+
* user,
|
|
717
|
+
* tap.async(async (u) => {
|
|
718
|
+
* await saveToDatabase(u);
|
|
719
|
+
* }, { onError: (err) => logError(err) })
|
|
720
|
+
* );
|
|
721
|
+
* ```
|
|
722
|
+
*/
|
|
723
|
+
const async: <A>(fn: (a: A) => Promise<unknown>, options?: AsyncOptions) => (a: A) => A;
|
|
724
|
+
/**
|
|
725
|
+
* Runs a function and measures its execution duration, returning the value unchanged.
|
|
726
|
+
* Supports both synchronous and asynchronous functions. If the timed function returns
|
|
727
|
+
* a Promise, duration measurement resolves asynchronously upon resolution/rejection.
|
|
728
|
+
*
|
|
729
|
+
* @example
|
|
730
|
+
* ```ts
|
|
731
|
+
* // Time a synchronous computation
|
|
732
|
+
* pipe(
|
|
733
|
+
* data,
|
|
734
|
+
* tap.time(processData, { label: "sync-process" })
|
|
735
|
+
* );
|
|
736
|
+
*
|
|
737
|
+
* // Time an asynchronous fetch with custom metrics callback
|
|
738
|
+
* pipe(
|
|
739
|
+
* data,
|
|
740
|
+
* tap.time(fetchData, {
|
|
741
|
+
* onFinish: (dur) => metrics.histogram("api.time", Duration.toMilliseconds(dur))
|
|
742
|
+
* })
|
|
743
|
+
* );
|
|
744
|
+
* ```
|
|
745
|
+
*/
|
|
746
|
+
const time: <A>(fn: (a: A) => unknown, config: TimeConfig) => (a: A) => A;
|
|
747
|
+
}
|
|
621
748
|
|
|
622
749
|
/**
|
|
623
750
|
* Converts a curried function into a multi-argument function.
|
package/dist/composition.js
CHANGED
|
@@ -369,10 +369,117 @@ pipe.try = (f, onError) => (a) => {
|
|
|
369
369
|
};
|
|
370
370
|
|
|
371
371
|
// src/Composition/tap.ts
|
|
372
|
-
var
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
372
|
+
var import_node_util = require("util");
|
|
373
|
+
|
|
374
|
+
// src/Types/Brand.ts
|
|
375
|
+
var Brand;
|
|
376
|
+
((Brand2) => {
|
|
377
|
+
Brand2.wrap = () => (value) => value;
|
|
378
|
+
Brand2.unwrap = (branded) => branded;
|
|
379
|
+
})(Brand || (Brand = {}));
|
|
380
|
+
|
|
381
|
+
// src/Types/Duration.ts
|
|
382
|
+
var Duration;
|
|
383
|
+
((Duration2) => {
|
|
384
|
+
const wrap = Brand.wrap();
|
|
385
|
+
Duration2.milliseconds = (ms) => wrap(ms);
|
|
386
|
+
Duration2.seconds = (s) => wrap(s * 1e3);
|
|
387
|
+
Duration2.minutes = (m) => wrap(m * 60 * 1e3);
|
|
388
|
+
Duration2.hours = (h) => wrap(h * 60 * 60 * 1e3);
|
|
389
|
+
Duration2.days = (d) => wrap(d * 24 * 60 * 60 * 1e3);
|
|
390
|
+
Duration2.toMilliseconds = (d) => Brand.unwrap(d);
|
|
391
|
+
Duration2.toSeconds = (d) => Brand.unwrap(d) / 1e3;
|
|
392
|
+
Duration2.toMinutes = (d) => Brand.unwrap(d) / (60 * 1e3);
|
|
393
|
+
Duration2.toHours = (d) => Brand.unwrap(d) / (60 * 60 * 1e3);
|
|
394
|
+
Duration2.toDays = (d) => Brand.unwrap(d) / (24 * 60 * 60 * 1e3);
|
|
395
|
+
Duration2.add = (other) => (self) => wrap(Brand.unwrap(self) + Brand.unwrap(other));
|
|
396
|
+
Duration2.subtract = (other) => (self) => wrap(Brand.unwrap(self) - Brand.unwrap(other));
|
|
397
|
+
})(Duration || (Duration = {}));
|
|
398
|
+
|
|
399
|
+
// src/Composition/tap.ts
|
|
400
|
+
function tap(f) {
|
|
401
|
+
return (a) => {
|
|
402
|
+
f(a);
|
|
403
|
+
return a;
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
((tap2) => {
|
|
407
|
+
tap2.log = (options) => (a) => {
|
|
408
|
+
const logger = options?.logger ?? console.log;
|
|
409
|
+
const formatter = options?.formatter ?? ((val) => {
|
|
410
|
+
try {
|
|
411
|
+
return typeof val === "object" && val !== null ? JSON.stringify(val) : String(val);
|
|
412
|
+
} catch {
|
|
413
|
+
return String(val);
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
const formatted = formatter(a);
|
|
417
|
+
if (options?.label !== void 0) {
|
|
418
|
+
logger(`[${options.label}]: ${formatted}`);
|
|
419
|
+
} else {
|
|
420
|
+
logger(formatted);
|
|
421
|
+
}
|
|
422
|
+
return a;
|
|
423
|
+
};
|
|
424
|
+
tap2.inspect = (options) => (a) => {
|
|
425
|
+
const label = options?.label;
|
|
426
|
+
const depth = options?.depth ?? null;
|
|
427
|
+
const colors = options?.colors ?? true;
|
|
428
|
+
let formatted;
|
|
429
|
+
if (typeof import_node_util.inspect === "function") {
|
|
430
|
+
formatted = (0, import_node_util.inspect)(a, { depth, colors });
|
|
431
|
+
} else {
|
|
432
|
+
try {
|
|
433
|
+
formatted = JSON.stringify(a, null, 2);
|
|
434
|
+
} catch {
|
|
435
|
+
formatted = String(a);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
if (label !== void 0) {
|
|
439
|
+
console.log(`[${label}]: ${formatted}`);
|
|
440
|
+
} else {
|
|
441
|
+
console.log(formatted);
|
|
442
|
+
}
|
|
443
|
+
return a;
|
|
444
|
+
};
|
|
445
|
+
tap2.async = (fn, options) => (a) => {
|
|
446
|
+
const onError = options?.onError ?? console.error;
|
|
447
|
+
fn(a).catch((err) => {
|
|
448
|
+
onError(err);
|
|
449
|
+
});
|
|
450
|
+
return a;
|
|
451
|
+
};
|
|
452
|
+
tap2.time = (fn, config) => (a) => {
|
|
453
|
+
const start = performance.now();
|
|
454
|
+
const triggerFinish = (duration) => {
|
|
455
|
+
if (config.label !== void 0) {
|
|
456
|
+
console.log(`[${config.label}]: ${Duration.toMilliseconds(duration)}ms`);
|
|
457
|
+
} else if (config.onFinish) {
|
|
458
|
+
config.onFinish(duration);
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
try {
|
|
462
|
+
const res = fn(a);
|
|
463
|
+
if (res instanceof Promise) {
|
|
464
|
+
res.then(() => {
|
|
465
|
+
const duration = Duration.milliseconds(performance.now() - start);
|
|
466
|
+
triggerFinish(duration);
|
|
467
|
+
}, () => {
|
|
468
|
+
const duration = Duration.milliseconds(performance.now() - start);
|
|
469
|
+
triggerFinish(duration);
|
|
470
|
+
});
|
|
471
|
+
} else {
|
|
472
|
+
const duration = Duration.milliseconds(performance.now() - start);
|
|
473
|
+
triggerFinish(duration);
|
|
474
|
+
}
|
|
475
|
+
} catch (err) {
|
|
476
|
+
const duration = Duration.milliseconds(performance.now() - start);
|
|
477
|
+
triggerFinish(duration);
|
|
478
|
+
throw err;
|
|
479
|
+
}
|
|
480
|
+
return a;
|
|
481
|
+
};
|
|
482
|
+
})(tap || (tap = {}));
|
|
376
483
|
|
|
377
484
|
// src/Composition/uncurry.ts
|
|
378
485
|
function uncurry(f) {
|
package/dist/composition.mjs
CHANGED
package/dist/core.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { M as Maybe, q as WithValue, k as WithLog, D as Deferred, R as Result, j as WithKind, g as WithError, c as RetryOptions, d as TimeoutOptions, p as WithTimeout, l as WithMinInterval, e as WithCooldown, W as WithConcurrency, o as WithSize, f as WithDuration, m as WithN, T as Task, i as WithFirst, n as WithSecond, h as WithErrors } from './Task-
|
|
2
|
-
export { E as Equality, a as Err, N as None, O as Ok, b as Ordering, S as Some } from './Task-
|
|
3
|
-
import { Duration
|
|
1
|
+
import { M as Maybe, q as WithValue, k as WithLog, D as Deferred, R as Result, j as WithKind, g as WithError, c as RetryOptions, d as TimeoutOptions, p as WithTimeout, l as WithMinInterval, e as WithCooldown, W as WithConcurrency, o as WithSize, f as WithDuration, m as WithN, T as Task, i as WithFirst, n as WithSecond, h as WithErrors } from './Task-BprUabHP.mjs';
|
|
2
|
+
export { E as Equality, a as Err, N as None, O as Ok, b as Ordering, S as Some } from './Task-BprUabHP.mjs';
|
|
3
|
+
import { D as Duration } from './Duration-BTeT9D-q.mjs';
|
|
4
|
+
import { NonEmptyList } from './types.mjs';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* A type that can combine two values of type `A` into one, with a neutral starting value.
|
|
@@ -2591,7 +2592,7 @@ declare namespace TaskResult {
|
|
|
2591
2592
|
* if (Result.isOk(result)) render(result.value);
|
|
2592
2593
|
* ```
|
|
2593
2594
|
*/
|
|
2594
|
-
const run: (signal?: AbortSignal) => <E, A>(task: TaskResult<E, A>) =>
|
|
2595
|
+
const run: (signal?: AbortSignal) => <E, A>(task: TaskResult<E, A>) => Deferred<Result<E, A>>;
|
|
2595
2596
|
/**
|
|
2596
2597
|
* Converts a TaskResult value into an object containing a single property.
|
|
2597
2598
|
* Initiates the pipeline accumulator record.
|
package/dist/core.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { M as Maybe, q as WithValue, k as WithLog, D as Deferred, R as Result, j as WithKind, g as WithError, c as RetryOptions, d as TimeoutOptions, p as WithTimeout, l as WithMinInterval, e as WithCooldown, W as WithConcurrency, o as WithSize, f as WithDuration, m as WithN, T as Task, i as WithFirst, n as WithSecond, h as WithErrors } from './Task-
|
|
2
|
-
export { E as Equality, a as Err, N as None, O as Ok, b as Ordering, S as Some } from './Task-
|
|
3
|
-
import { Duration
|
|
1
|
+
import { M as Maybe, q as WithValue, k as WithLog, D as Deferred, R as Result, j as WithKind, g as WithError, c as RetryOptions, d as TimeoutOptions, p as WithTimeout, l as WithMinInterval, e as WithCooldown, W as WithConcurrency, o as WithSize, f as WithDuration, m as WithN, T as Task, i as WithFirst, n as WithSecond, h as WithErrors } from './Task-Dt3ZMen6.js';
|
|
2
|
+
export { E as Equality, a as Err, N as None, O as Ok, b as Ordering, S as Some } from './Task-Dt3ZMen6.js';
|
|
3
|
+
import { D as Duration } from './Duration-BTeT9D-q.js';
|
|
4
|
+
import { NonEmptyList } from './types.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* A type that can combine two values of type `A` into one, with a neutral starting value.
|
|
@@ -2591,7 +2592,7 @@ declare namespace TaskResult {
|
|
|
2591
2592
|
* if (Result.isOk(result)) render(result.value);
|
|
2592
2593
|
* ```
|
|
2593
2594
|
*/
|
|
2594
|
-
const run: (signal?: AbortSignal) => <E, A>(task: TaskResult<E, A>) =>
|
|
2595
|
+
const run: (signal?: AbortSignal) => <E, A>(task: TaskResult<E, A>) => Deferred<Result<E, A>>;
|
|
2595
2596
|
/**
|
|
2596
2597
|
* Converts a TaskResult value into an object containing a single property.
|
|
2597
2598
|
* Initiates the pipeline accumulator record.
|
package/dist/core.js
CHANGED
|
@@ -1870,7 +1870,7 @@ var Task;
|
|
|
1870
1870
|
};
|
|
1871
1871
|
return { task, abort };
|
|
1872
1872
|
};
|
|
1873
|
-
Task2.run = (signal) => (task) =>
|
|
1873
|
+
Task2.run = (signal) => (task) => task(signal);
|
|
1874
1874
|
Task2.bindTo = (key) => (data) => (0, Task2.map)((a) => ({ [key]: a }))(data);
|
|
1875
1875
|
Task2.bind = (key, f) => (data) => (0, Task2.chain)(
|
|
1876
1876
|
(a) => (0, Task2.map)((b) => ({ ...a, [key]: b }))(f(a))
|
|
@@ -1934,7 +1934,7 @@ var TaskResult3;
|
|
|
1934
1934
|
([of_, oa]) => Result.ap(oa)(of_)
|
|
1935
1935
|
)
|
|
1936
1936
|
);
|
|
1937
|
-
TaskResult4.run = (signal) => (task) =>
|
|
1937
|
+
TaskResult4.run = (signal) => (task) => task(signal);
|
|
1938
1938
|
TaskResult4.bindTo = (key) => (data) => (0, TaskResult4.map)((a) => ({ [key]: a }))(data);
|
|
1939
1939
|
TaskResult4.bind = (key, f) => (data) => (0, TaskResult4.chain)(
|
|
1940
1940
|
(a) => (0, TaskResult4.map)((b) => ({ ...a, [key]: b }))(f(a))
|
package/dist/core.mjs
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { and, compose, constFalse, constNull, constTrue, constUndefined, constVoid, constant, converge, curry, curry3, curry4, defaultTo, flip, flow, identity, juxt, memoize, memoizeWeak, not, on, once, or, pipe, tap, uncurry, uncurry3, uncurry4 } from './composition.mjs';
|
|
2
2
|
export { Combinable, Failed, Failure, Lazy, Lens, Loading, Logged, NotAsked, Op, Optional, Passed, Predicate, Reader, Refinement, RemoteData, Resource, State, Success, TaskMaybe, TaskResult, TaskValidation, These, TheseBoth, TheseFirst, TheseSecond, Tuple, Validation } from './core.mjs';
|
|
3
|
-
export { D as Deferred, E as Equality, a as Err, M as Maybe, N as None, O as Ok, b as Ordering, R as Result, S as Some, T as Task } from './Task-
|
|
3
|
+
export { D as Deferred, E as Equality, a as Err, M as Maybe, N as None, O as Ok, b as Ordering, R as Result, S as Some, T as Task } from './Task-BprUabHP.mjs';
|
|
4
4
|
export { Arr, Dict, Num, Rec, Str, Uniq } from './utils.mjs';
|
|
5
|
-
export { Brand,
|
|
5
|
+
export { B as Brand, D as Duration } from './Duration-BTeT9D-q.mjs';
|
|
6
|
+
export { NonEmptyList, isNonEmptyList } from './types.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { and, compose, constFalse, constNull, constTrue, constUndefined, constVoid, constant, converge, curry, curry3, curry4, defaultTo, flip, flow, identity, juxt, memoize, memoizeWeak, not, on, once, or, pipe, tap, uncurry, uncurry3, uncurry4 } from './composition.js';
|
|
2
2
|
export { Combinable, Failed, Failure, Lazy, Lens, Loading, Logged, NotAsked, Op, Optional, Passed, Predicate, Reader, Refinement, RemoteData, Resource, State, Success, TaskMaybe, TaskResult, TaskValidation, These, TheseBoth, TheseFirst, TheseSecond, Tuple, Validation } from './core.js';
|
|
3
|
-
export { D as Deferred, E as Equality, a as Err, M as Maybe, N as None, O as Ok, b as Ordering, R as Result, S as Some, T as Task } from './Task-
|
|
3
|
+
export { D as Deferred, E as Equality, a as Err, M as Maybe, N as None, O as Ok, b as Ordering, R as Result, S as Some, T as Task } from './Task-Dt3ZMen6.js';
|
|
4
4
|
export { Arr, Dict, Num, Rec, Str, Uniq } from './utils.js';
|
|
5
|
-
export { Brand,
|
|
5
|
+
export { B as Brand, D as Duration } from './Duration-BTeT9D-q.js';
|
|
6
|
+
export { NonEmptyList, isNonEmptyList } from './types.js';
|
package/dist/index.js
CHANGED
|
@@ -402,10 +402,120 @@ pipe.try = (f, onError) => (a) => {
|
|
|
402
402
|
};
|
|
403
403
|
|
|
404
404
|
// src/Composition/tap.ts
|
|
405
|
-
var
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
405
|
+
var import_node_util = require("util");
|
|
406
|
+
|
|
407
|
+
// src/Types/Brand.ts
|
|
408
|
+
var Brand;
|
|
409
|
+
((Brand2) => {
|
|
410
|
+
Brand2.wrap = () => (value) => value;
|
|
411
|
+
Brand2.unwrap = (branded) => branded;
|
|
412
|
+
})(Brand || (Brand = {}));
|
|
413
|
+
|
|
414
|
+
// src/Types/NonEmptyList.ts
|
|
415
|
+
var isNonEmptyList = (list) => list.length > 0;
|
|
416
|
+
|
|
417
|
+
// src/Types/Duration.ts
|
|
418
|
+
var Duration;
|
|
419
|
+
((Duration2) => {
|
|
420
|
+
const wrap = Brand.wrap();
|
|
421
|
+
Duration2.milliseconds = (ms) => wrap(ms);
|
|
422
|
+
Duration2.seconds = (s) => wrap(s * 1e3);
|
|
423
|
+
Duration2.minutes = (m) => wrap(m * 60 * 1e3);
|
|
424
|
+
Duration2.hours = (h) => wrap(h * 60 * 60 * 1e3);
|
|
425
|
+
Duration2.days = (d) => wrap(d * 24 * 60 * 60 * 1e3);
|
|
426
|
+
Duration2.toMilliseconds = (d) => Brand.unwrap(d);
|
|
427
|
+
Duration2.toSeconds = (d) => Brand.unwrap(d) / 1e3;
|
|
428
|
+
Duration2.toMinutes = (d) => Brand.unwrap(d) / (60 * 1e3);
|
|
429
|
+
Duration2.toHours = (d) => Brand.unwrap(d) / (60 * 60 * 1e3);
|
|
430
|
+
Duration2.toDays = (d) => Brand.unwrap(d) / (24 * 60 * 60 * 1e3);
|
|
431
|
+
Duration2.add = (other) => (self) => wrap(Brand.unwrap(self) + Brand.unwrap(other));
|
|
432
|
+
Duration2.subtract = (other) => (self) => wrap(Brand.unwrap(self) - Brand.unwrap(other));
|
|
433
|
+
})(Duration || (Duration = {}));
|
|
434
|
+
|
|
435
|
+
// src/Composition/tap.ts
|
|
436
|
+
function tap(f) {
|
|
437
|
+
return (a) => {
|
|
438
|
+
f(a);
|
|
439
|
+
return a;
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
((tap2) => {
|
|
443
|
+
tap2.log = (options) => (a) => {
|
|
444
|
+
const logger = options?.logger ?? console.log;
|
|
445
|
+
const formatter = options?.formatter ?? ((val) => {
|
|
446
|
+
try {
|
|
447
|
+
return typeof val === "object" && val !== null ? JSON.stringify(val) : String(val);
|
|
448
|
+
} catch {
|
|
449
|
+
return String(val);
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
const formatted = formatter(a);
|
|
453
|
+
if (options?.label !== void 0) {
|
|
454
|
+
logger(`[${options.label}]: ${formatted}`);
|
|
455
|
+
} else {
|
|
456
|
+
logger(formatted);
|
|
457
|
+
}
|
|
458
|
+
return a;
|
|
459
|
+
};
|
|
460
|
+
tap2.inspect = (options) => (a) => {
|
|
461
|
+
const label = options?.label;
|
|
462
|
+
const depth = options?.depth ?? null;
|
|
463
|
+
const colors = options?.colors ?? true;
|
|
464
|
+
let formatted;
|
|
465
|
+
if (typeof import_node_util.inspect === "function") {
|
|
466
|
+
formatted = (0, import_node_util.inspect)(a, { depth, colors });
|
|
467
|
+
} else {
|
|
468
|
+
try {
|
|
469
|
+
formatted = JSON.stringify(a, null, 2);
|
|
470
|
+
} catch {
|
|
471
|
+
formatted = String(a);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
if (label !== void 0) {
|
|
475
|
+
console.log(`[${label}]: ${formatted}`);
|
|
476
|
+
} else {
|
|
477
|
+
console.log(formatted);
|
|
478
|
+
}
|
|
479
|
+
return a;
|
|
480
|
+
};
|
|
481
|
+
tap2.async = (fn, options) => (a) => {
|
|
482
|
+
const onError = options?.onError ?? console.error;
|
|
483
|
+
fn(a).catch((err2) => {
|
|
484
|
+
onError(err2);
|
|
485
|
+
});
|
|
486
|
+
return a;
|
|
487
|
+
};
|
|
488
|
+
tap2.time = (fn, config) => (a) => {
|
|
489
|
+
const start = performance.now();
|
|
490
|
+
const triggerFinish = (duration) => {
|
|
491
|
+
if (config.label !== void 0) {
|
|
492
|
+
console.log(`[${config.label}]: ${Duration.toMilliseconds(duration)}ms`);
|
|
493
|
+
} else if (config.onFinish) {
|
|
494
|
+
config.onFinish(duration);
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
try {
|
|
498
|
+
const res = fn(a);
|
|
499
|
+
if (res instanceof Promise) {
|
|
500
|
+
res.then(() => {
|
|
501
|
+
const duration = Duration.milliseconds(performance.now() - start);
|
|
502
|
+
triggerFinish(duration);
|
|
503
|
+
}, () => {
|
|
504
|
+
const duration = Duration.milliseconds(performance.now() - start);
|
|
505
|
+
triggerFinish(duration);
|
|
506
|
+
});
|
|
507
|
+
} else {
|
|
508
|
+
const duration = Duration.milliseconds(performance.now() - start);
|
|
509
|
+
triggerFinish(duration);
|
|
510
|
+
}
|
|
511
|
+
} catch (err2) {
|
|
512
|
+
const duration = Duration.milliseconds(performance.now() - start);
|
|
513
|
+
triggerFinish(duration);
|
|
514
|
+
throw err2;
|
|
515
|
+
}
|
|
516
|
+
return a;
|
|
517
|
+
};
|
|
518
|
+
})(tap || (tap = {}));
|
|
409
519
|
|
|
410
520
|
// src/Composition/uncurry.ts
|
|
411
521
|
function uncurry(f) {
|
|
@@ -575,34 +685,6 @@ var Maybe;
|
|
|
575
685
|
};
|
|
576
686
|
})(Maybe || (Maybe = {}));
|
|
577
687
|
|
|
578
|
-
// src/Types/Brand.ts
|
|
579
|
-
var Brand;
|
|
580
|
-
((Brand2) => {
|
|
581
|
-
Brand2.wrap = () => (value) => value;
|
|
582
|
-
Brand2.unwrap = (branded) => branded;
|
|
583
|
-
})(Brand || (Brand = {}));
|
|
584
|
-
|
|
585
|
-
// src/Types/Duration.ts
|
|
586
|
-
var Duration;
|
|
587
|
-
((Duration2) => {
|
|
588
|
-
const wrap = Brand.wrap();
|
|
589
|
-
Duration2.milliseconds = (ms) => wrap(ms);
|
|
590
|
-
Duration2.seconds = (s) => wrap(s * 1e3);
|
|
591
|
-
Duration2.minutes = (m) => wrap(m * 60 * 1e3);
|
|
592
|
-
Duration2.hours = (h) => wrap(h * 60 * 60 * 1e3);
|
|
593
|
-
Duration2.days = (d) => wrap(d * 24 * 60 * 60 * 1e3);
|
|
594
|
-
Duration2.toMilliseconds = (d) => Brand.unwrap(d);
|
|
595
|
-
Duration2.toSeconds = (d) => Brand.unwrap(d) / 1e3;
|
|
596
|
-
Duration2.toMinutes = (d) => Brand.unwrap(d) / (60 * 1e3);
|
|
597
|
-
Duration2.toHours = (d) => Brand.unwrap(d) / (60 * 60 * 1e3);
|
|
598
|
-
Duration2.toDays = (d) => Brand.unwrap(d) / (24 * 60 * 60 * 1e3);
|
|
599
|
-
Duration2.add = (other) => (self) => wrap(Brand.unwrap(self) + Brand.unwrap(other));
|
|
600
|
-
Duration2.subtract = (other) => (self) => wrap(Brand.unwrap(self) - Brand.unwrap(other));
|
|
601
|
-
})(Duration || (Duration = {}));
|
|
602
|
-
|
|
603
|
-
// src/Types/NonEmptyList.ts
|
|
604
|
-
var isNonEmptyList = (list) => list.length > 0;
|
|
605
|
-
|
|
606
688
|
// src/internal/Op.util.ts
|
|
607
689
|
var _abortedNil = { kind: "OpNil", reason: "aborted" };
|
|
608
690
|
var _droppedNil = { kind: "OpNil", reason: "dropped" };
|
|
@@ -2243,7 +2325,7 @@ var Task;
|
|
|
2243
2325
|
};
|
|
2244
2326
|
return { task, abort };
|
|
2245
2327
|
};
|
|
2246
|
-
Task2.run = (signal) => (task) =>
|
|
2328
|
+
Task2.run = (signal) => (task) => task(signal);
|
|
2247
2329
|
Task2.bindTo = (key) => (data) => (0, Task2.map)((a) => ({ [key]: a }))(data);
|
|
2248
2330
|
Task2.bind = (key, f) => (data) => (0, Task2.chain)(
|
|
2249
2331
|
(a) => (0, Task2.map)((b) => ({ ...a, [key]: b }))(f(a))
|
|
@@ -2307,7 +2389,7 @@ var TaskResult3;
|
|
|
2307
2389
|
([of_, oa]) => Result.ap(oa)(of_)
|
|
2308
2390
|
)
|
|
2309
2391
|
);
|
|
2310
|
-
TaskResult4.run = (signal) => (task) =>
|
|
2392
|
+
TaskResult4.run = (signal) => (task) => task(signal);
|
|
2311
2393
|
TaskResult4.bindTo = (key) => (data) => (0, TaskResult4.map)((a) => ({ [key]: a }))(data);
|
|
2312
2394
|
TaskResult4.bind = (key, f) => (data) => (0, TaskResult4.chain)(
|
|
2313
2395
|
(a) => (0, TaskResult4.map)((b) => ({ ...a, [key]: b }))(f(a))
|
|
@@ -3035,6 +3117,7 @@ var Num;
|
|
|
3035
3117
|
};
|
|
3036
3118
|
Num2.clamp = (min2, max2) => (n) => Math.min(Math.max(n, min2), max2);
|
|
3037
3119
|
Num2.between = (min2, max2) => (n) => n >= min2 && n <= max2;
|
|
3120
|
+
Num2.inRange = (start, end) => (n) => n >= start && n < end;
|
|
3038
3121
|
Num2.parse = (s) => {
|
|
3039
3122
|
if (s.trim() === "") {
|
|
3040
3123
|
return Maybe.none();
|
package/dist/index.mjs
CHANGED
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
uncurry,
|
|
28
28
|
uncurry3,
|
|
29
29
|
uncurry4
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-TCE2UETM.mjs";
|
|
31
31
|
import {
|
|
32
32
|
Arr,
|
|
33
33
|
Dict,
|
|
@@ -35,7 +35,7 @@ import {
|
|
|
35
35
|
Rec,
|
|
36
36
|
Str,
|
|
37
37
|
Uniq
|
|
38
|
-
} from "./chunk-
|
|
38
|
+
} from "./chunk-V37OUM35.mjs";
|
|
39
39
|
import {
|
|
40
40
|
Combinable,
|
|
41
41
|
Deferred,
|
|
@@ -61,12 +61,12 @@ import {
|
|
|
61
61
|
These,
|
|
62
62
|
Tuple,
|
|
63
63
|
Validation
|
|
64
|
-
} from "./chunk-
|
|
64
|
+
} from "./chunk-COGQKPIP.mjs";
|
|
65
65
|
import {
|
|
66
66
|
Brand,
|
|
67
67
|
Duration,
|
|
68
68
|
isNonEmptyList
|
|
69
|
-
} from "./chunk-
|
|
69
|
+
} from "./chunk-GBB6LVLI.mjs";
|
|
70
70
|
export {
|
|
71
71
|
Arr,
|
|
72
72
|
Brand,
|