Skip to content

Commit 32089a9

Browse files
committed
Merge branch 'main' of github.com:googleapis/google-cloud-node into markduckworth/search
2 parents a95b65d + fb317f8 commit 32089a9

8 files changed

Lines changed: 1722 additions & 11 deletions

File tree

handwritten/firestore/api-report/firestore.api.md

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,9 @@ function countDistinct(expr: Expression | string): AggregateFunction;
682682
// @public
683683
function countIf(booleanExpr: BooleanExpression): AggregateFunction;
684684

685+
// @public
686+
function currentDocument(): Expression;
687+
685688
// @public
686689
function currentTimestamp(): FunctionExpression;
687690

@@ -754,6 +757,9 @@ function documentId(documentPath: string | firestore.DocumentReference): Functio
754757
// @public
755758
function documentId(documentPathExpr: Expression): FunctionExpression;
756759

760+
// @beta
761+
function documentMatches(rquery: string | Expression): BooleanExpression;
762+
757763
// Warning: (tsdoc-undefined-tag) The TSDoc tag "@class" is not defined in this configuration
758764
// Warning: (ae-forgotten-export) The symbol "Serializable" needs to be exported by the entry point index.d.ts
759765
//
@@ -1145,6 +1151,7 @@ abstract class Expression implements firestore.Pipelines.Expression, HasUserData
11451151
abstract expressionType: firestore.Pipelines.ExpressionType;
11461152
first(): AggregateFunction;
11471153
floor(): FunctionExpression;
1154+
getField(key: string | Expression): Expression;
11481155
greaterThan(expression: Expression): BooleanExpression;
11491156
greaterThan(value: unknown): BooleanExpression;
11501157
greaterThanOrEqual(expression: Expression): BooleanExpression;
@@ -1281,6 +1288,8 @@ class Field extends Expression implements firestore.Pipelines.Selectable {
12811288
readonly expressionType: firestore.Pipelines.ExpressionType;
12821289
// (undocumented)
12831290
get fieldName(): string;
1291+
// @beta
1292+
geoDistance(location: GeoPoint | Expression): Expression;
12841293
// (undocumented)
12851294
selectable: true;
12861295
// Warning: (tsdoc-undefined-tag) The TSDoc tag "@private" is not defined in this configuration
@@ -1588,6 +1597,9 @@ class FunctionExpression extends Expression {
15881597
_validateUserData(ignoreUndefinedProperties: boolean): void;
15891598
}
15901599

1600+
// @beta
1601+
function geoDistance(fieldName: string | Field, location: GeoPoint | Expression): Expression;
1602+
15911603
// Warning: (tsdoc-undefined-tag) The TSDoc tag "@class" is not defined in this configuration
15921604
//
15931605
// @public
@@ -1619,6 +1631,18 @@ export class GeoPoint implements Serializable, firestore.GeoPoint {
16191631
toProto(): api.IValue;
16201632
}
16211633

1634+
// @public
1635+
function getField(expression: Expression, key: string): Expression;
1636+
1637+
// @public
1638+
function getField(expression: Expression, keyExpr: Expression): Expression;
1639+
1640+
// @public
1641+
function getField(fieldName: string, key: string): Expression;
1642+
1643+
// @public
1644+
function getField(fieldName: string, keyExpr: Expression): Expression;
1645+
16221646
// @public
16231647
function greaterThan(left: Expression, right: Expression): BooleanExpression;
16241648

@@ -1938,6 +1962,8 @@ class Pipeline implements firestore.Pipelines.Pipeline {
19381962
addFields(options: firestore.Pipelines.AddFieldsStageOptions): Pipeline;
19391963
aggregate(accumulator: firestore.Pipelines.AliasedAggregate, ...additionalAccumulators: firestore.Pipelines.AliasedAggregate[]): Pipeline;
19401964
aggregate(options: firestore.Pipelines.AggregateStageOptions): Pipeline;
1965+
define(aliasedExpression: firestore.Pipelines.AliasedExpression, ...additionalExpressions: firestore.Pipelines.AliasedExpression[]): Pipeline;
1966+
define(options: firestore.Pipelines.DefineStageOptions): Pipeline;
19411967
// Warning: (tsdoc-undefined-tag) The TSDoc tag "@return" is not defined in this configuration
19421968
// Warning: (tsdoc-undefined-tag) The TSDoc tag "@code" is not defined in this configuration
19431969
//
@@ -1969,15 +1995,21 @@ class Pipeline implements firestore.Pipelines.Pipeline {
19691995
// Warning: (tsdoc-escape-right-brace) The "}" character should be escaped using a backslash to avoid confusion with a TSDoc inline tag
19701996
// Warning: (tsdoc-malformed-inline-tag) Expecting a TSDoc tag starting with "{@"
19711997
sample(options: firestore.Pipelines.SampleStageOptions): Pipeline;
1998+
// Warning: (tsdoc-undefined-tag) The TSDoc tag "@return" is not defined in this configuration
1999+
//
2000+
// @beta
2001+
search(options: firestore.Pipelines.SearchStageOptions): Pipeline;
19722002
select(selection: firestore.Pipelines.Selectable | string, ...additionalSelections: Array<firestore.Pipelines.Selectable | string>): Pipeline;
19732003
select(options: firestore.Pipelines.SelectStageOptions): Pipeline;
19742004
sort(ordering: firestore.Pipelines.Ordering, ...additionalOrderings: firestore.Pipelines.Ordering[]): Pipeline;
19752005
sort(options: firestore.Pipelines.SortStageOptions): Pipeline;
19762006
// Warning: (tsdoc-escape-right-brace) The "}" character should be escaped using a backslash to avoid confusion with a TSDoc inline tag
19772007
// Warning: (tsdoc-malformed-inline-tag) Expecting a TSDoc tag starting with "{@"
19782008
stream(): NodeJS.ReadableStream;
2009+
toArrayExpression(): firestore.Pipelines.Expression;
19792010
// (undocumented)
1980-
_toProto(): api.IPipeline;
2011+
_toProto(serializer?: Serializer): api.IPipeline;
2012+
toScalarExpression(): firestore.Pipelines.Expression;
19812013
// Warning: (ae-forgotten-export) The symbol "StructuredPipeline" needs to be exported by the entry point index.d.ts
19822014
//
19832015
// (undocumented)
@@ -2055,6 +2087,7 @@ declare namespace Pipelines {
20552087
PipelineResult,
20562088
PipelineSnapshot,
20572089
PipelineSource,
2090+
subcollection,
20582091
and,
20592092
arrayContains,
20602093
arrayContainsAny,
@@ -2194,8 +2227,14 @@ declare namespace Pipelines {
21942227
stringReplaceOne,
21952228
nor,
21962229
switchOn,
2230+
getField,
2231+
variable,
2232+
currentDocument,
21972233
ifNull,
2198-
coalesce
2234+
coalesce,
2235+
documentMatches,
2236+
score,
2237+
geoDistance
21992238
}
22002239
}
22012240
export { Pipelines }
@@ -2607,6 +2646,9 @@ function rtrim(fieldName: string, valueToTrim?: string | Expression | Uint8Array
26072646
// @public
26082647
function rtrim(expression: Expression, valueToTrim?: string | Expression | Uint8Array | Buffer): FunctionExpression;
26092648

2649+
// @beta
2650+
function score(): Expression;
2651+
26102652
// @public
26112653
export function setLogFunction(logger: ((msg: string) => void) | null): void;
26122654

@@ -2688,6 +2730,12 @@ function stringReverse(stringExpression: Expression): FunctionExpression;
26882730
// @public
26892731
function stringReverse(field: string): FunctionExpression;
26902732

2733+
// @public
2734+
function subcollection(path: string): Pipeline;
2735+
2736+
// @public
2737+
function subcollection(options: firestore.Pipelines.SubcollectionStageOptions): Pipeline;
2738+
26912739
// @public
26922740
function substring(field: string, position: number, length?: number): FunctionExpression;
26932741

@@ -2983,6 +3031,9 @@ function unixSecondsToTimestamp(expr: Expression): FunctionExpression;
29833031
// @public
29843032
function unixSecondsToTimestamp(fieldName: string): FunctionExpression;
29853033

3034+
// @public
3035+
function variable(name: string): Expression;
3036+
29863037
// @public
29873038
function vectorLength(vectorExpression: Expression): FunctionExpression;
29883039

handwritten/firestore/dev/src/pipelines/expression.ts

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
} from './pipeline-util';
3030
import {HasUserData, Serializer, validateUserInput} from '../serializer';
3131
import {cast} from '../util';
32+
import {Pipeline} from './pipelines';
3233
import {GeoPoint} from '../geo-point';
3334
import {OptionsUtil} from './options-util';
3435

@@ -3075,6 +3076,22 @@ export abstract class Expression
30753076
]).asBoolean();
30763077
}
30773078

3079+
/**
3080+
* Creates an expression that returns the value of a field from the document that results from the evaluation of this expression.
3081+
*
3082+
* @example
3083+
* ```typescript
3084+
* // Get the value of the "city" field in the "address" document.
3085+
* field("address").getField("city")
3086+
* ```
3087+
*
3088+
* @param key The field to access in the document.
3089+
* @returns A new `Expression` representing the value of the field in the document.
3090+
*/
3091+
getField(key: string | Expression): Expression {
3092+
return new FunctionExpression('get_field', [this, valueToDefaultExpr(key)]);
3093+
}
3094+
30783095
// /**
30793096
// * Evaluates if the result of this `expression` is between
30803097
// * the `lowerBound` (inclusive) and `upperBound` (inclusive).
@@ -10412,6 +10429,184 @@ export function isType(
1041210429
return fieldOrExpression(fieldNameOrExpression).isType(type);
1041310430
}
1041410431

10432+
/**
10433+
* Creates an expression that gets a field from this map (object).
10434+
*
10435+
* @example
10436+
* ```typescript
10437+
* // Get the value of the "city" field in the "address" document.
10438+
* getField(field("address"), "city")
10439+
* ```
10440+
*
10441+
* @param expression The expression evaluating to the map from which the field will be extracted.
10442+
* @param key The field to access in the document.
10443+
* @returns A new `Expression` representing the value of the field in the document.
10444+
*/
10445+
export function getField(expression: Expression, key: string): Expression;
10446+
/**
10447+
* Creates an expression that gets a field from this map (object).
10448+
*
10449+
* @example
10450+
* ```typescript
10451+
* // Get the value of the "city" field in the "address" document.
10452+
* getField(field("address"), "city")
10453+
* ```
10454+
*
10455+
* @param expression The expression evaluating to the map from which the field will be extracted.
10456+
* @param keyExpr The expression representing the key to access in the document.
10457+
* @returns A new `Expression` representing the value of the field in the document.
10458+
*/
10459+
export function getField(
10460+
expression: Expression,
10461+
keyExpr: Expression,
10462+
): Expression;
10463+
/**
10464+
* Creates an expression that returns the value of a field from the document with the given field name.
10465+
*
10466+
* @example
10467+
* ```typescript
10468+
* // Get the value of the "city" field in the "address" document.
10469+
* getField("address", "city")
10470+
* ```
10471+
*
10472+
* @param fieldName The name of the field containing the map/document.
10473+
* @param key The key to access.
10474+
* @returns A new `Expression` representing the value of the field in the document.
10475+
*/
10476+
export function getField(fieldName: string, key: string): Expression;
10477+
/**
10478+
* Creates an expression that returns the value of a field from the document with the given field name.
10479+
*
10480+
* @example
10481+
* ```typescript
10482+
* // Get the value of the "city" field in the "address" document.
10483+
* getField("address", variable("addressField"))
10484+
* ```
10485+
*
10486+
* @param fieldName The name of the field containing the map/document.
10487+
* @param keyExpr The key expression to access.
10488+
* @returns A new `Expression` representing the value of the field in the document.
10489+
*/
10490+
export function getField(fieldName: string, keyExpr: Expression): Expression;
10491+
export function getField(
10492+
fieldOrExpr: string | Expression,
10493+
keyOrExpr: string | Expression,
10494+
): Expression {
10495+
return fieldOrExpression(fieldOrExpr).getField(keyOrExpr);
10496+
}
10497+
10498+
/**
10499+
* @internal
10500+
* Expression representing a variable reference. This evaluates to the value of a variable
10501+
* defined in a pipeline.
10502+
*/
10503+
export class VariableExpression extends Expression {
10504+
expressionType: firestore.Pipelines.ExpressionType = 'Variable';
10505+
10506+
/**
10507+
* @hideconstructor
10508+
*/
10509+
constructor(private readonly name: string) {
10510+
super();
10511+
}
10512+
10513+
/**
10514+
* @internal
10515+
*/
10516+
_toProto(_serializer: Serializer): api.IValue {
10517+
return {
10518+
variableReferenceValue: this.name,
10519+
};
10520+
}
10521+
10522+
/**
10523+
* @internal
10524+
*/
10525+
_validateUserData(_ignoreUndefinedProperties: boolean): void {}
10526+
}
10527+
10528+
/**
10529+
* Creates an expression that retrieves the value of a variable bound via `define()`.
10530+
*
10531+
* @example
10532+
* ```typescript
10533+
* db.pipeline().collection("products")
10534+
* .define(
10535+
* field("price").multiply(0.9).as("discountedPrice"),
10536+
* field("stock").add(10).as("newStock")
10537+
* )
10538+
* .where(variable("discountedPrice").lessThan(100))
10539+
* .select(field("name"), variable("newStock"));
10540+
* ```
10541+
*
10542+
* @param name - The name of the variable to retrieve.
10543+
* @returns An `Expression` representing the variable's value.
10544+
*/
10545+
export function variable(name: string): Expression {
10546+
return new VariableExpression(name);
10547+
}
10548+
10549+
/**
10550+
* Creates an expression that represents the current document being processed.
10551+
*
10552+
* @example
10553+
* ```typescript
10554+
* // Define the current document as a variable "doc"
10555+
* firestore.pipeline().collection("books")
10556+
* .define(currentDocument().as("doc"))
10557+
* // Access a field from the defined document variable
10558+
* .select(variable("doc").getField("title"));
10559+
* ```
10560+
*
10561+
* @returns An `Expression` representing the current document.
10562+
*/
10563+
export function currentDocument(): Expression {
10564+
return new FunctionExpression('current_document', []);
10565+
}
10566+
10567+
/**
10568+
* @internal
10569+
*/
10570+
class PipelineValueExpression extends Expression {
10571+
expressionType: firestore.Pipelines.ExpressionType = 'PipelineValue';
10572+
10573+
/**
10574+
* @hideconstructor
10575+
*/
10576+
constructor(private readonly pipeline: firestore.Pipelines.Pipeline) {
10577+
super();
10578+
}
10579+
10580+
/**
10581+
* @internal
10582+
*/
10583+
_toProto(serializer: Serializer): api.IValue {
10584+
return {
10585+
// Casting to bypass type checking becuase _validateUserData does not exist in the public types
10586+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
10587+
pipelineValue: (this.pipeline as Pipeline)._toProto(serializer),
10588+
};
10589+
}
10590+
10591+
/**
10592+
* @internal
10593+
*/
10594+
_validateUserData(_ignoreUndefinedProperties: boolean): void {
10595+
// Casting to bypass type checking becuase _validateUserData does not exist in the public types
10596+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
10597+
(this.pipeline as any)._validateUserData('PipelineValueExpression');
10598+
}
10599+
}
10600+
10601+
/**
10602+
* @internal
10603+
*/
10604+
export function pipelineValue(
10605+
pipeline: firestore.Pipelines.Pipeline,
10606+
): Expression {
10607+
return new PipelineValueExpression(pipeline);
10608+
}
10609+
1041510610
// /**
1041610611
// * @beta
1041710612
// * Perform a full-text search on the specified field.

handwritten/firestore/dev/src/pipelines/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export {
1717
PipelineResult,
1818
PipelineSnapshot,
1919
PipelineSource,
20+
subcollection,
2021
} from './pipelines';
2122

2223
export {
@@ -159,6 +160,9 @@ export {
159160
stringReplaceOne,
160161
nor,
161162
switchOn,
163+
getField,
164+
variable,
165+
currentDocument,
162166
ifNull,
163167
coalesce,
164168
documentMatches,

0 commit comments

Comments
 (0)