@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.
@@ -21,7 +21,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var Data_exports = {};
22
22
  __export(Data_exports, {
23
23
  Arr: () => Arr,
24
+ BigNum: () => BigNum,
24
25
  Dict: () => Dict,
26
+ Json: () => Json,
25
27
  Num: () => Num,
26
28
  Rec: () => Rec,
27
29
  Str: () => Str,
@@ -43,6 +45,8 @@ var Deferred;
43
45
  ((to2) => {
44
46
  to2.Promise = (d) => new globalThis.Promise((resolve) => d.then(resolve));
45
47
  })(to = Deferred2.to || (Deferred2.to = {}));
48
+ Deferred2.all = (deferreds) => from.Promise(globalThis.Promise.all(deferreds.map((d) => to.Promise(d))));
49
+ Deferred2.race = (deferreds) => from.Promise(globalThis.Promise.race(deferreds.map((d) => to.Promise(d))));
46
50
  })(Deferred || (Deferred = {}));
47
51
 
48
52
  // src/Core/Maybe.ts
@@ -102,6 +106,7 @@ var Maybe;
102
106
  }
103
107
  return make.some(result);
104
108
  };
109
+ Maybe3.transposeResult = (data) => is.none(data) ? Result.make.ok(make.none()) : Result.is.ok(data.value) ? Result.make.ok(make.some(data.value.value)) : Result.make.err(data.value.error);
105
110
  })(Maybe || (Maybe = {}));
106
111
 
107
112
  // src/Types/Brand.ts
@@ -145,11 +150,11 @@ var Result;
145
150
  is2.ok = (data) => data.kind === "Ok";
146
151
  is2.err = (data) => data.kind === "Err";
147
152
  })(is = Result3.is || (Result3.is = {}));
148
- Result3.tryCatch = (f, onError) => {
153
+ Result3.tryCatch = (f, options) => {
149
154
  try {
150
155
  return make.ok(f());
151
156
  } catch (error) {
152
- return make.err(onError(error));
157
+ return make.err(options.onError(error));
153
158
  }
154
159
  };
155
160
  Result3.map = (f) => (data) => is.ok(data) ? make.ok(f(data.value)) : data;
@@ -175,20 +180,23 @@ var Result;
175
180
  from2.Predicate = (pred, onFalse) => (a) => pred(a) ? make.ok(a) : make.err(onFalse(a));
176
181
  from2.nullable = (onNull) => (value) => value === null || value === void 0 ? make.err(onNull()) : make.ok(value);
177
182
  from2.Maybe = (onNone) => (maybe) => Maybe.is.none(maybe) ? make.err(onNone()) : make.ok(maybe.value);
178
- from2.throwable = (f, onError) => (...args) => {
183
+ from2.throwable = (f, options) => (...args) => {
179
184
  try {
180
185
  return make.ok(f(...args));
181
186
  } catch (error) {
182
- return make.err(onError(error));
187
+ return make.err(options.onError(error));
183
188
  }
184
189
  };
190
+ from2.Validation = (combineErrors) => (val) => Validation.is.passed(val) ? make.ok(val.value) : make.err(combineErrors(val.errors));
185
191
  })(from = Result3.from || (Result3.from = {}));
186
192
  Result3.recover = (fallback) => (data) => is.ok(data) ? data : fallback(data.error);
187
193
  Result3.recoverUnless = (isBlocked, fallback) => (data) => is.err(data) && !isBlocked(data.error) ? fallback() : data;
188
194
  let to;
189
195
  ((to2) => {
190
196
  to2.Maybe = (data) => is.ok(data) ? Maybe.make.some(data.value) : Maybe.make.none();
197
+ to2.Validation = (data) => Validation.from.Result(data);
191
198
  })(to = Result3.to || (Result3.to = {}));
199
+ Result3.transposeMaybe = (data) => is.err(data) ? Maybe.make.some(data) : Maybe.is.some(data.value) ? Maybe.make.some(make.ok(data.value.value)) : Maybe.make.none();
192
200
  Result3.ap = (arg) => (data) => is.ok(data) && is.ok(arg) ? make.ok(data.value(arg.value)) : is.err(data) ? data : arg;
193
201
  Result3.bindTo = (key) => (data) => (0, Result3.map)((a) => ({ [key]: a }))(data);
194
202
  Result3.bind = (key, f) => (data) => (0, Result3.chain)(
@@ -207,13 +215,20 @@ var Result;
207
215
  }
208
216
  return make.ok(result);
209
217
  };
218
+ Result3.ensure = (predicate, onFail) => (data) => is.err(data) ? data : predicate(data.value) ? data : make.err(onFail(data.value));
219
+ Result3.bimap = (onErr, onOk) => (data) => is.ok(data) ? make.ok(onOk(data.value)) : make.err(onErr(data.error));
210
220
  })(Result || (Result = {}));
211
221
 
212
222
  // src/Core/TaskMaybe.ts
213
223
  var TaskMaybe;
214
224
  ((TaskMaybe2) => {
215
- TaskMaybe2.some = (value) => Task.resolve(Maybe.make.some(value));
216
- TaskMaybe2.none = () => Task.resolve(Maybe.make.none());
225
+ let make;
226
+ ((make2) => {
227
+ make2.some = (value) => Task.resolve(Maybe.make.some(value));
228
+ make2.none = () => Task.resolve(Maybe.make.none());
229
+ })(make = TaskMaybe2.make || (TaskMaybe2.make = {}));
230
+ ({ some: TaskMaybe2.some } = make);
231
+ ({ none: TaskMaybe2.none } = make);
217
232
  let from;
218
233
  ((from2) => {
219
234
  from2.Maybe = (option) => Task.resolve(option);
@@ -269,19 +284,28 @@ var TaskMaybe;
269
284
  // src/Core/TaskResult.ts
270
285
  var TaskResult;
271
286
  ((TaskResult2) => {
272
- TaskResult2.ok = (value) => Task.resolve(Result.make.ok(value));
273
- TaskResult2.err = (error) => Task.resolve(Result.make.err(error));
287
+ let make;
288
+ ((make2) => {
289
+ make2.ok = (value) => Task.resolve(Result.make.ok(value));
290
+ make2.err = (error) => Task.resolve(Result.make.err(error));
291
+ })(make = TaskResult2.make || (TaskResult2.make = {}));
292
+ ({ ok: TaskResult2.ok } = make);
293
+ ({ err: TaskResult2.err } = make);
274
294
  let from;
275
295
  ((from2) => {
276
296
  from2.nullable = (onNull) => (value) => Task.resolve(value === null || value === void 0 ? Result.make.err(onNull()) : Result.make.ok(value));
277
297
  from2.Maybe = (onNone) => (maybe) => Task.resolve(Maybe.is.none(maybe) ? Result.make.err(onNone()) : Result.make.ok(maybe.value));
278
298
  from2.Result = (result) => Task.resolve(result);
279
- from2.throwable = (f, onError) => (...args) => Task.from.Promise(
280
- () => f(...args).then(Result.make.ok).catch((error) => Result.make.err(onError(error)))
299
+ from2.throwable = (f, options) => (...args) => Task.from.Promise(
300
+ () => f(...args).then(Result.make.ok).catch((error) => Result.make.err(options.onError(error)))
281
301
  );
282
302
  })(from = TaskResult2.from || (TaskResult2.from = {}));
283
- TaskResult2.tryCatch = (f, onError) => Task.from.Promise(
284
- (signal) => Promise.resolve(f(signal)).then(Result.make.ok).catch((error) => Result.make.err(onError(error)))
303
+ let to;
304
+ ((to2) => {
305
+ to2.Maybe = (data) => Task.map(Result.to.Maybe)(data);
306
+ })(to = TaskResult2.to || (TaskResult2.to = {}));
307
+ TaskResult2.tryCatch = (f, options) => Task.from.Promise(
308
+ (signal) => Promise.resolve(f(signal)).then(Result.make.ok).catch((error) => Result.make.err(options.onError(error)))
285
309
  );
286
310
  TaskResult2.map = (f) => (data) => Task.map(Result.map(f))(data);
287
311
  TaskResult2.mapError = (f) => (data) => Task.map(Result.mapError(f))(data);
@@ -321,6 +345,60 @@ var TaskResult;
321
345
  return Result.make.ok(record);
322
346
  });
323
347
  });
348
+ TaskResult2.retry = (policy) => (task) => Task.from.Promise((signal) => {
349
+ const { attempts } = policy;
350
+ const wait = (duration) => new Promise((res) => {
351
+ let timerId;
352
+ const onAbort = () => {
353
+ clearTimeout(timerId);
354
+ res();
355
+ };
356
+ if (signal) {
357
+ if (signal.aborted) {
358
+ return res();
359
+ }
360
+ signal.addEventListener("abort", onAbort, { once: true });
361
+ }
362
+ timerId = setTimeout(() => {
363
+ signal?.removeEventListener("abort", onAbort);
364
+ res();
365
+ }, Duration.to.milliseconds(duration));
366
+ });
367
+ const executeAttempt = (attempt) => Deferred.to.Promise(task(signal)).then((res) => {
368
+ if (Result.is.ok(res) || attempt >= attempts || signal?.aborted) {
369
+ return res;
370
+ }
371
+ const delay = policy.getDelay(attempt);
372
+ return wait(delay).then(() => executeAttempt(attempt + 1));
373
+ });
374
+ return executeAttempt(1);
375
+ });
376
+ TaskResult2.memoize = (task) => Task.memoize(task);
377
+ TaskResult2.timeout = (options) => (task) => Task.from.Promise((signal) => {
378
+ const ms = Duration.to.milliseconds(options.duration);
379
+ return new Promise((resolve) => {
380
+ let timerId;
381
+ const onAbort = () => {
382
+ clearTimeout(timerId);
383
+ };
384
+ if (signal) {
385
+ if (signal.aborted) {
386
+ return Deferred.to.Promise(task(signal)).then(resolve);
387
+ }
388
+ signal.addEventListener("abort", onAbort, { once: true });
389
+ }
390
+ timerId = setTimeout(() => {
391
+ signal?.removeEventListener("abort", onAbort);
392
+ resolve(Result.make.err(options.onTimeout()));
393
+ }, ms);
394
+ Deferred.to.Promise(task(signal)).then((res) => {
395
+ clearTimeout(timerId);
396
+ signal?.removeEventListener("abort", onAbort);
397
+ resolve(res);
398
+ });
399
+ });
400
+ });
401
+ TaskResult2.allSettled = (tasks) => Task.from.Promise((signal) => Promise.all(tasks.map((task) => Deferred.to.Promise(task(signal)))));
324
402
  })(TaskResult || (TaskResult = {}));
325
403
 
326
404
  // src/internal/InternalTypes.ts
@@ -329,9 +407,15 @@ var isNonEmptyArr = (list) => list.length > 0;
329
407
  // src/Core/TaskValidation.ts
330
408
  var TaskValidation;
331
409
  ((TaskValidation2) => {
332
- TaskValidation2.passed = (value) => Task.resolve(Validation.make.passed(value));
333
- TaskValidation2.failed = (error) => Task.resolve(Validation.make.failed(error));
334
- TaskValidation2.failedAll = (errors) => Task.resolve(Validation.make.failedAll(errors));
410
+ let make;
411
+ ((make2) => {
412
+ make2.passed = (value) => Task.resolve(Validation.make.passed(value));
413
+ make2.failed = (error) => Task.resolve(Validation.make.failed(error));
414
+ make2.failedAll = (errors) => Task.resolve(Validation.make.failedAll(errors));
415
+ })(make = TaskValidation2.make || (TaskValidation2.make = {}));
416
+ ({ passed: TaskValidation2.passed } = make);
417
+ ({ failed: TaskValidation2.failed } = make);
418
+ ({ failedAll: TaskValidation2.failedAll } = make);
335
419
  let from;
336
420
  ((from2) => {
337
421
  from2.Validation = (validation) => Task.resolve(validation);
@@ -549,7 +633,8 @@ var Task;
549
633
  }
550
634
  return results;
551
635
  });
552
- Task2.timeout = (duration, onTimeout) => (task) => from.Promise((outerSignal) => {
636
+ Task2.timeout = (options) => (task) => from.Promise((outerSignal) => {
637
+ const { duration, onTimeout } = options;
553
638
  const controller = new AbortController();
554
639
  let timerId;
555
640
  let cleanUp = () => {
@@ -606,6 +691,30 @@ var Task;
606
691
  Task2.bind = (key, f) => (data) => (0, Task2.chain)(
607
692
  (a) => (0, Task2.map)((b) => ({ ...a, [key]: b }))(f(a))
608
693
  )(data);
694
+ Task2.memoize = (task) => {
695
+ let cached = null;
696
+ return (signal) => {
697
+ if (cached === null) {
698
+ cached = task(signal);
699
+ }
700
+ return cached;
701
+ };
702
+ };
703
+ Task2.withProgress = (onProgress) => (task) => (signal) => {
704
+ onProgress(0);
705
+ const d = task(signal);
706
+ return Deferred.from.Promise(
707
+ Deferred.to.Promise(d).then((res) => {
708
+ onProgress(1);
709
+ return res;
710
+ })
711
+ );
712
+ };
713
+ Task2.withLabel = (label) => (task) => {
714
+ const fn = ((signal) => task(signal));
715
+ Object.defineProperty(fn, "label", { value: label, writable: false, enumerable: true, configurable: true });
716
+ return fn;
717
+ };
609
718
  Task2.Maybe = TaskMaybe;
610
719
  Task2.Result = TaskResult;
611
720
  Task2.Validation = TaskValidation;
@@ -625,6 +734,13 @@ var Validation;
625
734
  is2.passed = (data) => data.kind === "Passed";
626
735
  is2.failed = (data) => data.kind === "Failed";
627
736
  })(is = Validation2.is || (Validation2.is = {}));
737
+ Validation2.tryCatch = (f, options) => {
738
+ try {
739
+ return make.passed(f());
740
+ } catch (error) {
741
+ return make.failed(options.onError(error));
742
+ }
743
+ };
628
744
  let from;
629
745
  ((from2) => {
630
746
  from2.Predicate = (pred, onFalse) => (a) => pred(a) ? make.passed(a) : make.failed(onFalse(a));
@@ -640,6 +756,12 @@ var Validation;
640
756
  }
641
757
  return is.passed(arg) ? make.failedAll(data.errors) : make.failedAll([...data.errors, ...arg.errors]);
642
758
  };
759
+ Validation2.apCustom = (concat) => (arg) => (data) => {
760
+ if (is.passed(data)) {
761
+ return is.passed(arg) ? make.passed(data.value(arg.value)) : make.failedAll(arg.errors);
762
+ }
763
+ return is.passed(arg) ? make.failedAll(data.errors) : make.failedAll(concat(data.errors, arg.errors));
764
+ };
643
765
  Validation2.fold = (onFailed, onPassed) => (data) => is.passed(data) ? onPassed(data.value) : onFailed(data.errors);
644
766
  Validation2.match = (cases) => (data) => is.passed(data) ? cases.passed(data.value) : cases.failed(data.errors);
645
767
  Validation2.getOrElse = (defaultValue) => (data) => is.passed(data) ? data.value : defaultValue();
@@ -659,7 +781,14 @@ var Validation;
659
781
  Validation2.recoverUnless = (isBlocked, fallback) => (data) => is.failed(data) && !data.errors.some(isBlocked) ? fallback() : data;
660
782
  let to;
661
783
  ((to2) => {
662
- to2.Result = (data) => is.passed(data) ? Result.make.ok(data.value) : Result.make.err(data.errors);
784
+ function Result3(arg) {
785
+ if (typeof arg === "function") {
786
+ const combine = arg;
787
+ return (val) => is.passed(val) ? Result.make.ok(val.value) : Result.make.err(combine(val.errors));
788
+ }
789
+ return is.passed(arg) ? Result.make.ok(arg.value) : Result.make.err(arg.errors);
790
+ }
791
+ to2.Result = Result3;
663
792
  to2.Maybe = (data) => is.passed(data) ? Maybe.make.some(data.value) : Maybe.make.none();
664
793
  })(to = Validation2.to || (Validation2.to = {}));
665
794
  Validation2.product = (first, second) => {
@@ -1082,9 +1211,154 @@ var Arr;
1082
1211
  const i = Math.max(0, index);
1083
1212
  return [data.slice(0, i), data.slice(i)];
1084
1213
  };
1214
+ Arr2.partitionMaybe = (f) => (data) => {
1215
+ const failures = [];
1216
+ const successes = [];
1217
+ for (let i = 0; i < data.length; i++) {
1218
+ const res = f(data[i]);
1219
+ if (res.kind === "Some") {
1220
+ successes.push(res.value);
1221
+ } else {
1222
+ failures.push(data[i]);
1223
+ }
1224
+ }
1225
+ return [failures, successes];
1226
+ };
1227
+ Arr2.at = (index) => (data) => {
1228
+ const targetIndex = index < 0 ? data.length + index : index;
1229
+ if (targetIndex < 0 || targetIndex >= data.length) {
1230
+ return Maybe.make.none();
1231
+ }
1232
+ return Maybe.make.some(data[targetIndex]);
1233
+ };
1234
+ Arr2.findMap = (f) => (data) => {
1235
+ for (let i = 0; i < data.length; i++) {
1236
+ const res = f(data[i]);
1237
+ if (res.kind === "Some") {
1238
+ return res;
1239
+ }
1240
+ }
1241
+ return Maybe.make.none();
1242
+ };
1243
+ Arr2.indexBy = (keyFn) => (data) => {
1244
+ const map2 = new globalThis.Map();
1245
+ for (let i = 0; i < data.length; i++) {
1246
+ map2.set(keyFn(data[i]), data[i]);
1247
+ }
1248
+ return map2;
1249
+ };
1250
+ Arr2.frequencies = (data) => {
1251
+ const map2 = new globalThis.Map();
1252
+ for (let i = 0; i < data.length; i++) {
1253
+ const item = data[i];
1254
+ map2.set(item, (map2.get(item) ?? 0) + 1);
1255
+ }
1256
+ return map2;
1257
+ };
1258
+ Arr2.chunkBy = (keyFn) => (data) => {
1259
+ if (data.length === 0) {
1260
+ return [];
1261
+ }
1262
+ const result = [];
1263
+ let currentChunk = [data[0]];
1264
+ let currentKey = keyFn(data[0]);
1265
+ for (let i = 1; i < data.length; i++) {
1266
+ const item = data[i];
1267
+ const key = keyFn(item);
1268
+ if (Object.is(key, currentKey)) {
1269
+ currentChunk.push(item);
1270
+ } else {
1271
+ result.push(currentChunk);
1272
+ currentChunk = [item];
1273
+ currentKey = key;
1274
+ }
1275
+ }
1276
+ result.push(currentChunk);
1277
+ return result;
1278
+ };
1279
+ Arr2.dedupeAdjacent = (eq = (a, b) => Object.is(a, b)) => (data) => {
1280
+ if (data.length === 0) {
1281
+ return [];
1282
+ }
1283
+ const result = [data[0]];
1284
+ for (let i = 1; i < data.length; i++) {
1285
+ if (!eq(data[i], result[result.length - 1])) {
1286
+ result.push(data[i]);
1287
+ }
1288
+ }
1289
+ return result;
1290
+ };
1291
+ Arr2.windowed = (size2, options) => (data) => {
1292
+ const step = options?.step ?? 1;
1293
+ if (size2 <= 0 || step <= 0 || data.length < size2) {
1294
+ return [];
1295
+ }
1296
+ const result = [];
1297
+ for (let i = 0; i <= data.length - size2; i += step) {
1298
+ result.push(data.slice(i, i + size2));
1299
+ }
1300
+ return result;
1301
+ };
1302
+ Arr2.unfold = (initial, f) => {
1303
+ const result = [];
1304
+ let currentState = initial;
1305
+ while (true) {
1306
+ const next = f(currentState);
1307
+ if (next.kind === "None") {
1308
+ break;
1309
+ }
1310
+ const [item, nextState] = next.value;
1311
+ result.push(item);
1312
+ currentState = nextState;
1313
+ }
1314
+ return result;
1315
+ };
1085
1316
  Arr2.NonEmpty = ArrNonEmpty;
1086
1317
  })(Arr || (Arr = {}));
1087
1318
 
1319
+ // src/Data/BigNum.ts
1320
+ var BigNum;
1321
+ ((BigNum2) => {
1322
+ let from;
1323
+ ((from2) => {
1324
+ from2.string = (s) => {
1325
+ try {
1326
+ if (s.trim() === "") {
1327
+ return Maybe.make.none();
1328
+ }
1329
+ return Maybe.make.some(BigInt(s));
1330
+ } catch {
1331
+ return Maybe.make.none();
1332
+ }
1333
+ };
1334
+ from2.number = (n) => {
1335
+ if (!Number.isInteger(n) || n < Number.MIN_SAFE_INTEGER || n > Number.MAX_SAFE_INTEGER) {
1336
+ return Maybe.make.none();
1337
+ }
1338
+ return Maybe.make.some(BigInt(n));
1339
+ };
1340
+ })(from = BigNum2.from || (BigNum2.from = {}));
1341
+ let to;
1342
+ ((to2) => {
1343
+ to2.number = (b) => {
1344
+ if (b < BigInt(Number.MIN_SAFE_INTEGER) || b > BigInt(Number.MAX_SAFE_INTEGER)) {
1345
+ return Maybe.make.none();
1346
+ }
1347
+ return Maybe.make.some(Number(b));
1348
+ };
1349
+ })(to = BigNum2.to || (BigNum2.to = {}));
1350
+ BigNum2.add = (b) => (a) => a + b;
1351
+ BigNum2.sub = (b) => (a) => a - b;
1352
+ BigNum2.mul = (b) => (a) => a * b;
1353
+ BigNum2.div = (b) => (a) => b === 0n ? Maybe.make.none() : Maybe.make.some(a / b);
1354
+ BigNum2.mod = (b) => (a) => b === 0n ? Maybe.make.none() : Maybe.make.some(a % b);
1355
+ BigNum2.clamp = (min2, max2) => (a) => a < min2 ? min2 : a > max2 ? max2 : a;
1356
+ BigNum2.inRange = (start, end) => (a) => a >= start && a < end;
1357
+ BigNum2.abs = (a) => a < 0n ? -a : a;
1358
+ BigNum2.min = (b) => (a) => a < b ? a : b;
1359
+ BigNum2.max = (b) => (a) => a > b ? a : b;
1360
+ })(BigNum || (BigNum = {}));
1361
+
1088
1362
  // src/Data/Dict.ts
1089
1363
  var DictNonEmpty;
1090
1364
  ((DictNonEmpty2) => {
@@ -1241,16 +1515,86 @@ var Dict;
1241
1515
  }
1242
1516
  return acc;
1243
1517
  };
1518
+ function mergeWith(combine) {
1519
+ return (arg1, arg2) => {
1520
+ if (arg2 !== void 0) {
1521
+ const first = arg1;
1522
+ const second2 = arg2;
1523
+ const res = new globalThis.Map(first);
1524
+ for (const [k, v] of second2) {
1525
+ if (res.has(k)) {
1526
+ res.set(k, combine(res.get(k), v));
1527
+ } else {
1528
+ res.set(k, v);
1529
+ }
1530
+ }
1531
+ return res;
1532
+ }
1533
+ const second = arg1;
1534
+ return (first) => {
1535
+ const res = new globalThis.Map(first);
1536
+ for (const [k, v] of second) {
1537
+ if (res.has(k)) {
1538
+ res.set(k, combine(res.get(k), v));
1539
+ } else {
1540
+ res.set(k, v);
1541
+ }
1542
+ }
1543
+ return res;
1544
+ };
1545
+ };
1546
+ }
1547
+ Dict2.mergeWith = mergeWith;
1244
1548
  let to;
1245
1549
  ((to2) => {
1246
1550
  to2.Record = (m) => Object.fromEntries(m);
1247
1551
  })(to = Dict2.to || (Dict2.to = {}));
1552
+ Dict2.mapEntries = (f) => (data) => {
1553
+ const res = new globalThis.Map();
1554
+ for (const [k, v] of data) {
1555
+ const [nk, nv] = f(k, v);
1556
+ res.set(nk, nv);
1557
+ }
1558
+ return res;
1559
+ };
1560
+ Dict2.mapKeys = (f) => (data) => {
1561
+ const res = new globalThis.Map();
1562
+ for (const [k, v] of data) {
1563
+ res.set(f(k), v);
1564
+ }
1565
+ return res;
1566
+ };
1248
1567
  Dict2.NonEmpty = DictNonEmpty;
1249
1568
  })(Dict || (Dict = {}));
1250
1569
 
1570
+ // src/Data/Json.ts
1571
+ var isSyntaxError = (err) => typeof err === "object" && err !== null && "name" in err && err.name === "SyntaxError";
1572
+ var isTypeError = (err) => typeof err === "object" && err !== null && "name" in err && err.name === "TypeError";
1573
+ var Json;
1574
+ ((Json2) => {
1575
+ Json2.parse = (text) => Result.tryCatch(() => JSON.parse(text), {
1576
+ onError: (err) => isSyntaxError(err) ? err : new SyntaxError(String(err))
1577
+ });
1578
+ Json2.stringify = (value, replacer, space) => Result.tryCatch(() => JSON.stringify(value, replacer, space), {
1579
+ onError: (err) => isTypeError(err) ? err : new TypeError(String(err))
1580
+ });
1581
+ })(Json || (Json = {}));
1582
+
1251
1583
  // src/Data/Num.ts
1252
1584
  var Num;
1253
1585
  ((Num2) => {
1586
+ let is;
1587
+ ((is2) => {
1588
+ is2.zero = (n) => n === 0;
1589
+ is2.integer = (n) => Number.isInteger(n);
1590
+ is2.float = (n) => Number.isFinite(n) && !Number.isInteger(n);
1591
+ is2.finite = (n) => Number.isFinite(n);
1592
+ is2.nan = (n) => Number.isNaN(n);
1593
+ is2.even = (n) => Number.isInteger(n) && n % 2 === 0;
1594
+ is2.odd = (n) => Number.isInteger(n) && n % 2 !== 0;
1595
+ is2.positive = (n) => n > 0;
1596
+ is2.negative = (n) => n < 0;
1597
+ })(is = Num2.is || (Num2.is = {}));
1254
1598
  Num2.range = (from, to, step = 1) => {
1255
1599
  if (step <= 0 || from > to) {
1256
1600
  return [];
@@ -1314,6 +1658,7 @@ var Num;
1314
1658
  }
1315
1659
  return Maybe.make.some(result);
1316
1660
  };
1661
+ Num2.format = (options, locales) => (n) => !Number.isFinite(n) ? Maybe.make.none() : Maybe.make.some(new Intl.NumberFormat(locales, options).format(n));
1317
1662
  })(Num || (Num = {}));
1318
1663
 
1319
1664
  // src/Data/Rec.ts
@@ -1501,6 +1846,36 @@ var Rec;
1501
1846
  ...data,
1502
1847
  ...other
1503
1848
  });
1849
+ function mergeWith(combine) {
1850
+ return (arg1, arg2) => {
1851
+ if (arg2 !== void 0) {
1852
+ const first = arg1;
1853
+ const second2 = arg2;
1854
+ const result = { ...first };
1855
+ for (const [k, v] of Object.entries(second2)) {
1856
+ if (Object.hasOwn(result, k)) {
1857
+ result[k] = combine(result[k], v);
1858
+ } else {
1859
+ result[k] = v;
1860
+ }
1861
+ }
1862
+ return result;
1863
+ }
1864
+ const second = arg1;
1865
+ return (first) => {
1866
+ const result = { ...first };
1867
+ for (const [k, v] of Object.entries(second)) {
1868
+ if (Object.hasOwn(result, k)) {
1869
+ result[k] = combine(result[k], v);
1870
+ } else {
1871
+ result[k] = v;
1872
+ }
1873
+ }
1874
+ return result;
1875
+ };
1876
+ };
1877
+ }
1878
+ Rec2.mergeWith = mergeWith;
1504
1879
  Rec2.size = (data) => Object.keys(data).length;
1505
1880
  Rec2.mapKeys = (f) => (data) => {
1506
1881
  const result = {};
@@ -1518,6 +1893,25 @@ var Rec;
1518
1893
  }
1519
1894
  return result;
1520
1895
  };
1896
+ Rec2.mapEntries = (f) => (data) => {
1897
+ const result = {};
1898
+ for (const [k, v] of Object.entries(data)) {
1899
+ const [newKey, newVal] = f(k, v);
1900
+ Object.defineProperty(result, newKey, { value: newVal, writable: true, enumerable: true, configurable: true });
1901
+ }
1902
+ return result;
1903
+ };
1904
+ Rec2.updateIn = (path, f) => (data) => {
1905
+ const updateNode = (obj, keys2) => {
1906
+ const [head, ...tail] = keys2;
1907
+ if (tail.length === 0) {
1908
+ return { ...obj, [head]: f(obj?.[head]) };
1909
+ }
1910
+ const child = obj && typeof obj === "object" && head in obj ? obj[head] : {};
1911
+ return { ...obj, [head]: updateNode(child, tail) };
1912
+ };
1913
+ return updateNode(data, path);
1914
+ };
1521
1915
  let traverse;
1522
1916
  ((traverse2) => {
1523
1917
  traverse2.Maybe = RecMaybe.traverse;
@@ -1600,6 +1994,17 @@ var Str;
1600
1994
  return Result.make.err(error);
1601
1995
  }
1602
1996
  };
1997
+ Str2.uncapitalize = (s) => s.length === 0 ? "" : s.charAt(0).toLowerCase() + s.slice(1);
1998
+ Str2.truncate = (options) => (s) => {
1999
+ const { length: targetLength, suffix = "..." } = options;
2000
+ if (s.length <= targetLength) {
2001
+ return s;
2002
+ }
2003
+ if (targetLength <= suffix.length) {
2004
+ return suffix.slice(0, targetLength);
2005
+ }
2006
+ return s.slice(0, targetLength - suffix.length) + suffix;
2007
+ };
1603
2008
  Str2.NonEmpty = StrNonEmpty;
1604
2009
  })(Str || (Str = {}));
1605
2010
 
@@ -1730,7 +2135,9 @@ var Uniq;
1730
2135
  // Annotate the CommonJS export names for ESM import in node:
1731
2136
  0 && (module.exports = {
1732
2137
  Arr,
2138
+ BigNum,
1733
2139
  Dict,
2140
+ Json,
1734
2141
  Num,
1735
2142
  Rec,
1736
2143
  Str,
package/dist/data.mjs ADDED
@@ -0,0 +1,22 @@
1
+ import {
2
+ Arr,
3
+ BigNum,
4
+ Dict,
5
+ Json,
6
+ Num,
7
+ Rec,
8
+ Str,
9
+ Uniq
10
+ } from "./chunk-UGVU2RTM.mjs";
11
+ import "./chunk-LR63GW6J.mjs";
12
+ import "./chunk-DENXUTKL.mjs";
13
+ export {
14
+ Arr,
15
+ BigNum,
16
+ Dict,
17
+ Json,
18
+ Num,
19
+ Rec,
20
+ Str,
21
+ Uniq
22
+ };
package/dist/index.d.mts CHANGED
@@ -1,6 +1,7 @@
1
- export { and, compose, constFalse, constNull, constTrue, constUndefined, constVoid, constant, converge, curry, curry3, curry4, defaultTo, flip, flow, identity, juxt, memoize, memoizeWeak, not, on, once, or, pipe, tap, uncurry, uncurry3, uncurry4 } from './composition.mjs';
1
+ export { and, compose, constFalse, constNull, constTrue, constUndefined, constVoid, constant, converge, curry, curry3, curry4, defaultTo, flip, flow, identity, juxt, memoize, memoizeWeak, not, on, once, or, pipe, tap, tuple, uncurry, uncurry3, uncurry4, untuple } from './composition.mjs';
2
2
  export { Combinable, Failure, Lazy, Lens, Loading, Logged, NotAsked, Op, Optional, Predicate, Reader, Refinement, RemoteData, Resource, State, Success, These, TheseBoth, TheseFirst, TheseSecond, Tuple } from './core.mjs';
3
- export { D as Deferred } from './InternalTypes-CLE7qlOc.mjs';
4
- export { E as Equality, a as Err, F as Failed, M as Maybe, N as None, O as Ok, b as Ordering, P as Passed, R as Result, S as Some, T as Task, c as TaskMaybe, d as TaskResult, e as TaskValidation, V as Validation } from './Validation-v38R0qH-.mjs';
5
- export { Arr, Dict, NonEmptyMap, NonEmptyRecord, NonEmptySet, NonEmptyString, Num, Rec, Str, Uniq } from './utils.mjs';
6
- export { Brand, Duration } from './types.mjs';
3
+ export { D as Deferred } from './InternalTypes-CDiDBAY4.mjs';
4
+ export { E as Equality, a as Err, F as Failed, M as Maybe, N as None, O as Ok, b as Ordering, P as Passed, R as Result, S as Some, T as Task, c as TaskMaybe, d as TaskResult, e as TaskValidation, V as Validation } from './Validation-D-aARYlP.mjs';
5
+ export { Arr, BigNum, Dict, Json, NonEmptyMap, NonEmptyRecord, NonEmptySet, NonEmptyString, Num, Rec, Str, Uniq } from './data.mjs';
6
+ export { B as Brand, D as Duration } from './Duration-B8joKzro.mjs';
7
+ export { RetryPolicy } from './types.mjs';
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- export { and, compose, constFalse, constNull, constTrue, constUndefined, constVoid, constant, converge, curry, curry3, curry4, defaultTo, flip, flow, identity, juxt, memoize, memoizeWeak, not, on, once, or, pipe, tap, uncurry, uncurry3, uncurry4 } from './composition.js';
1
+ export { and, compose, constFalse, constNull, constTrue, constUndefined, constVoid, constant, converge, curry, curry3, curry4, defaultTo, flip, flow, identity, juxt, memoize, memoizeWeak, not, on, once, or, pipe, tap, tuple, uncurry, uncurry3, uncurry4, untuple } from './composition.js';
2
2
  export { Combinable, Failure, Lazy, Lens, Loading, Logged, NotAsked, Op, Optional, Predicate, Reader, Refinement, RemoteData, Resource, State, Success, These, TheseBoth, TheseFirst, TheseSecond, Tuple } from './core.js';
3
- export { D as Deferred } from './InternalTypes-Mssktd7z.js';
4
- export { E as Equality, a as Err, F as Failed, M as Maybe, N as None, O as Ok, b as Ordering, P as Passed, R as Result, S as Some, T as Task, c as TaskMaybe, d as TaskResult, e as TaskValidation, V as Validation } from './Validation-BMsvixWH.js';
5
- export { Arr, Dict, NonEmptyMap, NonEmptyRecord, NonEmptySet, NonEmptyString, Num, Rec, Str, Uniq } from './utils.js';
6
- export { Brand, Duration } from './types.js';
3
+ export { D as Deferred } from './InternalTypes-LdhLQx3N.js';
4
+ export { E as Equality, a as Err, F as Failed, M as Maybe, N as None, O as Ok, b as Ordering, P as Passed, R as Result, S as Some, T as Task, c as TaskMaybe, d as TaskResult, e as TaskValidation, V as Validation } from './Validation-1OgJJdeA.js';
5
+ export { Arr, BigNum, Dict, Json, NonEmptyMap, NonEmptyRecord, NonEmptySet, NonEmptyString, Num, Rec, Str, Uniq } from './data.js';
6
+ export { B as Brand, D as Duration } from './Duration-B8joKzro.js';
7
+ export { RetryPolicy } from './types.js';