Skip to content

Commit 6603c27

Browse files
authored
feat(firestore): change Type string union to raw string (#7621)
1 parent 9fc552c commit 6603c27

3 files changed

Lines changed: 31 additions & 74 deletions

File tree

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

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -29,39 +29,6 @@ import {
2929
import {HasUserData, Serializer, validateUserInput} from '../serializer';
3030
import {cast} from '../util';
3131

32-
/**
33-
* @beta
34-
*
35-
* An enumeration of the different types generated by the Firestore backend.
36-
*
37-
* <ul>
38-
* <li>Numerics evaluate directly to backend representation (`int64` or `float64`), not JS `number`.</li>
39-
* <li>JavaScript `Date` and firestore `Timestamp` objects strictly evaluate to `'timestamp'`.</li>
40-
* <li>Advanced configurations parsing backend types (such as `decimal128`, `max_key` or `min_key` from BSON) are also incorporated in this union string type. Note that `decimal128` is a backend-only numeric type that the JavaScript SDK cannot create natively, but can be evaluated in pipelines.</li>
41-
* </ul>
42-
*/
43-
export type Type =
44-
| 'null'
45-
| 'array'
46-
| 'boolean'
47-
| 'bytes'
48-
| 'timestamp'
49-
| 'geo_point'
50-
| 'number'
51-
| 'int32'
52-
| 'int64'
53-
| 'float64'
54-
| 'decimal128'
55-
| 'map'
56-
| 'reference'
57-
| 'string'
58-
| 'vector'
59-
| 'max_key'
60-
| 'min_key'
61-
| 'object_id'
62-
| 'regex'
63-
| 'request_timestamp';
64-
6532
/**
6633
* @beta
6734
* Represents an expression that can be evaluated to a value within the execution of a `Pipeline`.
@@ -3083,6 +3050,10 @@ export abstract class Expression
30833050
* Creates an expression that checks if the result of this expression is of the given type.
30843051
*
30853052
* @remarks Null or undefined fields evaluate to skip/error. Use `ifAbsent()` / `isAbsent()` to evaluate missing data.
3053+
* Supported values for `type` are:
3054+
* `'null'`, `'array'`, `'boolean'`, `'bytes'`, `'timestamp'`, `'geo_point'`, `'number'`,
3055+
* `'int32'`, `'int64'`, `'float64'`, `'decimal128'`, `'map'`, `'reference'`, `'string'`,
3056+
* `'vector'`, `'max_key'`, `'min_key'`, `'object_id'`, `'regex'`, `'request_timestamp'`.
30863057
*
30873058
* @example
30883059
* ```typescript
@@ -3093,7 +3064,7 @@ export abstract class Expression
30933064
* @param type The type to check for.
30943065
* @returns A new `BooleanExpression` that evaluates to true if the expression's result is of the given type, false otherwise.
30953066
*/
3096-
isType(type: Type): BooleanExpression {
3067+
isType(type: string): BooleanExpression {
30973068
return new FunctionExpression('is_type', [
30983069
this,
30993070
constant(type),
@@ -10221,6 +10192,10 @@ export function arrayIndexOfAll(
1022110192
* Creates an expression that checks if the value in the specified field is of the given type.
1022210193
*
1022310194
* @remarks Null or undefined fields evaluate to skip/error. Use `ifAbsent()` / `isAbsent()` to evaluate missing data.
10195+
* Supported values for `type` are:
10196+
* `'null'`, `'array'`, `'boolean'`, `'bytes'`, `'timestamp'`, `'geo_point'`, `'number'`,
10197+
* `'int32'`, `'int64'`, `'float64'`, `'decimal128'`, `'map'`, `'reference'`, `'string'`,
10198+
* `'vector'`, `'max_key'`, `'min_key'`, `'object_id'`, `'regex'`, `'request_timestamp'`.
1022410199
*
1022510200
* @example
1022610201
* ```typescript
@@ -10232,13 +10207,17 @@ export function arrayIndexOfAll(
1023210207
* @param type The type to check for.
1023310208
* @returns A new `BooleanExpression` that evaluates to true if the field's value is of the given type, false otherwise.
1023410209
*/
10235-
export function isType(fieldName: string, type: Type): BooleanExpression;
10210+
export function isType(fieldName: string, type: string): BooleanExpression;
1023610211

1023710212
/**
1023810213
* @beta
1023910214
* Creates an expression that checks if the result of an expression is of the given type.
1024010215
*
1024110216
* @remarks Null or undefined fields evaluate to skip/error. Use `ifAbsent()` / `isAbsent()` to evaluate missing data.
10217+
* Supported values for `type` are:
10218+
* `'null'`, `'array'`, `'boolean'`, `'bytes'`, `'timestamp'`, `'geo_point'`, `'number'`,
10219+
* `'int32'`, `'int64'`, `'float64'`, `'decimal128'`, `'map'`, `'reference'`, `'string'`,
10220+
* `'vector'`, `'max_key'`, `'min_key'`, `'object_id'`, `'regex'`, `'request_timestamp'`.
1024210221
*
1024310222
* @example
1024410223
* ```typescript
@@ -10250,10 +10229,10 @@ export function isType(fieldName: string, type: Type): BooleanExpression;
1025010229
* @param type The type to check for.
1025110230
* @returns A new `BooleanExpression` that evaluates to true if the expression's result is of the given type, false otherwise.
1025210231
*/
10253-
export function isType(expression: Expression, type: Type): BooleanExpression;
10232+
export function isType(expression: Expression, type: string): BooleanExpression;
1025410233
export function isType(
1025510234
fieldNameOrExpression: string | Expression,
10256-
type: Type,
10235+
type: string,
1025710236
): BooleanExpression {
1025810237
return fieldOrExpression(fieldNameOrExpression).isType(type);
1025910238
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ export {
146146
arrayConcat,
147147
type,
148148
isType,
149-
Type,
150149
timestampTruncate,
151150
split,
152151
ltrim,

handwritten/firestore/types/firestore.d.ts

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5599,6 +5599,10 @@ declare namespace FirebaseFirestore {
55995599
* Creates an expression that checks if the result of this expression is of the given type.
56005600
*
56015601
* @remarks Null or undefined fields evaluate to skip/error. Use `ifAbsent()` / `isAbsent()` to evaluate missing data.
5602+
* Supported values for `type` are:
5603+
* `'null'`, `'array'`, `'boolean'`, `'bytes'`, `'timestamp'`, `'geo_point'`, `'number'`,
5604+
* `'int32'`, `'int64'`, `'float64'`, `'decimal128'`, `'map'`, `'reference'`, `'string'`,
5605+
* `'vector'`, `'max_key'`, `'min_key'`, `'object_id'`, `'regex'`, `'request_timestamp'`.
56025606
*
56035607
* @example
56045608
* ```typescript
@@ -5609,7 +5613,7 @@ declare namespace FirebaseFirestore {
56095613
* @param type The type to check for.
56105614
* @returns A new `BooleanExpression` that evaluates to true if the expression's result is of the given type, false otherwise.
56115615
*/
5612-
isType(type: Type): BooleanExpression;
5616+
isType(type: string): BooleanExpression;
56135617

56145618
// TODO(new-expression): Add new expression method declarations above this line
56155619
/**
@@ -11342,39 +11346,6 @@ declare namespace FirebaseFirestore {
1134211346
timezone?: string | Expression,
1134311347
): FunctionExpression;
1134411348

11345-
/**
11346-
* @beta
11347-
*
11348-
* An enumeration of the different types generated by the Firestore backend.
11349-
*
11350-
* <ul>
11351-
* <li>Numerics evaluate directly to backend representation (`int64` or `float64`), not JS `number`.</li>
11352-
* <li>JavaScript `Date` and firestore `Timestamp` objects strictly evaluate to `'timestamp'`.</li>
11353-
* <li>Advanced configurations parsing backend types (such as `decimal128`, `max_key` or `min_key` from BSON) are also incorporated in this union string type. Note that `decimal128` is a backend-only numeric type that the JavaScript SDK cannot create natively, but can be evaluated in pipelines.</li>
11354-
* </ul>
11355-
*/
11356-
export type Type =
11357-
| 'null'
11358-
| 'array'
11359-
| 'boolean'
11360-
| 'bytes'
11361-
| 'timestamp'
11362-
| 'geo_point'
11363-
| 'number'
11364-
| 'int32'
11365-
| 'int64'
11366-
| 'float64'
11367-
| 'decimal128'
11368-
| 'map'
11369-
| 'reference'
11370-
| 'string'
11371-
| 'vector'
11372-
| 'max_key'
11373-
| 'min_key'
11374-
| 'object_id'
11375-
| 'regex'
11376-
| 'request_timestamp';
11377-
1137811349
/**
1137911350
* @beta
1138011351
* Creates an expression that returns the data type of the data in the specified field.
@@ -11407,6 +11378,10 @@ declare namespace FirebaseFirestore {
1140711378
* Creates an expression that checks if the value in the specified field is of the given type.
1140811379
*
1140911380
* @remarks Null or undefined fields evaluate to skip/error. Use `ifAbsent()` / `isAbsent()` to evaluate missing data.
11381+
* Supported values for `type` are:
11382+
* `'null'`, `'array'`, `'boolean'`, `'bytes'`, `'timestamp'`, `'geo_point'`, `'number'`,
11383+
* `'int32'`, `'int64'`, `'float64'`, `'decimal128'`, `'map'`, `'reference'`, `'string'`,
11384+
* `'vector'`, `'max_key'`, `'min_key'`, `'object_id'`, `'regex'`, `'request_timestamp'`.
1141011385
*
1141111386
* @example
1141211387
* ```typescript
@@ -11418,12 +11393,16 @@ declare namespace FirebaseFirestore {
1141811393
* @param type The type to check for.
1141911394
* @returns A new `BooleanExpression` that evaluates to true if the field's value is of the given type, false otherwise.
1142011395
*/
11421-
export function isType(fieldName: string, type: Type): BooleanExpression;
11396+
export function isType(fieldName: string, type: string): BooleanExpression;
1142211397
/**
1142311398
* @beta
1142411399
* Creates an expression that checks if the result of an expression is of the given type.
1142511400
*
1142611401
* @remarks Null or undefined fields evaluate to skip/error. Use `ifAbsent()` / `isAbsent()` to evaluate missing data.
11402+
* Supported values for `type` are:
11403+
* `'null'`, `'array'`, `'boolean'`, `'bytes'`, `'timestamp'`, `'geo_point'`, `'number'`,
11404+
* `'int32'`, `'int64'`, `'float64'`, `'decimal128'`, `'map'`, `'reference'`, `'string'`,
11405+
* `'vector'`, `'max_key'`, `'min_key'`, `'object_id'`, `'regex'`, `'request_timestamp'`.
1142711406
*
1142811407
* @example
1142911408
* ```typescript
@@ -11437,7 +11416,7 @@ declare namespace FirebaseFirestore {
1143711416
*/
1143811417
export function isType(
1143911418
expression: Expression,
11440-
type: Type,
11419+
type: string,
1144111420
): BooleanExpression;
1144211421

1144311422
// TODO(new-expression): Add new top-level expression function declarations above this line

0 commit comments

Comments
 (0)