Skip to content

Commit d18310a

Browse files
Markduckworth/ppl mep (#8801)
* Multiple entry points for main package. * MEP for firestore lite building * Fix issue with external exports * Refactor to support multiple entry points for the lite SDK. Fixes import issues and makes code organization across /pipelines and /lite/pipeliens * Type and comment cleanup * Make PipelineSource generic and remove useFluentPipelines * Remove converter and placeholders for converter. * cleanup: remove documentReferenceFactory * Linting and formatting * Update the typings export for pipelines and lite pipelines so that it auguments the Firestore and Query classes. * Add missing Expr export * Lint fixes * TODO cleanup * update api review * Query to Proto with integration tests * API tweaks from review. Selectable, FilterCondition, and Accumulator are abstract classes not interfaces. Removed extraneous Pipeline.sort overload * Remove console.log statements from prune-dts.ts * code cleanup in prune-dts * Add missing imports to pipelines.ts * If argument to FunctionExpr is a plain object or array, convert these to expression using map(...) or array(...) * Add tests for evaluating expressions in arrays and maps * implement new FunctionExpressions as standalone functions * Fix typo and formatting in pipeline.test.ts * Implement support for genericStage and genericFunction * Implement new function expressions as methods on the Expr class. * Pipeline test reorganization * Implementing new stages Sample, Union, Unnest, Replace * Rename FilterCondition to BooleanExpr * Update functions with variadic params to match signatures of the backend * Fix and implementation. * Refactor AggregateFunction out of Expr * Add ScalarExpr class and make Expr a base class of AggregateFunction * fixing missing imports and renames * Remove classes for individual function types * Separate scalar expressions and aggregate functions into different class hierarchies * Remove deleted Expr classes from the pipelines exports * Replace not(fn()) with notFn() in the query to pipeline conversion * Fix circular dependency between user_data_reader and expressions * removing modular pipeline creation and removing fluent pipline execution. This was a decision from API review * Change return type of execute from PipelineResult[] to PipelineSnapshot * Renames for API review: FunctionExpr, BooleanExpr, params * missing readonly * Build and test fixes * Replace Field.of() with field() * Add missing export PipelineSnaphsot * Replace Constant.of() with constant() * Removed constant(...) overloads to create a map or array. Use the array or map function instead. * Implemented and documented ascending|descending(fieldName) as a convenient way to create orderings for a specific field * fix tests creating a constant map and array * Remove genericFunction, genericAggregateFunction, and genericBooleanExpr. Replace usage with constructor * Pipeline result timestamp testing * Testing timestamp edge cases * Query to pipeline conversion is performed from the PipelineSource class rather than the Query class * Timestamp tests and fix pipeline tests for change in pipeline creation from a classic query * test fix * Refactor and rename all functions to match API proposal changes after API review. * Fix build issues * New integration util pipeline_export file to support the pipelines subpackage * Rename several FunctionExpr standalone exports from <name>Function to <name>. Meets API design * Removing the all-packages api report script because it is no longer needed * Remove any from the public api surface * lint fix * Code cleanup * FindNearest integration tests * Filling in gaps in test coverage * Implement Pipeline tests for the lite SDK * Fixed a build issue with the lite SDK * Improved error message context when invalid user data is passed to a pipeline without being wrapped in a call to constant(...) * Fix typo in old error message * Fix lite pipeline exports * api-review files * Fixing tests and improving test coverage * PR feedback * Updating replaceWith to take an Expr * yarn format
1 parent 09508e9 commit d18310a

32 files changed

+12181
-8687
lines changed

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

+721-1,426
Large diffs are not rendered by default.

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

+690-745
Large diffs are not rendered by default.

common/api-review/firestore.api.md

+8-1,335
Large diffs are not rendered by default.

packages/firestore/lite/pipelines/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"module": "../../dist/lite/pipelines.browser.esm2017.js",
77
"browser": "../../dist/lite/pipelines.browser.esm2017.js",
88
"react-native": "../../dist/lite/pipelines.rn.esm2017.js",
9-
"typings": "../../dist/lite/pipelines.d.ts",
9+
"typings": "./pipelines.d.ts",
1010
"private": true,
1111
"engines": {
1212
"node": ">=18.0.0"

packages/firestore/lite/pipelines/pipelines.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { PipelineSource, Pipeline } from '../../dist/lite/pipelines';
1919
// Augument the Firestore class with the pipeline() method.
2020
// This is stripped from dist/lite/pipelines.d.ts during the build
2121
// so it needs to be re-added here.
22-
declare module '@firebase/firestore' {
22+
declare module '@firebase/firestore/lite' {
2323
interface Firestore {
2424
pipeline(): PipelineSource<Pipeline>;
2525
}

packages/firestore/lite/pipelines/pipelines.ts

+39-69
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,14 @@ export type {
5050

5151
export { PipelineSource } from '../../src/lite-api/pipeline-source';
5252

53-
export { PipelineResult } from '../../src/lite-api/pipeline-result';
53+
export {
54+
PipelineResult,
55+
PipelineSnapshot
56+
} from '../../src/lite-api/pipeline-result';
5457

5558
export { Pipeline } from '../../src/lite-api/pipeline';
5659

57-
export { pipeline, execute } from '../../src/lite-api/pipeline_impl';
60+
export { execute } from '../../src/lite-api/pipeline_impl';
5861

5962
export {
6063
Stage,
@@ -76,14 +79,44 @@ export {
7679
} from '../../src/lite-api/stage';
7780

7881
export {
82+
Expr,
83+
field,
84+
and,
85+
array,
86+
arrayOffset,
87+
constant,
7988
add,
8089
subtract,
8190
multiply,
91+
avg,
92+
bitAnd,
93+
substr,
94+
constantVector,
95+
bitLeftShift,
96+
bitNot,
97+
count,
98+
mapMerge,
99+
mapRemove,
100+
bitOr,
101+
ifError,
102+
isAbsent,
103+
isError,
104+
or,
105+
rand,
106+
bitRightShift,
107+
bitXor,
82108
divide,
109+
isNotNan,
110+
map,
111+
isNotNull,
112+
isNull,
83113
mod,
114+
documentId,
84115
eq,
85116
neq,
86117
lt,
118+
countIf,
119+
currentContext,
87120
lte,
88121
gt,
89122
gte,
@@ -132,79 +165,16 @@ export {
132165
timestampToUnixSeconds,
133166
timestampAdd,
134167
timestampSub,
135-
genericFunction,
136168
ascending,
137169
descending,
138170
ExprWithAlias,
139171
Field,
140-
Fields,
141172
Constant,
142-
FirestoreFunction,
143-
Add,
144-
Subtract,
145-
Multiply,
146-
Divide,
147-
Mod,
148-
Eq,
149-
Neq,
150-
Lt,
151-
Lte,
152-
Gt,
153-
Gte,
154-
ArrayConcat,
155-
ArrayReverse,
156-
ArrayContains,
157-
ArrayContainsAll,
158-
ArrayContainsAny,
159-
ArrayLength,
160-
ArrayElement,
161-
EqAny,
162-
IsNan,
163-
Exists,
164-
Not,
165-
And,
166-
Or,
167-
Xor,
168-
Cond,
169-
LogicalMaximum,
170-
LogicalMinimum,
171-
Reverse,
172-
ReplaceFirst,
173-
ReplaceAll,
174-
CharLength,
175-
ByteLength,
176-
Like,
177-
RegexContains,
178-
RegexMatch,
179-
StrContains,
180-
StartsWith,
181-
EndsWith,
182-
ToLower,
183-
ToUpper,
184-
Trim,
185-
StrConcat,
186-
MapGet,
187-
Count,
188-
Sum,
189-
Avg,
190-
Minimum,
191-
Maximum,
192-
CosineDistance,
193-
DotProduct,
194-
EuclideanDistance,
195-
VectorLength,
196-
UnixMicrosToTimestamp,
197-
TimestampToUnixMicros,
198-
UnixMillisToTimestamp,
199-
TimestampToUnixMillis,
200-
UnixSecondsToTimestamp,
201-
TimestampToUnixSeconds,
202-
TimestampAdd,
203-
TimestampSub,
173+
FunctionExpr,
204174
Ordering,
205175
ExprType,
206-
AccumulatorTarget,
176+
AggregateWithAlias,
207177
Selectable,
208-
FilterCondition,
209-
Accumulator
178+
BooleanExpr,
179+
AggregateFunction
210180
} from '../../src/lite-api/expressions';

packages/firestore/package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,11 @@
4848
"test:minified": "(cd ../../integration/firestore ; yarn test)",
4949
"trusted-type-check": "tsec -p tsconfig.json --noEmit",
5050
"api-report:main": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' ts-node ../../repo-scripts/prune-dts/extract-public-api.ts --package firestore --packageRoot . --typescriptDts ./dist/firestore/src/index.d.ts --rollupDts ./dist/private.d.ts --untrimmedRollupDts ./dist/internal.d.ts --publicDts ./dist/index.d.ts",
51-
"api-report:all-packages": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' ts-node ../../repo-scripts/prune-dts/extract-public-api.ts --package firestore --packageRoot . --typescriptDts ./dist/firestore/src/all_packages.d.ts --rollupDts ./dist/private.all_packages.d.ts --untrimmedRollupDts ./dist/internal.all_packages.d.ts --publicDts ./dist/all_packages.d.ts",
5251
"api-report:pipelines": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' ts-node ../../repo-scripts/prune-dts/extract-public-api.ts --package firestore-pipelines --packageRoot . --typescriptDts ./dist/firestore/pipelines/pipelines.d.ts --rollupDts ./dist/private.pipelines.d.ts --untrimmedRollupDts ./dist/internal.pipelines.d.ts --publicDts ./dist/pipelines.d.ts --otherExportsPublicDtsFiles ./dist/index.d.ts",
5352
"api-report:lite": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' ts-node ../../repo-scripts/prune-dts/extract-public-api.ts --package firestore-lite --packageRoot . --typescriptDts ./dist/firestore/lite/index.d.ts --rollupDts ./dist/lite/private.d.ts --untrimmedRollupDts ./dist/lite/internal.d.ts --publicDts ./dist/lite/index.d.ts",
54-
"api-report:lite:pipelines": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' ts-node ../../repo-scripts/prune-dts/extract-public-api.ts --package firestore-lite-pipelines --packageRoot . --typescriptDts ./dist/firestore/lite/pipelines/pipelines.d.ts --rollupDts ./dist/lite/private.pipelines.d.ts --untrimmedRollupDts ./dist/lite/internal.pipelines.d.ts --publicDts ./dist/lite/pipelines.d.ts --otherExportsPublicDtsFiles ./dist/index.d.ts",
53+
"api-report:lite:pipelines": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' ts-node ../../repo-scripts/prune-dts/extract-public-api.ts --package firestore-lite-pipelines --packageRoot . --typescriptDts ./dist/firestore/lite/pipelines/pipelines.d.ts --rollupDts ./dist/lite/private.pipelines.d.ts --untrimmedRollupDts ./dist/lite/internal.pipelines.d.ts --publicDts ./dist/lite/pipelines.d.ts --otherExportsPublicDtsFiles ./dist/lite/index.d.ts",
5554
"api-report:api-json": "rm -rf temp && api-extractor run --local --verbose",
56-
"api-report": "run-s --npm-path npm api-report:main api-report:pipelines api-report:all-packages api-report:lite api-report:lite:pipelines && yarn api-report:api-json",
55+
"api-report": "run-s --npm-path npm api-report:main api-report:pipelines api-report:lite api-report:lite:pipelines && yarn api-report:api-json",
5756
"doc": "api-documenter markdown --input temp --output docs",
5857
"typings:public": "node ../../scripts/build/use_typings.js ./dist/all-packages.d.ts"
5958
},

packages/firestore/pipelines/pipelines.d.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
import {PipelineSource, Pipeline} from "../dist/pipelines";
17+
import { PipelineSource, Pipeline } from '../dist/pipelines';
1818

1919
// Augument the Firestore and Query classes with the pipeline() method.
2020
// This is stripped from dist/lite/pipelines.d.ts during the build
@@ -23,9 +23,6 @@ declare module '@firebase/firestore' {
2323
interface Firestore {
2424
pipeline(): PipelineSource<Pipeline>;
2525
}
26-
interface Query {
27-
pipeline(): Pipeline;
28-
}
2926
}
3027

31-
export * from "../dist/pipelines";
28+
export * from '../dist/pipelines';

packages/firestore/src/api.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,7 @@ export { isBase64Available as _isBase64Available } from './platform/base64';
224224
export { DatabaseId as _DatabaseId } from './core/database_info';
225225
export {
226226
_internalQueryToProtoQueryTarget,
227-
_internalAggregationQueryToProtoRunAggregationQueryRequest,
228-
_internalPipelineToExecutePipelineRequestProto
227+
_internalAggregationQueryToProtoRunAggregationQueryRequest
229228
} from './remote/internal_serializer';
230229
export {
231230
cast as _cast,

packages/firestore/src/api/parse_context.ts

+45
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,53 @@
1616
*/
1717

1818
import { DatabaseId } from '../core/database_info';
19+
import { UserDataSource } from '../lite-api/user_data_reader';
20+
import { DocumentKey } from '../model/document_key';
21+
import { FieldTransform } from '../model/mutation';
22+
import { FieldPath as InternalFieldPath } from '../model/path';
23+
import { JsonProtoSerializer } from '../remote/serializer';
24+
import { FirestoreError } from '../util/error';
25+
26+
/** Contains the settings that are mutated as we parse user data. */
27+
export interface ContextSettings {
28+
/** Indicates what kind of API method this data came from. */
29+
readonly dataSource: UserDataSource;
30+
/** The name of the method the user called to create the ParseContext. */
31+
readonly methodName: string;
32+
/** The document the user is attempting to modify, if that applies. */
33+
readonly targetDoc?: DocumentKey;
34+
/**
35+
* A path within the object being parsed. This could be an empty path (in
36+
* which case the context represents the root of the data being parsed), or a
37+
* nonempty path (indicating the context represents a nested location within
38+
* the data).
39+
*/
40+
readonly path?: InternalFieldPath;
41+
/**
42+
* Whether or not this context corresponds to an element of an array.
43+
* If not set, elements are treated as if they were outside of arrays.
44+
*/
45+
readonly arrayElement?: boolean;
46+
/**
47+
* Whether or not a converter was specified in this context. If true, error
48+
* messages will reference the converter when invalid data is provided.
49+
*/
50+
readonly hasConverter?: boolean;
51+
}
1952

2053
export interface ParseContext {
54+
readonly settings: ContextSettings;
2155
readonly databaseId: DatabaseId;
56+
readonly serializer: JsonProtoSerializer;
2257
readonly ignoreUndefinedProperties: boolean;
58+
fieldTransforms: FieldTransform[];
59+
fieldMask: InternalFieldPath[];
60+
get path(): InternalFieldPath | undefined;
61+
get dataSource(): UserDataSource;
62+
contextWith(configuration: Partial<ContextSettings>): ParseContext;
63+
childContextForField(field: string): ParseContext;
64+
childContextForFieldPath(field: InternalFieldPath): ParseContext;
65+
childContextForArray(index: number): ParseContext;
66+
createError(reason: string): FirestoreError;
67+
contains(fieldPath: InternalFieldPath): boolean;
2368
}

packages/firestore/src/api/pipeline.ts

+2-64
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,12 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { firestoreClientExecutePipeline } from '../core/firestore_client';
1918
import { Pipeline as LitePipeline } from '../lite-api/pipeline';
20-
import { PipelineResult } from '../lite-api/pipeline-result';
21-
import { DocumentReference } from '../lite-api/reference';
2219
import { Stage } from '../lite-api/stage';
2320
import { UserDataReader } from '../lite-api/user_data_reader';
2421
import { AbstractUserDataWriter } from '../lite-api/user_data_writer';
25-
import { cast } from '../util/input_validation';
2622

27-
import { ensureFirestoreConfigured, Firestore } from './database';
23+
import { Firestore } from './database';
2824

2925
export class Pipeline extends LitePipeline {
3026
/**
@@ -41,66 +37,8 @@ export class Pipeline extends LitePipeline {
4137
db: Firestore,
4238
userDataReader: UserDataReader,
4339
userDataWriter: AbstractUserDataWriter,
44-
stages: Stage[],
45-
converter: unknown = {}
40+
stages: Stage[]
4641
): Pipeline {
4742
return new Pipeline(db, userDataReader, userDataWriter, stages);
4843
}
49-
50-
/**
51-
* Executes this pipeline and returns a Promise to represent the asynchronous operation.
52-
*
53-
* <p>The returned Promise can be used to track the progress of the pipeline execution
54-
* and retrieve the results (or handle any errors) asynchronously.
55-
*
56-
* <p>The pipeline results are returned as a list of {@link PipelineResult} objects. Each {@link
57-
* PipelineResult} typically represents a single key/value map that has passed through all the
58-
* stages of the pipeline, however this might differ depending on the stages involved in the
59-
* pipeline. For example:
60-
*
61-
* <ul>
62-
* <li>If there are no stages or only transformation stages, each {@link PipelineResult}
63-
* represents a single document.</li>
64-
* <li>If there is an aggregation, only a single {@link PipelineResult} is returned,
65-
* representing the aggregated results over the entire dataset .</li>
66-
* <li>If there is an aggregation stage with grouping, each {@link PipelineResult} represents a
67-
* distinct group and its associated aggregated values.</li>
68-
* </ul>
69-
*
70-
* <p>Example:
71-
*
72-
* ```typescript
73-
* const futureResults = await firestore.pipeline().collection("books")
74-
* .where(gt(Field.of("rating"), 4.5))
75-
* .select("title", "author", "rating")
76-
* .execute();
77-
* ```
78-
*
79-
* @return A Promise representing the asynchronous pipeline execution.
80-
*/
81-
execute(): Promise<PipelineResult[]> {
82-
const firestore = cast(this._db, Firestore);
83-
const client = ensureFirestoreConfigured(firestore);
84-
return firestoreClientExecutePipeline(client, this).then(result => {
85-
const docs = result
86-
// Currently ignore any response from ExecutePipeline that does
87-
// not contain any document data in the `fields` property.
88-
.filter(element => !!element.fields)
89-
.map(
90-
element =>
91-
new PipelineResult(
92-
this._userDataWriter,
93-
element.key?.path
94-
? new DocumentReference(firestore, null, element.key)
95-
: undefined,
96-
element.fields,
97-
element.executionTime?.toTimestamp(),
98-
element.createTime?.toTimestamp(),
99-
element.updateTime?.toTimestamp()
100-
)
101-
);
102-
103-
return docs;
104-
});
105-
}
10644
}

0 commit comments

Comments
 (0)