@nlozgachev/pipelined 0.62.0 → 0.63.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/types.cjs CHANGED
@@ -27,41 +27,185 @@ __export(Types_exports, {
27
27
  module.exports = __toCommonJS(Types_exports);
28
28
 
29
29
  // src/Types/Brand.ts
30
- var Brand;
31
- ((Brand2) => {
32
- Brand2.wrap = () => (value) => value;
33
- Brand2.unwrap = (branded) => branded;
34
- })(Brand || (Brand = {}));
30
+ var Brand = {
31
+ /**
32
+ * Returns a constructor that wraps a value of type T in brand K.
33
+ * The resulting function performs an unchecked cast — only use when the raw
34
+ * value is known to satisfy the brand's invariants.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * type PositiveNumber = Brand<"PositiveNumber", number>;
39
+ * const toPositiveNumber = Brand.wrap<"PositiveNumber", number>();
40
+ *
41
+ * const n: PositiveNumber = toPositiveNumber(42);
42
+ * ```
43
+ */
44
+ wrap: () => (value) => value,
45
+ /**
46
+ * Strips the brand and returns the underlying value.
47
+ * Since Brand<K, T> extends T this is rarely needed, but can improve readability.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * type UserId = Brand<"UserId", string>;
52
+ * const toUserId = Brand.wrap<"UserId", string>();
53
+ * const userId: UserId = toUserId("user-123");
54
+ * const raw: string = Brand.unwrap(userId); // "user-123"
55
+ * ```
56
+ */
57
+ unwrap: (branded) => branded
58
+ };
35
59
 
36
60
  // 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
- let to;
46
- ((to2) => {
47
- to2.milliseconds = (d) => Brand.unwrap(d);
48
- to2.seconds = (d) => Brand.unwrap(d) / 1e3;
49
- to2.minutes = (d) => Brand.unwrap(d) / (60 * 1e3);
50
- to2.hours = (d) => Brand.unwrap(d) / (60 * 60 * 1e3);
51
- to2.days = (d) => Brand.unwrap(d) / (24 * 60 * 60 * 1e3);
52
- })(to = Duration2.to || (Duration2.to = {}));
53
- Duration2.add = (other) => (self) => wrap(Brand.unwrap(self) + Brand.unwrap(other));
54
- Duration2.subtract = (other) => (self) => wrap(Brand.unwrap(self) - Brand.unwrap(other));
55
- })(Duration || (Duration = {}));
61
+ var wrap = Brand.wrap();
62
+ var Duration = {
63
+ /**
64
+ * Creates a Duration from milliseconds.
65
+ *
66
+ * @example
67
+ * ```ts
68
+ * Duration.milliseconds(500); // 500ms Duration
69
+ * ```
70
+ */
71
+ milliseconds: (ms) => wrap(ms),
72
+ /**
73
+ * Creates a Duration from seconds.
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * Duration.seconds(2); // 2000ms Duration
78
+ * ```
79
+ */
80
+ seconds: (s) => wrap(s * 1e3),
81
+ /**
82
+ * Creates a Duration from minutes.
83
+ *
84
+ * @example
85
+ * ```ts
86
+ * Duration.minutes(5); // 300000ms Duration
87
+ * ```
88
+ */
89
+ minutes: (m) => wrap(m * 60 * 1e3),
90
+ /**
91
+ * Creates a Duration from hours.
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * Duration.hours(1); // 3600000ms Duration
96
+ * ```
97
+ */
98
+ hours: (h) => wrap(h * 60 * 60 * 1e3),
99
+ /**
100
+ * Creates a Duration from days.
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * Duration.days(1); // 86400000ms Duration
105
+ * ```
106
+ */
107
+ days: (d) => wrap(d * 24 * 60 * 60 * 1e3),
108
+ // --- to ---
109
+ to: {
110
+ /**
111
+ * Converts a Duration back to raw milliseconds.
112
+ *
113
+ * @example
114
+ * ```ts
115
+ * Duration.to.milliseconds(Duration.seconds(2)); // 2000
116
+ * ```
117
+ */
118
+ milliseconds: (d) => Brand.unwrap(d),
119
+ /**
120
+ * Converts a Duration to seconds.
121
+ *
122
+ * @example
123
+ * ```ts
124
+ * Duration.to.seconds(Duration.milliseconds(2500)); // 2.5
125
+ * ```
126
+ */
127
+ seconds: (d) => Brand.unwrap(d) / 1e3,
128
+ /**
129
+ * Converts a Duration to minutes.
130
+ *
131
+ * @example
132
+ * ```ts
133
+ * Duration.to.minutes(Duration.seconds(120)); // 2
134
+ * ```
135
+ */
136
+ minutes: (d) => Brand.unwrap(d) / (60 * 1e3),
137
+ /**
138
+ * Converts a Duration to hours.
139
+ *
140
+ * @example
141
+ * ```ts
142
+ * Duration.to.hours(Duration.minutes(90)); // 1.5
143
+ * ```
144
+ */
145
+ hours: (d) => Brand.unwrap(d) / (60 * 60 * 1e3),
146
+ /**
147
+ * Converts a Duration to days.
148
+ *
149
+ * @example
150
+ * ```ts
151
+ * Duration.to.days(Duration.hours(36)); // 1.5
152
+ * ```
153
+ */
154
+ days: (d) => Brand.unwrap(d) / (24 * 60 * 60 * 1e3)
155
+ },
156
+ /**
157
+ * Adds two Durations together.
158
+ *
159
+ * @example
160
+ * ```ts
161
+ * pipe(Duration.seconds(1), Duration.add(Duration.milliseconds(500))); // 1500ms
162
+ * ```
163
+ */
164
+ add: (other) => (self) => wrap(Brand.unwrap(self) + Brand.unwrap(other)),
165
+ /**
166
+ * Subtracts the other Duration from this one.
167
+ *
168
+ * @example
169
+ * ```ts
170
+ * pipe(Duration.seconds(1), Duration.subtract(Duration.milliseconds(500))); // 500ms
171
+ * ```
172
+ */
173
+ subtract: (other) => (self) => wrap(Brand.unwrap(self) - Brand.unwrap(other))
174
+ };
56
175
 
57
176
  // src/Types/RetryPolicy.ts
58
- var RetryPolicy;
59
- ((RetryPolicy2) => {
60
- RetryPolicy2.constant = (options) => ({
177
+ var RetryPolicy = {
178
+ /**
179
+ * Creates a RetryPolicy with a constant delay between retry attempts.
180
+ *
181
+ * @example
182
+ * ```ts
183
+ * const policy = RetryPolicy.constant({
184
+ * attempts: 3,
185
+ * delay: Duration.seconds(1),
186
+ * });
187
+ * ```
188
+ */
189
+ constant: (options) => ({
61
190
  attempts: Math.max(1, options.attempts),
62
191
  getDelay: () => options.delay
63
- });
64
- RetryPolicy2.exponential = (options) => {
192
+ }),
193
+ /**
194
+ * Creates a RetryPolicy with exponential backoff delays between attempts.
195
+ * An optional `factor` (default 2) controls the growth rate.
196
+ * An optional `jitter` (default false) adds randomized variance to prevent thundering herd problems.
197
+ *
198
+ * @example
199
+ * ```ts
200
+ * const policy = RetryPolicy.exponential({
201
+ * attempts: 5,
202
+ * initial: Duration.milliseconds(100),
203
+ * factor: 2,
204
+ * jitter: true,
205
+ * });
206
+ * ```
207
+ */
208
+ exponential: (options) => {
65
209
  const attempts = Math.max(1, options.attempts);
66
210
  const initialMs = Duration.to.milliseconds(options.initial);
67
211
  const factor = options.factor ?? 2;
@@ -74,8 +218,8 @@ var RetryPolicy;
74
218
  return Duration.milliseconds(finalMs);
75
219
  }
76
220
  };
77
- };
78
- })(RetryPolicy || (RetryPolicy = {}));
221
+ }
222
+ };
79
223
  // Annotate the CommonJS export names for ESM import in node:
80
224
  0 && (module.exports = {
81
225
  Brand,
package/dist/types.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { D as Duration } from './Duration-B8joKzro.cjs';
2
- export { B as Brand } from './Duration-B8joKzro.cjs';
1
+ import { D as Duration } from './Duration-DeyxG6VQ.cjs';
2
+ export { B as Brand } from './Duration-DeyxG6VQ.cjs';
3
3
 
4
4
  /**
5
5
  * An immutable policy describing retry limits and backoff delay strategies.
@@ -16,7 +16,7 @@ type RetryPolicy = {
16
16
  readonly attempts: number;
17
17
  readonly getDelay: (attempt: number) => Duration;
18
18
  };
19
- declare namespace RetryPolicy {
19
+ declare const RetryPolicy: {
20
20
  /**
21
21
  * Creates a RetryPolicy with a constant delay between retry attempts.
22
22
  *
@@ -28,7 +28,7 @@ declare namespace RetryPolicy {
28
28
  * });
29
29
  * ```
30
30
  */
31
- const constant: (options: {
31
+ constant: (options: {
32
32
  attempts: number;
33
33
  delay: Duration;
34
34
  }) => RetryPolicy;
@@ -47,12 +47,12 @@ declare namespace RetryPolicy {
47
47
  * });
48
48
  * ```
49
49
  */
50
- const exponential: (options: {
50
+ exponential: (options: {
51
51
  attempts: number;
52
52
  initial: Duration;
53
53
  factor?: number;
54
54
  jitter?: boolean;
55
55
  }) => RetryPolicy;
56
- }
56
+ };
57
57
 
58
58
  export { Duration, RetryPolicy };
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { D as Duration } from './Duration-B8joKzro.js';
2
- export { B as Brand } from './Duration-B8joKzro.js';
1
+ import { D as Duration } from './Duration-DeyxG6VQ.js';
2
+ export { B as Brand } from './Duration-DeyxG6VQ.js';
3
3
 
4
4
  /**
5
5
  * An immutable policy describing retry limits and backoff delay strategies.
@@ -16,7 +16,7 @@ type RetryPolicy = {
16
16
  readonly attempts: number;
17
17
  readonly getDelay: (attempt: number) => Duration;
18
18
  };
19
- declare namespace RetryPolicy {
19
+ declare const RetryPolicy: {
20
20
  /**
21
21
  * Creates a RetryPolicy with a constant delay between retry attempts.
22
22
  *
@@ -28,7 +28,7 @@ declare namespace RetryPolicy {
28
28
  * });
29
29
  * ```
30
30
  */
31
- const constant: (options: {
31
+ constant: (options: {
32
32
  attempts: number;
33
33
  delay: Duration;
34
34
  }) => RetryPolicy;
@@ -47,12 +47,12 @@ declare namespace RetryPolicy {
47
47
  * });
48
48
  * ```
49
49
  */
50
- const exponential: (options: {
50
+ exponential: (options: {
51
51
  attempts: number;
52
52
  initial: Duration;
53
53
  factor?: number;
54
54
  jitter?: boolean;
55
55
  }) => RetryPolicy;
56
- }
56
+ };
57
57
 
58
58
  export { Duration, RetryPolicy };
package/dist/types.mjs CHANGED
@@ -1,39 +1,183 @@
1
1
  // src/Types/Brand.ts
2
- var Brand;
3
- ((Brand2) => {
4
- Brand2.wrap = () => (value) => value;
5
- Brand2.unwrap = (branded) => branded;
6
- })(Brand || (Brand = {}));
2
+ var Brand = {
3
+ /**
4
+ * Returns a constructor that wraps a value of type T in brand K.
5
+ * The resulting function performs an unchecked cast — only use when the raw
6
+ * value is known to satisfy the brand's invariants.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * type PositiveNumber = Brand<"PositiveNumber", number>;
11
+ * const toPositiveNumber = Brand.wrap<"PositiveNumber", number>();
12
+ *
13
+ * const n: PositiveNumber = toPositiveNumber(42);
14
+ * ```
15
+ */
16
+ wrap: () => (value) => value,
17
+ /**
18
+ * Strips the brand and returns the underlying value.
19
+ * Since Brand<K, T> extends T this is rarely needed, but can improve readability.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * type UserId = Brand<"UserId", string>;
24
+ * const toUserId = Brand.wrap<"UserId", string>();
25
+ * const userId: UserId = toUserId("user-123");
26
+ * const raw: string = Brand.unwrap(userId); // "user-123"
27
+ * ```
28
+ */
29
+ unwrap: (branded) => branded
30
+ };
7
31
 
8
32
  // src/Types/Duration.ts
9
- var Duration;
10
- ((Duration2) => {
11
- const wrap = Brand.wrap();
12
- Duration2.milliseconds = (ms) => wrap(ms);
13
- Duration2.seconds = (s) => wrap(s * 1e3);
14
- Duration2.minutes = (m) => wrap(m * 60 * 1e3);
15
- Duration2.hours = (h) => wrap(h * 60 * 60 * 1e3);
16
- Duration2.days = (d) => wrap(d * 24 * 60 * 60 * 1e3);
17
- let to;
18
- ((to2) => {
19
- to2.milliseconds = (d) => Brand.unwrap(d);
20
- to2.seconds = (d) => Brand.unwrap(d) / 1e3;
21
- to2.minutes = (d) => Brand.unwrap(d) / (60 * 1e3);
22
- to2.hours = (d) => Brand.unwrap(d) / (60 * 60 * 1e3);
23
- to2.days = (d) => Brand.unwrap(d) / (24 * 60 * 60 * 1e3);
24
- })(to = Duration2.to || (Duration2.to = {}));
25
- Duration2.add = (other) => (self) => wrap(Brand.unwrap(self) + Brand.unwrap(other));
26
- Duration2.subtract = (other) => (self) => wrap(Brand.unwrap(self) - Brand.unwrap(other));
27
- })(Duration || (Duration = {}));
33
+ var wrap = Brand.wrap();
34
+ var Duration = {
35
+ /**
36
+ * Creates a Duration from milliseconds.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * Duration.milliseconds(500); // 500ms Duration
41
+ * ```
42
+ */
43
+ milliseconds: (ms) => wrap(ms),
44
+ /**
45
+ * Creates a Duration from seconds.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * Duration.seconds(2); // 2000ms Duration
50
+ * ```
51
+ */
52
+ seconds: (s) => wrap(s * 1e3),
53
+ /**
54
+ * Creates a Duration from minutes.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * Duration.minutes(5); // 300000ms Duration
59
+ * ```
60
+ */
61
+ minutes: (m) => wrap(m * 60 * 1e3),
62
+ /**
63
+ * Creates a Duration from hours.
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * Duration.hours(1); // 3600000ms Duration
68
+ * ```
69
+ */
70
+ hours: (h) => wrap(h * 60 * 60 * 1e3),
71
+ /**
72
+ * Creates a Duration from days.
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * Duration.days(1); // 86400000ms Duration
77
+ * ```
78
+ */
79
+ days: (d) => wrap(d * 24 * 60 * 60 * 1e3),
80
+ // --- to ---
81
+ to: {
82
+ /**
83
+ * Converts a Duration back to raw milliseconds.
84
+ *
85
+ * @example
86
+ * ```ts
87
+ * Duration.to.milliseconds(Duration.seconds(2)); // 2000
88
+ * ```
89
+ */
90
+ milliseconds: (d) => Brand.unwrap(d),
91
+ /**
92
+ * Converts a Duration to seconds.
93
+ *
94
+ * @example
95
+ * ```ts
96
+ * Duration.to.seconds(Duration.milliseconds(2500)); // 2.5
97
+ * ```
98
+ */
99
+ seconds: (d) => Brand.unwrap(d) / 1e3,
100
+ /**
101
+ * Converts a Duration to minutes.
102
+ *
103
+ * @example
104
+ * ```ts
105
+ * Duration.to.minutes(Duration.seconds(120)); // 2
106
+ * ```
107
+ */
108
+ minutes: (d) => Brand.unwrap(d) / (60 * 1e3),
109
+ /**
110
+ * Converts a Duration to hours.
111
+ *
112
+ * @example
113
+ * ```ts
114
+ * Duration.to.hours(Duration.minutes(90)); // 1.5
115
+ * ```
116
+ */
117
+ hours: (d) => Brand.unwrap(d) / (60 * 60 * 1e3),
118
+ /**
119
+ * Converts a Duration to days.
120
+ *
121
+ * @example
122
+ * ```ts
123
+ * Duration.to.days(Duration.hours(36)); // 1.5
124
+ * ```
125
+ */
126
+ days: (d) => Brand.unwrap(d) / (24 * 60 * 60 * 1e3)
127
+ },
128
+ /**
129
+ * Adds two Durations together.
130
+ *
131
+ * @example
132
+ * ```ts
133
+ * pipe(Duration.seconds(1), Duration.add(Duration.milliseconds(500))); // 1500ms
134
+ * ```
135
+ */
136
+ add: (other) => (self) => wrap(Brand.unwrap(self) + Brand.unwrap(other)),
137
+ /**
138
+ * Subtracts the other Duration from this one.
139
+ *
140
+ * @example
141
+ * ```ts
142
+ * pipe(Duration.seconds(1), Duration.subtract(Duration.milliseconds(500))); // 500ms
143
+ * ```
144
+ */
145
+ subtract: (other) => (self) => wrap(Brand.unwrap(self) - Brand.unwrap(other))
146
+ };
28
147
 
29
148
  // src/Types/RetryPolicy.ts
30
- var RetryPolicy;
31
- ((RetryPolicy2) => {
32
- RetryPolicy2.constant = (options) => ({
149
+ var RetryPolicy = {
150
+ /**
151
+ * Creates a RetryPolicy with a constant delay between retry attempts.
152
+ *
153
+ * @example
154
+ * ```ts
155
+ * const policy = RetryPolicy.constant({
156
+ * attempts: 3,
157
+ * delay: Duration.seconds(1),
158
+ * });
159
+ * ```
160
+ */
161
+ constant: (options) => ({
33
162
  attempts: Math.max(1, options.attempts),
34
163
  getDelay: () => options.delay
35
- });
36
- RetryPolicy2.exponential = (options) => {
164
+ }),
165
+ /**
166
+ * Creates a RetryPolicy with exponential backoff delays between attempts.
167
+ * An optional `factor` (default 2) controls the growth rate.
168
+ * An optional `jitter` (default false) adds randomized variance to prevent thundering herd problems.
169
+ *
170
+ * @example
171
+ * ```ts
172
+ * const policy = RetryPolicy.exponential({
173
+ * attempts: 5,
174
+ * initial: Duration.milliseconds(100),
175
+ * factor: 2,
176
+ * jitter: true,
177
+ * });
178
+ * ```
179
+ */
180
+ exponential: (options) => {
37
181
  const attempts = Math.max(1, options.attempts);
38
182
  const initialMs = Duration.to.milliseconds(options.initial);
39
183
  const factor = options.factor ?? 2;
@@ -46,8 +190,8 @@ var RetryPolicy;
46
190
  return Duration.milliseconds(finalMs);
47
191
  }
48
192
  };
49
- };
50
- })(RetryPolicy || (RetryPolicy = {}));
193
+ }
194
+ };
51
195
  export {
52
196
  Brand,
53
197
  Duration,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nlozgachev/pipelined",
3
- "version": "0.62.0",
3
+ "version": "0.63.0",
4
4
  "description": "Opinionated functional abstractions for TypeScript",
5
5
  "license": "BSD-3-Clause",
6
6
  "homepage": "https://pipelined.lozgachev.dev",
@@ -84,17 +84,16 @@
84
84
  "lint": "oxlint src/",
85
85
  "format": "dprint fmt && dprint fmt --config dprint.md.json \"docs/**/*.md\" \"docs/**/*.mdx\" \"README.md\"",
86
86
  "format:check": "dprint check && dprint check --config dprint.md.json \"docs/**/*.md\" \"docs/**/*.mdx\" \"README.md\"",
87
- "release:patch": "bumpp --patch -c -t -p",
88
- "release:minor": "bumpp --minor -c -t -p",
89
87
  "docs:dev": "pnpm --filter pipelined-docs dev",
90
88
  "docs:build": "pnpm --filter pipelined-docs build"
91
89
  },
92
90
  "devDependencies": {
91
+ "@size-limit/esbuild": "13.0.3",
93
92
  "@size-limit/file": "13.0.3",
94
93
  "@types/node": "26.2.0",
95
94
  "@vitest/coverage-v8": "4.1.10",
96
- "bumpp": "12.2.0",
97
95
  "dprint": "0.55.2",
96
+ "esbuild": "0.28.2",
98
97
  "fast-check": "4.9.0",
99
98
  "oxlint": "1.78.0",
100
99
  "size-limit": "13.0.3",
@@ -104,28 +103,40 @@
104
103
  },
105
104
  "size-limit": [
106
105
  {
106
+ "name": "Index (Monolithic import *)",
107
+ "import": "*",
107
108
  "path": "dist/index.mjs",
108
- "limit": "25 KB",
109
- "gzip": true
109
+ "limit": "18 KB",
110
+ "gzip": true,
111
+ "ignore": ["util", "node:util"]
110
112
  },
111
113
  {
114
+ "name": "Core (import * as Core)",
115
+ "import": "*",
112
116
  "path": "dist/core.mjs",
113
- "limit": "16 KB",
117
+ "limit": "11 KB",
114
118
  "gzip": true
115
119
  },
116
120
  {
117
- "path": "dist/composition.mjs",
118
- "limit": "3 KB",
121
+ "name": "Data (import * as Data)",
122
+ "import": "*",
123
+ "path": "dist/data.mjs",
124
+ "limit": "7 KB",
119
125
  "gzip": true
120
126
  },
121
127
  {
122
- "path": "dist/data.mjs",
123
- "limit": "10 KB",
124
- "gzip": true
128
+ "name": "Composition (import * as Composition)",
129
+ "import": "*",
130
+ "path": "dist/composition.mjs",
131
+ "limit": "2 KB",
132
+ "gzip": true,
133
+ "ignore": ["util", "node:util"]
125
134
  },
126
135
  {
136
+ "name": "Types (import * as Types)",
137
+ "import": "*",
127
138
  "path": "dist/types.mjs",
128
- "limit": "700 B",
139
+ "limit": "400 B",
129
140
  "gzip": true
130
141
  }
131
142
  ],