Skip to content

Commit

Permalink
Change client to always include /documents for root document paths (b…
Browse files Browse the repository at this point in the history
…ut not when we just need the database name).

The v1 protocol now enforces that /documents be included for root document paths.
  • Loading branch information
Michael Lehenbauer committed Jan 11, 2019
1 parent e5d521b commit 52c7381
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 19 deletions.
6 changes: 5 additions & 1 deletion dev/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,11 @@ export class Firestore {
* @private
*/
get formattedName(): string {
return this._referencePath!.formattedName;
const components = [
'projects', this._referencePath!.projectId, 'databases',
this._referencePath!.databaseId
];
return components.join('/');
}

/**
Expand Down
11 changes: 3 additions & 8 deletions dev/src/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,15 +343,10 @@ export class ResourcePath extends Path<ResourcePath> {
* @returns {string} The representation as expected by the API.
*/
canonicalString(): string {
let components = [
'projects',
this.projectId,
'databases',
this.databaseId,
const components = [
'projects', this.projectId, 'databases', this.databaseId, 'documents',
...this.segments
];
if (this.segments.length > 0) {
components = components.concat('documents', this.segments);
}
return components.join('/');
}

Expand Down
2 changes: 1 addition & 1 deletion dev/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ describe('listCollections() method', () => {
const overrides = {
listCollectionIds: (request, options, callback) => {
expect(request).to.deep.eq({
parent: `projects/${PROJECT_ID}/databases/(default)`,
parent: `projects/${PROJECT_ID}/databases/(default)/documents`,
});

callback(null, ['first', 'second']);
Expand Down
6 changes: 3 additions & 3 deletions dev/test/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('ResourcePath', () => {

it('has append() method', () => {
let path = new ResourcePath(PROJECT_ID, '(default)');
expect(path.formattedName).to.equal(DATABASE_ROOT);
expect(path.formattedName).to.equal(`${DATABASE_ROOT}/documents`);
path = path.append('foo');
expect(path.formattedName).to.equal(`${DATABASE_ROOT}/documents/foo`);
});
Expand All @@ -39,13 +39,13 @@ describe('ResourcePath', () => {
let path = new ResourcePath(PROJECT_ID, '(default)', 'foo');
expect(path.formattedName).to.equal(`${DATABASE_ROOT}/documents/foo`);
path = path.parent()!;
expect(path.formattedName).to.equal(DATABASE_ROOT);
expect(path.formattedName).to.equal(`${DATABASE_ROOT}/documents`);
expect(path.parent()).to.be.null;
});

it('parses strings', () => {
let path = ResourcePath.fromSlashSeparatedString(DATABASE_ROOT);
expect(path.formattedName).to.equal(DATABASE_ROOT);
expect(path.formattedName).to.equal(`${DATABASE_ROOT}/documents`);
path =
ResourcePath.fromSlashSeparatedString(`${DATABASE_ROOT}/documents/foo`);
expect(path.formattedName).to.equal(`${DATABASE_ROOT}/documents/foo`);
Expand Down
2 changes: 1 addition & 1 deletion dev/test/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ function endAt(before: boolean, ...values: Array<string|api.IValue>):
function queryEquals(
actual: api.IRunQueryRequest, ...protoComponents: api.IStructuredQuery[]) {
const query: api.IRunQueryRequest = {
parent: DATABASE_ROOT,
parent: DATABASE_ROOT + '/documents',
structuredQuery: {
from: [
{
Expand Down
2 changes: 1 addition & 1 deletion dev/test/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ function getAll(docs: string[], fieldMask?: string[]) {

function query(transaction?) {
const request = {
parent: DATABASE_ROOT,
parent: `${DATABASE_ROOT}/documents`,
structuredQuery: {
from: [
{
Expand Down
8 changes: 4 additions & 4 deletions dev/test/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ describe('Query watch', () => {
database: `projects/${PROJECT_ID}/databases/(default)`,
addTarget: {
query: {
parent: `projects/${PROJECT_ID}/databases/(default)`,
parent: `projects/${PROJECT_ID}/databases/(default)/documents`,
structuredQuery: {
from: [{collectionId: 'col'}],
},
Expand All @@ -546,7 +546,7 @@ describe('Query watch', () => {
database: `projects/${PROJECT_ID}/databases/(default)`,
addTarget: {
query: {
parent: `projects/${PROJECT_ID}/databases/(default)`,
parent: `projects/${PROJECT_ID}/databases/(default)/documents`,
structuredQuery: {
from: [{collectionId: 'col'}],
where: {
Expand All @@ -573,7 +573,7 @@ describe('Query watch', () => {
database: `projects/${PROJECT_ID}/databases/(default)`,
addTarget: {
query: {
parent: `projects/${PROJECT_ID}/databases/(default)`,
parent: `projects/${PROJECT_ID}/databases/(default)/documents`,
structuredQuery: {
from: [{collectionId: 'col'}],
},
Expand All @@ -594,7 +594,7 @@ describe('Query watch', () => {
database: `projects/${PROJECT_ID}/databases/(default)`,
addTarget: {
query: {
parent: `projects/${PROJECT_ID}/databases/(default)`,
parent: `projects/${PROJECT_ID}/databases/(default)/documents`,
structuredQuery: {
from: [{collectionId: 'col'}],
orderBy: [{direction: 'DESCENDING', field: {fieldPath: 'foo'}}],
Expand Down

0 comments on commit 52c7381

Please sign in to comment.