Skip to content

Commit

Permalink
Modular-style pipeline and execute methods for experimentation. Plus …
Browse files Browse the repository at this point in the history
…cleanup.
  • Loading branch information
MarkDuckworth committed Nov 13, 2024
1 parent 56c4e4a commit bcfaf2a
Show file tree
Hide file tree
Showing 12 changed files with 162 additions and 83 deletions.
17 changes: 14 additions & 3 deletions common/api-review/firestore-lite.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,9 @@ export function euclideanDistance(expr: Constant, other: VectorValue): Euclidean
// @beta
export function euclideanDistance(expr: Constant, other: Constant): EuclideanDistance;

// @beta
export function execute<AppModelType>(pipeline: Pipeline<AppModelType>): Promise<Array<PipelineResult<AppModelType>>>;

// @beta (undocumented)
export class Exists extends FirestoreFunction implements FilterCondition {
constructor(expr: Constant);
Expand Down Expand Up @@ -1612,6 +1615,14 @@ export class Pipeline<AppModelType = DocumentData> {
where(condition: FilterCondition & Constant): Pipeline<AppModelType>;
}

// Warning: (ae-incompatible-release-tags) The symbol "pipeline" is marked as @public, but its signature references "PipelineSource" which is marked as @beta
//
// @public
export function pipeline(firestore: Firestore): PipelineSource;

// @public
export function pipeline(query: Query): Pipeline;

// @beta
export class PipelineResult<AppModelType = DocumentData> {
/* Excluded from this release type: _ref */
Expand Down Expand Up @@ -2203,8 +2214,8 @@ export function xor(left: FilterExpr, ...right: FilterExpr[]): Xor;

// Warnings were encountered during analysis:
//
// /home/runner/work/firebase-js-sdk/firebase-js-sdk/packages/firestore/dist/lite/index.d.ts:9237:9 - (ae-incompatible-release-tags) The symbol "accumulators" is marked as @public, but its signature references "AccumulatorTarget" which is marked as @beta
// /home/runner/work/firebase-js-sdk/firebase-js-sdk/packages/firestore/dist/lite/index.d.ts:9238:9 - (ae-incompatible-release-tags) The symbol "groups" is marked as @public, but its signature references "Selectable" which is marked as @beta
// /home/runner/work/firebase-js-sdk/firebase-js-sdk/packages/firestore/dist/lite/index.d.ts:9267:9 - (ae-incompatible-release-tags) The symbol "orderings" is marked as @public, but its signature references "Ordering" which is marked as @beta
// /Users/markduckworth/projects/firebase-js-sdk/packages/firestore/dist/lite/index.d.ts:9243:9 - (ae-incompatible-release-tags) The symbol "accumulators" is marked as @public, but its signature references "AccumulatorTarget" which is marked as @beta
// /Users/markduckworth/projects/firebase-js-sdk/packages/firestore/dist/lite/index.d.ts:9244:9 - (ae-incompatible-release-tags) The symbol "groups" is marked as @public, but its signature references "Selectable" which is marked as @beta
// /Users/markduckworth/projects/firebase-js-sdk/packages/firestore/dist/lite/index.d.ts:9273:9 - (ae-incompatible-release-tags) The symbol "orderings" is marked as @public, but its signature references "Ordering" which is marked as @beta

```
65 changes: 28 additions & 37 deletions common/api-review/firestore.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,9 @@ export function euclideanDistance(expr: Constant, other: VectorValue): Euclidean
// @beta
export function euclideanDistance(expr: Constant, other: Constant): EuclideanDistance;

// @beta
export function execute<AppModelType>(pipeline: Pipeline<AppModelType>): Promise<Array<PipelineResult<AppModelType>>>;

// @beta (undocumented)
export class Exists extends FirestoreFunction implements FilterCondition {
constructor(expr: Constant);
Expand Down Expand Up @@ -1819,65 +1822,53 @@ export interface PersistentSingleTabManagerSettings {
// @public
export type PersistentTabManager = PersistentSingleTabManager | PersistentMultipleTabManager;

// @public
// @public (undocumented)
export class Pipeline<AppModelType = DocumentData> {
/* Excluded from this release type: _db */
/* Excluded from this release type: __constructor */
// Warning: (ae-incompatible-release-tags) The symbol "addFields" is marked as @public, but its signature references "Selectable" which is marked as @beta
addFields(...fields: Selectable[]): Pipeline<AppModelType>;
/* Excluded from this release type: userDataWriter */
/* Excluded from this release type: documentReferenceFactory */
// Warning: (ae-incompatible-release-tags) The symbol "aggregate" is marked as @public, but its signature references "AccumulatorTarget" which is marked as @beta
aggregate(...accumulators: AccumulatorTarget[]): Pipeline<AppModelType>;
/* Excluded from this release type: userDataWriter */
/* Excluded from this release type: documentReferenceFactory */
aggregate(options: {
accumulators: AccumulatorTarget[];
groups?: Array<string | Selectable>;
}): Pipeline<AppModelType>;
/* Excluded from this release type: userDataWriter */
/* Excluded from this release type: documentReferenceFactory */
aggregate(options: { accumulators: AccumulatorTarget[]; groups?: Array<string | Selectable>; }): Pipeline<AppModelType>;
// (undocumented)
converter: any;
// Warning: (ae-incompatible-release-tags) The symbol "distinct" is marked as @public, but its signature references "Selectable" which is marked as @beta
distinct(...groups: Array<string | Selectable>): Pipeline<AppModelType>;
/* Excluded from this release type: userDataWriter */
/* Excluded from this release type: documentReferenceFactory */
// Warning: (ae-incompatible-release-tags) The symbol "execute" is marked as @public, but its signature references "PipelineResult" which is marked as @beta
execute(): Promise<Array<PipelineResult<AppModelType>>>;
/* Excluded from this release type: userDataWriter */
/* Excluded from this release type: documentReferenceFactory */
// Warning: (ae-incompatible-release-tags) The symbol "findNearest" is marked as @public, but its signature references "FindNearestOptions" which is marked as @beta
//
// (undocumented)
findNearest(options: FindNearestOptions): Pipeline<AppModelType>;
/* Excluded from this release type: userDataWriter */
/* Excluded from this release type: documentReferenceFactory */
genericStage(name: string, params: any[]): Pipeline<AppModelType>;
/* Excluded from this release type: userDataWriter */
/* Excluded from this release type: documentReferenceFactory */
limit(limit: number): Pipeline<AppModelType>;
/* Excluded from this release type: userDataWriter */
/* Excluded from this release type: documentReferenceFactory */
offset(offset: number): Pipeline<AppModelType>;
/* Excluded from this release type: userDataWriter */
/* Excluded from this release type: documentReferenceFactory */
readUserData: any;
// Warning: (ae-incompatible-release-tags) The symbol "select" is marked as @public, but its signature references "Selectable" which is marked as @beta
select(...selections: Array<Selectable | string>): Pipeline<AppModelType>;
/* Excluded from this release type: userDataWriter */
/* Excluded from this release type: documentReferenceFactory */
// (undocumented)
selectablesToMap: any;
// Warning: (ae-incompatible-release-tags) The symbol "sort" is marked as @public, but its signature references "Ordering" which is marked as @beta
sort(...orderings: Ordering[]): Pipeline<AppModelType>;
/* Excluded from this release type: userDataWriter */
/* Excluded from this release type: documentReferenceFactory */
// (undocumented)
sort(options: {
orderings: Ordering[];
}): Pipeline<AppModelType>;
/* Excluded from this release type: userDataWriter */
/* Excluded from this release type: documentReferenceFactory */
// (undocumented)
sort(options: { orderings: Ordering[]; }): Pipeline<AppModelType>;
// (undocumented)
stages: any;
// (undocumented)
userDataReader: any;
// Warning: (ae-incompatible-release-tags) The symbol "where" is marked as @public, but its signature references "FilterCondition" which is marked as @beta
// Warning: (ae-incompatible-release-tags) The symbol "where" is marked as @public, but its signature references "Constant" which is marked as @beta
where(condition: FilterCondition & Constant): Pipeline<AppModelType>;
}

// Warning: (ae-incompatible-release-tags) The symbol "pipeline" is marked as @public, but its signature references "PipelineSource" which is marked as @beta
//
// @public
export function pipeline(firestore: Firestore): PipelineSource;

// @public
export function pipeline(query: Query): Pipeline;

// @beta
export class PipelineResult<AppModelType = DocumentData> {
/* Excluded from this release type: _ref */
Expand Down Expand Up @@ -2499,8 +2490,8 @@ export function xor(left: FilterExpr, ...right: FilterExpr[]): Xor;

// Warnings were encountered during analysis:
//
// /home/runner/work/firebase-js-sdk/firebase-js-sdk/packages/firestore/dist/index.d.ts:10116:9 - (ae-incompatible-release-tags) The symbol "accumulators" is marked as @public, but its signature references "AccumulatorTarget" which is marked as @beta
// /home/runner/work/firebase-js-sdk/firebase-js-sdk/packages/firestore/dist/index.d.ts:10117:9 - (ae-incompatible-release-tags) The symbol "groups" is marked as @public, but its signature references "Selectable" which is marked as @beta
// /home/runner/work/firebase-js-sdk/firebase-js-sdk/packages/firestore/dist/index.d.ts:10146:9 - (ae-incompatible-release-tags) The symbol "orderings" is marked as @public, but its signature references "Ordering" which is marked as @beta
// /Users/markduckworth/projects/firebase-js-sdk/packages/firestore/dist/index.d.ts:10106:26 - (ae-incompatible-release-tags) The symbol "accumulators" is marked as @public, but its signature references "AccumulatorTarget" which is marked as @beta
// /Users/markduckworth/projects/firebase-js-sdk/packages/firestore/dist/index.d.ts:10106:61 - (ae-incompatible-release-tags) The symbol "groups" is marked as @public, but its signature references "Selectable" which is marked as @beta
// /Users/markduckworth/projects/firebase-js-sdk/packages/firestore/dist/index.d.ts:10133:21 - (ae-incompatible-release-tags) The symbol "orderings" is marked as @public, but its signature references "Ordering" which is marked as @beta

```
9 changes: 4 additions & 5 deletions packages/firestore/lite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ export { PipelineSource } from '../src/lite-api/pipeline-source';

export { PipelineResult } from '../src/lite-api/pipeline-result';

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

export { useFirestorePipelines } from '../src/lite-api/database_augmentation';

export { execute } from '../src/lite-api/pipeline_impl';

export {
Stage,
FindNearestOptions,
Expand Down Expand Up @@ -238,10 +240,7 @@ export {
queryEqual
} from '../src/lite-api/reference';

export {
and,
or,
} from '../src/lite-api/overloads';
export { and, or } from '../src/lite-api/overloads';

export {
endAt,
Expand Down
4 changes: 3 additions & 1 deletion packages/firestore/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ export { PipelineSource } from './lite-api/pipeline-source';

export { PipelineResult } from './lite-api/pipeline-result';

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

export { useFirestorePipelines } from './api/database_augmentation';

export { execute } from './lite-api/pipeline_impl';

export {
Stage,
FindNearestOptions,
Expand Down
21 changes: 20 additions & 1 deletion packages/firestore/src/api/pipeline.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { firestoreClientExecutePipeline } from '../core/firestore_client';
import { Pipeline as LitePipeline } from '../lite-api/pipeline';
import { PipelineResult } from '../lite-api/pipeline-result';
import { DocumentData, DocumentReference } from '../lite-api/reference';
import { PipelineSource } from '../lite-api/pipeline-source';
import { DocumentData, DocumentReference, Query } from '../lite-api/reference';
import { Stage } from '../lite-api/stage';
import { UserDataReader } from '../lite-api/user_data_reader';
import { AbstractUserDataWriter } from '../lite-api/user_data_writer';
Expand Down Expand Up @@ -97,3 +98,21 @@ export class Pipeline<
});
}
}

/**
* Experimental Modular API for console testing.
* @param firestore
*/
export function pipeline(firestore: Firestore): PipelineSource;

/**
* Experimental Modular API for console testing.
* @param query
*/
export function pipeline(query: Query): Pipeline;

export function pipeline(
firestoreOrQuery: Firestore | Query
): PipelineSource | Pipeline {
return firestoreOrQuery.pipeline();
}
7 changes: 2 additions & 5 deletions packages/firestore/src/core/pipeline-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ import {
Expr,
Field,
FilterCondition,
not,
not
} from '../lite-api/expressions';
import {
and,
or
} from '../lite-api/overloads';
import { and, or } from '../lite-api/overloads';
import { isNanValue, isNullValue } from '../model/values';
import {
ArrayValue as ProtoArrayValue,
Expand Down
12 changes: 6 additions & 6 deletions packages/firestore/src/lite-api/database_augmentation.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { DocumentKey } from '../model/document_key';

import { Firestore } from './database';
import { And, FilterExpr, Or } from './expressions';
import { or, and } from './overloads';
import { Pipeline } from './pipeline';
import { PipelineSource } from './pipeline-source';
import { DocumentReference, Query } from './reference';
import { LiteUserDataWriter } from './reference_impl';
import { newUserDataReader } from './user_data_reader';
import {or, and} from "./overloads";
import {And, Avg, Expr, Field, FilterExpr, Or, Sum} from "./expressions";

export function useFirestorePipelines(): void {
Firestore.prototype.pipeline = function (): PipelineSource {
Expand Down Expand Up @@ -41,11 +41,11 @@ export function useFirestorePipelines(): void {
return pipeline;
};

and._andFunction = function(left: FilterExpr, ...right: FilterExpr[]): And {
and._andFunction = function (left: FilterExpr, ...right: FilterExpr[]): And {
return new And([left, ...right]);
}
};

or._orFunction = function(left: FilterExpr, ...right: FilterExpr[]): Or {
or._orFunction = function (left: FilterExpr, ...right: FilterExpr[]): Or {
return new Or([left, ...right]);
}
};
}
25 changes: 5 additions & 20 deletions packages/firestore/src/lite-api/overloads.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
import { CompositeOperator } from '../core/filter';

import {
And, Avg, Expr, Field,
FilterExpr,
Or, Sum
} from './expressions';

import { And, FilterExpr, Or } from './expressions';
import {
QueryCompositeFilterConstraint,
QueryConstraint,
QueryFilterConstraint,
validateQueryFilterConstraint
} from './query';
import {FieldPath} from "./field_path";
import {AggregateField} from "./aggregate_types";
import {fieldPathFromArgument} from "./user_data_reader";

/**
* @beta
Expand Down Expand Up @@ -53,8 +45,7 @@ export function or(
): Or | QueryCompositeFilterConstraint {
if (leftFilterExprOrQueryConstraint === undefined) {
return or._orFilters();
}
else if (
} else if (
leftFilterExprOrQueryConstraint instanceof QueryConstraint ||
leftFilterExprOrQueryConstraint instanceof QueryCompositeFilterConstraint ||
leftFilterExprOrQueryConstraint === undefined
Expand All @@ -65,7 +56,7 @@ export function or(
);
} else {
// @ts-ignore
return or._orFunction(leftFilterExprOrQueryConstraint, ...(right));
return or._orFunction(leftFilterExprOrQueryConstraint, ...right);
}
}

Expand All @@ -83,10 +74,7 @@ or._orFilters = function (
);
};

or._orFunction = function (
left: FilterExpr,
...right: FilterExpr[]
): Or {
or._orFunction = function (left: FilterExpr, ...right: FilterExpr[]): Or {
throw new Error(
'Pipelines not initialized. Your application must call `useFirestorePipelines()` before using Firestore Pipeline features.'
);
Expand Down Expand Up @@ -160,10 +148,7 @@ and._andFilters = function (
);
};

and._andFunction = function (
left: FilterExpr,
...right: FilterExpr[]
): And {
and._andFunction = function (left: FilterExpr, ...right: FilterExpr[]): And {
throw new Error(
'Pipelines not initialized. Your application must call `useFirestorePipelines()` before using Firestore Pipeline features.'
);
Expand Down
21 changes: 20 additions & 1 deletion packages/firestore/src/lite-api/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ import {
Selectable
} from './expressions';
import { PipelineResult } from './pipeline-result';
import { DocumentData, DocumentReference } from './reference';
import { PipelineSource } from './pipeline-source';
import { DocumentData, DocumentReference, Query } from './reference';
import {
AddFields,
Aggregate,
Expand Down Expand Up @@ -829,3 +830,21 @@ export class Pipeline<AppModelType = DocumentData>
};
}
}

/**
* Experimental Modular API for console testing.
* @param firestore
*/
export function pipeline(firestore: Firestore): PipelineSource;

/**
* Experimental Modular API for console testing.
* @param query
*/
export function pipeline(query: Query): Pipeline;

export function pipeline(
firestoreOrQuery: Firestore | Query
): PipelineSource | Pipeline {
return firestoreOrQuery.pipeline();
}
13 changes: 13 additions & 0 deletions packages/firestore/src/lite-api/pipeline_impl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Pipeline } from './pipeline';
import { PipelineResult } from './pipeline-result';

/**
* Modular API for console experimentation.
* @param pipeline Execute this pipeline.
* @beta
*/
export function execute<AppModelType>(
pipeline: Pipeline<AppModelType>
): Promise<Array<PipelineResult<AppModelType>>> {
return pipeline.execute();
}
Loading

0 comments on commit bcfaf2a

Please sign in to comment.