Skip to content

Commit 1076551

Browse files
authored
Expose setIndexConfiguration (#6496)
* Expose setIndexConfiguration * Expose IndexConfiguration types * Changeset to expose setIndexConfiguration
1 parent 772da5a commit 1076551

File tree

5 files changed

+45
-10
lines changed

5 files changed

+45
-10
lines changed

.changeset/honest-waves-brake.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@firebase/firestore': patch
3+
---
4+
5+
Expose client side indexing feature with `setIndexConfiguration`.

common/api-review/firestore.api.md

+30
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,30 @@ export function getFirestore(app?: FirebaseApp): Firestore;
233233
// @public
234234
export function increment(n: number): FieldValue;
235235

236+
// @public
237+
export interface Index {
238+
// (undocumented)
239+
[key: string]: unknown;
240+
readonly collectionGroup: string;
241+
readonly fields?: IndexField[];
242+
}
243+
244+
// @public
245+
export interface IndexConfiguration {
246+
// (undocumented)
247+
[key: string]: unknown;
248+
readonly indexes?: Index[];
249+
}
250+
251+
// @public
252+
export interface IndexField {
253+
// (undocumented)
254+
[key: string]: unknown;
255+
readonly arrayConfig?: 'CONTAINS';
256+
readonly fieldPath: string;
257+
readonly order?: 'ASCENDING' | 'DESCENDING';
258+
}
259+
236260
// @public
237261
export function initializeFirestore(app: FirebaseApp, settings: FirestoreSettings): Firestore;
238262

@@ -396,6 +420,12 @@ export function setDoc<T>(reference: DocumentReference<T>, data: WithFieldValue<
396420
// @public
397421
export function setDoc<T>(reference: DocumentReference<T>, data: PartialWithFieldValue<T>, options: SetOptions): Promise<void>;
398422

423+
// @public
424+
export function setIndexConfiguration(firestore: Firestore, configuration: IndexConfiguration): Promise<void>;
425+
426+
// @public
427+
export function setIndexConfiguration(firestore: Firestore, json: string): Promise<void>;
428+
399429
// @public
400430
export function setLogLevel(logLevel: LogLevel): void;
401431

packages/firestore/src/api.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ export {
143143
UnionToIntersection
144144
} from '../src/lite-api/types';
145145

146+
export {
147+
setIndexConfiguration,
148+
Index,
149+
IndexConfiguration,
150+
IndexField
151+
} from './api/index_configuration';
152+
146153
/**
147154
* Internal exports
148155
*/
@@ -160,4 +167,3 @@ export type { ByteString as _ByteString } from './util/byte_string';
160167
export { logWarn as _logWarn } from './util/log';
161168
export { EmptyAuthCredentialsProvider as _EmptyAuthCredentialsProvider } from './api/credentials';
162169
export { EmptyAppCheckTokenProvider as _EmptyAppCheckTokenProvider } from './api/credentials';
163-
export { setIndexConfiguration as _setIndexConfiguration } from './api/index_configuration';

packages/firestore/src/api/index_configuration.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ export {
3939

4040
/**
4141
* A single field element in an index configuration.
42-
*
43-
* @internal
4442
*/
4543
export interface IndexField {
4644
/** The field path to index. */
@@ -65,8 +63,6 @@ export interface IndexField {
6563

6664
/**
6765
* The SDK definition of a Firestore index.
68-
*
69-
* @internal
7066
*/
7167
export interface Index {
7268
/** The ID of the collection to index. */
@@ -82,8 +78,6 @@ export interface Index {
8278
*
8379
* See {@link https://firebase.google.com/docs/reference/firestore/indexes/#json_format | JSON Format}
8480
* for a description of the format of the index definition.
85-
*
86-
* @internal
8781
*/
8882
export interface IndexConfiguration {
8983
/** A list of all Firestore indexes. */
@@ -107,7 +101,6 @@ export interface IndexConfiguration {
107101
* before setting an index configuration. If IndexedDb is not enabled, any
108102
* index configuration is ignored.
109103
*
110-
* @internal
111104
* @param firestore - The {@link Firestore} instance to configure indexes for.
112105
* @param configuration -The index definition.
113106
* @throws FirestoreError if the JSON format is invalid.
@@ -118,6 +111,7 @@ export function setIndexConfiguration(
118111
firestore: Firestore,
119112
configuration: IndexConfiguration
120113
): Promise<void>;
114+
121115
/**
122116
* Configures indexing for local query execution. Any previous index
123117
* configuration is overridden. The `Promise` resolves once the index
@@ -137,7 +131,6 @@ export function setIndexConfiguration(
137131
* firestore:indexes`). If the JSON format is invalid, this method throws an
138132
* error.
139133
*
140-
* @internal
141134
* @param firestore - The {@link Firestore} instance to configure indexes for.
142135
* @param json -The JSON format exported by the Firebase CLI.
143136
* @throws FirestoreError if the JSON format is invalid.
@@ -148,6 +141,7 @@ export function setIndexConfiguration(
148141
firestore: Firestore,
149142
json: string
150143
): Promise<void>;
144+
151145
export function setIndexConfiguration(
152146
firestore: Firestore,
153147
jsonOrConfiguration: string | IndexConfiguration

packages/firestore/test/integration/api/index_configuration.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import { expect } from 'chai';
1919

20-
import { _setIndexConfiguration as setIndexConfiguration } from '../util/firebase_export';
20+
import { setIndexConfiguration } from '../util/firebase_export';
2121
import { apiDescribe, withTestDb } from '../util/helpers';
2222

2323
apiDescribe('Index Configuration:', (persistence: boolean) => {

0 commit comments

Comments
 (0)