@aligent/microservice-util-lib
Ƭ ObjectMap: readonly readonly [string
, string
, Function?][]
A list of keys to keys, with an optional transformer function
Ƭ Remap<MapArray
, Original
>: SimplifyIntersection
<ConstructTypeFromProperties
<MapArray
, Original
>>
Name | Type |
---|---|
MapArray |
extends ObjectMap |
Original |
extends Object |
▸ 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]]
Name |
---|
ArrayItem |
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) |
ArrayItem
[][]
▸ fetchSsmParams(param
): Promise
<Parameter
>
Fetch one SSM parameter
Name | Type | Description |
---|---|---|
param |
string |
key of the parameter to fetch |
Promise
<Parameter
>
fetchSsmParams/fetchSsmParams.ts:14
▸ fetchSsmParams(...params
): Promise
<Parameter
[]>
Fetch a list of SSM parameters
Name | Type | Description |
---|---|---|
...params |
string [] |
list of parameter keys to fetch |
Promise
<Parameter
[]>
fetchSsmParams/fetchSsmParams.ts:21
▸ 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')
Name | Type | Description |
---|---|---|
resourceArn |
string |
the ARN of the AWS resource |
string
the ID (if present in the ARN) of the AWS resource/execution
getAwsIdFromArn/getAwsIdFromArn.ts:11
▸ 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;
// }
}
Name | Type |
---|---|
T |
extends Object |
K |
extends string | number | symbol |
Name | Type | Description |
---|---|---|
obj |
object | T |
The object to check. |
...keys |
K [] |
The keys to check. |
obj is SimplifyIntersection<Required<Pick<T, K>> & Omit<T, K>>
true
if the object has the given properties defined, false
otherwise.
hasPropertiesDefined/hasPropertiesDefined.ts:22
▸ 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 }
Name | Type |
---|---|
Original |
extends Object |
MapArray |
extends readonly readonly [string , string , (...args : any []) => any ][] |
Name | Type | Description |
---|---|---|
object |
Original |
the object to map from |
map |
MapArray |
the keys for the mapping |
Remap
<MapArray
, Original
>
the remapped object
▸ retryWrapper<T
>(fn
, config
): Promise
<T
>
Retry an async function if it fails
Example
retryWrapper(someAsyncFunction, {
retries: 3,
onRetry: (_, error) => console.error(error)
});
Name |
---|
T |
Name | Type | Description |
---|---|---|
fn |
() => Promise <T > |
the function to be retried |
config |
RetryConfig |
the configuration for retries |
Promise
<T
>