Skip to content

Commit 4b3c7ab

Browse files
Merge branch 'main' into release-please--branches--main--components--firestore
2 parents 7036a50 + 55d6385 commit 4b3c7ab

9 files changed

Lines changed: 792 additions & 39 deletions

File tree

ci/run_conditional_tests.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ for subdir in ${subdirs[@]}; do
123123
continue
124124
fi
125125

126+
# Sample tests for packages are broken/flaky and blocking PRs.
127+
# See https://github.com/googleapis/google-cloud-node/issues/7976#issuecomment-4210458096.
128+
#
129+
# Per https://github.com/googleapis/google-cloud-node/issues/7921,
130+
# we are likely to permanently remove these tests in the near future.
131+
if [[ "${subdir}" == "packages" && "${TEST_TYPE}" == "samples" ]]; then
132+
echo "Skipping ${TEST_TYPE} test for packages: ${d}"
133+
continue
134+
fi
135+
126136
# Our CI uses Git Bash on Windows to execute this script, which returns "msys" for OSTYPE.
127137
if [[ "$OSTYPE" == "msys" ]]; then
128138
if [[ "${windows_exempt_tests}" =~ "${d}" ]]; then

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,12 @@ function arrayContainsAny(array: Expression, values: Expression): BooleanExpress
229229
// @public
230230
function arrayContainsAny(fieldName: string, values: Expression): BooleanExpression;
231231

232+
// @public
233+
function arrayFilter(fieldName: string, alias: string, filter: BooleanExpression): FunctionExpression;
234+
235+
// @public
236+
function arrayFilter(arrayExpression: Expression, alias: string, filter: BooleanExpression): FunctionExpression;
237+
232238
// @public
233239
function arrayFirst(fieldName: string): FunctionExpression;
234240

@@ -343,12 +349,30 @@ function arrayReverse(fieldName: string): FunctionExpression;
343349
// @public
344350
function arrayReverse(arrayExpression: Expression): FunctionExpression;
345351

352+
// @public
353+
function arraySlice(arrayName: string, offset: number | Expression, length?: number | Expression): FunctionExpression;
354+
355+
// @public
356+
function arraySlice(arrayExpression: Expression, offset: number | Expression, length?: number | Expression): FunctionExpression;
357+
346358
// @public
347359
function arraySum(fieldName: string): FunctionExpression;
348360

349361
// @public
350362
function arraySum(expression: Expression): FunctionExpression;
351363

364+
// @public
365+
function arrayTransform(fieldName: string, elementAlias: string, transform: Expression): FunctionExpression;
366+
367+
// @public
368+
function arrayTransform(arrayExpression: Expression, elementAlias: string, transform: Expression): FunctionExpression;
369+
370+
// @public
371+
function arrayTransformWithIndex(fieldName: string, elementAlias: string, indexAlias: string, transform: Expression): FunctionExpression;
372+
373+
// @public
374+
function arrayTransformWithIndex(arrayExpression: Expression, elementAlias: string, indexAlias: string, transform: Expression): FunctionExpression;
375+
352376
// @public
353377
function ascending(expr: Expression): Ordering;
354378

@@ -1090,6 +1114,7 @@ abstract class Expression implements firestore.Pipelines.Expression, HasUserData
10901114
arrayContainsAll(arrayExpression: Expression): BooleanExpression;
10911115
arrayContainsAny(values: Array<Expression | unknown>): BooleanExpression;
10921116
arrayContainsAny(arrayExpression: Expression): BooleanExpression;
1117+
arrayFilter(alias: string, filter: BooleanExpression): FunctionExpression;
10931118
arrayFirst(): FunctionExpression;
10941119
arrayFirstN(n: number): FunctionExpression;
10951120
arrayFirstN(n: Expression): FunctionExpression;
@@ -1112,7 +1137,10 @@ abstract class Expression implements firestore.Pipelines.Expression, HasUserData
11121137
arrayMinimumN(n: number): FunctionExpression;
11131138
arrayMinimumN(n: Expression): FunctionExpression;
11141139
arrayReverse(): FunctionExpression;
1140+
arraySlice(offset: number | Expression, length?: number | Expression): FunctionExpression;
11151141
arraySum(): FunctionExpression;
1142+
arrayTransform(elementAlias: string, transform: Expression): FunctionExpression;
1143+
arrayTransformWithIndex(elementAlias: string, indexAlias: string, transform: Expression): FunctionExpression;
11161144
as(name: string): AliasedExpression;
11171145
asBoolean(): BooleanExpression;
11181146
ascending(): Ordering;
@@ -2135,6 +2163,10 @@ declare namespace Pipelines {
21352163
arrayMinimum,
21362164
arrayMaximumN,
21372165
arrayMinimumN,
2166+
arrayFilter,
2167+
arrayTransform,
2168+
arrayTransformWithIndex,
2169+
arraySlice,
21382170
field,
21392171
xor,
21402172
AggregateFunction,

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

Lines changed: 294 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,105 @@ export abstract class Expression
581581
]).asBoolean();
582582
}
583583

584+
/**
585+
* Creates an expression that filters an array using a provided alias and predicate expression.
586+
*
587+
* @example
588+
* ```typescript
589+
* // Filter "scores" to include only values greater than 50
590+
* field("scores").arrayFilter("score", greaterThan(variable("score"), 50));
591+
* ```
592+
*
593+
* @param alias The variable name to use for each element.
594+
* @param filter The predicate boolean expression to evaluate for each element.
595+
* @returns A new `Expression` representing the filtered array.
596+
*/
597+
arrayFilter(alias: string, filter: BooleanExpression): FunctionExpression {
598+
return new FunctionExpression('array_filter', [
599+
this,
600+
valueToDefaultExpr(alias),
601+
filter,
602+
]);
603+
}
604+
605+
/**
606+
* Creates an expression that applies a provided transformation to each element in an array.
607+
*
608+
* @example
609+
* ```typescript
610+
* // Transform the 'scores' array by multiplying each score by 10
611+
* field("scores").arrayTransform("score", multiply(variable("score"), 10));
612+
* ```
613+
*
614+
* @param elementAlias The variable name to use for each element.
615+
* @param transform The lambda expression used to transform the elements.
616+
* @returns A new `Expression` representing the arrayTransform operation.
617+
*/
618+
arrayTransform(
619+
elementAlias: string,
620+
transform: Expression,
621+
): FunctionExpression {
622+
return new FunctionExpression('array_transform', [
623+
this,
624+
valueToDefaultExpr(elementAlias),
625+
transform,
626+
]);
627+
}
628+
629+
/**
630+
* Creates an expression that applies a provided transformation to each element in an array, providing the element's index to the transformation expression.
631+
*
632+
* @example
633+
* ```typescript
634+
* // Transform the 'scores' array by adding the index to each score
635+
* field("scores").arrayTransformWithIndex("score", "i", add(variable("score"), variable("i")));
636+
* ```
637+
*
638+
* @param elementAlias The variable name to use for each element.
639+
* @param indexAlias The variable name to use for the current index.
640+
* @param transform The lambda expression used to transform the elements.
641+
* @returns A new `Expression` representing the arrayTransformWithIndex operation.
642+
*/
643+
arrayTransformWithIndex(
644+
elementAlias: string,
645+
indexAlias: string,
646+
transform: Expression,
647+
): FunctionExpression {
648+
return new FunctionExpression('array_transform', [
649+
this,
650+
valueToDefaultExpr(elementAlias),
651+
valueToDefaultExpr(indexAlias),
652+
transform,
653+
]);
654+
}
655+
656+
/**
657+
* Creates an expression that returns a slice of an array from `offset` with `length` elements.
658+
*
659+
* @example
660+
* ```typescript
661+
* // Get 5 elements from the 'items' array starting from index 2
662+
* field("items").arraySlice(2, 5);
663+
*
664+
* // Get n number of elements from the 'items' array starting from index 2
665+
* field("items").arraySlice(2, field("count"));
666+
* ```
667+
*
668+
* @param offset The starting offset.
669+
* @param length The optional length of the slice.
670+
* @returns A new `Expression` representing the sliced array.
671+
*/
672+
arraySlice(
673+
offset: number | Expression,
674+
length?: number | Expression,
675+
): FunctionExpression {
676+
const args: Expression[] = [this, valueToDefaultExpr(offset)];
677+
if (length !== undefined) {
678+
args.push(valueToDefaultExpr(length));
679+
}
680+
return new FunctionExpression('array_slice', args);
681+
}
682+
584683
/**
585684
* Creates an expression that reverses an array.
586685
*
@@ -6067,6 +6166,201 @@ export function reverse(expr: Expression | string): FunctionExpression {
60676166
return fieldOrExpression(expr).reverse();
60686167
}
60696168

6169+
/**
6170+
* Creates an expression that filters an array using a provided alias and predicate expression.
6171+
*
6172+
* ```typescript
6173+
* // Get a filtered array of the 'scores' field containing only elements greater than 50.
6174+
* arrayFilter("scores", "score", greaterThan(variable("score"), 50));
6175+
* ```
6176+
*
6177+
* @param fieldName The name of the field containing the array.
6178+
* @param alias The variable name to use for each element.
6179+
* @param filter The predicate boolean expression to evaluate for each element.
6180+
* @returns A new `Expression` representing the filtered array.
6181+
*/
6182+
export function arrayFilter(
6183+
fieldName: string,
6184+
alias: string,
6185+
filter: BooleanExpression,
6186+
): FunctionExpression;
6187+
6188+
/**
6189+
* Creates an expression that filters an array using a provided alias and predicate expression.
6190+
*
6191+
* ```typescript
6192+
* // Filter "scores" to include only values greater than 50
6193+
* arrayFilter(field("scores"), "score", greaterThan(variable("score"), 50));
6194+
* ```
6195+
*
6196+
* @param arrayExpression The expression representing the array.
6197+
* @param alias The variable name to use for each element.
6198+
* @param filter The predicate boolean expression to evaluate for each element.
6199+
* @returns A new `Expression` representing the filtered array.
6200+
*/
6201+
export function arrayFilter(
6202+
arrayExpression: Expression,
6203+
alias: string,
6204+
filter: BooleanExpression,
6205+
): FunctionExpression;
6206+
export function arrayFilter(
6207+
array: Expression | string,
6208+
alias: string,
6209+
filter: BooleanExpression,
6210+
): FunctionExpression {
6211+
return fieldOrExpression(array).arrayFilter(alias, filter);
6212+
}
6213+
6214+
/**
6215+
* Creates an expression that applies a provided transformation to each element in an array.
6216+
*
6217+
* ```typescript
6218+
* // Transform "scores" array by multiplying each score by 10
6219+
* arrayTransform("scores", "score", multiply(variable("score"), 10));
6220+
* ```
6221+
*
6222+
* @param fieldName The name of the field containing the array.
6223+
* @param elementAlias The variable name to use for each element.
6224+
* @param transform The lambda expression used to transform the elements.
6225+
* @returns A new `Expression` representing the transformed array.
6226+
*/
6227+
export function arrayTransform(
6228+
fieldName: string,
6229+
elementAlias: string,
6230+
transform: Expression,
6231+
): FunctionExpression;
6232+
6233+
/**
6234+
* Creates an expression that applies a provided transformation to each element in an array.
6235+
*
6236+
* ```typescript
6237+
* // Transform "scores" array by multiplying each score by 10
6238+
* arrayTransform(field("scores"), "score", multiply(variable("score"), 10));
6239+
* ```
6240+
*
6241+
* @param arrayExpression The expression representing the array.
6242+
* @param elementAlias The variable name to use for each element.
6243+
* @param transform The lambda expression used to transform the elements.
6244+
* @returns A new `Expression` representing the transformed array.
6245+
*/
6246+
export function arrayTransform(
6247+
arrayExpression: Expression,
6248+
elementAlias: string,
6249+
transform: Expression,
6250+
): FunctionExpression;
6251+
export function arrayTransform(
6252+
array: Expression | string,
6253+
elementAlias: string,
6254+
transform: Expression,
6255+
): FunctionExpression {
6256+
return fieldOrExpression(array).arrayTransform(elementAlias, transform);
6257+
}
6258+
6259+
/**
6260+
* Creates an expression that applies a provided transformation to each element in an array, providing the element's index to the transformation expression.
6261+
*
6262+
* ```typescript
6263+
* // Transform "scores" array by adding the index to each score
6264+
* arrayTransformWithIndex("scores", "score", "i", add(variable("score"), variable("i")));
6265+
* ```
6266+
*
6267+
* @param fieldName The name of the field containing the array.
6268+
* @param elementAlias The variable name to use for each element.
6269+
* @param indexAlias The variable name to use for the current index.
6270+
* @param transform The lambda expression used to transform the elements.
6271+
* @returns A new `Expression` representing the transformed array.
6272+
*/
6273+
export function arrayTransformWithIndex(
6274+
fieldName: string,
6275+
elementAlias: string,
6276+
indexAlias: string,
6277+
transform: Expression,
6278+
): FunctionExpression;
6279+
6280+
/**
6281+
* Creates an expression that applies a provided transformation to each element in an array, providing the element's index to the transformation expression.
6282+
*
6283+
* ```typescript
6284+
* // Transform "scores" array by adding the index to each score
6285+
* arrayTransformWithIndex(field("scores"), "score", "i", add(variable("score"), variable("i")));
6286+
* ```
6287+
*
6288+
* @param arrayExpression The expression representing the array.
6289+
* @param elementAlias The variable name to use for each element.
6290+
* @param indexAlias The variable name to use for the current index.
6291+
* @param transform The expression used to transform the elements.
6292+
* @returns A new `Expression` representing the transformed array.
6293+
*/
6294+
export function arrayTransformWithIndex(
6295+
arrayExpression: Expression,
6296+
elementAlias: string,
6297+
indexAlias: string,
6298+
transform: Expression,
6299+
): FunctionExpression;
6300+
export function arrayTransformWithIndex(
6301+
array: Expression | string,
6302+
elementAlias: string,
6303+
indexAlias: string,
6304+
transform: Expression,
6305+
): FunctionExpression {
6306+
return fieldOrExpression(array).arrayTransformWithIndex(
6307+
elementAlias,
6308+
indexAlias,
6309+
transform,
6310+
);
6311+
}
6312+
6313+
/**
6314+
* Creates an expression that returns a slice of an array from `offset` with `length` elements.
6315+
*
6316+
* ```typescript
6317+
* // Get 5 elements from the 'items' array field starting from index 2
6318+
* arraySlice("items", 2, 5);
6319+
*
6320+
* // Get n elements from the 'items' array field starting from index 2
6321+
* arraySlice("items", 2, field("length"));
6322+
* ```
6323+
*
6324+
* @param arrayName The name of the field containing the array.
6325+
* @param offset The starting offset.
6326+
* @param length The optional length of the slice.
6327+
* @returns A new `Expression` representing the sliced array.
6328+
*/
6329+
export function arraySlice(
6330+
arrayName: string,
6331+
offset: number | Expression,
6332+
length?: number | Expression,
6333+
): FunctionExpression;
6334+
6335+
/**
6336+
* Creates an expression that returns a slice of an array from `offset` with `length` elements.
6337+
*
6338+
* ```typescript
6339+
* // Get 5 elements from an array expression starting from index 2
6340+
* arraySlice(field("items"), 2, 5);
6341+
*
6342+
* // Get n elements from an array expression starting from index 2
6343+
* arraySlice(field("items"), 2, field("length"));
6344+
* ```
6345+
*
6346+
* @param arrayExpression The expression representing the array.
6347+
* @param offset The starting offset.
6348+
* @param length The optional length of the slice.
6349+
* @returns A new `Expression` representing the sliced array.
6350+
*/
6351+
export function arraySlice(
6352+
arrayExpression: Expression,
6353+
offset: number | Expression,
6354+
length?: number | Expression,
6355+
): FunctionExpression;
6356+
export function arraySlice(
6357+
array: Expression | string,
6358+
offset: number | Expression,
6359+
length?: number | Expression,
6360+
): FunctionExpression {
6361+
return fieldOrExpression(array).arraySlice(offset, length);
6362+
}
6363+
60706364
/**
60716365
* Creates an expression that reverses an array.
60726366
*

0 commit comments

Comments
 (0)