@aligent/microservice-util-lib 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,206 @@
1
+ [@aligent/microservice-util-lib](../modules.md) / S3Dao
2
+
3
+ # Class: S3Dao
4
+
5
+ A data access object for an S3 bucket
6
+
7
+ ## Table of contents
8
+
9
+ ### Constructors
10
+
11
+ - [constructor](S3Dao.md#constructor)
12
+
13
+ ### Properties
14
+
15
+ - [bucket](S3Dao.md#bucket)
16
+ - [s3](S3Dao.md#s3)
17
+
18
+ ### Methods
19
+
20
+ - [deleteData](S3Dao.md#deletedata)
21
+ - [fetchChunks](S3Dao.md#fetchchunks)
22
+ - [fetchData](S3Dao.md#fetchdata)
23
+ - [storeChunked](S3Dao.md#storechunked)
24
+ - [storeData](S3Dao.md#storedata)
25
+
26
+ ## Constructors
27
+
28
+ ### <a id="constructor" name="constructor"></a> constructor
29
+
30
+ • **new S3Dao**(`bucket`)
31
+
32
+ #### Parameters
33
+
34
+ | Name | Type | Description |
35
+ | :------ | :------ | :------ |
36
+ | `bucket` | `string` | the location of the bucket that objects should be stored in |
37
+
38
+ #### Defined in
39
+
40
+ [s3/s3.ts:14](https://bitbucket.org/aligent/microservice-util-lib/src/0052f4c/src/s3/s3.ts#lines-14)
41
+
42
+ ## Properties
43
+
44
+ ### <a id="bucket" name="bucket"></a> bucket
45
+
46
+ • `Private` **bucket**: `string`
47
+
48
+ #### Defined in
49
+
50
+ [s3/s3.ts:9](https://bitbucket.org/aligent/microservice-util-lib/src/0052f4c/src/s3/s3.ts#lines-9)
51
+
52
+ ___
53
+
54
+ ### <a id="s3" name="s3"></a> s3
55
+
56
+ • `Private` **s3**: `S3`
57
+
58
+ #### Defined in
59
+
60
+ [s3/s3.ts:8](https://bitbucket.org/aligent/microservice-util-lib/src/0052f4c/src/s3/s3.ts#lines-8)
61
+
62
+ ## Methods
63
+
64
+ ### <a id="deletedata" name="deletedata"></a> deleteData
65
+
66
+ ▸ **deleteData**(`objectDetails`): `Promise`<`PromiseResult`<`DeleteObjectOutput`, `AWSError`\>\>
67
+
68
+ Delete an object from the S3 bucket
69
+
70
+ #### Parameters
71
+
72
+ | Name | Type | Description |
73
+ | :------ | :------ | :------ |
74
+ | `objectDetails` | `GetObjectRequest` | the object to delete |
75
+
76
+ #### Returns
77
+
78
+ `Promise`<`PromiseResult`<`DeleteObjectOutput`, `AWSError`\>\>
79
+
80
+ #### Defined in
81
+
82
+ [s3/s3.ts:90](https://bitbucket.org/aligent/microservice-util-lib/src/0052f4c/src/s3/s3.ts#lines-90)
83
+
84
+ ___
85
+
86
+ ### <a id="fetchchunks" name="fetchchunks"></a> fetchChunks
87
+
88
+ ▸ **fetchChunks**<`T`\>(`chunks`): `AsyncGenerator`<{ `chunk`: `T` ; `s3Object`: `GetObjectRequest` }, { `chunk`: `T` ; `s3Object`: `GetObjectRequest` }, `unknown`\>
89
+
90
+ Generator to fetch chunked data, chunk by chunk
91
+
92
+ #### Type parameters
93
+
94
+ | Name |
95
+ | :------ |
96
+ | `T` |
97
+
98
+ #### Parameters
99
+
100
+ | Name | Type | Description |
101
+ | :------ | :------ | :------ |
102
+ | `chunks` | `GetObjectRequest`[] | the list of object chunks |
103
+
104
+ #### Returns
105
+
106
+ `AsyncGenerator`<{ `chunk`: `T` ; `s3Object`: `GetObjectRequest` }, { `chunk`: `T` ; `s3Object`: `GetObjectRequest` }, `unknown`\>
107
+
108
+ #### Defined in
109
+
110
+ [s3/s3.ts:70](https://bitbucket.org/aligent/microservice-util-lib/src/0052f4c/src/s3/s3.ts#lines-70)
111
+
112
+ ___
113
+
114
+ ### <a id="fetchdata" name="fetchdata"></a> fetchData
115
+
116
+ ▸ **fetchData**<`T`\>(`objectDetails`): `Promise`<`T`\>
117
+
118
+ Fetch an object from the S3 bucket
119
+
120
+ #### Type parameters
121
+
122
+ | Name |
123
+ | :------ |
124
+ | `T` |
125
+
126
+ #### Parameters
127
+
128
+ | Name | Type | Description |
129
+ | :------ | :------ | :------ |
130
+ | `objectDetails` | `GetObjectRequest` | the object which describes the location of the object |
131
+
132
+ #### Returns
133
+
134
+ `Promise`<`T`\>
135
+
136
+ the body of the object
137
+
138
+ #### Defined in
139
+
140
+ [s3/s3.ts:61](https://bitbucket.org/aligent/microservice-util-lib/src/0052f4c/src/s3/s3.ts#lines-61)
141
+
142
+ ___
143
+
144
+ ### <a id="storechunked" name="storechunked"></a> storeChunked
145
+
146
+ ▸ **storeChunked**<`T`\>(`data`, `chunkSize`): `Promise`<`GetObjectRequest`[]\>
147
+
148
+ Store an array of object as individual chunks in S3
149
+
150
+ #### Type parameters
151
+
152
+ | Name | Type |
153
+ | :------ | :------ |
154
+ | `T` | extends `any`[] |
155
+
156
+ #### Parameters
157
+
158
+ | Name | Type | Description |
159
+ | :------ | :------ | :------ |
160
+ | `data` | `T` | the data to store |
161
+ | `chunkSize` | `number` | the number of entries that should be in each chunk |
162
+
163
+ #### Returns
164
+
165
+ `Promise`<`GetObjectRequest`[]\>
166
+
167
+ an array of objects which can be used to fetch the chunks
168
+
169
+ #### Defined in
170
+
171
+ [s3/s3.ts:51](https://bitbucket.org/aligent/microservice-util-lib/src/0052f4c/src/s3/s3.ts#lines-51)
172
+
173
+ ___
174
+
175
+ ### <a id="storedata" name="storedata"></a> storeData
176
+
177
+ ▸ **storeData**<`T`\>(`data`, `name?`): `Promise`<`GetObjectRequest`\>
178
+
179
+ Store data in an S3 bucket
180
+
181
+ **`Default`**
182
+
183
+ the hash of the data
184
+
185
+ #### Type parameters
186
+
187
+ | Name |
188
+ | :------ |
189
+ | `T` |
190
+
191
+ #### Parameters
192
+
193
+ | Name | Type | Description |
194
+ | :------ | :------ | :------ |
195
+ | `data` | `T` | the data to store |
196
+ | `name?` | `string` | the name to call the object in S3 |
197
+
198
+ #### Returns
199
+
200
+ `Promise`<`GetObjectRequest`\>
201
+
202
+ an object which can be used to fetch the data
203
+
204
+ #### Defined in
205
+
206
+ [s3/s3.ts:25](https://bitbucket.org/aligent/microservice-util-lib/src/0052f4c/src/s3/s3.ts#lines-25)
@@ -0,0 +1,90 @@
1
+ [@aligent/microservice-util-lib](../modules.md) / RetryConfig
2
+
3
+ # Interface: RetryConfig
4
+
5
+ Configuration for the retryWrapper
6
+
7
+ ## Table of contents
8
+
9
+ ### Properties
10
+
11
+ - [backoffAmount](RetryConfig.md#backoffamount)
12
+ - [delay](RetryConfig.md#delay)
13
+ - [onRetry](RetryConfig.md#onretry)
14
+ - [retries](RetryConfig.md#retries)
15
+
16
+ ## Properties
17
+
18
+ ### <a id="backoffamount" name="backoffamount"></a> backoffAmount
19
+
20
+ • `Optional` **backoffAmount**: `number`
21
+
22
+ The amount to increase the delay by each retry (in ms)
23
+
24
+ **`Default`**
25
+
26
+ 0
27
+
28
+ #### Defined in
29
+
30
+ [retryWrapper/retryWrapper.ts:17](https://bitbucket.org/aligent/microservice-util-lib/src/0052f4c/src/retryWrapper/retryWrapper.ts#lines-17)
31
+
32
+ ___
33
+
34
+ ### <a id="delay" name="delay"></a> delay
35
+
36
+ • `Optional` **delay**: `number`
37
+
38
+ The base delay between retries (in ms)
39
+
40
+ **`Default`**
41
+
42
+ 0
43
+
44
+ #### Defined in
45
+
46
+ [retryWrapper/retryWrapper.ts:12](https://bitbucket.org/aligent/microservice-util-lib/src/0052f4c/src/retryWrapper/retryWrapper.ts#lines-12)
47
+
48
+ ___
49
+
50
+ ### <a id="onretry" name="onretry"></a> onRetry
51
+
52
+ • `Optional` **onRetry**: (`retries`: `number`, `error`: `Error`, `config`: [`RetryConfig`](RetryConfig.md)) => `void`
53
+
54
+ #### Type declaration
55
+
56
+ ▸ (`retries`, `error`, `config`): `void`
57
+
58
+ A callback to run before each retry
59
+
60
+ ##### Parameters
61
+
62
+ | Name | Type | Description |
63
+ | :------ | :------ | :------ |
64
+ | `retries` | `number` | the number of retries so far (will start at 1) |
65
+ | `error` | `Error` | the error from the last attempt |
66
+ | `config` | [`RetryConfig`](RetryConfig.md) | the configuration supplied to the retryWrapper |
67
+
68
+ ##### Returns
69
+
70
+ `void`
71
+
72
+ #### Defined in
73
+
74
+ [retryWrapper/retryWrapper.ts:24](https://bitbucket.org/aligent/microservice-util-lib/src/0052f4c/src/retryWrapper/retryWrapper.ts#lines-24)
75
+
76
+ ___
77
+
78
+ ### <a id="retries" name="retries"></a> retries
79
+
80
+ • `Optional` **retries**: `number`
81
+
82
+ The number of retries to attempt after the first run
83
+
84
+ **`Default`**
85
+
86
+ 1
87
+
88
+ #### Defined in
89
+
90
+ [retryWrapper/retryWrapper.ts:7](https://bitbucket.org/aligent/microservice-util-lib/src/0052f4c/src/retryWrapper/retryWrapper.ts#lines-7)
@@ -0,0 +1,281 @@
1
+ @aligent/microservice-util-lib
2
+
3
+ # @aligent/microservice-util-lib
4
+
5
+ ## Table of contents
6
+
7
+ ### Classes
8
+
9
+ - [S3Dao](classes/S3Dao.md)
10
+
11
+ ### Interfaces
12
+
13
+ - [RetryConfig](interfaces/RetryConfig.md)
14
+
15
+ ### Type Aliases
16
+
17
+ - [ObjectMap](modules.md#objectmap)
18
+ - [Remap](modules.md#remap)
19
+
20
+ ### Functions
21
+
22
+ - [chunkBy](modules.md#chunkby)
23
+ - [fetchSsmParams](modules.md#fetchssmparams)
24
+ - [hasDefinedProperties](modules.md#hasdefinedproperties)
25
+ - [remap](modules.md#remap-1)
26
+ - [retryWrapper](modules.md#retrywrapper)
27
+
28
+ ## Type Aliases
29
+
30
+ ### <a id="objectmap" name="objectmap"></a> ObjectMap
31
+
32
+ Ƭ **ObjectMap**: readonly readonly [`string`, `string`, Function?][]
33
+
34
+ A list of keys to keys, with an optional transformer function
35
+
36
+ #### Defined in
37
+
38
+ [remap/remap.ts:15](https://bitbucket.org/aligent/microservice-util-lib/src/0052f4c/src/remap/remap.ts#lines-15)
39
+
40
+ ___
41
+
42
+ ### <a id="remap" name="remap"></a> Remap
43
+
44
+ Ƭ **Remap**<`MapArray`, `Original`\>: `SimplifyIntersection`<`ConstructTypeFromProperties`<`MapArray`, `Original`\>\>
45
+
46
+ #### Type parameters
47
+
48
+ | Name | Type |
49
+ | :------ | :------ |
50
+ | `MapArray` | extends [`ObjectMap`](modules.md#objectmap) |
51
+ | `Original` | extends `Object` |
52
+
53
+ #### Defined in
54
+
55
+ [remap/remap.ts:159](https://bitbucket.org/aligent/microservice-util-lib/src/0052f4c/src/remap/remap.ts#lines-159)
56
+
57
+ ## Functions
58
+
59
+ ### <a id="chunkby" name="chunkby"></a> chunkBy
60
+
61
+ ▸ **chunkBy**<`ArrayItem`\>(`source`, `chunkSize`): `ArrayItem`[][]
62
+
63
+ Split an array into chunks of a certain size
64
+
65
+ **`Example`**
66
+
67
+ ```ts
68
+ chunkBy([1, 2, 3, 4, 5, 6, 7], 2) // [[1, 2], [3, 4], [5, 6], [7]]
69
+ ```
70
+
71
+ #### Type parameters
72
+
73
+ | Name |
74
+ | :------ |
75
+ | `ArrayItem` |
76
+
77
+ #### Parameters
78
+
79
+ | Name | Type | Description |
80
+ | :------ | :------ | :------ |
81
+ | `source` | `ArrayItem`[] | the array to split up |
82
+ | `chunkSize` | `number` | the size of each chunk. (The final chunk will be whatever is remaining) |
83
+
84
+ #### Returns
85
+
86
+ `ArrayItem`[][]
87
+
88
+ #### Defined in
89
+
90
+ [chunkBy/chunkBy.ts:10](https://bitbucket.org/aligent/microservice-util-lib/src/0052f4c/src/chunkBy/chunkBy.ts#lines-10)
91
+
92
+ ___
93
+
94
+ ### <a id="fetchssmparams" name="fetchssmparams"></a> fetchSsmParams
95
+
96
+ ▸ **fetchSsmParams**(`param`): `Promise`<`SSM.Parameter`\>
97
+
98
+ Fetch one SSM parameter
99
+
100
+ #### Parameters
101
+
102
+ | Name | Type | Description |
103
+ | :------ | :------ | :------ |
104
+ | `param` | `string` | key of the parameter to fetch |
105
+
106
+ #### Returns
107
+
108
+ `Promise`<`SSM.Parameter`\>
109
+
110
+ #### Defined in
111
+
112
+ [fetchSsmParams/fetchSsmParams.ts:9](https://bitbucket.org/aligent/microservice-util-lib/src/0052f4c/src/fetchSsmParams/fetchSsmParams.ts#lines-9)
113
+
114
+ ▸ **fetchSsmParams**(`...params`): `Promise`<`SSM.ParameterList`\>
115
+
116
+ Fetch a list of SSM parameters
117
+
118
+ #### Parameters
119
+
120
+ | Name | Type | Description |
121
+ | :------ | :------ | :------ |
122
+ | `...params` | `string`[] | list of parameter keys to fetch |
123
+
124
+ #### Returns
125
+
126
+ `Promise`<`SSM.ParameterList`\>
127
+
128
+ #### Defined in
129
+
130
+ [fetchSsmParams/fetchSsmParams.ts:16](https://bitbucket.org/aligent/microservice-util-lib/src/0052f4c/src/fetchSsmParams/fetchSsmParams.ts#lines-16)
131
+
132
+ ___
133
+
134
+ ### <a id="hasdefinedproperties" name="hasdefinedproperties"></a> hasDefinedProperties
135
+
136
+ ▸ **hasDefinedProperties**<`T`, `K`\>(`obj`, `...keys`): obj is SimplifyIntersection<Required<Pick<T, K\>\> & Omit<T, K\>\>
137
+
138
+ Ensure that the given properties are defined on the object.
139
+
140
+ **`Example`**
141
+
142
+ ```ts
143
+ type Foo = { a?: number; b?: number };
144
+ const foo: Foo = { a: 1, b: 2 };
145
+ if (hasDefinedProperties(foo, 'a')) {
146
+ console.log(foo);
147
+ // ^? const bar: {
148
+ // a: number;
149
+ // b?: number;
150
+ // }
151
+ }
152
+ ```
153
+
154
+ #### Type parameters
155
+
156
+ | Name | Type |
157
+ | :------ | :------ |
158
+ | `T` | extends `Object` |
159
+ | `K` | extends `string` \| `number` \| `symbol` |
160
+
161
+ #### Parameters
162
+
163
+ | Name | Type | Description |
164
+ | :------ | :------ | :------ |
165
+ | `obj` | `object` \| `T` | The object to check. |
166
+ | `...keys` | `K`[] | The keys to check. |
167
+
168
+ #### Returns
169
+
170
+ obj is SimplifyIntersection<Required<Pick<T, K\>\> & Omit<T, K\>\>
171
+
172
+ `true` if the object has the given properties defined, `false` otherwise.
173
+
174
+ #### Defined in
175
+
176
+ [hasPropertiesDefined/hasPropertiesDefined.ts:22](https://bitbucket.org/aligent/microservice-util-lib/src/0052f4c/src/hasPropertiesDefined/hasPropertiesDefined.ts#lines-22)
177
+
178
+ ___
179
+
180
+ ### <a id="remap-1" name="remap-1"></a> remap
181
+
182
+ ▸ **remap**<`Original`, `MapArray`\>(`object`, `map`): [`Remap`](modules.md#remap)<`MapArray`, `Original`\>
183
+
184
+ Map one object's values to another structure
185
+
186
+ **`Example`**
187
+
188
+ without a transformer function
189
+ ```ts
190
+ const map = [
191
+ ['foo', 'baz'],
192
+ ['bar', 'qux.0']
193
+ ] as const;
194
+ const obj = { foo: 'hi', bar: 7 }
195
+ remap(obj, map); // { baz: 'hi', qux: [7] }
196
+ ```
197
+
198
+ **`Example`**
199
+
200
+ with a transformer function
201
+ ```ts
202
+ const map = [
203
+ ['foo', 'baz'],
204
+ ['bar', 'qux.0', (x: number) => x + 1]
205
+ ] as const;
206
+ const obj = { foo: 'hi', bar: 7 }
207
+ remap(obj, map); // { baz: 'hi', qux: [8] }
208
+ ```
209
+
210
+ **`Example`**
211
+
212
+ with an empty initial key
213
+ ```ts
214
+ const map = [
215
+ ['', 'baz', (x: { foo: number, bar: number }) => x.foo + x.bar]
216
+ ]
217
+ const obj = { foo: 3, bar: 7 }
218
+ remap(obj, map); // { baz: 10 }
219
+ ```
220
+
221
+ #### Type parameters
222
+
223
+ | Name | Type |
224
+ | :------ | :------ |
225
+ | `Original` | extends `Object` |
226
+ | `MapArray` | extends readonly readonly [`string`, `string`, (...`args`: `any`[]) => `any`][] |
227
+
228
+ #### Parameters
229
+
230
+ | Name | Type | Description |
231
+ | :------ | :------ | :------ |
232
+ | `object` | `Original` | the object to map from |
233
+ | `map` | `MapArray` | the keys for the mapping |
234
+
235
+ #### Returns
236
+
237
+ [`Remap`](modules.md#remap)<`MapArray`, `Original`\>
238
+
239
+ the remapped object
240
+
241
+ #### Defined in
242
+
243
+ [remap/remap.ts:198](https://bitbucket.org/aligent/microservice-util-lib/src/0052f4c/src/remap/remap.ts#lines-198)
244
+
245
+ ___
246
+
247
+ ### <a id="retrywrapper" name="retrywrapper"></a> retryWrapper
248
+
249
+ ▸ **retryWrapper**<`T`\>(`fn`, `config`): `Promise`<`T`\>
250
+
251
+ Retry an async function if it fails
252
+
253
+ **`Example`**
254
+
255
+ ```ts
256
+ retryWrapper(someAsyncFunction, {
257
+ retries: 3,
258
+ onRetry: (_, error) => console.error(error)
259
+ });
260
+ ```
261
+
262
+ #### Type parameters
263
+
264
+ | Name |
265
+ | :------ |
266
+ | `T` |
267
+
268
+ #### Parameters
269
+
270
+ | Name | Type | Description |
271
+ | :------ | :------ | :------ |
272
+ | `fn` | () => `Promise`<`T`\> | the function to be retried |
273
+ | `config` | [`RetryConfig`](interfaces/RetryConfig.md) | the configuration for retries |
274
+
275
+ #### Returns
276
+
277
+ `Promise`<`T`\>
278
+
279
+ #### Defined in
280
+
281
+ [retryWrapper/retryWrapper.ts:78](https://bitbucket.org/aligent/microservice-util-lib/src/0052f4c/src/retryWrapper/retryWrapper.ts#lines-78)
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@aligent/microservice-util-lib",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "A set of utility functions for Aligent Microservices",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
7
- "build": "tsc",
7
+ "build": "tsc && npm run docs",
8
8
  "lint": "eslint src/*.ts src/**/*.ts",
9
9
  "lint:fix": "eslint --fix src/*.ts src/**/*.ts",
10
10
  "test": "npm run lint && npm run test:types && npm run test:jest",
@@ -14,7 +14,7 @@
14
14
  },
15
15
  "repository": {
16
16
  "type": "git",
17
- "url": "git+ssh://git@bitbucket.org/aligent/microservices-utilities.git"
17
+ "url": "git+ssh://git@bitbucket.org/aligent/microservice-util-lib.git"
18
18
  },
19
19
  "author": "Aligent",
20
20
  "license": "ISC",
@@ -39,6 +39,7 @@
39
39
  "object-hash": "^3.0.0"
40
40
  },
41
41
  "files": [
42
- "dist"
42
+ "dist",
43
+ "docs"
43
44
  ]
44
45
  }