Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 16 additions & 8 deletions firebase-vscode/src/data-connect/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,27 +305,35 @@ export class ResolvedDataConnectConfig {
export class ResolvedDataConnectConfigs {
constructor(readonly values: DeepReadOnly<ResolvedDataConnectConfig[]>) {}

get serviceIds() {
get serviceIds(): string[] {
return this.values.map((config) => config.value.serviceId);
}

get allConnectors() {
get allConnectors(): ResolvedConnectorYaml[] {
return this.values.flatMap((dc) => dc.resolvedConnectors);
}

findById(serviceId: string) {
return this.values.find((dc) => dc.value.serviceId === serviceId);
findById(serviceId: string): ResolvedDataConnectConfig {
const dc = this.values.find((dc) => dc.value.serviceId === serviceId);
if (!dc) {
throw new Error(`No dataconnect.yaml with serviceId ${serviceId}. Available: ${this.serviceIds.join(", ")}`);
}
return dc;
}

findEnclosingServiceForPath(filePath: string) {
return this.values.find((dc) => dc.containsPath(filePath));
findEnclosingServiceForPath(filePath: string): ResolvedDataConnectConfig {
const dc = this.values.find((dc) => dc.containsPath(filePath));
if (!dc) {
throw new Error(`No enclosing dataconnect.yaml found for path ${filePath}. Available Paths: ${this.values.map((dc) => dc.path).join(", ")}`);
}
return dc;
}

getApiServicePathByPath(projectId: string, path: string) {
getApiServicePathByPath(projectId: string | undefined, path: string): string {
const dataConnectConfig = this.findEnclosingServiceForPath(path);
const serviceId = dataConnectConfig?.value.serviceId;
const locationId = dataConnectConfig?.dataConnectLocation;
return `projects/${projectId}/locations/${locationId}/services/${serviceId}`;
return `projects/${projectId || "p"}/locations/${locationId}/services/${serviceId}`;
Copy link
Member

Choose a reason for hiding this comment

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

Do we still need this? If so, I'd suggest

Suggested change
return `projects/${projectId || "p"}/locations/${locationId}/services/${serviceId}`;
return `projects/${projectId || "demo-ignored"}/locations/${locationId}/services/${serviceId}`;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, when .firebaserc is missing. project is undefined here.

Sure, I will use the no-project placeholder.

Copy link
Member

Choose a reason for hiding this comment

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

Just add a comment that the Data Connect emulator ignores the project ID and will return the right response pretending that there's only one project

}
}

Expand Down
18 changes: 6 additions & 12 deletions firebase-vscode/src/data-connect/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,14 @@ export class DataConnectService {
async servicePath(path: string): Promise<string | undefined> {
const dataConnectConfigsValue = await firstWhereDefined(dataConnectConfigs);
// TODO: avoid calling this here and in getApiServicePathByPath
const serviceId =
dataConnectConfigsValue?.tryReadValue?.findEnclosingServiceForPath(path)
?.value.serviceId;
const projectId = firebaseRC.value?.tryReadValue?.projects?.default;

if (serviceId === undefined || projectId === undefined) {
return undefined;
const dcs = dataConnectConfigsValue?.tryReadValue;
if (!dcs) {
throw new Error("cannot find dataconnect.yaml in the project");
}

return (
dataConnectConfigsValue?.tryReadValue?.getApiServicePathByPath(
projectId,
return ( dcs?.getApiServicePathByPath(
firebaseRC.value?.tryReadValue?.projects?.default,
path,
) || `projects/p/locations/l/services/${serviceId}`
)
);
}

Expand Down
Loading