Skip to content

Commit e0c7822

Browse files
dconeybeNhienLam
authored andcommitted
Move newTextEncoder() and newTextDecoder() to their own file: text_serializer.ts (#7018)
1 parent 0c442f4 commit e0c7822

File tree

17 files changed

+196
-75
lines changed

17 files changed

+196
-75
lines changed

.changeset/large-lemons-relax.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@firebase/firestore': patch
3+
'firebase': patch
4+
---
5+
6+
Internal refactor of platform-specific logic to create TextEncoder and TextDecoder objects.

packages/firestore/src/core/firestore_client.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ import { DocumentKey } from '../model/document_key';
3636
import { Mutation } from '../model/mutation';
3737
import { ObjectValue } from '../model/object_value';
3838
import { toByteStreamReader } from '../platform/byte_stream_reader';
39-
import { newSerializer, newTextEncoder } from '../platform/serializer';
39+
import { newSerializer } from '../platform/serializer';
40+
import { newTextEncoder } from '../platform/text_serializer';
4041
import { Datastore, invokeRunAggregationQueryRpc } from '../remote/datastore';
4142
import {
4243
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 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+
/**
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 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+
export * from '../browser/text_serializer';

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 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 { 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 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+
export * from '../browser_lite/text_serializer';

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 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+
export { newTextEncoder, newTextDecoder } from '../browser/text_serializer';

0 commit comments

Comments
 (0)