Skip to content
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

Drop Node 6 / Replace grpc w/ @grpc/grpc-js #2856

Merged
merged 10 commits into from
Apr 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
"private": true,
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
"license": "Apache-2.0",
"engines": {
"node": "^8.13.0 || >=10.10.0"
},
"homepage": "https://github.com/firebase/firebase-js-sdk",
"keywords": [
"authentication",
"database",
"Firebase",
"firebase",
"firestore",
"functions",
"realtime",
"storage",
Expand Down Expand Up @@ -57,7 +61,7 @@
"@types/chai-as-promised": "7.1.2",
"@types/long": "4.0.1",
"@types/mocha": "7.0.2",
"@types/node": "8.10.59",
"@types/node": "12.12.34",
"@types/sinon": "7.5.2",
"@types/sinon-chai": "3.2.3",
"@typescript-eslint/eslint-plugin": "2.24.0",
Expand Down
4 changes: 4 additions & 0 deletions packages/firebase/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
"license": "Apache-2.0",
"homepage": "https://firebase.google.com/",
"engines": {
"node": "^8.13.0 || >=10.10.0"
},
"keywords": [
"authentication",
"database",
"Firebase",
"firebase",
"firestore",
"realtime",
"storage",
"performance",
Expand Down
5 changes: 4 additions & 1 deletion packages/firestore/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"name": "@firebase/firestore",
"version": "1.13.1",
"engines": {
"node": "^8.13.0 || >=10.10.0"
},
"description": "The Cloud Firestore component of the Firebase JS SDK.",
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
"scripts": {
Expand Down Expand Up @@ -41,8 +44,8 @@
"@firebase/logger": "0.2.1",
"@firebase/util": "0.2.44",
"@firebase/webchannel-wrapper": "0.2.38",
"@grpc/grpc-js": "0.7.5",
"@grpc/proto-loader": "^0.5.0",
"grpc": "1.24.2",
"tslib": "1.11.1"
},
"peerDependencies": {
Expand Down
28 changes: 17 additions & 11 deletions packages/firestore/src/platform_node/grpc_connection.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/**
* @license
* Copyright 2017 Google LLC
Expand All @@ -15,13 +16,18 @@
* limitations under the License.
*/

import * as grpc from 'grpc';
import {
Metadata,
GrpcObject,
credentials as GrpcCredentials,
ServiceError
} from '@grpc/grpc-js';
import * as grpcPkgJson from '@grpc/grpc-js/package.json';

import firebase from '@firebase/app';
const SDK_VERSION = firebase.SDK_VERSION;

// eslint-disable-next-line @typescript-eslint/no-require-imports
const grpcVersion = require('grpc/package.json').version;
const grpcVersion = grpcPkgJson.version;

import { Token } from '../api/credentials';
import { DatabaseInfo } from '../core/database_info';
Expand All @@ -44,13 +50,13 @@ const X_GOOG_API_CLIENT_VALUE = `gl-node/${process.versions.node} fire/${SDK_VER
function createMetadata(
databaseInfo: DatabaseInfo,
token: Token | null
): grpc.Metadata {
): Metadata {
assert(
token === null || token.type === 'OAuth',
'If provided, token must be OAuth'
);

const metadata = new grpc.Metadata();
const metadata = new Metadata();
if (token) {
for (const header in token.authHeaders) {
if (token.authHeaders.hasOwnProperty(header)) {
Expand Down Expand Up @@ -84,7 +90,7 @@ export class GrpcConnection implements Connection {
// We cache stubs for the most-recently-used token.
private cachedStub: GeneratedGrpcStub | null = null;

constructor(protos: grpc.GrpcObject, private databaseInfo: DatabaseInfo) {
constructor(protos: GrpcObject, private databaseInfo: DatabaseInfo) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
this.firestore = (protos as any)['google']['firestore']['v1'];
}
Expand All @@ -93,8 +99,8 @@ export class GrpcConnection implements Connection {
if (!this.cachedStub) {
logDebug(LOG_TAG, 'Creating Firestore stub.');
const credentials = this.databaseInfo.ssl
? grpc.credentials.createSsl()
: grpc.credentials.createInsecure();
? GrpcCredentials.createSsl()
: GrpcCredentials.createInsecure();
this.cachedStub = new this.firestore.Firestore(
this.databaseInfo.host,
credentials
Expand All @@ -116,7 +122,7 @@ export class GrpcConnection implements Connection {
return stub[rpcName](
request,
metadata,
(grpcError?: grpc.ServiceError, value?: Resp) => {
(grpcError?: ServiceError, value?: Resp) => {
if (grpcError) {
logDebug(LOG_TAG, `RPC '${rpcName}' failed with error:`, grpcError);
callback(
Expand Down Expand Up @@ -162,7 +168,7 @@ export class GrpcConnection implements Connection {
logDebug(LOG_TAG, `RPC '${rpcName}' completed.`);
responseDeferred.resolve(results);
});
stream.on('error', (grpcError: grpc.ServiceError) => {
stream.on('error', (grpcError: ServiceError) => {
logDebug(LOG_TAG, `RPC '${rpcName}' failed with error:`, grpcError);
const code = mapCodeFromRpcCode(grpcError.code);
responseDeferred.reject(new FirestoreError(code, grpcError.message));
Expand Down Expand Up @@ -224,7 +230,7 @@ export class GrpcConnection implements Connection {
close();
});

grpcStream.on('error', (grpcError: grpc.ServiceError) => {
grpcStream.on('error', (grpcError: ServiceError) => {
logDebug(
LOG_TAG,
'GRPC stream error. Code:',
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/src/platform_node/load_protos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import { loadSync } from '@grpc/proto-loader';
import { loadPackageDefinition, GrpcObject } from 'grpc';
import { loadPackageDefinition, GrpcObject } from '@grpc/grpc-js';
import { join, resolve, isAbsolute } from 'path';
// only used in tests
// eslint-disable-next-line import/no-extraneous-dependencies
Expand Down
18 changes: 16 additions & 2 deletions packages/firestore/src/util/promise.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @license
* Copyright 2017 Google Inc.
* Copyright 2017 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,7 +23,21 @@ export interface Rejecter {
(reason?: Error): void;
}

export interface CancelablePromise<T> extends Promise<T> {
export interface CancelablePromise<T> {
// We are not extending Promise, since Node's Promise API require us to
// implement 'finally', which is not fully supported on Web.
then<TResult1 = T, TResult2 = never>(
onfulfilled?:
| ((value: T) => TResult1 | PromiseLike<TResult1>)
| undefined
| null,
onrejected?: // eslint-disable-next-line @typescript-eslint/no-explicit-any
((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null
): Promise<TResult1 | TResult2>;
catch<TResult = never>(
onrejected?: // eslint-disable-next-line @typescript-eslint/no-explicit-any
((reason: any) => TResult | PromiseLike<TResult>) | undefined | null
): Promise<T | TResult>;
cancel(): void;
}

Expand Down
4 changes: 3 additions & 1 deletion packages/testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"description": "",
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
"main": "dist/index.cjs.js",
"engines": {
"node": "^8.13.0 || >=10.10.0"
},
"files": [
"dist"
],
Expand All @@ -20,7 +23,6 @@
"@firebase/logger": "0.2.1",
"@firebase/util": "0.2.44",
"@types/request": "2.48.4",
"grpc": "1.24.2",
"request": "2.88.2"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/testing/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @license
* Copyright 2018 Google Inc.
* Copyright 2018 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,7 +21,7 @@ import { FirebaseAuthInternal } from '@firebase/auth-interop-types';
import * as request from 'request';
import { base64 } from '@firebase/util';
import { setLogLevel, LogLevel } from '@firebase/logger';
import * as grpc from 'grpc';
import * as grpc from '@grpc/grpc-js';
import * as protoLoader from '@grpc/proto-loader';
import { resolve } from 'path';
import { Component, ComponentType } from '@firebase/component';
Expand Down
Loading