Project: /docs/reference/js/_project.yaml
Book: /docs/reference/_book.yaml
page_type: reference
{% comment %}
DO NOT EDIT THIS FILE!
This is generated by the JS SDK team, and any local changes will be
overwritten. Changes should be made in the source code at
https://github.com/firebase/firebase-js-sdk
{% endcomment %}
# WindowFunction class
> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
>
A function that is evaluated over a window frame of documents, as part of an [Pipeline.addWindowFields()](./firestore_lite_pipelines.pipeline.md#pipelineaddwindowfields) stage.
Window Functions SDK features are in preview until the backend feature launches. Look for launch announcement at: https://docs.cloud.google.com/firestore/docs/release-notes
A `WindowFunction` is created either by one of the dedicated window function factories (such as [rank()](./firestore_lite_pipelines.md#rank)), or by calling `over()` on an [AggregateFunction](./firestore_lite_pipelines.aggregatefunction.md#aggregatefunction_class).
Signature:
```typescript
export declare class WindowFunction
```
## Constructors
| Constructor | Modifiers | Description |
| --- | --- | --- |
| [(constructor)(name, params)](./firestore_pipelines.windowfunction.md#windowfunctionconstructor) | | (Public Preview) Constructs a new instance of the WindowFunction class |
## Properties
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [exprType](./firestore_pipelines.windowfunction.md#windowfunctionexprtype) | | [ExpressionType](./firestore_pipelines.md#expressiontype) | (Public Preview) |
## Methods
| Method | Modifiers | Description |
| --- | --- | --- |
| [as(name)](./firestore_pipelines.windowfunction.md#windowfunctionas) | | (Public Preview) Assigns an alias to this WindowFunction. The alias specifies the name that the computed value will have in the output document.Window Functions SDK features are in preview until the backend feature launches. Look for launch announcement at: https://docs.cloud.google.com/firestore/docs/release-notes |
| [over(frame)](./firestore_pipelines.windowfunction.md#windowfunctionover) | | (Public Preview) Evaluates this window function over a specific window frame, rather than over the window frame defined by the enclosing [Pipeline.addWindowFields()](./firestore_lite_pipelines.pipeline.md#pipelineaddwindowfields) stage.Window Functions SDK features are in preview until the backend feature launches. Look for launch announcement at: https://docs.cloud.google.com/firestore/docs/release-notesThe backend only accepts a frame (documents or range) here, and rejects partition and sort, which must be specified on the enclosing addWindowFields() stage.- In a documents frame, bounds are document offsets relative to the current document's position ('current' refers strictly to the current document's position; tied documents are not included). For preceding, a positive integer (e.g. 2) includes up to that many documents before the current document, and a negative integer (e.g. -1) indicates a boundary following the current document, enabling frames that start after the current document. For following, a positive integer (e.g. 2) includes up to that many documents after the current document, and a negative integer (e.g. -1) indicates a boundary preceding the current document, enabling frames that end before the current document (e.g. excluding the current document). - In a range frame, bounds are value or time offsets relative to the current document's sort value(s) ('current' is peer-inclusive and includes all documents tied with the current document's sort value(s), equivalent to an offset of 0). For preceding, a positive offset subtracts from the current document's sort value (looking into the past), and a negative offset adds to the current document's sort value (shifting the lower boundary past the current document). For following, a positive offset adds to the current document's sort value (looking into the future), and a negative offset subtracts from the current document's sort value (shifting the upper boundary before the current document). Range frames with numeric or time-unit offsets require a single numeric or timestamp sort ordering on the enclosing stage, whereas range frames bounded only by 'current' and 'unbounded' support multiple sort orderings and non-numeric sort values. |
## WindowFunction.(constructor)
> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
>
Constructs a new instance of the `WindowFunction` class
Signature:
```typescript
constructor(name: string, params?: Expression[]);
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| name | string | |
| params | [Expression](./firestore_pipelines.expression.md#expression_class)\[\] | |
## WindowFunction.exprType
> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
>
Signature:
```typescript
exprType: ExpressionType;
```
## WindowFunction.as()
> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
>
Assigns an alias to this `WindowFunction`. The alias specifies the name that the computed value will have in the output document.
Window Functions SDK features are in preview until the backend feature launches. Look for launch announcement at: https://docs.cloud.google.com/firestore/docs/release-notes
Signature:
```typescript
as(name: string): AliasedWindowFunction;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| name | string | The alias to assign to this WindowFunction. |
Returns:
[AliasedWindowFunction](./firestore_pipelines.aliasedwindowfunction.md#aliasedwindowfunction_class)
A new [AliasedWindowFunction](./firestore_lite_pipelines.aliasedwindowfunction.md#aliasedwindowfunction_class).
## WindowFunction.over()
> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
>
Evaluates this window function over a specific window frame, rather than over the window frame defined by the enclosing [Pipeline.addWindowFields()](./firestore_lite_pipelines.pipeline.md#pipelineaddwindowfields) stage.
Window Functions SDK features are in preview until the backend feature launches. Look for launch announcement at: https://docs.cloud.google.com/firestore/docs/release-notes
The backend only accepts a frame (`documents` or `range`) here, and rejects `partition` and `sort`, which must be specified on the enclosing `addWindowFields()` stage.
- In a `documents` frame, bounds are document offsets relative to the current document's position (`'current'` refers strictly to the current document's position; tied documents are not included). For `preceding`, a positive integer (e.g. `2`) includes up to that many documents before the current document, and a negative integer (e.g. `-1`) indicates a boundary following the current document, enabling frames that start after the current document. For `following`, a positive integer (e.g. `2`) includes up to that many documents after the current document, and a negative integer (e.g. `-1`) indicates a boundary preceding the current document, enabling frames that end before the current document (e.g. excluding the current document). - In a `range` frame, bounds are value or time offsets relative to the current document's sort value(s) (`'current'` is peer-inclusive and includes all documents tied with the current document's sort value(s), equivalent to an offset of `0`). For `preceding`, a positive offset subtracts from the current document's sort value (looking into the past), and a negative offset adds to the current document's sort value (shifting the lower boundary past the current document). For `following`, a positive offset adds to the current document's sort value (looking into the future), and a negative offset subtracts from the current document's sort value (shifting the upper boundary before the current document). Range frames with numeric or time-unit offsets require a single numeric or timestamp `sort` ordering on the enclosing stage, whereas range frames bounded only by `'current'` and `'unbounded'` support multiple `sort` orderings and non-numeric sort values.
Signature:
```typescript
over(
frame: OneOf<{
documents: DocumentWindowFrame;
range: RangeWindowFrame;
}>
): WindowFunction;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| frame | [OneOf](./firestore_pipelines.md#oneof)<{ documents: [DocumentWindowFrame](./firestore_pipelines.documentwindowframe.md#documentwindowframe_interface); range: [RangeWindowFrame](./firestore_pipelines.rangewindowframe.md#rangewindowframe_interface); }> | The documents or range window frame to evaluate this function over. |
Returns:
[WindowFunction](./firestore_pipelines.windowfunction.md#windowfunction_class)
A new [WindowFunction](./firestore_lite_pipelines.windowfunction.md#windowfunction_class).