@nlozgachev/pipelined 0.46.0 → 0.48.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
@@ -24,18 +24,22 @@ import {
24
24
  or,
25
25
  pipe,
26
26
  tap,
27
+ tuple,
27
28
  uncurry,
28
29
  uncurry3,
29
- uncurry4
30
- } from "./chunk-KOYYDQH4.mjs";
30
+ uncurry4,
31
+ untuple
32
+ } from "./chunk-5OFVS5UZ.mjs";
31
33
  import {
32
34
  Arr,
35
+ BigNum,
33
36
  Dict,
37
+ Json,
34
38
  Num,
35
39
  Rec,
36
40
  Str,
37
41
  Uniq
38
- } from "./chunk-W2L244AS.mjs";
42
+ } from "./chunk-UGVU2RTM.mjs";
39
43
  import {
40
44
  Combinable,
41
45
  Deferred,
@@ -61,19 +65,22 @@ import {
61
65
  These,
62
66
  Tuple,
63
67
  Validation
64
- } from "./chunk-VSU36S2K.mjs";
68
+ } from "./chunk-LR63GW6J.mjs";
65
69
  import {
66
70
  Brand,
67
- Duration
68
- } from "./chunk-XTVF5R6R.mjs";
71
+ Duration,
72
+ RetryPolicy
73
+ } from "./chunk-DENXUTKL.mjs";
69
74
  export {
70
75
  Arr,
76
+ BigNum,
71
77
  Brand,
72
78
  Combinable,
73
79
  Deferred,
74
80
  Dict,
75
81
  Duration,
76
82
  Equality,
83
+ Json,
77
84
  Lazy,
78
85
  Lens,
79
86
  Logged,
@@ -89,6 +96,7 @@ export {
89
96
  RemoteData,
90
97
  Resource,
91
98
  Result,
99
+ RetryPolicy,
92
100
  State,
93
101
  Str,
94
102
  Task,
@@ -124,7 +132,9 @@ export {
124
132
  or,
125
133
  pipe,
126
134
  tap,
135
+ tuple,
127
136
  uncurry,
128
137
  uncurry3,
129
- uncurry4
138
+ uncurry4,
139
+ untuple
130
140
  };
package/dist/types.d.mts CHANGED
@@ -1,129 +1,58 @@
1
- declare const _brand: unique symbol;
2
- /**
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.
5
- *
6
- * @example
7
- * ```ts
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>();
13
- *
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;
19
- * ```
20
- */
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
- }
1
+ import { D as Duration } from './Duration-B8joKzro.mjs';
2
+ export { B as Brand } from './Duration-B8joKzro.mjs';
51
3
 
52
4
  /**
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.
5
+ * An immutable policy describing retry limits and backoff delay strategies.
55
6
  *
56
7
  * @example
57
8
  * ```ts
58
- * const halfSecond = Duration.milliseconds(500);
59
- * const twoSeconds = Duration.seconds(2);
60
- * const total = pipe(halfSecond, Duration.add(twoSeconds));
61
- *
62
- * Duration.to.seconds(total); // 2.5
9
+ * const policy: RetryPolicy = RetryPolicy.constant({
10
+ * attempts: 3,
11
+ * delay: Duration.seconds(1),
12
+ * });
63
13
  * ```
64
14
  */
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
- namespace to {
88
- /**
89
- * Converts a Duration back to raw milliseconds.
90
- */
91
- const milliseconds: (d: Duration) => number;
92
- /**
93
- * Converts a Duration to seconds.
94
- */
95
- const seconds: (d: Duration) => number;
96
- /**
97
- * Converts a Duration to minutes.
98
- */
99
- const minutes: (d: Duration) => number;
100
- /**
101
- * Converts a Duration to hours.
102
- */
103
- const hours: (d: Duration) => number;
104
- /**
105
- * Converts a Duration to days.
106
- */
107
- const days: (d: Duration) => number;
108
- }
15
+ type RetryPolicy = {
16
+ readonly attempts: number;
17
+ readonly getDelay: (attempt: number) => Duration;
18
+ };
19
+ declare namespace RetryPolicy {
109
20
  /**
110
- * Adds two Durations together.
21
+ * Creates a RetryPolicy with a constant delay between retry attempts.
111
22
  *
112
23
  * @example
113
24
  * ```ts
114
- * pipe(Duration.seconds(1), Duration.add(Duration.milliseconds(500))); // 1500ms
25
+ * const policy = RetryPolicy.constant({
26
+ * attempts: 3,
27
+ * delay: Duration.seconds(1),
28
+ * });
115
29
  * ```
116
30
  */
117
- const add: (other: Duration) => (self: Duration) => Duration;
31
+ const constant: (options: {
32
+ attempts: number;
33
+ delay: Duration;
34
+ }) => RetryPolicy;
118
35
  /**
119
- * Subtracts the other Duration from this one.
36
+ * Creates a RetryPolicy with exponential backoff delays between attempts.
37
+ * An optional `factor` (default 2) controls the growth rate.
38
+ * An optional `jitter` (default false) adds randomized variance to prevent thundering herd problems.
120
39
  *
121
40
  * @example
122
41
  * ```ts
123
- * pipe(Duration.seconds(1), Duration.subtract(Duration.milliseconds(500))); // 500ms
42
+ * const policy = RetryPolicy.exponential({
43
+ * attempts: 5,
44
+ * initial: Duration.milliseconds(100),
45
+ * factor: 2,
46
+ * jitter: true,
47
+ * });
124
48
  * ```
125
49
  */
126
- const subtract: (other: Duration) => (self: Duration) => Duration;
50
+ const exponential: (options: {
51
+ attempts: number;
52
+ initial: Duration;
53
+ factor?: number;
54
+ jitter?: boolean;
55
+ }) => RetryPolicy;
127
56
  }
128
57
 
129
- export { Brand, Duration };
58
+ export { Duration, RetryPolicy };
package/dist/types.d.ts CHANGED
@@ -1,129 +1,58 @@
1
- declare const _brand: unique symbol;
2
- /**
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.
5
- *
6
- * @example
7
- * ```ts
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>();
13
- *
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;
19
- * ```
20
- */
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
- }
1
+ import { D as Duration } from './Duration-B8joKzro.js';
2
+ export { B as Brand } from './Duration-B8joKzro.js';
51
3
 
52
4
  /**
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.
5
+ * An immutable policy describing retry limits and backoff delay strategies.
55
6
  *
56
7
  * @example
57
8
  * ```ts
58
- * const halfSecond = Duration.milliseconds(500);
59
- * const twoSeconds = Duration.seconds(2);
60
- * const total = pipe(halfSecond, Duration.add(twoSeconds));
61
- *
62
- * Duration.to.seconds(total); // 2.5
9
+ * const policy: RetryPolicy = RetryPolicy.constant({
10
+ * attempts: 3,
11
+ * delay: Duration.seconds(1),
12
+ * });
63
13
  * ```
64
14
  */
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
- namespace to {
88
- /**
89
- * Converts a Duration back to raw milliseconds.
90
- */
91
- const milliseconds: (d: Duration) => number;
92
- /**
93
- * Converts a Duration to seconds.
94
- */
95
- const seconds: (d: Duration) => number;
96
- /**
97
- * Converts a Duration to minutes.
98
- */
99
- const minutes: (d: Duration) => number;
100
- /**
101
- * Converts a Duration to hours.
102
- */
103
- const hours: (d: Duration) => number;
104
- /**
105
- * Converts a Duration to days.
106
- */
107
- const days: (d: Duration) => number;
108
- }
15
+ type RetryPolicy = {
16
+ readonly attempts: number;
17
+ readonly getDelay: (attempt: number) => Duration;
18
+ };
19
+ declare namespace RetryPolicy {
109
20
  /**
110
- * Adds two Durations together.
21
+ * Creates a RetryPolicy with a constant delay between retry attempts.
111
22
  *
112
23
  * @example
113
24
  * ```ts
114
- * pipe(Duration.seconds(1), Duration.add(Duration.milliseconds(500))); // 1500ms
25
+ * const policy = RetryPolicy.constant({
26
+ * attempts: 3,
27
+ * delay: Duration.seconds(1),
28
+ * });
115
29
  * ```
116
30
  */
117
- const add: (other: Duration) => (self: Duration) => Duration;
31
+ const constant: (options: {
32
+ attempts: number;
33
+ delay: Duration;
34
+ }) => RetryPolicy;
118
35
  /**
119
- * Subtracts the other Duration from this one.
36
+ * Creates a RetryPolicy with exponential backoff delays between attempts.
37
+ * An optional `factor` (default 2) controls the growth rate.
38
+ * An optional `jitter` (default false) adds randomized variance to prevent thundering herd problems.
120
39
  *
121
40
  * @example
122
41
  * ```ts
123
- * pipe(Duration.seconds(1), Duration.subtract(Duration.milliseconds(500))); // 500ms
42
+ * const policy = RetryPolicy.exponential({
43
+ * attempts: 5,
44
+ * initial: Duration.milliseconds(100),
45
+ * factor: 2,
46
+ * jitter: true,
47
+ * });
124
48
  * ```
125
49
  */
126
- const subtract: (other: Duration) => (self: Duration) => Duration;
50
+ const exponential: (options: {
51
+ attempts: number;
52
+ initial: Duration;
53
+ factor?: number;
54
+ jitter?: boolean;
55
+ }) => RetryPolicy;
127
56
  }
128
57
 
129
- export { Brand, Duration };
58
+ export { Duration, RetryPolicy };
package/dist/types.js CHANGED
@@ -21,7 +21,8 @@ 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
+ Duration: () => Duration,
25
+ RetryPolicy: () => RetryPolicy
25
26
  });
26
27
  module.exports = __toCommonJS(Types_exports);
27
28
 
@@ -52,8 +53,32 @@ var Duration;
52
53
  Duration2.add = (other) => (self) => wrap(Brand.unwrap(self) + Brand.unwrap(other));
53
54
  Duration2.subtract = (other) => (self) => wrap(Brand.unwrap(self) - Brand.unwrap(other));
54
55
  })(Duration || (Duration = {}));
56
+
57
+ // src/Types/RetryPolicy.ts
58
+ var RetryPolicy;
59
+ ((RetryPolicy2) => {
60
+ RetryPolicy2.constant = (options) => ({
61
+ attempts: Math.max(1, options.attempts),
62
+ getDelay: () => options.delay
63
+ });
64
+ RetryPolicy2.exponential = (options) => {
65
+ const attempts = Math.max(1, options.attempts);
66
+ const initialMs = Duration.to.milliseconds(options.initial);
67
+ const factor = options.factor ?? 2;
68
+ const jitter = options.jitter ?? false;
69
+ return {
70
+ attempts,
71
+ getDelay: (attempt) => {
72
+ const rawMs = initialMs * factor ** Math.max(0, attempt - 1);
73
+ const finalMs = jitter ? Math.random() * rawMs : rawMs;
74
+ return Duration.milliseconds(finalMs);
75
+ }
76
+ };
77
+ };
78
+ })(RetryPolicy || (RetryPolicy = {}));
55
79
  // Annotate the CommonJS export names for ESM import in node:
56
80
  0 && (module.exports = {
57
81
  Brand,
58
- Duration
82
+ Duration,
83
+ RetryPolicy
59
84
  });
package/dist/types.mjs CHANGED
@@ -1,8 +1,10 @@
1
1
  import {
2
2
  Brand,
3
- Duration
4
- } from "./chunk-XTVF5R6R.mjs";
3
+ Duration,
4
+ RetryPolicy
5
+ } from "./chunk-DENXUTKL.mjs";
5
6
  export {
6
7
  Brand,
7
- Duration
8
+ Duration,
9
+ RetryPolicy
8
10
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nlozgachev/pipelined",
3
- "version": "0.46.0",
3
+ "version": "0.48.0",
4
4
  "description": "Opinionated functional abstractions for TypeScript",
5
5
  "license": "BSD-3-Clause",
6
6
  "homepage": "https://pipelined.lozgachev.dev",
@@ -41,10 +41,10 @@
41
41
  "import": "./dist/core.mjs",
42
42
  "require": "./dist/core.cjs"
43
43
  },
44
- "./utils": {
45
- "types": "./dist/utils.d.ts",
46
- "import": "./dist/utils.mjs",
47
- "require": "./dist/utils.cjs"
44
+ "./data": {
45
+ "types": "./dist/data.d.ts",
46
+ "import": "./dist/data.mjs",
47
+ "require": "./dist/data.cjs"
48
48
  },
49
49
  "./types": {
50
50
  "types": "./dist/types.d.ts",
@@ -84,7 +84,7 @@
84
84
  { "path": "dist/index.js", "limit": "25 KB", "gzip": true },
85
85
  { "path": "dist/core.js", "limit": "15 KB", "gzip": true },
86
86
  { "path": "dist/composition.js", "limit": "4 KB", "gzip": true },
87
- { "path": "dist/utils.js", "limit": "12 KB", "gzip": true },
87
+ { "path": "dist/data.js", "limit": "12 KB", "gzip": true },
88
88
  { "path": "dist/types.js", "limit": "1 KB", "gzip": true }
89
89
  ],
90
90
  "packageManager": "pnpm@11.6.0+sha512.9a36518224080c6fe5165afdcfe79bfa118c29be703f3f462b1e32efe1e98e47e8750b148e08286250aad4113cc7993ca413c4e2cd447752708c2ee5751bc95f"
package/dist/utils.mjs DELETED
@@ -1,18 +0,0 @@
1
- import {
2
- Arr,
3
- Dict,
4
- Num,
5
- Rec,
6
- Str,
7
- Uniq
8
- } from "./chunk-W2L244AS.mjs";
9
- import "./chunk-VSU36S2K.mjs";
10
- import "./chunk-XTVF5R6R.mjs";
11
- export {
12
- Arr,
13
- Dict,
14
- Num,
15
- Rec,
16
- Str,
17
- Uniq
18
- };