|
1 | 1 | import { fromBase64 } from '@aws-sdk/util-base64-node'; |
| 2 | +import { GetOptions } from './GetOptions'; |
| 3 | +import { GetMultipleOptions } from './GetMultipleOptions'; |
| 4 | +import { ExpirableValue } from './ExpirableValue'; |
2 | 5 | import { GetParameterError, TransformParameterError } from './Exceptions'; |
3 | | -import type { BaseProviderInterface, ExpirableValueInterface, GetMultipleOptionsInterface, GetOptionsInterface, TransformOptions } from './types'; |
| 6 | +import type { BaseProviderInterface, GetMultipleOptionsInterface, GetOptionsInterface, TransformOptions } from './types'; |
4 | 7 |
|
5 | | -const DEFAULT_MAX_AGE_SECS = 5; |
6 | 8 | const TRANSFORM_METHOD_JSON = 'json'; |
7 | 9 | const TRANSFORM_METHOD_BINARY = 'binary'; |
8 | 10 |
|
9 | | -class GetOptions implements GetOptionsInterface { |
10 | | - public forceFetch: boolean = false; |
11 | | - public maxAge: number = DEFAULT_MAX_AGE_SECS; |
12 | | - public sdkOptions?: unknown; |
13 | | - public transform?: TransformOptions; |
14 | | - |
15 | | - public constructor(options: GetOptionsInterface = {}) { |
16 | | - Object.assign(this, options); |
17 | | - } |
18 | | -} |
19 | | - |
20 | | -class GetMultipleOptions implements GetMultipleOptionsInterface { |
21 | | - public forceFetch: boolean = false; |
22 | | - public maxAge: number = DEFAULT_MAX_AGE_SECS; |
23 | | - public sdkOptions?: unknown; |
24 | | - public throwOnTransformError: boolean = false; |
25 | | - public transform?: TransformOptions; |
26 | | - |
27 | | - public constructor(options: GetMultipleOptionsInterface) { |
28 | | - Object.assign(this, options); |
29 | | - } |
30 | | -} |
31 | | - |
32 | | -class ExpirableValue implements ExpirableValueInterface { |
33 | | - public ttl: number; |
34 | | - public value: string | Record<string, unknown>; |
35 | | - |
36 | | - public constructor(value: string | Record<string, unknown>, maxAge: number) { |
37 | | - this.value = value; |
38 | | - const timeNow = new Date(); |
39 | | - this.ttl = timeNow.setSeconds(timeNow.getSeconds() + maxAge); |
40 | | - } |
41 | | - |
42 | | - public isExpired(): boolean { |
43 | | - return this.ttl < Date.now(); |
44 | | - } |
45 | | -} |
46 | | - |
47 | 11 | abstract class BaseProvider implements BaseProviderInterface { |
48 | 12 | public store: Map<string, ExpirableValue> = new Map; |
49 | 13 |
|
|
0 commit comments