Skip to content

Commit 82d7df4

Browse files
authoredJul 12, 2023
Included initStandalone (#7258)
Added private `initStandalone` API into modular SDK
1 parent b58a617 commit 82d7df4

File tree

4 files changed

+130
-3
lines changed

4 files changed

+130
-3
lines changed
 

‎.changeset/pretty-donkeys-brush.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@firebase/database-compat": patch
3+
"@firebase/database": patch
4+
---
5+
6+
Included `initStandalone` as an internal method to RTDB.

‎packages/database-compat/src/api/internal.ts

+24-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
17+
import {
18+
AppCheckInternalComponentName,
19+
FirebaseAppCheckInternal
20+
} from '@firebase/app-check-interop-types';
1821
import { FirebaseApp } from '@firebase/app-types';
1922
import {
2023
FirebaseAuthInternal,
@@ -48,13 +51,15 @@ export function initStandalone<T>({
4851
url,
4952
version,
5053
customAuthImpl,
54+
customAppCheckImpl,
5155
namespace,
5256
nodeAdmin = false
5357
}: {
5458
app: FirebaseApp;
5559
url: string;
5660
version: string;
5761
customAuthImpl: FirebaseAuthInternal;
62+
customAppCheckImpl?: FirebaseAppCheckInternal;
5863
namespace: T;
5964
nodeAdmin?: boolean;
6065
}): {
@@ -63,24 +68,40 @@ export function initStandalone<T>({
6368
} {
6469
_setSDKVersion(version);
6570

71+
const container = new ComponentContainer('database-standalone');
6672
/**
6773
* ComponentContainer('database-standalone') is just a placeholder that doesn't perform
6874
* any actual function.
6975
*/
7076
const authProvider = new Provider<FirebaseAuthInternalName>(
7177
'auth-internal',
72-
new ComponentContainer('database-standalone')
78+
container
7379
);
7480
authProvider.setComponent(
7581
new Component('auth-internal', () => customAuthImpl, ComponentType.PRIVATE)
7682
);
7783

84+
let appCheckProvider: Provider<AppCheckInternalComponentName> = undefined;
85+
if (customAppCheckImpl) {
86+
appCheckProvider = new Provider<AppCheckInternalComponentName>(
87+
'app-check-internal',
88+
container
89+
);
90+
appCheckProvider.setComponent(
91+
new Component(
92+
'app-check-internal',
93+
() => customAppCheckImpl,
94+
ComponentType.PRIVATE
95+
)
96+
);
97+
}
98+
7899
return {
79100
instance: new Database(
80101
_repoManagerDatabaseFromApp(
81102
app,
82103
authProvider,
83-
/* appCheckProvider= */ undefined,
104+
appCheckProvider,
84105
url,
85106
nodeAdmin
86107
),

‎packages/database/src/api.standalone.ts

+1
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,5 @@ export {
9696
hijackHash as _TEST_ACCESS_hijackHash,
9797
forceRestClient as _TEST_ACCESS_forceRestClient
9898
} from './api/test_access';
99+
export * from './internal/index';
99100
/* eslint-enable camelcase */
+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/**
2+
* @license
3+
* Copyright 2023 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import {
19+
FirebaseAppCheckInternal,
20+
AppCheckInternalComponentName
21+
} from '@firebase/app-check-interop-types';
22+
import { FirebaseApp } from '@firebase/app-types';
23+
import {
24+
FirebaseAuthInternal,
25+
FirebaseAuthInternalName
26+
} from '@firebase/auth-interop-types';
27+
import {
28+
Component,
29+
ComponentContainer,
30+
ComponentType,
31+
Provider
32+
} from '@firebase/component';
33+
34+
import { Database } from '../api.standalone';
35+
import { repoManagerDatabaseFromApp } from '../api/Database';
36+
import { setSDKVersion } from '../core/version';
37+
38+
/**
39+
* Used by console to create a database based on the app,
40+
* passed database URL and a custom auth implementation.
41+
* @internal
42+
* @param app - A valid FirebaseApp-like object
43+
* @param url - A valid Firebase databaseURL
44+
* @param version - custom version e.g. firebase-admin version
45+
* @param customAppCheckImpl - custom app check implementation
46+
* @param customAuthImpl - custom auth implementation
47+
*/
48+
export function _initStandalone({
49+
app,
50+
url,
51+
version,
52+
customAuthImpl,
53+
customAppCheckImpl,
54+
nodeAdmin = false
55+
}: {
56+
app: FirebaseApp;
57+
url: string;
58+
version: string;
59+
customAuthImpl: FirebaseAuthInternal;
60+
customAppCheckImpl?: FirebaseAppCheckInternal;
61+
nodeAdmin?: boolean;
62+
}): Database {
63+
setSDKVersion(version);
64+
65+
/**
66+
* ComponentContainer('database-standalone') is just a placeholder that doesn't perform
67+
* any actual function.
68+
*/
69+
const componentContainer = new ComponentContainer('database-standalone');
70+
const authProvider = new Provider<FirebaseAuthInternalName>(
71+
'auth-internal',
72+
componentContainer
73+
);
74+
let appCheckProvider: Provider<AppCheckInternalComponentName>;
75+
if (customAppCheckImpl) {
76+
appCheckProvider = new Provider<AppCheckInternalComponentName>(
77+
'app-check-internal',
78+
componentContainer
79+
);
80+
appCheckProvider.setComponent(
81+
new Component(
82+
'app-check-internal',
83+
() => customAppCheckImpl,
84+
ComponentType.PRIVATE
85+
)
86+
);
87+
}
88+
authProvider.setComponent(
89+
new Component('auth-internal', () => customAuthImpl, ComponentType.PRIVATE)
90+
);
91+
92+
return repoManagerDatabaseFromApp(
93+
app,
94+
authProvider,
95+
appCheckProvider,
96+
url,
97+
nodeAdmin
98+
);
99+
}

0 commit comments

Comments
 (0)
Please sign in to comment.