|
1 | 1 | /** |
2 | | - * Copyright 2021-2022, Optimizely |
| 2 | + * Copyright 2021-2022, 2024, Optimizely |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | | - import { LoggerFacade } from '../../modules/logging'; |
17 | | - import { HttpPollingDatafileManager } from '../../modules/datafile-manager/index.react_native'; |
18 | | - import { DatafileOptions, DatafileManagerConfig, DatafileManager } from '../../shared_types'; |
19 | | - import { toDatafile, tryCreatingProjectConfig } from '../../core/project_config'; |
20 | | - import fns from '../../utils/fns'; |
| 16 | +import { LoggerFacade } from '../../modules/logging'; |
| 17 | +import { HttpPollingDatafileManager } from '../../modules/datafile-manager/index.react_native'; |
| 18 | +import { DatafileOptions, DatafileManager, PersistentCacheProvider } from '../../shared_types'; |
| 19 | +import { DatafileManagerConfig } from '../../modules/datafile-manager/index.react_native'; |
| 20 | +import { toDatafile, tryCreatingProjectConfig } from '../../core/project_config'; |
| 21 | +import fns from '../../utils/fns'; |
21 | 22 |
|
22 | | - export function createHttpPollingDatafileManager( |
23 | | - sdkKey: string, |
24 | | - logger: LoggerFacade, |
25 | | - // TODO[OASIS-6649]: Don't use object type |
26 | | - // eslint-disable-next-line @typescript-eslint/ban-types |
27 | | - datafile?: string | object, |
28 | | - datafileOptions?: DatafileOptions, |
| 23 | +export function createHttpPollingDatafileManager( |
| 24 | + sdkKey: string, |
| 25 | + logger: LoggerFacade, |
| 26 | + // TODO[OASIS-6649]: Don't use object type |
| 27 | + // eslint-disable-next-line @typescript-eslint/ban-types |
| 28 | + datafile?: string | object, |
| 29 | + datafileOptions?: DatafileOptions, |
| 30 | + persistentCacheProvider?: PersistentCacheProvider, |
29 | 31 | ): DatafileManager { |
30 | | - const datafileManagerConfig: DatafileManagerConfig = { sdkKey }; |
31 | | - if (datafileOptions === undefined || (typeof datafileOptions === 'object' && datafileOptions !== null)) { |
32 | | - fns.assign(datafileManagerConfig, datafileOptions); |
33 | | - } |
34 | | - if (datafile) { |
35 | | - const { configObj, error } = tryCreatingProjectConfig({ |
36 | | - datafile: datafile, |
37 | | - jsonSchemaValidator: undefined, |
38 | | - logger: logger, |
39 | | - }); |
40 | | - |
41 | | - if (error) { |
42 | | - logger.error(error); |
43 | | - } |
44 | | - if (configObj) { |
45 | | - datafileManagerConfig.datafile = toDatafile(configObj); |
46 | | - } |
47 | | - } |
48 | | - return new HttpPollingDatafileManager(datafileManagerConfig); |
49 | | - } |
| 32 | + const datafileManagerConfig: DatafileManagerConfig = { sdkKey }; |
| 33 | + if (datafileOptions === undefined || (typeof datafileOptions === 'object' && datafileOptions !== null)) { |
| 34 | + fns.assign(datafileManagerConfig, datafileOptions); |
| 35 | + } |
| 36 | + if (datafile) { |
| 37 | + const { configObj, error } = tryCreatingProjectConfig({ |
| 38 | + datafile: datafile, |
| 39 | + jsonSchemaValidator: undefined, |
| 40 | + logger: logger, |
| 41 | + }); |
| 42 | + |
| 43 | + if (error) { |
| 44 | + logger.error(error); |
| 45 | + } |
| 46 | + if (configObj) { |
| 47 | + datafileManagerConfig.datafile = toDatafile(configObj); |
| 48 | + } |
| 49 | + } |
| 50 | + if (persistentCacheProvider) { |
| 51 | + datafileManagerConfig.cache = persistentCacheProvider(); |
| 52 | + } |
| 53 | + return new HttpPollingDatafileManager(datafileManagerConfig); |
| 54 | +} |
0 commit comments