@oscarpalmer/atoms 0.166.2 → 0.167.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/array/difference.d.mts +1 -1
- package/dist/array/exists.d.mts +1 -1
- package/dist/array/filter.d.mts +2 -2
- package/dist/array/find.d.mts +1 -1
- package/dist/array/intersection.d.mts +1 -1
- package/dist/array/move.d.mts +2 -2
- package/dist/array/partition.d.mts +1 -1
- package/dist/array/select.d.mts +1 -1
- package/dist/array/slice.d.mts +2 -2
- package/dist/array/sort.d.mts +4 -4
- package/dist/array/swap.d.mts +2 -2
- package/dist/array/to-set.d.mts +1 -1
- package/dist/array/toggle.d.mts +1 -1
- package/dist/array/union.d.mts +1 -1
- package/dist/array/update.d.mts +1 -1
- package/dist/index.d.mts +243 -211
- package/dist/index.mjs +29 -29
- package/dist/internal/array/index-of.d.mts +1 -1
- package/dist/internal/math/aggregate.d.mts +1 -1
- package/dist/internal/value/partial.d.mts +2 -2
- package/dist/math.d.mts +1 -1
- package/dist/models.d.mts +7 -7
- package/dist/promise/index.d.mts +2 -7
- package/dist/promise/index.mjs +5 -7
- package/dist/promise/misc.d.mts +3 -1
- package/dist/promise/misc.mjs +3 -2
- package/dist/promise/models.d.mts +4 -4
- package/dist/result/index.d.mts +2 -5
- package/dist/result/index.mjs +2 -4
- package/dist/result/misc.d.mts +2 -1
- package/dist/result/misc.mjs +2 -2
- package/dist/sized/map.d.mts +11 -11
- package/dist/value/omit.d.mts +1 -1
- package/dist/value/pick.d.mts +1 -1
- package/dist/value/smush.d.mts +1 -1
- package/dist/value/unsmush.d.mts +1 -1
- package/package.json +30 -2
- package/src/array/difference.ts +2 -2
- package/src/array/exists.ts +3 -3
- package/src/array/filter.ts +6 -6
- package/src/array/find.ts +3 -3
- package/src/array/intersection.ts +2 -2
- package/src/array/move.ts +4 -4
- package/src/array/partition.ts +3 -3
- package/src/array/select.ts +3 -3
- package/src/array/slice.ts +6 -6
- package/src/array/sort.ts +4 -4
- package/src/array/swap.ts +4 -4
- package/src/array/to-set.ts +3 -3
- package/src/array/toggle.ts +2 -2
- package/src/array/union.ts +2 -2
- package/src/array/update.ts +2 -2
- package/src/index.ts +9 -0
- package/src/internal/array/index-of.ts +3 -3
- package/src/internal/math/aggregate.ts +2 -2
- package/src/internal/value/partial.ts +9 -9
- package/src/math.ts +3 -3
- package/src/models.ts +30 -20
- package/src/promise/index.ts +0 -22
- package/src/promise/misc.ts +7 -0
- package/src/promise/models.ts +13 -11
- package/src/result/index.ts +0 -9
- package/src/result/misc.ts +6 -0
- package/src/sized/map.ts +14 -14
- package/src/value/omit.ts +3 -3
- package/src/value/pick.ts +3 -3
- package/src/value/smush.ts +1 -1
- package/src/value/unsmush.ts +1 -1
package/src/array/partition.ts
CHANGED
|
@@ -22,10 +22,10 @@ export function partition<
|
|
|
22
22
|
* @param value Value to match against
|
|
23
23
|
* @returns Partitioned array of items
|
|
24
24
|
*/
|
|
25
|
-
export function partition<Item extends PlainObject,
|
|
25
|
+
export function partition<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
26
26
|
array: Item[],
|
|
27
|
-
key:
|
|
28
|
-
value: Item[
|
|
27
|
+
key: ItemKey,
|
|
28
|
+
value: Item[ItemKey],
|
|
29
29
|
): Item[][];
|
|
30
30
|
|
|
31
31
|
/**
|
package/src/array/select.ts
CHANGED
|
@@ -30,12 +30,12 @@ export function select<
|
|
|
30
30
|
*/
|
|
31
31
|
export function select<
|
|
32
32
|
Item extends PlainObject,
|
|
33
|
-
|
|
33
|
+
ItemKey extends keyof Item,
|
|
34
34
|
MapCallback extends (item: Item, index: number, array: Item[]) => unknown,
|
|
35
35
|
>(
|
|
36
36
|
array: Item[],
|
|
37
|
-
filterKey:
|
|
38
|
-
filterValue: Item[
|
|
37
|
+
filterKey: ItemKey,
|
|
38
|
+
filterValue: Item[ItemKey],
|
|
39
39
|
mapCallback: MapCallback,
|
|
40
40
|
): Array<ReturnType<MapCallback>>;
|
|
41
41
|
|
package/src/array/slice.ts
CHANGED
|
@@ -16,10 +16,10 @@ type ExtractType = 'drop' | 'take';
|
|
|
16
16
|
* @param value Value to match against
|
|
17
17
|
* @returns New array with items dropped
|
|
18
18
|
*/
|
|
19
|
-
export function drop<Item extends PlainObject,
|
|
19
|
+
export function drop<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
20
20
|
array: Item[],
|
|
21
|
-
key:
|
|
22
|
-
value: Item[
|
|
21
|
+
key: ItemKey,
|
|
22
|
+
value: Item[ItemKey],
|
|
23
23
|
): Item[];
|
|
24
24
|
|
|
25
25
|
/**
|
|
@@ -192,10 +192,10 @@ export function slice(array: unknown[], first?: number, second?: number): unknow
|
|
|
192
192
|
* @param value Value to match against
|
|
193
193
|
* @returns New array with taken items
|
|
194
194
|
*/
|
|
195
|
-
export function take<Item extends PlainObject,
|
|
195
|
+
export function take<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
196
196
|
array: Item[],
|
|
197
|
-
key:
|
|
198
|
-
value: Item[
|
|
197
|
+
key: ItemKey,
|
|
198
|
+
value: Item[ItemKey],
|
|
199
199
|
): Item[];
|
|
200
200
|
|
|
201
201
|
/**
|
package/src/array/sort.ts
CHANGED
|
@@ -21,11 +21,11 @@ export type ArrayComparisonSorter<Item> = {
|
|
|
21
21
|
/**
|
|
22
22
|
* Sorting information for arrays _(using a key)_
|
|
23
23
|
*/
|
|
24
|
-
export type ArrayKeySorter<Item extends PlainObject,
|
|
24
|
+
export type ArrayKeySorter<Item extends PlainObject, ItemKey extends keyof Item> = {
|
|
25
25
|
/**
|
|
26
26
|
* Comparator to use when comparing items and values
|
|
27
27
|
*/
|
|
28
|
-
compare?: CompareCallback<Item, Item[
|
|
28
|
+
compare?: CompareCallback<Item, Item[ItemKey]>;
|
|
29
29
|
/**
|
|
30
30
|
* Direction to sort by
|
|
31
31
|
*/
|
|
@@ -33,14 +33,14 @@ export type ArrayKeySorter<Item extends PlainObject, Key extends keyof Item> = {
|
|
|
33
33
|
/**
|
|
34
34
|
* Key to sort by
|
|
35
35
|
*/
|
|
36
|
-
key:
|
|
36
|
+
key: ItemKey;
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* Sorters based on keys in an object
|
|
41
41
|
*/
|
|
42
42
|
type ArrayKeySorters<Item extends PlainObject> = {
|
|
43
|
-
[
|
|
43
|
+
[ItemKey in keyof Item]: ArrayKeySorter<Item, ItemKey>;
|
|
44
44
|
}[keyof Item];
|
|
45
45
|
|
|
46
46
|
/**
|
package/src/array/swap.ts
CHANGED
|
@@ -14,11 +14,11 @@ import {indexOfArray} from './position';
|
|
|
14
14
|
* @param key Key to get an item's value for matching
|
|
15
15
|
* @returns Original array with items swapped _(or unchanged if unable to swap)_
|
|
16
16
|
*/
|
|
17
|
-
export function swap<Item extends PlainObject,
|
|
17
|
+
export function swap<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
18
18
|
array: Item[],
|
|
19
19
|
first: Item[],
|
|
20
20
|
second: Item[],
|
|
21
|
-
key:
|
|
21
|
+
key: ItemKey,
|
|
22
22
|
): Item[];
|
|
23
23
|
|
|
24
24
|
/**
|
|
@@ -59,11 +59,11 @@ export function swap<Item>(array: Item[], first: Item[], second: Item[]): Item[]
|
|
|
59
59
|
* @param key Key to get an item's value for matching
|
|
60
60
|
* @returns Original array with items swapped _(or unchanged if unable to swap)_
|
|
61
61
|
*/
|
|
62
|
-
export function swap<Item extends PlainObject,
|
|
62
|
+
export function swap<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
63
63
|
array: Item[],
|
|
64
64
|
first: Item,
|
|
65
65
|
second: Item,
|
|
66
|
-
key:
|
|
66
|
+
key: ItemKey,
|
|
67
67
|
): Item[];
|
|
68
68
|
|
|
69
69
|
/**
|
package/src/array/to-set.ts
CHANGED
|
@@ -20,10 +20,10 @@ export function toSet<Item, Callback extends (item: Item, index: number, array:
|
|
|
20
20
|
* @param key Key to use for value
|
|
21
21
|
* @returns Set of values
|
|
22
22
|
*/
|
|
23
|
-
export function toSet<Item extends PlainObject,
|
|
23
|
+
export function toSet<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
24
24
|
array: Item[],
|
|
25
|
-
key:
|
|
26
|
-
): Set<Item[
|
|
25
|
+
key: ItemKey,
|
|
26
|
+
): Set<Item[ItemKey]>;
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* Create a Set from an array of items
|
package/src/array/toggle.ts
CHANGED
|
@@ -21,10 +21,10 @@ export function toggle<Item>(
|
|
|
21
21
|
* @param key Key to find existing item
|
|
22
22
|
* @returns Original array
|
|
23
23
|
*/
|
|
24
|
-
export function toggle<Item extends PlainObject,
|
|
24
|
+
export function toggle<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
25
25
|
destination: Item[],
|
|
26
26
|
toggled: Item[],
|
|
27
|
-
key:
|
|
27
|
+
key: ItemKey,
|
|
28
28
|
): Item[];
|
|
29
29
|
|
|
30
30
|
/**
|
package/src/array/union.ts
CHANGED
|
@@ -23,8 +23,8 @@ export function union<First, Second>(
|
|
|
23
23
|
export function union<
|
|
24
24
|
First extends Record<string, unknown>,
|
|
25
25
|
Second extends Record<string, unknown>,
|
|
26
|
-
|
|
27
|
-
>(first: First[], second: Second[], key:
|
|
26
|
+
SharedKey extends keyof First & keyof Second,
|
|
27
|
+
>(first: First[], second: Second[], key: SharedKey): (First | Second)[];
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* Get the combined, unique values from two arrays
|
package/src/array/update.ts
CHANGED
|
@@ -21,10 +21,10 @@ export function update<Item>(
|
|
|
21
21
|
* @param key Key to find existing item
|
|
22
22
|
* @returns Original array
|
|
23
23
|
*/
|
|
24
|
-
export function update<Item extends PlainObject,
|
|
24
|
+
export function update<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
25
25
|
destination: Item[],
|
|
26
26
|
updated: Item[],
|
|
27
|
-
key:
|
|
27
|
+
key: ItemKey,
|
|
28
28
|
): Item[];
|
|
29
29
|
|
|
30
30
|
/**
|
package/src/index.ts
CHANGED
|
@@ -38,10 +38,19 @@ export * from './logger';
|
|
|
38
38
|
export * from './math';
|
|
39
39
|
export * from './models';
|
|
40
40
|
export * from './number';
|
|
41
|
+
export * from './promise/delay';
|
|
41
42
|
export * from './promise/index';
|
|
43
|
+
export * from './promise/misc';
|
|
44
|
+
export * from './promise/models';
|
|
45
|
+
export * from './promise/timed';
|
|
42
46
|
export * from './query';
|
|
43
47
|
export * from './queue';
|
|
44
48
|
export * from './random';
|
|
45
49
|
export * from './result/index';
|
|
50
|
+
export * from './result/match';
|
|
51
|
+
export * from './result/misc';
|
|
52
|
+
export * from './result/models';
|
|
53
|
+
export * from './result/work/flow';
|
|
54
|
+
export * from './result/work/pipe';
|
|
46
55
|
export * from './sized/map';
|
|
47
56
|
export * from './sized/set';
|
|
@@ -22,10 +22,10 @@ export function indexOf<
|
|
|
22
22
|
* @param value Value to match against
|
|
23
23
|
* @returns Index of the first matching item, or `-1` if no match is found
|
|
24
24
|
*/
|
|
25
|
-
export function indexOf<Item extends PlainObject,
|
|
25
|
+
export function indexOf<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
26
26
|
array: Item[],
|
|
27
|
-
key:
|
|
28
|
-
value: Item[
|
|
27
|
+
key: ItemKey,
|
|
28
|
+
value: Item[ItemKey],
|
|
29
29
|
): number;
|
|
30
30
|
|
|
31
31
|
/**
|
|
@@ -81,9 +81,9 @@ export function max<Item>(
|
|
|
81
81
|
* @param key Key to use for value
|
|
82
82
|
* @returns Maximum value, or `NaN` if no maximum can be found
|
|
83
83
|
*/
|
|
84
|
-
export function max<Item extends PlainObject,
|
|
84
|
+
export function max<Item extends PlainObject, ItemKey extends keyof NumericalValues<Item>>(
|
|
85
85
|
items: Item[],
|
|
86
|
-
key:
|
|
86
|
+
key: ItemKey,
|
|
87
87
|
): number;
|
|
88
88
|
|
|
89
89
|
/**
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import type {PlainObject} from '../../models';
|
|
2
2
|
|
|
3
|
-
export function partial<Value extends object,
|
|
3
|
+
export function partial<Value extends object, ValueKey extends keyof Value>(
|
|
4
4
|
value: unknown,
|
|
5
|
-
keys:
|
|
5
|
+
keys: ValueKey[],
|
|
6
6
|
omit: true,
|
|
7
|
-
): Omit<Value,
|
|
7
|
+
): Omit<Value, ValueKey>;
|
|
8
8
|
|
|
9
|
-
export function partial<Value extends object,
|
|
9
|
+
export function partial<Value extends object, ValueKey extends keyof Value>(
|
|
10
10
|
value: unknown,
|
|
11
|
-
keys:
|
|
11
|
+
keys: ValueKey[],
|
|
12
12
|
omit: false,
|
|
13
|
-
): Pick<Value,
|
|
13
|
+
): Pick<Value, ValueKey>;
|
|
14
14
|
|
|
15
|
-
export function partial<Value extends object,
|
|
15
|
+
export function partial<Value extends object, ValueKey extends keyof Value>(
|
|
16
16
|
value: unknown,
|
|
17
|
-
providedKeys:
|
|
17
|
+
providedKeys: ValueKey[],
|
|
18
18
|
omit: boolean,
|
|
19
19
|
): Partial<Value> {
|
|
20
20
|
if (typeof value !== 'object' || value === null) {
|
|
@@ -37,7 +37,7 @@ export function partial<Value extends object, Key extends keyof Value>(
|
|
|
37
37
|
continue;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
if (omit ? !providedKeys.includes(key as
|
|
40
|
+
if (omit ? !providedKeys.includes(key as ValueKey) : true) {
|
|
41
41
|
(partials as PlainObject)[key] = (value as PlainObject)[key];
|
|
42
42
|
}
|
|
43
43
|
}
|
package/src/math.ts
CHANGED
|
@@ -76,10 +76,10 @@ export function count<Item>(
|
|
|
76
76
|
* @param value Value to match and count
|
|
77
77
|
* @returns Number of items with the specified key value, or `NaN` if no count can be calculated
|
|
78
78
|
*/
|
|
79
|
-
export function count<Item extends PlainObject,
|
|
79
|
+
export function count<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
80
80
|
array: Item[],
|
|
81
|
-
key:
|
|
82
|
-
value: Item[
|
|
81
|
+
key: ItemKey,
|
|
82
|
+
value: Item[ItemKey],
|
|
83
83
|
): number;
|
|
84
84
|
|
|
85
85
|
/**
|
package/src/models.ts
CHANGED
|
@@ -50,8 +50,8 @@ export type GenericCallback = (...args: any[]) => any;
|
|
|
50
50
|
*/
|
|
51
51
|
export type Key = number | string;
|
|
52
52
|
|
|
53
|
-
export type KeyedValue<Item,
|
|
54
|
-
? Item[
|
|
53
|
+
export type KeyedValue<Item, ItemKey extends keyof Item> = Item[ItemKey] extends PropertyKey
|
|
54
|
+
? Item[ItemKey]
|
|
55
55
|
: never;
|
|
56
56
|
|
|
57
57
|
/**
|
|
@@ -71,20 +71,24 @@ type _NestedKeys<Value, Depth extends number = 5> = Depth extends 0
|
|
|
71
71
|
? Value extends readonly [any, ...any]
|
|
72
72
|
? // Tuple: extract actual indices
|
|
73
73
|
{
|
|
74
|
-
[
|
|
75
|
-
? NonNullable<Value[
|
|
76
|
-
?
|
|
77
|
-
|
|
74
|
+
[ItemKey in keyof Value]-?: ItemKey extends `${number}`
|
|
75
|
+
? NonNullable<Value[ItemKey]> extends readonly any[] | PlainObject
|
|
76
|
+
?
|
|
77
|
+
| `${ItemKey}`
|
|
78
|
+
| `${ItemKey}.${_NestedKeys<NonNullable<Value[ItemKey]>, SubtractDepth<Depth>>}`
|
|
79
|
+
: `${ItemKey}`
|
|
78
80
|
: never;
|
|
79
81
|
}[number]
|
|
80
82
|
: // Array: use no indices
|
|
81
83
|
never
|
|
82
84
|
: Value extends PlainObject
|
|
83
85
|
? {
|
|
84
|
-
[
|
|
85
|
-
? NonNullable<Value[
|
|
86
|
-
?
|
|
87
|
-
|
|
86
|
+
[ItemKey in keyof Value]-?: ItemKey extends number | string
|
|
87
|
+
? NonNullable<Value[ItemKey]> extends readonly any[] | PlainObject
|
|
88
|
+
?
|
|
89
|
+
| `${ItemKey}`
|
|
90
|
+
| `${ItemKey}.${_NestedKeys<NonNullable<Value[ItemKey]>, SubtractDepth<Depth>>}`
|
|
91
|
+
: `${ItemKey}`
|
|
88
92
|
: never;
|
|
89
93
|
}[keyof Value]
|
|
90
94
|
: never;
|
|
@@ -93,7 +97,9 @@ type _NestedKeys<Value, Depth extends number = 5> = Depth extends 0
|
|
|
93
97
|
* An extended version of `Partial` that allows for nested properties to be optional
|
|
94
98
|
*/
|
|
95
99
|
export type NestedPartial<Value> = {
|
|
96
|
-
[
|
|
100
|
+
[ItemKey in keyof Value]?: Value[ItemKey] extends object
|
|
101
|
+
? NestedPartial<Value[ItemKey]>
|
|
102
|
+
: Value[ItemKey];
|
|
97
103
|
};
|
|
98
104
|
|
|
99
105
|
/**
|
|
@@ -101,12 +107,12 @@ export type NestedPartial<Value> = {
|
|
|
101
107
|
*/
|
|
102
108
|
export type NestedValue<Value extends PlainObject, Path extends string> = _NestedValue<Value, Path>;
|
|
103
109
|
|
|
104
|
-
type _NestedValue<Value, Path extends string> = Path extends `${infer
|
|
105
|
-
?
|
|
106
|
-
? undefined extends Value[
|
|
107
|
-
? _NestedValue<Exclude<Value[
|
|
108
|
-
: _NestedValue<Value[
|
|
109
|
-
:
|
|
110
|
+
type _NestedValue<Value, Path extends string> = Path extends `${infer ItemKey}.${infer Rest}`
|
|
111
|
+
? ItemKey extends keyof Value
|
|
112
|
+
? undefined extends Value[ItemKey]
|
|
113
|
+
? _NestedValue<Exclude<Value[ItemKey], undefined>, Rest> | undefined
|
|
114
|
+
: _NestedValue<Value[ItemKey], Rest>
|
|
115
|
+
: ItemKey extends `${number}`
|
|
110
116
|
? Value extends readonly any[]
|
|
111
117
|
? _NestedValue<Value[number], Rest>
|
|
112
118
|
: never
|
|
@@ -130,14 +136,18 @@ export type NestedValues<Value extends PlainObject> = {
|
|
|
130
136
|
* The numerical keys of an object
|
|
131
137
|
*/
|
|
132
138
|
export type NumericalKeys<Value> = {
|
|
133
|
-
[
|
|
139
|
+
[ItemKey in keyof Value]: ItemKey extends number
|
|
140
|
+
? ItemKey
|
|
141
|
+
: ItemKey extends `${number}`
|
|
142
|
+
? ItemKey
|
|
143
|
+
: never;
|
|
134
144
|
}[keyof Value];
|
|
135
145
|
|
|
136
146
|
/**
|
|
137
147
|
* The numerical values of an object
|
|
138
148
|
*/
|
|
139
149
|
export type NumericalValues<Item extends PlainObject> = {
|
|
140
|
-
[
|
|
150
|
+
[ItemKey in keyof Item as Item[ItemKey] extends number ? ItemKey : never]: Item[ItemKey];
|
|
141
151
|
};
|
|
142
152
|
|
|
143
153
|
/**
|
|
@@ -200,7 +210,7 @@ export type RequiredKeys<Model extends object, Keys extends keyof Model> = Requi
|
|
|
200
210
|
*
|
|
201
211
|
* _(Thanks, type-fest!)_
|
|
202
212
|
*/
|
|
203
|
-
export type Simplify<Value> = {[
|
|
213
|
+
export type Simplify<Value> = {[ValueKey in keyof Value]: Value[ValueKey]} & {};
|
|
204
214
|
|
|
205
215
|
type SubtractDepth<Value extends number> = Value extends 5
|
|
206
216
|
? 4
|
package/src/promise/index.ts
CHANGED
|
@@ -283,25 +283,3 @@ async function resultPromises(
|
|
|
283
283
|
}
|
|
284
284
|
|
|
285
285
|
// #endregion
|
|
286
|
-
|
|
287
|
-
// #region Exports
|
|
288
|
-
|
|
289
|
-
export {toPromise as fromResult} from '../result/misc';
|
|
290
|
-
export {delay} from './delay';
|
|
291
|
-
export {isFulfilled, isRejected} from './helpers';
|
|
292
|
-
export {cancelable, toResult} from './misc';
|
|
293
|
-
export {
|
|
294
|
-
CancelablePromise,
|
|
295
|
-
PromiseTimeoutError,
|
|
296
|
-
type FulfilledPromise,
|
|
297
|
-
type PromiseOptions,
|
|
298
|
-
type PromisesOptions,
|
|
299
|
-
type PromisesResult,
|
|
300
|
-
type PromiseStrategy,
|
|
301
|
-
type PromisesValues as PromisesValue,
|
|
302
|
-
type PromisesValue as PromisesValueItem,
|
|
303
|
-
type RejectedPromise,
|
|
304
|
-
} from './models';
|
|
305
|
-
export {timed} from './timed';
|
|
306
|
-
|
|
307
|
-
// #endregion
|
package/src/promise/misc.ts
CHANGED
package/src/promise/models.ts
CHANGED
|
@@ -84,13 +84,13 @@ export class PromiseTimeoutError extends Error {
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
export type PromisesItems<Items extends unknown[]> = {
|
|
87
|
-
[
|
|
88
|
-
? ReturnType<Items[
|
|
87
|
+
[ItemsKey in keyof Items]: Items[ItemsKey] extends GenericCallback
|
|
88
|
+
? ReturnType<Items[ItemsKey]> extends Promise<infer Value>
|
|
89
89
|
? Promise<Value>
|
|
90
90
|
: never
|
|
91
|
-
: Items[
|
|
91
|
+
: Items[ItemsKey] extends Promise<infer Value>
|
|
92
92
|
? Promise<Value>
|
|
93
|
-
: Promise<Items[
|
|
93
|
+
: Promise<Items[ItemsKey]>;
|
|
94
94
|
};
|
|
95
95
|
|
|
96
96
|
export type PromisesOptions = {
|
|
@@ -99,15 +99,17 @@ export type PromisesOptions = {
|
|
|
99
99
|
};
|
|
100
100
|
|
|
101
101
|
export type PromisesResult<Items extends unknown[]> = {
|
|
102
|
-
[
|
|
102
|
+
[ItemsKey in keyof Items]: Items[ItemsKey] extends Promise<infer Value>
|
|
103
|
+
? Result<Awaited<Value>>
|
|
104
|
+
: never;
|
|
103
105
|
};
|
|
104
106
|
|
|
105
107
|
export type PromisesUnwrapped<Items extends unknown[]> = {
|
|
106
|
-
[
|
|
107
|
-
? ReturnType<Items[
|
|
108
|
+
[ItemsKey in keyof Items]: Items[ItemsKey] extends GenericCallback
|
|
109
|
+
? ReturnType<Items[ItemsKey]> extends Promise<infer Value>
|
|
108
110
|
? Awaited<Value>
|
|
109
111
|
: never
|
|
110
|
-
: Items[
|
|
112
|
+
: Items[ItemsKey] extends Promise<infer Value>
|
|
111
113
|
? Awaited<Value>
|
|
112
114
|
: never;
|
|
113
115
|
};
|
|
@@ -115,11 +117,11 @@ export type PromisesUnwrapped<Items extends unknown[]> = {
|
|
|
115
117
|
export type PromisesValue<Value> = FulfilledPromise<Value> | RejectedPromise;
|
|
116
118
|
|
|
117
119
|
export type PromisesValues<Items extends unknown[]> = {
|
|
118
|
-
[
|
|
119
|
-
? ReturnType<Items[
|
|
120
|
+
[ItemsKey in keyof Items]: Items[ItemsKey] extends GenericCallback
|
|
121
|
+
? ReturnType<Items[ItemsKey]> extends Promise<infer Value>
|
|
120
122
|
? PromisesValue<Awaited<Value>>
|
|
121
123
|
: never
|
|
122
|
-
: Items[
|
|
124
|
+
: Items[ItemsKey] extends Promise<infer Value>
|
|
123
125
|
? PromisesValue<Awaited<Value>>
|
|
124
126
|
: never;
|
|
125
127
|
};
|
package/src/result/index.ts
CHANGED
|
@@ -95,12 +95,3 @@ attempt.pipe = attemptPipe;
|
|
|
95
95
|
attempt.promise = attemptPromise;
|
|
96
96
|
|
|
97
97
|
// #endregion
|
|
98
|
-
|
|
99
|
-
// #region Exports
|
|
100
|
-
|
|
101
|
-
export {isError, isOk, isResult} from '../internal/result';
|
|
102
|
-
export {toResult as fromPromise} from '../promise/misc';
|
|
103
|
-
export {error, ok, toPromise, unwrap} from './misc';
|
|
104
|
-
export type {Err, ExtendedErr, ExtendedResult, Ok, Result} from './models';
|
|
105
|
-
|
|
106
|
-
// #endregion
|
package/src/result/misc.ts
CHANGED
|
@@ -113,3 +113,9 @@ export function unwrap(value: unknown, defaultValue: unknown): unknown {
|
|
|
113
113
|
const MESSAGE_PROMISE_RESULT = 'toPromise expected to receive a Result';
|
|
114
114
|
|
|
115
115
|
// #endregion
|
|
116
|
+
|
|
117
|
+
// #region Exports
|
|
118
|
+
|
|
119
|
+
export {isError, isOk, isResult} from '../internal/result';
|
|
120
|
+
|
|
121
|
+
// #endregion
|
package/src/sized/map.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {getSizedMaximum} from '../internal/sized';
|
|
|
7
7
|
*
|
|
8
8
|
* Behavior is similar to a _LRU_-cache, where the least recently used entries are removed
|
|
9
9
|
*/
|
|
10
|
-
export class SizedMap<
|
|
10
|
+
export class SizedMap<SizedKey = unknown, SizedValue = unknown> extends Map<SizedKey, SizedValue> {
|
|
11
11
|
/**
|
|
12
12
|
* The maximum size of the Map
|
|
13
13
|
*/
|
|
@@ -27,16 +27,16 @@ export class SizedMap<Key = unknown, Value = unknown> extends Map<Key, Value> {
|
|
|
27
27
|
/**
|
|
28
28
|
* Create a new SizedMap with entries and a maximum size _(2^20)_
|
|
29
29
|
* @param entries Array of key-value pairs to initialize the SizedMap with
|
|
30
|
-
* @template
|
|
31
|
-
* @template
|
|
30
|
+
* @template SizedKey Type of the keys in the SizedMap
|
|
31
|
+
* @template SizedValue Type of the values in the SizedMap
|
|
32
32
|
*/
|
|
33
|
-
constructor(entries: [
|
|
33
|
+
constructor(entries: [SizedKey, SizedValue][]);
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* Create a new SizedMap with a maximum size _(but clamped at 2^24)_
|
|
37
37
|
* @param maximum Maximum size of the SizedMap
|
|
38
|
-
* @template
|
|
39
|
-
* @template
|
|
38
|
+
* @template SizedKey Type of the keys in the SizedMap
|
|
39
|
+
* @template SizedValue Type of the values in the SizedMap
|
|
40
40
|
*/
|
|
41
41
|
constructor(maximum: number);
|
|
42
42
|
|
|
@@ -44,12 +44,12 @@ export class SizedMap<Key = unknown, Value = unknown> extends Map<Key, Value> {
|
|
|
44
44
|
* Create a new SizedMap with _(optional)_ entries and a maximum size _(defaults to 2^20; clamped at 2^24)_
|
|
45
45
|
* @param entries Array of key-value pairs to initialize the SizedMap with
|
|
46
46
|
* @param maximum Maximum size of the SizedMap
|
|
47
|
-
* @template
|
|
48
|
-
* @template
|
|
47
|
+
* @template SizedKey Type of the keys in the SizedMap
|
|
48
|
+
* @template SizedValue Type of the values in the SizedMap
|
|
49
49
|
*/
|
|
50
|
-
constructor(entries?: [
|
|
50
|
+
constructor(entries?: [SizedKey, SizedValue][], maximum?: number);
|
|
51
51
|
|
|
52
|
-
constructor(first?: [
|
|
52
|
+
constructor(first?: [SizedKey, SizedValue][] | number, second?: number) {
|
|
53
53
|
const maximum = getSizedMaximum(first, second);
|
|
54
54
|
|
|
55
55
|
super();
|
|
@@ -74,11 +74,11 @@ export class SizedMap<Key = unknown, Value = unknown> extends Map<Key, Value> {
|
|
|
74
74
|
/**
|
|
75
75
|
* @inheritdoc
|
|
76
76
|
*/
|
|
77
|
-
override get(key:
|
|
77
|
+
override get(key: SizedKey): SizedValue | undefined {
|
|
78
78
|
const value = super.get(key);
|
|
79
79
|
|
|
80
80
|
if (value !== undefined || this.has(key)) {
|
|
81
|
-
this.set(key, value as
|
|
81
|
+
this.set(key, value as SizedValue);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
return value;
|
|
@@ -87,11 +87,11 @@ export class SizedMap<Key = unknown, Value = unknown> extends Map<Key, Value> {
|
|
|
87
87
|
/**
|
|
88
88
|
* @inheritdoc
|
|
89
89
|
*/
|
|
90
|
-
override set(key:
|
|
90
|
+
override set(key: SizedKey, value: SizedValue): this {
|
|
91
91
|
if (this.has(key)) {
|
|
92
92
|
this.delete(key);
|
|
93
93
|
} else if (this.size >= this.#maximumSize) {
|
|
94
|
-
this.delete(this.keys().next().value as
|
|
94
|
+
this.delete(this.keys().next().value as SizedKey);
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
return super.set(key, value);
|
package/src/value/omit.ts
CHANGED
|
@@ -9,10 +9,10 @@ import type {PlainObject} from '../models';
|
|
|
9
9
|
* @param keys Keys to omit
|
|
10
10
|
* @returns Partial object without the specified keys
|
|
11
11
|
*/
|
|
12
|
-
export function omit<Value extends PlainObject,
|
|
12
|
+
export function omit<Value extends PlainObject, ValueKey extends keyof Value>(
|
|
13
13
|
value: Value,
|
|
14
|
-
keys:
|
|
15
|
-
): Omit<Value,
|
|
14
|
+
keys: ValueKey[],
|
|
15
|
+
): Omit<Value, ValueKey> {
|
|
16
16
|
return partial(value, keys, true);
|
|
17
17
|
}
|
|
18
18
|
|
package/src/value/pick.ts
CHANGED
|
@@ -9,10 +9,10 @@ import type {PlainObject} from '../models';
|
|
|
9
9
|
* @param keys Keys to use
|
|
10
10
|
* @returns Partial object with only the specified keys
|
|
11
11
|
*/
|
|
12
|
-
export function pick<Value extends PlainObject,
|
|
12
|
+
export function pick<Value extends PlainObject, ValueKey extends keyof Value>(
|
|
13
13
|
value: Value,
|
|
14
|
-
keys:
|
|
15
|
-
): Pick<Value,
|
|
14
|
+
keys: ValueKey[],
|
|
15
|
+
): Pick<Value, ValueKey> {
|
|
16
16
|
return partial(value, keys, false);
|
|
17
17
|
}
|
|
18
18
|
|
package/src/value/smush.ts
CHANGED
|
@@ -12,7 +12,7 @@ import type {
|
|
|
12
12
|
// #region Types
|
|
13
13
|
|
|
14
14
|
export type Smushed<Value extends PlainObject> = Simplify<{
|
|
15
|
-
[
|
|
15
|
+
[NestedKey in NestedKeys<Value>]: NestedValue<Value, ToString<NestedKey>>;
|
|
16
16
|
}>;
|
|
17
17
|
|
|
18
18
|
// #endregion
|
package/src/value/unsmush.ts
CHANGED