Skip to content

Commit 0ec6389

Browse files
backport fixes in the console to feat/pipelines (#9340)
* dist/firestore/src/global_index.d.ts now includes pipelines in namespace 'pipelines' * Update global.ts * Custom replacer plugin to remove declare module block from global.d.ts * Update CDN and g3 builds of Firestore to include Pipelines in the firebase-firestore.js file * Updated CDN bundles so that firebase-firestore.js is not modified, but firebase-firestore-pipelines.js contains both classic and pipelines APIs. * Fix regression in _internalPipelineToExecutePipelineRequestProto * Fixing missing paths in package.json * Fix binary size script * Add support for index.cdn.ts files in packages/firebase. Then added a cdn.ts to packages/firebase/firestore/pipelines * Rename grpc_connection.node.test.ts, so the file is filtered from browser unit testing.
1 parent adba599 commit 0ec6389

File tree

10 files changed

+115
-17
lines changed

10 files changed

+115
-17
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @license
3+
* Copyright 2024 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
export * from '@firebase/firestore';
19+
20+
import * as pipelines from '@firebase/firestore/pipelines';
21+
export { pipelines };

packages/firebase/gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const replace = require('gulp-replace');
2121

2222
const pkgJson = require('./package.json');
2323
const files = pkgJson.components.map(component => {
24-
const componentName = component.replace('/', '-');
24+
const componentName = component.replaceAll('/', '-');
2525
return `firebase-${componentName}.js`;
2626
});
2727
const FIREBASE_APP_URL = `https://www.gstatic.com/firebasejs/${pkgJson.version}/firebase-app.js`;

packages/firebase/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,8 @@
476476
"auth/web-extension",
477477
"functions",
478478
"firestore",
479-
"firestore/pipelines",
480479
"firestore/lite",
480+
"firestore/pipelines",
481481
"firestore/lite/pipelines",
482482
"installations",
483483
"storage",

packages/firebase/rollup.config.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import commonjs from '@rollup/plugin-commonjs';
2020
import json from '@rollup/plugin-json';
2121
import pkg from './package.json';
2222
import { resolve } from 'path';
23+
import { existsSync } from 'fs';
2324
import resolveModule from '@rollup/plugin-node-resolve';
2425
import rollupTypescriptPlugin from 'rollup-plugin-typescript2';
2526
import sourcemaps from 'rollup-plugin-sourcemaps';
@@ -149,10 +150,12 @@ const cdnBuilds = [
149150
.map(component => {
150151
// It is needed for handling sub modules, for example firestore/lite which should produce firebase-firestore-lite.js
151152
// Otherwise, we will create a directory with '/' in the name.
152-
const componentName = component.replace('/', '-');
153+
const componentName = component.replaceAll('/', '-');
153154

154155
return {
155-
input: `${component}/index.ts`,
156+
input: existsSync(`${component}/index.cdn.ts`)
157+
? `${component}/index.cdn.ts`
158+
: `${component}/index.ts`,
156159
output: {
157160
file: `firebase-${componentName}.js`,
158161
sourcemap: true,

packages/firestore/rollup.config.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,35 @@ const browserPlugins = [
5959
terser(util.manglePrivatePropertiesOptions)
6060
];
6161

62+
// TODO - update the implementation to match all content in the declare module block.
63+
function declareModuleReplacePlugin() {
64+
// The regex we created earlier
65+
const moduleToReplace =
66+
/declare module '\.\/\S+' \{\s+interface Firestore \{\s+pipeline\(\): PipelineSource<Pipeline>;\s+}\s*}/gm;
67+
68+
// What to replace it with (an empty string to remove it)
69+
const replacement =
70+
'interface Firestore {pipeline(): PipelineSource<Pipeline>;}';
71+
72+
return {
73+
name: 'declare-module-replace',
74+
generateBundle(options, bundle) {
75+
const outputFileName = 'global_index.d.ts';
76+
if (!bundle[outputFileName]) {
77+
console.warn(
78+
`[regexReplacePlugin] File not found in bundle: ${outputFileName}`
79+
);
80+
return;
81+
}
82+
83+
const chunk = bundle[outputFileName];
84+
if (chunk.type === 'chunk') {
85+
chunk.code = chunk.code.replace(moduleToReplace, replacement);
86+
}
87+
}
88+
};
89+
}
90+
6291
const allBuilds = [
6392
// Intermediate Node ESM build without build target reporting
6493
// this is an intermediate build used to generate the actual esm and cjs builds
@@ -214,15 +243,17 @@ const allBuilds = [
214243
}
215244
},
216245
{
217-
input: 'dist/firestore/src/index.d.ts',
246+
input: 'dist/firestore/src/global.d.ts',
218247
output: {
219248
file: 'dist/firestore/src/global_index.d.ts',
220249
format: 'es'
221250
},
222251
plugins: [
223252
dts({
224253
respectExternal: true
225-
})
254+
}),
255+
256+
declareModuleReplacePlugin()
226257
]
227258
}
228259
];

packages/firestore/src/global.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @license
3+
* Copyright 2025 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
// This file supports a special internal build that includes the entire
19+
// Firestore classic and pipeline api surface in one bundle.
20+
21+
import * as pipelines from './api_pipelines';
22+
export * from './api';
23+
export { pipelines };

packages/firestore/src/remote/internal_serializer.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,23 @@
1818
import { ensureFirestoreConfigured, Firestore } from '../api/database';
1919
import { AggregateImpl } from '../core/aggregate';
2020
import { queryToAggregateTarget, queryToTarget } from '../core/query';
21+
import {
22+
StructuredPipeline,
23+
StructuredPipelineOptions
24+
} from '../core/structured_pipeline';
2125
import { AggregateSpec } from '../lite-api/aggregate_types';
2226
import { getDatastore } from '../lite-api/components';
2327
import { Pipeline } from '../lite-api/pipeline';
2428
import { Query } from '../lite-api/reference';
29+
import { ExecutePipelineRequest as ProtoExecutePipelineRequest } from '../protos/firestore_proto_api';
2530
import { cast } from '../util/input_validation';
2631
import { mapToArray } from '../util/obj';
2732

28-
import { toQueryTarget, toRunAggregationQueryRequest } from './serializer';
33+
import {
34+
getEncodedDatabaseId,
35+
toQueryTarget,
36+
toRunAggregationQueryRequest
37+
} from './serializer';
2938

3039
/**
3140
* @internal
@@ -112,5 +121,15 @@ export function _internalPipelineToExecutePipelineRequestProto(
112121
if (serializer === undefined) {
113122
return null;
114123
}
115-
return pipeline._toProto(serializer);
124+
125+
const structuredPipeline = new StructuredPipeline(
126+
pipeline,
127+
new StructuredPipelineOptions()
128+
);
129+
const executePipelineRequest: ProtoExecutePipelineRequest = {
130+
database: getEncodedDatabaseId(serializer),
131+
structuredPipeline: structuredPipeline._toProto(serializer)
132+
};
133+
134+
return executePipelineRequest;
116135
}

packages/firestore/test/integration/api/pipeline.test.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -346,18 +346,19 @@ const timestampDeltaMS = 1000;
346346

347347
describe('console support', () => {
348348
it('supports internal serialization to proto', async () => {
349+
// Perform the same test as the console
349350
const pipeline = firestore
350351
.pipeline()
351-
.collection('books')
352-
.where(equal('awards.hugo', true))
353-
.select(
354-
'title',
355-
field('nestedField.level.1'),
356-
mapGet('nestedField', 'level.1').mapGet('level.2').as('nested')
357-
);
352+
.collection('customers')
353+
.where(field('country').equal('United Kingdom'));
358354

359355
const proto = _internalPipelineToExecutePipelineRequestProto(pipeline);
360-
expect(proto).not.to.be.null;
356+
357+
const expectedStructuredPipelineProto =
358+
'{"pipeline":{"stages":[{"name":"collection","options":{},"args":[{"referenceValue":"/customers"}]},{"name":"where","options":{},"args":[{"functionValue":{"name":"equal","args":[{"fieldReferenceValue":"country"},{"stringValue":"United Kingdom"}]}}]}]}}';
359+
expect(JSON.stringify(proto.structuredPipeline)).to.equal(
360+
expectedStructuredPipelineProto
361+
);
361362
});
362363
});
363364

scripts/size_report/report_binary_size.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function generateReportForCDNScripts(): Report[] {
5757
...special_files.map((file: string) => `${firebaseRoot}/${file}`),
5858
...pkgJson.components.map(
5959
(component: string) =>
60-
`${firebaseRoot}/firebase-${component.replace('/', '-')}.js`
60+
`${firebaseRoot}/firebase-${component.replaceAll('/', '-')}.js`
6161
),
6262
...compatPkgJson.components.map(
6363
(component: string) => `${firebaseRoot}/firebase-${component}-compat.js`

0 commit comments

Comments
 (0)