Skip to content

Commit 5a63738

Browse files
Drop Node 6 / Replace grpc w/ @grpc/grpc-js (#2856)
1 parent 7766278 commit 5a63738

File tree

9 files changed

+1536
-1644
lines changed

9 files changed

+1536
-1644
lines changed

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
"private": true,
66
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
77
"license": "Apache-2.0",
8+
"engines": {
9+
"node": "^8.13.0 || >=10.10.0"
10+
},
811
"homepage": "https://github.com/firebase/firebase-js-sdk",
912
"keywords": [
1013
"authentication",
1114
"database",
1215
"Firebase",
1316
"firebase",
17+
"firestore",
1418
"functions",
1519
"realtime",
1620
"storage",
@@ -57,7 +61,7 @@
5761
"@types/chai-as-promised": "7.1.2",
5862
"@types/long": "4.0.1",
5963
"@types/mocha": "7.0.2",
60-
"@types/node": "8.10.59",
64+
"@types/node": "12.12.34",
6165
"@types/sinon": "7.5.2",
6266
"@types/sinon-chai": "3.2.3",
6367
"@typescript-eslint/eslint-plugin": "2.24.0",

packages/firebase/package.json

+4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
66
"license": "Apache-2.0",
77
"homepage": "https://firebase.google.com/",
8+
"engines": {
9+
"node": "^8.13.0 || >=10.10.0"
10+
},
811
"keywords": [
912
"authentication",
1013
"database",
1114
"Firebase",
1215
"firebase",
16+
"firestore",
1317
"realtime",
1418
"storage",
1519
"performance",

packages/firestore/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"name": "@firebase/firestore",
33
"version": "1.13.1",
4+
"engines": {
5+
"node": "^8.13.0 || >=10.10.0"
6+
},
47
"description": "The Cloud Firestore component of the Firebase JS SDK.",
58
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
69
"scripts": {
@@ -41,8 +44,8 @@
4144
"@firebase/logger": "0.2.1",
4245
"@firebase/util": "0.2.44",
4346
"@firebase/webchannel-wrapper": "0.2.38",
47+
"@grpc/grpc-js": "0.7.5",
4448
"@grpc/proto-loader": "^0.5.0",
45-
"grpc": "1.24.2",
4649
"tslib": "1.11.1"
4750
},
4851
"peerDependencies": {

packages/firestore/src/platform_node/grpc_connection.ts

+17-11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
/**
23
* @license
34
* Copyright 2017 Google LLC
@@ -15,13 +16,18 @@
1516
* limitations under the License.
1617
*/
1718

18-
import * as grpc from 'grpc';
19+
import {
20+
Metadata,
21+
GrpcObject,
22+
credentials as GrpcCredentials,
23+
ServiceError
24+
} from '@grpc/grpc-js';
25+
import * as grpcPkgJson from '@grpc/grpc-js/package.json';
1926

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

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

2632
import { Token } from '../api/credentials';
2733
import { DatabaseInfo } from '../core/database_info';
@@ -44,13 +50,13 @@ const X_GOOG_API_CLIENT_VALUE = `gl-node/${process.versions.node} fire/${SDK_VER
4450
function createMetadata(
4551
databaseInfo: DatabaseInfo,
4652
token: Token | null
47-
): grpc.Metadata {
53+
): Metadata {
4854
assert(
4955
token === null || token.type === 'OAuth',
5056
'If provided, token must be OAuth'
5157
);
5258

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

87-
constructor(protos: grpc.GrpcObject, private databaseInfo: DatabaseInfo) {
93+
constructor(protos: GrpcObject, private databaseInfo: DatabaseInfo) {
8894
// eslint-disable-next-line @typescript-eslint/no-explicit-any
8995
this.firestore = (protos as any)['google']['firestore']['v1'];
9096
}
@@ -93,8 +99,8 @@ export class GrpcConnection implements Connection {
9399
if (!this.cachedStub) {
94100
logDebug(LOG_TAG, 'Creating Firestore stub.');
95101
const credentials = this.databaseInfo.ssl
96-
? grpc.credentials.createSsl()
97-
: grpc.credentials.createInsecure();
102+
? GrpcCredentials.createSsl()
103+
: GrpcCredentials.createInsecure();
98104
this.cachedStub = new this.firestore.Firestore(
99105
this.databaseInfo.host,
100106
credentials
@@ -116,7 +122,7 @@ export class GrpcConnection implements Connection {
116122
return stub[rpcName](
117123
request,
118124
metadata,
119-
(grpcError?: grpc.ServiceError, value?: Resp) => {
125+
(grpcError?: ServiceError, value?: Resp) => {
120126
if (grpcError) {
121127
logDebug(LOG_TAG, `RPC '${rpcName}' failed with error:`, grpcError);
122128
callback(
@@ -162,7 +168,7 @@ export class GrpcConnection implements Connection {
162168
logDebug(LOG_TAG, `RPC '${rpcName}' completed.`);
163169
responseDeferred.resolve(results);
164170
});
165-
stream.on('error', (grpcError: grpc.ServiceError) => {
171+
stream.on('error', (grpcError: ServiceError) => {
166172
logDebug(LOG_TAG, `RPC '${rpcName}' failed with error:`, grpcError);
167173
const code = mapCodeFromRpcCode(grpcError.code);
168174
responseDeferred.reject(new FirestoreError(code, grpcError.message));
@@ -224,7 +230,7 @@ export class GrpcConnection implements Connection {
224230
close();
225231
});
226232

227-
grpcStream.on('error', (grpcError: grpc.ServiceError) => {
233+
grpcStream.on('error', (grpcError: ServiceError) => {
228234
logDebug(
229235
LOG_TAG,
230236
'GRPC stream error. Code:',

packages/firestore/src/platform_node/load_protos.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
import { loadSync } from '@grpc/proto-loader';
19-
import { loadPackageDefinition, GrpcObject } from 'grpc';
19+
import { loadPackageDefinition, GrpcObject } from '@grpc/grpc-js';
2020
import { join, resolve, isAbsolute } from 'path';
2121
// only used in tests
2222
// eslint-disable-next-line import/no-extraneous-dependencies

packages/firestore/src/util/promise.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright 2017 Google Inc.
3+
* Copyright 2017 Google LLC
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -23,7 +23,21 @@ export interface Rejecter {
2323
(reason?: Error): void;
2424
}
2525

26-
export interface CancelablePromise<T> extends Promise<T> {
26+
export interface CancelablePromise<T> {
27+
// We are not extending Promise, since Node's Promise API require us to
28+
// implement 'finally', which is not fully supported on Web.
29+
then<TResult1 = T, TResult2 = never>(
30+
onfulfilled?:
31+
| ((value: T) => TResult1 | PromiseLike<TResult1>)
32+
| undefined
33+
| null,
34+
onrejected?: // eslint-disable-next-line @typescript-eslint/no-explicit-any
35+
((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null
36+
): Promise<TResult1 | TResult2>;
37+
catch<TResult = never>(
38+
onrejected?: // eslint-disable-next-line @typescript-eslint/no-explicit-any
39+
((reason: any) => TResult | PromiseLike<TResult>) | undefined | null
40+
): Promise<T | TResult>;
2741
cancel(): void;
2842
}
2943

packages/testing/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
"description": "",
55
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
66
"main": "dist/index.cjs.js",
7+
"engines": {
8+
"node": "^8.13.0 || >=10.10.0"
9+
},
710
"files": [
811
"dist"
912
],
@@ -20,7 +23,6 @@
2023
"@firebase/logger": "0.2.1",
2124
"@firebase/util": "0.2.44",
2225
"@types/request": "2.48.4",
23-
"grpc": "1.24.2",
2426
"request": "2.88.2"
2527
},
2628
"devDependencies": {

packages/testing/src/api/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright 2018 Google Inc.
3+
* Copyright 2018 Google LLC
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@ import { FirebaseAuthInternal } from '@firebase/auth-interop-types';
2121
import * as request from 'request';
2222
import { base64 } from '@firebase/util';
2323
import { setLogLevel, LogLevel } from '@firebase/logger';
24-
import * as grpc from 'grpc';
24+
import * as grpc from '@grpc/grpc-js';
2525
import * as protoLoader from '@grpc/proto-loader';
2626
import { resolve } from 'path';
2727
import { Component, ComponentType } from '@firebase/component';

0 commit comments

Comments
 (0)