Skip to content

Commit 0cbd6f6

Browse files
committed
break dependency circle
1 parent 2d45742 commit 0cbd6f6

18 files changed

+192
-77
lines changed

packages/firestore/src/core/firestore_client.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ import { Document } from '../model/document';
4141
import { DocumentKey } from '../model/document_key';
4242
import { Mutation } from '../model/mutation';
4343
import { toByteStreamReader } from '../platform/byte_stream_reader';
44-
import { newSerializer, newTextEncoder } from '../platform/serializer';
44+
import { newSerializer } from '../platform/serializer';
45+
import { newTextEncoder } from '../platform/text_reader';
4546
import { Datastore } from '../remote/datastore';
4647
import {
4748
canUseNetwork,

packages/firestore/src/platform/browser/serializer.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,3 @@ import { JsonProtoSerializer } from '../../remote/serializer';
2222
export function newSerializer(databaseId: DatabaseId): JsonProtoSerializer {
2323
return new JsonProtoSerializer(databaseId, /* useProto3Json= */ true);
2424
}
25-
26-
/**
27-
* An instance of the Platform's 'TextEncoder' implementation.
28-
*/
29-
export function newTextEncoder(): TextEncoder {
30-
return new TextEncoder();
31-
}
32-
33-
/**
34-
* An instance of the Platform's 'TextDecoder' implementation.
35-
*/
36-
export function newTextDecoder(): TextDecoder {
37-
return new TextDecoder('utf-8');
38-
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @license
3+
* Copyright 2022 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+
/**
19+
* An instance of the Platform's 'TextEncoder' implementation.
20+
*/
21+
export function newTextEncoder(): TextEncoder {
22+
return new TextEncoder();
23+
}
24+
25+
/**
26+
* An instance of the Platform's 'TextDecoder' implementation.
27+
*/
28+
export function newTextDecoder(): TextDecoder {
29+
return new TextDecoder('utf-8');
30+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @license
3+
* Copyright 2022 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 * from '../browser/text_reader';

packages/firestore/src/platform/node/serializer.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,9 @@
1616
*/
1717

1818
/** Return the Platform-specific serializer monitor. */
19-
import { TextDecoder, TextEncoder } from 'util';
20-
2119
import { DatabaseId } from '../../core/database_info';
2220
import { JsonProtoSerializer } from '../../remote/serializer';
2321

2422
export function newSerializer(databaseId: DatabaseId): JsonProtoSerializer {
2523
return new JsonProtoSerializer(databaseId, /* useProto3Json= */ false);
2624
}
27-
28-
/**
29-
* An instance of the Platform's 'TextEncoder' implementation.
30-
*/
31-
export function newTextEncoder(): TextEncoder {
32-
return new TextEncoder();
33-
}
34-
35-
/**
36-
* An instance of the Platform's 'TextDecoder' implementation.
37-
*/
38-
export function newTextDecoder(): TextDecoder {
39-
return new TextDecoder('utf-8');
40-
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @license
3+
* Copyright 2022 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 { TextDecoder, TextEncoder } from 'util';
19+
20+
/**
21+
* An instance of the Platform's 'TextEncoder' implementation.
22+
*/
23+
export function newTextEncoder(): TextEncoder {
24+
return new TextEncoder();
25+
}
26+
27+
/**
28+
* An instance of the Platform's 'TextDecoder' implementation.
29+
*/
30+
export function newTextDecoder(): TextDecoder {
31+
return new TextDecoder('utf-8');
32+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @license
3+
* Copyright 2022 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 * from '../browser_lite/text_reader';

packages/firestore/src/platform/rn/serializer.ts

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

18-
export {
19-
newSerializer,
20-
newTextEncoder,
21-
newTextDecoder
22-
} from '../browser/serializer';
18+
export { newSerializer } from '../browser/serializer';
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @license
3+
* Copyright 2022 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 { newTextEncoder, newTextDecoder } from '../browser/text_reader';
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @license
3+
* Copyright 2022 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 * from '../browser_lite/text_reader';

packages/firestore/src/platform/serializer.ts

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

18-
import { isNode, isReactNative } from '@firebase/util';
19-
2018
import { DatabaseId } from '../core/database_info';
2119
import { JsonProtoSerializer } from '../remote/serializer';
2220

23-
import * as browser from './browser/serializer';
24-
import * as node from './node/serializer';
25-
import * as rn from './rn/serializer';
26-
2721
// This file is only used under ts-node.
2822
// eslint-disable-next-line @typescript-eslint/no-require-imports
2923
const platform = require(`./${process.env.TEST_PLATFORM ?? 'node'}/serializer`);
3024

3125
export function newSerializer(databaseId: DatabaseId): JsonProtoSerializer {
3226
return platform.newSerializer(databaseId);
3327
}
34-
35-
/**
36-
* An instance of the Platform's 'TextEncoder' implementation.
37-
*/
38-
export function newTextEncoder(): TextEncoder {
39-
if (isNode()) {
40-
return node.newTextEncoder();
41-
} else if (isReactNative()) {
42-
return rn.newTextEncoder();
43-
} else {
44-
return browser.newTextEncoder();
45-
}
46-
}
47-
48-
/**
49-
* An instance of the Platform's 'TextDecoder' implementation.
50-
*/
51-
export function newTextDecoder(): TextDecoder {
52-
if (isNode()) {
53-
return node.newTextDecoder() as TextDecoder;
54-
} else if (isReactNative()) {
55-
return rn.newTextDecoder();
56-
} else {
57-
return browser.newTextDecoder();
58-
}
59-
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* @license
3+
* Copyright 2022 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 { isNode, isReactNative } from '@firebase/util';
19+
20+
import * as browser from './browser/text_reader';
21+
import * as node from './node/text_reader';
22+
import * as rn from './rn/text_reader';
23+
24+
/**
25+
* An instance of the Platform's 'TextEncoder' implementation.
26+
*/
27+
export function newTextEncoder(): TextEncoder {
28+
if (isNode()) {
29+
return node.newTextEncoder();
30+
} else if (isReactNative()) {
31+
return rn.newTextEncoder();
32+
} else {
33+
return browser.newTextEncoder();
34+
}
35+
}
36+
37+
/**
38+
* An instance of the Platform's 'TextDecoder' implementation.
39+
*/
40+
export function newTextDecoder(): TextDecoder {
41+
if (isNode()) {
42+
return node.newTextDecoder() as TextDecoder;
43+
} else if (isReactNative()) {
44+
return rn.newTextDecoder();
45+
} else {
46+
return browser.newTextDecoder();
47+
}
48+
}

packages/firestore/src/remote/bloom_filter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
import { Md5, Integer } from '@firebase/webchannel-wrapper';
1818

19-
import { newTextEncoder } from '../platform/serializer';
19+
import { newTextEncoder } from '../platform/text_reader';
2020
import { debugAssert } from '../util/assert';
2121

2222
const MAX_64_BIT_UNSIGNED_INTEGER = new Integer([0xffffffff, 0xffffffff], 0);

packages/firestore/src/util/bundle_reader_impl.ts

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

18-
import { newTextDecoder } from '../platform/serializer';
18+
import { newTextDecoder } from '../platform/text_reader';
1919
import { BundleMetadata } from '../protos/firestore_bundle_proto';
2020
import { JsonProtoSerializer } from '../remote/serializer';
2121

packages/firestore/test/unit/core/webchannel_wrapper.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import { Md5, Integer } from '@firebase/webchannel-wrapper';
2323
import { expect } from 'chai';
2424

25-
import { newTextEncoder } from '../../../src/platform/serializer';
25+
import { newTextEncoder } from '../../../src/platform/text_reader';
2626

2727
describe('Md5', () => {
2828
// The precomputed MD5 digests of the 3-character strings "abc" and "def".

packages/firestore/test/unit/specs/spec_test_runner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ import { Mutation } from '../../../src/model/mutation';
9090
import { JsonObject } from '../../../src/model/object_value';
9191
import { encodeBase64 } from '../../../src/platform/base64';
9292
import { toByteStreamReader } from '../../../src/platform/byte_stream_reader';
93-
import { newTextEncoder } from '../../../src/platform/serializer';
93+
import { newTextEncoder } from '../../../src/platform/text_reader';
9494
import * as api from '../../../src/protos/firestore_proto_api';
9595
import { ExistenceFilter } from '../../../src/remote/existence_filter';
9696
import {

packages/firestore/test/unit/util/bundle.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { expect, use } from 'chai';
1818
import chaiAsPromised from 'chai-as-promised';
1919

2020
import { toByteStreamReader } from '../../../src/platform/byte_stream_reader';
21-
import { newTextEncoder } from '../../../src/platform/serializer';
21+
import { newTextEncoder } from '../../../src/platform/text_reader';
2222
import {
2323
BundleReader,
2424
SizedBundleElement

packages/firestore/test/unit/util/bundle_data.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ import {
2222
queryWithLimit
2323
} from '../../../src/core/query';
2424
import { DocumentKey } from '../../../src/model/document_key';
25-
import {
26-
newSerializer,
27-
newTextEncoder
28-
} from '../../../src/platform/serializer';
25+
import { newSerializer } from '../../../src/platform/serializer';
26+
import { newTextEncoder } from '../../../src/platform/text_reader';
2927
import {
3028
BundleElement,
3129
LimitType as BundleLimitType

0 commit comments

Comments
 (0)