@@ -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