Skip to content
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
21 changes: 21 additions & 0 deletions packages/firebase/firestore/pipelines/index.cdn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @license
* Copyright 2024 Google LLC
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2025?

*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export * from '@firebase/firestore';

import * as pipelines from '@firebase/firestore/pipelines';
export { pipelines };
2 changes: 1 addition & 1 deletion packages/firebase/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const replace = require('gulp-replace');

const pkgJson = require('./package.json');
const files = pkgJson.components.map(component => {
const componentName = component.replace('/', '-');
const componentName = component.replaceAll('/', '-');
return `firebase-${componentName}.js`;
});
const FIREBASE_APP_URL = `https://www.gstatic.com/firebasejs/${pkgJson.version}/firebase-app.js`;
Expand Down
2 changes: 1 addition & 1 deletion packages/firebase/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,8 @@
"auth/web-extension",
"functions",
"firestore",
"firestore/pipelines",
"firestore/lite",
"firestore/pipelines",
"firestore/lite/pipelines",
"installations",
"storage",
Expand Down
7 changes: 5 additions & 2 deletions packages/firebase/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import pkg from './package.json';
import { resolve } from 'path';
import { existsSync } from 'fs';
import resolveModule from '@rollup/plugin-node-resolve';
import rollupTypescriptPlugin from 'rollup-plugin-typescript2';
import sourcemaps from 'rollup-plugin-sourcemaps';
Expand Down Expand Up @@ -149,10 +150,12 @@ const cdnBuilds = [
.map(component => {
// It is needed for handling sub modules, for example firestore/lite which should produce firebase-firestore-lite.js
// Otherwise, we will create a directory with '/' in the name.
const componentName = component.replace('/', '-');
const componentName = component.replaceAll('/', '-');

return {
input: `${component}/index.ts`,
input: existsSync(`${component}/index.cdn.ts`)
? `${component}/index.cdn.ts`
: `${component}/index.ts`,
output: {
file: `firebase-${componentName}.js`,
sourcemap: true,
Expand Down
35 changes: 33 additions & 2 deletions packages/firestore/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,35 @@ const browserPlugins = [
terser(util.manglePrivatePropertiesOptions)
];

// TODO - update the implementation to match all content in the declare module block.
function declareModuleReplacePlugin() {
// The regex we created earlier
const moduleToReplace =
/declare module '\.\/\S+' \{\s+interface Firestore \{\s+pipeline\(\): PipelineSource<Pipeline>;\s+}\s*}/gm;

// What to replace it with (an empty string to remove it)
const replacement =
'interface Firestore {pipeline(): PipelineSource<Pipeline>;}';

return {
name: 'declare-module-replace',
generateBundle(options, bundle) {
const outputFileName = 'global_index.d.ts';
if (!bundle[outputFileName]) {
console.warn(
`[regexReplacePlugin] File not found in bundle: ${outputFileName}`
);
return;
}

const chunk = bundle[outputFileName];
if (chunk.type === 'chunk') {
chunk.code = chunk.code.replace(moduleToReplace, replacement);
}
}
};
}

const allBuilds = [
// Intermediate Node ESM build without build target reporting
// this is an intermediate build used to generate the actual esm and cjs builds
Expand Down Expand Up @@ -214,15 +243,17 @@ const allBuilds = [
}
},
{
input: 'dist/firestore/src/index.d.ts',
input: 'dist/firestore/src/global.d.ts',
output: {
file: 'dist/firestore/src/global_index.d.ts',
format: 'es'
},
plugins: [
dts({
respectExternal: true
})
}),

declareModuleReplacePlugin()
]
}
];
Expand Down
23 changes: 23 additions & 0 deletions packages/firestore/src/global.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* @license
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// This file supports a special internal build that includes the entire
// Firestore classic and pipeline api surface in one bundle.

import * as pipelines from './api_pipelines';
export * from './api';
export { pipelines };
23 changes: 21 additions & 2 deletions packages/firestore/src/remote/internal_serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,23 @@
import { ensureFirestoreConfigured, Firestore } from '../api/database';
import { AggregateImpl } from '../core/aggregate';
import { queryToAggregateTarget, queryToTarget } from '../core/query';
import {
StructuredPipeline,
StructuredPipelineOptions
} from '../core/structured_pipeline';
import { AggregateSpec } from '../lite-api/aggregate_types';
import { getDatastore } from '../lite-api/components';
import { Pipeline } from '../lite-api/pipeline';
import { Query } from '../lite-api/reference';
import { ExecutePipelineRequest as ProtoExecutePipelineRequest } from '../protos/firestore_proto_api';
import { cast } from '../util/input_validation';
import { mapToArray } from '../util/obj';

import { toQueryTarget, toRunAggregationQueryRequest } from './serializer';
import {
getEncodedDatabaseId,
toQueryTarget,
toRunAggregationQueryRequest
} from './serializer';

/**
* @internal
Expand Down Expand Up @@ -112,5 +121,15 @@ export function _internalPipelineToExecutePipelineRequestProto(
if (serializer === undefined) {
return null;
}
return pipeline._toProto(serializer);

const structuredPipeline = new StructuredPipeline(
pipeline,
new StructuredPipelineOptions()
);
const executePipelineRequest: ProtoExecutePipelineRequest = {
database: getEncodedDatabaseId(serializer),
structuredPipeline: structuredPipeline._toProto(serializer)
};

return executePipelineRequest;
}
17 changes: 9 additions & 8 deletions packages/firestore/test/integration/api/pipeline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,18 +346,19 @@ const timestampDeltaMS = 1000;

describe('console support', () => {
it('supports internal serialization to proto', async () => {
// Perform the same test as the console
const pipeline = firestore
.pipeline()
.collection('books')
.where(equal('awards.hugo', true))
.select(
'title',
field('nestedField.level.1'),
mapGet('nestedField', 'level.1').mapGet('level.2').as('nested')
);
.collection('customers')
.where(field('country').equal('United Kingdom'));

const proto = _internalPipelineToExecutePipelineRequestProto(pipeline);
expect(proto).not.to.be.null;

const expectedStructuredPipelineProto =
'{"pipeline":{"stages":[{"name":"collection","options":{},"args":[{"referenceValue":"/customers"}]},{"name":"where","options":{},"args":[{"functionValue":{"name":"equal","args":[{"fieldReferenceValue":"country"},{"stringValue":"United Kingdom"}]}}]}]}}';
expect(JSON.stringify(proto.structuredPipeline)).to.equal(
expectedStructuredPipelineProto
);
});
});

Expand Down
2 changes: 1 addition & 1 deletion scripts/size_report/report_binary_size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function generateReportForCDNScripts(): Report[] {
...special_files.map((file: string) => `${firebaseRoot}/${file}`),
...pkgJson.components.map(
(component: string) =>
`${firebaseRoot}/firebase-${component.replace('/', '-')}.js`
`${firebaseRoot}/firebase-${component.replaceAll('/', '-')}.js`
),
...compatPkgJson.components.map(
(component: string) => `${firebaseRoot}/firebase-${component}-compat.js`
Expand Down
Loading