Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Included initStandalone #7258

Merged
merged 20 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/pretty-donkeys-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@firebase/database-compat": patch
"@firebase/database": patch
---

Included `initStandalone` as an internal method to RTDB.
27 changes: 24 additions & 3 deletions packages/database-compat/src/api/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {
AppCheckInternalComponentName,
FirebaseAppCheckInternal
} from '@firebase/app-check-interop-types';
import { FirebaseApp } from '@firebase/app-types';
import {
FirebaseAuthInternal,
Expand Down Expand Up @@ -48,13 +51,15 @@ export function initStandalone<T>({
url,
version,
customAuthImpl,
customAppCheckImpl,
namespace,
nodeAdmin = false
}: {
app: FirebaseApp;
url: string;
version: string;
customAuthImpl: FirebaseAuthInternal;
customAppCheckImpl?: FirebaseAppCheckInternal;
namespace: T;
nodeAdmin?: boolean;
}): {
Expand All @@ -63,24 +68,40 @@ export function initStandalone<T>({
} {
_setSDKVersion(version);

const container = new ComponentContainer('database-standalone');
/**
* ComponentContainer('database-standalone') is just a placeholder that doesn't perform
* any actual function.
*/
const authProvider = new Provider<FirebaseAuthInternalName>(
'auth-internal',
new ComponentContainer('database-standalone')
container
);
authProvider.setComponent(
new Component('auth-internal', () => customAuthImpl, ComponentType.PRIVATE)
);

let appCheckProvider: Provider<AppCheckInternalComponentName> = undefined;
if (customAppCheckImpl) {
appCheckProvider = new Provider<AppCheckInternalComponentName>(
'app-check-internal',
container
);
appCheckProvider.setComponent(
new Component(
'app-check-internal',
() => customAppCheckImpl,
ComponentType.PRIVATE
)
);
}

return {
instance: new Database(
_repoManagerDatabaseFromApp(
app,
authProvider,
/* appCheckProvider= */ undefined,
appCheckProvider,
url,
nodeAdmin
),
Expand Down
1 change: 1 addition & 0 deletions packages/database/src/api.standalone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,5 @@ export {
hijackHash as _TEST_ACCESS_hijackHash,
forceRestClient as _TEST_ACCESS_forceRestClient
} from './api/test_access';
export * from './internal/index';
/* eslint-enable camelcase */
99 changes: 99 additions & 0 deletions packages/database/src/internal/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/**
* @license
* Copyright 2023 Google LLC
*
* 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 {
FirebaseAppCheckInternal,
AppCheckInternalComponentName
} from '@firebase/app-check-interop-types';
import { FirebaseApp } from '@firebase/app-types';
import {
FirebaseAuthInternal,
FirebaseAuthInternalName
} from '@firebase/auth-interop-types';
import {
Component,
ComponentContainer,
ComponentType,
Provider
} from '@firebase/component';

import { Database } from '../api.standalone';
import { repoManagerDatabaseFromApp } from '../api/Database';
import { setSDKVersion } from '../core/version';

/**
* Used by console to create a database based on the app,
* passed database URL and a custom auth implementation.
* @internal
* @param app - A valid FirebaseApp-like object
* @param url - A valid Firebase databaseURL
* @param version - custom version e.g. firebase-admin version
* @param customAppCheckImpl - custom app check implementation
* @param customAuthImpl - custom auth implementation
*/
export function _initStandalone({
app,
url,
version,
customAuthImpl,
customAppCheckImpl,
nodeAdmin = false
}: {
app: FirebaseApp;
url: string;
version: string;
customAuthImpl: FirebaseAuthInternal;
customAppCheckImpl?: FirebaseAppCheckInternal;
nodeAdmin?: boolean;
}): Database {
setSDKVersion(version);

/**
* ComponentContainer('database-standalone') is just a placeholder that doesn't perform
* any actual function.
*/
const componentContainer = new ComponentContainer('database-standalone');
const authProvider = new Provider<FirebaseAuthInternalName>(
'auth-internal',
componentContainer
);
let appCheckProvider: Provider<AppCheckInternalComponentName>;
if (customAppCheckImpl) {
appCheckProvider = new Provider<AppCheckInternalComponentName>(
'app-check-internal',
componentContainer
);
appCheckProvider.setComponent(
new Component(
'app-check-internal',
() => customAppCheckImpl,
ComponentType.PRIVATE
)
);
}
authProvider.setComponent(
new Component('auth-internal', () => customAuthImpl, ComponentType.PRIVATE)
);

return repoManagerDatabaseFromApp(
app,
authProvider,
appCheckProvider,
url,
nodeAdmin
);
}