@@ -20,6 +20,7 @@ import { DataConnectMultiple } from "../firebaseConfig";
20
20
import path from "path" ;
21
21
import { ExtensionBrokerImpl } from "../extension-broker" ;
22
22
import * as fs from "fs" ;
23
+ import { EmulatorHub } from "../emulator/hub" ;
23
24
24
25
export * from "../core/config" ;
25
26
@@ -305,26 +306,37 @@ export class ResolvedDataConnectConfig {
305
306
export class ResolvedDataConnectConfigs {
306
307
constructor ( readonly values : DeepReadOnly < ResolvedDataConnectConfig [ ] > ) { }
307
308
308
- get serviceIds ( ) {
309
+ get serviceIds ( ) : string [ ] {
309
310
return this . values . map ( ( config ) => config . value . serviceId ) ;
310
311
}
311
312
312
- get allConnectors ( ) {
313
+ get allConnectors ( ) : ResolvedConnectorYaml [ ] {
313
314
return this . values . flatMap ( ( dc ) => dc . resolvedConnectors ) ;
314
315
}
315
316
316
- findById ( serviceId : string ) {
317
- return this . values . find ( ( dc ) => dc . value . serviceId === serviceId ) ;
317
+ findById ( serviceId : string ) : ResolvedDataConnectConfig {
318
+ const dc = this . values . find ( ( dc ) => dc . value . serviceId === serviceId ) ;
319
+ if ( ! dc ) {
320
+ throw new Error ( `No dataconnect.yaml with serviceId ${ serviceId } . Available: ${ this . serviceIds . join ( ", " ) } ` ) ;
321
+ }
322
+ return dc ;
318
323
}
319
324
320
- findEnclosingServiceForPath ( filePath : string ) {
321
- return this . values . find ( ( dc ) => dc . containsPath ( filePath ) ) ;
325
+ findEnclosingServiceForPath ( filePath : string ) : ResolvedDataConnectConfig {
326
+ const dc = this . values . find ( ( dc ) => dc . containsPath ( filePath ) ) ;
327
+ if ( ! dc ) {
328
+ throw new Error ( `No enclosing dataconnect.yaml found for path ${ filePath } . Available Paths: ${ this . values . map ( ( dc ) => dc . path ) . join ( ", " ) } ` ) ;
329
+ }
330
+ return dc ;
322
331
}
323
332
324
- getApiServicePathByPath ( projectId : string , path : string ) {
333
+ getApiServicePathByPath ( projectId : string | undefined , path : string ) : string {
325
334
const dataConnectConfig = this . findEnclosingServiceForPath ( path ) ;
326
335
const serviceId = dataConnectConfig ?. value . serviceId ;
327
336
const locationId = dataConnectConfig ?. dataConnectLocation ;
337
+ // FDC emulator can service multiple services keyed by serviceId.
338
+ // ${projectId} and ${locationId} aren't used to resolve emulator service.
339
+ projectId = projectId || EmulatorHub . MISSING_PROJECT_PLACEHOLDER ;
328
340
return `projects/${ projectId } /locations/${ locationId } /services/${ serviceId } ` ;
329
341
}
330
342
}
0 commit comments