@nlozgachev/pipelined 0.62.0 → 0.64.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/README.md +14 -14
- package/dist/{Duration-B8joKzro.d.cts → Duration-DeyxG6VQ.d.cts} +20 -20
- package/dist/{Duration-B8joKzro.d.ts → Duration-DeyxG6VQ.d.ts} +20 -20
- package/dist/{InternalTypes-LdhLQx3N.d.ts → InternalTypes-CCXa8Kvr.d.ts} +11 -11
- package/dist/{InternalTypes-DuK_XpTi.d.cts → InternalTypes-GFn4RTwD.d.cts} +11 -11
- package/dist/{Validation-DZLizBZ0.d.ts → Task-9SJCMtG4.d.ts} +690 -1395
- package/dist/{Validation-DC3uUizM.d.cts → Task-C_goFYQ1.d.cts} +690 -1395
- package/dist/composition.cjs +216 -95
- package/dist/composition.d.cts +8 -76
- package/dist/composition.d.ts +8 -76
- package/dist/composition.mjs +216 -95
- package/dist/core.cjs +4905 -1028
- package/dist/core.d.cts +371 -773
- package/dist/core.d.ts +371 -773
- package/dist/core.mjs +4905 -1028
- package/dist/data.cjs +3313 -1242
- package/dist/data.d.cts +676 -1823
- package/dist/data.d.ts +676 -1823
- package/dist/data.mjs +3309 -1239
- package/dist/index.cjs +7270 -2216
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.mjs +7269 -2216
- package/dist/types.cjs +175 -31
- package/dist/types.d.cts +6 -6
- package/dist/types.d.ts +6 -6
- package/dist/types.mjs +175 -31
- package/package.json +24 -13
package/dist/composition.mjs
CHANGED
|
@@ -222,9 +222,9 @@ var memoize = (f, options) => {
|
|
|
222
222
|
const result = f(a);
|
|
223
223
|
cache.set(key, result);
|
|
224
224
|
if (maxSize !== void 0 && cache.size > maxSize) {
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
|
|
225
|
+
for (const k of cache.keys()) {
|
|
226
|
+
cache.delete(k);
|
|
227
|
+
break;
|
|
228
228
|
}
|
|
229
229
|
}
|
|
230
230
|
return result;
|
|
@@ -334,32 +334,151 @@ pipe.try = (f, onError) => (a) => {
|
|
|
334
334
|
import { inspect as nodeInspect } from "util";
|
|
335
335
|
|
|
336
336
|
// src/Types/Brand.ts
|
|
337
|
-
var Brand
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
337
|
+
var Brand = {
|
|
338
|
+
/**
|
|
339
|
+
* Returns a constructor that wraps a value of type T in brand K.
|
|
340
|
+
* The resulting function performs an unchecked cast — only use when the raw
|
|
341
|
+
* value is known to satisfy the brand's invariants.
|
|
342
|
+
*
|
|
343
|
+
* @example
|
|
344
|
+
* ```ts
|
|
345
|
+
* type PositiveNumber = Brand<"PositiveNumber", number>;
|
|
346
|
+
* const toPositiveNumber = Brand.wrap<"PositiveNumber", number>();
|
|
347
|
+
*
|
|
348
|
+
* const n: PositiveNumber = toPositiveNumber(42);
|
|
349
|
+
* ```
|
|
350
|
+
*/
|
|
351
|
+
wrap: () => (value) => value,
|
|
352
|
+
/**
|
|
353
|
+
* Strips the brand and returns the underlying value.
|
|
354
|
+
* Since Brand<K, T> extends T this is rarely needed, but can improve readability.
|
|
355
|
+
*
|
|
356
|
+
* @example
|
|
357
|
+
* ```ts
|
|
358
|
+
* type UserId = Brand<"UserId", string>;
|
|
359
|
+
* const toUserId = Brand.wrap<"UserId", string>();
|
|
360
|
+
* const userId: UserId = toUserId("user-123");
|
|
361
|
+
* const raw: string = Brand.unwrap(userId); // "user-123"
|
|
362
|
+
* ```
|
|
363
|
+
*/
|
|
364
|
+
unwrap: (branded) => branded
|
|
365
|
+
};
|
|
342
366
|
|
|
343
367
|
// src/Types/Duration.ts
|
|
344
|
-
var
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
368
|
+
var wrap = Brand.wrap();
|
|
369
|
+
var Duration = {
|
|
370
|
+
/**
|
|
371
|
+
* Creates a Duration from milliseconds.
|
|
372
|
+
*
|
|
373
|
+
* @example
|
|
374
|
+
* ```ts
|
|
375
|
+
* Duration.milliseconds(500); // 500ms Duration
|
|
376
|
+
* ```
|
|
377
|
+
*/
|
|
378
|
+
milliseconds: (ms) => wrap(ms),
|
|
379
|
+
/**
|
|
380
|
+
* Creates a Duration from seconds.
|
|
381
|
+
*
|
|
382
|
+
* @example
|
|
383
|
+
* ```ts
|
|
384
|
+
* Duration.seconds(2); // 2000ms Duration
|
|
385
|
+
* ```
|
|
386
|
+
*/
|
|
387
|
+
seconds: (s) => wrap(s * 1e3),
|
|
388
|
+
/**
|
|
389
|
+
* Creates a Duration from minutes.
|
|
390
|
+
*
|
|
391
|
+
* @example
|
|
392
|
+
* ```ts
|
|
393
|
+
* Duration.minutes(5); // 300000ms Duration
|
|
394
|
+
* ```
|
|
395
|
+
*/
|
|
396
|
+
minutes: (m) => wrap(m * 60 * 1e3),
|
|
397
|
+
/**
|
|
398
|
+
* Creates a Duration from hours.
|
|
399
|
+
*
|
|
400
|
+
* @example
|
|
401
|
+
* ```ts
|
|
402
|
+
* Duration.hours(1); // 3600000ms Duration
|
|
403
|
+
* ```
|
|
404
|
+
*/
|
|
405
|
+
hours: (h) => wrap(h * 60 * 60 * 1e3),
|
|
406
|
+
/**
|
|
407
|
+
* Creates a Duration from days.
|
|
408
|
+
*
|
|
409
|
+
* @example
|
|
410
|
+
* ```ts
|
|
411
|
+
* Duration.days(1); // 86400000ms Duration
|
|
412
|
+
* ```
|
|
413
|
+
*/
|
|
414
|
+
days: (d) => wrap(d * 24 * 60 * 60 * 1e3),
|
|
415
|
+
// --- to ---
|
|
416
|
+
to: {
|
|
417
|
+
/**
|
|
418
|
+
* Converts a Duration back to raw milliseconds.
|
|
419
|
+
*
|
|
420
|
+
* @example
|
|
421
|
+
* ```ts
|
|
422
|
+
* Duration.to.milliseconds(Duration.seconds(2)); // 2000
|
|
423
|
+
* ```
|
|
424
|
+
*/
|
|
425
|
+
milliseconds: (d) => Brand.unwrap(d),
|
|
426
|
+
/**
|
|
427
|
+
* Converts a Duration to seconds.
|
|
428
|
+
*
|
|
429
|
+
* @example
|
|
430
|
+
* ```ts
|
|
431
|
+
* Duration.to.seconds(Duration.milliseconds(2500)); // 2.5
|
|
432
|
+
* ```
|
|
433
|
+
*/
|
|
434
|
+
seconds: (d) => Brand.unwrap(d) / 1e3,
|
|
435
|
+
/**
|
|
436
|
+
* Converts a Duration to minutes.
|
|
437
|
+
*
|
|
438
|
+
* @example
|
|
439
|
+
* ```ts
|
|
440
|
+
* Duration.to.minutes(Duration.seconds(120)); // 2
|
|
441
|
+
* ```
|
|
442
|
+
*/
|
|
443
|
+
minutes: (d) => Brand.unwrap(d) / (60 * 1e3),
|
|
444
|
+
/**
|
|
445
|
+
* Converts a Duration to hours.
|
|
446
|
+
*
|
|
447
|
+
* @example
|
|
448
|
+
* ```ts
|
|
449
|
+
* Duration.to.hours(Duration.minutes(90)); // 1.5
|
|
450
|
+
* ```
|
|
451
|
+
*/
|
|
452
|
+
hours: (d) => Brand.unwrap(d) / (60 * 60 * 1e3),
|
|
453
|
+
/**
|
|
454
|
+
* Converts a Duration to days.
|
|
455
|
+
*
|
|
456
|
+
* @example
|
|
457
|
+
* ```ts
|
|
458
|
+
* Duration.to.days(Duration.hours(36)); // 1.5
|
|
459
|
+
* ```
|
|
460
|
+
*/
|
|
461
|
+
days: (d) => Brand.unwrap(d) / (24 * 60 * 60 * 1e3)
|
|
462
|
+
},
|
|
463
|
+
/**
|
|
464
|
+
* Adds two Durations together.
|
|
465
|
+
*
|
|
466
|
+
* @example
|
|
467
|
+
* ```ts
|
|
468
|
+
* pipe(Duration.seconds(1), Duration.add(Duration.milliseconds(500))); // 1500ms
|
|
469
|
+
* ```
|
|
470
|
+
*/
|
|
471
|
+
add: (other) => (self) => wrap(Brand.unwrap(self) + Brand.unwrap(other)),
|
|
472
|
+
/**
|
|
473
|
+
* Subtracts the other Duration from this one.
|
|
474
|
+
*
|
|
475
|
+
* @example
|
|
476
|
+
* ```ts
|
|
477
|
+
* pipe(Duration.seconds(1), Duration.subtract(Duration.milliseconds(500))); // 500ms
|
|
478
|
+
* ```
|
|
479
|
+
*/
|
|
480
|
+
subtract: (other) => (self) => wrap(Brand.unwrap(self) - Brand.unwrap(other))
|
|
481
|
+
};
|
|
363
482
|
|
|
364
483
|
// src/Composition/tap.ts
|
|
365
484
|
function tap(f) {
|
|
@@ -368,83 +487,85 @@ function tap(f) {
|
|
|
368
487
|
return a;
|
|
369
488
|
};
|
|
370
489
|
}
|
|
371
|
-
((
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
formatted = String(a);
|
|
401
|
-
}
|
|
490
|
+
var log = (options) => (a) => {
|
|
491
|
+
const logger = options?.logger ?? console.log;
|
|
492
|
+
const formatter = options?.formatter ?? ((val) => {
|
|
493
|
+
try {
|
|
494
|
+
return typeof val === "object" && val !== null ? JSON.stringify(val) : String(val);
|
|
495
|
+
} catch {
|
|
496
|
+
return String(val);
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
const formatted = formatter(a);
|
|
500
|
+
if (options?.label !== void 0) {
|
|
501
|
+
logger(`[${options.label}]: ${formatted}`);
|
|
502
|
+
} else {
|
|
503
|
+
logger(formatted);
|
|
504
|
+
}
|
|
505
|
+
return a;
|
|
506
|
+
};
|
|
507
|
+
var inspect = (options) => (a) => {
|
|
508
|
+
const label = options?.label;
|
|
509
|
+
const depth = options?.depth ?? null;
|
|
510
|
+
const colors = options?.colors ?? true;
|
|
511
|
+
let formatted;
|
|
512
|
+
if (typeof nodeInspect === "function") {
|
|
513
|
+
formatted = nodeInspect(a, { depth, colors });
|
|
514
|
+
} else {
|
|
515
|
+
try {
|
|
516
|
+
formatted = JSON.stringify(a, null, 2);
|
|
517
|
+
} catch {
|
|
518
|
+
formatted = String(a);
|
|
402
519
|
}
|
|
403
|
-
|
|
404
|
-
|
|
520
|
+
}
|
|
521
|
+
if (label !== void 0) {
|
|
522
|
+
console.log(`[${label}]: ${formatted}`);
|
|
523
|
+
} else {
|
|
524
|
+
console.log(formatted);
|
|
525
|
+
}
|
|
526
|
+
return a;
|
|
527
|
+
};
|
|
528
|
+
var async3 = (fn, options) => (a) => {
|
|
529
|
+
const onError = options?.onError ?? console.error;
|
|
530
|
+
Promise.resolve(fn(a)).catch((err) => {
|
|
531
|
+
onError(err);
|
|
532
|
+
});
|
|
533
|
+
return a;
|
|
534
|
+
};
|
|
535
|
+
var time = (fn, config) => (a) => {
|
|
536
|
+
const start = performance.now();
|
|
537
|
+
const triggerFinish = (duration) => {
|
|
538
|
+
if (config.label !== void 0) {
|
|
539
|
+
console.log(`[${config.label}]: ${Duration.to.milliseconds(duration)}ms`);
|
|
405
540
|
} else {
|
|
406
|
-
|
|
541
|
+
config.onFinish(duration);
|
|
407
542
|
}
|
|
408
|
-
return a;
|
|
409
|
-
};
|
|
410
|
-
tap2.async = (fn, options) => (a) => {
|
|
411
|
-
const onError = options?.onError ?? console.error;
|
|
412
|
-
Promise.resolve(fn(a)).catch((err) => {
|
|
413
|
-
onError(err);
|
|
414
|
-
});
|
|
415
|
-
return a;
|
|
416
543
|
};
|
|
417
|
-
|
|
418
|
-
const
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
console.log(`[${config.label}]: ${Duration.to.milliseconds(duration)}ms`);
|
|
422
|
-
} else {
|
|
423
|
-
config.onFinish(duration);
|
|
424
|
-
}
|
|
425
|
-
};
|
|
426
|
-
try {
|
|
427
|
-
const res = fn(a);
|
|
428
|
-
if (res !== null && (typeof res === "object" || typeof res === "function") && typeof res.then === "function") {
|
|
429
|
-
res.then(() => {
|
|
430
|
-
const duration = Duration.milliseconds(performance.now() - start);
|
|
431
|
-
triggerFinish(duration);
|
|
432
|
-
}, () => {
|
|
433
|
-
const duration = Duration.milliseconds(performance.now() - start);
|
|
434
|
-
triggerFinish(duration);
|
|
435
|
-
});
|
|
436
|
-
} else {
|
|
544
|
+
try {
|
|
545
|
+
const res = fn(a);
|
|
546
|
+
if (res !== null && (typeof res === "object" || typeof res === "function") && typeof res.then === "function") {
|
|
547
|
+
res.then(() => {
|
|
437
548
|
const duration = Duration.milliseconds(performance.now() - start);
|
|
438
549
|
triggerFinish(duration);
|
|
439
|
-
}
|
|
440
|
-
|
|
550
|
+
}, () => {
|
|
551
|
+
const duration = Duration.milliseconds(performance.now() - start);
|
|
552
|
+
triggerFinish(duration);
|
|
553
|
+
});
|
|
554
|
+
} else {
|
|
441
555
|
const duration = Duration.milliseconds(performance.now() - start);
|
|
442
556
|
triggerFinish(duration);
|
|
443
|
-
throw err;
|
|
444
557
|
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
558
|
+
} catch (err) {
|
|
559
|
+
const duration = Duration.milliseconds(performance.now() - start);
|
|
560
|
+
triggerFinish(duration);
|
|
561
|
+
throw err;
|
|
562
|
+
}
|
|
563
|
+
return a;
|
|
564
|
+
};
|
|
565
|
+
tap.log = log;
|
|
566
|
+
tap.inspect = inspect;
|
|
567
|
+
tap.async = async3;
|
|
568
|
+
tap.time = time;
|
|
448
569
|
|
|
449
570
|
// src/Composition/uncurry.ts
|
|
450
571
|
function uncurry(f) {
|