1
0
mirror of https://github.com/musix-org/musix-oss synced 2025-06-18 14:56:00 +00:00
This commit is contained in:
MatteZ02
2020-03-03 22:30:50 +02:00
parent edfcc6f474
commit 30022c7634
11800 changed files with 1984416 additions and 1 deletions

View File

@ -0,0 +1,45 @@
/**
* @license
* Copyright 2019 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { StorageCache } from '../storage/storage_cache';
import { FetchResponse, RemoteConfigFetchClient, FetchRequest } from './remote_config_fetch_client';
import { Storage } from '../storage/storage';
import { Logger } from '@firebase/logger';
/**
* Implements the {@link RemoteConfigClient} abstraction with success response caching.
*
* <p>Comparable to the browser's Cache API for responses, but the Cache API requires a Service
* Worker, which requires HTTPS, which would significantly complicate SDK installation. Also, the
* Cache API doesn't support matching entries by time.
*/
export declare class CachingClient implements RemoteConfigFetchClient {
private readonly client;
private readonly storage;
private readonly storageCache;
private readonly logger;
constructor(client: RemoteConfigFetchClient, storage: Storage, storageCache: StorageCache, logger: Logger);
/**
* Returns true if the age of the cached fetched configs is less than or equal to
* {@link Settings#minimumFetchIntervalInSeconds}.
*
* <p>This is comparable to passing `headers = { 'Cache-Control': max-age <maxAge> }` to the
* native Fetch API.
*
* <p>Visible for testing.
*/
isCachedDataFresh(cacheMaxAgeMillis: number, lastSuccessfulFetchTimestampMillis: number | undefined): boolean;
fetch(request: FetchRequest): Promise<FetchResponse>;
}

View File

@ -0,0 +1,37 @@
/**
* @license
* Copyright 2019 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* The maximum milliseconds to increase to.
*
* <p>Visible for testing
*/
export declare const MAX_VALUE_MILLIS: number;
/**
* The percentage of backoff time to randomize by.
* See
* http://go/safe-client-behavior#step-1-determine-the-appropriate-retry-interval-to-handle-spike-traffic
* for context.
*
* <p>Visible for testing
*/
export declare const RANDOM_FACTOR = 0.5;
/**
* Based on the backoff method from
* https://github.com/google/closure-library/blob/master/closure/goog/math/exponentialbackoff.js.
* Extracted here so we don't need to pass metadata and a stateful ExponentialBackoff object around.
*/
export declare function calculateBackoffMillis(backoffCount: number): number;

View File

@ -0,0 +1,123 @@
/**
* @license
* Copyright 2019 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Defines a client, as in https://en.wikipedia.org/wiki/Client%E2%80%93server_model, for the
* Remote Config server (https://firebase.google.com/docs/reference/remote-config/rest).
*
* <p>Abstracts throttle, response cache and network implementation details.
*
* <p>Modeled after the native {@link GlobalFetch} interface, which is relatively modern and
* convenient, but simplified for Remote Config's use case.
*
* Disambiguation: {@link GlobalFetch} interface and the Remote Config service define "fetch"
* methods. The RestClient uses the former to make HTTP calls. This interface abstracts the latter.
*/
export interface RemoteConfigFetchClient {
/**
* @throws if response status is not 200 or 304.
*/
fetch(request: FetchRequest): Promise<FetchResponse>;
}
/**
* Defines a self-descriptive reference for config key-value pairs.
*/
export interface FirebaseRemoteConfigObject {
[key: string]: string;
}
/**
* Shims a minimal AbortSignal.
*
* <p>AbortController's AbortSignal conveniently decouples fetch timeout logic from other aspects
* of networking, such as retries. Firebase doesn't use AbortController enough to justify a
* polyfill recommendation, like we do with the Fetch API, but this minimal shim can easily be
* swapped out if/when we do.
*/
export declare class RemoteConfigAbortSignal {
listeners: Array<() => void>;
addEventListener(listener: () => void): void;
abort(): void;
}
/**
* Defines per-request inputs for the Remote Config fetch request.
*
* <p>Modeled after the native {@link Request} interface, but simplified for Remote Config's
* use case.
*/
export interface FetchRequest {
/**
* Uses cached config if it is younger than this age.
*
* <p>Required because it's defined by settings, which always have a value.
*
* <p>Comparable to passing `headers = { 'Cache-Control': max-age <maxAge> }` to the native
* Fetch API.
*/
cacheMaxAgeMillis: number;
/**
* An event bus for the signal to abort a request.
*
* <p>Required because all requests should be abortable.
*
* <p>Comparable to the native
* Fetch API's "signal" field on its request configuration object
* https://fetch.spec.whatwg.org/#dom-requestinit-signal.
*
* <p>Disambiguation: Remote Config commonly refers to API inputs as
* "signals". See the private ConfigFetchRequestBody interface for those:
* http://google3/firebase/remote_config/web/src/core/rest_client.ts?l=14&rcl=255515243.
*/
signal: RemoteConfigAbortSignal;
/**
* The ETag header value from the last response.
*
* <p>Optional in case this is the first request.
*
* <p>Comparable to passing `headers = { 'If-None-Match': <eTag> }` to the native Fetch API.
*/
eTag?: string;
}
/**
* Defines a successful response (200 or 304).
*
* <p>Modeled after the native {@link Response} interface, but simplified for Remote Config's
* use case.
*/
export interface FetchResponse {
/**
* The HTTP status, which is useful for differentiating success responses with data from
* those without.
*
* <p>{@link RemoteConfigClient} is modeled after the native {@link GlobalFetch} interface, so
* HTTP status is first-class.
*
* <p>Disambiguation: the fetch response returns a legacy "state" value that is redundant with the
* HTTP status code. The former is normalized into the latter.
*/
status: number;
/**
* Defines the ETag response header value.
*
* <p>Only defined for 200 and 304 responses.
*/
eTag?: string;
/**
* Defines the map of parameters returned as "entries" in the fetch response body.
*
* <p>Only defined for 200 responses.
*/
config?: FirebaseRemoteConfigObject;
}

View File

@ -0,0 +1,40 @@
/**
* @license
* Copyright 2019 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { FirebaseInstallations } from '@firebase/installations-types';
import { FetchResponse, RemoteConfigFetchClient, FetchRequest } from './remote_config_fetch_client';
/**
* Implements the Client abstraction for the Remote Config REST API.
*/
export declare class RestClient implements RemoteConfigFetchClient {
private readonly firebaseInstallations;
private readonly sdkVersion;
private readonly namespace;
private readonly projectId;
private readonly apiKey;
private readonly appId;
constructor(firebaseInstallations: FirebaseInstallations, sdkVersion: string, namespace: string, projectId: string, apiKey: string, appId: string);
/**
* Fetches from the Remote Config REST API.
*
* @throws a {@link ErrorCode.FETCH_NETWORK} error if {@link GlobalFetch#fetch} can't
* connect to the network.
* @throws a {@link ErrorCode.FETCH_PARSE} error if {@link Response#json} can't parse the
* fetch response.
* @throws a {@link ErrorCode.FETCH_STATUS} error if the service returns an HTTP error status.
*/
fetch(request: FetchRequest): Promise<FetchResponse>;
}

View File

@ -0,0 +1,49 @@
/**
* @license
* Copyright 2019 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { RemoteConfigAbortSignal, RemoteConfigFetchClient, FetchResponse, FetchRequest } from './remote_config_fetch_client';
import { ThrottleMetadata, Storage } from '../storage/storage';
/**
* Supports waiting on a backoff by:
*
* <ul>
* <li>Promisifying setTimeout, so we can set a timeout in our Promise chain</li>
* <li>Listening on a signal bus for abort events, just like the Fetch API</li>
* <li>Failing in the same way the Fetch API fails, so timing out a live request and a throttled
* request appear the same.</li>
* </ul>
*
* <p>Visible for testing.
*/
export declare function setAbortableTimeout(signal: RemoteConfigAbortSignal, throttleEndTimeMillis: number): Promise<void>;
/**
* Decorates a Client with retry logic.
*
* <p>Comparable to CachingClient, but uses backoff logic instead of cache max age and doesn't cache
* responses (because the SDK has no use for error responses).
*/
export declare class RetryingClient implements RemoteConfigFetchClient {
private readonly client;
private readonly storage;
constructor(client: RemoteConfigFetchClient, storage: Storage);
fetch(request: FetchRequest): Promise<FetchResponse>;
/**
* A recursive helper for attempting a fetch request repeatedly.
*
* @throws any non-retriable errors.
*/
attemptFetch(request: FetchRequest, { throttleEndTimeMillis, backoffCount }: ThrottleMetadata): Promise<FetchResponse>;
}

View File

@ -0,0 +1,61 @@
/**
* @license
* Copyright 2019 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ErrorFactory } from '@firebase/util';
export declare const enum ErrorCode {
REGISTRATION_WINDOW = "registration-window",
REGISTRATION_PROJECT_ID = "registration-project-id",
REGISTRATION_API_KEY = "registration-api-key",
REGISTRATION_APP_ID = "registration-app-id",
STORAGE_OPEN = "storage-open",
STORAGE_GET = "storage-get",
STORAGE_SET = "storage-set",
STORAGE_DELETE = "storage-delete",
FETCH_NETWORK = "fetch-client-network",
FETCH_TIMEOUT = "fetch-timeout",
FETCH_THROTTLE = "fetch-throttle",
FETCH_PARSE = "fetch-client-parse",
FETCH_STATUS = "fetch-status"
}
interface ErrorParams {
[ErrorCode.STORAGE_OPEN]: {
originalErrorMessage: string | undefined;
};
[ErrorCode.STORAGE_GET]: {
originalErrorMessage: string | undefined;
};
[ErrorCode.STORAGE_SET]: {
originalErrorMessage: string | undefined;
};
[ErrorCode.STORAGE_DELETE]: {
originalErrorMessage: string | undefined;
};
[ErrorCode.FETCH_NETWORK]: {
originalErrorMessage: string;
};
[ErrorCode.FETCH_THROTTLE]: {
throttleEndTimeMillis: number;
};
[ErrorCode.FETCH_PARSE]: {
originalErrorMessage: string;
};
[ErrorCode.FETCH_STATUS]: {
httpStatus: number;
};
}
export declare const ERROR_FACTORY: ErrorFactory<ErrorCode, ErrorParams>;
export declare function hasErrorCode(e: Error, errorCode: ErrorCode): boolean;
export {};

View File

@ -0,0 +1,26 @@
/**
* @license
* Copyright 2019 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Attempts to get the most accurate browser language setting.
*
* <p>Adapted from getUserLanguage in packages/auth/src/utils.js for TypeScript.
*
* <p>Defers default language specification to server logic for consistency.
*
* @param navigatorLanguage Enables tests to override read-only {@link NavigatorLanguage}.
*/
export declare function getUserLanguage(navigatorLanguage?: NavigatorLanguage): string;

View File

@ -0,0 +1,60 @@
/**
* @license
* Copyright 2019 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { FirebaseApp } from '@firebase/app-types';
import { RemoteConfig as RemoteConfigType, FetchStatus, Settings, Value as ValueType, LogLevel as RemoteConfigLogLevel } from '@firebase/remote-config-types';
import { StorageCache } from './storage/storage_cache';
import { RemoteConfigFetchClient } from './client/remote_config_fetch_client';
import { Storage } from './storage/storage';
import { Logger } from '@firebase/logger';
/**
* Encapsulates business logic mapping network and storage dependencies to the public SDK API.
*
* See {@link https://github.com/FirebasePrivate/firebase-js-sdk/blob/master/packages/firebase/index.d.ts|interface documentation} for method descriptions.
*/
export declare class RemoteConfig implements RemoteConfigType {
readonly app: FirebaseApp;
private readonly _client;
private readonly _storageCache;
private readonly _storage;
private readonly _logger;
private _isInitializationComplete;
private _initializePromise?;
settings: Settings;
defaultConfig: {
[key: string]: string | number | boolean;
};
setLogLevel(logLevel: RemoteConfigLogLevel): void;
get fetchTimeMillis(): number;
get lastFetchStatus(): FetchStatus;
constructor(app: FirebaseApp, _client: RemoteConfigFetchClient, _storageCache: StorageCache, _storage: Storage, _logger: Logger);
activate(): Promise<boolean>;
ensureInitialized(): Promise<void>;
/**
* @throws a {@link ErrorCode.FETCH_CLIENT_TIMEOUT} if the request takes longer than
* {@link Settings.fetchTimeoutInSeconds} or
* {@link DEFAULT_FETCH_TIMEOUT_SECONDS}.
*/
fetch(): Promise<void>;
fetchAndActivate(): Promise<boolean>;
getAll(): {
[key: string]: ValueType;
};
getBoolean(key: string): boolean;
getNumber(key: string): number;
getString(key: string): string;
getValue(key: string): ValueType;
}

View File

@ -0,0 +1,76 @@
/**
* @license
* Copyright 2019 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { FetchStatus } from '@firebase/remote-config-types';
import { FetchResponse, FirebaseRemoteConfigObject } from '../client/remote_config_fetch_client';
/**
* A general-purpose store keyed by app + namespace + {@link
* ProjectNamespaceKeyFieldValue}.
*
* <p>The Remote Config SDK can be used with multiple app installations, and each app can interact
* with multiple namespaces, so this store uses app (ID + name) and namespace as common parent keys
* for a set of key-value pairs. See {@link Storage#createCompositeKey}.
*
* <p>Visible for testing.
*/
export declare const APP_NAMESPACE_STORE = "app_namespace_store";
/**
* Encapsulates metadata concerning throttled fetch requests.
*/
export interface ThrottleMetadata {
backoffCount: number;
throttleEndTimeMillis: number;
}
/**
* Provides type-safety for the "key" field used by {@link APP_NAMESPACE_STORE}.
*
* <p>This seems like a small price to avoid potentially subtle bugs caused by a typo.
*/
declare type ProjectNamespaceKeyFieldValue = 'active_config' | 'active_config_etag' | 'last_fetch_status' | 'last_successful_fetch_timestamp_millis' | 'last_successful_fetch_response' | 'settings' | 'throttle_metadata';
export declare function openDatabase(): Promise<IDBDatabase>;
/**
* Abstracts data persistence.
*/
export declare class Storage {
private readonly appId;
private readonly appName;
private readonly namespace;
private readonly openDbPromise;
/**
* @param appId enables storage segmentation by app (ID + name).
* @param appName enables storage segmentation by app (ID + name).
* @param namespace enables storage segmentation by namespace.
*/
constructor(appId: string, appName: string, namespace: string, openDbPromise?: Promise<IDBDatabase>);
getLastFetchStatus(): Promise<FetchStatus | undefined>;
setLastFetchStatus(status: FetchStatus): Promise<void>;
getLastSuccessfulFetchTimestampMillis(): Promise<number | undefined>;
setLastSuccessfulFetchTimestampMillis(timestamp: number): Promise<void>;
getLastSuccessfulFetchResponse(): Promise<FetchResponse | undefined>;
setLastSuccessfulFetchResponse(response: FetchResponse): Promise<void>;
getActiveConfig(): Promise<FirebaseRemoteConfigObject | undefined>;
setActiveConfig(config: FirebaseRemoteConfigObject): Promise<void>;
getActiveConfigEtag(): Promise<string | undefined>;
setActiveConfigEtag(etag: string): Promise<void>;
getThrottleMetadata(): Promise<ThrottleMetadata | undefined>;
setThrottleMetadata(metadata: ThrottleMetadata): Promise<void>;
deleteThrottleMetadata(): Promise<void>;
get<T>(key: ProjectNamespaceKeyFieldValue): Promise<T | undefined>;
set<T>(key: ProjectNamespaceKeyFieldValue, value: T): Promise<void>;
delete(key: ProjectNamespaceKeyFieldValue): Promise<void>;
createCompositeKey(key: ProjectNamespaceKeyFieldValue): string;
}
export {};

View File

@ -0,0 +1,48 @@
/**
* @license
* Copyright 2019 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { FetchStatus } from '@firebase/remote-config-types';
import { FirebaseRemoteConfigObject } from '../client/remote_config_fetch_client';
import { Storage } from './storage';
/**
* A memory cache layer over storage to support the SDK's synchronous read requirements.
*/
export declare class StorageCache {
private readonly storage;
constructor(storage: Storage);
/**
* Memory caches.
*/
private lastFetchStatus?;
private lastSuccessfulFetchTimestampMillis?;
private activeConfig?;
/**
* Memory-only getters
*/
getLastFetchStatus(): FetchStatus | undefined;
getLastSuccessfulFetchTimestampMillis(): number | undefined;
getActiveConfig(): FirebaseRemoteConfigObject | undefined;
/**
* Read-ahead getter
*/
loadFromStorage(): Promise<void>;
/**
* Write-through setters
*/
setLastFetchStatus(status: FetchStatus): Promise<void>;
setLastSuccessfulFetchTimestampMillis(timestampMillis: number): Promise<void>;
setActiveConfig(activeConfig: FirebaseRemoteConfigObject): Promise<void>;
}

View File

@ -0,0 +1,26 @@
/**
* @license
* Copyright 2019 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Value as ValueType, ValueSource } from '@firebase/remote-config-types';
export declare class Value implements ValueType {
private readonly _source;
private readonly _value;
constructor(_source: ValueSource, _value?: string);
asString(): string;
asBoolean(): boolean;
asNumber(): number;
getSource(): ValueSource;
}