-
Notifications
You must be signed in to change notification settings - Fork 909
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New bundle analysis to evaluate useFirestorePipelines vs execute
- Loading branch information
1 parent
0750f35
commit ecd931d
Showing
13 changed files
with
1,410 additions
and
884 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +0,0 @@ | ||
/** | ||
* @license | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { Pipeline } from '../lite-api/pipeline'; | ||
import { PipelineSource } from '../lite-api/pipeline-source'; | ||
import { newUserDataReader } from '../lite-api/user_data_reader'; | ||
import { DocumentKey } from '../model/document_key'; | ||
|
||
import { Firestore } from './database'; | ||
import { DocumentReference, Query } from './reference'; | ||
import { ExpUserDataWriter } from './user_data_writer'; | ||
|
||
export function useFirestorePipelines(): void { | ||
Firestore.prototype.pipeline = function (): PipelineSource { | ||
const firestore = this; | ||
return new PipelineSource( | ||
this, | ||
newUserDataReader(firestore), | ||
new ExpUserDataWriter(firestore), | ||
(key: DocumentKey) => { | ||
return new DocumentReference(firestore, null, key); | ||
} | ||
); | ||
}; | ||
|
||
Query.prototype.pipeline = function (): Pipeline { | ||
let pipeline; | ||
if (this._query.collectionGroup) { | ||
pipeline = this.firestore | ||
.pipeline() | ||
.collectionGroup(this._query.collectionGroup); | ||
} else { | ||
pipeline = this.firestore | ||
.pipeline() | ||
.collection(this._query.path.canonicalString()); | ||
} | ||
|
||
// TODO(pipeline) convert existing query filters, limits, etc into | ||
// pipeline stages | ||
|
||
return pipeline; | ||
}; | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/** | ||
* @license | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { PipelineSource as LitePipelineSoure } from '../lite-api/pipeline-source'; | ||
import { | ||
CollectionGroupSource, | ||
CollectionSource, | ||
DatabaseSource, | ||
DocumentsSource | ||
} from '../lite-api/stage'; | ||
import { UserDataReader } from '../lite-api/user_data_reader'; | ||
import { AbstractUserDataWriter } from '../lite-api/user_data_writer'; | ||
import { DocumentKey } from '../model/document_key'; | ||
import { cast } from '../util/input_validation'; | ||
|
||
import { Firestore } from './database'; | ||
import { Pipeline } from './pipeline'; | ||
import { DocumentReference } from './reference'; | ||
|
||
/** | ||
* Represents the source of a Firestore {@link Pipeline}. | ||
* @beta | ||
*/ | ||
export class PipelineSource extends LitePipelineSoure { | ||
/** | ||
* @internal | ||
* @private | ||
* @param db | ||
* @param userDataReader | ||
* @param userDataWriter | ||
* @param documentReferenceFactory | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-useless-constructor | ||
constructor( | ||
db: Firestore, | ||
userDataReader: UserDataReader, | ||
userDataWriter: AbstractUserDataWriter, | ||
documentReferenceFactory: (id: DocumentKey) => DocumentReference | ||
) { | ||
super(db, userDataReader, userDataWriter, documentReferenceFactory); | ||
} | ||
|
||
collection(collectionPath: string): Pipeline { | ||
const db = cast<Firestore>(this.db, Firestore); | ||
return new Pipeline( | ||
db, | ||
this.userDataReader, | ||
this.userDataWriter, | ||
this.documentReferenceFactory, | ||
[new CollectionSource(collectionPath)] | ||
); | ||
} | ||
|
||
collectionGroup(collectionId: string): Pipeline { | ||
const db = cast<Firestore>(this.db, Firestore); | ||
return new Pipeline( | ||
db, | ||
this.userDataReader, | ||
this.userDataWriter, | ||
this.documentReferenceFactory, | ||
[new CollectionGroupSource(collectionId)] | ||
); | ||
} | ||
|
||
database(): Pipeline { | ||
const db = cast<Firestore>(this.db, Firestore); | ||
return new Pipeline( | ||
db, | ||
this.userDataReader, | ||
this.userDataWriter, | ||
this.documentReferenceFactory, | ||
[new DatabaseSource()] | ||
); | ||
} | ||
|
||
documents(docs: DocumentReference[]): Pipeline { | ||
const db = cast<Firestore>(this.db, Firestore); | ||
return new Pipeline( | ||
db, | ||
this.userDataReader, | ||
this.userDataWriter, | ||
this.documentReferenceFactory, | ||
[DocumentsSource.of(docs)] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.