Skip to content

Commit 558574e

Browse files
committed
local_store_indexeddb.test.ts: fix build
1 parent d878f45 commit 558574e

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

packages/firestore/src/local/local_store_impl.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,6 +1536,17 @@ export function localStoreSetFieldIndexManagementApi(
15361536
localStoreImpl.queryEngine.fieldIndexManagementApi = fieldIndexManagementApi;
15371537
}
15381538

1539+
export function localStoreGetOrSetFieldIndexManagementApi(
1540+
localStore: LocalStore,
1541+
factory: () => FieldIndexManagementApi
1542+
): FieldIndexManagementApi {
1543+
const localStoreImpl = debugCast(localStore, LocalStoreImpl);
1544+
if (!localStoreImpl.queryEngine.fieldIndexManagementApi) {
1545+
localStoreImpl.queryEngine.fieldIndexManagementApi = factory();
1546+
}
1547+
return localStoreImpl.queryEngine.fieldIndexManagementApi;
1548+
}
1549+
15391550
export function localStoreDeleteAllFieldIndexes(
15401551
localStore: LocalStore
15411552
): Promise<void> {

packages/firestore/test/unit/local/local_store_indexeddb.test.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@ import {
3737
localStoreConfigureFieldIndexes,
3838
localStoreDeleteAllFieldIndexes,
3939
localStoreExecuteQuery,
40-
localStoreSetIndexAutoCreationEnabled,
40+
localStoreGetOrSetFieldIndexManagementApi,
4141
localStoreWriteLocally,
42-
newLocalStore,
43-
TestingHooks as LocalStoreTestingHooks
42+
newLocalStore
4443
} from '../../../src/local/local_store_impl';
4544
import { Persistence } from '../../../src/local/persistence';
4645
import { DocumentMap } from '../../../src/model/collections';
@@ -72,6 +71,7 @@ import {
7271
import { CountingQueryEngine } from './counting_query_engine';
7372
import * as persistenceHelpers from './persistence_test_helpers';
7473
import { JSON_SERIALIZER } from './persistence_test_helpers';
74+
import { FieldIndexManagementApiImpl } from '../../../src/index/field_index_management';
7575

7676
class AsyncLocalStoreTester {
7777
private bundleConverter: BundleConverterImpl;
@@ -143,13 +143,28 @@ class AsyncLocalStoreTester {
143143
}): void {
144144
this.prepareNextStep();
145145

146-
if (config.isEnabled !== undefined) {
147-
localStoreSetIndexAutoCreationEnabled(this.localStore, config.isEnabled);
148-
}
149-
LocalStoreTestingHooks.setIndexAutoCreationSettings(
146+
const fieldIndexManagementApi = localStoreGetOrSetFieldIndexManagementApi(
150147
this.localStore,
151-
config
148+
() => new FieldIndexManagementApiImpl()
152149
);
150+
if (!(fieldIndexManagementApi instanceof FieldIndexManagementApiImpl)) {
151+
throw new Error(
152+
`fieldIndexManagementApi should be an instance of ` +
153+
`FieldIndexManagementApiImpl: $fieldIndexManagementApi`
154+
);
155+
}
156+
157+
if (config.isEnabled !== undefined) {
158+
fieldIndexManagementApi.indexAutoCreationEnabled = config.isEnabled;
159+
}
160+
if (config.indexAutoCreationMinCollectionSize !== undefined) {
161+
fieldIndexManagementApi.indexAutoCreationMinCollectionSize =
162+
config.indexAutoCreationMinCollectionSize;
163+
}
164+
if (config.relativeIndexReadCostPerDocument !== undefined) {
165+
fieldIndexManagementApi.relativeIndexReadCostPerDocument =
166+
config.relativeIndexReadCostPerDocument;
167+
}
153168
}
154169

155170
deleteAllFieldIndexes(): Promise<void> {

0 commit comments

Comments
 (0)