Skip to content

Commit 14d9745

Browse files
authored
feat(firestore): add support for remaining map pipeline expressions (#9483)
1 parent 887fc51 commit 14d9745

File tree

12 files changed

+1448
-0
lines changed

12 files changed

+1448
-0
lines changed

.changeset/afraid-pigs-heal.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'firebase': minor
3+
'@firebase/firestore': minor
4+
---
5+
6+
Support added for `mapSet`, `mapValues`, `mapEntries`, `mapKeys` Pipelines expressions.

common/api-review/firestore-lite-pipelines.api.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,14 +534,22 @@ export abstract class Expression {
534534
/* Excluded from this release type: _readUserData */
535535
ltrim(valueToTrim?: string | Expression | Bytes): FunctionExpression;
536536
/* Excluded from this release type: _readUserData */
537+
mapEntries(): FunctionExpression;
538+
/* Excluded from this release type: _readUserData */
537539
mapGet(subfield: string): FunctionExpression;
538540
/* Excluded from this release type: _readUserData */
541+
mapKeys(): FunctionExpression;
542+
/* Excluded from this release type: _readUserData */
539543
mapMerge(secondMap: Record<string, unknown> | Expression, ...otherMaps: Array<Record<string, unknown> | Expression>): FunctionExpression;
540544
/* Excluded from this release type: _readUserData */
541545
mapRemove(key: string): FunctionExpression;
542546
/* Excluded from this release type: _readUserData */
543547
mapRemove(keyExpr: Expression): FunctionExpression;
544548
/* Excluded from this release type: _readUserData */
549+
mapSet(key: string | Expression, value: unknown, ...moreKeyValues: unknown[]): FunctionExpression;
550+
/* Excluded from this release type: _readUserData */
551+
mapValues(): FunctionExpression;
552+
/* Excluded from this release type: _readUserData */
545553
maximum(): AggregateFunction;
546554
/* Excluded from this release type: _readUserData */
547555
minimum(): AggregateFunction;
@@ -891,12 +899,24 @@ export function ltrim(expression: Expression, valueToTrim?: string | Expression
891899
// @beta
892900
export function map(elements: Record<string, unknown>): FunctionExpression;
893901

902+
// @beta
903+
export function mapEntries(mapField: string): FunctionExpression;
904+
905+
// @beta
906+
export function mapEntries(mapExpression: Expression): FunctionExpression;
907+
894908
// @beta
895909
export function mapGet(fieldName: string, subField: string): FunctionExpression;
896910

897911
// @beta
898912
export function mapGet(mapExpression: Expression, subField: string): FunctionExpression;
899913

914+
// @beta
915+
export function mapKeys(mapField: string): FunctionExpression;
916+
917+
// @beta
918+
export function mapKeys(mapExpression: Expression): FunctionExpression;
919+
900920
// @beta
901921
export function mapMerge(mapField: string, secondMap: Record<string, unknown> | Expression, ...otherMaps: Array<Record<string, unknown> | Expression>): FunctionExpression;
902922

@@ -915,6 +935,18 @@ export function mapRemove(mapField: string, keyExpr: Expression): FunctionExpres
915935
// @beta
916936
export function mapRemove(mapExpr: Expression, keyExpr: Expression): FunctionExpression;
917937

938+
// @beta
939+
export function mapSet(mapField: string, key: string | Expression, value: unknown, ...moreKeyValues: unknown[]): FunctionExpression;
940+
941+
// @beta
942+
export function mapSet(mapExpression: Expression, key: string | Expression, value: unknown, ...moreKeyValues: unknown[]): FunctionExpression;
943+
944+
// @beta
945+
export function mapValues(mapField: string): FunctionExpression;
946+
947+
// @beta
948+
export function mapValues(mapExpression: Expression): FunctionExpression;
949+
918950
// @beta
919951
export function maximum(expression: Expression): AggregateFunction;
920952

common/api-review/firestore-pipelines.api.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,14 +537,22 @@ export abstract class Expression {
537537
/* Excluded from this release type: _readUserData */
538538
ltrim(valueToTrim?: string | Expression | Bytes): FunctionExpression;
539539
/* Excluded from this release type: _readUserData */
540+
mapEntries(): FunctionExpression;
541+
/* Excluded from this release type: _readUserData */
540542
mapGet(subfield: string): FunctionExpression;
541543
/* Excluded from this release type: _readUserData */
544+
mapKeys(): FunctionExpression;
545+
/* Excluded from this release type: _readUserData */
542546
mapMerge(secondMap: Record<string, unknown> | Expression, ...otherMaps: Array<Record<string, unknown> | Expression>): FunctionExpression;
543547
/* Excluded from this release type: _readUserData */
544548
mapRemove(key: string): FunctionExpression;
545549
/* Excluded from this release type: _readUserData */
546550
mapRemove(keyExpr: Expression): FunctionExpression;
547551
/* Excluded from this release type: _readUserData */
552+
mapSet(key: string | Expression, value: unknown, ...moreKeyValues: unknown[]): FunctionExpression;
553+
/* Excluded from this release type: _readUserData */
554+
mapValues(): FunctionExpression;
555+
/* Excluded from this release type: _readUserData */
548556
maximum(): AggregateFunction;
549557
/* Excluded from this release type: _readUserData */
550558
minimum(): AggregateFunction;
@@ -894,12 +902,24 @@ export function ltrim(expression: Expression, valueToTrim?: string | Expression
894902
// @beta
895903
export function map(elements: Record<string, unknown>): FunctionExpression;
896904

905+
// @beta
906+
export function mapEntries(mapField: string): FunctionExpression;
907+
908+
// @beta
909+
export function mapEntries(mapExpression: Expression): FunctionExpression;
910+
897911
// @beta
898912
export function mapGet(fieldName: string, subField: string): FunctionExpression;
899913

900914
// @beta
901915
export function mapGet(mapExpression: Expression, subField: string): FunctionExpression;
902916

917+
// @beta
918+
export function mapKeys(mapField: string): FunctionExpression;
919+
920+
// @beta
921+
export function mapKeys(mapExpression: Expression): FunctionExpression;
922+
903923
// @beta
904924
export function mapMerge(mapField: string, secondMap: Record<string, unknown> | Expression, ...otherMaps: Array<Record<string, unknown> | Expression>): FunctionExpression;
905925

@@ -918,6 +938,18 @@ export function mapRemove(mapField: string, keyExpr: Expression): FunctionExpres
918938
// @beta
919939
export function mapRemove(mapExpr: Expression, keyExpr: Expression): FunctionExpression;
920940

941+
// @beta
942+
export function mapSet(mapField: string, key: string | Expression, value: unknown, ...moreKeyValues: unknown[]): FunctionExpression;
943+
944+
// @beta
945+
export function mapSet(mapExpression: Expression, key: string | Expression, value: unknown, ...moreKeyValues: unknown[]): FunctionExpression;
946+
947+
// @beta
948+
export function mapValues(mapField: string): FunctionExpression;
949+
950+
// @beta
951+
export function mapValues(mapExpression: Expression): FunctionExpression;
952+
921953
// @beta
922954
export function maximum(expression: Expression): AggregateFunction;
923955

docs-devsite/firestore_lite_pipelines.expression.md

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,14 @@ field("optional_field").ifAbsent(field('default_field'))
117117
| [logicalMaximum(second, others)](./firestore_lite_pipelines.expression.md#expressionlogicalmaximum) | | <b><i>(Public Preview)</i></b> Creates an expression that returns the larger value between this expression and another expression, based on Firestore's value type ordering. |
118118
| [logicalMinimum(second, others)](./firestore_lite_pipelines.expression.md#expressionlogicalminimum) | | <b><i>(Public Preview)</i></b> Creates an expression that returns the smaller value between this expression and another expression, based on Firestore's value type ordering. |
119119
| [ltrim(valueToTrim)](./firestore_lite_pipelines.expression.md#expressionltrim) | | <b><i>(Public Preview)</i></b> Trims whitespace or a specified set of characters/bytes from the beginning of a string or byte array. |
120+
| [mapEntries()](./firestore_lite_pipelines.expression.md#expressionmapentries) | | <b><i>(Public Preview)</i></b> Creates an expression that returns the entries of a map as an array of maps, where each map contains a <code>&quot;k&quot;</code> property for the key and a <code>&quot;v&quot;</code> property for the value. For example: <code>[{ k: &quot;key1&quot;, v: &quot;value1&quot; }, ...]</code>. |
120121
| [mapGet(subfield)](./firestore_lite_pipelines.expression.md#expressionmapget) | | <b><i>(Public Preview)</i></b> Accesses a value from a map (object) field using the provided key. |
122+
| [mapKeys()](./firestore_lite_pipelines.expression.md#expressionmapkeys) | | <b><i>(Public Preview)</i></b> Creates an expression that returns the keys of a map. |
121123
| [mapMerge(secondMap, otherMaps)](./firestore_lite_pipelines.expression.md#expressionmapmerge) | | <b><i>(Public Preview)</i></b> Creates an expression that merges multiple map values. |
122124
| [mapRemove(key)](./firestore_lite_pipelines.expression.md#expressionmapremove) | | <b><i>(Public Preview)</i></b> Creates an expression that removes a key from the map produced by evaluating this expression. |
123125
| [mapRemove(keyExpr)](./firestore_lite_pipelines.expression.md#expressionmapremove) | | <b><i>(Public Preview)</i></b> Creates an expression that removes a key from the map produced by evaluating this expression. |
126+
| [mapSet(key, value, moreKeyValues)](./firestore_lite_pipelines.expression.md#expressionmapset) | | <b><i>(Public Preview)</i></b> Creates an expression that returns a new map with the specified entries added or updated. |
127+
| [mapValues()](./firestore_lite_pipelines.expression.md#expressionmapvalues) | | <b><i>(Public Preview)</i></b> Creates an expression that returns the values of a map. |
124128
| [maximum()](./firestore_lite_pipelines.expression.md#expressionmaximum) | | <b><i>(Public Preview)</i></b> Creates an aggregation that finds the maximum value of a field across multiple stage inputs. |
125129
| [minimum()](./firestore_lite_pipelines.expression.md#expressionminimum) | | <b><i>(Public Preview)</i></b> Creates an aggregation that finds the minimum value of a field across multiple stage inputs. |
126130
| [mod(expression)](./firestore_lite_pipelines.expression.md#expressionmod) | | <b><i>(Public Preview)</i></b> Creates an expression that calculates the modulo (remainder) of dividing this expression by another expression. |
@@ -2504,6 +2508,33 @@ field("userInput").ltrim('"');
25042508

25052509
```
25062510
2511+
## Expression.mapEntries()
2512+
2513+
> 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.
2514+
>
2515+
2516+
Creates an expression that returns the entries of a map as an array of maps, where each map contains a `"k"` property for the key and a `"v"` property for the value. For example: `[{ k: "key1", v: "value1" }, ...]`<!-- -->.
2517+
2518+
<b>Signature:</b>
2519+
2520+
```typescript
2521+
mapEntries(): FunctionExpression;
2522+
```
2523+
<b>Returns:</b>
2524+
2525+
[FunctionExpression](./firestore_lite_pipelines.functionexpression.md#functionexpression_class)
2526+
2527+
A new `Expression` representing the entries of the map.
2528+
2529+
### Example
2530+
2531+
2532+
```typescript
2533+
// Get the entries of the 'address' map
2534+
field("address").mapEntries();
2535+
2536+
```
2537+
25072538
## Expression.mapGet()
25082539
25092540
> 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.
@@ -2538,6 +2569,35 @@ field("address").mapGet("city");
25382569

25392570
```
25402571
2572+
## Expression.mapKeys()
2573+
2574+
> 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.
2575+
>
2576+
2577+
Creates an expression that returns the keys of a map.
2578+
2579+
While the backend generally preserves insertion order, relying on the order of the output array is not guaranteed and should be avoided.
2580+
2581+
<b>Signature:</b>
2582+
2583+
```typescript
2584+
mapKeys(): FunctionExpression;
2585+
```
2586+
<b>Returns:</b>
2587+
2588+
[FunctionExpression](./firestore_lite_pipelines.functionexpression.md#functionexpression_class)
2589+
2590+
A new `Expression` representing the keys of the map.
2591+
2592+
### Example
2593+
2594+
2595+
```typescript
2596+
// Get the keys of the 'address' map
2597+
field("address").mapKeys();
2598+
2599+
```
2600+
25412601
## Expression.mapMerge()
25422602
25432603
> 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.
@@ -2643,6 +2703,73 @@ map({foo: 'bar', baz: true}).mapRemove(constant('baz'));
26432703

26442704
```
26452705
2706+
## Expression.mapSet()
2707+
2708+
> 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.
2709+
>
2710+
2711+
Creates an expression that returns a new map with the specified entries added or updated.
2712+
2713+
Note that `mapSet` only performs shallow updates to the map. Setting a value to `null` will retain the key with a `null` value. To remove a key entirely, use `mapRemove`<!-- -->.
2714+
2715+
<b>Signature:</b>
2716+
2717+
```typescript
2718+
mapSet(key: string | Expression, value: unknown, ...moreKeyValues: unknown[]): FunctionExpression;
2719+
```
2720+
2721+
#### Parameters
2722+
2723+
| Parameter | Type | Description |
2724+
| --- | --- | --- |
2725+
| key | string \| [Expression](./firestore_lite_pipelines.expression.md#expression_class) | The key to set. Must be a string or a constant string expression. |
2726+
| value | unknown | The value to set. |
2727+
| moreKeyValues | unknown\[\] | Additional key-value pairs to set. |
2728+
2729+
<b>Returns:</b>
2730+
2731+
[FunctionExpression](./firestore_lite_pipelines.functionexpression.md#functionexpression_class)
2732+
2733+
A new `Expression` representing the map with the entries set.
2734+
2735+
### Example
2736+
2737+
2738+
```typescript
2739+
// Set the 'city' to "San Francisco" in the 'address' map
2740+
field("address").mapSet("city", "San Francisco");
2741+
2742+
```
2743+
2744+
## Expression.mapValues()
2745+
2746+
> 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.
2747+
>
2748+
2749+
Creates an expression that returns the values of a map.
2750+
2751+
While the backend generally preserves insertion order, relying on the order of the output array is not guaranteed and should be avoided.
2752+
2753+
<b>Signature:</b>
2754+
2755+
```typescript
2756+
mapValues(): FunctionExpression;
2757+
```
2758+
<b>Returns:</b>
2759+
2760+
[FunctionExpression](./firestore_lite_pipelines.functionexpression.md#functionexpression_class)
2761+
2762+
A new `Expression` representing the values of the map.
2763+
2764+
### Example
2765+
2766+
2767+
```typescript
2768+
// Get the values of the 'address' map
2769+
field("address").mapValues();
2770+
2771+
```
2772+
26462773
## Expression.maximum()
26472774
26482775
> 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.

0 commit comments

Comments
 (0)