Skip to content

Commit

Permalink
deps/refactor: Removing @google-cloud/projectify (#564)
Browse files Browse the repository at this point in the history
  • Loading branch information
schmidt-sebastian committed Mar 12, 2019
1 parent 44ad277 commit 114de25
Show file tree
Hide file tree
Showing 20 changed files with 712 additions and 633 deletions.
26 changes: 14 additions & 12 deletions dev/conformance/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import * as proto from '../protos/firestore_proto_api';
import {DocumentChange, DocumentSnapshot, FieldPath, FieldValue, Firestore, Query, QueryDocumentSnapshot, QuerySnapshot, Timestamp} from '../src';
import {fieldsFromJson} from '../src/convert';
import {DocumentChangeType} from '../src/document-change';
import {ResourcePath} from '../src/path';
import {QualifiedResourcePath} from '../src/path';
import {DocumentData} from '../src/types';
import {isObject} from '../src/util';
import {ApiOverride, createInstance as createInstanceHelper} from '../test/util/helpers';
Expand Down Expand Up @@ -68,13 +68,13 @@ const COMMIT_REQUEST_TYPE =
let firestore: Firestore;

const docRef = (path: string) => {
const relativePath = ResourcePath.fromSlashSeparatedString(path).relativeName;
return firestore.doc(relativePath);
const resourcePath = QualifiedResourcePath.fromSlashSeparatedString(path);
return firestore.doc(resourcePath.relativeName);
};

const collRef = (path: string) => {
const relativePath = ResourcePath.fromSlashSeparatedString(path).relativeName;
return firestore.collection(relativePath);
const resourcePath = QualifiedResourcePath.fromSlashSeparatedString(path);
return firestore.collection(resourcePath.relativeName);
};

const watchQuery = () => {
Expand Down Expand Up @@ -287,7 +287,7 @@ function runTest(spec: ConformanceProto) {
varargs[0] = convertInput.argument(spec.jsonData);
} else {
for (let i = 0; i < spec.fieldPaths.length; ++i) {
varargs[2 * i] = new FieldPath(spec.fieldPaths[i].field);
varargs[2 * i] = new FieldPath(...spec.fieldPaths[i].field);
}
for (let i = 0; i < spec.jsonValues.length; ++i) {
varargs[2 * i + 1] = convertInput.argument(spec.jsonValues[i]);
Expand Down Expand Up @@ -324,15 +324,17 @@ function runTest(spec: ConformanceProto) {
} else if (clause.limit) {
query = query.limit(clause.limit);
} else if (clause.startAt) {
query = query.startAt.apply(query, convertInput.cursor(clause.startAt));
const cursor = convertInput.cursor(clause.startAt);
query = query.startAt(...cursor);
} else if (clause.startAfter) {
query = query.startAfter.apply(
query, convertInput.cursor(clause.startAfter));
const cursor = convertInput.cursor(clause.startAfter);
query = query.startAfter(...cursor);
} else if (clause.endAt) {
query = query.endAt.apply(query, convertInput.cursor(clause.endAt));
const cursor = convertInput.cursor(clause.endAt);
query = query.endAt(...cursor);
} else if (clause.endBefore) {
query =
query.endBefore.apply(query, convertInput.cursor(clause.endBefore));
const cursor = convertInput.cursor(clause.endBefore);
query = query.endBefore(...cursor);
}

return query;
Expand Down
30 changes: 16 additions & 14 deletions dev/src/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ export class DocumentSnapshot {
* 'target'.
*/
function merge(
target: ApiMapValue, value: unknown, path: string[], pos: number) {
target: ApiMapValue, value: unknown, path: string[],
pos: number): ApiMapValue|null {
const key = path[pos];
const isLast = pos === path.length - 1;

Expand Down Expand Up @@ -199,10 +200,10 @@ export class DocumentSnapshot {

const res: ApiMapValue = {};

data.forEach((value, key) => {
const components = key.toArray();
merge(res, value, components, 0);
});
for (const [key, value] of data) {
const path = key.toArray();
merge(res, value, path, 0);
}

return new DocumentSnapshot(ref, res);
}
Expand Down Expand Up @@ -445,7 +446,7 @@ export class DocumentSnapshot {
* @private
* @returns The document in the format the API expects.
*/
toProto(): api.IWrite|null {
toProto(): api.IWrite {
return {
update: {
name: this._ref.formattedName,
Expand Down Expand Up @@ -790,8 +791,8 @@ export class DocumentMask {
const result = applyDocumentMask(data);

if (result.remainingPaths.length !== 0) {
throw new Error(`Input data is missing for field "${
result.remainingPaths[0].toString()}".`);
throw new Error(
`Input data is missing for field "${result.remainingPaths[0]}".`);
}

return result.filteredData;
Expand Down Expand Up @@ -942,15 +943,15 @@ export class DocumentTransform {
return null;
}

const protoTransforms: Array<{}> = [];
this.transforms.forEach((transform, path) => {
protoTransforms.push(transform.toProto(serializer, path));
});
const fieldTransforms: api.DocumentTransform.IFieldTransform[] = [];
for (const [path, transform] of this.transforms) {
fieldTransforms.push(transform.toProto(serializer, path));
}

return {
transform: {
document: this.ref.formattedName,
fieldTransforms: protoTransforms,
fieldTransforms,
},
};
}
Expand Down Expand Up @@ -998,7 +999,8 @@ export class Precondition {
const proto: api.IPrecondition = {};

if (this._lastUpdateTime !== undefined) {
proto.updateTime = this._lastUpdateTime!.toProto().timestampValue;
const valueProto = this._lastUpdateTime!.toProto();
proto.updateTime = valueProto.timestampValue;
} else {
proto.exists = this._exists;
}
Expand Down
Loading

0 comments on commit 114de25

Please sign in to comment.