Skip to content

Commit b1f6c75

Browse files
Finish TypeScript Migration (#512)
1 parent 6b5bd1e commit b1f6c75

34 files changed

+1427
-1165
lines changed

dev/conformance/runner.ts

+14-15
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,22 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {expect} from 'chai';
1817
const duplexify = require('duplexify');
1918

20-
import * as is from 'is';
19+
import {expect} from 'chai';
2120
import * as path from 'path';
2221
import * as protobufjs from 'protobufjs';
2322
import * as through2 from 'through2';
24-
2523
import * as proto from '../protos/firestore_proto_api';
26-
import api = proto.google.firestore.v1;
2724

2825
import * as Firestore from '../src';
29-
26+
import {documentFromJson} from '../src/convert';
27+
import {DocumentChangeType} from '../src/document-change';
3028
import {ResourcePath} from '../src/path';
31-
import * as convert from '../src/convert';
32-
29+
import {isObject} from '../src/util';
3330
import {createInstance as createInstanceHelper} from '../test/util/helpers';
34-
import {AnyDuringMigration} from '../src/types';
35-
import {DocumentChangeType} from '../src/document-change';
31+
32+
import api = proto.google.firestore.v1;
3633

3734
const REQUEST_TIME = 'REQUEST_TIME';
3835

@@ -93,9 +90,9 @@ const convertInput = {
9390
argument: json => {
9491
const obj = JSON.parse(json);
9592
function convertValue(value) {
96-
if (is.object(value)) {
93+
if (isObject(value)) {
9794
return convertObject(value);
98-
} else if (is.array(value)) {
95+
} else if (Array.isArray(value)) {
9996
return convertArray(value);
10097
} else if (value === 'NaN') {
10198
return NaN;
@@ -175,15 +172,15 @@ const convertInput = {
175172

176173
for (const doc of snapshot.docs) {
177174
const deepCopy = JSON.parse(JSON.stringify(doc));
178-
deepCopy.fields = convert.documentFromJson(deepCopy.fields);
175+
deepCopy.fields = documentFromJson(deepCopy.fields);
179176
docs.push(
180177
firestore.snapshot_(deepCopy, readTime, 'json') as
181178
Firestore.QueryDocumentSnapshot);
182179
}
183180

184181
for (const change of snapshot.changes) {
185182
const deepCopy = JSON.parse(JSON.stringify(change.doc));
186-
deepCopy.fields = convert.documentFromJson(deepCopy.fields);
183+
deepCopy.fields = documentFromJson(deepCopy.fields);
187184
const doc = firestore.snapshot_(deepCopy, readTime, 'json');
188185
const type =
189186
(['unspecified', 'added', 'removed', 'modified'][change.kind] as
@@ -208,7 +205,7 @@ const convertProto = {
208205
}
209206
if (deepCopy.documentChange) {
210207
deepCopy.documentChange.document.fields =
211-
convert.documentFromJson(deepCopy.documentChange.document.fields);
208+
documentFromJson(deepCopy.documentChange.document.fields);
212209
}
213210
return deepCopy;
214211
},
@@ -351,7 +348,8 @@ function runTest(spec) {
351348
const setTest = spec => {
352349
const overrides = {commit: commitHandler(spec)};
353350
return createInstance(overrides).then(() => {
354-
const setOption: AnyDuringMigration = {};
351+
const setOption: {merge?: boolean,
352+
mergeFields?: Firestore.FieldPath[]} = {};
355353
if (spec.option && spec.option.all) {
356354
setOption.merge = true;
357355
} else if (spec.option && spec.option.fields) {
@@ -472,6 +470,7 @@ describe('Conformance Tests', () => {
472470
const binaryProtoData =
473471
require('fs').readFileSync(path.join(__dirname, 'test-suite.binproto'));
474472

473+
// We don't have type information for the conformance proto.
475474
// tslint:disable-next-line:no-any
476475
const testSuite: any = TEST_SUITE_TYPE.decode(binaryProtoData);
477476

dev/src/convert.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
*/
1616

1717
import {google} from '../protos/firestore_proto_api';
18-
import api = google.firestore.v1;
19-
import {createValidator} from './validate';
18+
2019
import {ProtobufJsValue} from './types';
20+
import {validateObject} from './validate';
2121

22-
const validate = createValidator();
22+
import api = google.firestore.v1;
2323

2424
/*!
2525
* @module firestore/convert
@@ -71,7 +71,7 @@ export function timestampFromJson(
7171
nanos: nanos || undefined,
7272
};
7373
} else if (timestampValue !== undefined) {
74-
validate.isObject('timestampValue', timestampValue);
74+
validateObject('timestampValue', timestampValue);
7575
timestampProto = {
7676
seconds: timestampValue.seconds || undefined,
7777
nanos: timestampValue.nanos || undefined,

dev/src/document-change.ts

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
import {QueryDocumentSnapshot} from './document';
18+
1819
export type DocumentChangeType = 'added'|'removed'|'modified';
1920

2021
/**

0 commit comments

Comments
 (0)