Skip to content

Commit 90ce598

Browse files
committed
Merge remote-tracking branch 'origin/feat/pipelines' into wuandy/offppl-type1
# Conflicts: # packages/firestore/lite/index.ts # packages/firestore/src/api/database_augmentation.ts # packages/firestore/src/api/pipeline_impl.ts # packages/firestore/src/lite-api/expressions.ts
2 parents 656e848 + df90a2e commit 90ce598

File tree

17 files changed

+540
-401
lines changed

17 files changed

+540
-401
lines changed

common/api-review/firestore-lite.api.md

Lines changed: 146 additions & 130 deletions
Large diffs are not rendered by default.

common/api-review/firestore.api.md

Lines changed: 134 additions & 108 deletions
Large diffs are not rendered by default.

packages/firestore/lite/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ export { PipelineResult } from '../src/lite-api/pipeline-result';
3333

3434
export { Pipeline } from '../src/lite-api/pipeline';
3535

36-
export { execute } from '../src/lite-api/pipeline_impl';
36+
export {
37+
useFluentPipelines,
38+
pipeline,
39+
execute
40+
} from '../src/lite-api/pipeline_impl';
3741

3842
export {
3943
Stage,

packages/firestore/src/api.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ export { PipelineResult } from './lite-api/pipeline-result';
2121

2222
export { Pipeline } from './api/pipeline';
2323

24-
export { useFirestorePipelines, pipeline } from './api/pipeline_impl';
25-
26-
export { execute } from './lite-api/pipeline_impl';
24+
export { useFluentPipelines, pipeline, execute } from './api/pipeline_impl';
2725

2826
export {
2927
Stage,

packages/firestore/src/api/database.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ import {
4646
connectFirestoreEmulator,
4747
Firestore as LiteFirestore
4848
} from '../lite-api/database';
49-
import type { PipelineSource } from '../lite-api/pipeline-source';
5049
import { Query } from '../lite-api/reference';
5150
import {
5251
indexedDbClearPersistence,
@@ -129,15 +128,6 @@ export class Firestore extends LiteFirestore {
129128
await terminate;
130129
}
131130
}
132-
133-
/**
134-
* Pipeline query.
135-
*/
136-
pipeline(): PipelineSource {
137-
throw new Error(
138-
'Pipelines not initialized. Your application must call `useFirestorePipelines()` before using Firestore Pipeline features.'
139-
);
140-
}
141131
}
142132

143133
/**

packages/firestore/src/api/database_augmentation.ts

Lines changed: 0 additions & 51 deletions
This file was deleted.

packages/firestore/src/api/pipeline-source.ts

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -39,61 +39,61 @@ export class PipelineSource extends LitePipelineSoure {
3939
/**
4040
* @internal
4141
* @private
42-
* @param db
43-
* @param userDataReader
44-
* @param userDataWriter
45-
* @param documentReferenceFactory
42+
* @param _db
43+
* @param _userDataReader
44+
* @param _userDataWriter
45+
* @param _documentReferenceFactory
4646
*/
4747
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
4848
constructor(
49-
db: Firestore,
50-
userDataReader: UserDataReader,
51-
userDataWriter: AbstractUserDataWriter,
52-
documentReferenceFactory: (id: DocumentKey) => DocumentReference
49+
_db: Firestore,
50+
_userDataReader: UserDataReader,
51+
_userDataWriter: AbstractUserDataWriter,
52+
_documentReferenceFactory: (id: DocumentKey) => DocumentReference
5353
) {
54-
super(db, userDataReader, userDataWriter, documentReferenceFactory);
54+
super(_db, _userDataReader, _userDataWriter, _documentReferenceFactory);
5555
}
5656

5757
collection(collectionPath: string): Pipeline {
58-
const db = cast<Firestore>(this.db, Firestore);
58+
const _db = cast<Firestore>(this._db, Firestore);
5959
return new Pipeline(
60-
db,
61-
this.userDataReader,
62-
this.userDataWriter,
63-
this.documentReferenceFactory,
60+
_db,
61+
this._userDataReader,
62+
this._userDataWriter,
63+
this._documentReferenceFactory,
6464
[new CollectionSource(collectionPath)]
6565
);
6666
}
6767

6868
collectionGroup(collectionId: string): Pipeline {
69-
const db = cast<Firestore>(this.db, Firestore);
69+
const _db = cast<Firestore>(this._db, Firestore);
7070
return new Pipeline(
71-
db,
72-
this.userDataReader,
73-
this.userDataWriter,
74-
this.documentReferenceFactory,
71+
_db,
72+
this._userDataReader,
73+
this._userDataWriter,
74+
this._documentReferenceFactory,
7575
[new CollectionGroupSource(collectionId)]
7676
);
7777
}
7878

7979
database(): Pipeline {
80-
const db = cast<Firestore>(this.db, Firestore);
80+
const _db = cast<Firestore>(this._db, Firestore);
8181
return new Pipeline(
82-
db,
83-
this.userDataReader,
84-
this.userDataWriter,
85-
this.documentReferenceFactory,
82+
_db,
83+
this._userDataReader,
84+
this._userDataWriter,
85+
this._documentReferenceFactory,
8686
[new DatabaseSource()]
8787
);
8888
}
8989

9090
documents(docs: DocumentReference[]): Pipeline {
91-
const db = cast<Firestore>(this.db, Firestore);
91+
const _db = cast<Firestore>(this._db, Firestore);
9292
return new Pipeline(
93-
db,
94-
this.userDataReader,
95-
this.userDataWriter,
96-
this.documentReferenceFactory,
93+
_db,
94+
this._userDataReader,
95+
this._userDataWriter,
96+
this._documentReferenceFactory,
9797
[DocumentsSource.of(docs)]
9898
);
9999
}

packages/firestore/src/api/pipeline.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ export class Pipeline<
5858
);
5959
}
6060

61+
/**
62+
* @internal
63+
* @private
64+
* @param db
65+
* @param userDataReader
66+
* @param userDataWriter
67+
* @param documentReferenceFactory
68+
* @param stages
69+
* @param converter
70+
* @protected
71+
*/
6172
protected newPipeline(
6273
db: Firestore,
6374
userDataReader: UserDataReader,
@@ -109,7 +120,7 @@ export class Pipeline<
109120
*/
110121
execute(): Promise<Array<PipelineResult<AppModelType>>> {
111122
throw new Error(
112-
'Pipelines not initialized. Your application must call `useFirestorePipelines()` before using Firestore Pipeline features.'
123+
'Pipelines not initialized. Your application must call `useFluentPipelines()` before using Firestore Pipeline features.'
113124
);
114125
}
115126
}

packages/firestore/src/api/pipeline_impl.ts

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
// Copyright 2024 Google LLC
2-
//
3-
// Licensed under the Apache License, Version 2.0 (the "License");
4-
// you may not use this file except in compliance with the License.
5-
// You may obtain a copy of the License at
6-
//
7-
// http://www.apache.org/licenses/LICENSE-2.0
8-
//
9-
// Unless required by applicable law or agreed to in writing, software
10-
// distributed under the License is distributed on an "AS IS" BASIS,
11-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
// See the License for the specific language governing permissions and
13-
// limitations under the License.
1+
/**
2+
* @license
3+
* Copyright 2024 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+
*/
1417

1518
import { PipelineSnapshot } from './snapshot';
1619
import { FirestoreError } from '../util/error';
@@ -28,13 +31,22 @@ import { PipelineResult } from '../lite-api/pipeline-result';
2831
import { CorePipeline } from '../core/pipeline_run';
2932

3033
import { PipelineSource } from '../api/pipeline-source';
34+
import { firestoreClientExecutePipeline } from '../core/firestore_client';
35+
import { Pipeline as LitePipeline } from '../lite-api/pipeline';
36+
import { PipelineResult } from '../lite-api/pipeline-result';
3137
import { newUserDataReader } from '../lite-api/user_data_reader';
3238
import { DocumentKey } from '../model/document_key';
3339
import { cast } from '../util/input_validation';
3440

3541
import { DocumentReference, Query } from './reference';
3642
import { ExpUserDataWriter } from './user_data_writer';
3743

44+
declare module './database' {
45+
interface Firestore {
46+
pipeline(): PipelineSource;
47+
}
48+
}
49+
3850
/**
3951
* Experimental Modular API for console testing.
4052
* @param firestore
@@ -76,7 +88,7 @@ export function pipeline(
7688
return result;
7789
}
7890
}
79-
export function useFirestorePipelines(): void {
91+
export function useFluentPipelines(): void {
8092
Firestore.prototype.pipeline = function (): PipelineSource {
8193
return pipeline(this);
8294
};
@@ -91,7 +103,7 @@ export function useFirestorePipelines(): void {
91103
}
92104

93105
export function execute<AppModelType>(
94-
pipeline: Pipeline
106+
pipeline: LitePipeline
95107
): Promise<Array<PipelineResult<AppModelType>>> {
96108
const firestore = cast(pipeline._db, Firestore);
97109
const client = ensureFirestoreConfigured(firestore);

packages/firestore/src/api_pipelines.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export { PipelineResult } from './lite-api/pipeline-result';
2020

2121
export { Pipeline } from './lite-api/pipeline';
2222

23-
export { useFirestorePipelines } from './api/database_augmentation';
23+
export { useFluentPipelines, execute, pipeline } from './api/pipeline_impl';
2424

2525
export {
2626
Stage,

0 commit comments

Comments
 (0)