Skip to content

Add deleteDoc() #3138

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

Merged
merged 52 commits into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
da82b5d
Add Firestore, initializeFirestore, getFirestore to Firestore lite
schmidt-sebastian May 26, 2020
30bfc3f
Review
schmidt-sebastian May 27, 2020
f49096f
add one more tests
schmidt-sebastian May 27, 2020
da3403f
Fix lint
schmidt-sebastian May 27, 2020
bd3596e
Add lite to build
schmidt-sebastian May 27, 2020
3aac6f4
Add private
schmidt-sebastian May 27, 2020
6f05e2f
Fix Path
schmidt-sebastian May 27, 2020
634145a
Remove unused import
schmidt-sebastian May 27, 2020
8187cb7
Update package.json
schmidt-sebastian May 27, 2020
5760b02
Simplify
schmidt-sebastian May 27, 2020
4ba0f4e
Merge branch 'mrschmidt/initializefirestore' of github.com:firebase/f…
schmidt-sebastian May 27, 2020
e40faf4
Merge branch 'master' into mrschmidt/initializefirestore
schmidt-sebastian May 27, 2020
f243a6c
Add DocumentReference
schmidt-sebastian May 27, 2020
d48405b
Feedback
schmidt-sebastian May 28, 2020
804fe94
Typo
schmidt-sebastian May 28, 2020
d244bcd
Lint fix
schmidt-sebastian May 28, 2020
bc342a3
Update integration.test.ts
schmidt-sebastian May 28, 2020
5297d47
Update rollup.config.lite.js
schmidt-sebastian May 28, 2020
867d9c0
One more test
schmidt-sebastian May 28, 2020
084fdcf
Update reference.ts
schmidt-sebastian May 28, 2020
ca44064
Add CollectionReference
schmidt-sebastian May 28, 2020
920c0e2
Merge branch 'master' into mrschmidt/initializefirestore
schmidt-sebastian May 28, 2020
d5745f0
Merge
schmidt-sebastian May 28, 2020
b636d27
Merge
schmidt-sebastian May 28, 2020
31ba3ba
Add DocumentSnapshot
schmidt-sebastian May 28, 2020
505792f
Add exports
schmidt-sebastian May 28, 2020
3750a00
Add getDoc()
schmidt-sebastian May 28, 2020
5d3e2aa
Fix build
schmidt-sebastian May 28, 2020
58a84d1
More integration test fixes
schmidt-sebastian May 29, 2020
6f91171
Fix Integration tests
schmidt-sebastian May 29, 2020
c63977f
Add DocumentReference
schmidt-sebastian May 29, 2020
6352026
Add deleteDoc()
schmidt-sebastian May 29, 2020
be02305
Cleanup
schmidt-sebastian May 29, 2020
518631d
Merge
schmidt-sebastian May 29, 2020
6318fa4
Update datastore.ts
schmidt-sebastian May 29, 2020
efa58c4
Add converter
schmidt-sebastian May 30, 2020
1a81864
Simplify
schmidt-sebastian May 30, 2020
068d5a5
Simplify
schmidt-sebastian May 30, 2020
94e22df
Merge branch 'mrschmidt/newgetdocument' into mrschmidt/deletedoc
schmidt-sebastian May 30, 2020
555a16c
Merge branch 'mrschmidt/deletedoc' of github.com:firebase/firebase-js…
schmidt-sebastian May 30, 2020
8a7fc93
Add documentID() (#3137)
schmidt-sebastian Jun 1, 2020
c3e3375
Merge
schmidt-sebastian Jun 3, 2020
835ad93
Merge
schmidt-sebastian Jun 3, 2020
bd5a998
Merge
schmidt-sebastian Jun 3, 2020
f6553cb
Merge branch 'mrschmidt/snapshot' of github.com:firebase/firebase-js-…
schmidt-sebastian Jun 3, 2020
25f01e8
Merge
schmidt-sebastian Jun 3, 2020
6a34bbb
Merge
schmidt-sebastian Jun 4, 2020
3361a63
Feedback
schmidt-sebastian Jun 4, 2020
27bed90
Merge
schmidt-sebastian Jun 4, 2020
6f8521a
Merge branch 'master' into mrschmidt/newgetdocument
schmidt-sebastian Jun 4, 2020
4142278
Merge
schmidt-sebastian Jun 4, 2020
a005ed5
Merge
schmidt-sebastian Jun 4, 2020
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
3 changes: 2 additions & 1 deletion packages/firestore/lite/index.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export {
collection,
doc,
parent,
getDoc
getDoc,
deleteDoc
} from './src/api/reference';

// TOOD(firestorelite): Add tests when setDoc() is available
Expand Down
19 changes: 18 additions & 1 deletion packages/firestore/lite/src/api/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ import { FirebaseFirestore, FirestoreDataConverter } from '../../index';
import { ResourcePath } from '../../../src/model/path';
import { AutoId } from '../../../src/util/misc';
import { DocumentSnapshot } from './snapshot';
import { invokeBatchGetDocumentsRpc } from '../../../src/remote/datastore';
import {
invokeBatchGetDocumentsRpc,
invokeCommitRpc
} from '../../../src/remote/datastore';
import { hardAssert } from '../../../src/util/assert';
import { DeleteMutation, Precondition } from '../../../src/model/mutation';
import { cast } from './util';
import {
validateArgType,
Expand Down Expand Up @@ -266,3 +270,16 @@ export function getDoc<T>(
);
});
}

export function deleteDoc(
reference: firestore.DocumentReference
): Promise<void> {
const ref = cast(reference, DocumentReference);
return ref.firestore
._ensureClientConfigured()
.then(datastore =>
invokeCommitRpc(datastore, [
new DeleteMutation(ref._key, Precondition.none())
])
);
}
10 changes: 9 additions & 1 deletion packages/firestore/lite/test/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import {
CollectionReference,
doc,
DocumentReference,
getDoc
getDoc,
deleteDoc
} from '../src/api/reference';
import { expectEqual, expectNotEqual } from '../../test/util/helpers';
import { FieldValue } from '../../src/api/field_value';
Expand Down Expand Up @@ -171,6 +172,13 @@ describe('getDoc()', () => {
// TODO(firestorelite): Expand test coverage once we can write docs
});

describe('deleteDoc()', () => {
it('can delete a non-existing document', () => {
return withTestDoc(docRef => deleteDoc(docRef));
});
});

// TODO(firestorelite): Expand test coverage once we can write docs
describe('FieldValue', () => {
it('support equality checking with isEqual()', () => {
expectEqual(FieldValue.delete(), FieldValue.delete());
Expand Down
13 changes: 3 additions & 10 deletions packages/firestore/src/remote/datastore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import { CredentialsProvider } from '../api/credentials';
import { MaybeDocument, Document } from '../model/document';
import { DocumentKey } from '../model/document_key';
import { Mutation, MutationResult } from '../model/mutation';
import { Mutation } from '../model/mutation';
import * as api from '../protos/firestore_proto_api';
import { debugCast, hardAssert } from '../util/assert';
import { Code, FirestoreError } from '../util/error';
Expand Down Expand Up @@ -106,20 +106,13 @@ export function newDatastore(
export async function invokeCommitRpc(
datastore: Datastore,
mutations: Mutation[]
): Promise<MutationResult[]> {
): Promise<void> {
const datastoreImpl = debugCast(datastore, DatastoreImpl);
const params = {
database: datastoreImpl.serializer.encodedDatabaseId,
writes: mutations.map(m => datastoreImpl.serializer.toMutation(m))
};
const response = await datastoreImpl.invokeRPC<
api.CommitRequest,
api.CommitResponse
>('Commit', params);
return datastoreImpl.serializer.fromWriteResults(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This result is never used - but it would force me to ignore it in every callsite if we do provide it.

response.writeResults,
response.commitTime
);
await datastoreImpl.invokeRPC('Commit', params);
}

export async function invokeBatchGetDocumentsRpc(
Expand Down
9 changes: 2 additions & 7 deletions packages/firestore/test/integration/remote/remote.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,9 @@ describe('Remote Storage', () => {
addEqualityMatcher();

it('can write', () => {
return withTestDatastore(async ds => {
return withTestDatastore(ds => {
const mutation = setMutation('docs/1', { sort: 1 });
const result = await invokeCommitRpc(ds, [mutation]);
expect(result.length).to.equal(1);

const version = result[0].version;
expect(version).not.to.equal(null);
expect(SnapshotVersion.min().compareTo(version!)).to.be.lessThan(0);
return invokeCommitRpc(ds, [mutation]);
});
});

Expand Down