Skip to content

Commit 5a4d0f2

Browse files
committed
Move newTextEncoder to serializer.ts
1 parent d175a14 commit 5a4d0f2

File tree

17 files changed

+86
-92
lines changed

17 files changed

+86
-92
lines changed

packages/firestore/src/core/firestore_client.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,8 @@ import {
5151
import { BundleReader } from '../util/bundle_reader';
5252
import { LoadBundleTask } from '../api/bundle';
5353
import { newConnection } from '../platform/connection';
54-
import { newSerializer } from '../platform/serializer';
54+
import { newSerializer, newTextEncoder } from '../platform/serializer';
5555
import { toByteStreamReader } from '../platform/byte_stream_reader';
56-
import { newTextEncoder } from '../platform/dom';
5756

5857
const LOG_TAG = 'FirestoreClient';
5958
const MAX_CONCURRENT_LIMBO_RESOLUTIONS = 100;

packages/firestore/src/core/sync_engine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1419,7 +1419,7 @@ export function loadBundle(
14191419

14201420
// eslint-disable-next-line @typescript-eslint/no-floating-promises
14211421
loadBundleImpl(syncEngineImpl, bundleReader, task).then(() => {
1422-
syncEngineImpl.sharedClientState.notifyBundleChangedRemoteDocuments();
1422+
syncEngineImpl.sharedClientState.notifyBundleLoaded();
14231423
});
14241424
}
14251425

packages/firestore/src/local/shared_client_state.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import {
4040
import {
4141
CLIENT_STATE_KEY_PREFIX,
4242
ClientStateSchema,
43-
createRemoteDocumentsLoadFromBundleKey,
43+
createBundleLoadedKey,
4444
createWebStorageClientStateKey,
4545
createWebStorageMutationBatchKey,
4646
createWebStorageOnlineStateKey,
@@ -179,7 +179,7 @@ export interface SharedClientState {
179179
* Notifies other clients when remote documents have changed due to loading
180180
* a bundle.
181181
*/
182-
notifyBundleChangedRemoteDocuments(): void;
182+
notifyBundleLoaded(): void;
183183
}
184184

185185
/**
@@ -484,7 +484,7 @@ export class WebStorageSharedClientState implements SharedClientState {
484484
private readonly sequenceNumberKey: string;
485485
private readonly storageListener = this.handleWebStorageEvent.bind(this);
486486
private readonly onlineStateKey: string;
487-
private readonly bundleChangedRemoteDocumentsKey: string;
487+
private readonly bundleLoadedKey: string;
488488
private readonly clientStateKeyRe: RegExp;
489489
private readonly mutationBatchKeyRe: RegExp;
490490
private readonly queryTargetKeyRe: RegExp;
@@ -540,9 +540,7 @@ export class WebStorageSharedClientState implements SharedClientState {
540540

541541
this.onlineStateKey = createWebStorageOnlineStateKey(this.persistenceKey);
542542

543-
this.bundleChangedRemoteDocumentsKey = createRemoteDocumentsLoadFromBundleKey(
544-
this.persistenceKey
545-
);
543+
this.bundleLoadedKey = createBundleLoadedKey(this.persistenceKey);
546544

547545
// Rather than adding the storage observer during start(), we add the
548546
// storage observer during initialization. This ensures that we collect
@@ -723,8 +721,8 @@ export class WebStorageSharedClientState implements SharedClientState {
723721
this.persistOnlineState(onlineState);
724722
}
725723

726-
notifyBundleChangedRemoteDocuments(): void {
727-
this.persistBundleChangedRemoteDocumentsState();
724+
notifyBundleLoaded(): void {
725+
this.persistBundleLoadedState();
728726
}
729727

730728
shutdown(): void {
@@ -834,7 +832,7 @@ export class WebStorageSharedClientState implements SharedClientState {
834832
if (sequenceNumber !== ListenSequence.INVALID) {
835833
this.sequenceNumberHandler!(sequenceNumber);
836834
}
837-
} else if (storageEvent.key === this.bundleChangedRemoteDocumentsKey) {
835+
} else if (storageEvent.key === this.bundleLoadedKey) {
838836
return this.syncEngine!.synchronizeWithChangedDocuments();
839837
}
840838
});
@@ -901,8 +899,8 @@ export class WebStorageSharedClientState implements SharedClientState {
901899
this.setItem(targetKey, targetMetadata.toWebStorageJSON());
902900
}
903901

904-
private persistBundleChangedRemoteDocumentsState(): void {
905-
this.setItem(this.bundleChangedRemoteDocumentsKey, 'value-not-used');
902+
private persistBundleLoadedState(): void {
903+
this.setItem(this.bundleLoadedKey, 'value-not-used');
906904
}
907905

908906
/**
@@ -1154,7 +1152,7 @@ export class MemorySharedClientState implements SharedClientState {
11541152

11551153
writeSequenceNumber(sequenceNumber: ListenSequenceNumber): void {}
11561154

1157-
notifyBundleChangedRemoteDocuments(): void {
1155+
notifyBundleLoaded(): void {
11581156
// No op.
11591157
}
11601158
}

packages/firestore/src/local/shared_client_state_schema.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,9 @@ export function createWebStorageOnlineStateKey(persistenceKey: string): string {
119119
// might have changed due to some secondary tabs loading a bundle.
120120
// format of the key is:
121121
// firestore_remote_documents_changed_<persistenceKey>
122-
export const REMOTE_DOCUMENTS_LOAD_FROM_BUNDLE_KEY_PREFIX =
123-
'firestore_bundle_loaded';
124-
export function createRemoteDocumentsLoadFromBundleKey(
125-
persistenceKey: string
126-
): string {
127-
return `${REMOTE_DOCUMENTS_LOAD_FROM_BUNDLE_KEY_PREFIX}_${persistenceKey}`;
122+
export const BUNDLE_LOADED_KEY_PREFIX = 'firestore_bundle_loaded';
123+
export function createBundleLoadedKey(persistenceKey: string): string {
124+
return `${BUNDLE_LOADED_KEY_PREFIX}_${persistenceKey}`;
128125
}
129126

130127
/**

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,3 @@ export function getDocument(): Document | null {
2828
// eslint-disable-next-line no-restricted-globals
2929
return typeof document !== 'undefined' ? document : null;
3030
}
31-
32-
/**
33-
* An instance of the Platform's 'TextEncoder' implementation.
34-
*/
35-
export function newTextEncoder(): TextEncoder {
36-
return new TextEncoder();
37-
}
38-
39-
/**
40-
* An instance of the Platform's 'TextDecoder' implementation.
41-
*/
42-
export function newTextDecoder(): TextDecoder {
43-
return new TextDecoder('utf-8');
44-
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,17 @@ 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+
}

packages/firestore/src/platform/dom.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,29 +41,3 @@ export function getDocument(): Document | null {
4141
return browser.getDocument();
4242
}
4343
}
44-
45-
/**
46-
* An instance of the Platform's 'TextEncoder' implementation.
47-
*/
48-
export function newTextEncoder(): TextEncoder {
49-
if (isNode()) {
50-
return node.newTextEncoder();
51-
} else if (isReactNative()) {
52-
return rn.newTextEncoder();
53-
} else {
54-
return browser.newTextEncoder();
55-
}
56-
}
57-
58-
/**
59-
* An instance of the Platform's 'TextDecoder' implementation.
60-
*/
61-
export function newTextDecoder(): TextDecoder {
62-
if (isNode()) {
63-
return node.newTextDecoder() as TextDecoder;
64-
} else if (isReactNative()) {
65-
return rn.newTextDecoder();
66-
} else {
67-
return browser.newTextDecoder();
68-
}
69-
}

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

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

18-
import { TextEncoder, TextDecoder } from 'util';
19-
2018
/** The Platform's 'window' implementation or null if not available. */
2119
export function getWindow(): Window | null {
2220
if (process.env.USE_MOCK_PERSISTENCE === 'YES') {
@@ -31,17 +29,3 @@ export function getWindow(): Window | null {
3129
export function getDocument(): Document | null {
3230
return null;
3331
}
34-
35-
/**
36-
* An instance of the Platform's 'TextEncoder' implementation.
37-
*/
38-
export function newTextEncoder(): TextEncoder {
39-
return new TextEncoder();
40-
}
41-
42-
/**
43-
* An instance of the Platform's 'TextDecoder' implementation.
44-
*/
45-
export function newTextDecoder(): TextDecoder {
46-
return new TextDecoder('utf-8');
47-
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,22 @@
1818
/** Return the Platform-specific serializer monitor. */
1919
import { JsonProtoSerializer } from '../../remote/serializer';
2020
import { DatabaseId } from '../../core/database_info';
21+
import { TextDecoder, TextEncoder } from 'util';
2122

2223
export function newSerializer(databaseId: DatabaseId): JsonProtoSerializer {
2324
return new JsonProtoSerializer(databaseId, /* useProto3Json= */ false);
2425
}
26+
27+
/**
28+
* An instance of the Platform's 'TextEncoder' implementation.
29+
*/
30+
export function newTextEncoder(): TextEncoder {
31+
return new TextEncoder();
32+
}
33+
34+
/**
35+
* An instance of the Platform's 'TextDecoder' implementation.
36+
*/
37+
export function newTextDecoder(): TextDecoder {
38+
return new TextDecoder('utf-8');
39+
}

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

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

18-
export {
19-
getWindow,
20-
getDocument,
21-
newTextEncoder,
22-
newTextDecoder
23-
} from '../browser/dom';
18+
export { getWindow, getDocument } from '../browser/dom';

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

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

18-
export { newSerializer } from '../browser/serializer';
18+
export {
19+
newSerializer,
20+
newTextEncoder,
21+
newTextDecoder
22+
} from '../browser/serializer';

packages/firestore/src/platform/serializer.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
*/
1717

1818
import { isNode, isReactNative } from '@firebase/util';
19+
import { DatabaseId } from '../core/database_info';
20+
import { JsonProtoSerializer } from '../remote/serializer';
1921
import * as node from './node/serializer';
2022
import * as rn from './rn/serializer';
2123
import * as browser from './browser/serializer';
22-
import { DatabaseId } from '../core/database_info';
23-
import { JsonProtoSerializer } from '../remote/serializer';
2424

2525
export function newSerializer(databaseId: DatabaseId): JsonProtoSerializer {
2626
if (isNode()) {
@@ -31,3 +31,29 @@ export function newSerializer(databaseId: DatabaseId): JsonProtoSerializer {
3131
return browser.newSerializer(databaseId);
3232
}
3333
}
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+
}

packages/firestore/src/util/bundle_reader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
import { Deferred } from './promise';
2323
import { debugAssert } from './assert';
2424
import { toByteStreamReader } from '../platform/byte_stream_reader';
25-
import { newTextDecoder } from '../platform/dom';
25+
import { newTextDecoder } from '../platform/serializer';
2626

2727
/**
2828
* A complete element in the bundle stream, together with the byte length it

packages/firestore/test/integration/api_internal/bundle.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { DatabaseId } from '../../../src/core/database_info';
2727
import { key } from '../../util/helpers';
2828
import { EventsAccumulator } from '../util/events_accumulator';
2929
import { TestBundleBuilder } from '../../unit/util/bundle_data';
30-
import { newTextEncoder } from '../../../src/platform/dom';
30+
import { newTextEncoder } from '../../../src/platform/serializer';
3131

3232
export const encoder = newTextEncoder();
3333

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ import {
126126
} from '../../util/test_platform';
127127
import { toByteStreamReader } from '../../../src/platform/byte_stream_reader';
128128
import { logWarn } from '../../../src/util/log';
129-
import { newTextEncoder } from '../../../src/platform/dom';
129+
import { newTextEncoder } from '../../../src/platform/serializer';
130130

131131
const ARBITRARY_SEQUENCE_NUMBER = 2;
132132

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import {
3939
doc1,
4040
doc2
4141
} from './bundle_data';
42-
import { newTextEncoder } from '../../../src/platform/dom';
42+
import { newTextEncoder } from '../../../src/platform/serializer';
4343

4444
use(chaiAsPromised);
4545

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ import * as api from '../../../src/protos/firestore_proto_api';
2323
import { Value } from '../../../src/protos/firestore_proto_api';
2424
import { JsonProtoSerializer, toName } from '../../../src/remote/serializer';
2525
import { DocumentKey } from '../../../src/model/document_key';
26-
import { newSerializer } from '../../../src/platform/serializer';
27-
import { newTextEncoder } from '../../../src/platform/dom';
26+
import {
27+
newSerializer,
28+
newTextEncoder
29+
} from '../../../src/platform/serializer';
2830

2931
export const encoder = newTextEncoder();
3032

0 commit comments

Comments
 (0)