3.1.0 • Published 1 month ago

@ti-platform/aide v3.1.0

Weekly downloads
-
License
-
Repository
-
Last release
1 month ago

@ti-platform/aide

This package exposes some types and functions as utilities that can be used by other packages. Refer to the below API Docs for more information.

Contents

API Docs

Classes

Deferred\

Extracting out a Promise's resolve and reject method to allow one to more easily pass around those methods.

Type parameters

Type parameterValueDescription
TvoidThe type to resolve with.

Constructors

new Deferred()

new Deferred<T>(): Deferred<T>

Create a new instance.

Returns

Deferred<T>

Source

promises.ts:32

Properties

PropertyModifierTypeDescription
promisereadonlyPromise<T>The underlying promise.
rejectpublic(reason?: any) => voidReject the internal promise.
resolvepublic(value: Awaitable<T>) => voidResolves the internal promise.

Queue\

Queue that execute handlers as per the configured concurrency limit. It also has the ability to rate limit how much execution happens within an interval.

Type parameters

Type parameterValueDescription
TvoidThe type of the item that the promise resolves with for the handlers. Defaults to void.

Constructors

new Queue(__namedParameters)

new Queue<T>(__namedParameters): Queue<T>

Create a new instance.

Parameters
ParameterType
__namedParametersQueueConstructorOptions
Returns

Queue<T>

Source

queue.ts:132

Properties

PropertyModifierTypeDescription
intervalMsreadonlynumberRefer to ~intervalMs.
maxConcurrentreadonlynumberRefer to ~maxConcurrent.
maxPerIntervalreadonlynumberRefer to ~maxPerInterval.

Methods

add()

add(item): Object

Add a new item to the queue for execution.

Parameters
ParameterType
itemQueueItem<T>
Returns

Object

An object containing 3 promises, onBeforeStart, onAfterStart, and onEnd. The promises are resolved right before the item is executed, right after the item is executed, and right after it finishes execution.

MemberTypeValue
onAfterStartPromise<void>onAfterStart.promise
onBeforeStartPromise<void>onBeforeStart.promise
onEndPromise<T>onEnd.promise
Throws

Error if items can no longer be added.

Source

queue.ts:147

lockQueue()

lockQueue(): Promise<void>

Lock the queue and return a promise that will resolve when all the handlers finished execution.

Returns

Promise<void>

Source

queue.ts:171

Type Aliases

AnyArray\

AnyArray<V>: V[] | ReadonlyArray<V>

Type matching against both a writable array and a readonly array.

Type parameters

Type parameterDescription
VThe type of each item in the array.

Source

arrays.ts:6


Awaitable\

Awaitable<T>: T | Promise<T>

The type is simply T or a promise which, when resolved, is given T.

Type parameters

Type parameter
T

Source

types.ts:9


MarkReadonly\<T, K>

MarkReadonly<T, K>: Omit<T, K> & Readonly<Pick<T, K>>

For a given object, T, mark the keys given as being readonly.

Type parameters

Type parameter
T
K extends keyof T

Source

types.ts:4


QueueConstructorOptions

QueueConstructorOptions: Object

Arguments for constructing a Queue.

Type declaration

MemberTypeDescription
intervalMsnumberIf given in addition with maxPerInterval, used to limit how many items can execute within an interval. This issimply the time, in milliseconds, for when to reset the execution counts per interval.
maxConcurrentnumberMaximum number of concurrent executions.
maxPerIntervalnumberIf given in addition with intervalMs, used to limit how many items can execute within an interval. This issimply the maximum number of executions within the interval.

Source

queue.ts:37


QueueItem()\

QueueItem<T>: () => Awaitable<T>

An item in the queue.

Type parameters

Type parameterValueDescription
TvoidThe type of the item that the promise resolves with. Defaults to void.

Returns

Awaitable<T>

Source

queue.ts:32

Functions

ensureType()

ensureType<V>(): <T>(list) => readonly T[]

This function is primarily here to help with stricter typing. When Typescript allows for partial inference of arguments to functions, this function would likely not be needed anymore.

Type parameters

Type parameterDescription
VThe type of each item in the array.

Returns

Function

An identity function that accepts a list and simply returns it.

Type parameters
Type parameter
T
Parameters
ParameterType
listreadonly T[]
Returns

readonly T[]

Example

type MyItem = { name: string, displayName: string };
 const list = ensureType<MyItem>()([
     { name: 'one', displayName: 'ONE' },    // <- You get proper linting and hinting support here
     { name: 'two', displayName: 'TWO' },
 ] as const); // <- The "as const" allows for better type restrictions as below

 type Name = typeof list[number]['name'];    // == "one" | "two" vs string if not using this

Source

arrays.ts:24


executeTasks()

executeTasks<T>(tasks, maxNumOfWorkers): Promise<T[]>

Given a list of tasks to execute, execute them, ensuring there is a maximum number of tasks actively running at the same time. The returning array of responses should match the order of the task that was given.

Type parameters

Type parameterDescription
TThe type of the result of each task.

Parameters

ParameterTypeDefault valueDescription
tasksreadonly () => Promise<T>[]undefinedThe tasks to run.
maxNumOfWorkersnumber10The maximum number of tasks to run at once.

Returns

Promise<T[]>

A promise that will resolve when all the tasks are completed.

Source

queue.ts:13


first()

first<V>(list): undefined | V

Type parameters

Type parameterDescription
VThe type of each item in the array.

Parameters

ParameterTypeDescription
listAnyArray<V>The list to retrieve the first element for.

Returns

undefined | V

The first item in the list or undefined if the list is empty.

Source

arrays.ts:35


firstDefined()

firstDefined<V>(list): V

Given a list of function, execute each until there is a function that does not return undefined. You should have at least one of the function return something to prevent problems.

Type parameters

Type parameterDescription
VThe type of each item in the list.

Parameters

ParameterTypeDescription
listAnyArray<() => undefinedV>The list of functions to execute.

Returns

V

The return value of the first function to not return an undefined value.

Source

arrays.ts:47


getOrDefault()

getOrDefault<K, V>(map, key, defaultValue): V

Type parameters

Type parameterDescription
KThe type of the key in the map.
VThe type of the value in the map.

Parameters

ParameterTypeDescription
mapMap<K, V>The map to get the data from.
keyKThe key to get the data for.
defaultValueVThe default value to return if the key does not exist.

Returns

V

The value in the map with the given key or if the key does not exist, the provided default value.

Source

map.ts:9


keepOnlyDefined()

keepOnlyDefined<V>(list): V[]

Given a list of items, remove null and undefined from the list.

Type parameters

Type parameterDescription
VThe type of each item in the list.

Parameters

ParameterTypeDescription
listAnyArray<V>The list of items to traverse and filter.

Returns

V[]

The given list without null or undefined values.

Source

arrays.ts:64


toMap()

toMap<K, V, V2>(list, keySupplier, valueSupplier): Record<K, V2>

Given a list, convert it to an object where the key will be provided using the given supplier.

Type parameters

Type parameterDescription
K extends PropertyKeyThe type for the key that will be produced for the map.
VThe type of each item in the list.
V2The type for the value when it is set to the map.

Parameters

ParameterTypeDescription
listAnyArray<V>The list of items to convert.
keySupplier(item, index) => KFunction to use to generate the key for each entry.
valueSupplier(item, key, index) => V2Function to use to generate the value for each entry.

Returns

Record<K, V2>

An object representation of the given list using the provided suppliers to generate the keys and values.

Source

arrays.ts:79

3.1.0

1 month ago

3.0.1

1 month ago

3.0.0

1 month ago

1.2.0

10 months ago

2.0.2

10 months ago

2.0.1

10 months ago

2.0.0

10 months ago

1.1.1

11 months ago

1.1.0

1 year ago

1.0.0

1 year ago

0.4.1

1 year ago

0.4.0

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago