Skip to content

Commit 5f6e062

Browse files
committed
feat(firestore): add support for remaining map pipeline expressions
1 parent b10a296 commit 5f6e062

File tree

12 files changed

+885
-0
lines changed

12 files changed

+885
-0
lines changed

.changeset/afraid-pigs-heal.md

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

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,14 +510,22 @@ export abstract class Expression {
510510
/* Excluded from this release type: _readUserData */
511511
logicalMinimum(second: Expression | unknown, ...others: Array<Expression | unknown>): FunctionExpression;
512512
/* Excluded from this release type: _readUserData */
513+
mapEntries(): FunctionExpression;
514+
/* Excluded from this release type: _readUserData */
513515
mapGet(subfield: string): FunctionExpression;
514516
/* Excluded from this release type: _readUserData */
517+
mapKeys(): FunctionExpression;
518+
/* Excluded from this release type: _readUserData */
515519
mapMerge(secondMap: Record<string, unknown> | Expression, ...otherMaps: Array<Record<string, unknown> | Expression>): FunctionExpression;
516520
/* Excluded from this release type: _readUserData */
517521
mapRemove(key: string): FunctionExpression;
518522
/* Excluded from this release type: _readUserData */
519523
mapRemove(keyExpr: Expression): FunctionExpression;
520524
/* Excluded from this release type: _readUserData */
525+
mapSet(key: string | Expression, value: unknown, ...moreKeyValues: unknown[]): FunctionExpression;
526+
/* Excluded from this release type: _readUserData */
527+
mapValues(): FunctionExpression;
528+
/* Excluded from this release type: _readUserData */
521529
maximum(): AggregateFunction;
522530
/* Excluded from this release type: _readUserData */
523531
minimum(): AggregateFunction;
@@ -827,12 +835,18 @@ export function logicalMinimum(fieldName: string, second: Expression | unknown,
827835
// @beta
828836
export function map(elements: Record<string, unknown>): FunctionExpression;
829837

838+
// @beta
839+
export function mapEntries(map: unknown): FunctionExpression;
840+
830841
// @beta
831842
export function mapGet(fieldName: string, subField: string): FunctionExpression;
832843

833844
// @beta
834845
export function mapGet(mapExpression: Expression, subField: string): FunctionExpression;
835846

847+
// @beta
848+
export function mapKeys(map: unknown): FunctionExpression;
849+
836850
// @beta
837851
export function mapMerge(mapField: string, secondMap: Record<string, unknown> | Expression, ...otherMaps: Array<Record<string, unknown> | Expression>): FunctionExpression;
838852

@@ -851,6 +865,12 @@ export function mapRemove(mapField: string, keyExpr: Expression): FunctionExpres
851865
// @beta
852866
export function mapRemove(mapExpr: Expression, keyExpr: Expression): FunctionExpression;
853867

868+
// @beta
869+
export function mapSet(map: unknown, key: string | Expression, value: unknown, ...moreKeyValues: unknown[]): FunctionExpression;
870+
871+
// @beta
872+
export function mapValues(map: unknown): FunctionExpression;
873+
854874
// @beta
855875
export function maximum(expression: Expression): AggregateFunction;
856876

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,14 +513,22 @@ export abstract class Expression {
513513
/* Excluded from this release type: _readUserData */
514514
logicalMinimum(second: Expression | unknown, ...others: Array<Expression | unknown>): FunctionExpression;
515515
/* Excluded from this release type: _readUserData */
516+
mapEntries(): FunctionExpression;
517+
/* Excluded from this release type: _readUserData */
516518
mapGet(subfield: string): FunctionExpression;
517519
/* Excluded from this release type: _readUserData */
520+
mapKeys(): FunctionExpression;
521+
/* Excluded from this release type: _readUserData */
518522
mapMerge(secondMap: Record<string, unknown> | Expression, ...otherMaps: Array<Record<string, unknown> | Expression>): FunctionExpression;
519523
/* Excluded from this release type: _readUserData */
520524
mapRemove(key: string): FunctionExpression;
521525
/* Excluded from this release type: _readUserData */
522526
mapRemove(keyExpr: Expression): FunctionExpression;
523527
/* Excluded from this release type: _readUserData */
528+
mapSet(key: string | Expression, value: unknown, ...moreKeyValues: unknown[]): FunctionExpression;
529+
/* Excluded from this release type: _readUserData */
530+
mapValues(): FunctionExpression;
531+
/* Excluded from this release type: _readUserData */
524532
maximum(): AggregateFunction;
525533
/* Excluded from this release type: _readUserData */
526534
minimum(): AggregateFunction;
@@ -830,12 +838,18 @@ export function logicalMinimum(fieldName: string, second: Expression | unknown,
830838
// @beta
831839
export function map(elements: Record<string, unknown>): FunctionExpression;
832840

841+
// @beta
842+
export function mapEntries(map: unknown): FunctionExpression;
843+
833844
// @beta
834845
export function mapGet(fieldName: string, subField: string): FunctionExpression;
835846

836847
// @beta
837848
export function mapGet(mapExpression: Expression, subField: string): FunctionExpression;
838849

850+
// @beta
851+
export function mapKeys(map: unknown): FunctionExpression;
852+
839853
// @beta
840854
export function mapMerge(mapField: string, secondMap: Record<string, unknown> | Expression, ...otherMaps: Array<Record<string, unknown> | Expression>): FunctionExpression;
841855

@@ -854,6 +868,12 @@ export function mapRemove(mapField: string, keyExpr: Expression): FunctionExpres
854868
// @beta
855869
export function mapRemove(mapExpr: Expression, keyExpr: Expression): FunctionExpression;
856870

871+
// @beta
872+
export function mapSet(map: unknown, key: string | Expression, value: unknown, ...moreKeyValues: unknown[]): FunctionExpression;
873+
874+
// @beta
875+
export function mapValues(map: unknown): FunctionExpression;
876+
857877
// @beta
858878
export function maximum(expression: Expression): AggregateFunction;
859879

docs-devsite/firestore_lite_pipelines.expression.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,14 @@ field("optional_field").ifAbsent(field('default_field'))
111111
| [log10()](./firestore_lite_pipelines.expression.md#expressionlog10) | | <b><i>(Public Preview)</i></b> Creates an expression that computes the base-10 logarithm of a numeric value. |
112112
| [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. |
113113
| [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. |
114+
| [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 objects with 'k' and 'v' fields. |
114115
| [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. |
116+
| [mapKeys()](./firestore_lite_pipelines.expression.md#expressionmapkeys) | | <b><i>(Public Preview)</i></b> Creates an expression that returns the keys of a map. |
115117
| [mapMerge(secondMap, otherMaps)](./firestore_lite_pipelines.expression.md#expressionmapmerge) | | <b><i>(Public Preview)</i></b> Creates an expression that merges multiple map values. |
116118
| [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. |
117119
| [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. |
120+
| [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. |
121+
| [mapValues()](./firestore_lite_pipelines.expression.md#expressionmapvalues) | | <b><i>(Public Preview)</i></b> Creates an expression that returns the values of a map. |
118122
| [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. |
119123
| [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. |
120124
| [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. |
@@ -2305,6 +2309,33 @@ field("timestamp").logicalMinimum(Function.currentTimestamp());
23052309

23062310
```
23072311

2312+
## Expression.mapEntries()
2313+
2314+
> 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.
2315+
>
2316+
2317+
Creates an expression that returns the entries of a map as an array of objects with 'k' and 'v' fields.
2318+
2319+
<b>Signature:</b>
2320+
2321+
```typescript
2322+
mapEntries(): FunctionExpression;
2323+
```
2324+
<b>Returns:</b>
2325+
2326+
[FunctionExpression](./firestore_lite_pipelines.functionexpression.md#functionexpression_class)
2327+
2328+
A new `Expression` representing the entries of the map.
2329+
2330+
### Example
2331+
2332+
2333+
```typescript
2334+
// Get the entries of the 'address' map
2335+
field("address").mapEntries();
2336+
2337+
```
2338+
23082339
## Expression.mapGet()
23092340

23102341
> 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.
@@ -2339,6 +2370,33 @@ field("address").mapGet("city");
23392370

23402371
```
23412372

2373+
## Expression.mapKeys()
2374+
2375+
> 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.
2376+
>
2377+
2378+
Creates an expression that returns the keys of a map.
2379+
2380+
<b>Signature:</b>
2381+
2382+
```typescript
2383+
mapKeys(): FunctionExpression;
2384+
```
2385+
<b>Returns:</b>
2386+
2387+
[FunctionExpression](./firestore_lite_pipelines.functionexpression.md#functionexpression_class)
2388+
2389+
A new `Expression` representing the keys of the map.
2390+
2391+
### Example
2392+
2393+
2394+
```typescript
2395+
// Get the keys of the 'address' map
2396+
field("address").mapKeys();
2397+
2398+
```
2399+
23422400
## Expression.mapMerge()
23432401

23442402
> 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.
@@ -2444,6 +2502,69 @@ map({foo: 'bar', baz: true}).mapRemove(constant('baz'));
24442502
24452503
```
24462504

2505+
## Expression.mapSet()
2506+
2507+
> 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.
2508+
>
2509+
2510+
Creates an expression that returns a new map with the specified entries added or updated.
2511+
2512+
<b>Signature:</b>
2513+
2514+
```typescript
2515+
mapSet(key: string | Expression, value: unknown, ...moreKeyValues: unknown[]): FunctionExpression;
2516+
```
2517+
2518+
#### Parameters
2519+
2520+
| Parameter | Type | Description |
2521+
| --- | --- | --- |
2522+
| key | string \| [Expression](./firestore_lite_pipelines.expression.md#expression_class) | The key to set. |
2523+
| value | unknown | The value to set. |
2524+
| moreKeyValues | unknown\[\] | Additional key-value pairs to set. |
2525+
2526+
<b>Returns:</b>
2527+
2528+
[FunctionExpression](./firestore_lite_pipelines.functionexpression.md#functionexpression_class)
2529+
2530+
A new `Expression` representing the map with the entries set.
2531+
2532+
### Example
2533+
2534+
2535+
```typescript
2536+
// Set the 'city' to "San Francisco" in the 'address' map
2537+
field("address").mapSet("city", "San Francisco");
2538+
2539+
```
2540+
2541+
## Expression.mapValues()
2542+
2543+
> 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.
2544+
>
2545+
2546+
Creates an expression that returns the values of a map.
2547+
2548+
<b>Signature:</b>
2549+
2550+
```typescript
2551+
mapValues(): FunctionExpression;
2552+
```
2553+
<b>Returns:</b>
2554+
2555+
[FunctionExpression](./firestore_lite_pipelines.functionexpression.md#functionexpression_class)
2556+
2557+
A new `Expression` representing the values of the map.
2558+
2559+
### Example
2560+
2561+
2562+
```typescript
2563+
// Get the values of the 'address' map
2564+
field("address").mapValues();
2565+
2566+
```
2567+
24472568
## Expression.maximum()
24482569

24492570
> 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)