Skip to content

Latest commit

 

History

History
316 lines (198 loc) · 6.99 KB

File metadata and controls

316 lines (198 loc) · 6.99 KB

@aligent/microservice-util-lib

@aligent/microservice-util-lib

Table of contents

Classes

Interfaces

Type Aliases

Functions

Type Aliases

ObjectMap

Ƭ ObjectMap: readonly readonly [string, string, Function?][]

A list of keys to keys, with an optional transformer function

Defined in

remap/remap.ts:15


Remap

Ƭ Remap<MapArray, Original>: SimplifyIntersection<ConstructTypeFromProperties<MapArray, Original>>

Type parameters

Name Type
MapArray extends ObjectMap
Original extends Object

Defined in

remap/remap.ts:159

Functions

chunkBy

chunkBy<ArrayItem>(source, chunkSize): ArrayItem[][]

Split an array into chunks of a certain size

Example

chunkBy([1, 2, 3, 4, 5, 6, 7], 2) // [[1, 2], [3, 4], [5, 6], [7]]

Type parameters

Name
ArrayItem

Parameters

Name Type Description
source ArrayItem[] the array to split up
chunkSize number the size of each chunk. (The final chunk will be whatever is remaining)

Returns

ArrayItem[][]

Defined in

chunkBy/chunkBy.ts:10


fetchSsmParams

fetchSsmParams(param): Promise<Parameter>

Fetch one SSM parameter

Parameters

Name Type Description
param string key of the parameter to fetch

Returns

Promise<Parameter>

Defined in

fetchSsmParams/fetchSsmParams.ts:14

fetchSsmParams(...params): Promise<Parameter[]>

Fetch a list of SSM parameters

Parameters

Name Type Description
...params string[] list of parameter keys to fetch

Returns

Promise<Parameter[]>

Defined in

fetchSsmParams/fetchSsmParams.ts:21


getAwsIdFromArn

getAwsIdFromArn(resourceArn): string

Get the AWS ID from its resource ARN

Throws

when the provided ARN is empty

Example

getAwsIdFromArn('arn:aws:states:ap-southeast-2:123123123:execution:prj-int-entity-ac-dc-dev-machine-name:this-is-the-id')

Parameters

Name Type Description
resourceArn string the ARN of the AWS resource

Returns

string

the ID (if present in the ARN) of the AWS resource/execution

Defined in

getAwsIdFromArn/getAwsIdFromArn.ts:11


hasDefinedProperties

hasDefinedProperties<T, K>(obj, ...keys): obj is SimplifyIntersection<Required<Pick<T, K>> & Omit<T, K>>

Ensure that the given properties are defined on the object.

Example

type Foo = { a?: number; b?: number };
const foo: Foo = { a: 1, b: 2 };
if (hasDefinedProperties(foo, 'a')) {
  console.log(foo);
 //          ^? const bar: {
 //               a: number;
 //               b?: number;
 //             }
}

Type parameters

Name Type
T extends Object
K extends string | number | symbol

Parameters

Name Type Description
obj object | T The object to check.
...keys K[] The keys to check.

Returns

obj is SimplifyIntersection<Required<Pick<T, K>> & Omit<T, K>>

true if the object has the given properties defined, false otherwise.

Defined in

hasPropertiesDefined/hasPropertiesDefined.ts:22


remap

remap<Original, MapArray>(object, map): Remap<MapArray, Original>

Map one object's values to another structure

Example

without a transformer function

const map = [
  ['foo', 'baz'],
  ['bar', 'qux.0']
] as const;
const obj = { foo: 'hi', bar: 7 }
remap(obj, map); // { baz: 'hi', qux: [7] }

Example

with a transformer function

const map = [
 ['foo', 'baz'],
 ['bar', 'qux.0', (x: number) => x + 1]
] as const;
const obj = { foo: 'hi', bar: 7 }
remap(obj, map); // { baz: 'hi', qux: [8] }

Example

with an empty initial key

const map = [
  ['', 'baz', (x: { foo: number, bar: number }) => x.foo + x.bar]
]
const obj = { foo: 3, bar: 7 }
remap(obj, map); // { baz: 10 }

Type parameters

Name Type
Original extends Object
MapArray extends readonly readonly [string, string, (...args: any[]) => any][]

Parameters

Name Type Description
object Original the object to map from
map MapArray the keys for the mapping

Returns

Remap<MapArray, Original>

the remapped object

Defined in

remap/remap.ts:198


retryWrapper

retryWrapper<T>(fn, config): Promise<T>

Retry an async function if it fails

Example

retryWrapper(someAsyncFunction, {
  retries: 3,
  onRetry: (_, error) => console.error(error)
});

Type parameters

Name
T

Parameters

Name Type Description
fn () => Promise<T> the function to be retried
config RetryConfig the configuration for retries

Returns

Promise<T>

Defined in

retryWrapper/retryWrapper.ts:78