Skip to content

Commit f63a3e5

Browse files
committed
Merge branch 'master' of https://github.com/firebase/firebase-js-sdk into issue-2393
2 parents e63607a + 0395a1d commit f63a3e5

File tree

6 files changed

+84
-12
lines changed

6 files changed

+84
-12
lines changed

packages/firestore/exp/index.d.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@ export interface SnapshotMetadata {
5252
isEqual(other: SnapshotMetadata): boolean;
5353
}
5454

55-
export type LogLevel = 'debug' | 'error' | 'silent';
55+
export type LogLevel =
56+
| 'debug'
57+
| 'error'
58+
| 'silent'
59+
| 'warn'
60+
| 'info'
61+
| 'verbose';
5662

5763
export function setLogLevel(logLevel: LogLevel): void;
5864

@@ -169,10 +175,7 @@ export class Transaction {
169175

170176
get<T>(documentRef: DocumentReference<T>): Promise<DocumentSnapshot<T>>;
171177

172-
set<T>(
173-
documentRef: DocumentReference<T>,
174-
data: T,
175-
): Transaction;
178+
set<T>(documentRef: DocumentReference<T>, data: T): Transaction;
176179
set<T>(
177180
documentRef: DocumentReference<T>,
178181
data: Partial<T>,
@@ -193,10 +196,7 @@ export class Transaction {
193196
export class WriteBatch {
194197
private constructor();
195198

196-
set<T>(
197-
documentRef: DocumentReference<T>,
198-
data: T,
199-
): WriteBatch;
199+
set<T>(documentRef: DocumentReference<T>, data: T): WriteBatch;
200200
set<T>(
201201
documentRef: DocumentReference<T>,
202202
data: Partial<T>,

packages/firestore/lite/index.d.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ export interface Settings {
3333
ignoreUndefinedProperties?: boolean;
3434
}
3535

36-
export type LogLevel = 'debug' | 'error' | 'silent';
36+
export type LogLevel =
37+
| 'debug'
38+
| 'error'
39+
| 'silent'
40+
| 'warn'
41+
| 'info'
42+
| 'verbose';
3743

3844
export function setLogLevel(logLevel: LogLevel): void;
3945

packages/firestore/lite/index.node.ts

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export {
2828
getFirestore
2929
} from './src/api/database';
3030

31+
export { DocumentReference } from './src/api/reference';
32+
3133
// TOOD(firestorelite): Add tests when setDoc() is available
3234
export {
3335
FieldValue,
@@ -38,6 +40,8 @@ export {
3840
serverTimestamp
3941
} from './src/api/field_value';
4042

43+
export { setLogLevel } from '../src/util/log';
44+
4145
export function registerFirestore(): void {
4246
_registerComponent(
4347
new Component(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import * as firestore from '../../index';
19+
20+
import { DocumentKey } from '../../../src/model/document_key';
21+
import { Firestore } from './database';
22+
import { DocumentKeyReference } from '../../../src/api/user_data_reader';
23+
24+
/**
25+
* A reference to a particular document in a collection in the database.
26+
*/
27+
export class DocumentReference<T = firestore.DocumentData>
28+
extends DocumentKeyReference<T>
29+
implements firestore.DocumentReference<T> {
30+
constructor(
31+
readonly firestore: Firestore,
32+
key: DocumentKey,
33+
readonly _converter?: firestore.FirestoreDataConverter<T>
34+
) {
35+
super(firestore._databaseId, key, _converter);
36+
}
37+
38+
get id(): string {
39+
return this._key.path.lastSegment();
40+
}
41+
42+
get path(): string {
43+
return this._key.path.canonicalString();
44+
}
45+
46+
withConverter<U>(
47+
converter: firestore.FirestoreDataConverter<U>
48+
): firestore.DocumentReference<U> {
49+
return new DocumentReference<U>(this.firestore, this._key, converter);
50+
}
51+
}

packages/firestore/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
99
"scripts": {
1010
"prebuild": "tsc -m es2015 --moduleResolution node scripts/*.ts ",
11+
"prebuild:release": "yarn prebuild",
1112
"build": "rollup -c rollup.config.es2017.js && rollup -c rollup.config.es5.js && yarn build:lite",
13+
"build:release": "rollup -c rollup.config.es2017.js && rollup -c rollup.config.es5.js",
1214
"build:deps": "lerna run --scope @firebase/'{app,firestore}' --include-dependencies build",
1315
"build:console": "node tools/console.build.js",
1416
"build:exp": "rollup -c rollup.config.exp.js",
@@ -35,7 +37,7 @@
3537
"test:minified": "(cd ../../integration/firestore ; yarn test)",
3638
"pretest:lite": "yarn build:lite",
3739
"test:lite": "TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'lite/test/**/*.test.ts' --file lite/index.node.ts --config ../../config/mocharc.node.js",
38-
"prepare": "yarn build"
40+
"prepare": "yarn build:release"
3941
},
4042
"main": "dist/index.node.cjs.js",
4143
"main-esm2017": "dist/index.node.esm2017.js",

packages/firestore/src/api/user_data_reader.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ import { PlatformSupport } from '../platform/platform';
4949

5050
const RESERVED_FIELD_REGEX = /^__.*__$/;
5151

52+
/**
53+
* An untyped Firestore Data Converter interface that is shared between the
54+
* lite, full and legacy SDK.
55+
*/
56+
export interface UntypedFirestoreDataConverter<T> {
57+
toFirestore(modelObject: T): firestore.DocumentData;
58+
fromFirestore(snapshot: unknown, options?: unknown): T;
59+
}
60+
5261
/**
5362
* A reference to a document in a Firebase project.
5463
*
@@ -59,7 +68,7 @@ export class DocumentKeyReference<T> {
5968
constructor(
6069
public readonly _databaseId: DatabaseId,
6170
public readonly _key: DocumentKey,
62-
public readonly _converter?: firestore.FirestoreDataConverter<T>
71+
public readonly _converter?: UntypedFirestoreDataConverter<T>
6372
) {}
6473
}
6574

0 commit comments

Comments
 (0)