@tstdl/base 0.91.0-beta9 → 0.91.1
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/enumerable/async-enumerable.d.ts +5 -1
- package/enumerable/async-enumerable.js +8 -8
- package/enumerable/enumerable.d.ts +5 -1
- package/enumerable/enumerable.js +8 -8
- package/intl/number-parser.d.ts +1 -1
- package/object-storage/s3/s3.object-storage-provider.d.ts +6 -6
- package/object-storage/s3/s3.object-storage-provider.js +6 -6
- package/package.json +5 -5
- package/schema/schema.d.ts +3 -2
- package/schema/schemas/array.js +10 -8
- package/schema/schemas/object.d.ts +19 -11
- package/schema/schemas/optional.d.ts +3 -2
- package/utils/async-iterable-helpers/group-single.d.ts +2 -1
- package/utils/async-iterable-helpers/group-single.js +2 -2
- package/utils/async-iterable-helpers/group-to-map.d.ts +2 -1
- package/utils/async-iterable-helpers/group-to-map.js +44 -17
- package/utils/async-iterable-helpers/group-to-single-map.d.ts +2 -1
- package/utils/async-iterable-helpers/group-to-single-map.js +44 -17
- package/utils/async-iterable-helpers/group.d.ts +2 -1
- package/utils/async-iterable-helpers/group.js +2 -2
- package/utils/async-iterable-helpers/types.d.ts +3 -0
- package/utils/iterable-helpers/group-single.d.ts +2 -1
- package/utils/iterable-helpers/group-single.js +2 -2
- package/utils/iterable-helpers/group-to-map.d.ts +2 -1
- package/utils/iterable-helpers/group-to-map.js +21 -7
- package/utils/iterable-helpers/group-to-single-map.d.ts +2 -1
- package/utils/iterable-helpers/group-to-single-map.js +21 -7
- package/utils/iterable-helpers/group.d.ts +2 -1
- package/utils/iterable-helpers/group.js +2 -2
- package/utils/iterable-helpers/types.d.ts +3 -0
- package/schema-old/array-constraints/index.d.ts +0 -2
- package/schema-old/array-constraints/index.js +0 -2
- package/schema-old/array-constraints/maximum-length.d.ts +0 -11
- package/schema-old/array-constraints/maximum-length.js +0 -22
- package/schema-old/array-constraints/minimum-length.d.ts +0 -11
- package/schema-old/array-constraints/minimum-length.js +0 -22
- package/schema-old/coercers/boolean.coercer.d.ts +0 -9
- package/schema-old/coercers/boolean.coercer.js +0 -27
- package/schema-old/coercers/date.coercer.d.ts +0 -9
- package/schema-old/coercers/date.coercer.js +0 -16
- package/schema-old/coercers/index.d.ts +0 -6
- package/schema-old/coercers/index.js +0 -6
- package/schema-old/coercers/number.coercer.d.ts +0 -9
- package/schema-old/coercers/number.coercer.js +0 -14
- package/schema-old/coercers/regexp.coercer.d.ts +0 -11
- package/schema-old/coercers/regexp.coercer.js +0 -20
- package/schema-old/coercers/string.coercer.d.ts +0 -9
- package/schema-old/coercers/string.coercer.js +0 -14
- package/schema-old/coercers/uint8-array.coercer.d.ts +0 -11
- package/schema-old/coercers/uint8-array.coercer.js +0 -22
- package/schema-old/constraints/enumeration.d.ts +0 -13
- package/schema-old/constraints/enumeration.js +0 -29
- package/schema-old/constraints/generic.d.ts +0 -20
- package/schema-old/constraints/generic.js +0 -23
- package/schema-old/constraints/index.d.ts +0 -12
- package/schema-old/constraints/index.js +0 -12
- package/schema-old/constraints/integer.d.ts +0 -12
- package/schema-old/constraints/integer.js +0 -23
- package/schema-old/constraints/length.d.ts +0 -6
- package/schema-old/constraints/length.js +0 -15
- package/schema-old/constraints/literal.d.ts +0 -10
- package/schema-old/constraints/literal.js +0 -24
- package/schema-old/constraints/maximum-date.d.ts +0 -12
- package/schema-old/constraints/maximum-date.js +0 -26
- package/schema-old/constraints/maximum-length.d.ts +0 -12
- package/schema-old/constraints/maximum-length.js +0 -25
- package/schema-old/constraints/maximum.d.ts +0 -12
- package/schema-old/constraints/maximum.js +0 -24
- package/schema-old/constraints/minimum-date.d.ts +0 -12
- package/schema-old/constraints/minimum-date.js +0 -26
- package/schema-old/constraints/minimum-length.d.ts +0 -12
- package/schema-old/constraints/minimum-length.js +0 -25
- package/schema-old/constraints/minimum.d.ts +0 -12
- package/schema-old/constraints/minimum.js +0 -24
- package/schema-old/constraints/pattern.d.ts +0 -13
- package/schema-old/constraints/pattern.js +0 -26
- package/schema-old/decorators/class.d.ts +0 -3
- package/schema-old/decorators/class.js +0 -5
- package/schema-old/decorators/coerce.d.ts +0 -2
- package/schema-old/decorators/coerce.js +0 -5
- package/schema-old/decorators/constraint.d.ts +0 -4
- package/schema-old/decorators/constraint.js +0 -7
- package/schema-old/decorators/index.d.ts +0 -6
- package/schema-old/decorators/index.js +0 -6
- package/schema-old/decorators/property.d.ts +0 -6
- package/schema-old/decorators/property.js +0 -17
- package/schema-old/decorators/types.d.ts +0 -19
- package/schema-old/decorators/types.js +0 -1
- package/schema-old/decorators/utils.d.ts +0 -15
- package/schema-old/decorators/utils.js +0 -48
- package/schema-old/index.d.ts +0 -10
- package/schema-old/index.js +0 -10
- package/schema-old/schema.d.ts +0 -15
- package/schema-old/schema.error.d.ts +0 -26
- package/schema-old/schema.error.js +0 -64
- package/schema-old/schema.js +0 -283
- package/schema-old/schemas/any.d.ts +0 -5
- package/schema-old/schemas/any.js +0 -9
- package/schema-old/schemas/array.d.ts +0 -12
- package/schema-old/schemas/array.js +0 -23
- package/schema-old/schemas/assign.d.ts +0 -7
- package/schema-old/schemas/assign.js +0 -24
- package/schema-old/schemas/boolean.d.ts +0 -5
- package/schema-old/schemas/boolean.js +0 -9
- package/schema-old/schemas/constraint.d.ts +0 -5
- package/schema-old/schemas/constraint.js +0 -7
- package/schema-old/schemas/date.d.ts +0 -8
- package/schema-old/schemas/date.js +0 -22
- package/schema-old/schemas/defaulted.d.ts +0 -6
- package/schema-old/schemas/defaulted.js +0 -10
- package/schema-old/schemas/enumeration.d.ts +0 -6
- package/schema-old/schemas/enumeration.js +0 -17
- package/schema-old/schemas/index.d.ts +0 -26
- package/schema-old/schemas/index.js +0 -26
- package/schema-old/schemas/instance.d.ts +0 -3
- package/schema-old/schemas/instance.js +0 -5
- package/schema-old/schemas/literal.d.ts +0 -5
- package/schema-old/schemas/literal.js +0 -17
- package/schema-old/schemas/nullable.d.ts +0 -6
- package/schema-old/schemas/nullable.js +0 -9
- package/schema-old/schemas/number.d.ts +0 -9
- package/schema-old/schemas/number.js +0 -27
- package/schema-old/schemas/object.d.ts +0 -7
- package/schema-old/schemas/object.js +0 -12
- package/schema-old/schemas/omit.d.ts +0 -3
- package/schema-old/schemas/omit.js +0 -15
- package/schema-old/schemas/one-or-many.d.ts +0 -9
- package/schema-old/schemas/one-or-many.js +0 -15
- package/schema-old/schemas/optional.d.ts +0 -7
- package/schema-old/schemas/optional.js +0 -8
- package/schema-old/schemas/partial.d.ts +0 -4
- package/schema-old/schemas/partial.js +0 -17
- package/schema-old/schemas/pick.d.ts +0 -3
- package/schema-old/schemas/pick.js +0 -15
- package/schema-old/schemas/readable-stream.d.ts +0 -6
- package/schema-old/schemas/readable-stream.js +0 -9
- package/schema-old/schemas/record.d.ts +0 -5
- package/schema-old/schemas/record.js +0 -10
- package/schema-old/schemas/regexp.d.ts +0 -6
- package/schema-old/schemas/regexp.js +0 -9
- package/schema-old/schemas/string.d.ts +0 -22
- package/schema-old/schemas/string.js +0 -38
- package/schema-old/schemas/transform.d.ts +0 -5
- package/schema-old/schemas/transform.js +0 -7
- package/schema-old/schemas/uint8-array.d.ts +0 -10
- package/schema-old/schemas/uint8-array.js +0 -29
- package/schema-old/schemas/union.d.ts +0 -7
- package/schema-old/schemas/union.js +0 -13
- package/schema-old/schemas/unknown.d.ts +0 -5
- package/schema-old/schemas/unknown.js +0 -9
- package/schema-old/transformers/generic.d.ts +0 -12
- package/schema-old/transformers/generic.js +0 -18
- package/schema-old/transformers/index.d.ts +0 -4
- package/schema-old/transformers/index.js +0 -4
- package/schema-old/transformers/lowercase.d.ts +0 -8
- package/schema-old/transformers/lowercase.js +0 -12
- package/schema-old/transformers/trim.d.ts +0 -8
- package/schema-old/transformers/trim.js +0 -12
- package/schema-old/transformers/uppercase.d.ts +0 -8
- package/schema-old/transformers/uppercase.js +0 -12
- package/schema-old/types/index.d.ts +0 -5
- package/schema-old/types/index.js +0 -5
- package/schema-old/types/schema-array-constraint.d.ts +0 -5
- package/schema-old/types/schema-array-constraint.js +0 -2
- package/schema-old/types/schema-value-coercer.d.ts +0 -8
- package/schema-old/types/schema-value-coercer.js +0 -2
- package/schema-old/types/schema-value-constraint.d.ts +0 -8
- package/schema-old/types/schema-value-constraint.js +0 -2
- package/schema-old/types/schema-value-transformer.d.ts +0 -7
- package/schema-old/types/schema-value-transformer.js +0 -2
- package/schema-old/types/types.d.ts +0 -175
- package/schema-old/types/types.js +0 -172
- package/schema-old/utils/index.d.ts +0 -2
- package/schema-old/utils/index.js +0 -2
- package/schema-old/utils/schema.d.ts +0 -18
- package/schema-old/utils/schema.js +0 -139
- package/schema-old/utils/value-type.d.ts +0 -8
- package/schema-old/utils/value-type.js +0 -56
|
@@ -2,7 +2,7 @@ import type { CancellationSignal } from '../cancellation/token.js';
|
|
|
2
2
|
import type { AnyIterable } from '../utils/any-iterable-iterator.js';
|
|
3
3
|
import type { AsyncComparator } from '../utils/sort.js';
|
|
4
4
|
import type { Observable } from 'rxjs';
|
|
5
|
-
import type { AsyncIteratorFunction, AsyncPredicate, AsyncReducer, AsyncRetryPredicate, ParallelizableIteratorFunction, ParallelizablePredicate, ThrottleFunction } from '../utils/async-iterable-helpers/index.js';
|
|
5
|
+
import type { AsyncGroupSelectors, AsyncIteratorFunction, AsyncPredicate, AsyncReducer, AsyncRetryPredicate, ParallelizableIteratorFunction, ParallelizablePredicate, ThrottleFunction } from '../utils/async-iterable-helpers/index.js';
|
|
6
6
|
import type { IterableItemMetadata, TypePredicate } from '../utils/iterable-helpers/index.js';
|
|
7
7
|
import type { EnumerableMethods } from './enumerable-methods.js';
|
|
8
8
|
import { Enumerable } from './enumerable.js';
|
|
@@ -33,9 +33,13 @@ export declare class AsyncEnumerable<T> implements EnumerableMethods, AsyncItera
|
|
|
33
33
|
forceCast<TNew>(): AsyncEnumerable<TNew>;
|
|
34
34
|
forEach(func: AsyncIteratorFunction<T, any>): Promise<void>;
|
|
35
35
|
group<TGroup>(selector: AsyncIteratorFunction<T, TGroup>): AsyncEnumerable<[TGroup, T[]]>;
|
|
36
|
+
group<TGroup extends [any, ...any[]]>(...selectors: AsyncGroupSelectors<T, TGroup>): AsyncEnumerable<[TGroup['length'] extends 1 ? TGroup[0] : TGroup, T[]]>;
|
|
36
37
|
groupSingle<TGroup>(selector: AsyncIteratorFunction<T, TGroup>): AsyncEnumerable<[TGroup, T]>;
|
|
38
|
+
groupSingle<TGroup extends [any, ...any[]]>(...selectors: AsyncGroupSelectors<T, TGroup>): AsyncEnumerable<[TGroup['length'] extends 1 ? TGroup[0] : TGroup, T]>;
|
|
37
39
|
groupToMap<TGroup>(selector: AsyncIteratorFunction<T, TGroup>): Promise<Map<TGroup, T[]>>;
|
|
40
|
+
groupToMap<TGroup extends [any, ...any[]]>(...selectors: AsyncGroupSelectors<T, TGroup>): Promise<Map<TGroup['length'] extends 1 ? TGroup[0] : TGroup, T[]>>;
|
|
38
41
|
groupToSingleMap<TGroup>(selector: AsyncIteratorFunction<T, TGroup>): Promise<Map<TGroup, T>>;
|
|
42
|
+
groupToSingleMap<TGroup extends [any, ...any[]]>(...selectors: AsyncGroupSelectors<T, TGroup>): Promise<Map<TGroup['length'] extends 1 ? TGroup[0] : TGroup, T>>;
|
|
39
43
|
tap(tapper: AsyncIteratorFunction<T, any>): AsyncEnumerable<T>;
|
|
40
44
|
interruptEvery(value: number): AsyncEnumerable<T>;
|
|
41
45
|
interruptPerSecond(value: number): AsyncEnumerable<T>;
|
|
@@ -91,19 +91,19 @@ export class AsyncEnumerable {
|
|
|
91
91
|
async forEach(func) {
|
|
92
92
|
await forEachAsync(this.source, func);
|
|
93
93
|
}
|
|
94
|
-
group(
|
|
95
|
-
const grouped = groupAsync(this.source,
|
|
94
|
+
group(...selectors) {
|
|
95
|
+
const grouped = groupAsync(this.source, ...selectors);
|
|
96
96
|
return new AsyncEnumerable(grouped);
|
|
97
97
|
}
|
|
98
|
-
groupSingle(
|
|
99
|
-
const grouped = groupSingleAsync(this.source,
|
|
98
|
+
groupSingle(...selectors) {
|
|
99
|
+
const grouped = groupSingleAsync(this.source, ...selectors);
|
|
100
100
|
return new AsyncEnumerable(grouped);
|
|
101
101
|
}
|
|
102
|
-
async groupToMap(
|
|
103
|
-
return groupToMapAsync(this.source,
|
|
102
|
+
async groupToMap(...selectors) {
|
|
103
|
+
return groupToMapAsync(this.source, ...selectors);
|
|
104
104
|
}
|
|
105
|
-
async groupToSingleMap(
|
|
106
|
-
return groupToSingleMapAsync(this.source,
|
|
105
|
+
async groupToSingleMap(...selectors) {
|
|
106
|
+
return groupToSingleMapAsync(this.source, ...selectors);
|
|
107
107
|
}
|
|
108
108
|
tap(tapper) {
|
|
109
109
|
const iterator = tapAsync(this.source, tapper);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CancellationSignal } from '../cancellation/token.js';
|
|
2
2
|
import type { Comparator } from '../utils/sort.js';
|
|
3
|
-
import type { IterableItemMetadata, IteratorFunction, Predicate, Reducer, TypePredicate } from '../utils/iterable-helpers/index.js';
|
|
3
|
+
import type { GroupSelectors, IterableItemMetadata, IteratorFunction, Predicate, Reducer, TypePredicate } from '../utils/iterable-helpers/index.js';
|
|
4
4
|
import { AsyncEnumerable } from './async-enumerable.js';
|
|
5
5
|
import type { EnumerableMethods } from './enumerable-methods.js';
|
|
6
6
|
export declare class Enumerable<T> implements EnumerableMethods, Iterable<T> {
|
|
@@ -28,9 +28,13 @@ export declare class Enumerable<T> implements EnumerableMethods, Iterable<T> {
|
|
|
28
28
|
forEach(func: IteratorFunction<T, void>): void;
|
|
29
29
|
forceCast<TNew>(): Enumerable<TNew>;
|
|
30
30
|
group<TGroup>(selector: IteratorFunction<T, TGroup>): Enumerable<[TGroup, T[]]>;
|
|
31
|
+
group<TGroup extends [any, ...any[]]>(...selectors: GroupSelectors<T, TGroup>): Enumerable<[TGroup['length'] extends 1 ? TGroup[0] : TGroup, T[]]>;
|
|
31
32
|
groupSingle<TGroup>(selector: IteratorFunction<T, TGroup>): Enumerable<[TGroup, T]>;
|
|
33
|
+
groupSingle<TGroup extends [any, ...any[]]>(...selectors: GroupSelectors<T, TGroup>): Enumerable<[TGroup['length'] extends 1 ? TGroup[0] : TGroup, T]>;
|
|
32
34
|
groupToMap<TGroup>(selector: IteratorFunction<T, TGroup>): Map<TGroup, T[]>;
|
|
35
|
+
groupToMap<TGroup extends [any, ...any[]]>(...selectors: GroupSelectors<T, TGroup>): Map<TGroup['length'] extends 1 ? TGroup[0] : TGroup, T[]>;
|
|
33
36
|
groupToSingleMap<TGroup>(selector: IteratorFunction<T, TGroup>): Map<TGroup, T>;
|
|
37
|
+
groupToSingleMap<TGroup extends [any, ...any[]]>(...selectors: GroupSelectors<T, TGroup>): Map<TGroup['length'] extends 1 ? TGroup[0] : TGroup, T>;
|
|
34
38
|
tap(tapper: IteratorFunction<T, any>): Enumerable<T>;
|
|
35
39
|
last<TPredicate extends T = T>(predicate?: Predicate<T> | TypePredicate<T, TPredicate>): TPredicate;
|
|
36
40
|
lastOrDefault<D, TPredicate extends T = T>(defaultValue: D, predicate?: Predicate<T> | TypePredicate<T, TPredicate>): TPredicate | D;
|
package/enumerable/enumerable.js
CHANGED
|
@@ -79,19 +79,19 @@ export class Enumerable {
|
|
|
79
79
|
forceCast() {
|
|
80
80
|
return this;
|
|
81
81
|
}
|
|
82
|
-
group(
|
|
83
|
-
const grouped = group(this.source,
|
|
82
|
+
group(...selectors) {
|
|
83
|
+
const grouped = group(this.source, ...selectors);
|
|
84
84
|
return new Enumerable(grouped);
|
|
85
85
|
}
|
|
86
|
-
groupSingle(
|
|
87
|
-
const grouped = groupSingle(this.source,
|
|
86
|
+
groupSingle(...selectors) {
|
|
87
|
+
const grouped = groupSingle(this.source, ...selectors);
|
|
88
88
|
return new Enumerable(grouped);
|
|
89
89
|
}
|
|
90
|
-
groupToMap(
|
|
91
|
-
return groupToMap(this.source,
|
|
90
|
+
groupToMap(...selectors) {
|
|
91
|
+
return groupToMap(this.source, ...selectors);
|
|
92
92
|
}
|
|
93
|
-
groupToSingleMap(
|
|
94
|
-
return groupToSingleMap(this.source,
|
|
93
|
+
groupToSingleMap(...selectors) {
|
|
94
|
+
return groupToSingleMap(this.source, ...selectors);
|
|
95
95
|
}
|
|
96
96
|
tap(tapper) {
|
|
97
97
|
const iterator = tap(this.source, tapper);
|
package/intl/number-parser.d.ts
CHANGED
|
@@ -14,5 +14,5 @@ export declare class NumberParser {
|
|
|
14
14
|
*/
|
|
15
15
|
parse(value: string, loose?: boolean): number;
|
|
16
16
|
}
|
|
17
|
-
export declare const getNumberParser: (locale: string) =>
|
|
17
|
+
export declare const getNumberParser: (locale: string) => NumberParser;
|
|
18
18
|
export declare function parseNumber(locale: string, value: string, loose?: boolean): number;
|
|
@@ -2,27 +2,27 @@ import { ObjectStorageProvider } from '../../object-storage/index.js';
|
|
|
2
2
|
import { S3ObjectStorage } from './s3.object-storage.js';
|
|
3
3
|
export declare class S3ObjectStorageProviderConfig {
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* S3 endpoint
|
|
6
6
|
*/
|
|
7
7
|
endpoint: string;
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* S3 bucket, use a single bucket for all modules (which will become transparent key prefixes)
|
|
10
10
|
*
|
|
11
11
|
* mutually exclusive with bucketPerModule
|
|
12
12
|
*/
|
|
13
13
|
bucket?: string;
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* Use an own bucket for every module
|
|
16
16
|
*
|
|
17
17
|
* mutually exclusive with bucket
|
|
18
18
|
*/
|
|
19
19
|
bucketPerModule?: boolean;
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
21
|
+
* S3 access key
|
|
22
22
|
*/
|
|
23
23
|
accessKey: string;
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
25
|
+
* S3 secret key
|
|
26
26
|
*/
|
|
27
27
|
secretKey: string;
|
|
28
28
|
}
|
|
@@ -34,7 +34,7 @@ export declare class S3ObjectStorageProvider extends ObjectStorageProvider<S3Obj
|
|
|
34
34
|
get(module: string): S3ObjectStorage;
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
37
|
+
* Configure s3 object storage provider
|
|
38
38
|
* @param config s3 config
|
|
39
39
|
* @param register whether to register for {@link ObjectStorage} and {@link ObjectStorageProvider}
|
|
40
40
|
*/
|
|
@@ -15,27 +15,27 @@ import { Client } from 'minio';
|
|
|
15
15
|
import { S3ObjectStorage } from './s3.object-storage.js';
|
|
16
16
|
export class S3ObjectStorageProviderConfig {
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
18
|
+
* S3 endpoint
|
|
19
19
|
*/
|
|
20
20
|
endpoint;
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* S3 bucket, use a single bucket for all modules (which will become transparent key prefixes)
|
|
23
23
|
*
|
|
24
24
|
* mutually exclusive with bucketPerModule
|
|
25
25
|
*/
|
|
26
26
|
bucket;
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
28
|
+
* Use an own bucket for every module
|
|
29
29
|
*
|
|
30
30
|
* mutually exclusive with bucket
|
|
31
31
|
*/
|
|
32
32
|
bucketPerModule;
|
|
33
33
|
/**
|
|
34
|
-
*
|
|
34
|
+
* S3 access key
|
|
35
35
|
*/
|
|
36
36
|
accessKey;
|
|
37
37
|
/**
|
|
38
|
-
*
|
|
38
|
+
* S3 secret key
|
|
39
39
|
*/
|
|
40
40
|
secretKey;
|
|
41
41
|
}
|
|
@@ -70,7 +70,7 @@ S3ObjectStorageProvider = __decorate([
|
|
|
70
70
|
], S3ObjectStorageProvider);
|
|
71
71
|
export { S3ObjectStorageProvider };
|
|
72
72
|
/**
|
|
73
|
-
*
|
|
73
|
+
* Configure s3 object storage provider
|
|
74
74
|
* @param config s3 config
|
|
75
75
|
* @param register whether to register for {@link ObjectStorage} and {@link ObjectStorageProvider}
|
|
76
76
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tstdl/base",
|
|
3
|
-
"version": "0.91.
|
|
3
|
+
"version": "0.91.1",
|
|
4
4
|
"author": "Patrick Hein",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -111,7 +111,7 @@
|
|
|
111
111
|
"luxon": "^3.4",
|
|
112
112
|
"reflect-metadata": "^0.2",
|
|
113
113
|
"rxjs": "^7.8",
|
|
114
|
-
"type-fest": "4.
|
|
114
|
+
"type-fest": "4.23"
|
|
115
115
|
},
|
|
116
116
|
"devDependencies": {
|
|
117
117
|
"@mxssfd/typedoc-theme": "1.1",
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
"@types/mjml": "4.7",
|
|
124
124
|
"@types/node": "20",
|
|
125
125
|
"@types/nodemailer": "6.4",
|
|
126
|
-
"@typescript-eslint/eslint-plugin": "7.
|
|
126
|
+
"@typescript-eslint/eslint-plugin": "7.17",
|
|
127
127
|
"concurrently": "8.2",
|
|
128
128
|
"eslint": "8.57",
|
|
129
129
|
"eslint-import-resolver-typescript": "3.6",
|
|
@@ -147,11 +147,11 @@
|
|
|
147
147
|
"koa": "^2.15",
|
|
148
148
|
"minio": "^8.0",
|
|
149
149
|
"mjml": "^4.15",
|
|
150
|
-
"mongodb": "^6.
|
|
150
|
+
"mongodb": "^6.8",
|
|
151
151
|
"nodemailer": "^6.9",
|
|
152
152
|
"pg": "^8.12",
|
|
153
153
|
"playwright": "^1.45",
|
|
154
|
-
"preact": "^10.
|
|
154
|
+
"preact": "^10.23",
|
|
155
155
|
"preact-render-to-string": "^6.5",
|
|
156
156
|
"undici": "^6.19",
|
|
157
157
|
"urlpattern-polyfill": "^10.0"
|
package/schema/schema.d.ts
CHANGED
|
@@ -19,10 +19,11 @@ export type SchemaTestResult<T> = {
|
|
|
19
19
|
error: SchemaError;
|
|
20
20
|
};
|
|
21
21
|
type NormalizePrimitiveToConstructor<T> = Or<IsEqual<T, string>, IsEqual<T, String>> extends true ? typeof String : Or<IsEqual<T, number>, IsEqual<T, Number>> extends true ? typeof Number : Or<IsEqual<T, boolean>, IsEqual<T, Boolean>> extends true ? typeof Boolean : Or<IsEqual<T, bigint>, IsEqual<T, BigInt>> extends true ? typeof BigInt : Or<IsEqual<T, symbol>, IsEqual<T, Symbol>> extends true ? typeof Symbol : never;
|
|
22
|
-
type NormalizeConstructorToPrimitve<T> = T extends String ? string : T extends Number ? number : T extends Boolean ? boolean : T extends BigInt ? bigint : T extends Symbol ? symbol : T;
|
|
23
22
|
export type SchemaTestable<T = unknown> = Schema<T> | AbstractConstructor<T> | NormalizePrimitiveToConstructor<T>;
|
|
24
|
-
export type SchemaOutput<T extends SchemaTestable> = T extends SchemaTestable<infer U> ?
|
|
23
|
+
export type SchemaOutput<T extends SchemaTestable> = T extends SchemaTestable<infer U> ? U : never;
|
|
24
|
+
export declare const OPTIONAL: unique symbol;
|
|
25
25
|
export declare abstract class Schema<T = unknown> {
|
|
26
|
+
readonly [OPTIONAL]: boolean;
|
|
26
27
|
/**
|
|
27
28
|
* Test an unknown value to see whether it corresponds to the schema.
|
|
28
29
|
* @param schema schema to test against
|
package/schema/schemas/array.js
CHANGED
|
@@ -11,16 +11,18 @@ export class ArraySchema extends Schema {
|
|
|
11
11
|
this.itemSchema = schemaTestableToSchema(itemSchema);
|
|
12
12
|
}
|
|
13
13
|
_test(value, path, options) {
|
|
14
|
-
if (isArray(value)) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
if (!isArray(value)) {
|
|
15
|
+
return { valid: false, error: SchemaError.expectedButGot('array', typeOf(value), path) };
|
|
16
|
+
}
|
|
17
|
+
const values = [];
|
|
18
|
+
for (let i = 0; i < value.length; i++) {
|
|
19
|
+
const result = this.itemSchema._test(value[i], path.add(i), options);
|
|
20
|
+
if (!result.valid) {
|
|
21
|
+
return result;
|
|
20
22
|
}
|
|
21
|
-
|
|
23
|
+
values.push(result.value);
|
|
22
24
|
}
|
|
23
|
-
return { valid:
|
|
25
|
+
return { valid: true, value: values };
|
|
24
26
|
}
|
|
25
27
|
}
|
|
26
28
|
export function array(schema) {
|
|
@@ -3,7 +3,7 @@ import type { JsonPath } from '../../json-path/json-path.js';
|
|
|
3
3
|
import type { AbstractConstructor, OneOrMany, PartialProperty, Record as RecordType, SimplifyObject, Type, TypedOmit } from '../../types.js';
|
|
4
4
|
import { type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
5
5
|
import type { SchemaPropertyDecorator } from '../decorators/types.js';
|
|
6
|
-
import { Schema, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
6
|
+
import { type OPTIONAL, Schema, type SchemaOutput, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
7
7
|
export type Record<K extends PropertyKey = PropertyKey, V = any> = RecordType<K, V>;
|
|
8
8
|
export type ObjectSchemaFactoryFunction<T> = (data: T) => T;
|
|
9
9
|
export type ObjectSchemaFactory<T> = {
|
|
@@ -22,6 +22,14 @@ export type ObjectSchemaOptions<T extends Record = Record, K extends PropertyKey
|
|
|
22
22
|
factory?: ObjectSchemaFactory<T> | null;
|
|
23
23
|
};
|
|
24
24
|
export type ObjectSchemaOrType<T extends Record = any> = ObjectSchema<T> | AbstractConstructor<T>;
|
|
25
|
+
export type OptionalProperties<T> = {
|
|
26
|
+
[P in keyof T]: T[P] extends {
|
|
27
|
+
[OPTIONAL]: true;
|
|
28
|
+
} ? P : never;
|
|
29
|
+
}[keyof T];
|
|
30
|
+
export type ObjectSchemaPropertiesType<TP extends ObjectSchemaProperties> = SimplifyObject<{
|
|
31
|
+
[P in keyof PartialProperty<TP, OptionalProperties<TP>>]: SchemaOutput<TP[P]>;
|
|
32
|
+
}>;
|
|
25
33
|
export declare const tryGetSchemaFromReflection: typeof _tryGetSchemaFromReflection;
|
|
26
34
|
export declare class ObjectSchema<T extends Record = Record> extends Schema<T> {
|
|
27
35
|
private readonly propertyKeys;
|
|
@@ -46,21 +54,21 @@ export declare function object<const V>(properties: Record<never>, options: Obje
|
|
|
46
54
|
unknownProperties: SchemaTestable<V>;
|
|
47
55
|
unknownPropertiesKey?: undefined;
|
|
48
56
|
}): ObjectSchema<Record<PropertyKey, V>>;
|
|
49
|
-
export declare function object<const
|
|
57
|
+
export declare function object<const TP extends ObjectSchemaProperties, const K extends PropertyKey, const V>(properties: TP, options: ObjectSchemaOptions<ObjectSchemaPropertiesType<TP> & Record<K, V>> & {
|
|
50
58
|
unknownProperties: SchemaTestable<V>;
|
|
51
59
|
unknownPropertiesKey: SchemaTestable<K>;
|
|
52
|
-
}): ObjectSchema<
|
|
53
|
-
export declare function object<const
|
|
60
|
+
}): ObjectSchema<ObjectSchemaPropertiesType<TP> & Record<K, V>>;
|
|
61
|
+
export declare function object<const TP extends ObjectSchemaProperties, const K extends PropertyKey>(properties: TP, options: ObjectSchemaOptions<ObjectSchemaPropertiesType<TP> & Record<K, unknown>> & {
|
|
54
62
|
unknownPropertiesKey: SchemaTestable<K>;
|
|
55
|
-
}): ObjectSchema<
|
|
56
|
-
export declare function object<const
|
|
63
|
+
}): ObjectSchema<ObjectSchemaPropertiesType<TP> & Record<K, unknown>>;
|
|
64
|
+
export declare function object<const TP extends ObjectSchemaProperties, const V>(properties: TP, options: ObjectSchemaOptions<ObjectSchemaPropertiesType<TP> & Record<PropertyKey, V>> & {
|
|
57
65
|
unknownProperties: SchemaTestable<V>;
|
|
58
|
-
}): ObjectSchema<
|
|
59
|
-
export declare function object<const
|
|
66
|
+
}): ObjectSchema<ObjectSchemaPropertiesType<TP> & Record<PropertyKey, V>>;
|
|
67
|
+
export declare function object<const TP extends ObjectSchemaProperties>(properties: TP, options?: ObjectSchemaOptions<ObjectSchemaPropertiesType<TP>> & {
|
|
60
68
|
unknownProperties?: undefined;
|
|
61
69
|
unknownPropertiesKey?: undefined;
|
|
62
|
-
}): ObjectSchema<
|
|
63
|
-
export declare function object<const
|
|
70
|
+
}): ObjectSchema<ObjectSchemaPropertiesType<TP>>;
|
|
71
|
+
export declare function object<const TP extends ObjectSchemaProperties, const K extends PropertyKey, const V>(properties: TP, options?: ObjectSchemaOptions<ObjectSchemaPropertiesType<TP>, K, V>): ObjectSchema<ObjectSchemaPropertiesType<TP> & Record<K, V>>;
|
|
64
72
|
export declare function explicitObject<const T extends Record>(properties: ObjectSchemaProperties<T>, options?: ObjectSchemaOptions<T>): ObjectSchema<T>;
|
|
65
73
|
export declare function record<const K extends PropertyKey, const V>(key: Schema<K>, value: Schema<V>, options?: TypedOmit<ObjectSchemaOptions<Record<K, V>>, 'unknownProperties' | 'unknownPropertiesKey'>): ObjectSchema<Record<K, V>>;
|
|
66
74
|
export declare function assign<const T1 extends Record, const T2 extends Record>(a: ObjectSchemaOrType<T1>, b: ObjectSchemaOrType<T2>): ObjectSchema<Merge<T1, T2>>;
|
|
@@ -73,7 +81,7 @@ export declare function partial<const T extends Record, const K extends keyof T>
|
|
|
73
81
|
export declare function pick<const T extends Record, const K extends keyof T>(schemaOrType: ObjectSchemaOrType<T>, keys: OneOrMany<K>): ObjectSchema<SimplifyObject<Pick<T, K>>>;
|
|
74
82
|
export declare function omit<const T extends Record, const K extends keyof T>(schemaOrType: ObjectSchemaOrType<T>, keys: OneOrMany<K>): ObjectSchema<SimplifyObject<Omit<T, K>>>;
|
|
75
83
|
export declare function getSchemaFromReflection<T extends Record>(type: AbstractConstructor<T>): Schema<T>;
|
|
76
|
-
declare function _tryGetSchemaFromReflection<T extends Record>(type: AbstractConstructor<T>): Schema<T> | null;
|
|
84
|
+
declare function _tryGetSchemaFromReflection<T extends Record>(type: AbstractConstructor<T>): Schema<T> | ObjectSchema<T> | null;
|
|
77
85
|
export declare function getObjectSchema<T extends Record>(schemaOrType: SchemaTestable<T>): ObjectSchema<T>;
|
|
78
86
|
export declare function Record<K extends PropertyKey, V>(key: Schema<K>, value: Schema<V>, options?: TypedOmit<ObjectSchemaOptions<Record<K, V>>, 'unknownProperties' | 'unknownPropertiesKey'> & SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
|
79
87
|
export declare const emptyObjectSchema: ObjectSchema<EmptyObject>;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
|
-
import { TypedOmit } from '../../types.js';
|
|
2
|
+
import type { TypedOmit } from '../../types.js';
|
|
3
3
|
import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
4
|
-
import { Schema, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
4
|
+
import { type OPTIONAL, Schema, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
5
5
|
export declare class OptionalSchema<T> extends Schema<T | undefined> {
|
|
6
|
+
readonly [OPTIONAL]: true;
|
|
6
7
|
readonly schema: Schema<T>;
|
|
7
8
|
constructor(schema: SchemaTestable<T>);
|
|
8
9
|
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T | undefined>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { AnyIterable } from '../any-iterable-iterator.js';
|
|
2
|
-
import type { AsyncIteratorFunction } from './types.js';
|
|
2
|
+
import type { AsyncGroupSelectors, AsyncIteratorFunction } from './types.js';
|
|
3
3
|
export declare function groupSingleAsync<TIn, TGroup>(iterable: AnyIterable<TIn>, selector: AsyncIteratorFunction<TIn, TGroup>): AsyncIterableIterator<[TGroup, TIn]>;
|
|
4
|
+
export declare function groupSingleAsync<TIn, TGroup extends [any, ...any[]]>(iterable: AnyIterable<TIn>, ...selectors: AsyncGroupSelectors<TIn, TGroup>): AsyncIterableIterator<[TGroup['length'] extends 1 ? TGroup[0] : TGroup, TIn]>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { groupToSingleMapAsync } from './group-to-single-map.js';
|
|
2
|
-
export async function* groupSingleAsync(iterable,
|
|
3
|
-
yield* await groupToSingleMapAsync(iterable,
|
|
2
|
+
export async function* groupSingleAsync(iterable, ...selectors) {
|
|
3
|
+
yield* await groupToSingleMapAsync(iterable, ...selectors);
|
|
4
4
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { AnyIterable } from '../any-iterable-iterator.js';
|
|
2
|
-
import type { AsyncIteratorFunction } from './types.js';
|
|
2
|
+
import type { AsyncGroupSelectors, AsyncIteratorFunction } from './types.js';
|
|
3
3
|
export declare function groupToMapAsync<TIn, TGroup>(iterable: AnyIterable<TIn>, selector: AsyncIteratorFunction<TIn, TGroup>): Promise<Map<TGroup, TIn[]>>;
|
|
4
|
+
export declare function groupToMapAsync<TIn, TGroup extends [any, ...any[]]>(iterable: AnyIterable<TIn>, ...selectors: AsyncGroupSelectors<TIn, TGroup>): Promise<Map<TGroup['length'] extends 1 ? TGroup[0] : TGroup, TIn[]>>;
|
|
@@ -1,30 +1,57 @@
|
|
|
1
|
+
import { MultiKeyMap } from '../../data-structures/multi-key-map.js';
|
|
1
2
|
import { isAsyncIterable } from './is-async-iterable.js';
|
|
2
|
-
export async function groupToMapAsync(iterable,
|
|
3
|
+
export async function groupToMapAsync(iterable, ...selectors) {
|
|
3
4
|
return isAsyncIterable(iterable)
|
|
4
|
-
? async(iterable,
|
|
5
|
-
: sync(iterable,
|
|
5
|
+
? async(iterable, ...selectors)
|
|
6
|
+
: sync(iterable, ...selectors);
|
|
6
7
|
}
|
|
7
|
-
async function async(iterable,
|
|
8
|
-
const map = new Map();
|
|
8
|
+
async function async(iterable, ...selectors) {
|
|
9
9
|
let index = 0;
|
|
10
|
+
if (selectors.length == 1) {
|
|
11
|
+
const selector = selectors[0];
|
|
12
|
+
const map = new Map();
|
|
13
|
+
for await (const item of iterable) {
|
|
14
|
+
const groupKey = await selector(item, index++);
|
|
15
|
+
if (!map.has(groupKey)) {
|
|
16
|
+
map.set(groupKey, []);
|
|
17
|
+
}
|
|
18
|
+
map.get(groupKey).push(item);
|
|
19
|
+
}
|
|
20
|
+
return map;
|
|
21
|
+
}
|
|
22
|
+
const map = new MultiKeyMap();
|
|
10
23
|
for await (const item of iterable) {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
24
|
+
const groupKeys = await Promise.all(selectors.map(async (selector) => selector(item, index))); // eslint-disable-line @typescript-eslint/no-loop-func
|
|
25
|
+
index++;
|
|
26
|
+
if (!map.has(groupKeys)) {
|
|
27
|
+
map.set(groupKeys, []);
|
|
14
28
|
}
|
|
15
|
-
map.get(
|
|
29
|
+
map.get(groupKeys).push(item);
|
|
16
30
|
}
|
|
17
|
-
return map;
|
|
31
|
+
return map.toMap();
|
|
18
32
|
}
|
|
19
|
-
async function sync(iterable,
|
|
20
|
-
const map = new Map();
|
|
33
|
+
async function sync(iterable, ...selectors) {
|
|
21
34
|
let index = 0;
|
|
35
|
+
if (selectors.length == 1) {
|
|
36
|
+
const selector = selectors[0];
|
|
37
|
+
const map = new Map();
|
|
38
|
+
for (const item of iterable) {
|
|
39
|
+
const groupKey = await selector(item, index++);
|
|
40
|
+
if (!map.has(groupKey)) {
|
|
41
|
+
map.set(groupKey, []);
|
|
42
|
+
}
|
|
43
|
+
map.get(groupKey).push(item);
|
|
44
|
+
}
|
|
45
|
+
return map;
|
|
46
|
+
}
|
|
47
|
+
const map = new MultiKeyMap();
|
|
22
48
|
for (const item of iterable) {
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
49
|
+
const groupKeys = await Promise.all(selectors.map(async (selector) => selector(item, index))); // eslint-disable-line @typescript-eslint/no-loop-func
|
|
50
|
+
index++;
|
|
51
|
+
if (!map.has(groupKeys)) {
|
|
52
|
+
map.set(groupKeys, []);
|
|
26
53
|
}
|
|
27
|
-
map.get(
|
|
54
|
+
map.get(groupKeys).push(item);
|
|
28
55
|
}
|
|
29
|
-
return map;
|
|
56
|
+
return map.toMap();
|
|
30
57
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { AnyIterable } from '../any-iterable-iterator.js';
|
|
2
|
-
import type { AsyncIteratorFunction } from './types.js';
|
|
2
|
+
import type { AsyncGroupSelectors, AsyncIteratorFunction } from './types.js';
|
|
3
3
|
export declare function groupToSingleMapAsync<TIn, TGroup>(iterable: AnyIterable<TIn>, selector: AsyncIteratorFunction<TIn, TGroup>): Promise<Map<TGroup, TIn>>;
|
|
4
|
+
export declare function groupToSingleMapAsync<TIn, TGroup extends [any, ...any[]]>(iterable: AnyIterable<TIn>, ...selectors: AsyncGroupSelectors<TIn, TGroup>): Promise<Map<TGroup['length'] extends 1 ? TGroup[0] : TGroup, TIn>>;
|
|
@@ -1,30 +1,57 @@
|
|
|
1
|
+
import { MultiKeyMap } from '../../data-structures/multi-key-map.js';
|
|
1
2
|
import { isAsyncIterable } from './is-async-iterable.js';
|
|
2
|
-
export async function groupToSingleMapAsync(iterable,
|
|
3
|
+
export async function groupToSingleMapAsync(iterable, ...selectors) {
|
|
3
4
|
return isAsyncIterable(iterable)
|
|
4
|
-
? async(iterable,
|
|
5
|
-
: sync(iterable,
|
|
5
|
+
? async(iterable, ...selectors)
|
|
6
|
+
: sync(iterable, ...selectors);
|
|
6
7
|
}
|
|
7
|
-
async function async(iterable,
|
|
8
|
-
const map = new Map();
|
|
8
|
+
async function async(iterable, ...selectors) {
|
|
9
9
|
let index = 0;
|
|
10
|
+
if (selectors.length == 1) {
|
|
11
|
+
const selector = selectors[0];
|
|
12
|
+
const map = new Map();
|
|
13
|
+
for await (const item of iterable) {
|
|
14
|
+
const groupKey = await selector(item, index++);
|
|
15
|
+
if (map.has(groupKey)) {
|
|
16
|
+
throw new Error(`Group ${String(groupKey)} has more than one item.`);
|
|
17
|
+
}
|
|
18
|
+
map.set(groupKey, item);
|
|
19
|
+
}
|
|
20
|
+
return map;
|
|
21
|
+
}
|
|
22
|
+
const map = new MultiKeyMap();
|
|
10
23
|
for await (const item of iterable) {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
24
|
+
const groupKeys = await Promise.all(selectors.map(async (selector) => selector(item, index))); // eslint-disable-line @typescript-eslint/no-loop-func
|
|
25
|
+
index++;
|
|
26
|
+
if (map.has(groupKeys)) {
|
|
27
|
+
throw new Error(`Group [${groupKeys.map((key) => String(key)).join(', ')}] has more than one item.`);
|
|
14
28
|
}
|
|
15
|
-
map.set(
|
|
29
|
+
map.set(groupKeys, item);
|
|
16
30
|
}
|
|
17
|
-
return map;
|
|
31
|
+
return map.toMap();
|
|
18
32
|
}
|
|
19
|
-
async function sync(iterable,
|
|
20
|
-
const map = new Map();
|
|
33
|
+
async function sync(iterable, ...selectors) {
|
|
21
34
|
let index = 0;
|
|
35
|
+
if (selectors.length == 1) {
|
|
36
|
+
const selector = selectors[0];
|
|
37
|
+
const map = new Map();
|
|
38
|
+
for (const item of iterable) {
|
|
39
|
+
const groupKey = await selector(item, index++);
|
|
40
|
+
if (map.has(groupKey)) {
|
|
41
|
+
throw new Error(`Group ${String(groupKey)} has more than one item.`);
|
|
42
|
+
}
|
|
43
|
+
map.set(groupKey, item);
|
|
44
|
+
}
|
|
45
|
+
return map;
|
|
46
|
+
}
|
|
47
|
+
const map = new MultiKeyMap();
|
|
22
48
|
for (const item of iterable) {
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
49
|
+
const groupKeys = await Promise.all(selectors.map(async (selector) => selector(item, index))); // eslint-disable-line @typescript-eslint/no-loop-func
|
|
50
|
+
index++;
|
|
51
|
+
if (map.has(groupKeys)) {
|
|
52
|
+
throw new Error(`Group [${groupKeys.map((key) => String(key)).join(', ')}] has more than one item.`);
|
|
26
53
|
}
|
|
27
|
-
map.set(
|
|
54
|
+
map.set(groupKeys, item);
|
|
28
55
|
}
|
|
29
|
-
return map;
|
|
56
|
+
return map.toMap();
|
|
30
57
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { AnyIterable } from '../any-iterable-iterator.js';
|
|
2
|
-
import type { AsyncIteratorFunction } from './types.js';
|
|
2
|
+
import type { AsyncGroupSelectors, AsyncIteratorFunction } from './types.js';
|
|
3
3
|
export declare function groupAsync<TIn, TGroup>(iterable: AnyIterable<TIn>, selector: AsyncIteratorFunction<TIn, TGroup>): AsyncIterableIterator<[TGroup, TIn[]]>;
|
|
4
|
+
export declare function groupAsync<TIn, TGroup extends [any, ...any[]]>(iterable: AnyIterable<TIn>, ...selectors: AsyncGroupSelectors<TIn, TGroup>): AsyncIterableIterator<[TGroup['length'] extends 1 ? TGroup[0] : TGroup, TIn[]]>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { groupToMapAsync } from './group-to-map.js';
|
|
2
|
-
export async function* groupAsync(iterable,
|
|
3
|
-
yield* await groupToMapAsync(iterable,
|
|
2
|
+
export async function* groupAsync(iterable, ...selectors) {
|
|
3
|
+
yield* await groupToMapAsync(iterable, ...selectors);
|
|
4
4
|
}
|
|
@@ -3,6 +3,9 @@ export type AsyncIteratorFunction<TIn, TOut> = (item: TIn, index: number) => TOu
|
|
|
3
3
|
export type AsyncPredicate<T> = (item: T, index: number) => boolean | Promise<boolean>;
|
|
4
4
|
export type AsyncRetryPredicate<T> = (error: Error, item: T, index: number) => boolean | Promise<boolean>;
|
|
5
5
|
export type AsyncReducer<T, U> = (previous: U, current: T, index: number) => U | Promise<U>;
|
|
6
|
+
export type AsyncGroupSelectors<T, TGroup extends any[]> = {
|
|
7
|
+
[P in keyof TGroup]: AsyncIteratorFunction<T, TGroup[P]>;
|
|
8
|
+
};
|
|
6
9
|
export type ParallelizableIteratorFunction<TIn, TOut> = (item: TIn, index: number) => Promise<TOut>;
|
|
7
10
|
export type ParallelizablePredicate<T> = ParallelizableIteratorFunction<T, boolean>;
|
|
8
11
|
export type ThrottleFunction = () => Promise<void>;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import type { IteratorFunction } from './types.js';
|
|
1
|
+
import type { GroupSelectors, IteratorFunction } from './types.js';
|
|
2
2
|
export declare function groupSingle<TIn, TGroup>(iterable: Iterable<TIn>, selector: IteratorFunction<TIn, TGroup>): IterableIterator<[TGroup, TIn]>;
|
|
3
|
+
export declare function groupSingle<TIn, TGroup extends [any, ...any[]]>(iterable: Iterable<TIn>, ...selectors: GroupSelectors<TIn, TGroup>): IterableIterator<[TGroup['length'] extends 1 ? TGroup[0] : TGroup, TIn]>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { groupToSingleMap } from './group-to-single-map.js';
|
|
2
|
-
export function groupSingle(iterable,
|
|
3
|
-
return groupToSingleMap(iterable,
|
|
2
|
+
export function groupSingle(iterable, ...selectors) {
|
|
3
|
+
return groupToSingleMap(iterable, ...selectors)[Symbol.iterator]();
|
|
4
4
|
}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import type { IteratorFunction } from './types.js';
|
|
1
|
+
import type { GroupSelectors, IteratorFunction } from './types.js';
|
|
2
2
|
export declare function groupToMap<TIn, TGroup>(iterable: Iterable<TIn>, selector: IteratorFunction<TIn, TGroup>): Map<TGroup, TIn[]>;
|
|
3
|
+
export declare function groupToMap<TIn, TGroup extends [any, ...any[]]>(iterable: Iterable<TIn>, ...selectors: GroupSelectors<TIn, TGroup>): Map<TGroup['length'] extends 1 ? TGroup[0] : TGroup, TIn[]>;
|
|
@@ -1,12 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { MultiKeyMap } from '../../data-structures/multi-key-map.js';
|
|
2
|
+
export function groupToMap(iterable, ...selectors) {
|
|
3
3
|
let index = 0;
|
|
4
|
+
if (selectors.length == 1) {
|
|
5
|
+
const selector = selectors[0];
|
|
6
|
+
const map = new Map();
|
|
7
|
+
for (const item of iterable) {
|
|
8
|
+
const groupKey = selector(item, index++);
|
|
9
|
+
if (!map.has(groupKey)) {
|
|
10
|
+
map.set(groupKey, []);
|
|
11
|
+
}
|
|
12
|
+
map.get(groupKey).push(item);
|
|
13
|
+
}
|
|
14
|
+
return map;
|
|
15
|
+
}
|
|
16
|
+
const map = new MultiKeyMap();
|
|
4
17
|
for (const item of iterable) {
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
18
|
+
const groupKeys = selectors.map((selector) => selector(item, index)); // eslint-disable-line @typescript-eslint/no-loop-func
|
|
19
|
+
index++;
|
|
20
|
+
if (!map.has(groupKeys)) {
|
|
21
|
+
map.set(groupKeys, []);
|
|
8
22
|
}
|
|
9
|
-
map.get(
|
|
23
|
+
map.get(groupKeys).push(item);
|
|
10
24
|
}
|
|
11
|
-
return map;
|
|
25
|
+
return map.toMap();
|
|
12
26
|
}
|