Skip to content

Commit d398704

Browse files
Load Protos from JSON
1 parent 3c20727 commit d398704

File tree

14 files changed

+2941
-287
lines changed

14 files changed

+2941
-287
lines changed

packages/firestore/rollup.config.js

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@
1818
import { version as grpcVersion } from '@grpc/grpc-js/package.json';
1919
import alias from '@rollup/plugin-alias';
2020
import json from '@rollup/plugin-json';
21-
import copy from 'rollup-plugin-copy';
2221
import replace from 'rollup-plugin-replace';
2322
import { terser } from 'rollup-plugin-terser';
2423
import typescriptPlugin from 'rollup-plugin-typescript2';
2524
import tmp from 'tmp';
26-
import { basename } from 'path';
2725
import typescript from 'typescript';
2826

2927
import { generateBuildTargetReplaceConfig } from '../../scripts/build/rollup_replace_build_target';
@@ -32,40 +30,6 @@ import pkg from './package.json';
3230

3331
const util = require('./rollup.shared');
3432

35-
// Customize how import.meta.url is polyfilled in cjs nodejs build. We use it to
36-
// be able to use require() in esm. It only generates the nodejs version of the
37-
// polyfill, as opposed to the default polyfill which supports both browser and
38-
// nodejs. The browser support doesn't work well with Jest.
39-
// See https://github.com/firebase/firebase-js-sdk/issues/5687
40-
// Although this is a cjs Node build and shouldn't require the browser option,
41-
// Vercel apps using this break on deployment, but work in local development.
42-
// See https://github.com/firebase/firebase-js-sdk/issues/5823
43-
function importMetaUrlPolyfillPlugin(filename) {
44-
return {
45-
name: 'import-meta-url-current-module',
46-
resolveImportMeta(property, { moduleId }) {
47-
if (property === 'url') {
48-
// Added a check for Jest (see issue 5687 linked above)
49-
// See https://jestjs.io/docs/environment-variables - apparently
50-
// these are not always both set.
51-
const JEST_CHECK =
52-
`typeof process !== 'undefined' && process.env !== undefined` +
53-
` && (process.env.JEST_WORKER_ID !== undefined || ` +
54-
`process.env.NODE_ENV === 'test')`;
55-
// Copied from rollup output
56-
return (
57-
`((typeof document === 'undefined' || (${JEST_CHECK})) ?` +
58-
` new (require('url').URL)` +
59-
`('file:' + __filename).href : (document.currentScript && ` +
60-
`document.currentScript.src || new URL('${filename}', ` +
61-
`document.baseURI).href))`
62-
);
63-
}
64-
return null;
65-
}
66-
};
67-
}
68-
6933
const nodePlugins = function () {
7034
return [
7135
typescriptPlugin({
@@ -80,17 +44,7 @@ const nodePlugins = function () {
8044
transformers: [util.removeAssertTransformer]
8145
}),
8246
json({ preferConst: true }),
83-
// Needed as we also use the *.proto files
84-
copy({
85-
targets: [
86-
{
87-
src: 'src/protos',
88-
dest: 'dist/src'
89-
}
90-
]
91-
}),
9247
replace({
93-
'process.env.FIRESTORE_PROTO_ROOT': JSON.stringify('src/protos'),
9448
'__GRPC_VERSION__': grpcVersion
9549
})
9650
];
@@ -142,8 +96,7 @@ const allBuilds = [
14296
},
14397
plugins: [
14498
...util.es2017ToEs5Plugins(/* mangled= */ false),
145-
replace(generateBuildTargetReplaceConfig('cjs', 2017)),
146-
importMetaUrlPolyfillPlugin(basename(pkg.main))
99+
replace(generateBuildTargetReplaceConfig('cjs', 2017))
147100
],
148101
external: util.resolveNodeExterns,
149102
treeshake: {

packages/firestore/rollup.config.lite.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import alias from '@rollup/plugin-alias';
2222
import typescriptPlugin from 'rollup-plugin-typescript2';
2323
import typescript from 'typescript';
2424
import sourcemaps from 'rollup-plugin-sourcemaps';
25-
import copy from 'rollup-plugin-copy';
2625
import replace from 'rollup-plugin-replace';
2726
import { terser } from 'rollup-plugin-terser';
2827

@@ -44,18 +43,7 @@ const nodePlugins = function () {
4443
abortOnError: false,
4544
transformers: [util.removeAssertTransformer]
4645
}),
47-
json({ preferConst: true }),
48-
copy({
49-
targets: [
50-
{
51-
src: 'src/protos',
52-
dest: 'dist/lite/src'
53-
}
54-
]
55-
}),
56-
replace({
57-
'process.env.FIRESTORE_PROTO_ROOT': JSON.stringify('src/protos')
58-
})
46+
json({ preferConst: true })
5947
];
6048
};
6149

packages/firestore/src/platform/node/load_protos.ts

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,16 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { join, resolve, isAbsolute, dirname } from 'path';
19-
import { fileURLToPath } from 'url';
20-
21-
// __filename and __dirname globals are unavailable in ES modules
22-
// @ts-ignore To avoid using `--module es2020` flag.
23-
const __filenameInESM = fileURLToPath(import.meta.url);
24-
const __dirnameInESM = dirname(__filenameInESM);
18+
import { join, resolve, isAbsolute } from 'path';
2519

2620
import { loadPackageDefinition, GrpcObject } from '@grpc/grpc-js';
27-
import { loadSync } from '@grpc/proto-loader';
21+
import { fromJSON } from '@grpc/proto-loader';
2822
// only used in tests
2923
// eslint-disable-next-line import/no-extraneous-dependencies
3024
import { IConversionOptions, Root } from 'protobufjs';
3125

26+
import * as protos from '../../protos/protos.json';
27+
3228
/** Used by tests so we can match @grpc/proto-loader behavior. */
3329
export const protoLoaderOptions: IConversionOptions = {
3430
longs: String,
@@ -43,17 +39,7 @@ export const protoLoaderOptions: IConversionOptions = {
4339
* @returns The GrpcObject representing our protos.
4440
*/
4541
export function loadProtos(): GrpcObject {
46-
const root = resolve(
47-
__dirnameInESM,
48-
process.env.FIRESTORE_PROTO_ROOT || '../../protos'
49-
);
50-
const firestoreProtoFile = join(root, 'google/firestore/v1/firestore.proto');
51-
52-
const packageDefinition = loadSync(firestoreProtoFile, {
53-
...protoLoaderOptions,
54-
includeDirs: [root]
55-
});
56-
42+
const packageDefinition = fromJSON(protos, protoLoaderOptions);
5743
return loadPackageDefinition(packageDefinition);
5844
}
5945

packages/firestore/src/protos/google/api/annotations.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2015, Google Inc.
1+
// Copyright 2015 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

packages/firestore/src/protos/google/api/http.proto

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018 Google LLC.
1+
// Copyright 2015 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -11,7 +11,6 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
//
1514

1615
syntax = "proto3";
1716

@@ -24,7 +23,6 @@ option java_outer_classname = "HttpProto";
2423
option java_package = "com.google.api";
2524
option objc_class_prefix = "GAPI";
2625

27-
2826
// Defines the HTTP configuration for an API service. It contains a list of
2927
// [HttpRule][google.api.HttpRule], each specifying the mapping of an RPC method
3028
// to one or more HTTP REST API methods.
@@ -34,7 +32,7 @@ message Http {
3432
// **NOTE:** All service configuration rules follow "last one wins" order.
3533
repeated HttpRule rules = 1;
3634

37-
// When set to true, URL path parmeters will be fully URI-decoded except in
35+
// When set to true, URL path parameters will be fully URI-decoded except in
3836
// cases of single segment matches in reserved expansion, where "%2F" will be
3937
// left encoded.
4038
//
@@ -112,7 +110,9 @@ message Http {
112110
//
113111
// HTTP | gRPC
114112
// -----|-----
115-
// `GET /v1/messages/123456?revision=2&sub.subfield=foo` | `GetMessage(message_id: "123456" revision: 2 sub: SubMessage(subfield: "foo"))`
113+
// `GET /v1/messages/123456?revision=2&sub.subfield=foo` |
114+
// `GetMessage(message_id: "123456" revision: 2 sub: SubMessage(subfield:
115+
// "foo"))`
116116
//
117117
// Note that fields which are mapped to URL query parameters must have a
118118
// primitive type or a repeated primitive type or a non-repeated message type.
@@ -144,7 +144,8 @@ message Http {
144144
//
145145
// HTTP | gRPC
146146
// -----|-----
147-
// `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: "123456" message { text: "Hi!" })`
147+
// `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id:
148+
// "123456" message { text: "Hi!" })`
148149
//
149150
// The special name `*` can be used in the body mapping to define that
150151
// every field not bound by the path template should be mapped to the
@@ -169,7 +170,8 @@ message Http {
169170
//
170171
// HTTP | gRPC
171172
// -----|-----
172-
// `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: "123456" text: "Hi!")`
173+
// `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id:
174+
// "123456" text: "Hi!")`
173175
//
174176
// Note that when using `*` in the body mapping, it is not possible to
175177
// have HTTP parameters, as all fields not bound by the path end in
@@ -200,7 +202,8 @@ message Http {
200202
// HTTP | gRPC
201203
// -----|-----
202204
// `GET /v1/messages/123456` | `GetMessage(message_id: "123456")`
203-
// `GET /v1/users/me/messages/123456` | `GetMessage(user_id: "me" message_id: "123456")`
205+
// `GET /v1/users/me/messages/123456` | `GetMessage(user_id: "me" message_id:
206+
// "123456")`
204207
//
205208
// ## Rules for HTTP mapping
206209
//
@@ -244,16 +247,18 @@ message Http {
244247
// `"{var=*}"`, when such a variable is expanded into a URL path on the client
245248
// side, all characters except `[-_.~0-9a-zA-Z]` are percent-encoded. The
246249
// server side does the reverse decoding. Such variables show up in the
247-
// [Discovery Document](https://developers.google.com/discovery/v1/reference/apis)
248-
// as `{var}`.
250+
// [Discovery
251+
// Document](https://developers.google.com/discovery/v1/reference/apis) as
252+
// `{var}`.
249253
//
250254
// If a variable contains multiple path segments, such as `"{var=foo/*}"`
251255
// or `"{var=**}"`, when such a variable is expanded into a URL path on the
252256
// client side, all characters except `[-_.~/0-9a-zA-Z]` are percent-encoded.
253257
// The server side does the reverse decoding, except "%2F" and "%2f" are left
254258
// unchanged. Such variables show up in the
255-
// [Discovery Document](https://developers.google.com/discovery/v1/reference/apis)
256-
// as `{+var}`.
259+
// [Discovery
260+
// Document](https://developers.google.com/discovery/v1/reference/apis) as
261+
// `{+var}`.
257262
//
258263
// ## Using gRPC API Service Configuration
259264
//

packages/firestore/src/protos/google/firestore/v1/common.proto

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018 Google LLC.
1+
// Copyright 2021 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -11,14 +11,13 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
//
1514

1615
syntax = "proto3";
1716

1817
package google.firestore.v1;
1918

20-
import "google/api/annotations.proto";
2119
import "google/protobuf/timestamp.proto";
20+
import "google/api/annotations.proto";
2221

2322
option csharp_namespace = "Google.Cloud.Firestore.V1";
2423
option go_package = "google.golang.org/genproto/googleapis/firestore/v1;firestore";
@@ -27,7 +26,7 @@ option java_outer_classname = "CommonProto";
2726
option java_package = "com.google.firestore.v1";
2827
option objc_class_prefix = "GCFS";
2928
option php_namespace = "Google\\Cloud\\Firestore\\V1";
30-
29+
option ruby_package = "Google::Cloud::Firestore::V1";
3130

3231
// A set of field paths on a document.
3332
// Used to restrict a get or update operation on a document to a subset of its

packages/firestore/src/protos/google/firestore/v1/document.proto

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018 Google LLC.
1+
// Copyright 2021 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -11,16 +11,15 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
//
1514

1615
syntax = "proto3";
1716

1817
package google.firestore.v1;
1918

20-
import "google/api/annotations.proto";
2119
import "google/protobuf/struct.proto";
2220
import "google/protobuf/timestamp.proto";
2321
import "google/type/latlng.proto";
22+
import "google/api/annotations.proto";
2423

2524
option csharp_namespace = "Google.Cloud.Firestore.V1";
2625
option go_package = "google.golang.org/genproto/googleapis/firestore/v1;firestore";
@@ -29,7 +28,7 @@ option java_outer_classname = "DocumentProto";
2928
option java_package = "com.google.firestore.v1";
3029
option objc_class_prefix = "GCFS";
3130
option php_namespace = "Google\\Cloud\\Firestore\\V1";
32-
31+
option ruby_package = "Google::Cloud::Firestore::V1";
3332

3433
// A Firestore document.
3534
//

0 commit comments

Comments
 (0)