Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
*/
'use strict';
import assert from 'power-assert';
import extend from 'extend';
import is from 'is';
import through2 from 'through2';
import {Firestore} from '../src/index';
import {DocumentReference, CollectionReference} from '../src/reference';
import {ResourcePath} from '../src/path';
import {createInstance} from '../test/util/helpers';
const gax = require('google-gax');
const grpc = new gax.GrpcClient().grpc;
const PROJECT_ID = 'test-project';
const DATABASE_ROOT = `projects/${PROJECT_ID}/databases/(default)`;
const DEFAULT_SETTINGS = {
projectId: PROJECT_ID,
sslCreds: grpc.credentials.createInsecure(),
keyFilename: './test/fake-certificate.json',
timestampsInSnapshots: true
};
// Change the argument to 'console.log' to enable debug output.
Firestore.setLogFunction(() => {});
const bytesData = Buffer.from('AQI=', 'base64');
const allSupportedTypesProtobufJs = document('documentId', {
'use strict';
import {GrpcClient} from 'google-gax';
import {google} from '../../protos/firestore_proto_api';
import api = google.firestore.v1beta1;
import v1beta1 from '../../src/v1beta1';
// TODO: This should be a TypeScript import after the full migration.
import Firestore = require('../../src');
import {ClientPool} from '../../src/pool';
/* tslint:disable:no-any */
type GapicClient = any;
const grpc = new GrpcClient({} as any).grpc;
const SSL_CREDENTIALS = (grpc.credentials as any).createInsecure();
/* tslint:enable:no-any */
const PROJECT_ID = 'test-project';
const DATABASE_ROOT = `projects/${PROJECT_ID}/databases/(default)`;
const DOCUMENT_NAME = `${DATABASE_ROOT}/documents/collectionId/documentId`;
/** A Promise implementation that supports deferred resolution. */
export class Deferred {
promise: Promise;
resolve: (value?: R|Promise) => void = () => {};
reject: (reason?: Error) => void = () => {};
constructor() {
this.promise = new Promise(
(resolve: (value?: R|Promise) => void,
constructor(opts) {
opts = opts || {};
this._descriptors = {};
if (global.isBrowser) {
// If we're in browser, we use gRPC fallback.
opts.fallback = true;
}
// If we are in browser, we are already using fallback because of the
// "browser" field in package.json.
// But if we were explicitly requested to use fallback, let's do it now.
const gaxModule = !global.isBrowser && opts.fallback ? gax.fallback : gax;
const servicePath =
opts.servicePath || opts.apiEndpoint || this.constructor.servicePath;
// Ensure that options include the service address and port.
opts = Object.assign(
{
clientConfig: {},
port: this.constructor.port,
servicePath,
},
opts
);
// Create a `gaxGrpc` object, with any grpc-specific options
// sent to the client.
constructor(opts) {
opts = opts || {};
this._descriptors = {};
if (global.isBrowser) {
// If we're in browser, we use gRPC fallback.
opts.fallback = true;
}
// If we are in browser, we are already using fallback because of the
// "browser" field in package.json.
// But if we were explicitly requested to use fallback, let's do it now.
const gaxModule = !global.isBrowser && opts.fallback ? gax.fallback : gax;
const servicePath =
opts.servicePath || opts.apiEndpoint || this.constructor.servicePath;
// Ensure that options include the service address and port.
opts = Object.assign(
{
clientConfig: {},
port: this.constructor.port,
servicePath,
},
opts
);
// Create a `gaxGrpc` object, with any grpc-specific options
// sent to the client.
constructor(opts) {
opts = opts || {};
this._descriptors = {};
if (global.isBrowser) {
// If we're in browser, we use gRPC fallback.
opts.fallback = true;
}
// If we are in browser, we are already using fallback because of the
// "browser" field in package.json.
// But if we were explicitly requested to use fallback, let's do it now.
const gaxModule = !global.isBrowser && opts.fallback ? gax.fallback : gax;
const servicePath =
opts.servicePath || opts.apiEndpoint || this.constructor.servicePath;
// Ensure that options include the service address and port.
opts = Object.assign(
{
clientConfig: {},
port: this.constructor.port,
servicePath,
},
opts
);
// Create a `gaxGrpc` object, with any grpc-specific options
// sent to the client.
constructor(opts) {
opts = opts || {};
this._descriptors = {};
if (global.isBrowser) {
// If we're in browser, we use gRPC fallback.
opts.fallback = true;
}
// If we are in browser, we are already using fallback because of the
// "browser" field in package.json.
// But if we were explicitly requested to use fallback, let's do it now.
const gaxModule = !global.isBrowser && opts.fallback ? gax.fallback : gax;
const servicePath =
opts.servicePath || opts.apiEndpoint || this.constructor.servicePath;
// Ensure that options include the service address and port.
opts = Object.assign(
{
clientConfig: {},
port: this.constructor.port,
servicePath,
},
opts
);
// Create a `gaxGrpc` object, with any grpc-specific options
// sent to the client.
constructor(opts) {
opts = opts || {};
this._descriptors = {};
if (global.isBrowser) {
// If we're in browser, we use gRPC fallback.
opts.fallback = true;
}
// If we are in browser, we are already using fallback because of the
// "browser" field in package.json.
// But if we were explicitly requested to use fallback, let's do it now.
const gaxModule = !global.isBrowser && opts.fallback ? gax.fallback : gax;
const servicePath =
opts.servicePath || opts.apiEndpoint || this.constructor.servicePath;
// Ensure that options include the service address and port.
opts = Object.assign(
{
clientConfig: {},
port: this.constructor.port,
servicePath,
},
opts
);
// Create a `gaxGrpc` object, with any grpc-specific options
// sent to the client.
constructor(opts) {
opts = opts || {};
this._descriptors = {};
if (global.isBrowser) {
// If we're in browser, we use gRPC fallback.
opts.fallback = true;
}
// If we are in browser, we are already using fallback because of the
// "browser" field in package.json.
// But if we were explicitly requested to use fallback, let's do it now.
const gaxModule = !global.isBrowser && opts.fallback ? gax.fallback : gax;
const servicePath =
opts.servicePath || opts.apiEndpoint || this.constructor.servicePath;
// Ensure that options include the service address and port.
opts = Object.assign(
{
clientConfig: {},
port: this.constructor.port,
servicePath,
},
opts
);
// Create a `gaxGrpc` object, with any grpc-specific options
// sent to the client.
constructor(opts) {
opts = opts || {};
this._descriptors = {};
if (global.isBrowser) {
// If we're in browser, we use gRPC fallback.
opts.fallback = true;
}
// If we are in browser, we are already using fallback because of the
// "browser" field in package.json.
// But if we were explicitly requested to use fallback, let's do it now.
const gaxModule = !global.isBrowser && opts.fallback ? gax.fallback : gax;
const servicePath =
opts.servicePath || opts.apiEndpoint || this.constructor.servicePath;
// Ensure that options include the service address and port.
opts = Object.assign(
{
clientConfig: {},
port: this.constructor.port,
servicePath,
},
opts
);
// Create a `gaxGrpc` object, with any grpc-specific options
// sent to the client.
constructor(opts) {
opts = opts || {};
this._descriptors = {};
if (global.isBrowser) {
// If we're in browser, we use gRPC fallback.
opts.fallback = true;
}
// If we are in browser, we are already using fallback because of the
// "browser" field in package.json.
// But if we were explicitly requested to use fallback, let's do it now.
const gaxModule = !global.isBrowser && opts.fallback ? gax.fallback : gax;
const servicePath =
opts.servicePath || opts.apiEndpoint || this.constructor.servicePath;
// Ensure that options include the service address and port.
opts = Object.assign(
{
clientConfig: {},
port: this.constructor.port,
servicePath,
},
opts
);
// Create a `gaxGrpc` object, with any grpc-specific options
// sent to the client.