@nlozgachev/pipelined 0.42.0 → 0.44.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/index.mjs CHANGED
@@ -27,7 +27,7 @@ import {
27
27
  uncurry,
28
28
  uncurry3,
29
29
  uncurry4
30
- } from "./chunk-F6SBU7GB.mjs";
30
+ } from "./chunk-X6XQX3OZ.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-6VYLZTAM.mjs";
38
+ } from "./chunk-LKTOK5IT.mjs";
39
39
  import {
40
40
  Combinable,
41
41
  Deferred,
@@ -61,12 +61,11 @@ import {
61
61
  These,
62
62
  Tuple,
63
63
  Validation
64
- } from "./chunk-OAP765G3.mjs";
64
+ } from "./chunk-ND476266.mjs";
65
65
  import {
66
66
  Brand,
67
- Duration,
68
- isNonEmptyList
69
- } from "./chunk-GBB6LVLI.mjs";
67
+ Duration
68
+ } from "./chunk-74JKKJ4R.mjs";
70
69
  export {
71
70
  Arr,
72
71
  Brand,
@@ -116,7 +115,6 @@ export {
116
115
  flip,
117
116
  flow,
118
117
  identity,
119
- isNonEmptyList,
120
118
  juxt,
121
119
  memoize,
122
120
  memoizeWeak,
package/dist/types.d.mts CHANGED
@@ -1,32 +1,127 @@
1
- export { B as Brand, D as Duration } from './Duration-BTeT9D-q.mjs';
2
-
1
+ declare const _brand: unique symbol;
3
2
  /**
4
- * A list that is guaranteed to have at least one element.
5
- * Useful for ensuring functions receive non-empty input and for
6
- * accumulating errors in Validation.
3
+ * Brand<K, T> creates a nominal type by tagging T with a phantom brand K.
4
+ * Prevents accidentally mixing up values that share the same underlying type.
7
5
  *
8
6
  * @example
9
7
  * ```ts
10
- * const errors: NonEmptyList<string> = ["First error", "Second error"];
8
+ * type UserId = Brand<"UserId", string>;
9
+ * type ProductId = Brand<"ProductId", string>;
10
+ *
11
+ * const toUserId = Brand.wrap<"UserId", string>();
12
+ * const toProductId = Brand.wrap<"ProductId", string>();
11
13
  *
12
- * // TypeScript ensures at least one element:
13
- * const invalid: NonEmptyList<string> = []; // Error!
14
+ * const userId: UserId = toUserId("user-123");
15
+ * const productId: ProductId = toProductId("prod-456");
16
+ *
17
+ * // Type error: ProductId is not assignable to UserId
18
+ * // const wrong: UserId = productId;
14
19
  * ```
15
20
  */
16
- type NonEmptyList<A> = readonly [A, ...A[]];
21
+ type Brand<K extends string, T> = T & {
22
+ readonly [_brand]: K;
23
+ };
24
+ declare namespace Brand {
25
+ /**
26
+ * Returns a constructor that wraps a value of type T in brand K.
27
+ * The resulting function performs an unchecked cast — only use when the raw
28
+ * value is known to satisfy the brand's invariants.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * type PositiveNumber = Brand<"PositiveNumber", number>;
33
+ * const toPositiveNumber = Brand.wrap<"PositiveNumber", number>();
34
+ *
35
+ * const n: PositiveNumber = toPositiveNumber(42);
36
+ * ```
37
+ */
38
+ const wrap: <K extends string, T>() => (value: T) => Brand<K, T>;
39
+ /**
40
+ * Strips the brand and returns the underlying value.
41
+ * Since Brand<K, T> extends T this is rarely needed, but can improve readability.
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * const userId: UserId = toUserId("user-123");
46
+ * const raw: string = Brand.unwrap(userId); // "user-123"
47
+ * ```
48
+ */
49
+ const unwrap: <K extends string, T>(branded: Brand<K, T>) => T;
50
+ }
51
+
17
52
  /**
18
- * Type guard that checks if an array is non-empty.
53
+ * A branded nominal type representing a duration of time in milliseconds.
54
+ * Use Duration to ensure safe time-based operators and clear unit conversions.
19
55
  *
20
56
  * @example
21
57
  * ```ts
22
- * const items: string[] = getItems();
58
+ * const halfSecond = Duration.milliseconds(500);
59
+ * const twoSeconds = Duration.seconds(2);
60
+ * const total = pipe(halfSecond, Duration.add(twoSeconds));
23
61
  *
24
- * if (isNonEmptyList(items)) {
25
- * // TypeScript knows items has at least one element
26
- * const first = items[0]; // string, not string | undefined
27
- * }
62
+ * Duration.toSeconds(total); // 2.5
28
63
  * ```
29
64
  */
30
- declare const isNonEmptyList: <A>(list: readonly A[]) => list is NonEmptyList<A>;
65
+ type Duration = Brand<"Duration", number>;
66
+ declare namespace Duration {
67
+ /**
68
+ * Creates a Duration from milliseconds.
69
+ */
70
+ const milliseconds: (ms: number) => Duration;
71
+ /**
72
+ * Creates a Duration from seconds.
73
+ */
74
+ const seconds: (s: number) => Duration;
75
+ /**
76
+ * Creates a Duration from minutes.
77
+ */
78
+ const minutes: (m: number) => Duration;
79
+ /**
80
+ * Creates a Duration from hours.
81
+ */
82
+ const hours: (h: number) => Duration;
83
+ /**
84
+ * Creates a Duration from days.
85
+ */
86
+ const days: (d: number) => Duration;
87
+ /**
88
+ * Converts a Duration back to raw milliseconds.
89
+ */
90
+ const toMilliseconds: (d: Duration) => number;
91
+ /**
92
+ * Converts a Duration to seconds.
93
+ */
94
+ const toSeconds: (d: Duration) => number;
95
+ /**
96
+ * Converts a Duration to minutes.
97
+ */
98
+ const toMinutes: (d: Duration) => number;
99
+ /**
100
+ * Converts a Duration to hours.
101
+ */
102
+ const toHours: (d: Duration) => number;
103
+ /**
104
+ * Converts a Duration to days.
105
+ */
106
+ const toDays: (d: Duration) => number;
107
+ /**
108
+ * Adds two Durations together.
109
+ *
110
+ * @example
111
+ * ```ts
112
+ * pipe(Duration.seconds(1), Duration.add(Duration.milliseconds(500))); // 1500ms
113
+ * ```
114
+ */
115
+ const add: (other: Duration) => (self: Duration) => Duration;
116
+ /**
117
+ * Subtracts the other Duration from this one.
118
+ *
119
+ * @example
120
+ * ```ts
121
+ * pipe(Duration.seconds(1), Duration.subtract(Duration.milliseconds(500))); // 500ms
122
+ * ```
123
+ */
124
+ const subtract: (other: Duration) => (self: Duration) => Duration;
125
+ }
31
126
 
32
- export { type NonEmptyList, isNonEmptyList };
127
+ export { Brand, Duration };
package/dist/types.d.ts CHANGED
@@ -1,32 +1,127 @@
1
- export { B as Brand, D as Duration } from './Duration-BTeT9D-q.js';
2
-
1
+ declare const _brand: unique symbol;
3
2
  /**
4
- * A list that is guaranteed to have at least one element.
5
- * Useful for ensuring functions receive non-empty input and for
6
- * accumulating errors in Validation.
3
+ * Brand<K, T> creates a nominal type by tagging T with a phantom brand K.
4
+ * Prevents accidentally mixing up values that share the same underlying type.
7
5
  *
8
6
  * @example
9
7
  * ```ts
10
- * const errors: NonEmptyList<string> = ["First error", "Second error"];
8
+ * type UserId = Brand<"UserId", string>;
9
+ * type ProductId = Brand<"ProductId", string>;
10
+ *
11
+ * const toUserId = Brand.wrap<"UserId", string>();
12
+ * const toProductId = Brand.wrap<"ProductId", string>();
11
13
  *
12
- * // TypeScript ensures at least one element:
13
- * const invalid: NonEmptyList<string> = []; // Error!
14
+ * const userId: UserId = toUserId("user-123");
15
+ * const productId: ProductId = toProductId("prod-456");
16
+ *
17
+ * // Type error: ProductId is not assignable to UserId
18
+ * // const wrong: UserId = productId;
14
19
  * ```
15
20
  */
16
- type NonEmptyList<A> = readonly [A, ...A[]];
21
+ type Brand<K extends string, T> = T & {
22
+ readonly [_brand]: K;
23
+ };
24
+ declare namespace Brand {
25
+ /**
26
+ * Returns a constructor that wraps a value of type T in brand K.
27
+ * The resulting function performs an unchecked cast — only use when the raw
28
+ * value is known to satisfy the brand's invariants.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * type PositiveNumber = Brand<"PositiveNumber", number>;
33
+ * const toPositiveNumber = Brand.wrap<"PositiveNumber", number>();
34
+ *
35
+ * const n: PositiveNumber = toPositiveNumber(42);
36
+ * ```
37
+ */
38
+ const wrap: <K extends string, T>() => (value: T) => Brand<K, T>;
39
+ /**
40
+ * Strips the brand and returns the underlying value.
41
+ * Since Brand<K, T> extends T this is rarely needed, but can improve readability.
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * const userId: UserId = toUserId("user-123");
46
+ * const raw: string = Brand.unwrap(userId); // "user-123"
47
+ * ```
48
+ */
49
+ const unwrap: <K extends string, T>(branded: Brand<K, T>) => T;
50
+ }
51
+
17
52
  /**
18
- * Type guard that checks if an array is non-empty.
53
+ * A branded nominal type representing a duration of time in milliseconds.
54
+ * Use Duration to ensure safe time-based operators and clear unit conversions.
19
55
  *
20
56
  * @example
21
57
  * ```ts
22
- * const items: string[] = getItems();
58
+ * const halfSecond = Duration.milliseconds(500);
59
+ * const twoSeconds = Duration.seconds(2);
60
+ * const total = pipe(halfSecond, Duration.add(twoSeconds));
23
61
  *
24
- * if (isNonEmptyList(items)) {
25
- * // TypeScript knows items has at least one element
26
- * const first = items[0]; // string, not string | undefined
27
- * }
62
+ * Duration.toSeconds(total); // 2.5
28
63
  * ```
29
64
  */
30
- declare const isNonEmptyList: <A>(list: readonly A[]) => list is NonEmptyList<A>;
65
+ type Duration = Brand<"Duration", number>;
66
+ declare namespace Duration {
67
+ /**
68
+ * Creates a Duration from milliseconds.
69
+ */
70
+ const milliseconds: (ms: number) => Duration;
71
+ /**
72
+ * Creates a Duration from seconds.
73
+ */
74
+ const seconds: (s: number) => Duration;
75
+ /**
76
+ * Creates a Duration from minutes.
77
+ */
78
+ const minutes: (m: number) => Duration;
79
+ /**
80
+ * Creates a Duration from hours.
81
+ */
82
+ const hours: (h: number) => Duration;
83
+ /**
84
+ * Creates a Duration from days.
85
+ */
86
+ const days: (d: number) => Duration;
87
+ /**
88
+ * Converts a Duration back to raw milliseconds.
89
+ */
90
+ const toMilliseconds: (d: Duration) => number;
91
+ /**
92
+ * Converts a Duration to seconds.
93
+ */
94
+ const toSeconds: (d: Duration) => number;
95
+ /**
96
+ * Converts a Duration to minutes.
97
+ */
98
+ const toMinutes: (d: Duration) => number;
99
+ /**
100
+ * Converts a Duration to hours.
101
+ */
102
+ const toHours: (d: Duration) => number;
103
+ /**
104
+ * Converts a Duration to days.
105
+ */
106
+ const toDays: (d: Duration) => number;
107
+ /**
108
+ * Adds two Durations together.
109
+ *
110
+ * @example
111
+ * ```ts
112
+ * pipe(Duration.seconds(1), Duration.add(Duration.milliseconds(500))); // 1500ms
113
+ * ```
114
+ */
115
+ const add: (other: Duration) => (self: Duration) => Duration;
116
+ /**
117
+ * Subtracts the other Duration from this one.
118
+ *
119
+ * @example
120
+ * ```ts
121
+ * pipe(Duration.seconds(1), Duration.subtract(Duration.milliseconds(500))); // 500ms
122
+ * ```
123
+ */
124
+ const subtract: (other: Duration) => (self: Duration) => Duration;
125
+ }
31
126
 
32
- export { type NonEmptyList, isNonEmptyList };
127
+ export { Brand, Duration };
package/dist/types.js CHANGED
@@ -21,8 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var Types_exports = {};
22
22
  __export(Types_exports, {
23
23
  Brand: () => Brand,
24
- Duration: () => Duration,
25
- isNonEmptyList: () => isNonEmptyList
24
+ Duration: () => Duration
26
25
  });
27
26
  module.exports = __toCommonJS(Types_exports);
28
27
 
@@ -50,12 +49,8 @@ var Duration;
50
49
  Duration2.add = (other) => (self) => wrap(Brand.unwrap(self) + Brand.unwrap(other));
51
50
  Duration2.subtract = (other) => (self) => wrap(Brand.unwrap(self) - Brand.unwrap(other));
52
51
  })(Duration || (Duration = {}));
53
-
54
- // src/Types/NonEmptyList.ts
55
- var isNonEmptyList = (list) => list.length > 0;
56
52
  // Annotate the CommonJS export names for ESM import in node:
57
53
  0 && (module.exports = {
58
54
  Brand,
59
- Duration,
60
- isNonEmptyList
55
+ Duration
61
56
  });
package/dist/types.mjs CHANGED
@@ -1,10 +1,8 @@
1
1
  import {
2
2
  Brand,
3
- Duration,
4
- isNonEmptyList
5
- } from "./chunk-GBB6LVLI.mjs";
3
+ Duration
4
+ } from "./chunk-74JKKJ4R.mjs";
6
5
  export {
7
6
  Brand,
8
- Duration,
9
- isNonEmptyList
7
+ Duration
10
8
  };