Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Vector Search #2006

Merged
merged 70 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
36a50cb
Implement vector field type
wu-hui Sep 15, 2023
415c94e
Merge branch 'main' into wuandy/VectorType
wu-hui Sep 15, 2023
3551acb
test
wu-hui Sep 19, 2023
248af30
Merge branch 'main' into wuandy/VectorType
wu-hui Nov 27, 2023
6042c4d
Added extra logs and vector type test
wu-hui Nov 29, 2023
764800b
Add vector watch test
wu-hui Dec 5, 2023
93ae1d7
Add vectorvalue to dts.
wu-hui Jan 17, 2024
a3d57e3
get d.ts right.
wu-hui Jan 10, 2024
68cafe1
VectorQuery and QueryUtil setup
wu-hui Jan 10, 2024
f8f1ecb
Stage proto
wu-hui Jan 11, 2024
9f973a6
Actual serialization
wu-hui Jan 12, 2024
57a3f25
Update proto
wu-hui Jan 15, 2024
e15721d
More integration tests
wu-hui Jan 15, 2024
3898181
fix some tests. Also what to do with mismatch dimentions
wu-hui Jan 15, 2024
069a3e4
Add unit tests and minor fixes
wu-hui Jan 16, 2024
4b8b624
Add comments and delete stream()
wu-hui Jan 17, 2024
cff8b5b
Fix rebase.
wu-hui Jan 17, 2024
2f1b964
Address Mark's comments.
wu-hui Jan 23, 2024
9ebd42a
Merge branch 'main' into wuandy/VectorType
wu-hui Jan 23, 2024
1132ff3
get d.ts right.
wu-hui Jan 10, 2024
ddec250
VectorQuery and QueryUtil setup
wu-hui Jan 10, 2024
86ce16e
Stage proto
wu-hui Jan 11, 2024
df0b01a
Actual serialization
wu-hui Jan 12, 2024
1755a4e
Update proto
wu-hui Jan 15, 2024
8da86bc
More integration tests
wu-hui Jan 15, 2024
b8a043c
fix some tests. Also what to do with mismatch dimentions
wu-hui Jan 15, 2024
629ed38
Add unit tests and minor fixes
wu-hui Jan 16, 2024
5ca985f
Add comments and delete stream()
wu-hui Jan 17, 2024
66cab1f
Fix rebase.
wu-hui Jan 17, 2024
30f9977
Address comments
wu-hui Jan 23, 2024
2ae6cfb
Merge remote-tracking branch 'origin/wuandy/FindNearestImpl' into wua…
wu-hui Jan 23, 2024
a6af2da
Address comments
wu-hui Jan 23, 2024
1943803
No retry with cursor for vector for now.
wu-hui Jan 29, 2024
e535fd1
Fix error message test
wu-hui Jan 31, 2024
0af118f
Fix broken array equality
wu-hui Jan 31, 2024
41ab580
Implementing IndexTestHelper and updating findNearest tests to use th…
MarkDuckworth Feb 29, 2024
bcf7f45
Add dot product support.
MarkDuckworth Mar 4, 2024
625e8d7
Merge branch 'main' of github.com:googleapis/nodejs-firestore into ma…
MarkDuckworth Mar 4, 2024
b512348
Adding missing file
MarkDuckworth Mar 4, 2024
0a9ab60
Lint
MarkDuckworth Mar 4, 2024
6b52042
Updating API reference docs.
MarkDuckworth Mar 5, 2024
afc4f99
Fixing API reference docs for TSDoc output on CGC.
MarkDuckworth Mar 5, 2024
3d0267f
Fix API reference docs.
MarkDuckworth Mar 6, 2024
c3a337e
Supporting Vector field order onSnapshot.
MarkDuckworth Mar 11, 2024
f0c6228
Add missing map-type file.
MarkDuckworth Mar 11, 2024
8436c1e
Cleanup and linting.
MarkDuckworth Mar 11, 2024
2fcf70a
Supporting Proto3 JSON with vector.
MarkDuckworth Mar 12, 2024
adb01c1
Additional test for vector in a map.
MarkDuckworth Mar 13, 2024
d916197
Merge branch 'main' of github.com:googleapis/nodejs-firestore into ma…
MarkDuckworth Mar 14, 2024
d3254cd
Update deps.
MarkDuckworth Mar 14, 2024
f0ed9bc
Add DOT_PRODUCT to d.ts
MarkDuckworth Mar 14, 2024
4791b1b
Merge branch 'main' of github.com:googleapis/nodejs-firestore into ma…
MarkDuckworth Mar 15, 2024
f2986f8
Merge branch 'main' of github.com:googleapis/nodejs-firestore into ma…
MarkDuckworth Mar 15, 2024
3a9e2ab
Merge branch 'main' of github.com:googleapis/nodejs-firestore into ma…
MarkDuckworth Mar 15, 2024
0d1b967
Staging protos
MarkDuckworth Mar 15, 2024
9d598a1
Types update for admin protos.
MarkDuckworth Mar 15, 2024
4513c24
License header fixes.
MarkDuckworth Mar 19, 2024
35303af
Fix docs CI for jsdoc build.
MarkDuckworth Mar 19, 2024
a40366a
Updated api-report
MarkDuckworth Mar 21, 2024
6e3796d
More integration test cases.
MarkDuckworth Mar 21, 2024
e5a3d9c
Clarifying supported range on options.limit
MarkDuckworth Mar 21, 2024
3840563
Merge branch 'main' into markduckworth/findnearest
MarkDuckworth Mar 25, 2024
970a3f1
Revert changes from staging protos that were not applied in stable.
MarkDuckworth Mar 25, 2024
b98c3e8
Improving test comments/name for PR feedback.
MarkDuckworth Mar 25, 2024
563ef55
Merge Query Profile to Find Nearest
MarkDuckworth Mar 26, 2024
ee3f1d6
Merge branch 'main' of github.com:googleapis/nodejs-firestore into ma…
MarkDuckworth Mar 27, 2024
ccabafd
Revert rename of internal toProto method name. It is marked internal,…
MarkDuckworth Mar 27, 2024
43a5cd1
Update api-report.md
MarkDuckworth Mar 27, 2024
a0f103e
Re-adding two internal methods to the Query class to minimize the ris…
MarkDuckworth Mar 27, 2024
bb56524
Merge branch 'main' of github.com:googleapis/nodejs-firestore into ma…
MarkDuckworth Mar 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 108 additions & 20 deletions api-report/firestore.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,7 @@ export class FieldValue implements firestore.FieldValue {
// Warning: (tsdoc-malformed-inline-tag) Expecting a TSDoc tag starting with "{@"
// Warning: (tsdoc-undefined-tag) The TSDoc tag "@return" is not defined in this configuration
static serverTimestamp(): FieldValue;
static vector(values?: number[]): VectorValue;
}

// @public
Expand Down Expand Up @@ -1003,6 +1004,10 @@ export class Query<AppModelType = firestore.DocumentData, DbModelType extends fi
count(): AggregateQuery<{
count: firestore.AggregateField<number>;
}, AppModelType, DbModelType>;
// Warning: (tsdoc-undefined-tag) The TSDoc tag "@private" is not defined in this configuration
//
// @internal
_createSnapshot(readTime: Timestamp, size: number, docs: () => Array<QueryDocumentSnapshot<AppModelType, DbModelType>>, changes: () => Array<DocumentChange<AppModelType, DbModelType>>): QuerySnapshot<AppModelType, DbModelType>;
// Warning: (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
// Warning: (tsdoc-param-tag-with-invalid-type) The @param block should not include a JSDoc-style '{type}'
// Warning: (tsdoc-escape-right-brace) The "}" character should be escaped using a backslash to avoid confusion with a TSDoc inline tag
Expand All @@ -1028,6 +1033,10 @@ export class Query<AppModelType = firestore.DocumentData, DbModelType extends fi
//
// @internal
static _extractFieldValues(documentSnapshot: DocumentSnapshot, fieldOrders: FieldOrder[]): unknown[];
findNearest(vectorField: string | firestore.FieldPath, queryVector: firestore.VectorValue | Array<number>, options: {
limit: number;
distanceMeasure: 'EUCLIDEAN' | 'COSINE' | 'DOT_PRODUCT';
}): VectorQuery<AppModelType, DbModelType>;
// Warning: (tsdoc-escape-right-brace) The "}" character should be escaped using a backslash to avoid confusion with a TSDoc inline tag
// Warning: (tsdoc-malformed-inline-tag) Expecting a TSDoc tag starting with "{@"
// Warning: (tsdoc-undefined-tag) The TSDoc tag "@type" is not defined in this configuration
Expand All @@ -1047,7 +1056,7 @@ export class Query<AppModelType = firestore.DocumentData, DbModelType extends fi
_get(transactionIdOrReadTime?: Uint8Array | Timestamp): Promise<QuerySnapshot<AppModelType, DbModelType>>;
// Warning: (tsdoc-undefined-tag) The TSDoc tag "@private" is not defined in this configuration
//
// @internal (undocumented)
// @internal
_hasRetryTimedOut(methodName: string, startTime: number): boolean;
// Warning: (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
// Warning: (tsdoc-param-tag-with-invalid-type) The @param block should not include a JSDoc-style '{type}'
Expand Down Expand Up @@ -1106,12 +1115,21 @@ export class Query<AppModelType = firestore.DocumentData, DbModelType extends fi
// Warning: (ae-forgotten-export) The symbol "QueryOptions" needs to be exported by the entry point index.d.ts
//
// @internal (undocumented)
protected readonly _queryOptions: QueryOptions<AppModelType, DbModelType>;
readonly _queryOptions: QueryOptions<AppModelType, DbModelType>;
// Warning: (tsdoc-undefined-tag) The TSDoc tag "@private" is not defined in this configuration
// Warning: (ae-forgotten-export) The symbol "QueryUtil" needs to be exported by the entry point index.d.ts
//
// @internal (undocumented)
readonly _queryUtil: QueryUtil<AppModelType, DbModelType, Query<AppModelType, DbModelType>>;
// Warning: (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
// Warning: (tsdoc-param-tag-with-invalid-type) The @param block should not include a JSDoc-style '{type}'
// Warning: (tsdoc-escape-right-brace) The "}" character should be escaped using a backslash to avoid confusion with a TSDoc inline tag
// Warning: (tsdoc-malformed-inline-tag) Expecting a TSDoc tag starting with "{@"
select(...fieldPaths: Array<string | FieldPath>): Query;
// Warning: (tsdoc-undefined-tag) The TSDoc tag "@private" is not defined in this configuration
//
// @internal (undocumented)
readonly _serializer: Serializer;
// Warning: (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
// Warning: (tsdoc-param-tag-with-invalid-type) The @param block should not include a JSDoc-style '{type}'
// Warning: (tsdoc-escape-right-brace) The "}" character should be escaped using a backslash to avoid confusion with a TSDoc inline tag
Expand Down Expand Up @@ -1424,6 +1442,74 @@ export class Transaction implements firestore.Transaction {
update<AppModelType, DbModelType extends firestore.DocumentData>(documentRef: firestore.DocumentReference<AppModelType, DbModelType>, dataOrField: firestore.UpdateData<DbModelType> | string | firestore.FieldPath, ...preconditionOrValues: Array<firestore.Precondition | unknown | string | firestore.FieldPath>): Transaction;
}

// @public
export class VectorQuery<AppModelType = firestore.DocumentData, DbModelType extends firestore.DocumentData = firestore.DocumentData> implements firestore.VectorQuery<AppModelType, DbModelType> {
// Warning: (tsdoc-undefined-tag) The TSDoc tag "@private" is not defined in this configuration
// Warning: (ae-forgotten-export) The symbol "VectorQueryOptions" needs to be exported by the entry point index.d.ts
//
// @internal
constructor(_query: Query<AppModelType, DbModelType>, vectorField: string | firestore.FieldPath, queryVector: firestore.VectorValue | Array<number>, options: VectorQueryOptions);
// Warning: (tsdoc-undefined-tag) The TSDoc tag "@private" is not defined in this configuration
//
// @internal
_createSnapshot(readTime: Timestamp, size: number, docs: () => Array<QueryDocumentSnapshot<AppModelType, DbModelType>>, changes: () => Array<DocumentChange<AppModelType, DbModelType>>): VectorQuerySnapshot<AppModelType, DbModelType>;
get(): Promise<VectorQuerySnapshot<AppModelType, DbModelType>>;
isEqual(other: firestore.VectorQuery<AppModelType, DbModelType>): boolean;
get query(): Query<AppModelType, DbModelType>;
// Warning: (tsdoc-undefined-tag) The TSDoc tag "@private" is not defined in this configuration
//
// @internal (undocumented)
readonly _queryUtil: QueryUtil<AppModelType, DbModelType, VectorQuery<AppModelType, DbModelType>>;
// Warning: (tsdoc-undefined-tag) The TSDoc tag "@private" is not defined in this configuration
//
// @internal
startAfter(...fieldValuesOrDocumentSnapshot: Array<unknown>): VectorQuery<AppModelType, DbModelType>;
// Warning: (tsdoc-undefined-tag) The TSDoc tag "@private" is not defined in this configuration
//
// @internal
_stream(transactionId?: Uint8Array): NodeJS.ReadableStream;
// Warning: (tsdoc-undefined-tag) The TSDoc tag "@private" is not defined in this configuration
//
// @internal
toProto(transactionIdOrReadTime?: Uint8Array | Timestamp): api.IRunQueryRequest;
}

// @public
export class VectorQuerySnapshot<AppModelType = firestore.DocumentData, DbModelType extends firestore.DocumentData = firestore.DocumentData> implements firestore.VectorQuerySnapshot<AppModelType, DbModelType> {
// Warning: (tsdoc-undefined-tag) The TSDoc tag "@private" is not defined in this configuration
//
// @internal
constructor(_query: VectorQuery<AppModelType, DbModelType>, _readTime: Timestamp, _size: number, docs: () => Array<QueryDocumentSnapshot<AppModelType, DbModelType>>, changes: () => Array<DocumentChange<AppModelType, DbModelType>>);
docChanges(): Array<DocumentChange<AppModelType, DbModelType>>;
get docs(): Array<QueryDocumentSnapshot<AppModelType, DbModelType>>;
get empty(): boolean;
forEach(callback: (result: firestore.QueryDocumentSnapshot<AppModelType, DbModelType>) => void, thisArg?: unknown): void;
isEqual(other: firestore.VectorQuerySnapshot<AppModelType, DbModelType>): boolean;
get query(): VectorQuery<AppModelType, DbModelType>;
get readTime(): Timestamp;
get size(): number;
}

// Warning: (tsdoc-undefined-tag) The TSDoc tag "@class" is not defined in this configuration
//
// @public
export class VectorValue implements firestore.VectorValue {
// Warning: (tsdoc-undefined-tag) The TSDoc tag "@private" is not defined in this configuration
//
// @internal
constructor(values: number[] | undefined);
// Warning: (tsdoc-undefined-tag) The TSDoc tag "@private" is not defined in this configuration
//
// @internal (undocumented)
static _fromProto(valueArray: api.IValue): VectorValue;
isEqual(other: VectorValue): boolean;
toArray(): number[];
// Warning: (tsdoc-undefined-tag) The TSDoc tag "@private" is not defined in this configuration
//
// @internal (undocumented)
_toProto(serializer: Serializer): api.IValue;
}

// Warning: (tsdoc-undefined-tag) The TSDoc tag "@class" is not defined in this configuration
//
// @public
Expand Down Expand Up @@ -1570,24 +1656,26 @@ export class WriteResult implements firestore.WriteResult {
// build/src/reference.d.ts:367:4 - (tsdoc-undefined-tag) The TSDoc tag "@class" is not defined in this configuration
// build/src/reference.d.ts:398:4 - (tsdoc-undefined-tag) The TSDoc tag "@private" is not defined in this configuration
// build/src/reference.d.ts:400:4 - (tsdoc-undefined-tag) The TSDoc tag "@class" is not defined in this configuration
// build/src/reference.d.ts:629:4 - (tsdoc-undefined-tag) The TSDoc tag "@private" is not defined in this configuration
// build/src/reference.d.ts:999:8 - (tsdoc-undefined-tag) The TSDoc tag "@return" is not defined in this configuration
// build/src/reference.d.ts:1005:8 - (tsdoc-undefined-tag) The TSDoc tag "@private" is not defined in this configuration
// build/src/reference.d.ts:1007:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
// build/src/reference.d.ts:1015:8 - (tsdoc-undefined-tag) The TSDoc tag "@private" is not defined in this configuration
// build/src/reference.d.ts:1017:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
// build/src/reference.d.ts:1017:15 - (tsdoc-param-tag-with-invalid-type) The @param block should not include a JSDoc-style '{type}'
// build/src/reference.d.ts:1019:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
// build/src/reference.d.ts:1019:15 - (tsdoc-param-tag-with-invalid-type) The @param block should not include a JSDoc-style '{type}'
// build/src/reference.d.ts:1021:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
// build/src/reference.d.ts:1023:24 - (tsdoc-escape-right-brace) The "}" character should be escaped using a backslash to avoid confusion with a TSDoc inline tag
// build/src/reference.d.ts:1023:17 - (tsdoc-malformed-inline-tag) Expecting a TSDoc tag starting with "{@"
// build/src/reference.d.ts:1032:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
// build/src/reference.d.ts:1034:8 - (tsdoc-undefined-tag) The TSDoc tag "@return" is not defined in this configuration
// build/src/reference.d.ts:1036:8 - (tsdoc-undefined-tag) The TSDoc tag "@private" is not defined in this configuration
// build/src/reference.d.ts:1220:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
// build/src/reference.d.ts:1221:8 - (tsdoc-undefined-tag) The TSDoc tag "@private" is not defined in this configuration
// build/src/reference.d.ts:1478:8 - (tsdoc-undefined-tag) The TSDoc tag "@private" is not defined in this configuration
// build/src/reference.d.ts:800:4 - (tsdoc-undefined-tag) The TSDoc tag "@private" is not defined in this configuration
// build/src/reference.d.ts:1228:8 - (tsdoc-undefined-tag) The TSDoc tag "@return" is not defined in this configuration
// build/src/reference.d.ts:1234:8 - (tsdoc-undefined-tag) The TSDoc tag "@private" is not defined in this configuration
// build/src/reference.d.ts:1236:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
// build/src/reference.d.ts:1244:8 - (tsdoc-undefined-tag) The TSDoc tag "@private" is not defined in this configuration
// build/src/reference.d.ts:1246:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
// build/src/reference.d.ts:1246:15 - (tsdoc-param-tag-with-invalid-type) The @param block should not include a JSDoc-style '{type}'
// build/src/reference.d.ts:1248:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
// build/src/reference.d.ts:1248:15 - (tsdoc-param-tag-with-invalid-type) The @param block should not include a JSDoc-style '{type}'
// build/src/reference.d.ts:1250:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
// build/src/reference.d.ts:1252:24 - (tsdoc-escape-right-brace) The "}" character should be escaped using a backslash to avoid confusion with a TSDoc inline tag
// build/src/reference.d.ts:1252:17 - (tsdoc-malformed-inline-tag) Expecting a TSDoc tag starting with "{@"
// build/src/reference.d.ts:1261:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
// build/src/reference.d.ts:1263:8 - (tsdoc-undefined-tag) The TSDoc tag "@return" is not defined in this configuration
// build/src/reference.d.ts:1265:8 - (tsdoc-undefined-tag) The TSDoc tag "@private" is not defined in this configuration
// build/src/reference.d.ts:1449:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
// build/src/reference.d.ts:1450:8 - (tsdoc-undefined-tag) The TSDoc tag "@private" is not defined in this configuration
// build/src/reference.d.ts:1715:8 - (tsdoc-undefined-tag) The TSDoc tag "@private" is not defined in this configuration
// build/src/reference.d.ts:1825:8 - (tsdoc-undefined-tag) The TSDoc tag "@private" is not defined in this configuration
// build/src/reference.d.ts:1830:8 - (tsdoc-undefined-tag) The TSDoc tag "@private" is not defined in this configuration
// build/src/serializer.d.ts:26:4 - (tsdoc-undefined-tag) The TSDoc tag "@private" is not defined in this configuration
// build/src/serializer.d.ts:36:4 - (tsdoc-undefined-tag) The TSDoc tag "@private" is not defined in this configuration
// build/src/transaction.d.ts:239:8 - (tsdoc-undefined-tag) The TSDoc tag "@private" is not defined in this configuration
Expand Down
2 changes: 1 addition & 1 deletion dev/src/aggregate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*!
/**
* Copyright 2023 Google LLC. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
103 changes: 62 additions & 41 deletions dev/src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {ApiMapValue, ProtobufJsValue} from './types';
import {validateObject} from './validate';

import api = google.firestore.v1;
import {RESERVED_MAP_KEY, RESERVED_MAP_KEY_VECTOR_VALUE} from './map-type';

/*!
* @module firestore/convert
Expand Down Expand Up @@ -112,53 +113,72 @@ function bytesFromJson(bytesValue: string | Uint8Array): Uint8Array {
* @return The string value for 'valueType'.
*/
export function detectValueType(proto: ProtobufJsValue): string {
let valueType: string | undefined;

if (proto.valueType) {
return proto.valueType;
}
valueType = proto.valueType;
} else {
const detectedValues: string[] = [];

const detectedValues: string[] = [];
if (proto.stringValue !== undefined) {
detectedValues.push('stringValue');
}
if (proto.booleanValue !== undefined) {
detectedValues.push('booleanValue');
}
if (proto.integerValue !== undefined) {
detectedValues.push('integerValue');
}
if (proto.doubleValue !== undefined) {
detectedValues.push('doubleValue');
}
if (proto.timestampValue !== undefined) {
detectedValues.push('timestampValue');
}
if (proto.referenceValue !== undefined) {
detectedValues.push('referenceValue');
}
if (proto.arrayValue !== undefined) {
detectedValues.push('arrayValue');
}
if (proto.nullValue !== undefined) {
detectedValues.push('nullValue');
}
if (proto.mapValue !== undefined) {
detectedValues.push('mapValue');
}
if (proto.geoPointValue !== undefined) {
detectedValues.push('geoPointValue');
}
if (proto.bytesValue !== undefined) {
detectedValues.push('bytesValue');
}

if (proto.stringValue !== undefined) {
detectedValues.push('stringValue');
}
if (proto.booleanValue !== undefined) {
detectedValues.push('booleanValue');
}
if (proto.integerValue !== undefined) {
detectedValues.push('integerValue');
}
if (proto.doubleValue !== undefined) {
detectedValues.push('doubleValue');
}
if (proto.timestampValue !== undefined) {
detectedValues.push('timestampValue');
}
if (proto.referenceValue !== undefined) {
detectedValues.push('referenceValue');
}
if (proto.arrayValue !== undefined) {
detectedValues.push('arrayValue');
}
if (proto.nullValue !== undefined) {
detectedValues.push('nullValue');
}
if (proto.mapValue !== undefined) {
detectedValues.push('mapValue');
}
if (proto.geoPointValue !== undefined) {
detectedValues.push('geoPointValue');
}
if (proto.bytesValue !== undefined) {
detectedValues.push('bytesValue');
if (detectedValues.length !== 1) {
throw new Error(
`Unable to infer type value from '${JSON.stringify(proto)}'.`
);
}

valueType = detectedValues[0];
}

if (detectedValues.length !== 1) {
throw new Error(
`Unable to infer type value from '${JSON.stringify(proto)}'.`
);
// Special handling of mapValues used to represent other data types
if (valueType === 'mapValue') {
const fields = proto.mapValue?.fields;
if (fields) {
const props = Object.keys(fields);
if (
props.indexOf(RESERVED_MAP_KEY) !== -1 &&
detectValueType(fields[RESERVED_MAP_KEY]) === 'stringValue' &&
fields[RESERVED_MAP_KEY].stringValue === RESERVED_MAP_KEY_VECTOR_VALUE
) {
valueType = 'vectorValue';
}
}
}

return detectedValues[0];
return valueType;
}

/**
Expand Down Expand Up @@ -240,7 +260,8 @@ export function valueFromJson(fieldValue: api.IValue): api.IValue {
},
};
}
case 'mapValue': {
case 'mapValue':
case 'vectorValue': {
const mapValue: ApiMapValue = {};
const fields = fieldValue.mapValue!.fields;
if (fields) {
Expand Down
Loading
Loading