@nlozgachev/pipelined 0.32.0 → 0.33.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/{Task-CjYKLeTY.d.ts → Task-5na0QzS4.d.mts} +63 -13
- package/dist/{Task-CJZfcOkO.d.mts → Task-DeiWgoeJ.d.ts} +63 -13
- package/dist/{chunk-L3NC44SN.mjs → chunk-FZX4MTRI.mjs} +14 -1
- package/dist/{chunk-TK5ZCGP2.mjs → chunk-GSTKY7MF.mjs} +51 -5
- package/dist/chunk-IPP4XFYH.mjs +0 -0
- package/dist/chunk-VWVPHDZO.mjs +29 -0
- package/dist/{chunk-EHQFUWZW.mjs → chunk-W53ZYTLX.mjs} +42 -1
- package/dist/core.d.mts +72 -3
- package/dist/core.d.ts +72 -3
- package/dist/core.js +85 -5
- package/dist/core.mjs +3 -2
- package/dist/index.d.mts +2 -3
- package/dist/index.d.ts +2 -3
- package/dist/index.js +128 -12
- package/dist/index.mjs +9 -6
- package/dist/types.d.mts +104 -2
- package/dist/types.d.ts +104 -2
- package/dist/types.js +20 -0
- package/dist/types.mjs +6 -3
- package/dist/utils.d.mts +44 -2
- package/dist/utils.d.ts +44 -2
- package/dist/utils.js +113 -5
- package/dist/utils.mjs +3 -2
- package/package.json +1 -1
- package/dist/NonEmptyList-BlGFjor5.d.mts +0 -30
- package/dist/NonEmptyList-BlGFjor5.d.ts +0 -30
- package/dist/chunk-BYWKZLHM.mjs +0 -10
package/dist/types.d.mts
CHANGED
|
@@ -1,4 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* A list that is guaranteed to have at least one element.
|
|
3
|
+
* Useful for ensuring functions receive non-empty input and for
|
|
4
|
+
* accumulating errors in Validation.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* const errors: NonEmptyList<string> = ["First error", "Second error"];
|
|
9
|
+
*
|
|
10
|
+
* // TypeScript ensures at least one element:
|
|
11
|
+
* const invalid: NonEmptyList<string> = []; // Error!
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
type NonEmptyList<A> = readonly [A, ...A[]];
|
|
15
|
+
/**
|
|
16
|
+
* Type guard that checks if an array is non-empty.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const items: string[] = getItems();
|
|
21
|
+
*
|
|
22
|
+
* if (isNonEmptyList(items)) {
|
|
23
|
+
* // TypeScript knows items has at least one element
|
|
24
|
+
* const first = items[0]; // string, not string | undefined
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
declare const isNonEmptyList: <A>(list: readonly A[]) => list is NonEmptyList<A>;
|
|
2
29
|
|
|
3
30
|
declare const _brand: unique symbol;
|
|
4
31
|
/**
|
|
@@ -51,4 +78,79 @@ declare namespace Brand {
|
|
|
51
78
|
const unwrap: <K extends string, T>(branded: Brand<K, T>) => T;
|
|
52
79
|
}
|
|
53
80
|
|
|
54
|
-
|
|
81
|
+
/**
|
|
82
|
+
* A branded nominal type representing a duration of time in milliseconds.
|
|
83
|
+
* Use Duration to ensure safe time-based operators and clear unit conversions.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* const halfSecond = Duration.milliseconds(500);
|
|
88
|
+
* const twoSeconds = Duration.seconds(2);
|
|
89
|
+
* const total = pipe(halfSecond, Duration.add(twoSeconds));
|
|
90
|
+
*
|
|
91
|
+
* Duration.toSeconds(total); // 2.5
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
type Duration = Brand<"Duration", number>;
|
|
95
|
+
declare namespace Duration {
|
|
96
|
+
/**
|
|
97
|
+
* Creates a Duration from milliseconds.
|
|
98
|
+
*/
|
|
99
|
+
const milliseconds: (ms: number) => Duration;
|
|
100
|
+
/**
|
|
101
|
+
* Creates a Duration from seconds.
|
|
102
|
+
*/
|
|
103
|
+
const seconds: (s: number) => Duration;
|
|
104
|
+
/**
|
|
105
|
+
* Creates a Duration from minutes.
|
|
106
|
+
*/
|
|
107
|
+
const minutes: (m: number) => Duration;
|
|
108
|
+
/**
|
|
109
|
+
* Creates a Duration from hours.
|
|
110
|
+
*/
|
|
111
|
+
const hours: (h: number) => Duration;
|
|
112
|
+
/**
|
|
113
|
+
* Creates a Duration from days.
|
|
114
|
+
*/
|
|
115
|
+
const days: (d: number) => Duration;
|
|
116
|
+
/**
|
|
117
|
+
* Converts a Duration back to raw milliseconds.
|
|
118
|
+
*/
|
|
119
|
+
const toMilliseconds: (d: Duration) => number;
|
|
120
|
+
/**
|
|
121
|
+
* Converts a Duration to seconds.
|
|
122
|
+
*/
|
|
123
|
+
const toSeconds: (d: Duration) => number;
|
|
124
|
+
/**
|
|
125
|
+
* Converts a Duration to minutes.
|
|
126
|
+
*/
|
|
127
|
+
const toMinutes: (d: Duration) => number;
|
|
128
|
+
/**
|
|
129
|
+
* Converts a Duration to hours.
|
|
130
|
+
*/
|
|
131
|
+
const toHours: (d: Duration) => number;
|
|
132
|
+
/**
|
|
133
|
+
* Converts a Duration to days.
|
|
134
|
+
*/
|
|
135
|
+
const toDays: (d: Duration) => number;
|
|
136
|
+
/**
|
|
137
|
+
* Adds two Durations together.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```ts
|
|
141
|
+
* pipe(Duration.seconds(1), Duration.add(Duration.milliseconds(500))); // 1500ms
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
const add: (other: Duration) => (self: Duration) => Duration;
|
|
145
|
+
/**
|
|
146
|
+
* Subtracts the other Duration from this one.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```ts
|
|
150
|
+
* pipe(Duration.seconds(1), Duration.subtract(Duration.milliseconds(500))); // 500ms
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
const subtract: (other: Duration) => (self: Duration) => Duration;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export { Brand, Duration, type NonEmptyList, isNonEmptyList };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* A list that is guaranteed to have at least one element.
|
|
3
|
+
* Useful for ensuring functions receive non-empty input and for
|
|
4
|
+
* accumulating errors in Validation.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* const errors: NonEmptyList<string> = ["First error", "Second error"];
|
|
9
|
+
*
|
|
10
|
+
* // TypeScript ensures at least one element:
|
|
11
|
+
* const invalid: NonEmptyList<string> = []; // Error!
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
type NonEmptyList<A> = readonly [A, ...A[]];
|
|
15
|
+
/**
|
|
16
|
+
* Type guard that checks if an array is non-empty.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const items: string[] = getItems();
|
|
21
|
+
*
|
|
22
|
+
* if (isNonEmptyList(items)) {
|
|
23
|
+
* // TypeScript knows items has at least one element
|
|
24
|
+
* const first = items[0]; // string, not string | undefined
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
declare const isNonEmptyList: <A>(list: readonly A[]) => list is NonEmptyList<A>;
|
|
2
29
|
|
|
3
30
|
declare const _brand: unique symbol;
|
|
4
31
|
/**
|
|
@@ -51,4 +78,79 @@ declare namespace Brand {
|
|
|
51
78
|
const unwrap: <K extends string, T>(branded: Brand<K, T>) => T;
|
|
52
79
|
}
|
|
53
80
|
|
|
54
|
-
|
|
81
|
+
/**
|
|
82
|
+
* A branded nominal type representing a duration of time in milliseconds.
|
|
83
|
+
* Use Duration to ensure safe time-based operators and clear unit conversions.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* const halfSecond = Duration.milliseconds(500);
|
|
88
|
+
* const twoSeconds = Duration.seconds(2);
|
|
89
|
+
* const total = pipe(halfSecond, Duration.add(twoSeconds));
|
|
90
|
+
*
|
|
91
|
+
* Duration.toSeconds(total); // 2.5
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
type Duration = Brand<"Duration", number>;
|
|
95
|
+
declare namespace Duration {
|
|
96
|
+
/**
|
|
97
|
+
* Creates a Duration from milliseconds.
|
|
98
|
+
*/
|
|
99
|
+
const milliseconds: (ms: number) => Duration;
|
|
100
|
+
/**
|
|
101
|
+
* Creates a Duration from seconds.
|
|
102
|
+
*/
|
|
103
|
+
const seconds: (s: number) => Duration;
|
|
104
|
+
/**
|
|
105
|
+
* Creates a Duration from minutes.
|
|
106
|
+
*/
|
|
107
|
+
const minutes: (m: number) => Duration;
|
|
108
|
+
/**
|
|
109
|
+
* Creates a Duration from hours.
|
|
110
|
+
*/
|
|
111
|
+
const hours: (h: number) => Duration;
|
|
112
|
+
/**
|
|
113
|
+
* Creates a Duration from days.
|
|
114
|
+
*/
|
|
115
|
+
const days: (d: number) => Duration;
|
|
116
|
+
/**
|
|
117
|
+
* Converts a Duration back to raw milliseconds.
|
|
118
|
+
*/
|
|
119
|
+
const toMilliseconds: (d: Duration) => number;
|
|
120
|
+
/**
|
|
121
|
+
* Converts a Duration to seconds.
|
|
122
|
+
*/
|
|
123
|
+
const toSeconds: (d: Duration) => number;
|
|
124
|
+
/**
|
|
125
|
+
* Converts a Duration to minutes.
|
|
126
|
+
*/
|
|
127
|
+
const toMinutes: (d: Duration) => number;
|
|
128
|
+
/**
|
|
129
|
+
* Converts a Duration to hours.
|
|
130
|
+
*/
|
|
131
|
+
const toHours: (d: Duration) => number;
|
|
132
|
+
/**
|
|
133
|
+
* Converts a Duration to days.
|
|
134
|
+
*/
|
|
135
|
+
const toDays: (d: Duration) => number;
|
|
136
|
+
/**
|
|
137
|
+
* Adds two Durations together.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```ts
|
|
141
|
+
* pipe(Duration.seconds(1), Duration.add(Duration.milliseconds(500))); // 1500ms
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
const add: (other: Duration) => (self: Duration) => Duration;
|
|
145
|
+
/**
|
|
146
|
+
* Subtracts the other Duration from this one.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```ts
|
|
150
|
+
* pipe(Duration.seconds(1), Duration.subtract(Duration.milliseconds(500))); // 500ms
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
const subtract: (other: Duration) => (self: Duration) => Duration;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export { Brand, Duration, type NonEmptyList, isNonEmptyList };
|
package/dist/types.js
CHANGED
|
@@ -21,6 +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,
|
|
24
25
|
isNonEmptyList: () => isNonEmptyList
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(Types_exports);
|
|
@@ -32,10 +33,29 @@ var Brand;
|
|
|
32
33
|
Brand2.unwrap = (branded) => branded;
|
|
33
34
|
})(Brand || (Brand = {}));
|
|
34
35
|
|
|
36
|
+
// src/Types/Duration.ts
|
|
37
|
+
var Duration;
|
|
38
|
+
((Duration2) => {
|
|
39
|
+
const wrap = Brand.wrap();
|
|
40
|
+
Duration2.milliseconds = (ms) => wrap(ms);
|
|
41
|
+
Duration2.seconds = (s) => wrap(s * 1e3);
|
|
42
|
+
Duration2.minutes = (m) => wrap(m * 60 * 1e3);
|
|
43
|
+
Duration2.hours = (h) => wrap(h * 60 * 60 * 1e3);
|
|
44
|
+
Duration2.days = (d) => wrap(d * 24 * 60 * 60 * 1e3);
|
|
45
|
+
Duration2.toMilliseconds = (d) => Brand.unwrap(d);
|
|
46
|
+
Duration2.toSeconds = (d) => Brand.unwrap(d) / 1e3;
|
|
47
|
+
Duration2.toMinutes = (d) => Brand.unwrap(d) / (60 * 1e3);
|
|
48
|
+
Duration2.toHours = (d) => Brand.unwrap(d) / (60 * 60 * 1e3);
|
|
49
|
+
Duration2.toDays = (d) => Brand.unwrap(d) / (24 * 60 * 60 * 1e3);
|
|
50
|
+
Duration2.add = (other) => (self) => wrap(Brand.unwrap(self) + Brand.unwrap(other));
|
|
51
|
+
Duration2.subtract = (other) => (self) => wrap(Brand.unwrap(self) - Brand.unwrap(other));
|
|
52
|
+
})(Duration || (Duration = {}));
|
|
53
|
+
|
|
35
54
|
// src/Types/NonEmptyList.ts
|
|
36
55
|
var isNonEmptyList = (list) => list.length > 0;
|
|
37
56
|
// Annotate the CommonJS export names for ESM import in node:
|
|
38
57
|
0 && (module.exports = {
|
|
39
58
|
Brand,
|
|
59
|
+
Duration,
|
|
40
60
|
isNonEmptyList
|
|
41
61
|
});
|
package/dist/types.mjs
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
Brand
|
|
3
|
-
} from "./chunk-BYWKZLHM.mjs";
|
|
1
|
+
import "./chunk-IPP4XFYH.mjs";
|
|
4
2
|
import {
|
|
5
3
|
isNonEmptyList
|
|
6
4
|
} from "./chunk-DBIC62UV.mjs";
|
|
5
|
+
import {
|
|
6
|
+
Brand,
|
|
7
|
+
Duration
|
|
8
|
+
} from "./chunk-VWVPHDZO.mjs";
|
|
7
9
|
export {
|
|
8
10
|
Brand,
|
|
11
|
+
Duration,
|
|
9
12
|
isNonEmptyList
|
|
10
13
|
};
|
package/dist/utils.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { M as Maybe,
|
|
2
|
-
import {
|
|
1
|
+
import { M as Maybe, R as Result, E as Equality, b as Ordering, T as Task } from './Task-5na0QzS4.mjs';
|
|
2
|
+
import { NonEmptyList } from './types.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Functional array utilities that compose well with pipe.
|
|
@@ -140,6 +140,38 @@ declare namespace Arr {
|
|
|
140
140
|
* ```
|
|
141
141
|
*/
|
|
142
142
|
const partition: <A>(predicate: (a: A) => boolean) => (data: readonly A[]) => readonly [readonly A[], readonly A[]];
|
|
143
|
+
/**
|
|
144
|
+
* Narrows a list of Maybe values down to a list of their underlying values,
|
|
145
|
+
* discarding all None instances.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```ts
|
|
149
|
+
* Arr.compact([Maybe.some(1), Maybe.none(), Maybe.some(3)]); // [1, 3]
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
const compact: <A>(data: readonly Maybe<A>[]) => readonly A[];
|
|
153
|
+
/**
|
|
154
|
+
* Separates an array of Result values into two separate lists of errors and successes.
|
|
155
|
+
* Returns a tuple containing `[errors, successes]`.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* Arr.separate([Result.ok(1), Result.error("bad"), Result.ok(3)]); // [["bad"], [1, 3]]
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
const separate: <E, A>(data: readonly Result<E, A>[]) => readonly [readonly E[], readonly A[]];
|
|
163
|
+
/**
|
|
164
|
+
* Maps each element to a Result, and separates the results into a tuple of failures and successes.
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```ts
|
|
168
|
+
* pipe(
|
|
169
|
+
* [1, 2, 3, 4],
|
|
170
|
+
* Arr.partitionMap(n => n % 2 === 0 ? Result.ok(n) : Result.error(`odd: ${n}`))
|
|
171
|
+
* ); // [["odd: 1", "odd: 3"], [2, 4]]
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
const partitionMap: <A, E, B>(f: (a: A) => Result<E, B>) => (data: readonly A[]) => readonly [readonly E[], readonly B[]];
|
|
143
175
|
/**
|
|
144
176
|
* Groups elements by a key function.
|
|
145
177
|
*
|
|
@@ -1390,6 +1422,16 @@ declare namespace Str {
|
|
|
1390
1422
|
*/
|
|
1391
1423
|
float: (s: string) => Maybe<number>;
|
|
1392
1424
|
};
|
|
1425
|
+
/**
|
|
1426
|
+
* Safely parses a JSON string, returning a `Result<SyntaxError, unknown>`.
|
|
1427
|
+
*
|
|
1428
|
+
* @example
|
|
1429
|
+
* ```ts
|
|
1430
|
+
* Str.parseJson('{"a": 1}'); // Ok({ a: 1 })
|
|
1431
|
+
* Str.parseJson('invalid'); // Error(SyntaxError)
|
|
1432
|
+
* ```
|
|
1433
|
+
*/
|
|
1434
|
+
const parseJson: (s: string) => Result<SyntaxError, unknown>;
|
|
1393
1435
|
}
|
|
1394
1436
|
|
|
1395
1437
|
/**
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { M as Maybe,
|
|
2
|
-
import {
|
|
1
|
+
import { M as Maybe, R as Result, E as Equality, b as Ordering, T as Task } from './Task-DeiWgoeJ.js';
|
|
2
|
+
import { NonEmptyList } from './types.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Functional array utilities that compose well with pipe.
|
|
@@ -140,6 +140,38 @@ declare namespace Arr {
|
|
|
140
140
|
* ```
|
|
141
141
|
*/
|
|
142
142
|
const partition: <A>(predicate: (a: A) => boolean) => (data: readonly A[]) => readonly [readonly A[], readonly A[]];
|
|
143
|
+
/**
|
|
144
|
+
* Narrows a list of Maybe values down to a list of their underlying values,
|
|
145
|
+
* discarding all None instances.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```ts
|
|
149
|
+
* Arr.compact([Maybe.some(1), Maybe.none(), Maybe.some(3)]); // [1, 3]
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
const compact: <A>(data: readonly Maybe<A>[]) => readonly A[];
|
|
153
|
+
/**
|
|
154
|
+
* Separates an array of Result values into two separate lists of errors and successes.
|
|
155
|
+
* Returns a tuple containing `[errors, successes]`.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* Arr.separate([Result.ok(1), Result.error("bad"), Result.ok(3)]); // [["bad"], [1, 3]]
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
const separate: <E, A>(data: readonly Result<E, A>[]) => readonly [readonly E[], readonly A[]];
|
|
163
|
+
/**
|
|
164
|
+
* Maps each element to a Result, and separates the results into a tuple of failures and successes.
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```ts
|
|
168
|
+
* pipe(
|
|
169
|
+
* [1, 2, 3, 4],
|
|
170
|
+
* Arr.partitionMap(n => n % 2 === 0 ? Result.ok(n) : Result.error(`odd: ${n}`))
|
|
171
|
+
* ); // [["odd: 1", "odd: 3"], [2, 4]]
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
const partitionMap: <A, E, B>(f: (a: A) => Result<E, B>) => (data: readonly A[]) => readonly [readonly E[], readonly B[]];
|
|
143
175
|
/**
|
|
144
176
|
* Groups elements by a key function.
|
|
145
177
|
*
|
|
@@ -1390,6 +1422,16 @@ declare namespace Str {
|
|
|
1390
1422
|
*/
|
|
1391
1423
|
float: (s: string) => Maybe<number>;
|
|
1392
1424
|
};
|
|
1425
|
+
/**
|
|
1426
|
+
* Safely parses a JSON string, returning a `Result<SyntaxError, unknown>`.
|
|
1427
|
+
*
|
|
1428
|
+
* @example
|
|
1429
|
+
* ```ts
|
|
1430
|
+
* Str.parseJson('{"a": 1}'); // Ok({ a: 1 })
|
|
1431
|
+
* Str.parseJson('invalid'); // Error(SyntaxError)
|
|
1432
|
+
* ```
|
|
1433
|
+
*/
|
|
1434
|
+
const parseJson: (s: string) => Result<SyntaxError, unknown>;
|
|
1393
1435
|
}
|
|
1394
1436
|
|
|
1395
1437
|
/**
|
package/dist/utils.js
CHANGED
|
@@ -68,6 +68,15 @@ var Result;
|
|
|
68
68
|
return data;
|
|
69
69
|
};
|
|
70
70
|
Result2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Result2.ok)(a) : (0, Result2.error)(onFalse(a));
|
|
71
|
+
Result2.fromNullable = (onNull) => (value) => value === null || value === void 0 ? (0, Result2.error)(onNull()) : (0, Result2.ok)(value);
|
|
72
|
+
Result2.fromMaybe = (onNone) => (maybe) => Maybe.isNone(maybe) ? (0, Result2.error)(onNone()) : (0, Result2.ok)(maybe.value);
|
|
73
|
+
Result2.fromThrowable = (f, onError) => (...args) => {
|
|
74
|
+
try {
|
|
75
|
+
return (0, Result2.ok)(f(...args));
|
|
76
|
+
} catch (e) {
|
|
77
|
+
return (0, Result2.error)(onError(e));
|
|
78
|
+
}
|
|
79
|
+
};
|
|
71
80
|
Result2.recover = (fallback) => (data) => (0, Result2.isOk)(data) ? data : fallback(data.error);
|
|
72
81
|
Result2.recoverUnless = (isBlocked, fallback) => (data) => (0, Result2.isError)(data) && !isBlocked(data.error) ? fallback() : data;
|
|
73
82
|
Result2.toMaybe = (data) => (0, Result2.isOk)(data) ? Maybe.some(data.value) : Maybe.none();
|
|
@@ -102,8 +111,34 @@ var Maybe;
|
|
|
102
111
|
Maybe2.ap = (arg) => (data) => (0, Maybe2.isSome)(data) && (0, Maybe2.isSome)(arg) ? (0, Maybe2.some)(data.value(arg.value)) : (0, Maybe2.none)();
|
|
103
112
|
})(Maybe || (Maybe = {}));
|
|
104
113
|
|
|
114
|
+
// src/Types/Brand.ts
|
|
115
|
+
var Brand;
|
|
116
|
+
((Brand2) => {
|
|
117
|
+
Brand2.wrap = () => (value) => value;
|
|
118
|
+
Brand2.unwrap = (branded) => branded;
|
|
119
|
+
})(Brand || (Brand = {}));
|
|
120
|
+
|
|
121
|
+
// src/Types/Duration.ts
|
|
122
|
+
var Duration;
|
|
123
|
+
((Duration2) => {
|
|
124
|
+
const wrap = Brand.wrap();
|
|
125
|
+
Duration2.milliseconds = (ms) => wrap(ms);
|
|
126
|
+
Duration2.seconds = (s) => wrap(s * 1e3);
|
|
127
|
+
Duration2.minutes = (m) => wrap(m * 60 * 1e3);
|
|
128
|
+
Duration2.hours = (h) => wrap(h * 60 * 60 * 1e3);
|
|
129
|
+
Duration2.days = (d) => wrap(d * 24 * 60 * 60 * 1e3);
|
|
130
|
+
Duration2.toMilliseconds = (d) => Brand.unwrap(d);
|
|
131
|
+
Duration2.toSeconds = (d) => Brand.unwrap(d) / 1e3;
|
|
132
|
+
Duration2.toMinutes = (d) => Brand.unwrap(d) / (60 * 1e3);
|
|
133
|
+
Duration2.toHours = (d) => Brand.unwrap(d) / (60 * 60 * 1e3);
|
|
134
|
+
Duration2.toDays = (d) => Brand.unwrap(d) / (24 * 60 * 60 * 1e3);
|
|
135
|
+
Duration2.add = (other) => (self) => wrap(Brand.unwrap(self) + Brand.unwrap(other));
|
|
136
|
+
Duration2.subtract = (other) => (self) => wrap(Brand.unwrap(self) - Brand.unwrap(other));
|
|
137
|
+
})(Duration || (Duration = {}));
|
|
138
|
+
|
|
105
139
|
// src/Core/Task.ts
|
|
106
140
|
var toPromise = (task, signal) => Deferred.toPromise(task(signal));
|
|
141
|
+
var getMs = (ms) => typeof ms === "number" ? ms : Duration.toMilliseconds(ms);
|
|
107
142
|
var Task;
|
|
108
143
|
((Task2) => {
|
|
109
144
|
Task2.resolve = (value) => () => Deferred.fromPromise(Promise.resolve(value));
|
|
@@ -144,7 +179,7 @@ var Task;
|
|
|
144
179
|
timerId = setTimeout(() => {
|
|
145
180
|
signal?.removeEventListener("abort", onAbort);
|
|
146
181
|
resolve2(toPromise(data, signal));
|
|
147
|
-
}, ms);
|
|
182
|
+
}, getMs(ms));
|
|
148
183
|
})
|
|
149
184
|
);
|
|
150
185
|
Task2.repeat = (options) => (task) => (0, Task2.from)((signal) => {
|
|
@@ -167,7 +202,7 @@ var Task;
|
|
|
167
202
|
timerId = setTimeout(() => {
|
|
168
203
|
signal?.removeEventListener("abort", onAbort);
|
|
169
204
|
r();
|
|
170
|
-
}, ms || 0);
|
|
205
|
+
}, getMs(ms || 0));
|
|
171
206
|
});
|
|
172
207
|
};
|
|
173
208
|
const run2 = (left) => {
|
|
@@ -200,7 +235,7 @@ var Task;
|
|
|
200
235
|
timerId = setTimeout(() => {
|
|
201
236
|
signal?.removeEventListener("abort", onAbort);
|
|
202
237
|
r();
|
|
203
|
-
}, ms || 0);
|
|
238
|
+
}, getMs(ms || 0));
|
|
204
239
|
});
|
|
205
240
|
};
|
|
206
241
|
const run2 = (attempt, lastValue) => {
|
|
@@ -216,7 +251,39 @@ var Task;
|
|
|
216
251
|
};
|
|
217
252
|
return run2(1);
|
|
218
253
|
});
|
|
219
|
-
Task2.race = (tasks) =>
|
|
254
|
+
Task2.race = (tasks) => {
|
|
255
|
+
if (tasks.length === 0) {
|
|
256
|
+
return () => Deferred.fromPromise(new Promise(() => {
|
|
257
|
+
}));
|
|
258
|
+
}
|
|
259
|
+
return (0, Task2.from)((outerSignal) => {
|
|
260
|
+
const controllers = tasks.map(() => new AbortController());
|
|
261
|
+
const onOuterAbort = () => {
|
|
262
|
+
for (const ctrl of controllers) ctrl.abort();
|
|
263
|
+
};
|
|
264
|
+
if (outerSignal) {
|
|
265
|
+
if (outerSignal.aborted) {
|
|
266
|
+
onOuterAbort();
|
|
267
|
+
} else {
|
|
268
|
+
outerSignal.addEventListener("abort", onOuterAbort, { once: true });
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
const promises = tasks.map((task, idx) => {
|
|
272
|
+
const ctrl = controllers[idx];
|
|
273
|
+
return toPromise(task, ctrl.signal).then((result) => {
|
|
274
|
+
for (let i = 0; i < controllers.length; i++) {
|
|
275
|
+
if (i !== idx) {
|
|
276
|
+
controllers[i].abort();
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
outerSignal?.removeEventListener("abort", onOuterAbort);
|
|
280
|
+
return result;
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
return Promise.race(promises);
|
|
284
|
+
});
|
|
285
|
+
};
|
|
286
|
+
Task2.sequence = (tasks) => (0, Task2.from)((signal) => Promise.all(tasks.map((t) => toPromise(t, signal))));
|
|
220
287
|
Task2.sequential = (tasks) => (0, Task2.from)(async (signal) => {
|
|
221
288
|
const results = [];
|
|
222
289
|
for (const task of tasks) {
|
|
@@ -257,7 +324,7 @@ var Task;
|
|
|
257
324
|
controller.abort();
|
|
258
325
|
cleanUp();
|
|
259
326
|
resolve2(Result.error(onTimeout()));
|
|
260
|
-
}, ms);
|
|
327
|
+
}, getMs(ms));
|
|
261
328
|
})
|
|
262
329
|
]);
|
|
263
330
|
});
|
|
@@ -342,6 +409,40 @@ var Arr;
|
|
|
342
409
|
}
|
|
343
410
|
return [pass, fail];
|
|
344
411
|
};
|
|
412
|
+
Arr2.compact = (data) => {
|
|
413
|
+
const result = [];
|
|
414
|
+
for (const item of data) {
|
|
415
|
+
if (item.kind === "Some") {
|
|
416
|
+
result.push(item.value);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
return result;
|
|
420
|
+
};
|
|
421
|
+
Arr2.separate = (data) => {
|
|
422
|
+
const errors = [];
|
|
423
|
+
const successes = [];
|
|
424
|
+
for (const item of data) {
|
|
425
|
+
if (item.kind === "Ok") {
|
|
426
|
+
successes.push(item.value);
|
|
427
|
+
} else {
|
|
428
|
+
errors.push(item.error);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
return [errors, successes];
|
|
432
|
+
};
|
|
433
|
+
Arr2.partitionMap = (f) => (data) => {
|
|
434
|
+
const errors = [];
|
|
435
|
+
const successes = [];
|
|
436
|
+
for (const item of data) {
|
|
437
|
+
const mapped = f(item);
|
|
438
|
+
if (mapped.kind === "Ok") {
|
|
439
|
+
successes.push(mapped.value);
|
|
440
|
+
} else {
|
|
441
|
+
errors.push(mapped.error);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
return [errors, successes];
|
|
445
|
+
};
|
|
345
446
|
Arr2.groupBy = (f) => (data) => {
|
|
346
447
|
const result = {};
|
|
347
448
|
for (const a of data) {
|
|
@@ -873,6 +974,13 @@ var Str;
|
|
|
873
974
|
return isNaN(n) ? Maybe.none() : Maybe.some(n);
|
|
874
975
|
}
|
|
875
976
|
};
|
|
977
|
+
Str2.parseJson = (s) => {
|
|
978
|
+
try {
|
|
979
|
+
return Result.ok(JSON.parse(s));
|
|
980
|
+
} catch (e) {
|
|
981
|
+
return Result.error(e);
|
|
982
|
+
}
|
|
983
|
+
};
|
|
876
984
|
})(Str || (Str = {}));
|
|
877
985
|
|
|
878
986
|
// src/Utils/Uniq.ts
|
package/dist/utils.mjs
CHANGED
|
@@ -5,9 +5,10 @@ import {
|
|
|
5
5
|
Rec,
|
|
6
6
|
Str,
|
|
7
7
|
Uniq
|
|
8
|
-
} from "./chunk-
|
|
9
|
-
import "./chunk-
|
|
8
|
+
} from "./chunk-W53ZYTLX.mjs";
|
|
9
|
+
import "./chunk-GSTKY7MF.mjs";
|
|
10
10
|
import "./chunk-DBIC62UV.mjs";
|
|
11
|
+
import "./chunk-VWVPHDZO.mjs";
|
|
11
12
|
export {
|
|
12
13
|
Arr,
|
|
13
14
|
Dict,
|
package/package.json
CHANGED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A list that is guaranteed to have at least one element.
|
|
3
|
-
* Useful for ensuring functions receive non-empty input and for
|
|
4
|
-
* accumulating errors in Validation.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```ts
|
|
8
|
-
* const errors: NonEmptyList<string> = ["First error", "Second error"];
|
|
9
|
-
*
|
|
10
|
-
* // TypeScript ensures at least one element:
|
|
11
|
-
* const invalid: NonEmptyList<string> = []; // Error!
|
|
12
|
-
* ```
|
|
13
|
-
*/
|
|
14
|
-
type NonEmptyList<A> = readonly [A, ...A[]];
|
|
15
|
-
/**
|
|
16
|
-
* Type guard that checks if an array is non-empty.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```ts
|
|
20
|
-
* const items: string[] = getItems();
|
|
21
|
-
*
|
|
22
|
-
* if (isNonEmptyList(items)) {
|
|
23
|
-
* // TypeScript knows items has at least one element
|
|
24
|
-
* const first = items[0]; // string, not string | undefined
|
|
25
|
-
* }
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
declare const isNonEmptyList: <A>(list: readonly A[]) => list is NonEmptyList<A>;
|
|
29
|
-
|
|
30
|
-
export { type NonEmptyList as N, isNonEmptyList as i };
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A list that is guaranteed to have at least one element.
|
|
3
|
-
* Useful for ensuring functions receive non-empty input and for
|
|
4
|
-
* accumulating errors in Validation.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```ts
|
|
8
|
-
* const errors: NonEmptyList<string> = ["First error", "Second error"];
|
|
9
|
-
*
|
|
10
|
-
* // TypeScript ensures at least one element:
|
|
11
|
-
* const invalid: NonEmptyList<string> = []; // Error!
|
|
12
|
-
* ```
|
|
13
|
-
*/
|
|
14
|
-
type NonEmptyList<A> = readonly [A, ...A[]];
|
|
15
|
-
/**
|
|
16
|
-
* Type guard that checks if an array is non-empty.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```ts
|
|
20
|
-
* const items: string[] = getItems();
|
|
21
|
-
*
|
|
22
|
-
* if (isNonEmptyList(items)) {
|
|
23
|
-
* // TypeScript knows items has at least one element
|
|
24
|
-
* const first = items[0]; // string, not string | undefined
|
|
25
|
-
* }
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
declare const isNonEmptyList: <A>(list: readonly A[]) => list is NonEmptyList<A>;
|
|
29
|
-
|
|
30
|
-
export { type NonEmptyList as N, isNonEmptyList as i };
|