AsyncPipe; table schemata; migrations; File logging
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-07-25 09:15:01 -05:00
parent e86cf420df
commit fcce28081b
42 changed files with 3139 additions and 56 deletions

View File

@@ -7,6 +7,7 @@ import {
} from './Collection'
import {Iterable, StopIteration} from './Iterable'
import {applyWhere, WhereOperator} from './where'
import {AsyncPipe, Pipe} from '../support/Pipe'
type AsyncCollectionComparable<T> = CollectionItem<T>[] | Collection<T> | AsyncCollection<T>
type AsyncKeyFunction<T, T2> = (item: CollectionItem<T>, index: number) => CollectionItem<T2> | Promise<CollectionItem<T2>>
type AsyncCollectionFunction<T, T2> = (items: AsyncCollection<T>) => T2
@@ -318,6 +319,24 @@ export class AsyncCollection<T> {
return new Collection<T2>(newItems)
}
/**
* Create a new collection by mapping the items in this collection using the given function,
* excluding any for which the function resolves undefined.
* @param func
*/
async partialMap<T2>(func: AsyncKeyFunction<T, T2 | undefined>): Promise<Collection<NonNullable<T2>>> {
const newItems: CollectionItem<NonNullable<T2>>[] = []
await this.each(async (item, index) => {
const result = await func(item, index)
if ( typeof result !== 'undefined' ) {
newItems.push(result as NonNullable<T2>)
}
})
return new Collection<NonNullable<T2>>(newItems)
}
/**
* Returns true if the given operator returns true for every item in the collection.
* @param {AsyncKeyFunction} func
@@ -783,10 +802,24 @@ export class AsyncCollection<T> {
* Return the value of the function, passing this collection to it.
* @param {AsyncCollectionFunction} func
*/
pipe<T2>(func: AsyncCollectionFunction<T, T2>): any {
pipeTo<T2>(func: AsyncCollectionFunction<T, T2>): any {
return func(this)
}
/**
* Return a new Pipe of this collection.
*/
pipe(): Pipe<AsyncCollection<T>> {
return Pipe.wrap(this)
}
/**
* Return a new AsyncPipe of this collection.
*/
asyncPipe(): AsyncPipe<AsyncCollection<T>> {
return AsyncPipe.wrap(this)
}
/* async pop(): Promise<MaybeCollectionItem<T>> {
const nextItem = await this.storedItems.next()
if ( !nextItem.done ) {