Skip to content

Commit f3296f5

Browse files
Merge
2 parents 3db3e59 + 731a695 commit f3296f5

File tree

13 files changed

+231
-55
lines changed

13 files changed

+231
-55
lines changed

packages/firebase/src/index.rn.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ import { name, version } from '../package.json';
2020

2121
import '../auth';
2222
import '../database';
23+
// TODO(b/158625454): Storage doesn't actually work by default in RN (it uses
24+
// `atob`). We should provide a RN build that works out of the box.
2325
import '../storage';
26+
import '../firestore';
2427

2528
firebase.registerVersion(name, version, 'rn');
2629

packages/firestore/index.node.memory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function registerFirestore(instance: FirebaseNamespace): void {
3434
instance,
3535
(app, auth) => new Firestore(app, auth, new MemoryComponentProvider())
3636
);
37-
instance.registerVersion(name, version);
37+
instance.registerVersion(name, version, 'node');
3838
}
3939

4040
registerFirestore(firebase);

packages/firestore/index.rn.memory.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* @license
3+
* Copyright 2020 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 firebase from '@firebase/app';
19+
import { FirebaseNamespace } from '@firebase/app-types';
20+
21+
import { Firestore } from './src/api/database';
22+
import { MemoryComponentProvider } from './src/core/component_provider';
23+
import { configureForFirebase } from './src/platform/config';
24+
25+
import './register-module';
26+
27+
import { name, version } from './package.json';
28+
29+
/**
30+
* Registers the memory-only Firestore build for ReactNative with the components
31+
* framework.
32+
*/
33+
export function registerFirestore(instance: FirebaseNamespace): void {
34+
configureForFirebase(
35+
instance,
36+
(app, auth) => new Firestore(app, auth, new MemoryComponentProvider())
37+
);
38+
instance.registerVersion(name, version, 'rn');
39+
}
40+
41+
registerFirestore(firebase);

packages/firestore/index.rn.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* @license
3+
* Copyright 2020 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+
import firebase from '@firebase/app';
18+
import { FirebaseNamespace } from '@firebase/app-types';
19+
20+
import { Firestore } from './src/api/database';
21+
import { IndexedDbComponentProvider } from './src/core/component_provider';
22+
import { configureForFirebase } from './src/platform/config';
23+
24+
import './register-module';
25+
import { name, version } from './package.json';
26+
27+
/**
28+
* Registers the main Firestore ReactNative build with the components framework.
29+
* Persistence can be enabled via `firebase.firestore().enablePersistence()`.
30+
*/
31+
export function registerFirestore(instance: FirebaseNamespace): void {
32+
configureForFirebase(
33+
instance,
34+
(app, auth) => new Firestore(app, auth, new IndexedDbComponentProvider())
35+
);
36+
instance.registerVersion(name, version, 'rn');
37+
}
38+
39+
registerFirestore(firebase);

packages/firestore/memory/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"description": "A memory-only build of the Cloud Firestore JS SDK.",
44
"main": "../dist/index.memory.node.cjs.js",
55
"main-esm2017": "../dist/index.memory.node.esm2017.js",
6+
"react-native": "../dist/index.memory.rn.esm2017.js",
67
"browser": "../dist/index.memory.cjs.js",
78
"module": "../dist/index.memory.esm.js",
89
"esm2017": "../dist/index.memory.esm2017.js",

packages/firestore/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
},
4242
"main": "dist/index.node.cjs.js",
4343
"main-esm2017": "dist/index.node.esm2017.js",
44+
"react-native": "dist/index.rn.esm2017.js",
4445
"browser": "dist/index.cjs.js",
4546
"module": "dist/index.esm.js",
4647
"esm2017": "dist/index.esm2017.js",
@@ -56,7 +57,7 @@
5657
"@firebase/logger": "0.2.5",
5758
"@firebase/util": "0.2.48",
5859
"@firebase/webchannel-wrapper": "0.2.41",
59-
"@grpc/grpc-js": "0.8.1",
60+
"@grpc/grpc-js": "^1.0.0",
6061
"@grpc/proto-loader": "^0.5.0",
6162
"tslib": "^1.11.1"
6263
},

packages/firestore/rollup.config.es2017.js

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ import {
3232
firestoreTransformers,
3333
manglePrivatePropertiesOptions,
3434
resolveNodeExterns,
35-
resolveBrowserExterns
35+
resolveBrowserExterns,
36+
generateAliasConfig
3637
} from './rollup.shared';
3738

3839
// Firestore is released in a number of different build configurations:
@@ -62,22 +63,7 @@ import {
6263
// MARK: Browser builds
6364

6465
const browserBuildPlugins = [
65-
alias({
66-
entries: [
67-
{
68-
find: /(.*)\/platform\/platform(.*)/,
69-
replacement: '$1/platform_browser/browser_platform$2'
70-
},
71-
{
72-
find: /(.*)\/platform\/random_bytes(.*)/,
73-
replacement: '$1/platform_browser/browser_random_bytes$2'
74-
},
75-
{
76-
find: /(.*)\/platform\/format_json(.*)/,
77-
replacement: '$1/platform_browser/browser_format_json$2'
78-
}
79-
]
80-
}),
66+
alias(generateAliasConfig('browser')),
8167
typescriptPlugin({
8268
typescript,
8369
tsconfigOverride: {
@@ -117,25 +103,40 @@ const browserBuilds = [
117103
}
118104
];
119105

106+
const reactNativeBuildPlugins = [
107+
alias(generateAliasConfig('rn')),
108+
...browserBuildPlugins.slice(1)
109+
];
110+
111+
const reactNativeBuilds = [
112+
// Persistence build
113+
{
114+
input: 'index.rn.ts',
115+
output: {
116+
file: pkg['react-native'],
117+
format: 'es',
118+
sourcemap: true
119+
},
120+
plugins: reactNativeBuildPlugins,
121+
external: resolveBrowserExterns
122+
},
123+
// Memory-only build
124+
{
125+
input: 'index.rn.memory.ts',
126+
output: {
127+
file: path.resolve('./memory', memoryPkg['react-native']),
128+
format: 'es',
129+
sourcemap: true
130+
},
131+
plugins: reactNativeBuildPlugins,
132+
external: resolveBrowserExterns
133+
}
134+
];
135+
120136
// MARK: Node builds
121137

122138
const nodeBuildPlugins = [
123-
alias({
124-
entries: [
125-
{
126-
find: /(.*)\/platform\/platform(.*)/,
127-
replacement: '$1/platform_node/node_platform$2'
128-
},
129-
{
130-
find: /(.*)\/platform\/random_bytes(.*)/,
131-
replacement: '$1/platform_node/node_random_bytes$2'
132-
},
133-
{
134-
find: /(.*)\/platform\/format_json(.*)/,
135-
replacement: '$1/platform_node/node_format_json$2'
136-
}
137-
]
138-
}),
139+
alias(generateAliasConfig('node')),
139140
typescriptPlugin({
140141
typescript,
141142
tsconfigOverride: {
@@ -178,4 +179,4 @@ const nodeBuilds = [
178179
}
179180
];
180181

181-
export default [...browserBuilds, ...nodeBuilds];
182+
export default [...browserBuilds, ...reactNativeBuilds, ...nodeBuilds];

packages/firestore/rollup.config.lite.js

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,13 @@ import alias from '@rollup/plugin-alias';
2020
import typescriptPlugin from 'rollup-plugin-typescript2';
2121
import typescript from 'typescript';
2222

23-
import { resolveNodeExterns } from './rollup.shared';
23+
import { resolveNodeExterns, generateAliasConfig } from './rollup.shared';
2424

2525
import pkg from './lite/package.json';
2626
import path from 'path';
2727

2828
const defaultPlugins = [
29-
alias({
30-
entries: [
31-
{
32-
find: /(.*)\/platform\/platform(.*)/,
33-
replacement: '$1/platform_node/node_platform$2'
34-
},
35-
{
36-
find: /(.*)\/platform\/random_bytes(.*)/,
37-
replacement: '$1/platform_node/node_random_bytes$2'
38-
},
39-
{
40-
find: /(.*)\/platform\/format_json(.*)/,
41-
replacement: '$1/platform_node/node_format_json$2'
42-
}
43-
]
44-
}),
29+
alias(generateAliasConfig('node')),
4530
typescriptPlugin({
4631
typescript,
4732
tsconfigOverride: {

packages/firestore/rollup.shared.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,30 @@ import { removeAsserts } from './scripts/remove-asserts';
2424

2525
import pkg from './package.json';
2626

27+
/**
28+
* Returns an replacement configuration for `@rollup/plugin-alias` that replaces
29+
* references to platform-specific files with those of the provided target
30+
* platform.
31+
*/
32+
export function generateAliasConfig(platform) {
33+
return {
34+
entries: [
35+
{
36+
find: /(.*)\/platform\/platform(.*)/,
37+
replacement: `$1/platform_${platform}/${platform}_platform$2`
38+
},
39+
{
40+
find: /(.*)\/platform\/random_bytes(.*)/,
41+
replacement: `$1/platform_${platform}/${platform}_random_bytes$2`
42+
},
43+
{
44+
find: /(.*)\/platform\/format_json(.*)/,
45+
replacement: `$1/platform_${platform}/${platform}_format_json$2`
46+
}
47+
]
48+
};
49+
}
50+
2751
const browserDeps = Object.keys(
2852
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
2953
);

packages/firestore/src/platform_browser/browser_platform.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ import { ConnectivityMonitor } from '../remote/connectivity_monitor';
2222
import { NoopConnectivityMonitor } from '../remote/connectivity_monitor_noop';
2323
import { BrowserConnectivityMonitor } from './browser_connectivity_monitor';
2424
import { WebChannelConnection } from './webchannel_connection';
25-
import { debugAssert } from '../util/assert';
2625

2726
// Implements the Platform API for browsers and some browser-like environments
28-
// (including ReactNative).
27+
// (including ReactNative, which has its own platform implementation that reuses
28+
// most of these methods).
2929
// The exports in this class must match the exports in ../platform/platform as
3030
// are bundled with the browser build during the Rollup build.
3131

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @license
3+
* Copyright 2020 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+
export { formatJSON } from '../platform_browser/browser_format_json';
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* @license
3+
* Copyright 2020 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 { base64 } from '@firebase/util';
19+
20+
export {
21+
loadConnection,
22+
newConnectivityMonitor,
23+
newSerializer,
24+
getWindow,
25+
getDocument
26+
} from '../platform_browser/browser_platform';
27+
28+
/** Converts a Base64 encoded string to a binary string. */
29+
export function decodeBase64(encoded: string): string {
30+
// WebSafe uses a different URL-encoding safe alphabet that doesn't match
31+
// the encoding used on the backend.
32+
return base64.decodeString(encoded, /* webSafe =*/ false);
33+
}
34+
35+
/** Converts a binary string to a Base64 encoded string. */
36+
export function encodeBase64(raw: string): string {
37+
// WebSafe uses a different URL-encoding safe alphabet that doesn't match
38+
// the encoding used on the backend.
39+
return base64.encodeString(raw, /* webSafe =*/ false);
40+
}
41+
42+
/** True if and only if the Base64 conversion functions are available. */
43+
export function isBase64Available(): boolean {
44+
return true;
45+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @license
3+
* Copyright 2020 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+
export { randomBytes } from '../platform_browser/browser_random_bytes';

0 commit comments

Comments
 (0)