MCPcopy Create free account
hub / github.com/firebase/firebase-tools / load

Function load

src/dataconnect/load.ts:84–135  ·  view source on GitHub ↗
(
  projectId: string,
  config: Config,
  sourceDirectory: string,
)

Source from the content-addressed store, hash-verified

82 * loads schemas and connectors from {sourceDirectory}/dataconnect.yaml
83 */
84export async function load(
85 projectId: string,
86 config: Config,
87 sourceDirectory: string,
88): Promise<ServiceInfo> {
89 // TODO: better error handling when config read fails
90 const resolvedDir = config.path(sourceDirectory);
91 const dataConnectYaml = await readDataConnectYaml(resolvedDir);
92 const serviceName = `projects/${projectId}/locations/${dataConnectYaml.location}/services/${dataConnectYaml.serviceId}`;
93 const schemaYamls = dataConnectYaml.schema ? [dataConnectYaml.schema] : dataConnectYaml.schemas;
94 const schemas = await Promise.all(
95 schemaYamls!.map(async (yaml) => {
96 const schemaDir = path.join(resolvedDir, yaml.source);
97 const schemaGQLs = await readGQLFiles(schemaDir);
98 return {
99 name: `${serviceName}/schemas/${yaml.id || MAIN_SCHEMA_ID}`,
100 datasources: [toDatasource(projectId, dataConnectYaml.location, yaml.datasource)],
101 source: {
102 files: schemaGQLs,
103 },
104 };
105 }),
106 );
107 const connectorInfo = await Promise.all(
108 dataConnectYaml.connectorDirs.map(async (dir) => {
109 const connectorDir = path.join(resolvedDir, dir);
110 const connectorYaml = await readConnectorYaml(connectorDir);
111 const connectorGqls = await readGQLFiles(connectorDir);
112 const clientCache = inferClientCache(connectorYaml);
113
114 return {
115 directory: connectorDir,
116 connectorYaml,
117 connector: {
118 name: `${serviceName}/connectors/${connectorYaml.connectorId}`,
119 source: {
120 files: connectorGqls,
121 },
122 client_cache: clientCache,
123 },
124 };
125 }),
126 );
127
128 return {
129 serviceName,
130 sourceDirectory: resolvedDir,
131 schemas: schemas,
132 dataConnectYaml,
133 connectorInfo,
134 };
135}
136
137export function readFirebaseJson(config?: Config): DataConnectMultiple {
138 if (!config?.has("dataconnect")) {

Callers 2

startMethod · 0.90
loadAllFunction · 0.70

Calls 7

toDatasourceFunction · 0.90
readDataConnectYamlFunction · 0.85
readGQLFilesFunction · 0.85
readConnectorYamlFunction · 0.85
inferClientCacheFunction · 0.85
allMethod · 0.80
pathMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…