Skip to content

Commit 6c893ca

Browse files
before brwoser fix
1 parent c675a2a commit 6c893ca

15 files changed

+205
-83
lines changed

packages/firestore/rollup.config.es2017.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ const browserBuildPlugins = [
6767
{
6868
find: /(.*)\/platform\/platform(.*)/,
6969
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'
7078
}
7179
]
7280
}),
@@ -117,6 +125,14 @@ const nodeBuildPlugins = [
117125
{
118126
find: /(.*)\/platform\/platform(.*)/,
119127
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'
120136
}
121137
]
122138
}),

packages/firestore/rollup.config.lite.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ const defaultPlugins = [
3131
{
3232
find: /(.*)\/platform\/platform(.*)/,
3333
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'
3442
}
3543
]
3644
}),

packages/firestore/src/model/collections.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { SortedSet } from '../util/sorted_set';
2222
import { TargetId } from '../core/types';
2323
import { Document, MaybeDocument } from './document';
2424
import { DocumentKey } from './document_key';
25+
import { primitiveComparator } from '../util/misc';
2526

2627
/** Miscellaneous collection types / constants. */
2728
export interface DocumentSizeEntry {
@@ -77,18 +78,8 @@ export function documentKeySet(...keys: DocumentKey[]): DocumentKeySet {
7778
return set;
7879
}
7980

80-
export function foo<T>(left: T, right: T): number {
81-
if (left < right) {
82-
return -1;
83-
}
84-
if (left > right) {
85-
return 1;
86-
}
87-
return 0;
88-
}
89-
9081
export type TargetIdSet = SortedSet<TargetId>;
91-
const EMPTY_TARGET_ID_SET = new SortedSet<TargetId>(foo);
82+
const EMPTY_TARGET_ID_SET = new SortedSet<TargetId>(primitiveComparator);
9283
export function targetIdSet(): SortedSet<TargetId> {
9384
return EMPTY_TARGET_ID_SET;
9485
}

packages/firestore/src/model/document_key.ts

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

18-
//import { debugAssert } from '../util/assert';
18+
import { debugAssert } from '../util/assert';
1919

2020
import { ResourcePath } from './path';
2121

2222
export class DocumentKey {
2323
constructor(readonly path: ResourcePath) {
24-
// debugAssert(
25-
// DocumentKey.isDocumentKey(path),
26-
// 'Invalid DocumentKey with an odd number of segments: ' +
27-
// path.toArray().join('/')
28-
// );
24+
debugAssert(
25+
DocumentKey.isDocumentKey(path),
26+
'Invalid DocumentKey with an odd number of segments: ' +
27+
path.toArray().join('/')
28+
);
2929
}
3030

3131
static fromName(name: string): DocumentKey {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 * as node from '../platform_node/node_format_json';
19+
import * as browser from '../platform_browser/browser_format_json';
20+
import { isNode } from '@firebase/util';
21+
22+
/** Formats an object as a JSON string, suitable for logging. */
23+
export function formatJSON(value: unknown): string {
24+
return isNode() ? node.formatJSON(value) : browser.formatJSON(value);
25+
}

packages/firestore/src/platform/platform.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ export function newSerializer(databaseId: DatabaseId): JsonProtoSerializer {
5252
: browser.newSerializer(databaseId);
5353
}
5454

55-
/** Formats an object as a JSON string, suitable for logging. */
56-
export function formatJSON(value: unknown): string {
57-
return isNode() ? node.formatJSON(value) : browser.formatJSON(value);
58-
}
59-
6055
/** Converts a Base64 encoded string to a binary string. */
6156
export function decodeBase64(encoded: string): string {
6257
return isNode() ? node.decodeBase64(encoded) : browser.decodeBase64(encoded);
@@ -67,15 +62,6 @@ export function encodeBase64(raw: string): string {
6762
return isNode() ? node.encodeBase64(raw) : browser.encodeBase64(raw);
6863
}
6964

70-
/**
71-
* Generates `nBytes` of random bytes.
72-
*
73-
* If `nBytes < 0` , an error will be thrown.
74-
*/
75-
export function randomBytes(nBytes: number): Uint8Array {
76-
return isNode() ? node.randomBytes(nBytes) : browser.randomBytes(nBytes);
77-
}
78-
7965
/** The Platform's 'window' implementation or null if not available. */
8066
export function getWindow(): Window | null {
8167
return isNode() ? node.getWindow() : browser.getWindow();
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 * as node from '../platform_node/node_random_bytes';
19+
import * as browser from '../platform_browser/browser_random_bytes';
20+
import { isNode } from '@firebase/util';
21+
22+
/**
23+
* Generates `nBytes` of random bytes.
24+
*
25+
* If `nBytes < 0` , an error will be thrown.
26+
*/
27+
export function randomBytes(nBytes: number): Uint8Array {
28+
return isNode() ? node.randomBytes(nBytes) : browser.randomBytes(nBytes);
29+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
/** Formats an object as a JSON string, suitable for logging. */
19+
export function formatJSON(value: unknown): string {
20+
return JSON.stringify(value);
21+
}

packages/firestore/src/platform_browser/browser_platform.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ export function newSerializer(databaseId: DatabaseId): JsonProtoSerializer {
5050
return new JsonProtoSerializer(databaseId, { useProto3Json: true });
5151
}
5252

53-
/** Formats an object as a JSON string, suitable for logging. */
54-
export function formatJSON(value: unknown): string {
55-
return JSON.stringify(value);
56-
}
57-
5853
/** Converts a Base64 encoded string to a binary string. */
5954
export function decodeBase64(encoded: string): string {
6055
return atob(encoded);
@@ -65,30 +60,6 @@ export function encodeBase64(raw: string): string {
6560
return btoa(raw);
6661
}
6762

68-
/**
69-
* Generates `nBytes` of random bytes.
70-
*
71-
* If `nBytes < 0` , an error will be thrown.
72-
*/
73-
export function randomBytes(nBytes: number): Uint8Array {
74-
debugAssert(nBytes >= 0, `Expecting non-negative nBytes, got: ${nBytes}`);
75-
76-
// Polyfills for IE and WebWorker by using `self` and `msCrypto` when `crypto` is not available.
77-
const crypto =
78-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
79-
typeof self !== 'undefined' && (self.crypto || (self as any)['msCrypto']);
80-
const bytes = new Uint8Array(nBytes);
81-
if (crypto) {
82-
crypto.getRandomValues(bytes);
83-
} else {
84-
// Falls back to Math.random
85-
for (let i = 0; i < nBytes; i++) {
86-
bytes[i] = Math.floor(Math.random() * 256);
87-
}
88-
}
89-
return bytes;
90-
}
91-
9263
/** The Platform's 'window' implementation or null if not available. */
9364
export function getWindow(): Window | null {
9465
// `window` is not always available, e.g. in ReactNative and WebWorkers.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 { debugAssert } from '../util/assert';
19+
20+
/**
21+
* Generates `nBytes` of random bytes.
22+
*
23+
* If `nBytes < 0` , an error will be thrown.
24+
*/
25+
export function randomBytes(nBytes: number): Uint8Array {
26+
debugAssert(nBytes >= 0, `Expecting non-negative nBytes, got: ${nBytes}`);
27+
28+
// Polyfills for IE and WebWorker by using `self` and `msCrypto` when `crypto` is not available.
29+
const crypto =
30+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
31+
typeof self !== 'undefined' && (self.crypto || (self as any)['msCrypto']);
32+
const bytes = new Uint8Array(nBytes);
33+
if (crypto) {
34+
crypto.getRandomValues(bytes);
35+
} else {
36+
// Falls back to Math.random
37+
for (let i = 0; i < nBytes; i++) {
38+
bytes[i] = Math.floor(Math.random() * 256);
39+
}
40+
}
41+
return bytes;
42+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 { inspect } from 'util';
19+
20+
/** Formats an object as a JSON string, suitable for logging. */
21+
export function formatJSON(value: unknown): string {
22+
// util.inspect() results in much more readable output than JSON.stringify()
23+
return inspect(value, { depth: 100 });
24+
}

packages/firestore/src/platform_node/node_platform.ts

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

18-
import { randomBytes as generateRandomBytes } from 'crypto';
19-
import { inspect } from 'util';
20-
2118
import { DatabaseId, DatabaseInfo } from '../core/database_info';
2219
import { Connection } from '../remote/connection';
2320
import { JsonProtoSerializer } from '../remote/serializer';
2421
import { Code, FirestoreError } from '../util/error';
2522
import { ConnectivityMonitor } from '../remote/connectivity_monitor';
26-
import { NoopConnectivityMonitor } from './../remote/connectivity_monitor_noop';
23+
import { NoopConnectivityMonitor } from '../remote/connectivity_monitor_noop';
2724

2825
import { GrpcConnection } from './grpc_connection';
2926
import { loadProtos } from './load_protos';
30-
import { debugAssert } from '../util/assert';
3127

3228
// The exports in this class must match the exports in ../platform/platform
3329
// are bundled with the Node build using Rollup.
@@ -50,12 +46,6 @@ export function newSerializer(databaseId: DatabaseId): JsonProtoSerializer {
5046
return new JsonProtoSerializer(databaseId, { useProto3Json: false });
5147
}
5248

53-
/** Formats an object as a JSON string, suitable for logging. */
54-
export function formatJSON(value: unknown): string {
55-
// util.inspect() results in much more readable output than JSON.stringify()
56-
return inspect(value, { depth: 100 });
57-
}
58-
5949
/** Converts a Base64 encoded string to a binary string. */
6050
export function decodeBase64(encoded: string): string {
6151
// Node actually doesn't validate base64 strings.
@@ -74,16 +64,6 @@ export function encodeBase64(raw: string): string {
7464
return new Buffer(raw, 'binary').toString('base64');
7565
}
7666

77-
/**
78-
* Generates `nBytes` of random bytes.
79-
*
80-
* If `nBytes < 0` , an error will be thrown.
81-
*/
82-
export function randomBytes(nBytes: number): Uint8Array {
83-
debugAssert(nBytes >= 0, `Expecting non-negative nBytes, got: ${nBytes}`);
84-
return generateRandomBytes(nBytes);
85-
}
86-
8767
/** The Platform's 'window' implementation or null if not available. */
8868
export function getWindow(): Window | null {
8969
if (process.env.USE_MOCK_PERSISTENCE === 'YES') {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 { debugAssert } from '../util/assert';
19+
import { randomBytes as generateRandomBytes } from 'crypto';
20+
21+
/**
22+
* Generates `nBytes` of random bytes.
23+
*
24+
* If `nBytes < 0` , an error will be thrown.
25+
*/
26+
export function randomBytes(nBytes: number): Uint8Array {
27+
debugAssert(nBytes >= 0, `Expecting non-negative nBytes, got: ${nBytes}`);
28+
return generateRandomBytes(nBytes);
29+
}

0 commit comments

Comments
 (0)