Skip to content

Commit 6898123

Browse files
author
kjelko
committed
move FetchResponse types to public_types
1 parent 7b76774 commit 6898123

File tree

12 files changed

+80
-90
lines changed

12 files changed

+80
-90
lines changed

packages/remote-config/src/client/caching_client.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
*/
1717

1818
import { StorageCache } from '../storage/storage_cache';
19+
import { FetchResponse } from '../public_types';
1920
import {
20-
FetchResponse,
2121
RemoteConfigFetchClient,
2222
FetchRequest
2323
} from './remote_config_fetch_client';
@@ -37,7 +37,7 @@ export class CachingClient implements RemoteConfigFetchClient {
3737
private readonly storage: Storage,
3838
private readonly storageCache: StorageCache,
3939
private readonly logger: Logger
40-
) {}
40+
) { }
4141

4242
/**
4343
* Returns true if the age of the cached fetched configs is less than or equal to
@@ -65,9 +65,9 @@ export class CachingClient implements RemoteConfigFetchClient {
6565

6666
this.logger.debug(
6767
'Config fetch cache check.' +
68-
` Cache age millis: ${cacheAgeMillis}.` +
69-
` Cache max age millis (minimumFetchIntervalMillis setting): ${cacheMaxAgeMillis}.` +
70-
` Is cache hit: ${isCachedDataFresh}.`
68+
` Cache age millis: ${cacheAgeMillis}.` +
69+
` Cache max age millis (minimumFetchIntervalMillis setting): ${cacheMaxAgeMillis}.` +
70+
` Is cache hit: ${isCachedDataFresh}.`
7171
);
7272

7373
return isCachedDataFresh;

packages/remote-config/src/client/remote_config_fetch_client.ts

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { CustomSignals } from '../public_types';
18+
import { CustomSignals, FetchResponse } from '../public_types';
1919

2020
/**
2121
* Defines a client, as in https://en.wikipedia.org/wiki/Client%E2%80%93server_model, for the
@@ -36,13 +36,6 @@ export interface RemoteConfigFetchClient {
3636
fetch(request: FetchRequest): Promise<FetchResponse>;
3737
}
3838

39-
/**
40-
* Defines a self-descriptive reference for config key-value pairs.
41-
*/
42-
export interface FirebaseRemoteConfigObject {
43-
[key: string]: string;
44-
}
45-
4639
/**
4740
* Shims a minimal AbortSignal.
4841
*
@@ -109,39 +102,3 @@ export interface FetchRequest {
109102
customSignals?: CustomSignals;
110103
}
111104

112-
/**
113-
* Defines a successful response (200 or 304).
114-
*
115-
* <p>Modeled after the native {@link Response} interface, but simplified for Remote Config's
116-
* use case.
117-
*/
118-
export interface FetchResponse {
119-
/**
120-
* The HTTP status, which is useful for differentiating success responses with data from
121-
* those without.
122-
*
123-
* <p>{@link RemoteConfigClient} is modeled after the native {@link GlobalFetch} interface, so
124-
* HTTP status is first-class.
125-
*
126-
* <p>Disambiguation: the fetch response returns a legacy "state" value that is redundant with the
127-
* HTTP status code. The former is normalized into the latter.
128-
*/
129-
status: number;
130-
131-
/**
132-
* Defines the ETag response header value.
133-
*
134-
* <p>Only defined for 200 and 304 responses.
135-
*/
136-
eTag?: string;
137-
138-
/**
139-
* Defines the map of parameters returned as "entries" in the fetch response body.
140-
*
141-
* <p>Only defined for 200 responses.
142-
*/
143-
config?: FirebaseRemoteConfigObject;
144-
145-
// Note: we're not extracting experiment metadata until
146-
// ABT and Analytics have Web SDKs.
147-
}

packages/remote-config/src/client/rest_client.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { CustomSignals } from '../public_types';
18+
import { CustomSignals, FetchResponse, FirebaseRemoteConfigObject } from '../public_types';
1919
import {
20-
FetchResponse,
2120
RemoteConfigFetchClient,
22-
FirebaseRemoteConfigObject,
2321
FetchRequest
2422
} from './remote_config_fetch_client';
2523
import { ERROR_FACTORY, ErrorCode } from '../errors';
@@ -57,7 +55,7 @@ export class RestClient implements RemoteConfigFetchClient {
5755
private readonly projectId: string,
5856
private readonly apiKey: string,
5957
private readonly appId: string
60-
) {}
58+
) { }
6159

6260
/**
6361
* Fetches from the Remote Config REST API.

packages/remote-config/src/client/retrying_client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
* limitations under the License.
1616
*/
1717

18+
import { FetchResponse } from '../public_types';
1819
import {
1920
RemoteConfigAbortSignal,
2021
RemoteConfigFetchClient,
21-
FetchResponse,
2222
FetchRequest
2323
} from './remote_config_fetch_client';
2424
import { ThrottleMetadata, Storage } from '../storage/storage';
@@ -91,7 +91,7 @@ export class RetryingClient implements RemoteConfigFetchClient {
9191
constructor(
9292
private readonly client: RemoteConfigFetchClient,
9393
private readonly storage: Storage
94-
) {}
94+
) { }
9595

9696
async fetch(request: FetchRequest): Promise<FetchResponse> {
9797
const throttleMetadata = (await this.storage.getThrottleMetadata()) || {

packages/remote-config/src/public_types.ts

Lines changed: 61 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,6 @@
1616
*/
1717

1818
import { FirebaseApp } from '@firebase/app';
19-
import { FetchResponse } from './client/remote_config_fetch_client';
20-
21-
export {
22-
FetchResponse,
23-
FirebaseRemoteConfigObject
24-
} from './client/remote_config_fetch_client';
25-
26-
/**
27-
* Options for Remote Config initialization.
28-
*
29-
* @public
30-
*/
31-
export interface RemoteConfigOptions {
32-
/**
33-
* The ID of the template to use. If not provided, defaults to "firebase".
34-
*/
35-
templateId?: string;
36-
37-
/**
38-
* Hydrates the state with an initial fetch response.
39-
*/
40-
initialFetchResponse?: FetchResponse;
41-
}
4219

4320
/**
4421
* The Firebase Remote Config service interface.
@@ -73,6 +50,67 @@ export interface RemoteConfig {
7350
lastFetchStatus: FetchStatus;
7451
}
7552

53+
/**
54+
* Defines a self-descriptive reference for config key-value pairs.
55+
*/
56+
export interface FirebaseRemoteConfigObject {
57+
[key: string]: string;
58+
}
59+
60+
/**
61+
* Defines a successful response (200 or 304).
62+
*
63+
* <p>Modeled after the native {@link Response} interface, but simplified for Remote Config's
64+
* use case.
65+
*/
66+
export interface FetchResponse {
67+
/**
68+
* The HTTP status, which is useful for differentiating success responses with data from
69+
* those without.
70+
*
71+
* <p>{@link RemoteConfigClient} is modeled after the native {@link GlobalFetch} interface, so
72+
* HTTP status is first-class.
73+
*
74+
* <p>Disambiguation: the fetch response returns a legacy "state" value that is redundant with the
75+
* HTTP status code. The former is normalized into the latter.
76+
*/
77+
status: number;
78+
79+
/**
80+
* Defines the ETag response header value.
81+
*
82+
* <p>Only defined for 200 and 304 responses.
83+
*/
84+
eTag?: string;
85+
86+
/**
87+
* Defines the map of parameters returned as "entries" in the fetch response body.
88+
*
89+
* <p>Only defined for 200 responses.
90+
*/
91+
config?: FirebaseRemoteConfigObject;
92+
93+
// Note: we're not extracting experiment metadata until
94+
// ABT and Analytics have Web SDKs.
95+
}
96+
97+
/**
98+
* Options for Remote Config initialization.
99+
*
100+
* @public
101+
*/
102+
export interface RemoteConfigOptions {
103+
/**
104+
* The ID of the template to use. If not provided, defaults to "firebase".
105+
*/
106+
templateId?: string;
107+
108+
/**
109+
* Hydrates the state with an initial fetch response.
110+
*/
111+
initialFetchResponse?: FetchResponse;
112+
}
113+
76114
/**
77115
* Indicates the source of a value.
78116
*

packages/remote-config/src/storage/storage.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616
*/
1717

1818
import { FetchStatus, CustomSignals } from '@firebase/remote-config-types';
19-
import {
20-
FetchResponse,
21-
FirebaseRemoteConfigObject
22-
} from '../client/remote_config_fetch_client';
19+
import { FetchResponse, FirebaseRemoteConfigObject } from '../public_types';
2320
import { ERROR_FACTORY, ErrorCode } from '../errors';
2421
import { RC_CUSTOM_SIGNAL_MAX_ALLOWED_SIGNALS } from '../constants';
2522
import { FirebaseError } from '@firebase/util';

packages/remote-config/src/storage/storage_cache.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
*/
1717

1818
import { FetchStatus, CustomSignals } from '@firebase/remote-config-types';
19-
import { FirebaseRemoteConfigObject } from '../client/remote_config_fetch_client';
19+
import { FirebaseRemoteConfigObject } from '../public_types';
2020
import { Storage } from './storage';
2121

2222
/**
2323
* A memory cache layer over storage to support the SDK's synchronous read requirements.
2424
*/
2525
export class StorageCache {
26-
constructor(private readonly storage: Storage) {}
26+
constructor(private readonly storage: Storage) { }
2727

2828
/**
2929
* Memory caches.

packages/remote-config/test/api.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ import { expect } from 'chai';
1919
import {
2020
ensureInitialized,
2121
fetchAndActivate,
22+
FetchResponse,
2223
getRemoteConfig,
2324
getString
24-
} from '../src/index';
25+
} from '../src';
2526
import '../test/setup';
2627
import {
2728
deleteApp,
@@ -30,7 +31,6 @@ import {
3031
_addOrOverwriteComponent
3132
} from '@firebase/app';
3233
import * as sinon from 'sinon';
33-
import { FetchResponse } from '../src/client/remote_config_fetch_client';
3434
import { Component, ComponentType } from '@firebase/component';
3535
import { FirebaseInstallations } from '@firebase/installations-types';
3636
import { openDatabase, APP_NAMESPACE_STORE } from '../src/storage/storage';

packages/remote-config/test/client/caching_client.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
import '../setup';
1919
import { expect } from 'chai';
20+
import { FetchResponse } from '../../src';
2021
import {
2122
RemoteConfigFetchClient,
22-
FetchResponse,
2323
FetchRequest,
2424
RemoteConfigAbortSignal
2525
} from '../../src/client/remote_config_fetch_client';

packages/remote-config/test/client/retrying_client.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
import { expect } from 'chai';
1919
import * as sinon from 'sinon';
2020
import { Storage, ThrottleMetadata } from '../../src/storage/storage';
21+
import { FetchResponse } from '../../src';
2122
import {
2223
RemoteConfigFetchClient,
2324
FetchRequest,
24-
FetchResponse,
2525
RemoteConfigAbortSignal
2626
} from '../../src/client/remote_config_fetch_client';
2727
import {

0 commit comments

Comments
 (0)