Skip to content

Commit

Permalink
Merge branch 'master' into bc/bulk-master
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Chen committed Mar 31, 2020
2 parents 6711782 + ce6c1f5 commit 65a177a
Show file tree
Hide file tree
Showing 17 changed files with 201 additions and 53 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
matrix:
node: [8, 10, 12, 13]
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
Expand All @@ -30,7 +30,7 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
Expand All @@ -39,7 +39,7 @@ jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
Expand All @@ -48,7 +48,7 @@ jobs:
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 13
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@

[1]: https://www.npmjs.com/package/@google-cloud/firestore?activeTab=versions

### [3.7.3](https://www.github.com/googleapis/nodejs-firestore/compare/v3.7.2...v3.7.3) (2020-03-31)


### Bug Fixes

* support array of references for IN queries ([#993](https://www.github.com/googleapis/nodejs-firestore/issues/993)) ([a6d8fe0](https://www.github.com/googleapis/nodejs-firestore/commit/a6d8fe061fcfe0fde7a4fa023b2ec454e2adb432))

### [3.7.2](https://www.github.com/googleapis/nodejs-firestore/compare/v3.7.1...v3.7.2) (2020-03-25)


### Bug Fixes

* fix flaky contention test ([#979](https://www.github.com/googleapis/nodejs-firestore/issues/979)) ([f294998](https://www.github.com/googleapis/nodejs-firestore/commit/f294998daab77a0a51c81265945e28eec34db186))
* fix: use Random Number from `crypto` to generate AutoId ([05b3363](https://www.github.com/googleapis/nodejs-firestore/commit/ce6ea390f2fffcbe796ba1c5b040ee02452e287a))

### [3.7.1](https://www.github.com/googleapis/nodejs-firestore/compare/v3.7.0...v3.7.1) (2020-03-16)


Expand Down
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,27 @@ has instructions for running the samples.
The [Cloud Firestore Node.js Client API Reference][client-docs] documentation
also contains samples.

## Supported Node.js Versions

Our client libraries follow the [Node.js release schedule](https://nodejs.org/en/about/releases/).
Libraries are compatible with all current _active_ and _maintenance_ versions of
Node.js.

Client libraries targetting some end-of-life versions of Node.js are available, and
can be installed via npm [dist-tags](https://docs.npmjs.com/cli/dist-tag).
The dist-tags follow the naming convention `legacy-(version)`.

_Legacy Node.js versions are supported as a best effort:_

* Legacy versions will not be tested in continuous integration.
* Some security patches may not be able to be backported.
* Dependencies will not be kept up-to-date, and features will not be backported.

#### Legacy tags available

* `legacy-8`: install client libraries from this dist-tag for versions
compatible with Node.js 8.

## Versioning

This library follows [Semantic Versioning](http://semver.org/).
Expand Down
20 changes: 0 additions & 20 deletions dev/src/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,26 +505,6 @@ export class DocumentSnapshot<T = DocumentData> {
export class QueryDocumentSnapshot<T = DocumentData> extends DocumentSnapshot<
T
> {
/**
* @hideconstructor
*
* @param ref The reference to the document.
* @param fieldsProto The fields of the Firestore `Document` Protobuf backing
* this document.
* @param readTime The time when this snapshot was read.
* @param createTime The time when the document was created.
* @param updateTime The time when the document was last updated.
*/
constructor(
ref: DocumentReference<T>,
fieldsProto: ApiMapValue,
readTime: Timestamp,
createTime: Timestamp,
updateTime: Timestamp
) {
super(ref, fieldsProto, readTime, createTime, updateTime);
}

/**
* The time the document was created.
*
Expand Down
20 changes: 18 additions & 2 deletions dev/src/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,23 @@ export class Query<T = DocumentData> {
const path = FieldPath.fromArgument(fieldPath);

if (FieldPath.documentId().isEqual(path)) {
value = this.validateReference(value);
if (opStr === 'array-contains' || opStr === 'array-contains-any') {
throw new Error(
`Invalid Query. You can't perform '${opStr}' ` +
'queries on FieldPath.documentId().'
);
}

if (opStr === 'in') {
if (!Array.isArray(value) || value.length === 0) {
throw new Error(
`Invalid Query. A non-empty array is required for '${opStr}' filters.`
);
}
value = value.map(el => this.validateReference(el));
} else {
value = this.validateReference(value);
}
}

const fieldFilter = new FieldFilter(
Expand Down Expand Up @@ -1595,7 +1611,7 @@ export class Query<T = DocumentData> {
} else {
throw new Error(
'The corresponding value for FieldPath.documentId() must be a ' +
'string or a DocumentReference.'
`string or a DocumentReference, but was "${val}".`
);
}

Expand Down
14 changes: 12 additions & 2 deletions dev/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import {randomBytes} from 'crypto';
import {GoogleError, ServiceConfig, Status} from 'google-gax';

import {DocumentData} from './types';
Expand Down Expand Up @@ -52,8 +53,17 @@ export function autoId(): string {
const chars =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let autoId = '';
for (let i = 0; i < 20; i++) {
autoId += chars.charAt(Math.floor(Math.random() * chars.length));
while (autoId.length < 20) {
const bytes = randomBytes(40);
bytes.forEach(b => {
// Length of `chars` is 62. We only take bytes between 0 and 62*4-1
// (both inclusive). The value is then evenly mapped to indices of `char`
// via a modulo operation.
const maxValue = 62 * 4 - 1;
if (autoId.length < 20 && b <= maxValue) {
autoId += chars.charAt(b % 62);
}
});
}
return autoId;
}
Expand Down
12 changes: 9 additions & 3 deletions dev/src/v1/firestore_admin_client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019 Google LLC
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -42,7 +42,12 @@ const version = require('../../../package.json').version;
* @memberof v1
*/
export class FirestoreAdminClient {
private _descriptors: Descriptors = {page: {}, stream: {}, longrunning: {}};
private _descriptors: Descriptors = {
page: {},
stream: {},
longrunning: {},
batching: {},
};
private _innerApiCalls: {[name: string]: Function};
private _pathTemplates: {[name: string]: gax.PathTemplate};
private _terminated = false;
Expand Down Expand Up @@ -307,7 +312,8 @@ export class FirestoreAdminClient {
if (this._terminated) {
return Promise.reject('The client has already been closed.');
}
return stub[methodName].apply(stub, args);
const func = stub[methodName];
return func.apply(stub, args);
},
(err: Error | null | undefined) => () => {
throw err;
Expand Down
12 changes: 9 additions & 3 deletions dev/src/v1/firestore_client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019 Google LLC
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -47,7 +47,12 @@ const version = require('../../../package.json').version;
* @memberof v1
*/
export class FirestoreClient {
private _descriptors: Descriptors = {page: {}, stream: {}, longrunning: {}};
private _descriptors: Descriptors = {
page: {},
stream: {},
longrunning: {},
batching: {},
};
private _innerApiCalls: {[name: string]: Function};
private _terminated = false;
private _opts: ClientOptions;
Expand Down Expand Up @@ -250,7 +255,8 @@ export class FirestoreClient {
if (this._terminated) {
return Promise.reject('The client has already been closed.');
}
return stub[methodName].apply(stub, args);
const func = stub[methodName];
return func.apply(stub, args);
},
(err: Error | null | undefined) => () => {
throw err;
Expand Down
12 changes: 9 additions & 3 deletions dev/src/v1beta1/firestore_client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019 Google LLC
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -55,7 +55,12 @@ const version = require('../../../package.json').version;
* @memberof v1beta1
*/
export class FirestoreClient {
private _descriptors: Descriptors = {page: {}, stream: {}, longrunning: {}};
private _descriptors: Descriptors = {
page: {},
stream: {},
longrunning: {},
batching: {},
};
private _innerApiCalls: {[name: string]: Function};
private _terminated = false;
private _opts: ClientOptions;
Expand Down Expand Up @@ -258,7 +263,8 @@ export class FirestoreClient {
if (this._terminated) {
return Promise.reject('The client has already been closed.');
}
return stub[methodName].apply(stub, args);
const func = stub[methodName];
return func.apply(stub, args);
},
(err: Error | null | undefined) => () => {
throw err;
Expand Down
14 changes: 7 additions & 7 deletions dev/synth.metadata
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"updateTime": "2020-03-05T23:07:35.336516Z",
"updateTime": "2020-03-22T11:28:16.621427Z",
"sources": [
{
"git": {
"name": "googleapis",
"remote": "https://github.com/googleapis/googleapis.git",
"sha": "f0b581b5bdf803e45201ecdb3688b60e381628a8",
"internalRef": "299181282"
"sha": "0be7105dc52590fa9a24e784052298ae37ce53aa",
"internalRef": "302154871"
}
},
{
"template": {
"name": "node_library",
"origin": "synthtool.gcp",
"version": "2020.2.4"
"git": {
"name": "synthtool",
"remote": "https://github.com/googleapis/synthtool.git",
"sha": "7e98e1609c91082f4eeb63b530c6468aefd18cfd"
}
}
],
Expand Down
23 changes: 20 additions & 3 deletions dev/system-test/firestore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import * as chaiAsPromised from 'chai-as-promised';
import {
CollectionReference,
DocumentData,
DocumentReference,
DocumentSnapshot,
FieldPath,
FieldValue,
Expand Down Expand Up @@ -1079,9 +1080,17 @@ describe('Query class', () => {
});
};

function addDocs(...data: DocumentData[]): Promise<WriteResult[]> {
async function addDocs(
...docs: DocumentData[]
): Promise<DocumentReference[]> {
let id = 0; // Guarantees consistent ordering for the first documents
return Promise.all(data.map(d => randomCol.doc('' + id++).set(d)));
const refs: DocumentReference[] = [];
for (const doc of docs) {
const ref = randomCol.doc('doc' + id++);
await ref.set(doc);
refs.push(ref);
}
return refs;
}

function expectDocs(result: QuerySnapshot, ...data: DocumentData[]) {
Expand Down Expand Up @@ -1171,7 +1180,7 @@ describe('Query class', () => {
});
});

it('supports in', async () => {
it('supports "in"', async () => {
await addDocs(
{zip: 98101},
{zip: 91102},
Expand All @@ -1184,6 +1193,14 @@ describe('Query class', () => {
expectDocs(res, {zip: 98101}, {zip: 98103});
});

it('supports "in" with document ID array', async () => {
const refs = await addDocs({count: 1}, {count: 2}, {count: 3});
const res = await randomCol
.where(FieldPath.documentId(), 'in', [refs[0].id, refs[1]])
.get();
expectDocs(res, {count: 1}, {count: 2});
});

it('supports array-contains-any', async () => {
await addDocs(
{array: [42]},
Expand Down
2 changes: 1 addition & 1 deletion dev/test/gapic-firestore-v1.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019 Google LLC
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion dev/test/gapic-firestore-v1beta1.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019 Google LLC
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion dev/test/gapic-firestore_admin-v1.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019 Google LLC
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Loading

0 comments on commit 65a177a

Please sign in to comment.