Socket
Socket
Sign inDemoInstall

@google-cloud/firestore

Package Overview
Dependencies
Maintainers
1
Versions
145
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@google-cloud/firestore - npm Package Compare versions

Comparing version 7.5.0 to 7.6.0

build/src/map-type.d.ts

2

build/src/aggregate.d.ts

@@ -1,2 +0,2 @@

/*!
/**
* Copyright 2023 Google LLC. All Rights Reserved.

@@ -3,0 +3,0 @@ *

"use strict";
/*!
/**
* Copyright 2023 Google LLC. All Rights Reserved.

@@ -4,0 +4,0 @@ *

@@ -20,2 +20,3 @@ "use strict";

const validate_1 = require("./validate");
const map_type_1 = require("./map-type");
/*!

@@ -99,43 +100,60 @@ * @module firestore/convert

function detectValueType(proto) {
var _a;
let valueType;
if (proto.valueType) {
return proto.valueType;
valueType = proto.valueType;
}
const detectedValues = [];
if (proto.stringValue !== undefined) {
detectedValues.push('stringValue');
else {
const detectedValues = [];
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 (proto.booleanValue !== undefined) {
detectedValues.push('booleanValue');
// Special handling of mapValues used to represent other data types
if (valueType === 'mapValue') {
const fields = (_a = proto.mapValue) === null || _a === void 0 ? void 0 : _a.fields;
if (fields) {
const props = Object.keys(fields);
if (props.indexOf(map_type_1.RESERVED_MAP_KEY) !== -1 &&
detectValueType(fields[map_type_1.RESERVED_MAP_KEY]) === 'stringValue' &&
fields[map_type_1.RESERVED_MAP_KEY].stringValue === map_type_1.RESERVED_MAP_KEY_VECTOR_VALUE) {
valueType = 'vectorValue';
}
}
}
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)}'.`);
}
return detectedValues[0];
return valueType;
}

@@ -214,3 +232,4 @@ exports.detectValueType = detectValueType;

}
case 'mapValue': {
case 'mapValue':
case 'vectorValue': {
const mapValue = {};

@@ -217,0 +236,0 @@ const fields = fieldValue.mapValue.fields;

@@ -23,2 +23,34 @@ /*!

/**
* Represent a vector type in Firestore documents.
* Create an instance with {@link FieldValue.vector}.
*
* @class VectorValue
*/
export declare class VectorValue implements firestore.VectorValue {
private readonly _values;
/**
* @private
* @internal
*/
constructor(values: number[] | undefined);
/**
* Returns a copy of the raw number array form of the vector.
*/
toArray(): number[];
/**
* @private
* @internal
*/
_toProto(serializer: Serializer): api.IValue;
/**
* @private
* @internal
*/
static _fromProto(valueArray: api.IValue): VectorValue;
/**
* Returns `true` if the two VectorValue has the same raw number arrays, returns `false` otherwise.
*/
isEqual(other: VectorValue): boolean;
}
/**
* Sentinel values that can be used when writing documents with set(), create()

@@ -33,2 +65,10 @@ * or update().

/**
* Creates a new `VectorValue` constructed with a copy of the given array of numbers.
*
* @param values - Create a `VectorValue` instance with a copy of this array of numbers.
*
* @returns A new `VectorValue` constructed with a copy of the given array of numbers.
*/
static vector(values?: number[]): VectorValue;
/**
* Returns a sentinel for use with update() or set() with {merge:true} to mark

@@ -35,0 +75,0 @@ * a field for deletion.

@@ -18,7 +18,55 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.DeleteTransform = exports.FieldTransform = exports.FieldValue = void 0;
exports.DeleteTransform = exports.FieldTransform = exports.FieldValue = exports.VectorValue = void 0;
const deepEqual = require("fast-deep-equal");
const serializer_1 = require("./serializer");
const util_1 = require("./util");
const validate_1 = require("./validate");
/**
* Represent a vector type in Firestore documents.
* Create an instance with {@link FieldValue.vector}.
*
* @class VectorValue
*/
class VectorValue {
/**
* @private
* @internal
*/
constructor(values) {
// Making a copy of the parameter.
this._values = (values || []).map(n => n);
}
/**
* Returns a copy of the raw number array form of the vector.
*/
toArray() {
return this._values.map(n => n);
}
/**
* @private
* @internal
*/
_toProto(serializer) {
return serializer.encodeVector(this._values);
}
/**
* @private
* @internal
*/
static _fromProto(valueArray) {
var _a, _b;
const values = (_b = (_a = valueArray.arrayValue) === null || _a === void 0 ? void 0 : _a.values) === null || _b === void 0 ? void 0 : _b.map(v => {
return v.doubleValue;
});
return new VectorValue(values);
}
/**
* Returns `true` if the two VectorValue has the same raw number arrays, returns `false` otherwise.
*/
isEqual(other) {
return (0, util_1.isPrimitiveArrayEqual)(this._values, other._values);
}
}
exports.VectorValue = VectorValue;
/**
* Sentinel values that can be used when writing documents with set(), create()

@@ -33,2 +81,12 @@ * or update().

/**
* Creates a new `VectorValue` constructed with a copy of the given array of numbers.
*
* @param values - Create a `VectorValue` instance with a copy of this array of numbers.
*
* @returns A new `VectorValue` constructed with a copy of the given array of numbers.
*/
static vector(values) {
return new VectorValue(values);
}
/**
* Returns a sentinel for use with update() or set() with {merge:true} to mark

@@ -35,0 +93,0 @@ * a field for deletion.

@@ -32,3 +32,3 @@ /*!

export { CollectionReference, DocumentReference, QuerySnapshot, Query, } from './reference';
export type { AggregateQuery, AggregateQuerySnapshot } from './reference';
export type { AggregateQuery, AggregateQuerySnapshot, VectorQuery, VectorQuerySnapshot, } from './reference';
export { BulkWriter } from './bulk-writer';

@@ -38,3 +38,3 @@ export type { BulkWriterError } from './bulk-writer';

export { DocumentSnapshot, QueryDocumentSnapshot } from './document';
export { FieldValue } from './field-value';
export { FieldValue, VectorValue } from './field-value';
export { Filter } from './filter';

@@ -41,0 +41,0 @@ export { WriteBatch, WriteResult } from './write-batch';

@@ -18,3 +18,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.Firestore = exports.DEFAULT_MAX_TRANSACTION_ATTEMPTS = exports.MAX_REQUEST_RETRIES = exports.AggregateField = exports.Aggregate = exports.setLogFunction = exports.QueryPartition = exports.CollectionGroup = exports.GeoPoint = exports.FieldPath = exports.DocumentChange = exports.Timestamp = exports.Transaction = exports.WriteResult = exports.WriteBatch = exports.Filter = exports.FieldValue = exports.QueryDocumentSnapshot = exports.DocumentSnapshot = exports.BulkWriter = exports.Query = exports.QuerySnapshot = exports.DocumentReference = exports.CollectionReference = void 0;
exports.Firestore = exports.DEFAULT_MAX_TRANSACTION_ATTEMPTS = exports.MAX_REQUEST_RETRIES = exports.AggregateField = exports.Aggregate = exports.setLogFunction = exports.QueryPartition = exports.CollectionGroup = exports.GeoPoint = exports.FieldPath = exports.DocumentChange = exports.Timestamp = exports.Transaction = exports.WriteResult = exports.WriteBatch = exports.Filter = exports.VectorValue = exports.FieldValue = exports.QueryDocumentSnapshot = exports.DocumentSnapshot = exports.BulkWriter = exports.Query = exports.QuerySnapshot = exports.DocumentReference = exports.CollectionReference = void 0;
const stream_1 = require("stream");

@@ -55,2 +55,3 @@ const url_1 = require("url");

Object.defineProperty(exports, "FieldValue", { enumerable: true, get: function () { return field_value_1.FieldValue; } });
Object.defineProperty(exports, "VectorValue", { enumerable: true, get: function () { return field_value_1.VectorValue; } });
var filter_1 = require("./filter");

@@ -57,0 +58,0 @@ Object.defineProperty(exports, "Filter", { enumerable: true, get: function () { return filter_1.Filter; } });

@@ -35,3 +35,4 @@ "use strict";

TypeOrder[TypeOrder["ARRAY"] = 8] = "ARRAY";
TypeOrder[TypeOrder["OBJECT"] = 9] = "OBJECT";
TypeOrder[TypeOrder["VECTOR"] = 9] = "VECTOR";
TypeOrder[TypeOrder["OBJECT"] = 10] = "OBJECT";
})(TypeOrder || (TypeOrder = {}));

@@ -67,2 +68,4 @@ /*!

return TypeOrder.OBJECT;
case 'vectorValue':
return TypeOrder.VECTOR;
default:

@@ -209,2 +212,17 @@ throw new Error('Unexpected value type: ' + valueType);

*/
function compareVectors(left, right) {
var _a, _b, _c, _d, _e, _f;
// The vector is a map, but only vector value is compared.
const leftArray = (_c = (_b = (_a = left === null || left === void 0 ? void 0 : left['value']) === null || _a === void 0 ? void 0 : _a.arrayValue) === null || _b === void 0 ? void 0 : _b.values) !== null && _c !== void 0 ? _c : [];
const rightArray = (_f = (_e = (_d = right === null || right === void 0 ? void 0 : right['value']) === null || _d === void 0 ? void 0 : _d.arrayValue) === null || _e === void 0 ? void 0 : _e.values) !== null && _f !== void 0 ? _f : [];
const lengthCompare = primitiveComparator(leftArray.length, rightArray.length);
if (lengthCompare !== 0) {
return lengthCompare;
}
return compareArrays(leftArray, rightArray);
}
/*!
* @private
* @internal
*/
function compare(left, right) {

@@ -241,2 +259,4 @@ // First compare the types.

return compareObjects(left.mapValue.fields || {}, right.mapValue.fields || {});
case TypeOrder.VECTOR:
return compareVectors(left.mapValue.fields || {}, right.mapValue.fields || {});
default:

@@ -243,0 +263,0 @@ throw new Error(`Encountered unknown type order: ${leftType}`);

@@ -63,2 +63,6 @@ /*!

/**
* @private
*/
encodeVector(rawVector: number[]): api.IValue;
/**
* Decodes a single Firestore 'Value' Protobuf.

@@ -65,0 +69,0 @@ *

@@ -19,4 +19,4 @@ "use strict";

exports.validateUserInput = exports.Serializer = void 0;
const field_value_1 = require("./field-value");
const convert_1 = require("./convert");
const field_value_1 = require("./field-value");
const geo_point_1 = require("./geo-point");

@@ -28,2 +28,3 @@ const index_1 = require("./index");

const validate_1 = require("./validate");
const map_type_1 = require("./map-type");
/**

@@ -138,2 +139,5 @@ * The maximum depth of a Firestore object.

}
if (val instanceof field_value_1.VectorValue) {
return val._toProto(this);
}
if ((0, util_1.isObject)(val)) {

@@ -180,2 +184,26 @@ const toProto = val['toProto'];

/**
* @private
*/
encodeVector(rawVector) {
// A Firestore Vector is a map with reserved key/value pairs.
return {
mapValue: {
fields: {
[map_type_1.RESERVED_MAP_KEY]: {
stringValue: map_type_1.RESERVED_MAP_KEY_VECTOR_VALUE,
},
[map_type_1.VECTOR_MAP_VECTORS_KEY]: {
arrayValue: {
values: rawVector.map(value => {
return {
doubleValue: value,
};
}),
},
},
},
},
};
}
/**
* Decodes a single Firestore 'Value' Protobuf.

@@ -223,11 +251,18 @@ *

case 'mapValue': {
const obj = {};
const fields = proto.mapValue.fields;
if (fields) {
const obj = {};
for (const prop of Object.keys(fields)) {
obj[prop] = this.decodeValue(fields[prop]);
}
return obj;
}
return obj;
else {
return {};
}
}
case 'vectorValue': {
const fields = proto.mapValue.fields;
return field_value_1.VectorValue._fromProto(fields[map_type_1.VECTOR_MAP_VECTORS_KEY]);
}
case 'geoPointValue': {

@@ -356,2 +391,5 @@ return geo_point_1.GeoPoint.fromProto(proto.geoPointValue);

}
else if (value instanceof field_value_1.VectorValue) {
// OK
}
else if (value instanceof field_value_1.DeleteTransform) {

@@ -358,0 +396,0 @@ if (inArray) {

@@ -159,1 +159,23 @@ /*!

export declare function mapToArray<V, R>(obj: Dict<V>, fn: (element: V, key: string, obj: Dict<V>) => R): R[];
/**
* Verifies equality for an array of objects using the `isEqual` interface.
*
* @private
* @internal
* @param left Array of objects supporting `isEqual`.
* @param right Array of objects supporting `isEqual`.
* @return True if arrays are equal.
*/
export declare function isArrayEqual<T extends {
isEqual: (t: T) => boolean;
}>(left: T[], right: T[]): boolean;
/**
* Verifies equality for an array of primitives.
*
* @private
* @internal
* @param left Array of primitives.
* @param right Array of primitives.
* @return True if arrays are equal.
*/
export declare function isPrimitiveArrayEqual<T extends number | string>(left: T[], right: T[]): boolean;

@@ -18,3 +18,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.mapToArray = exports.tryGetPreferRestEnvironmentVariable = exports.wrapError = exports.silencePromise = exports.getRetryParams = exports.getTotalTimeout = exports.getRetryCodes = exports.isPermanentRpcError = exports.isFunction = exports.isEmpty = exports.isPlainObject = exports.isObject = exports.requestTag = exports.autoId = exports.Deferred = void 0;
exports.isPrimitiveArrayEqual = exports.isArrayEqual = exports.mapToArray = exports.tryGetPreferRestEnvironmentVariable = exports.wrapError = exports.silencePromise = exports.getRetryParams = exports.getTotalTimeout = exports.getRetryCodes = exports.isPermanentRpcError = exports.isFunction = exports.isEmpty = exports.isPlainObject = exports.isObject = exports.requestTag = exports.autoId = exports.Deferred = void 0;
const crypto_1 = require("crypto");

@@ -264,2 +264,44 @@ const gapicConfig = require("./v1/firestore_client_config.json");

exports.mapToArray = mapToArray;
/**
* Verifies equality for an array of objects using the `isEqual` interface.
*
* @private
* @internal
* @param left Array of objects supporting `isEqual`.
* @param right Array of objects supporting `isEqual`.
* @return True if arrays are equal.
*/
function isArrayEqual(left, right) {
if (left.length !== right.length) {
return false;
}
for (let i = 0; i < left.length; ++i) {
if (!left[i].isEqual(right[i])) {
return false;
}
}
return true;
}
exports.isArrayEqual = isArrayEqual;
/**
* Verifies equality for an array of primitives.
*
* @private
* @internal
* @param left Array of primitives.
* @param right Array of primitives.
* @return True if arrays are equal.
*/
function isPrimitiveArrayEqual(left, right) {
if (left.length !== right.length) {
return false;
}
for (let i = 0; i < left.length; ++i) {
if (left[i] !== right[i]) {
return false;
}
}
return true;
}
exports.isPrimitiveArrayEqual = isPrimitiveArrayEqual;
//# sourceMappingURL=util.js.map
{
"name": "@google-cloud/firestore",
"description": "Firestore Client Library for Node.js",
"version": "7.5.0",
"version": "7.6.0",
"license": "Apache-2.0",

@@ -68,4 +68,4 @@ "author": "Google Inc.",

"functional-red-black-tree": "^1.0.1",
"google-gax": "^4.0.4",
"protobufjs": "^7.2.5"
"google-gax": "^4.3.1",
"protobufjs": "^7.2.6"
},

@@ -72,0 +72,0 @@ "devDependencies": {

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc