Skip to content

Commit 0880c8d

Browse files
committed
Revert to get public API back, as free functions.
1 parent 6c6c49a commit 0880c8d

File tree

13 files changed

+431
-298
lines changed

13 files changed

+431
-298
lines changed

integration/firestore/firebase_export.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,16 @@ const Timestamp = firebase.firestore.Timestamp;
5555
const GeoPoint = firebase.firestore.GeoPoint;
5656
const FieldValue = firebase.firestore.FieldValue;
5757
const Blob = firebase.firestore.Blob;
58+
const loadBundle = firebase.firestore.loadBundle;
59+
const namedQuery = firebase.firestore.namedQuery;
5860

59-
export { Firestore, FieldValue, FieldPath, Timestamp, Blob, GeoPoint };
61+
export {
62+
Firestore,
63+
FieldValue,
64+
FieldPath,
65+
Timestamp,
66+
Blob,
67+
GeoPoint,
68+
loadBundle,
69+
namedQuery
70+
};

integration/firestore/firebase_export_memory.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,16 @@ const Timestamp = firebase.firestore.Timestamp;
5555
const GeoPoint = firebase.firestore.GeoPoint;
5656
const FieldValue = firebase.firestore.FieldValue;
5757
const Blob = firebase.firestore.Blob;
58+
const loadBundle = firebase.firestore.loadBundle;
59+
const namedQuery = firebase.firestore.namedQuery;
5860

59-
export { Firestore, FieldValue, FieldPath, Timestamp, Blob, GeoPoint };
61+
export {
62+
Firestore,
63+
FieldValue,
64+
FieldPath,
65+
Timestamp,
66+
Blob,
67+
GeoPoint,
68+
loadBundle,
69+
namedQuery
70+
};

packages/firebase/index.d.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8285,6 +8285,43 @@ declare namespace firebase.firestore {
82858285
INTERNAL: { delete: () => Promise<void> };
82868286
}
82878287

8288+
export function loadBundle(
8289+
db: Firestore,
8290+
bundleData: ArrayBuffer | ReadableStream<ArrayBuffer> | string
8291+
): LoadBundleTask;
8292+
8293+
export function namedQuery(
8294+
db: Firestore,
8295+
name: string
8296+
): Promise<Query<DocumentData> | null>;
8297+
8298+
export interface LoadBundleTask {
8299+
onProgress(
8300+
next?: (progress: LoadBundleTaskProgress) => any,
8301+
error?: (error: Error) => any,
8302+
complete?: () => void
8303+
): void;
8304+
8305+
then<T, R>(
8306+
onFulfilled?: (a: LoadBundleTaskProgress) => T | PromiseLike<T>,
8307+
onRejected?: (a: Error) => R | PromiseLike<R>
8308+
): Promise<T | R>;
8309+
8310+
catch<R>(
8311+
onRejected: (a: Error) => R | PromiseLike<R>
8312+
): Promise<R | LoadBundleTaskProgress>;
8313+
}
8314+
8315+
export interface LoadBundleTaskProgress {
8316+
documentsLoaded: number;
8317+
totalDocuments: number;
8318+
bytesLoaded: number;
8319+
totalBytes: number;
8320+
taskState: TaskState;
8321+
}
8322+
8323+
export type TaskState = 'Error' | 'Running' | 'Success';
8324+
82888325
/**
82898326
* An immutable object representing a geo point in Firestore. The geo point
82908327
* is represented as latitude/longitude pair.

packages/firestore-types/index.d.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,43 @@ export class FirebaseFirestore {
9999
INTERNAL: { delete: () => Promise<void> };
100100
}
101101

102+
export function loadBundle(
103+
db: FirebaseFirestore,
104+
bundleData: ArrayBuffer | ReadableStream<ArrayBuffer> | string
105+
): LoadBundleTask;
106+
107+
export function namedQuery(
108+
db: FirebaseFirestore,
109+
name: string
110+
): Promise<Query<DocumentData> | null>;
111+
112+
export interface LoadBundleTask {
113+
onProgress(
114+
next?: (progress: LoadBundleTaskProgress) => any,
115+
error?: (error: Error) => any,
116+
complete?: () => void
117+
): void;
118+
119+
then<T, R>(
120+
onFulfilled?: (a: LoadBundleTaskProgress) => T | PromiseLike<T>,
121+
onRejected?: (a: Error) => R | PromiseLike<R>
122+
): Promise<T | R>;
123+
124+
catch<R>(
125+
onRejected: (a: Error) => R | PromiseLike<R>
126+
): Promise<R | LoadBundleTaskProgress>;
127+
}
128+
129+
export interface LoadBundleTaskProgress {
130+
documentsLoaded: number;
131+
totalDocuments: number;
132+
bytesLoaded: number;
133+
totalBytes: number;
134+
taskState: TaskState;
135+
}
136+
137+
export type TaskState = 'Error' | 'Running' | 'Success';
138+
102139
export class GeoPoint {
103140
constructor(latitude: number, longitude: number);
104141

packages/firestore/exp-types/index.d.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,43 @@ export function snapshotEqual<T>(
516516
right: DocumentSnapshot<T> | QuerySnapshot<T>
517517
): boolean;
518518

519+
export interface LoadBundleTask {
520+
onProgress(
521+
next?: (progress: LoadBundleTaskProgress) => any,
522+
error?: (error: Error) => any,
523+
complete?: () => void
524+
): void;
525+
526+
then<T, R>(
527+
onFulfilled?: (a: LoadBundleTaskProgress) => T | PromiseLike<T>,
528+
onRejected?: (a: Error) => R | PromiseLike<R>
529+
): Promise<T | R>;
530+
531+
catch<R>(
532+
onRejected: (a: Error) => R | PromiseLike<R>
533+
): Promise<R | LoadBundleTaskProgress>;
534+
}
535+
536+
export interface LoadBundleTaskProgress {
537+
documentsLoaded: number;
538+
totalDocuments: number;
539+
bytesLoaded: number;
540+
totalBytes: number;
541+
taskState: TaskState;
542+
}
543+
544+
export type TaskState = 'Error' | 'Running' | 'Success';
545+
546+
export function loadBundle(
547+
firestore: FirebaseFirestore,
548+
bundleData: ArrayBuffer | ReadableStream<Uint8Array> | string
549+
): LoadBundleTask;
550+
551+
export function namedQuery(
552+
firestore: FirebaseFirestore,
553+
name: string
554+
): Promise<Query<DocumentData> | null>;
555+
519556
export type FirestoreErrorCode =
520557
| 'cancelled'
521558
| 'unknown'

packages/firestore/exp/test/shim.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,13 @@ import {
5151
DocumentSnapshot,
5252
QuerySnapshot,
5353
wrapObserver,
54-
extractSnapshotOptions
54+
extractSnapshotOptions,
55+
loadBundle,
56+
namedQuery
5557
} from '../../src/api/database';
5658

5759
export { GeoPoint, Timestamp } from '../index';
60+
export { loadBundle, namedQuery };
5861

5962
/* eslint-disable @typescript-eslint/no-explicit-any */
6063

packages/firestore/register-module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ declare module '@firebase/app-types' {
3636
Transaction: typeof types.Transaction;
3737
WriteBatch: typeof types.WriteBatch;
3838
setLogLevel: typeof types.setLogLevel;
39+
loadBundle: typeof types.loadBundle;
40+
namedQuery: typeof types.namedQuery;
3941
};
4042
}
4143
interface FirebaseApp {

packages/firestore/src/api/bundle.ts

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,46 +15,24 @@
1515
* limitations under the License.
1616
*/
1717

18+
import * as firestore from '@firebase/firestore-types';
1819
import { Deferred } from '../util/promise';
1920
import { PartialObserver } from './observer';
2021
import { debugAssert } from '../util/assert';
2122
import { FirestoreError } from '../util/error';
2223

23-
export interface ApiLoadBundleTask {
24-
onProgress(
25-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
26-
next?: (progress: ApiLoadBundleTaskProgress) => any,
27-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
28-
error?: (error: Error) => any,
29-
complete?: () => void
30-
): void;
31-
32-
then<T, R>(
33-
onFulfilled?: (a: ApiLoadBundleTaskProgress) => T | PromiseLike<T>,
34-
onRejected?: (a: Error) => R | PromiseLike<R>
35-
): Promise<T | R>;
36-
37-
catch<R>(
38-
onRejected: (a: Error) => R | PromiseLike<R>
39-
): Promise<R | ApiLoadBundleTaskProgress>;
40-
}
41-
42-
export interface ApiLoadBundleTaskProgress {
43-
documentsLoaded: number;
44-
totalDocuments: number;
45-
bytesLoaded: number;
46-
totalBytes: number;
47-
taskState: TaskState;
48-
}
49-
50-
export type TaskState = 'Error' | 'Running' | 'Success';
51-
5224
export class LoadBundleTask
53-
implements ApiLoadBundleTask, PromiseLike<ApiLoadBundleTaskProgress> {
54-
private _progressObserver: PartialObserver<ApiLoadBundleTaskProgress> = {};
55-
private _taskCompletionResolver = new Deferred<ApiLoadBundleTaskProgress>();
56-
57-
private _lastProgress: ApiLoadBundleTaskProgress = {
25+
implements
26+
firestore.LoadBundleTask,
27+
PromiseLike<firestore.LoadBundleTaskProgress> {
28+
private _progressObserver: PartialObserver<
29+
firestore.LoadBundleTaskProgress
30+
> = {};
31+
private _taskCompletionResolver = new Deferred<
32+
firestore.LoadBundleTaskProgress
33+
>();
34+
35+
private _lastProgress: firestore.LoadBundleTaskProgress = {
5836
taskState: 'Running',
5937
totalBytes: 0,
6038
totalDocuments: 0,
@@ -63,7 +41,7 @@ export class LoadBundleTask
6341
};
6442

6543
onProgress(
66-
next?: (progress: ApiLoadBundleTaskProgress) => unknown,
44+
next?: (progress: firestore.LoadBundleTaskProgress) => unknown,
6745
error?: (err: Error) => unknown,
6846
complete?: () => void
6947
): void {
@@ -76,12 +54,12 @@ export class LoadBundleTask
7654

7755
catch<R>(
7856
onRejected: (a: Error) => R | PromiseLike<R>
79-
): Promise<R | ApiLoadBundleTaskProgress> {
57+
): Promise<R | firestore.LoadBundleTaskProgress> {
8058
return this._taskCompletionResolver.promise.catch(onRejected);
8159
}
8260

8361
then<T, R>(
84-
onFulfilled?: (a: ApiLoadBundleTaskProgress) => T | PromiseLike<T>,
62+
onFulfilled?: (a: firestore.LoadBundleTaskProgress) => T | PromiseLike<T>,
8563
onRejected?: (a: Error) => R | PromiseLike<R>
8664
): Promise<T | R> {
8765
return this._taskCompletionResolver.promise.then(onFulfilled, onRejected);
@@ -91,7 +69,7 @@ export class LoadBundleTask
9169
* Notifies all observers that bundle loading has completed, with a provided
9270
* `LoadBundleTaskProgress` object.
9371
*/
94-
_completeWith(progress: ApiLoadBundleTaskProgress): void {
72+
_completeWith(progress: firestore.LoadBundleTaskProgress): void {
9573
debugAssert(
9674
progress.taskState === 'Success',
9775
'Task is not completed with Success.'
@@ -126,7 +104,7 @@ export class LoadBundleTask
126104
* Notifies a progress update of loading a bundle.
127105
* @param progress The new progress.
128106
*/
129-
_updateProgress(progress: ApiLoadBundleTaskProgress): void {
107+
_updateProgress(progress: firestore.LoadBundleTaskProgress): void {
130108
debugAssert(
131109
this._lastProgress.taskState === 'Running',
132110
'Cannot update progress on a completed or failed task'

packages/firestore/src/api/database.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ import {
156156

157157
import { makeDatabaseInfo } from '../../lite/src/api/database';
158158
import { DEFAULT_HOST } from '../../lite/src/api/components';
159-
import { ApiLoadBundleTask, LoadBundleTask } from './bundle';
159+
import { LoadBundleTask } from './bundle';
160160

161161
/**
162162
* Constant used to indicate the LRU garbage collection should be disabled.
@@ -448,7 +448,7 @@ export function setLogLevel(level: PublicLogLevel): void {
448448
export function loadBundle(
449449
db: Firestore,
450450
bundleData: ArrayBuffer | ReadableStream<Uint8Array> | string
451-
): ApiLoadBundleTask {
451+
): LoadBundleTask {
452452
const resultTask = new LoadBundleTask();
453453
// eslint-disable-next-line @typescript-eslint/no-floating-promises
454454
firestoreClientLoadBundle(

packages/firestore/src/config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ import {
3030
QuerySnapshot,
3131
Transaction,
3232
WriteBatch,
33-
setLogLevel
33+
setLogLevel,
34+
loadBundle,
35+
namedQuery
3436
} from './api/database';
3537
import { Blob } from './api/blob';
3638
import { FieldPath } from './api/field_path';
@@ -54,6 +56,8 @@ const firestoreNamespace = {
5456
FieldPath,
5557
FieldValue,
5658
setLogLevel,
59+
loadBundle,
60+
namedQuery,
5761
CACHE_SIZE_UNLIMITED
5862
};
5963

packages/firestore/src/core/bundle.ts

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

18+
import * as firestore from '@firebase/firestore-types';
1819
import { Query } from './query';
1920
import { SnapshotVersion } from './snapshot_version';
2021
import {
@@ -40,7 +41,6 @@ import {
4041
DocumentKeySet,
4142
MaybeDocumentMap
4243
} from '../model/collections';
43-
import { ApiLoadBundleTaskProgress } from '../api/bundle';
4444

4545
/**
4646
* Represents a Firestore bundle saved by the SDK in its local storage.
@@ -118,7 +118,7 @@ export class BundleConverter {
118118
*/
119119
export function bundleInitialProgress(
120120
metadata: BundleMetadata
121-
): ApiLoadBundleTaskProgress {
121+
): firestore.LoadBundleTaskProgress {
122122
return {
123123
taskState: 'Running',
124124
documentsLoaded: 0,
@@ -134,7 +134,7 @@ export function bundleInitialProgress(
134134
*/
135135
export function bundleSuccessProgress(
136136
metadata: BundleMetadata
137-
): ApiLoadBundleTaskProgress {
137+
): firestore.LoadBundleTaskProgress {
138138
return {
139139
taskState: 'Success',
140140
documentsLoaded: metadata.totalDocuments!,
@@ -146,7 +146,7 @@ export function bundleSuccessProgress(
146146

147147
export class BundleLoadResult {
148148
constructor(
149-
readonly progress: ApiLoadBundleTaskProgress,
149+
readonly progress: firestore.LoadBundleTaskProgress,
150150
readonly changedDocs: MaybeDocumentMap
151151
) {}
152152
}
@@ -157,7 +157,7 @@ export class BundleLoadResult {
157157
*/
158158
export class BundleLoader {
159159
/** The current progress of loading */
160-
private progress: ApiLoadBundleTaskProgress;
160+
private progress: firestore.LoadBundleTaskProgress;
161161
/** Batched queries to be saved into storage */
162162
private queries: bundleProto.NamedQuery[] = [];
163163
/** Batched documents to be saved into storage */
@@ -179,7 +179,7 @@ export class BundleLoader {
179179
*/
180180
addSizedElement(
181181
element: SizedBundleElement
182-
): ApiLoadBundleTaskProgress | null {
182+
): firestore.LoadBundleTaskProgress | null {
183183
debugAssert(!element.isBundleMetadata(), 'Unexpected bundle metadata.');
184184

185185
this.progress.bytesLoaded += element.byteLength;

0 commit comments

Comments
 (0)