functools-kit
Advanced tools
Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "functools-kit", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "A library with helpers for react-declarative app backend development", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -32,3 +32,4 @@ export { randomString } from './utils/randomString'; | ||
import type TSubjectInternal from './model/TSubject'; | ||
import TSubjectInternal from './model/TSubject'; | ||
import { IRowData, RowId } from './model/IRowData'; | ||
import TBehaviorSubjectInternal from './model/TBehaviorSubject'; | ||
@@ -42,2 +43,16 @@ import TObserverInternal, { TObservable as TObservableInternal } from './model/TObserver'; | ||
export type { IRowData, RowId }; | ||
export { paginateDocuments } from './api/paginateDocuments'; | ||
export { distinctDocuments } from './api/distinctDocuments'; | ||
export { resolveDocuments } from './api/resolveDocuments'; | ||
export { filterDocuments } from './api/filterDocuments'; | ||
export { pickDocuments } from './api/pickDocuments'; | ||
export { mapDocuments } from './api/mapDocuments'; | ||
export { iterateDocuments } from './api/iterateDocuments'; | ||
export { iteratePromise } from './api/iteratePromise'; | ||
export { iterateUnion } from './api/iterateUnion'; | ||
export { iterateList } from './api/iterateList'; | ||
export { compose } from './utils/compose'; |
114
types.d.ts
@@ -190,3 +190,3 @@ /** | ||
*/ | ||
interface IConfig$1 { | ||
interface IConfig$2 { | ||
maxExec: number; | ||
@@ -222,3 +222,3 @@ delay: number; | ||
*/ | ||
declare const execpool: <T extends unknown = any, P extends any[] = any[]>(run: (...args: P) => Promise<T>, { maxExec, delay, }?: Partial<IConfig$1>) => IWrappedFn$1<T, P>; | ||
declare const execpool: <T extends unknown = any, P extends any[] = any[]>(run: (...args: P) => Promise<T>, { maxExec, delay, }?: Partial<IConfig$2>) => IWrappedFn$1<T, P>; | ||
@@ -308,3 +308,3 @@ /** | ||
*/ | ||
interface IConfig { | ||
interface IConfig$1 { | ||
allowedErrors?: { | ||
@@ -331,3 +331,3 @@ new (): IError; | ||
*/ | ||
declare const trycatch: <T extends (...args: A) => any, A extends any[], V extends unknown>(run: T, { allowedErrors, fallback, defaultValue, }?: Partial<IConfig>) => (...args: A) => ReturnType<T> | null; | ||
declare const trycatch: <T extends (...args: A) => any, A extends any[], V extends unknown>(run: T, { allowedErrors, fallback, defaultValue, }?: Partial<IConfig$1>) => (...args: A) => ReturnType<T> | null; | ||
@@ -1199,2 +1199,106 @@ /** | ||
/** | ||
* Represents a data row in a table. | ||
* @interface | ||
*/ | ||
interface IRowData { | ||
id: RowId; | ||
} | ||
/** | ||
* Represents a unique identifier for a row in a data table. | ||
*/ | ||
type RowId = string | number; | ||
/** | ||
* Resolves the documents from an async generator and paginates them. | ||
* | ||
* @param iterator - The async generator to resolve documents from. | ||
* @returns - A promise that resolves to the flattened array of documents. | ||
*/ | ||
declare const paginateDocuments: <T extends unknown>(iterator: AsyncGenerator<T | T[], void, unknown>, limit: number, offset: number) => Promise<T[]>; | ||
/** | ||
* Resolves the documents from an async generator and distincts them. | ||
* | ||
* @param iterator - The async generator to resolve documents from. | ||
* @returns - A promise that resolves to the flattened array of documents. | ||
*/ | ||
declare function distinctDocuments<T extends IRowData>(iterator: AsyncGenerator<T | T[], void, unknown>): AsyncGenerator<T, void, unknown>; | ||
/** | ||
* Resolves the documents from an async generator and returns them as a flattened array. | ||
* | ||
* @param iterator - The async generator to resolve documents from. | ||
* @returns - A promise that resolves to the flattened array of documents. | ||
*/ | ||
declare const resolveDocuments: <T extends unknown>(iterator: AsyncGenerator<T | T[], void, unknown>) => Promise<T[]>; | ||
/** | ||
* Filters the documents from an async generator and yield them by the condition | ||
* | ||
* @param iterator - The async generator to resolve documents from. | ||
* @returns - A promise that resolves to the flattened array of documents. | ||
*/ | ||
declare function filterDocuments<T extends unknown>(iterator: AsyncGenerator<T | T[], void, unknown>, predicate: (value: T) => boolean | Promise<boolean>): AsyncGenerator<Awaited<T>, void, unknown>; | ||
/** | ||
* A function that picks a subset of documents from an array of documents, given a limit and offset. | ||
* | ||
* @template T - The type of the documents in the array. | ||
* @param limit - The maximum number of documents to pick. | ||
* @param offset - The number of documents to skip before picking. | ||
* @returns - A function that takes an array of documents and returns an object with `rows` and `done` properties. | ||
* The `rows` property contains the picked documents, and `done` property indicates if the picking is finished. | ||
*/ | ||
declare const pickDocuments: <T extends unknown>(limit: number, offset: number) => (rows?: T[]) => { | ||
rows: T[]; | ||
done: boolean; | ||
}; | ||
/** | ||
* Maps the documents from an async generator and yield them | ||
* | ||
* @param iterator - The async generator to resolve documents from. | ||
* @returns - A promise that resolves to the flattened array of documents. | ||
*/ | ||
declare function mapDocuments<T extends unknown, U = T>(iterator: AsyncGenerator<T | T[], void, unknown>, callbackfn: (value: T) => U | Promise<U>): AsyncGenerator<Awaited<U>, void, unknown>; | ||
/** | ||
* Represents a configuration interface for data retrieval. | ||
* @template Data - The type of row data. | ||
*/ | ||
interface IConfig<Data extends IRowData = IRowData> { | ||
totalDocuments?: number; | ||
limit?: number; | ||
delay?: number; | ||
createRequest: (data: { | ||
limit: number; | ||
offset: number; | ||
page: number; | ||
lastId: RowId | null; | ||
} & Omit<IConfig<Data>, 'createRequest'>) => (Data[] | Promise<Data[]>); | ||
} | ||
/** | ||
* Asynchronous generator function that iterates over documents. | ||
* | ||
* @template Data - The type of the row data in the documents. | ||
* | ||
* @param config - The configuration object. | ||
* @param [config.totalDocuments=TOTAL_DOCUMENTS] - The total number of documents to iterate over. | ||
* @param [config.limit=REQUEST_LIMIT] - The number of documents to fetch in each request. | ||
* @param [config.delay=REQUEST_DELAY] - The delay between each request. | ||
* @param [config.createRequest=() => []] - The function used to create the request. | ||
* | ||
* @returns An asynchronous generator that yields an array of documents. | ||
* | ||
* @throws If the response length is greater than the specified limit. | ||
*/ | ||
declare const iterateDocuments: <Data extends IRowData = IRowData>({ totalDocuments, limit, delay, createRequest, }: IConfig<Data>) => AsyncGenerator<Data[], void, unknown>; | ||
declare function iteratePromise<T extends IRowData = IRowData>(fn: () => Promise<T[]>): AsyncGenerator<T, void, unknown>; | ||
declare const iterateUnion: <T extends IRowData = IRowData>(iterators: AsyncGenerator<T | T[], void, unknown>[]) => (limit: number, offset: number) => AsyncGenerator<T, void, unknown>; | ||
declare function iterateList<T extends IRowData = IRowData>(rows: T[], map?: (row: T) => Promise<Awaited<T>>): AsyncGenerator<Awaited<T>, void, unknown>; | ||
type TSubject<Data = void> = TSubject$1<Data>; | ||
@@ -1205,2 +1309,2 @@ type TObserver<Data = void> = TObserver$1<Data>; | ||
export { BehaviorSubject, CANCELED_SYMBOL as CANCELED_PROMISE_SYMBOL, EventEmitter, Observer, Operator, Source, Subject, type TBehaviorSubject, type TObservable, type TObserver, type TSubject, Task, cached, cancelable, compareArray, compareFulltext, compose, createAwaiter, debounce, deepFlat, execpool, formatText, isObject, memoize, queued, randomString, retry, singlerun, singleshot, sleep, trycatch }; | ||
export { BehaviorSubject, CANCELED_SYMBOL as CANCELED_PROMISE_SYMBOL, EventEmitter, type IRowData, Observer, Operator, type RowId, Source, Subject, type TBehaviorSubject, type TObservable, type TObserver, type TSubject, Task, cached, cancelable, compareArray, compareFulltext, compose, createAwaiter, debounce, deepFlat, distinctDocuments, execpool, filterDocuments, formatText, isObject, iterateDocuments, iterateList, iteratePromise, iterateUnion, mapDocuments, memoize, paginateDocuments, pickDocuments, queued, randomString, resolveDocuments, retry, singlerun, singleshot, sleep, trycatch }; |
185144
68
4683